@shopify/cli
Version:
A CLI tool to build for the Shopify platform
2 lines (1 loc) • 2 kB
JavaScript
import{n as a}from"./chunk-XONFGLJQ.js";import{d as i}from"./chunk-M56NDIMD.js";import{g as s}from"./chunk-VPRTJUIN.js";s();var e={LOCALHOST:"localhost",HTTP:"http",PUBSUB:"google-pub-sub",EVENTBRIDGE:"event-bridge"},g={LOCALHOST:new RegExp("^http:","i"),HTTP:new RegExp("^https:","i"),PUBSUB:new RegExp("^pubsub:"),EVENTBRIDGE:new RegExp("^arn:aws:events:")};function p(t,n){let r=T(t);return r===e.LOCALHOST&&n===e.HTTP?!0:r===n}function f(t){return g.LOCALHOST.test(t)?new URL(t.toLowerCase()).hostname==="localhost":!1}function w(t,n){if(!p(t,n))throw new i(`Can't deliver your webhook payload to this address using '${n}'`,"Use a valid URL for address",l(n));let r=n;return f(t)&&(r=e.LOCALHOST),[t.trim(),r]}function l(t){return t===e.HTTP?["For remote HTTP testing, use a URL that starts with https://","For local HTTP testing, use http://localhost:{port}/{url-path}"]:t===e.PUBSUB?["For Google Pub/Sub, use pubsub://{project-id}:{topic-id}"]:t===e.EVENTBRIDGE?["For Amazon EventBridge, use an Amazon Resource Name (ARN) starting with arn:aws:events:"]:[]}function d(t,n){if(n.includes(t))return t;throw new i(`Api Version '${t}' does not exist`,`Allowed values: ${n.join(", ")}`,["Try again with a valid api-version value"])}function E(t,n,r){if(r.length===0)throw new i(`No topics found for '${n}'`);let o=c(t.trim(),r);if(o===void 0)throw new i(`Topic '${t}' does not exist for ApiVersion '${n}'`,`Allowed values: ${r.join(", ")}`,["Try again with a valid api-version - topic pair"]);return o}function c(t,n){return n.includes(t)?t:n.find(r=>r.toUpperCase().replace("/","_")===t)}function T(t){if(t){if(t.startsWith("pubsub:"))return e.PUBSUB;if(t.startsWith("arn:aws:events:"))return e.EVENTBRIDGE;if(f(t))return e.LOCALHOST;if(g.HTTP.test(t))return e.HTTP}}s();async function H(t,n,r){let o={method:"POST",body:n,headers:{"Content-Type":"application/json",...JSON.parse(r)}},u=await a(t,o);return u.status>=200&&u.status<300}export{H as a,e as b,p as c,w as d,d as e,E as f,T as g};