@walkeros/web-destination-segment 3.3.0-next-1776098542393

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.
@@ -0,0 +1,141 @@
1
+ import { Destination as Destination$1, Mapping as Mapping$1 } from '@walkeros/core';
2
+ import { DestinationWeb } from '@walkeros/web-core';
3
+ import { InitOptions, AnalyticsBrowserSettings } from '@segment/analytics-next';
4
+
5
+ /**
6
+ * Destination-level settings.
7
+ *
8
+ * Extends Segment's `InitOptions` (minus the `group` key which clashes with
9
+ * walkerOS's own `group` mapping) so every passthrough option (cookie,
10
+ * storage, integrations, plan, etc.) keeps IntelliSense intact. walkerOS
11
+ * adds:
12
+ * - `apiKey` (required) — maps to `writeKey` in `AnalyticsBrowser.load()`
13
+ * - `identify` — destination-level identity mapping (Segment `identify()`)
14
+ * - `group` — destination-level group mapping (Segment `group()`)
15
+ * - `include` — event sections flattened into track `properties`
16
+ * - `consent` — walkerOS consent key → Segment category name mapping
17
+ * - `_state` — runtime state (not user-facing, mutated by init/push)
18
+ */
19
+ interface Settings extends Omit<InitOptions, 'group'> {
20
+ /** Segment write key. Maps to `writeKey` in the load() settings arg. */
21
+ apiKey: string;
22
+ /** walkerOS mapping value resolving to an identity object (userId, traits, anonymousId). */
23
+ identify?: Mapping$1.Value;
24
+ /** walkerOS mapping value resolving to a group object (groupId, traits). */
25
+ group?: Mapping$1.Value;
26
+ /**
27
+ * Mapping from walkerOS consent keys → Segment `categoryPreferences` keys.
28
+ * Example: { marketing: "Advertising", analytics: "Analytics" }
29
+ * If omitted, walkerOS keys are forwarded 1:1.
30
+ */
31
+ consent?: Record<string, string>;
32
+ /** Runtime state — populated by init() and mutated by push(). Not user-facing. */
33
+ _state?: RuntimeState;
34
+ }
35
+ interface RuntimeState {
36
+ /** Last-set identity values, used to skip redundant identify() calls. */
37
+ lastIdentity?: {
38
+ userId?: string;
39
+ anonymousId?: string;
40
+ traitsHash?: string;
41
+ };
42
+ /** Last-set group assignment, used to skip redundant group() calls. */
43
+ lastGroup?: {
44
+ groupId?: string;
45
+ traitsHash?: string;
46
+ };
47
+ /** Holds the AnalyticsBrowser instance created in init(). */
48
+ analytics?: SegmentAnalytics;
49
+ /** True once load() has been called (may be deferred pending consent). */
50
+ loaded?: boolean;
51
+ }
52
+ type InitSettings = Partial<Settings>;
53
+ /**
54
+ * Per-rule mapping settings. Every feature here is a walkerOS mapping
55
+ * value resolved via getMappingValue(). The resolved object's keys drive
56
+ * which Segment SDK methods to call.
57
+ */
58
+ interface Mapping {
59
+ identify?: Mapping$1.Value;
60
+ group?: Mapping$1.Value;
61
+ page?: Mapping$1.Value | boolean;
62
+ reset?: Mapping$1.Value | boolean;
63
+ }
64
+ /**
65
+ * Segment SDK surface — the subset of @segment/analytics-next the
66
+ * destination actually uses. Mirrors the AnalyticsBrowser instance shape
67
+ * so tests can mock each method individually via env.analytics.
68
+ */
69
+ interface SegmentAnalytics {
70
+ track: (event: string, properties?: Record<string, unknown>, options?: SegmentEventOptions) => Promise<unknown> | void;
71
+ identify: (userId?: string | Record<string, unknown>, traits?: Record<string, unknown>, options?: SegmentEventOptions) => Promise<unknown> | void;
72
+ group: (groupId: string, traits?: Record<string, unknown>, options?: SegmentEventOptions) => Promise<unknown> | void;
73
+ page: (category?: string | null, name?: string | null, properties?: Record<string, unknown>, options?: SegmentEventOptions) => Promise<unknown> | void;
74
+ alias: (to: string, from?: string, options?: SegmentEventOptions) => Promise<unknown> | void;
75
+ reset: () => Promise<unknown> | void;
76
+ setAnonymousId: (id: string) => Promise<unknown> | void;
77
+ }
78
+ /**
79
+ * Segment event options — the fourth argument to track/identify/group/page
80
+ * that carries context and integration overrides. The destination uses
81
+ * this to stamp consent context on every event.
82
+ */
83
+ interface SegmentEventOptions {
84
+ context?: {
85
+ consent?: {
86
+ categoryPreferences?: Record<string, boolean>;
87
+ };
88
+ [key: string]: unknown;
89
+ };
90
+ integrations?: Record<string, boolean | Record<string, unknown>>;
91
+ }
92
+ /**
93
+ * The module namespace used for `env?.analytics ?? realSegment`.
94
+ * AnalyticsBrowser is the class; tests mock with a factory that returns
95
+ * an object matching SegmentAnalytics.
96
+ *
97
+ * Task 1 verified: `AnalyticsBrowser.load(settings, options)` returns an
98
+ * `AnalyticsBrowser` instance **synchronously**. The instance buffers
99
+ * method calls until the internal load promise resolves.
100
+ */
101
+ interface SegmentSDK {
102
+ load: (settings: AnalyticsBrowserSettings, options?: InitOptions) => SegmentAnalytics;
103
+ }
104
+ /**
105
+ * Env — optional SDK override. Production leaves this undefined and the
106
+ * destination falls back to the real @segment/analytics-next module.
107
+ * Tests provide a mock via env.analytics = { ... }.
108
+ */
109
+ interface Env extends DestinationWeb.Env {
110
+ analytics?: SegmentSDK;
111
+ }
112
+ type Types = Destination$1.Types<Settings, Mapping, Env, InitSettings>;
113
+ type Destination = DestinationWeb.Destination<Types>;
114
+ type Config = DestinationWeb.Config<Types>;
115
+ interface SegmentDestination extends Destination {
116
+ env?: Env;
117
+ }
118
+ type Rule = Mapping$1.Rule<Mapping>;
119
+ type Rules = Mapping$1.Rules<Rule>;
120
+
121
+ type index_Config = Config;
122
+ type index_Destination = Destination;
123
+ type index_Env = Env;
124
+ type index_InitSettings = InitSettings;
125
+ type index_Mapping = Mapping;
126
+ type index_Rule = Rule;
127
+ type index_Rules = Rules;
128
+ type index_RuntimeState = RuntimeState;
129
+ type index_SegmentAnalytics = SegmentAnalytics;
130
+ type index_SegmentDestination = SegmentDestination;
131
+ type index_SegmentEventOptions = SegmentEventOptions;
132
+ type index_SegmentSDK = SegmentSDK;
133
+ type index_Settings = Settings;
134
+ type index_Types = Types;
135
+ declare namespace index {
136
+ export type { index_Config as Config, index_Destination as Destination, index_Env as Env, index_InitSettings as InitSettings, index_Mapping as Mapping, index_Rule as Rule, index_Rules as Rules, index_RuntimeState as RuntimeState, index_SegmentAnalytics as SegmentAnalytics, index_SegmentDestination as SegmentDestination, index_SegmentEventOptions as SegmentEventOptions, index_SegmentSDK as SegmentSDK, index_Settings as Settings, index_Types as Types };
137
+ }
138
+
139
+ declare const destinationSegment: Destination;
140
+
141
+ export { index as DestinationSegment, destinationSegment as default, destinationSegment };
@@ -0,0 +1,141 @@
1
+ import { Destination as Destination$1, Mapping as Mapping$1 } from '@walkeros/core';
2
+ import { DestinationWeb } from '@walkeros/web-core';
3
+ import { InitOptions, AnalyticsBrowserSettings } from '@segment/analytics-next';
4
+
5
+ /**
6
+ * Destination-level settings.
7
+ *
8
+ * Extends Segment's `InitOptions` (minus the `group` key which clashes with
9
+ * walkerOS's own `group` mapping) so every passthrough option (cookie,
10
+ * storage, integrations, plan, etc.) keeps IntelliSense intact. walkerOS
11
+ * adds:
12
+ * - `apiKey` (required) — maps to `writeKey` in `AnalyticsBrowser.load()`
13
+ * - `identify` — destination-level identity mapping (Segment `identify()`)
14
+ * - `group` — destination-level group mapping (Segment `group()`)
15
+ * - `include` — event sections flattened into track `properties`
16
+ * - `consent` — walkerOS consent key → Segment category name mapping
17
+ * - `_state` — runtime state (not user-facing, mutated by init/push)
18
+ */
19
+ interface Settings extends Omit<InitOptions, 'group'> {
20
+ /** Segment write key. Maps to `writeKey` in the load() settings arg. */
21
+ apiKey: string;
22
+ /** walkerOS mapping value resolving to an identity object (userId, traits, anonymousId). */
23
+ identify?: Mapping$1.Value;
24
+ /** walkerOS mapping value resolving to a group object (groupId, traits). */
25
+ group?: Mapping$1.Value;
26
+ /**
27
+ * Mapping from walkerOS consent keys → Segment `categoryPreferences` keys.
28
+ * Example: { marketing: "Advertising", analytics: "Analytics" }
29
+ * If omitted, walkerOS keys are forwarded 1:1.
30
+ */
31
+ consent?: Record<string, string>;
32
+ /** Runtime state — populated by init() and mutated by push(). Not user-facing. */
33
+ _state?: RuntimeState;
34
+ }
35
+ interface RuntimeState {
36
+ /** Last-set identity values, used to skip redundant identify() calls. */
37
+ lastIdentity?: {
38
+ userId?: string;
39
+ anonymousId?: string;
40
+ traitsHash?: string;
41
+ };
42
+ /** Last-set group assignment, used to skip redundant group() calls. */
43
+ lastGroup?: {
44
+ groupId?: string;
45
+ traitsHash?: string;
46
+ };
47
+ /** Holds the AnalyticsBrowser instance created in init(). */
48
+ analytics?: SegmentAnalytics;
49
+ /** True once load() has been called (may be deferred pending consent). */
50
+ loaded?: boolean;
51
+ }
52
+ type InitSettings = Partial<Settings>;
53
+ /**
54
+ * Per-rule mapping settings. Every feature here is a walkerOS mapping
55
+ * value resolved via getMappingValue(). The resolved object's keys drive
56
+ * which Segment SDK methods to call.
57
+ */
58
+ interface Mapping {
59
+ identify?: Mapping$1.Value;
60
+ group?: Mapping$1.Value;
61
+ page?: Mapping$1.Value | boolean;
62
+ reset?: Mapping$1.Value | boolean;
63
+ }
64
+ /**
65
+ * Segment SDK surface — the subset of @segment/analytics-next the
66
+ * destination actually uses. Mirrors the AnalyticsBrowser instance shape
67
+ * so tests can mock each method individually via env.analytics.
68
+ */
69
+ interface SegmentAnalytics {
70
+ track: (event: string, properties?: Record<string, unknown>, options?: SegmentEventOptions) => Promise<unknown> | void;
71
+ identify: (userId?: string | Record<string, unknown>, traits?: Record<string, unknown>, options?: SegmentEventOptions) => Promise<unknown> | void;
72
+ group: (groupId: string, traits?: Record<string, unknown>, options?: SegmentEventOptions) => Promise<unknown> | void;
73
+ page: (category?: string | null, name?: string | null, properties?: Record<string, unknown>, options?: SegmentEventOptions) => Promise<unknown> | void;
74
+ alias: (to: string, from?: string, options?: SegmentEventOptions) => Promise<unknown> | void;
75
+ reset: () => Promise<unknown> | void;
76
+ setAnonymousId: (id: string) => Promise<unknown> | void;
77
+ }
78
+ /**
79
+ * Segment event options — the fourth argument to track/identify/group/page
80
+ * that carries context and integration overrides. The destination uses
81
+ * this to stamp consent context on every event.
82
+ */
83
+ interface SegmentEventOptions {
84
+ context?: {
85
+ consent?: {
86
+ categoryPreferences?: Record<string, boolean>;
87
+ };
88
+ [key: string]: unknown;
89
+ };
90
+ integrations?: Record<string, boolean | Record<string, unknown>>;
91
+ }
92
+ /**
93
+ * The module namespace used for `env?.analytics ?? realSegment`.
94
+ * AnalyticsBrowser is the class; tests mock with a factory that returns
95
+ * an object matching SegmentAnalytics.
96
+ *
97
+ * Task 1 verified: `AnalyticsBrowser.load(settings, options)` returns an
98
+ * `AnalyticsBrowser` instance **synchronously**. The instance buffers
99
+ * method calls until the internal load promise resolves.
100
+ */
101
+ interface SegmentSDK {
102
+ load: (settings: AnalyticsBrowserSettings, options?: InitOptions) => SegmentAnalytics;
103
+ }
104
+ /**
105
+ * Env — optional SDK override. Production leaves this undefined and the
106
+ * destination falls back to the real @segment/analytics-next module.
107
+ * Tests provide a mock via env.analytics = { ... }.
108
+ */
109
+ interface Env extends DestinationWeb.Env {
110
+ analytics?: SegmentSDK;
111
+ }
112
+ type Types = Destination$1.Types<Settings, Mapping, Env, InitSettings>;
113
+ type Destination = DestinationWeb.Destination<Types>;
114
+ type Config = DestinationWeb.Config<Types>;
115
+ interface SegmentDestination extends Destination {
116
+ env?: Env;
117
+ }
118
+ type Rule = Mapping$1.Rule<Mapping>;
119
+ type Rules = Mapping$1.Rules<Rule>;
120
+
121
+ type index_Config = Config;
122
+ type index_Destination = Destination;
123
+ type index_Env = Env;
124
+ type index_InitSettings = InitSettings;
125
+ type index_Mapping = Mapping;
126
+ type index_Rule = Rule;
127
+ type index_Rules = Rules;
128
+ type index_RuntimeState = RuntimeState;
129
+ type index_SegmentAnalytics = SegmentAnalytics;
130
+ type index_SegmentDestination = SegmentDestination;
131
+ type index_SegmentEventOptions = SegmentEventOptions;
132
+ type index_SegmentSDK = SegmentSDK;
133
+ type index_Settings = Settings;
134
+ type index_Types = Types;
135
+ declare namespace index {
136
+ export type { index_Config as Config, index_Destination as Destination, index_Env as Env, index_InitSettings as InitSettings, index_Mapping as Mapping, index_Rule as Rule, index_Rules as Rules, index_RuntimeState as RuntimeState, index_SegmentAnalytics as SegmentAnalytics, index_SegmentDestination as SegmentDestination, index_SegmentEventOptions as SegmentEventOptions, index_SegmentSDK as SegmentSDK, index_Settings as Settings, index_Types as Types };
137
+ }
138
+
139
+ declare const destinationSegment: Destination;
140
+
141
+ export { index as DestinationSegment, destinationSegment as default, destinationSegment };