@venturekit/notify 0.0.46 → 0.0.47
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +105 -3
- package/dist/client.d.ts +11 -0
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +118 -13
- package/dist/client.js.map +1 -1
- package/dist/devices/devices.d.ts +135 -0
- package/dist/devices/devices.d.ts.map +1 -0
- package/dist/devices/devices.js +178 -0
- package/dist/devices/devices.js.map +1 -0
- package/dist/devices/index.d.ts +6 -0
- package/dist/devices/index.d.ts.map +1 -0
- package/dist/devices/index.js +3 -0
- package/dist/devices/index.js.map +1 -0
- package/dist/devices/push.d.ts +84 -0
- package/dist/devices/push.d.ts.map +1 -0
- package/dist/devices/push.js +86 -0
- package/dist/devices/push.js.map +1 -0
- package/dist/dispatcher.d.ts.map +1 -1
- package/dist/dispatcher.js +6 -1
- package/dist/dispatcher.js.map +1 -1
- package/dist/inbox/inbox.d.ts +3 -2
- package/dist/inbox/inbox.d.ts.map +1 -1
- package/dist/inbox/inbox.js.map +1 -1
- package/dist/index.d.ts +4 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +4 -2
- package/dist/index.js.map +1 -1
- package/dist/migrations/0000_vk_notify_push_devices.sql +73 -0
- package/dist/migrations/0000_vk_notify_templates.sql +75 -0
- package/dist/migrations/vk_notify_006_dedupe_key.sql +19 -0
- package/dist/providers/index.d.ts +1 -1
- package/dist/providers/index.d.ts.map +1 -1
- package/dist/providers/index.js +1 -1
- package/dist/providers/index.js.map +1 -1
- package/dist/providers/push-expo.d.ts +3 -1
- package/dist/providers/push-expo.d.ts.map +1 -1
- package/dist/providers/push-expo.js +5 -3
- package/dist/providers/push-expo.js.map +1 -1
- package/dist/providers/types.d.ts +11 -0
- package/dist/providers/types.d.ts.map +1 -1
- package/dist/providers/types.js +15 -0
- package/dist/providers/types.js.map +1 -1
- package/dist/querier.d.ts +20 -0
- package/dist/querier.d.ts.map +1 -0
- package/dist/querier.js +16 -0
- package/dist/querier.js.map +1 -0
- package/dist/store/index.d.ts +1 -0
- package/dist/store/index.d.ts.map +1 -1
- package/dist/store/index.js +1 -0
- package/dist/store/index.js.map +1 -1
- package/dist/store/postgres.d.ts.map +1 -1
- package/dist/store/postgres.js +23 -4
- package/dist/store/postgres.js.map +1 -1
- package/dist/store/types.d.ts +18 -1
- package/dist/store/types.d.ts.map +1 -1
- package/dist/store/types.js +14 -1
- package/dist/store/types.js.map +1 -1
- package/dist/templates/index.d.ts +5 -0
- package/dist/templates/index.d.ts.map +1 -0
- package/dist/templates/index.js +3 -0
- package/dist/templates/index.js.map +1 -0
- package/dist/templates/stored.d.ts +200 -0
- package/dist/templates/stored.d.ts.map +1 -0
- package/dist/templates/stored.js +248 -0
- package/dist/templates/stored.js.map +1 -0
- package/dist/types.d.ts +22 -0
- package/dist/types.d.ts.map +1 -1
- package/package.json +14 -6
- package/src/migrations/0000_vk_notify_push_devices.sql +73 -0
- package/src/migrations/0000_vk_notify_templates.sql +75 -0
- package/src/migrations/vk_notify_006_dedupe_key.sql +19 -0
package/dist/store/types.js
CHANGED
|
@@ -10,5 +10,18 @@
|
|
|
10
10
|
* {@link NotificationRow}); persistence-layer types (`Date`,
|
|
11
11
|
* `Timestamp`) stay inside the adapter.
|
|
12
12
|
*/
|
|
13
|
-
|
|
13
|
+
/**
|
|
14
|
+
* Thrown by {@link NotifyStore.createNotification} when the input's `dedupeKey` is already
|
|
15
|
+
* held: carries the row that holds it. The client turns it into `EnqueueResult.duplicate`.
|
|
16
|
+
* A store must not let two rows hold one key — the Postgres store's unique index decides,
|
|
17
|
+
* so two enqueues at once cannot both write.
|
|
18
|
+
*/
|
|
19
|
+
export class DuplicateNotificationError extends Error {
|
|
20
|
+
existing;
|
|
21
|
+
constructor(existing) {
|
|
22
|
+
super(`[venturekit/notify] a notification already holds dedupe key '${existing.dedupeKey ?? ''}' (${existing.id})`);
|
|
23
|
+
this.name = 'DuplicateNotificationError';
|
|
24
|
+
this.existing = existing;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
14
27
|
//# sourceMappingURL=types.js.map
|
package/dist/store/types.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/store/types.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG"}
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/store/types.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAqBH;;;;;GAKG;AACH,MAAM,OAAO,0BAA2B,SAAQ,KAAK;IAC1C,QAAQ,CAAkB;IACnC,YAAY,QAAyB;QACnC,KAAK,CAAC,gEAAgE,QAAQ,CAAC,SAAS,IAAI,EAAE,MAAM,QAAQ,CAAC,EAAE,GAAG,CAAC,CAAC;QACpH,IAAI,CAAC,IAAI,GAAG,4BAA4B,CAAC;QACzC,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;IAC3B,CAAC;CACF"}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export { listStoredTemplates, getStoredTemplate, saveTemplateDraft, approveTemplateDraft, discardTemplateDraft, approvedTemplateVariants, resolveStoredTemplate, renderStoredTemplate, publishDefaultTemplate, StoredTemplateError, } from './stored.js';
|
|
2
|
+
export type { StoredTemplate, StoredTemplateErrorCode, ListStoredTemplatesOptions, SaveTemplateDraftInput, ResolveStoredTemplateInput, RenderStoredTemplateOutcome, PublishDefaultTemplateInput, } from './stored.js';
|
|
3
|
+
export { createTemplateRegistry, TemplateNotFoundError, type TemplateRegistry } from './registry.js';
|
|
4
|
+
export type { Querier as TemplatesQuerier } from '../querier.js';
|
|
5
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/templates/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,mBAAmB,EACnB,iBAAiB,EACjB,iBAAiB,EACjB,oBAAoB,EACpB,oBAAoB,EACpB,wBAAwB,EACxB,qBAAqB,EACrB,oBAAoB,EACpB,sBAAsB,EACtB,mBAAmB,GACpB,MAAM,aAAa,CAAC;AACrB,YAAY,EACV,cAAc,EACd,uBAAuB,EACvB,0BAA0B,EAC1B,sBAAsB,EACtB,0BAA0B,EAC1B,2BAA2B,EAC3B,2BAA2B,GAC5B,MAAM,aAAa,CAAC;AACrB,OAAO,EAAE,sBAAsB,EAAE,qBAAqB,EAAE,KAAK,gBAAgB,EAAE,MAAM,eAAe,CAAC;AACrG,YAAY,EAAE,OAAO,IAAI,gBAAgB,EAAE,MAAM,eAAe,CAAC"}
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
export { listStoredTemplates, getStoredTemplate, saveTemplateDraft, approveTemplateDraft, discardTemplateDraft, approvedTemplateVariants, resolveStoredTemplate, renderStoredTemplate, publishDefaultTemplate, StoredTemplateError, } from './stored.js';
|
|
2
|
+
export { createTemplateRegistry, TemplateNotFoundError } from './registry.js';
|
|
3
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/templates/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,mBAAmB,EACnB,iBAAiB,EACjB,iBAAiB,EACjB,oBAAoB,EACpB,oBAAoB,EACpB,wBAAwB,EACxB,qBAAqB,EACrB,oBAAoB,EACpB,sBAAsB,EACtB,mBAAmB,GACpB,MAAM,aAAa,CAAC;AAUrB,OAAO,EAAE,sBAAsB,EAAE,qBAAqB,EAAyB,MAAM,eAAe,CAAC"}
|
|
@@ -0,0 +1,200 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Templates stored as data (`vk_notification_templates`, this package's migrations): the
|
|
3
|
+
* product's defaults and each tenant's own copy, versioned, a draft until approved.
|
|
4
|
+
*
|
|
5
|
+
* ```ts
|
|
6
|
+
* import { saveTemplateDraft, approveTemplateDraft, renderStoredTemplate } from '@venturekit/notify/templates';
|
|
7
|
+
*
|
|
8
|
+
* // a tenant rewords the product's default — a draft, inheriting its placeholders
|
|
9
|
+
* const draft = await saveTemplateDraft(tx.query, { tenantId, key: 'trip_started', locale: 'fr', title, body, createdBy: userId });
|
|
10
|
+
* await approveTemplateDraft(tx.query, { id: draft.id, tenantId, approvedBy: userId });
|
|
11
|
+
*
|
|
12
|
+
* // the send path: the tenant's approved copy, else the default, in the reader's language
|
|
13
|
+
* const out = await renderStoredTemplate(tx.query, { key: 'trip_started', tenantId, preferred: [parent.locale, school.locale], values });
|
|
14
|
+
* ```
|
|
15
|
+
*
|
|
16
|
+
* The rules, which are the reason to keep this in one place:
|
|
17
|
+
*
|
|
18
|
+
* - **Only approved rows are sent.** A draft is work in progress; the send path never reads it.
|
|
19
|
+
* - **An approved row never changes.** Rewording it writes the next version as a draft, so what
|
|
20
|
+
* went out under version 2 can be read back for as long as the row is kept.
|
|
21
|
+
* - **A placeholder must be declared.** Approval refuses `{bus_colour}` in a text whose declared
|
|
22
|
+
* variables do not have it, and a tenant's copy declares exactly what its default declares —
|
|
23
|
+
* it cannot invent a placeholder the sender never fills.
|
|
24
|
+
* - **Some defaults are the product's own words** (`overridable` false): an operator notice, a
|
|
25
|
+
* legal text. No tenant copy of those is written, or read.
|
|
26
|
+
* - **A tenant's copy wins over the default, per locale** — a tenant that translated a message
|
|
27
|
+
* into French only still sends the product's English to English readers.
|
|
28
|
+
*
|
|
29
|
+
* Rendering is `renderStringTemplate`'s (`policy/string-templates.ts`): an unresolved
|
|
30
|
+
* placeholder blocks the send rather than shipping a hole.
|
|
31
|
+
*
|
|
32
|
+
* `tenantId` names the tenant whose copies are in play; `null` (or absent, where optional)
|
|
33
|
+
* means the defaults alone. A multi-tenant project also installs its policy on the table, so a
|
|
34
|
+
* query under one tenant's scope cannot read another's drafts whatever it passes.
|
|
35
|
+
*/
|
|
36
|
+
import { type RenderStringTemplateOptions, type StringTemplate } from '../policy/string-templates.js';
|
|
37
|
+
import type { Querier } from '../querier.js';
|
|
38
|
+
export interface StoredTemplate extends StringTemplate {
|
|
39
|
+
id: string;
|
|
40
|
+
/** `null`: the product's default. */
|
|
41
|
+
tenantId: string | null;
|
|
42
|
+
version: number;
|
|
43
|
+
category: string | null;
|
|
44
|
+
/** On a default: whether a tenant may write its own copy. */
|
|
45
|
+
overridable: boolean;
|
|
46
|
+
/** `null`: a draft, never sent. */
|
|
47
|
+
approvedAt: Date | null;
|
|
48
|
+
approvedBy: string | null;
|
|
49
|
+
createdBy: string | null;
|
|
50
|
+
createdAt: Date;
|
|
51
|
+
updatedAt: Date;
|
|
52
|
+
}
|
|
53
|
+
export type StoredTemplateErrorCode =
|
|
54
|
+
/** A title or body that is blank. */
|
|
55
|
+
'empty'
|
|
56
|
+
/** A tenant copy of a key the product has no default for. */
|
|
57
|
+
| 'no_default'
|
|
58
|
+
/** A tenant copy of a default that is the product's own words. */
|
|
59
|
+
| 'not_overridable'
|
|
60
|
+
/** A text using a placeholder that is not declared. */
|
|
61
|
+
| 'undeclared_placeholders'
|
|
62
|
+
/** No such row for this tenant (or not a draft, for a discard). */
|
|
63
|
+
| 'not_found'
|
|
64
|
+
/** Approving a row that already is. */
|
|
65
|
+
| 'already_approved';
|
|
66
|
+
/** A refusal the caller can phrase: `code` says which, `placeholders` / `allowed` say what. */
|
|
67
|
+
export declare class StoredTemplateError extends Error {
|
|
68
|
+
readonly code: StoredTemplateErrorCode;
|
|
69
|
+
/** For `undeclared_placeholders`: the ones used but not declared. */
|
|
70
|
+
readonly placeholders: string[];
|
|
71
|
+
/** For `undeclared_placeholders`: the declared set. */
|
|
72
|
+
readonly allowed: string[];
|
|
73
|
+
constructor(code: StoredTemplateErrorCode, message: string, detail?: {
|
|
74
|
+
placeholders?: string[];
|
|
75
|
+
allowed?: string[];
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
export interface ListStoredTemplatesOptions {
|
|
79
|
+
/** The tenant whose copies to include beside the defaults; `null` = defaults only; absent = every row. */
|
|
80
|
+
tenantId?: string | null;
|
|
81
|
+
key?: string;
|
|
82
|
+
/** Keys starting with this (e.g. `'announcement.'`). */
|
|
83
|
+
keyPrefix?: string;
|
|
84
|
+
}
|
|
85
|
+
/** Defaults and a tenant's rows, every version — what an editor shows as each key's lineage. */
|
|
86
|
+
export declare function listStoredTemplates(querier: Querier, options?: ListStoredTemplatesOptions): Promise<StoredTemplate[]>;
|
|
87
|
+
/**
|
|
88
|
+
* One row by id, as a tenant may see it: its own (draft or approved) or a default. `null` when
|
|
89
|
+
* there is none — or another tenant's, or not a uuid. `tenantId` null: defaults only; absent: any row.
|
|
90
|
+
*/
|
|
91
|
+
export declare function getStoredTemplate(querier: Querier, input: {
|
|
92
|
+
id: string;
|
|
93
|
+
tenantId?: string | null;
|
|
94
|
+
}): Promise<StoredTemplate | null>;
|
|
95
|
+
export interface SaveTemplateDraftInput {
|
|
96
|
+
tenantId: string;
|
|
97
|
+
key: string;
|
|
98
|
+
locale: string;
|
|
99
|
+
title: string;
|
|
100
|
+
body: string;
|
|
101
|
+
createdBy?: string | null;
|
|
102
|
+
/**
|
|
103
|
+
* A tenant's own key with no default behind it (a snippet the tenant keeps for itself). Its
|
|
104
|
+
* placeholders are `variables` when given — checked like a copy's — else whatever the text
|
|
105
|
+
* uses. Default `false`: the row is a copy of the product's default, from which it takes its
|
|
106
|
+
* declared placeholders and category.
|
|
107
|
+
*/
|
|
108
|
+
standalone?: boolean;
|
|
109
|
+
/** For a standalone row: its declared placeholders. */
|
|
110
|
+
variables?: readonly string[];
|
|
111
|
+
/** For a standalone row: its category. */
|
|
112
|
+
category?: string | null;
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* Write a tenant's version of a key in a locale. Its open draft is reworded in place; when the
|
|
116
|
+
* latest version is approved (or there is none) the next version is written, a draft. Refused
|
|
117
|
+
* (`StoredTemplateError`) for a blank text, a key with no default (unless `standalone`), a
|
|
118
|
+
* default that is not `overridable`, and a placeholder that is not declared.
|
|
119
|
+
*/
|
|
120
|
+
export declare function saveTemplateDraft(querier: Querier, input: SaveTemplateDraftInput): Promise<StoredTemplate>;
|
|
121
|
+
/**
|
|
122
|
+
* Record the approval of a tenant's draft: from here the row is immutable and the send path
|
|
123
|
+
* may use it. Scoped to `tenantId` — a lookup by id alone would let one tenant approve
|
|
124
|
+
* another's draft — so a default is never approved through this. Refused for a row that is not
|
|
125
|
+
* the tenant's, one already approved, and a text with an undeclared placeholder.
|
|
126
|
+
*/
|
|
127
|
+
export declare function approveTemplateDraft(querier: Querier, input: {
|
|
128
|
+
id: string;
|
|
129
|
+
tenantId: string;
|
|
130
|
+
approvedBy?: string | null;
|
|
131
|
+
}): Promise<StoredTemplate>;
|
|
132
|
+
/** Drop a tenant's draft — never an approved version: those are history. Returns whether one went. */
|
|
133
|
+
export declare function discardTemplateDraft(querier: Querier, input: {
|
|
134
|
+
id: string;
|
|
135
|
+
tenantId: string;
|
|
136
|
+
}): Promise<boolean>;
|
|
137
|
+
/**
|
|
138
|
+
* What the send path may use for a key: one row per locale — the tenant's latest approved copy
|
|
139
|
+
* where it has one (and the default is `overridable`), else the default's latest approved
|
|
140
|
+
* version. Empty when nothing approved exists.
|
|
141
|
+
*/
|
|
142
|
+
export declare function approvedTemplateVariants(querier: Querier, input: {
|
|
143
|
+
key: string;
|
|
144
|
+
tenantId?: string | null;
|
|
145
|
+
}): Promise<StoredTemplate[]>;
|
|
146
|
+
export interface ResolveStoredTemplateInput {
|
|
147
|
+
key: string;
|
|
148
|
+
tenantId?: string | null;
|
|
149
|
+
/** Preferred locales, most specific first: the reader's, then the tenant's. */
|
|
150
|
+
preferred: readonly (string | null | undefined)[];
|
|
151
|
+
/** Tried after `preferred` (a product's house language). */
|
|
152
|
+
fallbacks?: readonly string[];
|
|
153
|
+
}
|
|
154
|
+
/** The one version to send for a reader: {@link approvedTemplateVariants}, then `resolveLocale` over them. */
|
|
155
|
+
export declare function resolveStoredTemplate(querier: Querier, input: ResolveStoredTemplateInput): Promise<StoredTemplate | null>;
|
|
156
|
+
export type RenderStoredTemplateOutcome = {
|
|
157
|
+
ok: true;
|
|
158
|
+
title: string;
|
|
159
|
+
body: string;
|
|
160
|
+
template: StoredTemplate;
|
|
161
|
+
} | {
|
|
162
|
+
ok: false;
|
|
163
|
+
reason: 'not_found';
|
|
164
|
+
} | {
|
|
165
|
+
ok: false;
|
|
166
|
+
reason: 'missing';
|
|
167
|
+
missing: string[];
|
|
168
|
+
template: StoredTemplate;
|
|
169
|
+
};
|
|
170
|
+
/**
|
|
171
|
+
* Resolve and render: the text to send, or why not — no approved version at all, or a value
|
|
172
|
+
* missing for a placeholder the chosen version uses (a send blocked, never a hole shipped).
|
|
173
|
+
*/
|
|
174
|
+
export declare function renderStoredTemplate(querier: Querier, input: ResolveStoredTemplateInput & {
|
|
175
|
+
values: Record<string, string | number | null | undefined>;
|
|
176
|
+
} & RenderStringTemplateOptions): Promise<RenderStoredTemplateOutcome>;
|
|
177
|
+
export interface PublishDefaultTemplateInput {
|
|
178
|
+
key: string;
|
|
179
|
+
locale: string;
|
|
180
|
+
title: string;
|
|
181
|
+
body: string;
|
|
182
|
+
/** Default: the placeholders the text uses. */
|
|
183
|
+
variables?: readonly string[];
|
|
184
|
+
category?: string | null;
|
|
185
|
+
/** Default `true`. */
|
|
186
|
+
overridable?: boolean;
|
|
187
|
+
/** Recorded as the approver too. Default `'system'`. */
|
|
188
|
+
publishedBy?: string | null;
|
|
189
|
+
}
|
|
190
|
+
/**
|
|
191
|
+
* Ship a product default from code (a seed, a deploy step): a new approved version when the
|
|
192
|
+
* text, placeholders, category or `overridable` differ from the latest one, nothing when they
|
|
193
|
+
* do not — so it can run on every deploy. A default is never edited in place, for the same
|
|
194
|
+
* reason a tenant's approved copy is not.
|
|
195
|
+
*/
|
|
196
|
+
export declare function publishDefaultTemplate(querier: Querier, input: PublishDefaultTemplateInput): Promise<{
|
|
197
|
+
template: StoredTemplate;
|
|
198
|
+
published: boolean;
|
|
199
|
+
}>;
|
|
200
|
+
//# sourceMappingURL=stored.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"stored.d.ts","sourceRoot":"","sources":["../../src/templates/stored.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkCG;AAEH,OAAO,EAKL,KAAK,2BAA2B,EAChC,KAAK,cAAc,EACpB,MAAM,+BAA+B,CAAC;AACvC,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC;AAE7C,MAAM,WAAW,cAAe,SAAQ,cAAc;IACpD,EAAE,EAAE,MAAM,CAAC;IACX,qCAAqC;IACrC,QAAQ,EAAE,MAAM,GAAG,IAAI,CAAC;IACxB,OAAO,EAAE,MAAM,CAAC;IAChB,QAAQ,EAAE,MAAM,GAAG,IAAI,CAAC;IACxB,6DAA6D;IAC7D,WAAW,EAAE,OAAO,CAAC;IACrB,mCAAmC;IACnC,UAAU,EAAE,IAAI,GAAG,IAAI,CAAC;IACxB,UAAU,EAAE,MAAM,GAAG,IAAI,CAAC;IAC1B,SAAS,EAAE,MAAM,GAAG,IAAI,CAAC;IACzB,SAAS,EAAE,IAAI,CAAC;IAChB,SAAS,EAAE,IAAI,CAAC;CACjB;AAED,MAAM,MAAM,uBAAuB;AACjC,qCAAqC;AACnC,OAAO;AACT,6DAA6D;GAC3D,YAAY;AACd,kEAAkE;GAChE,iBAAiB;AACnB,uDAAuD;GACrD,yBAAyB;AAC3B,mEAAmE;GACjE,WAAW;AACb,uCAAuC;GACrC,kBAAkB,CAAC;AAEvB,+FAA+F;AAC/F,qBAAa,mBAAoB,SAAQ,KAAK;IAC5C,QAAQ,CAAC,IAAI,EAAE,uBAAuB,CAAC;IACvC,qEAAqE;IACrE,QAAQ,CAAC,YAAY,EAAE,MAAM,EAAE,CAAC;IAChC,uDAAuD;IACvD,QAAQ,CAAC,OAAO,EAAE,MAAM,EAAE,CAAC;gBACf,IAAI,EAAE,uBAAuB,EAAE,OAAO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,EAAE,EAAE,KAAK,CAAC;IAAC,MAAM,EAAE,SAAS,CAAC;IAAC,OAAO,EAAE,MAAM,EAAE,CAAC;IAAC,QAAQ,EAAE,cAAc,CAAA;CAAE,CAAC;AAElF;;;GAGG;AACH,wBAAsB,oBAAoB,CACxC,OAAO,EAAE,OAAO,EAChB,KAAK,EAAE,0BAA0B,GAAG;IAAE,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,GAAG,SAAS,CAAC,CAAA;CAAE,GAAG,2BAA2B,GAC/H,OAAO,CAAC,2BAA2B,CAAC,CAKtC;AAED,MAAM,WAAW,2BAA2B;IAC1C,GAAG,EAAE,MAAM,CAAC;IACZ,MAAM,EAAE,MAAM,CAAC;IACf,KAAK,EAAE,MAAM,CAAC;IACd,IAAI,EAAE,MAAM,CAAC;IACb,+CAA+C;IAC/C,SAAS,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;IAC9B,QAAQ,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACzB,sBAAsB;IACtB,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB,wDAAwD;IACxD,WAAW,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;CAC7B;AAED;;;;;GAKG;AACH,wBAAsB,sBAAsB,CAC1C,OAAO,EAAE,OAAO,EAChB,KAAK,EAAE,2BAA2B,GACjC,OAAO,CAAC;IAAE,QAAQ,EAAE,cAAc,CAAC;IAAC,SAAS,EAAE,OAAO,CAAA;CAAE,CAAC,CAkC3D"}
|
|
@@ -0,0 +1,248 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Templates stored as data (`vk_notification_templates`, this package's migrations): the
|
|
3
|
+
* product's defaults and each tenant's own copy, versioned, a draft until approved.
|
|
4
|
+
*
|
|
5
|
+
* ```ts
|
|
6
|
+
* import { saveTemplateDraft, approveTemplateDraft, renderStoredTemplate } from '@venturekit/notify/templates';
|
|
7
|
+
*
|
|
8
|
+
* // a tenant rewords the product's default — a draft, inheriting its placeholders
|
|
9
|
+
* const draft = await saveTemplateDraft(tx.query, { tenantId, key: 'trip_started', locale: 'fr', title, body, createdBy: userId });
|
|
10
|
+
* await approveTemplateDraft(tx.query, { id: draft.id, tenantId, approvedBy: userId });
|
|
11
|
+
*
|
|
12
|
+
* // the send path: the tenant's approved copy, else the default, in the reader's language
|
|
13
|
+
* const out = await renderStoredTemplate(tx.query, { key: 'trip_started', tenantId, preferred: [parent.locale, school.locale], values });
|
|
14
|
+
* ```
|
|
15
|
+
*
|
|
16
|
+
* The rules, which are the reason to keep this in one place:
|
|
17
|
+
*
|
|
18
|
+
* - **Only approved rows are sent.** A draft is work in progress; the send path never reads it.
|
|
19
|
+
* - **An approved row never changes.** Rewording it writes the next version as a draft, so what
|
|
20
|
+
* went out under version 2 can be read back for as long as the row is kept.
|
|
21
|
+
* - **A placeholder must be declared.** Approval refuses `{bus_colour}` in a text whose declared
|
|
22
|
+
* variables do not have it, and a tenant's copy declares exactly what its default declares —
|
|
23
|
+
* it cannot invent a placeholder the sender never fills.
|
|
24
|
+
* - **Some defaults are the product's own words** (`overridable` false): an operator notice, a
|
|
25
|
+
* legal text. No tenant copy of those is written, or read.
|
|
26
|
+
* - **A tenant's copy wins over the default, per locale** — a tenant that translated a message
|
|
27
|
+
* into French only still sends the product's English to English readers.
|
|
28
|
+
*
|
|
29
|
+
* Rendering is `renderStringTemplate`'s (`policy/string-templates.ts`): an unresolved
|
|
30
|
+
* placeholder blocks the send rather than shipping a hole.
|
|
31
|
+
*
|
|
32
|
+
* `tenantId` names the tenant whose copies are in play; `null` (or absent, where optional)
|
|
33
|
+
* means the defaults alone. A multi-tenant project also installs its policy on the table, so a
|
|
34
|
+
* query under one tenant's scope cannot read another's drafts whatever it passes.
|
|
35
|
+
*/
|
|
36
|
+
import { placeholdersOf, renderStringTemplate, resolveLocale, undeclaredPlaceholders, } from '../policy/string-templates.js';
|
|
37
|
+
/** A refusal the caller can phrase: `code` says which, `placeholders` / `allowed` say what. */
|
|
38
|
+
export class StoredTemplateError extends Error {
|
|
39
|
+
code;
|
|
40
|
+
/** For `undeclared_placeholders`: the ones used but not declared. */
|
|
41
|
+
placeholders;
|
|
42
|
+
/** For `undeclared_placeholders`: the declared set. */
|
|
43
|
+
allowed;
|
|
44
|
+
constructor(code, message, detail = {}) {
|
|
45
|
+
super(`[venturekit/notify] ${message}`);
|
|
46
|
+
this.name = 'StoredTemplateError';
|
|
47
|
+
this.code = code;
|
|
48
|
+
this.placeholders = detail.placeholders ?? [];
|
|
49
|
+
this.allowed = detail.allowed ?? [];
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
/** The row as {@link StoredTemplate}, its columns qualified by `alias` when the query joins the table to itself. */
|
|
53
|
+
const columnsOf = (alias = '') => {
|
|
54
|
+
const c = alias ? `${alias}.` : '';
|
|
55
|
+
return `${c}id, ${c}tenant_id AS "tenantId", ${c}key, ${c}locale, ${c}version, ${c}category, ${c}title, ${c}body, ${c}variables,
|
|
56
|
+
${c}overridable, ${c}approved_at AS "approvedAt", ${c}approved_by AS "approvedBy", ${c}created_by AS "createdBy",
|
|
57
|
+
${c}created_at AS "createdAt", ${c}updated_at AS "updatedAt"`;
|
|
58
|
+
};
|
|
59
|
+
const COLUMNS = columnsOf();
|
|
60
|
+
const UUID = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
|
|
61
|
+
function undeclaredError(template) {
|
|
62
|
+
const undeclared = undeclaredPlaceholders(template);
|
|
63
|
+
if (undeclared.length === 0)
|
|
64
|
+
return null;
|
|
65
|
+
return new StoredTemplateError('undeclared_placeholders', `'${template.key}' uses ${undeclared.map((v) => `{${v}}`).join(', ')}, which ${undeclared.length === 1 ? 'is' : 'are'} not declared`, { placeholders: undeclared, allowed: [...template.variables] });
|
|
66
|
+
}
|
|
67
|
+
/** Defaults and a tenant's rows, every version — what an editor shows as each key's lineage. */
|
|
68
|
+
export async function listStoredTemplates(querier, options = {}) {
|
|
69
|
+
const params = [];
|
|
70
|
+
const where = [];
|
|
71
|
+
if (options.tenantId === null)
|
|
72
|
+
where.push('tenant_id IS NULL');
|
|
73
|
+
else if (options.tenantId !== undefined) {
|
|
74
|
+
params.push(options.tenantId);
|
|
75
|
+
where.push(`(tenant_id IS NULL OR tenant_id = $${params.length})`);
|
|
76
|
+
}
|
|
77
|
+
if (options.key !== undefined) {
|
|
78
|
+
params.push(options.key);
|
|
79
|
+
where.push(`key = $${params.length}`);
|
|
80
|
+
}
|
|
81
|
+
if (options.keyPrefix !== undefined) {
|
|
82
|
+
params.push(`${options.keyPrefix.replace(/[\\%_]/g, (c) => `\\${c}`)}%`);
|
|
83
|
+
where.push(`key LIKE $${params.length}`);
|
|
84
|
+
}
|
|
85
|
+
return querier(`SELECT ${COLUMNS} FROM vk_notification_templates
|
|
86
|
+
${where.length > 0 ? `WHERE ${where.join(' AND ')}` : ''}
|
|
87
|
+
ORDER BY key, locale, (tenant_id IS NOT NULL), version`, params);
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* One row by id, as a tenant may see it: its own (draft or approved) or a default. `null` when
|
|
91
|
+
* there is none — or another tenant's, or not a uuid. `tenantId` null: defaults only; absent: any row.
|
|
92
|
+
*/
|
|
93
|
+
export async function getStoredTemplate(querier, input) {
|
|
94
|
+
if (!UUID.test(input.id))
|
|
95
|
+
return null;
|
|
96
|
+
const params = [input.id];
|
|
97
|
+
let scope = '';
|
|
98
|
+
if (input.tenantId === null)
|
|
99
|
+
scope = ' AND tenant_id IS NULL';
|
|
100
|
+
else if (input.tenantId !== undefined) {
|
|
101
|
+
params.push(input.tenantId);
|
|
102
|
+
scope = ' AND (tenant_id IS NULL OR tenant_id = $2)';
|
|
103
|
+
}
|
|
104
|
+
const [row] = await querier(`SELECT ${COLUMNS} FROM vk_notification_templates WHERE id = $1${scope}`, params);
|
|
105
|
+
return row ?? null;
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
* Write a tenant's version of a key in a locale. Its open draft is reworded in place; when the
|
|
109
|
+
* latest version is approved (or there is none) the next version is written, a draft. Refused
|
|
110
|
+
* (`StoredTemplateError`) for a blank text, a key with no default (unless `standalone`), a
|
|
111
|
+
* default that is not `overridable`, and a placeholder that is not declared.
|
|
112
|
+
*/
|
|
113
|
+
export async function saveTemplateDraft(querier, input) {
|
|
114
|
+
const title = input.title.trim();
|
|
115
|
+
const body = input.body.trim();
|
|
116
|
+
if (!input.tenantId)
|
|
117
|
+
throw new StoredTemplateError('not_found', 'saveTemplateDraft: tenantId is required (defaults are published, not drafted)');
|
|
118
|
+
if (!title || !body)
|
|
119
|
+
throw new StoredTemplateError('empty', `'${input.key}' needs a title and a body`);
|
|
120
|
+
let variables;
|
|
121
|
+
let category;
|
|
122
|
+
if (input.standalone) {
|
|
123
|
+
variables = input.variables ? [...new Set(input.variables)] : [...new Set([...placeholdersOf(title), ...placeholdersOf(body)])];
|
|
124
|
+
category = input.category ?? null;
|
|
125
|
+
}
|
|
126
|
+
else {
|
|
127
|
+
const [base] = await querier(`SELECT category, variables, overridable FROM vk_notification_templates
|
|
128
|
+
WHERE tenant_id IS NULL AND key = $1
|
|
129
|
+
ORDER BY (locale = $2) DESC, (approved_at IS NOT NULL) DESC, version DESC LIMIT 1`, [input.key, input.locale]);
|
|
130
|
+
if (!base)
|
|
131
|
+
throw new StoredTemplateError('no_default', `the product has no template '${input.key}' to copy`);
|
|
132
|
+
if (!base.overridable)
|
|
133
|
+
throw new StoredTemplateError('not_overridable', `'${input.key}' is the product's own text and has no tenant version`);
|
|
134
|
+
variables = base.variables;
|
|
135
|
+
category = base.category;
|
|
136
|
+
}
|
|
137
|
+
const refusal = undeclaredError({ key: input.key, locale: input.locale, title, body, variables });
|
|
138
|
+
if (refusal)
|
|
139
|
+
throw refusal;
|
|
140
|
+
const [latest] = await querier(`SELECT id, version, (approved_at IS NOT NULL) AS approved FROM vk_notification_templates
|
|
141
|
+
WHERE tenant_id = $1 AND key = $2 AND locale = $3 ORDER BY version DESC LIMIT 1`, [input.tenantId, input.key, input.locale]);
|
|
142
|
+
if (latest && !latest.approved) {
|
|
143
|
+
const [row] = await querier(`UPDATE vk_notification_templates SET title = $3, body = $4, variables = $5::text[], category = $6, updated_at = now()
|
|
144
|
+
WHERE id = $1 AND tenant_id = $2 AND approved_at IS NULL RETURNING ${COLUMNS}`, [latest.id, input.tenantId, title, body, variables, category]);
|
|
145
|
+
if (row)
|
|
146
|
+
return row;
|
|
147
|
+
}
|
|
148
|
+
const [row] = await querier(`INSERT INTO vk_notification_templates (tenant_id, key, locale, version, category, title, body, variables, created_by)
|
|
149
|
+
VALUES ($1, $2, $3, $4, $5, $6, $7, $8::text[], $9) RETURNING ${COLUMNS}`, [input.tenantId, input.key, input.locale, (latest?.version ?? 0) + 1, category, title, body, variables, input.createdBy ?? null]);
|
|
150
|
+
return row;
|
|
151
|
+
}
|
|
152
|
+
/**
|
|
153
|
+
* Record the approval of a tenant's draft: from here the row is immutable and the send path
|
|
154
|
+
* may use it. Scoped to `tenantId` — a lookup by id alone would let one tenant approve
|
|
155
|
+
* another's draft — so a default is never approved through this. Refused for a row that is not
|
|
156
|
+
* the tenant's, one already approved, and a text with an undeclared placeholder.
|
|
157
|
+
*/
|
|
158
|
+
export async function approveTemplateDraft(querier, input) {
|
|
159
|
+
if (!UUID.test(input.id) || !input.tenantId)
|
|
160
|
+
throw new StoredTemplateError('not_found', `no template ${input.id}`);
|
|
161
|
+
const [draft] = await querier(`SELECT ${COLUMNS} FROM vk_notification_templates WHERE id = $1 AND tenant_id = $2`, [input.id, input.tenantId]);
|
|
162
|
+
if (!draft)
|
|
163
|
+
throw new StoredTemplateError('not_found', `no template ${input.id}`);
|
|
164
|
+
if (draft.approvedAt)
|
|
165
|
+
throw new StoredTemplateError('already_approved', `template ${input.id} is already approved`);
|
|
166
|
+
const refusal = undeclaredError(draft);
|
|
167
|
+
if (refusal)
|
|
168
|
+
throw refusal;
|
|
169
|
+
const [row] = await querier(`UPDATE vk_notification_templates SET approved_at = now(), approved_by = $3, updated_at = now()
|
|
170
|
+
WHERE id = $1 AND tenant_id = $2 AND approved_at IS NULL RETURNING ${COLUMNS}`, [input.id, input.tenantId, input.approvedBy ?? null]);
|
|
171
|
+
if (!row)
|
|
172
|
+
throw new StoredTemplateError('already_approved', `template ${input.id} is already approved`);
|
|
173
|
+
return row;
|
|
174
|
+
}
|
|
175
|
+
/** Drop a tenant's draft — never an approved version: those are history. Returns whether one went. */
|
|
176
|
+
export async function discardTemplateDraft(querier, input) {
|
|
177
|
+
if (!UUID.test(input.id) || !input.tenantId)
|
|
178
|
+
return false;
|
|
179
|
+
const rows = await querier(`DELETE FROM vk_notification_templates WHERE id = $1 AND tenant_id = $2 AND approved_at IS NULL RETURNING id`, [input.id, input.tenantId]);
|
|
180
|
+
return rows.length > 0;
|
|
181
|
+
}
|
|
182
|
+
/**
|
|
183
|
+
* What the send path may use for a key: one row per locale — the tenant's latest approved copy
|
|
184
|
+
* where it has one (and the default is `overridable`), else the default's latest approved
|
|
185
|
+
* version. Empty when nothing approved exists.
|
|
186
|
+
*/
|
|
187
|
+
export async function approvedTemplateVariants(querier, input) {
|
|
188
|
+
const tenantId = input.tenantId ?? null;
|
|
189
|
+
return querier(`SELECT DISTINCT ON (t.locale) ${columnsOf('t')}
|
|
190
|
+
FROM vk_notification_templates t
|
|
191
|
+
WHERE t.key = $1 AND t.approved_at IS NOT NULL
|
|
192
|
+
AND (t.tenant_id IS NULL OR (t.tenant_id = $2 AND NOT EXISTS (
|
|
193
|
+
SELECT 1 FROM vk_notification_templates d WHERE d.tenant_id IS NULL AND d.key = t.key AND NOT d.overridable)))
|
|
194
|
+
ORDER BY t.locale, (t.tenant_id IS NOT NULL) DESC, t.version DESC`, [input.key, tenantId]);
|
|
195
|
+
}
|
|
196
|
+
/** The one version to send for a reader: {@link approvedTemplateVariants}, then `resolveLocale` over them. */
|
|
197
|
+
export async function resolveStoredTemplate(querier, input) {
|
|
198
|
+
const variants = await approvedTemplateVariants(querier, input);
|
|
199
|
+
const locale = resolveLocale({ preferred: input.preferred, available: variants.map((v) => v.locale), fallbacks: input.fallbacks });
|
|
200
|
+
return variants.find((v) => v.locale === locale) ?? null;
|
|
201
|
+
}
|
|
202
|
+
/**
|
|
203
|
+
* Resolve and render: the text to send, or why not — no approved version at all, or a value
|
|
204
|
+
* missing for a placeholder the chosen version uses (a send blocked, never a hole shipped).
|
|
205
|
+
*/
|
|
206
|
+
export async function renderStoredTemplate(querier, input) {
|
|
207
|
+
const template = await resolveStoredTemplate(querier, input);
|
|
208
|
+
if (!template)
|
|
209
|
+
return { ok: false, reason: 'not_found' };
|
|
210
|
+
const rendered = renderStringTemplate(template, input.values, input.escape ? { escape: input.escape } : {});
|
|
211
|
+
return rendered.ok ? { ok: true, title: rendered.title, body: rendered.body, template } : { ok: false, reason: 'missing', missing: rendered.missing, template };
|
|
212
|
+
}
|
|
213
|
+
/**
|
|
214
|
+
* Ship a product default from code (a seed, a deploy step): a new approved version when the
|
|
215
|
+
* text, placeholders, category or `overridable` differ from the latest one, nothing when they
|
|
216
|
+
* do not — so it can run on every deploy. A default is never edited in place, for the same
|
|
217
|
+
* reason a tenant's approved copy is not.
|
|
218
|
+
*/
|
|
219
|
+
export async function publishDefaultTemplate(querier, input) {
|
|
220
|
+
const title = input.title.trim();
|
|
221
|
+
const body = input.body.trim();
|
|
222
|
+
if (!title || !body)
|
|
223
|
+
throw new StoredTemplateError('empty', `'${input.key}' needs a title and a body`);
|
|
224
|
+
const variables = input.variables ? [...new Set(input.variables)] : [...new Set([...placeholdersOf(title), ...placeholdersOf(body)])];
|
|
225
|
+
const refusal = undeclaredError({ key: input.key, locale: input.locale, title, body, variables });
|
|
226
|
+
if (refusal)
|
|
227
|
+
throw refusal;
|
|
228
|
+
const category = input.category ?? null;
|
|
229
|
+
const overridable = input.overridable ?? true;
|
|
230
|
+
const [latest] = await querier(`SELECT ${COLUMNS} FROM vk_notification_templates
|
|
231
|
+
WHERE tenant_id IS NULL AND key = $1 AND locale = $2 AND approved_at IS NOT NULL ORDER BY version DESC LIMIT 1`, [input.key, input.locale]);
|
|
232
|
+
const same = latest &&
|
|
233
|
+
latest.title === title &&
|
|
234
|
+
latest.body === body &&
|
|
235
|
+
latest.category === category &&
|
|
236
|
+
latest.overridable === overridable &&
|
|
237
|
+
latest.variables.length === variables.length &&
|
|
238
|
+
latest.variables.every((v, i) => v === variables[i]);
|
|
239
|
+
if (same)
|
|
240
|
+
return { template: latest, published: false };
|
|
241
|
+
const by = input.publishedBy ?? 'system';
|
|
242
|
+
const [row] = await querier(`INSERT INTO vk_notification_templates (tenant_id, key, locale, version, category, title, body, variables, overridable, approved_at, approved_by, created_by)
|
|
243
|
+
SELECT NULL, $1, $2, COALESCE(MAX(version), 0) + 1, $3, $4, $5, $6::text[], $7, now(), $8, $8
|
|
244
|
+
FROM vk_notification_templates WHERE tenant_id IS NULL AND key = $1 AND locale = $2
|
|
245
|
+
RETURNING ${COLUMNS}`, [input.key, input.locale, category, title, body, variables, overridable, by]);
|
|
246
|
+
return { template: row, published: true };
|
|
247
|
+
}
|
|
248
|
+
//# sourceMappingURL=stored.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"stored.js","sourceRoot":"","sources":["../../src/templates/stored.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkCG;AAEH,OAAO,EACL,cAAc,EACd,oBAAoB,EACpB,aAAa,EACb,sBAAsB,GAGvB,MAAM,+BAA+B,CAAC;AAiCvC,+FAA+F;AAC/F,MAAM,OAAO,mBAAoB,SAAQ,KAAK;IACnC,IAAI,CAA0B;IACvC,qEAAqE;IAC5D,YAAY,CAAW;IAChC,uDAAuD;IAC9C,OAAO,CAAW;IAC3B,YAAY,IAA6B,EAAE,OAAe,EAAE,SAA0D,EAAE;QACtH,KAAK,CAAC,uBAAuB,OAAO,EAAE,CAAC,CAAC;QACxC,IAAI,CAAC,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AC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,KAAK,SAAS,CAAC,CAAC,CAAC,CAAC,CAAC;IACvD,IAAI,IAAI;QAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,SAAS,EAAE,KAAK,EAAE,CAAC;IAExD,MAAM,EAAE,GAAG,KAAK,CAAC,WAAW,IAAI,QAAQ,CAAC;IACzC,MAAM,CAAC,GAAG,CAAC,GAAG,MAAM,OAAO,CACzB;;;iBAGa,OAAO,EAAE,EACtB,CAAC,KAAK,CAAC,GAAG,EAAE,KAAK,CAAC,MAAM,EAAE,QAAQ,EAAE,KAAK,EAAE,IAAI,EAAE,SAAS,EAAE,WAAW,EAAE,EAAE,CAAC,CAC7E,CAAC;IACF,OAAO,EAAE,QAAQ,EAAE,GAAI,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC;AAC7C,CAAC"}
|
package/dist/types.d.ts
CHANGED
|
@@ -101,6 +101,8 @@ export interface NotificationRow {
|
|
|
101
101
|
attempts: number;
|
|
102
102
|
/** When the row was created. */
|
|
103
103
|
createdAtISO: string;
|
|
104
|
+
/** The key it was enqueued under ({@link EnqueueInput.dedupeKey}); `null` / absent without one. */
|
|
105
|
+
dedupeKey?: string | null;
|
|
104
106
|
}
|
|
105
107
|
/**
|
|
106
108
|
* Input to {@link NotifyClient.enqueue}. Either `recipientUserId` or
|
|
@@ -143,6 +145,15 @@ export interface EnqueueInput {
|
|
|
143
145
|
/** Loose FK to the originating entity. */
|
|
144
146
|
relatedKind?: string | null;
|
|
145
147
|
relatedId?: string | null;
|
|
148
|
+
/**
|
|
149
|
+
* Once per key: when a row already holds this key — whatever became of it, sent or
|
|
150
|
+
* cancelled — nothing is written and the earlier row comes back
|
|
151
|
+
* ({@link EnqueueResult.duplicate}). For a message that must go out once however often the
|
|
152
|
+
* code sending it runs: a digest retried by its cron, a webhook delivered twice. Global to
|
|
153
|
+
* the outbox, so a multi-tenant product puts the tenant in it. A push fanned out to a
|
|
154
|
+
* person's phones keys each phone's row `${dedupeKey}#${token}`.
|
|
155
|
+
*/
|
|
156
|
+
dedupeKey?: string;
|
|
146
157
|
}
|
|
147
158
|
/**
|
|
148
159
|
* Result of an enqueue call. Returned synchronously from the calling
|
|
@@ -151,6 +162,17 @@ export interface EnqueueInput {
|
|
|
151
162
|
export interface EnqueueResult {
|
|
152
163
|
/** Outbox row id (`notif_…`). */
|
|
153
164
|
id: string;
|
|
165
|
+
/**
|
|
166
|
+
* Every row written, when one call wrote several — a push to a person with a
|
|
167
|
+
* `pushDevices` directory is a row per live phone. `id` is the first of them.
|
|
168
|
+
* Absent when one row was written.
|
|
169
|
+
*/
|
|
170
|
+
ids?: string[];
|
|
171
|
+
/**
|
|
172
|
+
* `true`: a row already held the call's `dedupeKey`, so nothing was written now; `id` is
|
|
173
|
+
* that earlier row (`suppressed` says whether it was cancelled).
|
|
174
|
+
*/
|
|
175
|
+
duplicate?: boolean;
|
|
154
176
|
/** Channel the row was enqueued on (echoes input). */
|
|
155
177
|
channel: NotifyChannel;
|
|
156
178
|
/** Whether the row was suppressed by user preference / bounce log. */
|
package/dist/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AAEtD,YAAY,EAAE,aAAa,EAAE,CAAC;AAE9B;;;;;;;;;;;;;;;GAeG;AACH,MAAM,MAAM,kBAAkB,GAC1B,SAAS,GACT,MAAM,GACN,QAAQ,GACR,SAAS,GACT,WAAW,CAAC;AAEhB;;;;;;;;;;;;GAYG;AACH,MAAM,MAAM,aAAa,GAAG,MAAM,CAAC;AAEnC;;;;;GAKG;AACH,MAAM,WAAW,eAAe;IAC9B,6BAA6B;IAC7B,EAAE,EAAE,MAAM,CAAC;IACX;;;;;;OAMG;IACH,eAAe,EAAE,MAAM,G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,CAAC;QACtB,mDAAmD;QACnD,UAAU,CAAC,EAAE,OAAO,EAAE,CAAC;KACxB,CAAC;CACH;AAED;;;;;;;GAOG;AACH,MAAM,WAAW,cAAc,CAAC,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;IACzD;2EACuE;IACvE,GAAG,EAAE,MAAM,CAAC;IACZ,0CAA0C;IAC1C,OAAO,EAAE,aAAa,CAAC;IACvB;yEACqE;IACrE,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,4DAA4D;IAC5D,MAAM,EAAE,CAAC,OAAO,EAAE,CAAC,KAAK,eAAe,CAAC;CACzC;AAED;;;GAGG;AACH,MAAM,WAAW,yBAAyB;IACxC,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,EAAE,aAAa,CAAC;IACvB,QAAQ,EAAE,MAAM,CAAC;IACjB,OAAO,EAAE,OAAO,CAAC;IACjB,YAAY,EAAE,MAAM,CAAC;CACtB;AAED;;;;;GAKG;AACH,MAAM,WAAW,uBAAuB;IACtC,EAAE,EAAE,MAAM,CAAC;IACX,OAAO,EAAE,aAAa,CAAC;IACvB,OAAO,EAAE,MAAM,CAAC;IAChB,gEAAgE;IAChE,SAAS,EAAE,MAAM,CAAC;IAClB,uEAAuE;IACvE,iBAAiB,EAAE,MAAM,GAAG,IAAI,CAAC;IACjC,+DAA+D;IAC/D,QAAQ,EAAE,OAAO,CAAC;IAClB,yDAAyD;IACzD,GAAG,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAC7B,aAAa,EAAE,MAAM,CAAC;CACvB"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@venturekit/notify",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.47",
|
|
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",
|
|
@@ -76,6 +76,14 @@
|
|
|
76
76
|
"types": "./dist/inbox/index.d.ts",
|
|
77
77
|
"import": "./dist/inbox/index.js"
|
|
78
78
|
},
|
|
79
|
+
"./devices": {
|
|
80
|
+
"types": "./dist/devices/index.d.ts",
|
|
81
|
+
"import": "./dist/devices/index.js"
|
|
82
|
+
},
|
|
83
|
+
"./templates": {
|
|
84
|
+
"types": "./dist/templates/index.d.ts",
|
|
85
|
+
"import": "./dist/templates/index.js"
|
|
86
|
+
},
|
|
79
87
|
"./store/postgres": {
|
|
80
88
|
"types": "./dist/store/postgres.d.ts",
|
|
81
89
|
"import": "./dist/store/postgres.js"
|
|
@@ -100,11 +108,11 @@
|
|
|
100
108
|
"outbox"
|
|
101
109
|
],
|
|
102
110
|
"dependencies": {
|
|
103
|
-
"@venturekit/core": "0.0.
|
|
111
|
+
"@venturekit/core": "0.0.47"
|
|
104
112
|
},
|
|
105
113
|
"peerDependencies": {
|
|
106
|
-
"@venturekit/data": "0.0.
|
|
107
|
-
"@venturekit/runtime": "0.0.
|
|
114
|
+
"@venturekit/data": "0.0.47",
|
|
115
|
+
"@venturekit/runtime": "0.0.47",
|
|
108
116
|
"@aws-sdk/client-sesv2": "^3.1126.0",
|
|
109
117
|
"@aws-sdk/client-secrets-manager": "^3.1126.0"
|
|
110
118
|
},
|
|
@@ -123,8 +131,8 @@
|
|
|
123
131
|
}
|
|
124
132
|
},
|
|
125
133
|
"devDependencies": {
|
|
126
|
-
"@venturekit/data": "0.0.
|
|
127
|
-
"@venturekit/runtime": "0.0.
|
|
134
|
+
"@venturekit/data": "0.0.47",
|
|
135
|
+
"@venturekit/runtime": "0.0.47",
|
|
128
136
|
"@aws-sdk/client-sesv2": "^3.1126.0",
|
|
129
137
|
"@aws-sdk/client-secrets-manager": "^3.1126.0",
|
|
130
138
|
"@types/aws-lambda": "^8.10.163",
|