0.3.8 • Published 10 months ago

@commercengine/storefront-sdk v0.3.8

Weekly downloads
-
License
All rights reserv...
Repository
-
Last release
10 months ago

Storefront SDK

TypeScript SDK for the CommerceEngine Storefront API.

Installation

npm install @commercengine/storefront-sdk

Or with yarn:

yarn add @commercengine/storefront-sdk

Or with pnpm:

pnpm add @commercengine/storefront-sdk

Usage

Initializing the SDK

You can initialize the SDK in just a few lines:

import StorefrontSDK, { Environment } from "@commercengine/storefront-sdk";

// Initialize with environment and store ID
const sdk = new StorefrontSDK({
  storeId: "your-store-id",
  environment: Environment.Staging, // or Environment.Production
});

// Or with a custom base URL (if needed)
const customSdk = new StorefrontSDK({
  storeId: "your-store-id",
  baseUrl: "https://custom-api.example.com",
});

Authentication

The SDK supports various authentication methods:

// Anonymous authentication
const { access_token, refresh_token, user } =
  await sdk.auth.getAnonymousToken();

// Phone login
const { otp_token, otp_action } = await sdk.auth.loginWithPhone("9876543210");

// Email login
const { otp_token, otp_action } = await sdk.auth.loginWithEmail(
  "user@example.com"
);

// Verify OTP
const { user, access_token, refresh_token } = await sdk.auth.verifyOtp(
  "123456",
  otp_token,
  "login"
);

// Password login
const { user, access_token, refresh_token } = await sdk.auth.loginWithPassword({
  email: "user@example.com",
  password: "your-password",
});

// Registration
const { user, access_token, refresh_token } = await sdk.auth.registerWithPhone({
  phone: "9876543210",
  email: "user@example.com",
  first_name: "John",
  last_name: "Doe",
});

// Token management
sdk.setToken(access_token); // Set token for all clients
sdk.clearToken(); // Clear token from all clients

Using the API Clients

The SDK provides dedicated clients for different API sections:

// Catalog client example (product listing)
const products = await sdk.catalog.listProducts();

// Cart client example (add to cart)
const cart = await sdk.cart.addToCart("product-id", 1);

Advanced Configuration

You can configure timeout and other options:

const sdk = new StorefrontSDK({
  storeId: "your-store-id",
  environment: Environment.Production,
  timeout: 5000, // 5 second timeout
  token: "existing-token", // Initialize with an existing token
});
0.3.8

10 months ago

0.3.7

10 months ago

0.3.6

10 months ago

0.3.5

10 months ago

0.3.4

10 months ago

0.3.3

10 months ago

0.3.2

10 months ago

0.3.1

10 months ago

0.3.0

1 year ago

0.2.1

1 year ago

0.2.0

1 year ago

0.1.3

1 year ago

0.1.2

1 year ago

0.1.1

1 year ago

0.1.0

1 year ago