@intuned/runtime-dev 1.2.0-cli.5 → 1.2.0-cli.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.
@@ -3,77 +3,65 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
+ exports._runCreateWithRetries = exports._runCreate = exports._runCheckWithRetries = exports._runCheck = void 0;
6
7
  exports.executeAttemptCheckAuthSessionCLI = executeAttemptCheckAuthSessionCLI;
7
8
  exports.executeAttemptCreateAuthSessionCLI = executeAttemptCreateAuthSessionCLI;
8
9
  exports.executeRunCreateAuthSessionCLI = executeRunCreateAuthSessionCLI;
9
10
  exports.executeRunUpdateAuthSessionCLI = executeRunUpdateAuthSessionCLI;
10
11
  exports.executeRunValidateAuthSessionCLI = executeRunValidateAuthSessionCLI;
11
- exports.runCreate = runCreate;
12
- var _path = _interopRequireDefault(require("path"));
13
12
  var _helpers = require("../helpers");
14
13
  var _runApi = require("../../../common/runApi");
15
14
  var _constants = require("../../../common/constants");
16
15
  var _tsNodeImport = require("../../common/tsNodeImport");
17
16
  var _terminal = require("../helpers/terminal");
18
- function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
19
17
  async function executeRunValidateAuthSessionCLI({
20
18
  id,
21
19
  autoRecreate,
22
20
  checkRetries,
23
21
  createRetries,
24
- useExistingContext = false,
25
22
  ...rest
26
23
  }) {
27
- const validate = async () => {
28
- (0, _terminal.terminal)(`^+Validating auth session with id ^c${id}^:\n`);
24
+ (0, _terminal.terminal)(`^+Validating auth session with id ^c${id}^:\n`);
25
+ const {
26
+ storageState
27
+ } = await (0, _helpers.loadAuthSessionInstance)(id);
28
+ await (0, _helpers.assertApiFileExists)(_constants.AUTH_SESSIONS_FOLDER_NAME, "check");
29
+ (0, _helpers.registerGetAuthSessionParameters)(id);
30
+ const checkResult = await runCheckWithRetries({
31
+ auth: storageState,
32
+ retries: checkRetries,
33
+ ...rest
34
+ });
35
+ if (!checkResult) {
36
+ if (!autoRecreate) {
37
+ throw new _helpers.CLIError("Auto recreate is disabled, please provide a new auth session or update it manually");
38
+ }
29
39
  const {
30
- authSessionInstanceStoragePath
31
- } = await (0, _helpers.retrieveAuthSessionInstance)(id, true);
32
- const authSessionPathToUse = authSessionInstanceStoragePath;
33
- await (0, _helpers.assertApiFileExists)(_constants.AUTH_SESSIONS_FOLDER_NAME, "check");
40
+ metadata
41
+ } = await (0, _helpers.loadAuthSessionInstance)(id);
42
+ if (metadata?.authSessionType === "MANUAL") {
43
+ throw new _helpers.CLIError("Auth session is recorder-based, please provide a new one or update it manually");
44
+ }
45
+ (0, _terminal.terminal)("^+Auto recreate is enabled - trying to re-create it^:\n");
46
+ await (0, _helpers.assertApiFileExists)(_constants.AUTH_SESSIONS_FOLDER_NAME, "create");
47
+ const authSessionInput = metadata?.authSessionInput ?? {};
48
+ const storageState = await runCreateWithRetries({
49
+ authSessionId: id,
50
+ authSessionInput,
51
+ retries: createRetries,
52
+ ...rest
53
+ });
34
54
  const checkResult = await runCheckWithRetries({
35
- authSessionPath: authSessionPathToUse,
55
+ auth: storageState,
36
56
  retries: checkRetries,
37
57
  ...rest
38
58
  });
39
59
  if (!checkResult) {
40
- if (!autoRecreate) {
41
- throw new _helpers.CLIError("Auto recreate is disabled, please provide a new auth session or update it manually");
42
- }
43
- const {
44
- metadata
45
- } = await (0, _helpers.retrieveAuthSessionInstance)(id);
46
- if (metadata?.authSessionType === "MANUAL") {
47
- throw new _helpers.CLIError("Auth session is recorder-based, please provide a new one or update it manually");
48
- }
49
- (0, _terminal.terminal)("^+Auto recreate is enabled - trying to re-create it^:\n");
50
- await (0, _helpers.assertApiFileExists)(_constants.AUTH_SESSIONS_FOLDER_NAME, "create");
51
- const authSessionInput = metadata?.authSessionInput ?? {};
52
- await runCreateWithRetries({
53
- authSessionId: id,
54
- authSessionInput,
55
- retries: createRetries,
56
- ...rest
57
- });
58
- const checkResult = await runCheckWithRetries({
59
- authSessionPath: authSessionPathToUse,
60
- retries: checkRetries,
61
- ...rest
62
- });
63
- if (!checkResult) {
64
- throw new _helpers.CLIError("Failed to re-create auth session");
65
- }
60
+ throw new _helpers.CLIError("Failed to re-create auth session");
66
61
  }
67
- (0, _terminal.terminal)(`^+^gAuth session validated successfully^:\n`);
68
- return authSessionPathToUse;
69
- };
70
- if (useExistingContext) {
71
- return await validate();
72
- } else {
73
- return await (0, _helpers.withCLIContext)(validate, {
74
- authSessionId: id
75
- });
76
62
  }
63
+ (0, _terminal.terminal)(`^+^gAuth session validated successfully^:\n`);
64
+ return storageState;
77
65
  }
78
66
  async function executeRunCreateAuthSessionCLI({
79
67
  id,
@@ -83,29 +71,28 @@ async function executeRunCreateAuthSessionCLI({
83
71
  log = true,
84
72
  ...rest
85
73
  }) {
86
- return (0, _helpers.withCLIContext)(async () => {
87
- id = id ?? `auth-session-${Date.now()}`;
88
- (0, _terminal.terminal)(`^+Creating auth session with id ^c${id}^:\n`);
89
- await Promise.all([await (0, _helpers.assertApiFileExists)(_constants.AUTH_SESSIONS_FOLDER_NAME, "create"), await (0, _helpers.assertApiFileExists)(_constants.AUTH_SESSIONS_FOLDER_NAME, "check")]);
90
- const authSessionPath = await runCreateWithRetries({
91
- authSessionId: id,
92
- authSessionInput: input,
93
- retries: createRetries,
94
- ...rest
95
- });
96
- const checkResult = await runCheckWithRetries({
97
- authSessionPath: _path.default.join(authSessionPath, "auth-session.json"),
98
- retries: checkRetries,
99
- ...rest
100
- });
101
- if (!checkResult) {
102
- throw new _helpers.CLIError("Failed to create auth session");
103
- }
104
- if (log) {
105
- (0, _terminal.terminal)(`^+^gAuth session created successfully^:\n`);
106
- }
107
- return authSessionPath;
74
+ id = id ?? `auth-session-${Date.now()}`;
75
+ (0, _terminal.terminal)(`^+Creating auth session with id ^c${id}^:\n`);
76
+ await Promise.all([await (0, _helpers.assertApiFileExists)(_constants.AUTH_SESSIONS_FOLDER_NAME, "create"), await (0, _helpers.assertApiFileExists)(_constants.AUTH_SESSIONS_FOLDER_NAME, "check")]);
77
+ const createdStorageState = await runCreateWithRetries({
78
+ authSessionId: id,
79
+ authSessionInput: input,
80
+ retries: createRetries,
81
+ ...rest
108
82
  });
83
+ const auth = createdStorageState;
84
+ const checkResult = await runCheckWithRetries({
85
+ auth,
86
+ retries: checkRetries,
87
+ ...rest
88
+ });
89
+ if (!checkResult) {
90
+ throw new _helpers.CLIError("Failed to create auth session");
91
+ }
92
+ if (log) {
93
+ (0, _terminal.terminal)(`^+^gAuth session created successfully^:\n`);
94
+ }
95
+ return auth;
109
96
  }
110
97
  async function executeRunUpdateAuthSessionCLI({
111
98
  id,
@@ -115,44 +102,40 @@ async function executeRunUpdateAuthSessionCLI({
115
102
  ...rest
116
103
  }) {
117
104
  (0, _terminal.terminal)(`^+Updating auth session with id ^c${id}^:\n`);
118
- return (0, _helpers.withCLIContext)(async () => {
119
- if (input === undefined) {
120
- const {
121
- metadata
122
- } = await (0, _helpers.retrieveAuthSessionInstance)(id);
123
- if (metadata?.authSessionType === "MANUAL") {
124
- throw new _helpers.CLIError("Auth session is recorder-based, it cannot be updated.");
125
- }
126
- input = metadata?.authSessionInput ?? {};
105
+ if (input === undefined) {
106
+ const {
107
+ metadata
108
+ } = await (0, _helpers.loadAuthSessionInstance)(id);
109
+ if (metadata?.authSessionType === "MANUAL") {
110
+ throw new _helpers.CLIError("Auth session is recorder-based, it cannot be updated.");
127
111
  }
128
- await Promise.all([await (0, _helpers.assertApiFileExists)(_constants.AUTH_SESSIONS_FOLDER_NAME, "create"), await (0, _helpers.assertApiFileExists)(_constants.AUTH_SESSIONS_FOLDER_NAME, "check")]);
129
- const authSession = await executeRunCreateAuthSessionCLI({
130
- id,
131
- input,
132
- checkRetries,
133
- createRetries,
134
- log: false,
135
- ...rest
136
- });
137
- (0, _terminal.terminal)(`^+^gAuth session updated successfully^:\n`);
138
- return authSession;
112
+ input = metadata?.authSessionInput ?? {};
113
+ }
114
+ await Promise.all([await (0, _helpers.assertApiFileExists)(_constants.AUTH_SESSIONS_FOLDER_NAME, "create"), await (0, _helpers.assertApiFileExists)(_constants.AUTH_SESSIONS_FOLDER_NAME, "check")]);
115
+ const authSession = await executeRunCreateAuthSessionCLI({
116
+ id,
117
+ input,
118
+ checkRetries,
119
+ createRetries,
120
+ log: false,
121
+ ...rest
139
122
  });
123
+ (0, _terminal.terminal)(`^+^gAuth session updated successfully^:\n`);
124
+ return authSession;
140
125
  }
141
126
  async function executeAttemptCreateAuthSessionCLI({
142
127
  id,
143
128
  input,
144
129
  ...rest
145
130
  }) {
146
- return await (0, _helpers.withCLIContext)(async () => {
147
- id = id ?? `auth-session-attempt-${Date.now()}`;
148
- (0, _terminal.terminal)(`^+Executing create auth session attempt with id ^c${id}^:\n`);
149
- await (0, _helpers.assertApiFileExists)(_constants.AUTH_SESSIONS_FOLDER_NAME, "create");
150
- return await runCreateWithRetries({
151
- authSessionId: id,
152
- authSessionInput: input,
153
- retries: 1,
154
- ...rest
155
- });
131
+ id = id ?? `auth-session-attempt-${Date.now()}`;
132
+ (0, _terminal.terminal)(`^+Executing create auth session attempt with id ^c${id}^:\n`);
133
+ await (0, _helpers.assertApiFileExists)(_constants.AUTH_SESSIONS_FOLDER_NAME, "create");
134
+ return await runCreateWithRetries({
135
+ authSessionId: id,
136
+ authSessionInput: input,
137
+ retries: 1,
138
+ ...rest
156
139
  });
157
140
  }
158
141
  async function executeAttemptCheckAuthSessionCLI({
@@ -161,27 +144,23 @@ async function executeAttemptCheckAuthSessionCLI({
161
144
  }) {
162
145
  (0, _terminal.terminal)(`^+Executing check auth session attempt with id ^c${id}^:\n`);
163
146
  await (0, _helpers.assertApiFileExists)(_constants.AUTH_SESSIONS_FOLDER_NAME, "check");
164
- return await (0, _helpers.withCLIContext)(async () => {
165
- const {
166
- authSessionInstanceStoragePath
167
- } = await (0, _helpers.retrieveAuthSessionInstance)(id, true);
168
- const authSessionPathToUse = authSessionInstanceStoragePath;
169
- const checkResult = await runCheckWithRetries({
170
- authSessionPath: authSessionPathToUse,
171
- retries: 1,
172
- ...rest
173
- });
174
- if (!checkResult) {
175
- throw new _helpers.CLIError("Check failed");
176
- }
177
- (0, _terminal.terminal)(`^+^gAuth session check passed^:\n`);
178
- return authSessionPathToUse;
179
- }, {
180
- authSessionId: id
147
+ (0, _helpers.registerGetAuthSessionParameters)(id);
148
+ const {
149
+ storageState
150
+ } = await (0, _helpers.loadAuthSessionInstance)(id);
151
+ const checkResult = await runCheckWithRetries({
152
+ auth: storageState,
153
+ retries: 1,
154
+ ...rest
181
155
  });
156
+ if (!checkResult) {
157
+ throw new _helpers.CLIError("Check failed");
158
+ }
159
+ (0, _terminal.terminal)(`^+^gAuth session check passed^:\n`);
160
+ return storageState;
182
161
  }
183
162
  async function runCheck({
184
- authSessionPath,
163
+ auth,
185
164
  proxy,
186
165
  headless,
187
166
  timeout
@@ -198,8 +177,8 @@ async function runCheck({
198
177
  },
199
178
  auth: {
200
179
  session: {
201
- type: "file",
202
- path: authSessionPath
180
+ type: "state",
181
+ state: auth
203
182
  },
204
183
  runCheck: false
205
184
  },
@@ -207,10 +186,7 @@ async function runCheck({
207
186
  abortSignal
208
187
  });
209
188
  if (runApiResult.isErr()) {
210
- if (runApiResult.error instanceof _runApi.AutomationError) {
211
- throw runApiResult.error;
212
- }
213
- return false;
189
+ throw runApiResult.error;
214
190
  }
215
191
  const result = runApiResult.value.result;
216
192
  if (!result) {
@@ -219,6 +195,7 @@ async function runCheck({
219
195
  return result;
220
196
  }, timeout);
221
197
  }
198
+ const _runCheck = exports._runCheck = runCheck;
222
199
  async function runCreate({
223
200
  authSessionInput,
224
201
  proxy,
@@ -226,10 +203,9 @@ async function runCreate({
226
203
  timeout
227
204
  }) {
228
205
  return await (0, _helpers.withTimeout)(async abortSignal => {
229
- const createApiName = `${_constants.AUTH_SESSIONS_FOLDER_NAME}/create`;
230
206
  const result = await (0, _runApi.runApi)({
231
207
  automationFunction: {
232
- name: createApiName,
208
+ name: `${_constants.AUTH_SESSIONS_FOLDER_NAME}/create`,
233
209
  params: authSessionInput
234
210
  },
235
211
  runOptions: {
@@ -247,8 +223,9 @@ async function runCreate({
247
223
  return result.value.session;
248
224
  }, timeout);
249
225
  }
226
+ const _runCreate = exports._runCreate = runCreate;
250
227
  async function runCheckWithRetries({
251
- authSessionPath,
228
+ auth,
252
229
  retries,
253
230
  ...rest
254
231
  }) {
@@ -256,9 +233,12 @@ async function runCheckWithRetries({
256
233
  (0, _terminal.terminal)(`\n^+Running ^cauth session check${i === 0 ? "" : ` ^/(Attempt ${i + 1})`}^:...\n`);
257
234
  try {
258
235
  const checkResult = await runCheck({
259
- authSessionPath,
236
+ auth,
260
237
  ...rest
261
238
  });
239
+ console.log({
240
+ checkResult
241
+ });
262
242
  if (checkResult) {
263
243
  (0, _terminal.terminal)(`^+^gAuth session check passed^:\n`);
264
244
  return true;
@@ -266,15 +246,16 @@ async function runCheckWithRetries({
266
246
  } catch (error) {
267
247
  if (error instanceof _runApi.AutomationError) {
268
248
  (0, _helpers.logAutomationError)(error);
269
- continue;
249
+ } else {
250
+ throw error;
270
251
  }
271
- throw error;
272
252
  }
273
253
  (0, _terminal.terminal)(`^+^yAuth session check failed^:\n`);
274
254
  }
275
255
  (0, _terminal.terminal)(`^+^rAuth session check failed after ${retries} attempts^:\n`);
276
256
  return false;
277
257
  }
258
+ const _runCheckWithRetries = exports._runCheckWithRetries = runCheckWithRetries;
278
259
  async function runCreateWithRetries({
279
260
  authSessionId,
280
261
  authSessionInput,
@@ -294,13 +275,21 @@ async function runCreateWithRetries({
294
275
  } catch (error) {
295
276
  if (error instanceof _runApi.AutomationError) {
296
277
  (0, _helpers.logAutomationError)(error);
297
- continue;
278
+ } else {
279
+ throw error;
298
280
  }
299
- throw error;
281
+ (0, _terminal.terminal)(`^+^yAuth session create failed^:\n`);
300
282
  }
301
283
  }
302
284
  if (!newAuthSessionInstance) {
303
285
  throw new _helpers.CLIError(`Failed to create auth session after ${retries} retries`);
304
286
  }
305
- return await (0, _helpers.storeAuthSessionInstance)(newAuthSessionInstance, authSessionId, authSessionInput);
306
- }
287
+ await (0, _helpers.storeAuthSessionInstance)({
288
+ state: newAuthSessionInstance,
289
+ id: authSessionId,
290
+ input: authSessionInput,
291
+ proxy: rest.proxy
292
+ });
293
+ return newAuthSessionInstance;
294
+ }
295
+ const _runCreateWithRetries = exports._runCreateWithRetries = runCreateWithRetries;
@@ -1,17 +1,41 @@
1
- import type { StorageState } from "../../../common/contextStorageStateHelpers";
2
1
  import type { AuthSessionMetadata } from "../types";
2
+ import { RunApiStorageState as StorageState } from "../../../common/runApi";
3
3
  export declare function isAuthEnabled(): Promise<boolean>;
4
4
  export declare function assertAuthEnabled(): Promise<void>;
5
5
  export declare function assertAuthConsistent(authSession: string | undefined): Promise<void>;
6
- export declare function retrieveAuthSessionInstance(authSessionId: string, pathsOnly?: boolean): Promise<{
7
- authSessionInstanceStoragePath: string;
8
- authSessionInstanceMetadataPath: string;
9
- authSessionInstance?: undefined;
10
- metadata?: undefined;
11
- } | {
12
- authSessionInstance: StorageState;
6
+ export declare function loadAuthSessionInstance(authSessionId: string): Promise<{
7
+ storageState: {
8
+ cookies: {
9
+ value: string;
10
+ name: string;
11
+ path: string;
12
+ domain: string;
13
+ expires: number;
14
+ httpOnly: boolean;
15
+ secure: boolean;
16
+ sameSite: "Strict" | "Lax" | "None";
17
+ }[];
18
+ origins: {
19
+ origin: string;
20
+ localStorage: {
21
+ value: string;
22
+ name: string;
23
+ }[];
24
+ }[];
25
+ sessionStorage?: {
26
+ sessionStorage: {
27
+ value: string;
28
+ name: string;
29
+ }[];
30
+ origin: string;
31
+ }[] | undefined;
32
+ };
13
33
  metadata: AuthSessionMetadata;
14
- authSessionInstanceStoragePath?: undefined;
15
- authSessionInstanceMetadataPath?: undefined;
16
34
  }>;
17
- export declare function storeAuthSessionInstance(authSessionInstance: StorageState, customName?: string, authSessionInput?: Record<string, any>): Promise<string>;
35
+ export declare function storeAuthSessionInstance({ state, id, input, proxy, }: {
36
+ state: StorageState;
37
+ id?: string;
38
+ input?: Record<string, any>;
39
+ proxy?: string;
40
+ }): Promise<string>;
41
+ export declare function registerGetAuthSessionParameters(authSessionId?: string): void;
@@ -6,13 +6,17 @@ Object.defineProperty(exports, "__esModule", {
6
6
  exports.assertAuthConsistent = assertAuthConsistent;
7
7
  exports.assertAuthEnabled = assertAuthEnabled;
8
8
  exports.isAuthEnabled = isAuthEnabled;
9
- exports.retrieveAuthSessionInstance = retrieveAuthSessionInstance;
9
+ exports.loadAuthSessionInstance = loadAuthSessionInstance;
10
+ exports.registerGetAuthSessionParameters = registerGetAuthSessionParameters;
10
11
  exports.storeAuthSessionInstance = storeAuthSessionInstance;
11
12
  var _constants = require("../../../common/constants");
12
13
  var _path = _interopRequireDefault(require("path"));
13
14
  var _fsExtra = require("fs-extra");
14
15
  var _intunedJson = require("./intunedJson");
15
16
  var _errors = require("./errors");
17
+ var _runApi = require("../../../common/runApi");
18
+ var _formatZodError = require("../../../common/formatZodError");
19
+ var _asyncLocalStorage = require("../../../common/asyncLocalStorage");
16
20
  function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
17
21
  async function isAuthEnabled() {
18
22
  try {
@@ -36,7 +40,7 @@ async function assertAuthConsistent(authSession) {
36
40
  throw new _errors.CLIAssertionError("Auth session is not enabled, enable it in Intuned.json to use it");
37
41
  }
38
42
  }
39
- async function retrieveAuthSessionInstance(authSessionId, pathsOnly = false) {
43
+ async function loadAuthSessionInstance(authSessionId) {
40
44
  try {
41
45
  const authSessionInstancePath = _path.default.join(process.cwd(), _constants.AUTH_SESSIONS_INSTANCES_FOLDER_NAME, authSessionId);
42
46
  const authSessionInstanceStoragePath = _path.default.join(authSessionInstancePath, `auth-session.json`);
@@ -44,32 +48,35 @@ async function retrieveAuthSessionInstance(authSessionId, pathsOnly = false) {
44
48
  if (!(await (0, _fsExtra.exists)(authSessionInstanceStoragePath))) {
45
49
  throw new _errors.CLIError(`Auth session instance with ID ${authSessionId} not found`);
46
50
  }
47
- if (pathsOnly) {
48
- return {
49
- authSessionInstanceStoragePath,
50
- authSessionInstanceMetadataPath
51
- };
51
+ const authSessionInstanceJson = await (0, _fsExtra.readJSON)(authSessionInstanceStoragePath);
52
+ const authSessionInstanceParseResult = _runApi.runApiStorageStateSchema.safeParse(authSessionInstanceJson);
53
+ if (!authSessionInstanceParseResult.success) {
54
+ throw new _errors.CLIError(`Auth session instance with ID ${authSessionId} is not valid: ${(0, _formatZodError.formatZodError)(authSessionInstanceParseResult.error)}`);
52
55
  }
53
- const authSessionInstance = await (0, _fsExtra.readJSON)(authSessionInstanceStoragePath);
54
56
  const metadata = await (0, _fsExtra.readJSON)(authSessionInstanceMetadataPath);
55
57
  return {
56
- authSessionInstance,
58
+ storageState: authSessionInstanceParseResult.data,
57
59
  metadata
58
60
  };
59
61
  } catch (error) {
60
62
  throw new _errors.CLIError(`Error retrieving auth session instance: ${error.message}`);
61
63
  }
62
64
  }
63
- async function storeAuthSessionInstance(authSessionInstance, customName, authSessionInput) {
65
+ async function storeAuthSessionInstance({
66
+ state,
67
+ id,
68
+ input,
69
+ proxy
70
+ }) {
64
71
  try {
65
72
  const authSessionsDirectoryPath = _path.default.join(process.cwd(), _constants.AUTH_SESSIONS_INSTANCES_FOLDER_NAME);
66
73
  await (0, _fsExtra.ensureDir)(authSessionsDirectoryPath);
67
- const authSessionInstanceId = customName ?? `auth-session-${Date.now()}`;
74
+ const authSessionInstanceId = id ?? `auth-session-${Date.now()}`;
68
75
  const authSessionInstancePath = _path.default.join(authSessionsDirectoryPath, authSessionInstanceId);
69
76
  const authSessionExists = await (0, _fsExtra.pathExists)(authSessionInstancePath);
70
77
  await (0, _fsExtra.ensureDir)(authSessionInstancePath);
71
78
  const authSessionInstanceStoragePath = _path.default.join(authSessionInstancePath, `auth-session.json`);
72
- await (0, _fsExtra.writeJSON)(authSessionInstanceStoragePath, authSessionInstance, {
79
+ await (0, _fsExtra.writeJSON)(authSessionInstanceStoragePath, state, {
73
80
  spaces: 2
74
81
  });
75
82
  const projectAuthConfig = await (0, _intunedJson.getSettingIntunedJSON)("authSessions");
@@ -86,14 +93,16 @@ async function storeAuthSessionInstance(authSessionInstance, customName, authSes
86
93
  createdAt: existingMetadata.createdAt || new Date().toISOString(),
87
94
  updatedAt: new Date().toISOString(),
88
95
  ...(projectAuthConfig.type === "API" && {
89
- authSessionInput: authSessionInput || existingMetadata.authSessionInput || {}
96
+ authSessionInput: input || existingMetadata.authSessionInput || {}
90
97
  }),
91
98
  authSessionId: authSessionInstanceId,
92
99
  authSessionType: projectAuthConfig.type ?? existingMetadata.authSessionType ?? "API",
93
100
  ...(projectAuthConfig.type === "MANUAL" && {
94
101
  recorderStartUrl: projectAuthConfig.startUrl,
95
102
  recorderEndUrl: projectAuthConfig.endUrl
96
- })
103
+ }),
104
+ authSessionInput: input || existingMetadata.authSessionInput || {},
105
+ authSessionProxy: proxy || existingMetadata.authSessionProxy
97
106
  };
98
107
  await (0, _fsExtra.writeJSON)(authSessionInstanceMetadataPath, authSessionMetadata, {
99
108
  spaces: 2
@@ -102,4 +111,19 @@ async function storeAuthSessionInstance(authSessionInstance, customName, authSes
102
111
  } catch (error) {
103
112
  throw new _errors.CLIError(`Error storing auth session instance: ${error.message}`);
104
113
  }
114
+ }
115
+ function registerGetAuthSessionParameters(authSessionId) {
116
+ async function getAuthSessionParameters() {
117
+ if (!authSessionId) {
118
+ throw new Error("getAuthSessionParameters cannot be called without using an auth session");
119
+ }
120
+ const {
121
+ metadata
122
+ } = await loadAuthSessionInstance(authSessionId);
123
+ if (metadata?.authSessionType === "MANUAL") {
124
+ throw new Error("Auth session is recorder-based, it does not have parameters.");
125
+ }
126
+ return metadata?.authSessionInput ?? {};
127
+ }
128
+ (0, _asyncLocalStorage.getExecutionContext)().getAuthSessionParameters = getAuthSessionParameters;
105
129
  }
@@ -17,7 +17,7 @@ async function withCLIContext(fn, options) {
17
17
  }
18
18
  const {
19
19
  metadata
20
- } = await (0, _auth.retrieveAuthSessionInstance)(id);
20
+ } = await (0, _auth.loadAuthSessionInstance)(id);
21
21
  if (metadata?.authSessionType === "MANUAL") {
22
22
  throw new Error("Auth session is recorder-based, it does not have parameters.");
23
23
  }
@@ -2,6 +2,7 @@
2
2
 
3
3
  var _dotenv = _interopRequireDefault(require("dotenv"));
4
4
  var _commands = require("./commands");
5
+ var _helpers = require("./helpers");
5
6
  function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
6
7
  _dotenv.default.config({
7
8
  path: `.env`
@@ -9,4 +10,6 @@ _dotenv.default.config({
9
10
  _commands.program.configureHelp({
10
11
  sortSubcommands: true
11
12
  });
12
- _commands.program.parse(process.argv);
13
+ void (0, _helpers.withCLIContext)(async () => {
14
+ _commands.program.parse(process.argv);
15
+ });
@@ -30,6 +30,7 @@ export type AuthSessionMetadata = {
30
30
  authSessionId: string;
31
31
  authSessionType: AuthSessionType;
32
32
  authSessionInput?: Record<string, any>;
33
+ authSessionProxy?: string;
33
34
  recorderStartUrl?: string;
34
35
  recorderEndUrl?: string;
35
36
  };