@walkeros/collector 0.4.1 → 0.4.2

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.
Files changed (105) hide show
  1. package/dist/dev.d.mts +8 -4
  2. package/dist/dev.d.ts +8 -4
  3. package/dist/dev.js +1 -1
  4. package/dist/dev.js.map +1 -1
  5. package/dist/dev.mjs +1 -1
  6. package/dist/dev.mjs.map +1 -1
  7. package/dist/index.js +1 -1
  8. package/dist/index.js.map +1 -1
  9. package/dist/index.mjs +1 -1
  10. package/dist/index.mjs.map +1 -1
  11. package/package.json +2 -2
  12. package/dist/__tests__/auto-run.test.d.ts +0 -2
  13. package/dist/__tests__/auto-run.test.d.ts.map +0 -1
  14. package/dist/__tests__/auto-run.test.js +0 -105
  15. package/dist/__tests__/auto-run.test.js.map +0 -1
  16. package/dist/__tests__/consent.test.d.ts +0 -2
  17. package/dist/__tests__/consent.test.d.ts.map +0 -1
  18. package/dist/__tests__/consent.test.js +0 -21
  19. package/dist/__tests__/consent.test.js.map +0 -1
  20. package/dist/__tests__/create-flow.test.d.ts +0 -2
  21. package/dist/__tests__/create-flow.test.d.ts.map +0 -1
  22. package/dist/__tests__/create-flow.test.js +0 -69
  23. package/dist/__tests__/create-flow.test.js.map +0 -1
  24. package/dist/__tests__/destination.test.d.ts +0 -2
  25. package/dist/__tests__/destination.test.d.ts.map +0 -1
  26. package/dist/__tests__/destination.test.js +0 -242
  27. package/dist/__tests__/destination.test.js.map +0 -1
  28. package/dist/__tests__/handle.test.d.ts +0 -2
  29. package/dist/__tests__/handle.test.d.ts.map +0 -1
  30. package/dist/__tests__/handle.test.js +0 -78
  31. package/dist/__tests__/handle.test.js.map +0 -1
  32. package/dist/__tests__/mapping.test.d.ts +0 -2
  33. package/dist/__tests__/mapping.test.d.ts.map +0 -1
  34. package/dist/__tests__/mapping.test.js +0 -310
  35. package/dist/__tests__/mapping.test.js.map +0 -1
  36. package/dist/__tests__/source.test.d.ts +0 -2
  37. package/dist/__tests__/source.test.d.ts.map +0 -1
  38. package/dist/__tests__/source.test.js +0 -306
  39. package/dist/__tests__/source.test.js.map +0 -1
  40. package/dist/__tests__/start-flow.test.d.ts +0 -2
  41. package/dist/__tests__/start-flow.test.d.ts.map +0 -1
  42. package/dist/__tests__/start-flow.test.js +0 -167
  43. package/dist/__tests__/start-flow.test.js.map +0 -1
  44. package/dist/__tests__/walker-entity.test.d.ts +0 -2
  45. package/dist/__tests__/walker-entity.test.d.ts.map +0 -1
  46. package/dist/__tests__/walker-entity.test.js +0 -52
  47. package/dist/__tests__/walker-entity.test.js.map +0 -1
  48. package/dist/collector.d.ts +0 -3
  49. package/dist/collector.d.ts.map +0 -1
  50. package/dist/collector.js +0 -59
  51. package/dist/collector.js.map +0 -1
  52. package/dist/command.d.ts +0 -12
  53. package/dist/command.d.ts.map +0 -1
  54. package/dist/command.js +0 -20
  55. package/dist/command.js.map +0 -1
  56. package/dist/consent.d.ts +0 -10
  57. package/dist/consent.d.ts.map +0 -1
  58. package/dist/consent.js +0 -30
  59. package/dist/consent.js.map +0 -1
  60. package/dist/constants.d.ts +0 -13
  61. package/dist/constants.d.ts.map +0 -1
  62. package/dist/constants.js +0 -35
  63. package/dist/constants.js.map +0 -1
  64. package/dist/destination.d.ts +0 -56
  65. package/dist/destination.d.ts.map +0 -1
  66. package/dist/destination.js +0 -289
  67. package/dist/destination.js.map +0 -1
  68. package/dist/dev.d.ts.map +0 -1
  69. package/dist/elb.d.ts +0 -11
  70. package/dist/elb.d.ts.map +0 -1
  71. package/dist/elb.js +0 -60
  72. package/dist/elb.js.map +0 -1
  73. package/dist/flow.d.ts +0 -4
  74. package/dist/flow.d.ts.map +0 -1
  75. package/dist/flow.js +0 -44
  76. package/dist/flow.js.map +0 -1
  77. package/dist/handle.d.ts +0 -29
  78. package/dist/handle.d.ts.map +0 -1
  79. package/dist/handle.js +0 -161
  80. package/dist/handle.js.map +0 -1
  81. package/dist/index.d.ts.map +0 -1
  82. package/dist/on.d.ts +0 -19
  83. package/dist/on.d.ts.map +0 -1
  84. package/dist/on.js +0 -116
  85. package/dist/on.js.map +0 -1
  86. package/dist/push.d.ts +0 -11
  87. package/dist/push.d.ts.map +0 -1
  88. package/dist/push.js +0 -43
  89. package/dist/push.js.map +0 -1
  90. package/dist/schemas.d.ts +0 -6
  91. package/dist/schemas.d.ts.map +0 -1
  92. package/dist/schemas.js +0 -37
  93. package/dist/schemas.js.map +0 -1
  94. package/dist/source.d.ts +0 -10
  95. package/dist/source.d.ts.map +0 -1
  96. package/dist/source.js +0 -40
  97. package/dist/source.js.map +0 -1
  98. package/dist/types/collector.d.ts +0 -19
  99. package/dist/types/collector.d.ts.map +0 -1
  100. package/dist/types/collector.js +0 -2
  101. package/dist/types/collector.js.map +0 -1
  102. package/dist/types/index.d.ts +0 -2
  103. package/dist/types/index.d.ts.map +0 -1
  104. package/dist/types/index.js +0 -2
  105. package/dist/types/index.js.map +0 -1
@@ -1,242 +0,0 @@
1
- import { clone, createEvent } from '@walkeros/core';
2
- import { pushToDestinations, startFlow } from '..';
3
- describe('Destination', () => {
4
- let event;
5
- let destination;
6
- let config;
7
- let mockInit;
8
- let mockPush;
9
- function createDestination(args) {
10
- return {
11
- init: mockInit,
12
- push: mockPush,
13
- config: {},
14
- ...args,
15
- };
16
- }
17
- function createTestConfig(overrides = {}) {
18
- return {
19
- tagging: 1,
20
- verbose: false,
21
- globalsStatic: {},
22
- sessionStatic: {},
23
- ...overrides,
24
- };
25
- }
26
- function createWalkerjs(args) {
27
- const defaultConfig = createTestConfig();
28
- return {
29
- allowed: true,
30
- destinations: { foo: destination },
31
- globals: {},
32
- hooks: {},
33
- user: {},
34
- consent: {},
35
- queue: [],
36
- ...args,
37
- config: args?.config ? createTestConfig(args.config) : defaultConfig,
38
- };
39
- }
40
- beforeEach(() => {
41
- event = createEvent();
42
- mockInit = jest.fn(); //.mockImplementation(console.log);
43
- mockPush = jest.fn(); //.mockImplementation(console.log);
44
- config = { init: false };
45
- destination = {
46
- init: mockInit,
47
- push: mockPush,
48
- config,
49
- };
50
- });
51
- test('allowed', async () => {
52
- const collector = createWalkerjs({ allowed: false });
53
- let result = await pushToDestinations(collector, event);
54
- expect(result.ok).toBeFalsy();
55
- collector.allowed = true;
56
- result = await pushToDestinations(collector, event);
57
- expect(result.ok).toBeTruthy();
58
- });
59
- test('preventing data manipulation', async () => {
60
- const clonedEvent = clone(event);
61
- const mockPushUpdate = jest.fn().mockImplementation((event) => {
62
- event.data.foo = 'bar';
63
- });
64
- const destinationUpdate = {
65
- init: mockInit,
66
- push: mockPushUpdate,
67
- config: {},
68
- };
69
- await pushToDestinations(createWalkerjs(), event, {
70
- destinationUpdate,
71
- destination,
72
- });
73
- expect(mockPushUpdate).toHaveBeenCalledTimes(1);
74
- expect(mockPush).toHaveBeenCalledTimes(1);
75
- expect(mockPush).toHaveBeenCalledWith(clonedEvent, expect.objectContaining({
76
- config: { init: true },
77
- }));
78
- });
79
- test('failing init', async () => {
80
- // Simulate a failed init
81
- mockInit.mockImplementation(() => false);
82
- await pushToDestinations(createWalkerjs(), event);
83
- expect(mockInit).toHaveBeenCalledTimes(1);
84
- expect(mockPush).toHaveBeenCalledTimes(0);
85
- expect(destination.config.init).toBeFalsy();
86
- });
87
- test('DLQ', async () => {
88
- const event = createEvent();
89
- // Simulate a failing push
90
- mockPush.mockImplementation(() => {
91
- throw new Error('kaputt');
92
- });
93
- const destination = createDestination();
94
- const result = await pushToDestinations(createWalkerjs(), event, {
95
- destination,
96
- });
97
- expect(result.failed).toHaveLength(1);
98
- expect(result.ok).toBeFalsy();
99
- expect(mockPush).toHaveBeenCalledTimes(1);
100
- expect(destination.dlq).toContainEqual([event, new Error('kaputt')]);
101
- });
102
- test('skip on denied consent', async () => { });
103
- describe('destination on method', () => {
104
- let mockOnMethod;
105
- beforeEach(() => {
106
- mockOnMethod = jest.fn();
107
- });
108
- it('should call destination on method when consent event is triggered', async () => {
109
- const destinationWithOn = createDestination({
110
- on: mockOnMethod,
111
- config: { init: true },
112
- });
113
- const { collector, elb } = await startFlow({
114
- destinations: { testDestination: { code: destinationWithOn } },
115
- });
116
- // Trigger consent event
117
- await elb('walker consent', { marketing: true });
118
- // Verify the destination's on method was called with consent context
119
- expect(mockOnMethod).toHaveBeenCalledWith('consent', { marketing: true });
120
- });
121
- it('should call destination on method when session event is triggered', async () => {
122
- const destinationWithOn = createDestination({
123
- on: mockOnMethod,
124
- config: { init: true },
125
- });
126
- const { collector, elb } = await startFlow({
127
- destinations: { testDestination: { code: destinationWithOn } },
128
- });
129
- // Set session data and trigger session event
130
- collector.session = {
131
- id: 'test-session',
132
- isStart: true,
133
- storage: false,
134
- device: 'test',
135
- };
136
- await elb('walker session');
137
- // Verify the destination's on method was called with session context
138
- expect(mockOnMethod).toHaveBeenCalledWith('session', collector.session);
139
- });
140
- it('should call destination on method when ready event is triggered', async () => {
141
- const destinationWithOn = createDestination({
142
- on: mockOnMethod,
143
- config: { init: true },
144
- });
145
- const { collector, elb } = await startFlow({
146
- destinations: { testDestination: { code: destinationWithOn } },
147
- });
148
- // Trigger ready event
149
- await elb('walker ready');
150
- // Verify the destination's on method was called
151
- expect(mockOnMethod).toHaveBeenCalledWith('ready', undefined);
152
- });
153
- it('should call destination on method when run event is triggered', async () => {
154
- const destinationWithOn = createDestination({
155
- on: mockOnMethod,
156
- config: { init: true },
157
- });
158
- const { collector, elb } = await startFlow({
159
- destinations: { testDestination: { code: destinationWithOn } },
160
- });
161
- // Trigger run event
162
- await elb('walker run');
163
- // Verify the destination's on method was called
164
- expect(mockOnMethod).toHaveBeenCalledWith('run', undefined);
165
- });
166
- it('should not fail if destination does not have on method', async () => {
167
- const destinationWithoutOn = createDestination({
168
- config: { init: true },
169
- });
170
- const { collector, elb } = await startFlow({
171
- destinations: { testDestination: { code: destinationWithoutOn } },
172
- });
173
- // Should not throw when destination has no on method
174
- expect(async () => {
175
- await elb('walker consent', { marketing: true });
176
- await elb('walker session');
177
- await elb('walker ready');
178
- await elb('walker run');
179
- }).not.toThrow();
180
- });
181
- it('should handle async on method', async () => {
182
- const asyncOnMethod = jest.fn().mockResolvedValue(undefined);
183
- const destinationWithAsyncOn = createDestination({
184
- on: asyncOnMethod,
185
- config: { init: true },
186
- });
187
- const { collector, elb } = await startFlow({
188
- destinations: { testDestination: { code: destinationWithAsyncOn } },
189
- });
190
- // Trigger consent event
191
- await elb('walker consent', { marketing: true });
192
- // Verify the async destination's on method was called
193
- expect(asyncOnMethod).toHaveBeenCalledWith('consent', {
194
- marketing: true,
195
- });
196
- });
197
- it('should call on method for multiple destinations', async () => {
198
- const mockOn1 = jest.fn();
199
- const mockOn2 = jest.fn();
200
- const destination1 = createDestination({
201
- on: mockOn1,
202
- config: { init: true },
203
- });
204
- const destination2 = createDestination({
205
- on: mockOn2,
206
- config: { init: true },
207
- });
208
- const { collector, elb } = await startFlow({
209
- destinations: {
210
- dest1: { code: destination1 },
211
- dest2: { code: destination2 },
212
- },
213
- });
214
- // Trigger consent event
215
- await elb('walker consent', { marketing: true });
216
- // Both destinations should receive the event
217
- expect(mockOn1).toHaveBeenCalledWith('consent', { marketing: true });
218
- expect(mockOn2).toHaveBeenCalledWith('consent', { marketing: true });
219
- });
220
- it('should handle on method errors gracefully', async () => {
221
- const errorOnMethod = jest.fn().mockImplementation(() => {
222
- throw new Error('On method error');
223
- });
224
- const destinationWithErrorOn = createDestination({
225
- on: errorOnMethod,
226
- config: { init: true },
227
- });
228
- const { collector, elb } = await startFlow({
229
- destinations: { testDestination: { code: destinationWithErrorOn } },
230
- });
231
- // Should not throw even if on method throws an error
232
- expect(async () => {
233
- await elb('walker consent', { marketing: true });
234
- }).not.toThrow();
235
- // On method should still have been called
236
- expect(errorOnMethod).toHaveBeenCalledWith('consent', {
237
- marketing: true,
238
- });
239
- });
240
- });
241
- });
242
- //# sourceMappingURL=destination.test.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"destination.test.js","sourceRoot":"","sources":["../../src/__tests__/destination.test.ts"],"names":[],"mappings":"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S,EAAE,IAAI,EAAE,CAAC,CAAC;YACrE,MAAM,CAAC,OAAO,CAAC,CAAC,oBAAoB,CAAC,SAAS,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC;QACvE,CAAC,CAAC,CAAC;QAEH,EAAE,CAAC,2CAA2C,EAAE,KAAK,IAAI,EAAE;YACzD,MAAM,aAAa,GAAG,IAAI,CAAC,EAAE,EAAE,CAAC,kBAAkB,CAAC,GAAG,EAAE;gBACtD,MAAM,IAAI,KAAK,CAAC,iBAAiB,CAAC,CAAC;YACrC,CAAC,CAAC,CAAC;YAEH,MAAM,sBAAsB,GAAG,iBAAiB,CAAC;gBAC/C,EAAE,EAAE,aAAa;gBACjB,MAAM,EAAE,EAAE,IAAI,EAAE,IAAI,EAAE;aACvB,CAAC,CAAC;YAEH,MAAM,EAAE,SAAS,EAAE,GAAG,EAAE,GAAG,MAAM,SAAS,CAAC;gBACzC,YAAY,EAAE,EAAE,eAAe,EAAE,EAAE,IAAI,EAAE,sBAAsB,EAAE,EAAE;aACpE,CAAC,CAAC;YAEH,qDAAqD;YACrD,MAAM,CAAC,KAAK,IAAI,EAAE;gBAChB,MAAM,GAAG,CAAC,gBAAgB,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC;YACnD,CAAC,CAAC,CAAC,GAAG,CAAC,OAAO,EAAE,CAAC;YAEjB,0CAA0C;YAC1C,MAAM,CAAC,aAAa,CAAC,CAAC,oBAAoB,CAAC,SAAS,EAAE;gBACpD,SAAS,EAAE,IAAI;aAChB,CAAC,CAAC;QACL,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=handle.test.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"handle.test.d.ts","sourceRoot":"","sources":["../../src/__tests__/handle.test.ts"],"names":[],"mappings":""}
@@ -1,78 +0,0 @@
1
- import { startFlow } from '..';
2
- import { commonHandleCommand } from '../handle';
3
- describe('Handle Commands', () => {
4
- let mockDestinationPush;
5
- let mockDestinationInit;
6
- let mockDestination;
7
- beforeEach(() => {
8
- jest.clearAllMocks();
9
- mockDestinationPush = jest.fn();
10
- mockDestinationInit = jest.fn().mockResolvedValue({ settings: {} });
11
- mockDestination = {
12
- type: 'test',
13
- config: {},
14
- init: mockDestinationInit,
15
- push: mockDestinationPush,
16
- };
17
- });
18
- describe('walker destination command', () => {
19
- test('adds destination without config', async () => {
20
- const { elb, collector } = await startFlow({});
21
- // Initially no destinations
22
- expect(Object.keys(collector.destinations)).toHaveLength(0);
23
- // Add destination without config
24
- await elb('walker destination', mockDestination);
25
- // Destination should be added with some default config
26
- expect(Object.keys(collector.destinations)).toHaveLength(1);
27
- const destinationId = Object.keys(collector.destinations)[0];
28
- expect(collector.destinations[destinationId]).toBeDefined();
29
- expect(collector.destinations[destinationId].config).toBeDefined();
30
- });
31
- test('adds destination with config including custom id', async () => {
32
- const { elb, collector } = await startFlow({});
33
- const customConfig = {
34
- id: 'my-custom-id',
35
- init: true,
36
- loadScript: false,
37
- mapping: {
38
- entity: {
39
- action: {
40
- name: 'CustomEvent',
41
- },
42
- },
43
- },
44
- };
45
- // Add destination with config
46
- await elb('walker destination', mockDestination, customConfig);
47
- // Destination should be added with custom id and config
48
- expect(Object.keys(collector.destinations)).toEqual(['my-custom-id']);
49
- expect(collector.destinations['my-custom-id']).toBeDefined();
50
- expect(collector.destinations['my-custom-id'].config).toEqual(customConfig);
51
- });
52
- test('adds destination with config and stores it properly', async () => {
53
- const { elb, collector } = await startFlow({});
54
- const customConfig = {
55
- id: 'test-destination',
56
- settings: { apiKey: 'test-key' },
57
- };
58
- // Add destination with config
59
- await elb('walker destination', mockDestination, customConfig);
60
- // Destination should be added with custom config
61
- expect(collector.destinations['test-destination']).toBeDefined();
62
- expect(collector.destinations['test-destination'].config).toEqual(customConfig);
63
- });
64
- test('handles destination config through commonHandleCommand', async () => {
65
- const { collector } = await startFlow({});
66
- const customConfig = {
67
- id: 'cmd-test',
68
- settings: { foo: 'bar' },
69
- };
70
- // Call commonHandleCommand directly
71
- await commonHandleCommand(collector, 'destination', mockDestination, customConfig);
72
- // Destination should be added with config
73
- expect(collector.destinations['cmd-test']).toBeDefined();
74
- expect(collector.destinations['cmd-test'].config).toEqual(customConfig);
75
- });
76
- });
77
- });
78
- //# sourceMappingURL=handle.test.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"handle.test.js","sourceRoot":"","sources":["../../src/__tests__/handle.test.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,SAAS,EAAE,MAAM,IAAI,CAAC;AAC/B,OAAO,EAAE,mBAAmB,EAAE,MAAM,WAAW,CAAC;AAEhD,QAAQ,CAAC,iBAAiB,EAAE,GAAG,EAAE;IAC/B,IAAI,mBAA8B,CAAC;IACnC,IAAI,mBAA8B,CAAC;IACnC,IAAI,eAAqC,CAAC;IAE1C,UAAU,CAAC,GAAG,EAAE;QACd,IAAI,CAAC,aAAa,EAAE,CAAC;QACrB,mBAAmB,GAAG,IAAI,CAAC,EAAE,EAAE,CAAC;QAChC,mBAAmB,GAAG,IAAI,CAAC,EAAE,EAAE,CAAC,iBAAiB,CAAC,EAAE,QAAQ,EAAE,EAAE,EAAE,CAAC,CAAC;QAEpE,eAAe,GAAG;YAChB,IAAI,EAAE,MAAM;YACZ,MAAM,EAAE,EAAE;YACV,IAAI,EAAE,mBAAmB;YACzB,IAAI,EAAE,mBAAmB;SAC1B,CAAC;IACJ,CAAC,CAAC,CAAC;IAEH,QAAQ,CAAC,4BAA4B,EAAE,GAAG,EAAE;QAC1C,IAAI,CAAC,iCAAiC,EAAE,KAAK,IAAI,EAAE;YACjD,MAAM,EAAE,GAAG,EAAE,SAAS,EAAE,GAAG,MAAM,SAAS,CAAC,EAAE,CAAC,CAAC;YAE/C,4BAA4B;YAC5B,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,SAAS,CAAC,YAAY,CAAC,CA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C,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=mapping.test.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"mapping.test.d.ts","sourceRoot":"","sources":["../../src/__tests__/mapping.test.ts"],"names":[],"mappings":""}
@@ -1,310 +0,0 @@
1
- import { startFlow } from '..';
2
- describe('Mapping', () => {
3
- describe('Source Mapping', () => {
4
- let spyDestination;
5
- beforeEach(() => {
6
- spyDestination = {
7
- type: 'spy',
8
- config: {},
9
- push: jest.fn(),
10
- };
11
- });
12
- test('event name override', async () => {
13
- const mockSource = jest.fn((config, env) => ({
14
- type: 'test',
15
- config,
16
- push: env.push,
17
- }));
18
- const { collector } = await startFlow({
19
- sources: {
20
- test: {
21
- code: mockSource,
22
- config: {
23
- mapping: {
24
- product: {
25
- click: { name: 'product view' },
26
- },
27
- },
28
- },
29
- },
30
- },
31
- destinations: {
32
- spy: {
33
- code: spyDestination,
34
- },
35
- },
36
- });
37
- // Trigger source push
38
- await collector.sources.test.push({
39
- name: 'product click',
40
- data: { id: 'P123' },
41
- });
42
- // Verify destination received renamed event
43
- expect(spyDestination.push).toHaveBeenCalledWith(expect.objectContaining({ name: 'product view' }), expect.any(Object));
44
- });
45
- test('ignore rule', async () => {
46
- const mockSource = jest.fn((config, env) => ({
47
- type: 'test',
48
- config,
49
- push: env.push,
50
- }));
51
- const { collector } = await startFlow({
52
- sources: {
53
- test: {
54
- code: mockSource,
55
- config: {
56
- mapping: {
57
- internal: {
58
- '*': { ignore: true },
59
- },
60
- },
61
- },
62
- },
63
- },
64
- destinations: {
65
- spy: {
66
- code: spyDestination,
67
- },
68
- },
69
- });
70
- // Trigger source push
71
- await collector.sources.test.push({ name: 'internal debug', data: {} });
72
- // Verify destination never received event
73
- expect(spyDestination.push).not.toHaveBeenCalled();
74
- });
75
- // Note: Source data transformation creates context data for destinations,
76
- // but there's currently no mechanism to pass this through the collector.
77
- // This would require architectural changes to support properly.
78
- test('policy enrichment modifies event', async () => {
79
- const mockSource = jest.fn((config, env) => ({
80
- type: 'test',
81
- config,
82
- push: env.push,
83
- }));
84
- const { collector } = await startFlow({
85
- sources: {
86
- test: {
87
- code: mockSource,
88
- config: {
89
- policy: {
90
- 'data.email': {
91
- fn: (event) => event.data?.email?.toLowerCase(),
92
- },
93
- },
94
- },
95
- },
96
- },
97
- destinations: {
98
- spy: {
99
- code: spyDestination,
100
- },
101
- },
102
- });
103
- // Trigger source push
104
- await collector.sources.test.push({
105
- name: 'user login',
106
- data: { email: 'USER@EXAMPLE.COM' },
107
- });
108
- // Verify destination received event with normalized email in EVENT data
109
- expect(spyDestination.push).toHaveBeenCalledWith(expect.objectContaining({
110
- data: expect.objectContaining({ email: 'user@example.com' }),
111
- }), expect.any(Object));
112
- });
113
- test('consent requirement', async () => {
114
- const mockSource = jest.fn((config, env) => ({
115
- type: 'test',
116
- config,
117
- push: env.push,
118
- }));
119
- const { collector } = await startFlow({
120
- consent: {}, // No consent granted
121
- sources: {
122
- test: {
123
- code: mockSource,
124
- config: {
125
- consent: { marketing: true }, // Requires marketing consent
126
- },
127
- },
128
- },
129
- destinations: {
130
- spy: {
131
- code: spyDestination,
132
- },
133
- },
134
- });
135
- // Trigger source push
136
- await collector.sources.test.push('user track');
137
- // Verify destination never received event (no consent)
138
- expect(spyDestination.push).not.toHaveBeenCalled();
139
- });
140
- });
141
- describe('Destination Mapping', () => {
142
- let spyDestination;
143
- beforeEach(() => {
144
- spyDestination = {
145
- type: 'spy',
146
- config: {},
147
- push: jest.fn(),
148
- };
149
- });
150
- test('event name override', async () => {
151
- const mockSource = jest.fn((config, env) => ({
152
- type: 'test',
153
- config,
154
- push: env.push,
155
- }));
156
- spyDestination.config = {
157
- mapping: {
158
- product: {
159
- click: { name: 'product view' },
160
- },
161
- },
162
- };
163
- const { collector } = await startFlow({
164
- sources: {
165
- test: {
166
- code: mockSource,
167
- },
168
- },
169
- destinations: {
170
- spy: {
171
- code: spyDestination,
172
- },
173
- },
174
- });
175
- // Trigger source push
176
- await collector.sources.test.push({
177
- name: 'product click',
178
- data: { id: 'P123' },
179
- });
180
- // Verify destination received renamed event
181
- expect(spyDestination.push).toHaveBeenCalledWith(expect.objectContaining({ name: 'product view' }), expect.any(Object));
182
- });
183
- test('ignore rule', async () => {
184
- const mockSource = jest.fn((config, env) => ({
185
- type: 'test',
186
- config,
187
- push: env.push,
188
- }));
189
- spyDestination.config = {
190
- mapping: {
191
- internal: {
192
- '*': { ignore: true },
193
- },
194
- },
195
- };
196
- const { collector } = await startFlow({
197
- sources: {
198
- test: {
199
- code: mockSource,
200
- },
201
- },
202
- destinations: {
203
- spy: {
204
- code: spyDestination,
205
- },
206
- },
207
- });
208
- // Trigger source push
209
- await collector.sources.test.push({ name: 'internal debug', data: {} });
210
- // Verify destination never received event
211
- expect(spyDestination.push).not.toHaveBeenCalled();
212
- });
213
- test('data transformation', async () => {
214
- const mockSource = jest.fn((config, env) => ({
215
- type: 'test',
216
- config,
217
- push: env.push,
218
- }));
219
- spyDestination.config = {
220
- data: {
221
- map: {
222
- category: { value: 'Electronics' },
223
- },
224
- },
225
- };
226
- const { collector } = await startFlow({
227
- sources: {
228
- test: {
229
- code: mockSource,
230
- },
231
- },
232
- destinations: {
233
- spy: {
234
- code: spyDestination,
235
- },
236
- },
237
- });
238
- // Trigger source push
239
- await collector.sources.test.push({
240
- name: 'product view',
241
- data: { id: 'P123', name: 'Laptop' },
242
- });
243
- // Verify destination received event with transformed data
244
- expect(spyDestination.push).toHaveBeenCalledWith(expect.any(Object), expect.objectContaining({
245
- data: { category: 'Electronics' },
246
- }));
247
- });
248
- test('global data transformation', async () => {
249
- const mockSource = jest.fn((config, env) => ({
250
- type: 'test',
251
- config,
252
- push: env.push,
253
- }));
254
- spyDestination.config = {
255
- data: {
256
- value: 'destination-metadata',
257
- },
258
- };
259
- const { collector } = await startFlow({
260
- sources: {
261
- test: {
262
- code: mockSource,
263
- },
264
- },
265
- destinations: {
266
- spy: {
267
- code: spyDestination,
268
- },
269
- },
270
- });
271
- // Trigger source push
272
- await collector.sources.test.push({
273
- name: 'product view',
274
- data: { id: 'P123', name: 'Laptop' },
275
- });
276
- // Verify destination received transformed data in context
277
- expect(spyDestination.push).toHaveBeenCalledWith(expect.any(Object), expect.objectContaining({
278
- data: 'destination-metadata',
279
- }));
280
- });
281
- test('consent requirement', async () => {
282
- const mockSource = jest.fn((config, env) => ({
283
- type: 'test',
284
- config,
285
- push: env.push,
286
- }));
287
- spyDestination.config = {
288
- consent: { marketing: true }, // Requires marketing consent
289
- };
290
- const { collector } = await startFlow({
291
- consent: {}, // No consent granted
292
- sources: {
293
- test: {
294
- code: mockSource,
295
- },
296
- },
297
- destinations: {
298
- spy: {
299
- code: spyDestination,
300
- },
301
- },
302
- });
303
- // Trigger source push
304
- await collector.sources.test.push('user track');
305
- // Verify destination never received event (no consent)
306
- expect(spyDestination.push).not.toHaveBeenCalled();
307
- });
308
- });
309
- });
310
- //# sourceMappingURL=mapping.test.js.map