@yougrowai/node 0.4.0 → 0.5.0
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 +27 -0
- package/dist/cjs/index.d.ts +35 -0
- package/dist/cjs/index.js +2 -2
- package/dist/index.d.ts +35 -0
- package/dist/index.js +2 -2
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -145,6 +145,27 @@ record an event twice. A key that was already recorded resolves
|
|
|
145
145
|
- Up to 50 steps, 50 facts and 50 traits per user. Step ids are lower-case
|
|
146
146
|
letters, digits, `_` and `-`; trait keys start with a letter.
|
|
147
147
|
|
|
148
|
+
### Several workspaces, brands or projects
|
|
149
|
+
|
|
150
|
+
When a person can have several of something, send them as `entities`, by your
|
|
151
|
+
own id. Each has a `kind` (your word for it; required the first time), a
|
|
152
|
+
`name`, the `parentId` it sits inside, the person's `role` (`owner`, `member` or
|
|
153
|
+
`invited`), and its own `steps` and `facts`. Each merges like the user, and
|
|
154
|
+
`null` removes one:
|
|
155
|
+
|
|
156
|
+
```ts
|
|
157
|
+
await yg.users.update(user.id, {
|
|
158
|
+
entities: {
|
|
159
|
+
brand_123: { kind: "brand", name: "Acme", role: "owner", steps: { run_audit: audit.finishedAt } },
|
|
160
|
+
brand_456: null, // deleted in your product
|
|
161
|
+
},
|
|
162
|
+
});
|
|
163
|
+
await yg.events.track(user.id, "audit.completed", { entityId: "brand_123" });
|
|
164
|
+
```
|
|
165
|
+
|
|
166
|
+
Journeys choose which of them each email is about, so send them all rather than
|
|
167
|
+
picking one. Up to 50 per user.
|
|
168
|
+
|
|
148
169
|
A user YouGrow hasn't seen is created by their first update.
|
|
149
170
|
`users.get(userId)` returns the state as YouGrow holds it, plus what YouGrow
|
|
150
171
|
decided: journey `enrolments`, and `optOuts` (unsubscribes made in YouGrow's
|
|
@@ -343,6 +364,12 @@ at https://yougrow.ai/developers.
|
|
|
343
364
|
`test/vectors.json` (included in this package) holds reference tokens for
|
|
344
365
|
checking your own verifier.
|
|
345
366
|
|
|
367
|
+
## Upgrading from 0.4
|
|
368
|
+
|
|
369
|
+
- New: `entities` in `users.update` and on the state it returns, `entityId` on
|
|
370
|
+
`events.track`, and `entityId` on enrolments from `users.get`. Nothing
|
|
371
|
+
existing changed.
|
|
372
|
+
|
|
346
373
|
## Upgrading from 0.3
|
|
347
374
|
|
|
348
375
|
- A network failure or timeout that outlasts the retries now rejects with a
|
package/dist/cjs/index.d.ts
CHANGED
|
@@ -12,6 +12,34 @@
|
|
|
12
12
|
* status throws a YouGrowError straight away.
|
|
13
13
|
*/
|
|
14
14
|
export type ConsentBasis = "consent" | "soft_opt_in" | "corporate_subscriber" | "none";
|
|
15
|
+
/** How a person relates to one of their entities. Only what they own counts toward their onboarding. */
|
|
16
|
+
export type EntityRole = "owner" | "member" | "invited";
|
|
17
|
+
/**
|
|
18
|
+
* One of the things a person has several of — a workspace, a brand, a project —
|
|
19
|
+
* in a write. It merges like the user; `kind` is required the first time.
|
|
20
|
+
*/
|
|
21
|
+
export interface EntityPatch {
|
|
22
|
+
/** What it is, in your product's words: "brand", "workspace", "project". */
|
|
23
|
+
kind?: string;
|
|
24
|
+
name?: string | null;
|
|
25
|
+
/** The entity it sits inside, e.g. a brand's workspace. */
|
|
26
|
+
parentId?: string | null;
|
|
27
|
+
role?: EntityRole | null;
|
|
28
|
+
steps?: Record<string, string | null>;
|
|
29
|
+
facts?: Record<string, number | string | boolean | null>;
|
|
30
|
+
/** When the person last worked on it. */
|
|
31
|
+
activeAt?: string | null;
|
|
32
|
+
}
|
|
33
|
+
/** One entity as YouGrow holds it. */
|
|
34
|
+
export interface EntityState {
|
|
35
|
+
kind: string;
|
|
36
|
+
name: string | null;
|
|
37
|
+
parentId: string | null;
|
|
38
|
+
role: EntityRole | null;
|
|
39
|
+
steps: Record<string, string>;
|
|
40
|
+
facts: Record<string, string | number | boolean>;
|
|
41
|
+
activeAt: string | null;
|
|
42
|
+
}
|
|
15
43
|
/**
|
|
16
44
|
* Any subset of a user's state, as a JSON Merge Patch (RFC 7396): fields sent
|
|
17
45
|
* replace YouGrow's, fields left out stay, `null` clears, and `steps`, `facts`
|
|
@@ -42,6 +70,8 @@ export interface UserPatch {
|
|
|
42
70
|
facts?: Record<string, number | string | boolean | null>;
|
|
43
71
|
/** Anything else journeys branch on (null removes a key). */
|
|
44
72
|
traits?: Record<string, string | number | boolean | null>;
|
|
73
|
+
/** The things this person has several of (workspaces, brands…), by your id; null removes one. */
|
|
74
|
+
entities?: Record<string, EntityPatch | null>;
|
|
45
75
|
/** When you read this state. A write older than the stored one is ignored. */
|
|
46
76
|
updatedAt?: string;
|
|
47
77
|
}
|
|
@@ -62,15 +92,18 @@ export interface UserState {
|
|
|
62
92
|
steps: Record<string, string>;
|
|
63
93
|
facts: Record<string, string | number | boolean>;
|
|
64
94
|
traits: Record<string, string | number | boolean>;
|
|
95
|
+
entities: Record<string, EntityState>;
|
|
65
96
|
updatedAt: string | null;
|
|
66
97
|
}
|
|
67
98
|
/** `users.get` adds what YouGrow decided: journeys and opt-outs. */
|
|
68
99
|
export interface UserView extends UserState {
|
|
100
|
+
/** `entityId`: the entity an enrolment is about, when its journey is about one of them. */
|
|
69
101
|
enrolments: Array<{
|
|
70
102
|
journeyId: string;
|
|
71
103
|
status: string;
|
|
72
104
|
mode: string;
|
|
73
105
|
enrolledAt: string;
|
|
106
|
+
entityId?: string | null;
|
|
74
107
|
}>;
|
|
75
108
|
/** Unsubscribes made in YouGrow's emails. They hold until the person lifts them; the API can't. */
|
|
76
109
|
optOuts: Array<{
|
|
@@ -165,6 +198,8 @@ export interface TrackOptions {
|
|
|
165
198
|
occurredAt?: string;
|
|
166
199
|
/** The same key is recorded once. Defaults to a random key per call, so the SDK's own retries never count twice. */
|
|
167
200
|
idempotencyKey?: string;
|
|
201
|
+
/** The entity it happened to (one of the user's `entities`), e.g. the brand an audit ran on. */
|
|
202
|
+
entityId?: string;
|
|
168
203
|
}
|
|
169
204
|
export interface UsersApi {
|
|
170
205
|
/** Merge a patch into one user's state; creates the user if YouGrow hasn't seen them. */
|
package/dist/cjs/index.js
CHANGED
|
@@ -93,9 +93,9 @@ class YouGrow {
|
|
|
93
93
|
this.events = {
|
|
94
94
|
track: async (userId, event, options = {}) => {
|
|
95
95
|
const path = `${userPath(userId)}/events`;
|
|
96
|
-
const { properties, occurredAt } = options;
|
|
96
|
+
const { properties, occurredAt, entityId } = options;
|
|
97
97
|
// One key for every attempt, so a retry is never recorded twice.
|
|
98
|
-
const body = { event, properties, occurredAt, idempotencyKey: options.idempotencyKey ?? (0, node_crypto_1.randomUUID)() };
|
|
98
|
+
const body = { event, properties, occurredAt, entityId, idempotencyKey: options.idempotencyKey ?? (0, node_crypto_1.randomUUID)() };
|
|
99
99
|
return (await this.#send("POST", path, JSON.stringify(body)));
|
|
100
100
|
},
|
|
101
101
|
};
|
package/dist/index.d.ts
CHANGED
|
@@ -12,6 +12,34 @@
|
|
|
12
12
|
* status throws a YouGrowError straight away.
|
|
13
13
|
*/
|
|
14
14
|
export type ConsentBasis = "consent" | "soft_opt_in" | "corporate_subscriber" | "none";
|
|
15
|
+
/** How a person relates to one of their entities. Only what they own counts toward their onboarding. */
|
|
16
|
+
export type EntityRole = "owner" | "member" | "invited";
|
|
17
|
+
/**
|
|
18
|
+
* One of the things a person has several of — a workspace, a brand, a project —
|
|
19
|
+
* in a write. It merges like the user; `kind` is required the first time.
|
|
20
|
+
*/
|
|
21
|
+
export interface EntityPatch {
|
|
22
|
+
/** What it is, in your product's words: "brand", "workspace", "project". */
|
|
23
|
+
kind?: string;
|
|
24
|
+
name?: string | null;
|
|
25
|
+
/** The entity it sits inside, e.g. a brand's workspace. */
|
|
26
|
+
parentId?: string | null;
|
|
27
|
+
role?: EntityRole | null;
|
|
28
|
+
steps?: Record<string, string | null>;
|
|
29
|
+
facts?: Record<string, number | string | boolean | null>;
|
|
30
|
+
/** When the person last worked on it. */
|
|
31
|
+
activeAt?: string | null;
|
|
32
|
+
}
|
|
33
|
+
/** One entity as YouGrow holds it. */
|
|
34
|
+
export interface EntityState {
|
|
35
|
+
kind: string;
|
|
36
|
+
name: string | null;
|
|
37
|
+
parentId: string | null;
|
|
38
|
+
role: EntityRole | null;
|
|
39
|
+
steps: Record<string, string>;
|
|
40
|
+
facts: Record<string, string | number | boolean>;
|
|
41
|
+
activeAt: string | null;
|
|
42
|
+
}
|
|
15
43
|
/**
|
|
16
44
|
* Any subset of a user's state, as a JSON Merge Patch (RFC 7396): fields sent
|
|
17
45
|
* replace YouGrow's, fields left out stay, `null` clears, and `steps`, `facts`
|
|
@@ -42,6 +70,8 @@ export interface UserPatch {
|
|
|
42
70
|
facts?: Record<string, number | string | boolean | null>;
|
|
43
71
|
/** Anything else journeys branch on (null removes a key). */
|
|
44
72
|
traits?: Record<string, string | number | boolean | null>;
|
|
73
|
+
/** The things this person has several of (workspaces, brands…), by your id; null removes one. */
|
|
74
|
+
entities?: Record<string, EntityPatch | null>;
|
|
45
75
|
/** When you read this state. A write older than the stored one is ignored. */
|
|
46
76
|
updatedAt?: string;
|
|
47
77
|
}
|
|
@@ -62,15 +92,18 @@ export interface UserState {
|
|
|
62
92
|
steps: Record<string, string>;
|
|
63
93
|
facts: Record<string, string | number | boolean>;
|
|
64
94
|
traits: Record<string, string | number | boolean>;
|
|
95
|
+
entities: Record<string, EntityState>;
|
|
65
96
|
updatedAt: string | null;
|
|
66
97
|
}
|
|
67
98
|
/** `users.get` adds what YouGrow decided: journeys and opt-outs. */
|
|
68
99
|
export interface UserView extends UserState {
|
|
100
|
+
/** `entityId`: the entity an enrolment is about, when its journey is about one of them. */
|
|
69
101
|
enrolments: Array<{
|
|
70
102
|
journeyId: string;
|
|
71
103
|
status: string;
|
|
72
104
|
mode: string;
|
|
73
105
|
enrolledAt: string;
|
|
106
|
+
entityId?: string | null;
|
|
74
107
|
}>;
|
|
75
108
|
/** Unsubscribes made in YouGrow's emails. They hold until the person lifts them; the API can't. */
|
|
76
109
|
optOuts: Array<{
|
|
@@ -165,6 +198,8 @@ export interface TrackOptions {
|
|
|
165
198
|
occurredAt?: string;
|
|
166
199
|
/** The same key is recorded once. Defaults to a random key per call, so the SDK's own retries never count twice. */
|
|
167
200
|
idempotencyKey?: string;
|
|
201
|
+
/** The entity it happened to (one of the user's `entities`), e.g. the brand an audit ran on. */
|
|
202
|
+
entityId?: string;
|
|
168
203
|
}
|
|
169
204
|
export interface UsersApi {
|
|
170
205
|
/** Merge a patch into one user's state; creates the user if YouGrow hasn't seen them. */
|
package/dist/index.js
CHANGED
|
@@ -88,9 +88,9 @@ export class YouGrow {
|
|
|
88
88
|
this.events = {
|
|
89
89
|
track: async (userId, event, options = {}) => {
|
|
90
90
|
const path = `${userPath(userId)}/events`;
|
|
91
|
-
const { properties, occurredAt } = options;
|
|
91
|
+
const { properties, occurredAt, entityId } = options;
|
|
92
92
|
// One key for every attempt, so a retry is never recorded twice.
|
|
93
|
-
const body = { event, properties, occurredAt, idempotencyKey: options.idempotencyKey ?? randomUUID() };
|
|
93
|
+
const body = { event, properties, occurredAt, entityId, idempotencyKey: options.idempotencyKey ?? randomUUID() };
|
|
94
94
|
return (await this.#send("POST", path, JSON.stringify(body)));
|
|
95
95
|
},
|
|
96
96
|
};
|
package/package.json
CHANGED