@mailoo/forms 0.0.0-stage → 1.32.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +16 -0
- package/README.md +205 -2
- package/dist/chunk-4B377BWO.js +147 -0
- package/dist/chunk-4B377BWO.js.map +1 -0
- package/dist/chunk-LD246ORB.js +86 -0
- package/dist/chunk-LD246ORB.js.map +1 -0
- package/dist/chunk-QBZAYHBD.js +36 -0
- package/dist/chunk-QBZAYHBD.js.map +1 -0
- package/dist/events/index.cjs +176 -0
- package/dist/events/index.cjs.map +1 -0
- package/dist/events/index.d.cts +107 -0
- package/dist/events/index.d.ts +107 -0
- package/dist/events/index.js +17 -0
- package/dist/events/index.js.map +1 -0
- package/dist/hooks/index.cjs +301 -0
- package/dist/hooks/index.cjs.map +1 -0
- package/dist/hooks/index.d.cts +130 -0
- package/dist/hooks/index.d.ts +130 -0
- package/dist/hooks/index.js +221 -0
- package/dist/hooks/index.js.map +1 -0
- package/dist/index.cjs +66 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +35 -0
- package/dist/index.d.ts +35 -0
- package/dist/index.js +19 -0
- package/dist/index.js.map +1 -0
- package/dist/routes/index.cjs +544 -0
- package/dist/routes/index.cjs.map +1 -0
- package/dist/routes/index.d.cts +59 -0
- package/dist/routes/index.d.ts +59 -0
- package/dist/routes/index.js +351 -0
- package/dist/routes/index.js.map +1 -0
- package/dist/server/index.cjs +270 -0
- package/dist/server/index.cjs.map +1 -0
- package/dist/server/index.d.cts +44 -0
- package/dist/server/index.d.ts +44 -0
- package/dist/server/index.js +112 -0
- package/dist/server/index.js.map +1 -0
- package/dist/webhooks/index.cjs +111 -0
- package/dist/webhooks/index.cjs.map +1 -0
- package/dist/webhooks/index.d.cts +37 -0
- package/dist/webhooks/index.d.ts +37 -0
- package/dist/webhooks/index.js +9 -0
- package/dist/webhooks/index.js.map +1 -0
- package/package.json +77 -3
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { NextRequest } from 'next/server';
|
|
2
|
+
import { MailooLogger, MailooIntegrationConfig } from '@mailoo/next-core';
|
|
3
|
+
import { MailooDeliveryWebhookPayload } from '../webhooks/index.cjs';
|
|
4
|
+
|
|
5
|
+
type CreateFormsHandlerOptions = {
|
|
6
|
+
logger?: MailooLogger;
|
|
7
|
+
/**
|
|
8
|
+
* Env prefix for credentials and (feedback) metadata/allowlist.
|
|
9
|
+
* Defaults: form → MAILOO_CONTACT_FORM_INTEGRATION;
|
|
10
|
+
* feedback → MAILOO_FEEDBACK_INTEGRATION;
|
|
11
|
+
* lifecycle → MAILOO_LIFECYCLE.
|
|
12
|
+
*/
|
|
13
|
+
prefix?: string;
|
|
14
|
+
/** Explicit config; wins over prefix/env when provided. */
|
|
15
|
+
getConfig?: () => MailooIntegrationConfig | null;
|
|
16
|
+
};
|
|
17
|
+
declare function createFormSubmitHandler(options?: CreateFormsHandlerOptions): (request: NextRequest) => Promise<Response>;
|
|
18
|
+
declare function createFeedbackSubmitHandler(options?: CreateFormsHandlerOptions): (request: NextRequest) => Promise<Response>;
|
|
19
|
+
/**
|
|
20
|
+
* BFF POST → Mailoo lifecycle ingest. Browser posts here; key stays on server.
|
|
21
|
+
* Body must include an explicit catalog `eventName` (no defaults).
|
|
22
|
+
*
|
|
23
|
+
* **Security:** this handler is an open proxy for any client that can reach the
|
|
24
|
+
* BFF. Integrators with identified users must verify a session and overwrite
|
|
25
|
+
* `externalUserId` / `email` from the session (do not trust the browser body).
|
|
26
|
+
*/
|
|
27
|
+
declare function createLifecycleEventHandler(options?: CreateFormsHandlerOptions): (request: NextRequest) => Promise<Response>;
|
|
28
|
+
/**
|
|
29
|
+
* BFF POST → Mailoo lifecycle event retry.
|
|
30
|
+
* Mount at e.g. `app/api/v1/webhooks/lifecycle/events/[eventId]/retry/route.ts`
|
|
31
|
+
* and pass `eventId` from the route params (or read from the URL path).
|
|
32
|
+
*/
|
|
33
|
+
declare function createLifecycleRetryHandler(options?: CreateFormsHandlerOptions & {
|
|
34
|
+
getEventId?: (request: NextRequest) => string | null;
|
|
35
|
+
}): (request: NextRequest, context?: {
|
|
36
|
+
params?: Promise<{
|
|
37
|
+
eventId?: string;
|
|
38
|
+
}> | {
|
|
39
|
+
eventId?: string;
|
|
40
|
+
};
|
|
41
|
+
}) => Promise<Response>;
|
|
42
|
+
/**
|
|
43
|
+
* BFF GET → Mailoo lifecycle status.
|
|
44
|
+
* Forwards `externalUserId`, `externalUserIds`, and `emails` query params.
|
|
45
|
+
*/
|
|
46
|
+
declare function createLifecycleStatusHandler(options?: CreateFormsHandlerOptions): (request: NextRequest) => Promise<Response>;
|
|
47
|
+
type CreateDeliveryWebhookHandlerOptions = {
|
|
48
|
+
logger?: MailooLogger;
|
|
49
|
+
/** Delivery webhook signing secret (integration config.deliveryWebhook.secret). */
|
|
50
|
+
secret: string | (() => string | null | Promise<string | null>);
|
|
51
|
+
onEvent: (payload: MailooDeliveryWebhookPayload, request: NextRequest) => Promise<Response | void> | Response | void;
|
|
52
|
+
};
|
|
53
|
+
/**
|
|
54
|
+
* Inbound Mailoo delivery webhook (HMAC). Use for consent.changed and
|
|
55
|
+
* delivered/opened/clicked/unsubscribed/bounced.
|
|
56
|
+
*/
|
|
57
|
+
declare function createDeliveryWebhookHandler(options: CreateDeliveryWebhookHandlerOptions): (request: NextRequest) => Promise<Response>;
|
|
58
|
+
|
|
59
|
+
export { type CreateDeliveryWebhookHandlerOptions, type CreateFormsHandlerOptions, createDeliveryWebhookHandler, createFeedbackSubmitHandler, createFormSubmitHandler, createLifecycleEventHandler, createLifecycleRetryHandler, createLifecycleStatusHandler };
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { NextRequest } from 'next/server';
|
|
2
|
+
import { MailooLogger, MailooIntegrationConfig } from '@mailoo/next-core';
|
|
3
|
+
import { MailooDeliveryWebhookPayload } from '../webhooks/index.js';
|
|
4
|
+
|
|
5
|
+
type CreateFormsHandlerOptions = {
|
|
6
|
+
logger?: MailooLogger;
|
|
7
|
+
/**
|
|
8
|
+
* Env prefix for credentials and (feedback) metadata/allowlist.
|
|
9
|
+
* Defaults: form → MAILOO_CONTACT_FORM_INTEGRATION;
|
|
10
|
+
* feedback → MAILOO_FEEDBACK_INTEGRATION;
|
|
11
|
+
* lifecycle → MAILOO_LIFECYCLE.
|
|
12
|
+
*/
|
|
13
|
+
prefix?: string;
|
|
14
|
+
/** Explicit config; wins over prefix/env when provided. */
|
|
15
|
+
getConfig?: () => MailooIntegrationConfig | null;
|
|
16
|
+
};
|
|
17
|
+
declare function createFormSubmitHandler(options?: CreateFormsHandlerOptions): (request: NextRequest) => Promise<Response>;
|
|
18
|
+
declare function createFeedbackSubmitHandler(options?: CreateFormsHandlerOptions): (request: NextRequest) => Promise<Response>;
|
|
19
|
+
/**
|
|
20
|
+
* BFF POST → Mailoo lifecycle ingest. Browser posts here; key stays on server.
|
|
21
|
+
* Body must include an explicit catalog `eventName` (no defaults).
|
|
22
|
+
*
|
|
23
|
+
* **Security:** this handler is an open proxy for any client that can reach the
|
|
24
|
+
* BFF. Integrators with identified users must verify a session and overwrite
|
|
25
|
+
* `externalUserId` / `email` from the session (do not trust the browser body).
|
|
26
|
+
*/
|
|
27
|
+
declare function createLifecycleEventHandler(options?: CreateFormsHandlerOptions): (request: NextRequest) => Promise<Response>;
|
|
28
|
+
/**
|
|
29
|
+
* BFF POST → Mailoo lifecycle event retry.
|
|
30
|
+
* Mount at e.g. `app/api/v1/webhooks/lifecycle/events/[eventId]/retry/route.ts`
|
|
31
|
+
* and pass `eventId` from the route params (or read from the URL path).
|
|
32
|
+
*/
|
|
33
|
+
declare function createLifecycleRetryHandler(options?: CreateFormsHandlerOptions & {
|
|
34
|
+
getEventId?: (request: NextRequest) => string | null;
|
|
35
|
+
}): (request: NextRequest, context?: {
|
|
36
|
+
params?: Promise<{
|
|
37
|
+
eventId?: string;
|
|
38
|
+
}> | {
|
|
39
|
+
eventId?: string;
|
|
40
|
+
};
|
|
41
|
+
}) => Promise<Response>;
|
|
42
|
+
/**
|
|
43
|
+
* BFF GET → Mailoo lifecycle status.
|
|
44
|
+
* Forwards `externalUserId`, `externalUserIds`, and `emails` query params.
|
|
45
|
+
*/
|
|
46
|
+
declare function createLifecycleStatusHandler(options?: CreateFormsHandlerOptions): (request: NextRequest) => Promise<Response>;
|
|
47
|
+
type CreateDeliveryWebhookHandlerOptions = {
|
|
48
|
+
logger?: MailooLogger;
|
|
49
|
+
/** Delivery webhook signing secret (integration config.deliveryWebhook.secret). */
|
|
50
|
+
secret: string | (() => string | null | Promise<string | null>);
|
|
51
|
+
onEvent: (payload: MailooDeliveryWebhookPayload, request: NextRequest) => Promise<Response | void> | Response | void;
|
|
52
|
+
};
|
|
53
|
+
/**
|
|
54
|
+
* Inbound Mailoo delivery webhook (HMAC). Use for consent.changed and
|
|
55
|
+
* delivered/opened/clicked/unsubscribed/bounced.
|
|
56
|
+
*/
|
|
57
|
+
declare function createDeliveryWebhookHandler(options: CreateDeliveryWebhookHandlerOptions): (request: NextRequest) => Promise<Response>;
|
|
58
|
+
|
|
59
|
+
export { type CreateDeliveryWebhookHandlerOptions, type CreateFormsHandlerOptions, createDeliveryWebhookHandler, createFeedbackSubmitHandler, createFormSubmitHandler, createLifecycleEventHandler, createLifecycleRetryHandler, createLifecycleStatusHandler };
|
|
@@ -0,0 +1,351 @@
|
|
|
1
|
+
import {
|
|
2
|
+
MAILOO_FEEDBACK_INTEGRATION_PREFIX,
|
|
3
|
+
MAILOO_FORM_INTEGRATION_PREFIX,
|
|
4
|
+
MAILOO_LIFECYCLE_INTEGRATION_PREFIX,
|
|
5
|
+
getMailooFormsIntegrationConfig
|
|
6
|
+
} from "../chunk-QBZAYHBD.js";
|
|
7
|
+
import {
|
|
8
|
+
validateMailooLifecycleEvent
|
|
9
|
+
} from "../chunk-4B377BWO.js";
|
|
10
|
+
import {
|
|
11
|
+
verifyMailooDeliveryWebhook
|
|
12
|
+
} from "../chunk-LD246ORB.js";
|
|
13
|
+
|
|
14
|
+
// src/routes/index.ts
|
|
15
|
+
import {
|
|
16
|
+
defaultMailooLogger,
|
|
17
|
+
jsonError,
|
|
18
|
+
proxyMailooApiGet,
|
|
19
|
+
proxyMailooWebhookJsonPost
|
|
20
|
+
} from "@mailoo/next-core";
|
|
21
|
+
var EMAIL_RE = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
|
|
22
|
+
function isPlainObject(v) {
|
|
23
|
+
return typeof v === "object" && v !== null && !Array.isArray(v);
|
|
24
|
+
}
|
|
25
|
+
function resolveFormsConfig(options, defaultPrefix) {
|
|
26
|
+
const prefix = options?.prefix ?? defaultPrefix;
|
|
27
|
+
const config = options?.getConfig?.() ?? getMailooFormsIntegrationConfig({ prefix });
|
|
28
|
+
return { config, prefix };
|
|
29
|
+
}
|
|
30
|
+
function createFormSubmitHandler(options) {
|
|
31
|
+
const logger = options?.logger ?? defaultMailooLogger;
|
|
32
|
+
const defaultPrefix = MAILOO_FORM_INTEGRATION_PREFIX;
|
|
33
|
+
return async function POST(request) {
|
|
34
|
+
const { config, prefix } = resolveFormsConfig(options, defaultPrefix);
|
|
35
|
+
if (!config) {
|
|
36
|
+
logger.error(
|
|
37
|
+
`${prefix}_API, _API_KEY, _PROJECT_UID and _ID (or _INTEGRATION_ID) must be set`
|
|
38
|
+
);
|
|
39
|
+
return jsonError(
|
|
40
|
+
{ success: false, message: "Form integration not configured" },
|
|
41
|
+
503
|
|
42
|
+
);
|
|
43
|
+
}
|
|
44
|
+
let body;
|
|
45
|
+
try {
|
|
46
|
+
body = await request.json();
|
|
47
|
+
} catch {
|
|
48
|
+
return jsonError(
|
|
49
|
+
{ success: false, message: "Invalid JSON body" },
|
|
50
|
+
400
|
|
51
|
+
);
|
|
52
|
+
}
|
|
53
|
+
const email = typeof body.email === "string" ? body.email.trim() : "";
|
|
54
|
+
if (!email) {
|
|
55
|
+
return jsonError(
|
|
56
|
+
{ success: false, message: "Email is required" },
|
|
57
|
+
400
|
|
58
|
+
);
|
|
59
|
+
}
|
|
60
|
+
if (!EMAIL_RE.test(email)) {
|
|
61
|
+
return jsonError(
|
|
62
|
+
{ success: false, message: "Invalid email format" },
|
|
63
|
+
400
|
|
64
|
+
);
|
|
65
|
+
}
|
|
66
|
+
const upstreamBody = { email };
|
|
67
|
+
if (typeof body.name === "string" && body.name.trim()) {
|
|
68
|
+
upstreamBody.name = body.name.trim();
|
|
69
|
+
}
|
|
70
|
+
if (typeof body.subject === "string" && body.subject.trim()) {
|
|
71
|
+
upstreamBody.subject = body.subject.trim();
|
|
72
|
+
}
|
|
73
|
+
if (typeof body.content === "string" && body.content.trim()) {
|
|
74
|
+
upstreamBody.content = body.content.trim();
|
|
75
|
+
}
|
|
76
|
+
if (typeof body.source === "string" && body.source.trim()) {
|
|
77
|
+
upstreamBody.source = body.source.trim();
|
|
78
|
+
}
|
|
79
|
+
if (isPlainObject(body.metadata)) {
|
|
80
|
+
upstreamBody.metadata = body.metadata;
|
|
81
|
+
}
|
|
82
|
+
const url = `${config.apiBaseUrl}/api/v1/webhooks/forms/${config.projectUid}/${config.integrationId}`;
|
|
83
|
+
try {
|
|
84
|
+
return await proxyMailooWebhookJsonPost({
|
|
85
|
+
request,
|
|
86
|
+
url,
|
|
87
|
+
apiKey: config.apiKey,
|
|
88
|
+
body: upstreamBody
|
|
89
|
+
});
|
|
90
|
+
} catch (error) {
|
|
91
|
+
logger.logException?.(error, "Form submit proxy error");
|
|
92
|
+
return jsonError(
|
|
93
|
+
{ success: false, message: "Internal server error" },
|
|
94
|
+
500
|
|
95
|
+
);
|
|
96
|
+
}
|
|
97
|
+
};
|
|
98
|
+
}
|
|
99
|
+
function createFeedbackSubmitHandler(options) {
|
|
100
|
+
const logger = options?.logger ?? defaultMailooLogger;
|
|
101
|
+
const defaultPrefix = MAILOO_FEEDBACK_INTEGRATION_PREFIX;
|
|
102
|
+
return async function POST(request) {
|
|
103
|
+
const { config, prefix } = resolveFormsConfig(options, defaultPrefix);
|
|
104
|
+
if (!config) {
|
|
105
|
+
logger.error(
|
|
106
|
+
`${prefix}_API, _API_KEY, _PROJECT_UID and _ID (or _INTEGRATION_ID) must be set`
|
|
107
|
+
);
|
|
108
|
+
return jsonError(
|
|
109
|
+
{ success: false, message: "Feedback integration not configured" },
|
|
110
|
+
503
|
|
111
|
+
);
|
|
112
|
+
}
|
|
113
|
+
let body;
|
|
114
|
+
try {
|
|
115
|
+
body = await request.json();
|
|
116
|
+
} catch {
|
|
117
|
+
return jsonError(
|
|
118
|
+
{ success: false, message: "Invalid JSON body" },
|
|
119
|
+
400
|
|
120
|
+
);
|
|
121
|
+
}
|
|
122
|
+
const email = typeof body.email === "string" ? body.email.trim() : "";
|
|
123
|
+
const message = typeof body.message === "string" ? body.message.trim() : "";
|
|
124
|
+
if (!email || !message) {
|
|
125
|
+
return jsonError(
|
|
126
|
+
{ success: false, message: "Email and message are required" },
|
|
127
|
+
400
|
|
128
|
+
);
|
|
129
|
+
}
|
|
130
|
+
const clientMeta = isPlainObject(body.metadata) ? { ...body.metadata } : {};
|
|
131
|
+
const topLevelFormKey = typeof body.formKey === "string" ? body.formKey.trim() : "";
|
|
132
|
+
if (topLevelFormKey && clientMeta.formKey === void 0) {
|
|
133
|
+
clientMeta.formKey = topLevelFormKey;
|
|
134
|
+
}
|
|
135
|
+
const namespace = process.env[`${prefix}_FORM_NAMESPACE`]?.trim();
|
|
136
|
+
if (namespace) clientMeta.siteFormNamespace = namespace;
|
|
137
|
+
const siteId = process.env[`${prefix}_SITE_ID`]?.trim();
|
|
138
|
+
if (siteId) clientMeta.siteId = siteId;
|
|
139
|
+
const allowedKeysRaw = process.env[`${prefix}_ALLOWED_FORM_KEYS`]?.trim();
|
|
140
|
+
if (allowedKeysRaw) {
|
|
141
|
+
const allowed = allowedKeysRaw.split(",").map((s) => s.trim()).filter(Boolean);
|
|
142
|
+
const fk = typeof clientMeta.formKey === "string" ? clientMeta.formKey.trim() : "";
|
|
143
|
+
if (!fk || !allowed.includes(fk)) {
|
|
144
|
+
return jsonError(
|
|
145
|
+
{ success: false, message: "Invalid or disallowed formKey" },
|
|
146
|
+
400
|
|
147
|
+
);
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
const name = typeof body.name === "string" && body.name.trim() ? body.name.trim() : void 0;
|
|
151
|
+
const subject = typeof body.subject === "string" && body.subject.trim() ? body.subject.trim() : void 0;
|
|
152
|
+
const upstreamBody = {
|
|
153
|
+
email,
|
|
154
|
+
message,
|
|
155
|
+
metadata: clientMeta
|
|
156
|
+
};
|
|
157
|
+
if (name) upstreamBody.name = name;
|
|
158
|
+
if (subject) upstreamBody.subject = subject;
|
|
159
|
+
const url = `${config.apiBaseUrl}/api/v1/webhooks/feedback/${config.projectUid}/${config.integrationId}`;
|
|
160
|
+
try {
|
|
161
|
+
return await proxyMailooWebhookJsonPost({
|
|
162
|
+
request,
|
|
163
|
+
url,
|
|
164
|
+
apiKey: config.apiKey,
|
|
165
|
+
body: upstreamBody
|
|
166
|
+
});
|
|
167
|
+
} catch (error) {
|
|
168
|
+
logger.logException?.(error, "Feedback submit proxy error");
|
|
169
|
+
return jsonError(
|
|
170
|
+
{ success: false, message: "Internal server error" },
|
|
171
|
+
500
|
|
172
|
+
);
|
|
173
|
+
}
|
|
174
|
+
};
|
|
175
|
+
}
|
|
176
|
+
function createLifecycleEventHandler(options) {
|
|
177
|
+
const logger = options?.logger ?? defaultMailooLogger;
|
|
178
|
+
const defaultPrefix = MAILOO_LIFECYCLE_INTEGRATION_PREFIX;
|
|
179
|
+
return async function POST(request) {
|
|
180
|
+
const { config, prefix } = resolveFormsConfig(options, defaultPrefix);
|
|
181
|
+
if (!config) {
|
|
182
|
+
logger.error(
|
|
183
|
+
`${prefix}_API, _API_KEY, _PROJECT_UID and _ID (or _INTEGRATION_ID) must be set`
|
|
184
|
+
);
|
|
185
|
+
return jsonError(
|
|
186
|
+
{ success: false, message: "Lifecycle integration not configured" },
|
|
187
|
+
503
|
|
188
|
+
);
|
|
189
|
+
}
|
|
190
|
+
let raw;
|
|
191
|
+
try {
|
|
192
|
+
raw = await request.json();
|
|
193
|
+
} catch {
|
|
194
|
+
return jsonError(
|
|
195
|
+
{ success: false, message: "Invalid JSON body" },
|
|
196
|
+
400
|
|
197
|
+
);
|
|
198
|
+
}
|
|
199
|
+
const validated = validateMailooLifecycleEvent(raw);
|
|
200
|
+
if (!validated.ok) {
|
|
201
|
+
return jsonError({ success: false, message: validated.message }, 400);
|
|
202
|
+
}
|
|
203
|
+
const url = `${config.apiBaseUrl}/api/v1/webhooks/lifecycle/${config.projectUid}/${config.integrationId}/events`;
|
|
204
|
+
try {
|
|
205
|
+
return await proxyMailooWebhookJsonPost({
|
|
206
|
+
request,
|
|
207
|
+
url,
|
|
208
|
+
apiKey: config.apiKey,
|
|
209
|
+
body: validated.value
|
|
210
|
+
});
|
|
211
|
+
} catch (error) {
|
|
212
|
+
logger.logException?.(error, "Lifecycle event proxy error");
|
|
213
|
+
return jsonError(
|
|
214
|
+
{ success: false, message: "Internal server error" },
|
|
215
|
+
500
|
|
216
|
+
);
|
|
217
|
+
}
|
|
218
|
+
};
|
|
219
|
+
}
|
|
220
|
+
function createLifecycleRetryHandler(options) {
|
|
221
|
+
const logger = options?.logger ?? defaultMailooLogger;
|
|
222
|
+
const defaultPrefix = MAILOO_LIFECYCLE_INTEGRATION_PREFIX;
|
|
223
|
+
return async function POST(request, context) {
|
|
224
|
+
const { config, prefix } = resolveFormsConfig(options, defaultPrefix);
|
|
225
|
+
if (!config) {
|
|
226
|
+
logger.error(
|
|
227
|
+
`${prefix}_API, _API_KEY, _PROJECT_UID and _ID (or _INTEGRATION_ID) must be set`
|
|
228
|
+
);
|
|
229
|
+
return jsonError(
|
|
230
|
+
{ success: false, message: "Lifecycle integration not configured" },
|
|
231
|
+
503
|
|
232
|
+
);
|
|
233
|
+
}
|
|
234
|
+
let eventId = null;
|
|
235
|
+
if (options?.getEventId) {
|
|
236
|
+
eventId = options.getEventId(request);
|
|
237
|
+
} else if (context?.params) {
|
|
238
|
+
const params = await Promise.resolve(context.params);
|
|
239
|
+
eventId = typeof params?.eventId === "string" ? params.eventId.trim() : null;
|
|
240
|
+
}
|
|
241
|
+
if (!eventId) {
|
|
242
|
+
const parts = request.nextUrl.pathname.split("/").filter(Boolean);
|
|
243
|
+
const eventsIdx = parts.lastIndexOf("events");
|
|
244
|
+
if (eventsIdx >= 0 && parts[eventsIdx + 1]) {
|
|
245
|
+
eventId = parts[eventsIdx + 1];
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
if (!eventId) {
|
|
249
|
+
return jsonError({ success: false, message: "eventId is required" }, 400);
|
|
250
|
+
}
|
|
251
|
+
const url = `${config.apiBaseUrl}/api/v1/webhooks/lifecycle/${config.projectUid}/${config.integrationId}/events/${encodeURIComponent(eventId)}/retry`;
|
|
252
|
+
try {
|
|
253
|
+
return await proxyMailooWebhookJsonPost({
|
|
254
|
+
request,
|
|
255
|
+
url,
|
|
256
|
+
apiKey: config.apiKey,
|
|
257
|
+
body: {}
|
|
258
|
+
});
|
|
259
|
+
} catch (error) {
|
|
260
|
+
logger.logException?.(error, "Lifecycle retry proxy error");
|
|
261
|
+
return jsonError(
|
|
262
|
+
{ success: false, message: "Internal server error" },
|
|
263
|
+
500
|
|
264
|
+
);
|
|
265
|
+
}
|
|
266
|
+
};
|
|
267
|
+
}
|
|
268
|
+
function createLifecycleStatusHandler(options) {
|
|
269
|
+
const logger = options?.logger ?? defaultMailooLogger;
|
|
270
|
+
const defaultPrefix = MAILOO_LIFECYCLE_INTEGRATION_PREFIX;
|
|
271
|
+
return async function GET(request) {
|
|
272
|
+
const { config, prefix } = resolveFormsConfig(options, defaultPrefix);
|
|
273
|
+
if (!config) {
|
|
274
|
+
logger.error(
|
|
275
|
+
`${prefix}_API, _API_KEY, _PROJECT_UID and _ID (or _INTEGRATION_ID) must be set`
|
|
276
|
+
);
|
|
277
|
+
return jsonError(
|
|
278
|
+
{ success: false, message: "Lifecycle integration not configured" },
|
|
279
|
+
503
|
|
280
|
+
);
|
|
281
|
+
}
|
|
282
|
+
const params = new URLSearchParams();
|
|
283
|
+
for (const key of [
|
|
284
|
+
"externalUserId",
|
|
285
|
+
"externalUserIds",
|
|
286
|
+
"emails"
|
|
287
|
+
]) {
|
|
288
|
+
const value = request.nextUrl.searchParams.get(key)?.trim();
|
|
289
|
+
if (value) params.set(key, value);
|
|
290
|
+
}
|
|
291
|
+
const qs = params.toString() ? `?${params.toString()}` : "";
|
|
292
|
+
const url = `${config.apiBaseUrl}/api/v1/webhooks/lifecycle/${config.projectUid}/${config.integrationId}/status${qs}`;
|
|
293
|
+
try {
|
|
294
|
+
return await proxyMailooApiGet({
|
|
295
|
+
url,
|
|
296
|
+
apiKey: config.apiKey
|
|
297
|
+
});
|
|
298
|
+
} catch (error) {
|
|
299
|
+
logger.logException?.(error, "Lifecycle status proxy error");
|
|
300
|
+
return jsonError(
|
|
301
|
+
{ success: false, message: "Internal server error" },
|
|
302
|
+
500
|
|
303
|
+
);
|
|
304
|
+
}
|
|
305
|
+
};
|
|
306
|
+
}
|
|
307
|
+
function createDeliveryWebhookHandler(options) {
|
|
308
|
+
const logger = options.logger ?? defaultMailooLogger;
|
|
309
|
+
return async function POST(request) {
|
|
310
|
+
const secretValue = typeof options.secret === "function" ? await options.secret() : options.secret;
|
|
311
|
+
if (!secretValue?.trim()) {
|
|
312
|
+
logger.error("Delivery webhook secret is not configured");
|
|
313
|
+
return jsonError(
|
|
314
|
+
{ success: false, message: "Delivery webhook not configured" },
|
|
315
|
+
503
|
|
316
|
+
);
|
|
317
|
+
}
|
|
318
|
+
const rawBody = await request.text();
|
|
319
|
+
const verified = verifyMailooDeliveryWebhook(
|
|
320
|
+
rawBody,
|
|
321
|
+
request.headers,
|
|
322
|
+
secretValue
|
|
323
|
+
);
|
|
324
|
+
if (!verified.ok) {
|
|
325
|
+
return jsonError({ success: false, message: verified.message }, 401);
|
|
326
|
+
}
|
|
327
|
+
try {
|
|
328
|
+
const maybe = await options.onEvent(verified.payload, request);
|
|
329
|
+
if (maybe instanceof Response) return maybe;
|
|
330
|
+
return new Response(JSON.stringify({ success: true }), {
|
|
331
|
+
status: 200,
|
|
332
|
+
headers: { "Content-Type": "application/json" }
|
|
333
|
+
});
|
|
334
|
+
} catch (error) {
|
|
335
|
+
logger.logException?.(error, "Delivery webhook handler error");
|
|
336
|
+
return jsonError(
|
|
337
|
+
{ success: false, message: "Internal server error" },
|
|
338
|
+
500
|
|
339
|
+
);
|
|
340
|
+
}
|
|
341
|
+
};
|
|
342
|
+
}
|
|
343
|
+
export {
|
|
344
|
+
createDeliveryWebhookHandler,
|
|
345
|
+
createFeedbackSubmitHandler,
|
|
346
|
+
createFormSubmitHandler,
|
|
347
|
+
createLifecycleEventHandler,
|
|
348
|
+
createLifecycleRetryHandler,
|
|
349
|
+
createLifecycleStatusHandler
|
|
350
|
+
};
|
|
351
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/routes/index.ts"],"sourcesContent":["import type { NextRequest } from 'next/server'\nimport {\n defaultMailooLogger,\n jsonError,\n proxyMailooApiGet,\n proxyMailooWebhookJsonPost,\n type MailooIntegrationConfig,\n type MailooLogger,\n} from '@mailoo/next-core'\nimport {\n getMailooFormsIntegrationConfig,\n MAILOO_FEEDBACK_INTEGRATION_PREFIX,\n MAILOO_FORM_INTEGRATION_PREFIX,\n MAILOO_LIFECYCLE_INTEGRATION_PREFIX,\n} from '../config.js'\nimport { validateMailooLifecycleEvent } from '../events/index.js'\nimport {\n verifyMailooDeliveryWebhook,\n type MailooDeliveryWebhookPayload,\n} from '../webhooks/index.js'\n\nconst EMAIL_RE = /^[^\\s@]+@[^\\s@]+\\.[^\\s@]+$/\n\nfunction isPlainObject(v: unknown): v is Record<string, unknown> {\n return typeof v === 'object' && v !== null && !Array.isArray(v)\n}\n\nexport type CreateFormsHandlerOptions = {\n logger?: MailooLogger\n /**\n * Env prefix for credentials and (feedback) metadata/allowlist.\n * Defaults: form → MAILOO_CONTACT_FORM_INTEGRATION;\n * feedback → MAILOO_FEEDBACK_INTEGRATION;\n * lifecycle → MAILOO_LIFECYCLE.\n */\n prefix?: string\n /** Explicit config; wins over prefix/env when provided. */\n getConfig?: () => MailooIntegrationConfig | null\n}\n\nfunction resolveFormsConfig(\n options: CreateFormsHandlerOptions | undefined,\n defaultPrefix: string\n): { config: MailooIntegrationConfig | null; prefix: string } {\n const prefix = options?.prefix ?? defaultPrefix\n const config =\n options?.getConfig?.() ?? getMailooFormsIntegrationConfig({ prefix })\n return { config, prefix }\n}\n\nexport function createFormSubmitHandler(\n options?: CreateFormsHandlerOptions\n) {\n const logger = options?.logger ?? defaultMailooLogger\n const defaultPrefix = MAILOO_FORM_INTEGRATION_PREFIX\n return async function POST(request: NextRequest): Promise<Response> {\n const { config, prefix } = resolveFormsConfig(options, defaultPrefix)\n if (!config) {\n logger.error(\n `${prefix}_API, _API_KEY, _PROJECT_UID and _ID (or _INTEGRATION_ID) must be set`\n )\n return jsonError(\n { success: false, message: 'Form integration not configured' },\n 503\n )\n }\n\n let body: Record<string, unknown>\n try {\n body = (await request.json()) as Record<string, unknown>\n } catch {\n return jsonError(\n { success: false, message: 'Invalid JSON body' },\n 400\n )\n }\n\n const email = typeof body.email === 'string' ? body.email.trim() : ''\n if (!email) {\n return jsonError(\n { success: false, message: 'Email is required' },\n 400\n )\n }\n if (!EMAIL_RE.test(email)) {\n return jsonError(\n { success: false, message: 'Invalid email format' },\n 400\n )\n }\n\n const upstreamBody: Record<string, unknown> = { email }\n if (typeof body.name === 'string' && body.name.trim()) {\n upstreamBody.name = body.name.trim()\n }\n if (typeof body.subject === 'string' && body.subject.trim()) {\n upstreamBody.subject = body.subject.trim()\n }\n if (typeof body.content === 'string' && body.content.trim()) {\n upstreamBody.content = body.content.trim()\n }\n if (typeof body.source === 'string' && body.source.trim()) {\n upstreamBody.source = body.source.trim()\n }\n if (isPlainObject(body.metadata)) {\n upstreamBody.metadata = body.metadata\n }\n\n const url = `${config.apiBaseUrl}/api/v1/webhooks/forms/${config.projectUid}/${config.integrationId}`\n try {\n return await proxyMailooWebhookJsonPost({\n request,\n url,\n apiKey: config.apiKey,\n body: upstreamBody,\n })\n } catch (error) {\n logger.logException?.(error, 'Form submit proxy error')\n return jsonError(\n { success: false, message: 'Internal server error' },\n 500\n )\n }\n }\n}\n\nexport function createFeedbackSubmitHandler(\n options?: CreateFormsHandlerOptions\n) {\n const logger = options?.logger ?? defaultMailooLogger\n const defaultPrefix = MAILOO_FEEDBACK_INTEGRATION_PREFIX\n return async function POST(request: NextRequest): Promise<Response> {\n const { config, prefix } = resolveFormsConfig(options, defaultPrefix)\n if (!config) {\n logger.error(\n `${prefix}_API, _API_KEY, _PROJECT_UID and _ID (or _INTEGRATION_ID) must be set`\n )\n return jsonError(\n { success: false, message: 'Feedback integration not configured' },\n 503\n )\n }\n\n let body: Record<string, unknown>\n try {\n body = (await request.json()) as Record<string, unknown>\n } catch {\n return jsonError(\n { success: false, message: 'Invalid JSON body' },\n 400\n )\n }\n\n const email = typeof body.email === 'string' ? body.email.trim() : ''\n const message = typeof body.message === 'string' ? body.message.trim() : ''\n if (!email || !message) {\n return jsonError(\n { success: false, message: 'Email and message are required' },\n 400\n )\n }\n\n const clientMeta = isPlainObject(body.metadata) ? { ...body.metadata } : {}\n const topLevelFormKey =\n typeof body.formKey === 'string' ? body.formKey.trim() : ''\n if (topLevelFormKey && clientMeta.formKey === undefined) {\n clientMeta.formKey = topLevelFormKey\n }\n\n const namespace = process.env[`${prefix}_FORM_NAMESPACE`]?.trim()\n if (namespace) clientMeta.siteFormNamespace = namespace\n const siteId = process.env[`${prefix}_SITE_ID`]?.trim()\n if (siteId) clientMeta.siteId = siteId\n\n const allowedKeysRaw = process.env[`${prefix}_ALLOWED_FORM_KEYS`]?.trim()\n if (allowedKeysRaw) {\n const allowed = allowedKeysRaw\n .split(',')\n .map((s) => s.trim())\n .filter(Boolean)\n const fk =\n typeof clientMeta.formKey === 'string' ? clientMeta.formKey.trim() : ''\n if (!fk || !allowed.includes(fk)) {\n return jsonError(\n { success: false, message: 'Invalid or disallowed formKey' },\n 400\n )\n }\n }\n\n const name =\n typeof body.name === 'string' && body.name.trim()\n ? body.name.trim()\n : undefined\n const subject =\n typeof body.subject === 'string' && body.subject.trim()\n ? body.subject.trim()\n : undefined\n\n const upstreamBody: Record<string, unknown> = {\n email,\n message,\n metadata: clientMeta,\n }\n if (name) upstreamBody.name = name\n if (subject) upstreamBody.subject = subject\n\n const url = `${config.apiBaseUrl}/api/v1/webhooks/feedback/${config.projectUid}/${config.integrationId}`\n try {\n return await proxyMailooWebhookJsonPost({\n request,\n url,\n apiKey: config.apiKey,\n body: upstreamBody,\n })\n } catch (error) {\n logger.logException?.(error, 'Feedback submit proxy error')\n return jsonError(\n { success: false, message: 'Internal server error' },\n 500\n )\n }\n }\n}\n\n/**\n * BFF POST → Mailoo lifecycle ingest. Browser posts here; key stays on server.\n * Body must include an explicit catalog `eventName` (no defaults).\n *\n * **Security:** this handler is an open proxy for any client that can reach the\n * BFF. Integrators with identified users must verify a session and overwrite\n * `externalUserId` / `email` from the session (do not trust the browser body).\n */\nexport function createLifecycleEventHandler(\n options?: CreateFormsHandlerOptions\n) {\n const logger = options?.logger ?? defaultMailooLogger\n const defaultPrefix = MAILOO_LIFECYCLE_INTEGRATION_PREFIX\n return async function POST(request: NextRequest): Promise<Response> {\n const { config, prefix } = resolveFormsConfig(options, defaultPrefix)\n if (!config) {\n logger.error(\n `${prefix}_API, _API_KEY, _PROJECT_UID and _ID (or _INTEGRATION_ID) must be set`\n )\n return jsonError(\n { success: false, message: 'Lifecycle integration not configured' },\n 503\n )\n }\n\n let raw: unknown\n try {\n raw = await request.json()\n } catch {\n return jsonError(\n { success: false, message: 'Invalid JSON body' },\n 400\n )\n }\n\n const validated = validateMailooLifecycleEvent(raw)\n if (!validated.ok) {\n return jsonError({ success: false, message: validated.message }, 400)\n }\n\n const url = `${config.apiBaseUrl}/api/v1/webhooks/lifecycle/${config.projectUid}/${config.integrationId}/events`\n try {\n return await proxyMailooWebhookJsonPost({\n request,\n url,\n apiKey: config.apiKey,\n body: validated.value,\n })\n } catch (error) {\n logger.logException?.(error, 'Lifecycle event proxy error')\n return jsonError(\n { success: false, message: 'Internal server error' },\n 500\n )\n }\n }\n}\n\n/**\n * BFF POST → Mailoo lifecycle event retry.\n * Mount at e.g. `app/api/v1/webhooks/lifecycle/events/[eventId]/retry/route.ts`\n * and pass `eventId` from the route params (or read from the URL path).\n */\nexport function createLifecycleRetryHandler(\n options?: CreateFormsHandlerOptions & {\n getEventId?: (request: NextRequest) => string | null\n }\n) {\n const logger = options?.logger ?? defaultMailooLogger\n const defaultPrefix = MAILOO_LIFECYCLE_INTEGRATION_PREFIX\n return async function POST(\n request: NextRequest,\n context?: { params?: Promise<{ eventId?: string }> | { eventId?: string } }\n ): Promise<Response> {\n const { config, prefix } = resolveFormsConfig(options, defaultPrefix)\n if (!config) {\n logger.error(\n `${prefix}_API, _API_KEY, _PROJECT_UID and _ID (or _INTEGRATION_ID) must be set`\n )\n return jsonError(\n { success: false, message: 'Lifecycle integration not configured' },\n 503\n )\n }\n\n let eventId: string | null = null\n if (options?.getEventId) {\n eventId = options.getEventId(request)\n } else if (context?.params) {\n const params = await Promise.resolve(context.params)\n eventId =\n typeof params?.eventId === 'string' ? params.eventId.trim() : null\n }\n if (!eventId) {\n const parts = request.nextUrl.pathname.split('/').filter(Boolean)\n const eventsIdx = parts.lastIndexOf('events')\n if (eventsIdx >= 0 && parts[eventsIdx + 1]) {\n eventId = parts[eventsIdx + 1]\n }\n }\n if (!eventId) {\n return jsonError({ success: false, message: 'eventId is required' }, 400)\n }\n\n const url = `${config.apiBaseUrl}/api/v1/webhooks/lifecycle/${config.projectUid}/${config.integrationId}/events/${encodeURIComponent(eventId)}/retry`\n try {\n return await proxyMailooWebhookJsonPost({\n request,\n url,\n apiKey: config.apiKey,\n body: {},\n })\n } catch (error) {\n logger.logException?.(error, 'Lifecycle retry proxy error')\n return jsonError(\n { success: false, message: 'Internal server error' },\n 500\n )\n }\n }\n}\n\n/**\n * BFF GET → Mailoo lifecycle status.\n * Forwards `externalUserId`, `externalUserIds`, and `emails` query params.\n */\nexport function createLifecycleStatusHandler(\n options?: CreateFormsHandlerOptions\n) {\n const logger = options?.logger ?? defaultMailooLogger\n const defaultPrefix = MAILOO_LIFECYCLE_INTEGRATION_PREFIX\n return async function GET(request: NextRequest): Promise<Response> {\n const { config, prefix } = resolveFormsConfig(options, defaultPrefix)\n if (!config) {\n logger.error(\n `${prefix}_API, _API_KEY, _PROJECT_UID and _ID (or _INTEGRATION_ID) must be set`\n )\n return jsonError(\n { success: false, message: 'Lifecycle integration not configured' },\n 503\n )\n }\n\n const params = new URLSearchParams()\n for (const key of [\n 'externalUserId',\n 'externalUserIds',\n 'emails',\n ] as const) {\n const value = request.nextUrl.searchParams.get(key)?.trim()\n if (value) params.set(key, value)\n }\n const qs = params.toString() ? `?${params.toString()}` : ''\n const url = `${config.apiBaseUrl}/api/v1/webhooks/lifecycle/${config.projectUid}/${config.integrationId}/status${qs}`\n try {\n return await proxyMailooApiGet({\n url,\n apiKey: config.apiKey,\n })\n } catch (error) {\n logger.logException?.(error, 'Lifecycle status proxy error')\n return jsonError(\n { success: false, message: 'Internal server error' },\n 500\n )\n }\n }\n}\n\nexport type CreateDeliveryWebhookHandlerOptions = {\n logger?: MailooLogger\n /** Delivery webhook signing secret (integration config.deliveryWebhook.secret). */\n secret: string | (() => string | null | Promise<string | null>)\n onEvent: (\n payload: MailooDeliveryWebhookPayload,\n request: NextRequest\n ) => Promise<Response | void> | Response | void\n}\n\n/**\n * Inbound Mailoo delivery webhook (HMAC). Use for consent.changed and\n * delivered/opened/clicked/unsubscribed/bounced.\n */\nexport function createDeliveryWebhookHandler(\n options: CreateDeliveryWebhookHandlerOptions\n) {\n const logger = options.logger ?? defaultMailooLogger\n return async function POST(request: NextRequest): Promise<Response> {\n const secretValue =\n typeof options.secret === 'function'\n ? await options.secret()\n : options.secret\n if (!secretValue?.trim()) {\n logger.error('Delivery webhook secret is not configured')\n return jsonError(\n { success: false, message: 'Delivery webhook not configured' },\n 503\n )\n }\n\n const rawBody = await request.text()\n const verified = verifyMailooDeliveryWebhook(\n rawBody,\n request.headers,\n secretValue\n )\n if (!verified.ok) {\n return jsonError({ success: false, message: verified.message }, 401)\n }\n\n try {\n const maybe = await options.onEvent(verified.payload, request)\n if (maybe instanceof Response) return maybe\n return new Response(JSON.stringify({ success: true }), {\n status: 200,\n headers: { 'Content-Type': 'application/json' },\n })\n } catch (error) {\n logger.logException?.(error, 'Delivery webhook handler error')\n return jsonError(\n { success: false, message: 'Internal server error' },\n 500\n )\n }\n }\n}\n"],"mappings":";;;;;;;;;;;;;;AACA;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OAGK;AAaP,IAAM,WAAW;AAEjB,SAAS,cAAc,GAA0C;AAC/D,SAAO,OAAO,MAAM,YAAY,MAAM,QAAQ,CAAC,MAAM,QAAQ,CAAC;AAChE;AAeA,SAAS,mBACP,SACA,eAC4D;AAC5D,QAAM,SAAS,SAAS,UAAU;AAClC,QAAM,SACJ,SAAS,YAAY,KAAK,gCAAgC,EAAE,OAAO,CAAC;AACtE,SAAO,EAAE,QAAQ,OAAO;AAC1B;AAEO,SAAS,wBACd,SACA;AACA,QAAM,SAAS,SAAS,UAAU;AAClC,QAAM,gBAAgB;AACtB,SAAO,eAAe,KAAK,SAAyC;AAClE,UAAM,EAAE,QAAQ,OAAO,IAAI,mBAAmB,SAAS,aAAa;AACpE,QAAI,CAAC,QAAQ;AACX,aAAO;AAAA,QACL,GAAG,MAAM;AAAA,MACX;AACA,aAAO;AAAA,QACL,EAAE,SAAS,OAAO,SAAS,kCAAkC;AAAA,QAC7D;AAAA,MACF;AAAA,IACF;AAEA,QAAI;AACJ,QAAI;AACF,aAAQ,MAAM,QAAQ,KAAK;AAAA,IAC7B,QAAQ;AACN,aAAO;AAAA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