posthog-node 5.60.0 → 5.61.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.
@@ -67,10 +67,11 @@ function setCustomErrorPrototype(error: Error, constructor: new (message: string
67
67
  }
68
68
 
69
69
  class RequiresServerEvaluation extends Error {
70
- // Server-side data such as a static cohort is never available locally.
71
- readonly reason: UnresolvedFlagReason = 'unsupported_definition'
72
-
73
- constructor(message: string) {
70
+ constructor(
71
+ message: string,
72
+ // Server-side data such as a static cohort is never available locally.
73
+ readonly reason: UnresolvedFlagReason = 'unsupported_definition'
74
+ ) {
74
75
  super(message)
75
76
  setCustomErrorPrototype(this, RequiresServerEvaluation)
76
77
  }
@@ -551,6 +552,14 @@ class FeatureFlagsPoller {
551
552
  const depResult = await this.computeFlagValueLocally(depFlag, evaluationContext)
552
553
  evaluationCache[depFlagKey] = depResult
553
554
  } catch (error) {
555
+ // Only the server knows this dependency's value, and that value can decide which
556
+ // condition of the dependent flag matches, so the dependent flag falls back too.
557
+ if (error instanceof RequiresServerEvaluation) {
558
+ throw new RequiresServerEvaluation(
559
+ `Flag dependency '${depFlagKey}' for flag '${targetFlagKey}' requires server evaluation: ${error.message}`,
560
+ 'unresolved_dependency'
561
+ )
562
+ }
554
563
  throw preserveRegexUncertainty(
555
564
  new InconclusiveMatchError(
556
565
  `Error evaluating flag dependency '${depFlagKey}' for flag '${targetFlagKey}': ${error}`,
@@ -680,8 +689,19 @@ class FeatureFlagsPoller {
680
689
  }
681
690
  } catch (e) {
682
691
  if (e instanceof RequiresServerEvaluation) {
683
- // Static cohort or other missing server-side data - must fallback to API
684
- throw e
692
+ // Static cohort or other missing server-side data - must fallback to API.
693
+ // The fallback skips later conditions, so a higher reason in them comes from the definition.
694
+ let definitionReason: UnresolvedFlagReason | undefined
695
+ try {
696
+ definitionReason = getDefinitionUnresolvedReason(flag, evaluationContext.definitions!)
697
+ } catch {
698
+ // A malformed definition must not turn the server fallback into an evaluation error.
699
+ }
700
+ const reason = pickUnresolvedReason(
701
+ pickUnresolvedReason(inconclusiveReason, e.reason),
702
+ definitionReason ?? e.reason
703
+ )
704
+ throw reason === e.reason ? e : new RequiresServerEvaluation(e.message, reason)
685
705
  } else if (e instanceof InconclusiveMatchError) {
686
706
  // Evaluation error (bad regex, invalid date, missing property, etc.)
687
707
  // Track that we had an inconclusive match, but try other conditions
@@ -793,6 +813,11 @@ class FeatureFlagsPoller {
793
813
  inconclusiveReason = pickUnresolvedReason(inconclusiveReason, e.reason)
794
814
  continue
795
815
  }
816
+ // After a filter that could not be checked, stop the condition there as inconclusive,
817
+ // so an unexpected error does not stop later conditions from resolving the flag.
818
+ if (inconclusiveReason !== undefined) {
819
+ break
820
+ }
796
821
  throw e
797
822
  }
798
823
 
package/src/types.ts CHANGED
@@ -15,6 +15,7 @@ import type {
15
15
  } from '@posthog/core'
16
16
  import { ContextData, ContextOptions } from './extensions/context/types'
17
17
 
18
+ import type { Emails } from './emails/types'
18
19
  import type { FeatureFlagEvaluations } from './feature-flag-evaluations'
19
20
  import type { FlagDefinitionCacheInput, FlagDefinitionCacheProvider } from './extensions/feature-flags/cache'
20
21
 
@@ -229,12 +230,15 @@ export type PostHogOptions = Omit<PostHogCoreOptions, 'before_send' | 'flushInte
229
230
  */
230
231
  traces?: TracesConfig
231
232
  /**
232
- * Credential for fetching local feature flag definitions and decrypting remote config.
233
+ * Credential for fetching local feature flag definitions, decrypting remote config and
234
+ * sending email.
233
235
  *
234
236
  * Accepts either a Personal API Key (`phx_...`) or a Project Secret API Key (`phs_...`).
235
237
  * Local evaluation can also use definitions from `flagDefinitionCacheProvider` without
236
238
  * this credential. Remote config payload decryption via `getRemoteConfigPayload`
237
- * still requires it. Prefer this over the deprecated
239
+ * still requires it. `emails.send` needs a Project Secret API Key with the
240
+ * `hog_flow:write` scope; set `enableLocalEvaluation: false` when the key is only for email.
241
+ * Prefer this over the deprecated
238
242
  * `personalApiKey` option; when both are set, `secretKey` takes precedence.
239
243
  *
240
244
  * @example
@@ -247,6 +251,28 @@ export type PostHogOptions = Omit<PostHogCoreOptions, 'before_send' | 'flushInte
247
251
  * @deprecated Use `secretKey` instead.
248
252
  */
249
253
  personalApiKey?: string
254
+ /**
255
+ * Your PostHog app host, such as `https://posthog.example.com`. `emails.send` sends there.
256
+ *
257
+ * Needed only when `host` is not PostHog Cloud, for example a reverse proxy, which must not
258
+ * receive the secret key. On PostHog Cloud, the client derives `https://us.posthog.com` or
259
+ * `https://eu.posthog.com` from `host`.
260
+ */
261
+ appHost?: string
262
+ /**
263
+ * Timeout in milliseconds for each `emails.send` request.
264
+ *
265
+ * @default 15000
266
+ */
267
+ emailRequestTimeoutMs?: number
268
+ /**
269
+ * Number of retries for an `emails.send` after a network error, a rate limit, or an
270
+ * unavailable service. Every retry sends the same idempotency key. Set to 0 when a job
271
+ * runner already retries the send.
272
+ *
273
+ * @default 2
274
+ */
275
+ emailRequestMaxRetries?: number
250
276
  /**
251
277
  * Redact prompts, outputs and error details from every event that the PostHog AI
252
278
  * integrations (`@posthog/ai`) capture with this client. Per-call privacy settings
@@ -922,6 +948,12 @@ export interface IPostHog {
922
948
  */
923
949
  readonly metrics: Metrics
924
950
 
951
+ /**
952
+ * @description The `posthog.emails` API: sends transactional email from PostHog email templates.
953
+ * Needs `secretKey`, a project secret API key with the `hog_flow:write` scope.
954
+ */
955
+ readonly emails: Emails
956
+
925
957
  /**
926
958
  * @description Starts a span without making it active, for work that can't wrap a callback.
927
959
  * Prefer `withSpan`. Always returns a handle — an inert one when tracing is off — so calling
package/src/version.ts CHANGED
@@ -1 +1 @@
1
- export const version = "5.60.0"
1
+ export const version = "5.61.0"