apify-cli 1.2.2-beta.13 → 1.2.2-beta.14

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.
@@ -1,56 +1,56 @@
1
- var Ga=Object.defineProperty;var c=(r,e)=>Ga(r,"name",{value:e,configurable:!0});import Ie from"process";import{parseArgs as Sn}from"util";import Ur from"chalk";import{satisfies as Dc}from"semver";import ks from"chalk";import hc from"indent-string";import yc from"widest-line";import wc from"wrap-ansi";import Ya from"chalk";function C(r,...e){process.env.APIFY_CLI_DEBUG&&console.error(Ya.gray(`[${r}]`),...e)}c(C,"cliDebugPrint");import{realpathSync as Ha}from"fs";import{dirname as Ja}from"path";import mt from"chalk";function Ze(r){r.stdoutOutput&&console.log(...r.stdoutOutput),r.stderrOutput&&console.error(...r.stderrOutput)}c(Ze,"internalLog");function R(r){Ze({[r.stdout?"stdoutOutput":"stderrOutput"]:[r.message]})}c(R,"simpleLog");function p(r){Ze({[r.stdout?"stdoutOutput":"stderrOutput"]:[mt.red("Error:"),r.message]})}c(p,"error");function x(r){Ze({[r.stdout?"stdoutOutput":"stderrOutput"]:[mt.yellow.bold("Warning:"),r.message]})}c(x,"warning");function $(r){Ze({[r.stdout?"stdoutOutput":"stderrOutput"]:[mt.green("Success:"),r.message]})}c($,"success");function Ae(r){Ze({[r.stdout?"stdoutOutput":"stderrOutput"]:[mt.gray("Run:"),r.message]})}c(Ae,"run");function v(r){Ze({[r.stdout?"stdoutOutput":"stderrOutput"]:[mt.white("Info:"),r.message]})}c(v,"info");function fs(r){Ze({[r.stdout?"stdoutOutput":"stderrOutput"]:[mt.blue(r.message),r.url]})}c(fs,"link");var gs="0.0.0";var Ka="1.2.2-beta.13",qa="15dc5f318f29938a1a434933de0e3fdf99594fef";function Wa(){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 r=process.argv[1];if(!r)return x({message:"Failed to detect install method of CLI, assuming npm"}),"npm";let e=Ha(r);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"}c(Wa,"detectInstallMethod");function za(){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}}c(za,"getRuntimeInfo");var xt=null;function K(){if(xt)return xt;let r=Wa(),e=za();return xt={version:Ka,hash:qa,arch:process.env.APIFY_BUNDLE_ARCH??process.arch,platform:process.platform==="win32"?"windows":process.platform,runtime:e,extraRuntimeData:e.nodeVersion?`(emulating node ${e.nodeVersion})`:"",installMethod:r,get fullVersionString(){return`apify-cli/${this.version} (${this.hash.slice(0,7)}) running on ${this.platform}-${this.arch} with ${this.runtime.runtime}-${e.version}${this.extraRuntimeData?` ${this.extraRuntimeData}`:""}, installed via ${this.installMethod}`},get isBeta(){return this.version.includes("beta")||this.version===gs}},r==="bundle"&&(xt.installPath=Ja(process.execPath)),xt}c(K,"useCLIMetadata");import{existsSync as Ol,mkdirSync as Nl,readFileSync as Pl,writeFileSync as Ll}from"fs";import{dirname as kl}from"path";import{cryptoRandomObjectId as Dl}from"@apify/utilities";import{homedir as Za}from"os";import{join as Qe}from"path";import{KEY_VALUE_STORE_KEYS as Qa,META_ORIGINS as el}from"@apify/consts";var ui={name:"apify-cli",version:"1.2.2-beta.13",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:">=20"},dependencies:{"@apify/actor-memory-expression":"^0.1.3","@apify/actor-templates":"^0.1.5","@apify/consts":"^2.36.0","@apify/input_schema":"^3.17.0","@apify/utilities":"^2.18.0","@crawlee/memory-storage":"^3.12.0","@inquirer/core":"^11.0.0","@inquirer/input":"^5.0.0","@inquirer/password":"^5.0.0","@inquirer/select":"^5.0.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.14.0",archiver:"~7.0.1",axios:"^1.11.0",chalk:"~5.6.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.2.0",globby:"~15.0.0",handlebars:"~4.7.8","indent-string":"^5.0.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.1.0",open:"~11.0.0",rimraf:"~6.1.0",semver:"~7.7.0","string-width":"^8.0.0","strip-ansi":"^7.1.0",tiged:"~2.12.7",which:"^6.0.0","widest-line":"^5.0.0","wrap-ansi":"^9.0.0"},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":"^7.0.0","@types/bun":"^1.2.5","@types/cors":"^2.8.17","@types/execa":"^2.0.2","@types/express":"^5.0.0","@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":"^24.0.0","@types/semver":"^7.5.8","@types/which":"^3.0.4","@yarnpkg/core":"^4.1.2",apify:"^3.2.4","cross-env":"^10.0.0",eslint:"^9.25.1","eslint-config-prettier":"^10.1.2","lint-staged":"^16.0.0","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:"^4.0.0"},volta:{node:"24.13.0",yarn:"4.12.0"},packageManager:"yarn@4.12.0",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"},resolutions:{tar:"7.5.6"}};var et="storage",hs="apify_storage",ys=1,nr={actorSpecification:ys,name:null,version:"0.0",buildTag:"latest",environmentVariables:{}},mi=1440*60*1e3,dt=c(()=>{let r=Qe(Za(),".apify");return process.env.__APIFY_INTERNAL_TEST_AUTH_PATH__?Qe(r,process.env.__APIFY_INTERNAL_TEST_AUTH_PATH__):r},"GLOBAL_CONFIGS_FOLDER"),ae=c(()=>Qe(dt(),"auth.json"),"AUTH_FILE_PATH"),ar=c(()=>Qe(dt(),"secrets.json"),"SECRETS_FILE_PATH"),lr=c(()=>Qe(dt(),"state.json"),"STATE_FILE_PATH"),cr=c(()=>Qe(dt(),"telemetry.json"),"TELEMETRY_FILE_PATH"),ur="apify.json",ws=".actor",tl="actor.json",V=Qe(ws,tl),As=new RegExp(`(^${Qa.INPUT}(?:\\.[^.]+)?$)`),be=ui.engines.node,di={"X-Apify-Request-Origin":el.CLI},tt="3.9.0",pi=".venv";import{createWriteStream as cl,existsSync as ce,mkdirSync as ul,readdirSync as bi,readFileSync as kt,writeFileSync as dr}from"fs";import{mkdir as ml,readFile as dl}from"fs/promises";import{get as pl}from"https";import{homedir as wi}from"os";import{dirname as Si,join as Se}from"path";import le from"process";import{finished as fl}from"stream/promises";import{DurationFormatter as vi,TimeTypes as rt}from"@sapphire/duration";import{Timestamp as bs}from"@sapphire/timestamp";import gl from"adm-zip";import hl from"ajv/dist/2019.js";import{ApifyClient as Ti}from"apify-client";import yl from"archiver";import{AxiosHeaders as wl}from"axios";import Al from"escape-string-regexp";import{globby as Ci}from"globby";import{getEncoding as bl}from"istextorbinary";import{Mime as Sl}from"mime";import vl from"mime/types/other.js";import Tl from"mime/types/standard.js";import{gte as Cl,minVersion as Il,satisfies as El}from"semver";import{ACTOR_ENV_VARS as Ss,ACTOR_JOB_TERMINAL_STATUSES as $l,ACTOR_NAME as Lt,APIFY_ENV_VARS as Rl,KEY_VALUE_STORE_KEYS as Ai,LOCAL_ACTOR_ENV_VARS as vs,LOCAL_STORAGE_SUBDIRS as Ts,SOURCE_FILE_FORMATS as Pt}from"@apify/consts";import{existsSync as rl,mkdirSync as ol}from"fs";import{readFile as sl,stat as fi,unlink as il,writeFile as nl}from"fs/promises";import{join as gi,sep as al}from"path";import{rimraf as ll}from"rimraf";var hi=c(async(r,e={},t=null)=>{let o=await sl(r,"utf-8"),s=JSON.parse(o),i;t?(i=s,i[t]={...s[t],...e}):i={...s,...e},await nl(r,JSON.stringify(i,null," "))},"updateLocalJson"),mr=c((r,e)=>{e||(e=r,r="."),e.split(al).reduce((o,s)=>(o=gi(o,s),rl(o)||ol(o),o),r)},"ensureFolderExistsSync"),Ot=c(async r=>{await ll(r)},"rimrafPromised"),Nt=c(async r=>{(await fi(r)).isFile()&&await il(r)},"deleteFile"),yi=c(async(r,e)=>(await Promise.all(r.map(async s=>fi(gi(e,s))))).map(s=>s.size).reduce((s,i)=>s+i,0),"sumFilesSizeInBytes");var pt=hl,pr=c(async r=>new Promise((e,t)=>{pl(r,o=>{o.statusCode===301||o.statusCode===302?(e(pr(o.headers.location)),o.destroy()):e(o)}).on("error",t)}),"httpsGet"),me=c(()=>{let r=Rl.LOCAL_STORAGE_DIR;return le.env[r]||le.env.CRAWLEE_STORAGE_DIR||et},"getLocalStorageDir"),ue=c(r=>{let e=Ss.DEFAULT_KEY_VALUE_STORE_ID,t=r||le.env[e]||vs[e];return Se(me(),Ts.keyValueStores,t)},"getLocalKeyValueStorePath"),Ii=c(r=>{let e=Ss.DEFAULT_DATASET_ID,t=r||le.env[e]||vs[e];return Se(me(),Ts.datasets,t)},"getLocalDatasetPath"),Ei=c(r=>{let e=Ss.DEFAULT_REQUEST_QUEUE_ID,t=r||le.env[e]||vs[e];return Se(me(),Ts.requestQueues,t)},"getLocalRequestQueuePath"),M=c(async()=>{let r={};try{let e=await dl(ae(),"utf-8");r=JSON.parse(e)}catch{return{}}if(!r.username&&!r.id)throw new Error('Corrupted local user info was found. Please run "apify login" to fix it.');return r},"getLocalUserInfo");async function I(){let r=await Dt();if(!r)throw new Error('You are not logged in with your Apify account. Call "apify login" to fix that.');return r}c(I,"getLoggedClientOrThrow");var $i=c(r=>{if(!r&&ce(dt())&&ce(ae())){let e=kt(ae(),"utf-8");return JSON.parse(e).token}return r},"getTokenWithAuthFileFallback"),Cs=c((r,e)=>(r=$i(r),{token:r,baseUrl:e||le.env.APIFY_CLIENT_BASE_URL,requestInterceptors:[t=>{t.headers??=new wl;for(let[o,s]of Object.entries(di))t.headers[o]=s;return t}]}),"getApifyClientOptions");async function Dt(r,e){r=$i(r);let t=new Ti(Cs(r,e)),o;try{o=await t.user("me").get()}catch{return null}return Es(ae()),dr(ae(),JSON.stringify({token:t.token,...o},null," ")),t}c(Dt,"getLoggedClient");var Is=c(r=>Se(r,V),"getLocalConfigPath"),de=c(r=>{if(ce(r))return JSON.parse(kt(r,{encoding:"utf-8"}))},"getJsonFileContent"),Me=c(r=>de(Is(r)),"getLocalConfig"),fr=c(async(r,e)=>{let t=Se(e||le.cwd(),V);await ml(Si(t),{recursive:!0}),dr(t,JSON.stringify(r,null," "))},"setLocalConfig"),_l=[me(),"node_modules",".venv"],gr=c(async r=>{let e=ue();mr(r,Ii()),mr(r,Ei()),mr(r,e);let t=Se(r,".gitignore"),o="";ce(t)&&(o=kt(t,{encoding:"utf-8"}));let s=[];for(let i of _l)RegExp(`^${Al(i)}$`,"mg").test(o)||s.push(i);s.length>0&&(o.length>0?(s.unshift("# Added by Apify CLI"),dr(t,`
1
+ var Ka=Object.defineProperty;var c=(r,e)=>Ka(r,"name",{value:e,configurable:!0});import Ie from"process";import{parseArgs as In}from"util";import Vr from"chalk";import{satisfies as jc}from"semver";import Us from"chalk";import bc from"indent-string";import Sc from"widest-line";import vc from"wrap-ansi";import qa from"chalk";function C(r,...e){process.env.APIFY_CLI_DEBUG&&console.error(qa.gray(`[${r}]`),...e)}c(C,"cliDebugPrint");import{realpathSync as Wa}from"fs";import{dirname as za}from"path";import ut from"chalk";function Ze(r){r.stdoutOutput&&console.log(...r.stdoutOutput),r.stderrOutput&&console.error(...r.stderrOutput)}c(Ze,"internalLog");function $(r){Ze({[r.stdout?"stdoutOutput":"stderrOutput"]:[r.message]})}c($,"simpleLog");function p(r){Ze({[r.stdout?"stdoutOutput":"stderrOutput"]:[ut.red("Error:"),r.message]})}c(p,"error");function x(r){Ze({[r.stdout?"stdoutOutput":"stderrOutput"]:[ut.yellow.bold("Warning:"),r.message]})}c(x,"warning");function R(r){Ze({[r.stdout?"stdoutOutput":"stderrOutput"]:[ut.green("Success:"),r.message]})}c(R,"success");function Ae(r){Ze({[r.stdout?"stdoutOutput":"stderrOutput"]:[ut.gray("Run:"),r.message]})}c(Ae,"run");function v(r){Ze({[r.stdout?"stdoutOutput":"stderrOutput"]:[ut.white("Info:"),r.message]})}c(v,"info");function ws(r){Ze({[r.stdout?"stdoutOutput":"stderrOutput"]:[ut.blue(r.message),r.url]})}c(ws,"link");var As="0.0.0";var Xa="1.2.2-beta.14",Za="ed916175513510a58c1cad49aeaf7ae0d9f03256";function Qa(){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 r=process.argv[1];if(!r)return x({message:"Failed to detect install method of CLI, assuming npm"}),"npm";let e=Wa(r);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"}c(Qa,"detectInstallMethod");function el(){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}}c(el,"getRuntimeInfo");var Nt=null;function K(){if(Nt)return Nt;let r=Qa(),e=el();return Nt={version:Xa,hash:Za,arch:process.env.APIFY_BUNDLE_ARCH??process.arch,platform:process.platform==="win32"?"windows":process.platform,runtime:e,extraRuntimeData:e.nodeVersion?`(emulating node ${e.nodeVersion})`:"",installMethod:r,get fullVersionString(){return`apify-cli/${this.version} (${this.hash.slice(0,7)}) running on ${this.platform}-${this.arch} with ${this.runtime.runtime}-${e.version}${this.extraRuntimeData?` ${this.extraRuntimeData}`:""}, installed via ${this.installMethod}`},get isBeta(){return this.version.includes("beta")||this.version===As}},r==="bundle"&&(Nt.installPath=za(process.execPath)),Nt}c(K,"useCLIMetadata");import{existsSync as kl,mkdirSync as Dl,readFileSync as Fl,writeFileSync as Ml}from"fs";import{dirname as Ul}from"path";import{cryptoRandomObjectId as jl}from"@apify/utilities";import{homedir as rl}from"os";import{join as Qe}from"path";import{KEY_VALUE_STORE_KEYS as ol,META_ORIGINS as sl}from"@apify/consts";var fi={name:"apify-cli",version:"1.2.2-beta.14",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:">=20"},dependencies:{"@apify/actor-memory-expression":"^0.1.3","@apify/actor-templates":"^0.1.5","@apify/consts":"^2.36.0","@apify/input_schema":"^3.17.0","@apify/utilities":"^2.18.0","@crawlee/memory-storage":"^3.12.0","@inquirer/core":"^11.0.0","@inquirer/input":"^5.0.0","@inquirer/password":"^5.0.0","@inquirer/select":"^5.0.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.14.0",archiver:"~7.0.1",axios:"^1.11.0",chalk:"~5.6.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.2.0",globby:"~15.0.0",handlebars:"~4.7.8","indent-string":"^5.0.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.1.0",open:"~11.0.0",rimraf:"~6.1.0",semver:"~7.7.0","string-width":"^8.0.0","strip-ansi":"^7.1.0",tiged:"~2.12.7",which:"^6.0.0","widest-line":"^5.0.0","wrap-ansi":"^9.0.0"},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":"^7.0.0","@types/bun":"^1.2.5","@types/cors":"^2.8.17","@types/execa":"^2.0.2","@types/express":"^5.0.0","@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":"^24.0.0","@types/semver":"^7.5.8","@types/which":"^3.0.4","@yarnpkg/core":"^4.1.2",apify:"^3.2.4","cross-env":"^10.0.0",eslint:"^9.25.1","eslint-config-prettier":"^10.1.2","lint-staged":"^16.0.0","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:"^4.0.0"},volta:{node:"24.13.0",yarn:"4.12.0"},packageManager:"yarn@4.12.0",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"},resolutions:{tar:"7.5.6"}};var et="storage",bs="apify_storage",Ss=1,lr={actorSpecification:Ss,name:null,version:"0.0",buildTag:"latest",environmentVariables:{}},gi=1440*60*1e3,dt=c(()=>{let r=Qe(rl(),".apify");return process.env.__APIFY_INTERNAL_TEST_AUTH_PATH__?Qe(r,process.env.__APIFY_INTERNAL_TEST_AUTH_PATH__):r},"GLOBAL_CONFIGS_FOLDER"),le=c(()=>Qe(dt(),"auth.json"),"AUTH_FILE_PATH"),cr=c(()=>Qe(dt(),"secrets.json"),"SECRETS_FILE_PATH"),mr=c(()=>Qe(dt(),"state.json"),"STATE_FILE_PATH"),ur=c(()=>Qe(dt(),"telemetry.json"),"TELEMETRY_FILE_PATH"),dr="apify.json",vs=".actor",il="actor.json",V=Qe(vs,il),Ts=new RegExp(`(^${ol.INPUT}(?:\\.[^.]+)?$)`),be=fi.engines.node,hi={"X-Apify-Request-Origin":sl.CLI},tt="3.9.0",yi=".venv";import{createWriteStream as pl,existsSync as ce,mkdirSync as fl,readdirSync as Ci,readFileSync as Ft,writeFileSync as fr}from"fs";import{mkdir as gl,readFile as hl}from"fs/promises";import{get as yl}from"https";import{homedir as vi}from"os";import{dirname as Ii,join as Se}from"path";import se from"process";import{finished as wl}from"stream/promises";import{DurationFormatter as Ei,TimeTypes as rt}from"@sapphire/duration";import{Timestamp as Cs}from"@sapphire/timestamp";import Al from"adm-zip";import bl from"ajv/dist/2019.js";import{ApifyClient as $i}from"apify-client";import Sl from"archiver";import{AxiosHeaders as vl}from"axios";import Tl from"escape-string-regexp";import{globby as Ri}from"globby";import{getEncoding as Cl}from"istextorbinary";import{Mime as Il}from"mime";import El from"mime/types/other.js";import $l from"mime/types/standard.js";import{gte as Rl,minVersion as _l,satisfies as xl}from"semver";import{ACTOR_ENV_VARS as Is,ACTOR_JOB_TERMINAL_STATUSES as Ol,ACTOR_NAME as Dt,APIFY_ENV_VARS as Nl,KEY_VALUE_STORE_KEYS as Ti,LOCAL_ACTOR_ENV_VARS as Es,LOCAL_STORAGE_SUBDIRS as $s,SOURCE_FILE_FORMATS as kt}from"@apify/consts";import{existsSync as nl,mkdirSync as al}from"fs";import{readFile as ll,stat as wi,unlink as cl,writeFile as ml}from"fs/promises";import{join as Ai,sep as ul}from"path";import{rimraf as dl}from"rimraf";var bi=c(async(r,e={},t=null)=>{let o=await ll(r,"utf-8"),s=JSON.parse(o),i;t?(i=s,i[t]={...s[t],...e}):i={...s,...e},await ml(r,JSON.stringify(i,null," "))},"updateLocalJson"),pr=c((r,e)=>{e||(e=r,r="."),e.split(ul).reduce((o,s)=>(o=Ai(o,s),nl(o)||al(o),o),r)},"ensureFolderExistsSync"),Pt=c(async r=>{await dl(r)},"rimrafPromised"),Lt=c(async r=>{(await wi(r)).isFile()&&await cl(r)},"deleteFile"),Si=c(async(r,e)=>(await Promise.all(r.map(async s=>wi(Ai(e,s))))).map(s=>s.size).reduce((s,i)=>s+i,0),"sumFilesSizeInBytes");var pt=bl,gr=c(async r=>new Promise((e,t)=>{yl(r,o=>{o.statusCode===301||o.statusCode===302?(e(gr(o.headers.location)),o.destroy()):e(o)}).on("error",t)}),"httpsGet"),ue=c(()=>{let r=Nl.LOCAL_STORAGE_DIR;return se.env[r]||se.env.CRAWLEE_STORAGE_DIR||et},"getLocalStorageDir"),me=c(r=>{let e=Is.DEFAULT_KEY_VALUE_STORE_ID,t=r||se.env[e]||Es[e];return Se(ue(),$s.keyValueStores,t)},"getLocalKeyValueStorePath"),_i=c(r=>{let e=Is.DEFAULT_DATASET_ID,t=r||se.env[e]||Es[e];return Se(ue(),$s.datasets,t)},"getLocalDatasetPath"),xi=c(r=>{let e=Is.DEFAULT_REQUEST_QUEUE_ID,t=r||se.env[e]||Es[e];return Se(ue(),$s.requestQueues,t)},"getLocalRequestQueuePath"),F=c(async()=>{let r={};try{let e=await hl(le(),"utf-8");r=JSON.parse(e)}catch{return{}}if(!r.username&&!r.id)throw new Error('Corrupted local user info was found. Please run "apify login" to fix it.');return r},"getLocalUserInfo");async function I(){let r=await Mt();if(!r)throw se.exitCode=1,new Error('You are not logged in with your Apify account. Call "apify login" to fix that.');return r}c(I,"getLoggedClientOrThrow");var Oi=c(r=>{if(!r&&ce(dt())&&ce(le())){let e=Ft(le(),"utf-8");return JSON.parse(e).token}return r},"getTokenWithAuthFileFallback"),Rs=c((r,e)=>(r=Oi(r),{token:r,baseUrl:e||se.env.APIFY_CLIENT_BASE_URL,requestInterceptors:[t=>{t.headers??=new vl;for(let[o,s]of Object.entries(hi))t.headers[o]=s;return t}]}),"getApifyClientOptions");async function Mt(r,e){r=Oi(r);let t=new $i(Rs(r,e)),o;try{o=await t.user("me").get()}catch{return null}return xs(le()),fr(le(),JSON.stringify({token:t.token,...o},null," ")),t}c(Mt,"getLoggedClient");var _s=c(r=>Se(r,V),"getLocalConfigPath"),de=c(r=>{if(ce(r))return JSON.parse(Ft(r,{encoding:"utf-8"}))},"getJsonFileContent"),Ue=c(r=>de(_s(r)),"getLocalConfig"),hr=c(async(r,e)=>{let t=Se(e||se.cwd(),V);await gl(Ii(t),{recursive:!0}),fr(t,JSON.stringify(r,null," "))},"setLocalConfig"),Pl=[ue(),"node_modules",".venv"],yr=c(async r=>{let e=me();pr(r,_i()),pr(r,xi()),pr(r,e);let t=Se(r,".gitignore"),o="";ce(t)&&(o=Ft(t,{encoding:"utf-8"}));let s=[];for(let i of Pl)RegExp(`^${Tl(i)}$`,"mg").test(o)||s.push(i);s.length>0&&(o.length>0?(s.unshift("# Added by Apify CLI"),fr(t,`
2
2
  ${s.join(`
3
3
  `)}
4
- `,{flag:"a"})):dr(t,`${s.join(`
4
+ `,{flag:"a"})):fr(t,`${s.join(`
5
5
  `)}
6
- `,{flag:"w"}))},"setLocalEnv"),Ri=new Sl(Tl,vl).define({"application/gzip":["tgz"],"text/typescript":["ts","tsx","mts"]},!0),xl=c((r,e)=>{let t=Ri.getType(r);return t?t.startsWith("text/")||t.includes("javascript")||t.includes("json")||t.includes("xml")||t.includes("application/node")||t.includes("application/toml")||t.includes("application/x-sh")||t.includes("application/x-httpd-php")?Pt.TEXT:Pt.BASE64:bl(e)==="binary"?Pt.BASE64:Pt.TEXT},"getSourceFileFormat"),_i=c(async(r,e)=>r.map(t=>{let o=kt(Se(e,t)),s=xl(t,o);return{name:t,format:s,content:s===Pt.TEXT?o.toString("utf8"):o.toString("base64")}}),"createSourceFiles"),xi=c(async r=>Ci(["*","**/**"],{ignore:[".git/**","apify_storage","node_modules","storage","crawlee_storage"],gitignore:!0,dot:!0,cwd:r}),"getActorLocalFilePaths"),Oi=c(async(r,e,t)=>{ce(r)&&await Nt(r);let o=cl(r),s=yl("zip");s.pipe(o),e.forEach(i=>s.glob(i,{cwd:t})),await s.finalize()},"createActZip"),Ft=c(r=>{let e=ue();if(!ce(Se(r,e)))return;let s=bi(Se(r,e)).find(a=>!!a.match(As));if(!s)return;let i=kt(Se(r,e,s)),n=Ri.getType(s);return{body:i,contentType:n,fileName:s}},"getLocalInput"),Ni=c(async()=>{let r=Ei();ce(me())&&ce(r)&&await Ot(r)},"purgeDefaultQueue"),Pi=c(async()=>{let r=Ii();ce(me())&&ce(r)&&await Ot(r)},"purgeDefaultDataset"),Li=c(async()=>{let r=ue();if(!ce(me())||!ce(r))return;let e=bi(r),t=[];e.forEach(o=>{o.match(As)||t.push(Nt(Se(r,o)))}),await Promise.all(t)},"purgeDefaultKeyValueStore"),$e=c(async({job:r,timeoutMillis:e,apifyClient:t})=>{let{id:o,status:s}=r,i=t||new Ti({baseUrl:le.env.APIFY_CLIENT_BASE_URL});if($l.includes(s)){if(le.env.APIFY_NO_LOGS_IN_TESTS)return;let n=await i.log(o).get();le.stderr.write(n);return}return new Promise(async n=>{let a=await i.log(o).stream();if(!a){n("no-logs");return}let l=null;a.on("data",m=>{le.env.APIFY_NO_LOGS_IN_TESTS||le.stderr.write(m.toString())}),a.once("end",()=>{n("finished"),l&&clearTimeout(l)}),e&&(l=setTimeout(()=>{a.destroy(),n("timeouts")},e))})},"outputJobLog");var ki=c(async()=>(await Ci([`${me()}/**`,`!${ue()}/${Ai.INPUT}.*`,`!${ue()}/${Ai.INPUT}_CLI-*`])).length===0,"checkIfStorageIsEmpty"),Mt=c(r=>{if(!Lt.REGEX.test(r))throw new Error("The Actor name must be a DNS hostname-friendly string (e.g. my-newest-actor).");if(r.length<Lt.MIN_LENGTH)throw new Error("The Actor name must be at least 3 characters long.");if(r.length>Lt.MAX_LENGTH)throw new Error("The Actor name must be a maximum of 30 characters long.")},"validateActorName"),Di=c(r=>{let e=r.replaceAll(/[^a-zA-Z0-9-]/g,"-");return e.length<Lt.MIN_LENGTH&&(e=`${e}-apify-actor`),e=e.replaceAll(/^-+/g,"").replaceAll(/-+$/g,""),e.slice(0,Lt.MAX_LENGTH)},"sanitizeActorName"),hr=c(r=>El(r,`^${tt}`),"isPythonVersionSupported"),yr=c(r=>{let e=Il(be);return Cl(r,e)},"isNodeVersionSupported"),wr=c(async({url:r,pathTo:e})=>{let t=await pr(r),o=[];t.on("data",i=>o.push(i)),await fl(t),new gl(Buffer.concat(o)).extractAllTo(e,!0)},"downloadAndUnzip");function Es(r){let e=Si(r);ul(e,{recursive:!0})}c(Es,"ensureApifyDirectory");var B=new bs("YYYY-MM-DD [at] HH:mm:ss"),Ut=new bs(`YYYY-MM-DD[
7
- ]HH:mm:ss`),Fi=new bs("YYYY-MM-DD"),jt=new vi,se=new vi({[rt.Day]:{DEFAULT:"d"},[rt.Hour]:{DEFAULT:"h"},[rt.Minute]:{DEFAULT:"m"},[rt.Month]:{DEFAULT:"M"},[rt.Second]:{DEFAULT:"s"},[rt.Week]:{DEFAULT:"w"},[rt.Year]:{DEFAULT:"y"}});function Ar(r,e){if("groupBy"in Object)return Object.groupBy(r,e);let t={},o=0;for(let s of r){let i=e(s,o++);t[i]||(t[i]=[]),t[i].push(s)}return t}c(Ar,"objectGroupBy");function Mi(r,e){let t=new Map,o=0;for(let s of r){let i=e(s,o++),n=t.get(i);n?n.push(s):t.set(i,[s])}return t}c(Mi,"mapGroupBy");function k(r){console.log(JSON.stringify(r,null,2))}c(k,"printJsonToStdout");var Ue=c(r=>r.startsWith(wi())?r.replace(wi(),"~"):r,"tildify");var Fl=["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", or by running "apify telemetry disable".',"You can find more information about our telemetry in https://docs.apify.com/cli/docs/telemetry."].join(`
8
- `);function Ui(){return`CLI:${Dl()}`}c(Ui,"createAnonymousId");async function Ml(r){if(r.version&&r.version>=1)return!1;let e=r,t=await M().catch(()=>({}));return br({version:1,enabled:!0},o=>{t.id&&e.distinctId===t.id?(o.anonymousId=Ui(),o.userId=t.id):o.anonymousId=e.distinctId}),!0}c(Ml,"migrateStateV0ToV1");async function pe(){let r=cr();if(!Ol(r)){let s=await M().catch(()=>({}));return br({version:1,enabled:!0,anonymousId:Ui(),userId:s.id}),v({message:Fl}),pe()}let t=JSON.parse(Pl(r,"utf-8"));return await Ml(t)?pe():t}c(pe,"useTelemetryState");function br(r,e){let t={...r};e?.(t);let o=cr(),s=kl(o);Nl(s,{recursive:!0}),Ll(cr(),JSON.stringify(t,null," "))}c(br,"updateTelemetryState");async function Sr(r){let e=await pe();br(e,t=>{t.userId=r})}c(Sr,"updateUserId");async function vr(r){let e=await pe();br(e,t=>{t.enabled=r})}c(vr,"updateTelemetryEnabled");async function ji(){if(process.env.APIFY_CLI_DISABLE_TELEMETRY&&!["false","0"].includes(process.env.APIFY_CLI_DISABLE_TELEMETRY))return C("telemetry","disabled by env variable"),!1;let r=await pe();return C("telemetry state",{telemetryState:r}),r.enabled}c(ji,"useTelemetryEnabled");async function Vi(){let r=await pe();return{anonymousId:r.anonymousId,userId:r.userId}}c(Vi,"useTelemetryIdentifiers");var Vt=K(),Ul="https://api.segment.io/v1/track",jl=Vt.isBeta?"rT67mFpIQD5qS9bJBoIYSFbZucrt2DZC":"2uPK6yhPqjC0eNUFhaY78S26cRKyaa6t";async function Bi(r,e){let t=await Vi(),o={anonymousId:t.anonymousId,context:{app:{name:"apify-cli",version:Vt.version,build:Vt.hash},library:{name:"apify-cli",version:Vt.version},os:{name:Vt.platform},userAgent:ot,channel:"server"},event:r,properties:{...e,app:"cli"},timestamp:new Date().toISOString(),userId:t.userId,writeKey:jl};if(C("trackEvent",o),!await ji()){C("trackEvent","telemetry disabled");return}try{let i=await fetch(Ul,{method:"POST",body:JSON.stringify(o)});if(!i.ok){C("trackEvent","failed to send event",await i.text());return}C("trackEvent","event sent")}catch(i){C("trackEvent","failed to send event",i)}}c(Bi,"trackEvent");import{access as Os,readFile as oc}from"fs/promises";import{basename as on,dirname as sc,join as H,resolve as sn}from"path";import ic from"process";import{ok as xs}from"@sapphire/result";import{existsSync as Ji,readdirSync as Kl}from"fs";import{join as Er,resolve as ql}from"path";import Wl from"configparser";import Hl from"@inquirer/input";import Yl from"is-ci";import{constants as Gi,fstat as Vl}from"fs";import Yi from"process";import{promisify as Bl}from"util";var Gl=Bl(Vl),$s;async function Tr(){if($s)return $s;let r=Yi.stdin,e={isTTY:r.isTTY,hasData:!1,waitDelay:0,stream:r},t=await Gl(0).then(o=>{if(C("useStdin",{stat:o,isRegularFile:o.isFile(),isDirectory:o.isDirectory(),isBlockDevice:o.isBlockDevice(),isCharDevice:o.isCharacterDevice(),isSymbolicLink:o.isSymbolicLink(),isFIFO:o.isFIFO(),isSocket:o.isSocket()}),Yi.platform==="win32"){if((o.mode&Gi.S_IFIFO)===Gi.S_IFIFO)return 100;if(o.isFile())return 50}return o.isFIFO()||o.isFile()||(o.isSocket()?50:!1)}).catch(()=>!1);return C("useStdin",{hasData:e.hasData,waitDelay:e.waitDelay,isTTY:e.isTTY,pipedIn:t,readableEnded:r.readableEnded}),(!r.isTTY||t!==!1&&(r.isTTY!==void 0||!r.readableEnded))&&(e.hasData=!0),typeof t=="number"&&(e.waitDelay=t),$s=e,e}c(Tr,"useStdin");var Rs="confirm",Hi=`no-${Rs}`;function Re(r,{errorMessageForStdin:e=`Please use the --${Rs}/--${Hi} flags to confirm the action.`}={}){return async(t,...o)=>{let{isTTY:s,hasData:i}=await Tr(),n=t;if(Yl||!s&&!i){if(typeof n.providedConfirmFromStdin>"u")throw new Error(n.errorMessageForStdin??e??`Please use the --${Rs}/--${Hi} flags to confirm the action.`);return n.providedConfirmFromStdin}return await r(t,...o)}}c(Re,"stdinCheckWrapper");var st=Re(async({message:r,validate:e,default:t})=>await Hl({message:r,validate:e,default:t}),{errorMessageForStdin:"Please provide a valid input based on the command options."});import{readFileSync as Jl}from"fs";var Cr=class{static{c(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 Ir=class{static{c(this,"SpiderFileAnalyzer")}pathname;constructor(e){this.pathname=e}getSpiders(){let e=Jl(this.pathname,"utf8"),t=/class\s+(\w+)/g,o=[],s=t.exec(e);for(;s;)o.push(new Cr({class_name:s[1],pathname:this.pathname})),s=t.exec(e);return o}};var it=class{static{c(this,"ScrapyProjectAnalyzer")}pathname;configuration=null;settings=null;constructor(e){this.pathname=e,this.settings=null,this.loadScrapyCfg()}static isApplicable(e){return Ji(Er(e,"scrapy.cfg"))}async init(){await this.loadSettings()}loadScrapyCfg(){let e=new Wl,t=ql(Er(this.pathname,"scrapy.cfg"));if(!Ji(t))throw new Error(`scrapy.cfg not found in "${t}".
9
- Are you sure there is a Scrapy project there?`);e.read(t),this.configuration=e}async loadSettings(){let e=this.configuration.get("settings","default").split(".")[0],t=await st({message:"Enter the Scrapy BOT_NAME (see settings.py):",default:e}),o=await st({message:"What folder are the Scrapy spider modules stored in? (see SPIDER_MODULES in settings.py):",default:`${e}.spiders`});this.settings={BOT_NAME:t,SPIDER_MODULES:typeof o=="string"?[o]:o}}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 t=[];for(let o of e){let s=Er(this.pathname,o.replaceAll(".","/")),i=Kl(s,{withFileTypes:!0});for(let n of i)n.isFile()&&n.name.endsWith(".py")&&n.name!=="__init__.py"&&t.push(...new Ir(Er(s,n.name)).getSpiders())}return t}};import _s from"process";import{none as qi,some as Wi}from"@sapphire/result";import{execa as Xi}from"execa";import zi from"which";import{stat as $r}from"fs/promises";import{isAbsolute as zl,join as Rr}from"path";function je(r){return r?r.startsWith('"')?r:zl(r)&&r.includes(" ")?`"${r}"`:r:null}c(je,"normalizeExecutablePath");async function Ki(r){let e=null;return await(await _e({cwd:r})).inspectAsync(async o=>{if(o.type===0){let[s,i,n,a]=await Promise.all([$r(Rr(r,"yarn.lock")).then(()=>!0).catch(()=>!1),$r(Rr(r,"pnpm-lock.yaml")).then(()=>!0).catch(()=>!1),$r(Rr(r,"bun.lockb")).then(()=>!0).catch(()=>!1),$r(Rr(r,"bun.lock")).then(()=>!0).catch(()=>!1)]);s?e="yarn install":i?e="pnpm install":n||a||o.runtime?.pmName==="bun"?e="bun install":o.runtime?.pmName==="deno"?e="deno install --node-modules-dir":e="npm install"}else(o.type===1||o.type===2)&&(e="python -m pip install -r requirements.txt")}),e}c(Ki,"getInstallCommandSuggestion");var _r=new Map,Xl={node:["--version"],deno:["eval",'"console.log(process.versions.node)"'],bun:["--eval",'"console.log(process.versions.node)"']};async function Zl(r,e){try{let t=await Xi(r,e,{shell:!0,windowsHide:!0,verbose:_s.env.APIFY_CLI_DEBUG?"full":void 0});return t.stdout?t.stdout.trim().replace(/^v/,""):null}catch{return null}}c(Zl,"getRuntimeVersion");async function Ql(r){let e=await Xi(r,["--version"],{shell:!0,windowsHide:!0,verbose:_s.env.APIFY_CLI_DEBUG?"full":void 0});return e.stdout?e.stdout.trim().replace(/^v/,""):null}c(Ql,"getNpmVersion");async function Zi(r=_s.cwd()){let e=_r.get(r);if(e)return C("useJavaScriptRuntime",{cacheHit:!0,cwd:r,runtime:e.unwrapOr(null)}),e;for(let[t,o]of Object.entries(Xl))try{let s=je(await zi(t)),i=await Zl(s,o);if(i){let n={executablePath:s,version:i};if(t==="node"){let a=je(await zi("npm").catch(()=>null));a&&(n.pmPath=a,n.pmVersion=await Ql(a),n.pmName="npm")}else n.runtimeShorthand=t,n.pmPath=s,n.pmVersion=i,n.pmName=t;return _r.set(r,Wi(n)),C("useJavaScriptRuntime",{cacheHit:!1,cwd:r,runtime:_r.get(r)?.unwrap()}),Wi(n)}}catch{}return _r.set(r,qi),C("useJavaScriptRuntime",{cacheHit:!1,cwd:r,runtime:null}),qi}c(Zi,"useJavaScriptRuntime");import{platform as ec}from"os";import{join as Qi}from"path";import xr from"process";import{none as en,some as tn}from"@sapphire/result";import{execa as tc}from"execa";import rc from"which";var Ve=new Map;async function rn(r){try{let e=await tc(r,["-c",'"import platform; print(platform.python_version())"'],{shell:!0,windowsHide:!0,verbose:xr.env.APIFY_CLI_DEBUG?"full":void 0});return e.stdout?e.stdout.trim():null}catch{return null}}c(rn,"getPythonVersion");async function Gt({cwd:r=xr.cwd(),force:e=!1}={}){let t=Ve.get(r);if(t&&!e)return C("usePythonRuntime",{cacheHit:!0,cwd:r,runtime:t.unwrapOr(null)}),t;let o=ec()==="win32",s=o?["Scripts","python.exe"]:["bin","python3"],i;xr.env.VIRTUAL_ENV?i=Qi(xr.env.VIRTUAL_ENV,...s):i=Qi(r,".venv",...s),i=je(i);try{let a=await rn(i);if(a)return Ve.set(r,tn({executablePath:i,version:a})),C("usePythonRuntime",{cacheHit:!1,cwd:r,runtime:Ve.get(r)?.unwrap()}),Ve.get(r)}catch{}let n=["python3","python",...o?["python3.exe","python.exe"]:[]];for(let a of n)try{let l=je(await rc(a)),m=await rn(l);if(m)return Ve.set(r,tn({executablePath:l,version:m})),C("usePythonRuntime",{cacheHit:!1,cwd:r,runtime:Ve.get(r)?.unwrap()}),Ve.get(r)}catch{}return Ve.set(r,en),C("usePythonRuntime",{cacheHit:!1,cwd:r,runtime:null}),en}c(Gt,"usePythonRuntime");var nn=new Map;async function _e({cwd:r=ic.cwd()}={}){let e=nn.get(r);if(e)return C("useCwdProject",{cacheHit:!0,project:e}),xs(e);let t={type:3},s=await c(async()=>{if(await ac(r)){t.type=2;let l=await Gt({cwd:r});t.runtime=l.unwrapOr(void 0);let m=new it(r);if(m.loadScrapyCfg(),m.configuration.hasKey("apify","mainpy_location"))t.entrypoint={path:m.configuration.get("apify","mainpy_location")};else{let u=await an(r);u&&(t.entrypoint={path:u})}return}let n=await an(r);if(n){t.type=1;let l=await Gt({cwd:r});t.entrypoint={path:n},t.runtime=l.unwrapOr(void 0);return}let a=await nc(r);if(a){t.type=0;let l=await Zi();t.runtime=l.unwrapOr(void 0),a.type==="file"?t.entrypoint={path:a.path}:a.type==="script"&&(t.entrypoint={script:a.script});return}return xs(t)},"check")();return s?.isErr()?(C("useCwdProject",{cacheHit:!1,error:s}),s):(C("useCwdProject",{cacheHit:!1,project:t}),nn.set(r,t),xs(t))}c(_e,"useCwdProject");async function nc(r){let e=H(r,"package.json");try{let o=await oc(e,"utf-8"),s=JSON.parse(o);if(s.scripts?.start)return{type:"script",script:"start"};if(s.main)try{return await Os(sn(r,s.main)),{path:sn(r,s.main),type:"file"}}catch{}return{type:"unknown-entrypoint"}}catch{}let t=[H(r,"index.js"),H(r,"index.mjs"),H(r,"index.cjs"),H(r,"main.js"),H(r,"main.mjs"),H(r,"main.cjs"),H(r,"src","index.js"),H(r,"src","index.mjs"),H(r,"src","index.cjs"),H(r,"src","main.js"),H(r,"src","main.mjs"),H(r,"src","main.cjs"),H(r,"dist","index.js"),H(r,"dist","index.mjs"),H(r,"dist","index.cjs"),H(r,"dist","main.js"),H(r,"dist","main.mjs"),H(r,"dist","main.cjs")];for(let o of t)try{return await Os(o),{path:o,type:"file"}}catch{}return null}c(nc,"checkNodeProject");async function an(r){let e=on(r),t=[H(r,"src","__main__.py"),H(r,"__main__.py"),H(r,e,"__main__.py"),H(r,e.replaceAll("-","_").replaceAll(" ","_"),"__main__.py")];for(let o of t)try{return await Os(o),on(sc(o))}catch{}return null}c(an,"checkPythonProject");async function ac(r){return it.isApplicable(r)}c(ac,"checkScrapyProject");import Y from"chalk";import Ht from"chalk";import mn from"indent-string";import dn from"widest-line";import pn from"wrap-ansi";import Or from"chalk";import Ns from"indent-string";import mc from"string-width";import cn from"strip-ansi";import un from"widest-line";import Ps from"wrap-ansi";import lc from"chalk";import cc from"indent-string";import ln from"string-width";import uc from"wrap-ansi";var Be;function oe(){if(Be)return Be;let r=Number(process.env.APIFY_CLI_MAX_LINE_WIDTH);if(!Number.isNaN(r))Be=r;else if(!process.stdout.isTTY)Be=80;else{let e=process.stdout.getWindowSize?.()[0]??-1;e<1?Be=80:e<40?Be=40:Be=e}return Be}c(oe,"getMaxLineWidth");var ft=class{static{c(this,"BaseCommandRenderer")}command;entrypoint;constructor(e,t){this.entrypoint=e,this.command=t}pushShortDescription(e){this.command.shortDescription?e.push(this.command.shortDescription,""):this.command.description&&e.push(this.command.description.split(`
10
- `)[0],"")}pushDescription(e){if(!this.command.description)return;e.push(lc.bold("DESCRIPTION"));let t=uc(this.command.description,oe()-2,{trim:!1}),o=cc(t,2);e.push(o),e.push("")}pushNewLineBeforeNewEntryIfLengthIsPastTheLimit({state:e,itemToAdd:t,indentSize:o}){let s=ln(e.join(" ").split(`
11
- `).at(-1)||"")+o,i=ln(t);s+i>oe()&&e.push(`
12
- `),e.push(t)}kebabFlagName(e){return ve(Te(e)).toLowerCase()}makeFlagString(e,t){let o=this.kebabFlagName(e),s=t.char?`-${t.char}`:`--${o}`;switch(t.flagTag){case"boolean":return s;case"string":case"integer":{let i=t.choices?.length?`${t.choices.join("|")}`:"<value>";return`${s} ${i}`}default:throw new RangeError(`Unhandled flag type: ${t.flagTag}`)}}};var Nr=class extends ft{static{c(this,"CommandHelp")}render(){let e=[];return this.pushShortDescription(e),this.pushUsageString(e),this.command.description&&this.pushDescription(e),e.join(`
6
+ `,{flag:"w"}))},"setLocalEnv"),Ni=new Il($l,El).define({"application/gzip":["tgz"],"text/typescript":["ts","tsx","mts"]},!0),Ll=c((r,e)=>{let t=Ni.getType(r);return t?t.startsWith("text/")||t.includes("javascript")||t.includes("json")||t.includes("xml")||t.includes("application/node")||t.includes("application/toml")||t.includes("application/x-sh")||t.includes("application/x-httpd-php")?kt.TEXT:kt.BASE64:Cl(e)==="binary"?kt.BASE64:kt.TEXT},"getSourceFileFormat"),Pi=c(async(r,e)=>r.map(t=>{let o=Ft(Se(e,t)),s=Ll(t,o);return{name:t,format:s,content:s===kt.TEXT?o.toString("utf8"):o.toString("base64")}}),"createSourceFiles"),Li=c(async r=>Ri(["*","**/**"],{ignore:[".git/**","apify_storage","node_modules","storage","crawlee_storage"],gitignore:!0,dot:!0,cwd:r}),"getActorLocalFilePaths"),ki=c(async(r,e,t)=>{ce(r)&&await Lt(r);let o=pl(r),s=Sl("zip");s.pipe(o),e.forEach(i=>s.glob(i,{cwd:t})),await s.finalize()},"createActZip"),Ut=c(r=>{let e=me();if(!ce(Se(r,e)))return;let s=Ci(Se(r,e)).find(a=>!!a.match(Ts));if(!s)return;let i=Ft(Se(r,e,s)),n=Ni.getType(s);return{body:i,contentType:n,fileName:s}},"getLocalInput"),Di=c(async()=>{let r=xi();ce(ue())&&ce(r)&&await Pt(r)},"purgeDefaultQueue"),Fi=c(async()=>{let r=_i();ce(ue())&&ce(r)&&await Pt(r)},"purgeDefaultDataset"),Mi=c(async()=>{let r=me();if(!ce(ue())||!ce(r))return;let e=Ci(r),t=[];e.forEach(o=>{o.match(Ts)||t.push(Lt(Se(r,o)))}),await Promise.all(t)},"purgeDefaultKeyValueStore"),$e=c(async({job:r,timeoutMillis:e,apifyClient:t})=>{let{id:o,status:s}=r,i=t||new $i({baseUrl:se.env.APIFY_CLIENT_BASE_URL});if(Ol.includes(s)){if(se.env.APIFY_NO_LOGS_IN_TESTS)return;let n=await i.log(o).get();se.stderr.write(n);return}return new Promise(async n=>{let a=await i.log(o).stream();if(!a){n("no-logs");return}let l=null;a.on("data",u=>{se.env.APIFY_NO_LOGS_IN_TESTS||se.stderr.write(u.toString())}),a.once("end",()=>{n("finished"),l&&clearTimeout(l)}),e&&(l=setTimeout(()=>{a.destroy(),n("timeouts")},e))})},"outputJobLog");var Ui=c(async()=>(await Ri([`${ue()}/**`,`!${me()}/${Ti.INPUT}.*`,`!${me()}/${Ti.INPUT}_CLI-*`])).length===0,"checkIfStorageIsEmpty"),jt=c(r=>{if(!Dt.REGEX.test(r))throw new Error("The Actor name must be a DNS hostname-friendly string (e.g. my-newest-actor).");if(r.length<Dt.MIN_LENGTH)throw new Error("The Actor name must be at least 3 characters long.");if(r.length>Dt.MAX_LENGTH)throw new Error("The Actor name must be a maximum of 30 characters long.")},"validateActorName"),ji=c(r=>{let e=r.replaceAll(/[^a-zA-Z0-9-]/g,"-");return e.length<Dt.MIN_LENGTH&&(e=`${e}-apify-actor`),e=e.replaceAll(/^-+/g,"").replaceAll(/-+$/g,""),e.slice(0,Dt.MAX_LENGTH)},"sanitizeActorName"),wr=c(r=>xl(r,`^${tt}`),"isPythonVersionSupported"),Ar=c(r=>{let e=_l(be);return Rl(r,e)},"isNodeVersionSupported"),br=c(async({url:r,pathTo:e})=>{let t=await gr(r),o=[];t.on("data",i=>o.push(i)),await wl(t),new Al(Buffer.concat(o)).extractAllTo(e,!0)},"downloadAndUnzip");function xs(r){let e=Ii(r);fl(e,{recursive:!0})}c(xs,"ensureApifyDirectory");var B=new Cs("YYYY-MM-DD [at] HH:mm:ss"),Vt=new Cs(`YYYY-MM-DD[
7
+ ]HH:mm:ss`),Vi=new Cs("YYYY-MM-DD"),Bt=new Ei,ie=new Ei({[rt.Day]:{DEFAULT:"d"},[rt.Hour]:{DEFAULT:"h"},[rt.Minute]:{DEFAULT:"m"},[rt.Month]:{DEFAULT:"M"},[rt.Second]:{DEFAULT:"s"},[rt.Week]:{DEFAULT:"w"},[rt.Year]:{DEFAULT:"y"}});function Sr(r,e){if("groupBy"in Object)return Object.groupBy(r,e);let t={},o=0;for(let s of r){let i=e(s,o++);t[i]||(t[i]=[]),t[i].push(s)}return t}c(Sr,"objectGroupBy");function Bi(r,e){let t=new Map,o=0;for(let s of r){let i=e(s,o++),n=t.get(i);n?n.push(s):t.set(i,[s])}return t}c(Bi,"mapGroupBy");function k(r){console.log(JSON.stringify(r,null,2))}c(k,"printJsonToStdout");var je=c(r=>r.startsWith(vi())?r.replace(vi(),"~"):r,"tildify");var Vl=["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", or by running "apify telemetry disable".',"You can find more information about our telemetry in https://docs.apify.com/cli/docs/telemetry."].join(`
8
+ `);function Gi(){return`CLI:${jl()}`}c(Gi,"createAnonymousId");async function Bl(r){if(r.version&&r.version>=1)return!1;let e=r,t=await F().catch(()=>({}));return vr({version:1,enabled:!0},o=>{t.id&&e.distinctId===t.id?(o.anonymousId=Gi(),o.userId=t.id):o.anonymousId=e.distinctId}),!0}c(Bl,"migrateStateV0ToV1");async function pe(){let r=ur();if(!kl(r)){let s=await F().catch(()=>({}));return vr({version:1,enabled:!0,anonymousId:Gi(),userId:s.id}),v({message:Vl}),pe()}let t=JSON.parse(Fl(r,"utf-8"));return await Bl(t)?pe():t}c(pe,"useTelemetryState");function vr(r,e){let t={...r};e?.(t);let o=ur(),s=Ul(o);Dl(s,{recursive:!0}),Ml(ur(),JSON.stringify(t,null," "))}c(vr,"updateTelemetryState");async function Tr(r){let e=await pe();vr(e,t=>{t.userId=r})}c(Tr,"updateUserId");async function Cr(r){let e=await pe();vr(e,t=>{t.enabled=r})}c(Cr,"updateTelemetryEnabled");async function Yi(){if(process.env.APIFY_CLI_DISABLE_TELEMETRY&&!["false","0"].includes(process.env.APIFY_CLI_DISABLE_TELEMETRY))return C("telemetry","disabled by env variable"),!1;let r=await pe();return C("telemetry state",{telemetryState:r}),r.enabled}c(Yi,"useTelemetryEnabled");async function Hi(){let r=await pe();return{anonymousId:r.anonymousId,userId:r.userId}}c(Hi,"useTelemetryIdentifiers");var Gt=K(),Gl="https://api.segment.io/v1/track",Yl=Gt.isBeta?"rT67mFpIQD5qS9bJBoIYSFbZucrt2DZC":"2uPK6yhPqjC0eNUFhaY78S26cRKyaa6t";async function Ji(r,e){let t=await Hi(),o={anonymousId:t.anonymousId,context:{app:{name:"apify-cli",version:Gt.version,build:Gt.hash},library:{name:"apify-cli",version:Gt.version},os:{name:Gt.platform},userAgent:ot,channel:"server"},event:r,properties:{...e,app:"cli"},timestamp:new Date().toISOString(),userId:t.userId,writeKey:Yl};if(C("trackEvent",o),!await Yi()){C("trackEvent","telemetry disabled");return}try{let i=await fetch(Gl,{method:"POST",body:JSON.stringify(o)});if(!i.ok){C("trackEvent","failed to send event",await i.text());return}C("trackEvent","event sent")}catch(i){C("trackEvent","failed to send event",i)}}c(Ji,"trackEvent");import{access as ks,readFile as ac}from"fs/promises";import{basename as ln,dirname as lc,join as H,resolve as cn}from"path";import cc from"process";import{ok as Ls}from"@sapphire/result";import{existsSync as zi,readdirSync as Xl}from"fs";import{join as Rr,resolve as Zl}from"path";import Ql from"configparser";import Wl from"@inquirer/input";import ql from"is-ci";import{constants as Ki,fstat as Hl}from"fs";import qi from"process";import{promisify as Jl}from"util";var Kl=Jl(Hl),Os;async function Ir(){if(Os)return Os;let r=qi.stdin,e={isTTY:r.isTTY,hasData:!1,waitDelay:0,stream:r},t=await Kl(0).then(o=>{if(C("useStdin",{stat:o,isRegularFile:o.isFile(),isDirectory:o.isDirectory(),isBlockDevice:o.isBlockDevice(),isCharDevice:o.isCharacterDevice(),isSymbolicLink:o.isSymbolicLink(),isFIFO:o.isFIFO(),isSocket:o.isSocket()}),qi.platform==="win32"){if((o.mode&Ki.S_IFIFO)===Ki.S_IFIFO)return 100;if(o.isFile())return 50}return o.isFIFO()||o.isFile()||(o.isSocket()?50:!1)}).catch(()=>!1);return C("useStdin",{hasData:e.hasData,waitDelay:e.waitDelay,isTTY:e.isTTY,pipedIn:t,readableEnded:r.readableEnded}),(!r.isTTY||t!==!1&&(r.isTTY!==void 0||!r.readableEnded))&&(e.hasData=!0),typeof t=="number"&&(e.waitDelay=t),Os=e,e}c(Ir,"useStdin");var Ns="confirm",Wi=`no-${Ns}`;function Re(r,{errorMessageForStdin:e=`Please use the --${Ns}/--${Wi} flags to confirm the action.`}={}){return async(t,...o)=>{let{isTTY:s,hasData:i}=await Ir(),n=t;if(ql||!s&&!i){if(typeof n.providedConfirmFromStdin>"u")throw new Error(n.errorMessageForStdin??e??`Please use the --${Ns}/--${Wi} flags to confirm the action.`);return n.providedConfirmFromStdin}return await r(t,...o)}}c(Re,"stdinCheckWrapper");var st=Re(async({message:r,validate:e,default:t})=>await Wl({message:r,validate:e,default:t}),{errorMessageForStdin:"Please provide a valid input based on the command options."});import{readFileSync as zl}from"fs";var Er=class{static{c(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 $r=class{static{c(this,"SpiderFileAnalyzer")}pathname;constructor(e){this.pathname=e}getSpiders(){let e=zl(this.pathname,"utf8"),t=/class\s+(\w+)/g,o=[],s=t.exec(e);for(;s;)o.push(new Er({class_name:s[1],pathname:this.pathname})),s=t.exec(e);return o}};var it=class{static{c(this,"ScrapyProjectAnalyzer")}pathname;configuration=null;settings=null;constructor(e){this.pathname=e,this.settings=null,this.loadScrapyCfg()}static isApplicable(e){return zi(Rr(e,"scrapy.cfg"))}async init(){await this.loadSettings()}loadScrapyCfg(){let e=new Ql,t=Zl(Rr(this.pathname,"scrapy.cfg"));if(!zi(t))throw new Error(`scrapy.cfg not found in "${t}".
9
+ Are you sure there is a Scrapy project there?`);e.read(t),this.configuration=e}async loadSettings(){let e=this.configuration.get("settings","default").split(".")[0],t=await st({message:"Enter the Scrapy BOT_NAME (see settings.py):",default:e}),o=await st({message:"What folder are the Scrapy spider modules stored in? (see SPIDER_MODULES in settings.py):",default:`${e}.spiders`});this.settings={BOT_NAME:t,SPIDER_MODULES:typeof o=="string"?[o]:o}}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 t=[];for(let o of e){let s=Rr(this.pathname,o.replaceAll(".","/")),i=Xl(s,{withFileTypes:!0});for(let n of i)n.isFile()&&n.name.endsWith(".py")&&n.name!=="__init__.py"&&t.push(...new $r(Rr(s,n.name)).getSpiders())}return t}};import Ps from"process";import{none as Zi,some as Qi}from"@sapphire/result";import{execa as tn}from"execa";import en from"which";import{stat as _r}from"fs/promises";import{isAbsolute as ec,join as xr}from"path";function Ve(r){return r?r.startsWith('"')?r:ec(r)&&r.includes(" ")?`"${r}"`:r:null}c(Ve,"normalizeExecutablePath");async function Xi(r){let e=null;return await(await _e({cwd:r})).inspectAsync(async o=>{if(o.type===0){let[s,i,n,a]=await Promise.all([_r(xr(r,"yarn.lock")).then(()=>!0).catch(()=>!1),_r(xr(r,"pnpm-lock.yaml")).then(()=>!0).catch(()=>!1),_r(xr(r,"bun.lockb")).then(()=>!0).catch(()=>!1),_r(xr(r,"bun.lock")).then(()=>!0).catch(()=>!1)]);s?e="yarn install":i?e="pnpm install":n||a||o.runtime?.pmName==="bun"?e="bun install":o.runtime?.pmName==="deno"?e="deno install --node-modules-dir":e="npm install"}else(o.type===1||o.type===2)&&(e="python -m pip install -r requirements.txt")}),e}c(Xi,"getInstallCommandSuggestion");var Or=new Map,tc={node:["--version"],deno:["eval",'"console.log(process.versions.node)"'],bun:["--eval",'"console.log(process.versions.node)"']};async function rc(r,e){try{let t=await tn(r,e,{shell:!0,windowsHide:!0,verbose:Ps.env.APIFY_CLI_DEBUG?"full":void 0});return t.stdout?t.stdout.trim().replace(/^v/,""):null}catch{return null}}c(rc,"getRuntimeVersion");async function oc(r){let e=await tn(r,["--version"],{shell:!0,windowsHide:!0,verbose:Ps.env.APIFY_CLI_DEBUG?"full":void 0});return e.stdout?e.stdout.trim().replace(/^v/,""):null}c(oc,"getNpmVersion");async function rn(r=Ps.cwd()){let e=Or.get(r);if(e)return C("useJavaScriptRuntime",{cacheHit:!0,cwd:r,runtime:e.unwrapOr(null)}),e;for(let[t,o]of Object.entries(tc))try{let s=Ve(await en(t)),i=await rc(s,o);if(i){let n={executablePath:s,version:i};if(t==="node"){let a=Ve(await en("npm").catch(()=>null));a&&(n.pmPath=a,n.pmVersion=await oc(a),n.pmName="npm")}else n.runtimeShorthand=t,n.pmPath=s,n.pmVersion=i,n.pmName=t;return Or.set(r,Qi(n)),C("useJavaScriptRuntime",{cacheHit:!1,cwd:r,runtime:Or.get(r)?.unwrap()}),Qi(n)}}catch{}return Or.set(r,Zi),C("useJavaScriptRuntime",{cacheHit:!1,cwd:r,runtime:null}),Zi}c(rn,"useJavaScriptRuntime");import{platform as sc}from"os";import{join as on}from"path";import Nr from"process";import{none as sn,some as nn}from"@sapphire/result";import{execa as ic}from"execa";import nc from"which";var Be=new Map;async function an(r){try{let e=await ic(r,["-c",'"import platform; print(platform.python_version())"'],{shell:!0,windowsHide:!0,verbose:Nr.env.APIFY_CLI_DEBUG?"full":void 0});return e.stdout?e.stdout.trim():null}catch{return null}}c(an,"getPythonVersion");async function Ht({cwd:r=Nr.cwd(),force:e=!1}={}){let t=Be.get(r);if(t&&!e)return C("usePythonRuntime",{cacheHit:!0,cwd:r,runtime:t.unwrapOr(null)}),t;let o=sc()==="win32",s=o?["Scripts","python.exe"]:["bin","python3"],i;Nr.env.VIRTUAL_ENV?i=on(Nr.env.VIRTUAL_ENV,...s):i=on(r,".venv",...s),i=Ve(i);try{let a=await an(i);if(a)return Be.set(r,nn({executablePath:i,version:a})),C("usePythonRuntime",{cacheHit:!1,cwd:r,runtime:Be.get(r)?.unwrap()}),Be.get(r)}catch{}let n=["python3","python",...o?["python3.exe","python.exe"]:[]];for(let a of n)try{let l=Ve(await nc(a)),u=await an(l);if(u)return Be.set(r,nn({executablePath:l,version:u})),C("usePythonRuntime",{cacheHit:!1,cwd:r,runtime:Be.get(r)?.unwrap()}),Be.get(r)}catch{}return Be.set(r,sn),C("usePythonRuntime",{cacheHit:!1,cwd:r,runtime:null}),sn}c(Ht,"usePythonRuntime");var mn=new Map;async function _e({cwd:r=cc.cwd()}={}){let e=mn.get(r);if(e)return C("useCwdProject",{cacheHit:!0,project:e}),Ls(e);let t={type:3},s=await c(async()=>{if(await uc(r)){t.type=2;let l=await Ht({cwd:r});t.runtime=l.unwrapOr(void 0);let u=new it(r);if(u.loadScrapyCfg(),u.configuration.hasKey("apify","mainpy_location"))t.entrypoint={path:u.configuration.get("apify","mainpy_location")};else{let m=await un(r);m&&(t.entrypoint={path:m})}return}let n=await un(r);if(n){t.type=1;let l=await Ht({cwd:r});t.entrypoint={path:n},t.runtime=l.unwrapOr(void 0);return}let a=await mc(r);if(a){t.type=0;let l=await rn();t.runtime=l.unwrapOr(void 0),a.type==="file"?t.entrypoint={path:a.path}:a.type==="script"&&(t.entrypoint={script:a.script});return}return Ls(t)},"check")();return s?.isErr()?(C("useCwdProject",{cacheHit:!1,error:s}),s):(C("useCwdProject",{cacheHit:!1,project:t}),mn.set(r,t),Ls(t))}c(_e,"useCwdProject");async function mc(r){let e=H(r,"package.json");try{let o=await ac(e,"utf-8"),s=JSON.parse(o);if(s.scripts?.start)return{type:"script",script:"start"};if(s.main)try{return await ks(cn(r,s.main)),{path:cn(r,s.main),type:"file"}}catch{}return{type:"unknown-entrypoint"}}catch{}let t=[H(r,"index.js"),H(r,"index.mjs"),H(r,"index.cjs"),H(r,"main.js"),H(r,"main.mjs"),H(r,"main.cjs"),H(r,"src","index.js"),H(r,"src","index.mjs"),H(r,"src","index.cjs"),H(r,"src","main.js"),H(r,"src","main.mjs"),H(r,"src","main.cjs"),H(r,"dist","index.js"),H(r,"dist","index.mjs"),H(r,"dist","index.cjs"),H(r,"dist","main.js"),H(r,"dist","main.mjs"),H(r,"dist","main.cjs")];for(let o of t)try{return await ks(o),{path:o,type:"file"}}catch{}return null}c(mc,"checkNodeProject");async function un(r){let e=ln(r),t=[H(r,"src","__main__.py"),H(r,"__main__.py"),H(r,e,"__main__.py"),H(r,e.replaceAll("-","_").replaceAll(" ","_"),"__main__.py")];for(let o of t)try{return await ks(o),ln(lc(o))}catch{}return null}c(un,"checkPythonProject");async function uc(r){return it.isApplicable(r)}c(uc,"checkScrapyProject");import Y from"chalk";import Kt from"chalk";import gn from"indent-string";import hn from"widest-line";import yn from"wrap-ansi";import Pr from"chalk";import Ds from"indent-string";import gc from"string-width";import pn from"strip-ansi";import fn from"widest-line";import Fs from"wrap-ansi";import dc from"chalk";import pc from"indent-string";import dn from"string-width";import fc from"wrap-ansi";var Ge;function oe(){if(Ge)return Ge;let r=Number(process.env.APIFY_CLI_MAX_LINE_WIDTH);if(!Number.isNaN(r))Ge=r;else if(!process.stdout.isTTY)Ge=80;else{let e=process.stdout.getWindowSize?.()[0]??-1;e<1?Ge=80:e<40?Ge=40:Ge=e}return Ge}c(oe,"getMaxLineWidth");var ft=class{static{c(this,"BaseCommandRenderer")}command;entrypoint;constructor(e,t){this.entrypoint=e,this.command=t}pushShortDescription(e){this.command.shortDescription?e.push(this.command.shortDescription,""):this.command.description&&e.push(this.command.description.split(`
10
+ `)[0],"")}pushDescription(e){if(!this.command.description)return;e.push(dc.bold("DESCRIPTION"));let t=fc(this.command.description,oe()-2,{trim:!1}),o=pc(t,2);e.push(o),e.push("")}pushNewLineBeforeNewEntryIfLengthIsPastTheLimit({state:e,itemToAdd:t,indentSize:o}){let s=dn(e.join(" ").split(`
11
+ `).at(-1)||"")+o,i=dn(t);s+i>oe()&&e.push(`
12
+ `),e.push(t)}kebabFlagName(e){return ve(Te(e)).toLowerCase()}makeFlagString(e,t){let o=this.kebabFlagName(e),s=t.char?`-${t.char}`:`--${o}`;switch(t.flagTag){case"boolean":return s;case"string":case"integer":{let i=t.choices?.length?`${t.choices.join("|")}`:"<value>";return`${s} ${i}`}default:throw new RangeError(`Unhandled flag type: ${t.flagTag}`)}}};var Lr=class extends ft{static{c(this,"CommandHelp")}render(){let e=[];return this.pushShortDescription(e),this.pushUsageString(e),this.command.description&&this.pushDescription(e),e.join(`
13
13
  `).trim()}selectiveRender(e){let t=[];return e.showShortDescription&&this.pushShortDescription(t),e.showUsageString&&this.pushUsageString(t),e.showDescription&&this.command.description&&this.pushDescription(t),t.join(`
14
- `).trim()}pushUsageString(e){e.push(Or.bold("USAGE"));let t=`$ ${this.entrypoint} ${this.command.name}`,o=2+mc(t),s=[t],i=Object.entries(this.command.args??{});if(i.length)for(let[f,d]of i){if(typeof d=="string")throw new RangeError("This is a type-check only value, do not actually use it");this.pushNewLineBeforeNewEntryIfLengthIsPastTheLimit({state:s,itemToAdd:d.required?`<${f}>`:`[${f}]`,indentSize:o})}let n=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&&n.push(["json",{choices: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 a=new Map(n.sort((f,d)=>{if(typeof f[1]=="string")throw new RangeError("This is a type-check only value, do not actually use it");if(typeof d[1]=="string")throw new RangeError("This is a type-check only value, do not actually use it");return f[1].required&&!d[1].required?-1:!f[1].required&&d[1].required?1:f[0].localeCompare(d[0])})),l=new Set;if(n.length)for(let[f,d]of a){if(typeof d=="string")throw new RangeError("This is a type-check only value, do not actually use it");if(l.has(f))continue;let g=d.required,b=[this.makeFlagString(f,d)];if(d.exclusive?.length)for(let S of d.exclusive){l.add(S);let E=a.get(S),T=this.makeFlagString(S,E);b.push(T),E.required&&(g=!0)}this.pushNewLineBeforeNewEntryIfLengthIsPastTheLimit({state:s,itemToAdd:g?b.join(" | "):`[${b.join(" | ")}]`,indentSize:o})}let m=Ps(s.join(" "),oe()-o),u=Ns(m,o+1).trim();e.push(` ${u}`,""),i.length&&this.pushArguments(e,i),n.length&&this.pushFlags(e,a)}pushArguments(e,t){if(!t.length)return;e.push(Or.bold("ARGUMENTS"));let o=un(t.map(([s])=>s).join(`
15
- `));for(let[s,i]of t){let n=`${s.padEnd(o)} ${i.description}`,a=Ps(n,oe()-o-2),l=Ns(a,o+2+2).trim();e.push(` ${l}`)}e.push("")}pushFlags(e,t){if(!t.size)return;e.push(Or.bold("FLAGS"));let o=new Map;for(let[i,n]of t){let a=[];switch(n.char?a.push(`-${n.char},`):a.push(" ".repeat(3)),n.flagTag){case"boolean":a.push(`--${this.kebabFlagName(i)}`);break;case"string":case"integer":{let l=n.choices?"<option>":"<value>";a.push(`--${this.kebabFlagName(i)}=${Or.underline(l)}`);break}default:throw new Error(`Unhandled flag tag: ${n.flagTag}`)}o.set(a.join(" "),n)}let s=un([...o.keys()].map(cn).join(`
16
- `));for(let[i,n]of o){let a=s-cn(i).length,l=`${i}${" ".repeat(a)} ${n.description??""}`;n.choices?.length&&(l+=`
17
- <options: ${n.choices.join("|")}>`);let m=Ps(l,oe()-s),u=Ns(m,s).trim().split(`
14
+ `).trim()}pushUsageString(e){e.push(Pr.bold("USAGE"));let t=`$ ${this.entrypoint} ${this.command.name}`,o=2+gc(t),s=[t],i=Object.entries(this.command.args??{});if(i.length)for(let[f,d]of i){if(typeof d=="string")throw new RangeError("This is a type-check only value, do not actually use it");this.pushNewLineBeforeNewEntryIfLengthIsPastTheLimit({state:s,itemToAdd:d.required?`<${f}>`:`[${f}]`,indentSize:o})}let n=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&&n.push(["json",{choices: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 a=new Map(n.sort((f,d)=>{if(typeof f[1]=="string")throw new RangeError("This is a type-check only value, do not actually use it");if(typeof d[1]=="string")throw new RangeError("This is a type-check only value, do not actually use it");return f[1].required&&!d[1].required?-1:!f[1].required&&d[1].required?1:f[0].localeCompare(d[0])})),l=new Set;if(n.length)for(let[f,d]of a){if(typeof d=="string")throw new RangeError("This is a type-check only value, do not actually use it");if(l.has(f))continue;let g=d.required,b=[this.makeFlagString(f,d)];if(d.exclusive?.length)for(let S of d.exclusive){l.add(S);let E=a.get(S),T=this.makeFlagString(S,E);b.push(T),E.required&&(g=!0)}this.pushNewLineBeforeNewEntryIfLengthIsPastTheLimit({state:s,itemToAdd:g?b.join(" | "):`[${b.join(" | ")}]`,indentSize:o})}let u=Fs(s.join(" "),oe()-o),m=Ds(u,o+1).trim();e.push(` ${m}`,""),i.length&&this.pushArguments(e,i),n.length&&this.pushFlags(e,a)}pushArguments(e,t){if(!t.length)return;e.push(Pr.bold("ARGUMENTS"));let o=fn(t.map(([s])=>s).join(`
15
+ `));for(let[s,i]of t){let n=`${s.padEnd(o)} ${i.description}`,a=Fs(n,oe()-o-2),l=Ds(a,o+2+2).trim();e.push(` ${l}`)}e.push("")}pushFlags(e,t){if(!t.size)return;e.push(Pr.bold("FLAGS"));let o=new Map;for(let[i,n]of t){let a=[];switch(n.char?a.push(`-${n.char},`):a.push(" ".repeat(3)),n.flagTag){case"boolean":a.push(`--${this.kebabFlagName(i)}`);break;case"string":case"integer":{let l=n.choices?"<option>":"<value>";a.push(`--${this.kebabFlagName(i)}=${Pr.underline(l)}`);break}default:throw new Error(`Unhandled flag tag: ${n.flagTag}`)}o.set(a.join(" "),n)}let s=fn([...o.keys()].map(pn).join(`
16
+ `));for(let[i,n]of o){let a=s-pn(i).length,l=`${i}${" ".repeat(a)} ${n.description??""}`;n.choices?.length&&(l+=`
17
+ <options: ${n.choices.join("|")}>`);let u=Fs(l,oe()-s),m=Ds(u,s).trim().split(`
18
18
  `).map(f=>/^-[a-z]/.test(f.trim())?f:` ${f}`).join(`
19
- `);e.push(` ${u}`)}e.push("")}};import dc from"chalk";import pc from"indent-string";import fc from"widest-line";import gc from"wrap-ansi";var Yt=class extends ft{static{c(this,"CommandWithSubcommandsHelp")}render(){let e=[];return this.pushShortDescription(e),this.command.description&&this.pushDescription(e),this.pushSubcommands(e),e.join(`
19
+ `);e.push(` ${m}`)}e.push("")}};import hc from"chalk";import yc from"indent-string";import wc from"widest-line";import Ac from"wrap-ansi";var Jt=class extends ft{static{c(this,"CommandWithSubcommandsHelp")}render(){let e=[];return this.pushShortDescription(e),this.command.description&&this.pushDescription(e),this.pushSubcommands(e),e.join(`
20
20
  `).trim()}selectiveRender(e){let t=[];return e.showShortDescription&&this.pushShortDescription(t),e.showDescription&&this.command.description&&this.pushDescription(t),e.showSubcommands&&this.pushSubcommands(t),t.join(`
21
- `).trim()}pushSubcommands(e){if(!this.command.subcommands?.length)return;e.push(dc.bold("SUBCOMMANDS"));let t=fc(this.command.subcommands.map(o=>`${this.command.name} ${o.name}`).join(`
21
+ `).trim()}pushSubcommands(e){if(!this.command.subcommands?.length)return;e.push(hc.bold("SUBCOMMANDS"));let t=wc(this.command.subcommands.map(o=>`${this.command.name} ${o.name}`).join(`
22
22
  `));for(let o of this.command.subcommands){let s=o.shortDescription||o.description?.split(`
23
- `)[0]||"",i=`${this.command.name} ${o.name.padEnd(t-this.command.name.length-1)} ${s}`,n=gc(i,oe()-t-2),a=pc(n,t+2+2).trim();e.push(` ${a}`)}e.push("")}};var Jt=new Map;function Ls(r,e){if(e.name.toLowerCase()!==e.name){p({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){Jt.set(e,new Yt(r,e));for(let t of e.subcommands)Ls(`${r} ${e.name}`,t)}else Jt.set(e,new Nr(r,e))}c(Ls,"registerCommandForHelpGeneration");function Pr(r){let e=Jt.get(r);if(!e)throw new Error(`No help renderer found for command ${r.name}`);return e.render()}c(Pr,"renderHelpForCommand");function Lr(r,e){let t=Jt.get(r);if(!t)throw new Error(`No help renderer found for command ${r.name}`);return t.selectiveRender(e)}c(Lr,"selectiveRenderHelpForCommand");function fn(r,e){return r[0].name.localeCompare(e[0].name)}c(fn,"sortByName");function kr(r){let e=K(),t=[];t.push("Apify command-line interface (CLI) helps you manage the Apify cloud platform and develop, build, and deploy Apify Actors.",""),t.push(Ht.bold("VERSION")),t.push(` ${e.fullVersionString}`),t.push(""),t.push(Ht.bold("USAGE")),t.push(` $ ${r} <command> [options]`),t.push("");let o=Mi(Jt,([n,a])=>a.entrypoint.includes(" ")||n.hidden?"ignored":a instanceof Yt?"subcommand":"command"),s=o.get("subcommand")?.sort(fn),i=o.get("command")?.sort(fn);if(s?.length){t.push(Ht.bold("TOPICS"));let n=[],a=dn(s.map(([l])=>l.name).join(`
24
- `));for(let[l]of s){if(l.hidden)continue;let m=l.shortDescription||l.description?.split(`
25
- `)[0]||"",u=`${l.name.padEnd(a)} ${m}`,f=pn(u,oe()-a-2);n.push(` ${mn(f,a+2+2).trim()}`)}t.push(...n,"")}if(i?.length){t.push(Ht.bold("COMMANDS"));let n=[],a=dn(i.map(([l])=>l.name).join(`
26
- `));for(let[l]of i){if(l.hidden)continue;let m=l.shortDescription||l.description?.split(`
27
- `)[0]||"",u=`${l.name.padEnd(a)} ${m}`,f=pn(u,oe()-a-2);n.push(` ${mn(f,a+2+2).trim()}`)}t.push(...n,"")}return t.push(Ht.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"),t.join(`
28
- `).trim()}c(kr,"renderMainHelpMenu");var Dr=(u=>(u[u.NODEJS_ERR_PARSE_ARGS_INVALID_OPTION_VALUE=0]="NODEJS_ERR_PARSE_ARGS_INVALID_OPTION_VALUE",u[u.NODEJS_ERR_PARSE_ARGS_UNEXPECTED_POSITIONAL=1]="NODEJS_ERR_PARSE_ARGS_UNEXPECTED_POSITIONAL",u[u.NODEJS_ERR_PARSE_ARGS_UNKNOWN_OPTION=2]="NODEJS_ERR_PARSE_ARGS_UNKNOWN_OPTION",u[u.APIFY_FLAG_PROVIDED_MULTIPLE_TIMES=3]="APIFY_FLAG_PROVIDED_MULTIPLE_TIMES",u[u.APIFY_INVALID_FLAG_INTEGER_VALUE=4]="APIFY_INVALID_FLAG_INTEGER_VALUE",u[u.APIFY_INVALID_CHOICE=5]="APIFY_INVALID_CHOICE",u[u.APIFY_MISSING_FLAG=6]="APIFY_MISSING_FLAG",u[u.APIFY_FLAG_IS_EXCLUSIVE_WITH_ANOTHER_FLAG=7]="APIFY_FLAG_IS_EXCLUSIVE_WITH_ANOTHER_FLAG",u[u.APIFY_TOO_MANY_REQUESTERS_OF_STDIN=8]="APIFY_TOO_MANY_REQUESTERS_OF_STDIN",u[u.APIFY_UNKNOWN_ERROR=9]="APIFY_UNKNOWN_ERROR",u))(Dr||{}),ie=class r extends Error{static{c(this,"CommandError")}code;command;metadata;constructor({code:e,message:t="",metadata:o={},command:s}){super(t||String(Dr[e])),this.code=e,this.metadata=o,this.command=s}extractFlagNameFromMessage(){switch(this.code){case 0:{let e=/'(?:-[a-z], )?-?-(?<flagName>[a-zA-Z-]+)(?: <value>)?' (?<noArg>does not take)?(?<missingArg>argument missing)?(?<ambiguous>argument is ambiguous\.(?<ambiguousMessage>\s*.*\s*.*)?)?/gi.exec(this.message);if(!e)throw new Error(`Encountered unparsable error message from argument parser: ${this.message}.
23
+ `)[0]||"",i=`${this.command.name} ${o.name.padEnd(t-this.command.name.length-1)} ${s}`,n=Ac(i,oe()-t-2),a=yc(n,t+2+2).trim();e.push(` ${a}`)}e.push("")}};var qt=new Map;function Ms(r,e){if(e.name.toLowerCase()!==e.name){p({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){qt.set(e,new Jt(r,e));for(let t of e.subcommands)Ms(`${r} ${e.name}`,t)}else qt.set(e,new Lr(r,e))}c(Ms,"registerCommandForHelpGeneration");function kr(r){let e=qt.get(r);if(!e)throw new Error(`No help renderer found for command ${r.name}`);return e.render()}c(kr,"renderHelpForCommand");function Dr(r,e){let t=qt.get(r);if(!t)throw new Error(`No help renderer found for command ${r.name}`);return t.selectiveRender(e)}c(Dr,"selectiveRenderHelpForCommand");function wn(r,e){return r[0].name.localeCompare(e[0].name)}c(wn,"sortByName");function Fr(r){let e=K(),t=[];t.push("Apify command-line interface (CLI) helps you manage the Apify cloud platform and develop, build, and deploy Apify Actors.",""),t.push(Kt.bold("VERSION")),t.push(` ${e.fullVersionString}`),t.push(""),t.push(Kt.bold("USAGE")),t.push(` $ ${r} <command> [options]`),t.push("");let o=Bi(qt,([n,a])=>a.entrypoint.includes(" ")||n.hidden?"ignored":a instanceof Jt?"subcommand":"command"),s=o.get("subcommand")?.sort(wn),i=o.get("command")?.sort(wn);if(s?.length){t.push(Kt.bold("TOPICS"));let n=[],a=hn(s.map(([l])=>l.name).join(`
24
+ `));for(let[l]of s){if(l.hidden)continue;let u=l.shortDescription||l.description?.split(`
25
+ `)[0]||"",m=`${l.name.padEnd(a)} ${u}`,f=yn(m,oe()-a-2);n.push(` ${gn(f,a+2+2).trim()}`)}t.push(...n,"")}if(i?.length){t.push(Kt.bold("COMMANDS"));let n=[],a=hn(i.map(([l])=>l.name).join(`
26
+ `));for(let[l]of i){if(l.hidden)continue;let u=l.shortDescription||l.description?.split(`
27
+ `)[0]||"",m=`${l.name.padEnd(a)} ${u}`,f=yn(m,oe()-a-2);n.push(` ${gn(f,a+2+2).trim()}`)}t.push(...n,"")}return t.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"),t.join(`
28
+ `).trim()}c(Fr,"renderMainHelpMenu");var Mr=(m=>(m[m.NODEJS_ERR_PARSE_ARGS_INVALID_OPTION_VALUE=0]="NODEJS_ERR_PARSE_ARGS_INVALID_OPTION_VALUE",m[m.NODEJS_ERR_PARSE_ARGS_UNEXPECTED_POSITIONAL=1]="NODEJS_ERR_PARSE_ARGS_UNEXPECTED_POSITIONAL",m[m.NODEJS_ERR_PARSE_ARGS_UNKNOWN_OPTION=2]="NODEJS_ERR_PARSE_ARGS_UNKNOWN_OPTION",m[m.APIFY_FLAG_PROVIDED_MULTIPLE_TIMES=3]="APIFY_FLAG_PROVIDED_MULTIPLE_TIMES",m[m.APIFY_INVALID_FLAG_INTEGER_VALUE=4]="APIFY_INVALID_FLAG_INTEGER_VALUE",m[m.APIFY_INVALID_CHOICE=5]="APIFY_INVALID_CHOICE",m[m.APIFY_MISSING_FLAG=6]="APIFY_MISSING_FLAG",m[m.APIFY_FLAG_IS_EXCLUSIVE_WITH_ANOTHER_FLAG=7]="APIFY_FLAG_IS_EXCLUSIVE_WITH_ANOTHER_FLAG",m[m.APIFY_TOO_MANY_REQUESTERS_OF_STDIN=8]="APIFY_TOO_MANY_REQUESTERS_OF_STDIN",m[m.APIFY_UNKNOWN_ERROR=9]="APIFY_UNKNOWN_ERROR",m))(Mr||{}),ne=class r extends Error{static{c(this,"CommandError")}code;command;metadata;constructor({code:e,message:t="",metadata:o={},command:s}){super(t||String(Mr[e])),this.code=e,this.metadata=o,this.command=s}extractFlagNameFromMessage(){switch(this.code){case 0:{let e=/'(?:-[a-z], )?-?-(?<flagName>[a-zA-Z-]+)(?: <value>)?' (?<noArg>does not take)?(?<missingArg>argument missing)?(?<ambiguous>argument is ambiguous\.(?<ambiguousMessage>\s*.*\s*.*)?)?/gi.exec(this.message);if(!e)throw new Error(`Encountered unparsable error message from argument parser: ${this.message}.
29
29
 
30
30
  Please report this issue at https://github.com/apify/apify-cli/issues`);return{name:e.groups.flagName,expectsValue:e.groups.noArg===void 0,ambiguousFlag:e.groups.ambiguous?e.groups.ambiguous:void 0,ambiguousMessage:e.groups.ambiguousMessage?e.groups.ambiguousMessage.trim():void 0}}case 2:{let e=/Unknown option '-(?<longForm>-)?(?<optionName>.+)'\.(?<nodeSuggestion>.*)/gi.exec(this.message);if(!e)throw new Error(`Encountered unparsable error message from argument parser: ${this.message}.
31
31
 
32
- Please report this issue at https://github.com/apify/apify-cli/issues`);return{name:e.groups.optionName,expectsValue:!1,unknownOptionSuggestion:e.groups.nodeSuggestion,shortForm:!e.groups.longForm}}default:throw new Error("Not implemented")}}getPrettyMessage(){switch(this.code){case 0:{let e=this.extractFlagNameFromMessage();return r.buildMessageFromFlagData(e)}case 2:{let e=this.extractFlagNameFromMessage(),t=Lr(this.command,{showUsageString:!0});return[Y.gray(`Unknown flag provided: ${Y.white.bold(e.shortForm?`-${e.name}`:`--${e.name}`)}`),e.unknownOptionSuggestion?Y.gray(` ${e.unknownOptionSuggestion.trim()}`):null,"",t].filter(o=>o!==null).join(`
32
+ Please report this issue at https://github.com/apify/apify-cli/issues`);return{name:e.groups.optionName,expectsValue:!1,unknownOptionSuggestion:e.groups.nodeSuggestion,shortForm:!e.groups.longForm}}default:throw new Error("Not implemented")}}getPrettyMessage(){switch(this.code){case 0:{let e=this.extractFlagNameFromMessage();return r.buildMessageFromFlagData(e)}case 2:{let e=this.extractFlagNameFromMessage(),t=Dr(this.command,{showUsageString:!0});return[Y.gray(`Unknown flag provided: ${Y.white.bold(e.shortForm?`-${e.name}`:`--${e.name}`)}`),e.unknownOptionSuggestion?Y.gray(` ${e.unknownOptionSuggestion.trim()}`):null,"",t].filter(o=>o!==null).join(`
33
33
  `)}case 3:{let e=`--${this.metadata.flag}`;return Y.gray(`Flag ${Y.white.bold(e)} can only be specified once.`)}case 4:{let e=`--${this.metadata.flag}`,t=Y.whiteBright(String(this.metadata.value));return Y.gray(`The provided value for the '${Y.white.bold(e)}' flag could not be processed as an integer. Received: ${t}.`)}case 6:{let{flag:e,matcher:t,providedButReceivedNoValue:o}=this.metadata,s=`'${Y.white.bold(`--${e}`)}'`;return t&&(s=`${s} (alias used: '${Y.white.bold(`--${t}`)}')`),o?Y.gray(`Flag ${s} was provided, but no value was received. Did you mean to pass the value as an argument or through standard input?`):Y.gray(`Flag ${s} is required, but was not provided.`)}case 7:{let{flagPairs:e}=this.metadata,t=[Y.gray("The following errors occurred:")],o=Y.red(" > ");for(let[s,i]of e)t.push(Y.gray(`${o}${Y.white.bold(s)} cannot also be provided when using ${Y.white.bold(i)}`));return t.push(Y.gray(`${o}See more help with ${Y.white.bold("--help")}`)),t.join(`
34
- `)}case 8:{let{firstUse:e,secondUse:t}=this.metadata;return Y.gray(`Flag ${Y.white.bold(`--${e}`)} and ${Y.white.bold(`--${t}`)} cannot both request that their value comes from standard input at the same time.`)}default:{let e=K();return["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:","",`- Error code: ${this.code} (${Dr[this.code]})`,`- Error metadata: ${JSON.stringify(this.metadata)}`,"",`- Stack:
34
+ `)}case 8:{let{firstUse:e,secondUse:t}=this.metadata;return Y.gray(`Flag ${Y.white.bold(`--${e}`)} and ${Y.white.bold(`--${t}`)} cannot both request that their value comes from standard input at the same time.`)}default:{let e=K();return["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:","",`- Error code: ${this.code} (${Mr[this.code]})`,`- Error metadata: ${JSON.stringify(this.metadata)}`,"",`- Stack:
35
35
  ${this.stack}`,"","- Arguments (!!!only provide these as is if there is no sensitive information!!!):",` ${JSON.stringify(process.argv.slice(2))}`,"",`- CLI version: \`${e.fullVersionString}\``,`- CLI debug logs (process.env.APIFY_CLI_DEBUG): ${process.env.APIFY_CLI_DEBUG?"Enabled":"Disabled"}`,`- Stdin data? ${Ce?"Yes":"No"}`].join(`
36
36
  `)}}}static buildMessageFromFlagData(e){let t=[`Flag ${Y.white.bold(e.shortForm?`-${e.name}`:`--${e.name}`)}`];return e.ambiguousFlag?(t.push("is ambiguous (meaning the provided value could be interpreted as a flag too)."),e.ambiguousMessage?t.push(`
37
37
  ${e.ambiguousMessage.split(`
38
38
  `).map(o=>` ${o}`).join(`
39
- `)}`):t.push(`To solve this, provide the flag like this: --${e.name}=<value>`)):e.expectsValue?t.push("expects a value"):t.push("does not take an argument"),t.map(o=>Y.gray(o)).join(" ")}static into(e,t){if(e instanceof r)return e;if(e instanceof Error&&"code"in e){let o=e;switch(o.code){case"ERR_PARSE_ARGS_INVALID_OPTION_VALUE":return new r({code:0,message:o.message,command:t});case"ERR_PARSE_ARGS_UNEXPECTED_POSITIONAL":return new r({code:1,message:o.message,command:t});case"ERR_PARSE_ARGS_UNKNOWN_OPTION":return new r({code:2,message:o.message,command:t});default:return new r({code:9,message:`Unknown error: ${e instanceof Error?e.message:String(e)}`,command:t})}}return new r({code:9,message:`Unknown error: ${e instanceof Error?e.message:String(e)}`,command:t})}};function gn(r){return r.replace(/[-_\s](.)/g,(e,t)=>t.toUpperCase())}c(gn,"camelCaseString");function ve(r){return r.replace(/[\s_]+/g,"-")}c(ve,"kebabCaseString");function Te(r){return r.replace(/([A-Z])/g,"-$1").toLowerCase()}c(Te,"camelCaseToKebabCase");var Ac={type:"boolean",multiple:!1,short:"h"},bc={type:"boolean",multiple:!1},q=new Map,Sc=["init","run","push","actors push","pull","actors pull","call","actors call","actors start"],h=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;commandString;aliasUsed;subcommandAliasUsed;skipTelemetry=!1;constructor(e,t,o,s){this.entrypoint=e,this.commandString=t,this.aliasUsed=o,this.subcommandAliasUsed=s;let i=K();this.telemetryData.installMethod=i.installMethod,this.telemetryData.osArch=i.arch,this.telemetryData.runtime=i.runtime.runtime,this.telemetryData.runtimeVersion=i.runtime.version,this.telemetryData.runtimeNodeVersion=i.runtime.nodeVersion??i.runtime.version,this.telemetryData.commandString=t,this.telemetryData.entrypoint=e}get ctor(){return this.constructor}pluralString(e,t,o){return e===1?t:o}static printHelp(){console.log(Pr(this)),process.exit(0)}printHelp(){return this.ctor.printHelp()}async _run(e){let{values:t,positionals:o,tokens:s}=e;t.help&&this.ctor.printHelp(),this.args={},this.flags={},this.ctor.enableJsonFlag&&(typeof t.json=="boolean"?this.flags.json=t.json:this.flags.json=!1);let i=new Map;if(this.ctor.args){let n=0;for(let[a,l]of Object.entries(this.ctor.args)){if(typeof l=="string")throw new RangeError("Do not provide the string for the json arg! It is a type level assertion!");let m=gn(a),u=o[n++];if(u)switch(l.argTag){default:this.args[m]=String(u),u==="-"&&l.stdin&&(this.args[m]=this._handleStdin(l.stdin)),l.catchAll&&(this.args[m]=o.slice(n-1).join(" "));break}else l.required&&i.set(a,l)}}if(i.size){this._printMissingRequiredArgs(i);return}this._parseFlags(t,s);try{await this.run()}catch(n){p({message:n.message})}finally{!this.telemetryData.actorLanguage&&Sc.includes(this.commandString)&&(await _e()).inspect(a=>{a.type===0?(this.telemetryData.actorLanguage="javascript",this.telemetryData.actorRuntime=a.runtime.runtimeShorthand||"node",this.telemetryData.actorRuntimeVersion=a.runtime.version):(a.type===1||a.type===2)&&(this.telemetryData.actorLanguage="python",this.telemetryData.actorRuntime="python",this.telemetryData.actorRuntimeVersion=a.runtime.version)}),this.telemetryData.flagsUsed=Object.keys(this.flags),this.skipTelemetry||await Bi(`cli_command_${this.commandString.replaceAll(" ","_").toLowerCase()}`,this.telemetryData)}}_userFlagNameToRegisteredName(e,t){let o=ve(Te(e)).toLowerCase(),s=o;o.startsWith("no-")&&(s=o.slice(3));let i=new Set;for(let n of t.aliases??[])i.add(ve(Te(n)).toLowerCase());return{baseFlagName:s,rawBaseFlagName:o,allMatchers:[s,...i]}}_commandFlagKeyToKebabCaseRegisteredName(e){let t=ve(Te(e)).toLowerCase();return t.startsWith("no-")&&(t=t.slice(3)),t}_parseFlags(e,t){if(!this.ctor.flags)return;let o=new Map,s;for(let[n,a]of Object.entries(this.ctor.flags)){if(typeof a=="string")throw new RangeError("Do not provide the string for the json arg! It is a type level assertion!");let{allMatchers:l,baseFlagName:m,rawBaseFlagName:u}=this._userFlagNameToRegisteredName(n,a),f=gn(u),d=t.some(b=>b.kind==="option"&&b.name===m);if(a.exclusive?.length){let b=o.get(m)??new Set;for(let S of a.exclusive)b.add(this._commandFlagKeyToKebabCaseRegisteredName(S));o.set(m,b);for(let S of a.exclusive){let E=this._commandFlagKeyToKebabCaseRegisteredName(S),T=o.get(E)??new Set;T.add(m),o.set(E,T)}}let g=l.filter(b=>e[b]);if(g.length>1)throw new ie({code:3,command:this.ctor,metadata:{flag:m}});let y=e[g[0]];if(!y&&a.required)throw new ie({code:6,command:this.ctor,metadata:{flag:m,matcher:g[0]}});if(Array.isArray(y)){if(y.length>1)throw new ie({code:3,command:this.ctor,metadata:{flag:m}});y=y[0]}if(d&&typeof y=="string"&&y.startsWith("=")&&(y=y.slice(1)),typeof y<"u")switch(a.flagTag){case"boolean":{this.flags[f]=u.startsWith("no-")?!y:y;break}case"integer":{let b=Number(y);if(Number.isNaN(b)||!Number.isInteger(b))throw new ie({code:4,command:this.ctor,metadata:{flag:m,value:String(y)}});this.flags[f]=b;break}default:{if(this.flags[f]=y,y==="-"&&a.stdin){if(s)throw new ie({code:8,command:this.ctor,metadata:{firstUse:s,secondUse:m}});s=m,this.flags[f]=this._handleStdin(a.stdin)}break}}else typeof a.hasDefault<"u"&&(this.flags[f]=a.hasDefault);if(this.flags[f]&&a.choices&&!a.choices.includes(this.flags[f]))throw new ie({code:5,command:this.ctor,metadata:{flag:m,choices:a.choices.map(b=>ks.white.bold(b)).join(", ")}});if(this.flags[f]==null&&(a.required||y!=null))throw new ie({code:6,command:this.ctor,metadata:{flag:m,matcher:g[0],providedButReceivedNoValue:!!y}})}let i=[];for(let[n,a]of o)if(e[n]!=null)for(let l of a){if(e[l]==null)continue;let m=e[n][0],u=e[l][0],f=c((d,g)=>typeof g=="boolean"?g?`--${d}`:`--no-${d}`:`--${d}=${g}`,"flagRepresentation");i.push([f(n,m),f(l,u)]);break}if(i.length)throw new ie({code:7,command:this.ctor,metadata:{flagPairs:i}})}_printMissingRequiredArgs(e){let t=Lr(this.ctor,{showUsageString:!0}),o=yc([...e.keys()].join(`
40
- `)),s=[];for(let[i,n]of e){let a=`${i.padEnd(o)} ${n.description}`,l=wc(a,oe()-o-2),m=hc(l,o+2+2).trim();s.push(` ${ks.red(">")} ${m}`)}p({message:[`Missing ${e.size} required ${this.pluralString(e.size,"argument","arguments")}:`,...s,ks.gray(" See more help with --help"),"",t].join(`
41
- `)})}_handleStdin(e){return e===2?(Ce?.toString("utf8")??"").trim():Ce}_buildParseArgsOption(){let e={allowNegative:!0,allowPositionals:!0,strict:!0,tokens:!0,options:{help:Ac}};if(this.ctor.flags)for(let[t,o]of Object.entries(this.ctor.flags)){if(typeof o=="string")throw new RangeError("Do not provide the string for the json flag! It is a type level assertion!");if(t.toLowerCase()==="json")continue;let s=ve(Te(t)).toLowerCase();s.startsWith("no-")&&(s=s.slice(3));let i=o.builder(s);for(let{flagName:n,option:a}of i)e.options[n]=a}return this.ctor.enableJsonFlag&&(e.options.json=bc),e}static registerCommand(e){if(Ls(e,this),q.set(this.name,this),this.aliases?.length)for(let t of this.aliases)q.set(t,this);if(this.hiddenAliases?.length)for(let t of this.hiddenAliases)q.set(t,this);if(this.subcommands?.length)for(let t of this.subcommands){if(q.set(`${this.name} ${t.name}`,t),this.aliases?.length)for(let o of this.aliases)q.set(`${o} ${t.name}`,t);if(this.hiddenAliases?.length)for(let o of this.hiddenAliases)q.set(`${o} ${t.name}`,t);if(t.aliases?.length)for(let o of t.aliases){if(q.set(`${this.name} ${o}`,t),this.aliases?.length)for(let s of this.aliases)q.set(`${s} ${o}`,t);if(this.hiddenAliases?.length)for(let s of this.hiddenAliases)q.set(`${s} ${o}`,t)}if(t.hiddenAliases?.length)for(let o of t.hiddenAliases){if(q.set(`${this.name} ${o}`,t),this.aliases?.length)for(let s of this.aliases)q.set(`${s} ${o}`,t);if(this.hiddenAliases?.length)for(let s of this.hiddenAliases)q.set(`${s} ${o}`,t)}}}};async function hn(r,e,t){let o={positionals:[],values:{},tokens:[]},s=0;for(let[n,a]of Object.entries(t)){let[l,m]=n.split("_");if(l==="args")o.positionals[s++]=a;else{let u=ve(Te(m)).toLowerCase();u.startsWith("no-")?o.values[u.slice(3)]=!a:o.values[u]=a}}let i=new e(r,e.name,e.name);i.skipTelemetry=!0,await i._run(o)}c(hn,"internalRunCommand");import{once as vc}from"events";async function yn(){let r=await Tr(),{hasData:e,waitDelay:t,stream:o}=r;if(!e)return;let s=[],i=new AbortController,n=null;t&&(n=setTimeout(()=>{i.abort()},t).unref()),o.on("data",l=>{s.push(l),n&&(clearTimeout(n),n=null)});try{await vc(o,"end",{signal:i.signal})}catch(l){if(l.name==="AbortError")return}n&&clearTimeout(n),r.hasData=!1;let a=Buffer.concat(s);if(a.length)return a}c(yn,"readStdin");import{gt as xc}from"semver";import{existsSync as Tc,mkdirSync as Cc,readFileSync as Ic,writeFileSync as Ec}from"fs";import{dirname as $c}from"path";function Rc(r){if(r.version&&r.version>=1)return!1;let e=r;if(e.latestNpmVersionCheckedAt){let t=new Date(e.latestNpmVersionCheckedAt).getTime(),o=e.latestNpmVersion;C("LocalStateV0ToV1","Migrating state from v0 to v1",{oldState:r,newState:{versionCheck:{lastChecked:t,lastVersion:o}}}),Fs({version:1},s=>{s.versionCheck={lastChecked:t,lastVersion:o}})}return!0}c(Rc,"migrateStateV0ToV1");var _c={version:1};function Ds(){let r=lr();if(!Tc(r))return _c;let t=JSON.parse(Ic(r,"utf-8"));return Rc(t)?Ds():t}c(Ds,"useLocalState");function Fs(r,e){let t={...r};e(t);let o=lr(),s=$c(o);Cc(s,{recursive:!0}),Ec(lr(),JSON.stringify(t,null," "))}c(Fs,"updateLocalState");var Fr=K(),wn=`Apify CLI/${Fr.version} (https://github.com/apify/apify-cli)`,Oc=["https://1.1.1.1","https://8.8.8.8"];async function Nc(r=500){let e=new AbortController,t=setTimeout(()=>{e.abort()},r),o=await Promise.any(Oc.map(async s=>fetch(s,{signal:e.signal,headers:{"User-Agent":wn},keepalive:!1}))).catch(()=>null);return clearTimeout(t),o?o.ok?(C("isOnline",{state:"online",site:o.url}),!0):(C("isOnline",{state:"offline"}),!1):(C("isOnline",{state:"timeout"}),!1)}c(Nc,"isOnline");async function Pc(r){let e=await fetch("https://api.github.com/repos/apify/apify-cli/releases/latest",{headers:{"User-Agent":wn}});if(!e.ok)return C("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 C("useCLIVersionCheck","Fetched latest version",{version:o}),Fs(r,s=>{s.versionCheck={lastChecked:Date.now(),lastVersion:o}}),o}c(Pc,"getLatestVersion");function An(){return!!(process.env.APIFY_CLI_SKIP_UPDATE_CHECK&&!["0","false"].includes(process.env.APIFY_CLI_SKIP_UPDATE_CHECK))}c(An,"shouldSkipVersionCheck");async function bn(r=!1){let e=Ds(),t=!e.versionCheck||Date.now()-e.versionCheck.lastChecked>mi,o=r||t&&await Nc(),s=o?await Pc(e):e.versionCheck?.lastVersion;if(!s)return{currentVersion:Fr.version,latestVersion:"unknown",shouldUpdate:!1,cacheHit:!1};let i=xc(s,Fr.version);return{currentVersion:Fr.version,latestVersion:s,shouldUpdate:i,cacheHit:!o}}c(bn,"useCLIVersionCheck");import{jaroWinkler as Lc}from"@skyra/jaro-winkler";import kc from"js-levenshtein";function Mr(r){let e=[...q.entries()].sort(([s],[i])=>s.localeCompare(i)),t=r.toLowerCase();return e.map(([s,i])=>{let n=s.toLowerCase(),a=s.split(" "),l=a[a.length-1].toLowerCase(),m=i.aliases?.includes(l)||i.hiddenAliases?.includes(l)||!1,u=kc(t,n),f=Lc(t,n),d=u<=2||f>=.975;return d?(C("useCommandSuggestions",{inputString:t,lowercased:n,matches:d,levenshtein:u,jaroWinkler:f}),m?{string:`${n} (alias for ${i.name})`,distance:f}:{string:`${n}`,distance:f}):null}).filter(s=>s!==null).sort((s,i)=>i.distance-s.distance).map(s=>s.string)}c(Mr,"useCommandSuggestions");var Ce=await yn(),Kt=K(),ot=`Apify CLI/${Kt.version} (https://github.com/apify/apify-cli)`;function Wh(r){Kt.installMethod!=="bundle"&&(Dc(Ie.version,be)||(p({message:`${r} CLI requires Node.js version ${be}. Your current version is ${Ie.version}.`}),Ie.exit(1)))}c(Wh,"processVersionCheck");function Fc(r){r.values.version===!0&&r.positionals.length===0&&(console.log(Kt.fullVersionString),Ie.exit(0))}c(Fc,"printCLIVersionAndExitIfFlagUsed");function Mc(r,e){(r.values.help===!0&&r.positionals.length===0||r.positionals.length===0)&&(console.log(kr(e)),Ie.exit(0))}c(Mc,"printHelpAndExitIfFlagUsedOrNoCommandPassed");function vn(r){let e=Mr(String(r)),t=Ur.gray(`Command ${Ur.whiteBright(r)} not found`);e.length&&(t+=`
42
- `,t+=Ur.gray(`Did you mean: ${e.map(o=>Ur.whiteBright(o)).join(", ")}?`)),p({message:t}),Ie.exit(1)}c(vn,"handleCommandNotFound");async function Uc(r,e){let t=q.get("upgrade");if([t.name,...t.aliases??[]].some(s=>e===s)){C("[VersionCheckMiddleware]","upgrade command detected, skipping version check");return}if(An()){C("[VersionCheckMiddleware]","skipping version check because APIFY_CLI_SKIP_UPDATE_CHECK is set");return}await hn(r,t,{flags_internalAutomaticCall:!0})}c(Uc,"runVersionCheck");async function zh(r){C("CLIMetadata",{...Kt,fullVersionString:Kt.fullVersionString,argv:Ie.argv,cwd:Ie.cwd(),execPath:Ie.execPath});let e=Ie.argv.slice(2);C("ProcessArgv",e);let t=Sn({allowPositionals:!0,strict:!1,options:{help:{type:"boolean",short:"h"},version:{type:"boolean",short:"v"}},args:e});Fc(t),Mc(t,r),await Uc(r,t.positionals[0]),C("TopLevelOptions",t);let[o,s]=t.positionals,i=!1,n=q.get(o);if(!n)return vn(o);let a=n;if(n.subcommands?.length){if(!s)return n.printHelp();i=!0,a=q.get(`${o} ${s}`)}if(!a)return vn(`${o} ${s}`);let l=[...e],m=l.indexOf(o);if(C("CommandNameIndex",m),l.splice(m,1),i){let d=l.indexOf(s);C("SubcommandNameIndex",d),l.splice(d,1)}C("RebuiltArgs",l),C("CommandToRun",a);let u=new a(r,i?`${n.name} ${s}`:n.name,o,i?s:void 0),f=u._buildParseArgsOption();C("ParserOptionsForCommand",f);try{let d=Sn({...f,args:l});await u._run(d),C("CommandArgsResult",d)}catch(d){let g=ie.into(d,a);p({message:g.getPrettyMessage()}),Ie.exit(1)}}c(zh,"runCLI");import{join as su,resolve as iu}from"path";import Us from"process";import{calculateRunDynamicMemory as nu}from"@apify/actor-memory-expression";var w={string:jc,boolean:Vc,integer:Bc};function jc(r){return{flagTag:"string",builder:c(e=>{let t=new Set([...r.aliases??[]]);t.delete(e);let o=[{flagName:e,option:{type:"string",multiple:!0}}];r.char&&(o[0].option.short=r.char);for(let s of t)o.push({flagName:ve(Te(s)).toLowerCase(),option:{type:"string",multiple:!0}});return o},"builder"),choices:r.choices,required:r.required??!1,hasDefault:r.default,stdin:r.stdin??2,description:r.description,aliases:r.aliases,char:r.char,hidden:r.hidden,exclusive:r.exclusive}}c(jc,"stringFlag");function Vc(r){return{flagTag:"boolean",builder:c(e=>{let t=new Set([...r.aliases??[]]);t.delete(e);let o=[{flagName:e,option:{type:"boolean",multiple:!0}}];r.char&&(o[0].option.short=r.char);for(let s of t)o.push({flagName:ve(Te(s)).toLowerCase(),option:{type:"boolean",multiple:!0}});return o},"builder"),choices:null,required:r.required??!1,hasDefault:r.default,stdin:r.stdin??1,description:r.description,aliases:r.aliases,char:r.char,hidden:r.hidden,exclusive:r.exclusive}}c(Vc,"booleanFlag");function Bc(r){return{flagTag:"integer",builder:c(e=>{let t=new Set([...r.aliases??[]]);t.delete(e);let o=[{flagName:e,option:{type:"string",multiple:!0}}];r.char&&(o[0].option.short=r.char);for(let s of t)o.push({flagName:ve(Te(s)).toLowerCase(),option:{type:"string",multiple:!0}});return o},"builder"),choices:null,required:r.required??!1,hasDefault:r.default,stdin:r.stdin??1,description:r.description,aliases:r.aliases,char:r.char,hidden:r.hidden,exclusive:r.exclusive}}c(Bc,"integerFlag");import{mkdir as qc,rename as $n,writeFile as Wc}from"fs/promises";import{dirname as zc,join as Xc}from"path";import En from"process";import{inspect as Zc}from"util";import{err as qt,ok as Br}from"@sapphire/result";import{createPrompt as Gc,isEnterKey as Yc,makeTheme as Hc,useKeypress as Jc,usePrefix as Kc,useState as Tn}from"@inquirer/core";function Ms(r,e){let t=e!==!1;return/^(y|yes)/i.test(r)?t=!0:/^(n|no)/i.test(r)&&(t=!1),t}c(Ms,"getBooleanValue");function Cn(r){return r?"Yes":"No"}c(Cn,"boolToString");var In=Gc((r,e)=>{let t=Cn,[o,s]=Tn("idle"),[i,n]=Tn(""),a=Hc(),l=Kc({status:o,theme:a});Jc((d,g)=>{if(Yc(d)){let y=Ms(i,r.default);n(t(y)),s("done"),e(y);return}if(d.name==="tab"){let y=Cn(!Ms(i,r.default));g.clearLine(0),g.write(y),n(y);return}if(d.name==="y"||d.name==="n"){let y=Ms(d.name,r.default);n(t(y)),s("done"),e(y);return}g.clearLine(0),g.write(i),n(g.line)});let m=i,u="";o==="done"?m=a.style.answer(i):u=` ${a.style.defaultAnswer(r.default===!1?"y/N":"Y/n")}`;let f=a.style.message(r.message,o);return`${l} ${f}${u} ${m}`});var z=Re(async({message:r,default:e})=>await In({message:r,default:e}));var Qc=c(r=>Xc(r,ur),"getDeprecatedLocalConfigPath"),Vr=new Map;async function xe({cwd:r=En.cwd(),migrateConfig:e=!0,warnAboutOldConfig:t=!0}={cwd:En.cwd(),migrateConfig:!0,warnAboutOldConfig:!0}){let o=Vr.get(r);if(o)return C("useActorConfig",{cacheHit:!0,config:o}),Br(o);let s=Is(r),i=Qc(r),n,a;try{n=de(s)}catch(m){return qt({message:`Failed to read local config at path: '${s}':`,cause:m,exists:!1,config:{}})}try{a=de(i)}catch(m){return qt({message:`Failed to read local config at path: '${i}':`,cause:m,exists:!1,config:{}})}if(n&&a&&t&&await eu(i),!n&&!a)return Vr.set(r,{exists:!1,migrated:!1,config:{}}),Br({exists:!1,migrated:!1,config:{}});let l=!1;if(!n&&a&&e){let m=await ru(a,i,s);if(m.isErr())return qt(m.unwrapErr());n=m.unwrap(),l=!0}return Vr.set(r,{exists:!0,migrated:l,config:n||a||{}}),C("useActorConfig",{cacheHit:!1,config:Vr.get(r)}),Br({exists:!0,migrated:l,config:n||a||{}})}c(xe,"useActorConfig");async function eu(r){if(!await z({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 $n(r,`${r}.deprecated`),v({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(t){t instanceof Error?p({message:`Failed to rename the deprecated "apify.json" file to "apify.json.deprecated".
39
+ `)}`):t.push(`To solve this, provide the flag like this: --${e.name}=<value>`)):e.expectsValue?t.push("expects a value"):t.push("does not take an argument"),t.map(o=>Y.gray(o)).join(" ")}static into(e,t){if(e instanceof r)return e;if(e instanceof Error&&"code"in e){let o=e;switch(o.code){case"ERR_PARSE_ARGS_INVALID_OPTION_VALUE":return new r({code:0,message:o.message,command:t});case"ERR_PARSE_ARGS_UNEXPECTED_POSITIONAL":return new r({code:1,message:o.message,command:t});case"ERR_PARSE_ARGS_UNKNOWN_OPTION":return new r({code:2,message:o.message,command:t});default:return new r({code:9,message:`Unknown error: ${e instanceof Error?e.message:String(e)}`,command:t})}}return new r({code:9,message:`Unknown error: ${e instanceof Error?e.message:String(e)}`,command:t})}};function An(r){return r.replace(/[-_\s](.)/g,(e,t)=>t.toUpperCase())}c(An,"camelCaseString");function ve(r){return r.replace(/[\s_]+/g,"-")}c(ve,"kebabCaseString");function Te(r){return r.replace(/([A-Z])/g,"-$1").toLowerCase()}c(Te,"camelCaseToKebabCase");var Tc={type:"boolean",multiple:!1,short:"h"},Cc={type:"boolean",multiple:!1},q=new Map,Ic=["init","run","push","actors push","pull","actors pull","call","actors call","actors start"],h=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;commandString;aliasUsed;subcommandAliasUsed;skipTelemetry=!1;constructor(e,t,o,s){this.entrypoint=e,this.commandString=t,this.aliasUsed=o,this.subcommandAliasUsed=s;let i=K();this.telemetryData.installMethod=i.installMethod,this.telemetryData.osArch=i.arch,this.telemetryData.runtime=i.runtime.runtime,this.telemetryData.runtimeVersion=i.runtime.version,this.telemetryData.runtimeNodeVersion=i.runtime.nodeVersion??i.runtime.version,this.telemetryData.commandString=t,this.telemetryData.entrypoint=e}get ctor(){return this.constructor}pluralString(e,t,o){return e===1?t:o}static printHelp(){console.log(kr(this)),process.exit(0)}printHelp(){return this.ctor.printHelp()}async _run(e){let{values:t,positionals:o,tokens:s}=e;t.help&&this.ctor.printHelp(),this.args={},this.flags={},this.ctor.enableJsonFlag&&(typeof t.json=="boolean"?this.flags.json=t.json:this.flags.json=!1);let i=new Map;if(this.ctor.args){let n=0;for(let[a,l]of Object.entries(this.ctor.args)){if(typeof l=="string")throw new RangeError("Do not provide the string for the json arg! It is a type level assertion!");let u=An(a),m=o[n++];if(m)switch(l.argTag){default:this.args[u]=String(m),m==="-"&&l.stdin&&(this.args[u]=this._handleStdin(l.stdin)),l.catchAll&&(this.args[u]=o.slice(n-1).join(" "));break}else l.required&&i.set(a,l)}}if(i.size){this._printMissingRequiredArgs(i);return}this._parseFlags(t,s);try{await this.run()}catch(n){p({message:n.message})}finally{!this.telemetryData.actorLanguage&&Ic.includes(this.commandString)&&(await _e()).inspect(a=>{a.type===0?(this.telemetryData.actorLanguage="javascript",this.telemetryData.actorRuntime=a.runtime.runtimeShorthand||"node",this.telemetryData.actorRuntimeVersion=a.runtime.version):(a.type===1||a.type===2)&&(this.telemetryData.actorLanguage="python",this.telemetryData.actorRuntime="python",this.telemetryData.actorRuntimeVersion=a.runtime.version)}),this.telemetryData.flagsUsed=Object.keys(this.flags),this.skipTelemetry||await Ji(`cli_command_${this.commandString.replaceAll(" ","_").toLowerCase()}`,this.telemetryData)}}_userFlagNameToRegisteredName(e,t){let o=ve(Te(e)).toLowerCase(),s=o;o.startsWith("no-")&&(s=o.slice(3));let i=new Set;for(let n of t.aliases??[])i.add(ve(Te(n)).toLowerCase());return{baseFlagName:s,rawBaseFlagName:o,allMatchers:[s,...i]}}_commandFlagKeyToKebabCaseRegisteredName(e){let t=ve(Te(e)).toLowerCase();return t.startsWith("no-")&&(t=t.slice(3)),t}_parseFlags(e,t){if(!this.ctor.flags)return;let o=new Map,s;for(let[n,a]of Object.entries(this.ctor.flags)){if(typeof a=="string")throw new RangeError("Do not provide the string for the json arg! It is a type level assertion!");let{allMatchers:l,baseFlagName:u,rawBaseFlagName:m}=this._userFlagNameToRegisteredName(n,a),f=An(m),d=t.some(b=>b.kind==="option"&&b.name===u);if(a.exclusive?.length){let b=o.get(u)??new Set;for(let S of a.exclusive)b.add(this._commandFlagKeyToKebabCaseRegisteredName(S));o.set(u,b);for(let S of a.exclusive){let E=this._commandFlagKeyToKebabCaseRegisteredName(S),T=o.get(E)??new Set;T.add(u),o.set(E,T)}}let g=l.filter(b=>e[b]);if(g.length>1)throw new ne({code:3,command:this.ctor,metadata:{flag:u}});let y=e[g[0]];if(!y&&a.required)throw new ne({code:6,command:this.ctor,metadata:{flag:u,matcher:g[0]}});if(Array.isArray(y)){if(y.length>1)throw new ne({code:3,command:this.ctor,metadata:{flag:u}});y=y[0]}if(d&&typeof y=="string"&&y.startsWith("=")&&(y=y.slice(1)),typeof y<"u")switch(a.flagTag){case"boolean":{this.flags[f]=m.startsWith("no-")?!y:y;break}case"integer":{let b=Number(y);if(Number.isNaN(b)||!Number.isInteger(b))throw new ne({code:4,command:this.ctor,metadata:{flag:u,value:String(y)}});this.flags[f]=b;break}default:{if(this.flags[f]=y,y==="-"&&a.stdin){if(s)throw new ne({code:8,command:this.ctor,metadata:{firstUse:s,secondUse:u}});s=u,this.flags[f]=this._handleStdin(a.stdin)}break}}else typeof a.hasDefault<"u"&&(this.flags[f]=a.hasDefault);if(this.flags[f]&&a.choices&&!a.choices.includes(this.flags[f]))throw new ne({code:5,command:this.ctor,metadata:{flag:u,choices:a.choices.map(b=>Us.white.bold(b)).join(", ")}});if(this.flags[f]==null&&(a.required||y!=null))throw new ne({code:6,command:this.ctor,metadata:{flag:u,matcher:g[0],providedButReceivedNoValue:!!y}})}let i=[];for(let[n,a]of o)if(e[n]!=null)for(let l of a){if(e[l]==null)continue;let u=e[n][0],m=e[l][0],f=c((d,g)=>typeof g=="boolean"?g?`--${d}`:`--no-${d}`:`--${d}=${g}`,"flagRepresentation");i.push([f(n,u),f(l,m)]);break}if(i.length)throw new ne({code:7,command:this.ctor,metadata:{flagPairs:i}})}_printMissingRequiredArgs(e){let t=Dr(this.ctor,{showUsageString:!0}),o=Sc([...e.keys()].join(`
40
+ `)),s=[];for(let[i,n]of e){let a=`${i.padEnd(o)} ${n.description}`,l=vc(a,oe()-o-2),u=bc(l,o+2+2).trim();s.push(` ${Us.red(">")} ${u}`)}p({message:[`Missing ${e.size} required ${this.pluralString(e.size,"argument","arguments")}:`,...s,Us.gray(" See more help with --help"),"",t].join(`
41
+ `)})}_handleStdin(e){return e===2?(Ce?.toString("utf8")??"").trim():Ce}_buildParseArgsOption(){let e={allowNegative:!0,allowPositionals:!0,strict:!0,tokens:!0,options:{help:Tc}};if(this.ctor.flags)for(let[t,o]of Object.entries(this.ctor.flags)){if(typeof o=="string")throw new RangeError("Do not provide the string for the json flag! It is a type level assertion!");if(t.toLowerCase()==="json")continue;let s=ve(Te(t)).toLowerCase();s.startsWith("no-")&&(s=s.slice(3));let i=o.builder(s);for(let{flagName:n,option:a}of i)e.options[n]=a}return this.ctor.enableJsonFlag&&(e.options.json=Cc),e}static registerCommand(e){if(Ms(e,this),q.set(this.name,this),this.aliases?.length)for(let t of this.aliases)q.set(t,this);if(this.hiddenAliases?.length)for(let t of this.hiddenAliases)q.set(t,this);if(this.subcommands?.length)for(let t of this.subcommands){if(q.set(`${this.name} ${t.name}`,t),this.aliases?.length)for(let o of this.aliases)q.set(`${o} ${t.name}`,t);if(this.hiddenAliases?.length)for(let o of this.hiddenAliases)q.set(`${o} ${t.name}`,t);if(t.aliases?.length)for(let o of t.aliases){if(q.set(`${this.name} ${o}`,t),this.aliases?.length)for(let s of this.aliases)q.set(`${s} ${o}`,t);if(this.hiddenAliases?.length)for(let s of this.hiddenAliases)q.set(`${s} ${o}`,t)}if(t.hiddenAliases?.length)for(let o of t.hiddenAliases){if(q.set(`${this.name} ${o}`,t),this.aliases?.length)for(let s of this.aliases)q.set(`${s} ${o}`,t);if(this.hiddenAliases?.length)for(let s of this.hiddenAliases)q.set(`${s} ${o}`,t)}}}};async function bn(r,e,t){let o={positionals:[],values:{},tokens:[]},s=0;for(let[n,a]of Object.entries(t)){let[l,u]=n.split("_");if(l==="args")o.positionals[s++]=a;else{let m=ve(Te(u)).toLowerCase();m.startsWith("no-")?o.values[m.slice(3)]=!a:o.values[m]=a}}let i=new e(r,e.name,e.name);i.skipTelemetry=!0,await i._run(o)}c(bn,"internalRunCommand");import{once as Ec}from"events";async function Sn(){let r=await Ir(),{hasData:e,waitDelay:t,stream:o}=r;if(!e)return;let s=[],i=new AbortController,n=null;t&&(n=setTimeout(()=>{i.abort()},t).unref()),o.on("data",l=>{s.push(l),n&&(clearTimeout(n),n=null)});try{await Ec(o,"end",{signal:i.signal})}catch(l){if(l.name==="AbortError")return}n&&clearTimeout(n),r.hasData=!1;let a=Buffer.concat(s);if(a.length)return a}c(Sn,"readStdin");import{gt as Lc}from"semver";import{existsSync as $c,mkdirSync as Rc,readFileSync as _c,writeFileSync as xc}from"fs";import{dirname as Oc}from"path";function Nc(r){if(r.version&&r.version>=1)return!1;let e=r;if(e.latestNpmVersionCheckedAt){let t=new Date(e.latestNpmVersionCheckedAt).getTime(),o=e.latestNpmVersion;C("LocalStateV0ToV1","Migrating state from v0 to v1",{oldState:r,newState:{versionCheck:{lastChecked:t,lastVersion:o}}}),Vs({version:1},s=>{s.versionCheck={lastChecked:t,lastVersion:o}})}return!0}c(Nc,"migrateStateV0ToV1");var Pc={version:1};function js(){let r=mr();if(!$c(r))return Pc;let t=JSON.parse(_c(r,"utf-8"));return Nc(t)?js():t}c(js,"useLocalState");function Vs(r,e){let t={...r};e(t);let o=mr(),s=Oc(o);Rc(s,{recursive:!0}),xc(mr(),JSON.stringify(t,null," "))}c(Vs,"updateLocalState");var Ur=K(),vn=`Apify CLI/${Ur.version} (https://github.com/apify/apify-cli)`,kc=["https://1.1.1.1","https://8.8.8.8"];async function Dc(r=500){let e=new AbortController,t=setTimeout(()=>{e.abort()},r),o=await Promise.any(kc.map(async s=>fetch(s,{signal:e.signal,headers:{"User-Agent":vn},keepalive:!1}))).catch(()=>null);return clearTimeout(t),o?o.ok?(C("isOnline",{state:"online",site:o.url}),!0):(C("isOnline",{state:"offline"}),!1):(C("isOnline",{state:"timeout"}),!1)}c(Dc,"isOnline");async function Fc(r){let e=await fetch("https://api.github.com/repos/apify/apify-cli/releases/latest",{headers:{"User-Agent":vn}});if(!e.ok)return C("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 C("useCLIVersionCheck","Fetched latest version",{version:o}),Vs(r,s=>{s.versionCheck={lastChecked:Date.now(),lastVersion:o}}),o}c(Fc,"getLatestVersion");function Tn(){return!!(process.env.APIFY_CLI_SKIP_UPDATE_CHECK&&!["0","false"].includes(process.env.APIFY_CLI_SKIP_UPDATE_CHECK))}c(Tn,"shouldSkipVersionCheck");async function Cn(r=!1){let e=js(),t=!e.versionCheck||Date.now()-e.versionCheck.lastChecked>gi,o=r||t&&await Dc(),s=o?await Fc(e):e.versionCheck?.lastVersion;if(!s)return{currentVersion:Ur.version,latestVersion:"unknown",shouldUpdate:!1,cacheHit:!1};let i=Lc(s,Ur.version);return{currentVersion:Ur.version,latestVersion:s,shouldUpdate:i,cacheHit:!o}}c(Cn,"useCLIVersionCheck");import{jaroWinkler as Mc}from"@skyra/jaro-winkler";import Uc from"js-levenshtein";function jr(r){let e=[...q.entries()].sort(([s],[i])=>s.localeCompare(i)),t=r.toLowerCase();return e.map(([s,i])=>{let n=s.toLowerCase(),a=s.split(" "),l=a[a.length-1].toLowerCase(),u=i.aliases?.includes(l)||i.hiddenAliases?.includes(l)||!1,m=Uc(t,n),f=Mc(t,n),d=m<=2||f>=.975;return d?(C("useCommandSuggestions",{inputString:t,lowercased:n,matches:d,levenshtein:m,jaroWinkler:f}),u?{string:`${n} (alias for ${i.name})`,distance:f}:{string:`${n}`,distance:f}):null}).filter(s=>s!==null).sort((s,i)=>i.distance-s.distance).map(s=>s.string)}c(jr,"useCommandSuggestions");var Ce=await Sn(),Wt=K(),ot=`Apify CLI/${Wt.version} (https://github.com/apify/apify-cli)`;function Qh(r){Wt.installMethod!=="bundle"&&(jc(Ie.version,be)||(p({message:`${r} CLI requires Node.js version ${be}. Your current version is ${Ie.version}.`}),Ie.exit(1)))}c(Qh,"processVersionCheck");function Vc(r){r.values.version===!0&&r.positionals.length===0&&(console.log(Wt.fullVersionString),Ie.exit(0))}c(Vc,"printCLIVersionAndExitIfFlagUsed");function Bc(r,e){(r.values.help===!0&&r.positionals.length===0||r.positionals.length===0)&&(console.log(Fr(e)),Ie.exit(0))}c(Bc,"printHelpAndExitIfFlagUsedOrNoCommandPassed");function En(r){let e=jr(String(r)),t=Vr.gray(`Command ${Vr.whiteBright(r)} not found`);e.length&&(t+=`
42
+ `,t+=Vr.gray(`Did you mean: ${e.map(o=>Vr.whiteBright(o)).join(", ")}?`)),p({message:t}),Ie.exit(1)}c(En,"handleCommandNotFound");async function Gc(r,e){let t=q.get("upgrade");if([t.name,...t.aliases??[]].some(s=>e===s)){C("[VersionCheckMiddleware]","upgrade command detected, skipping version check");return}if(Tn()){C("[VersionCheckMiddleware]","skipping version check because APIFY_CLI_SKIP_UPDATE_CHECK is set");return}await bn(r,t,{flags_internalAutomaticCall:!0})}c(Gc,"runVersionCheck");async function ey(r){C("CLIMetadata",{...Wt,fullVersionString:Wt.fullVersionString,argv:Ie.argv,cwd:Ie.cwd(),execPath:Ie.execPath});let e=Ie.argv.slice(2);C("ProcessArgv",e);let t=In({allowPositionals:!0,strict:!1,options:{help:{type:"boolean",short:"h"},version:{type:"boolean",short:"v"}},args:e});Vc(t),Bc(t,r),await Gc(r,t.positionals[0]),C("TopLevelOptions",t);let[o,s]=t.positionals,i=!1,n=q.get(o);if(!n)return En(o);let a=n;if(n.subcommands?.length){if(!s)return n.printHelp();i=!0,a=q.get(`${o} ${s}`)}if(!a)return En(`${o} ${s}`);let l=[...e],u=l.indexOf(o);if(C("CommandNameIndex",u),l.splice(u,1),i){let d=l.indexOf(s);C("SubcommandNameIndex",d),l.splice(d,1)}C("RebuiltArgs",l),C("CommandToRun",a);let m=new a(r,i?`${n.name} ${s}`:n.name,o,i?s:void 0),f=m._buildParseArgsOption();C("ParserOptionsForCommand",f);try{let d=In({...f,args:l});await m._run(d),C("CommandArgsResult",d)}catch(d){let g=ne.into(d,a);p({message:g.getPrettyMessage()}),Ie.exit(1)}}c(ey,"runCLI");import{join as lm,resolve as cm}from"path";import Gs from"process";import{calculateRunDynamicMemory as mm}from"@apify/actor-memory-expression";var w={string:Yc,boolean:Hc,integer:Jc};function Yc(r){return{flagTag:"string",builder:c(e=>{let t=new Set([...r.aliases??[]]);t.delete(e);let o=[{flagName:e,option:{type:"string",multiple:!0}}];r.char&&(o[0].option.short=r.char);for(let s of t)o.push({flagName:ve(Te(s)).toLowerCase(),option:{type:"string",multiple:!0}});return o},"builder"),choices:r.choices,required:r.required??!1,hasDefault:r.default,stdin:r.stdin??2,description:r.description,aliases:r.aliases,char:r.char,hidden:r.hidden,exclusive:r.exclusive}}c(Yc,"stringFlag");function Hc(r){return{flagTag:"boolean",builder:c(e=>{let t=new Set([...r.aliases??[]]);t.delete(e);let o=[{flagName:e,option:{type:"boolean",multiple:!0}}];r.char&&(o[0].option.short=r.char);for(let s of t)o.push({flagName:ve(Te(s)).toLowerCase(),option:{type:"boolean",multiple:!0}});return o},"builder"),choices:null,required:r.required??!1,hasDefault:r.default,stdin:r.stdin??1,description:r.description,aliases:r.aliases,char:r.char,hidden:r.hidden,exclusive:r.exclusive}}c(Hc,"booleanFlag");function Jc(r){return{flagTag:"integer",builder:c(e=>{let t=new Set([...r.aliases??[]]);t.delete(e);let o=[{flagName:e,option:{type:"string",multiple:!0}}];r.char&&(o[0].option.short=r.char);for(let s of t)o.push({flagName:ve(Te(s)).toLowerCase(),option:{type:"string",multiple:!0}});return o},"builder"),choices:null,required:r.required??!1,hasDefault:r.default,stdin:r.stdin??1,description:r.description,aliases:r.aliases,char:r.char,hidden:r.hidden,exclusive:r.exclusive}}c(Jc,"integerFlag");import{mkdir as Zc,rename as On,writeFile as Qc}from"fs/promises";import{dirname as em,join as tm}from"path";import xn from"process";import{inspect as rm}from"util";import{err as zt,ok as Yr}from"@sapphire/result";import{createPrompt as Kc,isEnterKey as qc,makeTheme as Wc,useKeypress as zc,usePrefix as Xc,useState as $n}from"@inquirer/core";function Bs(r,e){let t=e!==!1;return/^(y|yes)/i.test(r)?t=!0:/^(n|no)/i.test(r)&&(t=!1),t}c(Bs,"getBooleanValue");function Rn(r){return r?"Yes":"No"}c(Rn,"boolToString");var _n=Kc((r,e)=>{let t=Rn,[o,s]=$n("idle"),[i,n]=$n(""),a=Wc(),l=Xc({status:o,theme:a});zc((d,g)=>{if(qc(d)){let y=Bs(i,r.default);n(t(y)),s("done"),e(y);return}if(d.name==="tab"){let y=Rn(!Bs(i,r.default));g.clearLine(0),g.write(y),n(y);return}if(d.name==="y"||d.name==="n"){let y=Bs(d.name,r.default);n(t(y)),s("done"),e(y);return}g.clearLine(0),g.write(i),n(g.line)});let u=i,m="";o==="done"?u=a.style.answer(i):m=` ${a.style.defaultAnswer(r.default===!1?"y/N":"Y/n")}`;let f=a.style.message(r.message,o);return`${l} ${f}${m} ${u}`});var z=Re(async({message:r,default:e})=>await _n({message:r,default:e}));var om=c(r=>tm(r,dr),"getDeprecatedLocalConfigPath"),Gr=new Map;async function xe({cwd:r=xn.cwd(),migrateConfig:e=!0,warnAboutOldConfig:t=!0}={cwd:xn.cwd(),migrateConfig:!0,warnAboutOldConfig:!0}){let o=Gr.get(r);if(o)return C("useActorConfig",{cacheHit:!0,config:o}),Yr(o);let s=_s(r),i=om(r),n,a;try{n=de(s)}catch(u){return zt({message:`Failed to read local config at path: '${s}':`,cause:u,exists:!1,config:{}})}try{a=de(i)}catch(u){return zt({message:`Failed to read local config at path: '${i}':`,cause:u,exists:!1,config:{}})}if(n&&a&&t&&await sm(i),!n&&!a)return Gr.set(r,{exists:!1,migrated:!1,config:{}}),Yr({exists:!1,migrated:!1,config:{}});let l=!1;if(!n&&a&&e){let u=await nm(a,i,s);if(u.isErr())return zt(u.unwrapErr());n=u.unwrap(),l=!0}return Gr.set(r,{exists:!0,migrated:l,config:n||a||{}}),C("useActorConfig",{cacheHit:!1,config:Gr.get(r)}),Yr({exists:!0,migrated:l,config:n||a||{}})}c(xe,"useActorConfig");async function sm(r){if(!await z({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 On(r,`${r}.deprecated`),v({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(t){t instanceof Error?p({message:`Failed to rename the deprecated "apify.json" file to "apify.json.deprecated".
43
43
  ${t.message||t}`}):p({message:`Failed to rename the deprecated "apify.json" file to "apify.json.deprecated".
44
- ${Zc(t,{showHidden:!1})}`})}}c(eu,"handleBothConfigVersionsFound");var tu=["name","version","buildTag"];async function ru(r,e,t){let o={...r};if(typeof o.version=="object"&&(o=ou(o)),o={actorSpecification:ys,environmentVariables:r?.env||void 0,...tu.reduce((i,n)=>(i[n]=r[n],i),{})},!await z({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 qt({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 qc(zc(t),{recursive:!0}),await Wc(t,JSON.stringify(o,null," "))}catch(i){let n=i;return qt({message:`Failed to write the new "actor.json" file to path: '${t}'.
45
- ${n.message||n}`,exists:!0,config:o})}try{await $n(e,`${e}.deprecated`)}catch(i){let n=i;x({message:`Failed to rename the deprecated "apify.json" file to "apify.json.deprecated".
46
- ${n.message||n}`})}return v({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.'}),Br(o)}c(ru,"handleMigrationFlow");function ou(r){let e={name:r.name,template:r.template,version:r.version.versionNumber,buildTag:r.version.buildTag,env:null};if(r.version.envVars?.length){let t={};r.version.envVars.forEach(o=>{o.name&&o.value&&(t[o.name]=o.value)}),e.env=t}return e}c(ou,"updateLocalConfigStructure");var au=su(ue("default"),"INPUT.json"),gt=class extends h{static name="calculate-memory";static description="Calculates the Actor\u2019s dynamic memory usage based on a memory expression from actor.json, input data, and run options.";static flags={input:w.string({description:"Path to the input JSON file used for the calculation.",required:!1,default:au}),defaultMemoryMbytes:w.string({description:"Memory-calculation expression (in MB). If omitted, the value is loaded from the actor.json file.",required:!1}),build:w.string({description:"Actor build version or build tag to evaluate the expression with.",required:!1}),timeoutSecs:w.integer({description:"Maximum run timeout, in seconds.",required:!1}),maxItems:w.integer({description:"Maximum number of items Actor can output.",required:!1}),maxTotalChargeUsd:w.integer({description:"Maximum total charge in USD.",required:!1})};async run(){let{input:e,memoryExpression:t,minMemory:o,maxMemory:s,runOptions:i}=await this.prepareMemoryArguments();if(!t)throw new Error("No memory-calculation expression found. Provide it via the --default-memory-mbytes flag or define defaultMemoryMbytes in actor.json.");let n=iu(Us.cwd(),e),a=de(n)??{};v({message:`Evaluating memory expression: ${t}`});try{let l=await nu(t,{input:a,runOptions:i}),m=Math.min(Math.max(l,o),s);$({message:`Calculated memory: ${m} MB`,stdout:!0})}catch(l){p({message:`Memory calculation failed: ${l.message}`})}}async prepareMemoryArguments(){let{input:e,defaultMemoryMbytes:t,...o}=this.flags,s=t,i=0,n=1/0;return s||({defaultMemoryMbytes:s,minMemoryMbytes:i=i,maxMemoryMbytes:n=n}=await this.getExpressionFromConfig()),{memoryExpression:s,minMemory:i,maxMemory:n,input:e,runOptions:o}}async getExpressionFromConfig(){let e=Us.cwd(),t=await xe({cwd:e});if(t.isErr()){let{message:s,cause:i}=t.unwrapErr();return p({message:`${s}${i?`
47
- ${i.message}`:""}`}),Us.exitCode=5,{}}let{config:o}=t.unwrap();return{defaultMemoryMbytes:o?.defaultMemoryMbytes?.toString(),minMemoryMbytes:o?.minMemoryMbytes,maxMemoryMbytes:o?.maxMemoryMbytes}}};import{APIFY_ENV_VARS as fu}from"@apify/consts";import Wt from"process";import{pipeline as lu}from"stream/promises";import{MemoryStorage as cu}from"@crawlee/memory-storage";import{ApifyClient as uu}from"apify-client";import{ACTOR_ENV_VARS as Rn,APIFY_ENV_VARS as _n,KEY_VALUE_STORE_KEYS as mu,LOCAL_ACTOR_ENV_VARS as du}from"@apify/consts";var zt={KEY_VALUE_STORE:"KEY_VALUE_STORE",DATASET:"DATASET",REQUEST_QUEUE:"REQUEST_QUEUE"},js=c(async()=>{let r=Wt.env[_n.TOKEN];if(r)return r;let e=await M();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"),nt=c(async(r={},e=Reflect.has(Wt.env,_n.IS_AT_HOME))=>{let t=me();if(t&&!e)return new cu({localDataDirectory:t,...r});let o=await js();return new uu({...Cs(o),...r})},"getApifyStorageClient"),Xt=c(r=>{let e=Rn[`DEFAULT_${r}_ID`];return Wt.env[e]||du[e]},"getDefaultStorageId"),Vs=c(async r=>{let e=await nt(),t=Xt(zt.KEY_VALUE_STORE),o=await e.keyValueStore(t).getRecord(r,{stream:!0});o&&await lu(o.value,Wt.stdout,{end:!1})},"outputRecordFromDefaultStore"),xn=c(async()=>Vs(Wt.env[Rn.INPUT_KEY]||mu.INPUT),"outputInputFromDefaultStore");function pu(r){return{argTag:"string",required:r.required??!1,stdin:r.stdin??1,description:r.description,aliases:r.aliases,catchAll:r.catchAll??!1}}c(pu,"stringArg");var A={string:pu};var ht=class extends h{static name="charge";static description="Charge for a specific event in the pay-per-event Actor run.";static args={eventName:A.string({description:"Name of the event to charge for",required:!0})};static flags={count:w.integer({description:"Number of events to charge",required:!1,default:1}),"idempotency-key":w.string({description:"Idempotency key for the charge request",required:!1}),"test-pay-per-event":w.boolean({description:"Test pay-per-event charging without actually charging",required:!1,default:!1})};async run(){let{eventName:e}=this.args,{count:t,testPayPerEvent:o,idempotencyKey:s}=this.flags;if(!!!process.env.APIFY_IS_AT_HOME){v({message:`No platform detected: would charge ${t} events of type "${e}" with idempotency key "${s??"not-provided"}".`,stdout:!0});return}if(o){v({message:`PPE test mode: would charge ${t} events of type "${e}" with idempotency key "${s??"not-provided"}".`,stdout:!0});return}let n=await js(),a=await Dt(n);if(!a)throw new Error("Apify token is not set. Please set it using the environment variable APIFY_TOKEN.");let l=process.env[fu.ACTOR_RUN_ID];if(!l)throw new Error("Charge command must be executed in a running Actor. Run ID not found.");if((await a.run(l).get())?.pricingInfo?.pricingModel!=="PAY_PER_EVENT")throw new Error("Charge command can only be used with pay-per-event pricing model.");v({message:`Charging ${t} events of type "${e}" with idempotency key "${s??"not-provided"}" (runId: ${l}).`,stdout:!0}),await a.run(l).charge({eventName:e,count:t,idempotencyKey:s})}};var yt=class extends h{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 xn()}};import{ACTOR_ENV_VARS as Bs,APIFY_ENV_VARS as gu}from"@apify/consts";var wt=class extends h{static name="get-public-url";static description="Get an HTTP URL that allows public access to a key-value store item.";static args={key:A.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[gu.IS_AT_HOME])){p({message:"get-public-url is not yet implemented for local development"}),process.exitCode=255;return}let t=process.env[Bs.DEFAULT_KEY_VALUE_STORE_ID];if(!t){p({message:`Missing environment variable: ${Bs.DEFAULT_KEY_VALUE_STORE_ID}. Please set it before running the command.`}),process.exitCode=5;return}let o=await nt();if(!await o.keyValueStore(t).get()){p({message:`Key-Value store with ID '${t}' was not found. Ensure the store exists and that the correct ID is set in ${Bs.DEFAULT_KEY_VALUE_STORE_ID}.`}),process.exitCode=250;return}let i=await o.keyValueStore(t).getRecordPublicUrl(e);console.log(i)}};var At=class extends h{static name="get-value";static description="Gets a value from the default key-value store associated with the Actor run.";static args={key:A.string({required:!0,description:"Key of the record in key-value store"})};async run(){let{key:e}=this.args;await Vs(e)}};var bt=class extends h{static name="push-data";static description=`Saves data to Actor's run default dataset.
44
+ ${rm(t,{showHidden:!1})}`})}}c(sm,"handleBothConfigVersionsFound");var im=["name","version","buildTag"];async function nm(r,e,t){let o={...r};if(typeof o.version=="object"&&(o=am(o)),o={actorSpecification:Ss,environmentVariables:r?.env||void 0,...im.reduce((i,n)=>(i[n]=r[n],i),{})},!await z({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 zt({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 Zc(em(t),{recursive:!0}),await Qc(t,JSON.stringify(o,null," "))}catch(i){let n=i;return zt({message:`Failed to write the new "actor.json" file to path: '${t}'.
45
+ ${n.message||n}`,exists:!0,config:o})}try{await On(e,`${e}.deprecated`)}catch(i){let n=i;x({message:`Failed to rename the deprecated "apify.json" file to "apify.json.deprecated".
46
+ ${n.message||n}`})}return v({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.'}),Yr(o)}c(nm,"handleMigrationFlow");function am(r){let e={name:r.name,template:r.template,version:r.version.versionNumber,buildTag:r.version.buildTag,env:null};if(r.version.envVars?.length){let t={};r.version.envVars.forEach(o=>{o.name&&o.value&&(t[o.name]=o.value)}),e.env=t}return e}c(am,"updateLocalConfigStructure");var um=lm(me("default"),"INPUT.json"),gt=class extends h{static name="calculate-memory";static description="Calculates the Actor\u2019s dynamic memory usage based on a memory expression from actor.json, input data, and run options.";static flags={input:w.string({description:"Path to the input JSON file used for the calculation.",required:!1,default:um}),defaultMemoryMbytes:w.string({description:"Memory-calculation expression (in MB). If omitted, the value is loaded from the actor.json file.",required:!1}),build:w.string({description:"Actor build version or build tag to evaluate the expression with.",required:!1}),timeoutSecs:w.integer({description:"Maximum run timeout, in seconds.",required:!1}),maxItems:w.integer({description:"Maximum number of items Actor can output.",required:!1}),maxTotalChargeUsd:w.integer({description:"Maximum total charge in USD.",required:!1})};async run(){let{input:e,memoryExpression:t,minMemory:o,maxMemory:s,runOptions:i}=await this.prepareMemoryArguments();if(!t)throw new Error("No memory-calculation expression found. Provide it via the --default-memory-mbytes flag or define defaultMemoryMbytes in actor.json.");let n=cm(Gs.cwd(),e),a=de(n)??{};v({message:`Evaluating memory expression: ${t}`});try{let l=await mm(t,{input:a,runOptions:i}),u=Math.min(Math.max(l,o),s);R({message:`Calculated memory: ${u} MB`,stdout:!0})}catch(l){p({message:`Memory calculation failed: ${l.message}`})}}async prepareMemoryArguments(){let{input:e,defaultMemoryMbytes:t,...o}=this.flags,s=t,i=0,n=1/0;return s||({defaultMemoryMbytes:s,minMemoryMbytes:i=i,maxMemoryMbytes:n=n}=await this.getExpressionFromConfig()),{memoryExpression:s,minMemory:i,maxMemory:n,input:e,runOptions:o}}async getExpressionFromConfig(){let e=Gs.cwd(),t=await xe({cwd:e});if(t.isErr()){let{message:s,cause:i}=t.unwrapErr();return p({message:`${s}${i?`
47
+ ${i.message}`:""}`}),Gs.exitCode=5,{}}let{config:o}=t.unwrap();return{defaultMemoryMbytes:o?.defaultMemoryMbytes?.toString(),minMemoryMbytes:o?.minMemoryMbytes,maxMemoryMbytes:o?.maxMemoryMbytes}}};import{APIFY_ENV_VARS as wm}from"@apify/consts";import Xt from"process";import{pipeline as dm}from"stream/promises";import{MemoryStorage as pm}from"@crawlee/memory-storage";import{ApifyClient as fm}from"apify-client";import{ACTOR_ENV_VARS as Nn,APIFY_ENV_VARS as Pn,KEY_VALUE_STORE_KEYS as gm,LOCAL_ACTOR_ENV_VARS as hm}from"@apify/consts";var Zt={KEY_VALUE_STORE:"KEY_VALUE_STORE",DATASET:"DATASET",REQUEST_QUEUE:"REQUEST_QUEUE"},Ys=c(async()=>{let r=Xt.env[Pn.TOKEN];if(r)return r;let e=await F();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"),nt=c(async(r={},e=Reflect.has(Xt.env,Pn.IS_AT_HOME))=>{let t=ue();if(t&&!e)return new pm({localDataDirectory:t,...r});let o=await Ys();return new fm({...Rs(o),...r})},"getApifyStorageClient"),Qt=c(r=>{let e=Nn[`DEFAULT_${r}_ID`];return Xt.env[e]||hm[e]},"getDefaultStorageId"),Hs=c(async r=>{let e=await nt(),t=Qt(Zt.KEY_VALUE_STORE),o=await e.keyValueStore(t).getRecord(r,{stream:!0});o&&await dm(o.value,Xt.stdout,{end:!1})},"outputRecordFromDefaultStore"),Ln=c(async()=>Hs(Xt.env[Nn.INPUT_KEY]||gm.INPUT),"outputInputFromDefaultStore");function ym(r){return{argTag:"string",required:r.required??!1,stdin:r.stdin??1,description:r.description,aliases:r.aliases,catchAll:r.catchAll??!1}}c(ym,"stringArg");var A={string:ym};var ht=class extends h{static name="charge";static description="Charge for a specific event in the pay-per-event Actor run.";static args={eventName:A.string({description:"Name of the event to charge for",required:!0})};static flags={count:w.integer({description:"Number of events to charge",required:!1,default:1}),"idempotency-key":w.string({description:"Idempotency key for the charge request",required:!1}),"test-pay-per-event":w.boolean({description:"Test pay-per-event charging without actually charging",required:!1,default:!1})};async run(){let{eventName:e}=this.args,{count:t,testPayPerEvent:o,idempotencyKey:s}=this.flags;if(!!!process.env.APIFY_IS_AT_HOME){v({message:`No platform detected: would charge ${t} events of type "${e}" with idempotency key "${s??"not-provided"}".`,stdout:!0});return}if(o){v({message:`PPE test mode: would charge ${t} events of type "${e}" with idempotency key "${s??"not-provided"}".`,stdout:!0});return}let n=await Ys(),a=await Mt(n);if(!a)throw new Error("Apify token is not set. Please set it using the environment variable APIFY_TOKEN.");let l=process.env[wm.ACTOR_RUN_ID];if(!l)throw new Error("Charge command must be executed in a running Actor. Run ID not found.");if((await a.run(l).get())?.pricingInfo?.pricingModel!=="PAY_PER_EVENT")throw new Error("Charge command can only be used with pay-per-event pricing model.");v({message:`Charging ${t} events of type "${e}" with idempotency key "${s??"not-provided"}" (runId: ${l}).`,stdout:!0}),await a.run(l).charge({eventName:e,count:t,idempotencyKey:s})}};var yt=class extends h{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 Ln()}};import{ACTOR_ENV_VARS as Js,APIFY_ENV_VARS as Am}from"@apify/consts";var wt=class extends h{static name="get-public-url";static description="Get an HTTP URL that allows public access to a key-value store item.";static args={key:A.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[Am.IS_AT_HOME])){p({message:"get-public-url is not yet implemented for local development"}),process.exitCode=255;return}let t=process.env[Js.DEFAULT_KEY_VALUE_STORE_ID];if(!t){p({message:`Missing environment variable: ${Js.DEFAULT_KEY_VALUE_STORE_ID}. Please set it before running the command.`}),process.exitCode=5;return}let o=await nt();if(!await o.keyValueStore(t).get()){p({message:`Key-Value store with ID '${t}' was not found. Ensure the store exists and that the correct ID is set in ${Js.DEFAULT_KEY_VALUE_STORE_ID}.`}),process.exitCode=250;return}let i=await o.keyValueStore(t).getRecordPublicUrl(e);console.log(i)}};var At=class extends h{static name="get-value";static description="Gets a value from the default key-value store associated with the Actor run.";static args={key:A.string({required:!0,description:"Key of the record in key-value store"})};async run(){let{key:e}=this.args;await Hs(e)}};var bt=class extends h{static name="push-data";static description=`Saves data to Actor's run default dataset.
48
48
 
49
49
  Accept input as:
50
50
  - JSON argument:
51
51
  $ apify actor push-data {"key": "value"}
52
52
  - Piped stdin:
53
- $ cat ./test.json | apify actor push-data`;static args={item:A.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,t=e||Ce;if(!t){p({message:"No item was provided."});return}let o=await nt(),s=Xt(zt.DATASET),i;try{i=JSON.parse(t.toString("utf8"))}catch(n){throw new Error(`Failed to parse data as JSON string: ${n.message}`)}await o.dataset(s).pushItems(i)}};var St=class extends h{static name="set-value";static description=`Sets or removes record into the default key-value store associated with the Actor run.
53
+ $ cat ./test.json | apify actor push-data`;static args={item:A.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,t=e||Ce;if(!t){p({message:"No item was provided."});return}let o=await nt(),s=Qt(Zt.DATASET),i;try{i=JSON.parse(t.toString("utf8"))}catch(n){throw new Error(`Failed to parse data as JSON string: ${n.message}`)}await o.dataset(s).pushItems(i)}};var St=class extends h{static name="set-value";static description=`Sets or removes record into the default key-value store associated with the Actor run.
54
54
 
55
55
  It is possible to pass data using argument or stdin.
56
56
 
@@ -61,54 +61,58 @@ Passing data using stdin with pipe:
61
61
  $ cat ./my-text-file.txt | apify actor set-value KEY --contentType text/plain`;static args={key:A.string({required:!0,description:"Key of the record in key-value store."}),value:A.string({required:!1,description:`Record data, which can be one of the following values:
62
62
  - If empty, the record in the key-value store is deleted.
63
63
  - If no \`contentType\` flag is specified, value is expected to be any JSON string value.
64
- - If options.contentType is set, value is taken as is.`})};static flags={contentType:w.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:t}=this.args,{contentType:o="application/json; charset=utf-8"}=this.flags,s=t||process.stdin,n=(await nt()).keyValueStore(Xt(zt.KEY_VALUE_STORE));s==null||s===""||s==="null"||s==="undefined"?await n.deleteRecord(e):await n.setRecord({key:e,value:s,contentType:o})}};var Gr=class extends h{static name="actor";static description="Manages runtime data operations inside of a running Actor.";static subcommands=[St,bt,At,wt,yt,ht,gt];async run(){this.printHelp()}};import Oe from"chalk";import hu from"process";async function Ye({providedActorNameOrId:r,client:e}){let t=await M(),o=t.username||t.id,s=Me(hu.cwd())||{};if(r?.includes("/")){let i=await e.actor(r).get();return i?{valid:!0,userFriendlyId:`${i.username}/${i.name}`,id:i.id}:{valid:!1,reason:`Actor with ID "${r}" was not found`}}if(r){let i=await e.actor(r).get();if(i)return{valid:!0,userFriendlyId:`${i.username}/${i.name}`,id:i.id};let n=await e.actor(`${o}/${r.toLowerCase()}`).get();return n?{valid:!0,userFriendlyId:`${n.username}/${n.name}`,id:n.id}:{valid:!1,reason:`Actor with name or ID "${r}" 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"}}c(Ye,"resolveActorContext");var vt=class extends h{static name="create";static description="Creates a new build of the Actor.";static flags={tag:w.string({description:'Build tag to be applied to the successful Actor build. By default, this is "latest".'}),version:w.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:w.boolean({description:"Whether to print out the build log after the build is triggered."})};static args={actorId:A.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:t,json:o,log:s}=this.flags,{actorId:i}=this.args,n=await I(),a=await Ye({providedActorNameOrId:i,client:n});if(!a.valid){p({message:`${a.reason}. Please run this command in an Actor directory, or specify the Actor ID.`,stdout:!0});return}let l=await n.actor(a.id).get(),u=Ar(l.versions,T=>T.buildTag??"latest")[e??"latest"],f=l.versions.find(T=>T.versionNumber===t),d,g=e;if(f){if(e&&(!u||!u.some(T=>T.versionNumber===t))){p({message:`The Actor Version "${t}" does not have the tag "${e}".`,stdout:!0});return}d=t,g=f.buildTag??"latest"}else if(u&&(d=u[0].versionNumber,g=e??"latest",u.length>1&&!t)){p({message:`Multiple Actor versions with the tag "${e}" found. Please specify the version number using the "--version" flag.
65
- Available versions for this tag: ${u.map(T=>Oe.yellow(T.versionNumber)).join(", ")}`,stdout:!0});return}if(!d){p({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 n.actor(a.id).build(d,{tag:e});if(o){k(y);return}let b=[`${Oe.yellow("Actor")}: ${l?.username?`${l.username}/`:""}${l?.name??"unknown-actor"} (${Oe.gray(y.actId)})`,` ${Oe.yellow("Version")}: ${d} (tagged with ${Oe.yellow(g)})`,"",`${Oe.greenBright("Build Started")} (ID: ${Oe.gray(y.id)})`,` ${Oe.yellow("Build Number")}: ${y.buildNumber} (will get tagged once finished)`,` ${Oe.yellow("Started")}: ${B.display(y.startedAt)}`,""],S=`https://console.apify.com/actors/${y.actId}/builds/${y.buildNumber}`,E=`${Oe.blue("View in Apify Console")}: ${S}`;if(R({message:b.join(`
66
- `),stdout:!0}),s){try{await $e({job:y,apifyClient:n})}catch(T){p({message:`Failed to print log for build with ID "${y.id}": ${T.message}`,stdout:!0})}R({message:"",stdout:!0})}R({message:E,stdout:!0})}};var Yr=class extends vt{static name="build"};import Ln from"process";import{DownloadItemsFormat as Su}from"apify-client";import re from"chalk";import{access as yu,readFile as wu}from"fs/promises";import Au,{resolve as On}from"path";import Ne from"process";import bu from"mime";function Nn(r,e){let t,o;if(e)t=e,o="application/json";else{let s=Ft(r);s&&(bu.getExtension(s.contentType)==="json"?(t=JSON.parse(s.body.toString("utf8")),o="application/json"):(t=s.body,o=s.contentType))}return!t||!o?null:{inputToUse:t,contentType:o}}c(Nn,"resolveInput");async function Tt(r,e,t){let o,s;if(!e&&!t){let i=Ce;if(i)try{let n=JSON.parse(i.toString("utf8"));if(Array.isArray(n))return p({message:"The provided input is invalid. It should be an object, not an array."}),Ne.exitCode=5,!1;o=n,s="stdin"}catch(n){return p({message:`Cannot parse JSON input from standard input.
67
- ${n.message}`}),Ne.exitCode=5,!1}}if(e)switch(e[0]){case"-":return p({message:"You need to pipe something into standard input when you specify the `-` value to `--input`."}),Ne.exitCode=5,!1;default:{let i=await yu(On(r,e)).then(()=>!0).catch(()=>!1),n=e.endsWith(".json")||e.endsWith(".json5")||Au.isAbsolute(e)||e.startsWith("./")||e.startsWith("../")||e.includes("~")||e.startsWith(".\\")||e.startsWith("..\\");if(i||n)return p({message:'Providing a JSON file path in the --input flag is not supported. Use the "--input-file=" flag instead'}),Ne.exitCode=5,!1;try{let a=JSON.parse(e);if(Array.isArray(a))return p({message:"The provided input is invalid. It should be an object, not an array."}),Ne.exitCode=5,!1;o=a,s="input"}catch(a){return p({message:`Cannot parse JSON input.
68
- ${a.message}`}),Ne.exitCode=5,!1}}}else if(t)switch(t[0]){case"-":return p({message:"You need to pipe something into standard input when you specify the `-` value to `--input-file`."}),Ne.exitCode=5,!1;default:{let i=On(r,t),n;try{let a=await wu(i,"utf8"),l=JSON.parse(a);if(Array.isArray(l))return p({message:"The provided input is invalid. It should be an object, not an array."}),Ne.exitCode=5,!1;o=l,s=t}catch(a){n=a}if(n)try{let a=JSON.parse(t);if(Array.isArray(a))return p({message:"The provided input is invalid. It should be an object, not an array."}),Ne.exitCode=5,!1;o=a,s=t}catch{return p({message:`Cannot read input file at path "${i}".
69
- ${n.message}`}),Ne.exitCode=5,!1}}}return o?{input:o,source:s}:void 0}c(Tt,"getInputOverride");import Gs from"process";import Hr from"chalk";import{ACTOR_JOB_STATUSES as He}from"@apify/consts";var Pn=[He.SUCCEEDED,He.ABORTED,He.FAILED,He.TIMED_OUT];async function*Ct(r,e){let t=Gs.cwd(),{actorOrTaskData:o,runOptions:s,type:i,waitForFinishMillis:n,inputOverride:a,silent:l,waitForRunToFinish:m,printRunLogs:u}=e,f=i==="Actor"?"actor":"task",d=Nn(t,a);l||(i==="Actor"?Ae({message:`Calling ${i} ${o.userFriendlyId} (${Hr.gray(o.id)})
70
- `}):o.title?Ae({message:`Calling ${i} ${o.title} (${o.userFriendlyId}, ${Hr.gray(o.id)})
71
- `}):Ae({message:`Calling ${i} ${o.userFriendlyId} (${Hr.gray(o.id)})
72
- `}));let g;try{d&&i==="Actor"?g=await r[f](o.id).start(d.inputToUse,{...s,contentType:d.contentType}):g=await r[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 g,!l&&u)try{await $e({job:g,timeoutMillis:n,apifyClient:r})==="timeouts"?console.error(`
73
- ${Hr.gray("Timeout for printing logs was hit, there may be future logs.")}
74
- `):console.error()}catch(y){x({message:"Can not get log:"}),console.error(y)}if(g=await r.run(g.id).get(),m)for(;!Pn.includes(g.status)&&(g=await r.run(g.id).get(),!Pn.includes(g.status));)await new Promise(y=>{setTimeout(y,1e3)});l||(g.status===He.SUCCEEDED?$({message:`${i} finished.`}):g.status===He.RUNNING?x({message:`${i} is still running!`}):g.status===He.ABORTED||g.status===He.ABORTING?(x({message:`${i} was aborted!`}),Gs.exitCode=3):(p({message:`${i} failed!`}),Gs.exitCode=1)),yield g}c(Ct,"runActorOrTaskOnCloud");var It=c(r=>({build:w.string({char:"b",description:'Tag or number of the build to run (e.g. "latest" or "1.2.34").',required:!1}),timeout:w.integer({char:"t",description:`Timeout for the ${r} run in seconds. Zero value means there is no timeout.`,required:!1}),memory:w.integer({char:"m",description:`Amount of memory allocated for the ${r} run, in megabytes.`,required:!1})}),"SharedRunOnCloudFlags");var Je=class r extends h{static name="call";static description=`Executes Actor remotely using your authenticated account.
75
- Reads input from local key-value store by default.`;static flags={...It("Actor"),input:w.string({char:"i",description:"Optional JSON input to be given to the Actor.",required:!1,stdin:2,exclusive:["input-file"]}),"input-file":w.string({char:"f",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:w.boolean({char:"s",description:"Prevents printing the logs of the Actor run to the console.",default:!1}),"output-dataset":w.boolean({char:"o",description:"Prints out the entire default dataset on successful run of the Actor."})};static enableJsonFlag=!0;static args={actorId:A.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 '${V}' file.`})};async run(){let e=Ln.cwd(),t=Me(e)||{},o=await I(),s=await M(),i=s.username||s.id;if(this.flags.json&&this.flags.outputDataset){p({message:"You cannot use both the --json and --output-dataset flags when running this command."}),Ln.exitCode=5;return}let{id:n,userFriendlyId:a,actorData:l}=await r.resolveActorId({client:o,localActorName:t.name,usernameOrId:i,providedActorNameOrId:this.args.actorId}),m={waitForFinish:2};this.flags.build&&(m.build=this.flags.build),this.flags.timeout&&(m.timeout=this.flags.timeout),this.flags.memory&&(m.memory=this.flags.memory);let u=await Tt(e,this.flags.input,this.flags.inputFile);if(u===!1)return;let f=!1,d,g,y,b=Ct(o,{actorOrTaskData:{id:n,userFriendlyId:a},runOptions:m,type:"Actor",inputOverride:u?.input,silent:this.flags.silent,waitForRunToFinish:!0,printRunLogs:!0});for await(let S of b)if(d=S,!f&&(f=!0,!this.flags.silent)){g=`https://console.apify.com/actors/${n}/runs/${S.id}`,y=`https://console.apify.com/storage/datasets/${S.defaultDatasetId}`;let E=[`${re.yellow("Started")}: ${B.display(S.startedAt)}`];S.containerUrl&&E.push(`${re.yellow("Container URL")}: ${re.blue(S.containerUrl)}`);let T=d.buildNumber.split(".").slice(0,2).join("."),N=l.versions.find(D=>D.versionNumber===T),P=Object.entries(l.taggedBuilds??{}).find(([,D])=>D.buildNumber===S.buildNumber)?.[0],L=[`${re.yellow("Build")}:`,re.cyan(d.buildNumber)];P?L.push(`(${re.yellow(P)})`):L.push(`(${re.gray("N/A")})`),N&&L.push(`| ${re.gray("Actor version:")} ${re.cyan(N.versionNumber)} (${re.yellow(N.buildTag)})`),E.push(L.join(" ")),E.push(`${re.yellow("Timeout")}: ${d.options.timeoutSecs.toLocaleString("en-US")} seconds`),E.push(`${re.yellow("Memory")}: ${d.options.memoryMbytes} MB`),E.push(`${re.blue("View on Apify Console")}: ${g}`,""),R({message:E.join(`
76
- `),stdout:!this.flags.json})}if(this.flags.json){k(d);return}if(this.flags.silent||R({message:["",`${re.blue("Export results")}: ${y}`,`${re.blue("View on Apify Console")}: ${g}`].join(`
77
- `),stdout:!0}),this.flags.outputDataset){let S=d.defaultDatasetId,E,T=4;do{if(E=await o.dataset(S).get(),E?.itemCount)break;await new Promise(P=>{setTimeout(P,250)})}while(T--);let N=await o.dataset(S).downloadItems(Su.JSON,{clean:!0});console.log(N.toString())}}static async resolveActorId({client:e,localActorName:t,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 n=await e.actor(`${o}/${s.toLowerCase()}`).get();if(n)return{userFriendlyId:`${n.username}/${n.name}`,id:n.id,actorData:n};throw new Error(`Cannot find Actor with name or ID '${s}' in your account.`)}if(t){let i=await e.actor(`${o}/${t}`).get();if(!i)throw new Error(`Cannot find Actor with ID '${o}/${t}' 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 vu from"cli-table3";var Tu={mid:"","left-mid":"","mid-mid":"","right-mid":"",middle:" ","top-mid":"\u2500","bottom-mid":"\u2500"},Cu={middle:" ","top-mid":"\u2500","bottom-mid":"\u2500",top:"\u2500",bottom:"\u2500","left-mid":"\u251C",mid:"\u2500","mid-mid":"\u2500","right-mid":"\u2524"},Iu={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 Eu={[-1]:void 0,0:Tu,1:Cu,2:Iu};function $u(r){return Array.from({length:r},()=>"cyan")}c($u,"generateHeaderColors");var Ru=process.stdout.columns??100,Jr=Symbol.for("@apify/cli:responsive-table:skip-column"),G=class r{static{c(this,"ResponsiveTable")}options;rows=[];constructor(e){this.options=e}pushRow(e){this.rows.push(e)}render(e){let t=r.isSmallTerminal()?this.options.mandatoryColumns:this.options.allColumns,o=$u(t.length),s=e===0||e===2,i=Eu[e],n=[],a=[],l=[];for(let u of t)this.options.hiddenColumns?.includes(u)||this.rows.some(f=>f[u]===Jr)||(n.push(this.options.columnAlignments?.[u]||"left"),r.isSmallTerminal()?(a.push(this.options.breakpointOverrides?.small?.[u]?.label??u),l.push(this.options.breakpointOverrides?.small?.[u]?.valueFrom??u)):(a.push(u),l.push(u)));let m=new vu({head:a,style:{head:o,compact:s},colAligns:n,chars:i});for(let u of this.rows){let f=l.map(d=>u[d]);m.push(f)}return m.toString()}static isSmallTerminal(){return Ru<100}};var Kr="\u200B",qr="\u200B\u200B",kn=new G({allColumns:[Kr,qr],mandatoryColumns:[Kr,qr],columnAlignments:{[Kr]:"left",[qr]:"right"}}),Wr=class extends h{static name="info";static description="Get information about an Actor.";static flags={readme:w.boolean({description:"Return the Actor README.",exclusive:["input"]}),input:w.boolean({description:"Return the Actor input schema.",exclusive:["readme"]})};static args={actorId:A.string({description:"The ID of the Actor to return information about.",required:!0})};static enableJsonFlag=!0;async run(){let{actorId:e}=this.args,{readme:t,input:o,json:s}=this.flags,i=await I(),n=await Ye({providedActorNameOrId:e,client:i});if(!n.valid){p({message:`${n.reason}. Please specify the Actor ID.`,stdout:!0});return}let a=await i.actor(n.id).get(),l=await i.user(a.userId).get();a.actorMaker=l;for(let d of Object.values(a.taggedBuilds??{})){if(!d.buildId)continue;let g=await i.build(d.buildId).get();d.build=g}if(s){k(a);return}let m=a.taggedBuilds?.latest;if(t){if(!m){p({message:"No README found for this Actor.",stdout:!0});return}if(!m.build?.readme){p({message:"No README found for this Actor.",stdout:!0});return}R({message:m.build.readme,stdout:!0})}if(o){if(!m){p({message:"No input schema found for this Actor.",stdout:!0});return}if(!m.build?.inputSchema){p({message:"No input schema found for this Actor.",stdout:!0});return}R({message:m.build.inputSchema,stdout:!0})}let u=[`Information about Actor ${O.yellow(`${a.username}/${a.name}`)} (${O.gray(a.id)})`,""];a.title&&u.push(`${O.yellow("Title:")} ${O.bold(a.title)}`),a.description&&u.push(`${O.yellow("Description:")} ${a.description}`),u.push(`${O.yellow("Created at:")} ${O.cyan(B.display(a.createdAt))} ${O.gray("|")} ${O.yellow("Updated at:")} ${O.cyan(B.display(a.modifiedAt))}`),a.actorMaker&&(u.push("",`${O.yellow("Made by:")} ${O.cyan(a.actorMaker.profile.name??a.actorMaker.username)}`),Reflect.get(a,"isCritical")&&(u[u.length-1]+=` ${O.bgGray("Maintained by Apify")}`)),a.isPublic?u.push("",`${O.yellow("Actor is")} ${O.green("PUBLIC")}`):u.push("",`${O.yellow("Actor is")} ${O.cyan("PRIVATE")}`),a.isDeprecated&&u.push("",`${O.yellow("Actor is")} ${O.red("DEPRECATED")}`);let f=Reflect.get(a,"pricingInfos");if(f?.length){let d=f.at(-1);switch(d.pricingModel){case"FLAT_PRICE_PER_MONTH":{if(u.push(`${O.yellow("Pricing information:")} ${O.bgGray(`$${d.pricePerUnitUsd}/month + usage`)}`),d.trialMinutes){let g=d.trialMinutes*60*1e3,y=jt.format(g);u.push(` ${O.yellow("Trial duration:")} ${O.bold(y)}`)}break}case"PRICE_PER_DATASET_ITEM":{let g=d.pricePerUnitUsd*1e3;u.push(`${O.yellow("Pricing information:")} ${O.bgGray(`$${g.toFixed(2)} / 1,000 results`)}`);break}case"PAY_PER_EVENT":{u.push(`${O.yellow("Pricing information:")} ${O.bgGray("Pay per event")}`);let g=Object.values(d.pricingPerEvent?.actorChargeEvents??{});for(let S of g)kn.pushRow({[Kr]:S.eventTitle,[qr]:O.bold(`$${S.eventPriceUsd.toFixed(2)}`)});let b=kn.render(0).split(`
78
- `);b.splice(1,1),u.push(b.join(`
79
- `));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(d.pricingModel)})`)}`)}}else u.push(`${O.yellow("Pricing information:")} ${O.bgGray("Pay for usage")}`);if((a.seoTitle||a.seoDescription)&&(u.push("",O.yellow("SEO information:")),a.seoTitle&&u.push(` ${O.yellow("Title:")} ${a.seoTitle}`),a.seoDescription&&u.push(` ${O.yellow("Description:")} ${a.seoDescription}`)),a.taggedBuilds){u.push("",O.yellow("Builds:"));let d=a.taggedBuilds.latest;d&&u.push(` ${O.yellow("-")} ${O.cyan(d.buildNumber)} ${O.gray("/")} ${O.yellow("latest")}`);for(let[g,y]of Object.entries(a.taggedBuilds))g!=="latest"&&u.push(` ${O.yellow("-")} ${O.cyan(y.buildNumber)} ${O.gray("/")} ${O.yellow(g)}`)}R({message:u.join(`
80
- `),stdout:!0})}};import{Time as _u}from"@sapphire/duration";import W from"chalk";import ke from"chalk";function Ee(r){switch(r){case"READY":return ke.green("Ready");case"RUNNING":return ke.blue("Running");case"SUCCEEDED":return ke.green("Succeeded");case"FAILED":return ke.red("Failed");case"ABORTING":return ke.yellow("Aborting");case"ABORTED":return ke.red("Aborted");case"TIMING-OUT":return ke.yellow("Timing Out");case"TIMED-OUT":return ke.red("Timed Out");default:return ke.gray(r.split("-").map(e=>e[0].toUpperCase()+e.slice(1).toLowerCase()).join(" "))}}c(Ee,"prettyPrintStatus");var xu={"TIMED-OUT":W.gray("after"),"TIMING-OUT":W.gray("after"),ABORTED:W.gray("after"),ABORTING:W.gray("after"),FAILED:W.gray("after"),READY:W.gray("for"),RUNNING:W.gray("for"),SUCCEEDED:W.gray("after")},Ou=new G({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"}}}}),Nu=new G({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"}}}}),zr=class extends h{static name="ls";static description="Prints a list of recently executed Actors or Actors you own.";static flags={my:w.boolean({description:"Whether to list Actors made by the logged in user.",default:!1}),offset:w.integer({description:"Number of Actors that will be skipped.",default:0}),limit:w.integer({description:"Number of Actors that will be listed.",default:20}),desc:w.boolean({description:"Sort Actors in descending order.",default:!1})};static enableJsonFlag=!0;async run(){let{desc:e,limit:t,offset:o,my:s,json:i}=this.flags,n=await I(),a=await n.actors().list({limit:t,offset:o,desc:e,my:s});if(a.count===0){if(i){k(a);return}v({message:s?"You don't have any Actors yet!":"There are no recent Actors used by you.",stdout:!0});return}let l={...a,items:await Promise.all(a.items.map(async f=>{let d=await n.actor(f.id).get(),g=await n.actor(f.id).runs().list({desc:!0,limit:1}).catch(()=>({count:0,desc:!0,items:[],limit:1,offset:0,total:0}));return{...f,actor:d??null,lastRun:g.items[0]??null}}))};if(l.items=s?this.sortByModifiedAt(l.items):this.sortByLastRun(l.items),i){k(l);return}let m=s?Nu:Ou,u=l.items.reduce((f,d)=>{let g=`${d.username}/${d.name}`;return g.length>f?g.length:f},0)+2+6;for(let f of l.items){let d=f.stats.lastRunStartedAt?Ut.display(f.stats.lastRunStartedAt):"",g=f.lastRun?(()=>{if(f.lastRun.finishedAt)return se.format(f.lastRun.finishedAt.getTime()-f.lastRun.startedAt.getTime());let S=Date.now()-f.lastRun.startedAt.getTime();return`${se.format(S)}\u2026`})():"",y=f.actor?(()=>{let S=Object.entries(f.actor.taggedBuilds??{}).find(([E,T])=>T.buildNumber===f.actor.defaultRunOptions.build||E===f.actor.defaultRunOptions.build);return S?`${W.yellow(S[0])} / ${W.cyan(S[1].buildNumber??f.actor.defaultRunOptions.build)}`:W.gray("Unknown")})():W.gray("Unknown"),b=(()=>{if(f.lastRun){let E=[Ee(f.lastRun.status)];if(g&&E.push(xu[f.lastRun.status],W.cyan(g)),f.lastRun.finishedAt){let T=Date.now()-f.lastRun.finishedAt.getTime();T<_u.Week?E.push(`
81
- `,W.gray(`${se.format(T)} ago`)):E.push(`
82
- `,W.gray("On",Fi.display(f.lastRun.finishedAt)))}return E.join(" ")}return""})();m.pushRow({Name:`${f.title}
83
- ${W.gray(`${f.username}/${f.name}`)}`,Runs:G.isSmallTerminal()&&u>=56?Jr:W.cyan(`${f.stats?.totalRuns??0}`),"Last run started at":d,"Last run":d,"Last run status":f.lastRun?Ee(f.lastRun.status):"","Modified at":Ut.display(f.modifiedAt),Builds:f.actor?W.cyan(f.actor.stats.totalBuilds):W.gray("Unknown"),"Last run duration":G.isSmallTerminal()?Jr:W.cyan(g),"Default build":y,_Small_LastRunText:b})}R({message:m.render(1),stdout:!0})}sortByModifiedAt(e){return e.sort((t,o)=>{let s=new Date(t.modifiedAt);return new Date(o.modifiedAt).getTime()-s.getTime()})}sortByLastRun(e){return e.sort((t,o)=>{let s=new Date(t.stats?.lastRunStartedAt??"1970-01-01T00:00Z");return new Date(o.stats?.lastRunStartedAt??"1970-01-01T00:00Z").getTime()-s.getTime()})}};import{mkdirSync as Dn,readdirSync as Pu,writeFileSync as Fn}from"fs";import{dirname as Lu,join as ku}from"path";import Mn from"process";import Du from"adm-zip";import Fu from"axios";import Un from"jju";import{gt as Mu}from"semver";import Uu from"tiged";var jn=c(async(r,e)=>{let{data:t}=await Fu.get(r,{responseType:"arraybuffer"}),o=new Du(Buffer.from(t,"binary"));o.extractEntryTo(o.getEntries()[0].entryName,e,!1)},"extractGitHubZip"),Et=class extends h{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:w.string({char:"v",description:"Actor version number which will be pulled, e.g. 1.2. Default: the highest version",required:!1}),dir:w.string({description:"Directory where the Actor should be pulled to",required:!1})};static args={actorId:A.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=Mn.cwd(),t=await xe({cwd:e});if(t.isErr()){p({message:t.unwrapErr().message}),Mn.exitCode=5;return}let{config:o}=t.unwrap(),s=await M(),i=await I(),n=!this.args.actorId,a=s.username||s.id,l=this.args?.actorId||o?.id||(o?.name?`${a}/${o.name}`:void 0);if(!l)throw new Error("Cannot find Actor in this directory.");let m;try{m=await i.actor(l).get()}catch{throw new Error(`Cannot find Actor with ID/name '${l}' in your account.`)}if(!m)throw new Error(`Cannot find Actor with ID/name '${l}' in your account.`);let{name:u,versions:f}=m,d=c(()=>{throw new Error("You cannot pull source code of this Actor because you do not have permission to do so.")},"throwMissingSourceCodeAccessError");if(!m.versions.length)throw new Error(`Actor ${l} has no versions.`);let g=null;if(this.flags.version&&(g=f.find(b=>b.versionNumber===this.flags.version),!g))throw new Error(`Cannot find version ${this.flags.version} of Actor ${l}.`);g||(g=f.reduce((b,S)=>Mu(`${S.versionNumber}.0`,`${b.versionNumber}.0`)?S:b));let y=n?e:ku(e,this.flags.dir??u);if(Dn(y,{recursive:!0}),!n&&Pu(y).length!==0){p({message:`Directory ${y} is not empty. Please empty it or choose another directory.`});return}switch(g.sourceType){case"TARBALL":{g.tarballUrl||d(),await jn(g.tarballUrl,y);break}case"SOURCE_FILES":{g.sourceFiles||d();let{sourceFiles:b}=g;for(let S of b){let E=Lu(S.name);if(Dn(`${y}/${E}`,{recursive:!0}),!S.folder){let T=S.format==="BASE64"?Buffer.from(S.content,"base64").toString():S.content;if(S.name===V){let N=Un.parse(T);N.name=m.name,Fn(`${y}/${S.name}`,Un.update(T,N))}else Fn(`${y}/${S.name}`,T)}}break}case"GIT_REPO":{g.gitRepoUrl||d();let{gitRepoUrl:b}=g,[S,E]=b.split("#"),T,N;E&&([T,N]=E.split(":"));let P=S;N&&(P+=`/${N}`),T&&(P+=`#${T}`);let L=Uu(P);try{await L.clone(y)}catch(D){throw new Error(`Failed to pull Actor from ${b}. ${D.message}`)}break}case"GITHUB_GIST":{g.gitHubGistUrl||d(),await jn(`${g.gitHubGistUrl}/archive/master.zip`,y);break}default:throw new Error(`Unknown source type: ${g.sourceType}`)}$({message:n?`Actor ${u} updated at ${y}/`:`Pulled to ${y}/`})}};import{readFileSync as Bu,statSync as Gu,unlinkSync as Yu}from"fs";import{join as Hu,resolve as Ju}from"path";import at from"process";import Ku from"open";import{fetchManifest as qu}from"@apify/actor-templates";import{ACTOR_JOB_STATUSES as lt,ACTOR_SOURCE_TYPES as Hs,MAX_MULTIFILE_BYTES as Wn}from"@apify/consts";import{createHmacSignature as Wu}from"@apify/utilities";import{readFileSync as ju,writeFileSync as Vu}from"fs";var Ys="@",Vn=100,Bn=5e4,$t=c(()=>{try{return JSON.parse(ju(ar(),"utf-8"))||{}}catch{return{}}},"getSecretsFile"),Gn=c(r=>(Es(ar()),Vu(ar(),JSON.stringify(r,null," ")),r),"writeSecretsFile"),Yn=c((r,e)=>{let t=$t();if(t[r])throw new Error(`Secret with name ${r} already exists. Call "apify secrets rm ${r}" to remove it.`);if(typeof r!="string"||r.length>Vn)throw new Error(`Secret name has to be string with maximum length ${Vn}.`);if(typeof e!="string"||e.length>Bn)throw new Error(`Secret value has to be string with maximum length ${Bn}.`);return t[r]=e,Gn(t)},"addSecret"),Hn=c(r=>{let e=$t();if(!e[r])throw new Error(`Secret with name ${r} doesn't exist.`);delete e[r],Gn(e)},"removeSecret"),Jn=c(r=>new RegExp(`^${Ys}.{1}`).test(r),"isSecretKey"),Kn=c((r,e)=>{e=e||$t();let t={};return Object.keys(r).forEach(o=>{if(Jn(r[o])){let s=r[o].replace(new RegExp(`^${Ys}`),"");e[s]?t[o]=e[s]:x({message:`Value for ${s} not found in local secrets. Set it by calling "apify secrets add ${s} [SECRET_VALUE]"`})}else t[o]=r[o]}),t},"replaceSecretsValue"),qn=c((r,e)=>{e=e||$t();let t=[];return Object.keys(r).forEach(o=>{if(Jn(r[o])){let s=r[o].replace(new RegExp(`^${Ys}`),"");e[s]?t.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 t.push({name:o,value:r[o]})}),t},"transformEnvToEnvVars");var Js="temp_file.zip",zu={build:"latest",memoryMbytes:4096,timeoutSecs:3600},zn="0.0",Xu="latest",Rt=class extends h{static name="push";static description=`Deploys Actor to Apify platform using settings from '${V}'.
84
- Files under '${Wn/1024**2}' MB upload as "Multiple source files"; larger projects upload as ZIP file.
85
- Use --force to override newer remote versions.`;static flags={version:w.string({char:"v",description:`Actor version number to which the files should be pushed. By default, it is taken from the '${V}' file.`,required:!1}),"build-tag":w.string({char:"b",description:`Build tag to be applied to the successful Actor build. By default, it is taken from the '${V}' file`,required:!1}),"wait-for-finish":w.string({char:"w",description:"Seconds for waiting to build to finish, if no value passed, it waits forever.",required:!1}),open:w.boolean({description:"Whether to open the browser automatically to the Actor details page.",default:!1,required:!1}),force:w.boolean({char:"f",description:"Push an Actor even when the local files are older than the Actor on the platform.",default:!1,required:!1}),dir:w.string({description:"Directory where the Actor is located",required:!1})};static args={actorId:A.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 '${V}' file.`})};async run(){let e=Ju(at.cwd(),this.flags.dir??"."),t=await xi(e);if(!t.length){p({message:"You need to call this command from a folder that has an Actor in it!"}),at.exitCode=4;return}if(![ur,"actor.json",".actor/actor.json",".actor"].some(F=>t.some(Q=>Q===F||Q.startsWith(F)))){p({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(`
86
- `)}),at.exitCode=4;return}let o=await I(),s=await xe({cwd:e});if(s.isErr()){p({message:s.unwrapErr().message}),at.exitCode=5;return}let{config:i}=s.unwrap(),n=await M(),l=!!n.organizationOwnerUserId?`/organization/${n.id}`:"",m,u,f=!1,d=this.flags.version||i?.version||zn,g=this.flags.buildTag||i?.buildTag;!g&&d===zn&&(g=Xu);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.`);m=u.id}else{let F=n.username||n.id;if(u=await o.actor(`${F}/${i.name}`).get(),u)m=u.id;else{let{templates:Q}=await qu(),we=Q.find(ir=>ir.name===i.template)?.defaultRunOptions||zu,_t={name:i.name,title:i.title,description:i.description,defaultRunOptions:we,versions:[{versionNumber:d,buildTag:g,sourceType:Hs.SOURCE_FILES,sourceFiles:[]}]};u=await o.actors().create(_t),m=u.id,f=!0,v({message:`Created Actor with name ${i.name} on Apify.`})}}let S=o.actor(m);v({message:`Deploying Actor '${i.name}' to Apify.`});let E=await yi(t,e),T,N,P;if(E<Wn){let F=await S.get();if(!f){let Q=t.reduce((we,_t)=>{let{mtimeMs:ir,ctimeMs:li}=Gu(Hu(e,_t)),ci=ir>li?ir:li;return we>ci?we:ci},0),ye=F?.modifiedAt.valueOf();if(!this.flags.force&&ye&&Q<ye&&(i?.name||b))throw new Error(`Actor with identifier "${i?.name||b}" is already on the platform and was modified there since modified locally.
87
- Skipping push. Use --force to override.`)}N=await _i(t,e),T=Hs.SOURCE_FILES}else{Ae({message:"Zipping Actor files"}),await Oi(Js,t,e);let F=await o.keyValueStores().getOrCreate(`actor-${m}-source`),Q=`version-${d}.zip`,ye=Bu(Js);await o.keyValueStore(F.id).setRecord({key:Q,value:ye,contentType:"application/zip"}),Yu(Js);let we=new URL(`${o.baseUrl}/key-value-stores/${F.id}/records/${Q}?disableRedirect=true`);if(F?.urlSigningSecretKey){let _t=Wu(F.urlSigningSecretKey,Q);we.searchParams.set("signature",_t)}P=we.toString(),T=Hs.TARBALL}let L=await S.version(d).get(),D=i.environmentVariables?qn(i.environmentVariables):void 0;if(L){let F={tarballUrl:P,sourceFiles:N,buildTag:g,sourceType:T,envVars:D};await S.version(d).update(F),Ae({message:`Updated version ${d} for Actor ${u.name}.`})}else{let F={versionNumber:d,tarballUrl:P,sourceFiles:N,buildTag:g,sourceType:T,envVars:D};await S.versions().create({...F}),Ae({message:`Created version ${d} for Actor ${u.name}.`})}Ae({message:`Building Actor ${u.name}`});let J=await S.build(d,{useCache:!0,waitForFinish:2});try{await $e({job:J,timeoutMillis:y,apifyClient:o})}catch(F){x({message:"Can not get log:"}),console.error(F)}J=await o.build(J.id).get(),fs({message:"Actor build detail",url:`https://console.apify.com${l}/actors/${J.actId}#/builds/${J.buildNumber}`}),fs({message:"Actor detail",url:`https://console.apify.com${l}/actors/${J.actId}`}),this.flags.open&&await Ku(`https://console.apify.com${l}/actors/${J.actId}`),J.status===lt.SUCCEEDED?$({message:"Actor was deployed to Apify cloud and built there."}):J.status===lt.READY?x({message:"Build is waiting for allocation."}):J.status===lt.RUNNING?x({message:"Build is still running."}):J.status===lt.ABORTED||J.status===lt.ABORTING?(x({message:"Build was aborted!"}),at.exitCode=3):J.status===lt.TIMED_OUT||J.status===lt.TIMING_OUT?(x({message:"Build timed out!"}),at.exitCode=2):(p({message:"Build failed!"}),at.exitCode=1)}};var Xr=class extends h{static name="rm";static description="Permanently removes an Actor from your account.";static args={actorId:A.string({description:"The Actor ID to delete.",required:!0})};async run(){let{actorId:e}=this.args,t=await I();if(!await t.actor(e).get()){p({message:`Actor with ID "${e}" was not found on your account.`});return}if(!await z({message:"Are you sure you want to delete this Actor?"})){v({message:`Deletion of Actor "${e}" was canceled.`});return}try{await t.actor(e).delete(),$({message:`Actor with ID "${e}" was deleted.`})}catch(i){let n=i;p({message:`Failed to delete Actor "${e}".
88
- ${n.message||n}`})}}};import ee from"chalk";var Zr=class extends h{static name="start";static description=`Starts Actor remotely and returns run details immediately.
89
- Uses authenticated account and local key-value store for input.`;static flags={...It("Actor"),input:w.string({char:"i",description:"Optional JSON input to be given to the Actor.",required:!1,stdin:2,exclusive:["input-file"]}),"input-file":w.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:A.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 '${V}' file.`})};async run(){let e=process.cwd(),t=Me(e)||{},o=await I(),s=await M(),i=s.username||s.id,{id:n,userFriendlyId:a,actorData:l}=await Je.resolveActorId({client:o,localActorName:t.name,usernameOrId:i,providedActorNameOrId:this.args.actorId}),m={};this.flags.build&&(m.build=this.flags.build),this.flags.timeout&&(m.timeout=this.flags.timeout),this.flags.memory&&(m.memory=this.flags.memory);let u=await Tt(e,this.flags.input,this.flags.inputFile);if(u===!1)return;let f=Ct(o,{actorOrTaskData:{id:n,userFriendlyId:a},runOptions:m,type:"Actor",inputOverride:u?.input,silent:!0,waitForRunToFinish:!1,printRunLogs:!1}),d;for await(let P of f)d=P;if(this.flags.json){k(d);return}let g=`https://console.apify.com/actors/${n}/runs/${d.id}`,y=`https://console.apify.com/storage/datasets/${d.defaultDatasetId}`,b=[`${ee.gray("Run:")} Calling Actor ${a} (${ee.gray(n)})`,"",`${ee.yellow("Started")}: ${B.display(d.startedAt)}`];d.containerUrl&&b.push(`${ee.yellow("Container URL")}: ${ee.blue(d.containerUrl)}`);let S=d.buildNumber.split(".").slice(0,2).join("."),E=l.versions.find(P=>P.versionNumber===S),T=Object.entries(l.taggedBuilds??{}).find(([,P])=>P.buildNumber===d.buildNumber)?.[0],N=[`${ee.yellow("Build")}:`,ee.cyan(d.buildNumber)];T?N.push(`(${ee.yellow(T)})`):N.push(`(${ee.gray("N/A")})`),E&&N.push(`| ${ee.gray("Actor version:")} ${ee.cyan(E.versionNumber)} (${ee.yellow(E.buildTag)})`),b.push(N.join(" ")),b.push(`${ee.yellow("Timeout")}: ${d.options.timeoutSecs.toLocaleString("en-US")} seconds`),b.push(`${ee.yellow("Memory")}: ${d.options.memoryMbytes} MB`),b.push("",`${ee.blue("Export results")}: ${y}`,`${ee.blue("View on Apify Console")}: ${g}`),R({message:b.join(`
90
- `),stdout:!0})}};var Qr=class extends h{static name="actors";static description="Manages Actor creation, deployment, and execution on the Apify platform.";static subcommands=[Zr,Xr,Rt,Et,zr,Wr,Je,Yr];async run(){this.printHelp()}};import Z from"chalk";var Zu=c(r=>r,"noColor");function X({bytes:r,shortBytes:e=!1,colorFunc:t=Zu,precision:o=2}){let s=[e?"B":"Bytes","KB","MB","GB","TB"];if(r===0)return e?`${0 .toPrecision(o)} B`:`${0 .toPrecision(o)} Byte`;let i=Math.floor(Math.log(r)/Math.log(1e3));return`${(r/1e3**i).toFixed(o)} ${t(s[i])}`}c(X,"prettyPrintBytes");var eo=class extends h{static name="info";static description="Prints information about a specific build.";static args={buildId:A.string({required:!0,description:"The build ID to get information about."})};static enableJsonFlag=!0;async run(){let{buildId:e}=this.args,t=await I(),o=await t.build(e).get();if(!o){p({message:`Build with ID "${e}" was not found on your account.`,stdout:!0});return}if(this.flags.json){k(o);return}let s=await t.actor(o.actId).get(),i;if(s?.taggedBuilds){for(let[g,y]of Object.entries(s.taggedBuilds))if(y.buildId===o.id){i=g;break}}let n=Reflect.get(o,"exitCode"),a=s?.username?`${s.username}/${s.name}`:s?.name??"unknown-actor",l=i?` (tagged as ${Z.yellow(i)})`:"",m=typeof n<"u"?` (exit code: ${Z.gray(n)})`:"",u=[`${Z.yellow("Actor")}: ${a} (${Z.gray(o.actId)})`,"",`${Z.yellow("Build Information")} (ID: ${Z.gray(o.id)})`,` ${Z.yellow("Build Number")}: ${o.buildNumber}${l}`,` ${Z.yellow("Status")}: ${Ee(o.status)}${m}`,` ${Z.yellow("Started")}: ${B.display(o.startedAt)}`];if(o.finishedAt)u.push(` ${Z.yellow("Finished")}: ${B.display(o.finishedAt)} (took ${Z.gray(jt.format(o.stats?.durationMillis??0))})`);else{let g=Date.now()-o.startedAt.getTime();u.push(` ${Z.yellow("Finished")}: ${Z.gray(`Running for ${jt.format(g)}`)}`)}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")}: ${X({bytes:f})}`),u.push(` ${Z.yellow("Origin")}: ${o.meta.origin??"UNKNOWN"}`),u.push("");let d=`https://console.apify.com/actors/${o.actId}/builds/${o.buildNumber}`;u.push(`${Z.blue("View in Apify Console")}: ${d}`),R({message:u.join(`
91
- `),stdout:!0})}};var to=class extends h{static name="log";static description="Prints the log of a specific build.";static args={buildId:A.string({required:!0,description:"The build ID to get the log from."})};async run(){let{buildId:e}=this.args,t=await I(),o=await t.build(e).get();if(!o){p({message:`Build with ID "${e}" was not found on your account.`,stdout:!0});return}v({message:`Log for build with ID "${e}":
92
- `});try{await $e({job:o,apifyClient:t})}catch(s){p({message:`Failed to get log for build with ID "${e}": ${s.message}`,stdout:!0})}}};import fe from"chalk";var Qu=c(()=>new G({allColumns:["Number","ID","Status","Took"],mandatoryColumns:["Number","ID","Status","Took"],columnAlignments:{Took:"right"}}),"tableFactory"),ro=class extends h{static name="ls";static description="Lists all builds of the Actor.";static flags={offset:w.integer({description:"Number of builds that will be skipped.",default:0}),limit:w.integer({description:"Number of builds that will be listed.",default:10}),desc:w.boolean({description:"Sort builds in descending order.",default:!1}),compact:w.boolean({description:"Display a compact table.",default:!1,char:"c"})};static args={actorId:A.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:t,offset:o,compact:s,json:i}=this.flags,{actorId:n}=this.args,a=await I(),l=await Ye({providedActorNameOrId:n,client:a});if(!l.valid){p({message:`${l.reason}. Please run this command in an Actor directory, or specify the Actor ID.`,stdout:!0});return}let m=await a.actor(l.id).builds().list({desc:e,limit:t,offset:o}),u=await a.actor(l.id).get(),f=Ar(m.items,y=>{let b=Reflect.get(y,"buildNumber"),[S,E]=b.split(".");return`${S}.${E}`}),d=Object.entries(u.taggedBuilds??{}).reduce((y,[b,S])=>(y[S.buildNumber]=b,y),{});if(i){for(let y of m.items){let b=Reflect.get(y,"buildNumber"),S=d[b];S&&Reflect.set(y,"buildTag",S)}k(m);return}R({message:`${fe.reset("Showing")} ${fe.yellow(m.items.length)} out of ${fe.yellow(m.total)} builds for Actor ${fe.yellow(l.userFriendlyId)} (${fe.gray(l.id)})
93
- `,stdout:!0});let g=Object.entries(f).sort((y,b)=>y[0].localeCompare(b[0]));for(let[y,b]of g){if(!b?.length){R({message:`No builds for version ${y}`,stdout:!0});continue}let S=u.versions.find(P=>P.versionNumber===y)?.buildTag,E=this.generateTableForActorVersion({buildsForVersion:b,buildTagToActorVersion:d}),T=S?` (latest build gets tagged with ${fe.yellow(S)})`:"",N=[fe.reset(`Builds for Actor Version ${fe.yellow(y)}${T}`),E.render(s?0:-1),""];R({message:N.join(`
94
- `),stdout:!0})}}generateTableForActorVersion({buildsForVersion:e,buildTagToActorVersion:t}){let o=Qu();for(let s of e){let i=Reflect.get(s,"buildNumber"),n=t[i]?` (${fe.yellow(t[i])})`:"",a;if(s.finishedAt){let l=s.finishedAt.getTime()-s.startedAt.getTime();a=fe.gray(`${se.format(l,void 0,{left:""})}`)}else{let l=Date.now()-s.startedAt.getTime();a=fe.gray(`Running for ${se.format(l,void 0,{left:""})}`)}o.pushRow({Number:`${i}${n}`,ID:fe.gray(s.id),Status:Ee(s.status),Took:a})}return o}};import em from"@inquirer/input";var Xn=Re(async({message:r,expectedValue:e,failureMessage:t})=>await em({message:r,validate(s){return s===e?!0:t??"That is not the correct input!"}}));var oo=class extends h{static name="rm";static description="Permanently removes an Actor build from the Apify platform.";static args={buildId:A.string({description:"The build ID to delete.",required:!0})};async run(){let{buildId:e}=this.args,t=await I(),o=await t.build(e).get();if(!o){p({message:`Build with ID "${e}" was not found on your account.`,stdout:!0});return}let s=await t.actor(o.actId).get(),i;if(s?.taggedBuilds){for(let[a,l]of Object.entries(s.taggedBuilds))if(e===l.buildId){i=a;break}}if(!await(i?Xn:z)({message:`Are you sure you want to delete this Actor Build?${i?` If so, please type in "${i}":`:""}`,expectedValue:i??"",failureMessage:"Your provided value does not match the build tag."})){v({message:`Deletion of build "${e}" was canceled.`,stdout:!0});return}try{await t.build(e).delete(),$({message:`Build with ID "${e}" was deleted.`,stdout:!0})}catch(a){let l=a;p({message:`Failed to delete build "${e}".
95
- ${l.message||l}`,stdout:!0})}}};var so=class extends h{static name="builds";static description="Manages Actor build processes and versioning.";static subcommands=[oo,ro,to,eo,vt];async run(){this.printHelp()}};var io=class extends Je{static name="call"};import tm from"assert";import{existsSync as no}from"fs";import{mkdir as rm,readFile as om,symlink as sm,unlink as im,writeFile as Zn}from"fs/promises";import{basename as nm,join as ge}from"path";import Ke from"chalk";var am=c(r=>ge(r,".install-marker"),"pathToInstallMarker"),Zt=class extends h{static name="install";static description="Finalizes the first-time setup of Apify and Actor CLI.";static hidden=!0;async run(){let{installMethod:e,installPath:t,version:o}=K();if(e!=="bundle"){v({message:"Apify and Actor CLI are already fully configured! \u{1F44D}"});return}tm(t,"When CLI is installed via bundles, the install path must be set");let s=am(t);if(no(s)){v({message:"Apify and Actor CLI are already fully configured! \u{1F44D}"});return}await this.symlinkToLocalBin(t),await this.promptAddToShell(),await Zn(s,o),C("[install] install marker written to",s),R({message:""}),$({message:"To get started, run:"}),R({message:Ke.white.bold(` apify --help
96
- actor --help`)})}async symlinkToLocalBin(e){let t=process.env.HOME;if(C("[install] user home directory",t),!t){C("[install] user home directory not found"),x({message:Ke.gray("User home directory not found, cannot symlink to ~/.local/bin")});return}let o=ge(t,".local","bin");no(o)||await rm(o,{recursive:!0});let s=["apify","actor","apify-cli"];for(let i of s){let n=ge(e,i);if(!no(n)){C("[install] file not found for symlinking",i,n),x({message:Ke.gray(`Bundle not found for symlinking: ${i}`)});continue}let a=ge(o,i);await im(a).catch(()=>{}),await sm(n,a),C("[install] symlink created for item",i,a)}v({message:Ke.gray(`Symlinked apify, actor, and apify-cli to ${o}`)})}async promptAddToShell(){let e=process.env.PROVIDED_INSTALL_DIR;if(!e){x({message:Ke.gray("Install directory not found, cannot add to shell")});return}let t=process.env.FINAL_BIN_DIR;R({message:""});let o=await z({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)",providedConfirmFromStdin:!1}),s=nm(process.env.SHELL??"sh"),i=`"${e.replaceAll('"','\\"')}"`,n=[],a="";switch(s){case"bash":{n.push(`export APIFY_CLI_INSTALL=${i}`),n.push('export PATH="$APIFY_CLI_INSTALL/bin:$PATH"');let l=[ge(process.env.HOME,".bashrc"),ge(process.env.HOME,".bash_profile")];process.env.XDG_CONFIG_HOME&&l.push(ge(process.env.XDG_CONFIG_HOME,".bashrc"),ge(process.env.XDG_CONFIG_HOME,".bash_profile"),ge(process.env.XDG_CONFIG_HOME,"bashrc"),ge(process.env.XDG_CONFIG_HOME,"bash_profile"));for(let m of l)if(no(m)){a=m;break}break}case"zsh":n.push(`export APIFY_CLI_INSTALL=${i}`),n.push('export PATH="$APIFY_CLI_INSTALL/bin:$PATH"'),a=ge(process.env.HOME,".zshrc");break;case"fish":{n.push(`set --export APIFY_CLI_INSTALL ${i}`),n.push(`set --export PATH ${t} $PATH`),a=ge(process.env.HOME,".config","fish","config.fish");break}default:n.push(`export APIFY_CLI_INSTALL=${i}`),n.push('export PATH="$APIFY_CLI_INSTALL/bin:$PATH"'),a="~/.bashrc";break}if(R({message:""}),o&&a){let m=`${await om(a,"utf-8")}
64
+ - If options.contentType is set, value is taken as is.`})};static flags={contentType:w.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:t}=this.args,{contentType:o="application/json; charset=utf-8"}=this.flags,s=t||process.stdin,n=(await nt()).keyValueStore(Qt(Zt.KEY_VALUE_STORE));s==null||s===""||s==="null"||s==="undefined"?await n.deleteRecord(e):await n.setRecord({key:e,value:s,contentType:o})}};var Hr=class extends h{static name="actor";static description="Manages runtime data operations inside of a running Actor.";static subcommands=[St,bt,At,wt,yt,ht,gt];async run(){this.printHelp()}};import Oe from"chalk";import bm from"process";async function Ye({providedActorNameOrId:r,client:e}){let t=await F(),o=t.username||t.id,s=Ue(bm.cwd())||{};if(r?.includes("/")){let i=await e.actor(r).get();return i?{valid:!0,userFriendlyId:`${i.username}/${i.name}`,id:i.id}:{valid:!1,reason:`Actor with ID "${r}" was not found`}}if(r){let i=await e.actor(r).get();if(i)return{valid:!0,userFriendlyId:`${i.username}/${i.name}`,id:i.id};let n=await e.actor(`${o}/${r.toLowerCase()}`).get();return n?{valid:!0,userFriendlyId:`${n.username}/${n.name}`,id:n.id}:{valid:!1,reason:`Actor with name or ID "${r}" 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"}}c(Ye,"resolveActorContext");var vt=class extends h{static name="create";static description="Creates a new build of the Actor.";static flags={tag:w.string({description:'Build tag to be applied to the successful Actor build. By default, this is "latest".'}),version:w.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:w.boolean({description:"Whether to print out the build log after the build is triggered."})};static args={actorId:A.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:t,json:o,log:s}=this.flags,{actorId:i}=this.args,n=await I(),a=await Ye({providedActorNameOrId:i,client:n});if(!a.valid){p({message:`${a.reason}. Please run this command in an Actor directory, or specify the Actor ID.`,stdout:!0});return}let l=await n.actor(a.id).get(),m=Sr(l.versions,T=>T.buildTag??"latest")[e??"latest"],f=l.versions.find(T=>T.versionNumber===t),d,g=e;if(f){if(e&&(!m||!m.some(T=>T.versionNumber===t))){p({message:`The Actor Version "${t}" does not have the tag "${e}".`,stdout:!0});return}d=t,g=f.buildTag??"latest"}else if(m&&(d=m[0].versionNumber,g=e??"latest",m.length>1&&!t)){p({message:`Multiple Actor versions with the tag "${e}" found. Please specify the version number using the "--version" flag.
65
+ Available versions for this tag: ${m.map(T=>Oe.yellow(T.versionNumber)).join(", ")}`,stdout:!0});return}if(!d){p({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 n.actor(a.id).build(d,{tag:e});if(o){k(y);return}let b=[`${Oe.yellow("Actor")}: ${l?.username?`${l.username}/`:""}${l?.name??"unknown-actor"} (${Oe.gray(y.actId)})`,` ${Oe.yellow("Version")}: ${d} (tagged with ${Oe.yellow(g)})`,"",`${Oe.greenBright("Build Started")} (ID: ${Oe.gray(y.id)})`,` ${Oe.yellow("Build Number")}: ${y.buildNumber} (will get tagged once finished)`,` ${Oe.yellow("Started")}: ${B.display(y.startedAt)}`,""],S=`https://console.apify.com/actors/${y.actId}/builds/${y.buildNumber}`,E=`${Oe.blue("View in Apify Console")}: ${S}`;if($({message:b.join(`
66
+ `),stdout:!0}),s){try{await $e({job:y,apifyClient:n})}catch(T){p({message:`Failed to print log for build with ID "${y.id}": ${T.message}`,stdout:!0})}$({message:"",stdout:!0})}$({message:E,stdout:!0})}};var Jr=class extends vt{static name="build"};import Mn from"process";import{DownloadItemsFormat as Im}from"apify-client";import re from"chalk";import{access as Sm,readFile as vm}from"fs/promises";import Tm,{resolve as kn}from"path";import Ne from"process";import Cm from"mime";function Dn(r,e){let t,o;if(e)t=e,o="application/json";else{let s=Ut(r);s&&(Cm.getExtension(s.contentType)==="json"?(t=JSON.parse(s.body.toString("utf8")),o="application/json"):(t=s.body,o=s.contentType))}return!t||!o?null:{inputToUse:t,contentType:o}}c(Dn,"resolveInput");async function Tt(r,e,t){let o,s;if(!e&&!t){let i=Ce;if(i)try{let n=JSON.parse(i.toString("utf8"));if(Array.isArray(n))return p({message:"The provided input is invalid. It should be an object, not an array."}),Ne.exitCode=5,!1;o=n,s="stdin"}catch(n){return p({message:`Cannot parse JSON input from standard input.
67
+ ${n.message}`}),Ne.exitCode=5,!1}}if(e)switch(e[0]){case"-":return p({message:"You need to pipe something into standard input when you specify the `-` value to `--input`."}),Ne.exitCode=5,!1;default:{let i=await Sm(kn(r,e)).then(()=>!0).catch(()=>!1),n=e.endsWith(".json")||e.endsWith(".json5")||Tm.isAbsolute(e)||e.startsWith("./")||e.startsWith("../")||e.includes("~")||e.startsWith(".\\")||e.startsWith("..\\");if(i||n)return p({message:'Providing a JSON file path in the --input flag is not supported. Use the "--input-file=" flag instead'}),Ne.exitCode=5,!1;try{let a=JSON.parse(e);if(Array.isArray(a))return p({message:"The provided input is invalid. It should be an object, not an array."}),Ne.exitCode=5,!1;o=a,s="input"}catch(a){return p({message:`Cannot parse JSON input.
68
+ ${a.message}`}),Ne.exitCode=5,!1}}}else if(t)switch(t[0]){case"-":return p({message:"You need to pipe something into standard input when you specify the `-` value to `--input-file`."}),Ne.exitCode=5,!1;default:{let i=kn(r,t),n;try{let a=await vm(i,"utf8"),l=JSON.parse(a);if(Array.isArray(l))return p({message:"The provided input is invalid. It should be an object, not an array."}),Ne.exitCode=5,!1;o=l,s=t}catch(a){n=a}if(n)try{let a=JSON.parse(t);if(Array.isArray(a))return p({message:"The provided input is invalid. It should be an object, not an array."}),Ne.exitCode=5,!1;o=a,s=t}catch{return p({message:`Cannot read input file at path "${i}".
69
+ ${n.message}`}),Ne.exitCode=5,!1}}}return o?{input:o,source:s}:void 0}c(Tt,"getInputOverride");import Ks from"process";import Kr from"chalk";import{ACTOR_JOB_STATUSES as He}from"@apify/consts";var Fn=[He.SUCCEEDED,He.ABORTED,He.FAILED,He.TIMED_OUT];async function*Ct(r,e){let t=Ks.cwd(),{actorOrTaskData:o,runOptions:s,type:i,waitForFinishMillis:n,inputOverride:a,silent:l,waitForRunToFinish:u,printRunLogs:m}=e,f=i==="Actor"?"actor":"task",d=Dn(t,a);l||(i==="Actor"?Ae({message:`Calling ${i} ${o.userFriendlyId} (${Kr.gray(o.id)})
70
+ `}):o.title?Ae({message:`Calling ${i} ${o.title} (${o.userFriendlyId}, ${Kr.gray(o.id)})
71
+ `}):Ae({message:`Calling ${i} ${o.userFriendlyId} (${Kr.gray(o.id)})
72
+ `}));let g;try{d&&i==="Actor"?g=await r[f](o.id).start(d.inputToUse,{...s,contentType:d.contentType}):g=await r[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 g,!l&&m)try{await $e({job:g,timeoutMillis:n,apifyClient:r})==="timeouts"?console.error(`
73
+ ${Kr.gray("Timeout for printing logs was hit, there may be future logs.")}
74
+ `):console.error()}catch(y){x({message:"Can not get log:"}),console.error(y)}if(g=await r.run(g.id).get(),u)for(;!Fn.includes(g.status)&&(g=await r.run(g.id).get(),!Fn.includes(g.status));)await new Promise(y=>{setTimeout(y,1e3)});l||(g.status===He.SUCCEEDED?R({message:`${i} finished.`}):g.status===He.RUNNING?x({message:`${i} is still running!`}):g.status===He.ABORTED||g.status===He.ABORTING?(x({message:`${i} was aborted!`}),Ks.exitCode=3):(p({message:`${i} failed!`}),Ks.exitCode=1)),yield g}c(Ct,"runActorOrTaskOnCloud");var It=c(r=>({build:w.string({char:"b",description:'Tag or number of the build to run (e.g. "latest" or "1.2.34").',required:!1}),timeout:w.integer({char:"t",description:`Timeout for the ${r} run in seconds. Zero value means there is no timeout.`,required:!1}),memory:w.integer({char:"m",description:`Amount of memory allocated for the ${r} run, in megabytes.`,required:!1})}),"SharedRunOnCloudFlags");var Je=class r extends h{static name="call";static description=`Executes Actor remotely using your authenticated account.
75
+ Reads input from local key-value store by default.`;static flags={...It("Actor"),input:w.string({char:"i",description:"Optional JSON input to be given to the Actor.",required:!1,stdin:2,exclusive:["input-file"]}),"input-file":w.string({char:"f",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:w.boolean({char:"s",description:"Prevents printing the logs of the Actor run to the console.",default:!1}),"output-dataset":w.boolean({char:"o",description:"Prints out the entire default dataset on successful run of the Actor."})};static enableJsonFlag=!0;static args={actorId:A.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 '${V}' file.`})};async run(){let e=Mn.cwd(),t=Ue(e)||{},o=await I(),s=await F(),i=s.username||s.id;if(this.flags.json&&this.flags.outputDataset){p({message:"You cannot use both the --json and --output-dataset flags when running this command."}),Mn.exitCode=5;return}let{id:n,userFriendlyId:a,actorData:l}=await r.resolveActorId({client:o,localActorName:t.name,usernameOrId:i,providedActorNameOrId:this.args.actorId}),u={waitForFinish:2};this.flags.build&&(u.build=this.flags.build),this.flags.timeout&&(u.timeout=this.flags.timeout),this.flags.memory&&(u.memory=this.flags.memory);let m=await Tt(e,this.flags.input,this.flags.inputFile);if(m===!1)return;let f=!1,d,g,y,b=Ct(o,{actorOrTaskData:{id:n,userFriendlyId:a},runOptions:u,type:"Actor",inputOverride:m?.input,silent:this.flags.silent,waitForRunToFinish:!0,printRunLogs:!0});for await(let S of b)if(d=S,!f&&(f=!0,!this.flags.silent)){g=`https://console.apify.com/actors/${n}/runs/${S.id}`,y=`https://console.apify.com/storage/datasets/${S.defaultDatasetId}`;let E=[`${re.yellow("Started")}: ${B.display(S.startedAt)}`];S.containerUrl&&E.push(`${re.yellow("Container URL")}: ${re.blue(S.containerUrl)}`);let T=d.buildNumber.split(".").slice(0,2).join("."),N=l.versions.find(D=>D.versionNumber===T),P=Object.entries(l.taggedBuilds??{}).find(([,D])=>D.buildNumber===S.buildNumber)?.[0],L=[`${re.yellow("Build")}:`,re.cyan(d.buildNumber)];P?L.push(`(${re.yellow(P)})`):L.push(`(${re.gray("N/A")})`),N&&L.push(`| ${re.gray("Actor version:")} ${re.cyan(N.versionNumber)} (${re.yellow(N.buildTag)})`),E.push(L.join(" ")),E.push(`${re.yellow("Timeout")}: ${d.options.timeoutSecs.toLocaleString("en-US")} seconds`),E.push(`${re.yellow("Memory")}: ${d.options.memoryMbytes} MB`),E.push(`${re.blue("View on Apify Console")}: ${g}`,""),$({message:E.join(`
76
+ `),stdout:!this.flags.json})}if(this.flags.json){k(d);return}if(this.flags.silent||$({message:["",`${re.blue("Export results")}: ${y}`,`${re.blue("View on Apify Console")}: ${g}`].join(`
77
+ `),stdout:!0}),this.flags.outputDataset){let S=d.defaultDatasetId,E,T=4;do{if(E=await o.dataset(S).get(),E?.itemCount)break;await new Promise(P=>{setTimeout(P,250)})}while(T--);let N=await o.dataset(S).downloadItems(Im.JSON,{clean:!0});console.log(N.toString())}}static async resolveActorId({client:e,localActorName:t,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 n=await e.actor(`${o}/${s.toLowerCase()}`).get();if(n)return{userFriendlyId:`${n.username}/${n.name}`,id:n.id,actorData:n};throw new Error(`Cannot find Actor with name or ID '${s}' in your account.`)}if(t){let i=await e.actor(`${o}/${t}`).get();if(!i)throw new Error(`Cannot find Actor with ID '${o}/${t}' 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 Em from"cli-table3";var $m={mid:"","left-mid":"","mid-mid":"","right-mid":"",middle:" ","top-mid":"\u2500","bottom-mid":"\u2500"},Rm={middle:" ","top-mid":"\u2500","bottom-mid":"\u2500",top:"\u2500",bottom:"\u2500","left-mid":"\u251C",mid:"\u2500","mid-mid":"\u2500","right-mid":"\u2524"},_m={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 xm={[-1]:void 0,0:$m,1:Rm,2:_m};function Om(r){return Array.from({length:r},()=>"cyan")}c(Om,"generateHeaderColors");var Nm=process.stdout.columns??100,qr=Symbol.for("@apify/cli:responsive-table:skip-column"),G=class r{static{c(this,"ResponsiveTable")}options;rows=[];constructor(e){this.options=e}pushRow(e){this.rows.push(e)}render(e){let t=r.isSmallTerminal()?this.options.mandatoryColumns:this.options.allColumns,o=Om(t.length),s=e===0||e===2,i=xm[e],n=[],a=[],l=[];for(let m of t)this.options.hiddenColumns?.includes(m)||this.rows.some(f=>f[m]===qr)||(n.push(this.options.columnAlignments?.[m]||"left"),r.isSmallTerminal()?(a.push(this.options.breakpointOverrides?.small?.[m]?.label??m),l.push(this.options.breakpointOverrides?.small?.[m]?.valueFrom??m)):(a.push(m),l.push(m)));let u=new Em({head:a,style:{head:o,compact:s},colAligns:n,chars:i});for(let m of this.rows){let f=l.map(d=>m[d]);u.push(f)}return u.toString()}static isSmallTerminal(){return Nm<100}};var Wr="\u200B",zr="\u200B\u200B",Un=new G({allColumns:[Wr,zr],mandatoryColumns:[Wr,zr],columnAlignments:{[Wr]:"left",[zr]:"right"}}),Xr=class extends h{static name="info";static description="Get information about an Actor.";static flags={readme:w.boolean({description:"Return the Actor README.",exclusive:["input"]}),input:w.boolean({description:"Return the Actor input schema.",exclusive:["readme"]})};static args={actorId:A.string({description:"The ID of the Actor to return information about.",required:!0})};static enableJsonFlag=!0;async run(){let{actorId:e}=this.args,{readme:t,input:o,json:s}=this.flags,i=await I(),n=await Ye({providedActorNameOrId:e,client:i});if(!n.valid){p({message:`${n.reason}. Please specify the Actor ID.`,stdout:!0});return}let a=await i.actor(n.id).get(),l=await i.user(a.userId).get();a.actorMaker=l;for(let d of Object.values(a.taggedBuilds??{})){if(!d.buildId)continue;let g=await i.build(d.buildId).get();d.build=g}if(s){k(a);return}let u=a.taggedBuilds?.latest;if(t){if(!u){p({message:"No README found for this Actor.",stdout:!0});return}if(!u.build?.readme){p({message:"No README found for this Actor.",stdout:!0});return}$({message:u.build.readme,stdout:!0})}if(o){if(!u){p({message:"No input schema found for this Actor.",stdout:!0});return}if(!u.build?.inputSchema){p({message:"No input schema found for this Actor.",stdout:!0});return}$({message:u.build.inputSchema,stdout:!0})}let m=[`Information about Actor ${O.yellow(`${a.username}/${a.name}`)} (${O.gray(a.id)})`,""];a.title&&m.push(`${O.yellow("Title:")} ${O.bold(a.title)}`),a.description&&m.push(`${O.yellow("Description:")} ${a.description}`),m.push(`${O.yellow("Created at:")} ${O.cyan(B.display(a.createdAt))} ${O.gray("|")} ${O.yellow("Updated at:")} ${O.cyan(B.display(a.modifiedAt))}`),a.actorMaker&&(m.push("",`${O.yellow("Made by:")} ${O.cyan(a.actorMaker.profile.name??a.actorMaker.username)}`),Reflect.get(a,"isCritical")&&(m[m.length-1]+=` ${O.bgGray("Maintained by Apify")}`)),a.isPublic?m.push("",`${O.yellow("Actor is")} ${O.green("PUBLIC")}`):m.push("",`${O.yellow("Actor is")} ${O.cyan("PRIVATE")}`),a.isDeprecated&&m.push("",`${O.yellow("Actor is")} ${O.red("DEPRECATED")}`);let f=Reflect.get(a,"pricingInfos");if(f?.length){let d=f.at(-1);switch(d.pricingModel){case"FLAT_PRICE_PER_MONTH":{if(m.push(`${O.yellow("Pricing information:")} ${O.bgGray(`$${d.pricePerUnitUsd}/month + usage`)}`),d.trialMinutes){let g=d.trialMinutes*60*1e3,y=Bt.format(g);m.push(` ${O.yellow("Trial duration:")} ${O.bold(y)}`)}break}case"PRICE_PER_DATASET_ITEM":{let g=d.pricePerUnitUsd*1e3;m.push(`${O.yellow("Pricing information:")} ${O.bgGray(`$${g.toFixed(2)} / 1,000 results`)}`);break}case"PAY_PER_EVENT":{m.push(`${O.yellow("Pricing information:")} ${O.bgGray("Pay per event")}`);let g=Object.values(d.pricingPerEvent?.actorChargeEvents??{});for(let S of g)Un.pushRow({[Wr]:S.eventTitle,[zr]:O.bold(`$${S.eventPriceUsd.toFixed(2)}`)});let b=Un.render(0).split(`
78
+ `);b.splice(1,1),m.push(b.join(`
79
+ `));break}case"FREE":{m.push(`${O.yellow("Pricing information:")} ${O.bgGray("Pay for usage")}`);break}default:m.push(`${O.yellow("Pricing information:")} ${O.bgGray(`Unknown pricing model (${O.yellow(d.pricingModel)})`)}`)}}else m.push(`${O.yellow("Pricing information:")} ${O.bgGray("Pay for usage")}`);if((a.seoTitle||a.seoDescription)&&(m.push("",O.yellow("SEO information:")),a.seoTitle&&m.push(` ${O.yellow("Title:")} ${a.seoTitle}`),a.seoDescription&&m.push(` ${O.yellow("Description:")} ${a.seoDescription}`)),a.taggedBuilds){m.push("",O.yellow("Builds:"));let d=a.taggedBuilds.latest;d&&m.push(` ${O.yellow("-")} ${O.cyan(d.buildNumber)} ${O.gray("/")} ${O.yellow("latest")}`);for(let[g,y]of Object.entries(a.taggedBuilds))g!=="latest"&&m.push(` ${O.yellow("-")} ${O.cyan(y.buildNumber)} ${O.gray("/")} ${O.yellow(g)}`)}$({message:m.join(`
80
+ `),stdout:!0})}};import{Time as Pm}from"@sapphire/duration";import W from"chalk";import De from"chalk";function Ee(r){switch(r){case"READY":return De.green("Ready");case"RUNNING":return De.blue("Running");case"SUCCEEDED":return De.green("Succeeded");case"FAILED":return De.red("Failed");case"ABORTING":return De.yellow("Aborting");case"ABORTED":return De.red("Aborted");case"TIMING-OUT":return De.yellow("Timing Out");case"TIMED-OUT":return De.red("Timed Out");default:return De.gray(r.split("-").map(e=>e[0].toUpperCase()+e.slice(1).toLowerCase()).join(" "))}}c(Ee,"prettyPrintStatus");var Lm={"TIMED-OUT":W.gray("after"),"TIMING-OUT":W.gray("after"),ABORTED:W.gray("after"),ABORTING:W.gray("after"),FAILED:W.gray("after"),READY:W.gray("for"),RUNNING:W.gray("for"),SUCCEEDED:W.gray("after")},km=new G({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"}}}}),Dm=new G({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"}}}}),Zr=class extends h{static name="ls";static description="Prints a list of recently executed Actors or Actors you own.";static flags={my:w.boolean({description:"Whether to list Actors made by the logged in user.",default:!1}),offset:w.integer({description:"Number of Actors that will be skipped.",default:0}),limit:w.integer({description:"Number of Actors that will be listed.",default:20}),desc:w.boolean({description:"Sort Actors in descending order.",default:!1})};static enableJsonFlag=!0;async run(){let{desc:e,limit:t,offset:o,my:s,json:i}=this.flags,n=await I(),a=await n.actors().list({limit:t,offset:o,desc:e,my:s});if(a.count===0){if(i){k(a);return}v({message:s?"You don't have any Actors yet!":"There are no recent Actors used by you.",stdout:!0});return}let l={...a,items:await Promise.all(a.items.map(async f=>{let d=await n.actor(f.id).get(),g=await n.actor(f.id).runs().list({desc:!0,limit:1}).catch(()=>({count:0,desc:!0,items:[],limit:1,offset:0,total:0}));return{...f,actor:d??null,lastRun:g.items[0]??null}}))};if(l.items=s?this.sortByModifiedAt(l.items):this.sortByLastRun(l.items),i){k(l);return}let u=s?Dm:km,m=l.items.reduce((f,d)=>{let g=`${d.username}/${d.name}`;return g.length>f?g.length:f},0)+2+6;for(let f of l.items){let d=f.stats.lastRunStartedAt?Vt.display(f.stats.lastRunStartedAt):"",g=f.lastRun?(()=>{if(f.lastRun.finishedAt)return ie.format(f.lastRun.finishedAt.getTime()-f.lastRun.startedAt.getTime());let S=Date.now()-f.lastRun.startedAt.getTime();return`${ie.format(S)}\u2026`})():"",y=f.actor?(()=>{let S=Object.entries(f.actor.taggedBuilds??{}).find(([E,T])=>T.buildNumber===f.actor.defaultRunOptions.build||E===f.actor.defaultRunOptions.build);return S?`${W.yellow(S[0])} / ${W.cyan(S[1].buildNumber??f.actor.defaultRunOptions.build)}`:W.gray("Unknown")})():W.gray("Unknown"),b=(()=>{if(f.lastRun){let E=[Ee(f.lastRun.status)];if(g&&E.push(Lm[f.lastRun.status],W.cyan(g)),f.lastRun.finishedAt){let T=Date.now()-f.lastRun.finishedAt.getTime();T<Pm.Week?E.push(`
81
+ `,W.gray(`${ie.format(T)} ago`)):E.push(`
82
+ `,W.gray("On",Vi.display(f.lastRun.finishedAt)))}return E.join(" ")}return""})();u.pushRow({Name:`${f.title}
83
+ ${W.gray(`${f.username}/${f.name}`)}`,Runs:G.isSmallTerminal()&&m>=56?qr:W.cyan(`${f.stats?.totalRuns??0}`),"Last run started at":d,"Last run":d,"Last run status":f.lastRun?Ee(f.lastRun.status):"","Modified at":Vt.display(f.modifiedAt),Builds:f.actor?W.cyan(f.actor.stats.totalBuilds):W.gray("Unknown"),"Last run duration":G.isSmallTerminal()?qr:W.cyan(g),"Default build":y,_Small_LastRunText:b})}$({message:u.render(1),stdout:!0})}sortByModifiedAt(e){return e.sort((t,o)=>{let s=new Date(t.modifiedAt);return new Date(o.modifiedAt).getTime()-s.getTime()})}sortByLastRun(e){return e.sort((t,o)=>{let s=new Date(t.stats?.lastRunStartedAt??"1970-01-01T00:00Z");return new Date(o.stats?.lastRunStartedAt??"1970-01-01T00:00Z").getTime()-s.getTime()})}};import{mkdirSync as jn,readdirSync as Fm,writeFileSync as Vn}from"fs";import{dirname as Mm,join as Um}from"path";import Bn from"process";import jm from"adm-zip";import Vm from"axios";import Gn from"jju";import{gt as Bm}from"semver";import Gm from"tiged";var Yn=c(async(r,e)=>{let{data:t}=await Vm.get(r,{responseType:"arraybuffer"}),o=new jm(Buffer.from(t,"binary"));o.extractEntryTo(o.getEntries()[0].entryName,e,!1)},"extractGitHubZip"),Et=class extends h{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:w.string({char:"v",description:"Actor version number which will be pulled, e.g. 1.2. Default: the highest version",required:!1}),dir:w.string({description:"Directory where the Actor should be pulled to",required:!1})};static args={actorId:A.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=Bn.cwd(),t=await xe({cwd:e});if(t.isErr()){p({message:t.unwrapErr().message}),Bn.exitCode=5;return}let{config:o}=t.unwrap(),s=await F(),i=await I(),n=!this.args.actorId,a=s.username||s.id,l=this.args?.actorId||o?.id||(o?.name?`${a}/${o.name}`:void 0);if(!l)throw new Error("Cannot find Actor in this directory.");let u;try{u=await i.actor(l).get()}catch{throw new Error(`Cannot find Actor with ID/name '${l}' in your account.`)}if(!u)throw new Error(`Cannot find Actor with ID/name '${l}' in your account.`);let{name:m,versions:f}=u,d=c(()=>{throw new Error("You cannot pull source code of this Actor because you do not have permission to do so.")},"throwMissingSourceCodeAccessError");if(!u.versions.length)throw new Error(`Actor ${l} has no versions.`);let g=null;if(this.flags.version&&(g=f.find(b=>b.versionNumber===this.flags.version),!g))throw new Error(`Cannot find version ${this.flags.version} of Actor ${l}.`);g||(g=f.reduce((b,S)=>Bm(`${S.versionNumber}.0`,`${b.versionNumber}.0`)?S:b));let y=n?e:Um(e,this.flags.dir??m);if(jn(y,{recursive:!0}),!n&&Fm(y).length!==0){p({message:`Directory ${y} is not empty. Please empty it or choose another directory.`});return}switch(g.sourceType){case"TARBALL":{g.tarballUrl||d(),await Yn(g.tarballUrl,y);break}case"SOURCE_FILES":{g.sourceFiles||d();let{sourceFiles:b}=g;for(let S of b){let E=Mm(S.name);if(jn(`${y}/${E}`,{recursive:!0}),!S.folder){let T=S.format==="BASE64"?Buffer.from(S.content,"base64").toString():S.content;if(S.name===V){let N=Gn.parse(T);N.name=u.name,Vn(`${y}/${S.name}`,Gn.update(T,N))}else Vn(`${y}/${S.name}`,T)}}break}case"GIT_REPO":{g.gitRepoUrl||d();let{gitRepoUrl:b}=g,[S,E]=b.split("#"),T,N;E&&([T,N]=E.split(":"));let P=S;N&&(P+=`/${N}`),T&&(P+=`#${T}`);let L=Gm(P);try{await L.clone(y)}catch(D){throw new Error(`Failed to pull Actor from ${b}. ${D.message}`)}break}case"GITHUB_GIST":{g.gitHubGistUrl||d(),await Yn(`${g.gitHubGistUrl}/archive/master.zip`,y);break}default:throw new Error(`Unknown source type: ${g.sourceType}`)}R({message:n?`Actor ${m} updated at ${y}/`:`Pulled to ${y}/`})}};import{readFileSync as Jm,statSync as Km,unlinkSync as qm}from"fs";import{join as Wm,resolve as zm}from"path";import at from"process";import Xm from"open";import{fetchManifest as Zm}from"@apify/actor-templates";import{ACTOR_JOB_STATUSES as lt,ACTOR_SOURCE_TYPES as Ws,MAX_MULTIFILE_BYTES as Qn}from"@apify/consts";import{createHmacSignature as Qm}from"@apify/utilities";import{readFileSync as Ym,writeFileSync as Hm}from"fs";var qs="@",Hn=100,Jn=5e4,$t=c(()=>{try{return JSON.parse(Ym(cr(),"utf-8"))||{}}catch{return{}}},"getSecretsFile"),Kn=c(r=>(xs(cr()),Hm(cr(),JSON.stringify(r,null," ")),r),"writeSecretsFile"),qn=c((r,e)=>{let t=$t();if(t[r])throw new Error(`Secret with name ${r} already exists. Call "apify secrets rm ${r}" to remove it.`);if(typeof r!="string"||r.length>Hn)throw new Error(`Secret name has to be string with maximum length ${Hn}.`);if(typeof e!="string"||e.length>Jn)throw new Error(`Secret value has to be string with maximum length ${Jn}.`);return t[r]=e,Kn(t)},"addSecret"),Wn=c(r=>{let e=$t();if(!e[r])throw new Error(`Secret with name ${r} doesn't exist.`);delete e[r],Kn(e)},"removeSecret"),zn=c(r=>new RegExp(`^${qs}.{1}`).test(r),"isSecretKey"),Xn=c((r,e)=>{e=e||$t();let t={};return Object.keys(r).forEach(o=>{if(zn(r[o])){let s=r[o].replace(new RegExp(`^${qs}`),"");e[s]?t[o]=e[s]:x({message:`Value for ${s} not found in local secrets. Set it by calling "apify secrets add ${s} [SECRET_VALUE]"`})}else t[o]=r[o]}),t},"replaceSecretsValue"),Zn=c((r,e)=>{e=e||$t();let t=[];return Object.keys(r).forEach(o=>{if(zn(r[o])){let s=r[o].replace(new RegExp(`^${qs}`),"");e[s]?t.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 t.push({name:o,value:r[o]})}),t},"transformEnvToEnvVars");var zs="temp_file.zip",eu={build:"latest",memoryMbytes:4096,timeoutSecs:3600},ea="0.0",tu="latest",Rt=class extends h{static name="push";static description=`Deploys Actor to Apify platform using settings from '${V}'.
84
+ Files under '${Qn/1024**2}' MB upload as "Multiple source files"; larger projects upload as ZIP file.
85
+ Use --force to override newer remote versions.`;static flags={version:w.string({char:"v",description:`Actor version number to which the files should be pushed. By default, it is taken from the '${V}' file.`,required:!1}),"build-tag":w.string({char:"b",description:`Build tag to be applied to the successful Actor build. By default, it is taken from the '${V}' file`,required:!1}),"wait-for-finish":w.string({char:"w",description:"Seconds for waiting to build to finish, if no value passed, it waits forever.",required:!1}),open:w.boolean({description:"Whether to open the browser automatically to the Actor details page.",default:!1,required:!1}),force:w.boolean({char:"f",description:"Push an Actor even when the local files are older than the Actor on the platform.",default:!1,required:!1}),dir:w.string({description:"Directory where the Actor is located",required:!1})};static args={actorId:A.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 '${V}' file.`})};async run(){let e=zm(at.cwd(),this.flags.dir??"."),t=await Li(e);if(!t.length){p({message:"You need to call this command from a folder that has an Actor in it!"}),at.exitCode=4;return}if(![dr,"actor.json",".actor/actor.json",".actor"].some(M=>t.some(Q=>Q===M||Q.startsWith(M)))){p({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(`
86
+ `)}),at.exitCode=4;return}let o=await I(),s=await xe({cwd:e});if(s.isErr()){p({message:s.unwrapErr().message}),at.exitCode=5;return}let{config:i}=s.unwrap(),n=await F(),l=!!n.organizationOwnerUserId?`/organization/${n.id}`:"",u,m,f=!1,d=this.flags.version||i?.version||ea,g=this.flags.buildTag||i?.buildTag;!g&&d===ea&&(g=tu);let y=Number.isNaN(this.flags.waitForFinish)?void 0:Number.parseInt(this.flags.waitForFinish,10)*1e3,b=this.args.actorId;if(b){if(m=await o.actor(b).get(),!m)throw new Error(`Cannot find Actor with ID '${b}' in your account.`);u=m.id}else{let M=n.username||n.id;if(m=await o.actor(`${M}/${i.name}`).get(),m)u=m.id;else{let{templates:Q}=await Zm(),we=Q.find(ar=>ar.name===i.template)?.defaultRunOptions||eu,Ot={name:i.name,title:i.title,description:i.description,defaultRunOptions:we,versions:[{versionNumber:d,buildTag:g,sourceType:Ws.SOURCE_FILES,sourceFiles:[]}]};m=await o.actors().create(Ot),u=m.id,f=!0,v({message:`Created Actor with name ${i.name} on Apify.`})}}let S=o.actor(u);v({message:`Deploying Actor '${i.name}' to Apify.`});let E=await Si(t,e),T,N,P;if(E<Qn){let M=await S.get();if(!f){let Q=t.reduce((we,Ot)=>{let{mtimeMs:ar,ctimeMs:di}=Km(Wm(e,Ot)),pi=ar>di?ar:di;return we>pi?we:pi},0),ye=M?.modifiedAt.valueOf();if(!this.flags.force&&ye&&Q<ye&&(i?.name||b))throw new Error(`Actor with identifier "${i?.name||b}" is already on the platform and was modified there since modified locally.
87
+ Skipping push. Use --force to override.`)}N=await Pi(t,e),T=Ws.SOURCE_FILES}else{Ae({message:"Zipping Actor files"}),await ki(zs,t,e);let M=await o.keyValueStores().getOrCreate(`actor-${u}-source`),Q=`version-${d}.zip`,ye=Jm(zs);await o.keyValueStore(M.id).setRecord({key:Q,value:ye,contentType:"application/zip"}),qm(zs);let we=new URL(`${o.baseUrl}/key-value-stores/${M.id}/records/${Q}?disableRedirect=true`);if(M?.urlSigningSecretKey){let Ot=Qm(M.urlSigningSecretKey,Q);we.searchParams.set("signature",Ot)}P=we.toString(),T=Ws.TARBALL}let L=await S.version(d).get(),D=i.environmentVariables?Zn(i.environmentVariables):void 0;if(L){let M={tarballUrl:P,sourceFiles:N,buildTag:g,sourceType:T,envVars:D};await S.version(d).update(M),Ae({message:`Updated version ${d} for Actor ${m.name}.`})}else{let M={versionNumber:d,tarballUrl:P,sourceFiles:N,buildTag:g,sourceType:T,envVars:D};await S.versions().create({...M}),Ae({message:`Created version ${d} for Actor ${m.name}.`})}Ae({message:`Building Actor ${m.name}`});let J=await S.build(d,{useCache:!0,waitForFinish:2});try{await $e({job:J,timeoutMillis:y,apifyClient:o})}catch(M){x({message:"Can not get log:"}),console.error(M)}J=await o.build(J.id).get(),ws({message:"Actor build detail",url:`https://console.apify.com${l}/actors/${J.actId}#/builds/${J.buildNumber}`}),ws({message:"Actor detail",url:`https://console.apify.com${l}/actors/${J.actId}`}),this.flags.open&&await Xm(`https://console.apify.com${l}/actors/${J.actId}`),J.status===lt.SUCCEEDED?R({message:"Actor was deployed to Apify cloud and built there."}):J.status===lt.READY?x({message:"Build is waiting for allocation."}):J.status===lt.RUNNING?x({message:"Build is still running."}):J.status===lt.ABORTED||J.status===lt.ABORTING?(x({message:"Build was aborted!"}),at.exitCode=3):J.status===lt.TIMED_OUT||J.status===lt.TIMING_OUT?(x({message:"Build timed out!"}),at.exitCode=2):(p({message:"Build failed!"}),at.exitCode=1)}};var Qr=class extends h{static name="rm";static description="Permanently removes an Actor from your account.";static args={actorId:A.string({description:"The Actor ID to delete.",required:!0})};async run(){let{actorId:e}=this.args,t=await I();if(!await t.actor(e).get()){p({message:`Actor with ID "${e}" was not found on your account.`});return}if(!await z({message:"Are you sure you want to delete this Actor?"})){v({message:`Deletion of Actor "${e}" was canceled.`});return}try{await t.actor(e).delete(),R({message:`Actor with ID "${e}" was deleted.`})}catch(i){let n=i;p({message:`Failed to delete Actor "${e}".
88
+ ${n.message||n}`})}}};import ee from"chalk";var eo=class extends h{static name="start";static description=`Starts Actor remotely and returns run details immediately.
89
+ Uses authenticated account and local key-value store for input.`;static flags={...It("Actor"),input:w.string({char:"i",description:"Optional JSON input to be given to the Actor.",required:!1,stdin:2,exclusive:["input-file"]}),"input-file":w.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:A.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 '${V}' file.`})};async run(){let e=process.cwd(),t=Ue(e)||{},o=await I(),s=await F(),i=s.username||s.id,{id:n,userFriendlyId:a,actorData:l}=await Je.resolveActorId({client:o,localActorName:t.name,usernameOrId:i,providedActorNameOrId:this.args.actorId}),u={};this.flags.build&&(u.build=this.flags.build),this.flags.timeout&&(u.timeout=this.flags.timeout),this.flags.memory&&(u.memory=this.flags.memory);let m=await Tt(e,this.flags.input,this.flags.inputFile);if(m===!1)return;let f=Ct(o,{actorOrTaskData:{id:n,userFriendlyId:a},runOptions:u,type:"Actor",inputOverride:m?.input,silent:!0,waitForRunToFinish:!1,printRunLogs:!1}),d;for await(let P of f)d=P;if(this.flags.json){k(d);return}let g=`https://console.apify.com/actors/${n}/runs/${d.id}`,y=`https://console.apify.com/storage/datasets/${d.defaultDatasetId}`,b=[`${ee.gray("Run:")} Calling Actor ${a} (${ee.gray(n)})`,"",`${ee.yellow("Started")}: ${B.display(d.startedAt)}`];d.containerUrl&&b.push(`${ee.yellow("Container URL")}: ${ee.blue(d.containerUrl)}`);let S=d.buildNumber.split(".").slice(0,2).join("."),E=l.versions.find(P=>P.versionNumber===S),T=Object.entries(l.taggedBuilds??{}).find(([,P])=>P.buildNumber===d.buildNumber)?.[0],N=[`${ee.yellow("Build")}:`,ee.cyan(d.buildNumber)];T?N.push(`(${ee.yellow(T)})`):N.push(`(${ee.gray("N/A")})`),E&&N.push(`| ${ee.gray("Actor version:")} ${ee.cyan(E.versionNumber)} (${ee.yellow(E.buildTag)})`),b.push(N.join(" ")),b.push(`${ee.yellow("Timeout")}: ${d.options.timeoutSecs.toLocaleString("en-US")} seconds`),b.push(`${ee.yellow("Memory")}: ${d.options.memoryMbytes} MB`),b.push("",`${ee.blue("Export results")}: ${y}`,`${ee.blue("View on Apify Console")}: ${g}`),$({message:b.join(`
90
+ `),stdout:!0})}};var to=class extends h{static name="actors";static description="Manages Actor creation, deployment, and execution on the Apify platform.";static subcommands=[eo,Qr,Rt,Et,Zr,Xr,Je,Jr];async run(){this.printHelp()}};import su from"chalk";import iu from"computer-name";import nu from"cors";import Xs from"express";import au from"open";import{cryptoRandomObjectId as lu}from"@apify/utilities";import ru from"@inquirer/password";var ta=Re(async({message:r,mask:e})=>await ru({message:r,mask:e??"*"}));import ou from"@inquirer/select";var Ke=Re(async({message:r,choices:e,pageSize:t,loop:o,default:s})=>await ou({message:r,choices:e,pageSize:t,loop:o,default:s}));var Qs="https://console.apify.com/settings/integrations",cu=new URL(Qs).origin,mu=Qs.includes("localhost")?"http://localhost:3333":void 0,ra="v1",Zs=c(async r=>{let e=await Mt(r,mu),t=await F();return e?(await Tr(t.id),R({message:`You are logged in to Apify as ${t.username||t.id}. ${su.gray(`Your token is stored at ${le()}.`)}`})):p({message:"Login to Apify failed, the provided API token is not valid."}),e},"tryToLogin"),_t=class extends h{static name="login";static description=`Authenticates your Apify account and saves credentials to '${je(le())}'.
91
+ All other commands use these stored credentials.
92
+
93
+ Run 'apify logout' to remove authentication.`;static flags={token:w.string({char:"t",description:"Apify API token",required:!1}),method:w.string({char:"m",description:"Method of logging in to Apify",choices:["console","manual"],required:!1})};async run(){let{token:e,method:t}=this.flags;if(e){await Zs(e);return}let o=t;if(t||(o=await Ke({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})),o==="console"){let s,i=Xs();i.use(nu({origin:cu,allowedHeaders:["Content-Type","Authorization"]})),i.use((m,f,d)=>{f.set("Connection","close"),d()}),i.use(Xs.json());let n=lu();i.use((m,f,d)=>{let{token:g}=m.query;if(!g){let y=m.get("Authorization");if(y){let[b,S,...E]=y.trim().split(/\s+/);b.toLowerCase()==="bearer"&&S&&E.length===0&&(g=S)}}g!==n?(f.status(401),f.send("Authorization failed")):d()});let a=Xs.Router();i.use(`/api/${ra}`,a),a.post("/login-token",async(m,f)=>{try{if(m.body.apiToken)await Zs(m.body.apiToken);else throw new Error("Request did not contain API token");f.end()}catch(d){let g=`Login to Apify failed with error: ${d.message}`;p({message:g}),f.status(500),f.send(g)}s.close()}),a.post("/exit",(m,f)=>{m.body.isWindowClosed?p({message:"Login to Apify failed, the console window was closed."}):m.body.actionCanceled?p({message:"Login to Apify failed, the action was canceled in the Apify Console."}):p({message:"Login to Apify failed."}),f.end(),s.close()}),s=i.listen(0);let{port:l}=s.address(),u=new URL(Qs);u.searchParams.set("localCliCommand","login"),u.searchParams.set("localCliPort",`${l}`),u.searchParams.set("localCliToken",n),u.searchParams.set("localCliApiVersion",ra);try{u.searchParams.set("localCliComputerName",encodeURIComponent(iu()))}catch{}v({message:`Opening Apify Console at "${u.href}"...`}),await au(u.href)}else{console.log("Enter your Apify API token. You can find it at https://console.apify.com/settings/integrations");let s=await ta({message:"token:"});await Zs(s)}}};var xt=class extends h{static name="logout";static description=`Removes authentication by deleting your API token and account information from '${je(le())}'.
94
+ Run 'apify login' to authenticate again.`;async run(){await Pt(le()),await Tr(null),R({message:"You are logged out from your Apify account."})}};var ro=class extends h{static name="token";static description="Prints the current API token for the Apify CLI.";async run(){await I();let e=await F();e.token&&$({message:e.token,stdout:!0})}};var oo=class extends h{static name="auth";static description="Manages authentication for Apify CLI.";static subcommands=[_t,xt,ro];async run(){this.printHelp()}};import Z from"chalk";var uu=c(r=>r,"noColor");function X({bytes:r,shortBytes:e=!1,colorFunc:t=uu,precision:o=2}){let s=[e?"B":"Bytes","KB","MB","GB","TB"];if(r===0)return e?`${0 .toPrecision(o)} B`:`${0 .toPrecision(o)} Byte`;let i=Math.floor(Math.log(r)/Math.log(1e3));return`${(r/1e3**i).toFixed(o)} ${t(s[i])}`}c(X,"prettyPrintBytes");var so=class extends h{static name="info";static description="Prints information about a specific build.";static args={buildId:A.string({required:!0,description:"The build ID to get information about."})};static enableJsonFlag=!0;async run(){let{buildId:e}=this.args,t=await I(),o=await t.build(e).get();if(!o){p({message:`Build with ID "${e}" was not found on your account.`,stdout:!0});return}if(this.flags.json){k(o);return}let s=await t.actor(o.actId).get(),i;if(s?.taggedBuilds){for(let[g,y]of Object.entries(s.taggedBuilds))if(y.buildId===o.id){i=g;break}}let n=Reflect.get(o,"exitCode"),a=s?.username?`${s.username}/${s.name}`:s?.name??"unknown-actor",l=i?` (tagged as ${Z.yellow(i)})`:"",u=typeof n<"u"?` (exit code: ${Z.gray(n)})`:"",m=[`${Z.yellow("Actor")}: ${a} (${Z.gray(o.actId)})`,"",`${Z.yellow("Build Information")} (ID: ${Z.gray(o.id)})`,` ${Z.yellow("Build Number")}: ${o.buildNumber}${l}`,` ${Z.yellow("Status")}: ${Ee(o.status)}${u}`,` ${Z.yellow("Started")}: ${B.display(o.startedAt)}`];if(o.finishedAt)m.push(` ${Z.yellow("Finished")}: ${B.display(o.finishedAt)} (took ${Z.gray(Bt.format(o.stats?.durationMillis??0))})`);else{let g=Date.now()-o.startedAt.getTime();m.push(` ${Z.yellow("Finished")}: ${Z.gray(`Running for ${Bt.format(g)}`)}`)}o.stats?.computeUnits&&m.push(` ${Z.yellow("Compute Units")}: ${o.stats.computeUnits.toFixed(3)}`);let f=Reflect.get(o.stats??{},"imageSizeBytes");f&&m.push(` ${Z.yellow("Docker Image Size")}: ${X({bytes:f})}`),m.push(` ${Z.yellow("Origin")}: ${o.meta.origin??"UNKNOWN"}`),m.push("");let d=`https://console.apify.com/actors/${o.actId}/builds/${o.buildNumber}`;m.push(`${Z.blue("View in Apify Console")}: ${d}`),$({message:m.join(`
95
+ `),stdout:!0})}};var io=class extends h{static name="log";static description="Prints the log of a specific build.";static args={buildId:A.string({required:!0,description:"The build ID to get the log from."})};async run(){let{buildId:e}=this.args,t=await I(),o=await t.build(e).get();if(!o){p({message:`Build with ID "${e}" was not found on your account.`,stdout:!0});return}v({message:`Log for build with ID "${e}":
96
+ `});try{await $e({job:o,apifyClient:t})}catch(s){p({message:`Failed to get log for build with ID "${e}": ${s.message}`,stdout:!0})}}};import fe from"chalk";var du=c(()=>new G({allColumns:["Number","ID","Status","Took"],mandatoryColumns:["Number","ID","Status","Took"],columnAlignments:{Took:"right"}}),"tableFactory"),no=class extends h{static name="ls";static description="Lists all builds of the Actor.";static flags={offset:w.integer({description:"Number of builds that will be skipped.",default:0}),limit:w.integer({description:"Number of builds that will be listed.",default:10}),desc:w.boolean({description:"Sort builds in descending order.",default:!1}),compact:w.boolean({description:"Display a compact table.",default:!1,char:"c"})};static args={actorId:A.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:t,offset:o,compact:s,json:i}=this.flags,{actorId:n}=this.args,a=await I(),l=await Ye({providedActorNameOrId:n,client:a});if(!l.valid){p({message:`${l.reason}. Please run this command in an Actor directory, or specify the Actor ID.`,stdout:!0});return}let u=await a.actor(l.id).builds().list({desc:e,limit:t,offset:o}),m=await a.actor(l.id).get(),f=Sr(u.items,y=>{let b=Reflect.get(y,"buildNumber"),[S,E]=b.split(".");return`${S}.${E}`}),d=Object.entries(m.taggedBuilds??{}).reduce((y,[b,S])=>(y[S.buildNumber]=b,y),{});if(i){for(let y of u.items){let b=Reflect.get(y,"buildNumber"),S=d[b];S&&Reflect.set(y,"buildTag",S)}k(u);return}$({message:`${fe.reset("Showing")} ${fe.yellow(u.items.length)} out of ${fe.yellow(u.total)} builds for Actor ${fe.yellow(l.userFriendlyId)} (${fe.gray(l.id)})
97
+ `,stdout:!0});let g=Object.entries(f).sort((y,b)=>y[0].localeCompare(b[0]));for(let[y,b]of g){if(!b?.length){$({message:`No builds for version ${y}`,stdout:!0});continue}let S=m.versions.find(P=>P.versionNumber===y)?.buildTag,E=this.generateTableForActorVersion({buildsForVersion:b,buildTagToActorVersion:d}),T=S?` (latest build gets tagged with ${fe.yellow(S)})`:"",N=[fe.reset(`Builds for Actor Version ${fe.yellow(y)}${T}`),E.render(s?0:-1),""];$({message:N.join(`
98
+ `),stdout:!0})}}generateTableForActorVersion({buildsForVersion:e,buildTagToActorVersion:t}){let o=du();for(let s of e){let i=Reflect.get(s,"buildNumber"),n=t[i]?` (${fe.yellow(t[i])})`:"",a;if(s.finishedAt){let l=s.finishedAt.getTime()-s.startedAt.getTime();a=fe.gray(`${ie.format(l,void 0,{left:""})}`)}else{let l=Date.now()-s.startedAt.getTime();a=fe.gray(`Running for ${ie.format(l,void 0,{left:""})}`)}o.pushRow({Number:`${i}${n}`,ID:fe.gray(s.id),Status:Ee(s.status),Took:a})}return o}};import pu from"@inquirer/input";var oa=Re(async({message:r,expectedValue:e,failureMessage:t})=>await pu({message:r,validate(s){return s===e?!0:t??"That is not the correct input!"}}));var ao=class extends h{static name="rm";static description="Permanently removes an Actor build from the Apify platform.";static args={buildId:A.string({description:"The build ID to delete.",required:!0})};async run(){let{buildId:e}=this.args,t=await I(),o=await t.build(e).get();if(!o){p({message:`Build with ID "${e}" was not found on your account.`,stdout:!0});return}let s=await t.actor(o.actId).get(),i;if(s?.taggedBuilds){for(let[a,l]of Object.entries(s.taggedBuilds))if(e===l.buildId){i=a;break}}if(!await(i?oa:z)({message:`Are you sure you want to delete this Actor Build?${i?` If so, please type in "${i}":`:""}`,expectedValue:i??"",failureMessage:"Your provided value does not match the build tag."})){v({message:`Deletion of build "${e}" was canceled.`,stdout:!0});return}try{await t.build(e).delete(),R({message:`Build with ID "${e}" was deleted.`,stdout:!0})}catch(a){let l=a;p({message:`Failed to delete build "${e}".
99
+ ${l.message||l}`,stdout:!0})}}};var lo=class extends h{static name="builds";static description="Manages Actor build processes and versioning.";static subcommands=[ao,no,io,so,vt];async run(){this.printHelp()}};var co=class extends Je{static name="call"};import fu from"assert";import{existsSync as mo}from"fs";import{mkdir as gu,readFile as hu,symlink as yu,unlink as wu,writeFile as sa}from"fs/promises";import{basename as Au,join as ge}from"path";import qe from"chalk";var bu=c(r=>ge(r,".install-marker"),"pathToInstallMarker"),er=class extends h{static name="install";static description="Finalizes the first-time setup of Apify and Actor CLI.";static hidden=!0;async run(){let{installMethod:e,installPath:t,version:o}=K();if(e!=="bundle"){v({message:"Apify and Actor CLI are already fully configured! \u{1F44D}"});return}fu(t,"When CLI is installed via bundles, the install path must be set");let s=bu(t);if(mo(s)){v({message:"Apify and Actor CLI are already fully configured! \u{1F44D}"});return}await this.symlinkToLocalBin(t),await this.promptAddToShell(),await sa(s,o),C("[install] install marker written to",s),$({message:""}),R({message:"To get started, run:"}),$({message:qe.white.bold(` apify --help
100
+ actor --help`)})}async symlinkToLocalBin(e){let t=process.env.HOME;if(C("[install] user home directory",t),!t){C("[install] user home directory not found"),x({message:qe.gray("User home directory not found, cannot symlink to ~/.local/bin")});return}let o=ge(t,".local","bin");mo(o)||await gu(o,{recursive:!0});let s=["apify","actor","apify-cli"];for(let i of s){let n=ge(e,i);if(!mo(n)){C("[install] file not found for symlinking",i,n),x({message:qe.gray(`Bundle not found for symlinking: ${i}`)});continue}let a=ge(o,i);await wu(a).catch(()=>{}),await yu(n,a),C("[install] symlink created for item",i,a)}v({message:qe.gray(`Symlinked apify, actor, and apify-cli to ${o}`)})}async promptAddToShell(){let e=process.env.PROVIDED_INSTALL_DIR;if(!e){x({message:qe.gray("Install directory not found, cannot add to shell")});return}let t=process.env.FINAL_BIN_DIR;$({message:""});let o=await z({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)",providedConfirmFromStdin:!1}),s=Au(process.env.SHELL??"sh"),i=`"${e.replaceAll('"','\\"')}"`,n=[],a="";switch(s){case"bash":{n.push(`export APIFY_CLI_INSTALL=${i}`),n.push('export PATH="$APIFY_CLI_INSTALL/bin:$PATH"');let l=[ge(process.env.HOME,".bashrc"),ge(process.env.HOME,".bash_profile")];process.env.XDG_CONFIG_HOME&&l.push(ge(process.env.XDG_CONFIG_HOME,".bashrc"),ge(process.env.XDG_CONFIG_HOME,".bash_profile"),ge(process.env.XDG_CONFIG_HOME,"bashrc"),ge(process.env.XDG_CONFIG_HOME,"bash_profile"));for(let u of l)if(mo(u)){a=u;break}break}case"zsh":n.push(`export APIFY_CLI_INSTALL=${i}`),n.push('export PATH="$APIFY_CLI_INSTALL/bin:$PATH"'),a=ge(process.env.HOME,".zshrc");break;case"fish":{n.push(`set --export APIFY_CLI_INSTALL ${i}`),n.push(`set --export PATH ${t} $PATH`),a=ge(process.env.HOME,".config","fish","config.fish");break}default:n.push(`export APIFY_CLI_INSTALL=${i}`),n.push('export PATH="$APIFY_CLI_INSTALL/bin:$PATH"'),a="~/.bashrc";break}if($({message:""}),o&&a){let u=`${await hu(a,"utf-8")}
97
101
 
98
102
  # apify cli
99
103
  ${n.join(`
100
- `)}`;await Zn(a,m),v({message:Ke.gray(`Added "${Ue(t)}" to $PATH in ${Ue(a)}`)})}else v({message:[Ke.gray(`Manually add the following lines to your shell config file (${Ue(a)} or similar):`),...n.map(l=>Ke.white.bold(` ${l}`))].join(`
101
- `)})}};import{spawn as gm}from"child_process";import{existsSync as hm}from"fs";import{lstat as ym,readdir as wm,writeFile as ta}from"fs/promises";import{dirname as Am,join as Ks}from"path";import qs from"chalk";import{gte as ra}from"semver";import{Result as lm}from"@sapphire/result";import{execa as cm}from"execa";var um=c(async(r,e,t)=>{let o=je(r);C("spawnPromised",{escapedCommand:o,args:e,opts:t});let s=cm(o,e,{shell:!0,windowsHide:!0,env:t.env,cwd:t.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 lm.fromAsync(s.catch(i=>{throw new Error(`${r} exited with code ${i.exitCode}`,{cause:i})}))},"spawnPromised");async function ne({cmd:r,args:e=[],opts:t={},overrideCommand:o}){Ae({message:`${o||r} ${e.join(" ")}`});let s=await um(r,e,t);if(s.isErr()){let i=s.unwrapErr();if(p({message:i.message}),i.cause)throw i.cause}}c(ne,"execWithLog");import{execSync as Qn}from"child_process";import{existsSync as mm,readFileSync as dm}from"fs";var De=K();function pm(){return De.platform==="linux"?mm("/etc/alpine-release"):!1}c(pm,"isInstalledOnMusl");function fm(){return De.platform==="darwin"&&De.arch==="x64"?!Qn("sysctl -a",{encoding:"utf-8"}).includes("AVX2"):De.platform==="linux"&&De.arch==="x64"?!dm("/proc/cpuinfo","utf-8").includes("avx2"):De.platform==="windows"?De.arch==="arm64"?!0:Qn(`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}c(fm,"isInstalledOnBaseline");async function ea(r){let e=r.replace(/^v(\d+)/,"$1"),t=e==="latest"?"latest":`tags/v${e}`,o=await fetch(`https://api.github.com/repos/apify/apify-cli/releases/${t}`,{headers:{"User-Agent":ot}});if(!o.ok)return C("useCLIVersionAssets","Failed to fetch release",{statusCode:o.status,body:await o.text(),version:r,tag:t}),null;let s=await o.json(),i=pm(),n=fm(),a=s.assets.filter(l=>{let[m,u,f,d,g,y]=l.name.replace(e,"version").replace(".exe","").split("-");return f!==De.platform||d!==De.arch?!1:i?g==="musl":n?y==="baseline"||g==="baseline":!g&&!y});return C("useCLIVersionAssets","Fetched release",{version:s.tag_name,filteredAssets:a}),{assets:a,version:s.tag_name.replace(/^v(\d+)/,"$1")}}c(ea,"useCLIVersionAssets");var oa={bundle:c((r,e)=>[`${e}`,"upgrade"],"bundle"),npm:c(r=>["npm","install","-g",`apify-cli@${r}`],"npm"),pnpm:c(r=>["pnpm","install","-g",`apify-cli@${r}`],"pnpm"),bun:c(r=>["bun","install","-g",`apify-cli@${r}`],"bun"),homebrew:c(()=>["brew","upgrade","apify-cli"],"homebrew"),volta:c(r=>["volta","install",`apify-cli@${r}`],"volta")},ao="1.0.1",sa="https://raw.githubusercontent.com/apify/apify-cli/main/scripts/install/upgrade.ps1",Qt=class extends h{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:w.boolean({description:"[DEPRECATED] This flag is now ignored, as running the command manually will always check for the latest version.",required:!1,char:"f"}),version:w.string({description:"The version of the CLI to upgrade to. If not provided, the latest version will be used.",required:!1}),"internal-automatic-call":w.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 bn(!this.flags.internalAutomaticCall),{installMethod:t}=K();if(!e.shouldUpdate||e.currentVersion===gs){C("[upgrade] no update needed",{shouldUpdate:e.shouldUpdate,currentVersion:e.currentVersion}),this.flags.internalAutomaticCall||v({message:`${this.cliName} is up to date \u{1F44D}
102
- `});return}if(!this.flags.internalAutomaticCall){await this.handleInstallSpecificVersion("latest");return}let o=oa[t]("latest",this.entrypoint).join(" ");R({message:""});let s=[`You are using an old version of ${this.cliName}. We strongly recommend you always use the latest available version.`,` \u21AA Run ${qs.bgWhite(qs.black(o))} to update! \u{1F44D}
104
+ `)}`;await sa(a,u),v({message:qe.gray(`Added "${je(t)}" to $PATH in ${je(a)}`)})}else v({message:[qe.gray(`Manually add the following lines to your shell config file (${je(a)} or similar):`),...n.map(l=>qe.white.bold(` ${l}`))].join(`
105
+ `)})}};import{spawn as Ru}from"child_process";import{existsSync as _u}from"fs";import{lstat as xu,readdir as Ou,writeFile as aa}from"fs/promises";import{dirname as Nu,join as ei}from"path";import ti from"chalk";import{gte as la}from"semver";import{Result as Su}from"@sapphire/result";import{execa as vu}from"execa";var Tu=c(async(r,e,t)=>{let o=Ve(r);C("spawnPromised",{escapedCommand:o,args:e,opts:t});let s=vu(o,e,{shell:!0,windowsHide:!0,env:t.env,cwd:t.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(`${r} exited with code ${i.exitCode}`,{cause:i})}))},"spawnPromised");async function ae({cmd:r,args:e=[],opts:t={},overrideCommand:o}){Ae({message:`${o||r} ${e.join(" ")}`});let s=await Tu(r,e,t);if(s.isErr()){let i=s.unwrapErr();if(p({message:i.message}),i.cause)throw i.cause}}c(ae,"execWithLog");import{execSync as ia}from"child_process";import{existsSync as Cu,readFileSync as Iu}from"fs";var Fe=K();function Eu(){return Fe.platform==="linux"?Cu("/etc/alpine-release"):!1}c(Eu,"isInstalledOnMusl");function $u(){return Fe.platform==="darwin"&&Fe.arch==="x64"?!ia("sysctl -a",{encoding:"utf-8"}).includes("AVX2"):Fe.platform==="linux"&&Fe.arch==="x64"?!Iu("/proc/cpuinfo","utf-8").includes("avx2"):Fe.platform==="windows"?Fe.arch==="arm64"?!0:ia(`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}c($u,"isInstalledOnBaseline");async function na(r){let e=r.replace(/^v(\d+)/,"$1"),t=e==="latest"?"latest":`tags/v${e}`,o=await fetch(`https://api.github.com/repos/apify/apify-cli/releases/${t}`,{headers:{"User-Agent":ot}});if(!o.ok)return C("useCLIVersionAssets","Failed to fetch release",{statusCode:o.status,body:await o.text(),version:r,tag:t}),null;let s=await o.json(),i=Eu(),n=$u(),a=s.assets.filter(l=>{let[u,m,f,d,g,y]=l.name.replace(e,"version").replace(".exe","").split("-");return f!==Fe.platform||d!==Fe.arch?!1:i?g==="musl":n?y==="baseline"||g==="baseline":!g&&!y});return C("useCLIVersionAssets","Fetched release",{version:s.tag_name,filteredAssets:a}),{assets:a,version:s.tag_name.replace(/^v(\d+)/,"$1")}}c(na,"useCLIVersionAssets");var ca={bundle:c((r,e)=>[`${e}`,"upgrade"],"bundle"),npm:c(r=>["npm","install","-g",`apify-cli@${r}`],"npm"),pnpm:c(r=>["pnpm","install","-g",`apify-cli@${r}`],"pnpm"),bun:c(r=>["bun","install","-g",`apify-cli@${r}`],"bun"),homebrew:c(()=>["brew","upgrade","apify-cli"],"homebrew"),volta:c(r=>["volta","install",`apify-cli@${r}`],"volta")},uo="1.0.1",ma="https://raw.githubusercontent.com/apify/apify-cli/main/scripts/install/upgrade.ps1",tr=class extends h{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:w.boolean({description:"[DEPRECATED] This flag is now ignored, as running the command manually will always check for the latest version.",required:!1,char:"f"}),version:w.string({description:"The version of the CLI to upgrade to. If not provided, the latest version will be used.",required:!1}),"internal-automatic-call":w.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 Cn(!this.flags.internalAutomaticCall),{installMethod:t}=K();if(!e.shouldUpdate||e.currentVersion===As){C("[upgrade] no update needed",{shouldUpdate:e.shouldUpdate,currentVersion:e.currentVersion}),this.flags.internalAutomaticCall||v({message:`${this.cliName} is up to date \u{1F44D}
106
+ `});return}if(!this.flags.internalAutomaticCall){await this.handleInstallSpecificVersion("latest");return}let o=ca[t]("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 ${ti.bgWhite(ti.black(o))} to update! \u{1F44D}
103
107
  `].join(`
104
- `);x({message:s})}async handleInstallSpecificVersion(e){if(e!=="latest"&&!ra(e,ao)){p({message:`The minimum version of the CLI you can manually downgrade/upgrade to is ${ao}.`});return}let t=await ea(e);if(!t){p({message:"The provided version does not exist. Please check the version number and try again."});return}let{assets:o,version:s}=t;if(!ra(s,ao)){p({message:`The minimum version of the CLI you can manually downgrade/upgrade to is ${ao}.`});return}let i=K();if(i.installMethod==="bundle"){if(!o.length){p({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(`
105
- `)});return}let a=Am(process.execPath);C("[upgrade] bundleDirectory",a);let l=await wm(a);if(!l.some(m=>m.startsWith("apify")||m.startsWith("actor"))){C("[upgrade] directoryEntries",l),p({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: ${a}`].join(`
106
- `)});return}if(i.platform==="windows")return this.startUpgradeProcess(a,s,o);await this.handleUnixUpgrade(a,s,o),this.successMessage(s);return}let n=oa[i.installMethod](e,this.entrypoint);if(process.env.APIFY_CLI_DEBUG){v({message:`Would run command: ${n.join(" ")}`});return}try{await ne({cmd:n[0],args:n.slice(1)}),this.successMessage(s)}catch{p({message:`Failed to upgrade the CLI. Please run the following command manually: ${n.join(" ")}`})}}successMessage(e){$({message:`Successfully upgraded to ${e} \u{1F44D}`})}async startUpgradeProcess(e,t,o){await this.upsertUpgradeScript(e);let s=["-ExecutionPolicy","Bypass","-File",`"${Ks(e,"upgrade.ps1")}"`,"-ProcessId",process.pid.toString(),"-InstallLocation",`"${e}"`,"-Version",`"${t}"`],i=o.map(a=>a.browser_download_url).join(",");s.push("-AllUrls",`"${i}"`),C("[upgrade] starting upgrade process with args",s),v({message:"Starting upgrade process..."});let n=gm("powershell.exe",s,{detached:!0,shell:!0,stdio:"inherit",windowsHide:!1,windowsVerbatimArguments:!0});n.on("spawn",()=>{C("[upgrade] upgrade process spawned"),n.unref(),process.exit(0)}),n.on("error",a=>{p({message:`Failed to start the upgrade process: ${a.message}`})})}async upsertUpgradeScript(e){let t=Ks(e,"upgrade.ps1");if(hm(t))return;let o=K(),s=await fetch(sa,{headers:{"User-Agent":ot}});s.ok||(p({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: ${sa}`,`- The status code of the response: ${s.status}`].join(`
107
- `)}),process.exit(1));let i=await s.arrayBuffer();await ta(t,Buffer.from(i)),C("[upgrade] downloaded upgrade script to",t)}async handleUnixUpgrade(e,t,o){let s=K();for(let i of o){let n=i.name.split("-")[0],a=Ks(e,n);v({message:`Downloading \`${n}\` binary of the Apify CLI...`});let l=await fetch(i.browser_download_url,{headers:{"User-Agent":ot}});if(!l.ok){let u=await l.text();C("[upgrade] failed to fetch asset",{asset:i,status:l.status,body:u}),p({message:[`Failed to fetch the ${n} 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: ${t}`,`- 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: ${l.status}`,`- The body of the response: ${u}`].join(`
108
- `)});return}if(process.env.APIFY_CLI_DEBUG&&!process.env.APIFY_CLI_FORCE){v({message:`Would write asset ${n} to ${a}`});continue}v({message:qs.gray(`Writing ${n} to ${a}...`)});let m=await l.arrayBuffer();try{let u=await ym(a).then(f=>f.mode).catch(()=>493);await ta(a,Buffer.from(m),{mode:u|448}),C(`[upgrade ${n}] wrote asset to`,a)}catch(u){C("[upgrade] failed to write asset",{error:u}),p({message:[`Failed to write the ${n} 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: ${t}`,`- 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(`
109
- `)})}}}};import{mkdir as Pm,readdir as Lm,stat as fa}from"fs/promises";import{join as ut}from"path";import ga from"process";import{gte as km,minVersion as Dm}from"semver";import{fetchManifest as Fm,manifestUrl as Mm}from"@apify/actor-templates";import{createWriteStream as Sm}from"fs";import{pipeline as vm}from"stream/promises";import{Separator as na}from"@inquirer/core";import bm from"@inquirer/select";var qe=Re(async({message:r,choices:e,pageSize:t,loop:o,default:s})=>await bm({message:r,choices:e,pageSize:t,loop:o,default:s}));var ia=["JavaScript","TypeScript","Python"];async function Ws(r){return r?(Mt(r),r):Tm()}c(Ws,"ensureValidActorName");async function aa(r,e){let t=await e;if(t instanceof Error)throw t;if(r){let o=t.templates.find(s=>s.name===r);if(!o)throw new Error(`Could not find the selected template: ${r} in the list of templates.`);return o}return ua(t)}c(aa,"getTemplateDefinition");async function la(r,e){let t=await e;if(t instanceof Error)throw t;try{let o=await pr(t.localReadmeSuffixUrl),s=Sm(r,{flags:"a"});s.write(`
108
+ `);x({message:s})}async handleInstallSpecificVersion(e){if(e!=="latest"&&!la(e,uo)){p({message:`The minimum version of the CLI you can manually downgrade/upgrade to is ${uo}.`});return}let t=await na(e);if(!t){p({message:"The provided version does not exist. Please check the version number and try again."});return}let{assets:o,version:s}=t;if(!la(s,uo)){p({message:`The minimum version of the CLI you can manually downgrade/upgrade to is ${uo}.`});return}let i=K();if(i.installMethod==="bundle"){if(!o.length){p({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(`
109
+ `)});return}let a=Nu(process.execPath);C("[upgrade] bundleDirectory",a);let l=await Ou(a);if(!l.some(u=>u.startsWith("apify")||u.startsWith("actor"))){C("[upgrade] directoryEntries",l),p({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: ${a}`].join(`
110
+ `)});return}if(i.platform==="windows")return this.startUpgradeProcess(a,s,o);await this.handleUnixUpgrade(a,s,o),this.successMessage(s);return}let n=ca[i.installMethod](e,this.entrypoint);if(process.env.APIFY_CLI_DEBUG){v({message:`Would run command: ${n.join(" ")}`});return}try{await ae({cmd:n[0],args:n.slice(1)}),this.successMessage(s)}catch{p({message:`Failed to upgrade the CLI. Please run the following command manually: ${n.join(" ")}`})}}successMessage(e){R({message:`Successfully upgraded to ${e} \u{1F44D}`})}async startUpgradeProcess(e,t,o){await this.upsertUpgradeScript(e);let s=["-ExecutionPolicy","Bypass","-File",`"${ei(e,"upgrade.ps1")}"`,"-ProcessId",process.pid.toString(),"-InstallLocation",`"${e}"`,"-Version",`"${t}"`],i=o.map(a=>a.browser_download_url).join(",");s.push("-AllUrls",`"${i}"`),C("[upgrade] starting upgrade process with args",s),v({message:"Starting upgrade process..."});let n=Ru("powershell.exe",s,{detached:!0,shell:!0,stdio:"inherit",windowsHide:!1,windowsVerbatimArguments:!0});n.on("spawn",()=>{C("[upgrade] upgrade process spawned"),n.unref(),process.exit(0)}),n.on("error",a=>{p({message:`Failed to start the upgrade process: ${a.message}`})})}async upsertUpgradeScript(e){let t=ei(e,"upgrade.ps1");if(_u(t))return;let o=K(),s=await fetch(ma,{headers:{"User-Agent":ot}});s.ok||(p({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: ${ma}`,`- The status code of the response: ${s.status}`].join(`
111
+ `)}),process.exit(1));let i=await s.arrayBuffer();await aa(t,Buffer.from(i)),C("[upgrade] downloaded upgrade script to",t)}async handleUnixUpgrade(e,t,o){let s=K();for(let i of o){let n=i.name.split("-")[0],a=ei(e,n);v({message:`Downloading \`${n}\` binary of the Apify CLI...`});let l=await fetch(i.browser_download_url,{headers:{"User-Agent":ot}});if(!l.ok){let m=await l.text();C("[upgrade] failed to fetch asset",{asset:i,status:l.status,body:m}),p({message:[`Failed to fetch the ${n} 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: ${t}`,`- 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: ${l.status}`,`- The body of the response: ${m}`].join(`
112
+ `)});return}if(process.env.APIFY_CLI_DEBUG&&!process.env.APIFY_CLI_FORCE){v({message:`Would write asset ${n} to ${a}`});continue}v({message:ti.gray(`Writing ${n} to ${a}...`)});let u=await l.arrayBuffer();try{let m=await xu(a).then(f=>f.mode).catch(()=>493);await aa(a,Buffer.from(u),{mode:m|448}),C(`[upgrade ${n}] wrote asset to`,a)}catch(m){C("[upgrade] failed to write asset",{error:m}),p({message:[`Failed to write the ${n} 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: ${t}`,`- 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: ${m.message}`].join(`
113
+ `)})}}}};import{mkdir as Hu,readdir as Ju,stat as ba}from"fs/promises";import{join as mt}from"path";import Sa from"process";import{gte as Ku,minVersion as qu}from"semver";import{fetchManifest as Wu,manifestUrl as zu}from"@apify/actor-templates";import{createWriteStream as Pu}from"fs";import{pipeline as Lu}from"stream/promises";import{Separator as da}from"@inquirer/core";var ua=["JavaScript","TypeScript","Python"];async function ri(r){return r?(jt(r),r):ku()}c(ri,"ensureValidActorName");async function pa(r,e){let t=await e;if(t instanceof Error)throw t;if(r){let o=t.templates.find(s=>s.name===r);if(!o)throw new Error(`Could not find the selected template: ${r} in the list of templates.`);return o}return ha(t)}c(pa,"getTemplateDefinition");async function fa(r,e){let t=await e;if(t instanceof Error)throw t;try{let o=await gr(t.localReadmeSuffixUrl),s=Pu(r,{flags:"a"});s.write(`
110
114
 
111
- `),await vm(o,s)}catch(o){x({message:`Could not append local development instructions to README.md. Cause: ${o.message}`})}}c(la,"enhanceReadmeWithLocalSuffix");function ca(r){let{actorName:e,dependenciesInstalled:t,postCreate:o,gitRepositoryInitialized:s,installCommandSuggestion:i}=r,n=`\u2705 Actor '${e}' created successfully!`;return t?n+=`
115
+ `),await Lu(o,s)}catch(o){x({message:`Could not append local development instructions to README.md. Cause: ${o.message}`})}}c(fa,"enhanceReadmeWithLocalSuffix");function ga(r){let{actorName:e,dependenciesInstalled:t,postCreate:o,gitRepositoryInitialized:s,installCommandSuggestion:i}=r,n=`\u2705 Actor '${e}' created successfully!`;return t?n+=`
112
116
 
113
117
  Next steps:
114
118
 
@@ -125,53 +129,49 @@ apify run`,n+=`
125
129
  \u{1F4D6} Docs: https://docs.apify.com/platform/actors/development`,s&&(n+=`
126
130
  \u{1F331} Git repository initialized in '${e}'. You can now commit and push your Actor to Git.`),o&&(n+=`
127
131
 
128
- ${o}`),n}c(ca,"formatCreateSuccessMessage");async function ua(r){let e=await Cm();for(;;){let t=await Im(r,e);if(t){if(await Em())return t}else return ua(r)}}c(ua,"executePrompts");async function Tm(){return await st({message:"Name of your new Actor:",validate:c(e=>{try{Mt(e)}catch(t){return t.message}return!0},"validate")})}c(Tm,"promptActorName");async function Cm(){return await qe({message:"Choose the programming language of your new Actor:",choices:ia,loop:!1,default:ia[0]})}c(Cm,"promptProgrammingLanguage");async function Im(r,e){let t=[...r.templates.filter(s=>s.category.toLowerCase()===e.toLowerCase()).map(s=>({name:s.label,value:s})),new na,{name:"Go back",value:!1}];return await qe({message:"Choose a template for your new Actor. You can check more information at https://apify.com/templates.",default:t[0],choices:t,loop:!1,pageSize:8})}c(Im,"promptTemplateDefinition");async function Em(){let r=[{name:"Install dependencies",value:!0},new na,{name:"Go back",value:!1}];return await qe({message:"Almost done! Last step is to install dependencies.",default:r[0],choices:r,loop:!1})}c(Em,"promptTemplateInstallation");import{existsSync as $m,writeFileSync as Rm}from"fs";import{join as lo}from"path";import _m from"process";import xm from"lodash.clonedeep";import{KEY_VALUE_STORE_KEYS as Om}from"@apify/consts";import{validateInputSchema as Nm}from"@apify/input_schema";var ma=[".actor/INPUT_SCHEMA.json","./INPUT_SCHEMA.json",".actor/input_schema.json","./input_schema.json"],ct=c(async({forcePath:r,cwd:e}={cwd:_m.cwd()})=>{if(r)return{inputSchema:de(r),inputSchemaPath:r};let t=Me(e);if(typeof t?.input=="object")return{inputSchema:t.input,inputSchemaPath:null};if(typeof t?.input=="string"){let o=lo(e,ws,t.input);return{inputSchema:de(o),inputSchemaPath:o}}for(let o of ma){let s=lo(e,o);if($m(s))return{inputSchema:de(s),inputSchemaPath:s}}return{inputSchema:null,inputSchemaPath:lo(e,ma[0])}},"readInputSchema"),co=c(async r=>{let e={};try{let{inputSchema:t}=await ct({cwd:r});if(t){let o=new pt({strict:!1});Nm(o,t),e=Object.entries(t.properties).reduce((s,[i,n])=>(s[i]=n.type==="boolean"||n.editor==="hidden"?n.default:n.prefill,s),{})}}catch(t){x({message:`Could not create default input based on input schema, creating empty input instead. Cause: ${t.message}`})}finally{let t=ue(),o=lo(r,t,`${Om.INPUT}.json`);Rm(o,JSON.stringify(e,null," "))}},"createPrefilledInputFileFromInputSchema"),da=c(r=>{let e={};for(let[t,o]of Object.entries(r.properties))o.default!==void 0&&(e[t]=o.default);return e},"getDefaultsFromInputSchema"),pa=c((r,e)=>{let t=xm(r);t.required=[];for(let[o,s]of Object.entries(r.properties)){let i=r.required?.includes(o),n=s.default!==void 0;i&&!n&&(t.required.push(o),s.type==="array"&&(s.minItems=Math.max(1,s.minItems||0)))}return delete t.$schema,e.compile(t)},"getAjvValidator");var uo=class extends h{static name="create";static description="Creates an Actor project from a template in a new directory. The command automatically initializes a git repository in the newly created Actor directory.";static flags={template:w.string({char:"t",description:`Template for the Actor. If not provided, the command will prompt for it. Visit ${Mm} to find available template names.`,required:!1}),"skip-dependency-install":w.boolean({description:"Skip installing Actor dependencies.",required:!1}),"template-archive-url":w.string({description:"Actor template archive url. Useful for developing new templates.",required:!1,hidden:!0}),"omit-optional-deps":w.boolean({aliases:["no-optional"],description:"Skip installing optional dependencies.",required:!1}),"skip-git-init":w.boolean({description:"Skip initializing a git repository in the Actor directory.",required:!1})};static args={actorName:A.string({required:!1,description:"Name of the Actor and its directory"})};async run(){let{actorName:e}=this.args,{template:t,skipDependencyInstall:o,skipGitInit:s}=this.flags,{templateArchiveUrl:i}=this.flags,n=!1,a=Fm().catch(T=>new Error(`Could not fetch template list from server. Cause: ${T?.message}`));e=await Ws(e);let l=ga.cwd(),m=ut(l,e);for(;;){let T=await fa(m).catch(()=>null),N=T&&await Lm(m).then(P=>P.length>0).catch(()=>!1);if(T?.isDirectory()&&N){p({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 Ws(),m=ut(l,e);continue}T||await Pm(m,{recursive:!0});break}let u=null;if(this.telemetryData.fromArchiveUrl=!!i,!i){let T=await aa(t,a);({archiveUrl:i,messages:u}=T),this.telemetryData.templateId=T.id,this.telemetryData.templateName=T.name,this.telemetryData.templateLanguage=T.category,"skipOptionalDeps"in T&&(n=T.skipOptionalDeps)}this.flags.omitOptionalDeps&&(n=!0),await wr({url:i,pathTo:m});let f=de(ut(m,V));await fr(Object.assign(f||nr,{name:e}),m),await gr(m),await co(m);let d=ut(m,"package.json"),g=ut(m,"README.md");await la(g,a);let y=!1;o||await(await _e({cwd:m})).inspectAsync(async N=>{let P=Dm(be);if(!N.runtime){switch(N.type){case 0:{x({message:`No Node.js detected! Please install Node.js ${P} or higher to be able to run Node.js Actors locally.`});break}case 2:case 1:{x({message:`No Python detected! Please install Python ${tt} or higher to be able to run Python Actors locally.`});break}default:}return}let{runtime:L}=N;switch(N.type){case 0:{yr(L.version)||x({message:`You are running Node.js version ${L.version}, which is no longer supported. Please upgrade to Node.js version ${P} or later.`}),await hi(d,{name:e});let D=["install"];if(n)switch(L.pmName){case"npm":{km(L.pmVersion,"7.0.0")?D.push("--omit=optional"):D.push("--no-optional");break}case"bun":{D.push("--omit=optional");break}case"deno":{D.push("--node-modules-dir");break}default:}await ne({cmd:L.pmPath,args:D,opts:{cwd:m},overrideCommand:L.pmName}),y=!0;break}case 1:case 2:{if(!hr(L.version)){x({message:`Python Actors require Python 3.9 or higher, but you have Python ${L.version}!`}),x({message:"Please install Python 3.9 or higher to be able to run Python Actors locally."});return}let D=ut(m,".venv");v({message:`Python version ${L.version} detected.`}),v({message:`Creating a virtual environment in "${D}" and installing dependencies from "requirements.txt"...`}),ga.env.VIRTUAL_ENV||(await ne({cmd:L.executablePath,args:["-m","venv","--prompt",".",pi],opts:{cwd:m}}),L=(await Gt({cwd:m,force:!0})).unwrap(),N.runtime=L),await ne({cmd:L.executablePath,args:["-m","pip","install","--no-cache-dir","--no-warn-script-location","--upgrade","pip","setuptools","wheel"],opts:{cwd:m}}),await ne({cmd:L.executablePath,args:["-m","pip","install","--no-cache-dir","--no-warn-script-location","-r","requirements.txt"],opts:{cwd:m}}),y=!0;break}default:}});let b={success:!0},S=await fa(ut(l,".git")).catch(()=>null);if(!s&&!S)try{await ne({cmd:"git",args:["init"],opts:{cwd:m}})}catch(T){b={success:!1,error:T}}let E=y?null:await Ki(m);R({message:""}),$({message:ca({actorName:e,dependenciesInstalled:y,postCreate:u?.postCreate??null,gitRepositoryInitialized:!s&&!S&&b.success,installCommandSuggestion:E})}),!s&&!S&&!b.success&&(x({message:`Failed to initialize git repository: ${b.error.message}`}),x({message:'You can manually run "git init" in the Actor directory if needed.'}))}};import ya from"chalk";async function ha(r,e,t){let o=await r[t](e).get().catch(()=>{});if(o)return{[t]:o,[`${t}Client`]:r[t](o.id)};let s=await M(),i=await r[t](`${s.username}/${e}`).get().catch(()=>{});return i?{[t]:i,[`${t}Client`]:r[t](i.id)}:null}c(ha,"tryToGetStorage");async function Le(r,e){return ha(r,e,"dataset")}c(Le,"tryToGetDataset");async function te(r,e){return ha(r,e,"keyValueStore")}c(te,"tryToGetKeyValueStore");var mo=class extends h{static name="create";static description="Creates a new dataset for storing structured data on your account.";static args={datasetName:A.string({description:"Optional name for the Dataset",required:!1})};static enableJsonFlag=!0;async run(){let{datasetName:e}=this.args,t=await I();if(e&&await Le(t,e)){p({message:"A Dataset with this name already exists!"});return}let o=await t.datasets().getOrCreate(e);if(this.flags.json){k(o);return}$({message:`Dataset with ID ${ya.yellow(o.id)}${e?` (called ${ya.yellow(e)})`:""} was created.`,stdout:!0})}};import{DownloadItemsFormat as We}from"apify-client";var wa={[We.JSON]:"application/json",[We.JSONL]:"application/jsonl",[We.CSV]:"text/csv",[We.HTML]:"text/html",[We.RSS]:"application/rss+xml",[We.XML]:"application/xml",[We.XLSX]:"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"},po=class extends h{static name="get-items";static description="Retrieves dataset items in specified format (JSON, CSV, etc).";static flags={limit:w.integer({description:"The amount of elements to get from the dataset. By default, it will return all available items."}),offset:w.integer({description:"The offset in the dataset where to start getting items."}),format:w.string({description:"The format of the returned output. By default, it is set to 'json'",choices:Object.keys(wa),default:We.JSON})};static args={datasetId:A.string({description:"The ID of the Dataset to export the items for",required:!0})};async run(){let{limit:e,offset:t,format:o}=this.flags,{datasetId:s}=this.args,i=await I(),n=await this.tryToGetDataset(i,s);if(!n){p({message:`Dataset with ID "${s}" not found.`});return}let{datasetClient:a}=n;process.stdout.write("");let l=await a.downloadItems(o,{limit:e,offset:t}),m=wa[o]??"application/octet-stream";R({message:m}),process.stdout.write(l),process.stdout.write(`
129
- `)}async tryToGetDataset(e,t){let o=await e.dataset(t).get().catch(()=>{});if(o)return{dataset:o,datasetClient:e.dataset(o.id)};let s=await M(),i=await e.dataset(`${s.username}/${t}`).get().catch(()=>{});return i?{dataset:i,datasetClient:e.dataset(i.id)}:null}};import j from"chalk";function fo(r){let e=Reflect.get(r,"planPricing");return e?Reflect.get(e,"chargeableServiceUnitPricesUsd"):null}c(fo,"getUserPlanPricing");var Aa=new G({allColumns:["Row1","Row2"],mandatoryColumns:["Row1","Row2"]}),go=class extends h{static name="info";static description="Prints information about a specific dataset.";static args={storeId:A.string({description:"The dataset store ID to print information about.",required:!0})};static enableJsonFlag=!0;async run(){let{storeId:e}=this.args,t=await I(),o=await Le(t,e);if(!o){p({message:`Key-value store with ID or name "${e}" not found.`});return}let{dataset:s}=o,[i,n,a]=await Promise.all([t.user(s.userId).get().then(F=>F),s.actId?t.actor(s.actId).get():Promise.resolve(void 0),s.actRunId?t.run(s.actRunId).get():Promise.resolve(void 0)]),l;if(a?.actorTaskId&&(l=await t.task(a.actorTaskId).get().catch(()=>{})),this.flags.json){k({...s,user:i,actor:n||null,run:a||null,task:l||null});return}let m=s.stats?.storageBytes||0,u=s.stats?.readCount||0,f=s.stats?.writeCount||0,d=(s.cleanItemCount||0).toLocaleString("en-US"),g=(s.itemCount||0).toLocaleString("en-US"),y=[`${j.bold(u.toLocaleString("en-US"))} ${j.gray(this.pluralString(u,"read","reads"))}`,`${j.bold(f.toLocaleString("en-US"))} ${j.gray(this.pluralString(f,"write","writes"))}`],b=`Items: ${j.bold(d)} ${j.gray("clean")} / ${j.bold(g)} ${j.gray("total")}
130
- Operations: ${y.join(" / ")}`;if(i.plan){let F=fo(i.plan);if(F){let Q=F.KEY_VALUE_STORE_TIMED_STORAGE_GBYTE_HOURS*(m/1e9),ye=Q*24*30,we=ye>1?`$${ye.toFixed(2)}`:`$${Q.toFixed(3)}`;b+=`
131
- Storage size: ${X({bytes:m,shortBytes:!0,precision:1})} / ${j.gray(`${we} per month`)}`}}else b+=`
132
- Storage size: ${X({bytes:m,shortBytes:!0,precision:1})}`;let S=[`Dataset ID: ${j.bgGray(s.id)}`,`Name: ${s.name?j.bgGray(s.name):j.bold(j.italic("Unnamed"))}`,`Created: ${j.bold(B.display(s.createdAt))}`,`Modified: ${j.bold(B.display(s.modifiedAt))}`].join(`
132
+ ${o}`),n}c(ga,"formatCreateSuccessMessage");async function ha(r){let e=await Du();for(;;){let t=await Fu(r,e);if(t){if(await Mu())return t}else return ha(r)}}c(ha,"executePrompts");async function ku(){return await st({message:"Name of your new Actor:",validate:c(e=>{try{jt(e)}catch(t){return t.message}return!0},"validate")})}c(ku,"promptActorName");async function Du(){return await Ke({message:"Choose the programming language of your new Actor:",choices:ua,loop:!1,default:ua[0]})}c(Du,"promptProgrammingLanguage");async function Fu(r,e){let t=[...r.templates.filter(s=>s.category.toLowerCase()===e.toLowerCase()).map(s=>({name:s.label,value:s})),new da,{name:"Go back",value:!1}];return await Ke({message:"Choose a template for your new Actor. You can check more information at https://apify.com/templates.",default:t[0],choices:t,loop:!1,pageSize:8})}c(Fu,"promptTemplateDefinition");async function Mu(){let r=[{name:"Install dependencies",value:!0},new da,{name:"Go back",value:!1}];return await Ke({message:"Almost done! Last step is to install dependencies.",default:r[0],choices:r,loop:!1})}c(Mu,"promptTemplateInstallation");import{existsSync as Uu,writeFileSync as ju}from"fs";import{join as po}from"path";import Vu from"process";import Bu from"lodash.clonedeep";import{KEY_VALUE_STORE_KEYS as Gu}from"@apify/consts";import{validateInputSchema as Yu}from"@apify/input_schema";var ya=[".actor/INPUT_SCHEMA.json","./INPUT_SCHEMA.json",".actor/input_schema.json","./input_schema.json"],ct=c(async({forcePath:r,cwd:e}={cwd:Vu.cwd()})=>{if(r)return{inputSchema:de(r),inputSchemaPath:r};let t=Ue(e);if(typeof t?.input=="object")return{inputSchema:t.input,inputSchemaPath:null};if(typeof t?.input=="string"){let o=po(e,vs,t.input);return{inputSchema:de(o),inputSchemaPath:o}}for(let o of ya){let s=po(e,o);if(Uu(s))return{inputSchema:de(s),inputSchemaPath:s}}return{inputSchema:null,inputSchemaPath:po(e,ya[0])}},"readInputSchema"),fo=c(async r=>{let e={};try{let{inputSchema:t}=await ct({cwd:r});if(t){let o=new pt({strict:!1});Yu(o,t),e=Object.entries(t.properties).reduce((s,[i,n])=>(s[i]=n.type==="boolean"||n.editor==="hidden"?n.default:n.prefill,s),{})}}catch(t){x({message:`Could not create default input based on input schema, creating empty input instead. Cause: ${t.message}`})}finally{let t=me(),o=po(r,t,`${Gu.INPUT}.json`);ju(o,JSON.stringify(e,null," "))}},"createPrefilledInputFileFromInputSchema"),wa=c(r=>{let e={};for(let[t,o]of Object.entries(r.properties))o.default!==void 0&&(e[t]=o.default);return e},"getDefaultsFromInputSchema"),Aa=c((r,e)=>{let t=Bu(r);t.required=[];for(let[o,s]of Object.entries(r.properties)){let i=r.required?.includes(o),n=s.default!==void 0;i&&!n&&(t.required.push(o),s.type==="array"&&(s.minItems=Math.max(1,s.minItems||0)))}return delete t.$schema,e.compile(t)},"getAjvValidator");var go=class extends h{static name="create";static description="Creates an Actor project from a template in a new directory. The command automatically initializes a git repository in the newly created Actor directory.";static flags={template:w.string({char:"t",description:`Template for the Actor. If not provided, the command will prompt for it. Visit ${zu} to find available template names.`,required:!1}),"skip-dependency-install":w.boolean({description:"Skip installing Actor dependencies.",required:!1}),"template-archive-url":w.string({description:"Actor template archive url. Useful for developing new templates.",required:!1,hidden:!0}),"omit-optional-deps":w.boolean({aliases:["no-optional"],description:"Skip installing optional dependencies.",required:!1}),"skip-git-init":w.boolean({description:"Skip initializing a git repository in the Actor directory.",required:!1})};static args={actorName:A.string({required:!1,description:"Name of the Actor and its directory"})};async run(){let{actorName:e}=this.args,{template:t,skipDependencyInstall:o,skipGitInit:s}=this.flags,{templateArchiveUrl:i}=this.flags,n=!1,a=Wu().catch(T=>new Error(`Could not fetch template list from server. Cause: ${T?.message}`));e=await ri(e);let l=Sa.cwd(),u=mt(l,e);for(;;){let T=await ba(u).catch(()=>null),N=T&&await Ju(u).then(P=>P.length>0).catch(()=>!1);if(T?.isDirectory()&&N){p({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 ri(),u=mt(l,e);continue}T||await Hu(u,{recursive:!0});break}let m=null;if(this.telemetryData.fromArchiveUrl=!!i,!i){let T=await pa(t,a);({archiveUrl:i,messages:m}=T),this.telemetryData.templateId=T.id,this.telemetryData.templateName=T.name,this.telemetryData.templateLanguage=T.category,"skipOptionalDeps"in T&&(n=T.skipOptionalDeps)}this.flags.omitOptionalDeps&&(n=!0),await br({url:i,pathTo:u});let f=de(mt(u,V));await hr(Object.assign(f||lr,{name:e}),u),await yr(u),await fo(u);let d=mt(u,"package.json"),g=mt(u,"README.md");await fa(g,a);let y=!1;o||await(await _e({cwd:u})).inspectAsync(async N=>{let P=qu(be);if(!N.runtime){switch(N.type){case 0:{x({message:`No Node.js detected! Please install Node.js ${P} or higher to be able to run Node.js Actors locally.`});break}case 2:case 1:{x({message:`No Python detected! Please install Python ${tt} or higher to be able to run Python Actors locally.`});break}default:}return}let{runtime:L}=N;switch(N.type){case 0:{Ar(L.version)||x({message:`You are running Node.js version ${L.version}, which is no longer supported. Please upgrade to Node.js version ${P} or later.`}),await bi(d,{name:e});let D=["install"];if(n)switch(L.pmName){case"npm":{Ku(L.pmVersion,"7.0.0")?D.push("--omit=optional"):D.push("--no-optional");break}case"bun":{D.push("--omit=optional");break}case"deno":{D.push("--node-modules-dir");break}default:}await ae({cmd:L.pmPath,args:D,opts:{cwd:u},overrideCommand:L.pmName}),y=!0;break}case 1:case 2:{if(!wr(L.version)){x({message:`Python Actors require Python 3.9 or higher, but you have Python ${L.version}!`}),x({message:"Please install Python 3.9 or higher to be able to run Python Actors locally."});return}let D=mt(u,".venv");v({message:`Python version ${L.version} detected.`}),v({message:`Creating a virtual environment in "${D}" and installing dependencies from "requirements.txt"...`}),Sa.env.VIRTUAL_ENV||(await ae({cmd:L.executablePath,args:["-m","venv","--prompt",".",yi],opts:{cwd:u}}),L=(await Ht({cwd:u,force:!0})).unwrap(),N.runtime=L),await ae({cmd:L.executablePath,args:["-m","pip","install","--no-cache-dir","--no-warn-script-location","--upgrade","pip","setuptools","wheel"],opts:{cwd:u}}),await ae({cmd:L.executablePath,args:["-m","pip","install","--no-cache-dir","--no-warn-script-location","-r","requirements.txt"],opts:{cwd:u}}),y=!0;break}default:}});let b={success:!0},S=await ba(mt(l,".git")).catch(()=>null);if(!s&&!S)try{await ae({cmd:"git",args:["init"],opts:{cwd:u}})}catch(T){b={success:!1,error:T}}let E=y?null:await Xi(u);$({message:""}),R({message:ga({actorName:e,dependenciesInstalled:y,postCreate:m?.postCreate??null,gitRepositoryInitialized:!s&&!S&&b.success,installCommandSuggestion:E})}),!s&&!S&&!b.success&&(x({message:`Failed to initialize git repository: ${b.error.message}`}),x({message:'You can manually run "git init" in the Actor directory if needed.'}))}};import Ta from"chalk";async function va(r,e,t){let o=await r[t](e).get().catch(()=>{});if(o)return{[t]:o,[`${t}Client`]:r[t](o.id)};let s=await F(),i=await r[t](`${s.username}/${e}`).get().catch(()=>{});return i?{[t]:i,[`${t}Client`]:r[t](i.id)}:null}c(va,"tryToGetStorage");async function Le(r,e){return va(r,e,"dataset")}c(Le,"tryToGetDataset");async function te(r,e){return va(r,e,"keyValueStore")}c(te,"tryToGetKeyValueStore");var ho=class extends h{static name="create";static description="Creates a new dataset for storing structured data on your account.";static args={datasetName:A.string({description:"Optional name for the Dataset",required:!1})};static enableJsonFlag=!0;async run(){let{datasetName:e}=this.args,t=await I();if(e&&await Le(t,e)){p({message:"A Dataset with this name already exists!"});return}let o=await t.datasets().getOrCreate(e);if(this.flags.json){k(o);return}R({message:`Dataset with ID ${Ta.yellow(o.id)}${e?` (called ${Ta.yellow(e)})`:""} was created.`,stdout:!0})}};import{DownloadItemsFormat as We}from"apify-client";var Ca={[We.JSON]:"application/json",[We.JSONL]:"application/jsonl",[We.CSV]:"text/csv",[We.HTML]:"text/html",[We.RSS]:"application/rss+xml",[We.XML]:"application/xml",[We.XLSX]:"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"},yo=class extends h{static name="get-items";static description="Retrieves dataset items in specified format (JSON, CSV, etc).";static flags={limit:w.integer({description:"The amount of elements to get from the dataset. By default, it will return all available items."}),offset:w.integer({description:"The offset in the dataset where to start getting items."}),format:w.string({description:"The format of the returned output. By default, it is set to 'json'",choices:Object.keys(Ca),default:We.JSON})};static args={datasetId:A.string({description:"The ID of the Dataset to export the items for",required:!0})};async run(){let{limit:e,offset:t,format:o}=this.flags,{datasetId:s}=this.args,i=await I(),n=await this.tryToGetDataset(i,s);if(!n){p({message:`Dataset with ID "${s}" not found.`});return}let{datasetClient:a}=n;process.stdout.write("");let l=await a.downloadItems(o,{limit:e,offset:t}),u=Ca[o]??"application/octet-stream";$({message:u}),process.stdout.write(l),process.stdout.write(`
133
+ `)}async tryToGetDataset(e,t){let o=await e.dataset(t).get().catch(()=>{});if(o)return{dataset:o,datasetClient:e.dataset(o.id)};let s=await F(),i=await e.dataset(`${s.username}/${t}`).get().catch(()=>{});return i?{dataset:i,datasetClient:e.dataset(i.id)}:null}};import j from"chalk";function wo(r){let e=Reflect.get(r,"planPricing");return e?Reflect.get(e,"chargeableServiceUnitPricesUsd"):null}c(wo,"getUserPlanPricing");var Ia=new G({allColumns:["Row1","Row2"],mandatoryColumns:["Row1","Row2"]}),Ao=class extends h{static name="info";static description="Prints information about a specific dataset.";static args={storeId:A.string({description:"The dataset store ID to print information about.",required:!0})};static enableJsonFlag=!0;async run(){let{storeId:e}=this.args,t=await I(),o=await Le(t,e);if(!o){p({message:`Key-value store with ID or name "${e}" not found.`});return}let{dataset:s}=o,[i,n,a]=await Promise.all([t.user(s.userId).get().then(M=>M),s.actId?t.actor(s.actId).get():Promise.resolve(void 0),s.actRunId?t.run(s.actRunId).get():Promise.resolve(void 0)]),l;if(a?.actorTaskId&&(l=await t.task(a.actorTaskId).get().catch(()=>{})),this.flags.json){k({...s,user:i,actor:n||null,run:a||null,task:l||null});return}let u=s.stats?.storageBytes||0,m=s.stats?.readCount||0,f=s.stats?.writeCount||0,d=(s.cleanItemCount||0).toLocaleString("en-US"),g=(s.itemCount||0).toLocaleString("en-US"),y=[`${j.bold(m.toLocaleString("en-US"))} ${j.gray(this.pluralString(m,"read","reads"))}`,`${j.bold(f.toLocaleString("en-US"))} ${j.gray(this.pluralString(f,"write","writes"))}`],b=`Items: ${j.bold(d)} ${j.gray("clean")} / ${j.bold(g)} ${j.gray("total")}
134
+ Operations: ${y.join(" / ")}`;if(i.plan){let M=wo(i.plan);if(M){let Q=M.KEY_VALUE_STORE_TIMED_STORAGE_GBYTE_HOURS*(u/1e9),ye=Q*24*30,we=ye>1?`$${ye.toFixed(2)}`:`$${Q.toFixed(3)}`;b+=`
135
+ Storage size: ${X({bytes:u,shortBytes:!0,precision:1})} / ${j.gray(`${we} per month`)}`}}else b+=`
136
+ Storage size: ${X({bytes:u,shortBytes:!0,precision:1})}`;let S=[`Dataset ID: ${j.bgGray(s.id)}`,`Name: ${s.name?j.bgGray(s.name):j.bold(j.italic("Unnamed"))}`,`Created: ${j.bold(B.display(s.createdAt))}`,`Modified: ${j.bold(B.display(s.modifiedAt))}`].join(`
133
137
  `),E=j.bold("\u2014");s.actRunId&&(a?E=j.bgBlue(a.id):E=j.italic(j.gray("Run removed")));let T=j.bold("\u2014");n&&(T=j.blue(n.title||n.name));let N=j.bold("\u2014");l&&(N=j.blue(l.title||l.name));let P=[`Run: ${E}`,`Actor: ${T}`,`Task: ${N}`].join(`
134
- `);Aa.pushRow({Row1:S,Row2:P});let D=Aa.render(2).split(`
135
- `).map(F=>F.trim());D.shift();let J=[`${j.bold(s.name||j.italic("Unnamed"))}`,`${j.gray(s.name?`${i.username}/${s.name}`:s.id)} ${j.gray("Owned by")} ${j.blue(i.username)}`,"",D.join(`
138
+ `);Ia.pushRow({Row1:S,Row2:P});let D=Ia.render(2).split(`
139
+ `).map(M=>M.trim());D.shift();let J=[`${j.bold(s.name||j.italic("Unnamed"))}`,`${j.gray(s.name?`${i.username}/${s.name}`:s.id)} ${j.gray("Owned by")} ${j.blue(i.username)}`,"",D.join(`
136
140
  `),"",b].join(`
137
- `);R({message:J,stdout:!0})}};import ba from"chalk";var Sa=new G({allColumns:["Dataset ID","Name","Items","Size","Created","Modified"],mandatoryColumns:["Dataset ID","Name","Items","Size"],columnAlignments:{Items:"right"}}),ho=class extends h{static name="ls";static description="Prints all datasets on your account.";static flags={offset:w.integer({description:"Number of datasets that will be skipped.",default:0}),limit:w.integer({description:"Number of datasets that will be listed.",default:20}),desc:w.boolean({description:"Sorts datasets in descending order.",default:!1}),unnamed:w.boolean({description:"Lists datasets that don't have a name set.",default:!1})};static enableJsonFlag=!0;async run(){let{desc:e,offset:t,limit:o,json:s,unnamed:i}=this.flags,n=await I(),a=await M(),l=await n.datasets().list({desc:e,offset:t,limit:o,unnamed:i});if(s){k(l);return}if(l.count===0){v({message:"You don't have any Datasets on your account",stdout:!0});return}for(let m of l.items){let u=Reflect.get(m.stats,"s3StorageBytes");Sa.pushRow({"Dataset ID":m.id,Created:B.display(m.createdAt),Items:`${m.itemCount}`,Modified:B.display(m.modifiedAt),Name:m.name?`${a.username}/${m.name}`:"",Size:typeof u=="number"?X({bytes:u,shortBytes:!0,colorFunc:ba.gray,precision:0}):ba.gray("N/A")})}R({message:Sa.render(1),stdout:!0})}};import yo from"chalk";var wo=class extends h{static name="push-items";static description="Adds data items to specified dataset. Accepts single object or array of objects.";static args={nameOrId:A.string({required:!0,description:"The dataset ID or name to push the objects to",ignoreStdin:!0}),item:A.string({description:"The object or array of objects to be pushed."})};async run(){let{nameOrId:e,item:t}=this.args,o=await I(),s=await Le(o,e);if(!s){p({message:`Dataset with ID or name "${e}" not found.`});return}let{datasetClient:i,dataset:n}=s,a,l=t||Ce;if(!l){p({message:"No items were provided."});return}try{a=JSON.parse(l.toString("utf8"))}catch(u){p({message:`Failed to parse data as JSON string: ${u.message}`});return}if(Array.isArray(a)&&a.length===0){p({message:"No items were provided."});return}let m=n.name?`Dataset named ${yo.yellow(n.name)} (${yo.gray("ID:")} ${yo.yellow(n.id)})`:`Dataset with ID ${yo.yellow(n.id)}`;try{await i.pushItems(a),$({message:`${this.pluralString(Array.isArray(a)?a.length:1,"Object","Objects")} pushed to ${m} successfully.`})}catch(u){let f=u;p({message:`Failed to push items into ${m}
138
- ${f.message||f}`})}}};import ze from"chalk";var Ao=class extends h{static name="rename";static description="Change dataset name or removes name with --unname flag.";static flags={unname:w.boolean({description:"Removes the unique name of the dataset."})};static args={nameOrId:A.string({description:"The dataset ID or name to delete.",required:!0}),newName:A.string({description:"The new name for the dataset."})};async run(){let{unname:e}=this.flags,{newName:t,nameOrId:o}=this.args;if(!t&&!e){p({message:"You must provide either a new name or the --unname flag."});return}if(t&&e){p({message:"You cannot provide a new name and the --unname flag."});return}let s=await I(),i=await Le(s,o);if(!i){p({message:`Dataset with ID or name "${o}" not found.`});return}let{id:n,name:a}=i.dataset,l=a?e?`The name of the dataset with ID ${ze.yellow(n)} has been removed (was ${ze.yellow(a)} previously).`:`The name of the dataset with ID ${ze.yellow(n)} was changed from ${ze.yellow(a)} to ${ze.yellow(t)}.`:`The name of the dataset with ID ${ze.yellow(n)} has been set to: ${ze.yellow(t)}`;try{await i.datasetClient.update({name:e?null:t}),$({message:l,stdout:!0})}catch(m){let u=m;p({message:`Failed to rename dataset with ID ${ze.yellow(n)}
139
- ${u.message||u}`})}}};import zs from"chalk";var bo=class extends h{static name="rm";static description="Permanently removes a dataset.";static args={datasetNameOrId:A.string({description:"The dataset ID or name to delete",required:!0})};async run(){let{datasetNameOrId:e}=this.args,t=await I(),o=await Le(t,e);if(!o){p({message:`Dataset with ID or name "${e}" not found.`});return}if(!await z({message:"Are you sure you want to delete this Dataset?"})){v({message:"Dataset deletion has been aborted."});return}let{id:i,name:n}=o.dataset;try{await o.datasetClient.delete(),$({message:`Dataset with ID ${zs.yellow(i)}${n?` (called ${zs.yellow(n)})`:""} has been deleted.`,stdout:!0})}catch(a){let l=a;p({message:`Failed to delete dataset with ID ${zs.yellow(i)}
140
- ${l.message||l}`})}}};var So=class extends h{static name="datasets";static description="Manages structured data storage and retrieval.";static subcommands=[mo,po,ho,go,bo,Ao,wo];async run(){this.printHelp()}};import{existsSync as Xs,mkdirSync as Um,readFileSync as jm,writeFileSync as Vm}from"fs";import{dirname as Bm}from"path";import Gm from"cors";import Ym from"detect-indent";import Zs from"express";import Hm from"open";import{cryptoRandomObjectId as Jm}from"@apify/utilities";var Ta="https://apify.github.io/input-schema-editor-react/",Km=new URL(Ta).origin,va="v1",vo=class extends h{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:A.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:t}=await ct({forcePath:this.args.path,cwd:process.cwd()});if(e&&!t)throw new Error(`Editing an input schema directly embedded in '${V}' is not yet supported.`);x({message:`This command is still experimental and might break at any time. Use at your own risk.
141
- `}),v({message:`Editing input schema at "${t}"...`});let o,s=Zs();s.use(Gm({origin:Km,allowedHeaders:["Content-Type","Authorization"]})),s.use((f,d,g)=>{d.set("Connection","close"),g()}),s.use(Zs.json());let i=Jm();s.use((f,d,g)=>{let{token:y}=f.query;if(!y){let b=f.get("Authorization");if(b){let[S,E,...T]=b.trim().split(/\s+/);S.toLowerCase()==="bearer"&&E&&T.length===0&&(y=E)}}y!==i?(d.status(401),d.send("Authorization failed")):g()});let n=Zs.Router();s.use(`/api/${va}`,n);let a=" ",l=!0;n.get("/input-schema",(f,d)=>{let g;try{g=Xs(t)?jm(t,{encoding:"utf-8"}):`{}
142
- `,g.length>3&&(a=Ym(g).indent||a),g&&(l=g[g.length-1]===`
143
- `),Xs(t)?v({message:`Input schema loaded from "${t}"`}):v({message:"Empty input schema initialized."})}catch(b){let S=`Reading input schema from disk failed with: ${b.message}`;p({message:S}),d.status(500),d.send(S);return}let y;try{y=JSON.parse(g||"{}")}catch(b){let S=`Parsing input schema failed with error: ${b.message}`;p({message:S}),d.status(500),d.send(S);return}d.send(y),v({message:"Input schema sent to editor."})}),n.post("/input-schema",(f,d)=>{try{v({message:"Got input schema from editor..."});let g=f.body,y=JSON.stringify(g,null,a);l&&(y+=`
144
- `);let b=Bm(t);Xs(b)||Um(b,{recursive:!0}),Vm(t,y,{encoding:"utf-8",flag:"w+"}),d.end(),v({message:"Input schema saved to disk."})}catch(g){let y=`Saving input schema failed with error: ${g.message}`;p({message:y}),d.status(500),d.send(y)}}),n.post("/exit",(f,d)=>{f.body.isWindowClosed?v({message:"Editor closed, finishing..."}):v({message:"Editing finished, you can close the editor."}),d.end(),o.close(()=>$({message:"Done."}))}),o=s.listen(0);let{port:m}=o.address();v({message:`Listening for messages from input schema editor on port ${m}...`});let u=`${Ta}?localCliPort=${m}&localCliToken=${i}&localCliApiVersion=${va}`;v({message:`Opening input schema editor at "${u}"...`}),await Hm(u)}};import To from"chalk";var er=class extends h{static name="help";static description="Prints out help about a command, or all available commands.";static hidden=!0;static args={commandString:A.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=kr(this.entrypoint);console.log(i);return}let t=e.toLowerCase(),o=q.get(t);if(!o){let i=Mr(t),n=To.gray(`Command ${To.whiteBright(e)} not found`);i.length&&(n+=`
145
- `,n+=To.gray(`Did you mean: ${i.map(a=>To.whiteBright(a)).join(", ")}?`)),p({message:n});return}let s=Pr(o);console.log(s)}};import Ca from"chalk";var Co=class extends h{static name="info";static description="Prints details about your currently authenticated Apify account.";async run(){await I();let e=await M();if(e){let t={username:e.username,userId:e.id};for(let o of Object.keys(t))console.log(`${Ca.gray(o)}: ${Ca.bold(t[o])}`)}}};import{basename as ld}from"path";import ri from"process";import{appendFileSync as qm,copyFileSync as Wm,createWriteStream as zm,existsSync as Qs,mkdirSync as Xm,readFileSync as Ia,rmSync as Zm,writeFileSync as Qm}from"fs";import{basename as ed,join as ei,relative as Ea,sep as ti}from"path";import{fileURLToPath as td}from"url";import rd from"@root/walk";import od from"configparser";import sd from"handlebars";import{fetchManifest as id,wrapperManifestUrl as nd}from"@apify/actor-templates";var ad=[".dockerignore",".gitignore"],Io=td(new URL("./templates/python-scrapy",import.meta.url));async function $a(r,e,t={bindings:{}}){await rd.walk(r,async(o,s,i)=>{if(s===r)return;let n=Ea(r,s),a=n.split(ti).map(m=>{if(m.startsWith("{")&&m.endsWith("}")){m=m.replace("{","").replace("}","");let u=t.bindings[m];if(!u)throw new Error(`Binding for ${m} not found.`);return u}return m}).join(ti),l=ei(e,a);if(i.isDirectory())return Qs(l)||Xm(l),$a(s,l);n.includes(".template")?Qm(ei(e,a.replace(".template","")),sd.compile(Ia(s,"utf8"))(t.bindings)):Qs(l)&&ad.includes(ed(a))?qm(l,Ia(s)):Wm(s,l)})}c($a,"merge");async function Eo({projectPath:r}){r||(r=".");let e=new it(r);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 t=await qe({message:"Pick the Scrapy spider you want to wrap:",choices:e.getAvailableSpiders().map((m,u)=>({name:`${m.class_name} (${m.pathname})`,value:u}))});function o(m){return`.${Ea(r,m).split(ti).slice(1).join(".").replace(".py","")}`}c(o,"translatePathToRelativeModuleName");let s={botName:Di(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()[t].class_name,spider_module_name:`${o(e.getAvailableSpiders()[t].pathname)}`,projectFolder:e.settings.BOT_NAME},i=await id(nd);v({message:"Downloading the latest Scrapy wrapper template..."});let{archiveUrl:n}=i.templates.find(({id:m})=>m==="python-scrapy");Qs(Io)&&Zm(Io,{recursive:!0}),await wr({url:n,pathTo:Io}),v({message:"Wrapping the Scrapy project..."}),await $a(Io,r,{bindings:s});let a=new od;a.addSection("apify"),a.set("apify","mainpy_location",e.settings.BOT_NAME);let l=zm(ei(r,"scrapy.cfg"),{flags:"a"});await new Promise(m=>{l.on("open",u=>{l.write(`
146
- `,()=>{a.write(u),m()})})}),$({message:"The Scrapy project has been wrapped successfully."})}c(Eo,"wrapScrapyProject");var $o=class extends h{static name="init";static description=`Sets up an Actor project in your current directory by creating actor.json and storage files.
141
+ `);$({message:J,stdout:!0})}};import Ea from"chalk";var $a=new G({allColumns:["Dataset ID","Name","Items","Size","Created","Modified"],mandatoryColumns:["Dataset ID","Name","Items","Size"],columnAlignments:{Items:"right"}}),bo=class extends h{static name="ls";static description="Prints all datasets on your account.";static flags={offset:w.integer({description:"Number of datasets that will be skipped.",default:0}),limit:w.integer({description:"Number of datasets that will be listed.",default:20}),desc:w.boolean({description:"Sorts datasets in descending order.",default:!1}),unnamed:w.boolean({description:"Lists datasets that don't have a name set.",default:!1})};static enableJsonFlag=!0;async run(){let{desc:e,offset:t,limit:o,json:s,unnamed:i}=this.flags,n=await I(),a=await F(),l=await n.datasets().list({desc:e,offset:t,limit:o,unnamed:i});if(s){k(l);return}if(l.count===0){v({message:"You don't have any Datasets on your account",stdout:!0});return}for(let u of l.items){let m=Reflect.get(u.stats,"s3StorageBytes");$a.pushRow({"Dataset ID":u.id,Created:B.display(u.createdAt),Items:`${u.itemCount}`,Modified:B.display(u.modifiedAt),Name:u.name?`${a.username}/${u.name}`:"",Size:typeof m=="number"?X({bytes:m,shortBytes:!0,colorFunc:Ea.gray,precision:0}):Ea.gray("N/A")})}$({message:$a.render(1),stdout:!0})}};import So from"chalk";var vo=class extends h{static name="push-items";static description="Adds data items to specified dataset. Accepts single object or array of objects.";static args={nameOrId:A.string({required:!0,description:"The dataset ID or name to push the objects to",ignoreStdin:!0}),item:A.string({description:"The object or array of objects to be pushed."})};async run(){let{nameOrId:e,item:t}=this.args,o=await I(),s=await Le(o,e);if(!s){p({message:`Dataset with ID or name "${e}" not found.`});return}let{datasetClient:i,dataset:n}=s,a,l=t||Ce;if(!l){p({message:"No items were provided."});return}try{a=JSON.parse(l.toString("utf8"))}catch(m){p({message:`Failed to parse data as JSON string: ${m.message}`});return}if(Array.isArray(a)&&a.length===0){p({message:"No items were provided."});return}let u=n.name?`Dataset named ${So.yellow(n.name)} (${So.gray("ID:")} ${So.yellow(n.id)})`:`Dataset with ID ${So.yellow(n.id)}`;try{await i.pushItems(a),R({message:`${this.pluralString(Array.isArray(a)?a.length:1,"Object","Objects")} pushed to ${u} successfully.`})}catch(m){let f=m;p({message:`Failed to push items into ${u}
142
+ ${f.message||f}`})}}};import ze from"chalk";var To=class extends h{static name="rename";static description="Change dataset name or removes name with --unname flag.";static flags={unname:w.boolean({description:"Removes the unique name of the dataset."})};static args={nameOrId:A.string({description:"The dataset ID or name to delete.",required:!0}),newName:A.string({description:"The new name for the dataset."})};async run(){let{unname:e}=this.flags,{newName:t,nameOrId:o}=this.args;if(!t&&!e){p({message:"You must provide either a new name or the --unname flag."});return}if(t&&e){p({message:"You cannot provide a new name and the --unname flag."});return}let s=await I(),i=await Le(s,o);if(!i){p({message:`Dataset with ID or name "${o}" not found.`});return}let{id:n,name:a}=i.dataset,l=a?e?`The name of the dataset with ID ${ze.yellow(n)} has been removed (was ${ze.yellow(a)} previously).`:`The name of the dataset with ID ${ze.yellow(n)} was changed from ${ze.yellow(a)} to ${ze.yellow(t)}.`:`The name of the dataset with ID ${ze.yellow(n)} has been set to: ${ze.yellow(t)}`;try{await i.datasetClient.update({name:e?null:t}),R({message:l,stdout:!0})}catch(u){let m=u;p({message:`Failed to rename dataset with ID ${ze.yellow(n)}
143
+ ${m.message||m}`})}}};import oi from"chalk";var Co=class extends h{static name="rm";static description="Permanently removes a dataset.";static args={datasetNameOrId:A.string({description:"The dataset ID or name to delete",required:!0})};async run(){let{datasetNameOrId:e}=this.args,t=await I(),o=await Le(t,e);if(!o){p({message:`Dataset with ID or name "${e}" not found.`});return}if(!await z({message:"Are you sure you want to delete this Dataset?"})){v({message:"Dataset deletion has been aborted."});return}let{id:i,name:n}=o.dataset;try{await o.datasetClient.delete(),R({message:`Dataset with ID ${oi.yellow(i)}${n?` (called ${oi.yellow(n)})`:""} has been deleted.`,stdout:!0})}catch(a){let l=a;p({message:`Failed to delete dataset with ID ${oi.yellow(i)}
144
+ ${l.message||l}`})}}};var Io=class extends h{static name="datasets";static description="Manages structured data storage and retrieval.";static subcommands=[ho,yo,bo,Ao,Co,To,vo];async run(){this.printHelp()}};import{existsSync as si,mkdirSync as Xu,readFileSync as Zu,writeFileSync as Qu}from"fs";import{dirname as ed}from"path";import td from"cors";import rd from"detect-indent";import ii from"express";import od from"open";import{cryptoRandomObjectId as sd}from"@apify/utilities";var _a="https://apify.github.io/input-schema-editor-react/",id=new URL(_a).origin,Ra="v1",Eo=class extends h{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:A.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:t}=await ct({forcePath:this.args.path,cwd:process.cwd()});if(e&&!t)throw new Error(`Editing an input schema directly embedded in '${V}' is not yet supported.`);x({message:`This command is still experimental and might break at any time. Use at your own risk.
145
+ `}),v({message:`Editing input schema at "${t}"...`});let o,s=ii();s.use(td({origin:id,allowedHeaders:["Content-Type","Authorization"]})),s.use((f,d,g)=>{d.set("Connection","close"),g()}),s.use(ii.json());let i=sd();s.use((f,d,g)=>{let{token:y}=f.query;if(!y){let b=f.get("Authorization");if(b){let[S,E,...T]=b.trim().split(/\s+/);S.toLowerCase()==="bearer"&&E&&T.length===0&&(y=E)}}y!==i?(d.status(401),d.send("Authorization failed")):g()});let n=ii.Router();s.use(`/api/${Ra}`,n);let a=" ",l=!0;n.get("/input-schema",(f,d)=>{let g;try{g=si(t)?Zu(t,{encoding:"utf-8"}):`{}
146
+ `,g.length>3&&(a=rd(g).indent||a),g&&(l=g[g.length-1]===`
147
+ `),si(t)?v({message:`Input schema loaded from "${t}"`}):v({message:"Empty input schema initialized."})}catch(b){let S=`Reading input schema from disk failed with: ${b.message}`;p({message:S}),d.status(500),d.send(S);return}let y;try{y=JSON.parse(g||"{}")}catch(b){let S=`Parsing input schema failed with error: ${b.message}`;p({message:S}),d.status(500),d.send(S);return}d.send(y),v({message:"Input schema sent to editor."})}),n.post("/input-schema",(f,d)=>{try{v({message:"Got input schema from editor..."});let g=f.body,y=JSON.stringify(g,null,a);l&&(y+=`
148
+ `);let b=ed(t);si(b)||Xu(b,{recursive:!0}),Qu(t,y,{encoding:"utf-8",flag:"w+"}),d.end(),v({message:"Input schema saved to disk."})}catch(g){let y=`Saving input schema failed with error: ${g.message}`;p({message:y}),d.status(500),d.send(y)}}),n.post("/exit",(f,d)=>{f.body.isWindowClosed?v({message:"Editor closed, finishing..."}):v({message:"Editing finished, you can close the editor."}),d.end(),o.close(()=>R({message:"Done."}))}),o=s.listen(0);let{port:u}=o.address();v({message:`Listening for messages from input schema editor on port ${u}...`});let m=`${_a}?localCliPort=${u}&localCliToken=${i}&localCliApiVersion=${Ra}`;v({message:`Opening input schema editor at "${m}"...`}),await od(m)}};import $o from"chalk";var rr=class extends h{static name="help";static description="Prints out help about a command, or all available commands.";static hidden=!0;static args={commandString:A.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=Fr(this.entrypoint);console.log(i);return}let t=e.toLowerCase(),o=q.get(t);if(!o){let i=jr(t),n=$o.gray(`Command ${$o.whiteBright(e)} not found`);i.length&&(n+=`
149
+ `,n+=$o.gray(`Did you mean: ${i.map(a=>$o.whiteBright(a)).join(", ")}?`)),p({message:n});return}let s=kr(o);console.log(s)}};import xa from"chalk";var Ro=class extends h{static name="info";static description="Prints details about your currently authenticated Apify account.";async run(){await I();let e=await F();if(e){let t={username:e.username,userId:e.id};for(let o of Object.keys(t))console.log(`${xa.gray(o)}: ${xa.bold(t[o])}`)}}};import{basename as bd}from"path";import ci from"process";import{appendFileSync as nd,copyFileSync as ad,createWriteStream as ld,existsSync as ni,mkdirSync as cd,readFileSync as Oa,rmSync as md,writeFileSync as ud}from"fs";import{basename as dd,join as ai,relative as Na,sep as li}from"path";import{fileURLToPath as pd}from"url";import fd from"@root/walk";import gd from"configparser";import hd from"handlebars";import{fetchManifest as yd,wrapperManifestUrl as wd}from"@apify/actor-templates";var Ad=[".dockerignore",".gitignore"],_o=pd(new URL("./templates/python-scrapy",import.meta.url));async function Pa(r,e,t={bindings:{}}){await fd.walk(r,async(o,s,i)=>{if(s===r)return;let n=Na(r,s),a=n.split(li).map(u=>{if(u.startsWith("{")&&u.endsWith("}")){u=u.replace("{","").replace("}","");let m=t.bindings[u];if(!m)throw new Error(`Binding for ${u} not found.`);return m}return u}).join(li),l=ai(e,a);if(i.isDirectory())return ni(l)||cd(l),Pa(s,l);n.includes(".template")?ud(ai(e,a.replace(".template","")),hd.compile(Oa(s,"utf8"))(t.bindings)):ni(l)&&Ad.includes(dd(a))?nd(l,Oa(s)):ad(s,l)})}c(Pa,"merge");async function xo({projectPath:r}){r||(r=".");let e=new it(r);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 t=await Ke({message:"Pick the Scrapy spider you want to wrap:",choices:e.getAvailableSpiders().map((u,m)=>({name:`${u.class_name} (${u.pathname})`,value:m}))});function o(u){return`.${Na(r,u).split(li).slice(1).join(".").replace(".py","")}`}c(o,"translatePathToRelativeModuleName");let s={botName:ji(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()[t].class_name,spider_module_name:`${o(e.getAvailableSpiders()[t].pathname)}`,projectFolder:e.settings.BOT_NAME},i=await yd(wd);v({message:"Downloading the latest Scrapy wrapper template..."});let{archiveUrl:n}=i.templates.find(({id:u})=>u==="python-scrapy");ni(_o)&&md(_o,{recursive:!0}),await br({url:n,pathTo:_o}),v({message:"Wrapping the Scrapy project..."}),await Pa(_o,r,{bindings:s});let a=new gd;a.addSection("apify"),a.set("apify","mainpy_location",e.settings.BOT_NAME);let l=ld(ai(r,"scrapy.cfg"),{flags:"a"});await new Promise(u=>{l.on("open",m=>{l.write(`
150
+ `,()=>{a.write(m),u()})})}),R({message:"The Scrapy project has been wrapped successfully."})}c(xo,"wrapScrapyProject");var Oo=class extends h{static name="init";static description=`Sets up an Actor project in your current directory by creating actor.json and storage files.
147
151
  If the directory contains a Scrapy project in Python, the command automatically creates wrappers so that you can run your scrapers without changes.
148
152
  Creates the '${V}' file and the '${et}' directory in the current directory, but does not touch any other existing files or directories.
149
153
 
150
- WARNING: Overwrites existing '${et}' directory.`;static args={actorName:A.string({required:!1,description:"Name of the Actor. If not provided, you will be prompted for it."})};static flags={yes:w.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}),dockerfile:w.string({description:'Path to a Dockerfile to use for the Actor (e.g., "./Dockerfile" or "./docker/Dockerfile").',required:!1})};async run(){let{actorName:e}=this.args,t=ri.cwd(),o=await _e();o.isErr()&&(p({message:o.unwrapErr().message}),ri.exit(1));let s=o.unwrap();if(s.type===2)return v({message:"The current directory looks like a Scrapy project. Using automatic project wrapping."}),this.telemetryData.actorWrapper="scrapy",Eo({projectPath:t});if(!this.flags.yes&&s.type===3&&(x({message:"The current directory does not look like a Node.js or Python project."}),!await z({message:"Do you want to continue?",providedConfirmFromStdin:this.flags.yes})))return;let i=await xe({cwd:t});if(i.isOkAnd(n=>n.exists&&!n.migrated))x({message:`Skipping creation of '${V}', the file already exists in the current directory.`});else{if(i.isErr()){p({message:i.unwrapErr().message}),ri.exitCode=5;return}if(!e){let l=i.isOkAnd(m=>m.exists)?i.unwrap().config.name:null;for(;!l;)try{let m=await st({message:"Actor name:",default:ld(t)});Mt(m),l=m}catch(m){p({message:m.message})}e=l}let a={...{...nr,...i.unwrap().config},name:e};this.flags.dockerfile&&(a.dockerfile=this.flags.dockerfile),await fr(a,t)}await gr(t),await co(t),$({message:"The Actor has been initialized in the current directory."})}};var Ro=class extends h{static name="init-wrap-scrapy";static description=`Wraps your existing Scrapy project to work like an Apify Actor.
154
+ WARNING: Overwrites existing '${et}' directory.`;static args={actorName:A.string({required:!1,description:"Name of the Actor. If not provided, you will be prompted for it."})};static flags={yes:w.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}),dockerfile:w.string({description:'Path to a Dockerfile to use for the Actor (e.g., "./Dockerfile" or "./docker/Dockerfile").',required:!1})};async run(){let{actorName:e}=this.args,t=ci.cwd(),o=await _e();o.isErr()&&(p({message:o.unwrapErr().message}),ci.exit(1));let s=o.unwrap();if(s.type===2)return v({message:"The current directory looks like a Scrapy project. Using automatic project wrapping."}),this.telemetryData.actorWrapper="scrapy",xo({projectPath:t});if(!this.flags.yes&&s.type===3&&(x({message:"The current directory does not look like a Node.js or Python project."}),!await z({message:"Do you want to continue?",providedConfirmFromStdin:this.flags.yes})))return;let i=await xe({cwd:t});if(i.isOkAnd(n=>n.exists&&!n.migrated))x({message:`Skipping creation of '${V}', the file already exists in the current directory.`});else{if(i.isErr()){p({message:i.unwrapErr().message}),ci.exitCode=5;return}if(!e){let l=i.isOkAnd(u=>u.exists)?i.unwrap().config.name:null;for(;!l;)try{let u=await st({message:"Actor name:",default:bd(t)});jt(u),l=u}catch(u){p({message:u.message})}e=l}let a={...{...lr,...i.unwrap().config},name:e};this.flags.dockerfile&&(a.dockerfile=this.flags.dockerfile),await hr(a,t)}await yr(t),await fo(t),R({message:"The Actor has been initialized in the current directory."})}};var No=class extends h{static name="init-wrap-scrapy";static description=`Wraps your existing Scrapy project to work like an Apify Actor.
151
155
 
152
156
  It adds the following features:
153
157
  - Automatic retry of failed requests
154
158
  - Automatic proxy rotation
155
159
  - Automatic user agent rotation
156
160
  ...
157
- `;static args={path:A.string({required:!1,description:"Optional path to your scrapy project. If not provided, the current directory is used."})};static hidden=!0;async run(){await Eo({projectPath:this.args.path}),v({message:"Scrapy project wrapped successfully."})}};import Ra from"chalk";var _o=class extends h{static name="create";static description="Creates a new key-value store on your account.";static args={"key-value store name":A.string({description:"Optional name for the key-value store",required:!1})};static enableJsonFlag=!0;async run(){let{keyValueStoreName:e}=this.args,t=await I();if(e&&await te(t,e)){p({message:"Cannot create a key-value store with the same name!"});return}let o=await t.keyValueStores().getOrCreate(e);if(this.flags.json){k(o);return}$({message:`Key-value store with ID ${Ra.yellow(o.id)}${e?` (called ${Ra.yellow(e)})`:""} was created.`,stdout:!0})}};import cd from"chalk";var xo=class extends h{static name="delete-value";static description="Delete a value from a key-value store.";static args={"store id":A.string({description:"The key-value store ID to delete the value from.",required:!0}),itemKey:A.string({description:"The key of the item in the key-value store.",required:!0})};async run(){let{storeId:e,itemKey:t}=this.args,o=await I(),s=await te(o,e);if(!s){p({message:`Key-value store with ID or name "${e}" not found.`});return}let{keyValueStoreClient:i}=s;if(!await i.getRecord(t)){p({message:`Item with key "${t}" not found in the key-value store.`});return}if(!await z({message:"Are you sure you want to delete this record?"})){v({message:"Key-value store record deletion aborted.",stdout:!0});return}try{await i.deleteRecord(t),v({message:`Record with key "${cd.yellow(t)}" deleted from the key-value store.`,stdout:!0})}catch(l){let m=l;p({message:`Failed to delete record with key "${t}" from the key-value store.
158
- ${m.message||m}`})}}};var Oo=class extends h{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":w.boolean({description:"Only return the content type of the specified key",default:!1})};static args={keyValueStoreId:A.string({description:"The key-value store ID to get the value from.",required:!0}),itemKey:A.string({description:"The key of the item in the key-value store.",required:!0})};async run(){let{onlyContentType:e}=this.flags,{keyValueStoreId:t,itemKey:o}=this.args,s=await I(),i=await te(s,t);if(!i){p({message:`Key-value store with ID "${t}" not found.`});return}let{keyValueStoreClient:n}=i,a=await n.getRecord(o,{stream:!0});if(!a){p({message:`Item with key "${o}" not found in the key-value store.`});return}if(R({message:a.contentType??"application/octet-stream"}),e){a.value.destroy();return}if(a.contentType?.includes("application/json")){let{value:l}=a,m=[];for await(let f of l)m.push(f);let u=Buffer.concat(m).toString();try{let f=JSON.parse(u);R({message:JSON.stringify(f,null,2),stdout:!0})}catch{R({message:u,stdout:!0})}return}a.value.pipe(process.stdout)}};import U from"chalk";var _a=new G({allColumns:["Row1","Row2"],mandatoryColumns:["Row1","Row2"]}),No=class extends h{static name="info";static description="Shows information about a key-value store.";static args={storeId:A.string({description:"The key-value store ID to print information about.",required:!0})};static enableJsonFlag=!0;async run(){let{storeId:e}=this.args,t=await I(),o=await te(t,e);if(!o){p({message:`Key-value store with ID or name "${e}" not found.`});return}let{keyValueStore:s}=o,[i,n,a]=await Promise.all([t.user(s.userId).get().then(F=>F),s.actId?t.actor(s.actId).get():Promise.resolve(void 0),s.actRunId?t.run(s.actRunId).get():Promise.resolve(void 0)]),l;if(a?.actorTaskId&&(l=await t.task(a.actorTaskId).get().catch(()=>{})),this.flags.json){k({...s,user:i,actor:n||null,run:a||null,task:l||null});return}let m=s.stats?.storageBytes||0,u=s.stats?.readCount||0,f=s.stats?.writeCount||0,d=s.stats?.deleteCount||0,g=s.stats?.listCount||0,b=`Operations: ${[`${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"))}`,`${U.bold(d.toLocaleString("en-US"))} ${U.gray(this.pluralString(d,"delete","deletes"))}`,`${U.bold(g.toLocaleString("en-US"))} ${U.gray(this.pluralString(g,"list","lists"))}`].join(" / ")}`;if(i.plan){let F=fo(i.plan);if(F){let Q=F.KEY_VALUE_STORE_TIMED_STORAGE_GBYTE_HOURS*(m/1e9),ye=Q*24*30,we=ye>1?`$${ye.toFixed(2)}`:`$${Q.toFixed(3)}`;b+=`
159
- Storage size: ${X({bytes:m,shortBytes:!0,precision:1})} / ${U.gray(`${we} per month`)}`}}else b+=`
160
- Storage size: ${X({bytes:m,shortBytes:!0,precision:1})} / ${U.gray("$unknown per month")}`;let S=[`Store 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(`
161
+ `;static args={path:A.string({required:!1,description:"Optional path to your scrapy project. If not provided, the current directory is used."})};static hidden=!0;async run(){await xo({projectPath:this.args.path}),v({message:"Scrapy project wrapped successfully."})}};import La from"chalk";var Po=class extends h{static name="create";static description="Creates a new key-value store on your account.";static args={"key-value store name":A.string({description:"Optional name for the key-value store",required:!1})};static enableJsonFlag=!0;async run(){let{keyValueStoreName:e}=this.args,t=await I();if(e&&await te(t,e)){p({message:"Cannot create a key-value store with the same name!"});return}let o=await t.keyValueStores().getOrCreate(e);if(this.flags.json){k(o);return}R({message:`Key-value store with ID ${La.yellow(o.id)}${e?` (called ${La.yellow(e)})`:""} was created.`,stdout:!0})}};import Sd from"chalk";var Lo=class extends h{static name="delete-value";static description="Delete a value from a key-value store.";static args={"store id":A.string({description:"The key-value store ID to delete the value from.",required:!0}),itemKey:A.string({description:"The key of the item in the key-value store.",required:!0})};async run(){let{storeId:e,itemKey:t}=this.args,o=await I(),s=await te(o,e);if(!s){p({message:`Key-value store with ID or name "${e}" not found.`});return}let{keyValueStoreClient:i}=s;if(!await i.getRecord(t)){p({message:`Item with key "${t}" not found in the key-value store.`});return}if(!await z({message:"Are you sure you want to delete this record?"})){v({message:"Key-value store record deletion aborted.",stdout:!0});return}try{await i.deleteRecord(t),v({message:`Record with key "${Sd.yellow(t)}" deleted from the key-value store.`,stdout:!0})}catch(l){let u=l;p({message:`Failed to delete record with key "${t}" from the key-value store.
162
+ ${u.message||u}`})}}};var ko=class extends h{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":w.boolean({description:"Only return the content type of the specified key",default:!1})};static args={keyValueStoreId:A.string({description:"The key-value store ID to get the value from.",required:!0}),itemKey:A.string({description:"The key of the item in the key-value store.",required:!0})};async run(){let{onlyContentType:e}=this.flags,{keyValueStoreId:t,itemKey:o}=this.args,s=await I(),i=await te(s,t);if(!i){p({message:`Key-value store with ID "${t}" not found.`});return}let{keyValueStoreClient:n}=i,a=await n.getRecord(o,{stream:!0});if(!a){p({message:`Item with key "${o}" not found in the key-value store.`});return}if($({message:a.contentType??"application/octet-stream"}),e){a.value.destroy();return}if(a.contentType?.includes("application/json")){let{value:l}=a,u=[];for await(let f of l)u.push(f);let m=Buffer.concat(u).toString();try{let f=JSON.parse(m);$({message:JSON.stringify(f,null,2),stdout:!0})}catch{$({message:m,stdout:!0})}return}a.value.pipe(process.stdout)}};import U from"chalk";var ka=new G({allColumns:["Row1","Row2"],mandatoryColumns:["Row1","Row2"]}),Do=class extends h{static name="info";static description="Shows information about a key-value store.";static args={storeId:A.string({description:"The key-value store ID to print information about.",required:!0})};static enableJsonFlag=!0;async run(){let{storeId:e}=this.args,t=await I(),o=await te(t,e);if(!o){p({message:`Key-value store with ID or name "${e}" not found.`});return}let{keyValueStore:s}=o,[i,n,a]=await Promise.all([t.user(s.userId).get().then(M=>M),s.actId?t.actor(s.actId).get():Promise.resolve(void 0),s.actRunId?t.run(s.actRunId).get():Promise.resolve(void 0)]),l;if(a?.actorTaskId&&(l=await t.task(a.actorTaskId).get().catch(()=>{})),this.flags.json){k({...s,user:i,actor:n||null,run:a||null,task:l||null});return}let u=s.stats?.storageBytes||0,m=s.stats?.readCount||0,f=s.stats?.writeCount||0,d=s.stats?.deleteCount||0,g=s.stats?.listCount||0,b=`Operations: ${[`${U.bold(m.toLocaleString("en-US"))} ${U.gray(this.pluralString(m,"read","reads"))}`,`${U.bold(f.toLocaleString("en-US"))} ${U.gray(this.pluralString(f,"write","writes"))}`,`${U.bold(d.toLocaleString("en-US"))} ${U.gray(this.pluralString(d,"delete","deletes"))}`,`${U.bold(g.toLocaleString("en-US"))} ${U.gray(this.pluralString(g,"list","lists"))}`].join(" / ")}`;if(i.plan){let M=wo(i.plan);if(M){let Q=M.KEY_VALUE_STORE_TIMED_STORAGE_GBYTE_HOURS*(u/1e9),ye=Q*24*30,we=ye>1?`$${ye.toFixed(2)}`:`$${Q.toFixed(3)}`;b+=`
163
+ Storage size: ${X({bytes:u,shortBytes:!0,precision:1})} / ${U.gray(`${we} per month`)}`}}else b+=`
164
+ Storage size: ${X({bytes:u,shortBytes:!0,precision:1})} / ${U.gray("$unknown per month")}`;let S=[`Store 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(`
161
165
  `),E=U.bold("\u2014");s.actRunId&&(a?E=U.bgBlue(a.id):E=U.italic(U.gray("Run removed")));let T=U.bold("\u2014");n&&(T=U.blue(n.title||n.name));let N=U.bold("\u2014");l&&(N=U.blue(l.title||l.name));let P=[`Run: ${E}`,`Actor: ${T}`,`Task: ${N}`].join(`
162
- `);_a.pushRow({Row1:S,Row2:P});let D=_a.render(2).split(`
163
- `).map(F=>F.trim());D.shift();let J=[`${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)}`,"",D.join(`
166
+ `);ka.pushRow({Row1:S,Row2:P});let D=ka.render(2).split(`
167
+ `).map(M=>M.trim());D.shift();let J=[`${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)}`,"",D.join(`
164
168
  `),"",b].join(`
165
- `);R({message:J,stdout:!0})}};var xa=new G({allColumns:["Key","Size"],mandatoryColumns:["Key","Size"]}),Po=class extends h{static name="keys";static description="Lists all keys in a key-value store.";static flags={limit:w.integer({description:"The maximum number of keys to return.",default:20}),"exclusive-start-key":w.string({description:"The key to start the list from."})};static args={storeId:A.string({description:"The key-value store ID to list keys for.",required:!0})};static enableJsonFlag=!0;async run(){let{storeId:e}=this.args,{limit:t,exclusiveStartKey:o}=this.flags,s=await I(),i=await te(s,e);if(!i){p({message:`Key-value store with ID or name "${e}" not found.`});return}let{keyValueStoreClient:n}=i,a=await n.listKeys({limit:t,exclusiveStartKey:o});if(this.flags.json){k(a);return}for(let l of a.items)xa.pushRow({Key:l.key,Size:X({bytes:l.size,shortBytes:!0,precision:0})});R({message:xa.render(1),stdout:!0})}};import Oa from"chalk";var Na=new G({allColumns:["Store ID","Name","Size","Created","Modified"],mandatoryColumns:["Store ID","Name","Size"]}),Lo=class extends h{static name="ls";static description="Lists all key-value stores on your account.";static flags={offset:w.integer({description:"Number of key-value stores that will be skipped.",default:0}),limit:w.integer({description:"Number of key-value stores that will be listed.",default:20}),desc:w.boolean({description:"Sorts key-value stores in descending order.",default:!1}),unnamed:w.boolean({description:"Lists key-value stores that don't have a name set.",default:!1})};static enableJsonFlag=!0;async run(){let{desc:e,offset:t,limit:o,json:s,unnamed:i}=this.flags,n=await I(),a=await M(),l=await n.keyValueStores().list({desc:e,offset:t,limit:o,unnamed:i});if(s){k(l);return}if(l.count===0){v({message:"You don't have any key-value stores on your account",stdout:!0});return}for(let m of l.items){let f=Reflect.get(m,"stats").s3StorageBytes;Na.pushRow({"Store ID":m.id,Created:B.display(m.createdAt),Modified:B.display(m.modifiedAt),Name:m.name?`${a.username}/${m.name}`:"",Size:typeof f=="number"?X({bytes:f,shortBytes:!0,colorFunc:Oa.gray,precision:0}):Oa.gray("N/A")})}R({message:Na.render(1),stdout:!0})}};import Xe from"chalk";var ko=class extends h{static name="rename";static description="Renames a key-value store, or removes its unique name.";static flags={unname:w.boolean({description:"Removes the unique name of the key-value store"})};static args={keyValueStoreNameOrId:A.string({description:"The key-value store ID or name to delete",required:!0}),newName:A.string({description:"The new name for the key-value store"})};async run(){let{unname:e}=this.flags,{newName:t,keyValueStoreNameOrId:o}=this.args;if(!t&&!e){p({message:"You must provide either a new name or the --unname flag."});return}if(t&&e){p({message:"You cannot provide a new name and the --unname flag."});return}let s=await I(),i=await te(s,o);if(!i){p({message:`Key-value store with ID or name "${o}" not found.`});return}let{id:n,name:a}=i.keyValueStore,l=a?e?`The name of the key-value store with ID ${Xe.yellow(n)} has been removed (was ${Xe.yellow(a)} previously).`:`The name of the key-value store with ID ${Xe.yellow(n)} was changed from ${Xe.yellow(a)} to ${Xe.yellow(t)}.`:`The name of the key-value store with ID ${Xe.yellow(n)} has been set to: ${Xe.yellow(t)}`;try{await i.keyValueStoreClient.update({name:e?null:t}),$({message:l,stdout:!0})}catch(m){let u=m;p({message:`Failed to rename key-value store with ID ${Xe.yellow(n)}
166
- ${u.message||u}`})}}};import oi from"chalk";var Do=class extends h{static name="rm";static description="Permanently removes a key-value store.";static args={keyValueStoreNameOrId:A.string({description:"The key-value store ID or name to delete",required:!0})};async run(){let{keyValueStoreNameOrId:e}=this.args,t=await I(),o=await te(t,e);if(!o){p({message:`Key-value store with ID or name "${e}" not found.`});return}if(!await z({message:"Are you sure you want to delete this Key-value store?"})){v({message:"Key-value store deletion has been aborted."});return}let{id:i,name:n}=o.keyValueStore;try{await o.keyValueStoreClient.delete(),$({message:`Key-value store with ID ${oi.yellow(i)}${n?` (called ${oi.yellow(n)})`:""} has been deleted.`,stdout:!0})}catch(a){let l=a;p({message:`Failed to delete key-value store with ID ${oi.yellow(i)}
167
- ${l.message||l}`})}}};var Fo=class extends h{static name="set-value";static description="Stores value with specified key. Set content-type with --content-type flag.";static flags={"content-type":w.string({description:'The MIME content type of the value. By default, "application/json" is assumed.',default:"application/json"})};static args={storeId:A.string({description:"The key-value store ID to set the value in.",required:!0}),itemKey:A.string({description:"The key of the item in the key-value store.",required:!0}),value:A.string({description:"The value to set."})};async run(){let{storeId:e,itemKey:t,value:o}=this.args,{contentType:s}=this.flags,i=await I(),n=await te(i,e);if(!n){p({message:`Key-value store with ID or name "${e}" not found.`});return}let{keyValueStoreClient:a}=n;try{await a.setRecord({key:t,value:o||process.stdin,contentType:s}),$({message:`Value with key "${t}" set in the key-value store.`,stdout:!0})}catch(l){let m=l;p({message:`Failed to set value with key "${t}" in the key-value store.
168
- ${m.message||m}`})}}};var Mo=class extends h{static name="key-value-stores";static description=`Manages persistent key-value storage.
169
-
170
- Alias: kvs`;static hiddenAliases=["kvs"];static subcommands=[_o,xo,Oo,No,Po,Lo,ko,Do,Fo];async run(){this.printHelp()}};import md from"chalk";import dd from"computer-name";import pd from"cors";import si from"express";import fd from"open";import{cryptoRandomObjectId as gd}from"@apify/utilities";import ud from"@inquirer/password";var Pa=Re(async({message:r,mask:e})=>await ud({message:r,mask:e??"*"}));var ni="https://console.apify.com/settings/integrations",hd=new URL(ni).origin,yd=ni.includes("localhost")?"http://localhost:3333":void 0,La="v1",ii=c(async r=>{let e=await Dt(r,yd),t=await M();return e?(await Sr(t.id),$({message:`You are logged in to Apify as ${t.username||t.id}. ${md.gray(`Your token is stored at ${ae()}.`)}`})):p({message:"Login to Apify failed, the provided API token is not valid."}),e},"tryToLogin"),Uo=class extends h{static name="login";static description=`Authenticates your Apify account and saves credentials to '${Ue(ae())}'.
171
- All other commands use these stored credentials.
169
+ `);$({message:J,stdout:!0})}};var Da=new G({allColumns:["Key","Size"],mandatoryColumns:["Key","Size"]}),Fo=class extends h{static name="keys";static description="Lists all keys in a key-value store.";static flags={limit:w.integer({description:"The maximum number of keys to return.",default:20}),"exclusive-start-key":w.string({description:"The key to start the list from."})};static args={storeId:A.string({description:"The key-value store ID to list keys for.",required:!0})};static enableJsonFlag=!0;async run(){let{storeId:e}=this.args,{limit:t,exclusiveStartKey:o}=this.flags,s=await I(),i=await te(s,e);if(!i){p({message:`Key-value store with ID or name "${e}" not found.`});return}let{keyValueStoreClient:n}=i,a=await n.listKeys({limit:t,exclusiveStartKey:o});if(this.flags.json){k(a);return}for(let l of a.items)Da.pushRow({Key:l.key,Size:X({bytes:l.size,shortBytes:!0,precision:0})});$({message:Da.render(1),stdout:!0})}};import Fa from"chalk";var Ma=new G({allColumns:["Store ID","Name","Size","Created","Modified"],mandatoryColumns:["Store ID","Name","Size"]}),Mo=class extends h{static name="ls";static description="Lists all key-value stores on your account.";static flags={offset:w.integer({description:"Number of key-value stores that will be skipped.",default:0}),limit:w.integer({description:"Number of key-value stores that will be listed.",default:20}),desc:w.boolean({description:"Sorts key-value stores in descending order.",default:!1}),unnamed:w.boolean({description:"Lists key-value stores that don't have a name set.",default:!1})};static enableJsonFlag=!0;async run(){let{desc:e,offset:t,limit:o,json:s,unnamed:i}=this.flags,n=await I(),a=await F(),l=await n.keyValueStores().list({desc:e,offset:t,limit:o,unnamed:i});if(s){k(l);return}if(l.count===0){v({message:"You don't have any key-value stores on your account",stdout:!0});return}for(let u of l.items){let f=Reflect.get(u,"stats").s3StorageBytes;Ma.pushRow({"Store ID":u.id,Created:B.display(u.createdAt),Modified:B.display(u.modifiedAt),Name:u.name?`${a.username}/${u.name}`:"",Size:typeof f=="number"?X({bytes:f,shortBytes:!0,colorFunc:Fa.gray,precision:0}):Fa.gray("N/A")})}$({message:Ma.render(1),stdout:!0})}};import Xe from"chalk";var Uo=class extends h{static name="rename";static description="Renames a key-value store, or removes its unique name.";static flags={unname:w.boolean({description:"Removes the unique name of the key-value store"})};static args={keyValueStoreNameOrId:A.string({description:"The key-value store ID or name to delete",required:!0}),newName:A.string({description:"The new name for the key-value store"})};async run(){let{unname:e}=this.flags,{newName:t,keyValueStoreNameOrId:o}=this.args;if(!t&&!e){p({message:"You must provide either a new name or the --unname flag."});return}if(t&&e){p({message:"You cannot provide a new name and the --unname flag."});return}let s=await I(),i=await te(s,o);if(!i){p({message:`Key-value store with ID or name "${o}" not found.`});return}let{id:n,name:a}=i.keyValueStore,l=a?e?`The name of the key-value store with ID ${Xe.yellow(n)} has been removed (was ${Xe.yellow(a)} previously).`:`The name of the key-value store with ID ${Xe.yellow(n)} was changed from ${Xe.yellow(a)} to ${Xe.yellow(t)}.`:`The name of the key-value store with ID ${Xe.yellow(n)} has been set to: ${Xe.yellow(t)}`;try{await i.keyValueStoreClient.update({name:e?null:t}),R({message:l,stdout:!0})}catch(u){let m=u;p({message:`Failed to rename key-value store with ID ${Xe.yellow(n)}
170
+ ${m.message||m}`})}}};import mi from"chalk";var jo=class extends h{static name="rm";static description="Permanently removes a key-value store.";static args={keyValueStoreNameOrId:A.string({description:"The key-value store ID or name to delete",required:!0})};async run(){let{keyValueStoreNameOrId:e}=this.args,t=await I(),o=await te(t,e);if(!o){p({message:`Key-value store with ID or name "${e}" not found.`});return}if(!await z({message:"Are you sure you want to delete this Key-value store?"})){v({message:"Key-value store deletion has been aborted."});return}let{id:i,name:n}=o.keyValueStore;try{await o.keyValueStoreClient.delete(),R({message:`Key-value store with ID ${mi.yellow(i)}${n?` (called ${mi.yellow(n)})`:""} has been deleted.`,stdout:!0})}catch(a){let l=a;p({message:`Failed to delete key-value store with ID ${mi.yellow(i)}
171
+ ${l.message||l}`})}}};var Vo=class extends h{static name="set-value";static description="Stores value with specified key. Set content-type with --content-type flag.";static flags={"content-type":w.string({description:'The MIME content type of the value. By default, "application/json" is assumed.',default:"application/json"})};static args={storeId:A.string({description:"The key-value store ID to set the value in.",required:!0}),itemKey:A.string({description:"The key of the item in the key-value store.",required:!0}),value:A.string({description:"The value to set."})};async run(){let{storeId:e,itemKey:t,value:o}=this.args,{contentType:s}=this.flags,i=await I(),n=await te(i,e);if(!n){p({message:`Key-value store with ID or name "${e}" not found.`});return}let{keyValueStoreClient:a}=n;try{await a.setRecord({key:t,value:o||process.stdin,contentType:s}),R({message:`Value with key "${t}" set in the key-value store.`,stdout:!0})}catch(l){let u=l;p({message:`Failed to set value with key "${t}" in the key-value store.
172
+ ${u.message||u}`})}}};var Bo=class extends h{static name="key-value-stores";static description=`Manages persistent key-value storage.
172
173
 
173
- Run 'apify logout' to remove authentication.`;static flags={token:w.string({char:"t",description:"Apify API token",required:!1}),method:w.string({char:"m",description:"Method of logging in to Apify",choices:["console","manual"],required:!1})};async run(){let{token:e,method:t}=this.flags;if(e){await ii(e);return}let o=t;if(t||(o=await qe({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})),o==="console"){let s,i=si();i.use(pd({origin:hd,allowedHeaders:["Content-Type","Authorization"]})),i.use((u,f,d)=>{f.set("Connection","close"),d()}),i.use(si.json());let n=gd();i.use((u,f,d)=>{let{token:g}=u.query;if(!g){let y=u.get("Authorization");if(y){let[b,S,...E]=y.trim().split(/\s+/);b.toLowerCase()==="bearer"&&S&&E.length===0&&(g=S)}}g!==n?(f.status(401),f.send("Authorization failed")):d()});let a=si.Router();i.use(`/api/${La}`,a),a.post("/login-token",async(u,f)=>{try{if(u.body.apiToken)await ii(u.body.apiToken);else throw new Error("Request did not contain API token");f.end()}catch(d){let g=`Login to Apify failed with error: ${d.message}`;p({message:g}),f.status(500),f.send(g)}s.close()}),a.post("/exit",(u,f)=>{u.body.isWindowClosed?p({message:"Login to Apify failed, the console window was closed."}):u.body.actionCanceled?p({message:"Login to Apify failed, the action was canceled in the Apify Console."}):p({message:"Login to Apify failed."}),f.end(),s.close()}),s=i.listen(0);let{port:l}=s.address(),m=new URL(ni);m.searchParams.set("localCliCommand","login"),m.searchParams.set("localCliPort",`${l}`),m.searchParams.set("localCliToken",n),m.searchParams.set("localCliApiVersion",La);try{m.searchParams.set("localCliComputerName",encodeURIComponent(dd()))}catch{}v({message:`Opening Apify Console at "${m.href}"...`}),await fd(m.href)}else{console.log("Enter your Apify API token. You can find it at https://console.apify.com/settings/integrations");let s=await Pa({message:"token:"});await ii(s)}}};var jo=class extends h{static name="logout";static description=`Removes authentication by deleting your API token and account information from '${Ue(ae())}'.
174
- Run 'apify login' to authenticate again.`;async run(){await Ot(ae()),await Sr(null),$({message:"You are logged out from your Apify account."})}};var Vo=class extends Et{static name="pull"};var Bo=class extends Rt{static name="push"};var Go=class extends h{static name="request-queues";static description="Manages URL queues for web scraping and automation tasks.";async run(){this.printHelp()}};import{existsSync as Da,renameSync as vd}from"fs";import{mkdir as Yo,readFile as Td,stat as Fa,writeFile as rr}from"fs/promises";import{dirname as Ho,join as Jo}from"path";import Fe from"process";import Cd from"mime";import{minVersion as Id}from"semver";import{APIFY_ENV_VARS as Ko}from"@apify/consts";import{validateInputSchema as Ed,validateInputUsingValidator as Ma}from"@apify/input_schema";import{none as tr,some as wd}from"@sapphire/result";import{execa as Ad}from"execa";var ai=c(r=>`
174
+ Alias: kvs`;static hiddenAliases=["kvs"];static subcommands=[Po,Lo,ko,Do,Fo,Mo,Uo,jo,Vo];async run(){this.printHelp()}};var Go=class extends _t{static name="login"};var Yo=class extends xt{static name="logout"};var Ho=class extends Et{static name="pull"};var Jo=class extends Rt{static name="push"};var Ko=class extends h{static name="request-queues";static description="Manages URL queues for web scraping and automation tasks.";async run(){this.printHelp()}};import{existsSync as ja,renameSync as Ed}from"fs";import{mkdir as qo,readFile as $d,stat as Va,writeFile as sr}from"fs/promises";import{dirname as Wo,join as zo}from"path";import Me from"process";import Rd from"mime";import{minVersion as _d}from"semver";import{APIFY_ENV_VARS as Xo}from"@apify/consts";import{validateInputSchema as xd,validateInputUsingValidator as Ba}from"@apify/input_schema";import{none as or,some as vd}from"@sapphire/result";import{execa as Td}from"execa";var ui=c(r=>`
175
175
  (async () => {
176
176
  const [nodeModule, process, path, fs] = await Promise.all([
177
177
  import('node:module'),
@@ -203,31 +203,31 @@ Run 'apify login' to authenticate again.`;async run(){await Ot(ae()),await Sr(nu
203
203
  }
204
204
  })();
205
205
  `.replaceAll(`
206
- `," ").replaceAll(" "," "),"jsScript"),bd=c(r=>`
206
+ `," ").replaceAll(" "," "),"jsScript"),Cd=c(r=>`
207
207
  try:
208
208
  import ${r}
209
209
  print(${r}.__version__)
210
210
  except:
211
211
  print('n/a')
212
- `,"pyScript"),Sd={node(r){return["-e",`"${ai(r)}"`]},deno(r){return["eval",`"${ai(r)}"`]},bun(r){return["--eval",`"${ai(r)}"`]},python(r){return["-c",`"${bd(r)}"`]}};async function ka({moduleName:r,project:e}){if(!e.runtime)return C("useModuleVersion",{status:"no_runtime_found",project:e,moduleName:r}),tr;let t;if(e.type===0)t=e.runtime.runtimeShorthand||"node";else if(e.type===1||e.type===2)t="python";else return C("useModuleVersion",{status:"unsupported_project_type",project:e,moduleName:r}),tr;let o=Sd[t]?.(r);if(!o)return C("useModuleVersion",{status:"no_version_script_found",project:e,moduleName:r}),tr;try{let s=await Ad(e.runtime.executablePath,o,{shell:!0,windowsHide:!0,verbose:process.env.APIFY_CLI_DEBUG?"full":void 0});return s.stdout.trim()==="n/a"?(C("useModuleVersion",{status:"no_version_found",project:e,moduleName:r}),tr):(C("useModuleVersion",{status:"success",project:e,moduleName:r,version:s.stdout.trim()}),wd(s.stdout.trim()))}catch(s){return C("useModuleVersion",{status:"failed_to_run_version_script",project:e,moduleName:r,error:s}),tr}}c(ka,"useModuleVersion");var qo=class extends h{static name="run";static description=`Executes Actor locally with simulated Apify environment variables.
212
+ `,"pyScript"),Id={node(r){return["-e",`"${ui(r)}"`]},deno(r){return["eval",`"${ui(r)}"`]},bun(r){return["--eval",`"${ui(r)}"`]},python(r){return["-c",`"${Cd(r)}"`]}};async function Ua({moduleName:r,project:e}){if(!e.runtime)return C("useModuleVersion",{status:"no_runtime_found",project:e,moduleName:r}),or;let t;if(e.type===0)t=e.runtime.runtimeShorthand||"node";else if(e.type===1||e.type===2)t="python";else return C("useModuleVersion",{status:"unsupported_project_type",project:e,moduleName:r}),or;let o=Id[t]?.(r);if(!o)return C("useModuleVersion",{status:"no_version_script_found",project:e,moduleName:r}),or;try{let s=await Td(e.runtime.executablePath,o,{shell:!0,windowsHide:!0,verbose:process.env.APIFY_CLI_DEBUG?"full":void 0});return s.stdout.trim()==="n/a"?(C("useModuleVersion",{status:"no_version_found",project:e,moduleName:r}),or):(C("useModuleVersion",{status:"success",project:e,moduleName:r,version:s.stdout.trim()}),vd(s.stdout.trim()))}catch(s){return C("useModuleVersion",{status:"failed_to_run_version_script",project:e,moduleName:r,error:s}),or}}c(Ua,"useModuleVersion");var Zo=class extends h{static name="run";static description=`Executes Actor locally with simulated Apify environment variables.
213
213
  Stores data in local '${et}' directory.
214
214
 
215
215
  NOTE: For Node.js Actors, customize behavior by modifying the 'start' script in package.json file.`;static flags={purge:w.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:w.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:w.string({description:["Optional entrypoint for running with injected environment variables.",`
216
216
  `,"For Python, it is the module name, or a path to a file.",`
217
- `,"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:w.string({char:"i",description:"Optional JSON input to be given to the Actor.",required:!1,stdin:2,exclusive:["input-file"]}),"input-file":w.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=Fe.cwd(),{proxy:t,id:o,token:s}=await M(),i=await xe({cwd:e});if(i.isErr()){let{message:L,cause:D}=i.unwrapErr();p({message:`${L}${D?`
218
- ${D.message}`:""}`}),Fe.exitCode=5;return}let{config:n}=i.unwrap(),a=me(),l=await _e({cwd:e});if(l.isErr()){p({message:l.unwrapErr().message}),Fe.exitCode=5;return}let m=l.unwrap(),{type:u,entrypoint:f,runtime:d}=m;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(!d){switch(u){case 0:p({message:`No Node.js detected! Please install Node.js ${be} (or higher) to be able to run Node.js Actors locally.`});break;case 2:case 1:p({message:`No Python detected! Please install Python ${tt} (or higher) to be able to run Python Actors locally.`});break;default:p({message:`No runtime detected! Make sure you have Python ${tt} (or higher) or Node.js ${be} (or higher) installed.`})}return}let g,y;if(this.flags.entrypoint){y=this.flags.entrypoint;let L=Jo(e,this.flags.entrypoint),D=await Fa(L).catch(()=>null);D?.isDirectory()?g=1:D?.isFile()?g=0:g=2}else if(f?.script)g=2,y=f.script;else if(f?.path)g=u!==0?1:0,y=f.path;else{p({message:"No entrypoint detected! Please provide an entrypoint using the --entrypoint flag, or make sure your project has an entrypoint."});return}Da(hs)&&!Da(a)&&(vd(hs,a),x({message:`The legacy 'apify_storage' directory was renamed to '${a}' to align it with Apify SDK v3. Contents were left intact.`}));let b=await ka({moduleName:"crawlee",project:m}),S="0";this.flags.resurrect&&(this.flags.purge=!1),this.flags.purge&&(S="1",b.isNone()&&(await Promise.all([Ni(),Li(),Pi()]),v({message:"All default local stores were purged."}))),this.flags.purge||!await ki()&&!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 E=await Tt(e,this.flags.input,this.flags.inputFile);if(E===!1)return;let T=await this.validateAndStoreInput(E),N={[Ko.LOCAL_STORAGE_DIR]:a,CRAWLEE_STORAGE_DIR:a,CRAWLEE_PURGE_ON_START:S};if(t&&t.password&&(N[Ko.PROXY_PASSWORD]=t.password),o&&(N[Ko.USER_ID]=o),s&&(N[Ko.TOKEN]=s),n.environmentVariables){let L=Kn(n.environmentVariables);Object.assign(N,L)}let P=Object.assign(N,Fe.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 L=Id(be);if(yr(d.version)?P.NODE_OPTIONS=P.NODE_OPTIONS?`${P.NODE_OPTIONS} --max-http-header-size=80000`:"--max-http-header-size=80000":x({message:`You are running Node.js version ${d.version}, which is no longer supported. Please upgrade to Node.js version ${L} or later.`}),g===0||g===1)await ne({cmd:d.executablePath,args:[y],opts:{env:P,cwd:e}});else{let D=await Td(Jo(e,"package.json"),"utf8").catch(()=>"{}"),J=JSON.parse(D);if(!J.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(!J.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(!d.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 ne({cmd:d.pmPath,args:["run",y],opts:{env:P,cwd:e},overrideCommand:d.pmName})}break}case 1:case 2:{if(!hr(d.version)){p({message:`Python Actors require Python 3.9 or higher, but you have Python ${d.version}!`}),p({message:"Please install Python 3.9 or higher to be able to run Python Actors locally."});return}g===1?await ne({cmd:d.executablePath,args:["-m",y],opts:{env:P,cwd:e}}):await ne({cmd:d.executablePath,args:[y],opts:{env:P,cwd:e}});break}default:p({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(L){let{stderr:D}=L}finally{if(T)if(T.existingInput){let L=await Fa(T.inputFilePath);if(Math.trunc(L.mtimeMs)-T.writtenAt>=5){x({message:`The "${T.inputFilePath}" file was overwritten during the run. The CLI will not undo the setting of missing default fields from your input schema.`});return}await rr(T.inputFilePath,T.existingInput.body)}else await Nt(T.inputFilePath)}}async validateAndStoreInput(e){let{inputSchema:t}=await ct({cwd:Fe.cwd()});if(!t){if(!e)return null;let m=Ft(Fe.cwd()),u=Jo(Fe.cwd(),ue(),m?.fileName??"INPUT.json");return await Yo(Ho(u),{recursive:!0}),await rr(u,JSON.stringify(e.input,null,2)),{existingInput:m,inputFilePath:u,writtenAt:Date.now()}}let o=new pt({strict:!1,unicodeRegExp:!1});Ed(o,t);let s=da(t),i=pa(t,o),n=Ft(Fe.cwd()),a=Jo(Fe.cwd(),ue(),n?.fileName??"INPUT.json"),l;switch(e?.source){case"stdin":l=`The input provided through standard input is invalid. Please fix the following errors:
217
+ `,"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:w.string({char:"i",description:"Optional JSON input to be given to the Actor.",required:!1,stdin:2,exclusive:["input-file"]}),"input-file":w.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=Me.cwd(),{proxy:t,id:o,token:s}=await F(),i=await xe({cwd:e});if(i.isErr()){let{message:L,cause:D}=i.unwrapErr();p({message:`${L}${D?`
218
+ ${D.message}`:""}`}),Me.exitCode=5;return}let{config:n}=i.unwrap(),a=ue(),l=await _e({cwd:e});if(l.isErr()){p({message:l.unwrapErr().message}),Me.exitCode=5;return}let u=l.unwrap(),{type:m,entrypoint:f,runtime:d}=u;if(m===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(!d){switch(m){case 0:p({message:`No Node.js detected! Please install Node.js ${be} (or higher) to be able to run Node.js Actors locally.`});break;case 2:case 1:p({message:`No Python detected! Please install Python ${tt} (or higher) to be able to run Python Actors locally.`});break;default:p({message:`No runtime detected! Make sure you have Python ${tt} (or higher) or Node.js ${be} (or higher) installed.`})}return}let g,y;if(this.flags.entrypoint){y=this.flags.entrypoint;let L=zo(e,this.flags.entrypoint),D=await Va(L).catch(()=>null);D?.isDirectory()?g=1:D?.isFile()?g=0:g=2}else if(f?.script)g=2,y=f.script;else if(f?.path)g=m!==0?1:0,y=f.path;else{p({message:"No entrypoint detected! Please provide an entrypoint using the --entrypoint flag, or make sure your project has an entrypoint."});return}ja(bs)&&!ja(a)&&(Ed(bs,a),x({message:`The legacy 'apify_storage' directory was renamed to '${a}' to align it with Apify SDK v3. Contents were left intact.`}));let b=await Ua({moduleName:"crawlee",project:u}),S="0";this.flags.resurrect&&(this.flags.purge=!1),this.flags.purge&&(S="1",b.isNone()&&(await Promise.all([Di(),Mi(),Fi()]),v({message:"All default local stores were purged."}))),this.flags.purge||!await Ui()&&!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 E=await Tt(e,this.flags.input,this.flags.inputFile);if(E===!1)return;let T=await this.validateAndStoreInput(E),N={[Xo.LOCAL_STORAGE_DIR]:a,CRAWLEE_STORAGE_DIR:a,CRAWLEE_PURGE_ON_START:S};if(t&&t.password&&(N[Xo.PROXY_PASSWORD]=t.password),o&&(N[Xo.USER_ID]=o),s&&(N[Xo.TOKEN]=s),n.environmentVariables){let L=Xn(n.environmentVariables);Object.assign(N,L)}let P=Object.assign(N,Me.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(m){case 0:{let L=_d(be);if(Ar(d.version)?P.NODE_OPTIONS=P.NODE_OPTIONS?`${P.NODE_OPTIONS} --max-http-header-size=80000`:"--max-http-header-size=80000":x({message:`You are running Node.js version ${d.version}, which is no longer supported. Please upgrade to Node.js version ${L} or later.`}),g===0||g===1)await ae({cmd:d.executablePath,args:[y],opts:{env:P,cwd:e}});else{let D=await $d(zo(e,"package.json"),"utf8").catch(()=>"{}"),J=JSON.parse(D);if(!J.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(!J.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(!d.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 ae({cmd:d.pmPath,args:["run",y],opts:{env:P,cwd:e},overrideCommand:d.pmName})}break}case 1:case 2:{if(!wr(d.version)){p({message:`Python Actors require Python 3.9 or higher, but you have Python ${d.version}!`}),p({message:"Please install Python 3.9 or higher to be able to run Python Actors locally."});return}g===1?await ae({cmd:d.executablePath,args:["-m",y],opts:{env:P,cwd:e}}):await ae({cmd:d.executablePath,args:[y],opts:{env:P,cwd:e}});break}default:p({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(L){let{stderr:D}=L}finally{if(T)if(T.existingInput){let L=await Va(T.inputFilePath);if(Math.trunc(L.mtimeMs)-T.writtenAt>=5){x({message:`The "${T.inputFilePath}" file was overwritten during the run. The CLI will not undo the setting of missing default fields from your input schema.`});return}await sr(T.inputFilePath,T.existingInput.body)}else await Lt(T.inputFilePath)}}async validateAndStoreInput(e){let{inputSchema:t}=await ct({cwd:Me.cwd()});if(!t){if(!e)return null;let u=Ut(Me.cwd()),m=zo(Me.cwd(),me(),u?.fileName??"INPUT.json");return await qo(Wo(m),{recursive:!0}),await sr(m,JSON.stringify(e.input,null,2)),{existingInput:u,inputFilePath:m,writtenAt:Date.now()}}let o=new pt({strict:!1,unicodeRegExp:!1});xd(o,t);let s=wa(t),i=Aa(t,o),n=Ut(Me.cwd()),a=zo(Me.cwd(),me(),n?.fileName??"INPUT.json"),l;switch(e?.source){case"stdin":l=`The input provided through standard input is invalid. Please fix the following errors:
219
219
  `;break;case"input":l=`The input provided through the --input flag is invalid. Please fix the following errors:
220
220
  `;break;default:e?l=`The input provided through the ${e.source} file is invalid. Please fix the following errors:
221
221
  `:l=`The input in your storage is invalid. Please fix the following errors:
222
- `;break}if(e){let m={...s,...e.input},u=Ma(i,t,m);if(u.length>0)throw new Error(`${l}${u.map(f=>` - ${f.message.replace("Field input.","Field ")}`).join(`
223
- `)}`);return await Yo(Ho(a),{recursive:!0}),await rr(a,JSON.stringify(m,null,2)),{existingInput:n,inputFilePath:a,writtenAt:Date.now()}}if(!n)return await Yo(Ho(a),{recursive:!0}),await rr(a,JSON.stringify(s,null,2)),{existingInput:n,inputFilePath:a,writtenAt:Date.now()};if(Cd.getExtension(n.contentType)==="json"){let m=JSON.parse(n.body.toString("utf-8"));if(Array.isArray(m))throw new Error("The input in your storage is invalid. It should be an object, not an array.");let u={...s,...m},f=Ma(i,t,u);if(f.length>0)throw new Error(`${l}${f.map(d=>` - ${d.message.replace("Field input.","Field ")}`).join(`
224
- `)}`);return await Yo(Ho(a),{recursive:!0}),await rr(a,JSON.stringify(u,null,2)),{existingInput:n,inputFilePath:a,writtenAt:Date.now()}}return null}};import{ACTOR_JOB_STATUSES as Wo}from"@apify/consts";var $d=[Wo.READY,Wo.RUNNING],Rd=[Wo.ABORTING,Wo.TIMING_OUT],zo=class extends h{static name="abort";static description="Aborts an Actor run.";static args={runId:A.string({required:!0,description:"The run ID to abort."})};static flags={force:w.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,t=await I(),o=await t.run(e).get();if(!o){p({message:`Run with ID "${e}" was not found on your account.`,stdout:!0});return}if(!$d.includes(o.status)){Rd.includes(o.status)?p({message:`Run with ID "${e}" is already aborting.`,stdout:!0}):p({message:`Run with ID "${e}" is already aborted.`,stdout:!0});return}try{let s=await t.run(e).abort({gracefully:!this.flags.force});if(this.flags.json){k(s);return}this.flags.force?$({message:`Triggered the immediate abort of run "${e}".`,stdout:!0}):$({message:`Triggered the abort of run "${e}", it should finish aborting in up to 30 seconds.`,stdout:!0})}catch(s){let i=s;p({message:`Failed to abort run "${e}".
225
- ${i.message||i}`,stdout:!0})}}};import _ from"chalk";var or=new G({allColumns:["","Unit","USD Amount"],mandatoryColumns:["","Unit","USD Amount"],columnAlignments:{Unit:"right","USD Amount":"right"}}),Ua={"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"},Xo=class extends h{static name="info";static description="Prints information about an Actor run.";static args={runId:A.string({required:!0,description:"The run ID to print information about."})};static flags={verbose:w.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,t=await I(),o=await t.run(e).get();if(!o){p({message:`Run with ID "${e}" was not found on your account.`});return}let[s,i,n,a,l]=await Promise.all([t.actor(o.actId).get(),t.build(o.buildId).get(),o.actorTaskId?t.task(o.actorTaskId).get():Promise.resolve(void 0),t.dataset(o.defaultDatasetId).get(),t.requestQueue(o.defaultRequestQueueId).get()]);if(this.flags.json){k({...o,actor:s,build:i,task:n,defaultDataset:a,defaultRequestQueue:l});return}this.addDetailedUsage(o);let m=s?.username?`${s.username}/${s.name}`:s?.name??"unknown-actor",u=[`${_.yellow("Actor")}: ${m} (${_.grey(o.actId)})`];n?u.push(`\u2514\u2500 ${_.yellow("Task")}: ${n.title??n.name} (${_.gray(o.actorTaskId)})`,""):o.actorTaskId?u.push(`\u2514\u2500 ${_.yellow("Task")}: unknown-task (${_.gray(o.actorTaskId)})`,""):u.push("");let f=` (exit code: ${_.gray(o.exitCode!==null?o.exitCode:"N/A")})`;u.push(`${_.yellow("Status")}: ${Ee(o.status)}${f}`),o.statusMessage&&u.push(`\u2514\u2500 ${_.yellow("Status Message:")} ${o.statusMessage}`);let d=a?.itemCount??0;u.push(`${_.yellow("Results")}: ${_.cyan(d.toLocaleString("en-US"))}`),l?u.push(`${_.yellow("Requests")}: ${_.cyan(l.handledRequestCount.toLocaleString("en-US"))} out of ${_.cyan(l.totalRequestCount.toLocaleString("en-US"))} handled`):u.push(`${_.yellow("Requests")}: ${_.gray("unknown handled")}`);let g=this.flags.verbose?"":_.gray(` (run with ${_.yellow("--verbose")} for a detailed breakdown)`);if(o.usageTotalUsd?u.push(`${_.yellow("Usage")}: ${_.cyan(this.formatUsd(o.usageTotalUsd))}${g}`):u.push(`${_.yellow("Usage")}: $${_.gray("0.000")}${g}`),this.flags.verbose&&u.push(or.render(0)),u.push(""),u.push(`${_.yellow("Started")}: ${B.display(o.startedAt)}`),o.finishedAt)u.push(`${_.yellow("Finished")}: ${B.display(o.finishedAt)} (took ${_.gray(se.format(o.stats.durationMillis))})`);else{let E=Date.now()-o.startedAt.getTime();u.push(`${_.yellow("Finished")}: ${_.gray(`Running for ${se.format(E)}`)}`)}if(u.push(""),o.stats.resurrectCount?u.push(`${_.yellow("Resurrected")}: Yes, ${_.cyan(o.stats.resurrectCount.toLocaleString("en-US"))} ${this.pluralString(o.stats.resurrectCount,"time","times")}`):u.push(`${_.yellow("Resurrected")}: No`),o.containerUrl&&u.push(`${_.yellow("Container URL")}: ${_.blue(o.containerUrl)}`),u.push(`${_.yellow("Origin")}: ${o.meta.origin}`),s){let E=o.buildNumber.split(".").slice(0,2).join("."),T=s.versions.find(L=>L.versionNumber===E),N=Object.entries(s.taggedBuilds??{}).find(([,L])=>L.buildNumber===o.buildNumber)?.[0],P=[`${_.yellow("Build")}:`,_.cyan(o.buildNumber)];N?P.push(`(${_.yellow(N)})`):P.push(`(${_.gray("N/A")})`),T&&P.push(`| ${_.gray("Actor version:")} ${_.cyan(T.versionNumber)} (${_.yellow(T.buildTag)})`),u.push(P.join(" "))}else u.push(`${_.yellow("Build")}: ${_.cyan(o.buildNumber)}`);u.push(`${_.yellow("Timeout")}: ${o.options.timeoutSecs.toLocaleString("en-US")} seconds`),u.push(`${_.yellow("Memory")}: ${o.options.memoryMbytes} MB`),u.push(""),u.push(`${_.yellow("CPU")}: ${_.gray("Average:")} ${o.stats.cpuAvgUsage.toFixed(2)}% | ${_.gray("Maximum:")} ${o.stats.cpuMaxUsage.toFixed(2)}%`),u.push(`${_.yellow("Memory")}: ${_.gray("Average:")} ${X({bytes:o.stats.memAvgBytes,shortBytes:!0})} | ${_.gray("Maximum:")} ${X({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}`,S=`https://console.apify.com/storage/key-value-stores/${o.defaultKeyValueStoreId}`;u.push(`${_.blue("Export results")}: ${b}`),u.push(`${_.blue("View saved items")}: ${S}`),u.push(`${_.blue("View in Apify Console")}: ${y}`),R({message:u.join(`
226
- `),stdout:!0})}addDetailedUsage(e){let{usage:t,usageUsd:o}=e;if(!t||!o){for(let s of Object.keys(Ua))or.pushRow({"":s,Unit:"N/A","USD Amount":"N/A"});return}for(let[s,i]of Object.entries(Ua)){let n=t[i]??0,a=o[i]??0;switch(i){case"ACTOR_COMPUTE_UNITS":{or.pushRow({"":s,Unit:n.toFixed(4),"USD Amount":this.formatUsd(a)});break}case"DATA_TRANSFER_INTERNAL_GBYTES":case"DATA_TRANSFER_EXTERNAL_GBYTES":case"PROXY_RESIDENTIAL_TRANSFER_GBYTES":{or.pushRow({"":s,Unit:X({bytes:n*1024*1024*1024,shortBytes:!0}),"USD Amount":this.formatUsd(a)});break}default:or.pushRow({"":s,Unit:n.toLocaleString("en-US"),"USD Amount":this.formatUsd(a)})}}}formatUsd(e){return`$${e.toFixed(3)}`}};var Zo=class extends h{static name="log";static description="Prints the log of a specific run.";static args={runId:A.string({required:!0,description:"The run ID to get the log from."})};async run(){let{runId:e}=this.args,t=await I(),o=await t.run(e).get();if(!o){p({message:`Run with ID "${e}" was not found on your account.`,stdout:!0});return}v({message:`Log for run with ID "${e}":
227
- `,stdout:!0});try{await $e({job:o,apifyClient:t})}catch(s){p({message:`Failed to get log for run with ID "${e}": ${s.message}`})}}};import he from"chalk";var ja=new G({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"}}),Qo=class extends h{static name="ls";static description="Lists all runs of the Actor.";static flags={offset:w.integer({description:"Number of runs that will be skipped.",default:0}),limit:w.integer({description:"Number of runs that will be listed.",default:10}),desc:w.boolean({description:"Sort runs in descending order.",default:!1}),compact:w.boolean({description:"Display a compact table.",default:!1,char:"c"})};static args={actorId:A.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:t,offset:o,compact:s,json:i}=this.flags,{actorId:n}=this.args,a=await I(),l=await Ye({providedActorNameOrId:n,client:a});if(!l.valid){p({message:`${l.reason}. Please run this command in an Actor directory, or specify the Actor ID.`});return}let m=await a.actor(l.id).runs().list({desc:e,limit:t,offset:o});if(i){k(m);return}if(!m.items.length){R({message:"There are no recent runs found for this Actor."});return}let u=[`${he.reset("Showing")} ${he.yellow(m.items.length)} out of ${he.yellow(m.total)} runs for Actor ${he.yellow(l.userFriendlyId)} (${he.gray(l.id)})`],f=new Map(await Promise.all(m.items.map(async d=>a.dataset(d.defaultDatasetId).get().then(g=>[d.id,he.yellow(g?.itemCount??0)],()=>[d.id,he.gray("N/A")]))));for(let d of m.items){let g;if(d.finishedAt){let y=d.finishedAt.getTime()-d.startedAt.getTime();g=he.gray(`${se.format(y,void 0,{left:""})}`)}else{let y=Date.now()-d.startedAt.getTime();g=he.gray(`Running for ${se.format(y,void 0,{left:""})}`)}ja.pushRow({ID:he.gray(d.id),Status:Ee(d.status),Results:f.get(d.id)||he.gray("N/A"),Usage:he.cyan(`$${(d.usageTotalUsd??0).toFixed(3)}`),"Started At":Ut.display(d.startedAt),Took:g,"Build No.":d.buildNumber,Origin:d.meta.origin??"UNKNOWN"})}u.push(ja.render(s?0:1)),R({message:u.join(`
228
- `),stdout:!0})}};import{ACTOR_JOB_STATUSES as es}from"@apify/consts";var _d=[es.SUCCEEDED,es.FAILED,es.ABORTED,es.TIMED_OUT],ts=class extends h{static name="resurrect";static description="Resurrects an aborted or finished Actor Run.";static args={runId:A.string({required:!0,description:"The run ID to resurrect."})};static enableJsonFlag=!0;async run(){let{runId:e}=this.args,t=await I(),o=await t.run(e).get();if(!o){p({message:`Run with ID "${e}" was not found on your account.`,stdout:!0});return}if(!_d.includes(o.status)){p({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 t.run(e).resurrect();if(this.flags.json){k(s);return}$({message:`Run with ID "${e}" was resurrected successfully.`,stdout:!0})}catch(s){let i=s;p({message:`Failed to resurrect run "${e}".
229
- ${i.message||i}`,stdout:!0})}}};import{ACTOR_JOB_STATUSES as rs}from"@apify/consts";var xd=[rs.SUCCEEDED,rs.FAILED,rs.ABORTED,rs.TIMED_OUT],os=class extends h{static name="rm";static description="Deletes an Actor Run.";static args={runId:A.string({description:"The run ID to delete.",required:!0})};async run(){let{runId:e}=this.args,t=await I(),o=await t.run(e).get();if(!o){p({message:`Run with ID "${e}" was not found on your account.`});return}if(!xd.includes(o.status)){p({message:`Run with ID "${e}" cannot be deleted, as it is still running or in the process of aborting.`});return}if(!await z({message:"Are you sure you want to delete this Actor Run?"})){v({message:`Deletion of run "${e}" was canceled.`});return}try{await t.run(e).delete(),$({message:`Run with ID "${e}" was deleted.`})}catch(i){let n=i;p({message:`Failed to delete run "${e}".
230
- ${n.message||n}`})}}};var ss=class extends h{static name="runs";static description="Manages Actor run operations ";static subcommands=[zo,Xo,Zo,Qo,ts,os];async run(){this.printHelp()}};var is=class extends h{static name="add";static description="Adds a new secret to '~/.apify' for use in Actor environment variables.";static args={name:A.string({required:!0,description:"Name of the secret"}),value:A.string({required:!0,description:"Value of the secret"})};async run(){let{name:e,value:t}=this.args;Yn(e,t)}};import Od from"chalk";var Va=new G({allColumns:["Secret Name"],mandatoryColumns:["Secret Name"],columnAlignments:{"Secret Name":"left"}}),ns=class extends h{static name="ls";static description="Lists all secret keys stored in your local configuration.";static enableJsonFlag=!0;async run(){let{json:e}=this.flags,t=$t(),o=Object.keys(t);if(e){k({keys:o});return}if(o.length===0){v({message:"You don't have any secrets stored locally. Use 'apify secrets add' to add a secret.",stdout:!0});return}for(let s of o)Va.pushRow({"Secret Name":Od.cyan(s)});R({message:Va.render(1),stdout:!0})}};var as=class extends h{static name="rm";static description="Permanently deletes a secret from your stored credentials.";static args={name:A.string({required:!0,description:"Name of the secret"})};async run(){let{name:e}=this.args;Hn(e)}};var ls=class extends h{static name="secrets";static description=`Manages secure environment variables for Actors.
222
+ `;break}if(e){let u={...s,...e.input},m=Ba(i,t,u);if(m.length>0)throw new Error(`${l}${m.map(f=>` - ${f.message.replace("Field input.","Field ")}`).join(`
223
+ `)}`);return await qo(Wo(a),{recursive:!0}),await sr(a,JSON.stringify(u,null,2)),{existingInput:n,inputFilePath:a,writtenAt:Date.now()}}if(!n)return await qo(Wo(a),{recursive:!0}),await sr(a,JSON.stringify(s,null,2)),{existingInput:n,inputFilePath:a,writtenAt:Date.now()};if(Rd.getExtension(n.contentType)==="json"){let u=JSON.parse(n.body.toString("utf-8"));if(Array.isArray(u))throw new Error("The input in your storage is invalid. It should be an object, not an array.");let m={...s,...u},f=Ba(i,t,m);if(f.length>0)throw new Error(`${l}${f.map(d=>` - ${d.message.replace("Field input.","Field ")}`).join(`
224
+ `)}`);return await qo(Wo(a),{recursive:!0}),await sr(a,JSON.stringify(m,null,2)),{existingInput:n,inputFilePath:a,writtenAt:Date.now()}}return null}};import{ACTOR_JOB_STATUSES as Qo}from"@apify/consts";var Od=[Qo.READY,Qo.RUNNING],Nd=[Qo.ABORTING,Qo.TIMING_OUT],es=class extends h{static name="abort";static description="Aborts an Actor run.";static args={runId:A.string({required:!0,description:"The run ID to abort."})};static flags={force:w.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,t=await I(),o=await t.run(e).get();if(!o){p({message:`Run with ID "${e}" was not found on your account.`,stdout:!0});return}if(!Od.includes(o.status)){Nd.includes(o.status)?p({message:`Run with ID "${e}" is already aborting.`,stdout:!0}):p({message:`Run with ID "${e}" is already aborted.`,stdout:!0});return}try{let s=await t.run(e).abort({gracefully:!this.flags.force});if(this.flags.json){k(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;p({message:`Failed to abort run "${e}".
225
+ ${i.message||i}`,stdout:!0})}}};import _ from"chalk";var ir=new G({allColumns:["","Unit","USD Amount"],mandatoryColumns:["","Unit","USD Amount"],columnAlignments:{Unit:"right","USD Amount":"right"}}),Ga={"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"},ts=class extends h{static name="info";static description="Prints information about an Actor run.";static args={runId:A.string({required:!0,description:"The run ID to print information about."})};static flags={verbose:w.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,t=await I(),o=await t.run(e).get();if(!o){p({message:`Run with ID "${e}" was not found on your account.`});return}let[s,i,n,a,l]=await Promise.all([t.actor(o.actId).get(),t.build(o.buildId).get(),o.actorTaskId?t.task(o.actorTaskId).get():Promise.resolve(void 0),t.dataset(o.defaultDatasetId).get(),t.requestQueue(o.defaultRequestQueueId).get()]);if(this.flags.json){k({...o,actor:s,build:i,task:n,defaultDataset:a,defaultRequestQueue:l});return}this.addDetailedUsage(o);let u=s?.username?`${s.username}/${s.name}`:s?.name??"unknown-actor",m=[`${_.yellow("Actor")}: ${u} (${_.grey(o.actId)})`];n?m.push(`\u2514\u2500 ${_.yellow("Task")}: ${n.title??n.name} (${_.gray(o.actorTaskId)})`,""):o.actorTaskId?m.push(`\u2514\u2500 ${_.yellow("Task")}: unknown-task (${_.gray(o.actorTaskId)})`,""):m.push("");let f=` (exit code: ${_.gray(o.exitCode!==null?o.exitCode:"N/A")})`;m.push(`${_.yellow("Status")}: ${Ee(o.status)}${f}`),o.statusMessage&&m.push(`\u2514\u2500 ${_.yellow("Status Message:")} ${o.statusMessage}`);let d=a?.itemCount??0;m.push(`${_.yellow("Results")}: ${_.cyan(d.toLocaleString("en-US"))}`),l?m.push(`${_.yellow("Requests")}: ${_.cyan(l.handledRequestCount.toLocaleString("en-US"))} out of ${_.cyan(l.totalRequestCount.toLocaleString("en-US"))} handled`):m.push(`${_.yellow("Requests")}: ${_.gray("unknown handled")}`);let g=this.flags.verbose?"":_.gray(` (run with ${_.yellow("--verbose")} for a detailed breakdown)`);if(o.usageTotalUsd?m.push(`${_.yellow("Usage")}: ${_.cyan(this.formatUsd(o.usageTotalUsd))}${g}`):m.push(`${_.yellow("Usage")}: $${_.gray("0.000")}${g}`),this.flags.verbose&&m.push(ir.render(0)),m.push(""),m.push(`${_.yellow("Started")}: ${B.display(o.startedAt)}`),o.finishedAt)m.push(`${_.yellow("Finished")}: ${B.display(o.finishedAt)} (took ${_.gray(ie.format(o.stats.durationMillis))})`);else{let E=Date.now()-o.startedAt.getTime();m.push(`${_.yellow("Finished")}: ${_.gray(`Running for ${ie.format(E)}`)}`)}if(m.push(""),o.stats.resurrectCount?m.push(`${_.yellow("Resurrected")}: Yes, ${_.cyan(o.stats.resurrectCount.toLocaleString("en-US"))} ${this.pluralString(o.stats.resurrectCount,"time","times")}`):m.push(`${_.yellow("Resurrected")}: No`),o.containerUrl&&m.push(`${_.yellow("Container URL")}: ${_.blue(o.containerUrl)}`),m.push(`${_.yellow("Origin")}: ${o.meta.origin}`),s){let E=o.buildNumber.split(".").slice(0,2).join("."),T=s.versions.find(L=>L.versionNumber===E),N=Object.entries(s.taggedBuilds??{}).find(([,L])=>L.buildNumber===o.buildNumber)?.[0],P=[`${_.yellow("Build")}:`,_.cyan(o.buildNumber)];N?P.push(`(${_.yellow(N)})`):P.push(`(${_.gray("N/A")})`),T&&P.push(`| ${_.gray("Actor version:")} ${_.cyan(T.versionNumber)} (${_.yellow(T.buildTag)})`),m.push(P.join(" "))}else m.push(`${_.yellow("Build")}: ${_.cyan(o.buildNumber)}`);m.push(`${_.yellow("Timeout")}: ${o.options.timeoutSecs.toLocaleString("en-US")} seconds`),m.push(`${_.yellow("Memory")}: ${o.options.memoryMbytes} MB`),m.push(""),m.push(`${_.yellow("CPU")}: ${_.gray("Average:")} ${o.stats.cpuAvgUsage.toFixed(2)}% | ${_.gray("Maximum:")} ${o.stats.cpuMaxUsage.toFixed(2)}%`),m.push(`${_.yellow("Memory")}: ${_.gray("Average:")} ${X({bytes:o.stats.memAvgBytes,shortBytes:!0})} | ${_.gray("Maximum:")} ${X({bytes:o.stats.memMaxBytes,shortBytes:!0})}`),m.push("");let y=`https://console.apify.com/actors/${o.actId}/runs/${o.id}`,b=`https://console.apify.com/storage/datasets/${o.defaultDatasetId}`,S=`https://console.apify.com/storage/key-value-stores/${o.defaultKeyValueStoreId}`;m.push(`${_.blue("Export results")}: ${b}`),m.push(`${_.blue("View saved items")}: ${S}`),m.push(`${_.blue("View in Apify Console")}: ${y}`),$({message:m.join(`
226
+ `),stdout:!0})}addDetailedUsage(e){let{usage:t,usageUsd:o}=e;if(!t||!o){for(let s of Object.keys(Ga))ir.pushRow({"":s,Unit:"N/A","USD Amount":"N/A"});return}for(let[s,i]of Object.entries(Ga)){let n=t[i]??0,a=o[i]??0;switch(i){case"ACTOR_COMPUTE_UNITS":{ir.pushRow({"":s,Unit:n.toFixed(4),"USD Amount":this.formatUsd(a)});break}case"DATA_TRANSFER_INTERNAL_GBYTES":case"DATA_TRANSFER_EXTERNAL_GBYTES":case"PROXY_RESIDENTIAL_TRANSFER_GBYTES":{ir.pushRow({"":s,Unit:X({bytes:n*1024*1024*1024,shortBytes:!0}),"USD Amount":this.formatUsd(a)});break}default:ir.pushRow({"":s,Unit:n.toLocaleString("en-US"),"USD Amount":this.formatUsd(a)})}}}formatUsd(e){return`$${e.toFixed(3)}`}};var rs=class extends h{static name="log";static description="Prints the log of a specific run.";static args={runId:A.string({required:!0,description:"The run ID to get the log from."})};async run(){let{runId:e}=this.args,t=await I(),o=await t.run(e).get();if(!o){p({message:`Run with ID "${e}" was not found on your account.`,stdout:!0});return}v({message:`Log for run with ID "${e}":
227
+ `,stdout:!0});try{await $e({job:o,apifyClient:t})}catch(s){p({message:`Failed to get log for run with ID "${e}": ${s.message}`})}}};import he from"chalk";var Ya=new G({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"}}),os=class extends h{static name="ls";static description="Lists all runs of the Actor.";static flags={offset:w.integer({description:"Number of runs that will be skipped.",default:0}),limit:w.integer({description:"Number of runs that will be listed.",default:10}),desc:w.boolean({description:"Sort runs in descending order.",default:!1}),compact:w.boolean({description:"Display a compact table.",default:!1,char:"c"})};static args={actorId:A.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:t,offset:o,compact:s,json:i}=this.flags,{actorId:n}=this.args,a=await I(),l=await Ye({providedActorNameOrId:n,client:a});if(!l.valid){p({message:`${l.reason}. Please run this command in an Actor directory, or specify the Actor ID.`});return}let u=await a.actor(l.id).runs().list({desc:e,limit:t,offset:o});if(i){k(u);return}if(!u.items.length){$({message:"There are no recent runs found for this Actor."});return}let m=[`${he.reset("Showing")} ${he.yellow(u.items.length)} out of ${he.yellow(u.total)} runs for Actor ${he.yellow(l.userFriendlyId)} (${he.gray(l.id)})`],f=new Map(await Promise.all(u.items.map(async d=>a.dataset(d.defaultDatasetId).get().then(g=>[d.id,he.yellow(g?.itemCount??0)],()=>[d.id,he.gray("N/A")]))));for(let d of u.items){let g;if(d.finishedAt){let y=d.finishedAt.getTime()-d.startedAt.getTime();g=he.gray(`${ie.format(y,void 0,{left:""})}`)}else{let y=Date.now()-d.startedAt.getTime();g=he.gray(`Running for ${ie.format(y,void 0,{left:""})}`)}Ya.pushRow({ID:he.gray(d.id),Status:Ee(d.status),Results:f.get(d.id)||he.gray("N/A"),Usage:he.cyan(`$${(d.usageTotalUsd??0).toFixed(3)}`),"Started At":Vt.display(d.startedAt),Took:g,"Build No.":d.buildNumber,Origin:d.meta.origin??"UNKNOWN"})}m.push(Ya.render(s?0:1)),$({message:m.join(`
228
+ `),stdout:!0})}};import{ACTOR_JOB_STATUSES as ss}from"@apify/consts";var Pd=[ss.SUCCEEDED,ss.FAILED,ss.ABORTED,ss.TIMED_OUT],is=class extends h{static name="resurrect";static description="Resurrects an aborted or finished Actor Run.";static args={runId:A.string({required:!0,description:"The run ID to resurrect."})};static enableJsonFlag=!0;async run(){let{runId:e}=this.args,t=await I(),o=await t.run(e).get();if(!o){p({message:`Run with ID "${e}" was not found on your account.`,stdout:!0});return}if(!Pd.includes(o.status)){p({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 t.run(e).resurrect();if(this.flags.json){k(s);return}R({message:`Run with ID "${e}" was resurrected successfully.`,stdout:!0})}catch(s){let i=s;p({message:`Failed to resurrect run "${e}".
229
+ ${i.message||i}`,stdout:!0})}}};import{ACTOR_JOB_STATUSES as ns}from"@apify/consts";var Ld=[ns.SUCCEEDED,ns.FAILED,ns.ABORTED,ns.TIMED_OUT],as=class extends h{static name="rm";static description="Deletes an Actor Run.";static args={runId:A.string({description:"The run ID to delete.",required:!0})};async run(){let{runId:e}=this.args,t=await I(),o=await t.run(e).get();if(!o){p({message:`Run with ID "${e}" was not found on your account.`});return}if(!Ld.includes(o.status)){p({message:`Run with ID "${e}" cannot be deleted, as it is still running or in the process of aborting.`});return}if(!await z({message:"Are you sure you want to delete this Actor Run?"})){v({message:`Deletion of run "${e}" was canceled.`});return}try{await t.run(e).delete(),R({message:`Run with ID "${e}" was deleted.`})}catch(i){let n=i;p({message:`Failed to delete run "${e}".
230
+ ${n.message||n}`})}}};var ls=class extends h{static name="runs";static description="Manages Actor run operations ";static subcommands=[es,ts,rs,os,is,as];async run(){this.printHelp()}};var cs=class extends h{static name="add";static description="Adds a new secret to '~/.apify' for use in Actor environment variables.";static args={name:A.string({required:!0,description:"Name of the secret"}),value:A.string({required:!0,description:"Value of the secret"})};async run(){let{name:e,value:t}=this.args;qn(e,t)}};import kd from"chalk";var Ha=new G({allColumns:["Secret Name"],mandatoryColumns:["Secret Name"],columnAlignments:{"Secret Name":"left"}}),ms=class extends h{static name="ls";static description="Lists all secret keys stored in your local configuration.";static enableJsonFlag=!0;async run(){let{json:e}=this.flags,t=$t(),o=Object.keys(t);if(e){k({keys:o});return}if(o.length===0){v({message:"You don't have any secrets stored locally. Use 'apify secrets add' to add a secret.",stdout:!0});return}for(let s of o)Ha.pushRow({"Secret Name":kd.cyan(s)});$({message:Ha.render(1),stdout:!0})}};var us=class extends h{static name="rm";static description="Permanently deletes a secret from your stored credentials.";static args={name:A.string({required:!0,description:"Name of the secret"})};async run(){let{name:e}=this.args;Wn(e)}};var ds=class extends h{static name="secrets";static description=`Manages secure environment variables for Actors.
231
231
 
232
232
  Example:
233
233
  $ apify secrets add mySecret TopSecretValue123
@@ -241,15 +241,15 @@ The "mySecret" value can be used in an environment variable defined in '${V}' fi
241
241
  "version": "0.1"
242
242
  }
243
243
 
244
- When the Actor is pushed to Apify cloud, the "SECRET_ENV_VAR" and its value is stored as a secret environment variable of the Actor.`;static subcommands=[is,ns,as];async run(){this.printHelp()}};import Ba from"chalk";var cs=class extends h{static name="run";static description=`Executes predefined Actor task remotely using local key-value store for input.
244
+ When the Actor is pushed to Apify cloud, the "SECRET_ENV_VAR" and its value is stored as a secret environment variable of the Actor.`;static subcommands=[cs,ms,us];async run(){this.printHelp()}};import Ja from"chalk";var ps=class extends h{static name="run";static description=`Executes predefined Actor task remotely using local key-value store for input.
245
245
  Customize with --memory and --timeout flags.
246
- `;static flags=It("Task");static args={taskId:A.string({required:!0,description:'Name or ID of the Task to run (e.g. "my-task" or "E2jjCZBezvAZnX8Rb").'})};async run(){let e=await I(),t=await M(),o=t.username||t.id,{id:s,userFriendlyId:i,title:n}=await this.resolveTaskId(e,o),a={waitForFinish:2};this.flags.build&&(a.build=this.flags.build),this.flags.timeout&&(a.timeout=this.flags.timeout),this.flags.memory&&(a.memory=this.flags.memory);let l,m,u=Ct(e,{actorOrTaskData:{id:s,userFriendlyId:i,title:n},runOptions:a,type:"Task",printRunLogs:!0});for await(let f of u)l=`https://console.apify.com/actors/${f.actId}/runs/${f.id}`,m=`https://console.apify.com/storage/datasets/${f.defaultDatasetId}`;R({message:["",`${Ba.blue("Export results")}: ${m}`,`${Ba.blue("View on Apify Console")}: ${l}`].join(`
247
- `),stdout:!0})}async resolveTaskId(e,t){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:`${t}/${s.name}`,title:s.title,task:s}}if(o){let s=await e.task(`${t}/${o.toLowerCase()}`).get();if(!s)throw new Error(`Cannot find Task with name '${o}' in your account.`);return{id:s.id,userFriendlyId:`${t}/${s.name}`,title:s.title,task:s}}throw new Error("Please provide a valid Task ID or name.")}};var us=class extends h{static name="task";static description="Manages scheduled and predefined Actor configurations.";static subcommands=[cs];async run(){this.printHelp()}};var ms=class extends h{static name="disable";static description="Disables telemetry.";async run(){(await pe()).enabled?(await vr(!1),$({message:"Telemetry disabled."})):v({message:"Telemetry is already disabled."})}};var ds=class extends h{static name="enable";static description="Enables telemetry.";async run(){(await pe()).enabled?v({message:"Telemetry is already enabled."}):(await vr(!0),$({message:"Telemetry enabled."}))}};var sr=class extends h{static name="telemetry";static description=`Manages telemetry settings. We use this data to improve the CLI and the Apify platform.
248
- Read more: https://docs.apify.com/cli/docs/telemetry`;static subcommands=[ds,ms];async run(){this.printHelp()}};import Nd from"process";import{validateInputSchema as Pd}from"@apify/input_schema";var ps=class extends h{static name="validate-schema";static description=`Validates Actor input schema from one of these locations (in priority order):
246
+ `;static flags=It("Task");static args={taskId:A.string({required:!0,description:'Name or ID of the Task to run (e.g. "my-task" or "E2jjCZBezvAZnX8Rb").'})};async run(){let e=await I(),t=await F(),o=t.username||t.id,{id:s,userFriendlyId:i,title:n}=await this.resolveTaskId(e,o),a={waitForFinish:2};this.flags.build&&(a.build=this.flags.build),this.flags.timeout&&(a.timeout=this.flags.timeout),this.flags.memory&&(a.memory=this.flags.memory);let l,u,m=Ct(e,{actorOrTaskData:{id:s,userFriendlyId:i,title:n},runOptions:a,type:"Task",printRunLogs:!0});for await(let f of m)l=`https://console.apify.com/actors/${f.actId}/runs/${f.id}`,u=`https://console.apify.com/storage/datasets/${f.defaultDatasetId}`;$({message:["",`${Ja.blue("Export results")}: ${u}`,`${Ja.blue("View on Apify Console")}: ${l}`].join(`
247
+ `),stdout:!0})}async resolveTaskId(e,t){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:`${t}/${s.name}`,title:s.title,task:s}}if(o){let s=await e.task(`${t}/${o.toLowerCase()}`).get();if(!s)throw new Error(`Cannot find Task with name '${o}' in your account.`);return{id:s.id,userFriendlyId:`${t}/${s.name}`,title:s.title,task:s}}throw new Error("Please provide a valid Task ID or name.")}};var fs=class extends h{static name="task";static description="Manages scheduled and predefined Actor configurations.";static subcommands=[ps];async run(){this.printHelp()}};var gs=class extends h{static name="disable";static description="Disables telemetry.";async run(){(await pe()).enabled?(await Cr(!1),R({message:"Telemetry disabled."})):v({message:"Telemetry is already disabled."})}};var hs=class extends h{static name="enable";static description="Enables telemetry.";async run(){(await pe()).enabled?v({message:"Telemetry is already enabled."}):(await Cr(!0),R({message:"Telemetry enabled."}))}};var nr=class extends h{static name="telemetry";static description=`Manages telemetry settings. We use this data to improve the CLI and the Apify platform.
248
+ Read more: https://docs.apify.com/cli/docs/telemetry`;static subcommands=[hs,gs];async run(){this.printHelp()}};import Dd from"process";import{validateInputSchema as Fd}from"@apify/input_schema";var ys=class extends h{static name="validate-schema";static description=`Validates Actor input schema from one of these locations (in priority order):
249
249
  1. Object in '${V}' under "input" key
250
250
  2. JSON file path in '${V}' "input" key
251
251
  3. .actor/INPUT_SCHEMA.json
252
252
  4. INPUT_SCHEMA.json
253
253
 
254
- Optionally specify custom schema path to validate.`;static args={path:A.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:t}=await ct({forcePath:this.args.path,cwd:Nd.cwd()});if(!e)throw new Error(`Input schema has not been found at ${t}.`);t?v({message:`Validating input schema stored at ${t}`}):v({message:`Validating input schema embedded in '${V}'`});let o=new pt({strict:!1});Pd(o,e),$({message:"Input schema is valid."})}};var nO=[Gr,Qr,so,So,Mo,Go,ss,ls,us,sr,io,Qt,Zt,uo,vo,Co,Ro,$o,Uo,jo,Vo,Bo,qo,ps,er],aO=[St,bt,At,wt,yt,ht,gt,er,Qt,Zt,sr];export{Wh as a,zh as b,nO as c,aO as d};
255
- //# sourceMappingURL=chunk-6QG32D64.js.map
254
+ Optionally specify custom schema path to validate.`;static args={path:A.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:t}=await ct({forcePath:this.args.path,cwd:Dd.cwd()});if(!e)throw new Error(`Input schema has not been found at ${t}.`);t?v({message:`Validating input schema stored at ${t}`}):v({message:`Validating input schema embedded in '${V}'`});let o=new pt({strict:!1});Fd(o,e),R({message:"Input schema is valid."})}};var CO=[Hr,to,oo,lo,Io,Bo,Ko,ls,ds,fs,nr,co,tr,er,go,Eo,Ro,No,Oo,Go,Yo,Ho,Jo,Zo,ys,rr],IO=[St,bt,At,wt,yt,ht,gt,rr,tr,er,nr];export{Qh as a,ey as b,CO as c,IO as d};
255
+ //# sourceMappingURL=chunk-IBKSU2CB.js.map