@venturekit/notify 0.0.0-dev.20260507015349
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/LICENSE +191 -0
- package/README.md +304 -0
- package/dist/admin/index.d.ts +88 -0
- package/dist/admin/index.d.ts.map +1 -0
- package/dist/admin/index.js +105 -0
- package/dist/admin/index.js.map +1 -0
- package/dist/bounce-handler.d.ts +65 -0
- package/dist/bounce-handler.d.ts.map +1 -0
- package/dist/bounce-handler.js +171 -0
- package/dist/bounce-handler.js.map +1 -0
- package/dist/client.d.ts +113 -0
- package/dist/client.d.ts.map +1 -0
- package/dist/client.js +213 -0
- package/dist/client.js.map +1 -0
- package/dist/dispatcher.d.ts +95 -0
- package/dist/dispatcher.d.ts.map +1 -0
- package/dist/dispatcher.js +251 -0
- package/dist/dispatcher.js.map +1 -0
- package/dist/index.d.ts +60 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +66 -0
- package/dist/index.js.map +1 -0
- package/dist/providers/email-noop.d.ts +30 -0
- package/dist/providers/email-noop.d.ts.map +1 -0
- package/dist/providers/email-noop.js +39 -0
- package/dist/providers/email-noop.js.map +1 -0
- package/dist/providers/email-ses.d.ts +39 -0
- package/dist/providers/email-ses.d.ts.map +1 -0
- package/dist/providers/email-ses.js +114 -0
- package/dist/providers/email-ses.js.map +1 -0
- package/dist/providers/index.d.ts +20 -0
- package/dist/providers/index.d.ts.map +1 -0
- package/dist/providers/index.js +20 -0
- package/dist/providers/index.js.map +1 -0
- package/dist/providers/push-noop.d.ts +12 -0
- package/dist/providers/push-noop.d.ts.map +1 -0
- package/dist/providers/push-noop.js +30 -0
- package/dist/providers/push-noop.js.map +1 -0
- package/dist/providers/sms-noop.d.ts +21 -0
- package/dist/providers/sms-noop.d.ts.map +1 -0
- package/dist/providers/sms-noop.js +42 -0
- package/dist/providers/sms-noop.js.map +1 -0
- package/dist/providers/types.d.ts +95 -0
- package/dist/providers/types.d.ts.map +1 -0
- package/dist/providers/types.js +40 -0
- package/dist/providers/types.js.map +1 -0
- package/dist/providers/whatsapp-meta.d.ts +63 -0
- package/dist/providers/whatsapp-meta.d.ts.map +1 -0
- package/dist/providers/whatsapp-meta.js +160 -0
- package/dist/providers/whatsapp-meta.js.map +1 -0
- package/dist/store/index.d.ts +6 -0
- package/dist/store/index.d.ts.map +1 -0
- package/dist/store/index.js +5 -0
- package/dist/store/index.js.map +1 -0
- package/dist/store/postgres.d.ts +36 -0
- package/dist/store/postgres.d.ts.map +1 -0
- package/dist/store/postgres.js +354 -0
- package/dist/store/postgres.js.map +1 -0
- package/dist/store/types.d.ts +139 -0
- package/dist/store/types.d.ts.map +1 -0
- package/dist/store/types.js +14 -0
- package/dist/store/types.js.map +1 -0
- package/dist/templates/registry.d.ts +55 -0
- package/dist/templates/registry.d.ts.map +1 -0
- package/dist/templates/registry.js +94 -0
- package/dist/templates/registry.js.map +1 -0
- package/dist/types.d.ts +214 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +12 -0
- package/dist/types.js.map +1 -0
- package/migrations/vk_notify_001_init.sql +109 -0
- package/package.json +109 -0
- package/runtime/bounce-handler-stub.ts +35 -0
- package/runtime/dispatcher-stub.ts +63 -0
- package/runtime/tsconfig.json +19 -0
package/dist/index.js
ADDED
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @venturekit/notify
|
|
3
|
+
*
|
|
4
|
+
* Transactional notifications for VentureKit applications. The shape:
|
|
5
|
+
*
|
|
6
|
+
* ```ts
|
|
7
|
+
* import {
|
|
8
|
+
* createNotifyClient, createPostgresNotifyStore,
|
|
9
|
+
* createSesEmailProvider, createMetaWhatsAppProvider,
|
|
10
|
+
* createSecretsTokenResolver,
|
|
11
|
+
* } from '@venturekit/notify';
|
|
12
|
+
*
|
|
13
|
+
* export const notify = createNotifyClient({
|
|
14
|
+
* store: createPostgresNotifyStore(),
|
|
15
|
+
* defaultFrom: process.env.VENTURE_NOTIFY_FROM,
|
|
16
|
+
* providers: [
|
|
17
|
+
* createSesEmailProvider({ region: process.env.AWS_REGION! }),
|
|
18
|
+
* createMetaWhatsAppProvider({
|
|
19
|
+
* phoneNumberId: process.env.VENTURE_NOTIFY_WHATSAPP_PHONE_ID!,
|
|
20
|
+
* tokenResolver: createSecretsTokenResolver({
|
|
21
|
+
* secretArn: process.env.VENTURE_NOTIFY_WHATSAPP_TOKEN_SECRET!,
|
|
22
|
+
* }),
|
|
23
|
+
* }),
|
|
24
|
+
* ],
|
|
25
|
+
* addressResolver: async (userId, channel) => {
|
|
26
|
+
* const user = await usersRepo.findById(userId);
|
|
27
|
+
* if (channel === 'email') return user?.email ?? null;
|
|
28
|
+
* if (channel === 'whatsapp') return user?.whatsappNumber ?? null;
|
|
29
|
+
* return null;
|
|
30
|
+
* },
|
|
31
|
+
* });
|
|
32
|
+
*
|
|
33
|
+
* notify.registerTemplate({
|
|
34
|
+
* key: 'application_registered',
|
|
35
|
+
* channel: 'email',
|
|
36
|
+
* category: 'transactional_application',
|
|
37
|
+
* render: ({ groupName }) => ({
|
|
38
|
+
* subject: `Inscription confirmée: ${groupName}`,
|
|
39
|
+
* text: `Votre inscription au groupe ${groupName} est confirmée.`,
|
|
40
|
+
* html: `<p>Votre inscription au groupe <b>${groupName}</b> est confirmée.</p>`,
|
|
41
|
+
* }),
|
|
42
|
+
* });
|
|
43
|
+
*
|
|
44
|
+
* await notify.enqueue({
|
|
45
|
+
* recipientUserId: 'usr_123',
|
|
46
|
+
* channel: 'email',
|
|
47
|
+
* templateKey: 'application_registered',
|
|
48
|
+
* payload: { groupName: 'Île-de-France #4' },
|
|
49
|
+
* });
|
|
50
|
+
* ```
|
|
51
|
+
*/
|
|
52
|
+
// Client ------------------------------------------------------------
|
|
53
|
+
export { createNotifyClient, } from './client.js';
|
|
54
|
+
// Templates ---------------------------------------------------------
|
|
55
|
+
export { createTemplateRegistry, TemplateNotFoundError, } from './templates/registry.js';
|
|
56
|
+
// Store -------------------------------------------------------------
|
|
57
|
+
export { createPostgresNotifyStore, } from './store/index.js';
|
|
58
|
+
// Providers ---------------------------------------------------------
|
|
59
|
+
export { ProviderHardError, ProviderSendError, createSesEmailProvider, __resetSesClientForTests, createMetaWhatsAppProvider, createSecretsTokenResolver, createSmsNoopProvider, createPushNoopProvider, createEmailNoopProvider, } from './providers/index.js';
|
|
60
|
+
// Dispatcher --------------------------------------------------------
|
|
61
|
+
export { dispatchOnce, makeDispatchHandler, } from './dispatcher.js';
|
|
62
|
+
// Bounce handler ----------------------------------------------------
|
|
63
|
+
export { makeBounceHandler, } from './bounce-handler.js';
|
|
64
|
+
// Admin -------------------------------------------------------------
|
|
65
|
+
export { adminListNotifications, adminGetNotification, adminSendNotification, adminRetryNotification, adminCancelNotification, adminClearSuppression, listUserPreferences, upsertUserPreference, listNotificationsForUser, } from './admin/index.js';
|
|
66
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkDG;AAgBH,sEAAsE;AACtE,OAAO,EACL,kBAAkB,GAInB,MAAM,aAAa,CAAC;AAErB,sEAAsE;AACtE,OAAO,EACL,sBAAsB,EACtB,qBAAqB,GAEtB,MAAM,yBAAyB,CAAC;AAEjC,sEAAsE;AACtE,OAAO,EACL,yBAAyB,GAO1B,MAAM,kBAAkB,CAAC;AAE1B,sEAAsE;AACtE,OAAO,EACL,iBAAiB,EACjB,iBAAiB,EAIjB,sBAAsB,EAEtB,wBAAwB,EACxB,0BAA0B,EAC1B,0BAA0B,EAE1B,qBAAqB,EACrB,sBAAsB,EACtB,uBAAuB,GAExB,MAAM,sBAAsB,CAAC;AAE9B,sEAAsE;AACtE,OAAO,EACL,YAAY,EACZ,mBAAmB,GAIpB,MAAM,iBAAiB,CAAC;AAEzB,sEAAsE;AACtE,OAAO,EACL,iBAAiB,GAElB,MAAM,qBAAqB,CAAC;AAE7B,sEAAsE;AACtE,OAAO,EACL,sBAAsB,EACtB,oBAAoB,EACpB,qBAAqB,EACrB,sBAAsB,EACtB,uBAAuB,EACvB,qBAAqB,EACrB,mBAAmB,EACnB,oBAAoB,EACpB,wBAAwB,GAGzB,MAAM,kBAAkB,CAAC"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @venturekit/notify — Email no-op provider (local dev / fallback)
|
|
3
|
+
*
|
|
4
|
+
* Used in two situations:
|
|
5
|
+
*
|
|
6
|
+
* - **Local dev** — when `VENTURE_LOCAL=true`, the runtime client picks
|
|
7
|
+
* this provider over SES so cognito-local + a blank AWS account never
|
|
8
|
+
* block the create-user path. The email is logged with full body so
|
|
9
|
+
* operators can grep CloudWatch / their dev terminal.
|
|
10
|
+
* - **MAIL_DRIVER=noop** — explicit opt-in for environments where SES
|
|
11
|
+
* isn't available (sandbox, demo deploy with no verified domain).
|
|
12
|
+
*/
|
|
13
|
+
import type { NotifyProvider } from './types.js';
|
|
14
|
+
export interface EmailNoopOptions {
|
|
15
|
+
/**
|
|
16
|
+
* Optional sink override — defaults to `console.info`. Lets tests
|
|
17
|
+
* inject a buffer they can assert against without monkey-patching
|
|
18
|
+
* `console`.
|
|
19
|
+
*/
|
|
20
|
+
sink?: (entry: {
|
|
21
|
+
notificationId: string;
|
|
22
|
+
to: string;
|
|
23
|
+
from: string;
|
|
24
|
+
subject?: string;
|
|
25
|
+
text: string;
|
|
26
|
+
html?: string;
|
|
27
|
+
}) => void;
|
|
28
|
+
}
|
|
29
|
+
export declare function createEmailNoopProvider(opts?: EmailNoopOptions): NotifyProvider;
|
|
30
|
+
//# sourceMappingURL=email-noop.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"email-noop.d.ts","sourceRoot":"","sources":["../../src/providers/email-noop.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,OAAO,KAAK,EACV,cAAc,EAGf,MAAM,YAAY,CAAC;AAEpB,MAAM,WAAW,gBAAgB;IAC/B;;;;OAIG;IACH,IAAI,CAAC,EAAE,CAAC,KAAK,EAAE;QACb,cAAc,EAAE,MAAM,CAAC;QACvB,EAAE,EAAE,MAAM,CAAC;QACX,IAAI,EAAE,MAAM,CAAC;QACb,OAAO,CAAC,EAAE,MAAM,CAAC;QACjB,IAAI,EAAE,MAAM,CAAC;QACb,IAAI,CAAC,EAAE,MAAM,CAAC;KACf,KAAK,IAAI,CAAC;CACZ;AAED,wBAAgB,uBAAuB,CACrC,IAAI,GAAE,gBAAqB,GAC1B,cAAc,CA6BhB"}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @venturekit/notify — Email no-op provider (local dev / fallback)
|
|
3
|
+
*
|
|
4
|
+
* Used in two situations:
|
|
5
|
+
*
|
|
6
|
+
* - **Local dev** — when `VENTURE_LOCAL=true`, the runtime client picks
|
|
7
|
+
* this provider over SES so cognito-local + a blank AWS account never
|
|
8
|
+
* block the create-user path. The email is logged with full body so
|
|
9
|
+
* operators can grep CloudWatch / their dev terminal.
|
|
10
|
+
* - **MAIL_DRIVER=noop** — explicit opt-in for environments where SES
|
|
11
|
+
* isn't available (sandbox, demo deploy with no verified domain).
|
|
12
|
+
*/
|
|
13
|
+
export function createEmailNoopProvider(opts = {}) {
|
|
14
|
+
const sink = opts.sink ??
|
|
15
|
+
((entry) => {
|
|
16
|
+
// eslint-disable-next-line no-console
|
|
17
|
+
console.info('[notify:email-noop]', entry);
|
|
18
|
+
});
|
|
19
|
+
return {
|
|
20
|
+
channel: 'email',
|
|
21
|
+
name: 'noop-email',
|
|
22
|
+
async send(request) {
|
|
23
|
+
sink({
|
|
24
|
+
notificationId: request.notificationId,
|
|
25
|
+
to: request.to,
|
|
26
|
+
from: request.from,
|
|
27
|
+
subject: request.message.subject,
|
|
28
|
+
text: request.message.text,
|
|
29
|
+
html: request.message.html,
|
|
30
|
+
});
|
|
31
|
+
return {
|
|
32
|
+
providerMessageId: `noop-email-${request.notificationId}`,
|
|
33
|
+
acceptedAtMs: Date.now(),
|
|
34
|
+
channel: 'email',
|
|
35
|
+
};
|
|
36
|
+
},
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
//# sourceMappingURL=email-noop.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"email-noop.js","sourceRoot":"","sources":["../../src/providers/email-noop.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAwBH,MAAM,UAAU,uBAAuB,CACrC,OAAyB,EAAE;IAE3B,MAAM,IAAI,GACR,IAAI,CAAC,IAAI;QACT,CAAC,CAAC,KAAK,EAAE,EAAE;YACT,sCAAsC;YACtC,OAAO,CAAC,IAAI,CAAC,qBAAqB,EAAE,KAAK,CAAC,CAAC;QAC7C,CAAC,CAAC,CAAC;IAEL,OAAO;QACL,OAAO,EAAE,OAAO;QAChB,IAAI,EAAE,YAAY;QAElB,KAAK,CAAC,IAAI,CAAC,OAA4B;YACrC,IAAI,CAAC;gBACH,cAAc,EAAE,OAAO,CAAC,cAAc;gBACtC,EAAE,EAAE,OAAO,CAAC,EAAE;gBACd,IAAI,EAAE,OAAO,CAAC,IAAI;gBAClB,OAAO,EAAE,OAAO,CAAC,OAAO,CAAC,OAAO;gBAChC,IAAI,EAAE,OAAO,CAAC,OAAO,CAAC,IAAI;gBAC1B,IAAI,EAAE,OAAO,CAAC,OAAO,CAAC,IAAI;aAC3B,CAAC,CAAC;YAEH,OAAO;gBACL,iBAAiB,EAAE,cAAc,OAAO,CAAC,cAAc,EAAE;gBACzD,YAAY,EAAE,IAAI,CAAC,GAAG,EAAE;gBACxB,OAAO,EAAE,OAAO;aACjB,CAAC;QACJ,CAAC;KACF,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @venturekit/notify — SESv2 email provider
|
|
3
|
+
*
|
|
4
|
+
* Uses `@aws-sdk/client-sesv2` (lazy-imported) so projects that disable
|
|
5
|
+
* the email channel never pay the SDK's bundle cost. Authentication
|
|
6
|
+
* piggy-backs on the Lambda execution role — `ses:SendEmail` is
|
|
7
|
+
* granted to the shared role by `createNotify()` in `@venturekit/infra`.
|
|
8
|
+
*
|
|
9
|
+
* Configuration-set wiring is required for the bounce/complaint flow
|
|
10
|
+
* (see `bounce-handler.ts`): the SES configuration set is created at
|
|
11
|
+
* deploy time and pointed at an SNS topic that this package's bounce
|
|
12
|
+
* handler subscribes to. Skipping the configuration set is supported
|
|
13
|
+
* but disables the bounce-suppression list.
|
|
14
|
+
*/
|
|
15
|
+
import { type NotifyProvider } from './types.js';
|
|
16
|
+
/** Construction options for {@link createSesEmailProvider}. */
|
|
17
|
+
export interface SesEmailProviderConfig {
|
|
18
|
+
/** AWS region (e.g. `'eu-west-1'`). */
|
|
19
|
+
region: string;
|
|
20
|
+
/**
|
|
21
|
+
* SES configuration set to attach to every send. When omitted, the
|
|
22
|
+
* provider sends without a configuration set — bounce / complaint
|
|
23
|
+
* events still arrive at SES's per-account notifications topic but
|
|
24
|
+
* the bounce handler can't auto-subscribe.
|
|
25
|
+
*/
|
|
26
|
+
configurationSetName?: string;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Reset the memoized client. Tests-only — the SDK constructor is cheap
|
|
30
|
+
* to call repeatedly but Lambdas keep one client per warm container in
|
|
31
|
+
* production for connection reuse.
|
|
32
|
+
*/
|
|
33
|
+
export declare function __resetSesClientForTests(): void;
|
|
34
|
+
/**
|
|
35
|
+
* Create the SES email provider. The returned object is stateless apart
|
|
36
|
+
* from the memoized SDK client — safe to share across handlers.
|
|
37
|
+
*/
|
|
38
|
+
export declare function createSesEmailProvider(config: SesEmailProviderConfig): NotifyProvider;
|
|
39
|
+
//# sourceMappingURL=email-ses.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"email-ses.d.ts","sourceRoot":"","sources":["../../src/providers/email-ses.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAEH,OAAO,EAGL,KAAK,cAAc,EAGpB,MAAM,YAAY,CAAC;AAEpB,+DAA+D;AAC/D,MAAM,WAAW,sBAAsB;IACrC,uCAAuC;IACvC,MAAM,EAAE,MAAM,CAAC;IACf;;;;;OAKG;IACH,oBAAoB,CAAC,EAAE,MAAM,CAAC;CAC/B;AA+BD;;;;GAIG;AACH,wBAAgB,wBAAwB,IAAI,IAAI,CAE/C;AAED;;;GAGG;AACH,wBAAgB,sBAAsB,CACpC,MAAM,EAAE,sBAAsB,GAC7B,cAAc,CAkFhB"}
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @venturekit/notify — SESv2 email provider
|
|
3
|
+
*
|
|
4
|
+
* Uses `@aws-sdk/client-sesv2` (lazy-imported) so projects that disable
|
|
5
|
+
* the email channel never pay the SDK's bundle cost. Authentication
|
|
6
|
+
* piggy-backs on the Lambda execution role — `ses:SendEmail` is
|
|
7
|
+
* granted to the shared role by `createNotify()` in `@venturekit/infra`.
|
|
8
|
+
*
|
|
9
|
+
* Configuration-set wiring is required for the bounce/complaint flow
|
|
10
|
+
* (see `bounce-handler.ts`): the SES configuration set is created at
|
|
11
|
+
* deploy time and pointed at an SNS topic that this package's bounce
|
|
12
|
+
* handler subscribes to. Skipping the configuration set is supported
|
|
13
|
+
* but disables the bounce-suppression list.
|
|
14
|
+
*/
|
|
15
|
+
import { ProviderHardError, ProviderSendError, } from './types.js';
|
|
16
|
+
/**
|
|
17
|
+
* Lazily-loaded SESv2 client. We avoid a top-level import so projects
|
|
18
|
+
* that don't enable email don't pay the SDK cost on cold start.
|
|
19
|
+
*/
|
|
20
|
+
let cachedClient = null;
|
|
21
|
+
async function getClient(region) {
|
|
22
|
+
// Lazy import — pinned via package.json peer dependency.
|
|
23
|
+
const sdk = (await import('@aws-sdk/client-sesv2'));
|
|
24
|
+
if (!cachedClient) {
|
|
25
|
+
cachedClient = new sdk.SESv2Client({ region });
|
|
26
|
+
}
|
|
27
|
+
return {
|
|
28
|
+
client: cachedClient,
|
|
29
|
+
SendEmailCommand: sdk.SendEmailCommand,
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Reset the memoized client. Tests-only — the SDK constructor is cheap
|
|
34
|
+
* to call repeatedly but Lambdas keep one client per warm container in
|
|
35
|
+
* production for connection reuse.
|
|
36
|
+
*/
|
|
37
|
+
export function __resetSesClientForTests() {
|
|
38
|
+
cachedClient = null;
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Create the SES email provider. The returned object is stateless apart
|
|
42
|
+
* from the memoized SDK client — safe to share across handlers.
|
|
43
|
+
*/
|
|
44
|
+
export function createSesEmailProvider(config) {
|
|
45
|
+
return {
|
|
46
|
+
channel: 'email',
|
|
47
|
+
name: 'ses',
|
|
48
|
+
async send(request) {
|
|
49
|
+
const { client, SendEmailCommand } = await getClient(config.region);
|
|
50
|
+
const { to, from, message, notificationId } = request;
|
|
51
|
+
// SES requires a non-empty body. We always populate `text`
|
|
52
|
+
// because the dispatcher rejects rendered messages without one
|
|
53
|
+
// upstream — this branch is defensive only.
|
|
54
|
+
if (!message.text || message.text.length === 0) {
|
|
55
|
+
throw new ProviderHardError('SES send rejected: rendered message has no text body');
|
|
56
|
+
}
|
|
57
|
+
const input = {
|
|
58
|
+
FromEmailAddress: from,
|
|
59
|
+
Destination: { ToAddresses: [to] },
|
|
60
|
+
Content: {
|
|
61
|
+
Simple: {
|
|
62
|
+
Subject: { Data: message.subject ?? '', Charset: 'UTF-8' },
|
|
63
|
+
Body: {
|
|
64
|
+
Text: { Data: message.text, Charset: 'UTF-8' },
|
|
65
|
+
...(message.html
|
|
66
|
+
? { Html: { Data: message.html, Charset: 'UTF-8' } }
|
|
67
|
+
: {}),
|
|
68
|
+
},
|
|
69
|
+
},
|
|
70
|
+
},
|
|
71
|
+
// Tag the send with the outbox row id so bounce / complaint
|
|
72
|
+
// events arriving via SNS can be correlated without an extra
|
|
73
|
+
// lookup. SES Tags are <= 50 chars and [A-Za-z0-9_-] only —
|
|
74
|
+
// outbox ids are `notif_<22-char-base32>` so they fit.
|
|
75
|
+
EmailTags: [
|
|
76
|
+
{ Name: 'venturekit_notification_id', Value: notificationId },
|
|
77
|
+
],
|
|
78
|
+
...(request.configurationSetName ?? config.configurationSetName
|
|
79
|
+
? {
|
|
80
|
+
ConfigurationSetName: request.configurationSetName ?? config.configurationSetName,
|
|
81
|
+
}
|
|
82
|
+
: {}),
|
|
83
|
+
};
|
|
84
|
+
try {
|
|
85
|
+
const result = await client.send(new SendEmailCommand(input));
|
|
86
|
+
return {
|
|
87
|
+
providerMessageId: result.MessageId ?? `ses-${Date.now()}`,
|
|
88
|
+
acceptedAtMs: Date.now(),
|
|
89
|
+
channel: 'email',
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
catch (err) {
|
|
93
|
+
// SES throws structured errors; surface the name so the
|
|
94
|
+
// dispatcher can decide on retry vs hard-fail. Specifically:
|
|
95
|
+
// - `MessageRejected` — hard (verification failure)
|
|
96
|
+
// - `MailFromDomainNotVerified` — hard
|
|
97
|
+
// - `AccountSuspendedException` — hard
|
|
98
|
+
// - `Throttling` / 5xx — transient
|
|
99
|
+
const errAny = err;
|
|
100
|
+
const name = errAny.name ?? 'UnknownError';
|
|
101
|
+
const hard = name === 'MessageRejected' ||
|
|
102
|
+
name === 'MailFromDomainNotVerified' ||
|
|
103
|
+
name === 'MailFromDomainNotVerifiedException' ||
|
|
104
|
+
name === 'AccountSuspendedException' ||
|
|
105
|
+
name === 'BadRequestException';
|
|
106
|
+
if (hard) {
|
|
107
|
+
throw new ProviderHardError(`SES SendEmail failed permanently (${name}): ${errAny.message ?? ''}`, err);
|
|
108
|
+
}
|
|
109
|
+
throw new ProviderSendError(`SES SendEmail failed (${name}): ${errAny.message ?? ''}`, err);
|
|
110
|
+
}
|
|
111
|
+
},
|
|
112
|
+
};
|
|
113
|
+
}
|
|
114
|
+
//# sourceMappingURL=email-ses.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"email-ses.js","sourceRoot":"","sources":["../../src/providers/email-ses.ts"],"names":[],"mappings":"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"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @venturekit/notify — provider barrel
|
|
3
|
+
*
|
|
4
|
+
* Re-exports all provider factories and the shared interface so
|
|
5
|
+
* consumers can import either:
|
|
6
|
+
*
|
|
7
|
+
* import { createSesEmailProvider } from '@venturekit/notify';
|
|
8
|
+
* // ↑ via the package barrel — recommended.
|
|
9
|
+
*
|
|
10
|
+
* import { createSesEmailProvider } from '@venturekit/notify/providers/email-ses';
|
|
11
|
+
* // ↑ direct subpath — useful when bundling and you want
|
|
12
|
+
* // precise tree-shaking control.
|
|
13
|
+
*/
|
|
14
|
+
export { ProviderHardError, ProviderSendError, type NotifyProvider, type ProviderSendRequest, type ProviderSendResult, } from './types.js';
|
|
15
|
+
export { createSesEmailProvider, type SesEmailProviderConfig, __resetSesClientForTests, } from './email-ses.js';
|
|
16
|
+
export { createMetaWhatsAppProvider, createSecretsTokenResolver, type MetaWhatsAppProviderConfig, } from './whatsapp-meta.js';
|
|
17
|
+
export { createSmsNoopProvider } from './sms-noop.js';
|
|
18
|
+
export { createPushNoopProvider } from './push-noop.js';
|
|
19
|
+
export { createEmailNoopProvider, type EmailNoopOptions } from './email-noop.js';
|
|
20
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/providers/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,OAAO,EACL,iBAAiB,EACjB,iBAAiB,EACjB,KAAK,cAAc,EACnB,KAAK,mBAAmB,EACxB,KAAK,kBAAkB,GACxB,MAAM,YAAY,CAAC;AAEpB,OAAO,EACL,sBAAsB,EACtB,KAAK,sBAAsB,EAC3B,wBAAwB,GACzB,MAAM,gBAAgB,CAAC;AAExB,OAAO,EACL,0BAA0B,EAC1B,0BAA0B,EAC1B,KAAK,0BAA0B,GAChC,MAAM,oBAAoB,CAAC;AAE5B,OAAO,EAAE,qBAAqB,EAAE,MAAM,eAAe,CAAC;AACtD,OAAO,EAAE,sBAAsB,EAAE,MAAM,gBAAgB,CAAC;AACxD,OAAO,EAAE,uBAAuB,EAAE,KAAK,gBAAgB,EAAE,MAAM,iBAAiB,CAAC"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @venturekit/notify — provider barrel
|
|
3
|
+
*
|
|
4
|
+
* Re-exports all provider factories and the shared interface so
|
|
5
|
+
* consumers can import either:
|
|
6
|
+
*
|
|
7
|
+
* import { createSesEmailProvider } from '@venturekit/notify';
|
|
8
|
+
* // ↑ via the package barrel — recommended.
|
|
9
|
+
*
|
|
10
|
+
* import { createSesEmailProvider } from '@venturekit/notify/providers/email-ses';
|
|
11
|
+
* // ↑ direct subpath — useful when bundling and you want
|
|
12
|
+
* // precise tree-shaking control.
|
|
13
|
+
*/
|
|
14
|
+
export { ProviderHardError, ProviderSendError, } from './types.js';
|
|
15
|
+
export { createSesEmailProvider, __resetSesClientForTests, } from './email-ses.js';
|
|
16
|
+
export { createMetaWhatsAppProvider, createSecretsTokenResolver, } from './whatsapp-meta.js';
|
|
17
|
+
export { createSmsNoopProvider } from './sms-noop.js';
|
|
18
|
+
export { createPushNoopProvider } from './push-noop.js';
|
|
19
|
+
export { createEmailNoopProvider } from './email-noop.js';
|
|
20
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/providers/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,OAAO,EACL,iBAAiB,EACjB,iBAAiB,GAIlB,MAAM,YAAY,CAAC;AAEpB,OAAO,EACL,sBAAsB,EAEtB,wBAAwB,GACzB,MAAM,gBAAgB,CAAC;AAExB,OAAO,EACL,0BAA0B,EAC1B,0BAA0B,GAE3B,MAAM,oBAAoB,CAAC;AAE5B,OAAO,EAAE,qBAAqB,EAAE,MAAM,eAAe,CAAC;AACtD,OAAO,EAAE,sBAAsB,EAAE,MAAM,gBAAgB,CAAC;AACxD,OAAO,EAAE,uBAAuB,EAAyB,MAAM,iBAAiB,CAAC"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @venturekit/notify — Push no-op provider (placeholder)
|
|
3
|
+
*
|
|
4
|
+
* Phase 1 ships no real push provider. The expected real implementation
|
|
5
|
+
* is AWS SNS Mobile Push (APNS / FCM via Platform Applications), but
|
|
6
|
+
* platform application ARNs and device-token registration are
|
|
7
|
+
* application concerns that vary heavily between consumers — so the
|
|
8
|
+
* default is a no-op and the consumer wires a real provider when ready.
|
|
9
|
+
*/
|
|
10
|
+
import type { NotifyProvider } from './types.js';
|
|
11
|
+
export declare function createPushNoopProvider(): NotifyProvider;
|
|
12
|
+
//# sourceMappingURL=push-noop.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"push-noop.d.ts","sourceRoot":"","sources":["../../src/providers/push-noop.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,KAAK,EACV,cAAc,EAGf,MAAM,YAAY,CAAC;AAEpB,wBAAgB,sBAAsB,IAAI,cAAc,CAqBvD"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @venturekit/notify — Push no-op provider (placeholder)
|
|
3
|
+
*
|
|
4
|
+
* Phase 1 ships no real push provider. The expected real implementation
|
|
5
|
+
* is AWS SNS Mobile Push (APNS / FCM via Platform Applications), but
|
|
6
|
+
* platform application ARNs and device-token registration are
|
|
7
|
+
* application concerns that vary heavily between consumers — so the
|
|
8
|
+
* default is a no-op and the consumer wires a real provider when ready.
|
|
9
|
+
*/
|
|
10
|
+
export function createPushNoopProvider() {
|
|
11
|
+
return {
|
|
12
|
+
channel: 'push',
|
|
13
|
+
name: 'noop-push',
|
|
14
|
+
async send(request) {
|
|
15
|
+
// eslint-disable-next-line no-console
|
|
16
|
+
console.info('[notify:push-noop]', {
|
|
17
|
+
notificationId: request.notificationId,
|
|
18
|
+
endpoint: request.to,
|
|
19
|
+
subject: request.message.subject,
|
|
20
|
+
bodyPreview: request.message.text.slice(0, 200),
|
|
21
|
+
});
|
|
22
|
+
return {
|
|
23
|
+
providerMessageId: `noop-push-${request.notificationId}`,
|
|
24
|
+
acceptedAtMs: Date.now(),
|
|
25
|
+
channel: 'push',
|
|
26
|
+
};
|
|
27
|
+
},
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
//# sourceMappingURL=push-noop.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"push-noop.js","sourceRoot":"","sources":["../../src/providers/push-noop.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAQH,MAAM,UAAU,sBAAsB;IACpC,OAAO;QACL,OAAO,EAAE,MAAM;QACf,IAAI,EAAE,WAAW;QAEjB,KAAK,CAAC,IAAI,CAAC,OAA4B;YACrC,sCAAsC;YACtC,OAAO,CAAC,IAAI,CAAC,oBAAoB,EAAE;gBACjC,cAAc,EAAE,OAAO,CAAC,cAAc;gBACtC,QAAQ,EAAE,OAAO,CAAC,EAAE;gBACpB,OAAO,EAAE,OAAO,CAAC,OAAO,CAAC,OAAO;gBAChC,WAAW,EAAE,OAAO,CAAC,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,EAAE,GAAG,CAAC;aAChD,CAAC,CAAC;YAEH,OAAO;gBACL,iBAAiB,EAAE,aAAa,OAAO,CAAC,cAAc,EAAE;gBACxD,YAAY,EAAE,IAAI,CAAC,GAAG,EAAE;gBACxB,OAAO,EAAE,MAAM;aAChB,CAAC;QACJ,CAAC;KACF,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @venturekit/notify — SMS no-op provider (placeholder)
|
|
3
|
+
*
|
|
4
|
+
* Phase 1 deliberately ships no real SMS provider. Declaring `'sms'` in
|
|
5
|
+
* `NotifyIntent.channels` only resolves to this placeholder — sends are
|
|
6
|
+
* accepted, logged, and recorded as `'sent'` so the outbox flow exercises
|
|
7
|
+
* end-to-end, but no real SMS leaves the system.
|
|
8
|
+
*
|
|
9
|
+
* Replace this with a real provider (AWS End User Messaging SMS, Twilio,
|
|
10
|
+
* Pinpoint v2, …) by registering a different provider for the `'sms'`
|
|
11
|
+
* channel via `client.registerProvider()` at app boot. The dispatcher
|
|
12
|
+
* uses whichever provider is registered last for a given channel.
|
|
13
|
+
*/
|
|
14
|
+
import type { NotifyProvider } from './types.js';
|
|
15
|
+
/**
|
|
16
|
+
* Create the SMS no-op provider. Logs the intent at INFO level via
|
|
17
|
+
* `console.info` so operators can grep CloudWatch for what would have
|
|
18
|
+
* been sent.
|
|
19
|
+
*/
|
|
20
|
+
export declare function createSmsNoopProvider(): NotifyProvider;
|
|
21
|
+
//# sourceMappingURL=sms-noop.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sms-noop.d.ts","sourceRoot":"","sources":["../../src/providers/sms-noop.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,OAAO,KAAK,EACV,cAAc,EAGf,MAAM,YAAY,CAAC;AAEpB;;;;GAIG;AACH,wBAAgB,qBAAqB,IAAI,cAAc,CAwBtD"}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @venturekit/notify — SMS no-op provider (placeholder)
|
|
3
|
+
*
|
|
4
|
+
* Phase 1 deliberately ships no real SMS provider. Declaring `'sms'` in
|
|
5
|
+
* `NotifyIntent.channels` only resolves to this placeholder — sends are
|
|
6
|
+
* accepted, logged, and recorded as `'sent'` so the outbox flow exercises
|
|
7
|
+
* end-to-end, but no real SMS leaves the system.
|
|
8
|
+
*
|
|
9
|
+
* Replace this with a real provider (AWS End User Messaging SMS, Twilio,
|
|
10
|
+
* Pinpoint v2, …) by registering a different provider for the `'sms'`
|
|
11
|
+
* channel via `client.registerProvider()` at app boot. The dispatcher
|
|
12
|
+
* uses whichever provider is registered last for a given channel.
|
|
13
|
+
*/
|
|
14
|
+
/**
|
|
15
|
+
* Create the SMS no-op provider. Logs the intent at INFO level via
|
|
16
|
+
* `console.info` so operators can grep CloudWatch for what would have
|
|
17
|
+
* been sent.
|
|
18
|
+
*/
|
|
19
|
+
export function createSmsNoopProvider() {
|
|
20
|
+
return {
|
|
21
|
+
channel: 'sms',
|
|
22
|
+
name: 'noop-sms',
|
|
23
|
+
async send(request) {
|
|
24
|
+
// Visibility for development & paper trail in production. Body
|
|
25
|
+
// is clipped to 160 chars to keep log lines bounded — full body
|
|
26
|
+
// remains in the outbox row.
|
|
27
|
+
// eslint-disable-next-line no-console
|
|
28
|
+
console.info('[notify:sms-noop]', {
|
|
29
|
+
notificationId: request.notificationId,
|
|
30
|
+
to: request.to,
|
|
31
|
+
from: request.from,
|
|
32
|
+
bodyPreview: request.message.text.slice(0, 160),
|
|
33
|
+
});
|
|
34
|
+
return {
|
|
35
|
+
providerMessageId: `noop-sms-${request.notificationId}`,
|
|
36
|
+
acceptedAtMs: Date.now(),
|
|
37
|
+
channel: 'sms',
|
|
38
|
+
};
|
|
39
|
+
},
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
//# sourceMappingURL=sms-noop.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sms-noop.js","sourceRoot":"","sources":["../../src/providers/sms-noop.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAQH;;;;GAIG;AACH,MAAM,UAAU,qBAAqB;IACnC,OAAO;QACL,OAAO,EAAE,KAAK;QACd,IAAI,EAAE,UAAU;QAEhB,KAAK,CAAC,IAAI,CAAC,OAA4B;YACrC,+DAA+D;YAC/D,gEAAgE;YAChE,6BAA6B;YAC7B,sCAAsC;YACtC,OAAO,CAAC,IAAI,CAAC,mBAAmB,EAAE;gBAChC,cAAc,EAAE,OAAO,CAAC,cAAc;gBACtC,EAAE,EAAE,OAAO,CAAC,EAAE;gBACd,IAAI,EAAE,OAAO,CAAC,IAAI;gBAClB,WAAW,EAAE,OAAO,CAAC,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,EAAE,GAAG,CAAC;aAChD,CAAC,CAAC;YAEH,OAAO;gBACL,iBAAiB,EAAE,YAAY,OAAO,CAAC,cAAc,EAAE;gBACvD,YAAY,EAAE,IAAI,CAAC,GAAG,EAAE;gBACxB,OAAO,EAAE,KAAK;aACf,CAAC;QACJ,CAAC;KACF,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @venturekit/notify — provider interface
|
|
3
|
+
*
|
|
4
|
+
* A `NotifyProvider` is the thin layer between the dispatcher and the
|
|
5
|
+
* underlying messaging service (SESv2, Meta Graph API, …). Providers are
|
|
6
|
+
* stateless and lazy — the AWS / HTTP clients they wrap are only
|
|
7
|
+
* constructed on the first send.
|
|
8
|
+
*
|
|
9
|
+
* The interface intentionally accepts a {@link RenderedMessage} rather
|
|
10
|
+
* than a template + payload: rendering is a separate concern owned by
|
|
11
|
+
* the template registry, so providers stay focused on transport
|
|
12
|
+
* mechanics (auth, retries, message-id parsing).
|
|
13
|
+
*/
|
|
14
|
+
import type { NotifyChannel, RenderedMessage } from '../types.js';
|
|
15
|
+
/** Single send request the dispatcher hands to a provider. */
|
|
16
|
+
export interface ProviderSendRequest {
|
|
17
|
+
/** Channel-specific destination address (email / phone / device). */
|
|
18
|
+
to: string;
|
|
19
|
+
/**
|
|
20
|
+
* Sender address. For email this is the SES-verified `From`; for
|
|
21
|
+
* WhatsApp it's the Meta phone number id (which the provider already
|
|
22
|
+
* has via config — passed here only so noop providers can echo it
|
|
23
|
+
* back in their fake receipt).
|
|
24
|
+
*/
|
|
25
|
+
from: string;
|
|
26
|
+
/** Already-rendered message. */
|
|
27
|
+
message: RenderedMessage;
|
|
28
|
+
/**
|
|
29
|
+
* Outbox row id (`notif_…`). Threaded into provider headers when
|
|
30
|
+
* supported (SES `Notify-Id` tag, Meta custom data) so bounce /
|
|
31
|
+
* complaint events can be correlated back to the originating row
|
|
32
|
+
* without an extra DB lookup.
|
|
33
|
+
*/
|
|
34
|
+
notificationId: string;
|
|
35
|
+
/**
|
|
36
|
+
* SES configuration set name to attach to the send. Producers
|
|
37
|
+
* outside SES ignore this field. The dispatcher passes it through
|
|
38
|
+
* from `NotifyIntent.configurationSetName`.
|
|
39
|
+
*/
|
|
40
|
+
configurationSetName?: string;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Result returned by every provider on a successful send. Failures
|
|
44
|
+
* throw — the dispatcher catches and converts to a `'failed'` outbox
|
|
45
|
+
* row with the error message preserved.
|
|
46
|
+
*/
|
|
47
|
+
export interface ProviderSendResult {
|
|
48
|
+
/** Provider-side message id (SES `MessageId`, Meta `wamid`, …). */
|
|
49
|
+
providerMessageId: string;
|
|
50
|
+
/** When the provider accepted the request (Date.now()). */
|
|
51
|
+
acceptedAtMs: number;
|
|
52
|
+
/** Channel echoed back so loggers can include it without a closure. */
|
|
53
|
+
channel: NotifyChannel;
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Provider abstraction over a single channel. The dispatcher resolves
|
|
57
|
+
* one provider per declared channel at boot time and reuses it across
|
|
58
|
+
* outbox rows in the same batch.
|
|
59
|
+
*
|
|
60
|
+
* Implementations should:
|
|
61
|
+
* - Lazy-init their underlying SDK client (avoid cold-start cost when
|
|
62
|
+
* the provider isn't actually used in this Lambda invocation).
|
|
63
|
+
* - Throw a `ProviderSendError` on transient failures so the
|
|
64
|
+
* dispatcher can mark the row `'pending'` again with a retry.
|
|
65
|
+
* - Throw a `ProviderHardError` on permanent failures so the
|
|
66
|
+
* dispatcher marks the row `'failed'` immediately and skips retries.
|
|
67
|
+
*/
|
|
68
|
+
export interface NotifyProvider {
|
|
69
|
+
/** Channel this provider implements. */
|
|
70
|
+
channel: NotifyChannel;
|
|
71
|
+
/** Human-readable provider name for logs (`'ses'`, `'meta-cloud'`,
|
|
72
|
+
* `'noop-sms'`). */
|
|
73
|
+
name: string;
|
|
74
|
+
/** Send a single rendered message. */
|
|
75
|
+
send(request: ProviderSendRequest): Promise<ProviderSendResult>;
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Transient error — the dispatcher will leave the row `'pending'` and
|
|
79
|
+
* retry on the next cron tick (subject to `maxAttempts`).
|
|
80
|
+
*/
|
|
81
|
+
export declare class ProviderSendError extends Error {
|
|
82
|
+
cause?: unknown;
|
|
83
|
+
constructor(message: string, cause?: unknown);
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* Permanent error — the dispatcher will mark the row `'failed'` and
|
|
87
|
+
* never retry. Use for malformed input, authentication problems, or
|
|
88
|
+
* provider 4xx responses indicating the request is structurally
|
|
89
|
+
* wrong.
|
|
90
|
+
*/
|
|
91
|
+
export declare class ProviderHardError extends Error {
|
|
92
|
+
cause?: unknown;
|
|
93
|
+
constructor(message: string, cause?: unknown);
|
|
94
|
+
}
|
|
95
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/providers/types.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,OAAO,KAAK,EAAE,aAAa,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAElE,8DAA8D;AAC9D,MAAM,WAAW,mBAAmB;IAClC,qEAAqE;IACrE,EAAE,EAAE,MAAM,CAAC;IACX;;;;;OAKG;IACH,IAAI,EAAE,MAAM,CAAC;IACb,gCAAgC;IAChC,OAAO,EAAE,eAAe,CAAC;IACzB;;;;;OAKG;IACH,cAAc,EAAE,MAAM,CAAC;IACvB;;;;OAIG;IACH,oBAAoB,CAAC,EAAE,MAAM,CAAC;CAC/B;AAED;;;;GAIG;AACH,MAAM,WAAW,kBAAkB;IACjC,mEAAmE;IACnE,iBAAiB,EAAE,MAAM,CAAC;IAC1B,2DAA2D;IAC3D,YAAY,EAAE,MAAM,CAAC;IACrB,uEAAuE;IACvE,OAAO,EAAE,aAAa,CAAC;CACxB;AAED;;;;;;;;;;;;GAYG;AACH,MAAM,WAAW,cAAc;IAC7B,wCAAwC;IACxC,OAAO,EAAE,aAAa,CAAC;IACvB;yBACqB;IACrB,IAAI,EAAE,MAAM,CAAC;IACb,sCAAsC;IACtC,IAAI,CAAC,OAAO,EAAE,mBAAmB,GAAG,OAAO,CAAC,kBAAkB,CAAC,CAAC;CACjE;AAED;;;GAGG;AACH,qBAAa,iBAAkB,SAAQ,KAAK;IAC1C,KAAK,CAAC,EAAE,OAAO,CAAC;gBACJ,OAAO,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,OAAO;CAK7C;AAED;;;;;GAKG;AACH,qBAAa,iBAAkB,SAAQ,KAAK;IAC1C,KAAK,CAAC,EAAE,OAAO,CAAC;gBACJ,OAAO,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,OAAO;CAK7C"}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @venturekit/notify — provider interface
|
|
3
|
+
*
|
|
4
|
+
* A `NotifyProvider` is the thin layer between the dispatcher and the
|
|
5
|
+
* underlying messaging service (SESv2, Meta Graph API, …). Providers are
|
|
6
|
+
* stateless and lazy — the AWS / HTTP clients they wrap are only
|
|
7
|
+
* constructed on the first send.
|
|
8
|
+
*
|
|
9
|
+
* The interface intentionally accepts a {@link RenderedMessage} rather
|
|
10
|
+
* than a template + payload: rendering is a separate concern owned by
|
|
11
|
+
* the template registry, so providers stay focused on transport
|
|
12
|
+
* mechanics (auth, retries, message-id parsing).
|
|
13
|
+
*/
|
|
14
|
+
/**
|
|
15
|
+
* Transient error — the dispatcher will leave the row `'pending'` and
|
|
16
|
+
* retry on the next cron tick (subject to `maxAttempts`).
|
|
17
|
+
*/
|
|
18
|
+
export class ProviderSendError extends Error {
|
|
19
|
+
cause;
|
|
20
|
+
constructor(message, cause) {
|
|
21
|
+
super(message);
|
|
22
|
+
this.name = 'ProviderSendError';
|
|
23
|
+
this.cause = cause;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Permanent error — the dispatcher will mark the row `'failed'` and
|
|
28
|
+
* never retry. Use for malformed input, authentication problems, or
|
|
29
|
+
* provider 4xx responses indicating the request is structurally
|
|
30
|
+
* wrong.
|
|
31
|
+
*/
|
|
32
|
+
export class ProviderHardError extends Error {
|
|
33
|
+
cause;
|
|
34
|
+
constructor(message, cause) {
|
|
35
|
+
super(message);
|
|
36
|
+
this.name = 'ProviderHardError';
|
|
37
|
+
this.cause = cause;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
//# sourceMappingURL=types.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/providers/types.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAqEH;;;GAGG;AACH,MAAM,OAAO,iBAAkB,SAAQ,KAAK;IAC1C,KAAK,CAAW;IAChB,YAAY,OAAe,EAAE,KAAe;QAC1C,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,mBAAmB,CAAC;QAChC,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;IACrB,CAAC;CACF;AAED;;;;;GAKG;AACH,MAAM,OAAO,iBAAkB,SAAQ,KAAK;IAC1C,KAAK,CAAW;IAChB,YAAY,OAAe,EAAE,KAAe;QAC1C,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,mBAAmB,CAAC;QAChC,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;IACrB,CAAC;CACF"}
|