@shopify/cli
Version:
A CLI tool to build for the Shopify platform
2 lines (1 loc) • 2.71 kB
JavaScript
import{a as h}from"./chunk-TQ6HYDVC.js";import{Ba as A}from"./chunk-54CAKCYR.js";import{d as y}from"./chunk-EKXY5COY.js";import{R as x,g as C}from"./chunk-XONFGLJQ.js";import{d as r,g as c}from"./chunk-M56NDIMD.js";import{Gb as f,Ib as s,Ta as g,ma as l}from"./chunk-N5PQPIBF.js";import{e as E,g as u}from"./chunk-VPRTJUIN.js";u();u();var m=E(C(),1);async function T(e,t){let n=e.apiSecretKeys[0]?.secret;if(!n)throw new c("No API secret keys found for app");return x(t,e.apiKey,n)}function v(e){let t;try{t=(0,m.parse)(e)}catch(o){throw o instanceof Error?new r(`Invalid GraphQL syntax: ${o.message}`):o}if(t.definitions.filter(o=>o.kind==="OperationDefinition").length!==1)throw new r("GraphQL document must contain exactly one operation definition. Multiple operations are not supported.")}async function b(e){let{adminSession:t,userSpecifiedVersion:n,minimumDefaultVersion:o}=e;if(n==="unstable")return n;let i=await y(t);if(!n){let p=i.filter(d=>d.supported).map(d=>d.handle);return o&&p.push(o),p.sort().reverse()[0]}let a=i.map(p=>p.handle);if(a.includes(n))return n;let S=s`Invalid API version: ${n}`.value,w=s`Allowed versions: ${a.join(", ")}`.value;throw new r(S,w)}function z(e){let{organization:t,remoteApp:n,storeFqdn:o,version:i}=e,a=[`Organization: ${t.businessName}`,`App: ${n.title}`,`Store: ${o}`];return i&&a.push(`API version: ${i}`),a}function O(e){return(0,m.parse)(e).definitions.find(o=>o.kind==="OperationDefinition")?.operation==="mutation"}function N(e,t){if(O(e)&&t.storeType!=="APP_DEVELOPMENT")throw new r("Mutations can only be executed on dev stores.")}async function P(e){let t=await A({directory:e.path,clientId:e["client-id"],forceRelink:e.reset,userProvidedConfigName:e.config}),n=await h({appContextResult:t,storeFqdn:e.store,forceReselectStore:e.reset,storeTypes:["APP_DEVELOPMENT","DEVELOPMENT","DEVELOPMENT_SUPERSET","PRODUCTION"]});return{appContextResult:t,store:n}}async function K(e){let t;if(e.query!==void 0){if(!e.query.trim())throw new r("The --query flag value is empty. Please provide a valid GraphQL query or mutation.");t=e.query}else if(e["query-file"]){let i=e["query-file"];if(!await g(i))throw new r(s`Query file not found at ${f.path(i)}. Please check the path and try again.`);if(t=await l(i,{encoding:"utf8"}),!t.trim())throw new r(s`Query file at ${f.path(i)} is empty. Please provide a valid GraphQL query or mutation.`)}if(!t)throw new c("Query should have been provided via --query or --query-file flags due to exactlyOne constraint. This indicates the oclif flag validation failed.");v(t);let{appContextResult:n,store:o}=await P(e);return{query:t,appContextResult:n,store:o}}export{T as a,v as b,b as c,z as d,O as e,N as f,P as g,K as h};