posthog-node 5.68.2 → 5.70.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 CHANGED
@@ -244,14 +244,15 @@ export declare abstract class PostHogBackendClient extends PostHogCoreStateless
244
244
  */
245
245
  get logger(): CaptureLogger;
246
246
  /**
247
- * The `posthog.emails` API: sends transactional email from PostHog email templates, and reads
248
- * the status of each email it sent.
249
- *
250
- * Needs `secretKey`, a project secret API key with the `transactional_email:write` scope (the
251
- * "Send transactional email" preset). A key with only `transactional_email:read` can read
252
- * statuses but not send. Keys made with `hog_flow:write` still work. Requests go to `appHost`,
253
- * or to the PostHog Cloud app host of `host`. `send` and `get` resolve to `{ data, error }` and
254
- * do not reject.
247
+ * The `posthog.emails` API: sends transactional email from PostHog email templates, reads
248
+ * the status of each email it sent, and sets a recipient's topic preferences.
249
+ *
250
+ * Needs `secretKey`, a project secret API key. `send` needs the `transactional_email:write` scope
251
+ * (the "Send transactional email" preset), and `get` needs `transactional_email:read` or
252
+ * `transactional_email:write`. `setPreferences` needs the
253
+ * `messaging_preference:write` scope, which cannot send email. Keys made with `hog_flow:write` still
254
+ * work for all three. Requests go to `appHost`, or to the PostHog Cloud app host of `host`. `send`,
255
+ * `get` and `setPreferences` resolve to `{ data, error }` and do not reject.
255
256
  * `data.id` is the queued email's message ID, which `get` takes. A disabled client sends nothing
256
257
  * and returns the error `client_disabled`. After `shutdown()`, the client sends nothing and
257
258
  * returns the error `client_closed`.
@@ -271,6 +272,9 @@ export declare abstract class PostHogBackendClient extends PostHogCoreStateless
271
272
  * }
272
273
  *
273
274
  * const status = await client.emails.get(data.id) // later, for example from a job
275
+ *
276
+ * // From a preference center: opt out of one topic, keep the rest
277
+ * await client.emails.setPreferences({ to: 'user@example.com', topics: { newsletter: false } })
274
278
  * ```
275
279
  *
276
280
  * {@label Emails}
@@ -1 +1 @@
1
- {"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../src/client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;;;;;;;;;;;;;;;;OAmCG;IACH,gBAAgB,CACd,KAAK,EAAE,OAAO,EACd,UAAU,CAAC,EAAE,MAAM,EACnB,oBAAoB,CAAC,EAAE,MAAM,CAAC,MAAM,GAAG,MAAM,EAAE,GAAG,CAAC,EACnD,IAAI,CAAC,EAAE,YAAY,CAAC,MAAM,CAAC,EAC3B,KAAK,CAAC,EAAE,sBAAsB,GAC7B,IAAI,CAcN;IAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OAmCG;IACG,yBAAyB,CAC7B,KAAK,EAAE,OAAO,EACd,UAAU,CAAC,EAAE,MAAM,EACnB,oBAAoB,CAAC,EAAE,MAAM,CAAC,MAAM,GAAG,MAAM,EAAE,GAAG,CAAC,EACnD,KAAK,CAAC,EAAE,sBAAsB,GAC7B,OAAO,CAAC,IAAI,CAAC,CAcf;IAEY,mBAAmB,CAAC,KAAK,EAAE,YAAY,GAAG,OAAO,CAAC;QAC7D,UAAU,EAAE,MAAM,CAAA;QAClB,KAAK,EAAE,MAAM,CAAA;QACb,UAAU,EAAE,sBAAsB,CAAA;QAClC,OAAO,EAAE,qBAAqB,CAAA;KAC/B,CAAC,CAED;IAED;;;;;;;OAOG;IACH,OAAO,CAAC,sBAAsB;IAK9B,yFAAyF;IACzF,OAAO,CAAC,mBAAmB;YAYb,oBAAoB;IA2JlC,OAAO,CAAC,cAAc;CA4BvB"}
@@ -1,5 +1,5 @@
1
1
  import { type FetchLike, type Logger } from '@posthog/core';
2
- import type { Emails, GetEmailResponse, SendEmailOptions, SendEmailResponse } from './types';
2
+ import type { Emails, GetEmailResponse, SendEmailOptions, SendEmailResponse, SetEmailPreferencesOptions, SetEmailPreferencesResponse } from './types';
3
3
  export declare const DEFAULT_EMAIL_REQUEST_TIMEOUT_MS = 15000;
4
4
  export declare const DEFAULT_EMAIL_REQUEST_MAX_RETRIES = 2;
5
5
  export interface EmailSenderConfig {
@@ -19,9 +19,9 @@ export interface EmailSenderHooks {
19
19
  userAgent?: string;
20
20
  }
21
21
  /**
22
- * Sends one transactional email per call to the messaging send API on the app host, and reads
23
- * the status of a sent email. Owns the attempt loop, so every attempt of a send carries the same
24
- * idempotency key.
22
+ * Sends one transactional email per call to the messaging send API on the app host, reads the
23
+ * status of a sent email, and sets a recipient's topic preferences. Owns the attempt loop, so every
24
+ * attempt of a send carries the same idempotency key.
25
25
  */
26
26
  export declare class EmailSender implements Emails {
27
27
  private readonly config;
@@ -30,14 +30,16 @@ export declare class EmailSender implements Emails {
30
30
  constructor(config: EmailSenderConfig, hooks: EmailSenderHooks);
31
31
  send(options: SendEmailOptions, ...unexpected: unknown[]): Promise<SendEmailResponse>;
32
32
  get(id: string): Promise<GetEmailResponse>;
33
+ setPreferences(options: SetEmailPreferencesOptions): Promise<SetEmailPreferencesResponse>;
33
34
  private track;
34
35
  /**
35
- * Resolves when every send and status read in flight, retries included, has settled.
36
+ * Resolves when every send, status read and preferences change in flight, retries included, has settled.
36
37
  * Kept apart from the client's pending-promise queue, so a send in its retry backoff does not hold back `flush()`.
37
38
  */
38
39
  drain(): Promise<void>;
39
40
  private sendUntracked;
40
41
  private getUntracked;
42
+ private setPreferencesUntracked;
41
43
  private connect;
42
44
  private headers;
43
45
  private withRetries;
@@ -1 +1 @@
1
- {"version":3,"file":"emails.d.ts","sourceRoot":"","sources":["../../src/emails/emails.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,SAAS,EACd,KAAK,MAAM,EAKZ,MAAM,eAAe,CAAA;AAGtB,OAAO,KAAK,EAIV,MAAM,EACN,gBAAgB,EAEhB,gBAAgB,EAChB,iBAAiB,EAIlB,MAAM,SAAS,CAAA;AAyDhB,eAAO,MAAM,gCAAgC,QAAS,CAAA;AACtD,eAAO,MAAM,iCAAiC,IAAI,CAAA;AAElD,MAAM,WAAW,iBAAiB;IAChC,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,+DAA+D;IAC/D,IAAI,EAAE,MAAM,CAAA;IACZ,OAAO,CAAC,EAAE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;YAwBX,OAAO;CA2DtB"}
@@ -36,6 +36,7 @@ const core_namespaceObject = require("@posthog/core");
36
36
  const external_errors_js_namespaceObject = require("./errors.js");
37
37
  const SEND_PATH = '/api/projects/@current/messaging/send/email/';
38
38
  const STATUS_PATH = '/api/projects/@current/messaging/emails/{messageId}/';
39
+ const PREFERENCES_PATH = '/api/projects/@current/messaging/preferences/';
39
40
  const US_APP_HOST = 'https://us.posthog.com';
40
41
  const EU_APP_HOST = 'https://eu.posthog.com';
41
42
  const CLOUD_APP_HOSTS = {
@@ -66,7 +67,8 @@ const CODE_FIELDS = {
66
67
  replyTo: true,
67
68
  captureEngagement: true,
68
69
  html: true,
69
- text: true
70
+ text: true,
71
+ react: true
70
72
  };
71
73
  const TEMPLATE_FORM = {
72
74
  name: 'templateId',
@@ -94,6 +96,9 @@ class EmailSender {
94
96
  get(id) {
95
97
  return this.track(this.getUntracked(id));
96
98
  }
99
+ setPreferences(options) {
100
+ return this.track(this.setPreferencesUntracked(options));
101
+ }
97
102
  track(pending) {
98
103
  this.inFlight.add(pending);
99
104
  pending.finally(()=>this.inFlight.delete(pending));
@@ -107,11 +112,12 @@ class EmailSender {
107
112
  refuseSecondArgument(unexpected);
108
113
  const prepared = prepareSend(options, this.config.maxRetries);
109
114
  const { appHost, secretKey } = this.connect('no email was sent', 'Sending email needs secretKey, a project secret API key with the transactional_email:write scope.');
115
+ const body = void 0 === prepared.react ? prepared.body : await withRenderedReact(prepared.body, prepared.react, this.config.requestTimeoutMs);
110
116
  const headers = this.headers(secretKey, {
111
117
  'Content-Type': 'application/json',
112
118
  'Idempotency-Key': prepared.idempotencyKey
113
119
  });
114
- const result = await this.withRetries(prepared.maxRetries, async ()=>parseSendReply(await this.request(appHost + prepared.path, 'POST', headers, prepared.body)));
120
+ const result = await this.withRetries(prepared.maxRetries, async ()=>parseSendReply(await this.request(appHost + SEND_PATH, 'POST', headers, body)));
115
121
  for (const warning of result.warnings)this.hooks.logger.warn(`PostHog email warning ${warning.code}: ${warning.message}`);
116
122
  return {
117
123
  data: result,
@@ -142,6 +148,25 @@ class EmailSender {
142
148
  };
143
149
  }
144
150
  }
151
+ async setPreferencesUntracked(options) {
152
+ try {
153
+ const body = preparePreferences(options);
154
+ const { appHost, secretKey } = this.connect('no preferences changed', 'Setting email preferences needs secretKey, a project secret API key with the messaging_preference:write scope.');
155
+ const headers = this.headers(secretKey, {
156
+ 'Content-Type': 'application/json'
157
+ });
158
+ const preferences = await this.withRetries(this.config.maxRetries, async ()=>parsePreferencesReply(await this.request(appHost + PREFERENCES_PATH, 'POST', headers, body)));
159
+ return {
160
+ data: preferences,
161
+ error: null
162
+ };
163
+ } catch (error) {
164
+ return {
165
+ data: null,
166
+ error: asEmailError(error, 'Setting the email preferences failed unexpectedly.')
167
+ };
168
+ }
169
+ }
145
170
  connect(nothingDone, missingSecretKey) {
146
171
  if (this.hooks.isDisabled()) throw new external_errors_js_namespaceObject.EmailError({
147
172
  code: 'client_disabled',
@@ -262,22 +287,40 @@ function prepareSend(options, defaultMaxRetries) {
262
287
  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');
263
288
  if (void 0 !== maxRetries && !isRetryCount(maxRetries)) throw invalid('invalid_max_retries', 'maxRetries must be a nonnegative integer.', 'maxRetries');
264
289
  return {
265
- path: SEND_PATH,
266
290
  body: (0, core_namespaceObject.safeJsonStringify)({
267
291
  ...content,
268
292
  to
269
293
  }),
294
+ react: isReactElement(send.react) ? send.react : void 0,
270
295
  idempotencyKey: idempotencyKey ?? globalThis.crypto.randomUUID(),
271
296
  maxRetries: isRetryCount(maxRetries) ? maxRetries : defaultMaxRetries
272
297
  };
273
298
  }
299
+ function preparePreferences(options) {
300
+ const fallback = {};
301
+ const { to, allMarketing, topics } = options ?? fallback;
302
+ if ('string' != typeof to || !to.trim()) throw invalid('invalid_recipient', 'to must be one email address as a nonempty string.', 'to');
303
+ if (void 0 !== allMarketing && 'boolean' != typeof allMarketing) throw invalid('invalid_preferences', 'allMarketing must be true or false.', 'allMarketing');
304
+ if (void 0 !== topics && ('object' != typeof topics || null === topics || Array.isArray(topics) || !Object.values(topics).every((value)=>'boolean' == typeof value))) throw invalid('invalid_preferences', 'topics must map each topic key to true or false.', 'topics');
305
+ const hasTopics = void 0 !== topics && Object.keys(topics).length > 0;
306
+ if (void 0 === allMarketing && !hasTopics) throw invalid('invalid_preferences', 'Set allMarketing, topics, or both.', 'topics');
307
+ return (0, core_namespaceObject.safeJsonStringify)({
308
+ identifier: to,
309
+ ...void 0 === allMarketing ? {} : {
310
+ all_marketing: allMarketing
311
+ },
312
+ ...hasTopics ? {
313
+ topics
314
+ } : {}
315
+ });
316
+ }
274
317
  function isRetryCount(value) {
275
318
  return 'number' == typeof value && Number.isInteger(value) && value >= 0;
276
319
  }
277
320
  function contentOf(send, distinctId) {
278
321
  if (void 0 === send.templateId === (void 0 === send.templateKey)) throw new external_errors_js_namespaceObject.EmailError({
279
322
  code: 'invalid_form',
280
- message: 'Send either templateId, or templateKey with subject and html or text.'
323
+ message: 'Send either templateId, or templateKey with subject and html, text or react.'
281
324
  });
282
325
  return void 0 === send.templateKey ? templateContent(send, distinctId) : codeContent(send, distinctId);
283
326
  }
@@ -295,13 +338,14 @@ function templateContent(send, distinctId) {
295
338
  };
296
339
  }
297
340
  function codeContent(send, distinctId) {
298
- const { templateKey, subject, html, text, from, replyTo, captureEngagement } = send;
341
+ const { templateKey, subject, html, text, react, from, replyTo, captureEngagement } = send;
299
342
  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');
300
343
  refuseFieldsOutside(send, CODE_FORM, TEMPLATE_FORM);
301
344
  if ('string' != typeof subject) throw invalid('invalid_form', 'A send with templateKey needs a subject.', 'subject');
302
345
  if (void 0 !== html && 'string' != typeof html) throw invalid('invalid_form', 'html must be a string.', 'html');
303
346
  if (void 0 !== text && 'string' != typeof text) throw invalid('invalid_form', 'text must be a string.', 'text');
304
- if (void 0 === html && void 0 === text) throw invalid('invalid_form', 'A send with templateKey needs html, text or both.', 'html');
347
+ if (void 0 !== react) checkReactContent(react, html);
348
+ else if (void 0 === html && void 0 === text) throw invalid('invalid_form', 'A send with templateKey needs html, text or react.', 'html');
305
349
  const sendsReplyTo = void 0 !== replyTo && !(Array.isArray(replyTo) && 0 === replyTo.length);
306
350
  return {
307
351
  template_key: templateKey,
@@ -326,6 +370,68 @@ function codeContent(send, distinctId) {
326
370
  }
327
371
  };
328
372
  }
373
+ function checkReactContent(react, html) {
374
+ if (!isReactElement(react)) throw invalid('invalid_form', 'react must be a React element, such as <WelcomeEmail />.', 'react');
375
+ if (void 0 !== html) throw new external_errors_js_namespaceObject.EmailError({
376
+ code: 'invalid_form',
377
+ message: 'A send with react renders its own html, so it takes no html. No email was sent.',
378
+ field: 'html',
379
+ fix: 'Remove html to send the rendered react element, or remove react to send your html.'
380
+ });
381
+ }
382
+ const REACT_18_AND_19_ELEMENT_MARKERS = [
383
+ Symbol.for('react.element'),
384
+ Symbol.for('react.transitional.element')
385
+ ];
386
+ function isReactElement(value) {
387
+ return 'object' == typeof value && null !== value && '$$typeof' in value && REACT_18_AND_19_ELEMENT_MARKERS.includes(value.$$typeof) && 'type' in value && 'props' in value;
388
+ }
389
+ async function withRenderedReact(body, react, timeoutMs) {
390
+ const { render, toPlainText } = await loadReactRenderer();
391
+ const fields = JSON.parse(body);
392
+ try {
393
+ const html = await settleWithin(render(react), timeoutMs, 'Rendering the react element');
394
+ return (0, core_namespaceObject.safeJsonStringify)({
395
+ ...fields,
396
+ html,
397
+ ...void 0 === fields.text && {
398
+ text: toPlainText(html)
399
+ }
400
+ });
401
+ } catch (cause) {
402
+ throw new external_errors_js_namespaceObject.EmailError({
403
+ code: 'react_render_failed',
404
+ message: 'Rendering the react element failed, so no email was sent.',
405
+ cause
406
+ });
407
+ }
408
+ }
409
+ async function settleWithin(work, timeoutMs, what) {
410
+ let timer;
411
+ const deadline = new Promise((_resolve, reject)=>{
412
+ timer = setTimeout(()=>reject(new Error(`${what} took longer than ${timeoutMs}ms.`)), timeoutMs);
413
+ });
414
+ try {
415
+ return await Promise.race([
416
+ work,
417
+ deadline
418
+ ]);
419
+ } finally{
420
+ clearTimeout(timer);
421
+ }
422
+ }
423
+ async function loadReactRenderer() {
424
+ try {
425
+ return await import("@react-email/render");
426
+ } catch (cause) {
427
+ throw new external_errors_js_namespaceObject.EmailError({
428
+ code: 'missing_react_renderer',
429
+ message: "react needs the @react-email/render package, which isn't installed or failed to load, so no email was sent.",
430
+ fix: 'Install @react-email/render with react and react-dom next to posthog-node, or render the email yourself and send html.',
431
+ cause
432
+ });
433
+ }
434
+ }
329
435
  function refuseFieldsOutside(send, form, otherForm) {
330
436
  const field = Object.entries(send).find(([name, value])=>void 0 !== value && !form.fields.has(name))?.[0];
331
437
  if (void 0 === field) return;
@@ -424,6 +530,23 @@ function parseStatusReply({ status, payload, retryAfterMs }) {
424
530
  reason: emails_text(fields.reason) ?? null
425
531
  };
426
532
  }
533
+ function parsePreferencesReply({ status, payload, retryAfterMs }) {
534
+ const fields = replyFields(payload);
535
+ if (status < 200 || status >= 300) throw replyError(fields, status, retryAfterMs);
536
+ const to = emails_text(fields.identifier);
537
+ const allMarketing = fields.all_marketing;
538
+ const topics = fields.topics;
539
+ if (!to || !(null === allMarketing || 'boolean' == typeof allMarketing) || null === topics || 'object' != typeof topics || Array.isArray(topics) || !Object.values(topics).every((value)=>'boolean' == typeof value)) throw new external_errors_js_namespaceObject.EmailError({
540
+ code: 'api_error',
541
+ message: 'PostHog answered without the preferences.',
542
+ statusCode: status
543
+ });
544
+ return {
545
+ to,
546
+ allMarketing,
547
+ topics: topics
548
+ };
549
+ }
427
550
  function replyError(fields, status, retryAfterMs) {
428
551
  return new external_errors_js_namespaceObject.EmailError({
429
552
  code: emails_text(fields.code) ?? 'api_error',
@@ -2,6 +2,7 @@ import { parseRetryAfterMs, removeTrailingSlash, safeJsonStringify } from "@post
2
2
  import { EmailError } from "./errors.mjs";
3
3
  const SEND_PATH = '/api/projects/@current/messaging/send/email/';
4
4
  const STATUS_PATH = '/api/projects/@current/messaging/emails/{messageId}/';
5
+ const PREFERENCES_PATH = '/api/projects/@current/messaging/preferences/';
5
6
  const US_APP_HOST = 'https://us.posthog.com';
6
7
  const EU_APP_HOST = 'https://eu.posthog.com';
7
8
  const CLOUD_APP_HOSTS = {
@@ -32,7 +33,8 @@ const CODE_FIELDS = {
32
33
  replyTo: true,
33
34
  captureEngagement: true,
34
35
  html: true,
35
- text: true
36
+ text: true,
37
+ react: true
36
38
  };
37
39
  const TEMPLATE_FORM = {
38
40
  name: 'templateId',
@@ -60,6 +62,9 @@ class EmailSender {
60
62
  get(id) {
61
63
  return this.track(this.getUntracked(id));
62
64
  }
65
+ setPreferences(options) {
66
+ return this.track(this.setPreferencesUntracked(options));
67
+ }
63
68
  track(pending) {
64
69
  this.inFlight.add(pending);
65
70
  pending.finally(()=>this.inFlight.delete(pending));
@@ -73,11 +78,12 @@ class EmailSender {
73
78
  refuseSecondArgument(unexpected);
74
79
  const prepared = prepareSend(options, this.config.maxRetries);
75
80
  const { appHost, secretKey } = this.connect('no email was sent', 'Sending email needs secretKey, a project secret API key with the transactional_email:write scope.');
81
+ const body = void 0 === prepared.react ? prepared.body : await withRenderedReact(prepared.body, prepared.react, this.config.requestTimeoutMs);
76
82
  const headers = this.headers(secretKey, {
77
83
  'Content-Type': 'application/json',
78
84
  'Idempotency-Key': prepared.idempotencyKey
79
85
  });
80
- const result = await this.withRetries(prepared.maxRetries, async ()=>parseSendReply(await this.request(appHost + prepared.path, 'POST', headers, prepared.body)));
86
+ const result = await this.withRetries(prepared.maxRetries, async ()=>parseSendReply(await this.request(appHost + SEND_PATH, 'POST', headers, body)));
81
87
  for (const warning of result.warnings)this.hooks.logger.warn(`PostHog email warning ${warning.code}: ${warning.message}`);
82
88
  return {
83
89
  data: result,
@@ -108,6 +114,25 @@ class EmailSender {
108
114
  };
109
115
  }
110
116
  }
117
+ async setPreferencesUntracked(options) {
118
+ try {
119
+ const body = preparePreferences(options);
120
+ const { appHost, secretKey } = this.connect('no preferences changed', 'Setting email preferences needs secretKey, a project secret API key with the messaging_preference:write scope.');
121
+ const headers = this.headers(secretKey, {
122
+ 'Content-Type': 'application/json'
123
+ });
124
+ const preferences = await this.withRetries(this.config.maxRetries, async ()=>parsePreferencesReply(await this.request(appHost + PREFERENCES_PATH, 'POST', headers, body)));
125
+ return {
126
+ data: preferences,
127
+ error: null
128
+ };
129
+ } catch (error) {
130
+ return {
131
+ data: null,
132
+ error: asEmailError(error, 'Setting the email preferences failed unexpectedly.')
133
+ };
134
+ }
135
+ }
111
136
  connect(nothingDone, missingSecretKey) {
112
137
  if (this.hooks.isDisabled()) throw new EmailError({
113
138
  code: 'client_disabled',
@@ -228,22 +253,40 @@ function prepareSend(options, defaultMaxRetries) {
228
253
  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');
229
254
  if (void 0 !== maxRetries && !isRetryCount(maxRetries)) throw invalid('invalid_max_retries', 'maxRetries must be a nonnegative integer.', 'maxRetries');
230
255
  return {
231
- path: SEND_PATH,
232
256
  body: safeJsonStringify({
233
257
  ...content,
234
258
  to
235
259
  }),
260
+ react: isReactElement(send.react) ? send.react : void 0,
236
261
  idempotencyKey: idempotencyKey ?? globalThis.crypto.randomUUID(),
237
262
  maxRetries: isRetryCount(maxRetries) ? maxRetries : defaultMaxRetries
238
263
  };
239
264
  }
265
+ function preparePreferences(options) {
266
+ const fallback = {};
267
+ const { to, allMarketing, topics } = options ?? fallback;
268
+ if ('string' != typeof to || !to.trim()) throw invalid('invalid_recipient', 'to must be one email address as a nonempty string.', 'to');
269
+ if (void 0 !== allMarketing && 'boolean' != typeof allMarketing) throw invalid('invalid_preferences', 'allMarketing must be true or false.', 'allMarketing');
270
+ if (void 0 !== topics && ('object' != typeof topics || null === topics || Array.isArray(topics) || !Object.values(topics).every((value)=>'boolean' == typeof value))) throw invalid('invalid_preferences', 'topics must map each topic key to true or false.', 'topics');
271
+ const hasTopics = void 0 !== topics && Object.keys(topics).length > 0;
272
+ if (void 0 === allMarketing && !hasTopics) throw invalid('invalid_preferences', 'Set allMarketing, topics, or both.', 'topics');
273
+ return safeJsonStringify({
274
+ identifier: to,
275
+ ...void 0 === allMarketing ? {} : {
276
+ all_marketing: allMarketing
277
+ },
278
+ ...hasTopics ? {
279
+ topics
280
+ } : {}
281
+ });
282
+ }
240
283
  function isRetryCount(value) {
241
284
  return 'number' == typeof value && Number.isInteger(value) && value >= 0;
242
285
  }
243
286
  function contentOf(send, distinctId) {
244
287
  if (void 0 === send.templateId === (void 0 === send.templateKey)) throw new EmailError({
245
288
  code: 'invalid_form',
246
- message: 'Send either templateId, or templateKey with subject and html or text.'
289
+ message: 'Send either templateId, or templateKey with subject and html, text or react.'
247
290
  });
248
291
  return void 0 === send.templateKey ? templateContent(send, distinctId) : codeContent(send, distinctId);
249
292
  }
@@ -261,13 +304,14 @@ function templateContent(send, distinctId) {
261
304
  };
262
305
  }
263
306
  function codeContent(send, distinctId) {
264
- const { templateKey, subject, html, text, from, replyTo, captureEngagement } = send;
307
+ const { templateKey, subject, html, text, react, from, replyTo, captureEngagement } = send;
265
308
  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');
266
309
  refuseFieldsOutside(send, CODE_FORM, TEMPLATE_FORM);
267
310
  if ('string' != typeof subject) throw invalid('invalid_form', 'A send with templateKey needs a subject.', 'subject');
268
311
  if (void 0 !== html && 'string' != typeof html) throw invalid('invalid_form', 'html must be a string.', 'html');
269
312
  if (void 0 !== text && 'string' != typeof text) throw invalid('invalid_form', 'text must be a string.', 'text');
270
- if (void 0 === html && void 0 === text) throw invalid('invalid_form', 'A send with templateKey needs html, text or both.', 'html');
313
+ if (void 0 !== react) checkReactContent(react, html);
314
+ else if (void 0 === html && void 0 === text) throw invalid('invalid_form', 'A send with templateKey needs html, text or react.', 'html');
271
315
  const sendsReplyTo = void 0 !== replyTo && !(Array.isArray(replyTo) && 0 === replyTo.length);
272
316
  return {
273
317
  template_key: templateKey,
@@ -292,6 +336,68 @@ function codeContent(send, distinctId) {
292
336
  }
293
337
  };
294
338
  }
339
+ function checkReactContent(react, html) {
340
+ if (!isReactElement(react)) throw invalid('invalid_form', 'react must be a React element, such as <WelcomeEmail />.', 'react');
341
+ if (void 0 !== html) throw new EmailError({
342
+ code: 'invalid_form',
343
+ message: 'A send with react renders its own html, so it takes no html. No email was sent.',
344
+ field: 'html',
345
+ fix: 'Remove html to send the rendered react element, or remove react to send your html.'
346
+ });
347
+ }
348
+ const REACT_18_AND_19_ELEMENT_MARKERS = [
349
+ Symbol.for('react.element'),
350
+ Symbol.for('react.transitional.element')
351
+ ];
352
+ function isReactElement(value) {
353
+ return 'object' == typeof value && null !== value && '$$typeof' in value && REACT_18_AND_19_ELEMENT_MARKERS.includes(value.$$typeof) && 'type' in value && 'props' in value;
354
+ }
355
+ async function withRenderedReact(body, react, timeoutMs) {
356
+ const { render, toPlainText } = await loadReactRenderer();
357
+ const fields = JSON.parse(body);
358
+ try {
359
+ const html = await settleWithin(render(react), timeoutMs, 'Rendering the react element');
360
+ return safeJsonStringify({
361
+ ...fields,
362
+ html,
363
+ ...void 0 === fields.text && {
364
+ text: toPlainText(html)
365
+ }
366
+ });
367
+ } catch (cause) {
368
+ throw new EmailError({
369
+ code: 'react_render_failed',
370
+ message: 'Rendering the react element failed, so no email was sent.',
371
+ cause
372
+ });
373
+ }
374
+ }
375
+ async function settleWithin(work, timeoutMs, what) {
376
+ let timer;
377
+ const deadline = new Promise((_resolve, reject)=>{
378
+ timer = setTimeout(()=>reject(new Error(`${what} took longer than ${timeoutMs}ms.`)), timeoutMs);
379
+ });
380
+ try {
381
+ return await Promise.race([
382
+ work,
383
+ deadline
384
+ ]);
385
+ } finally{
386
+ clearTimeout(timer);
387
+ }
388
+ }
389
+ async function loadReactRenderer() {
390
+ try {
391
+ return await import("@react-email/render");
392
+ } catch (cause) {
393
+ throw new EmailError({
394
+ code: 'missing_react_renderer',
395
+ message: "react needs the @react-email/render package, which isn't installed or failed to load, so no email was sent.",
396
+ fix: 'Install @react-email/render with react and react-dom next to posthog-node, or render the email yourself and send html.',
397
+ cause
398
+ });
399
+ }
400
+ }
295
401
  function refuseFieldsOutside(send, form, otherForm) {
296
402
  const field = Object.entries(send).find(([name, value])=>void 0 !== value && !form.fields.has(name))?.[0];
297
403
  if (void 0 === field) return;
@@ -390,6 +496,23 @@ function parseStatusReply({ status, payload, retryAfterMs }) {
390
496
  reason: emails_text(fields.reason) ?? null
391
497
  };
392
498
  }
499
+ function parsePreferencesReply({ status, payload, retryAfterMs }) {
500
+ const fields = replyFields(payload);
501
+ if (status < 200 || status >= 300) throw replyError(fields, status, retryAfterMs);
502
+ const to = emails_text(fields.identifier);
503
+ const allMarketing = fields.all_marketing;
504
+ const topics = fields.topics;
505
+ if (!to || !(null === allMarketing || 'boolean' == typeof allMarketing) || null === topics || 'object' != typeof topics || Array.isArray(topics) || !Object.values(topics).every((value)=>'boolean' == typeof value)) throw new EmailError({
506
+ code: 'api_error',
507
+ message: 'PostHog answered without the preferences.',
508
+ statusCode: status
509
+ });
510
+ return {
511
+ to,
512
+ allMarketing,
513
+ topics: topics
514
+ };
515
+ }
393
516
  function replyError(fields, status, retryAfterMs) {
394
517
  return new EmailError({
395
518
  code: emails_text(fields.code) ?? 'api_error',
@@ -14,7 +14,7 @@ export interface EmailErrorParams {
14
14
  cause?: unknown;
15
15
  }
16
16
  /**
17
- * PostHog did not queue the email, or the client could not tell whether it did.
17
+ * PostHog refused an email call, or the client could not tell whether it succeeded.
18
18
  *
19
19
  * Branch on `code`, PostHog's stable error code, or on `name`, a coarse category of the
20
20
  * failure. The message never contains the secret key or the request body.