@pulseri/js 1.0.1 → 1.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -91,13 +91,17 @@ Without it, anyone who knows a user's id can send events as that user. With it,
91
91
  passes the signature along, so Pulseri can check that the call came from your app. `identify()`, `group()`, `track()`
92
92
  and `page()` all take an optional `signature`.
93
93
 
94
- On your server, compute an HMAC-SHA256 of the user id, in hex, with the identity verification secret from the Pulseri
95
- dashboard:
94
+ On your server, compute an HMAC-SHA256 in hex, with the identity verification secret from the Pulseri dashboard, of
95
+ `person:` followed by the user id, or of `group:` followed by the group id. The prefix keeps a person and a group that
96
+ share an id (user 7 and company 7) from sharing a signature; a signature of the bare id is refused.
96
97
 
97
98
  ```js
98
99
  import { createHmac } from 'node:crypto'
99
100
 
100
- const signature = createHmac('sha256', process.env.PULSERI_IDV_SECRET).update(user.id).digest('hex')
101
+ const sign = (kind, id) => createHmac('sha256', process.env.PULSERI_IDV_SECRET).update(`${kind}:${id}`).digest('hex')
102
+
103
+ const signature = sign('person', user.id) // person:<id>
104
+ const groupSignature = sign('group', company.id) // group:<id>
101
105
  ```
102
106
 
103
107
  Send the signature to the browser with the rest of your page data, then pass it along:
@@ -105,11 +109,13 @@ Send the signature to the browser with the rest of your page data, then pass it
105
109
  ```js
106
110
  Pulseri.identify(user.id, { plan: 'pro' }, { signature })
107
111
  Pulseri.track('checkout_completed', {}, { personId: user.id, signature })
112
+ Pulseri.group(company.id, { seats: 12 }, { signature: groupSignature })
108
113
  ```
109
114
 
110
- Sign the same id you send: the user id for `identify()` and for `track()`/`page()` (`personId`), the group id for
111
- `group()`. For automatic page views, pass `signature` to `init()` next to `personId`, as a string or a function (read on
112
- every page view). Keep the secret on your server: it must never appear in browser code, a bundle or a public repository.
115
+ Sign the same id you send, with the matching prefix: `person:` and the user id for `identify()` and for
116
+ `track()`/`page()` (`personId`), `group:` and the group id for `group()`. For automatic page views, pass `signature` to
117
+ `init()` next to `personId`, as a string or a function (read on every page view). Keep the secret on your server: it
118
+ must never appear in browser code, a bundle or a public repository.
113
119
 
114
120
  ## Versioning
115
121
 
package/dist/index.d.cts CHANGED
@@ -6,14 +6,14 @@ declare function init(publicKey: string, options?: {
6
6
  personId?: PersonId;
7
7
  signature?: PersonId;
8
8
  }): void;
9
- /** Create or update a person. Optional `email`, `name`, `groupId` and `signature` (identity verification). */
9
+ /** Create or update a person. Optional `email`, `name`, `groupId` and `signature` (identity verification: the HMAC of `person:<externalId>`). */
10
10
  declare function identify(externalId: string, traits?: Record<string, unknown>, options?: {
11
11
  email?: string;
12
12
  name?: string;
13
13
  groupId?: string;
14
14
  signature?: string;
15
15
  }): void;
16
- /** Create or update a group, for example a company. Optional `name` and `signature`. */
16
+ /** Create or update a group, for example a company. Optional `name` and `signature` (identity verification: the HMAC of `group:<externalId>`). */
17
17
  declare function group(externalId: string, traits?: Record<string, unknown>, options?: {
18
18
  name?: string;
19
19
  signature?: string;
package/dist/index.d.ts CHANGED
@@ -6,14 +6,14 @@ declare function init(publicKey: string, options?: {
6
6
  personId?: PersonId;
7
7
  signature?: PersonId;
8
8
  }): void;
9
- /** Create or update a person. Optional `email`, `name`, `groupId` and `signature` (identity verification). */
9
+ /** Create or update a person. Optional `email`, `name`, `groupId` and `signature` (identity verification: the HMAC of `person:<externalId>`). */
10
10
  declare function identify(externalId: string, traits?: Record<string, unknown>, options?: {
11
11
  email?: string;
12
12
  name?: string;
13
13
  groupId?: string;
14
14
  signature?: string;
15
15
  }): void;
16
- /** Create or update a group, for example a company. Optional `name` and `signature`. */
16
+ /** Create or update a group, for example a company. Optional `name` and `signature` (identity verification: the HMAC of `group:<externalId>`). */
17
17
  declare function group(externalId: string, traits?: Record<string, unknown>, options?: {
18
18
  name?: string;
19
19
  signature?: string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pulseri/js",
3
- "version": "1.0.1",
3
+ "version": "1.0.3",
4
4
  "description": "Pulseri browser SDK: identify, group, track and page for tenant websites, plus the in-app survey widget.",
5
5
  "license": "MIT",
6
6
  "homepage": "https://github.com/getpulseri/js#readme",
@@ -39,7 +39,9 @@
39
39
  "test:watch": "vitest",
40
40
  "typecheck": "tsc --noEmit",
41
41
  "release": "node scripts/release.mjs",
42
- "assemble": "node scripts/assemble.mjs"
42
+ "assemble": "node scripts/assemble.mjs",
43
+ "preversion": "npm run typecheck && npm test",
44
+ "version": "npm run release && git add releases"
43
45
  },
44
46
  "devDependencies": {
45
47
  "@types/node": "^22.10.5",