@intuned/runtime 1.0.5
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/.babelrc +21 -0
- package/.eslintignore +10 -0
- package/.eslintrc.js +39 -0
- package/CHANGELOG.md +7 -0
- package/InterfaceTemplate/index.playwright.ts +5 -0
- package/InterfaceTemplate/utils.ts +39 -0
- package/bin/intuned-api-run +2 -0
- package/bin/intuned-auth-session-check +2 -0
- package/bin/intuned-auth-session-create +2 -0
- package/bin/intuned-auth-session-load +2 -0
- package/bin/intuned-auth-session-refresh +2 -0
- package/bin/intuned-browser-save-state +2 -0
- package/bin/intuned-browser-start +2 -0
- package/bin/intuned-build +2 -0
- package/bin/intuned-ts-check +2 -0
- package/dist/commands/api/run.d.ts +6 -0
- package/dist/commands/api/run.js +115 -0
- package/dist/commands/auth-sessions/load.d.ts +2 -0
- package/dist/commands/auth-sessions/load.js +32 -0
- package/dist/commands/auth-sessions/run-check.d.ts +2 -0
- package/dist/commands/auth-sessions/run-check.js +62 -0
- package/dist/commands/auth-sessions/run-create.d.ts +2 -0
- package/dist/commands/auth-sessions/run-create.js +101 -0
- package/dist/commands/browser/save-state.d.ts +2 -0
- package/dist/commands/browser/save-state.js +17 -0
- package/dist/commands/browser/start-browser.d.ts +2 -0
- package/dist/commands/browser/start-browser.js +14 -0
- package/dist/commands/build.d.ts +1 -0
- package/dist/commands/build.js +84 -0
- package/dist/commands/common/browserUtils.d.ts +14 -0
- package/dist/commands/common/browserUtils.js +58 -0
- package/dist/commands/common/getFirstLineNumber.d.ts +9 -0
- package/dist/commands/common/getFirstLineNumber.js +103 -0
- package/dist/commands/common/getFirstLineNumber.test.js +228 -0
- package/dist/commands/common/sendMessageToClient.d.ts +1 -0
- package/dist/commands/common/sendMessageToClient.js +10 -0
- package/dist/commands/common/tsNodeImport.d.ts +1 -0
- package/dist/commands/common/tsNodeImport.js +20 -0
- package/dist/commands/common/utils/fileUtils.d.ts +6 -0
- package/dist/commands/common/utils/fileUtils.js +33 -0
- package/dist/commands/common/utils/settings.d.ts +2 -0
- package/dist/commands/common/utils/settings.js +28 -0
- package/dist/commands/common/utils/template.d.ts +2 -0
- package/dist/commands/common/utils/template.js +31 -0
- package/dist/commands/common/utils/unixSocket.d.ts +9 -0
- package/dist/commands/common/utils/unixSocket.js +44 -0
- package/dist/commands/interface/run.d.ts +1 -0
- package/dist/commands/interface/run.js +214 -0
- package/dist/commands/ts-check.d.ts +2 -0
- package/dist/commands/ts-check.js +56 -0
- package/dist/common/Logger/Logger/index.d.ts +12 -0
- package/dist/common/Logger/Logger/index.js +60 -0
- package/dist/common/Logger/Logger/types.d.ts +8 -0
- package/dist/common/Logger/Logger/types.js +5 -0
- package/dist/common/Logger/index.d.ts +12 -0
- package/dist/common/Logger/index.js +60 -0
- package/dist/common/Logger/types.d.ts +8 -0
- package/dist/common/Logger/types.js +5 -0
- package/dist/common/assets/browser_scripts.js +2214 -0
- package/dist/common/asyncLocalStorage/index.d.ts +16 -0
- package/dist/common/asyncLocalStorage/index.js +17 -0
- package/dist/common/cleanEnvironmentVariables.d.ts +1 -0
- package/dist/common/cleanEnvironmentVariables.js +16 -0
- package/dist/common/constants.d.ts +1 -0
- package/dist/common/constants.js +7 -0
- package/dist/common/contextStorageStateHelpers.d.ts +21 -0
- package/dist/common/contextStorageStateHelpers.js +81 -0
- package/dist/common/formatZodError.d.ts +2 -0
- package/dist/common/formatZodError.js +18 -0
- package/dist/common/getPlaywrightConstructs.d.ts +30 -0
- package/dist/common/getPlaywrightConstructs.js +196 -0
- package/dist/common/jwtTokenManager.d.ts +16 -0
- package/dist/common/jwtTokenManager.js +81 -0
- package/dist/common/runApi/errors.d.ts +65 -0
- package/dist/common/runApi/errors.js +156 -0
- package/dist/common/runApi/index.d.ts +12 -0
- package/dist/common/runApi/index.js +265 -0
- package/dist/common/runApi/types.d.ts +702 -0
- package/dist/common/runApi/types.js +74 -0
- package/dist/common/settingsSchema.d.ts +19 -0
- package/dist/common/settingsSchema.js +17 -0
- package/dist/common/telemetry.d.ts +3 -0
- package/dist/common/telemetry.js +32 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.js +69 -0
- package/dist/runtime/RunError.d.ts +5 -0
- package/dist/runtime/RunError.js +19 -0
- package/dist/runtime/downloadDirectory.d.ts +1 -0
- package/dist/runtime/downloadDirectory.js +19 -0
- package/dist/runtime/enums.d.js +5 -0
- package/dist/runtime/enums.d.ts +11 -0
- package/dist/runtime/enums.js +18 -0
- package/dist/runtime/executionHelpers.test.js +53 -0
- package/dist/runtime/export.d.js +5 -0
- package/dist/runtime/export.d.ts +202 -0
- package/dist/runtime/extendPayload.d.ts +2 -0
- package/dist/runtime/extendPayload.js +21 -0
- package/dist/runtime/extendTimeout.d.ts +1 -0
- package/dist/runtime/extendTimeout.js +30 -0
- package/dist/runtime/index.d.ts +7 -0
- package/dist/runtime/index.js +53 -0
- package/dist/runtime/requestMoreInfo.d.ts +18 -0
- package/dist/runtime/requestMoreInfo.js +25 -0
- package/dist/runtime/runInfo.d.ts +2 -0
- package/dist/runtime/runInfo.js +21 -0
- package/package.json +136 -0
- package/template.tsconfig.json +14 -0
- package/tsconfig.eslint.json +5 -0
- package/tsconfig.json +24 -0
- package/typedoc.json +49 -0
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.runApiSessionSchema = exports.runApiParametersSchema = void 0;
|
|
7
|
+
var _zod = _interopRequireDefault(require("zod"));
|
|
8
|
+
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
9
|
+
const runApiSessionSchema = exports.runApiSessionSchema = _zod.default.discriminatedUnion("type", [_zod.default.object({
|
|
10
|
+
type: _zod.default.literal("file"),
|
|
11
|
+
path: _zod.default.string()
|
|
12
|
+
}), _zod.default.object({
|
|
13
|
+
type: _zod.default.literal("state"),
|
|
14
|
+
state: _zod.default.object({
|
|
15
|
+
cookies: _zod.default.array(_zod.default.object({
|
|
16
|
+
name: _zod.default.string(),
|
|
17
|
+
value: _zod.default.string(),
|
|
18
|
+
domain: _zod.default.string(),
|
|
19
|
+
path: _zod.default.string(),
|
|
20
|
+
expires: _zod.default.number(),
|
|
21
|
+
httpOnly: _zod.default.boolean(),
|
|
22
|
+
secure: _zod.default.boolean(),
|
|
23
|
+
sameSite: _zod.default.enum(["Strict", "Lax", "None"])
|
|
24
|
+
})),
|
|
25
|
+
origins: _zod.default.array(_zod.default.object({
|
|
26
|
+
origin: _zod.default.string(),
|
|
27
|
+
localStorage: _zod.default.array(_zod.default.object({
|
|
28
|
+
name: _zod.default.string(),
|
|
29
|
+
value: _zod.default.string()
|
|
30
|
+
}))
|
|
31
|
+
})),
|
|
32
|
+
sessionStorage: _zod.default.array(_zod.default.object({
|
|
33
|
+
origin: _zod.default.string(),
|
|
34
|
+
sessionStorage: _zod.default.array(_zod.default.object({
|
|
35
|
+
name: _zod.default.string(),
|
|
36
|
+
value: _zod.default.string()
|
|
37
|
+
}))
|
|
38
|
+
})).optional()
|
|
39
|
+
}).nullable().optional()
|
|
40
|
+
})]);
|
|
41
|
+
const runApiParametersSchema = exports.runApiParametersSchema = _zod.default.object({
|
|
42
|
+
automationFunction: _zod.default.object({
|
|
43
|
+
name: _zod.default.string(),
|
|
44
|
+
params: _zod.default.any().optional()
|
|
45
|
+
}),
|
|
46
|
+
tracing: _zod.default.discriminatedUnion("enabled", [_zod.default.object({
|
|
47
|
+
enabled: _zod.default.literal(false)
|
|
48
|
+
}), _zod.default.object({
|
|
49
|
+
enabled: _zod.default.literal(true),
|
|
50
|
+
filePath: _zod.default.string()
|
|
51
|
+
})]).optional().default({
|
|
52
|
+
enabled: false
|
|
53
|
+
}),
|
|
54
|
+
auth: _zod.default.object({
|
|
55
|
+
session: runApiSessionSchema,
|
|
56
|
+
runCheck: _zod.default.boolean().default(false)
|
|
57
|
+
}).optional(),
|
|
58
|
+
runOptions: _zod.default.discriminatedUnion("environment", [_zod.default.object({
|
|
59
|
+
environment: _zod.default.literal("standalone"),
|
|
60
|
+
headless: _zod.default.boolean().default(true),
|
|
61
|
+
proxy: _zod.default.object({
|
|
62
|
+
server: _zod.default.string(),
|
|
63
|
+
username: _zod.default.string(),
|
|
64
|
+
password: _zod.default.string()
|
|
65
|
+
}).optional()
|
|
66
|
+
}), _zod.default.object({
|
|
67
|
+
environment: _zod.default.literal("cdp"),
|
|
68
|
+
cdpAddress: _zod.default.string(),
|
|
69
|
+
mode: _zod.default.union([_zod.default.literal("vanilla"), _zod.default.literal("playwright"), _zod.default.literal("playwright-standalone"), _zod.default.literal("playwright-headless")])
|
|
70
|
+
})]).default({
|
|
71
|
+
environment: "standalone"
|
|
72
|
+
}),
|
|
73
|
+
retrieveSession: _zod.default.boolean().default(false)
|
|
74
|
+
});
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import * as z from "zod";
|
|
2
|
+
export declare const settingsSchema: z.ZodObject<{
|
|
3
|
+
authSessions: z.ZodDefault<z.ZodOptional<z.ZodObject<{
|
|
4
|
+
enabled: z.ZodBoolean;
|
|
5
|
+
}, "strip", z.ZodTypeAny, {
|
|
6
|
+
enabled: boolean;
|
|
7
|
+
}, {
|
|
8
|
+
enabled: boolean;
|
|
9
|
+
}>>>;
|
|
10
|
+
}, "strip", z.ZodTypeAny, {
|
|
11
|
+
authSessions: {
|
|
12
|
+
enabled: boolean;
|
|
13
|
+
};
|
|
14
|
+
}, {
|
|
15
|
+
authSessions?: {
|
|
16
|
+
enabled: boolean;
|
|
17
|
+
} | undefined;
|
|
18
|
+
}>;
|
|
19
|
+
export type IntunedSettings = z.infer<typeof settingsSchema>;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.settingsSchema = void 0;
|
|
7
|
+
var z = _interopRequireWildcard(require("zod"));
|
|
8
|
+
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); }
|
|
9
|
+
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 && {}.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; }
|
|
10
|
+
const authSessionsSchema = z.object({
|
|
11
|
+
enabled: z.boolean()
|
|
12
|
+
}).optional().default({
|
|
13
|
+
enabled: false
|
|
14
|
+
});
|
|
15
|
+
const settingsSchema = exports.settingsSchema = z.object({
|
|
16
|
+
authSessions: authSessionsSchema
|
|
17
|
+
});
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.getTelemetryClient = getTelemetryClient;
|
|
7
|
+
exports.initializeAppInsights = initializeAppInsights;
|
|
8
|
+
var appInsights = _interopRequireWildcard(require("applicationinsights"));
|
|
9
|
+
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); }
|
|
10
|
+
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 && {}.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; }
|
|
11
|
+
function gracefulShutdown() {
|
|
12
|
+
console.log("Shutting down, so flushing app insights.");
|
|
13
|
+
appInsights.defaultClient.flush();
|
|
14
|
+
process.exit();
|
|
15
|
+
}
|
|
16
|
+
function initializeAppInsights() {
|
|
17
|
+
const appInsightsConnectionString = process.env.APPINSIGHTS_CONNECTION_STRING;
|
|
18
|
+
if (appInsightsConnectionString) {
|
|
19
|
+
console.log("Initializing app insights.");
|
|
20
|
+
appInsights.setup(appInsightsConnectionString).setAutoCollectConsole(true, true).setAutoCollectDependencies(true).setAutoCollectExceptions(true).setAutoCollectHeartbeat(true).setAutoCollectPerformance(true, true).setAutoCollectRequests(true).setAutoDependencyCorrelation(true).setDistributedTracingMode(appInsights.DistributedTracingModes.AI_AND_W3C).setSendLiveMetrics(true).setUseDiskRetryCaching(true);
|
|
21
|
+
appInsights.defaultClient.context.tags[appInsights.defaultClient.context.keys.cloudRole] = "@intuned/sdk";
|
|
22
|
+
if (process.env.FLY_APP_NAME) {
|
|
23
|
+
appInsights.defaultClient.context.tags[appInsights.defaultClient.context.keys.cloudRoleInstance] = process.env.FLY_APP_NAME;
|
|
24
|
+
}
|
|
25
|
+
process.on("SIGTERM", gracefulShutdown);
|
|
26
|
+
process.on("SIGINT", gracefulShutdown);
|
|
27
|
+
appInsights.start();
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
function getTelemetryClient() {
|
|
31
|
+
return appInsights.defaultClient;
|
|
32
|
+
}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export { extendPayload, extendTimeout, runInfo, RunError, requestMultipleChoice, requestOTP, } from "./runtime";
|
|
2
|
+
export { runWithContext, getExecutionContext, } from "./common/asyncLocalStorage";
|
|
3
|
+
export { getDownloadDirectoryPath } from "./runtime/downloadDirectory";
|
|
4
|
+
export { getProductionPlaywrightConstructs } from "./common/getPlaywrightConstructs";
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
Object.defineProperty(exports, "RunError", {
|
|
7
|
+
enumerable: true,
|
|
8
|
+
get: function () {
|
|
9
|
+
return _runtime.RunError;
|
|
10
|
+
}
|
|
11
|
+
});
|
|
12
|
+
Object.defineProperty(exports, "extendPayload", {
|
|
13
|
+
enumerable: true,
|
|
14
|
+
get: function () {
|
|
15
|
+
return _runtime.extendPayload;
|
|
16
|
+
}
|
|
17
|
+
});
|
|
18
|
+
Object.defineProperty(exports, "extendTimeout", {
|
|
19
|
+
enumerable: true,
|
|
20
|
+
get: function () {
|
|
21
|
+
return _runtime.extendTimeout;
|
|
22
|
+
}
|
|
23
|
+
});
|
|
24
|
+
Object.defineProperty(exports, "getDownloadDirectoryPath", {
|
|
25
|
+
enumerable: true,
|
|
26
|
+
get: function () {
|
|
27
|
+
return _downloadDirectory.getDownloadDirectoryPath;
|
|
28
|
+
}
|
|
29
|
+
});
|
|
30
|
+
Object.defineProperty(exports, "getExecutionContext", {
|
|
31
|
+
enumerable: true,
|
|
32
|
+
get: function () {
|
|
33
|
+
return _asyncLocalStorage.getExecutionContext;
|
|
34
|
+
}
|
|
35
|
+
});
|
|
36
|
+
Object.defineProperty(exports, "getProductionPlaywrightConstructs", {
|
|
37
|
+
enumerable: true,
|
|
38
|
+
get: function () {
|
|
39
|
+
return _getPlaywrightConstructs.getProductionPlaywrightConstructs;
|
|
40
|
+
}
|
|
41
|
+
});
|
|
42
|
+
Object.defineProperty(exports, "requestMultipleChoice", {
|
|
43
|
+
enumerable: true,
|
|
44
|
+
get: function () {
|
|
45
|
+
return _runtime.requestMultipleChoice;
|
|
46
|
+
}
|
|
47
|
+
});
|
|
48
|
+
Object.defineProperty(exports, "requestOTP", {
|
|
49
|
+
enumerable: true,
|
|
50
|
+
get: function () {
|
|
51
|
+
return _runtime.requestOTP;
|
|
52
|
+
}
|
|
53
|
+
});
|
|
54
|
+
Object.defineProperty(exports, "runInfo", {
|
|
55
|
+
enumerable: true,
|
|
56
|
+
get: function () {
|
|
57
|
+
return _runtime.runInfo;
|
|
58
|
+
}
|
|
59
|
+
});
|
|
60
|
+
Object.defineProperty(exports, "runWithContext", {
|
|
61
|
+
enumerable: true,
|
|
62
|
+
get: function () {
|
|
63
|
+
return _asyncLocalStorage.runWithContext;
|
|
64
|
+
}
|
|
65
|
+
});
|
|
66
|
+
var _runtime = require("./runtime");
|
|
67
|
+
var _asyncLocalStorage = require("./common/asyncLocalStorage");
|
|
68
|
+
var _downloadDirectory = require("./runtime/downloadDirectory");
|
|
69
|
+
var _getPlaywrightConstructs = require("./common/getPlaywrightConstructs");
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.RunError = void 0;
|
|
7
|
+
class RunError extends Error {
|
|
8
|
+
constructor(message, options) {
|
|
9
|
+
super(message);
|
|
10
|
+
this.message = message;
|
|
11
|
+
this.name = "USER_GENERATED_ERROR";
|
|
12
|
+
this.options = options ?? {
|
|
13
|
+
retryable: false
|
|
14
|
+
};
|
|
15
|
+
Object.setPrototypeOf(this, RunError.prototype);
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
exports.RunError = RunError;
|
|
19
|
+
new RunError("", {});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function getDownloadDirectoryPath(): string;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.getDownloadDirectoryPath = getDownloadDirectoryPath;
|
|
7
|
+
var _ = require("..");
|
|
8
|
+
var _fsExtra = require("fs-extra");
|
|
9
|
+
function getDownloadDirectoryPath() {
|
|
10
|
+
const context = (0, _.getExecutionContext)();
|
|
11
|
+
if (!context) {
|
|
12
|
+
throw new Error("ExecutionContext not found");
|
|
13
|
+
}
|
|
14
|
+
const path = `/tmp/downloads/${context.runId}`;
|
|
15
|
+
(0, _fsExtra.ensureDirSync)(path, {
|
|
16
|
+
mode: 0o2775
|
|
17
|
+
});
|
|
18
|
+
return path;
|
|
19
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.RunType = exports.RunEnvironment = void 0;
|
|
7
|
+
let RunEnvironment = exports.RunEnvironment = function (RunEnvironment) {
|
|
8
|
+
RunEnvironment["IDE"] = "IDE";
|
|
9
|
+
RunEnvironment["DEPLOYED"] = "DEPLOYED";
|
|
10
|
+
return RunEnvironment;
|
|
11
|
+
}({});
|
|
12
|
+
let RunType = exports.RunType = function (RunType) {
|
|
13
|
+
RunType["SYNC"] = "SYNC";
|
|
14
|
+
RunType["ASYNC"] = "ASYNC";
|
|
15
|
+
RunType["JOB"] = "JOB";
|
|
16
|
+
RunType["QUEUE"] = "QUEUE";
|
|
17
|
+
return RunType;
|
|
18
|
+
}({});
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _vitest = require("vitest");
|
|
4
|
+
var _asyncLocalStorage = require("../common/asyncLocalStorage");
|
|
5
|
+
var _ = require(".");
|
|
6
|
+
var _enums = require("./enums");
|
|
7
|
+
(0, _vitest.describe)("Execution Helpers", () => {
|
|
8
|
+
(0, _vitest.it)("should be able to get execution info", () => {
|
|
9
|
+
(0, _asyncLocalStorage.runWithContext)({
|
|
10
|
+
runEnvironment: _enums.RunEnvironment.IDE,
|
|
11
|
+
runId: "test-run-id",
|
|
12
|
+
extendedPayloads: []
|
|
13
|
+
}, () => {
|
|
14
|
+
(0, _vitest.expect)((0, _.runInfo)().runId).toEqual("test-run-id");
|
|
15
|
+
});
|
|
16
|
+
});
|
|
17
|
+
(0, _vitest.it)("should be able to mutate extendedPayloads and get the accmulated value at the end ", () => {
|
|
18
|
+
const context = {
|
|
19
|
+
extendedPayloads: [],
|
|
20
|
+
runId: "test-run-id"
|
|
21
|
+
};
|
|
22
|
+
(0, _asyncLocalStorage.runWithContext)({
|
|
23
|
+
runEnvironment: _enums.RunEnvironment.IDE,
|
|
24
|
+
runId: "test-run-id",
|
|
25
|
+
extendedPayloads: []
|
|
26
|
+
}, () => {
|
|
27
|
+
var _getExecutionContext, _getExecutionContext2;
|
|
28
|
+
(0, _vitest.expect)((_getExecutionContext = (0, _asyncLocalStorage.getExecutionContext)()) === null || _getExecutionContext === void 0 ? void 0 : _getExecutionContext.extendedPayloads).toEqual([]);
|
|
29
|
+
(0, _.extendPayload)({
|
|
30
|
+
api: "test-api",
|
|
31
|
+
parameters: {}
|
|
32
|
+
});
|
|
33
|
+
(0, _vitest.expect)((_getExecutionContext2 = (0, _asyncLocalStorage.getExecutionContext)()) === null || _getExecutionContext2 === void 0 ? void 0 : _getExecutionContext2.extendedPayloads).toEqual([{
|
|
34
|
+
api: "test-api",
|
|
35
|
+
parameters: {}
|
|
36
|
+
}]);
|
|
37
|
+
(0, _.extendPayload)({
|
|
38
|
+
api: "test-api",
|
|
39
|
+
parameters: {}
|
|
40
|
+
});
|
|
41
|
+
(0, _.extendPayload)({
|
|
42
|
+
api: "test-api",
|
|
43
|
+
parameters: {}
|
|
44
|
+
});
|
|
45
|
+
(0, _.extendPayload)({
|
|
46
|
+
api: "test-api",
|
|
47
|
+
parameters: {}
|
|
48
|
+
});
|
|
49
|
+
const context = (0, _asyncLocalStorage.getExecutionContext)();
|
|
50
|
+
(0, _vitest.expect)(context === null || context === void 0 ? void 0 : context.extendedPayloads).toHaveLength(4);
|
|
51
|
+
});
|
|
52
|
+
});
|
|
53
|
+
});
|
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
import { RunEnvironment } from "./enums";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* ## Description
|
|
5
|
+
* In the context of a job, extendTimeout will increase the timeout of the currently executing payload.
|
|
6
|
+
* This is useful when the payload is expected to take a long time. For example, when running pagination code.
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* ```typescript Example
|
|
10
|
+
* import { extendTimeout } from "@intuned/sdk/runtime"
|
|
11
|
+
*
|
|
12
|
+
* extendTimeout();
|
|
13
|
+
* ```
|
|
14
|
+
*
|
|
15
|
+
*/
|
|
16
|
+
export declare function extendTimeout(): void;
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* ## Description
|
|
20
|
+
* In the context of a job or queue execution, extendPayload appends new payloads to the end of the queue of job.
|
|
21
|
+
* Calling extendPayload will also call extendTimeout.
|
|
22
|
+
*
|
|
23
|
+
* @param {Payload | Payload[]} payload - The payload or array of payloads to extend. you can specify the api name and what parameters you want to pass it, the new added apis will use the same proxy and auth-session settings as the api that extended them
|
|
24
|
+
*
|
|
25
|
+
* @example
|
|
26
|
+
* ```typescript Single payload
|
|
27
|
+
* import { extendPayload } from "@intuned/sdk/runtime"
|
|
28
|
+
*
|
|
29
|
+
* // this function will append the exampleApi to the end of the queue or job it's executing in.
|
|
30
|
+
* extendPayload({ api: 'exampleApi', parameters: { key: 'value' } });
|
|
31
|
+
* ```
|
|
32
|
+
*
|
|
33
|
+
* @example
|
|
34
|
+
* ```typescript Array of payloads
|
|
35
|
+
* import { extendPayload } from "@intuned/sdk/runtime"
|
|
36
|
+
*
|
|
37
|
+
* const payloadArray: Payload[] = [
|
|
38
|
+
* { api: 'exampleApi1', parameters: { key1: 'value1' } },
|
|
39
|
+
* { api: 'exampleApi2', parameters: { key2: 'value2' } }
|
|
40
|
+
* ];
|
|
41
|
+
*
|
|
42
|
+
* // this function will append 2 apis to the end of the queue or job it's executing in.
|
|
43
|
+
* extendPayload(payloadArray);
|
|
44
|
+
* ```
|
|
45
|
+
*/
|
|
46
|
+
export declare function extendPayload(payload: Payload | Payload[]): void;
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* @interface Payload
|
|
50
|
+
* @property {string} api - The API path you want to extend.
|
|
51
|
+
* @property {Record<string, any>} parameters - A record of key-value pairs representing the parameters to be sent to the API
|
|
52
|
+
*
|
|
53
|
+
* @example
|
|
54
|
+
*
|
|
55
|
+
* ```typescript payload
|
|
56
|
+
* import { Payload } from "@intuned/sdk/runtime"
|
|
57
|
+
*
|
|
58
|
+
* const payload: Payload = {
|
|
59
|
+
* api: 'exampleApi',
|
|
60
|
+
* parameters: {
|
|
61
|
+
* key1: 'value1',
|
|
62
|
+
* key2: 'value2'
|
|
63
|
+
* }
|
|
64
|
+
* };
|
|
65
|
+
* ```
|
|
66
|
+
*/
|
|
67
|
+
export interface Payload {
|
|
68
|
+
api: string;
|
|
69
|
+
parameters: Record<string, any>;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* Retrieves information about the current run environment.
|
|
74
|
+
*
|
|
75
|
+
* @returns {RunInfo} An object containing details about the run environment and the run ID.
|
|
76
|
+
*
|
|
77
|
+
* @example
|
|
78
|
+
* ```typescript runInfo
|
|
79
|
+
* import { runInfo } from "@intuned/sdk/runtime"
|
|
80
|
+
*
|
|
81
|
+
* const info = runInfo();
|
|
82
|
+
* console.log(info.runEnvironment); // Outputs the run environment, IDE or DEPLOYED
|
|
83
|
+
* console.log(info.runId); // Outputs the run ID, if available, in IDE run id will be undefined
|
|
84
|
+
* ```
|
|
85
|
+
*/
|
|
86
|
+
export declare function runInfo(): RunInfo;
|
|
87
|
+
|
|
88
|
+
/**
|
|
89
|
+
* Represents information about the current run.
|
|
90
|
+
*
|
|
91
|
+
* @interface RunInfo
|
|
92
|
+
* @property {RunEnvironment} runEnvironment - the run environment `IDE` or `DEPLOYED`
|
|
93
|
+
* @property {string} [runId] - Optional. The ID of the current run, in IDE environment, run id will be undefined
|
|
94
|
+
*/
|
|
95
|
+
export interface RunInfo {
|
|
96
|
+
runEnvironment: RunEnvironment;
|
|
97
|
+
runId?: string;
|
|
98
|
+
jobId?: string;
|
|
99
|
+
jobRunId?: string;
|
|
100
|
+
queueId?: string;
|
|
101
|
+
proxy?: string;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
/**
|
|
105
|
+
* @interface RunErrorOptions
|
|
106
|
+
* @property {boolean} [retryable] - Optional. Indicates whether the error is retryable.
|
|
107
|
+
* @property {number} [status_code] - Optional. The HTTP status code associated with the error.
|
|
108
|
+
* @property {string} [error_code] - Optional. A specific error code to identify the type of error.
|
|
109
|
+
*
|
|
110
|
+
* @example
|
|
111
|
+
* ```typescript RunErrorOptions
|
|
112
|
+
* import { RunErrorOptions } from "@intuned/sdk/runtime"
|
|
113
|
+
*
|
|
114
|
+
* const options: RunErrorOptions = {
|
|
115
|
+
* retryable: true,
|
|
116
|
+
* status_code: 500,
|
|
117
|
+
* error_code: 'SERVER_ERROR'
|
|
118
|
+
* };
|
|
119
|
+
* ```
|
|
120
|
+
*/
|
|
121
|
+
export interface RunErrorOptions {
|
|
122
|
+
retryable?: boolean;
|
|
123
|
+
status_code?: number;
|
|
124
|
+
error_code?: string;
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
/**
|
|
128
|
+
* Represents an error that occurs during a run.
|
|
129
|
+
*
|
|
130
|
+
* @class
|
|
131
|
+
* @extends Error
|
|
132
|
+
*
|
|
133
|
+
* @param {string} message - The error message.
|
|
134
|
+
* @param {RunErrorOptions} [options] - Optional. Additional options for the error.
|
|
135
|
+
*
|
|
136
|
+
* @property {RunErrorOptions} options - The options associated with the error.
|
|
137
|
+
*
|
|
138
|
+
* @example
|
|
139
|
+
* ```typescript RunError
|
|
140
|
+
* import { RunError } from "@intuned/sdk/runtime"
|
|
141
|
+
*
|
|
142
|
+
* throw new RunError('An error occurred', {
|
|
143
|
+
* retryable: true,
|
|
144
|
+
* status_code: 500,
|
|
145
|
+
* error_code: 'SERVER_ERROR'
|
|
146
|
+
* });
|
|
147
|
+
*
|
|
148
|
+
* ```
|
|
149
|
+
*/
|
|
150
|
+
export declare class RunError extends Error {
|
|
151
|
+
constructor(message: string, options?: RunErrorOptions);
|
|
152
|
+
options: RunErrorOptions;
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
/**
|
|
156
|
+
* in the create auth session flow, you might to need a multiple choice answer from the user, requestMultipleChoice prompts the user with the question and possible options and returns their selection.
|
|
157
|
+
*
|
|
158
|
+
* **Note:** This function is currently in beta and may be subject to changes.
|
|
159
|
+
*
|
|
160
|
+
* @param {string} message - The message to display to the user.
|
|
161
|
+
* @param {string[]} choices - An array of choices to present to the user.
|
|
162
|
+
*
|
|
163
|
+
* @example
|
|
164
|
+
* ```typescript requestMultipleChoice
|
|
165
|
+
* // in auth-sessions/create.ts
|
|
166
|
+
*
|
|
167
|
+
* import { requestMultipleChoice } from "@intuned/sdk/runtime"
|
|
168
|
+
*
|
|
169
|
+
* const message = "What is your favorite color?";
|
|
170
|
+
* const choices = ["Red", "Blue", "Green", "Yellow"];
|
|
171
|
+
*
|
|
172
|
+
* const selectedChoice = yield requestMultipleChoice(message, choices);
|
|
173
|
+
*
|
|
174
|
+
* console.log(selectedChoice);
|
|
175
|
+
* ```
|
|
176
|
+
*/
|
|
177
|
+
export declare function requestMultipleChoice(
|
|
178
|
+
message: string,
|
|
179
|
+
choices: string[]
|
|
180
|
+
): unknown;
|
|
181
|
+
|
|
182
|
+
/**
|
|
183
|
+
* **Note:** This function is currently in beta and may be subject to changes.
|
|
184
|
+
*
|
|
185
|
+
* requestOTP help you to ask the user for an otp in the create auth-session flow.
|
|
186
|
+
*
|
|
187
|
+
* @param {string} message - The message to display to the user.
|
|
188
|
+
*
|
|
189
|
+
* @example
|
|
190
|
+
* ```typescript requestOTP
|
|
191
|
+
* // in auth-sessions/create.ts
|
|
192
|
+
*
|
|
193
|
+
* import { requestOTP } from "@intuned/sdk/runtime"
|
|
194
|
+
*
|
|
195
|
+
* const message = "please submit and OTP from your authenticator app";
|
|
196
|
+
*
|
|
197
|
+
* const otp = yield requestOTP(message);
|
|
198
|
+
*
|
|
199
|
+
* console.log(otp);
|
|
200
|
+
* ```
|
|
201
|
+
*/
|
|
202
|
+
export declare function requestOTP(message: string): unknown;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.extendPayload = extendPayload;
|
|
7
|
+
var _asyncLocalStorage = require("../common/asyncLocalStorage");
|
|
8
|
+
var _extendTimeout = require("./extendTimeout");
|
|
9
|
+
function extendPayload(payload) {
|
|
10
|
+
const context = (0, _asyncLocalStorage.getExecutionContext)();
|
|
11
|
+
if (!context) {
|
|
12
|
+
throw new Error("extendPayload failed due to an internal error.");
|
|
13
|
+
}
|
|
14
|
+
const items = Array.isArray(payload) ? payload : [payload];
|
|
15
|
+
if (!context.extendedPayloads) {
|
|
16
|
+
context.extendedPayloads = [...items];
|
|
17
|
+
return;
|
|
18
|
+
}
|
|
19
|
+
context === null || context === void 0 || context.extendedPayloads.push(...items);
|
|
20
|
+
(0, _extendTimeout.extendTimeout)();
|
|
21
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function extendTimeout(): void;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.extendTimeout = extendTimeout;
|
|
7
|
+
var _asyncLocalStorage = require("../common/asyncLocalStorage");
|
|
8
|
+
const _DEBOUNCE_TIME = 60_000;
|
|
9
|
+
function extendTimeout() {
|
|
10
|
+
const context = (0, _asyncLocalStorage.getExecutionContext)();
|
|
11
|
+
if (!context) {
|
|
12
|
+
throw new Error("extendTimeout failed due to an internal error.");
|
|
13
|
+
}
|
|
14
|
+
const {
|
|
15
|
+
timeoutInfo
|
|
16
|
+
} = context;
|
|
17
|
+
if (!timeoutInfo) {
|
|
18
|
+
return;
|
|
19
|
+
}
|
|
20
|
+
if (timeoutInfo.timeoutTimestamp !== undefined && timeoutInfo.timeoutDuration !== undefined) {
|
|
21
|
+
const newTimeoutStamp = Date.now() + timeoutInfo.timeoutDuration;
|
|
22
|
+
if (newTimeoutStamp - timeoutInfo.timeoutTimestamp < _DEBOUNCE_TIME) {
|
|
23
|
+
return;
|
|
24
|
+
}
|
|
25
|
+
timeoutInfo.timeoutTimestamp = newTimeoutStamp;
|
|
26
|
+
}
|
|
27
|
+
if (timeoutInfo.extendTimeoutCallback !== undefined) {
|
|
28
|
+
void timeoutInfo.extendTimeoutCallback().catch(() => undefined);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export { extendPayload } from "./extendPayload";
|
|
2
|
+
export { extendTimeout } from "./extendTimeout";
|
|
3
|
+
export { runInfo } from "./runInfo";
|
|
4
|
+
export { RunError } from "./RunError";
|
|
5
|
+
export { requestMultipleChoice, requestOTP } from "./requestMoreInfo";
|
|
6
|
+
export type { RequestMoreInfoDetails } from "./requestMoreInfo";
|
|
7
|
+
export { getDownloadDirectoryPath } from "./downloadDirectory";
|