@crvouga/mockingbird-service-customerio 2.1.0 → 2.3.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/dist/cli.js CHANGED
@@ -3,8 +3,8 @@ import {
3
3
  runCli,
4
4
  serveCommand,
5
5
  serveTarget
6
- } from "./chunk-53O3NJZ5.js";
7
- import "./chunk-LFEHF77A.js";
6
+ } from "./chunk-E7RLJOZK.js";
7
+ import "./chunk-VG47BJN6.js";
8
8
 
9
9
  // src/cli.ts
10
10
  var code = await runCli(
package/dist/index.d.ts CHANGED
@@ -10,36 +10,6 @@ interface FetchAPI$1 {
10
10
  fetch(request: Request): Promise<Response>;
11
11
  }
12
12
 
13
- /**
14
- * The single source of time for a service.
15
- *
16
- * Every timestamp a mock writes reads from here, so a suite moves time instead of
17
- * sleeping: appointment windows, result delays and expiries become reachable in
18
- * milliseconds. A frozen clock also makes timestamps reproducible from a seed.
19
- */
20
- type ClockState = {
21
- /** Current epoch milliseconds. */
22
- now: number;
23
- /** True while time does not advance on its own. */
24
- frozen: boolean;
25
- /** Milliseconds this clock adds to its underlying source. */
26
- offsetMs: number;
27
- };
28
- type Clock = {
29
- now(): number;
30
- /** Pin the clock to an exact instant, keeping it frozen if it already was. */
31
- set(epochMs: number): void;
32
- /** Move the clock forward, or back with a negative delta. */
33
- advance(deltaMs: number): void;
34
- /** Stop time at the current instant. */
35
- freeze(): void;
36
- /** Resume from the current instant. */
37
- unfreeze(): void;
38
- /** Drop back to the underlying source, live. */
39
- reset(): void;
40
- state(): ClockState;
41
- };
42
-
43
13
  /** Bind values accepted by Mockingbird's SQLite port (matches sqlite-mem / better-sqlite3). */
44
14
  type SqliteValue$1 = null | number | bigint | string | Uint8Array | boolean;
45
15
  /** Mutation counters returned by {@link SqliteStatement.run}. */
@@ -111,6 +81,151 @@ declare class Collection<T> {
111
81
  }>;
112
82
  }
113
83
 
84
+ /**
85
+ * Sequential id source persisted in SQLite. Ids are deterministic for a given
86
+ * sequence history (`cus_` + 14 opaque chars), so reproductions stay stable.
87
+ */
88
+ declare class IdSequence {
89
+ private readonly sqlite;
90
+ private readonly namespace;
91
+ private readonly salt;
92
+ constructor(sqlite: SqliteClient$1, namespace: string, salt?: string);
93
+ next(prefix: string, length?: number): string;
94
+ }
95
+
96
+ /** A stable identifier for a point in a {@link Timeline}. */
97
+ type CheckpointId = string;
98
+ /** An immutable node in a timeline's checkpoint DAG. */
99
+ type Checkpoint<T> = Readonly<{
100
+ id: CheckpointId;
101
+ branch: string;
102
+ parent: CheckpointId | null;
103
+ /** Logical time supplied by the timeline's injected clock. */
104
+ at: number;
105
+ value: T;
106
+ }>;
107
+ type TimelineOptions = {
108
+ /** Logical clock used to stamp checkpoints. Defaults to a deterministic counter. */
109
+ now?: () => number;
110
+ /** Maximum retained checkpoints. Branch heads are never collected. Default 1,000. */
111
+ maxCheckpoints?: number;
112
+ /** Customize deterministic checkpoint IDs. */
113
+ id?: (sequence: number) => CheckpointId;
114
+ };
115
+ type CommitOptions = {
116
+ branch?: string;
117
+ /** Parent checkpoint. Defaults to the selected branch's current head. */
118
+ parent?: CheckpointId | null;
119
+ };
120
+ type ForkOptions = {
121
+ /** Checkpoint to fork from. Defaults to the main branch's head. */
122
+ from?: CheckpointId;
123
+ };
124
+ /**
125
+ * Small, storage-agnostic checkpoint DAG shared by service runtimes. Its values may be immutable
126
+ * records, namespace images, or copy-on-write SQL engine snapshots.
127
+ *
128
+ * Values are retained by reference. Engines can therefore use persistent/COW snapshots while
129
+ * simpler services can use immutable values. IDs and GC order are deterministic, and all IO
130
+ * (the logical clock) is injected.
131
+ */
132
+ declare class Timeline<T> {
133
+ readonly maxCheckpoints: number;
134
+ private readonly now;
135
+ private readonly makeId;
136
+ private readonly nodes;
137
+ private readonly heads;
138
+ /** Unreferenced nodes in the exact order they became collectible. */
139
+ private readonly evictable;
140
+ /** Branch heads plus explicit retainers. Absent means zero. */
141
+ private readonly references;
142
+ private readonly explicitPins;
143
+ private sequence;
144
+ constructor(options?: TimelineOptions);
145
+ /** Capture a new immutable value and move `branch` to it. */
146
+ commit(value: T, options?: CommitOptions): Checkpoint<T>;
147
+ /** Create a branch pointer without copying its checkpoint value. */
148
+ fork(branch: string, options?: ForkOptions): Checkpoint<T> | undefined;
149
+ /** Move a branch pointer to an existing checkpoint. */
150
+ checkout(branch: string, id: CheckpointId): Checkpoint<T>;
151
+ get(id: CheckpointId): Checkpoint<T>;
152
+ head(branch?: string): Checkpoint<T> | undefined;
153
+ hasBranch(branch: string): boolean;
154
+ branches(): Readonly<Record<string, CheckpointId>>;
155
+ checkpoints(): readonly Checkpoint<T>[];
156
+ /** Number of retained checkpoints without allocating an array. */
157
+ get size(): number;
158
+ /** Pin a checkpoint independently of branch heads (used by compatibility snapshot handles). */
159
+ retain(id: CheckpointId): Checkpoint<T>;
160
+ /** Release one explicit pin. Branch heads remain pinned until moved or deleted. */
161
+ release(id: CheckpointId): boolean;
162
+ deleteBranch(branch: string): boolean;
163
+ /**
164
+ * Deterministically discard oldest unpinned checkpoints. Collection is O(number removed):
165
+ * commits never scan pinned nodes or the retained history. Parents are metadata rather than a
166
+ * storage dependency, so a retained node remains usable after pruning.
167
+ */
168
+ gc(max?: number): CheckpointId[];
169
+ private collect;
170
+ private moveHead;
171
+ private addReference;
172
+ private removeReference;
173
+ private assertBranch;
174
+ }
175
+
176
+ /**
177
+ * Anything that can answer a Fetch `Request` with a `Response`.
178
+ *
179
+ * Every Mockingbird service implements this, and every runtime adapter consumes it.
180
+ * It is the only contract shared across the whole graph.
181
+ */
182
+ interface FetchAPI {
183
+ fetch(request: Request): Promise<Response>;
184
+ }
185
+
186
+ /** Options every provider constructor accepts. */
187
+ type APIOptions = {
188
+ /** Sync SQLite client. Defaults to `@crvouga/mockingbird-service-sqlite`. */
189
+ sqlite?: SqliteClient$1;
190
+ /** Clock used for `created`-style fields. Default `Date.now`. */
191
+ now?: () => number;
192
+ /**
193
+ * Storage namespace for this instance's records. Instances sharing one SQLite
194
+ * client stay isolated when their namespaces differ. Defaults to the service name.
195
+ */
196
+ namespace?: string;
197
+ };
198
+
199
+ /**
200
+ * The single source of time for a service.
201
+ *
202
+ * Every timestamp a mock writes reads from here, so a suite moves time instead of
203
+ * sleeping: appointment windows, result delays and expiries become reachable in
204
+ * milliseconds. A frozen clock also makes timestamps reproducible from a seed.
205
+ */
206
+ type ClockState = {
207
+ /** Current epoch milliseconds. */
208
+ now: number;
209
+ /** True while time does not advance on its own. */
210
+ frozen: boolean;
211
+ /** Milliseconds this clock adds to its underlying source. */
212
+ offsetMs: number;
213
+ };
214
+ type Clock = {
215
+ now(): number;
216
+ /** Pin the clock to an exact instant, keeping it frozen if it already was. */
217
+ set(epochMs: number): void;
218
+ /** Move the clock forward, or back with a negative delta. */
219
+ advance(deltaMs: number): void;
220
+ /** Stop time at the current instant. */
221
+ freeze(): void;
222
+ /** Resume from the current instant. */
223
+ unfreeze(): void;
224
+ /** Drop back to the underlying source, live. */
225
+ reset(): void;
226
+ state(): ClockState;
227
+ };
228
+
114
229
  /**
115
230
  * Seeded pseudo-random numbers, so anything a mock invents — ids, jitter, which
116
231
  * request a percentage fault hits — is reproducible from a seed.
@@ -251,109 +366,6 @@ type FaultRegistry = {
251
366
  take(candidate: FaultCandidate): Promise<FaultHit[]>;
252
367
  };
253
368
 
254
- /** A stable identifier for a point in a {@link Timeline}. */
255
- type CheckpointId = string;
256
- /** An immutable node in a timeline's checkpoint DAG. */
257
- type Checkpoint<T> = Readonly<{
258
- id: CheckpointId;
259
- branch: string;
260
- parent: CheckpointId | null;
261
- /** Logical time supplied by the timeline's injected clock. */
262
- at: number;
263
- value: T;
264
- }>;
265
- type TimelineOptions = {
266
- /** Logical clock used to stamp checkpoints. Defaults to a deterministic counter. */
267
- now?: () => number;
268
- /** Maximum retained checkpoints. Branch heads are never collected. Default 1,000. */
269
- maxCheckpoints?: number;
270
- /** Customize deterministic checkpoint IDs. */
271
- id?: (sequence: number) => CheckpointId;
272
- };
273
- type CommitOptions = {
274
- branch?: string;
275
- /** Parent checkpoint. Defaults to the selected branch's current head. */
276
- parent?: CheckpointId | null;
277
- };
278
- type ForkOptions = {
279
- /** Checkpoint to fork from. Defaults to the main branch's head. */
280
- from?: CheckpointId;
281
- };
282
- /**
283
- * Small, storage-agnostic checkpoint DAG shared by service runtimes. Its values may be immutable
284
- * records, namespace images, or copy-on-write SQL engine snapshots.
285
- *
286
- * Values are retained by reference. Engines can therefore use persistent/COW snapshots while
287
- * simpler services can use immutable values. IDs and GC order are deterministic, and all IO
288
- * (the logical clock) is injected.
289
- */
290
- declare class Timeline<T> {
291
- readonly maxCheckpoints: number;
292
- private readonly now;
293
- private readonly makeId;
294
- private readonly nodes;
295
- private readonly heads;
296
- /** Unreferenced nodes in the exact order they became collectible. */
297
- private readonly evictable;
298
- /** Branch heads plus explicit retainers. Absent means zero. */
299
- private readonly references;
300
- private readonly explicitPins;
301
- private sequence;
302
- constructor(options?: TimelineOptions);
303
- /** Capture a new immutable value and move `branch` to it. */
304
- commit(value: T, options?: CommitOptions): Checkpoint<T>;
305
- /** Create a branch pointer without copying its checkpoint value. */
306
- fork(branch: string, options?: ForkOptions): Checkpoint<T> | undefined;
307
- /** Move a branch pointer to an existing checkpoint. */
308
- checkout(branch: string, id: CheckpointId): Checkpoint<T>;
309
- get(id: CheckpointId): Checkpoint<T>;
310
- head(branch?: string): Checkpoint<T> | undefined;
311
- hasBranch(branch: string): boolean;
312
- branches(): Readonly<Record<string, CheckpointId>>;
313
- checkpoints(): readonly Checkpoint<T>[];
314
- /** Number of retained checkpoints without allocating an array. */
315
- get size(): number;
316
- /** Pin a checkpoint independently of branch heads (used by compatibility snapshot handles). */
317
- retain(id: CheckpointId): Checkpoint<T>;
318
- /** Release one explicit pin. Branch heads remain pinned until moved or deleted. */
319
- release(id: CheckpointId): boolean;
320
- deleteBranch(branch: string): boolean;
321
- /**
322
- * Deterministically discard oldest unpinned checkpoints. Collection is O(number removed):
323
- * commits never scan pinned nodes or the retained history. Parents are metadata rather than a
324
- * storage dependency, so a retained node remains usable after pruning.
325
- */
326
- gc(max?: number): CheckpointId[];
327
- private collect;
328
- private moveHead;
329
- private addReference;
330
- private removeReference;
331
- private assertBranch;
332
- }
333
-
334
- /**
335
- * Anything that can answer a Fetch `Request` with a `Response`.
336
- *
337
- * Every Mockingbird service implements this, and every runtime adapter consumes it.
338
- * It is the only contract shared across the whole graph.
339
- */
340
- interface FetchAPI {
341
- fetch(request: Request): Promise<Response>;
342
- }
343
-
344
- /** Options every provider constructor accepts. */
345
- type APIOptions = {
346
- /** Sync SQLite client. Defaults to `@crvouga/mockingbird-service-sqlite`. */
347
- sqlite?: SqliteClient$1;
348
- /** Clock used for `created`-style fields. Default `Date.now`. */
349
- now?: () => number;
350
- /**
351
- * Storage namespace for this instance's records. Instances sharing one SQLite
352
- * client stay isolated when their namespaces differ. Defaults to the service name.
353
- */
354
- namespace?: string;
355
- };
356
-
357
369
  /**
358
370
  * One problem with a request body, at a dotted path (`patient.address.city`, `items.0.sku`).
359
371
  * `kind` is `media_type` when the body is present but its media type is not one the operation
@@ -395,6 +407,10 @@ type RequestLog = {
395
407
  ids?: Record<string, string>;
396
408
  /** Set when the service created a resource the request referred to but that did not exist. */
397
409
  adopted?: boolean;
410
+ /** Explicit durable acceptance, independent of response delivery. */
411
+ accepted?: boolean;
412
+ /** Checkpoint captured at explicit acceptance. */
413
+ checkpoint?: string;
398
414
  /** Set on a rejection (status ≥ 400) the mock produced itself, never on a scripted fault. */
399
415
  request?: RejectedRequest;
400
416
  /** The validation issues behind a rejection, when the service found any. */
@@ -458,18 +474,6 @@ type CredentialRegistry = {
458
474
  }[];
459
475
  };
460
476
 
461
- /**
462
- * Sequential id source persisted in SQLite. Ids are deterministic for a given
463
- * sequence history (`cus_` + 14 opaque chars), so reproductions stay stable.
464
- */
465
- declare class IdSequence {
466
- private readonly sqlite;
467
- private readonly namespace;
468
- private readonly salt;
469
- constructor(sqlite: SqliteClient$1, namespace: string, salt?: string);
470
- next(prefix: string, length?: number): string;
471
- }
472
-
473
477
  /**
474
478
  * A point-in-time copy of everything a service namespace holds.
475
479
  *
@@ -814,6 +818,15 @@ type Profile = {
814
818
  preferences: SubscriptionPreferences;
815
819
  updatedAt: string;
816
820
  };
821
+ /** Sender opt-outs are independent of marketing subscription preferences. */
822
+ type SenderOptOut = {
823
+ channel: "sms" | "whatsapp";
824
+ from: string;
825
+ };
826
+ type CustomerOptOuts = {
827
+ customerId: string;
828
+ optouts: SenderOptOut[];
829
+ };
817
830
  type TrackedLink = {
818
831
  linkId: string;
819
832
  deliveryId: string;
@@ -862,6 +875,7 @@ declare class CustomerIoState {
862
875
  readonly deliveries: OutboxStore<Delivery>;
863
876
  readonly cdp: Collection<CdpEvent>;
864
877
  readonly profiles: Collection<Profile>;
878
+ readonly optouts: Collection<CustomerOptOuts>;
865
879
  readonly messages: Collection<TransactionalMessage>;
866
880
  readonly links: Collection<TrackedLink>;
867
881
  readonly settings: Collection<Settings>;
@@ -876,6 +890,7 @@ declare class CustomerIoState {
876
890
  catalog(): TransactionalMessage[];
877
891
  /** A catalog message by numeric id or (case-insensitive) trigger name. */
878
892
  message(idOrTrigger: string): TransactionalMessage | undefined;
893
+ setOptOut(customerId: string, from: string, channel: SenderOptOut["channel"], optout: boolean): CustomerOptOuts | undefined;
879
894
  profile(id: string): Profile | undefined;
880
895
  profileByEmail(email: string): Profile | undefined;
881
896
  profileByCioId(cioId: string): Profile | undefined;
@@ -1057,10 +1072,10 @@ type OpenAPIDocument = {
1057
1072
  };
1058
1073
 
1059
1074
  declare const document: OpenAPIDocument;
1060
- type OperationId = "CdpIdentify" | "CdpTrack" | "CdpBatch" | "SendEmail" | "SendSms" | "SendInboxMessage" | "ListTransactionalMessages" | "GetTransactionalMessage" | "GetCustomerAttributes" | "GetMessage" | "FollowClick" | "ReportClick";
1061
- type SupportedOperationId = "CdpIdentify" | "CdpTrack" | "CdpBatch" | "SendEmail" | "SendSms" | "SendInboxMessage" | "ListTransactionalMessages" | "GetTransactionalMessage" | "GetCustomerAttributes" | "GetMessage" | "FollowClick" | "ReportClick";
1062
- declare const operationIds: readonly ["CdpIdentify", "CdpTrack", "CdpBatch", "SendEmail", "SendSms", "SendInboxMessage", "ListTransactionalMessages", "GetTransactionalMessage", "GetCustomerAttributes", "GetMessage", "FollowClick", "ReportClick"];
1063
- declare const supportedOperationIds: readonly ["CdpIdentify", "CdpTrack", "CdpBatch", "SendEmail", "SendSms", "SendInboxMessage", "ListTransactionalMessages", "GetTransactionalMessage", "GetCustomerAttributes", "GetMessage", "FollowClick", "ReportClick"];
1075
+ type OperationId = "CdpIdentify" | "CdpTrack" | "CdpBatch" | "SendEmail" | "SendSms" | "SendInboxMessage" | "ListTransactionalMessages" | "GetTransactionalMessage" | "GetCustomerAttributes" | "ListOptOuts" | "GetCustomerOptOuts" | "GetMessage" | "FollowClick" | "ReportClick";
1076
+ type SupportedOperationId = "CdpIdentify" | "CdpTrack" | "CdpBatch" | "SendEmail" | "SendSms" | "SendInboxMessage" | "ListTransactionalMessages" | "GetTransactionalMessage" | "GetCustomerAttributes" | "ListOptOuts" | "GetCustomerOptOuts" | "GetMessage" | "FollowClick" | "ReportClick";
1077
+ declare const operationIds: readonly ["CdpIdentify", "CdpTrack", "CdpBatch", "SendEmail", "SendSms", "SendInboxMessage", "ListTransactionalMessages", "GetTransactionalMessage", "GetCustomerAttributes", "ListOptOuts", "GetCustomerOptOuts", "GetMessage", "FollowClick", "ReportClick"];
1078
+ declare const supportedOperationIds: readonly ["CdpIdentify", "CdpTrack", "CdpBatch", "SendEmail", "SendSms", "SendInboxMessage", "ListTransactionalMessages", "GetTransactionalMessage", "GetCustomerAttributes", "ListOptOuts", "GetCustomerOptOuts", "GetMessage", "FollowClick", "ReportClick"];
1064
1079
 
1065
1080
  /** Where our backend receives reporting webhooks (`customer-io.reporting.controller.ts`). */
1066
1081
  declare const REPORTING_WEBHOOK_PATH = "/v1/customer-io/reporting-webhook";
@@ -1180,6 +1195,8 @@ declare class CustomerIoAPI implements FetchAPI$1 {
1180
1195
  private send;
1181
1196
  private listMessages;
1182
1197
  private oneMessage;
1198
+ private listOptOuts;
1199
+ private customerOptOuts;
1183
1200
  private attributes;
1184
1201
  private deliveryMessage;
1185
1202
  private click;
@@ -1206,4 +1223,4 @@ declare class CustomerIoAPI implements FetchAPI$1 {
1206
1223
  }
1207
1224
 
1208
1225
  export { CUSTOMERIO_NAMESPACE, CUSTOMERIO_PRESETS, CustomerIoAPI, DEFAULT_SETTINGS, DEFAULT_TRANSACTIONAL_MESSAGES, DELIVERY_STATES, FAILURE_STATES, REPORTING_WEBHOOK_PATH, TRANSACTIONAL_EMAIL_KEYS, createRuntime, customerIoCredential, document, operationIds, signReporting, supportedOperationIds };
1209
- export type { CdpEvent, Channel, CustomerIoAPIOptions, CustomerIoRuntime, CustomerIoRuntimeOptions, Delivery, DeliveryState, FetchAPI$1 as FetchAPI, OperationId, Profile, ReportInput, ReportingEvent, Settings, SqliteClient, SubscriptionPreferences, SupportedOperationId, TrackedLink, TransactionalMessage };
1226
+ export type { CdpEvent, Channel, CustomerIoAPIOptions, CustomerIoRuntime, CustomerIoRuntimeOptions, CustomerOptOuts, Delivery, DeliveryState, FetchAPI$1 as FetchAPI, OperationId, Profile, ReportInput, ReportingEvent, SenderOptOut, Settings, SqliteClient, SubscriptionPreferences, SupportedOperationId, TrackedLink, TransactionalMessage };
package/dist/index.js CHANGED
@@ -14,7 +14,7 @@ import {
14
14
  operationIds,
15
15
  signReporting,
16
16
  supportedOperationIds
17
- } from "./chunk-LFEHF77A.js";
17
+ } from "./chunk-VG47BJN6.js";
18
18
  export {
19
19
  CUSTOMERIO_NAMESPACE,
20
20
  CUSTOMERIO_PRESETS,