advanced-commerce-sdk
v1.2.12
Published
<img src="https://advancedcommerce.io/wp-content/uploads/2024/02/AC-LOGO-2022-HORIZONTAL-NOTAG.png" alt="" width="400" />
Downloads
21
Readme
AdvancedCommerce Typescript SDK
This is the typescirpt sdk for Advanced-commerce.
Installation
Install the latest version of SDK from NPM registry.
npm i advanced-commerce-sdkUsage
The SDK can be initialised with Admin or Store Credentials individually, or with both together.
import {
AdminCredentialBuilder,
AdvacedCommerceConfigBuilder,
} from "advanced-commerce-sdk";
import { AuthenticationMode, SandboxEnvironment } from "advanced-commerce-sdk";
import { AdvancedCommerce } from "advanced-commerce-js-sdk";
const adminApiKey = "<accessKey>"; //admin API Key
const adminSecretKey = "<secretKey>"; //Admin Secret Key
const domainKey = "domainKey";
const config = AdvacedCommerceConfigBuilder.of()
.withAdminCredentials(
AdminCredentialBuilder.of()
.withAdminApiKey(adminApiKey)
.withAdminSecretKey(adminSecretKey)
.build()
)
.withDomainKey(domainKey)
.withAuthenticationModel(AuthenticationMode.BasicAuth)
.withEvironemnt(SandboxEnvironment.DEV)
.build();
/* Initalising with both admin and store credentials together
const config2 = AdvacedCommerceConfigBuilder.of()
.withAdminCredentials(
AdminCredentialBuilder.of()
.withAdminApiKey(adminApiKey)
.withAdminSecretKey(adminSecretKey)
.build()
).withStoreCredentials(StoreCredentialBuilder.of()
.withStoreApiKey("")
.withStoreSecretKey("").build()
).withDomainKey(domainKey)
.withAuthenticationModel(AuthenticationMode.BasicAuth)
.withEvironemnt(SandboxEnvironment.DEV)
.build();
*/
const advancedCommerce = new AdvancedCommerce(config);The creation of credentials and all other types follows a uniform builder pattern which along with strong type support from Typescript gives enough intuitions for developers while coding.
In order to initialise SDK we have to provide the environment(
SandboxEnvironment) in the config so that SDK would initialize the DNS for advanced-commerce accordingly.In order to initialize we have to provide the authentication mode(
AuthenticationMode) (for query APIs) to choose between basic authentication and ip whitelisting
Making first API call
In order to fetch report for a previous indexing operation, do the following
const advancedCommerce = new AdvancedCommerce(config);
const report = await advancedCommerce.operations.getReport(
"c0a855457d6d4a06a825d735cde2d8b7"
);
console.log(report.data);Uploading zip to advanced-commerce
const advancedCommerce = new AdvancedCommerceGateway(config);
const uploadResponse = await advancedCommerce.batch.upload(
"./data.zip",
UploadType.DELTA
);
console.log(uploadResponse.data);
/* console log
{
domain: 'ayatadev',
type: 'delta',
operation: 'delta upload operation executed',
receipt: '6e793b616c4d4b2b93ce40eefcf9c404',
size: 366,
filename: 'data.zip'
}
*/For more information regarding file upload refer docs from advancedcommerce.
Processing uploaded zip file
const advancedCommerce = new AdvancedCommerceGateway(config);
const processResponse = await advancedCommerce.batch.process(
uploadResponse.data.receipt,
false
);
console.log(processResponse.data);
/* console log
{
domain: 'ayatadev',
operation: 'Process execution for 6e793b616c4d4b2b93ce40eefcf9c404 requested',
receipt: '6e793b616c4d4b2b93ce40eefcf9c404'
}
*/Contribution guidelines
- Clone the repository
- Change directory to the root of repository.
npm install- Create a feature branch or bug branch
- Make changes in the code.
- Before making PR, test your changes in the
playground/index.tsfile. You can run this file by giving the commandnpm run local - commit your changes. (Please don't add changes in the plaground/index.ts file in your commit. This file is for testing the changes locally, we are not expeting any code changes in this file.)
- Push and create a PR to main branch.
