@clipboard-health/notifications 2.5.0 → 2.5.1
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 +5 -5
- package/src/lib/internal/triggerIdempotencyKeyParamsToHash.js +7 -5
- package/src/lib/internal/triggerIdempotencyKeyParamsToHash.js.map +1 -1
- package/src/lib/notificationJobEnqueuer.d.ts +3 -14
- package/src/lib/notificationJobEnqueuer.js +0 -1
- package/src/lib/notificationJobEnqueuer.js.map +1 -1
- package/src/lib/triggerIdempotencyKey.d.ts +2 -2
- package/src/lib/triggerIdempotencyKey.js +1 -1
- package/src/lib/triggerIdempotencyKey.js.map +1 -1
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": "2.5.
|
|
4
|
+
"version": "2.5.1",
|
|
5
5
|
"bugs": "https://github.com/ClipboardHealth/core-utils/issues",
|
|
6
6
|
"dependencies": {
|
|
7
|
-
"@clipboard-health/background-jobs-adapter": "1.5.
|
|
8
|
-
"@clipboard-health/phone-number": "1.5.
|
|
9
|
-
"@clipboard-health/util-ts": "4.5.
|
|
7
|
+
"@clipboard-health/background-jobs-adapter": "1.5.1",
|
|
8
|
+
"@clipboard-health/phone-number": "1.5.1",
|
|
9
|
+
"@clipboard-health/util-ts": "4.5.1",
|
|
10
10
|
"@knocklabs/node": "1.24.0",
|
|
11
11
|
"tslib": "2.8.1"
|
|
12
12
|
},
|
|
13
13
|
"devDependencies": {
|
|
14
|
-
"@clipboard-health/testing-core": "1.5.
|
|
14
|
+
"@clipboard-health/testing-core": "1.5.1",
|
|
15
15
|
"type-fest": "5.3.1"
|
|
16
16
|
},
|
|
17
17
|
"keywords": [],
|
|
@@ -5,16 +5,18 @@ const createDeterministicHash_1 = require("./createDeterministicHash");
|
|
|
5
5
|
function triggerIdempotencyKeyParamsToHash(params) {
|
|
6
6
|
return (0, createDeterministicHash_1.createDeterministicHash)(toSorted(params));
|
|
7
7
|
}
|
|
8
|
+
/**
|
|
9
|
+
* Sort the object keys to ensure a deterministic hash.
|
|
10
|
+
*/
|
|
8
11
|
function toSorted(params) {
|
|
9
12
|
return {
|
|
10
13
|
chunk: params.chunk,
|
|
11
14
|
eventOccurredAt: params.eventOccurredAt,
|
|
12
15
|
recipients: [...params.recipients].sort(),
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
:
|
|
16
|
-
|
|
17
|
-
: undefined,
|
|
16
|
+
resource: {
|
|
17
|
+
id: params.resource?.id,
|
|
18
|
+
type: params.resource?.type,
|
|
19
|
+
},
|
|
18
20
|
workflowKey: params.workflowKey,
|
|
19
21
|
workplaceId: params.workplaceId,
|
|
20
22
|
};
|
|
@@ -1 +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,
|
|
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;;GAEG;AACH,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,QAAQ,EAAE;YACR,EAAE,EAAE,MAAM,CAAC,QAAQ,EAAE,EAAE;YACvB,IAAI,EAAE,MAAM,CAAC,QAAQ,EAAE,IAAI;SAC5B;QACD,WAAW,EAAE,MAAM,CAAC,WAAW;QAC/B,WAAW,EAAE,MAAM,CAAC,WAAW;KAChC,CAAC;AACJ,CAAC"}
|
|
@@ -1,13 +1,6 @@
|
|
|
1
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
|
-
/**
|
|
5
|
-
* @deprecated Use `IdempotencyKeyParts` instead.
|
|
6
|
-
*/
|
|
7
|
-
export interface IdempotencyKey {
|
|
8
|
-
eventOccurredAt?: string | undefined;
|
|
9
|
-
resourceId?: string | undefined;
|
|
10
|
-
}
|
|
11
4
|
export type IdempotencyKeyParts = {
|
|
12
5
|
/**
|
|
13
6
|
* Prefer `resourceId` over `eventOccurredAt`; it's harder to misuse.
|
|
@@ -37,10 +30,6 @@ export type IdempotencyKeyParts = {
|
|
|
37
30
|
};
|
|
38
31
|
};
|
|
39
32
|
export interface NotificationEnqueueData {
|
|
40
|
-
/**
|
|
41
|
-
* @deprecated Use `idempotencyKeyParts` instead.
|
|
42
|
-
*/
|
|
43
|
-
idempotencyKey?: IdempotencyKey;
|
|
44
33
|
/**
|
|
45
34
|
* Do not include `workflowKey`, `recipients`, or `workplaceId`; they are included
|
|
46
35
|
* automatically.
|
|
@@ -59,7 +48,7 @@ export interface NotificationEnqueueData {
|
|
|
59
48
|
* same notification multiple times within the idempotency key's validity window, the recipient
|
|
60
49
|
* will only receive the first notification.
|
|
61
50
|
*/
|
|
62
|
-
idempotencyKeyParts
|
|
51
|
+
idempotencyKeyParts: IdempotencyKeyParts;
|
|
63
52
|
/** @see {@link TriggerRequest.expiresAt} */
|
|
64
53
|
expiresAt: string;
|
|
65
54
|
/** @see {@link TriggerBody.recipients} */
|
|
@@ -67,7 +56,7 @@ export interface NotificationEnqueueData {
|
|
|
67
56
|
/** @see {@link TriggerRequest.workflowKey} */
|
|
68
57
|
workflowKey: string;
|
|
69
58
|
}
|
|
70
|
-
export interface NotificationJobData extends Omit<NotificationEnqueueData, "
|
|
59
|
+
export interface NotificationJobData extends Omit<NotificationEnqueueData, "idempotencyKeyParts"> {
|
|
71
60
|
idempotencyKey: TriggerIdempotencyKey;
|
|
72
61
|
}
|
|
73
62
|
/**
|
|
@@ -103,7 +92,7 @@ export interface NotificationData<T> {
|
|
|
103
92
|
* There are valid use cases for `startAt`, however. For example, if you do checks in your job (or
|
|
104
93
|
* in a service the job calls) to validate the notification is still valid prior to triggering it.
|
|
105
94
|
*/
|
|
106
|
-
export type EnqueueOneOrMoreOptions = Pick<EnqueueOptions, "startAt"> & (Pick<MongoEnqueueOptions, "session"
|
|
95
|
+
export type EnqueueOneOrMoreOptions = Pick<EnqueueOptions, "startAt"> & (Pick<MongoEnqueueOptions, "session"> | Pick<PostgresEnqueueOptions, "transaction">);
|
|
107
96
|
interface NotificationJobEnqueuerParams {
|
|
108
97
|
adapter: BackgroundJobsAdapter;
|
|
109
98
|
}
|
|
@@ -86,7 +86,6 @@ class NotificationJobEnqueuer {
|
|
|
86
86
|
async enqueueOneOrMore(handlerClassOrInstance, data, options) {
|
|
87
87
|
await Promise.all((0, chunkRecipients_1.chunkRecipients)({ recipients: data.recipients }).map(async ({ number, recipients }) => {
|
|
88
88
|
const idempotencyKeyParams = {
|
|
89
|
-
...data.idempotencyKey,
|
|
90
89
|
...data.idempotencyKeyParts,
|
|
91
90
|
chunk: number,
|
|
92
91
|
recipients,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"notificationJobEnqueuer.js","sourceRoot":"","sources":["../../../../../packages/notifications/src/lib/notificationJobEnqueuer.ts"],"names":[],"mappings":";;;AAAA,uFAMmD;AAEnD,gEAA6D;AAC7D,oGAAiG;AACjG,mEAIiC;
|
|
1
|
+
{"version":3,"file":"notificationJobEnqueuer.js","sourceRoot":"","sources":["../../../../../packages/notifications/src/lib/notificationJobEnqueuer.ts"],"names":[],"mappings":";;;AAAA,uFAMmD;AAEnD,gEAA6D;AAC7D,oGAAiG;AACjG,mEAIiC;AAoHjC,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;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OAuEG;IACH,KAAK,CAAC,gBAAgB,CACpB,sBAA4C,EAC5C,IAAkB,EAClB,OAAiC;QAEjC,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,mBAAmB;gBAC3B,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;AA/GD,0DA+GC"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { type Tagged } from "type-fest";
|
|
2
|
-
import { type
|
|
2
|
+
import { type IdempotencyKeyParts } from "./notificationJobEnqueuer";
|
|
3
3
|
/**
|
|
4
4
|
* Idempotency keys prevent duplicate notifications. `NotificationClient.trigger` should be called
|
|
5
5
|
* after properly enqueuing a job using `NotificationJobEnqueuer.enqueueOneOrMore` to help ensure
|
|
@@ -10,7 +10,7 @@ import { type IdempotencyKey, type IdempotencyKeyParts } from "./notificationJob
|
|
|
10
10
|
* unnecessary.
|
|
11
11
|
*/
|
|
12
12
|
export type TriggerIdempotencyKey = Tagged<string, "TriggerIdempotencyKey">;
|
|
13
|
-
export type TriggerIdempotencyKeyParams =
|
|
13
|
+
export type TriggerIdempotencyKeyParams = IdempotencyKeyParts & {
|
|
14
14
|
/**
|
|
15
15
|
* The recipient chunk number.
|
|
16
16
|
*/
|
|
@@ -23,6 +23,6 @@ function isTriggerIdempotencyKeyParams(value) {
|
|
|
23
23
|
*/
|
|
24
24
|
function DO_NOT_CALL_THIS_OUTSIDE_OF_TESTS(params) {
|
|
25
25
|
// eslint-disable-next-line no-restricted-syntax -- allow test casts
|
|
26
|
-
return
|
|
26
|
+
return (0, util_ts_1.stringify)(params);
|
|
27
27
|
}
|
|
28
28
|
//# sourceMappingURL=triggerIdempotencyKey.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"triggerIdempotencyKey.js","sourceRoot":"","sources":["../../../../../packages/notifications/src/lib/triggerIdempotencyKey.ts"],"names":[],"mappings":";;
|
|
1
|
+
{"version":3,"file":"triggerIdempotencyKey.js","sourceRoot":"","sources":["../../../../../packages/notifications/src/lib/triggerIdempotencyKey.ts"],"names":[],"mappings":";;AAwCA,sEAeC;AAMD,8EAKC;AAlED,uDAA6D;AAqC7D;;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,KAAoC,CAAC;IACpD,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,oEAAoE;IACpE,OAAO,IAAA,mBAAS,EAAC,MAAM,CAA0B,CAAC;AACpD,CAAC"}
|