posthog-node 5.71.0 → 5.72.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.
@@ -35,7 +35,7 @@ export class EmailError extends Error {
35
35
  override name: EmailErrorName
36
36
  /** PostHog's error code, such as `quota_limited`, or an SDK code such as `network_error`. */
37
37
  readonly code: string
38
- /** The HTTP status, when PostHog answered. */
38
+ /** The HTTP status, when PostHog or its file storage answered. */
39
39
  readonly statusCode?: number
40
40
  readonly why?: string
41
41
  readonly fix?: string
@@ -58,6 +58,8 @@ export class EmailError extends Error {
58
58
  }
59
59
  }
60
60
 
61
+ const ATTACHMENT_LIMIT_CODES: ReadonlySet<string> = new Set(['too_many_attachments', 'message_too_large'])
62
+
61
63
  function emailErrorName(status: number | undefined, code: string): EmailErrorName {
62
64
  if (code === 'missing_secret_key' || status === 401) {
63
65
  return 'missing_api_key'
@@ -66,7 +68,10 @@ function emailErrorName(status: number | undefined, code: string): EmailErrorNam
66
68
  if (code === 'network_error') {
67
69
  return 'service_unavailable'
68
70
  }
69
- return code.startsWith('invalid_') ? 'validation_error' : 'application_error'
71
+ return code.startsWith('invalid_') || ATTACHMENT_LIMIT_CODES.has(code) ? 'validation_error' : 'application_error'
72
+ }
73
+ if (code === 'attachment_upload_failed') {
74
+ return status >= 500 ? 'service_unavailable' : 'application_error'
70
75
  }
71
76
  switch (status) {
72
77
  case 400:
@@ -39,6 +39,16 @@ interface CodeEmailFields {
39
39
  /** A verified sender, such as `'Acme <security@example.com>'`. Without it, the project's default sender. */
40
40
  from?: string
41
41
  replyTo?: string | string[]
42
+ /** Bare addresses, such as `'finance@example.com'`, that get a copy. */
43
+ cc?: string | string[]
44
+ /** Bare addresses that get a copy the other recipients never see. */
45
+ bcc?: string | string[]
46
+ /**
47
+ * Files sent with the email: at most 10, and at most 40 MB for the whole email after Base64
48
+ * encoding, about 29 MB of files. The SDK checks both before any request. It uploads each file
49
+ * PostHog doesn't have yet, then sends the email. When an upload fails, it sends nothing.
50
+ */
51
+ attachments?: EmailAttachment[]
42
52
  /**
43
53
  * Whether PostHog captures the email's engagement events (sent, delivered, opened, clicked,
44
54
  * bounced) as events of the recipient. Defaults to `true`. A project whose admin turned
@@ -92,6 +102,20 @@ export interface EmailTracking {
92
102
  engagement?: boolean
93
103
  }
94
104
 
105
+ /** A file sent with the email. */
106
+ export interface EmailAttachment {
107
+ /** The name the recipient sees, such as `'invoice.pdf'`. */
108
+ filename: string
109
+ /** The file's bytes, or its content already Base64 encoded. At least one byte. */
110
+ content: Uint8Array | string
111
+ /** A MIME type, such as `'application/pdf'`. */
112
+ contentType?: string
113
+ /** Shows the file inline where the HTML has `<img src="cid:...">` with this id. */
114
+ contentId?: string
115
+ /** PostHog can't fetch a file from a path or URL: read the file and pass its `content`. */
116
+ path?: never
117
+ }
118
+
95
119
  /**
96
120
  * A React element, such as `<WelcomeEmail firstName="Ada" />`. Typed by its shape, so
97
121
  * posthog-node needs no React types.
package/src/exports.ts CHANGED
@@ -9,6 +9,7 @@ export { EmailError } from './emails/errors'
9
9
  export type { EmailErrorName } from './emails/errors'
10
10
  export type {
11
11
  CodeEmailForm,
12
+ EmailAttachment,
12
13
  EmailDeliveryStatus,
13
14
  EmailPreferences,
14
15
  EmailReactElement,
package/src/types.ts CHANGED
@@ -276,7 +276,8 @@ export type PostHogOptions = Omit<PostHogCoreOptions, 'before_send' | 'flushInte
276
276
  */
277
277
  appHost?: string
278
278
  /**
279
- * Timeout in milliseconds for each `emails.send` request.
279
+ * Timeout in milliseconds for each `emails.send` request. Each attachment upload is one request,
280
+ * so raise it when large files upload slowly.
280
281
  *
281
282
  * @default 15000
282
283
  */
package/src/version.ts CHANGED
@@ -1 +1 @@
1
- export const version = "5.71.0"
1
+ export const version = "5.72.0"