@clipboard-health/notifications 0.8.0 → 0.8.2

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
@@ -38,27 +38,31 @@ npm install @clipboard-health/notifications
38
38
  <embedex source="packages/notifications/examples/enqueueNotificationJob.ts">
39
39
 
40
40
  ```ts
41
- import { IdempotencyKey } from "@clipboard-health/notifications";
42
-
43
- import { ExampleNotificationJob } from "./exampleNotification.job";
41
+ import {
42
+ type ExampleNotificationEnqueueData,
43
+ ExampleNotificationJob,
44
+ } from "./exampleNotification.job";
44
45
  import { notificationJobEnqueuer } from "./notificationJobEnqueuer";
45
46
 
46
47
  async function enqueueNotificationJob() {
47
- await notificationJobEnqueuer.enqueueOneOrMore(ExampleNotificationJob, {
48
- // Set expiresAt at enqueue-time so it remains stable across job retries.
49
- expiresAt: minutesFromNow(60),
50
- // Set idempotencyKey at enqueue-time so it remains stable across job retries.
51
- idempotencyKey: new IdempotencyKey({
52
- resourceId: "event-123",
53
- }),
54
- // Set recipients at enqueue-time so they respect our notification provider's limits.
55
- recipients: ["user-1"],
56
-
57
- workflowKey: "event-starting-reminder",
58
-
59
- // Any additional enqueue-time data passed to the job:
60
- workplaceId: "workplace-123",
61
- });
48
+ await notificationJobEnqueuer.enqueueOneOrMore<ExampleNotificationEnqueueData>(
49
+ ExampleNotificationJob,
50
+ {
51
+ // Set expiresAt at enqueue-time so it remains stable across job retries.
52
+ expiresAt: minutesFromNow(60).toISOString(),
53
+ // Set idempotencyKey at enqueue-time so it remains stable across job retries.
54
+ idempotencyKey: {
55
+ resourceId: "event-123",
56
+ },
57
+ // Set recipients at enqueue-time so they respect our notification provider's limits.
58
+ recipients: ["user-1"],
59
+
60
+ workflowKey: "event-starting-reminder",
61
+
62
+ // Any additional enqueue-time data passed to the job:
63
+ workplaceId: "workplace-123",
64
+ },
65
+ );
62
66
  }
63
67
 
64
68
  // eslint-disable-next-line unicorn/prefer-top-level-await
@@ -78,12 +82,10 @@ npm install @clipboard-health/notifications
78
82
  ```ts
79
83
  import { type BaseHandler } from "@clipboard-health/background-jobs-adapter";
80
84
  import {
81
- errorsInResult,
82
85
  type NotificationEnqueueData,
83
86
  type NotificationJobData,
84
- RETRYABLE_ERRORS,
85
87
  } from "@clipboard-health/notifications";
86
- import { toError } from "@clipboard-health/util-ts";
88
+ import { isFailure, toError } from "@clipboard-health/util-ts";
87
89
 
88
90
  import { type ExampleNotificationService } from "./exampleNotification.service";
89
91
 
@@ -104,7 +106,7 @@ npm install @clipboard-health/notifications
104
106
  attempt: job.attemptsCount + 1,
105
107
  });
106
108
 
107
- if (errorsInResult(result, RETRYABLE_ERRORS)) {
109
+ if (isFailure(result)) {
108
110
  throw toError(result.error);
109
111
  }
110
112
  }
@@ -140,7 +142,7 @@ npm install @clipboard-health/notifications
140
142
  data,
141
143
  workplaceId,
142
144
  },
143
- expiresAt,
145
+ expiresAt: new Date(expiresAt),
144
146
  idempotencyKey,
145
147
  key: workflowKey,
146
148
  keysToRedact: ["secret"],
package/package.json CHANGED
@@ -1,17 +1,18 @@
1
1
  {
2
2
  "name": "@clipboard-health/notifications",
3
3
  "description": "Send notifications through third-party providers.",
4
- "version": "0.8.0",
4
+ "version": "0.8.2",
5
5
  "bugs": "https://github.com/ClipboardHealth/core-utils/issues",
6
6
  "dependencies": {
7
- "@clipboard-health/background-jobs-adapter": "0.3.0",
8
- "@clipboard-health/phone-number": "0.7.0",
9
- "@clipboard-health/util-ts": "3.16.0",
10
- "@knocklabs/node": "1.16.0",
7
+ "@clipboard-health/background-jobs-adapter": "0.3.1",
8
+ "@clipboard-health/phone-number": "0.7.1",
9
+ "@clipboard-health/util-ts": "3.16.1",
10
+ "@knocklabs/node": "1.20.0",
11
11
  "tslib": "2.8.1"
12
12
  },
13
13
  "devDependencies": {
14
- "@clipboard-health/testing-core": "0.25.0"
14
+ "@clipboard-health/testing-core": "0.25.1",
15
+ "type-fest": "5.0.1"
15
16
  },
16
17
  "keywords": [],
17
18
  "license": "MIT",
package/src/index.d.ts CHANGED
@@ -1,5 +1,4 @@
1
1
  export * from "./lib/errorsInResult";
2
- export * from "./lib/idempotencyKey";
3
2
  export * from "./lib/notificationClient";
4
3
  export * from "./lib/notificationJobEnqueuer";
5
4
  export * from "./lib/triggerIdempotencyKey";
package/src/index.js CHANGED
@@ -2,7 +2,6 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const tslib_1 = require("tslib");
4
4
  tslib_1.__exportStar(require("./lib/errorsInResult"), exports);
5
- tslib_1.__exportStar(require("./lib/idempotencyKey"), exports);
6
5
  tslib_1.__exportStar(require("./lib/notificationClient"), exports);
7
6
  tslib_1.__exportStar(require("./lib/notificationJobEnqueuer"), exports);
8
7
  tslib_1.__exportStar(require("./lib/triggerIdempotencyKey"), exports);
package/src/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../packages/notifications/src/index.ts"],"names":[],"mappings":";;;AAAA,+DAAqC;AACrC,+DAAqC;AACrC,mEAAyC;AACzC,wEAA8C;AAC9C,sEAA4C;AAC5C,sDAA4B"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../packages/notifications/src/index.ts"],"names":[],"mappings":";;;AAAA,+DAAqC;AACrC,mEAAyC;AACzC,wEAA8C;AAC9C,sEAA4C;AAC5C,sDAA4B"}
@@ -0,0 +1,5 @@
1
+ import { type TriggerIdempotencyKey } from "../triggerIdempotencyKey";
2
+ export declare function parseTriggerIdempotencyKey(params: {
3
+ idempotencyKey: TriggerIdempotencyKey | string;
4
+ workplaceId?: string | undefined;
5
+ }): string;
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.parseTriggerIdempotencyKey = parseTriggerIdempotencyKey;
4
+ const triggerIdempotencyKey_1 = require("../triggerIdempotencyKey");
5
+ const triggerIdempotencyKeyParamsToHash_1 = require("./triggerIdempotencyKeyParamsToHash");
6
+ function parseTriggerIdempotencyKey(params) {
7
+ const { idempotencyKey, workplaceId } = params;
8
+ try {
9
+ const parsed = JSON.parse(idempotencyKey);
10
+ if ((0, triggerIdempotencyKey_1.isTriggerIdempotencyKeyParams)(parsed)) {
11
+ return (0, triggerIdempotencyKeyParamsToHash_1.triggerIdempotencyKeyParamsToHash)({ ...parsed, workplaceId });
12
+ }
13
+ }
14
+ catch {
15
+ // Not a branded key; fall through
16
+ }
17
+ return idempotencyKey;
18
+ }
19
+ //# sourceMappingURL=parseTriggerIdempotencyKey.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"parseTriggerIdempotencyKey.js","sourceRoot":"","sources":["../../../../../../packages/notifications/src/lib/internal/parseTriggerIdempotencyKey.ts"],"names":[],"mappings":";;AAOA,gEAgBC;AAvBD,oEAIkC;AAClC,2FAAwF;AAExF,SAAgB,0BAA0B,CAAC,MAG1C;IACC,MAAM,EAAE,cAAc,EAAE,WAAW,EAAE,GAAG,MAAM,CAAC;IAE/C,IAAI,CAAC;QACH,MAAM,MAAM,GAAG,IAAI,CAAC,KAAK,CAAC,cAAc,CAAyC,CAAC;QAClF,IAAI,IAAA,qDAA6B,EAAC,MAAM,CAAC,EAAE,CAAC;YAC1C,OAAO,IAAA,qEAAiC,EAAC,EAAE,GAAG,MAAM,EAAE,WAAW,EAAE,CAAC,CAAC;QACvE,CAAC;IACH,CAAC;IAAC,MAAM,CAAC;QACP,kCAAkC;IACpC,CAAC;IAED,OAAO,cAAc,CAAC;AACxB,CAAC"}
@@ -0,0 +1,6 @@
1
+ import { type TriggerIdempotencyKeyParams } from "../triggerIdempotencyKey";
2
+ interface HashParams extends TriggerIdempotencyKeyParams {
3
+ workplaceId?: string | undefined;
4
+ }
5
+ export declare function triggerIdempotencyKeyParamsToHash(params: HashParams): string;
6
+ export {};
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.triggerIdempotencyKeyParamsToHash = triggerIdempotencyKeyParamsToHash;
4
+ const createDeterministicHash_1 = require("./createDeterministicHash");
5
+ function triggerIdempotencyKeyParamsToHash(params) {
6
+ return (0, createDeterministicHash_1.createDeterministicHash)(toSorted(params));
7
+ }
8
+ function toSorted(params) {
9
+ return {
10
+ chunk: params.chunk,
11
+ eventOccurredAt: params.eventOccurredAt,
12
+ recipients: [...params.recipients].sort(),
13
+ resourceId: params.resourceId,
14
+ workflowKey: params.workflowKey,
15
+ workplaceId: params.workplaceId,
16
+ };
17
+ }
18
+ //# sourceMappingURL=triggerIdempotencyKeyParamsToHash.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"triggerIdempotencyKeyParamsToHash.js","sourceRoot":"","sources":["../../../../../../packages/notifications/src/lib/internal/triggerIdempotencyKeyParamsToHash.ts"],"names":[],"mappings":";;AAOA,8EAEC;AARD,uEAAoE;AAMpE,SAAgB,iCAAiC,CAAC,MAAkB;IAClE,OAAO,IAAA,iDAAuB,EAAC,QAAQ,CAAC,MAAM,CAAC,CAAC,CAAC;AACnD,CAAC;AAED,SAAS,QAAQ,CAAC,MAAkB;IAClC,OAAO;QACL,KAAK,EAAE,MAAM,CAAC,KAAK;QACnB,eAAe,EAAE,MAAM,CAAC,eAAe;QACvC,UAAU,EAAE,CAAC,GAAG,MAAM,CAAC,UAAU,CAAC,CAAC,IAAI,EAAE;QACzC,UAAU,EAAE,MAAM,CAAC,UAAU;QAC7B,WAAW,EAAE,MAAM,CAAC,WAAW;QAC/B,WAAW,EAAE,MAAM,CAAC,WAAW;KAChC,CAAC;AACJ,CAAC"}
@@ -64,7 +64,7 @@ export declare class NotificationClient {
64
64
  * data,
65
65
  * workplaceId,
66
66
  * },
67
- * expiresAt,
67
+ * expiresAt: new Date(expiresAt),
68
68
  * idempotencyKey,
69
69
  * key: workflowKey,
70
70
  * keysToRedact: ["secret"],
@@ -6,10 +6,10 @@ const node_1 = require("@knocklabs/node");
6
6
  const createTriggerLogParams_1 = require("./internal/createTriggerLogParams");
7
7
  const createTriggerTraceOptions_1 = require("./internal/createTriggerTraceOptions");
8
8
  const idempotentKnock_1 = require("./internal/idempotentKnock");
9
+ const parseTriggerIdempotencyKey_1 = require("./internal/parseTriggerIdempotencyKey");
9
10
  const redact_1 = require("./internal/redact");
10
11
  const toTenantSetRequest_1 = require("./internal/toTenantSetRequest");
11
12
  const toTriggerBody_1 = require("./internal/toTriggerBody");
12
- const triggerIdempotencyKey_1 = require("./triggerIdempotencyKey");
13
13
  const LOG_PARAMS = {
14
14
  trigger: {
15
15
  traceName: "notifications.trigger",
@@ -98,7 +98,7 @@ class NotificationClient {
98
98
  * data,
99
99
  * workplaceId,
100
100
  * },
101
- * expiresAt,
101
+ * expiresAt: new Date(expiresAt),
102
102
  * idempotencyKey,
103
103
  * key: workflowKey,
104
104
  * keysToRedact: ["secret"],
@@ -119,13 +119,10 @@ class NotificationClient {
119
119
  }
120
120
  try {
121
121
  const { body, idempotencyKey, key, keysToRedact = [], workflowKey } = validated.value;
122
+ const { workplaceId } = body;
122
123
  const triggerBody = (0, toTriggerBody_1.toTriggerBody)(body);
123
124
  this.logTriggerRequest({ logParams, body, keysToRedact });
124
- const response = await this.provider.workflows.trigger(workflowKey ?? /* istanbul ignore next */ key, triggerBody, {
125
- idempotencyKey: (0, util_ts_1.isString)(idempotencyKey)
126
- ? idempotencyKey
127
- : idempotencyKey.toHash({ workplaceId: body.workplaceId }),
128
- });
125
+ const response = await this.provider.workflows.trigger(workflowKey ?? /* istanbul ignore next */ key, triggerBody, { idempotencyKey: (0, parseTriggerIdempotencyKey_1.parseTriggerIdempotencyKey)({ idempotencyKey, workplaceId }) });
129
126
  const id = response.workflow_run_id;
130
127
  this.logTriggerResponse({ span, response, id, logParams });
131
128
  return (0, util_ts_1.success)({ id });
@@ -273,7 +270,7 @@ class NotificationClient {
273
270
  return (0, util_ts_1.failure)(new util_ts_1.ServiceError({ issues: [{ code, message }] }));
274
271
  }
275
272
  validateTriggerRequest(params) {
276
- const { body, expiresAt, idempotencyKey, span, logParams } = params;
273
+ const { body, expiresAt, span, logParams } = params;
277
274
  if (body.recipients.length <= 0) {
278
275
  return this.createAndLogError({
279
276
  notificationError: {
@@ -296,17 +293,6 @@ class NotificationClient {
296
293
  metadata: { recipientsCount },
297
294
  });
298
295
  }
299
- const validatedIdempotencyKey = toIdempotencyKey(idempotencyKey);
300
- if ((0, util_ts_1.isNil)(validatedIdempotencyKey)) {
301
- return this.createAndLogError({
302
- notificationError: {
303
- code: exports.ERROR_CODES.invalidIdempotencyKey,
304
- message: "Invalid idempotency key.",
305
- },
306
- span,
307
- logParams,
308
- });
309
- }
310
296
  const now = new Date();
311
297
  if (expiresAt instanceof Date && now > expiresAt) {
312
298
  return this.createAndLogError({
@@ -319,7 +305,7 @@ class NotificationClient {
319
305
  metadata: { currentTime: now.toISOString(), expiresAt: expiresAt.toISOString() },
320
306
  });
321
307
  }
322
- return (0, util_ts_1.success)({ ...params, idempotencyKey: validatedIdempotencyKey });
308
+ return (0, util_ts_1.success)(params);
323
309
  }
324
310
  async getExistingTokens(params) {
325
311
  const { userId, channelId, logParams } = params;
@@ -360,28 +346,4 @@ class NotificationClient {
360
346
  }
361
347
  }
362
348
  exports.NotificationClient = NotificationClient;
363
- /**
364
- * Cannot rely on `instanceof` because idempotencyKey may have been serialized to/deserialized from
365
- * a database and just a regular object.
366
- */
367
- function toIdempotencyKey(idempotencyKey) {
368
- if ((0, util_ts_1.isString)(idempotencyKey)) {
369
- return idempotencyKey;
370
- }
371
- if (idempotencyKey instanceof triggerIdempotencyKey_1.TriggerIdempotencyKey) {
372
- return idempotencyKey;
373
- }
374
- if (typeof idempotencyKey === "object" &&
375
- idempotencyKey !== null &&
376
- "chunk" in idempotencyKey &&
377
- "recipients" in idempotencyKey &&
378
- "workflowKey" in idempotencyKey) {
379
- const { eventOccurredAt, ...rest } = idempotencyKey;
380
- return triggerIdempotencyKey_1.TriggerIdempotencyKey.DO_NOT_CALL_THIS_OUTSIDE_OF_TESTS({
381
- ...rest,
382
- eventOccurredAt: (0, util_ts_1.isString)(eventOccurredAt) ? new Date(eventOccurredAt) : eventOccurredAt,
383
- });
384
- }
385
- return undefined;
386
- }
387
349
  //# sourceMappingURL=notificationClient.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"notificationClient.js","sourceRoot":"","sources":["../../../../../packages/notifications/src/lib/notificationClient.ts"],"names":[],"mappings":";;;AAAA,uDAUmC;AACnC,0CAAgD;AAEhD,8EAA2E;AAC3E,oFAAiF;AACjF,gEAA6D;AAC7D,8CAA2C;AAC3C,sEAAmE;AACnE,4DAAyD;AACzD,mEAAkG;AAgBlG,MAAM,UAAU,GAAG;IACjB,OAAO,EAAE;QACP,SAAS,EAAE,uBAAuB;QAClC,WAAW,EAAE,yBAAyB;KACvC;IACD,eAAe,EAAE;QACf,SAAS,EAAE,+BAA+B;QAC1C,WAAW,EAAE,4BAA4B;KAC1C;IACD,eAAe,EAAE;QACf,SAAS,EAAE,+BAA+B;QAC1C,WAAW,EAAE,mBAAmB;KACjC;IACD,aAAa,EAAE;QACb,SAAS,EAAE,6BAA6B;QACxC,WAAW,EAAE,qBAAqB;KACnC;CACF,CAAC;AAEW,QAAA,wBAAwB,GAAG,IAAI,CAAC;AAEhC,QAAA,WAAW,GAAG;IACzB,OAAO,EAAE,SAAS;IAClB,qBAAqB,EAAE,uBAAuB;IAC9C,0BAA0B,EAAE,4BAA4B;IACxD,0BAA0B,EAAE,4BAA4B;IACxD,iBAAiB,EAAE,mBAAmB;IACtC,OAAO,EAAE,SAAS;CACV,CAAC;AASX;;GAEG;AACH,MAAa,kBAAkB;IACV,MAAM,CAAqC;IAC3C,QAAQ,CAAiD;IACzD,MAAM,CAAqC;IAC7C,UAAU,CAAyC;IAEpE;;OAEG;IACH,YAAY,MAAgC;QAC1C,MAAM,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,EAAE,GAAG,MAAM,CAAC;QAE9C,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,IAAI,CAA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O,EAAE,IAAI;SACd,CAAC,CAAC;QAEH,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,SAAS,CAAC,SAAS,WAAW,EAAE,EAAE,GAAG,SAAS,EAAE,EAAE,EAAE,QAAQ,EAAE,CAAC,CAAC;QAEpF,OAAO,EAAE,CAAC;IACZ,CAAC;CACF;AAvYD,gDAuYC;AAED;;;GAGG;AACH,SAAS,gBAAgB,CACvB,cAGgE;IAEhE,IAAI,IAAA,kBAAQ,EAAC,cAAc,CAAC,EAAE,CAAC;QAC7B,OAAO,cAAc,CAAC;IACxB,CAAC;IAED,IAAI,cAAc,YAAY,6CAAqB,EAAE,CAAC;QACpD,OAAO,cAAc,CAAC;IACxB,CAAC;IAED,IACE,OAAO,cAAc,KAAK,QAAQ;QAClC,cAAc,KAAK,IAAI;QACvB,OAAO,IAAI,cAAc;QACzB,YAAY,IAAI,cAAc;QAC9B,aAAa,IAAI,cAAc,EAC/B,CAAC;QACD,MAAM,EAAE,eAAe,EAAE,GAAG,IAAI,EAAE,GAAG,cAEpC,CAAC;QAEF,OAAO,6CAAqB,CAAC,iCAAiC,CAAC;YAC7D,GAAG,IAAI;YACP,eAAe,EAAE,IAAA,kBAAQ,EAAC,eAAe,CAAC,CAAC,CAAC,CAAC,IAAI,IAAI,CAAC,eAAe,CAAC,CAAC,CAAC,CAAC,eAAe;SACzF,CAAC,CAAC;IACL,CAAC;IAED,OAAO,SAAS,CAAC;AACnB,CAAC"}
1
+ {"version":3,"file":"notificationClient.js","sourceRoot":"","sources":["../../../../../packages/notifications/src/lib/notificationClient.ts"],"names":[],"mappings":";;;AAAA,uDAQmC;AACnC,0CAAgD;AAEhD,8EAA2E;AAC3E,oFAAiF;AACjF,gEAA6D;AAC7D,sFAAmF;AACnF,8CAA2C;AAC3C,sEAAmE;AACnE,4DAAyD;AAgBzD,MAAM,UAAU,GAAG;IACjB,OAAO,EAAE;QACP,SAAS,EAAE,uBAAuB;QAClC,WAAW,EAAE,yBAAyB;KAC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,IAAI,CAAC,UAAU,CAAC,MAAM;gBAClC,IAAI,EAAE,IAAA,eAAM,EAAC,EAAE,IAAI,EAAE,IAAI,CAAC,IAAI,IAAI,SAAS,EAAE,YAAY,EAAE,CAAC;aAC7D;SACF,CAAC,CAAC;IACL,CAAC;IAEO,kBAAkB,CAAC,MAK1B;QACC,MAAM,EAAE,IAAI,EAAE,QAAQ,EAAE,EAAE,EAAE,SAAS,EAAE,GAAG,MAAM,CAAC;QAEjD,IAAI,EAAE,OAAO,CAAC;YACZ,aAAa,EAAE,EAAE;YACjB,OAAO,EAAE,IAAI;SACd,CAAC,CAAC;QAEH,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,SAAS,CAAC,SAAS,WAAW,EAAE,EAAE,GAAG,SAAS,EAAE,EAAE,EAAE,QAAQ,EAAE,CAAC,CAAC;QAEpF,OAAO,EAAE,CAAC;IACZ,CAAC;CACF;AAxXD,gDAwXC"}
@@ -1,18 +1,50 @@
1
1
  import { type BackgroundJobsAdapter } from "@clipboard-health/background-jobs-adapter";
2
- import { type IdempotencyKey } from "./idempotencyKey";
3
- import { type ErrorCode } from "./notificationClient";
4
- import { TriggerIdempotencyKey } from "./triggerIdempotencyKey";
5
- import { type TriggerRequest } from "./types";
6
- /**
7
- * Assuming `NotificationClient` is called from a background job with unchanging recipients, only
8
- * the following are retryable.
9
- */
10
- export declare const RETRYABLE_ERRORS: ErrorCode[];
2
+ import { type TriggerIdempotencyKey } from "./triggerIdempotencyKey";
11
3
  type EnqueueParameters = Parameters<BackgroundJobsAdapter["enqueue"]>;
4
+ export interface IdempotencyKey {
5
+ /**
6
+ * Prefer `resourceId` over `eventOccurredAt`; it's harder to misuse.
7
+ *
8
+ * If an event triggered your workflow and it doesn't have a unique ID, you may decide to use its
9
+ * occurrence timestamp. For example, if you have a daily CRON job, use the date it ran.
10
+ *
11
+ * Use `.toISOString()`.
12
+ */
13
+ eventOccurredAt?: string | undefined;
14
+ /**
15
+ * If a resource triggered your workflow, include its unique ID.
16
+ *
17
+ * @note `workflowKey`, `recipients`, and `workplaceId` (if it exists in the trigger body) are
18
+ * included in the idempotency key automatically.
19
+ *
20
+ * @example
21
+ * 1. For a "meeting starts in one hour" notification, set resourceId to the meeting ID.
22
+ * 2. For a payout notification, set resourceId to the payment ID.
23
+ */
24
+ resourceId?: string | undefined;
25
+ }
12
26
  export interface NotificationEnqueueData {
27
+ /**
28
+ * Idempotency keys prevent duplicate notifications. They should be deterministic and remain the
29
+ * same across retry logic.
30
+ *
31
+ * If you retry a request with the same idempotency key within 24 hours, the client returns the same
32
+ * response as the original request.
33
+ *
34
+ * @note `workflowKey`, `recipients`, and `workplaceId` (if it exists in the trigger body) are
35
+ * included in the idempotency key automatically.
36
+ *
37
+ * We provide this class because idempotency keys can be difficult to use correctly. If the key
38
+ * changes on each retry (e.g., Date.now() or uuid.v4()), it won't prevent duplicate notifications.
39
+ * Conversely, if you don't provide enough information, you prevent recipients from receiving
40
+ * notifications they otherwise should have. For example, if you use the trigger key and the
41
+ * recipient's ID as the idempotency key, but it's possible the recipient could receive the same
42
+ * notification multiple times within the idempotency key's validity window, the recipient will only
43
+ * receive the first notification.
44
+ */
13
45
  idempotencyKey: IdempotencyKey;
14
46
  /** @see {@link TriggerRequest.expiresAt} */
15
- expiresAt: TriggerRequest["expiresAt"];
47
+ expiresAt: string;
16
48
  /** @see {@link TriggerBody.recipients} */
17
49
  recipients: string[];
18
50
  /** @see {@link TriggerRequest.workflowKey} */
@@ -58,27 +90,31 @@ export declare class NotificationJobEnqueuer {
58
90
  * <embedex source="packages/notifications/examples/enqueueNotificationJob.ts">
59
91
  *
60
92
  * ```ts
61
- * import { IdempotencyKey } from "@clipboard-health/notifications";
62
- *
63
- * import { ExampleNotificationJob } from "./exampleNotification.job";
93
+ * import {
94
+ * type ExampleNotificationEnqueueData,
95
+ * ExampleNotificationJob,
96
+ * } from "./exampleNotification.job";
64
97
  * import { notificationJobEnqueuer } from "./notificationJobEnqueuer";
65
98
  *
66
99
  * async function enqueueNotificationJob() {
67
- * await notificationJobEnqueuer.enqueueOneOrMore(ExampleNotificationJob, {
68
- * // Set expiresAt at enqueue-time so it remains stable across job retries.
69
- * expiresAt: minutesFromNow(60),
70
- * // Set idempotencyKey at enqueue-time so it remains stable across job retries.
71
- * idempotencyKey: new IdempotencyKey({
72
- * resourceId: "event-123",
73
- * }),
74
- * // Set recipients at enqueue-time so they respect our notification provider's limits.
75
- * recipients: ["user-1"],
76
- *
77
- * workflowKey: "event-starting-reminder",
78
- *
79
- * // Any additional enqueue-time data passed to the job:
80
- * workplaceId: "workplace-123",
81
- * });
100
+ * await notificationJobEnqueuer.enqueueOneOrMore<ExampleNotificationEnqueueData>(
101
+ * ExampleNotificationJob,
102
+ * {
103
+ * // Set expiresAt at enqueue-time so it remains stable across job retries.
104
+ * expiresAt: minutesFromNow(60).toISOString(),
105
+ * // Set idempotencyKey at enqueue-time so it remains stable across job retries.
106
+ * idempotencyKey: {
107
+ * resourceId: "event-123",
108
+ * },
109
+ * // Set recipients at enqueue-time so they respect our notification provider's limits.
110
+ * recipients: ["user-1"],
111
+ *
112
+ * workflowKey: "event-starting-reminder",
113
+ *
114
+ * // Any additional enqueue-time data passed to the job:
115
+ * workplaceId: "workplace-123",
116
+ * },
117
+ * );
82
118
  * }
83
119
  *
84
120
  * // eslint-disable-next-line unicorn/prefer-top-level-await
@@ -1,15 +1,10 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.NotificationJobEnqueuer = exports.RETRYABLE_ERRORS = void 0;
3
+ exports.NotificationJobEnqueuer = void 0;
4
4
  const background_jobs_adapter_1 = require("@clipboard-health/background-jobs-adapter");
5
5
  const chunkRecipients_1 = require("./internal/chunkRecipients");
6
- const notificationClient_1 = require("./notificationClient");
6
+ const triggerIdempotencyKeyParamsToHash_1 = require("./internal/triggerIdempotencyKeyParamsToHash");
7
7
  const triggerIdempotencyKey_1 = require("./triggerIdempotencyKey");
8
- /**
9
- * Assuming `NotificationClient` is called from a background job with unchanging recipients, only
10
- * the following are retryable.
11
- */
12
- exports.RETRYABLE_ERRORS = [notificationClient_1.ERROR_CODES.unknown];
13
8
  class NotificationJobEnqueuer {
14
9
  adapter;
15
10
  constructor(params) {
@@ -47,27 +42,31 @@ class NotificationJobEnqueuer {
47
42
  * <embedex source="packages/notifications/examples/enqueueNotificationJob.ts">
48
43
  *
49
44
  * ```ts
50
- * import { IdempotencyKey } from "@clipboard-health/notifications";
51
- *
52
- * import { ExampleNotificationJob } from "./exampleNotification.job";
45
+ * import {
46
+ * type ExampleNotificationEnqueueData,
47
+ * ExampleNotificationJob,
48
+ * } from "./exampleNotification.job";
53
49
  * import { notificationJobEnqueuer } from "./notificationJobEnqueuer";
54
50
  *
55
51
  * async function enqueueNotificationJob() {
56
- * await notificationJobEnqueuer.enqueueOneOrMore(ExampleNotificationJob, {
57
- * // Set expiresAt at enqueue-time so it remains stable across job retries.
58
- * expiresAt: minutesFromNow(60),
59
- * // Set idempotencyKey at enqueue-time so it remains stable across job retries.
60
- * idempotencyKey: new IdempotencyKey({
61
- * resourceId: "event-123",
62
- * }),
63
- * // Set recipients at enqueue-time so they respect our notification provider's limits.
64
- * recipients: ["user-1"],
52
+ * await notificationJobEnqueuer.enqueueOneOrMore<ExampleNotificationEnqueueData>(
53
+ * ExampleNotificationJob,
54
+ * {
55
+ * // Set expiresAt at enqueue-time so it remains stable across job retries.
56
+ * expiresAt: minutesFromNow(60).toISOString(),
57
+ * // Set idempotencyKey at enqueue-time so it remains stable across job retries.
58
+ * idempotencyKey: {
59
+ * resourceId: "event-123",
60
+ * },
61
+ * // Set recipients at enqueue-time so they respect our notification provider's limits.
62
+ * recipients: ["user-1"],
65
63
  *
66
- * workflowKey: "event-starting-reminder",
64
+ * workflowKey: "event-starting-reminder",
67
65
  *
68
- * // Any additional enqueue-time data passed to the job:
69
- * workplaceId: "workplace-123",
70
- * });
66
+ * // Any additional enqueue-time data passed to the job:
67
+ * workplaceId: "workplace-123",
68
+ * },
69
+ * );
71
70
  * }
72
71
  *
73
72
  * // eslint-disable-next-line unicorn/prefer-top-level-await
@@ -84,15 +83,19 @@ class NotificationJobEnqueuer {
84
83
  // The job's idempotency/unique key is set automatically.
85
84
  options) {
86
85
  await Promise.all((0, chunkRecipients_1.chunkRecipients)({ recipients: data.recipients }).map(async ({ number, recipients }) => {
87
- const idempotencyKey = triggerIdempotencyKey_1.TriggerIdempotencyKey.DO_NOT_CALL_THIS_OUTSIDE_OF_TESTS({
86
+ const idempotencyKeyParams = {
88
87
  ...data.idempotencyKey,
89
88
  chunk: number,
90
89
  recipients,
91
90
  workflowKey: data.workflowKey,
92
- });
93
- await this.adapter.enqueue(handlerClassOrInstance, { ...data, recipients, idempotencyKey }, {
91
+ };
92
+ await this.adapter.enqueue(handlerClassOrInstance, {
93
+ ...data,
94
+ recipients,
95
+ idempotencyKey: (0, triggerIdempotencyKey_1.DO_NOT_CALL_THIS_OUTSIDE_OF_TESTS)(idempotencyKeyParams),
96
+ }, {
94
97
  ...(options ? { ...options } : {}),
95
- [background_jobs_adapter_1.ENQUEUE_FIELD_NAMES[this.adapter.implementation].idempotencyKey]: idempotencyKey.toHash({}),
98
+ [background_jobs_adapter_1.ENQUEUE_FIELD_NAMES[this.adapter.implementation].idempotencyKey]: (0, triggerIdempotencyKeyParamsToHash_1.triggerIdempotencyKeyParamsToHash)(idempotencyKeyParams),
96
99
  });
97
100
  }));
98
101
  }
@@ -1 +1 @@
1
- {"version":3,"file":"notificationJobEnqueuer.js","sourceRoot":"","sources":["../../../../../packages/notifications/src/lib/notificationJobEnqueuer.ts"],"names":[],"mappings":";;;AAAA,uFAGmD;AAGnD,gEAA6D;AAC7D,6DAAmE;AACnE,mEAAgE;AAOhE;;;GAGG;AACU,QAAA,gBAAgB,GAAgB,CAAC,gCAAW,CAAC,OAAO,CAAC,CAAC;AAyBnE,MAAa,uBAAuB;IACjB,OAAO,CAA2C;IAEnE,YAAY,MAAqC;QAC/C,MAAM,EAAE,OAAO,EAAE,GAAG,MAAM,CAAC;QAE3B,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;IACzB,CAAC;IAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OA+DG;IACH,KAAK,CAAC,gBAAgB,CACpB,sBAA4C,EAC5C,IAAkB;IAClB,yDAAyD;IACzD,OAAiE;QAEjE,MAAM,OAAO,CAAC,GAAG,CACf,IAAA,iCAAe,EAAC,EAAE,UAAU,EAAE,IAAI,CAAC,UAAU,EAAE,CAAC,CAAC,GAAG,CAAC,KAAK,EAAE,EAAE,MAAM,EAAE,UAAU,EAAE,EAAE,EAAE;YACpF,MAAM,cAAc,GAAG,6CAAqB,CAAC,iCAAiC,CAAC;gBAC7E,GAAG,IAAI,CAAC,cAAc;gBACtB,KAAK,EAAE,MAAM;gBACb,UAAU;gBACV,WAAW,EAAE,IAAI,CAAC,WAAW;aAC9B,CAAC,CAAC;YAEH,MAAM,IAAI,CAAC,OAAO,CAAC,OAAO,CACxB,sBAAsB,EACtB,EAAE,GAAG,IAAI,EAAE,UAAU,EAAE,cAAc,EAAE,EACvC;gBACE,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,GAAG,OAAO,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;gBAClC,CAAC,6CAAmB,CAAC,IAAI,CAAC,OAAO,CAAC,cAAc,CAAC,CAAC,cAAc,CAAC,EAC/D,cAAc,CAAC,MAAM,CAAC,EAAE,CAAC;aAC5B,CACF,CAAC;QACJ,CAAC,CAAC,CACH,CAAC;IACJ,CAAC;CACF;AApGD,0DAoGC"}
1
+ {"version":3,"file":"notificationJobEnqueuer.js","sourceRoot":"","sources":["../../../../../packages/notifications/src/lib/notificationJobEnqueuer.ts"],"names":[],"mappings":";;;AAAA,uFAGmD;AAEnD,gEAA6D;AAC7D,oGAAiG;AACjG,mEAIiC;AAyEjC,MAAa,uBAAuB;IACjB,OAAO,CAA2C;IAEnE,YAAY,MAAqC;QAC/C,MAAM,EAAE,OAAO,EAAE,GAAG,MAAM,CAAC;QAE3B,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;IACzB,CAAC;IAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OAmEG;IACH,KAAK,CAAC,gBAAgB,CACpB,sBAA4C,EAC5C,IAAkB;IAClB,yDAAyD;IACzD,OAAiE;QAEjE,MAAM,OAAO,CAAC,GAAG,CACf,IAAA,iCAAe,EAAC,EAAE,UAAU,EAAE,IAAI,CAAC,UAAU,EAAE,CAAC,CAAC,GAAG,CAAC,KAAK,EAAE,EAAE,MAAM,EAAE,UAAU,EAAE,EAAE,EAAE;YACpF,MAAM,oBAAoB,GAAgC;gBACxD,GAAG,IAAI,CAAC,cAAc;gBACtB,KAAK,EAAE,MAAM;gBACb,UAAU;gBACV,WAAW,EAAE,IAAI,CAAC,WAAW;aAC9B,CAAC;YAEF,MAAM,IAAI,CAAC,OAAO,CAAC,OAAO,CACxB,sBAAsB,EACtB;gBACE,GAAG,IAAI;gBACP,UAAU;gBACV,cAAc,EAAE,IAAA,yDAAiC,EAAC,oBAAoB,CAAC;aACxE,EACD;gBACE,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,GAAG,OAAO,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;gBAClC,CAAC,6CAAmB,CAAC,IAAI,CAAC,OAAO,CAAC,cAAc,CAAC,CAAC,cAAc,CAAC,EAC/D,IAAA,qEAAiC,EAAC,oBAAoB,CAAC;aAC1D,CACF,CAAC;QACJ,CAAC,CAAC,CACH,CAAC;IACJ,CAAC;CACF;AA5GD,0DA4GC"}
@@ -1,5 +1,16 @@
1
- import { IdempotencyKey, type IdempotencyKeyParams } from "./idempotencyKey";
2
- export interface TriggerIdempotencyKeyParams extends IdempotencyKeyParams {
1
+ import { type Tagged } from "type-fest";
2
+ import { type IdempotencyKey } from "./notificationJobEnqueuer";
3
+ /**
4
+ * Idempotency keys prevent duplicate notifications. `NotificationClient.trigger` should be called
5
+ * after properly enqueuing a job using `NotificationJobEnqueuer.enqueueOneOrMore` to help ensure
6
+ * we're following best practices so customers don't receive duplicate or stale notifications.
7
+ *
8
+ * Yes, you could use an as assertion to create a TriggerIdempotencyKey and then call
9
+ * `NotificationClient.trigger` directly. We're using the honor system in hopes that enforcement is
10
+ * unnecessary.
11
+ */
12
+ export type TriggerIdempotencyKey = Tagged<string, "TriggerIdempotencyKey">;
13
+ export interface TriggerIdempotencyKeyParams extends IdempotencyKey {
3
14
  /**
4
15
  * The recipient chunk number.
5
16
  */
@@ -14,29 +25,11 @@ export interface TriggerIdempotencyKeyParams extends IdempotencyKeyParams {
14
25
  workflowKey: string;
15
26
  }
16
27
  /**
17
- * Idempotency keys prevent duplicate notifications. `NotificationClient.trigger` should be called
18
- * after properly enqueuing a job using `NotificationJobEnqueuer.enqueueOneOrMore` to help ensure
19
- * we're following best practices so customers don't receive duplicate or stale notifications.
20
- *
21
- * Yes, you could import this class into your service, create an instance, and call
22
- * `NotificationClient.trigger` directly. We're using the honor system in hopes that enforcement is
23
- * unnecessary.
24
- *
25
- * @see {@link NotificationJobEnqueuer.enqueueOneOrMore}.
28
+ * Type guard to check if a value is a valid TriggerIdempotencyKeyParams object.
26
29
  */
27
- export declare class TriggerIdempotencyKey extends IdempotencyKey {
28
- /**
29
- * For internal library use and testing only. Service code should use
30
- * {@link NotificationJobEnqueuer.enqueueOneOrMore} instead.
31
- *
32
- * @see {@link TriggerIdempotencyKey}.
33
- */
34
- static DO_NOT_CALL_THIS_OUTSIDE_OF_TESTS(params: TriggerIdempotencyKeyParams): TriggerIdempotencyKey;
35
- private readonly chunk;
36
- private readonly recipients;
37
- private readonly workflowKey;
38
- private constructor();
39
- toHash(params: {
40
- workplaceId?: string | undefined;
41
- }): string;
42
- }
30
+ export declare function isTriggerIdempotencyKeyParams(value: unknown): value is TriggerIdempotencyKeyParams;
31
+ /**
32
+ * For internal library use and testing only. Service code should use
33
+ * {@link NotificationJobEnqueuer.enqueueOneOrMore} instead.
34
+ */
35
+ export declare function DO_NOT_CALL_THIS_OUTSIDE_OF_TESTS(params: TriggerIdempotencyKeyParams): TriggerIdempotencyKey;
@@ -1,53 +1,27 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.TriggerIdempotencyKey = void 0;
3
+ exports.isTriggerIdempotencyKeyParams = isTriggerIdempotencyKeyParams;
4
+ exports.DO_NOT_CALL_THIS_OUTSIDE_OF_TESTS = DO_NOT_CALL_THIS_OUTSIDE_OF_TESTS;
4
5
  const util_ts_1 = require("@clipboard-health/util-ts");
5
- const idempotencyKey_1 = require("./idempotencyKey");
6
- const createDeterministicHash_1 = require("./internal/createDeterministicHash");
7
6
  /**
8
- * Idempotency keys prevent duplicate notifications. `NotificationClient.trigger` should be called
9
- * after properly enqueuing a job using `NotificationJobEnqueuer.enqueueOneOrMore` to help ensure
10
- * we're following best practices so customers don't receive duplicate or stale notifications.
11
- *
12
- * Yes, you could import this class into your service, create an instance, and call
13
- * `NotificationClient.trigger` directly. We're using the honor system in hopes that enforcement is
14
- * unnecessary.
15
- *
16
- * @see {@link NotificationJobEnqueuer.enqueueOneOrMore}.
7
+ * Type guard to check if a value is a valid TriggerIdempotencyKeyParams object.
17
8
  */
18
- class TriggerIdempotencyKey extends idempotencyKey_1.IdempotencyKey {
19
- /**
20
- * For internal library use and testing only. Service code should use
21
- * {@link NotificationJobEnqueuer.enqueueOneOrMore} instead.
22
- *
23
- * @see {@link TriggerIdempotencyKey}.
24
- */
25
- static DO_NOT_CALL_THIS_OUTSIDE_OF_TESTS(params) {
26
- return new TriggerIdempotencyKey(params);
27
- }
28
- chunk;
29
- recipients;
30
- workflowKey;
31
- constructor(params) {
32
- const { chunk, recipients, workflowKey, ...rest } = params;
33
- super(rest);
34
- this.chunk = chunk;
35
- this.recipients = recipients;
36
- this.workflowKey = workflowKey;
37
- }
38
- toHash(params) {
39
- const { workplaceId } = params;
40
- return (0, createDeterministicHash_1.createDeterministicHash)([
41
- this.workflowKey,
42
- this.chunk,
43
- this.resourceId,
44
- this.eventOccurredAt?.toISOString(),
45
- this.recipients.join(","),
46
- workplaceId,
47
- ]
48
- .filter(util_ts_1.isDefined)
49
- .join(","));
9
+ function isTriggerIdempotencyKeyParams(value) {
10
+ if ((0, util_ts_1.isNil)(value) || typeof value !== "object") {
11
+ return false;
50
12
  }
13
+ const params = value;
14
+ return ("chunk" in params &&
15
+ "workflowKey" in params &&
16
+ "recipients" in params &&
17
+ Array.isArray(params.recipients) &&
18
+ params.recipients.every((recipient) => typeof recipient === "string"));
19
+ }
20
+ /**
21
+ * For internal library use and testing only. Service code should use
22
+ * {@link NotificationJobEnqueuer.enqueueOneOrMore} instead.
23
+ */
24
+ function DO_NOT_CALL_THIS_OUTSIDE_OF_TESTS(params) {
25
+ return JSON.stringify(params);
51
26
  }
52
- exports.TriggerIdempotencyKey = TriggerIdempotencyKey;
53
27
  //# sourceMappingURL=triggerIdempotencyKey.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"triggerIdempotencyKey.js","sourceRoot":"","sources":["../../../../../packages/notifications/src/lib/triggerIdempotencyKey.ts"],"names":[],"mappings":";;;AAAA,uDAAsD;AAEtD,qDAA6E;AAC7E,gFAA6E;AAuB7E;;;;;;;;;;GAUG;AACH,MAAa,qBAAsB,SAAQ,+BAAc;IACvD;;;;;OAKG;IACI,MAAM,CAAC,iCAAiC,CAC7C,MAAmC;QAEnC,OAAO,IAAI,qBAAqB,CAAC,MAAM,CAAC,CAAC;IAC3C,CAAC;IAEgB,KAAK,CAAuC;IAC5C,UAAU,CAA4C;IACtD,WAAW,CAA6C;IAEzE,YAAoB,MAAmC;QACrD,MAAM,EAAE,KAAK,EAAE,UAAU,EAAE,WAAW,EAAE,GAAG,IAAI,EAAE,GAAG,MAAM,CAAC;QAE3D,KAAK,CAAC,IAAI,CAAC,CAAC;QACZ,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;QACnB,IAAI,CAAC,UAAU,GAAG,UAAU,CAAC;QAC7B,IAAI,CAAC,WAAW,GAAG,WAAW,CAAC;IACjC,CAAC;IAEM,MAAM,CAAC,MAA4C;QACxD,MAAM,EAAE,WAAW,EAAE,GAAG,MAAM,CAAC;QAE/B,OAAO,IAAA,iDAAuB,EAC5B;YACE,IAAI,CAAC,WAAW;YAChB,IAAI,CAAC,KAAK;YACV,IAAI,CAAC,UAAU;YACf,IAAI,CAAC,eAAe,EAAE,WAAW,EAAE;YACnC,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC,GAAG,CAAC;YACzB,WAAW;SACZ;aACE,MAAM,CAAC,mBAAS,CAAC;aACjB,IAAI,CAAC,GAAG,CAAC,CACb,CAAC;IACJ,CAAC;CACF;AA1CD,sDA0CC"}
1
+ {"version":3,"file":"triggerIdempotencyKey.js","sourceRoot":"","sources":["../../../../../packages/notifications/src/lib/triggerIdempotencyKey.ts"],"names":[],"mappings":";;AAwCA,sEAeC;AAMD,8EAIC;AAjED,uDAAkD;AAqClD;;GAEG;AACH,SAAgB,6BAA6B,CAC3C,KAAc;IAEd,IAAI,IAAA,eAAK,EAAC,KAAK,CAAC,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE,CAAC;QAC9C,OAAO,KAAK,CAAC;IACf,CAAC;IAED,MAAM,MAAM,GAAG,KAA6C,CAAC;IAC7D,OAAO,CACL,OAAO,IAAI,MAAM;QACjB,aAAa,IAAI,MAAM;QACvB,YAAY,IAAI,MAAM;QACtB,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC,UAAU,CAAC;QAChC,MAAM,CAAC,UAAU,CAAC,KAAK,CAAC,CAAC,SAAS,EAAE,EAAE,CAAC,OAAO,SAAS,KAAK,QAAQ,CAAC,CACtE,CAAC;AACJ,CAAC;AAED;;;GAGG;AACH,SAAgB,iCAAiC,CAC/C,MAAmC;IAEnC,OAAO,IAAI,CAAC,SAAS,CAAC,MAAM,CAA0B,CAAC;AACzD,CAAC"}
@@ -144,13 +144,11 @@ export interface TriggerRequest {
144
144
  * expiresAt`. If, for example, you're notifying about an event that starts in one hour, you might
145
145
  * set this to one hour from now.
146
146
  *
147
- * If you are not retrying or your notification is never stale, set it to `false`.
148
- *
149
147
  * If you're triggering from a background job, don't set this at the call site, set it when you
150
148
  * enqueue the job. Otherwise, it gets updated each time the job retries, will always be in the
151
149
  * future, and won't prevent stale notifications.
152
150
  */
153
- expiresAt: Date | false;
151
+ expiresAt: Date;
154
152
  /** Attempt number for tracing. */
155
153
  attempt: number;
156
154
  }
@@ -1,46 +0,0 @@
1
- export interface IdempotencyKeyParams {
2
- /**
3
- * Prefer `resourceId` over `eventOccurredAt`; it's harder to misuse.
4
- *
5
- * If an event triggered your workflow and it doesn't have a unique ID, you may decide to use its
6
- * occurrence timestamp. For example, if you have a daily CRON job, use the date it ran.
7
- *
8
- * Take care when using `Date.now()` or `new Date()`. These change each time your job runs, which
9
- * means the idempotency key will always be different and doesn't prevent duplicate notifications.
10
- */
11
- eventOccurredAt?: Date | undefined;
12
- /**
13
- * If a resource triggered your workflow, include its unique ID.
14
- *
15
- * @note `workflowKey`, `recipients`, and `workplaceId` (if it exists in the trigger body) are
16
- * included in the idempotency key automatically.
17
- *
18
- * @example
19
- * 1. For a "meeting starts in one hour" notification, set resourceId to the meeting ID.
20
- * 2. For a payout notification, set resourceId to the payment ID.
21
- */
22
- resourceId?: string | undefined;
23
- }
24
- /**
25
- * Idempotency keys prevent duplicate notifications. They should be deterministic and remain the
26
- * same across retry logic.
27
- *
28
- * If you retry a request with the same idempotency key within 24 hours, the client returns the same
29
- * response as the original request.
30
- *
31
- * @note `workflowKey`, `recipients`, and `workplaceId` (if it exists in the trigger body) are
32
- * included in the idempotency key automatically.
33
- *
34
- * We provide this class because idempotency keys can be difficult to use correctly. If the key
35
- * changes on each retry (e.g., Date.now() or uuid.v4()), it won't prevent duplicate notifications.
36
- * Conversely, if you don't provide enough information, you prevent recipients from receiving
37
- * notifications they otherwise should have. For example, if you use the trigger key and the
38
- * recipient's ID as the idempotency key, but it's possible the recipient could receive the same
39
- * notification multiple times within the idempotency key's validity window, the recipient will only
40
- * receive the first notification.
41
- */
42
- export declare class IdempotencyKey {
43
- protected readonly eventOccurredAt: IdempotencyKeyParams["eventOccurredAt"];
44
- protected readonly resourceId: IdempotencyKeyParams["resourceId"];
45
- constructor(params: IdempotencyKeyParams);
46
- }
@@ -1,32 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.IdempotencyKey = void 0;
4
- /**
5
- * Idempotency keys prevent duplicate notifications. They should be deterministic and remain the
6
- * same across retry logic.
7
- *
8
- * If you retry a request with the same idempotency key within 24 hours, the client returns the same
9
- * response as the original request.
10
- *
11
- * @note `workflowKey`, `recipients`, and `workplaceId` (if it exists in the trigger body) are
12
- * included in the idempotency key automatically.
13
- *
14
- * We provide this class because idempotency keys can be difficult to use correctly. If the key
15
- * changes on each retry (e.g., Date.now() or uuid.v4()), it won't prevent duplicate notifications.
16
- * Conversely, if you don't provide enough information, you prevent recipients from receiving
17
- * notifications they otherwise should have. For example, if you use the trigger key and the
18
- * recipient's ID as the idempotency key, but it's possible the recipient could receive the same
19
- * notification multiple times within the idempotency key's validity window, the recipient will only
20
- * receive the first notification.
21
- */
22
- class IdempotencyKey {
23
- eventOccurredAt;
24
- resourceId;
25
- constructor(params) {
26
- const { eventOccurredAt, resourceId } = params;
27
- this.eventOccurredAt = eventOccurredAt;
28
- this.resourceId = resourceId;
29
- }
30
- }
31
- exports.IdempotencyKey = IdempotencyKey;
32
- //# sourceMappingURL=idempotencyKey.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"idempotencyKey.js","sourceRoot":"","sources":["../../../../../packages/notifications/src/lib/idempotencyKey.ts"],"names":[],"mappings":";;;AAyBA;;;;;;;;;;;;;;;;;GAiBG;AACH,MAAa,cAAc;IACN,eAAe,CAA0C;IACzD,UAAU,CAAqC;IAElE,YAAmB,MAA4B;QAC7C,MAAM,EAAE,eAAe,EAAE,UAAU,EAAE,GAAG,MAAM,CAAC;QAE/C,IAAI,CAAC,eAAe,GAAG,eAAe,CAAC;QACvC,IAAI,CAAC,UAAU,GAAG,UAAU,CAAC;IAC/B,CAAC;CACF;AAVD,wCAUC"}