@clipboard-health/notifications 1.2.0 → 1.2.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/package.json CHANGED
@@ -1,17 +1,17 @@
1
1
  {
2
2
  "name": "@clipboard-health/notifications",
3
3
  "description": "Send notifications through third-party providers.",
4
- "version": "1.2.0",
4
+ "version": "1.2.2",
5
5
  "bugs": "https://github.com/ClipboardHealth/core-utils/issues",
6
6
  "dependencies": {
7
- "@clipboard-health/background-jobs-adapter": "0.5.0",
8
- "@clipboard-health/phone-number": "0.9.0",
9
- "@clipboard-health/util-ts": "3.18.0",
7
+ "@clipboard-health/background-jobs-adapter": "0.5.1",
8
+ "@clipboard-health/phone-number": "0.9.1",
9
+ "@clipboard-health/util-ts": "3.18.1",
10
10
  "@knocklabs/node": "1.20.0",
11
11
  "tslib": "2.8.1"
12
12
  },
13
13
  "devDependencies": {
14
- "@clipboard-health/testing-core": "0.27.0",
14
+ "@clipboard-health/testing-core": "0.27.1",
15
15
  "type-fest": "5.0.1"
16
16
  },
17
17
  "keywords": [],
@@ -1,4 +1,4 @@
1
- import { type BackgroundJobsAdapter } from "@clipboard-health/background-jobs-adapter";
1
+ import { type BackgroundJobsAdapter, type EnqueueOptions, type MongoEnqueueOptions, type PostgresEnqueueOptions } from "@clipboard-health/background-jobs-adapter";
2
2
  import { type TriggerIdempotencyKey } from "./triggerIdempotencyKey";
3
3
  type EnqueueParameters = Parameters<BackgroundJobsAdapter["enqueue"]>;
4
4
  export interface IdempotencyKey {
@@ -76,6 +76,17 @@ export interface NotificationData<T> {
76
76
  Job: NotificationJobData & T;
77
77
  Enqueue: NotificationEnqueueData & T;
78
78
  }
79
+ /**
80
+ * `enqueueOneOrMore` sets `idempotencyKey`/`unique` automatically, so it's not accepted here.
81
+ *
82
+ * Use `startAt` with care to prevent stale recipient lists. To prevent stale recipient lists, it
83
+ * may make more sense to schedule a normal job in the future that, when executed, looks up
84
+ * recipients and queues a notification job that runs immediately.
85
+ *
86
+ * There are valid use cases for `startAt`, however. For example, if you do checks in your job (or
87
+ * in a service the job calls) to validate the notification is still valid prior to triggering it.
88
+ */
89
+ export type EnqueueOneOrMoreOptions = Pick<EnqueueOptions, "startAt"> & (Pick<MongoEnqueueOptions, "session" | "startAt"> | Pick<PostgresEnqueueOptions, "transaction" | "startAt">);
79
90
  interface NotificationJobEnqueuerParams {
80
91
  adapter: BackgroundJobsAdapter;
81
92
  }
@@ -150,6 +161,6 @@ export declare class NotificationJobEnqueuer {
150
161
  *
151
162
  * </embedex>
152
163
  */
153
- enqueueOneOrMore<TEnqueueData extends NotificationEnqueueData>(handlerClassOrInstance: EnqueueParameters[0], data: TEnqueueData, options?: Omit<EnqueueParameters[2], "idempotencyKey" | "unique">): Promise<void>;
164
+ enqueueOneOrMore<TEnqueueData extends NotificationEnqueueData>(handlerClassOrInstance: EnqueueParameters[0], data: TEnqueueData, options?: EnqueueOneOrMoreOptions): Promise<void>;
154
165
  }
155
166
  export {};
@@ -79,9 +79,7 @@ class NotificationJobEnqueuer {
79
79
  *
80
80
  * </embedex>
81
81
  */
82
- async enqueueOneOrMore(handlerClassOrInstance, data,
83
- // The job's idempotency/unique key is set automatically.
84
- options) {
82
+ async enqueueOneOrMore(handlerClassOrInstance, data, options) {
85
83
  await Promise.all((0, chunkRecipients_1.chunkRecipients)({ recipients: data.recipients }).map(async ({ number, recipients }) => {
86
84
  const idempotencyKeyParams = {
87
85
  ...data.idempotencyKey,
@@ -1 +1 @@
1
- {"version":3,"file":"notificationJobEnqueuer.js","sourceRoot":"","sources":["../../../../../packages/notifications/src/lib/notificationJobEnqueuer.ts"],"names":[],"mappings":";;;AAAA,uFAGmD;AAEnD,gEAA6D;AAC7D,oGAAiG;AACjG,mEAIiC;AAiGjC,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
+ {"version":3,"file":"notificationJobEnqueuer.js","sourceRoot":"","sources":["../../../../../packages/notifications/src/lib/notificationJobEnqueuer.ts"],"names":[],"mappings":";;;AAAA,uFAMmD;AAEnD,gEAA6D;AAC7D,oGAAiG;AACjG,mEAIiC;AAiHjC,MAAa,uBAAuB;IACjB,OAAO,CAA2C;IAEnE,YAAY,MAAqC;QAC/C,MAAM,EAAE,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