@intuned/runtime-dev 1.0.6-cli.8.3.4 → 1.0.6-dev
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/bin/intuned-run +3 -0
- package/dist/commands/deploy/deploy.js +11 -24
- package/dist/commands/deploy/utils.d.ts +2 -11
- package/dist/commands/deploy/utils.js +65 -211
- package/dist/commands/init/init.js +4 -3
- package/dist/{common/cli → commands/init}/types.js +1 -1
- package/dist/commands/init/utils.d.ts +3 -3
- package/dist/commands/init/utils.js +24 -57
- package/dist/commands/intuned-run/intuned-run.d.ts +4 -0
- package/dist/commands/intuned-run/intuned-run.js +84 -0
- package/dist/commands/intuned-run/utils.d.ts +1 -0
- package/dist/{common/cli → commands/intuned-run}/utils.js +21 -18
- package/dist/common/asyncLocalStorage/index.d.ts +1 -1
- package/dist/common/asyncLocalStorage/index.js +2 -2
- package/my-intuned-project/Intuned.json +15 -0
- package/my-intuned-project/api/book-details.ts +46 -0
- package/my-intuned-project/api/books-all.ts +68 -0
- package/my-intuned-project/package.json +36 -0
- package/my-intuned-project/params/bookInput.json +3 -0
- package/my-intuned-project/yarn.lock +4539 -0
- package/package.json +5 -11
- package/bin/cli-build +0 -3
- package/bin/run-api +0 -3
- package/dist/commands/cli-build/cli-build.d.ts +0 -2
- package/dist/commands/cli-build/cli-build.js +0 -20
- package/dist/commands/common/projectExclusions.d.ts +0 -2
- package/dist/commands/common/projectExclusions.js +0 -8
- package/dist/commands/run-api-cli/run-api.d.ts +0 -2
- package/dist/commands/run-api-cli/run-api.js +0 -48
- package/dist/commands/run-api-cli/utils.d.ts +0 -7
- package/dist/commands/run-api-cli/utils.js +0 -94
- package/dist/common/cli/cliReadme.d.ts +0 -1
- package/dist/common/cli/cliReadme.js +0 -65
- package/dist/common/cli/constants.d.ts +0 -24
- package/dist/common/cli/constants.js +0 -30
- package/dist/common/cli/utils.d.ts +0 -5
- /package/bin/{deploy → intuned-deploy} +0 -0
- /package/bin/{init → intuned-init} +0 -0
- /package/dist/{common/cli → commands/init}/types.d.ts +0 -0
|
@@ -0,0 +1,84 @@
|
|
|
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);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function loadParameters(parametersFile: string): Promise<object | null>;
|
|
@@ -3,29 +3,32 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.
|
|
7
|
-
exports.getSettingIntunedJSON = getSettingIntunedJSON;
|
|
6
|
+
exports.loadParameters = loadParameters;
|
|
8
7
|
var _path = _interopRequireDefault(require("path"));
|
|
9
8
|
var fs = _interopRequireWildcard(require("fs-extra"));
|
|
10
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); }
|
|
11
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; }
|
|
12
11
|
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
13
|
-
async function
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
if (!workspaceId || !apiKey) {
|
|
17
|
-
throw new Error("Authentication details are required. Please provide them via command line options(api key, workspace id), intuned.json(workspace id) or environment variables(api key).");
|
|
12
|
+
async function loadParameters(parametersFile) {
|
|
13
|
+
if (!parametersFile) {
|
|
14
|
+
return {};
|
|
18
15
|
}
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
return
|
|
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}`);
|
|
29
33
|
}
|
|
30
|
-
return null;
|
|
31
34
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
|
-
import { AsyncLocalStorage } from "
|
|
2
|
+
import { AsyncLocalStorage } from "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
|
|
10
|
-
const asyncLocalStorage = exports.asyncLocalStorage = new
|
|
9
|
+
var _async_hooks = require("async_hooks");
|
|
10
|
+
const asyncLocalStorage = exports.asyncLocalStorage = new _async_hooks.AsyncLocalStorage();
|
|
11
11
|
function runWithContext(contextData, callback, ...args) {
|
|
12
12
|
return asyncLocalStorage.run(contextData, callback, ...args);
|
|
13
13
|
}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { BrowserContext, Page } from "playwright-core";
|
|
2
|
+
import { extendPlaywrightPage } from "@intuned/sdk/playwright";
|
|
3
|
+
|
|
4
|
+
interface Params {
|
|
5
|
+
bookFullUrl: string;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
export default async function handler(
|
|
9
|
+
params: Params,
|
|
10
|
+
_playwrightPage: Page,
|
|
11
|
+
context: BrowserContext
|
|
12
|
+
) {
|
|
13
|
+
const page = extendPlaywrightPage(_playwrightPage);
|
|
14
|
+
|
|
15
|
+
console.log(params);
|
|
16
|
+
// go to the url that is passed in the params
|
|
17
|
+
await page.goto(params.bookFullUrl);
|
|
18
|
+
|
|
19
|
+
// optimized extractor!
|
|
20
|
+
// for more info checkout
|
|
21
|
+
// https://docs.intunedhq.com/docs/data-extraction/web-data-extraction
|
|
22
|
+
const result = await page.extractObjectOptimized({
|
|
23
|
+
label: "book-deatils",
|
|
24
|
+
entityName: "book_info",
|
|
25
|
+
entitySchema: {
|
|
26
|
+
type: "object",
|
|
27
|
+
properties: {
|
|
28
|
+
name: {
|
|
29
|
+
type: "string",
|
|
30
|
+
description: "book name",
|
|
31
|
+
},
|
|
32
|
+
upc: {
|
|
33
|
+
type: "string",
|
|
34
|
+
description: "upc of the book",
|
|
35
|
+
},
|
|
36
|
+
numberOfReviews: {
|
|
37
|
+
type: "string",
|
|
38
|
+
description: "Number of reviews on the book",
|
|
39
|
+
},
|
|
40
|
+
},
|
|
41
|
+
required: ["name", "upc"],
|
|
42
|
+
},
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
return result;
|
|
46
|
+
}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { BrowserContext, Page } from "playwright-core";
|
|
2
|
+
import { extendPlaywrightPage } from "@intuned/sdk/playwright";
|
|
3
|
+
import { extendPayload } from "@intuned/sdk/runtime";
|
|
4
|
+
import { AsyncLocalStorage } from "async_hooks";
|
|
5
|
+
|
|
6
|
+
interface Params {
|
|
7
|
+
// Add your params here
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export default async function handler(
|
|
11
|
+
params: Params,
|
|
12
|
+
_playwrightPage: Page,
|
|
13
|
+
context: BrowserContext
|
|
14
|
+
) {
|
|
15
|
+
// extends playwright page with Intuned helpers.
|
|
16
|
+
const page = extendPlaywrightPage(_playwrightPage);
|
|
17
|
+
|
|
18
|
+
await page.goto("https://books.toscrape.com/");
|
|
19
|
+
|
|
20
|
+
// optimized extractor!
|
|
21
|
+
// for more info checkout
|
|
22
|
+
// https://docs.intunedhq.com/docs/data-extraction/web-data-extraction
|
|
23
|
+
const result = await page.extractArrayOptimized({
|
|
24
|
+
itemEntityName: "book",
|
|
25
|
+
label: "books-scraper",
|
|
26
|
+
itemEntitySchema: {
|
|
27
|
+
type: "object",
|
|
28
|
+
properties: {
|
|
29
|
+
name: {
|
|
30
|
+
type: "string",
|
|
31
|
+
description: "name of the book",
|
|
32
|
+
primary: true,
|
|
33
|
+
},
|
|
34
|
+
bookUrl: {
|
|
35
|
+
type: "string",
|
|
36
|
+
description: "url of the book",
|
|
37
|
+
},
|
|
38
|
+
},
|
|
39
|
+
required: ["name", "bookUrl"],
|
|
40
|
+
},
|
|
41
|
+
// you can change the model and strategy type,
|
|
42
|
+
// for links, HTML is the right strategy to use
|
|
43
|
+
strategy: {
|
|
44
|
+
type: "HTML",
|
|
45
|
+
model: "claude-3-sonnet",
|
|
46
|
+
},
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
console.log(result);
|
|
50
|
+
|
|
51
|
+
extendPayload({
|
|
52
|
+
api: "book-details",
|
|
53
|
+
parameters: {
|
|
54
|
+
bookFullUrl: `${page.url()}${result[0].bookUrl}`,
|
|
55
|
+
},
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
// // for each book on the main page, schedule api to get details
|
|
59
|
+
// result.forEach((book) => {
|
|
60
|
+
// // Extend job payload so it runs API `book-details` with provided params
|
|
61
|
+
// extendPayload({
|
|
62
|
+
// api: "book-details",
|
|
63
|
+
// parameters: {
|
|
64
|
+
// bookFullUrl: `${page.url()}${book.bookUrl}`,
|
|
65
|
+
// },
|
|
66
|
+
// });
|
|
67
|
+
// });
|
|
68
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "Nested-Scheduling",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "project uses nested scheduling feature",
|
|
5
|
+
"tags": [
|
|
6
|
+
"Scrapper"
|
|
7
|
+
],
|
|
8
|
+
"main": "index.js",
|
|
9
|
+
"scripts": {
|
|
10
|
+
"dev:local": "intuned-api-run sample playwright -j '{}'",
|
|
11
|
+
"dev": "intuned-api-run",
|
|
12
|
+
"debug": "node --inspect-brk ./node_modules/.bin/intuned-api-run",
|
|
13
|
+
"build": "intuned-build",
|
|
14
|
+
"types-check": "intuned-ts-check",
|
|
15
|
+
"pre-publish": "intuned-ts-check && intuned-build",
|
|
16
|
+
"start": "node ./output/bundle_v2.js",
|
|
17
|
+
"browser-save-state": "intuned-browser-save-state",
|
|
18
|
+
"auth-session-check": "intuned-auth-session-check",
|
|
19
|
+
"auth-session-create": "intuned-auth-session-create",
|
|
20
|
+
"auth-session-refresh": "intuned-auth-session-refresh",
|
|
21
|
+
"auth-session-load": "intuned-auth-session-load"
|
|
22
|
+
},
|
|
23
|
+
"author": "",
|
|
24
|
+
"license": "ISC",
|
|
25
|
+
"dependencies": {
|
|
26
|
+
"@intuned/runtime": "1.0.5",
|
|
27
|
+
"@intuned/sdk": "2.0.2",
|
|
28
|
+
"@types/intuned__sdk": "npm:@intuned/sdk-types@2.0.2",
|
|
29
|
+
"@types/node": "^20.10.3",
|
|
30
|
+
"axios": "^1.9.0",
|
|
31
|
+
"lodash": "^4.17.21",
|
|
32
|
+
"playwright": "1.44.1",
|
|
33
|
+
"playwright-core": "1.44.1",
|
|
34
|
+
"ts-node": "^10.9.2"
|
|
35
|
+
}
|
|
36
|
+
}
|