@clipboard-health/notifications 1.2.1 → 1.2.3
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 +67 -80
- package/package.json +3 -3
- package/src/lib/notificationClient.d.ts +7 -6
- package/src/lib/notificationClient.js +7 -6
- package/src/lib/notificationClient.js.map +1 -1
- package/src/lib/notificationJobEnqueuer.d.ts +19 -17
- package/src/lib/notificationJobEnqueuer.js +11 -12
- package/src/lib/notificationJobEnqueuer.js.map +1 -1
package/README.md
CHANGED
|
@@ -4,102 +4,47 @@ Send notifications through third-party providers.
|
|
|
4
4
|
|
|
5
5
|
## Table of contents <!-- omit from toc -->
|
|
6
6
|
|
|
7
|
-
- [Install](#install)
|
|
8
|
-
- [Usage](#usage)
|
|
9
7
|
- [Local development commands](#local-development-commands)
|
|
10
8
|
|
|
11
|
-
|
|
9
|
+
<embedex source="packages/notifications/examples/usage.md">
|
|
12
10
|
|
|
13
|
-
|
|
14
|
-
npm install @clipboard-health/notifications
|
|
15
|
-
```
|
|
16
|
-
|
|
17
|
-
## Usage
|
|
18
|
-
|
|
19
|
-
1. Export a `NotificationJobEnqueuer` instance:
|
|
20
|
-
|
|
21
|
-
<embedex source="packages/notifications/examples/notificationJobEnqueuer.ts">
|
|
11
|
+
1. Search your service for a `NotificationJobEnqueuer` instance. If there isn't one, create and export it:
|
|
22
12
|
|
|
23
13
|
```ts
|
|
24
14
|
import { NotificationJobEnqueuer } from "@clipboard-health/notifications";
|
|
25
15
|
|
|
26
16
|
import { BackgroundJobsService } from "./setup";
|
|
27
17
|
|
|
28
|
-
//
|
|
18
|
+
// Create and export one instance of this in your microservice.
|
|
29
19
|
export const notificationJobEnqueuer = new NotificationJobEnqueuer({
|
|
20
|
+
// Use your instance of `@clipboard-health/mongo-jobs` or `@clipboard-health/background-jobs-postgres` here.
|
|
30
21
|
adapter: new BackgroundJobsService(),
|
|
31
22
|
});
|
|
32
23
|
```
|
|
33
24
|
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
1. Enqueue your job:
|
|
37
|
-
|
|
38
|
-
<embedex source="packages/notifications/examples/enqueueNotificationJob.ts">
|
|
39
|
-
|
|
40
|
-
```ts
|
|
41
|
-
import {
|
|
42
|
-
type ExampleNotificationEnqueueData,
|
|
43
|
-
ExampleNotificationJob,
|
|
44
|
-
} from "./exampleNotification.job";
|
|
45
|
-
import { notificationJobEnqueuer } from "./notificationJobEnqueuer";
|
|
46
|
-
|
|
47
|
-
async function enqueueNotificationJob() {
|
|
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
|
-
);
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
// eslint-disable-next-line unicorn/prefer-top-level-await
|
|
69
|
-
void enqueueNotificationJob();
|
|
70
|
-
|
|
71
|
-
function minutesFromNow(minutes: number) {
|
|
72
|
-
return new Date(Date.now() + minutes * 60_000);
|
|
73
|
-
}
|
|
74
|
-
```
|
|
75
|
-
|
|
76
|
-
</embedex>
|
|
77
|
-
|
|
78
|
-
1. Implement your job, which should be minimal, calling off to a service to send the actual notification:
|
|
79
|
-
|
|
80
|
-
<embedex source="packages/notifications/examples/exampleNotification.job.ts">
|
|
25
|
+
1. Implement a minimal job, calling off to a NestJS service for any business logic and to send the notification.
|
|
81
26
|
|
|
82
27
|
```ts
|
|
83
28
|
import { type BaseHandler } from "@clipboard-health/background-jobs-adapter";
|
|
84
|
-
import {
|
|
85
|
-
type NotificationEnqueueData,
|
|
86
|
-
type NotificationJobData,
|
|
87
|
-
} from "@clipboard-health/notifications";
|
|
29
|
+
import { type NotificationData } from "@clipboard-health/notifications";
|
|
88
30
|
import { isFailure, toError } from "@clipboard-health/util-ts";
|
|
89
31
|
|
|
90
32
|
import { type ExampleNotificationService } from "./exampleNotification.service";
|
|
91
33
|
|
|
92
|
-
|
|
34
|
+
export type ExampleNotificationData = NotificationData<{
|
|
93
35
|
workplaceId: string;
|
|
94
|
-
}
|
|
36
|
+
}>;
|
|
95
37
|
|
|
96
|
-
export
|
|
97
|
-
|
|
38
|
+
export const EXAMPLE_NOTIFICATION_JOB_NAME = "ExampleNotificationJob";
|
|
39
|
+
|
|
40
|
+
// For mongo-jobs, you'll implement HandlerInterface<ExampleNotificationData["Job"]>
|
|
41
|
+
// For background-jobs-postgres, you'll implement Handler<ExampleNotificationData["Job"]>
|
|
42
|
+
export class ExampleNotificationJob implements BaseHandler<ExampleNotificationData["Job"]> {
|
|
43
|
+
public name = EXAMPLE_NOTIFICATION_JOB_NAME;
|
|
98
44
|
|
|
99
|
-
export class ExampleNotificationJob implements BaseHandler<ExampleNotificationJobData> {
|
|
100
45
|
constructor(private readonly service: ExampleNotificationService) {}
|
|
101
46
|
|
|
102
|
-
async perform(data:
|
|
47
|
+
async perform(data: ExampleNotificationData["Job"], job: { attemptsCount: number }) {
|
|
103
48
|
const result = await this.service.sendNotification({
|
|
104
49
|
...data,
|
|
105
50
|
// Include the job's attempts count for debugging, this is called `retryAttempts` in `background-jobs-postgres`.
|
|
@@ -113,18 +58,59 @@ npm install @clipboard-health/notifications
|
|
|
113
58
|
}
|
|
114
59
|
```
|
|
115
60
|
|
|
116
|
-
|
|
61
|
+
1. Search your service for a constant that stores workflow keys. If there isn't one, create and export it:
|
|
62
|
+
|
|
63
|
+
```ts
|
|
64
|
+
export const WORKFLOW_KEYS = {
|
|
65
|
+
eventStartingReminder: "event-starting-reminder",
|
|
66
|
+
} as const;
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
1. Enqueue your job:
|
|
70
|
+
|
|
71
|
+
```ts
|
|
72
|
+
import {
|
|
73
|
+
EXAMPLE_NOTIFICATION_JOB_NAME,
|
|
74
|
+
type ExampleNotificationData,
|
|
75
|
+
} from "./exampleNotification.job";
|
|
76
|
+
import { notificationJobEnqueuer } from "./notificationJobEnqueuer";
|
|
77
|
+
import { WORKFLOW_KEYS } from "./workflowKeys";
|
|
78
|
+
|
|
79
|
+
async function enqueueNotificationJob() {
|
|
80
|
+
await notificationJobEnqueuer.enqueueOneOrMore<ExampleNotificationData["Enqueue"]>(
|
|
81
|
+
EXAMPLE_NOTIFICATION_JOB_NAME,
|
|
82
|
+
// Important: Read the TypeDoc documentation for additional context.
|
|
83
|
+
{
|
|
84
|
+
// Set expiresAt at enqueue-time so it remains stable across job retries.
|
|
85
|
+
// Use date-fns in your service instead of this manual calculation.
|
|
86
|
+
expiresAt: new Date(Date.now() + 60 * 60_000).toISOString(),
|
|
87
|
+
// Set idempotencyKey at enqueue-time so it remains stable across job retries.
|
|
88
|
+
idempotencyKey: {
|
|
89
|
+
resourceId: "event-123",
|
|
90
|
+
},
|
|
91
|
+
// Set recipients at enqueue-time so they respect our notification provider's limits.
|
|
92
|
+
recipients: ["userId-1"],
|
|
93
|
+
|
|
94
|
+
workflowKey: WORKFLOW_KEYS.eventStartingReminder,
|
|
117
95
|
|
|
118
|
-
|
|
96
|
+
// Any additional enqueue-time data passed to the job:
|
|
97
|
+
workplaceId: "workplaceId-123",
|
|
98
|
+
},
|
|
99
|
+
);
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
// eslint-disable-next-line unicorn/prefer-top-level-await
|
|
103
|
+
void enqueueNotificationJob();
|
|
104
|
+
```
|
|
119
105
|
|
|
120
|
-
|
|
106
|
+
1. Trigger the job in your NestJS service:
|
|
121
107
|
|
|
122
108
|
```ts
|
|
123
109
|
import { type NotificationClient } from "@clipboard-health/notifications";
|
|
124
110
|
|
|
125
|
-
import { type
|
|
111
|
+
import { type ExampleNotificationData } from "./exampleNotification.job";
|
|
126
112
|
|
|
127
|
-
type ExampleNotificationDo =
|
|
113
|
+
type ExampleNotificationDo = ExampleNotificationData["Job"] & { attempt: number };
|
|
128
114
|
|
|
129
115
|
export class ExampleNotificationService {
|
|
130
116
|
constructor(private readonly client: NotificationClient) {}
|
|
@@ -132,19 +118,20 @@ npm install @clipboard-health/notifications
|
|
|
132
118
|
async sendNotification(params: ExampleNotificationDo) {
|
|
133
119
|
const { attempt, expiresAt, idempotencyKey, recipients, workflowKey, workplaceId } = params;
|
|
134
120
|
|
|
135
|
-
// Assume this comes from a database and
|
|
136
|
-
|
|
121
|
+
// Assume this comes from a database and are used as template variables...
|
|
122
|
+
// Use @clipboard-health/date-time's formatShortDateTime in your service for consistency.
|
|
123
|
+
const data = { favoriteColor: "blue", favoriteAt: new Date().toISOString(), secret: "2" };
|
|
137
124
|
|
|
125
|
+
// Important: Read the TypeDoc documentation for additional context.
|
|
138
126
|
return await this.client.trigger({
|
|
139
127
|
attempt,
|
|
140
128
|
body: {
|
|
141
|
-
recipients,
|
|
142
129
|
data,
|
|
130
|
+
recipients,
|
|
143
131
|
workplaceId,
|
|
144
132
|
},
|
|
145
133
|
expiresAt: new Date(expiresAt),
|
|
146
134
|
idempotencyKey,
|
|
147
|
-
key: workflowKey,
|
|
148
135
|
keysToRedact: ["secret"],
|
|
149
136
|
workflowKey,
|
|
150
137
|
});
|
|
@@ -152,7 +139,7 @@ npm install @clipboard-health/notifications
|
|
|
152
139
|
}
|
|
153
140
|
```
|
|
154
141
|
|
|
155
|
-
|
|
142
|
+
</embedex>
|
|
156
143
|
|
|
157
144
|
## Local development commands
|
|
158
145
|
|
package/package.json
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@clipboard-health/notifications",
|
|
3
3
|
"description": "Send notifications through third-party providers.",
|
|
4
|
-
"version": "1.2.
|
|
4
|
+
"version": "1.2.3",
|
|
5
5
|
"bugs": "https://github.com/ClipboardHealth/core-utils/issues",
|
|
6
6
|
"dependencies": {
|
|
7
|
-
"@clipboard-health/background-jobs-adapter": "0.5.
|
|
7
|
+
"@clipboard-health/background-jobs-adapter": "0.5.2",
|
|
8
8
|
"@clipboard-health/phone-number": "0.9.1",
|
|
9
9
|
"@clipboard-health/util-ts": "3.18.1",
|
|
10
10
|
"@knocklabs/node": "1.20.0",
|
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
},
|
|
13
13
|
"devDependencies": {
|
|
14
14
|
"@clipboard-health/testing-core": "0.27.1",
|
|
15
|
-
"type-fest": "5.0
|
|
15
|
+
"type-fest": "5.1.0"
|
|
16
16
|
},
|
|
17
17
|
"keywords": [],
|
|
18
18
|
"license": "MIT",
|
|
@@ -44,9 +44,9 @@ export declare class NotificationClient {
|
|
|
44
44
|
* ```ts
|
|
45
45
|
* import { type NotificationClient } from "@clipboard-health/notifications";
|
|
46
46
|
*
|
|
47
|
-
* import { type
|
|
47
|
+
* import { type ExampleNotificationData } from "./exampleNotification.job";
|
|
48
48
|
*
|
|
49
|
-
* type ExampleNotificationDo =
|
|
49
|
+
* type ExampleNotificationDo = ExampleNotificationData["Job"] & { attempt: number };
|
|
50
50
|
*
|
|
51
51
|
* export class ExampleNotificationService {
|
|
52
52
|
* constructor(private readonly client: NotificationClient) {}
|
|
@@ -54,19 +54,20 @@ export declare class NotificationClient {
|
|
|
54
54
|
* async sendNotification(params: ExampleNotificationDo) {
|
|
55
55
|
* const { attempt, expiresAt, idempotencyKey, recipients, workflowKey, workplaceId } = params;
|
|
56
56
|
*
|
|
57
|
-
* // Assume this comes from a database and
|
|
58
|
-
*
|
|
57
|
+
* // Assume this comes from a database and are used as template variables...
|
|
58
|
+
* // Use @clipboard-health/date-time's formatShortDateTime in your service for consistency.
|
|
59
|
+
* const data = { favoriteColor: "blue", favoriteAt: new Date().toISOString(), secret: "2" };
|
|
59
60
|
*
|
|
61
|
+
* // Important: Read the TypeDoc documentation for additional context.
|
|
60
62
|
* return await this.client.trigger({
|
|
61
63
|
* attempt,
|
|
62
64
|
* body: {
|
|
63
|
-
* recipients,
|
|
64
65
|
* data,
|
|
66
|
+
* recipients,
|
|
65
67
|
* workplaceId,
|
|
66
68
|
* },
|
|
67
69
|
* expiresAt: new Date(expiresAt),
|
|
68
70
|
* idempotencyKey,
|
|
69
|
-
* key: workflowKey,
|
|
70
71
|
* keysToRedact: ["secret"],
|
|
71
72
|
* workflowKey,
|
|
72
73
|
* });
|
|
@@ -79,9 +79,9 @@ class NotificationClient {
|
|
|
79
79
|
* ```ts
|
|
80
80
|
* import { type NotificationClient } from "@clipboard-health/notifications";
|
|
81
81
|
*
|
|
82
|
-
* import { type
|
|
82
|
+
* import { type ExampleNotificationData } from "./exampleNotification.job";
|
|
83
83
|
*
|
|
84
|
-
* type ExampleNotificationDo =
|
|
84
|
+
* type ExampleNotificationDo = ExampleNotificationData["Job"] & { attempt: number };
|
|
85
85
|
*
|
|
86
86
|
* export class ExampleNotificationService {
|
|
87
87
|
* constructor(private readonly client: NotificationClient) {}
|
|
@@ -89,19 +89,20 @@ class NotificationClient {
|
|
|
89
89
|
* async sendNotification(params: ExampleNotificationDo) {
|
|
90
90
|
* const { attempt, expiresAt, idempotencyKey, recipients, workflowKey, workplaceId } = params;
|
|
91
91
|
*
|
|
92
|
-
* // Assume this comes from a database and
|
|
93
|
-
*
|
|
92
|
+
* // Assume this comes from a database and are used as template variables...
|
|
93
|
+
* // Use @clipboard-health/date-time's formatShortDateTime in your service for consistency.
|
|
94
|
+
* const data = { favoriteColor: "blue", favoriteAt: new Date().toISOString(), secret: "2" };
|
|
94
95
|
*
|
|
96
|
+
* // Important: Read the TypeDoc documentation for additional context.
|
|
95
97
|
* return await this.client.trigger({
|
|
96
98
|
* attempt,
|
|
97
99
|
* body: {
|
|
98
|
-
* recipients,
|
|
99
100
|
* data,
|
|
101
|
+
* recipients,
|
|
100
102
|
* workplaceId,
|
|
101
103
|
* },
|
|
102
104
|
* expiresAt: new Date(expiresAt),
|
|
103
105
|
* idempotencyKey,
|
|
104
|
-
* key: workflowKey,
|
|
105
106
|
* keysToRedact: ["secret"],
|
|
106
107
|
* workflowKey,
|
|
107
108
|
* });
|
|
@@ -1 +1 @@
|
|
|
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;AACzD,oGAAiG;AAiBjG,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,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,IAAI,CAAC,UAAU,GAAG,UAAU,CAAC;QAC7B,IAAI,CAAC,QAAQ;YACX,UAAU,IAAI,MAAM;gBAClB,CAAC,CAAC,4DAA4D;oBAC5D,MAAM,CAAC,QAAQ;gBACjB,CAAC,CAAC,4DAA4D;oBAC5D,IAAI,iCAAe,CAAC,EAAE,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,EAAE,CAAC,CAAC;IAC/D,CAAC;IAED
|
|
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;AACzD,oGAAiG;AAiBjG,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,4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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;AAtYD,gDAsYC"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { type BackgroundJobsAdapter, type MongoEnqueueOptions, type PostgresEnqueueOptions } 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 {
|
|
@@ -79,11 +79,14 @@ export interface NotificationData<T> {
|
|
|
79
79
|
/**
|
|
80
80
|
* `enqueueOneOrMore` sets `idempotencyKey`/`unique` automatically, so it's not accepted here.
|
|
81
81
|
*
|
|
82
|
-
* `startAt`
|
|
83
|
-
*
|
|
84
|
-
*
|
|
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.
|
|
85
88
|
*/
|
|
86
|
-
export type EnqueueOneOrMoreOptions = Pick<MongoEnqueueOptions, "session"> | Pick<PostgresEnqueueOptions, "transaction"
|
|
89
|
+
export type EnqueueOneOrMoreOptions = Pick<EnqueueOptions, "startAt"> & (Pick<MongoEnqueueOptions, "session" | "startAt"> | Pick<PostgresEnqueueOptions, "transaction" | "startAt">);
|
|
87
90
|
interface NotificationJobEnqueuerParams {
|
|
88
91
|
adapter: BackgroundJobsAdapter;
|
|
89
92
|
}
|
|
@@ -122,38 +125,37 @@ export declare class NotificationJobEnqueuer {
|
|
|
122
125
|
*
|
|
123
126
|
* ```ts
|
|
124
127
|
* import {
|
|
125
|
-
*
|
|
126
|
-
*
|
|
128
|
+
* EXAMPLE_NOTIFICATION_JOB_NAME,
|
|
129
|
+
* type ExampleNotificationData,
|
|
127
130
|
* } from "./exampleNotification.job";
|
|
128
131
|
* import { notificationJobEnqueuer } from "./notificationJobEnqueuer";
|
|
132
|
+
* import { WORKFLOW_KEYS } from "./workflowKeys";
|
|
129
133
|
*
|
|
130
134
|
* async function enqueueNotificationJob() {
|
|
131
|
-
* await notificationJobEnqueuer.enqueueOneOrMore<
|
|
132
|
-
*
|
|
135
|
+
* await notificationJobEnqueuer.enqueueOneOrMore<ExampleNotificationData["Enqueue"]>(
|
|
136
|
+
* EXAMPLE_NOTIFICATION_JOB_NAME,
|
|
137
|
+
* // Important: Read the TypeDoc documentation for additional context.
|
|
133
138
|
* {
|
|
134
139
|
* // Set expiresAt at enqueue-time so it remains stable across job retries.
|
|
135
|
-
*
|
|
140
|
+
* // Use date-fns in your service instead of this manual calculation.
|
|
141
|
+
* expiresAt: new Date(Date.now() + 60 * 60_000).toISOString(),
|
|
136
142
|
* // Set idempotencyKey at enqueue-time so it remains stable across job retries.
|
|
137
143
|
* idempotencyKey: {
|
|
138
144
|
* resourceId: "event-123",
|
|
139
145
|
* },
|
|
140
146
|
* // Set recipients at enqueue-time so they respect our notification provider's limits.
|
|
141
|
-
* recipients: ["
|
|
147
|
+
* recipients: ["userId-1"],
|
|
142
148
|
*
|
|
143
|
-
* workflowKey:
|
|
149
|
+
* workflowKey: WORKFLOW_KEYS.eventStartingReminder,
|
|
144
150
|
*
|
|
145
151
|
* // Any additional enqueue-time data passed to the job:
|
|
146
|
-
* workplaceId: "
|
|
152
|
+
* workplaceId: "workplaceId-123",
|
|
147
153
|
* },
|
|
148
154
|
* );
|
|
149
155
|
* }
|
|
150
156
|
*
|
|
151
157
|
* // eslint-disable-next-line unicorn/prefer-top-level-await
|
|
152
158
|
* void enqueueNotificationJob();
|
|
153
|
-
*
|
|
154
|
-
* function minutesFromNow(minutes: number) {
|
|
155
|
-
* return new Date(Date.now() + minutes * 60_000);
|
|
156
|
-
* }
|
|
157
159
|
* ```
|
|
158
160
|
*
|
|
159
161
|
* </embedex>
|
|
@@ -43,38 +43,37 @@ class NotificationJobEnqueuer {
|
|
|
43
43
|
*
|
|
44
44
|
* ```ts
|
|
45
45
|
* import {
|
|
46
|
-
*
|
|
47
|
-
*
|
|
46
|
+
* EXAMPLE_NOTIFICATION_JOB_NAME,
|
|
47
|
+
* type ExampleNotificationData,
|
|
48
48
|
* } from "./exampleNotification.job";
|
|
49
49
|
* import { notificationJobEnqueuer } from "./notificationJobEnqueuer";
|
|
50
|
+
* import { WORKFLOW_KEYS } from "./workflowKeys";
|
|
50
51
|
*
|
|
51
52
|
* async function enqueueNotificationJob() {
|
|
52
|
-
* await notificationJobEnqueuer.enqueueOneOrMore<
|
|
53
|
-
*
|
|
53
|
+
* await notificationJobEnqueuer.enqueueOneOrMore<ExampleNotificationData["Enqueue"]>(
|
|
54
|
+
* EXAMPLE_NOTIFICATION_JOB_NAME,
|
|
55
|
+
* // Important: Read the TypeDoc documentation for additional context.
|
|
54
56
|
* {
|
|
55
57
|
* // Set expiresAt at enqueue-time so it remains stable across job retries.
|
|
56
|
-
*
|
|
58
|
+
* // Use date-fns in your service instead of this manual calculation.
|
|
59
|
+
* expiresAt: new Date(Date.now() + 60 * 60_000).toISOString(),
|
|
57
60
|
* // Set idempotencyKey at enqueue-time so it remains stable across job retries.
|
|
58
61
|
* idempotencyKey: {
|
|
59
62
|
* resourceId: "event-123",
|
|
60
63
|
* },
|
|
61
64
|
* // Set recipients at enqueue-time so they respect our notification provider's limits.
|
|
62
|
-
* recipients: ["
|
|
65
|
+
* recipients: ["userId-1"],
|
|
63
66
|
*
|
|
64
|
-
* workflowKey:
|
|
67
|
+
* workflowKey: WORKFLOW_KEYS.eventStartingReminder,
|
|
65
68
|
*
|
|
66
69
|
* // Any additional enqueue-time data passed to the job:
|
|
67
|
-
* workplaceId: "
|
|
70
|
+
* workplaceId: "workplaceId-123",
|
|
68
71
|
* },
|
|
69
72
|
* );
|
|
70
73
|
* }
|
|
71
74
|
*
|
|
72
75
|
* // eslint-disable-next-line unicorn/prefer-top-level-await
|
|
73
76
|
* void enqueueNotificationJob();
|
|
74
|
-
*
|
|
75
|
-
* function minutesFromNow(minutes: number) {
|
|
76
|
-
* return new Date(Date.now() + minutes * 60_000);
|
|
77
|
-
* }
|
|
78
77
|
* ```
|
|
79
78
|
*
|
|
80
79
|
* </embedex>
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"notificationJobEnqueuer.js","sourceRoot":"","sources":["../../../../../packages/notifications/src/lib/notificationJobEnqueuer.ts"],"names":[],"mappings":";;;AAAA,
|
|
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,OAAO,EAAE,GAAG,MAAM,CAAC;QAE3B,IAAI,CAAC,OAAO,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