@intuned/runtime-dev 1.0.6-dev.4 → 1.0.6-playwright-1.46.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.
- package/InterfaceTemplate/utils.ts +31 -53
- package/dist/commands/common/tsNodeImport.d.ts +1 -2
- package/dist/commands/common/tsNodeImport.js +5 -19
- package/dist/commands/common/utils/unixSocket.d.ts +0 -1
- package/dist/commands/interface/run.js +3 -30
- package/dist/common/asyncLocalStorage/index.d.ts +0 -1
- package/dist/common/runApi/index.d.ts +0 -1
- package/dist/common/runApi/index.js +2 -9
- package/dist/common/runApi/types.d.ts +3 -9
- package/package.json +3 -3
- package/dist/commands/deploy/deploy.d.ts +0 -2
- package/dist/commands/deploy/deploy.js +0 -34
- package/dist/commands/deploy/utils.d.ts +0 -7
- package/dist/commands/deploy/utils.js +0 -203
- package/dist/commands/init/init.d.ts +0 -2
- package/dist/commands/init/init.js +0 -23
- package/dist/commands/init/types.d.ts +0 -52
- package/dist/commands/init/types.js +0 -7
- package/dist/commands/init/utils.d.ts +0 -9
- package/dist/commands/init/utils.js +0 -145
- package/dist/commands/intuned-run/intuned-run.d.ts +0 -4
- package/dist/commands/intuned-run/intuned-run.js +0 -84
- package/dist/commands/intuned-run/utils.d.ts +0 -1
- package/dist/commands/intuned-run/utils.js +0 -34
|
@@ -1,7 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
import { err, ok } from "neverthrow";
|
|
3
|
-
|
|
4
|
-
export const importModule: ImportFunction = async (path: string) => {
|
|
1
|
+
export async function importModule(path: string) {
|
|
5
2
|
const [folderName, ...functionNameParts] = path.split("/");
|
|
6
3
|
const functionNameDepth = functionNameParts.length;
|
|
7
4
|
|
|
@@ -9,53 +6,34 @@ export const importModule: ImportFunction = async (path: string) => {
|
|
|
9
6
|
// currently we support only 5 levels of depth
|
|
10
7
|
// rollup dynamic import does not support multiple levels of dynamic imports so we need to specify the possible paths explicitly
|
|
11
8
|
let imported: any = undefined;
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
error: new Error(
|
|
41
|
-
`intuned supports maximum 5 levels of depth in the api folder`
|
|
42
|
-
),
|
|
43
|
-
});
|
|
44
|
-
}
|
|
45
|
-
return ok(imported);
|
|
46
|
-
} catch (e: any) {
|
|
47
|
-
if (
|
|
48
|
-
"message" in e &&
|
|
49
|
-
typeof e.message === "string" &&
|
|
50
|
-
e.message.includes("Unknown variable dynamic import")
|
|
51
|
-
) {
|
|
52
|
-
return err({
|
|
53
|
-
type: "not_found",
|
|
54
|
-
});
|
|
55
|
-
}
|
|
56
|
-
return err({
|
|
57
|
-
type: "other",
|
|
58
|
-
error: e,
|
|
59
|
-
});
|
|
9
|
+
switch (functionNameDepth) {
|
|
10
|
+
case 1:
|
|
11
|
+
imported = await import(`./${folderName}/${functionNameParts[0]}.ts`);
|
|
12
|
+
break;
|
|
13
|
+
case 2:
|
|
14
|
+
imported = await import(
|
|
15
|
+
`./${folderName}/${functionNameParts[0]}/${functionNameParts[1]}.ts`
|
|
16
|
+
);
|
|
17
|
+
break;
|
|
18
|
+
case 3:
|
|
19
|
+
imported = await import(
|
|
20
|
+
`./${folderName}/${functionNameParts[0]}/${functionNameParts[1]}/${functionNameParts[2]}.ts`
|
|
21
|
+
);
|
|
22
|
+
break;
|
|
23
|
+
case 4:
|
|
24
|
+
imported = await import(
|
|
25
|
+
`./${folderName}/${functionNameParts[0]}/${functionNameParts[1]}/${functionNameParts[2]}/${functionNameParts[3]}.ts`
|
|
26
|
+
);
|
|
27
|
+
break;
|
|
28
|
+
case 5:
|
|
29
|
+
imported = await import(
|
|
30
|
+
`./${folderName}/${functionNameParts[0]}/${functionNameParts[1]}/${functionNameParts[2]}/${functionNameParts[3]}/${functionNameParts[4]}.ts`
|
|
31
|
+
);
|
|
32
|
+
break;
|
|
33
|
+
default:
|
|
34
|
+
throw new Error(
|
|
35
|
+
"intuned supports maximum 5 levels of depth in the api folder"
|
|
36
|
+
);
|
|
60
37
|
}
|
|
61
|
-
|
|
38
|
+
return imported;
|
|
39
|
+
}
|
|
@@ -1,2 +1 @@
|
|
|
1
|
-
|
|
2
|
-
export declare const tsNodeImport: ExtendedRunApiParameters["importFunction"];
|
|
1
|
+
export declare function tsNodeImport(apiName: string): Promise<any>;
|
|
@@ -3,12 +3,11 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.tsNodeImport =
|
|
7
|
-
var _neverthrow = require("neverthrow");
|
|
6
|
+
exports.tsNodeImport = tsNodeImport;
|
|
8
7
|
var _fileUtils = require("./utils/fileUtils");
|
|
9
8
|
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
9
|
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
|
-
|
|
10
|
+
async function tsNodeImport(apiName) {
|
|
12
11
|
require("ts-node").register({
|
|
13
12
|
transpileOnly: true,
|
|
14
13
|
compilerOptions: {
|
|
@@ -16,19 +15,6 @@ const tsNodeImport = async apiName => {
|
|
|
16
15
|
}
|
|
17
16
|
});
|
|
18
17
|
const path = (0, _fileUtils.getFullPathInProject)(...apiName.split("/"));
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
} catch (e) {
|
|
23
|
-
if ("code" in e && e.code === "MODULE_NOT_FOUND") {
|
|
24
|
-
return (0, _neverthrow.err)({
|
|
25
|
-
type: "not_found"
|
|
26
|
-
});
|
|
27
|
-
}
|
|
28
|
-
return (0, _neverthrow.err)({
|
|
29
|
-
type: "other",
|
|
30
|
-
error: e
|
|
31
|
-
});
|
|
32
|
-
}
|
|
33
|
-
};
|
|
34
|
-
exports.tsNodeImport = tsNodeImport;
|
|
18
|
+
const imported = await (specifier => new Promise(r => r(`${specifier}`)).then(s => _interopRequireWildcard(require(s))))(path);
|
|
19
|
+
return imported;
|
|
20
|
+
}
|
|
@@ -15,10 +15,9 @@ 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 _neverthrow = require("neverthrow");
|
|
19
|
-
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
20
18
|
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
19
|
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; }
|
|
20
|
+
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
22
21
|
const startRunApiSchema = _zod.default.object({
|
|
23
22
|
type: _zod.default.literal("start"),
|
|
24
23
|
parameters: _runApi.runApiParametersSchema.extend({
|
|
@@ -48,11 +47,7 @@ const tokenUpdateSchema = _zod.default.object({
|
|
|
48
47
|
functionsToken: _zod.default.string()
|
|
49
48
|
})
|
|
50
49
|
});
|
|
51
|
-
const
|
|
52
|
-
type: _zod.default.literal("ping"),
|
|
53
|
-
parameters: _zod.default.object({}).optional()
|
|
54
|
-
});
|
|
55
|
-
const inputSchema = _zod.default.union([startRunApiSchema, nextRunApiSchema, abortRunApiSchema, tokenUpdateSchema, pingSchema]);
|
|
50
|
+
const inputSchema = _zod.default.union([startRunApiSchema, nextRunApiSchema, abortRunApiSchema, tokenUpdateSchema]);
|
|
56
51
|
_dotenv.default.config({
|
|
57
52
|
path: `.env`
|
|
58
53
|
});
|
|
@@ -110,7 +105,7 @@ function runAutomationCLI(importFunction) {
|
|
|
110
105
|
generator = (0, _runApi.runApiGenerator)({
|
|
111
106
|
...message.parameters,
|
|
112
107
|
abortSignal: abortController.signal,
|
|
113
|
-
importFunction
|
|
108
|
+
importFunction
|
|
114
109
|
});
|
|
115
110
|
context = {
|
|
116
111
|
extendedPayloads: [],
|
|
@@ -185,12 +180,6 @@ function runAutomationCLI(importFunction) {
|
|
|
185
180
|
});
|
|
186
181
|
break;
|
|
187
182
|
}
|
|
188
|
-
if (message.type === "ping") {
|
|
189
|
-
jsonUnixSocket.sendJSON({
|
|
190
|
-
type: "pong"
|
|
191
|
-
});
|
|
192
|
-
break;
|
|
193
|
-
}
|
|
194
183
|
await handleMessage(message);
|
|
195
184
|
receiveMessagesPromise = receiveMessages();
|
|
196
185
|
continue;
|
|
@@ -220,22 +209,6 @@ function getProxyUrlFromRunOptions(runOptions) {
|
|
|
220
209
|
url.password = proxy.password;
|
|
221
210
|
return url.toString();
|
|
222
211
|
}
|
|
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
|
-
};
|
|
239
212
|
if (require.main === module) {
|
|
240
213
|
runAutomationCLI();
|
|
241
214
|
}
|
|
@@ -10,4 +10,3 @@ export declare function runApiGenerator<ResultType = any, _YieldType = any, _Nex
|
|
|
10
10
|
export declare function runApiGenerator<ResultType = any, _YieldType = any, _NextType = any>(params: ExtendedRunApiParameters): AsyncGenerator<_YieldType, RunApiResult<ResultType>, _NextType>;
|
|
11
11
|
export declare function runApi<ResultType = any>(params: ExtendedRunApiParameters): Promise<RunApiResult<ResultType>>;
|
|
12
12
|
export declare function checkAuthSessionWithRetries(page: Page, context: BrowserContext, checkFn: (..._: any) => Promise<boolean>, retries?: number): Promise<Result<boolean, RunAutomationError>>;
|
|
13
|
-
export type ImportFunction = ExtendedRunApiParameters["importFunction"];
|
|
@@ -242,14 +242,7 @@ async function checkAuthSessionWithRetries(page, context, checkFn, retries = 3)
|
|
|
242
242
|
}
|
|
243
243
|
async function importUsingImportFunction(path, importFunction) {
|
|
244
244
|
try {
|
|
245
|
-
const
|
|
246
|
-
if (importedResult.isErr()) {
|
|
247
|
-
if (importedResult.error.type === "not_found") {
|
|
248
|
-
return (0, _neverthrow.err)(new _errors.ApiNotFoundError(path));
|
|
249
|
-
}
|
|
250
|
-
return (0, _neverthrow.err)(new _errors.AutomationError(importedResult.error.error));
|
|
251
|
-
}
|
|
252
|
-
const imported = importedResult.value;
|
|
245
|
+
const imported = importFunction ? await importFunction(path) : await (specifier => new Promise(r => r(specifier)).then(s => _interopRequireWildcard(require(s))))(`../../../${path}.ts`);
|
|
253
246
|
if (!imported || !imported.default || !imported.default.constructor) {
|
|
254
247
|
return (0, _neverthrow.err)(new _errors.InvalidApiError("API file path does not have a default export"));
|
|
255
248
|
}
|
|
@@ -267,6 +260,6 @@ async function importUsingImportFunction(path, importFunction) {
|
|
|
267
260
|
}
|
|
268
261
|
return (0, _neverthrow.err)(new _errors.InvalidApiError("API file path does not have a default async function/generator export"));
|
|
269
262
|
} catch (error) {
|
|
270
|
-
return (0, _neverthrow.err)(new _errors.
|
|
263
|
+
return (0, _neverthrow.err)(new _errors.ApiNotFoundError(path));
|
|
271
264
|
}
|
|
272
265
|
}
|
|
@@ -545,12 +545,12 @@ export declare const runApiParametersSchema: z.ZodObject<{
|
|
|
545
545
|
} | undefined;
|
|
546
546
|
}, {
|
|
547
547
|
environment: "standalone";
|
|
548
|
-
headless?: boolean | undefined;
|
|
549
548
|
proxy?: {
|
|
550
549
|
server: string;
|
|
551
550
|
username: string;
|
|
552
551
|
password: string;
|
|
553
552
|
} | undefined;
|
|
553
|
+
headless?: boolean | undefined;
|
|
554
554
|
}>, z.ZodObject<{
|
|
555
555
|
environment: z.ZodLiteral<"cdp">;
|
|
556
556
|
cdpAddress: z.ZodString;
|
|
@@ -673,12 +673,12 @@ export declare const runApiParametersSchema: z.ZodObject<{
|
|
|
673
673
|
} | undefined;
|
|
674
674
|
runOptions?: {
|
|
675
675
|
environment: "standalone";
|
|
676
|
-
headless?: boolean | undefined;
|
|
677
676
|
proxy?: {
|
|
678
677
|
server: string;
|
|
679
678
|
username: string;
|
|
680
679
|
password: string;
|
|
681
680
|
} | undefined;
|
|
681
|
+
headless?: boolean | undefined;
|
|
682
682
|
} | {
|
|
683
683
|
mode: "vanilla" | "playwright" | "playwright-standalone" | "playwright-headless";
|
|
684
684
|
environment: "cdp";
|
|
@@ -688,15 +688,9 @@ export declare const runApiParametersSchema: z.ZodObject<{
|
|
|
688
688
|
}>;
|
|
689
689
|
export type RunApiSession = z.infer<typeof runApiSessionSchema>;
|
|
690
690
|
export type RunApiParameters = z.input<typeof runApiParametersSchema>;
|
|
691
|
-
export type ImportFunctionError = {
|
|
692
|
-
type: "not_found";
|
|
693
|
-
} | {
|
|
694
|
-
type: "other";
|
|
695
|
-
error: any;
|
|
696
|
-
};
|
|
697
691
|
export type ExtendedRunApiParameters = RunApiParameters & {
|
|
698
692
|
abortSignal?: AbortSignal;
|
|
699
|
-
importFunction
|
|
693
|
+
importFunction?: (name: string) => Promise<any> | undefined;
|
|
700
694
|
};
|
|
701
695
|
export type RunApiResultOk<R = any> = {
|
|
702
696
|
result: R;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@intuned/runtime-dev",
|
|
3
|
-
"version": "1.0.6-
|
|
3
|
+
"version": "1.0.6-playwright-1.46.0",
|
|
4
4
|
"description": "Intuned runtime",
|
|
5
5
|
"exports": {
|
|
6
6
|
".": "./dist/index.js",
|
|
@@ -81,7 +81,7 @@
|
|
|
81
81
|
"ms": "^2.1.3",
|
|
82
82
|
"nanoid": "3",
|
|
83
83
|
"neverthrow": "^6.1.0",
|
|
84
|
-
"playwright": "1.
|
|
84
|
+
"playwright": "1.46.0",
|
|
85
85
|
"playwright-extra": "^4.3.6",
|
|
86
86
|
"prettier": "^2.8.0",
|
|
87
87
|
"promptly": "^3.2.0",
|
|
@@ -133,4 +133,4 @@
|
|
|
133
133
|
"peerDependencies": {
|
|
134
134
|
"@intuned/runtime": "*"
|
|
135
135
|
}
|
|
136
|
-
}
|
|
136
|
+
}
|
|
@@ -1,34 +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("../init/utils");
|
|
8
|
-
var _utils2 = require("./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
|
-
if (!projectName) {
|
|
16
|
-
throw new Error("Project name is required");
|
|
17
|
-
}
|
|
18
|
-
const projectNameValidation = (0, _utils2.validateProjectName)(projectName);
|
|
19
|
-
if (!projectNameValidation.isValid) {
|
|
20
|
-
throw new Error(projectNameValidation.errorMessage);
|
|
21
|
-
}
|
|
22
|
-
const auth = (0, _utils.getAuthCredentials)(options);
|
|
23
|
-
const deployStarted = await (0, _utils2.deployProject)(projectName, auth);
|
|
24
|
-
if (!deployStarted) {
|
|
25
|
-
throw new Error("Project not deployed");
|
|
26
|
-
}
|
|
27
|
-
const url = `https://rauf-2.intuned-team-local.com/projects`;
|
|
28
|
-
console.log(_chalk.default.green(`\n🚀 Project "${projectName}" started deployment successfully!` + `\n\nYou can check your project on the platform: ${_chalk.default.bold(url)}\n`));
|
|
29
|
-
} catch (error) {
|
|
30
|
-
console.error(_chalk.default.red(`\n${error.message}`));
|
|
31
|
-
process.exit(1);
|
|
32
|
-
}
|
|
33
|
-
});
|
|
34
|
-
_commander.program.parse(process.argv);
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import { AuthCredentials, FileSystemTree } from "../init/types";
|
|
2
|
-
export declare function convertProjectToCodeTree(projectPath: string): Promise<FileSystemTree>;
|
|
3
|
-
export declare function deployProject(projectName: string, auth: AuthCredentials): Promise<boolean>;
|
|
4
|
-
export declare const validateProjectName: (projectName: string) => {
|
|
5
|
-
isValid: boolean;
|
|
6
|
-
errorMessage?: string;
|
|
7
|
-
};
|
|
@@ -1,203 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.convertProjectToCodeTree = convertProjectToCodeTree;
|
|
7
|
-
exports.deployProject = deployProject;
|
|
8
|
-
exports.validateProjectName = void 0;
|
|
9
|
-
var fs = _interopRequireWildcard(require("fs"));
|
|
10
|
-
var path = _interopRequireWildcard(require("path"));
|
|
11
|
-
var _chalk = _interopRequireDefault(require("chalk"));
|
|
12
|
-
var _minimatch = _interopRequireDefault(require("minimatch"));
|
|
13
|
-
var _zod = require("zod");
|
|
14
|
-
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
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 formatBytes(bytes) {
|
|
18
|
-
if (bytes === 0) return "0 Bytes";
|
|
19
|
-
const k = 1024;
|
|
20
|
-
const sizes = ["Bytes", "KB", "MB", "GB"];
|
|
21
|
-
const i = Math.floor(Math.log(bytes) / Math.log(k));
|
|
22
|
-
return parseFloat((bytes / Math.pow(k, i)).toFixed(2)) + " " + sizes[i];
|
|
23
|
-
}
|
|
24
|
-
function matchesGitignorePatterns(filePath, patterns, projectPath) {
|
|
25
|
-
const relativePath = path.relative(projectPath, filePath);
|
|
26
|
-
if (relativePath.startsWith("node_modules")) {
|
|
27
|
-
return true;
|
|
28
|
-
}
|
|
29
|
-
for (const pattern of patterns) {
|
|
30
|
-
if (!pattern || pattern.startsWith("#")) continue;
|
|
31
|
-
if (pattern.startsWith("!")) {
|
|
32
|
-
if ((0, _minimatch.default)(relativePath, pattern.substring(1))) {
|
|
33
|
-
return false;
|
|
34
|
-
}
|
|
35
|
-
} else if ((0, _minimatch.default)(relativePath, pattern)) {
|
|
36
|
-
return true;
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
return false;
|
|
40
|
-
}
|
|
41
|
-
function listFilesNotIgnored(projectPath, ignorePatterns) {
|
|
42
|
-
const results = [];
|
|
43
|
-
function traverseDirectory(dirPath) {
|
|
44
|
-
try {
|
|
45
|
-
const entries = fs.readdirSync(dirPath);
|
|
46
|
-
for (const entry of entries) {
|
|
47
|
-
const fullPath = path.join(dirPath, entry);
|
|
48
|
-
if (matchesGitignorePatterns(fullPath, ignorePatterns, projectPath)) {
|
|
49
|
-
continue;
|
|
50
|
-
}
|
|
51
|
-
try {
|
|
52
|
-
const stats = fs.statSync(fullPath);
|
|
53
|
-
if (stats.isDirectory()) {
|
|
54
|
-
traverseDirectory(fullPath);
|
|
55
|
-
} else if (stats.isFile()) {
|
|
56
|
-
results.push(path.relative(projectPath, fullPath));
|
|
57
|
-
}
|
|
58
|
-
} catch (error) {
|
|
59
|
-
console.log(_chalk.default.yellow(`Warning: Could not access ${fullPath}`));
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
} catch (error) {
|
|
63
|
-
console.log(_chalk.default.yellow(`Warning: Could not read directory ${dirPath}`));
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
traverseDirectory(projectPath);
|
|
67
|
-
return results;
|
|
68
|
-
}
|
|
69
|
-
async function convertProjectToCodeTree(projectPath) {
|
|
70
|
-
const defaultExcludes = ["node_modules/**", ".git/**", "dist/**", "build/**", "coverage/**", ".next/**", ".cache/**", "out/**", "tmp/**", ".DS_Store", "npm-debug.log*", "yarn-debug.log*", "yarn-error.log*", ".env", ".env.*", "**/*.map", "**/*.tsbuildinfo"];
|
|
71
|
-
let ignorePatterns = [...defaultExcludes];
|
|
72
|
-
let currentDir = path.normalize(projectPath);
|
|
73
|
-
let gitignoreFound = false;
|
|
74
|
-
while (currentDir !== path.parse(currentDir).root) {
|
|
75
|
-
const gitignorePath = path.join(currentDir, ".gitignore");
|
|
76
|
-
if (fs.existsSync(gitignorePath)) {
|
|
77
|
-
const gitignoreContent = fs.readFileSync(gitignorePath, "utf-8").split("\n");
|
|
78
|
-
ignorePatterns = [...ignorePatterns, ...gitignoreContent];
|
|
79
|
-
console.log(`Found .gitignore file: ${_chalk.default.cyan.bold(gitignorePath)}`);
|
|
80
|
-
gitignoreFound = true;
|
|
81
|
-
break;
|
|
82
|
-
} else {
|
|
83
|
-
currentDir = path.dirname(currentDir);
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
if (!gitignoreFound) {
|
|
87
|
-
console.log(_chalk.default.yellow(".gitignore file not found. Using default exclusions only."));
|
|
88
|
-
} else {
|
|
89
|
-
console.log(_chalk.default.yellow("Using standard exclusions plus .gitignore patterns."));
|
|
90
|
-
}
|
|
91
|
-
const filesToDeploy = listFilesNotIgnored(projectPath, ignorePatterns);
|
|
92
|
-
let totalSize = 0;
|
|
93
|
-
for (const file of filesToDeploy) {
|
|
94
|
-
try {
|
|
95
|
-
const stats = fs.statSync(path.join(projectPath, file));
|
|
96
|
-
totalSize += stats.size;
|
|
97
|
-
} catch (error) {}
|
|
98
|
-
}
|
|
99
|
-
console.log(_chalk.default.cyan("\nFiles to be deployed:"));
|
|
100
|
-
if (filesToDeploy.length > 100) {
|
|
101
|
-
console.log(_chalk.default.yellow(` ${filesToDeploy.length} files (too many to display)`));
|
|
102
|
-
} else {
|
|
103
|
-
const filesToDeployText = "\n " + filesToDeploy.join("\n ");
|
|
104
|
-
console.log(filesToDeployText);
|
|
105
|
-
}
|
|
106
|
-
console.log(_chalk.default.cyan(`\nSummary: ${filesToDeploy.length} files, ${formatBytes(totalSize)}`));
|
|
107
|
-
function readDirectory(dirPath) {
|
|
108
|
-
const tree = {};
|
|
109
|
-
try {
|
|
110
|
-
const entries = fs.readdirSync(dirPath);
|
|
111
|
-
for (const entry of entries) {
|
|
112
|
-
const entryPath = path.join(dirPath, entry);
|
|
113
|
-
if (matchesGitignorePatterns(entryPath, ignorePatterns, projectPath)) {
|
|
114
|
-
continue;
|
|
115
|
-
}
|
|
116
|
-
try {
|
|
117
|
-
const stats = fs.statSync(entryPath);
|
|
118
|
-
if (stats.isFile()) {
|
|
119
|
-
try {
|
|
120
|
-
const content = fs.readFileSync(entryPath, "utf-8");
|
|
121
|
-
tree[entry] = {
|
|
122
|
-
file: {
|
|
123
|
-
contents: content
|
|
124
|
-
}
|
|
125
|
-
};
|
|
126
|
-
} catch (error) {
|
|
127
|
-
console.log(_chalk.default.yellow(`Warning: Could not read file ${entryPath}`));
|
|
128
|
-
}
|
|
129
|
-
} else if (stats.isDirectory()) {
|
|
130
|
-
const subTree = readDirectory(entryPath);
|
|
131
|
-
if (Object.keys(subTree).length > 0) {
|
|
132
|
-
tree[entry] = {
|
|
133
|
-
directory: subTree
|
|
134
|
-
};
|
|
135
|
-
}
|
|
136
|
-
}
|
|
137
|
-
} catch (error) {
|
|
138
|
-
console.log(_chalk.default.yellow(`Warning: Could not access ${entryPath}`));
|
|
139
|
-
}
|
|
140
|
-
}
|
|
141
|
-
} catch (error) {
|
|
142
|
-
console.log(_chalk.default.yellow(`Warning: Could not read directory ${dirPath}`));
|
|
143
|
-
}
|
|
144
|
-
return tree;
|
|
145
|
-
}
|
|
146
|
-
console.log(_chalk.default.cyan("\nBuilding code tree..."));
|
|
147
|
-
const tree = readDirectory(projectPath);
|
|
148
|
-
console.log(_chalk.default.green("Code tree generation complete!"));
|
|
149
|
-
return tree;
|
|
150
|
-
}
|
|
151
|
-
async function deployProject(projectName, auth) {
|
|
152
|
-
const {
|
|
153
|
-
workspaceId,
|
|
154
|
-
apiKey
|
|
155
|
-
} = auth;
|
|
156
|
-
const baseUrl = "https://rauf-2.intuned-team-local.com";
|
|
157
|
-
const url = `${baseUrl}/api/v1/workspace/${workspaceId}/projects/create`;
|
|
158
|
-
const headers = {
|
|
159
|
-
"x-api-key": apiKey,
|
|
160
|
-
"Content-Type": "application/json"
|
|
161
|
-
};
|
|
162
|
-
const projectPath = process.cwd();
|
|
163
|
-
const codeTree = await convertProjectToCodeTree(projectPath);
|
|
164
|
-
const deployProjectPayload = {
|
|
165
|
-
name: projectName,
|
|
166
|
-
codeTree: codeTree,
|
|
167
|
-
isCli: true,
|
|
168
|
-
language: "typescript"
|
|
169
|
-
};
|
|
170
|
-
const response = await fetch(url, {
|
|
171
|
-
headers,
|
|
172
|
-
method: "POST",
|
|
173
|
-
body: JSON.stringify(deployProjectPayload)
|
|
174
|
-
});
|
|
175
|
-
if (!response.ok) {
|
|
176
|
-
throw new Error(`Error deploying project`);
|
|
177
|
-
}
|
|
178
|
-
const data = await response.json();
|
|
179
|
-
if (response.status === 202) {
|
|
180
|
-
return true;
|
|
181
|
-
}
|
|
182
|
-
if (!data) {
|
|
183
|
-
throw new Error("Project not deployed");
|
|
184
|
-
}
|
|
185
|
-
return false;
|
|
186
|
-
}
|
|
187
|
-
const validateProjectName = projectName => {
|
|
188
|
-
const nameSchema = _zod.z.string().min(1, "Project Name is required").max(50, "Name must be 50 characters or less").regex(/^[a-z0-9]+(?:[-_][a-z0-9]+)*$/, "Name can only contain lowercase letters, numbers, hyphens, and underscores in between").refine(value => !_zod.z.string().uuid().safeParse(value).success, {
|
|
189
|
-
message: "Name cannot be a UUID"
|
|
190
|
-
});
|
|
191
|
-
const validation = nameSchema.safeParse(projectName);
|
|
192
|
-
if (!validation.success) {
|
|
193
|
-
console.error(_chalk.default.red(validation.error.errors[0].message));
|
|
194
|
-
return {
|
|
195
|
-
isValid: false,
|
|
196
|
-
errorMessage: validation.error.errors[0].message
|
|
197
|
-
};
|
|
198
|
-
}
|
|
199
|
-
return {
|
|
200
|
-
isValid: true
|
|
201
|
-
};
|
|
202
|
-
};
|
|
203
|
-
exports.validateProjectName = validateProjectName;
|
|
@@ -1,23 +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").option("-w, --workspace-id <id>", "Your Intuned workspace ID").option("-k, --api-key <key>", "Your Intuned API key").action(async (templateName, options) => {
|
|
13
|
-
try {
|
|
14
|
-
const auth = (0, _utils.getAuthCredentials)(options);
|
|
15
|
-
const template = await (0, _utils.selectTemplate)(templateName);
|
|
16
|
-
await (0, _utils.checkEmptyDirectory)();
|
|
17
|
-
await (0, _utils.scaffoldProject)(template, auth);
|
|
18
|
-
} catch (error) {
|
|
19
|
-
console.error(_chalk.default.red(`\n${error.message}`));
|
|
20
|
-
process.exit(1);
|
|
21
|
-
}
|
|
22
|
-
});
|
|
23
|
-
_commander.program.parse(process.argv);
|
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
export declare const templateIds: string[];
|
|
2
|
-
export type TemplateId = (typeof templateIds)[number];
|
|
3
|
-
/**
|
|
4
|
-
* A simple, tree-like structure to describe the contents of a folder to be mounted.
|
|
5
|
-
*
|
|
6
|
-
* @example
|
|
7
|
-
* ```
|
|
8
|
-
* const tree = {
|
|
9
|
-
* myproject: {
|
|
10
|
-
* directory: {
|
|
11
|
-
* 'foo.js': {
|
|
12
|
-
* file: {
|
|
13
|
-
* contents: 'const x = 1;',
|
|
14
|
-
* },
|
|
15
|
-
* },
|
|
16
|
-
* .envrc: {
|
|
17
|
-
* file: {
|
|
18
|
-
* contents: 'ENVIRONMENT=staging'
|
|
19
|
-
* }
|
|
20
|
-
* },
|
|
21
|
-
* },
|
|
22
|
-
* },
|
|
23
|
-
* emptyFolder: {
|
|
24
|
-
* directory: {}
|
|
25
|
-
* },
|
|
26
|
-
* };
|
|
27
|
-
* ```
|
|
28
|
-
*/
|
|
29
|
-
export interface FileSystemTree {
|
|
30
|
-
[name: string]: DirectoryNode | FileNode;
|
|
31
|
-
}
|
|
32
|
-
/**
|
|
33
|
-
* Represents a directory, see {@link FileSystemTree}.
|
|
34
|
-
*/
|
|
35
|
-
export interface DirectoryNode {
|
|
36
|
-
directory: FileSystemTree;
|
|
37
|
-
}
|
|
38
|
-
/**
|
|
39
|
-
* Represents a file, see {@link FileSystemTree}.
|
|
40
|
-
*/
|
|
41
|
-
export interface FileNode {
|
|
42
|
-
file: {
|
|
43
|
-
/**
|
|
44
|
-
* The contents of the file, either as a UTF-8 string or as raw binary.
|
|
45
|
-
*/
|
|
46
|
-
contents: string | Uint8Array;
|
|
47
|
-
};
|
|
48
|
-
}
|
|
49
|
-
export interface AuthCredentials {
|
|
50
|
-
workspaceId: string;
|
|
51
|
-
apiKey: string;
|
|
52
|
-
}
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.templateIds = void 0;
|
|
7
|
-
const templateIds = exports.templateIds = ["default", "empty", "linkedin-recorder", "api-auth-sessions", "nested-scheduling", "ai-extractors", "npm-auth-sessions", "python-empty"];
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import { AuthCredentials, FileSystemTree } from "./types";
|
|
2
|
-
export declare function mountFiles(cwd: string, tree: FileSystemTree): Promise<void>;
|
|
3
|
-
export declare function checkEmptyDirectory(): Promise<void>;
|
|
4
|
-
export declare function getAuthCredentials(options: any): {
|
|
5
|
-
workspaceId: any;
|
|
6
|
-
apiKey: any;
|
|
7
|
-
};
|
|
8
|
-
export declare function selectTemplate(templateName: any): Promise<any>;
|
|
9
|
-
export declare function scaffoldProject(templateId: string, authCredentials: AuthCredentials): Promise<void>;
|
|
@@ -1,145 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.checkEmptyDirectory = checkEmptyDirectory;
|
|
7
|
-
exports.getAuthCredentials = getAuthCredentials;
|
|
8
|
-
exports.mountFiles = mountFiles;
|
|
9
|
-
exports.scaffoldProject = scaffoldProject;
|
|
10
|
-
exports.selectTemplate = selectTemplate;
|
|
11
|
-
var fs = _interopRequireWildcard(require("fs-extra"));
|
|
12
|
-
var _types = require("./types");
|
|
13
|
-
var _chalk = _interopRequireDefault(require("chalk"));
|
|
14
|
-
var _inquirer = _interopRequireDefault(require("inquirer"));
|
|
15
|
-
var _path = _interopRequireDefault(require("path"));
|
|
16
|
-
var _boxen = _interopRequireDefault(require("boxen"));
|
|
17
|
-
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
18
|
-
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); }
|
|
19
|
-
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; }
|
|
20
|
-
function _isDirectoryNode(node) {
|
|
21
|
-
return node.directory !== undefined;
|
|
22
|
-
}
|
|
23
|
-
function _isFileNode(node) {
|
|
24
|
-
return node.file !== undefined;
|
|
25
|
-
}
|
|
26
|
-
async function mountFiles(cwd, tree) {
|
|
27
|
-
for (const name in tree) {
|
|
28
|
-
const fullPath = _path.default.join(cwd, name);
|
|
29
|
-
const node = tree[name];
|
|
30
|
-
if (_isDirectoryNode(node)) {
|
|
31
|
-
await fs.ensureDir(fullPath);
|
|
32
|
-
await mountFiles(fullPath, node.directory);
|
|
33
|
-
} else if (_isFileNode(node)) {
|
|
34
|
-
await fs.writeFile(fullPath, node.file.contents);
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
async function checkEmptyDirectory() {
|
|
39
|
-
const currentDir = process.cwd();
|
|
40
|
-
try {
|
|
41
|
-
const stats = await fs.stat(currentDir);
|
|
42
|
-
if (!stats.isDirectory()) {
|
|
43
|
-
throw new Error("The current path is not a directory.");
|
|
44
|
-
}
|
|
45
|
-
const files = await fs.readdir(currentDir);
|
|
46
|
-
const significantFiles = files.filter(file => ![".git", ".DS_Store", "Thumbs.db", ".gitkeep"].includes(file));
|
|
47
|
-
if (significantFiles.length) {
|
|
48
|
-
throw new Error("The current directory is not empty.");
|
|
49
|
-
}
|
|
50
|
-
} catch (error) {
|
|
51
|
-
if (error.code === "ENOENT") {
|
|
52
|
-
throw new Error("The specified directory does not exist.");
|
|
53
|
-
}
|
|
54
|
-
throw error;
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
function getAuthCredentials(options) {
|
|
58
|
-
const workspaceId = options.workspaceId || process.env.INTUNED_WORKSPACE_ID;
|
|
59
|
-
const apiKey = options.apiKey || process.env.INTUNED_API_KEY;
|
|
60
|
-
const missingAuth = [];
|
|
61
|
-
if (!workspaceId) {
|
|
62
|
-
missingAuth.push({
|
|
63
|
-
type: "input",
|
|
64
|
-
name: "workspaceId",
|
|
65
|
-
message: "Enter your Intuned workspace ID:",
|
|
66
|
-
validate: input => input.trim() !== "" ? true : "Workspace ID is required"
|
|
67
|
-
});
|
|
68
|
-
}
|
|
69
|
-
if (!apiKey) {
|
|
70
|
-
missingAuth.push({
|
|
71
|
-
type: "password",
|
|
72
|
-
name: "apiKey",
|
|
73
|
-
message: "Enter your Intuned API key:",
|
|
74
|
-
mask: "*",
|
|
75
|
-
validate: input => input.trim() !== "" ? true : "API key is required"
|
|
76
|
-
});
|
|
77
|
-
}
|
|
78
|
-
if (missingAuth.length) {
|
|
79
|
-
throw new Error("Authentication details are required. Please provide them via command line options or environment variables.");
|
|
80
|
-
}
|
|
81
|
-
return {
|
|
82
|
-
workspaceId,
|
|
83
|
-
apiKey
|
|
84
|
-
};
|
|
85
|
-
}
|
|
86
|
-
async function selectTemplate(templateName) {
|
|
87
|
-
if (templateName) {
|
|
88
|
-
const validTemplate = _types.templateIds.find(t => t === templateName);
|
|
89
|
-
if (!validTemplate) {
|
|
90
|
-
console.log(_chalk.default.yellow(`\n⚠️ Template "${templateName}" not found.`));
|
|
91
|
-
} else {
|
|
92
|
-
return templateName;
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
console.log(_chalk.default.yellow("\n📋 Select a Template"));
|
|
96
|
-
const {
|
|
97
|
-
template
|
|
98
|
-
} = await _inquirer.default.prompt([{
|
|
99
|
-
type: "list",
|
|
100
|
-
name: "template",
|
|
101
|
-
message: "Which template would you like to use?",
|
|
102
|
-
choices: _types.templateIds,
|
|
103
|
-
loop: false
|
|
104
|
-
}]);
|
|
105
|
-
return template;
|
|
106
|
-
}
|
|
107
|
-
async function scaffoldProject(templateId, authCredentials) {
|
|
108
|
-
const cwd = process.cwd();
|
|
109
|
-
console.log(_chalk.default.cyan(`\n🚀 Initializing ${_chalk.default.bold(templateId)} project...\n`));
|
|
110
|
-
console.log(_chalk.default.cyan("📦 Fetching template..."));
|
|
111
|
-
const template = await fetchProjectTemplate(templateId, authCredentials);
|
|
112
|
-
console.log(_chalk.default.green(`✓ Template "${template}" fetched successfully!`));
|
|
113
|
-
console.log(_chalk.default.cyan("🔨 Creating project files..."));
|
|
114
|
-
const codeTree = template;
|
|
115
|
-
await mountFiles(cwd, codeTree);
|
|
116
|
-
console.log(_chalk.default.green("✓ Project files created!"));
|
|
117
|
-
console.log((0, _boxen.default)(_chalk.default.green(`✅ Project initialized successfully!`) + `\n\n${_chalk.default.cyan("Project details:")}` + `\n• Template: ${_chalk.default.bold(template)}` + `\n• Directory: ${_chalk.default.bold(process.cwd())}` + `\n• Workspace ID: ${_chalk.default.bold(authCredentials.workspaceId.substring(0, 5) + "...")}` + `\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 install")} to install dependencies` + `\n3. Run ${_chalk.default.bold("npm start")} to start the development server`, {
|
|
118
|
-
padding: 1,
|
|
119
|
-
margin: 1,
|
|
120
|
-
borderStyle: "round",
|
|
121
|
-
borderColor: "green"
|
|
122
|
-
}));
|
|
123
|
-
}
|
|
124
|
-
async function fetchProjectTemplate(templateId, authCredentials) {
|
|
125
|
-
const {
|
|
126
|
-
workspaceId,
|
|
127
|
-
apiKey
|
|
128
|
-
} = authCredentials;
|
|
129
|
-
const baseUrl = "https://rauf-2.intuned-team-local.com";
|
|
130
|
-
const url = `${baseUrl}/api/v1/workspace/${workspaceId}/templates/${templateId}`;
|
|
131
|
-
const headers = {
|
|
132
|
-
"x-api-key": apiKey
|
|
133
|
-
};
|
|
134
|
-
const response = await fetch(url, {
|
|
135
|
-
headers
|
|
136
|
-
});
|
|
137
|
-
if (!response.ok) {
|
|
138
|
-
throw new Error(`Error fetching template: ${response.statusText} (${response.status})`);
|
|
139
|
-
}
|
|
140
|
-
const data = await response.json();
|
|
141
|
-
if (!data) {
|
|
142
|
-
throw new Error("Template not found");
|
|
143
|
-
}
|
|
144
|
-
return data.template;
|
|
145
|
-
}
|
|
@@ -1,84 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
"use strict";
|
|
3
|
-
|
|
4
|
-
Object.defineProperty(exports, "__esModule", {
|
|
5
|
-
value: true
|
|
6
|
-
});
|
|
7
|
-
exports.executeCLI = executeCLI;
|
|
8
|
-
var _commander = require("commander");
|
|
9
|
-
var _chalk = _interopRequireDefault(require("chalk"));
|
|
10
|
-
var fs = _interopRequireWildcard(require("fs-extra"));
|
|
11
|
-
var _runApi = require("../../common/runApi");
|
|
12
|
-
var _tsNodeImport = require("../common/tsNodeImport");
|
|
13
|
-
var _utils = require("./utils");
|
|
14
|
-
var _asyncLocalStorage = require("../../common/asyncLocalStorage");
|
|
15
|
-
var _nanoid = require("nanoid");
|
|
16
|
-
var _enums = require("../../runtime/enums");
|
|
17
|
-
var _Logger = require("../../common/Logger");
|
|
18
|
-
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); }
|
|
19
|
-
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; }
|
|
20
|
-
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
21
|
-
async function executeCLI(apiName, inputData, options) {
|
|
22
|
-
const runApiResult = await (0, _runApi.runApi)({
|
|
23
|
-
automationFunction: {
|
|
24
|
-
name: `api/${apiName}`,
|
|
25
|
-
params: inputData
|
|
26
|
-
},
|
|
27
|
-
runOptions: {
|
|
28
|
-
environment: "standalone"
|
|
29
|
-
},
|
|
30
|
-
importFunction: _tsNodeImport.tsNodeImport
|
|
31
|
-
});
|
|
32
|
-
if (runApiResult.isErr()) {
|
|
33
|
-
if (runApiResult.error instanceof _runApi.AutomationError) {
|
|
34
|
-
throw runApiResult.error.error;
|
|
35
|
-
}
|
|
36
|
-
console.error(runApiResult.error);
|
|
37
|
-
throw new Error("An error occurred while running the API");
|
|
38
|
-
}
|
|
39
|
-
const {
|
|
40
|
-
result,
|
|
41
|
-
extendedPayloads: payloadToAppend
|
|
42
|
-
} = runApiResult.value;
|
|
43
|
-
const isResponseObject = typeof result === "object" && result !== null;
|
|
44
|
-
const hasMoreThank5Keys = isResponseObject && Object.keys(result).length > 5;
|
|
45
|
-
const hasNestedObjects = isResponseObject && Object.values(result).some(value => typeof value === "object");
|
|
46
|
-
const shouldWriteToFile = isResponseObject && (hasMoreThank5Keys || hasNestedObjects);
|
|
47
|
-
const resultsDir = "/tmp/run-results";
|
|
48
|
-
if (options.outputFileId && shouldWriteToFile) {
|
|
49
|
-
_Logger.logger.info(_chalk.default.underline.bgBlue.white(`Click to Open: Results saved (Run: ${options.outputFileId})`));
|
|
50
|
-
fs.ensureDirSync(resultsDir);
|
|
51
|
-
const path = `${resultsDir}/${options.outputFileId}.json`;
|
|
52
|
-
await fs.writeJson(path, result, {
|
|
53
|
-
spaces: 2
|
|
54
|
-
});
|
|
55
|
-
} else {
|
|
56
|
-
console.log("result:", result);
|
|
57
|
-
}
|
|
58
|
-
const hasPayloadToAppend = payloadToAppend && payloadToAppend.length > 0;
|
|
59
|
-
if (hasPayloadToAppend && options.outputFileId) {
|
|
60
|
-
_Logger.logger.info(_chalk.default.underline.bgBlue.white(`Click to Open: payloads to append (Run: ${options.outputFileId})`));
|
|
61
|
-
fs.ensureDirSync(resultsDir);
|
|
62
|
-
const path = `${resultsDir}/${options.outputFileId}-payloads-to-append.json`;
|
|
63
|
-
await fs.writeJson(path, payloadToAppend, {
|
|
64
|
-
spaces: 2
|
|
65
|
-
});
|
|
66
|
-
} else if (hasPayloadToAppend) {
|
|
67
|
-
_Logger.logger.info("payload to append:", payloadToAppend);
|
|
68
|
-
_Logger.logger.info("This will only take an effect if this API run was part of a job.");
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
_commander.program.name("intuned-run").description("Run an Intuned API with parameters").argument("<api-name>", "Name of the API to run").option("-p, --parameters-file <file>", "JSON file containing API parameters").option("-o, --output-file <file>", "File to write the API output to").action(async (apiName, options) => {
|
|
72
|
-
const inputData = await (0, _utils.loadParameters)(options.parametersFile);
|
|
73
|
-
try {
|
|
74
|
-
await (0, _asyncLocalStorage.runWithContext)({
|
|
75
|
-
runEnvironment: _enums.RunEnvironment.IDE,
|
|
76
|
-
extendedPayloads: [],
|
|
77
|
-
runId: (0, _nanoid.nanoid)()
|
|
78
|
-
}, () => executeCLI(apiName, inputData, options));
|
|
79
|
-
} catch (error) {
|
|
80
|
-
console.error(_chalk.default.red(`\nError: ${error.message}`));
|
|
81
|
-
process.exit(1);
|
|
82
|
-
}
|
|
83
|
-
});
|
|
84
|
-
_commander.program.parse(process.argv);
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare function loadParameters(parametersFile: string): Promise<object | null>;
|
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.loadParameters = loadParameters;
|
|
7
|
-
var _path = _interopRequireDefault(require("path"));
|
|
8
|
-
var fs = _interopRequireWildcard(require("fs-extra"));
|
|
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 && {}.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
|
-
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
12
|
-
async function loadParameters(parametersFile) {
|
|
13
|
-
if (!parametersFile) {
|
|
14
|
-
return {};
|
|
15
|
-
}
|
|
16
|
-
try {
|
|
17
|
-
const filePath = _path.default.resolve(process.cwd(), parametersFile);
|
|
18
|
-
await fs.access(filePath);
|
|
19
|
-
let inputData = null;
|
|
20
|
-
if (parametersFile) {
|
|
21
|
-
inputData = await fs.readJSON(parametersFile);
|
|
22
|
-
} else {
|
|
23
|
-
inputData = {};
|
|
24
|
-
}
|
|
25
|
-
return inputData;
|
|
26
|
-
} catch (error) {
|
|
27
|
-
if (error.code === "ENOENT") {
|
|
28
|
-
throw new Error(`Parameters file not found: ${parametersFile}`);
|
|
29
|
-
} else if (error instanceof SyntaxError) {
|
|
30
|
-
throw new Error(`Invalid JSON in parameters file: ${error.message}`);
|
|
31
|
-
}
|
|
32
|
-
throw new Error(`Error reading parameters file: ${error.message}`);
|
|
33
|
-
}
|
|
34
|
-
}
|