|
| 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 | +# API Destination for walkerOS |
| 8 | + |
| 9 | +[Source Code](https://github.com/elbwalker/walkerOS/tree/main/packages/server/destinations/api) |
| 10 | +• |
| 11 | +[NPM Package](https://www.npmjs.com/package/@walkeros/server-destination-api) |
| 12 | + |
| 13 | +walkerOS follows a **source → collector → destination** architecture. This API |
| 14 | +destination receives processed events from the walkerOS collector and sends them |
| 15 | +to any HTTP(S) endpoint, enabling integration with custom APIs, webhooks, and |
| 16 | +third-party services. |
| 17 | + |
| 18 | +## Installation |
| 19 | + |
| 20 | +```sh |
| 21 | +npm install @walkeros/server-destination-api |
| 22 | +``` |
| 23 | + |
| 24 | +## Quick Start |
| 25 | + |
| 26 | +Configure in your Flow JSON: |
| 27 | + |
| 28 | +```json |
| 29 | +{ |
| 30 | + "version": 1, |
| 31 | + "flows": { |
| 32 | + "default": { |
| 33 | + "server": {}, |
| 34 | + "destinations": { |
| 35 | + "api": { |
| 36 | + "package": "@walkeros/server-destination-api", |
| 37 | + "config": { |
| 38 | + "settings": { |
| 39 | + "url": "https://api.example.com/events" |
| 40 | + } |
| 41 | + } |
| 42 | + } |
| 43 | + } |
| 44 | + } |
| 45 | + } |
| 46 | +} |
| 47 | +``` |
| 48 | + |
| 49 | +Or programmatically: |
| 50 | + |
| 51 | +```typescript |
| 52 | +import { startFlow } from '@walkeros/collector'; |
| 53 | +import { destinationAPI } from '@walkeros/server-destination-api'; |
| 54 | + |
| 55 | +const { elb } = await startFlow({ |
| 56 | + destinations: [ |
| 57 | + { |
| 58 | + destination: destinationAPI, |
| 59 | + config: { |
| 60 | + settings: { |
| 61 | + url: 'https://api.example.com/events', |
| 62 | + headers: { |
| 63 | + Authorization: 'Bearer your-api-key', |
| 64 | + 'Content-Type': 'application/json', |
| 65 | + }, |
| 66 | + method: 'POST', |
| 67 | + timeout: 5000, |
| 68 | + }, |
| 69 | + }, |
| 70 | + }, |
| 71 | + ], |
| 72 | +}); |
| 73 | +``` |
| 74 | + |
| 75 | +## Configuration |
| 76 | + |
| 77 | +| Name | Type | Description | Required | Default | |
| 78 | +| ----------- | ------------------------ | ----------------------------------- | -------- | ------- | |
| 79 | +| `url` | `string` | The API endpoint URL to send events | Yes | - | |
| 80 | +| `headers` | `Record<string, string>` | Custom HTTP headers | No | - | |
| 81 | +| `method` | `string` | HTTP method | No | `POST` | |
| 82 | +| `timeout` | `number` | Request timeout in milliseconds | No | `5000` | |
| 83 | +| `transform` | `Function` | Custom data transformation function | No | - | |
| 84 | + |
| 85 | +## Features |
| 86 | + |
| 87 | +- **Flexible URL Configuration**: Send events to any HTTP(S) endpoint |
| 88 | +- **Custom Headers**: Add authentication tokens, API keys, or custom headers |
| 89 | +- **HTTP Method Control**: Use POST, PUT, PATCH, or any HTTP method |
| 90 | +- **Request Timeout**: Configure timeout for slow endpoints |
| 91 | +- **Data Transformation**: Transform event data before sending with custom |
| 92 | + functions |
| 93 | +- **Dependency Injection**: Mock the sendServer function for testing |
| 94 | + |
| 95 | +## Advanced Usage |
| 96 | + |
| 97 | +### Custom Transform Function |
| 98 | + |
| 99 | +Transform event data before sending: |
| 100 | + |
| 101 | +```typescript |
| 102 | +import { destinationAPI } from '@walkeros/server-destination-api'; |
| 103 | + |
| 104 | +const config = { |
| 105 | + settings: { |
| 106 | + url: 'https://api.example.com/events', |
| 107 | + transform: (data, config, mapping) => { |
| 108 | + // Return custom body (string or object) |
| 109 | + return JSON.stringify({ |
| 110 | + eventType: data.event, |
| 111 | + properties: data.data, |
| 112 | + timestamp: Date.now(), |
| 113 | + }); |
| 114 | + }, |
| 115 | + }, |
| 116 | +}; |
| 117 | +``` |
| 118 | + |
| 119 | +### Using with Mapping |
| 120 | + |
| 121 | +Use walkerOS mapping to transform events: |
| 122 | + |
| 123 | +```typescript |
| 124 | +const config = { |
| 125 | + settings: { url: 'https://api.example.com/events' }, |
| 126 | + mapping: { |
| 127 | + page: { |
| 128 | + view: { |
| 129 | + data: { |
| 130 | + map: { |
| 131 | + pageUrl: 'data.path', |
| 132 | + pageTitle: 'data.title', |
| 133 | + }, |
| 134 | + }, |
| 135 | + }, |
| 136 | + }, |
| 137 | + }, |
| 138 | +}; |
| 139 | +``` |
| 140 | + |
| 141 | +## Type Definitions |
| 142 | + |
| 143 | +See [src/types/](./src/types/) for TypeScript interfaces. |
| 144 | + |
| 145 | +## Related |
| 146 | + |
| 147 | +- [Destination Interface](../../../core/src/types/destination.ts) |
| 148 | + |
| 149 | +## Contribute |
| 150 | + |
| 151 | +Feel free to contribute by submitting an |
| 152 | +[issue](https://github.com/elbwalker/walkerOS/issues), starting a |
| 153 | +[discussion](https://github.com/elbwalker/walkerOS/discussions), or getting in |
| 154 | +[contact](https://calendly.com/elb-alexander/30min). |
| 155 | + |
| 156 | +## License |
| 157 | + |
| 158 | +This project is licensed under the MIT License. |
0 commit comments