posthog-node 5.71.0 → 5.73.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.
- package/dist/client.d.ts +53 -7
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +94 -19
- package/dist/client.mjs +94 -19
- package/dist/emails/attachments.d.ts +23 -0
- package/dist/emails/attachments.d.ts.map +1 -0
- package/dist/emails/attachments.js +170 -0
- package/dist/emails/attachments.mjs +123 -0
- package/dist/emails/emails.d.ts +7 -2
- package/dist/emails/emails.d.ts.map +1 -1
- package/dist/emails/emails.js +193 -37
- package/dist/emails/emails.mjs +193 -37
- package/dist/emails/errors.d.ts +1 -1
- package/dist/emails/errors.d.ts.map +1 -1
- package/dist/emails/errors.js +6 -1
- package/dist/emails/errors.mjs +6 -1
- package/dist/emails/types.d.ts +23 -0
- package/dist/emails/types.d.ts.map +1 -1
- package/dist/exports.d.ts +1 -1
- package/dist/exports.d.ts.map +1 -1
- package/dist/feature-flag-evaluations.d.ts +14 -0
- package/dist/feature-flag-evaluations.d.ts.map +1 -1
- package/dist/feature-flag-evaluations.js +2 -1
- package/dist/feature-flag-evaluations.mjs +2 -1
- package/dist/flag-events.d.ts +112 -0
- package/dist/flag-events.d.ts.map +1 -0
- package/dist/flag-events.js +230 -0
- package/dist/flag-events.mjs +174 -0
- package/dist/flags-response.d.ts +83 -0
- package/dist/flags-response.d.ts.map +1 -0
- package/dist/flags-response.js +255 -0
- package/dist/flags-response.mjs +208 -0
- package/dist/types.d.ts +2 -1
- package/dist/types.d.ts.map +1 -1
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/dist/version.mjs +1 -1
- package/package.json +4 -3
- package/src/client.ts +238 -45
- package/src/emails/attachments.ts +209 -0
- package/src/emails/emails.ts +243 -35
- package/src/emails/errors.ts +7 -2
- package/src/emails/types.ts +24 -0
- package/src/exports.ts +1 -0
- package/src/feature-flag-evaluations.ts +17 -0
- package/src/flag-events.ts +280 -0
- package/src/flags-response.ts +340 -0
- package/src/types.ts +2 -1
- package/src/version.ts +1 -1
package/dist/emails/emails.mjs
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import { parseRetryAfterMs, removeTrailingSlash, safeJsonStringify } from "@posthog/core";
|
|
2
|
+
import { attachmentFiles, attachmentReference, hashedFiles, refuseRenderedMessageOverLimit } from "./attachments.mjs";
|
|
2
3
|
import { EmailError } from "./errors.mjs";
|
|
3
4
|
const SEND_PATH = '/api/projects/@current/messaging/send/email/';
|
|
5
|
+
const UPLOADS_PATH = '/api/projects/@current/messaging/attachments/uploads/';
|
|
4
6
|
const STATUS_PATH = '/api/projects/@current/messaging/emails/{messageId}/';
|
|
5
7
|
const PREFERENCES_PATH = '/api/projects/@current/messaging/preferences/';
|
|
6
8
|
const US_APP_HOST = 'https://us.posthog.com';
|
|
@@ -32,6 +34,9 @@ const CODE_FIELDS = {
|
|
|
32
34
|
from: true,
|
|
33
35
|
replyTo: true,
|
|
34
36
|
captureEngagement: true,
|
|
37
|
+
cc: true,
|
|
38
|
+
bcc: true,
|
|
39
|
+
attachments: true,
|
|
35
40
|
sensitive: true,
|
|
36
41
|
tracking: true,
|
|
37
42
|
html: true,
|
|
@@ -80,7 +85,13 @@ class EmailSender {
|
|
|
80
85
|
refuseSecondArgument(unexpected);
|
|
81
86
|
const prepared = prepareSend(options, this.config.maxRetries);
|
|
82
87
|
const { appHost, secretKey } = this.connect('no email was sent', 'Sending email needs secretKey, a project secret API key with the transactional_email:write scope.');
|
|
83
|
-
const
|
|
88
|
+
const content = void 0 === prepared.react ? prepared.content : await withRenderedReact(prepared.content, prepared.react, this.config.requestTimeoutMs);
|
|
89
|
+
if (void 0 !== prepared.react) refuseRenderedMessageOverLimit(prepared.files, content);
|
|
90
|
+
const attachments = await this.uploadAttachments(prepared, appHost, secretKey);
|
|
91
|
+
const body = safeJsonStringify({
|
|
92
|
+
...content,
|
|
93
|
+
...unlessEmpty('attachments', attachments)
|
|
94
|
+
});
|
|
84
95
|
const headers = this.headers(secretKey, {
|
|
85
96
|
'Content-Type': 'application/json',
|
|
86
97
|
'Idempotency-Key': prepared.idempotencyKey
|
|
@@ -116,6 +127,69 @@ class EmailSender {
|
|
|
116
127
|
};
|
|
117
128
|
}
|
|
118
129
|
}
|
|
130
|
+
async uploadAttachments({ files, maxRetries }, appHost, secretKey) {
|
|
131
|
+
if (0 === files.length) return [];
|
|
132
|
+
const hashed = await hashedFiles(files);
|
|
133
|
+
const distinct = new Map();
|
|
134
|
+
for (const file of hashed)if (!distinct.has(file.sha256)) distinct.set(file.sha256, file);
|
|
135
|
+
const requested = [
|
|
136
|
+
...distinct.values()
|
|
137
|
+
];
|
|
138
|
+
const body = safeJsonStringify({
|
|
139
|
+
files: requested.map(({ sha256, bytes })=>({
|
|
140
|
+
sha256,
|
|
141
|
+
size: bytes.byteLength
|
|
142
|
+
}))
|
|
143
|
+
});
|
|
144
|
+
const headers = this.headers(secretKey, {
|
|
145
|
+
'Content-Type': 'application/json'
|
|
146
|
+
});
|
|
147
|
+
const uploads = await this.withRetries(maxRetries, async ()=>parseUploadsReply(await this.request(appHost + UPLOADS_PATH, 'POST', headers, body), requested));
|
|
148
|
+
const unencrypted = isPlainHttp(appHost) ? void 0 : uploads.find(({ url })=>!isHttps(url));
|
|
149
|
+
if (unencrypted) throw new EmailError({
|
|
150
|
+
code: 'api_error',
|
|
151
|
+
message: `PostHog named an upload URL for ${unencrypted.field} that isn't https, so the file would travel unencrypted. No email was sent.`,
|
|
152
|
+
field: unencrypted.field,
|
|
153
|
+
fix: "Make your PostHog's file storage URL use https. For local development over plain HTTP, set appHost to your http app host."
|
|
154
|
+
});
|
|
155
|
+
for (const upload of uploads)await this.withRetries(maxRetries, ()=>this.uploadFile(upload));
|
|
156
|
+
return hashed.map(attachmentReference);
|
|
157
|
+
}
|
|
158
|
+
async uploadFile({ url, headers, bytes, field }) {
|
|
159
|
+
let reply;
|
|
160
|
+
try {
|
|
161
|
+
reply = await this.request(url, 'PUT', headers, bytes, 'manual');
|
|
162
|
+
} catch (cause) {
|
|
163
|
+
if (cause instanceof Error && 'AbortError' === cause.name) throw new EmailError({
|
|
164
|
+
code: 'network_error',
|
|
165
|
+
message: `The upload of ${field} timed out after ${this.config.requestTimeoutMs}ms, so no email was sent.`,
|
|
166
|
+
fix: 'Raise emailRequestTimeoutMs on the client, or send smaller files.',
|
|
167
|
+
field,
|
|
168
|
+
cause
|
|
169
|
+
});
|
|
170
|
+
throw new EmailError({
|
|
171
|
+
code: 'network_error',
|
|
172
|
+
message: `The upload of ${field} didn't reach PostHog's file storage, so no email was sent.`,
|
|
173
|
+
field,
|
|
174
|
+
cause
|
|
175
|
+
});
|
|
176
|
+
}
|
|
177
|
+
if (reply.status >= 300 && reply.status < 400) throw new EmailError({
|
|
178
|
+
code: 'attachment_upload_failed',
|
|
179
|
+
message: `PostHog's file storage redirected the upload of ${field} elsewhere. The SDK uploads only to the URL PostHog signed, so no email was sent.`,
|
|
180
|
+
statusCode: reply.status,
|
|
181
|
+
fix: "Make your PostHog's file storage URL point straight at the storage, over https.",
|
|
182
|
+
field
|
|
183
|
+
});
|
|
184
|
+
if (reply.status < 200 || reply.status >= 300) throw new EmailError({
|
|
185
|
+
code: 'attachment_upload_failed',
|
|
186
|
+
message: `PostHog's file storage refused the upload of ${field}, so no email was sent. ${storageAnswer(reply)}`,
|
|
187
|
+
statusCode: reply.status,
|
|
188
|
+
fix: 'Send the email again. Each send asks for new upload URLs.',
|
|
189
|
+
field,
|
|
190
|
+
retryAfterMs: reply.retryAfterMs
|
|
191
|
+
});
|
|
192
|
+
}
|
|
119
193
|
async setPreferencesUntracked(options) {
|
|
120
194
|
try {
|
|
121
195
|
const body = preparePreferences(options);
|
|
@@ -186,7 +260,7 @@ class EmailSender {
|
|
|
186
260
|
await new Promise((resolve)=>setTimeout(resolve, delayMs));
|
|
187
261
|
}
|
|
188
262
|
}
|
|
189
|
-
async request(url, method, headers, body) {
|
|
263
|
+
async request(url, method, headers, body, redirect) {
|
|
190
264
|
const controller = new AbortController();
|
|
191
265
|
const timeoutMs = this.config.requestTimeoutMs;
|
|
192
266
|
let timer;
|
|
@@ -204,6 +278,9 @@ class EmailSender {
|
|
|
204
278
|
...void 0 === body ? {} : {
|
|
205
279
|
body
|
|
206
280
|
},
|
|
281
|
+
...redirect ? {
|
|
282
|
+
redirect
|
|
283
|
+
} : {},
|
|
207
284
|
signal: controller.signal
|
|
208
285
|
}));
|
|
209
286
|
fetchPromise.then((lateResponse)=>{
|
|
@@ -225,13 +302,13 @@ class EmailSender {
|
|
|
225
302
|
if (response.status >= 200 && response.status < 300) throw error;
|
|
226
303
|
return {
|
|
227
304
|
status: response.status,
|
|
228
|
-
|
|
305
|
+
text: '',
|
|
229
306
|
retryAfterMs: readRetryAfter(response)
|
|
230
307
|
};
|
|
231
308
|
}
|
|
232
309
|
return {
|
|
233
310
|
status: response.status,
|
|
234
|
-
|
|
311
|
+
text,
|
|
235
312
|
retryAfterMs: readRetryAfter(response)
|
|
236
313
|
};
|
|
237
314
|
} finally{
|
|
@@ -251,19 +328,23 @@ function prepareSend(options, defaultMaxRetries) {
|
|
|
251
328
|
const { to, distinctId, idempotencyKey, maxRetries } = send;
|
|
252
329
|
if ('string' != typeof to || !to.trim()) throw invalid('invalid_recipient', 'to must be one email address as a nonempty string.', 'to');
|
|
253
330
|
if (void 0 !== distinctId && ('string' != typeof distinctId || !distinctId)) throw invalid('invalid_distinct_id', 'distinctId must be a nonempty string.', 'distinctId');
|
|
254
|
-
const content = contentOf(send, distinctId);
|
|
331
|
+
const { content, files } = contentOf(send, distinctId);
|
|
255
332
|
if (void 0 !== idempotencyKey && ('string' != typeof idempotencyKey || !IDEMPOTENCY_KEY_PATTERN.test(idempotencyKey))) throw invalid('invalid_idempotency_key', 'idempotencyKey must be 1 to 255 visible ASCII characters without spaces.', 'idempotencyKey');
|
|
256
333
|
if (void 0 !== maxRetries && !isRetryCount(maxRetries)) throw invalid('invalid_max_retries', 'maxRetries must be a nonnegative integer.', 'maxRetries');
|
|
257
334
|
return {
|
|
258
|
-
|
|
335
|
+
content: snapshotOf({
|
|
259
336
|
...content,
|
|
260
337
|
to
|
|
261
338
|
}),
|
|
339
|
+
files,
|
|
262
340
|
react: isReactElement(send.react) ? send.react : void 0,
|
|
263
341
|
idempotencyKey: idempotencyKey ?? globalThis.crypto.randomUUID(),
|
|
264
342
|
maxRetries: isRetryCount(maxRetries) ? maxRetries : defaultMaxRetries
|
|
265
343
|
};
|
|
266
344
|
}
|
|
345
|
+
function snapshotOf(content) {
|
|
346
|
+
return JSON.parse(safeJsonStringify(content));
|
|
347
|
+
}
|
|
267
348
|
function preparePreferences(options) {
|
|
268
349
|
const fallback = {};
|
|
269
350
|
const { to, allMarketing, topics } = options ?? fallback;
|
|
@@ -290,7 +371,10 @@ function contentOf(send, distinctId) {
|
|
|
290
371
|
code: 'invalid_form',
|
|
291
372
|
message: 'Send either templateId, or templateKey with subject and html, text or react.'
|
|
292
373
|
});
|
|
293
|
-
return void 0 === send.templateKey ?
|
|
374
|
+
return void 0 === send.templateKey ? {
|
|
375
|
+
content: templateContent(send, distinctId),
|
|
376
|
+
files: []
|
|
377
|
+
} : codeContent(send, distinctId);
|
|
294
378
|
}
|
|
295
379
|
function templateContent(send, distinctId) {
|
|
296
380
|
const { templateId, templateData } = send;
|
|
@@ -306,7 +390,7 @@ function templateContent(send, distinctId) {
|
|
|
306
390
|
};
|
|
307
391
|
}
|
|
308
392
|
function codeContent(send, distinctId) {
|
|
309
|
-
const { templateKey, subject, html, text, react
|
|
393
|
+
const { templateKey, subject, html, text, react } = send;
|
|
310
394
|
if ('string' != typeof templateKey || !TEMPLATE_KEY_PATTERN.test(templateKey)) throw invalid('invalid_template_key', 'templateKey can only have letters, digits, hyphens (-) and underscores (_), at most 400.', 'templateKey');
|
|
311
395
|
refuseFieldsOutside(send, CODE_FORM, TEMPLATE_FORM);
|
|
312
396
|
if ('string' != typeof subject) throw invalid('invalid_form', 'A send with templateKey needs a subject.', 'subject');
|
|
@@ -314,24 +398,38 @@ function codeContent(send, distinctId) {
|
|
|
314
398
|
if (void 0 !== text && 'string' != typeof text) throw invalid('invalid_form', 'text must be a string.', 'text');
|
|
315
399
|
if (void 0 !== react) checkReactContent(react, html);
|
|
316
400
|
else if (void 0 === html && void 0 === text) throw invalid('invalid_form', 'A send with templateKey needs html, text or react.', 'html');
|
|
317
|
-
const
|
|
401
|
+
const files = void 0 === send.attachments ? [] : attachmentFiles(send.attachments, {
|
|
402
|
+
html,
|
|
403
|
+
text,
|
|
404
|
+
subject
|
|
405
|
+
});
|
|
318
406
|
return {
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
html
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
text
|
|
407
|
+
content: {
|
|
408
|
+
template_key: templateKey,
|
|
409
|
+
subject,
|
|
410
|
+
...void 0 !== html && {
|
|
411
|
+
html
|
|
412
|
+
},
|
|
413
|
+
...void 0 !== text && {
|
|
414
|
+
text
|
|
415
|
+
},
|
|
416
|
+
...codeFormFields(send),
|
|
417
|
+
...void 0 !== distinctId && {
|
|
418
|
+
distinct_id: distinctId
|
|
419
|
+
}
|
|
326
420
|
},
|
|
421
|
+
files
|
|
422
|
+
};
|
|
423
|
+
}
|
|
424
|
+
function codeFormFields(send) {
|
|
425
|
+
const { from, replyTo, cc, bcc, captureEngagement, sensitive, tracking } = send;
|
|
426
|
+
return {
|
|
327
427
|
...void 0 !== from && {
|
|
328
428
|
from
|
|
329
429
|
},
|
|
330
|
-
...
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
] : replyTo
|
|
334
|
-
},
|
|
430
|
+
...void 0 !== replyTo && unlessEmpty('reply_to', addressList(replyTo)),
|
|
431
|
+
...void 0 !== cc && unlessEmpty('cc', addressList(cc)),
|
|
432
|
+
...void 0 !== bcc && unlessEmpty('bcc', addressList(bcc)),
|
|
335
433
|
...void 0 !== captureEngagement && {
|
|
336
434
|
capture_engagement: captureEngagement
|
|
337
435
|
},
|
|
@@ -340,12 +438,19 @@ function codeContent(send, distinctId) {
|
|
|
340
438
|
},
|
|
341
439
|
...void 0 !== tracking && {
|
|
342
440
|
tracking
|
|
343
|
-
},
|
|
344
|
-
...void 0 !== distinctId && {
|
|
345
|
-
distinct_id: distinctId
|
|
346
441
|
}
|
|
347
442
|
};
|
|
348
443
|
}
|
|
444
|
+
function unlessEmpty(field, list) {
|
|
445
|
+
return Array.isArray(list) && 0 === list.length ? {} : {
|
|
446
|
+
[field]: list
|
|
447
|
+
};
|
|
448
|
+
}
|
|
449
|
+
function addressList(addresses) {
|
|
450
|
+
return 'string' == typeof addresses ? [
|
|
451
|
+
addresses
|
|
452
|
+
] : addresses;
|
|
453
|
+
}
|
|
349
454
|
function checkReactContent(react, html) {
|
|
350
455
|
if (!isReactElement(react)) throw invalid('invalid_form', 'react must be a React element, such as <WelcomeEmail />.', 'react');
|
|
351
456
|
if (void 0 !== html) throw new EmailError({
|
|
@@ -362,18 +467,17 @@ const REACT_18_AND_19_ELEMENT_MARKERS = [
|
|
|
362
467
|
function isReactElement(value) {
|
|
363
468
|
return 'object' == typeof value && null !== value && '$$typeof' in value && REACT_18_AND_19_ELEMENT_MARKERS.includes(value.$$typeof) && 'type' in value && 'props' in value;
|
|
364
469
|
}
|
|
365
|
-
async function withRenderedReact(
|
|
470
|
+
async function withRenderedReact(content, react, timeoutMs) {
|
|
366
471
|
const { render, toPlainText } = await loadReactRenderer();
|
|
367
|
-
const fields = JSON.parse(body);
|
|
368
472
|
try {
|
|
369
473
|
const html = await settleWithin(render(react), timeoutMs, 'Rendering the react element');
|
|
370
|
-
return
|
|
371
|
-
...
|
|
474
|
+
return {
|
|
475
|
+
...content,
|
|
372
476
|
html,
|
|
373
|
-
...void 0 ===
|
|
477
|
+
...void 0 === content.text && {
|
|
374
478
|
text: toPlainText(html)
|
|
375
479
|
}
|
|
376
|
-
}
|
|
480
|
+
};
|
|
377
481
|
} catch (cause) {
|
|
378
482
|
throw new EmailError({
|
|
379
483
|
code: 'react_render_failed',
|
|
@@ -436,6 +540,12 @@ function invalid(code, message, field) {
|
|
|
436
540
|
field
|
|
437
541
|
});
|
|
438
542
|
}
|
|
543
|
+
function isHttps(url) {
|
|
544
|
+
return url.toLowerCase().startsWith('https://');
|
|
545
|
+
}
|
|
546
|
+
function isPlainHttp(url) {
|
|
547
|
+
return url.toLowerCase().startsWith('http://');
|
|
548
|
+
}
|
|
439
549
|
function resolveAppHost(host, appHost) {
|
|
440
550
|
const explicit = 'string' == typeof appHost ? removeTrailingSlash(appHost.trim()) : '';
|
|
441
551
|
if (explicit) return CLOUD_APP_HOSTS[explicit] ?? explicit;
|
|
@@ -461,8 +571,8 @@ function emails_text(value) {
|
|
|
461
571
|
function replyFields(payload) {
|
|
462
572
|
return null === payload || 'object' != typeof payload || Array.isArray(payload) ? {} : payload;
|
|
463
573
|
}
|
|
464
|
-
function parseSendReply({ status,
|
|
465
|
-
const fields = replyFields(
|
|
574
|
+
function parseSendReply({ status, text: body, retryAfterMs }) {
|
|
575
|
+
const fields = replyFields(parseJson(body));
|
|
466
576
|
if (status >= 200 && status < 300) {
|
|
467
577
|
const id = emails_text(fields.message_id);
|
|
468
578
|
if (!id) throw new EmailError({
|
|
@@ -486,8 +596,8 @@ function parseSendReply({ status, payload, retryAfterMs }) {
|
|
|
486
596
|
}
|
|
487
597
|
throw replyError(fields, status, retryAfterMs);
|
|
488
598
|
}
|
|
489
|
-
function parseStatusReply({ status,
|
|
490
|
-
const fields = replyFields(
|
|
599
|
+
function parseStatusReply({ status, text: body, retryAfterMs }) {
|
|
600
|
+
const fields = replyFields(parseJson(body));
|
|
491
601
|
if (status < 200 || status >= 300) throw replyError(fields, status, retryAfterMs);
|
|
492
602
|
const id = emails_text(fields.id);
|
|
493
603
|
const deliveryStatus = emails_text(fields.status);
|
|
@@ -506,8 +616,53 @@ function parseStatusReply({ status, payload, retryAfterMs }) {
|
|
|
506
616
|
reason: emails_text(fields.reason) ?? null
|
|
507
617
|
};
|
|
508
618
|
}
|
|
509
|
-
function
|
|
510
|
-
const fields = replyFields(
|
|
619
|
+
function parseUploadsReply({ status, text: body, retryAfterMs }, requested) {
|
|
620
|
+
const fields = replyFields(parseJson(body));
|
|
621
|
+
if (404 === status) throw replyError({
|
|
622
|
+
code: 'not_found',
|
|
623
|
+
...fields,
|
|
624
|
+
attr: emails_text(fields.attr) ?? 'attachments'
|
|
625
|
+
}, status, retryAfterMs);
|
|
626
|
+
if (status < 200 || status >= 300) throw replyError({
|
|
627
|
+
...fields,
|
|
628
|
+
attr: callerField(emails_text(fields.attr), requested)
|
|
629
|
+
}, status, retryAfterMs);
|
|
630
|
+
const answers = Array.isArray(fields.files) ? fields.files.map(replyFields) : [];
|
|
631
|
+
const uploads = [];
|
|
632
|
+
for (const { sha256, bytes, field } of requested){
|
|
633
|
+
const answer = answers.find((file)=>file.sha256 === sha256);
|
|
634
|
+
if (answer?.status === 'present') continue;
|
|
635
|
+
const url = emails_text(answer?.url);
|
|
636
|
+
if (answer?.status !== 'upload' || !url || !isStringRecord(answer.headers)) throw new EmailError({
|
|
637
|
+
code: 'api_error',
|
|
638
|
+
message: 'PostHog answered without telling where to upload every file.',
|
|
639
|
+
statusCode: status
|
|
640
|
+
});
|
|
641
|
+
uploads.push({
|
|
642
|
+
url,
|
|
643
|
+
headers: answer.headers,
|
|
644
|
+
bytes,
|
|
645
|
+
field
|
|
646
|
+
});
|
|
647
|
+
}
|
|
648
|
+
return uploads;
|
|
649
|
+
}
|
|
650
|
+
function callerField(attr, requested) {
|
|
651
|
+
const file = void 0 === attr ? null : /^files(?:__(\d+))?(?:__|$)/.exec(attr);
|
|
652
|
+
if (!file) return attr;
|
|
653
|
+
return void 0 === file[1] ? 'attachments' : requested[Number(file[1])]?.field ?? 'attachments';
|
|
654
|
+
}
|
|
655
|
+
function isStringRecord(value) {
|
|
656
|
+
return null !== value && 'object' == typeof value && !Array.isArray(value) && Object.values(value).every((item)=>'string' == typeof item);
|
|
657
|
+
}
|
|
658
|
+
function storageAnswer({ status, text: body }) {
|
|
659
|
+
const code = /<Code>([^<]{1,100})<\/Code>/.exec(body)?.[1];
|
|
660
|
+
const message = /<Message>([^<]{1,300})<\/Message>/.exec(body)?.[1];
|
|
661
|
+
const answer = `It answered HTTP ${status}${code ? ` ${code}` : ''}${message ? `: ${message}` : ''}`;
|
|
662
|
+
return answer.endsWith('.') ? answer : `${answer}.`;
|
|
663
|
+
}
|
|
664
|
+
function parsePreferencesReply({ status, text: body, retryAfterMs }) {
|
|
665
|
+
const fields = replyFields(parseJson(body));
|
|
511
666
|
if (status < 200 || status >= 300) throw replyError(fields, status, retryAfterMs);
|
|
512
667
|
const to = emails_text(fields.identifier);
|
|
513
668
|
const allMarketing = fields.all_marketing;
|
|
@@ -544,8 +699,9 @@ function asEmailError(error, message) {
|
|
|
544
699
|
}
|
|
545
700
|
function isRetryable(error) {
|
|
546
701
|
if (void 0 === error.statusCode) return 'network_error' === error.code;
|
|
702
|
+
if ('attachment_upload_failed' === error.code) return 429 === error.statusCode || error.statusCode >= 500;
|
|
547
703
|
if (409 === error.statusCode) return 'idempotency_key_in_flight' === error.code;
|
|
548
|
-
if (429 === error.statusCode) return 'quota_limited' !== error.code;
|
|
704
|
+
if (429 === error.statusCode) return 'quota_limited' !== error.code && 'upload_quota_exceeded' !== error.code;
|
|
549
705
|
return 503 === error.statusCode;
|
|
550
706
|
}
|
|
551
707
|
function retryDelayMs(error, attempt, maxRetries) {
|
package/dist/emails/errors.d.ts
CHANGED
|
@@ -23,7 +23,7 @@ export declare class EmailError extends Error {
|
|
|
23
23
|
name: EmailErrorName;
|
|
24
24
|
/** PostHog's error code, such as `quota_limited`, or an SDK code such as `network_error`. */
|
|
25
25
|
readonly code: string;
|
|
26
|
-
/** The HTTP status, when PostHog answered. */
|
|
26
|
+
/** The HTTP status, when PostHog or its file storage answered. */
|
|
27
27
|
readonly statusCode?: number;
|
|
28
28
|
readonly why?: string;
|
|
29
29
|
readonly fix?: string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../../src/emails/errors.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,MAAM,cAAc,GACtB,kBAAkB,GAClB,iBAAiB,GACjB,oBAAoB,GACpB,WAAW,GACX,gCAAgC,GAChC,4BAA4B,GAC5B,qBAAqB,GACrB,wBAAwB,GACxB,qBAAqB,GACrB,mBAAmB,CAAA;AAEvB,MAAM,WAAW,gBAAgB;IAC/B,IAAI,EAAE,MAAM,CAAA;IACZ,OAAO,EAAE,MAAM,CAAA;IACf,UAAU,CAAC,EAAE,MAAM,CAAA;IACnB,GAAG,CAAC,EAAE,MAAM,CAAA;IACZ,GAAG,CAAC,EAAE,MAAM,CAAA;IACZ,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,YAAY,CAAC,EAAE,MAAM,CAAA;IACrB,KAAK,CAAC,EAAE,OAAO,CAAA;CAChB;AAED;;;;;GAKG;AACH,qBAAa,UAAW,SAAQ,KAAK;IAC1B,IAAI,EAAE,cAAc,CAAA;IAC7B,6FAA6F;IAC7F,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAA;IACrB,
|
|
1
|
+
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../../src/emails/errors.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,MAAM,cAAc,GACtB,kBAAkB,GAClB,iBAAiB,GACjB,oBAAoB,GACpB,WAAW,GACX,gCAAgC,GAChC,4BAA4B,GAC5B,qBAAqB,GACrB,wBAAwB,GACxB,qBAAqB,GACrB,mBAAmB,CAAA;AAEvB,MAAM,WAAW,gBAAgB;IAC/B,IAAI,EAAE,MAAM,CAAA;IACZ,OAAO,EAAE,MAAM,CAAA;IACf,UAAU,CAAC,EAAE,MAAM,CAAA;IACnB,GAAG,CAAC,EAAE,MAAM,CAAA;IACZ,GAAG,CAAC,EAAE,MAAM,CAAA;IACZ,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,YAAY,CAAC,EAAE,MAAM,CAAA;IACrB,KAAK,CAAC,EAAE,OAAO,CAAA;CAChB;AAED;;;;;GAKG;AACH,qBAAa,UAAW,SAAQ,KAAK;IAC1B,IAAI,EAAE,cAAc,CAAA;IAC7B,6FAA6F;IAC7F,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAA;IACrB,kEAAkE;IAClE,QAAQ,CAAC,UAAU,CAAC,EAAE,MAAM,CAAA;IAC5B,QAAQ,CAAC,GAAG,CAAC,EAAE,MAAM,CAAA;IACrB,QAAQ,CAAC,GAAG,CAAC,EAAE,MAAM,CAAA;IACrB,QAAQ,CAAC,OAAO,CAAC,EAAE,MAAM,CAAA;IACzB,oEAAoE;IACpE,QAAQ,CAAC,KAAK,CAAC,EAAE,MAAM,CAAA;IACvB,wFAAwF;IACxF,QAAQ,CAAC,YAAY,CAAC,EAAE,MAAM,CAAA;IAE9B,YAAY,MAAM,EAAE,gBAAgB,EAUnC;CACF"}
|
package/dist/emails/errors.js
CHANGED
|
@@ -42,12 +42,17 @@ class EmailError extends Error {
|
|
|
42
42
|
this.retryAfterMs = params.retryAfterMs;
|
|
43
43
|
}
|
|
44
44
|
}
|
|
45
|
+
const ATTACHMENT_LIMIT_CODES = new Set([
|
|
46
|
+
'too_many_attachments',
|
|
47
|
+
'message_too_large'
|
|
48
|
+
]);
|
|
45
49
|
function emailErrorName(status, code) {
|
|
46
50
|
if ('missing_secret_key' === code || 401 === status) return 'missing_api_key';
|
|
47
51
|
if (void 0 === status) {
|
|
48
52
|
if ('network_error' === code) return 'service_unavailable';
|
|
49
|
-
return code.startsWith('invalid_') ? 'validation_error' : 'application_error';
|
|
53
|
+
return code.startsWith('invalid_') || ATTACHMENT_LIMIT_CODES.has(code) ? 'validation_error' : 'application_error';
|
|
50
54
|
}
|
|
55
|
+
if ('attachment_upload_failed' === code) return status >= 500 ? 'service_unavailable' : 'application_error';
|
|
51
56
|
switch(status){
|
|
52
57
|
case 400:
|
|
53
58
|
return 'validation_error';
|
package/dist/emails/errors.mjs
CHANGED
|
@@ -13,12 +13,17 @@ class EmailError extends Error {
|
|
|
13
13
|
this.retryAfterMs = params.retryAfterMs;
|
|
14
14
|
}
|
|
15
15
|
}
|
|
16
|
+
const ATTACHMENT_LIMIT_CODES = new Set([
|
|
17
|
+
'too_many_attachments',
|
|
18
|
+
'message_too_large'
|
|
19
|
+
]);
|
|
16
20
|
function emailErrorName(status, code) {
|
|
17
21
|
if ('missing_secret_key' === code || 401 === status) return 'missing_api_key';
|
|
18
22
|
if (void 0 === status) {
|
|
19
23
|
if ('network_error' === code) return 'service_unavailable';
|
|
20
|
-
return code.startsWith('invalid_') ? 'validation_error' : 'application_error';
|
|
24
|
+
return code.startsWith('invalid_') || ATTACHMENT_LIMIT_CODES.has(code) ? 'validation_error' : 'application_error';
|
|
21
25
|
}
|
|
26
|
+
if ('attachment_upload_failed' === code) return status >= 500 ? 'service_unavailable' : 'application_error';
|
|
22
27
|
switch(status){
|
|
23
28
|
case 400:
|
|
24
29
|
return 'validation_error';
|
package/dist/emails/types.d.ts
CHANGED
|
@@ -36,6 +36,16 @@ interface CodeEmailFields {
|
|
|
36
36
|
/** A verified sender, such as `'Acme <security@example.com>'`. Without it, the project's default sender. */
|
|
37
37
|
from?: string;
|
|
38
38
|
replyTo?: string | string[];
|
|
39
|
+
/** Bare addresses, such as `'finance@example.com'`, that get a copy. */
|
|
40
|
+
cc?: string | string[];
|
|
41
|
+
/** Bare addresses that get a copy the other recipients never see. */
|
|
42
|
+
bcc?: string | string[];
|
|
43
|
+
/**
|
|
44
|
+
* Files sent with the email: at most 10, and at most 40 MB for the whole email after Base64
|
|
45
|
+
* encoding, about 29 MB of files. The SDK checks both before any request. It uploads each file
|
|
46
|
+
* PostHog doesn't have yet, then sends the email. When an upload fails, it sends nothing.
|
|
47
|
+
*/
|
|
48
|
+
attachments?: EmailAttachment[];
|
|
39
49
|
/**
|
|
40
50
|
* Whether PostHog captures the email's engagement events (sent, delivered, opened, clicked,
|
|
41
51
|
* bounced) as events of the recipient. Defaults to `true`. A project whose admin turned
|
|
@@ -87,6 +97,19 @@ export interface EmailTracking {
|
|
|
87
97
|
*/
|
|
88
98
|
engagement?: boolean;
|
|
89
99
|
}
|
|
100
|
+
/** A file sent with the email. */
|
|
101
|
+
export interface EmailAttachment {
|
|
102
|
+
/** The name the recipient sees, such as `'invoice.pdf'`. */
|
|
103
|
+
filename: string;
|
|
104
|
+
/** The file's bytes, or its content already Base64 encoded. At least one byte. */
|
|
105
|
+
content: Uint8Array | string;
|
|
106
|
+
/** A MIME type, such as `'application/pdf'`. */
|
|
107
|
+
contentType?: string;
|
|
108
|
+
/** Shows the file inline where the HTML has `<img src="cid:...">` with this id. */
|
|
109
|
+
contentId?: string;
|
|
110
|
+
/** PostHog can't fetch a file from a path or URL: read the file and pass its `content`. */
|
|
111
|
+
path?: never;
|
|
112
|
+
}
|
|
90
113
|
/**
|
|
91
114
|
* A React element, such as `<WelcomeEmail firstName="Ada" />`. Typed by its shape, so
|
|
92
115
|
* posthog-node needs no React types.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/emails/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,UAAU,CAAA;AAE1C,gDAAgD;AAChD,MAAM,WAAW,aAAa;IAC5B,mCAAmC;IACnC,EAAE,EAAE,MAAM,CAAA;IACV;;;OAGG;IACH,UAAU,CAAC,EAAE,MAAM,CAAA;IACnB;;;;;;OAMG;IACH,cAAc,CAAC,EAAE,MAAM,CAAA;IACvB,4FAA4F;IAC5F,UAAU,CAAC,EAAE,MAAM,CAAA;CACpB;AAED,gEAAgE;AAChE,MAAM,WAAW,iBAAiB;IAChC,mEAAmE;IACnE,UAAU,EAAE,MAAM,CAAA;IAClB,0FAA0F;IAC1F,YA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,EAAE,IAAI,CAAC;IAAC,KAAK,EAAE,UAAU,CAAA;CAAE,CAAA;AAErG;;GAEG;AACH,MAAM,WAAW,0BAA0B;IACzC;;;OAGG;IACH,EAAE,EAAE,MAAM,CAAA;IACV,mHAAmH;IACnH,YAAY,CAAC,EAAE,OAAO,CAAA;IACtB;;;;;OAKG;IACH,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;CACjC;AAED,kDAAkD;AAClD,MAAM,WAAW,gBAAgB;IAC/B,EAAE,EAAE,MAAM,CAAA;IACV,2HAA2H;IAC3H,YAAY,EAAE,OAAO,GAAG,IAAI,CAAA;IAC5B,kGAAkG;IAClG,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;CAChC;AAED;;;GAGG;AACH,MAAM,MAAM,2BAA2B,GAAG;IAAE,IAAI,EAAE,gBAAgB,CAAC;IAAC,KAAK,EAAE,IAAI,CAAA;CAAE,GAAG;IAAE,IAAI,EAAE,IAAI,CAAC;IAAC,KAAK,EAAE,UAAU,CAAA;CAAE,CAAA;AAErH;;;;GAIG;AACH,MAAM,WAAW,MAAM;IACrB;;;;;;OAMG;IACH,IAAI,CAAC,OAAO,EAAE,gBAAgB,GAAG,OAAO,CAAC,iBAAiB,CAAC,CAAA;IAE3D;;;;;;OAMG;IACH,GAAG,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,gBAAgB,CAAC,CAAA;IAE1C;;;;;;;;;OASG;IACH,cAAc,CAAC,OAAO,EAAE,0BAA0B,GAAG,OAAO,CAAC,2BAA2B,CAAC,CAAA;CAC1F"}
|
package/dist/exports.d.ts
CHANGED
|
@@ -6,7 +6,7 @@ export { enrichCurrentSpan } from './extensions/context/listeners';
|
|
|
6
6
|
export { FeatureFlagEvaluations } from './feature-flag-evaluations';
|
|
7
7
|
export { EmailError } from './emails/errors';
|
|
8
8
|
export type { EmailErrorName } from './emails/errors';
|
|
9
|
-
export type { CodeEmailForm, EmailDeliveryStatus, EmailPreferences, EmailReactElement, Emails, EmailStatus, EmailTracking, EmailWarning, GetEmailResponse, SendCodeEmailOptions, SendEmailBase, SendEmailOptions, SendEmailResponse, SendEmailResult, SendTemplateEmailOptions, SetEmailPreferencesOptions, SetEmailPreferencesResponse, TemplateEmailForm, } from './emails/types';
|
|
9
|
+
export type { CodeEmailForm, EmailAttachment, EmailDeliveryStatus, EmailPreferences, EmailReactElement, Emails, EmailStatus, EmailTracking, EmailWarning, GetEmailResponse, SendCodeEmailOptions, SendEmailBase, SendEmailOptions, SendEmailResponse, SendEmailResult, SendTemplateEmailOptions, SetEmailPreferencesOptions, SetEmailPreferencesResponse, TemplateEmailForm, } from './emails/types';
|
|
10
10
|
export type { FlagDefinitionCacheData, FlagDefinitionCacheInput, FlagDefinitionCacheProvider, } from './extensions/feature-flags/cache';
|
|
11
11
|
export { FeatureFlagError } from '@posthog/core';
|
|
12
12
|
export type { FeatureFlagErrorType, UnresolvedFlagReason } from '@posthog/core';
|
package/dist/exports.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"exports.d.ts","sourceRoot":"","sources":["../src/exports.ts"],"names":[],"mappings":"AAAA,cAAc,iCAAiC,CAAA;AAC/C,cAAc,sBAAsB,CAAA;AACpC,cAAc,4BAA4B,CAAA;AAC1C,cAAc,SAAS,CAAA;AACvB,OAAO,EAAE,iBAAiB,EAAE,MAAM,gCAAgC,CAAA;AAElE,OAAO,EAAE,sBAAsB,EAAE,MAAM,4BAA4B,CAAA;AACnE,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAA;AAC5C,YAAY,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAA;AACrD,YAAY,EACV,aAAa,EACb,mBAAmB,EACnB,gBAAgB,EAChB,iBAAiB,EACjB,MAAM,EACN,WAAW,EACX,aAAa,EACb,YAAY,EACZ,gBAAgB,EAChB,oBAAoB,EACpB,aAAa,EACb,gBAAgB,EAChB,iBA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,EACX,aAAa,EACb,YAAY,EACZ,gBAAgB,EAChB,oBAAoB,EACpB,aAAa,EACb,gBAAgB,EAChB,iBAAiB,EACjB,eAAe,EACf,wBAAwB,EACxB,0BAA0B,EAC1B,2BAA2B,EAC3B,iBAAiB,GAClB,MAAM,gBAAgB,CAAA;AACvB,YAAY,EACV,uBAAuB,EACvB,wBAAwB,EACxB,2BAA2B,GAC5B,MAAM,kCAAkC,CAAA;AAIzC,OAAO,EAAE,gBAAgB,EAAE,MAAM,eAAe,CAAA;AAChD,YAAY,EAAE,oBAAoB,EAAE,oBAAoB,EAAE,MAAM,eAAe,CAAA;AAI/E,YAAY,EAAE,oBAAoB,EAAE,gBAAgB,EAAE,OAAO,EAAE,aAAa,EAAE,MAAM,eAAe,CAAA;AAInG,YAAY,EACV,IAAI,EACJ,cAAc,EACd,kBAAkB,EAClB,QAAQ,EACR,cAAc,EACd,aAAa,EACb,gBAAgB,EAChB,UAAU,EACV,gBAAgB,EAChB,YAAY,GACb,MAAM,eAAe,CAAA;AAKtB,OAAO,EACL,uBAAuB,EACvB,qBAAqB,EACrB,oBAAoB,EACpB,kBAAkB,EAClB,iBAAiB,EACjB,sBAAsB,EACtB,MAAM,GACP,MAAM,eAAe,CAAA;AACtB,YAAY,EAAE,WAAW,EAAE,kBAAkB,EAAE,MAAM,eAAe,CAAA"}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { FeatureFlagValue, JsonType, UnresolvedFlagReason } from '@posthog/core';
|
|
2
|
+
import type { ParsedFlagRecord } from './flags-response';
|
|
2
3
|
/**
|
|
3
4
|
* Internal per-flag record stored by a {@link FeatureFlagEvaluations} instance.
|
|
4
5
|
* Not part of the public API.
|
|
@@ -16,6 +17,12 @@ export type EvaluatedFlagRecord = {
|
|
|
16
17
|
locallyEvaluated: boolean;
|
|
17
18
|
/** Whether the flag is linked to an experiment; undefined when the server did not report it. */
|
|
18
19
|
hasExperiment: boolean | undefined;
|
|
20
|
+
/**
|
|
21
|
+
* The parsed `/flags` record of a remotely evaluated flag, with its typed value, failure
|
|
22
|
+
* state, reason and rule metadata, for the typed flag API and flag events. Absent for locally
|
|
23
|
+
* evaluated flags and flags with a value override.
|
|
24
|
+
*/
|
|
25
|
+
parsed?: ParsedFlagRecord;
|
|
19
26
|
};
|
|
20
27
|
/**
|
|
21
28
|
* Parameters passed to the host when a `$feature_flag_called` event should be captured.
|
|
@@ -29,6 +36,13 @@ export type FlagCalledEventParams = {
|
|
|
29
36
|
groups: Record<string, string | number> | undefined;
|
|
30
37
|
disableGeoip: boolean | undefined;
|
|
31
38
|
properties: Record<string, any>;
|
|
39
|
+
/**
|
|
40
|
+
* The parsed `/flags` record that supplied the read's value. Absent when the value came from
|
|
41
|
+
* local evaluation or an override, or the flag is missing. A config version 2 record adds its
|
|
42
|
+
* attribution to `$feature_flag_called`, and a complete experiment split also sends
|
|
43
|
+
* `$experiment_exposure`.
|
|
44
|
+
*/
|
|
45
|
+
record?: ParsedFlagRecord;
|
|
32
46
|
};
|
|
33
47
|
/**
|
|
34
48
|
* Thin interface the evaluations object uses to talk back to the PostHog client.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"feature-flag-evaluations.d.ts","sourceRoot":"","sources":["../src/feature-flag-evaluations.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,QAAQ,EAAE,oBAAoB,EAAE,MAAM,eAAe,CAAA;
|
|
1
|
+
{"version":3,"file":"feature-flag-evaluations.d.ts","sourceRoot":"","sources":["../src/feature-flag-evaluations.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,QAAQ,EAAE,oBAAoB,EAAE,MAAM,eAAe,CAAA;AAEhF,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,kBAAkB,CAAA;AAGxD;;;;;GAKG;AACH,MAAM,MAAM,mBAAmB,GAAG;IAChC,GAAG,EAAE,MAAM,CAAA;IACX,OAAO,EAAE,OAAO,CAAA;IAChB,OAAO,EA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