posthog-node 5.69.0 → 5.71.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 +12 -8
- package/dist/client.d.ts.map +1 -1
- package/dist/emails/emails.d.ts +7 -5
- package/dist/emails/emails.d.ts.map +1 -1
- package/dist/emails/emails.js +70 -2
- package/dist/emails/emails.mjs +70 -2
- package/dist/emails/errors.d.ts +1 -1
- package/dist/emails/types.d.ts +94 -1
- 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/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/dist/version.mjs +1 -1
- package/package.json +5 -6
- package/src/client.ts +12 -8
- package/src/emails/emails.ts +90 -6
- package/src/emails/errors.ts +1 -1
- package/src/emails/types.ts +93 -1
- package/src/exports.ts +4 -0
- package/src/version.ts +1 -1
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,
|
|
248
|
-
* the status of each email it sent.
|
|
249
|
-
*
|
|
250
|
-
* Needs `secretKey`, a project secret API key
|
|
251
|
-
* "Send transactional email" preset)
|
|
252
|
-
*
|
|
253
|
-
*
|
|
254
|
-
*
|
|
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}
|
package/dist/client.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAEA,OAAO,EAEL,gBAAgB,EAKhB,QAAQ,EAER,qBAAqB,EACrB,oBAAoB,EACpB,sBAAsB,EACtB,mBAAmB,EACnB,oBAAoB,EACpB,+BAA+B,EAG/B,wBAAwB,EAGxB,KAAK,aAAa,EAClB,KAAK,iBAAiB,EAEtB,UAAU,EAIV,gBAAgB,EAKjB,MAAM,eAAe,CAAA;AACtB,OAAO,KAAK,EACV,OAAO,EACP,yBAAyB,EACzB,IAAI,EACJ,kBAAkB,EAClB,gBAAgB,EAGjB,MAAM,eAAe,CAAA;AACtB,OAAO,EACL,eAAe,EACf,YAAY,EAGZ,4BAA4B,EAE5B,iBAAiB,EACjB,qBAAqB,EACrB,oBAAoB,EACpB,eAAe,EACf,QAAQ,EACR,2BAA2B,EAC3B,cAAc,EAEd,0BAA0B,EAC1B,4BAA4B,EAC7B,MAAM,SAAS,CAAA;AAChB,OAAO,EAEL,sBAAsB,EAEtB,qBAAqB,EACtB,M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AE,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"}
|
package/dist/emails/emails.d.ts
CHANGED
|
@@ -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,
|
|
23
|
-
*
|
|
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
|
|
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,
|
|
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,EAMV,MAAM,EACN,gBAAgB,EAEhB,gBAAgB,EAChB,iBAAiB,EAGjB,0BAA0B,EAC1B,2BAA2B,EAE5B,MAAM,SAAS,CAAA;AAiEhB,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,MAAM,CAAA;IAChB,gBAAgB,EAAE,MAAM,CAAA;IACxB,UAAU,EAAE,MAAM,CAAA;IAClB,YAAY,CAAC,EAAE,MAAM,CAAA;CACtB;AAED,MAAM,WAAW,gBAAgB;IAC/B,KAAK,EAAE,SAAS,CAAA;IAChB,UAAU,EAAE,MAAM,OAAO,CAAA;IACzB,QAAQ,EAAE,MAAM,OAAO,CAAA;IACvB,MAAM,EAAE,MAAM,CAAA;IACd,SAAS,CAAC,EAAE,MAAM,CAAA;CACnB;AAeD;;;;GAIG;AACH,qBAAa,WAAY,YAAW,MAAM;IACxC,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAmB;IAC1C,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAkB;IACxC,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAA8B;IAEvD,YAAY,MAAM,EAAE,iBAAiB,EAAE,KAAK,EAAE,gBAAgB,EAG7D;IAED,IAAI,CAAC,OAAO,EAAE,gBAAgB,EAAE,GAAG,UAAU,EAAE,OAAO,EAAE,GAAG,OAAO,CAAC,iBAAiB,CAAC,CAEpF;IAED,GAAG,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,gBAAgB,CAAC,CAEzC;IAED,cAAc,CAAC,OAAO,EAAE,0BAA0B,GAAG,OAAO,CAAC,2BAA2B,CAAC,CAExF;IAED,OAAO,CAAC,KAAK;IAMb;;;OAGG;IACG,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC,CAI3B;YAEa,aAAa;YA4Bb,YAAY;YAoBZ,uBAAuB;IAiBrC,OAAO,CAAC,OAAO;IA6Bf,OAAO,CAAC,OAAO;YAeD,WAAW;YAwBX,OAAO;CA2DtB"}
|
package/dist/emails/emails.js
CHANGED
|
@@ -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 = {
|
|
@@ -65,6 +66,8 @@ const CODE_FIELDS = {
|
|
|
65
66
|
from: true,
|
|
66
67
|
replyTo: true,
|
|
67
68
|
captureEngagement: true,
|
|
69
|
+
sensitive: true,
|
|
70
|
+
tracking: true,
|
|
68
71
|
html: true,
|
|
69
72
|
text: true,
|
|
70
73
|
react: true
|
|
@@ -95,6 +98,9 @@ class EmailSender {
|
|
|
95
98
|
get(id) {
|
|
96
99
|
return this.track(this.getUntracked(id));
|
|
97
100
|
}
|
|
101
|
+
setPreferences(options) {
|
|
102
|
+
return this.track(this.setPreferencesUntracked(options));
|
|
103
|
+
}
|
|
98
104
|
track(pending) {
|
|
99
105
|
this.inFlight.add(pending);
|
|
100
106
|
pending.finally(()=>this.inFlight.delete(pending));
|
|
@@ -144,6 +150,25 @@ class EmailSender {
|
|
|
144
150
|
};
|
|
145
151
|
}
|
|
146
152
|
}
|
|
153
|
+
async setPreferencesUntracked(options) {
|
|
154
|
+
try {
|
|
155
|
+
const body = preparePreferences(options);
|
|
156
|
+
const { appHost, secretKey } = this.connect('no preferences changed', 'Setting email preferences needs secretKey, a project secret API key with the messaging_preference:write scope.');
|
|
157
|
+
const headers = this.headers(secretKey, {
|
|
158
|
+
'Content-Type': 'application/json'
|
|
159
|
+
});
|
|
160
|
+
const preferences = await this.withRetries(this.config.maxRetries, async ()=>parsePreferencesReply(await this.request(appHost + PREFERENCES_PATH, 'POST', headers, body)));
|
|
161
|
+
return {
|
|
162
|
+
data: preferences,
|
|
163
|
+
error: null
|
|
164
|
+
};
|
|
165
|
+
} catch (error) {
|
|
166
|
+
return {
|
|
167
|
+
data: null,
|
|
168
|
+
error: asEmailError(error, 'Setting the email preferences failed unexpectedly.')
|
|
169
|
+
};
|
|
170
|
+
}
|
|
171
|
+
}
|
|
147
172
|
connect(nothingDone, missingSecretKey) {
|
|
148
173
|
if (this.hooks.isDisabled()) throw new external_errors_js_namespaceObject.EmailError({
|
|
149
174
|
code: 'client_disabled',
|
|
@@ -273,6 +298,24 @@ function prepareSend(options, defaultMaxRetries) {
|
|
|
273
298
|
maxRetries: isRetryCount(maxRetries) ? maxRetries : defaultMaxRetries
|
|
274
299
|
};
|
|
275
300
|
}
|
|
301
|
+
function preparePreferences(options) {
|
|
302
|
+
const fallback = {};
|
|
303
|
+
const { to, allMarketing, topics } = options ?? fallback;
|
|
304
|
+
if ('string' != typeof to || !to.trim()) throw invalid('invalid_recipient', 'to must be one email address as a nonempty string.', 'to');
|
|
305
|
+
if (void 0 !== allMarketing && 'boolean' != typeof allMarketing) throw invalid('invalid_preferences', 'allMarketing must be true or false.', 'allMarketing');
|
|
306
|
+
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');
|
|
307
|
+
const hasTopics = void 0 !== topics && Object.keys(topics).length > 0;
|
|
308
|
+
if (void 0 === allMarketing && !hasTopics) throw invalid('invalid_preferences', 'Set allMarketing, topics, or both.', 'topics');
|
|
309
|
+
return (0, core_namespaceObject.safeJsonStringify)({
|
|
310
|
+
identifier: to,
|
|
311
|
+
...void 0 === allMarketing ? {} : {
|
|
312
|
+
all_marketing: allMarketing
|
|
313
|
+
},
|
|
314
|
+
...hasTopics ? {
|
|
315
|
+
topics
|
|
316
|
+
} : {}
|
|
317
|
+
});
|
|
318
|
+
}
|
|
276
319
|
function isRetryCount(value) {
|
|
277
320
|
return 'number' == typeof value && Number.isInteger(value) && value >= 0;
|
|
278
321
|
}
|
|
@@ -297,7 +340,7 @@ function templateContent(send, distinctId) {
|
|
|
297
340
|
};
|
|
298
341
|
}
|
|
299
342
|
function codeContent(send, distinctId) {
|
|
300
|
-
const { templateKey, subject, html, text, react, from, replyTo, captureEngagement } = send;
|
|
343
|
+
const { templateKey, subject, html, text, react, from, replyTo, captureEngagement, sensitive, tracking } = send;
|
|
301
344
|
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');
|
|
302
345
|
refuseFieldsOutside(send, CODE_FORM, TEMPLATE_FORM);
|
|
303
346
|
if ('string' != typeof subject) throw invalid('invalid_form', 'A send with templateKey needs a subject.', 'subject');
|
|
@@ -323,7 +366,15 @@ function codeContent(send, distinctId) {
|
|
|
323
366
|
replyTo
|
|
324
367
|
] : replyTo
|
|
325
368
|
},
|
|
326
|
-
|
|
369
|
+
...void 0 !== captureEngagement && {
|
|
370
|
+
capture_engagement: captureEngagement
|
|
371
|
+
},
|
|
372
|
+
...void 0 !== sensitive && {
|
|
373
|
+
sensitive
|
|
374
|
+
},
|
|
375
|
+
...void 0 !== tracking && {
|
|
376
|
+
tracking
|
|
377
|
+
},
|
|
327
378
|
...void 0 !== distinctId && {
|
|
328
379
|
distinct_id: distinctId
|
|
329
380
|
}
|
|
@@ -489,6 +540,23 @@ function parseStatusReply({ status, payload, retryAfterMs }) {
|
|
|
489
540
|
reason: emails_text(fields.reason) ?? null
|
|
490
541
|
};
|
|
491
542
|
}
|
|
543
|
+
function parsePreferencesReply({ status, payload, retryAfterMs }) {
|
|
544
|
+
const fields = replyFields(payload);
|
|
545
|
+
if (status < 200 || status >= 300) throw replyError(fields, status, retryAfterMs);
|
|
546
|
+
const to = emails_text(fields.identifier);
|
|
547
|
+
const allMarketing = fields.all_marketing;
|
|
548
|
+
const topics = fields.topics;
|
|
549
|
+
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({
|
|
550
|
+
code: 'api_error',
|
|
551
|
+
message: 'PostHog answered without the preferences.',
|
|
552
|
+
statusCode: status
|
|
553
|
+
});
|
|
554
|
+
return {
|
|
555
|
+
to,
|
|
556
|
+
allMarketing,
|
|
557
|
+
topics: topics
|
|
558
|
+
};
|
|
559
|
+
}
|
|
492
560
|
function replyError(fields, status, retryAfterMs) {
|
|
493
561
|
return new external_errors_js_namespaceObject.EmailError({
|
|
494
562
|
code: emails_text(fields.code) ?? 'api_error',
|
package/dist/emails/emails.mjs
CHANGED
|
@@ -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 = {
|
|
@@ -31,6 +32,8 @@ const CODE_FIELDS = {
|
|
|
31
32
|
from: true,
|
|
32
33
|
replyTo: true,
|
|
33
34
|
captureEngagement: true,
|
|
35
|
+
sensitive: true,
|
|
36
|
+
tracking: true,
|
|
34
37
|
html: true,
|
|
35
38
|
text: true,
|
|
36
39
|
react: true
|
|
@@ -61,6 +64,9 @@ class EmailSender {
|
|
|
61
64
|
get(id) {
|
|
62
65
|
return this.track(this.getUntracked(id));
|
|
63
66
|
}
|
|
67
|
+
setPreferences(options) {
|
|
68
|
+
return this.track(this.setPreferencesUntracked(options));
|
|
69
|
+
}
|
|
64
70
|
track(pending) {
|
|
65
71
|
this.inFlight.add(pending);
|
|
66
72
|
pending.finally(()=>this.inFlight.delete(pending));
|
|
@@ -110,6 +116,25 @@ class EmailSender {
|
|
|
110
116
|
};
|
|
111
117
|
}
|
|
112
118
|
}
|
|
119
|
+
async setPreferencesUntracked(options) {
|
|
120
|
+
try {
|
|
121
|
+
const body = preparePreferences(options);
|
|
122
|
+
const { appHost, secretKey } = this.connect('no preferences changed', 'Setting email preferences needs secretKey, a project secret API key with the messaging_preference:write scope.');
|
|
123
|
+
const headers = this.headers(secretKey, {
|
|
124
|
+
'Content-Type': 'application/json'
|
|
125
|
+
});
|
|
126
|
+
const preferences = await this.withRetries(this.config.maxRetries, async ()=>parsePreferencesReply(await this.request(appHost + PREFERENCES_PATH, 'POST', headers, body)));
|
|
127
|
+
return {
|
|
128
|
+
data: preferences,
|
|
129
|
+
error: null
|
|
130
|
+
};
|
|
131
|
+
} catch (error) {
|
|
132
|
+
return {
|
|
133
|
+
data: null,
|
|
134
|
+
error: asEmailError(error, 'Setting the email preferences failed unexpectedly.')
|
|
135
|
+
};
|
|
136
|
+
}
|
|
137
|
+
}
|
|
113
138
|
connect(nothingDone, missingSecretKey) {
|
|
114
139
|
if (this.hooks.isDisabled()) throw new EmailError({
|
|
115
140
|
code: 'client_disabled',
|
|
@@ -239,6 +264,24 @@ function prepareSend(options, defaultMaxRetries) {
|
|
|
239
264
|
maxRetries: isRetryCount(maxRetries) ? maxRetries : defaultMaxRetries
|
|
240
265
|
};
|
|
241
266
|
}
|
|
267
|
+
function preparePreferences(options) {
|
|
268
|
+
const fallback = {};
|
|
269
|
+
const { to, allMarketing, topics } = options ?? fallback;
|
|
270
|
+
if ('string' != typeof to || !to.trim()) throw invalid('invalid_recipient', 'to must be one email address as a nonempty string.', 'to');
|
|
271
|
+
if (void 0 !== allMarketing && 'boolean' != typeof allMarketing) throw invalid('invalid_preferences', 'allMarketing must be true or false.', 'allMarketing');
|
|
272
|
+
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');
|
|
273
|
+
const hasTopics = void 0 !== topics && Object.keys(topics).length > 0;
|
|
274
|
+
if (void 0 === allMarketing && !hasTopics) throw invalid('invalid_preferences', 'Set allMarketing, topics, or both.', 'topics');
|
|
275
|
+
return safeJsonStringify({
|
|
276
|
+
identifier: to,
|
|
277
|
+
...void 0 === allMarketing ? {} : {
|
|
278
|
+
all_marketing: allMarketing
|
|
279
|
+
},
|
|
280
|
+
...hasTopics ? {
|
|
281
|
+
topics
|
|
282
|
+
} : {}
|
|
283
|
+
});
|
|
284
|
+
}
|
|
242
285
|
function isRetryCount(value) {
|
|
243
286
|
return 'number' == typeof value && Number.isInteger(value) && value >= 0;
|
|
244
287
|
}
|
|
@@ -263,7 +306,7 @@ function templateContent(send, distinctId) {
|
|
|
263
306
|
};
|
|
264
307
|
}
|
|
265
308
|
function codeContent(send, distinctId) {
|
|
266
|
-
const { templateKey, subject, html, text, react, from, replyTo, captureEngagement } = send;
|
|
309
|
+
const { templateKey, subject, html, text, react, from, replyTo, captureEngagement, sensitive, tracking } = send;
|
|
267
310
|
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');
|
|
268
311
|
refuseFieldsOutside(send, CODE_FORM, TEMPLATE_FORM);
|
|
269
312
|
if ('string' != typeof subject) throw invalid('invalid_form', 'A send with templateKey needs a subject.', 'subject');
|
|
@@ -289,7 +332,15 @@ function codeContent(send, distinctId) {
|
|
|
289
332
|
replyTo
|
|
290
333
|
] : replyTo
|
|
291
334
|
},
|
|
292
|
-
|
|
335
|
+
...void 0 !== captureEngagement && {
|
|
336
|
+
capture_engagement: captureEngagement
|
|
337
|
+
},
|
|
338
|
+
...void 0 !== sensitive && {
|
|
339
|
+
sensitive
|
|
340
|
+
},
|
|
341
|
+
...void 0 !== tracking && {
|
|
342
|
+
tracking
|
|
343
|
+
},
|
|
293
344
|
...void 0 !== distinctId && {
|
|
294
345
|
distinct_id: distinctId
|
|
295
346
|
}
|
|
@@ -455,6 +506,23 @@ function parseStatusReply({ status, payload, retryAfterMs }) {
|
|
|
455
506
|
reason: emails_text(fields.reason) ?? null
|
|
456
507
|
};
|
|
457
508
|
}
|
|
509
|
+
function parsePreferencesReply({ status, payload, retryAfterMs }) {
|
|
510
|
+
const fields = replyFields(payload);
|
|
511
|
+
if (status < 200 || status >= 300) throw replyError(fields, status, retryAfterMs);
|
|
512
|
+
const to = emails_text(fields.identifier);
|
|
513
|
+
const allMarketing = fields.all_marketing;
|
|
514
|
+
const topics = fields.topics;
|
|
515
|
+
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({
|
|
516
|
+
code: 'api_error',
|
|
517
|
+
message: 'PostHog answered without the preferences.',
|
|
518
|
+
statusCode: status
|
|
519
|
+
});
|
|
520
|
+
return {
|
|
521
|
+
to,
|
|
522
|
+
allMarketing,
|
|
523
|
+
topics: topics
|
|
524
|
+
};
|
|
525
|
+
}
|
|
458
526
|
function replyError(fields, status, retryAfterMs) {
|
|
459
527
|
return new EmailError({
|
|
460
528
|
code: emails_text(fields.code) ?? 'api_error',
|
package/dist/emails/errors.d.ts
CHANGED
|
@@ -14,7 +14,7 @@ export interface EmailErrorParams {
|
|
|
14
14
|
cause?: unknown;
|
|
15
15
|
}
|
|
16
16
|
/**
|
|
17
|
-
* PostHog
|
|
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.
|
package/dist/emails/types.d.ts
CHANGED
|
@@ -41,8 +41,51 @@ interface CodeEmailFields {
|
|
|
41
41
|
* bounced) as events of the recipient. Defaults to `true`. A project whose admin turned
|
|
42
42
|
* engagement capture off captures nothing, whatever the send asks. A template made in PostHog
|
|
43
43
|
* follows the project's setting.
|
|
44
|
+
*
|
|
45
|
+
* @deprecated Use `tracking: { engagement: false }`. It keeps working, but PostHog refuses a
|
|
46
|
+
* send that sets both `captureEngagement` and `tracking`.
|
|
44
47
|
*/
|
|
45
48
|
captureEngagement?: boolean;
|
|
49
|
+
/**
|
|
50
|
+
* Marks the email as sensitive, such as one that carries login links, reset tokens or codes.
|
|
51
|
+
* A sensitive email keeps its links as they are unless `tracking` turns clicks on, leaves its
|
|
52
|
+
* subject off engagement events, and keeps its content out of PostHog's logs.
|
|
53
|
+
*
|
|
54
|
+
* Without it, a send whose `templateKey` matches a template saved in PostHog follows that
|
|
55
|
+
* template's setting, and any other send is sensitive. PostHog refuses `sensitive: false` when
|
|
56
|
+
* the matching template is sensitive.
|
|
57
|
+
*/
|
|
58
|
+
sensitive?: boolean;
|
|
59
|
+
/**
|
|
60
|
+
* What PostHog tracks for this email. Without it, PostHog counts opens with its open pixel,
|
|
61
|
+
* captures engagement events, and counts clicks only when the email isn't sensitive.
|
|
62
|
+
*
|
|
63
|
+
* - `true` turns on opens, clicks and engagement events.
|
|
64
|
+
* - `false` turns off all tracking, including kinds PostHog adds later. PostHog can't count the
|
|
65
|
+
* email's opens or clicks, and captures no engagement events.
|
|
66
|
+
* - An object turns each kind on or off. A key you leave out keeps its default.
|
|
67
|
+
*
|
|
68
|
+
* Turn clicks on for a sensitive email only when its links are safe to send through PostHog's
|
|
69
|
+
* click tracking.
|
|
70
|
+
*/
|
|
71
|
+
tracking?: boolean | EmailTracking;
|
|
72
|
+
}
|
|
73
|
+
/** Which kinds of tracking a send with `templateKey` turns on. */
|
|
74
|
+
export interface EmailTracking {
|
|
75
|
+
/** Counts opens with PostHog's open pixel. Defaults to `true`. */
|
|
76
|
+
opens?: boolean;
|
|
77
|
+
/**
|
|
78
|
+
* Counts clicks by sending the email's links through PostHog's click tracking. Defaults to
|
|
79
|
+
* `false` for a sensitive email and `true` for any other. Needs `opens`: PostHog refuses a send
|
|
80
|
+
* with `opens: false` and `clicks: true`.
|
|
81
|
+
*/
|
|
82
|
+
clicks?: boolean;
|
|
83
|
+
/**
|
|
84
|
+
* Captures the email's engagement events (sent, delivered, opened, clicked, bounced) as events
|
|
85
|
+
* of the recipient. Defaults to `true`. A project whose admin turned engagement capture off
|
|
86
|
+
* captures nothing, whatever the send asks.
|
|
87
|
+
*/
|
|
88
|
+
engagement?: boolean;
|
|
46
89
|
}
|
|
47
90
|
/**
|
|
48
91
|
* A React element, such as `<WelcomeEmail firstName="Ada" />`. Typed by its shape, so
|
|
@@ -150,9 +193,48 @@ export type GetEmailResponse = {
|
|
|
150
193
|
data: null;
|
|
151
194
|
error: EmailError;
|
|
152
195
|
};
|
|
196
|
+
/**
|
|
197
|
+
* Options for `posthog.emails.setPreferences()`. Set `allMarketing`, `topics`, or both.
|
|
198
|
+
*/
|
|
199
|
+
export interface SetEmailPreferencesOptions {
|
|
200
|
+
/**
|
|
201
|
+
* The recipient's email address, exactly as Workflows sends to it. Matching is exact, so `Jane@example.com` and
|
|
202
|
+
* `jane@example.com` are two recipients.
|
|
203
|
+
*/
|
|
204
|
+
to: string;
|
|
205
|
+
/** `false` opts the recipient out of every marketing topic. `true` lifts that opt-out. Applied before `topics`. */
|
|
206
|
+
allMarketing?: boolean;
|
|
207
|
+
/**
|
|
208
|
+
* Topic key to `false` to opt the recipient out of that topic, or `true` to opt them back in. Topic keys are the
|
|
209
|
+
* ones you set under Workflows opt-outs. Opting back in to one marketing topic after an all-marketing opt-out lifts
|
|
210
|
+
* that opt-out, so `allMarketing` becomes `true`, and keeps the other marketing topics opted out. Topics you leave out
|
|
211
|
+
* keep their current choice.
|
|
212
|
+
*/
|
|
213
|
+
topics?: Record<string, boolean>;
|
|
214
|
+
}
|
|
215
|
+
/** A recipient's preferences after the change. */
|
|
216
|
+
export interface EmailPreferences {
|
|
217
|
+
to: string;
|
|
218
|
+
/** `false` when the recipient opted out of all marketing, `true` when they opted back in, `null` when they never chose. */
|
|
219
|
+
allMarketing: boolean | null;
|
|
220
|
+
/** Topic key to `false` (opted out) or `true` (opted in), for every topic the recipient chose. */
|
|
221
|
+
topics: Record<string, boolean>;
|
|
222
|
+
}
|
|
223
|
+
/**
|
|
224
|
+
* What `posthog.emails.setPreferences()` resolves to. Exactly one of `data` and `error` is set.
|
|
225
|
+
* The promise does not reject.
|
|
226
|
+
*/
|
|
227
|
+
export type SetEmailPreferencesResponse = {
|
|
228
|
+
data: EmailPreferences;
|
|
229
|
+
error: null;
|
|
230
|
+
} | {
|
|
231
|
+
data: null;
|
|
232
|
+
error: EmailError;
|
|
233
|
+
};
|
|
153
234
|
/**
|
|
154
235
|
* The `posthog.emails` API: sends transactional email from PostHog email templates or from
|
|
155
|
-
* content your code rendered,
|
|
236
|
+
* content your code rendered, reads the status of each email it sent, and sets a recipient's
|
|
237
|
+
* topic preferences.
|
|
156
238
|
*/
|
|
157
239
|
export interface Emails {
|
|
158
240
|
/**
|
|
@@ -171,6 +253,17 @@ export interface Emails {
|
|
|
171
253
|
* seconds after the send. Network errors, rate limits and an unavailable service are retried.
|
|
172
254
|
*/
|
|
173
255
|
get(id: string): Promise<GetEmailResponse>;
|
|
256
|
+
/**
|
|
257
|
+
* Opt one recipient out of topics, or back in, in one request. PostHog saves the whole change at once. The same
|
|
258
|
+
* change twice ends the same, but a retry that lands after a newer change for the same recipient undoes that
|
|
259
|
+
* change. A failed call may still have saved the change. Workflows sends skip a marketing topic the recipient
|
|
260
|
+
* opted out of.
|
|
261
|
+
*
|
|
262
|
+
* Resolves to `{ data, error }` and does not reject. The error code is `unknown_topic` when a topic key names no
|
|
263
|
+
* topic of the project, and nothing is saved. A plain `not_found` means the PostHog instance has no preferences
|
|
264
|
+
* API yet. Network errors, rate limits and an unavailable service are retried.
|
|
265
|
+
*/
|
|
266
|
+
setPreferences(options: SetEmailPreferencesOptions): Promise<SetEmailPreferencesResponse>;
|
|
174
267
|
}
|
|
175
268
|
export {};
|
|
176
269
|
//# sourceMappingURL=types.d.ts.map
|
|
@@ -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,aA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AE,WAAW,CAAC;IAAC,KAAK,EAAE,IAAI,CAAA;CAAE,GAAG;IAAE,IAAI,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, EmailReactElement, Emails, EmailStatus, EmailWarning, GetEmailResponse, SendCodeEmailOptions, SendEmailBase, SendEmailOptions, SendEmailResponse, SendEmailResult, SendTemplateEmailOptions, TemplateEmailForm, } from './emails/types';
|
|
9
|
+
export type { CodeEmailForm, 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,iBAAiB,EACjB,MAAM,EACN,WAAW,EACX,YAAY,EACZ,gBAAgB,EAChB,oBAAoB,EACpB,aAAa,EACb,gBAAgB,EAChB,iBAAiB,EACjB,eAAe,E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Aa,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"}
|
package/dist/version.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export declare const version = "5.
|
|
1
|
+
export declare const version = "5.71.0";
|
|
2
2
|
//# sourceMappingURL=version.d.ts.map
|
package/dist/version.js
CHANGED
package/dist/version.mjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
const version = "5.
|
|
1
|
+
const version = "5.71.0";
|
|
2
2
|
export { version };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "posthog-node",
|
|
3
|
-
"version": "5.
|
|
3
|
+
"version": "5.71.0",
|
|
4
4
|
"bugs": {
|
|
5
5
|
"url": "https://github.com/PostHog/posthog-js/issues"
|
|
6
6
|
},
|
|
@@ -29,7 +29,7 @@
|
|
|
29
29
|
"module": "dist/entrypoints/index.node.mjs",
|
|
30
30
|
"types": "dist/entrypoints/index.node.d.ts",
|
|
31
31
|
"dependencies": {
|
|
32
|
-
"@posthog/core": "^1.67.
|
|
32
|
+
"@posthog/core": "^1.67.2"
|
|
33
33
|
},
|
|
34
34
|
"devDependencies": {
|
|
35
35
|
"@edge-runtime/vm": "^5.0.0",
|
|
@@ -48,8 +48,8 @@
|
|
|
48
48
|
"rxjs": "^7.8.0",
|
|
49
49
|
"typescript": "7.0.2",
|
|
50
50
|
"vitest": "^1.6.1",
|
|
51
|
-
"@posthog/
|
|
52
|
-
"@posthog
|
|
51
|
+
"@posthog-tooling/tsconfig-base": "1.1.1",
|
|
52
|
+
"@posthog/types": "^1.424.1"
|
|
53
53
|
},
|
|
54
54
|
"peerDependencies": {
|
|
55
55
|
"@opentelemetry/api": "^1.2.0",
|
|
@@ -139,7 +139,6 @@
|
|
|
139
139
|
"prebuild": "node ../../tooling/write-version.mjs",
|
|
140
140
|
"build": "rslib build",
|
|
141
141
|
"dev": "rslib build -w",
|
|
142
|
-
"package": "pnpm pack --out $PACKAGE_DEST/%s.tgz"
|
|
143
|
-
"generate-references": "pnpm exec api-extractor run --config ./api-extractor.jsonc --local && node scripts/generate-docs.mjs"
|
|
142
|
+
"package": "pnpm pack --out $PACKAGE_DEST/%s.tgz"
|
|
144
143
|
}
|
|
145
144
|
}
|
package/src/client.ts
CHANGED
|
@@ -814,14 +814,15 @@ export abstract class PostHogBackendClient extends PostHogCoreStateless implemen
|
|
|
814
814
|
}
|
|
815
815
|
|
|
816
816
|
/**
|
|
817
|
-
* The `posthog.emails` API: sends transactional email from PostHog email templates,
|
|
818
|
-
* the status of each email it sent.
|
|
819
|
-
*
|
|
820
|
-
* Needs `secretKey`, a project secret API key
|
|
821
|
-
* "Send transactional email" preset)
|
|
822
|
-
*
|
|
823
|
-
*
|
|
824
|
-
*
|
|
817
|
+
* The `posthog.emails` API: sends transactional email from PostHog email templates, reads
|
|
818
|
+
* the status of each email it sent, and sets a recipient's topic preferences.
|
|
819
|
+
*
|
|
820
|
+
* Needs `secretKey`, a project secret API key. `send` needs the `transactional_email:write` scope
|
|
821
|
+
* (the "Send transactional email" preset), and `get` needs `transactional_email:read` or
|
|
822
|
+
* `transactional_email:write`. `setPreferences` needs the
|
|
823
|
+
* `messaging_preference:write` scope, which cannot send email. Keys made with `hog_flow:write` still
|
|
824
|
+
* work for all three. Requests go to `appHost`, or to the PostHog Cloud app host of `host`. `send`,
|
|
825
|
+
* `get` and `setPreferences` resolve to `{ data, error }` and do not reject.
|
|
825
826
|
* `data.id` is the queued email's message ID, which `get` takes. A disabled client sends nothing
|
|
826
827
|
* and returns the error `client_disabled`. After `shutdown()`, the client sends nothing and
|
|
827
828
|
* returns the error `client_closed`.
|
|
@@ -841,6 +842,9 @@ export abstract class PostHogBackendClient extends PostHogCoreStateless implemen
|
|
|
841
842
|
* }
|
|
842
843
|
*
|
|
843
844
|
* const status = await client.emails.get(data.id) // later, for example from a job
|
|
845
|
+
*
|
|
846
|
+
* // From a preference center: opt out of one topic, keep the rest
|
|
847
|
+
* await client.emails.setPreferences({ to: 'user@example.com', topics: { newsletter: false } })
|
|
844
848
|
* ```
|
|
845
849
|
*
|
|
846
850
|
* {@label Emails}
|
package/src/emails/emails.ts
CHANGED
|
@@ -10,6 +10,7 @@ import {
|
|
|
10
10
|
import { EmailError } from './errors'
|
|
11
11
|
import type {
|
|
12
12
|
CodeEmailForm,
|
|
13
|
+
EmailPreferences,
|
|
13
14
|
EmailReactElement,
|
|
14
15
|
EmailStatus,
|
|
15
16
|
EmailWarning,
|
|
@@ -20,11 +21,14 @@ import type {
|
|
|
20
21
|
SendEmailResponse,
|
|
21
22
|
SendEmailResult,
|
|
22
23
|
SendTemplateEmailOptions,
|
|
24
|
+
SetEmailPreferencesOptions,
|
|
25
|
+
SetEmailPreferencesResponse,
|
|
23
26
|
TemplateEmailForm,
|
|
24
27
|
} from './types'
|
|
25
28
|
|
|
26
29
|
const SEND_PATH = '/api/projects/@current/messaging/send/email/'
|
|
27
30
|
const STATUS_PATH = '/api/projects/@current/messaging/emails/{messageId}/'
|
|
31
|
+
const PREFERENCES_PATH = '/api/projects/@current/messaging/preferences/'
|
|
28
32
|
const US_APP_HOST = 'https://us.posthog.com'
|
|
29
33
|
const EU_APP_HOST = 'https://eu.posthog.com'
|
|
30
34
|
const CLOUD_APP_HOSTS: Record<string, string> = {
|
|
@@ -66,6 +70,8 @@ const CODE_FIELDS: EveryField<CodeEmailForm> = {
|
|
|
66
70
|
from: true,
|
|
67
71
|
replyTo: true,
|
|
68
72
|
captureEngagement: true,
|
|
73
|
+
sensitive: true,
|
|
74
|
+
tracking: true,
|
|
69
75
|
html: true,
|
|
70
76
|
text: true,
|
|
71
77
|
react: true,
|
|
@@ -118,9 +124,9 @@ interface Reply {
|
|
|
118
124
|
}
|
|
119
125
|
|
|
120
126
|
/**
|
|
121
|
-
* Sends one transactional email per call to the messaging send API on the app host,
|
|
122
|
-
*
|
|
123
|
-
* idempotency key.
|
|
127
|
+
* Sends one transactional email per call to the messaging send API on the app host, reads the
|
|
128
|
+
* status of a sent email, and sets a recipient's topic preferences. Owns the attempt loop, so every
|
|
129
|
+
* attempt of a send carries the same idempotency key.
|
|
124
130
|
*/
|
|
125
131
|
export class EmailSender implements Emails {
|
|
126
132
|
private readonly config: EmailSenderConfig
|
|
@@ -140,6 +146,10 @@ export class EmailSender implements Emails {
|
|
|
140
146
|
return this.track(this.getUntracked(id))
|
|
141
147
|
}
|
|
142
148
|
|
|
149
|
+
setPreferences(options: SetEmailPreferencesOptions): Promise<SetEmailPreferencesResponse> {
|
|
150
|
+
return this.track(this.setPreferencesUntracked(options))
|
|
151
|
+
}
|
|
152
|
+
|
|
143
153
|
private track<T>(pending: Promise<T>): Promise<T> {
|
|
144
154
|
this.inFlight.add(pending)
|
|
145
155
|
void pending.finally(() => this.inFlight.delete(pending))
|
|
@@ -147,7 +157,7 @@ export class EmailSender implements Emails {
|
|
|
147
157
|
}
|
|
148
158
|
|
|
149
159
|
/**
|
|
150
|
-
* Resolves when every send
|
|
160
|
+
* Resolves when every send, status read and preferences change in flight, retries included, has settled.
|
|
151
161
|
* Kept apart from the client's pending-promise queue, so a send in its retry backoff does not hold back `flush()`.
|
|
152
162
|
*/
|
|
153
163
|
async drain(): Promise<void> {
|
|
@@ -204,6 +214,23 @@ export class EmailSender implements Emails {
|
|
|
204
214
|
}
|
|
205
215
|
}
|
|
206
216
|
|
|
217
|
+
private async setPreferencesUntracked(options: SetEmailPreferencesOptions): Promise<SetEmailPreferencesResponse> {
|
|
218
|
+
try {
|
|
219
|
+
const body = preparePreferences(options)
|
|
220
|
+
const { appHost, secretKey } = this.connect(
|
|
221
|
+
'no preferences changed',
|
|
222
|
+
'Setting email preferences needs secretKey, a project secret API key with the messaging_preference:write scope.'
|
|
223
|
+
)
|
|
224
|
+
const headers = this.headers(secretKey, { 'Content-Type': 'application/json' })
|
|
225
|
+
const preferences = await this.withRetries(this.config.maxRetries, async () =>
|
|
226
|
+
parsePreferencesReply(await this.request(appHost + PREFERENCES_PATH, 'POST', headers, body))
|
|
227
|
+
)
|
|
228
|
+
return { data: preferences, error: null }
|
|
229
|
+
} catch (error) {
|
|
230
|
+
return { data: null, error: asEmailError(error, 'Setting the email preferences failed unexpectedly.') }
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
|
|
207
234
|
private connect(nothingDone: string, missingSecretKey: string): { appHost: string; secretKey: string } {
|
|
208
235
|
if (this.hooks.isDisabled()) {
|
|
209
236
|
throw new EmailError({
|
|
@@ -374,6 +401,35 @@ function prepareSend(options: SendEmailOptions, defaultMaxRetries: number): Prep
|
|
|
374
401
|
}
|
|
375
402
|
}
|
|
376
403
|
|
|
404
|
+
function preparePreferences(options: SetEmailPreferencesOptions): string {
|
|
405
|
+
const fallback: Partial<SetEmailPreferencesOptions> = {}
|
|
406
|
+
const { to, allMarketing, topics } = options ?? fallback
|
|
407
|
+
if (typeof to !== 'string' || !to.trim()) {
|
|
408
|
+
throw invalid('invalid_recipient', 'to must be one email address as a nonempty string.', 'to')
|
|
409
|
+
}
|
|
410
|
+
if (allMarketing !== undefined && typeof allMarketing !== 'boolean') {
|
|
411
|
+
throw invalid('invalid_preferences', 'allMarketing must be true or false.', 'allMarketing')
|
|
412
|
+
}
|
|
413
|
+
if (
|
|
414
|
+
topics !== undefined &&
|
|
415
|
+
(typeof topics !== 'object' ||
|
|
416
|
+
topics === null ||
|
|
417
|
+
Array.isArray(topics) ||
|
|
418
|
+
!Object.values(topics).every((value) => typeof value === 'boolean'))
|
|
419
|
+
) {
|
|
420
|
+
throw invalid('invalid_preferences', 'topics must map each topic key to true or false.', 'topics')
|
|
421
|
+
}
|
|
422
|
+
const hasTopics = topics !== undefined && Object.keys(topics).length > 0
|
|
423
|
+
if (allMarketing === undefined && !hasTopics) {
|
|
424
|
+
throw invalid('invalid_preferences', 'Set allMarketing, topics, or both.', 'topics')
|
|
425
|
+
}
|
|
426
|
+
return safeJsonStringify({
|
|
427
|
+
identifier: to,
|
|
428
|
+
...(allMarketing === undefined ? {} : { all_marketing: allMarketing }),
|
|
429
|
+
...(hasTopics ? { topics } : {}),
|
|
430
|
+
})
|
|
431
|
+
}
|
|
432
|
+
|
|
377
433
|
function isRetryCount(value: unknown): value is number {
|
|
378
434
|
return typeof value === 'number' && Number.isInteger(value) && value >= 0
|
|
379
435
|
}
|
|
@@ -408,7 +464,7 @@ function templateContent(send: UncheckedSend, distinctId: string | undefined): R
|
|
|
408
464
|
}
|
|
409
465
|
|
|
410
466
|
function codeContent(send: UncheckedSend, distinctId: string | undefined): Record<string, unknown> {
|
|
411
|
-
const { templateKey, subject, html, text, react, from, replyTo, captureEngagement } = send
|
|
467
|
+
const { templateKey, subject, html, text, react, from, replyTo, captureEngagement, sensitive, tracking } = send
|
|
412
468
|
if (typeof templateKey !== 'string' || !TEMPLATE_KEY_PATTERN.test(templateKey)) {
|
|
413
469
|
throw invalid(
|
|
414
470
|
'invalid_template_key',
|
|
@@ -439,7 +495,9 @@ function codeContent(send: UncheckedSend, distinctId: string | undefined): Recor
|
|
|
439
495
|
...(text !== undefined && { text }),
|
|
440
496
|
...(from !== undefined && { from }),
|
|
441
497
|
...(sendsReplyTo && { reply_to: typeof replyTo === 'string' ? [replyTo] : replyTo }),
|
|
442
|
-
capture_engagement: captureEngagement
|
|
498
|
+
...(captureEngagement !== undefined && { capture_engagement: captureEngagement }),
|
|
499
|
+
...(sensitive !== undefined && { sensitive }),
|
|
500
|
+
...(tracking !== undefined && { tracking }),
|
|
443
501
|
...(distinctId !== undefined && { distinct_id: distinctId }),
|
|
444
502
|
}
|
|
445
503
|
}
|
|
@@ -629,6 +687,31 @@ function parseStatusReply({ status, payload, retryAfterMs }: Reply): EmailStatus
|
|
|
629
687
|
return { id, status: deliveryStatus, createdAt, statusAt, reason: text(fields.reason) ?? null }
|
|
630
688
|
}
|
|
631
689
|
|
|
690
|
+
function parsePreferencesReply({ status, payload, retryAfterMs }: Reply): EmailPreferences {
|
|
691
|
+
const fields = replyFields(payload)
|
|
692
|
+
if (status < 200 || status >= 300) {
|
|
693
|
+
throw replyError(fields, status, retryAfterMs)
|
|
694
|
+
}
|
|
695
|
+
const to = text(fields.identifier)
|
|
696
|
+
const allMarketing = fields.all_marketing
|
|
697
|
+
const topics = fields.topics
|
|
698
|
+
if (
|
|
699
|
+
!to ||
|
|
700
|
+
!(allMarketing === null || typeof allMarketing === 'boolean') ||
|
|
701
|
+
topics === null ||
|
|
702
|
+
typeof topics !== 'object' ||
|
|
703
|
+
Array.isArray(topics) ||
|
|
704
|
+
!Object.values(topics).every((value) => typeof value === 'boolean')
|
|
705
|
+
) {
|
|
706
|
+
throw new EmailError({
|
|
707
|
+
code: 'api_error',
|
|
708
|
+
message: 'PostHog answered without the preferences.',
|
|
709
|
+
statusCode: status,
|
|
710
|
+
})
|
|
711
|
+
}
|
|
712
|
+
return { to, allMarketing, topics: topics as Record<string, boolean> }
|
|
713
|
+
}
|
|
714
|
+
|
|
632
715
|
function replyError(fields: Record<string, unknown>, status: number, retryAfterMs: number | undefined): EmailError {
|
|
633
716
|
return new EmailError({
|
|
634
717
|
code: text(fields.code) ?? 'api_error',
|
|
@@ -648,6 +731,7 @@ function asEmailError(error: unknown, message: string): EmailError {
|
|
|
648
731
|
|
|
649
732
|
function isRetryable(error: EmailError): boolean {
|
|
650
733
|
// A send carries an idempotency key, so a retry can't queue a second email. A status read changes nothing.
|
|
734
|
+
// A preferences change sets each named choice to a value, so repeating it ends the same.
|
|
651
735
|
if (error.statusCode === undefined) {
|
|
652
736
|
return error.code === 'network_error'
|
|
653
737
|
}
|
package/src/emails/errors.ts
CHANGED
|
@@ -26,7 +26,7 @@ export interface EmailErrorParams {
|
|
|
26
26
|
}
|
|
27
27
|
|
|
28
28
|
/**
|
|
29
|
-
* PostHog
|
|
29
|
+
* PostHog refused an email call, or the client could not tell whether it succeeded.
|
|
30
30
|
*
|
|
31
31
|
* Branch on `code`, PostHog's stable error code, or on `name`, a coarse category of the
|
|
32
32
|
* failure. The message never contains the secret key or the request body.
|
package/src/emails/types.ts
CHANGED
|
@@ -44,8 +44,52 @@ interface CodeEmailFields {
|
|
|
44
44
|
* bounced) as events of the recipient. Defaults to `true`. A project whose admin turned
|
|
45
45
|
* engagement capture off captures nothing, whatever the send asks. A template made in PostHog
|
|
46
46
|
* follows the project's setting.
|
|
47
|
+
*
|
|
48
|
+
* @deprecated Use `tracking: { engagement: false }`. It keeps working, but PostHog refuses a
|
|
49
|
+
* send that sets both `captureEngagement` and `tracking`.
|
|
47
50
|
*/
|
|
48
51
|
captureEngagement?: boolean
|
|
52
|
+
/**
|
|
53
|
+
* Marks the email as sensitive, such as one that carries login links, reset tokens or codes.
|
|
54
|
+
* A sensitive email keeps its links as they are unless `tracking` turns clicks on, leaves its
|
|
55
|
+
* subject off engagement events, and keeps its content out of PostHog's logs.
|
|
56
|
+
*
|
|
57
|
+
* Without it, a send whose `templateKey` matches a template saved in PostHog follows that
|
|
58
|
+
* template's setting, and any other send is sensitive. PostHog refuses `sensitive: false` when
|
|
59
|
+
* the matching template is sensitive.
|
|
60
|
+
*/
|
|
61
|
+
sensitive?: boolean
|
|
62
|
+
/**
|
|
63
|
+
* What PostHog tracks for this email. Without it, PostHog counts opens with its open pixel,
|
|
64
|
+
* captures engagement events, and counts clicks only when the email isn't sensitive.
|
|
65
|
+
*
|
|
66
|
+
* - `true` turns on opens, clicks and engagement events.
|
|
67
|
+
* - `false` turns off all tracking, including kinds PostHog adds later. PostHog can't count the
|
|
68
|
+
* email's opens or clicks, and captures no engagement events.
|
|
69
|
+
* - An object turns each kind on or off. A key you leave out keeps its default.
|
|
70
|
+
*
|
|
71
|
+
* Turn clicks on for a sensitive email only when its links are safe to send through PostHog's
|
|
72
|
+
* click tracking.
|
|
73
|
+
*/
|
|
74
|
+
tracking?: boolean | EmailTracking
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
/** Which kinds of tracking a send with `templateKey` turns on. */
|
|
78
|
+
export interface EmailTracking {
|
|
79
|
+
/** Counts opens with PostHog's open pixel. Defaults to `true`. */
|
|
80
|
+
opens?: boolean
|
|
81
|
+
/**
|
|
82
|
+
* Counts clicks by sending the email's links through PostHog's click tracking. Defaults to
|
|
83
|
+
* `false` for a sensitive email and `true` for any other. Needs `opens`: PostHog refuses a send
|
|
84
|
+
* with `opens: false` and `clicks: true`.
|
|
85
|
+
*/
|
|
86
|
+
clicks?: boolean
|
|
87
|
+
/**
|
|
88
|
+
* Captures the email's engagement events (sent, delivered, opened, clicked, bounced) as events
|
|
89
|
+
* of the recipient. Defaults to `true`. A project whose admin turned engagement capture off
|
|
90
|
+
* captures nothing, whatever the send asks.
|
|
91
|
+
*/
|
|
92
|
+
engagement?: boolean
|
|
49
93
|
}
|
|
50
94
|
|
|
51
95
|
/**
|
|
@@ -147,9 +191,45 @@ export interface EmailStatus {
|
|
|
147
191
|
*/
|
|
148
192
|
export type GetEmailResponse = { data: EmailStatus; error: null } | { data: null; error: EmailError }
|
|
149
193
|
|
|
194
|
+
/**
|
|
195
|
+
* Options for `posthog.emails.setPreferences()`. Set `allMarketing`, `topics`, or both.
|
|
196
|
+
*/
|
|
197
|
+
export interface SetEmailPreferencesOptions {
|
|
198
|
+
/**
|
|
199
|
+
* The recipient's email address, exactly as Workflows sends to it. Matching is exact, so `Jane@example.com` and
|
|
200
|
+
* `jane@example.com` are two recipients.
|
|
201
|
+
*/
|
|
202
|
+
to: string
|
|
203
|
+
/** `false` opts the recipient out of every marketing topic. `true` lifts that opt-out. Applied before `topics`. */
|
|
204
|
+
allMarketing?: boolean
|
|
205
|
+
/**
|
|
206
|
+
* Topic key to `false` to opt the recipient out of that topic, or `true` to opt them back in. Topic keys are the
|
|
207
|
+
* ones you set under Workflows opt-outs. Opting back in to one marketing topic after an all-marketing opt-out lifts
|
|
208
|
+
* that opt-out, so `allMarketing` becomes `true`, and keeps the other marketing topics opted out. Topics you leave out
|
|
209
|
+
* keep their current choice.
|
|
210
|
+
*/
|
|
211
|
+
topics?: Record<string, boolean>
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
/** A recipient's preferences after the change. */
|
|
215
|
+
export interface EmailPreferences {
|
|
216
|
+
to: string
|
|
217
|
+
/** `false` when the recipient opted out of all marketing, `true` when they opted back in, `null` when they never chose. */
|
|
218
|
+
allMarketing: boolean | null
|
|
219
|
+
/** Topic key to `false` (opted out) or `true` (opted in), for every topic the recipient chose. */
|
|
220
|
+
topics: Record<string, boolean>
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
/**
|
|
224
|
+
* What `posthog.emails.setPreferences()` resolves to. Exactly one of `data` and `error` is set.
|
|
225
|
+
* The promise does not reject.
|
|
226
|
+
*/
|
|
227
|
+
export type SetEmailPreferencesResponse = { data: EmailPreferences; error: null } | { data: null; error: EmailError }
|
|
228
|
+
|
|
150
229
|
/**
|
|
151
230
|
* The `posthog.emails` API: sends transactional email from PostHog email templates or from
|
|
152
|
-
* content your code rendered,
|
|
231
|
+
* content your code rendered, reads the status of each email it sent, and sets a recipient's
|
|
232
|
+
* topic preferences.
|
|
153
233
|
*/
|
|
154
234
|
export interface Emails {
|
|
155
235
|
/**
|
|
@@ -169,4 +249,16 @@ export interface Emails {
|
|
|
169
249
|
* seconds after the send. Network errors, rate limits and an unavailable service are retried.
|
|
170
250
|
*/
|
|
171
251
|
get(id: string): Promise<GetEmailResponse>
|
|
252
|
+
|
|
253
|
+
/**
|
|
254
|
+
* Opt one recipient out of topics, or back in, in one request. PostHog saves the whole change at once. The same
|
|
255
|
+
* change twice ends the same, but a retry that lands after a newer change for the same recipient undoes that
|
|
256
|
+
* change. A failed call may still have saved the change. Workflows sends skip a marketing topic the recipient
|
|
257
|
+
* opted out of.
|
|
258
|
+
*
|
|
259
|
+
* Resolves to `{ data, error }` and does not reject. The error code is `unknown_topic` when a topic key names no
|
|
260
|
+
* topic of the project, and nothing is saved. A plain `not_found` means the PostHog instance has no preferences
|
|
261
|
+
* API yet. Network errors, rate limits and an unavailable service are retried.
|
|
262
|
+
*/
|
|
263
|
+
setPreferences(options: SetEmailPreferencesOptions): Promise<SetEmailPreferencesResponse>
|
|
172
264
|
}
|
package/src/exports.ts
CHANGED
|
@@ -10,9 +10,11 @@ export type { EmailErrorName } from './emails/errors'
|
|
|
10
10
|
export type {
|
|
11
11
|
CodeEmailForm,
|
|
12
12
|
EmailDeliveryStatus,
|
|
13
|
+
EmailPreferences,
|
|
13
14
|
EmailReactElement,
|
|
14
15
|
Emails,
|
|
15
16
|
EmailStatus,
|
|
17
|
+
EmailTracking,
|
|
16
18
|
EmailWarning,
|
|
17
19
|
GetEmailResponse,
|
|
18
20
|
SendCodeEmailOptions,
|
|
@@ -21,6 +23,8 @@ export type {
|
|
|
21
23
|
SendEmailResponse,
|
|
22
24
|
SendEmailResult,
|
|
23
25
|
SendTemplateEmailOptions,
|
|
26
|
+
SetEmailPreferencesOptions,
|
|
27
|
+
SetEmailPreferencesResponse,
|
|
24
28
|
TemplateEmailForm,
|
|
25
29
|
} from './emails/types'
|
|
26
30
|
export type {
|
package/src/version.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const version = "5.
|
|
1
|
+
export const version = "5.71.0"
|