apify-cli 1.10.1-beta.20 → 1.10.1-beta.22
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 a,{basename as s,dirname as c,isAbsolute as l,join as u,relative as f,resolve as p,sep as m}from"node:path";import{inspect as h,parseArgs as g,promisify as _}from"node:util";import{gt as v,gte as y,minVersion as b,satisfies as x}from"semver";import{appendFileSync as S,chmodSync as C,constants as w,copyFileSync as T,createWriteStream as E,existsSync as D,fstat as O,mkdirSync as k,openSync as A,readFileSync as j,readdirSync as ee,realpathSync as M,renameSync as N,rmSync as P,statSync as te,unlinkSync as ne,writeFileSync as F}from"node:fs";import re from"string-width";import ie from"strip-ansi";import{once as ae}from"node:events";import{homedir as oe,platform as se}from"node:os";import ce,{isCI as le}from"ci-info";import{ACTOR_ENV_VARS as I,ACTOR_JOB_STATUSES as L,ACTOR_JOB_TERMINAL_STATUSES as ue,ACTOR_NAME as de,ACTOR_SOURCE_TYPES as fe,APIFY_ENV_VARS as R,KEY_VALUE_STORE_KEYS as pe,LOCAL_ACTOR_ENV_VARS as me,LOCAL_STORAGE_SUBDIRS as he,MAX_MULTIFILE_BYTES as ge,META_ORIGINS as _e,SOURCE_FILE_FORMATS as ve}from"@apify/consts";import{jaroWinkler as ye}from"@skyra/jaro-winkler";import be from"js-levenshtein";import{Result as xe,err as Se,none as Ce,ok as we,some as Te}from"@sapphire/result";import{execa as Ee}from"execa";import{access as De,appendFile as Oe,mkdir as z,readFile as B,readdir as ke,rename as Ae,rm as je,stat as V,symlink as Me,unlink as Ne,writeFile as H}from"node:fs/promises";import Pe from"configparser";import Fe from"@inquirer/input";import Ie from"which";import{createHmacSignature as Le,cryptoRandomObjectId as Re}from"@apify/utilities";import{execSync as ze,spawn as Be}from"node:child_process";import{DurationFormatter as Ve,Time as He,TimeTypes as Ue}from"@sapphire/duration";import{Timestamp as We}from"@sapphire/timestamp";import Ge from"adm-zip";import Ke from"ajv/dist/2019.js";import{ApifyClient as qe,DownloadItemsFormat as U}from"apify-client";import{ZipArchive as Je}from"archiver";import Ye,{AxiosHeaders as Xe}from"axios";import Ze from"escape-string-regexp";import Qe from"ignore";import{getEncoding as $e}from"istextorbinary";import et,{Mime as tt}from"mime";import nt from"mime/types/other.js";import rt from"mime/types/standard.js";import{glob as it}from"tinyglobby";import{calculateRunDynamicMemory as at}from"@apify/actor-memory-expression";import{Separator as ot,createPrompt as st,isEnterKey as ct,makeTheme as lt,useKeypress as ut,usePrefix as dt,useState as ft}from"@inquirer/core";import{pipeline as pt}from"node:stream/promises";import{MemoryStorage as mt}from"@crawlee/memory-storage";import{compile as ht}from"json-schema-to-typescript";import{validateInputSchema as gt,validateInputUsingValidator as _t}from"@apify/input_schema";import{getDatasetSchemaValidator as vt,getKeyValueStoreSchemaValidator as yt,getOutputSchemaValidator as bt}from"@apify/json_schemas";import xt from"cli-table3";import{downloadTemplate as St}from"giget";import Ct from"jju";import wt from"open";import{fetchManifest as Tt,manifestUrl as Et,wrapperManifestUrl as Dt}from"@apify/actor-templates";import Ot from"computer-name";import kt from"@inquirer/password";import At from"@inquirer/select";import{createServer as jt}from"node:http";import Mt from"node:assert";import{ReadStream as Nt}from"node:tty";import{setTimeout as Pt}from"node:timers/promises";import Ft from"detect-indent";import{fileURLToPath as It}from"node:url";import Lt from"@root/walk";import Rt 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 detectInstallMethod(){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=M(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 zt=null;function useCLIMetadata(){if(zt)return zt;let e=detectInstallMethod(),t=getRuntimeInfo();return zt={version:`1.10.1-beta.
|
|
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 a,{basename as s,dirname as c,isAbsolute as l,join as u,relative as f,resolve as p,sep as m}from"node:path";import{inspect as h,parseArgs as g,promisify as _}from"node:util";import{gt as v,gte as y,minVersion as b,satisfies as x}from"semver";import{appendFileSync as S,chmodSync as C,constants as w,copyFileSync as T,createWriteStream as E,existsSync as D,fstat as O,mkdirSync as k,openSync as A,readFileSync as j,readdirSync as ee,realpathSync as M,renameSync as N,rmSync as P,statSync as te,unlinkSync as ne,writeFileSync as F}from"node:fs";import re from"string-width";import ie from"strip-ansi";import{once as ae}from"node:events";import{homedir as oe,platform as se}from"node:os";import ce,{isCI as le}from"ci-info";import{ACTOR_ENV_VARS as I,ACTOR_JOB_STATUSES as L,ACTOR_JOB_TERMINAL_STATUSES as ue,ACTOR_NAME as de,ACTOR_SOURCE_TYPES as fe,APIFY_ENV_VARS as R,KEY_VALUE_STORE_KEYS as pe,LOCAL_ACTOR_ENV_VARS as me,LOCAL_STORAGE_SUBDIRS as he,MAX_MULTIFILE_BYTES as ge,META_ORIGINS as _e,SOURCE_FILE_FORMATS as ve}from"@apify/consts";import{jaroWinkler as ye}from"@skyra/jaro-winkler";import be from"js-levenshtein";import{Result as xe,err as Se,none as Ce,ok as we,some as Te}from"@sapphire/result";import{execa as Ee}from"execa";import{access as De,appendFile as Oe,mkdir as z,readFile as B,readdir as ke,rename as Ae,rm as je,stat as V,symlink as Me,unlink as Ne,writeFile as H}from"node:fs/promises";import Pe from"configparser";import Fe from"@inquirer/input";import Ie from"which";import{createHmacSignature as Le,cryptoRandomObjectId as Re}from"@apify/utilities";import{execSync as ze,spawn as Be}from"node:child_process";import{DurationFormatter as Ve,Time as He,TimeTypes as Ue}from"@sapphire/duration";import{Timestamp as We}from"@sapphire/timestamp";import Ge from"adm-zip";import Ke from"ajv/dist/2019.js";import{ApifyClient as qe,DownloadItemsFormat as U}from"apify-client";import{ZipArchive as Je}from"archiver";import Ye,{AxiosHeaders as Xe}from"axios";import Ze from"escape-string-regexp";import Qe from"ignore";import{getEncoding as $e}from"istextorbinary";import et,{Mime as tt}from"mime";import nt from"mime/types/other.js";import rt from"mime/types/standard.js";import{glob as it}from"tinyglobby";import{calculateRunDynamicMemory as at}from"@apify/actor-memory-expression";import{Separator as ot,createPrompt as st,isEnterKey as ct,makeTheme as lt,useKeypress as ut,usePrefix as dt,useState as ft}from"@inquirer/core";import{pipeline as pt}from"node:stream/promises";import{MemoryStorage as mt}from"@crawlee/memory-storage";import{compile as ht}from"json-schema-to-typescript";import{validateInputSchema as gt,validateInputUsingValidator as _t}from"@apify/input_schema";import{getDatasetSchemaValidator as vt,getKeyValueStoreSchemaValidator as yt,getOutputSchemaValidator as bt}from"@apify/json_schemas";import xt from"cli-table3";import{downloadTemplate as St}from"giget";import Ct from"jju";import wt from"open";import{fetchManifest as Tt,manifestUrl as Et,wrapperManifestUrl as Dt}from"@apify/actor-templates";import Ot from"computer-name";import kt from"@inquirer/password";import At from"@inquirer/select";import{createServer as jt}from"node:http";import Mt from"node:assert";import{ReadStream as Nt}from"node:tty";import{setTimeout as Pt}from"node:timers/promises";import Ft from"detect-indent";import{fileURLToPath as It}from"node:url";import Lt from"@root/walk";import Rt 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 detectInstallMethod(){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=M(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 zt=null;function useCLIMetadata(){if(zt)return zt;let e=detectInstallMethod(),t=getRuntimeInfo();return zt={version:`1.10.1-beta.22`,hash:`44ea85470dc21df5481ee1978310b7721bde7406`,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`&&(zt.installPath=c(process.execPath)),zt}function cliDebugPrint(e,...n){process.env.APIFY_CLI_DEBUG&&console.error(t.gray(`[${e}]`),...n)}const Bt=[`apify`,`actor`];function unixWrapperScript(e){return[`#!/bin/sh`,`DIR="$(CDPATH= cd -- "$(dirname -- "$0")" && pwd)"`,`APIFY_CLI_ENTRYPOINT=${e} exec "$DIR/apify-cli" "$@"`,``].join(`
|
|
2
2
|
`)}function windowsCmdWrapperScript(e){return[`@echo off`,`setlocal`,`set "APIFY_CLI_ENTRYPOINT=${e}"`,`"%~dp0apify-cli.exe" %*`,``].join(`\r
|
|
3
3
|
`)}function windowsPowershellWrapperScript(e){return[`#!/usr/bin/env pwsh`,`$prev = $env:APIFY_CLI_ENTRYPOINT`,`$env:APIFY_CLI_ENTRYPOINT = "${e}"`,`try {`,` & "$PSScriptRoot\\apify-cli.exe" @args`,`} finally {`,` $env:APIFY_CLI_ENTRYPOINT = $prev`,`}`,`exit $LASTEXITCODE`,``].join(`\r
|
|
4
4
|
`)}function atomicWriteSync(t,n,r){let i=`${t}.${e.pid}.tmp`;try{F(i,n),r!==void 0&&C(i,r),N(i,t)}catch(e){try{P(i,{force:!0})}catch{}throw e}}function atomicCopySync(t,n,r){let i=`${n}.${e.pid}.tmp`;try{T(t,i),r!==void 0&&C(i,r),N(i,n)}catch(e){try{P(i,{force:!0})}catch{}throw e}}function writeEntrypointShims(e,t){for(let n of Bt)atomicWriteSync(u(e,n),unixWrapperScript(n),493),t&&(atomicWriteSync(u(e,`${n}.cmd`),windowsCmdWrapperScript(n)),atomicWriteSync(u(e,`${n}.ps1`),windowsPowershellWrapperScript(n)))}function migrateLegacyBundleInstallIfNeeded(){let t=useCLIMetadata();if(t.installMethod!==`bundle`)return;let n=t.platform===`windows`,r=c(e.execPath),i=s(e.execPath).replace(/\.exe$/i,``).toLowerCase();if(n)for(let e of Bt){let t=u(r,`${e}.exe.old`);if(D(t))try{P(t,{force:!0}),cliDebugPrint(`[migration] removed stale legacy binary`,t)}catch(e){cliDebugPrint(`[migration] failed to remove stale legacy binary`,{stalePath:t,err:e})}}if(i===`apify-cli`||!Bt.includes(i))return;cliDebugPrint(`[migration] legacy multi-bundle install detected, migrating to single bundle`,{binDir:r,selfName:i});let a=u(r,`apify-cli${n?`.exe`:``}`);try{atomicCopySync(e.execPath,a,n?void 0:493),cliDebugPrint(`[migration] copied current bundle to`,a)}catch(e){cliDebugPrint(`[migration] failed to copy current bundle, will retry on next run`,{err:e});return}try{writeEntrypointShims(r,n),cliDebugPrint(`[migration] wrote entrypoint shims`)}catch(e){cliDebugPrint(`[migration] failed to write entrypoint shims, will retry on next run`,{err:e})}if(n){for(let t of Bt){let n=u(r,`${t}.exe`);if(D(n))try{p(n)===p(e.execPath)?(N(n,`${n}.old`),cliDebugPrint(`[migration] renamed running legacy binary`,n)):P(n,{force:!0})}catch(e){try{N(n,`${n}.old`)}catch{}cliDebugPrint(`[migration] failed to remove legacy binary`,{legacyBinaryPath:n,err:e})}}let t=u(r,`upgrade.ps1`);try{P(t,{force:!0}),cliDebugPrint(`[migration] removed upgrade script, it will be re-downloaded on the next upgrade`)}catch(e){cliDebugPrint(`[migration] failed to remove upgrade script`,{upgradeScriptPath:t,err:e})}}cliDebugPrint(`[migration] migration to single bundle complete`)}let Vt;function getMaxLineWidth(){if(Vt)return Vt;let e=Number(process.env.APIFY_CLI_MAX_LINE_WIDTH);if(!Number.isNaN(e))Vt=e;else if(!process.stdout.isTTY)Vt=80;else{let e=process.stdout.getWindowSize?.()[0]??-1;Vt=e<1?80:e<40?40:e}return Vt}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(`
|
|
@@ -144,8 +144,8 @@ Returns exit code 0 only when the build SUCCEEDED. Designed for CI and agentic w
|
|
|
144
144
|
💡 Tip: Turn on Automatic builds in the Actor's Source settings to rebuild on every push.`)):(c+=`
|
|
145
145
|
|
|
146
146
|
💡 Tip: Use 'apify push' to deploy your Actor to the Apify platform`,i&&(c+=`\n🌱 Git repository initialized in '${t}'. You can now commit and push your Actor to Git.`)),c+=`
|
|
147
|
-
📖 Docs: https://docs.apify.com/platform/actors/development`,r&&(c+=`\n\n${r}`),c}async function executePrompts(e,t){return promptTemplate(e,t.useCase?useCaseFlagToTag(t.useCase)??`any-use-case`:await promptUseCase(),t.language?languageFlagToTag(t.language)??t.language:await promptLanguage())}async function promptActorName(){return await _n({message:`Name of your new Actor:`,validate:e=>{try{validateActorName(e)}catch(e){return e.message}return!0}})}async function promptUseCase(){let e=[...Nr.map(e=>({name:e.label,value:e.templateTag})),new ot,{name:`Any use case`,value:Ar}];return Sr({message:`What do you want to build?`,choices:e,default:Nr[0].templateTag,loop:!1})}async function promptLanguage(){let e=[...Pr.map(e=>({name:e.label,value:e.templateTag})),new ot,{name:`Any language`,value:kr}];return Sr({message:`Choose the programming language of your new Actor:`,choices:e,default:Pr[0].templateTag,loop:!1})}async function promptTemplate(e,t,n){let{rows:r,separatorIndex:i,noExactMatchHint:a}=buildTemplateChoiceList(getTemplateRecommendation(e.templates,t,n),t,n);if(r.length===0)throw Error(`No Actor templates are available right now. Please try again later.`);let s=[];return r.forEach((e,t)=>{t===i&&s.push(new ot(`── The templates below don't exactly match your selection ──`)),s.push({name:e.label,value:e.template})}),a&&info({message:a,stdout:!1}),Sr({message:`Choose a template for your new Actor. More info at https://apify.com/templates`,choices:s,default:r[0].template,loop:!1,pageSize:8})}const Lr=3e5,connectViaConsole=async(e,t,{abortSignal:n,account:r}={})=>{let i=getConsoleUrl(),a=Re(),s,c=new Promise(e=>{s=e}),l=createLocalApiServer({corsOrigin:new URL(i).origin,authToken:a,routes:{"POST /api/v1/git-provider-connected":(e,t)=>{t.end(),cliDebugPrint(`git-source`,`connected`,e),s({connected:!0})},"POST /api/v1/exit":(e,n)=>{n.end(),s({stopReason:`connectCancelled`,message:e.isWindowClosed?`Connecting your ${t} account stopped: the Apify Console window was closed.`:`Connecting your ${t} account was canceled in Apify Console.`})}}}),u=setTimeout(()=>s({stopReason:`connectTimedOut`,message:`Connecting your ${t} account did not finish within ${Lr/6e4} minutes.`}),Lr);n?.addEventListener(`abort`,()=>s({abandoned:!0}),{once:!0}),l.listen(0);let{port:f}=l.address(),p=new URL(getConsoleIntegrationsUrl(r));p.searchParams.set(`localCliCommand`,`connect-git-provider`),p.searchParams.set(`gitProvider`,e),p.searchParams.set(`localCliPort`,`${f}`),p.searchParams.set(`localCliToken`,a),p.searchParams.set(`localCliApiVersion`,`v1`);try{p.searchParams.set(`localCliComputerName`,encodeURIComponent(Ot()))}catch{}info({message:`Connect your ${t} account to Apify: ${p.href}`}),wt(p.href).catch(()=>void 0),info({message:`Waiting for the connection to complete in your browser...`});try{return await c}finally{clearTimeout(u),l.closeAllConnections(),l.close()}},Rr=[`apify`,`github`,`gitlab`,`bitbucket`],zr={github:{label:`GitHub`,authorize:{endpoint:`https://github.com/login/oauth/authorize`,defaultClientId:`Iv1.e39b3ed87e74885f`,clientIdEnvVar:`APIFY_GITHUB_APP_CLIENT_ID`,defaultAppName:`apify`,appNameEnvVar:`APIFY_GITHUB_APP_NAME`,appInstallUrl:`https://github.com/apps/{app}/installations/new`,redirectPath:`/actors/new/git/connected?service=github`}},gitlab:{label:`GitLab`},bitbucket:{label:`Bitbucket`}},isGitProvider=e=>Object.hasOwn(zr,e),toGitAccount=({id:e,username:t,organizationOwnerUserId:n})=>({id:e,username:t,organizationOwnerUserId:n}),getGitConnectUrl=(t,n)=>{let{authorize:r}=zr[t];if(!r)return getConsoleIntegrationsUrl(n);let i=new URL(r.redirectPath,getConsoleUrl()),a=getConsoleRoutePrefix(n);a&&i.searchParams.set(`routePrefix`,encodeURIComponent(a));let s=new URL(r.endpoint);return s.searchParams.set(`client_id`,e.env[r.clientIdEnvVar]||r.defaultClientId),s.searchParams.set(`redirect_uri`,i.href),s.href},getAddWorkspaceUrl=(t,n)=>{let{authorize:r}=zr[t];return r?r.appInstallUrl.replace(`{app}`,e.env[r.appNameEnvVar]||r.defaultAppName):getConsoleIntegrationsUrl(n)},promptGitSource=async()=>Sr({message:`Where will the source code live?`,choices:[{name:`Apify`,value:`apify`,description:`Deploy with "apify push". No Git provider involved.`},...Rr.filter(isGitProvider).map(e=>({name:zr[e].label,value:e,description:`Apify creates a private repository on ${zr[e].label} and builds the Actor from it.`}))],default:`apify`,loop:!1}),parseGitRepoFlag=(e,t)=>{if(!e)return{workspace:void 0,repoName:t};let n=e.lastIndexOf(`/`);if(n===-1)return{workspace:void 0,repoName:e};let r=e.slice(0,n),i=e.slice(n+1);if(!r||!i)throw Error(`Invalid --git-repo "${e}". Use "workspace/name" or just "name".`);return{workspace:r,repoName:i}},apiUrl=({client:e},t)=>`${e.baseUrl}/${t}`,authHeader=({client:e})=>({Authorization:`Bearer ${e.token}`}),fetchGitIntegrations=async e=>{let t=apiUrl(e,`integrations/git`);cliDebugPrint(`git-source`,`GET`,t);let n=await fetch(t,{headers:authHeader(e)}),r=await n.text();if(cliDebugPrint(`git-source`,`GET`,t,`->`,n.status,r.slice(0,400)),!n.ok)throw Error(`Could not read your Git integrations (${n.status} ${n.statusText}).`);return(()=>{try{return JSON.parse(r)}catch{return null}})()?.data??[]},readProviderState=(e,t)=>{let n=e.filter(e=>e.provider===t);return{connected:n.length>0,workspaces:n.flatMap(e=>e.workspaces.map(t=>({...t,providerId:e.id}))),addWorkspaceUrl:n.find(({addWorkspaceUrl:e})=>e)?.addWorkspaceUrl}},Br=2e3,Vr=18e4,pollForWorkspaces=async(e,{timeoutMs:t,abortSignal:n,onState:r})=>{let i=Date.now()+t,a=Br,s=null;for(;Date.now()<i;){try{await Pt(a,void 0,{signal:n})}catch{return s}a=Math.min(Math.round(a*1.5),1e4);try{s=await e()}catch(e){cliDebugPrint(`git-source`,`poll failed:`,e);continue}if(s.workspaces.length)return s;await r?.(s)}return s},ensureUsableIntegration=async(e,{client:t,isInteractive:n,account:r})=>{let load=async()=>readProviderState(await fetchGitIntegrations({client:t}),e),i=await load();if(cliDebugPrint(`git-source`,`integrations:`,e,i.connected,`workspaces=${i.workspaces.length}`),i.workspaces.length||!n)return i;let{label:a,authorize:s}=zr[e];if(!i.connected&&!s){let t=new AbortController,n=Date.now(),s=connectViaConsole(e,a,{abortSignal:t.signal,account:r}),c;try{c=await Promise.race([s.then(()=>null),pollForWorkspaces(load,{timeoutMs:Lr,abortSignal:t.signal})])}finally{t.abort()}if(c?.workspaces.length)return c;let l=await s;if(`stopReason`in l)return warning({message:l.message}),i;if(i=await load(),i.workspaces.length)return i;let u=Math.min(Vr,Lr-(Date.now()-n));return u<Br?i:(info({message:`Waiting for Apify to finish connecting your ${a} account...`}),await pollForWorkspaces(load,{timeoutMs:u})??i)}let c=null,offer=async t=>{let n=t.connected?t.addWorkspaceUrl??getAddWorkspaceUrl(e,r):getGitConnectUrl(e,r);n!==c&&(c=n,info({message:`${t.connected?`Give Apify access to a ${a} account`:`Connect your ${a} account to Apify`}: ${n}`}),await wt(n).catch(()=>void 0),info({message:r?.username?`Waiting for authorization to complete in your browser. It connects ${a} to the Apify account ${r.username}.`:`Waiting for authorization to complete in your browser...`}))};return await offer(i),await pollForWorkspaces(load,{timeoutMs:Vr,onState:offer})??i},chooseWorkspace=async(e,t,n)=>{if(t){let n=t.toLowerCase(),r=e.find(({id:e,label:t})=>e.toLowerCase()===n||t.toLowerCase()===n);return r?{workspace:r}:{stopReason:`unknownWorkspace`}}return e.length===1?{workspace:e[0]}:n?{workspace:await Sr({message:`Which account should own the repository?`,choices:e.map(e=>({name:e.label,value:e})),loop:!1})}:{stopReason:`ambiguousWorkspace`}};var CreateRemoteRepoError=class extends Error{stopReason;constructor(e,t){super(e),this.stopReason=t,this.name=`CreateRemoteRepoError`}};const Hr=new Set([`integration-auth-error`,`invalid-git-auth-token`]),withoutUserInfo=e=>{if(!URL.canParse(e))return e;let t=new URL(e);return t.username=``,t.password=``,t.href},createRemoteRepo=async e=>{let{providerId:t,workspace:n,repoName:r,isPrivate:i,templateArchiveUrl:a}=e,s=apiUrl(e,`integrations/git/${t}/create-repo`),c=JSON.stringify({workspace:n,repoName:r,isPrivate:i,templateArchiveUrl:a});cliDebugPrint(`git-source`,`POST`,s,c);let l=await fetch(s,{method:`POST`,headers:{...authHeader(e),"Content-Type":`application/json`},body:c}),u=await l.text();cliDebugPrint(`git-source`,`POST`,s,`->`,l.status,u.slice(0,400));let f=(()=>{try{return JSON.parse(u)}catch{return null}})();if(l.ok&&f?.data)return{...f.data,httpsUrl:withoutUserInfo(f.data.httpsUrl)};let p=f?.error?.type,m=f?.error?.message||`${l.status} ${l.statusText}`;throw p&&Hr.has(p)?new CreateRemoteRepoError(m,`notAuthorized`):p===`invalid-parameter`?new CreateRemoteRepoError(m,`repoNameRejected`):new CreateRemoteRepoError(m,`repoCreateFailed`)},cloneRepo=async(e,t,n)=>{await Ee(`git`,[`clone`,t,e],{env:n?void 0:{GIT_TERMINAL_PROMPT:`0`,GIT_SSH_COMMAND:`ssh -o BatchMode=yes`}})},createGitActor=async({client:e,actorName:t,gitRepoUrl:n})=>e.actors().create({name:t,versions:[{versionNumber:`0.0`,sourceType:fe.GIT_REPO,gitRepoUrl:n}]}),registerDeploymentKey=async({client:e,providerId:t,actorId:n,repoUrl:r})=>{let i=apiUrl({client:e},`integrations/git/${t}/register-deployment-key`),a=JSON.stringify({actorId:n,repoName:r});cliDebugPrint(`git-source`,`POST`,i,a);let s=await fetch(i,{method:`POST`,headers:{...authHeader({client:e}),"Content-Type":`application/json`},body:a}),c=await s.text();if(cliDebugPrint(`git-source`,`POST`,i,`->`,s.status,c.slice(0,400)),s.ok)return;let l=(()=>{try{return JSON.parse(c).error?.message}catch{return null}})();throw Error(l||`${s.status} ${s.statusText}`)},enableAutomaticBuilds=async({client:e,providerId:t,actorId:n})=>{let r=apiUrl({client:e},`actors/${n}/versions/0.0/build-on-push`),i=JSON.stringify({providerId:t,enabled:!0});cliDebugPrint(`git-source`,`PUT`,r,i);let a=await fetch(r,{method:`PUT`,headers:{...authHeader({client:e}),"Content-Type":`application/json`},body:i}),s=await a.text();if(cliDebugPrint(`git-source`,`PUT`,r,`->`,a.status,s.slice(0,400)),a.ok)return;let c=(()=>{try{return JSON.parse(s).error?.message}catch{return null}})();throw Error(c||`${a.status} ${a.statusText}`)},runGitSourceFlow=async({client:e,provider:t,actorDir:n,actorName:r,workspace:i,repoName:a,isPrivate:s,templateArchiveUrl:c,isInteractive:l,account:u,autoBuild:f,customize:p})=>{let m=!1,stopped=(e,t,n={})=>({remoteUrl:null,httpsUrl:null,actorId:null,workspaces:null,scaffolded:m,automaticBuilds:`off`,...n,stopReason:e,error:t instanceof Error?t.message:String(t)}),h;try{h=await ensureUsableIntegration(t,{client:e,isInteractive:l,account:u})}catch(e){return stopped(`lookupFailed`,e)}let{label:g}=zr[t],_=u?.username?`The Apify account ${u.username}`:`Apify`;if(!h.connected)return stopped(`notAuthorized`,Error(`${_} is not authorized to access your ${g} account.`));if(!h.workspaces.length)return stopped(`noWorkspace`,Error(`${_} has no ${g} account to create the repository in.`));let v=h.workspaces.map(({label:e})=>e),y=v.join(`, `),b=await chooseWorkspace(h.workspaces,i,l);if(`stopReason`in b)return stopped(b.stopReason,Error(b.stopReason===`unknownWorkspace`?`"${i}" is not one of your connected accounts (${y}).`:`Several accounts are connected (${y}); pick one with --git-repo <account>/<name>.`),{workspaces:v});let{workspace:x}=b,S;for(;;)try{info({message:`Creating ${s?`private`:`public`} repository ${x.label}/${a} from the template...`}),S=await createRemoteRepo({client:e,providerId:x.providerId,workspace:x.id,repoName:a,isPrivate:s,templateArchiveUrl:c});break}catch(e){if(e instanceof CreateRemoteRepoError&&e.stopReason===`repoNameRejected`&&l){warning({message:e.message}),a=await _n({message:`Choose a different repository name:`,validate:e=>e.trim().length>0||`Enter a repository name.`});continue}return stopped(e instanceof CreateRemoteRepoError?e.stopReason:`repoCreateFailed`,e,{workspaces:v})}let C=null;try{info({message:`Cloning ${S.httpsUrl}...`}),await cloneRepo(n,S.httpsUrl,l),m=!0,await p(n)}catch(e){let t=e.stderr?.trim();C=t?Error(t):e}let w;try{let t=await createGitActor({client:e,actorName:r,gitRepoUrl:S.sshUrl});info({message:`Created Actor ${t.name} on Apify.`}),w=t.id}catch(e){return stopped(`actorCreateFailed`,e,{workspaces:v,remoteUrl:S.sshUrl,httpsUrl:S.httpsUrl})}try{await registerDeploymentKey({client:e,providerId:x.providerId,actorId:w,repoUrl:S.htmlUrl})}catch(e){return stopped(`deploymentKeyFailed`,e,{workspaces:v,remoteUrl:S.sshUrl,httpsUrl:S.httpsUrl,actorId:w})}let T=`off`;if(f)try{await enableAutomaticBuilds({client:e,providerId:x.providerId,actorId:w}),T=`on`,info({message:`Turned on automatic builds.`})}catch(e){T=`failed`,warning({message:`Automatic builds stay off: ${e instanceof Error?e.message:String(e)}`})}else info({message:`Automatic builds stay off, so a push does not rebuild the Actor.`});return C?stopped(`gitSetupFailed`,C,{workspaces:v,remoteUrl:S.sshUrl,httpsUrl:S.httpsUrl,actorId:w,automaticBuilds:T}):{remoteUrl:S.sshUrl,httpsUrl:S.httpsUrl,actorId:w,workspaces:v,stopReason:null,error:null,scaffolded:!0,automaticBuilds:T}},getGitStopUrl=(e,t,n)=>t===`notAuthorized`?getGitConnectUrl(e,n):t===`noWorkspace`?getAddWorkspaceUrl(e,n):null,buildGitSourceNextSteps=({actorName:e,stopReason:t,provider:n,remoteUrl:r,httpsUrl:i,repoName:a,scaffolded:s,actorId:c,account:l})=>{let u=`cd "${e}"`;switch(t){case`lookupFailed`:return[`Re-run with APIFY_CLI_DEBUG=1 to see the failing request`];case`notAuthorized`:return[`Connect your ${zr[n].label} account to Apify: ${getGitConnectUrl(n,l)}`,`then re-run apify create`];case`noWorkspace`:return[`Give Apify access to a ${zr[n].label} account: ${getAddWorkspaceUrl(n,l)}`,`then re-run apify create`];case`unknownWorkspace`:case`ambiguousWorkspace`:return[`Re-run naming the account: --git-repo <account>/${a}`];case`repoNameRejected`:return[`Re-run with a different repository name: --git-repo <account>/<other-name>`,`The name has to be free, and to use only letters, numbers, hyphens and underscores`];case`repoCreateFailed`:return[`Re-run apify create to try again`];case`gitSetupFailed`:return s?[u,`Apply the local configuration by hand: the error above says what failed`]:[`git clone ${i} "${e}"`,`Or clone over SSH, if you have a key for the provider: git clone ${r} "${e}"`,u];case`actorCreateFailed`:return[u,`Create an Actor from ${r} in Apify Console`];case`deploymentKeyFailed`:return[...s?[u]:[`git clone ${i} "${e}"`,u],`Add the Apify deploy key in the Actor's Source settings before building: ${getConsoleUrl()}/actors/${c}`]}},logGitSourceOutcome=(e,t)=>{e.stopReason&&(warning({message:`${e.scaffolded?`Actor scaffolded, but the Git setup did not finish`:e.actorId?`Actor created, but the clone failed`:`The Actor was not created: the Git setup stopped`}: ${e.error}`}),info({message:`Next steps:\n${t.map(e=>` ${e}`).join(`
|
|
148
|
-
`)}`}))};var CreateCommand=class extends ApifyCommand{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 group=`Local Actor Development`;static interactive=!0;static interactiveNote=`Prompts for an Actor name, then guides you through what you want to build, a language, a template, and where the source code lives when they are not provided. To run non-interactively, pass the name and --template; --source defaults to "apify". Use --use-case and --language to narrow the template list.`;static examples=[{description:`Create a new Actor project interactively (guided name, use case, language, and template prompts).`,command:`apify create`},{description:`Narrow the guided template list by use case and language.`,command:`apify create my-actor --use-case web-scraper --language python`},{description:`Create non-interactively with explicit name and template.`,command:`apify create my-actor --template js-crawlee-cheerio`},{description:`Create without installing dependencies (faster; run install yourself later).`,command:`apify create my-actor --template python-start --skip-dependency-install`},{description:`Host the source code on GitHub. Apify creates the repository and builds the Actor from it.`,command:`apify create my-actor --template js-crawlee-cheerio --source github`},{description:`Name the account and the repository to create, instead of being asked.`,command:`apify create my-actor --template js-crawlee-cheerio --source github --git-repo my-org/my-scraper`}];static docsUrl=`https://docs.apify.com/cli/docs/reference#apify-create`;static flags={template:Y.string({char:`t`,description:`Template for the Actor. If not provided, the command will prompt for it. Visit ${Et} to find available template names.`,required:!1}),"use-case":Y.string({char:`u`,description:`Filter templates by use case. Ignored when --template is provided. To see the use cases each template supports, run "apify templates ls".`,choices:Ir,required:!1}),language:Y.string({char:`l`,description:`Filter templates by programming language. Ignored when --template is provided.`,choices:Fr,required:!1}),"skip-dependency-install":Y.boolean({description:`Skip installing Actor dependencies.`,required:!1}),"template-archive-url":Y.string({description:`Actor template archive url. Useful for developing new templates.`,required:!1,hidden:!0}),"omit-optional-deps":Y.boolean({aliases:[`no-optional`],description:`Skip installing optional dependencies.`,required:!1}),"skip-git-init":Y.boolean({description:`Skip initializing a git repository in the Actor directory.`,required:!1}),source:Y.string({description:`Where the Actor source code will live. With a Git provider, Apify creates the repository on your connected account from the template, clones it here, and creates an Actor that builds from it.`,choices:[...Rr],required:!1}),"git-repo":Y.string({description:`Repository to create, as "workspace/name" — a workspace being an account or organization you have given Apify access to. A bare value is read as the name, not the workspace. The name defaults to the Actor name, and the workspace is asked for when you have more than one. List yours with "apify api integrations/git". Only used when --source is a Git provider.`,required:!1}),"auto-build":Y.string({description:`Whether a push to the repository rebuilds the Actor. On by default. Turning it on registers a push webhook on the new repository, which needs admin rights on it. Only used when --source is a Git provider.`,choices:[`on`,`off`],required:!1}),origin:Y.string({description:`Where the command was invoked from. Used for funnel telemetry.`,choices:[`console`,`cli`],default:`cli`,required:!1,hidden:!0})};static args={actorName:Z.string({required:!1,description:`Name of the Actor and its directory.`})};static enableJsonFlag=!0;async run(){let{actorName:t}=this.args,{template:n,useCase:r,language:i,skipDependencyInstall:a,skipGitInit:s,origin:c,json:l,gitRepo:f}=this.flags,{templateArchiveUrl:p}=this.flags,m=!1,h=!n&&!p;if(l&&(!t||h)){let e=[...t?[]:[`the Actor name as an argument`],...h?[`--template <name>`]:[]],n=h?` Run "apify templates ls" to list template names.`:``;throw Error(`--json runs non-interactively. Pass ${e.join(` and `)}.${n}`)}let g=this.flags.source,_=Tt().catch(e=>Error(`Could not fetch template list from server. Cause: ${e?.message}`));t=await ensureValidActorName(t);let v=e.cwd(),x=u(v,t);for(;;){let e=await V(x).catch(()=>null),n=e&&await ke(x).then(e=>e.length>0).catch(()=>!1);if(e?.isDirectory()&&n){let e=`Cannot create new Actor, directory '${t}' already exists. Provide a different name. To create a local Actor environment inside an existing directory, use "apify init".`;if(l)throw Error(e);error({message:e}),t=await ensureValidActorName(),x=u(v,t);continue}e||await z(x,{recursive:!0});break}let S=null,C=null;if(this.telemetryData.create={fromArchiveUrl:!!p,origin:c},!p){let e=await getTemplateDefinition(n,_,{useCase:r,language:i});({archiveUrl:p,messages:S}=e),C=e.id,this.telemetryData.create.templateId=e.id,this.telemetryData.create.templateName=e.name,this.telemetryData.create.templateLanguage=e.category,`skipOptionalDeps`in e&&(m=e.skipOptionalDeps)}this.flags.omitOptionalDeps&&(m=!0);let{isTTY:w}=await useStdin(),T=w&&!le&&!l;g??=T?await promptGitSource():`apify`;let E=isGitProvider(g)?g:null;if(this.telemetryData.create.source=g,E&&s)throw Error(`--source ${g} clones a git repository, so --skip-git-init cannot apply.`);if(!E&&f)throw Error(`--git-repo only applies to a Git source, so add --source github|gitlab|bitbucket or drop it.`);if(!E&&this.flags.autoBuild)throw Error(`--auto-build only applies to a Git source, so add --source github|gitlab|bitbucket or drop it.`);if(E&&this.flags.templateArchiveUrl)throw Error(`--template-archive-url is not supported with --source ${g}.`);let D=E?{provider:E,client:await getLoggedClientOrThrow(),account:toGitAccount(await getLocalUserInfo()),autoBuild:this.flags.autoBuild!==`off`,...parseGitRepoFlag(f,t)}:null,applyLocalConfig=async e=>{let n=getJsonFileContent(u(e,G));await setLocalConfig(Object.assign(n||Qt,{name:t}),e),await setLocalEnv(e),await createPrefilledInputFileFromInputSchema(e)};E||(await downloadAndUnzip({url:p,pathTo:x}),await applyLocalConfig(x),await enhanceReadmeWithLocalSuffix(u(x,`README.md`),_));let O=u(x,`package.json`),k=null;D&&(k=await runGitSourceFlow({provider:D.provider,actorDir:x,actorName:t,workspace:D.workspace,repoName:D.repoName,isPrivate:!0,templateArchiveUrl:p,client:D.client,isInteractive:T,account:D.account,autoBuild:D.autoBuild,customize:applyLocalConfig}));let A=!1;a||await(await useCwdProject({cwd:x})).inspectAsync(async n=>{let r=b(nn);if((n.type===1||n.type===2)&&n.packageManager===`uv`){let e=await Ie(`uv`,{nothrow:!0});if(!e){warning({message:`This Actor uses uv to manage its dependencies, but the uv executable was not found. Install uv (https://docs.astral.sh/uv/getting-started/installation/), then run "uv sync" in the Actor directory.`});return}info({message:`Installing dependencies with "uv sync"...`}),await execWithLog({cmd:e,args:[`sync`],opts:{cwd:x}}),A=!0;return}if(!n.runtime){switch(n.type){case 0:warning({message:`No Node.js detected! Please install Node.js ${r} or higher to be able to run Node.js Actors locally.`});break;case 2:case 1:warning({message:`No Python detected! Please install Python ${on} or higher to be able to run Python Actors locally.`})}return}let{runtime:i}=n;switch(n.type){case 0:{isNodeVersionSupported(i.version)||warning({message:`You are running Node.js version ${i.version}, which is no longer supported. Please upgrade to Node.js version ${r} or later.`}),await updateLocalJson(O,{name:t});let e=[`install`];if(m)switch(i.pmName){case`npm`:y(i.pmVersion,`7.0.0`)?e.push(`--omit=optional`):e.push(`--no-optional`);break;case`bun`:e.push(`--omit=optional`);break;case`deno`:e.push(`--node-modules-dir`)}await execWithLog({cmd:i.pmPath,args:e,opts:{cwd:x},overrideCommand:i.pmName}),A=!0;break}case 1:case 2:{if(!isPythonVersionSupported(i.version)){warning({message:`Python Actors require Python ${on} or higher, but you have Python ${i.version}!`}),warning({message:`Please install Python ${on} or higher to be able to run Python Actors locally.`});return}let t=u(x,`.venv`);info({message:`Python version ${i.version} detected.`}),info({message:`Creating a virtual environment in "${t}" and installing dependencies from "requirements.txt"...`}),e.env.VIRTUAL_ENV||(await execWithLog({cmd:i.executablePath,args:[`-m`,`venv`,`--prompt`,`.`,`.venv`],opts:{cwd:x}}),i=(await usePythonRuntime({cwd:x,force:!0})).unwrap(),n.runtime=i),await execWithLog({cmd:i.executablePath,args:[`-m`,`pip`,`install`,`--no-cache-dir`,`--no-warn-script-location`,`--upgrade`,`pip`,`setuptools`,`wheel`],opts:{cwd:x}}),await execWithLog({cmd:i.executablePath,args:[`-m`,`pip`,`install`,`--no-cache-dir`,`--no-warn-script-location`,`-r`,`requirements.txt`],opts:{cwd:x}}),A=!0;break}}});let j={success:!0},ee=await V(u(v,`.git`)).catch(()=>null),M=await V(u(x,`.git`)).catch(()=>null),N=k!==null&&!k.scaffolded,P=!s&&!ee&&!M&&!N;if(P)try{await execWithLog({cmd:`git`,args:[`init`],opts:{cwd:x}})}catch(e){j={success:!1,error:e}}let te=A?null:await getInstallCommandSuggestion(x),ne=P&&j.success||!!M;k?.stopReason&&(e.exitCode=1);let F=D&&k?.stopReason?buildGitSourceNextSteps({actorName:t,stopReason:k.stopReason,provider:D.provider,remoteUrl:k.remoteUrl,httpsUrl:k.httpsUrl,repoName:D.repoName,scaffolded:k.scaffolded,actorId:k.actorId,account:D.account}):buildNextSteps({actorName:t,dependenciesInstalled:A,installCommandSuggestion:te}),re=!k?.stopReason;l?printJsonToStdout({dir:x,actorJsonPath:u(x,G),template:C,source:g,nextSteps:F,postCreate:S?.postCreate??null,gitRepositoryInitialized:ne,remote:k?.remoteUrl??null,automaticBuilds:k?.automaticBuilds??null,actorId:k?.actorId??null,stopReason:k?.stopReason??null,error:k?.error??null,gitConnectUrl:E?getGitStopUrl(E,k?.stopReason??null,D?.account):null,workspaces:k?.workspaces??null}):re&&(simpleLog({message:``}),success({message:formatCreateSuccessMessage({actorName:t,dependenciesInstalled:A,postCreate:S?.postCreate??null,gitRepositoryInitialized:ne,installCommandSuggestion:te,gitRemote:k?.remoteUrl&&k.actorId?{remoteUrl:k.remoteUrl,actorId:k.actorId,automaticBuilds:k.automaticBuilds}:null})})),P&&!j.success&&(warning({message:`Failed to initialize git repository: ${j.error.message}`}),warning({message:`You can manually run "git init" in the Actor directory if needed.`})),k&&!l&&logGitSourceOutcome(k,F)}};async function tryToGetStorage(e,t,n){let r=await e[n](t).get().catch(()=>void 0);if(r)return{[n]:r,[`${n}Client`]:e[n](r.id)};let i=await getLocalUserInfo(),a=await e[n](`${i.username}/${t}`).get().catch(()=>void 0);return a?{[n]:a,[`${n}Client`]:e[n](a.id)}:null}async function tryToGetDataset(e,t){return tryToGetStorage(e,t,`dataset`)}async function tryToGetKeyValueStore(e,t){return tryToGetStorage(e,t,`keyValueStore`)}var DatasetsCreateCommand=class extends ApifyCommand{static name=`create`;static description=`Creates a new dataset for storing structured data on your account.`;static examples=[{description:`Create an unnamed dataset.`,command:`apify datasets create`},{description:`Create a named dataset.`,command:`apify datasets create my-dataset`}];static docsUrl=`https://docs.apify.com/cli/docs/reference#apify-datasets-create`;static args={datasetName:Z.string({description:`Optional name for the Dataset.`,required:!1})};static enableJsonFlag=!0;async run(){let{datasetName:e}=this.args,n=await getLoggedClientOrThrow();if(e&&await tryToGetDataset(n,e)){error({message:`A Dataset with this name already exists!`});return}let r=await n.datasets().getOrCreate(e);if(this.flags.json){printJsonToStdout(r);return}success({message:`Dataset with ID ${t.yellow(r.id)}${e?` (called ${t.yellow(e)})`:``} was created.`,stdout:!0})}};const Ur={[U.JSON]:`application/json`,[U.JSONL]:`application/jsonl`,[U.CSV]:`text/csv`,[U.HTML]:`text/html`,[U.RSS]:`application/rss+xml`,[U.XML]:`application/xml`,[U.XLSX]:`application/vnd.openxmlformats-officedocument.spreadsheetml.sheet`};var DatasetsGetItems=class extends ApifyCommand{static name=`get-items`;static description=`Retrieves dataset items in specified format (JSON, CSV, etc).`;static examples=[{description:`Print all items from a dataset as JSON.`,command:`apify datasets get-items <datasetId>`},{description:`Export the first 100 items as CSV to a file.`,command:`apify datasets get-items <datasetId> --format csv --limit 100 > items.csv`},{description:`Paginate: skip the first 500 items, return the next 500.`,command:`apify datasets get-items <datasetId> --offset 500 --limit 500`}];static docsUrl=`https://docs.apify.com/cli/docs/reference#apify-datasets-get-items`;static flags={limit:Y.integer({description:`The amount of elements to get from the dataset. By default, it will return all available items.`}),offset:Y.integer({description:`The offset in the dataset where to start getting items.`}),format:Y.string({description:`The format of the returned output. By default, it is set to 'json'.`,choices:Object.keys(Ur),default:U.JSON})};static args={datasetId:Z.string({description:`The ID of the Dataset to export the items for.`,required:!0})};async run(){let{limit:e,offset:t,format:n}=this.flags,{datasetId:r}=this.args,i=await getLoggedClientOrThrow(),a=await this.tryToGetDataset(i,r);if(!a){error({message:`Dataset with ID "${r}" not found.`});return}let{datasetClient:s}=a;process.stdout.write(``);let c=await s.downloadItems(n,{limit:e,offset:t});simpleLog({message:Ur[n]??`application/octet-stream`}),process.stdout.write(c),process.stdout.write(`
|
|
147
|
+
📖 Docs: https://docs.apify.com/platform/actors/development`,r&&(c+=`\n\n${r}`),c}async function executePrompts(e,t){return promptTemplate(e,t.useCase?useCaseFlagToTag(t.useCase)??`any-use-case`:await promptUseCase(),t.language?languageFlagToTag(t.language)??t.language:await promptLanguage())}async function promptActorName(){return await _n({message:`Name of your new Actor:`,validate:e=>{try{validateActorName(e)}catch(e){return e.message}return!0}})}async function promptUseCase(){let e=[...Nr.map(e=>({name:e.label,value:e.templateTag})),new ot,{name:`Any use case`,value:Ar}];return Sr({message:`What do you want to build?`,choices:e,default:Nr[0].templateTag,loop:!1})}async function promptLanguage(){let e=[...Pr.map(e=>({name:e.label,value:e.templateTag})),new ot,{name:`Any language`,value:kr}];return Sr({message:`Choose the programming language of your new Actor:`,choices:e,default:Pr[0].templateTag,loop:!1})}async function promptTemplate(e,t,n){let{rows:r,separatorIndex:i,noExactMatchHint:a}=buildTemplateChoiceList(getTemplateRecommendation(e.templates,t,n),t,n);if(r.length===0)throw Error(`No Actor templates are available right now. Please try again later.`);let s=[];return r.forEach((e,t)=>{t===i&&s.push(new ot(`── The templates below don't exactly match your selection ──`)),s.push({name:e.label,value:e.template})}),a&&info({message:a,stdout:!1}),Sr({message:`Choose a template for your new Actor. More info at https://apify.com/templates`,choices:s,default:r[0].template,loop:!1,pageSize:8})}const Lr=3e5,connectViaConsole=async(e,t,{abortSignal:n,account:r}={})=>{let i=getConsoleUrl(),a=Re(),s,c=new Promise(e=>{s=e}),l=createLocalApiServer({corsOrigin:new URL(i).origin,authToken:a,routes:{"POST /api/v1/git-provider-connected":(e,t)=>{t.end(),cliDebugPrint(`git-source`,`connected`,e),s({connected:!0})},"POST /api/v1/exit":(e,n)=>{n.end(),s({stopReason:`connectCancelled`,message:e.isWindowClosed?`Connecting your ${t} account stopped: the Apify Console window was closed.`:`Connecting your ${t} account was canceled in Apify Console.`})}}}),u=setTimeout(()=>s({stopReason:`connectTimedOut`,message:`Connecting your ${t} account did not finish within ${Lr/6e4} minutes.`}),Lr);n?.addEventListener(`abort`,()=>s({abandoned:!0}),{once:!0}),l.listen(0);let{port:f}=l.address(),p=new URL(getConsoleIntegrationsUrl(r));p.searchParams.set(`localCliCommand`,`connect-git-provider`),p.searchParams.set(`gitProvider`,e),p.searchParams.set(`localCliPort`,`${f}`),p.searchParams.set(`localCliToken`,a),p.searchParams.set(`localCliApiVersion`,`v1`);try{p.searchParams.set(`localCliComputerName`,encodeURIComponent(Ot()))}catch{}info({message:`Connect your ${t} account to Apify: ${p.href}`}),wt(p.href).catch(()=>void 0),info({message:`Waiting for the connection to complete in your browser...`});try{return await c}finally{clearTimeout(u),l.closeAllConnections(),l.close()}},Rr=[`apify`,`github`,`gitlab`,`bitbucket`],zr={github:{label:`GitHub`,authorize:{endpoint:`https://github.com/login/oauth/authorize`,defaultClientId:`Iv1.e39b3ed87e74885f`,clientIdEnvVar:`APIFY_GITHUB_APP_CLIENT_ID`,defaultAppName:`apify`,appNameEnvVar:`APIFY_GITHUB_APP_NAME`,appInstallUrl:`https://github.com/apps/{app}/installations/new`,redirectPath:`/actors/new/git/connected?service=github`}},gitlab:{label:`GitLab`},bitbucket:{label:`Bitbucket`}},isGitProvider=e=>Object.hasOwn(zr,e),toGitAccount=({id:e,username:t,organizationOwnerUserId:n})=>({id:e,username:t,organizationOwnerUserId:n}),getGitConnectUrl=(t,n)=>{let{authorize:r}=zr[t];if(!r)return getConsoleIntegrationsUrl(n);let i=new URL(r.redirectPath,getConsoleUrl()),a=getConsoleRoutePrefix(n);a&&i.searchParams.set(`routePrefix`,encodeURIComponent(a));let s=new URL(r.endpoint);return s.searchParams.set(`client_id`,e.env[r.clientIdEnvVar]||r.defaultClientId),s.searchParams.set(`redirect_uri`,i.href),s.href},getAddWorkspaceUrl=(t,n)=>{let{authorize:r}=zr[t];return r?r.appInstallUrl.replace(`{app}`,e.env[r.appNameEnvVar]||r.defaultAppName):getConsoleIntegrationsUrl(n)},promptGitSource=async()=>Sr({message:`How do you want to set up the source code?`,choices:[{name:`Local only`,value:`apify`,description:`Everything stays on this machine and nothing is uploaded. Deploy with "apify push".`},...Rr.filter(isGitProvider).map(e=>{let{label:t}=zr[e];return{name:`Host on ${t}`,value:e,description:`Apify creates a private repository on ${t}, clones it into the Actor directory, and creates an Actor that builds from it.`}})],default:`apify`,loop:!1}),parseGitRepoFlag=(e,t)=>{if(!e)return{workspace:void 0,repoName:t};let n=e.lastIndexOf(`/`);if(n===-1)return{workspace:void 0,repoName:e};let r=e.slice(0,n),i=e.slice(n+1);if(!r||!i)throw Error(`Invalid --git-repo "${e}". Use "workspace/name" or just "name".`);return{workspace:r,repoName:i}},apiUrl=({client:e},t)=>`${e.baseUrl}/${t}`,authHeader=({client:e})=>({Authorization:`Bearer ${e.token}`}),fetchGitIntegrations=async e=>{let t=apiUrl(e,`integrations/git`);cliDebugPrint(`git-source`,`GET`,t);let n=await fetch(t,{headers:authHeader(e)}),r=await n.text();if(cliDebugPrint(`git-source`,`GET`,t,`->`,n.status,r.slice(0,400)),!n.ok)throw Error(`Could not read your Git integrations (${n.status} ${n.statusText}).`);return(()=>{try{return JSON.parse(r)}catch{return null}})()?.data??[]},readProviderState=(e,t)=>{let n=e.filter(e=>e.provider===t);return{connected:n.length>0,workspaces:n.flatMap(e=>e.workspaces.map(t=>({...t,providerId:e.id}))),addWorkspaceUrl:n.find(({addWorkspaceUrl:e})=>e)?.addWorkspaceUrl}},Br=2e3,Vr=18e4,pollForWorkspaces=async(e,{timeoutMs:t,abortSignal:n,onState:r})=>{let i=Date.now()+t,a=Br,s=null;for(;Date.now()<i;){try{await Pt(a,void 0,{signal:n})}catch{return s}a=Math.min(Math.round(a*1.5),1e4);try{s=await e()}catch(e){cliDebugPrint(`git-source`,`poll failed:`,e);continue}if(s.workspaces.length)return s;await r?.(s)}return s},ensureUsableIntegration=async(e,{client:t,isInteractive:n,account:r})=>{let load=async()=>readProviderState(await fetchGitIntegrations({client:t}),e),i=await load();if(cliDebugPrint(`git-source`,`integrations:`,e,i.connected,`workspaces=${i.workspaces.length}`),i.workspaces.length||!n)return i;let{label:a,authorize:s}=zr[e];if(!i.connected&&!s){let t=new AbortController,n=Date.now(),s=connectViaConsole(e,a,{abortSignal:t.signal,account:r}),c;try{c=await Promise.race([s.then(()=>null),pollForWorkspaces(load,{timeoutMs:Lr,abortSignal:t.signal})])}finally{t.abort()}if(c?.workspaces.length)return c;let l=await s;if(`stopReason`in l)return warning({message:l.message}),i;if(i=await load(),i.workspaces.length)return i;let u=Math.min(Vr,Lr-(Date.now()-n));return u<Br?i:(info({message:`Waiting for Apify to finish connecting your ${a} account...`}),await pollForWorkspaces(load,{timeoutMs:u})??i)}let c=null,offer=async t=>{let n=t.connected?t.addWorkspaceUrl??getAddWorkspaceUrl(e,r):getGitConnectUrl(e,r);n!==c&&(c=n,info({message:`${t.connected?`Give Apify access to a ${a} account`:`Connect your ${a} account to Apify`}: ${n}`}),await wt(n).catch(()=>void 0),info({message:r?.username?`Waiting for authorization to complete in your browser. It connects ${a} to the Apify account ${r.username}.`:`Waiting for authorization to complete in your browser...`}))};return await offer(i),await pollForWorkspaces(load,{timeoutMs:Vr,onState:offer})??i},chooseWorkspace=async(e,t,n)=>{if(t){let n=t.toLowerCase(),r=e.find(({id:e,label:t})=>e.toLowerCase()===n||t.toLowerCase()===n);return r?{workspace:r}:{stopReason:`unknownWorkspace`}}return e.length===1?{workspace:e[0]}:n?{workspace:await Sr({message:`Which account should own the repository?`,choices:e.map(e=>({name:e.label,value:e})),loop:!1})}:{stopReason:`ambiguousWorkspace`}};var CreateRemoteRepoError=class extends Error{stopReason;constructor(e,t){super(e),this.stopReason=t,this.name=`CreateRemoteRepoError`}};const Hr=new Set([`integration-auth-error`,`invalid-git-auth-token`]),withoutUserInfo=e=>{if(!URL.canParse(e))return e;let t=new URL(e);return t.username=``,t.password=``,t.href},createRemoteRepo=async e=>{let{providerId:t,workspace:n,repoName:r,isPrivate:i,templateArchiveUrl:a}=e,s=apiUrl(e,`integrations/git/${t}/create-repo`),c=JSON.stringify({workspace:n,repoName:r,isPrivate:i,templateArchiveUrl:a});cliDebugPrint(`git-source`,`POST`,s,c);let l=await fetch(s,{method:`POST`,headers:{...authHeader(e),"Content-Type":`application/json`},body:c}),u=await l.text();cliDebugPrint(`git-source`,`POST`,s,`->`,l.status,u.slice(0,400));let f=(()=>{try{return JSON.parse(u)}catch{return null}})();if(l.ok&&f?.data)return{...f.data,httpsUrl:withoutUserInfo(f.data.httpsUrl)};let p=f?.error?.type,m=f?.error?.message||`${l.status} ${l.statusText}`;throw p&&Hr.has(p)?new CreateRemoteRepoError(m,`notAuthorized`):p===`invalid-parameter`?new CreateRemoteRepoError(m,`repoNameRejected`):new CreateRemoteRepoError(m,`repoCreateFailed`)},cloneRepo=async(e,t,n)=>{await Ee(`git`,[`clone`,t,e],{env:n?void 0:{GIT_TERMINAL_PROMPT:`0`,GIT_SSH_COMMAND:`ssh -o BatchMode=yes`}})},createGitActor=async({client:e,actorName:t,gitRepoUrl:n})=>e.actors().create({name:t,versions:[{versionNumber:`0.0`,sourceType:fe.GIT_REPO,gitRepoUrl:n}]}),registerDeploymentKey=async({client:e,providerId:t,actorId:n,repoUrl:r})=>{let i=apiUrl({client:e},`integrations/git/${t}/register-deployment-key`),a=JSON.stringify({actorId:n,repoName:r});cliDebugPrint(`git-source`,`POST`,i,a);let s=await fetch(i,{method:`POST`,headers:{...authHeader({client:e}),"Content-Type":`application/json`},body:a}),c=await s.text();if(cliDebugPrint(`git-source`,`POST`,i,`->`,s.status,c.slice(0,400)),s.ok)return;let l=(()=>{try{return JSON.parse(c).error?.message}catch{return null}})();throw Error(l||`${s.status} ${s.statusText}`)},enableAutomaticBuilds=async({client:e,providerId:t,actorId:n})=>{let r=apiUrl({client:e},`actors/${n}/versions/0.0/build-on-push`),i=JSON.stringify({providerId:t,enabled:!0});cliDebugPrint(`git-source`,`PUT`,r,i);let a=await fetch(r,{method:`PUT`,headers:{...authHeader({client:e}),"Content-Type":`application/json`},body:i}),s=await a.text();if(cliDebugPrint(`git-source`,`PUT`,r,`->`,a.status,s.slice(0,400)),a.ok)return;let c=(()=>{try{return JSON.parse(s).error?.message}catch{return null}})();throw Error(c||`${a.status} ${a.statusText}`)},runGitSourceFlow=async({client:e,provider:t,actorDir:n,actorName:r,workspace:i,repoName:a,isPrivate:s,templateArchiveUrl:c,isInteractive:l,account:u,autoBuild:f,customize:p})=>{let m=!1,stopped=(e,t,n={})=>({remoteUrl:null,httpsUrl:null,actorId:null,workspaces:null,scaffolded:m,automaticBuilds:`off`,...n,stopReason:e,error:t instanceof Error?t.message:String(t)}),h;try{h=await ensureUsableIntegration(t,{client:e,isInteractive:l,account:u})}catch(e){return stopped(`lookupFailed`,e)}let{label:g}=zr[t],_=u?.username?`The Apify account ${u.username}`:`Apify`;if(!h.connected)return stopped(`notAuthorized`,Error(`${_} is not authorized to access your ${g} account.`));if(!h.workspaces.length)return stopped(`noWorkspace`,Error(`${_} has no ${g} account to create the repository in.`));let v=h.workspaces.map(({label:e})=>e),y=v.join(`, `),b=await chooseWorkspace(h.workspaces,i,l);if(`stopReason`in b)return stopped(b.stopReason,Error(b.stopReason===`unknownWorkspace`?`"${i}" is not one of your connected accounts (${y}).`:`Several accounts are connected (${y}); pick one with --git-repo <account>/<name>.`),{workspaces:v});let{workspace:x}=b,S;for(;;)try{info({message:`Creating ${s?`private`:`public`} repository ${x.label}/${a} from the template...`}),S=await createRemoteRepo({client:e,providerId:x.providerId,workspace:x.id,repoName:a,isPrivate:s,templateArchiveUrl:c});break}catch(e){if(e instanceof CreateRemoteRepoError&&e.stopReason===`repoNameRejected`&&l){warning({message:e.message}),a=await _n({message:`Choose a different repository name:`,validate:e=>e.trim().length>0||`Enter a repository name.`});continue}return stopped(e instanceof CreateRemoteRepoError?e.stopReason:`repoCreateFailed`,e,{workspaces:v})}let C=null;try{info({message:`Cloning ${S.httpsUrl}...`}),await cloneRepo(n,S.httpsUrl,l),m=!0,await p(n)}catch(e){let t=e.stderr?.trim();C=t?Error(t):e}let w;try{let t=await createGitActor({client:e,actorName:r,gitRepoUrl:S.sshUrl});info({message:`Created Actor ${t.name} on Apify.`}),w=t.id}catch(e){return stopped(`actorCreateFailed`,e,{workspaces:v,remoteUrl:S.sshUrl,httpsUrl:S.httpsUrl})}try{await registerDeploymentKey({client:e,providerId:x.providerId,actorId:w,repoUrl:S.htmlUrl})}catch(e){return stopped(`deploymentKeyFailed`,e,{workspaces:v,remoteUrl:S.sshUrl,httpsUrl:S.httpsUrl,actorId:w})}let T=`off`;if(f)try{await enableAutomaticBuilds({client:e,providerId:x.providerId,actorId:w}),T=`on`,info({message:`Turned on automatic builds.`})}catch(e){T=`failed`,warning({message:`Automatic builds stay off: ${e instanceof Error?e.message:String(e)}`})}else info({message:`Automatic builds stay off, so a push does not rebuild the Actor.`});return C?stopped(`gitSetupFailed`,C,{workspaces:v,remoteUrl:S.sshUrl,httpsUrl:S.httpsUrl,actorId:w,automaticBuilds:T}):{remoteUrl:S.sshUrl,httpsUrl:S.httpsUrl,actorId:w,workspaces:v,stopReason:null,error:null,scaffolded:!0,automaticBuilds:T}},getGitStopUrl=(e,t,n)=>t===`notAuthorized`?getGitConnectUrl(e,n):t===`noWorkspace`?getAddWorkspaceUrl(e,n):null,buildGitSourceNextSteps=({actorName:e,stopReason:t,provider:n,remoteUrl:r,httpsUrl:i,repoName:a,scaffolded:s,actorId:c,account:l})=>{let u=`cd "${e}"`;switch(t){case`lookupFailed`:return[`Re-run with APIFY_CLI_DEBUG=1 to see the failing request`];case`notAuthorized`:return[`Connect your ${zr[n].label} account to Apify: ${getGitConnectUrl(n,l)}`,`then re-run apify create`];case`noWorkspace`:return[`Give Apify access to a ${zr[n].label} account: ${getAddWorkspaceUrl(n,l)}`,`then re-run apify create`];case`unknownWorkspace`:case`ambiguousWorkspace`:return[`Re-run naming the account: --git-repo <account>/${a}`];case`repoNameRejected`:return[`Re-run with a different repository name: --git-repo <account>/<other-name>`,`The name has to be free, and to use only letters, numbers, hyphens and underscores`];case`repoCreateFailed`:return[`Re-run apify create to try again`];case`gitSetupFailed`:return s?[u,`Apply the local configuration by hand: the error above says what failed`]:[`git clone ${i} "${e}"`,`Or clone over SSH, if you have a key for the provider: git clone ${r} "${e}"`,u];case`actorCreateFailed`:return[u,`Create an Actor from ${r} in Apify Console`];case`deploymentKeyFailed`:return[...s?[u]:[`git clone ${i} "${e}"`,u],`Add the Apify deploy key in the Actor's Source settings before building: ${getConsoleUrl()}/actors/${c}`]}},logGitSourceOutcome=(e,t)=>{e.stopReason&&(warning({message:`${e.scaffolded?`Actor scaffolded, but the Git setup did not finish`:e.actorId?`Actor created, but the clone failed`:`The Actor was not created: the Git setup stopped`}: ${e.error}`}),info({message:`Next steps:\n${t.map(e=>` ${e}`).join(`
|
|
148
|
+
`)}`}))};var CreateCommand=class extends ApifyCommand{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 group=`Local Actor Development`;static interactive=!0;static interactiveNote=`Prompts for an Actor name, then guides you through what you want to build, a language, a template, and how the source code is set up when they are not provided. To run non-interactively, pass the name and --template; --source defaults to "apify". Use --use-case and --language to narrow the template list.`;static examples=[{description:`Create a new Actor project interactively, with guided prompts for the name, use case, language, template, and source.`,command:`apify create`},{description:`Narrow the guided template list by use case and language.`,command:`apify create my-actor --use-case web-scraper --language python`},{description:`Create non-interactively with explicit name and template.`,command:`apify create my-actor --template js-crawlee-cheerio`},{description:`Create without installing dependencies (faster; run install yourself later).`,command:`apify create my-actor --template python-start --skip-dependency-install`},{description:`Host the source code on GitHub. Apify creates the repository and builds the Actor from it.`,command:`apify create my-actor --template js-crawlee-cheerio --source github`},{description:`Name the account and the repository to create, instead of being asked.`,command:`apify create my-actor --template js-crawlee-cheerio --source github --git-repo my-org/my-scraper`}];static docsUrl=`https://docs.apify.com/cli/docs/reference#apify-create`;static flags={template:Y.string({char:`t`,description:`Template for the Actor. If not provided, the command will prompt for it. Visit ${Et} to find available template names.`,required:!1}),"use-case":Y.string({char:`u`,description:`Filter templates by use case. Ignored when --template is provided. To see the use cases each template supports, run "apify templates ls".`,choices:Ir,required:!1}),language:Y.string({char:`l`,description:`Filter templates by programming language. Ignored when --template is provided.`,choices:Fr,required:!1}),"skip-dependency-install":Y.boolean({description:`Skip installing Actor dependencies.`,required:!1}),"template-archive-url":Y.string({description:`Actor template archive url. Useful for developing new templates.`,required:!1,hidden:!0}),"omit-optional-deps":Y.boolean({aliases:[`no-optional`],description:`Skip installing optional dependencies.`,required:!1}),"skip-git-init":Y.boolean({description:`Skip initializing a git repository in the Actor directory.`,required:!1}),source:Y.string({description:`Where the Actor source code lives. With "apify", the code stays on your machine and nothing is uploaded. You can still deploy your Actor with "apify push". With a Git provider, Apify creates a private repository from the template on your connected account, clones the repository into the Actor directory, and builds the Actor from it.`,choices:[...Rr],required:!1}),"git-repo":Y.string({description:`Repository to create, as "workspace/name" — a workspace being an account or organization you have given Apify access to. A bare value is read as the name, not the workspace. The name defaults to the Actor name, and the workspace is asked for when you have more than one. List yours with "apify api integrations/git". Only used when --source is a Git provider.`,required:!1}),"auto-build":Y.string({description:`Whether a push to the repository rebuilds the Actor. On by default. Turning it on registers a push webhook on the new repository, which needs admin rights on it. Only used when --source is a Git provider.`,choices:[`on`,`off`],required:!1}),origin:Y.string({description:`Where the command was invoked from. Used for funnel telemetry.`,choices:[`console`,`cli`],default:`cli`,required:!1,hidden:!0})};static args={actorName:Z.string({required:!1,description:`Name of the Actor and its directory.`})};static enableJsonFlag=!0;async run(){let{actorName:t}=this.args,{template:n,useCase:r,language:i,skipDependencyInstall:a,skipGitInit:s,origin:c,json:l,gitRepo:f}=this.flags,{templateArchiveUrl:p}=this.flags,m=!1,h=!n&&!p;if(l&&(!t||h)){let e=[...t?[]:[`the Actor name as an argument`],...h?[`--template <name>`]:[]],n=h?` Run "apify templates ls" to list template names.`:``;throw Error(`--json runs non-interactively. Pass ${e.join(` and `)}.${n}`)}let g=this.flags.source,_=Tt().catch(e=>Error(`Could not fetch template list from server. Cause: ${e?.message}`));t=await ensureValidActorName(t);let v=e.cwd(),x=u(v,t);for(;;){let e=await V(x).catch(()=>null),n=e&&await ke(x).then(e=>e.length>0).catch(()=>!1);if(e?.isDirectory()&&n){let e=`Cannot create new Actor, directory '${t}' already exists. Provide a different name. To create a local Actor environment inside an existing directory, use "apify init".`;if(l)throw Error(e);error({message:e}),t=await ensureValidActorName(),x=u(v,t);continue}e||await z(x,{recursive:!0});break}let S=null,C=null;if(this.telemetryData.create={fromArchiveUrl:!!p,origin:c},!p){let e=await getTemplateDefinition(n,_,{useCase:r,language:i});({archiveUrl:p,messages:S}=e),C=e.id,this.telemetryData.create.templateId=e.id,this.telemetryData.create.templateName=e.name,this.telemetryData.create.templateLanguage=e.category,`skipOptionalDeps`in e&&(m=e.skipOptionalDeps)}this.flags.omitOptionalDeps&&(m=!0);let{isTTY:w}=await useStdin(),T=w&&!le&&!l;g??=T?await promptGitSource():`apify`;let E=isGitProvider(g)?g:null;if(this.telemetryData.create.source=g,E&&s)throw Error(`--source ${g} clones a git repository, so --skip-git-init cannot apply.`);if(!E&&f)throw Error(`--git-repo only applies to a Git source, so add --source github|gitlab|bitbucket or drop it.`);if(!E&&this.flags.autoBuild)throw Error(`--auto-build only applies to a Git source, so add --source github|gitlab|bitbucket or drop it.`);if(E&&this.flags.templateArchiveUrl)throw Error(`--template-archive-url is not supported with --source ${g}.`);let D=E?{provider:E,client:await getLoggedClientOrThrow(),account:toGitAccount(await getLocalUserInfo()),autoBuild:this.flags.autoBuild!==`off`,...parseGitRepoFlag(f,t)}:null,applyLocalConfig=async e=>{let n=getJsonFileContent(u(e,G));await setLocalConfig(Object.assign(n||Qt,{name:t}),e),await setLocalEnv(e),await createPrefilledInputFileFromInputSchema(e)};E||(await downloadAndUnzip({url:p,pathTo:x}),await applyLocalConfig(x),await enhanceReadmeWithLocalSuffix(u(x,`README.md`),_));let O=u(x,`package.json`),k=null;D&&(k=await runGitSourceFlow({provider:D.provider,actorDir:x,actorName:t,workspace:D.workspace,repoName:D.repoName,isPrivate:!0,templateArchiveUrl:p,client:D.client,isInteractive:T,account:D.account,autoBuild:D.autoBuild,customize:applyLocalConfig}));let A=!1;a||await(await useCwdProject({cwd:x})).inspectAsync(async n=>{let r=b(nn);if((n.type===1||n.type===2)&&n.packageManager===`uv`){let e=await Ie(`uv`,{nothrow:!0});if(!e){warning({message:`This Actor uses uv to manage its dependencies, but the uv executable was not found. Install uv (https://docs.astral.sh/uv/getting-started/installation/), then run "uv sync" in the Actor directory.`});return}info({message:`Installing dependencies with "uv sync"...`}),await execWithLog({cmd:e,args:[`sync`],opts:{cwd:x}}),A=!0;return}if(!n.runtime){switch(n.type){case 0:warning({message:`No Node.js detected! Please install Node.js ${r} or higher to be able to run Node.js Actors locally.`});break;case 2:case 1:warning({message:`No Python detected! Please install Python ${on} or higher to be able to run Python Actors locally.`})}return}let{runtime:i}=n;switch(n.type){case 0:{isNodeVersionSupported(i.version)||warning({message:`You are running Node.js version ${i.version}, which is no longer supported. Please upgrade to Node.js version ${r} or later.`}),await updateLocalJson(O,{name:t});let e=[`install`];if(m)switch(i.pmName){case`npm`:y(i.pmVersion,`7.0.0`)?e.push(`--omit=optional`):e.push(`--no-optional`);break;case`bun`:e.push(`--omit=optional`);break;case`deno`:e.push(`--node-modules-dir`)}await execWithLog({cmd:i.pmPath,args:e,opts:{cwd:x},overrideCommand:i.pmName}),A=!0;break}case 1:case 2:{if(!isPythonVersionSupported(i.version)){warning({message:`Python Actors require Python ${on} or higher, but you have Python ${i.version}!`}),warning({message:`Please install Python ${on} or higher to be able to run Python Actors locally.`});return}let t=u(x,`.venv`);info({message:`Python version ${i.version} detected.`}),info({message:`Creating a virtual environment in "${t}" and installing dependencies from "requirements.txt"...`}),e.env.VIRTUAL_ENV||(await execWithLog({cmd:i.executablePath,args:[`-m`,`venv`,`--prompt`,`.`,`.venv`],opts:{cwd:x}}),i=(await usePythonRuntime({cwd:x,force:!0})).unwrap(),n.runtime=i),await execWithLog({cmd:i.executablePath,args:[`-m`,`pip`,`install`,`--no-cache-dir`,`--no-warn-script-location`,`--upgrade`,`pip`,`setuptools`,`wheel`],opts:{cwd:x}}),await execWithLog({cmd:i.executablePath,args:[`-m`,`pip`,`install`,`--no-cache-dir`,`--no-warn-script-location`,`-r`,`requirements.txt`],opts:{cwd:x}}),A=!0;break}}});let j={success:!0},ee=await V(u(v,`.git`)).catch(()=>null),M=await V(u(x,`.git`)).catch(()=>null),N=k!==null&&!k.scaffolded,P=!s&&!ee&&!M&&!N;if(P)try{await execWithLog({cmd:`git`,args:[`init`],opts:{cwd:x}})}catch(e){j={success:!1,error:e}}let te=A?null:await getInstallCommandSuggestion(x),ne=P&&j.success||!!M;k?.stopReason&&(e.exitCode=1);let F=D&&k?.stopReason?buildGitSourceNextSteps({actorName:t,stopReason:k.stopReason,provider:D.provider,remoteUrl:k.remoteUrl,httpsUrl:k.httpsUrl,repoName:D.repoName,scaffolded:k.scaffolded,actorId:k.actorId,account:D.account}):buildNextSteps({actorName:t,dependenciesInstalled:A,installCommandSuggestion:te}),re=!k?.stopReason;l?printJsonToStdout({dir:x,actorJsonPath:u(x,G),template:C,source:g,nextSteps:F,postCreate:S?.postCreate??null,gitRepositoryInitialized:ne,remote:k?.remoteUrl??null,automaticBuilds:k?.automaticBuilds??null,actorId:k?.actorId??null,stopReason:k?.stopReason??null,error:k?.error??null,gitConnectUrl:E?getGitStopUrl(E,k?.stopReason??null,D?.account):null,workspaces:k?.workspaces??null}):re&&(simpleLog({message:``}),success({message:formatCreateSuccessMessage({actorName:t,dependenciesInstalled:A,postCreate:S?.postCreate??null,gitRepositoryInitialized:ne,installCommandSuggestion:te,gitRemote:k?.remoteUrl&&k.actorId?{remoteUrl:k.remoteUrl,actorId:k.actorId,automaticBuilds:k.automaticBuilds}:null})})),P&&!j.success&&(warning({message:`Failed to initialize git repository: ${j.error.message}`}),warning({message:`You can manually run "git init" in the Actor directory if needed.`})),k&&!l&&logGitSourceOutcome(k,F)}};async function tryToGetStorage(e,t,n){let r=await e[n](t).get().catch(()=>void 0);if(r)return{[n]:r,[`${n}Client`]:e[n](r.id)};let i=await getLocalUserInfo(),a=await e[n](`${i.username}/${t}`).get().catch(()=>void 0);return a?{[n]:a,[`${n}Client`]:e[n](a.id)}:null}async function tryToGetDataset(e,t){return tryToGetStorage(e,t,`dataset`)}async function tryToGetKeyValueStore(e,t){return tryToGetStorage(e,t,`keyValueStore`)}var DatasetsCreateCommand=class extends ApifyCommand{static name=`create`;static description=`Creates a new dataset for storing structured data on your account.`;static examples=[{description:`Create an unnamed dataset.`,command:`apify datasets create`},{description:`Create a named dataset.`,command:`apify datasets create my-dataset`}];static docsUrl=`https://docs.apify.com/cli/docs/reference#apify-datasets-create`;static args={datasetName:Z.string({description:`Optional name for the Dataset.`,required:!1})};static enableJsonFlag=!0;async run(){let{datasetName:e}=this.args,n=await getLoggedClientOrThrow();if(e&&await tryToGetDataset(n,e)){error({message:`A Dataset with this name already exists!`});return}let r=await n.datasets().getOrCreate(e);if(this.flags.json){printJsonToStdout(r);return}success({message:`Dataset with ID ${t.yellow(r.id)}${e?` (called ${t.yellow(e)})`:``} was created.`,stdout:!0})}};const Ur={[U.JSON]:`application/json`,[U.JSONL]:`application/jsonl`,[U.CSV]:`text/csv`,[U.HTML]:`text/html`,[U.RSS]:`application/rss+xml`,[U.XML]:`application/xml`,[U.XLSX]:`application/vnd.openxmlformats-officedocument.spreadsheetml.sheet`};var DatasetsGetItems=class extends ApifyCommand{static name=`get-items`;static description=`Retrieves dataset items in specified format (JSON, CSV, etc).`;static examples=[{description:`Print all items from a dataset as JSON.`,command:`apify datasets get-items <datasetId>`},{description:`Export the first 100 items as CSV to a file.`,command:`apify datasets get-items <datasetId> --format csv --limit 100 > items.csv`},{description:`Paginate: skip the first 500 items, return the next 500.`,command:`apify datasets get-items <datasetId> --offset 500 --limit 500`}];static docsUrl=`https://docs.apify.com/cli/docs/reference#apify-datasets-get-items`;static flags={limit:Y.integer({description:`The amount of elements to get from the dataset. By default, it will return all available items.`}),offset:Y.integer({description:`The offset in the dataset where to start getting items.`}),format:Y.string({description:`The format of the returned output. By default, it is set to 'json'.`,choices:Object.keys(Ur),default:U.JSON})};static args={datasetId:Z.string({description:`The ID of the Dataset to export the items for.`,required:!0})};async run(){let{limit:e,offset:t,format:n}=this.flags,{datasetId:r}=this.args,i=await getLoggedClientOrThrow(),a=await this.tryToGetDataset(i,r);if(!a){error({message:`Dataset with ID "${r}" not found.`});return}let{datasetClient:s}=a;process.stdout.write(``);let c=await s.downloadItems(n,{limit:e,offset:t});simpleLog({message:Ur[n]??`application/octet-stream`}),process.stdout.write(c),process.stdout.write(`
|
|
149
149
|
`)}async tryToGetDataset(e,t){let n=await e.dataset(t).get().catch(()=>void 0);if(n)return{dataset:n,datasetClient:e.dataset(n.id)};let r=await getLocalUserInfo(),i=await e.dataset(`${r.username}/${t}`).get().catch(()=>void 0);return i?{dataset:i,datasetClient:e.dataset(i.id)}:null}};function getUserPlanPricing(e){let t=Reflect.get(e,`planPricing`);return t?Reflect.get(t,`chargeableServiceUnitPricesUsd`):null}const Wr=new Q({allColumns:[`Row1`,`Row2`],mandatoryColumns:[`Row1`,`Row2`]});var DatasetsInfoCommand=class extends ApifyCommand{static name=`info`;static description=`Prints information about a specific dataset.`;static examples=[{description:`Show dataset metadata (item count, size, timestamps).`,command:`apify datasets info <datasetId>`}];static docsUrl=`https://docs.apify.com/cli/docs/reference#apify-datasets-info`;static args={storeId:Z.string({description:`The dataset store ID to print information about.`,required:!0})};static enableJsonFlag=!0;async run(){let{storeId:e}=this.args,n=await getLoggedClientOrThrow(),r=await tryToGetDataset(n,e);if(!r){error({message:`Key-value store with ID or name "${e}" not found.`});return}let{dataset:i}=r,[a,s,c]=await Promise.all([n.user(i.userId).get().then(e=>e),i.actId?n.actor(i.actId).get():Promise.resolve(void 0),i.actRunId?n.run(i.actRunId).get():Promise.resolve(void 0)]),l;if(c?.actorTaskId&&(l=await n.task(c.actorTaskId).get().catch(()=>void 0)),this.flags.json){printJsonToStdout({...i,user:a,actor:s||null,run:c||null,task:l||null});return}let u=i.stats?.storageBytes||0,f=i.stats?.readCount||0,p=i.stats?.writeCount||0,m=(i.cleanItemCount||0).toLocaleString(`en-US`),h=(i.itemCount||0).toLocaleString(`en-US`),g=[`${t.bold(f.toLocaleString(`en-US`))} ${t.gray(this.pluralString(f,`read`,`reads`))}`,`${t.bold(p.toLocaleString(`en-US`))} ${t.gray(this.pluralString(p,`write`,`writes`))}`],_=`Items: ${t.bold(m)} ${t.gray(`clean`)} / ${t.bold(h)} ${t.gray(`total`)}\nOperations: ${g.join(` / `)}`;if(a.plan){let e=getUserPlanPricing(a.plan);if(e){let n=e.KEY_VALUE_STORE_TIMED_STORAGE_GBYTE_HOURS*(u/1e3**3),r=n*24*30,i=r>1?`$${r.toFixed(2)}`:`$${n.toFixed(3)}`;_+=`\nStorage size: ${prettyPrintBytes({bytes:u,shortBytes:!0,precision:1})} / ${t.gray(`${i} per month`)}`}}else _+=`\nStorage size: ${prettyPrintBytes({bytes:u,shortBytes:!0,precision:1})}`;let v=[`Dataset ID: ${t.bgGray(i.id)}`,`Name: ${i.name?t.bgGray(i.name):t.bold(t.italic(`Unnamed`))}`,`Created: ${t.bold(K.display(i.createdAt))}`,`Modified: ${t.bold(K.display(i.modifiedAt))}`].join(`
|
|
150
150
|
`),y=t.bold(`—`);i.actRunId&&(y=c?t.bgBlue(c.id):t.italic(t.gray(`Run removed`)));let b=t.bold(`—`);s&&(b=t.blue(s.title||s.name));let x=t.bold(`—`);l&&(x=t.blue(l.title||l.name));let S=[`Run: ${y}`,`Actor: ${b}`,`Task: ${x}`].join(`
|
|
151
151
|
`);Wr.pushRow({Row1:v,Row2:S});let C=Wr.render(2).split(`
|
|
@@ -241,4 +241,4 @@ When no path is provided, validates all schemas found in '${G}':
|
|
|
241
241
|
- Dataset schema (from "storages.dataset")
|
|
242
242
|
- Output schema (from "output")
|
|
243
243
|
- 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 '${G}'.`})};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});if(e){n=!0,info({message:`Validating input schema ${r?`at ${r}`:`embedded in '${G}'`}`});let t=new Nn({strict:!1});gt(t,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 '${G}'`}`}),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 '${G}' exists and defines at least one schema.`);r&&(e.exitCode=5)}};const mi=[ActorIndexCommand,ActorsIndexCommand,AuthIndexCommand,BuildsIndexCommand,DatasetsIndexCommand,KeyValueStoresIndexCommand,MCPIndexCommand,RequestQueuesIndexCommand,RunsIndexCommand,SecretsIndexCommand,TasksIndexCommand,TelemetryIndexCommand,TemplatesIndexCommand,ApiCommand,TopLevelCallCommand,UpgradeCommand,InstallCommand,CreateCommand,EditInputSchemaCommand,InfoCommand,WrapScrapyCommand,InitCommand,LoginCommand,LogoutCommand,TopLevelPullCommand,ToplevelPushCommand,RunCommand,ValidateSchemaCommand,HelpCommand],hi=[ActorSetValueCommand,ActorPushDataCommand,ActorGetValueCommand,ActorGetPublicUrlCommand,ActorGetInputCommand,ActorChargeCommand,ActorCalculateMemoryCommand,ActorGenerateSchemaTypesCommand,HelpCommand,UpgradeCommand,InstallCommand,TelemetryIndexCommand];export{runCLI as i,mi as n,processVersionCheck as r,hi as t};
|
|
244
|
-
//# sourceMappingURL=_register-
|
|
244
|
+
//# sourceMappingURL=_register-CZOJ7yfV.js.map
|