@pulseri/js 1.0.2 → 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 +12 -6
- package/dist/index.d.cts +2 -2
- package/dist/index.d.ts +2 -2
- package/package.json +1 -1
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
|
|
95
|
-
|
|
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
|
|
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
|
|
111
|
-
`group()`. For automatic page views, pass `signature` to
|
|
112
|
-
every page view). Keep the secret on your server: it
|
|
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.
|
|
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",
|