Skip to content

Commit a28cb74

Browse files
Merge pull request #573 from elbwalker/542-server-api-destination
542 server api destination
2 parents 23950b8 + 4d3c884 commit a28cb74

File tree

32 files changed

+929
-23
lines changed

32 files changed

+929
-23
lines changed

package-lock.json

Lines changed: 21 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,10 @@
2323
"website"
2424
],
2525
"scripts": {
26-
"build": "turbo run build --filter=!@walkeros/website --output-logs=errors-only",
27-
"build:website": "turbo run build --filter=@walkeros/website --output-logs=errors-only",
26+
"build": "npm run build:packages && npm run build:apps && npm run build:website",
27+
"build:packages": "turbo run build --filter='./packages/**'",
28+
"build:apps": "turbo run build --filter='./apps/*'",
29+
"build:website": "turbo run build --filter=@walkeros/website",
2830
"clean": "turbo run clean",
2931
"dev": "turbo run dev --output-logs=errors-only",
3032
"format": "prettier --write .",
Lines changed: 158 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,158 @@
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+
&bull;
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.
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import baseConfig from '@walkeros/config/jest';
2+
3+
const config = {};
4+
5+
export default { ...baseConfig, ...config };
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
{
2+
"name": "@walkeros/server-destination-api",
3+
"description": "API server destination for walkerOS",
4+
"version": "0.5.0",
5+
"license": "MIT",
6+
"main": "./dist/index.js",
7+
"module": "./dist/index.mjs",
8+
"types": "./dist/index.d.ts",
9+
"exports": {
10+
".": {
11+
"types": "./dist/index.d.ts",
12+
"import": "./dist/index.mjs",
13+
"require": "./dist/index.js"
14+
},
15+
"./dev": {
16+
"types": "./dist/dev.d.ts",
17+
"import": "./dist/dev.mjs",
18+
"require": "./dist/dev.js"
19+
},
20+
"./examples": {
21+
"types": "./dist/examples/index.d.ts",
22+
"import": "./dist/examples/index.mjs",
23+
"require": "./dist/examples/index.js"
24+
}
25+
},
26+
"files": [
27+
"dist/**"
28+
],
29+
"scripts": {
30+
"build": "tsup --silent",
31+
"clean": "rm -rf .turbo && rm -rf node_modules && rm -rf dist",
32+
"dev": "jest --watchAll --colors",
33+
"lint": "tsc && eslint \"**/*.ts*\"",
34+
"test": "jest",
35+
"update": "npx npm-check-updates -u && npm update"
36+
},
37+
"dependencies": {
38+
"@walkeros/core": "0.5.0",
39+
"@walkeros/server-core": "0.5.0"
40+
},
41+
"devDependencies": {},
42+
"repository": {
43+
"url": "git+https://github.com/elbwalker/walkerOS.git",
44+
"directory": "packages/server/destinations/api"
45+
},
46+
"author": "elbwalker <[email protected]>",
47+
"homepage": "https://github.com/elbwalker/walkerOS#readme",
48+
"bugs": {
49+
"url": "https://github.com/elbwalker/walkerOS/issues"
50+
},
51+
"keywords": [
52+
"walker",
53+
"walkerOS",
54+
"destination",
55+
"server",
56+
"api"
57+
],
58+
"funding": [
59+
{
60+
"type": "GitHub Sponsors",
61+
"url": "https://github.com/sponsors/elbwalker"
62+
}
63+
]
64+
}
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
export * as schemas from './schemas';
2+
export * as examples from './examples';
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import type { Env } from '../types';
2+
3+
/**
4+
* Example environment configurations for API destination
5+
*
6+
* These environments provide standardized mock structures for testing
7+
* and development without requiring external dependencies.
8+
*/
9+
10+
const noop = () => Promise.resolve({ ok: true });
11+
12+
export const init: Env | undefined = {
13+
sendServer: undefined,
14+
};
15+
16+
export const standard: Env = {
17+
sendServer: Object.assign(noop, {
18+
// Add any specific properties if needed for sendServer
19+
}) as unknown as Env['sendServer'],
20+
};
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import { getEvent } from '@walkeros/core';
2+
3+
export function entity_action() {
4+
const event = getEvent('entity action');
5+
6+
return JSON.stringify(event.data);
7+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
export * as env from './env';
2+
export * as events from './events';
3+
export * as mapping from './mapping';
4+
export * as outputs from './outputs';
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import type { Mapping } from '@walkeros/core';
2+
import type { Rule, Rules } from '../types';
3+
4+
export const entity_action: Rule = {
5+
data: 'data',
6+
};
7+
8+
export const config = {
9+
entity: { action: entity_action },
10+
} satisfies Rules;

0 commit comments

Comments
 (0)