@shopify/cli
Version:
A CLI tool to build for the Shopify platform
26 lines (20 loc) • 8.12 kB
JavaScript
import{a as k,b as i,c as E,d as C,e as L,f as F,g as M}from"../../../../chunk-FKMC5OFF.js";import{a as S}from"../../../../chunk-JCL2RRU6.js";import{a as P}from"../../../../chunk-AGNMOFJS.js";import{Ba as w,ca as A}from"../../../../chunk-54CAKCYR.js";import{H as b,I as T,J as I}from"../../../../chunk-7ESSIN27.js";import"../../../../chunk-GZS44BUW.js";import"../../../../chunk-K2WUCOQJ.js";import"../../../../chunk-7QIOUDCX.js";import"../../../../chunk-7MUKLZOL.js";import"../../../../chunk-VBUZWRUL.js";import"../../../../chunk-DCPBRWVC.js";import"../../../../chunk-KR6QDE7D.js";import"../../../../chunk-UXVZ2P63.js";import"../../../../chunk-QSTEVZFQ.js";import"../../../../chunk-5Y7GIF2W.js";import"../../../../chunk-EKXY5COY.js";import"../../../../chunk-4DCQNGUV.js";import"../../../../chunk-QBSKKQBN.js";import"../../../../chunk-FQWB2F75.js";import"../../../../chunk-XONFGLJQ.js";import"../../../../chunk-4LNCYIS3.js";import"../../../../chunk-L2MGAEV3.js";import"../../../../chunk-PRKBO42R.js";import"../../../../chunk-ZSBA6VIC.js";import"../../../../chunk-F2QU6WWX.js";import"../../../../chunk-XULPJ6UG.js";import"../../../../chunk-3TNEIDOD.js";import"../../../../chunk-MHWV5RQV.js";import"../../../../chunk-XOTA6JTZ.js";import"../../../../chunk-MOA33ZFO.js";import"../../../../chunk-JUVAGMIH.js";import{B as f,F as y,z as l}from"../../../../chunk-6G6TMKXF.js";import"../../../../chunk-P6XE4MH5.js";import"../../../../chunk-KLMDWDT2.js";import"../../../../chunk-5CH3B62S.js";import"../../../../chunk-QUTQDXSL.js";import"../../../../chunk-WSDN25F5.js";import"../../../../chunk-M56NDIMD.js";import"../../../../chunk-PD5ZHJWI.js";import{r as z}from"../../../../chunk-LDGAHMS7.js";import"../../../../chunk-ZR76GGZ6.js";import"../../../../chunk-EENHXSWU.js";import"../../../../chunk-FUOIGXI4.js";import"../../../../chunk-6M3ZYNGO.js";import"../../../../chunk-QYR5VPQA.js";import"../../../../chunk-OBEWZXOQ.js";import{Ob as c,Rb as m,Tb as v}from"../../../../chunk-N5PQPIBF.js";import"../../../../chunk-CERXUPGC.js";import"../../../../chunk-T4M5CWAO.js";import"../../../../chunk-PRVQAHWI.js";import"../../../../chunk-YTNDFQJT.js";import"../../../../chunk-ULQG3XQS.js";import{j as u}from"../../../../chunk-IU2ZQ6TE.js";import"../../../../chunk-PIBY5DDZ.js";import{e as Y,g as s}from"../../../../chunk-VPRTJUIN.js";s();s();s();s();async function O(e){let t=e.map(o=>({label:o,value:o}));return await f({message:"Webhook Topic",choices:t})}async function V(e){return l({message:"Webhook ApiVersion",choices:e.map(t=>({label:t,value:t}))})}async function D(){return l({message:"Delivery method",choices:[{label:"HTTP",value:i.HTTP},{label:"Google Pub/Sub",value:i.PUBSUB},{label:"Amazon EventBridge",value:i.EVENTBRIDGE}]})}async function W(e){return(await y({message:"Address for delivery",validate:r=>{let o=r.trim();if(o.length===0)return"Address can't be empty";if(!E(o,e))return`Invalid address.
${d(e)}`}})).trim()}function N(e){return e===i.HTTP?["For remote HTTP testing, use a URL that starts with https://","For local HTTP testing, use http://localhost:{port}/{url-path}"]:e===i.PUBSUB?["For Google Pub/Sub, use pubsub://{project-id}:{topic-id}"]:e===i.EVENTBRIDGE?["For Amazon EventBridge, use an Amazon Resource Name (ARN) starting with arn:aws:events:"]:[]}function d(e){return N(e).map(t=>` \xB7 ${v(t)}`).join(`
`)}async function H(e,t){let{clientSecret:r,clientId:o,remoteApp:n,app:p}=e;return r&&(o||t!==i.EVENTBRIDGE)?{clientSecret:r,apiKey:o}:(A({appName:n.title,configFile:u(p.configPath)}),{clientSecret:n.apiSecretKeys.find(h=>h.secret).secret,apiKey:n.apiKey})}async function _(e,t,r){let o=await T(e,r);return t?L(t,o):V(o)}async function R(e,t,r,o){let n=await I(e,t,o);return r?F(r,t,n):O(n)}async function x(e,t){let r=e??M(t)??await D(),o=t??await W(r);return C(o,r)}async function B(e){let t=await G(e);await U(t)}async function G(e){let t=await _(e.developerPlatformClient,e.apiVersion,e.organizationId),r=await R(e.developerPlatformClient,t,e.topic,e.organizationId),[o,n]=await x(e.deliveryMethod,e.address),p=await H(e,n);return{topic:r,apiVersion:t,deliveryMethod:n,address:o,apiKey:p.apiKey,clientSecret:p.clientSecret,developerPlatformClient:e.developerPlatformClient,organizationId:e.organizationId}}async function U(e){let t={topic:e.topic,api_version:e.apiVersion,address:e.address,delivery_method:e.deliveryMethod,shared_secret:e.clientSecret,api_key:e.apiKey},r=await b(e.developerPlatformClient,t,e.organizationId);if(!r.success){m(`Request errors:
${q(r.userErrors)}`);return}if(e.deliveryMethod===i.LOCALHOST){if(await k(e.address,r.samplePayload,r.headers)){c("Localhost delivery sucessful");return}m("Localhost delivery failed");return}r.samplePayload===JSON.stringify({})&&c("Webhook has been enqueued for delivery")}function q(e){try{return e.map(t=>JSON.parse(t.message).map(r=>` \xB7 ${r}`).join(`
`)).join(`
`)}catch{return JSON.stringify(e)}}var a=Y(z(),1),g=class e extends S{static{this.summary="Trigger delivery of a sample webhook topic payload to a designated address."}static{this.descriptionWithMarkdown=`
Triggers the delivery of a sample Admin API event topic payload to a designated address.
You should use this command to experiment with webhooks, to initially test your webhook configuration, or for unit testing. However, to test your webhook configuration from end to end, you should always trigger webhooks by performing the related action in Shopify.
Because most webhook deliveries use remote endpoints, you can trigger the command from any directory where you can use Shopify CLI, and send the webhook to any of the supported endpoint types. For example, you can run the command from your app's local directory, but send the webhook to a staging environment endpoint.
To learn more about using webhooks in a Shopify app, refer to [Webhooks overview](https://shopify.dev/docs/apps/webhooks).
### Limitations
- Webhooks triggered using this method always have the same payload, so they can't be used to test scenarios that differ based on the payload contents.
- Webhooks triggered using this method aren't retried when they fail.
- Trigger requests are rate-limited using the [Partner API rate limit](https://shopify.dev/docs/api/partner#rate_limits).
- You can't use this method to validate your API webhook subscriptions.
`}static{this.description=this.descriptionWithoutMarkdown()}static{this.flags={...P,help:a.Flags.help({required:!1,hidden:!1,env:"SHOPIFY_FLAG_HELP",description:"This help. When you run the trigger command the CLI will prompt you for any information that isn't passed using flags."}),topic:a.Flags.string({required:!1,hidden:!1,env:"SHOPIFY_FLAG_TOPIC",description:"The requested webhook topic."}),"api-version":a.Flags.string({required:!1,hidden:!1,env:"SHOPIFY_FLAG_API_VERSION",description:"The API Version of the webhook topic."}),"delivery-method":a.Flags.string({required:!1,hidden:!1,options:[i.HTTP,i.PUBSUB,i.EVENTBRIDGE],env:"SHOPIFY_FLAG_DELIVERY_METHOD",description:"Method chosen to deliver the topic payload. If not passed, it's inferred from the address."}),"client-secret":a.Flags.string({required:!1,hidden:!1,env:"SHOPIFY_FLAG_CLIENT_SECRET",description:"Your app's client secret. This secret allows us to return the X-Shopify-Hmac-SHA256 header that lets you validate the origin of the response that you receive."}),address:a.Flags.string({required:!1,hidden:!1,env:"SHOPIFY_FLAG_ADDRESS",description:`The URL where the webhook payload should be sent.
You will need a different address type for each delivery-method:
${d(i.HTTP)}
${d(i.PUBSUB)}
${d(i.EVENTBRIDGE)}`})}}async run(){let{flags:t}=await this.parse(e),r=await w({directory:t.path,clientId:t["client-id"],forceRelink:t.reset,userProvidedConfigName:t.config}),o={...r,topic:t.topic,apiVersion:t["api-version"],deliveryMethod:t["delivery-method"],address:t.address,clientId:t["client-id"],clientSecret:t["client-secret"],path:t.path,config:t.config,organizationId:r.organization.id};return await B(o),{app:r.app}}};export{g as default};