import{c as oe,e as ie,f as R,g as se}from"./chunk-DKKBJ4H5.js";import{a as X,c as ee,d as ne,e as te}from"./chunk-5U6MXSNY.js";import{a as Q}from"./chunk-6ZRHK4ON.js";import{a as K}from"./chunk-7XQDZF73.js";import{$ as P,Fa as Z,H as T,K as q,T as I,da as J,g as W}from"./chunk-UZ7U322K.js";import{a as H}from"./chunk-5JCREGSD.js";import{b as G}from"./chunk-Q6LCSRIW.js";import{A as M,D as j,I as S,t as U,u as Y,v as A}from"./chunk-E24W34C4.js";import{d as V}from"./chunk-3QVXHF6I.js";import{d as h,f as z}from"./chunk-ELIH6GCC.js";import{Ca as B,Gb as C,L as $,Mb as k,Rb as D,wa as _}from"./chunk-EYDNSYYE.js";import{d as E,i as N}from"./chunk-773TIA5M.js";import{r as fe}from"./chunk-T6CC5WUU.js";import{e as me,g}from"./chunk-VKWPEFWQ.js";g();g();g();async function ae(e){let n,t;e.bundlePath&&(n=await te(e.developerPlatformClient,{id:e.apiKey,apiKey:e.apiKey,organizationId:e.organizationId}),await ne(n,e.bundlePath));let o={appManifest:e.appManifest,appId:e.appId,apiKey:e.apiKey,name:e.name,organizationId:e.organizationId,skipPublish:!e.release,message:e.message,versionTag:e.version,commitReference:e.commitReference};n&&(o.bundleUrl=n),e.appModules.length>0&&(o.appModules=e.appModules);let i=await e.developerPlatformClient.deploy(o);if(!i.appDeploy.appVersion){let a=ge(i.appDeploy.userErrors??[],e.extensionIds,e.appModules,{version:e.version});throw new h({bold:"Version couldn't be created."},null,[],a)}return i.appDeploy.userErrors?.length>0&&(t=i.appDeploy.userErrors.map(a=>a.message).join(", ")),{validationErrors:i.appDeploy.appVersion.appModuleVersions.filter(a=>a.validationErrors.length>0).map(a=>({uuid:a.registrationUuid,errors:a.validationErrors})),versionTag:i.appDeploy.appVersion.versionTag,location:i.appDeploy.appVersion.location,message:i.appDeploy.appVersion.message,deployError:t}}var x=`
Validation errors`,F=`
`;function ge(e,n,t,o={}){let i=p=>p.details?.some(b=>b.extension_id)??!1,s=(p,b)=>{let v=p.details?.find(O=>typeof O.extension_id<"u")?.extension_id??"";return Object.values(b).includes(v.toString())},a=p=>{let b=p.on?p.on[0]:void 0;return t.some(v=>v.uid===b?.user_identifier)},[r,d]=I(e,p=>a(p)),[m,c]=I(d,p=>i(p)),[f,l]=I(m,p=>s(p,n));return[...he(c,{version:o.version}),...ye(f,n),...be(l),...we(r,t)]}function he(e,n={}){return e.length>0?e.filter(t=>t.field&&t.field.includes("version_tag")&&t.message==="has already been taken").length>0&&n.version?[{body:["An app version with the name",{userInput:n.version},"already exists. Deploy again with a different version name."]}]:e.length===1?[{body:e[0]?.message??""}]:[{body:{list:{items:e.map(t=>t.message)}}}]:[]}function ye(e,n){return e.reduce((t,o)=>{let i=(o.field??["unknown"]).join(".").replace("extension_points","extensions.targeting"),s=i==="base"?o.message:`${i}: ${o.message}`,a=o.details.find(l=>typeof l.extension_title<"u")?.extension_title,r=o.details.find(l=>typeof l.specification_identifier<"u")?.specification_identifier,d=o.details.find(l=>typeof l.extension_id<"u")?.extension_id?.toString(),c=Object.keys(n).find(l=>n[l]===d)??a;r==="webhook_subscription"&&(c="Webhook Subscription");let f=t.find(l=>l.title===c);if(f){let l=f.body,u=o.category==="invalid"?l.find(p=>p.list.title===x):l.find(p=>p.list.title===F);u?u.list.items.includes(s)||u.list.items.push(s):l.push({list:{title:o.category==="invalid"?x:F,items:[s]}})}else t.push({title:c,body:[{list:{title:o.category==="invalid"?x:F,items:[s]}}]});return t.forEach(l=>{l.body.sort((u,p)=>u.list.title===x?1:p.list.title===x?-1:0)}),t},[])}function we(e,n){return e.reduce((t,o)=>{let s=(o.on?o.on[0]:void 0)?.user_identifier,a=n.find(l=>l.uid===s),r=s?`Extension with uid: ${s}`:"Unknown Extension",d=a?.handle??r,c=`${(o.field??["unknown"]).join(".")}: ${o.message}`,f=t.find(l=>l.title===d);if(f){let u=f.body.find(p=>p.list.title===x);u&&(u.list.items.includes(c)||u.list.items.push(c))}else t.push({title:d,body:[{list:{title:x,items:[c]}}]});return t},[])}function be(e){return e.reduce((n,t)=>{let o=t.details.find(s=>typeof s.extension_title<"u")?.extension_title,i=n.find(s=>s.title===o);return i?i.errorCount+=1:n.push({title:o,errorCount:1}),n},[]).map(n=>({title:n.title,body:`
${n.errorCount} error${n.errorCount>1?"s":""} found in your extensions. Fix these issues and try deploying again.`}))}g();async function re(e){let n=E(e.app.directory,".shopify","deploy-bundle");await B(n,{force:!0}),await _(n),await X(e.appManifest,n),e.skipBuild||await W(e.app);let t=e.app.allExtensions.map(i=>({prefix:i.localIdentifier,action:async(s,a,r)=>{let d=e.isDevDashboardApp?void 0:e.identifiers?.extensions[i.localIdentifier];await i.buildForBundle({stderr:a,stdout:s,signal:r,app:e.app,environment:"production",skipBuild:e.skipBuild},n,d)}}));if(await U({processes:t,showTimestamps:!1}),e.app.allExtensions.some(i=>i.hasDeploySteps))return await ee(n,e.bundlePath),e.bundlePath}async function ve(e){let{app:n,remoteApp:t,developerPlatformClient:o,force:i,extensions:s}=e;if(i||!S())return n;let a=[`App includes legacy extensions that will be deprecated soon:
`,s.map(d=>`  - ${d.title}`).join(`
`),`

Run `,{command:"shopify app import-extensions"},"to add legacy extensions now?"];return await M({message:a,confirmationMessage:"Yes, add legacy extensions and deploy",cancellationMessage:"No, skip for now"})?(await R({app:n,remoteApp:t,developerPlatformClient:o,extensions:s}),T(n)):n}async function xe(e){let{app:n,remoteApp:t,developerPlatformClient:o,force:i,extensions:s}=e,a=[`App can't be deployed until Partner Dashboard managed extensions are added to your version or removed from your app:
`,s.map(c=>`  - ${c.title}`).join(`
`)],r=[`

Run `,{command:"shopify app import-extensions"},"to add legacy extensions."];if(i||!S())throw new h(a,r);let d=[`

Run `,{command:"shopify app import-extensions"}," to add legacy extensions now?"];if(await M({message:[...a,...d],confirmationMessage:"Yes, add legacy extensions and deploy",cancellationMessage:"No, don't add legacy extensions"}))return await R({app:n,remoteApp:t,developerPlatformClient:o,extensions:s}),T(n);throw new z}async function Ee(e){let{app:n,remoteApp:t,developerPlatformClient:o}=e,i=await se({developerPlatformClient:o,apiKey:t.apiKey,organizationId:t.organizationId,extensionTypes:oe,onlyDashboardManaged:!0}),s=ie(e.app,i);return s.length===0?n:o.supportsDashboardManagedExtensions?ve({...e,extensions:s}):xe({...e,extensions:s})}async function le(e){let{remoteApp:n,developerPlatformClient:t,noRelease:o,force:i,allowUpdates:s,allowDeletes:a}=e,r=await Ee({app:e.app,remoteApp:n,developerPlatformClient:t,force:i}),{identifiers:d,didMigrateExtensionsToDevDash:m}=await J({...e,app:r,developerPlatformClient:t,allowUpdates:s,allowDeletes:a}),c=!o,f=n.apiKey;D(),c?k(`Releasing a new app version as part of ${n.title}`):k(`Creating a new app version as part of ${n.title}`),D();let l;try{let u=E(e.app.directory,".shopify",`deploy-bundle.${t.bundleFormat}`);await _(N(u));let p=await r.manifest(d),b=await re({app:r,appManifest:p,bundlePath:u,identifiers:d,skipBuild:e.skipBuild,isDevDashboardApp:t.supportsAtomicDeployments}),v;c?v="Releasing an app version":v="Creating an app version",await j([{title:"Running validation",task:async()=>{await r.preDeployValidation()}},{title:v,task:async()=>{let ce=await Promise.all(r.allExtensions.flatMap(ue=>ue.bundleConfig({identifiers:d,developerPlatformClient:t,apiKey:f,appConfiguration:r.configuration})));l=await ae({appManifest:p,appId:n.id,apiKey:f,name:r.name,organizationId:n.organizationId,bundlePath:b,appModules:$(ce),release:c,developerPlatformClient:t,extensionIds:d.extensionIds,message:e.message,version:e.version,commitReference:e.commitReference}),await P({app:r,identifiers:d,command:"deploy",developerPlatformClient:t})}}]),await _e({app:r,project:e.project,release:c,uploadExtensionsBundleResult:l,didMigrateExtensionsToDevDash:m})}catch(u){throw await P({app:r,identifiers:d,command:"deploy",developerPlatformClient:t}),u}return{app:r}}async function _e({app:e,project:n,release:t,uploadExtensionsBundleResult:o,didMigrateExtensionsToDevDash:i}){let s=[{link:{label:o.versionTag??"version",url:o.location}},o.message?`
${o.message}`:""],a=[];if(i){let r=await q(e.directory),d=Object.values(r).filter(c=>c!==r[e.configuration.client_id]),m=[];d.length>0&&m.push("\u2022 Map extension IDs to other copies of your app by running",{command:C(n.packageManager,"shopify app deploy")},"for: ",{list:{items:d}}),m.push("\u2022 Commit to source control to ensure your extension IDs aren't regenerated on the next deploy."),a=[{title:"Next steps",body:m},{title:"Reference",body:["\u2022 ",{link:{label:"Migrating from the Partner Dashboard",url:"https://shopify.dev/docs/apps/build/dev-dashboard/migrate-from-partners"}}]}]}return t?o.deployError?Y({headline:"New version created, but not released.",body:[...s,`

${o.deployError}`],customSections:a}):A({headline:"New version released to users.",body:s,customSections:a}):A({headline:"New version created.",body:s,customSections:a,nextSteps:[["Run",{command:C(n.packageManager,"shopify app release",`--version=${o.versionTag}`)},"to release this version to users."]]})}g();function de(e){if(typeof e>"u")return;let n=["Invalid version name:",{userInput:e}],t=100;if(e.length>t)throw new h(n,`Version name must be ${t} characters or less.`);let o=[".",".."];if(o.find(s=>e===s))throw new h(n,`Version name may not be any of: ${o.map(s=>`'${s}'`).join(" , ")}`);let i=/^[a-zA-Z0-9.\-_]+$/;if(!e.match(i))throw new h(n,["Version name can only contain alphanumeric characters, periods, hyphens, and underscores"])}g();function pe(e){if(typeof e>"u")return;let n=["Invalid message:",{userInput:e}],t=200;if(e.length>t)throw new h(n,`Message name must be ${t} characters or less.`)}var y=me(fe(),1);var L,w=class extends Q{async run(){let{flags:n}=await this.parse(L);await H.addPublicMetadata(()=>({cmd_deploy_flag_message_used:!!n.message,cmd_deploy_flag_version_used:!!n.version,cmd_deploy_flag_source_url_used:!!n["source-control-url"]})),de(n.version),pe(n.message);let t=n["client-id"];await V(()=>({cmd_app_reset_used:n.reset}));let o=n["no-release"],i=[];o||n["allow-updates"]||n["allow-deletes"]||i.push("allow-updates"),this.failMissingNonTTYFlags(n,i);let{app:a,project:r,remoteApp:d,developerPlatformClient:m,organization:c}=await Z({directory:n.path,clientId:t,forceRelink:n.reset,userProvidedConfigName:n.config}),f=o||n["allow-updates"],l=o||n["allow-deletes"];return{app:(await le({app:a,project:r,remoteApp:d,organization:c,developerPlatformClient:m,reset:n.reset,force:o,allowUpdates:f,allowDeletes:l,noRelease:n["no-release"],message:n.message,version:n.version,commitReference:n["source-control-url"],skipBuild:n["no-build"]})).app}}};L=w;w.summary="Deploy your Shopify app.";w.descriptionWithMarkdown=`[Builds the app](https://shopify.dev/docs/api/shopify-cli/app/app-build), then deploys your app configuration and extensions.

  This command creates an app version, which is a snapshot of your app configuration and all extensions. This version is then released to users.

  This command doesn't deploy your [web app](https://shopify.dev/docs/apps/tools/cli/structure#web-components). You need to [deploy your web app](https://shopify.dev/docs/apps/deployment/web) to your own hosting solution.
  `;w.description=L.descriptionWithoutMarkdown();w.flags={...G,...K,"allow-updates":y.Flags.boolean({hidden:!1,description:"Allows adding and updating extensions and configuration without requiring user confirmation. Recommended option for CI/CD environments.",env:"SHOPIFY_FLAG_ALLOW_UPDATES"}),"allow-deletes":y.Flags.boolean({hidden:!1,description:"Allows removing extensions and configuration without requiring user confirmation. For CI/CD environments, the recommended flag is --allow-updates.",env:"SHOPIFY_FLAG_ALLOW_DELETES"}),"no-release":y.Flags.boolean({hidden:!1,description:"Creates a version but doesn't release it - it's not made available to merchants. With this flag, a user confirmation is not required.",env:"SHOPIFY_FLAG_NO_RELEASE",default:!1,exclusive:["allow-updates","allow-deletes"]}),"no-build":y.Flags.boolean({description:"Use with caution: Skips building any elements of the app that require building. You should ensure your app has been prepared in advance, such as by running `shopify app build` or by caching build artifacts.",env:"SHOPIFY_FLAG_NO_BUILD",default:!1}),message:y.Flags.string({hidden:!1,description:"Optional message that will be associated with this version. This is for internal use only and won't be available externally.",env:"SHOPIFY_FLAG_MESSAGE"}),version:y.Flags.string({hidden:!1,description:"Optional version tag that will be associated with this app version. If not provided, an auto-generated identifier will be generated for this app version.",env:"SHOPIFY_FLAG_VERSION"}),"source-control-url":y.Flags.string({hidden:!1,description:"URL associated with the new app version.",env:"SHOPIFY_FLAG_SOURCE_CONTROL_URL"})};var fn=w;export{fn as a};
