apify-cli 0.21.10-beta.5 → 0.21.10-beta.7
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/dist/.tsbuildinfo +1 -1
- package/dist/actor.js +3 -0
- package/dist/actor.js.map +1 -0
- package/dist/apify.js +3 -0
- package/dist/apify.js.map +1 -0
- package/dist/chunk-RGQHG4D4.js +236 -0
- package/dist/chunk-RGQHG4D4.js.map +1 -0
- package/dist/index.js +2 -3
- package/package.json +6 -6
- package/dist/commands/_register.js +0 -72
- package/dist/commands/_register.js.map +0 -1
- package/dist/commands/actor/_index.js +0 -24
- package/dist/commands/actor/_index.js.map +0 -1
- package/dist/commands/actor/charge.js +0 -84
- package/dist/commands/actor/charge.js.map +0 -1
- package/dist/commands/actor/get-input.js +0 -10
- package/dist/commands/actor/get-input.js.map +0 -1
- package/dist/commands/actor/get-public-url.js +0 -52
- package/dist/commands/actor/get-public-url.js.map +0 -1
- package/dist/commands/actor/get-value.js +0 -18
- package/dist/commands/actor/get-value.js.map +0 -1
- package/dist/commands/actor/push-data.js +0 -38
- package/dist/commands/actor/push-data.js.map +0 -1
- package/dist/commands/actor/set-value.js +0 -52
- package/dist/commands/actor/set-value.js.map +0 -1
- package/dist/commands/actors/_index.js +0 -28
- package/dist/commands/actors/_index.js.map +0 -1
- package/dist/commands/actors/build.js +0 -6
- package/dist/commands/actors/build.js.map +0 -1
- package/dist/commands/actors/call.js +0 -224
- package/dist/commands/actors/call.js.map +0 -1
- package/dist/commands/actors/info.js +0 -203
- package/dist/commands/actors/info.js.map +0 -1
- package/dist/commands/actors/ls.js +0 -226
- package/dist/commands/actors/ls.js.map +0 -1
- package/dist/commands/actors/pull.js +0 -150
- package/dist/commands/actors/pull.js.map +0 -1
- package/dist/commands/actors/push.js +0 -300
- package/dist/commands/actors/push.js.map +0 -1
- package/dist/commands/actors/rm.js +0 -43
- package/dist/commands/actors/rm.js.map +0 -1
- package/dist/commands/actors/start.js +0 -125
- package/dist/commands/actors/start.js.map +0 -1
- package/dist/commands/builds/_index.js +0 -22
- package/dist/commands/builds/_index.js.map +0 -1
- package/dist/commands/builds/create.js +0 -130
- package/dist/commands/builds/create.js.map +0 -1
- package/dist/commands/builds/info.js +0 -78
- package/dist/commands/builds/info.js.map +0 -1
- package/dist/commands/builds/log.js +0 -35
- package/dist/commands/builds/log.js.map +0 -1
- package/dist/commands/builds/ls.js +0 -141
- package/dist/commands/builds/ls.js.map +0 -1
- package/dist/commands/builds/rm.js +0 -59
- package/dist/commands/builds/rm.js.map +0 -1
- package/dist/commands/call.js +0 -5
- package/dist/commands/call.js.map +0 -1
- package/dist/commands/cli-management/install.js +0 -138
- package/dist/commands/cli-management/install.js.map +0 -1
- package/dist/commands/cli-management/upgrade.js +0 -270
- package/dist/commands/cli-management/upgrade.js.map +0 -1
- package/dist/commands/create.js +0 -264
- package/dist/commands/create.js.map +0 -1
- package/dist/commands/datasets/_index.js +0 -25
- package/dist/commands/datasets/_index.js.map +0 -1
- package/dist/commands/datasets/create.js +0 -38
- package/dist/commands/datasets/create.js.map +0 -1
- package/dist/commands/datasets/get-items.js +0 -84
- package/dist/commands/datasets/get-items.js.map +0 -1
- package/dist/commands/datasets/info.js +0 -125
- package/dist/commands/datasets/info.js.map +0 -1
- package/dist/commands/datasets/ls.js +0 -73
- package/dist/commands/datasets/ls.js.map +0 -1
- package/dist/commands/datasets/push-items.js +0 -70
- package/dist/commands/datasets/push-items.js.map +0 -1
- package/dist/commands/datasets/rename.js +0 -71
- package/dist/commands/datasets/rename.js.map +0 -1
- package/dist/commands/datasets/rm.js +0 -48
- package/dist/commands/datasets/rm.js.map +0 -1
- package/dist/commands/edit-input-schema.js +0 -162
- package/dist/commands/edit-input-schema.js.map +0 -1
- package/dist/commands/help.js +0 -43
- package/dist/commands/help.js.map +0 -1
- package/dist/commands/info.js +0 -21
- package/dist/commands/info.js.map +0 -1
- package/dist/commands/init-wrap-scrapy.js +0 -27
- package/dist/commands/init-wrap-scrapy.js.map +0 -1
- package/dist/commands/init.js +0 -94
- package/dist/commands/init.js.map +0 -1
- package/dist/commands/key-value-stores/_index.js +0 -30
- package/dist/commands/key-value-stores/_index.js.map +0 -1
- package/dist/commands/key-value-stores/create.js +0 -38
- package/dist/commands/key-value-stores/create.js.map +0 -1
- package/dist/commands/key-value-stores/delete-value.js +0 -61
- package/dist/commands/key-value-stores/delete-value.js.map +0 -1
- package/dist/commands/key-value-stores/get-value.js +0 -70
- package/dist/commands/key-value-stores/get-value.js.map +0 -1
- package/dist/commands/key-value-stores/info.js +0 -127
- package/dist/commands/key-value-stores/info.js.map +0 -1
- package/dist/commands/key-value-stores/keys.js +0 -61
- package/dist/commands/key-value-stores/keys.js.map +0 -1
- package/dist/commands/key-value-stores/ls.js +0 -70
- package/dist/commands/key-value-stores/ls.js.map +0 -1
- package/dist/commands/key-value-stores/rename.js +0 -71
- package/dist/commands/key-value-stores/rename.js.map +0 -1
- package/dist/commands/key-value-stores/rm.js +0 -48
- package/dist/commands/key-value-stores/rm.js.map +0 -1
- package/dist/commands/key-value-stores/set-value.js +0 -57
- package/dist/commands/key-value-stores/set-value.js.map +0 -1
- package/dist/commands/login.js +0 -183
- package/dist/commands/login.js.map +0 -1
- package/dist/commands/logout.js +0 -16
- package/dist/commands/logout.js.map +0 -1
- package/dist/commands/pull.js +0 -5
- package/dist/commands/pull.js.map +0 -1
- package/dist/commands/push.js +0 -5
- package/dist/commands/push.js.map +0 -1
- package/dist/commands/request-queues/_index.js +0 -9
- package/dist/commands/request-queues/_index.js.map +0 -1
- package/dist/commands/run.js +0 -434
- package/dist/commands/run.js.map +0 -1
- package/dist/commands/runs/_index.js +0 -23
- package/dist/commands/runs/_index.js.map +0 -1
- package/dist/commands/runs/abort.js +0 -68
- package/dist/commands/runs/abort.js.map +0 -1
- package/dist/commands/runs/info.js +0 -238
- package/dist/commands/runs/info.js.map +0 -1
- package/dist/commands/runs/log.js +0 -32
- package/dist/commands/runs/log.js.map +0 -1
- package/dist/commands/runs/ls.js +0 -106
- package/dist/commands/runs/ls.js.map +0 -1
- package/dist/commands/runs/resurrect.js +0 -54
- package/dist/commands/runs/resurrect.js.map +0 -1
- package/dist/commands/runs/rm.js +0 -58
- package/dist/commands/runs/rm.js.map +0 -1
- package/dist/commands/secrets/_index.js +0 -25
- package/dist/commands/secrets/_index.js.map +0 -1
- package/dist/commands/secrets/add.js +0 -22
- package/dist/commands/secrets/add.js.map +0 -1
- package/dist/commands/secrets/rm.js +0 -18
- package/dist/commands/secrets/rm.js.map +0 -1
- package/dist/commands/task/_index.js +0 -11
- package/dist/commands/task/_index.js.map +0 -1
- package/dist/commands/task/run.js +0 -91
- package/dist/commands/task/run.js.map +0 -1
- package/dist/commands/validate-schema.js +0 -44
- package/dist/commands/validate-schema.js.map +0 -1
- package/dist/entrypoints/_shared.js +0 -258
- package/dist/entrypoints/_shared.js.map +0 -1
- package/dist/entrypoints/actor.js +0 -19
- package/dist/entrypoints/actor.js.map +0 -1
- package/dist/entrypoints/apify.js +0 -18
- package/dist/entrypoints/apify.js.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/lib/actor.js +0 -74
- package/dist/lib/actor.js.map +0 -1
- package/dist/lib/command-framework/apify-command.js +0 -429
- package/dist/lib/command-framework/apify-command.js.map +0 -1
- package/dist/lib/command-framework/args.js +0 -24
- package/dist/lib/command-framework/args.js.map +0 -1
- package/dist/lib/command-framework/flags.js +0 -99
- package/dist/lib/command-framework/flags.js.map +0 -1
- package/dist/lib/command-framework/help/CommandHelp.js +0 -233
- package/dist/lib/command-framework/help/CommandHelp.js.map +0 -1
- package/dist/lib/command-framework/help/CommandWithSubcommands.js +0 -75
- package/dist/lib/command-framework/help/CommandWithSubcommands.js.map +0 -1
- package/dist/lib/command-framework/help/_BaseCommandRenderer.js +0 -63
- package/dist/lib/command-framework/help/_BaseCommandRenderer.js.map +0 -1
- package/dist/lib/command-framework/help/consts.js +0 -27
- package/dist/lib/command-framework/help/consts.js.map +0 -1
- package/dist/lib/command-framework/help.js +0 -105
- package/dist/lib/command-framework/help.js.map +0 -1
- package/dist/lib/commands/pretty-print-bytes.js +0 -13
- package/dist/lib/commands/pretty-print-bytes.js.map +0 -1
- package/dist/lib/commands/pretty-print-status.js +0 -29
- package/dist/lib/commands/pretty-print-status.js.map +0 -1
- package/dist/lib/commands/read-stdin.js +0 -42
- package/dist/lib/commands/read-stdin.js.map +0 -1
- package/dist/lib/commands/resolve-actor-context.js +0 -70
- package/dist/lib/commands/resolve-actor-context.js.map +0 -1
- package/dist/lib/commands/resolve-input.js +0 -162
- package/dist/lib/commands/resolve-input.js.map +0 -1
- package/dist/lib/commands/responsive-table.js +0 -129
- package/dist/lib/commands/responsive-table.js.map +0 -1
- package/dist/lib/commands/run-on-cloud.js +0 -126
- package/dist/lib/commands/run-on-cloud.js.map +0 -1
- package/dist/lib/commands/storage-size.js +0 -8
- package/dist/lib/commands/storage-size.js.map +0 -1
- package/dist/lib/commands/storages.js +0 -30
- package/dist/lib/commands/storages.js.map +0 -1
- package/dist/lib/consts.js +0 -58
- package/dist/lib/consts.js.map +0 -1
- package/dist/lib/create-utils.js +0 -156
- package/dist/lib/create-utils.js.map +0 -1
- package/dist/lib/exec.js +0 -34
- package/dist/lib/exec.js.map +0 -1
- package/dist/lib/files.js +0 -54
- package/dist/lib/files.js.map +0 -1
- package/dist/lib/hooks/runtimes/javascript.js +0 -86
- package/dist/lib/hooks/runtimes/javascript.js.map +0 -1
- package/dist/lib/hooks/runtimes/python.js +0 -80
- package/dist/lib/hooks/runtimes/python.js.map +0 -1
- package/dist/lib/hooks/runtimes/utils.js +0 -16
- package/dist/lib/hooks/runtimes/utils.js.map +0 -1
- package/dist/lib/hooks/useActorConfig.js +0 -177
- package/dist/lib/hooks/useActorConfig.js.map +0 -1
- package/dist/lib/hooks/useCLIMetadata.js +0 -83
- package/dist/lib/hooks/useCLIMetadata.js.map +0 -1
- package/dist/lib/hooks/useCLIVersionAssets.js +0 -92
- package/dist/lib/hooks/useCLIVersionAssets.js.map +0 -1
- package/dist/lib/hooks/useCLIVersionCheck.js +0 -91
- package/dist/lib/hooks/useCLIVersionCheck.js.map +0 -1
- package/dist/lib/hooks/useCommandSuggestions.js +0 -37
- package/dist/lib/hooks/useCommandSuggestions.js.map +0 -1
- package/dist/lib/hooks/useCwdProject.js +0 -174
- package/dist/lib/hooks/useCwdProject.js.map +0 -1
- package/dist/lib/hooks/useLocalState.js +0 -56
- package/dist/lib/hooks/useLocalState.js.map +0 -1
- package/dist/lib/hooks/useModuleVersion.js +0 -103
- package/dist/lib/hooks/useModuleVersion.js.map +0 -1
- package/dist/lib/hooks/useStdin.js +0 -65
- package/dist/lib/hooks/useStdin.js.map +0 -1
- package/dist/lib/input_schema.js +0 -130
- package/dist/lib/input_schema.js.map +0 -1
- package/dist/lib/outputs.js +0 -45
- package/dist/lib/outputs.js.map +0 -1
- package/dist/lib/project_analyzer.js +0 -30
- package/dist/lib/project_analyzer.js.map +0 -1
- package/dist/lib/projects/CrawleeAnalyzer.js +0 -20
- package/dist/lib/projects/CrawleeAnalyzer.js.map +0 -1
- package/dist/lib/projects/OldApifySDKAnalyzer.js +0 -38
- package/dist/lib/projects/OldApifySDKAnalyzer.js.map +0 -1
- package/dist/lib/projects/scrapy/ScrapyProjectAnalyzer.js +0 -73
- package/dist/lib/projects/scrapy/ScrapyProjectAnalyzer.js.map +0 -1
- package/dist/lib/projects/scrapy/Spider.js +0 -13
- package/dist/lib/projects/scrapy/Spider.js.map +0 -1
- package/dist/lib/projects/scrapy/SpiderFileAnalyzer.js +0 -20
- package/dist/lib/projects/scrapy/SpiderFileAnalyzer.js.map +0 -1
- package/dist/lib/projects/scrapy/wrapScrapyProject.js +0 -113
- package/dist/lib/projects/scrapy/wrapScrapyProject.js.map +0 -1
- package/dist/lib/projects/shared.js +0 -13
- package/dist/lib/projects/shared.js.map +0 -1
- package/dist/lib/secrets.js +0 -106
- package/dist/lib/secrets.js.map +0 -1
- package/dist/lib/telemetry.js +0 -86
- package/dist/lib/telemetry.js.map +0 -1
- package/dist/lib/types.js +0 -4
- package/dist/lib/types.js.map +0 -1
- package/dist/lib/utils/cliDebugPrint.js +0 -7
- package/dist/lib/utils/cliDebugPrint.js.map +0 -1
- package/dist/lib/utils/confirm.js +0 -28
- package/dist/lib/utils/confirm.js.map +0 -1
- package/dist/lib/utils.js +0 -457
- package/dist/lib/utils.js.map +0 -1
|
@@ -0,0 +1,236 @@
|
|
|
1
|
+
var Aa=Object.defineProperty;var l=(t,e)=>Aa(t,"name",{value:e,configurable:!0});import de from"process";import ue from"chalk";import{satisfies as kc}from"semver";import Fc from"yargs/yargs";import $i from"chalk";import gc from"indent-string";import hc from"widest-line";import yc from"wrap-ansi";import st from"chalk";function Je(t){t.stdoutOutput&&console.log(...t.stdoutOutput),t.stderrOutput&&console.error(...t.stderrOutput)}l(Je,"internalLog");function _(t){Je({[t.stdout?"stdoutOutput":"stderrOutput"]:[t.message]})}l(_,"simpleLog");function m(t){Je({[t.stdout?"stdoutOutput":"stderrOutput"]:[st.red("Error:"),t.message]})}l(m,"error");function x(t){Je({[t.stdout?"stdoutOutput":"stderrOutput"]:[st.yellow.bold("Warning:"),t.message]})}l(x,"warning");function R(t){Je({[t.stdout?"stdoutOutput":"stderrOutput"]:[st.green("Success:"),t.message]})}l(R,"success");function ye(t){Je({[t.stdout?"stdoutOutput":"stderrOutput"]:[st.gray("Run:"),t.message]})}l(ye,"run");function T(t){Je({[t.stdout?"stdoutOutput":"stderrOutput"]:[st.white("Info:"),t.message]})}l(T,"info");function Vs(t){Je({[t.stdout?"stdoutOutput":"stderrOutput"]:[st.blue(t.message),t.url]})}l(Vs,"link");import kt from"chalk";import Ti from"indent-string";import Si from"widest-line";import Ci from"wrap-ansi";import{realpathSync as ba}from"fs";import{dirname as va}from"path";var Gs="0.0.0";var Ta="0.21.10-beta.7",Sa="df71348af9567e33f4f3ed411c0b734f6d99d259";function Ca(){if(process.env.APIFY_CLI_MARKED_INSTALL_METHOD)return process.env.APIFY_CLI_MARKED_INSTALL_METHOD;if(process.env.APIFY_CLI_BUNDLE)return"bundle";let t=process.argv[1];if(!t)return x({message:"Failed to detect install method of CLI, assuming npm"}),"npm";let e=ba(t);return process.env.VOLTA_HOME&&e.includes(process.env.VOLTA_HOME)?"volta":e.includes("homebrew/Cellar")||e.includes("linuxbrew/Cellar")?"homebrew":process.env.PNPM_HOME&&e.includes(process.env.PNPM_HOME)?"pnpm":process.env.BUN_INSTALL&&e.includes(process.env.BUN_INSTALL)?"bun":"npm"}l(Ca,"detectInstallMethod");function Ia(){return process.versions.bun?{runtime:"bun",version:process.versions.bun,nodeVersion:process.versions.node}:process.versions.deno?{runtime:"deno",version:process.versions.deno,nodeVersion:process.versions.node}:{runtime:"node",version:process.versions.node}}l(Ia,"getRuntimeInfo");var Ct=null;function ee(){if(Ct)return Ct;let t=Ca(),e=Ia();return Ct={version:Ta,hash:Sa,arch:process.env.APIFY_BUNDLE_ARCH??process.arch,platform:process.platform==="win32"?"windows":process.platform,runtime:e.runtime,extraRuntimeData:e.nodeVersion?`(emulating node ${e.nodeVersion})`:"",installMethod:t,get fullVersionString(){return`apify-cli/${this.version} (${this.hash.slice(0,7)}) running on ${this.platform}-${this.arch} with ${this.runtime}-${e.version}${this.extraRuntimeData?` ${this.extraRuntimeData}`:""}, installed via ${this.installMethod}`}},t==="bundle"&&(Ct.installPath=va(process.execPath)),Ct}l(ee,"useCLIMetadata");import{createWriteStream as Ua,existsSync as ne,mkdirSync as ja,readdirSync as ti,readFileSync as _t,writeFileSync as or}from"fs";import{mkdir as Ma,readFile as Ba}from"fs/promises";import{get as Va}from"https";import{dirname as ri,join as Ae}from"path";import ie from"process";import{finished as Ga}from"stream/promises";import{DurationFormatter as oi,TimeTypes as ze}from"@sapphire/duration";import{Timestamp as es}from"@sapphire/timestamp";import Ha from"adm-zip";import Ya from"ajv/dist/2019.js";import{ApifyClient as si}from"apify-client";import Ja from"archiver";import{AxiosHeaders as qa}from"axios";import Ka from"escape-string-regexp";import{globby as ii}from"globby";import{getEncoding as Wa}from"istextorbinary";import{Mime as za}from"mime";import Xa from"mime/types/other.js";import Qa from"mime/types/standard.js";import{gte as Za,minVersion as ec,satisfies as tc}from"semver";import{ACTOR_ENV_VARS as ts,ACTOR_JOB_TERMINAL_STATUSES as rc,ACTOR_NAME as Rt,APIFY_ENV_VARS as oc,KEY_VALUE_STORE_KEYS as ei,LOCAL_ACTOR_ENV_VARS as rs,LOCAL_STORAGE_SUBDIRS as os,SOURCE_FILE_FORMATS as Et}from"@apify/consts";import{homedir as Ea}from"os";import{join as qe}from"path";import{KEY_VALUE_STORE_KEYS as Ra,META_ORIGINS as _a}from"@apify/consts";var Hs={name:"apify-cli",version:"0.21.10-beta.7",description:"Apify command-line interface (CLI) helps you manage the Apify cloud platform and develop, build, and deploy Apify Actors.",exports:"./dist/index.js",type:"module",scripts:{"dev:apify":"tsx ./src/entrypoints/apify.ts","dev:actor":"tsx ./src/entrypoints/actor.ts","test:all":"yarn test:local && yarn test:api","test:local":"vitest run --testNamePattern '^((?!\\[api]).)*$' --exclude ./test/api","test:api":"vitest run --testNamePattern '\\[api\\]'","test:python":"vitest run --testNamePattern '\\[python\\]'","test:cucumber":'cross-env NODE_OPTIONS="--import tsx" cucumber-js',lint:"eslint src test scripts features --ext .ts,.cjs,.mjs","lint:fix":"eslint src test scripts features --fix --ext .ts,.cjs,.mjs",format:'biome format . && prettier --check "**/*.{md,yml,yaml}"',"format:fix":'biome format --write . && prettier --write "**/*.{md,yml,yaml}"',clean:"rimraf dist",build:"yarn clean && tsc && tsup","build-bundles":"bun run scripts/build-cli-bundles.ts",prepack:"yarn insert-cli-metadata && yarn build && yarn update-docs","insert-cli-metadata":"tsx scripts/insert-cli-metadata.ts","update-docs":"tsx scripts/generate-cli-docs.ts",postinstall:`node -e "console.log('We have an active developer community on Discord. You can find it on https://discord.gg/crawlee-apify-801163717915574323.');"`},files:["dist"],bin:{actor:"./dist/actor.js",apify:"./dist/apify.js","apify-cli":"./dist/apify.js"},contributors:["Jakub Drobn\xEDk <jakub.drobnik@apify.com>","Jan Curn <jan@apify.com>","Vlad Frangu <vlad.frangu@apify.com>"],repository:{type:"git",url:"git+https://github.com/apify/apify-cli.git"},keywords:["apify","client","node","command","line","bash"],author:{name:"Apify",email:"support@apify.com",url:"https://www.apify.com"},license:"Apache-2.0",bugs:{url:"https://github.com/apify/apify-cli/issues"},homepage:"https://github.com/apify/apify-cli#readme",engines:{node:">=18"},dependencies:{"@apify/actor-templates":"^0.1.5","@apify/consts":"^2.36.0","@apify/input_schema":"^3.17.0","@apify/utilities":"^2.15.1","@crawlee/memory-storage":"^3.12.0","@root/walk":"~1.1.0","@sapphire/duration":"^1.1.2","@sapphire/result":"^2.7.2","@sapphire/timestamp":"^1.0.3","@skyra/jaro-winkler":"^1.1.1","adm-zip":"~0.5.15",ajv:"~8.17.1","apify-client":"^2.12.6",archiver:"~7.0.1",axios:"^1.11.0",chalk:"~5.4.0","cli-table3":"^0.6.5","computer-name":"~0.1.0",configparser:"~0.3.10",cors:"~2.8.5","detect-indent":"~7.0.1","escape-string-regexp":"~5.0.0",execa:"^9.5.2",express:"~5.1.0",globby:"~14.1.0",handlebars:"~4.7.8","indent-string":"^5.0.0",inquirer:"~12.9.0","is-ci":"~4.1.0",istextorbinary:"~9.5.0",jju:"~1.4.0","js-levenshtein":"^1.1.6","lodash.clonedeep":"^4.5.0",mime:"~4.0.4",mixpanel:"~0.18.0",open:"~10.2.0",ow:"~2.0.0",rimraf:"~6.0.1",semver:"~7.7.0","string-width":"^7.2.0","strip-ansi":"^7.1.0",tiged:"~2.12.7",which:"^5.0.0","widest-line":"^5.0.0","wrap-ansi":"^9.0.0",yargs:"^17.7.2"},devDependencies:{"@apify/eslint-config":"^1.0.0","@apify/tsconfig":"^0.1.1","@biomejs/biome":"^2.0.0","@crawlee/types":"^3.11.1","@cucumber/cucumber":"^12.0.0","@types/adm-zip":"^0.5.5","@types/archiver":"^6.0.2","@types/bun":"^1.2.5","@types/chai":"^4.3.17","@types/cors":"^2.8.17","@types/execa":"^2.0.2","@types/express":"^5.0.0","@types/fs-extra":"^11","@types/inquirer":"^9.0.7","@types/is-ci":"^3.0.4","@types/jju":"^1.4.5","@types/js-levenshtein":"^1","@types/lodash.clonedeep":"^4","@types/mime":"^4.0.0","@types/node":"^22.0.0","@types/semver":"^7.5.8","@types/which":"^3.0.4","@types/yargs":"^17.0.33","@yarnpkg/core":"^4.1.2",apify:"^3.2.4",chai:"^4.4.1","cross-env":"^10.0.0",eslint:"^9.25.1","eslint-config-prettier":"^10.1.2","lint-staged":"^16.0.0","mdast-util-from-markdown":"^2.0.2","mock-stdin":"^1.0.0",prettier:"^3.5.3",tsup:"^8.5.0",tsx:"^4.16.5",typescript:"^5.8.3","typescript-eslint":"^8.31.0",vitest:"^3.0.0"},volta:{node:"22.17.1",yarn:"4.9.2"},packageManager:"yarn@4.9.2",devEngines:{runtime:[{name:"node",version:">= 20",onFail:"error"},{name:"bun",version:">= 1.2.5",onFail:"ignore"}],packageManager:{name:"yarn",version:">= 4",onFail:"warn"}},"lint-staged":{"*":"biome format --write --no-errors-on-unmatched","*.{mjs,js,ts}":"eslint --fix --ext mjs,js,ts","*.md":"prettier --write"}};var Ke="storage",zo="apify_storage",Xo=1,Qt={actorSpecification:Xo,name:null,version:"0.0",buildTag:"latest",environmentVariables:{}},Ys={SCRAPY:"scrapy",CRAWLEE:"crawlee",PRE_CRAWLEE_APIFY_SDK:"apify",UNKNOWN:"unknown"},Js=1440*60*1e3,it=l(()=>{let t=qe(Ea(),".apify");return process.env.__APIFY_INTERNAL_TEST_AUTH_PATH__?qe(t,process.env.__APIFY_INTERNAL_TEST_AUTH_PATH__):t},"GLOBAL_CONFIGS_FOLDER"),se=l(()=>qe(it(),"auth.json"),"AUTH_FILE_PATH"),Zt=l(()=>qe(it(),"secrets.json"),"SECRETS_FILE_PATH"),er=l(()=>qe(it(),"state.json"),"STATE_FILE_PATH"),Le=l(()=>qe(it(),"telemetry.json"),"TELEMETRY_FILE_PATH"),tr="apify.json",Qo=".actor",xa="actor.json",M=qe(Qo,xa),Zo=new RegExp(`^${Ra.INPUT}\\..*`),we=Hs.engines.node,qs={"X-Apify-Request-Origin":_a.CLI},We="3.9.0",Ks=".venv",Ws="ea75e434d4b4d2405d79ed9d14bfc93b";import{existsSync as Oa,mkdirSync as Na}from"fs";import{readFile as La,stat as zs,unlink as Da,writeFile as Pa}from"fs/promises";import{join as Xs,sep as ka}from"path";import{rimraf as Fa}from"rimraf";var Qs=l(async(t,e={},r=null)=>{let o=await La(t,"utf-8"),s=JSON.parse(o),i;r?(i=s,i[r]={...s[r],...e}):i={...s,...e},await Pa(t,JSON.stringify(i,null," "))},"updateLocalJson"),rr=l((t,e)=>{e||(e=t,t="."),e.split(ka).reduce((o,s)=>(o=Xs(o,s),Oa(o)||Na(o),o),t)},"ensureFolderExistsSync"),It=l(async t=>{await Fa(t)},"rimrafPromised"),$t=l(async t=>{(await zs(t)).isFile()&&await Da(t)},"deleteFile"),Zs=l(async(t,e)=>(await Promise.all(t.map(async s=>zs(Xs(e,s))))).map(s=>s.size).reduce((s,i)=>s+i,0),"sumFilesSizeInBytes");var nt=Ya,sr=l(async t=>new Promise((e,r)=>{Va(t,o=>{o.statusCode===301||o.statusCode===302?(e(sr(o.headers.location)),o.destroy()):e(o)}).on("error",r)}),"httpsGet"),ae=l(()=>{let t=oc.LOCAL_STORAGE_DIR;return ie.env[t]||ie.env.CRAWLEE_STORAGE_DIR||Ke},"getLocalStorageDir"),ve=l(t=>{let e=ts.DEFAULT_KEY_VALUE_STORE_ID,r=t||ie.env[e]||rs[e];return Ae(ae(),os.keyValueStores,r)},"getLocalKeyValueStorePath"),ni=l(t=>{let e=ts.DEFAULT_DATASET_ID,r=t||ie.env[e]||rs[e];return Ae(ae(),os.datasets,r)},"getLocalDatasetPath"),ai=l(t=>{let e=ts.DEFAULT_REQUEST_QUEUE_ID,r=t||ie.env[e]||rs[e];return Ae(ae(),os.requestQueues,r)},"getLocalRequestQueuePath"),k=l(async()=>{let t={};try{let e=await Ba(se(),"utf-8");t=JSON.parse(e)}catch{return{}}if(!t.username&&!t.id)throw new Error('Corrupted local user info was found. Please run "apify login" to fix it.');return t},"getLocalUserInfo");async function S(){let t=await xt();if(!t)throw new Error('You are not logged in with your Apify account. Call "apify login" to fix that.');return t}l(S,"getLoggedClientOrThrow");var ci=l(t=>{if(!t&&ne(it())&&ne(se())){let e=_t(se(),"utf-8");return JSON.parse(e).token}return t},"getTokenWithAuthFileFallback"),ss=l((t,e)=>(t=ci(t),{token:t,baseUrl:e||ie.env.APIFY_CLIENT_BASE_URL,requestInterceptors:[r=>{r.headers??=new qa;for(let[o,s]of Object.entries(qs))r.headers[o]=s;return r}]}),"getApifyClientOptions");async function xt(t,e){t=ci(t);let r=new si(ss(t,e)),o;try{o=await r.user("me").get()}catch{return null}return Xe(se()),or(se(),JSON.stringify({token:r.token,...o},null," ")),r}l(xt,"getLoggedClient");var is=l(t=>Ae(t,M),"getLocalConfigPath"),Te=l(t=>{if(ne(t))return JSON.parse(_t(t,{encoding:"utf-8"}))},"getJsonFileContent"),De=l(t=>Te(is(t)),"getLocalConfig"),ir=l(async(t,e)=>{let r=Ae(e||ie.cwd(),M);await Ma(ri(r),{recursive:!0}),or(r,JSON.stringify(t,null," "))},"setLocalConfig"),sc=[ae(),"node_modules",".venv"],nr=l(async t=>{let e=ve();rr(t,ni()),rr(t,ai()),rr(t,e);let r=Ae(t,".gitignore"),o="";ne(r)&&(o=_t(r,{encoding:"utf-8"}));let s=[];for(let i of sc)RegExp(`^${Ka(i)}$`,"mg").test(o)||s.push(i);s.length>0&&(o.length>0?(s.unshift("# Added by Apify CLI"),or(r,`
|
|
2
|
+
${s.join(`
|
|
3
|
+
`)}
|
|
4
|
+
`,{flag:"a"})):or(r,`${s.join(`
|
|
5
|
+
`)}
|
|
6
|
+
`,{flag:"w"}))},"setLocalEnv"),li=new za(Qa,Xa).define({"application/gzip":["tgz"],"text/typescript":["ts","tsx","mts"]},!0),ic=l((t,e)=>{let r=li.getType(t);return r?r.startsWith("text/")||r.includes("javascript")||r.includes("json")||r.includes("xml")||r.includes("application/node")||r.includes("application/toml")||r.includes("application/x-sh")||r.includes("application/x-httpd-php")?Et.TEXT:Et.BASE64:Wa(e)==="binary"?Et.BASE64:Et.TEXT},"getSourceFileFormat"),ui=l(async(t,e)=>t.map(r=>{let o=_t(Ae(e,r)),s=ic(r,o);return{name:r,format:s,content:s===Et.TEXT?o.toString("utf8"):o.toString("base64")}}),"createSourceFiles"),di=l(async t=>ii(["*","**/**"],{ignore:[".git/**","apify_storage","node_modules","storage","crawlee_storage"],gitignore:!0,dot:!0,cwd:t}),"getActorLocalFilePaths"),mi=l(async(t,e,r)=>{ne(t)&&await $t(t);let o=Ua(t),s=Ja("zip");s.pipe(o),e.forEach(i=>s.glob(i,{cwd:r})),await s.finalize()},"createActZip"),Ot=l(t=>{let e=ve();if(!ne(Ae(t,e)))return;let s=ti(Ae(t,e)).find(n=>!!n.match(Zo));if(!s)return;let i=_t(Ae(t,e,s)),a=li.getType(s);return{body:i,contentType:a,fileName:s}},"getLocalInput"),pi=l(async()=>{let t=ai();ne(ae())&&ne(t)&&await It(t)},"purgeDefaultQueue"),fi=l(async()=>{let t=ni();ne(ae())&&ne(t)&&await It(t)},"purgeDefaultDataset"),gi=l(async()=>{let t=ve();if(!ne(ae())||!ne(t))return;let e=ti(t),r=[];e.forEach(o=>{o.match(Zo)||r.push($t(Ae(t,o)))}),await Promise.all(r)},"purgeDefaultKeyValueStore"),Se=l(async({job:t,timeoutMillis:e,apifyClient:r})=>{let{id:o,status:s}=t,i=r||new si({baseUrl:ie.env.APIFY_CLIENT_BASE_URL});if(rc.includes(s)){if(ie.env.APIFY_NO_LOGS_IN_TESTS)return;let a=await i.log(o).get();ie.stderr.write(a);return}return new Promise(async a=>{let n=await i.log(o).stream();if(!n){a("no-logs");return}let c=null;n.on("data",d=>{ie.env.APIFY_NO_LOGS_IN_TESTS||ie.stderr.write(d.toString())}),n.once("end",()=>{a("finished"),c&&clearTimeout(c)}),e&&(c=setTimeout(()=>{n.destroy(),a("timeouts")},e))})},"outputJobLog");var hi=l(async()=>(await ii([`${ae()}/**`,`!${ve()}/${ei.INPUT}.*`,`!${ve()}/${ei.INPUT}_CLI-*`])).length===0,"checkIfStorageIsEmpty"),Nt=l(t=>{if(!Rt.REGEX.test(t))throw new Error("The Actor name must be a DNS hostname-friendly string (e.g. my-newest-actor).");if(t.length<Rt.MIN_LENGTH)throw new Error("The Actor name must be at least 3 characters long.");if(t.length>Rt.MAX_LENGTH)throw new Error("The Actor name must be a maximum of 30 characters long.")},"validateActorName"),yi=l(t=>{let e=t.replaceAll(/[^a-zA-Z0-9-]/g,"-");return e.length<Rt.MIN_LENGTH&&(e=`${e}-apify-actor`),e=e.replaceAll(/^-+/g,"").replaceAll(/-+$/g,""),e.slice(0,Rt.MAX_LENGTH)},"sanitizeActorName"),ar=l(t=>tc(t,`^${We}`),"isPythonVersionSupported"),cr=l(t=>{let e=ec(we);return Za(t,e)},"isNodeVersionSupported"),lr=l(async({url:t,pathTo:e})=>{let r=await sr(t),o=[];r.on("data",i=>o.push(i)),await Ga(r),new Ha(Buffer.concat(o)).extractAllTo(e,!0)},"downloadAndUnzip");function Xe(t){let e=ri(t);ja(e,{recursive:!0})}l(Xe,"ensureApifyDirectory");var B=new es("YYYY-MM-DD [at] HH:mm:ss"),Lt=new es(`YYYY-MM-DD[
|
|
7
|
+
]HH:mm:ss`),wi=new es("YYYY-MM-DD"),Dt=new oi,oe=new oi({[ze.Day]:{DEFAULT:"d"},[ze.Hour]:{DEFAULT:"h"},[ze.Minute]:{DEFAULT:"m"},[ze.Month]:{DEFAULT:"M"},[ze.Second]:{DEFAULT:"s"},[ze.Week]:{DEFAULT:"w"},[ze.Year]:{DEFAULT:"y"}});function ur(t,e){if("groupBy"in Object)return Object.groupBy(t,e);let r={},o=0;for(let s of t){let i=e(s,o++);r[i]||(r[i]=[]),r[i].push(s)}return r}l(ur,"objectGroupBy");function Ai(t,e){let r=new Map,o=0;for(let s of t){let i=e(s,o++),a=r.get(i);a?a.push(s):r.set(i,[s])}return r}l(Ai,"mapGroupBy");function N(t){console.log(JSON.stringify(t,null,2))}l(N,"printJsonToStdout");import dr from"chalk";import ns from"indent-string";import lc from"string-width";import uc from"strip-ansi";import vi from"widest-line";import as from"wrap-ansi";import nc from"chalk";import ac from"indent-string";import bi from"string-width";import cc from"wrap-ansi";var Pe;function re(){if(Pe)return Pe;let t=Number(process.env.APIFY_CLI_MAX_LINE_WIDTH);if(!Number.isNaN(t))Pe=t;else if(!process.stdout.isTTY)Pe=80;else{let e=process.stdout.getWindowSize?.()[0]??-1;e<1?Pe=80:e<40?Pe=40:Pe=e}return Pe}l(re,"getMaxLineWidth");var at=class{static{l(this,"BaseCommandRenderer")}command;entrypoint;constructor(e,r){this.entrypoint=e,this.command=r}pushShortDescription(e){this.command.shortDescription?e.push(this.command.shortDescription,""):this.command.description&&e.push(this.command.description.split(`
|
|
8
|
+
`)[0],"")}pushDescription(e){if(!this.command.description)return;e.push(nc.bold("DESCRIPTION"));let r=cc(this.command.description,re()-2,{trim:!1}),o=ac(r,2);e.push(o),e.push("")}pushNewLineBeforeNewEntryIfLengthIsPastTheLimit({state:e,itemToAdd:r,indentSize:o}){let s=bi(e.join(" ").split(`
|
|
9
|
+
`).at(-1)||"")+o,i=bi(r);s+i>re()&&e.push(`
|
|
10
|
+
`),e.push(r)}kebabFlagName(e){return ce(le(e)).toLowerCase()}makeFlagString(e,r){let o=this.kebabFlagName(e),s=r.char?`-${r.char}`:`--${o}`;switch(r.flagTag){case"boolean":return s;case"string":case"integer":{let i=r.choicesType?.length?`${r.choicesType.join("|")}`:"<value>";return`${s} ${i}`}default:throw new RangeError(`Unhandled flag type: ${r.flagTag}`)}}};var mr=class extends at{static{l(this,"CommandHelp")}render(){let e=[];return this.pushShortDescription(e),this.pushUsageString(e),this.command.description&&this.pushDescription(e),e.join(`
|
|
11
|
+
`).trim()}selectiveRender(e){let r=[];return e.showShortDescription&&this.pushShortDescription(r),e.showUsageString&&this.pushUsageString(r),e.showDescription&&this.command.description&&this.pushDescription(r),r.join(`
|
|
12
|
+
`).trim()}pushUsageString(e){e.push(dr.bold("USAGE"));let r=`$ ${this.entrypoint} ${this.command.name}`,o=2+lc(r),s=[r],i=Object.entries(this.command.args??{});if(i.length)for(let[f,p]of i){if(typeof p=="string")throw new RangeError("This is a type-check only value, do not actually use it");this.pushNewLineBeforeNewEntryIfLengthIsPastTheLimit({state:s,itemToAdd:p.required?`<${f}>`:`[${f}]`,indentSize:o})}let a=Object.entries(this.command.flags??{}).filter(([,f])=>{if(typeof f=="string")throw new RangeError("This is a type-check only value, do not actually use it");return!f.hidden});this.command.enableJsonFlag&&a.push(["json",{choicesType:null,flagTag:"boolean",hasDefault:!1,required:!1,stdin:null,builder:null,aliases:void 0,char:void 0,description:"Format the command output as JSON",hidden:void 0,exclusive:void 0}]);let n=new Map(a.sort((f,p)=>{if(typeof f[1]=="string")throw new RangeError("This is a type-check only value, do not actually use it");if(typeof p[1]=="string")throw new RangeError("This is a type-check only value, do not actually use it");return f[1].required&&!p[1].required?-1:!f[1].required&&p[1].required?1:f[0].localeCompare(p[0])})),c=new Set;if(a.length)for(let[f,p]of n){if(typeof p=="string")throw new RangeError("This is a type-check only value, do not actually use it");if(c.has(f))continue;let h=p.required,b=[this.makeFlagString(f,p)];if(p.exclusive?.length)for(let C of p.exclusive){c.add(C);let v=n.get(C),I=this.makeFlagString(C,v);b.push(I),v.required&&(h=!0)}this.pushNewLineBeforeNewEntryIfLengthIsPastTheLimit({state:s,itemToAdd:h?b.join(" | "):`[${b.join(" | ")}]`,indentSize:o})}let d=as(s.join(" "),re()-o),u=ns(d,o+1).trim();e.push(` ${u}`,""),i.length&&this.pushArguments(e,i),a.length&&this.pushFlags(e,n)}pushArguments(e,r){if(!r.length)return;e.push(dr.bold("ARGUMENTS"));let o=vi(r.map(([s])=>s).join(`
|
|
13
|
+
`));for(let[s,i]of r){let a=`${s.padEnd(o)} ${i.description}`,n=as(a,re()-o-2),c=ns(n,o+2+2).trim();e.push(` ${c}`)}e.push("")}pushFlags(e,r){if(!r.size)return;e.push(dr.bold("FLAGS"));let o=new Map;for(let[i,a]of r){let n=[];switch(a.char?n.push(`-${a.char},`):n.push(" ".repeat(3)),a.flagTag){case"boolean":n.push(`--${this.kebabFlagName(i)}`);break;case"string":case"integer":{let c=a.choicesType?"<option>":"<value>";n.push(`--${this.kebabFlagName(i)}=${dr.underline(c)}`);break}default:throw new Error(`Unhandled flag tag: ${a.flagTag}`)}o.set(n.join(" "),a)}let s=vi([...o.keys()].join(`
|
|
14
|
+
`));for(let[i,a]of o){let n=s-uc(i).length,c=`${i}${" ".repeat(n)} ${a.description??""}`;a.choicesType?.length&&(c+=`
|
|
15
|
+
<options: ${a.choicesType.join("|")}>`);let d=as(c,re()-s),u=ns(d,s).trim().split(`
|
|
16
|
+
`).map(f=>/^-[a-z]/.test(f.trim())?f:` ${f}`).join(`
|
|
17
|
+
`);e.push(` ${u}`)}e.push("")}};import dc from"chalk";import mc from"indent-string";import pc from"widest-line";import fc from"wrap-ansi";var Pt=class extends at{static{l(this,"CommandWithSubcommandsHelp")}render(){let e=[];return this.pushShortDescription(e),this.command.description&&this.pushDescription(e),this.pushSubcommands(e),e.join(`
|
|
18
|
+
`).trim()}selectiveRender(e){let r=[];return e.showShortDescription&&this.pushShortDescription(r),e.showDescription&&this.command.description&&this.pushDescription(r),e.showSubcommands&&this.pushSubcommands(r),r.join(`
|
|
19
|
+
`).trim()}pushSubcommands(e){if(!this.command.subcommands?.length)return;e.push(dc.bold("SUBCOMMANDS"));let r=pc(this.command.subcommands.map(o=>`${this.command.name} ${o.name}`).join(`
|
|
20
|
+
`));for(let o of this.command.subcommands){let s=o.shortDescription||o.description?.split(`
|
|
21
|
+
`)[0]||"",i=`${this.command.name} ${o.name.padEnd(r-this.command.name.length-1)} ${s}`,a=fc(i,re()-r-2),n=mc(a,r+2+2).trim();e.push(` ${n}`)}e.push("")}};var Ft=new Map;function cs(t,e){if(e.name.toLowerCase()!==e.name){m({message:`Command name "${e.name}" is not correctly set up internally. Make sure you fill out the "name" field in the command class extension.`});return}if(e.subcommands?.length){Ft.set(e,new Pt(t,e));for(let r of e.subcommands)cs(`${t} ${e.name}`,r)}else Ft.set(e,new mr(t,e))}l(cs,"registerCommandForHelpGeneration");function pr(t){let e=Ft.get(t);if(!e)throw new Error(`No help renderer found for command ${t.name}`);return e.render()}l(pr,"renderHelpForCommand");function fr(t,e){let r=Ft.get(t);if(!r)throw new Error(`No help renderer found for command ${t.name}`);return r.selectiveRender(e)}l(fr,"selectiveRenderHelpForCommand");function Ii(t,e){return t[0].name.localeCompare(e[0].name)}l(Ii,"sortByName");function gr(t){let e=ee(),r=[];r.push("Apify command-line interface (CLI) helps you manage the Apify cloud platform and develop, build, and deploy Apify Actors.",""),r.push(kt.bold("VERSION")),r.push(` ${e.fullVersionString}`),r.push(""),r.push(kt.bold("USAGE")),r.push(` $ ${t} <command> [options]`),r.push("");let o=Ai(Ft,([a,n])=>n.entrypoint.includes(" ")||a.hidden?"ignored":n instanceof Pt?"subcommand":"command"),s=o.get("subcommand")?.sort(Ii),i=o.get("command")?.sort(Ii);if(s?.length){r.push(kt.bold("TOPICS"));let a=[],n=Si(s.map(([c])=>c.name).join(`
|
|
22
|
+
`));for(let[c]of s){if(c.hidden)continue;let d=c.shortDescription||c.description?.split(`
|
|
23
|
+
`)[0]||"",u=`${c.name.padEnd(n)} ${d}`,f=Ci(u,re()-n-2);a.push(` ${Ti(f,n+2+2).trim()}`)}r.push(...a,"")}if(i?.length){r.push(kt.bold("COMMANDS"));let a=[],n=Si(i.map(([c])=>c.name).join(`
|
|
24
|
+
`));for(let[c]of i){if(c.hidden)continue;let d=c.shortDescription||c.description?.split(`
|
|
25
|
+
`)[0]||"",u=`${c.name.padEnd(n)} ${d}`,f=Ci(u,re()-n-2);a.push(` ${Ti(f,n+2+2).trim()}`)}r.push(...a,"")}return r.push(kt.bold("TROUBLESHOOTING")," For general support, reach out to us at https://apify.com/contact",""," If you believe you are encountering a bug, file it at https://github.com/apify/apify-cli/issues/new"),r.join(`
|
|
26
|
+
`).trim()}l(gr,"renderMainHelpMenu");function Ei(t){return t.replace(/[-_\s](.)/g,(e,r)=>r.toUpperCase())}l(Ei,"camelCaseString");function ce(t){return t.replace(/[\s_]+/g,"-")}l(ce,"kebabCaseString");function le(t){return t.replace(/([A-Z])/g,"-$1").toLowerCase()}l(le,"camelCaseToKebabCase");var J=new Map,g=class{static args;static flags;static subcommands;static enableJsonFlag=!1;static name;static shortDescription;static description;static aliases;static hidden;static hiddenAliases;telemetryData={};flags;args;entrypoint;constructor(e){this.entrypoint=e}get ctor(){return this.constructor}pluralString(e,r,o){return e===1?r:o}printHelp(){console.log(pr(this.ctor)),process.exit(0)}async _run(e){e.help&&this.printHelp(),this.args={},this.flags={},this.ctor.enableJsonFlag&&(typeof e.json=="boolean"?this.flags.json=e.json:this.flags.json=!1);let r=new Map;if(this.ctor.args)for(let[o,s]of Object.entries(this.ctor.args)){if(typeof s=="string")throw new RangeError("Do not provide the string for the json arg! It is a type level assertion!");let i=o.replaceAll(" ",""),a=Ei(o);if(e[i])switch(s.argTag){case"string":default:this.args[a]=String(e[i]),e[i]==="-"&&s.stdin&&(this.args[a]=this._handleStdin(s.stdin)),s.catchAll&&(this.args[a]=this.args[a].split(",").join(" "));break}else s.required&&r.set(o,s)}if(r.size){this._printMissingRequiredArgs(r);return}if(this.ctor.flags)for(let[o,s]of Object.entries(this.ctor.flags)){if(typeof s=="string")throw new RangeError("Do not provide the string for the json arg! It is a type level assertion!");let i=ce(le(o)).toLowerCase(),a=Ei(i),n=i;if(i.startsWith("no-")&&(n=i.slice(3)),typeof e[n]<"u"){if(Array.isArray(e[n])){m({message:`Flag --${n} can only be specified once`});return}switch(s.flagTag){case"boolean":{this.flags[a]=i.startsWith("no-")?!e[n]:e[n];break}case"integer":{let c=Number(e[n]);if(Number.isNaN(c)||!Number.isInteger(c)){m({message:`The provided value for the '--${n}' flag could not be processed as an integer.`});return}this.flags[a]=c;break}case"string":default:{if(this.flags[a]=e[n],e[n]==="-"&&s.stdin&&(this.flags[a]=this._handleStdin(s.stdin)),!this.flags[a]){m({message:`Flag --${n} expects a value`});return}break}}}else if(s.required){m({message:`Flag --${n} is required`});return}else typeof s.hasDefault<"u"&&(this.flags[a]=s.hasDefault)}try{await this.run()}catch(o){m({message:o.message})}finally{}}_printMissingRequiredArgs(e){let r=fr(this.ctor,{showUsageString:!0}),o=hc([...e.keys()].join(`
|
|
27
|
+
`)),s=[];for(let[i,a]of e){let n=`${i.padEnd(o)} ${a.description}`,c=yc(n,re()-o-2),d=gc(c,o+2+2).trim();s.push(` ${$i.red(">")} ${d}`)}m({message:[`Missing ${e.size} required ${this.pluralString(e.size,"argument","arguments")}:`,...s,$i.gray(" See more help with --help"),"",r].join(`
|
|
28
|
+
`)})}_handleStdin(e){switch(e){case 2:return Ce?.toString("utf8")??"";default:return Ce}}_buildCommandStrings(e){let r=`${e||this.ctor.name}`;if(this.ctor.args){let o=!1;for(let[s,i]of Object.entries(this.ctor.args)){if(typeof i=="string")throw new RangeError("Do not provide the string for the json arg! It is a type level assertion!");if(i.catchAll){if(o)throw new RangeError("Only one catch-all argument is allowed in a command");o=!0,r+=` [${s}...]`}else r+=` [${s}]`}}return[r,...this.ctor.aliases??[]]}_buildCommandBuilder(){return e=>{let r=e;if(this.ctor.args)for(let[o,s]of Object.entries(this.ctor.args)){if(typeof s=="string")throw new RangeError("Do not provide the string for the json arg! It is a type level assertion!");o.toLowerCase()!=="json"&&(r=s.builder(r,o))}if(this.ctor.flags)for(let[o,s]of Object.entries(this.ctor.flags)){if(typeof s=="string")throw new RangeError("Do not provide the string for the json flag! It is a type level assertion!");if(o.toLowerCase()==="json")continue;let i=ce(le(o)).toLowerCase();i.startsWith("no-")?r=s.builder(r,i.slice(3)):r=s.builder(r,i)}if(this.ctor.subcommands?.length)for(let o of this.ctor.subcommands){let s=new o(`${this.entrypoint} ${this.ctor.name}`)._toYargs();r=r.command(s)}return this.ctor.enableJsonFlag&&(r=r.option("json",{boolean:!0,describe:"Format output as json."})),r}}_toYargs(){let e={handler:this._run.bind(this),command:this._buildCommandStrings(),describe:this.ctor.hidden?!1:this.ctor.description,builder:this._buildCommandBuilder()},r=[{...e,aliases:this.ctor.aliases}];if(this.ctor.hiddenAliases?.length)for(let o of this.ctor.hiddenAliases)r.push({...e,command:this._buildCommandStrings(o),describe:!1});return r}static registerCommand(e,r){let s=new this(e)._toYargs();if(r.command(s),cs(e,this),J.set(this.name,this),this.aliases?.length)for(let i of this.aliases)J.set(i,this);if(this.hiddenAliases?.length)for(let i of this.hiddenAliases)J.set(i,this);if(this.subcommands?.length)for(let i of this.subcommands){if(J.set(`${this.name} ${i.name}`,i),this.aliases?.length)for(let a of this.aliases)J.set(`${a} ${i.name}`,i);if(this.hiddenAliases?.length)for(let a of this.hiddenAliases)J.set(`${a} ${i.name}`,i);if(i.aliases?.length)for(let a of i.aliases){if(J.set(`${this.name} ${a}`,i),this.aliases?.length)for(let n of this.aliases)J.set(`${n} ${a}`,i);if(this.hiddenAliases?.length)for(let n of this.hiddenAliases)J.set(`${n} ${a}`,i)}if(i.hiddenAliases?.length)for(let a of i.hiddenAliases){if(J.set(`${this.name} ${a}`,i),this.aliases?.length)for(let n of this.aliases)J.set(`${n} ${a}`,i);if(this.hiddenAliases?.length)for(let n of this.hiddenAliases)J.set(`${n} ${a}`,i)}}}};async function Ri(t,e,r){let o={_:[],$0:"apify"};for(let[i,a]of Object.entries(r)){let[n,c]=i.split("_");if(n==="args")o[c]=a;else{let d=ce(le(c)).toLowerCase();d.startsWith("no-")?o[d.slice(3)]=!a:o[d]=a}}await new e(t)._run(o)}l(Ri,"internalRunCommand");import{once as Tc}from"events";import{constants as _i,fstat as Ac}from"fs";import xi from"process";import{promisify as bc}from"util";import wc from"chalk";function $(t,...e){process.env.APIFY_CLI_DEBUG&&console.error(wc.gray(`[${t}]`),...e)}l($,"cliDebugPrint");var vc=bc(Ac),ls;async function Oi(){if(ls)return ls;let t=xi.stdin,e={isTTY:t.isTTY,hasData:!1,waitDelay:0,stream:t},r=await vc(0).then(o=>{if($("useStdin",{stat:o,isRegularFile:o.isFile(),isDirectory:o.isDirectory(),isBlockDevice:o.isBlockDevice(),isCharDevice:o.isCharacterDevice(),isSymbolicLink:o.isSymbolicLink(),isFIFO:o.isFIFO(),isSocket:o.isSocket()}),xi.platform==="win32"){if((o.mode&_i.S_IFIFO)===_i.S_IFIFO)return 100;if(o.isFile())return 50}return o.isFIFO()||o.isFile()||(o.isSocket()?50:!1)}).catch(()=>!1);return $("useStdin",{isTTY:e.isTTY,pipedIn:r,readableEnded:t.readableEnded}),(!t.isTTY||r!==!1&&(t.isTTY!==void 0||!t.readableEnded))&&(e.hasData=!0),typeof r=="number"&&(e.waitDelay=r),ls=e,e}l(Oi,"useStdin");async function Ni(){let{hasData:t,waitDelay:e,stream:r}=await Oi();if(!t)return;let o=[],s=new AbortController,i=null;e&&(i=setTimeout(()=>{s.abort()},e).unref()),r.on("data",n=>{o.push(n),i&&(clearTimeout(i),i=null)});try{await Tc(r,"end",{signal:s.signal})}catch(n){if(n.name==="AbortError")return}i&&clearTimeout(i);let a=Buffer.concat(o);if(a.length)return a}l(Ni,"readStdin");import{gt as xc}from"semver";import{existsSync as Sc,mkdirSync as Cc,readFileSync as Ic,writeFileSync as $c}from"fs";import{dirname as Ec}from"path";function Rc(t){if(t.version&&t.version>=1)return!1;let e=t;if(e.latestNpmVersionCheckedAt){let r=new Date(e.latestNpmVersionCheckedAt).getTime(),o=e.latestNpmVersion;$("LocalStateV0ToV1","Migrating state from v0 to v1",{oldState:t,newState:{versionCheck:{lastChecked:r,lastVersion:o}}}),ds({version:1},s=>{s.versionCheck={lastChecked:r,lastVersion:o}})}return!0}l(Rc,"migrateStateV0ToV1");var _c={version:1};function us(){let t=er();if(!Sc(t))return _c;let r=JSON.parse(Ic(t,"utf-8"));return Rc(r)?us():r}l(us,"useLocalState");function ds(t,e){let r={...t};e(r);let o=er(),s=Ec(o);Cc(s,{recursive:!0}),$c(er(),JSON.stringify(r,null," "))}l(ds,"updateLocalState");var hr=ee(),Li=`Apify CLI/${hr.version} (https://github.com/apify/apify-cli)`,Oc=["https://1.1.1.1","https://8.8.8.8"];async function Nc(t=500){let e=new AbortController,r=setTimeout(()=>{e.abort()},t),o=await Promise.any(Oc.map(async s=>fetch(s,{signal:e.signal,headers:{"User-Agent":Li},keepalive:!1}))).catch(()=>null);return clearTimeout(r),o?o.ok?($("isOnline",{state:"online",site:o.url}),!0):($("isOnline",{state:"offline"}),!1):($("isOnline",{state:"timeout"}),!1)}l(Nc,"isOnline");async function Lc(t){let e=await fetch("https://api.github.com/repos/apify/apify-cli/releases/latest",{headers:{"User-Agent":Li}});if(!e.ok)return $("useCLIVersionCheck","Failed to fetch latest version",{statusCode:e.status,body:await e.text()}),x({message:"Failed to fetch latest version of Apify CLI, using the cached version instead."}),null;let o=(await e.json()).tag_name.replace(/^v/,"");return $("useCLIVersionCheck","Fetched latest version",{version:o}),ds(t,s=>{s.versionCheck={lastChecked:Date.now(),lastVersion:o}}),o}l(Lc,"getLatestVersion");function Di(){return!!(process.env.APIFY_CLI_SKIP_UPDATE_CHECK&&!["0","false"].includes(process.env.APIFY_CLI_SKIP_UPDATE_CHECK))}l(Di,"shouldSkipVersionCheck");async function Pi(t=!1){let e=us(),r=!e.versionCheck||Date.now()-e.versionCheck.lastChecked>Js,o=t||r&&await Nc(),s=o?await Lc(e):e.versionCheck?.lastVersion;if(!s)return{currentVersion:hr.version,latestVersion:"unknown",shouldUpdate:!1,cacheHit:!1};let i=xc(s,hr.version);return{currentVersion:hr.version,latestVersion:s,shouldUpdate:i,cacheHit:!o}}l(Pi,"useCLIVersionCheck");import{jaroWinkler as Dc}from"@skyra/jaro-winkler";import Pc from"js-levenshtein";function Ut(t){let e=[...J.entries()].sort(([s],[i])=>s.localeCompare(i)),r=t.toLowerCase();return e.map(([s,i])=>{let a=s.toLowerCase(),n=s.split(" "),c=n[n.length-1].toLowerCase(),d=i.aliases?.includes(c)||i.hiddenAliases?.includes(c)||!1,u=Pc(r,a),f=Dc(r,a),p=u<=2||f>=.975;return p?($("useCommandSuggestions",{inputString:r,lowercased:a,matches:p,levenshtein:u,jaroWinkler:f}),d?{string:`${a} (alias for ${i.name})`,distance:f}:{string:`${a}`,distance:f}):null}).filter(s=>s!==null).sort((s,i)=>i.distance-s.distance).map(s=>s.string)}l(Ut,"useCommandSuggestions");var Ce=await Ni(),yr=Fc().version(!1).help(!1).parserConfiguration({"camel-case-expansion":!1,"dot-notation":!1,"parse-numbers":!1,"parse-positional-numbers":!1,"short-option-groups":!1}).strict().locale("en").updateStrings({"Not enough arguments following: %s":"MISSING_ARGUMENT_INPUT %s","Unknown argument: %s":{one:"UNKNOWN_ARGUMENT_INPUT %s",other:"UNKNOWN_ARGUMENTS_INPUT %s"},"Not enough non-option arguments: got %s, need at least %s":{one:'NOT_ENOUGH_NON_OPTION_ARGUMENTS_INPUT {"got":%s,"need":%s}',other:'NOT_ENOUGH_NON_OPTION_ARGUMENTS_INPUT {"got":%s,"need":%s}'},"Arguments %s and %s are mutually exclusive":'ARGUMENTS_ARE_MUTUALLY_EXCLUSIVE_INPUT ["%s","%s"]',"Invalid values:":"INVALID_VALUES_INPUT","Argument: %s, Given: %s, Choices: %s":'INVALID_ARGUMENT_OPTION {"argument":"%s","given":%s,"choices":[%s]}'}).option("help",{boolean:!0,describe:"Shows this help message.",alias:"h"});yr.usageConfiguration({"hide-types":!0});yr.middleware(async t=>{let e=J.get("upgrade");[e.name,...e.aliases??[]].some(o=>t._[0]===o)||Di()||await Ri(t.$0,e,{flags_internalAutomaticCall:!0})});var ct=ee(),jt=`Apify CLI/${ct.version} (https://github.com/apify/apify-cli)`;function Df(t){ct.installMethod!=="bundle"&&(kc(de.version,we)||(m({message:`${t} CLI requires Node.js version ${we}. Your current version is ${de.version}.`}),de.exit(1)))}l(Df,"processVersionCheck");function Uc(t){(t.v===!0||t.version===!0)&&(console.log(ct.fullVersionString),de.exit(0))}l(Uc,"printCLIVersionAndExitIfFlagUsed");function jc(t,e){(t.help===!0||t.h===!0||t._.length===0)&&(console.log(gr(e)),de.exit(0))}l(jc,"printHelpAndExitIfFlagUsedOrNoCommandPassed");async function Pf(t){$("CLIMetadata",{...ct,fullVersionString:ct.fullVersionString,argv:de.argv,cwd:de.cwd(),execPath:de.execPath}),yr.scriptName(t),await yr.parse(de.argv.slice(2),{},(e,r)=>{if(e&&r._.length>0){$("RunCLIError",{type:"parsed",error:e?.message,parsed:r});let o=e.message.split(" ").map(n=>n.trim()),s=[`${r._[0]} ${r._[1]}`,`${r._[0]}`],i=J.get(s.find(n=>J.has(n))??"");if(!i){let n=Ut(String(r._[0])),c=ue.gray(`Command ${ue.whiteBright(r._[0])} not found`);n.length&&(c+=`
|
|
29
|
+
`,c+=ue.gray(`Did you mean: ${n.map(d=>ue.whiteBright(d)).join(", ")}?`)),m({message:c});return}let a=Object.entries(i.flags??{}).filter(([,n])=>typeof n!="string").map(([n,c])=>{let d=c;return{flagKey:ce(le(n)).toLowerCase(),char:d.char,aliases:d.aliases?.map(f=>ce(le(f)).toLowerCase()),matches(f){return this.flagKey===f||this.char===f||this.aliases?.some(p=>p===f)}}});switch(o[0]){case"MISSING_ARGUMENT_INPUT":{for(let n of a)if(n.matches(o[1])){m({message:`Flag --${n.flagKey} expects a value`});return}break}case"ARGUMENTS_ARE_MUTUALLY_EXCLUSIVE_INPUT":{let n=JSON.parse(o[1]);m({message:["The following errors occurred:",...n.sort((c,d)=>c.localeCompare(d)).map(c=>{let d=r[c],f=typeof d=="boolean"?`--${c}`:`--${c}=${d}`;return` ${ue.red(">")} ${ue.gray(`${f} cannot also be provided when using ${n.filter(p=>p!==c).map(p=>`--${p}`).join(", ")}`)}`}),` ${ue.red(">")} See more help with --help`].join(`
|
|
30
|
+
`)});break}case"UNKNOWN_ARGUMENT_INPUT":case"UNKNOWN_ARGUMENTS_INPUT":{let n=a.length?"flag":i.subcommands?.length?"subcommand":"argument",c=n==="flag"?o[1].length===1?`-${o[1]}`:`--${o[1]}`:o[1],d=n==="subcommand"?Ut(`${r._[0]} ${o[1]}`):[],u=[ue.gray(`Nonexistent ${n}: ${ue.whiteBright(c)}`)];d.length&&u.push(ue.gray(` Did you mean: ${d.map(f=>ue.whiteBright(f)).join(", ")}?`)),m({message:[...u,"",fr(i,{showUsageString:!0,showSubcommands:!0})].join(`
|
|
31
|
+
`)});break}case"INVALID_VALUES_INPUT":if(o[2]==="INVALID_ARGUMENT_OPTION"){let n=o.slice(3).join(" ");try{let c=JSON.parse(n),u=(a.some(f=>f.matches(c.argument))?"flag":"argument")==="flag"?`--${c.argument}`:c.argument;m({message:[`Expected ${u} to have one of the following values: ${c.choices.join(", ")}`,` ${ue.red(">")} See more help with --help`].join(`
|
|
32
|
+
`)});break}catch{$("RunCLIError",{type:"parse_error_invalid_choices",error:e.message,parsed:r,jsonPart:n})}}default:$("RunCLIError",{type:"unhandled",error:e.message,parsed:r}),console.error(["The CLI encountered an unhandled argument parsing error!","Please report this issue at https://github.com/apify/apify-cli/issues, and provide the following information:","",`- Stack:
|
|
33
|
+
${e.stack}`,"","- Arguments (!!!only provide these as is if there is no sensitive information!!!):",` ${JSON.stringify(de.argv.slice(2))}`,"",`- CLI version: \`${ct.fullVersionString}\``,`- CLI debug logs (process.env.APIFY_CLI_DEBUG): ${de.env.APIFY_CLI_DEBUG?"Enabled":"Disabled"}`,`- Stdin data? ${Ce?"Yes":"No"}`].join(`
|
|
34
|
+
`)),de.exit(1)}}else Mc(r,t)})}l(Pf,"runCLI");function Mc(t,e){t._.length===0&&(Uc(t),jc(t,e))}l(Mc,"handleParseResults");import{APIFY_ENV_VARS as zc}from"@apify/consts";import Mt from"process";import{pipeline as Bc}from"stream/promises";import{MemoryStorage as Vc}from"@crawlee/memory-storage";import{ApifyClient as Gc}from"apify-client";import ki from"ow";import{ACTOR_ENV_VARS as Fi,APIFY_ENV_VARS as Ui,KEY_VALUE_STORE_KEYS as Hc,LOCAL_ACTOR_ENV_VARS as Yc}from"@apify/consts";var Bt={KEY_VALUE_STORE:"KEY_VALUE_STORE",DATASET:"DATASET",REQUEST_QUEUE:"REQUEST_QUEUE"},ms=l(async()=>{let t=Mt.env[Ui.TOKEN];if(t)return t;let e=await k();if(!e||!e.token)throw new Error("Apify token is not set. Please set it using the environment variable APIFY_TOKEN or apify login command.");return e.token},"getApifyTokenFromEnvOrAuthFile"),Qe=l(async(t={},e=Reflect.has(Mt.env,Ui.IS_AT_HOME))=>{let r=ae();if(r&&!e)return new Vc({localDataDirectory:r,...t});let o=await ms();return new Gc({...ss(o),...t})},"getApifyStorageClient"),Vt=l(t=>{let e=Fi[`DEFAULT_${t}_ID`];return Mt.env[e]||Yc[e]},"getDefaultStorageId"),ps=l(async t=>{ki(t,ki.string);let e=await Qe(),r=Vt(Bt.KEY_VALUE_STORE),o=await e.keyValueStore(r).getRecord(t,{stream:!0});o&&await Bc(o.value,Mt.stdout,{end:!1})},"outputRecordFromDefaultStore"),ji=l(async()=>ps(Mt.env[Fi.INPUT_KEY]||Hc.INPUT),"outputInputFromDefaultStore");function Jc(t){return{argTag:"string",builder:l((e,r)=>(e.positional(r,{type:"string",alias:t.aliases,description:t.description,demandOption:!1}),e),"builder"),required:t.required??!1,stdin:t.stdin??1,description:t.description,aliases:t.aliases,catchAll:t.catchAll??!1}}l(Jc,"stringArg");var w={string:Jc};var A={string:qc,boolean:Kc,integer:Wc};function qc(t){return{flagTag:"string",builder:l((e,r,o)=>{let s=new Set([...t.aliases??[],...o??[]]);return t.char&&s.add(t.char),s.delete(r),e.option(r,{demandOption:!1,describe:t.description,alias:[...s].map(i=>ce(le(i))),hidden:t.hidden??!1,conflicts:t.exclusive,choices:t.choices,string:!0,nargs:1})},"builder"),choicesType:t.choices,required:t.required??!1,hasDefault:t.default,stdin:t.stdin??1,description:t.description,aliases:t.aliases,char:t.char,hidden:t.hidden,exclusive:t.exclusive}}l(qc,"stringFlag");function Kc(t){return{flagTag:"boolean",builder:l((e,r,o)=>{let s=new Set([...t.aliases??[],...o??[]]);return t.char&&s.add(t.char),s.delete(r),e.option(r,{demandOption:!1,describe:t.description,alias:[...s].map(i=>ce(le(i))),hidden:t.hidden??!1,conflicts:t.exclusive,boolean:!0})},"builder"),choicesType:null,required:t.required??!1,hasDefault:t.default,stdin:t.stdin??1,description:t.description,aliases:t.aliases,char:t.char,hidden:t.hidden,exclusive:t.exclusive}}l(Kc,"booleanFlag");function Wc(t){return{flagTag:"integer",builder:l((e,r,o)=>{let s=new Set([...t.aliases??[],...o??[]]);return t.char&&s.add(t.char),s.delete(r),e.option(r,{demandOption:!1,describe:t.description,alias:[...s].map(i=>ce(le(i))),hidden:t.hidden??!1,conflicts:t.exclusive,choices:t.choices,string:!0,nargs:1})},"builder"),choicesType:null,required:t.required??!1,hasDefault:t.default,stdin:t.stdin??1,description:t.description,aliases:t.aliases,char:t.char,hidden:t.hidden,exclusive:t.exclusive}}l(Wc,"integerFlag");var lt=class extends g{static name="charge";static description="Charge for a specific event in the pay-per-event Actor run.";static args={eventName:w.string({description:"Name of the event to charge for",required:!0})};static flags={count:A.integer({description:"Number of events to charge",required:!1,default:1}),"idempotency-key":A.string({description:"Idempotency key for the charge request",required:!1}),"test-pay-per-event":A.boolean({description:"Test pay-per-event charging without actually charging",required:!1,default:!1})};async run(){let{eventName:e}=this.args,{count:r,testPayPerEvent:o,idempotencyKey:s}=this.flags;if(!!!process.env.APIFY_IS_AT_HOME){T({message:`No platform detected: would charge ${r} events of type "${e}" with idempotency key "${s??"not-provided"}".`,stdout:!0});return}if(o){T({message:`PPE test mode: would charge ${r} events of type "${e}" with idempotency key "${s??"not-provided"}".`,stdout:!0});return}let a=await ms(),n=await xt(a);if(!n)throw new Error("Apify token is not set. Please set it using the environment variable APIFY_TOKEN.");let c=process.env[zc.ACTOR_RUN_ID];if(!c)throw new Error("Charge command must be executed in a running Actor. Run ID not found.");if((await n.run(c).get())?.pricingInfo?.pricingModel!=="PAY_PER_EVENT")throw new Error("Charge command can only be used with pay-per-event pricing model.");T({message:`Charging ${r} events of type "${e}" with idempotency key "${s??"not-provided"}" (runId: ${c}).`,stdout:!0}),await n.run(c).charge({eventName:e,count:r,idempotencyKey:s})}};var ut=class extends g{static name="get-input";static description="Gets the Actor input value from the default key-value store associated with the Actor run.";async run(){await ji()}};import{ACTOR_ENV_VARS as fs,APIFY_ENV_VARS as Mi}from"@apify/consts";import{createHmacSignature as Xc}from"@apify/utilities";var dt=class extends g{static name="get-public-url";static description="Get an HTTP URL that allows public access to a key-value store item.";static args={key:w.string({required:!0,description:"Key of the record in key-value store"})};async run(){let{key:e}=this.args;if([void 0,"false",""].includes(process.env[Mi.IS_AT_HOME])){m({message:"get-public-url is not yet implemented for local development"}),process.exitCode=255;return}let r=process.env[Mi.API_PUBLIC_BASE_URL],o=process.env[fs.DEFAULT_KEY_VALUE_STORE_ID];if(!o){m({message:`Missing environment variable: ${fs.DEFAULT_KEY_VALUE_STORE_ID}. Please set it before running the command.`}),process.exitCode=5;return}let i=await(await Qe()).keyValueStore(o).get(),a=new URL(`${r}/v2/key-value-stores/${o}/records/${e}`);if(!i){m({message:`Key-Value store with ID '${o}' was not found. Ensure the store exists and that the correct ID is set in ${fs.DEFAULT_KEY_VALUE_STORE_ID}.`}),process.exitCode=250;return}let{urlSigningSecretKey:n}=i;n&&a.searchParams.append("signature",Xc(n,e)),console.log(a.toString())}};var mt=class extends g{static name="get-value";static description="Gets a value from the default key-value store associated with the Actor run.";static args={key:w.string({required:!0,description:"Key of the record in key-value store"})};async run(){let{key:e}=this.args;await ps(e)}};var pt=class extends g{static name="push-data";static description=`Saves data to Actor's run default dataset.
|
|
35
|
+
|
|
36
|
+
Accept input as:
|
|
37
|
+
- JSON argument:
|
|
38
|
+
$ apify actor push-data {"key": "value"}
|
|
39
|
+
- Piped stdin:
|
|
40
|
+
$ cat ./test.json | apify actor push-data`;static args={item:w.string({description:"JSON string with one object or array of objects containing data to be stored in the default dataset."})};async run(){let{item:e}=this.args,r=e||Ce;if(!r){m({message:"No item was provided."});return}let o=await Qe(),s=Vt(Bt.DATASET),i;try{i=JSON.parse(r.toString("utf8"))}catch(a){throw new Error(`Failed to parse data as JSON string: ${a.message}`)}await o.dataset(s).pushItems(i)}};var ft=class extends g{static name="set-value";static description=`Sets or removes record into the default key-value store associated with the Actor run.
|
|
41
|
+
|
|
42
|
+
It is possible to pass data using argument or stdin.
|
|
43
|
+
|
|
44
|
+
Passing data using argument:
|
|
45
|
+
$ apify actor set-value KEY my-value
|
|
46
|
+
|
|
47
|
+
Passing data using stdin with pipe:
|
|
48
|
+
$ cat ./my-text-file.txt | apify actor set-value KEY --contentType text/plain`;static args={key:w.string({required:!0,description:"Key of the record in key-value store."}),value:w.string({required:!1,description:`Record data, which can be one of the following values:
|
|
49
|
+
- If empty, the record in the key-value store is deleted.
|
|
50
|
+
- If no \`contentType\` flag is specified, value is expected to be any JSON string value.
|
|
51
|
+
- If options.contentType is set, value is taken as is.`})};static flags={contentType:A.string({char:"c",description:'Specifies a custom MIME content type of the record. By default "application/json" is used.',required:!1})};async run(){let{key:e,value:r}=this.args,{contentType:o="application/json; charset=utf-8"}=this.flags,s=r||process.stdin,a=(await Qe()).keyValueStore(Vt(Bt.KEY_VALUE_STORE));s==null||s===""||s==="null"||s==="undefined"?await a.deleteRecord(e):await a.setRecord({key:e,value:s,contentType:o})}};var Ar=class extends g{static name="actor";static description="Manages runtime data operations inside of a running Actor.";static subcommands=[ft,pt,mt,dt,ut,lt];async run(){this.printHelp()}};import Ie from"chalk";import Qc from"process";async function ke({providedActorNameOrId:t,client:e}){let r=await k(),o=r.username||r.id,s=De(Qc.cwd())||{};if(t?.includes("/")){let i=await e.actor(t).get();return i?{valid:!0,userFriendlyId:`${i.username}/${i.name}`,id:i.id}:{valid:!1,reason:`Actor with ID "${t}" was not found`}}if(t){let i=await e.actor(t).get();if(i)return{valid:!0,userFriendlyId:`${i.username}/${i.name}`,id:i.id};let a=await e.actor(`${o}/${t.toLowerCase()}`).get();return a?{valid:!0,userFriendlyId:`${a.username}/${a.name}`,id:a.id}:{valid:!1,reason:`Actor with name or ID "${t}" was not found`}}if(s.name){let i=await e.actor(`${o}/${s.name}`).get();return i?{valid:!0,userFriendlyId:`${i.username}/${i.name}`,id:i.id}:{valid:!1,reason:`Actor with name "${s.name}" was not found`}}return{valid:!1,reason:"Unable to detect what Actor to create a build for"}}l(ke,"resolveActorContext");var gt=class extends g{static name="create";static description="Creates a new build of the Actor.";static flags={tag:A.string({description:'Build tag to be applied to the successful Actor build. By default, this is "latest".'}),version:A.string({description:"Optional Actor Version to build. By default, this will be inferred from the tag, but this flag is required when multiple versions have the same tag.",required:!1}),log:A.boolean({description:"Whether to print out the build log after the build is triggered."})};static args={actorId:w.string({description:"Optional Actor ID or Name to trigger a build for. By default, it will use the Actor from the current directory."})};static enableJsonFlag=!0;async run(){let{tag:e,version:r,json:o,log:s}=this.flags,{actorId:i}=this.args,a=await S(),n=await ke({providedActorNameOrId:i,client:a});if(!n.valid){m({message:`${n.reason}. Please run this command in an Actor directory, or specify the Actor ID.`,stdout:!0});return}let c=await a.actor(n.id).get(),u=ur(c.versions,I=>I.buildTag??"latest")[e??"latest"],f=c.versions.find(I=>I.versionNumber===r),p,h=e;if(f){if(e&&(!u||!u.some(I=>I.versionNumber===r))){m({message:`The Actor Version "${r}" does not have the tag "${e}".`,stdout:!0});return}p=r,h=f.buildTag??"latest"}else if(u&&(p=u[0].versionNumber,h=e??"latest",u.length>1&&!r)){m({message:`Multiple Actor versions with the tag "${e}" found. Please specify the version number using the "--version" flag.
|
|
52
|
+
Available versions for this tag: ${u.map(I=>Ie.yellow(I.versionNumber)).join(", ")}`,stdout:!0});return}if(!p){m({message:`No Actor versions with the tag "${e}" found. You can push a new version with this tag by using "apify push --build-tag=${e}".`,stdout:!0});return}let y=await a.actor(n.id).build(p,{tag:e});if(o){N(y);return}let b=[`${Ie.yellow("Actor")}: ${c?.username?`${c.username}/`:""}${c?.name??"unknown-actor"} (${Ie.gray(y.actId)})`,` ${Ie.yellow("Version")}: ${p} (tagged with ${Ie.yellow(h)})`,"",`${Ie.greenBright("Build Started")} (ID: ${Ie.gray(y.id)})`,` ${Ie.yellow("Build Number")}: ${y.buildNumber} (will get tagged once finished)`,` ${Ie.yellow("Started")}: ${B.display(y.startedAt)}`,""],C=`https://console.apify.com/actors/${y.actId}/builds/${y.buildNumber}`,v=`${Ie.blue("View in Apify Console")}: ${C}`;if(_({message:b.join(`
|
|
53
|
+
`),stdout:!0}),s){try{await Se({job:y,apifyClient:a})}catch(I){m({message:`Failed to print log for build with ID "${y.id}": ${I.message}`,stdout:!0})}_({message:"",stdout:!0})}_({message:v,stdout:!0})}};var br=class extends gt{static name="build"};import Hi from"process";import{DownloadItemsFormat as ol}from"apify-client";import te from"chalk";import{access as Zc,readFile as el}from"fs/promises";import tl,{resolve as Bi}from"path";import $e from"process";import rl from"mime";function Vi(t,e){let r,o;if(e)r=e,o="application/json";else{let s=Ot(t);s&&(rl.getExtension(s.contentType)==="json"?(r=JSON.parse(s.body.toString("utf8")),o="application/json"):(r=s.body,o=s.contentType))}return!r||!o?null:{inputToUse:r,contentType:o}}l(Vi,"resolveInput");async function ht(t,e,r){let o,s;if(!e&&!r){let i=Ce;if(i)try{let a=JSON.parse(i.toString("utf8"));if(Array.isArray(a))return m({message:"The provided input is invalid. It should be an object, not an array."}),$e.exitCode=5,!1;o=a,s="stdin"}catch(a){return m({message:`Cannot parse JSON input from standard input.
|
|
54
|
+
${a.message}`}),$e.exitCode=5,!1}}if(e)switch(e[0]){case"-":return m({message:"You need to pipe something into standard input when you specify the `-` value to `--input`."}),$e.exitCode=5,!1;default:{let i=await Zc(Bi(t,e)).then(()=>!0).catch(()=>!1),a=e.endsWith(".json")||e.endsWith(".json5")||tl.isAbsolute(e)||e.startsWith("./")||e.startsWith("../")||e.includes("~")||e.startsWith(".\\")||e.startsWith("..\\");if(i||a)return m({message:'Providing a JSON file path in the --input flag is not supported. Use the "--input-file=" flag instead'}),$e.exitCode=5,!1;try{let n=JSON.parse(e);if(Array.isArray(n))return m({message:"The provided input is invalid. It should be an object, not an array."}),$e.exitCode=5,!1;o=n,s="input"}catch(n){return m({message:`Cannot parse JSON input.
|
|
55
|
+
${n.message}`}),$e.exitCode=5,!1}}}else if(r)switch(r[0]){case"-":return m({message:"You need to pipe something into standard input when you specify the `-` value to `--input-file`."}),$e.exitCode=5,!1;default:{let i=Bi(t,r),a;try{let n=await el(i,"utf8"),c=JSON.parse(n);if(Array.isArray(c))return m({message:"The provided input is invalid. It should be an object, not an array."}),$e.exitCode=5,!1;o=c,s=r}catch(n){a=n}if(a)try{let n=JSON.parse(r);if(Array.isArray(n))return m({message:"The provided input is invalid. It should be an object, not an array."}),$e.exitCode=5,!1;o=n,s=r}catch{return m({message:`Cannot read input file at path "${i}".
|
|
56
|
+
${a.message}`}),$e.exitCode=5,!1}}}return o?{input:o,source:s}:void 0}l(ht,"getInputOverride");import gs from"process";import vr from"chalk";import{ACTOR_JOB_STATUSES as Fe}from"@apify/consts";var Gi=[Fe.SUCCEEDED,Fe.ABORTED,Fe.FAILED,Fe.TIMED_OUT];async function*yt(t,e){let r=gs.cwd(),{actorOrTaskData:o,runOptions:s,type:i,waitForFinishMillis:a,inputOverride:n,silent:c,waitForRunToFinish:d,printRunLogs:u}=e,f=i==="Actor"?"actor":"task",p=Vi(r,n);c||(i==="Actor"?ye({message:`Calling ${i} ${o.userFriendlyId} (${vr.gray(o.id)})
|
|
57
|
+
`}):o.title?ye({message:`Calling ${i} ${o.title} (${o.userFriendlyId}, ${vr.gray(o.id)})
|
|
58
|
+
`}):ye({message:`Calling ${i} ${o.userFriendlyId} (${vr.gray(o.id)})
|
|
59
|
+
`}));let h;try{p&&i==="Actor"?h=await t[f](o.id).start(p.inputToUse,{...s,contentType:p.contentType}):h=await t[f](o.id).start(void 0,s)}catch(y){throw y.type==="record-not-found"?new Error(`${i} ${o.userFriendlyId} (${o.id}) not found!`):y}if(yield h,!c&&u)try{await Se({job:h,timeoutMillis:a,apifyClient:t})==="timeouts"?console.error(`
|
|
60
|
+
${vr.gray("Timeout for printing logs was hit, there may be future logs.")}
|
|
61
|
+
`):console.error()}catch(y){x({message:"Can not get log:"}),console.error(y)}if(h=await t.run(h.id).get(),d)for(;!Gi.includes(h.status)&&(h=await t.run(h.id).get(),!Gi.includes(h.status));)await new Promise(y=>{setTimeout(y,1e3)});c||(h.status===Fe.SUCCEEDED?R({message:`${i} finished.`}):h.status===Fe.RUNNING?x({message:`${i} is still running!`}):h.status===Fe.ABORTED||h.status===Fe.ABORTING?(x({message:`${i} was aborted!`}),gs.exitCode=3):(m({message:`${i} failed!`}),gs.exitCode=1)),yield h}l(yt,"runActorOrTaskOnCloud");var wt=l(t=>({build:A.string({char:"b",description:'Tag or number of the build to run (e.g. "latest" or "1.2.34").',required:!1}),timeout:A.integer({char:"t",description:`Timeout for the ${t} run in seconds. Zero value means there is no timeout.`,required:!1}),memory:A.integer({char:"m",description:`Amount of memory allocated for the ${t} run, in megabytes.`,required:!1})}),"SharedRunOnCloudFlags");var Ue=class t extends g{static name="call";static description=`Executes Actor remotely using your authenticated account.
|
|
62
|
+
Reads input from local key-value store by default.`;static flags={...wt("Actor"),input:A.string({char:"i",description:"Optional JSON input to be given to the Actor.",required:!1,stdin:2,exclusive:["input-file"]}),"input-file":A.string({aliases:["if"],description:"Optional path to a file with JSON input to be given to the Actor. The file must be a valid JSON file. You can also specify `-` to read from standard input.",required:!1,stdin:2,exclusive:["input"]}),silent:A.boolean({char:"s",description:"Prevents printing the logs of the Actor run to the console.",default:!1}),"output-dataset":A.boolean({char:"o",description:"Prints out the entire default dataset on successful run of the Actor."})};static enableJsonFlag=!0;static args={actorId:w.string({required:!1,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 '${M}' file.`})};async run(){let e=Hi.cwd(),r=De(e)||{},o=await S(),s=await k(),i=s.username||s.id;if(this.flags.json&&this.flags.outputDataset){m({message:"You cannot use both the --json and --output-dataset flags when running this command."}),Hi.exitCode=5;return}let{id:a,userFriendlyId:n,actorData:c}=await t.resolveActorId({client:o,localActorName:r.name,usernameOrId:i,providedActorNameOrId:this.args.actorId}),d={waitForFinish:2};this.flags.build&&(d.build=this.flags.build),this.flags.timeout&&(d.timeout=this.flags.timeout),this.flags.memory&&(d.memory=this.flags.memory);let u=await ht(e,this.flags.input,this.flags.inputFile);if(u===!1)return;let f=!1,p,h,y,b=yt(o,{actorOrTaskData:{id:a,userFriendlyId:n},runOptions:d,type:"Actor",inputOverride:u?.input,silent:this.flags.silent,waitForRunToFinish:!0,printRunLogs:!0});for await(let C of b)if(p=C,!f&&(f=!0,!this.flags.silent)){h=`https://console.apify.com/actors/${a}/runs/${C.id}`,y=`https://console.apify.com/storage/datasets/${C.defaultDatasetId}`;let v=[`${te.yellow("Started")}: ${B.display(C.startedAt)}`];C.containerUrl&&v.push(`${te.yellow("Container URL")}: ${te.blue(C.containerUrl)}`);let I=p.buildNumber.split(".").slice(0,2).join("."),L=c.versions.find(G=>G.versionNumber===I),D=Object.entries(c.taggedBuilds??{}).find(([,G])=>G.buildNumber===C.buildNumber)?.[0],j=[`${te.yellow("Build")}:`,te.cyan(p.buildNumber)];D?j.push(`(${te.yellow(D)})`):j.push(`(${te.gray("N/A")})`),L&&j.push(`| ${te.gray("Actor version:")} ${te.cyan(L.versionNumber)} (${te.yellow(L.buildTag)})`),v.push(j.join(" ")),v.push(`${te.yellow("Timeout")}: ${p.options.timeoutSecs.toLocaleString("en-US")} seconds`),v.push(`${te.yellow("Memory")}: ${p.options.memoryMbytes} MB`),v.push(`${te.blue("View on Apify Console")}: ${h}`,""),_({message:v.join(`
|
|
63
|
+
`),stdout:!this.flags.json})}if(this.flags.json){N(p);return}if(this.flags.silent||_({message:["",`${te.blue("Export results")}: ${y}`,`${te.blue("View on Apify Console")}: ${h}`].join(`
|
|
64
|
+
`),stdout:!0}),this.flags.outputDataset){let C=p.defaultDatasetId,v,I=4;do{if(v=await o.dataset(C).get(),v?.itemCount)break;await new Promise(D=>{setTimeout(D,250)})}while(I--);let L=await o.dataset(C).downloadItems(ol.JSON,{clean:!0});console.log(L.toString())}}static async resolveActorId({client:e,localActorName:r,usernameOrId:o,providedActorNameOrId:s}){if(s?.includes("/")){let i=await e.actor(s).get();if(!i)throw new Error(`Cannot find Actor with ID '${s}' in your account.`);return{userFriendlyId:`${i.username}/${i.name}`,id:i.id,actorData:i}}if(s){let i=await e.actor(s).get();if(i)return{userFriendlyId:`${i.username}/${i.name}`,id:i.id,actorData:i};let a=await e.actor(`${o}/${s.toLowerCase()}`).get();if(a)return{userFriendlyId:`${a.username}/${a.name}`,id:a.id,actorData:a};throw new Error(`Cannot find Actor with name or ID '${s}' in your account.`)}if(r){let i=await e.actor(`${o}/${r}`).get();if(!i)throw new Error(`Cannot find Actor with ID '${o}/${r}' in your account. Call "apify push" to push this Actor to Apify platform.`);return{userFriendlyId:`${i.username}/${i.name}`,id:i.id,actorData:i}}throw new Error("Please provide an Actor ID or name, or run this command from a directory with a valid Apify Actor.")}};import O from"chalk";import sl from"cli-table3";var il={mid:"","left-mid":"","mid-mid":"","right-mid":"",middle:" ","top-mid":"\u2500","bottom-mid":"\u2500"},nl={middle:" ","top-mid":"\u2500","bottom-mid":"\u2500",top:"\u2500",bottom:"\u2500","left-mid":"\u251C",mid:"\u2500","mid-mid":"\u2500","right-mid":"\u2524"},al={left:"",right:"",mid:"","bottom-left":"","bottom-mid":"","bottom-right":"",top:"","top-left":"","top-mid":"","top-right":"","left-mid":"","mid-mid":"","right-mid":"",bottom:"",middle:" "};var cl={[-1]:void 0,0:il,1:nl,2:al};function ll(t){return Array.from({length:t},()=>"cyan")}l(ll,"generateHeaderColors");var ul=process.stdout.columns??100,Tr=Symbol.for("@apify/cli:responsive-table:skip-column"),V=class t{static{l(this,"ResponsiveTable")}options;rows=[];constructor(e){this.options=e}pushRow(e){this.rows.push(e)}render(e){let r=t.isSmallTerminal()?this.options.mandatoryColumns:this.options.allColumns,o=ll(r.length),s=e===0||e===2,i=cl[e],a=[],n=[],c=[];for(let u of r)this.options.hiddenColumns?.includes(u)||this.rows.some(f=>f[u]===Tr)||(a.push(this.options.columnAlignments?.[u]||"left"),t.isSmallTerminal()?(n.push(this.options.breakpointOverrides?.small?.[u]?.label??u),c.push(this.options.breakpointOverrides?.small?.[u]?.valueFrom??u)):(n.push(u),c.push(u)));let d=new sl({head:n,style:{head:o,compact:s},colAligns:a,chars:i});for(let u of this.rows){let f=c.map(p=>u[p]);d.push(f)}return d.toString()}static isSmallTerminal(){return ul<100}};var Sr="\u200B",Cr="\u200B\u200B",Yi=new V({allColumns:[Sr,Cr],mandatoryColumns:[Sr,Cr],columnAlignments:{[Sr]:"left",[Cr]:"right"}}),Ir=class extends g{static name="info";static description="Get information about an Actor.";static flags={readme:A.boolean({description:"Return the Actor README.",exclusive:["input"]}),input:A.boolean({description:"Return the Actor input schema.",exclusive:["readme"]})};static args={actorId:w.string({description:"The ID of the Actor to return information about.",required:!0})};static enableJsonFlag=!0;async run(){let{actorId:e}=this.args,{readme:r,input:o,json:s}=this.flags,i=await S(),a=await ke({providedActorNameOrId:e,client:i});if(!a.valid){m({message:`${a.reason}. Please specify the Actor ID.`,stdout:!0});return}let n=await i.actor(a.id).get(),c=await i.user(n.userId).get();n.actorMaker=c;for(let p of Object.values(n.taggedBuilds??{})){if(!p.buildId)continue;let h=await i.build(p.buildId).get();p.build=h}if(s){N(n);return}let d=n.taggedBuilds?.latest;if(r){if(!d){m({message:"No README found for this Actor.",stdout:!0});return}if(!d.build?.readme){m({message:"No README found for this Actor.",stdout:!0});return}_({message:d.build.readme,stdout:!0})}if(o){if(!d){m({message:"No input schema found for this Actor.",stdout:!0});return}if(!d.build?.inputSchema){m({message:"No input schema found for this Actor.",stdout:!0});return}_({message:d.build.inputSchema,stdout:!0})}let u=[`Information about Actor ${O.yellow(`${n.username}/${n.name}`)} (${O.gray(n.id)})`,""];n.title&&u.push(`${O.yellow("Title:")} ${O.bold(n.title)}`),n.description&&u.push(`${O.yellow("Description:")} ${n.description}`),u.push(`${O.yellow("Created at:")} ${O.cyan(B.display(n.createdAt))} ${O.gray("|")} ${O.yellow("Updated at:")} ${O.cyan(B.display(n.modifiedAt))}`),n.actorMaker&&(u.push("",`${O.yellow("Made by:")} ${O.cyan(n.actorMaker.profile.name??n.actorMaker.username)}`),Reflect.get(n,"isCritical")&&(u[u.length-1]+=` ${O.bgGray("Maintained by Apify")}`)),n.isPublic?u.push("",`${O.yellow("Actor is")} ${O.green("PUBLIC")}`):u.push("",`${O.yellow("Actor is")} ${O.cyan("PRIVATE")}`),n.isDeprecated&&u.push("",`${O.yellow("Actor is")} ${O.red("DEPRECATED")}`);let f=Reflect.get(n,"pricingInfos");if(f?.length){let p=f.at(-1);switch(p.pricingModel){case"FLAT_PRICE_PER_MONTH":{if(u.push(`${O.yellow("Pricing information:")} ${O.bgGray(`$${p.pricePerUnitUsd}/month + usage`)}`),p.trialMinutes){let h=p.trialMinutes*60*1e3,y=Dt.format(h);u.push(` ${O.yellow("Trial duration:")} ${O.bold(y)}`)}break}case"PRICE_PER_DATASET_ITEM":{let h=p.pricePerUnitUsd*1e3;u.push(`${O.yellow("Pricing information:")} ${O.bgGray(`$${h.toFixed(2)} / 1,000 results`)}`);break}case"PAY_PER_EVENT":{u.push(`${O.yellow("Pricing information:")} ${O.bgGray("Pay per event")}`);let h=Object.values(p.pricingPerEvent?.actorChargeEvents??{});for(let C of h)Yi.pushRow({[Sr]:C.eventTitle,[Cr]:O.bold(`$${C.eventPriceUsd.toFixed(2)}`)});let b=Yi.render(0).split(`
|
|
65
|
+
`);b.splice(1,1),u.push(b.join(`
|
|
66
|
+
`));break}case"FREE":{u.push(`${O.yellow("Pricing information:")} ${O.bgGray("Pay for usage")}`);break}default:u.push(`${O.yellow("Pricing information:")} ${O.bgGray(`Unknown pricing model (${O.yellow(p.pricingModel)})`)}`)}}else u.push(`${O.yellow("Pricing information:")} ${O.bgGray("Pay for usage")}`);if((n.seoTitle||n.seoDescription)&&(u.push("",O.yellow("SEO information:")),n.seoTitle&&u.push(` ${O.yellow("Title:")} ${n.seoTitle}`),n.seoDescription&&u.push(` ${O.yellow("Description:")} ${n.seoDescription}`)),n.taggedBuilds){u.push("",O.yellow("Builds:"));let p=n.taggedBuilds.latest;p&&u.push(` ${O.yellow("-")} ${O.cyan(p.buildNumber)} ${O.gray("/")} ${O.yellow("latest")}`);for(let[h,y]of Object.entries(n.taggedBuilds))h!=="latest"&&u.push(` ${O.yellow("-")} ${O.cyan(y.buildNumber)} ${O.gray("/")} ${O.yellow(h)}`)}_({message:u.join(`
|
|
67
|
+
`),stdout:!0})}};import{Time as dl}from"@sapphire/duration";import q from"chalk";import _e from"chalk";function be(t){switch(t){case"READY":return _e.green("Ready");case"RUNNING":return _e.blue("Running");case"SUCCEEDED":return _e.green("Succeeded");case"FAILED":return _e.red("Failed");case"ABORTING":return _e.yellow("Aborting");case"ABORTED":return _e.red("Aborted");case"TIMING-OUT":return _e.yellow("Timing Out");case"TIMED-OUT":return _e.red("Timed Out");default:return _e.gray(t.split("-").map(e=>e[0].toUpperCase()+e.slice(1).toLowerCase()).join(" "))}}l(be,"prettyPrintStatus");var ml={"TIMED-OUT":q.gray("after"),"TIMING-OUT":q.gray("after"),ABORTED:q.gray("after"),ABORTING:q.gray("after"),FAILED:q.gray("after"),READY:q.gray("for"),RUNNING:q.gray("for"),SUCCEEDED:q.gray("after")},pl=new V({allColumns:["Name","Runs","Last run started at","Last run status","Last run duration","_Small_LastRunText"],mandatoryColumns:["Name","Runs","Last run status","Last run duration"],columnAlignments:{Runs:"right","Last run duration":"right",Name:"left","Last run status":"center"},hiddenColumns:["_Small_LastRunText"],breakpointOverrides:{small:{"Last run status":{label:"Last run",valueFrom:"_Small_LastRunText"}}}}),fl=new V({allColumns:["Name","Modified at","Builds","Default build","Runs","Last run","Last run status","Last run duration","_Small_LastRunText"],mandatoryColumns:["Name","Runs","Last run","Last run duration"],hiddenColumns:["_Small_LastRunText"],columnAlignments:{Builds:"right",Runs:"right","Last run duration":"right",Name:"left","Last run status":"center"},breakpointOverrides:{small:{"Last run":{label:"Last run",valueFrom:"_Small_LastRunText"}}}}),$r=class extends g{static name="ls";static description="Prints a list of recently executed Actors or Actors you own.";static flags={my:A.boolean({description:"Whether to list Actors made by the logged in user.",default:!1}),offset:A.integer({description:"Number of Actors that will be skipped.",default:0}),limit:A.integer({description:"Number of Actors that will be listed.",default:20}),desc:A.boolean({description:"Sort Actors in descending order.",default:!1})};static enableJsonFlag=!0;async run(){let{desc:e,limit:r,offset:o,my:s,json:i}=this.flags,a=await S(),n=await a.actors().list({limit:r,offset:o,desc:e,my:s});if(n.count===0){if(i){N(n);return}T({message:s?"You don't have any Actors yet!":"There are no recent Actors used by you.",stdout:!0});return}let c={...n,items:await Promise.all(n.items.map(async f=>{let p=await a.actor(f.id).get(),h=await a.actor(f.id).runs().list({desc:!0,limit:1}).catch(()=>({count:0,desc:!0,items:[],limit:1,offset:0,total:0}));return{...f,actor:p??null,lastRun:h.items[0]??null}}))};if(c.items=s?this.sortByModifiedAt(c.items):this.sortByLastRun(c.items),i){N(c);return}let d=s?fl:pl,u=c.items.reduce((f,p)=>{let h=`${p.username}/${p.name}`;return h.length>f?h.length:f},0)+2+6;for(let f of c.items){let p=f.stats.lastRunStartedAt?Lt.display(f.stats.lastRunStartedAt):"",h=f.lastRun?(()=>{if(f.lastRun.finishedAt)return oe.format(f.lastRun.finishedAt.getTime()-f.lastRun.startedAt.getTime());let C=Date.now()-f.lastRun.startedAt.getTime();return`${oe.format(C)}\u2026`})():"",y=f.actor?(()=>{let C=Object.entries(f.actor.taggedBuilds??{}).find(([v,I])=>I.buildNumber===f.actor.defaultRunOptions.build||v===f.actor.defaultRunOptions.build);return C?`${q.yellow(C[0])} / ${q.cyan(C[1].buildNumber??f.actor.defaultRunOptions.build)}`:q.gray("Unknown")})():q.gray("Unknown"),b=(()=>{if(f.lastRun){let v=[be(f.lastRun.status)];if(h&&v.push(ml[f.lastRun.status],q.cyan(h)),f.lastRun.finishedAt){let I=Date.now()-f.lastRun.finishedAt.getTime();I<dl.Week?v.push(`
|
|
68
|
+
`,q.gray(`${oe.format(I)} ago`)):v.push(`
|
|
69
|
+
`,q.gray("On",wi.display(f.lastRun.finishedAt)))}return v.join(" ")}return""})();d.pushRow({Name:`${f.title}
|
|
70
|
+
${q.gray(`${f.username}/${f.name}`)}`,Runs:V.isSmallTerminal()&&u>=56?Tr:q.cyan(`${f.stats?.totalRuns??0}`),"Last run started at":p,"Last run":p,"Last run status":f.lastRun?be(f.lastRun.status):"","Modified at":Lt.display(f.modifiedAt),Builds:f.actor?q.cyan(f.actor.stats.totalBuilds):q.gray("Unknown"),"Last run duration":V.isSmallTerminal()?Tr:q.cyan(h),"Default build":y,_Small_LastRunText:b})}_({message:d.render(1),stdout:!0})}sortByModifiedAt(e){return e.sort((r,o)=>{let s=new Date(r.modifiedAt);return new Date(o.modifiedAt).getTime()-s.getTime()})}sortByLastRun(e){return e.sort((r,o)=>{let s=new Date(r.stats?.lastRunStartedAt??"1970-01-01T00:00Z");return new Date(o.stats?.lastRunStartedAt??"1970-01-01T00:00Z").getTime()-s.getTime()})}};import{mkdirSync as Ki,readdirSync as Rl,writeFileSync as Wi}from"fs";import{dirname as _l,join as xl}from"path";import zi from"process";import Ol from"adm-zip";import Nl from"axios";import Xi from"jju";import{gt as Ll}from"semver";import Dl from"tiged";import{mkdir as wl,rename as qi,writeFile as Al}from"fs/promises";import{dirname as bl,join as vl}from"path";import Ji from"process";import{inspect as Tl}from"util";import{err as Gt,ok as Rr}from"@sapphire/result";import gl from"inquirer";var hl=l(({type:t,message:e})=>({name:"confirmed",type:"confirm",message:e??`Are you sure you want to delete this ${t}?`,default:!1}),"yesNoConfirmation"),yl=l(({type:t,expectedValue:e,failureMessage:r="That is not the correct input!",message:o=`Are you sure you want to delete this ${t}? If so, please type in "${e}":`})=>({name:"confirmed",type:"input",message:o,validate(s){return s===e?!0:r}}),"inputValidation");async function W({expectedValue:t,type:e,failureMessage:r,message:o}){let s=await gl.prompt(t?yl({type:e,expectedValue:t,failureMessage:r,message:o}):hl({type:e,message:o}));return typeof s.confirmed=="boolean"?s.confirmed:s.confirmed===t}l(W,"confirmAction");var Sl=l(t=>vl(t,tr),"getDeprecatedLocalConfigPath"),Er=new Map;async function je({cwd:t=Ji.cwd(),migrateConfig:e=!0,warnAboutOldConfig:r=!0}={cwd:Ji.cwd(),migrateConfig:!0,warnAboutOldConfig:!0}){let o=Er.get(t);if(o)return $("useActorConfig",{cacheHit:!0,config:o}),Rr(o);let s=is(t),i=Sl(t),a,n;try{a=Te(s)}catch(d){return Gt({message:`Failed to read local config at path: '${s}':`,cause:d,exists:!1,config:{}})}try{n=Te(i)}catch(d){return Gt({message:`Failed to read local config at path: '${i}':`,cause:d,exists:!1,config:{}})}if(a&&n&&r&&await Cl(i),!a&&!n)return Er.set(t,{exists:!1,migrated:!1,config:{}}),Rr({exists:!1,migrated:!1,config:{}});let c=!1;if(!a&&n&&e){let d=await $l(n,i,s);if(d.isErr())return Gt(d.unwrapErr());a=d.unwrap(),c=!0}return Er.set(t,{exists:!0,migrated:c,config:a||n||{}}),$("useActorConfig",{cacheHit:!1,config:Er.get(t)}),Rr({exists:!0,migrated:c,config:a||n||{}})}l(je,"useActorConfig");async function Cl(t){if(!await W({type:"actor config",message:'The new version of Apify CLI uses the ".actor/actor.json" instead of the "apify.json" file. Since we have found both files in your Actor directory, "apify.json" will be renamed to "apify.json.deprecated". Going forward, all commands will use ".actor/actor.json". You can read about the differences between the old and the new config at https://github.com/apify/apify-cli/blob/master/MIGRATIONS.md. Do you want to continue?'})){x({message:'The "apify.json" file present in your Actor directory will be ignored, and the new ".actor/actor.json" file will be used instead. Please, either rename or remove the old file.'});return}try{await qi(t,`${t}.deprecated`),T({message:'The "apify.json" file has been renamed to "apify.json.deprecated". The deprecated file is no longer used by the CLI or Apify Console. If you do not need it for some specific purpose, it can be safely deleted.'})}catch(r){r instanceof Error?m({message:`Failed to rename the deprecated "apify.json" file to "apify.json.deprecated".
|
|
71
|
+
${r.message||r}`}):m({message:`Failed to rename the deprecated "apify.json" file to "apify.json.deprecated".
|
|
72
|
+
${Tl(r,{showHidden:!1})}`})}}l(Cl,"handleBothConfigVersionsFound");var Il=["name","version","buildTag"];async function $l(t,e,r){let o={...t};if(typeof o.version=="object"&&(o=El(o)),o={actorSpecification:Xo,environmentVariables:t?.env||void 0,...Il.reduce((i,a)=>(i[a]=t[a],i),{})},!await W({type:"actor config",message:'The new version of Apify CLI uses the ".actor/actor.json" instead of the "apify.json" file. Your "apify.json" file will be automatically updated to the new format under ".actor/actor.json". The original file will be renamed by adding the ".deprecated" suffix. Do you want to continue?'}))return Gt({message:'Command can not run with old "apify.json" structure. Either let the CLI auto-update it or follow the guide on https://github.com/apify/apify-cli/blob/master/MIGRATIONS.md and update it manually.',exists:!0,config:o});try{await wl(bl(r),{recursive:!0}),await Al(r,JSON.stringify(o,null," "))}catch(i){let a=i;return Gt({message:`Failed to write the new "actor.json" file to path: '${r}'.
|
|
73
|
+
${a.message||a}`,exists:!0,config:o})}try{await qi(e,`${e}.deprecated`)}catch(i){let a=i;x({message:`Failed to rename the deprecated "apify.json" file to "apify.json.deprecated".
|
|
74
|
+
${a.message||a}`})}return T({message:'The "apify.json" file has been migrated to ".actor/actor.json" and the original file renamed to "apify.json.deprecated". The deprecated file is no longer used by the CLI or Apify Console. If you do not need it for some specific purpose, it can be safely deleted. Do not forget to commit the new file to your Git repository.'}),Rr(o)}l($l,"handleMigrationFlow");function El(t){let e={name:t.name,template:t.template,version:t.version.versionNumber,buildTag:t.version.buildTag,env:null};if(t.version.envVars?.length){let r={};t.version.envVars.forEach(o=>{o.name&&o.value&&(r[o.name]=o.value)}),e.env=r}return e}l(El,"updateLocalConfigStructure");var Qi=l(async(t,e)=>{let{data:r}=await Nl.get(t,{responseType:"arraybuffer"}),o=new Ol(Buffer.from(r,"binary"));o.extractEntryTo(o.getEntries()[0].entryName,e,!1)},"extractGitHubZip"),At=class extends g{static name="pull";static description="Download Actor code to current directory. Clones Git repositories or fetches Actor files based on the source type.";static flags={version:A.string({char:"v",description:"Actor version number which will be pulled, e.g. 1.2. Default: the highest version",required:!1}),dir:A.string({description:"Directory where the Actor should be pulled to",required:!1})};static args={actorId:w.string({required:!1,description:'Name or ID of the Actor to run (e.g. "apify/hello-world" or "E2jjCZBezvAZnX8Rb"). If not provided, the command will update the Actor in the current directory based on its name in ".actor/actor.json" file.'})};async run(){let e=zi.cwd(),r=await je({cwd:e});if(r.isErr()){m({message:r.unwrapErr().message}),zi.exitCode=5;return}let{config:o}=r.unwrap(),s=await k(),i=await S(),a=!this.args.actorId,n=s.username||s.id,c=this.args?.actorId||o?.id||(o?.name?`${n}/${o.name}`:void 0);if(!c)throw new Error("Cannot find Actor in this directory.");let d;try{d=await i.actor(c).get()}catch{throw new Error(`Cannot find Actor with ID/name '${c}' in your account.`)}if(!d)throw new Error(`Cannot find Actor with ID/name '${c}' in your account.`);let{name:u,versions:f}=d,p=null;if(this.flags.version&&(p=f.find(y=>y.versionNumber===this.flags.version),!p))throw new Error(`Cannot find version ${this.flags.version} of Actor ${c}.`);p||(p=f.reduce((y,b)=>Ll(`${b.versionNumber}.0`,`${y.versionNumber}.0`)?b:y));let h=a?e:xl(e,this.flags.dir??u);if(Ki(h,{recursive:!0}),!a&&Rl(h).length!==0){m({message:`Directory ${h} is not empty. Please empty it or choose another directory.`});return}switch(p.sourceType){case"TARBALL":{await Qi(p.tarballUrl,h);break}case"SOURCE_FILES":{let{sourceFiles:y}=p;for(let b of y){let C=_l(b.name);if(Ki(`${h}/${C}`,{recursive:!0}),!b.folder){let v=b.format==="BASE64"?Buffer.from(b.content,"base64").toString():b.content;if(b.name===M){let I=Xi.parse(v);I.name=d.name,Wi(`${h}/${b.name}`,Xi.update(v,I))}else Wi(`${h}/${b.name}`,v)}}break}case"GIT_REPO":{let{gitRepoUrl:y}=p,[b,C]=y.split("#"),v,I;C&&([v,I]=C.split(":"));let L=b;I&&(L+=`/${I}`),v&&(L+=`#${v}`);let D=Dl(L);try{await D.clone(h)}catch(j){throw new Error(`Failed to pull Actor from ${y}. ${j.message}`)}break}case"GITHUB_GIST":{await Qi(`${p.gitHubGistUrl}/archive/master.zip`,h);break}default:throw new Error(`Unknown source type: ${p.sourceType}`)}R({message:a?`Actor ${u} updated at ${h}/`:`Pulled to ${h}/`})}};import{readFileSync as Fl,statSync as Ul,unlinkSync as jl}from"fs";import{join as Ml,resolve as Bl}from"path";import et from"process";import Vl from"inquirer";import Gl from"is-ci";import Hl from"open";import{fetchManifest as Yl}from"@apify/actor-templates";import{ACTOR_JOB_STATUSES as tt,ACTOR_SOURCE_TYPES as ys,MAX_MULTIFILE_BYTES as cn}from"@apify/consts";import{readFileSync as Pl,writeFileSync as kl}from"fs";var hs="@",Zi=100,en=5e4,_r=l(()=>{try{return JSON.parse(Pl(Zt(),"utf-8"))||{}}catch{return{}}},"getSecretsFile"),tn=l(t=>(Xe(Zt()),kl(Zt(),JSON.stringify(t,null," ")),t),"writeSecretsFile"),rn=l((t,e)=>{let r=_r();if(r[t])throw new Error(`Secret with name ${t} already exists. Call "apify secrets rm ${t}" to remove it.`);if(typeof t!="string"||t.length>Zi)throw new Error(`Secret name has to be string with maximum length ${Zi}.`);if(typeof e!="string"||e.length>en)throw new Error(`Secret value has to be string with maximum length ${en}.`);return r[t]=e,tn(r)},"addSecret"),on=l(t=>{let e=_r();if(!e[t])throw new Error(`Secret with name ${t} doesn't exist.`);delete e[t],tn(e)},"removeSecret"),sn=l(t=>new RegExp(`^${hs}.{1}`).test(t),"isSecretKey"),nn=l((t,e)=>{e=e||_r();let r={};return Object.keys(t).forEach(o=>{if(sn(t[o])){let s=t[o].replace(new RegExp(`^${hs}`),"");e[s]?r[o]=e[s]:x({message:`Value for ${s} not found in local secrets. Set it by calling "apify secrets add ${s} [SECRET_VALUE]"`})}else r[o]=t[o]}),r},"replaceSecretsValue"),an=l((t,e)=>{e=e||_r();let r=[];return Object.keys(t).forEach(o=>{if(sn(t[o])){let s=t[o].replace(new RegExp(`^${hs}`),"");e[s]?r.push({name:o,value:e[s],isSecret:!0}):x({message:`Value for ${s} not found in local secrets. Set it by calling "apify secrets add ${s} [SECRET_VALUE]"`})}else r.push({name:o,value:t[o]})}),r},"transformEnvToEnvVars");var ws="temp_file.zip",Jl={build:"latest",memoryMbytes:4096,timeoutSecs:3600},ln="0.0",ql="latest",bt=class extends g{static name="push";static description=`Deploys Actor to Apify platform using settings from '${M}'.
|
|
75
|
+
Files under '${cn/1024**2}' MB upload as "Multiple source files"; larger projects upload as ZIP file.
|
|
76
|
+
Use --force to override newer remote versions.`;static flags={version:A.string({char:"v",description:`Actor version number to which the files should be pushed. By default, it is taken from the '${M}' file.`,required:!1}),"build-tag":A.string({char:"b",description:`Build tag to be applied to the successful Actor build. By default, it is taken from the '${M}' file`,required:!1}),"wait-for-finish":A.string({char:"w",description:"Seconds for waiting to build to finish, if no value passed, it waits forever.",required:!1}),"no-prompt":A.boolean({description:"Do not prompt for opening the Actor details in a browser. This will also not open the browser automatically.",default:!1,required:!1}),force:A.boolean({description:"Push an Actor even when the local files are older than the Actor on the platform.",default:!1,required:!1}),dir:A.string({description:"Directory where the Actor is located",required:!1})};static args={actorId:w.string({required:!1,description:`Name or ID of the Actor to push (e.g. "apify/hello-world" or "E2jjCZBezvAZnX8Rb"). If not provided, the command will create or modify the Actor with the name specified in '${M}' file.`})};async run(){let e=Bl(et.cwd(),this.flags.dir??"."),r=await di(e);if(!r.length){m({message:"You need to call this command from a folder that has an Actor in it!"}),et.exitCode=4;return}if(![tr,"actor.json",".actor/actor.json",".actor"].some(P=>r.some(Z=>Z===P||Z.startsWith(P)))){m({message:["A valid Actor could not be found in the current directory. Please make sure you are in the correct directory.","You can also turn this directory into an Actor by running `apify init`."].join(`
|
|
77
|
+
`)}),et.exitCode=4;return}let o=await S(),s=await je({cwd:e});if(s.isErr()){m({message:s.unwrapErr().message}),et.exitCode=5;return}let{config:i}=s.unwrap(),a=await k(),c=!!a.organizationOwnerUserId?`/organization/${a.id}`:"",d,u,f=!1,p=this.flags.version||i?.version||ln,h=this.flags.buildTag||i?.buildTag;!h&&p===ln&&(h=ql);let y=Number.isNaN(this.flags.waitForFinish)?void 0:Number.parseInt(this.flags.waitForFinish,10)*1e3,b=this.args.actorId;if(b){if(u=await o.actor(b).get(),!u)throw new Error(`Cannot find Actor with ID '${b}' in your account.`);d=u.id}else{let P=a.username||a.id;if(u=await o.actor(`${P}/${i.name}`).get(),u)d=u.id;else{let{templates:Z}=await Yl(),Ne=Z.find(Xt=>Xt.name===i.template)?.defaultRunOptions||Jl,Wo={name:i.name,defaultRunOptions:Ne,versions:[{versionNumber:p,buildTag:h,sourceType:ys.SOURCE_FILES,sourceFiles:[]}]};u=await o.actors().create(Wo),d=u.id,f=!0,T({message:`Created Actor with name ${i.name} on Apify.`})}}T({message:`Deploying Actor '${i.name}' to Apify.`});let C=await Zs(r,e),v=o.actor(d),I,L,D;if(C<cn){let P=await v.get();if(!f){let Z=r.reduce((Ne,Wo)=>{let{mtimeMs:Xt,ctimeMs:Ms}=Ul(Ml(e,Wo)),Bs=Xt>Ms?Xt:Ms;return Ne>Bs?Ne:Bs},0),he=P?.modifiedAt.valueOf();if(!this.flags.force&&he&&Z<he&&(i?.name||b))throw new Error(`Actor with identifier "${i?.name||b}" is already on the platform and was modified there since modified locally.
|
|
78
|
+
Skipping push. Use --force to override.`)}L=await ui(r,e),I=ys.SOURCE_FILES}else{ye({message:"Zipping Actor files"}),await mi(ws,r,e);let P=await o.keyValueStores().getOrCreate(`actor-${d}-source`),Z=`version-${p}.zip`,he=Fl(ws);await o.keyValueStore(P.id).setRecord({key:Z,value:he,contentType:"application/zip"}),jl(ws),D=`${o.baseUrl}/key-value-stores/${P.id}/records/${Z}?disableRedirect=true`,I=ys.TARBALL}let j=await v.version(p).get(),G=i.environmentVariables?an(i.environmentVariables):void 0;if(j){let P={tarballUrl:D,sourceFiles:L,buildTag:h,sourceType:I,envVars:G};await v.version(p).update(P),ye({message:`Updated version ${p} for Actor ${u.name}.`})}else{let P={versionNumber:p,tarballUrl:D,sourceFiles:L,buildTag:h,sourceType:I,envVars:G};await v.versions().create({...P}),ye({message:`Created version ${p} for Actor ${u.name}.`})}ye({message:`Building Actor ${u.name}`});let Y=await v.build(p,{useCache:!0,waitForFinish:2});try{await Se({job:Y,timeoutMillis:y,apifyClient:o})}catch(P){x({message:"Can not get log:"}),console.error(P)}Y=await o.build(Y.id).get(),Vs({message:"Actor build detail",url:`https://console.apify.com${c}/actors/${Y.actId}#/builds/${Y.buildNumber}`}),!Gl&&!this.flags.noPrompt&&(await Vl.prompt([{type:"confirm",name:"continue",message:"Do you want to open the Actor detail in your browser?",default:!0}])).continue&&await Hl(`https://console.apify.com${c}/actors/${Y.actId}`),Y.status===tt.SUCCEEDED?R({message:"Actor was deployed to Apify cloud and built there."}):Y.status===tt.READY?x({message:"Build is waiting for allocation."}):Y.status===tt.RUNNING?x({message:"Build is still running."}):Y.status===tt.ABORTED||Y.status===tt.ABORTING?(x({message:"Build was aborted!"}),et.exitCode=3):Y.status===tt.TIMED_OUT||Y.status===tt.TIMING_OUT?(x({message:"Build timed out!"}),et.exitCode=2):(m({message:"Build failed!"}),et.exitCode=1)}};var xr=class extends g{static name="rm";static description="Permanently removes an Actor from your account.";static args={actorId:w.string({description:"The Actor ID to delete.",required:!0})};async run(){let{actorId:e}=this.args,r=await S();if(!await r.actor(e).get()){m({message:`Actor with ID "${e}" was not found on your account.`});return}if(!await W({type:"Actor",failureMessage:"Your provided value does not match the Actor ID."})){T({message:`Deletion of Actor "${e}" was canceled.`});return}try{await r.actor(e).delete(),R({message:`Actor with ID "${e}" was deleted.`})}catch(i){let a=i;m({message:`Failed to delete Actor "${e}".
|
|
79
|
+
${a.message||a}`})}}};import X from"chalk";var Or=class extends g{static name="start";static description=`Starts Actor remotely and returns run details immediately.
|
|
80
|
+
Uses authenticated account and local key-value store for input.`;static flags={...wt("Actor"),input:A.string({char:"i",description:"Optional JSON input to be given to the Actor.",required:!1,stdin:2,exclusive:["input-file"]}),"input-file":A.string({aliases:["if"],description:"Optional path to a file with JSON input to be given to the Actor. The file must be a valid JSON file. You can also specify `-` to read from standard input.",required:!1,stdin:2,exclusive:["input"]})};static enableJsonFlag=!0;static args={actorId:w.string({required:!1,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 '${M}' file.`})};async run(){let e=process.cwd(),r=De(e)||{},o=await S(),s=await k(),i=s.username||s.id,{id:a,userFriendlyId:n,actorData:c}=await Ue.resolveActorId({client:o,localActorName:r.name,usernameOrId:i,providedActorNameOrId:this.args.actorId}),d={};this.flags.build&&(d.build=this.flags.build),this.flags.timeout&&(d.timeout=this.flags.timeout),this.flags.memory&&(d.memory=this.flags.memory);let u=await ht(e,this.flags.input,this.flags.inputFile);if(u===!1)return;let f=yt(o,{actorOrTaskData:{id:a,userFriendlyId:n},runOptions:d,type:"Actor",inputOverride:u?.input,silent:!0,waitForRunToFinish:!1,printRunLogs:!1}),p;for await(let D of f)p=D;if(this.flags.json){N(p);return}let h=`https://console.apify.com/actors/${a}/runs/${p.id}`,y=`https://console.apify.com/storage/datasets/${p.defaultDatasetId}`,b=[`${X.gray("Run:")} Calling Actor ${n} (${X.gray(a)})`,"",`${X.yellow("Started")}: ${B.display(p.startedAt)}`];p.containerUrl&&b.push(`${X.yellow("Container URL")}: ${X.blue(p.containerUrl)}`);let C=p.buildNumber.split(".").slice(0,2).join("."),v=c.versions.find(D=>D.versionNumber===C),I=Object.entries(c.taggedBuilds??{}).find(([,D])=>D.buildNumber===p.buildNumber)?.[0],L=[`${X.yellow("Build")}:`,X.cyan(p.buildNumber)];I?L.push(`(${X.yellow(I)})`):L.push(`(${X.gray("N/A")})`),v&&L.push(`| ${X.gray("Actor version:")} ${X.cyan(v.versionNumber)} (${X.yellow(v.buildTag)})`),b.push(L.join(" ")),b.push(`${X.yellow("Timeout")}: ${p.options.timeoutSecs.toLocaleString("en-US")} seconds`),b.push(`${X.yellow("Memory")}: ${p.options.memoryMbytes} MB`),b.push("",`${X.blue("Export results")}: ${y}`,`${X.blue("View on Apify Console")}: ${h}`),_({message:b.join(`
|
|
81
|
+
`),stdout:!0})}};var Nr=class extends g{static name="actors";static description="Manages Actor creation, deployment, and execution on the Apify platform.";static subcommands=[Or,xr,bt,At,$r,Ir,Ue,br];async run(){this.printHelp()}};import z from"chalk";var Kl=l(t=>t,"noColor");function K({bytes:t,shortBytes:e=!1,colorFunc:r=Kl,precision:o=2}){let s=[e?"B":"Bytes","KB","MB","GB","TB"];if(t===0)return e?`${0 .toPrecision(o)} B`:`${0 .toPrecision(o)} Byte`;let i=Math.floor(Math.log(t)/Math.log(1e3));return`${(t/1e3**i).toFixed(o)} ${r(s[i])}`}l(K,"prettyPrintBytes");var Lr=class extends g{static name="info";static description="Prints information about a specific build.";static args={buildId:w.string({required:!0,description:"The build ID to get information about."})};static enableJsonFlag=!0;async run(){let{buildId:e}=this.args,r=await S(),o=await r.build(e).get();if(!o){m({message:`Build with ID "${e}" was not found on your account.`,stdout:!0});return}if(this.flags.json){N(o);return}let s=await r.actor(o.actId).get(),i;if(s?.taggedBuilds){for(let[h,y]of Object.entries(s.taggedBuilds))if(y.buildId===o.id){i=h;break}}let a=Reflect.get(o,"exitCode"),n=s?.username?`${s.username}/${s.name}`:s?.name??"unknown-actor",c=i?` (tagged as ${z.yellow(i)})`:"",d=typeof a<"u"?` (exit code: ${z.gray(a)})`:"",u=[`${z.yellow("Actor")}: ${n} (${z.gray(o.actId)})`,"",`${z.yellow("Build Information")} (ID: ${z.gray(o.id)})`,` ${z.yellow("Build Number")}: ${o.buildNumber}${c}`,` ${z.yellow("Status")}: ${be(o.status)}${d}`,` ${z.yellow("Started")}: ${B.display(o.startedAt)}`];if(o.finishedAt)u.push(` ${z.yellow("Finished")}: ${B.display(o.finishedAt)} (took ${z.gray(Dt.format(o.stats?.durationMillis??0))})`);else{let h=Date.now()-o.startedAt.getTime();u.push(` ${z.yellow("Finished")}: ${z.gray(`Running for ${Dt.format(h)}`)}`)}o.stats?.computeUnits&&u.push(` ${z.yellow("Compute Units")}: ${o.stats.computeUnits.toFixed(3)}`);let f=Reflect.get(o.stats??{},"imageSizeBytes");f&&u.push(` ${z.yellow("Docker Image Size")}: ${K({bytes:f})}`),u.push(` ${z.yellow("Origin")}: ${o.meta.origin??"UNKNOWN"}`),u.push("");let p=`https://console.apify.com/actors/${o.actId}/builds/${o.buildNumber}`;u.push(`${z.blue("View in Apify Console")}: ${p}`),_({message:u.join(`
|
|
82
|
+
`),stdout:!0})}};var Dr=class extends g{static name="log";static description="Prints the log of a specific build.";static args={buildId:w.string({required:!0,description:"The build ID to get the log from."})};async run(){let{buildId:e}=this.args,r=await S(),o=await r.build(e).get();if(!o){m({message:`Build with ID "${e}" was not found on your account.`,stdout:!0});return}T({message:`Log for build with ID "${e}":
|
|
83
|
+
`});try{await Se({job:o,apifyClient:r})}catch(s){m({message:`Failed to get log for build with ID "${e}": ${s.message}`,stdout:!0})}}};import me from"chalk";var Wl=l(()=>new V({allColumns:["Number","ID","Status","Took"],mandatoryColumns:["Number","ID","Status","Took"],columnAlignments:{Took:"right"}}),"tableFactory"),Pr=class extends g{static name="ls";static description="Lists all builds of the Actor.";static flags={offset:A.integer({description:"Number of builds that will be skipped.",default:0}),limit:A.integer({description:"Number of builds that will be listed.",default:10}),desc:A.boolean({description:"Sort builds in descending order.",default:!1}),compact:A.boolean({description:"Display a compact table.",default:!1,char:"c"})};static args={actorId:w.string({description:"Optional Actor ID or Name to list runs for. By default, it will use the Actor from the current directory."})};static enableJsonFlag=!0;async run(){let{desc:e,limit:r,offset:o,compact:s,json:i}=this.flags,{actorId:a}=this.args,n=await S(),c=await ke({providedActorNameOrId:a,client:n});if(!c.valid){m({message:`${c.reason}. Please run this command in an Actor directory, or specify the Actor ID.`,stdout:!0});return}let d=await n.actor(c.id).builds().list({desc:e,limit:r,offset:o}),u=await n.actor(c.id).get(),f=ur(d.items,y=>{let b=Reflect.get(y,"buildNumber"),[C,v]=b.split(".");return`${C}.${v}`}),p=Object.entries(u.taggedBuilds??{}).reduce((y,[b,C])=>(y[C.buildNumber]=b,y),{});if(i){for(let y of d.items){let b=Reflect.get(y,"buildNumber"),C=p[b];C&&Reflect.set(y,"buildTag",C)}N(d);return}_({message:`${me.reset("Showing")} ${me.yellow(d.items.length)} out of ${me.yellow(d.total)} builds for Actor ${me.yellow(c.userFriendlyId)} (${me.gray(c.id)})
|
|
84
|
+
`,stdout:!0});let h=Object.entries(f).sort((y,b)=>y[0].localeCompare(b[0]));for(let[y,b]of h){if(!b?.length){_({message:`No builds for version ${y}`,stdout:!0});continue}let C=u.versions.find(D=>D.versionNumber===y)?.buildTag,v=this.generateTableForActorVersion({buildsForVersion:b,buildTagToActorVersion:p}),I=C?` (latest build gets tagged with ${me.yellow(C)})`:"",L=[me.reset(`Builds for Actor Version ${me.yellow(y)}${I}`),v.render(s?0:-1),""];_({message:L.join(`
|
|
85
|
+
`),stdout:!0})}}generateTableForActorVersion({buildsForVersion:e,buildTagToActorVersion:r}){let o=Wl();for(let s of e){let i=Reflect.get(s,"buildNumber"),a=r[i]?` (${me.yellow(r[i])})`:"",n;if(s.finishedAt){let c=s.finishedAt.getTime()-s.startedAt.getTime();n=me.gray(`${oe.format(c,void 0,{left:""})}`)}else{let c=Date.now()-s.startedAt.getTime();n=me.gray(`Running for ${oe.format(c,void 0,{left:""})}`)}o.pushRow({Number:`${i}${a}`,ID:me.gray(s.id),Status:be(s.status),Took:n})}return o}};var kr=class extends g{static name="rm";static description="Permanently removes an Actor build from the Apify platform.";static args={buildId:w.string({description:"The build ID to delete.",required:!0})};async run(){let{buildId:e}=this.args,r=await S(),o=await r.build(e).get();if(!o){m({message:`Build with ID "${e}" was not found on your account.`,stdout:!0});return}let s=await r.actor(o.actId).get(),i;if(s?.taggedBuilds){for(let[n,c]of Object.entries(s.taggedBuilds))if(e===c.buildId){i=n;break}}if(!await W({type:"Actor Build",expectedValue:i,failureMessage:"Your provided value does not match the build tag."})){T({message:`Deletion of build "${e}" was canceled.`,stdout:!0});return}try{await r.build(e).delete(),R({message:`Build with ID "${e}" was deleted.`,stdout:!0})}catch(n){let c=n;m({message:`Failed to delete build "${e}".
|
|
86
|
+
${c.message||c}`,stdout:!0})}}};var Fr=class extends g{static name="builds";static description="Manages Actor build processes and versioning.";static subcommands=[kr,Pr,Dr,Lr,gt];async run(){this.printHelp()}};var Ur=class extends Ue{static name="call"};import zl from"assert";import{existsSync as jr}from"fs";import{mkdir as Xl,readFile as Ql,symlink as Zl,unlink as eu,writeFile as un}from"fs/promises";import{basename as tu,join as pe}from"path";import Me from"chalk";var ru=l(t=>pe(t,".install-marker"),"pathToInstallMarker"),As=l(t=>t.startsWith(process.env.HOME)?t.replace(process.env.HOME,"~"):t,"tildify"),Ht=class extends g{static name="install";static description="Finalizes the first-time setup of Apify and Actor CLI.";static hidden=!0;async run(){let{installMethod:e,installPath:r,version:o}=ee();if(e!=="bundle"){T({message:`Apify and Actor CLI are already fully configured! \u{1F44D}
|
|
87
|
+
`});return}zl(r,"When CLI is installed via bundles, the install path must be set");let s=ru(r);if(jr(s)){T({message:`Apify and Actor CLI are already fully configured! \u{1F44D}
|
|
88
|
+
`});return}await this.symlinkToLocalBin(r),await this.promptAddToShell(),await un(s,o),$("[install] install marker written to",s),_({message:""}),R({message:"To get started, run:"}),_({message:Me.white.bold(` apify --help
|
|
89
|
+
actor --help`)})}async symlinkToLocalBin(e){let r=process.env.HOME;if($("[install] user home directory",r),!r){$("[install] user home directory not found"),x({message:Me.gray("User home directory not found, cannot symlink to ~/.local/bin")});return}let o=pe(r,".local","bin");jr(o)||await Xl(o,{recursive:!0});let s=["apify","actor","apify-cli"];for(let i of s){let a=pe(e,i);if(!jr(a)){$("[install] file not found for symlinking",i,a),x({message:Me.gray(`Bundle not found for symlinking: ${i}`)});continue}let n=pe(o,i);await eu(n),await Zl(a,n),$("[install] symlink created for item",i,n)}T({message:Me.gray(`Symlinked apify, actor, and apify-cli to ${o}`)})}async promptAddToShell(){let e=process.env.PROVIDED_INSTALL_DIR;if(!e){x({message:Me.gray("Install directory not found, cannot add to shell")});return}let r=process.env.FINAL_BIN_DIR;_({message:""});let o=await W({type:"boolean",message:"Should the CLI handle adding itself to your shell automatically? (If you say no, you will receive the lines to add to your shell config file)"}),s=tu(process.env.SHELL??"sh"),i=`"${e.replaceAll('"','\\"')}"`,a=[],n="";switch(s){case"bash":{a.push(`export APIFY_CLI_INSTALL=${i}`),a.push('export PATH="$APIFY_CLI_INSTALL/bin:$PATH"');let c=[pe(process.env.HOME,".bashrc"),pe(process.env.HOME,".bash_profile")];process.env.XDG_CONFIG_HOME&&c.push(pe(process.env.XDG_CONFIG_HOME,".bashrc"),pe(process.env.XDG_CONFIG_HOME,".bash_profile"),pe(process.env.XDG_CONFIG_HOME,"bashrc"),pe(process.env.XDG_CONFIG_HOME,"bash_profile"));for(let d of c)if(jr(d)){n=d;break}break}case"zsh":a.push(`export APIFY_CLI_INSTALL=${i}`),a.push('export PATH="$APIFY_CLI_INSTALL/bin:$PATH"'),n=pe(process.env.HOME,".zshrc");break;case"fish":{a.push(`set --export APIFY_CLI_INSTALL ${i}`),a.push(`set --export PATH ${r} $PATH`),n=pe(process.env.HOME,".config","fish","config.fish");break}default:a.push(`export APIFY_CLI_INSTALL=${i}`),a.push('export PATH="$APIFY_CLI_INSTALL/bin:$PATH"'),n="~/.bashrc";break}if(_({message:""}),o&&n){let d=`${await Ql(n,"utf-8")}
|
|
90
|
+
|
|
91
|
+
# apify cli
|
|
92
|
+
${a.join(`
|
|
93
|
+
`)}`;await un(n,d),T({message:Me.gray(`Added "${As(r)}" to $PATH in ${As(n)}`)})}else T({message:[Me.gray(`Manually add the following lines to your shell config file (${As(n)} or similar):`),...a.map(c=>Me.white.bold(` ${c}`))].join(`
|
|
94
|
+
`)})}};import{spawn as du}from"child_process";import{existsSync as mu}from"fs";import{lstat as pu,readdir as fu,writeFile as pn}from"fs/promises";import{dirname as gu,join as bs}from"path";import vs from"chalk";import{gte as fn}from"semver";import{Result as su}from"@sapphire/result";import{execa as iu}from"execa";import{isAbsolute as ou}from"path";function Be(t){return t?t.startsWith('"')?t:ou(t)&&t.includes(" ")?`"${t}"`:t:null}l(Be,"normalizeExecutablePath");var nu=l(async(t,e,r)=>{let o=Be(t);$("spawnPromised",{escapedCommand:o,args:e,opts:r});let s=iu(o,e,{shell:!0,windowsHide:!0,env:r.env,cwd:r.cwd,stdout:process.env.APIFY_NO_LOGS_IN_TESTS?["pipe"]:["pipe","inherit"],stderr:process.env.APIFY_NO_LOGS_IN_TESTS?["pipe"]:["pipe","inherit"],verbose:process.env.APIFY_CLI_DEBUG?"full":void 0});return su.fromAsync(s.catch(i=>{throw new Error(`${t} exited with code ${i.exitCode}`,{cause:i})}))},"spawnPromised");async function fe({cmd:t,args:e=[],opts:r={},overrideCommand:o}){ye({message:`${o||t} ${e.join(" ")}`});let s=await nu(t,e,r);if(s.isErr()){let i=s.unwrapErr();if(m({message:i.message}),i.cause)throw i.cause}}l(fe,"execWithLog");import{execSync as dn}from"child_process";import{existsSync as au,readFileSync as cu}from"fs";var xe=ee();function lu(){return xe.platform==="linux"?au("/etc/alpine-release"):!1}l(lu,"isInstalledOnMusl");function uu(){return xe.platform==="darwin"&&xe.arch==="x64"?!dn("sysctl -a",{encoding:"utf-8"}).includes("AVX2"):xe.platform==="linux"&&xe.arch==="x64"?!cu("/proc/cpuinfo","utf-8").includes("avx2"):xe.platform==="windows"?xe.arch==="arm64"?!0:dn(`pwsh -c "!(Add-Type -MemberDefinition '[DllImport(\\"kernel32.dll\\")] public static extern bool IsProcessorFeaturePresent(int ProcessorFeature);' -Name 'Kernel32' -Namespace 'Win32' -PassThru)::IsProcessorFeaturePresent(40)"`,{encoding:"utf-8",windowsHide:!0}).trim().toLowerCase()==="true":!1}l(uu,"isInstalledOnBaseline");async function mn(t){let e=t.replace(/^v(\d+)/,"$1"),r=e==="latest"?"latest":`tags/v${e}`,o=await fetch(`https://api.github.com/repos/apify/apify-cli/releases/${r}`,{headers:{"User-Agent":jt}});if(!o.ok)return $("useCLIVersionAssets","Failed to fetch release",{statusCode:o.status,body:await o.text(),version:t,tag:r}),null;let s=await o.json(),i=lu(),a=uu(),n=s.assets.filter(c=>{let[d,u,f,p,h,y]=c.name.replace(e,"version").replace(".exe","").split("-");return f!==xe.platform||p!==xe.arch?!1:i?h==="musl":a?y==="baseline"||h==="baseline":!h&&!y});return $("useCLIVersionAssets","Fetched release",{version:s.tag_name,filteredAssets:n}),{assets:n,version:s.tag_name.replace(/^v(\d+)/,"$1")}}l(mn,"useCLIVersionAssets");var gn={bundle:l((t,e)=>[`${e}`,"upgrade"],"bundle"),npm:l(t=>["npm","install","-g",`apify-cli@${t}`],"npm"),pnpm:l(t=>["pnpm","install","-g",`apify-cli@${t}`],"pnpm"),bun:l(t=>["bun","install","-g",`apify-cli@${t}`],"bun"),homebrew:l(()=>["brew","upgrade","apify-cli"],"homebrew"),volta:l(t=>["volta","install",`apify-cli@${t}`],"volta")},Mr="0.21.8",hn="https://raw.githubusercontent.com/apify/apify-cli/main/scripts/install/upgrade.ps1",Yt=class extends g{static name="upgrade";static description="Checks that installed Apify CLI version is up to date.";static hidden=!0;static aliases=["cv","check-version"];static flags={force:A.boolean({description:"Whether to skip checking the locally cached latest version of the CLI and fetch it from the internet instead.",required:!1,char:"f"}),version:A.string({description:"The version of the CLI to upgrade to. If not provided, the latest version will be used.",required:!1}),"internal-automatic-call":A.boolean({description:"Whether the command was called automatically by the CLI for a version check.",hidden:!0,default:!1})};get cliName(){return this.entrypoint==="apify"?"Apify CLI":"Actor CLI"}async run(){if(this.flags.version){await this.handleInstallSpecificVersion(this.flags.version);return}let e=await Pi(this.flags.force),{installMethod:r}=ee();if(!e.shouldUpdate||e.currentVersion===Gs){this.flags.internalAutomaticCall||T({message:`${this.cliName} is up to date \u{1F44D}
|
|
95
|
+
`});return}if(!this.flags.internalAutomaticCall){await this.handleInstallSpecificVersion("latest");return}let o=gn[r]("latest",this.entrypoint).join(" ");_({message:""});let s=[`You are using an old version of ${this.cliName}. We strongly recommend you always use the latest available version.`,` \u21AA Run ${vs.bgWhite(vs.black(o))} to update! \u{1F44D}
|
|
96
|
+
`].join(`
|
|
97
|
+
`);x({message:s})}async handleInstallSpecificVersion(e){if(e!=="latest"&&!fn(e,Mr)){m({message:`The minimum version of the CLI you can manually downgrade/upgrade to is ${Mr}.`});return}let r=await mn(e);if(!r){m({message:"The provided version does not exist. Please check the version number and try again."});return}let{assets:o,version:s}=r;if(!fn(s,Mr)){m({message:`The minimum version of the CLI you can manually downgrade/upgrade to is ${Mr}.`});return}let i=ee();if(i.installMethod==="bundle"){if(!o.length){m({message:["Failed to find the assets for your system and the provided version. Please open an issue on https://github.com/apify/apify-cli/issues/new and provide the following information:",`- The version you are trying to upgrade to: ${s}`,`- The system you are running on: ${i.platform} ${i.arch}`].join(`
|
|
98
|
+
`)});return}let n=gu(process.execPath);$("[upgrade] bundleDirectory",n);let c=await fu(n);if(!c.some(d=>d.startsWith("apify")||d.startsWith("actor"))){$("[upgrade] directoryEntries",c),m({message:[`Failed to find the currently installed ${this.cliName} bundle. Please open an issue on https://github.com/apify/apify-cli/issues/new and provide the following information:`,`- The version you are trying to upgrade to: ${s}`,`- The system you are running on: ${i.platform} ${i.arch}`,`- The directory where the ${this.cliName} bundle is installed: ${n}`].join(`
|
|
99
|
+
`)});return}if(i.platform==="windows")return this.startUpgradeProcess(n,s,o);await this.handleUnixUpgrade(n,s,o),this.successMessage(s);return}let a=gn[i.installMethod](e,this.entrypoint);if(process.env.APIFY_CLI_DEBUG){T({message:`Would run command: ${a.join(" ")}`});return}try{await fe({cmd:a[0],args:a.slice(1)}),this.successMessage(s)}catch{m({message:`Failed to upgrade the CLI. Please run the following command manually: ${a.join(" ")}`})}}successMessage(e){R({message:`Successfully upgraded to ${e} \u{1F44D}`})}async startUpgradeProcess(e,r,o){await this.upsertUpgradeScript(e);let s=["-ExecutionPolicy","Bypass","-File",`"${bs(e,"upgrade.ps1")}"`,"-ProcessId",process.pid.toString(),"-InstallLocation",`"${e}"`,"-Version",`"${r}"`],i=o.map(n=>n.browser_download_url).join(",");s.push("-AllUrls",`"${i}"`),$("[upgrade] starting upgrade process with args",s),T({message:"Starting upgrade process..."});let a=du("powershell.exe",s,{detached:!0,shell:!0,stdio:"inherit",windowsHide:!1,windowsVerbatimArguments:!0});a.on("spawn",()=>{$("[upgrade] upgrade process spawned"),a.unref(),process.exit(0)}),a.on("error",n=>{m({message:`Failed to start the upgrade process: ${n.message}`})})}async upsertUpgradeScript(e){let r=bs(e,"upgrade.ps1");if(mu(r))return;let o=ee(),s=await fetch(hn,{headers:{"User-Agent":jt}});s.ok||(m({message:["Failed to fetch the upgrade script. Please open an issue on https://github.com/apify/apify-cli/issues/new and provide the following information:",`- The system you are running on: ${o.platform} ${o.arch}`,`- The URL of the asset that failed to fetch: ${hn}`,`- The status code of the response: ${s.status}`].join(`
|
|
100
|
+
`)}),process.exit(1));let i=await s.arrayBuffer();await pn(r,Buffer.from(i)),$("[upgrade] downloaded upgrade script to",r)}async handleUnixUpgrade(e,r,o){let s=ee();for(let i of o){let a=i.name.split("-")[0],n=bs(e,a);T({message:`Downloading ${a}...`});let c=await fetch(i.browser_download_url,{headers:{"User-Agent":jt}});if(!c.ok){let u=await c.text();$("[upgrade] failed to fetch asset",{asset:i,status:c.status,body:u}),m({message:[`Failed to fetch the ${a} bundle. Please open an issue on https://github.com/apify/apify-cli/issues/new and provide the following information:`,`- The version you are trying to upgrade to: ${r}`,`- The system you are running on: ${s.platform} ${s.arch}`,`- The URL of the asset that failed to fetch: ${i.browser_download_url}`,`- The status code of the response: ${c.status}`,`- The body of the response: ${u}`].join(`
|
|
101
|
+
`)});return}if(process.env.APIFY_CLI_DEBUG&&!process.env.APIFY_CLI_FORCE){T({message:`Would write asset ${a} to ${n}`});continue}T({message:vs.gray(`Writing ${a} to ${n}...`)});let d=await c.arrayBuffer();try{let u=await pu(n).then(f=>f.mode).catch(()=>493);await pn(n,Buffer.from(d),{mode:u|448}),$(`[upgrade ${a}] wrote asset to`,n)}catch(u){$("[upgrade] failed to write asset",{error:u}),m({message:[`Failed to write the ${a} bundle. Please open an issue on https://github.com/apify/apify-cli/issues/new and provide the following information:`,`- The version you are trying to upgrade to: ${r}`,`- The system you are running on: ${s.platform} ${s.arch}`,`- The URL of the asset that failed to fetch: ${i.browser_download_url}`,`- The error: ${u.message}`].join(`
|
|
102
|
+
`)})}}}};import{mkdir as Hu,readdir as Yu,stat as Ju}from"fs/promises";import{join as St}from"path";import jn from"process";import{gte as qu,minVersion as Ku}from"semver";import{fetchManifest as Wu,manifestUrl as zu}from"@apify/actor-templates";import{createWriteStream as hu}from"fs";import{pipeline as yu}from"stream/promises";import yn from"chalk";import vt from"inquirer";var wn=["JavaScript","TypeScript","Python"];async function Ts(t){return t?(Nt(t),t):wu()}l(Ts,"ensureValidActorName");async function An(t,e){let r=await e;if(r instanceof Error)throw r;if(t){let o=r.templates.find(s=>s.name===t);if(!o)throw new Error(`Could not find the selected template: ${t} in the list of templates.`);return o}return vn(r)}l(An,"getTemplateDefinition");async function bn(t,e){let r=await e;if(r instanceof Error)throw r;try{let o=await sr(r.localReadmeSuffixUrl),s=hu(t,{flags:"a"});s.write(`
|
|
103
|
+
|
|
104
|
+
`),await yu(o,s)}catch(o){x({message:`Could not append local development instructions to README.md. Cause: ${o.message}`})}}l(bn,"enhanceReadmeWithLocalSuffix");async function vn(t){let e=await Au();for(;;){let r=await bu(t,e);if(r){if(await vu(r))return r}else return vn(t)}}l(vn,"executePrompts");async function wu(){return(await vt.prompt([{name:"actorName",message:"Name of your new Actor:",type:"input",validate:l(e=>{try{Nt(e)}catch(r){return r.message}return!0},"validate")}])).actorName}l(wu,"promptActorName");async function Au(){return(await vt.prompt([{type:"list",name:"programmingLanguage",message:"Choose the programming language of your new Actor:",default:wn[0],choices:wn,loop:!1}])).programmingLanguage}l(Au,"promptProgrammingLanguage");async function bu(t,e){let r=[...t.templates.filter(s=>s.category.toLowerCase()===e.toLowerCase()).map(s=>({name:s.label,value:s})),new vt.Separator,{name:"Go back",value:!1}];return(await vt.prompt([{type:"list",name:"templateDefinition",message:"Choose a template for your new Actor. Detailed information about the template will be shown in the next step.",default:r[0],choices:r,loop:!1,pageSize:8}])).templateDefinition}l(bu,"promptTemplateDefinition");async function vu(t){let e=[{name:"Install template",value:!0},new vt.Separator,{name:"Go back",value:!1}],r=yn.underline(t.label),o=yn.dim(t.description),i=`Do you want to install the following template?${`
|
|
105
|
+
${r}:
|
|
106
|
+
${o}`}`;return(await vt.prompt([{type:"list",name:"shouldInstall",message:i,default:e[0],choices:e,loop:!1}])).shouldInstall}l(vu,"promptTemplateInstallation");import{platform as Tu}from"os";import{join as Tn}from"path";import Br from"process";import{none as Sn,some as Cn}from"@sapphire/result";import{execa as Su}from"execa";import Cu from"which";var Ve=new Map;async function In(t){try{let e=await Su(t,["-c",'"import platform; print(platform.python_version())"'],{shell:!0,windowsHide:!0,verbose:Br.env.APIFY_CLI_DEBUG?"full":void 0});return e.stdout?e.stdout.trim():null}catch{return null}}l(In,"getPythonVersion");async function Jt({cwd:t=Br.cwd(),force:e=!1}={}){let r=Ve.get(t);if(r&&!e)return $("usePythonRuntime",{cacheHit:!0,cwd:t,runtime:r.unwrapOr(null)}),r;let o=Tu()==="win32",s=o?["Scripts","python.exe"]:["bin","python3"],i;Br.env.VIRTUAL_ENV?i=Tn(Br.env.VIRTUAL_ENV,...s):i=Tn(t,".venv",...s),i=Be(i);try{let n=await In(i);if(n)return Ve.set(t,Cn({executablePath:i,version:n})),$("usePythonRuntime",{cacheHit:!1,cwd:t,runtime:Ve.get(t)?.unwrap()}),Ve.get(t)}catch{}let a=["python3","python",...o?["python3.exe","python.exe"]:[]];for(let n of a)try{let c=Be(await Cu(n)),d=await In(c);if(d)return Ve.set(t,Cn({executablePath:c,version:d})),$("usePythonRuntime",{cacheHit:!1,cwd:t,runtime:Ve.get(t)?.unwrap()}),Ve.get(t)}catch{}return Ve.set(t,Sn),$("usePythonRuntime",{cacheHit:!1,cwd:t,runtime:null}),Sn}l(Jt,"usePythonRuntime");import{access as Is,readFile as Lu}from"fs/promises";import{basename as Nn,dirname as Du,join as H,resolve as Ln}from"path";import Pu from"process";import{ok as Cs}from"@sapphire/result";import{existsSync as $n,readdirSync as $u}from"fs";import{join as Hr,resolve as Eu}from"path";import Ru from"configparser";import _u from"inquirer";import{readFileSync as Iu}from"fs";var Vr=class{static{l(this,"Spider")}name;class_name;start_urls;pathname;constructor(e){this.name=e.name,this.class_name=e.class_name,this.start_urls=e.start_urls,this.pathname=e.pathname}};var Gr=class{static{l(this,"SpiderFileAnalyzer")}pathname;constructor(e){this.pathname=e}getSpiders(){let e=Iu(this.pathname,"utf8"),r=/class\s+(\w+)/g,o=[],s=r.exec(e);for(;s;)o.push(new Vr({class_name:s[1],pathname:this.pathname})),s=r.exec(e);return o}};var rt=class{static{l(this,"ScrapyProjectAnalyzer")}pathname;configuration=null;settings=null;constructor(e){this.pathname=e,this.settings=null,this.loadScrapyCfg()}static isApplicable(e){return $n(Hr(e,"scrapy.cfg"))}async init(){await this.loadSettings()}loadScrapyCfg(){let e=new Ru,r=Eu(Hr(this.pathname,"scrapy.cfg"));if(!$n(r))throw new Error(`scrapy.cfg not found in "${r}".
|
|
107
|
+
Are you sure there is a Scrapy project there?`);e.read(r),this.configuration=e}async loadSettings(){let e=this.configuration.get("settings","default").split(".")[0],r=await _u.prompt([{type:"input",name:"BOT_NAME",message:"Enter the Scrapy BOT_NAME (see settings.py):",default:e},{type:"input",name:"SPIDER_MODULES",message:"What folder are the Scrapy spider modules stored in? (see SPIDER_MODULES in settings.py):",default:`${e}.spiders`}]);this.settings={BOT_NAME:r.BOT_NAME,SPIDER_MODULES:typeof r.SPIDER_MODULES=="string"?[r.SPIDER_MODULES]:r.SPIDER_MODULES}}getName(){return this.settings?.BOT_NAME}getAvailableSpiders(){let e=this.settings?.SPIDER_MODULES;if(!e)throw new Error("SPIDER_MODULES path not found in settings.");let r=[];for(let o of e){let s=Hr(this.pathname,o.replaceAll(".","/")),i=$u(s,{withFileTypes:!0});for(let a of i)a.isFile()&&a.name.endsWith(".py")&&a.name!=="__init__.py"&&r.push(...new Gr(Hr(s,a.name)).getSpiders())}return r}};import Ss from"process";import{none as En,some as Rn}from"@sapphire/result";import{execa as xn}from"execa";import _n from"which";var Yr=new Map,xu={node:["--version"],deno:["eval",'"console.log(process.versions.node)"'],bun:["--eval",'"console.log(process.versions.node)"']};async function Ou(t,e){try{let r=await xn(t,e,{shell:!0,windowsHide:!0,verbose:Ss.env.APIFY_CLI_DEBUG?"full":void 0});return r.stdout?r.stdout.trim().replace(/^v/,""):null}catch{return null}}l(Ou,"getRuntimeVersion");async function Nu(t){let e=await xn(t,["--version"],{shell:!0,windowsHide:!0,verbose:Ss.env.APIFY_CLI_DEBUG?"full":void 0});return e.stdout?e.stdout.trim().replace(/^v/,""):null}l(Nu,"getNpmVersion");async function On(t=Ss.cwd()){let e=Yr.get(t);if(e)return $("useJavaScriptRuntime",{cacheHit:!0,cwd:t,runtime:e.unwrapOr(null)}),e;for(let[r,o]of Object.entries(xu))try{let s=Be(await _n(r)),i=await Ou(s,o);if(i){let a={executablePath:s,version:i};if(r==="node"){let n=Be(await _n("npm").catch(()=>null));n&&(a.pmPath=n,a.pmVersion=await Nu(n),a.pmName="npm")}else a.runtimeShorthand=r,a.pmPath=s,a.pmVersion=i,a.pmName=r;return Yr.set(t,Rn(a)),$("useJavaScriptRuntime",{cacheHit:!1,cwd:t,runtime:Yr.get(t)?.unwrap()}),Rn(a)}}catch{}return Yr.set(t,En),$("useJavaScriptRuntime",{cacheHit:!1,cwd:t,runtime:null}),En}l(On,"useJavaScriptRuntime");var Dn=new Map;async function Tt({cwd:t=Pu.cwd()}={}){let e=Dn.get(t);if(e)return $("useCwdProject",{cacheHit:!0,project:e}),Cs(e);let r={type:3},s=await l(async()=>{if(await Fu(t)){r.type=2;let c=await Jt({cwd:t});r.runtime=c.unwrapOr(void 0);let d=new rt(t);if(d.loadScrapyCfg(),d.configuration.hasKey("apify","mainpy_location"))r.entrypoint={path:d.configuration.get("apify","mainpy_location")};else{let u=await Pn(t);u&&(r.entrypoint={path:u})}return}let a=await Pn(t);if(a){r.type=1;let c=await Jt({cwd:t});r.entrypoint={path:a},r.runtime=c.unwrapOr(void 0);return}let n=await ku(t);if(n){r.type=0;let c=await On();r.runtime=c.unwrapOr(void 0),n.type==="file"?r.entrypoint={path:n.path}:n.type==="script"&&(r.entrypoint={script:n.script});return}return Cs(r)},"check")();return s?.isErr()?($("useCwdProject",{cacheHit:!1,error:s}),s):($("useCwdProject",{cacheHit:!1,project:r}),Dn.set(t,r),Cs(r))}l(Tt,"useCwdProject");async function ku(t){let e=H(t,"package.json");try{let o=await Lu(e,"utf-8"),s=JSON.parse(o);if(s.scripts?.start)return{type:"script",script:"start"};if(s.main)try{return await Is(Ln(t,s.main)),{path:Ln(t,s.main),type:"file"}}catch{}return{type:"unknown-entrypoint"}}catch{}let r=[H(t,"index.js"),H(t,"index.mjs"),H(t,"index.cjs"),H(t,"main.js"),H(t,"main.mjs"),H(t,"main.cjs"),H(t,"src","index.js"),H(t,"src","index.mjs"),H(t,"src","index.cjs"),H(t,"src","main.js"),H(t,"src","main.mjs"),H(t,"src","main.cjs"),H(t,"dist","index.js"),H(t,"dist","index.mjs"),H(t,"dist","index.cjs"),H(t,"dist","main.js"),H(t,"dist","main.mjs"),H(t,"dist","main.cjs")];for(let o of r)try{return await Is(o),{path:o,type:"file"}}catch{}return null}l(ku,"checkNodeProject");async function Pn(t){let e=Nn(t),r=[H(t,"src","__main__.py"),H(t,"__main__.py"),H(t,e,"__main__.py"),H(t,e.replaceAll("-","_").replaceAll(" ","_"),"__main__.py")];for(let o of r)try{return await Is(o),Nn(Du(o))}catch{}return null}l(Pn,"checkPythonProject");async function Fu(t){return rt.isApplicable(t)}l(Fu,"checkScrapyProject");import{existsSync as Uu,writeFileSync as ju}from"fs";import{join as Jr}from"path";import Mu from"process";import Bu from"lodash.clonedeep";import{KEY_VALUE_STORE_KEYS as Vu}from"@apify/consts";import{validateInputSchema as Gu}from"@apify/input_schema";var kn=[".actor/INPUT_SCHEMA.json","./INPUT_SCHEMA.json",".actor/input_schema.json","./input_schema.json"],ot=l(async({forcePath:t,cwd:e}={cwd:Mu.cwd()})=>{if(t)return{inputSchema:Te(t),inputSchemaPath:t};let r=De(e);if(typeof r?.input=="object")return{inputSchema:r.input,inputSchemaPath:null};if(typeof r?.input=="string"){let o=Jr(e,Qo,r.input);return{inputSchema:Te(o),inputSchemaPath:o}}for(let o of kn){let s=Jr(e,o);if(Uu(s))return{inputSchema:Te(s),inputSchemaPath:s}}return{inputSchema:null,inputSchemaPath:Jr(e,kn[0])}},"readInputSchema"),qr=l(async t=>{let e={};try{let{inputSchema:r}=await ot({cwd:t});if(r){let o=new nt({strict:!1});Gu(o,r),e=Object.entries(r.properties).reduce((s,[i,a])=>(s[i]=a.type==="boolean"||a.editor==="hidden"?a.default:a.prefill,s),{})}}catch(r){x({message:`Could not create default input based on input schema, creating empty input instead. Cause: ${r.message}`})}finally{let r=ve(),o=Jr(t,r,`${Vu.INPUT}.json`);ju(o,JSON.stringify(e,null," "))}},"createPrefilledInputFileFromInputSchema"),Fn=l(t=>{let e={};for(let[r,o]of Object.entries(t.properties))o.default!==void 0&&(e[r]=o.default);return e},"getDefaultsFromInputSchema"),Un=l((t,e)=>{let r=Bu(t);r.required=[];for(let[o,s]of Object.entries(t.properties)){let i=t.required?.includes(o),a=s.default!==void 0;i&&!a&&(r.required.push(o),s.type==="array"&&(s.minItems=Math.max(1,s.minItems||0)))}return delete r.$schema,e.compile(r)},"getAjvValidator");var Kr=class extends g{static name="create";static description="Creates an Actor project from a template in a new directory.";static flags={template:A.string({char:"t",description:`Template for the Actor. If not provided, the command will prompt for it.
|
|
108
|
+
Visit ${zu} to find available template names.`,required:!1}),"skip-dependency-install":A.boolean({description:"Skip installing Actor dependencies.",required:!1}),"template-archive-url":A.string({description:"Actor template archive url. Useful for developing new templates.",required:!1,hidden:!0}),"omit-optional-deps":A.boolean({aliases:["no-optional"],description:"Skip installing optional dependencies.",required:!1})};static args={actorName:w.string({required:!1,description:"Name of the Actor and its directory"})};async run(){let{actorName:e}=this.args,{template:r,skipDependencyInstall:o}=this.flags,{templateArchiveUrl:s}=this.flags,i=!1,a=Wu().catch(y=>new Error(`Could not fetch template list from server. Cause: ${y?.message}`));e=await Ts(e);let n=jn.cwd(),c=St(n,e);for(;;){let y=await Ju(c).catch(()=>null),b=y&&await Yu(c).then(C=>C.length>0).catch(()=>!1);if(y?.isDirectory()&&b){m({message:`Cannot create new Actor, directory '${e}' already exists. Please provide a different name. You can use "apify init" to create a local Actor environment inside an existing directory.`}),e=await Ts(),c=St(n,e);continue}y||await Hu(c,{recursive:!0});break}let d=null;if(this.telemetryData.fromArchiveUrl=!!s,!s){let y=await An(r,a);({archiveUrl:s,messages:d}=y),this.telemetryData.templateId=y.id,this.telemetryData.templateName=y.name,this.telemetryData.templateLanguage=y.category,"skipOptionalDeps"in y&&(i=y.skipOptionalDeps)}this.flags.omitOptionalDeps&&(i=!0),await lr({url:s,pathTo:c});let u=Te(St(c,M));await ir(Object.assign(u||Qt,{name:e}),c),await nr(c),await qr(c);let f=St(c,"package.json"),p=St(c,"README.md");await bn(p,a);let h=!1;o||await(await Tt({cwd:c})).inspectAsync(async b=>{let C=Ku(we);if(!b.runtime){switch(b.type){case 0:{x({message:`No Node.js detected! Please install Node.js ${C} or higher to be able to run Node.js Actors locally.`});break}case 2:case 1:{x({message:`No Python detected! Please install Python ${We} or higher to be able to run Python Actors locally.`});break}default:}return}let{runtime:v}=b;switch(b.type){case 0:{cr(v.version)||x({message:`You are running Node.js version ${v.version}, which is no longer supported. Please upgrade to Node.js version ${C} or later.`}),await Qs(f,{name:e});let I=["install"];if(i)switch(v.pmName){case"npm":{qu(v.pmVersion,"7.0.0")?I.push("--omit=optional"):I.push("--no-optional");break}case"bun":{I.push("--omit=optional");break}case"deno":{I.push("--node-modules-dir");break}default:}await fe({cmd:v.pmPath,args:I,opts:{cwd:c},overrideCommand:v.pmName}),h=!0;break}case 1:case 2:{if(!ar(v.version)){x({message:`Python Actors require Python 3.9 or higher, but you have Python ${v.version}!`}),x({message:"Please install Python 3.9 or higher to be able to run Python Actors locally."});return}let I=St(c,".venv");T({message:`Python version ${v.version} detected.`}),T({message:`Creating a virtual environment in "${I}" and installing dependencies from "requirements.txt"...`}),jn.env.VIRTUAL_ENV||(await fe({cmd:v.executablePath,args:["-m","venv","--prompt",".",Ks],opts:{cwd:c}}),v=(await Jt({cwd:c,force:!0})).unwrap(),b.runtime=v),await fe({cmd:v.executablePath,args:["-m","pip","install","--no-cache-dir","--no-warn-script-location","--upgrade","pip","setuptools","wheel"],opts:{cwd:c}}),await fe({cmd:v.executablePath,args:["-m","pip","install","--no-cache-dir","--no-warn-script-location","-r","requirements.txt"],opts:{cwd:c}}),h=!0;break}default:}}),h?(R({message:`Actor '${e}' was created. To run it, run "cd ${e}" and "apify run".`}),T({message:'To run your code in the cloud, run "apify push" and deploy your code to Apify Console.'}),d?.postCreate&&T({message:d?.postCreate})):R({message:`Actor '${e}' was created. Please install its dependencies to be able to run it using "apify run".`})}};import Bn from"chalk";async function Mn(t,e,r){let o=await t[r](e).get().catch(()=>{});if(o)return{[r]:o,[`${r}Client`]:t[r](o.id)};let s=await k(),i=await t[r](`${s.username}/${e}`).get().catch(()=>{});return i?{[r]:i,[`${r}Client`]:t[r](i.id)}:null}l(Mn,"tryToGetStorage");async function Ee(t,e){return Mn(t,e,"dataset")}l(Ee,"tryToGetDataset");async function Q(t,e){return Mn(t,e,"keyValueStore")}l(Q,"tryToGetKeyValueStore");var Wr=class extends g{static name="create";static description="Creates a new dataset for storing structured data on your account.";static args={datasetName:w.string({description:"Optional name for the Dataset",required:!1})};static enableJsonFlag=!0;async run(){let{datasetName:e}=this.args,r=await S();if(e&&await Ee(r,e)){m({message:"A Dataset with this name already exists!"});return}let o=await r.datasets().getOrCreate(e);if(this.flags.json){N(o);return}R({message:`Dataset with ID ${Bn.yellow(o.id)}${e?` (called ${Bn.yellow(e)})`:""} was created.`,stdout:!0})}};import{DownloadItemsFormat as Ge}from"apify-client";var Vn={[Ge.JSON]:"application/json",[Ge.JSONL]:"application/jsonl",[Ge.CSV]:"text/csv",[Ge.HTML]:"text/html",[Ge.RSS]:"application/rss+xml",[Ge.XML]:"application/xml",[Ge.XLSX]:"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"},zr=class extends g{static name="get-items";static description="Retrieves dataset items in specified format (JSON, CSV, etc).";static flags={limit:A.integer({description:"The amount of elements to get from the dataset. By default, it will return all available items."}),offset:A.integer({description:"The offset in the dataset where to start getting items."}),format:A.string({description:"The format of the returned output. By default, it is set to 'json'",choices:Object.keys(Vn),default:Ge.JSON})};static args={datasetId:w.string({description:"The ID of the Dataset to export the items for",required:!0})};async run(){let{limit:e,offset:r,format:o}=this.flags,{datasetId:s}=this.args,i=await S(),a=await this.tryToGetDataset(i,s);if(!a){m({message:`Dataset with ID "${s}" not found.`});return}let{datasetClient:n}=a;process.stdout.write("");let c=await n.downloadItems(o,{limit:e,offset:r}),d=Vn[o]??"application/octet-stream";_({message:d}),process.stdout.write(c),process.stdout.write(`
|
|
109
|
+
`)}async tryToGetDataset(e,r){let o=await e.dataset(r).get().catch(()=>{});if(o)return{dataset:o,datasetClient:e.dataset(o.id)};let s=await k(),i=await e.dataset(`${s.username}/${r}`).get().catch(()=>{});return i?{dataset:i,datasetClient:e.dataset(i.id)}:null}};import U from"chalk";function Xr(t){let e=Reflect.get(t,"planPricing");return e?Reflect.get(e,"chargeableServiceUnitPricesUsd"):null}l(Xr,"getUserPlanPricing");var Gn=new V({allColumns:["Row1","Row2"],mandatoryColumns:["Row1","Row2"]}),Qr=class extends g{static name="info";static description="Prints information about a specific dataset.";static args={storeId:w.string({description:"The dataset store ID to print information about.",required:!0})};static enableJsonFlag=!0;async run(){let{storeId:e}=this.args,r=await S(),o=await Ee(r,e);if(!o){m({message:`Key-value store with ID or name "${e}" not found.`});return}let{dataset:s}=o,[i,a,n]=await Promise.all([r.user(s.userId).get().then(P=>P),s.actId?r.actor(s.actId).get():Promise.resolve(void 0),s.actRunId?r.run(s.actRunId).get():Promise.resolve(void 0)]),c;if(n?.actorTaskId&&(c=await r.task(n.actorTaskId).get().catch(()=>{})),this.flags.json){N({...s,user:i,actor:a||null,run:n||null,task:c||null});return}let d=s.stats?.storageBytes||0,u=s.stats?.readCount||0,f=s.stats?.writeCount||0,p=(s.cleanItemCount||0).toLocaleString("en-US"),h=(s.itemCount||0).toLocaleString("en-US"),y=[`${U.bold(u.toLocaleString("en-US"))} ${U.gray(this.pluralString(u,"read","reads"))}`,`${U.bold(f.toLocaleString("en-US"))} ${U.gray(this.pluralString(f,"write","writes"))}`],b=`Items: ${U.bold(p)} ${U.gray("clean")} / ${U.bold(h)} ${U.gray("total")}
|
|
110
|
+
Operations: ${y.join(" / ")}`;if(i.plan){let P=Xr(i.plan);if(P){let Z=P.KEY_VALUE_STORE_TIMED_STORAGE_GBYTE_HOURS*(d/1e9),he=Z*24*30,Ne=he>1?`$${he.toFixed(2)}`:`$${Z.toFixed(3)}`;b+=`
|
|
111
|
+
Storage size: ${K({bytes:d,shortBytes:!0,precision:1})} / ${U.gray(`${Ne} per month`)}`}}else b+=`
|
|
112
|
+
Storage size: ${K({bytes:d,shortBytes:!0,precision:1})}`;let C=[`Dataset ID: ${U.bgGray(s.id)}`,`Name: ${s.name?U.bgGray(s.name):U.bold(U.italic("Unnamed"))}`,`Created: ${U.bold(B.display(s.createdAt))}`,`Modified: ${U.bold(B.display(s.modifiedAt))}`].join(`
|
|
113
|
+
`),v=U.bold("\u2014");s.actRunId&&(n?v=U.bgBlue(n.id):v=U.italic(U.gray("Run removed")));let I=U.bold("\u2014");a&&(I=U.blue(a.title||a.name));let L=U.bold("\u2014");c&&(L=U.blue(c.title||c.name));let D=[`Run: ${v}`,`Actor: ${I}`,`Task: ${L}`].join(`
|
|
114
|
+
`);Gn.pushRow({Row1:C,Row2:D});let G=Gn.render(2).split(`
|
|
115
|
+
`).map(P=>P.trim());G.shift();let Y=[`${U.bold(s.name||U.italic("Unnamed"))}`,`${U.gray(s.name?`${i.username}/${s.name}`:s.id)} ${U.gray("Owned by")} ${U.blue(i.username)}`,"",G.join(`
|
|
116
|
+
`),"",b].join(`
|
|
117
|
+
`);_({message:Y,stdout:!0})}};import Hn from"chalk";var Yn=new V({allColumns:["Dataset ID","Name","Items","Size","Created","Modified"],mandatoryColumns:["Dataset ID","Name","Items","Size"],columnAlignments:{Items:"right"}}),Zr=class extends g{static name="ls";static description="Prints all datasets on your account.";static flags={offset:A.integer({description:"Number of datasets that will be skipped.",default:0}),limit:A.integer({description:"Number of datasets that will be listed.",default:20}),desc:A.boolean({description:"Sorts datasets in descending order.",default:!1}),unnamed:A.boolean({description:"Lists datasets that don't have a name set.",default:!1})};static enableJsonFlag=!0;async run(){let{desc:e,offset:r,limit:o,json:s,unnamed:i}=this.flags,a=await S(),n=await k(),c=await a.datasets().list({desc:e,offset:r,limit:o,unnamed:i});if(s){N(c);return}if(c.count===0){T({message:"You don't have any Datasets on your account",stdout:!0});return}for(let d of c.items){let u=Reflect.get(d.stats,"s3StorageBytes");Yn.pushRow({"Dataset ID":d.id,Created:B.display(d.createdAt),Items:`${d.itemCount}`,Modified:B.display(d.modifiedAt),Name:d.name?`${n.username}/${d.name}`:"",Size:typeof u=="number"?K({bytes:u,shortBytes:!0,colorFunc:Hn.gray,precision:0}):Hn.gray("N/A")})}_({message:Yn.render(1),stdout:!0})}};import eo from"chalk";var to=class extends g{static name="push-items";static description="Adds data items to specified dataset. Accepts single object or array of objects.";static args={nameOrId:w.string({required:!0,description:"The dataset ID or name to push the objects to",ignoreStdin:!0}),item:w.string({description:"The object or array of objects to be pushed."})};async run(){let{nameOrId:e,item:r}=this.args,o=await S(),s=await Ee(o,e);if(!s){m({message:`Dataset with ID or name "${e}" not found.`});return}let{datasetClient:i,dataset:a}=s,n,c=r||Ce;if(!c){m({message:"No items were provided."});return}try{n=JSON.parse(c.toString("utf8"))}catch(u){m({message:`Failed to parse data as JSON string: ${u.message}`});return}if(Array.isArray(n)&&n.length===0){m({message:"No items were provided."});return}let d=a.name?`Dataset named ${eo.yellow(a.name)} (${eo.gray("ID:")} ${eo.yellow(a.id)})`:`Dataset with ID ${eo.yellow(a.id)}`;try{await i.pushItems(n),R({message:`${this.pluralString(Array.isArray(n)?n.length:1,"Object","Objects")} pushed to ${d} successfully.`})}catch(u){let f=u;m({message:`Failed to push items into ${d}
|
|
118
|
+
${f.message||f}`})}}};import He from"chalk";var ro=class extends g{static name="rename";static description="Change dataset name or removes name with --unname flag.";static flags={unname:A.boolean({description:"Removes the unique name of the dataset."})};static args={nameOrId:w.string({description:"The dataset ID or name to delete.",required:!0}),newName:w.string({description:"The new name for the dataset."})};async run(){let{unname:e}=this.flags,{newName:r,nameOrId:o}=this.args;if(!r&&!e){m({message:"You must provide either a new name or the --unname flag."});return}if(r&&e){m({message:"You cannot provide a new name and the --unname flag."});return}let s=await S(),i=await Ee(s,o);if(!i){m({message:`Dataset with ID or name "${o}" not found.`});return}let{id:a,name:n}=i.dataset,c=n?e?`The name of the dataset with ID ${He.yellow(a)} has been removed (was ${He.yellow(n)} previously).`:`The name of the dataset with ID ${He.yellow(a)} was changed from ${He.yellow(n)} to ${He.yellow(r)}.`:`The name of the dataset with ID ${He.yellow(a)} has been set to: ${He.yellow(r)}`;try{await i.datasetClient.update({name:e?null:r}),R({message:c,stdout:!0})}catch(d){let u=d;m({message:`Failed to rename dataset with ID ${He.yellow(a)}
|
|
119
|
+
${u.message||u}`})}}};import Es from"chalk";var oo=class extends g{static name="rm";static description="Permanently removes a dataset.";static args={datasetNameOrId:w.string({description:"The dataset ID or name to delete",required:!0})};async run(){let{datasetNameOrId:e}=this.args,r=await S(),o=await Ee(r,e);if(!o){m({message:`Dataset with ID or name "${e}" not found.`});return}if(!await W({type:"Dataset"})){T({message:"Dataset deletion has been aborted."});return}let{id:i,name:a}=o.dataset;try{await o.datasetClient.delete(),R({message:`Dataset with ID ${Es.yellow(i)}${a?` (called ${Es.yellow(a)})`:""} has been deleted.`,stdout:!0})}catch(n){let c=n;m({message:`Failed to delete dataset with ID ${Es.yellow(i)}
|
|
120
|
+
${c.message||c}`})}}};var so=class extends g{static name="datasets";static description="Manages structured data storage and retrieval.";static subcommands=[Wr,zr,Zr,Qr,oo,ro,to];async run(){this.printHelp()}};import{existsSync as Rs,mkdirSync as Xu,readFileSync as Qu,writeFileSync as Zu}from"fs";import{dirname as ed}from"path";import td from"cors";import rd from"detect-indent";import _s from"express";import od from"open";import{cryptoRandomObjectId as sd}from"@apify/utilities";var qn="https://apify.github.io/input-schema-editor-react/",id=new URL(qn).origin,Jn="v1",io=class extends g{static name="edit-input-schema";static description="Lets you edit your input schema that would be used on the platform in a visual input schema editor.";static args={path:w.string({required:!1,description:"Optional path to your INPUT_SCHEMA.json file. If not provided default platform location for input schema is used."})};static hidden=!0;static aliases=["eis"];async run(){let{inputSchema:e,inputSchemaPath:r}=await ot({forcePath:this.args.path,cwd:process.cwd()});if(e&&!r)throw new Error(`Editing an input schema directly embedded in '${M}' is not yet supported.`);x({message:`This command is still experimental and might break at any time. Use at your own risk.
|
|
121
|
+
`}),T({message:`Editing input schema at "${r}"...`});let o,s=_s();s.use(td({origin:id,allowedHeaders:["Content-Type","Authorization"]})),s.use((f,p,h)=>{p.set("Connection","close"),h()}),s.use(_s.json());let i=sd();s.use((f,p,h)=>{let{token:y}=f.query;if(!y){let b=f.get("Authorization");if(b){let[C,v,...I]=b.trim().split(/\s+/);C.toLowerCase()==="bearer"&&v&&I.length===0&&(y=v)}}y!==i?(p.status(401),p.send("Authorization failed")):h()});let a=_s.Router();s.use(`/api/${Jn}`,a);let n=" ",c=!0;a.get("/input-schema",(f,p)=>{let h;try{h=Rs(r)?Qu(r,{encoding:"utf-8"}):`{}
|
|
122
|
+
`,h.length>3&&(n=rd(h).indent||n),h&&(c=h[h.length-1]===`
|
|
123
|
+
`),Rs(r)?T({message:`Input schema loaded from "${r}"`}):T({message:"Empty input schema initialized."})}catch(b){let C=`Reading input schema from disk failed with: ${b.message}`;m({message:C}),p.status(500),p.send(C);return}let y;try{y=JSON.parse(h||"{}")}catch(b){let C=`Parsing input schema failed with error: ${b.message}`;m({message:C}),p.status(500),p.send(C);return}p.send(y),T({message:"Input schema sent to editor."})}),a.post("/input-schema",(f,p)=>{try{T({message:"Got input schema from editor..."});let h=f.body,y=JSON.stringify(h,null,n);c&&(y+=`
|
|
124
|
+
`);let b=ed(r);Rs(b)||Xu(b,{recursive:!0}),Zu(r,y,{encoding:"utf-8",flag:"w+"}),p.end(),T({message:"Input schema saved to disk."})}catch(h){let y=`Saving input schema failed with error: ${h.message}`;m({message:y}),p.status(500),p.send(y)}}),a.post("/exit",(f,p)=>{f.body.isWindowClosed?T({message:"Editor closed, finishing..."}):T({message:"Editing finished, you can close the editor."}),p.end(),o.close(()=>R({message:"Done."}))}),o=s.listen(0);let{port:d}=o.address();T({message:`Listening for messages from input schema editor on port ${d}...`});let u=`${qn}?localCliPort=${d}&localCliToken=${i}&localCliApiVersion=${Jn}`;T({message:`Opening input schema editor at "${u}"...`}),await od(u)}};import no from"chalk";var qt=class extends g{static name="help";static description="Prints out help about a command, or all available commands.";static hidden=!0;static args={commandString:w.string({required:!1,description:"The command to get help for.",catchAll:!0})};async run(){let{commandString:e}=this.args;if(!e||e.toLowerCase().startsWith("help")){let i=gr(this.entrypoint);console.log(i);return}let r=e.toLowerCase(),o=J.get(r);if(!o){let i=Ut(r),a=no.gray(`Command ${no.whiteBright(e)} not found`);i.length&&(a+=`
|
|
125
|
+
`,a+=no.gray(`Did you mean: ${i.map(n=>no.whiteBright(n)).join(", ")}?`)),m({message:a});return}let s=pr(o);console.log(s)}};import Kn from"chalk";var ao=class extends g{static name="info";static description="Prints details about your currently authenticated Apify account.";async run(){await S();let e=await k();if(e){let r={username:e.username,userId:e.id};for(let o of Object.keys(r))console.log(`${Kn.gray(o)}: ${Kn.bold(r[o])}`)}}};import{basename as vd}from"path";import Ls from"process";import Qn from"inquirer";import{appendFileSync as nd,copyFileSync as ad,createWriteStream as cd,existsSync as xs,mkdirSync as ld,readFileSync as Wn,rmSync as ud,writeFileSync as dd}from"fs";import{basename as md,join as Os,relative as zn,sep as Ns}from"path";import{fileURLToPath as pd}from"url";import fd from"@root/walk";import gd from"configparser";import hd from"handlebars";import yd from"inquirer";import{fetchManifest as wd,wrapperManifestUrl as Ad}from"@apify/actor-templates";var bd=[".dockerignore",".gitignore"],co=pd(new URL("./templates/python-scrapy",import.meta.url));async function Xn(t,e,r={bindings:{}}){await fd.walk(t,async(o,s,i)=>{if(s===t)return;let a=zn(t,s),n=a.split(Ns).map(d=>{if(d.startsWith("{")&&d.endsWith("}")){d=d.replace("{","").replace("}","");let u=r.bindings[d];if(!u)throw new Error(`Binding for ${d} not found.`);return u}return d}).join(Ns),c=Os(e,n);if(i.isDirectory())return xs(c)||ld(c),Xn(s,c);a.includes(".template")?dd(Os(e,n.replace(".template","")),hd.compile(Wn(s,"utf8"))(r.bindings)):xs(c)&&bd.includes(md(n))?nd(c,Wn(s)):ad(s,c)})}l(Xn,"merge");async function lo({projectPath:t}){t||(t=".");let e=new rt(t);if(e.configuration.hasSection("apify"))throw new Error("The Scrapy project configuration already contains Apify settings. Are you sure you didn't already wrap this project?");await e.init();let{spiderIndex:r}=await yd.prompt([{type:"list",name:"spiderIndex",message:"Pick the Scrapy spider you want to wrap:",choices:e.getAvailableSpiders().map((d,u)=>({name:`${d.class_name} (${d.pathname})`,value:u}))}]);function o(d){return`.${zn(t,d).split(Ns).slice(1).join(".").replace(".py","")}`}l(o,"translatePathToRelativeModuleName");let s={botName:yi(e.settings.BOT_NAME),scrapy_settings_module:e.configuration.get("settings","default"),apify_module_path:`${e.settings.BOT_NAME}.apify`,spider_class_name:e.getAvailableSpiders()[r].class_name,spider_module_name:`${o(e.getAvailableSpiders()[r].pathname)}`,projectFolder:e.settings.BOT_NAME},i=await wd(Ad);T({message:"Downloading the latest Scrapy wrapper template..."});let{archiveUrl:a}=i.templates.find(({id:d})=>d==="python-scrapy");xs(co)&&ud(co,{recursive:!0}),await lr({url:a,pathTo:co}),T({message:"Wrapping the Scrapy project..."}),await Xn(co,t,{bindings:s});let n=new gd;n.addSection("apify"),n.set("apify","mainpy_location",e.settings.BOT_NAME);let c=cd(Os(t,"scrapy.cfg"),{flags:"a"});await new Promise(d=>{c.on("open",u=>{c.write(`
|
|
126
|
+
`,()=>{n.write(u),d()})})}),R({message:"The Scrapy project has been wrapped successfully."})}l(lo,"wrapScrapyProject");var uo=class extends g{static name="init";static description=`Sets up an Actor project in your current directory by creating actor.json and storage files.
|
|
127
|
+
If the directory contains a Scrapy project in Python, the command automatically creates wrappers so that you can run your scrapers without changes.
|
|
128
|
+
Creates the '${M}' file and the '${Ke}' directory in the current directory, but does not touch any other existing files or directories.
|
|
129
|
+
|
|
130
|
+
WARNING: Overwrites existing '${Ke}' directory.`;static args={actorName:w.string({required:!1,description:"Name of the Actor. If not provided, you will be prompted for it."})};static flags={yes:A.boolean({char:"y",description:'Automatic yes to prompts; assume "yes" as answer to all prompts. Note that in some cases, the command may still ask for confirmation.',required:!1})};async run(){let{actorName:e}=this.args,r=Ls.cwd(),o=await Tt();o.isErr()&&(m({message:o.unwrapErr().message}),Ls.exit(1));let s=o.unwrap();if(s.type===2)return T({message:"The current directory looks like a Scrapy project. Using automatic project wrapping."}),this.telemetryData.actorWrapper=Ys.SCRAPY,lo({projectPath:r});if(!this.flags.yes&&s.type===3){x({message:"The current directory does not look like a Node.js or Python project."});let{c:a}=await Qn.prompt([{name:"c",message:"Do you want to continue?",type:"confirm"}]);if(!a)return}let i=await je({cwd:r});if(i.isOkAnd(a=>a.exists&&!a.migrated))x({message:`Skipping creation of '${M}', the file already exists in the current directory.`});else{if(i.isErr()){m({message:i.unwrapErr().message}),Ls.exitCode=5;return}if(!e){let n=i.isOkAnd(c=>c.exists)?{actName:i.unwrap().config.name}:null;for(;!n;)try{let c=await Qn.prompt([{name:"actName",message:"Actor name:",default:vd(r),type:"input"}]);Nt(c.actName),n=c}catch(c){m({message:c.message})}({actName:e}=n)}let a={...Qt,...i.unwrap().config};await ir(Object.assign(a,{name:e}),r)}await nr(r),await qr(r),R({message:"The Actor has been initialized in the current directory."})}};var mo=class extends g{static name="init-wrap-scrapy";static description=`Wraps your existing Scrapy project to work like an Apify Actor.
|
|
131
|
+
|
|
132
|
+
It adds the following features:
|
|
133
|
+
- Automatic retry of failed requests
|
|
134
|
+
- Automatic proxy rotation
|
|
135
|
+
- Automatic user agent rotation
|
|
136
|
+
...
|
|
137
|
+
`;static args={path:w.string({required:!1,description:"Optional path to your scrapy project. If not provided, the current directory is used."})};static hidden=!0;async run(){await lo({projectPath:this.args.path}),T({message:"Scrapy project wrapped successfully."})}};import Zn from"chalk";var po=class extends g{static name="create";static description="Creates a new key-value store on your account.";static args={"key-value store name":w.string({description:"Optional name for the key-value store",required:!1})};static enableJsonFlag=!0;async run(){let{keyValueStoreName:e}=this.args,r=await S();if(e&&await Q(r,e)){m({message:"Cannot create a key-value store with the same name!"});return}let o=await r.keyValueStores().getOrCreate(e);if(this.flags.json){N(o);return}R({message:`Key-value store with ID ${Zn.yellow(o.id)}${e?` (called ${Zn.yellow(e)})`:""} was created.`,stdout:!0})}};import Td from"chalk";var fo=class extends g{static name="delete-value";static description="Delete a value from a key-value store.";static args={"store id":w.string({description:"The key-value store ID to delete the value from.",required:!0}),itemKey:w.string({description:"The key of the item in the key-value store.",required:!0})};async run(){let{storeId:e,itemKey:r}=this.args,o=await S(),s=await Q(o,e);if(!s){m({message:`Key-value store with ID or name "${e}" not found.`});return}let{keyValueStoreClient:i}=s;if(!await i.getRecord(r)){m({message:`Item with key "${r}" not found in the key-value store.`});return}if(!await W({type:"record"})){T({message:"Key-value store record deletion aborted.",stdout:!0});return}try{await i.deleteRecord(r),T({message:`Record with key "${Td.yellow(r)}" deleted from the key-value store.`,stdout:!0})}catch(c){let d=c;m({message:`Failed to delete record with key "${r}" from the key-value store.
|
|
138
|
+
${d.message||d}`})}}};var go=class extends g{static name="get-value";static description="Retrieves stored value for specified key. Use --only-content-type to check MIME type.";static flags={"only-content-type":A.boolean({description:"Only return the content type of the specified key",default:!1})};static args={keyValueStoreId:w.string({description:"The key-value store ID to get the value from.",required:!0}),itemKey:w.string({description:"The key of the item in the key-value store.",required:!0})};async run(){let{onlyContentType:e}=this.flags,{keyValueStoreId:r,itemKey:o}=this.args,s=await S(),i=await Q(s,r);if(!i){m({message:`Key-value store with ID "${r}" not found.`});return}let{keyValueStoreClient:a}=i,n=await a.getRecord(o,{stream:!0});if(!n){m({message:`Item with key "${o}" not found in the key-value store.`});return}if(_({message:n.contentType??"application/octet-stream"}),e){n.value.destroy();return}if(n.contentType?.includes("application/json")){let{value:c}=n,d=[];for await(let f of c)d.push(f);let u=Buffer.concat(d).toString();try{let f=JSON.parse(u);_({message:JSON.stringify(f,null,2),stdout:!0})}catch{_({message:u,stdout:!0})}return}n.value.pipe(process.stdout)}};import F from"chalk";var ea=new V({allColumns:["Row1","Row2"],mandatoryColumns:["Row1","Row2"]}),ho=class extends g{static name="info";static description="Shows information about a key-value store.";static args={storeId:w.string({description:"The key-value store ID to print information about.",required:!0})};static enableJsonFlag=!0;async run(){let{storeId:e}=this.args,r=await S(),o=await Q(r,e);if(!o){m({message:`Key-value store with ID or name "${e}" not found.`});return}let{keyValueStore:s}=o,[i,a,n]=await Promise.all([r.user(s.userId).get().then(P=>P),s.actId?r.actor(s.actId).get():Promise.resolve(void 0),s.actRunId?r.run(s.actRunId).get():Promise.resolve(void 0)]),c;if(n?.actorTaskId&&(c=await r.task(n.actorTaskId).get().catch(()=>{})),this.flags.json){N({...s,user:i,actor:a||null,run:n||null,task:c||null});return}let d=s.stats?.storageBytes||0,u=s.stats?.readCount||0,f=s.stats?.writeCount||0,p=s.stats?.deleteCount||0,h=s.stats?.listCount||0,b=`Operations: ${[`${F.bold(u.toLocaleString("en-US"))} ${F.gray(this.pluralString(u,"read","reads"))}`,`${F.bold(f.toLocaleString("en-US"))} ${F.gray(this.pluralString(f,"write","writes"))}`,`${F.bold(p.toLocaleString("en-US"))} ${F.gray(this.pluralString(p,"delete","deletes"))}`,`${F.bold(h.toLocaleString("en-US"))} ${F.gray(this.pluralString(h,"list","lists"))}`].join(" / ")}`;if(i.plan){let P=Xr(i.plan);if(P){let Z=P.KEY_VALUE_STORE_TIMED_STORAGE_GBYTE_HOURS*(d/1e9),he=Z*24*30,Ne=he>1?`$${he.toFixed(2)}`:`$${Z.toFixed(3)}`;b+=`
|
|
139
|
+
Storage size: ${K({bytes:d,shortBytes:!0,precision:1})} / ${F.gray(`${Ne} per month`)}`}}else b+=`
|
|
140
|
+
Storage size: ${K({bytes:d,shortBytes:!0,precision:1})} / ${F.gray("$unknown per month")}`;let C=[`Store ID: ${F.bgGray(s.id)}`,`Name: ${s.name?F.bgGray(s.name):F.bold(F.italic("Unnamed"))}`,`Created: ${F.bold(B.display(s.createdAt))}`,`Modified: ${F.bold(B.display(s.modifiedAt))}`].join(`
|
|
141
|
+
`),v=F.bold("\u2014");s.actRunId&&(n?v=F.bgBlue(n.id):v=F.italic(F.gray("Run removed")));let I=F.bold("\u2014");a&&(I=F.blue(a.title||a.name));let L=F.bold("\u2014");c&&(L=F.blue(c.title||c.name));let D=[`Run: ${v}`,`Actor: ${I}`,`Task: ${L}`].join(`
|
|
142
|
+
`);ea.pushRow({Row1:C,Row2:D});let G=ea.render(2).split(`
|
|
143
|
+
`).map(P=>P.trim());G.shift();let Y=[`${F.bold(s.name||F.italic("Unnamed"))}`,`${F.gray(s.name?`${i.username}/${s.name}`:s.id)} ${F.gray("Owned by")} ${F.blue(i.username)}`,"",G.join(`
|
|
144
|
+
`),"",b].join(`
|
|
145
|
+
`);_({message:Y,stdout:!0})}};var ta=new V({allColumns:["Key","Size"],mandatoryColumns:["Key","Size"]}),yo=class extends g{static name="keys";static description="Lists all keys in a key-value store.";static flags={limit:A.integer({description:"The maximum number of keys to return.",default:20}),"exclusive-start-key":A.string({description:"The key to start the list from."})};static args={storeId:w.string({description:"The key-value store ID to list keys for.",required:!0})};static enableJsonFlag=!0;async run(){let{storeId:e}=this.args,{limit:r,exclusiveStartKey:o}=this.flags,s=await S(),i=await Q(s,e);if(!i){m({message:`Key-value store with ID or name "${e}" not found.`});return}let{keyValueStoreClient:a}=i,n=await a.listKeys({limit:r,exclusiveStartKey:o});if(this.flags.json){N(n);return}for(let c of n.items)ta.pushRow({Key:c.key,Size:K({bytes:c.size,shortBytes:!0,precision:0})});_({message:ta.render(1),stdout:!0})}};import ra from"chalk";var oa=new V({allColumns:["Store ID","Name","Size","Created","Modified"],mandatoryColumns:["Store ID","Name","Size"]}),wo=class extends g{static name="ls";static description="Lists all key-value stores on your account.";static flags={offset:A.integer({description:"Number of key-value stores that will be skipped.",default:0}),limit:A.integer({description:"Number of key-value stores that will be listed.",default:20}),desc:A.boolean({description:"Sorts key-value stores in descending order.",default:!1}),unnamed:A.boolean({description:"Lists key-value stores that don't have a name set.",default:!1})};static enableJsonFlag=!0;async run(){let{desc:e,offset:r,limit:o,json:s,unnamed:i}=this.flags,a=await S(),n=await k(),c=await a.keyValueStores().list({desc:e,offset:r,limit:o,unnamed:i});if(s){N(c);return}if(c.count===0){T({message:"You don't have any key-value stores on your account",stdout:!0});return}for(let d of c.items){let f=Reflect.get(d,"stats").s3StorageBytes;oa.pushRow({"Store ID":d.id,Created:B.display(d.createdAt),Modified:B.display(d.modifiedAt),Name:d.name?`${n.username}/${d.name}`:"",Size:typeof f=="number"?K({bytes:f,shortBytes:!0,colorFunc:ra.gray,precision:0}):ra.gray("N/A")})}_({message:oa.render(1),stdout:!0})}};import Ye from"chalk";var Ao=class extends g{static name="rename";static description="Renames a key-value store, or removes its unique name.";static flags={unname:A.boolean({description:"Removes the unique name of the key-value store"})};static args={keyValueStoreNameOrId:w.string({description:"The key-value store ID or name to delete",required:!0}),newName:w.string({description:"The new name for the key-value store"})};async run(){let{unname:e}=this.flags,{newName:r,keyValueStoreNameOrId:o}=this.args;if(!r&&!e){m({message:"You must provide either a new name or the --unname flag."});return}if(r&&e){m({message:"You cannot provide a new name and the --unname flag."});return}let s=await S(),i=await Q(s,o);if(!i){m({message:`Key-value store with ID or name "${o}" not found.`});return}let{id:a,name:n}=i.keyValueStore,c=n?e?`The name of the key-value store with ID ${Ye.yellow(a)} has been removed (was ${Ye.yellow(n)} previously).`:`The name of the key-value store with ID ${Ye.yellow(a)} was changed from ${Ye.yellow(n)} to ${Ye.yellow(r)}.`:`The name of the key-value store with ID ${Ye.yellow(a)} has been set to: ${Ye.yellow(r)}`;try{await i.keyValueStoreClient.update({name:e?null:r}),R({message:c,stdout:!0})}catch(d){let u=d;m({message:`Failed to rename key-value store with ID ${Ye.yellow(a)}
|
|
146
|
+
${u.message||u}`})}}};import Ds from"chalk";var bo=class extends g{static name="rm";static description="Permanently removes a key-value store.";static args={keyValueStoreNameOrId:w.string({description:"The key-value store ID or name to delete",required:!0})};async run(){let{keyValueStoreNameOrId:e}=this.args,r=await S(),o=await Q(r,e);if(!o){m({message:`Key-value store with ID or name "${e}" not found.`});return}if(!await W({type:"Key-value store"})){T({message:"Key-value store deletion has been aborted."});return}let{id:i,name:a}=o.keyValueStore;try{await o.keyValueStoreClient.delete(),R({message:`Key-value store with ID ${Ds.yellow(i)}${a?` (called ${Ds.yellow(a)})`:""} has been deleted.`,stdout:!0})}catch(n){let c=n;m({message:`Failed to delete key-value store with ID ${Ds.yellow(i)}
|
|
147
|
+
${c.message||c}`})}}};var vo=class extends g{static name="set-value";static description="Stores value with specified key. Set content-type with --content-type flag.";static flags={"content-type":A.string({description:'The MIME content type of the value. By default, "application/json" is assumed.',default:"application/json"})};static args={storeId:w.string({description:"The key-value store ID to set the value in.",required:!0}),itemKey:w.string({description:"The key of the item in the key-value store.",required:!0}),value:w.string({description:"The value to set."})};async run(){let{storeId:e,itemKey:r,value:o}=this.args,{contentType:s}=this.flags,i=await S(),a=await Q(i,e);if(!a){m({message:`Key-value store with ID or name "${e}" not found.`});return}let{keyValueStoreClient:n}=a;try{await n.setRecord({key:r,value:o||process.stdin,contentType:s}),R({message:`Value with key "${r}" set in the key-value store.`,stdout:!0})}catch(c){let d=c;m({message:`Failed to set value with key "${r}" in the key-value store.
|
|
148
|
+
${d.message||d}`})}}};var To=class extends g{static name="key-value-stores";static description=`Manages persistent key-value storage.
|
|
149
|
+
|
|
150
|
+
Alias: kvs`;static hiddenAliases=["kvs"];static subcommands=[po,fo,go,ho,yo,wo,Ao,bo,vo];async run(){this.printHelp()}};import xd from"chalk";import Od from"computer-name";import Nd from"cors";import ks from"express";import ua from"inquirer";import Ld from"open";import{cryptoRandomObjectId as Dd}from"@apify/utilities";import{readFileSync as Sd,writeFileSync as Ps}from"fs";import{promisify as Cd}from"util";import Id from"mixpanel";import{cryptoRandomObjectId as $d}from"@apify/utilities";var sa=Id.init(Ws,{keepAlive:!1}),Ed='Apify collects telemetry data about general usage of Apify CLI to help us improve the product. This feature is enabled by default, and you can disable it by setting the "APIFY_CLI_DISABLE_TELEMETRY" environment variable to "1". You can find more information about our telemetry in https://docs.apify.com/cli/docs/telemetry.',Rd=Cd(sa.track.bind(sa)),ia=l(()=>`CLI:${$d()}`,"createLocalDistinctId"),na=l(async()=>{try{return JSON.parse(Sd(Le(),"utf-8")).distinctId}catch{let e=(await k()).id||ia();return T({message:Ed}),Xe(Le()),Ps(Le(),JSON.stringify({distinctId:e},null," ")),e}},"getOrCreateLocalDistinctId"),aa=l(()=>{try{Xe(Le()),Ps(Le(),JSON.stringify({distinctId:ia()},null," "))}catch{}},"regenerateLocalDistinctId"),ca=!process.env.APIFY_CLI_DISABLE_TELEMETRY||["false","0"].includes(process.env.APIFY_CLI_DISABLE_TELEMETRY),_d=l(async({eventName:t,eventData:e})=>{if(ca)try{let r=na();await Rd(t,{distinct_id:r,app:"cli",...e})}catch{}},"maybeTrackTelemetry"),la=l(async t=>{if(ca)try{let e=na();Xe(Le()),Ps(Le(),JSON.stringify({distinctId:t},null," ")),await _d({eventName:"$create_alias",eventData:{alias:e}})}catch{}},"useApifyIdentity");var Us="https://console.apify.com/settings/integrations",Pd=new URL(Us).origin,kd=Us.includes("localhost")?"http://localhost:3333":void 0,da="v1",Fs=l(async t=>{let e=await xt(t,kd),r=await k();return e?(await la(r.id),R({message:`You are logged in to Apify as ${r.username||r.id}. ${xd.gray(`Your token is stored at ${se()}.`)}`})):m({message:"Login to Apify failed, the provided API token is not valid."}),e},"tryToLogin"),So=class extends g{static name="login";static description=`Authenticates your Apify account and saves credentials to '${se()}'.
|
|
151
|
+
All other commands use these stored credentials.
|
|
152
|
+
|
|
153
|
+
Run 'apify logout' to remove authentication.`;static flags={token:A.string({char:"t",description:"[Optional] Apify API token",required:!1}),method:A.string({char:"m",description:"[Optional] Method of logging in to Apify",choices:["console","manual"],required:!1})};async run(){let{token:e,method:r}=this.flags;if(e){await Fs(e);return}let o=r;if(r||(o=(await ua.prompt([{type:"list",name:"loginMethod",message:"Choose how you want to log in to Apify",choices:[{value:"console",name:"Through Apify Console in your default browser",short:"Through Apify Console"},{value:"manual",name:"Enter API token manually",short:"Manually"}],loop:!0}])).loginMethod),o==="console"){let s,i=ks();i.use(Nd({origin:Pd,allowedHeaders:["Content-Type","Authorization"]})),i.use((u,f,p)=>{f.set("Connection","close"),p()}),i.use(ks.json());let a=Dd();i.use((u,f,p)=>{let{token:h}=u.query;if(!h){let y=u.get("Authorization");if(y){let[b,C,...v]=y.trim().split(/\s+/);b.toLowerCase()==="bearer"&&C&&v.length===0&&(h=C)}}h!==a?(f.status(401),f.send("Authorization failed")):p()});let n=ks.Router();i.use(`/api/${da}`,n),n.post("/login-token",async(u,f)=>{try{if(u.body.apiToken)await Fs(u.body.apiToken);else throw new Error("Request did not contain API token");f.end()}catch(p){let h=`Login to Apify failed with error: ${p.message}`;m({message:h}),f.status(500),f.send(h)}s.close()}),n.post("/exit",(u,f)=>{u.body.isWindowClosed?m({message:"Login to Apify failed, the console window was closed."}):u.body.actionCanceled?m({message:"Login to Apify failed, the action was canceled in the Apify Console."}):m({message:"Login to Apify failed."}),f.end(),s.close()}),s=i.listen(0);let{port:c}=s.address(),d=new URL(Us);d.searchParams.set("localCliCommand","login"),d.searchParams.set("localCliPort",`${c}`),d.searchParams.set("localCliToken",a),d.searchParams.set("localCliApiVersion",da);try{d.searchParams.set("localCliComputerName",encodeURIComponent(Od()))}catch{}T({message:`Opening Apify Console at "${d.href}"...`}),await Ld(d.href)}else{console.log("Enter your Apify API token. You can find it at https://console.apify.com/settings/integrations");let s=await ua.prompt([{name:"token",message:"token:",type:"password"}]);await Fs(s.token)}}};var Co=class extends g{static name="logout";static description=`Removes authentication by deleting your API token and account information from '${se()}'.
|
|
154
|
+
Run 'apify login' to authenticate again.`;async run(){await It(se()),aa(),R({message:"You are logged out from your Apify account."})}};var Io=class extends At{static name="pull"};var $o=class extends bt{static name="push"};var Eo=class extends g{static name="request-queues";static description="Manages URL queues for web scraping and automation tasks.";async run(){this.printHelp()}};import{existsSync as pa,renameSync as Bd}from"fs";import{mkdir as Ro,readFile as Vd,stat as fa,writeFile as Wt}from"fs/promises";import{dirname as _o,join as xo}from"path";import Oe from"process";import Gd from"mime";import{minVersion as Hd}from"semver";import{APIFY_ENV_VARS as Oo}from"@apify/consts";import{validateInputSchema as Yd,validateInputUsingValidator as ga}from"@apify/input_schema";import{none as Kt,some as Fd}from"@sapphire/result";import{execa as Ud}from"execa";var js=l(t=>`
|
|
155
|
+
(async () => {
|
|
156
|
+
const [nodeModule, process, path, fs] = await Promise.all([
|
|
157
|
+
import('node:module'),
|
|
158
|
+
import('node:process'),
|
|
159
|
+
import('node:path'),
|
|
160
|
+
import('node:fs/promises'),
|
|
161
|
+
]);
|
|
162
|
+
|
|
163
|
+
/* we fake a script file here because otherwise node AND deno will fail to resolve modules, but bun works -.- */
|
|
164
|
+
const dirname = path.join(process.cwd(), '__apify_cli_fetch_module_version__.js');
|
|
165
|
+
|
|
166
|
+
const _require = nodeModule.createRequire(dirname);
|
|
167
|
+
|
|
168
|
+
try {
|
|
169
|
+
const modulePath = _require.resolve('${t}');
|
|
170
|
+
const moduleDir = path.dirname(modulePath);
|
|
171
|
+
|
|
172
|
+
const packageJson = await fs.readFile(path.join(moduleDir, 'package.json'), 'utf8').catch(() => null);
|
|
173
|
+
|
|
174
|
+
if (!packageJson) {
|
|
175
|
+
console.log('n/a');
|
|
176
|
+
return;
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
const packageJsonObj = JSON.parse(packageJson);
|
|
180
|
+
console.log(packageJsonObj.version);
|
|
181
|
+
} catch {
|
|
182
|
+
console.log('n/a');
|
|
183
|
+
}
|
|
184
|
+
})();
|
|
185
|
+
`.replaceAll(`
|
|
186
|
+
`," ").replaceAll(" "," "),"jsScript"),jd=l(t=>`
|
|
187
|
+
try:
|
|
188
|
+
import ${t}
|
|
189
|
+
print(${t}.__version__)
|
|
190
|
+
except:
|
|
191
|
+
print('n/a')
|
|
192
|
+
`,"pyScript"),Md={node(t){return["-e",`"${js(t)}"`]},deno(t){return["eval",`"${js(t)}"`]},bun(t){return["--eval",`"${js(t)}"`]},python(t){return["-c",`"${jd(t)}"`]}};async function ma({moduleName:t,project:e}){if(!e.runtime)return $("useModuleVersion",{status:"no_runtime_found",project:e,moduleName:t}),Kt;let r;if(e.type===0)r=e.runtime.runtimeShorthand||"node";else if(e.type===1||e.type===2)r="python";else return $("useModuleVersion",{status:"unsupported_project_type",project:e,moduleName:t}),Kt;let o=Md[r]?.(t);if(!o)return $("useModuleVersion",{status:"no_version_script_found",project:e,moduleName:t}),Kt;try{let s=await Ud(e.runtime.executablePath,o,{shell:!0,windowsHide:!0,verbose:process.env.APIFY_CLI_DEBUG?"full":void 0});return s.stdout.trim()==="n/a"?($("useModuleVersion",{status:"no_version_found",project:e,moduleName:t}),Kt):($("useModuleVersion",{status:"success",project:e,moduleName:t,version:s.stdout.trim()}),Fd(s.stdout.trim()))}catch(s){return $("useModuleVersion",{status:"failed_to_run_version_script",project:e,moduleName:t,error:s}),Kt}}l(ma,"useModuleVersion");var No=class extends g{static name="run";static description=`Executes Actor locally with simulated Apify environment variables.
|
|
193
|
+
Stores data in local '${Ke}' directory.
|
|
194
|
+
|
|
195
|
+
NOTE: For Node.js Actors, customize behavior by modifying the 'start' script in package.json file.`;static flags={purge:A.boolean({char:"p",description:"Whether to purge the default request queue, dataset and key-value store before the run starts.\nFor crawlee projects, this is the default behavior, and the flag is optional.\nUse `--no-purge` to keep the storage folder intact.",required:!1,default:!0,exclusive:["resurrect"]}),resurrect:A.boolean({description:"Whether to keep the default request queue, dataset and key-value store before the run starts.",required:!1,default:!1,exclusive:["purge"]}),entrypoint:A.string({description:["Optional entrypoint for running with injected environment variables.",`
|
|
196
|
+
`,"For Python, it is the module name, or a path to a file.",`
|
|
197
|
+
`,"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.'].join(" "),required:!1}),input:A.string({char:"i",description:"Optional JSON input to be given to the Actor.",required:!1,stdin:2,exclusive:["input-file"]}),"input-file":A.string({aliases:["if"],description:"Optional path to a file with JSON input to be given to the Actor. The file must be a valid JSON file. You can also specify `-` to read from standard input.",required:!1,stdin:2,exclusive:["input"]})};async run(){let e=Oe.cwd(),{proxy:r,id:o,token:s}=await k(),i=await je({cwd:e});if(i.isErr()){let{message:j,cause:G}=i.unwrapErr();m({message:`${j}${G?`
|
|
198
|
+
${G.message}`:""}`}),Oe.exitCode=5;return}let{config:a}=i.unwrap(),n=ae(),c=await Tt({cwd:e});if(c.isErr()){m({message:c.unwrapErr().message}),Oe.exitCode=5;return}let d=c.unwrap(),{type:u,entrypoint:f,runtime:p}=d;if(u===3)throw new Error("Actor is of an unknown format. Make sure your project is supported by Apify CLI (either a package.json file is present, or a Python entrypoint could be found) or you are in a migrated Scrapy project.");if(!p){switch(u){case 0:m({message:`No Node.js detected! Please install Node.js ${we} (or higher) to be able to run Node.js Actors locally.`});break;case 2:case 1:m({message:`No Python detected! Please install Python ${We} (or higher) to be able to run Python Actors locally.`});break;default:m({message:`No runtime detected! Make sure you have Python ${We} (or higher) or Node.js ${we} (or higher) installed.`})}return}let h,y;if(this.flags.entrypoint){y=this.flags.entrypoint;let j=xo(e,this.flags.entrypoint),G=await fa(j).catch(()=>null);G?.isDirectory()?h=1:G?.isFile()?h=0:h=2}else if(f?.script)h=2,y=f.script;else if(f?.path)h=u!==0?1:0,y=f.path;else{m({message:"No entrypoint detected! Please provide an entrypoint using the --entrypoint flag, or make sure your project has an entrypoint."});return}pa(zo)&&!pa(n)&&(Bd(zo,n),x({message:`The legacy 'apify_storage' directory was renamed to '${n}' to align it with Apify SDK v3. Contents were left intact.`}));let b=await ma({moduleName:"crawlee",project:d}),C="0";this.flags.resurrect&&(this.flags.purge=!1),this.flags.purge&&(C="1",b.isNone()&&(await Promise.all([pi(),gi(),fi()]),T({message:"All default local stores were purged."}))),this.flags.purge||!await hi()&&!this.flags.resurrect&&x({message:"The storage directory contains a previous state, the Actor will continue where it left off. To start from the initial state, use --purge parameter to clean the storage directory."});let v=await ht(e,this.flags.input,this.flags.inputFile);if(v===!1)return;let I=await this.validateAndStoreInput(v),L={[Oo.LOCAL_STORAGE_DIR]:n,CRAWLEE_STORAGE_DIR:n,CRAWLEE_PURGE_ON_START:C};if(r&&r.password&&(L[Oo.PROXY_PASSWORD]=r.password),o&&(L[Oo.USER_ID]=o),s&&(L[Oo.TOKEN]=s),a.environmentVariables){let j=nn(a.environmentVariables);Object.assign(L,j)}let D=Object.assign(L,Oe.env);o||x({message:'You are not logged in with your Apify Account. Some features like Apify Proxy will not work. Call "apify login" to fix that.'});try{switch(u){case 0:{let j=Hd(we);if(cr(p.version)?D.NODE_OPTIONS=D.NODE_OPTIONS?`${D.NODE_OPTIONS} --max-http-header-size=80000`:"--max-http-header-size=80000":x({message:`You are running Node.js version ${p.version}, which is no longer supported. Please upgrade to Node.js version ${j} or later.`}),h===0||h===1)await fe({cmd:p.executablePath,args:[y],opts:{env:D,cwd:e}});else{let G=await Vd(xo(e,"package.json"),"utf8").catch(()=>"{}"),Y=JSON.parse(G);if(!Y.scripts)throw new Error('No scripts were found in package.json. Please set it up for your project. For more information about that call "apify help run".');if(!Y.scripts[y])throw new Error(`The script "${y}" was not found in package.json. Please set it up for your project. For more information about that call "apify help run".`);if(!p.pmPath)throw new Error("No npm executable found! Please make sure your Node.js runtime has npm installed if you want to run package.json scripts locally.");await fe({cmd:p.pmPath,args:["run",y],opts:{env:D,cwd:e},overrideCommand:p.pmName})}break}case 1:case 2:{if(!ar(p.version)){m({message:`Python Actors require Python 3.9 or higher, but you have Python ${p.version}!`}),m({message:"Please install Python 3.9 or higher to be able to run Python Actors locally."});return}h===1?await fe({cmd:p.executablePath,args:["-m",y],opts:{env:D,cwd:e}}):await fe({cmd:p.executablePath,args:[y],opts:{env:D,cwd:e}});break}default:m({message:"Failed to detect the language of your project. Please report this issue to the Apify team with your project structure over at https://github.com/apify/apify-cli/issues"})}}catch(j){let{stderr:G}=j}finally{if(I)if(I.existingInput){let j=await fa(I.inputFilePath);if(Math.trunc(j.mtimeMs)-I.writtenAt>=5){x({message:`The "${I.inputFilePath}" file was overwritten during the run. The CLI will not undo the setting of missing default fields from your input schema.`});return}await Wt(I.inputFilePath,I.existingInput.body)}else await $t(I.inputFilePath)}}async validateAndStoreInput(e){let{inputSchema:r}=await ot({cwd:Oe.cwd()});if(!r){if(!e)return null;let d=Ot(Oe.cwd()),u=xo(Oe.cwd(),ve(),d?.fileName??"INPUT.json");return await Ro(_o(u),{recursive:!0}),await Wt(u,JSON.stringify(e.input,null,2)),{existingInput:d,inputFilePath:u,writtenAt:Date.now()}}let o=new nt({strict:!1,unicodeRegExp:!1});Yd(o,r);let s=Fn(r),i=Un(r,o),a=Ot(Oe.cwd()),n=xo(Oe.cwd(),ve(),a?.fileName??"INPUT.json"),c;switch(e?.source){case"stdin":c=`The input provided through standard input is invalid. Please fix the following errors:
|
|
199
|
+
`;break;case"input":c=`The input provided through the --input flag is invalid. Please fix the following errors:
|
|
200
|
+
`;break;default:e?c=`The input provided through the ${e.source} file is invalid. Please fix the following errors:
|
|
201
|
+
`:c=`The input in your storage is invalid. Please fix the following errors:
|
|
202
|
+
`;break}if(e){let d={...s,...e.input},u=ga(i,r,d);if(u.length>0)throw new Error(`${c}${u.map(f=>` - ${f.message.replace("Field input.","Field ")}`).join(`
|
|
203
|
+
`)}`);return await Ro(_o(n),{recursive:!0}),await Wt(n,JSON.stringify(d,null,2)),{existingInput:a,inputFilePath:n,writtenAt:Date.now()}}if(!a)return await Ro(_o(n),{recursive:!0}),await Wt(n,JSON.stringify(s,null,2)),{existingInput:a,inputFilePath:n,writtenAt:Date.now()};if(Gd.getExtension(a.contentType)==="json"){let d=JSON.parse(a.body.toString("utf-8"));if(Array.isArray(d))throw new Error("The input in your storage is invalid. It should be an object, not an array.");let u={...s,...d},f=ga(i,r,u);if(f.length>0)throw new Error(`${c}${f.map(p=>` - ${p.message.replace("Field input.","Field ")}`).join(`
|
|
204
|
+
`)}`);return await Ro(_o(n),{recursive:!0}),await Wt(n,JSON.stringify(u,null,2)),{existingInput:a,inputFilePath:n,writtenAt:Date.now()}}return null}};import{ACTOR_JOB_STATUSES as Lo}from"@apify/consts";var Jd=[Lo.READY,Lo.RUNNING],qd=[Lo.ABORTING,Lo.TIMING_OUT],Do=class extends g{static name="abort";static description="Aborts an Actor run.";static args={runId:w.string({required:!0,description:"The run ID to abort."})};static flags={force:A.boolean({description:"Whether to force the run to abort immediately, instead of gracefully.",default:!1,char:"f"})};static enableJsonFlag=!0;async run(){let{runId:e}=this.args,r=await S(),o=await r.run(e).get();if(!o){m({message:`Run with ID "${e}" was not found on your account.`,stdout:!0});return}if(!Jd.includes(o.status)){qd.includes(o.status)?m({message:`Run with ID "${e}" is already aborting.`,stdout:!0}):m({message:`Run with ID "${e}" is already aborted.`,stdout:!0});return}try{let s=await r.run(e).abort({gracefully:!this.flags.force});if(this.flags.json){N(s);return}this.flags.force?R({message:`Triggered the immediate abort of run "${e}".`,stdout:!0}):R({message:`Triggered the abort of run "${e}", it should finish aborting in up to 30 seconds.`,stdout:!0})}catch(s){let i=s;m({message:`Failed to abort run "${e}".
|
|
205
|
+
${i.message||i}`,stdout:!0})}}};import E from"chalk";var zt=new V({allColumns:["","Unit","USD Amount"],mandatoryColumns:["","Unit","USD Amount"],columnAlignments:{Unit:"right","USD Amount":"right"}}),ha={"Actor compute units":"ACTOR_COMPUTE_UNITS","Dataset reads":"DATASET_READS","Dataset writes":"DATASET_WRITES","Key-value store reads":"KEY_VALUE_STORE_READS","Key-value store writes":"KEY_VALUE_STORE_WRITES","Key-value store lists":"KEY_VALUE_STORE_LISTS","Request queue reads":"REQUEST_QUEUE_READS","Request queue writes":"REQUEST_QUEUE_WRITES","Data transfer internal":"DATA_TRANSFER_INTERNAL_GBYTES","Data transfer external":"DATA_TRANSFER_EXTERNAL_GBYTES","Proxy residential data transfer":"PROXY_RESIDENTIAL_TRANSFER_GBYTES","Proxy SERPs":"PROXY_SERPS"},Po=class extends g{static name="info";static description="Prints information about an Actor run.";static args={runId:w.string({required:!0,description:"The run ID to print information about."})};static flags={verbose:A.boolean({char:"v",description:"Prints more in-depth information about the Actor run.",default:!1})};static enableJsonFlag=!0;async run(){let{runId:e}=this.args,r=await S(),o=await r.run(e).get();if(!o){m({message:`Run with ID "${e}" was not found on your account.`});return}let[s,i,a,n,c]=await Promise.all([r.actor(o.actId).get(),r.build(o.buildId).get(),o.actorTaskId?r.task(o.actorTaskId).get():Promise.resolve(void 0),r.dataset(o.defaultDatasetId).get(),r.requestQueue(o.defaultRequestQueueId).get()]);if(this.flags.json){N({...o,actor:s,build:i,task:a,defaultDataset:n,defaultRequestQueue:c});return}this.addDetailedUsage(o);let d=s?.username?`${s.username}/${s.name}`:s?.name??"unknown-actor",u=[`${E.yellow("Actor")}: ${d} (${E.grey(o.actId)})`];a?u.push(`\u2514\u2500 ${E.yellow("Task")}: ${a.title??a.name} (${E.gray(o.actorTaskId)})`,""):o.actorTaskId?u.push(`\u2514\u2500 ${E.yellow("Task")}: unknown-task (${E.gray(o.actorTaskId)})`,""):u.push("");let f=` (exit code: ${E.gray(o.exitCode!==null?o.exitCode:"N/A")})`;u.push(`${E.yellow("Status")}: ${be(o.status)}${f}`),o.statusMessage&&u.push(`\u2514\u2500 ${E.yellow("Status Message:")} ${o.statusMessage}`);let p=n?.itemCount??0;u.push(`${E.yellow("Results")}: ${E.cyan(p.toLocaleString("en-US"))}`),c?u.push(`${E.yellow("Requests")}: ${E.cyan(c.handledRequestCount.toLocaleString("en-US"))} out of ${E.cyan(c.totalRequestCount.toLocaleString("en-US"))} handled`):u.push(`${E.yellow("Requests")}: ${E.gray("unknown handled")}`);let h=this.flags.verbose?"":E.gray(` (run with ${E.yellow("--verbose")} for a detailed breakdown)`);if(o.usageTotalUsd?u.push(`${E.yellow("Usage")}: ${E.cyan(this.formatUsd(o.usageTotalUsd))}${h}`):u.push(`${E.yellow("Usage")}: $${E.gray("0.000")}${h}`),this.flags.verbose&&u.push(zt.render(0)),u.push(""),u.push(`${E.yellow("Started")}: ${B.display(o.startedAt)}`),o.finishedAt)u.push(`${E.yellow("Finished")}: ${B.display(o.finishedAt)} (took ${E.gray(oe.format(o.stats.durationMillis))})`);else{let v=Date.now()-o.startedAt.getTime();u.push(`${E.yellow("Finished")}: ${E.gray(`Running for ${oe.format(v)}`)}`)}if(u.push(""),o.stats.resurrectCount?u.push(`${E.yellow("Resurrected")}: Yes, ${E.cyan(o.stats.resurrectCount.toLocaleString("en-US"))} ${this.pluralString(o.stats.resurrectCount,"time","times")}`):u.push(`${E.yellow("Resurrected")}: No`),o.containerUrl&&u.push(`${E.yellow("Container URL")}: ${E.blue(o.containerUrl)}`),u.push(`${E.yellow("Origin")}: ${o.meta.origin}`),s){let v=o.buildNumber.split(".").slice(0,2).join("."),I=s.versions.find(j=>j.versionNumber===v),L=Object.entries(s.taggedBuilds??{}).find(([,j])=>j.buildNumber===o.buildNumber)?.[0],D=[`${E.yellow("Build")}:`,E.cyan(o.buildNumber)];L?D.push(`(${E.yellow(L)})`):D.push(`(${E.gray("N/A")})`),I&&D.push(`| ${E.gray("Actor version:")} ${E.cyan(I.versionNumber)} (${E.yellow(I.buildTag)})`),u.push(D.join(" "))}else u.push(`${E.yellow("Build")}: ${E.cyan(o.buildNumber)}`);u.push(`${E.yellow("Timeout")}: ${o.options.timeoutSecs.toLocaleString("en-US")} seconds`),u.push(`${E.yellow("Memory")}: ${o.options.memoryMbytes} MB`),u.push(""),u.push(`${E.yellow("CPU")}: ${E.gray("Average:")} ${o.stats.cpuAvgUsage.toFixed(2)}% | ${E.gray("Maximum:")} ${o.stats.cpuMaxUsage.toFixed(2)}%`),u.push(`${E.yellow("Memory")}: ${E.gray("Average:")} ${K({bytes:o.stats.memAvgBytes,shortBytes:!0})} | ${E.gray("Maximum:")} ${K({bytes:o.stats.memMaxBytes,shortBytes:!0})}`),u.push("");let y=`https://console.apify.com/actors/${o.actId}/runs/${o.id}`,b=`https://console.apify.com/storage/datasets/${o.defaultDatasetId}`,C=`https://console.apify.com/storage/key-value-stores/${o.defaultKeyValueStoreId}`;u.push(`${E.blue("Export results")}: ${b}`),u.push(`${E.blue("View saved items")}: ${C}`),u.push(`${E.blue("View in Apify Console")}: ${y}`),_({message:u.join(`
|
|
206
|
+
`),stdout:!0})}addDetailedUsage(e){let{usage:r,usageUsd:o}=e;if(!r||!o){for(let s of Object.keys(ha))zt.pushRow({"":s,Unit:"N/A","USD Amount":"N/A"});return}for(let[s,i]of Object.entries(ha)){let a=r[i]??0,n=o[i]??0;switch(i){case"ACTOR_COMPUTE_UNITS":{zt.pushRow({"":s,Unit:a.toFixed(4),"USD Amount":this.formatUsd(n)});break}case"DATA_TRANSFER_INTERNAL_GBYTES":case"DATA_TRANSFER_EXTERNAL_GBYTES":case"PROXY_RESIDENTIAL_TRANSFER_GBYTES":{zt.pushRow({"":s,Unit:K({bytes:a*1024*1024*1024,shortBytes:!0}),"USD Amount":this.formatUsd(n)});break}default:zt.pushRow({"":s,Unit:a.toLocaleString("en-US"),"USD Amount":this.formatUsd(n)})}}}formatUsd(e){return`$${e.toFixed(3)}`}};var ko=class extends g{static name="log";static description="Prints the log of a specific run.";static args={runId:w.string({required:!0,description:"The run ID to get the log from."})};async run(){let{runId:e}=this.args,r=await S(),o=await r.run(e).get();if(!o){m({message:`Run with ID "${e}" was not found on your account.`,stdout:!0});return}T({message:`Log for run with ID "${e}":
|
|
207
|
+
`,stdout:!0});try{await Se({job:o,apifyClient:r})}catch(s){m({message:`Failed to get log for run with ID "${e}": ${s.message}`})}}};import ge from"chalk";var ya=new V({allColumns:["ID","Status","Results","Usage","Started At","Took","Build No.","Origin"],mandatoryColumns:["ID","Status","Results","Usage","Started At","Took"],columnAlignments:{Results:"right",Usage:"right",Took:"right","Build No.":"right"}}),Fo=class extends g{static name="ls";static description="Lists all runs of the Actor.";static flags={offset:A.integer({description:"Number of runs that will be skipped.",default:0}),limit:A.integer({description:"Number of runs that will be listed.",default:10}),desc:A.boolean({description:"Sort runs in descending order.",default:!1}),compact:A.boolean({description:"Display a compact table.",default:!1,char:"c"})};static args={actorId:w.string({description:"Optional Actor ID or Name to list runs for. By default, it will use the Actor from the current directory."})};static enableJsonFlag=!0;async run(){let{desc:e,limit:r,offset:o,compact:s,json:i}=this.flags,{actorId:a}=this.args,n=await S(),c=await ke({providedActorNameOrId:a,client:n});if(!c.valid){m({message:`${c.reason}. Please run this command in an Actor directory, or specify the Actor ID.`});return}let d=await n.actor(c.id).runs().list({desc:e,limit:r,offset:o});if(i){N(d);return}if(!d.items.length){_({message:"There are no recent runs found for this Actor."});return}let u=[`${ge.reset("Showing")} ${ge.yellow(d.items.length)} out of ${ge.yellow(d.total)} runs for Actor ${ge.yellow(c.userFriendlyId)} (${ge.gray(c.id)})`],f=new Map(await Promise.all(d.items.map(async p=>n.dataset(p.defaultDatasetId).get().then(h=>[p.id,ge.yellow(h?.itemCount??0)],()=>[p.id,ge.gray("N/A")]))));for(let p of d.items){let h;if(p.finishedAt){let y=p.finishedAt.getTime()-p.startedAt.getTime();h=ge.gray(`${oe.format(y,void 0,{left:""})}`)}else{let y=Date.now()-p.startedAt.getTime();h=ge.gray(`Running for ${oe.format(y,void 0,{left:""})}`)}ya.pushRow({ID:ge.gray(p.id),Status:be(p.status),Results:f.get(p.id)||ge.gray("N/A"),Usage:ge.cyan(`$${(p.usageTotalUsd??0).toFixed(3)}`),"Started At":Lt.display(p.startedAt),Took:h,"Build No.":p.buildNumber,Origin:p.meta.origin??"UNKNOWN"})}u.push(ya.render(s?0:1)),_({message:u.join(`
|
|
208
|
+
`),stdout:!0})}};import{ACTOR_JOB_STATUSES as Uo}from"@apify/consts";var Kd=[Uo.SUCCEEDED,Uo.FAILED,Uo.ABORTED,Uo.TIMED_OUT],jo=class extends g{static name="resurrect";static description="Resurrects an aborted or finished Actor Run.";static args={runId:w.string({required:!0,description:"The run ID to resurrect."})};static enableJsonFlag=!0;async run(){let{runId:e}=this.args,r=await S(),o=await r.run(e).get();if(!o){m({message:`Run with ID "${e}" was not found on your account.`,stdout:!0});return}if(!Kd.includes(o.status)){m({message:`Run with ID "${e}" cannot be resurrected, as it is still running or in the process of aborting.`,stdout:!0});return}try{let s=await r.run(e).resurrect();if(this.flags.json){N(s);return}R({message:`Run with ID "${e}" was resurrected successfully.`,stdout:!0})}catch(s){let i=s;m({message:`Failed to resurrect run "${e}".
|
|
209
|
+
${i.message||i}`,stdout:!0})}}};import{ACTOR_JOB_STATUSES as Mo}from"@apify/consts";var Wd=[Mo.SUCCEEDED,Mo.FAILED,Mo.ABORTED,Mo.TIMED_OUT],Bo=class extends g{static name="rm";static description="Deletes an Actor Run.";static args={runId:w.string({description:"The run ID to delete.",required:!0})};async run(){let{runId:e}=this.args,r=await S(),o=await r.run(e).get();if(!o){m({message:`Run with ID "${e}" was not found on your account.`});return}if(!Wd.includes(o.status)){m({message:`Run with ID "${e}" cannot be deleted, as it is still running or in the process of aborting.`});return}if(!await W({type:"Actor Run",failureMessage:"Your provided value does not match the run ID."})){T({message:`Deletion of run "${e}" was canceled.`});return}try{await r.run(e).delete(),R({message:`Run with ID "${e}" was deleted.`})}catch(i){let a=i;m({message:`Failed to delete run "${e}".
|
|
210
|
+
${a.message||a}`})}}};var Vo=class extends g{static name="runs";static description="Manages Actor run operations ";static subcommands=[Do,Po,ko,Fo,jo,Bo];async run(){this.printHelp()}};var Go=class extends g{static name="add";static description="Adds a new secret to '~/.apify' for use in Actor environment variables.";static args={name:w.string({required:!0,description:"Name of the secret"}),value:w.string({required:!0,description:"Value of the secret"})};async run(){let{name:e,value:r}=this.args;rn(e,r)}};var Ho=class extends g{static name="rm";static description="Permanently deletes a secret from your stored credentials.";static args={name:w.string({required:!0,description:"Name of the secret"})};async run(){let{name:e}=this.args;on(e)}};var Yo=class extends g{static name="secrets";static description=`Manages secure environment variables for Actors.
|
|
211
|
+
|
|
212
|
+
Example:
|
|
213
|
+
$ apify secrets add mySecret TopSecretValue123
|
|
214
|
+
|
|
215
|
+
The "mySecret" value can be used in an environment variable defined in '${M}' file by adding the "@"
|
|
216
|
+
prefix:
|
|
217
|
+
|
|
218
|
+
{
|
|
219
|
+
"actorSpecification": 1,
|
|
220
|
+
"name": "my_actor",
|
|
221
|
+
"environmentVariables": { "SECRET_ENV_VAR": "@mySecret" },
|
|
222
|
+
"version": "0.1"
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
When the Actor is pushed to Apify cloud, the "SECRET_ENV_VAR" and its value is stored as a secret environment variable
|
|
226
|
+
of the Actor.`;static subcommands=[Go,Ho];async run(){this.printHelp()}};import wa from"chalk";var Jo=class extends g{static name="run";static description=`Executes predefined Actor task remotely using local key-value store for input.
|
|
227
|
+
Customize with --memory and --timeout flags.
|
|
228
|
+
`;static flags=wt("Task");static args={taskId:w.string({required:!0,description:'Name or ID of the Task to run (e.g. "my-task" or "E2jjCZBezvAZnX8Rb").'})};async run(){let e=await S(),r=await k(),o=r.username||r.id,{id:s,userFriendlyId:i,title:a}=await this.resolveTaskId(e,o),n={waitForFinish:2};this.flags.build&&(n.build=this.flags.build),this.flags.timeout&&(n.timeout=this.flags.timeout),this.flags.memory&&(n.memory=this.flags.memory);let c,d,u=yt(e,{actorOrTaskData:{id:s,userFriendlyId:i,title:a},runOptions:n,type:"Task",printRunLogs:!0});for await(let f of u)c=`https://console.apify.com/actors/${f.actId}/runs/${f.id}`,d=`https://console.apify.com/storage/datasets/${f.defaultDatasetId}`;_({message:["",`${wa.blue("Export results")}: ${d}`,`${wa.blue("View on Apify Console")}: ${c}`].join(`
|
|
229
|
+
`),stdout:!0})}async resolveTaskId(e,r){let{taskId:o}=this.args;if(o?.includes("/")){let s=await e.task(o).get();if(!s)throw new Error(`Cannot find Task with ID '${o}' in your account.`);return{id:s.id,userFriendlyId:`${r}/${s.name}`,title:s.title,task:s}}if(o){let s=await e.task(`${r}/${o.toLowerCase()}`).get();if(!s)throw new Error(`Cannot find Task with name '${o}' in your account.`);return{id:s.id,userFriendlyId:`${r}/${s.name}`,title:s.title,task:s}}throw new Error("Please provide a valid Task ID or name.")}};var qo=class extends g{static name="task";static description="Manages scheduled and predefined Actor configurations.";static subcommands=[Jo];async run(){this.printHelp()}};import zd from"process";import{validateInputSchema as Xd}from"@apify/input_schema";var Ko=class extends g{static name="validate-schema";static description=`Validates Actor input schema from one of these locations (in priority order):
|
|
230
|
+
1. Object in '${M}' under "input" key
|
|
231
|
+
2. JSON file path in '${M}' "input" key
|
|
232
|
+
3. .actor/INPUT_SCHEMA.json
|
|
233
|
+
4. INPUT_SCHEMA.json
|
|
234
|
+
|
|
235
|
+
Optionally specify custom schema path to validate.`;static args={path:w.string({required:!1,description:"Optional path to your INPUT_SCHEMA.json file. If not provided ./INPUT_SCHEMA.json is used."})};static hiddenAliases=["vis"];async run(){let{inputSchema:e,inputSchemaPath:r}=await ot({forcePath:this.args.path,cwd:zd.cwd()});if(!e)throw new Error(`Input schema has not been found at ${r}.`);r?T({message:`Validating input schema stored at ${r}`}):T({message:`Validating input schema embedded in '${M}'`});let o=new nt({strict:!1});Xd(o,e),R({message:"Input schema is valid."})}};var WR=[Ar,Nr,Fr,so,To,Eo,Vo,Yo,qo,Ur,Yt,Ht,Kr,io,ao,mo,uo,So,Co,Io,$o,No,Ko,qt],zR=[ft,pt,mt,dt,ut,lt,qt,Yt,Ht];export{yr as a,Df as b,Pf as c,WR as d,zR as e};
|
|
236
|
+
//# sourceMappingURL=chunk-RGQHG4D4.js.map
|