@versori/run 0.2.0-alpha.8 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/{script/deps/jsr.io/@std/bytes/1.0.5 → esm/deps/jsr.io/@std/bytes/1.0.6}/_types.d.ts.map +1 -1
- package/{script/deps/jsr.io/@std/bytes/1.0.5 → esm/deps/jsr.io/@std/bytes/1.0.6}/concat.d.ts +1 -1
- package/esm/deps/jsr.io/@std/bytes/{1.0.5 → 1.0.6}/concat.d.ts.map +1 -1
- package/esm/deps/jsr.io/@std/bytes/{1.0.5 → 1.0.6}/copy.d.ts.map +1 -1
- package/esm/deps/jsr.io/@std/fmt/{1.0.7 → 1.0.8}/colors.d.ts.map +1 -1
- package/esm/deps/jsr.io/@std/io/0.225.2/buffer.js +1 -1
- package/esm/deps/jsr.io/@std/io/0.225.2/read_all.js +1 -1
- package/esm/deps/jsr.io/@std/log/0.224.14/console_handler.js +1 -1
- package/esm/src/context/Context.d.ts +5 -1
- package/esm/src/context/Context.d.ts.map +1 -1
- package/esm/src/context/Context.js +15 -4
- package/esm/src/context/ContextProvider.d.ts +3 -1
- package/esm/src/context/ContextProvider.d.ts.map +1 -1
- package/esm/src/context/ContextProvider.js +9 -2
- package/esm/src/dsl/http/default.d.ts +2 -0
- package/esm/src/dsl/http/default.d.ts.map +1 -1
- package/esm/src/dsl/http/default.js +10 -0
- package/esm/src/dsl/http/types.d.ts +5 -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/contextcredentials.d.ts +10 -0
- package/esm/src/dsl/http/versori/contextcredentials.d.ts.map +1 -0
- package/esm/src/dsl/http/versori/contextcredentials.js +1 -0
- package/esm/src/dsl/http/versori/credentials/client.d.ts +3 -0
- package/esm/src/dsl/http/versori/credentials/client.d.ts.map +1 -1
- package/esm/src/dsl/http/versori/credentials/client.js +11 -3
- package/esm/src/dsl/http/versori/credentials/credentials.d.ts +38 -0
- package/esm/src/dsl/http/versori/credentials/credentials.d.ts.map +1 -1
- package/esm/src/dsl/http/versori/credentials/credentials.js +7 -8
- package/esm/src/dsl/http/versori/credentials/v1alpha1/common_pb.d.ts +31 -0
- package/esm/src/dsl/http/versori/credentials/v1alpha1/common_pb.d.ts.map +1 -0
- package/esm/src/dsl/http/versori/credentials/v1alpha1/common_pb.js +31 -0
- package/esm/src/dsl/http/versori/credentials/v1alpha1/credential_service_pb.d.ts +84 -0
- package/esm/src/dsl/http/versori/credentials/v1alpha1/credential_service_pb.d.ts.map +1 -0
- package/esm/src/dsl/http/versori/credentials/v1alpha1/credential_service_pb.js +128 -0
- 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 +38 -6
- package/esm/src/dsl/http/versori/roundtripper.d.ts +11 -4
- package/esm/src/dsl/http/versori/roundtripper.d.ts.map +1 -1
- package/esm/src/dsl/http/versori/roundtripper.js +83 -16
- package/esm/src/dsl/tasks/HttpTask.d.ts.map +1 -1
- package/esm/src/dsl/tasks/HttpTask.js +1 -1
- package/esm/src/interpreter/memory/MemoryInterpreter.d.ts.map +1 -1
- package/esm/src/interpreter/memory/MemoryInterpreter.js +11 -3
- package/esm/src/observability/logging/ConsoleLogger.d.ts +1 -0
- package/esm/src/observability/logging/ConsoleLogger.d.ts.map +1 -1
- package/esm/src/observability/logging/ConsoleLogger.js +124 -30
- package/package.json +2 -1
- package/{esm/deps/jsr.io/@std/bytes/1.0.5 → script/deps/jsr.io/@std/bytes/1.0.6}/_types.d.ts.map +1 -1
- package/{esm/deps/jsr.io/@std/bytes/1.0.5 → script/deps/jsr.io/@std/bytes/1.0.6}/concat.d.ts +1 -1
- package/script/deps/jsr.io/@std/bytes/{1.0.5 → 1.0.6}/concat.d.ts.map +1 -1
- package/script/deps/jsr.io/@std/bytes/{1.0.5 → 1.0.6}/copy.d.ts.map +1 -1
- package/script/deps/jsr.io/@std/fmt/{1.0.7 → 1.0.8}/colors.d.ts.map +1 -1
- package/script/deps/jsr.io/@std/io/0.225.2/buffer.js +1 -1
- package/script/deps/jsr.io/@std/io/0.225.2/read_all.js +1 -1
- package/script/deps/jsr.io/@std/log/0.224.14/console_handler.js +1 -1
- package/script/src/context/Context.d.ts +5 -1
- package/script/src/context/Context.d.ts.map +1 -1
- package/script/src/context/Context.js +15 -4
- package/script/src/context/ContextProvider.d.ts +3 -1
- package/script/src/context/ContextProvider.d.ts.map +1 -1
- package/script/src/context/ContextProvider.js +9 -2
- package/script/src/dsl/http/default.d.ts +2 -0
- package/script/src/dsl/http/default.d.ts.map +1 -1
- package/script/src/dsl/http/default.js +10 -0
- package/script/src/dsl/http/types.d.ts +5 -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/contextcredentials.d.ts +10 -0
- package/script/src/dsl/http/versori/contextcredentials.d.ts.map +1 -0
- package/script/src/dsl/http/versori/contextcredentials.js +2 -0
- package/script/src/dsl/http/versori/credentials/client.d.ts +3 -0
- package/script/src/dsl/http/versori/credentials/client.d.ts.map +1 -1
- package/script/src/dsl/http/versori/credentials/client.js +10 -0
- package/script/src/dsl/http/versori/credentials/credentials.d.ts +38 -0
- package/script/src/dsl/http/versori/credentials/credentials.d.ts.map +1 -1
- package/script/src/dsl/http/versori/credentials/credentials.js +8 -8
- package/script/src/dsl/http/versori/credentials/v1alpha1/common_pb.d.ts +31 -0
- package/script/src/dsl/http/versori/credentials/v1alpha1/common_pb.d.ts.map +1 -0
- package/script/src/dsl/http/versori/credentials/v1alpha1/common_pb.js +34 -0
- package/script/src/dsl/http/versori/credentials/v1alpha1/credential_service_pb.d.ts +84 -0
- package/script/src/dsl/http/versori/credentials/v1alpha1/credential_service_pb.d.ts.map +1 -0
- package/script/src/dsl/http/versori/credentials/v1alpha1/credential_service_pb.js +131 -0
- 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 +38 -6
- package/script/src/dsl/http/versori/roundtripper.d.ts +11 -4
- package/script/src/dsl/http/versori/roundtripper.d.ts.map +1 -1
- package/script/src/dsl/http/versori/roundtripper.js +85 -18
- package/script/src/dsl/tasks/HttpTask.d.ts.map +1 -1
- package/script/src/dsl/tasks/HttpTask.js +1 -1
- package/script/src/interpreter/memory/MemoryInterpreter.d.ts.map +1 -1
- package/script/src/interpreter/memory/MemoryInterpreter.js +10 -2
- package/script/src/observability/logging/ConsoleLogger.d.ts +1 -0
- package/script/src/observability/logging/ConsoleLogger.d.ts.map +1 -1
- package/script/src/observability/logging/ConsoleLogger.js +124 -30
- /package/esm/deps/jsr.io/@std/bytes/{1.0.5 → 1.0.6}/_types.d.ts +0 -0
- /package/esm/deps/jsr.io/@std/bytes/{1.0.5 → 1.0.6}/_types.js +0 -0
- /package/esm/deps/jsr.io/@std/bytes/{1.0.5 → 1.0.6}/concat.js +0 -0
- /package/esm/deps/jsr.io/@std/bytes/{1.0.5 → 1.0.6}/copy.d.ts +0 -0
- /package/esm/deps/jsr.io/@std/bytes/{1.0.5 → 1.0.6}/copy.js +0 -0
- /package/esm/deps/jsr.io/@std/fmt/{1.0.7 → 1.0.8}/colors.d.ts +0 -0
- /package/esm/deps/jsr.io/@std/fmt/{1.0.7 → 1.0.8}/colors.js +0 -0
- /package/script/deps/jsr.io/@std/bytes/{1.0.5 → 1.0.6}/_types.d.ts +0 -0
- /package/script/deps/jsr.io/@std/bytes/{1.0.5 → 1.0.6}/_types.js +0 -0
- /package/script/deps/jsr.io/@std/bytes/{1.0.5 → 1.0.6}/concat.js +0 -0
- /package/script/deps/jsr.io/@std/bytes/{1.0.5 → 1.0.6}/copy.d.ts +0 -0
- /package/script/deps/jsr.io/@std/bytes/{1.0.5 → 1.0.6}/copy.js +0 -0
- /package/script/deps/jsr.io/@std/fmt/{1.0.7 → 1.0.8}/colors.d.ts +0 -0
- /package/script/deps/jsr.io/@std/fmt/{1.0.7 → 1.0.8}/colors.js +0 -0
|
@@ -2,6 +2,7 @@ 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
|
+
import { Credentials } from './contextcredentials.js';
|
|
5
6
|
/**
|
|
6
7
|
* VersoriRoundTripper is an implementation of the RoundTripperFactory interface for Versori connections.
|
|
7
8
|
* This is the intended implementation for when projects/services are hosted on Versori infrastructure.
|
|
@@ -9,28 +10,34 @@ import { Logger } from '../../../observability/logging/Logger.js';
|
|
|
9
10
|
*
|
|
10
11
|
* @example
|
|
11
12
|
* ```typescript
|
|
12
|
-
* const factory = new
|
|
13
|
+
* const factory = new VersoriCredentialsFactory(connectAPIClient, tokenClient);
|
|
13
14
|
* const customFetch = await factory.create('connectionName');
|
|
14
15
|
* const response = await customFetch('https://api.example.com/data');
|
|
15
16
|
* ```
|
|
16
17
|
*/
|
|
17
|
-
export declare class
|
|
18
|
+
export declare class VersoriCredentialsFactory implements RoundTripperFactory {
|
|
18
19
|
private tokenClient;
|
|
20
|
+
private credsBaseURL;
|
|
19
21
|
private platformAPIClient;
|
|
20
22
|
private versoriCfg;
|
|
21
23
|
private log;
|
|
22
24
|
private readonly defaultDynamic;
|
|
23
|
-
constructor(credsClient: VersoriCredentialClient, platformAPIClient: PlatformAPIClient, logger: Logger);
|
|
24
|
-
static fromEnv(logger?: Logger):
|
|
25
|
+
constructor(credsClient: VersoriCredentialClient, credsBaseURL: string, platformAPIClient: PlatformAPIClient, logger: Logger);
|
|
26
|
+
static fromEnv(logger?: Logger): VersoriCredentialsFactory;
|
|
25
27
|
private changeRequestInit;
|
|
26
28
|
private changeBaseUrl;
|
|
27
29
|
create(connName: string, fn?: typeof fetch): Promise<typeof fetch | undefined>;
|
|
28
30
|
createDynamic(templateName: string, fn?: typeof fetch): Promise<DynamicFetcher | undefined>;
|
|
31
|
+
credentials(): Credentials;
|
|
32
|
+
private getTokenByName;
|
|
33
|
+
private getRawByName;
|
|
34
|
+
private getCredentialIDFromName;
|
|
29
35
|
private getConnectionID;
|
|
30
36
|
private getTemplateID;
|
|
31
37
|
private apiKeyFetcher;
|
|
32
38
|
private basicAuthFetcher;
|
|
33
39
|
private bearerTokenFetcher;
|
|
34
40
|
private oauth2Fetcher;
|
|
41
|
+
private getToken;
|
|
35
42
|
}
|
|
36
43
|
//# 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":"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;
|
|
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;AAWlE,OAAO,EAAE,WAAW,EAAS,MAAM,yBAAyB,CAAC;AAE7D;;;;;;;;;;;GAWG;AACH,qBAAa,yBAA0B,YAAW,mBAAmB;IACjE,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;IAWlB,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,EAAE,MAAM,GAAG,yBAAyB;IA6B1D,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,WAAW,IAAI,WAAW;YAOZ,cAAc;YAed,YAAY;YAaZ,uBAAuB;IAkBrC,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,11 +1,12 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.VersoriCredentialsFactory = void 0;
|
|
4
4
|
const configloader_js_1 = require("./configloader.js");
|
|
5
5
|
const mod_js_1 = require("./credentials/mod.js");
|
|
6
6
|
const platformapi_js_1 = require("./platformapi.js");
|
|
7
7
|
const mod_js_2 = require("../../../observability/mod.js");
|
|
8
8
|
const constants_js_1 = require("./constants.js");
|
|
9
|
+
const connect_1 = require("@connectrpc/connect");
|
|
9
10
|
/**
|
|
10
11
|
* VersoriRoundTripper is an implementation of the RoundTripperFactory interface for Versori connections.
|
|
11
12
|
* This is the intended implementation for when projects/services are hosted on Versori infrastructure.
|
|
@@ -13,19 +14,25 @@ const constants_js_1 = require("./constants.js");
|
|
|
13
14
|
*
|
|
14
15
|
* @example
|
|
15
16
|
* ```typescript
|
|
16
|
-
* const factory = new
|
|
17
|
+
* const factory = new VersoriCredentialsFactory(connectAPIClient, tokenClient);
|
|
17
18
|
* const customFetch = await factory.create('connectionName');
|
|
18
19
|
* const response = await customFetch('https://api.example.com/data');
|
|
19
20
|
* ```
|
|
20
21
|
*/
|
|
21
|
-
class
|
|
22
|
-
constructor(credsClient, platformAPIClient, logger) {
|
|
22
|
+
class VersoriCredentialsFactory {
|
|
23
|
+
constructor(credsClient, credsBaseURL, platformAPIClient, logger) {
|
|
23
24
|
Object.defineProperty(this, "tokenClient", {
|
|
24
25
|
enumerable: true,
|
|
25
26
|
configurable: true,
|
|
26
27
|
writable: true,
|
|
27
28
|
value: void 0
|
|
28
29
|
});
|
|
30
|
+
Object.defineProperty(this, "credsBaseURL", {
|
|
31
|
+
enumerable: true,
|
|
32
|
+
configurable: true,
|
|
33
|
+
writable: true,
|
|
34
|
+
value: void 0
|
|
35
|
+
});
|
|
29
36
|
Object.defineProperty(this, "platformAPIClient", {
|
|
30
37
|
enumerable: true,
|
|
31
38
|
configurable: true,
|
|
@@ -56,9 +63,11 @@ class VersoriRoundTripperFactory {
|
|
|
56
63
|
}
|
|
57
64
|
});
|
|
58
65
|
this.tokenClient = credsClient;
|
|
66
|
+
this.credsBaseURL = credsBaseURL;
|
|
59
67
|
this.platformAPIClient = platformAPIClient;
|
|
60
68
|
this.versoriCfg = (0, configloader_js_1.LoadConfigFromFile)();
|
|
61
69
|
this.log = logger;
|
|
70
|
+
this.credentials = this.credentials.bind(this);
|
|
62
71
|
}
|
|
63
72
|
static fromEnv(logger) {
|
|
64
73
|
const credsBaseURL = Deno.env.get(constants_js_1.envVarCredsBaseURL);
|
|
@@ -77,10 +86,10 @@ class VersoriRoundTripperFactory {
|
|
|
77
86
|
missingVars.push(constants_js_1.envVarCredsBaseURL);
|
|
78
87
|
throw new Error(`Missing environment variables: ${missingVars.join(', ')}`);
|
|
79
88
|
}
|
|
80
|
-
const pAPIClient = new platformapi_js_1.PlatformAPIClient(platformApiBaseURL, orgId, envId);
|
|
81
|
-
const tokenClient = new mod_js_1.VersoriCredentialClient(credsBaseURL);
|
|
82
89
|
const log = logger || new mod_js_2.ConsoleLogger('debug');
|
|
83
|
-
|
|
90
|
+
const pAPIClient = new platformapi_js_1.PlatformAPIClient(platformApiBaseURL, orgId, envId, log);
|
|
91
|
+
const tokenClient = new mod_js_1.VersoriCredentialClient(credsBaseURL);
|
|
92
|
+
return new VersoriCredentialsFactory(tokenClient, credsBaseURL, pAPIClient, log);
|
|
84
93
|
}
|
|
85
94
|
// takes the info and modifies the url using changeBaseUrl if necessary
|
|
86
95
|
// if a full valid URL is passed as a string, it will be returned as is
|
|
@@ -118,7 +127,7 @@ class VersoriRoundTripperFactory {
|
|
|
118
127
|
this.log.debug('Using baseURL from connection', { url: newURL.toString() });
|
|
119
128
|
return newURL.toString();
|
|
120
129
|
}
|
|
121
|
-
|
|
130
|
+
create(connName, fn = globalThis.fetch) {
|
|
122
131
|
const cnxId = this.getConnectionID(connName);
|
|
123
132
|
if (!cnxId) {
|
|
124
133
|
this.log.debug('Connection not found in config, could be a dynamic connection', {
|
|
@@ -150,7 +159,7 @@ class VersoriRoundTripperFactory {
|
|
|
150
159
|
};
|
|
151
160
|
return _fn;
|
|
152
161
|
}
|
|
153
|
-
|
|
162
|
+
createDynamic(templateName, fn = globalThis.fetch) {
|
|
154
163
|
const template = this.getTemplateID(templateName);
|
|
155
164
|
if (!template) {
|
|
156
165
|
this.log.debug('Template not found in config, could be a static connection', {
|
|
@@ -183,6 +192,47 @@ class VersoriRoundTripperFactory {
|
|
|
183
192
|
};
|
|
184
193
|
return _fn;
|
|
185
194
|
}
|
|
195
|
+
credentials() {
|
|
196
|
+
return {
|
|
197
|
+
getRaw: this.getRawByName.bind(this),
|
|
198
|
+
getAccessToken: this.getTokenByName.bind(this),
|
|
199
|
+
};
|
|
200
|
+
}
|
|
201
|
+
async getTokenByName(name) {
|
|
202
|
+
const credId = await this.getCredentialIDFromName(name);
|
|
203
|
+
const token = await this.tokenClient.getToken(credId);
|
|
204
|
+
if (!token?.token) {
|
|
205
|
+
throw new Error(`Token not found for connection ${name} with credential ID ${credId}`);
|
|
206
|
+
}
|
|
207
|
+
return {
|
|
208
|
+
accessToken: token.token.accessToken,
|
|
209
|
+
tokenType: token.token.tokenType,
|
|
210
|
+
expiry: token.token.expiry ? new Date(Number(token.token.expiry.seconds) * 1000) : undefined,
|
|
211
|
+
};
|
|
212
|
+
}
|
|
213
|
+
async getRawByName(name) {
|
|
214
|
+
const credId = await this.getCredentialIDFromName(name);
|
|
215
|
+
const raw = await this.tokenClient.getRaw(credId);
|
|
216
|
+
if (!raw) {
|
|
217
|
+
throw new Error(`Raw data not found for connection ${name} with credential ID ${credId}`);
|
|
218
|
+
}
|
|
219
|
+
let buffer = raw?.credential?.data['raw'];
|
|
220
|
+
return buffer;
|
|
221
|
+
}
|
|
222
|
+
async getCredentialIDFromName(name) {
|
|
223
|
+
const conId = this.getConnectionID(name);
|
|
224
|
+
if (!conId) {
|
|
225
|
+
throw new Error(`Connection ${name} not found`);
|
|
226
|
+
}
|
|
227
|
+
const conn = await this.platformAPIClient.getStaticConnection(conId);
|
|
228
|
+
if (!conn) {
|
|
229
|
+
throw new Error(`Connection ${name} not found`);
|
|
230
|
+
}
|
|
231
|
+
if (!conn?.credentials[0]?.credential?.id) {
|
|
232
|
+
throw new Error(`Connection ${name}/${conId} has no credentials defined on it`);
|
|
233
|
+
}
|
|
234
|
+
return conn.credentials[0].credential.id;
|
|
235
|
+
}
|
|
186
236
|
getConnectionID(connName) {
|
|
187
237
|
const conn = this.versoriCfg.mappings.find((c) => (c.dynamic === undefined || c.dynamic === false) &&
|
|
188
238
|
c.name.toLowerCase() === connName.toLowerCase());
|
|
@@ -198,9 +248,9 @@ class VersoriRoundTripperFactory {
|
|
|
198
248
|
}
|
|
199
249
|
return template.templateId;
|
|
200
250
|
}
|
|
201
|
-
|
|
251
|
+
apiKeyFetcher(conn, fn) {
|
|
202
252
|
const _fn = async (input, init) => {
|
|
203
|
-
const tokenResponse = await this.
|
|
253
|
+
const tokenResponse = await this.getToken(conn.credentials[0].credential.id);
|
|
204
254
|
const token = tokenResponse.token?.accessToken;
|
|
205
255
|
const asc = conn.credentials[0].authSchemeConfig.apiKey;
|
|
206
256
|
if (!token) {
|
|
@@ -246,9 +296,9 @@ class VersoriRoundTripperFactory {
|
|
|
246
296
|
};
|
|
247
297
|
return _fn;
|
|
248
298
|
}
|
|
249
|
-
|
|
299
|
+
basicAuthFetcher(conn, fn) {
|
|
250
300
|
const _fn = async (input, init) => {
|
|
251
|
-
const tokenResponse = await this.
|
|
301
|
+
const tokenResponse = await this.getToken(conn.credentials[0].credential.id);
|
|
252
302
|
const token = tokenResponse.token?.accessToken;
|
|
253
303
|
if (!token) {
|
|
254
304
|
throw new Error('Token not found');
|
|
@@ -276,9 +326,9 @@ class VersoriRoundTripperFactory {
|
|
|
276
326
|
return _fn;
|
|
277
327
|
}
|
|
278
328
|
// TODO: need to make the prefix and header name configurable from authschemeconfig
|
|
279
|
-
|
|
329
|
+
bearerTokenFetcher(conn, fn) {
|
|
280
330
|
const _fn = async (input, init) => {
|
|
281
|
-
const tokenResponse = await this.
|
|
331
|
+
const tokenResponse = await this.getToken(conn.credentials[0].credential.id);
|
|
282
332
|
const token = tokenResponse.token?.accessToken;
|
|
283
333
|
if (!token) {
|
|
284
334
|
throw new Error('Token not found');
|
|
@@ -305,9 +355,9 @@ class VersoriRoundTripperFactory {
|
|
|
305
355
|
};
|
|
306
356
|
return _fn;
|
|
307
357
|
}
|
|
308
|
-
|
|
358
|
+
oauth2Fetcher(conn, fn) {
|
|
309
359
|
const refreshFn = async (input, init, forceRefresh = false) => {
|
|
310
|
-
const tokenResponse = await this.
|
|
360
|
+
const tokenResponse = await this.getToken(conn.credentials[0].credential.id, forceRefresh);
|
|
311
361
|
const token = tokenResponse.token?.accessToken;
|
|
312
362
|
const tokenType = tokenResponse.token?.tokenType;
|
|
313
363
|
if (!token) {
|
|
@@ -360,8 +410,25 @@ class VersoriRoundTripperFactory {
|
|
|
360
410
|
};
|
|
361
411
|
return _fn;
|
|
362
412
|
}
|
|
413
|
+
async getToken(id) {
|
|
414
|
+
try {
|
|
415
|
+
return await this.tokenClient.getToken(id);
|
|
416
|
+
}
|
|
417
|
+
catch (error) {
|
|
418
|
+
this.log.error('unable to get credential', { error });
|
|
419
|
+
if (error instanceof connect_1.ConnectError) {
|
|
420
|
+
if (error.rawMessage.includes("connection error received: not a result of an error") && error.code === connect_1.Code.Internal) {
|
|
421
|
+
this.log.info('Connection error received, attempting to reconnect');
|
|
422
|
+
this.tokenClient = new mod_js_1.VersoriCredentialClient(this.credsBaseURL);
|
|
423
|
+
return await this.tokenClient.getToken(id);
|
|
424
|
+
}
|
|
425
|
+
throw error;
|
|
426
|
+
}
|
|
427
|
+
throw error;
|
|
428
|
+
}
|
|
429
|
+
}
|
|
363
430
|
}
|
|
364
|
-
exports.
|
|
431
|
+
exports.VersoriCredentialsFactory = VersoriCredentialsFactory;
|
|
365
432
|
function isValidURL(url) {
|
|
366
433
|
try {
|
|
367
434
|
new URL(url);
|
|
@@ -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,CAA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A0B;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;IAmB3B,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.options);
|
|
69
|
+
super(ctx.log, internalCtx.kvp, ctx.creds, ctx.executionId, ctx.startTime, ctx.data, ctx.options);
|
|
70
70
|
Object.defineProperty(this, "connectionVariables", {
|
|
71
71
|
enumerable: true,
|
|
72
72
|
configurable: true,
|
|
@@ -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","s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BAAmB;IACpC,OAAO,CAAC,QAAQ,CAAC,MAAM;IACvB,OAAO,CAAC,YAAY;IACpB,OAAO,CAAC,QAAQ,CAAC,kBAAkB;IACnC,OAAO,CAAC,QAAQ,CAAC,YAAY;IAbjC,OAAO,CAAC,mBAAmB,CAA2B;IACtD,OAAO,CAAC,MAAM,CAAC,CAAS;IACxB,OAAO,CAAC,cAAc,CAAC,CAAa;IACpC,OAAO,CAAC,cAAc,CAAS;gBAGV,GAAG,EAAE,MAAM,EACX,QAAQ,EAAE,kBAAkB,EAC5B,eAAe,EAAE,eAAe,EAChC,mBAAmB,EAAE,mBAAmB,EACxC,MAAM,EAAE,MAAM,EACvB,YAAY,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,EACxB,kBAAkB,EAAE,kBAAkB,EACtC,YAAY,EAAE,YAAY;WASlC,WAAW,CAAC,OAAO,GAAE,wBAA6B,GAAG,OAAO,CAAC,iBAAiB,CAAC;IAwC5F,QAAQ,CAAC,CAAC,EAAE,QAAQ,EAAE,QAAQ,CAAC,CAAC,CAAC,EAAE,OAAO,CAAC,EAAE,wBAAwB;IA8C/D,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;IAoJtB,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC;CAK9B"}
|
|
@@ -4,6 +4,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.MemoryInterpreter = void 0;
|
|
7
|
+
const express_xml_bodyparser_1 = __importDefault(require("express-xml-bodyparser"));
|
|
7
8
|
const express_1 = __importDefault(require("express"));
|
|
8
9
|
const rxjs_1 = require("rxjs");
|
|
9
10
|
const ContextProvider_js_1 = require("../../context/ContextProvider.js");
|
|
@@ -101,7 +102,7 @@ class MemoryInterpreter {
|
|
|
101
102
|
const compiler = options.compiler || new ObservableCompiler_js_1.ObservableCompiler();
|
|
102
103
|
const roundTripperFactory = options.skipVersoriCredentials
|
|
103
104
|
? new default_js_1.DefaultRoundTripperFactory()
|
|
104
|
-
: roundtripper_js_1.
|
|
105
|
+
: roundtripper_js_1.VersoriCredentialsFactory.fromEnv(log);
|
|
105
106
|
if (options.contextProvider) {
|
|
106
107
|
// no need to set up a key-value provider if options.contextProvider is already
|
|
107
108
|
// initialised.
|
|
@@ -110,7 +111,7 @@ class MemoryInterpreter {
|
|
|
110
111
|
const kvp = await (options.skipVersoriCredentials
|
|
111
112
|
? new MemoryKeyValueProvider_js_1.MemoryKeyValueProvider()
|
|
112
113
|
: NatsKeyValueProvider_js_1.NatsKeyValueProvider.fromEnv());
|
|
113
|
-
return new MemoryInterpreter(log, compiler, new ContextProvider_js_1.ContextProviderImpl(log, kvp), roundTripperFactory, express_1.default.Router(), new Map(), platformapi_js_1.PlatformAPIClient.fromEnv(), cronapi_js_1.CronAPIClient.fromEnv());
|
|
114
|
+
return new MemoryInterpreter(log, compiler, new ContextProvider_js_1.ContextProviderImpl(log, kvp, roundTripperFactory.credentials()), roundTripperFactory, express_1.default.Router(), new Map(), platformapi_js_1.PlatformAPIClient.fromEnv(), cronapi_js_1.CronAPIClient.fromEnv());
|
|
114
115
|
}
|
|
115
116
|
register(workflow, options) {
|
|
116
117
|
const localAbortController = new AbortController();
|
|
@@ -148,6 +149,13 @@ class MemoryInterpreter {
|
|
|
148
149
|
const port = Deno.env.get('PORT') || 3000;
|
|
149
150
|
const app = (0, express_1.default)();
|
|
150
151
|
app.use(express_1.default.json()); // Add JSON body parser middleware
|
|
152
|
+
const xml2jsDefaults = {
|
|
153
|
+
explicitArray: false,
|
|
154
|
+
normalize: false,
|
|
155
|
+
normalizeTags: false,
|
|
156
|
+
trim: true,
|
|
157
|
+
};
|
|
158
|
+
app.use((0, express_xml_bodyparser_1.default)(xml2jsDefaults));
|
|
151
159
|
// Add health check route
|
|
152
160
|
this.router.get("/health", (_req, res) => {
|
|
153
161
|
res.json({ status: "healthy" });
|
|
@@ -10,6 +10,7 @@ export declare class ConsoleLogger implements Logger {
|
|
|
10
10
|
constructor(level: LogLevel, fields?: Record<string, unknown>);
|
|
11
11
|
debug(message: string, fields?: Record<string, unknown>): void;
|
|
12
12
|
info(message: string, fields?: Record<string, unknown>): void;
|
|
13
|
+
error(message: string, err?: Error, fields?: Record<string, unknown>): void;
|
|
13
14
|
error(message: string, fields?: Record<string, unknown>): void;
|
|
14
15
|
child(fields: {
|
|
15
16
|
[key: string]: string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ConsoleLogger.d.ts","sourceRoot":"","sources":["../../../../src/src/observability/logging/ConsoleLogger.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,GAAG,MAAM,+CAA+C,CAAC;AACrE,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;
|
|
1
|
+
{"version":3,"file":"ConsoleLogger.d.ts","sourceRoot":"","sources":["../../../../src/src/observability/logging/ConsoleLogger.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,GAAG,MAAM,+CAA+C,CAAC;AACrE,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AAqM/C;;GAEG;AACH,qBAAa,aAAc,YAAW,MAAM;IACxC,GAAG,EAAE,GAAG,CAAC,MAAM,CAAC;IAEhB,KAAK,EAAE,QAAQ,CAAC;IAEhB,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;gBAEpB,KAAK,EAAE,QAAQ,EAAE,MAAM,GAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAM;IAOjE,KAAK,CAAC,OAAO,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,IAAI;IAO9D,IAAI,CAAC,OAAO,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,IAAI;IAO7D,KAAK,CAAC,OAAO,EAAE,MAAM,EAAE,GAAG,CAAC,EAAE,KAAK,EAAE,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,IAAI;IAC3E,KAAK,CAAC,OAAO,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,IAAI;IAsB9D,KAAK,CAAC,MAAM,EAAE;QAAE,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAAA;KAAE,GAAG,aAAa;IAOvD,QAAQ,CAAC,KAAK,EAAE,QAAQ,GAAG,IAAI;CAGlC"}
|
|
@@ -25,41 +25,132 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
25
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
26
|
exports.ConsoleLogger = void 0;
|
|
27
27
|
const log = __importStar(require("../../../deps/jsr.io/@std/log/0.224.14/mod.js"));
|
|
28
|
-
function
|
|
29
|
-
|
|
28
|
+
function isObjectLiteral(obj) {
|
|
29
|
+
return Object.getPrototypeOf(obj) === Object.prototype;
|
|
30
|
+
}
|
|
31
|
+
function formatError(err) {
|
|
32
|
+
if (Symbol.toPrimitive in err) {
|
|
33
|
+
const toPrimitive = err[Symbol.toPrimitive];
|
|
34
|
+
if (typeof toPrimitive === 'function') {
|
|
35
|
+
return toPrimitive();
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
const ret = {
|
|
39
|
+
error: err.message,
|
|
40
|
+
};
|
|
41
|
+
if (err.cause) {
|
|
42
|
+
if (err.cause instanceof Error) {
|
|
43
|
+
ret.cause = formatError(err.cause);
|
|
44
|
+
}
|
|
45
|
+
else {
|
|
46
|
+
// potential place to Deno.inspect?
|
|
47
|
+
ret.cause = formatArg(err.cause);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
if (err.stack) {
|
|
51
|
+
ret.stacktrace = err.stack;
|
|
52
|
+
}
|
|
53
|
+
return ret;
|
|
54
|
+
}
|
|
55
|
+
// deno-lint-ignore ban-types
|
|
56
|
+
function formatFunction(fn) {
|
|
57
|
+
const str = fn.toString();
|
|
58
|
+
return {
|
|
59
|
+
[`<fn:${fn.name}>`]: str.length > 40 ? `${str.substring(0, 40)}...` : str,
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
function formatArg(arg, nested = false) {
|
|
63
|
+
switch (typeof arg) {
|
|
30
64
|
case 'object':
|
|
31
|
-
if (
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
65
|
+
if (arg === null) {
|
|
66
|
+
return null;
|
|
67
|
+
}
|
|
68
|
+
if (Array.isArray(arg)) {
|
|
69
|
+
return arg.map((arg) => formatArg(arg));
|
|
70
|
+
}
|
|
71
|
+
if (arg instanceof Date) {
|
|
72
|
+
return arg.toISOString();
|
|
73
|
+
}
|
|
74
|
+
if (Symbol.toPrimitive in arg) {
|
|
75
|
+
const toPrimitive = arg[Symbol.toPrimitive];
|
|
76
|
+
if (typeof toPrimitive === 'function') {
|
|
77
|
+
return toPrimitive();
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
if (arg instanceof Error) {
|
|
81
|
+
if (nested) {
|
|
82
|
+
return formatError(arg);
|
|
35
83
|
}
|
|
36
|
-
return
|
|
37
|
-
[`arg${idx}`]: obj,
|
|
38
|
-
};
|
|
84
|
+
return arg;
|
|
39
85
|
}
|
|
40
|
-
if (
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
86
|
+
if (isObjectLiteral(arg)) {
|
|
87
|
+
// object literal or directly created by `new Object()`, not subclasses of Object.
|
|
88
|
+
return Object.entries(arg).reduce((acc, [key, value]) => ({
|
|
89
|
+
...acc,
|
|
90
|
+
[key]: formatArg(value, true),
|
|
91
|
+
}), {});
|
|
44
92
|
}
|
|
45
|
-
return
|
|
93
|
+
return Deno.inspect(arg);
|
|
46
94
|
case 'undefined':
|
|
47
|
-
return
|
|
48
|
-
[`arg${idx}`]: undefined,
|
|
49
|
-
};
|
|
95
|
+
return '<undefined>';
|
|
50
96
|
case 'function':
|
|
51
|
-
return
|
|
52
|
-
[`arg${idx}`]: obj.valueOf(),
|
|
53
|
-
};
|
|
97
|
+
return formatFunction(arg);
|
|
54
98
|
default:
|
|
55
|
-
return
|
|
56
|
-
|
|
57
|
-
|
|
99
|
+
return arg;
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
function formatArgs(args) {
|
|
103
|
+
if (args.length === 0) {
|
|
104
|
+
return {};
|
|
105
|
+
}
|
|
106
|
+
if (args.length === 1) {
|
|
107
|
+
const formatted = formatArg(args[0]);
|
|
108
|
+
if (formatted instanceof Error) {
|
|
109
|
+
return formatError(formatted);
|
|
110
|
+
}
|
|
111
|
+
if (typeof formatted === 'object' && formatted !== null) {
|
|
112
|
+
return formatted;
|
|
113
|
+
}
|
|
114
|
+
return {
|
|
115
|
+
arg0: formatted,
|
|
116
|
+
};
|
|
117
|
+
}
|
|
118
|
+
const errors = [];
|
|
119
|
+
const others = [];
|
|
120
|
+
for (const arg of args) {
|
|
121
|
+
const formatted = formatArgs([arg]);
|
|
122
|
+
if (arg instanceof Error) {
|
|
123
|
+
// formatted isn't an instanceof Error after `formatArgs()`, so check original `arg`.
|
|
124
|
+
errors.push(formatted);
|
|
125
|
+
}
|
|
126
|
+
else {
|
|
127
|
+
others.push(formatted);
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
const othersMerged = others.length === 1
|
|
131
|
+
? others[0]
|
|
132
|
+
: others.reduce((acc, value, idx) => ({
|
|
133
|
+
...acc,
|
|
134
|
+
[`arg${idx}`]: value,
|
|
135
|
+
}), {});
|
|
136
|
+
if (errors.length === 1) {
|
|
137
|
+
return {
|
|
138
|
+
...othersMerged,
|
|
139
|
+
// if there's only one error, we want to splat 'error', 'cause' and 'stacktrace' over
|
|
140
|
+
// all other merged fields.
|
|
141
|
+
...errors[0],
|
|
142
|
+
};
|
|
58
143
|
}
|
|
144
|
+
return {
|
|
145
|
+
...othersMerged,
|
|
146
|
+
// array of errors.
|
|
147
|
+
errors: errors,
|
|
148
|
+
};
|
|
59
149
|
}
|
|
60
150
|
log.setup({
|
|
61
151
|
handlers: {
|
|
62
152
|
default: new log.ConsoleHandler('DEBUG', {
|
|
153
|
+
useColors: false,
|
|
63
154
|
formatter: (record) => {
|
|
64
155
|
// log.formatters.jsonFormatter bugs me:
|
|
65
156
|
// - time is in unix milliseconds
|
|
@@ -72,12 +163,7 @@ log.setup({
|
|
|
72
163
|
time: record.datetime.toISOString(),
|
|
73
164
|
...(record.loggerName ? { name: record.loggerName } : {}),
|
|
74
165
|
msg: record.msg,
|
|
75
|
-
...(
|
|
76
|
-
? (record.args.reduce((acc, next, idx) => ({
|
|
77
|
-
...acc,
|
|
78
|
-
...(valueOfUnknown(next, idx)),
|
|
79
|
-
}), {}))
|
|
80
|
-
: {}),
|
|
166
|
+
...formatArgs(record.args),
|
|
81
167
|
});
|
|
82
168
|
}
|
|
83
169
|
catch (err) {
|
|
@@ -138,9 +224,17 @@ class ConsoleLogger {
|
|
|
138
224
|
...fields,
|
|
139
225
|
});
|
|
140
226
|
}
|
|
141
|
-
error(message, fields) {
|
|
227
|
+
error(message, fieldsOrError, fields) {
|
|
228
|
+
if (fieldsOrError instanceof Error) {
|
|
229
|
+
this.log.error(message, fieldsOrError, {
|
|
230
|
+
...this.fields,
|
|
231
|
+
...fields,
|
|
232
|
+
});
|
|
233
|
+
return;
|
|
234
|
+
}
|
|
142
235
|
this.log.error(message, {
|
|
143
236
|
...this.fields,
|
|
237
|
+
...fieldsOrError,
|
|
144
238
|
...fields,
|
|
145
239
|
});
|
|
146
240
|
}
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|