From 3b82c37cada828909b5f980bb27dda50112b09e5 Mon Sep 17 00:00:00 2001 From: Wenxi Zeng Date: Fri, 11 Oct 2024 14:09:57 -0500 Subject: [PATCH] fix: check enrichment closure type before calling it (#1012) Co-authored-by: Wenxi Zeng --- packages/core/src/timeline.ts | 2 +- packages/core/src/types.ts | 10 +++++----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/packages/core/src/timeline.ts b/packages/core/src/timeline.ts index 533fc77a..a0c94aa4 100644 --- a/packages/core/src/timeline.ts +++ b/packages/core/src/timeline.ts @@ -75,7 +75,7 @@ export class Timeline { if (key !== PluginType.destination) { if (result === undefined) { return; - } else if (key === PluginType.enrichment && pluginResult?.enrichment) { + } else if (key === PluginType.enrichment && pluginResult?.enrichment && typeof pluginResult.enrichment === 'function') { result = pluginResult.enrichment(pluginResult); } else { result = pluginResult; diff --git a/packages/core/src/types.ts b/packages/core/src/types.ts index 65d51377..e58c64ef 100644 --- a/packages/core/src/types.ts +++ b/packages/core/src/types.ts @@ -153,12 +153,12 @@ export type Config = { }; export type ClientMethods = { - screen: (name: string, properties?: JsonMap) => Promise; - track: (event: string, properties?: JsonMap) => Promise; - identify: (userId?: string, userTraits?: UserTraits) => Promise; + screen: (name: string, properties?: JsonMap, enrichment?: EnrichmentClosure) => Promise; + track: (event: string, properties?: JsonMap, enrichment?: EnrichmentClosure) => Promise; + identify: (userId?: string, userTraits?: UserTraits, enrichment?: EnrichmentClosure) => Promise; flush: () => Promise; - group: (groupId: string, groupTraits?: GroupTraits) => Promise; - alias: (newUserId: string) => Promise; + group: (groupId: string, groupTraits?: GroupTraits, enrichment?: EnrichmentClosure) => Promise; + alias: (newUserId: string, enrichment?: EnrichmentClosure) => Promise; reset: (resetAnonymousId?: boolean) => Promise; };