apify-cli 1.6.3-beta.2 → 1.6.3-beta.4

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,4 +1,4 @@
1
- import e from"node:process";import t from"chalk";import n from"indent-string";import r from"widest-line";import i from"wrap-ansi";import{inspect as a,parseArgs as s,promisify as c}from"node:util";import{gt as l,gte as u,minVersion as f,satisfies as p}from"semver";import{appendFileSync as m,constants as h,copyFileSync as g,createWriteStream as _,existsSync as v,fstat as y,mkdirSync as b,openSync as x,readFileSync as S,readdirSync as C,realpathSync as ee,renameSync as te,rmSync as w,statSync as T,unlinkSync as ne,writeFileSync as E}from"node:fs";import D,{basename as re,dirname as O,isAbsolute as ie,join as k,relative as ae,resolve as oe,sep as se}from"node:path";import ce from"string-width";import le from"strip-ansi";import{once as ue}from"node:events";import{homedir as de,platform as fe}from"node:os";import pe from"ci-info";import{ACTOR_ENV_VARS as A,ACTOR_JOB_STATUSES as j,ACTOR_JOB_TERMINAL_STATUSES as me,ACTOR_NAME as he,ACTOR_SOURCE_TYPES as ge,APIFY_ENV_VARS as M,KEY_VALUE_STORE_KEYS as _e,LOCAL_ACTOR_ENV_VARS as ve,LOCAL_STORAGE_SUBDIRS as ye,MAX_MULTIFILE_BYTES as be,META_ORIGINS as xe,SOURCE_FILE_FORMATS as Se}from"@apify/consts";import{jaroWinkler as Ce}from"@skyra/jaro-winkler";import we from"js-levenshtein";import{createHmacSignature as Te,cryptoRandomObjectId as Ee}from"@apify/utilities";import{execSync as De,spawn as Oe}from"node:child_process";import{access as ke,lstat as Ae,mkdir as N,readFile as P,readdir as F,rename as je,stat as I,symlink as Me,unlink as Ne,writeFile as L}from"node:fs/promises";import{get as Pe}from"node:https";import{finished as Fe,pipeline as Ie}from"node:stream/promises";import{DurationFormatter as Le,Time as Re,TimeTypes as R}from"@sapphire/duration";import{Timestamp as ze}from"@sapphire/timestamp";import Be from"adm-zip";import Ve from"ajv/dist/2019.js";import{ApifyClient as He,DownloadItemsFormat as z}from"apify-client";import Ue from"archiver";import We,{AxiosHeaders as Ge}from"axios";import Ke from"escape-string-regexp";import qe from"ignore";import{getEncoding as Je}from"istextorbinary";import Ye,{Mime as Xe}from"mime";import Ze from"mime/types/other.js";import Qe from"mime/types/standard.js";import{glob as $e}from"tinyglobby";import{rimraf as et}from"rimraf";import{Result as tt,err as nt,none as B,ok as V,some as rt}from"@sapphire/result";import it from"configparser";import at from"@inquirer/input";import ot from"is-ci";import{execa as st}from"execa";import ct from"which";import{calculateRunDynamicMemory as lt}from"@apify/actor-memory-expression";import{Separator as ut,createPrompt as dt,isEnterKey as ft,makeTheme as pt,useKeypress as mt,usePrefix as ht,useState as gt}from"@inquirer/core";import{MemoryStorage as _t}from"@crawlee/memory-storage";import{compile as vt}from"json-schema-to-typescript";import{cloneDeep as H}from"es-toolkit";import{validateInputSchema as yt,validateInputUsingValidator as bt}from"@apify/input_schema";import{getDatasetSchemaValidator as xt,getKeyValueStoreSchemaValidator as St,getOutputSchemaValidator as Ct}from"@apify/json_schemas";import wt from"cli-table3";import Tt from"jju";import Et from"tiged";import Dt from"open";import{fetchManifest as Ot,manifestUrl as kt,wrapperManifestUrl as At}from"@apify/actor-templates";import jt from"computer-name";import Mt from"cors";import Nt from"express";import Pt from"@inquirer/password";import Ft from"@inquirer/select";import It from"node:assert";import{ReadStream as Lt}from"node:tty";import Rt from"detect-indent";import{fileURLToPath as zt}from"node:url";import Bt from"@root/walk";import Vt from"handlebars";function internalLog(e){e.stdoutOutput&&console.log(...e.stdoutOutput),e.stderrOutput&&console.error(...e.stderrOutput)}function simpleLog(e){internalLog({[e.stdout?`stdoutOutput`:`stderrOutput`]:[e.message]})}function error(e){internalLog({[e.stdout?`stdoutOutput`:`stderrOutput`]:[t.red(`Error:`),e.message]})}function warning(e){internalLog({[e.stdout?`stdoutOutput`:`stderrOutput`]:[t.yellow.bold(`Warning:`),e.message]})}function success(e){internalLog({[e.stdout?`stdoutOutput`:`stderrOutput`]:[t.green(`Success:`),e.message]})}function run(e){internalLog({[e.stdout?`stdoutOutput`:`stderrOutput`]:[t.gray(`Run:`),e.message]})}function info(e){internalLog({[e.stdout?`stdoutOutput`:`stderrOutput`]:[t.white(`Info:`),e.message]})}function link(e){internalLog({[e.stdout?`stdoutOutput`:`stderrOutput`]:[t.blue(e.message),e.url]})}function detectInstallMethod(){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 e=process.argv[1];if(!e)return warning({message:`Failed to detect install method of CLI, assuming npm`}),`npm`;let t=ee(e);return process.env.VOLTA_HOME&&t.includes(process.env.VOLTA_HOME)?`volta`:t.includes(`homebrew/Cellar`)||t.includes(`linuxbrew/Cellar`)?`homebrew`:process.env.PNPM_HOME&&t.includes(process.env.PNPM_HOME)?`pnpm`:process.env.BUN_INSTALL&&t.includes(process.env.BUN_INSTALL)?`bun`:`npm`}function getRuntimeInfo(){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}}let Ht=null;function useCLIMetadata(){if(Ht)return Ht;let e=detectInstallMethod(),t=getRuntimeInfo();return Ht={version:`1.6.3-beta.2`,hash:`51089bdca0ca8330b81392742e7e10c24bc33e3b`,arch:process.env.APIFY_BUNDLE_ARCH??process.arch,platform:process.platform===`win32`?`windows`:process.platform,runtime:t,extraRuntimeData:t.nodeVersion?`(emulating node ${t.nodeVersion})`:``,installMethod:e,get fullVersionString(){return`apify-cli/${this.version} (${this.hash.slice(0,7)}) running on ${this.platform}-${this.arch} with ${this.runtime.runtime}-${t.version}${this.extraRuntimeData?` ${this.extraRuntimeData}`:``}, installed via ${this.installMethod}`},get isBeta(){return this.version.includes(`beta`)||this.version===`0.0.0`}},e===`bundle`&&(Ht.installPath=O(process.execPath)),Ht}let Ut;function getMaxLineWidth(){if(Ut)return Ut;let e=Number(process.env.APIFY_CLI_MAX_LINE_WIDTH);if(!Number.isNaN(e))Ut=e;else if(!process.stdout.isTTY)Ut=80;else{let e=process.stdout.getWindowSize?.()[0]??-1;Ut=e<1?80:e<40?40:e}return Ut}var BaseCommandRenderer=class{command;entrypoint;constructor(e,t){this.entrypoint=e,this.command=t}pushShortDescription(e){let n=this.command.interactive?`${t.yellow(`[INTERACTIVE]`)} `:``;this.command.shortDescription?e.push(`${n}${this.command.shortDescription}`,``):this.command.description&&e.push(`${n}${this.command.description.split(`
1
+ import e from"node:process";import t from"chalk";import n from"indent-string";import r from"widest-line";import i from"wrap-ansi";import{inspect as a,parseArgs as s,promisify as c}from"node:util";import{gt as l,gte as u,minVersion as f,satisfies as p}from"semver";import{appendFileSync as m,constants as h,copyFileSync as g,createWriteStream as _,existsSync as v,fstat as y,mkdirSync as b,openSync as x,readFileSync as S,readdirSync as C,realpathSync as ee,renameSync as te,rmSync as w,statSync as T,unlinkSync as ne,writeFileSync as E}from"node:fs";import D,{basename as re,dirname as O,isAbsolute as ie,join as k,relative as ae,resolve as oe,sep as se}from"node:path";import ce from"string-width";import le from"strip-ansi";import{once as ue}from"node:events";import{homedir as de,platform as fe}from"node:os";import pe from"ci-info";import{ACTOR_ENV_VARS as A,ACTOR_JOB_STATUSES as j,ACTOR_JOB_TERMINAL_STATUSES as me,ACTOR_NAME as he,ACTOR_SOURCE_TYPES as ge,APIFY_ENV_VARS as M,KEY_VALUE_STORE_KEYS as _e,LOCAL_ACTOR_ENV_VARS as ve,LOCAL_STORAGE_SUBDIRS as ye,MAX_MULTIFILE_BYTES as be,META_ORIGINS as xe,SOURCE_FILE_FORMATS as Se}from"@apify/consts";import{jaroWinkler as Ce}from"@skyra/jaro-winkler";import we from"js-levenshtein";import{createHmacSignature as Te,cryptoRandomObjectId as Ee}from"@apify/utilities";import{execSync as De,spawn as Oe}from"node:child_process";import{access as ke,lstat as Ae,mkdir as N,readFile as P,readdir as F,rename as je,stat as I,symlink as Me,unlink as Ne,writeFile as L}from"node:fs/promises";import{get as Pe}from"node:https";import{finished as Fe,pipeline as Ie}from"node:stream/promises";import{DurationFormatter as Le,Time as Re,TimeTypes as R}from"@sapphire/duration";import{Timestamp as ze}from"@sapphire/timestamp";import Be from"adm-zip";import Ve from"ajv/dist/2019.js";import{ApifyClient as He,DownloadItemsFormat as z}from"apify-client";import Ue from"archiver";import We,{AxiosHeaders as Ge}from"axios";import Ke from"escape-string-regexp";import qe from"ignore";import{getEncoding as Je}from"istextorbinary";import Ye,{Mime as Xe}from"mime";import Ze from"mime/types/other.js";import Qe from"mime/types/standard.js";import{glob as $e}from"tinyglobby";import{rimraf as et}from"rimraf";import{Result as tt,err as nt,none as B,ok as V,some as rt}from"@sapphire/result";import it from"configparser";import at from"@inquirer/input";import ot from"is-ci";import{execa as st}from"execa";import ct from"which";import{calculateRunDynamicMemory as lt}from"@apify/actor-memory-expression";import{Separator as ut,createPrompt as dt,isEnterKey as ft,makeTheme as pt,useKeypress as mt,usePrefix as ht,useState as gt}from"@inquirer/core";import{MemoryStorage as _t}from"@crawlee/memory-storage";import{compile as vt}from"json-schema-to-typescript";import{cloneDeep as H}from"es-toolkit";import{validateInputSchema as yt,validateInputUsingValidator as bt}from"@apify/input_schema";import{getDatasetSchemaValidator as xt,getKeyValueStoreSchemaValidator as St,getOutputSchemaValidator as Ct}from"@apify/json_schemas";import wt from"cli-table3";import Tt from"jju";import Et from"tiged";import Dt from"open";import{fetchManifest as Ot,manifestUrl as kt,wrapperManifestUrl as At}from"@apify/actor-templates";import jt from"computer-name";import Mt from"cors";import Nt from"express";import Pt from"@inquirer/password";import Ft from"@inquirer/select";import It from"node:assert";import{ReadStream as Lt}from"node:tty";import Rt from"detect-indent";import{fileURLToPath as zt}from"node:url";import Bt from"@root/walk";import Vt from"handlebars";function internalLog(e){e.stdoutOutput&&console.log(...e.stdoutOutput),e.stderrOutput&&console.error(...e.stderrOutput)}function simpleLog(e){internalLog({[e.stdout?`stdoutOutput`:`stderrOutput`]:[e.message]})}function error(e){internalLog({[e.stdout?`stdoutOutput`:`stderrOutput`]:[t.red(`Error:`),e.message]})}function warning(e){internalLog({[e.stdout?`stdoutOutput`:`stderrOutput`]:[t.yellow.bold(`Warning:`),e.message]})}function success(e){internalLog({[e.stdout?`stdoutOutput`:`stderrOutput`]:[t.green(`Success:`),e.message]})}function run(e){internalLog({[e.stdout?`stdoutOutput`:`stderrOutput`]:[t.gray(`Run:`),e.message]})}function info(e){internalLog({[e.stdout?`stdoutOutput`:`stderrOutput`]:[t.white(`Info:`),e.message]})}function link(e){internalLog({[e.stdout?`stdoutOutput`:`stderrOutput`]:[t.blue(e.message),e.url]})}function detectInstallMethod(){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 e=process.argv[1];if(!e)return warning({message:`Failed to detect install method of CLI, assuming npm`}),`npm`;let t=ee(e);return process.env.VOLTA_HOME&&t.includes(process.env.VOLTA_HOME)?`volta`:t.includes(`homebrew/Cellar`)||t.includes(`linuxbrew/Cellar`)?`homebrew`:process.env.PNPM_HOME&&t.includes(process.env.PNPM_HOME)?`pnpm`:process.env.BUN_INSTALL&&t.includes(process.env.BUN_INSTALL)?`bun`:`npm`}function getRuntimeInfo(){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}}let Ht=null;function useCLIMetadata(){if(Ht)return Ht;let e=detectInstallMethod(),t=getRuntimeInfo();return Ht={version:`1.6.3-beta.4`,hash:`81d46afa159e66127ab40b8ecc01206746034a5d`,arch:process.env.APIFY_BUNDLE_ARCH??process.arch,platform:process.platform===`win32`?`windows`:process.platform,runtime:t,extraRuntimeData:t.nodeVersion?`(emulating node ${t.nodeVersion})`:``,installMethod:e,get fullVersionString(){return`apify-cli/${this.version} (${this.hash.slice(0,7)}) running on ${this.platform}-${this.arch} with ${this.runtime.runtime}-${t.version}${this.extraRuntimeData?` ${this.extraRuntimeData}`:``}, installed via ${this.installMethod}`},get isBeta(){return this.version.includes(`beta`)||this.version===`0.0.0`}},e===`bundle`&&(Ht.installPath=O(process.execPath)),Ht}let Ut;function getMaxLineWidth(){if(Ut)return Ut;let e=Number(process.env.APIFY_CLI_MAX_LINE_WIDTH);if(!Number.isNaN(e))Ut=e;else if(!process.stdout.isTTY)Ut=80;else{let e=process.stdout.getWindowSize?.()[0]??-1;Ut=e<1?80:e<40?40:e}return Ut}var BaseCommandRenderer=class{command;entrypoint;constructor(e,t){this.entrypoint=e,this.command=t}pushShortDescription(e){let n=this.command.interactive?`${t.yellow(`[INTERACTIVE]`)} `:``;this.command.shortDescription?e.push(`${n}${this.command.shortDescription}`,``):this.command.description&&e.push(`${n}${this.command.description.split(`
2
2
  `)[0]}`,``)}pushDescription(e){if(!this.command.description)return;e.push(t.bold(`DESCRIPTION`));let r=n(i(this.command.description,getMaxLineWidth()-2,{trim:!1}),2);e.push(r),e.push(``)}pushExamples(e){let{examples:r}=this.command;if(r?.length){e.push(t.bold(`EXAMPLES`));for(let a of r){if(a.description){let r=n(i(a.description,getMaxLineWidth()-4,{trim:!1}).split(`
3
3
  `).map(e=>`# ${e}`).join(`
4
4
  `),2);e.push(t.dim(r))}e.push(` $ ${this.normalizeExampleCommand(a.command)}`),e.push(``)}}}normalizeExampleCommand(e){let t=this.entrypoint.split(` `);if(t.length<2)return e;let n=t[t.length-1],r=`${t.slice(0,-1).join(` `)} `,i=n.replace(/[.*+?^${}()|[\]\\]/g,`\\$&`),a=e;return a.startsWith(`${n} `)&&(a=`${r}${a}`),a=a.replace(RegExp(`\\|\\s+${i}\\s`,`g`),`| ${r}${n} `),a}pushInteractiveNote(e){if(!this.command.interactive)return;e.push(t.bold(`NOTE`));let r=n(i(this.command.interactiveNote||`This command prompts the user for input. To run non-interactively (e.g. in CI or from an AI agent), pass all required arguments and flags explicitly.`,getMaxLineWidth()-2,{trim:!1}),2);e.push(r),e.push(``)}pushLearnMore(e){this.command.docsUrl&&(e.push(t.bold(`LEARN MORE`)),e.push(` ${this.command.docsUrl}`),e.push(``))}pushNewLineBeforeNewEntryIfLengthIsPastTheLimit({state:e,itemToAdd:t,indentSize:n}){ce(e.join(` `).split(`
@@ -202,7 +202,7 @@ Stores data in local '${$t}' directory.\n\nNOTE: For Node.js Actors, customize b
202
202
  For crawlee projects, this is the default behavior, and the flag is optional.
203
203
  Use \`--no-purge\` to keep the storage folder intact.`,required:!1,default:!0,exclusive:[`resurrect`]}),resurrect:Y.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:Y.string({description:[`Optional entrypoint for running with injected environment variables.`,`
204
204
  `,`For Python, it is the module name, or a path to a file.`,`
205
- `,`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:Y.string({char:`i`,description:`Optional JSON input to be given to the Actor.`,required:!1,stdin:2,exclusive:[`input-file`]}),"input-file":Y.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`]}),"allow-missing-secrets":Y.boolean({description:`Allow the command to continue even when secret values are not found in the local secrets storage.`,required:!1,default:!1})};async run(){let t=e.cwd(),{proxy:n,id:r,token:i}=await getLocalUserInfo(),a=await useActorConfig({cwd:t});if(a.isErr()){let{message:t,cause:n}=a.unwrapErr();error({message:`${t}${n?`\n ${n.message}`:``}`}),e.exitCode=5;return}let{config:s}=a.unwrap(),c=getLocalStorageDir(),l=resolveInputKey(),u=await useCwdProject({cwd:t});if(u.isErr()){error({message:u.unwrapErr().message}),e.exitCode=5;return}let p=u.unwrap(),{type:m,entrypoint:h,runtime:g}=p;if(p.warnings?.length)for(let e of p.warnings)warning({message:e});if(m===3)throw 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(!g){switch(m){case 0:error({message:`No Node.js detected! Please install Node.js ${rn} (or higher) to be able to run Node.js Actors locally.`});break;case 2:case 1:error({message:`No Python detected! Please install Python ${sn} (or higher) to be able to run Python Actors locally.`});break;default:error({message:`No runtime detected! Make sure you have Python ${sn} (or higher) or Node.js ${rn} (or higher) installed.`})}return}let _,y;if(this.flags.entrypoint){y=this.flags.entrypoint;let e=await I(k(t,this.flags.entrypoint)).catch(()=>null);_=e?.isDirectory()?1:e?.isFile()?0:2}else if(h?.script)_=2,y=h.script;else if(h?.path)_=m===0?0:1,y=h.path;else{error({message:`No entrypoint detected! Please provide an entrypoint using the --entrypoint flag, or make sure your project has an entrypoint.`});return}v(`apify_storage`)&&!v(c)&&(te(`apify_storage`,c),warning({message:`The legacy 'apify_storage' directory was renamed to '${c}' to align it with Apify SDK v3. Contents were left intact.`}));let b=await useModuleVersion({moduleName:`crawlee`,project:p}),x=`0`;this.flags.resurrect&&(this.flags.purge=!1),this.flags.purge&&(x=`1`,b.isNone()&&(await Promise.all([purgeDefaultQueue(),purgeDefaultKeyValueStore(l),purgeDefaultDataset()]),info({message:`All default local stores were purged.`}))),this.flags.purge||!await checkIfStorageIsEmpty(l)&&!this.flags.resurrect&&warning({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 S=await getInputOverride(t,this.flags.input,this.flags.inputFile);if(S===!1)return;let C=await this.validateAndStoreInput(S,l),ee=l;C&&`tempInputKey`in C&&(this.flags.purge&&b.isSome()&&await Promise.all([purgeDefaultQueue(),purgeDefaultKeyValueStore(l,C.tempInputKey),purgeDefaultDataset()]),x=`0`,ee=C.tempInputKey);let w={[M.LOCAL_STORAGE_DIR]:c,CRAWLEE_STORAGE_DIR:c,CRAWLEE_PURGE_ON_START:x,[A.INPUT_KEY]:ee,[M.INPUT_KEY]:ee,CRAWLEE_INPUT_KEY:ee};if(n&&n.password&&(w[M.PROXY_PASSWORD]=n.password),r&&(w[M.USER_ID]=r),i&&(w[M.TOKEN]=i),s.environmentVariables){let e=replaceSecretsValue(s.environmentVariables,void 0,{allowMissing:this.flags.allowMissingSecrets});Object.assign(w,e)}let T={...e.env,...w};r||warning({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 e=f(rn);if(isNodeVersionSupported(g.version)?T.NODE_OPTIONS=T.NODE_OPTIONS?`${T.NODE_OPTIONS} --max-http-header-size=80000`:`--max-http-header-size=80000`:warning({message:`You are running Node.js version ${g.version}, which is no longer supported. Please upgrade to Node.js version ${e} or later.`}),_===0||_===1)await execWithLog({cmd:g.executablePath,args:[y],opts:{env:T,cwd:t},forwardSignals:tn});else{let e=await P(k(t,`package.json`),`utf8`).catch(()=>`{}`),n=JSON.parse(e);if(!n.scripts)throw 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(!n.scripts[y])throw 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(!g.pmPath)throw 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 execWithLog({cmd:g.pmPath,args:[`run`,y],opts:{env:T,cwd:t},overrideCommand:g.pmName,forwardSignals:tn})}break}case 1:case 2:if(!isPythonVersionSupported(g.version)){error({message:`Python Actors require Python 3.9 or higher, but you have Python ${g.version}!`}),error({message:`Please install Python 3.9 or higher to be able to run Python Actors locally.`});return}_===1?await execWithLog({cmd:g.executablePath,args:[`-m`,y],opts:{env:T,cwd:t},forwardSignals:tn}):await execWithLog({cmd:g.executablePath,args:[y],opts:{env:T,cwd:t},forwardSignals:tn});break;default:error({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(e){let{stderr:t}=e}finally{if(C)if(`tempInputKey`in C)await deleteFile(C.tempInputFilePath);else if(C.existingInput){let e=await I(C.inputFilePath);if(Math.trunc(e.mtimeMs)-C.writtenAt>=5){warning({message:`The "${C.inputFilePath}" file was overwritten during the run. The CLI will not undo the setting of missing default fields from your input schema.`});return}await L(C.inputFilePath,C.existingInput.body)}else await deleteFile(C.inputFilePath)}}async validateAndStoreInput(t,n=`INPUT`){let{inputSchema:r}=await readInputSchema({cwd:e.cwd()});if(!r){if(!t)return null;let r=k(e.cwd(),getLocalKeyValueStorePath());await N(r,{recursive:!0});let i=`${xn}${n}`,a=k(r,`${i}.json`);return await L(a,JSON.stringify(t.input,null,2)),{tempInputKey:i,tempInputFilePath:a}}let i=new Cn({strict:!1,unicodeRegExp:!1});yt(i,r);let a=getDefaultsFromInputSchema(r),s=getAjvValidator(r,i),c=getLocalInput(e.cwd(),n),l=k(e.cwd(),getLocalKeyValueStorePath(),c?.fileName??`${n}.json`),u;switch(t?.source){case`stdin`:u=`The input provided through standard input is invalid. Please fix the following errors:
205
+ `,`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:Y.string({char:`i`,description:`Optional JSON input to be given to the Actor.`,required:!1,stdin:2,exclusive:[`input-file`]}),"input-file":Y.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`]}),"allow-missing-secrets":Y.boolean({description:`Allow the command to continue even when secret values are not found in the local secrets storage.`,required:!1,default:!1})};async run(){let t=e.cwd(),{proxy:n,id:r,token:i}=await getLocalUserInfo(),a=await useActorConfig({cwd:t});if(a.isErr()){let{message:t,cause:n}=a.unwrapErr();error({message:`${t}${n?`\n ${n.message}`:``}`}),e.exitCode=5;return}let{config:s}=a.unwrap(),c=getLocalStorageDir(),l=resolveInputKey(),u=await useCwdProject({cwd:t});if(u.isErr()){error({message:u.unwrapErr().message}),e.exitCode=5;return}let p=u.unwrap(),{type:m,entrypoint:h,runtime:g}=p;if(p.warnings?.length)for(let e of p.warnings)warning({message:e});if(m===3)throw 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(!g){switch(m){case 0:error({message:`No Node.js detected! Please install Node.js ${rn} (or higher) to be able to run Node.js Actors locally.`});break;case 2:case 1:error({message:`No Python detected! Please install Python ${sn} (or higher) to be able to run Python Actors locally.`});break;default:error({message:`No runtime detected! Make sure you have Python ${sn} (or higher) or Node.js ${rn} (or higher) installed.`})}return}let _,y;if(this.flags.entrypoint){y=this.flags.entrypoint;let e=await I(k(t,this.flags.entrypoint)).catch(()=>null);_=e?.isDirectory()?1:e?.isFile()?0:2}else if(h?.script)_=2,y=h.script;else if(h?.path)_=m===0?0:1,y=h.path;else{error({message:`No entrypoint detected! Please provide an entrypoint using the --entrypoint flag, or make sure your project has an entrypoint.`});return}v(`apify_storage`)&&!v(c)&&(te(`apify_storage`,c),warning({message:`The legacy 'apify_storage' directory was renamed to '${c}' to align it with Apify SDK v3. Contents were left intact.`}));let b=await useModuleVersion({moduleName:`crawlee`,project:p}),x=`0`;this.flags.resurrect&&(this.flags.purge=!1),this.flags.purge&&(x=`1`,b.isNone()&&(await Promise.all([purgeDefaultQueue(),purgeDefaultKeyValueStore(l),purgeDefaultDataset()]),info({message:`All default local stores were purged.`}))),this.flags.purge||!await checkIfStorageIsEmpty(l)&&!this.flags.resurrect&&warning({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 S=await getInputOverride(t,this.flags.input,this.flags.inputFile);if(S===!1)return;let C=await this.validateAndStoreInput(S,l),ee=l;C&&`tempInputKey`in C&&(this.flags.purge&&b.isSome()&&await Promise.all([purgeDefaultQueue(),purgeDefaultKeyValueStore(l,C.tempInputKey),purgeDefaultDataset()]),x=`0`,ee=C.tempInputKey);let w={[M.LOCAL_STORAGE_DIR]:c,CRAWLEE_STORAGE_DIR:c,CRAWLEE_PURGE_ON_START:x,[A.INPUT_KEY]:ee,[M.INPUT_KEY]:ee,CRAWLEE_INPUT_KEY:ee};if(n&&n.password&&(w[M.PROXY_PASSWORD]=n.password),r&&(w[M.USER_ID]=r),i&&(w[M.TOKEN]=i),s.environmentVariables){let e=replaceSecretsValue(s.environmentVariables,void 0,{allowMissing:this.flags.allowMissingSecrets});Object.assign(w,e)}let T={...e.env,...w};r||warning({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 e=f(rn);if(isNodeVersionSupported(g.version)?T.NODE_OPTIONS=T.NODE_OPTIONS?`${T.NODE_OPTIONS} --max-http-header-size=80000`:`--max-http-header-size=80000`:warning({message:`You are running Node.js version ${g.version}, which is no longer supported. Please upgrade to Node.js version ${e} or later.`}),_===0||_===1)await execWithLog({cmd:g.executablePath,args:[y],opts:{env:T,cwd:t},forwardSignals:tn});else{let e=await P(k(t,`package.json`),`utf8`).catch(()=>`{}`),n=JSON.parse(e);if(!n.scripts)throw 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(!n.scripts[y])throw 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(!g.pmPath)throw 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 execWithLog({cmd:g.pmPath,args:[`run`,y],opts:{env:T,cwd:t},overrideCommand:g.pmName,forwardSignals:tn})}break}case 1:case 2:if(!isPythonVersionSupported(g.version)){error({message:`Python Actors require Python 3.9 or higher, but you have Python ${g.version}!`}),error({message:`Please install Python 3.9 or higher to be able to run Python Actors locally.`});return}_===1?await execWithLog({cmd:g.executablePath,args:[`-m`,y],opts:{env:T,cwd:t},forwardSignals:tn}):await execWithLog({cmd:g.executablePath,args:[y],opts:{env:T,cwd:t},forwardSignals:tn});break;default:error({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(t){e.exitCode=t.exitCode??1}finally{if(C)if(`tempInputKey`in C)await deleteFile(C.tempInputFilePath);else if(C.existingInput){let e=await I(C.inputFilePath);if(Math.trunc(e.mtimeMs)-C.writtenAt>=5){warning({message:`The "${C.inputFilePath}" file was overwritten during the run. The CLI will not undo the setting of missing default fields from your input schema.`});return}await L(C.inputFilePath,C.existingInput.body)}else await deleteFile(C.inputFilePath)}}async validateAndStoreInput(t,n=`INPUT`){let{inputSchema:r}=await readInputSchema({cwd:e.cwd()});if(!r){if(!t)return null;let r=k(e.cwd(),getLocalKeyValueStorePath());await N(r,{recursive:!0});let i=`${xn}${n}`,a=k(r,`${i}.json`);return await L(a,JSON.stringify(t.input,null,2)),{tempInputKey:i,tempInputFilePath:a}}let i=new Cn({strict:!1,unicodeRegExp:!1});yt(i,r);let a=getDefaultsFromInputSchema(r),s=getAjvValidator(r,i),c=getLocalInput(e.cwd(),n),l=k(e.cwd(),getLocalKeyValueStorePath(),c?.fileName??`${n}.json`),u;switch(t?.source){case`stdin`:u=`The input provided through standard input is invalid. Please fix the following errors:
206
206
  `;break;case`input`:u=`The input provided through the --input flag is invalid. Please fix the following errors:
207
207
  `;break;default:u=t?`The input provided through the ${t.source} file is invalid. Please fix the following errors:\n`:`The input in your storage is invalid. Please fix the following errors:
208
208
  `;break}if(t){let e={...a,...t.input},i=bt(s,r,e);if(i.length>0)throw Error(`${u}${i.map(e=>` - ${e.message.replace(`Field input.`,`Field `)}`).join(`
@@ -222,4 +222,4 @@ When no path is provided, validates all schemas found in '${W}':
222
222
  - Dataset schema (from "storages.dataset")
223
223
  - Output schema (from "output")
224
224
  - Key-Value Store schema (from "storages.keyValueStore")`;static group=`Local Actor Development`;static examples=[{description:`Validate the input schema discovered from the default locations.`,command:`apify validate-schema`},{description:`Validate a specific INPUT_SCHEMA.json file.`,command:`apify validate-schema ./my-schema.json`}];static docsUrl=`https://docs.apify.com/cli/docs/reference#apify-validate-schema`;static args={path:Z.string({required:!1,description:`Optional path to your INPUT_SCHEMA.json file. If not provided, validates all schemas in '${W}'.`})};static hiddenAliases=[`vis`];async run(){if(this.args.path){await this.validateInputSchemaAtPath(this.args.path);return}await this.validateAllSchemas()}async validateInputSchemaAtPath(t){await readAndValidateInputSchema({forcePath:t,cwd:e.cwd(),getMessage:e=>`Validating input schema at ${e??t}`}),success({message:`Input schema is valid.`})}async validateAllSchemas(){let t=e.cwd(),n=!1,r=!1;try{let{inputSchema:e,inputSchemaPath:r}=await readInputSchema({cwd:t,throwOnMissing:!0});e&&(n=!0,info({message:`Validating input schema ${r?`at ${r}`:`embedded in '${W}'`}`}),yt(new Cn({strict:!1}),e),success({message:`Input schema is valid.`}))}catch(e){n=!0,r=!0,error({message:e.message})}let i=[{label:`Dataset`,read:()=>readStorageSchema({cwd:t,key:`dataset`,label:`Dataset`,throwOnMissing:!0}),validate:validateDatasetSchema},{label:`Output`,read:()=>readStorageSchema({cwd:t,key:`output`,label:`Output`,getRef:e=>e?.output,throwOnMissing:!0}),validate:validateOutputSchema},{label:`Key-Value Store`,read:()=>readStorageSchema({cwd:t,key:`keyValueStore`,label:`Key-Value Store`,throwOnMissing:!0}),validate:validateKvsSchema}];for(let{label:e,read:t,validate:a}of i)try{let r=t();r&&(n=!0,info({message:`Validating ${e} schema ${r.schemaPath?`at ${r.schemaPath}`:`embedded in '${W}'`}`}),a(r.schema),success({message:`${e} schema is valid.`}))}catch(e){n=!0,r=!0,error({message:e.message})}if(!n)throw Error(`No schemas found. Make sure '${W}' exists and defines at least one schema.`);r&&(e.exitCode=5)}};const Gr=[ActorIndexCommand,ActorsIndexCommand,AuthIndexCommand,BuildsIndexCommand,DatasetsIndexCommand,KeyValueStoresIndexCommand,RequestQueuesIndexCommand,RunsIndexCommand,SecretsIndexCommand,TasksIndexCommand,TelemetryIndexCommand,ApiCommand,TopLevelCallCommand,UpgradeCommand,InstallCommand,CreateCommand,EditInputSchemaCommand,InfoCommand,WrapScrapyCommand,InitCommand,LoginCommand,LogoutCommand,TopLevelPullCommand,ToplevelPushCommand,RunCommand,ValidateSchemaCommand,HelpCommand],Kr=[ActorSetValueCommand,ActorPushDataCommand,ActorGetValueCommand,ActorGetPublicUrlCommand,ActorGetInputCommand,ActorChargeCommand,ActorCalculateMemoryCommand,ActorGenerateSchemaTypesCommand,HelpCommand,UpgradeCommand,InstallCommand,TelemetryIndexCommand];export{runCLI as i,Gr as n,processVersionCheck as r,Kr as t};
225
- //# sourceMappingURL=_register-DqlEeog8.js.map
225
+ //# sourceMappingURL=_register-DTarVRWq.js.map