@venturekit/notify 0.0.32 → 0.0.33
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/dist/admin/index.d.ts +1 -2
- package/dist/admin/index.d.ts.map +1 -1
- package/dist/policy/channel-chain.d.ts +106 -0
- package/dist/policy/channel-chain.d.ts.map +1 -0
- package/dist/policy/channel-chain.js +70 -0
- package/dist/policy/channel-chain.js.map +1 -0
- package/dist/policy/index.d.ts +16 -0
- package/dist/policy/index.d.ts.map +1 -0
- package/dist/policy/index.js +16 -0
- package/dist/policy/index.js.map +1 -0
- package/dist/policy/quiet-hours.d.ts +52 -0
- package/dist/policy/quiet-hours.d.ts.map +1 -0
- package/dist/policy/quiet-hours.js +95 -0
- package/dist/policy/quiet-hours.js.map +1 -0
- package/dist/policy/string-templates.d.ts +92 -0
- package/dist/policy/string-templates.d.ts.map +1 -0
- package/dist/policy/string-templates.js +96 -0
- package/dist/policy/string-templates.js.map +1 -0
- package/dist/providers/email-mailhog.d.ts.map +1 -1
- package/dist/providers/email-mailhog.js +0 -4
- package/dist/providers/email-mailhog.js.map +1 -1
- package/dist/providers/index.d.ts +1 -0
- package/dist/providers/index.d.ts.map +1 -1
- package/dist/providers/index.js +1 -0
- package/dist/providers/index.js.map +1 -1
- package/dist/providers/push-expo.d.ts +145 -0
- package/dist/providers/push-expo.d.ts.map +1 -0
- package/dist/providers/push-expo.js +206 -0
- package/dist/providers/push-expo.js.map +1 -0
- package/package.json +14 -6
package/dist/admin/index.d.ts
CHANGED
|
@@ -48,8 +48,7 @@ export interface AdminListResult {
|
|
|
48
48
|
*/
|
|
49
49
|
export declare function adminListNotifications(client: NotifyClient, options?: AdminListOptions): Promise<AdminListResult>;
|
|
50
50
|
export declare function adminGetNotification(client: NotifyClient, id: string): Promise<NotificationRow | null>;
|
|
51
|
-
export
|
|
52
|
-
}
|
|
51
|
+
export type AdminSendInput = EnqueueInput;
|
|
53
52
|
/**
|
|
54
53
|
* Admin-driven send. Equivalent to `client.enqueue(...)` — exposed as a
|
|
55
54
|
* named admin helper so route handlers can audit-log the operator who
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/admin/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;AAEH,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AACjD,OAAO,KAAK,EACV,gBAAgB,EAChB,kBAAkB,EACnB,MAAM,mBAAmB,CAAC;AAC3B,OAAO,KAAK,EACV,YAAY,EACZ,yBAAyB,EACzB,eAAe,EACf,aAAa,EACd,MAAM,aAAa,CAAC;AAIrB,MAAM,WAAW,eAAe;IAC9B,IAAI,EAAE,eAAe,EAAE,CAAC;IACxB,KAAK,EAAE,MAAM,CAAC;IACd,gEAAgE;IAChE,KAAK,EAAE,MAAM,CAAC;IACd,wBAAwB;IACxB,MAAM,EAAE,MAAM,CAAC;CAChB;AAED;;;;GAIG;AACH,wBAAsB,sBAAsB,CAC1C,MAAM,EAAE,YAAY,EACpB,OAAO,GAAE,gBAAqB,GAC7B,OAAO,CAAC,eAAe,CAAC,CAQ1B;AAID,wBAAsB,oBAAoB,CACxC,MAAM,EAAE,YAAY,EACpB,EAAE,EAAE,MAAM,GACT,OAAO,CAAC,eAAe,GAAG,IAAI,CAAC,CAEjC;AAID,MAAM,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/admin/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;AAEH,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AACjD,OAAO,KAAK,EACV,gBAAgB,EAChB,kBAAkB,EACnB,MAAM,mBAAmB,CAAC;AAC3B,OAAO,KAAK,EACV,YAAY,EACZ,yBAAyB,EACzB,eAAe,EACf,aAAa,EACd,MAAM,aAAa,CAAC;AAIrB,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9D,wBAAsB,oBAAoB,CACxC,MAAM,EAAE,YAAY,EACpB,KAAK,EAAE,IAAI,CAAC,yBAAyB,EAAE,cAAc,CAAC,GACrD,OAAO,CAAC,yBAAyB,CAAC,CAEpC;AAID;;;GAGG;AACH,wBAAsB,wBAAwB,CAC5C,MAAM,EAAE,YAAY,EACpB,MAAM,EAAE,MAAM,EACd,OAAO,GAAE,kBAAuB,GAC/B,OAAO,CAAC,eAAe,EAAE,CAAC,CAE5B"}
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @venturekit/notify — channel fallback chains.
|
|
3
|
+
*
|
|
4
|
+
* `NotificationPreferenceRow` answers "may I use this channel for this
|
|
5
|
+
* category". It does not answer the question that comes first: *which* channels,
|
|
6
|
+
* in what order, and what happens when the preferred one cannot be used. A
|
|
7
|
+
* consumer with push, WhatsApp, SMS and e-mail has to decide that per message,
|
|
8
|
+
* and the shape of the decision is the same everywhere even though the answer
|
|
9
|
+
* never is.
|
|
10
|
+
*
|
|
11
|
+
* So the mechanism is here and the policy is not. This module will not tell you
|
|
12
|
+
* that push comes before e-mail — that depends on what your product is, what
|
|
13
|
+
* your channels cost, and what your regulator says. It will make an ordered,
|
|
14
|
+
* reachability-filtered chain out of the order *you* declare, and give the
|
|
15
|
+
* fallback position a name.
|
|
16
|
+
*/
|
|
17
|
+
import type { NotifyChannel } from '../types.js';
|
|
18
|
+
/** What the recipient can actually be reached on. */
|
|
19
|
+
export interface ChannelReachability {
|
|
20
|
+
/**
|
|
21
|
+
* `true` when a channel has a usable address for this recipient: a live push
|
|
22
|
+
* subscription, a phone number, a verified e-mail. A channel that is absent
|
|
23
|
+
* from the map counts as unreachable — the safe reading, since the failure of
|
|
24
|
+
* forgetting to declare one is a message sent nowhere rather than a message
|
|
25
|
+
* sent twice.
|
|
26
|
+
*/
|
|
27
|
+
[channel: string]: boolean | undefined;
|
|
28
|
+
}
|
|
29
|
+
export interface ChannelChainOptions {
|
|
30
|
+
/**
|
|
31
|
+
* Channels in preference order, best first. Yours to choose: this package has
|
|
32
|
+
* no opinion on whether a push beats an e-mail.
|
|
33
|
+
*/
|
|
34
|
+
order: readonly NotifyChannel[];
|
|
35
|
+
/** What the recipient can be reached on. */
|
|
36
|
+
reachable: ChannelReachability;
|
|
37
|
+
/**
|
|
38
|
+
* Used when nothing in `order` is reachable. An in-app or inbox channel is the
|
|
39
|
+
* usual answer, because a message that reached nobody should still be
|
|
40
|
+
* *recorded* — "we never had a way to contact them" and "we never tried" look
|
|
41
|
+
* identical in a support conversation otherwise.
|
|
42
|
+
*/
|
|
43
|
+
fallback?: NotifyChannel;
|
|
44
|
+
/**
|
|
45
|
+
* Channels to drop regardless of reachability — an opt-out, an entitlement the
|
|
46
|
+
* tenant does not hold, a channel disabled for this message class.
|
|
47
|
+
*/
|
|
48
|
+
exclude?: readonly NotifyChannel[];
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* The channels to attempt, in order.
|
|
52
|
+
*
|
|
53
|
+
* Filtering happens before ordering is applied, so a chain never contains a
|
|
54
|
+
* channel the recipient cannot receive on. Duplicates in `order` collapse.
|
|
55
|
+
*
|
|
56
|
+
* @example
|
|
57
|
+
* ```ts
|
|
58
|
+
* buildChannelChain({
|
|
59
|
+
* order: ['push', 'whatsapp', 'email'],
|
|
60
|
+
* reachable: { push: hasDevice, whatsapp: Boolean(phone), email: Boolean(email) },
|
|
61
|
+
* exclude: optedOutChannels,
|
|
62
|
+
* fallback: 'in_app',
|
|
63
|
+
* });
|
|
64
|
+
* ```
|
|
65
|
+
*/
|
|
66
|
+
export declare function buildChannelChain(options: ChannelChainOptions): NotifyChannel[];
|
|
67
|
+
/** What {@link nextChannel} decided. */
|
|
68
|
+
export type ChainStep = {
|
|
69
|
+
action: 'attempt';
|
|
70
|
+
channel: NotifyChannel;
|
|
71
|
+
remaining: NotifyChannel[];
|
|
72
|
+
} | {
|
|
73
|
+
action: 'hold';
|
|
74
|
+
channel: NotifyChannel;
|
|
75
|
+
until: Date;
|
|
76
|
+
remaining: NotifyChannel[];
|
|
77
|
+
} | {
|
|
78
|
+
action: 'exhausted';
|
|
79
|
+
};
|
|
80
|
+
export interface NextChannelOptions {
|
|
81
|
+
/** The chain from {@link buildChannelChain}. */
|
|
82
|
+
chain: readonly NotifyChannel[];
|
|
83
|
+
/** Channels already attempted for this message. */
|
|
84
|
+
attempted?: readonly NotifyChannel[];
|
|
85
|
+
/**
|
|
86
|
+
* Channels that must not be attempted until a deadline has passed without the
|
|
87
|
+
* recipient responding — a paid or intrusive channel kept as a true fallback.
|
|
88
|
+
* The value is when to release it.
|
|
89
|
+
*
|
|
90
|
+
* This is the pattern behind "try the free channel, and only pay if nobody
|
|
91
|
+
* answered": the expensive channel is enqueued *held*, and released by a
|
|
92
|
+
* scheduled pass if nothing was acknowledged. Holding it rather than deciding
|
|
93
|
+
* later is deliberate — the decision to escalate was made when the message was
|
|
94
|
+
* created, and re-deciding at release time means re-loading facts that have
|
|
95
|
+
* since changed.
|
|
96
|
+
*/
|
|
97
|
+
deferUntil?: Partial<Record<NotifyChannel, Date>>;
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* The next channel to act on, and how.
|
|
101
|
+
*
|
|
102
|
+
* Returns `hold` rather than `attempt` for a channel in `deferUntil`, so the
|
|
103
|
+
* caller enqueues it with a release time instead of sending it now.
|
|
104
|
+
*/
|
|
105
|
+
export declare function nextChannel(options: NextChannelOptions): ChainStep;
|
|
106
|
+
//# sourceMappingURL=channel-chain.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"channel-chain.d.ts","sourceRoot":"","sources":["../../src/policy/channel-chain.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAEH,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAEjD,qDAAqD;AACrD,MAAM,WAAW,mBAAmB;IAClC;;;;;;OAMG;IACH,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,GAAG,SAAS,CAAC;CACxC;AAED,MAAM,WAAW,mBAAmB;IAClC;;;OAGG;IACH,KAAK,EAAE,SAAS,aAAa,EAAE,CAAC;IAChC,4CAA4C;IAC5C,SAAS,EAAE,mBAAmB,CAAC;IAC/B;;;;;OAKG;IACH,QAAQ,CAAC,EAAE,aAAa,CAAC;IACzB;;;OAGG;IACH,OAAO,CAAC,EAAE,SAAS,aAAa,EAAE,CAAC;CACpC;AAED;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,iBAAiB,CAAC,OAAO,EAAE,mBAAmB,GAAG,aAAa,EAAE,CAiB/E;AAED,wCAAwC;AACxC,MAAM,MAAM,SAAS,GACjB;IAAE,MAAM,EAAE,SAAS,CAAC;IAAC,OAAO,EAAE,aAAa,CAAC;IAAC,SAAS,EAAE,aAAa,EAAE,CAAA;CAAE,GACzE;IAAE,MAAM,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,aAAa,CAAC;IAAC,KAAK,EAAE,IAAI,CAAC;IAAC,SAAS,EAAE,aAAa,EAAE,CAAA;CAAE,GACnF;IAAE,MAAM,EAAE,WAAW,CAAA;CAAE,CAAC;AAE5B,MAAM,WAAW,kBAAkB;IACjC,gDAAgD;IAChD,KAAK,EAAE,SAAS,aAAa,EAAE,CAAC;IAChC,mDAAmD;IACnD,SAAS,CAAC,EAAE,SAAS,aAAa,EAAE,CAAC;IACrC;;;;;;;;;;;OAWG;IACH,UAAU,CAAC,EAAE,OAAO,CAAC,MAAM,CAAC,aAAa,EAAE,IAAI,CAAC,CAAC,CAAC;CACnD;AAED;;;;;GAKG;AACH,wBAAgB,WAAW,CAAC,OAAO,EAAE,kBAAkB,GAAG,SAAS,CASlE"}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @venturekit/notify — channel fallback chains.
|
|
3
|
+
*
|
|
4
|
+
* `NotificationPreferenceRow` answers "may I use this channel for this
|
|
5
|
+
* category". It does not answer the question that comes first: *which* channels,
|
|
6
|
+
* in what order, and what happens when the preferred one cannot be used. A
|
|
7
|
+
* consumer with push, WhatsApp, SMS and e-mail has to decide that per message,
|
|
8
|
+
* and the shape of the decision is the same everywhere even though the answer
|
|
9
|
+
* never is.
|
|
10
|
+
*
|
|
11
|
+
* So the mechanism is here and the policy is not. This module will not tell you
|
|
12
|
+
* that push comes before e-mail — that depends on what your product is, what
|
|
13
|
+
* your channels cost, and what your regulator says. It will make an ordered,
|
|
14
|
+
* reachability-filtered chain out of the order *you* declare, and give the
|
|
15
|
+
* fallback position a name.
|
|
16
|
+
*/
|
|
17
|
+
/**
|
|
18
|
+
* The channels to attempt, in order.
|
|
19
|
+
*
|
|
20
|
+
* Filtering happens before ordering is applied, so a chain never contains a
|
|
21
|
+
* channel the recipient cannot receive on. Duplicates in `order` collapse.
|
|
22
|
+
*
|
|
23
|
+
* @example
|
|
24
|
+
* ```ts
|
|
25
|
+
* buildChannelChain({
|
|
26
|
+
* order: ['push', 'whatsapp', 'email'],
|
|
27
|
+
* reachable: { push: hasDevice, whatsapp: Boolean(phone), email: Boolean(email) },
|
|
28
|
+
* exclude: optedOutChannels,
|
|
29
|
+
* fallback: 'in_app',
|
|
30
|
+
* });
|
|
31
|
+
* ```
|
|
32
|
+
*/
|
|
33
|
+
export function buildChannelChain(options) {
|
|
34
|
+
const excluded = new Set(options.exclude ?? []);
|
|
35
|
+
const seen = new Set();
|
|
36
|
+
const chain = [];
|
|
37
|
+
for (const channel of options.order) {
|
|
38
|
+
if (seen.has(channel) || excluded.has(channel))
|
|
39
|
+
continue;
|
|
40
|
+
seen.add(channel);
|
|
41
|
+
if (options.reachable[channel] === true)
|
|
42
|
+
chain.push(channel);
|
|
43
|
+
}
|
|
44
|
+
if (chain.length > 0)
|
|
45
|
+
return chain;
|
|
46
|
+
/* The fallback is exempt from `reachable` — it is the channel of last resort
|
|
47
|
+
and typically has no address at all (an in-app inbox). It is not exempt from
|
|
48
|
+
`exclude`: a channel somebody switched off stays off. */
|
|
49
|
+
if (options.fallback && !excluded.has(options.fallback))
|
|
50
|
+
return [options.fallback];
|
|
51
|
+
return [];
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* The next channel to act on, and how.
|
|
55
|
+
*
|
|
56
|
+
* Returns `hold` rather than `attempt` for a channel in `deferUntil`, so the
|
|
57
|
+
* caller enqueues it with a release time instead of sending it now.
|
|
58
|
+
*/
|
|
59
|
+
export function nextChannel(options) {
|
|
60
|
+
const attempted = new Set(options.attempted ?? []);
|
|
61
|
+
const rest = options.chain.filter((c) => !attempted.has(c));
|
|
62
|
+
const [head, ...remaining] = rest;
|
|
63
|
+
if (!head)
|
|
64
|
+
return { action: 'exhausted' };
|
|
65
|
+
const until = options.deferUntil?.[head];
|
|
66
|
+
if (until)
|
|
67
|
+
return { action: 'hold', channel: head, until, remaining };
|
|
68
|
+
return { action: 'attempt', channel: head, remaining };
|
|
69
|
+
}
|
|
70
|
+
//# sourceMappingURL=channel-chain.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"channel-chain.js","sourceRoot":"","sources":["../../src/policy/channel-chain.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAsCH;;;;;;;;;;;;;;;GAeG;AACH,MAAM,UAAU,iBAAiB,CAAC,OAA4B;IAC5D,MAAM,QAAQ,GAAG,IAAI,GAAG,CAAC,OAAO,CAAC,OAAO,IAAI,EAAE,CAAC,CAAC;IAChD,MAAM,IAAI,GAAG,IAAI,GAAG,EAAiB,CAAC;IACtC,MAAM,KAAK,GAAoB,EAAE,CAAC;IAElC,KAAK,MAAM,OAAO,IAAI,OAAO,CAAC,KAAK,EAAE,CAAC;QACpC,IAAI,IAAI,CAAC,GAAG,CAAC,OAAO,CAAC,IAAI,QAAQ,CAAC,GAAG,CAAC,OAAO,CAAC;YAAE,SAAS;QACzD,IAAI,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC;QAClB,IAAI,OAAO,CAAC,SAAS,CAAC,OAAO,CAAC,KAAK,IAAI;YAAE,KAAK,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;IAC/D,CAAC;IAED,IAAI,KAAK,CAAC,MAAM,GAAG,CAAC;QAAE,OAAO,KAAK,CAAC;IACnC;;+DAE2D;IAC3D,IAAI,OAAO,CAAC,QAAQ,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,OAAO,CAAC,QAAQ,CAAC;QAAE,OAAO,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC;IACnF,OAAO,EAAE,CAAC;AACZ,CAAC;AA4BD;;;;;GAKG;AACH,MAAM,UAAU,WAAW,CAAC,OAA2B;IACrD,MAAM,SAAS,GAAG,IAAI,GAAG,CAAC,OAAO,CAAC,SAAS,IAAI,EAAE,CAAC,CAAC;IACnD,MAAM,IAAI,GAAG,OAAO,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,SAAS,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC;IAC5D,MAAM,CAAC,IAAI,EAAE,GAAG,SAAS,CAAC,GAAG,IAAI,CAAC;IAClC,IAAI,CAAC,IAAI;QAAE,OAAO,EAAE,MAAM,EAAE,WAAW,EAAE,CAAC;IAE1C,MAAM,KAAK,GAAG,OAAO,CAAC,UAAU,EAAE,CAAC,IAAI,CAAC,CAAC;IACzC,IAAI,KAAK;QAAE,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,IAAI,EAAE,KAAK,EAAE,SAAS,EAAE,CAAC;IACtE,OAAO,EAAE,MAAM,EAAE,SAAS,EAAE,OAAO,EAAE,IAAI,EAAE,SAAS,EAAE,CAAC;AACzD,CAAC"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @venturekit/notify/policy — send-path mechanisms.
|
|
3
|
+
*
|
|
4
|
+
* The decisions every multi-channel sender has to make, as pure functions:
|
|
5
|
+
* which channels to try and in what order, when to hold a message rather than
|
|
6
|
+
* send it, which locale to render, and how to interpolate an operator-authored
|
|
7
|
+
* template without shipping a hole where a fact should be.
|
|
8
|
+
*
|
|
9
|
+
* Mechanism only. The *policy* — that push beats e-mail, that this message class
|
|
10
|
+
* is urgent enough to pay for, that a tenant on the free plan gets no SMS —
|
|
11
|
+
* stays with the consumer, because it is the part that differs per product.
|
|
12
|
+
*/
|
|
13
|
+
export { inQuietHours, quietHoursEnd, type QuietHours, } from './quiet-hours.js';
|
|
14
|
+
export { buildChannelChain, nextChannel, type ChannelChainOptions, type ChannelReachability, type ChainStep, type NextChannelOptions, } from './channel-chain.js';
|
|
15
|
+
export { placeholdersOf, undeclaredPlaceholders, renderStringTemplate, resolveLocale, type StringTemplate, type RenderOutcome, type ResolveLocaleOptions, } from './string-templates.js';
|
|
16
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/policy/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,OAAO,EACL,YAAY,EACZ,aAAa,EACb,KAAK,UAAU,GAChB,MAAM,kBAAkB,CAAC;AAE1B,OAAO,EACL,iBAAiB,EACjB,WAAW,EACX,KAAK,mBAAmB,EACxB,KAAK,mBAAmB,EACxB,KAAK,SAAS,EACd,KAAK,kBAAkB,GACxB,MAAM,oBAAoB,CAAC;AAE5B,OAAO,EACL,cAAc,EACd,sBAAsB,EACtB,oBAAoB,EACpB,aAAa,EACb,KAAK,cAAc,EACnB,KAAK,aAAa,EAClB,KAAK,oBAAoB,GAC1B,MAAM,uBAAuB,CAAC"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @venturekit/notify/policy — send-path mechanisms.
|
|
3
|
+
*
|
|
4
|
+
* The decisions every multi-channel sender has to make, as pure functions:
|
|
5
|
+
* which channels to try and in what order, when to hold a message rather than
|
|
6
|
+
* send it, which locale to render, and how to interpolate an operator-authored
|
|
7
|
+
* template without shipping a hole where a fact should be.
|
|
8
|
+
*
|
|
9
|
+
* Mechanism only. The *policy* — that push beats e-mail, that this message class
|
|
10
|
+
* is urgent enough to pay for, that a tenant on the free plan gets no SMS —
|
|
11
|
+
* stays with the consumer, because it is the part that differs per product.
|
|
12
|
+
*/
|
|
13
|
+
export { inQuietHours, quietHoursEnd, } from './quiet-hours.js';
|
|
14
|
+
export { buildChannelChain, nextChannel, } from './channel-chain.js';
|
|
15
|
+
export { placeholdersOf, undeclaredPlaceholders, renderStringTemplate, resolveLocale, } from './string-templates.js';
|
|
16
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/policy/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,OAAO,EACL,YAAY,EACZ,aAAa,GAEd,MAAM,kBAAkB,CAAC;AAE1B,OAAO,EACL,iBAAiB,EACjB,WAAW,GAKZ,MAAM,oBAAoB,CAAC;AAE5B,OAAO,EACL,cAAc,EACd,sBAAsB,EACtB,oBAAoB,EACpB,aAAa,GAId,MAAM,uBAAuB,CAAC"}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @venturekit/notify — quiet hours.
|
|
3
|
+
*
|
|
4
|
+
* A window in which routine messages are held rather than sent. Pure functions:
|
|
5
|
+
* where the window is *stored* is a product decision — per tenant, per user, or
|
|
6
|
+
* both — and this package should not force one. What it can do is get the time
|
|
7
|
+
* arithmetic right, which is the part that is easy to get wrong.
|
|
8
|
+
*
|
|
9
|
+
* Two things make it non-obvious:
|
|
10
|
+
*
|
|
11
|
+
* - **The window may cross midnight.** `21:00 → 07:00` is the common case and
|
|
12
|
+
* `start < now < end` is false for all of it.
|
|
13
|
+
* - **The window is in the recipient's zone, not the server's.** A Lambda runs in
|
|
14
|
+
* UTC; a parent's evening does not. And the offset is not constant — a window
|
|
15
|
+
* that ends at 07:00 ends 23 hours after the previous 07:00 on one day a year
|
|
16
|
+
* and 25 on another, so "add 24 hours" and "add the offset" are both wrong.
|
|
17
|
+
*/
|
|
18
|
+
/** A daily local-time window. `HH:MM`, 24-hour. */
|
|
19
|
+
export interface QuietHours {
|
|
20
|
+
/** Local start, inclusive. */
|
|
21
|
+
start: string;
|
|
22
|
+
/** Local end, exclusive. */
|
|
23
|
+
end: string;
|
|
24
|
+
/** IANA zone the window is expressed in, e.g. `'Africa/Casablanca'`. */
|
|
25
|
+
timezone: string;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Is `at` inside the quiet window?
|
|
29
|
+
*
|
|
30
|
+
* A window whose start equals its end is treated as *empty* rather than as
|
|
31
|
+
* all-day. Both readings are defensible; this one is safe, because the
|
|
32
|
+
* alternative silently stops every routine message the moment someone saves
|
|
33
|
+
* `00:00`–`00:00` in a settings form.
|
|
34
|
+
*/
|
|
35
|
+
export declare function inQuietHours(at: Date, quiet: QuietHours): boolean;
|
|
36
|
+
/**
|
|
37
|
+
* The next instant at which the window ends, at or after `at`. Minute precision.
|
|
38
|
+
*
|
|
39
|
+
* Computed by projection rather than by scanning: take the local time now, add
|
|
40
|
+
* the minutes to the target, then *verify* — because a DST transition inside the
|
|
41
|
+
* interval moves the answer by an hour. The correction searches a bounded ±90
|
|
42
|
+
* minutes around the projection, which covers every transition in the tz
|
|
43
|
+
* database (all are 30, 60 or, historically, up to 120 minutes at fixed offsets).
|
|
44
|
+
*
|
|
45
|
+
* If the target local minute does not exist on that day at all — clocks jump
|
|
46
|
+
* 02:00 → 03:00 and the window ends at 02:30 — no instant can satisfy it, so the
|
|
47
|
+
* first instant *past* the target is returned. Holding until "the window ends"
|
|
48
|
+
* has to resolve to something, and later is the safe direction: releasing early
|
|
49
|
+
* sends inside somebody's night.
|
|
50
|
+
*/
|
|
51
|
+
export declare function quietHoursEnd(at: Date, quiet: QuietHours): Date;
|
|
52
|
+
//# sourceMappingURL=quiet-hours.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"quiet-hours.d.ts","sourceRoot":"","sources":["../../src/policy/quiet-hours.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAEH,mDAAmD;AACnD,MAAM,WAAW,UAAU;IACzB,8BAA8B;IAC9B,KAAK,EAAE,MAAM,CAAC;IACd,4BAA4B;IAC5B,GAAG,EAAE,MAAM,CAAC;IACZ,wEAAwE;IACxE,QAAQ,EAAE,MAAM,CAAC;CAClB;AAsBD;;;;;;;GAOG;AACH,wBAAgB,YAAY,CAAC,EAAE,EAAE,IAAI,EAAE,KAAK,EAAE,UAAU,GAAG,OAAO,CAQjE;AAED;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,aAAa,CAAC,EAAE,EAAE,IAAI,EAAE,KAAK,EAAE,UAAU,GAAG,IAAI,CA+B/D"}
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @venturekit/notify — quiet hours.
|
|
3
|
+
*
|
|
4
|
+
* A window in which routine messages are held rather than sent. Pure functions:
|
|
5
|
+
* where the window is *stored* is a product decision — per tenant, per user, or
|
|
6
|
+
* both — and this package should not force one. What it can do is get the time
|
|
7
|
+
* arithmetic right, which is the part that is easy to get wrong.
|
|
8
|
+
*
|
|
9
|
+
* Two things make it non-obvious:
|
|
10
|
+
*
|
|
11
|
+
* - **The window may cross midnight.** `21:00 → 07:00` is the common case and
|
|
12
|
+
* `start < now < end` is false for all of it.
|
|
13
|
+
* - **The window is in the recipient's zone, not the server's.** A Lambda runs in
|
|
14
|
+
* UTC; a parent's evening does not. And the offset is not constant — a window
|
|
15
|
+
* that ends at 07:00 ends 23 hours after the previous 07:00 on one day a year
|
|
16
|
+
* and 25 on another, so "add 24 hours" and "add the offset" are both wrong.
|
|
17
|
+
*/
|
|
18
|
+
/** Local wall clock of an instant in a zone, as minutes since midnight. */
|
|
19
|
+
function localMinutes(at, timezone) {
|
|
20
|
+
const parts = new Intl.DateTimeFormat('en-GB', {
|
|
21
|
+
hour: '2-digit',
|
|
22
|
+
minute: '2-digit',
|
|
23
|
+
hour12: false,
|
|
24
|
+
timeZone: timezone,
|
|
25
|
+
}).formatToParts(at);
|
|
26
|
+
const h = Number(parts.find((p) => p.type === 'hour')?.value ?? 0) % 24;
|
|
27
|
+
const m = Number(parts.find((p) => p.type === 'minute')?.value ?? 0);
|
|
28
|
+
return h * 60 + m;
|
|
29
|
+
}
|
|
30
|
+
function minutesOf(hhmm) {
|
|
31
|
+
const [h, m] = hhmm.split(':').map(Number);
|
|
32
|
+
return (h ?? 0) * 60 + (m ?? 0);
|
|
33
|
+
}
|
|
34
|
+
const DAY = 24 * 60;
|
|
35
|
+
/**
|
|
36
|
+
* Is `at` inside the quiet window?
|
|
37
|
+
*
|
|
38
|
+
* A window whose start equals its end is treated as *empty* rather than as
|
|
39
|
+
* all-day. Both readings are defensible; this one is safe, because the
|
|
40
|
+
* alternative silently stops every routine message the moment someone saves
|
|
41
|
+
* `00:00`–`00:00` in a settings form.
|
|
42
|
+
*/
|
|
43
|
+
export function inQuietHours(at, quiet) {
|
|
44
|
+
const now = localMinutes(at, quiet.timezone);
|
|
45
|
+
const start = minutesOf(quiet.start);
|
|
46
|
+
const end = minutesOf(quiet.end);
|
|
47
|
+
if (start === end)
|
|
48
|
+
return false;
|
|
49
|
+
return start < end
|
|
50
|
+
? now >= start && now < end
|
|
51
|
+
: now >= start || now < end;
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* The next instant at which the window ends, at or after `at`. Minute precision.
|
|
55
|
+
*
|
|
56
|
+
* Computed by projection rather than by scanning: take the local time now, add
|
|
57
|
+
* the minutes to the target, then *verify* — because a DST transition inside the
|
|
58
|
+
* interval moves the answer by an hour. The correction searches a bounded ±90
|
|
59
|
+
* minutes around the projection, which covers every transition in the tz
|
|
60
|
+
* database (all are 30, 60 or, historically, up to 120 minutes at fixed offsets).
|
|
61
|
+
*
|
|
62
|
+
* If the target local minute does not exist on that day at all — clocks jump
|
|
63
|
+
* 02:00 → 03:00 and the window ends at 02:30 — no instant can satisfy it, so the
|
|
64
|
+
* first instant *past* the target is returned. Holding until "the window ends"
|
|
65
|
+
* has to resolve to something, and later is the safe direction: releasing early
|
|
66
|
+
* sends inside somebody's night.
|
|
67
|
+
*/
|
|
68
|
+
export function quietHoursEnd(at, quiet) {
|
|
69
|
+
const end = minutesOf(quiet.end);
|
|
70
|
+
const now = localMinutes(at, quiet.timezone);
|
|
71
|
+
/* Minutes forward to the next occurrence. Exactly on it means the next one is
|
|
72
|
+
a full day away, not now — the caller is asking when the hold *ends*, and an
|
|
73
|
+
answer of "now" would release a message it just decided to hold. */
|
|
74
|
+
const delta = ((end - now + DAY) % DAY) || DAY;
|
|
75
|
+
const base = new Date(at);
|
|
76
|
+
base.setUTCSeconds(0, 0);
|
|
77
|
+
const projected = new Date(base.getTime() + delta * 60_000);
|
|
78
|
+
if (localMinutes(projected, quiet.timezone) === end)
|
|
79
|
+
return projected;
|
|
80
|
+
/* DST moved it. Walk outward from the projection, nearest first, so the
|
|
81
|
+
answer is the closest instant whose local clock reads `end`. */
|
|
82
|
+
for (let offset = 1; offset <= 90; offset++) {
|
|
83
|
+
for (const signed of [offset, -offset]) {
|
|
84
|
+
const candidate = new Date(projected.getTime() + signed * 60_000);
|
|
85
|
+
if (candidate.getTime() >= base.getTime() &&
|
|
86
|
+
localMinutes(candidate, quiet.timezone) === end) {
|
|
87
|
+
return candidate;
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
/* The local minute is skipped entirely by a forward transition. Release after
|
|
92
|
+
it rather than before. */
|
|
93
|
+
return new Date(projected.getTime() + 60 * 60_000);
|
|
94
|
+
}
|
|
95
|
+
//# sourceMappingURL=quiet-hours.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"quiet-hours.js","sourceRoot":"","sources":["../../src/policy/quiet-hours.ts"],"names":[],"mappings":"AAAA;;;;;;;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,IACE,SAAS,CAAC,OAAO,EAAE,IAAI,IAAI,CAAC,OAAO,EAAE;gBACrC,YAAY,CAAC,SAAS,EAAE,KAAK,CAAC,QAAQ,CAAC,KAAK,GAAG,EAC/C,CAAC;gBACD,OAAO,SAAS,CAAC;YACnB,CAAC;QACH,CAAC;IACH,CAAC;IAED;gCAC4B;IAC5B,OAAO,IAAI,IAAI,CAAC,SAAS,CAAC,OAAO,EAAE,GAAG,EAAE,GAAG,MAAM,CAAC,CAAC;AACrD,CAAC"}
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @venturekit/notify — string templates and locale resolution.
|
|
3
|
+
*
|
|
4
|
+
* `NotifyTemplate.render` is a TypeScript function, which is the right shape for
|
|
5
|
+
* a template the *developers* own: typed payload, arbitrary logic, caught by the
|
|
6
|
+
* compiler. It is the wrong shape for a template the *operator* owns — a school
|
|
7
|
+
* editing its own arrival message, a tenant customising a receipt — and
|
|
8
|
+
* `types.ts` says as much ("Phase 1 keeps templates in code only; Phase 2 will
|
|
9
|
+
* introduce external storage").
|
|
10
|
+
*
|
|
11
|
+
* This is the other half: templates as data, with `{placeholder}` interpolation,
|
|
12
|
+
* safe to store in a row and edit in a form. The two coexist — code templates
|
|
13
|
+
* for the product's own messages, string templates for the ones its customers
|
|
14
|
+
* write.
|
|
15
|
+
*
|
|
16
|
+
* The rule that makes it safe to put in front of users: **an unresolved
|
|
17
|
+
* placeholder blocks the send.** Never interpolate a blank, never ship
|
|
18
|
+
* `Hello {name}` to a person called {name}. Both failures are the kind that
|
|
19
|
+
* reach a customer before they reach a test.
|
|
20
|
+
*/
|
|
21
|
+
/** A template stored as data rather than code. */
|
|
22
|
+
export interface StringTemplate {
|
|
23
|
+
/** Stable identifier. */
|
|
24
|
+
key: string;
|
|
25
|
+
/** BCP-47 tag this variant is written in. */
|
|
26
|
+
locale: string;
|
|
27
|
+
/** Subject / title line. May contain placeholders. */
|
|
28
|
+
title: string;
|
|
29
|
+
/** Body. May contain placeholders. */
|
|
30
|
+
body: string;
|
|
31
|
+
/**
|
|
32
|
+
* Placeholders the author declared. {@link undeclaredPlaceholders} compares
|
|
33
|
+
* this against what the text actually uses, which is what an approval step
|
|
34
|
+
* checks: a typo'd `{childName}` against a declared `{child_name}` is
|
|
35
|
+
* otherwise invisible until the first send fails.
|
|
36
|
+
*/
|
|
37
|
+
variables: readonly string[];
|
|
38
|
+
}
|
|
39
|
+
/** Distinct placeholders a string uses, in first-appearance order. */
|
|
40
|
+
export declare function placeholdersOf(text: string): string[];
|
|
41
|
+
/**
|
|
42
|
+
* Placeholders the text uses but the author did not declare.
|
|
43
|
+
*
|
|
44
|
+
* Non-empty is an authoring error and should block approval rather than wait for
|
|
45
|
+
* a send to fail.
|
|
46
|
+
*/
|
|
47
|
+
export declare function undeclaredPlaceholders(template: StringTemplate): string[];
|
|
48
|
+
export type RenderOutcome = {
|
|
49
|
+
ok: true;
|
|
50
|
+
title: string;
|
|
51
|
+
body: string;
|
|
52
|
+
} | {
|
|
53
|
+
ok: false;
|
|
54
|
+
missing: string[];
|
|
55
|
+
};
|
|
56
|
+
/**
|
|
57
|
+
* Substitute values, or refuse.
|
|
58
|
+
*
|
|
59
|
+
* `undefined`, `null` and `''` all count as missing: an empty string is almost
|
|
60
|
+
* never a deliberate value for a name or a time, and rendering it produces a
|
|
61
|
+
* message with a hole where the fact should be — which reads as a bug to the
|
|
62
|
+
* recipient and is invisible to the sender.
|
|
63
|
+
*/
|
|
64
|
+
export declare function renderStringTemplate(template: StringTemplate, values: Record<string, string | number | null | undefined>): RenderOutcome;
|
|
65
|
+
export interface ResolveLocaleOptions {
|
|
66
|
+
/**
|
|
67
|
+
* Preferred locales, most specific first — typically the recipient's, then the
|
|
68
|
+
* tenant's, then the product's default.
|
|
69
|
+
*/
|
|
70
|
+
preferred: readonly (string | null | undefined)[];
|
|
71
|
+
/** Locales a template actually exists in. */
|
|
72
|
+
available: readonly string[];
|
|
73
|
+
/**
|
|
74
|
+
* Tried after `preferred` runs out. Empty by default: this package has no
|
|
75
|
+
* house language, and guessing one is how a French tenant gets English mail.
|
|
76
|
+
*/
|
|
77
|
+
fallbacks?: readonly string[];
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* Pick the locale to render in.
|
|
81
|
+
*
|
|
82
|
+
* Matches on the **language subtag only** (`fr-MA` satisfies `fr`, and `fr`
|
|
83
|
+
* satisfies `fr-CA`). Region-exact matching sounds more correct and in practice
|
|
84
|
+
* means a `fr-MA` reader gets English because the only French variant on file is
|
|
85
|
+
* `fr-FR`.
|
|
86
|
+
*
|
|
87
|
+
* Returns the first available locale when nothing matches, or `null` when there
|
|
88
|
+
* are none — a caller with no templates at all has a configuration problem, and
|
|
89
|
+
* inventing a locale would hide it.
|
|
90
|
+
*/
|
|
91
|
+
export declare function resolveLocale(options: ResolveLocaleOptions): string | null;
|
|
92
|
+
//# sourceMappingURL=string-templates.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"string-templates.d.ts","sourceRoot":"","sources":["../../src/policy/string-templates.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AAEH,kDAAkD;AAClD,MAAM,WAAW,cAAc;IAC7B,yBAAyB;IACzB,GAAG,EAAE,MAAM,CAAC;IACZ,6CAA6C;IAC7C,MAAM,EAAE,MAAM,CAAC;IACf,sDAAsD;IACtD,KAAK,EAAE,MAAM,CAAC;IACd,sCAAsC;IACtC,IAAI,EAAE,MAAM,CAAC;IACb;;;;;OAKG;IACH,SAAS,EAAE,SAAS,MAAM,EAAE,CAAC;CAC9B;AAYD,sEAAsE;AACtE,wBAAgB,cAAc,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,EAAE,CAErD;AAED;;;;;GAKG;AACH,wBAAgB,sBAAsB,CAAC,QAAQ,EAAE,cAAc,GAAG,MAAM,EAAE,CAQzE;AAED,MAAM,MAAM,aAAa,GACrB;IAAE,EAAE,EAAE,IAAI,CAAC;IAAC,KAAK,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,CAAA;CAAE,GACzC;IAAE,EAAE,EAAE,KAAK,CAAC;IAAC,OAAO,EAAE,MAAM,EAAE,CAAA;CAAE,CAAC;AAErC;;;;;;;GAOG;AACH,wBAAgB,oBAAoB,CAClC,QAAQ,EAAE,cAAc,EACxB,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,GAAG,SAAS,CAAC,GACzD,aAAa,CAgBf;AAED,MAAM,WAAW,oBAAoB;IACnC;;;OAGG;IACH,SAAS,EAAE,SAAS,CAAC,MAAM,GAAG,IAAI,GAAG,SAAS,CAAC,EAAE,CAAC;IAClD,6CAA6C;IAC7C,SAAS,EAAE,SAAS,MAAM,EAAE,CAAC;IAC7B;;;OAGG;IACH,SAAS,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;CAC/B;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,aAAa,CAAC,OAAO,EAAE,oBAAoB,GAAG,MAAM,GAAG,IAAI,CAY1E"}
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @venturekit/notify — string templates and locale resolution.
|
|
3
|
+
*
|
|
4
|
+
* `NotifyTemplate.render` is a TypeScript function, which is the right shape for
|
|
5
|
+
* a template the *developers* own: typed payload, arbitrary logic, caught by the
|
|
6
|
+
* compiler. It is the wrong shape for a template the *operator* owns — a school
|
|
7
|
+
* editing its own arrival message, a tenant customising a receipt — and
|
|
8
|
+
* `types.ts` says as much ("Phase 1 keeps templates in code only; Phase 2 will
|
|
9
|
+
* introduce external storage").
|
|
10
|
+
*
|
|
11
|
+
* This is the other half: templates as data, with `{placeholder}` interpolation,
|
|
12
|
+
* safe to store in a row and edit in a form. The two coexist — code templates
|
|
13
|
+
* for the product's own messages, string templates for the ones its customers
|
|
14
|
+
* write.
|
|
15
|
+
*
|
|
16
|
+
* The rule that makes it safe to put in front of users: **an unresolved
|
|
17
|
+
* placeholder blocks the send.** Never interpolate a blank, never ship
|
|
18
|
+
* `Hello {name}` to a person called {name}. Both failures are the kind that
|
|
19
|
+
* reach a customer before they reach a test.
|
|
20
|
+
*/
|
|
21
|
+
/**
|
|
22
|
+
* `{snake_case}` only.
|
|
23
|
+
*
|
|
24
|
+
* Deliberately narrow. Allowing dots or brackets invites `{user.name}` and
|
|
25
|
+
* `{items[0]}`, and then the renderer owns an expression language, path
|
|
26
|
+
* traversal into caller objects, and a prototype-pollution question. A flat
|
|
27
|
+
* namespace keeps the substitution a lookup.
|
|
28
|
+
*/
|
|
29
|
+
const PLACEHOLDER = /\{([a-z_][a-z0-9_]*)\}/g;
|
|
30
|
+
/** Distinct placeholders a string uses, in first-appearance order. */
|
|
31
|
+
export function placeholdersOf(text) {
|
|
32
|
+
return [...new Set([...text.matchAll(PLACEHOLDER)].map((m) => m[1]))];
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Placeholders the text uses but the author did not declare.
|
|
36
|
+
*
|
|
37
|
+
* Non-empty is an authoring error and should block approval rather than wait for
|
|
38
|
+
* a send to fail.
|
|
39
|
+
*/
|
|
40
|
+
export function undeclaredPlaceholders(template) {
|
|
41
|
+
const declared = new Set(template.variables);
|
|
42
|
+
return [
|
|
43
|
+
...new Set([
|
|
44
|
+
...placeholdersOf(template.title),
|
|
45
|
+
...placeholdersOf(template.body),
|
|
46
|
+
]),
|
|
47
|
+
].filter((name) => !declared.has(name));
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Substitute values, or refuse.
|
|
51
|
+
*
|
|
52
|
+
* `undefined`, `null` and `''` all count as missing: an empty string is almost
|
|
53
|
+
* never a deliberate value for a name or a time, and rendering it produces a
|
|
54
|
+
* message with a hole where the fact should be — which reads as a bug to the
|
|
55
|
+
* recipient and is invisible to the sender.
|
|
56
|
+
*/
|
|
57
|
+
export function renderStringTemplate(template, values) {
|
|
58
|
+
const used = [
|
|
59
|
+
...new Set([
|
|
60
|
+
...placeholdersOf(template.title),
|
|
61
|
+
...placeholdersOf(template.body),
|
|
62
|
+
]),
|
|
63
|
+
];
|
|
64
|
+
const missing = used.filter((name) => {
|
|
65
|
+
const value = values[name];
|
|
66
|
+
return value === undefined || value === null || value === '';
|
|
67
|
+
});
|
|
68
|
+
if (missing.length > 0)
|
|
69
|
+
return { ok: false, missing };
|
|
70
|
+
const fill = (text) => text.replace(PLACEHOLDER, (_match, name) => String(values[name]));
|
|
71
|
+
return { ok: true, title: fill(template.title), body: fill(template.body) };
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Pick the locale to render in.
|
|
75
|
+
*
|
|
76
|
+
* Matches on the **language subtag only** (`fr-MA` satisfies `fr`, and `fr`
|
|
77
|
+
* satisfies `fr-CA`). Region-exact matching sounds more correct and in practice
|
|
78
|
+
* means a `fr-MA` reader gets English because the only French variant on file is
|
|
79
|
+
* `fr-FR`.
|
|
80
|
+
*
|
|
81
|
+
* Returns the first available locale when nothing matches, or `null` when there
|
|
82
|
+
* are none — a caller with no templates at all has a configuration problem, and
|
|
83
|
+
* inventing a locale would hide it.
|
|
84
|
+
*/
|
|
85
|
+
export function resolveLocale(options) {
|
|
86
|
+
const language = (tag) => tag.toLowerCase().split(/[-_]/)[0];
|
|
87
|
+
for (const candidate of [...options.preferred, ...(options.fallbacks ?? [])]) {
|
|
88
|
+
if (!candidate)
|
|
89
|
+
continue;
|
|
90
|
+
const hit = options.available.find((a) => language(a) === language(candidate));
|
|
91
|
+
if (hit)
|
|
92
|
+
return hit;
|
|
93
|
+
}
|
|
94
|
+
return options.available[0] ?? null;
|
|
95
|
+
}
|
|
96
|
+
//# sourceMappingURL=string-templates.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"string-templates.js","sourceRoot":"","sources":["../../src/policy/string-templates.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AAqBH;;;;;;;GAOG;AACH,MAAM,WAAW,GAAG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AAEpB,8DAA8D;AAC9D,MAAM,WAAW,qBAAqB;IACpC,iDAAiD;IACjD,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,0CAA0C;IAC1C,IAAI,CAAC,EAAE,MAAM,CAAC;IACd;;;;;;OAMG;IACH,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;
|
|
1
|
+
{"version":3,"file":"email-mailhog.d.ts","sourceRoot":"","sources":["../../src/providers/email-mailhog.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAGH,OAAO,EAGL,KAAK,cAAc,EAGpB,MAAM,YAAY,CAAC;AAEpB,8DAA8D;AAC9D,MAAM,WAAW,qBAAqB;IACpC,iDAAiD;IACjD,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,0CAA0C;IAC1C,IAAI,CAAC,EAAE,MAAM,CAAC;IACd;;;;;;OAMG;IACH,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AAiJD;;;GAGG;AACH,wBAAgB,qBAAqB,CACnC,MAAM,GAAE,qBAA0B,GACjC,cAAc,CAiDhB"}
|
|
@@ -25,10 +25,6 @@ function sendSmtp(host, port, from, to, subject, text, html, project) {
|
|
|
25
25
|
function send(line) {
|
|
26
26
|
client.write(line + '\r\n');
|
|
27
27
|
}
|
|
28
|
-
function expectCode(buffer, expected) {
|
|
29
|
-
const code = parseInt(buffer.trim().substring(0, 3), 10);
|
|
30
|
-
return code === expected;
|
|
31
|
-
}
|
|
32
28
|
client.setTimeout(10000);
|
|
33
29
|
client.on('data', (data) => {
|
|
34
30
|
const response = data.toString();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"email-mailhog.js","sourceRoot":"","sources":["../../src/providers/email-mailhog.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,EAAE,gBAAgB,EAAe,MAAM,KAAK,CAAC;AACpD,OAAO,EACL,iBAAiB,EACjB,iBAAiB,GAIlB,MAAM,YAAY,CAAC;AAkBpB,SAAS,gBAAgB,CA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AAG,EAAE,CAAC;gBACb,uDAAuD;gBACvD,IAAI,GAAG,YAAY,KAAK,IAAI,GAAG,CAAC,OAAO,CAAC,QAAQ,CAAC,cAAc,CAAC,EAAE,CAAC;oBACjE,MAAM,IAAI,iBAAiB,CACzB,4BAA4B,IAAI,IAAI,IAAI,yBAAyB,EACjE,GAAG,CACJ,CAAC;gBACJ,CAAC;gBACD,MAAM,GAAG,CAAC;YACZ,CAAC;QACH,CAAC;KACF,CAAC;AACJ,CAAC"}
|
|
@@ -16,6 +16,7 @@ export { createSesEmailProvider, type SesEmailProviderConfig, __resetSesClientFo
|
|
|
16
16
|
export { createMetaWhatsAppProvider, createSecretsTokenResolver, type MetaWhatsAppProvider, type MetaWhatsAppProviderConfig, type WhatsAppTemplateCategory, type WhatsAppTemplateCategoryReported, type WhatsAppTemplateStatus, type WhatsAppTemplateRejectedReason, type WhatsAppTemplateComponent, type WhatsAppTemplateInput, type WhatsAppTemplateCreateResult, type WhatsAppTemplateStatusResult, type WhatsAppTemplateUpdateInput, type WhatsAppTemplateUpdateResult, type WhatsAppTemplateDeleteInput, type WhatsAppTemplateDeleteResult, } from './whatsapp-meta.js';
|
|
17
17
|
export { toMetaLanguage, fromMetaLanguage, DEFAULT_META_LANGUAGE_MAP, } from './whatsapp-meta-language.js';
|
|
18
18
|
export { verifyMetaWebhookSignature, handleMetaWebhookVerification, parseMetaWebhookEvents, MetaWebhookSignatureError, MetaWebhookVerificationError, MetaWebhookPayloadError, META_SIGNATURE_HEADER, type VerifyMetaWebhookSignatureInput, type HandleMetaWebhookVerificationInput, type MetaWebhookQuery, type MetaWebhookEvent, type MetaTemplateWebhookEventBase, type MetaTemplateCategoryChangedEvent, type MetaTemplateCategoryChangeScheduledEvent, type MetaTemplateStatusUpdatedEvent, type MetaUnknownWebhookEvent, type WhatsAppTemplateStatusEvent, createMetaWhatsAppWebhookHandler, type MetaWhatsAppWebhookHandler, type MetaWhatsAppWebhookHandlerConfig, WHATSAPP_APP_SECRET_ENV, WHATSAPP_VERIFY_TOKEN_SECRET_ENV, } from './whatsapp-meta-webhook.js';
|
|
19
|
+
export { createExpoPushProvider, sendExpoPush, fetchExpoPushReceipts, isDeviceGone, type ExpoPushConfig, type ExpoPushProviderConfig, type ExpoPushMessage, type ExpoPushTicket, type ExpoPushTicketFor, type ExpoPushReceipt, type FetchLike, } from './push-expo.js';
|
|
19
20
|
export { createSmsNoopProvider } from './sms-noop.js';
|
|
20
21
|
export { createPushNoopProvider } from './push-noop.js';
|
|
21
22
|
export { createEmailNoopProvider, type EmailNoopOptions } from './email-noop.js';
|
|
@@ -1 +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,oBAAoB,EACzB,KAAK,0BAA0B,EAC/B,KAAK,wBAAwB,EAC7B,KAAK,gCAAgC,EACrC,KAAK,sBAAsB,EAC3B,KAAK,8BAA8B,EACnC,KAAK,yBAAyB,EAC9B,KAAK,qBAAqB,EAC1B,KAAK,4BAA4B,EACjC,KAAK,4BAA4B,EACjC,KAAK,2BAA2B,EAChC,KAAK,4BAA4B,EACjC,KAAK,2BAA2B,EAChC,KAAK,4BAA4B,GAClC,MAAM,oBAAoB,CAAC;AAE5B,OAAO,EACL,cAAc,EACd,gBAAgB,EAChB,yBAAyB,GAC1B,MAAM,6BAA6B,CAAC;AAErC,OAAO,EACL,0BAA0B,EAC1B,6BAA6B,EAC7B,sBAAsB,EACtB,yBAAyB,EACzB,4BAA4B,EAC5B,uB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,4BAA4B,GAClC,MAAM,oBAAoB,CAAC;AAE5B,OAAO,EACL,cAAc,EACd,gBAAgB,EAChB,yBAAyB,GAC1B,MAAM,6BAA6B,CAAC;AAErC,OAAO,EACL,0BAA0B,EAC1B,6BAA6B,EAC7B,sBAAsB,EACtB,yBAAyB,EACzB,4BAA4B,EAC5B,uBAAuB,EACvB,qBAAqB,EACrB,KAAK,+BAA+B,EACpC,KAAK,kCAAkC,EACvC,KAAK,gBAAgB,EACrB,KAAK,gBAAgB,EACrB,KAAK,4BAA4B,EACjC,KAAK,gCAAgC,EACrC,KAAK,wCAAwC,EAC7C,KAAK,8BAA8B,EACnC,KAAK,uBAAuB,EAC5B,KAAK,2BAA2B,EAChC,gCAAgC,EAChC,KAAK,0BAA0B,EAC/B,KAAK,gCAAgC,EACrC,uBAAuB,EACvB,gCAAgC,GACjC,MAAM,4BAA4B,CAAC;AAEpC,OAAO,EACL,sBAAsB,EACtB,YAAY,EACZ,qBAAqB,EACrB,YAAY,EACZ,KAAK,cAAc,EACnB,KAAK,sBAAsB,EAC3B,KAAK,eAAe,EACpB,KAAK,cAAc,EACnB,KAAK,iBAAiB,EACtB,KAAK,eAAe,EACpB,KAAK,SAAS,GACf,MAAM,gBAAgB,CAAC;AAExB,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;AACjF,OAAO,EAAE,qBAAqB,EAAE,KAAK,qBAAqB,EAAE,MAAM,oBAAoB,CAAC"}
|
package/dist/providers/index.js
CHANGED
|
@@ -16,6 +16,7 @@ export { createSesEmailProvider, __resetSesClientForTests, } from './email-ses.j
|
|
|
16
16
|
export { createMetaWhatsAppProvider, createSecretsTokenResolver, } from './whatsapp-meta.js';
|
|
17
17
|
export { toMetaLanguage, fromMetaLanguage, DEFAULT_META_LANGUAGE_MAP, } from './whatsapp-meta-language.js';
|
|
18
18
|
export { verifyMetaWebhookSignature, handleMetaWebhookVerification, parseMetaWebhookEvents, MetaWebhookSignatureError, MetaWebhookVerificationError, MetaWebhookPayloadError, META_SIGNATURE_HEADER, createMetaWhatsAppWebhookHandler, WHATSAPP_APP_SECRET_ENV, WHATSAPP_VERIFY_TOKEN_SECRET_ENV, } from './whatsapp-meta-webhook.js';
|
|
19
|
+
export { createExpoPushProvider, sendExpoPush, fetchExpoPushReceipts, isDeviceGone, } from './push-expo.js';
|
|
19
20
|
export { createSmsNoopProvider } from './sms-noop.js';
|
|
20
21
|
export { createPushNoopProvider } from './push-noop.js';
|
|
21
22
|
export { createEmailNoopProvider } from './email-noop.js';
|
|
@@ -1 +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,EACL,cAAc,EACd,gBAAgB,EAChB,yBAAyB,GAC1B,MAAM,6BAA6B,CAAC;AAErC,OAAO,EACL,0BAA0B,EAC1B,6BAA6B,EAC7B,sBAAsB,EACtB,yBAAyB,EACzB,4BAA4B,EAC5B,uBAAuB,EACvB,qBAAqB,EAWrB,gCAAgC,EAGhC,uBAAuB,EACvB,gCAAgC,GACjC,MAAM,4BAA4B,CAAC;AAEpC,OAAO,EAAE,qBAAqB,EAAE,MAAM,eAAe,CAAC;AACtD,OAAO,EAAE,sBAAsB,EAAE,MAAM,gBAAgB,CAAC;AACxD,OAAO,EAAE,uBAAuB,EAAyB,MAAM,iBAAiB,CAAC;AACjF,OAAO,EAAE,qBAAqB,EAA8B,MAAM,oBAAoB,CAAC"}
|
|
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,EACL,cAAc,EACd,gBAAgB,EAChB,yBAAyB,GAC1B,MAAM,6BAA6B,CAAC;AAErC,OAAO,EACL,0BAA0B,EAC1B,6BAA6B,EAC7B,sBAAsB,EACtB,yBAAyB,EACzB,4BAA4B,EAC5B,uBAAuB,EACvB,qBAAqB,EAWrB,gCAAgC,EAGhC,uBAAuB,EACvB,gCAAgC,GACjC,MAAM,4BAA4B,CAAC;AAEpC,OAAO,EACL,sBAAsB,EACtB,YAAY,EACZ,qBAAqB,EACrB,YAAY,GAQb,MAAM,gBAAgB,CAAC;AAExB,OAAO,EAAE,qBAAqB,EAAE,MAAM,eAAe,CAAC;AACtD,OAAO,EAAE,sBAAsB,EAAE,MAAM,gBAAgB,CAAC;AACxD,OAAO,EAAE,uBAAuB,EAAyB,MAAM,iBAAiB,CAAC;AACjF,OAAO,EAAE,qBAAqB,EAA8B,MAAM,oBAAoB,CAAC"}
|
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @venturekit/notify — Expo push provider.
|
|
3
|
+
*
|
|
4
|
+
* `push-noop.ts` says Phase 1 ships no real push provider and names SNS Mobile
|
|
5
|
+
* Push as the expected one. For anything with a React Native client the
|
|
6
|
+
* realistic answer is Expo: it fronts APNs and FCM, takes a single HTTP call,
|
|
7
|
+
* and needs no platform application ARNs or certificate management.
|
|
8
|
+
*
|
|
9
|
+
* ### Two surfaces, because push does not fit one
|
|
10
|
+
*
|
|
11
|
+
* `NotifyProvider.send()` addresses ONE recipient. Expo push is inherently
|
|
12
|
+
* multi-token — a person has a phone and a tablet, one request carries all their
|
|
13
|
+
* tokens, and the answer is one ticket per token. Squeezing that through a
|
|
14
|
+
* single-address interface would either lose the "delivered if any device took
|
|
15
|
+
* it" semantics or smuggle a token list through a string. So:
|
|
16
|
+
*
|
|
17
|
+
* - {@link createExpoPushProvider} conforms to `NotifyProvider`; `to` is one Expo
|
|
18
|
+
* push token. Use it with this package's dispatcher and enqueue a row per
|
|
19
|
+
* device.
|
|
20
|
+
* - {@link sendExpoPush} is the multi-token client underneath, returning a ticket
|
|
21
|
+
* per token. Use it when you own the outbox and a notification means "reach
|
|
22
|
+
* this person on whatever they have".
|
|
23
|
+
*
|
|
24
|
+
* ### A ticket is not a delivery
|
|
25
|
+
*
|
|
26
|
+
* The send returns a *ticket*: Expo accepted the message. Whether it reached
|
|
27
|
+
* APNs/FCM is in a *receipt*, available a few minutes later and for about a day
|
|
28
|
+
* ({@link fetchExpoPushReceipts}). Two consequences worth stating because both
|
|
29
|
+
* are routinely got wrong:
|
|
30
|
+
*
|
|
31
|
+
* - **`DeviceNotRegistered` means stop sending to that token.** It arrives on
|
|
32
|
+
* either the ticket or the receipt, and a sender that ignores it keeps pushing
|
|
33
|
+
* to uninstalled apps forever. {@link isDeviceGone} is the check.
|
|
34
|
+
* - **An `ok` receipt is not "read", and arguably not even "delivered".** It
|
|
35
|
+
* means the gateway took it; a phone can be off for a day. Anything that
|
|
36
|
+
* depends on the person actually seeing the message — a fallback to SMS, an
|
|
37
|
+
* escalation — should key off an act of theirs, not off a receipt.
|
|
38
|
+
*/
|
|
39
|
+
import { type NotifyProvider } from './types.js';
|
|
40
|
+
/** The subset of `fetch` this module uses, so it is testable without a network. */
|
|
41
|
+
export type FetchLike = (url: string, init: {
|
|
42
|
+
method: string;
|
|
43
|
+
headers: Record<string, string>;
|
|
44
|
+
body: string;
|
|
45
|
+
}) => Promise<{
|
|
46
|
+
ok: boolean;
|
|
47
|
+
status: number;
|
|
48
|
+
json(): Promise<unknown>;
|
|
49
|
+
}>;
|
|
50
|
+
export interface ExpoPushConfig {
|
|
51
|
+
/**
|
|
52
|
+
* Expo access token. Required only when the project has "enforce push
|
|
53
|
+
* security" on, but harmless to set always — and if the project *does* enforce
|
|
54
|
+
* it, sends fail with 403 until it is.
|
|
55
|
+
*/
|
|
56
|
+
accessToken?: string | null;
|
|
57
|
+
/** Injected for tests. Defaults to the global `fetch`. */
|
|
58
|
+
fetchImpl?: FetchLike;
|
|
59
|
+
}
|
|
60
|
+
/** One message in a {@link sendExpoPush} batch. */
|
|
61
|
+
export interface ExpoPushMessage {
|
|
62
|
+
/** An Expo push token (`ExponentPushToken[…]`). */
|
|
63
|
+
to: string;
|
|
64
|
+
title?: string;
|
|
65
|
+
body?: string;
|
|
66
|
+
/** Arbitrary JSON the app receives; typically what the notification opens. */
|
|
67
|
+
data?: Record<string, unknown>;
|
|
68
|
+
sound?: 'default' | null;
|
|
69
|
+
/** `high` asks the OS not to batch it. Reserve it for time-critical messages. */
|
|
70
|
+
priority?: 'default' | 'normal' | 'high';
|
|
71
|
+
/** Android notification channel id. */
|
|
72
|
+
channelId?: string;
|
|
73
|
+
badge?: number;
|
|
74
|
+
/** Seconds Expo may keep trying. */
|
|
75
|
+
ttl?: number;
|
|
76
|
+
}
|
|
77
|
+
/** Expo's per-message answer. `id` is the receipt id; absent on rejection. */
|
|
78
|
+
export interface ExpoPushTicket {
|
|
79
|
+
status: 'ok' | 'error';
|
|
80
|
+
id?: string;
|
|
81
|
+
message?: string;
|
|
82
|
+
details?: {
|
|
83
|
+
error?: string;
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
/** A ticket paired with the token it concerns — Expo answers positionally. */
|
|
87
|
+
export interface ExpoPushTicketFor {
|
|
88
|
+
to: string;
|
|
89
|
+
ticket: ExpoPushTicket;
|
|
90
|
+
}
|
|
91
|
+
export interface ExpoPushReceipt {
|
|
92
|
+
status: 'ok' | 'error';
|
|
93
|
+
message?: string;
|
|
94
|
+
details?: {
|
|
95
|
+
error?: string;
|
|
96
|
+
};
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* Does this ticket or receipt mean the token is dead?
|
|
100
|
+
*
|
|
101
|
+
* `DeviceNotRegistered` is the app being uninstalled, the token rotated, or the
|
|
102
|
+
* build replaced. It is permanent: revoke the token. Anything else is worth
|
|
103
|
+
* retrying.
|
|
104
|
+
*/
|
|
105
|
+
export declare function isDeviceGone(result: ExpoPushTicket | ExpoPushReceipt | undefined): boolean;
|
|
106
|
+
/**
|
|
107
|
+
* Send to many tokens, returning a ticket per token.
|
|
108
|
+
*
|
|
109
|
+
* Chunked at Expo's 100-per-request limit. Expo answers `data` **positionally**,
|
|
110
|
+
* so the result re-joins each ticket to its token — reading the array by index
|
|
111
|
+
* against the wrong input is the classic way a revocation gets applied to the
|
|
112
|
+
* wrong device.
|
|
113
|
+
*
|
|
114
|
+
* Throws on a transport or HTTP failure; a per-token rejection is data, not an
|
|
115
|
+
* exception, and comes back in the tickets.
|
|
116
|
+
*/
|
|
117
|
+
export declare function sendExpoPush(messages: readonly ExpoPushMessage[], config?: ExpoPushConfig): Promise<ExpoPushTicketFor[]>;
|
|
118
|
+
/**
|
|
119
|
+
* Fetch receipts for ticket ids, keyed by id.
|
|
120
|
+
*
|
|
121
|
+
* An id absent from the result has no receipt *yet* — ask again later. Expo
|
|
122
|
+
* keeps receipts for roughly a day, so an id that never appears within that
|
|
123
|
+
* window is honestly unknown rather than failed.
|
|
124
|
+
*/
|
|
125
|
+
export declare function fetchExpoPushReceipts(ticketIds: readonly string[], config?: ExpoPushConfig): Promise<Record<string, ExpoPushReceipt>>;
|
|
126
|
+
export interface ExpoPushProviderConfig extends ExpoPushConfig {
|
|
127
|
+
/** Android channel id for sends that do not name one. */
|
|
128
|
+
defaultChannelId?: string;
|
|
129
|
+
/** `sound` for sends that do not name one. Default `'default'`. */
|
|
130
|
+
defaultSound?: 'default' | null;
|
|
131
|
+
}
|
|
132
|
+
/**
|
|
133
|
+
* A `NotifyProvider` for the `push` channel, where `to` is one Expo push token.
|
|
134
|
+
*
|
|
135
|
+
* `providerMessageId` is the ticket id, which is also the **receipt id** — so
|
|
136
|
+
* the outbox row already holds what a later receipts pass needs to look it up.
|
|
137
|
+
* That is the whole reason to record it.
|
|
138
|
+
*
|
|
139
|
+
* Error mapping follows the dispatcher's contract: `DeviceNotRegistered` and a
|
|
140
|
+
* malformed request are {@link ProviderHardError} (no retry — the token is gone
|
|
141
|
+
* or the request is wrong), while a network blip, a 429 or a 5xx are
|
|
142
|
+
* {@link ProviderSendError} (retry on the next tick).
|
|
143
|
+
*/
|
|
144
|
+
export declare function createExpoPushProvider(config?: ExpoPushProviderConfig): NotifyProvider;
|
|
145
|
+
//# sourceMappingURL=push-expo.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"push-expo.d.ts","sourceRoot":"","sources":["../../src/providers/push-expo.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAqCG;AAGH,OAAO,EAGL,KAAK,cAAc,EAGpB,MAAM,YAAY,CAAC;AAUpB,mFAAmF;AACnF,MAAM,MAAM,SAAS,GAAG,CACtB,GAAG,EAAE,MAAM,EACX,IAAI,EAAE;IAAE,MAAM,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAAC,IAAI,EAAE,MAAM,CAAA;CAAE,KACpE,OAAO,CAAC;IAAE,EAAE,EAAE,OAAO,CAAC;IAAC,MAAM,EAAE,MAAM,CAAC;IAAC,IAAI,IAAI,OAAO,CAAC,OAAO,CAAC,CAAA;CAAE,CAAC,CAAC;AAExE,MAAM,WAAW,cAAc;IAC7B;;;;OAIG;IACH,WAAW,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAC5B,0DAA0D;IAC1D,SAAS,CAAC,EAAE,S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,GAAE,cAAmB,GAC1B,OAAO,CAAC,iBAAiB,EAAE,CAAC,CA6C9B;AAED;;;;;;GAMG;AACH,wBAAsB,qBAAqB,CACzC,SAAS,EAAE,SAAS,MAAM,EAAE,EAC5B,MAAM,GAAE,cAAmB,GAC1B,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,eAAe,CAAC,CAAC,CAgC1C;AAED,MAAM,WAAW,sBAAuB,SAAQ,cAAc;IAC5D,yDAAyD;IACzD,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,mEAAmE;IACnE,YAAY,CAAC,EAAE,SAAS,GAAG,IAAI,CAAC;CACjC;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,sBAAsB,CACpC,MAAM,GAAE,sBAA2B,GAClC,cAAc,CA2ChB"}
|
|
@@ -0,0 +1,206 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @venturekit/notify — Expo push provider.
|
|
3
|
+
*
|
|
4
|
+
* `push-noop.ts` says Phase 1 ships no real push provider and names SNS Mobile
|
|
5
|
+
* Push as the expected one. For anything with a React Native client the
|
|
6
|
+
* realistic answer is Expo: it fronts APNs and FCM, takes a single HTTP call,
|
|
7
|
+
* and needs no platform application ARNs or certificate management.
|
|
8
|
+
*
|
|
9
|
+
* ### Two surfaces, because push does not fit one
|
|
10
|
+
*
|
|
11
|
+
* `NotifyProvider.send()` addresses ONE recipient. Expo push is inherently
|
|
12
|
+
* multi-token — a person has a phone and a tablet, one request carries all their
|
|
13
|
+
* tokens, and the answer is one ticket per token. Squeezing that through a
|
|
14
|
+
* single-address interface would either lose the "delivered if any device took
|
|
15
|
+
* it" semantics or smuggle a token list through a string. So:
|
|
16
|
+
*
|
|
17
|
+
* - {@link createExpoPushProvider} conforms to `NotifyProvider`; `to` is one Expo
|
|
18
|
+
* push token. Use it with this package's dispatcher and enqueue a row per
|
|
19
|
+
* device.
|
|
20
|
+
* - {@link sendExpoPush} is the multi-token client underneath, returning a ticket
|
|
21
|
+
* per token. Use it when you own the outbox and a notification means "reach
|
|
22
|
+
* this person on whatever they have".
|
|
23
|
+
*
|
|
24
|
+
* ### A ticket is not a delivery
|
|
25
|
+
*
|
|
26
|
+
* The send returns a *ticket*: Expo accepted the message. Whether it reached
|
|
27
|
+
* APNs/FCM is in a *receipt*, available a few minutes later and for about a day
|
|
28
|
+
* ({@link fetchExpoPushReceipts}). Two consequences worth stating because both
|
|
29
|
+
* are routinely got wrong:
|
|
30
|
+
*
|
|
31
|
+
* - **`DeviceNotRegistered` means stop sending to that token.** It arrives on
|
|
32
|
+
* either the ticket or the receipt, and a sender that ignores it keeps pushing
|
|
33
|
+
* to uninstalled apps forever. {@link isDeviceGone} is the check.
|
|
34
|
+
* - **An `ok` receipt is not "read", and arguably not even "delivered".** It
|
|
35
|
+
* means the gateway took it; a phone can be off for a day. Anything that
|
|
36
|
+
* depends on the person actually seeing the message — a fallback to SMS, an
|
|
37
|
+
* escalation — should key off an act of theirs, not off a receipt.
|
|
38
|
+
*/
|
|
39
|
+
import { ProviderHardError, ProviderSendError, } from './types.js';
|
|
40
|
+
const SEND_URL = 'https://exp.host/--/api/v2/push/send';
|
|
41
|
+
const RECEIPTS_URL = 'https://exp.host/--/api/v2/push/getReceipts';
|
|
42
|
+
/** Expo's documented ceiling for one send request. */
|
|
43
|
+
const SEND_CHUNK = 100;
|
|
44
|
+
/** Expo's documented ceiling for one getReceipts request. */
|
|
45
|
+
const RECEIPTS_CHUNK = 1000;
|
|
46
|
+
/**
|
|
47
|
+
* Does this ticket or receipt mean the token is dead?
|
|
48
|
+
*
|
|
49
|
+
* `DeviceNotRegistered` is the app being uninstalled, the token rotated, or the
|
|
50
|
+
* build replaced. It is permanent: revoke the token. Anything else is worth
|
|
51
|
+
* retrying.
|
|
52
|
+
*/
|
|
53
|
+
export function isDeviceGone(result) {
|
|
54
|
+
return result?.details?.error === 'DeviceNotRegistered';
|
|
55
|
+
}
|
|
56
|
+
function headers(accessToken) {
|
|
57
|
+
return {
|
|
58
|
+
'content-type': 'application/json',
|
|
59
|
+
accept: 'application/json',
|
|
60
|
+
...(accessToken ? { authorization: `Bearer ${accessToken}` } : {}),
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
function chunk(items, size) {
|
|
64
|
+
const out = [];
|
|
65
|
+
for (let i = 0; i < items.length; i += size)
|
|
66
|
+
out.push(items.slice(i, i + size));
|
|
67
|
+
return out;
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Send to many tokens, returning a ticket per token.
|
|
71
|
+
*
|
|
72
|
+
* Chunked at Expo's 100-per-request limit. Expo answers `data` **positionally**,
|
|
73
|
+
* so the result re-joins each ticket to its token — reading the array by index
|
|
74
|
+
* against the wrong input is the classic way a revocation gets applied to the
|
|
75
|
+
* wrong device.
|
|
76
|
+
*
|
|
77
|
+
* Throws on a transport or HTTP failure; a per-token rejection is data, not an
|
|
78
|
+
* exception, and comes back in the tickets.
|
|
79
|
+
*/
|
|
80
|
+
export async function sendExpoPush(messages, config = {}) {
|
|
81
|
+
if (messages.length === 0)
|
|
82
|
+
return [];
|
|
83
|
+
const doFetch = config.fetchImpl ?? globalThis.fetch;
|
|
84
|
+
if (!doFetch) {
|
|
85
|
+
throw new ProviderHardError('[notify:push-expo] no fetch available — pass `fetchImpl` on Node without a global fetch');
|
|
86
|
+
}
|
|
87
|
+
const out = [];
|
|
88
|
+
for (const batch of chunk(messages, SEND_CHUNK)) {
|
|
89
|
+
let response;
|
|
90
|
+
try {
|
|
91
|
+
response = await doFetch(SEND_URL, {
|
|
92
|
+
method: 'POST',
|
|
93
|
+
headers: headers(config.accessToken),
|
|
94
|
+
body: JSON.stringify(batch),
|
|
95
|
+
});
|
|
96
|
+
}
|
|
97
|
+
catch (err) {
|
|
98
|
+
/* Network-level: retryable. */
|
|
99
|
+
throw new ProviderSendError('[notify:push-expo] send failed', err);
|
|
100
|
+
}
|
|
101
|
+
if (!response.ok) {
|
|
102
|
+
/* 4xx is a request we built wrong or an auth problem — retrying sends the
|
|
103
|
+
same broken request. 5xx and 429 are Expo's problem and will pass. */
|
|
104
|
+
const message = `[notify:push-expo] send returned HTTP ${response.status}`;
|
|
105
|
+
if (response.status >= 400 && response.status < 500 && response.status !== 429) {
|
|
106
|
+
throw new ProviderHardError(message);
|
|
107
|
+
}
|
|
108
|
+
throw new ProviderSendError(message);
|
|
109
|
+
}
|
|
110
|
+
const json = (await response.json());
|
|
111
|
+
const tickets = json.data ?? [];
|
|
112
|
+
batch.forEach((message, i) => {
|
|
113
|
+
out.push({
|
|
114
|
+
to: message.to,
|
|
115
|
+
/* A short `data` array means Expo answered about fewer messages than we
|
|
116
|
+
sent; treat the gap as an error rather than as success. */
|
|
117
|
+
ticket: tickets[i] ?? { status: 'error', message: 'no ticket returned' },
|
|
118
|
+
});
|
|
119
|
+
});
|
|
120
|
+
}
|
|
121
|
+
return out;
|
|
122
|
+
}
|
|
123
|
+
/**
|
|
124
|
+
* Fetch receipts for ticket ids, keyed by id.
|
|
125
|
+
*
|
|
126
|
+
* An id absent from the result has no receipt *yet* — ask again later. Expo
|
|
127
|
+
* keeps receipts for roughly a day, so an id that never appears within that
|
|
128
|
+
* window is honestly unknown rather than failed.
|
|
129
|
+
*/
|
|
130
|
+
export async function fetchExpoPushReceipts(ticketIds, config = {}) {
|
|
131
|
+
if (ticketIds.length === 0)
|
|
132
|
+
return {};
|
|
133
|
+
const doFetch = config.fetchImpl ?? globalThis.fetch;
|
|
134
|
+
if (!doFetch) {
|
|
135
|
+
throw new ProviderHardError('[notify:push-expo] no fetch available — pass `fetchImpl` on Node without a global fetch');
|
|
136
|
+
}
|
|
137
|
+
const out = {};
|
|
138
|
+
for (const batch of chunk(ticketIds, RECEIPTS_CHUNK)) {
|
|
139
|
+
let response;
|
|
140
|
+
try {
|
|
141
|
+
response = await doFetch(RECEIPTS_URL, {
|
|
142
|
+
method: 'POST',
|
|
143
|
+
headers: headers(config.accessToken),
|
|
144
|
+
body: JSON.stringify({ ids: batch }),
|
|
145
|
+
});
|
|
146
|
+
}
|
|
147
|
+
catch (err) {
|
|
148
|
+
throw new ProviderSendError('[notify:push-expo] getReceipts failed', err);
|
|
149
|
+
}
|
|
150
|
+
if (!response.ok) {
|
|
151
|
+
throw new ProviderSendError(`[notify:push-expo] getReceipts returned HTTP ${response.status}`);
|
|
152
|
+
}
|
|
153
|
+
const json = (await response.json());
|
|
154
|
+
Object.assign(out, json.data ?? {});
|
|
155
|
+
}
|
|
156
|
+
return out;
|
|
157
|
+
}
|
|
158
|
+
/**
|
|
159
|
+
* A `NotifyProvider` for the `push` channel, where `to` is one Expo push token.
|
|
160
|
+
*
|
|
161
|
+
* `providerMessageId` is the ticket id, which is also the **receipt id** — so
|
|
162
|
+
* the outbox row already holds what a later receipts pass needs to look it up.
|
|
163
|
+
* That is the whole reason to record it.
|
|
164
|
+
*
|
|
165
|
+
* Error mapping follows the dispatcher's contract: `DeviceNotRegistered` and a
|
|
166
|
+
* malformed request are {@link ProviderHardError} (no retry — the token is gone
|
|
167
|
+
* or the request is wrong), while a network blip, a 429 or a 5xx are
|
|
168
|
+
* {@link ProviderSendError} (retry on the next tick).
|
|
169
|
+
*/
|
|
170
|
+
export function createExpoPushProvider(config = {}) {
|
|
171
|
+
const channel = 'push';
|
|
172
|
+
return {
|
|
173
|
+
channel,
|
|
174
|
+
name: 'expo-push',
|
|
175
|
+
async send(request) {
|
|
176
|
+
const [result] = await sendExpoPush([
|
|
177
|
+
{
|
|
178
|
+
to: request.to,
|
|
179
|
+
...(request.message.subject ? { title: request.message.subject } : {}),
|
|
180
|
+
body: request.message.text,
|
|
181
|
+
/* The row id travels in `data` so a tap can be traced back to the
|
|
182
|
+
notification that caused it without a second lookup. */
|
|
183
|
+
data: { notificationId: request.notificationId },
|
|
184
|
+
sound: config.defaultSound === undefined ? 'default' : config.defaultSound,
|
|
185
|
+
...(config.defaultChannelId ? { channelId: config.defaultChannelId } : {}),
|
|
186
|
+
},
|
|
187
|
+
], config);
|
|
188
|
+
const ticket = result?.ticket;
|
|
189
|
+
if (!ticket || ticket.status !== 'ok' || !ticket.id) {
|
|
190
|
+
const reason = ticket?.details?.error ?? ticket?.message ?? 'unknown error';
|
|
191
|
+
/* A dead token will never succeed; retrying it wastes attempts and keeps
|
|
192
|
+
pushing at an app that is gone. */
|
|
193
|
+
if (isDeviceGone(ticket)) {
|
|
194
|
+
throw new ProviderHardError(`[notify:push-expo] device not registered: ${request.to}`);
|
|
195
|
+
}
|
|
196
|
+
throw new ProviderSendError(`[notify:push-expo] rejected: ${reason}`);
|
|
197
|
+
}
|
|
198
|
+
return {
|
|
199
|
+
providerMessageId: ticket.id,
|
|
200
|
+
acceptedAtMs: Date.now(),
|
|
201
|
+
channel,
|
|
202
|
+
};
|
|
203
|
+
},
|
|
204
|
+
};
|
|
205
|
+
}
|
|
206
|
+
//# sourceMappingURL=push-expo.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"push-expo.js","sourceRoot":"","sources":["../../src/providers/push-expo.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAqCG;AAGH,OAAO,EACL,iBAAiB,EACjB,iBAAiB,GAIlB,MAAM,YAAY,CAAC;AAEpB,MAAM,QAAQ,GAAG,sCAAsC,CAAC;AACxD,MAAM,YAAY,GAAG,6CAA6C,CAAC;AAEnE,sDAAsD;AACtD,MAAM,UAAU,GAAG,GAAG,CAAC;AACvB,6DAA6D;AAC7D,MAAM,cAAc,GAAG,IAAI,CAAC;AAyD5B;;;;;;GAMG;AACH,MAAM,UAAU,YAAY,CAC1B,MAAoD;IAEpD,OAAO,MAAM,EAAE,OAAO,EAAE,KAAK,KAAK,qBAAqB,CAAC;AAC1D,CAAC;AAED,SAAS,OAAO,CAAC,WAA2B;IAC1C,OAAO;QACL,cAAc,EAAE,kBAAkB;QAClC,MAAM,EAAE,kBAAkB;QAC1B,GAAG,CAAC,WAAW,CAAC,CAAC,CAAC,EAAE,aAAa,EAAE,UAAU,WAAW,E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,OAAO,CAAC,IAAI;oBAC1B;8EAC0D;oBAC1D,IAAI,EAAE,EAAE,cAAc,EAAE,OAAO,CAAC,cAAc,EAAE;oBAChD,KAAK,EAAE,MAAM,CAAC,YAAY,KAAK,SAAS,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,MAAM,CAAC,YAAY;oBAC1E,GAAG,CAAC,MAAM,CAAC,gBAAgB,CAAC,CAAC,CAAC,EAAE,SAAS,EAAE,MAAM,CAAC,gBAAgB,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;iBAC3E;aACF,EACD,MAAM,CACP,CAAC;YAEF,MAAM,MAAM,GAAG,MAAM,EAAE,MAAM,CAAC;YAC9B,IAAI,CAAC,MAAM,IAAI,MAAM,CAAC,MAAM,KAAK,IAAI,IAAI,CAAC,MAAM,CAAC,EAAE,EAAE,CAAC;gBACpD,MAAM,MAAM,GAAG,MAAM,EAAE,OAAO,EAAE,KAAK,IAAI,MAAM,EAAE,OAAO,IAAI,eAAe,CAAC;gBAC5E;qDACqC;gBACrC,IAAI,YAAY,CAAC,MAAM,CAAC,EAAE,CAAC;oBACzB,MAAM,IAAI,iBAAiB,CACzB,6CAA6C,OAAO,CAAC,EAAE,EAAE,CAC1D,CAAC;gBACJ,CAAC;gBACD,MAAM,IAAI,iBAAiB,CAAC,gCAAgC,MAAM,EAAE,CAAC,CAAC;YACxE,CAAC;YAED,OAAO;gBACL,iBAAiB,EAAE,MAAM,CAAC,EAAE;gBAC5B,YAAY,EAAE,IAAI,CAAC,GAAG,EAAE;gBACxB,OAAO;aACR,CAAC;QACJ,CAAC;KACF,CAAC;AACJ,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@venturekit/notify",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.33",
|
|
4
4
|
"description": "Transactional notifications for VentureKit — email (SES), WhatsApp (Meta Cloud), with a Postgres outbox + cron dispatcher.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -48,6 +48,10 @@
|
|
|
48
48
|
"types": "./dist/providers/email-ses.d.ts",
|
|
49
49
|
"import": "./dist/providers/email-ses.js"
|
|
50
50
|
},
|
|
51
|
+
"./providers/push-expo": {
|
|
52
|
+
"types": "./dist/providers/push-expo.d.ts",
|
|
53
|
+
"import": "./dist/providers/push-expo.js"
|
|
54
|
+
},
|
|
51
55
|
"./providers/whatsapp-meta": {
|
|
52
56
|
"types": "./dist/providers/whatsapp-meta.d.ts",
|
|
53
57
|
"import": "./dist/providers/whatsapp-meta.js"
|
|
@@ -60,6 +64,10 @@
|
|
|
60
64
|
"types": "./dist/providers/whatsapp-meta-language.d.ts",
|
|
61
65
|
"import": "./dist/providers/whatsapp-meta-language.js"
|
|
62
66
|
},
|
|
67
|
+
"./policy": {
|
|
68
|
+
"types": "./dist/policy/index.d.ts",
|
|
69
|
+
"import": "./dist/policy/index.js"
|
|
70
|
+
},
|
|
63
71
|
"./store/postgres": {
|
|
64
72
|
"types": "./dist/store/postgres.d.ts",
|
|
65
73
|
"import": "./dist/store/postgres.js"
|
|
@@ -84,11 +92,11 @@
|
|
|
84
92
|
"outbox"
|
|
85
93
|
],
|
|
86
94
|
"dependencies": {
|
|
87
|
-
"@venturekit/core": "0.0.
|
|
95
|
+
"@venturekit/core": "0.0.33"
|
|
88
96
|
},
|
|
89
97
|
"peerDependencies": {
|
|
90
|
-
"@venturekit/data": "0.0.
|
|
91
|
-
"@venturekit/runtime": "0.0.
|
|
98
|
+
"@venturekit/data": "0.0.33",
|
|
99
|
+
"@venturekit/runtime": "0.0.33",
|
|
92
100
|
"@aws-sdk/client-sesv2": "^3.1126.0",
|
|
93
101
|
"@aws-sdk/client-secrets-manager": "^3.1126.0"
|
|
94
102
|
},
|
|
@@ -107,8 +115,8 @@
|
|
|
107
115
|
}
|
|
108
116
|
},
|
|
109
117
|
"devDependencies": {
|
|
110
|
-
"@venturekit/data": "0.0.
|
|
111
|
-
"@venturekit/runtime": "0.0.
|
|
118
|
+
"@venturekit/data": "0.0.33",
|
|
119
|
+
"@venturekit/runtime": "0.0.33",
|
|
112
120
|
"@aws-sdk/client-sesv2": "^3.1126.0",
|
|
113
121
|
"@aws-sdk/client-secrets-manager": "^3.1126.0",
|
|
114
122
|
"@types/aws-lambda": "^8.10.131",
|