@versori/run 0.1.0-alpha.9 → 0.2.0-alpha.2
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/esm/_dnt.shims.d.ts +1 -5
- package/esm/_dnt.shims.d.ts.map +1 -1
- package/esm/_dnt.shims.js +1 -5
- package/esm/deps/jsr.io/@nats-io/transport-deno/3.0.2/src/deno_transport.d.ts +1 -2
- package/esm/deps/jsr.io/@nats-io/transport-deno/3.0.2/src/deno_transport.d.ts.map +1 -1
- package/esm/deps/jsr.io/@nats-io/transport-deno/3.0.2/src/deno_transport.js +6 -7
- package/esm/deps/jsr.io/@std/fs/1.0.16/exists.d.ts +1 -0
- package/esm/deps/jsr.io/@std/fs/1.0.16/exists.d.ts.map +1 -1
- package/esm/deps/jsr.io/@std/fs/1.0.16/exists.js +10 -12
- package/esm/deps/jsr.io/@std/log/0.224.14/base_handler.d.ts +0 -21
- package/esm/deps/jsr.io/@std/log/0.224.14/base_handler.d.ts.map +1 -1
- package/esm/deps/jsr.io/@std/log/0.224.14/file_handler.d.ts +2 -3
- package/esm/deps/jsr.io/@std/log/0.224.14/file_handler.d.ts.map +1 -1
- package/esm/deps/jsr.io/@std/log/0.224.14/file_handler.js +1 -2
- package/esm/deps/jsr.io/@std/log/0.224.14/rotating_file_handler.d.ts.map +1 -1
- package/esm/deps/jsr.io/@std/log/0.224.14/rotating_file_handler.js +6 -8
- package/esm/src/context/Context.d.ts +14 -4
- package/esm/src/context/Context.d.ts.map +1 -1
- package/esm/src/context/Context.js +16 -10
- package/esm/src/context/ContextProvider.d.ts +3 -4
- package/esm/src/context/ContextProvider.d.ts.map +1 -1
- package/esm/src/context/ContextProvider.js +5 -5
- package/esm/src/dsl/http/versori/configloader.d.ts.map +1 -1
- package/esm/src/dsl/http/versori/configloader.js +2 -3
- package/esm/src/dsl/http/versori/internalauth.d.ts.map +1 -1
- package/esm/src/dsl/http/versori/internalauth.js +5 -6
- package/esm/src/dsl/http/versori/platformapi.d.ts.map +1 -1
- package/esm/src/dsl/http/versori/platformapi.js +3 -4
- package/esm/src/dsl/http/versori/roundtripper.d.ts.map +1 -1
- package/esm/src/dsl/http/versori/roundtripper.js +5 -6
- package/esm/src/dsl/tasks/HttpTask.d.ts +1 -1
- package/esm/src/dsl/tasks/HttpTask.d.ts.map +1 -1
- package/esm/src/dsl/tasks/HttpTask.js +1 -1
- package/esm/src/dsl/triggers/WebhookTrigger.d.ts +45 -3
- package/esm/src/dsl/triggers/WebhookTrigger.d.ts.map +1 -1
- package/esm/src/dsl/triggers/WebhookTrigger.js +10 -6
- package/esm/src/interpreter/memory/MemoryInterpreter.d.ts +6 -1
- package/esm/src/interpreter/memory/MemoryInterpreter.d.ts.map +1 -1
- package/esm/src/interpreter/memory/MemoryInterpreter.js +79 -10
- package/esm/src/interpreter/memory/compilers/schedule.js +1 -1
- package/esm/src/interpreter/memory/compilers/webhook.d.ts.map +1 -1
- package/esm/src/interpreter/memory/compilers/webhook.js +132 -25
- package/esm/src/kv/nats/NatsKeyValueProvider.d.ts +0 -1
- package/esm/src/kv/nats/NatsKeyValueProvider.d.ts.map +1 -1
- package/esm/src/kv/nats/NatsKeyValueProvider.js +7 -8
- package/package.json +3 -6
- package/script/_dnt.shims.d.ts +1 -5
- package/script/_dnt.shims.d.ts.map +1 -1
- package/script/_dnt.shims.js +2 -7
- package/script/deps/jsr.io/@nats-io/transport-deno/3.0.2/src/deno_transport.d.ts +1 -2
- package/script/deps/jsr.io/@nats-io/transport-deno/3.0.2/src/deno_transport.d.ts.map +1 -1
- package/script/deps/jsr.io/@nats-io/transport-deno/3.0.2/src/deno_transport.js +9 -33
- package/script/deps/jsr.io/@std/fs/1.0.16/exists.d.ts +1 -0
- package/script/deps/jsr.io/@std/fs/1.0.16/exists.d.ts.map +1 -1
- package/script/deps/jsr.io/@std/fs/1.0.16/exists.js +10 -35
- package/script/deps/jsr.io/@std/log/0.224.14/base_handler.d.ts +0 -21
- package/script/deps/jsr.io/@std/log/0.224.14/base_handler.d.ts.map +1 -1
- package/script/deps/jsr.io/@std/log/0.224.14/file_handler.d.ts +2 -3
- package/script/deps/jsr.io/@std/log/0.224.14/file_handler.d.ts.map +1 -1
- package/script/deps/jsr.io/@std/log/0.224.14/file_handler.js +1 -25
- package/script/deps/jsr.io/@std/log/0.224.14/rotating_file_handler.d.ts.map +1 -1
- package/script/deps/jsr.io/@std/log/0.224.14/rotating_file_handler.js +6 -31
- package/script/src/context/Context.d.ts +14 -4
- package/script/src/context/Context.d.ts.map +1 -1
- package/script/src/context/Context.js +16 -10
- package/script/src/context/ContextProvider.d.ts +3 -4
- package/script/src/context/ContextProvider.d.ts.map +1 -1
- package/script/src/context/ContextProvider.js +5 -5
- package/script/src/dsl/http/versori/configloader.d.ts.map +1 -1
- package/script/src/dsl/http/versori/configloader.js +2 -26
- package/script/src/dsl/http/versori/internalauth.d.ts.map +1 -1
- package/script/src/dsl/http/versori/internalauth.js +5 -29
- package/script/src/dsl/http/versori/platformapi.d.ts.map +1 -1
- package/script/src/dsl/http/versori/platformapi.js +3 -27
- package/script/src/dsl/http/versori/roundtripper.d.ts.map +1 -1
- package/script/src/dsl/http/versori/roundtripper.js +5 -29
- package/script/src/dsl/tasks/HttpTask.d.ts +1 -1
- package/script/src/dsl/tasks/HttpTask.d.ts.map +1 -1
- package/script/src/dsl/tasks/HttpTask.js +1 -1
- package/script/src/dsl/triggers/WebhookTrigger.d.ts +45 -3
- package/script/src/dsl/triggers/WebhookTrigger.d.ts.map +1 -1
- package/script/src/dsl/triggers/WebhookTrigger.js +10 -6
- package/script/src/interpreter/memory/MemoryInterpreter.d.ts +6 -1
- package/script/src/interpreter/memory/MemoryInterpreter.d.ts.map +1 -1
- package/script/src/interpreter/memory/MemoryInterpreter.js +79 -33
- package/script/src/interpreter/memory/compilers/schedule.js +1 -1
- package/script/src/interpreter/memory/compilers/webhook.d.ts.map +1 -1
- package/script/src/interpreter/memory/compilers/webhook.js +135 -25
- package/script/src/kv/nats/NatsKeyValueProvider.d.ts +0 -1
- package/script/src/kv/nats/NatsKeyValueProvider.d.ts.map +1 -1
- package/script/src/kv/nats/NatsKeyValueProvider.js +7 -31
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import * as dntShim from "../../../../_dnt.shims.js";
|
|
2
1
|
import { LoadConfigFromFile } from './configloader.js';
|
|
3
2
|
import { VersoriCredentialClient } from './credentials/mod.js';
|
|
4
3
|
import { PlatformAPIClient } from './platformapi.js';
|
|
@@ -59,10 +58,10 @@ export class VersoriRoundTripperFactory {
|
|
|
59
58
|
this.log = logger;
|
|
60
59
|
}
|
|
61
60
|
static fromEnv(logger) {
|
|
62
|
-
const credsBaseURL =
|
|
63
|
-
const platformApiBaseURL =
|
|
64
|
-
const orgId =
|
|
65
|
-
const envId =
|
|
61
|
+
const credsBaseURL = Deno.env.get(envVarCredsBaseURL);
|
|
62
|
+
const platformApiBaseURL = Deno.env.get(envVarPlatformApiBaseURL);
|
|
63
|
+
const orgId = Deno.env.get(envVarOrgId);
|
|
64
|
+
const envId = Deno.env.get(envVarEnvId);
|
|
66
65
|
if (!orgId || !envId || !platformApiBaseURL || !credsBaseURL) {
|
|
67
66
|
const missingVars = [];
|
|
68
67
|
if (!orgId)
|
|
@@ -75,7 +74,7 @@ export class VersoriRoundTripperFactory {
|
|
|
75
74
|
missingVars.push(envVarCredsBaseURL);
|
|
76
75
|
throw new Error(`Missing environment variables: ${missingVars.join(', ')}`);
|
|
77
76
|
}
|
|
78
|
-
const pAPIClient = new PlatformAPIClient(platformApiBaseURL, orgId, envId
|
|
77
|
+
const pAPIClient = new PlatformAPIClient(platformApiBaseURL, orgId, envId);
|
|
79
78
|
const tokenClient = new VersoriCredentialClient(credsBaseURL);
|
|
80
79
|
const log = logger || new ConsoleLogger('debug');
|
|
81
80
|
return new VersoriRoundTripperFactory(tokenClient, pAPIClient, log);
|
|
@@ -33,7 +33,7 @@ export declare class HttpContextImpl<D, PageParams> extends ContextImpl<D> imple
|
|
|
33
33
|
pageParams?: PageParams;
|
|
34
34
|
private dynamicFetcher?;
|
|
35
35
|
private staticFetcher?;
|
|
36
|
-
constructor(ctx:
|
|
36
|
+
constructor(ctx: ContextImpl<D, any>, connectionVars: Record<string, any>, staticFetcher?: typeof globalThis.fetch, dynamicFetcher?: DynamicFetcher, pageParams?: PageParams);
|
|
37
37
|
get fetch(): typeof globalThis.fetch;
|
|
38
38
|
nextPage(nextParams: PageParams): Promise<void>;
|
|
39
39
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"HttpTask.d.ts","sourceRoot":"","sources":["../../../../src/src/dsl/tasks/HttpTask.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,WAAW,EAAmB,MAAM,0BAA0B,CAAC;AAGjF,OAAO,EAAc,cAAc,EAAsB,MAAM,kBAAkB,CAAC;AAClF,OAAO,EAAE,SAAS,EAAE,IAAI,EAAE,QAAQ,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAOjE,MAAM,WAAW,WAAW,CAAC,IAAI,EAAE,UAAU,GAAG,SAAS,CAAE,SAAQ,OAAO,CAAC,IAAI,CAAC;IAC5E,KAAK,EAAE,OAAO,KAAK,CAAC;IACpB,mBAAmB,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;IACzC,UAAU,CAAC,EAAE,UAAU,CAAC;IACxB,QAAQ,EAAE,CAAC,UAAU,EAAE,UAAU,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;CACvD;AAED,MAAM,MAAM,eAAe,CAAC,EAAE,EAAE,GAAG,EAAE,UAAU,IAAI,CAC/C,GAAG,EAAE,WAAW,CAAC,EAAE,EAAE,UAAU,CAAC,KAC/B,OAAO,CAAC,GAAG,CAAC,CAAC;AAElB,MAAM,MAAM,eAAe,CAAC,CAAC,IAAI;IAC7B,aAAa,EAAE,CAAC,CAAC;CACpB,CAAC;AAEF,MAAM,MAAM,WAAW,CAAC,EAAE,EAAE,GAAG,EA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e,CAAC,CAAC,EAAE,UAAU,CAAE,SAAQ,WAAW,CAAC,CAAC,CAAE,YAAW,WAAW,CAAC,CAAC,EAAE,UAAU,CAAC;IACpG,mBAAmB,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAM;IAC9C,UAAU,CAAC,EAAE,UAAU,CAAC;IAGxB,OAAO,CAAC,cAAc,CAAC,CAAiB;IACxC,OAAO,CAAC,aAAa,CAAC,CAA0B;gBAG5C,GAAG,EAAE,WAAW,CAAC,CAAC,EAAE,GAAG,CAAC,EACxB,cAAc,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,EACnC,aAAa,CAAC,EAAE,OAAO,UAAU,CAAC,KAAK,EACvC,cAAc,CAAC,EAAE,cAAc,EAC/B,UAAU,CAAC,EAAE,UAAU;IAkB3B,IAAI,KAAK,IAAI,OAAO,UAAU,CAAC,KAAK,CAGnC;IAEK,QAAQ,CAAC,UAAU,EAAE,UAAU,GAAG,OAAO,CAAC,IAAI,CAAC;CAGxD;AAED,wBAAgB,IAAI,CAAC,EAAE,GAAG,GAAG,EAAE,GAAG,GAAG,GAAG,EAAE,UAAU,GAAG,OAAO,EAC1D,MAAM,EAAE,MAAM,EACd,IAAI,EAAE,WAAW,CAAC,EAAE,EAAE,GAAG,EAAE,UAAU,CAAC,EACtC,EAAE,EAAE,eAAe,CAAC,EAAE,EAAE,GAAG,EAAE,UAAU,CAAC,GACzC,IAAI,CAAC,EAAE,EAAE,GAAG,CAAC,CAEf"}
|
|
@@ -61,7 +61,7 @@ export class HttpContextImpl extends ContextImpl {
|
|
|
61
61
|
constructor(ctx, connectionVars, staticFetcher, dynamicFetcher, pageParams) {
|
|
62
62
|
// We need to cast ctx to InternalContext to access kvp
|
|
63
63
|
const internalCtx = ctx;
|
|
64
|
-
super(ctx.log, internalCtx.kvp, ctx.executionId, ctx.startTime, ctx.data, ctx.
|
|
64
|
+
super(ctx.log, internalCtx.kvp, ctx.executionId, ctx.startTime, ctx.data, ctx.options);
|
|
65
65
|
Object.defineProperty(this, "connectionVariables", {
|
|
66
66
|
enumerable: true,
|
|
67
67
|
configurable: true,
|
|
@@ -1,13 +1,55 @@
|
|
|
1
|
+
import { Context } from '../../context/Context.js';
|
|
1
2
|
import { Taskable } from '../Task.js';
|
|
2
3
|
import { Trigger, TriggerType } from '../Trigger.js';
|
|
3
4
|
import { Workflow } from '../Workflow.js';
|
|
4
5
|
export type WebhookData = Record<string, never>;
|
|
6
|
+
export type WebhookCorsOptions = boolean | {
|
|
7
|
+
origin: string;
|
|
8
|
+
methods: string[];
|
|
9
|
+
allowedHeaders: string[];
|
|
10
|
+
exposedHeaders: string[];
|
|
11
|
+
credentials: boolean;
|
|
12
|
+
};
|
|
13
|
+
export type WebhookResponseOptions = {
|
|
14
|
+
/**
|
|
15
|
+
* Mode determines how the response is sent to the client. The response can be customized by
|
|
16
|
+
* the `onSuccess` and `onError` functions, which have sensible defaults for each mode.
|
|
17
|
+
*
|
|
18
|
+
* - `sync`: The response is sent at the end of the workflow.
|
|
19
|
+
* - `async`: The response is sent immediately after the trigger is activated.
|
|
20
|
+
*
|
|
21
|
+
* @default 'sync'
|
|
22
|
+
*/
|
|
23
|
+
mode?: 'sync' | 'async';
|
|
24
|
+
/**
|
|
25
|
+
* Function that returns a response for a successful trigger activation.
|
|
26
|
+
*
|
|
27
|
+
* Defaults to a 202 Accepted response for 'async' mode, and a 200 OK response for 'sync' mode.
|
|
28
|
+
*
|
|
29
|
+
* @param ctx The current context of the workflow, containing data from the final step.
|
|
30
|
+
* @returns A response to send to the client.
|
|
31
|
+
*/
|
|
32
|
+
onSuccess?: <T>(ctx: Context<T>) => Response;
|
|
33
|
+
/**
|
|
34
|
+
* Function that returns a response for a failed trigger activation.
|
|
35
|
+
*
|
|
36
|
+
* Defaults to a 500 Internal Server Error response for both modes.
|
|
37
|
+
*
|
|
38
|
+
* @param ctx The current context of the workflow, containing data from the final step.
|
|
39
|
+
* @returns A response to send to the client.
|
|
40
|
+
*/
|
|
41
|
+
onError?: <T>(ctx: Context<T>) => Response;
|
|
42
|
+
};
|
|
43
|
+
export type WebhookOptions = {
|
|
44
|
+
cors?: WebhookCorsOptions;
|
|
45
|
+
response?: WebhookResponseOptions;
|
|
46
|
+
};
|
|
5
47
|
export declare class WebhookTrigger implements Trigger<WebhookData> {
|
|
6
48
|
id: string;
|
|
49
|
+
options: WebhookOptions;
|
|
7
50
|
[TriggerType]: string;
|
|
8
|
-
constructor(id: string);
|
|
51
|
+
constructor(id: string, options?: WebhookOptions);
|
|
9
52
|
then<OO>(task: Taskable<WebhookData, OO>): Workflow<OO>;
|
|
10
|
-
catch<OO>(error: any): Workflow<OO>;
|
|
11
53
|
}
|
|
12
|
-
export declare function webhook(id: string):
|
|
54
|
+
export declare function webhook(id: string, options?: WebhookOptions): Trigger<WebhookData>;
|
|
13
55
|
//# sourceMappingURL=WebhookTrigger.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"WebhookTrigger.d.ts","sourceRoot":"","sources":["../../../../src/src/dsl/triggers/WebhookTrigger.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"WebhookTrigger.d.ts","sourceRoot":"","sources":["../../../../src/src/dsl/triggers/WebhookTrigger.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,0BAA0B,CAAC;AAEnD,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AACtC,OAAO,EAAE,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AACrD,OAAO,EAAE,QAAQ,EAAgB,MAAM,gBAAgB,CAAC;AAExD,MAAM,MAAM,WAAW,GAAG,MAAM,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC;AAEhD,MAAM,MAAM,kBAAkB,GAAG,OAAO,GAAG;IACvC,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,EAAE,MAAM,EAAE,CAAC;IAClB,cAAc,EAAE,MAAM,EAAE,CAAC;IACzB,cAAc,EAAE,MAAM,EAAE,CAAC;IACzB,WAAW,EAAE,OAAO,CAAC;CACxB,CAAA;AAED,MAAM,MAAM,sBAAsB,GAAG;IACjC;;;;;;;;OAQG;IACH,IAAI,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC;IAExB;;;;;;;OAOG;IACH,SAAS,CAAC,EAAE,CAAC,CAAC,EAAE,GAAG,EAAE,OAAO,CAAC,CAAC,CAAC,KAAK,QAAQ,CAAC;IAE7C;;;;;;;OAOG;IACH,OAAO,CAAC,EAAE,CAAC,CAAC,EAAE,GAAG,EAAE,OAAO,CAAC,CAAC,CAAC,KAAK,QAAQ,CAAC;CAC9C,CAAA;AAED,MAAM,MAAM,cAAc,GAAG;IACzB,IAAI,CAAC,EAAE,kBAAkB,CAAC;IAC1B,QAAQ,CAAC,EAAE,sBAAsB,CAAC;CACrC,CAAA;AAED,qBAAa,cAAe,YAAW,OAAO,CAAC,WAAW,CAAC;IACvD,EAAE,EAAE,MAAM,CAAC;IACX,OAAO,EAAE,cAAc,CAAC;IAExB,CAAC,WAAW,CAAC,EAAE,MAAM,CAAa;gBAEtB,EAAE,EAAE,MAAM,EAAE,OAAO,GAAE,cAAmB;IAKpD,IAAI,CAAC,EAAE,EAAE,IAAI,EAAE,QAAQ,CAAC,WAAW,EAAE,EAAE,CAAC,GAAG,QAAQ,CAAC,EAAE,CAAC;CAG1D;AAED,wBAAgB,OAAO,CAAC,EAAE,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,cAAc,GAAG,OAAO,CAAC,WAAW,CAAC,CAElF"}
|
|
@@ -3,13 +3,19 @@ import { ensureTask } from "../ensureTask.js";
|
|
|
3
3
|
import { TriggerType } from '../Trigger.js';
|
|
4
4
|
import { WorkflowImpl } from '../Workflow.js';
|
|
5
5
|
export class WebhookTrigger {
|
|
6
|
-
constructor(id) {
|
|
6
|
+
constructor(id, options = {}) {
|
|
7
7
|
Object.defineProperty(this, "id", {
|
|
8
8
|
enumerable: true,
|
|
9
9
|
configurable: true,
|
|
10
10
|
writable: true,
|
|
11
11
|
value: void 0
|
|
12
12
|
});
|
|
13
|
+
Object.defineProperty(this, "options", {
|
|
14
|
+
enumerable: true,
|
|
15
|
+
configurable: true,
|
|
16
|
+
writable: true,
|
|
17
|
+
value: void 0
|
|
18
|
+
});
|
|
13
19
|
Object.defineProperty(this, _a, {
|
|
14
20
|
enumerable: true,
|
|
15
21
|
configurable: true,
|
|
@@ -17,15 +23,13 @@ export class WebhookTrigger {
|
|
|
17
23
|
value: 'webhook'
|
|
18
24
|
});
|
|
19
25
|
this.id = id;
|
|
26
|
+
this.options = options;
|
|
20
27
|
}
|
|
21
28
|
then(task) {
|
|
22
29
|
return new WorkflowImpl(this, ensureTask(task));
|
|
23
30
|
}
|
|
24
|
-
catch(error) {
|
|
25
|
-
return this;
|
|
26
|
-
}
|
|
27
31
|
}
|
|
28
32
|
_a = TriggerType;
|
|
29
|
-
export function webhook(id) {
|
|
30
|
-
return new WebhookTrigger(id);
|
|
33
|
+
export function webhook(id, options) {
|
|
34
|
+
return new WebhookTrigger(id, options);
|
|
31
35
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Router } from 'express';
|
|
2
|
-
import { Observable } from 'rxjs';
|
|
2
|
+
import { Observable, Subscription } from 'rxjs';
|
|
3
3
|
import { ContextProvider } from '../../context/ContextProvider.js';
|
|
4
4
|
import { ConnectionProvider, RoundTripperFactory } from '../../dsl/http/types.js';
|
|
5
5
|
import { Workflow } from '../../dsl/Workflow.js';
|
|
@@ -18,6 +18,7 @@ type Registration = {
|
|
|
18
18
|
task$: ContextOperatorFunction<any, any, any>;
|
|
19
19
|
localAbortController: AbortController;
|
|
20
20
|
sigintListener: () => void;
|
|
21
|
+
subscription?: Subscription;
|
|
21
22
|
};
|
|
22
23
|
export declare class MemoryInterpreter {
|
|
23
24
|
private readonly log;
|
|
@@ -27,10 +28,14 @@ export declare class MemoryInterpreter {
|
|
|
27
28
|
private readonly router;
|
|
28
29
|
private readonly connectionProvider;
|
|
29
30
|
private registeredWorkflows;
|
|
31
|
+
private server?;
|
|
32
|
+
private shutdownServer?;
|
|
33
|
+
private isShuttingDown;
|
|
30
34
|
constructor(log: Logger, compiler: ObservableCompiler, contextProvider: ContextProvider, roundTripperFactory: RoundTripperFactory, router: Router, connectionProvider: ConnectionProvider);
|
|
31
35
|
static newInstance(options?: MemoryInterpreterOptions): Promise<MemoryInterpreter>;
|
|
32
36
|
register<O>(workflow: Workflow<O>, options?: MemoryInterpreterOptions): Registration;
|
|
33
37
|
start(): Promise<void>;
|
|
38
|
+
stop(): Promise<void>;
|
|
34
39
|
}
|
|
35
40
|
export {};
|
|
36
41
|
//# sourceMappingURL=MemoryInterpreter.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MemoryInterpreter.d.ts","sourceRoot":"","sources":["../../../../src/src/interpreter/memory/MemoryInterpreter.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"MemoryInterpreter.d.ts","sourceRoot":"","sources":["../../../../src/src/interpreter/memory/MemoryInterpreter.ts"],"names":[],"mappings":"AAAA,OAAgB,EAAqB,MAAM,EAAE,MAAM,SAAS,CAAC;AAC7D,OAAO,EAA+B,UAAU,EAAW,YAAY,EAAE,MAAM,MAAM,CAAC;AACtF,OAAO,EAAE,eAAe,EAAuB,MAAM,kCAAkC,CAAC;AAExF,OAAO,EAAE,kBAAkB,EAAE,mBAAmB,EAAE,MAAM,yBAAyB,CAAC;AAGlF,OAAO,EAAE,QAAQ,EAAgB,MAAM,uBAAuB,CAAC;AAI/D,OAAO,EAAE,MAAM,EAAE,MAAM,uCAAuC,CAAC;AAC/D,OAAO,EAAmB,kBAAkB,EAAE,MAAM,yBAAyB,CAAC;AAC9E,OAAO,EAAE,WAAW,EAAE,uBAAuB,EAAE,MAAM,cAAc,CAAC;AAIpE,MAAM,MAAM,wBAAwB,GAAG;IACnC,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,QAAQ,C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AAI,OAAO,CAAC,IAAI,CAAC;CAK9B"}
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import * as dntShim from "../../../_dnt.shims.js";
|
|
2
1
|
import express from 'express';
|
|
3
2
|
import { catchError, EMPTY, mergeMap, of, tap } from 'rxjs';
|
|
4
3
|
import { ContextProviderImpl } from '../../context/ContextProvider.js';
|
|
@@ -54,6 +53,29 @@ export class MemoryInterpreter {
|
|
|
54
53
|
writable: true,
|
|
55
54
|
value: []
|
|
56
55
|
});
|
|
56
|
+
Object.defineProperty(this, "server", {
|
|
57
|
+
enumerable: true,
|
|
58
|
+
configurable: true,
|
|
59
|
+
writable: true,
|
|
60
|
+
value: void 0
|
|
61
|
+
});
|
|
62
|
+
Object.defineProperty(this, "shutdownServer", {
|
|
63
|
+
enumerable: true,
|
|
64
|
+
configurable: true,
|
|
65
|
+
writable: true,
|
|
66
|
+
value: void 0
|
|
67
|
+
});
|
|
68
|
+
Object.defineProperty(this, "isShuttingDown", {
|
|
69
|
+
enumerable: true,
|
|
70
|
+
configurable: true,
|
|
71
|
+
writable: true,
|
|
72
|
+
value: false
|
|
73
|
+
});
|
|
74
|
+
if (typeof this.log === 'undefined') {
|
|
75
|
+
// this captures the old way of instantiating the MemoryInterpreter and provides an
|
|
76
|
+
// error message back to the user to let them know they should use the new way.
|
|
77
|
+
throw new Error('MemoryInterpreter should not be instantiated directly. Use MemoryInterpreter.newInstance() instead.');
|
|
78
|
+
}
|
|
57
79
|
}
|
|
58
80
|
static async newInstance(options = {}) {
|
|
59
81
|
const log = options.logger || new ConsoleLogger('debug');
|
|
@@ -103,7 +125,7 @@ export class MemoryInterpreter {
|
|
|
103
125
|
return registration;
|
|
104
126
|
}
|
|
105
127
|
async start() {
|
|
106
|
-
const port =
|
|
128
|
+
const port = Deno.env.get('PORT') || 3000;
|
|
107
129
|
const app = express();
|
|
108
130
|
app.use(express.json()); // Add JSON body parser middleware
|
|
109
131
|
// Add health check route
|
|
@@ -114,12 +136,13 @@ export class MemoryInterpreter {
|
|
|
114
136
|
app.use(this.router);
|
|
115
137
|
// Start all registered workflows
|
|
116
138
|
for (const registration of this.registeredWorkflows) {
|
|
117
|
-
|
|
118
|
-
registration.trigger$
|
|
139
|
+
Deno.addSignalListener('SIGINT', registration.sigintListener);
|
|
140
|
+
registration.subscription = registration.trigger$
|
|
119
141
|
.pipe(tap((ctx) => {
|
|
120
142
|
ctx.log.info('MemoryInterpreter.executionStarted', { data: ctx.data });
|
|
121
|
-
}), mergeMap((ctx) => of(ctx).pipe(registration.task$, catchError((
|
|
122
|
-
ctx.log.error('MemoryInterpreter.executionError', { error });
|
|
143
|
+
}), mergeMap((ctx) => of(ctx).pipe(registration.task$, catchError((err) => {
|
|
144
|
+
ctx.log.error('MemoryInterpreter.executionError', { error: err instanceof Error ? err.toString() : err });
|
|
145
|
+
ctx.options.onError?.(ctx.withData(err));
|
|
123
146
|
return EMPTY;
|
|
124
147
|
}))))
|
|
125
148
|
.subscribe({
|
|
@@ -129,20 +152,66 @@ export class MemoryInterpreter {
|
|
|
129
152
|
durationMs,
|
|
130
153
|
data: ctx.data,
|
|
131
154
|
});
|
|
155
|
+
ctx.options.onSuccess?.(ctx);
|
|
132
156
|
this.contextProvider.destroy(ctx);
|
|
133
157
|
},
|
|
134
158
|
error: (err) => {
|
|
135
|
-
this.log.error('MemoryInterpreter.error', { error: err });
|
|
136
|
-
|
|
159
|
+
this.log.error('MemoryInterpreter.error', { error: err instanceof Error ? err.toString() : err });
|
|
160
|
+
Deno.removeSignalListener('SIGINT', registration.sigintListener);
|
|
137
161
|
},
|
|
138
162
|
complete: () => {
|
|
139
163
|
this.log.info('MemoryInterpreter.workflowCompleted');
|
|
140
|
-
|
|
164
|
+
Deno.removeSignalListener('SIGINT', registration.sigintListener);
|
|
141
165
|
},
|
|
142
166
|
});
|
|
167
|
+
registration.subscription.add(() => {
|
|
168
|
+
registration.subscription = undefined;
|
|
169
|
+
});
|
|
143
170
|
}
|
|
144
|
-
app.listen(port, () => {
|
|
171
|
+
this.server = app.listen(port, () => {
|
|
145
172
|
this.log.info(`Express server listening on http://localhost:${port}`);
|
|
146
173
|
});
|
|
174
|
+
this.shutdownServer = () => {
|
|
175
|
+
if (this.isShuttingDown) {
|
|
176
|
+
return;
|
|
177
|
+
}
|
|
178
|
+
this.isShuttingDown = true;
|
|
179
|
+
this.log.info('Shutting down server');
|
|
180
|
+
// Close the server
|
|
181
|
+
if (this.server) {
|
|
182
|
+
this.server.close();
|
|
183
|
+
}
|
|
184
|
+
// Remove all signal listeners
|
|
185
|
+
for (const registration of this.registeredWorkflows) {
|
|
186
|
+
Deno.removeSignalListener('SIGINT', registration.sigintListener);
|
|
187
|
+
// Unsubscribe from all observables
|
|
188
|
+
if (registration.subscription) {
|
|
189
|
+
registration.subscription.unsubscribe();
|
|
190
|
+
}
|
|
191
|
+
// Abort all controllers
|
|
192
|
+
registration.localAbortController.abort();
|
|
193
|
+
}
|
|
194
|
+
// Remove the server shutdown listener
|
|
195
|
+
if (this.shutdownServer) {
|
|
196
|
+
Deno.removeSignalListener('SIGINT', this.shutdownServer);
|
|
197
|
+
}
|
|
198
|
+
};
|
|
199
|
+
Deno.addSignalListener('SIGINT', this.shutdownServer);
|
|
200
|
+
return new Promise((resolve) => {
|
|
201
|
+
if (this.server) {
|
|
202
|
+
this.server.on('close', () => {
|
|
203
|
+
this.log.info('Server closed');
|
|
204
|
+
resolve();
|
|
205
|
+
});
|
|
206
|
+
}
|
|
207
|
+
else {
|
|
208
|
+
resolve();
|
|
209
|
+
}
|
|
210
|
+
});
|
|
211
|
+
}
|
|
212
|
+
async stop() {
|
|
213
|
+
if (this.shutdownServer) {
|
|
214
|
+
this.shutdownServer();
|
|
215
|
+
}
|
|
147
216
|
}
|
|
148
217
|
}
|
|
@@ -30,7 +30,7 @@ function compileSchedule(ctx, trigger, signal) {
|
|
|
30
30
|
return;
|
|
31
31
|
}
|
|
32
32
|
activations.forEach((activation) => {
|
|
33
|
-
const executionCtx = ctx.contextProvider.create({}, activation);
|
|
33
|
+
const executionCtx = ctx.contextProvider.create({}, { activation });
|
|
34
34
|
executionCtx.log.info('no activations found, continuing');
|
|
35
35
|
try {
|
|
36
36
|
subscriber.next(executionCtx);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"webhook.d.ts","sourceRoot":"","sources":["../../../../../src/src/interpreter/memory/compilers/webhook.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"webhook.d.ts","sourceRoot":"","sources":["../../../../../src/src/interpreter/memory/compilers/webhook.ts"],"names":[],"mappings":"AAOA,OAAO,EAAE,WAAW,EAAE,cAAc,EAAE,MAAM,yCAAyC,CAAC;AAEtF,OAAO,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAgD7C,eAAO,MAAM,eAAe,EAAE,eAAe,CAAC,WAAW,EAAE,cAAc,CA+LxE,CAAC"}
|
|
@@ -1,71 +1,169 @@
|
|
|
1
1
|
// In src/interpreter/memory/compilers/webhook.ts
|
|
2
|
+
import cors from 'cors';
|
|
2
3
|
import { Observable } from 'rxjs';
|
|
4
|
+
import { pipeline } from 'node:stream/promises';
|
|
3
5
|
import { WebhookTrigger } from '../../../dsl/triggers/WebhookTrigger.js';
|
|
6
|
+
const DEFAULT_SYNC_ON_SUCCESS = (ctx) => new Response(JSON.stringify(ctx.data), {
|
|
7
|
+
status: 200,
|
|
8
|
+
headers: {
|
|
9
|
+
'Content-Type': 'application/json',
|
|
10
|
+
'X-Execution-Id': ctx.executionId,
|
|
11
|
+
},
|
|
12
|
+
});
|
|
13
|
+
const DEFAULT_SYNC_ON_ERROR = (ctx) => new Response(JSON.stringify({ message: 'Internal server error', error: ctx.data }), {
|
|
14
|
+
status: 500,
|
|
15
|
+
headers: {
|
|
16
|
+
'Content-Type': 'application/json',
|
|
17
|
+
'X-Execution-Id': ctx.executionId,
|
|
18
|
+
},
|
|
19
|
+
});
|
|
20
|
+
const DEFAULT_ASYNC_ON_SUCCESS = (ctx) => new Response(JSON.stringify({
|
|
21
|
+
status: 'accepted',
|
|
22
|
+
executionId: ctx.executionId,
|
|
23
|
+
}), {
|
|
24
|
+
status: 202,
|
|
25
|
+
headers: {
|
|
26
|
+
'Content-Type': 'application/json',
|
|
27
|
+
'X-Execution-Id': ctx.executionId,
|
|
28
|
+
},
|
|
29
|
+
});
|
|
30
|
+
const DEFAULT_ASYNC_ON_ERROR = (ctx) => new Response(JSON.stringify({
|
|
31
|
+
message: 'Internal server error',
|
|
32
|
+
executionId: ctx.executionId,
|
|
33
|
+
}), {
|
|
34
|
+
status: 500,
|
|
35
|
+
headers: {
|
|
36
|
+
'Content-Type': 'application/json',
|
|
37
|
+
'X-Execution-Id': ctx.executionId,
|
|
38
|
+
},
|
|
39
|
+
});
|
|
4
40
|
export const webhookCompiler = {
|
|
5
41
|
ctor: WebhookTrigger,
|
|
6
42
|
compile: (ctx, trigger, signal) => {
|
|
43
|
+
const { response: { mode = 'async', } = {}, cors: corsOptions, } = trigger.options;
|
|
44
|
+
const isSync = mode === 'sync';
|
|
45
|
+
const isAsync = mode === 'async';
|
|
46
|
+
if (!isSync && !isAsync) {
|
|
47
|
+
throw new Error('Invalid response mode, must be either "sync" or "async"');
|
|
48
|
+
}
|
|
49
|
+
let onSuccess = isSync ? DEFAULT_SYNC_ON_SUCCESS : DEFAULT_ASYNC_ON_SUCCESS;
|
|
50
|
+
let onError = isSync ? DEFAULT_SYNC_ON_ERROR : DEFAULT_ASYNC_ON_ERROR;
|
|
51
|
+
if (trigger.options.response?.onSuccess) {
|
|
52
|
+
onSuccess = trigger.options.response.onSuccess;
|
|
53
|
+
}
|
|
54
|
+
if (trigger.options.response?.onError) {
|
|
55
|
+
onError = trigger.options.response.onError;
|
|
56
|
+
}
|
|
57
|
+
const ctxOptionsFn = (res) => ({
|
|
58
|
+
onSuccess: (ctx) => {
|
|
59
|
+
if (isSync) {
|
|
60
|
+
sendResponse(res, onSuccess(ctx));
|
|
61
|
+
}
|
|
62
|
+
},
|
|
63
|
+
onError: (ctx) => {
|
|
64
|
+
if (isSync) {
|
|
65
|
+
sendResponse(res, onError(ctx));
|
|
66
|
+
}
|
|
67
|
+
},
|
|
68
|
+
});
|
|
7
69
|
return new Observable((subscriber) => {
|
|
8
70
|
if (!ctx.router) {
|
|
9
71
|
throw new Error('Router not available in compiler context');
|
|
10
72
|
}
|
|
11
73
|
// add the webhook endpoint to the router
|
|
12
74
|
ctx.log.info('webhook endpoint added:', { trigger });
|
|
75
|
+
if (corsOptions) {
|
|
76
|
+
if (typeof corsOptions === 'boolean') {
|
|
77
|
+
ctx.router.use(cors());
|
|
78
|
+
}
|
|
79
|
+
else {
|
|
80
|
+
ctx.router.use(cors(corsOptions));
|
|
81
|
+
}
|
|
82
|
+
}
|
|
13
83
|
// endpoint for sans user because I'm not quite sure how the dynamic routing works
|
|
14
84
|
ctx.router.post(`/${trigger.id}`, (req, res) => {
|
|
15
|
-
const executionCtx = ctx.contextProvider.create(req.body,
|
|
85
|
+
const executionCtx = ctx.contextProvider.create(req.body, ctxOptionsFn(res));
|
|
16
86
|
try {
|
|
17
87
|
subscriber.next(executionCtx);
|
|
18
|
-
|
|
88
|
+
if (isAsync) {
|
|
89
|
+
sendResponse(res, onSuccess(executionCtx));
|
|
90
|
+
}
|
|
19
91
|
}
|
|
20
92
|
catch (error) {
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
93
|
+
executionCtx.log.error('webhook execution error', {
|
|
94
|
+
error: JSON.stringify(error),
|
|
95
|
+
});
|
|
96
|
+
if (isAsync) {
|
|
97
|
+
sendResponse(res, onError(executionCtx.withData(error)));
|
|
98
|
+
}
|
|
24
99
|
}
|
|
25
100
|
});
|
|
26
101
|
// this endpoint will trigger the workflow for each activation given by the external user ID
|
|
27
102
|
ctx.router.post(`/${trigger.id}/users/:userId`, async (req, res) => {
|
|
28
|
-
const userId = req.params.userId
|
|
29
|
-
if (!userId) {
|
|
30
|
-
res.status(400).json({ status: 'error', message: 'User ID is required' });
|
|
31
|
-
return;
|
|
32
|
-
}
|
|
103
|
+
const userId = req.params.userId;
|
|
33
104
|
const activations = await ctx.connectionProvider.getUserActivations(userId);
|
|
34
105
|
if (!activations || activations.length === 0) {
|
|
35
|
-
res.status(404).json({
|
|
106
|
+
res.status(404).json({
|
|
107
|
+
status: 'error',
|
|
108
|
+
message: `No activations found for user: ${userId}`,
|
|
109
|
+
});
|
|
36
110
|
return;
|
|
37
111
|
}
|
|
112
|
+
const executionCtx = ctx.contextProvider.create(req.body, ctxOptionsFn(res));
|
|
113
|
+
const errors = [];
|
|
38
114
|
activations.forEach((activation) => {
|
|
39
|
-
const
|
|
115
|
+
const activationCtx = executionCtx.withActivation(activation);
|
|
40
116
|
try {
|
|
41
|
-
subscriber.next(
|
|
117
|
+
subscriber.next(activationCtx);
|
|
42
118
|
}
|
|
43
119
|
catch (error) {
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
120
|
+
activationCtx.log.error('webhook execution error', {
|
|
121
|
+
error: JSON.stringify(error),
|
|
122
|
+
});
|
|
123
|
+
errors.push({
|
|
124
|
+
activationId: activation.id,
|
|
125
|
+
error,
|
|
126
|
+
});
|
|
47
127
|
}
|
|
48
128
|
});
|
|
49
|
-
|
|
129
|
+
if (isAsync) {
|
|
130
|
+
if (errors.length === 0) {
|
|
131
|
+
sendResponse(res, onSuccess(executionCtx));
|
|
132
|
+
}
|
|
133
|
+
else {
|
|
134
|
+
sendResponse(res, onError(executionCtx.withData(errors)));
|
|
135
|
+
}
|
|
136
|
+
}
|
|
50
137
|
});
|
|
51
138
|
// this endpoint will trigger the workflow only for the activation given by its ID
|
|
52
139
|
ctx.router.post(`/${trigger.id}/activations/:activationId`, async (req, res) => {
|
|
53
|
-
const activationId = req.params.activationId
|
|
140
|
+
const activationId = req.params.activationId;
|
|
54
141
|
const activation = await ctx.connectionProvider.getActivation(activationId);
|
|
55
142
|
if (!activation) {
|
|
56
143
|
// TODO report back actual errors
|
|
57
|
-
res.status(404).json({
|
|
144
|
+
res.status(404).json({
|
|
145
|
+
status: 'error',
|
|
146
|
+
message: `No activation found for ID: ${activationId}`,
|
|
147
|
+
});
|
|
58
148
|
return;
|
|
59
149
|
}
|
|
60
|
-
const
|
|
150
|
+
const activationCtx = ctx.contextProvider.create(req.body, {
|
|
151
|
+
...ctxOptionsFn(res),
|
|
152
|
+
activation,
|
|
153
|
+
});
|
|
61
154
|
try {
|
|
62
|
-
subscriber.next(
|
|
63
|
-
|
|
155
|
+
subscriber.next(activationCtx);
|
|
156
|
+
if (isAsync) {
|
|
157
|
+
sendResponse(res, onSuccess(activationCtx));
|
|
158
|
+
}
|
|
64
159
|
}
|
|
65
160
|
catch (error) {
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
161
|
+
activationCtx.log.error('webhook execution error', {
|
|
162
|
+
error: JSON.stringify(error),
|
|
163
|
+
});
|
|
164
|
+
if (isAsync) {
|
|
165
|
+
sendResponse(res, onError(activationCtx.withData(error)));
|
|
166
|
+
}
|
|
69
167
|
}
|
|
70
168
|
});
|
|
71
169
|
function cleanup() {
|
|
@@ -80,3 +178,12 @@ export const webhookCompiler = {
|
|
|
80
178
|
});
|
|
81
179
|
},
|
|
82
180
|
};
|
|
181
|
+
function sendResponse(res, response) {
|
|
182
|
+
res.status(response.status);
|
|
183
|
+
response.headers.forEach((value, key) => {
|
|
184
|
+
res.setHeader(key, value);
|
|
185
|
+
});
|
|
186
|
+
if (response.body) {
|
|
187
|
+
pipeline(response.body, res);
|
|
188
|
+
}
|
|
189
|
+
}
|
|
@@ -19,7 +19,6 @@ export declare class NatsKeyValueProvider implements KeyValueProvider, AsyncDisp
|
|
|
19
19
|
private constructor();
|
|
20
20
|
static newInstance(opts?: Partial<NatsKeyValueProviderOptions>): Promise<NatsKeyValueProvider>;
|
|
21
21
|
static fromEnv(): Promise<NatsKeyValueProvider>;
|
|
22
|
-
[Symbol.asyncDispose](): PromiseLike<void>;
|
|
23
22
|
kv(options: KVOptions): KeyValue;
|
|
24
23
|
destroy(options: DestroyOptions): Promise<void>;
|
|
25
24
|
private subjectPrefix;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"NatsKeyValueProvider.d.ts","sourceRoot":"","sources":["../../../../src/src/kv/nats/NatsKeyValueProvider.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"NatsKeyValueProvider.d.ts","sourceRoot":"","sources":["../../../../src/src/kv/nats/NatsKeyValueProvider.ts"],"names":[],"mappings":"AAEA,OAAO,EAA+B,UAAU,EAAE,MAAM,+DAA+D,CAAC;AACxH,OAAO,EACH,cAAc,EAEd,QAAQ,EACR,gBAAgB,EAChB,SAAS,EACZ,MAAM,gBAAgB,CAAC;AA4CxB,MAAM,MAAM,2BAA2B,GAAG;IACtC,cAAc,EAAE,MAAM,CAAC;IACvB,SAAS,EAAE,MAAM,CAAC;IAClB,WAAW,EAAE,MAAM,CAAC;IACpB,IAAI,EAAE;QACF,GAAG,EAAE,MAAM,CAAC;QACZ,SAAS,CAAC,EAAE,MAAM,CAAC;QACnB,GAAG,CAAC,EAAE,UAAU,CAAC;KACpB,CAAC;CACL,CAAC;AAuBF,qBAAa,oBAAqB,YAAW,gBAAgB,EAAE,eAAe;IAEtE,OAAO,CAAC,QAAQ,CAAC,GAAG;IACpB,OAAO,CAAC,QAAQ,CAAC,UAAU;IAC3B,OAAO,CAAC,QAAQ,CAAC,cAAc;IAC/B,OAAO,CAAC,QAAQ,CAAC,gBAAgB;IACjC,OAAO,CAAC,QAAQ,CAAC,IAAI;IALzB,OAAO;WAQM,WAAW,CACpB,IAAI,GAAE,OAAO,CAAC,2BAA2B,CAAM,GAChD,OAAO,CAAC,oBAAoB,CAAC;IA0BhC,MAAM,CAAC,OAAO,IAAI,OAAO,CAAC,oBAAoB,CAAC;IAQ/C,EAAE,CAAC,OAAO,EAAE,SAAS,GAAG,QAAQ;IAqB1B,OAAO,CAAC,OAAO,EAAE,cAAc,GAAG,OAAO,CAAC,IAAI,CAAC;IAuBrD,OAAO,CAAC,aAAa;CAYxB"}
|
|
@@ -1,18 +1,17 @@
|
|
|
1
|
-
import * as dntShim from "../../../_dnt.shims.js";
|
|
2
1
|
import { JetStreamApiCodes, JetStreamApiError } from '../../../deps/jsr.io/@nats-io/jetstream/3.0.2/src/mod.js';
|
|
3
2
|
import { Kvm } from '../../../deps/jsr.io/@nats-io/kv/3.0.2/src/mod.js';
|
|
4
3
|
import { connect, credsAuthenticator } from '../../../deps/jsr.io/@nats-io/transport-deno/3.0.2/src/mod.js';
|
|
5
4
|
import { isKVOptionsExecution, } from '../KeyValue.js';
|
|
6
5
|
import { NatsKeyValue } from './NatsKeyValue.js';
|
|
7
6
|
function getOptionsFromEnv() {
|
|
8
|
-
const natsTlsCaFile =
|
|
7
|
+
const natsTlsCaFile = Deno.env.get('RUN_NATS_TLS_CA_FILE');
|
|
9
8
|
return {
|
|
10
|
-
organizationId:
|
|
11
|
-
projectId:
|
|
12
|
-
environment:
|
|
9
|
+
organizationId: Deno.env.get('RUN_ORGANISATION_ID'),
|
|
10
|
+
projectId: Deno.env.get('RUN_SERVICE_ID'),
|
|
11
|
+
environment: Deno.env.get('RUN_ENVIRONMENT'),
|
|
13
12
|
nats: {
|
|
14
|
-
url:
|
|
15
|
-
credsFile:
|
|
13
|
+
url: Deno.env.get('RUN_NATS_URL') || 'nats://localhost:4222',
|
|
14
|
+
credsFile: Deno.env.get('RUN_NATS_CREDS_FILE'),
|
|
16
15
|
...(natsTlsCaFile && {
|
|
17
16
|
tls: {
|
|
18
17
|
caFile: natsTlsCaFile,
|
|
@@ -85,7 +84,7 @@ export class NatsKeyValueProvider {
|
|
|
85
84
|
static async newInstance(opts = {}) {
|
|
86
85
|
const parsedOpts = mergeOptions(getOptionsFromEnv(), opts);
|
|
87
86
|
const credsFile = parsedOpts.nats.credsFile
|
|
88
|
-
? await
|
|
87
|
+
? await Deno.readFile(parsedOpts.nats.credsFile)
|
|
89
88
|
: undefined;
|
|
90
89
|
const conn = await connect({
|
|
91
90
|
servers: [parsedOpts.nats.url],
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@versori/run",
|
|
3
|
-
"version": "v0.
|
|
3
|
+
"version": "v0.2.0-alpha.2",
|
|
4
4
|
"description": "Versori Run",
|
|
5
5
|
"homepage": "https://github.com/versori/versori-run#readme",
|
|
6
6
|
"repository": {
|
|
@@ -26,14 +26,11 @@
|
|
|
26
26
|
"@bufbuild/protobuf": "^2.2.3",
|
|
27
27
|
"@connectrpc/connect": "^2.0.1",
|
|
28
28
|
"@connectrpc/connect-node": "^2.0.1",
|
|
29
|
+
"cors": "^2.8.5",
|
|
29
30
|
"cron": "3.5.0",
|
|
30
31
|
"express": "^4.18.3",
|
|
31
32
|
"rxjs": "^7.8.1",
|
|
32
|
-
"tweetnacl": "1.0.3"
|
|
33
|
-
"@deno/shim-deno": "~0.18.0"
|
|
34
|
-
},
|
|
35
|
-
"devDependencies": {
|
|
36
|
-
"@types/node": "^20.9.0"
|
|
33
|
+
"tweetnacl": "1.0.3"
|
|
37
34
|
},
|
|
38
35
|
"_generatedBy": "dnt@dev"
|
|
39
36
|
}
|