@versori/run 0.0.1-alpha.7 → 0.1.0-alpha.8
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/src/context/Context.d.ts +6 -1
- package/esm/src/context/Context.d.ts.map +1 -1
- package/esm/src/context/Context.js +17 -3
- package/esm/src/context/ContextProvider.d.ts +3 -2
- package/esm/src/context/ContextProvider.d.ts.map +1 -1
- package/esm/src/context/ContextProvider.js +2 -2
- package/esm/src/dsl/http/default.d.ts.map +1 -1
- package/esm/src/dsl/http/default.js +3 -1
- package/esm/src/dsl/http/types.d.ts +122 -16
- package/esm/src/dsl/http/types.d.ts.map +1 -1
- package/esm/src/dsl/http/types.js +6 -2
- package/esm/src/dsl/http/versori/configloader.d.ts +2 -2
- package/esm/src/dsl/http/versori/configloader.d.ts.map +1 -1
- package/esm/src/dsl/http/versori/configloader.js +9 -3
- package/esm/src/dsl/http/versori/constants.d.ts +10 -0
- package/esm/src/dsl/http/versori/constants.d.ts.map +1 -0
- package/esm/src/dsl/http/versori/constants.js +12 -0
- package/esm/src/dsl/http/versori/internalauth.d.ts.map +1 -1
- package/esm/src/dsl/http/versori/internalauth.js +10 -9
- package/esm/src/dsl/http/versori/platformapi.d.ts +14 -0
- package/esm/src/dsl/http/versori/platformapi.d.ts.map +1 -0
- package/esm/src/dsl/http/versori/platformapi.js +91 -0
- package/esm/src/dsl/http/versori/roundtripper.d.ts +13 -6
- package/esm/src/dsl/http/versori/roundtripper.d.ts.map +1 -1
- package/esm/src/dsl/http/versori/roundtripper.js +171 -54
- package/esm/src/dsl/tasks/HttpTask.d.ts +18 -2
- package/esm/src/dsl/tasks/HttpTask.d.ts.map +1 -1
- package/esm/src/dsl/tasks/HttpTask.js +82 -0
- package/esm/src/dsl/triggers/ScheduleTrigger.d.ts +6 -2
- package/esm/src/dsl/triggers/ScheduleTrigger.d.ts.map +1 -1
- package/esm/src/dsl/triggers/ScheduleTrigger.js +10 -3
- package/esm/src/interpreter/memory/MemoryInterpreter.d.ts +1 -0
- package/esm/src/interpreter/memory/MemoryInterpreter.d.ts.map +1 -1
- package/esm/src/interpreter/memory/MemoryInterpreter.js +12 -3
- package/esm/src/interpreter/memory/ObservableCompiler.d.ts +2 -1
- package/esm/src/interpreter/memory/ObservableCompiler.d.ts.map +1 -1
- package/esm/src/interpreter/memory/compilers/background.d.ts.map +1 -1
- package/esm/src/interpreter/memory/compilers/background.js +4 -2
- package/esm/src/interpreter/memory/compilers/http.d.ts.map +1 -1
- package/esm/src/interpreter/memory/compilers/http.js +6 -12
- package/esm/src/interpreter/memory/compilers/schedule.d.ts.map +1 -1
- package/esm/src/interpreter/memory/compilers/schedule.js +32 -6
- package/esm/src/interpreter/memory/compilers/serial.js +1 -1
- package/esm/src/interpreter/memory/compilers/webhook.d.ts.map +1 -1
- package/esm/src/interpreter/memory/compilers/webhook.js +20 -4
- package/package.json +2 -1
- package/script/src/context/Context.d.ts +6 -1
- package/script/src/context/Context.d.ts.map +1 -1
- package/script/src/context/Context.js +17 -3
- package/script/src/context/ContextProvider.d.ts +3 -2
- package/script/src/context/ContextProvider.d.ts.map +1 -1
- package/script/src/context/ContextProvider.js +2 -2
- package/script/src/dsl/http/default.d.ts.map +1 -1
- package/script/src/dsl/http/default.js +3 -1
- package/script/src/dsl/http/types.d.ts +122 -16
- package/script/src/dsl/http/types.d.ts.map +1 -1
- package/script/src/dsl/http/types.js +7 -1
- package/script/src/dsl/http/versori/configloader.d.ts +2 -2
- package/script/src/dsl/http/versori/configloader.d.ts.map +1 -1
- package/script/src/dsl/http/versori/configloader.js +10 -4
- package/script/src/dsl/http/versori/constants.d.ts +10 -0
- package/script/src/dsl/http/versori/constants.d.ts.map +1 -0
- package/script/src/dsl/http/versori/constants.js +15 -0
- package/script/src/dsl/http/versori/internalauth.d.ts.map +1 -1
- package/script/src/dsl/http/versori/internalauth.js +10 -9
- package/script/src/dsl/http/versori/platformapi.d.ts +14 -0
- package/script/src/dsl/http/versori/platformapi.d.ts.map +1 -0
- package/script/src/dsl/http/versori/platformapi.js +118 -0
- package/script/src/dsl/http/versori/roundtripper.d.ts +13 -6
- package/script/src/dsl/http/versori/roundtripper.d.ts.map +1 -1
- package/script/src/dsl/http/versori/roundtripper.js +170 -54
- package/script/src/dsl/tasks/HttpTask.d.ts +18 -2
- package/script/src/dsl/tasks/HttpTask.d.ts.map +1 -1
- package/script/src/dsl/tasks/HttpTask.js +84 -1
- package/script/src/dsl/triggers/ScheduleTrigger.d.ts +6 -2
- package/script/src/dsl/triggers/ScheduleTrigger.d.ts.map +1 -1
- package/script/src/dsl/triggers/ScheduleTrigger.js +10 -3
- package/script/src/interpreter/memory/MemoryInterpreter.d.ts +1 -0
- package/script/src/interpreter/memory/MemoryInterpreter.d.ts.map +1 -1
- package/script/src/interpreter/memory/MemoryInterpreter.js +12 -3
- package/script/src/interpreter/memory/ObservableCompiler.d.ts +2 -1
- package/script/src/interpreter/memory/ObservableCompiler.d.ts.map +1 -1
- package/script/src/interpreter/memory/compilers/background.d.ts.map +1 -1
- package/script/src/interpreter/memory/compilers/background.js +3 -1
- package/script/src/interpreter/memory/compilers/http.d.ts.map +1 -1
- package/script/src/interpreter/memory/compilers/http.js +5 -11
- package/script/src/interpreter/memory/compilers/schedule.d.ts.map +1 -1
- package/script/src/interpreter/memory/compilers/schedule.js +32 -6
- package/script/src/interpreter/memory/compilers/serial.js +1 -1
- package/script/src/interpreter/memory/compilers/webhook.d.ts.map +1 -1
- package/script/src/interpreter/memory/compilers/webhook.js +20 -4
- package/esm/src/dsl/http/versori/connectapi.d.ts +0 -11
- package/esm/src/dsl/http/versori/connectapi.d.ts.map +0 -1
- package/esm/src/dsl/http/versori/connectapi.js +0 -57
- package/script/src/dsl/http/versori/connectapi.d.ts +0 -11
- package/script/src/dsl/http/versori/connectapi.d.ts.map +0 -1
- package/script/src/dsl/http/versori/connectapi.js +0 -61
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { Activation, Connection, ConnectionProvider } from '../types.js';
|
|
2
|
+
export declare class PlatformAPIClient implements ConnectionProvider {
|
|
3
|
+
private baseUrl;
|
|
4
|
+
private orgId;
|
|
5
|
+
private envId;
|
|
6
|
+
private internalAuth;
|
|
7
|
+
private cache;
|
|
8
|
+
constructor(baseUrl: string, orgId: string, envId: string, cache?: Record<string, Connection>);
|
|
9
|
+
static fromEnv(): PlatformAPIClient;
|
|
10
|
+
getStaticConnection(cnxId: string): Promise<Connection | undefined>;
|
|
11
|
+
getEndUserConnection(templateId: string, userId: string): Promise<Connection | undefined>;
|
|
12
|
+
listActivations(): Promise<Activation[]>;
|
|
13
|
+
}
|
|
14
|
+
//# sourceMappingURL=platformapi.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"platformapi.d.ts","sourceRoot":"","sources":["../../../../../src/src/dsl/http/versori/platformapi.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAC;AAIzE,qBAAa,iBAAkB,YAAW,kBAAkB;IACxD,OAAO,CAAC,OAAO,CAAS;IAExB,OAAO,CAAC,KAAK,CAAS;IAEtB,OAAO,CAAC,KAAK,CAAS;IAEtB,OAAO,CAAC,YAAY,CAAe;IAEnC,OAAO,CAAC,KAAK,CAA6B;gBAGtC,OAAO,EAAE,MAAM,EACf,KAAK,EAAE,MAAM,EACb,KAAK,EAAE,MAAM,EACb,KAAK,GAAE,MAAM,CAAC,MAAM,EAAE,UAAU,CAAM;IAS1C,MAAM,CAAC,OAAO,IAAI,iBAAiB;IAY7B,mBAAmB,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,UAAU,GAAG,SAAS,CAAC;IA2BnE,oBAAoB,CAAC,UAAU,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,UAAU,GAAG,SAAS,CAAC;IAmBzF,eAAe,IAAI,OAAO,CAAC,UAAU,EAAE,CAAC;CAkBjD"}
|
|
@@ -0,0 +1,118 @@
|
|
|
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
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
+
exports.PlatformAPIClient = void 0;
|
|
27
|
+
const dntShim = __importStar(require("../../../../_dnt.shims.js"));
|
|
28
|
+
const constants_js_1 = require("./constants.js");
|
|
29
|
+
const internalauth_js_1 = require("./internalauth.js");
|
|
30
|
+
class PlatformAPIClient {
|
|
31
|
+
constructor(baseUrl, orgId, envId, cache = {}) {
|
|
32
|
+
Object.defineProperty(this, "baseUrl", {
|
|
33
|
+
enumerable: true,
|
|
34
|
+
configurable: true,
|
|
35
|
+
writable: true,
|
|
36
|
+
value: void 0
|
|
37
|
+
});
|
|
38
|
+
Object.defineProperty(this, "orgId", {
|
|
39
|
+
enumerable: true,
|
|
40
|
+
configurable: true,
|
|
41
|
+
writable: true,
|
|
42
|
+
value: void 0
|
|
43
|
+
});
|
|
44
|
+
Object.defineProperty(this, "envId", {
|
|
45
|
+
enumerable: true,
|
|
46
|
+
configurable: true,
|
|
47
|
+
writable: true,
|
|
48
|
+
value: void 0
|
|
49
|
+
});
|
|
50
|
+
Object.defineProperty(this, "internalAuth", {
|
|
51
|
+
enumerable: true,
|
|
52
|
+
configurable: true,
|
|
53
|
+
writable: true,
|
|
54
|
+
value: void 0
|
|
55
|
+
});
|
|
56
|
+
Object.defineProperty(this, "cache", {
|
|
57
|
+
enumerable: true,
|
|
58
|
+
configurable: true,
|
|
59
|
+
writable: true,
|
|
60
|
+
value: void 0
|
|
61
|
+
});
|
|
62
|
+
this.baseUrl = baseUrl;
|
|
63
|
+
this.orgId = orgId;
|
|
64
|
+
this.cache = cache;
|
|
65
|
+
this.envId = envId;
|
|
66
|
+
this.internalAuth = new internalauth_js_1.InternalAuth();
|
|
67
|
+
}
|
|
68
|
+
static fromEnv() {
|
|
69
|
+
const baseUrl = dntShim.Deno.env.get(constants_js_1.envVarPlatformApiBaseURL);
|
|
70
|
+
const orgId = dntShim.Deno.env.get(constants_js_1.envVarOrgId);
|
|
71
|
+
const envId = dntShim.Deno.env.get(constants_js_1.envVarEnvId);
|
|
72
|
+
if (!baseUrl || !orgId || !envId) {
|
|
73
|
+
throw new Error('Missing required environment variables');
|
|
74
|
+
}
|
|
75
|
+
return new PlatformAPIClient(baseUrl, orgId, envId);
|
|
76
|
+
}
|
|
77
|
+
async getStaticConnection(cnxId) {
|
|
78
|
+
if (this.cache[cnxId]) {
|
|
79
|
+
return this.cache[cnxId];
|
|
80
|
+
}
|
|
81
|
+
const resp = await fetch(`${this.baseUrl}/o/${this.orgId}/connections/${cnxId}`, {
|
|
82
|
+
headers: {
|
|
83
|
+
'x-versori-internal-token': await this.internalAuth.getToken(),
|
|
84
|
+
},
|
|
85
|
+
});
|
|
86
|
+
if (!resp.ok) {
|
|
87
|
+
return undefined;
|
|
88
|
+
}
|
|
89
|
+
const result = (await resp.json());
|
|
90
|
+
this.cache[cnxId] = result;
|
|
91
|
+
return result;
|
|
92
|
+
}
|
|
93
|
+
async getEndUserConnection(templateId, userId) {
|
|
94
|
+
const resp = await fetch(`${this.baseUrl}/o/${this.orgId}/environment-systems/${templateId}/users/${userId}`, {
|
|
95
|
+
headers: {
|
|
96
|
+
'x-versori-internal-token': await this.internalAuth.getToken(),
|
|
97
|
+
},
|
|
98
|
+
});
|
|
99
|
+
if (!resp.ok) {
|
|
100
|
+
return undefined;
|
|
101
|
+
}
|
|
102
|
+
const result = (await resp.json());
|
|
103
|
+
return result;
|
|
104
|
+
}
|
|
105
|
+
async listActivations() {
|
|
106
|
+
const resp = await fetch(`${this.baseUrl}/o/${this.orgId}/environments/${this.envId}/activations`, {
|
|
107
|
+
headers: {
|
|
108
|
+
'x-versori-internal-token': await this.internalAuth.getToken(),
|
|
109
|
+
},
|
|
110
|
+
});
|
|
111
|
+
if (!resp.ok) {
|
|
112
|
+
return [];
|
|
113
|
+
}
|
|
114
|
+
const result = (await resp.json());
|
|
115
|
+
return result;
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
exports.PlatformAPIClient = PlatformAPIClient;
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { DynamicFetcher, RoundTripperFactory } from "../types.js";
|
|
1
|
+
import { DynamicFetcher, RoundTripperFactory } from '../types.js';
|
|
3
2
|
import { VersoriCredentialClient } from './credentials/mod.js';
|
|
3
|
+
import { PlatformAPIClient } from './platformapi.js';
|
|
4
|
+
import { Logger } from '../../../observability/logging/Logger.js';
|
|
4
5
|
export type RunningEnvironment = 'local' | 'versori' | 'staging';
|
|
5
|
-
export declare function CreateFromEnv(): VersoriRoundTripperFactory;
|
|
6
6
|
/**
|
|
7
7
|
* VersoriRoundTripper is an implementation of the RoundTripperFactory interface for Versori connections.
|
|
8
8
|
* This is the intended implementation for when projects/services are hosted on Versori infrastructure.
|
|
@@ -16,13 +16,20 @@ export declare function CreateFromEnv(): VersoriRoundTripperFactory;
|
|
|
16
16
|
* ```
|
|
17
17
|
*/
|
|
18
18
|
export declare class VersoriRoundTripperFactory implements RoundTripperFactory {
|
|
19
|
-
private cAPIClient;
|
|
20
19
|
private tokenClient;
|
|
20
|
+
private platformAPIClient;
|
|
21
21
|
private versoriCfg;
|
|
22
|
-
|
|
22
|
+
private log;
|
|
23
|
+
private readonly defaultStatic;
|
|
24
|
+
private readonly defaultDynamic;
|
|
25
|
+
constructor(credsClient: VersoriCredentialClient, platformAPIClient: PlatformAPIClient, logger: Logger);
|
|
26
|
+
static fromEnv(logger?: Logger): VersoriRoundTripperFactory;
|
|
27
|
+
private changeRequestInit;
|
|
28
|
+
private changeBaseUrl;
|
|
23
29
|
create(connName: string, fn?: typeof fetch): Promise<typeof fetch>;
|
|
24
|
-
createDynamic(templateName: string, fn
|
|
30
|
+
createDynamic(templateName: string, fn?: typeof fetch): Promise<DynamicFetcher>;
|
|
25
31
|
private getConnectionID;
|
|
32
|
+
private getTemplateID;
|
|
26
33
|
private apiKeyFetcher;
|
|
27
34
|
private basicAuthFetcher;
|
|
28
35
|
private bearerTokenFetcher;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"roundtripper.d.ts","sourceRoot":"","sources":["../../../../../src/src/dsl/http/versori/roundtripper.ts"],"names":[],"mappings":"AACA,OAAO,
|
|
1
|
+
{"version":3,"file":"roundtripper.d.ts","sourceRoot":"","sources":["../../../../../src/src/dsl/http/versori/roundtripper.ts"],"names":[],"mappings":"AACA,OAAO,EAAc,cAAc,EAAE,mBAAmB,EAAoB,MAAM,aAAa,CAAC;AAEhG,OAAO,EAAE,uBAAuB,EAAE,MAAM,sBAAsB,CAAC;AAE/D,OAAO,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAC;AACrD,OAAO,EAAE,MAAM,EAAE,MAAM,0CAA0C,CAAC;AASlE,MAAM,MAAM,kBAAkB,GAAG,OAAO,GAAG,SAAS,GAAG,SAAS,CAAC;AAEjE;;;;;;;;;;;GAWG;AACH,qBAAa,0BAA2B,YAAW,mBAAmB;IAClE,OAAO,CAAC,WAAW,CAA0B;IAE7C,OAAO,CAAC,iBAAiB,CAAoB;IAE7C,OAAO,CAAC,UAAU,CAAmB;IAErC,OAAO,CAAC,GAAG,CAAS;IAEpB,OAAO,CAAC,QAAQ,CAAC,aAAa,CAK5B;IAEF,OAAO,CAAC,QAAQ,CAAC,cAAc,CAM7B;gBAGE,WAAW,EAAE,uBAAuB,EACpC,iBAAiB,EAAE,iBAAiB,EACpC,MAAM,EAAE,MAAM;IAQlB,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,EAAE,MAAM,GAAG,0BAA0B;IA0B3D,OAAO,CAAC,iBAAiB;IAYzB,OAAO,CAAC,aAAa;IAmBf,MAAM,CAAC,QAAQ,EAAE,MAAM,EAAE,EAAE,GAAE,OAAO,KAAwB,GAAG,OAAO,CAAC,OAAO,KAAK,CAAC;IAyBpF,aAAa,CACf,YAAY,EAAE,MAAM,EACpB,EAAE,GAAE,OAAO,KAAwB,GACpC,OAAO,CAAC,cAAc,CAAC;IA0D1B,OAAO,CAAC,eAAe;IAavB,OAAO,CAAC,aAAa;YAYP,aAAa;YAoDb,gBAAgB;YA0BhB,kBAAkB;YAiClB,aAAa;CAkD9B"}
|
|
@@ -24,32 +24,13 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
24
24
|
};
|
|
25
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
26
|
exports.VersoriRoundTripperFactory = void 0;
|
|
27
|
-
exports.CreateFromEnv = CreateFromEnv;
|
|
28
27
|
const dntShim = __importStar(require("../../../../_dnt.shims.js"));
|
|
29
|
-
const connectapi_js_1 = require("./connectapi.js");
|
|
30
28
|
const configloader_js_1 = require("./configloader.js");
|
|
31
29
|
const mod_js_1 = require("./credentials/mod.js");
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
const serviceConnId = dntShim.Deno.env.get('RUN_CONNECTOR_ID');
|
|
37
|
-
if (!orgId || !serviceConnId || !connAPIBaseURL || !credsBaseURL) {
|
|
38
|
-
const missingVars = [];
|
|
39
|
-
if (!orgId)
|
|
40
|
-
missingVars.push('RUN_ORGANISATION_ID');
|
|
41
|
-
if (!serviceConnId)
|
|
42
|
-
missingVars.push('RUN_CONNECTOR_ID');
|
|
43
|
-
if (!connAPIBaseURL)
|
|
44
|
-
missingVars.push('RUN_CONNECT_API_INTERNAL_URL');
|
|
45
|
-
if (!credsBaseURL)
|
|
46
|
-
missingVars.push('RUN_CREDENTIALS_SERVICE_INTERNAL_URL');
|
|
47
|
-
throw new Error(`Missing environment variables: ${missingVars.join(', ')}`);
|
|
48
|
-
}
|
|
49
|
-
const cAPIClient = new connectapi_js_1.ConnectAPIClient(connAPIBaseURL, orgId, serviceConnId, {});
|
|
50
|
-
const tokenClient = new mod_js_1.VersoriCredentialClient(credsBaseURL);
|
|
51
|
-
return new VersoriRoundTripperFactory(cAPIClient, tokenClient);
|
|
52
|
-
}
|
|
30
|
+
const lru_cache_1 = require("lru-cache");
|
|
31
|
+
const platformapi_js_1 = require("./platformapi.js");
|
|
32
|
+
const mod_js_2 = require("../../../observability/mod.js");
|
|
33
|
+
const constants_js_1 = require("./constants.js");
|
|
53
34
|
/**
|
|
54
35
|
* VersoriRoundTripper is an implementation of the RoundTripperFactory interface for Versori connections.
|
|
55
36
|
* This is the intended implementation for when projects/services are hosted on Versori infrastructure.
|
|
@@ -63,14 +44,14 @@ function CreateFromEnv() {
|
|
|
63
44
|
* ```
|
|
64
45
|
*/
|
|
65
46
|
class VersoriRoundTripperFactory {
|
|
66
|
-
constructor(
|
|
67
|
-
Object.defineProperty(this, "
|
|
47
|
+
constructor(credsClient, platformAPIClient, logger) {
|
|
48
|
+
Object.defineProperty(this, "tokenClient", {
|
|
68
49
|
enumerable: true,
|
|
69
50
|
configurable: true,
|
|
70
51
|
writable: true,
|
|
71
52
|
value: void 0
|
|
72
53
|
});
|
|
73
|
-
Object.defineProperty(this, "
|
|
54
|
+
Object.defineProperty(this, "platformAPIClient", {
|
|
74
55
|
enumerable: true,
|
|
75
56
|
configurable: true,
|
|
76
57
|
writable: true,
|
|
@@ -82,17 +63,99 @@ class VersoriRoundTripperFactory {
|
|
|
82
63
|
writable: true,
|
|
83
64
|
value: void 0
|
|
84
65
|
});
|
|
85
|
-
this
|
|
66
|
+
Object.defineProperty(this, "log", {
|
|
67
|
+
enumerable: true,
|
|
68
|
+
configurable: true,
|
|
69
|
+
writable: true,
|
|
70
|
+
value: void 0
|
|
71
|
+
});
|
|
72
|
+
Object.defineProperty(this, "defaultStatic", {
|
|
73
|
+
enumerable: true,
|
|
74
|
+
configurable: true,
|
|
75
|
+
writable: true,
|
|
76
|
+
value: (msg, values) => {
|
|
77
|
+
return (input, init) => {
|
|
78
|
+
this.log.error(msg, values);
|
|
79
|
+
return globalThis.fetch(input, init);
|
|
80
|
+
};
|
|
81
|
+
}
|
|
82
|
+
});
|
|
83
|
+
Object.defineProperty(this, "defaultDynamic", {
|
|
84
|
+
enumerable: true,
|
|
85
|
+
configurable: true,
|
|
86
|
+
writable: true,
|
|
87
|
+
value: (msg, values) => {
|
|
88
|
+
return (userId, input, init) => {
|
|
89
|
+
values['userId'] = userId;
|
|
90
|
+
this.log.error(msg, values);
|
|
91
|
+
return globalThis.fetch(input, init);
|
|
92
|
+
};
|
|
93
|
+
}
|
|
94
|
+
});
|
|
86
95
|
this.tokenClient = credsClient;
|
|
87
|
-
this.
|
|
96
|
+
this.platformAPIClient = platformAPIClient;
|
|
97
|
+
this.versoriCfg = (0, configloader_js_1.LoadConfigFromFile)();
|
|
98
|
+
this.log = logger;
|
|
99
|
+
}
|
|
100
|
+
static fromEnv(logger) {
|
|
101
|
+
const credsBaseURL = dntShim.Deno.env.get(constants_js_1.envVarCredsBaseURL);
|
|
102
|
+
const platformApiBaseURL = dntShim.Deno.env.get(constants_js_1.envVarPlatformApiBaseURL);
|
|
103
|
+
const orgId = dntShim.Deno.env.get(constants_js_1.envVarOrgId);
|
|
104
|
+
const envId = dntShim.Deno.env.get(constants_js_1.envVarEnvId);
|
|
105
|
+
if (!orgId || !envId || !platformApiBaseURL || !credsBaseURL) {
|
|
106
|
+
const missingVars = [];
|
|
107
|
+
if (!orgId)
|
|
108
|
+
missingVars.push(constants_js_1.envVarOrgId);
|
|
109
|
+
if (!envId)
|
|
110
|
+
missingVars.push(constants_js_1.envVarEnvId);
|
|
111
|
+
if (!platformApiBaseURL)
|
|
112
|
+
missingVars.push(constants_js_1.envVarPlatformApiBaseURL);
|
|
113
|
+
if (!credsBaseURL)
|
|
114
|
+
missingVars.push(constants_js_1.envVarCredsBaseURL);
|
|
115
|
+
throw new Error(`Missing environment variables: ${missingVars.join(', ')}`);
|
|
116
|
+
}
|
|
117
|
+
const pAPIClient = new platformapi_js_1.PlatformAPIClient(platformApiBaseURL, orgId, envId, {});
|
|
118
|
+
const tokenClient = new mod_js_1.VersoriCredentialClient(credsBaseURL);
|
|
119
|
+
const log = logger || new mod_js_2.ConsoleLogger('debug');
|
|
120
|
+
return new VersoriRoundTripperFactory(tokenClient, pAPIClient, log);
|
|
121
|
+
}
|
|
122
|
+
// takes the info and modifies the url using changeBaseUrl if necessary
|
|
123
|
+
changeRequestInit(info, conn) {
|
|
124
|
+
if (typeof info === 'string') {
|
|
125
|
+
return this.changeBaseUrl(info, conn);
|
|
126
|
+
}
|
|
127
|
+
else if (info instanceof URL) {
|
|
128
|
+
return this.changeBaseUrl(info.toString(), conn);
|
|
129
|
+
}
|
|
130
|
+
else if (info instanceof Request) {
|
|
131
|
+
const url = this.changeBaseUrl(info.url, conn);
|
|
132
|
+
return new Request(url, info);
|
|
133
|
+
}
|
|
134
|
+
return info;
|
|
88
135
|
}
|
|
89
|
-
|
|
136
|
+
changeBaseUrl(url, conn) {
|
|
137
|
+
const baseUrl = conn.baseUrl;
|
|
138
|
+
if (!baseUrl) {
|
|
139
|
+
return url;
|
|
140
|
+
}
|
|
141
|
+
const urlObj = new URL(url);
|
|
142
|
+
const baseUrlObj = new URL(baseUrl);
|
|
143
|
+
urlObj.hostname = baseUrlObj.hostname;
|
|
144
|
+
this.log.debug('Changing base URL', {
|
|
145
|
+
originalUrl: url,
|
|
146
|
+
newUrl: urlObj.toString(),
|
|
147
|
+
});
|
|
148
|
+
return url.toString();
|
|
149
|
+
}
|
|
150
|
+
async create(connName, fn = globalThis.fetch) {
|
|
90
151
|
const cnxId = this.getConnectionID(connName);
|
|
91
|
-
const conn = await this.
|
|
152
|
+
const conn = await this.platformAPIClient.getStaticConnection(cnxId);
|
|
92
153
|
if (!conn) {
|
|
93
|
-
|
|
154
|
+
return this.defaultStatic('Connection not found for static, using default fetch', {
|
|
155
|
+
connName: connName,
|
|
156
|
+
});
|
|
94
157
|
}
|
|
95
|
-
switch (conn.credentials
|
|
158
|
+
switch (conn.credentials[0].authSchemeConfig.type) {
|
|
96
159
|
case 'api-key':
|
|
97
160
|
return this.apiKeyFetcher(conn, fn);
|
|
98
161
|
case 'basic-auth':
|
|
@@ -105,55 +168,108 @@ class VersoriRoundTripperFactory {
|
|
|
105
168
|
return fn;
|
|
106
169
|
}
|
|
107
170
|
}
|
|
108
|
-
async createDynamic(templateName, fn) {
|
|
109
|
-
|
|
171
|
+
async createDynamic(templateName, fn = globalThis.fetch) {
|
|
172
|
+
const lruCacheOptions = {
|
|
173
|
+
max: 100,
|
|
174
|
+
};
|
|
175
|
+
const cache = new lru_cache_1.LRUCache(lruCacheOptions);
|
|
176
|
+
const template = this.getTemplateID(templateName);
|
|
177
|
+
if (!template) {
|
|
178
|
+
return this.defaultDynamic('Template not found for dynamic, using default fetch', {
|
|
179
|
+
templateName: templateName,
|
|
180
|
+
});
|
|
181
|
+
}
|
|
182
|
+
const _fn = async (userId, input, init) => {
|
|
183
|
+
let conn = undefined;
|
|
184
|
+
if (cache.has(userId)) {
|
|
185
|
+
conn = cache.get(userId);
|
|
186
|
+
}
|
|
187
|
+
else {
|
|
188
|
+
conn = await this.platformAPIClient.getEndUserConnection(template, userId);
|
|
189
|
+
if (conn) {
|
|
190
|
+
cache.set(userId, conn);
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
if (!conn) {
|
|
194
|
+
return this.defaultDynamic('Connection not found for user, using default fetch', {
|
|
195
|
+
templateName: templateName,
|
|
196
|
+
userId: userId,
|
|
197
|
+
})(userId, input, init);
|
|
198
|
+
}
|
|
199
|
+
const _input = this.changeRequestInit(input, conn);
|
|
200
|
+
switch (conn.credentials[0].authSchemeConfig.type) {
|
|
201
|
+
case 'api-key':
|
|
202
|
+
return (await this.apiKeyFetcher(conn, fn))(_input, init);
|
|
203
|
+
case 'basic-auth':
|
|
204
|
+
return (await this.basicAuthFetcher(conn, fn))(_input, init);
|
|
205
|
+
case 'jwt-bearer':
|
|
206
|
+
return (await this.bearerTokenFetcher(conn, fn))(_input, init);
|
|
207
|
+
case 'oauth2':
|
|
208
|
+
return (await this.oauth2Fetcher(conn, fn))(_input, init);
|
|
209
|
+
default:
|
|
210
|
+
return fn(_input, init);
|
|
211
|
+
}
|
|
212
|
+
};
|
|
213
|
+
return _fn;
|
|
110
214
|
}
|
|
111
215
|
getConnectionID(connName) {
|
|
112
216
|
// Note that this is till very up in the air whether we are going to store the connection ID in the config
|
|
113
|
-
const conn = this.versoriCfg.
|
|
114
|
-
if (!conn) {
|
|
115
|
-
|
|
217
|
+
const conn = this.versoriCfg.mappings.find((c) => (c.dynamic === undefined || c.dynamic === false) && c.name === connName);
|
|
218
|
+
if (!conn || !conn.connId) {
|
|
219
|
+
return '';
|
|
116
220
|
}
|
|
117
|
-
return conn.
|
|
221
|
+
return conn.connId;
|
|
222
|
+
}
|
|
223
|
+
getTemplateID(templateName) {
|
|
224
|
+
// see above, also I'm assuming for now that the template id is simply the same as the connection id
|
|
225
|
+
// but there is another flag that denotes it as dynamic??
|
|
226
|
+
const template = this.versoriCfg.mappings.find((c) => c.dynamic && c.name === templateName);
|
|
227
|
+
if (!template || !template.templateId) {
|
|
228
|
+
return '';
|
|
229
|
+
}
|
|
230
|
+
return template.templateId;
|
|
118
231
|
}
|
|
119
232
|
async apiKeyFetcher(conn, fn) {
|
|
120
|
-
const tokenResponse = await this.tokenClient.getToken(conn.credentials
|
|
233
|
+
const tokenResponse = await this.tokenClient.getToken(conn.credentials[0].credential.id);
|
|
121
234
|
const token = tokenResponse.token?.accessToken;
|
|
235
|
+
const asc = conn.credentials[0].authSchemeConfig.apiKey;
|
|
122
236
|
if (!token) {
|
|
123
237
|
throw new Error('Token not found');
|
|
124
238
|
}
|
|
239
|
+
if (!asc) {
|
|
240
|
+
throw new Error('API Key configuration not found');
|
|
241
|
+
}
|
|
125
242
|
const _fn = (input, init) => {
|
|
126
243
|
if (!init) {
|
|
127
244
|
init = {};
|
|
128
245
|
}
|
|
129
|
-
|
|
130
|
-
switch (conn.credentials.action[0].authSchemeConfig.in) {
|
|
246
|
+
switch (asc.in) {
|
|
131
247
|
case 'header':
|
|
132
248
|
if (!init.headers) {
|
|
133
249
|
init.headers = new Headers();
|
|
134
250
|
}
|
|
135
251
|
if (init.headers instanceof Headers) {
|
|
136
|
-
init.headers.set(
|
|
252
|
+
init.headers.set(asc.name, token);
|
|
137
253
|
}
|
|
138
254
|
else if (init.headers instanceof Array) {
|
|
139
|
-
init.headers.push([
|
|
255
|
+
init.headers.push([asc.name, token]);
|
|
140
256
|
}
|
|
141
257
|
else {
|
|
142
258
|
init.headers = {
|
|
143
259
|
...init.headers,
|
|
144
|
-
[
|
|
260
|
+
[asc.name]: token,
|
|
145
261
|
};
|
|
146
262
|
}
|
|
147
263
|
break;
|
|
148
264
|
case 'query':
|
|
149
265
|
if (typeof input === 'string') {
|
|
150
|
-
input += `?${
|
|
266
|
+
input += `?${asc.name}=${token}`;
|
|
151
267
|
}
|
|
152
268
|
else if (input instanceof Request) {
|
|
153
|
-
input = new Request(input.url + `?${
|
|
269
|
+
input = new Request(input.url + `?${asc.name}=${token}`, init);
|
|
154
270
|
}
|
|
155
271
|
else if (input instanceof URL) {
|
|
156
|
-
input.searchParams.append(
|
|
272
|
+
input.searchParams.append(asc.name, token);
|
|
157
273
|
}
|
|
158
274
|
break;
|
|
159
275
|
}
|
|
@@ -162,7 +278,7 @@ class VersoriRoundTripperFactory {
|
|
|
162
278
|
return _fn;
|
|
163
279
|
}
|
|
164
280
|
async basicAuthFetcher(conn, fn) {
|
|
165
|
-
const tokenResponse = await this.tokenClient.getToken(conn.credentials
|
|
281
|
+
const tokenResponse = await this.tokenClient.getToken(conn.credentials[0].credential.id);
|
|
166
282
|
const token = tokenResponse.token?.accessToken;
|
|
167
283
|
if (!token) {
|
|
168
284
|
throw new Error('Token not found');
|
|
@@ -174,14 +290,14 @@ class VersoriRoundTripperFactory {
|
|
|
174
290
|
if (!init.headers) {
|
|
175
291
|
init.headers = new Headers();
|
|
176
292
|
}
|
|
177
|
-
init.headers.set('Authorization', token);
|
|
293
|
+
init.headers.set('Authorization', `Basic ${token}`);
|
|
178
294
|
return fn(input, init);
|
|
179
295
|
};
|
|
180
296
|
return _fn;
|
|
181
297
|
}
|
|
182
|
-
// TODO: need to make the prefix and header name
|
|
298
|
+
// TODO: need to make the prefix and header name configurable from authschemeconfig
|
|
183
299
|
async bearerTokenFetcher(conn, fn) {
|
|
184
|
-
const tokenResponse = await this.tokenClient.getToken(conn.credentials
|
|
300
|
+
const tokenResponse = await this.tokenClient.getToken(conn.credentials[0].credential.id);
|
|
185
301
|
const token = tokenResponse.token?.accessToken;
|
|
186
302
|
if (!token) {
|
|
187
303
|
throw new Error('Token not found');
|
|
@@ -202,7 +318,7 @@ class VersoriRoundTripperFactory {
|
|
|
202
318
|
else {
|
|
203
319
|
init.headers = {
|
|
204
320
|
...init.headers,
|
|
205
|
-
['Authorization']: `Bearer ${token}
|
|
321
|
+
['Authorization']: `Bearer ${token}`,
|
|
206
322
|
};
|
|
207
323
|
}
|
|
208
324
|
return fn(input, init);
|
|
@@ -210,7 +326,7 @@ class VersoriRoundTripperFactory {
|
|
|
210
326
|
return _fn;
|
|
211
327
|
}
|
|
212
328
|
async oauth2Fetcher(conn, fn) {
|
|
213
|
-
const tokenResponse = await this.tokenClient.getOAuth2Token(conn.credentials
|
|
329
|
+
const tokenResponse = await this.tokenClient.getOAuth2Token(conn.credentials[0].credential.id);
|
|
214
330
|
const token = tokenResponse.token?.accessToken;
|
|
215
331
|
const tokenType = tokenResponse.token?.tokenType;
|
|
216
332
|
if (!token) {
|
|
@@ -245,7 +361,7 @@ class VersoriRoundTripperFactory {
|
|
|
245
361
|
else {
|
|
246
362
|
init.headers = {
|
|
247
363
|
...init.headers,
|
|
248
|
-
['Authorization']: `${_tokenType()} ${token}
|
|
364
|
+
['Authorization']: `${_tokenType()} ${token}`,
|
|
249
365
|
};
|
|
250
366
|
}
|
|
251
367
|
return fn(input, init);
|
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
import { Context } from '../../context/Context.js';
|
|
2
|
+
import { Logger } from '../../mod.js';
|
|
3
|
+
import { Activation, DynamicFetcher } from '../http/types.js';
|
|
2
4
|
import { ArrayTask, Task, Taskable, TaskType } from '../Task.js';
|
|
3
|
-
export
|
|
5
|
+
export interface HttpContext<Data, PageParams = undefined> extends Context<Data> {
|
|
4
6
|
fetch: typeof fetch;
|
|
5
7
|
connectionVariables: Record<string, any>;
|
|
6
8
|
pageParams?: PageParams;
|
|
7
9
|
nextPage: (nextParams: PageParams) => Promise<void>;
|
|
8
|
-
}
|
|
10
|
+
}
|
|
9
11
|
export type HttpContextFunc<In, Out, PageParams> = (ctx: HttpContext<In, PageParams>) => Promise<Out>;
|
|
10
12
|
export type PaginateOptions<P> = {
|
|
11
13
|
initialParams: P;
|
|
@@ -27,5 +29,19 @@ export declare class HttpTaskImpl<In, Out, PageParams> implements Task<In, Out>
|
|
|
27
29
|
unpack<NextOut>(mapper: (data: Out) => NextOut[]): ArrayTask<In, NextOut>;
|
|
28
30
|
clone(): Task<In, Out>;
|
|
29
31
|
}
|
|
32
|
+
export declare class HttpContextImpl<D, PageParams> implements HttpContext<D, PageParams> {
|
|
33
|
+
log: Logger;
|
|
34
|
+
startTime: Date;
|
|
35
|
+
executionId: string;
|
|
36
|
+
activation?: Activation;
|
|
37
|
+
data: D;
|
|
38
|
+
connectionVariables: Record<string, any>;
|
|
39
|
+
pageParams?: PageParams;
|
|
40
|
+
private dynamicFetcher?;
|
|
41
|
+
private staticFetcher;
|
|
42
|
+
constructor(ctx: Context<D>, connectionVars: Record<string, any>, staticFetcher: typeof fetch, dynamicFetcher?: DynamicFetcher, pageParams?: PageParams);
|
|
43
|
+
get fetch(): typeof globalThis.fetch;
|
|
44
|
+
nextPage(nextParams: PageParams): Promise<void>;
|
|
45
|
+
}
|
|
30
46
|
export declare function http<In = any, Out = any, PageParams = unknown>(taskId: string, opts: HttpOptions<In, Out, PageParams>, fn: HttpContextFunc<In, Out, PageParams>): Task<In, Out>;
|
|
31
47
|
//# sourceMappingURL=HttpTask.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"HttpTask.d.ts","sourceRoot":"","sources":["../../../../src/src/dsl/tasks/HttpTask.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,0BAA0B,CAAC;
|
|
1
|
+
{"version":3,"file":"HttpTask.d.ts","sourceRoot":"","sources":["../../../../src/src/dsl/tasks/HttpTask.ts"],"names":[],"mappings":"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"}
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
var _a;
|
|
3
3
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
-
exports.HttpTaskImpl = void 0;
|
|
4
|
+
exports.HttpContextImpl = exports.HttpTaskImpl = void 0;
|
|
5
5
|
exports.http = http;
|
|
6
6
|
const ensureTask_js_1 = require("../ensureTask.js");
|
|
7
|
+
const types_js_1 = require("../http/types.js");
|
|
7
8
|
const Task_js_1 = require("../Task.js");
|
|
8
9
|
const BackgroundTask_js_1 = require("./BackgroundTask.js");
|
|
9
10
|
const CatchTask_js_1 = require("./CatchTask.js");
|
|
@@ -60,6 +61,88 @@ class HttpTaskImpl {
|
|
|
60
61
|
}
|
|
61
62
|
exports.HttpTaskImpl = HttpTaskImpl;
|
|
62
63
|
_a = Task_js_1.TaskType;
|
|
64
|
+
class HttpContextImpl {
|
|
65
|
+
constructor(ctx, connectionVars, staticFetcher, dynamicFetcher, pageParams) {
|
|
66
|
+
Object.defineProperty(this, "log", {
|
|
67
|
+
enumerable: true,
|
|
68
|
+
configurable: true,
|
|
69
|
+
writable: true,
|
|
70
|
+
value: void 0
|
|
71
|
+
});
|
|
72
|
+
Object.defineProperty(this, "startTime", {
|
|
73
|
+
enumerable: true,
|
|
74
|
+
configurable: true,
|
|
75
|
+
writable: true,
|
|
76
|
+
value: void 0
|
|
77
|
+
});
|
|
78
|
+
Object.defineProperty(this, "executionId", {
|
|
79
|
+
enumerable: true,
|
|
80
|
+
configurable: true,
|
|
81
|
+
writable: true,
|
|
82
|
+
value: void 0
|
|
83
|
+
});
|
|
84
|
+
Object.defineProperty(this, "activation", {
|
|
85
|
+
enumerable: true,
|
|
86
|
+
configurable: true,
|
|
87
|
+
writable: true,
|
|
88
|
+
value: void 0
|
|
89
|
+
});
|
|
90
|
+
Object.defineProperty(this, "data", {
|
|
91
|
+
enumerable: true,
|
|
92
|
+
configurable: true,
|
|
93
|
+
writable: true,
|
|
94
|
+
value: void 0
|
|
95
|
+
});
|
|
96
|
+
Object.defineProperty(this, "connectionVariables", {
|
|
97
|
+
enumerable: true,
|
|
98
|
+
configurable: true,
|
|
99
|
+
writable: true,
|
|
100
|
+
value: {}
|
|
101
|
+
});
|
|
102
|
+
Object.defineProperty(this, "pageParams", {
|
|
103
|
+
enumerable: true,
|
|
104
|
+
configurable: true,
|
|
105
|
+
writable: true,
|
|
106
|
+
value: void 0
|
|
107
|
+
}); // TODO: Implement page params
|
|
108
|
+
Object.defineProperty(this, "dynamicFetcher", {
|
|
109
|
+
enumerable: true,
|
|
110
|
+
configurable: true,
|
|
111
|
+
writable: true,
|
|
112
|
+
value: void 0
|
|
113
|
+
});
|
|
114
|
+
Object.defineProperty(this, "staticFetcher", {
|
|
115
|
+
enumerable: true,
|
|
116
|
+
configurable: true,
|
|
117
|
+
writable: true,
|
|
118
|
+
value: void 0
|
|
119
|
+
});
|
|
120
|
+
this.log = ctx.log;
|
|
121
|
+
this.executionId = ctx.executionId;
|
|
122
|
+
this.startTime = ctx.startTime;
|
|
123
|
+
this.activation = ctx.activation;
|
|
124
|
+
this.data = ctx.data;
|
|
125
|
+
this.pageParams = pageParams;
|
|
126
|
+
this.connectionVariables = connectionVars;
|
|
127
|
+
this.dynamicFetcher = dynamicFetcher;
|
|
128
|
+
this.staticFetcher = staticFetcher;
|
|
129
|
+
}
|
|
130
|
+
get fetch() {
|
|
131
|
+
// TODO: this will need some work to make dynamic and static connections work in tandem.
|
|
132
|
+
let fetch;
|
|
133
|
+
if (this.dynamicFetcher && this.activation) {
|
|
134
|
+
fetch = (0, types_js_1.wrapDynamicFetcher)(this.dynamicFetcher, this.activation.id);
|
|
135
|
+
}
|
|
136
|
+
else {
|
|
137
|
+
fetch = this.staticFetcher;
|
|
138
|
+
}
|
|
139
|
+
return fetch;
|
|
140
|
+
}
|
|
141
|
+
async nextPage(nextParams) {
|
|
142
|
+
throw new Error("Method not implemented.");
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
exports.HttpContextImpl = HttpContextImpl;
|
|
63
146
|
function http(taskId, opts, fn) {
|
|
64
147
|
return new HttpTaskImpl(taskId, opts, fn);
|
|
65
148
|
}
|