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 +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 +129 -6
- package/dist/emails/emails.mjs +129 -6
- package/dist/emails/errors.d.ts +1 -1
- package/dist/emails/types.d.ts +75 -4
- 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 +12 -5
- package/src/client.ts +12 -8
- package/src/emails/emails.ts +174 -11
- package/src/emails/errors.ts +1 -1
- package/src/emails/types.ts +78 -6
- package/src/exports.ts +4 -0
- package/src/version.ts +1 -1
package/src/emails/types.ts
CHANGED
|
@@ -49,17 +49,41 @@ interface CodeEmailFields {
|
|
|
49
49
|
}
|
|
50
50
|
|
|
51
51
|
/**
|
|
52
|
-
*
|
|
53
|
-
*
|
|
54
|
-
* the `html`.
|
|
52
|
+
* A React element, such as `<WelcomeEmail firstName="Ada" />`. Typed by its shape, so
|
|
53
|
+
* posthog-node needs no React types.
|
|
55
54
|
*/
|
|
56
|
-
export
|
|
55
|
+
export interface EmailReactElement {
|
|
56
|
+
type: unknown
|
|
57
|
+
props: unknown
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* Email content from your code, named by a key: `html`, `text` or both, or a `react` element
|
|
62
|
+
* the client renders. PostHog sends it as is and never stores it. PostHog derives a missing
|
|
63
|
+
* `text` from the `html`.
|
|
64
|
+
*/
|
|
65
|
+
export type CodeEmailForm = CodeEmailFields &
|
|
66
|
+
(
|
|
67
|
+
| { html: string; text?: string; react?: never }
|
|
68
|
+
| { html?: string; text: string; react?: never }
|
|
69
|
+
| {
|
|
70
|
+
/**
|
|
71
|
+
* A React Email element. The client renders it into `html`, and into `text` when the
|
|
72
|
+
* send has none. Needs the `@react-email/render` package installed next to posthog-node.
|
|
73
|
+
* The client renders the element after `send()` returns, so give each send its own
|
|
74
|
+
* element and props, and don't change them while the send is pending.
|
|
75
|
+
*/
|
|
76
|
+
react: EmailReactElement
|
|
77
|
+
text?: string
|
|
78
|
+
html?: never
|
|
79
|
+
}
|
|
80
|
+
)
|
|
57
81
|
|
|
58
82
|
type Without<T> = { [K in keyof T]?: never }
|
|
59
83
|
|
|
60
84
|
export type SendTemplateEmailOptions = SendEmailBase &
|
|
61
85
|
TemplateEmailForm &
|
|
62
|
-
Without<CodeEmailFields & { html: string; text: string }>
|
|
86
|
+
Without<CodeEmailFields & { html: string; text: string; react: EmailReactElement }>
|
|
63
87
|
|
|
64
88
|
export type SendCodeEmailOptions = SendEmailBase & CodeEmailForm & Without<TemplateEmailForm>
|
|
65
89
|
|
|
@@ -123,9 +147,45 @@ export interface EmailStatus {
|
|
|
123
147
|
*/
|
|
124
148
|
export type GetEmailResponse = { data: EmailStatus; error: null } | { data: null; error: EmailError }
|
|
125
149
|
|
|
150
|
+
/**
|
|
151
|
+
* Options for `posthog.emails.setPreferences()`. Set `allMarketing`, `topics`, or both.
|
|
152
|
+
*/
|
|
153
|
+
export interface SetEmailPreferencesOptions {
|
|
154
|
+
/**
|
|
155
|
+
* The recipient's email address, exactly as Workflows sends to it. Matching is exact, so `Jane@example.com` and
|
|
156
|
+
* `jane@example.com` are two recipients.
|
|
157
|
+
*/
|
|
158
|
+
to: string
|
|
159
|
+
/** `false` opts the recipient out of every marketing topic. `true` lifts that opt-out. Applied before `topics`. */
|
|
160
|
+
allMarketing?: boolean
|
|
161
|
+
/**
|
|
162
|
+
* Topic key to `false` to opt the recipient out of that topic, or `true` to opt them back in. Topic keys are the
|
|
163
|
+
* ones you set under Workflows opt-outs. Opting back in to one marketing topic after an all-marketing opt-out lifts
|
|
164
|
+
* that opt-out, so `allMarketing` becomes `true`, and keeps the other marketing topics opted out. Topics you leave out
|
|
165
|
+
* keep their current choice.
|
|
166
|
+
*/
|
|
167
|
+
topics?: Record<string, boolean>
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
/** A recipient's preferences after the change. */
|
|
171
|
+
export interface EmailPreferences {
|
|
172
|
+
to: string
|
|
173
|
+
/** `false` when the recipient opted out of all marketing, `true` when they opted back in, `null` when they never chose. */
|
|
174
|
+
allMarketing: boolean | null
|
|
175
|
+
/** Topic key to `false` (opted out) or `true` (opted in), for every topic the recipient chose. */
|
|
176
|
+
topics: Record<string, boolean>
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
/**
|
|
180
|
+
* What `posthog.emails.setPreferences()` resolves to. Exactly one of `data` and `error` is set.
|
|
181
|
+
* The promise does not reject.
|
|
182
|
+
*/
|
|
183
|
+
export type SetEmailPreferencesResponse = { data: EmailPreferences; error: null } | { data: null; error: EmailError }
|
|
184
|
+
|
|
126
185
|
/**
|
|
127
186
|
* The `posthog.emails` API: sends transactional email from PostHog email templates or from
|
|
128
|
-
* content your code rendered,
|
|
187
|
+
* content your code rendered, reads the status of each email it sent, and sets a recipient's
|
|
188
|
+
* topic preferences.
|
|
129
189
|
*/
|
|
130
190
|
export interface Emails {
|
|
131
191
|
/**
|
|
@@ -145,4 +205,16 @@ export interface Emails {
|
|
|
145
205
|
* seconds after the send. Network errors, rate limits and an unavailable service are retried.
|
|
146
206
|
*/
|
|
147
207
|
get(id: string): Promise<GetEmailResponse>
|
|
208
|
+
|
|
209
|
+
/**
|
|
210
|
+
* Opt one recipient out of topics, or back in, in one request. PostHog saves the whole change at once. The same
|
|
211
|
+
* change twice ends the same, but a retry that lands after a newer change for the same recipient undoes that
|
|
212
|
+
* change. A failed call may still have saved the change. Workflows sends skip a marketing topic the recipient
|
|
213
|
+
* opted out of.
|
|
214
|
+
*
|
|
215
|
+
* Resolves to `{ data, error }` and does not reject. The error code is `unknown_topic` when a topic key names no
|
|
216
|
+
* topic of the project, and nothing is saved. A plain `not_found` means the PostHog instance has no preferences
|
|
217
|
+
* API yet. Network errors, rate limits and an unavailable service are retried.
|
|
218
|
+
*/
|
|
219
|
+
setPreferences(options: SetEmailPreferencesOptions): Promise<SetEmailPreferencesResponse>
|
|
148
220
|
}
|
package/src/exports.ts
CHANGED
|
@@ -10,6 +10,8 @@ export type { EmailErrorName } from './emails/errors'
|
|
|
10
10
|
export type {
|
|
11
11
|
CodeEmailForm,
|
|
12
12
|
EmailDeliveryStatus,
|
|
13
|
+
EmailPreferences,
|
|
14
|
+
EmailReactElement,
|
|
13
15
|
Emails,
|
|
14
16
|
EmailStatus,
|
|
15
17
|
EmailWarning,
|
|
@@ -20,6 +22,8 @@ export type {
|
|
|
20
22
|
SendEmailResponse,
|
|
21
23
|
SendEmailResult,
|
|
22
24
|
SendTemplateEmailOptions,
|
|
25
|
+
SetEmailPreferencesOptions,
|
|
26
|
+
SetEmailPreferencesResponse,
|
|
23
27
|
TemplateEmailForm,
|
|
24
28
|
} from './emails/types'
|
|
25
29
|
export type {
|
package/src/version.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const version = "5.
|
|
1
|
+
export const version = "5.70.0"
|