@mailoo/forms 0.0.0-stage → 1.33.0

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.
Files changed (45) hide show
  1. package/LICENSE +16 -0
  2. package/README.md +208 -2
  3. package/dist/chunk-4B377BWO.js +147 -0
  4. package/dist/chunk-4B377BWO.js.map +1 -0
  5. package/dist/chunk-LD246ORB.js +86 -0
  6. package/dist/chunk-LD246ORB.js.map +1 -0
  7. package/dist/chunk-QBZAYHBD.js +36 -0
  8. package/dist/chunk-QBZAYHBD.js.map +1 -0
  9. package/dist/events/index.cjs +176 -0
  10. package/dist/events/index.cjs.map +1 -0
  11. package/dist/events/index.d.cts +107 -0
  12. package/dist/events/index.d.ts +107 -0
  13. package/dist/events/index.js +17 -0
  14. package/dist/events/index.js.map +1 -0
  15. package/dist/hooks/index.cjs +301 -0
  16. package/dist/hooks/index.cjs.map +1 -0
  17. package/dist/hooks/index.d.cts +130 -0
  18. package/dist/hooks/index.d.ts +130 -0
  19. package/dist/hooks/index.js +221 -0
  20. package/dist/hooks/index.js.map +1 -0
  21. package/dist/index.cjs +66 -0
  22. package/dist/index.cjs.map +1 -0
  23. package/dist/index.d.cts +35 -0
  24. package/dist/index.d.ts +35 -0
  25. package/dist/index.js +19 -0
  26. package/dist/index.js.map +1 -0
  27. package/dist/routes/index.cjs +544 -0
  28. package/dist/routes/index.cjs.map +1 -0
  29. package/dist/routes/index.d.cts +59 -0
  30. package/dist/routes/index.d.ts +59 -0
  31. package/dist/routes/index.js +351 -0
  32. package/dist/routes/index.js.map +1 -0
  33. package/dist/server/index.cjs +270 -0
  34. package/dist/server/index.cjs.map +1 -0
  35. package/dist/server/index.d.cts +44 -0
  36. package/dist/server/index.d.ts +44 -0
  37. package/dist/server/index.js +112 -0
  38. package/dist/server/index.js.map +1 -0
  39. package/dist/webhooks/index.cjs +111 -0
  40. package/dist/webhooks/index.cjs.map +1 -0
  41. package/dist/webhooks/index.d.cts +37 -0
  42. package/dist/webhooks/index.d.ts +37 -0
  43. package/dist/webhooks/index.js +9 -0
  44. package/dist/webhooks/index.js.map +1 -0
  45. package/package.json +77 -3
package/LICENSE ADDED
@@ -0,0 +1,16 @@
1
+ Mailoo Integrator Use License
2
+
3
+ Copyright (c) 2026 Mailoo
4
+
5
+ Permission is granted to use, install, and distribute this software in
6
+ unmodified form, including as a dependency of an application.
7
+
8
+ Modification of this software is not permitted.
9
+
10
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
11
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
12
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
13
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
14
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
15
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
16
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,209 @@
1
- # Temporary Holding Version
1
+ # `@mailoo/forms`
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ FORM (newsletter), CONTACT_FORM (feedback), and lifecycle **events** for Next.js:
4
+ BFF route factories, client hooks, and server-side event ingest.
5
+
6
+ ## Install
7
+
8
+ ```bash
9
+ pnpm add @mailoo/forms @mailoo/next-core
10
+ ```
11
+
12
+ Published on npm as `@mailoo/forms`. Inside this monorepo, apps use
13
+ `workspace:*`.
14
+
15
+ ## Scopes (API keys)
16
+
17
+ | Integration path | Required scope |
18
+ | --------------------- | --------------------------------------- |
19
+ | FORM submit | `webhook.form-submission` (or FULL) |
20
+ | CONTACT_FORM feedback | `webhook.feedback-submission` (or FULL) |
21
+ | Lifecycle events | `lifecycle.ingest` (or FULL) |
22
+
23
+ Use a **separate** key (or FULL) for lifecycle — do not reuse a form-only RESTRICTED key.
24
+
25
+ ## Env (per BFF binding)
26
+
27
+ Each route binds one Mailoo integration via an env **prefix** (or explicit `getConfig`).
28
+
29
+ Looks for:
30
+
31
+ - `${prefix}_API`
32
+ - `${prefix}_API_KEY`
33
+ - `${prefix}_PROJECT_UID`
34
+ - `${prefix}_ID` or `${prefix}_INTEGRATION_ID`
35
+
36
+ Feedback also reads (same prefix):
37
+
38
+ - `${prefix}_FORM_NAMESPACE` → `metadata.siteFormNamespace`
39
+ - `${prefix}_SITE_ID` → `metadata.siteId`
40
+ - `${prefix}_ALLOWED_FORM_KEYS` → comma-separated `formKey` allowlist
41
+
42
+ **Defaults** when `prefix` is omitted:
43
+
44
+ - Form: `MAILOO_CONTACT_FORM_INTEGRATION` (**historical name** — this is the **FORM** / newsletter binding, not CONTACT_FORM)
45
+ - Feedback: `MAILOO_FEEDBACK_INTEGRATION`
46
+ - Lifecycle: `MAILOO_LIFECYCLE`
47
+
48
+ ## Identity (lifecycle)
49
+
50
+ | Field | Who owns it | Use |
51
+ | ---------------- | ------------------------ | --------------------------------------------------------------------- |
52
+ | `externalUserId` | Host (e.g. Firebase UID) | Stable key for ingest, status, welcome idempotency, `consent.changed` |
53
+ | `email` | Host + Mailoo | Unique merge / bulk status lookup |
54
+ | `contactId` | Mailoo cuid | Debug only — **not** your user id |
55
+
56
+ Pass **both** UID and email on ingest. Do not put email into `externalUserId`.
57
+
58
+ ## Routes
59
+
60
+ ```ts
61
+ import {
62
+ createFormSubmitHandler,
63
+ createFeedbackSubmitHandler,
64
+ createLifecycleEventHandler,
65
+ createLifecycleStatusHandler,
66
+ createLifecycleRetryHandler,
67
+ createDeliveryWebhookHandler,
68
+ } from '@mailoo/forms/routes'
69
+
70
+ export const POST = createFormSubmitHandler()
71
+
72
+ export const POST = createFeedbackSubmitHandler({
73
+ prefix: 'MAILOO_TEAM_SUBSCRIPTION_FORM',
74
+ })
75
+
76
+ // app/api/v1/webhooks/lifecycle/events/route.ts
77
+ // Open proxy — overwrite identity from your session for identified users.
78
+ export const POST = createLifecycleEventHandler()
79
+
80
+ // app/api/v1/webhooks/lifecycle/status/route.ts
81
+ export const GET = createLifecycleStatusHandler()
82
+
83
+ // app/api/v1/webhooks/lifecycle/events/[eventId]/retry/route.ts
84
+ export const POST = createLifecycleRetryHandler()
85
+
86
+ // inbound Mailoo delivery / consent.changed
87
+ export const POST = createDeliveryWebhookHandler({
88
+ secret: process.env.MAILOO_LIFECYCLE_DELIVERY_WEBHOOK_SECRET!,
89
+ async onEvent(payload) {
90
+ if (payload.event === 'consent.changed') {
91
+ // copy payload.marketingConsentGranted onto host newsletterConsent
92
+ }
93
+ },
94
+ })
95
+ ```
96
+
97
+ Verify signatures without a route: `verifyMailooDeliveryWebhook` from
98
+ `@mailoo/forms/webhooks`.
99
+
100
+ ## Lifecycle events (rigid contract, host chooses when)
101
+
102
+ Catalog lives in `@mailoo/forms/events`. Do **not** invent event names.
103
+
104
+ ```ts
105
+ import {
106
+ MAILOO_LIFECYCLE_EVENTS,
107
+ MAILOO_LIFECYCLE_ATTRIBUTE_KEYS,
108
+ validateMailooLifecycleEvent,
109
+ } from '@mailoo/forms/events'
110
+ ```
111
+
112
+ Supported `eventName` values:
113
+
114
+ - `user.registered` (`MAILOO_LIFECYCLE_EVENTS.USER_REGISTERED`)
115
+ - `user.activated` (`MAILOO_LIFECYCLE_EVENTS.USER_ACTIVATED`)
116
+
117
+ Allowed `attributes` keys only: `plan`, `tier`, `country`, `signupChannel`, `referrer`.
118
+
119
+ ### Server emit (recommended)
120
+
121
+ After **your** app creates or activates a user:
122
+
123
+ ```ts
124
+ import {
125
+ ingestMailooLifecycleEvent,
126
+ retryMailooLifecycleEvent,
127
+ } from '@mailoo/forms/server'
128
+ import { MAILOO_LIFECYCLE_EVENTS } from '@mailoo/forms/events'
129
+
130
+ const result = await ingestMailooLifecycleEvent({
131
+ eventName: MAILOO_LIFECYCLE_EVENTS.USER_REGISTERED,
132
+ idempotencyKey: `reg:${user.id}`,
133
+ externalUserId: user.id,
134
+ email: user.email,
135
+ marketingConsent: { granted: user.acceptedMarketing, source: 'signup' },
136
+ locale: user.locale,
137
+ })
138
+ if (!result.ok) {
139
+ // Feature-local failure — do not crash signup for the whole app
140
+ // result.status / result.message (503 not configured, 502 upstream, …)
141
+ }
142
+ // result.ok → result.data.processingStatus / skipReason / send
143
+ ```
144
+
145
+ `ingestMailooLifecycleEvent` / `retryMailooLifecycleEvent` **never throw** on
146
+ missing env or network failure — they return `{ ok: false, status, message }`.
147
+
148
+ ### Browser → BFF
149
+
150
+ ```ts
151
+ import {
152
+ useMailooLifecycleEvent,
153
+ useMailooLifecycleStatus,
154
+ useMailooLifecycleRetry,
155
+ } from '@mailoo/forms/hooks'
156
+ import { MAILOO_LIFECYCLE_EVENTS } from '@mailoo/forms/events'
157
+
158
+ const { emit, pending } = useMailooLifecycleEvent({
159
+ endpoint: '/api/v1/webhooks/lifecycle/events',
160
+ getHeaders: async () => ({
161
+ Authorization: `Bearer ${await getIdToken()}`,
162
+ }),
163
+ })
164
+
165
+ const r = await emit({
166
+ eventName: MAILOO_LIFECYCLE_EVENTS.USER_ACTIVATED,
167
+ idempotencyKey: `act:${userId}`,
168
+ externalUserId: userId,
169
+ email,
170
+ marketingConsent: true,
171
+ })
172
+
173
+ const { load } = useMailooLifecycleStatus()
174
+ await load({ externalUserIds: pageUserIds })
175
+
176
+ const { retry } = useMailooLifecycleRetry()
177
+ await retry(eventId)
178
+ ```
179
+
180
+ There is **no default** `eventName` — the caller must pass a catalog value.
181
+
182
+ ## Form / feedback hooks
183
+
184
+ ```ts
185
+ import {
186
+ useMailooFormSubmit,
187
+ useMailooFeedbackSubmit,
188
+ } from '@mailoo/forms/hooks'
189
+
190
+ const { submit, pending } = useMailooFormSubmit()
191
+ const result = await submit({
192
+ email: 'a@b.c',
193
+ name: 'Ada',
194
+ source: window.location.href,
195
+ })
196
+ // result.ok + result.data; FORM may omit messageId when already subscribed
197
+ ```
198
+
199
+ FORM body: `email` (required), optional `name`, `subject`, `content`, `source`, `metadata`.
200
+ Use `content` (not `message`) for a custom inbox body.
201
+
202
+ Feedback body: `email` + `message` (required), optional `name`, `subject`, `formKey`, `metadata`.
203
+
204
+ ## Build / test
205
+
206
+ ```bash
207
+ pnpm --filter @mailoo/forms build
208
+ pnpm --filter @mailoo/forms test
209
+ ```
@@ -0,0 +1,147 @@
1
+ // src/events/index.ts
2
+ var MAILOO_LIFECYCLE_EVENTS = {
3
+ USER_REGISTERED: "user.registered",
4
+ USER_ACTIVATED: "user.activated"
5
+ };
6
+ var MAILOO_LIFECYCLE_EVENT_NAMES = [
7
+ MAILOO_LIFECYCLE_EVENTS.USER_REGISTERED,
8
+ MAILOO_LIFECYCLE_EVENTS.USER_ACTIVATED
9
+ ];
10
+ var EVENT_NAME_SET = new Set(MAILOO_LIFECYCLE_EVENT_NAMES);
11
+ var MAILOO_LIFECYCLE_ATTRIBUTE_KEYS = [
12
+ "plan",
13
+ "tier",
14
+ "country",
15
+ "signupChannel",
16
+ "referrer"
17
+ ];
18
+ var ATTRIBUTE_KEY_SET = new Set(MAILOO_LIFECYCLE_ATTRIBUTE_KEYS);
19
+ var EMAIL_RE = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
20
+ function isPlainObject(v) {
21
+ return typeof v === "object" && v !== null && !Array.isArray(v);
22
+ }
23
+ function validateMailooLifecycleEvent(body) {
24
+ if (!isPlainObject(body)) {
25
+ return { ok: false, message: "JSON body object is required" };
26
+ }
27
+ const idempotencyKey = typeof body.idempotencyKey === "string" ? body.idempotencyKey.trim() : "";
28
+ if (!idempotencyKey || idempotencyKey.length > 256) {
29
+ return {
30
+ ok: false,
31
+ message: "idempotencyKey is required (max 256 characters)"
32
+ };
33
+ }
34
+ const eventName = typeof body.eventName === "string" ? body.eventName.trim() : "";
35
+ if (!eventName) {
36
+ return { ok: false, message: "eventName is required" };
37
+ }
38
+ if (!EVENT_NAME_SET.has(eventName)) {
39
+ return {
40
+ ok: false,
41
+ message: `Unknown eventName: ${eventName}. Allowed: ${MAILOO_LIFECYCLE_EVENT_NAMES.join(", ")}`
42
+ };
43
+ }
44
+ const externalUserId = typeof body.externalUserId === "string" ? body.externalUserId.trim() : "";
45
+ if (!externalUserId) {
46
+ return { ok: false, message: "externalUserId is required" };
47
+ }
48
+ const emailRaw = typeof body.email === "string" ? body.email.trim() : "";
49
+ if (!emailRaw || !EMAIL_RE.test(emailRaw)) {
50
+ return { ok: false, message: "Valid email is required" };
51
+ }
52
+ const locale = typeof body.locale === "string" && body.locale.trim() ? body.locale.trim() : void 0;
53
+ const name = typeof body.name === "string" && body.name.trim() ? body.name.trim() : void 0;
54
+ let marketingConsent;
55
+ const rawConsent = body.marketingConsent;
56
+ if (rawConsent === true || rawConsent === false) {
57
+ marketingConsent = rawConsent;
58
+ } else if (isPlainObject(rawConsent) && typeof rawConsent.granted === "boolean") {
59
+ const at = typeof rawConsent.at === "string" && rawConsent.at.trim() ? rawConsent.at.trim() : void 0;
60
+ if (at !== void 0) {
61
+ const parsed = new Date(at);
62
+ if (Number.isNaN(parsed.getTime())) {
63
+ return {
64
+ ok: false,
65
+ message: "marketingConsent.at must be a valid ISO timestamp"
66
+ };
67
+ }
68
+ }
69
+ marketingConsent = {
70
+ granted: rawConsent.granted,
71
+ ...at ? { at } : {},
72
+ ...typeof rawConsent.source === "string" ? { source: rawConsent.source } : {}
73
+ };
74
+ } else {
75
+ return {
76
+ ok: false,
77
+ message: "marketingConsent is required (boolean or { granted })"
78
+ };
79
+ }
80
+ let attributes;
81
+ if (body.attributes !== void 0) {
82
+ if (!isPlainObject(body.attributes)) {
83
+ return { ok: false, message: "attributes must be an object" };
84
+ }
85
+ attributes = {};
86
+ for (const [key, value] of Object.entries(body.attributes)) {
87
+ if (!ATTRIBUTE_KEY_SET.has(key)) {
88
+ return { ok: false, message: `Unknown attribute key: ${key}` };
89
+ }
90
+ attributes[key] = value;
91
+ }
92
+ }
93
+ return {
94
+ ok: true,
95
+ value: {
96
+ eventName,
97
+ idempotencyKey,
98
+ externalUserId,
99
+ email: emailRaw,
100
+ marketingConsent,
101
+ ...locale ? { locale } : {},
102
+ ...name ? { name } : {},
103
+ ...attributes ? { attributes } : {}
104
+ }
105
+ };
106
+ }
107
+ function isMailooLifecycleEventName(value) {
108
+ return EVENT_NAME_SET.has(value);
109
+ }
110
+ function parseMailooLifecycleIngestData(data) {
111
+ if (!isPlainObject(data)) return null;
112
+ if (typeof data.eventId !== "string" || typeof data.contactId !== "string") {
113
+ return null;
114
+ }
115
+ let send = null;
116
+ if (data.send === null) {
117
+ send = null;
118
+ } else if (isPlainObject(data.send) && typeof data.send.sendId === "string") {
119
+ send = {
120
+ sendId: data.send.sendId,
121
+ status: String(data.send.status ?? ""),
122
+ messageId: data.send.messageId === null || typeof data.send.messageId === "string" ? data.send.messageId : null,
123
+ trackingToken: String(data.send.trackingToken ?? ""),
124
+ campaignId: data.send.campaignId === null || typeof data.send.campaignId === "string" ? data.send.campaignId : null
125
+ };
126
+ } else {
127
+ return null;
128
+ }
129
+ return {
130
+ eventId: data.eventId,
131
+ contactId: data.contactId,
132
+ idempotentReplay: data.idempotentReplay === true,
133
+ processingStatus: String(data.processingStatus ?? ""),
134
+ skipReason: data.skipReason === null || typeof data.skipReason === "string" ? data.skipReason : null,
135
+ send
136
+ };
137
+ }
138
+
139
+ export {
140
+ MAILOO_LIFECYCLE_EVENTS,
141
+ MAILOO_LIFECYCLE_EVENT_NAMES,
142
+ MAILOO_LIFECYCLE_ATTRIBUTE_KEYS,
143
+ validateMailooLifecycleEvent,
144
+ isMailooLifecycleEventName,
145
+ parseMailooLifecycleIngestData
146
+ };
147
+ //# sourceMappingURL=chunk-4B377BWO.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/events/index.ts"],"sourcesContent":["/**\n * Closed lifecycle event catalog for FORM / CONTACT_FORM integrations.\n * Integrators choose *when* to emit; they must not invent event names or\n * attribute keys.\n */\n\nexport const MAILOO_LIFECYCLE_EVENTS = {\n USER_REGISTERED: 'user.registered',\n USER_ACTIVATED: 'user.activated',\n} as const\n\nexport type MailooLifecycleEventName =\n (typeof MAILOO_LIFECYCLE_EVENTS)[keyof typeof MAILOO_LIFECYCLE_EVENTS]\n\nexport const MAILOO_LIFECYCLE_EVENT_NAMES = [\n MAILOO_LIFECYCLE_EVENTS.USER_REGISTERED,\n MAILOO_LIFECYCLE_EVENTS.USER_ACTIVATED,\n] as const\n\nconst EVENT_NAME_SET = new Set<string>(MAILOO_LIFECYCLE_EVENT_NAMES)\n\nexport const MAILOO_LIFECYCLE_ATTRIBUTE_KEYS = [\n 'plan',\n 'tier',\n 'country',\n 'signupChannel',\n 'referrer',\n] as const\n\nexport type MailooLifecycleAttributeKey =\n (typeof MAILOO_LIFECYCLE_ATTRIBUTE_KEYS)[number]\n\nconst ATTRIBUTE_KEY_SET = new Set<string>(MAILOO_LIFECYCLE_ATTRIBUTE_KEYS)\n\nconst EMAIL_RE = /^[^\\s@]+@[^\\s@]+\\.[^\\s@]+$/\n\nexport type MailooMarketingConsent =\n | boolean\n | {\n granted: boolean\n at?: string\n source?: string\n }\n\nexport type MailooLifecycleEventInput = {\n eventName: MailooLifecycleEventName\n idempotencyKey: string\n externalUserId: string\n email: string\n marketingConsent: MailooMarketingConsent\n locale?: string\n name?: string\n attributes?: Partial<Record<MailooLifecycleAttributeKey, unknown>>\n}\n\nexport type MailooLifecycleEventValidation =\n | { ok: true; value: MailooLifecycleEventInput }\n | { ok: false; message: string }\n\nfunction isPlainObject(v: unknown): v is Record<string, unknown> {\n return typeof v === 'object' && v !== null && !Array.isArray(v)\n}\n\n/**\n * Parse and validate a lifecycle ingest body. Fail-fast — no default\n * `eventName`. Used by BFF handlers and server ingest.\n */\nexport function validateMailooLifecycleEvent(\n body: unknown\n): MailooLifecycleEventValidation {\n if (!isPlainObject(body)) {\n return { ok: false, message: 'JSON body object is required' }\n }\n\n const idempotencyKey =\n typeof body.idempotencyKey === 'string' ? body.idempotencyKey.trim() : ''\n if (!idempotencyKey || idempotencyKey.length > 256) {\n return {\n ok: false,\n message: 'idempotencyKey is required (max 256 characters)',\n }\n }\n\n const eventName =\n typeof body.eventName === 'string' ? body.eventName.trim() : ''\n if (!eventName) {\n return { ok: false, message: 'eventName is required' }\n }\n if (!EVENT_NAME_SET.has(eventName)) {\n return {\n ok: false,\n message: `Unknown eventName: ${eventName}. Allowed: ${MAILOO_LIFECYCLE_EVENT_NAMES.join(', ')}`,\n }\n }\n\n const externalUserId =\n typeof body.externalUserId === 'string' ? body.externalUserId.trim() : ''\n if (!externalUserId) {\n return { ok: false, message: 'externalUserId is required' }\n }\n\n const emailRaw = typeof body.email === 'string' ? body.email.trim() : ''\n if (!emailRaw || !EMAIL_RE.test(emailRaw)) {\n return { ok: false, message: 'Valid email is required' }\n }\n\n const locale =\n typeof body.locale === 'string' && body.locale.trim()\n ? body.locale.trim()\n : undefined\n const name =\n typeof body.name === 'string' && body.name.trim()\n ? body.name.trim()\n : undefined\n\n let marketingConsent: MailooMarketingConsent\n const rawConsent = body.marketingConsent\n if (rawConsent === true || rawConsent === false) {\n marketingConsent = rawConsent\n } else if (isPlainObject(rawConsent) && typeof rawConsent.granted === 'boolean') {\n const at =\n typeof rawConsent.at === 'string' && rawConsent.at.trim()\n ? rawConsent.at.trim()\n : undefined\n if (at !== undefined) {\n const parsed = new Date(at)\n if (Number.isNaN(parsed.getTime())) {\n return {\n ok: false,\n message: 'marketingConsent.at must be a valid ISO timestamp',\n }\n }\n }\n marketingConsent = {\n granted: rawConsent.granted,\n ...(at ? { at } : {}),\n ...(typeof rawConsent.source === 'string'\n ? { source: rawConsent.source }\n : {}),\n }\n } else {\n return {\n ok: false,\n message: 'marketingConsent is required (boolean or { granted })',\n }\n }\n\n let attributes:\n | Partial<Record<MailooLifecycleAttributeKey, unknown>>\n | undefined\n if (body.attributes !== undefined) {\n if (!isPlainObject(body.attributes)) {\n return { ok: false, message: 'attributes must be an object' }\n }\n attributes = {}\n for (const [key, value] of Object.entries(body.attributes)) {\n if (!ATTRIBUTE_KEY_SET.has(key)) {\n return { ok: false, message: `Unknown attribute key: ${key}` }\n }\n attributes[key as MailooLifecycleAttributeKey] = value\n }\n }\n\n return {\n ok: true,\n value: {\n eventName: eventName as MailooLifecycleEventName,\n idempotencyKey,\n externalUserId,\n email: emailRaw,\n marketingConsent,\n ...(locale ? { locale } : {}),\n ...(name ? { name } : {}),\n ...(attributes ? { attributes } : {}),\n },\n }\n}\n\nexport function isMailooLifecycleEventName(\n value: string\n): value is MailooLifecycleEventName {\n return EVENT_NAME_SET.has(value)\n}\n\n/** Send row returned by lifecycle ingest / retry. */\nexport type MailooLifecycleSendResult = {\n sendId: string\n status: string\n messageId: string | null\n trackingToken: string\n campaignId: string | null\n}\n\n/**\n * Typed `data` from lifecycle ingest / retry success JSON.\n * `contactId` is Mailoo's Subscriber cuid — not the host user id.\n * Host identity key is `externalUserId` (e.g. Firebase UID).\n */\nexport type MailooLifecycleIngestData = {\n eventId: string\n contactId: string\n idempotentReplay: boolean\n processingStatus: string\n skipReason: string | null\n send: MailooLifecycleSendResult | null\n}\n\nexport type MailooLifecycleIngestSuccess = {\n success: true\n data: MailooLifecycleIngestData\n}\n\nexport type MailooLifecycleContactSummary = {\n requestedExternalUserId: string | null\n requestedEmail: string | null\n matchedBy: 'externalUserId' | 'email' | null\n contactId: string | null\n externalUserId: string | null\n email: string | null\n marketingConsentGranted: boolean | null\n unsubscribedAt: string | null\n lastEvent: {\n eventId: string\n eventName: string\n processingStatus: string\n skipReason: string | null\n createdAt: string\n } | null\n lastSend: {\n sendId: string\n status: string\n messageId: string | null\n openedAt: string | null\n clickedAt: string | null\n } | null\n}\n\nexport type MailooLifecycleStatusData = {\n success: true\n configured: true\n contacts: number\n contact: Record<string, unknown> | null\n events: Array<Record<string, unknown>>\n sends: Array<Record<string, unknown>>\n segments: Array<{\n id: string\n name: string\n systemKey: string | null\n }>\n summaries?: MailooLifecycleContactSummary[]\n}\n\nexport function parseMailooLifecycleIngestData(\n data: unknown\n): MailooLifecycleIngestData | null {\n if (!isPlainObject(data)) return null\n if (typeof data.eventId !== 'string' || typeof data.contactId !== 'string') {\n return null\n }\n let send: MailooLifecycleSendResult | null = null\n if (data.send === null) {\n send = null\n } else if (isPlainObject(data.send) && typeof data.send.sendId === 'string') {\n send = {\n sendId: data.send.sendId,\n status: String(data.send.status ?? ''),\n messageId:\n data.send.messageId === null || typeof data.send.messageId === 'string'\n ? (data.send.messageId as string | null)\n : null,\n trackingToken: String(data.send.trackingToken ?? ''),\n campaignId:\n data.send.campaignId === null ||\n typeof data.send.campaignId === 'string'\n ? (data.send.campaignId as string | null)\n : null,\n }\n } else {\n return null\n }\n return {\n eventId: data.eventId,\n contactId: data.contactId,\n idempotentReplay: data.idempotentReplay === true,\n processingStatus: String(data.processingStatus ?? ''),\n skipReason:\n data.skipReason === null || typeof data.skipReason === 'string'\n ? (data.skipReason as string | null)\n : null,\n send,\n }\n}\n"],"mappings":";AAMO,IAAM,0BAA0B;AAAA,EACrC,iBAAiB;AAAA,EACjB,gBAAgB;AAClB;AAKO,IAAM,+BAA+B;AAAA,EAC1C,wBAAwB;AAAA,EACxB,wBAAwB;AAC1B;AAEA,IAAM,iBAAiB,IAAI,IAAY,4BAA4B;AAE5D,IAAM,kCAAkC;AAAA,EAC7C;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF;AAKA,IAAM,oBAAoB,IAAI,IAAY,+BAA+B;AAEzE,IAAM,WAAW;AAyBjB,SAAS,cAAc,GAA0C;AAC/D,SAAO,OAAO,MAAM,YAAY,MAAM,QAAQ,CAAC,MAAM,QAAQ,CAAC;AAChE;AAMO,SAAS,6BACd,MACgC;AAChC,MAAI,CAAC,cAAc,IAAI,GAAG;AACxB,WAAO,EAAE,IAAI,OAAO,SAAS,+BAA+B;AAAA,EAC9D;AAEA,QAAM,iBACJ,OAAO,KAAK,mBAAmB,WAAW,KAAK,eAAe,KAAK,IAAI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KAAK,cAAc,UAAU;AAC1E,WAAO;AAAA,EACT;AACA,MAAI,OAAyC;AAC7C,MAAI,KAAK,SAAS,MAAM;AACtB,WAAO;AAAA,EACT,WAAW,cAAc,KAAK,IAAI,KAAK,OAAO,KAAK,KAAK,WAAW,UAAU;AAC3E,WAAO;AAAA,MACL,QAAQ,KAAK,KAAK;AAAA,MAClB,QAAQ,OAAO,KAAK,KAAK,UAAU,EAAE;AAAA,MACrC,WACE,KAAK,KAAK,cAAc,QAAQ,OAAO,KAAK,KAAK,cAAc,WAC1D,KAAK,KAAK,YACX;AAAA,MACN,eAAe,OAAO,KAAK,KAAK,iBAAiB,EAAE;AAAA,MACnD,YACE,KAAK,KAAK,eAAe,QACzB,OAAO,KAAK,KAAK,eAAe,WAC3B,KAAK,KAAK,aACX;AAAA,IACR;AAAA,EACF,OAAO;AACL,WAAO;AAAA,EACT;AACA,SAAO;AAAA,IACL,SAAS,KAAK;AAAA,IACd,WAAW,KAAK;AAAA,IAChB,kBAAkB,KAAK,qBAAqB;AAAA,IAC5C,kBAAkB,OAAO,KAAK,oBAAoB,EAAE;AAAA,IACpD,YACE,KAAK,eAAe,QAAQ,OAAO,KAAK,eAAe,WAClD,KAAK,aACN;AAAA,IACN;AAAA,EACF;AACF;","names":[]}
@@ -0,0 +1,86 @@
1
+ // src/webhooks/index.ts
2
+ import { createHmac, timingSafeEqual } from "crypto";
3
+ function isPlainObject(v) {
4
+ return typeof v === "object" && v !== null && !Array.isArray(v);
5
+ }
6
+ function verifyMailooDeliveryWebhook(rawBody, headers, secret) {
7
+ const get = (name) => {
8
+ if (headers instanceof Headers) {
9
+ return headers.get(name);
10
+ }
11
+ const lower = name.toLowerCase();
12
+ for (const [k, v] of Object.entries(headers)) {
13
+ if (k.toLowerCase() === lower) {
14
+ return typeof v === "string" ? v : v ?? null;
15
+ }
16
+ }
17
+ return null;
18
+ };
19
+ const signatureHeader = get("x-mailoo-signature");
20
+ if (!signatureHeader || !signatureHeader.trim()) {
21
+ return { ok: false, message: "Missing X-Mailoo-Signature" };
22
+ }
23
+ if (!secret.trim()) {
24
+ return { ok: false, message: "Webhook secret is empty" };
25
+ }
26
+ let timestamp = 0;
27
+ let v1 = "";
28
+ for (const part of signatureHeader.split(",")) {
29
+ const [k, v] = part.trim().split("=", 2);
30
+ if (k === "t" && v) timestamp = Number(v);
31
+ if (k === "v1" && v) v1 = v;
32
+ }
33
+ if (!Number.isFinite(timestamp) || timestamp <= 0 || !v1) {
34
+ return { ok: false, message: "Invalid X-Mailoo-Signature format" };
35
+ }
36
+ const expected = createHmac("sha256", secret).update(`${timestamp}.${rawBody}`).digest("hex");
37
+ const a = Buffer.from(expected, "utf8");
38
+ const b = Buffer.from(v1, "utf8");
39
+ if (a.length !== b.length || !timingSafeEqual(a, b)) {
40
+ return { ok: false, message: "Invalid delivery webhook signature" };
41
+ }
42
+ let parsed;
43
+ try {
44
+ parsed = JSON.parse(rawBody);
45
+ } catch {
46
+ return { ok: false, message: "Invalid JSON body" };
47
+ }
48
+ if (!isPlainObject(parsed) || typeof parsed.event !== "string") {
49
+ return { ok: false, message: "Invalid delivery webhook payload" };
50
+ }
51
+ if (typeof parsed.integrationId !== "string") {
52
+ return { ok: false, message: "integrationId is required" };
53
+ }
54
+ if (typeof parsed.timestamp !== "string") {
55
+ return { ok: false, message: "timestamp is required" };
56
+ }
57
+ return {
58
+ ok: true,
59
+ timestamp,
60
+ payload: parsed
61
+ };
62
+ }
63
+ function asMailooConsentChanged(payload) {
64
+ if (payload.event !== "consent.changed") return null;
65
+ if (typeof payload.recipientEmail !== "string" || !payload.recipientEmail) {
66
+ return null;
67
+ }
68
+ if (typeof payload.marketingConsentGranted !== "boolean") {
69
+ return null;
70
+ }
71
+ return {
72
+ event: "consent.changed",
73
+ integrationId: payload.integrationId,
74
+ externalUserId: typeof payload.externalUserId === "string" ? payload.externalUserId : payload.externalUserId === null ? null : null,
75
+ recipientEmail: payload.recipientEmail,
76
+ marketingConsentGranted: payload.marketingConsentGranted,
77
+ unsubscribedAt: typeof payload.unsubscribedAt === "string" ? payload.unsubscribedAt : null,
78
+ timestamp: payload.timestamp
79
+ };
80
+ }
81
+
82
+ export {
83
+ verifyMailooDeliveryWebhook,
84
+ asMailooConsentChanged
85
+ };
86
+ //# sourceMappingURL=chunk-LD246ORB.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/webhooks/index.ts"],"sourcesContent":["import { createHmac, timingSafeEqual } from 'node:crypto'\n\nexport type MailooDeliveryWebhookEventName =\n | 'accepted'\n | 'deferred'\n | 'delivered'\n | 'opened'\n | 'clicked'\n | 'unsubscribed'\n | 'bounced'\n | 'consent.changed'\n\nexport type MailooDeliveryWebhookPayload = {\n event: MailooDeliveryWebhookEventName | string\n integrationId: string\n messageId?: string\n idempotencyKey?: string\n recipientEmail?: string\n externalUserId?: string | null\n marketingConsentGranted?: boolean\n unsubscribedAt?: string | null\n timestamp: string\n metadata?: Record<string, unknown>\n}\n\nexport type MailooConsentChangedPayload = {\n event: 'consent.changed'\n integrationId: string\n externalUserId: string | null\n recipientEmail: string\n marketingConsentGranted: boolean\n unsubscribedAt: string | null\n timestamp: string\n}\n\nexport type VerifyMailooDeliveryWebhookResult =\n | { ok: true; timestamp: number; payload: MailooDeliveryWebhookPayload }\n | { ok: false; message: string }\n\nfunction isPlainObject(v: unknown): v is Record<string, unknown> {\n return typeof v === 'object' && v !== null && !Array.isArray(v)\n}\n\n/**\n * Verify `X-Mailoo-Signature: t={unix},v1={hex}` over `\"{timestamp}.{rawBody}\"`.\n */\nexport function verifyMailooDeliveryWebhook(\n rawBody: string,\n headers: Headers | Record<string, string | null | undefined>,\n secret: string\n): VerifyMailooDeliveryWebhookResult {\n const get = (name: string): string | null => {\n if (headers instanceof Headers) {\n return headers.get(name)\n }\n const lower = name.toLowerCase()\n for (const [k, v] of Object.entries(headers)) {\n if (k.toLowerCase() === lower) {\n return typeof v === 'string' ? v : v ?? null\n }\n }\n return null\n }\n\n const signatureHeader = get('x-mailoo-signature')\n if (!signatureHeader || !signatureHeader.trim()) {\n return { ok: false, message: 'Missing X-Mailoo-Signature' }\n }\n if (!secret.trim()) {\n return { ok: false, message: 'Webhook secret is empty' }\n }\n\n let timestamp = 0\n let v1 = ''\n for (const part of signatureHeader.split(',')) {\n const [k, v] = part.trim().split('=', 2)\n if (k === 't' && v) timestamp = Number(v)\n if (k === 'v1' && v) v1 = v\n }\n if (!Number.isFinite(timestamp) || timestamp <= 0 || !v1) {\n return { ok: false, message: 'Invalid X-Mailoo-Signature format' }\n }\n\n const expected = createHmac('sha256', secret)\n .update(`${timestamp}.${rawBody}`)\n .digest('hex')\n const a = Buffer.from(expected, 'utf8')\n const b = Buffer.from(v1, 'utf8')\n if (a.length !== b.length || !timingSafeEqual(a, b)) {\n return { ok: false, message: 'Invalid delivery webhook signature' }\n }\n\n let parsed: unknown\n try {\n parsed = JSON.parse(rawBody)\n } catch {\n return { ok: false, message: 'Invalid JSON body' }\n }\n if (!isPlainObject(parsed) || typeof parsed.event !== 'string') {\n return { ok: false, message: 'Invalid delivery webhook payload' }\n }\n if (typeof parsed.integrationId !== 'string') {\n return { ok: false, message: 'integrationId is required' }\n }\n if (typeof parsed.timestamp !== 'string') {\n return { ok: false, message: 'timestamp is required' }\n }\n\n return {\n ok: true,\n timestamp,\n payload: parsed as MailooDeliveryWebhookPayload,\n }\n}\n\nexport function asMailooConsentChanged(\n payload: MailooDeliveryWebhookPayload\n): MailooConsentChangedPayload | null {\n if (payload.event !== 'consent.changed') return null\n if (typeof payload.recipientEmail !== 'string' || !payload.recipientEmail) {\n return null\n }\n if (typeof payload.marketingConsentGranted !== 'boolean') {\n return null\n }\n return {\n event: 'consent.changed',\n integrationId: payload.integrationId,\n externalUserId:\n typeof payload.externalUserId === 'string'\n ? payload.externalUserId\n : payload.externalUserId === null\n ? null\n : null,\n recipientEmail: payload.recipientEmail,\n marketingConsentGranted: payload.marketingConsentGranted,\n unsubscribedAt:\n typeof payload.unsubscribedAt === 'string'\n ? payload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F;","names":[]}
@@ -0,0 +1,36 @@
1
+ // src/config.ts
2
+ import {
3
+ readMailooIntegrationConfig
4
+ } from "@mailoo/next-core";
5
+ var MAILOO_FORM_INTEGRATION_PREFIX = "MAILOO_CONTACT_FORM_INTEGRATION";
6
+ var MAILOO_FEEDBACK_INTEGRATION_PREFIX = "MAILOO_FEEDBACK_INTEGRATION";
7
+ var MAILOO_LIFECYCLE_INTEGRATION_PREFIX = "MAILOO_LIFECYCLE";
8
+ function getMailooFormsIntegrationConfig(options) {
9
+ return readMailooIntegrationConfig({ prefix: options.prefix });
10
+ }
11
+ function getMailooFormIntegrationConfig() {
12
+ return getMailooFormsIntegrationConfig({
13
+ prefix: MAILOO_FORM_INTEGRATION_PREFIX
14
+ });
15
+ }
16
+ function getMailooFeedbackIntegrationConfig() {
17
+ return getMailooFormsIntegrationConfig({
18
+ prefix: MAILOO_FEEDBACK_INTEGRATION_PREFIX
19
+ });
20
+ }
21
+ function isMailooFeedbackIntegrationConfigured() {
22
+ return getMailooFormsIntegrationConfig({
23
+ prefix: MAILOO_FEEDBACK_INTEGRATION_PREFIX
24
+ }) !== null;
25
+ }
26
+
27
+ export {
28
+ MAILOO_FORM_INTEGRATION_PREFIX,
29
+ MAILOO_FEEDBACK_INTEGRATION_PREFIX,
30
+ MAILOO_LIFECYCLE_INTEGRATION_PREFIX,
31
+ getMailooFormsIntegrationConfig,
32
+ getMailooFormIntegrationConfig,
33
+ getMailooFeedbackIntegrationConfig,
34
+ isMailooFeedbackIntegrationConfigured
35
+ };
36
+ //# sourceMappingURL=chunk-QBZAYHBD.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/config.ts"],"sourcesContent":["import {\n readMailooIntegrationConfig,\n type MailooIntegrationConfig,\n} from '@mailoo/next-core'\n\n/** Default env prefix for newsletter / FORM BFF binding. */\nexport const MAILOO_FORM_INTEGRATION_PREFIX =\n 'MAILOO_CONTACT_FORM_INTEGRATION' as const\n\n/** Default env prefix for feedback / CONTACT_FORM BFF binding. */\nexport const MAILOO_FEEDBACK_INTEGRATION_PREFIX =\n 'MAILOO_FEEDBACK_INTEGRATION' as const\n\n/**\n * Default env prefix for lifecycle ingest BFF / server emit.\n * Needs an API key with `lifecycle.ingest` (separate from form-submission).\n */\nexport const MAILOO_LIFECYCLE_INTEGRATION_PREFIX = 'MAILOO_LIFECYCLE' as const\n\n/**\n * Preferred: read integration credentials for any env prefix\n * (`${prefix}_API`, `_API_KEY`, `_PROJECT_UID`, `_ID` or `_INTEGRATION_ID`).\n */\nexport function getMailooFormsIntegrationConfig(options: {\n prefix: string\n}): MailooIntegrationConfig | null {\n return readMailooIntegrationConfig({ prefix: options.prefix })\n}\n\n/**\n * @deprecated Use\n * `getMailooFormsIntegrationConfig({ prefix: 'MAILOO_CONTACT_FORM_INTEGRATION' })`\n */\nexport function getMailooFormIntegrationConfig(): MailooIntegrationConfig | null {\n return getMailooFormsIntegrationConfig({\n prefix: MAILOO_FORM_INTEGRATION_PREFIX,\n })\n}\n\n/**\n * @deprecated Use\n * `getMailooFormsIntegrationConfig({ prefix: 'MAILOO_FEEDBACK_INTEGRATION' })`\n */\nexport function getMailooFeedbackIntegrationConfig(): MailooIntegrationConfig | null {\n return getMailooFormsIntegrationConfig({\n prefix: MAILOO_FEEDBACK_INTEGRATION_PREFIX,\n })\n}\n\n/**\n * @deprecated Use\n * `getMailooFormsIntegrationConfig({ prefix: 'MAILOO_FEEDBACK_INTEGRATION' }) !== null`\n */\nexport function isMailooFeedbackIntegrationConfigured(): boolean {\n return (\n getMailooFormsIntegrationConfig({\n prefix: MAILOO_FEEDBACK_INTEGRATION_PREFIX,\n }) !== null\n )\n}\n"],"mappings":";AAAA;AAAA,EACE;AAAA,OAEK;AAGA,IAAM,iCACX;AAGK,IAAM,qCACX;AAMK,IAAM,sCAAsC;AAM5C,SAAS,gCAAgC,SAEb;AACjC,SAAO,4BAA4B,EAAE,QAAQ,QAAQ,OAAO,CAAC;AAC/D;AAMO,SAAS,iCAAiE;AAC/E,SAAO,gCAAgC;AAAA,IACrC,QAAQ;AAAA,EACV,CAAC;AACH;AAMO,SAAS,qCAAqE;AACnF,SAAO,gCAAgC;AAAA,IACrC,QAAQ;AAAA,EACV,CAAC;AACH;AAMO,SAAS,wCAAiD;AAC/D,SACE,gCAAgC;AAAA,IAC9B,QAAQ;AAAA,EACV,CAAC,MAAM;AAEX;","names":[]}