@walkeros/web-destination-api 0.0.0-next-20251219153324

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 ADDED
@@ -0,0 +1,209 @@
1
+ <p align="left">
2
+ <a href="https://www.walkeros.io">
3
+ <img title="elbwalker" src="https://www.walkeros.io/img/elbwalker_logo.png" width="256px"/>
4
+ </a>
5
+ </p>
6
+
7
+ # Web API Destination for walkerOS
8
+
9
+ [Source Code](https://github.com/elbwalker/walkerOS/tree/main/packages/web/destinations/api)
10
+ &bull;
11
+ [NPM Package](https://www.npmjs.com/package/@walkeros/web-destination-api)
12
+
13
+ The API destination allows you to send events to any HTTP endpoint with
14
+ customizable data transformation and transport methods.
15
+
16
+ walkerOS follows a **source → collector → destination** architecture. This API
17
+ destination receives processed events from the walkerOS collector and sends them
18
+ to your custom API endpoint, enabling integration with internal analytics
19
+ systems, data warehouses, or custom business logic that requires real-time event
20
+ data.
21
+
22
+ ## Installation
23
+
24
+ ```sh
25
+ npm install @walkeros/web-destination-api
26
+ ```
27
+
28
+ ## Configuration
29
+
30
+ | Name | Type | Description | Required | Example |
31
+ | ----------- | ------------------------------ | ------------------------------------------------ | -------- | ------------------------------------------------------------------------- |
32
+ | `url` | `string` | The HTTP endpoint URL to send events to | Yes | `'https://api.example.com/events'` |
33
+ | `headers` | `Record<string, string>` | Additional HTTP headers to include with requests | No | `{ 'Authorization': 'Bearer token', 'Content-Type': 'application/json' }` |
34
+ | `method` | `string` | HTTP method for the request | No | `'POST'` |
35
+ | `transform` | `function` | Function to transform event data before sending | No | `(data, config, mapping) => JSON.stringify(data)` |
36
+ | `transport` | `'fetch' \| 'xhr' \| 'beacon'` | Transport method for sending requests | No | `'fetch'` |
37
+
38
+ ## Quick Start
39
+
40
+ Configure in your Flow JSON:
41
+
42
+ ```json
43
+ {
44
+ "version": 1,
45
+ "flows": {
46
+ "default": {
47
+ "web": {},
48
+ "destinations": {
49
+ "api": {
50
+ "package": "@walkeros/web-destination-api",
51
+ "config": {
52
+ "settings": {
53
+ "url": "https://api.example.com/events",
54
+ "method": "POST",
55
+ "headers": { "Authorization": "Bearer your-token" }
56
+ }
57
+ }
58
+ }
59
+ }
60
+ }
61
+ }
62
+ }
63
+ ```
64
+
65
+ Or programmatically:
66
+
67
+ ```typescript
68
+ import { startFlow } from '@walkeros/collector';
69
+ import { destinationAPI } from '@walkeros/web-destination-api';
70
+
71
+ const { elb } = await startFlow({
72
+ destinations: [
73
+ {
74
+ destination: destinationAPI,
75
+ config: {
76
+ settings: {
77
+ url: 'https://api.example.com/events',
78
+ method: 'POST',
79
+ headers: { Authorization: 'Bearer your-token' },
80
+ },
81
+ },
82
+ },
83
+ ],
84
+ });
85
+ ```
86
+
87
+ ## Usage
88
+
89
+ ### Advanced Usage with Transform
90
+
91
+ ```typescript
92
+ import { startFlow } from '@walkeros/collector';
93
+ import { destinationAPI } from '@walkeros/web-destination-api';
94
+
95
+ const { elb } = await startFlow({
96
+ destinations: [
97
+ {
98
+ destination: destinationAPI,
99
+ config: {
100
+ settings: {
101
+ url: 'https://api.example.com/events',
102
+ transport: 'fetch',
103
+ transform: (event, config, mapping) => {
104
+ return JSON.stringify({
105
+ timestamp: Date.now(),
106
+ event_name: `${event.entity}_${event.action}`,
107
+ properties: event.data,
108
+ context: event.context,
109
+ });
110
+ },
111
+ },
112
+ },
113
+ },
114
+ ],
115
+ });
116
+ ```
117
+
118
+ ## Examples
119
+
120
+ ### Sending to Analytics API
121
+
122
+ ```json
123
+ {
124
+ "destinations": {
125
+ "analytics": {
126
+ "package": "@walkeros/web-destination-api",
127
+ "config": {
128
+ "settings": {
129
+ "url": "https://analytics.example.com/track",
130
+ "method": "POST",
131
+ "headers": {
132
+ "Content-Type": "application/json",
133
+ "X-API-Key": "your-api-key"
134
+ }
135
+ }
136
+ }
137
+ }
138
+ }
139
+ }
140
+ ```
141
+
142
+ ### Using Beacon Transport
143
+
144
+ For critical events that need to be sent even when the page is unloading:
145
+
146
+ ```json
147
+ {
148
+ "destinations": {
149
+ "critical": {
150
+ "package": "@walkeros/web-destination-api",
151
+ "config": {
152
+ "settings": {
153
+ "url": "https://api.example.com/critical-events",
154
+ "transport": "beacon"
155
+ }
156
+ }
157
+ }
158
+ }
159
+ }
160
+ ```
161
+
162
+ ### Custom Data Mapping
163
+
164
+ Use mapping rules to control which events are sent:
165
+
166
+ ```json
167
+ {
168
+ "destinations": {
169
+ "api": {
170
+ "package": "@walkeros/web-destination-api",
171
+ "config": {
172
+ "settings": { "url": "https://api.example.com/events" },
173
+ "mapping": {
174
+ "entity": {
175
+ "action": { "data": "data" }
176
+ }
177
+ }
178
+ }
179
+ }
180
+ }
181
+ }
182
+ ```
183
+
184
+ ## Transport Methods
185
+
186
+ - **fetch** (default): Modern, promise-based HTTP requests
187
+ - **xhr**: Traditional XMLHttpRequest for older browser compatibility
188
+ - **beacon**: Uses Navigator.sendBeacon() for reliable data transmission during
189
+ page unload
190
+
191
+ ## Type Definitions
192
+
193
+ See [src/types/](./src/types/) for TypeScript interfaces.
194
+
195
+ ## Related
196
+
197
+ - [Website Documentation](https://www.walkeros.io/docs/destinations/web/api/)
198
+ - [Destination Interface](../../../core/src/types/destination.ts)
199
+
200
+ ## Contribute
201
+
202
+ Feel free to contribute by submitting an
203
+ [issue](https://github.com/elbwalker/walkerOS/issues), starting a
204
+ [discussion](https://github.com/elbwalker/walkerOS/discussions), or getting in
205
+ [contact](https://calendly.com/elb-alexander/30min).
206
+
207
+ ## License
208
+
209
+ This project is licensed under the MIT License.
package/dist/dev.d.mts ADDED
@@ -0,0 +1,81 @@
1
+ import * as _walkeros_core_dev from '@walkeros/core/dev';
2
+ import { z } from '@walkeros/core/dev';
3
+ import { Mapping as Mapping$2 } from '@walkeros/core';
4
+ import { DestinationWeb, sendWeb } from '@walkeros/web-core';
5
+
6
+ declare const SettingsSchema: z.ZodObject<{
7
+ url: z.ZodString;
8
+ headers: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
9
+ method: z.ZodDefault<z.ZodString>;
10
+ transform: z.ZodOptional<z.ZodAny>;
11
+ transport: z.ZodDefault<z.ZodEnum<{
12
+ fetch: "fetch";
13
+ xhr: "xhr";
14
+ beacon: "beacon";
15
+ }>>;
16
+ }, z.core.$strip>;
17
+ type Settings = z.infer<typeof SettingsSchema>;
18
+
19
+ declare const MappingSchema: z.ZodObject<{}, z.core.$strip>;
20
+ type Mapping$1 = z.infer<typeof MappingSchema>;
21
+
22
+ declare const settings: _walkeros_core_dev.JSONSchema;
23
+ declare const mapping$1: _walkeros_core_dev.JSONSchema;
24
+
25
+ declare const index$1_MappingSchema: typeof MappingSchema;
26
+ type index$1_Settings = Settings;
27
+ declare const index$1_SettingsSchema: typeof SettingsSchema;
28
+ declare const index$1_settings: typeof settings;
29
+ declare namespace index$1 {
30
+ export { type Mapping$1 as Mapping, index$1_MappingSchema as MappingSchema, type index$1_Settings as Settings, index$1_SettingsSchema as SettingsSchema, mapping$1 as mapping, index$1_settings as settings };
31
+ }
32
+
33
+ interface Mapping {
34
+ }
35
+ interface Env extends DestinationWeb.Env {
36
+ sendWeb?: typeof sendWeb;
37
+ }
38
+ type Rule = Mapping$2.Rule<Mapping>;
39
+
40
+ declare const init: Env | undefined;
41
+ declare const push: Env;
42
+ /**
43
+ * Simulation tracking paths
44
+ * Specifies which function calls to track during simulation
45
+ */
46
+ declare const simulation: string[];
47
+
48
+ declare const env_init: typeof init;
49
+ declare const env_push: typeof push;
50
+ declare const env_simulation: typeof simulation;
51
+ declare namespace env {
52
+ export { env_init as init, env_push as push, env_simulation as simulation };
53
+ }
54
+
55
+ declare function entity_action$1(): string;
56
+
57
+ declare namespace events {
58
+ export { entity_action$1 as entity_action };
59
+ }
60
+
61
+ declare const entity_action: Rule;
62
+ declare const config: {
63
+ entity: {
64
+ action: Rule;
65
+ };
66
+ };
67
+
68
+ declare const mapping_config: typeof config;
69
+ declare const mapping_entity_action: typeof entity_action;
70
+ declare namespace mapping {
71
+ export { mapping_config as config, mapping_entity_action as entity_action };
72
+ }
73
+
74
+ declare const index_env: typeof env;
75
+ declare const index_events: typeof events;
76
+ declare const index_mapping: typeof mapping;
77
+ declare namespace index {
78
+ export { index_env as env, index_events as events, index_mapping as mapping };
79
+ }
80
+
81
+ export { index as examples, index$1 as schemas };
package/dist/dev.d.ts ADDED
@@ -0,0 +1,81 @@
1
+ import * as _walkeros_core_dev from '@walkeros/core/dev';
2
+ import { z } from '@walkeros/core/dev';
3
+ import { Mapping as Mapping$2 } from '@walkeros/core';
4
+ import { DestinationWeb, sendWeb } from '@walkeros/web-core';
5
+
6
+ declare const SettingsSchema: z.ZodObject<{
7
+ url: z.ZodString;
8
+ headers: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
9
+ method: z.ZodDefault<z.ZodString>;
10
+ transform: z.ZodOptional<z.ZodAny>;
11
+ transport: z.ZodDefault<z.ZodEnum<{
12
+ fetch: "fetch";
13
+ xhr: "xhr";
14
+ beacon: "beacon";
15
+ }>>;
16
+ }, z.core.$strip>;
17
+ type Settings = z.infer<typeof SettingsSchema>;
18
+
19
+ declare const MappingSchema: z.ZodObject<{}, z.core.$strip>;
20
+ type Mapping$1 = z.infer<typeof MappingSchema>;
21
+
22
+ declare const settings: _walkeros_core_dev.JSONSchema;
23
+ declare const mapping$1: _walkeros_core_dev.JSONSchema;
24
+
25
+ declare const index$1_MappingSchema: typeof MappingSchema;
26
+ type index$1_Settings = Settings;
27
+ declare const index$1_SettingsSchema: typeof SettingsSchema;
28
+ declare const index$1_settings: typeof settings;
29
+ declare namespace index$1 {
30
+ export { type Mapping$1 as Mapping, index$1_MappingSchema as MappingSchema, type index$1_Settings as Settings, index$1_SettingsSchema as SettingsSchema, mapping$1 as mapping, index$1_settings as settings };
31
+ }
32
+
33
+ interface Mapping {
34
+ }
35
+ interface Env extends DestinationWeb.Env {
36
+ sendWeb?: typeof sendWeb;
37
+ }
38
+ type Rule = Mapping$2.Rule<Mapping>;
39
+
40
+ declare const init: Env | undefined;
41
+ declare const push: Env;
42
+ /**
43
+ * Simulation tracking paths
44
+ * Specifies which function calls to track during simulation
45
+ */
46
+ declare const simulation: string[];
47
+
48
+ declare const env_init: typeof init;
49
+ declare const env_push: typeof push;
50
+ declare const env_simulation: typeof simulation;
51
+ declare namespace env {
52
+ export { env_init as init, env_push as push, env_simulation as simulation };
53
+ }
54
+
55
+ declare function entity_action$1(): string;
56
+
57
+ declare namespace events {
58
+ export { entity_action$1 as entity_action };
59
+ }
60
+
61
+ declare const entity_action: Rule;
62
+ declare const config: {
63
+ entity: {
64
+ action: Rule;
65
+ };
66
+ };
67
+
68
+ declare const mapping_config: typeof config;
69
+ declare const mapping_entity_action: typeof entity_action;
70
+ declare namespace mapping {
71
+ export { mapping_config as config, mapping_entity_action as entity_action };
72
+ }
73
+
74
+ declare const index_env: typeof env;
75
+ declare const index_events: typeof events;
76
+ declare const index_mapping: typeof mapping;
77
+ declare namespace index {
78
+ export { index_env as env, index_events as events, index_mapping as mapping };
79
+ }
80
+
81
+ export { index as examples, index$1 as schemas };