demo-pkg-dalana 0.0.1 → 0.0.3
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 +37 -2
- package/index.ts +1 -1
- package/package.json +4 -1
- package/src/_internal/flagger/index.ts +5 -0
- package/src/_internal/index.ts +13 -0
- package/src/_internal/switchboard/index.ts +70 -0
- package/src/config/index.ts +11 -0
- package/src/digital-twin/index.ts +4 -0
- package/src/main.ts +13 -0
- package/src/utils/chrono.ts +4 -0
- package/src/utils/errors.ts +0 -0
- package/src/utils/index.ts +0 -0
package/README.md
CHANGED
|
@@ -1,4 +1,8 @@
|
|
|
1
|
-
#
|
|
1
|
+
# Zeya Development Kit (ZDK)
|
|
2
|
+
|
|
3
|
+
The Zeya Development Kit (ZDK) is a TypeScript SDK designed to interact with various Zeya services, including configuration management, digital twins, and internal services like Flagger and Switchboard.
|
|
4
|
+
|
|
5
|
+
## Installation and Usage
|
|
2
6
|
|
|
3
7
|
To install dependencies:
|
|
4
8
|
|
|
@@ -12,4 +16,35 @@ To run:
|
|
|
12
16
|
bun run index.ts
|
|
13
17
|
```
|
|
14
18
|
|
|
15
|
-
|
|
19
|
+
## Modules
|
|
20
|
+
|
|
21
|
+
Different modules can be found in the `src` folder.
|
|
22
|
+
- Internal
|
|
23
|
+
- Flagger: client for the config backend
|
|
24
|
+
- Switchboard: client for the switchboard (proxy / event broker) backend
|
|
25
|
+
|
|
26
|
+
- Public
|
|
27
|
+
- Digital Twin: client for the digital twin backend
|
|
28
|
+
- Config: configuration management module
|
|
29
|
+
- Utils: utility functions and helpers
|
|
30
|
+
|
|
31
|
+
# Responsibilities
|
|
32
|
+
|
|
33
|
+
## Flagger
|
|
34
|
+
Configuration management
|
|
35
|
+
- tenant & app scoping (app can be a worklfow, backend service, or a simple script)
|
|
36
|
+
|
|
37
|
+
## Switch Board
|
|
38
|
+
Routing of payloads for both egress and ingress
|
|
39
|
+
- Credentials
|
|
40
|
+
- Rate limits, retries handling
|
|
41
|
+
- Tracing
|
|
42
|
+
|
|
43
|
+
## Digital Twin aka Integrator
|
|
44
|
+
|
|
45
|
+
Integration with external world (CMS / Converse, Plato, Google, ...)
|
|
46
|
+
- Caching
|
|
47
|
+
- Validation
|
|
48
|
+
- API augmentation / enrichment
|
|
49
|
+
- Job-based requests
|
|
50
|
+
- Shadow Execution
|
package/index.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
export * from "./src/main.ts";
|
package/package.json
CHANGED
|
@@ -2,11 +2,14 @@
|
|
|
2
2
|
"name": "demo-pkg-dalana",
|
|
3
3
|
"module": "index.ts",
|
|
4
4
|
"type": "module",
|
|
5
|
-
"version": "0.0.
|
|
5
|
+
"version": "0.0.3",
|
|
6
6
|
"devDependencies": {
|
|
7
7
|
"@types/bun": "latest"
|
|
8
8
|
},
|
|
9
9
|
"peerDependencies": {
|
|
10
10
|
"typescript": "^5"
|
|
11
|
+
},
|
|
12
|
+
"dependencies": {
|
|
13
|
+
"windmill-client": "^1.616.0"
|
|
11
14
|
}
|
|
12
15
|
}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
export interface HttpCallbackPayload {
|
|
2
|
+
body?: string;
|
|
3
|
+
method: "GET" | "POST" | "PUT" | "DELETE" | "PATCH";
|
|
4
|
+
headers?: Record<string, string>;
|
|
5
|
+
url: string;
|
|
6
|
+
callbacks: {
|
|
7
|
+
onSuccess: string;
|
|
8
|
+
onError?: string;
|
|
9
|
+
};
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export interface RegisterEventCallbackPayload {
|
|
13
|
+
source: string;
|
|
14
|
+
filter: Record<string, unknown>;
|
|
15
|
+
url: string;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export class Switchboard {
|
|
19
|
+
|
|
20
|
+
constructor(private baseUrl: string) {}
|
|
21
|
+
// will do the requested http call and call the success or failure callbacks with the response
|
|
22
|
+
async registerHttpCallback(payload: HttpCallbackPayload): Promise<void> {
|
|
23
|
+
const response = await fetch(`${this.baseUrl}/proxy`, {
|
|
24
|
+
method: "POST",
|
|
25
|
+
headers: { "Content-Type": "application/json" },
|
|
26
|
+
body: JSON.stringify(payload),
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
if (!response.ok) {
|
|
30
|
+
throw new Error(
|
|
31
|
+
`Failed to register http callback: ${response.statusText}`,
|
|
32
|
+
);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
// will register an event listener for the given event filter returns a context id
|
|
37
|
+
async registerEventCallback(
|
|
38
|
+
payload: RegisterEventCallbackPayload,
|
|
39
|
+
): Promise<string> {
|
|
40
|
+
const response = await fetch(`${this.baseUrl}/register_event_handler`, {
|
|
41
|
+
method: "POST",
|
|
42
|
+
headers: { "Content-Type": "application/json" },
|
|
43
|
+
body: JSON.stringify(payload),
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
if (!response.ok) {
|
|
47
|
+
throw new Error(
|
|
48
|
+
`Failed to register event callback: ${response.statusText}`,
|
|
49
|
+
);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
const data = (await response.json()) as { contextId: string };
|
|
53
|
+
return data.contextId;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
// will deregister the event listener for the given context id
|
|
57
|
+
async deregisterEventCallback(contextId: string): Promise<void> {
|
|
58
|
+
const response = await fetch(`${this.baseUrl}/deregister_event_handler`, {
|
|
59
|
+
method: "POST",
|
|
60
|
+
headers: { "Content-Type": "application/json" },
|
|
61
|
+
body: JSON.stringify({ contextId }),
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
if (!response.ok) {
|
|
65
|
+
throw new Error(
|
|
66
|
+
`Failed to deregister event callback: ${response.statusText}`,
|
|
67
|
+
);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export class Config {
|
|
2
|
+
// validate and ensure the config schema is resolvable within the current context
|
|
3
|
+
static validate(schema: unknown) {
|
|
4
|
+
// call flagger with schema and current context
|
|
5
|
+
throw new Error("Not implemented");
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
static getConfig(key: string) {
|
|
9
|
+
throw new Error("Not implemented");
|
|
10
|
+
}
|
|
11
|
+
}
|
package/src/main.ts
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { init, type ZDKOptions } from "./_internal/index";
|
|
2
|
+
|
|
3
|
+
import { Config } from "./config";
|
|
4
|
+
import { DigitalTwin } from "./digital-twin";
|
|
5
|
+
|
|
6
|
+
await init();
|
|
7
|
+
|
|
8
|
+
export const ZDK = (options?: ZDKOptions) => {
|
|
9
|
+
return {
|
|
10
|
+
Config,
|
|
11
|
+
DigitalTwin,
|
|
12
|
+
};
|
|
13
|
+
};
|
|
File without changes
|
|
File without changes
|