https://stila.co.uk/cdn/shopifycloud/checkout-web/assets/c1/extensibility-browser-engine.DyY02SX8.js
1import{r as ce,s as de,c as W,i as D,a as le}from"./hooks-useReplaceShopPayInHistory.DPpLejwu.js";import{dW as he,cJ as fe,dX as pe,bN as Y,dY as X,dZ as G,d_ as ue,d$ as ye,e0 as xe}from"./addresses-is-address-empty.Bn2lNY_L.js";import{E as be}from"./utilities-extension-execution-errors.Bov3aYbn.js";import{e as g,S as Z,m as J}from"./performance-index.mu6MOGR9.js";import{E as te,c as we,a as me,r as ge}from"./extensions-rpc.BMPl-VrM.js";import{r as ke,a3 as H,a4 as Se,R as Ae,a5 as ee,a6 as Ee}from"./esnext-vendor.B9Da21W6.js";import{s as Pe}from"./context-browser.DZZzP-lc.js";import"./app.DbSrjjlA.js";import"./amazon-pay-useAmazonPayPaymentLine.Ju006AId.js";import"./shared-buyer-consent.B_gDyRCR.js";import"./proposal-delegated-payment-instrument.Gc2rhfd3.js";import"./shared-shop-theme.DIHIQUEd.js";import"./consent-manager-shared.DROIEFP2.js";import"./shared-receipt-mapper-load-recovery.Ci5IIc7r.js";import"./shared-receipt-eager-mappers.BEm77m4Q.js";import"./shared-report-graphql-error.0sJ2-gTk.js";import"./shop-pay-normalizeBuyerDetails.CCnGCeBZ.js";import"./helpers-derivations.Dug6X2_v.js";import"./redemption-promotions.DicFJEgz.js";import"./cvv-cvvBridge.B-VIACTq.js";import"./graphql-PaymentSessionMutation.CAXCwUvV.js";async function _e(r){const{scriptUrl:e}=r;try{g.markStarted("partner-js-fetch",{extension:r,instanceId:null,type:"extension"});const t=await fetch(e);if(!t.ok)throw new Error(`Failed to fetch extension asset, received http status ${t.status}`);const n=await t.text();return g.markFinished("partner-js-fetch",{extension:r,instanceId:null,type:"extension",transferredBundleSize:Number(t.headers.get("content-length")),bundleSize:n.length}),{scriptBody:n,scriptUrl:e,extensionId:r.id}}catch(t){const n=t instanceof Error&&typeof t.message=="string"&&t.message.length>0?t.message:"Failed to fetch extension asset";throw new he(n,{cause:t})}}function se(r){if(typeof r=="function"||r instanceof AbortSignal)return;if(typeof r!="object"||r==null)return r;const e={};for(const t in r)e[t]=se(r[t]);return e}const Te=/^\/api\/.+\/graphql\.json$/,Ie=/^(\/\/)?(\/)?storefront\/api\/(.+\/)?graphql\.json$/;function Re(r,e,t){const n=new URL(r),d=new URL(e),a=new URL(`https://${t}`),l=Te.test(n.pathname)&&(n.host===d.host||n.host===a.host);return Ie.test(n.pathname)||l}async function Fe(){throw new te(`permission to access the storefront API must be specified under [capabilities] with flag "api_access = true"; this can be done within your extension's configuration. View the docs for more information: 2 3https://shopify.dev/docs/api/checkout-ui-extensions/configuration#api-access`)}async function Ue(){throw new te(`invalid request URL for storefront API. View the docs for more information: 4 5https://shopify.dev/docs/api/storefront#endpoints`)}function ve({appId:r,extensionType:e,storefrontTokens:t,storefrontUrl:n,myshopifyDomain:d,allowApiAccess:a,apiVersion:l}){async function y(f){const m=ce(f.url,{storefront:de(n,l)});let _;try{_=new Request(m,f)}catch(A){throw new fe(`Invalid API request: ${A}`)}if(!Re(_.url,n,d))return Ue();if(a){const A=await t.get(r,e,"apiFetch");A&&_.headers.set("Shopify-Storefront-Extension-Token",A);let E;try{E=await fetch(_)}catch(v){throw v instanceof TypeError&&v.message.includes("Failed to fetch")?new pe("Failed to query Storefront API",{cause:v}):v}const M=await E.text();return{...se(E),headers:E.headers?Array.from(E.headers.entries()):[],body:M}}return Fe()}return y}const Me=2,Le=.5;async function Ce(r,e){const{observability:t}=e;let n="",d=0;g.markStarted(Z,{type:"sandbox-fetch"});try{const{response:a,text:l}=await ke(async()=>{const y=d>0?{cache:"reload"}:{},f=await fetch(r,y);if(!f.ok)throw new Y(`Failed to fetch sandbox polyfills: ${f.status}`);const m=await f.text();if(n=m,!m.slice(-256).includes("SANDBOX_EOF"))throw d++,t.leaveErrorBreadcrumb("truncated_sandbox_polyfill_fetch",{scriptUrl:r,httpStatus:f.status,contentLengthHeader:f.headers.get("content-length"),scriptBodyLength:m.length,scriptEnd:m.slice(-50)},"error"),new X("Polyfill script does not have expected end of file marker, likely truncated");return d>0&&t.log("successful_retry_truncated_sandbox_polyfill_fetch","Successful retry of truncated sandbox polyfill fetch",{scriptUrl:r,truncatedPolyfillCounter:d}),{response:f,text:m}},{maxAttempts:Me,initialRetryDelay:Le});return g.markFinished(Z,{type:"sandbox-fetch",transferredBundleSize:Number(a.headers.get("content-length")),bundleSize:l.length}),l}catch(a){if(a instanceof X&&n.length>0)return n;throw a instanceof Y?a:new Y(a instanceof Error&&a.message.length>0?a.message:"Failed to fetch sandbox polyfills",{cause:a})}}const Ne="/cdn/shopifycloud/checkout-web/assets/c1/polyfills-entry-legacy.D3EVUnMj.worker.js",Be="/cdn/shopifycloud/checkout-web/assets/c1/polyfills-entry-modern.DCV3miiE.worker.js",Oe="/cdn/shopifycloud/checkout-web/assets/c1/sandbox.BHWel2fs.worker.js",je="/cdn/shopifycloud/checkout-web/assets/c1/sandbox-2023-04.ZwRa-_pA.worker.js",De="/cdn/shopifycloud/checkout-web/assets/c1/sandbox-2025-07.D1aPqhNY.worker.js";new Proxy({},{get(r,e){return Promise.reject(new Error(`Called ${String(e)} on dummyWorker. Methods are not executable in dummyWorker.`))}});const $e=H(Oe),qe=H(De),Ke=H(je),ze=Ne,Qe=Be;function We(r){"signal"in r&&Object.assign(r,{signal:Ye(r.signal)}
5)}function Ye(r){const e=new Set;return r.aborted?{aborted:!0}:(r.addEventListener("abort",()=>{for(const t of e)t(r.aborted),Se(t);e.clear()},{once:!0}),{aborted:!1,start(t){r.aborted?t(!0):(Ae(t),e.add(t))}})}const He=200;function Ve(r,e){const n=!r.assets.isBaselineBrowser?Qe:ze,d=we({extensionsPublicPath:r.assets.extensionsBase,isPostPurchase:!1,observability:e.observability,getPolyfills:()=>Ce(ge(n,r.assets.extensionsBase),{observability:e.observability}),appSandboxPermissions:e.appSandboxPermissions}),a=new Map,l=new Map,y=new Set,f=[],m=[];let _=!1;function O(){_=!0;const o=m.splice(0);for(const h of o)requestIdleCallback(()=>$(h))}const A=ye(O,500);function E(o){Ee(o.worker),o.worker=null,o.extensionPreloads.clear(),o.loadedExtensions.clear()}return{get(o){return a.get(o)},on(o,h){y.add(h);for(const k of f.splice(0))h(k);return()=>{y.delete(h)}},getOrCreate({extension:o,storefrontUrl:h,myshopifyDomain:k}){const F=$({extension:o,storefrontUrl:h,myshopifyDomain:k,appSandboxPermissions:e.appSandboxPermissions}),T=l.get(F);return T.userCount+=1,F},release(o){const h=l.get(o);return h==null?Promise.reject(new G("Could not release the provided sandbox, which usually means the sandbox has already been destroyed.")):(h.userCount-=1,h.userCount>0||(h.listeners.clear(),E(h),l.delete(o),a.delete(h.id)),Promise.resolve())},preload({extensions:o,storefrontUrl:h,myshopifyDomain:k}){const F=T=>e.deferThankYouPreloads&&!ue(T.extensionPoint.target)&&!_;for(const T of o)F(T)?m.push({extension:T,storefrontUrl:h,myshopifyDomain:k,appSandboxPermissions:e.appSandboxPermissions}):$({extension:T,storefrontUrl:h,myshopifyDomain:k,appSandboxPermissions:e.appSandboxPermissions});o.length>0&&o.every(F)&&A()}};function v(o){if(y.size>0){for(const h of y)h(o);return}f.push(o),f.length>He&&f.shift()}function $({extension:o,storefrontUrl:h,myshopifyDomain:k,appSandboxPermissions:F}){const{capabilities:T,scriptUrl:re,id:oe,extensionPoint:ne,apiVersion:U}=o,S=me({extension:o,appSandboxPermissions:F,observability:e.observability}),L=Xe({target:ne.target,publicId:oe,apiVersion:U,sandboxConfig:S});if(a.has(L)){const s=a.get(L);return S.isShared&&(s.loadExtension(o),e.observability.log("extension_loaded_in_shared_sandbox","Extension loaded into shared sandbox",{appId:o.appId,extensionId:o.id,sandboxCacheKey:L})),s}const I=new Map,p={id:L,userCount:0,scriptUrl:re,extensionPreloads:new Map,loadedExtensions:new Map,listeners:I,worker:null,workerReady:void 0},j={allowNetworkAccess:S.isShared?S.hasSharedNetworkAccess:W(o)};p.workerReady=V();async function q(s){const u=p.loadedExtensions.get(s.id);if(u&&u.scriptUrl===s.scriptUrl)return;g.markStarted("js-loading",{extension:s,instanceId:null,type:"extension"}),p.loadedExtensions.set(s.id,s);const i=_e(s),c=(async()=>{await p.workerReady;let b;try{b=await i}catch(P){throw p.loadedExtensions.delete(s.id),p.extensionPreloads.delete(s.id),g.markFinished("js-loading",{extension:s,instanceId:null,type:"extension"}),P}if(p.worker==null){g.markFinished("js-loading",{extension:s,instanceId:null,type:"extension"});return}await p.worker.load(b),g.markFinished("js-loading",{extension:s,instanceId:null,type:"extension"})})();p.extensionPreloads.set(s.id,c)}q(o);async function V(){let s=null;U==="2023-04"?s=Ke({createMessenger:d(i=>{I.get("error")?.forEach(c=>c(i))},j,o)}):D(U)?s=$e({createMessenger:d(i=>{I.get("error")?.forEach(c=>c(i))},j,o)}):s=qe({createMessenger:d(i=>{I.get("error")?.forEach(c=>c(i))},j,o)}),p.worker=s,ee(s,{reload:()=>{},extensionPerformanceMarkStarted:(i,c)=>{i in J&&g.markStarted(i,{type:"extension",extension:C(c.extensionId),...c})},extensionPerformanceMarkFinished:(i,c)=>{i in J&&g.markFinished(i,{type:"extension",extension:C(c.extensionId),...c})},reportSandboxError:(i,c)=>{const b=new be(`${i?.name??"Error"}: ${i?.message??"Unknown sandbox error"}`);i?.stack&&(b.stack=i.stack),e.observability.error(b,{severity:"error",metadata:{sandbox:ie(c?.scriptUrl)}})},reportApiRead:(i,c)=>{if(!Array.isArray(i))return;const b=typeof c?.extensionId=="string"?c.extensionId:void 0,P=b==null?o:C(b);if(P.type==="local")return;const x=[];for(const R of i)typeof R!="string"||R===""||x.push(R);x.length>0&&v({apiPropertyNames:x,extension:P,initialLoad:g.initialLoad,timestamp:new Date})}}),D(U)||await s.sandbox({allowNetworkAccess:j.allowNetworkAccess,allowApiAccess:T.apiAccess,storefrontUrl:h,myshopifyDomain:k})}function C(s){return p.loadedExtensions.get(s)??o}function ie(s){const{appId:u,appName:i}=o,c=s==null?!S.isShared&&o||void 0:[...p.loadedExtensions.values()].find(b=>b.scriptUrl===s);return{appId:u,appName:i,extensionId:c?.extensionId,extensionName:c?.name}}function N(){const s=p.worker;if(s==null)throw new G("You attempted to call a function on a terminated web worker after its extension sandbox was released.");return s}const K={async render(s,u,i,c,b,P,x,R,B,ae){const w=C(x);return ee(N(),{apiFetch:ve({appId:S.isShared?S.appId:w.appId,storefrontTokens:b,storefrontUrl:h,myshopifyDomain:k,extensionType:S.isShared?S.extensionType:w.type,allowApiAccess:S.isShared?S.hasSharedApiAccess:w.capabilities.apiAccess,apiVersion:U})}),await p.extensionPreloads.get(w.id),A(),g.markStarted("execution",{extension:w,instanceId:P,type:"extension"}),D(U)?N().render({connection:u,target:w.extensionPoint.target,translations:w.translations,extensionType:w.type,scriptUrl:w.scriptUrl,api:c,instanceId:P,extensionId:w.id,allowNetworkAccess:W(w),allowApiAccess:w.capabilities.apiAccess,storefrontUrl:h,myshopifyDomain:k,initialValues:B,relayApi:ae}).then(({output:z,teardown:Q})=>({output:z,teardown:Q})):N().render(s,u,i,c,w.translations,w.type,P,R).then(({output:z,teardown:Q})=>({output:z,teardown:Q}))},async run(s,u,i,c,b,P){const x=C(c);return We(u),await p.extensionPreloads.get(x.id),A(),D(U)?N().run({target:x.extensionPoint.target,translations:x.translations,extensionType:x.type,scriptUrl:
5x.scriptUrl,api:u,instanceId:i,extensionId:x.id,allowNetworkAccess:W(x),allowApiAccess:x.capabilities.apiAccess,storefrontUrl:h,myshopifyDomain:k,initialValues:P}).then(({output:R,teardown:B})=>({output:R,teardown:B})):N().run(s,u,x.translations,x.type,i,b).then(({output:R,teardown:B})=>({output:R,teardown:B}))},async restart(){const s=[...p.loadedExtensions.values()];E(p),p.workerReady=V();for(const u of s)q(u);I.get("restart")?.forEach(u=>u())},on(s,u){return I.has(s)?I.get(s)?.add(u):I.set(s,new Set([u])),()=>{I.get(s)?.delete(u)}},getUserCount(){return p.userCount},isWorkerAvailable(){return p.worker!==null},loadExtension(s){q(s)}};return a.set(L,K),l.set(K,p),K}}function Xe({target:r,publicId:e,apiVersion:t,sandboxConfig:n}){return n.isShared?n.cacheKey():`${e}:${r}:${t}`}const Ge={id:"19a6a28598862a756fd845752b04b4eed5d189eed0b08c3a5033847732004301",type:"query",name:"ExtensionTokens",source:""},Ze=60*1e3;class kt{#e;#r;#s;#t;#o;#i;#n;#a;#c;constructor({options:e,activatedExtensions:t,isCheckoutEditor:n,extensions:d,metafields:a,afterHydrate:l}){const{client:y,shop:f,observability:m,persistence:_,proposal:O,serializedReceipt:A,graphql:E,source:M}=e;this.#r=d,this.#s=a,this.#t=f,this.#o=_,this.#i=O,this.#n=A,this.#a=M,this.#e=new le,this.syncPermissions(d.value),this.sandboxCache=Ve(y,{observability:m,appSandboxPermissions:this.#e,deferThankYouPreloads:!n}),this.storefrontTokens=new Je({activatedExtensions:t,globalExtensions:f.globalUIExtensions,graphql:E,observability:m,source:M}),l.then(()=>this.#d()).catch(()=>{})}registerExtensionsManager(e){this.#c=e}syncPermissions(e){for(const t of e)t.appId&&this.#e.app(t.appId).syncExtension(t)}removePermissions(e){for(const t of e)t.appId&&this.#e.app(t.appId).removeExtension(t.id)}destroyExtensions(e,t){e.forEach(n=>{this.#c?.findAll({id:n.id,target:n.extensionPoint.target}).forEach(d=>{d.destroy({reason:t})})})}refreshStorefrontTokens(e){e.forEach(t=>{t.apiTokens?.storefrontApi&&this.storefrontTokens.cache.set(this.storefrontTokens.cacheKey(t.extension.appId,"persisted"),t.apiTokens.storefrontApi)})}#d(){Pe({metafields:this.#s,persistence:this.#o,proposal:this.#i,serializedReceipt:this.#n,source:this.#a}),this.#r.subscribe(e=>{this.sandboxCache.preload({extensions:e,storefrontUrl:this.#t.storefrontUrl??"",myshopifyDomain:this.#t.myshopifyDomain})})}}class Je{#e;#r;#s;#t;constructor({activatedExtensions:e,globalExtensions:t=[],graphql:n,observability:d,source:a}){this.#r=n,this.#s=d,this.#t=a,this.#e=new Map;for(const l of e){const y=this.cacheKey(l.extension.appId,"persisted");l.apiTokens?.storefrontApi&&this.#e.set(y,l.apiTokens.storefrontApi)}for(const l of t){const y=this.cacheKey(l.extension.appId,"global");l.apiTokens?.storefrontApi&&this.#e.set(y,l.apiTokens.storefrontApi)}}async get(e,t,n){const d=this.cacheKey(e,t),a=this.#e.get(d);if(a){if(!this.#i(a.expiresAt))return this.#n(t),a.token;this.#e.delete(d)}try{const{data:l,error:y}=await this.#r.staticQuery(Ge,{cache:!1,variables:{appId:e,extensionType:t}});if(y)return this.#o(y,e,t),null;const f=l?.extensionApiTokens?.storefrontApi;return f?(this.#e.set(d,f),this.#n(t),f.token):(this.#s.log("use_ensure_storefront_token_not_found_in_response","Extension storefront token not found in API response",{appId:e,extensionType:t,sourceType:this.#t.type,reason:n}),null)}catch(l){return this.#o(l,e,t),null}}get cache(){return this.#e}cacheKey(e,t){return`${e}-${t}`}#o(e,t,n){const d=e instanceof Error?e:new xe(`Failed to fetch extension storefront token for app ${t}: ${String(e)}`);this.#s.error(d,{severity:"error",metadata:{graphQL:{name:"ExtensionTokensQuery",appId:t,extensionType:n},source:{type:this.#t.type}}}),this.#s.log("use_ensure_storefront_token_fetch_failed","Failed to fetch extension storefront token",{appId:t,extensionType:n,sourceType:this.#t.type,error:e instanceof Error?e.message:String(e),errorType:e instanceof Error?e.constructor.name:typeof e})}#i(e){return Date.now()>new Date(e).getTime()-Ze}#n(e){e==="local"&&this.#t.type==="draftOrder"&&console.warn("Queries to the storefront API might not return data for certain products. The extension is currently using the online store channel for product availability. This is because the extension is in development mode, the extension is not published to the checkout configuration, and the current checkout is a draft order invoice. Install the app and add the extension in order to use draft order product availability.")}}export{Je as StorefrontTokensForBrowser,kt as UIExtensibilityBrowserEngine};
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.