- Table of Contents
- Available packages
- Installation
- Getting Started
- Configuration
- API Versions
- async/await
- Promises
- Error handling
- Documentation
- Contributing
- License
- @smash-sdk/billing
- @smash-sdk/customization
- @smash-sdk/discovery
- @smash-sdk/directory
- @smash-sdk/domain
- @smash-sdk/iam
- @smash-sdk/image
- @smash-sdk/link
- @smash-sdk/promotion
- @smash-sdk/transfer
- @smash-sdk/vat
You can install packages using npm:
npm install @smash-sdk/transfer
npm install @smash-sdk/iam
npm install @smash-sdk/link
We will use the @smash-sdk/transfer
package as an example.
Let’s walk through setting up a project that depends on @smash-sdk/transfer
service from the Smash SDK and makes a simple service call. These steps assume you have Node.js and NPM already installed.
import { Transfer } from "@smash-sdk/transfer/10-2019";
const transferSdk = new Transfer({ region: "Your Smash API region here", token: "Your Smash API key here" });
const { transfers } = await transferSdk.listTransfers();
The Smash SDK for JavaScript uses the config
object to store configuration information. The config
object is a singleton object that is shared by all Smash SDK for JavaScript packages. You can use the config
object to configure the Smash SDK for JavaScript.
It is recommended to set the token
and region
before using any Smash SDK for JavaScript package.
import { Transfer } from "@smash-sdk/transfer/10-2019";
import { config } from "@smash-sdk/core";
config.setToken("Your Smash API key here");
config.setRegion("Your Smash API region here");
const transferSdk = new Transfer();
For more information about the config
object, check the @smash-sdk/core documentation.
Each Smash API is available in multiple versions, identified by a date (in MM-YYYY
format). For example, the Transfer
API is currently available in 07-2022
, 07-2020
, and 10-2019
versions. The Smash SDK for JavaScript is version-modulated. It means that you can use the version you want by importing the corresponding module.
For example, you can import the Transfer
API in 07-2022
version by using the following import statement:
import { Transfer } from "@smash-sdk/transfer/07-2022";
and the Transfer
API in 10-2019
version by using the following import statement:
import { Transfer } from "@smash-sdk/transfer/10-2019";
Some SDK methods are only available in latest version of a package. For example, the Transfer
API in 10-2019
version doesn't have the GetTransferFilePreview()
method available in 07-2022
version.
Make sure you're using the right version according to the documentation to be able to use a particular method.
The Smash SDK for JavaScript uses async/await to handle asynchronous operations. All API calls return a promise that you can await. For example, you can use the following code to list all transfers:
import { Transfer } from "@smash-sdk/transfer/10-2019";
const transferSdk = new Transfer({ region: "Your Smash API region here", token: "Your Smash API key here" });
async function listTransfers() {
const { transfers } = await transferSdk.listTransfers();
return transfers;
}
You can also use promises to handle asynchronous operations. For example, you can use the following code to list all transfers:
import { Transfer } from "@smash-sdk/transfer/10-2019";
const transferSdk = new Transfer({ region: "Your Smash API region here", token: "Your Smash API key here" });
transferSdk.listTransfers().then(({ transfers }) => {
console.log(transfers);
}).catch((error) => {
console.log(error);
});
The Smash SDK for JavaScript provides a set of error classes that you can use to handle errors. For example, you can use the following code to handle an invalid parameter error:
import { Transfer, errors } from "@smash-sdk/transfer/10-2019";
try {
const { transfers } = await transferSdk.listTransfers();
} catch (error) {
if (error instanceof errors.ListTransfersError.InvalidParameterError) {
console.log(error);
}
}
Check the Smash SDK for JavaScript documentation for more information about the Smash SDK for JavaScript.
Contibutions are welcome! If you'd like to help improving the Smash SDK for JavaScript, please fork the repository, make your changes, and submit a pull request.
Smash SDK for JavaScript is released under the MIT License.