demo-pkg-dalana 0.0.2 → 0.0.5

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,4 +1,8 @@
1
- # zeyasdk
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
- This project was created using `bun init` in bun v1.3.6. [Bun](https://bun.com) is a fast all-in-one JavaScript runtime.
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/build.ts ADDED
@@ -0,0 +1,7 @@
1
+ import dts from "bun-plugin-dts";
2
+
3
+ await Bun.build({
4
+ entrypoints: ["./src/index.ts"],
5
+ outdir: "./dist",
6
+ plugins: [dts()],
7
+ });
package/index.ts CHANGED
@@ -1,7 +1 @@
1
- console.log("Hello via Bun!");
2
-
3
- export const Sdk = {
4
- greet: function () {
5
- return "Hello from the SDK!";
6
- },
7
- };
1
+ export * from "./src/index.ts";
package/package.json CHANGED
@@ -2,11 +2,17 @@
2
2
  "name": "demo-pkg-dalana",
3
3
  "module": "index.ts",
4
4
  "type": "module",
5
- "version": "0.0.2",
5
+ "version": "0.0.5",
6
6
  "devDependencies": {
7
- "@types/bun": "latest"
7
+ "@types/bun": "latest",
8
+ "bun-plugin-dts": "^0.3.0"
8
9
  },
10
+ "main": "dist/index.js",
11
+ "types": "dist/index.d.ts",
9
12
  "peerDependencies": {
10
13
  "typescript": "^5"
14
+ },
15
+ "dependencies": {
16
+ "windmill-client": "^1.616.0"
11
17
  }
12
18
  }
@@ -0,0 +1,5 @@
1
+ export const Flagger = {
2
+ get: () => {
3
+ throw new Error("Not implemented");
4
+ },
5
+ };
@@ -0,0 +1,13 @@
1
+ type ZDKContext = {
2
+ appId: string;
3
+ tenantId: string;
4
+ branchId: string;
5
+ };
6
+
7
+ export type ZDKOptions = {
8
+ appId?: string;
9
+ tenantId?: string;
10
+ branchId?: string;
11
+ };
12
+
13
+ export async function init(options?: ZDKOptions) {}
@@ -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
+ }
@@ -0,0 +1,4 @@
1
+ export class DigitalTwin {
2
+ query() {}
3
+ mutate() {}
4
+ }
package/src/index.ts ADDED
@@ -0,0 +1,8 @@
1
+ import { init } from "./_internal/index";
2
+
3
+ import { Config } from "./config";
4
+ import { DigitalTwin } from "./digital-twin";
5
+
6
+ await init();
7
+
8
+ export { Config, DigitalTwin };
@@ -0,0 +1,4 @@
1
+ export const Time = {
2
+ now: () => Date.now(),
3
+ toDateString: (timestamp: number) => new Date(timestamp).toDateString(),
4
+ };
File without changes
File without changes