@gem-sdk/pages 2.0.0-staging.1059 → 2.0.0-staging.1060
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/cjs/libs/fetcher.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var getStorefrontApi=require("./get-storefront-api.js");const createFetcher=e=>{let r=e||process.env.NEXT_PUBLIC_SHOP_TOKEN;return async e=>{let[t,o,n]=e;if(!r)throw Error("shopToken is not defined");let
|
|
1
|
+
"use strict";var getStorefrontApi=require("./get-storefront-api.js"),extractOperation=require("./helpers/extract-operation.js");const createFetcher=e=>{let r=e||process.env.NEXT_PUBLIC_SHOP_TOKEN;return async e=>{let[t,o,n]=e;if(!r)throw Error("shopToken is not defined");let i=process.env.NEXT_PUBLIC_API_URL;if(!i)throw Error("NEXT_PUBLIC_API_URL is not defined");let s=extractOperation.extractOperation(t);s&&(i=`${i}?gp-online-store-operation=${s}`);let p={"Content-Type":"application/json","X-GemX-Shop-Token":r};return fetch(i,{method:"POST",headers:p,body:JSON.stringify({query:t,variables:o,operationName:n})}).then(e=>e.json()).then(e=>e.errors?Promise.reject(e.errors):e.data)}},createAppAPIFetcher=(e,r)=>{let t=process.env.NEXT_APP_API_URL;return async o=>{let[n,i,s]=o;if(!e)throw Error("shopToken is not defined");if(!t)throw Error("NEXT_APP_API_URL is not defined");let p=extractOperation.extractOperation(n);p&&(t=`${t}?gp-online-store-operation=${p}`);let c={"Content-Type":"application/json",Authorization:`Token ${e}`,"X-GemX-Shop-ID":r||""};return fetch(`${t}?gp-online-store-operation=${s}`,{method:"POST",headers:c,body:JSON.stringify({query:n,variables:i,operationName:s})}).then(e=>e.json()).then(e=>e.errors?Promise.reject(e.errors):e.data)}},createShopifyFetcher=(e,r)=>{let t=e??process.env.NEXT_PUBLIC_STOREFRONT_TOKEN,o=r??process.env.NEXT_PUBLIC_STOREFRONT_HANDLE;return async e=>{if(!t)throw Error("NEXT_PUBLIC_STOREFRONT_TOKEN is not defined");if(!o)throw Error("NEXT_PUBLIC_STOREFRONT_HANDLE is not defined");let r={"Content-Type":"application/json","X-Shopify-Storefront-Access-Token":t},[n,i]=e;return fetch(getStorefrontApi.getStorefrontApi(o),{method:"POST",headers:r,body:JSON.stringify({query:n,variables:i})}).then(e=>e.json()).then(e=>e.errors?Promise.reject(e.errors):e.data)}};exports.createAppAPIFetcher=createAppAPIFetcher,exports.createFetcher=createFetcher,exports.createShopifyFetcher=createShopifyFetcher;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";const extractOperation=t=>{if(!t)return"";let r=t.trim().replace(/\s+/g," "),e=/^(query|mutation|subscription)\s+(\w+)/,a=r.match(e);return a?a[2]:null};exports.extractOperation=extractOperation;
|
package/dist/esm/libs/fetcher.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{getStorefrontApi as e}from"./get-storefront-api.js";let createFetcher=e=>{let
|
|
1
|
+
import{getStorefrontApi as e}from"./get-storefront-api.js";import{extractOperation as r}from"./helpers/extract-operation.js";let createFetcher=e=>{let t=e||process.env.NEXT_PUBLIC_SHOP_TOKEN;return async e=>{let[o,n,i]=e;if(!t)throw Error("shopToken is not defined");let s=process.env.NEXT_PUBLIC_API_URL;if(!s)throw Error("NEXT_PUBLIC_API_URL is not defined");let p=r(o);p&&(s=`${s}?gp-online-store-operation=${p}`);let h={"Content-Type":"application/json","X-GemX-Shop-Token":t};return fetch(s,{method:"POST",headers:h,body:JSON.stringify({query:o,variables:n,operationName:i})}).then(e=>e.json()).then(e=>e.errors?Promise.reject(e.errors):e.data)}},createAppAPIFetcher=(e,t)=>{let o=process.env.NEXT_APP_API_URL;return async n=>{let[i,s,p]=n;if(!e)throw Error("shopToken is not defined");if(!o)throw Error("NEXT_APP_API_URL is not defined");let h=r(i);h&&(o=`${o}?gp-online-store-operation=${h}`);let c={"Content-Type":"application/json",Authorization:`Token ${e}`,"X-GemX-Shop-ID":t||""};return fetch(`${o}?gp-online-store-operation=${p}`,{method:"POST",headers:c,body:JSON.stringify({query:i,variables:s,operationName:p})}).then(e=>e.json()).then(e=>e.errors?Promise.reject(e.errors):e.data)}},createShopifyFetcher=(r,t)=>{let o=r??process.env.NEXT_PUBLIC_STOREFRONT_TOKEN,n=t??process.env.NEXT_PUBLIC_STOREFRONT_HANDLE;return async r=>{if(!o)throw Error("NEXT_PUBLIC_STOREFRONT_TOKEN is not defined");if(!n)throw Error("NEXT_PUBLIC_STOREFRONT_HANDLE is not defined");let t={"Content-Type":"application/json","X-Shopify-Storefront-Access-Token":o},[i,s]=r;return fetch(e(n),{method:"POST",headers:t,body:JSON.stringify({query:i,variables:s})}).then(e=>e.json()).then(e=>e.errors?Promise.reject(e.errors):e.data)}};export{createAppAPIFetcher,createFetcher,createShopifyFetcher};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
let extractOperation=t=>{if(!t)return"";let r=t.trim().replace(/\s+/g," "),e=/^(query|mutation|subscription)\s+(\w+)/,a=r.match(e);return a?a[2]:null};export{extractOperation};
|