@intuned/runtime-dev 1.2.0-dev-52 → 1.2.1-hooks.0

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 (135) hide show
  1. package/.babelrc +2 -2
  2. package/.npmrc.wtf +1 -0
  3. package/CHANGELOG.md +5 -1
  4. package/WebTemplate.zip +0 -0
  5. package/bin/intuned +2 -0
  6. package/dist/commands/api/run.js +4 -3
  7. package/dist/commands/common/getFirstLineNumber.js +2 -4
  8. package/dist/commands/interface/run.js +5 -6
  9. package/dist/commands/intuned-cli/commands/attempt.command.d.ts +1 -0
  10. package/dist/commands/intuned-cli/commands/attempt.command.js +8 -0
  11. package/dist/commands/intuned-cli/commands/attempt_api.command.d.ts +1 -0
  12. package/dist/commands/intuned-cli/commands/attempt_api.command.js +40 -0
  13. package/dist/commands/intuned-cli/commands/attempt_authsession.command.d.ts +1 -0
  14. package/dist/commands/intuned-cli/commands/attempt_authsession.command.js +8 -0
  15. package/dist/commands/intuned-cli/commands/attempt_authsession_check.command.d.ts +1 -0
  16. package/dist/commands/intuned-cli/commands/attempt_authsession_check.command.js +24 -0
  17. package/dist/commands/intuned-cli/commands/attempt_authsession_create.command.d.ts +1 -0
  18. package/dist/commands/intuned-cli/commands/attempt_authsession_create.command.js +36 -0
  19. package/dist/commands/intuned-cli/commands/build.command.d.ts +1 -0
  20. package/dist/commands/intuned-cli/commands/build.command.js +12 -0
  21. package/dist/commands/intuned-cli/commands/command.d.ts +2 -0
  22. package/dist/commands/intuned-cli/commands/command.js +9 -0
  23. package/dist/commands/intuned-cli/commands/deploy.command.d.ts +1 -0
  24. package/dist/commands/intuned-cli/commands/deploy.command.js +46 -0
  25. package/dist/commands/intuned-cli/commands/index.d.ts +15 -0
  26. package/dist/commands/intuned-cli/commands/index.js +170 -0
  27. package/dist/commands/intuned-cli/commands/init.command.d.ts +1 -0
  28. package/dist/commands/intuned-cli/commands/init.command.js +13 -0
  29. package/dist/commands/intuned-cli/commands/run.command.d.ts +1 -0
  30. package/dist/commands/intuned-cli/commands/run.command.js +8 -0
  31. package/dist/commands/intuned-cli/commands/run_api.command.d.ts +1 -0
  32. package/dist/commands/intuned-cli/commands/run_api.command.js +54 -0
  33. package/dist/commands/intuned-cli/commands/run_authsession.command.d.ts +20 -0
  34. package/dist/commands/intuned-cli/commands/run_authsession.command.js +13 -0
  35. package/dist/commands/intuned-cli/commands/run_authsession_create.command.d.ts +1 -0
  36. package/dist/commands/intuned-cli/commands/run_authsession_create.command.js +39 -0
  37. package/dist/commands/intuned-cli/commands/run_authsession_update.command.d.ts +1 -0
  38. package/dist/commands/intuned-cli/commands/run_authsession_update.command.js +39 -0
  39. package/dist/commands/intuned-cli/commands/run_authsession_validate.command.d.ts +1 -0
  40. package/dist/commands/intuned-cli/commands/run_authsession_validate.command.js +37 -0
  41. package/dist/commands/intuned-cli/commands/types.d.ts +21 -0
  42. package/dist/commands/intuned-cli/commands/types.js +21 -0
  43. package/dist/commands/intuned-cli/constants/index.d.ts +17 -0
  44. package/dist/commands/intuned-cli/constants/index.js +25 -0
  45. package/dist/commands/intuned-cli/controller/__test__/api.test.js +280 -0
  46. package/dist/commands/intuned-cli/controller/__test__/authSession.test.js +676 -0
  47. package/dist/commands/intuned-cli/controller/api.d.ts +44 -0
  48. package/dist/commands/intuned-cli/controller/api.js +181 -0
  49. package/dist/commands/intuned-cli/controller/authSession.d.ts +198 -0
  50. package/dist/commands/intuned-cli/controller/authSession.js +292 -0
  51. package/dist/commands/intuned-cli/controller/build.d.ts +1 -0
  52. package/dist/commands/intuned-cli/controller/build.js +36 -0
  53. package/dist/commands/intuned-cli/controller/deploy.d.ts +15 -0
  54. package/dist/commands/{deploy/utils.js → intuned-cli/controller/deploy.js} +115 -109
  55. package/dist/commands/intuned-cli/controller/index.d.ts +1 -0
  56. package/dist/commands/intuned-cli/controller/index.js +46 -0
  57. package/dist/commands/intuned-cli/helpers/api.d.ts +3 -0
  58. package/dist/commands/intuned-cli/helpers/api.js +19 -0
  59. package/dist/commands/intuned-cli/helpers/auth.d.ts +41 -0
  60. package/dist/commands/intuned-cli/helpers/auth.js +129 -0
  61. package/dist/commands/intuned-cli/helpers/backend.d.ts +8 -0
  62. package/dist/commands/intuned-cli/helpers/backend.js +26 -0
  63. package/dist/commands/intuned-cli/helpers/context.d.ts +3 -0
  64. package/dist/commands/intuned-cli/helpers/context.js +33 -0
  65. package/dist/commands/intuned-cli/helpers/errors.d.ts +14 -0
  66. package/dist/commands/intuned-cli/helpers/errors.js +55 -0
  67. package/dist/commands/intuned-cli/helpers/index.d.ts +10 -0
  68. package/dist/commands/intuned-cli/helpers/index.js +115 -0
  69. package/dist/commands/intuned-cli/helpers/intunedJson.d.ts +1 -0
  70. package/dist/{common/cli/utils.js → commands/intuned-cli/helpers/intunedJson.js} +0 -16
  71. package/dist/commands/intuned-cli/helpers/proxy.d.ts +5 -0
  72. package/dist/commands/intuned-cli/helpers/proxy.js +23 -0
  73. package/dist/commands/intuned-cli/helpers/terminal.d.ts +5 -0
  74. package/dist/commands/intuned-cli/helpers/terminal.js +13 -0
  75. package/dist/commands/intuned-cli/helpers/timeout.d.ts +1 -0
  76. package/dist/commands/intuned-cli/helpers/timeout.js +23 -0
  77. package/dist/commands/intuned-cli/helpers/validation.d.ts +2 -0
  78. package/dist/commands/intuned-cli/helpers/validation.js +12 -0
  79. package/dist/commands/intuned-cli/index.d.ts +1 -0
  80. package/dist/commands/intuned-cli/index.js +16 -0
  81. package/dist/commands/intuned-cli/main.d.ts +1 -0
  82. package/dist/commands/intuned-cli/main.js +15 -0
  83. package/dist/{common/cli → commands/intuned-cli}/types.d.ts +1 -34
  84. package/dist/{common/cli → commands/intuned-cli}/types.js +1 -2
  85. package/dist/common/assets/browser_scripts.js +2509 -2143
  86. package/dist/common/asyncLocalStorage/index.d.ts +1 -0
  87. package/dist/common/constants.d.ts +1 -0
  88. package/dist/common/constants.js +2 -1
  89. package/dist/common/getPlaywrightConstructs.d.ts +5 -4
  90. package/dist/common/getPlaywrightConstructs.js +71 -35
  91. package/dist/common/jwtTokenManager.js +3 -5
  92. package/dist/common/runApi/errors.js +5 -6
  93. package/dist/common/runApi/index.d.ts +3 -0
  94. package/dist/common/runApi/index.js +22 -21
  95. package/dist/common/runApi/types.d.ts +144 -13
  96. package/dist/common/runApi/types.js +28 -27
  97. package/dist/runtime/executionHelpers.test.js +3 -4
  98. package/dist/runtime/export.d.ts +17 -0
  99. package/dist/runtime/extendPayload.js +1 -1
  100. package/dist/runtime/getCdpAddress.d.ts +1 -0
  101. package/dist/runtime/getCdpAddress.js +11 -0
  102. package/dist/runtime/index.d.ts +1 -0
  103. package/dist/runtime/index.js +8 -1
  104. package/package.json +11 -12
  105. package/tsconfig.json +2 -1
  106. package/bin/check-auth-session +0 -3
  107. package/bin/cli-build +0 -3
  108. package/bin/create-auth-session +0 -3
  109. package/bin/deploy +0 -3
  110. package/bin/init +0 -3
  111. package/bin/run-api +0 -3
  112. package/dist/commands/cli-auth-sessions/check.d.ts +0 -2
  113. package/dist/commands/cli-auth-sessions/check.js +0 -40
  114. package/dist/commands/cli-auth-sessions/create.d.ts +0 -2
  115. package/dist/commands/cli-auth-sessions/create.js +0 -53
  116. package/dist/commands/cli-auth-sessions/utils.d.ts +0 -28
  117. package/dist/commands/cli-auth-sessions/utils.js +0 -285
  118. package/dist/commands/cli-build/cli-build.d.ts +0 -2
  119. package/dist/commands/cli-build/cli-build.js +0 -20
  120. package/dist/commands/deploy/deploy.d.ts +0 -2
  121. package/dist/commands/deploy/deploy.js +0 -47
  122. package/dist/commands/deploy/utils.d.ts +0 -16
  123. package/dist/commands/init/init.d.ts +0 -2
  124. package/dist/commands/init/init.js +0 -22
  125. package/dist/commands/init/utils.d.ts +0 -11
  126. package/dist/commands/init/utils.js +0 -181
  127. package/dist/commands/run-api-cli/run-api.d.ts +0 -2
  128. package/dist/commands/run-api-cli/run-api.js +0 -57
  129. package/dist/commands/run-api-cli/utils.d.ts +0 -9
  130. package/dist/commands/run-api-cli/utils.js +0 -144
  131. package/dist/common/cli/cliReadme.d.ts +0 -1
  132. package/dist/common/cli/cliReadme.js +0 -92
  133. package/dist/common/cli/constants.d.ts +0 -33
  134. package/dist/common/cli/constants.js +0 -39
  135. package/dist/common/cli/utils.d.ts +0 -6
@@ -1,285 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.ensureAuthApi = ensureAuthApi;
7
- exports.ensureRecorderURLs = ensureRecorderURLs;
8
- exports.getAuthType = getAuthType;
9
- exports.getStorageState = getStorageState;
10
- exports.isAuthEnabled = isAuthEnabled;
11
- exports.recordAuthSession = recordAuthSession;
12
- exports.retrieveAuthSessionInstance = retrieveAuthSessionInstance;
13
- exports.runCheckApi = runCheckApi;
14
- exports.runCheckApiViaCLI = runCheckApiViaCLI;
15
- exports.runCreateApi = runCreateApi;
16
- exports.runCreateApiViaCLI = runCreateApiViaCLI;
17
- exports.storeAuthSessionInstance = storeAuthSessionInstance;
18
- var _path = _interopRequireDefault(require("path"));
19
- var _constants = require("../../common/constants");
20
- var fs = _interopRequireWildcard(require("fs-extra"));
21
- var _asyncLocalStorage = require("../../common/asyncLocalStorage");
22
- var _enums = require("../../runtime/enums");
23
- var _nanoid = require("nanoid");
24
- var _runApi = require("../../common/runApi");
25
- var _tsNodeImport = require("../common/tsNodeImport");
26
- var _promptly = require("promptly");
27
- var _utils = require("../../common/cli/utils");
28
- var _types = require("../../common/cli/types");
29
- var playwright = _interopRequireWildcard(require("playwright"));
30
- 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); }
31
- 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; }
32
- function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
33
- async function isAuthEnabled() {
34
- try {
35
- var _intunedJson$authSess;
36
- const intunedJson = await fs.readJSON(_path.default.join(process.cwd(), "Intuned.json"));
37
- return Boolean(intunedJson === null || intunedJson === void 0 || (_intunedJson$authSess = intunedJson.authSessions) === null || _intunedJson$authSess === void 0 ? void 0 : _intunedJson$authSess.enabled);
38
- } catch (error) {
39
- return false;
40
- }
41
- }
42
- async function getAuthType() {
43
- const projectAuthConfig = await (0, _utils.getSettingIntunedJSON)("authSessions");
44
- return projectAuthConfig.type ?? "API";
45
- }
46
- async function ensureRecorderURLs() {
47
- const projectAuthConfig = await (0, _utils.getSettingIntunedJSON)("authSessions");
48
- if (projectAuthConfig.type === "MANUAL" && projectAuthConfig.startUrl && projectAuthConfig.endUrl) {
49
- return {
50
- startUrl: projectAuthConfig.startUrl,
51
- endUrl: projectAuthConfig.endUrl
52
- };
53
- }
54
- throw new Error("Auth session recorder URLs are not configured, please configure them in Intuned.json");
55
- }
56
- async function ensureAuthApi(operation) {
57
- const authApiFile = `${_constants.AUTH_SESSIONS_FOLDER_NAME}/${operation}.ts`;
58
- const authApiFilePath = _path.default.join(process.cwd(), authApiFile);
59
- return await fs.exists(authApiFilePath);
60
- }
61
- async function runCreateApi(authSessionInput) {
62
- try {
63
- const createApiOperationId = (0, _nanoid.nanoid)();
64
- const authSessionInstance = await (0, _asyncLocalStorage.runWithContext)({
65
- runEnvironment: _enums.RunEnvironment.IDE,
66
- extendedPayloads: [],
67
- runId: createApiOperationId
68
- }, () => runCreateApiViaCLI(authSessionInput));
69
- return authSessionInstance;
70
- } catch (error) {
71
- throw new Error(`Error running the create API: ${error.message}`);
72
- }
73
- }
74
- async function runCheckApi(authSessionPath) {
75
- try {
76
- const checkApiOperationId = (0, _nanoid.nanoid)();
77
- const checkResult = await (0, _asyncLocalStorage.runWithContext)({
78
- runEnvironment: _enums.RunEnvironment.IDE,
79
- extendedPayloads: [],
80
- runId: checkApiOperationId
81
- }, () => runCheckApiViaCLI(authSessionPath));
82
- return checkResult;
83
- } catch (error) {
84
- if (error.message === _types.CHECK_FAILED_ERROR_MESSAGE) {
85
- return false;
86
- }
87
- throw new Error(`Error running the check API: ${error.message}`);
88
- }
89
- }
90
- async function runCreateApiViaCLI(authSessionInput) {
91
- const createApiName = `${_constants.AUTH_SESSIONS_FOLDER_NAME}/create`;
92
- const generator = (0, _runApi.runApiGenerator)({
93
- automationFunction: {
94
- name: createApiName,
95
- params: authSessionInput
96
- },
97
- runOptions: {
98
- headless: false,
99
- environment: "standalone"
100
- },
101
- retrieveSession: true,
102
- importFunction: _tsNodeImport.tsNodeImport
103
- });
104
- let nextGeneratorParam = undefined;
105
- while (true) {
106
- const {
107
- value,
108
- done
109
- } = await generator.next(...(nextGeneratorParam ? [nextGeneratorParam] : []));
110
- if (done) {
111
- if (value.isErr()) {
112
- if (value.error instanceof _runApi.AutomationError) {
113
- throw value.error.error;
114
- }
115
- console.error(value.error);
116
- throw new Error("Error while running create");
117
- }
118
- return value.value.session;
119
- }
120
- if (value.action === "request_more_info" && value.requestType == "multiple_choice") {
121
- nextGeneratorParam = await (0, _promptly.prompt)(value.messageToUser + `, choices: ${value.choices}`, {
122
- validator: input => {
123
- if (!value.choices.includes(input)) {
124
- throw new Error("Please type on of the allowed choices");
125
- }
126
- return input;
127
- }
128
- });
129
- } else if (value.action === "request_more_info" && value.requestType == "otp") {
130
- nextGeneratorParam = await (0, _promptly.prompt)(value.messageToUser, {});
131
- }
132
- }
133
- }
134
- async function runCheckApiViaCLI(authSessionPath) {
135
- const runApiResult = await (0, _runApi.runApi)({
136
- automationFunction: {
137
- name: `${_constants.AUTH_SESSIONS_FOLDER_NAME}/check`
138
- },
139
- runOptions: {
140
- headless: false,
141
- environment: "standalone"
142
- },
143
- auth: {
144
- session: {
145
- type: "file",
146
- path: authSessionPath
147
- },
148
- runCheck: false
149
- },
150
- importFunction: _tsNodeImport.tsNodeImport
151
- });
152
- if (runApiResult.isErr()) {
153
- if (runApiResult.error instanceof _runApi.AutomationError) {
154
- throw runApiResult.error.error;
155
- }
156
- return false;
157
- }
158
- const result = runApiResult.value.result;
159
- if (!result) {
160
- return false;
161
- }
162
- return result;
163
- }
164
- async function storeAuthSessionInstance(authSessionInstance, customName, authSessionInput) {
165
- try {
166
- const authSessionsDirectoryPath = _path.default.join(process.cwd(), _constants.AUTH_SESSIONS_INSTANCES_FOLDER_NAME);
167
- await fs.ensureDir(authSessionsDirectoryPath);
168
- const authSessionInstanceId = customName ?? `auth-session-${Date.now()}`;
169
- const authSessionInstancePath = _path.default.join(authSessionsDirectoryPath, authSessionInstanceId);
170
- const authSessionExists = await fs.pathExists(authSessionInstancePath);
171
- await fs.ensureDir(authSessionInstancePath);
172
- const authSessionInstanceStoragePath = _path.default.join(authSessionInstancePath, `auth-session.json`);
173
- await fs.writeJSON(authSessionInstanceStoragePath, authSessionInstance, {
174
- spaces: 2
175
- });
176
- const projectAuthConfig = await (0, _utils.getSettingIntunedJSON)("authSessions");
177
- let existingMetadata = {};
178
- const authSessionInstanceMetadataPath = _path.default.join(authSessionInstancePath, `metadata.json`);
179
- if (authSessionExists) {
180
- try {
181
- existingMetadata = await fs.readJSON(authSessionInstanceMetadataPath);
182
- } catch (readError) {
183
- existingMetadata = {};
184
- }
185
- }
186
- const authSessionMetadata = {
187
- createdAt: existingMetadata.createdAt || new Date().toISOString(),
188
- updatedAt: new Date().toISOString(),
189
- ...(projectAuthConfig.type === "API" && {
190
- authSessionInput: authSessionInput || existingMetadata.authSessionInput || {}
191
- }),
192
- authSessionId: authSessionInstanceId,
193
- authSessionType: projectAuthConfig.type ?? existingMetadata.authSessionType ?? "API",
194
- ...(projectAuthConfig.type === "MANUAL" && {
195
- recorderStartUrl: projectAuthConfig.startUrl,
196
- recorderEndUrl: projectAuthConfig.endUrl
197
- })
198
- };
199
- await fs.writeJSON(authSessionInstanceMetadataPath, authSessionMetadata, {
200
- spaces: 2
201
- });
202
- return authSessionInstancePath;
203
- } catch (error) {
204
- throw new Error(`Error storing auth session instance: ${error.message}`);
205
- }
206
- }
207
- async function retrieveAuthSessionInstance(authSessionId, pathsOnly = false) {
208
- try {
209
- const authSessionInstancePath = _path.default.join(process.cwd(), _constants.AUTH_SESSIONS_INSTANCES_FOLDER_NAME, authSessionId);
210
- const authSessionInstanceStoragePath = _path.default.join(authSessionInstancePath, `auth-session.json`);
211
- const authSessionInstanceMetadataPath = _path.default.join(authSessionInstancePath, `metadata.json`);
212
- if (!(await fs.exists(authSessionInstanceStoragePath))) {
213
- throw new Error(`Auth session instance with ID ${authSessionId} not found`);
214
- }
215
- if (pathsOnly) {
216
- return {
217
- authSessionInstanceStoragePath,
218
- authSessionInstanceMetadataPath
219
- };
220
- }
221
- const authSessionInstance = await fs.readJSON(authSessionInstanceStoragePath);
222
- const metadata = await fs.readJSON(authSessionInstanceMetadataPath);
223
- return {
224
- authSessionInstance,
225
- metadata
226
- };
227
- } catch (error) {
228
- throw new Error(`Error retrieving auth session instance: ${error.message}`);
229
- }
230
- }
231
- async function getStorageState(context) {
232
- const result = {};
233
- const storageState = await context.storageState();
234
- result.cookies = storageState.cookies;
235
- result.origins = storageState.origins;
236
- const sessionDataList = [];
237
- const pages = context.pages();
238
- for (const page of pages) {
239
- if (page.isClosed()) continue;
240
- try {
241
- const sessionData = await page.evaluate(() => {
242
- const items = {
243
- ...window.sessionStorage
244
- };
245
- return {
246
- origin: window.location.origin,
247
- sessionStorage: Object.entries(items).map(([name, value]) => ({
248
- name,
249
- value
250
- }))
251
- };
252
- });
253
- sessionDataList.push(sessionData);
254
- } catch (error) {
255
- console.error("Error getting sessionStorage:", error);
256
- }
257
- }
258
- result.sessionStorage = sessionDataList;
259
- return result;
260
- }
261
- async function recordAuthSession(startUrl, endUrl) {
262
- let browser;
263
- try {
264
- browser = await playwright.chromium.launch({
265
- headless: false,
266
- args: ["--start-maximized", "--no-sandbox"]
267
- });
268
- const context = await browser.newContext({
269
- viewport: null
270
- });
271
- const page = await context.newPage();
272
- await page.goto(startUrl);
273
- await page.waitForURL(url => url.toString().startsWith(endUrl), {
274
- timeout: 300000
275
- });
276
- const storageState = await getStorageState(context);
277
- return storageState;
278
- } catch (error) {
279
- throw new Error(`Authentication recording failed: ${error.message}`);
280
- } finally {
281
- if (browser) {
282
- await browser.close();
283
- }
284
- }
285
- }
@@ -1,2 +0,0 @@
1
- #!/usr/bin/env node
2
- export {};
@@ -1,20 +0,0 @@
1
- #!/usr/bin/env node
2
- "use strict";
3
-
4
- var _commander = require("commander");
5
- var _dotenv = _interopRequireDefault(require("dotenv"));
6
- var _utils = require("../deploy/utils");
7
- function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
8
- _dotenv.default.config({
9
- path: `.env`
10
- });
11
- _commander.program.name("intuned-build-project").description("Build your current Intuned project").action(async () => {
12
- try {
13
- await (0, _utils.runBuild)();
14
- } catch (error) {
15
- process.exit(1);
16
- } finally {
17
- process.exit(0);
18
- }
19
- });
20
- _commander.program.parse(process.argv);
@@ -1,2 +0,0 @@
1
- #!/usr/bin/env node
2
- export {};
@@ -1,47 +0,0 @@
1
- #!/usr/bin/env node
2
- "use strict";
3
-
4
- var _commander = require("commander");
5
- var _chalk = _interopRequireDefault(require("chalk"));
6
- var _dotenv = _interopRequireDefault(require("dotenv"));
7
- var _utils = require("./utils");
8
- var _utils2 = require("../../common/cli/utils");
9
- function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
10
- _dotenv.default.config({
11
- path: `.env`
12
- });
13
- _commander.program.description("Deploy an Intuned project to be public").argument("[project-name]", "Name of the project to deploy").option("-w, --workspace-id <id>", "Your Intuned workspace ID").option("-k, --api-key <key>", "Your Intuned API key").action(async (projectName, options) => {
14
- try {
15
- const {
16
- isValid,
17
- errorMessage
18
- } = await (0, _utils.validateIntunedProject)();
19
- if (!isValid) {
20
- const userErrorMesage = `Project to be deployed is not a valid Intuned project: ${errorMessage}, modify and check again`;
21
- throw new Error(userErrorMesage);
22
- }
23
- const _projectName = projectName || (await (0, _utils2.getSettingIntunedJSON)("projectName"));
24
- if (!_projectName) {
25
- throw new Error("Project name is required");
26
- }
27
- const projectNameValidation = (0, _utils.validateProjectName)(_projectName);
28
- if (!projectNameValidation.isValid) {
29
- throw new Error(projectNameValidation.errorMessage);
30
- }
31
- const auth = await (0, _utils2.getAuthCredentials)(options);
32
- const {
33
- deployDone,
34
- projectId,
35
- deployErrorMessage
36
- } = await (0, _utils.deployProject)(_projectName, auth);
37
- if (!deployDone) {
38
- throw new Error(`Project not deployed: ${deployErrorMessage}`);
39
- }
40
- const url = (0, _utils2.getBaseUrl)();
41
- console.log(_chalk.default.green(`\n✅ Project "${_projectName}" deployed successfully!` + `\n\nYou can check your project on the platform: ${_chalk.default.bold(`${url}/projects/${projectId}/details`)}\n`));
42
- } catch (error) {
43
- console.error(_chalk.default.red(`\n${error.message}`));
44
- process.exit(1);
45
- }
46
- });
47
- _commander.program.parse(process.argv);
@@ -1,16 +0,0 @@
1
- import { AuthCredentials, FileSystemTree } from "../../common/cli/types";
2
- export declare function convertProjectToCodeTree(projectPath: string): Promise<FileSystemTree>;
3
- export declare function deployProject(projectName: string, auth: AuthCredentials): Promise<{
4
- deployDone: boolean;
5
- projectId?: string;
6
- deployErrorMessage?: string;
7
- }>;
8
- export declare const validateProjectName: (projectName: string) => {
9
- isValid: boolean;
10
- errorMessage?: string;
11
- };
12
- export declare const validateIntunedProject: () => Promise<{
13
- isValid: boolean;
14
- errorMessage?: string;
15
- }>;
16
- export declare const runBuild: () => Promise<boolean>;
@@ -1,2 +0,0 @@
1
- #!/usr/bin/env node
2
- export {};
@@ -1,22 +0,0 @@
1
- #!/usr/bin/env node
2
- "use strict";
3
-
4
- var _commander = require("commander");
5
- var _chalk = _interopRequireDefault(require("chalk"));
6
- var _dotenv = _interopRequireDefault(require("dotenv"));
7
- var _utils = require("./utils");
8
- function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
9
- _dotenv.default.config({
10
- path: `.env`
11
- });
12
- _commander.program.description("Initialize a new Intuned project from a template").argument("[template-name]", "Name of the template to use").action(async templateName => {
13
- try {
14
- const template = await (0, _utils.selectTemplate)(templateName);
15
- const isTargetDirectoryEmpty = await (0, _utils.checkEmptyDirectory)();
16
- await (0, _utils.scaffoldProject)(template, isTargetDirectoryEmpty);
17
- } catch (error) {
18
- console.error(_chalk.default.red(`\n${error.message}`));
19
- process.exit(1);
20
- }
21
- });
22
- _commander.program.parse(process.argv);
@@ -1,11 +0,0 @@
1
- import { DirectoryNode, FileNode, FileSystemTree } from "../../common/cli/types";
2
- export declare function _isDirectoryNode(node: DirectoryNode | FileNode): node is DirectoryNode;
3
- export declare function _isFileNode(node: DirectoryNode | FileNode): node is FileNode;
4
- export declare function mountFiles(cwd: string, tree: FileSystemTree): Promise<void>;
5
- export declare function checkEmptyDirectory(): Promise<boolean>;
6
- export declare function getAuthCredentials(options: any): {
7
- workspaceId: any;
8
- apiKey: any;
9
- };
10
- export declare function selectTemplate(templateName: any): Promise<any>;
11
- export declare function scaffoldProject(templateId: string, isTargetDirectoryEmpty: boolean): Promise<void>;
@@ -1,181 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports._isDirectoryNode = _isDirectoryNode;
7
- exports._isFileNode = _isFileNode;
8
- exports.checkEmptyDirectory = checkEmptyDirectory;
9
- exports.getAuthCredentials = getAuthCredentials;
10
- exports.mountFiles = mountFiles;
11
- exports.scaffoldProject = scaffoldProject;
12
- exports.selectTemplate = selectTemplate;
13
- var fs = _interopRequireWildcard(require("fs-extra"));
14
- var _types = require("../../common/cli/types");
15
- var _chalk = _interopRequireDefault(require("chalk"));
16
- var _inquirer = _interopRequireDefault(require("inquirer"));
17
- var _path = _interopRequireDefault(require("path"));
18
- var _boxen = _interopRequireDefault(require("boxen"));
19
- var _projectExclusions = _interopRequireDefault(require("../common/projectExclusions"));
20
- var _constants = require("../../common/cli/constants");
21
- var _cliReadme = require("../../common/cli/cliReadme");
22
- var _utils = require("../../common/cli/utils");
23
- function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
24
- 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); }
25
- 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; }
26
- function _isDirectoryNode(node) {
27
- return node.directory !== undefined;
28
- }
29
- function _isFileNode(node) {
30
- return node.file !== undefined;
31
- }
32
- async function mountFiles(cwd, tree) {
33
- for (const name in tree) {
34
- const fullPath = _path.default.join(cwd, name);
35
- const node = tree[name];
36
- if (_isDirectoryNode(node)) {
37
- await fs.ensureDir(fullPath);
38
- await mountFiles(fullPath, node.directory);
39
- } else if (_isFileNode(node)) {
40
- await fs.writeFile(fullPath, node.file.contents);
41
- }
42
- }
43
- }
44
- async function checkEmptyDirectory() {
45
- const currentDir = process.cwd();
46
- try {
47
- const stats = await fs.stat(currentDir);
48
- if (!stats.isDirectory()) {
49
- throw new Error("The current path is not a directory.");
50
- }
51
- const files = await fs.readdir(currentDir);
52
- const significantFiles = files.filter(file => !_projectExclusions.default.includes(file));
53
- return significantFiles.length === 0;
54
- } catch (error) {
55
- if (error.code === "ENOENT") {
56
- throw new Error("The specified directory does not exist.");
57
- }
58
- throw error;
59
- }
60
- }
61
- function getAuthCredentials(options) {
62
- const workspaceId = options.workspaceId || process.env.INTUNED_WORKSPACE_ID;
63
- const apiKey = options.apiKey || process.env.INTUNED_API_KEY;
64
- const missingAuth = [];
65
- if (!workspaceId) {
66
- missingAuth.push({
67
- type: "input",
68
- name: "workspaceId",
69
- message: "Enter your Intuned workspace ID:",
70
- validate: input => input.trim() !== "" ? true : "Workspace ID is required"
71
- });
72
- }
73
- if (!apiKey) {
74
- missingAuth.push({
75
- type: "password",
76
- name: "apiKey",
77
- message: "Enter your Intuned API key:",
78
- mask: "*",
79
- validate: input => input.trim() !== "" ? true : "API key is required"
80
- });
81
- }
82
- if (missingAuth.length) {
83
- throw new Error(`Authentication failed: Missing ${missingAuth.join(" and ")}.\n\n` + `To fix this issue:\n\n` + `1. For workspaceId:\n` + ` - Add it to your intuned.json file under the "workspaceId" property\n` + ` - OR provide via command line: --workspace-id YOUR_WORKSPACE_ID\n` + ` - See how to get your workspaceId: https://docs.intunedhq.com/docs/guides/platform/how-to-get-a-workspace-id\n\n` + `2. For API key:\n` + ` - Include in your .env file INTUNED_API_KEY=your_api_key_here \n` + ` - OR provide via command line: --api-key YOUR_API_KEY\n\n` + `Run commands from the project root directory where intuned.json is located.`);
84
- }
85
- return {
86
- workspaceId,
87
- apiKey
88
- };
89
- }
90
- async function selectTemplate(templateName) {
91
- if (templateName) {
92
- const validTemplate = _types.templateIds.find(t => t === templateName);
93
- if (!validTemplate) {
94
- console.log(_chalk.default.yellow(`\n⚠️ Template "${templateName}" not found.`));
95
- } else {
96
- return templateName;
97
- }
98
- }
99
- console.log(_chalk.default.yellow("\n📋 Select a Template"));
100
- const {
101
- template
102
- } = await _inquirer.default.prompt([{
103
- type: "list",
104
- name: "template",
105
- message: "Which template would you like to use?",
106
- choices: _types.templateIds,
107
- loop: false
108
- }]);
109
- return template;
110
- }
111
- async function scaffoldProject(templateId, isTargetDirectoryEmpty) {
112
- if (!isTargetDirectoryEmpty) {
113
- const {
114
- confirm
115
- } = await _inquirer.default.prompt([{
116
- type: "confirm",
117
- name: "confirm",
118
- message: `The current directory is not empty. Do you want to proceed and override files?`,
119
- default: false,
120
- choices: [{
121
- name: "Yes,",
122
- value: true
123
- }, {
124
- name: "No",
125
- value: false
126
- }]
127
- }]);
128
- if (!confirm) {
129
- throw new Error("Project initialization cancelled");
130
- }
131
- }
132
- const cwd = process.cwd();
133
- console.log(_chalk.default.cyan(`\n🚀 Initializing ${_chalk.default.bold(templateId)} project...\n`));
134
- console.log(_chalk.default.cyan("📦 Fetching template..."));
135
- const template = await fetchProjectTemplate(templateId);
136
- console.log(_chalk.default.green(`✓ Template "${templateId}" fetched successfully`));
137
- console.log(_chalk.default.cyan("🔨 Creating project files..."));
138
- const codeTree = template;
139
- await prepareCLITemplate(codeTree);
140
- await mountFiles(cwd, codeTree);
141
- console.log(_chalk.default.green("✓ Project files created"));
142
- console.log((0, _boxen.default)(_chalk.default.green(`✅ Project initialized successfully`) + `\n\n${_chalk.default.cyan("Project details:")}` + `\n• Template: ${_chalk.default.bold(templateId)}` + `\n• Directory: ${_chalk.default.bold(process.cwd())}` + `\n\n${_chalk.default.cyan("Next steps:")}` + `\n1. ${_chalk.default.bold("cd")} into your project directory (if not already there)` + `\n2. Run ${_chalk.default.bold("npm/yarn install")} to install dependencies` + `\n3. Develop, test and run your automation APIs`, {
143
- padding: 1,
144
- margin: 1,
145
- borderStyle: "round",
146
- borderColor: "green"
147
- }));
148
- }
149
- async function fetchProjectTemplate(templateId) {
150
- const baseUrl = (0, _utils.getBaseUrl)();
151
- const url = `${baseUrl}/api/templates/${templateId}`;
152
- const response = await fetch(url);
153
- if (!response.ok) {
154
- throw new Error(`Error fetching template: ${response.statusText} (${response.status})`);
155
- }
156
- const data = await response.json();
157
- if (!data) {
158
- throw new Error("Template not found");
159
- }
160
- return data.template;
161
- }
162
- async function prepareCLITemplate(codeTree) {
163
- codeTree["parameters"] = {
164
- directory: {}
165
- };
166
- codeTree["tsconfig.json"] = {
167
- file: {
168
- contents: JSON.stringify(_constants.tsConfigCli, null, 2)
169
- }
170
- };
171
- if (_isFileNode(codeTree["package.json"]) && codeTree["package.json"].file) {
172
- const packageJson = JSON.parse(codeTree["package.json"].file.contents);
173
- packageJson.scripts = _constants.userCLIScripts;
174
- codeTree["package.json"].file.contents = JSON.stringify(packageJson, null, 2);
175
- }
176
- codeTree["README.md"] = {
177
- file: {
178
- contents: _cliReadme.cliReadme
179
- }
180
- };
181
- }
@@ -1,2 +0,0 @@
1
- #!/usr/bin/env node
2
- export {};
@@ -1,57 +0,0 @@
1
- #!/usr/bin/env node
2
- "use strict";
3
-
4
- var _commander = require("commander");
5
- var _chalk = _interopRequireDefault(require("chalk"));
6
- var _nanoid = require("nanoid");
7
- var _dotenv = _interopRequireDefault(require("dotenv"));
8
- var _utils = require("./utils");
9
- var _enums = require("../../runtime/enums");
10
- var _asyncLocalStorage = require("../../common/asyncLocalStorage");
11
- var _utils2 = require("../cli-auth-sessions/utils");
12
- function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
13
- _dotenv.default.config({
14
- path: `.env`
15
- });
16
- _commander.program.name("intuned-run").description("Run an Intuned API with parameters").argument("<api-name>", "Name of the API to run").option("-i, --parameters-file <file>", "JSON file containing API parameters").option("-a, --auth-session <session>", "Name of the auth session instance to use").option("-s, --store-results", "Store the results of the running API in a dedicated folder").action(async (apiName, options) => {
17
- try {
18
- if (!apiName) {
19
- throw new Error("API name is required, please provide it");
20
- }
21
- const _isAuthEnabled = await (0, _utils2.isAuthEnabled)();
22
- if (!_isAuthEnabled && options.authSession) {
23
- throw new Error("Auth session is not enabled, enable it in Intuned.json to be able to use it");
24
- }
25
- if (_isAuthEnabled && !options.authSession) {
26
- throw new Error("Auth session is enabled but no auth session provided, please provide it");
27
- }
28
- const inputData = await (0, _utils.loadParameters)(options.parametersFile);
29
- const runId = (0, _nanoid.nanoid)();
30
- const {
31
- result,
32
- payloadToAppend
33
- } = await (0, _asyncLocalStorage.runWithContext)({
34
- runEnvironment: _enums.RunEnvironment.IDE,
35
- extendedPayloads: [],
36
- runId
37
- }, () => (0, _utils.runApiViaCLI)(apiName, inputData, {
38
- authSession: options.authSession
39
- }));
40
- if (!result) {
41
- console.log(_chalk.default.yellow("No result returned from the API"));
42
- return;
43
- }
44
- if (!options.storeResults) {
45
- console.log(_chalk.default.green(`✓ API executed successfully`));
46
- console.log(_chalk.default.green("Result:"));
47
- console.log(_chalk.default.white(JSON.stringify(result, null, 2)));
48
- return;
49
- }
50
- await (0, _utils.writeResultToFile)(runId, result, payloadToAppend);
51
- } catch (error) {
52
- console.error(_chalk.default.red(`\nError: ${error.message}`));
53
- } finally {
54
- process.exit(0);
55
- }
56
- });
57
- _commander.program.parse(process.argv);
@@ -1,9 +0,0 @@
1
- import { Payload } from "../../runtime/export";
2
- export declare function loadParameters(parametersFile: string): Promise<object | null>;
3
- export declare function writeResultToFile(runId: string, result: any, payloadToAppend?: Payload[]): Promise<void>;
4
- export declare function runApiViaCLI(apiName: string, inputData: object | null | undefined, options?: {
5
- authSession?: string;
6
- }): Promise<{
7
- result: any;
8
- payloadToAppend: Payload[] | undefined;
9
- }>;