@intuned/runtime 1.3.16 → 1.3.18-interface.6
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/bin/intuned +0 -0
- package/bin/intuned-interface +7 -0
- package/dist/chunk-6ZRJOUQS.mjs +16 -0
- package/dist/chunk-6ZRJOUQS.mjs.map +1 -0
- package/dist/chunk-7YL2JUTE.mjs +146 -0
- package/dist/chunk-7YL2JUTE.mjs.map +1 -0
- package/dist/chunk-B3T6RXPC.mjs +794 -0
- package/dist/chunk-B3T6RXPC.mjs.map +1 -0
- package/dist/chunk-FGV5T6SI.mjs +27 -0
- package/dist/chunk-FGV5T6SI.mjs.map +1 -0
- package/dist/chunk-G4PO5RIV.mjs +85 -0
- package/dist/chunk-G4PO5RIV.mjs.map +1 -0
- package/dist/chunk-LZOMFHX3.mjs +38 -0
- package/dist/chunk-LZOMFHX3.mjs.map +1 -0
- package/dist/{common/formatZodError.js → chunk-NDMVGENG.mjs} +9 -9
- package/dist/chunk-NDMVGENG.mjs.map +1 -0
- package/dist/chunk-W4UX6G4X.mjs +17 -0
- package/dist/chunk-W4UX6G4X.mjs.map +1 -0
- package/dist/chunk-XC75QGFG.mjs +1106 -0
- package/dist/chunk-XC75QGFG.mjs.map +1 -0
- package/dist/chunk-XOAZ2MGA.mjs +59 -0
- package/dist/chunk-XOAZ2MGA.mjs.map +1 -0
- package/dist/commands/interface/run.d.mts +3 -0
- package/dist/commands/interface/run.d.ts +3 -1
- package/dist/commands/interface/run.js +2060 -178
- package/dist/commands/interface/run.js.map +1 -0
- package/dist/commands/interface/run.mjs +255 -0
- package/dist/commands/interface/run.mjs.map +1 -0
- package/dist/common/asyncLocalStorage/index.d.mts +17 -0
- package/dist/common/asyncLocalStorage/index.d.ts +9 -8
- package/dist/common/asyncLocalStorage/index.js +34 -9
- package/dist/common/asyncLocalStorage/index.js.map +1 -0
- package/dist/common/asyncLocalStorage/index.mjs +12 -0
- package/dist/common/asyncLocalStorage/index.mjs.map +1 -0
- package/dist/common/binStartupScript.d.mts +2 -0
- package/dist/common/binStartupScript.d.ts +2 -1
- package/dist/common/binStartupScript.js +127 -11
- package/dist/common/binStartupScript.js.map +1 -0
- package/dist/common/binStartupScript.mjs +135 -0
- package/dist/common/binStartupScript.mjs.map +1 -0
- package/dist/common/cleanEnvironmentVariables.d.mts +3 -0
- package/dist/common/cleanEnvironmentVariables.d.ts +3 -1
- package/dist/common/cleanEnvironmentVariables.js +30 -7
- package/dist/common/cleanEnvironmentVariables.js.map +1 -0
- package/dist/common/cleanEnvironmentVariables.mjs +8 -0
- package/dist/common/cleanEnvironmentVariables.mjs.map +1 -0
- package/dist/common/constants.d.mts +13 -0
- package/dist/common/constants.d.ts +13 -10
- package/dist/common/constants.js +58 -14
- package/dist/common/constants.js.map +1 -0
- package/dist/common/constants.mjs +28 -0
- package/dist/common/constants.mjs.map +1 -0
- package/dist/common/contextStorageStateHelpers.d.mts +24 -0
- package/dist/common/contextStorageStateHelpers.d.ts +8 -5
- package/dist/common/contextStorageStateHelpers.js +51 -23
- package/dist/common/contextStorageStateHelpers.js.map +1 -0
- package/dist/common/contextStorageStateHelpers.mjs +10 -0
- package/dist/common/contextStorageStateHelpers.mjs.map +1 -0
- package/dist/common/jwtTokenManager.d.mts +19 -0
- package/dist/common/jwtTokenManager.d.ts +6 -4
- package/dist/common/jwtTokenManager.js +112 -40
- package/dist/common/jwtTokenManager.js.map +1 -0
- package/dist/common/jwtTokenManager.mjs +11 -0
- package/dist/common/jwtTokenManager.mjs.map +1 -0
- package/dist/common/runApi/index.d.mts +11 -0
- package/dist/common/runApi/index.d.ts +10 -10
- package/dist/common/runApi/index.js +1776 -93
- package/dist/common/runApi/index.js.map +1 -0
- package/dist/common/runApi/index.mjs +18 -0
- package/dist/common/runApi/index.mjs.map +1 -0
- package/dist/common/settingsSchema.d.mts +536 -0
- package/dist/common/settingsSchema.d.ts +9 -6
- package/dist/common/settingsSchema.js +55 -20
- package/dist/common/settingsSchema.js.map +1 -0
- package/dist/common/settingsSchema.mjs +10 -0
- package/dist/common/settingsSchema.mjs.map +1 -0
- package/dist/common/telemetry.d.mts +6 -0
- package/dist/common/telemetry.d.ts +6 -3
- package/dist/common/telemetry.js +41 -9
- package/dist/common/telemetry.js.map +1 -0
- package/dist/common/telemetry.mjs +31 -0
- package/dist/common/telemetry.mjs.map +1 -0
- package/dist/export.d-BAUMB-lG.d.mts +140 -0
- package/dist/export.d-BAUMB-lG.d.ts +140 -0
- package/dist/index.d.mts +6 -0
- package/dist/index.d.ts +6 -5
- package/dist/index.js +783 -98
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +47 -0
- package/dist/index.mjs.map +1 -0
- package/dist/runtime/index.d.mts +163 -0
- package/dist/runtime/index.d.ts +163 -10
- package/dist/runtime/index.js +779 -88
- package/dist/runtime/index.js.map +1 -0
- package/dist/runtime/index.mjs +42 -0
- package/dist/runtime/index.mjs.map +1 -0
- package/package.json +80 -23
- package/.babelrc +0 -21
- package/.eslintignore +0 -10
- package/.eslintrc.js +0 -39
- package/InterfaceTemplate/index.playwright.ts +0 -6
- package/InterfaceTemplate/utils.ts +0 -61
- package/dist/commands/api/run.d.ts +0 -6
- package/dist/commands/api/run.js +0 -123
- package/dist/commands/auth-sessions/load.d.ts +0 -2
- package/dist/commands/auth-sessions/load.js +0 -35
- package/dist/commands/auth-sessions/run-check.d.ts +0 -2
- package/dist/commands/auth-sessions/run-check.js +0 -74
- package/dist/commands/auth-sessions/run-create.d.ts +0 -2
- package/dist/commands/auth-sessions/run-create.js +0 -78
- 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 -1
- package/dist/commands/build.js +0 -84
- package/dist/commands/common/browserUtils.d.ts +0 -14
- package/dist/commands/common/browserUtils.js +0 -58
- package/dist/commands/common/getFirstLineNumber.d.ts +0 -9
- package/dist/commands/common/getFirstLineNumber.js +0 -101
- package/dist/commands/common/getFirstLineNumber.test.js +0 -228
- package/dist/commands/common/projectExclusions.d.ts +0 -2
- package/dist/commands/common/projectExclusions.js +0 -8
- package/dist/commands/common/sendMessageToClient.d.ts +0 -1
- package/dist/commands/common/sendMessageToClient.js +0 -10
- package/dist/commands/common/tsNodeImport.d.ts +0 -2
- package/dist/commands/common/tsNodeImport.js +0 -34
- 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 -31
- package/dist/commands/common/utils/template.d.ts +0 -2
- package/dist/commands/common/utils/template.js +0 -31
- package/dist/commands/common/utils/unixSocket.d.ts +0 -23
- package/dist/commands/common/utils/unixSocket.js +0 -87
- package/dist/commands/get-headless-user-agent.d.ts +0 -1
- package/dist/commands/get-headless-user-agent.js +0 -18
- package/dist/commands/intuned-cli/commands/attempt.command.d.ts +0 -1
- package/dist/commands/intuned-cli/commands/attempt.command.js +0 -8
- package/dist/commands/intuned-cli/commands/attempt_api.command.d.ts +0 -1
- package/dist/commands/intuned-cli/commands/attempt_api.command.js +0 -30
- package/dist/commands/intuned-cli/commands/attempt_authsession.command.d.ts +0 -1
- package/dist/commands/intuned-cli/commands/attempt_authsession.command.js +0 -8
- package/dist/commands/intuned-cli/commands/attempt_authsession_check.command.d.ts +0 -1
- package/dist/commands/intuned-cli/commands/attempt_authsession_check.command.js +0 -19
- package/dist/commands/intuned-cli/commands/attempt_authsession_create.command.d.ts +0 -1
- package/dist/commands/intuned-cli/commands/attempt_authsession_create.command.js +0 -24
- package/dist/commands/intuned-cli/commands/authsession.command.d.ts +0 -1
- package/dist/commands/intuned-cli/commands/authsession.command.js +0 -8
- package/dist/commands/intuned-cli/commands/authsession_record.command.d.ts +0 -1
- package/dist/commands/intuned-cli/commands/authsession_record.command.js +0 -32
- package/dist/commands/intuned-cli/commands/build.command.d.ts +0 -1
- package/dist/commands/intuned-cli/commands/build.command.js +0 -12
- package/dist/commands/intuned-cli/commands/command.d.ts +0 -2
- package/dist/commands/intuned-cli/commands/command.js +0 -9
- package/dist/commands/intuned-cli/commands/deploy.command.d.ts +0 -1
- package/dist/commands/intuned-cli/commands/deploy.command.js +0 -38
- package/dist/commands/intuned-cli/commands/index.d.ts +0 -18
- package/dist/commands/intuned-cli/commands/index.js +0 -203
- package/dist/commands/intuned-cli/commands/init.command.d.ts +0 -1
- package/dist/commands/intuned-cli/commands/init.command.js +0 -13
- package/dist/commands/intuned-cli/commands/run.command.d.ts +0 -1
- package/dist/commands/intuned-cli/commands/run.command.js +0 -8
- package/dist/commands/intuned-cli/commands/run_api.command.d.ts +0 -1
- package/dist/commands/intuned-cli/commands/run_api.command.js +0 -46
- package/dist/commands/intuned-cli/commands/run_authsession.command.d.ts +0 -31
- package/dist/commands/intuned-cli/commands/run_authsession.command.js +0 -17
- package/dist/commands/intuned-cli/commands/run_authsession_create.command.d.ts +0 -1
- package/dist/commands/intuned-cli/commands/run_authsession_create.command.js +0 -35
- package/dist/commands/intuned-cli/commands/run_authsession_update.command.d.ts +0 -1
- package/dist/commands/intuned-cli/commands/run_authsession_update.command.js +0 -35
- package/dist/commands/intuned-cli/commands/run_authsession_validate.command.d.ts +0 -1
- package/dist/commands/intuned-cli/commands/run_authsession_validate.command.js +0 -33
- package/dist/commands/intuned-cli/commands/save.command.d.ts +0 -13
- package/dist/commands/intuned-cli/commands/save.command.js +0 -42
- package/dist/commands/intuned-cli/commands/types.d.ts +0 -35
- package/dist/commands/intuned-cli/commands/types.js +0 -31
- package/dist/commands/intuned-cli/constants/index.d.ts +0 -17
- package/dist/commands/intuned-cli/constants/index.js +0 -25
- package/dist/commands/intuned-cli/controller/__test__/api.test.js +0 -397
- package/dist/commands/intuned-cli/controller/__test__/authSession.test.js +0 -1059
- package/dist/commands/intuned-cli/controller/api.d.ts +0 -42
- package/dist/commands/intuned-cli/controller/api.js +0 -191
- package/dist/commands/intuned-cli/controller/authSession.d.ts +0 -209
- package/dist/commands/intuned-cli/controller/authSession.js +0 -424
- package/dist/commands/intuned-cli/controller/build.d.ts +0 -1
- package/dist/commands/intuned-cli/controller/build.js +0 -36
- package/dist/commands/intuned-cli/controller/deploy.d.ts +0 -5
- package/dist/commands/intuned-cli/controller/deploy.js +0 -276
- package/dist/commands/intuned-cli/controller/index.d.ts +0 -1
- package/dist/commands/intuned-cli/controller/index.js +0 -46
- package/dist/commands/intuned-cli/controller/save.d.ts +0 -17
- package/dist/commands/intuned-cli/controller/save.js +0 -351
- package/dist/commands/intuned-cli/helpers/__test__/browser.test.js +0 -114
- package/dist/commands/intuned-cli/helpers/__test__/tracing.test.js +0 -40
- package/dist/commands/intuned-cli/helpers/api.d.ts +0 -3
- package/dist/commands/intuned-cli/helpers/api.js +0 -19
- package/dist/commands/intuned-cli/helpers/auth.d.ts +0 -46
- package/dist/commands/intuned-cli/helpers/auth.js +0 -144
- package/dist/commands/intuned-cli/helpers/backend.d.ts +0 -8
- package/dist/commands/intuned-cli/helpers/backend.js +0 -27
- package/dist/commands/intuned-cli/helpers/browser.d.ts +0 -15
- package/dist/commands/intuned-cli/helpers/browser.js +0 -64
- package/dist/commands/intuned-cli/helpers/context.d.ts +0 -3
- package/dist/commands/intuned-cli/helpers/context.js +0 -33
- package/dist/commands/intuned-cli/helpers/errors.d.ts +0 -16
- package/dist/commands/intuned-cli/helpers/errors.js +0 -44
- package/dist/commands/intuned-cli/helpers/index.d.ts +0 -12
- package/dist/commands/intuned-cli/helpers/index.js +0 -137
- package/dist/commands/intuned-cli/helpers/intunedJson.d.ts +0 -39
- package/dist/commands/intuned-cli/helpers/intunedJson.js +0 -20
- package/dist/commands/intuned-cli/helpers/proxy.d.ts +0 -5
- package/dist/commands/intuned-cli/helpers/proxy.js +0 -23
- package/dist/commands/intuned-cli/helpers/terminal.d.ts +0 -5
- package/dist/commands/intuned-cli/helpers/terminal.js +0 -13
- package/dist/commands/intuned-cli/helpers/timeout.d.ts +0 -1
- package/dist/commands/intuned-cli/helpers/timeout.js +0 -23
- package/dist/commands/intuned-cli/helpers/traces.d.ts +0 -2
- package/dist/commands/intuned-cli/helpers/traces.js +0 -32
- package/dist/commands/intuned-cli/helpers/validation.d.ts +0 -2
- package/dist/commands/intuned-cli/helpers/validation.js +0 -14
- package/dist/commands/intuned-cli/helpers/wrapper.d.ts +0 -2
- package/dist/commands/intuned-cli/helpers/wrapper.js +0 -66
- package/dist/commands/intuned-cli/index.d.ts +0 -1
- package/dist/commands/intuned-cli/index.js +0 -16
- package/dist/commands/intuned-cli/main.d.ts +0 -1
- package/dist/commands/intuned-cli/main.js +0 -23
- package/dist/commands/intuned-cli/types.d.ts +0 -41
- package/dist/commands/intuned-cli/types.js +0 -12
- package/dist/commands/ts-check.d.ts +0 -2
- package/dist/commands/ts-check.js +0 -56
- 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.d.ts +0 -8
- 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.d.ts +0 -8
- package/dist/common/Logger/types.js +0 -5
- package/dist/common/backendFunctions/getAuthSessionParameters.d.ts +0 -1
- package/dist/common/backendFunctions/getAuthSessionParameters.js +0 -38
- package/dist/common/extension/extensionsHelpers.d.ts +0 -11
- package/dist/common/extension/extensionsHelpers.js +0 -147
- package/dist/common/extension/intunedExtensionServer.d.ts +0 -24
- package/dist/common/extension/intunedExtensionServer.js +0 -178
- package/dist/common/extension/types.d.ts +0 -212
- package/dist/common/extension/types.js +0 -51
- package/dist/common/formatZodError.d.ts +0 -2
- package/dist/common/intunedJson.d.ts +0 -229
- package/dist/common/intunedJson.js +0 -133
- package/dist/common/launchBrowser.d.ts +0 -31
- package/dist/common/launchBrowser.js +0 -207
- package/dist/common/playwrightContext.d.ts +0 -31
- package/dist/common/playwrightContext.js +0 -144
- package/dist/common/runApi/errors.d.ts +0 -72
- package/dist/common/runApi/errors.js +0 -169
- package/dist/common/runApi/importUsingImportFunction.d.ts +0 -9
- package/dist/common/runApi/importUsingImportFunction.js +0 -46
- package/dist/common/runApi/types.d.ts +0 -830
- package/dist/common/runApi/types.js +0 -73
- package/dist/common/setupContextHook.d.ts +0 -17
- package/dist/common/setupContextHook.js +0 -22
- package/dist/runtime/RunError.d.ts +0 -5
- package/dist/runtime/RunError.js +0 -19
- package/dist/runtime/attemptStore.d.ts +0 -2
- package/dist/runtime/attemptStore.js +0 -23
- package/dist/runtime/captcha.d.ts +0 -15
- package/dist/runtime/captcha.js +0 -191
- package/dist/runtime/captcha.test.js +0 -821
- 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.d.ts +0 -11
- package/dist/runtime/enums.js +0 -18
- package/dist/runtime/executionHelpers.test.js +0 -52
- package/dist/runtime/export.d.js +0 -5
- package/dist/runtime/export.d.ts +0 -284
- 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 -23
- package/dist/runtime/getAiGatewayConfig.d.ts +0 -10
- package/dist/runtime/getAiGatewayConfig.js +0 -16
- package/dist/runtime/getAuthSessionParameters.d.ts +0 -1
- package/dist/runtime/getAuthSessionParameters.js +0 -20
- package/dist/runtime/persistentStore.d.ts +0 -2
- package/dist/runtime/persistentStore.js +0 -37
- package/dist/runtime/persistentStore.test.js +0 -101
- package/dist/runtime/runInfo.d.ts +0 -2
- package/dist/runtime/runInfo.js +0 -21
- package/template.tsconfig.json +0 -11
- package/tsconfig.eslint.json +0 -5
- package/tsconfig.json +0 -25
- package/typedoc.json +0 -49
- /package/dist/common/assets/{browser_scripts.js → assets/browser_scripts.js} +0 -0
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import {
|
|
2
|
+
API_BASE_URL_ENV_VAR_KEY,
|
|
3
|
+
API_FOLDER_NAME,
|
|
4
|
+
API_KEY_ENV_VAR_KEY,
|
|
5
|
+
API_KEY_HEADER_NAME,
|
|
6
|
+
AUTH_SESSIONS_FOLDER_NAME,
|
|
7
|
+
AUTH_SESSIONS_INSTANCES_FOLDER_NAME,
|
|
8
|
+
AUTH_TOKEN_ENV_VAR_KEY,
|
|
9
|
+
CLI_ENV_VAR_KEY,
|
|
10
|
+
EXTENSION_PATH_ENV_VAR_KEY,
|
|
11
|
+
PROJECT_ID_ENV_VAR_KEY,
|
|
12
|
+
WORKSPACE_ID_ENV_VAR_KEY
|
|
13
|
+
} from "../chunk-FGV5T6SI.mjs";
|
|
14
|
+
import "../chunk-LZOMFHX3.mjs";
|
|
15
|
+
export {
|
|
16
|
+
API_BASE_URL_ENV_VAR_KEY,
|
|
17
|
+
API_FOLDER_NAME,
|
|
18
|
+
API_KEY_ENV_VAR_KEY,
|
|
19
|
+
API_KEY_HEADER_NAME,
|
|
20
|
+
AUTH_SESSIONS_FOLDER_NAME,
|
|
21
|
+
AUTH_SESSIONS_INSTANCES_FOLDER_NAME,
|
|
22
|
+
AUTH_TOKEN_ENV_VAR_KEY,
|
|
23
|
+
CLI_ENV_VAR_KEY,
|
|
24
|
+
EXTENSION_PATH_ENV_VAR_KEY,
|
|
25
|
+
PROJECT_ID_ENV_VAR_KEY,
|
|
26
|
+
WORKSPACE_ID_ENV_VAR_KEY
|
|
27
|
+
};
|
|
28
|
+
//# sourceMappingURL=constants.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import * as playwright from 'playwright';
|
|
2
|
+
import { RunApiStorageState } from '@intuned/runtime-interface';
|
|
3
|
+
|
|
4
|
+
interface StorageEntry {
|
|
5
|
+
name: string;
|
|
6
|
+
value: string;
|
|
7
|
+
}
|
|
8
|
+
interface LocalStorageState {
|
|
9
|
+
origin: string;
|
|
10
|
+
localStorage: StorageEntry[];
|
|
11
|
+
}
|
|
12
|
+
interface SessionStorageState {
|
|
13
|
+
origin: string;
|
|
14
|
+
sessionStorage: StorageEntry[];
|
|
15
|
+
}
|
|
16
|
+
interface StorageState {
|
|
17
|
+
cookies?: playwright.Cookie[] | null;
|
|
18
|
+
origins?: LocalStorageState[] | null;
|
|
19
|
+
sessionStorage?: SessionStorageState[] | null;
|
|
20
|
+
}
|
|
21
|
+
declare function setStorageState(context: playwright.BrowserContext, state: RunApiStorageState): Promise<void>;
|
|
22
|
+
declare function getStorageState(context: playwright.BrowserContext): Promise<RunApiStorageState>;
|
|
23
|
+
|
|
24
|
+
export { type StorageState, getStorageState, setStorageState };
|
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
import * as playwright from
|
|
1
|
+
import * as playwright from 'playwright';
|
|
2
|
+
import { RunApiStorageState } from '@intuned/runtime-interface';
|
|
3
|
+
|
|
2
4
|
interface StorageEntry {
|
|
3
5
|
name: string;
|
|
4
6
|
value: string;
|
|
@@ -11,11 +13,12 @@ interface SessionStorageState {
|
|
|
11
13
|
origin: string;
|
|
12
14
|
sessionStorage: StorageEntry[];
|
|
13
15
|
}
|
|
14
|
-
|
|
16
|
+
interface StorageState {
|
|
15
17
|
cookies?: playwright.Cookie[] | null;
|
|
16
18
|
origins?: LocalStorageState[] | null;
|
|
17
19
|
sessionStorage?: SessionStorageState[] | null;
|
|
18
20
|
}
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
21
|
+
declare function setStorageState(context: playwright.BrowserContext, state: RunApiStorageState): Promise<void>;
|
|
22
|
+
declare function getStorageState(context: playwright.BrowserContext): Promise<RunApiStorageState>;
|
|
23
|
+
|
|
24
|
+
export { type StorageState, getStorageState, setStorageState };
|
|
@@ -1,10 +1,28 @@
|
|
|
1
|
-
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __export = (target, all) => {
|
|
6
|
+
for (var name in all)
|
|
7
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
8
|
+
};
|
|
9
|
+
var __copyProps = (to, from, except, desc) => {
|
|
10
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
|
+
for (let key of __getOwnPropNames(from))
|
|
12
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
13
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
14
|
+
}
|
|
15
|
+
return to;
|
|
16
|
+
};
|
|
17
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
2
18
|
|
|
3
|
-
|
|
4
|
-
|
|
19
|
+
// src/common/contextStorageStateHelpers.ts
|
|
20
|
+
var contextStorageStateHelpers_exports = {};
|
|
21
|
+
__export(contextStorageStateHelpers_exports, {
|
|
22
|
+
getStorageState: () => getStorageState,
|
|
23
|
+
setStorageState: () => setStorageState
|
|
5
24
|
});
|
|
6
|
-
exports
|
|
7
|
-
exports.setStorageState = setStorageState;
|
|
25
|
+
module.exports = __toCommonJS(contextStorageStateHelpers_exports);
|
|
8
26
|
async function setStorageState(context, state) {
|
|
9
27
|
if ("cookies" in state && state.cookies) {
|
|
10
28
|
await context.addCookies(state.cookies);
|
|
@@ -13,17 +31,23 @@ async function setStorageState(context, state) {
|
|
|
13
31
|
if ("origins" in state && state.origins) {
|
|
14
32
|
for (const originData of state.origins || []) {
|
|
15
33
|
const origin = originData.origin;
|
|
16
|
-
await page.route(
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
34
|
+
await page.route(
|
|
35
|
+
`${origin}/*`,
|
|
36
|
+
(route) => route.fulfill({
|
|
37
|
+
body: "<html><head><title>Set Storage</title></head><body><h1>Set Storage</h1></body></html>",
|
|
38
|
+
contentType: "text/html",
|
|
39
|
+
status: 200
|
|
40
|
+
})
|
|
41
|
+
);
|
|
21
42
|
try {
|
|
22
43
|
await page.goto(origin);
|
|
23
44
|
for (const item of originData.localStorage) {
|
|
24
|
-
await page.evaluate(
|
|
25
|
-
|
|
26
|
-
|
|
45
|
+
await page.evaluate(
|
|
46
|
+
([key, value]) => {
|
|
47
|
+
window.localStorage.setItem(key, value);
|
|
48
|
+
},
|
|
49
|
+
[item.name, item.value]
|
|
50
|
+
);
|
|
27
51
|
}
|
|
28
52
|
} finally {
|
|
29
53
|
await page.unroute(`${origin}/*`);
|
|
@@ -31,11 +55,8 @@ async function setStorageState(context, state) {
|
|
|
31
55
|
}
|
|
32
56
|
}
|
|
33
57
|
if ("sessionStorage" in state && state.sessionStorage) {
|
|
34
|
-
await context.addInitScript(storage => {
|
|
35
|
-
for (const {
|
|
36
|
-
origin,
|
|
37
|
-
sessionStorage
|
|
38
|
-
} of storage) {
|
|
58
|
+
await context.addInitScript((storage) => {
|
|
59
|
+
for (const { origin, sessionStorage } of storage) {
|
|
39
60
|
if (window.location.origin === origin) {
|
|
40
61
|
for (const item of sessionStorage) {
|
|
41
62
|
const value = window.sessionStorage.getItem(item.name);
|
|
@@ -50,7 +71,10 @@ async function setStorageState(context, state) {
|
|
|
50
71
|
await page.close();
|
|
51
72
|
}
|
|
52
73
|
async function getStorageState(context) {
|
|
53
|
-
const result = {
|
|
74
|
+
const result = {
|
|
75
|
+
cookies: [],
|
|
76
|
+
origins: []
|
|
77
|
+
};
|
|
54
78
|
const storageState = await context.storageState();
|
|
55
79
|
result.cookies = storageState.cookies;
|
|
56
80
|
result.origins = storageState.origins;
|
|
@@ -60,9 +84,7 @@ async function getStorageState(context) {
|
|
|
60
84
|
if (page.isClosed()) continue;
|
|
61
85
|
try {
|
|
62
86
|
const sessionData = await page.evaluate(() => {
|
|
63
|
-
const items = {
|
|
64
|
-
...window.sessionStorage
|
|
65
|
-
};
|
|
87
|
+
const items = { ...window.sessionStorage };
|
|
66
88
|
return {
|
|
67
89
|
origin: window.location.origin,
|
|
68
90
|
sessionStorage: Object.entries(items).map(([name, value]) => ({
|
|
@@ -78,4 +100,10 @@ async function getStorageState(context) {
|
|
|
78
100
|
}
|
|
79
101
|
result["sessionStorage"] = sessionDataList;
|
|
80
102
|
return result;
|
|
81
|
-
}
|
|
103
|
+
}
|
|
104
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
105
|
+
0 && (module.exports = {
|
|
106
|
+
getStorageState,
|
|
107
|
+
setStorageState
|
|
108
|
+
});
|
|
109
|
+
//# sourceMappingURL=contextStorageStateHelpers.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/common/contextStorageStateHelpers.ts"],"sourcesContent":["import type * as playwright from \"playwright\";\nimport type { RunApiStorageState } from \"@intuned/runtime-interface\";\n\ninterface StorageEntry {\n name: string;\n value: string;\n}\n\ninterface LocalStorageState {\n origin: string;\n localStorage: StorageEntry[];\n}\n\ninterface SessionStorageState {\n origin: string;\n sessionStorage: StorageEntry[];\n}\n\nexport interface StorageState {\n cookies?: playwright.Cookie[] | null;\n origins?: LocalStorageState[] | null;\n sessionStorage?: SessionStorageState[] | null;\n}\n\nexport async function setStorageState(\n context: playwright.BrowserContext,\n state: RunApiStorageState\n): Promise<void> {\n if (\"cookies\" in state && state.cookies) {\n await context.addCookies(state.cookies);\n }\n const page = await context.newPage();\n if (\"origins\" in state && state.origins) {\n for (const originData of state.origins || []) {\n const origin = originData.origin;\n await page.route(`${origin}/*`, (route) =>\n route.fulfill({\n body: \"<html><head><title>Set Storage</title></head><body><h1>Set Storage</h1></body></html>\",\n contentType: \"text/html\",\n status: 200,\n })\n );\n\n try {\n await page.goto(origin);\n\n for (const item of originData.localStorage) {\n await page.evaluate(\n ([key, value]) => {\n window.localStorage.setItem(key, value);\n },\n [item.name, item.value]\n );\n }\n } finally {\n await page.unroute(`${origin}/*`);\n }\n }\n }\n\n if (\"sessionStorage\" in state && state.sessionStorage) {\n await context.addInitScript((storage) => {\n for (const { origin, sessionStorage } of storage) {\n if (window.location.origin === origin) {\n for (const item of sessionStorage) {\n const value = window.sessionStorage.getItem(item.name);\n if (!value) {\n window.sessionStorage.setItem(item.name, item.value);\n }\n }\n }\n }\n }, state.sessionStorage);\n }\n\n await page.close();\n}\n\nexport async function getStorageState(\n context: playwright.BrowserContext\n): Promise<RunApiStorageState> {\n const result: RunApiStorageState = {\n cookies: [],\n origins: [],\n };\n const storageState = await context.storageState();\n result.cookies = storageState.cookies as playwright.Cookie[];\n result.origins = storageState.origins as LocalStorageState[];\n\n const sessionDataList: SessionStorageState[] = [];\n const pages = await context.pages();\n\n for (const page of pages) {\n if (page.isClosed()) continue;\n\n try {\n const sessionData: SessionStorageState = await page.evaluate(() => {\n const items = { ...window.sessionStorage };\n return {\n origin: window.location.origin,\n sessionStorage: Object.entries(items).map(([name, value]) => ({\n name,\n value,\n })),\n };\n });\n\n sessionDataList.push(sessionData);\n } catch (error) {\n console.error(\"Error getting sessionStorage:\", error);\n }\n }\n\n result[\"sessionStorage\"] = sessionDataList;\n\n return result;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAwBA,eAAsB,gBACpB,SACA,OACe;AACf,MAAI,aAAa,SAAS,MAAM,SAAS;AACvC,UAAM,QAAQ,WAAW,MAAM,OAAO;AAAA,EACxC;AACA,QAAM,OAAO,MAAM,QAAQ,QAAQ;AACnC,MAAI,aAAa,SAAS,MAAM,SAAS;AACvC,eAAW,cAAc,MAAM,WAAW,CAAC,GAAG;AAC5C,YAAM,SAAS,WAAW;AAC1B,YAAM,KAAK;AAAA,QAAM,GAAG,MAAM;AAAA,QAAM,CAAC,UAC/B,MAAM,QAAQ;AAAA,UACZ,MAAM;AAAA,UACN,aAAa;AAAA,U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AO;AAAA,UACL,QAAQ,OAAO,SAAS;AAAA,UACxB,gBAAgB,OAAO,QAAQ,KAAK,EAAE,IAAI,CAAC,CAAC,MAAM,KAAK,OAAO;AAAA,YAC5D;AAAA,YACA;AAAA,UACF,EAAE;AAAA,QACJ;AAAA,MACF,CAAC;AAED,sBAAgB,KAAK,WAAW;AAAA,IAClC,SAAS,OAAO;AACd,cAAQ,MAAM,iCAAiC,KAAK;AAAA,IACtD;AAAA,EACF;AAEA,SAAO,gBAAgB,IAAI;AAE3B,SAAO;AACT;","names":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import fetch from 'cross-fetch';
|
|
2
|
+
|
|
3
|
+
declare class JwtTokenManager {
|
|
4
|
+
private _token;
|
|
5
|
+
private tokenRefreshTimeout;
|
|
6
|
+
private refreshTokenPath;
|
|
7
|
+
constructor(refreshTokenPath: string);
|
|
8
|
+
get token(): string | undefined;
|
|
9
|
+
set token(newToken: string | undefined);
|
|
10
|
+
private get timeToRefresh();
|
|
11
|
+
private scheduleTokenRefresh;
|
|
12
|
+
private refreshToken;
|
|
13
|
+
fetchWithToken(...[input, init]: Parameters<typeof fetch>): Promise<Response>;
|
|
14
|
+
get backendFunctionsBaseUrl(): string | undefined;
|
|
15
|
+
}
|
|
16
|
+
declare const backendFunctionsTokenManager: JwtTokenManager;
|
|
17
|
+
declare function callBackendFunctionWithToken(path: string, init?: Parameters<typeof fetch>[1]): Promise<Response>;
|
|
18
|
+
|
|
19
|
+
export { backendFunctionsTokenManager, callBackendFunctionWithToken };
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import fetch from
|
|
1
|
+
import fetch from 'cross-fetch';
|
|
2
|
+
|
|
2
3
|
declare class JwtTokenManager {
|
|
3
4
|
private _token;
|
|
4
5
|
private tokenRefreshTimeout;
|
|
@@ -12,6 +13,7 @@ declare class JwtTokenManager {
|
|
|
12
13
|
fetchWithToken(...[input, init]: Parameters<typeof fetch>): Promise<Response>;
|
|
13
14
|
get backendFunctionsBaseUrl(): string | undefined;
|
|
14
15
|
}
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
16
|
+
declare const backendFunctionsTokenManager: JwtTokenManager;
|
|
17
|
+
declare function callBackendFunctionWithToken(path: string, init?: Parameters<typeof fetch>[1]): Promise<Response>;
|
|
18
|
+
|
|
19
|
+
export { backendFunctionsTokenManager, callBackendFunctionWithToken };
|
|
@@ -1,25 +1,63 @@
|
|
|
1
|
-
|
|
1
|
+
var __create = Object.create;
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __export = (target, all) => {
|
|
8
|
+
for (var name in all)
|
|
9
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
10
|
+
};
|
|
11
|
+
var __copyProps = (to, from, except, desc) => {
|
|
12
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
13
|
+
for (let key of __getOwnPropNames(from))
|
|
14
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
15
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
16
|
+
}
|
|
17
|
+
return to;
|
|
18
|
+
};
|
|
19
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
20
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
21
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
22
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
23
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
24
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
25
|
+
mod
|
|
26
|
+
));
|
|
27
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
2
28
|
|
|
3
|
-
|
|
4
|
-
|
|
29
|
+
// src/common/jwtTokenManager.ts
|
|
30
|
+
var jwtTokenManager_exports = {};
|
|
31
|
+
__export(jwtTokenManager_exports, {
|
|
32
|
+
backendFunctionsTokenManager: () => backendFunctionsTokenManager,
|
|
33
|
+
callBackendFunctionWithToken: () => callBackendFunctionWithToken
|
|
5
34
|
});
|
|
6
|
-
exports
|
|
7
|
-
|
|
8
|
-
var
|
|
9
|
-
var
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
35
|
+
module.exports = __toCommonJS(jwtTokenManager_exports);
|
|
36
|
+
var import_cross_fetch = __toESM(require("cross-fetch"));
|
|
37
|
+
var jwt = __toESM(require("jsonwebtoken"));
|
|
38
|
+
var import_neverthrow = require("neverthrow");
|
|
39
|
+
|
|
40
|
+
// src/common/constants.ts
|
|
41
|
+
var WORKSPACE_ID_ENV_VAR_KEY = "INTUNED_WORKSPACE_ID";
|
|
42
|
+
var PROJECT_ID_ENV_VAR_KEY = "INTUNED_PROJECT_ID";
|
|
43
|
+
var API_KEY_ENV_VAR_KEY = "INTUNED_API_KEY";
|
|
44
|
+
var AUTH_TOKEN_ENV_VAR_KEY = "INTUNED_AUTH_TOKEN";
|
|
45
|
+
var API_KEY_HEADER_NAME = "x-api-key";
|
|
46
|
+
var CLI_ENV_VAR_KEY = "INTUNED_CLI";
|
|
47
|
+
|
|
48
|
+
// src/common/jwtTokenManager.ts
|
|
49
|
+
var JwtTokenManager = class {
|
|
16
50
|
constructor(refreshTokenPath) {
|
|
17
51
|
this.refreshTokenPath = refreshTokenPath;
|
|
18
|
-
this._token =
|
|
52
|
+
this._token = void 0;
|
|
19
53
|
}
|
|
20
54
|
get token() {
|
|
21
55
|
return this._token;
|
|
22
56
|
}
|
|
57
|
+
// When the token is set, the schedule for renewal is issued automatically
|
|
58
|
+
// This is currently being set it two places:
|
|
59
|
+
// 1. Whenever the runner starts, initializes it from the environment variable (set whenever the api is run from the authoring IDE)
|
|
60
|
+
// 2. Whenever a published api is called to run (/api/run/*), it is set to the token received in the run request.
|
|
23
61
|
set token(newToken) {
|
|
24
62
|
if (this._token != newToken) {
|
|
25
63
|
this._token = newToken;
|
|
@@ -32,14 +70,14 @@ class JwtTokenManager {
|
|
|
32
70
|
if (!payload || typeof payload == "string") return;
|
|
33
71
|
const expiry = payload.expiry;
|
|
34
72
|
if (!expiry || typeof expiry !== "number") return;
|
|
35
|
-
const timeWindow = 60 *
|
|
73
|
+
const timeWindow = 60 * 1e3;
|
|
36
74
|
const timeToRefresh = expiry - Date.now() - timeWindow;
|
|
37
75
|
return Math.max(timeToRefresh, timeWindow);
|
|
38
76
|
}
|
|
39
77
|
async scheduleTokenRefresh() {
|
|
40
78
|
if (process.env.RUN_ENVIRONMENT?.toLowerCase() !== "authoring") return;
|
|
41
79
|
const timeToRefresh = this.timeToRefresh;
|
|
42
|
-
if (timeToRefresh ===
|
|
80
|
+
if (timeToRefresh === void 0) return;
|
|
43
81
|
if (this.tokenRefreshTimeout) clearTimeout(this.tokenRefreshTimeout);
|
|
44
82
|
this.tokenRefreshTimeout = setTimeout(async () => {
|
|
45
83
|
const result = await this.refreshToken();
|
|
@@ -52,58 +90,92 @@ class JwtTokenManager {
|
|
|
52
90
|
}
|
|
53
91
|
async refreshToken() {
|
|
54
92
|
if (process.env.RUN_ENVIRONMENT?.toLowerCase() !== "authoring") return;
|
|
55
|
-
const res = await this.fetchWithToken(
|
|
56
|
-
|
|
57
|
-
|
|
93
|
+
const res = await this.fetchWithToken(
|
|
94
|
+
`${this.backendFunctionsBaseUrl}/${this.refreshTokenPath}`,
|
|
95
|
+
{
|
|
96
|
+
method: "GET"
|
|
97
|
+
}
|
|
98
|
+
);
|
|
58
99
|
if (res.status === 401) {
|
|
59
|
-
return (0,
|
|
100
|
+
return (0, import_neverthrow.err)("Unauthorized");
|
|
60
101
|
}
|
|
61
|
-
const jsonResult = await
|
|
102
|
+
const jsonResult = await import_neverthrow.ResultAsync.fromPromise(
|
|
103
|
+
res.json(),
|
|
104
|
+
() => "not json"
|
|
105
|
+
);
|
|
62
106
|
if (jsonResult.isErr()) return;
|
|
63
107
|
const newToken = jsonResult.value.token;
|
|
64
108
|
if (newToken) this._token = newToken;
|
|
65
109
|
}
|
|
66
110
|
async fetchWithToken(...[input, init]) {
|
|
67
111
|
const headers = new Headers(init?.headers);
|
|
68
|
-
|
|
69
|
-
|
|
112
|
+
const apiKey = process.env[API_KEY_ENV_VAR_KEY];
|
|
113
|
+
if (apiKey) {
|
|
114
|
+
headers.set(API_KEY_HEADER_NAME, apiKey);
|
|
70
115
|
}
|
|
71
|
-
|
|
116
|
+
const token = process.env[AUTH_TOKEN_ENV_VAR_KEY];
|
|
117
|
+
if (token) {
|
|
118
|
+
headers.set("Authorization", `Bearer ${token}`);
|
|
119
|
+
}
|
|
120
|
+
if (this.token !== void 0) {
|
|
72
121
|
headers.set("Authorization", `Bearer ${this.token}`);
|
|
73
122
|
}
|
|
74
|
-
const result = await (0,
|
|
123
|
+
const result = await (0, import_cross_fetch.default)(input, {
|
|
75
124
|
...init,
|
|
76
125
|
headers
|
|
77
126
|
});
|
|
78
|
-
if (result.status === 401 && process.env[
|
|
79
|
-
console.warn(
|
|
127
|
+
if (result.status === 401 && process.env[CLI_ENV_VAR_KEY] === "true") {
|
|
128
|
+
console.warn(
|
|
129
|
+
"Unauthorized backend function call - make sure to provision your project to Intuned to set up the correct API credentials.\nRun 'intuned provision' or see https://docs.intunedhq.com/docs/05-references/cli#provision-project for more information."
|
|
130
|
+
);
|
|
80
131
|
}
|
|
81
132
|
return result;
|
|
82
133
|
}
|
|
83
134
|
get backendFunctionsBaseUrl() {
|
|
84
135
|
try {
|
|
85
136
|
if (!process.env.FUNCTIONS_DOMAIN) {
|
|
86
|
-
throw new Error(
|
|
137
|
+
throw new Error(
|
|
138
|
+
`Cannot call backend function - FUNCTIONS_DOMAIN not set`
|
|
139
|
+
);
|
|
87
140
|
}
|
|
88
141
|
const domain = process.env.FUNCTIONS_DOMAIN;
|
|
89
|
-
if (!process.env[
|
|
90
|
-
throw new Error(
|
|
142
|
+
if (!process.env[WORKSPACE_ID_ENV_VAR_KEY]) {
|
|
143
|
+
throw new Error(
|
|
144
|
+
`Cannot call backend function - ${WORKSPACE_ID_ENV_VAR_KEY} not set`
|
|
145
|
+
);
|
|
91
146
|
}
|
|
92
|
-
const workspaceId = process.env[
|
|
93
|
-
if (!process.env[
|
|
94
|
-
throw new Error(
|
|
147
|
+
const workspaceId = process.env[WORKSPACE_ID_ENV_VAR_KEY];
|
|
148
|
+
if (!process.env[PROJECT_ID_ENV_VAR_KEY] && !process.env.INTUNED_INTEGRATION_ID) {
|
|
149
|
+
throw new Error(
|
|
150
|
+
`Cannot call backend function - ${PROJECT_ID_ENV_VAR_KEY} or INTUNED_INTEGRATION_ID not set`
|
|
151
|
+
);
|
|
95
152
|
}
|
|
96
|
-
const projectId = process.env.INTUNED_INTEGRATION_ID ?? process.env[
|
|
153
|
+
const projectId = process.env.INTUNED_INTEGRATION_ID ?? process.env[PROJECT_ID_ENV_VAR_KEY];
|
|
97
154
|
return `${domain}/api/${workspaceId}/functions/${projectId}`;
|
|
98
155
|
} catch (e) {
|
|
99
|
-
if (process.env[
|
|
100
|
-
throw new Error(
|
|
156
|
+
if (process.env[CLI_ENV_VAR_KEY] === "true") {
|
|
157
|
+
throw new Error(
|
|
158
|
+
`API credentials not set - make sure to provision your project to Intuned to set up the correct API credentials.
|
|
159
|
+
Run 'intuned provision' or see https://docs.intunedhq.com/docs/05-references/cli#provision-project for more information.
|
|
160
|
+
Original error: ${e.message}`
|
|
161
|
+
);
|
|
101
162
|
}
|
|
102
163
|
}
|
|
103
164
|
}
|
|
104
|
-
}
|
|
105
|
-
|
|
165
|
+
};
|
|
166
|
+
var backendFunctionsTokenManager = new JwtTokenManager(
|
|
167
|
+
`refreshBackendFunctionsToken`
|
|
168
|
+
);
|
|
106
169
|
backendFunctionsTokenManager.token = process.env.INTUNED_AUTHORING_SESSION_BACKEND_FUNCTIONS_TOKEN;
|
|
107
170
|
function callBackendFunctionWithToken(path, init) {
|
|
108
|
-
return backendFunctionsTokenManager.fetchWithToken(
|
|
109
|
-
}
|
|
171
|
+
return backendFunctionsTokenManager.fetchWithToken(
|
|
172
|
+
`${backendFunctionsTokenManager.backendFunctionsBaseUrl}/${path}`,
|
|
173
|
+
init
|
|
174
|
+
);
|
|
175
|
+
}
|
|
176
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
177
|
+
0 && (module.exports = {
|
|
178
|
+
backendFunctionsTokenManager,
|
|
179
|
+
callBackendFunctionWithToken
|
|
180
|
+
});
|
|
181
|
+
//# sourceMappingURL=jwtTokenManager.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/common/jwtTokenManager.ts","../../src/common/constants.ts"],"sourcesContent":["import fetch from \"cross-fetch\";\nimport * as jwt from \"jsonwebtoken\";\nimport { err, ResultAsync } from \"neverthrow\";\nimport {\n API_KEY_ENV_VAR_KEY,\n API_KEY_HEADER_NAME,\n PROJECT_ID_ENV_VAR_KEY,\n CLI_ENV_VAR_KEY,\n WORKSPACE_ID_ENV_VAR_KEY,\n AUTH_TOKEN_ENV_VAR_KEY,\n} from \"./constants\";\n\n// Manages JWT token with renewal\nclass JwtTokenManager {\n private _token: string | undefined;\n private tokenRefreshTimeout: NodeJS.Timeout | undefined;\n private refreshTokenPath: string;\n\n constructor(refreshTokenPath: string) {\n this.refreshTokenPath = refreshTokenPath;\n this._token = undefined;\n }\n\n public get token() {\n return this._token;\n }\n\n // When the token is set, the schedule for renewal is issued automatically\n // This is currently being set it two places:\n // 1. Whenever the runner starts, initializes it from the environment variable (set whenever the api is run from the authoring IDE)\n // 2. Whenever a published api is called to run (/api/run/*), it is set to the token received in the run request.\n public set token(newToken: string | undefined) {\n if (this._token != newToken) {\n this._token = newToken;\n void this.scheduleTokenRefresh();\n }\n }\n\n private get timeToRefresh() {\n if (!this._token) return;\n\n const payload = jwt.decode(this._token);\n\n if (!payload || typeof payload == \"string\") return;\n\n const expiry = payload.expiry;\n if (!expiry || typeof expiry !== \"number\") return;\n\n const timeWindow = 60 * 1000; // 1 minute\n\n const timeToRefresh = expiry - Date.now() - timeWindow;\n return Math.max(timeToRefresh, timeWindow);\n }\n\n private async scheduleTokenRefresh() {\n if (process.env.RUN_ENVIRONMENT?.toLowerCase() !== \"authoring\") return;\n const timeToRefresh = this.timeToRefresh;\n if (timeToRefresh === undefined) return;\n\n if (this.tokenRefreshTimeout) clearTimeout(this.tokenRefreshTimeout);\n\n this.tokenRefreshTimeout = setTimeout(async () => {\n const result = await this.refreshToken();\n if (result && result.isErr()) {\n console.error(`[Internal Error] ${result.error}`);\n return;\n }\n await this.scheduleTokenRefresh();\n }, timeToRefresh);\n }\n\n private async refreshToken() {\n if (process.env.RUN_ENVIRONMENT?.toLowerCase() !== \"authoring\") return;\n const res = await this.fetchWithToken(\n `${this.backendFunctionsBaseUrl}/${this.refreshTokenPath}`,\n {\n method: \"GET\",\n }\n );\n\n if (res.status === 401) {\n return err(\"Unauthorized\");\n }\n\n const jsonResult = await ResultAsync.fromPromise(\n res.json(),\n () => \"not json\"\n );\n\n if (jsonResult.isErr()) return;\n\n const newToken = jsonResult.value.token;\n if (newToken) this._token = newToken;\n }\n\n public async fetchWithToken(...[input, init]: Parameters<typeof fetch>) {\n const headers = new Headers(init?.headers);\n const apiKey = process.env[API_KEY_ENV_VAR_KEY];\n if (apiKey) {\n headers.set(API_KEY_HEADER_NAME, apiKey);\n }\n const token = process.env[AUTH_TOKEN_ENV_VAR_KEY];\n if (token) {\n headers.set(\"Authorization\", `Bearer ${token}`);\n }\n if (this.token !== undefined) {\n headers.set(\"Authorization\", `Bearer ${this.token}`);\n }\n const result = await fetch(input, {\n ...init,\n headers,\n });\n if (result.status === 401 && process.env[CLI_ENV_VAR_KEY] === \"true\") {\n console.warn(\n \"Unauthorized backend function call - make sure to provision your project to Intuned to set up the correct API credentials.\\n\" +\n \"Run 'intuned provision' or see https://docs.intunedhq.com/docs/05-references/cli#provision-project for more information.\"\n );\n }\n return result;\n }\n\n get backendFunctionsBaseUrl() {\n try {\n if (!process.env.FUNCTIONS_DOMAIN) {\n throw new Error(\n `Cannot call backend function - FUNCTIONS_DOMAIN not set`\n );\n }\n const domain = process.env.FUNCTIONS_DOMAIN;\n if (!process.env[WORKSPACE_ID_ENV_VAR_KEY]) {\n throw new Error(\n `Cannot call backend function - ${WORKSPACE_ID_ENV_VAR_KEY} not set`\n );\n }\n const workspaceId = process.env[WORKSPACE_ID_ENV_VAR_KEY];\n if (\n !process.env[PROJECT_ID_ENV_VAR_KEY] &&\n !process.env.INTUNED_INTEGRATION_ID\n ) {\n throw new Error(\n `Cannot call backend function - ${PROJECT_ID_ENV_VAR_KEY} or INTUNED_INTEGRATION_ID not set`\n );\n }\n\n const projectId =\n process.env.INTUNED_INTEGRATION_ID ??\n process.env[PROJECT_ID_ENV_VAR_KEY];\n return `${domain}/api/${workspaceId}/functions/${projectId}`;\n } catch (e) {\n if (process.env[CLI_ENV_VAR_KEY] === \"true\") {\n throw new Error(\n `API credentials not set - make sure to provision your project to Intuned to set up the correct API credentials.\\n` +\n `Run 'intuned provision' or see https://docs.intunedhq.com/docs/05-references/cli#provision-project for more information.\\n` +\n `Original error: ${e.message}`\n );\n }\n }\n }\n}\n\nexport const backendFunctionsTokenManager = new JwtTokenManager(\n `refreshBackendFunctionsToken`\n);\nbackendFunctionsTokenManager.token =\n process.env.INTUNED_AUTHORING_SESSION_BACKEND_FUNCTIONS_TOKEN;\n\nexport function callBackendFunctionWithToken(\n path: string,\n init?: Parameters<typeof fetch>[1]\n) {\n return backendFunctionsTokenManager.fetchWithToken(\n `${backendFunctionsTokenManager.backendFunctionsBaseUrl}/${path}`,\n init\n );\n}\n","export const API_FOLDER_NAME = \"api\";\nexport const AUTH_SESSIONS_FOLDER_NAME = \"auth-sessions\";\nexport const AUTH_SESSIONS_INSTANCES_FOLDER_NAME = \"auth-sessions-instances\";\nexport const WORKSPACE_ID_ENV_VAR_KEY = \"INTUNED_WORKSPACE_ID\";\nexport const EXTENSION_PATH_ENV_VAR_KEY = \"INTUNED_EXTENSION_PATH\";\nexport const PROJECT_ID_ENV_VAR_KEY = \"INTUNED_PROJECT_ID\";\nexport const API_KEY_ENV_VAR_KEY = \"INTUNED_API_KEY\";\nexport const AUTH_TOKEN_ENV_VAR_KEY = \"INTUNED_AUTH_TOKEN\";\nexport const API_KEY_HEADER_NAME = \"x-api-key\";\nexport const API_BASE_URL_ENV_VAR_KEY = \"INTUNED_API_BASE_URL\";\nexport const CLI_ENV_VAR_KEY = \"INTUNED_CLI\";\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,yBAAkB;AAClB,UAAqB;AACrB,wBAAiC;;;ACC1B,IAAM,2BAA2B;AAEjC,IAAM,yBAAyB;AAC/B,IAAM,sBAAsB;AAC5B,IAAM,yBAAyB;AAC/B,IAAM,sBAAsB;AAE5B,IAAM,kBAAkB;;;ADG/B,IAAM,kBAAN,MAAsB;AAAA,EAKpB,YAAY,kBAA0B;AACpC,SAAK,mBAAmB;AACxB,SAAK,SAAS;AAAA,EAChB;AAAA,EAEA,IAAW,QAAQ;AACjB,WAAO,KAAK;AAAA,EACd;AAAA;AAAA;AAAA;AAAA;AAAA,EAMA,IAAW,MAAM,UAA8B;AAC7C,QAAI,KAAK,UAAU,UAAU;AAC3B,WAAK,SAAS;AACd,WAAK,KAAK,qBAAqB;AAAA,IACjC;AAAA,EACF;AAAA,EAEA,IAAY,gBAAgB;AAC1B,QAAI,CAAC,KAAK,OAAQ;AAElB,UAAM,UAAc,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AAAA,MACF;AAAA,IACF;AAAA,EACF;AACF;AAEO,IAAM,+BAA+B,IAAI;AAAA,EAC9C;AACF;AACA,6BAA6B,QAC3B,QAAQ,IAAI;AAEP,SAAS,6BACd,MACA,MACA;AACA,SAAO,6BAA6B;AAAA,IAClC,GAAG,6BAA6B,uBAAuB,IAAI,IAAI;AAAA,IAC/D;AAAA,EACF;AACF;","names":["fetch"]}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import {
|
|
2
|
+
backendFunctionsTokenManager,
|
|
3
|
+
callBackendFunctionWithToken
|
|
4
|
+
} from "../chunk-7YL2JUTE.mjs";
|
|
5
|
+
import "../chunk-FGV5T6SI.mjs";
|
|
6
|
+
import "../chunk-LZOMFHX3.mjs";
|
|
7
|
+
export {
|
|
8
|
+
backendFunctionsTokenManager,
|
|
9
|
+
callBackendFunctionWithToken
|
|
10
|
+
};
|
|
11
|
+
//# sourceMappingURL=jwtTokenManager.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { Result } from 'neverthrow';
|
|
2
|
+
import { Page, BrowserContext } from 'playwright';
|
|
3
|
+
import { RunAutomationError, ExtendedRunApiParameters, RunApiResult, RunApiResultWithSessionOk } from '@intuned/runtime-interface';
|
|
4
|
+
|
|
5
|
+
declare function runApi<ResultType = any>(input: ExtendedRunApiParameters & {
|
|
6
|
+
retrieveSession: true;
|
|
7
|
+
}): Promise<RunApiResult<ResultType, RunApiResultWithSessionOk<ResultType>>>;
|
|
8
|
+
declare function runApi<ResultType = any>(input: ExtendedRunApiParameters): Promise<RunApiResult<ResultType>>;
|
|
9
|
+
declare function checkAuthSessionWithRetries(page: Page, context: BrowserContext, checkFn: (..._: any) => Promise<boolean>, retries?: number): Promise<Result<boolean, RunAutomationError>>;
|
|
10
|
+
|
|
11
|
+
export { checkAuthSessionWithRetries, runApi };
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import { Result } from
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
export * from "./errors";
|
|
7
|
-
export declare function runApi<ResultType = any>(input: ExtendedRunApiParameters & {
|
|
1
|
+
import { Result } from 'neverthrow';
|
|
2
|
+
import { Page, BrowserContext } from 'playwright';
|
|
3
|
+
import { RunAutomationError, ExtendedRunApiParameters, RunApiResult, RunApiResultWithSessionOk } from '@intuned/runtime-interface';
|
|
4
|
+
|
|
5
|
+
declare function runApi<ResultType = any>(input: ExtendedRunApiParameters & {
|
|
8
6
|
retrieveSession: true;
|
|
9
|
-
}): Promise<RunApiResult<ResultType, RunApiResultWithSessionOk
|
|
10
|
-
|
|
11
|
-
|
|
7
|
+
}): Promise<RunApiResult<ResultType, RunApiResultWithSessionOk<ResultType>>>;
|
|
8
|
+
declare function runApi<ResultType = any>(input: ExtendedRunApiParameters): Promise<RunApiResult<ResultType>>;
|
|
9
|
+
declare function checkAuthSessionWithRetries(page: Page, context: BrowserContext, checkFn: (..._: any) => Promise<boolean>, retries?: number): Promise<Result<boolean, RunAutomationError>>;
|
|
10
|
+
|
|
11
|
+
export { checkAuthSessionWithRetries, runApi };
|