@walkeros/collector 0.4.1 → 0.5.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.
- package/README.md +29 -18
- package/dist/__tests__/auto-run.test.js +1 -4
- package/dist/__tests__/auto-run.test.js.map +1 -1
- package/dist/__tests__/destination-code.test.d.ts +2 -0
- package/dist/__tests__/destination-code.test.d.ts.map +1 -0
- package/dist/__tests__/destination-code.test.js +323 -0
- package/dist/__tests__/destination-code.test.js.map +1 -0
- package/dist/__tests__/destination.test.js +92 -14
- package/dist/__tests__/destination.test.js.map +1 -1
- package/dist/collector.d.ts.map +1 -1
- package/dist/collector.js +8 -7
- package/dist/collector.js.map +1 -1
- package/dist/destination-code.d.ts +4 -0
- package/dist/destination-code.d.ts.map +1 -0
- package/dist/destination-code.js +60 -0
- package/dist/destination-code.js.map +1 -0
- package/dist/destination.d.ts +5 -0
- package/dist/destination.d.ts.map +1 -1
- package/dist/destination.js +37 -12
- package/dist/destination.js.map +1 -1
- package/dist/dev.d.mts +8 -4
- package/dist/dev.d.ts +8 -4
- package/dist/dev.d.ts.map +1 -1
- package/dist/dev.js +1 -1
- package/dist/dev.js.map +1 -1
- package/dist/dev.mjs +1 -1
- package/dist/dev.mjs.map +1 -1
- package/dist/index.d.mts +46 -2
- package/dist/index.d.ts +46 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +1 -1
- package/dist/index.mjs.map +1 -1
- package/dist/on.d.ts.map +1 -1
- package/dist/on.js +14 -3
- package/dist/on.js.map +1 -1
- package/dist/schemas.d.ts +1 -3
- package/dist/schemas.d.ts.map +1 -1
- package/dist/schemas.js +13 -15
- package/dist/schemas.js.map +1 -1
- package/dist/source.d.ts.map +1 -1
- package/dist/source.js +7 -0
- package/dist/source.js.map +1 -1
- package/dist/types/code.d.ts +22 -0
- package/dist/types/code.d.ts.map +1 -0
- package/dist/types/code.js +2 -0
- package/dist/types/code.js.map +1 -0
- package/dist/types/index.d.ts +1 -0
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/index.js +2 -0
- package/dist/types/index.js.map +1 -1
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
<p align="left">
|
|
2
|
-
<a href="https://
|
|
3
|
-
<img title="elbwalker" src="https://www.
|
|
2
|
+
<a href="https://www.walkeros.io">
|
|
3
|
+
<img title="elbwalker" src="https://www.walkeros.io/img/elbwalker_logo.png" width="256px"/>
|
|
4
4
|
</a>
|
|
5
5
|
</p>
|
|
6
6
|
|
|
@@ -75,7 +75,7 @@ action by space the collector won't process it.
|
|
|
75
75
|
npm install @walkeros/collector
|
|
76
76
|
```
|
|
77
77
|
|
|
78
|
-
##
|
|
78
|
+
## Quick Start
|
|
79
79
|
|
|
80
80
|
### Basic setup
|
|
81
81
|
|
|
@@ -108,27 +108,38 @@ const { collector, elb } = await startFlow({
|
|
|
108
108
|
destinations: [
|
|
109
109
|
// add your event destinations
|
|
110
110
|
],
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
console.log(`[${level}] ${message}`);
|
|
111
|
+
logger: {
|
|
112
|
+
level: 'debug', // 'debug' | 'info' | 'warn' | 'error'
|
|
113
|
+
handler: (message, level) => {
|
|
114
|
+
console.log(`[${level}] ${message}`);
|
|
115
|
+
},
|
|
117
116
|
},
|
|
118
117
|
});
|
|
119
118
|
```
|
|
120
119
|
|
|
121
120
|
## Configuration
|
|
122
121
|
|
|
123
|
-
| Name | Type
|
|
124
|
-
| -------------- |
|
|
125
|
-
| `run` | `boolean`
|
|
126
|
-
| `sources` | `array`
|
|
127
|
-
| `destinations` | `array`
|
|
128
|
-
| `consent` | `object`
|
|
129
|
-
| `
|
|
130
|
-
|
|
131
|
-
|
|
122
|
+
| Name | Type | Description | Required | Example |
|
|
123
|
+
| -------------- | --------- | ------------------------------------------------------------ | -------- | --------------------------------------- |
|
|
124
|
+
| `run` | `boolean` | Automatically start the collector pipeline on initialization | No | `true` |
|
|
125
|
+
| `sources` | `array` | Configurations for sources providing events to the collector | No | `[{ source, config }]` |
|
|
126
|
+
| `destinations` | `array` | Configurations for destinations receiving processed events | No | `[{ destination, config }]` |
|
|
127
|
+
| `consent` | `object` | Initial consent state to control routing of events | No | `{ analytics: true, marketing: false }` |
|
|
128
|
+
| `logger` | `object` | Logger configuration with level and custom handler | No | `{ level: 'info', handler: fn }` |
|
|
129
|
+
|
|
130
|
+
## Type Definitions
|
|
131
|
+
|
|
132
|
+
See [src/types/](./src/types/) for TypeScript interfaces:
|
|
133
|
+
|
|
134
|
+
- [flow.ts](./src/types/flow.ts) - Flow configuration
|
|
135
|
+
- [collector.ts](./src/types/collector.ts) - Collector interface
|
|
136
|
+
|
|
137
|
+
## Related
|
|
138
|
+
|
|
139
|
+
- [Website Documentation](https://www.walkeros.io/docs/getting-started/flow/)
|
|
140
|
+
- [Core Package](../core/) - Types and utilities
|
|
141
|
+
- [Web Sources](../web/sources/) - Browser event sources
|
|
142
|
+
- [Server Sources](../server/sources/) - Node.js event sources
|
|
132
143
|
|
|
133
144
|
## Contribute
|
|
134
145
|
|
|
@@ -29,17 +29,14 @@ describe('Auto-run functionality', () => {
|
|
|
29
29
|
});
|
|
30
30
|
test('config state is preserved correctly for different run values', async () => {
|
|
31
31
|
// Test with run: true
|
|
32
|
-
const collectorTrue = await startFlow({ run: true
|
|
32
|
+
const collectorTrue = await startFlow({ run: true });
|
|
33
33
|
expect(collectorTrue.collector.config.run).toBe(true);
|
|
34
|
-
expect(collectorTrue.collector.config.verbose).toBe(true);
|
|
35
34
|
expect(collectorTrue.collector.allowed).toBe(true);
|
|
36
35
|
// Test with run: false
|
|
37
36
|
const collectorFalse = await startFlow({
|
|
38
37
|
run: false,
|
|
39
|
-
verbose: true,
|
|
40
38
|
});
|
|
41
39
|
expect(collectorFalse.collector.config.run).toBe(false);
|
|
42
|
-
expect(collectorFalse.collector.config.verbose).toBe(true);
|
|
43
40
|
expect(collectorFalse.collector.allowed).toBe(false);
|
|
44
41
|
});
|
|
45
42
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"auto-run.test.js","sourceRoot":"","sources":["../../src/__tests__/auto-run.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,IAAI,CAAC;AAE/B,QAAQ,CAAC,wBAAwB,EAAE,GAAG,EAAE;IACtC,QAAQ,CAAC,6BAA6B,EAAE,GAAG,EAAE;QAC3C,IAAI,CAAC,yDAAyD,EAAE,KAAK,IAAI,EAAE;YACzE,MAAM,EAAE,SAAS,EAAE,GAAG,MAAM,SAAS,EAAE,CAAC;YAExC,2DAA2D;YAC3D,MAAM,CAAC,SAAS,CAAC,OAAO,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;YACrC,MAAM,CAAC,SAAS,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QAC1C,CAAC,CAAC,CAAC;QAEH,IAAI,CAAC,0EAA0E,EAAE,KAAK,IAAI,EAAE;YAC1F,MAAM,EAAE,SAAS,EAAE,GAAG,MAAM,SAAS,CAAC,EAAE,GAAG,EAAE,IAAI,EAAE,CAAC,CAAC;YAErD,uEAAuE;YACvE,MAAM,CAAC,SAAS,CAAC,OAAO,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;YACrC,MAAM,CAAC,SAAS,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QAC1C,CAAC,CAAC,CAAC;QAEH,IAAI,CAAC,yEAAyE,EAAE,KAAK,IAAI,EAAE;YACzF,MAAM,EAAE,SAAS,EAAE,GAAG,MAAM,SAAS,CAAC,EAAE,GAAG,EAAE,KAAK,EAAE,CAAC,CAAC;YAEtD,uEAAuE;YACvE,MAAM,CAAC,SAAS,CAAC,OAAO,CAAC,CAAC,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AC,kDAAkD,EAAE,KAAK,IAAI,EAAE;YAClE,MAAM,WAAW,GAAG,EAAE,UAAU,EAAE,IAAI,EAAE,SAAS,EAAE,KAAK,EAAE,CAAC;YAC3D,MAAM,QAAQ,GAAG,EAAE,EAAE,EAAE,eAAe,EAAE,CAAC;YACzC,MAAM,WAAW,GAAG,EAAE,UAAU,EAAE,WAAW,EAAE,CAAC;YAChD,MAAM,UAAU,GAAG,EAAE,WAAW,EAAE,WAAW,EAAE,CAAC;YAEhD,MAAM,EAAE,SAAS,EAAE,GAAG,MAAM,SAAS,CAAC;gBACpC,GAAG,EAAE,KAAK;gBACV,OAAO,EAAE,WAAW;gBACpB,IAAI,EAAE,QAAQ;gBACd,OAAO,EAAE,WAAW;gBACpB,MAAM,EAAE,UAAU;aACnB,CAAC,CAAC;YAEH,4CAA4C;YAC5C,MAAM,CAAC,SAAS,CAAC,OAAO,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;YAEtC,gEAAgE;YAChE,MAAM,CAAC,SAAS,CAAC,OAAO,CAAC,CAAC,OAAO,CAAC,WAAW,CAAC,CAAC;YAC/C,MAAM,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC;YACzC,MAAM,CAAC,SAAS,CAAC,OAAO,CAAC,CAAC,OAAO,CAAC,MAAM,CAAC,gBAAgB,CAAC,WAAW,CAAC,CAAC,CAAC;YACxE,MAAM,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC,OAAO,CAAC,UAAU,CAAC,CAAC;QAC/C,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"destination-code.test.d.ts","sourceRoot":"","sources":["../../src/__tests__/destination-code.test.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,323 @@
|
|
|
1
|
+
import { createEvent, createMockLogger } from '@walkeros/core';
|
|
2
|
+
import { destinationCode } from '../destination-code';
|
|
3
|
+
import { initDestinations } from '../destination';
|
|
4
|
+
describe('destinationCode', () => {
|
|
5
|
+
const createMockCollector = () => ({
|
|
6
|
+
consent: {},
|
|
7
|
+
destinations: {},
|
|
8
|
+
sources: {},
|
|
9
|
+
queue: [],
|
|
10
|
+
hooks: {},
|
|
11
|
+
on: {},
|
|
12
|
+
globals: {},
|
|
13
|
+
user: {},
|
|
14
|
+
allowed: true,
|
|
15
|
+
config: {},
|
|
16
|
+
count: 0,
|
|
17
|
+
logger: createMockLogger(),
|
|
18
|
+
push: jest.fn(),
|
|
19
|
+
});
|
|
20
|
+
beforeEach(() => {
|
|
21
|
+
jest.clearAllMocks();
|
|
22
|
+
});
|
|
23
|
+
describe('basic properties', () => {
|
|
24
|
+
it('should have correct type', () => {
|
|
25
|
+
expect(destinationCode.type).toBe('code');
|
|
26
|
+
});
|
|
27
|
+
it('should have empty default config', () => {
|
|
28
|
+
expect(destinationCode.config).toEqual({});
|
|
29
|
+
});
|
|
30
|
+
});
|
|
31
|
+
describe('init', () => {
|
|
32
|
+
it('executes init code string', () => {
|
|
33
|
+
const mockLogger = createMockLogger();
|
|
34
|
+
const context = {
|
|
35
|
+
collector: createMockCollector(),
|
|
36
|
+
config: {
|
|
37
|
+
settings: {
|
|
38
|
+
init: "context.logger.info('initialized')",
|
|
39
|
+
},
|
|
40
|
+
},
|
|
41
|
+
env: {},
|
|
42
|
+
logger: mockLogger,
|
|
43
|
+
};
|
|
44
|
+
destinationCode.init(context);
|
|
45
|
+
expect(mockLogger.info).toHaveBeenCalledWith('initialized');
|
|
46
|
+
});
|
|
47
|
+
it('handles missing init code gracefully', () => {
|
|
48
|
+
const context = {
|
|
49
|
+
collector: createMockCollector(),
|
|
50
|
+
config: { settings: {} },
|
|
51
|
+
env: {},
|
|
52
|
+
logger: createMockLogger(),
|
|
53
|
+
};
|
|
54
|
+
expect(() => destinationCode.init(context)).not.toThrow();
|
|
55
|
+
});
|
|
56
|
+
it('catches and logs errors in init code', () => {
|
|
57
|
+
const mockLogger = createMockLogger();
|
|
58
|
+
const context = {
|
|
59
|
+
collector: createMockCollector(),
|
|
60
|
+
config: {
|
|
61
|
+
settings: {
|
|
62
|
+
init: "throw new Error('test error')",
|
|
63
|
+
},
|
|
64
|
+
},
|
|
65
|
+
env: {},
|
|
66
|
+
logger: mockLogger,
|
|
67
|
+
};
|
|
68
|
+
destinationCode.init(context);
|
|
69
|
+
expect(mockLogger.error).toHaveBeenCalled();
|
|
70
|
+
});
|
|
71
|
+
});
|
|
72
|
+
describe('push', () => {
|
|
73
|
+
it('executes push code from mapping', () => {
|
|
74
|
+
const mockLogger = createMockLogger();
|
|
75
|
+
const context = {
|
|
76
|
+
collector: createMockCollector(),
|
|
77
|
+
config: {},
|
|
78
|
+
data: { transformed: true },
|
|
79
|
+
env: {},
|
|
80
|
+
logger: mockLogger,
|
|
81
|
+
mapping: {
|
|
82
|
+
push: 'context.logger.info(event.name, context.data)',
|
|
83
|
+
},
|
|
84
|
+
};
|
|
85
|
+
destinationCode.push(createEvent({ name: 'product view' }), context);
|
|
86
|
+
expect(mockLogger.info).toHaveBeenCalledWith('product view', {
|
|
87
|
+
transformed: true,
|
|
88
|
+
});
|
|
89
|
+
});
|
|
90
|
+
it('falls back to settings.push when mapping.push is missing', () => {
|
|
91
|
+
const mockLogger = createMockLogger();
|
|
92
|
+
const context = {
|
|
93
|
+
collector: createMockCollector(),
|
|
94
|
+
config: {
|
|
95
|
+
settings: {
|
|
96
|
+
push: "context.logger.info('settings fallback')",
|
|
97
|
+
},
|
|
98
|
+
},
|
|
99
|
+
data: {},
|
|
100
|
+
env: {},
|
|
101
|
+
logger: mockLogger,
|
|
102
|
+
mapping: {},
|
|
103
|
+
};
|
|
104
|
+
destinationCode.push(createEvent({ name: 'product view' }), context);
|
|
105
|
+
expect(mockLogger.info).toHaveBeenCalledWith('settings fallback');
|
|
106
|
+
});
|
|
107
|
+
it('prefers mapping.push over settings.push', () => {
|
|
108
|
+
const mockLogger = createMockLogger();
|
|
109
|
+
const context = {
|
|
110
|
+
collector: createMockCollector(),
|
|
111
|
+
config: {
|
|
112
|
+
settings: {
|
|
113
|
+
push: "context.logger.info('from settings')",
|
|
114
|
+
},
|
|
115
|
+
},
|
|
116
|
+
data: {},
|
|
117
|
+
env: {},
|
|
118
|
+
logger: mockLogger,
|
|
119
|
+
mapping: {
|
|
120
|
+
push: "context.logger.info('from mapping')",
|
|
121
|
+
},
|
|
122
|
+
};
|
|
123
|
+
destinationCode.push(createEvent({ name: 'product view' }), context);
|
|
124
|
+
expect(mockLogger.info).toHaveBeenCalledWith('from mapping');
|
|
125
|
+
expect(mockLogger.info).not.toHaveBeenCalledWith('from settings');
|
|
126
|
+
});
|
|
127
|
+
it('handles missing push code gracefully', () => {
|
|
128
|
+
const context = {
|
|
129
|
+
collector: createMockCollector(),
|
|
130
|
+
config: {},
|
|
131
|
+
env: {},
|
|
132
|
+
logger: createMockLogger(),
|
|
133
|
+
mapping: {},
|
|
134
|
+
data: {},
|
|
135
|
+
};
|
|
136
|
+
expect(() => destinationCode.push(createEvent({ name: 'product view' }), context)).not.toThrow();
|
|
137
|
+
});
|
|
138
|
+
it('catches and logs errors in push code', () => {
|
|
139
|
+
const mockLogger = createMockLogger();
|
|
140
|
+
const context = {
|
|
141
|
+
collector: createMockCollector(),
|
|
142
|
+
config: {},
|
|
143
|
+
env: {},
|
|
144
|
+
logger: mockLogger,
|
|
145
|
+
mapping: {
|
|
146
|
+
push: "throw new Error('test error')",
|
|
147
|
+
},
|
|
148
|
+
data: {},
|
|
149
|
+
};
|
|
150
|
+
destinationCode.push(createEvent({ name: 'product view' }), context);
|
|
151
|
+
expect(mockLogger.error).toHaveBeenCalled();
|
|
152
|
+
});
|
|
153
|
+
});
|
|
154
|
+
describe('pushBatch', () => {
|
|
155
|
+
it('executes pushBatch code from mapping', () => {
|
|
156
|
+
const mockLogger = createMockLogger();
|
|
157
|
+
const batch = {
|
|
158
|
+
key: 'product view',
|
|
159
|
+
events: [
|
|
160
|
+
createEvent({ name: 'product view', id: '1' }),
|
|
161
|
+
createEvent({ name: 'product view', id: '2' }),
|
|
162
|
+
],
|
|
163
|
+
data: [{ id: '1' }, { id: '2' }],
|
|
164
|
+
};
|
|
165
|
+
const context = {
|
|
166
|
+
collector: createMockCollector(),
|
|
167
|
+
config: {},
|
|
168
|
+
env: {},
|
|
169
|
+
logger: mockLogger,
|
|
170
|
+
mapping: {
|
|
171
|
+
pushBatch: "context.logger.info('batch size:', batch.events.length)",
|
|
172
|
+
},
|
|
173
|
+
};
|
|
174
|
+
destinationCode.pushBatch(batch, context);
|
|
175
|
+
expect(mockLogger.info).toHaveBeenCalledWith('batch size:', 2);
|
|
176
|
+
});
|
|
177
|
+
it('falls back to settings.pushBatch when mapping.pushBatch is missing', () => {
|
|
178
|
+
const mockLogger = createMockLogger();
|
|
179
|
+
const batch = {
|
|
180
|
+
key: 'test',
|
|
181
|
+
events: [],
|
|
182
|
+
data: [],
|
|
183
|
+
};
|
|
184
|
+
const context = {
|
|
185
|
+
collector: createMockCollector(),
|
|
186
|
+
config: {
|
|
187
|
+
settings: {
|
|
188
|
+
pushBatch: "context.logger.info('batch settings fallback')",
|
|
189
|
+
},
|
|
190
|
+
},
|
|
191
|
+
env: {},
|
|
192
|
+
logger: mockLogger,
|
|
193
|
+
mapping: {},
|
|
194
|
+
};
|
|
195
|
+
destinationCode.pushBatch(batch, context);
|
|
196
|
+
expect(mockLogger.info).toHaveBeenCalledWith('batch settings fallback');
|
|
197
|
+
});
|
|
198
|
+
it('handles missing pushBatch code gracefully', () => {
|
|
199
|
+
const batch = {
|
|
200
|
+
key: 'test',
|
|
201
|
+
events: [],
|
|
202
|
+
data: [],
|
|
203
|
+
};
|
|
204
|
+
const context = {
|
|
205
|
+
collector: createMockCollector(),
|
|
206
|
+
config: {},
|
|
207
|
+
env: {},
|
|
208
|
+
logger: createMockLogger(),
|
|
209
|
+
mapping: {},
|
|
210
|
+
};
|
|
211
|
+
expect(() => destinationCode.pushBatch(batch, context)).not.toThrow();
|
|
212
|
+
});
|
|
213
|
+
it('catches and logs errors in pushBatch code', () => {
|
|
214
|
+
const mockLogger = createMockLogger();
|
|
215
|
+
const batch = {
|
|
216
|
+
key: 'test',
|
|
217
|
+
events: [],
|
|
218
|
+
data: [],
|
|
219
|
+
};
|
|
220
|
+
const context = {
|
|
221
|
+
collector: createMockCollector(),
|
|
222
|
+
config: {},
|
|
223
|
+
env: {},
|
|
224
|
+
logger: mockLogger,
|
|
225
|
+
mapping: {
|
|
226
|
+
pushBatch: "throw new Error('test error')",
|
|
227
|
+
},
|
|
228
|
+
};
|
|
229
|
+
destinationCode.pushBatch(batch, context);
|
|
230
|
+
expect(mockLogger.error).toHaveBeenCalled();
|
|
231
|
+
});
|
|
232
|
+
});
|
|
233
|
+
describe('on', () => {
|
|
234
|
+
it('executes on code string', () => {
|
|
235
|
+
const mockLogger = createMockLogger();
|
|
236
|
+
const context = {
|
|
237
|
+
collector: createMockCollector(),
|
|
238
|
+
config: {
|
|
239
|
+
settings: {
|
|
240
|
+
on: "if (type === 'consent') context.logger.info('consent:', context.data)",
|
|
241
|
+
},
|
|
242
|
+
},
|
|
243
|
+
data: { marketing: true },
|
|
244
|
+
env: {},
|
|
245
|
+
logger: mockLogger,
|
|
246
|
+
};
|
|
247
|
+
destinationCode.on('consent', context);
|
|
248
|
+
expect(mockLogger.info).toHaveBeenCalledWith('consent:', {
|
|
249
|
+
marketing: true,
|
|
250
|
+
});
|
|
251
|
+
});
|
|
252
|
+
it('handles missing on code gracefully', () => {
|
|
253
|
+
const context = {
|
|
254
|
+
collector: createMockCollector(),
|
|
255
|
+
config: { settings: {} },
|
|
256
|
+
env: {},
|
|
257
|
+
logger: createMockLogger(),
|
|
258
|
+
};
|
|
259
|
+
expect(() => destinationCode.on('consent', context)).not.toThrow();
|
|
260
|
+
});
|
|
261
|
+
it('catches and logs errors in on code', () => {
|
|
262
|
+
const mockLogger = createMockLogger();
|
|
263
|
+
const context = {
|
|
264
|
+
collector: createMockCollector(),
|
|
265
|
+
config: {
|
|
266
|
+
settings: {
|
|
267
|
+
on: "throw new Error('test error')",
|
|
268
|
+
},
|
|
269
|
+
},
|
|
270
|
+
env: {},
|
|
271
|
+
logger: mockLogger,
|
|
272
|
+
};
|
|
273
|
+
destinationCode.on('consent', context);
|
|
274
|
+
expect(mockLogger.error).toHaveBeenCalled();
|
|
275
|
+
});
|
|
276
|
+
});
|
|
277
|
+
});
|
|
278
|
+
describe('code: true initialization', () => {
|
|
279
|
+
it('uses built-in destinationCode when code is true', async () => {
|
|
280
|
+
const collector = {
|
|
281
|
+
logger: createMockLogger(),
|
|
282
|
+
};
|
|
283
|
+
const destinations = await initDestinations(collector, {
|
|
284
|
+
myCodeDest: {
|
|
285
|
+
code: true,
|
|
286
|
+
config: {
|
|
287
|
+
settings: {
|
|
288
|
+
init: "context.logger.info('ready')",
|
|
289
|
+
},
|
|
290
|
+
},
|
|
291
|
+
},
|
|
292
|
+
});
|
|
293
|
+
expect(destinations.myCodeDest).toBeDefined();
|
|
294
|
+
expect(destinations.myCodeDest.type).toBe('code');
|
|
295
|
+
expect(destinations.myCodeDest.init).toBeDefined();
|
|
296
|
+
expect(destinations.myCodeDest.push).toBeDefined();
|
|
297
|
+
});
|
|
298
|
+
it('preserves provided config with code: true', async () => {
|
|
299
|
+
const collector = {
|
|
300
|
+
logger: createMockLogger(),
|
|
301
|
+
};
|
|
302
|
+
const destinations = await initDestinations(collector, {
|
|
303
|
+
myCodeDest: {
|
|
304
|
+
code: true,
|
|
305
|
+
config: {
|
|
306
|
+
settings: {
|
|
307
|
+
init: "context.logger.info('custom init')",
|
|
308
|
+
push: "context.logger.info('custom push')",
|
|
309
|
+
},
|
|
310
|
+
consent: { functional: true },
|
|
311
|
+
},
|
|
312
|
+
},
|
|
313
|
+
});
|
|
314
|
+
expect(destinations.myCodeDest.config.settings).toEqual({
|
|
315
|
+
init: "context.logger.info('custom init')",
|
|
316
|
+
push: "context.logger.info('custom push')",
|
|
317
|
+
});
|
|
318
|
+
expect(destinations.myCodeDest.config.consent).toEqual({
|
|
319
|
+
functional: true,
|
|
320
|
+
});
|
|
321
|
+
});
|
|
322
|
+
});
|
|
323
|
+
//# sourceMappingURL=destination-code.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"destination-code.test.js","sourceRoot":"","sources":["../../src/__tests__/destination-code.test.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;AAC/D,OAAO,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAC;AACtD,OAAO,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;AAUlD,QAAQ,CAAC,iBAAiB,EAAE,GAAG,EAAE;IAC/B,MAAM,mBAAmB,GAAG,GAAuB,EAAE,CACnD,CAAC;QACC,OAAO,EAAE,EAAE;QACX,YAAY,EAAE,EAAE;QAChB,OAAO,EAAE,EAAE;QACX,KAAK,EAAE,EAAE;QACT,KAAK,EAAE,EAAE;QACT,EAAE,EAAE,EAAE;QACN,OAAO,EAAE,EAAE;QACX,IAAI,EAAE,EAAE;QACR,OAAO,EAAE,IAAI;QACb,MAAM,EAAE,EAAE;QACV,KAAK,EAAE,CAAC;QACR,MAAM,EAAE,gBAAgB,EAAE;QAC1B,IAAI,EAAE,IAAI,CAAC,EAAE,EAAE;KAChB,CAAkC,CAAC;IAEtC,UAAU,CAAC,GAAG,EAAE;QACd,IAAI,CAAC,aAAa,EAAE,CAAC;IACvB,CAAC,CAAC,CAAC;IAEH,QAAQ,CAAC,kBAAkB,EAAE,GAAG,EAAE;QAChC,EAAE,CAAC,0BAA0B,EAAE,GAAG,EAAE;YAClC,MAAM,CAAC,eAAe,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;QAC5C,CAAC,CAAC,CAAC;QAEH,EAAE,CAAC,kCAAkC,EAAE,GAAG,EAAE;YAC1C,M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C9C,MAAM,CAAC,YAAY,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;QAClD,MAAM,CAAC,YAAY,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC,WAAW,EAAE,CAAC;QACnD,MAAM,CAAC,YAAY,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC,WAAW,EAAE,CAAC;IACrD,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,2CAA2C,EAAE,KAAK,IAAI,EAAE;QACzD,MAAM,SAAS,GAAG;YAChB,MAAM,EAAE,gBAAgB,EAAE;SACM,CAAC;QAEnC,MAAM,YAAY,GAAG,MAAM,gBAAgB,CAAC,SAAS,EAAE;YACrD,UAAU,EAAE;gBACV,IAAI,EAAE,IAAuC;gBAC7C,MAAM,EAAE;oBACN,QAAQ,EAAE;wBACR,IAAI,EAAE,oCAAoC;wBAC1C,IAAI,EAAE,oCAAoC;qBAC3C;oBACD,OAAO,EAAE,EAAE,UAAU,EAAE,IAAI,EAAE;iBAC9B;aACF;SACF,CAAC,CAAC;QAEH,MAAM,CAAC,YAAY,CAAC,UAAU,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC,OAAO,CAAC;YACtD,IAAI,EAAE,oCAAoC;YAC1C,IAAI,EAAE,oCAAoC;SAC3C,CAAC,CAAC;QACH,MAAM,CAAC,YAAY,CAAC,UAAU,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,OAAO,CAAC;YACrD,UAAU,EAAE,IAAI;SACjB,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { clone, createEvent } from '@walkeros/core';
|
|
1
|
+
import { clone, createEvent, createMockLogger } from '@walkeros/core';
|
|
2
2
|
import { pushToDestinations, startFlow } from '..';
|
|
3
3
|
describe('Destination', () => {
|
|
4
4
|
let event;
|
|
@@ -17,7 +17,6 @@ describe('Destination', () => {
|
|
|
17
17
|
function createTestConfig(overrides = {}) {
|
|
18
18
|
return {
|
|
19
19
|
tagging: 1,
|
|
20
|
-
verbose: false,
|
|
21
20
|
globalsStatic: {},
|
|
22
21
|
sessionStatic: {},
|
|
23
22
|
...overrides,
|
|
@@ -25,11 +24,16 @@ describe('Destination', () => {
|
|
|
25
24
|
}
|
|
26
25
|
function createWalkerjs(args) {
|
|
27
26
|
const defaultConfig = createTestConfig();
|
|
27
|
+
// Create mock logger with proper scope chaining
|
|
28
|
+
const mockLogger = createMockLogger();
|
|
29
|
+
const scopedMockLogger = createMockLogger();
|
|
30
|
+
mockLogger.scope = jest.fn().mockReturnValue(scopedMockLogger);
|
|
28
31
|
return {
|
|
29
32
|
allowed: true,
|
|
30
33
|
destinations: { foo: destination },
|
|
31
34
|
globals: {},
|
|
32
35
|
hooks: {},
|
|
36
|
+
logger: mockLogger,
|
|
33
37
|
user: {},
|
|
34
38
|
consent: {},
|
|
35
39
|
queue: [],
|
|
@@ -84,6 +88,36 @@ describe('Destination', () => {
|
|
|
84
88
|
expect(mockPush).toHaveBeenCalledTimes(0);
|
|
85
89
|
expect(destination.config.init).toBeFalsy();
|
|
86
90
|
});
|
|
91
|
+
test('logs init lifecycle', async () => {
|
|
92
|
+
const collector = createWalkerjs();
|
|
93
|
+
await pushToDestinations(collector, event);
|
|
94
|
+
expect(mockInit).toHaveBeenCalledTimes(1);
|
|
95
|
+
expect(mockPush).toHaveBeenCalledTimes(1);
|
|
96
|
+
// Verify logger.scope was called with destination type
|
|
97
|
+
expect(collector.logger.scope).toHaveBeenCalledWith('unknown');
|
|
98
|
+
// Get the scoped logger instance
|
|
99
|
+
const scopedLogger = collector.logger.scope.mock.results[0]
|
|
100
|
+
.value;
|
|
101
|
+
// Verify init lifecycle logs
|
|
102
|
+
expect(scopedLogger.debug).toHaveBeenCalledWith('init');
|
|
103
|
+
expect(scopedLogger.debug).toHaveBeenCalledWith('init done');
|
|
104
|
+
});
|
|
105
|
+
test('logs push lifecycle', async () => {
|
|
106
|
+
const collector = createWalkerjs();
|
|
107
|
+
destination.config.init = true; // Skip init for this test
|
|
108
|
+
await pushToDestinations(collector, event);
|
|
109
|
+
expect(mockPush).toHaveBeenCalledTimes(1);
|
|
110
|
+
// Verify logger.scope was called with destination type
|
|
111
|
+
expect(collector.logger.scope).toHaveBeenCalledWith('unknown');
|
|
112
|
+
// Get the scoped logger instance
|
|
113
|
+
const scopedLogger = collector.logger.scope.mock.results[0]
|
|
114
|
+
.value;
|
|
115
|
+
// Verify push lifecycle logs
|
|
116
|
+
expect(scopedLogger.debug).toHaveBeenCalledWith('push', {
|
|
117
|
+
event: event.name,
|
|
118
|
+
});
|
|
119
|
+
expect(scopedLogger.debug).toHaveBeenCalledWith('push done');
|
|
120
|
+
});
|
|
87
121
|
test('DLQ', async () => {
|
|
88
122
|
const event = createEvent();
|
|
89
123
|
// Simulate a failing push
|
|
@@ -116,7 +150,13 @@ describe('Destination', () => {
|
|
|
116
150
|
// Trigger consent event
|
|
117
151
|
await elb('walker consent', { marketing: true });
|
|
118
152
|
// Verify the destination's on method was called with consent context
|
|
119
|
-
expect(mockOnMethod).toHaveBeenCalledWith('consent', {
|
|
153
|
+
expect(mockOnMethod).toHaveBeenCalledWith('consent', expect.objectContaining({
|
|
154
|
+
data: { marketing: true },
|
|
155
|
+
collector: expect.any(Object),
|
|
156
|
+
config: expect.any(Object),
|
|
157
|
+
env: expect.any(Object),
|
|
158
|
+
logger: expect.any(Object),
|
|
159
|
+
}));
|
|
120
160
|
});
|
|
121
161
|
it('should call destination on method when session event is triggered', async () => {
|
|
122
162
|
const destinationWithOn = createDestination({
|
|
@@ -135,7 +175,13 @@ describe('Destination', () => {
|
|
|
135
175
|
};
|
|
136
176
|
await elb('walker session');
|
|
137
177
|
// Verify the destination's on method was called with session context
|
|
138
|
-
expect(mockOnMethod).toHaveBeenCalledWith('session',
|
|
178
|
+
expect(mockOnMethod).toHaveBeenCalledWith('session', expect.objectContaining({
|
|
179
|
+
data: collector.session,
|
|
180
|
+
collector: expect.any(Object),
|
|
181
|
+
config: expect.any(Object),
|
|
182
|
+
env: expect.any(Object),
|
|
183
|
+
logger: expect.any(Object),
|
|
184
|
+
}));
|
|
139
185
|
});
|
|
140
186
|
it('should call destination on method when ready event is triggered', async () => {
|
|
141
187
|
const destinationWithOn = createDestination({
|
|
@@ -148,7 +194,13 @@ describe('Destination', () => {
|
|
|
148
194
|
// Trigger ready event
|
|
149
195
|
await elb('walker ready');
|
|
150
196
|
// Verify the destination's on method was called
|
|
151
|
-
expect(mockOnMethod).toHaveBeenCalledWith('ready',
|
|
197
|
+
expect(mockOnMethod).toHaveBeenCalledWith('ready', expect.objectContaining({
|
|
198
|
+
data: undefined,
|
|
199
|
+
collector: expect.any(Object),
|
|
200
|
+
config: expect.any(Object),
|
|
201
|
+
env: expect.any(Object),
|
|
202
|
+
logger: expect.any(Object),
|
|
203
|
+
}));
|
|
152
204
|
});
|
|
153
205
|
it('should call destination on method when run event is triggered', async () => {
|
|
154
206
|
const destinationWithOn = createDestination({
|
|
@@ -161,7 +213,13 @@ describe('Destination', () => {
|
|
|
161
213
|
// Trigger run event
|
|
162
214
|
await elb('walker run');
|
|
163
215
|
// Verify the destination's on method was called
|
|
164
|
-
expect(mockOnMethod).toHaveBeenCalledWith('run',
|
|
216
|
+
expect(mockOnMethod).toHaveBeenCalledWith('run', expect.objectContaining({
|
|
217
|
+
data: undefined,
|
|
218
|
+
collector: expect.any(Object),
|
|
219
|
+
config: expect.any(Object),
|
|
220
|
+
env: expect.any(Object),
|
|
221
|
+
logger: expect.any(Object),
|
|
222
|
+
}));
|
|
165
223
|
});
|
|
166
224
|
it('should not fail if destination does not have on method', async () => {
|
|
167
225
|
const destinationWithoutOn = createDestination({
|
|
@@ -190,9 +248,13 @@ describe('Destination', () => {
|
|
|
190
248
|
// Trigger consent event
|
|
191
249
|
await elb('walker consent', { marketing: true });
|
|
192
250
|
// Verify the async destination's on method was called
|
|
193
|
-
expect(asyncOnMethod).toHaveBeenCalledWith('consent', {
|
|
194
|
-
marketing: true,
|
|
195
|
-
|
|
251
|
+
expect(asyncOnMethod).toHaveBeenCalledWith('consent', expect.objectContaining({
|
|
252
|
+
data: { marketing: true },
|
|
253
|
+
collector: expect.any(Object),
|
|
254
|
+
config: expect.any(Object),
|
|
255
|
+
env: expect.any(Object),
|
|
256
|
+
logger: expect.any(Object),
|
|
257
|
+
}));
|
|
196
258
|
});
|
|
197
259
|
it('should call on method for multiple destinations', async () => {
|
|
198
260
|
const mockOn1 = jest.fn();
|
|
@@ -214,8 +276,20 @@ describe('Destination', () => {
|
|
|
214
276
|
// Trigger consent event
|
|
215
277
|
await elb('walker consent', { marketing: true });
|
|
216
278
|
// Both destinations should receive the event
|
|
217
|
-
expect(mockOn1).toHaveBeenCalledWith('consent', {
|
|
218
|
-
|
|
279
|
+
expect(mockOn1).toHaveBeenCalledWith('consent', expect.objectContaining({
|
|
280
|
+
data: { marketing: true },
|
|
281
|
+
collector: expect.any(Object),
|
|
282
|
+
config: expect.any(Object),
|
|
283
|
+
env: expect.any(Object),
|
|
284
|
+
logger: expect.any(Object),
|
|
285
|
+
}));
|
|
286
|
+
expect(mockOn2).toHaveBeenCalledWith('consent', expect.objectContaining({
|
|
287
|
+
data: { marketing: true },
|
|
288
|
+
collector: expect.any(Object),
|
|
289
|
+
config: expect.any(Object),
|
|
290
|
+
env: expect.any(Object),
|
|
291
|
+
logger: expect.any(Object),
|
|
292
|
+
}));
|
|
219
293
|
});
|
|
220
294
|
it('should handle on method errors gracefully', async () => {
|
|
221
295
|
const errorOnMethod = jest.fn().mockImplementation(() => {
|
|
@@ -233,9 +307,13 @@ describe('Destination', () => {
|
|
|
233
307
|
await elb('walker consent', { marketing: true });
|
|
234
308
|
}).not.toThrow();
|
|
235
309
|
// On method should still have been called
|
|
236
|
-
expect(errorOnMethod).toHaveBeenCalledWith('consent', {
|
|
237
|
-
marketing: true,
|
|
238
|
-
|
|
310
|
+
expect(errorOnMethod).toHaveBeenCalledWith('consent', expect.objectContaining({
|
|
311
|
+
data: { marketing: true },
|
|
312
|
+
collector: expect.any(Object),
|
|
313
|
+
config: expect.any(Object),
|
|
314
|
+
env: expect.any(Object),
|
|
315
|
+
logger: expect.any(Object),
|
|
316
|
+
}));
|
|
239
317
|
});
|
|
240
318
|
});
|
|
241
319
|
});
|