@versori/run 0.1.0-alpha.9 → 0.2.0-alpha.10
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/{script/deps/jsr.io/@std/fmt/1.0.6 → esm/deps/jsr.io/@std/fmt/1.0.7}/colors.d.ts.map +1 -1
- package/{script/deps/jsr.io/@std/fs/1.0.16 → esm/deps/jsr.io/@std/fs/1.0.17}/exists.d.ts +1 -0
- package/esm/deps/jsr.io/@std/fs/1.0.17/exists.d.ts.map +1 -0
- package/esm/deps/jsr.io/@std/fs/{1.0.16 → 1.0.17}/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/console_handler.js +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 +7 -9
- package/esm/src/context/Context.d.ts +16 -4
- package/esm/src/context/Context.d.ts.map +1 -1
- package/esm/src/context/Context.js +31 -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/types.d.ts +13 -2
- package/esm/src/dsl/http/types.d.ts.map +1 -1
- package/esm/src/dsl/http/versori/activation.d.ts +13 -0
- package/esm/src/dsl/http/versori/activation.d.ts.map +1 -0
- package/esm/src/dsl/http/versori/activation.js +65 -0
- 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/constants.d.ts +5 -0
- package/esm/src/dsl/http/versori/constants.d.ts.map +1 -1
- package/esm/src/dsl/http/versori/constants.js +5 -0
- package/esm/src/dsl/http/versori/credentials/client.d.ts +1 -4
- package/esm/src/dsl/http/versori/credentials/client.d.ts.map +1 -1
- package/esm/src/dsl/http/versori/credentials/client.js +3 -16
- package/esm/src/dsl/http/versori/cronapi.d.ts +10 -0
- package/esm/src/dsl/http/versori/cronapi.d.ts.map +1 -0
- package/esm/src/dsl/http/versori/cronapi.js +51 -0
- 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 +4 -1
- package/esm/src/dsl/http/versori/platformapi.d.ts.map +1 -1
- package/esm/src/dsl/http/versori/platformapi.js +41 -10
- package/esm/src/dsl/http/versori/roundtripper.d.ts +3 -2
- package/esm/src/dsl/http/versori/roundtripper.d.ts.map +1 -1
- package/esm/src/dsl/http/versori/roundtripper.js +128 -78
- 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 +10 -3
- package/esm/src/interpreter/memory/MemoryInterpreter.d.ts.map +1 -1
- package/esm/src/interpreter/memory/MemoryInterpreter.js +121 -13
- package/esm/src/interpreter/memory/ObservableCompiler.d.ts +1 -0
- package/esm/src/interpreter/memory/ObservableCompiler.d.ts.map +1 -1
- package/esm/src/interpreter/memory/compilers/schedule.d.ts.map +1 -1
- package/esm/src/interpreter/memory/compilers/schedule.js +19 -24
- 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/esm/src/observability/logging/ConsoleLogger.d.ts.map +1 -1
- package/esm/src/observability/logging/ConsoleLogger.js +55 -10
- 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/{esm/deps/jsr.io/@std/fmt/1.0.6 → script/deps/jsr.io/@std/fmt/1.0.7}/colors.d.ts.map +1 -1
- package/{esm/deps/jsr.io/@std/fs/1.0.16 → script/deps/jsr.io/@std/fs/1.0.17}/exists.d.ts +1 -0
- package/script/deps/jsr.io/@std/fs/1.0.17/exists.d.ts.map +1 -0
- package/script/deps/jsr.io/@std/fs/{1.0.16 → 1.0.17}/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/console_handler.js +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 +7 -32
- package/script/src/context/Context.d.ts +16 -4
- package/script/src/context/Context.d.ts.map +1 -1
- package/script/src/context/Context.js +31 -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/types.d.ts +13 -2
- package/script/src/dsl/http/types.d.ts.map +1 -1
- package/script/src/dsl/http/versori/activation.d.ts +13 -0
- package/script/src/dsl/http/versori/activation.d.ts.map +1 -0
- package/script/src/dsl/http/versori/activation.js +69 -0
- 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/constants.d.ts +5 -0
- package/script/src/dsl/http/versori/constants.d.ts.map +1 -1
- package/script/src/dsl/http/versori/constants.js +6 -1
- package/script/src/dsl/http/versori/credentials/client.d.ts +1 -4
- package/script/src/dsl/http/versori/credentials/client.d.ts.map +1 -1
- package/script/src/dsl/http/versori/credentials/client.js +2 -15
- package/script/src/dsl/http/versori/cronapi.d.ts +10 -0
- package/script/src/dsl/http/versori/cronapi.d.ts.map +1 -0
- package/script/src/dsl/http/versori/cronapi.js +55 -0
- 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 +4 -1
- package/script/src/dsl/http/versori/platformapi.d.ts.map +1 -1
- package/script/src/dsl/http/versori/platformapi.js +41 -33
- package/script/src/dsl/http/versori/roundtripper.d.ts +3 -2
- package/script/src/dsl/http/versori/roundtripper.d.ts.map +1 -1
- package/script/src/dsl/http/versori/roundtripper.js +128 -101
- 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 +10 -3
- package/script/src/interpreter/memory/MemoryInterpreter.d.ts.map +1 -1
- package/script/src/interpreter/memory/MemoryInterpreter.js +121 -36
- package/script/src/interpreter/memory/ObservableCompiler.d.ts +1 -0
- package/script/src/interpreter/memory/ObservableCompiler.d.ts.map +1 -1
- package/script/src/interpreter/memory/compilers/schedule.d.ts.map +1 -1
- package/script/src/interpreter/memory/compilers/schedule.js +19 -24
- 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
- package/script/src/observability/logging/ConsoleLogger.d.ts.map +1 -1
- package/script/src/observability/logging/ConsoleLogger.js +55 -10
- package/esm/deps/jsr.io/@std/fs/1.0.16/exists.d.ts.map +0 -1
- package/script/deps/jsr.io/@std/fs/1.0.16/exists.d.ts.map +0 -1
- /package/esm/deps/jsr.io/@std/fmt/{1.0.6 → 1.0.7}/colors.d.ts +0 -0
- /package/esm/deps/jsr.io/@std/fmt/{1.0.6 → 1.0.7}/colors.js +0 -0
- /package/script/deps/jsr.io/@std/fmt/{1.0.6 → 1.0.7}/colors.d.ts +0 -0
- /package/script/deps/jsr.io/@std/fmt/{1.0.6 → 1.0.7}/colors.js +0 -0
|
@@ -1,34 +1,12 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
-
if (mod && mod.__esModule) return mod;
|
|
20
|
-
var result = {};
|
|
21
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
-
__setModuleDefault(result, mod);
|
|
23
|
-
return result;
|
|
24
|
-
};
|
|
25
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
3
|
exports.PlatformAPIClient = void 0;
|
|
27
|
-
const dntShim = __importStar(require("../../../../_dnt.shims.js"));
|
|
28
4
|
const constants_js_1 = require("./constants.js");
|
|
29
5
|
const internalauth_js_1 = require("./internalauth.js");
|
|
6
|
+
const mod_js_1 = require("../../../mod.js");
|
|
7
|
+
const activation_js_1 = require("./activation.js");
|
|
30
8
|
class PlatformAPIClient {
|
|
31
|
-
constructor(baseUrl, orgId, envId) {
|
|
9
|
+
constructor(baseUrl, orgId, envId, log) {
|
|
32
10
|
Object.defineProperty(this, "baseUrl", {
|
|
33
11
|
enumerable: true,
|
|
34
12
|
configurable: true,
|
|
@@ -53,19 +31,27 @@ class PlatformAPIClient {
|
|
|
53
31
|
writable: true,
|
|
54
32
|
value: void 0
|
|
55
33
|
});
|
|
34
|
+
Object.defineProperty(this, "log", {
|
|
35
|
+
enumerable: true,
|
|
36
|
+
configurable: true,
|
|
37
|
+
writable: true,
|
|
38
|
+
value: void 0
|
|
39
|
+
});
|
|
56
40
|
this.baseUrl = baseUrl;
|
|
57
41
|
this.orgId = orgId;
|
|
58
42
|
this.envId = envId;
|
|
59
43
|
this.internalAuth = new internalauth_js_1.InternalAuth();
|
|
44
|
+
this.log = log;
|
|
60
45
|
}
|
|
61
46
|
static fromEnv() {
|
|
62
|
-
const baseUrl =
|
|
63
|
-
const orgId =
|
|
64
|
-
const envId =
|
|
47
|
+
const baseUrl = Deno.env.get(constants_js_1.envVarPlatformApiBaseURL);
|
|
48
|
+
const orgId = Deno.env.get(constants_js_1.envVarOrgId);
|
|
49
|
+
const envId = Deno.env.get(constants_js_1.envVarEnvId);
|
|
50
|
+
const log = new mod_js_1.ConsoleLogger('debug');
|
|
65
51
|
if (!baseUrl || !orgId || !envId) {
|
|
66
52
|
throw new Error('Missing required environment variables');
|
|
67
53
|
}
|
|
68
|
-
return new PlatformAPIClient(baseUrl, orgId, envId);
|
|
54
|
+
return new PlatformAPIClient(baseUrl, orgId, envId, log);
|
|
69
55
|
}
|
|
70
56
|
async getStaticConnection(cnxId) {
|
|
71
57
|
const resp = await fetch(`${this.baseUrl}/o/${this.orgId}/connections/${cnxId}`, {
|
|
@@ -88,7 +74,10 @@ class PlatformAPIClient {
|
|
|
88
74
|
if (!resp.ok) {
|
|
89
75
|
return [];
|
|
90
76
|
}
|
|
91
|
-
const
|
|
77
|
+
const activations = (await resp.json());
|
|
78
|
+
const result = activations.map((act) => {
|
|
79
|
+
return new activation_js_1.ActivationImpl(act.id, act.user, this, this.log, act.dynamicVariables);
|
|
80
|
+
});
|
|
92
81
|
return result;
|
|
93
82
|
}
|
|
94
83
|
async getActivation(activationId) {
|
|
@@ -100,8 +89,8 @@ class PlatformAPIClient {
|
|
|
100
89
|
if (!resp.ok) {
|
|
101
90
|
return undefined;
|
|
102
91
|
}
|
|
103
|
-
const
|
|
104
|
-
return
|
|
92
|
+
const act = (await resp.json());
|
|
93
|
+
return new activation_js_1.ActivationImpl(act.id, act.user, this, this.log, act.dynamicVariables);
|
|
105
94
|
}
|
|
106
95
|
async getActivationConnection(templateId, activationId) {
|
|
107
96
|
const resp = await fetch(`${this.baseUrl}/o/${this.orgId}/environment-systems/${templateId}/activations/${activationId}`, {
|
|
@@ -124,8 +113,27 @@ class PlatformAPIClient {
|
|
|
124
113
|
if (!resp.ok) {
|
|
125
114
|
return [];
|
|
126
115
|
}
|
|
127
|
-
const
|
|
116
|
+
const activations = (await resp.json());
|
|
117
|
+
const result = activations.map((act) => {
|
|
118
|
+
return new activation_js_1.ActivationImpl(act.id, act.user, this, this.log, act.dynamicVariables);
|
|
119
|
+
});
|
|
128
120
|
return result;
|
|
129
121
|
}
|
|
122
|
+
async updateDynamicVariable(activationId, name, value) {
|
|
123
|
+
this.log.debug(`value is ${JSON.stringify(value)}`);
|
|
124
|
+
const resp = await fetch(`${this.baseUrl}/o/${this.orgId}/environments/${this.envId}/activations/${activationId}/variables/${name}`, {
|
|
125
|
+
method: 'PUT',
|
|
126
|
+
headers: {
|
|
127
|
+
'x-versori-internal-token': await this.internalAuth.getToken(),
|
|
128
|
+
'Content-Type': 'application/json',
|
|
129
|
+
},
|
|
130
|
+
body: JSON.stringify({
|
|
131
|
+
value,
|
|
132
|
+
}),
|
|
133
|
+
});
|
|
134
|
+
if (!resp.ok) {
|
|
135
|
+
throw new Error(`Failed to update dynamic variable ${name}`);
|
|
136
|
+
}
|
|
137
|
+
}
|
|
130
138
|
}
|
|
131
139
|
exports.PlatformAPIClient = PlatformAPIClient;
|
|
@@ -2,7 +2,6 @@ import { DynamicFetcher, RoundTripperFactory } from '../types.js';
|
|
|
2
2
|
import { VersoriCredentialClient } from './credentials/mod.js';
|
|
3
3
|
import { PlatformAPIClient } from './platformapi.js';
|
|
4
4
|
import { Logger } from '../../../observability/logging/Logger.js';
|
|
5
|
-
export type RunningEnvironment = 'local' | 'versori' | 'staging';
|
|
6
5
|
/**
|
|
7
6
|
* VersoriRoundTripper is an implementation of the RoundTripperFactory interface for Versori connections.
|
|
8
7
|
* This is the intended implementation for when projects/services are hosted on Versori infrastructure.
|
|
@@ -17,11 +16,12 @@ export type RunningEnvironment = 'local' | 'versori' | 'staging';
|
|
|
17
16
|
*/
|
|
18
17
|
export declare class VersoriRoundTripperFactory implements RoundTripperFactory {
|
|
19
18
|
private tokenClient;
|
|
19
|
+
private credsBaseURL;
|
|
20
20
|
private platformAPIClient;
|
|
21
21
|
private versoriCfg;
|
|
22
22
|
private log;
|
|
23
23
|
private readonly defaultDynamic;
|
|
24
|
-
constructor(credsClient: VersoriCredentialClient, platformAPIClient: PlatformAPIClient, logger: Logger);
|
|
24
|
+
constructor(credsClient: VersoriCredentialClient, credsBaseURL: string, platformAPIClient: PlatformAPIClient, logger: Logger);
|
|
25
25
|
static fromEnv(logger?: Logger): VersoriRoundTripperFactory;
|
|
26
26
|
private changeRequestInit;
|
|
27
27
|
private changeBaseUrl;
|
|
@@ -33,5 +33,6 @@ export declare class VersoriRoundTripperFactory implements RoundTripperFactory {
|
|
|
33
33
|
private basicAuthFetcher;
|
|
34
34
|
private bearerTokenFetcher;
|
|
35
35
|
private oauth2Fetcher;
|
|
36
|
+
private getToken;
|
|
36
37
|
}
|
|
37
38
|
//# sourceMappingURL=roundtripper.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"roundtripper.d.ts","sourceRoot":"","sources":["../../../../../src/src/dsl/http/versori/roundtripper.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"roundtripper.d.ts","sourceRoot":"","sources":["../../../../../src/src/dsl/http/versori/roundtripper.ts"],"names":[],"mappings":"AAAA,OAAO,EAGH,cAAc,EACd,mBAAmB,EAEtB,MAAM,aAAa,CAAC;AAErB,OAAO,EAAE,uBAAuB,EAAE,MAAM,sBAAsB,CAAC;AAC/D,OAAO,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAC;AACrD,OAAO,EAAE,MAAM,EAAE,MAAM,0CAA0C,CAAC;AAYlE;;;;;;;;;;;GAWG;AACH,qBAAa,0BAA2B,YAAW,mBAAmB;IAClE,OAAO,CAAC,WAAW,CAA0B;IAC7C,OAAO,CAAC,YAAY,CAAS;IAE7B,OAAO,CAAC,iBAAiB,CAAoB;IAE7C,OAAO,CAAC,UAAU,CAAmB;IAErC,OAAO,CAAC,GAAG,CAAS;IAEpB,OAAO,CAAC,QAAQ,CAAC,cAAc,CAK7B;gBAGE,WAAW,EAAE,uBAAuB,EACpC,YAAY,EAAE,MAAM,EACpB,iBAAiB,EAAE,iBAAiB,EACpC,MAAM,EAAE,MAAM;IASlB,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,EAAE,MAAM,GAAG,0BAA0B;IA6B3D,OAAO,CAAC,iBAAiB;IAezB,OAAO,CAAC,aAAa;IAwBrB,MAAM,CACF,QAAQ,EAAE,MAAM,EAChB,EAAE,GAAE,OAAO,KAAwB,GACpC,OAAO,CAAC,OAAO,KAAK,GAAG,SAAS,CAAC;IAqCpC,aAAa,CACT,YAAY,EAAE,MAAM,EACpB,EAAE,GAAE,OAAO,KAAwB,GACpC,OAAO,CAAC,cAAc,GAAG,SAAS,CAAC;IA+CtC,OAAO,CAAC,eAAe;IAcvB,OAAO,CAAC,aAAa;IAYrB,OAAO,CAAC,aAAa;IAyDrB,OAAO,CAAC,gBAAgB;IAqCxB,OAAO,CAAC,kBAAkB;IAmC1B,OAAO,CAAC,aAAa;YAwEP,QAAQ;CAuBzB"}
|
|
@@ -1,35 +1,12 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
-
if (mod && mod.__esModule) return mod;
|
|
20
|
-
var result = {};
|
|
21
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
-
__setModuleDefault(result, mod);
|
|
23
|
-
return result;
|
|
24
|
-
};
|
|
25
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
3
|
exports.VersoriRoundTripperFactory = void 0;
|
|
27
|
-
const dntShim = __importStar(require("../../../../_dnt.shims.js"));
|
|
28
4
|
const configloader_js_1 = require("./configloader.js");
|
|
29
5
|
const mod_js_1 = require("./credentials/mod.js");
|
|
30
6
|
const platformapi_js_1 = require("./platformapi.js");
|
|
31
7
|
const mod_js_2 = require("../../../observability/mod.js");
|
|
32
8
|
const constants_js_1 = require("./constants.js");
|
|
9
|
+
const connect_1 = require("@connectrpc/connect");
|
|
33
10
|
/**
|
|
34
11
|
* VersoriRoundTripper is an implementation of the RoundTripperFactory interface for Versori connections.
|
|
35
12
|
* This is the intended implementation for when projects/services are hosted on Versori infrastructure.
|
|
@@ -43,13 +20,19 @@ const constants_js_1 = require("./constants.js");
|
|
|
43
20
|
* ```
|
|
44
21
|
*/
|
|
45
22
|
class VersoriRoundTripperFactory {
|
|
46
|
-
constructor(credsClient, platformAPIClient, logger) {
|
|
23
|
+
constructor(credsClient, credsBaseURL, platformAPIClient, logger) {
|
|
47
24
|
Object.defineProperty(this, "tokenClient", {
|
|
48
25
|
enumerable: true,
|
|
49
26
|
configurable: true,
|
|
50
27
|
writable: true,
|
|
51
28
|
value: void 0
|
|
52
29
|
});
|
|
30
|
+
Object.defineProperty(this, "credsBaseURL", {
|
|
31
|
+
enumerable: true,
|
|
32
|
+
configurable: true,
|
|
33
|
+
writable: true,
|
|
34
|
+
value: void 0
|
|
35
|
+
});
|
|
53
36
|
Object.defineProperty(this, "platformAPIClient", {
|
|
54
37
|
enumerable: true,
|
|
55
38
|
configurable: true,
|
|
@@ -80,15 +63,16 @@ class VersoriRoundTripperFactory {
|
|
|
80
63
|
}
|
|
81
64
|
});
|
|
82
65
|
this.tokenClient = credsClient;
|
|
66
|
+
this.credsBaseURL = credsBaseURL;
|
|
83
67
|
this.platformAPIClient = platformAPIClient;
|
|
84
68
|
this.versoriCfg = (0, configloader_js_1.LoadConfigFromFile)();
|
|
85
69
|
this.log = logger;
|
|
86
70
|
}
|
|
87
71
|
static fromEnv(logger) {
|
|
88
|
-
const credsBaseURL =
|
|
89
|
-
const platformApiBaseURL =
|
|
90
|
-
const orgId =
|
|
91
|
-
const envId =
|
|
72
|
+
const credsBaseURL = Deno.env.get(constants_js_1.envVarCredsBaseURL);
|
|
73
|
+
const platformApiBaseURL = Deno.env.get(constants_js_1.envVarPlatformApiBaseURL);
|
|
74
|
+
const orgId = Deno.env.get(constants_js_1.envVarOrgId);
|
|
75
|
+
const envId = Deno.env.get(constants_js_1.envVarEnvId);
|
|
92
76
|
if (!orgId || !envId || !platformApiBaseURL || !credsBaseURL) {
|
|
93
77
|
const missingVars = [];
|
|
94
78
|
if (!orgId)
|
|
@@ -101,20 +85,23 @@ class VersoriRoundTripperFactory {
|
|
|
101
85
|
missingVars.push(constants_js_1.envVarCredsBaseURL);
|
|
102
86
|
throw new Error(`Missing environment variables: ${missingVars.join(', ')}`);
|
|
103
87
|
}
|
|
104
|
-
const pAPIClient = new platformapi_js_1.PlatformAPIClient(platformApiBaseURL, orgId, envId, {});
|
|
105
|
-
const tokenClient = new mod_js_1.VersoriCredentialClient(credsBaseURL);
|
|
106
88
|
const log = logger || new mod_js_2.ConsoleLogger('debug');
|
|
107
|
-
|
|
89
|
+
const pAPIClient = new platformapi_js_1.PlatformAPIClient(platformApiBaseURL, orgId, envId, log);
|
|
90
|
+
const tokenClient = new mod_js_1.VersoriCredentialClient(credsBaseURL);
|
|
91
|
+
return new VersoriRoundTripperFactory(tokenClient, credsBaseURL, pAPIClient, log);
|
|
108
92
|
}
|
|
109
93
|
// takes the info and modifies the url using changeBaseUrl if necessary
|
|
94
|
+
// if a full valid URL is passed as a string, it will be returned as is
|
|
95
|
+
// if a valid URL object is passed, it will be returned as is
|
|
110
96
|
changeRequestInit(info, conn) {
|
|
111
97
|
if (typeof info === 'string') {
|
|
112
|
-
|
|
98
|
+
if (isValidURL(info)) {
|
|
99
|
+
return info;
|
|
100
|
+
}
|
|
113
101
|
return this.changeBaseUrl(info, conn);
|
|
114
102
|
}
|
|
115
103
|
else if (info instanceof URL) {
|
|
116
|
-
|
|
117
|
-
return newUrl;
|
|
104
|
+
return info;
|
|
118
105
|
}
|
|
119
106
|
else if (info instanceof Request) {
|
|
120
107
|
const url = this.changeBaseUrl(info.url, conn);
|
|
@@ -126,6 +113,7 @@ class VersoriRoundTripperFactory {
|
|
|
126
113
|
const connBaseURL = conn.baseUrl;
|
|
127
114
|
// if the connection has no baseUrl set, but the pathname is a valid URL, return it as is
|
|
128
115
|
if (!connBaseURL && isValidURL(pathname)) {
|
|
116
|
+
this.log.debug('Using given URL as is', { url: pathname });
|
|
129
117
|
return pathname;
|
|
130
118
|
}
|
|
131
119
|
const connBaseURLObj = new URL(connBaseURL);
|
|
@@ -135,36 +123,45 @@ class VersoriRoundTripperFactory {
|
|
|
135
123
|
_pathname = pathnameObj.pathname;
|
|
136
124
|
}
|
|
137
125
|
const newURL = new URL(_pathname, connBaseURLObj.origin);
|
|
126
|
+
this.log.debug('Using baseURL from connection', { url: newURL.toString() });
|
|
138
127
|
return newURL.toString();
|
|
139
128
|
}
|
|
140
|
-
|
|
141
|
-
async create(connName, fn = globalThis.fetch) {
|
|
129
|
+
create(connName, fn = globalThis.fetch) {
|
|
142
130
|
const cnxId = this.getConnectionID(connName);
|
|
143
|
-
|
|
144
|
-
|
|
131
|
+
if (!cnxId) {
|
|
132
|
+
this.log.debug('Connection not found in config, could be a dynamic connection', {
|
|
133
|
+
connectionName: connName,
|
|
134
|
+
});
|
|
145
135
|
return undefined;
|
|
146
136
|
}
|
|
147
|
-
const _fn = (input, init) => {
|
|
137
|
+
const _fn = async (input, init) => {
|
|
138
|
+
const conn = await this.platformAPIClient.getStaticConnection(cnxId);
|
|
139
|
+
if (!conn) {
|
|
140
|
+
this.log.error('Connection not found for user, using default fetch', {
|
|
141
|
+
connectionName: connName,
|
|
142
|
+
});
|
|
143
|
+
return globalThis.fetch(input, init);
|
|
144
|
+
}
|
|
148
145
|
const _input = this.changeRequestInit(input, conn);
|
|
149
|
-
|
|
146
|
+
switch (conn.credentials[0].authSchemeConfig.type) {
|
|
147
|
+
case 'api-key':
|
|
148
|
+
return (await this.apiKeyFetcher(conn, fn))(_input, init);
|
|
149
|
+
case 'basic-auth':
|
|
150
|
+
return (await this.basicAuthFetcher(conn, fn))(_input, init);
|
|
151
|
+
case 'jwt-bearer':
|
|
152
|
+
return (await this.bearerTokenFetcher(conn, fn))(_input, init);
|
|
153
|
+
case 'oauth2':
|
|
154
|
+
return (await this.oauth2Fetcher(conn, fn))(_input, init);
|
|
155
|
+
default:
|
|
156
|
+
return fn(_input, init);
|
|
157
|
+
}
|
|
150
158
|
};
|
|
151
|
-
|
|
152
|
-
case 'api-key':
|
|
153
|
-
return this.apiKeyFetcher(conn, _fn);
|
|
154
|
-
case 'basic-auth':
|
|
155
|
-
return this.basicAuthFetcher(conn, _fn);
|
|
156
|
-
case 'jwt-bearer':
|
|
157
|
-
return this.bearerTokenFetcher(conn, _fn);
|
|
158
|
-
case 'oauth2':
|
|
159
|
-
return this.oauth2Fetcher(conn, _fn);
|
|
160
|
-
default:
|
|
161
|
-
return fn;
|
|
162
|
-
}
|
|
159
|
+
return _fn;
|
|
163
160
|
}
|
|
164
|
-
|
|
161
|
+
createDynamic(templateName, fn = globalThis.fetch) {
|
|
165
162
|
const template = this.getTemplateID(templateName);
|
|
166
163
|
if (!template) {
|
|
167
|
-
this.log.
|
|
164
|
+
this.log.debug('Template not found in config, could be a static connection', {
|
|
168
165
|
templateName: templateName,
|
|
169
166
|
});
|
|
170
167
|
return undefined;
|
|
@@ -195,7 +192,8 @@ class VersoriRoundTripperFactory {
|
|
|
195
192
|
return _fn;
|
|
196
193
|
}
|
|
197
194
|
getConnectionID(connName) {
|
|
198
|
-
const conn = this.versoriCfg.mappings.find((c) => (c.dynamic === undefined || c.dynamic === false) &&
|
|
195
|
+
const conn = this.versoriCfg.mappings.find((c) => (c.dynamic === undefined || c.dynamic === false) &&
|
|
196
|
+
c.name.toLowerCase() === connName.toLowerCase());
|
|
199
197
|
if (!conn || !conn.connId) {
|
|
200
198
|
return '';
|
|
201
199
|
}
|
|
@@ -208,17 +206,17 @@ class VersoriRoundTripperFactory {
|
|
|
208
206
|
}
|
|
209
207
|
return template.templateId;
|
|
210
208
|
}
|
|
211
|
-
|
|
212
|
-
const
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
209
|
+
apiKeyFetcher(conn, fn) {
|
|
210
|
+
const _fn = async (input, init) => {
|
|
211
|
+
const tokenResponse = await this.getToken(conn.credentials[0].credential.id);
|
|
212
|
+
const token = tokenResponse.token?.accessToken;
|
|
213
|
+
const asc = conn.credentials[0].authSchemeConfig.apiKey;
|
|
214
|
+
if (!token) {
|
|
215
|
+
throw new Error('Token not found');
|
|
216
|
+
}
|
|
217
|
+
if (!asc) {
|
|
218
|
+
throw new Error('API Key configuration not found');
|
|
219
|
+
}
|
|
222
220
|
if (!init) {
|
|
223
221
|
init = {};
|
|
224
222
|
}
|
|
@@ -256,13 +254,13 @@ class VersoriRoundTripperFactory {
|
|
|
256
254
|
};
|
|
257
255
|
return _fn;
|
|
258
256
|
}
|
|
259
|
-
|
|
260
|
-
const
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
257
|
+
basicAuthFetcher(conn, fn) {
|
|
258
|
+
const _fn = async (input, init) => {
|
|
259
|
+
const tokenResponse = await this.getToken(conn.credentials[0].credential.id);
|
|
260
|
+
const token = tokenResponse.token?.accessToken;
|
|
261
|
+
if (!token) {
|
|
262
|
+
throw new Error('Token not found');
|
|
263
|
+
}
|
|
266
264
|
if (!init) {
|
|
267
265
|
init = {};
|
|
268
266
|
}
|
|
@@ -286,13 +284,13 @@ class VersoriRoundTripperFactory {
|
|
|
286
284
|
return _fn;
|
|
287
285
|
}
|
|
288
286
|
// TODO: need to make the prefix and header name configurable from authschemeconfig
|
|
289
|
-
|
|
290
|
-
const
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
287
|
+
bearerTokenFetcher(conn, fn) {
|
|
288
|
+
const _fn = async (input, init) => {
|
|
289
|
+
const tokenResponse = await this.getToken(conn.credentials[0].credential.id);
|
|
290
|
+
const token = tokenResponse.token?.accessToken;
|
|
291
|
+
if (!token) {
|
|
292
|
+
throw new Error('Token not found');
|
|
293
|
+
}
|
|
296
294
|
if (!init) {
|
|
297
295
|
init = {};
|
|
298
296
|
}
|
|
@@ -315,27 +313,27 @@ class VersoriRoundTripperFactory {
|
|
|
315
313
|
};
|
|
316
314
|
return _fn;
|
|
317
315
|
}
|
|
318
|
-
|
|
319
|
-
const
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
const _tokenType = () => {
|
|
326
|
-
const _tt = tokenType?.toLowerCase();
|
|
327
|
-
switch (_tt) {
|
|
328
|
-
case 'bearer':
|
|
329
|
-
return 'Bearer';
|
|
330
|
-
case 'mac':
|
|
331
|
-
return 'MAC';
|
|
332
|
-
case 'basic':
|
|
333
|
-
return 'Basic';
|
|
334
|
-
default:
|
|
335
|
-
return 'Bearer';
|
|
316
|
+
oauth2Fetcher(conn, fn) {
|
|
317
|
+
const refreshFn = async (input, init, forceRefresh = false) => {
|
|
318
|
+
const tokenResponse = await this.getToken(conn.credentials[0].credential.id, forceRefresh);
|
|
319
|
+
const token = tokenResponse.token?.accessToken;
|
|
320
|
+
const tokenType = tokenResponse.token?.tokenType;
|
|
321
|
+
if (!token) {
|
|
322
|
+
throw new Error('Token not found');
|
|
336
323
|
}
|
|
337
|
-
|
|
338
|
-
|
|
324
|
+
const _tokenType = () => {
|
|
325
|
+
const _tt = tokenType?.toLowerCase();
|
|
326
|
+
switch (_tt) {
|
|
327
|
+
case 'bearer':
|
|
328
|
+
return 'Bearer';
|
|
329
|
+
case 'mac':
|
|
330
|
+
return 'MAC';
|
|
331
|
+
case 'basic':
|
|
332
|
+
return 'Basic';
|
|
333
|
+
default:
|
|
334
|
+
return 'Bearer';
|
|
335
|
+
}
|
|
336
|
+
};
|
|
339
337
|
if (!init) {
|
|
340
338
|
init = {};
|
|
341
339
|
}
|
|
@@ -356,8 +354,37 @@ class VersoriRoundTripperFactory {
|
|
|
356
354
|
}
|
|
357
355
|
return fn(input, init);
|
|
358
356
|
};
|
|
357
|
+
const _fn = async (input, init) => {
|
|
358
|
+
const resp = await refreshFn(input, init, false);
|
|
359
|
+
if (resp.status === 401) {
|
|
360
|
+
this.log.debug('Received 401 Unauthorized response, attempting refresh', {
|
|
361
|
+
url: input,
|
|
362
|
+
status: resp.status,
|
|
363
|
+
});
|
|
364
|
+
// TODO: attempt refresh until precondition failed??
|
|
365
|
+
return refreshFn(input, init, true);
|
|
366
|
+
}
|
|
367
|
+
return Promise.resolve(resp);
|
|
368
|
+
};
|
|
359
369
|
return _fn;
|
|
360
370
|
}
|
|
371
|
+
async getToken(id) {
|
|
372
|
+
try {
|
|
373
|
+
return await this.tokenClient.getToken(id);
|
|
374
|
+
}
|
|
375
|
+
catch (error) {
|
|
376
|
+
this.log.error('unable to get credential', { error });
|
|
377
|
+
if (error instanceof connect_1.ConnectError) {
|
|
378
|
+
if (error.rawMessage.includes("connection error received: not a result of an error") && error.code === connect_1.Code.Internal) {
|
|
379
|
+
this.log.info('Connection error received, attempting to reconnect');
|
|
380
|
+
this.tokenClient = new mod_js_1.VersoriCredentialClient(this.credsBaseURL);
|
|
381
|
+
return await this.tokenClient.getToken(id);
|
|
382
|
+
}
|
|
383
|
+
throw error;
|
|
384
|
+
}
|
|
385
|
+
throw error;
|
|
386
|
+
}
|
|
387
|
+
}
|
|
361
388
|
}
|
|
362
389
|
exports.VersoriRoundTripperFactory = VersoriRoundTripperFactory;
|
|
363
390
|
function isValidURL(url) {
|
|
@@ -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,EAAs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,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"}
|
|
@@ -66,7 +66,7 @@ class HttpContextImpl extends Context_js_1.ContextImpl {
|
|
|
66
66
|
constructor(ctx, connectionVars, staticFetcher, dynamicFetcher, pageParams) {
|
|
67
67
|
// We need to cast ctx to InternalContext to access kvp
|
|
68
68
|
const internalCtx = ctx;
|
|
69
|
-
super(ctx.log, internalCtx.kvp, ctx.executionId, ctx.startTime, ctx.data, ctx.
|
|
69
|
+
super(ctx.log, internalCtx.kvp, ctx.executionId, ctx.startTime, ctx.data, ctx.options);
|
|
70
70
|
Object.defineProperty(this, "connectionVariables", {
|
|
71
71
|
enumerable: true,
|
|
72
72
|
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"}
|
|
@@ -7,13 +7,19 @@ const ensureTask_js_1 = require("../ensureTask.js");
|
|
|
7
7
|
const Trigger_js_1 = require("../Trigger.js");
|
|
8
8
|
const Workflow_js_1 = require("../Workflow.js");
|
|
9
9
|
class WebhookTrigger {
|
|
10
|
-
constructor(id) {
|
|
10
|
+
constructor(id, options = {}) {
|
|
11
11
|
Object.defineProperty(this, "id", {
|
|
12
12
|
enumerable: true,
|
|
13
13
|
configurable: true,
|
|
14
14
|
writable: true,
|
|
15
15
|
value: void 0
|
|
16
16
|
});
|
|
17
|
+
Object.defineProperty(this, "options", {
|
|
18
|
+
enumerable: true,
|
|
19
|
+
configurable: true,
|
|
20
|
+
writable: true,
|
|
21
|
+
value: void 0
|
|
22
|
+
});
|
|
17
23
|
Object.defineProperty(this, _a, {
|
|
18
24
|
enumerable: true,
|
|
19
25
|
configurable: true,
|
|
@@ -21,16 +27,14 @@ class WebhookTrigger {
|
|
|
21
27
|
value: 'webhook'
|
|
22
28
|
});
|
|
23
29
|
this.id = id;
|
|
30
|
+
this.options = options;
|
|
24
31
|
}
|
|
25
32
|
then(task) {
|
|
26
33
|
return new Workflow_js_1.WorkflowImpl(this, (0, ensureTask_js_1.ensureTask)(task));
|
|
27
34
|
}
|
|
28
|
-
catch(error) {
|
|
29
|
-
return this;
|
|
30
|
-
}
|
|
31
35
|
}
|
|
32
36
|
exports.WebhookTrigger = WebhookTrigger;
|
|
33
37
|
_a = Trigger_js_1.TriggerType;
|
|
34
|
-
function webhook(id) {
|
|
35
|
-
return new WebhookTrigger(id);
|
|
38
|
+
function webhook(id, options) {
|
|
39
|
+
return new WebhookTrigger(id, options);
|
|
36
40
|
}
|