@intuned/runtime-dev 1.2.0-cli.4 → 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.
Files changed (86) hide show
  1. package/dist/commands/api/run.js +2 -1
  2. package/dist/commands/intuned-cli/commands/attempt_api.command.js +1 -1
  3. package/dist/commands/intuned-cli/commands/attempt_authsession_check.command.js +1 -1
  4. package/dist/commands/intuned-cli/commands/attempt_authsession_create.command.js +1 -1
  5. package/dist/commands/intuned-cli/commands/build.command.js +1 -1
  6. package/dist/commands/intuned-cli/commands/deploy.command.js +3 -4
  7. package/dist/commands/intuned-cli/commands/init.command.js +1 -1
  8. package/dist/commands/intuned-cli/commands/run_api.command.js +1 -1
  9. package/dist/commands/intuned-cli/commands/run_authsession.command.d.ts +0 -1
  10. package/dist/commands/intuned-cli/commands/run_authsession_create.command.js +1 -1
  11. package/dist/commands/intuned-cli/commands/run_authsession_update.command.js +1 -1
  12. package/dist/commands/intuned-cli/commands/run_authsession_validate.command.js +1 -1
  13. package/dist/{common/cli/constants.d.ts → commands/intuned-cli/constants/index.d.ts} +2 -4
  14. package/dist/{common/cli/constants.js → commands/intuned-cli/constants/index.js} +22 -5
  15. package/dist/commands/intuned-cli/constants/readme.d.ts +1 -0
  16. package/dist/{common/cli/cliReadme.js → commands/intuned-cli/constants/readme.js} +13 -15
  17. package/dist/commands/intuned-cli/controller/__test__/api.test.js +280 -0
  18. package/dist/commands/intuned-cli/controller/__test__/authSession.test.js +676 -0
  19. package/dist/commands/intuned-cli/controller/api.d.ts +25 -0
  20. package/dist/commands/intuned-cli/controller/api.js +28 -31
  21. package/dist/commands/intuned-cli/controller/authSession.d.ts +176 -10
  22. package/dist/commands/intuned-cli/controller/authSession.js +116 -126
  23. package/dist/commands/intuned-cli/controller/build.js +1 -1
  24. package/dist/commands/intuned-cli/controller/deploy.d.ts +1 -1
  25. package/dist/commands/intuned-cli/controller/deploy.js +9 -11
  26. package/dist/commands/intuned-cli/controller/index.js +5 -4
  27. package/dist/commands/intuned-cli/controller/init.d.ts +1 -1
  28. package/dist/commands/intuned-cli/controller/init.js +12 -15
  29. package/dist/commands/intuned-cli/helpers/api.d.ts +3 -0
  30. package/dist/commands/intuned-cli/helpers/api.js +19 -0
  31. package/dist/commands/intuned-cli/helpers/auth.d.ts +41 -0
  32. package/dist/commands/intuned-cli/helpers/auth.js +129 -0
  33. package/dist/{common/cli/utils.d.ts → commands/intuned-cli/helpers/backend.d.ts} +0 -1
  34. package/dist/commands/intuned-cli/helpers/backend.js +26 -0
  35. package/dist/commands/intuned-cli/helpers/context.d.ts +3 -0
  36. package/dist/commands/intuned-cli/helpers/context.js +33 -0
  37. package/dist/commands/intuned-cli/helpers/errors.d.ts +14 -0
  38. package/dist/commands/intuned-cli/helpers/errors.js +55 -0
  39. package/dist/commands/intuned-cli/helpers/index.d.ts +10 -0
  40. package/dist/commands/intuned-cli/helpers/index.js +115 -0
  41. package/dist/commands/intuned-cli/helpers/intunedJson.d.ts +1 -0
  42. package/dist/{common/cli/utils.js → commands/intuned-cli/helpers/intunedJson.js} +0 -20
  43. package/dist/commands/intuned-cli/helpers/proxy.d.ts +5 -0
  44. package/dist/commands/intuned-cli/helpers/proxy.js +23 -0
  45. package/dist/commands/intuned-cli/helpers/timeout.d.ts +1 -0
  46. package/dist/commands/intuned-cli/helpers/timeout.js +23 -0
  47. package/dist/commands/intuned-cli/helpers/validation.d.ts +2 -0
  48. package/dist/commands/intuned-cli/helpers/validation.js +12 -0
  49. package/dist/commands/intuned-cli/main.js +4 -1
  50. package/dist/{common/cli → commands/intuned-cli}/types.d.ts +1 -32
  51. package/dist/common/runApi/types.d.ts +140 -9
  52. package/dist/common/runApi/types.js +28 -27
  53. package/package.json +2 -7
  54. package/tsconfig.json +2 -1
  55. package/bin/check-auth-session +0 -3
  56. package/bin/cli-build +0 -3
  57. package/bin/create-auth-session +0 -3
  58. package/bin/deploy +0 -3
  59. package/bin/init +0 -3
  60. package/bin/run-api +0 -3
  61. package/dist/commands/cli-auth-sessions/check.d.ts +0 -2
  62. package/dist/commands/cli-auth-sessions/check.js +0 -40
  63. package/dist/commands/cli-auth-sessions/create.d.ts +0 -2
  64. package/dist/commands/cli-auth-sessions/create.js +0 -53
  65. package/dist/commands/cli-auth-sessions/utils.d.ts +0 -28
  66. package/dist/commands/cli-auth-sessions/utils.js +0 -284
  67. package/dist/commands/cli-build/cli-build.d.ts +0 -2
  68. package/dist/commands/cli-build/cli-build.js +0 -20
  69. package/dist/commands/deploy/deploy.d.ts +0 -2
  70. package/dist/commands/deploy/deploy.js +0 -47
  71. package/dist/commands/deploy/utils.d.ts +0 -16
  72. package/dist/commands/deploy/utils.js +0 -407
  73. package/dist/commands/init/init.d.ts +0 -2
  74. package/dist/commands/init/init.js +0 -22
  75. package/dist/commands/init/utils.d.ts +0 -11
  76. package/dist/commands/init/utils.js +0 -175
  77. package/dist/commands/intuned-cli/commands/helpers.d.ts +0 -28
  78. package/dist/commands/intuned-cli/commands/helpers.js +0 -138
  79. package/dist/commands/run-api-cli/run-api.d.ts +0 -2
  80. package/dist/commands/run-api-cli/run-api.js +0 -57
  81. package/dist/commands/run-api-cli/utils.d.ts +0 -9
  82. package/dist/commands/run-api-cli/utils.js +0 -144
  83. package/dist/common/cli/cliReadme.d.ts +0 -1
  84. /package/dist/commands/intuned-cli/{terminal.d.ts → helpers/terminal.d.ts} +0 -0
  85. /package/dist/commands/intuned-cli/{terminal.js → helpers/terminal.js} +0 -0
  86. /package/dist/{common/cli → commands/intuned-cli}/types.js +0 -0
@@ -3,76 +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 _utils = require("../../cli-auth-sessions/utils");
13
- var _path = _interopRequireDefault(require("path"));
14
- var _helpers = require("../commands/helpers");
12
+ var _helpers = require("../helpers");
15
13
  var _runApi = require("../../../common/runApi");
16
14
  var _constants = require("../../../common/constants");
17
15
  var _tsNodeImport = require("../../common/tsNodeImport");
18
- var _terminal = require("../terminal");
19
- function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
16
+ var _terminal = require("../helpers/terminal");
20
17
  async function executeRunValidateAuthSessionCLI({
21
18
  id,
22
19
  autoRecreate,
23
20
  checkRetries,
24
21
  createRetries,
25
- useExistingContext = false,
26
22
  ...rest
27
23
  }) {
28
- const validate = async () => {
29
- (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
+ }
30
39
  const {
31
- authSessionInstanceStoragePath
32
- } = await (0, _utils.retrieveAuthSessionInstance)(id, true);
33
- const authSessionPathToUse = authSessionInstanceStoragePath;
34
- 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
+ });
35
54
  const checkResult = await runCheckWithRetries({
36
- authSessionPath: authSessionPathToUse,
55
+ auth: storageState,
37
56
  retries: checkRetries,
38
57
  ...rest
39
58
  });
40
59
  if (!checkResult) {
41
- if (!autoRecreate) {
42
- throw new _helpers.CLIError("Auto recreate is disabled, please provide a new auth session or update it manually");
43
- }
44
- const {
45
- metadata
46
- } = await (0, _utils.retrieveAuthSessionInstance)(id);
47
- if (metadata?.authSessionType === "MANUAL") {
48
- throw new _helpers.CLIError("Auth session is recorder-based, please provide a new one or update it manually");
49
- }
50
- (0, _terminal.terminal)("^+Auto recreate is enabled - trying to re-create it^:\n");
51
- await (0, _helpers.assertApiFileExists)(_constants.AUTH_SESSIONS_FOLDER_NAME, "create");
52
- const authSessionInput = metadata?.authSessionInput ?? {};
53
- await runCreateWithRetries({
54
- authSessionId: id,
55
- authSessionInput,
56
- retries: createRetries,
57
- ...rest
58
- });
59
- const checkResult = await runCheckWithRetries({
60
- authSessionPath: authSessionPathToUse,
61
- retries: checkRetries,
62
- ...rest
63
- });
64
- if (!checkResult) {
65
- throw new _helpers.CLIError("Failed to re-create auth session");
66
- }
60
+ throw new _helpers.CLIError("Failed to re-create auth session");
67
61
  }
68
- (0, _terminal.terminal)(`^+^gAuth session validated successfully^:\n`);
69
- return authSessionPathToUse;
70
- };
71
- if (useExistingContext) {
72
- return await validate();
73
- } else {
74
- return await (0, _helpers.withCLIContext)(validate);
75
62
  }
63
+ (0, _terminal.terminal)(`^+^gAuth session validated successfully^:\n`);
64
+ return storageState;
76
65
  }
77
66
  async function executeRunCreateAuthSessionCLI({
78
67
  id,
@@ -82,29 +71,28 @@ async function executeRunCreateAuthSessionCLI({
82
71
  log = true,
83
72
  ...rest
84
73
  }) {
85
- return (0, _helpers.withCLIContext)(async () => {
86
- id = id ?? `auth-session-${Date.now()}`;
87
- (0, _terminal.terminal)(`^+Creating auth session with id ^c${id}^:\n`);
88
- await Promise.all([await (0, _helpers.assertApiFileExists)(_constants.AUTH_SESSIONS_FOLDER_NAME, "create"), await (0, _helpers.assertApiFileExists)(_constants.AUTH_SESSIONS_FOLDER_NAME, "check")]);
89
- const authSessionPath = await runCreateWithRetries({
90
- authSessionId: id,
91
- authSessionInput: input,
92
- retries: createRetries,
93
- ...rest
94
- });
95
- const checkResult = await runCheckWithRetries({
96
- authSessionPath: _path.default.join(authSessionPath, "auth-session.json"),
97
- retries: checkRetries,
98
- ...rest
99
- });
100
- if (!checkResult) {
101
- throw new _helpers.CLIError("Failed to create auth session");
102
- }
103
- if (log) {
104
- (0, _terminal.terminal)(`^+^gAuth session created successfully^:\n`);
105
- }
106
- 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
107
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;
108
96
  }
109
97
  async function executeRunUpdateAuthSessionCLI({
110
98
  id,
@@ -114,28 +102,26 @@ async function executeRunUpdateAuthSessionCLI({
114
102
  ...rest
115
103
  }) {
116
104
  (0, _terminal.terminal)(`^+Updating auth session with id ^c${id}^:\n`);
117
- return (0, _helpers.withCLIContext)(async () => {
118
- if (input === undefined) {
119
- const {
120
- metadata
121
- } = await (0, _utils.retrieveAuthSessionInstance)(id);
122
- if (metadata?.authSessionType === "MANUAL") {
123
- throw new Error("Auth session is recorder-based, it cannot be updated.");
124
- }
125
- 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.");
126
111
  }
127
- await Promise.all([await (0, _helpers.assertApiFileExists)(_constants.AUTH_SESSIONS_FOLDER_NAME, "create"), await (0, _helpers.assertApiFileExists)(_constants.AUTH_SESSIONS_FOLDER_NAME, "check")]);
128
- const authSession = await executeRunCreateAuthSessionCLI({
129
- id,
130
- input,
131
- checkRetries,
132
- createRetries,
133
- log: false,
134
- ...rest
135
- });
136
- (0, _terminal.terminal)(`^+^gAuth session updated successfully^:\n`);
137
- 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
138
122
  });
123
+ (0, _terminal.terminal)(`^+^gAuth session updated successfully^:\n`);
124
+ return authSession;
139
125
  }
140
126
  async function executeAttemptCreateAuthSessionCLI({
141
127
  id,
@@ -158,25 +144,23 @@ async function executeAttemptCheckAuthSessionCLI({
158
144
  }) {
159
145
  (0, _terminal.terminal)(`^+Executing check auth session attempt with id ^c${id}^:\n`);
160
146
  await (0, _helpers.assertApiFileExists)(_constants.AUTH_SESSIONS_FOLDER_NAME, "check");
161
- return await (0, _helpers.withCLIContext)(async () => {
162
- const {
163
- authSessionInstanceStoragePath
164
- } = await (0, _utils.retrieveAuthSessionInstance)(id, true);
165
- const authSessionPathToUse = authSessionInstanceStoragePath;
166
- const checkResult = await runCheckWithRetries({
167
- authSessionPath: authSessionPathToUse,
168
- retries: 1,
169
- ...rest
170
- });
171
- if (!checkResult) {
172
- throw new _helpers.CLIError("Check failed");
173
- }
174
- (0, _terminal.terminal)(`^+^gAuth session check passed^:\n`);
175
- return authSessionPathToUse;
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
176
155
  });
156
+ if (!checkResult) {
157
+ throw new _helpers.CLIError("Check failed");
158
+ }
159
+ (0, _terminal.terminal)(`^+^gAuth session check passed^:\n`);
160
+ return storageState;
177
161
  }
178
162
  async function runCheck({
179
- authSessionPath,
163
+ auth,
180
164
  proxy,
181
165
  headless,
182
166
  timeout
@@ -193,8 +177,8 @@ async function runCheck({
193
177
  },
194
178
  auth: {
195
179
  session: {
196
- type: "file",
197
- path: authSessionPath
180
+ type: "state",
181
+ state: auth
198
182
  },
199
183
  runCheck: false
200
184
  },
@@ -202,10 +186,7 @@ async function runCheck({
202
186
  abortSignal
203
187
  });
204
188
  if (runApiResult.isErr()) {
205
- if (runApiResult.error instanceof _runApi.AutomationError) {
206
- throw runApiResult.error;
207
- }
208
- return false;
189
+ throw runApiResult.error;
209
190
  }
210
191
  const result = runApiResult.value.result;
211
192
  if (!result) {
@@ -214,6 +195,7 @@ async function runCheck({
214
195
  return result;
215
196
  }, timeout);
216
197
  }
198
+ const _runCheck = exports._runCheck = runCheck;
217
199
  async function runCreate({
218
200
  authSessionInput,
219
201
  proxy,
@@ -221,10 +203,9 @@ async function runCreate({
221
203
  timeout
222
204
  }) {
223
205
  return await (0, _helpers.withTimeout)(async abortSignal => {
224
- const createApiName = `${_constants.AUTH_SESSIONS_FOLDER_NAME}/create`;
225
206
  const result = await (0, _runApi.runApi)({
226
207
  automationFunction: {
227
- name: createApiName,
208
+ name: `${_constants.AUTH_SESSIONS_FOLDER_NAME}/create`,
228
209
  params: authSessionInput
229
210
  },
230
211
  runOptions: {
@@ -237,17 +218,14 @@ async function runCreate({
237
218
  abortSignal
238
219
  });
239
220
  if (result.isErr()) {
240
- if (result.error instanceof _runApi.AutomationError) {
241
- throw result.error.error;
242
- }
243
- console.error(result.error);
244
- throw new Error("Error while running create");
221
+ throw result.error;
245
222
  }
246
223
  return result.value.session;
247
224
  }, timeout);
248
225
  }
226
+ const _runCreate = exports._runCreate = runCreate;
249
227
  async function runCheckWithRetries({
250
- authSessionPath,
228
+ auth,
251
229
  retries,
252
230
  ...rest
253
231
  }) {
@@ -255,9 +233,12 @@ async function runCheckWithRetries({
255
233
  (0, _terminal.terminal)(`\n^+Running ^cauth session check${i === 0 ? "" : ` ^/(Attempt ${i + 1})`}^:...\n`);
256
234
  try {
257
235
  const checkResult = await runCheck({
258
- authSessionPath,
236
+ auth,
259
237
  ...rest
260
238
  });
239
+ console.log({
240
+ checkResult
241
+ });
261
242
  if (checkResult) {
262
243
  (0, _terminal.terminal)(`^+^gAuth session check passed^:\n`);
263
244
  return true;
@@ -265,15 +246,16 @@ async function runCheckWithRetries({
265
246
  } catch (error) {
266
247
  if (error instanceof _runApi.AutomationError) {
267
248
  (0, _helpers.logAutomationError)(error);
268
- continue;
249
+ } else {
250
+ throw error;
269
251
  }
270
- throw error;
271
252
  }
272
253
  (0, _terminal.terminal)(`^+^yAuth session check failed^:\n`);
273
254
  }
274
255
  (0, _terminal.terminal)(`^+^rAuth session check failed after ${retries} attempts^:\n`);
275
256
  return false;
276
257
  }
258
+ const _runCheckWithRetries = exports._runCheckWithRetries = runCheckWithRetries;
277
259
  async function runCreateWithRetries({
278
260
  authSessionId,
279
261
  authSessionInput,
@@ -293,13 +275,21 @@ async function runCreateWithRetries({
293
275
  } catch (error) {
294
276
  if (error instanceof _runApi.AutomationError) {
295
277
  (0, _helpers.logAutomationError)(error);
296
- continue;
278
+ } else {
279
+ throw error;
297
280
  }
298
- throw error;
281
+ (0, _terminal.terminal)(`^+^yAuth session create failed^:\n`);
299
282
  }
300
283
  }
301
284
  if (!newAuthSessionInstance) {
302
285
  throw new _helpers.CLIError(`Failed to create auth session after ${retries} retries`);
303
286
  }
304
- return await (0, _utils.storeAuthSessionInstance)(newAuthSessionInstance, authSessionId, authSessionInput);
305
- }
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;
@@ -8,7 +8,7 @@ var fs = _interopRequireWildcard(require("fs-extra"));
8
8
  var path = _interopRequireWildcard(require("path"));
9
9
  var _child_process = require("child_process");
10
10
  var _util = require("util");
11
- var _terminal = require("../terminal");
11
+ var _terminal = require("../helpers/terminal");
12
12
  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); }
13
13
  function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
14
14
  const execPromise = (0, _util.promisify)(_child_process.exec);
@@ -1,5 +1,5 @@
1
1
  import { z } from "zod";
2
- import { AuthCredentials, FileSystemTree } from "../../../common/cli/types";
2
+ import type { AuthCredentials, FileSystemTree } from "../types";
3
3
  export declare function convertProjectToCodeTree(projectPath: string): Promise<FileSystemTree>;
4
4
  export declare function runDeployProject(projectName: string, auth: AuthCredentials): Promise<void>;
5
5
  export declare const projectNameSchema: z.ZodEffects<z.ZodString, string, string>;
@@ -12,14 +12,12 @@ var path = _interopRequireWildcard(require("path"));
12
12
  var _minimatch = require("minimatch");
13
13
  var _zod = require("zod");
14
14
  var _projectExclusions = _interopRequireDefault(require("../../common/projectExclusions"));
15
- var _constants = require("../../../common/cli/constants");
16
- var _utils = require("../../../common/cli/utils");
17
- var _utils2 = require("../../init/utils");
15
+ var _constants = require("../constants");
16
+ var _helpers = require("../helpers");
18
17
  var _lodash = require("lodash");
19
18
  var _uuid = require("uuid");
20
- var _terminal = require("../terminal");
19
+ var _terminal = require("../helpers/terminal");
21
20
  var _promises = require("timers/promises");
22
- var _helpers = require("../commands/helpers");
23
21
  var _ms = _interopRequireDefault(require("ms"));
24
22
  var _build = require("./build");
25
23
  function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
@@ -123,7 +121,7 @@ async function runDeployProject(projectName, auth) {
123
121
  workspaceId,
124
122
  apiKey
125
123
  } = auth;
126
- const baseUrl = (0, _utils.getBaseUrl)();
124
+ const baseUrl = (0, _helpers.getBaseUrl)();
127
125
  const url = `${baseUrl}/api/v1/workspace/${workspaceId}/projects/create`;
128
126
  const headers = {
129
127
  "x-api-key": apiKey,
@@ -188,7 +186,7 @@ async function runDeployProject(projectName, auth) {
188
186
  _terminal.terminal.eraseLine();
189
187
  spinner.animate(false);
190
188
  if (status === "completed") {
191
- const url = (0, _utils.getBaseUrl)();
189
+ const url = (0, _helpers.getBaseUrl)();
192
190
  (0, _terminal.terminal)(`\n^g^+Project deployed successfully!^:\n`);
193
191
  (0, _terminal.terminal)(`^+You can check your project on the platform:^s ^c^_${url}/projects/${projectId}/details^:\n`);
194
192
  return;
@@ -309,7 +307,7 @@ const validateIntunedProject = async () => {
309
307
  };
310
308
  exports.validateIntunedProject = validateIntunedProject;
311
309
  const checkIntunedProjectDeployStatus = async (workspaceId, projectName, apiKey) => {
312
- const baseUrl = (0, _utils.getBaseUrl)();
310
+ const baseUrl = (0, _helpers.getBaseUrl)();
313
311
  const url = `${baseUrl}/api/v1/workspace/${workspaceId}/projects/create/${projectName}/result`;
314
312
  const headers = {
315
313
  "x-api-key": apiKey,
@@ -326,7 +324,7 @@ const checkIntunedProjectDeployStatus = async (workspaceId, projectName, apiKey)
326
324
  };
327
325
  }
328
326
  if (!response.ok) {
329
- throw new Error(`Error querying deployment status ${response.status}: ${await response.text()}`);
327
+ throw new _helpers.CLIError(`Error querying deployment status ${response.status}: ${await response.text()}`);
330
328
  }
331
329
  const data = await response.json();
332
330
  if (data.status) {
@@ -345,7 +343,7 @@ async function mapToIDEParams(tree) {
345
343
  if (!tree) {
346
344
  return;
347
345
  }
348
- if (!tree["parameters"] || (0, _utils2._isFileNode)(tree["parameters"])) {
346
+ if (!tree["parameters"] || "file" in tree["parameters"]) {
349
347
  return;
350
348
  }
351
349
  const apiParametersMap = {};
@@ -355,7 +353,7 @@ async function mapToIDEParams(tree) {
355
353
  };
356
354
  for (const parameterKey of cliParameters) {
357
355
  const parameter = tree["parameters"].directory[parameterKey];
358
- if ((0, _utils2._isDirectoryNode)(parameter)) {
356
+ if ("directory" in parameter) {
359
357
  continue;
360
358
  }
361
359
  if ((0, _lodash.isEmpty)(parameter.file.contents)) {
@@ -5,6 +5,7 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.loadParameters = loadParameters;
7
7
  var fs = _interopRequireWildcard(require("fs-extra"));
8
+ var _helpers = require("../helpers");
8
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); }
9
10
  function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
10
11
  async function loadParameters(parameters) {
@@ -15,7 +16,7 @@ async function loadParameters(parameters) {
15
16
  try {
16
17
  inputData = JSON.parse(parameters);
17
18
  } catch (err) {
18
- throw new Error("Parameters must be a valid JSON string or a path to a JSON file");
19
+ throw new _helpers.CLIError("Parameters must be a valid JSON string or a path to a JSON file");
19
20
  }
20
21
  }
21
22
  return inputData;
@@ -36,10 +37,10 @@ async function loadParametersFromFile(parametersFile) {
36
37
  return inputData;
37
38
  } catch (error) {
38
39
  if (error.code === "ENOENT") {
39
- throw new Error(`Parameters file not found: ${parametersFile}`);
40
+ throw new _helpers.CLIError(`Parameters file not found: ${parametersFile}`);
40
41
  } else if (error instanceof SyntaxError) {
41
- throw new Error(`Invalid JSON in parameters file: ${error.message}`);
42
+ throw new _helpers.CLIError(`Invalid JSON in parameters file: ${error.message}`);
42
43
  }
43
- throw new Error(`Error reading parameters file: ${error.message}`);
44
+ throw new _helpers.CLIError(`Error reading parameters file: ${error.message}`);
44
45
  }
45
46
  }
@@ -1,4 +1,4 @@
1
- import { FileSystemTree, TemplateId } from "../../../common/cli/types";
1
+ import { FileSystemTree, TemplateId } from "../types";
2
2
  export declare function mountFiles(cwd: string, tree: FileSystemTree): Promise<void>;
3
3
  export declare function checkEmptyDirectory(): Promise<boolean>;
4
4
  export declare function selectTemplate(templateName: string): Promise<TemplateId>;
@@ -8,14 +8,11 @@ exports.mountFiles = mountFiles;
8
8
  exports.scaffoldProject = scaffoldProject;
9
9
  exports.selectTemplate = selectTemplate;
10
10
  var fs = _interopRequireWildcard(require("fs-extra"));
11
- var _types = require("../../../common/cli/types");
11
+ var _types = require("../types");
12
12
  var _path = _interopRequireDefault(require("path"));
13
13
  var _projectExclusions = _interopRequireDefault(require("../../common/projectExclusions"));
14
- var _constants = require("../../../common/cli/constants");
15
- var _cliReadme = require("../../../common/cli/cliReadme");
16
- var _utils = require("../../../common/cli/utils");
17
- var _helpers = require("../commands/helpers");
18
- var _terminal = require("../terminal");
14
+ var _constants = require("../constants");
15
+ var _helpers = require("../helpers");
19
16
  function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
20
17
  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); }
21
18
  function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
@@ -61,10 +58,10 @@ async function selectTemplate(templateName) {
61
58
  }
62
59
  return templateName;
63
60
  }
64
- (0, _terminal.terminal)("^+Select a template (ESC to cancel):^:\n");
61
+ (0, _helpers.terminal)("^+Select a template (ESC to cancel):^:\n");
65
62
  const {
66
63
  promise: selectedCommandPromise
67
- } = _terminal.terminal.singleColumnMenu(_types.templateIds, {
64
+ } = _helpers.terminal.singleColumnMenu(_types.templateIds, {
68
65
  cancelable: true
69
66
  });
70
67
  const selectedTemplateIndex = (await selectedCommandPromise).selectedIndex;
@@ -77,10 +74,10 @@ async function selectTemplate(templateName) {
77
74
  }
78
75
  async function scaffoldProject(templateId, isTargetDirectoryEmpty) {
79
76
  if (!isTargetDirectoryEmpty) {
80
- (0, _terminal.terminal)("^+The current directory is not empty. Do you want to proceed and override files?^: (y/N)");
77
+ (0, _helpers.terminal)("^+The current directory is not empty. Do you want to proceed and override files?^: (y/N)");
81
78
  const {
82
79
  promise
83
- } = _terminal.terminal.yesOrNo({
80
+ } = _helpers.terminal.yesOrNo({
84
81
  no: ["n", "ENTER", "ESCAPE"],
85
82
  yes: ["y"],
86
83
  echoNo: " no\n",
@@ -94,16 +91,16 @@ async function scaffoldProject(templateId, isTargetDirectoryEmpty) {
94
91
  }
95
92
  }
96
93
  const cwd = process.cwd();
97
- (0, _terminal.terminal)(`^c🚀 Initializing ^:^+${templateId}^:^c project...\n`);
94
+ (0, _helpers.terminal)(`^c🚀 Initializing ^:^+${templateId}^:^c project...\n`);
98
95
  const template = await fetchProjectTemplate(templateId);
99
- (0, _terminal.terminal)(`^c🔨 Creating project files...^:\n`);
96
+ (0, _helpers.terminal)(`^c🔨 Creating project files...^:\n`);
100
97
  const codeTree = template;
101
98
  await prepareCLITemplate(codeTree);
102
99
  await mountFiles(cwd, codeTree);
103
- (0, _terminal.terminal)(`^g^+🎉 Project initialized successfully!^ ^GRun ^:^+yarn^:^G to install dependencies and start coding!\n`);
100
+ (0, _helpers.terminal)(`^g^+🎉 Project initialized successfully!^ ^GRun ^:^+yarn^:^G to install dependencies and start coding!\n`);
104
101
  }
105
102
  async function fetchProjectTemplate(templateId) {
106
- const baseUrl = (0, _utils.getBaseUrl)();
103
+ const baseUrl = (0, _helpers.getBaseUrl)();
107
104
  const url = `${baseUrl}/api/templates/${templateId}`;
108
105
  const response = await fetch(url);
109
106
  if (!response.ok) {
@@ -133,7 +130,7 @@ async function prepareCLITemplate(codeTree) {
133
130
  }
134
131
  codeTree["README.md"] = {
135
132
  file: {
136
- contents: _cliReadme.cliReadme
133
+ contents: _constants.readme
137
134
  }
138
135
  };
139
136
  }
@@ -0,0 +1,3 @@
1
+ import { API_FOLDER_NAME, AUTH_SESSIONS_FOLDER_NAME } from "../../../common/constants";
2
+ export declare function assertApiFileExists(dirname: typeof AUTH_SESSIONS_FOLDER_NAME, api: "create" | "check"): Promise<void>;
3
+ export declare function assertApiFileExists(dirname: typeof API_FOLDER_NAME, api: string): Promise<void>;
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.assertApiFileExists = assertApiFileExists;
7
+ var _path = _interopRequireDefault(require("path"));
8
+ var _fsExtra = require("fs-extra");
9
+ var _errors = require("./errors");
10
+ function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
11
+ async function assertApiFileExists(dirname, api) {
12
+ const file = `${dirname}/${api}.ts`;
13
+ const filePath = _path.default.join(process.cwd(), file);
14
+ if (!(await (0, _fsExtra.exists)(filePath))) {
15
+ throw new _errors.CLIAssertionError(`^+^r API^ ^+${dirname}/${api}^ ^r^+is not implemented.^:`, {
16
+ autoColor: false
17
+ });
18
+ }
19
+ }
@@ -0,0 +1,41 @@
1
+ import type { AuthSessionMetadata } from "../types";
2
+ import { RunApiStorageState as StorageState } from "../../../common/runApi";
3
+ export declare function isAuthEnabled(): Promise<boolean>;
4
+ export declare function assertAuthEnabled(): Promise<void>;
5
+ export declare function assertAuthConsistent(authSession: string | undefined): Promise<void>;
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
+ };
33
+ metadata: AuthSessionMetadata;
34
+ }>;
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;