@walkeros/web-destination-api 0.4.2 → 0.5.1-next.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 CHANGED
@@ -1,6 +1,6 @@
1
1
  <p align="left">
2
- <a href="https://elbwalker.com">
3
- <img title="elbwalker" src="https://www.elbwalker.com/img/elbwalker_logo.png" width="256px"/>
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
 
@@ -35,50 +35,83 @@ npm install @walkeros/web-destination-api
35
35
  | `transform` | `function` | Function to transform event data before sending | No | `(data, config, mapping) => JSON.stringify(data)` |
36
36
  | `transport` | `'fetch' \| 'xhr' \| 'beacon'` | Transport method for sending requests | No | `'fetch'` |
37
37
 
38
- ## Usage
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
+ ```
39
64
 
40
- ### Basic Usage
65
+ Or programmatically:
41
66
 
42
67
  ```typescript
43
68
  import { startFlow } from '@walkeros/collector';
44
69
  import { destinationAPI } from '@walkeros/web-destination-api';
45
70
 
46
- const { elb } = await startFlow();
47
-
48
- elb('walker destination', destinationAPI, {
49
- settings: {
50
- url: 'https://api.example.com/events',
51
- method: 'POST',
52
- headers: {
53
- 'Content-Type': 'application/json',
54
- Authorization: 'Bearer your-token',
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
+ },
55
82
  },
56
- },
83
+ ],
57
84
  });
58
85
  ```
59
86
 
87
+ ## Usage
88
+
60
89
  ### Advanced Usage with Transform
61
90
 
62
91
  ```typescript
63
92
  import { startFlow } from '@walkeros/collector';
64
93
  import { destinationAPI } from '@walkeros/web-destination-api';
65
94
 
66
- const { elb } = await startFlow();
67
-
68
- elb('walker destination', destinationAPI, {
69
- settings: {
70
- url: 'https://api.example.com/events',
71
- transport: 'fetch',
72
- transform: (event, config, mapping) => {
73
- // Custom transformation logic
74
- return JSON.stringify({
75
- timestamp: Date.now(),
76
- event_name: `${event.entity}_${event.action}`,
77
- properties: event.data,
78
- context: event.context,
79
- });
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
+ },
80
113
  },
81
- },
114
+ ],
82
115
  });
83
116
  ```
84
117
 
@@ -86,64 +119,66 @@ elb('walker destination', destinationAPI, {
86
119
 
87
120
  ### Sending to Analytics API
88
121
 
89
- ```typescript
90
- import { startFlow } from '@walkeros/collector';
91
- import { destinationAPI } from '@walkeros/web-destination-api';
92
-
93
- const { elb } = await startFlow();
94
-
95
- // Configure for analytics API
96
- elb('walker destination', destinationAPI, {
97
- settings: {
98
- url: 'https://analytics.example.com/track',
99
- method: 'POST',
100
- headers: {
101
- 'Content-Type': 'application/json',
102
- 'X-API-Key': 'your-api-key',
103
- },
104
- transform: (event) => {
105
- return JSON.stringify({
106
- event_type: `${event.entity}_${event.action}`,
107
- user_id: event.user?.id,
108
- session_id: event.user?.session,
109
- properties: event.data,
110
- timestamp: event.timing,
111
- });
112
- },
113
- },
114
- });
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
+ }
115
140
  ```
116
141
 
117
142
  ### Using Beacon Transport
118
143
 
119
144
  For critical events that need to be sent even when the page is unloading:
120
145
 
121
- ```typescript
122
- elb('walker destination', destinationAPI, {
123
- settings: {
124
- url: 'https://api.example.com/critical-events',
125
- transport: 'beacon', // Reliable for page unload scenarios
126
- },
127
- });
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
+ }
128
160
  ```
129
161
 
130
162
  ### Custom Data Mapping
131
163
 
132
164
  Use mapping rules to control which events are sent:
133
165
 
134
- ```typescript
135
- elb('walker destination', destinationAPI, {
136
- settings: {
137
- url: 'https://api.example.com/events',
138
- },
139
- mapping: {
140
- entity: {
141
- action: {
142
- data: 'data',
143
- },
144
- },
145
- },
146
- });
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
+ }
147
182
  ```
148
183
 
149
184
  ## Transport Methods
@@ -153,6 +188,15 @@ elb('walker destination', destinationAPI, {
153
188
  - **beacon**: Uses Navigator.sendBeacon() for reliable data transmission during
154
189
  page unload
155
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
+
156
200
  ## Contribute
157
201
 
158
202
  Feel free to contribute by submitting an