Install the web SDK
Add the package
Section titled “Add the package”The package is installed from its git tag:
npm install github:MichalTDev/crm-web#v0.3.0That writes this line in your 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.
ES modules, CommonJS and types
Section titled “ES modules, CommonJS and types”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 modulesconst { Crm, CrmAuth, CrmTokens } = require("crm-sdk"); // CommonJSIt 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.
Pages rendered on the server
Section titled “Pages rendered on the server”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.
Name your site in Web origins
Section titled “Name your site in Web origins”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.examplehttps://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;
httponly forlocalhostwhile 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.
On the Install page
Section titled “On the Install page”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
Versions
Section titled “Versions”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.
Browsers
Section titled “Browsers”The package is ES2017. It needs fetch, Promise, AbortController, TextEncoder and TextDecoder, and crypto.getRandomValues, which every browser below has:
| Browser | From |
|---|---|
| Chrome, Edge | 66 |
| Firefox | 60 |
| Safari | 12.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.