Skip to content

Install the web SDK

The package is installed from its git tag:

Terminal window
npm install github:MichalTDev/crm-web#v0.3.0

That writes this line in your package.json:

package.json
{
"dependencies": {
"crm-sdk": "github:MichalTDev/crm-web#v0.3.0"
}
}

The package is called crm-sdk, whatever the repository is called, so you import it as crm-sdk. It has no runtime dependencies. npm builds it as it installs (its prepare script compiles the TypeScript), so the first install takes a few seconds longer than a published package’s.

The repository is at https://github.com/MichalTDev/crm-web.

The package carries both builds, each with its .d.ts types, and your bundler or Node picks the right one:

import { Crm, CrmAuth, CrmTokens } from "crm-sdk"; // ES modules
const { Crm, CrmAuth, CrmTokens } = require("crm-sdk"); // CommonJS

It has two entry points: crm-sdk, everything on these pages, and crm-sdk/debug, the setup check. The SDK loads crm-sdk/debug itself, with a dynamic import(), only when debug is on, so your bundler puts it in a chunk of its own that a page with debug off never loads. TypeScript finds crm-sdk/debug’s types with moduleResolution set to bundler, node16 or nodenext.

Importing the package touches neither window nor document, and neither does making a Crm. A page rendered on the server (Next.js, Nuxt, SvelteKit, Remix) may import it and make the facade in a module both sides share. Everything that needs the browser starts in crm.start(), which you call in the browser only: see Initialise.

A browser only lets a page read an answer from another site when that site says it may. PurrCRM says so for the sites you name, and for no others. On Settings › your app › Developers › Install, in the Web origins card, write each site that runs the SDK in Sites, one a line. Then save with the bar at the bottom of the page:

https://www.northwind.example
https://app.northwind.example
  • Write the scheme and the host (and a port only if it is not the usual one), with no path.
  • Use https; http only for localhost while you develop.
  • A live app and its test app keep a list each: switch Live | Test to edit the test app’s, and name your staging site there.
  • An app can have up to 20.

From a website or web app says more about the list.

The SDK sends X-CRM-App-Key, Authorization (or X-CRM-User-Id for unverified sign-in), X-Crm-Sdk, X-Crm-Sdk-Kind, X-App-Version, Idempotency-Key, Content-Type and Accept-Language. It sets no cookies and sends none.

Settings › your app › Developers › Install also has the App key card, with your app’s key (app_…, and in Test the Test app key, app_test_…). It also has What your app sees, the app’s public face as the SDK reads it. The steps in the Install card are for the Flutter SDK. For the web, copy the key from the App key card and follow these pages.

The version is the tag at the end of the dependency (#v0.3.0). The package’s CHANGELOG.md lists the releases, and each one says the oldest PurrCRM it needs. To move to a newer release, change the tag and run npm install again.

Every request says which SDK sent it and which version (X-Crm-Sdk-Kind: web, X-Crm-Sdk); crmSdkVersion and crmSdkKind say the same in your code. Your team can set the oldest version they want people on (Settings › your app › General › Money › Advanced › Oldest SDK), which your app reads as crm.publicApp.value?.minSdkVersion. PurrCRM refuses no version for it.

The package is ES2017. It needs fetch, Promise, AbortController, TextEncoder and TextDecoder, and crypto.getRandomValues, which every browser below has:

BrowserFrom
Chrome, Edge66
Firefox60
Safari12.1 (iOS 12.2)

Two things need a secure context (a page on https, or on localhost): web pushes, and the digest of your declared places, made with WebCrypto’s SHA-256 (Links). On a plain-http page everything else works, those two do not, and the setup check says so.

Text limits count Unicode code points, as PurrCRM does, so an emoji counts as one.

Initialise the SDK.