apify-cli 0.6.7 → 0.7.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/CHANGELOG.md +2 -0
- package/README.md +7 -7
- package/npm-shrinkwrap.json +470 -304
- package/oclif.manifest.json +1 -1
- package/package.json +15 -14
- package/src/commands/call.js +15 -8
- package/src/commands/push.js +14 -21
- package/src/commands/run.js +1 -1
- package/src/commands/vis.js +2 -2
- package/src/lib/consts.js +1 -1
- package/src/lib/files.js +1 -1
- package/src/lib/utils.js +8 -9
package/oclif.manifest.json
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":"0.
|
|
1
|
+
{"version":"0.7.0","commands":{"call":{"id":"call","description":"Runs a specific actor remotely on the Apify cloud platform.\nThe actor is run under your current Apify account, therefore you need to be logged in by calling \"apify login\". It takes input for the actor from the default local key-value store by default.","pluginName":"apify-cli","pluginType":"core","aliases":[],"flags":{"build":{"name":"build","type":"option","char":"b","description":"Tag or number of the build to run (e.g. \"latest\" or \"1.2.34\").","required":false},"timeout":{"name":"timeout","type":"option","char":"t","description":"Timeout for the actor run in seconds. Zero value means there is no timeout.","required":false},"memory":{"name":"memory","type":"option","char":"m","description":"Amount of memory allocated for the actor run, in megabytes.","required":false},"wait-for-finish":{"name":"wait-for-finish","type":"option","char":"w","description":"Seconds for waiting to run to finish, if no value passed, it waits forever.","required":false}},"args":[{"name":"actId","description":"Name or ID of the actor to run (e.g. \"apify/hello-world\" or \"E2jjCZBezvAZnX8Rb\"). If not provided, the command runs the remote actor specified in the \"apify.json\" file.","required":false}]},"create":{"id":"create","description":"Creates a new actor project directory from a selected boilerplate template.","pluginName":"apify-cli","pluginType":"core","aliases":[],"flags":{"template":{"name":"template","type":"option","char":"t","description":"Template for the actor. If not provided, the command will prompt for it.Visit https://github.com/apifytech/actor-templates/raw/master/templates/manifest.json to find available template names.","required":false}},"args":[{"name":"actorName","description":"Name of the actor and its directory","required":false}]},"info":{"id":"info","description":"Displays information about the currently active Apify account.\nThe information is printed to the console.","pluginName":"apify-cli","pluginType":"core","aliases":[],"flags":{},"args":[]},"init":{"id":"init","description":"Initializes a new actor project in an existing directory.\nThe command only creates the \"apify.json\" file and the \"apify_storage\" directory in the current directory, but will not touch anything else.\n\nWARNING: The directory at \"apify_storage\" will be overwritten if it already exists.","pluginName":"apify-cli","pluginType":"core","aliases":[],"flags":{},"args":[{"name":"actorName","description":"Name of the actor. If not provided, you will be prompted for it.","required":false}]},"login":{"id":"login","description":"Logs in to your Apify account using a provided API token.\nThe API token and other account information is stored in the ~/.apify directory, from where it is read by all other \"apify\" commands. To log out, call \"apify logout\".","pluginName":"apify-cli","pluginType":"core","aliases":[],"flags":{"token":{"name":"token","type":"option","char":"t","description":"[Optional] Apify API token","required":false}},"args":[]},"logout":{"id":"logout","description":"Logs out of your Apify account.\nThe command deletes the API token and all other account information stored in the ~/.apify directory. To log in again, call \"apify login\".","pluginName":"apify-cli","pluginType":"core","aliases":[],"flags":{},"args":[]},"push":{"id":"push","description":"Uploads the actor to the Apify platform and builds it there.\nThe actor settings are read from the \"apify.json\" file in the current directory, but they can be overridden using command-line options.\nNOTE: If the source files are smaller than 3 MB then they are uploaded as \n\"Multiple source files\", otherwise they are uploaded as \"Zip file\".\n\nWARNING: If the target actor already exists in your Apify account, it will be overwritten!","pluginName":"apify-cli","pluginType":"core","aliases":[],"flags":{"version-number":{"name":"version-number","type":"option","description":"DEPRECATED: Use flag version instead. Actor version number to which the files should be pushed. By default, it is taken from the \"apify.json\" file.","required":false},"version":{"name":"version","type":"option","char":"v","description":"Actor version number to which the files should be pushed. By default, it is taken from the \"apify.json\" file.","required":false},"build-tag":{"name":"build-tag","type":"option","char":"b","description":"Build tag to be applied to the successful actor build. By default, it is taken from the \"apify.json\" file","required":false},"wait-for-finish":{"name":"wait-for-finish","type":"option","char":"w","description":"Seconds for waiting to build to finish, if no value passed, it waits forever.","required":false}},"args":[{"name":"actorId","description":"ID of an existing actor on the Apify platform where the files will be pushed. If not provided, the command will create or modify the actor with the name specified in \"apify.json\" file.","required":false}]},"run":{"id":"run","description":"Runs the actor locally in the current directory by executing \"npm start\".\nIt sets various APIFY_XYZ environment variables in order to provide a working execution environment for the actor. For example, this causes the actor input, as well as all other data in key-value stores, datasets or request queues to be stored in the \"apify_storage\" directory, rather than on the Apify platform.\n\nNOTE: You can override the default behaviour of command overriding npm start script value in a package.json file. You can set up your own main file or environment variables by changing it.","pluginName":"apify-cli","pluginType":"core","aliases":[],"flags":{"purge":{"name":"purge","type":"boolean","char":"p","description":"Shortcut that combines the --purge-queue, --purge-dataset and --purge-key-value-store options.","required":false,"allowNo":false},"purge-queue":{"name":"purge-queue","type":"boolean","description":"Deletes the local directory containing the default request queue before the run starts.","required":false,"allowNo":false},"purge-dataset":{"name":"purge-dataset","type":"boolean","description":"Deletes the local directory containing the default dataset before the run starts.","required":false,"allowNo":false},"purge-key-value-store":{"name":"purge-key-value-store","type":"boolean","description":"Deletes all records from the default key-value store in the local directory before the run starts, except for the \"INPUT\" key.","required":false,"allowNo":false}},"args":[]},"vis":{"id":"vis","description":"Validates INPUT_SCHEMA.json file and prints errors found.","pluginName":"apify-cli","pluginType":"core","aliases":[],"flags":{},"args":[{"name":"path","description":"Optional path to your INPUT_SCHEMA.json file. If not provided ./INPUT_SCHEMA.json is used.","required":false}]},"secrets:add":{"id":"secrets:add","description":"Adds a new secret value.\nThe secrets are stored to a file at ~/.apify","pluginName":"apify-cli","pluginType":"core","aliases":[],"flags":{},"args":[{"name":"name","description":"Name of the secret","required":true},{"name":"value","description":"Value of the secret","required":true}]},"secrets":{"id":"secrets","description":"Manages secret values for actor environment variables.\n\nExample:\n$ apify secrets:add mySecret TopSecretValue123\n\nNow the \"mySecret\" value can be used in an environment variable defined in \"apify.json\" file by adding the \"@\" prefix:\n\n{\n \"name\": \"my_actor\",\n \"env\": { \"SECRET_ENV_VAR\": \"@mySecret\" },\n \"version\": \"0.1\n}\n\nWhen the actor is pushed to Apify cloud, the \"SECRET_ENV_VAR\" and its value is stored as a secret environment variable of the actor.","pluginName":"apify-cli","pluginType":"core","aliases":[],"flags":{},"args":[]},"secrets:rm":{"id":"secrets:rm","description":"Removes the secret.","pluginName":"apify-cli","pluginType":"core","aliases":[],"flags":{},"args":[{"name":"name","description":"Name of the secret","required":true}]}}}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "apify-cli",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.7.0",
|
|
4
4
|
"description": "Apify command-line interface helps you create, develop, build and run Apify actors, and manage the Apify cloud platform.",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -48,24 +48,25 @@
|
|
|
48
48
|
},
|
|
49
49
|
"homepage": "https://github.com/apify/apify-cli#readme",
|
|
50
50
|
"engines": {
|
|
51
|
-
"node": ">=
|
|
51
|
+
"node": ">=12.0.0"
|
|
52
52
|
},
|
|
53
53
|
"dependencies": {
|
|
54
54
|
"@apify/actor-templates": "^0.1.1",
|
|
55
|
+
"@apify/consts": "^1.7.0",
|
|
55
56
|
"@apify/http-request": "^2.1.2",
|
|
56
|
-
"@
|
|
57
|
-
"@oclif/
|
|
57
|
+
"@apify/input_schema": "^2.0.8",
|
|
58
|
+
"@oclif/command": "^1.8.16",
|
|
59
|
+
"@oclif/config": "^1.18.3",
|
|
58
60
|
"@oclif/errors": "^1.3.5",
|
|
59
|
-
"@oclif/plugin-commands": "^1.
|
|
60
|
-
"@oclif/plugin-help": "^
|
|
61
|
-
"ajv": "^
|
|
62
|
-
"apify-client": "^
|
|
63
|
-
"apify-shared": "^0.6.3",
|
|
61
|
+
"@oclif/plugin-commands": "^2.1.0",
|
|
62
|
+
"@oclif/plugin-help": "^5.1.12",
|
|
63
|
+
"ajv": "^8.10.0",
|
|
64
|
+
"apify-client": "^2.2.0",
|
|
64
65
|
"archiver-promise": "^1.0.0",
|
|
65
66
|
"chalk": "^4.1.2",
|
|
66
67
|
"child-process-promise": "^2.2.1",
|
|
67
68
|
"extract-zip": "^2.0.1",
|
|
68
|
-
"globby": "^11.0
|
|
69
|
+
"globby": "^11.1.0",
|
|
69
70
|
"inquirer": "^7.3.3",
|
|
70
71
|
"is-online": "^9.0.1",
|
|
71
72
|
"load-json-file": "^6.2.0",
|
|
@@ -73,17 +74,17 @@
|
|
|
73
74
|
"minimist": "^1.2.5",
|
|
74
75
|
"rimraf": "^3.0.2",
|
|
75
76
|
"semver": "^7.3.5",
|
|
76
|
-
"underscore": "^1.13.
|
|
77
|
+
"underscore": "^1.13.2",
|
|
77
78
|
"unzipper": "^0.10.11",
|
|
78
79
|
"write-json-file": "^4.3.0"
|
|
79
80
|
},
|
|
80
81
|
"devDependencies": {
|
|
81
|
-
"@apify/eslint-config": "^0.
|
|
82
|
+
"@apify/eslint-config": "^0.2.3",
|
|
82
83
|
"@oclif/dev-cli": "^1.26.0",
|
|
83
|
-
"@oclif/test": "^1.
|
|
84
|
+
"@oclif/test": "^2.1.0",
|
|
84
85
|
"chai": "^4.3.4",
|
|
85
86
|
"chai-as-promised": "^7.1.1",
|
|
86
|
-
"eslint": "^
|
|
87
|
+
"eslint": "^8.11.0",
|
|
87
88
|
"mocha": "^8.4.0",
|
|
88
89
|
"sinon": "^9.2.4"
|
|
89
90
|
},
|
package/src/commands/call.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
const { flags: flagsHelper } = require('@oclif/command');
|
|
2
|
-
const { ACT_JOB_STATUSES } = require('apify
|
|
2
|
+
const { ACT_JOB_STATUSES } = require('@apify/consts');
|
|
3
|
+
const mime = require('mime');
|
|
3
4
|
const { ApifyCommand } = require('../lib/apify_command');
|
|
4
5
|
const { getLocalConfig, getLoggedClientOrThrow,
|
|
5
6
|
getLocalUserInfo, getLocalInput, outputJobLog } = require('../lib/utils');
|
|
@@ -21,12 +22,12 @@ class CallCommand extends ApifyCommand {
|
|
|
21
22
|
const forceActorId = args.actId;
|
|
22
23
|
let actorId;
|
|
23
24
|
if (forceActorId) {
|
|
24
|
-
const actor = await apifyClient.
|
|
25
|
+
const actor = await apifyClient.actor(forceActorId).get();
|
|
25
26
|
if (!actor) throw new Error(`Cannot find actor with ID '${forceActorId}' in your account.`);
|
|
26
27
|
actorId = actor.username ? `${actor.username}/${actor.name}` : actor.id;
|
|
27
28
|
} else {
|
|
28
29
|
actorId = `${usernameOrId}/${localConfig.name}`;
|
|
29
|
-
const actor = await apifyClient.
|
|
30
|
+
const actor = await apifyClient.actor(actorId).get();
|
|
30
31
|
if (!actor) {
|
|
31
32
|
throw new Error(`Cannot find actor with ID '${actorId}' `
|
|
32
33
|
+ 'in your account. Call "apify push" to push this actor to Apify platform.');
|
|
@@ -34,7 +35,6 @@ class CallCommand extends ApifyCommand {
|
|
|
34
35
|
}
|
|
35
36
|
|
|
36
37
|
const runOpts = {
|
|
37
|
-
actId: actorId,
|
|
38
38
|
waitForFinish: 2, // NOTE: We need to wait some time to Apify open stream and we can create connection
|
|
39
39
|
};
|
|
40
40
|
const waitForFinishMillis = Number.isNaN(flags.waitForFinish)
|
|
@@ -47,13 +47,20 @@ class CallCommand extends ApifyCommand {
|
|
|
47
47
|
|
|
48
48
|
// Get input for act
|
|
49
49
|
const localInput = getLocalInput();
|
|
50
|
-
if (localInput) Object.assign(runOpts, localInput);
|
|
51
50
|
|
|
52
|
-
outputs.run(`Calling actor ${
|
|
51
|
+
outputs.run(`Calling actor ${actorId}`);
|
|
53
52
|
|
|
54
53
|
let run;
|
|
55
54
|
try {
|
|
56
|
-
|
|
55
|
+
if (localInput) {
|
|
56
|
+
// TODO: For some reason we cannot pass json as buffer with right contentType into apify-client.
|
|
57
|
+
// It will save malformed JSON which looks like buffer as INPUT.
|
|
58
|
+
// We need to fix this in v1 during removing call under actor namespace.
|
|
59
|
+
const input = mime.getExtension(localInput.contentType) === 'json' ? JSON.parse(localInput.body.toString('utf-8')) : localInput.body;
|
|
60
|
+
run = await apifyClient.actor(actorId).start(input, { ...runOpts, contentType: localInput.contentType });
|
|
61
|
+
} else {
|
|
62
|
+
run = await apifyClient.actor(actorId).start(null, runOpts);
|
|
63
|
+
}
|
|
57
64
|
} catch (err) {
|
|
58
65
|
// TODO: Better error message in apify-client-js
|
|
59
66
|
if (err.type === 'record-not-found') throw new Error(`Actor ${runOpts.actId} not found!`);
|
|
@@ -67,7 +74,7 @@ class CallCommand extends ApifyCommand {
|
|
|
67
74
|
console.error(err);
|
|
68
75
|
}
|
|
69
76
|
|
|
70
|
-
run = await apifyClient.
|
|
77
|
+
run = await apifyClient.run(run.id).get();
|
|
71
78
|
console.dir(run);
|
|
72
79
|
|
|
73
80
|
outputs.link('Actor run detail', `https://console.apify.com/actors/${run.actId}#/runs/${run.id}`);
|
package/src/commands/push.js
CHANGED
|
@@ -2,7 +2,7 @@ const fs = require('fs');
|
|
|
2
2
|
const { flags: flagsHelper } = require('@oclif/command');
|
|
3
3
|
const actorTemplates = require('@apify/actor-templates');
|
|
4
4
|
const { ACT_JOB_STATUSES, ACT_SOURCE_TYPES,
|
|
5
|
-
MAX_MULTIFILE_BYTES } = require('apify
|
|
5
|
+
MAX_MULTIFILE_BYTES } = require('@apify/consts');
|
|
6
6
|
const { ApifyCommand } = require('../lib/apify_command');
|
|
7
7
|
const { createActZip, getLoggedClientOrThrow,
|
|
8
8
|
outputJobLog, getLocalUserInfo, getActorLocalFilePaths,
|
|
@@ -33,12 +33,12 @@ class PushCommand extends ApifyCommand {
|
|
|
33
33
|
// It causes that we push actor to this id but attributes in localConfig will remain same.
|
|
34
34
|
const forceActorId = args.actorId;
|
|
35
35
|
if (forceActorId) {
|
|
36
|
-
actor = await apifyClient.
|
|
36
|
+
actor = await apifyClient.actor(forceActorId).get();
|
|
37
37
|
if (!actor) throw new Error(`Cannot find actor with ID '${forceActorId}' in your account.`);
|
|
38
38
|
actorId = actor.id;
|
|
39
39
|
} else {
|
|
40
40
|
const usernameOrId = userInfo.username || userInfo.id;
|
|
41
|
-
actor = await apifyClient.
|
|
41
|
+
actor = await apifyClient.actor(`${usernameOrId}/${localConfig.name}`).get();
|
|
42
42
|
if (actor) {
|
|
43
43
|
actorId = actor.id;
|
|
44
44
|
} else {
|
|
@@ -55,7 +55,7 @@ class PushCommand extends ApifyCommand {
|
|
|
55
55
|
tarballUrl: actorTemplate.archiveUrl,
|
|
56
56
|
}],
|
|
57
57
|
};
|
|
58
|
-
actor = await apifyClient.
|
|
58
|
+
actor = await apifyClient.actors().create(newActor);
|
|
59
59
|
actorId = actor.id;
|
|
60
60
|
outputs.info(`Created actor with name ${localConfig.name} on Apify.`);
|
|
61
61
|
console.dir(actor);
|
|
@@ -66,6 +66,7 @@ class PushCommand extends ApifyCommand {
|
|
|
66
66
|
|
|
67
67
|
const filePathsToPush = await getActorLocalFilePaths();
|
|
68
68
|
const filesSize = await sumFilesSizeInBytes(filePathsToPush);
|
|
69
|
+
const actorClient = apifyClient.actor(actorId);
|
|
69
70
|
|
|
70
71
|
let sourceType;
|
|
71
72
|
let sourceFiles;
|
|
@@ -79,13 +80,12 @@ class PushCommand extends ApifyCommand {
|
|
|
79
80
|
await createActZip(TEMP_ZIP_FILE_NAME, filePathsToPush);
|
|
80
81
|
|
|
81
82
|
// Upload it to Apify.keyValueStores
|
|
82
|
-
const store = await apifyClient.keyValueStores.
|
|
83
|
+
const store = await apifyClient.keyValueStores().getOrCreate(UPLOADS_STORE_NAME);
|
|
83
84
|
const key = `${actor.name}-${version}.zip`;
|
|
84
85
|
const buffer = fs.readFileSync(TEMP_ZIP_FILE_NAME);
|
|
85
|
-
await apifyClient.
|
|
86
|
-
storeId: store.id,
|
|
86
|
+
await apifyClient.keyValueStore(store.id).setRecord({
|
|
87
87
|
key,
|
|
88
|
-
|
|
88
|
+
value: buffer,
|
|
89
89
|
contentType: 'application/zip',
|
|
90
90
|
});
|
|
91
91
|
fs.unlinkSync(TEMP_ZIP_FILE_NAME);
|
|
@@ -94,15 +94,11 @@ class PushCommand extends ApifyCommand {
|
|
|
94
94
|
}
|
|
95
95
|
|
|
96
96
|
// Update actor version
|
|
97
|
-
const actorCurrentVersion = await
|
|
97
|
+
const actorCurrentVersion = await actorClient.version(version).get();
|
|
98
98
|
if (actorCurrentVersion) {
|
|
99
99
|
const actorVersionModifier = { tarballUrl, sourceFiles, buildTag, sourceType };
|
|
100
100
|
if (localConfig.env) actorVersionModifier.envVars = transformEnvToEnvVars(localConfig.env);
|
|
101
|
-
await
|
|
102
|
-
actId: actorId,
|
|
103
|
-
versionNumber: version,
|
|
104
|
-
actVersion: actorVersionModifier,
|
|
105
|
-
});
|
|
101
|
+
await actorClient.version(version).update(actorVersionModifier);
|
|
106
102
|
outputs.run(`Updated version ${version} for ${actor.name} actor.`);
|
|
107
103
|
} else {
|
|
108
104
|
const actorNewVersion = {
|
|
@@ -113,19 +109,16 @@ class PushCommand extends ApifyCommand {
|
|
|
113
109
|
sourceType,
|
|
114
110
|
};
|
|
115
111
|
if (localConfig.env) actorNewVersion.envVars = transformEnvToEnvVars(localConfig.env);
|
|
116
|
-
await
|
|
117
|
-
actId: actorId,
|
|
112
|
+
await actorClient.versions().create({
|
|
118
113
|
versionNumber: version,
|
|
119
|
-
|
|
114
|
+
...actorNewVersion,
|
|
120
115
|
});
|
|
121
116
|
outputs.run(`Created version ${version} for ${actor.name} actor.`);
|
|
122
117
|
}
|
|
123
118
|
|
|
124
119
|
// Build actor on Apify and wait for build to finish
|
|
125
120
|
outputs.run(`Building actor ${actor.name}`);
|
|
126
|
-
let build = await
|
|
127
|
-
actId: actorId,
|
|
128
|
-
version,
|
|
121
|
+
let build = await actorClient.build(version, {
|
|
129
122
|
useCache: true,
|
|
130
123
|
waitForFinish: 2, // NOTE: We need to wait some time to Apify open stream and we can create connection
|
|
131
124
|
});
|
|
@@ -137,7 +130,7 @@ class PushCommand extends ApifyCommand {
|
|
|
137
130
|
console.error(err);
|
|
138
131
|
}
|
|
139
132
|
|
|
140
|
-
build = await apifyClient.
|
|
133
|
+
build = await apifyClient.build(build.id).get();
|
|
141
134
|
console.dir(build);
|
|
142
135
|
|
|
143
136
|
outputs.link('Actor build detail', `https://console.apify.com/actors/${build.actId}#/builds/${build.buildNumber}`);
|
package/src/commands/run.js
CHANGED
|
@@ -2,7 +2,7 @@ const { flags: flagsHelper } = require('@oclif/command');
|
|
|
2
2
|
const fs = require('fs');
|
|
3
3
|
const path = require('path');
|
|
4
4
|
const loadJson = require('load-json-file');
|
|
5
|
-
const { ENV_VARS } = require('apify
|
|
5
|
+
const { ENV_VARS } = require('@apify/consts');
|
|
6
6
|
const semver = require('semver');
|
|
7
7
|
const execWithLog = require('../lib/exec');
|
|
8
8
|
const { DEFAULT_LOCAL_STORAGE_DIR, SUPPORTED_NODEJS_VERSION } = require('../lib/consts');
|
package/src/commands/vis.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
const { validateInputSchema } = require('apify
|
|
1
|
+
const { validateInputSchema } = require('@apify/input_schema');
|
|
2
2
|
const Ajv = require('ajv');
|
|
3
3
|
const fs = require('fs');
|
|
4
4
|
const { ApifyCommand } = require('../lib/apify_command');
|
|
@@ -10,7 +10,7 @@ class ValidateInputSchemaCommand extends ApifyCommand {
|
|
|
10
10
|
async run() {
|
|
11
11
|
const { args } = this.parse(ValidateInputSchemaCommand);
|
|
12
12
|
const { path = DEFAULT_INPUT_SCHEMA_PATH } = args;
|
|
13
|
-
const validator = new Ajv({ cache: false });
|
|
13
|
+
const validator = new Ajv({ cache: false, strict: false });
|
|
14
14
|
|
|
15
15
|
let inputSchemaObj;
|
|
16
16
|
|
package/src/lib/consts.js
CHANGED
package/src/lib/files.js
CHANGED
|
@@ -4,7 +4,7 @@ const fs = require('fs');
|
|
|
4
4
|
const path = require('path');
|
|
5
5
|
const rimraf = require('rimraf');
|
|
6
6
|
|
|
7
|
-
const updateLocalJson = async (jsonFilePath, updateAttrs = {}, nestedObjectAttr) => {
|
|
7
|
+
const updateLocalJson = async (jsonFilePath, updateAttrs = {}, nestedObjectAttr = null) => {
|
|
8
8
|
const currentObject = await loadJson(jsonFilePath);
|
|
9
9
|
let newObject;
|
|
10
10
|
|
package/src/lib/utils.js
CHANGED
|
@@ -8,9 +8,9 @@ const loadJson = require('load-json-file');
|
|
|
8
8
|
const writeJson = require('write-json-file');
|
|
9
9
|
const inquirer = require('inquirer');
|
|
10
10
|
const { LOCAL_STORAGE_SUBDIRS, ENV_VARS, LOCAL_ENV_VARS,
|
|
11
|
-
KEY_VALUE_STORE_KEYS, ACT_JOB_TERMINAL_STATUSES, SOURCE_FILE_FORMATS, ACTOR_NAME } = require('apify
|
|
11
|
+
KEY_VALUE_STORE_KEYS, ACT_JOB_TERMINAL_STATUSES, SOURCE_FILE_FORMATS, ACTOR_NAME } = require('@apify/consts');
|
|
12
12
|
const https = require('https');
|
|
13
|
-
const ApifyClient = require('apify-client');
|
|
13
|
+
const { ApifyClient } = require('apify-client');
|
|
14
14
|
const { execSync, spawnSync } = require('child_process');
|
|
15
15
|
const semver = require('semver');
|
|
16
16
|
const isOnline = require('is-online');
|
|
@@ -73,15 +73,14 @@ const getLoggedClientOrThrow = async () => {
|
|
|
73
73
|
* @return {Promise<*>}
|
|
74
74
|
*/
|
|
75
75
|
const getLoggedClient = async (token) => {
|
|
76
|
-
let userInfo;
|
|
77
|
-
const apifyClient = new ApifyClient();
|
|
78
|
-
|
|
79
76
|
if (!token && fs.existsSync(GLOBAL_CONFIGS_FOLDER) && fs.existsSync(AUTH_FILE_PATH)) {
|
|
80
77
|
({ token } = loadJson.sync(AUTH_FILE_PATH));
|
|
81
78
|
}
|
|
82
79
|
|
|
80
|
+
const apifyClient = new ApifyClient({ token });
|
|
81
|
+
let userInfo;
|
|
83
82
|
try {
|
|
84
|
-
userInfo = await apifyClient.
|
|
83
|
+
userInfo = await apifyClient.user('me').get();
|
|
85
84
|
} catch (e) {
|
|
86
85
|
return false;
|
|
87
86
|
}
|
|
@@ -89,7 +88,6 @@ const getLoggedClient = async (token) => {
|
|
|
89
88
|
// Always refresh Auth file
|
|
90
89
|
if (!fs.existsSync(GLOBAL_CONFIGS_FOLDER)) fs.mkdirSync(GLOBAL_CONFIGS_FOLDER);
|
|
91
90
|
writeJson.sync(AUTH_FILE_PATH, { token, ...userInfo });
|
|
92
|
-
apifyClient.setOptions({ token, userId: userInfo.id });
|
|
93
91
|
return apifyClient;
|
|
94
92
|
};
|
|
95
93
|
|
|
@@ -305,12 +303,13 @@ const outputJobLog = async (job, jobStatus, timeout) => {
|
|
|
305
303
|
const { id: logId, status } = job;
|
|
306
304
|
// In case job was already done just output log
|
|
307
305
|
if (ACT_JOB_TERMINAL_STATUSES.includes(status)) {
|
|
308
|
-
const
|
|
309
|
-
const log = await
|
|
306
|
+
const apifyClient = new ApifyClient();
|
|
307
|
+
const log = await apifyClient.log(logId).get();
|
|
310
308
|
process.stdout.write(log);
|
|
311
309
|
}
|
|
312
310
|
|
|
313
311
|
// In other case stream it to stdout
|
|
312
|
+
// TODO: Use apifyClient.log(logId).stream() instead of http request stream.
|
|
314
313
|
return new Promise((resolve, reject) => {
|
|
315
314
|
const req = https.get(`https://api.apify.com/v2/logs/${logId}?stream=1`);
|
|
316
315
|
let res;
|