@fatagnus/dink-sdk 2.17.1 → 2.19.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 +37 -1
- package/dist/edge/index.d.ts +1 -0
- package/dist/edge/index.d.ts.map +1 -1
- package/dist/edge/index.js +1 -0
- package/dist/edge/index.js.map +1 -1
- package/dist/edge/worker.d.ts +58 -0
- package/dist/edge/worker.d.ts.map +1 -0
- package/dist/edge/worker.js +89 -0
- package/dist/edge/worker.js.map +1 -0
- package/dist/errors.d.ts +47 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/errors.js +65 -0
- package/dist/errors.js.map +1 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -0
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -16,7 +16,26 @@ This SDK is for **Lite Edge** - edges that require constant connectivity. For of
|
|
|
16
16
|
npm install @fatagnus/dink-sdk
|
|
17
17
|
```
|
|
18
18
|
|
|
19
|
-
## Quick Start
|
|
19
|
+
## Quick Start (createEdgeWorker)
|
|
20
|
+
|
|
21
|
+
The fastest way to start an edge service:
|
|
22
|
+
|
|
23
|
+
```typescript
|
|
24
|
+
import { createEdgeWorker } from '@fatagnus/dink-sdk/edge';
|
|
25
|
+
import { createServices } from './generated/registry.js';
|
|
26
|
+
import { SensorServiceImpl } from './sensor-impl.js';
|
|
27
|
+
|
|
28
|
+
await createEdgeWorker({
|
|
29
|
+
services: createServices({ sensor: new SensorServiceImpl() }),
|
|
30
|
+
labels: { region: 'us-east', type: 'sensor' },
|
|
31
|
+
});
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
Credentials resolve automatically from `DINK_EDGE_KEY` or `DINK_API_KEY` environment variables. Graceful shutdown on SIGINT/SIGTERM is built-in.
|
|
35
|
+
|
|
36
|
+
For more control, see the [EdgeClient](#quick-start-edgeclient) section below.
|
|
37
|
+
|
|
38
|
+
## Quick Start (EdgeClient)
|
|
20
39
|
|
|
21
40
|
### Edge Client
|
|
22
41
|
|
|
@@ -81,6 +100,23 @@ const result = await center.call({
|
|
|
81
100
|
console.log(result); // { temperature: 22.5 }
|
|
82
101
|
```
|
|
83
102
|
|
|
103
|
+
### Error Types
|
|
104
|
+
|
|
105
|
+
Typed errors for structured error handling:
|
|
106
|
+
|
|
107
|
+
```typescript
|
|
108
|
+
import { ConnectionError, AuthError, ServiceError, TimeoutError, ConfigError } from '@fatagnus/dink-sdk';
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
| Error | Code | Fields | Use Case |
|
|
112
|
+
|-------|------|--------|----------|
|
|
113
|
+
| `DinkError` | varies | `code` | Base class for all SDK errors |
|
|
114
|
+
| `ConnectionError` | `CONNECTION_ERROR` | | NATS connection issues |
|
|
115
|
+
| `AuthError` | `AUTH_ERROR` | | Invalid/expired/revoked keys |
|
|
116
|
+
| `ServiceError` | `SERVICE_ERROR` | `status`, `service`, `method` | RPC call failures |
|
|
117
|
+
| `TimeoutError` | `TIMEOUT` | `timeoutMs` | Request timeouts |
|
|
118
|
+
| `ConfigError` | `CONFIG_ERROR` | | Missing required configuration |
|
|
119
|
+
|
|
84
120
|
### Peer RPC (Edge-to-Edge)
|
|
85
121
|
|
|
86
122
|
Edges in the same group can call each other's services directly:
|
package/dist/edge/index.d.ts
CHANGED
package/dist/edge/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/edge/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/edge/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AACtD,OAAO,EAAE,gBAAgB,EAAE,KAAK,iBAAiB,EAAE,KAAK,gBAAgB,EAAE,MAAM,aAAa,CAAC"}
|
package/dist/edge/index.js
CHANGED
package/dist/edge/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/edge/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/edge/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AACtD,OAAO,EAAE,gBAAgB,EAAiD,MAAM,aAAa,CAAC"}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { EdgeClient } from './client.js';
|
|
2
|
+
import type { ServiceHandler } from '../types.js';
|
|
3
|
+
/**
|
|
4
|
+
* Options for createEdgeWorker.
|
|
5
|
+
*/
|
|
6
|
+
export interface EdgeWorkerOptions {
|
|
7
|
+
/** Services to expose. Required, at least one. */
|
|
8
|
+
services: ServiceHandler[];
|
|
9
|
+
/** API key. Defaults to process.env.DINK_EDGE_KEY || process.env.DINK_API_KEY */
|
|
10
|
+
apiKey?: string;
|
|
11
|
+
/** Server URL. Optional if using new key format with embedded URL. Defaults to process.env.DINK_SERVER_URL */
|
|
12
|
+
serverUrl?: string;
|
|
13
|
+
/** Display name for the edge. Defaults to process.env.EDGE_NAME */
|
|
14
|
+
edgeName?: string;
|
|
15
|
+
/** Labels for edge discovery */
|
|
16
|
+
labels?: Record<string, string>;
|
|
17
|
+
/** Heartbeat interval in ms (default: 30000) */
|
|
18
|
+
heartbeatInterval?: number;
|
|
19
|
+
/** Whether to register SIGINT/SIGTERM handlers for graceful shutdown (default: true) */
|
|
20
|
+
gracefulShutdown?: boolean;
|
|
21
|
+
/** Callback when connected */
|
|
22
|
+
onConnected?: (edge: EdgeClient) => void;
|
|
23
|
+
/** Callback when disconnected */
|
|
24
|
+
onDisconnected?: () => void;
|
|
25
|
+
/** Callback on error */
|
|
26
|
+
onError?: (error: Error) => void;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Handle returned by createEdgeWorker for lifecycle control.
|
|
30
|
+
*/
|
|
31
|
+
export interface EdgeWorkerHandle {
|
|
32
|
+
/** The underlying EdgeClient instance */
|
|
33
|
+
client: EdgeClient;
|
|
34
|
+
/** Gracefully shut down the worker */
|
|
35
|
+
shutdown: () => Promise<void>;
|
|
36
|
+
/** Promise that resolves when the worker shuts down */
|
|
37
|
+
done: Promise<void>;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Create and start an edge worker with minimal configuration.
|
|
41
|
+
*
|
|
42
|
+
* Handles credential resolution from environment, connection, service exposure,
|
|
43
|
+
* signal handling, and graceful shutdown automatically.
|
|
44
|
+
*
|
|
45
|
+
* @example
|
|
46
|
+
* ```typescript
|
|
47
|
+
* import { createEdgeWorker } from '@fatagnus/dink-sdk/edge'
|
|
48
|
+
* import { SensorServiceHandler } from './generated/sensorservice.handler.js'
|
|
49
|
+
* import { SensorServiceImpl } from './sensor-impl.js'
|
|
50
|
+
*
|
|
51
|
+
* await createEdgeWorker({
|
|
52
|
+
* services: [new SensorServiceHandler(new SensorServiceImpl())],
|
|
53
|
+
* labels: { region: 'us-east', type: 'sensor' },
|
|
54
|
+
* })
|
|
55
|
+
* ```
|
|
56
|
+
*/
|
|
57
|
+
export declare function createEdgeWorker(options: EdgeWorkerOptions): Promise<EdgeWorkerHandle>;
|
|
58
|
+
//# sourceMappingURL=worker.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"worker.d.ts","sourceRoot":"","sources":["../../src/edge/worker.ts"],"names":[],"mapp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+
*
|
|
5
|
+
* Handles credential resolution from environment, connection, service exposure,
|
|
6
|
+
* signal handling, and graceful shutdown automatically.
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* ```typescript
|
|
10
|
+
* import { createEdgeWorker } from '@fatagnus/dink-sdk/edge'
|
|
11
|
+
* import { SensorServiceHandler } from './generated/sensorservice.handler.js'
|
|
12
|
+
* import { SensorServiceImpl } from './sensor-impl.js'
|
|
13
|
+
*
|
|
14
|
+
* await createEdgeWorker({
|
|
15
|
+
* services: [new SensorServiceHandler(new SensorServiceImpl())],
|
|
16
|
+
* labels: { region: 'us-east', type: 'sensor' },
|
|
17
|
+
* })
|
|
18
|
+
* ```
|
|
19
|
+
*/
|
|
20
|
+
export async function createEdgeWorker(options) {
|
|
21
|
+
if (!options.services || options.services.length === 0) {
|
|
22
|
+
throw new Error('At least one service is required');
|
|
23
|
+
}
|
|
24
|
+
// Resolve credentials from options or environment
|
|
25
|
+
const apiKey = options.apiKey
|
|
26
|
+
|| (typeof process !== 'undefined' ? process.env.DINK_EDGE_KEY : undefined)
|
|
27
|
+
|| (typeof process !== 'undefined' ? process.env.DINK_API_KEY : undefined);
|
|
28
|
+
if (!apiKey) {
|
|
29
|
+
throw new Error('Edge API key is required. Set DINK_EDGE_KEY or DINK_API_KEY environment variable, '
|
|
30
|
+
+ 'or pass apiKey in options.');
|
|
31
|
+
}
|
|
32
|
+
const serverUrl = options.serverUrl
|
|
33
|
+
|| (typeof process !== 'undefined' ? process.env.DINK_SERVER_URL : undefined);
|
|
34
|
+
const edgeName = options.edgeName
|
|
35
|
+
|| (typeof process !== 'undefined' ? process.env.EDGE_NAME : undefined);
|
|
36
|
+
const edge = new EdgeClient({
|
|
37
|
+
apiKey,
|
|
38
|
+
serverUrl,
|
|
39
|
+
edgeName,
|
|
40
|
+
labels: options.labels,
|
|
41
|
+
heartbeatInterval: options.heartbeatInterval,
|
|
42
|
+
});
|
|
43
|
+
// Connect
|
|
44
|
+
await edge.connect();
|
|
45
|
+
if (options.onConnected) {
|
|
46
|
+
options.onConnected(edge);
|
|
47
|
+
}
|
|
48
|
+
// Expose all services
|
|
49
|
+
for (const service of options.services) {
|
|
50
|
+
await edge.exposeService(service);
|
|
51
|
+
}
|
|
52
|
+
// Track connection quality changes for callbacks
|
|
53
|
+
if (options.onDisconnected || options.onError) {
|
|
54
|
+
edge.onConnectionQualityChange((quality) => {
|
|
55
|
+
if (quality.state === 'disconnected' && options.onDisconnected) {
|
|
56
|
+
options.onDisconnected();
|
|
57
|
+
}
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
// Create shutdown function
|
|
61
|
+
let shutdownCalled = false;
|
|
62
|
+
let resolveShutdown;
|
|
63
|
+
const done = new Promise((resolve) => {
|
|
64
|
+
resolveShutdown = resolve;
|
|
65
|
+
});
|
|
66
|
+
const shutdown = async () => {
|
|
67
|
+
if (shutdownCalled)
|
|
68
|
+
return;
|
|
69
|
+
shutdownCalled = true;
|
|
70
|
+
try {
|
|
71
|
+
await edge.disconnect();
|
|
72
|
+
}
|
|
73
|
+
catch {
|
|
74
|
+
// Ignore disconnect errors during shutdown
|
|
75
|
+
}
|
|
76
|
+
resolveShutdown();
|
|
77
|
+
};
|
|
78
|
+
// Register signal handlers for graceful shutdown
|
|
79
|
+
const enableSignals = options.gracefulShutdown !== false;
|
|
80
|
+
if (enableSignals && typeof process !== 'undefined' && process.on) {
|
|
81
|
+
const handler = () => {
|
|
82
|
+
shutdown();
|
|
83
|
+
};
|
|
84
|
+
process.on('SIGINT', handler);
|
|
85
|
+
process.on('SIGTERM', handler);
|
|
86
|
+
}
|
|
87
|
+
return { client: edge, shutdown, done };
|
|
88
|
+
}
|
|
89
|
+
//# sourceMappingURL=worker.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"worker.js","sourceRoot":"","sources":["../../src/edge/worker.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAA;AAoDxC;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E,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAA;QAC7B,OAAO,CAAC,EAAE,CAAC,SAAS,EAAE,OAAO,CAAC,CAAA;IAC/B,CAAC;IAED,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAA;AACxC,CAAC"}
|
package/dist/errors.d.ts
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Base error class for all Dink SDK errors.
|
|
3
|
+
*/
|
|
4
|
+
export declare class DinkError extends Error {
|
|
5
|
+
readonly code: string;
|
|
6
|
+
constructor(message: string, code: string);
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* Connection-related errors (NATS connect, disconnect, timeout).
|
|
10
|
+
*/
|
|
11
|
+
export declare class ConnectionError extends DinkError {
|
|
12
|
+
constructor(message: string, code?: string);
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Authentication/authorization errors (invalid key, expired, revoked).
|
|
16
|
+
*/
|
|
17
|
+
export declare class AuthError extends DinkError {
|
|
18
|
+
constructor(message: string, code?: string);
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Service RPC errors with status codes.
|
|
22
|
+
*/
|
|
23
|
+
export declare class ServiceError extends DinkError {
|
|
24
|
+
readonly status: number;
|
|
25
|
+
readonly service: string;
|
|
26
|
+
readonly method: string;
|
|
27
|
+
constructor(message: string, opts: {
|
|
28
|
+
status?: number;
|
|
29
|
+
service?: string;
|
|
30
|
+
method?: string;
|
|
31
|
+
code?: string;
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Timeout errors for requests that exceeded their deadline.
|
|
36
|
+
*/
|
|
37
|
+
export declare class TimeoutError extends DinkError {
|
|
38
|
+
readonly timeoutMs: number;
|
|
39
|
+
constructor(message: string, timeoutMs: number);
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Configuration errors (missing required fields, invalid values).
|
|
43
|
+
*/
|
|
44
|
+
export declare class ConfigError extends DinkError {
|
|
45
|
+
constructor(message: string);
|
|
46
|
+
}
|
|
47
|
+
//# sourceMappingURL=errors.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,qBAAa,SAAU,SAAQ,KAAK;IACnC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAA;gBAET,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM;CAKzC;AAED;;GAEG;AACH,qBAAa,eAAgB,SAAQ,SAAS;gBACjC,OAAO,EAAE,MAAM,EAAE,IAAI,GAAE,MAA2B;CAI9D;AAED;;GAEG;AACH,qBAAa,SAAU,SAAQ,SAAS;gBAC3B,OAAO,EAAE,MAAM,EAAE,IAAI,GAAE,MAAqB;CAIxD;AAED;;GAEG;AACH,qBAAa,YAAa,SAAQ,SAAS;IAC1C,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAA;IACvB,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAA;IACxB,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAA;gBAEX,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE;QAAE,MAAM,CAAC,EAAE,MAAM,CAAC;QAAC,OAAO,CAAC,EAAE,MAAM,CAAC;QAAC,MAAM,CAAC,EAAE,MAAM,CAAC;QAAC,IAAI,CAAC,EAAE,MAAM,CAAA;KAAE;CAOxG;AAED;;GAEG;AACH,qBAAa,YAAa,SAAQ,SAAS;IAC1C,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAA;gBAEd,OAAO,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM;CAK9C;AAED;;GAEG;AACH,qBAAa,WAAY,SAAQ,SAAS;gBAC7B,OAAO,EAAE,MAAM;CAI3B"}
|
package/dist/errors.js
ADDED
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Base error class for all Dink SDK errors.
|
|
3
|
+
*/
|
|
4
|
+
export class DinkError extends Error {
|
|
5
|
+
code;
|
|
6
|
+
constructor(message, code) {
|
|
7
|
+
super(message);
|
|
8
|
+
this.name = 'DinkError';
|
|
9
|
+
this.code = code;
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Connection-related errors (NATS connect, disconnect, timeout).
|
|
14
|
+
*/
|
|
15
|
+
export class ConnectionError extends DinkError {
|
|
16
|
+
constructor(message, code = 'CONNECTION_ERROR') {
|
|
17
|
+
super(message, code);
|
|
18
|
+
this.name = 'ConnectionError';
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Authentication/authorization errors (invalid key, expired, revoked).
|
|
23
|
+
*/
|
|
24
|
+
export class AuthError extends DinkError {
|
|
25
|
+
constructor(message, code = 'AUTH_ERROR') {
|
|
26
|
+
super(message, code);
|
|
27
|
+
this.name = 'AuthError';
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Service RPC errors with status codes.
|
|
32
|
+
*/
|
|
33
|
+
export class ServiceError extends DinkError {
|
|
34
|
+
status;
|
|
35
|
+
service;
|
|
36
|
+
method;
|
|
37
|
+
constructor(message, opts) {
|
|
38
|
+
super(message, opts.code ?? 'SERVICE_ERROR');
|
|
39
|
+
this.name = 'ServiceError';
|
|
40
|
+
this.status = opts.status ?? 500;
|
|
41
|
+
this.service = opts.service ?? '';
|
|
42
|
+
this.method = opts.method ?? '';
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Timeout errors for requests that exceeded their deadline.
|
|
47
|
+
*/
|
|
48
|
+
export class TimeoutError extends DinkError {
|
|
49
|
+
timeoutMs;
|
|
50
|
+
constructor(message, timeoutMs) {
|
|
51
|
+
super(message, 'TIMEOUT');
|
|
52
|
+
this.name = 'TimeoutError';
|
|
53
|
+
this.timeoutMs = timeoutMs;
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Configuration errors (missing required fields, invalid values).
|
|
58
|
+
*/
|
|
59
|
+
export class ConfigError extends DinkError {
|
|
60
|
+
constructor(message) {
|
|
61
|
+
super(message, 'CONFIG_ERROR');
|
|
62
|
+
this.name = 'ConfigError';
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
//# sourceMappingURL=errors.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,OAAO,SAAU,SAAQ,KAAK;IAC1B,IAAI,CAAQ;IAErB,YAAY,OAAe,EAAE,IAAY;QACxC,KAAK,CAAC,OAAO,CAAC,CAAA;QACd,IAAI,CAAC,IAAI,GAAG,WAAW,CAAA;QACvB,IAAI,CAAC,IAAI,GAAG,IAAI,CAAA;IACjB,CAAC;CACD;AAED;;GAEG;AACH,MAAM,OAAO,eAAgB,SAAQ,SAAS;IAC7C,YAAY,OAAe,EAAE,OAAe,kBAAkB;QAC7D,KAAK,CAAC,OAAO,EAAE,IAAI,CAAC,CAAA;QACpB,IAAI,CAAC,IAAI,GAAG,iBAAiB,CAAA;IAC9B,CAAC;CACD;AAED;;GAEG;AACH,MAAM,OAAO,SAAU,SAAQ,SAAS;IACvC,YAAY,OAAe,EAAE,OAAe,YAAY;QACvD,KAAK,CAAC,OAAO,EAAE,IAAI,CAAC,CAAA;QACpB,IAAI,CAAC,IAAI,GAAG,WAAW,CAAA;IACxB,CAAC;CACD;AAED;;GAEG;AACH,MAAM,OAAO,YAAa,SAAQ,SAAS;IACjC,MAAM,CAAQ;IACd,OAAO,CAAQ;IACf,MAAM,CAAQ;IAEvB,YAAY,OAAe,EAAE,IAA2E;QACvG,KAAK,CAAC,OAAO,EAAE,IAAI,CAAC,IAAI,IAAI,eAAe,CAAC,CAAA;QAC5C,IAAI,CAAC,IAAI,GAAG,cAAc,CAAA;QAC1B,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC,MAAM,IAAI,GAAG,CAAA;QAChC,IAAI,CAAC,OAAO,GAAG,IAAI,CAAC,OAAO,IAAI,EAAE,CAAA;QACjC,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC,MAAM,IAAI,EAAE,CAAA;IAChC,CAAC;CACD;AAED;;GAEG;AACH,MAAM,OAAO,YAAa,SAAQ,SAAS;IACjC,SAAS,CAAQ;IAE1B,YAAY,OAAe,EAAE,SAAiB;QAC7C,KAAK,CAAC,OAAO,EAAE,SAAS,CAAC,CAAA;QACzB,IAAI,CAAC,IAAI,GAAG,cAAc,CAAA;QAC1B,IAAI,CAAC,SAAS,GAAG,SAAS,CAAA;IAC3B,CAAC;CACD;AAED;;GAEG;AACH,MAAM,OAAO,WAAY,SAAQ,SAAS;IACzC,YAAY,OAAe;QAC1B,KAAK,CAAC,OAAO,EAAE,cAAc,CAAC,CAAA;QAC9B,IAAI,CAAC,IAAI,GAAG,aAAa,CAAA;IAC1B,CAAC;CACD"}
|
package/dist/index.d.ts
CHANGED
|
@@ -2,6 +2,8 @@ export type { ServiceDefinition, ServiceHandler, ServiceCaller, Subscription, Ke
|
|
|
2
2
|
export { extractPayload, wrapResponse } from './types.js';
|
|
3
3
|
export { EdgeClient, parseEdgeKey, type ParsedEdgeKey } from './edge/client.js';
|
|
4
4
|
export { ServiceBuilder } from './edge/service-builder.js';
|
|
5
|
+
export { createEdgeWorker, type EdgeWorkerOptions, type EdgeWorkerHandle } from './edge/worker.js';
|
|
5
6
|
export { CenterClient } from './center/index.js';
|
|
6
7
|
export { loadDinkEnv, DinkEnvError, type DinkEnv, type LoadOptions } from './env/index.js';
|
|
8
|
+
export { DinkError, ConnectionError, AuthError, ServiceError, TimeoutError, ConfigError } from './errors.js';
|
|
7
9
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAIA,YAAY,EACV,iBAAiB,EACjB,cAAc,EACd,aAAa,EACb,YAAY,EAEZ,OAAO,EACP,SAAS,EACT,WAAW,EACX,gBAAgB,EAChB,eAAe,EACf,eAAe,GAChB,MAAM,YAAY,CAAC;AAGpB,OAAO,EAAE,cAAc,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAG1D,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,KAAK,aAAa,EAAE,MAAM,kBAAkB,CAAC;AAChF,OAAO,EAAE,cAAc,EAAE,MAAM,2BAA2B,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAIA,YAAY,EACV,iBAAiB,EACjB,cAAc,EACd,aAAa,EACb,YAAY,EAEZ,OAAO,EACP,SAAS,EACT,WAAW,EACX,gBAAgB,EAChB,eAAe,EACf,eAAe,GAChB,MAAM,YAAY,CAAC;AAGpB,OAAO,EAAE,cAAc,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAG1D,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,KAAK,aAAa,EAAE,MAAM,kBAAkB,CAAC;AAChF,OAAO,EAAE,cAAc,EAAE,MAAM,2BAA2B,CAAC;AAC3D,OAAO,EAAE,gBAAgB,EAAE,KAAK,iBAAiB,EAAE,KAAK,gBAAgB,EAAE,MAAM,kBAAkB,CAAC;AAGnG,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAGjD,OAAO,EAAE,WAAW,EAAE,YAAY,EAAE,KAAK,OAAO,EAAE,KAAK,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAG3F,OAAO,EAAE,SAAS,EAAE,eAAe,EAAE,SAAS,EAAE,YAAY,EAAE,YAAY,EAAE,WAAW,EAAE,MAAM,aAAa,CAAA"}
|
package/dist/index.js
CHANGED
|
@@ -5,8 +5,11 @@ export { extractPayload, wrapResponse } from './types.js';
|
|
|
5
5
|
// Export edge client for connecting edge devices to dinkd
|
|
6
6
|
export { EdgeClient, parseEdgeKey } from './edge/client.js';
|
|
7
7
|
export { ServiceBuilder } from './edge/service-builder.js';
|
|
8
|
+
export { createEdgeWorker } from './edge/worker.js';
|
|
8
9
|
// Export center client for connecting to dinkd from the center/cloud
|
|
9
10
|
export { CenterClient } from './center/index.js';
|
|
10
11
|
// Export environment/credential loader (Node.js only)
|
|
11
12
|
export { loadDinkEnv, DinkEnvError } from './env/index.js';
|
|
13
|
+
// Export error types
|
|
14
|
+
export { DinkError, ConnectionError, AuthError, ServiceError, TimeoutError, ConfigError } from './errors.js';
|
|
12
15
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,kEAAkE;AAClE,2EAA2E;AAiB3E,0BAA0B;AAC1B,OAAO,EAAE,cAAc,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAE1D,0DAA0D;AAC1D,OAAO,EAAE,UAAU,EAAE,YAAY,EAAsB,MAAM,kBAAkB,CAAC;AAChF,OAAO,EAAE,cAAc,EAAE,MAAM,2BAA2B,CAAC;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,kEAAkE;AAClE,2EAA2E;AAiB3E,0BAA0B;AAC1B,OAAO,EAAE,cAAc,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAE1D,0DAA0D;AAC1D,OAAO,EAAE,UAAU,EAAE,YAAY,EAAsB,MAAM,kBAAkB,CAAC;AAChF,OAAO,EAAE,cAAc,EAAE,MAAM,2BAA2B,CAAC;AAC3D,OAAO,EAAE,gBAAgB,EAAiD,MAAM,kBAAkB,CAAC;AAEnG,qEAAqE;AACrE,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAEjD,sDAAsD;AACtD,OAAO,EAAE,WAAW,EAAE,YAAY,EAAkC,MAAM,gBAAgB,CAAC;AAE3F,qBAAqB;AACrB,OAAO,EAAE,SAAS,EAAE,eAAe,EAAE,SAAS,EAAE,YAAY,EAAE,YAAY,EAAE,WAAW,EAAE,MAAM,aAAa,CAAA"}
|