@intuned/runtime-dev 0.0.1-testing.0 → 0.0.1
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/.vite/deps_temp_01af7156/package.json +3 -0
- package/.vscode/extensions.json +3 -0
- package/.vscode/launch.json +102 -0
- package/.vscode/settings.json +12 -0
- package/WebTemplate/controllers/authSessions/create.ts +1 -1
- package/WebTemplate/controllers/runApi/helpers.ts +3 -1
- package/package.json +3 -3
- package/playwright.config.ts +48 -0
- package/src/commands/api/run.ts +225 -0
- package/src/commands/auth-sessions/load.ts +42 -0
- package/src/commands/auth-sessions/run-check.ts +70 -0
- package/src/commands/auth-sessions/run-create.ts +124 -0
- package/src/commands/browser/save-state.ts +22 -0
- package/src/commands/browser/start-browser.ts +17 -0
- package/src/commands/build.ts +125 -0
- package/src/commands/common/browserUtils.ts +80 -0
- package/src/commands/common/getDefaultExportFromFile.ts +13 -0
- package/{dist/commands/common/getFirstLineNumber.test.js → src/commands/common/getFirstLineNumber.test.ts} +121 -75
- package/src/commands/common/getFirstLineNumber.ts +146 -0
- package/src/commands/common/sendMessageToClient.ts +8 -0
- package/src/commands/common/utils/fileUtils.ts +25 -0
- package/src/commands/common/utils/settings.ts +23 -0
- package/src/commands/common/utils/webTemplate.ts +46 -0
- package/src/commands/testing/saveVisibleHtml.ts +29 -0
- package/src/commands/ts-check.ts +88 -0
- package/src/common/Logger/Logger/index.ts +64 -0
- package/{dist/common/Logger/types.d.ts → src/common/Logger/Logger/types.ts} +5 -4
- package/src/common/Logger/index.ts +64 -0
- package/{dist/common/Logger/Logger/types.d.ts → src/common/Logger/types.ts} +5 -4
- package/src/common/asyncLocalStorage/index.ts +29 -0
- package/src/common/cleanEnvironmentVariables.ts +13 -0
- package/src/common/constants.ts +1 -0
- package/src/common/contextStorageStateHelpers.ts +71 -0
- package/src/common/getPlaywrightConstructs.ts +283 -0
- package/src/common/jwtTokenManager.ts +111 -0
- package/src/common/settingsSchema.ts +16 -0
- package/src/common/telemetry.ts +49 -0
- package/src/index.ts +14 -0
- package/src/runtime/RunError.ts +16 -0
- package/src/runtime/downloadDirectory.ts +14 -0
- package/src/runtime/enums.ts +11 -0
- package/src/runtime/executionHelpers.test.ts +70 -0
- package/src/runtime/extendPayload.ts +22 -0
- package/src/runtime/extendTimeout.ts +32 -0
- package/{dist/runtime/index.d.ts → src/runtime/index.ts} +3 -1
- package/src/runtime/requestMoreInfo.ts +40 -0
- package/src/runtime/runInfo.ts +19 -0
- package/vite.config.ts +17 -0
- package/bin/intuned-api-run +0 -2
- package/bin/intuned-auth-session-check +0 -2
- package/bin/intuned-auth-session-create +0 -2
- package/bin/intuned-auth-session-load +0 -2
- package/bin/intuned-auth-session-refresh +0 -2
- package/bin/intuned-browser-save-state +0 -2
- package/bin/intuned-browser-start +0 -2
- package/bin/intuned-build +0 -2
- package/bin/intuned-ts-check +0 -2
- package/dist/commands/api/run.d.ts +0 -6
- package/dist/commands/api/run.js +0 -135
- package/dist/commands/auth-sessions/load.d.ts +0 -2
- package/dist/commands/auth-sessions/load.js +0 -26
- package/dist/commands/auth-sessions/run-check.d.ts +0 -2
- package/dist/commands/auth-sessions/run-check.js +0 -42
- package/dist/commands/auth-sessions/run-create.d.ts +0 -2
- package/dist/commands/auth-sessions/run-create.js +0 -75
- package/dist/commands/browser/save-state.d.ts +0 -2
- package/dist/commands/browser/save-state.js +0 -17
- package/dist/commands/browser/start-browser.d.ts +0 -2
- package/dist/commands/browser/start-browser.js +0 -14
- package/dist/commands/build.d.ts +0 -2
- package/dist/commands/build.js +0 -80
- package/dist/commands/common/browserUtils.d.ts +0 -14
- package/dist/commands/common/browserUtils.js +0 -58
- package/dist/commands/common/getDefaultExportFromFile.d.ts +0 -1
- package/dist/commands/common/getDefaultExportFromFile.js +0 -19
- package/dist/commands/common/getFirstLineNumber.d.ts +0 -9
- package/dist/commands/common/getFirstLineNumber.js +0 -103
- package/dist/commands/common/sendMessageToClient.d.ts +0 -1
- package/dist/commands/common/sendMessageToClient.js +0 -10
- package/dist/commands/common/utils/fileUtils.d.ts +0 -6
- package/dist/commands/common/utils/fileUtils.js +0 -33
- package/dist/commands/common/utils/settings.d.ts +0 -2
- package/dist/commands/common/utils/settings.js +0 -28
- package/dist/commands/common/utils/webTemplate.d.ts +0 -1
- package/dist/commands/common/utils/webTemplate.js +0 -31
- package/dist/commands/ts-check.d.ts +0 -2
- package/dist/commands/ts-check.js +0 -54
- package/dist/common/Logger/Logger/index.d.ts +0 -12
- package/dist/common/Logger/Logger/index.js +0 -60
- package/dist/common/Logger/Logger/types.js +0 -5
- package/dist/common/Logger/index.d.ts +0 -12
- package/dist/common/Logger/index.js +0 -60
- package/dist/common/Logger/types.js +0 -5
- package/dist/common/asyncLocalStorage/index.d.ts +0 -16
- package/dist/common/asyncLocalStorage/index.js +0 -17
- package/dist/common/cleanEnvironmentVariables.d.ts +0 -1
- package/dist/common/cleanEnvironmentVariables.js +0 -16
- package/dist/common/constants.d.ts +0 -1
- package/dist/common/constants.js +0 -7
- package/dist/common/contextStorageStateHelpers.d.ts +0 -15
- package/dist/common/contextStorageStateHelpers.js +0 -48
- package/dist/common/getPlaywrightConstructs.d.ts +0 -28
- package/dist/common/getPlaywrightConstructs.js +0 -175
- package/dist/common/jwtTokenManager.d.ts +0 -16
- package/dist/common/jwtTokenManager.js +0 -81
- package/dist/common/settingsSchema.d.ts +0 -19
- package/dist/common/settingsSchema.js +0 -17
- package/dist/common/telemetry.d.ts +0 -3
- package/dist/common/telemetry.js +0 -32
- package/dist/index.d.ts +0 -4
- package/dist/index.js +0 -69
- package/dist/runtime/RunError.d.ts +0 -5
- package/dist/runtime/RunError.js +0 -19
- package/dist/runtime/downloadDirectory.d.ts +0 -1
- package/dist/runtime/downloadDirectory.js +0 -19
- package/dist/runtime/enums.d.js +0 -5
- package/dist/runtime/enums.js +0 -18
- package/dist/runtime/executionHelpers.test.js +0 -53
- package/dist/runtime/export.d.js +0 -5
- package/dist/runtime/extendPayload.d.ts +0 -2
- package/dist/runtime/extendPayload.js +0 -21
- package/dist/runtime/extendTimeout.d.ts +0 -1
- package/dist/runtime/extendTimeout.js +0 -26
- package/dist/runtime/index.js +0 -53
- package/dist/runtime/requestMoreInfo.d.ts +0 -17
- package/dist/runtime/requestMoreInfo.js +0 -25
- package/dist/runtime/runInfo.d.ts +0 -2
- package/dist/runtime/runInfo.js +0 -21
- /package/{dist → src}/common/assets/browser_scripts.js +0 -0
- /package/{dist → src}/runtime/enums.d.ts +0 -0
- /package/{dist → src}/runtime/export.d.ts +0 -0
|
@@ -1,175 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.getPlaywrightConstructsForMode = getPlaywrightConstructsForMode;
|
|
7
|
-
exports.getProductionPlaywrightConstructs = getProductionPlaywrightConstructs;
|
|
8
|
-
exports.getRemotePlaywrightContext = getRemotePlaywrightContext;
|
|
9
|
-
exports.loadAuthSessionToContext = loadAuthSessionToContext;
|
|
10
|
-
var playwright = _interopRequireWildcard(require("@intuned/playwright-core"));
|
|
11
|
-
var _fsExtra = _interopRequireWildcard(require("fs-extra"));
|
|
12
|
-
var fs = _fsExtra;
|
|
13
|
-
var _contextStorageStateHelpers = require("./contextStorageStateHelpers");
|
|
14
|
-
var _path = _interopRequireWildcard(require("path"));
|
|
15
|
-
var _fileUtils = require("../commands/common/utils/fileUtils");
|
|
16
|
-
var _waitOn = _interopRequireDefault(require("wait-on"));
|
|
17
|
-
var _runtime = require("../runtime");
|
|
18
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
19
|
-
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); }
|
|
20
|
-
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; }
|
|
21
|
-
async function createUserDirWithPreferences() {
|
|
22
|
-
const playwrightTempDir = await (0, _fsExtra.mkdtemp)("/tmp/pw-");
|
|
23
|
-
const userDir = (0, _path.join)(playwrightTempDir, "userdir");
|
|
24
|
-
const defaultDir = (0, _path.join)(userDir, "Default");
|
|
25
|
-
await (0, _fsExtra.mkdir)(defaultDir, {
|
|
26
|
-
recursive: true
|
|
27
|
-
});
|
|
28
|
-
const preferences = {
|
|
29
|
-
plugins: {
|
|
30
|
-
always_open_pdf_externally: true
|
|
31
|
-
}
|
|
32
|
-
};
|
|
33
|
-
await (0, _fsExtra.writeFile)((0, _path.join)(defaultDir, "Preferences"), JSON.stringify(preferences));
|
|
34
|
-
return userDir;
|
|
35
|
-
}
|
|
36
|
-
async function getProductionPlaywrightConstructs({
|
|
37
|
-
proxy,
|
|
38
|
-
headless = true,
|
|
39
|
-
storageState,
|
|
40
|
-
downloadsPath
|
|
41
|
-
}) {
|
|
42
|
-
const extraArgs = ["--no-first-run", "--disable-sync", "--disable-translate", "--disable-features=TranslateUI", "--disable-features=NetworkService", "--lang=en"];
|
|
43
|
-
if (headless) {
|
|
44
|
-
extraArgs.push("--headless=new");
|
|
45
|
-
}
|
|
46
|
-
const executablePath = playwright.chromium.executablePath();
|
|
47
|
-
const chromium127Path = executablePath.replace("chromium-1117", "chromium-1124");
|
|
48
|
-
const isChrome127There = (0, _fsExtra.existsSync)(chromium127Path);
|
|
49
|
-
const userAgent = `Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/${isChrome127There ? 127 : 125}.0.0.0 Safari/537.36`;
|
|
50
|
-
const userDataDir = await createUserDirWithPreferences();
|
|
51
|
-
const context = await playwright.chromium.launchPersistentContext(userDataDir, {
|
|
52
|
-
headless,
|
|
53
|
-
ignoreDefaultArgs: [...getChromiumLaunchArgsToIgnore(), "--headless"],
|
|
54
|
-
proxy,
|
|
55
|
-
executablePath: isChrome127There ? chromium127Path : executablePath,
|
|
56
|
-
args: extraArgs,
|
|
57
|
-
downloadsPath,
|
|
58
|
-
userAgent
|
|
59
|
-
});
|
|
60
|
-
context.once("close", async () => {
|
|
61
|
-
try {
|
|
62
|
-
await (0, _fsExtra.rm)(userDataDir, {
|
|
63
|
-
recursive: true,
|
|
64
|
-
force: true,
|
|
65
|
-
retryDelay: 1000,
|
|
66
|
-
maxRetries: 5
|
|
67
|
-
});
|
|
68
|
-
} catch (error) {
|
|
69
|
-
console.error("Failed to remove user data dir", error);
|
|
70
|
-
}
|
|
71
|
-
});
|
|
72
|
-
if (storageState) {
|
|
73
|
-
await (0, _contextStorageStateHelpers.setContextStorageState)(context, storageState);
|
|
74
|
-
}
|
|
75
|
-
const assetsFile = _path.default.join(__dirname, "./assets/browser_scripts.js");
|
|
76
|
-
await context.addInitScript({
|
|
77
|
-
path: assetsFile
|
|
78
|
-
});
|
|
79
|
-
let page = context.pages().at(0);
|
|
80
|
-
if (page) {
|
|
81
|
-
const scriptString = await (0, _fsExtra.readFile)(assetsFile, "utf8");
|
|
82
|
-
await page.evaluate(scriptString);
|
|
83
|
-
} else {
|
|
84
|
-
page = await context.newPage();
|
|
85
|
-
}
|
|
86
|
-
return {
|
|
87
|
-
page,
|
|
88
|
-
context
|
|
89
|
-
};
|
|
90
|
-
}
|
|
91
|
-
const getChromiumLaunchArgsToIgnore = () => ["--disable-field-trial-config", "--disable-background-networking", "--enable-features=NetworkService,NetworkServiceInProcess", "--disable-background-timer-throttling", "--disable-backgrounding-occluded-windows", "--disable-back-forward-cache", "--disable-breakpad", "--disable-client-side-phishing-detection", "--disable-component-extensions-with-background-pages", "--disable-component-update", "--no-default-browser-check", "--disable-default-apps", "--disable-dev-shm-usage", "--disable-extensions", "--disable-features=ImprovedCookieControls,LazyFrameLoading,GlobalMediaControls,DestroyProfileOnBrowserClose,MediaRouter,DialMediaRouteProvider,AcceptCHFrame,AutoExpandDetailsElement,CertificateTransparencyComponentUpdater,AvoidUnnecessaryBeforeUnloadCheckSync,Translate,TranslateUI", "--allow-pre-commit-input", "--disable-hang-monitor", "--disable-ipc-flooding-protection", "--disable-prompt-on-repost", "--disable-renderer-backgrounding", "--force-color-profile=srgb", "--metrics-recording-only", "--no-first-run", "--enable-automation", "--password-store=basic", "--use-mock-keychain", "--no-service-autorun", "--export-tagged-pdf", "--enable-use-zoom-for-dsf=false"];
|
|
92
|
-
async function getPlaywrightConstructsForMode(mode, cdpAddress, authSessionPath) {
|
|
93
|
-
if (mode == "playwright-standalone") {
|
|
94
|
-
if (!cdpAddress) {
|
|
95
|
-
throw new Error("cdpAddress is required");
|
|
96
|
-
}
|
|
97
|
-
const {
|
|
98
|
-
context
|
|
99
|
-
} = await getRemotePlaywrightContext(cdpAddress);
|
|
100
|
-
if (!context) {
|
|
101
|
-
throw new Error("no context found");
|
|
102
|
-
}
|
|
103
|
-
const assetsFile = _path.default.join(__dirname, "./assets/browser_scripts.js");
|
|
104
|
-
await context.addInitScript({
|
|
105
|
-
path: assetsFile
|
|
106
|
-
});
|
|
107
|
-
const pages = await context.pages();
|
|
108
|
-
let page = null;
|
|
109
|
-
if (pages.length > 0) {
|
|
110
|
-
page = pages[0];
|
|
111
|
-
const scriptString = await fs.readFile(assetsFile, "utf8");
|
|
112
|
-
await page.evaluate(scriptString);
|
|
113
|
-
} else {
|
|
114
|
-
page = await context.newPage();
|
|
115
|
-
}
|
|
116
|
-
if (authSessionPath) {
|
|
117
|
-
await loadAuthSessionToContext(context, authSessionPath);
|
|
118
|
-
}
|
|
119
|
-
return {
|
|
120
|
-
page,
|
|
121
|
-
context
|
|
122
|
-
};
|
|
123
|
-
}
|
|
124
|
-
const downloadsPath = (0, _runtime.getDownloadDirectoryPath)();
|
|
125
|
-
if (mode === "playwright" || mode === "playwright-headless") {
|
|
126
|
-
const productionConstructs = await getProductionPlaywrightConstructs({
|
|
127
|
-
headless: mode === "playwright-headless",
|
|
128
|
-
downloadsPath
|
|
129
|
-
});
|
|
130
|
-
if (authSessionPath) {
|
|
131
|
-
await loadAuthSessionToContext(productionConstructs.context, authSessionPath);
|
|
132
|
-
}
|
|
133
|
-
return {
|
|
134
|
-
...productionConstructs
|
|
135
|
-
};
|
|
136
|
-
}
|
|
137
|
-
throw "invalid mode";
|
|
138
|
-
}
|
|
139
|
-
async function loadAuthSessionToContext(context, authSessionPath) {
|
|
140
|
-
const fullPath = (0, _fileUtils.getFullPathInProject)(authSessionPath);
|
|
141
|
-
const data = await fs.readJson(fullPath);
|
|
142
|
-
await (0, _contextStorageStateHelpers.setContextStorageState)(context, data);
|
|
143
|
-
}
|
|
144
|
-
async function getRemotePlaywrightContext(cdpAddress) {
|
|
145
|
-
const playwright = await Promise.resolve().then(() => _interopRequireWildcard(require("@intuned/playwright-core")));
|
|
146
|
-
let browser = null;
|
|
147
|
-
if (!cdpAddress) {
|
|
148
|
-
throw new Error("cdpAddress is required");
|
|
149
|
-
}
|
|
150
|
-
const cdpAddressWithoutProtocol = cdpAddress.replace("http://", "").replace("https://", "").replace("localhost", "127.0.0.1");
|
|
151
|
-
try {
|
|
152
|
-
await (0, _waitOn.default)({
|
|
153
|
-
resources: [`http-get://${cdpAddressWithoutProtocol}/json/version`],
|
|
154
|
-
delay: 100,
|
|
155
|
-
interval: 100,
|
|
156
|
-
timeout: 5000,
|
|
157
|
-
tcpTimeout: 1000,
|
|
158
|
-
window: 1000
|
|
159
|
-
});
|
|
160
|
-
} catch (error) {
|
|
161
|
-
console.error("Failed to connect to the browser");
|
|
162
|
-
process.exit(128 + 9);
|
|
163
|
-
}
|
|
164
|
-
try {
|
|
165
|
-
browser = await playwright.chromium.connectOverCDP(cdpAddress);
|
|
166
|
-
} catch (e) {
|
|
167
|
-
console.log(e);
|
|
168
|
-
throw new Error("failed to connect to the browser");
|
|
169
|
-
}
|
|
170
|
-
const context = browser.contexts()[0];
|
|
171
|
-
return {
|
|
172
|
-
browser,
|
|
173
|
-
context
|
|
174
|
-
};
|
|
175
|
-
}
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import fetch from "cross-fetch";
|
|
2
|
-
declare class JwtTokenManager {
|
|
3
|
-
private _token;
|
|
4
|
-
private tokenRefreshTimeout;
|
|
5
|
-
private refreshTokenPath;
|
|
6
|
-
constructor(refreshTokenPath: string);
|
|
7
|
-
get token(): string | undefined;
|
|
8
|
-
set token(newToken: string | undefined);
|
|
9
|
-
private get timeToRefresh();
|
|
10
|
-
private scheduleTokenRefresh;
|
|
11
|
-
private refreshToken;
|
|
12
|
-
fetchWithToken(...[input, init]: Parameters<typeof fetch>): Promise<Response>;
|
|
13
|
-
}
|
|
14
|
-
export declare const backendFunctionsTokenManager: JwtTokenManager;
|
|
15
|
-
export declare function callBackendFunctionWithToken(path: string, init?: Parameters<typeof fetch>[1]): Promise<Response>;
|
|
16
|
-
export {};
|
|
@@ -1,81 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.backendFunctionsTokenManager = void 0;
|
|
7
|
-
exports.callBackendFunctionWithToken = callBackendFunctionWithToken;
|
|
8
|
-
var _crossFetch = _interopRequireDefault(require("cross-fetch"));
|
|
9
|
-
var jwt = _interopRequireWildcard(require("jsonwebtoken"));
|
|
10
|
-
var _neverthrow = require("neverthrow");
|
|
11
|
-
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); }
|
|
12
|
-
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; }
|
|
13
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
14
|
-
class JwtTokenManager {
|
|
15
|
-
constructor(refreshTokenPath) {
|
|
16
|
-
this.refreshTokenPath = refreshTokenPath;
|
|
17
|
-
this._token = undefined;
|
|
18
|
-
}
|
|
19
|
-
get token() {
|
|
20
|
-
return this._token;
|
|
21
|
-
}
|
|
22
|
-
set token(newToken) {
|
|
23
|
-
if (this._token != newToken) {
|
|
24
|
-
this._token = newToken;
|
|
25
|
-
void this.scheduleTokenRefresh();
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
get timeToRefresh() {
|
|
29
|
-
if (!this._token) return;
|
|
30
|
-
const payload = jwt.decode(this._token);
|
|
31
|
-
if (!payload || typeof payload == "string") return;
|
|
32
|
-
const expiry = payload.expiry;
|
|
33
|
-
if (!expiry || typeof expiry !== "number") return;
|
|
34
|
-
const timeWindow = 60 * 1000;
|
|
35
|
-
const timeToRefresh = expiry - Date.now() - timeWindow;
|
|
36
|
-
return Math.max(timeToRefresh, timeWindow);
|
|
37
|
-
}
|
|
38
|
-
async scheduleTokenRefresh() {
|
|
39
|
-
var _process$env$RUN_ENVI;
|
|
40
|
-
if (((_process$env$RUN_ENVI = process.env.RUN_ENVIRONMENT) === null || _process$env$RUN_ENVI === void 0 ? void 0 : _process$env$RUN_ENVI.toLowerCase()) !== "authoring") return;
|
|
41
|
-
const timeToRefresh = this.timeToRefresh;
|
|
42
|
-
if (timeToRefresh === undefined) return;
|
|
43
|
-
if (this.tokenRefreshTimeout) clearTimeout(this.tokenRefreshTimeout);
|
|
44
|
-
this.tokenRefreshTimeout = setTimeout(async () => {
|
|
45
|
-
const result = await this.refreshToken();
|
|
46
|
-
if (result && result.isErr()) {
|
|
47
|
-
console.error(`[Internal Error] ${result.error}`);
|
|
48
|
-
return;
|
|
49
|
-
}
|
|
50
|
-
await this.scheduleTokenRefresh();
|
|
51
|
-
}, timeToRefresh);
|
|
52
|
-
}
|
|
53
|
-
async refreshToken() {
|
|
54
|
-
var _process$env$RUN_ENVI2;
|
|
55
|
-
if (((_process$env$RUN_ENVI2 = process.env.RUN_ENVIRONMENT) === null || _process$env$RUN_ENVI2 === void 0 ? void 0 : _process$env$RUN_ENVI2.toLowerCase()) !== "authoring") return;
|
|
56
|
-
const res = await this.fetchWithToken(this.refreshTokenPath, {
|
|
57
|
-
method: "GET"
|
|
58
|
-
});
|
|
59
|
-
if (res.status === 401) {
|
|
60
|
-
return (0, _neverthrow.err)("Unauthorized");
|
|
61
|
-
}
|
|
62
|
-
const jsonResult = await _neverthrow.ResultAsync.fromPromise(res.json(), () => "not json");
|
|
63
|
-
if (jsonResult.isErr()) return;
|
|
64
|
-
const newToken = jsonResult.value.token;
|
|
65
|
-
if (newToken) this._token = newToken;
|
|
66
|
-
}
|
|
67
|
-
fetchWithToken(...[input, init]) {
|
|
68
|
-
const headers = new Headers(init === null || init === void 0 ? void 0 : init.headers);
|
|
69
|
-
headers.set("Authorization", `Bearer ${this.token}`);
|
|
70
|
-
return (0, _crossFetch.default)(input, {
|
|
71
|
-
...init,
|
|
72
|
-
headers
|
|
73
|
-
});
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
const backendFunctionsPath = `${process.env.FUNCTIONS_DOMAIN}/api/${process.env.INTUNED_WORKSPACE_ID}/functions/${process.env.INTUNED_INTEGRATION_ID}`;
|
|
77
|
-
const backendFunctionsTokenManager = exports.backendFunctionsTokenManager = new JwtTokenManager(`${backendFunctionsPath}/refreshBackendFunctionsToken`);
|
|
78
|
-
backendFunctionsTokenManager.token = process.env.INTUNED_AUTHORING_SESSION_BACKEND_FUNCTIONS_TOKEN;
|
|
79
|
-
function callBackendFunctionWithToken(path, init) {
|
|
80
|
-
return backendFunctionsTokenManager.fetchWithToken(`${backendFunctionsPath}/${path}`, init);
|
|
81
|
-
}
|
|
@@ -1,19 +0,0 @@
|
|
|
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>;
|
|
@@ -1,17 +0,0 @@
|
|
|
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 && 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; }
|
|
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
|
-
});
|
package/dist/common/telemetry.js
DELETED
|
@@ -1,32 +0,0 @@
|
|
|
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 && 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; }
|
|
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
DELETED
|
@@ -1,4 +0,0 @@
|
|
|
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
DELETED
|
@@ -1,69 +0,0 @@
|
|
|
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");
|
package/dist/runtime/RunError.js
DELETED
|
@@ -1,19 +0,0 @@
|
|
|
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("", {});
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare function getDownloadDirectoryPath(): string;
|
|
@@ -1,19 +0,0 @@
|
|
|
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
|
-
}
|
package/dist/runtime/enums.d.js
DELETED
package/dist/runtime/enums.js
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
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
|
-
}({});
|
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
var _vitest = require("vitest");
|
|
4
|
-
var _asyncLocalStorage = require("../common/asyncLocalStorage");
|
|
5
|
-
var _index = require("./index");
|
|
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, _index.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, _index.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, _index.extendPayload)({
|
|
38
|
-
api: "test-api",
|
|
39
|
-
parameters: {}
|
|
40
|
-
});
|
|
41
|
-
(0, _index.extendPayload)({
|
|
42
|
-
api: "test-api",
|
|
43
|
-
parameters: {}
|
|
44
|
-
});
|
|
45
|
-
(0, _index.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
|
-
});
|
package/dist/runtime/export.d.js
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
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
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare function extendTimeout(): void;
|
|
@@ -1,26 +0,0 @@
|
|
|
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 || timeoutInfo.timeoutTimestamp === undefined || timeoutInfo.timeoutDuration === undefined || timeoutInfo.extendTimeoutCallback === undefined) {
|
|
18
|
-
return;
|
|
19
|
-
}
|
|
20
|
-
const newTimeoutStamp = Date.now() + timeoutInfo.timeoutDuration;
|
|
21
|
-
if (newTimeoutStamp - timeoutInfo.timeoutTimestamp < _DEBOUNCE_TIME) {
|
|
22
|
-
return;
|
|
23
|
-
}
|
|
24
|
-
timeoutInfo.timeoutTimestamp = newTimeoutStamp;
|
|
25
|
-
void timeoutInfo.extendTimeoutCallback().catch(() => undefined);
|
|
26
|
-
}
|