JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 48
  • Score
    100M100P100Q80058F
  • License MIT

Official CRM.COM Self-Service JavaScript SDK for consumer-facing API integration

Package Exports

  • @crmcom/self-service-sdk
  • @crmcom/self-service-sdk/account
  • @crmcom/self-service-sdk/authentication
  • @crmcom/self-service-sdk/communications
  • @crmcom/self-service-sdk/community
  • @crmcom/self-service-sdk/config
  • @crmcom/self-service-sdk/connectx
  • @crmcom/self-service-sdk/contacts
  • @crmcom/self-service-sdk/eventListener
  • @crmcom/self-service-sdk/httpBackOfficeUtil
  • @crmcom/self-service-sdk/httpUtil
  • @crmcom/self-service-sdk/jcccards
  • @crmcom/self-service-sdk/logger
  • @crmcom/self-service-sdk/mobilepass
  • @crmcom/self-service-sdk/orders
  • @crmcom/self-service-sdk/organisations
  • @crmcom/self-service-sdk/payment
  • @crmcom/self-service-sdk/paymentgateway
  • @crmcom/self-service-sdk/payouts
  • @crmcom/self-service-sdk/resultUtil
  • @crmcom/self-service-sdk/rewards
  • @crmcom/self-service-sdk/servicerequest
  • @crmcom/self-service-sdk/subscriptions
  • @crmcom/self-service-sdk/wallet

Readme

@crmcom/self-service-sdk

Official CRM.COM Self-Service JavaScript SDK for consumer-facing API integration.

Installation

npm install @crmcom/self-service-sdk

Peer Dependencies

npm install jwt-decode js-sha256 xml2js

Quick Start

1. Initialize the SDK

You must call init() before using any other SDK method. This configures the HTTP layer with your API credentials and session management callbacks.

import { init } from '@crmcom/self-service-sdk';

await init({
  apiKey: 'YOUR_API_KEY',
  host: 'https://api.crm.com',
  storeKVFn: (key, value) => localStorage.setItem(key, value),
  getKVFn: (key) => localStorage.getItem(key),
  sessionInvalidCallback: (shouldLogout) => {
    if (shouldLogout) {
      // redirect to login
    }
  },
});

2. Use SDK modules

Once initialized, import and use any module:

import { authentication, contacts, orders, wallet } from '@crmcom/self-service-sdk';

// Authenticate
const authResult = await authentication.authenticateEmail({
  username: 'user@example.com',
  password: 'password',
});

// Get contact profile
const profile = await contacts.getContact();

// Browse products
const products = await orders.getProducts({ page: 1, size: 20 });

// Check wallet balance
const myWallet = await wallet.getWallet();

React Example

// App.jsx
import { useEffect, useState } from 'react';
import { init } from '@crmcom/self-service-sdk';

function App() {
  const [ready, setReady] = useState(false);

  useEffect(() => {
    init({
      apiKey: process.env.REACT_APP_CRM_API_KEY,
      host: process.env.REACT_APP_CRM_HOST,
      storeKVFn: (key, value) => localStorage.setItem(key, JSON.stringify(value)),
      getKVFn: (key) => JSON.parse(localStorage.getItem(key)),
      sessionInvalidCallback: () => {
        window.location.href = '/login';
      },
    }).then(() => setReady(true));
  }, []);

  if (!ready) return <div>Loading...</div>;

  return <YourApp />;
}

Init Options

Parameter Type Required Description
apiKey string Yes Your CRM.COM API key
host string Yes Base API URL (e.g. https://api.crm.com)
storeKVFn (key, value) => void | Promise<void> Yes Function to persist key-value pairs (tokens, session data)
getKVFn (key) => any | Promise<any> Yes Function to retrieve persisted values
sessionInvalidCallback (shouldLogout) => void Yes Called when session is invalid and refresh fails
fetchFn typeof fetch No Custom fetch implementation (defaults to global fetch)
enableSslPinning boolean No Enable SSL pinning (mobile apps)
sslPinningOptions Record<string, any> No SSL pinning configuration
isBackend boolean No Set true for backend/server usage
middlewareHost string No Middleware service host URL
middlewareApiKey string No Middleware API key
mwNodejsHost string No Node.js middleware host URL
mwNodejsApiKey string No Node.js middleware API key

Available Modules

Module Description
authentication Phone, email, Facebook, SSO/OIDC auth flows
contacts Contact profile, addresses, preferences
orders Catalogue, products, order estimation and placement
wallet Balance, transactions, top-ups, transfers
payment Payment methods, forms, top-ups
subscriptions Services, devices, billing
rewards Offers, promotions, schemes
account Journals, balances, rewards
communications Messages, notifications
community Members, relations, groups
config App config, languages, address lookup
organisations Organisation search, locations
servicerequest Support tickets
connectx SIM management
jcccards Card operations
mobilepass Mobile wallet passes
paymentgateway Payment gateway client tokens
payouts Payout creation

Error Handling

All SDK methods return an SDKResult object:

const result = await contacts.getContact();

if (result.code === 'OK') {
  console.log(result.data);
} else {
  console.error('Error:', result.code, result.error);
}

If the SDK is used before calling init(), it throws:

Error: CRM.COM SDK not initialized. Call init() before using any SDK methods.

Migration from v2

If you were using setupChannel, it still works but is deprecated:

- import { httpUtil } from '@crmcom/self-service-sdk';
- await httpUtil.setupChannel({ apiKey, host, ... });

+ import { init } from '@crmcom/self-service-sdk';
+ await init({ apiKey, host, ... });

License

MIT