apify-cli 1.0.0-beta.4 → 1.0.0-beta.41

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 (46) hide show
  1. package/CHANGELOG.md +200 -0
  2. package/README.md +66 -56
  3. package/bin/dev.js +7 -2
  4. package/bin/dev.sh +4 -0
  5. package/bin/run.js +7 -0
  6. package/dist/.tsbuildinfo +1 -1
  7. package/dist/commands/actor/push-data.js +2 -2
  8. package/dist/commands/actor/set-value.js +3 -3
  9. package/dist/commands/actor/set-value.js.map +1 -1
  10. package/dist/commands/call.d.ts +1 -0
  11. package/dist/commands/call.d.ts.map +1 -1
  12. package/dist/commands/call.js +48 -19
  13. package/dist/commands/call.js.map +1 -1
  14. package/dist/commands/create.d.ts +1 -0
  15. package/dist/commands/create.d.ts.map +1 -1
  16. package/dist/commands/create.js +10 -1
  17. package/dist/commands/create.js.map +1 -1
  18. package/dist/commands/login.d.ts +1 -0
  19. package/dist/commands/login.d.ts.map +1 -1
  20. package/dist/commands/login.js +143 -12
  21. package/dist/commands/login.js.map +1 -1
  22. package/dist/commands/push.d.ts +2 -0
  23. package/dist/commands/push.d.ts.map +1 -1
  24. package/dist/commands/push.js +33 -3
  25. package/dist/commands/push.js.map +1 -1
  26. package/dist/commands/run.d.ts +1 -0
  27. package/dist/commands/run.d.ts.map +1 -1
  28. package/dist/commands/run.js +68 -17
  29. package/dist/commands/run.js.map +1 -1
  30. package/dist/commands/secrets/index.js +1 -1
  31. package/dist/lib/consts.d.ts +7 -0
  32. package/dist/lib/consts.d.ts.map +1 -1
  33. package/dist/lib/consts.js +9 -0
  34. package/dist/lib/consts.js.map +1 -1
  35. package/dist/lib/exec.js +1 -1
  36. package/dist/lib/exec.js.map +1 -1
  37. package/dist/lib/secrets.js +3 -3
  38. package/dist/lib/utils.d.ts.map +1 -1
  39. package/dist/lib/utils.js +11 -0
  40. package/dist/lib/utils.js.map +1 -1
  41. package/oclif.manifest.json +42 -34
  42. package/package.json +145 -141
  43. package/dist/commands/login-new.d.ts +0 -10
  44. package/dist/commands/login-new.d.ts.map +0 -1
  45. package/dist/commands/login-new.js +0 -166
  46. package/dist/commands/login-new.js.map +0 -1
@@ -4,7 +4,7 @@
4
4
  "aliases": [],
5
5
  "args": {
6
6
  "actorId": {
7
- "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 \".actor/actor.json\" file.",
7
+ "description": "Name or ID of the Actor to run (e.g. \"my-actor\", \"apify/hello-world\" or \"E2jjCZBezvAZnX8Rb\"). If not provided, the command runs the remote Actor specified in the \".actor/actor.json\" file.",
8
8
  "name": "actorId",
9
9
  "required": false
10
10
  }
@@ -128,6 +128,16 @@
128
128
  "hasDynamicHelp": false,
129
129
  "multiple": false,
130
130
  "type": "option"
131
+ },
132
+ "omit-optional-deps": {
133
+ "aliases": [
134
+ "no-optional"
135
+ ],
136
+ "description": "Skip installing optional dependencies.",
137
+ "name": "omit-optional-deps",
138
+ "required": false,
139
+ "allowNo": false,
140
+ "type": "boolean"
131
141
  }
132
142
  },
133
143
  "hasDynamicHelp": false,
@@ -251,10 +261,10 @@
251
261
  "init.js"
252
262
  ]
253
263
  },
254
- "login-new": {
264
+ "login": {
255
265
  "aliases": [],
256
266
  "args": {},
257
- "description": "Logs in to your Apify account using your 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\".",
267
+ "description": "Logs in to your Apify account.\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\".",
258
268
  "flags": {
259
269
  "token": {
260
270
  "char": "t",
@@ -264,35 +274,18 @@
264
274
  "hasDynamicHelp": false,
265
275
  "multiple": false,
266
276
  "type": "option"
267
- }
268
- },
269
- "hasDynamicHelp": false,
270
- "hidden": true,
271
- "hiddenAliases": [],
272
- "id": "login-new",
273
- "pluginAlias": "apify-cli",
274
- "pluginName": "apify-cli",
275
- "pluginType": "core",
276
- "strict": true,
277
- "isESM": true,
278
- "relativePath": [
279
- "dist",
280
- "commands",
281
- "login-new.js"
282
- ]
283
- },
284
- "login": {
285
- "aliases": [],
286
- "args": {},
287
- "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\".",
288
- "flags": {
289
- "token": {
290
- "char": "t",
291
- "description": "[Optional] Apify API token",
292
- "name": "token",
277
+ },
278
+ "method": {
279
+ "char": "m",
280
+ "description": "[Optional] Method of logging in to Apify",
281
+ "name": "method",
293
282
  "required": false,
294
283
  "hasDynamicHelp": false,
295
284
  "multiple": false,
285
+ "options": [
286
+ "console",
287
+ "manual"
288
+ ],
296
289
  "type": "option"
297
290
  }
298
291
  },
@@ -373,7 +366,7 @@
373
366
  "required": false
374
367
  }
375
368
  },
376
- "description": "Uploads the Actor to the Apify platform and builds it there.\nThe Actor settings are read from the \".actor/actor.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!",
369
+ "description": "Uploads the Actor to the Apify platform and builds it there.\nThe Actor settings are read from the \".actor/actor.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\nWhen there's an attempt to push files that are older than the Actor on the platform, the command will fail. Can be overwritten with --force flag.",
377
370
  "flags": {
378
371
  "version-number": {
379
372
  "deprecated": true,
@@ -417,6 +410,13 @@
417
410
  "required": false,
418
411
  "allowNo": false,
419
412
  "type": "boolean"
413
+ },
414
+ "force": {
415
+ "description": "Push an Actor even when the local files are older than the Actor on the platform.",
416
+ "name": "force",
417
+ "required": false,
418
+ "allowNo": false,
419
+ "type": "boolean"
420
420
  }
421
421
  },
422
422
  "hasDynamicHelp": false,
@@ -466,6 +466,14 @@
466
466
  "required": false,
467
467
  "allowNo": false,
468
468
  "type": "boolean"
469
+ },
470
+ "entrypoint": {
471
+ "description": "Optional entrypoint for running with injected environment variables. \n For Python, it is the module name, or a path to a file. \n For node.js, it is the npm script name, or a path to a JS/MJS file. You can also pass in a directory name, provided that directory contains an \"index.js\" file.",
472
+ "name": "entrypoint",
473
+ "required": false,
474
+ "hasDynamicHelp": false,
475
+ "multiple": false,
476
+ "type": "option"
469
477
  }
470
478
  },
471
479
  "hasDynamicHelp": false,
@@ -582,7 +590,7 @@
582
590
  "required": false
583
591
  }
584
592
  },
585
- "description": "Stores an object or an array of objects to the default dataset of the Actor run.\nIt is possible to pass data using item argument or stdin.\nPassing data using argument:\n$ apify actor:push-data {\"foo\": \"bar\"}\nPassing data using stdin with pipe:\n$ cat ./test.json | apify actor:push-data\n",
593
+ "description": "Stores an object or an array of objects to the default dataset of the Actor run.\nIt is possible to pass data using item argument or stdin.\nPassing data using argument:\n$ apify actor push-data {\"foo\": \"bar\"}\nPassing data using stdin with pipe:\n$ cat ./test.json | apify actor push-data\n",
586
594
  "flags": {},
587
595
  "hasDynamicHelp": false,
588
596
  "hiddenAliases": [],
@@ -613,7 +621,7 @@
613
621
  "required": false
614
622
  }
615
623
  },
616
- "description": "Sets or removes record into the default KeyValueStore associated with the Actor run.\nIt is possible to pass data using argument or stdin.\nPassing data using argument:\n$ apify actor:set-value KEY my-value\nPassing data using stdin with pipe:\n$ cat ./my-text-file.txt | apify actor:set-value KEY --contentType text/plain\n",
624
+ "description": "Sets or removes record into the default KeyValueStore associated with the Actor run.\nIt is possible to pass data using argument or stdin.\nPassing data using argument:\n$ apify actor set-value KEY my-value\nPassing data using stdin with pipe:\n$ cat ./my-text-file.txt | apify actor set-value KEY --contentType text/plain\n",
617
625
  "flags": {
618
626
  "contentType": {
619
627
  "char": "c",
@@ -674,7 +682,7 @@
674
682
  "secrets": {
675
683
  "aliases": [],
676
684
  "args": {},
677
- "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 \".actor/actor.json\" file by adding the \"@\" prefix:\n\n{\n \"actorSpecification\": 1,\n \"name\": \"my_actor\",\n \"environmentVariables\": { \"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.",
685
+ "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 \".actor/actor.json\" file by adding the \"@\" prefix:\n\n{\n \"actorSpecification\": 1,\n \"name\": \"my_actor\",\n \"environmentVariables\": { \"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.",
678
686
  "flags": {},
679
687
  "hasDynamicHelp": false,
680
688
  "hiddenAliases": [],
@@ -718,5 +726,5 @@
718
726
  ]
719
727
  }
720
728
  },
721
- "version": "1.0.0-beta.4"
729
+ "version": "1.0.0-beta.41"
722
730
  }
package/package.json CHANGED
@@ -1,146 +1,150 @@
1
1
  {
2
- "name": "apify-cli",
3
- "version": "1.0.0-beta.4",
4
- "description": "Apify command-line interface (CLI) helps you manage the Apify cloud platform and develop, build, and deploy Apify Actors.",
5
- "exports": "./dist/index.js",
6
- "types": "./dist/index.d.ts",
7
- "type": "module",
8
- "scripts": {
9
- "test": "vitest run",
10
- "test-python": "vitest run -t '.*\\[python\\]'",
11
- "lint": "eslint src test",
12
- "lint:fix": "eslint src test --fix",
13
- "clean": "rimraf dist",
14
- "build": "npm run clean && tsc",
15
- "postpack": "rimraf oclif.manifest.json",
16
- "prepack": "npm run build && oclif manifest && oclif readme && oclif readme --readme-path=docs/reference.md",
17
- "prepare": "npm run build && node ./bin/run.js check-version && node ./dist/lib/community.js"
18
- },
19
- "files": [
20
- "dist",
21
- "oclif.manifest.json",
22
- "bin"
2
+ "name": "apify-cli",
3
+ "version": "1.0.0-beta.41",
4
+ "description": "Apify command-line interface (CLI) helps you manage the Apify cloud platform and develop, build, and deploy Apify Actors.",
5
+ "exports": "./dist/index.js",
6
+ "types": "./dist/index.d.ts",
7
+ "type": "module",
8
+ "scripts": {
9
+ "dev": "tsx ./bin/dev.js",
10
+ "test": "vitest run",
11
+ "test-python": "vitest run -t '.*\\[python\\]'",
12
+ "lint": "eslint src test .yarn/plugins --ext .ts,.cjs,.mjs",
13
+ "lint:fix": "eslint src test .yarn/plugins --fix --ext .ts,.cjs,.mjs",
14
+ "clean": "rimraf dist",
15
+ "build": "yarn clean && tsc",
16
+ "postpack": "rimraf oclif.manifest.json",
17
+ "prepack": "yarn build && oclif manifest && oclif readme && oclif readme --readme-path=docs/reference.md",
18
+ "postinstallDev": "yarn build && node ./bin/run.js check-version && node ./dist/lib/community.js"
19
+ },
20
+ "files": [
21
+ "dist",
22
+ "oclif.manifest.json",
23
+ "bin"
24
+ ],
25
+ "bin": {
26
+ "apify": "./bin/run.js"
27
+ },
28
+ "contributors": [
29
+ "Jakub Drobník <jakub.drobnik@apify.com>",
30
+ "Jan Curn <jan@apify.com>"
31
+ ],
32
+ "repository": {
33
+ "type": "git",
34
+ "url": "git+https://github.com/apify/apify-cli.git"
35
+ },
36
+ "keywords": [
37
+ "apify",
38
+ "client",
39
+ "node",
40
+ "command",
41
+ "line",
42
+ "bash"
43
+ ],
44
+ "author": {
45
+ "name": "Apify",
46
+ "email": "support@apify.com",
47
+ "url": "https://www.apify.com"
48
+ },
49
+ "license": "Apache-2.0",
50
+ "bugs": {
51
+ "url": "https://github.com/apify/apify-cli/issues"
52
+ },
53
+ "homepage": "https://github.com/apify/apify-cli#readme",
54
+ "engines": {
55
+ "node": ">=18"
56
+ },
57
+ "dependencies": {
58
+ "@apify/actor-templates": "~0.1.5",
59
+ "@apify/consts": "~2.26.0",
60
+ "@apify/input_schema": "~3.5.15",
61
+ "@apify/utilities": "~2.10.0",
62
+ "@crawlee/memory-storage": "~3.8.1",
63
+ "@oclif/core": "~3.26.0",
64
+ "@oclif/plugin-help": "~6.0.14",
65
+ "@root/walk": "~1.1.0",
66
+ "adm-zip": "~0.5.10",
67
+ "ajv": "~8.12.0",
68
+ "apify-client": "~2.9.3",
69
+ "archiver": "~7.0.0",
70
+ "axios": "~1.6.7",
71
+ "chalk": "~5.3.0",
72
+ "computer-name": "~0.1.0",
73
+ "configparser": "~0.3.10",
74
+ "cors": "~2.8.5",
75
+ "detect-indent": "~7.0.1",
76
+ "escape-string-regexp": "~5.0.0",
77
+ "express": "~4.19.0",
78
+ "globby": "~14.0.1",
79
+ "handlebars": "~4.7.8",
80
+ "inquirer": "~9.2.15",
81
+ "is-ci": "~3.0.1",
82
+ "is-online": "~10.0.0",
83
+ "istextorbinary": "~9.5.0",
84
+ "jju": "~1.4.0",
85
+ "load-json-file": "~7.0.1",
86
+ "mime": "~4.0.1",
87
+ "mixpanel": "~0.18.0",
88
+ "open": "~10.1.0",
89
+ "ow": "~1.1.1",
90
+ "rimraf": "~5.0.5",
91
+ "semver": "~7.6.0",
92
+ "tiged": "~2.12.7",
93
+ "underscore": "~1.13.6",
94
+ "write-json-file": "~5.0.0"
95
+ },
96
+ "devDependencies": {
97
+ "@apify/eslint-config": "^0.4.0",
98
+ "@apify/eslint-config-ts": "^0.4.1",
99
+ "@apify/tsconfig": "^0.1.0",
100
+ "@crawlee/types": "^3.8.1",
101
+ "@oclif/test": "^3.2.1",
102
+ "@types/adm-zip": "^0.5.5",
103
+ "@types/archiver": "^6.0.2",
104
+ "@types/chai": "^4.3.12",
105
+ "@types/cors": "^2.8.17",
106
+ "@types/express": "^4.17.21",
107
+ "@types/inquirer": "^9.0.7",
108
+ "@types/is-ci": "^3.0.4",
109
+ "@types/jju": "^1.4.5",
110
+ "@types/mime": "^4.0.0",
111
+ "@types/node": "^20.11.20",
112
+ "@types/semver": "^7.5.8",
113
+ "@types/underscore": "^1.11.15",
114
+ "@typescript-eslint/eslint-plugin": "^7.0.2",
115
+ "@typescript-eslint/parser": "^7.0.2",
116
+ "@yarnpkg/core": "^4.0.3",
117
+ "chai": "^4.4.1",
118
+ "eslint": "^8.57.0",
119
+ "oclif": "^4.4.18",
120
+ "tsx": "^4.7.1",
121
+ "typescript": "^5.3.3",
122
+ "vitest": "^1.3.1"
123
+ },
124
+ "oclif": {
125
+ "bin": "apify",
126
+ "dirname": "apify",
127
+ "commands": "./dist/commands",
128
+ "plugins": [
129
+ "@oclif/plugin-help"
23
130
  ],
24
- "bin": {
25
- "apify": "./bin/run.js"
131
+ "hooks": {
132
+ "init": [
133
+ "./dist/hooks/init"
134
+ ]
26
135
  },
27
- "contributors": [
28
- "Jakub Drobník <jakub.drobnik@apify.com>",
29
- "Jan Curn <jan@apify.com>"
136
+ "helpClass": "./dist/lib/apify-oclif-help",
137
+ "additionalHelpFlags": [
138
+ "-h"
30
139
  ],
31
- "repository": {
32
- "type": "git",
33
- "url": "git+https://github.com/apify/apify-cli.git"
34
- },
35
- "keywords": [
36
- "apify",
37
- "client",
38
- "node",
39
- "command",
40
- "line",
41
- "bash"
140
+ "additionalVersionFlags": [
141
+ "-v"
42
142
  ],
43
- "author": {
44
- "name": "Apify",
45
- "email": "support@apify.com",
46
- "url": "https://www.apify.com"
47
- },
48
- "license": "Apache-2.0",
49
- "bugs": {
50
- "url": "https://github.com/apify/apify-cli/issues"
51
- },
52
- "homepage": "https://github.com/apify/apify-cli#readme",
53
- "engines": {
54
- "node": ">=16.0.0"
55
- },
56
- "dependencies": {
57
- "@apify/actor-templates": "~0.1.5",
58
- "@apify/consts": "~2.26.0",
59
- "@apify/input_schema": "~3.5.15",
60
- "@apify/utilities": "~2.10.0",
61
- "@crawlee/memory-storage": "~3.8.1",
62
- "@oclif/core": "~3.20.0",
63
- "@oclif/plugin-help": "~6.0.14",
64
- "@root/walk": "~1.1.0",
65
- "adm-zip": "~0.5.10",
66
- "ajv": "~8.12.0",
67
- "apify-client": "~2.9.3",
68
- "archiver": "~7.0.0",
69
- "axios": "~1.6.7",
70
- "chalk": "~5.3.0",
71
- "computer-name": "~0.1.0",
72
- "configparser": "~0.3.10",
73
- "cors": "~2.8.5",
74
- "detect-indent": "~7.0.1",
75
- "escape-string-regexp": "~5.0.0",
76
- "express": "~4.18.2",
77
- "globby": "~14.0.1",
78
- "handlebars": "~4.7.8",
79
- "inquirer": "~9.2.15",
80
- "is-ci": "~3.0.1",
81
- "is-online": "~10.0.0",
82
- "istextorbinary": "~9.5.0",
83
- "jju": "~1.4.0",
84
- "load-json-file": "~7.0.1",
85
- "mime": "~4.0.1",
86
- "mixpanel": "~0.18.0",
87
- "open": "~10.0.4",
88
- "ow": "~1.1.1",
89
- "rimraf": "~5.0.5",
90
- "semver": "~7.6.0",
91
- "tiged": "~2.12.7",
92
- "underscore": "~1.13.6",
93
- "write-json-file": "~5.0.0"
94
- },
95
- "devDependencies": {
96
- "@apify/eslint-config": "^0.4.0",
97
- "@apify/eslint-config-ts": "^0.4.1",
98
- "@apify/tsconfig": "^0.1.0",
99
- "@crawlee/types": "^3.8.1",
100
- "@oclif/test": "^3.2.1",
101
- "@types/adm-zip": "^0.5.5",
102
- "@types/archiver": "^6.0.2",
103
- "@types/chai": "^4.3.12",
104
- "@types/cors": "^2.8.17",
105
- "@types/express": "^4.17.21",
106
- "@types/inquirer": "^9.0.7",
107
- "@types/is-ci": "^3.0.4",
108
- "@types/jju": "^1.4.5",
109
- "@types/mime": "^3.0.4",
110
- "@types/node": "^20.11.20",
111
- "@types/semver": "^7.5.8",
112
- "@types/underscore": "^1.11.15",
113
- "@typescript-eslint/eslint-plugin": "^7.0.2",
114
- "@typescript-eslint/parser": "^7.0.2",
115
- "chai": "^4.4.1",
116
- "eslint": "^8.57.0",
117
- "oclif": "^4.4.18",
118
- "tsx": "^4.7.1",
119
- "typescript": "^5.3.3",
120
- "vitest": "^1.3.1"
121
- },
122
- "oclif": {
123
- "bin": "apify",
124
- "dirname": "apify",
125
- "commands": "./dist/commands",
126
- "plugins": [
127
- "@oclif/plugin-help"
128
- ],
129
- "hooks": {
130
- "init": [
131
- "./dist/hooks/init"
132
- ]
133
- },
134
- "helpClass": "./dist/lib/apify-oclif-help",
135
- "additionalHelpFlags": [
136
- "-h"
137
- ],
138
- "additionalVersionFlags": [
139
- "-v"
140
- ]
141
- },
142
- "volta": {
143
- "node": "20.11.1",
144
- "npm": "10.5.0"
145
- }
146
- }
143
+ "topicSeparator": " "
144
+ },
145
+ "volta": {
146
+ "node": "20.12.0",
147
+ "yarn": "4.1.1"
148
+ },
149
+ "packageManager": "yarn@4.1.1"
150
+ }
@@ -1,10 +0,0 @@
1
- import { ApifyCommand } from '../lib/apify_command.js';
2
- export declare class LoginNewCommand extends ApifyCommand<typeof LoginNewCommand> {
3
- static description: string;
4
- static flags: {
5
- token: import("@oclif/core/lib/interfaces/parser.js").OptionFlag<string | undefined, import("@oclif/core/lib/interfaces/parser.js").CustomOptions>;
6
- };
7
- static hidden: boolean;
8
- run(): Promise<void>;
9
- }
10
- //# sourceMappingURL=login-new.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"login-new.d.ts","sourceRoot":"","sources":["../../src/commands/login-new.ts"],"names":[],"mappings":"AAWA,OAAO,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAC;AA0BvD,qBAAa,eAAgB,SAAQ,YAAY,CAAC,OAAO,eAAe,CAAC;IACrE,OAAgB,WAAW,SAEU;IAErC,OAAgB,KAAK;;MAMnB;IAEF,OAAgB,MAAM,UAAQ;IAExB,GAAG;CAoHZ"}
@@ -1,166 +0,0 @@
1
- import { cryptoRandomObjectId } from '@apify/utilities';
2
- import { Flags } from '@oclif/core';
3
- import computerName from 'computer-name';
4
- import cors from 'cors';
5
- import express from 'express';
6
- import inquirer from 'inquirer';
7
- import open from 'open';
8
- import { ApifyCommand } from '../lib/apify_command.js';
9
- import { error, info, success, warning } from '../lib/outputs.js';
10
- import { useApifyIdentity } from '../lib/telemetry.js';
11
- import { getLocalUserInfo, getLoggedClient } from '../lib/utils.js';
12
- const CONSOLE_BASE_URL = 'https://console.apify.com/account?tab=integrations';
13
- // const CONSOLE_BASE_URL = 'http://localhost:3000/account?tab=integrations';
14
- const CONSOLE_URL_ORIGIN = new URL(CONSOLE_BASE_URL).origin;
15
- const API_BASE_URL = CONSOLE_BASE_URL.includes('localhost') ? 'http://localhost:3333' : undefined;
16
- // Not really checked right now, but it might come useful if we ever need to do some breaking changes
17
- const API_VERSION = 'v1';
18
- const tryToLogin = async (token) => {
19
- const isUserLogged = await getLoggedClient(token, API_BASE_URL);
20
- const userInfo = await getLocalUserInfo();
21
- if (isUserLogged) {
22
- await useApifyIdentity(userInfo.id);
23
- success(`You are logged in to Apify as ${userInfo.username || userInfo.id}!`);
24
- }
25
- else {
26
- error('Login to Apify failed, the provided API token is not valid.');
27
- }
28
- return isUserLogged;
29
- };
30
- export class LoginNewCommand extends ApifyCommand {
31
- async run() {
32
- warning('This command is still experimental and might break at any time. Use at your own risk.\n');
33
- const { token } = this.flags;
34
- if (token) {
35
- await tryToLogin(token);
36
- return;
37
- }
38
- const answer = await inquirer.prompt([{
39
- type: 'list',
40
- name: 'loginMethod',
41
- message: 'Choose how you want to log in to Apify',
42
- choices: [
43
- { value: 'console', name: 'Through Apify Console in your default browser', short: 'Through Apify Console' },
44
- { value: 'manual', name: 'Enter API token manually', short: 'Manually' },
45
- ],
46
- loop: false,
47
- }]);
48
- if (answer.loginMethod === 'console') {
49
- let server;
50
- const app = express();
51
- // To send requests from browser to localhost, CORS has to be configured properly
52
- app.use(cors({
53
- origin: CONSOLE_URL_ORIGIN,
54
- allowedHeaders: ['Content-Type', 'Authorization'],
55
- }));
56
- // Turn off keepalive, otherwise closing the server when command is finished is lagging
57
- app.use((_, res, next) => {
58
- res.set('Connection', 'close');
59
- next();
60
- });
61
- app.use(express.json());
62
- // Basic authorization via a random token, which is passed to the Apify Console,
63
- // and that sends it back via the `token` query param, or `Authorization` header
64
- const authToken = cryptoRandomObjectId();
65
- app.use((req, res, next) => {
66
- let { token: serverToken } = req.query;
67
- if (!serverToken) {
68
- const authorizationHeader = req.get('Authorization');
69
- if (authorizationHeader) {
70
- const [schema, tokenFromHeader, ...extra] = authorizationHeader.trim().split(/\s+/);
71
- if (schema.toLowerCase() === 'bearer' && tokenFromHeader && extra.length === 0) {
72
- serverToken = tokenFromHeader;
73
- }
74
- }
75
- }
76
- if (serverToken !== authToken) {
77
- res.status(401);
78
- res.send('Authorization failed');
79
- }
80
- else {
81
- next();
82
- }
83
- });
84
- const apiRouter = express.Router();
85
- app.use(`/api/${API_VERSION}`, apiRouter);
86
- apiRouter.post('/login-token', async (req, res) => {
87
- try {
88
- if (req.body.apiToken) {
89
- await tryToLogin(req.body.apiToken);
90
- }
91
- else {
92
- throw new Error('Request did not contain API token');
93
- }
94
- res.end();
95
- }
96
- catch (err) {
97
- const errorMessage = `Login to Apify failed with error: ${err.message}`;
98
- error(errorMessage);
99
- res.status(500);
100
- res.send(errorMessage);
101
- }
102
- server.close();
103
- });
104
- apiRouter.post('/exit', (req, res) => {
105
- if (req.body.isWindowClosed) {
106
- error('Login to Apify failed, the console window was closed.');
107
- }
108
- else if (req.body.actionCanceled) {
109
- error('Login to Apify failed, the action was canceled in the Apify Console.');
110
- }
111
- else {
112
- error('Login to Apify failed.');
113
- }
114
- res.end();
115
- server.close();
116
- });
117
- // Listening on port 0 will assign a random available port
118
- server = app.listen(0);
119
- const { port } = server.address();
120
- const consoleUrl = new URL(CONSOLE_BASE_URL);
121
- consoleUrl.searchParams.set('localCliCommand', 'login');
122
- consoleUrl.searchParams.set('localCliPort', `${port}`);
123
- consoleUrl.searchParams.set('localCliToken', authToken);
124
- consoleUrl.searchParams.set('localCliApiVersion', API_VERSION);
125
- try {
126
- consoleUrl.searchParams.set('localCliComputerName', encodeURIComponent(computerName()));
127
- }
128
- catch {
129
- // Ignore errors from fetching computer name as it's not critical
130
- }
131
- info(`Opening Apify Console at "${consoleUrl.href}"...`);
132
- await open(consoleUrl.href);
133
- }
134
- else {
135
- const tokenAnswer = await inquirer.prompt([{ name: 'token', message: 'Insert your Apify API token', type: 'password' }]);
136
- await tryToLogin(tokenAnswer.token);
137
- }
138
- }
139
- }
140
- Object.defineProperty(LoginNewCommand, "description", {
141
- enumerable: true,
142
- configurable: true,
143
- writable: true,
144
- value: 'Logs in to your Apify account using your API token.\nThe API token and other account '
145
- + 'information is stored in the ~/.apify directory, from where it is read by all other "apify" commands. '
146
- + 'To log out, call "apify logout".'
147
- });
148
- Object.defineProperty(LoginNewCommand, "flags", {
149
- enumerable: true,
150
- configurable: true,
151
- writable: true,
152
- value: {
153
- token: Flags.string({
154
- char: 't',
155
- description: '[Optional] Apify API token',
156
- required: false,
157
- }),
158
- }
159
- });
160
- Object.defineProperty(LoginNewCommand, "hidden", {
161
- enumerable: true,
162
- configurable: true,
163
- writable: true,
164
- value: true
165
- });
166
- //# sourceMappingURL=login-new.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"login-new.js","sourceRoot":"","sources":["../../src/commands/login-new.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,oBAAoB,EAAE,MAAM,kBAAkB,CAAC;AACxD,OAAO,EAAE,KAAK,EAAE,MAAM,aAAa,CAAC;AACpC,OAAO,YAAY,MAAM,eAAe,CAAC;AACzC,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,OAAO,MAAM,SAAS,CAAC;AAC9B,OAAO,QAAQ,MAAM,UAAU,CAAC;AAChC,OAAO,IAAI,MAAM,MAAM,CAAC;AAExB,OAAO,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAC;AACvD,OAAO,EAAE,KAAK,EAAE,IAAI,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAC;AAClE,OAAO,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AACvD,OAAO,EAAE,gBAAgB,EAA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