@gem-sdk/core 1.5.17 → 1.5.22

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.
Files changed (206) hide show
  1. package/dist/cjs/components/AddOn.js +7 -7
  2. package/dist/cjs/components/ComponentWrapper.js +14 -8
  3. package/dist/cjs/components/ComponentWrapperPreview.js +55 -46
  4. package/dist/cjs/components/Empty.js +1 -1
  5. package/dist/cjs/components/Render.js +50 -13
  6. package/dist/cjs/components/Render.liquid.js +81 -57
  7. package/dist/cjs/components/RenderBlock.js +41 -8
  8. package/dist/cjs/components/RenderPreview.js +51 -13
  9. package/dist/cjs/components/RenderSection.js +11 -7
  10. package/dist/cjs/components/constant.js +24 -24
  11. package/dist/cjs/contexts/AddonContext.js +25 -14
  12. package/dist/cjs/contexts/BuilderComponent.js +23 -19
  13. package/dist/cjs/contexts/BuilderContext.js +25 -19
  14. package/dist/cjs/contexts/BuilderPreviewContext.js +349 -341
  15. package/dist/cjs/contexts/CartLineContext.js +19 -14
  16. package/dist/cjs/contexts/CollectionContext.js +21 -13
  17. package/dist/cjs/contexts/ProductContext.js +136 -115
  18. package/dist/cjs/contexts/ProductListContext.js +21 -13
  19. package/dist/cjs/contexts/SectionContext.js +41 -37
  20. package/dist/cjs/contexts/ShopContext.js +49 -31
  21. package/dist/cjs/graphql/fragments/analytic.generated.js +1 -1
  22. package/dist/cjs/graphql/fragments/collection-detail.generated.js +1 -1
  23. package/dist/cjs/graphql/fragments/collection-product.generated.js +1 -1
  24. package/dist/cjs/graphql/fragments/custom-code.generated.js +1 -1
  25. package/dist/cjs/graphql/fragments/data-seo.generated.js +1 -1
  26. package/dist/cjs/graphql/fragments/media.generated.js +1 -1
  27. package/dist/cjs/graphql/fragments/product-little.generated.js +1 -1
  28. package/dist/cjs/graphql/fragments/product-option-value.generated.js +1 -1
  29. package/dist/cjs/graphql/fragments/product-option.generated.js +1 -1
  30. package/dist/cjs/graphql/fragments/product.generated.js +1 -1
  31. package/dist/cjs/graphql/fragments/published-custom-section.generated.js +1 -1
  32. package/dist/cjs/graphql/fragments/published-page-section.generated.js +1 -1
  33. package/dist/cjs/graphql/fragments/published-theme-page.generated.js +1 -1
  34. package/dist/cjs/graphql/fragments/published-theme-style.generated.js +1 -1
  35. package/dist/cjs/graphql/fragments/selected-option.generated.js +1 -1
  36. package/dist/cjs/graphql/fragments/variant.generated.js +1 -1
  37. package/dist/cjs/graphql/mutations/page-view-up.generated.js +1 -1
  38. package/dist/cjs/graphql/queries/products.generated.js +1 -1
  39. package/dist/cjs/graphql/queries/store-property.generated.js +1 -1
  40. package/dist/cjs/helpers/GlobalEvent.js +12 -10
  41. package/dist/cjs/helpers/background.js +96 -96
  42. package/dist/cjs/helpers/borders.js +123 -127
  43. package/dist/cjs/helpers/clone-deep.js +1 -1
  44. package/dist/cjs/helpers/cls.js +11 -15
  45. package/dist/cjs/helpers/colors.js +121 -156
  46. package/dist/cjs/helpers/compose-advance-style.js +115 -121
  47. package/dist/cjs/helpers/constant.js +16 -11
  48. package/dist/cjs/helpers/css-variable.js +2 -2
  49. package/dist/cjs/helpers/email.js +3 -3
  50. package/dist/cjs/helpers/flatten-connection.js +4 -5
  51. package/dist/cjs/helpers/get-resonsive-value.js +24 -25
  52. package/dist/cjs/helpers/get-shortname.js +87 -87
  53. package/dist/cjs/helpers/is-browser.js +2 -2
  54. package/dist/cjs/helpers/is-defined.js +2 -2
  55. package/dist/cjs/helpers/is-empty-children.js +2 -2
  56. package/dist/cjs/helpers/layout.js +9 -10
  57. package/dist/cjs/helpers/load-script.js +26 -27
  58. package/dist/cjs/helpers/make-style.js +77 -86
  59. package/dist/cjs/helpers/normalize-builder-data.js +18 -12
  60. package/dist/cjs/helpers/prefetch-queries.js +72 -52
  61. package/dist/cjs/helpers/product.js +25 -29
  62. package/dist/cjs/helpers/queries/get-collection.js +179 -167
  63. package/dist/cjs/helpers/queries/get-product-by-slug.js +103 -94
  64. package/dist/cjs/helpers/queries/get-product.js +121 -106
  65. package/dist/cjs/helpers/queries/get-products.js +137 -125
  66. package/dist/cjs/helpers/radius.js +78 -81
  67. package/dist/cjs/helpers/render.js +56 -56
  68. package/dist/cjs/helpers/shadow.js +38 -38
  69. package/dist/cjs/helpers/size.js +12 -13
  70. package/dist/cjs/helpers/spacing.js +35 -37
  71. package/dist/cjs/helpers/tracking/fpixel.js +21 -22
  72. package/dist/cjs/helpers/tracking/gtag.js +84 -90
  73. package/dist/cjs/helpers/tracking/tiktokpixel.js +12 -12
  74. package/dist/cjs/helpers/typography.js +2 -2
  75. package/dist/cjs/hooks/cart/use-add-to-cart.js +10 -10
  76. package/dist/cjs/hooks/cart/use-cart-data.js +18 -16
  77. package/dist/cjs/hooks/cart/use-cart-discount-codes-update.js +10 -10
  78. package/dist/cjs/hooks/cart/use-cart-note-update.js +10 -10
  79. package/dist/cjs/hooks/cart/use-create-cart.js +12 -12
  80. package/dist/cjs/hooks/cart/use-remove-cart-item.js +10 -10
  81. package/dist/cjs/hooks/cart/use-update-cart-item.js +10 -10
  82. package/dist/cjs/hooks/shop/use-collection-query.js +12 -6
  83. package/dist/cjs/hooks/shop/use-product-query.js +12 -6
  84. package/dist/cjs/hooks/shop/use-products-query.js +14 -6
  85. package/dist/cjs/hooks/shop.js +86 -67
  86. package/dist/cjs/hooks/use-current-device.js +14 -16
  87. package/dist/cjs/hooks/use-lazy-video.js +7 -7
  88. package/dist/cjs/hooks/useCartId.js +35 -27
  89. package/dist/cjs/hooks/useCartLine.js +2 -2
  90. package/dist/cjs/hooks/useCartUI.js +37 -31
  91. package/dist/cjs/hooks/useCollection.js +2 -2
  92. package/dist/cjs/hooks/useFetchHandle.js +6 -6
  93. package/dist/cjs/hooks/useFormatMoney.js +11 -7
  94. package/dist/cjs/hooks/useIsomorphicLayoutEffect.js +1 -1
  95. package/dist/cjs/hooks/useLoadScript.js +22 -20
  96. package/dist/cjs/hooks/useMoney.js +59 -42
  97. package/dist/cjs/hooks/usePrevious.js +12 -10
  98. package/dist/cjs/hooks/useProduct.js +92 -69
  99. package/dist/cjs/hooks/useProductList.js +11 -11
  100. package/dist/cjs/hooks/useSuspenseFetch.js +20 -17
  101. package/dist/cjs/hooks/useSwatchesOptions.js +32 -30
  102. package/dist/cjs/types/global-style.js +9 -2
  103. package/dist/esm/components/AddOn.js +7 -7
  104. package/dist/esm/components/ComponentWrapper.js +14 -8
  105. package/dist/esm/components/ComponentWrapperPreview.js +55 -46
  106. package/dist/esm/components/Empty.js +1 -1
  107. package/dist/esm/components/Render.js +50 -13
  108. package/dist/esm/components/Render.liquid.js +81 -57
  109. package/dist/esm/components/RenderBlock.js +41 -8
  110. package/dist/esm/components/RenderPreview.js +51 -13
  111. package/dist/esm/components/RenderSection.js +11 -7
  112. package/dist/esm/components/constant.js +24 -24
  113. package/dist/esm/contexts/AddonContext.js +26 -15
  114. package/dist/esm/contexts/BuilderComponent.js +24 -20
  115. package/dist/esm/contexts/BuilderContext.js +26 -20
  116. package/dist/esm/contexts/BuilderPreviewContext.js +350 -342
  117. package/dist/esm/contexts/CartLineContext.js +20 -15
  118. package/dist/esm/contexts/CollectionContext.js +22 -14
  119. package/dist/esm/contexts/ProductContext.js +137 -116
  120. package/dist/esm/contexts/ProductListContext.js +22 -14
  121. package/dist/esm/contexts/SectionContext.js +42 -38
  122. package/dist/esm/contexts/ShopContext.js +50 -32
  123. package/dist/esm/graphql/fragments/analytic.generated.js +1 -1
  124. package/dist/esm/graphql/fragments/collection-detail.generated.js +1 -1
  125. package/dist/esm/graphql/fragments/collection-product.generated.js +1 -1
  126. package/dist/esm/graphql/fragments/custom-code.generated.js +1 -1
  127. package/dist/esm/graphql/fragments/data-seo.generated.js +1 -1
  128. package/dist/esm/graphql/fragments/media.generated.js +1 -1
  129. package/dist/esm/graphql/fragments/product-little.generated.js +1 -1
  130. package/dist/esm/graphql/fragments/product-option-value.generated.js +1 -1
  131. package/dist/esm/graphql/fragments/product-option.generated.js +1 -1
  132. package/dist/esm/graphql/fragments/product.generated.js +1 -1
  133. package/dist/esm/graphql/fragments/published-custom-section.generated.js +1 -1
  134. package/dist/esm/graphql/fragments/published-page-section.generated.js +1 -1
  135. package/dist/esm/graphql/fragments/published-theme-page.generated.js +1 -1
  136. package/dist/esm/graphql/fragments/published-theme-style.generated.js +1 -1
  137. package/dist/esm/graphql/fragments/selected-option.generated.js +1 -1
  138. package/dist/esm/graphql/fragments/variant.generated.js +1 -1
  139. package/dist/esm/graphql/mutations/page-view-up.generated.js +1 -1
  140. package/dist/esm/graphql/queries/products.generated.js +1 -1
  141. package/dist/esm/graphql/queries/store-property.generated.js +1 -1
  142. package/dist/esm/helpers/GlobalEvent.js +12 -10
  143. package/dist/esm/helpers/background.js +96 -96
  144. package/dist/esm/helpers/borders.js +123 -127
  145. package/dist/esm/helpers/clone-deep.js +1 -1
  146. package/dist/esm/helpers/cls.js +11 -15
  147. package/dist/esm/helpers/colors.js +121 -156
  148. package/dist/esm/helpers/compose-advance-style.js +115 -121
  149. package/dist/esm/helpers/constant.js +16 -11
  150. package/dist/esm/helpers/css-variable.js +2 -2
  151. package/dist/esm/helpers/email.js +3 -3
  152. package/dist/esm/helpers/flatten-connection.js +4 -5
  153. package/dist/esm/helpers/get-resonsive-value.js +24 -25
  154. package/dist/esm/helpers/get-shortname.js +87 -87
  155. package/dist/esm/helpers/is-browser.js +2 -2
  156. package/dist/esm/helpers/is-defined.js +2 -2
  157. package/dist/esm/helpers/is-empty-children.js +2 -2
  158. package/dist/esm/helpers/layout.js +9 -10
  159. package/dist/esm/helpers/load-script.js +26 -27
  160. package/dist/esm/helpers/make-style.js +77 -86
  161. package/dist/esm/helpers/normalize-builder-data.js +18 -12
  162. package/dist/esm/helpers/prefetch-queries.js +72 -52
  163. package/dist/esm/helpers/product.js +25 -29
  164. package/dist/esm/helpers/queries/get-collection.js +179 -167
  165. package/dist/esm/helpers/queries/get-product-by-slug.js +103 -94
  166. package/dist/esm/helpers/queries/get-product.js +121 -106
  167. package/dist/esm/helpers/queries/get-products.js +137 -125
  168. package/dist/esm/helpers/radius.js +78 -81
  169. package/dist/esm/helpers/render.js +56 -56
  170. package/dist/esm/helpers/shadow.js +38 -38
  171. package/dist/esm/helpers/size.js +12 -13
  172. package/dist/esm/helpers/spacing.js +35 -37
  173. package/dist/esm/helpers/tracking/fpixel.js +21 -22
  174. package/dist/esm/helpers/tracking/gtag.js +84 -90
  175. package/dist/esm/helpers/tracking/tiktokpixel.js +12 -12
  176. package/dist/esm/helpers/typography.js +2 -2
  177. package/dist/esm/hooks/cart/use-add-to-cart.js +10 -10
  178. package/dist/esm/hooks/cart/use-cart-data.js +18 -16
  179. package/dist/esm/hooks/cart/use-cart-discount-codes-update.js +10 -10
  180. package/dist/esm/hooks/cart/use-cart-note-update.js +10 -10
  181. package/dist/esm/hooks/cart/use-create-cart.js +12 -12
  182. package/dist/esm/hooks/cart/use-remove-cart-item.js +10 -10
  183. package/dist/esm/hooks/cart/use-update-cart-item.js +10 -10
  184. package/dist/esm/hooks/shop/use-collection-query.js +12 -6
  185. package/dist/esm/hooks/shop/use-product-query.js +12 -6
  186. package/dist/esm/hooks/shop/use-products-query.js +14 -6
  187. package/dist/esm/hooks/shop.js +86 -67
  188. package/dist/esm/hooks/use-current-device.js +14 -16
  189. package/dist/esm/hooks/use-lazy-video.js +7 -7
  190. package/dist/esm/hooks/useCartId.js +35 -27
  191. package/dist/esm/hooks/useCartLine.js +2 -2
  192. package/dist/esm/hooks/useCartUI.js +37 -31
  193. package/dist/esm/hooks/useCollection.js +2 -2
  194. package/dist/esm/hooks/useFetchHandle.js +6 -6
  195. package/dist/esm/hooks/useFormatMoney.js +11 -7
  196. package/dist/esm/hooks/useIsomorphicLayoutEffect.js +1 -1
  197. package/dist/esm/hooks/useLoadScript.js +22 -20
  198. package/dist/esm/hooks/useMoney.js +59 -42
  199. package/dist/esm/hooks/usePrevious.js +12 -10
  200. package/dist/esm/hooks/useProduct.js +92 -69
  201. package/dist/esm/hooks/useProductList.js +11 -11
  202. package/dist/esm/hooks/useSuspenseFetch.js +20 -17
  203. package/dist/esm/hooks/useSwatchesOptions.js +32 -30
  204. package/dist/esm/types/global-style.js +9 -2
  205. package/dist/types/index.d.ts +24 -2
  206. package/package.json +1 -1
@@ -2,100 +2,109 @@ import { ProductLittleDetailDocument } from '../../graphql/queries/product-littl
2
2
  import { ProductMediasDocument } from '../../graphql/queries/product-medias.generated.js';
3
3
  import { ProductVariantsDocument } from '../../graphql/queries/product-variants.generated.js';
4
4
 
5
- const getProductBySlug = async (fetcher, slug) => {
6
- const [product, variants, medias] = await Promise.all([
7
- fetchProduct(fetcher, slug),
8
- fetchVariants(fetcher, slug),
9
- fetchMedias(fetcher, slug),
10
- ]);
11
- if (!product) {
12
- throw new Error('Product not found');
13
- }
14
- return {
15
- ...product,
16
- variants: {
17
- edges: variants,
18
- },
19
- medias: {
20
- edges: medias,
21
- },
22
- };
23
- };
24
- const orderBy = {
25
- field: 'UPDATED_AT',
26
- direction: 'DESC',
27
- };
28
- const fetchProduct = async (fetcher, handle) => {
29
- const variables = {
30
- orderBy,
31
- where: { handle, isStorefront: true },
32
- };
33
- const response = await fetcher([ProductLittleDetailDocument, variables]);
34
- return response.product?.edges?.[0]?.node;
35
- };
36
- const fetchVariants = async (fetcher, handle) => {
37
- const initVariables = {
38
- orderBy,
39
- where: { handle, isStorefront: true },
40
- };
41
- const query = async (variables, olds) => {
42
- try {
43
- const response = await fetcher([
44
- ProductVariantsDocument,
45
- variables,
46
- ]);
47
- const product = response.variants?.edges?.[0];
48
- const items = olds?.concat(product?.node?.variants?.edges ?? []);
49
- if (product?.node?.variants?.pageInfo?.hasNextPage) {
50
- return query({
51
- ...variables,
52
- afterVariant: product?.node?.variants?.pageInfo.endCursor,
53
- }, items);
54
- }
55
- return items ?? [];
56
- }
57
- catch {
58
- return olds ?? [];
59
- }
60
- };
61
- return query(initVariables, []);
62
- };
63
- const fetchMedias = async (fetcher, handle) => {
64
- const initVariables = {
65
- orderBy,
66
- where: { handle, isStorefront: true },
67
- orderByMedia: {
68
- field: 'POSITION',
69
- direction: 'ASC',
70
- },
71
- };
72
- const query = async (variables) => {
73
- try {
74
- const response = await fetcher([
75
- ProductMediasDocument,
76
- variables,
77
- ]);
78
- const product = response.medias?.edges?.[0];
79
- const items = product?.node?.medias?.edges ?? [];
80
- if (product?.node?.medias?.pageInfo?.hasNextPage) {
81
- try {
82
- const newData = await query({
83
- ...variables,
84
- afterMedia: product?.node?.medias?.pageInfo.endCursor,
85
- });
86
- return items.concat(newData);
87
- }
88
- catch {
89
- return items;
90
- }
91
- }
92
- return items;
93
- }
94
- catch {
95
- return [];
96
- }
97
- };
98
- return query(initVariables);
5
+ const getProductBySlug = async (fetcher, slug)=>{
6
+ const [product, variants, medias] = await Promise.all([
7
+ fetchProduct(fetcher, slug),
8
+ fetchVariants(fetcher, slug),
9
+ fetchMedias(fetcher, slug)
10
+ ]);
11
+ if (!product) {
12
+ throw new Error('Product not found');
13
+ }
14
+ return {
15
+ ...product,
16
+ variants: {
17
+ edges: variants
18
+ },
19
+ medias: {
20
+ edges: medias
21
+ }
22
+ };
23
+ };
24
+ const orderBy = {
25
+ field: 'UPDATED_AT',
26
+ direction: 'DESC'
27
+ };
28
+ const fetchProduct = async (fetcher, handle)=>{
29
+ const variables = {
30
+ orderBy,
31
+ where: {
32
+ handle,
33
+ isStorefront: true
34
+ }
35
+ };
36
+ const response = await fetcher([
37
+ ProductLittleDetailDocument,
38
+ variables
39
+ ]);
40
+ return response.product?.edges?.[0]?.node;
41
+ };
42
+ const fetchVariants = async (fetcher, handle)=>{
43
+ const initVariables = {
44
+ orderBy,
45
+ where: {
46
+ handle,
47
+ isStorefront: true
48
+ }
49
+ };
50
+ const query = async (variables, olds)=>{
51
+ try {
52
+ const response = await fetcher([
53
+ ProductVariantsDocument,
54
+ variables
55
+ ]);
56
+ const product = response.variants?.edges?.[0];
57
+ const items = olds?.concat(product?.node?.variants?.edges ?? []);
58
+ if (product?.node?.variants?.pageInfo?.hasNextPage) {
59
+ return query({
60
+ ...variables,
61
+ afterVariant: product?.node?.variants?.pageInfo.endCursor
62
+ }, items);
63
+ }
64
+ return items ?? [];
65
+ } catch {
66
+ return olds ?? [];
67
+ }
68
+ };
69
+ return query(initVariables, []);
70
+ };
71
+ const fetchMedias = async (fetcher, handle)=>{
72
+ const initVariables = {
73
+ orderBy,
74
+ where: {
75
+ handle,
76
+ isStorefront: true
77
+ },
78
+ orderByMedia: {
79
+ field: 'POSITION',
80
+ direction: 'ASC'
81
+ }
82
+ };
83
+ const query = async (variables)=>{
84
+ try {
85
+ const response = await fetcher([
86
+ ProductMediasDocument,
87
+ variables
88
+ ]);
89
+ const product = response.medias?.edges?.[0];
90
+ const items = product?.node?.medias?.edges ?? [];
91
+ if (product?.node?.medias?.pageInfo?.hasNextPage) {
92
+ try {
93
+ const newData = await query({
94
+ ...variables,
95
+ afterMedia: product?.node?.medias?.pageInfo.endCursor
96
+ });
97
+ return items.concat(newData);
98
+ } catch {
99
+ return items;
100
+ }
101
+ }
102
+ return items;
103
+ } catch {
104
+ return [];
105
+ }
106
+ };
107
+ return query(initVariables);
99
108
  };
100
109
 
101
110
  export { getProductBySlug };
@@ -2,112 +2,127 @@ import { ProductLittleDetailDocument } from '../../graphql/queries/product-littl
2
2
  import { ProductMediasDocument } from '../../graphql/queries/product-medias.generated.js';
3
3
  import { ProductVariantsDocument } from '../../graphql/queries/product-variants.generated.js';
4
4
 
5
- const getProduct = async (fetcher, { id, isSample }) => {
6
- const [product, variants, medias] = await Promise.all([
7
- fetchProduct(fetcher, { id, isSample }),
8
- fetchVariants(fetcher, { id, isSample }),
9
- fetchMedias(fetcher, { id, isSample }),
10
- ]);
11
- if (!product) {
12
- throw new Error('Product not found');
13
- }
14
- return {
15
- ...product,
16
- variants: {
17
- edges: variants,
18
- },
19
- medias: {
20
- edges: medias,
21
- },
22
- };
23
- };
24
- const orderBy = {
25
- field: 'UPDATED_AT',
26
- direction: 'DESC',
27
- };
28
- const fetchProduct = async (fetcher, { id, isSample }) => {
29
- const variables = {
30
- orderBy,
31
- where: {
32
- isStorefront: true,
33
- isSample,
34
- ...(id && id.toLowerCase() !== 'latest' && { baseID: id }),
35
- },
36
- };
37
- const response = await fetcher([ProductLittleDetailDocument, variables]);
38
- return response.product?.edges?.[0]?.node;
39
- };
40
- const fetchVariants = async (fetcher, { id, isSample }) => {
41
- const initVariables = {
42
- orderBy,
43
- where: {
44
- isStorefront: true,
45
- isSample,
46
- ...(id && id.toLowerCase() !== 'latest' && { baseID: id }),
47
- },
48
- };
49
- const query = async (variables, olds) => {
50
- try {
51
- const response = await fetcher([
52
- ProductVariantsDocument,
53
- variables,
54
- ]);
55
- const product = response.variants?.edges?.[0];
56
- const items = olds?.concat(product?.node?.variants?.edges ?? []);
57
- if (product?.node?.variants?.pageInfo?.hasNextPage) {
58
- return query({
59
- ...variables,
60
- afterVariant: product?.node?.variants?.pageInfo.endCursor,
61
- }, items);
62
- }
63
- return items ?? [];
64
- }
65
- catch {
66
- return olds ?? [];
67
- }
68
- };
69
- return query(initVariables, []);
70
- };
71
- const fetchMedias = async (fetcher, { id, isSample }) => {
72
- const initVariables = {
73
- orderBy,
74
- where: {
75
- isStorefront: true,
76
- isSample,
77
- ...(id && id.toLowerCase() !== 'latest' && { baseID: id }),
78
- },
79
- orderByMedia: {
80
- field: 'POSITION',
81
- direction: 'ASC',
82
- },
83
- };
84
- const query = async (variables) => {
85
- try {
86
- const response = await fetcher([
87
- ProductMediasDocument,
88
- variables,
89
- ]);
90
- const product = response.medias?.edges?.[0];
91
- const items = product?.node?.medias?.edges ?? [];
92
- if (product?.node?.medias?.pageInfo?.hasNextPage) {
93
- try {
94
- const newData = await query({
95
- ...variables,
96
- afterMedia: product?.node?.medias?.pageInfo.endCursor,
97
- });
98
- return items.concat(newData);
99
- }
100
- catch {
101
- return items;
102
- }
103
- }
104
- return items;
105
- }
106
- catch {
107
- return [];
108
- }
109
- };
110
- return query(initVariables);
5
+ const getProduct = async (fetcher, { id , isSample })=>{
6
+ const [product, variants, medias] = await Promise.all([
7
+ fetchProduct(fetcher, {
8
+ id,
9
+ isSample
10
+ }),
11
+ fetchVariants(fetcher, {
12
+ id,
13
+ isSample
14
+ }),
15
+ fetchMedias(fetcher, {
16
+ id,
17
+ isSample
18
+ })
19
+ ]);
20
+ if (!product) {
21
+ throw new Error('Product not found');
22
+ }
23
+ return {
24
+ ...product,
25
+ variants: {
26
+ edges: variants
27
+ },
28
+ medias: {
29
+ edges: medias
30
+ }
31
+ };
32
+ };
33
+ const orderBy = {
34
+ field: 'UPDATED_AT',
35
+ direction: 'DESC'
36
+ };
37
+ const fetchProduct = async (fetcher, { id , isSample })=>{
38
+ const variables = {
39
+ orderBy,
40
+ where: {
41
+ isStorefront: true,
42
+ isSample,
43
+ ...id && id.toLowerCase() !== 'latest' && {
44
+ baseID: id
45
+ }
46
+ }
47
+ };
48
+ const response = await fetcher([
49
+ ProductLittleDetailDocument,
50
+ variables
51
+ ]);
52
+ return response.product?.edges?.[0]?.node;
53
+ };
54
+ const fetchVariants = async (fetcher, { id , isSample })=>{
55
+ const initVariables = {
56
+ orderBy,
57
+ where: {
58
+ isStorefront: true,
59
+ isSample,
60
+ ...id && id.toLowerCase() !== 'latest' && {
61
+ baseID: id
62
+ }
63
+ }
64
+ };
65
+ const query = async (variables, olds)=>{
66
+ try {
67
+ const response = await fetcher([
68
+ ProductVariantsDocument,
69
+ variables
70
+ ]);
71
+ const product = response.variants?.edges?.[0];
72
+ const items = olds?.concat(product?.node?.variants?.edges ?? []);
73
+ if (product?.node?.variants?.pageInfo?.hasNextPage) {
74
+ return query({
75
+ ...variables,
76
+ afterVariant: product?.node?.variants?.pageInfo.endCursor
77
+ }, items);
78
+ }
79
+ return items ?? [];
80
+ } catch {
81
+ return olds ?? [];
82
+ }
83
+ };
84
+ return query(initVariables, []);
85
+ };
86
+ const fetchMedias = async (fetcher, { id , isSample })=>{
87
+ const initVariables = {
88
+ orderBy,
89
+ where: {
90
+ isStorefront: true,
91
+ isSample,
92
+ ...id && id.toLowerCase() !== 'latest' && {
93
+ baseID: id
94
+ }
95
+ },
96
+ orderByMedia: {
97
+ field: 'POSITION',
98
+ direction: 'ASC'
99
+ }
100
+ };
101
+ const query = async (variables)=>{
102
+ try {
103
+ const response = await fetcher([
104
+ ProductMediasDocument,
105
+ variables
106
+ ]);
107
+ const product = response.medias?.edges?.[0];
108
+ const items = product?.node?.medias?.edges ?? [];
109
+ if (product?.node?.medias?.pageInfo?.hasNextPage) {
110
+ try {
111
+ const newData = await query({
112
+ ...variables,
113
+ afterMedia: product?.node?.medias?.pageInfo.endCursor
114
+ });
115
+ return items.concat(newData);
116
+ } catch {
117
+ return items;
118
+ }
119
+ }
120
+ return items;
121
+ } catch {
122
+ return [];
123
+ }
124
+ };
125
+ return query(initVariables);
111
126
  };
112
127
 
113
128
  export { fetchMedias, fetchVariants, getProduct };