@anker-in/lib 0.0.0-beta.1 → 0.0.0-beta.3

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 (247) hide show
  1. package/.gitkeep +0 -0
  2. package/.turbo/turbo-build.log +22 -0
  3. package/.turbo/turbo-test.log +5 -0
  4. package/dist/cjs/context/HeadlessProvider.js +1 -1
  5. package/dist/cjs/context/HeadlessProvider.js.map +2 -2
  6. package/dist/context/HeadlessProvider.d.ts.map +1 -1
  7. package/dist/esm/cart/const.js +2 -0
  8. package/dist/esm/cart/const.js.map +7 -0
  9. package/dist/esm/cart/hooks/basic/useBuyNow.js +2 -0
  10. package/dist/esm/cart/hooks/basic/useBuyNow.js.map +7 -0
  11. package/dist/esm/cart/index.js +2 -0
  12. package/dist/esm/cart/index.js.map +7 -0
  13. package/dist/esm/cart/track/fbq.js +2 -0
  14. package/dist/esm/cart/track/fbq.js.map +7 -0
  15. package/dist/esm/cart/types/index.js +1 -0
  16. package/dist/esm/cart/types/index.js.map +7 -0
  17. package/dist/esm/cart/utils/index.js +2 -0
  18. package/dist/esm/cart/utils/index.js.map +7 -0
  19. package/dist/esm/context/HeadlessProvider.js +2 -0
  20. package/dist/esm/context/HeadlessProvider.js.map +7 -0
  21. package/dist/esm/context/config.js +1 -0
  22. package/dist/esm/context/config.js.map +7 -0
  23. package/dist/esm/context/index.js +2 -0
  24. package/dist/esm/context/index.js.map +7 -0
  25. package/dist/esm/index.js +2 -0
  26. package/dist/esm/index.js.map +7 -0
  27. package/dist/esm/package.json +3 -0
  28. package/dist/esm/shopify/fetchers/add-cart-lines.js +2 -0
  29. package/dist/esm/shopify/fetchers/add-cart-lines.js.map +7 -0
  30. package/dist/esm/shopify/fetchers/create-cart.js +2 -0
  31. package/dist/esm/shopify/fetchers/create-cart.js.map +7 -0
  32. package/dist/esm/shopify/fetchers/get-cart.js +2 -0
  33. package/dist/esm/shopify/fetchers/get-cart.js.map +7 -0
  34. package/dist/esm/shopify/fetchers/get-products-by-handles.js +2 -0
  35. package/dist/esm/shopify/fetchers/get-products-by-handles.js.map +7 -0
  36. package/dist/esm/shopify/fetchers/index.js +2 -0
  37. package/dist/esm/shopify/fetchers/index.js.map +7 -0
  38. package/dist/esm/shopify/fetchers/remove-cart-lines.js +2 -0
  39. package/dist/esm/shopify/fetchers/remove-cart-lines.js.map +7 -0
  40. package/dist/esm/shopify/fetchers/update-cart-attributes.js +2 -0
  41. package/dist/esm/shopify/fetchers/update-cart-attributes.js.map +7 -0
  42. package/dist/esm/shopify/fetchers/update-cart-buyer-identity.js +2 -0
  43. package/dist/esm/shopify/fetchers/update-cart-buyer-identity.js.map +7 -0
  44. package/dist/esm/shopify/fetchers/update-cart-codes.js +2 -0
  45. package/dist/esm/shopify/fetchers/update-cart-codes.js.map +7 -0
  46. package/dist/esm/shopify/fetchers/update-cart-lines.js +2 -0
  47. package/dist/esm/shopify/fetchers/update-cart-lines.js.map +7 -0
  48. package/dist/esm/shopify/fragments/article.js +50 -0
  49. package/dist/esm/shopify/fragments/article.js.map +7 -0
  50. package/dist/esm/shopify/fragments/blog.js +11 -0
  51. package/dist/esm/shopify/fragments/blog.js.map +7 -0
  52. package/dist/esm/shopify/fragments/cart.js +189 -0
  53. package/dist/esm/shopify/fragments/cart.js.map +7 -0
  54. package/dist/esm/shopify/fragments/collection.js +16 -0
  55. package/dist/esm/shopify/fragments/collection.js.map +7 -0
  56. package/dist/esm/shopify/fragments/image.js +9 -0
  57. package/dist/esm/shopify/fragments/image.js.map +7 -0
  58. package/dist/esm/shopify/fragments/index.js +2 -0
  59. package/dist/esm/shopify/fragments/index.js.map +7 -0
  60. package/dist/esm/shopify/fragments/metafields.js +16 -0
  61. package/dist/esm/shopify/fragments/metafields.js.map +7 -0
  62. package/dist/esm/shopify/fragments/page-info.js +9 -0
  63. package/dist/esm/shopify/fragments/page-info.js.map +7 -0
  64. package/dist/esm/shopify/fragments/page.js +13 -0
  65. package/dist/esm/shopify/fragments/page.js.map +7 -0
  66. package/dist/esm/shopify/fragments/product.js +72 -0
  67. package/dist/esm/shopify/fragments/product.js.map +7 -0
  68. package/dist/esm/shopify/fragments/seo.js +7 -0
  69. package/dist/esm/shopify/fragments/seo.js.map +7 -0
  70. package/dist/esm/shopify/fragments/variant.js +30 -0
  71. package/dist/esm/shopify/fragments/variant.js.map +7 -0
  72. package/dist/esm/shopify/gql/fragment-masking.js +2 -0
  73. package/dist/esm/shopify/gql/fragment-masking.js.map +7 -0
  74. package/dist/esm/shopify/gql/gql.js +2 -0
  75. package/dist/esm/shopify/gql/gql.js.map +7 -0
  76. package/dist/esm/shopify/gql/graphql.js +2 -0
  77. package/dist/esm/shopify/gql/graphql.js.map +7 -0
  78. package/dist/esm/shopify/gql/index.js +2 -0
  79. package/dist/esm/shopify/gql/index.js.map +7 -0
  80. package/dist/esm/shopify/hooks/index.js +2 -0
  81. package/dist/esm/shopify/hooks/index.js.map +7 -0
  82. package/dist/esm/shopify/hooks/useProductsByHandles.js +2 -0
  83. package/dist/esm/shopify/hooks/useProductsByHandles.js.map +7 -0
  84. package/dist/esm/shopify/index.js +2 -0
  85. package/dist/esm/shopify/index.js.map +7 -0
  86. package/dist/esm/shopify/mutations/add-cart-lines.js +15 -0
  87. package/dist/esm/shopify/mutations/add-cart-lines.js.map +7 -0
  88. package/dist/esm/shopify/mutations/create-cart.js +21 -0
  89. package/dist/esm/shopify/mutations/create-cart.js.map +7 -0
  90. package/dist/esm/shopify/mutations/remove-cart-items.js +15 -0
  91. package/dist/esm/shopify/mutations/remove-cart-items.js.map +7 -0
  92. package/dist/esm/shopify/mutations/update-cart-attributes.js +15 -0
  93. package/dist/esm/shopify/mutations/update-cart-attributes.js.map +7 -0
  94. package/dist/esm/shopify/mutations/update-cart-buyer-identity.js +15 -0
  95. package/dist/esm/shopify/mutations/update-cart-buyer-identity.js.map +7 -0
  96. package/dist/esm/shopify/mutations/update-cart-discount-code.js +15 -0
  97. package/dist/esm/shopify/mutations/update-cart-discount-code.js.map +7 -0
  98. package/dist/esm/shopify/mutations/update-cart-items.js +15 -0
  99. package/dist/esm/shopify/mutations/update-cart-items.js.map +7 -0
  100. package/dist/esm/shopify/queries/get-cart.js +13 -0
  101. package/dist/esm/shopify/queries/get-cart.js.map +7 -0
  102. package/dist/esm/shopify/queries/get-product-by-handles.js +29 -0
  103. package/dist/esm/shopify/queries/get-product-by-handles.js.map +7 -0
  104. package/dist/esm/shopify/queries/index.js +2 -0
  105. package/dist/esm/shopify/queries/index.js.map +7 -0
  106. package/dist/esm/shopify/types/article.js +1 -0
  107. package/dist/esm/shopify/types/article.js.map +7 -0
  108. package/dist/esm/shopify/types/cart.js +1 -0
  109. package/dist/esm/shopify/types/cart.js.map +7 -0
  110. package/dist/esm/shopify/types/checkout.js +1 -0
  111. package/dist/esm/shopify/types/checkout.js.map +7 -0
  112. package/dist/esm/shopify/types/collection.js +1 -0
  113. package/dist/esm/shopify/types/collection.js.map +7 -0
  114. package/dist/esm/shopify/types/common.js +1 -0
  115. package/dist/esm/shopify/types/common.js.map +7 -0
  116. package/dist/esm/shopify/types/config.js +1 -0
  117. package/dist/esm/shopify/types/config.js.map +7 -0
  118. package/dist/esm/shopify/types/customer.js +1 -0
  119. package/dist/esm/shopify/types/customer.js.map +7 -0
  120. package/dist/esm/shopify/types/fetcher.js +2 -0
  121. package/dist/esm/shopify/types/fetcher.js.map +7 -0
  122. package/dist/esm/shopify/types/index.js +2 -0
  123. package/dist/esm/shopify/types/index.js.map +7 -0
  124. package/dist/esm/shopify/types/page.js +1 -0
  125. package/dist/esm/shopify/types/page.js.map +7 -0
  126. package/dist/esm/shopify/types/product.js +1 -0
  127. package/dist/esm/shopify/types/product.js.map +7 -0
  128. package/dist/esm/shopify/types/search.js +1 -0
  129. package/dist/esm/shopify/types/search.js.map +7 -0
  130. package/dist/esm/shopify/types/site.js +1 -0
  131. package/dist/esm/shopify/types/site.js.map +7 -0
  132. package/dist/esm/shopify/types/type-helper.js +1 -0
  133. package/dist/esm/shopify/types/type-helper.js.map +7 -0
  134. package/dist/esm/shopify/utils/colors.js +2 -0
  135. package/dist/esm/shopify/utils/colors.js.map +7 -0
  136. package/dist/esm/shopify/utils/const.js +2 -0
  137. package/dist/esm/shopify/utils/const.js.map +7 -0
  138. package/dist/esm/shopify/utils/cookie.js +2 -0
  139. package/dist/esm/shopify/utils/cookie.js.map +7 -0
  140. package/dist/esm/shopify/utils/errors.js +3 -0
  141. package/dist/esm/shopify/utils/errors.js.map +7 -0
  142. package/dist/esm/shopify/utils/fetch-graphql-api.js +3 -0
  143. package/dist/esm/shopify/utils/fetch-graphql-api.js.map +7 -0
  144. package/dist/esm/shopify/utils/handle-fetch-response.js +2 -0
  145. package/dist/esm/shopify/utils/handle-fetch-response.js.map +7 -0
  146. package/dist/esm/shopify/utils/helper.js +2 -0
  147. package/dist/esm/shopify/utils/helper.js.map +7 -0
  148. package/dist/esm/shopify/utils/normalize/cart.js +2 -0
  149. package/dist/esm/shopify/utils/normalize/cart.js.map +7 -0
  150. package/dist/esm/shopify/utils/normalize/customer.js +2 -0
  151. package/dist/esm/shopify/utils/normalize/customer.js.map +7 -0
  152. package/dist/esm/shopify/utils/normalize/index.js +2 -0
  153. package/dist/esm/shopify/utils/normalize/index.js.map +7 -0
  154. package/dist/esm/shopify/utils/normalize/metafield.js +2 -0
  155. package/dist/esm/shopify/utils/normalize/metafield.js.map +7 -0
  156. package/dist/esm/shopify/utils/normalize/product.js +2 -0
  157. package/dist/esm/shopify/utils/normalize/product.js.map +7 -0
  158. package/dist/esm/shopify/utils/store.js +2 -0
  159. package/dist/esm/shopify/utils/store.js.map +7 -0
  160. package/dist/esm/shopify/utils/type-helper.js +1 -0
  161. package/dist/esm/shopify/utils/type-helper.js.map +7 -0
  162. package/esbuild-cjs.mjs +23 -0
  163. package/esbuild-esm.mjs +30 -0
  164. package/jest.config.ts +12 -0
  165. package/package.json +10 -15
  166. package/src/cart/const.ts +23 -0
  167. package/src/cart/hooks/basic/useBuyNow.ts +105 -0
  168. package/src/cart/index.ts +19 -0
  169. package/src/cart/track/fbq.ts +63 -0
  170. package/src/cart/types/index.ts +25 -0
  171. package/src/cart/utils/index.ts +22 -0
  172. package/src/context/HeadlessProvider.tsx +30 -0
  173. package/src/context/config.ts +10 -0
  174. package/src/context/index.ts +3 -0
  175. package/src/index.ts +22 -0
  176. package/src/shopify/fetchers/add-cart-lines.ts +53 -0
  177. package/src/shopify/fetchers/create-cart.ts +43 -0
  178. package/src/shopify/fetchers/get-cart.ts +48 -0
  179. package/src/shopify/fetchers/get-products-by-handles.ts +48 -0
  180. package/src/shopify/fetchers/index.ts +10 -0
  181. package/src/shopify/fetchers/remove-cart-lines.ts +31 -0
  182. package/src/shopify/fetchers/update-cart-attributes.ts +29 -0
  183. package/src/shopify/fetchers/update-cart-buyer-identity.ts +32 -0
  184. package/src/shopify/fetchers/update-cart-codes.ts +32 -0
  185. package/src/shopify/fetchers/update-cart-lines.ts +42 -0
  186. package/src/shopify/fragments/article.ts +51 -0
  187. package/src/shopify/fragments/blog.ts +10 -0
  188. package/src/shopify/fragments/cart.ts +193 -0
  189. package/src/shopify/fragments/collection.ts +15 -0
  190. package/src/shopify/fragments/image.ts +8 -0
  191. package/src/shopify/fragments/index.ts +11 -0
  192. package/src/shopify/fragments/metafields.ts +17 -0
  193. package/src/shopify/fragments/page-info.ts +8 -0
  194. package/src/shopify/fragments/page.ts +12 -0
  195. package/src/shopify/fragments/product.ts +71 -0
  196. package/src/shopify/fragments/seo.ts +6 -0
  197. package/src/shopify/fragments/variant.ts +29 -0
  198. package/src/shopify/gql/fragment-masking.ts +85 -0
  199. package/src/shopify/gql/gql.ts +110 -0
  200. package/src/shopify/gql/graphql.ts +11780 -0
  201. package/src/shopify/gql/index.ts +4 -0
  202. package/src/shopify/hooks/index.ts +1 -0
  203. package/src/shopify/hooks/useProductsByHandles.ts +24 -0
  204. package/src/shopify/index.ts +5 -0
  205. package/src/shopify/mutations/add-cart-lines.ts +16 -0
  206. package/src/shopify/mutations/create-cart.ts +22 -0
  207. package/src/shopify/mutations/remove-cart-items.ts +16 -0
  208. package/src/shopify/mutations/update-cart-attributes.ts +16 -0
  209. package/src/shopify/mutations/update-cart-buyer-identity.ts +16 -0
  210. package/src/shopify/mutations/update-cart-discount-code.ts +16 -0
  211. package/src/shopify/mutations/update-cart-items.ts +16 -0
  212. package/src/shopify/queries/get-cart.ts +14 -0
  213. package/src/shopify/queries/get-product-by-handles.ts +32 -0
  214. package/src/shopify/queries/index.ts +2 -0
  215. package/src/shopify/types/article.ts +46 -0
  216. package/src/shopify/types/cart.ts +204 -0
  217. package/src/shopify/types/checkout.ts +44 -0
  218. package/src/shopify/types/collection.ts +104 -0
  219. package/src/shopify/types/common.ts +53 -0
  220. package/src/shopify/types/config.ts +14 -0
  221. package/src/shopify/types/customer.ts +31 -0
  222. package/src/shopify/types/fetcher.ts +67 -0
  223. package/src/shopify/types/index.ts +11 -0
  224. package/src/shopify/types/page.ts +45 -0
  225. package/src/shopify/types/product.ts +176 -0
  226. package/src/shopify/types/search.ts +62 -0
  227. package/src/shopify/types/site.ts +38 -0
  228. package/src/shopify/types/type-helper.ts +5 -0
  229. package/src/shopify/utils/colors.ts +206 -0
  230. package/src/shopify/utils/const.ts +115 -0
  231. package/src/shopify/utils/cookie.ts +28 -0
  232. package/src/shopify/utils/errors.ts +65 -0
  233. package/src/shopify/utils/fetch-graphql-api.ts +67 -0
  234. package/src/shopify/utils/handle-fetch-response.ts +60 -0
  235. package/src/shopify/utils/helper.ts +89 -0
  236. package/src/shopify/utils/normalize/cart.ts +106 -0
  237. package/src/shopify/utils/normalize/customer.ts +18 -0
  238. package/src/shopify/utils/normalize/index.ts +2 -0
  239. package/src/shopify/utils/normalize/metafield.ts +69 -0
  240. package/src/shopify/utils/normalize/product.ts +193 -0
  241. package/src/shopify/utils/store.ts +5 -0
  242. package/src/shopify/utils/type-helper.ts +7 -0
  243. package/tsconfig.json +20 -0
  244. package/tsup.config.ts +17 -0
  245. package/dist/index.esm.js +0 -1669
  246. package/dist/index.js +0 -1679
  247. package/dist/index.mjs +0 -1669
@@ -0,0 +1,31 @@
1
+ export interface GetCustomerQueryResponse {}
2
+
3
+ export type CustomerAddress = {
4
+ id: string
5
+ firstName: string
6
+ lastName: string
7
+ address1: string
8
+ address2: string
9
+ city: string
10
+ province: string
11
+ provinceCode: string
12
+ countryCodeV2: string
13
+ phone: string
14
+ zip: string
15
+ }
16
+
17
+ export type Customer = {
18
+ id: string
19
+ firstName?: string
20
+ lastName?: string
21
+ displayName?: string
22
+ email: string
23
+ phone?: string
24
+ tags?: string[]
25
+ acceptsMarketing?: boolean
26
+ createdAt?: string
27
+ orders: {
28
+ id: string
29
+ }[]
30
+ defaultAddress?: CustomerAddress
31
+ }
@@ -0,0 +1,67 @@
1
+ import { HasMetafieldsIdentifier } from '../gql'
2
+ import { PartialRecord } from './type-helper'
3
+ import { SWRMutationResponse } from 'swr/mutation'
4
+ import { ShopifyConfig } from './config'
5
+
6
+ type RequestBasicParams = {
7
+ query?: string
8
+ config: ShopifyConfig
9
+ }
10
+
11
+ export enum HasMetafieldQueryRoot {
12
+ Product = 'product',
13
+ Variant = 'variant',
14
+ Page = 'page',
15
+ Article = 'article',
16
+ Blog = 'blog',
17
+ Collection = 'collection',
18
+ Shop = 'shop',
19
+ Cart = 'product | variant',
20
+ Customer = 'customer',
21
+ Location = 'location',
22
+ Market = 'market',
23
+ Order = 'order',
24
+ }
25
+
26
+ export type ConstructMetafieldIdentifiersQueryInput<Roots extends HasMetafieldQueryRoot> = Partial<
27
+ Record<Roots, HasMetafieldsIdentifier[]>
28
+ >
29
+ export type metafieldIdentifiersGroup<M extends HasMetafieldQueryRoot> = {
30
+ metafieldIdentifiers?: PartialRecord<
31
+ M,
32
+ HasMetafieldsIdentifier[] // MetafieldIdentifiers[]
33
+ >
34
+ comboMetafieldsNamespace?: string
35
+ }
36
+
37
+ type RequestWithOptions<T, M extends HasMetafieldQueryRoot> = RequestBasicParams & {
38
+ options: T & metafieldIdentifiersGroup<M>
39
+ }
40
+
41
+ export type ShopifyFetcherVariables<T, M extends HasMetafieldQueryRoot> = M extends HasMetafieldQueryRoot
42
+ ? T & PartialRecord<`${M}MetafieldIdentifiers`, HasMetafieldsIdentifier[]>
43
+ : T
44
+
45
+ // Shopify Fetcher 工具类,新增除请求参数外统一的 shopify config(店铺域名, storefront token) 和 metafields 相关参数
46
+ export type ShopifyFetcher<
47
+ Data = Record<string, any>,
48
+ Req = undefined,
49
+ Metafields extends HasMetafieldQueryRoot = HasMetafieldQueryRoot,
50
+ > = (
51
+ req: Req extends Record<string, any>
52
+ ? RequestWithOptions<Req, Metafields> & { config: ShopifyConfig }
53
+ : RequestBasicParams & { config: ShopifyConfig }
54
+ ) => Promise<Data>
55
+
56
+ export type ShopifyHookOptions<T, M extends HasMetafieldQueryRoot> = {
57
+ locale?: string
58
+ query?: string
59
+ metafieldIdentifiers?: PartialRecord<
60
+ M,
61
+ HasMetafieldsIdentifier[] // MetafieldIdentifiers[]
62
+ >
63
+ } & T
64
+
65
+ export type ShopifyMutationHook<Req, Metafields extends HasMetafieldQueryRoot> = (
66
+ options: ShopifyHookOptions<Req, Metafields>
67
+ ) => SWRMutationResponse
@@ -0,0 +1,11 @@
1
+ export * from './common'
2
+ export * from './cart'
3
+ export * from './checkout'
4
+ export * from './page'
5
+ export * from './product'
6
+ export * from './site'
7
+ export * from './collection'
8
+ export * from './search'
9
+ export * from './article'
10
+ export * from './customer'
11
+ export * from './config'
@@ -0,0 +1,45 @@
1
+ // TODO: define this type
2
+ export type Page = {
3
+ // ID of the Web page.
4
+ id: string
5
+ // handle of page
6
+ handle: string
7
+ // Page name, as displayed on the storefront.
8
+ name: string
9
+ // Relative URL on the storefront for this page.
10
+ path?: string
11
+ // HTML or variable that populates this page’s `<body>` element, in default/desktop view. Required in POST if page type is `raw`.
12
+ body: string
13
+ // If true, this page appears in the storefront’s navigation menu.
14
+ is_visible?: boolean
15
+ // Order in which this page should display on the storefront. (Lower integers specify earlier display.)
16
+ sort_order?: number
17
+
18
+ url?: string
19
+
20
+ seo?: any
21
+
22
+ metafields?: {
23
+ [key: string]: any
24
+ }
25
+ }
26
+
27
+ export type PageTypes = {
28
+ page: Page
29
+ }
30
+
31
+ export type GetAllPagesOperation<T extends PageTypes = PageTypes> = {
32
+ data: {
33
+ pages: T['page'][]
34
+ }
35
+ }
36
+
37
+ export type GetPageOperation<T extends PageTypes = PageTypes> = {
38
+ data: {
39
+ page?: T['page']
40
+ metafields?: {
41
+ [key: string]: any
42
+ }
43
+ }
44
+ variables: { id: string }
45
+ }
@@ -0,0 +1,176 @@
1
+ import { Media, Product as ShopifyProduct } from '../gql'
2
+
3
+ import { SearchHook } from './search'
4
+
5
+ export type ProductImage = {
6
+ url: string
7
+ alt?: string
8
+ }
9
+
10
+ export type ProductPrice = {
11
+ amount: number
12
+ currencyCode?: 'USD' | 'EUR' | 'ARS' | string
13
+ retailPrice?: number
14
+ salePrice?: number
15
+ listPrice?: number
16
+ extendedSalePrice?: number
17
+ extendedListPrice?: number
18
+ }
19
+
20
+ export type ProductOption = {
21
+ __typename?: 'ProductOption'
22
+ id: string
23
+ name: string
24
+ values: ProductOptionValues[]
25
+ }
26
+
27
+ export type ProductOptionValues = {
28
+ label: string
29
+ hexColors?: string[]
30
+ }
31
+
32
+ export type ProductVariant = {
33
+ id: string | number
34
+ options: ProductOption[]
35
+ availableForSale?: boolean
36
+ quantityAvailable: number
37
+ metafields?: Record<string, any>
38
+ [key: string]: any
39
+ }
40
+
41
+ type NormalizedProduct = {
42
+ id: string
43
+ description: string
44
+ descriptionHtml?: string
45
+ productType?: string
46
+ sku?: string
47
+ slug?: string
48
+ handle?: string
49
+ path?: string
50
+ images: ProductImage[]
51
+ media: ProductMedia[]
52
+ variants: ProductVariant[]
53
+ price: ProductPrice
54
+ listPrice?: number
55
+ options: ProductOption[]
56
+ preRender?: string
57
+ seo?: any
58
+ metafields?: { [key: string]: any }
59
+ }
60
+
61
+ export type Product = Omit<ShopifyProduct, keyof NormalizedProduct> & NormalizedProduct
62
+
63
+ export type GetProductBody = {
64
+ handles: string
65
+ locale?: string
66
+ }
67
+
68
+ export type ProductTypes = {
69
+ product: Product
70
+ getBody: GetProductBody
71
+ }
72
+
73
+ export type GetProductHook<T extends ProductTypes = ProductTypes> = {
74
+ data: {
75
+ products: (T['product'] | {})[] | []
76
+ }
77
+ body: T['getBody']
78
+ input: T['getBody']
79
+ fetcherInput: T['getBody']
80
+ }
81
+
82
+ export type ProductsSchema<T extends ProductTypes = ProductTypes> = {
83
+ endpoint: {
84
+ options: {}
85
+ handlers: {
86
+ getProducts: SearchHook
87
+ getProduct: GetProductHook<T>
88
+ }
89
+ }
90
+ }
91
+
92
+ export type GetAllProductPathsOperation<T extends ProductTypes = ProductTypes> = {
93
+ data: { products: Pick<T['product'], 'path'>[] }
94
+ variables: { first?: number }
95
+ }
96
+
97
+ export type GetAllProductsOperation<T extends ProductTypes = ProductTypes> = {
98
+ data: { products: T['product'][] }
99
+ variables: {
100
+ relevance?: 'featured' | 'best_selling' | 'newest'
101
+ ids?: string[]
102
+ first?: number
103
+ }
104
+ }
105
+
106
+ export type GetProductOperation<T extends ProductTypes = ProductTypes> = {
107
+ data: { product?: T['product'] }
108
+ variables: { path: string; slug?: never } | { path?: never; slug: string }
109
+ }
110
+
111
+ export type Options = Record<string, string>
112
+
113
+ export type ProductCoupon = {
114
+ sku: string
115
+ variant_shopify_id: number
116
+ variant_price: string
117
+ handle: string
118
+ product_type: string
119
+ product_title: string
120
+ product_shopify_id: number
121
+ title: string
122
+ starts_at: string
123
+ ends_at?: string
124
+ value_type: string
125
+ value: string
126
+ shopify_domain: string
127
+ currency: string
128
+ custom_domain: string
129
+ shop_discount_threshold_value: number
130
+ fixed_value: string
131
+ value_style: string
132
+ variant_price4wscode: number
133
+ variant_image: string
134
+ currency_symbol: string
135
+ fixed_amount_sort_key: number
136
+ percentage_sort_key: number
137
+ variant_url: string
138
+ variant_metafields: any[]
139
+ product_tags: string
140
+ product_metafields: any[]
141
+ available_for_sale: boolean
142
+ shopify_created_at: string
143
+ shopify_updated_at: string
144
+ timezone: string
145
+ starts_at_with_timezone: string
146
+ ends_at_with_timezone?: string
147
+ amazon_deal: boolean
148
+ }
149
+
150
+ export type VariantCoupon = {
151
+ title: string
152
+ starts_at: string // ISO 8601 日期字符串
153
+ ends_at: string | null // ISO 8601 日期字符串或 null
154
+ variant_shopify_id: number
155
+ value_type: 'percentage' | 'fixed' | 'fixed_amount' | 'fix_discount_amount' // 假设 value_type 只有 'percentage' 和 'fixed' 两种可能值
156
+ value: string // 负数的百分比值
157
+ currency: string
158
+ fixed_value: string // 固定值
159
+ value_style: string // 带有货币符号的值
160
+ variant_price4wscode: number // 折后价
161
+ discount_type: string // 假设 discount_type 是一个字符串
162
+ amazon_deal: boolean
163
+ cdi_id: number
164
+ cdi_updated_at: string // ISO 8601 日期字符串
165
+ }
166
+
167
+ export type ProductMedia = Media & {
168
+ sources?: {
169
+ url: string
170
+ altText: string
171
+ }[]
172
+ image?: {
173
+ url: string
174
+ altText: string
175
+ }
176
+ }
@@ -0,0 +1,62 @@
1
+ import type { ProductTypes } from './product'
2
+ import type { PageTypes } from './page'
3
+
4
+ export type SearchBody = {
5
+ first?: number
6
+ after?: string
7
+ before?: string
8
+ reverse?: boolean
9
+ sort?: string
10
+ sku?: string
11
+ query?: string
12
+ search?: string
13
+ sortKey?: string
14
+ filters?: any
15
+ productFilters?: any
16
+ categoryId?: string | number
17
+ brandId?: string | number
18
+ termSearch?: string
19
+ types?: string[]
20
+ }
21
+
22
+ export type SearchProductsInput = {
23
+ after?: string
24
+ before?: string
25
+ sortKey?: string
26
+ locale?: string
27
+ first?: number
28
+ last?: number
29
+ types?: string[]
30
+ filters?: any
31
+ productFilters?: any
32
+ reverse?: boolean
33
+ searchTerm?: string
34
+ }
35
+
36
+ export type ShopifySearchOperation = {
37
+ data:
38
+ | {
39
+ products: ProductTypes['product'][]
40
+ found: boolean
41
+ }
42
+ | {
43
+ pages: PageTypes['page'][]
44
+ products: ProductTypes['product'][]
45
+ }
46
+ variables: SearchBody
47
+ }
48
+
49
+ export type SearchHook = {
50
+ data:
51
+ | {
52
+ products: ProductTypes['product'][]
53
+ found: boolean
54
+ }
55
+ | {
56
+ pages: PageTypes['page'][]
57
+ products: ProductTypes['product'][]
58
+ }
59
+ body: SearchBody
60
+ input: SearchBody
61
+ fetcherInput: SearchBody
62
+ }
@@ -0,0 +1,38 @@
1
+ import { Category } from './collection'
2
+
3
+ export type Brand = any
4
+
5
+ export type Policy = {
6
+ handle: string
7
+ id: string
8
+ title: string
9
+ body?: string
10
+ url?: string
11
+ }
12
+
13
+ export type Shop = {
14
+ name: string
15
+ privacyPolicy: Policy
16
+ refundPolicy: Policy
17
+ shippingPolicy: Policy
18
+ termsOfService: Policy
19
+ subscriptionPolicy: Policy
20
+ }
21
+
22
+ export type SiteTypes = {
23
+ shop: Shop
24
+ category: Category
25
+ brand: Brand
26
+ }
27
+
28
+ export type GetSiteInfoOperation<T extends SiteTypes = SiteTypes> = {
29
+ data: {
30
+ shop: Shop
31
+ categories: T['category'][]
32
+ brands: T['brand'][]
33
+ shopName?: string
34
+ metafields?: {
35
+ [key: string]: any
36
+ }
37
+ }
38
+ }
@@ -0,0 +1,5 @@
1
+ export type PartialRecord<K extends string | number | symbol, T> = Partial<Record<K, T>>
2
+
3
+ export type Optional<T, K extends keyof T> = Pick<Partial<T>, K> & Omit<T, K>
4
+
5
+ export type Replace<T, K extends keyof T, V> = Omit<T, K> & { [P in K]: V }
@@ -0,0 +1,206 @@
1
+ import random from 'lodash.random'
2
+
3
+ export function getRandomPairOfColors() {
4
+ const colors = ['#37B679', '#DA3C3C', '#3291FF', '#7928CA', '#79FFE1']
5
+ const getRandomIdx = () => random(0, colors.length - 1)
6
+ let idx = getRandomIdx()
7
+ let idx2 = getRandomIdx()
8
+
9
+ // Has to be a different color
10
+ while (idx2 === idx) {
11
+ idx2 = getRandomIdx()
12
+ }
13
+
14
+ // Returns a pair of colors
15
+ return [colors[idx], colors[idx2]]
16
+ }
17
+
18
+ function hexToRgb(hex: string = '') {
19
+ // @ts-ignore
20
+ const match = hex.toString(16).match(/[a-f0-9]{6}|[a-f0-9]{3}/i)
21
+
22
+ if (!match) {
23
+ return [0, 0, 0]
24
+ }
25
+
26
+ let colorString = match[0]
27
+
28
+ if (match[0].length === 3) {
29
+ colorString = colorString
30
+ .split('')
31
+ .map((char: string) => {
32
+ return char + char
33
+ })
34
+ .join('')
35
+ }
36
+
37
+ const integer = parseInt(colorString, 16)
38
+ const r = (integer >> 16) & 0xff
39
+ const g = (integer >> 8) & 0xff
40
+ const b = integer & 0xff
41
+
42
+ return [r, g, b]
43
+ }
44
+
45
+ export const colorMap: Record<string, string> = {
46
+ aliceblue: '#F0F8FF',
47
+ antiquewhite: '#FAEBD7',
48
+ aqua: '#00FFFF',
49
+ aquamarine: '#7FFFD4',
50
+ azure: '#F0FFFF',
51
+ beige: '#F5F5DC',
52
+ bisque: '#FFE4C4',
53
+ black: '#000000',
54
+ blanchedalmond: '#FFEBCD',
55
+ blue: '#0000FF',
56
+ blueviolet: '#8A2BE2',
57
+ brown: '#A52A2A',
58
+ burlywood: '#DEB887',
59
+ burgandy: '#800020',
60
+ burgundy: '#800020',
61
+ cadetblue: '#5F9EA0',
62
+ chartreuse: '#7FFF00',
63
+ chocolate: '#D2691E',
64
+ coral: '#FF7F50',
65
+ cornflowerblue: '#6495ED',
66
+ cornsilk: '#FFF8DC',
67
+ crimson: '#DC143C',
68
+ cyan: '#00FFFF',
69
+ darkblue: '#00008B',
70
+ darkcyan: '#008B8B',
71
+ darkgoldenrod: '#B8860B',
72
+ darkgray: '#A9A9A9',
73
+ darkgreen: '#006400',
74
+ darkgrey: '#A9A9A9',
75
+ darkkhaki: '#BDB76B',
76
+ darkmagenta: '#8B008B',
77
+ darkolivegreen: '#556B2F',
78
+ darkorange: '#FF8C00',
79
+ darkorchid: '#9932CC',
80
+ darkred: '#8B0000',
81
+ darksalmon: '#E9967A',
82
+ darkseagreen: '#8FBC8F',
83
+ darkslateblue: '#483D8B',
84
+ darkslategray: '#2F4F4F',
85
+ darkslategrey: '#2F4F4F',
86
+ darkturquoise: '#00CED1',
87
+ darkviolet: '#9400D3',
88
+ deeppink: '#FF1493',
89
+ deepskyblue: '#00BFFF',
90
+ dimgray: '#696969',
91
+ dimgrey: '#696969',
92
+ dodgerblue: '#1E90FF',
93
+ firebrick: '#B22222',
94
+ floralwhite: '#FFFAF0',
95
+ forestgreen: '#228B22',
96
+ fuchsia: '#FF00FF',
97
+ gainsboro: '#DCDCDC',
98
+ ghostwhite: '#F8F8FF',
99
+ gold: '#FFD700',
100
+ goldenrod: '#DAA520',
101
+ gray: '#808080',
102
+ green: '#008000',
103
+ greenyellow: '#ADFF2F',
104
+ grey: '#808080',
105
+ honeydew: '#F0FFF0',
106
+ hotpink: '#FF69B4',
107
+ indianred: '#CD5C5C',
108
+ indigo: '#4B0082',
109
+ ivory: '#FFFFF0',
110
+ khaki: '#F0E68C',
111
+ lavender: '#E6E6FA',
112
+ lavenderblush: '#FFF0F5',
113
+ lawngreen: '#7CFC00',
114
+ lemonchiffon: '#FFFACD',
115
+ lightblue: '#ADD8E6',
116
+ lightcoral: '#F08080',
117
+ lightcyan: '#E0FFFF',
118
+ lightgoldenrodyellow: '#FAFAD2',
119
+ lightgray: '#D3D3D3',
120
+ lightgreen: '#90EE90',
121
+ lightgrey: '#D3D3D3',
122
+ lightpink: '#FFB6C1',
123
+ lightsalmon: '#FFA07A',
124
+ lightseagreen: '#20B2AA',
125
+ lightskyblue: '#87CEFA',
126
+ lightslategray: '#778899',
127
+ lightslategrey: '#778899',
128
+ lightsteelblue: '#B0C4DE',
129
+ lightyellow: '#FFFFE0',
130
+ lime: '#00FF00',
131
+ limegreen: '#32CD32',
132
+ linen: '#FAF0E6',
133
+ magenta: '#FF00FF',
134
+ maroon: '#800000',
135
+ mediumaquamarine: '#66CDAA',
136
+ mediumblue: '#0000CD',
137
+ mediumorchid: '#BA55D3',
138
+ mediumpurple: '#9370DB',
139
+ mediumseagreen: '#3CB371',
140
+ mediumslateblue: '#7B68EE',
141
+ mediumspringgreen: '#00FA9A',
142
+ mediumturquoise: '#48D1CC',
143
+ mediumvioletred: '#C71585',
144
+ midnightblue: '#191970',
145
+ mintcream: '#F5FFFA',
146
+ mistyrose: '#FFE4E1',
147
+ moccasin: '#FFE4B5',
148
+ navajowhite: '#FFDEAD',
149
+ navy: '#000080',
150
+ oldlace: '#FDF5E6',
151
+ olive: '#808000',
152
+ olivedrab: '#6B8E23',
153
+ orange: '#FFA500',
154
+ orangered: '#FF4500',
155
+ orchid: '#DA70D6',
156
+ palegoldenrod: '#EEE8AA',
157
+ palegreen: '#98FB98',
158
+ paleturquoise: '#AFEEEE',
159
+ palevioletred: '#DB7093',
160
+ papayawhip: '#FFEFD5',
161
+ peachpuff: '#FFDAB9',
162
+ peru: '#CD853F',
163
+ pink: '#FFC0CB',
164
+ plum: '#DDA0DD',
165
+ powderblue: '#B0E0E6',
166
+ purple: '#800080',
167
+ rebeccapurple: '#663399',
168
+ red: '#FF0000',
169
+ rosybrown: '#BC8F8F',
170
+ royalblue: '#4169E1',
171
+ saddlebrown: '#8B4513',
172
+ salmon: '#FA8072',
173
+ sandybrown: '#F4A460',
174
+ seagreen: '#2E8B57',
175
+ seashell: '#FFF5EE',
176
+ sienna: '#A0522D',
177
+ silver: '#C0C0C0',
178
+ skyblue: '#87CEEB',
179
+ slateblue: '#6A5ACD',
180
+ slategray: '#708090',
181
+ slategrey: '#708090',
182
+ spacegrey: '#65737e',
183
+ spacegray: '#65737e',
184
+ snow: '#FFFAFA',
185
+ springgreen: '#00FF7F',
186
+ steelblue: '#4682B4',
187
+ tan: '#D2B48C',
188
+ teal: '#008080',
189
+ thistle: '#D8BFD8',
190
+ tomato: '#FF6347',
191
+ turquoise: '#40E0D0',
192
+ violet: '#EE82EE',
193
+ wheat: '#F5DEB3',
194
+ white: '#FFFFFF',
195
+ whitesmoke: '#F5F5F5',
196
+ yellow: '#FFFF00',
197
+ yellowgreen: '#9ACD32',
198
+ }
199
+
200
+ export function isDark(color: string = ''): boolean {
201
+ color = color.toLowerCase()
202
+ // Equation from http://24ways.org/2010/calculating-color-contrast
203
+ let rgb = colorMap[color] ? hexToRgb(colorMap[color]) : hexToRgb(color)
204
+ const res = (rgb[0] * 299 + rgb[1] * 587 + rgb[2] * 114) / 1000
205
+ return res < 128
206
+ }