Client SDK for interacting with your Bastion application. If you would like to know more, you can read our Bastion case study here.
- To install:
npm install bastion-sdk
within your project directory. - Import the package in your JavaScript file:
import initialize from 'bastion-sdk'
- Initialize the SDK:
const sdk = initialize("yourURL", "yourApiKey")
- You can get the URL and API key for your application instance in your Bastion admin app.
- To deploy your admin app, you can view instructions for the Bastion cli.
- You are now ready to use the SDK methods below in your JavaScript code.
Register a new user, email, and password. Passwords are stored as encrypted values.
Inputs:
- username: String
- email: String
- password: String
Outputs:
- Status 200
Log in a user with the given username and password.
Inputs:
- username: String
- password: String
Outputs:
- Status 200
Logout current user and invalidate their session.
Inputs:
- None
Outputs:
- Status 200
Get all items in a collection with the given collection name.
Inputs:
- collectionName: String
Outputs:
- Status 200
- Array of items as JSON objects:
[
{
"_id": "62506e75c2c8fa04b730e509",
"name": "example_property",
"createdAt": "2022-04-08T17:18:45.525Z",
"updatedAt": "2022-04-08T17:18:45.525Z",
"__v":0
},
{
"_id": "62509a30c2c8fa04b730e521",
"name": "another_example_property",
"createdAt": "2022-04-08T20:25:20.040Z",
"updatedAt": "2022-04-08T20:25:20.040Z",
"__v":0
},
]
Get a single database record with the given collection name and ID.
Inputs:
- collectionName: String
- itemId: String
Outputs:
- Status 200
- The database record as a JSON object:
{
"_id": "62506e75c2c8fa04b730e509",
"name": "example_property",
"createdAt": "2022-04-08T17:18:45.525Z",
"updatedAt": "2022-04-08T17:18:45.525Z",
"__v":0
}
Create a single database record in the collection specified. Pass in the JSON object you want to store in that collection.
Inputs:
- collectionName: String
- data: JSON object
Outputs:
- Status 201
- The newly created database record as a JSON object:
{
"_id": "62506e75c2c8fa04b730e509",
"name": "newly_created_property",
"createdAt": "2022-04-08T17:18:45.525Z",
"updatedAt": "2022-04-08T17:18:45.525Z",
"__v":0
}
Overwrite a single database record with the given collection name and ID. Pass in the JSON object with key-value pairs you wish to overwrite. Other key-value pairs remain unchanged.
Inputs:
- collectionName: String
- itemId: String
- data: JSON object
Outputs:
- Status 201
- The updated database record as a JSON object:
{
"_id": "62506e75c2c8fa04b730e509",
"name": "overwritten_property",
"createdAt": "2022-04-08T17:18:45.525Z",
"updatedAt": "2022-04-08T17:18:45.525Z",
"__v":0
}
Update a single database record in the collection specified. Pass in the updated JSON object you want to store in that collection. Replaces the entire record, so you must supply all key-value pairs, even if they have not changed.
Inputs:
- collectionName: String
- itemId: String
- data: JSON object
Outputs:
- Status 201
- The updated database record as a JSON object:
{
"_id": "62506e75c2c8fa04b730e509",
"name": "updated_property",
"createdAt": "2022-04-08T17:18:45.525Z",
"updatedAt": "2022-04-08T17:18:45.525Z",
"__v":0
}
Delete a single database record with the given collection name and ID.
Inputs:
- collectionName: String
- itemId: String
Outputs:
- Status 204
Runs the code for an existing cloud code function in your Bastion application and returns the resulting value.
Inputs:
- cloudFunctionName: String
- parameters (optional): determined by the user
Outputs:
- Return value of the cloud code function specified
- Status 200
Retrieves all files that have been uploaded.
Inputs:
- None
Outputs:
- Status 200
- Array of files as JSON objects:
[
{
"fileName":"exampleImage.png",
"url":"https://s3_bucket_url.png",
"createdAt":"2022-04-08T16:38:35.768Z",
"updatedAt":"2022-04-08T16:38:35.768Z",
"id":"6250650bc2c8fa04b730e4f1"
},
{
"fileName":"exampleFile.zip",
"url":"https://another_s3_bucket_url.zip",
"createdAt":"2022-04-08T20:35:47.633Z",
"updatedAt":"2022-04-08T20:35:47.633Z",
"id":"62509ca3c2c8fa04b730e528"
}
]
Retrieve a single file with the given file ID.
Inputs:
- fileId: String
Outputs:
- Status 200
- File specified as a JSON object:
{
"fileName":"exampleImage.png",
"url":"https://s3_bucket_url.png",
"createdAt":"2022-04-08T16:38:35.768Z",
"updatedAt":"2022-04-08T16:38:35.768Z",
"id":"6250650bc2c8fa04b730e4f1"
}
Uploads your file as multipart/form-data to a public S3 bucket.
Inputs:
- file: multipart/form-data
- fileName: String
Outputs:
- Status 201
- The newly created file as an object:
{
"fileName":"yourCreatedImage.png",
"url":"https://s3_bucket_url.png",
"createdAt":"2022-04-08T16:38:35.768Z",
"updatedAt":"2022-04-08T16:38:35.768Z",
"id":"6250650bc2c8fa04b730e4f1"
}
Deletes a file with the given file ID.
Inputs:
- fileId: String
Outputs:
- Status 204