@anker-in/lib 1.1.2-beta.1 → 1.1.2

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.
@@ -1,20 +1,20 @@
1
1
 
2
- > @anker-in/lib@1.1.1 build /Users/anker/Code/headless-ui/packages/lib
2
+ > @anker-in/lib@1.1.2-beta.2 build /Users/anker/Code/headless-ui/packages/lib
3
3
  > pnpm run build:js:esm & pnpm run build:js:cjs & pnpm run build:types:esm & pnpm run build:types:cjs
4
4
 
5
5
 
6
- > @anker-in/lib@1.1.1 build:js:cjs /Users/anker/Code/headless-ui/packages/lib
6
+ > @anker-in/lib@1.1.2-beta.2 build:js:cjs /Users/anker/Code/headless-ui/packages/lib
7
7
  > node esbuild-cjs.mjs
8
8
 
9
9
 
10
- > @anker-in/lib@1.1.1 build:types:esm /Users/anker/Code/headless-ui/packages/lib
11
- > tsc --outdir dist/esm
12
-
13
-
14
- > @anker-in/lib@1.1.1 build:js:esm /Users/anker/Code/headless-ui/packages/lib
10
+ > @anker-in/lib@1.1.2-beta.2 build:js:esm /Users/anker/Code/headless-ui/packages/lib
15
11
  > node esbuild-esm.mjs
16
12
 
17
13
 
18
- > @anker-in/lib@1.1.1 build:types:cjs /Users/anker/Code/headless-ui/packages/lib
14
+ > @anker-in/lib@1.1.2-beta.2 build:types:cjs /Users/anker/Code/headless-ui/packages/lib
19
15
  > tsc --outdir dist/cjs
20
16
 
17
+
18
+ > @anker-in/lib@1.1.2-beta.2 build:types:esm /Users/anker/Code/headless-ui/packages/lib
19
+ > tsc --outdir dist/esm
20
+
@@ -1,5 +1,5 @@
1
1
 
2
- > @anker-in/lib@1.1.1 test /Users/anker/Code/headless-ui/packages/lib
2
+ > @anker-in/lib@1.1.2-beta.2 test /Users/anker/Code/headless-ui/packages/lib
3
3
  > jest --passWithNoTests
4
4
 
5
5
  No tests found, exiting with code 0
@@ -1 +1 @@
1
- {"version":3,"file":"get-products-by-handles.d.ts","sourceRoot":"","sources":["../../../../src/shopify/fetchers/get-products-by-handles.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,qBAAqB,EAAE,cAAc,EAA2B,MAAM,kBAAkB,CAAA;AACjG,OAAO,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAA;AAE1C,MAAM,MAAM,6BAA6B,GAAG,qBAAqB,CAAC,OAAO,GAAG,qBAAqB,CAAC,OAAO,CAAA;AAEzG,MAAM,MAAM,uBAAuB,GAAG;IACpC,OAAO,EAAE,MAAM,EAAE,CAAA;CAClB,CAAA;AAED;;;;;;GAMG;AACH,eAAO,MAAM,oBAAoB,EAAE,cAAc,CAC/C,OAAO,EAAE,EACT,uBAAuB,EACvB,6BAA6B,CAuB9B,CAAA"}
1
+ {"version":3,"file":"get-products-by-handles.d.ts","sourceRoot":"","sources":["../../../../src/shopify/fetchers/get-products-by-handles.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,qBAAqB,EAAE,cAAc,EAA2B,MAAM,kBAAkB,CAAA;AACjG,OAAO,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAA;AAE1C,MAAM,MAAM,6BAA6B,GAAG,qBAAqB,CAAC,OAAO,GAAG,qBAAqB,CAAC,OAAO,CAAA;AAEzG,MAAM,MAAM,uBAAuB,GAAG;IACpC,OAAO,EAAE,MAAM,EAAE,CAAA;CAClB,CAAA;AAED;;;;;;GAMG;AACH,eAAO,MAAM,oBAAoB,EAAE,cAAc,CAC/C,OAAO,EAAE,EACT,uBAAuB,EACvB,6BAA6B,CA2B9B,CAAA"}
@@ -1,2 +1,2 @@
1
- "use strict";var i=Object.defineProperty;var p=Object.getOwnPropertyDescriptor;var y=Object.getOwnPropertyNames;var n=Object.prototype.hasOwnProperty;var m=(t,e)=>{for(var r in e)i(t,r,{get:e[r],enumerable:!0})},P=(t,e,r,a)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of y(e))!n.call(t,o)&&o!==r&&i(t,o,{get:()=>e[o],enumerable:!(a=p(e,o))||a.enumerable});return t};var h=t=>P(i({},"__esModule",{value:!0}),t);var H={};m(H,{getProductsByHandles:()=>R});module.exports=h(H);var s=require("../queries/get-product-by-handles"),c=require("../utils/fetch-graphql-api"),u=require("../utils/helper"),f=require("../utils/normalize/product");const R=async({options:t,config:e})=>{const{handles:r,metafieldIdentifiers:a,comboMetafieldsNamespace:o}=t;if(!r?.length)throw new Error("Handles are required");const l=await(0,c.fetchGraphqlApi)({query:(0,s.getProductsByHandlesQuery)(r),variables:{handles:r,...(0,u.constructMetafieldIdentifiersQueryParams)(a,o)},config:e});return Object.values(l.data).filter(d=>!!d).map(d=>(0,f.normalizeProduct)(d,""))};
1
+ "use strict";var d=Object.defineProperty;var p=Object.getOwnPropertyDescriptor;var y=Object.getOwnPropertyNames;var m=Object.prototype.hasOwnProperty;var P=(t,e)=>{for(var r in e)d(t,r,{get:e[r],enumerable:!0})},h=(t,e,r,a)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of y(e))!m.call(t,o)&&o!==r&&d(t,o,{get:()=>e[o],enumerable:!(a=p(e,o))||a.enumerable});return t};var M=t=>h(d({},"__esModule",{value:!0}),t);var H={};P(H,{getProductsByHandles:()=>R});module.exports=M(H);var f=require("../queries/get-product-by-handles"),c=require("../utils/fetch-graphql-api"),u=require("../utils/helper"),l=require("../utils/normalize/product");const R=async({options:t,config:e})=>{const{handles:r,metafieldIdentifiers:a={},comboMetafieldsNamespace:o}=t;if(!r?.length)throw new Error("Handles are required");const s=(0,u.constructMetafieldIdentifiersQueryParams)(a,o),n=await(0,c.fetchGraphqlApi)({query:(0,f.getProductsByHandlesQuery)(r),variables:{handles:r,productMetafieldIdentifiers:s.productMetafieldIdentifiers||[],variantMetafieldIdentifiers:s.variantMetafieldIdentifiers||[]},config:e});return Object.values(n.data).filter(i=>!!i).map(i=>(0,l.normalizeProduct)(i,""))};
2
2
  //# sourceMappingURL=get-products-by-handles.js.map
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../../src/shopify/fetchers/get-products-by-handles.ts"],
4
- "sourcesContent": ["import { getProductsByHandlesQuery } from '../queries/get-product-by-handles'\nimport { fetchGraphqlApi } from '../utils/fetch-graphql-api'\nimport { constructMetafieldIdentifiersQueryParams } from '../utils/helper'\nimport { normalizeProduct } from '../utils/normalize/product'\nimport { Product as ShopifyProduct } from '../gql'\nimport { HasMetafieldQueryRoot, ShopifyFetcher, ShopifyFetcherVariables } from '../types/fetcher'\nimport { Product } from '../types/product'\n\nexport type GetProductsMetafieldQueryRoot = HasMetafieldQueryRoot.Product | HasMetafieldQueryRoot.Variant\n\nexport type GetProductsByHandlesReq = {\n handles: string[]\n}\n\n/**\n * Gets products by their handles.\n *\n * @param options - The options for getting products.\n * @param config - The store configuration.\n * @returns An array of products.\n */\nexport const getProductsByHandles: ShopifyFetcher<\n Product[],\n GetProductsByHandlesReq,\n GetProductsMetafieldQueryRoot\n> = async ({ options, config }) => {\n const { handles, metafieldIdentifiers, comboMetafieldsNamespace } = options\n\n if (!handles?.length) {\n throw new Error('Handles are required')\n }\n\n const products = await fetchGraphqlApi<\n Record<string, ShopifyProduct>,\n ShopifyFetcherVariables<GetProductsByHandlesReq, GetProductsMetafieldQueryRoot>\n >({\n query: getProductsByHandlesQuery(handles),\n variables: {\n handles,\n ...constructMetafieldIdentifiersQueryParams(metafieldIdentifiers, comboMetafieldsNamespace),\n },\n config,\n })\n\n return Object.values(products.data)\n .filter(item => !!item)\n .map(product => normalizeProduct(product, '')) as Product[]\n}\n"],
5
- "mappings": "yaAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,0BAAAE,IAAA,eAAAC,EAAAH,GAAA,IAAAI,EAA0C,6CAC1CC,EAAgC,sCAChCC,EAAyD,2BACzDC,EAAiC,sCAkB1B,MAAML,EAIT,MAAO,CAAE,QAAAM,EAAS,OAAAC,CAAO,IAAM,CACjC,KAAM,CAAE,QAAAC,EAAS,qBAAAC,EAAsB,yBAAAC,CAAyB,EAAIJ,EAEpE,GAAI,CAACE,GAAS,OACZ,MAAM,IAAI,MAAM,sBAAsB,EAGxC,MAAMG,EAAW,QAAM,mBAGrB,CACA,SAAO,6BAA0BH,CAAO,EACxC,UAAW,CACT,QAAAA,EACA,MAAG,4CAAyCC,EAAsBC,CAAwB,CAC5F,EACA,OAAAH,CACF,CAAC,EAED,OAAO,OAAO,OAAOI,EAAS,IAAI,EAC/B,OAAOC,GAAQ,CAAC,CAACA,CAAI,EACrB,IAAIC,MAAW,oBAAiBA,EAAS,EAAE,CAAC,CACjD",
6
- "names": ["get_products_by_handles_exports", "__export", "getProductsByHandles", "__toCommonJS", "import_get_product_by_handles", "import_fetch_graphql_api", "import_helper", "import_product", "options", "config", "handles", "metafieldIdentifiers", "comboMetafieldsNamespace", "products", "item", "product"]
4
+ "sourcesContent": ["import { getProductsByHandlesQuery } from '../queries/get-product-by-handles'\nimport { fetchGraphqlApi } from '../utils/fetch-graphql-api'\nimport { constructMetafieldIdentifiersQueryParams } from '../utils/helper'\nimport { normalizeProduct } from '../utils/normalize/product'\nimport { Product as ShopifyProduct } from '../gql'\nimport { HasMetafieldQueryRoot, ShopifyFetcher, ShopifyFetcherVariables } from '../types/fetcher'\nimport { Product } from '../types/product'\n\nexport type GetProductsMetafieldQueryRoot = HasMetafieldQueryRoot.Product | HasMetafieldQueryRoot.Variant\n\nexport type GetProductsByHandlesReq = {\n handles: string[]\n}\n\n/**\n * Gets products by their handles.\n *\n * @param options - The options for getting products.\n * @param config - The store configuration.\n * @returns An array of products.\n */\nexport const getProductsByHandles: ShopifyFetcher<\n Product[],\n GetProductsByHandlesReq,\n GetProductsMetafieldQueryRoot\n> = async ({ options, config }) => {\n const { handles, metafieldIdentifiers = {}, comboMetafieldsNamespace } = options\n\n if (!handles?.length) {\n throw new Error('Handles are required')\n }\n\n // \u6784\u5EFA metafield identifiers\uFF0C\u786E\u4FDD\u9ED8\u8BA4\u503C\u4E3A\u7A7A\u6570\u7EC4\n const metafieldParams = constructMetafieldIdentifiersQueryParams(metafieldIdentifiers, comboMetafieldsNamespace)\n\n const products = await fetchGraphqlApi<\n Record<string, ShopifyProduct>,\n ShopifyFetcherVariables<GetProductsByHandlesReq, GetProductsMetafieldQueryRoot>\n >({\n query: getProductsByHandlesQuery(handles),\n variables: {\n handles,\n productMetafieldIdentifiers: metafieldParams.productMetafieldIdentifiers || [],\n variantMetafieldIdentifiers: metafieldParams.variantMetafieldIdentifiers || [],\n },\n config,\n })\n\n return Object.values(products.data)\n .filter(item => !!item)\n .map(product => normalizeProduct(product, '')) as Product[]\n}\n"],
5
+ "mappings": "yaAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,0BAAAE,IAAA,eAAAC,EAAAH,GAAA,IAAAI,EAA0C,6CAC1CC,EAAgC,sCAChCC,EAAyD,2BACzDC,EAAiC,sCAkB1B,MAAML,EAIT,MAAO,CAAE,QAAAM,EAAS,OAAAC,CAAO,IAAM,CACjC,KAAM,CAAE,QAAAC,EAAS,qBAAAC,EAAuB,CAAC,EAAG,yBAAAC,CAAyB,EAAIJ,EAEzE,GAAI,CAACE,GAAS,OACZ,MAAM,IAAI,MAAM,sBAAsB,EAIxC,MAAMG,KAAkB,4CAAyCF,EAAsBC,CAAwB,EAEzGE,EAAW,QAAM,mBAGrB,CACA,SAAO,6BAA0BJ,CAAO,EACxC,UAAW,CACT,QAAAA,EACA,4BAA6BG,EAAgB,6BAA+B,CAAC,EAC7E,4BAA6BA,EAAgB,6BAA+B,CAAC,CAC/E,EACA,OAAAJ,CACF,CAAC,EAED,OAAO,OAAO,OAAOK,EAAS,IAAI,EAC/B,OAAOC,GAAQ,CAAC,CAACA,CAAI,EACrB,IAAIC,MAAW,oBAAiBA,EAAS,EAAE,CAAC,CACjD",
6
+ "names": ["get_products_by_handles_exports", "__export", "getProductsByHandles", "__toCommonJS", "import_get_product_by_handles", "import_fetch_graphql_api", "import_helper", "import_product", "options", "config", "handles", "metafieldIdentifiers", "comboMetafieldsNamespace", "metafieldParams", "products", "item", "product"]
7
7
  }
@@ -1 +1 @@
1
- {"version":3,"file":"useProductsByHandles.d.ts","sourceRoot":"","sources":["../../../../src/shopify/hooks/useProductsByHandles.ts"],"names":[],"mappings":"AAGA,OAAO,EAAwB,6BAA6B,EAAE,MAAM,qCAAqC,CAAA;AACzG,OAAO,EAAE,kBAAkB,EAAE,MAAM,kBAAkB,CAAA;AACrD,OAAO,EAAE,uBAAuB,EAAE,MAAM,qCAAqC,CAAA;AAE7E,wBAAgB,oBAAoB,CAAC,EACnC,OAAO,EACP,oBAAoB,GACrB,EAAE,kBAAkB,CAAC,uBAAuB,EAAE,6BAA6B,CAAC,+DAa5E"}
1
+ {"version":3,"file":"useProductsByHandles.d.ts","sourceRoot":"","sources":["../../../../src/shopify/hooks/useProductsByHandles.ts"],"names":[],"mappings":"AAGA,OAAO,EAAwB,6BAA6B,EAAE,MAAM,qCAAqC,CAAA;AACzG,OAAO,EAAE,kBAAkB,EAAE,MAAM,kBAAkB,CAAA;AACrD,OAAO,EAAE,uBAAuB,EAAE,MAAM,qCAAqC,CAAA;AAE7E,wBAAgB,oBAAoB,CAAC,EACnC,OAAO,EACP,oBAAyB,GAC1B,EAAE,kBAAkB,CAAC,uBAAuB,EAAE,6BAA6B,CAAC,+DAa5E"}
@@ -1,2 +1,2 @@
1
- "use strict";var m=Object.create;var n=Object.defineProperty;var c=Object.getOwnPropertyDescriptor;var p=Object.getOwnPropertyNames;var a=Object.getPrototypeOf,y=Object.prototype.hasOwnProperty;var l=(o,e)=>{for(var t in e)n(o,t,{get:e[t],enumerable:!0})},i=(o,e,t,s)=>{if(e&&typeof e=="object"||typeof e=="function")for(let r of p(e))!y.call(o,r)&&r!==t&&n(o,r,{get:()=>e[r],enumerable:!(s=c(e,r))||s.enumerable});return o};var H=(o,e,t)=>(t=o!=null?m(a(o)):{},i(e||!o||!o.__esModule?n(t,"default",{value:o,enumerable:!0}):t,o)),P=o=>i(n({},"__esModule",{value:!0}),o);var B={};l(B,{useProductsByHandles:()=>R});module.exports=P(B);var d=H(require("swr")),u=require("../../context"),f=require("../fetchers/get-products-by-handles");function R({handles:o,metafieldIdentifiers:e}){const{storefrontToken:t,storeDomain:s,comboMetafieldsNamespace:r}=(0,u.useHeadlessContext)();return(0,d.default)(o?.length?{handles:o,metafieldIdentifiers:e}:void 0,async()=>(0,f.getProductsByHandles)({options:{handles:o,metafieldIdentifiers:e,comboMetafieldsNamespace:r},config:{storefrontToken:t,storeDomain:s}}))}
1
+ "use strict";var m=Object.create;var n=Object.defineProperty;var c=Object.getOwnPropertyDescriptor;var p=Object.getOwnPropertyNames;var a=Object.getPrototypeOf,y=Object.prototype.hasOwnProperty;var l=(o,e)=>{for(var t in e)n(o,t,{get:e[t],enumerable:!0})},i=(o,e,t,s)=>{if(e&&typeof e=="object"||typeof e=="function")for(let r of p(e))!y.call(o,r)&&r!==t&&n(o,r,{get:()=>e[r],enumerable:!(s=c(e,r))||s.enumerable});return o};var H=(o,e,t)=>(t=o!=null?m(a(o)):{},i(e||!o||!o.__esModule?n(t,"default",{value:o,enumerable:!0}):t,o)),P=o=>i(n({},"__esModule",{value:!0}),o);var B={};l(B,{useProductsByHandles:()=>R});module.exports=P(B);var d=H(require("swr")),u=require("../../context"),f=require("../fetchers/get-products-by-handles");function R({handles:o,metafieldIdentifiers:e={}}){const{storefrontToken:t,storeDomain:s,comboMetafieldsNamespace:r}=(0,u.useHeadlessContext)();return(0,d.default)(o?.length?{handles:o,metafieldIdentifiers:e}:void 0,async()=>(0,f.getProductsByHandles)({options:{handles:o,metafieldIdentifiers:e,comboMetafieldsNamespace:r},config:{storefrontToken:t,storeDomain:s}}))}
2
2
  //# sourceMappingURL=useProductsByHandles.js.map
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../../src/shopify/hooks/useProductsByHandles.ts"],
4
- "sourcesContent": ["import useSWR from 'swr'\nimport { useHeadlessContext } from '../../context'\n\nimport { getProductsByHandles, GetProductsMetafieldQueryRoot } from '../fetchers/get-products-by-handles'\nimport { ShopifyHookOptions } from '../types/fetcher'\nimport { GetProductsByHandlesReq } from '../fetchers/get-products-by-handles'\n\nexport function useProductsByHandles({\n handles,\n metafieldIdentifiers,\n}: ShopifyHookOptions<GetProductsByHandlesReq, GetProductsMetafieldQueryRoot>) {\n const { storefrontToken, storeDomain, comboMetafieldsNamespace } = useHeadlessContext()\n\n return useSWR(handles?.length ? { handles, metafieldIdentifiers } : undefined, async () => {\n return getProductsByHandles({\n options: {\n handles: handles,\n metafieldIdentifiers: metafieldIdentifiers,\n comboMetafieldsNamespace,\n },\n config: { storefrontToken, storeDomain },\n })\n })\n}\n"],
5
- "mappings": "0jBAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,0BAAAE,IAAA,eAAAC,EAAAH,GAAA,IAAAI,EAAmB,kBACnBC,EAAmC,yBAEnCC,EAAoE,+CAI7D,SAASJ,EAAqB,CACnC,QAAAK,EACA,qBAAAC,CACF,EAA+E,CAC7E,KAAM,CAAE,gBAAAC,EAAiB,YAAAC,EAAa,yBAAAC,CAAyB,KAAI,sBAAmB,EAEtF,SAAO,EAAAC,SAAOL,GAAS,OAAS,CAAE,QAAAA,EAAS,qBAAAC,CAAqB,EAAI,OAAW,YACtE,wBAAqB,CAC1B,QAAS,CACP,QAASD,EACT,qBAAsBC,EACtB,yBAAAG,CACF,EACA,OAAQ,CAAE,gBAAAF,EAAiB,YAAAC,CAAY,CACzC,CAAC,CACF,CACH",
4
+ "sourcesContent": ["import useSWR from 'swr'\nimport { useHeadlessContext } from '../../context'\n\nimport { getProductsByHandles, GetProductsMetafieldQueryRoot } from '../fetchers/get-products-by-handles'\nimport { ShopifyHookOptions } from '../types/fetcher'\nimport { GetProductsByHandlesReq } from '../fetchers/get-products-by-handles'\n\nexport function useProductsByHandles({\n handles,\n metafieldIdentifiers = {},\n}: ShopifyHookOptions<GetProductsByHandlesReq, GetProductsMetafieldQueryRoot>) {\n const { storefrontToken, storeDomain, comboMetafieldsNamespace } = useHeadlessContext()\n\n return useSWR(handles?.length ? { handles, metafieldIdentifiers } : undefined, async () => {\n return getProductsByHandles({\n options: {\n handles: handles,\n metafieldIdentifiers: metafieldIdentifiers,\n comboMetafieldsNamespace,\n },\n config: { storefrontToken, storeDomain },\n })\n })\n}\n"],
5
+ "mappings": "0jBAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,0BAAAE,IAAA,eAAAC,EAAAH,GAAA,IAAAI,EAAmB,kBACnBC,EAAmC,yBAEnCC,EAAoE,+CAI7D,SAASJ,EAAqB,CACnC,QAAAK,EACA,qBAAAC,EAAuB,CAAC,CAC1B,EAA+E,CAC7E,KAAM,CAAE,gBAAAC,EAAiB,YAAAC,EAAa,yBAAAC,CAAyB,KAAI,sBAAmB,EAEtF,SAAO,EAAAC,SAAOL,GAAS,OAAS,CAAE,QAAAA,EAAS,qBAAAC,CAAqB,EAAI,OAAW,YACtE,wBAAqB,CAC1B,QAAS,CACP,QAASD,EACT,qBAAsBC,EACtB,yBAAAG,CACF,EACA,OAAQ,CAAE,gBAAAF,EAAiB,YAAAC,CAAY,CACzC,CAAC,CACF,CACH",
6
6
  "names": ["useProductsByHandles_exports", "__export", "useProductsByHandles", "__toCommonJS", "import_swr", "import_context", "import_get_products_by_handles", "handles", "metafieldIdentifiers", "storefrontToken", "storeDomain", "comboMetafieldsNamespace", "useSWR"]
7
7
  }
@@ -1 +1 @@
1
- {"version":3,"file":"get-products-by-handles.d.ts","sourceRoot":"","sources":["../../../../src/shopify/fetchers/get-products-by-handles.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,qBAAqB,EAAE,cAAc,EAA2B,MAAM,kBAAkB,CAAA;AACjG,OAAO,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAA;AAE1C,MAAM,MAAM,6BAA6B,GAAG,qBAAqB,CAAC,OAAO,GAAG,qBAAqB,CAAC,OAAO,CAAA;AAEzG,MAAM,MAAM,uBAAuB,GAAG;IACpC,OAAO,EAAE,MAAM,EAAE,CAAA;CAClB,CAAA;AAED;;;;;;GAMG;AACH,eAAO,MAAM,oBAAoB,EAAE,cAAc,CAC/C,OAAO,EAAE,EACT,uBAAuB,EACvB,6BAA6B,CAuB9B,CAAA"}
1
+ {"version":3,"file":"get-products-by-handles.d.ts","sourceRoot":"","sources":["../../../../src/shopify/fetchers/get-products-by-handles.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,qBAAqB,EAAE,cAAc,EAA2B,MAAM,kBAAkB,CAAA;AACjG,OAAO,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAA;AAE1C,MAAM,MAAM,6BAA6B,GAAG,qBAAqB,CAAC,OAAO,GAAG,qBAAqB,CAAC,OAAO,CAAA;AAEzG,MAAM,MAAM,uBAAuB,GAAG;IACpC,OAAO,EAAE,MAAM,EAAE,CAAA;CAClB,CAAA;AAED;;;;;;GAMG;AACH,eAAO,MAAM,oBAAoB,EAAE,cAAc,CAC/C,OAAO,EAAE,EACT,uBAAuB,EACvB,6BAA6B,CA2B9B,CAAA"}
@@ -1,2 +1,2 @@
1
- import{getProductsByHandlesQuery as s}from"../queries/get-product-by-handles";import{fetchGraphqlApi as c}from"../utils/fetch-graphql-api";import{constructMetafieldIdentifiersQueryParams as u}from"../utils/helper";import{normalizeProduct as f}from"../utils/normalize/product";const q=async({options:r,config:o})=>{const{handles:e,metafieldIdentifiers:a,comboMetafieldsNamespace:d}=r;if(!e?.length)throw new Error("Handles are required");const i=await c({query:s(e),variables:{handles:e,...u(a,d)},config:o});return Object.values(i.data).filter(t=>!!t).map(t=>f(t,""))};export{q as getProductsByHandles};
1
+ import{getProductsByHandlesQuery as f}from"../queries/get-product-by-handles";import{fetchGraphqlApi as c}from"../utils/fetch-graphql-api";import{constructMetafieldIdentifiersQueryParams as u}from"../utils/helper";import{normalizeProduct as l}from"../utils/normalize/product";const I=async({options:o,config:a})=>{const{handles:e,metafieldIdentifiers:i={},comboMetafieldsNamespace:d}=o;if(!e?.length)throw new Error("Handles are required");const r=u(i,d),s=await c({query:f(e),variables:{handles:e,productMetafieldIdentifiers:r.productMetafieldIdentifiers||[],variantMetafieldIdentifiers:r.variantMetafieldIdentifiers||[]},config:a});return Object.values(s.data).filter(t=>!!t).map(t=>l(t,""))};export{I as getProductsByHandles};
2
2
  //# sourceMappingURL=get-products-by-handles.js.map
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../../src/shopify/fetchers/get-products-by-handles.ts"],
4
- "sourcesContent": ["import { getProductsByHandlesQuery } from '../queries/get-product-by-handles'\nimport { fetchGraphqlApi } from '../utils/fetch-graphql-api'\nimport { constructMetafieldIdentifiersQueryParams } from '../utils/helper'\nimport { normalizeProduct } from '../utils/normalize/product'\nimport { Product as ShopifyProduct } from '../gql'\nimport { HasMetafieldQueryRoot, ShopifyFetcher, ShopifyFetcherVariables } from '../types/fetcher'\nimport { Product } from '../types/product'\n\nexport type GetProductsMetafieldQueryRoot = HasMetafieldQueryRoot.Product | HasMetafieldQueryRoot.Variant\n\nexport type GetProductsByHandlesReq = {\n handles: string[]\n}\n\n/**\n * Gets products by their handles.\n *\n * @param options - The options for getting products.\n * @param config - The store configuration.\n * @returns An array of products.\n */\nexport const getProductsByHandles: ShopifyFetcher<\n Product[],\n GetProductsByHandlesReq,\n GetProductsMetafieldQueryRoot\n> = async ({ options, config }) => {\n const { handles, metafieldIdentifiers, comboMetafieldsNamespace } = options\n\n if (!handles?.length) {\n throw new Error('Handles are required')\n }\n\n const products = await fetchGraphqlApi<\n Record<string, ShopifyProduct>,\n ShopifyFetcherVariables<GetProductsByHandlesReq, GetProductsMetafieldQueryRoot>\n >({\n query: getProductsByHandlesQuery(handles),\n variables: {\n handles,\n ...constructMetafieldIdentifiersQueryParams(metafieldIdentifiers, comboMetafieldsNamespace),\n },\n config,\n })\n\n return Object.values(products.data)\n .filter(item => !!item)\n .map(product => normalizeProduct(product, '')) as Product[]\n}\n"],
5
- "mappings": "AAAA,OAAS,6BAAAA,MAAiC,oCAC1C,OAAS,mBAAAC,MAAuB,6BAChC,OAAS,4CAAAC,MAAgD,kBACzD,OAAS,oBAAAC,MAAwB,6BAkB1B,MAAMC,EAIT,MAAO,CAAE,QAAAC,EAAS,OAAAC,CAAO,IAAM,CACjC,KAAM,CAAE,QAAAC,EAAS,qBAAAC,EAAsB,yBAAAC,CAAyB,EAAIJ,EAEpE,GAAI,CAACE,GAAS,OACZ,MAAM,IAAI,MAAM,sBAAsB,EAGxC,MAAMG,EAAW,MAAMT,EAGrB,CACA,MAAOD,EAA0BO,CAAO,EACxC,UAAW,CACT,QAAAA,EACA,GAAGL,EAAyCM,EAAsBC,CAAwB,CAC5F,EACA,OAAAH,CACF,CAAC,EAED,OAAO,OAAO,OAAOI,EAAS,IAAI,EAC/B,OAAOC,GAAQ,CAAC,CAACA,CAAI,EACrB,IAAIC,GAAWT,EAAiBS,EAAS,EAAE,CAAC,CACjD",
6
- "names": ["getProductsByHandlesQuery", "fetchGraphqlApi", "constructMetafieldIdentifiersQueryParams", "normalizeProduct", "getProductsByHandles", "options", "config", "handles", "metafieldIdentifiers", "comboMetafieldsNamespace", "products", "item", "product"]
4
+ "sourcesContent": ["import { getProductsByHandlesQuery } from '../queries/get-product-by-handles'\nimport { fetchGraphqlApi } from '../utils/fetch-graphql-api'\nimport { constructMetafieldIdentifiersQueryParams } from '../utils/helper'\nimport { normalizeProduct } from '../utils/normalize/product'\nimport { Product as ShopifyProduct } from '../gql'\nimport { HasMetafieldQueryRoot, ShopifyFetcher, ShopifyFetcherVariables } from '../types/fetcher'\nimport { Product } from '../types/product'\n\nexport type GetProductsMetafieldQueryRoot = HasMetafieldQueryRoot.Product | HasMetafieldQueryRoot.Variant\n\nexport type GetProductsByHandlesReq = {\n handles: string[]\n}\n\n/**\n * Gets products by their handles.\n *\n * @param options - The options for getting products.\n * @param config - The store configuration.\n * @returns An array of products.\n */\nexport const getProductsByHandles: ShopifyFetcher<\n Product[],\n GetProductsByHandlesReq,\n GetProductsMetafieldQueryRoot\n> = async ({ options, config }) => {\n const { handles, metafieldIdentifiers = {}, comboMetafieldsNamespace } = options\n\n if (!handles?.length) {\n throw new Error('Handles are required')\n }\n\n // \u6784\u5EFA metafield identifiers\uFF0C\u786E\u4FDD\u9ED8\u8BA4\u503C\u4E3A\u7A7A\u6570\u7EC4\n const metafieldParams = constructMetafieldIdentifiersQueryParams(metafieldIdentifiers, comboMetafieldsNamespace)\n\n const products = await fetchGraphqlApi<\n Record<string, ShopifyProduct>,\n ShopifyFetcherVariables<GetProductsByHandlesReq, GetProductsMetafieldQueryRoot>\n >({\n query: getProductsByHandlesQuery(handles),\n variables: {\n handles,\n productMetafieldIdentifiers: metafieldParams.productMetafieldIdentifiers || [],\n variantMetafieldIdentifiers: metafieldParams.variantMetafieldIdentifiers || [],\n },\n config,\n })\n\n return Object.values(products.data)\n .filter(item => !!item)\n .map(product => normalizeProduct(product, '')) as Product[]\n}\n"],
5
+ "mappings": "AAAA,OAAS,6BAAAA,MAAiC,oCAC1C,OAAS,mBAAAC,MAAuB,6BAChC,OAAS,4CAAAC,MAAgD,kBACzD,OAAS,oBAAAC,MAAwB,6BAkB1B,MAAMC,EAIT,MAAO,CAAE,QAAAC,EAAS,OAAAC,CAAO,IAAM,CACjC,KAAM,CAAE,QAAAC,EAAS,qBAAAC,EAAuB,CAAC,EAAG,yBAAAC,CAAyB,EAAIJ,EAEzE,GAAI,CAACE,GAAS,OACZ,MAAM,IAAI,MAAM,sBAAsB,EAIxC,MAAMG,EAAkBR,EAAyCM,EAAsBC,CAAwB,EAEzGE,EAAW,MAAMV,EAGrB,CACA,MAAOD,EAA0BO,CAAO,EACxC,UAAW,CACT,QAAAA,EACA,4BAA6BG,EAAgB,6BAA+B,CAAC,EAC7E,4BAA6BA,EAAgB,6BAA+B,CAAC,CAC/E,EACA,OAAAJ,CACF,CAAC,EAED,OAAO,OAAO,OAAOK,EAAS,IAAI,EAC/B,OAAOC,GAAQ,CAAC,CAACA,CAAI,EACrB,IAAIC,GAAWV,EAAiBU,EAAS,EAAE,CAAC,CACjD",
6
+ "names": ["getProductsByHandlesQuery", "fetchGraphqlApi", "constructMetafieldIdentifiersQueryParams", "normalizeProduct", "getProductsByHandles", "options", "config", "handles", "metafieldIdentifiers", "comboMetafieldsNamespace", "metafieldParams", "products", "item", "product"]
7
7
  }
@@ -1 +1 @@
1
- {"version":3,"file":"useProductsByHandles.d.ts","sourceRoot":"","sources":["../../../../src/shopify/hooks/useProductsByHandles.ts"],"names":[],"mappings":"AAGA,OAAO,EAAwB,6BAA6B,EAAE,MAAM,qCAAqC,CAAA;AACzG,OAAO,EAAE,kBAAkB,EAAE,MAAM,kBAAkB,CAAA;AACrD,OAAO,EAAE,uBAAuB,EAAE,MAAM,qCAAqC,CAAA;AAE7E,wBAAgB,oBAAoB,CAAC,EACnC,OAAO,EACP,oBAAoB,GACrB,EAAE,kBAAkB,CAAC,uBAAuB,EAAE,6BAA6B,CAAC,+DAa5E"}
1
+ {"version":3,"file":"useProductsByHandles.d.ts","sourceRoot":"","sources":["../../../../src/shopify/hooks/useProductsByHandles.ts"],"names":[],"mappings":"AAGA,OAAO,EAAwB,6BAA6B,EAAE,MAAM,qCAAqC,CAAA;AACzG,OAAO,EAAE,kBAAkB,EAAE,MAAM,kBAAkB,CAAA;AACrD,OAAO,EAAE,uBAAuB,EAAE,MAAM,qCAAqC,CAAA;AAE7E,wBAAgB,oBAAoB,CAAC,EACnC,OAAO,EACP,oBAAyB,GAC1B,EAAE,kBAAkB,CAAC,uBAAuB,EAAE,6BAA6B,CAAC,+DAa5E"}
@@ -1,2 +1,2 @@
1
- import n from"swr";import{useHeadlessContext as i}from"../../context";import{getProductsByHandles as d}from"../fetchers/get-products-by-handles";function H({handles:o,metafieldIdentifiers:e}){const{storefrontToken:t,storeDomain:r,comboMetafieldsNamespace:s}=i();return n(o?.length?{handles:o,metafieldIdentifiers:e}:void 0,async()=>d({options:{handles:o,metafieldIdentifiers:e,comboMetafieldsNamespace:s},config:{storefrontToken:t,storeDomain:r}}))}export{H as useProductsByHandles};
1
+ import n from"swr";import{useHeadlessContext as i}from"../../context";import{getProductsByHandles as d}from"../fetchers/get-products-by-handles";function H({handles:o,metafieldIdentifiers:e={}}){const{storefrontToken:t,storeDomain:r,comboMetafieldsNamespace:s}=i();return n(o?.length?{handles:o,metafieldIdentifiers:e}:void 0,async()=>d({options:{handles:o,metafieldIdentifiers:e,comboMetafieldsNamespace:s},config:{storefrontToken:t,storeDomain:r}}))}export{H as useProductsByHandles};
2
2
  //# sourceMappingURL=useProductsByHandles.js.map
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../../src/shopify/hooks/useProductsByHandles.ts"],
4
- "sourcesContent": ["import useSWR from 'swr'\nimport { useHeadlessContext } from '../../context'\n\nimport { getProductsByHandles, GetProductsMetafieldQueryRoot } from '../fetchers/get-products-by-handles'\nimport { ShopifyHookOptions } from '../types/fetcher'\nimport { GetProductsByHandlesReq } from '../fetchers/get-products-by-handles'\n\nexport function useProductsByHandles({\n handles,\n metafieldIdentifiers,\n}: ShopifyHookOptions<GetProductsByHandlesReq, GetProductsMetafieldQueryRoot>) {\n const { storefrontToken, storeDomain, comboMetafieldsNamespace } = useHeadlessContext()\n\n return useSWR(handles?.length ? { handles, metafieldIdentifiers } : undefined, async () => {\n return getProductsByHandles({\n options: {\n handles: handles,\n metafieldIdentifiers: metafieldIdentifiers,\n comboMetafieldsNamespace,\n },\n config: { storefrontToken, storeDomain },\n })\n })\n}\n"],
5
- "mappings": "AAAA,OAAOA,MAAY,MACnB,OAAS,sBAAAC,MAA0B,gBAEnC,OAAS,wBAAAC,MAA2D,sCAI7D,SAASC,EAAqB,CACnC,QAAAC,EACA,qBAAAC,CACF,EAA+E,CAC7E,KAAM,CAAE,gBAAAC,EAAiB,YAAAC,EAAa,yBAAAC,CAAyB,EAAIP,EAAmB,EAEtF,OAAOD,EAAOI,GAAS,OAAS,CAAE,QAAAA,EAAS,qBAAAC,CAAqB,EAAI,OAAW,SACtEH,EAAqB,CAC1B,QAAS,CACP,QAASE,EACT,qBAAsBC,EACtB,yBAAAG,CACF,EACA,OAAQ,CAAE,gBAAAF,EAAiB,YAAAC,CAAY,CACzC,CAAC,CACF,CACH",
4
+ "sourcesContent": ["import useSWR from 'swr'\nimport { useHeadlessContext } from '../../context'\n\nimport { getProductsByHandles, GetProductsMetafieldQueryRoot } from '../fetchers/get-products-by-handles'\nimport { ShopifyHookOptions } from '../types/fetcher'\nimport { GetProductsByHandlesReq } from '../fetchers/get-products-by-handles'\n\nexport function useProductsByHandles({\n handles,\n metafieldIdentifiers = {},\n}: ShopifyHookOptions<GetProductsByHandlesReq, GetProductsMetafieldQueryRoot>) {\n const { storefrontToken, storeDomain, comboMetafieldsNamespace } = useHeadlessContext()\n\n return useSWR(handles?.length ? { handles, metafieldIdentifiers } : undefined, async () => {\n return getProductsByHandles({\n options: {\n handles: handles,\n metafieldIdentifiers: metafieldIdentifiers,\n comboMetafieldsNamespace,\n },\n config: { storefrontToken, storeDomain },\n })\n })\n}\n"],
5
+ "mappings": "AAAA,OAAOA,MAAY,MACnB,OAAS,sBAAAC,MAA0B,gBAEnC,OAAS,wBAAAC,MAA2D,sCAI7D,SAASC,EAAqB,CACnC,QAAAC,EACA,qBAAAC,EAAuB,CAAC,CAC1B,EAA+E,CAC7E,KAAM,CAAE,gBAAAC,EAAiB,YAAAC,EAAa,yBAAAC,CAAyB,EAAIP,EAAmB,EAEtF,OAAOD,EAAOI,GAAS,OAAS,CAAE,QAAAA,EAAS,qBAAAC,CAAqB,EAAI,OAAW,SACtEH,EAAqB,CAC1B,QAAS,CACP,QAASE,EACT,qBAAsBC,EACtB,yBAAAG,CACF,EACA,OAAQ,CAAE,gBAAAF,EAAiB,YAAAC,CAAY,CACzC,CAAC,CACF,CACH",
6
6
  "names": ["useSWR", "useHeadlessContext", "getProductsByHandles", "useProductsByHandles", "handles", "metafieldIdentifiers", "storefrontToken", "storeDomain", "comboMetafieldsNamespace"]
7
7
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@anker-in/lib",
3
- "version": "1.1.2-beta.1",
3
+ "version": "1.1.2",
4
4
  "description": "Unified Anker headless library with shared context, Shopify integration, and cart utilities",
5
5
  "main": "./dist/cjs/index.js",
6
6
  "module": "./dist/esm/index.js",
@@ -24,12 +24,15 @@ export const getProductsByHandles: ShopifyFetcher<
24
24
  GetProductsByHandlesReq,
25
25
  GetProductsMetafieldQueryRoot
26
26
  > = async ({ options, config }) => {
27
- const { handles, metafieldIdentifiers, comboMetafieldsNamespace } = options
27
+ const { handles, metafieldIdentifiers = {}, comboMetafieldsNamespace } = options
28
28
 
29
29
  if (!handles?.length) {
30
30
  throw new Error('Handles are required')
31
31
  }
32
32
 
33
+ // 构建 metafield identifiers,确保默认值为空数组
34
+ const metafieldParams = constructMetafieldIdentifiersQueryParams(metafieldIdentifiers, comboMetafieldsNamespace)
35
+
33
36
  const products = await fetchGraphqlApi<
34
37
  Record<string, ShopifyProduct>,
35
38
  ShopifyFetcherVariables<GetProductsByHandlesReq, GetProductsMetafieldQueryRoot>
@@ -37,7 +40,8 @@ export const getProductsByHandles: ShopifyFetcher<
37
40
  query: getProductsByHandlesQuery(handles),
38
41
  variables: {
39
42
  handles,
40
- ...constructMetafieldIdentifiersQueryParams(metafieldIdentifiers, comboMetafieldsNamespace),
43
+ productMetafieldIdentifiers: metafieldParams.productMetafieldIdentifiers || [],
44
+ variantMetafieldIdentifiers: metafieldParams.variantMetafieldIdentifiers || [],
41
45
  },
42
46
  config,
43
47
  })
@@ -7,7 +7,7 @@ import { GetProductsByHandlesReq } from '../fetchers/get-products-by-handles'
7
7
 
8
8
  export function useProductsByHandles({
9
9
  handles,
10
- metafieldIdentifiers,
10
+ metafieldIdentifiers = {},
11
11
  }: ShopifyHookOptions<GetProductsByHandlesReq, GetProductsMetafieldQueryRoot>) {
12
12
  const { storefrontToken, storeDomain, comboMetafieldsNamespace } = useHeadlessContext()
13
13