mymx 0.3.5 → 0.3.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/contract.d.ts +1 -1
- package/dist/index.d.ts +170 -4
- package/dist/index.js +341 -2
- package/dist/{types-BRl0ogvI.d.cts → types-C8JlcpcT.d.ts} +211 -1
- package/dist/{zod-Ced9Kav9.js → zod-CalKEwR4.js} +65 -2
- package/dist/zod.d.ts +232 -2
- package/dist/zod.js +2 -2
- package/package.json +8 -27
- package/dist/contract.cjs +0 -188
- package/dist/contract.d.cts +0 -146
- package/dist/errors-CwKIO2XZ.d.cts +0 -211
- package/dist/errors-DOkb_I6u.cjs +0 -318
- package/dist/index.cjs +0 -869
- package/dist/index.d.cts +0 -764
- package/dist/signing-Bqe14lp0.cjs +0 -218
- package/dist/signing-ChbxCBRQ.d.cts +0 -84
- package/dist/types-DJTmrgCz.d.ts +0 -520
- package/dist/zod-CyQz4zEa.cjs +0 -384
- package/dist/zod.cjs +0 -16
- package/dist/zod.d.cts +0 -1356
package/dist/errors-DOkb_I6u.cjs
DELETED
|
@@ -1,318 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
//#region rolldown:runtime
|
|
3
|
-
var __create = Object.create;
|
|
4
|
-
var __defProp = Object.defineProperty;
|
|
5
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
6
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
7
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
8
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
9
|
-
var __copyProps = (to, from, except, desc) => {
|
|
10
|
-
if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
|
|
11
|
-
key = keys[i];
|
|
12
|
-
if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
|
|
13
|
-
get: ((k) => from[k]).bind(null, key),
|
|
14
|
-
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
15
|
-
});
|
|
16
|
-
}
|
|
17
|
-
return to;
|
|
18
|
-
};
|
|
19
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
|
|
20
|
-
value: mod,
|
|
21
|
-
enumerable: true
|
|
22
|
-
}) : target, mod));
|
|
23
|
-
|
|
24
|
-
//#endregion
|
|
25
|
-
|
|
26
|
-
//#region src/version.ts
|
|
27
|
-
/**
|
|
28
|
-
* Webhook API Version
|
|
29
|
-
*
|
|
30
|
-
* Single source of truth for the webhook version.
|
|
31
|
-
* Update this file when bumping the API version.
|
|
32
|
-
*/
|
|
33
|
-
/**
|
|
34
|
-
* The current webhook API version this SDK is built for.
|
|
35
|
-
* Webhooks may be sent with different versions - the SDK accepts any valid
|
|
36
|
-
* YYYY-MM-DD formatted version string. Compare against this constant if you
|
|
37
|
-
* need to handle version-specific behavior.
|
|
38
|
-
*/
|
|
39
|
-
const WEBHOOK_VERSION = "2025-12-14";
|
|
40
|
-
|
|
41
|
-
//#endregion
|
|
42
|
-
//#region src/errors.ts
|
|
43
|
-
/**
|
|
44
|
-
* Verification error definitions.
|
|
45
|
-
* Use these for documentation, dashboards, and i18n.
|
|
46
|
-
*/
|
|
47
|
-
const VERIFICATION_ERRORS = {
|
|
48
|
-
INVALID_SIGNATURE_HEADER: {
|
|
49
|
-
message: "Missing or malformed MyMX-Signature header",
|
|
50
|
-
suggestion: "Check that you're reading the correct header (MyMX-Signature) and it's being passed correctly from your web framework."
|
|
51
|
-
},
|
|
52
|
-
TIMESTAMP_OUT_OF_RANGE: {
|
|
53
|
-
message: "Timestamp is too old (possible replay attack)",
|
|
54
|
-
suggestion: "This could indicate a replay attack, network delay, or server clock drift. Check your server's time is synced."
|
|
55
|
-
},
|
|
56
|
-
SIGNATURE_MISMATCH: {
|
|
57
|
-
message: "Signature doesn't match expected value",
|
|
58
|
-
suggestion: "Verify the webhook secret matches and you're using the raw request body (not re-serialized JSON)."
|
|
59
|
-
},
|
|
60
|
-
MISSING_SECRET: {
|
|
61
|
-
message: "No webhook secret was provided",
|
|
62
|
-
suggestion: "Pass your webhook secret from the MyMX dashboard. Check that the environment variable is set."
|
|
63
|
-
}
|
|
64
|
-
};
|
|
65
|
-
/**
|
|
66
|
-
* Payload parsing error definitions.
|
|
67
|
-
* Use these for documentation, dashboards, and i18n.
|
|
68
|
-
*/
|
|
69
|
-
const PAYLOAD_ERRORS = {
|
|
70
|
-
PAYLOAD_NULL: {
|
|
71
|
-
message: "Webhook payload is null",
|
|
72
|
-
suggestion: "Ensure you're passing the parsed JSON body, not null. Check your framework's body parsing middleware."
|
|
73
|
-
},
|
|
74
|
-
PAYLOAD_UNDEFINED: {
|
|
75
|
-
message: "Webhook payload is undefined",
|
|
76
|
-
suggestion: "The payload was not provided. Make sure you're passing the request body to the handler."
|
|
77
|
-
},
|
|
78
|
-
PAYLOAD_WRONG_TYPE: {
|
|
79
|
-
message: "Webhook payload must be an object",
|
|
80
|
-
suggestion: "The payload should be a parsed JSON object. Check that you're not passing a string or other primitive."
|
|
81
|
-
},
|
|
82
|
-
PAYLOAD_IS_ARRAY: {
|
|
83
|
-
message: "Webhook payload is an array, expected object",
|
|
84
|
-
suggestion: "MyMX webhooks are single event objects, not arrays. Check the payload structure."
|
|
85
|
-
},
|
|
86
|
-
PAYLOAD_MISSING_EVENT: {
|
|
87
|
-
message: "Webhook payload missing 'event' field",
|
|
88
|
-
suggestion: "All webhook payloads must have an 'event' field. This may not be a valid MyMX webhook."
|
|
89
|
-
},
|
|
90
|
-
PAYLOAD_UNKNOWN_EVENT: {
|
|
91
|
-
message: "Unknown webhook event type",
|
|
92
|
-
suggestion: "This event type is not recognized. You may need to update your SDK or handle unknown events gracefully."
|
|
93
|
-
},
|
|
94
|
-
PAYLOAD_EMPTY_BODY: {
|
|
95
|
-
message: "Request body is empty",
|
|
96
|
-
suggestion: "The request body was empty. Ensure the webhook is sending data and your framework is parsing it correctly."
|
|
97
|
-
},
|
|
98
|
-
JSON_PARSE_FAILED: {
|
|
99
|
-
message: "Failed to parse JSON body",
|
|
100
|
-
suggestion: "The request body is not valid JSON. Check the raw body content and Content-Type header."
|
|
101
|
-
},
|
|
102
|
-
INVALID_ENCODING: {
|
|
103
|
-
message: "Invalid body encoding",
|
|
104
|
-
suggestion: "The request body encoding is not supported. MyMX webhooks use UTF-8 encoded JSON."
|
|
105
|
-
}
|
|
106
|
-
};
|
|
107
|
-
/**
|
|
108
|
-
* Raw email decode error definitions.
|
|
109
|
-
* Use these for documentation, dashboards, and i18n.
|
|
110
|
-
*/
|
|
111
|
-
const RAW_EMAIL_ERRORS = {
|
|
112
|
-
NOT_INCLUDED: {
|
|
113
|
-
message: "Raw email content not included inline",
|
|
114
|
-
suggestion: "Use the download URL at event.email.content.download.url to fetch the raw email."
|
|
115
|
-
},
|
|
116
|
-
HASH_MISMATCH: {
|
|
117
|
-
message: "SHA-256 hash verification failed",
|
|
118
|
-
suggestion: "The raw email data may be corrupted. Try downloading from the URL instead."
|
|
119
|
-
}
|
|
120
|
-
};
|
|
121
|
-
/**
|
|
122
|
-
* Base class for all MyMX webhook errors.
|
|
123
|
-
*
|
|
124
|
-
* Catch this to handle any error from the SDK in a single catch block.
|
|
125
|
-
*
|
|
126
|
-
* @example
|
|
127
|
-
* ```typescript
|
|
128
|
-
* import { handleWebhook, MyMXWebhookError } from 'mymx';
|
|
129
|
-
*
|
|
130
|
-
* try {
|
|
131
|
-
* const event = handleWebhook({ body, signature, secret });
|
|
132
|
-
* } catch (err) {
|
|
133
|
-
* if (err instanceof MyMXWebhookError) {
|
|
134
|
-
* console.error(`[${err.code}] ${err.message}`);
|
|
135
|
-
* return res.status(400).json({ error: err.code });
|
|
136
|
-
* }
|
|
137
|
-
* throw err;
|
|
138
|
-
* }
|
|
139
|
-
* ```
|
|
140
|
-
*/
|
|
141
|
-
var MyMXWebhookError = class extends Error {
|
|
142
|
-
/**
|
|
143
|
-
* Formats the error for logging/display.
|
|
144
|
-
*/
|
|
145
|
-
toString() {
|
|
146
|
-
return `${this.name} [${this.code}]: ${this.message}\n\nSuggestion: ${this.suggestion}`;
|
|
147
|
-
}
|
|
148
|
-
/**
|
|
149
|
-
* Serializes cleanly for structured logging (Datadog, CloudWatch, etc.)
|
|
150
|
-
*/
|
|
151
|
-
toJSON() {
|
|
152
|
-
return {
|
|
153
|
-
name: this.name,
|
|
154
|
-
code: this.code,
|
|
155
|
-
message: this.message,
|
|
156
|
-
suggestion: this.suggestion
|
|
157
|
-
};
|
|
158
|
-
}
|
|
159
|
-
};
|
|
160
|
-
/**
|
|
161
|
-
* Error thrown when webhook signature verification fails.
|
|
162
|
-
*
|
|
163
|
-
* Use the `code` property to programmatically handle specific error cases.
|
|
164
|
-
*/
|
|
165
|
-
var WebhookVerificationError = class extends MyMXWebhookError {
|
|
166
|
-
code;
|
|
167
|
-
suggestion;
|
|
168
|
-
constructor(code, message, suggestion) {
|
|
169
|
-
super(message ?? VERIFICATION_ERRORS[code].message);
|
|
170
|
-
this.name = "WebhookVerificationError";
|
|
171
|
-
this.code = code;
|
|
172
|
-
this.suggestion = suggestion ?? VERIFICATION_ERRORS[code].suggestion;
|
|
173
|
-
}
|
|
174
|
-
};
|
|
175
|
-
/**
|
|
176
|
-
* Error thrown when webhook payload parsing fails (lightweight parser).
|
|
177
|
-
*
|
|
178
|
-
* Use the `code` property for programmatic handling and monitoring.
|
|
179
|
-
* The `suggestion` property contains actionable guidance for fixing the issue.
|
|
180
|
-
*/
|
|
181
|
-
var WebhookPayloadError = class extends MyMXWebhookError {
|
|
182
|
-
code;
|
|
183
|
-
suggestion;
|
|
184
|
-
/** Original error if this wraps another error (e.g., JSON.parse failure) */
|
|
185
|
-
cause;
|
|
186
|
-
constructor(code, message, suggestion, cause) {
|
|
187
|
-
super(message ?? PAYLOAD_ERRORS[code].message);
|
|
188
|
-
this.name = "WebhookPayloadError";
|
|
189
|
-
this.code = code;
|
|
190
|
-
this.suggestion = suggestion ?? PAYLOAD_ERRORS[code].suggestion;
|
|
191
|
-
this.cause = cause;
|
|
192
|
-
}
|
|
193
|
-
};
|
|
194
|
-
/**
|
|
195
|
-
* Error thrown when Zod schema validation fails.
|
|
196
|
-
*
|
|
197
|
-
* Wraps ZodError with human-friendly messages and actionable suggestions.
|
|
198
|
-
*/
|
|
199
|
-
var WebhookValidationError = class extends MyMXWebhookError {
|
|
200
|
-
code = "SCHEMA_VALIDATION_FAILED";
|
|
201
|
-
suggestion;
|
|
202
|
-
/** The specific field path that failed (e.g., "email.headers.from") */
|
|
203
|
-
field;
|
|
204
|
-
/** Original Zod error for advanced debugging */
|
|
205
|
-
zodError;
|
|
206
|
-
/** Number of additional validation errors beyond the first */
|
|
207
|
-
additionalErrorCount;
|
|
208
|
-
constructor(field, message, suggestion, zodError) {
|
|
209
|
-
super(message);
|
|
210
|
-
this.name = "WebhookValidationError";
|
|
211
|
-
this.field = field;
|
|
212
|
-
this.suggestion = suggestion;
|
|
213
|
-
this.zodError = zodError;
|
|
214
|
-
this.additionalErrorCount = Math.max(0, zodError.issues.length - 1);
|
|
215
|
-
}
|
|
216
|
-
/**
|
|
217
|
-
* Formats the error for logging/display.
|
|
218
|
-
* Includes error count and suggestion.
|
|
219
|
-
*/
|
|
220
|
-
toString() {
|
|
221
|
-
let output = `${this.name} [${this.code}]: ${this.message}`;
|
|
222
|
-
if (this.additionalErrorCount > 0) output += ` (and ${this.additionalErrorCount} more validation error${this.additionalErrorCount > 1 ? "s" : ""})`;
|
|
223
|
-
output += `\n\nSuggestion: ${this.suggestion}`;
|
|
224
|
-
return output;
|
|
225
|
-
}
|
|
226
|
-
/**
|
|
227
|
-
* Serializes cleanly for structured logging (Datadog, CloudWatch, etc.)
|
|
228
|
-
*/
|
|
229
|
-
toJSON() {
|
|
230
|
-
return {
|
|
231
|
-
name: this.name,
|
|
232
|
-
code: this.code,
|
|
233
|
-
field: this.field,
|
|
234
|
-
message: this.message,
|
|
235
|
-
suggestion: this.suggestion,
|
|
236
|
-
additionalErrorCount: this.additionalErrorCount
|
|
237
|
-
};
|
|
238
|
-
}
|
|
239
|
-
};
|
|
240
|
-
/**
|
|
241
|
-
* Error thrown when raw email decoding or verification fails.
|
|
242
|
-
*
|
|
243
|
-
* Use the `code` property to determine the failure reason:
|
|
244
|
-
* - `NOT_INCLUDED`: Raw email not inline, must download from URL
|
|
245
|
-
* - `HASH_MISMATCH`: SHA-256 verification failed, content may be corrupted
|
|
246
|
-
*/
|
|
247
|
-
var RawEmailDecodeError = class extends MyMXWebhookError {
|
|
248
|
-
code;
|
|
249
|
-
suggestion;
|
|
250
|
-
constructor(code, message) {
|
|
251
|
-
super(message ?? RAW_EMAIL_ERRORS[code].message);
|
|
252
|
-
this.name = "RawEmailDecodeError";
|
|
253
|
-
this.code = code;
|
|
254
|
-
this.suggestion = RAW_EMAIL_ERRORS[code].suggestion;
|
|
255
|
-
}
|
|
256
|
-
};
|
|
257
|
-
|
|
258
|
-
//#endregion
|
|
259
|
-
Object.defineProperty(exports, 'MyMXWebhookError', {
|
|
260
|
-
enumerable: true,
|
|
261
|
-
get: function () {
|
|
262
|
-
return MyMXWebhookError;
|
|
263
|
-
}
|
|
264
|
-
});
|
|
265
|
-
Object.defineProperty(exports, 'PAYLOAD_ERRORS', {
|
|
266
|
-
enumerable: true,
|
|
267
|
-
get: function () {
|
|
268
|
-
return PAYLOAD_ERRORS;
|
|
269
|
-
}
|
|
270
|
-
});
|
|
271
|
-
Object.defineProperty(exports, 'RAW_EMAIL_ERRORS', {
|
|
272
|
-
enumerable: true,
|
|
273
|
-
get: function () {
|
|
274
|
-
return RAW_EMAIL_ERRORS;
|
|
275
|
-
}
|
|
276
|
-
});
|
|
277
|
-
Object.defineProperty(exports, 'RawEmailDecodeError', {
|
|
278
|
-
enumerable: true,
|
|
279
|
-
get: function () {
|
|
280
|
-
return RawEmailDecodeError;
|
|
281
|
-
}
|
|
282
|
-
});
|
|
283
|
-
Object.defineProperty(exports, 'VERIFICATION_ERRORS', {
|
|
284
|
-
enumerable: true,
|
|
285
|
-
get: function () {
|
|
286
|
-
return VERIFICATION_ERRORS;
|
|
287
|
-
}
|
|
288
|
-
});
|
|
289
|
-
Object.defineProperty(exports, 'WEBHOOK_VERSION', {
|
|
290
|
-
enumerable: true,
|
|
291
|
-
get: function () {
|
|
292
|
-
return WEBHOOK_VERSION;
|
|
293
|
-
}
|
|
294
|
-
});
|
|
295
|
-
Object.defineProperty(exports, 'WebhookPayloadError', {
|
|
296
|
-
enumerable: true,
|
|
297
|
-
get: function () {
|
|
298
|
-
return WebhookPayloadError;
|
|
299
|
-
}
|
|
300
|
-
});
|
|
301
|
-
Object.defineProperty(exports, 'WebhookValidationError', {
|
|
302
|
-
enumerable: true,
|
|
303
|
-
get: function () {
|
|
304
|
-
return WebhookValidationError;
|
|
305
|
-
}
|
|
306
|
-
});
|
|
307
|
-
Object.defineProperty(exports, 'WebhookVerificationError', {
|
|
308
|
-
enumerable: true,
|
|
309
|
-
get: function () {
|
|
310
|
-
return WebhookVerificationError;
|
|
311
|
-
}
|
|
312
|
-
});
|
|
313
|
-
Object.defineProperty(exports, '__toESM', {
|
|
314
|
-
enumerable: true,
|
|
315
|
-
get: function () {
|
|
316
|
-
return __toESM;
|
|
317
|
-
}
|
|
318
|
-
});
|