@walkeros/collector 0.4.2 → 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.d.ts +2 -0
- package/dist/__tests__/auto-run.test.d.ts.map +1 -0
- package/dist/__tests__/auto-run.test.js +102 -0
- package/dist/__tests__/auto-run.test.js.map +1 -0
- package/dist/__tests__/consent.test.d.ts +2 -0
- package/dist/__tests__/consent.test.d.ts.map +1 -0
- package/dist/__tests__/consent.test.js +21 -0
- package/dist/__tests__/consent.test.js.map +1 -0
- package/dist/__tests__/create-flow.test.d.ts +2 -0
- package/dist/__tests__/create-flow.test.d.ts.map +1 -0
- package/dist/__tests__/create-flow.test.js +69 -0
- package/dist/__tests__/create-flow.test.js.map +1 -0
- 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.d.ts +2 -0
- package/dist/__tests__/destination.test.d.ts.map +1 -0
- package/dist/__tests__/destination.test.js +320 -0
- package/dist/__tests__/destination.test.js.map +1 -0
- package/dist/__tests__/handle.test.d.ts +2 -0
- package/dist/__tests__/handle.test.d.ts.map +1 -0
- package/dist/__tests__/handle.test.js +78 -0
- package/dist/__tests__/handle.test.js.map +1 -0
- package/dist/__tests__/mapping.test.d.ts +2 -0
- package/dist/__tests__/mapping.test.d.ts.map +1 -0
- package/dist/__tests__/mapping.test.js +310 -0
- package/dist/__tests__/mapping.test.js.map +1 -0
- package/dist/__tests__/source.test.d.ts +2 -0
- package/dist/__tests__/source.test.d.ts.map +1 -0
- package/dist/__tests__/source.test.js +306 -0
- package/dist/__tests__/source.test.js.map +1 -0
- package/dist/__tests__/start-flow.test.d.ts +2 -0
- package/dist/__tests__/start-flow.test.d.ts.map +1 -0
- package/dist/__tests__/start-flow.test.js +167 -0
- package/dist/__tests__/start-flow.test.js.map +1 -0
- package/dist/__tests__/walker-entity.test.d.ts +2 -0
- package/dist/__tests__/walker-entity.test.d.ts.map +1 -0
- package/dist/__tests__/walker-entity.test.js +52 -0
- package/dist/__tests__/walker-entity.test.js.map +1 -0
- package/dist/collector.d.ts +3 -0
- package/dist/collector.d.ts.map +1 -0
- package/dist/collector.js +60 -0
- package/dist/collector.js.map +1 -0
- package/dist/command.d.ts +12 -0
- package/dist/command.d.ts.map +1 -0
- package/dist/command.js +20 -0
- package/dist/command.js.map +1 -0
- package/dist/consent.d.ts +10 -0
- package/dist/consent.d.ts.map +1 -0
- package/dist/consent.js +30 -0
- package/dist/consent.js.map +1 -0
- package/dist/constants.d.ts +13 -0
- package/dist/constants.d.ts.map +1 -0
- package/dist/constants.js +35 -0
- package/dist/constants.js.map +1 -0
- 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 +61 -0
- package/dist/destination.d.ts.map +1 -0
- package/dist/destination.js +314 -0
- package/dist/destination.js.map +1 -0
- package/dist/dev.d.ts.map +1 -0
- package/dist/elb.d.ts +11 -0
- package/dist/elb.d.ts.map +1 -0
- package/dist/elb.js +60 -0
- package/dist/elb.js.map +1 -0
- package/dist/flow.d.ts +4 -0
- package/dist/flow.d.ts.map +1 -0
- package/dist/flow.js +44 -0
- package/dist/flow.js.map +1 -0
- package/dist/handle.d.ts +29 -0
- package/dist/handle.d.ts.map +1 -0
- package/dist/handle.js +161 -0
- package/dist/handle.js.map +1 -0
- package/dist/index.d.mts +46 -2
- package/dist/index.d.ts +46 -2
- package/dist/index.d.ts.map +1 -0
- 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 +19 -0
- package/dist/on.d.ts.map +1 -0
- package/dist/on.js +127 -0
- package/dist/on.js.map +1 -0
- package/dist/push.d.ts +11 -0
- package/dist/push.d.ts.map +1 -0
- package/dist/push.js +43 -0
- package/dist/push.js.map +1 -0
- package/dist/schemas.d.ts +4 -0
- package/dist/schemas.d.ts.map +1 -0
- package/dist/schemas.js +35 -0
- package/dist/schemas.js.map +1 -0
- package/dist/source.d.ts +10 -0
- package/dist/source.d.ts.map +1 -0
- package/dist/source.js +47 -0
- package/dist/source.js.map +1 -0
- 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/collector.d.ts +19 -0
- package/dist/types/collector.d.ts.map +1 -0
- package/dist/types/collector.js +2 -0
- package/dist/types/collector.js.map +1 -0
- package/dist/types/index.d.ts +3 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/index.js +4 -0
- package/dist/types/index.js.map +1 -0
- 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
|
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"auto-run.test.d.ts","sourceRoot":"","sources":["../../src/__tests__/auto-run.test.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
import { startFlow } from '..';
|
|
2
|
+
describe('Auto-run functionality', () => {
|
|
3
|
+
describe('startFlow auto-run behavior', () => {
|
|
4
|
+
test('auto-runs by default (collector.allowed should be true)', async () => {
|
|
5
|
+
const { collector } = await startFlow();
|
|
6
|
+
// Default behavior should auto-run and set allowed to true
|
|
7
|
+
expect(collector.allowed).toBe(true);
|
|
8
|
+
expect(collector.config.run).toBe(true);
|
|
9
|
+
});
|
|
10
|
+
test('auto-runs when explicitly set to true (collector.allowed should be true)', async () => {
|
|
11
|
+
const { collector } = await startFlow({ run: true });
|
|
12
|
+
// Explicitly setting run: true should auto-run and set allowed to true
|
|
13
|
+
expect(collector.allowed).toBe(true);
|
|
14
|
+
expect(collector.config.run).toBe(true);
|
|
15
|
+
});
|
|
16
|
+
test('does not auto-run when set to false (collector.allowed should be false)', async () => {
|
|
17
|
+
const { collector } = await startFlow({ run: false });
|
|
18
|
+
// Setting run: false should NOT auto-run and allowed should stay false
|
|
19
|
+
expect(collector.allowed).toBe(false);
|
|
20
|
+
expect(collector.config.run).toBe(false);
|
|
21
|
+
});
|
|
22
|
+
test('manual run after initialization with run: false should set allowed to true', async () => {
|
|
23
|
+
const { collector, elb } = await startFlow({ run: false });
|
|
24
|
+
// Initially should not be allowed
|
|
25
|
+
expect(collector.allowed).toBe(false);
|
|
26
|
+
// Manual run should set allowed to true
|
|
27
|
+
await elb('walker run');
|
|
28
|
+
expect(collector.allowed).toBe(true);
|
|
29
|
+
});
|
|
30
|
+
test('config state is preserved correctly for different run values', async () => {
|
|
31
|
+
// Test with run: true
|
|
32
|
+
const collectorTrue = await startFlow({ run: true });
|
|
33
|
+
expect(collectorTrue.collector.config.run).toBe(true);
|
|
34
|
+
expect(collectorTrue.collector.allowed).toBe(true);
|
|
35
|
+
// Test with run: false
|
|
36
|
+
const collectorFalse = await startFlow({
|
|
37
|
+
run: false,
|
|
38
|
+
});
|
|
39
|
+
expect(collectorFalse.collector.config.run).toBe(false);
|
|
40
|
+
expect(collectorFalse.collector.allowed).toBe(false);
|
|
41
|
+
});
|
|
42
|
+
});
|
|
43
|
+
describe('auto-run with additional configuration', () => {
|
|
44
|
+
test('applies consent during auto-run', async () => {
|
|
45
|
+
const testConsent = { functional: true, marketing: false };
|
|
46
|
+
const { collector } = await startFlow({
|
|
47
|
+
run: true,
|
|
48
|
+
consent: testConsent,
|
|
49
|
+
});
|
|
50
|
+
expect(collector.allowed).toBe(true);
|
|
51
|
+
expect(collector.consent).toEqual(testConsent);
|
|
52
|
+
});
|
|
53
|
+
test('applies user data during auto-run', async () => {
|
|
54
|
+
const testUser = { id: 'test-user-123', custom: { type: 'premium' } };
|
|
55
|
+
const { collector } = await startFlow({
|
|
56
|
+
run: true,
|
|
57
|
+
user: testUser,
|
|
58
|
+
});
|
|
59
|
+
expect(collector.allowed).toBe(true);
|
|
60
|
+
expect(collector.user).toEqual(testUser);
|
|
61
|
+
});
|
|
62
|
+
test('applies globals during auto-run', async () => {
|
|
63
|
+
const testGlobals = { page_title: 'Test Page', environment: 'test' };
|
|
64
|
+
const { collector } = await startFlow({
|
|
65
|
+
run: true,
|
|
66
|
+
globals: testGlobals,
|
|
67
|
+
});
|
|
68
|
+
expect(collector.allowed).toBe(true);
|
|
69
|
+
expect(collector.globals).toEqual(expect.objectContaining(testGlobals));
|
|
70
|
+
});
|
|
71
|
+
test('applies custom data during auto-run', async () => {
|
|
72
|
+
const testCustom = { tracking_id: 'GTM-12345', debug: true };
|
|
73
|
+
const { collector } = await startFlow({
|
|
74
|
+
run: true,
|
|
75
|
+
custom: testCustom,
|
|
76
|
+
});
|
|
77
|
+
expect(collector.allowed).toBe(true);
|
|
78
|
+
expect(collector.custom).toEqual(testCustom);
|
|
79
|
+
});
|
|
80
|
+
test('does not apply additional config when run: false', async () => {
|
|
81
|
+
const testConsent = { functional: true, marketing: false };
|
|
82
|
+
const testUser = { id: 'test-user-123' };
|
|
83
|
+
const testGlobals = { page_title: 'Test Page' };
|
|
84
|
+
const testCustom = { tracking_id: 'GTM-12345' };
|
|
85
|
+
const { collector } = await startFlow({
|
|
86
|
+
run: false,
|
|
87
|
+
consent: testConsent,
|
|
88
|
+
user: testUser,
|
|
89
|
+
globals: testGlobals,
|
|
90
|
+
custom: testCustom,
|
|
91
|
+
});
|
|
92
|
+
// Should not be allowed since we didn't run
|
|
93
|
+
expect(collector.allowed).toBe(false);
|
|
94
|
+
// But the config should still be stored for potential later use
|
|
95
|
+
expect(collector.consent).toEqual(testConsent);
|
|
96
|
+
expect(collector.user).toEqual(testUser);
|
|
97
|
+
expect(collector.globals).toEqual(expect.objectContaining(testGlobals));
|
|
98
|
+
expect(collector.custom).toEqual(testCustom);
|
|
99
|
+
});
|
|
100
|
+
});
|
|
101
|
+
});
|
|
102
|
+
//# sourceMappingURL=auto-run.test.js.map
|
|
@@ -0,0 +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;YA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U,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":"consent.test.d.ts","sourceRoot":"","sources":["../../src/__tests__/consent.test.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { getGrantedConsent } from '@walkeros/core';
|
|
2
|
+
describe('consent', () => {
|
|
3
|
+
test('nothing required', () => {
|
|
4
|
+
expect(getGrantedConsent(undefined, { foo: true })).toStrictEqual({
|
|
5
|
+
foo: true,
|
|
6
|
+
});
|
|
7
|
+
});
|
|
8
|
+
test('denied', () => {
|
|
9
|
+
expect(getGrantedConsent({ marketing: true }, { functional: true, marketing: false })).toBeFalsy();
|
|
10
|
+
});
|
|
11
|
+
test('granted by destination', () => {
|
|
12
|
+
expect(getGrantedConsent({ functional: true }, { functional: true })).toStrictEqual({ functional: true });
|
|
13
|
+
});
|
|
14
|
+
test('granted individually', () => {
|
|
15
|
+
expect(getGrantedConsent({ marketing: true }, { marketing: false }, { marketing: true })).toStrictEqual({ marketing: true });
|
|
16
|
+
});
|
|
17
|
+
test('granted states', () => {
|
|
18
|
+
expect(getGrantedConsent({ foo: true }, { foo: true }, { bar: true })).toStrictEqual({ foo: true, bar: true });
|
|
19
|
+
});
|
|
20
|
+
});
|
|
21
|
+
//# sourceMappingURL=consent.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"consent.test.js","sourceRoot":"","sources":["../../src/__tests__/consent.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAC;AAEnD,QAAQ,CAAC,SAAS,EAAE,GAAG,EAAE;IACvB,IAAI,CAAC,kBAAkB,EAAE,GAAG,EAAE;QAC5B,MAAM,CAAC,iBAAiB,CAAC,SAAS,EAAE,EAAE,GAAG,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC,aAAa,CAAC;YAChE,GAAG,EAAE,IAAI;SACV,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;IAEH,IAAI,CAAC,QAAQ,EAAE,GAAG,EAAE;QAClB,MAAM,CACJ,iBAAiB,CACf,EAAE,SAAS,EAAE,IAAI,EAAE,EACnB,EAAE,UAAU,EAAE,IAAI,EAAE,SAAS,EAAE,KAAK,EAAE,CACvC,CACF,CAAC,SAAS,EAAE,CAAC;IAChB,CAAC,CAAC,CAAC;IAEH,IAAI,CAAC,wBAAwB,EAAE,GAAG,EAAE;QAClC,MAAM,CACJ,iBAAiB,CAAC,EAAE,UAAU,EAAE,IAAI,EAAE,EAAE,EAAE,UAAU,EAAE,IAAI,EAAE,CAAC,CAC9D,CAAC,aAAa,CAAC,EAAE,UAAU,EAAE,IAAI,EAAE,CAAC,CAAC;IACxC,CAAC,CAAC,CAAC;IAEH,IAAI,CAAC,sBAAsB,EAAE,GAAG,EAAE;QAChC,MAAM,CACJ,iBAAiB,CACf,EAAE,SAAS,EAAE,IAAI,EAAE,EACnB,EAAE,SAAS,EAAE,KAAK,EAAE,EACpB,EAAE,SAAS,EAAE,IAAI,EAAE,CACpB,CACF,CAAC,aAAa,CAAC,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC;IACvC,CAAC,CAAC,CAAC;IAEH,IAAI,CAAC,gBAAgB,EAAE,GAAG,EAAE;QAC1B,MAAM,CACJ,iBAAiB,CAAC,EAAE,GAAG,EAAE,IAAI,EAAE,EAAE,EAAE,GAAG,EAAE,IAAI,EAAE,EAAE,EAAE,GAAG,EAAE,IAAI,EAAE,CAAC,CAC/D,CAAC,aAAa,CAAC,EAAE,GAAG,EAAE,IAAI,EAAE,GAAG,EAAE,IAAI,EAAE,CAAC,CAAC;IAC5C,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"create-flow.test.d.ts","sourceRoot":"","sources":["../../src/__tests__/create-flow.test.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import { startFlow } from '../flow';
|
|
2
|
+
describe('Source Create Flow Integration', () => {
|
|
3
|
+
it('should initialize complete setup from flow config', async () => {
|
|
4
|
+
const mockPushCalls = [];
|
|
5
|
+
const mockSource = async (config, env) => {
|
|
6
|
+
expect(config).toEqual({
|
|
7
|
+
settings: {
|
|
8
|
+
test: 'value',
|
|
9
|
+
},
|
|
10
|
+
});
|
|
11
|
+
expect(env).toMatchObject({
|
|
12
|
+
push: expect.any(Function),
|
|
13
|
+
command: expect.any(Function),
|
|
14
|
+
sources: expect.any(Object),
|
|
15
|
+
elb: expect.any(Function),
|
|
16
|
+
foo: 'bar',
|
|
17
|
+
});
|
|
18
|
+
return {
|
|
19
|
+
type: 'mock',
|
|
20
|
+
config: {
|
|
21
|
+
settings: config.settings || {},
|
|
22
|
+
},
|
|
23
|
+
push: env.push, // Required push method
|
|
24
|
+
};
|
|
25
|
+
};
|
|
26
|
+
const { collector, elb } = await startFlow({
|
|
27
|
+
sources: {
|
|
28
|
+
mockSource: {
|
|
29
|
+
code: mockSource,
|
|
30
|
+
config: {
|
|
31
|
+
settings: {
|
|
32
|
+
test: 'value',
|
|
33
|
+
},
|
|
34
|
+
},
|
|
35
|
+
env: {
|
|
36
|
+
foo: 'bar',
|
|
37
|
+
// elb will be injected by collector
|
|
38
|
+
},
|
|
39
|
+
},
|
|
40
|
+
},
|
|
41
|
+
destinations: {
|
|
42
|
+
test: {
|
|
43
|
+
code: {
|
|
44
|
+
type: 'test',
|
|
45
|
+
config: {},
|
|
46
|
+
push: (event) => {
|
|
47
|
+
mockPushCalls.push(event);
|
|
48
|
+
},
|
|
49
|
+
},
|
|
50
|
+
},
|
|
51
|
+
},
|
|
52
|
+
});
|
|
53
|
+
expect(collector.sources.mockSource).toEqual({
|
|
54
|
+
type: 'mock',
|
|
55
|
+
config: {
|
|
56
|
+
settings: { test: 'value' },
|
|
57
|
+
},
|
|
58
|
+
push: expect.any(Function),
|
|
59
|
+
});
|
|
60
|
+
expect(collector.sources.elb).toBeDefined();
|
|
61
|
+
await elb({ name: 'manual event', data: { test: 'data' } });
|
|
62
|
+
expect(mockPushCalls).toHaveLength(1);
|
|
63
|
+
expect(mockPushCalls[0]).toMatchObject({
|
|
64
|
+
name: 'manual event',
|
|
65
|
+
data: { test: 'data' },
|
|
66
|
+
});
|
|
67
|
+
});
|
|
68
|
+
});
|
|
69
|
+
//# sourceMappingURL=create-flow.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|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ACF;aACF;YACD,YAAY,EAAE;gBACZ,IAAI,EAAE;oBACJ,IAAI,EAAE;wBACJ,IAAI,EAAE,MAAM;wBACZ,MAAM,EAAE,EAAE;wBACV,IAAI,EAAE,CAAC,KAAqB,EAAE,EAAE;4BAC9B,aAAa,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;wBAC5B,CAAC;qBACF;iBACF;aACF;SACF,CAAC,CAAC;QAEH,MAAM,CAAC,SAAS,CAAC,OAAO,CAAC,UAAU,CAAC,CAAC,OAAO,CAAC;YAC3C,IAAI,EAAE,MAAM;YACZ,MAAM,EAAE;gBACN,QAAQ,EAAE,EAAE,IAAI,EAAE,OAAO,EAAE;aAC5B;YACD,IAAI,EAAE,MAAM,CAAC,GAAG,CAAC,QAAQ,CAAC;SAC3B,CAAC,CAAC;QACH,MAAM,CAAC,SAAS,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,WAAW,EAAE,CAAC;QAE5C,MAAM,GAAG,CAAC,EAAE,IAAI,EAAE,cAAc,EAAE,IAAI,EAAE,EAAE,IAAI,EAAE,MAAM,EAAE,EAAE,CAAC,CAAC;QAE5D,MAAM,CAAC,aAAa,CAAC,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC;QACtC,MAAM,CAAC,aAAa,CAAC,CAAC,CAAC,CAAC,CAAC,aAAa,CAAC;YACrC,IAAI,EAAE,cAAc;YACpB,IAAI,EAAE,EAAE,IAAI,EAAE,MAAM,EAAE;SACvB,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
|