UNPKG

@shopify/cli

Version:

A CLI tool to build for the Shopify platform

6 lines (5 loc) 5.2 kB
import{l as R}from"./chunk-6G6TMKXF.js";import{d}from"./chunk-M56NDIMD.js";import{Qb as u,Rb as b,Z as h,da as y}from"./chunk-N5PQPIBF.js";import{g as c}from"./chunk-VPRTJUIN.js";c();c();var l=class{constructor({export:e,input:r,inputBytes:n,output:o,outputBytes:s,logs:i,functionId:g,fuelConsumed:p,target:x,errorMessage:N,errorType:T,inputQueryVariablesMetafieldValue:O,inputQueryVariablesMetafieldNamespace:L,inputQueryVariablesMetafieldKey:k}){this.export=e,this.input=r,this.inputBytes=n,this.output=o,this.outputBytes=s,this.logs=i,this.functionId=g,this.fuelConsumed=p,this.target=x,this.errorMessage=N,this.errorType=T,this.inputQueryVariablesMetafieldValue=O,this.inputQueryVariablesMetafieldNamespace=L,this.inputQueryVariablesMetafieldKey=k}},f=class{constructor({cacheEntryEpochMs:e,cacheTtlMs:r,httpRequest:n,httpResponse:o}){this.cacheEntryEpochMs=e,this.cacheTtlMs=r,this.httpRequest=n,this.httpResponse=o}};var _=class{constructor({reason:e,httpRequest:r}){this.reason=e,this.httpRequest=r}},m=class{constructor({attempt:e,connectTimeMs:r,writeReadTimeMs:n,httpRequest:o,httpResponse:s,error:i}){this.attempt=e,this.connectTimeMs=r,this.writeReadTimeMs=n,this.httpRequest=o,this.httpResponse=s,this.error=i}};c();function E(t){return t!==null&&typeof t=="object"&&!Array.isArray(t)&&Object.getPrototypeOf(t)===Object.prototype}function M(t,e){return e?.deep&&E(t)||e?.deep&&Array.isArray(t)?a(t,e):t}function a(t,e){if(Array.isArray(t))return t.map(r=>e?.deep?a(r,e):r);if(E(t)){let r={};for(let[n,o]of Object.entries(t))r[h(n)]=M(o,e);return r}return t}var S=450,I=5*1e3,w=60*1e3,z=5,Z=1e6,P="function_run",ee="function_network_access",C="function_network_access.response_from_cache",V="function_network_access.request_execution_in_background",q="function_network_access.request_execution",te="no_cached_response",re="cached_response_about_to_expire";function se(t){let e=JSON.parse(t),r=e.input_query_variables_metafield_value&&A(e.input_query_variables_metafield_value);return new l({export:e.export,input:e.input,inputBytes:e.input_bytes,output:e.output,outputBytes:e.output_bytes,logs:e.logs,functionId:e.function_id,fuelConsumed:e.fuel_consumed,target:e.target,errorMessage:e.error_message,errorType:e.error_type,inputQueryVariablesMetafieldValue:r,inputQueryVariablesMetafieldNamespace:e.input_query_variables_metafield_namespace,inputQueryVariablesMetafieldKey:e.input_query_variables_metafield_key})}function ne(t){let e=JSON.parse(t);return new f({cacheEntryEpochMs:e.cache_entry_epoch_ms,cacheTtlMs:e.cache_ttl_ms,httpRequest:e.http_request,httpResponse:e.http_response})}var U={no_cached_response:0,cached_response_about_to_expire:1};function oe(t){let e=JSON.parse(t);return new _({reason:U[e.reason]??2,httpRequest:e.http_request})}function ie(t){let e=JSON.parse(t);return new m({attempt:e.attempt,connectTimeMs:e.connect_time_ms??null,writeReadTimeMs:e.write_read_time_ms??null,httpRequest:e.http_request,httpResponse:e.http_response??null,error:e.error??null})}var ue=async t=>{let{errors:e}=t.response,r=S,n=null,o="not_attempted";if(e.length>0)if(u(`Errors: ${e.map(s=>s.message).join(", ")}`),e.some(s=>s.status===401))try{n=await t.onResubscribe(),o="succeeded"}catch(s){u(`Failed to resubscribe to app logs: ${s}`),r=w,o="failed",t.onThrottle(r)}else e.some(s=>s.status===429)?(r=w,t.onThrottle(r)):(r=I,t.onUnknownError(r));return{retryIntervalMs:r,nextJwtToken:n,resubscribeResult:o}};function ae(t){return t.allExtensions.flatMap(e=>e.isFunctionExtension?[`extensions.${e.configuration.handle}`]:[])}var pe=({appLog:t,appLogPayload:e,storeName:r,prettyPrint:n=!0})=>{let{cursor:o,...s}=t,i=a({...s,payload:e,localTime:y(t.log_timestamp),storeName:r});return e instanceof l&&(i.payload.logs=e.logs.split(` `).filter(Boolean),i.payload.inputQueryVariablesMetafieldValue&&(i.payload.inputQueryVariablesMetafieldValue=A(i.payload.inputQueryVariablesMetafieldValue))),n?JSON.stringify(i,null,2):JSON.stringify(i)},ce=(t,e)=>{let r=a(JSON.parse(t));return e===P?new l(r):e===C?new f(r):e===V?new _(r):e===q?new m(r):r},le=async(t,e,r,n)=>{let o=await t.subscribeToAppLogs(e,r);if(!o.appLogsSubscribe)throw new d("Failed to subscribe to app logs: No response received");let{jwtToken:s,success:i,errors:g}=o.appLogsSubscribe;if(u(`Token: ${s} `),u(`API Key: ${e.apiKey} `),g&&g.length>0){let p=g.join(", ");throw await R({stripAnsi:!1},()=>{b(`Errors subscribing to app logs: ${p}`,n),b("App log streaming is not available in this session.",n)}),new d(p)}else{if(!s)throw new d("Failed to subscribe to app logs: No response received");let p=Array.isArray(e.shopIds)?e.shopIds:[e.shopIds];u(`Subscribed to App Events for shop ID(s) ${p.join(", ")}`),i!==void 0&&u(`Success: ${i} `)}return s};function ge(t){try{if(typeof t=="string"){let e=JSON.parse(t);return JSON.stringify(e,null,2)}else return typeof t=="object"&&t!==null?JSON.stringify(t,null,2):void 0}catch(e){throw new Error(`Error parsing JSON: ${e}`)}}var A=t=>{try{return JSON.parse(t)}catch{return t}};export{l as a,f as b,_ as c,m as d,a as e,S as f,I as g,z as h,Z as i,P as j,ee as k,C as l,V as m,q as n,te as o,re as p,se as q,ne as r,oe as s,ie as t,ue as u,ae as v,pe as w,ce as x,le as y,ge as z};