@intuned/runtime-dev 0.1.0-test.21 → 0.1.0-test.22
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/WebTemplate/controllers/authSessions/check.ts +2 -1
- package/WebTemplate/controllers/authSessions/create.ts +2 -1
- package/WebTemplate/controllers/runApi/helpers.ts +2 -1
- package/dist/commands/api/run.js +3 -5
- package/dist/commands/auth-sessions/run-check.js +3 -3
- package/dist/commands/auth-sessions/run-create.js +3 -3
- package/dist/commands/interface/run.js +3 -11
- package/dist/common/runApi/index.d.ts +1 -1
- package/dist/common/runApi/index.js +33 -20
- package/dist/common/runApi/types.d.ts +6 -19
- package/dist/common/runApi/types.js +1 -5
- package/package.json +1 -1
|
@@ -33,7 +33,7 @@ export async function checkAuthSession({
|
|
|
33
33
|
|
|
34
34
|
const result = await runApi<boolean>({
|
|
35
35
|
automationFunction: {
|
|
36
|
-
|
|
36
|
+
name: "auth-sessions/check",
|
|
37
37
|
},
|
|
38
38
|
runOptions: {
|
|
39
39
|
environment: "deployed",
|
|
@@ -47,6 +47,7 @@ export async function checkAuthSession({
|
|
|
47
47
|
},
|
|
48
48
|
runCheck: false,
|
|
49
49
|
},
|
|
50
|
+
importFunction: importModule,
|
|
50
51
|
});
|
|
51
52
|
if (result.isErr()) {
|
|
52
53
|
return result.error.apiResponse;
|
|
@@ -53,7 +53,7 @@ export async function createAuthSession({
|
|
|
53
53
|
unknown
|
|
54
54
|
>({
|
|
55
55
|
automationFunction: {
|
|
56
|
-
|
|
56
|
+
name: "auth-sessions/create",
|
|
57
57
|
params: parameters,
|
|
58
58
|
},
|
|
59
59
|
tracing: saveTrace
|
|
@@ -69,6 +69,7 @@ export async function createAuthSession({
|
|
|
69
69
|
},
|
|
70
70
|
abortSignal: abortController.signal,
|
|
71
71
|
retrieveSession: true,
|
|
72
|
+
importFunction: importModule,
|
|
72
73
|
});
|
|
73
74
|
|
|
74
75
|
const result = await createGenerator.next();
|
|
@@ -68,7 +68,7 @@ export async function runApi({
|
|
|
68
68
|
const resultWithTimeout = await waitWithExtendableTimeout({
|
|
69
69
|
promise: runApiInternal({
|
|
70
70
|
automationFunction: {
|
|
71
|
-
|
|
71
|
+
name: `api/${functionName}`,
|
|
72
72
|
params,
|
|
73
73
|
},
|
|
74
74
|
auth: isAuthSessionEnabled
|
|
@@ -93,6 +93,7 @@ export async function runApi({
|
|
|
93
93
|
: { enabled: false },
|
|
94
94
|
functionsToken,
|
|
95
95
|
abortSignal: abortController.signal,
|
|
96
|
+
importFunction: importModule,
|
|
96
97
|
}),
|
|
97
98
|
initialTimeout: requestTimeout,
|
|
98
99
|
abortController,
|
package/dist/commands/api/run.js
CHANGED
|
@@ -17,7 +17,6 @@ var _nanoid = require("nanoid");
|
|
|
17
17
|
var _chalk = _interopRequireDefault(require("chalk"));
|
|
18
18
|
var _runApi = require("../../common/runApi");
|
|
19
19
|
var _tsNodeImport = require("../common/tsNodeImport");
|
|
20
|
-
var _fileUtils = require("../common/utils/fileUtils");
|
|
21
20
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
22
21
|
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
|
|
23
22
|
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
|
|
@@ -38,11 +37,9 @@ async function executeCLI(apiName, mode, inputData, options) {
|
|
|
38
37
|
throw new Error("Auth session is not enabled but auth session provided. To use auth session please enable it in Intuned.json");
|
|
39
38
|
}
|
|
40
39
|
}
|
|
41
|
-
const apiFilePath = (0, _fileUtils.getFullPathInProject)("api", `${apiName}.ts`);
|
|
42
|
-
const runApiModule = await (0, _tsNodeImport.tsNodeImport)(apiFilePath);
|
|
43
40
|
const runApiResult = await (0, _runApi.runApi)({
|
|
44
41
|
automationFunction: {
|
|
45
|
-
|
|
42
|
+
name: `api/${apiName}`,
|
|
46
43
|
params: inputData
|
|
47
44
|
},
|
|
48
45
|
auth: authSessionPathToUse ? {
|
|
@@ -56,7 +53,8 @@ async function executeCLI(apiName, mode, inputData, options) {
|
|
|
56
53
|
environment: "ide",
|
|
57
54
|
cdpAddress: options.cdpAddress,
|
|
58
55
|
mode
|
|
59
|
-
}
|
|
56
|
+
},
|
|
57
|
+
importFunction: _tsNodeImport.tsNodeImport
|
|
60
58
|
});
|
|
61
59
|
if (runApiResult.isErr()) {
|
|
62
60
|
if (runApiResult.error instanceof _runApi.AutomationError) {
|
|
@@ -27,10 +27,9 @@ _commander.program.description("run auth session check").option("--cdpAddress <c
|
|
|
27
27
|
if (!fs.exists(checkFilePath)) {
|
|
28
28
|
throw new Error("auth session check file not found");
|
|
29
29
|
}
|
|
30
|
-
const checkModule = await (0, _tsNodeImport.tsNodeImport)(checkFilePath);
|
|
31
30
|
const runApiResult = await (0, _runApi.runApi)({
|
|
32
31
|
automationFunction: {
|
|
33
|
-
|
|
32
|
+
name: `${_constants.AUTH_SESSIONS_FOLDER_NAME}/check`
|
|
34
33
|
},
|
|
35
34
|
runOptions: {
|
|
36
35
|
environment: "ide",
|
|
@@ -43,7 +42,8 @@ _commander.program.description("run auth session check").option("--cdpAddress <c
|
|
|
43
42
|
path: authSessionPath
|
|
44
43
|
},
|
|
45
44
|
runCheck: false
|
|
46
|
-
}
|
|
45
|
+
},
|
|
46
|
+
importFunction: _tsNodeImport.tsNodeImport
|
|
47
47
|
});
|
|
48
48
|
if (runApiResult.isErr()) {
|
|
49
49
|
throw new Error(runApiResult.error);
|
|
@@ -41,11 +41,10 @@ _commander.program.description("run auth session create").option("--cdpAddress <
|
|
|
41
41
|
if (!fs.exists(createFilePath)) {
|
|
42
42
|
throw new Error("auth session create file not found");
|
|
43
43
|
}
|
|
44
|
-
const createModule = await (0, _tsNodeImport.tsNodeImport)(createFilePath);
|
|
45
44
|
async function runCreate() {
|
|
46
45
|
const generator = (0, _runApi.runApiGenerator)({
|
|
47
46
|
automationFunction: {
|
|
48
|
-
|
|
47
|
+
name: `${_constants.AUTH_SESSIONS_FOLDER_NAME}/create`,
|
|
49
48
|
params: inputData
|
|
50
49
|
},
|
|
51
50
|
runOptions: {
|
|
@@ -53,7 +52,8 @@ _commander.program.description("run auth session create").option("--cdpAddress <
|
|
|
53
52
|
mode,
|
|
54
53
|
cdpAddress
|
|
55
54
|
},
|
|
56
|
-
retrieveSession: true
|
|
55
|
+
retrieveSession: true,
|
|
56
|
+
importFunction: _tsNodeImport.tsNodeImport
|
|
57
57
|
});
|
|
58
58
|
let nextGeneratorParam = undefined;
|
|
59
59
|
while (true) {
|
|
@@ -11,17 +11,12 @@ var _enums = require("src/runtime/enums");
|
|
|
11
11
|
var _unixSocket = require("../common/utils/unixSocket");
|
|
12
12
|
var _promises = require("timers/promises");
|
|
13
13
|
var _jwtTokenManager = require("src/common/jwtTokenManager");
|
|
14
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
15
14
|
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
|
|
16
15
|
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
|
|
16
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
17
17
|
const startRunApiSchema = _zod.default.object({
|
|
18
18
|
type: _zod.default.literal("start"),
|
|
19
19
|
parameters: _runApi.runApiParametersSchema.extend({
|
|
20
|
-
automationFunction: _runApi.runApiParametersSchema.shape.automationFunction.omit({
|
|
21
|
-
module: true
|
|
22
|
-
}).extend({
|
|
23
|
-
name: _zod.default.string()
|
|
24
|
-
}),
|
|
25
20
|
retrieveSession: _zod.default.boolean(),
|
|
26
21
|
context: _zod.default.object({
|
|
27
22
|
jobId: _zod.default.string().optional(),
|
|
@@ -127,11 +122,8 @@ function main(importFunction) {
|
|
|
127
122
|
if (input.type === "start") {
|
|
128
123
|
const gen = (0, _runApi.runApiGenerator)({
|
|
129
124
|
...input.parameters,
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
module: importFunction ? await importFunction(input.parameters.automationFunction.name) : await (specifier => new Promise(r => r(`${specifier}`)).then(s => _interopRequireWildcard(require(s))))(input.parameters.automationFunction.name)
|
|
133
|
-
},
|
|
134
|
-
abortSignal: abortController.signal
|
|
125
|
+
abortSignal: abortController.signal,
|
|
126
|
+
importFunction
|
|
135
127
|
});
|
|
136
128
|
generator = gen;
|
|
137
129
|
context = {
|
|
@@ -9,4 +9,4 @@ export declare function runApiGenerator<ResultType = any, _YieldType = any, _Nex
|
|
|
9
9
|
}): AsyncGenerator<_YieldType, RunApiResult<ResultType, RunApiResultWithSessionOk>, _NextType>;
|
|
10
10
|
export declare function runApiGenerator<ResultType = any, _YieldType = any, _NextType = any>(params: ExtendedRunApiParameters): AsyncGenerator<_YieldType, RunApiResult<ResultType>, _NextType>;
|
|
11
11
|
export declare function runApi<ResultType = any>(params: ExtendedRunApiParameters): Promise<RunApiResult<ResultType>>;
|
|
12
|
-
export declare function checkAuthSessionWithRetries(page: Page, context: BrowserContext, retries?: number): Promise<Result<boolean, RunAutomationError>>;
|
|
12
|
+
export declare function checkAuthSessionWithRetries(page: Page, context: BrowserContext, importFunction: ExtendedRunApiParameters["importFunction"], retries?: number): Promise<Result<boolean, RunAutomationError>>;
|
|
@@ -49,6 +49,7 @@ function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e;
|
|
|
49
49
|
async function* runApiGenerator({
|
|
50
50
|
retrieveSession = false,
|
|
51
51
|
abortSignal,
|
|
52
|
+
importFunction,
|
|
52
53
|
...input
|
|
53
54
|
}) {
|
|
54
55
|
let traceStarted = false;
|
|
@@ -131,7 +132,7 @@ async function* runApiGenerator({
|
|
|
131
132
|
return (0, _neverthrow.err)(new _errors.AuthRequiredError());
|
|
132
133
|
}
|
|
133
134
|
console.log("Running auth check");
|
|
134
|
-
const authCheckResult = await checkAuthSessionWithRetries(page, context, 2);
|
|
135
|
+
const authCheckResult = await checkAuthSessionWithRetries(page, context, importFunction, 2);
|
|
135
136
|
if (authCheckResult.isErr()) {
|
|
136
137
|
const error = authCheckResult.error;
|
|
137
138
|
if (["APINotFoundError", "InvalidAPIError"].includes(error.code)) {
|
|
@@ -144,7 +145,7 @@ async function* runApiGenerator({
|
|
|
144
145
|
}
|
|
145
146
|
}
|
|
146
147
|
const args = [...(automationFunction.params ? [automationFunction.params] : []), page, context];
|
|
147
|
-
const validatedModuleResult = await
|
|
148
|
+
const validatedModuleResult = await importUsingImportFunction(automationFunction.name, importFunction);
|
|
148
149
|
if (validatedModuleResult.isErr()) {
|
|
149
150
|
return validatedModuleResult;
|
|
150
151
|
}
|
|
@@ -206,13 +207,13 @@ async function runApi(params) {
|
|
|
206
207
|
}
|
|
207
208
|
return (0, _neverthrow.err)(new _errors.InvalidApiError("Expected API to be async function, got async generator"));
|
|
208
209
|
}
|
|
209
|
-
async function checkAuthSessionWithRetries(page, context, retries = 3) {
|
|
210
|
+
async function checkAuthSessionWithRetries(page, context, importFunction, retries = 3) {
|
|
210
211
|
if (retries === 0) {
|
|
211
212
|
return (0, _neverthrow.ok)(false);
|
|
212
213
|
}
|
|
213
214
|
let tryNumber = 0;
|
|
214
215
|
console.log("Checking auth session with retries", `${_constants.AUTH_SESSIONS_FOLDER_NAME}/check`);
|
|
215
|
-
const importResult = await
|
|
216
|
+
const importResult = await importUsingImportFunction(`${_constants.AUTH_SESSIONS_FOLDER_NAME}/check`, importFunction);
|
|
216
217
|
if (importResult.isErr()) {
|
|
217
218
|
return (0, _neverthrow.err)(importResult.error);
|
|
218
219
|
}
|
|
@@ -227,21 +228,33 @@ async function checkAuthSessionWithRetries(page, context, retries = 3) {
|
|
|
227
228
|
}
|
|
228
229
|
return (0, _neverthrow.ok)(false);
|
|
229
230
|
}
|
|
230
|
-
async function
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
231
|
+
async function importUsingImportFunction(path, importFunction) {
|
|
232
|
+
try {
|
|
233
|
+
const imported = importFunction ? await importFunction(path) : await (specifier => new Promise(r => r(`${specifier}`)).then(s => _interopRequireWildcard(require(s))))(path);
|
|
234
|
+
if (!imported || !imported.default || !imported.default.constructor) {
|
|
235
|
+
return (0, _neverthrow.err)(new _errors.InvalidApiError("API file path does not have a default export"));
|
|
236
|
+
}
|
|
237
|
+
if (imported.default.constructor.name === "AsyncGeneratorFunction") {
|
|
238
|
+
return (0, _neverthrow.ok)({
|
|
239
|
+
type: "async-generator",
|
|
240
|
+
generator: imported.default
|
|
241
|
+
});
|
|
242
|
+
}
|
|
243
|
+
if (imported.default.constructor.name === "AsyncFunction") {
|
|
244
|
+
return (0, _neverthrow.ok)({
|
|
245
|
+
type: "async",
|
|
246
|
+
func: imported.default
|
|
247
|
+
});
|
|
248
|
+
}
|
|
249
|
+
return (0, _neverthrow.err)(new _errors.InvalidApiError("API file path does not have a default async function/generator export"));
|
|
250
|
+
} catch (error) {
|
|
251
|
+
if (error.message.includes("Unknown variable dynamic import")) {
|
|
252
|
+
return (0, _neverthrow.err)(new _errors.ApiNotFoundError(path));
|
|
253
|
+
}
|
|
254
|
+
if ((error === null || error === void 0 ? void 0 : error.code) === "ERR_MODULE_NOT_FOUND") {
|
|
255
|
+
console.log("API not found", error);
|
|
256
|
+
return (0, _neverthrow.err)(new _errors.ApiNotFoundError(path));
|
|
257
|
+
}
|
|
258
|
+
throw error;
|
|
245
259
|
}
|
|
246
|
-
return (0, _neverthrow.err)(new _errors.InvalidApiError(`API file path does not have a default async function/generator export. Got ${moduleToValidate.default.constructor.name}`));
|
|
247
260
|
}
|
|
@@ -127,23 +127,13 @@ export declare const runApiSessionSchema: z.ZodDiscriminatedUnion<"type", [z.Zod
|
|
|
127
127
|
export declare const runApiParametersSchema: z.ZodObject<{
|
|
128
128
|
functionsToken: z.ZodOptional<z.ZodString>;
|
|
129
129
|
automationFunction: z.ZodObject<{
|
|
130
|
-
|
|
131
|
-
default: z.ZodFunction<z.ZodTuple<[], z.ZodUnknown>, z.ZodUnknown>;
|
|
132
|
-
}, "strip", z.ZodTypeAny, {
|
|
133
|
-
default: (...args: unknown[]) => unknown;
|
|
134
|
-
}, {
|
|
135
|
-
default: (...args: unknown[]) => unknown;
|
|
136
|
-
}>;
|
|
130
|
+
name: z.ZodString;
|
|
137
131
|
params: z.ZodOptional<z.ZodAny>;
|
|
138
132
|
}, "strip", z.ZodTypeAny, {
|
|
139
|
-
|
|
140
|
-
default: (...args: unknown[]) => unknown;
|
|
141
|
-
};
|
|
133
|
+
name: string;
|
|
142
134
|
params?: any;
|
|
143
135
|
}, {
|
|
144
|
-
|
|
145
|
-
default: (...args: unknown[]) => unknown;
|
|
146
|
-
};
|
|
136
|
+
name: string;
|
|
147
137
|
params?: any;
|
|
148
138
|
}>;
|
|
149
139
|
tracing: z.ZodDefault<z.ZodOptional<z.ZodDiscriminatedUnion<"enabled", [z.ZodObject<{
|
|
@@ -370,9 +360,7 @@ export declare const runApiParametersSchema: z.ZodObject<{
|
|
|
370
360
|
retrieveSession: z.ZodDefault<z.ZodBoolean>;
|
|
371
361
|
}, "strip", z.ZodTypeAny, {
|
|
372
362
|
automationFunction: {
|
|
373
|
-
|
|
374
|
-
default: (...args: unknown[]) => unknown;
|
|
375
|
-
};
|
|
363
|
+
name: string;
|
|
376
364
|
params?: any;
|
|
377
365
|
};
|
|
378
366
|
tracing: {
|
|
@@ -428,9 +416,7 @@ export declare const runApiParametersSchema: z.ZodObject<{
|
|
|
428
416
|
} | undefined;
|
|
429
417
|
}, {
|
|
430
418
|
automationFunction: {
|
|
431
|
-
|
|
432
|
-
default: (...args: unknown[]) => unknown;
|
|
433
|
-
};
|
|
419
|
+
name: string;
|
|
434
420
|
params?: any;
|
|
435
421
|
};
|
|
436
422
|
functionsToken?: string | undefined;
|
|
@@ -489,6 +475,7 @@ export type RunApiSession = z.infer<typeof runApiSessionSchema>;
|
|
|
489
475
|
export type RunApiParameters = z.input<typeof runApiParametersSchema>;
|
|
490
476
|
export type ExtendedRunApiParameters = RunApiParameters & {
|
|
491
477
|
abortSignal?: AbortSignal;
|
|
478
|
+
importFunction?: (name: string) => Promise<any> | undefined;
|
|
492
479
|
};
|
|
493
480
|
export type RunApiResultOk<R = any> = {
|
|
494
481
|
result: R;
|
|
@@ -16,11 +16,7 @@ const runApiSessionSchema = exports.runApiSessionSchema = _zod.default.discrimin
|
|
|
16
16
|
const runApiParametersSchema = exports.runApiParametersSchema = _zod.default.object({
|
|
17
17
|
functionsToken: _zod.default.string().optional(),
|
|
18
18
|
automationFunction: _zod.default.object({
|
|
19
|
-
|
|
20
|
-
default: _zod.default.function()
|
|
21
|
-
}, {
|
|
22
|
-
required_error: "API handler must have a default export function"
|
|
23
|
-
}),
|
|
19
|
+
name: _zod.default.string(),
|
|
24
20
|
params: _zod.default.any().optional()
|
|
25
21
|
}),
|
|
26
22
|
tracing: _zod.default.discriminatedUnion("enabled", [_zod.default.object({
|