@walkeros/core 4.1.0-next-1778668930820 → 4.1.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/CHANGELOG.md +1089 -0
- package/README.md +13 -413
- package/dist/dev.d.mts +1043 -358
- package/dist/dev.d.ts +1043 -358
- 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 +542 -119
- package/dist/index.d.ts +542 -119
- 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/package.json +3 -2
package/README.md
CHANGED
|
@@ -4,14 +4,15 @@
|
|
|
4
4
|
</a>
|
|
5
5
|
</p>
|
|
6
6
|
|
|
7
|
-
#
|
|
7
|
+
# @walkeros/core
|
|
8
8
|
|
|
9
|
-
|
|
10
|
-
|
|
9
|
+
Platform-agnostic types and utilities used across all walkerOS environments,
|
|
10
|
+
providing standardized building blocks for data manipulation, validation, and
|
|
11
|
+
mapping.
|
|
11
12
|
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
13
|
+
[Documentation](https://www.walkeros.io/docs/core) •
|
|
14
|
+
[NPM Package](https://www.npmjs.com/package/@walkeros/core) •
|
|
15
|
+
[Source Code](https://github.com/elbwalker/walkerOS/tree/main/packages/core)
|
|
15
16
|
|
|
16
17
|
## Installation
|
|
17
18
|
|
|
@@ -19,419 +20,18 @@ data manipulation, validation, mapping, and more.
|
|
|
19
20
|
npm install @walkeros/core
|
|
20
21
|
```
|
|
21
22
|
|
|
22
|
-
## Quick
|
|
23
|
-
|
|
24
|
-
The core package provides types and utilities used across walkerOS. In a Flow
|
|
25
|
-
configuration:
|
|
26
|
-
|
|
27
|
-
```json
|
|
28
|
-
{
|
|
29
|
-
"version": 3,
|
|
30
|
-
"flows": {
|
|
31
|
-
"default": {
|
|
32
|
-
"web": {},
|
|
33
|
-
"destinations": {
|
|
34
|
-
"api": {
|
|
35
|
-
"package": "@walkeros/web-destination-api",
|
|
36
|
-
"config": {
|
|
37
|
-
"url": "https://collect.example.com/events"
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
```
|
|
23
|
+
## Quick start
|
|
45
24
|
|
|
46
|
-
Import utilities directly:
|
|
25
|
+
Import the types and utilities you need directly:
|
|
47
26
|
|
|
48
27
|
```ts
|
|
49
28
|
import { assign, anonymizeIP, getMappingValue } from '@walkeros/core';
|
|
50
29
|
```
|
|
51
30
|
|
|
52
|
-
##
|
|
53
|
-
|
|
54
|
-
Flow configurations support two dynamic patterns for reusable, environment-aware
|
|
55
|
-
configs:
|
|
56
|
-
|
|
57
|
-
### `$var.name` - Variable References
|
|
58
|
-
|
|
59
|
-
Reference values defined in `variables`. Values can be scalars (string, number,
|
|
60
|
-
boolean), objects, arrays, or whole mapping templates. The reference may include
|
|
61
|
-
a deep path that walks the value:
|
|
62
|
-
|
|
63
|
-
```json
|
|
64
|
-
{
|
|
65
|
-
"variables": {
|
|
66
|
-
"currency": "EUR",
|
|
67
|
-
"apiVersion": "v2",
|
|
68
|
-
"itemsLoop": {
|
|
69
|
-
"loop": ["nested", { "map": { "item_id": "data.id" } }]
|
|
70
|
-
},
|
|
71
|
-
"api": { "version": "v2", "url": "https://api.example.com" }
|
|
72
|
-
},
|
|
73
|
-
"destinations": {
|
|
74
|
-
"api": {
|
|
75
|
-
"config": {
|
|
76
|
-
"endpoint": "https://api.example.com/$var.apiVersion/collect",
|
|
77
|
-
"defaultCurrency": "$var.currency"
|
|
78
|
-
}
|
|
79
|
-
},
|
|
80
|
-
"ga4": {
|
|
81
|
-
"config": {
|
|
82
|
-
"mapping": {
|
|
83
|
-
"order": {
|
|
84
|
-
"complete": {
|
|
85
|
-
"data": { "map": { "items": "$var.itemsLoop" } }
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
},
|
|
91
|
-
"split": {
|
|
92
|
-
"config": {
|
|
93
|
-
"endpoint": "$var.api.url",
|
|
94
|
-
"version": "$var.api.version"
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
|
-
```
|
|
100
|
-
|
|
101
|
-
**Resolution rules:**
|
|
102
|
-
|
|
103
|
-
- A whole-string reference (`"$var.itemsLoop"`) replaces the value with the
|
|
104
|
-
variable's native type. Object, array, number, and boolean values are
|
|
105
|
-
preserved.
|
|
106
|
-
- An inline reference (`"Bearer $var.token"`) substitutes a scalar mid-string.
|
|
107
|
-
If the referenced variable resolves to an object or array, resolution throws;
|
|
108
|
-
only scalars (string, number, boolean) may be substituted inline.
|
|
109
|
-
- Variables may reference other variables. Resolution is recursive with cycle
|
|
110
|
-
detection, mirroring the `$flow` reference resolver.
|
|
111
|
-
|
|
112
|
-
Variables can be defined at setup, flow, or source/destination level (higher
|
|
113
|
-
specificity wins).
|
|
114
|
-
|
|
115
|
-
### `$env.NAME` - Environment Variables
|
|
116
|
-
|
|
117
|
-
Reference environment variables with optional defaults:
|
|
118
|
-
|
|
119
|
-
```json
|
|
120
|
-
{
|
|
121
|
-
"destinations": {
|
|
122
|
-
"ga4": {
|
|
123
|
-
"config": {
|
|
124
|
-
"measurementId": "$env.GA4_ID:G-DEMO123456"
|
|
125
|
-
}
|
|
126
|
-
}
|
|
127
|
-
}
|
|
128
|
-
}
|
|
129
|
-
```
|
|
130
|
-
|
|
131
|
-
- `$env.GA4_ID` - Throws if not set
|
|
132
|
-
- `$env.GA4_ID:default` - Uses "default" if not set
|
|
133
|
-
|
|
134
|
-
Only `$env` supports defaults because environment variables are external and may
|
|
135
|
-
not be set. Variables (`$var`) are explicitly defined in config, so missing ones
|
|
136
|
-
indicate a configuration error.
|
|
137
|
-
|
|
138
|
-
## Core Utilities
|
|
139
|
-
|
|
140
|
-
### Data Manipulation
|
|
141
|
-
|
|
142
|
-
#### assign
|
|
143
|
-
|
|
144
|
-
`assign<T, U>(target: T, source: U, options?): T & U` merges two objects with
|
|
145
|
-
advanced merging capabilities. It has special behavior for arrays: when merging,
|
|
146
|
-
it concatenates arrays from both objects, removing duplicates.
|
|
147
|
-
|
|
148
|
-
```ts
|
|
149
|
-
interface AssignOptions {
|
|
150
|
-
merge?: boolean; // Merge array properties (default: true)
|
|
151
|
-
shallow?: boolean; // Create shallow copy (default: true)
|
|
152
|
-
extend?: boolean; // Extend with new properties (default: true)
|
|
153
|
-
}
|
|
154
|
-
|
|
155
|
-
const obj1 = { a: 1, b: [1, 2] };
|
|
156
|
-
const obj2 = { b: [2, 3], c: 3 };
|
|
157
|
-
|
|
158
|
-
assign(obj1, obj2); // Returns { a: 1, b: [1, 2, 3], c: 3 }
|
|
159
|
-
assign(obj1, obj2, { merge: false }); // Returns { a: 1, b: [2, 3], c: 3 }
|
|
160
|
-
```
|
|
161
|
-
|
|
162
|
-
#### Path Operations
|
|
163
|
-
|
|
164
|
-
##### getByPath
|
|
165
|
-
|
|
166
|
-
`getByPath(object: unknown, path: string, defaultValue?: unknown): unknown`
|
|
167
|
-
accesses nested properties using dot notation. Supports wildcard `*` for array
|
|
168
|
-
iteration.
|
|
169
|
-
|
|
170
|
-
```js
|
|
171
|
-
getByPath({ data: { id: 'wow' } }, 'data.id'); // Returns "wow"
|
|
172
|
-
getByPath({ nested: [1, 2, { id: 'cool' }] }, 'nested.*.id'); // Returns ['', '', 'cool']
|
|
173
|
-
getByPath({ arr: ['foo', 'bar'] }, 'arr.1'); // Returns "bar"
|
|
174
|
-
```
|
|
175
|
-
|
|
176
|
-
##### setByPath
|
|
177
|
-
|
|
178
|
-
`setByPath(object: WalkerOS.Event, path: string, value: unknown): WalkerOS.Event`
|
|
179
|
-
sets nested values using dot notation, returning a new object with the updated
|
|
180
|
-
value.
|
|
181
|
-
|
|
182
|
-
```js
|
|
183
|
-
const updatedEvent = setByPath(event, 'data.id', 'new-value');
|
|
184
|
-
// Returns a new event with data.id set to 'new-value'
|
|
185
|
-
```
|
|
186
|
-
|
|
187
|
-
#### clone
|
|
188
|
-
|
|
189
|
-
`clone<T>(original: T): T` creates a deep copy of objects/arrays with circular
|
|
190
|
-
reference handling.
|
|
191
|
-
|
|
192
|
-
```js
|
|
193
|
-
const original = { foo: true, arr: ['a', 'b'] };
|
|
194
|
-
const cloned = clone(original);
|
|
195
|
-
original.foo = false; // cloned.foo remains true
|
|
196
|
-
```
|
|
197
|
-
|
|
198
|
-
#### castValue
|
|
199
|
-
|
|
200
|
-
`castValue(value: unknown): WalkerOS.PropertyType` converts string values to
|
|
201
|
-
appropriate types (number, boolean).
|
|
202
|
-
|
|
203
|
-
```js
|
|
204
|
-
castValue('123'); // Returns 123 (number)
|
|
205
|
-
castValue('true'); // Returns true (boolean)
|
|
206
|
-
castValue('hello'); // Returns 'hello' (unchanged)
|
|
207
|
-
```
|
|
208
|
-
|
|
209
|
-
### Privacy & Security
|
|
210
|
-
|
|
211
|
-
#### anonymizeIP
|
|
212
|
-
|
|
213
|
-
`anonymizeIP(ip: string): string` anonymizes IPv4 addresses by setting the last
|
|
214
|
-
oclet to zero.
|
|
215
|
-
|
|
216
|
-
```js
|
|
217
|
-
anonymizeIP('192.168.1.100'); // Returns '192.168.1.0'
|
|
218
|
-
```
|
|
219
|
-
|
|
220
|
-
#### Hashing
|
|
221
|
-
|
|
222
|
-
`getId(length?: number): string` generates random alphanumeric strings for
|
|
223
|
-
unique identifiers.
|
|
224
|
-
|
|
225
|
-
```js
|
|
226
|
-
getId(); // Returns random 6-char string like 'a1b2c3'
|
|
227
|
-
getId(10); // Returns 10-character string
|
|
228
|
-
```
|
|
229
|
-
|
|
230
|
-
### Event Processing
|
|
231
|
-
|
|
232
|
-
#### getMappingValue
|
|
233
|
-
|
|
234
|
-
`getMappingValue(event: WalkerOS.Event, mapping: Mapping.Data, context?: Partial<Mapping.Context>): Promise<WalkerOS.Property | undefined>`
|
|
235
|
-
extracts values from events using
|
|
236
|
-
[mapping configurations](https://www.walkeros.io/docs/destinations/event-mapping).
|
|
237
|
-
The `context` argument requires at least `{ collector }`; `event`, `logger`, and
|
|
238
|
-
`consent` are derived or optional.
|
|
239
|
-
|
|
240
|
-
```ts
|
|
241
|
-
// Simple path mapping
|
|
242
|
-
await getMappingValue(event, 'data.productId');
|
|
243
|
-
|
|
244
|
-
// Complex mapping with conditions and loops
|
|
245
|
-
const mapping = {
|
|
246
|
-
map: {
|
|
247
|
-
orderId: 'data.id',
|
|
248
|
-
products: {
|
|
249
|
-
loop: [
|
|
250
|
-
'nested',
|
|
251
|
-
{
|
|
252
|
-
condition: (entity) => entity.entity === 'product',
|
|
253
|
-
map: { id: 'data.id', name: 'data.name' },
|
|
254
|
-
},
|
|
255
|
-
],
|
|
256
|
-
},
|
|
257
|
-
},
|
|
258
|
-
};
|
|
259
|
-
await getMappingValue(event, mapping);
|
|
260
|
-
```
|
|
261
|
-
|
|
262
|
-
#### getMappingEvent
|
|
263
|
-
|
|
264
|
-
`getMappingEvent(event: WalkerOS.PartialEvent, mapping?: Mapping.Rules): Promise<Mapping.Result>`
|
|
265
|
-
finds the appropriate mapping rule for an event.
|
|
266
|
-
|
|
267
|
-
### Marketing & Analytics
|
|
268
|
-
|
|
269
|
-
#### getMarketingParameters
|
|
270
|
-
|
|
271
|
-
`getMarketingParameters(url: URL, custom?: MarketingParameters, clickIds?: ClickIdEntry[]): WalkerOS.Properties`
|
|
272
|
-
extracts UTM and click ID parameters from URLs. When a known ad-platform click
|
|
273
|
-
ID is present, the result also includes a `platform` field resolving to a
|
|
274
|
-
canonical identifier (e.g. `gclid` → `google`, `fbclid` → `meta`).
|
|
275
|
-
|
|
276
|
-
```js
|
|
277
|
-
getMarketingParameters(
|
|
278
|
-
new URL('https://example.com/?utm_source=docs&gclid=123'),
|
|
279
|
-
);
|
|
280
|
-
// Returns { source: "docs", gclid: "123", clickId: "gclid", platform: "google" }
|
|
281
|
-
|
|
282
|
-
// With custom parameters
|
|
283
|
-
getMarketingParameters(url, { utm_custom: 'custom', partner: 'partnerId' });
|
|
284
|
-
|
|
285
|
-
// With a custom click-ID registry (extends or overrides defaults)
|
|
286
|
-
getMarketingParameters(url, undefined, [{ param: 'xyzclid', platform: 'xyz' }]);
|
|
287
|
-
```
|
|
288
|
-
|
|
289
|
-
Multi-click-ID URLs preserve every raw value, but `clickId` and `platform`
|
|
290
|
-
reference the highest-priority match. See
|
|
291
|
-
[`src/getMarketingParameters.ts`](./src/getMarketingParameters.ts) for the full
|
|
292
|
-
registry and priority order.
|
|
293
|
-
|
|
294
|
-
### Type Validation
|
|
295
|
-
|
|
296
|
-
#### Type Checkers
|
|
297
|
-
|
|
298
|
-
A comprehensive set of type checking functions:
|
|
299
|
-
|
|
300
|
-
- `isString(value)`, `isNumber(value)`, `isBoolean(value)`
|
|
301
|
-
- `isArray(value)`, `isObject(value)`, `isFunction(value)`
|
|
302
|
-
- `isDefined(value)`, `isSameType(a, b)`
|
|
303
|
-
- `isPropertyType(value)` - Checks if value is valid walkerOS property
|
|
304
|
-
|
|
305
|
-
#### Property Utilities
|
|
306
|
-
|
|
307
|
-
- `castToProperty(value)` - Casts to valid property type
|
|
308
|
-
- `filterValues(object)` - Filters object to valid properties only
|
|
309
|
-
- `isPropertyType(value)` - Type guard for property validation
|
|
310
|
-
|
|
311
|
-
### Request Handling
|
|
312
|
-
|
|
313
|
-
#### requestToData
|
|
314
|
-
|
|
315
|
-
`requestToData(parameter: unknown): WalkerOS.AnyObject | undefined` converts
|
|
316
|
-
query strings to JavaScript objects with type casting.
|
|
317
|
-
|
|
318
|
-
```js
|
|
319
|
-
requestToData('a=1&b=true&c=hello&arr[0]=x&arr[1]=y');
|
|
320
|
-
// Returns { a: 1, b: true, c: 'hello', arr: ['x', 'y'] }
|
|
321
|
-
```
|
|
322
|
-
|
|
323
|
-
#### requestToParameter
|
|
324
|
-
|
|
325
|
-
`requestToParameter(data: WalkerOS.AnyObject): string` converts objects to
|
|
326
|
-
URL-encoded query strings.
|
|
327
|
-
|
|
328
|
-
```js
|
|
329
|
-
requestToParameter({ a: 1, b: true, arr: ['x', 'y'] });
|
|
330
|
-
// Returns 'a=1&b=true&arr[0]=x&arr[1]=y'
|
|
331
|
-
```
|
|
332
|
-
|
|
333
|
-
### User Agent Parsing
|
|
334
|
-
|
|
335
|
-
#### parseUserAgent
|
|
336
|
-
|
|
337
|
-
`parseUserAgent(userAgent?: string): WalkerOS.User` extracts browser, OS, and
|
|
338
|
-
device information.
|
|
339
|
-
|
|
340
|
-
```js
|
|
341
|
-
parseUserAgent(navigator.userAgent);
|
|
342
|
-
// Returns { browser: 'Chrome', browserVersion: '91.0', os: 'Windows', ... }
|
|
343
|
-
```
|
|
344
|
-
|
|
345
|
-
Individual functions are also available:
|
|
346
|
-
|
|
347
|
-
- `getBrowser(userAgent)` - Returns browser name
|
|
348
|
-
- `getBrowserVersion(userAgent)` - Returns browser version
|
|
349
|
-
- `getOS(userAgent)` - Returns operating system
|
|
350
|
-
- `getOSVersion(userAgent)` - Returns OS version
|
|
351
|
-
- `getDeviceType(userAgent)` - Returns 'Desktop', 'Tablet', or 'Mobile'
|
|
352
|
-
|
|
353
|
-
### Error Handling
|
|
354
|
-
|
|
355
|
-
#### tryCatch
|
|
356
|
-
|
|
357
|
-
`tryCatch(tryFn: Function, catchFn?: Function, finallyFn?: Function)` wraps
|
|
358
|
-
functions with error handling.
|
|
359
|
-
|
|
360
|
-
```js
|
|
361
|
-
const safeParse = tryCatch(JSON.parse, () => ({}));
|
|
362
|
-
safeParse('{"valid": "json"}'); // Parses successfully
|
|
363
|
-
safeParse('invalid'); // Returns {} instead of throwing
|
|
364
|
-
```
|
|
365
|
-
|
|
366
|
-
#### tryCatchAsync
|
|
367
|
-
|
|
368
|
-
`tryCatchAsync(tryFn: Function, catchFn?: Function, finallyFn?: Function)` for
|
|
369
|
-
async operations.
|
|
370
|
-
|
|
371
|
-
```js
|
|
372
|
-
const safeAsyncCall = tryCatchAsync(
|
|
373
|
-
() => fetchUserData(),
|
|
374
|
-
(error) => ({ error: 'Failed to load user' }),
|
|
375
|
-
);
|
|
376
|
-
```
|
|
377
|
-
|
|
378
|
-
### Performance Optimization
|
|
379
|
-
|
|
380
|
-
#### debounce
|
|
381
|
-
|
|
382
|
-
`debounce(fn: Function, wait?: number)` delays function execution until after
|
|
383
|
-
the wait time.
|
|
384
|
-
|
|
385
|
-
```js
|
|
386
|
-
const debouncedSearch = debounce(searchFunction, 300);
|
|
387
|
-
// Only executes after 300ms of inactivity
|
|
388
|
-
```
|
|
389
|
-
|
|
390
|
-
#### throttle
|
|
391
|
-
|
|
392
|
-
`throttle(fn: Function, wait?: number)` limits function execution frequency.
|
|
393
|
-
|
|
394
|
-
```js
|
|
395
|
-
const throttledScroll = throttle(scrollHandler, 100);
|
|
396
|
-
// Executes at most every 100ms
|
|
397
|
-
```
|
|
398
|
-
|
|
399
|
-
### Utilities
|
|
400
|
-
|
|
401
|
-
#### trim
|
|
402
|
-
|
|
403
|
-
`trim(str: string): string` removes whitespace from string ends.
|
|
404
|
-
|
|
405
|
-
#### throwError
|
|
406
|
-
|
|
407
|
-
`throwError(message: string)` throws descriptive errors.
|
|
408
|
-
|
|
409
|
-
#### onLog
|
|
410
|
-
|
|
411
|
-
`onLog(message: unknown, verbose?: boolean)` provides consistent logging.
|
|
412
|
-
|
|
413
|
-
```js
|
|
414
|
-
onLog('Debug info', true); // Logs message
|
|
415
|
-
onLog('Silent message'); // No output
|
|
416
|
-
```
|
|
417
|
-
|
|
418
|
-
## Type Definitions
|
|
419
|
-
|
|
420
|
-
See [src/types/](./src/types/) for TypeScript interfaces:
|
|
421
|
-
|
|
422
|
-
- [event.ts](./src/types/event.ts) - Event structure
|
|
423
|
-
- [destination.ts](./src/types/destination.ts) - Destination interface
|
|
424
|
-
- [source.ts](./src/types/source.ts) - Source interface
|
|
425
|
-
- [mapping.ts](./src/types/mapping.ts) - Mapping configuration
|
|
426
|
-
|
|
427
|
-
## Related
|
|
31
|
+
## Documentation
|
|
428
32
|
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
- [Web Core](https://www.walkeros.io/docs/sources/web/) - Browser-specific
|
|
432
|
-
functions
|
|
433
|
-
- [Server Core](https://www.walkeros.io/docs/sources/server/) - Node.js server
|
|
434
|
-
functions
|
|
33
|
+
Full configuration, mapping, and examples live in the docs:
|
|
34
|
+
**https://www.walkeros.io/docs/core**
|
|
435
35
|
|
|
436
36
|
## Contribute
|
|
437
37
|
|
|
@@ -442,4 +42,4 @@ Feel free to contribute by submitting an
|
|
|
442
42
|
|
|
443
43
|
## License
|
|
444
44
|
|
|
445
|
-
|
|
45
|
+
MIT
|