@intuned/runtime-dev 1.0.4-stuck.1 → 1.0.6-cli-auth.0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (95) hide show
  1. package/InterfaceTemplate/utils.ts +53 -31
  2. package/bin/cli-build +3 -0
  3. package/bin/create-auth-session +3 -0
  4. package/bin/deploy +3 -0
  5. package/bin/init +3 -0
  6. package/bin/run-api +3 -0
  7. package/dist/commands/api/run.js +2 -2
  8. package/dist/commands/auth-sessions/load.js +1 -1
  9. package/dist/commands/auth-sessions/run-check.js +2 -2
  10. package/dist/commands/auth-sessions/run-create.js +2 -2
  11. package/dist/commands/browser/save-state.js +1 -1
  12. package/dist/commands/browser/start-browser.js +1 -1
  13. package/dist/commands/build.js +4 -4
  14. package/dist/commands/cli-auth-sessions/check.d.ts +0 -0
  15. package/dist/commands/cli-auth-sessions/check.js +1 -0
  16. package/dist/commands/cli-auth-sessions/create.d.ts +2 -0
  17. package/dist/commands/cli-auth-sessions/create.js +28 -0
  18. package/dist/commands/cli-auth-sessions/utils.d.ts +4 -0
  19. package/dist/commands/cli-auth-sessions/utils.js +55 -0
  20. package/dist/commands/cli-build/cli-build.d.ts +2 -0
  21. package/dist/commands/cli-build/cli-build.js +20 -0
  22. package/dist/commands/common/browserUtils.d.ts +1 -1
  23. package/dist/commands/common/browserUtils.js +3 -3
  24. package/dist/commands/common/getFirstLineNumber.test.js +2 -2
  25. package/dist/commands/common/projectExclusions.d.ts +2 -0
  26. package/dist/commands/common/projectExclusions.js +8 -0
  27. package/dist/commands/common/tsNodeImport.d.ts +2 -1
  28. package/dist/commands/common/tsNodeImport.js +20 -6
  29. package/dist/commands/common/utils/fileUtils.js +2 -2
  30. package/dist/commands/common/utils/settings.js +1 -1
  31. package/dist/commands/common/utils/template.d.ts +1 -1
  32. package/dist/commands/common/utils/template.js +1 -1
  33. package/dist/commands/deploy/deploy.d.ts +2 -0
  34. package/dist/commands/deploy/deploy.js +47 -0
  35. package/dist/commands/deploy/utils.d.ts +16 -0
  36. package/dist/commands/deploy/utils.js +350 -0
  37. package/dist/commands/init/init.d.ts +2 -0
  38. package/dist/commands/init/init.js +22 -0
  39. package/dist/commands/init/utils.d.ts +9 -0
  40. package/dist/commands/init/utils.js +179 -0
  41. package/dist/commands/interface/run.js +141 -94
  42. package/dist/commands/run-api-cli/run-api.d.ts +2 -0
  43. package/dist/commands/run-api-cli/run-api.js +48 -0
  44. package/dist/commands/run-api-cli/utils.d.ts +10 -0
  45. package/dist/commands/run-api-cli/utils.js +98 -0
  46. package/dist/commands/ts-check.js +2 -2
  47. package/dist/common/Logger/Logger/index.js +1 -1
  48. package/dist/common/Logger/index.js +1 -1
  49. package/dist/common/asyncLocalStorage/index.d.ts +1 -1
  50. package/dist/common/asyncLocalStorage/index.js +2 -2
  51. package/dist/common/cli/cliReadme.d.ts +1 -0
  52. package/dist/common/cli/cliReadme.js +69 -0
  53. package/dist/common/cli/constants.d.ts +24 -0
  54. package/dist/common/cli/constants.js +30 -0
  55. package/dist/common/cli/types.d.ts +52 -0
  56. package/dist/common/cli/types.js +7 -0
  57. package/dist/common/cli/utils.d.ts +6 -0
  58. package/dist/common/cli/utils.js +35 -0
  59. package/dist/common/contextStorageStateHelpers.d.ts +20 -13
  60. package/dist/common/contextStorageStateHelpers.js +69 -42
  61. package/dist/common/getPlaywrightConstructs.d.ts +1 -1
  62. package/dist/common/getPlaywrightConstructs.js +5 -5
  63. package/dist/common/jwtTokenManager.js +2 -2
  64. package/dist/common/runApi/errors.d.ts +0 -11
  65. package/dist/common/runApi/errors.js +2 -41
  66. package/dist/common/runApi/index.d.ts +2 -1
  67. package/dist/common/runApi/index.js +11 -4
  68. package/dist/common/runApi/types.d.ts +82 -76
  69. package/dist/common/runApi/types.js +1 -1
  70. package/dist/common/settingsSchema.js +1 -1
  71. package/dist/common/telemetry.js +1 -1
  72. package/package.json +14 -6
  73. package/WebTemplate/accessKeyHelpers.ts +0 -28
  74. package/WebTemplate/api.ts +0 -139
  75. package/WebTemplate/app.ts +0 -18
  76. package/WebTemplate/controllers/async.ts +0 -142
  77. package/WebTemplate/controllers/authSessions/check.ts +0 -61
  78. package/WebTemplate/controllers/authSessions/create.ts +0 -101
  79. package/WebTemplate/controllers/authSessions/index.ts +0 -41
  80. package/WebTemplate/controllers/authSessions/killOperation.ts +0 -35
  81. package/WebTemplate/controllers/authSessions/resumeOperation.ts +0 -56
  82. package/WebTemplate/controllers/authSessions/store.ts +0 -19
  83. package/WebTemplate/controllers/controllers.ts +0 -73
  84. package/WebTemplate/controllers/runApi/helpers.ts +0 -128
  85. package/WebTemplate/controllers/runApi/index.ts +0 -68
  86. package/WebTemplate/controllers/runApi/types.ts +0 -13
  87. package/WebTemplate/controllers/traces.ts +0 -151
  88. package/WebTemplate/features.ts +0 -8
  89. package/WebTemplate/headers.ts +0 -6
  90. package/WebTemplate/index.playwright.ts +0 -47
  91. package/WebTemplate/index.vanilla.ts +0 -26
  92. package/WebTemplate/jobs.ts +0 -356
  93. package/WebTemplate/shutdown.ts +0 -64
  94. package/WebTemplate/utils.ts +0 -257
  95. package/WebTemplate.zip +0 -0
@@ -15,10 +15,10 @@ var _unixSocket = require("../common/utils/unixSocket");
15
15
  var _promises = require("timers/promises");
16
16
  var _jwtTokenManager = require("../../common/jwtTokenManager");
17
17
  var _formatZodError = require("../../common/formatZodError");
18
- var _stream = require("stream");
18
+ var _neverthrow = require("neverthrow");
19
+ function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
19
20
  function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
20
- function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
21
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
21
+ 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; }
22
22
  const startRunApiSchema = _zod.default.object({
23
23
  type: _zod.default.literal("start"),
24
24
  parameters: _runApi.runApiParametersSchema.extend({
@@ -48,7 +48,11 @@ const tokenUpdateSchema = _zod.default.object({
48
48
  functionsToken: _zod.default.string()
49
49
  })
50
50
  });
51
- const inputSchema = _zod.default.union([startRunApiSchema, nextRunApiSchema, abortRunApiSchema, tokenUpdateSchema]);
51
+ const pingSchema = _zod.default.object({
52
+ type: _zod.default.literal("ping"),
53
+ parameters: _zod.default.object({}).optional()
54
+ });
55
+ const inputSchema = _zod.default.union([startRunApiSchema, nextRunApiSchema, abortRunApiSchema, tokenUpdateSchema, pingSchema]);
52
56
  _dotenv.default.config({
53
57
  path: `.env`
54
58
  });
@@ -61,116 +65,143 @@ function runAutomationCLI(importFunction) {
61
65
  let generator = null;
62
66
  const abortController = new AbortController();
63
67
  client.on("error", err => {
64
- var _generator2;
65
- void ((_generator2 = generator) === null || _generator2 === void 0 ? void 0 : _generator2.throw(err).catch(() => undefined));
68
+ var _generator;
69
+ void ((_generator = generator) === null || _generator === void 0 ? void 0 : _generator.throw(err).catch(() => undefined));
66
70
  });
67
- process.on("SIGINT", () => {
68
- var _generator3;
69
- void ((_generator3 = generator) === null || _generator3 === void 0 ? void 0 : _generator3.throw(new Error("Interrupted")).catch(() => undefined));
70
- client.end();
71
- process.exit(1);
72
- });
73
- process.on("SIGTERM", () => {
74
- var _generator4;
75
- void ((_generator4 = generator) === null || _generator4 === void 0 ? void 0 : _generator4.throw(new Error("Interrupted")).catch(() => undefined));
71
+ const interruptSignalHandler = async () => {
72
+ var _generator2;
73
+ abortController.abort();
74
+ await (0, _promises.setTimeout)(60_000);
75
+ void ((_generator2 = generator) === null || _generator2 === void 0 ? void 0 : _generator2.throw(new Error("Interrupted")).catch(() => undefined));
76
76
  client.end();
77
77
  process.exit(1);
78
- });
78
+ };
79
+ process.on("SIGINT", interruptSignalHandler);
80
+ process.on("SIGTERM", interruptSignalHandler);
79
81
  const jsonUnixSocket = new _unixSocket.JSONUnixSocket(client);
80
- async function runGeneratorAndSendResult(next) {
81
- const _generator = generator;
82
- if (_generator == null) return {
83
- done: true
84
- };
85
- const result = await (0, _asyncLocalStorage.runWithContext)(context, () => _generator.next(next));
86
- if (result.done) {
87
- const resultToSend = result.value.isOk() ? result.value.value : result.value.error.json;
88
- const success = result.value.isOk();
89
- jsonUnixSocket.sendJSON({
90
- type: "done",
91
- result: resultToSend,
92
- success
82
+ const messagesGenerator = jsonUnixSocket.receiveJSON();
83
+ async function receiveMessages() {
84
+ const data = await messagesGenerator.next();
85
+ if (data.done) {
86
+ return;
87
+ }
88
+ const inputParseResult = inputSchema.safeParse(data.value);
89
+ if (!inputParseResult.success) {
90
+ console.error("Validation error:", (0, _formatZodError.formatZodError)(inputParseResult.error));
91
+ return {
92
+ type: "error",
93
+ error: new _runApi.InternalInvalidInputError("Invalid input", (0, _formatZodError.formatZodError)(inputParseResult.error))
94
+ };
95
+ }
96
+ const input = inputParseResult.data;
97
+ return input;
98
+ }
99
+ let resultPromise = null;
100
+ async function handleMessage(message) {
101
+ if (message.type === "abort") {
102
+ abortController.abort();
103
+ return;
104
+ }
105
+ if (message.type === "tokenUpdate") {
106
+ _jwtTokenManager.backendFunctionsTokenManager.token = message.parameters.functionsToken;
107
+ return;
108
+ }
109
+ if (message.type === "start") {
110
+ generator = (0, _runApi.runApiGenerator)({
111
+ ...message.parameters,
112
+ abortSignal: abortController.signal,
113
+ importFunction: importFunction ?? _defaultImport
114
+ });
115
+ context = {
116
+ extendedPayloads: [],
117
+ runEnvironment: message.parameters.runOptions.environment === "standalone" ? _enums.RunEnvironment.DEPLOYED : _enums.RunEnvironment.IDE,
118
+ timeoutInfo: {
119
+ extendTimeoutCallback: async () => {
120
+ if (Date.now() - timeoutTimestamp < throttleTime) return;
121
+ timeoutTimestamp = Date.now();
122
+ jsonUnixSocket.sendJSON({
123
+ type: "extend"
124
+ });
125
+ }
126
+ },
127
+ ...(message.parameters.context ?? {}),
128
+ proxy: getProxyUrlFromRunOptions(message.parameters.runOptions)
129
+ };
130
+ _jwtTokenManager.backendFunctionsTokenManager.token = message.parameters.functionsToken;
131
+ resultPromise = (0, _asyncLocalStorage.runWithContext)(context, async () => {
132
+ return await generator.next();
133
+ });
134
+ return;
135
+ }
136
+ if (message.type === "next") {
137
+ if (!generator) {
138
+ throw new Error("generator not started");
139
+ }
140
+ resultPromise = (0, _asyncLocalStorage.runWithContext)(context, async () => {
141
+ return await generator.next(message.parameters.value);
93
142
  });
94
- } else {
143
+ return;
144
+ }
145
+ }
146
+ async function handleResult(generatorResult) {
147
+ if (!generatorResult.done) {
95
148
  jsonUnixSocket.sendJSON({
96
149
  type: "yield",
97
- result: result.value
150
+ result: generatorResult.value
98
151
  });
152
+ return false;
99
153
  }
100
- return {
101
- done: result.done ?? false
102
- };
154
+ const result = generatorResult.value;
155
+ const success = result.isOk();
156
+ const resultToSend = success ? result.value : result.error.json;
157
+ jsonUnixSocket.sendJSON({
158
+ type: "done",
159
+ result: resultToSend,
160
+ success
161
+ });
162
+ return true;
103
163
  }
104
- const stream = new _stream.PassThrough({
105
- objectMode: true
106
- });
107
- async function messagesLoop() {
108
- for await (const data of jsonUnixSocket.receiveJSON()) {
109
- const inputParseResult = inputSchema.safeParse(data);
110
- if (!inputParseResult.success) {
111
- console.error("Validation error:", (0, _formatZodError.formatZodError)(inputParseResult.error));
164
+ let receiveMessagesPromise = receiveMessages();
165
+ while (true) {
166
+ const messageOrResult = await Promise.race([receiveMessagesPromise.then(message => ({
167
+ type: "message",
168
+ message
169
+ })), ...(resultPromise ? [resultPromise.then(result => ({
170
+ type: "result",
171
+ result
172
+ }))] : [])]);
173
+ if (messageOrResult.type === "message") {
174
+ const {
175
+ message
176
+ } = messageOrResult;
177
+ if (message === undefined) {
178
+ break;
179
+ }
180
+ if (message.type === "error") {
112
181
  jsonUnixSocket.sendJSON({
113
182
  type: "done",
114
- result: new _runApi.InternalInvalidInputError("Invalid input", (0, _formatZodError.formatZodError)(inputParseResult.error)).json,
183
+ result: message.error.json,
115
184
  success: false
116
185
  });
117
186
  break;
118
187
  }
119
- const input = inputParseResult.data;
120
- if (input.type === "abort") {
121
- abortController.abort();
122
- break;
123
- }
124
- if (input.type === "tokenUpdate") {
125
- _jwtTokenManager.backendFunctionsTokenManager.token = input.parameters.functionsToken;
126
- continue;
127
- }
128
- if (input.type === "start") {
129
- _jwtTokenManager.backendFunctionsTokenManager.token = input.parameters.functionsToken;
130
- generator = (0, _runApi.runApiGenerator)({
131
- ...input.parameters,
132
- abortSignal: abortController.signal,
133
- importFunction
134
- });
135
- context = {
136
- extendedPayloads: [],
137
- runEnvironment: input.parameters.runOptions.environment === "standalone" ? _enums.RunEnvironment.DEPLOYED : _enums.RunEnvironment.IDE,
138
- timeoutInfo: {
139
- extendTimeoutCallback: async () => {
140
- if (Date.now() - timeoutTimestamp < throttleTime) return;
141
- timeoutTimestamp = Date.now();
142
- jsonUnixSocket.sendJSON({
143
- type: "extend"
144
- });
145
- }
146
- },
147
- ...(input.parameters.context ?? {}),
148
- proxy: getProxyUrlFromRunOptions(input.parameters.runOptions)
149
- };
150
- stream.write({});
151
- continue;
152
- }
153
- if (input.type === "next") {
154
- if (!generator) {
155
- throw new Error("generator not started");
156
- }
157
- stream.write({
158
- value: input.parameters.value
188
+ if (message.type === "ping") {
189
+ jsonUnixSocket.sendJSON({
190
+ type: "pong"
159
191
  });
160
- continue;
192
+ break;
161
193
  }
194
+ await handleMessage(message);
195
+ receiveMessagesPromise = receiveMessages();
196
+ continue;
162
197
  }
163
- stream.end();
164
- client.end();
165
- }
166
- void messagesLoop();
167
- for await (const {
168
- value
169
- } of stream) {
170
198
  const {
171
- done
172
- } = await runGeneratorAndSendResult(value);
173
- if (done) break;
199
+ result
200
+ } = messageOrResult;
201
+ const done = await handleResult(result);
202
+ if (done) {
203
+ break;
204
+ }
174
205
  }
175
206
  if (!client.closed) {
176
207
  client.end();
@@ -189,6 +220,22 @@ function getProxyUrlFromRunOptions(runOptions) {
189
220
  url.password = proxy.password;
190
221
  return url.toString();
191
222
  }
223
+ const _defaultImport = async path => {
224
+ try {
225
+ const imported = await (specifier => new Promise(r => r(specifier)).then(s => _interopRequireWildcard(require(s))))(`../../../${path}.ts`);
226
+ return (0, _neverthrow.ok)(imported);
227
+ } catch (e) {
228
+ if ("code" in e && e.code === "MODULE_NOT_FOUND") {
229
+ return (0, _neverthrow.err)({
230
+ type: "not_found"
231
+ });
232
+ }
233
+ return (0, _neverthrow.err)({
234
+ type: "other",
235
+ error: e
236
+ });
237
+ }
238
+ };
192
239
  if (require.main === module) {
193
240
  runAutomationCLI();
194
241
  }
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env node
2
+ export {};
@@ -0,0 +1,48 @@
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
+ function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
12
+ _dotenv.default.config({
13
+ path: `.env`
14
+ });
15
+ _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("-s, --store-results", "Store the results of the running API in a dedicated folder").action(async (apiName, options) => {
16
+ try {
17
+ if (!apiName) {
18
+ throw new Error("API name is required, please provide it");
19
+ }
20
+ const inputData = await (0, _utils.loadParameters)(options.parametersFile);
21
+ const runId = (0, _nanoid.nanoid)();
22
+ const {
23
+ result,
24
+ payloadToAppend
25
+ } = await (0, _asyncLocalStorage.runWithContext)({
26
+ runEnvironment: _enums.RunEnvironment.IDE,
27
+ extendedPayloads: [],
28
+ runId
29
+ }, () => (0, _utils.runApiViaCLI)(apiName, inputData));
30
+ if (!result) {
31
+ console.log(_chalk.default.yellow("No result returned from the API"));
32
+ return;
33
+ }
34
+ if (!options.storeResults) {
35
+ console.log(_chalk.default.green(`✓ API executed successfully`));
36
+ console.log(_chalk.default.green("Result:"));
37
+ console.log(_chalk.default.white(JSON.stringify(result, null, 2)));
38
+ return;
39
+ }
40
+ await (0, _utils.writeResultToFile)(runId, result, payloadToAppend);
41
+ } catch (error) {
42
+ console.error(_chalk.default.red(`\nError: ${error.message}`));
43
+ process.exit(1);
44
+ } finally {
45
+ process.exit(0);
46
+ }
47
+ });
48
+ _commander.program.parse(process.argv);
@@ -0,0 +1,10 @@
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
+ retrieveSession?: boolean;
6
+ }): Promise<{
7
+ result: any;
8
+ payloadToAppend: Payload[] | undefined;
9
+ session: import("../../common/contextStorageStateHelpers").StorageState | undefined;
10
+ }>;
@@ -0,0 +1,98 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.loadParameters = loadParameters;
7
+ exports.runApiViaCLI = runApiViaCLI;
8
+ exports.writeResultToFile = writeResultToFile;
9
+ var _path = _interopRequireDefault(require("path"));
10
+ var fs = _interopRequireWildcard(require("fs-extra"));
11
+ var _Logger = require("../../common/Logger");
12
+ var _chalk = _interopRequireDefault(require("chalk"));
13
+ var _runApi = require("../../common/runApi");
14
+ var _tsNodeImport = require("../common/tsNodeImport");
15
+ 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); }
16
+ 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; }
17
+ function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
18
+ async function loadParameters(parametersFile) {
19
+ if (!parametersFile) {
20
+ return {};
21
+ }
22
+ try {
23
+ const filePath = _path.default.join(process.cwd(), parametersFile);
24
+ await fs.access(filePath);
25
+ let inputData = null;
26
+ if (parametersFile) {
27
+ inputData = await fs.readJSON(filePath);
28
+ } else {
29
+ inputData = {};
30
+ }
31
+ return inputData;
32
+ } catch (error) {
33
+ if (error.code === "ENOENT") {
34
+ throw new Error(`Parameters file not found: ${parametersFile}`);
35
+ } else if (error instanceof SyntaxError) {
36
+ throw new Error(`Invalid JSON in parameters file: ${error.message}`);
37
+ }
38
+ throw new Error(`Error reading parameters file: ${error.message}`);
39
+ }
40
+ }
41
+ async function writeResultToFile(runId, result, payloadToAppend) {
42
+ const outputDir = _path.default.join(process.cwd(), "output", runId);
43
+ const resultsPath = _path.default.join(outputDir, "results.json");
44
+ const extendedPayloadsPath = _path.default.join(outputDir, "extendedPayloads.json");
45
+ await fs.ensureDir(outputDir);
46
+ try {
47
+ await fs.writeJSON(resultsPath, result, {
48
+ spaces: 2
49
+ });
50
+ if (payloadToAppend && payloadToAppend.length > 0) {
51
+ await fs.writeJSON(extendedPayloadsPath, payloadToAppend, {
52
+ spaces: 2
53
+ });
54
+ _Logger.logger.info(_chalk.default.underline.green.white(`Payloads to append saved into (${extendedPayloadsPath})`));
55
+ }
56
+ console.log(_chalk.default.underline.green.white(`✓ API executed successfully. Results stored in ${outputDir}`));
57
+ console.log(_chalk.default.blue(`Run ID: ${runId}`));
58
+ } catch (error) {
59
+ _Logger.logger.error(`Failed to write result to file: ${error.message}`);
60
+ }
61
+ }
62
+ async function runApiViaCLI(apiName, inputData, options) {
63
+ const runApiResult = await (0, _runApi.runApi)({
64
+ automationFunction: {
65
+ name: `api/${apiName}`,
66
+ params: inputData
67
+ },
68
+ runOptions: {
69
+ headless: false,
70
+ environment: "standalone"
71
+ },
72
+ retrieveSession: (options === null || options === void 0 ? void 0 : options.retrieveSession) ?? false,
73
+ importFunction: _tsNodeImport.tsNodeImport
74
+ });
75
+ if (runApiResult.isErr()) {
76
+ if (runApiResult.error instanceof _runApi.AutomationError) {
77
+ throw runApiResult.error.error;
78
+ }
79
+ console.error(runApiResult.error);
80
+ throw new Error("An error occurred while running the API");
81
+ }
82
+ const {
83
+ result,
84
+ extendedPayloads: payloadToAppend,
85
+ ...rest
86
+ } = runApiResult.value;
87
+ const session = "session" in rest ? rest.session : undefined;
88
+ const hasPayloadToAppend = payloadToAppend && payloadToAppend.length > 0;
89
+ if (hasPayloadToAppend) {
90
+ _Logger.logger.info("payload to append:", payloadToAppend);
91
+ _Logger.logger.info("This will only take an effect if this API run was part of a job.");
92
+ }
93
+ return {
94
+ result,
95
+ payloadToAppend,
96
+ session
97
+ };
98
+ }
@@ -7,8 +7,8 @@ var fs = _interopRequireWildcard(require("fs-extra"));
7
7
  var path = _interopRequireWildcard(require("path"));
8
8
  var _template = require("./common/utils/template");
9
9
  function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
10
- function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
11
- _commander.program.description("Check TypeScript types in the project").option("-t, --template <type>", "template to use", "WebTemplate").allowUnknownOption().action(async ({
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; }
11
+ _commander.program.description("Check TypeScript types in the project").option("-t, --template <type>", "template to use", "InterfaceTemplate").allowUnknownOption().action(async ({
12
12
  template
13
13
  }) => {
14
14
  await (0, _template.moveTemplateFiles)(template);
@@ -6,7 +6,7 @@ Object.defineProperty(exports, "__esModule", {
6
6
  exports.logger = void 0;
7
7
  var _nodeUtil = require("node:util");
8
8
  var _chalk = _interopRequireDefault(require("chalk"));
9
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
9
+ function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
10
10
  const format = _nodeUtil.formatWithOptions.bind(undefined, {
11
11
  colors: true
12
12
  });
@@ -6,7 +6,7 @@ Object.defineProperty(exports, "__esModule", {
6
6
  exports.logger = void 0;
7
7
  var _nodeUtil = require("node:util");
8
8
  var _chalk = _interopRequireDefault(require("chalk"));
9
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
9
+ function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
10
10
  const format = _nodeUtil.formatWithOptions.bind(undefined, {
11
11
  colors: true
12
12
  });
@@ -1,5 +1,5 @@
1
1
  /// <reference types="node" />
2
- import { AsyncLocalStorage } from "async_hooks";
2
+ import { AsyncLocalStorage } from "node:async_hooks";
3
3
  import { Payload, RunInfo } from "../../runtime/export";
4
4
  export declare const asyncLocalStorage: AsyncLocalStorage<InternalRunInfo>;
5
5
  export declare function runWithContext<R, TArgs extends any[]>(contextData: InternalRunInfo, callback: (...args: TArgs) => R, ...args: TArgs): R;
@@ -6,8 +6,8 @@ Object.defineProperty(exports, "__esModule", {
6
6
  exports.asyncLocalStorage = void 0;
7
7
  exports.getExecutionContext = getExecutionContext;
8
8
  exports.runWithContext = runWithContext;
9
- var _async_hooks = require("async_hooks");
10
- const asyncLocalStorage = exports.asyncLocalStorage = new _async_hooks.AsyncLocalStorage();
9
+ var _nodeAsync_hooks = require("node:async_hooks");
10
+ const asyncLocalStorage = exports.asyncLocalStorage = new _nodeAsync_hooks.AsyncLocalStorage();
11
11
  function runWithContext(contextData, callback, ...args) {
12
12
  return asyncLocalStorage.run(contextData, callback, ...args);
13
13
  }
@@ -0,0 +1 @@
1
+ export declare const cliReadme = "# Intuned CLI\n## Introduction\nThe Intuned CLI exposes a variaty of commands to develop your Intuned projects locally\n\n## Development Commands\n\n### Initialize a Project\n`npx -p @intuned/runtime init`\n\n### Run an API\n`yarn run-api <api-name>`\nor\n`npm run run-api <api-name>`\n\nOptions:\n- `-i, --parameters-file file-path`: JSON file containing API parameters\n- `-s, --store-results`: Store the results in `./output/[runId]/results.json` and `./output/[runId]/extendedPayloads.json`\n\n### Build a Project\n`yarn cli-build`\n\n### Deploy a Project\n`yarn deploy <project-name>`\nor\n`npm run deploy <project-name>`\n\n- `project-name`: Optional name that overrides the one in intuned.json\n- Options:\n - `--workspace-id`: Overrides the workspace ID in intuned.json\n - `--api-key`: Overrides the API key from environment variables\n\n## Configuration\n\n### Environment Variables and Settings\n- `workspaceId`: Your Intuned workspace ID ([How to get your workspaceId](https://docs.intunedhq.com/docs/guides/platform/how-to-get-a-workspace-id))\n - Set in `intuned.json` file under the `workspaceId` property\n - Or provide via CLI with `--workspace-id` flag during deployment\n \n- `projectName`: The name of your Intuned project\n - Set in `intuned.json` file under the `projectName` property\n - Or override via command line when deploying with `yarn deploy my-project-name` or `npm run deploy my-project-name`\n \n- `INTUNED_API_KEY`: Your Intuned API key\n - Set as an environment variable: `export INTUNED_API_KEY=your_api_key_here`\n - Or include in your .env file for development\n - Or provide via CLI with `--api-key` flag during deployment\n\n## Project Structure\n\n### Generated Artifacts\n- `./intuned.json`: Project configuration file\n- `./api`: Folder containing API implementation files\n- `./parameters`: Folder for API parameters injection\n- `./output`: Folder containing generated output files\n\n### Notes\n- You can use either `yarn` or `npm run` to execute commands\n- All commands must be run from the project root directory\n- Verify you're in the correct location by confirming the presence of package.json and intuned.json\n- Running commands from subdirectories may result in errors\n- You can manage your deployed projects through the Intuned platform\n- WARNING: \u26A0\uFE0F Changes to TS Config may break some Intuned functionalities\n";
@@ -0,0 +1,69 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.cliReadme = void 0;
7
+ const cliReadme = exports.cliReadme = `# Intuned CLI
8
+ ## Introduction
9
+ The Intuned CLI exposes a variaty of commands to develop your Intuned projects locally
10
+
11
+ ## Development Commands
12
+
13
+ ### Initialize a Project
14
+ \`npx -p @intuned/runtime init\`
15
+
16
+ ### Run an API
17
+ \`yarn run-api <api-name>\`
18
+ or
19
+ \`npm run run-api <api-name>\`
20
+
21
+ Options:
22
+ - \`-i, --parameters-file file-path\`: JSON file containing API parameters
23
+ - \`-s, --store-results\`: Store the results in \`./output/[runId]/results.json\` and \`./output/[runId]/extendedPayloads.json\`
24
+
25
+ ### Build a Project
26
+ \`yarn cli-build\`
27
+
28
+ ### Deploy a Project
29
+ \`yarn deploy <project-name>\`
30
+ or
31
+ \`npm run deploy <project-name>\`
32
+
33
+ - \`project-name\`: Optional name that overrides the one in intuned.json
34
+ - Options:
35
+ - \`--workspace-id\`: Overrides the workspace ID in intuned.json
36
+ - \`--api-key\`: Overrides the API key from environment variables
37
+
38
+ ## Configuration
39
+
40
+ ### Environment Variables and Settings
41
+ - \`workspaceId\`: Your Intuned workspace ID ([How to get your workspaceId](https://docs.intunedhq.com/docs/guides/platform/how-to-get-a-workspace-id))
42
+ - Set in \`intuned.json\` file under the \`workspaceId\` property
43
+ - Or provide via CLI with \`--workspace-id\` flag during deployment
44
+
45
+ - \`projectName\`: The name of your Intuned project
46
+ - Set in \`intuned.json\` file under the \`projectName\` property
47
+ - Or override via command line when deploying with \`yarn deploy my-project-name\` or \`npm run deploy my-project-name\`
48
+
49
+ - \`INTUNED_API_KEY\`: Your Intuned API key
50
+ - Set as an environment variable: \`export INTUNED_API_KEY=your_api_key_here\`
51
+ - Or include in your .env file for development
52
+ - Or provide via CLI with \`--api-key\` flag during deployment
53
+
54
+ ## Project Structure
55
+
56
+ ### Generated Artifacts
57
+ - \`./intuned.json\`: Project configuration file
58
+ - \`./api\`: Folder containing API implementation files
59
+ - \`./parameters\`: Folder for API parameters injection
60
+ - \`./output\`: Folder containing generated output files
61
+
62
+ ### Notes
63
+ - You can use either \`yarn\` or \`npm run\` to execute commands
64
+ - All commands must be run from the project root directory
65
+ - Verify you're in the correct location by confirming the presence of package.json and intuned.json
66
+ - Running commands from subdirectories may result in errors
67
+ - You can manage your deployed projects through the Intuned platform
68
+ - WARNING: ⚠️ Changes to TS Config may break some Intuned functionalities
69
+ `;
@@ -0,0 +1,24 @@
1
+ export declare const CURRENT_PLAYWRIGHT_VERSION = "1.44.1";
2
+ export declare const ProjectDeploymentStatus: string[];
3
+ export declare const PROJECT_DEPLOY_TIMEOUT = 600000;
4
+ export declare const userCLIScripts: {
5
+ build: string;
6
+ "types-check": string;
7
+ "pre-publish": string;
8
+ start: string;
9
+ "run-api": string;
10
+ "cli-build": string;
11
+ deploy: string;
12
+ };
13
+ export declare const tsConfigCli: {
14
+ compilerOptions: {
15
+ moduleResolution: string;
16
+ target: string;
17
+ outDir: string;
18
+ sourceMap: boolean;
19
+ declaration: boolean;
20
+ esModuleInterop: boolean;
21
+ };
22
+ include: string[];
23
+ exclude: string[];
24
+ };
@@ -0,0 +1,30 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.userCLIScripts = exports.tsConfigCli = exports.ProjectDeploymentStatus = exports.PROJECT_DEPLOY_TIMEOUT = exports.CURRENT_PLAYWRIGHT_VERSION = void 0;
7
+ const CURRENT_PLAYWRIGHT_VERSION = exports.CURRENT_PLAYWRIGHT_VERSION = "1.44.1";
8
+ const ProjectDeploymentStatus = exports.ProjectDeploymentStatus = ["completed", "failed", "pending", "not_found"];
9
+ const PROJECT_DEPLOY_TIMEOUT = exports.PROJECT_DEPLOY_TIMEOUT = 600000;
10
+ const userCLIScripts = exports.userCLIScripts = {
11
+ build: "intuned-build",
12
+ "types-check": "intuned-ts-check",
13
+ "pre-publish": "intuned-ts-check && intuned-build",
14
+ start: "node ./output/bundle_v2.js",
15
+ "run-api": "run-api",
16
+ "cli-build": "cli-build",
17
+ deploy: "deploy"
18
+ };
19
+ const tsConfigCli = exports.tsConfigCli = {
20
+ compilerOptions: {
21
+ moduleResolution: "node",
22
+ target: "ES2021",
23
+ outDir: "./dist",
24
+ sourceMap: false,
25
+ declaration: true,
26
+ esModuleInterop: true
27
+ },
28
+ include: ["**/*.ts"],
29
+ exclude: ["node_modules", "dist"]
30
+ };