@scayle/storefront-core 7.22.1

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 (268) hide show
  1. package/CHANGELOG.md +480 -0
  2. package/LICENSE +21 -0
  3. package/README.md +29 -0
  4. package/dist/bapi/init.cjs +30 -0
  5. package/dist/bapi/init.d.ts +14 -0
  6. package/dist/bapi/init.mjs +23 -0
  7. package/dist/cache/cache.cjs +1 -0
  8. package/dist/cache/cache.d.ts +8 -0
  9. package/dist/cache/cache.mjs +0 -0
  10. package/dist/cache/cached.cjs +89 -0
  11. package/dist/cache/cached.d.ts +24 -0
  12. package/dist/cache/cached.mjs +92 -0
  13. package/dist/cache/index.cjs +38 -0
  14. package/dist/cache/index.d.ts +3 -0
  15. package/dist/cache/index.mjs +3 -0
  16. package/dist/cache/providers/redis.cjs +94 -0
  17. package/dist/cache/providers/redis.d.ts +28 -0
  18. package/dist/cache/providers/redis.mjs +86 -0
  19. package/dist/cache/providers/unstorage.cjs +54 -0
  20. package/dist/cache/providers/unstorage.d.ts +16 -0
  21. package/dist/cache/providers/unstorage.mjs +49 -0
  22. package/dist/cache/types.cjs +11 -0
  23. package/dist/cache/types.d.ts +6 -0
  24. package/dist/cache/types.mjs +4 -0
  25. package/dist/constants/basket.cjs +13 -0
  26. package/dist/constants/basket.d.ts +8 -0
  27. package/dist/constants/basket.mjs +6 -0
  28. package/dist/constants/cache.cjs +8 -0
  29. package/dist/constants/cache.d.ts +1 -0
  30. package/dist/constants/cache.mjs +1 -0
  31. package/dist/constants/hash.cjs +11 -0
  32. package/dist/constants/hash.d.ts +6 -0
  33. package/dist/constants/hash.mjs +4 -0
  34. package/dist/constants/httpStatus.cjs +636 -0
  35. package/dist/constants/httpStatus.d.ts +632 -0
  36. package/dist/constants/httpStatus.mjs +629 -0
  37. package/dist/constants/index.cjs +93 -0
  38. package/dist/constants/index.d.ts +8 -0
  39. package/dist/constants/index.mjs +8 -0
  40. package/dist/constants/product.cjs +11 -0
  41. package/dist/constants/product.d.ts +6 -0
  42. package/dist/constants/product.mjs +4 -0
  43. package/dist/constants/promotion.cjs +10 -0
  44. package/dist/constants/promotion.d.ts +2 -0
  45. package/dist/constants/promotion.mjs +2 -0
  46. package/dist/constants/sorting.cjs +24 -0
  47. package/dist/constants/sorting.d.ts +20 -0
  48. package/dist/constants/sorting.mjs +17 -0
  49. package/dist/constants/withParameters.cjs +138 -0
  50. package/dist/constants/withParameters.d.ts +30 -0
  51. package/dist/constants/withParameters.mjs +132 -0
  52. package/dist/errors/BAPIError.cjs +16 -0
  53. package/dist/errors/BAPIError.d.ts +6 -0
  54. package/dist/errors/BAPIError.mjs +9 -0
  55. package/dist/errors/baseError.cjs +17 -0
  56. package/dist/errors/baseError.d.ts +5 -0
  57. package/dist/errors/baseError.mjs +10 -0
  58. package/dist/errors/index.cjs +27 -0
  59. package/dist/errors/index.d.ts +2 -0
  60. package/dist/errors/index.mjs +2 -0
  61. package/dist/helpers/advancedAttributeHelpers.cjs +26 -0
  62. package/dist/helpers/advancedAttributeHelpers.d.ts +12 -0
  63. package/dist/helpers/advancedAttributeHelpers.mjs +21 -0
  64. package/dist/helpers/arrayHelpers.cjs +10 -0
  65. package/dist/helpers/arrayHelpers.d.ts +1 -0
  66. package/dist/helpers/arrayHelpers.mjs +3 -0
  67. package/dist/helpers/attributeHelpers.cjs +24 -0
  68. package/dist/helpers/attributeHelpers.d.ts +5 -0
  69. package/dist/helpers/attributeHelpers.mjs +17 -0
  70. package/dist/helpers/autobind.cjs +44 -0
  71. package/dist/helpers/autobind.d.ts +39 -0
  72. package/dist/helpers/autobind.mjs +35 -0
  73. package/dist/helpers/basketHelpers.cjs +12 -0
  74. package/dist/helpers/basketHelpers.d.ts +2 -0
  75. package/dist/helpers/basketHelpers.mjs +5 -0
  76. package/dist/helpers/categoryHelper.cjs +61 -0
  77. package/dist/helpers/categoryHelper.d.ts +7 -0
  78. package/dist/helpers/categoryHelper.mjs +44 -0
  79. package/dist/helpers/filterHelper.cjs +156 -0
  80. package/dist/helpers/filterHelper.d.ts +82 -0
  81. package/dist/helpers/filterHelper.mjs +147 -0
  82. package/dist/helpers/formHelpers.cjs +114 -0
  83. package/dist/helpers/formHelpers.d.ts +48 -0
  84. package/dist/helpers/formHelpers.mjs +106 -0
  85. package/dist/helpers/imageHelpers.cjs +20 -0
  86. package/dist/helpers/imageHelpers.d.ts +4 -0
  87. package/dist/helpers/imageHelpers.mjs +14 -0
  88. package/dist/helpers/index.cjs +192 -0
  89. package/dist/helpers/index.d.ts +17 -0
  90. package/dist/helpers/index.mjs +17 -0
  91. package/dist/helpers/localization.cjs +13 -0
  92. package/dist/helpers/localization.d.ts +7 -0
  93. package/dist/helpers/localization.mjs +6 -0
  94. package/dist/helpers/objectHelpers.cjs +19 -0
  95. package/dist/helpers/objectHelpers.d.ts +1 -0
  96. package/dist/helpers/objectHelpers.mjs +6 -0
  97. package/dist/helpers/orderHelpers.cjs +10 -0
  98. package/dist/helpers/orderHelpers.d.ts +67 -0
  99. package/dist/helpers/orderHelpers.mjs +4 -0
  100. package/dist/helpers/product.fixture.cjs +770 -0
  101. package/dist/helpers/product.fixture.d.ts +415 -0
  102. package/dist/helpers/product.fixture.mjs +838 -0
  103. package/dist/helpers/productDisruptorHelper.cjs +37 -0
  104. package/dist/helpers/productDisruptorHelper.d.ts +10 -0
  105. package/dist/helpers/productDisruptorHelper.mjs +23 -0
  106. package/dist/helpers/productHelpers.cjs +188 -0
  107. package/dist/helpers/productHelpers.d.ts +41 -0
  108. package/dist/helpers/productHelpers.mjs +170 -0
  109. package/dist/helpers/sanitizationHelpers.cjs +15 -0
  110. package/dist/helpers/sanitizationHelpers.d.ts +2 -0
  111. package/dist/helpers/sanitizationHelpers.mjs +6 -0
  112. package/dist/helpers/sortingHelper.cjs +67 -0
  113. package/dist/helpers/sortingHelper.d.ts +69 -0
  114. package/dist/helpers/sortingHelper.mjs +66 -0
  115. package/dist/helpers/stringHelpers.cjs +8 -0
  116. package/dist/helpers/stringHelpers.d.ts +2 -0
  117. package/dist/helpers/stringHelpers.mjs +2 -0
  118. package/dist/index.cjs +85 -0
  119. package/dist/index.d.ts +19 -0
  120. package/dist/index.mjs +8 -0
  121. package/dist/rpc/methods/basket/basket.cjs +183 -0
  122. package/dist/rpc/methods/basket/basket.d.ts +23 -0
  123. package/dist/rpc/methods/basket/basket.mjs +181 -0
  124. package/dist/rpc/methods/brands.cjs +34 -0
  125. package/dist/rpc/methods/brands.d.ts +5 -0
  126. package/dist/rpc/methods/brands.mjs +16 -0
  127. package/dist/rpc/methods/categories.cjs +102 -0
  128. package/dist/rpc/methods/categories.d.ts +21 -0
  129. package/dist/rpc/methods/categories.mjs +64 -0
  130. package/dist/rpc/methods/cbd.cjs +45 -0
  131. package/dist/rpc/methods/cbd.d.ts +4 -0
  132. package/dist/rpc/methods/cbd.mjs +36 -0
  133. package/dist/rpc/methods/checkout/index.cjs +38 -0
  134. package/dist/rpc/methods/checkout/index.d.ts +3 -0
  135. package/dist/rpc/methods/checkout/index.mjs +3 -0
  136. package/dist/rpc/methods/checkout/order.cjs +55 -0
  137. package/dist/rpc/methods/checkout/order.d.ts +4 -0
  138. package/dist/rpc/methods/checkout/order.mjs +43 -0
  139. package/dist/rpc/methods/checkout/shopUser.cjs +126 -0
  140. package/dist/rpc/methods/checkout/shopUser.d.ts +7 -0
  141. package/dist/rpc/methods/checkout/shopUser.mjs +109 -0
  142. package/dist/rpc/methods/checkout/shopUserAddresses.cjs +25 -0
  143. package/dist/rpc/methods/checkout/shopUserAddresses.d.ts +3 -0
  144. package/dist/rpc/methods/checkout/shopUserAddresses.mjs +19 -0
  145. package/dist/rpc/methods/index.cjs +159 -0
  146. package/dist/rpc/methods/index.d.ts +14 -0
  147. package/dist/rpc/methods/index.mjs +14 -0
  148. package/dist/rpc/methods/navigationTrees.cjs +33 -0
  149. package/dist/rpc/methods/navigationTrees.d.ts +5 -0
  150. package/dist/rpc/methods/navigationTrees.mjs +10 -0
  151. package/dist/rpc/methods/products.cjs +261 -0
  152. package/dist/rpc/methods/products.d.ts +13 -0
  153. package/dist/rpc/methods/products.mjs +217 -0
  154. package/dist/rpc/methods/promotion.cjs +53 -0
  155. package/dist/rpc/methods/promotion.d.ts +4 -0
  156. package/dist/rpc/methods/promotion.mjs +38 -0
  157. package/dist/rpc/methods/search.cjs +38 -0
  158. package/dist/rpc/methods/search.d.ts +10 -0
  159. package/dist/rpc/methods/search.mjs +22 -0
  160. package/dist/rpc/methods/session.cjs +274 -0
  161. package/dist/rpc/methods/session.d.ts +20 -0
  162. package/dist/rpc/methods/session.mjs +309 -0
  163. package/dist/rpc/methods/shopConfiguration.cjs +15 -0
  164. package/dist/rpc/methods/shopConfiguration.d.ts +4 -0
  165. package/dist/rpc/methods/shopConfiguration.mjs +6 -0
  166. package/dist/rpc/methods/user.cjs +89 -0
  167. package/dist/rpc/methods/user.d.ts +20 -0
  168. package/dist/rpc/methods/user.mjs +56 -0
  169. package/dist/rpc/methods/variants.cjs +29 -0
  170. package/dist/rpc/methods/variants.d.ts +8 -0
  171. package/dist/rpc/methods/variants.mjs +12 -0
  172. package/dist/rpc/methods/wishlist.cjs +85 -0
  173. package/dist/rpc/methods/wishlist.d.ts +13 -0
  174. package/dist/rpc/methods/wishlist.mjs +61 -0
  175. package/dist/server.cjs +39 -0
  176. package/dist/server.d.ts +5 -0
  177. package/dist/server.mjs +4 -0
  178. package/dist/types/api/auth.cjs +1 -0
  179. package/dist/types/api/auth.d.ts +63 -0
  180. package/dist/types/api/auth.mjs +0 -0
  181. package/dist/types/api/context.cjs +1 -0
  182. package/dist/types/api/context.d.ts +61 -0
  183. package/dist/types/api/context.mjs +0 -0
  184. package/dist/types/api/rpc.cjs +1 -0
  185. package/dist/types/api/rpc.d.ts +4 -0
  186. package/dist/types/api/rpc.mjs +0 -0
  187. package/dist/types/bapi/basket.cjs +1 -0
  188. package/dist/types/bapi/basket.d.ts +25 -0
  189. package/dist/types/bapi/basket.mjs +0 -0
  190. package/dist/types/bapi/brand.cjs +1 -0
  191. package/dist/types/bapi/brand.d.ts +2 -0
  192. package/dist/types/bapi/brand.mjs +0 -0
  193. package/dist/types/bapi/category.cjs +1 -0
  194. package/dist/types/bapi/category.d.ts +6 -0
  195. package/dist/types/bapi/category.mjs +0 -0
  196. package/dist/types/bapi/filter.cjs +1 -0
  197. package/dist/types/bapi/filter.d.ts +49 -0
  198. package/dist/types/bapi/filter.mjs +0 -0
  199. package/dist/types/bapi/navigation.cjs +1 -0
  200. package/dist/types/bapi/navigation.d.ts +10 -0
  201. package/dist/types/bapi/navigation.mjs +0 -0
  202. package/dist/types/bapi/order.cjs +1 -0
  203. package/dist/types/bapi/order.d.ts +554 -0
  204. package/dist/types/bapi/order.mjs +0 -0
  205. package/dist/types/bapi/pagination.cjs +1 -0
  206. package/dist/types/bapi/pagination.d.ts +13 -0
  207. package/dist/types/bapi/pagination.mjs +0 -0
  208. package/dist/types/bapi/product.cjs +1 -0
  209. package/dist/types/bapi/product.d.ts +84 -0
  210. package/dist/types/bapi/product.mjs +0 -0
  211. package/dist/types/bapi/productFilter.cjs +1 -0
  212. package/dist/types/bapi/productFilter.d.ts +7 -0
  213. package/dist/types/bapi/productFilter.mjs +0 -0
  214. package/dist/types/bapi/promotion.cjs +1 -0
  215. package/dist/types/bapi/promotion.d.ts +2 -0
  216. package/dist/types/bapi/promotion.mjs +0 -0
  217. package/dist/types/bapi/redirects.cjs +1 -0
  218. package/dist/types/bapi/redirects.d.ts +1 -0
  219. package/dist/types/bapi/redirects.mjs +0 -0
  220. package/dist/types/bapi/router.cjs +1 -0
  221. package/dist/types/bapi/router.d.ts +1 -0
  222. package/dist/types/bapi/router.mjs +0 -0
  223. package/dist/types/bapi/search.cjs +1 -0
  224. package/dist/types/bapi/search.d.ts +21 -0
  225. package/dist/types/bapi/search.mjs +0 -0
  226. package/dist/types/bapi/sorting.cjs +5 -0
  227. package/dist/types/bapi/sorting.d.ts +10 -0
  228. package/dist/types/bapi/sorting.mjs +1 -0
  229. package/dist/types/bapi/wishlist.cjs +1 -0
  230. package/dist/types/bapi/wishlist.d.ts +9 -0
  231. package/dist/types/bapi/wishlist.mjs +0 -0
  232. package/dist/types/breadcrumb.cjs +1 -0
  233. package/dist/types/breadcrumb.d.ts +4 -0
  234. package/dist/types/breadcrumb.mjs +0 -0
  235. package/dist/types/index.cjs +236 -0
  236. package/dist/types/index.d.ts +22 -0
  237. package/dist/types/index.mjs +21 -0
  238. package/dist/types/promises.cjs +1 -0
  239. package/dist/types/promises.d.ts +2 -0
  240. package/dist/types/promises.mjs +0 -0
  241. package/dist/types/user.cjs +1 -0
  242. package/dist/types/user.d.ts +100 -0
  243. package/dist/types/user.mjs +0 -0
  244. package/dist/utils/compression.cjs +24 -0
  245. package/dist/utils/compression.d.ts +2 -0
  246. package/dist/utils/compression.mjs +16 -0
  247. package/dist/utils/hash.cjs +68 -0
  248. package/dist/utils/hash.d.ts +8 -0
  249. package/dist/utils/hash.mjs +61 -0
  250. package/dist/utils/index.cjs +27 -0
  251. package/dist/utils/index.d.ts +2 -0
  252. package/dist/utils/index.mjs +2 -0
  253. package/dist/utils/keys.cjs +67 -0
  254. package/dist/utils/keys.d.ts +24 -0
  255. package/dist/utils/keys.mjs +56 -0
  256. package/dist/utils/log.cjs +93 -0
  257. package/dist/utils/log.d.ts +43 -0
  258. package/dist/utils/log.mjs +75 -0
  259. package/dist/utils/rpc.cjs +41 -0
  260. package/dist/utils/rpc.d.ts +6 -0
  261. package/dist/utils/rpc.mjs +35 -0
  262. package/dist/utils/timeout.cjs +17 -0
  263. package/dist/utils/timeout.d.ts +2 -0
  264. package/dist/utils/timeout.mjs +9 -0
  265. package/dist/utils/user.cjs +75 -0
  266. package/dist/utils/user.d.ts +14 -0
  267. package/dist/utils/user.mjs +65 -0
  268. package/package.json +97 -0
@@ -0,0 +1,217 @@
1
+ import { splitAndRemoveEmpty } from "../../helpers/index.mjs";
2
+ import { MIN_WITH_PARAMS_PRODUCT } from "../../constants/index.mjs";
3
+ const MAX_PER_PAGE = 100;
4
+ export const getProductById = async function getProductById2(options, { bapiClient, cached, campaignKey, withParams }) {
5
+ return await cached(bapiClient.products.getById, {
6
+ cacheKeyPrefix: `getById-product-${options.id}`
7
+ })(options.id, {
8
+ with: options.with ?? withParams?.product ?? MIN_WITH_PARAMS_PRODUCT,
9
+ campaignKey,
10
+ pricePromotionKey: options.pricePromotionKey,
11
+ includeSellableForFree: options.includeSellableForFree
12
+ });
13
+ };
14
+ export const getProductsByIds = async function getProductsByIds2(options, { bapiClient, cached, campaignKey, withParams }) {
15
+ return await cached(bapiClient.products.getByIds, {
16
+ cacheKeyPrefix: "getByIds-products"
17
+ })(options.ids, {
18
+ with: options.with ?? withParams?.product ?? MIN_WITH_PARAMS_PRODUCT,
19
+ campaignKey,
20
+ pricePromotionKey: options.pricePromotionKey,
21
+ includeSellableForFree: options.includeSellableForFree
22
+ });
23
+ };
24
+ export const getProductsByCategory = async function getProductsByCategory2({
25
+ category = "/",
26
+ cache,
27
+ with: _with,
28
+ perPage = 20,
29
+ page = 1,
30
+ where = void 0,
31
+ sort = void 0,
32
+ pricePromotionKey = "",
33
+ includeSellableForFree = void 0,
34
+ includeSoldOut = void 0,
35
+ orFiltersOperator = void 0
36
+ }, context) {
37
+ let result;
38
+ const { cached, bapiClient, campaignKey } = context;
39
+ if (category !== "/") {
40
+ result = await cached(bapiClient.categories.getByPath, {
41
+ cacheKeyPrefix: `getByPath-categories-${category}`
42
+ })(splitAndRemoveEmpty(category));
43
+ }
44
+ const { filters } = await getFilters(
45
+ { category, includeSoldOut, where, includeSellableForFree },
46
+ context
47
+ );
48
+ const { entities: products, pagination } = await cached(
49
+ bapiClient.products.query,
50
+ {
51
+ ...cache,
52
+ cacheKeyPrefix: `products-query-category-${category === "/" ? "root" : category}`
53
+ }
54
+ )({
55
+ where: {
56
+ term: where?.term,
57
+ categoryId: result?.id,
58
+ minPrice: where?.minPrice,
59
+ maxPrice: where?.maxPrice,
60
+ attributes: [
61
+ ...sanitizeAttributesForBAPI({
62
+ attributes: where?.attributes || [],
63
+ filterKeys: mapFiltersToSlugs(filters)
64
+ }),
65
+ ...where?.whitelistAttributes || []
66
+ ],
67
+ disableFuzziness: where?.disableFuzziness
68
+ },
69
+ pagination: {
70
+ perPage: Math.min(perPage, MAX_PER_PAGE),
71
+ page
72
+ },
73
+ campaignKey,
74
+ pricePromotionKey,
75
+ includeSellableForFree,
76
+ includeSoldOut,
77
+ with: _with ?? context.withParams?.product ?? MIN_WITH_PARAMS_PRODUCT,
78
+ sort,
79
+ orFiltersOperator
80
+ });
81
+ return {
82
+ products,
83
+ pagination
84
+ };
85
+ };
86
+ export const getFilters = async function getFilters2({
87
+ category = "/",
88
+ includedFilters,
89
+ where = void 0,
90
+ includeSoldOut = false,
91
+ includeSellableForFree = false,
92
+ orFiltersOperator
93
+ }, { cached, bapiClient, campaignKey }) {
94
+ let result;
95
+ let allFiltersForCategory = [];
96
+ if (category !== "/") {
97
+ result = await cached(bapiClient.categories.getByPath, {
98
+ cacheKeyPrefix: `getByPath-categories-${category}`
99
+ })(splitAndRemoveEmpty(category));
100
+ allFiltersForCategory = await fetchAllFiltersForCategory(
101
+ { category: { id: result.id, slug: category }, includedFilters },
102
+ { cached, bapiClient, campaignKey }
103
+ );
104
+ }
105
+ const sanitizedAttributes = sanitizeAttributesForBAPI({
106
+ attributes: where?.attributes || [],
107
+ filterKeys: allFiltersForCategory,
108
+ includedFilters
109
+ });
110
+ const [filters, productCount] = await Promise.all([
111
+ cached(bapiClient.filters.get, {
112
+ cacheKeyPrefix: `get-filters-${category}`
113
+ })({
114
+ where: {
115
+ categoryId: result?.id,
116
+ minPrice: where?.minPrice,
117
+ maxPrice: where?.maxPrice,
118
+ term: where?.term,
119
+ attributes: [
120
+ ...sanitizedAttributes,
121
+ ...where?.whitelistAttributes || []
122
+ ]
123
+ },
124
+ includeSoldOut,
125
+ includeSellableForFree,
126
+ campaignKey,
127
+ including: includedFilters,
128
+ orFiltersOperator
129
+ }),
130
+ cached(bapiClient.products.query, {
131
+ cacheKeyPrefix: `products-query-category-${category === "/" ? "root" : category}`
132
+ })({
133
+ where: {
134
+ categoryId: result?.id,
135
+ minPrice: where?.minPrice,
136
+ maxPrice: where?.maxPrice,
137
+ term: where?.term,
138
+ attributes: [
139
+ ...sanitizedAttributes,
140
+ ...where?.whitelistAttributes || []
141
+ ]
142
+ },
143
+ includeSoldOut,
144
+ campaignKey,
145
+ pagination: {
146
+ perPage: 1
147
+ },
148
+ orFiltersOperator
149
+ })
150
+ ]);
151
+ return {
152
+ filters,
153
+ unfilteredCount: productCount?.pagination.total
154
+ };
155
+ };
156
+ export const fetchAllFiltersForCategory = async function fetchAllFiltersForCategory2({ includedFilters = [], category }, { cached, bapiClient, campaignKey }) {
157
+ const fetchAndMapFiltersToSlugs = async () => {
158
+ const filtersFromBAPI = await cached(bapiClient.filters.get)({
159
+ where: { categoryId: category.id },
160
+ campaignKey,
161
+ including: includedFilters
162
+ });
163
+ return mapFiltersToSlugs(filtersFromBAPI);
164
+ };
165
+ return await cached(fetchAndMapFiltersToSlugs, {
166
+ ttl: 4 * 60 * 60,
167
+ // cached for 4 hours
168
+ cacheKey: `filters-for-category-${category.slug}`
169
+ })();
170
+ };
171
+ export const getProductsCount = async function getProductsCount2({
172
+ category = "/",
173
+ categoryId = void 0,
174
+ where = void 0,
175
+ includeSoldOut = false,
176
+ includeSellableForFree = false,
177
+ orFiltersOperator = void 0
178
+ }, { cached, bapiClient, campaignKey }) {
179
+ let result;
180
+ if (category !== "/") {
181
+ const sanitizedPath = splitAndRemoveEmpty(category);
182
+ result = await cached(bapiClient.categories.getByPath, {
183
+ cacheKeyPrefix: `getByPath-categories-${sanitizedPath}`
184
+ })(sanitizedPath);
185
+ }
186
+ const productCount = await cached(bapiClient.products.query, {
187
+ cacheKeyPrefix: "products-query"
188
+ })({
189
+ where: {
190
+ categoryId: categoryId ?? result?.id,
191
+ minPrice: where?.minPrice,
192
+ maxPrice: where?.maxPrice,
193
+ attributes: where?.attributes,
194
+ term: where?.term
195
+ },
196
+ includeSoldOut,
197
+ includeSellableForFree,
198
+ campaignKey,
199
+ pagination: {
200
+ perPage: 1
201
+ },
202
+ orFiltersOperator
203
+ });
204
+ return {
205
+ count: productCount?.pagination.total
206
+ };
207
+ };
208
+ const sanitizeAttributesForBAPI = ({
209
+ attributes,
210
+ filterKeys,
211
+ includedFilters = []
212
+ }) => {
213
+ return attributes.filter(
214
+ ({ key }) => key && filterKeys.includes(key.toLowerCase()) && !includedFilters?.includes(key.toLowerCase())
215
+ );
216
+ };
217
+ const mapFiltersToSlugs = (filters = []) => filters.map(({ slug }) => slug.toLowerCase());
@@ -0,0 +1,53 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.getPromotionsByIds = exports.getPromotions = exports.getCurrentPromotions = void 0;
7
+ var _constants = require("../../constants/index.cjs");
8
+ const setPaginationDefault = pagination => {
9
+ return {
10
+ page: pagination?.page || _constants.PROMOTION_PAGE_DEFAULT,
11
+ perPage: pagination?.perPage || _constants.PROMOTION_PER_PAGE_DEFAULT
12
+ };
13
+ };
14
+ const getPromotions = async function getPromotions2(params = {}, context) {
15
+ const {
16
+ bapiClient,
17
+ cached
18
+ } = context;
19
+ return await cached(bapiClient.promotions.get, {
20
+ cacheKeyPrefix: "getPromotions"
21
+ })({
22
+ ...params,
23
+ pagination: setPaginationDefault(params.pagination)
24
+ });
25
+ };
26
+ exports.getPromotions = getPromotions;
27
+ const getCurrentPromotions = async function getCurrentPromotions2(params = {}, context) {
28
+ const {
29
+ bapiClient,
30
+ cached
31
+ } = context;
32
+ const now = /* @__PURE__ */new Date();
33
+ now.setSeconds(0, 0);
34
+ const activeAt = now.toISOString();
35
+ return await cached(bapiClient.promotions.get, {
36
+ cacheKeyPrefix: "getPromotions"
37
+ })({
38
+ ...params,
39
+ activeAt,
40
+ pagination: setPaginationDefault(params.pagination)
41
+ });
42
+ };
43
+ exports.getCurrentPromotions = getCurrentPromotions;
44
+ const getPromotionsByIds = async function getPromotionsByIds2(ids, context) {
45
+ const {
46
+ bapiClient,
47
+ cached
48
+ } = context;
49
+ return await cached(bapiClient.promotions.getByIds, {
50
+ cacheKeyPrefix: "getByIds-promotions"
51
+ })(ids);
52
+ };
53
+ exports.getPromotionsByIds = getPromotionsByIds;
@@ -0,0 +1,4 @@
1
+ import { RpcHandler, PromotionsParams, PromotionsResponseData } from '../../types';
2
+ export declare const getPromotions: RpcHandler<Omit<PromotionsParams, 'ids'>, PromotionsResponseData>;
3
+ export declare const getCurrentPromotions: RpcHandler<Omit<PromotionsParams, 'ids' | 'activeAt'>, PromotionsResponseData>;
4
+ export declare const getPromotionsByIds: RpcHandler<string[], PromotionsResponseData>;
@@ -0,0 +1,38 @@
1
+ import {
2
+ PROMOTION_PAGE_DEFAULT,
3
+ PROMOTION_PER_PAGE_DEFAULT
4
+ } from "../../constants/index.mjs";
5
+ const setPaginationDefault = (pagination) => {
6
+ return {
7
+ page: pagination?.page || PROMOTION_PAGE_DEFAULT,
8
+ perPage: pagination?.perPage || PROMOTION_PER_PAGE_DEFAULT
9
+ };
10
+ };
11
+ export const getPromotions = async function getPromotions2(params = {}, context) {
12
+ const { bapiClient, cached } = context;
13
+ return await cached(bapiClient.promotions.get, {
14
+ cacheKeyPrefix: "getPromotions"
15
+ })({
16
+ ...params,
17
+ pagination: setPaginationDefault(params.pagination)
18
+ });
19
+ };
20
+ export const getCurrentPromotions = async function getCurrentPromotions2(params = {}, context) {
21
+ const { bapiClient, cached } = context;
22
+ const now = /* @__PURE__ */ new Date();
23
+ now.setSeconds(0, 0);
24
+ const activeAt = now.toISOString();
25
+ return await cached(bapiClient.promotions.get, {
26
+ cacheKeyPrefix: "getPromotions"
27
+ })({
28
+ ...params,
29
+ activeAt,
30
+ pagination: setPaginationDefault(params.pagination)
31
+ });
32
+ };
33
+ export const getPromotionsByIds = async function getPromotionsByIds2(ids, context) {
34
+ const { bapiClient, cached } = context;
35
+ return await cached(bapiClient.promotions.getByIds, {
36
+ cacheKeyPrefix: "getByIds-promotions"
37
+ })(ids);
38
+ };
@@ -0,0 +1,38 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.searchProducts = void 0;
7
+ var _constants = require("../../constants/index.cjs");
8
+ var _stringHelpers = require("../../helpers/stringHelpers.cjs");
9
+ const searchProducts = async function searchProducts2({
10
+ term,
11
+ slug,
12
+ with: _with,
13
+ productLimit
14
+ }, {
15
+ cached,
16
+ bapiClient,
17
+ withParams
18
+ }) {
19
+ const categoryId = await getCategoryId(cached, bapiClient, slug);
20
+ return await cached(bapiClient.typeahead.suggestions, {
21
+ cacheKeyPrefix: `typeahead-suggestions-${term}`
22
+ })(term, {
23
+ productLimit,
24
+ categoryId,
25
+ with: _with ?? withParams?.search ?? _constants.MIN_WITH_PARAMS_SEARCH
26
+ });
27
+ };
28
+ exports.searchProducts = searchProducts;
29
+ const getCategoryId = async (cached, bapiClient, slug) => {
30
+ if (!slug) {
31
+ return;
32
+ }
33
+ const sanitizedPath = (0, _stringHelpers.splitAndRemoveEmpty)(slug);
34
+ const result = await cached(bapiClient.categories.getByPath, {
35
+ cacheKeyPrefix: `getByPath-categories-${sanitizedPath}`
36
+ })(sanitizedPath);
37
+ return result.id;
38
+ };
@@ -0,0 +1,10 @@
1
+ import type { TypeaheadSuggestionsEndpointRequestParameters, TypeaheadSuggestionsEndpointResponseData } from '@aboutyou/backbone/endpoints/typeahead/typeahead';
2
+ import { RpcHandler } from '../../types';
3
+ type SearchWith = TypeaheadSuggestionsEndpointRequestParameters['with'];
4
+ export declare const searchProducts: RpcHandler<{
5
+ term: string;
6
+ slug?: string;
7
+ with?: SearchWith;
8
+ productLimit?: number;
9
+ }, TypeaheadSuggestionsEndpointResponseData>;
10
+ export {};
@@ -0,0 +1,22 @@
1
+ import { MIN_WITH_PARAMS_SEARCH } from "../../constants/index.mjs";
2
+ import { splitAndRemoveEmpty } from "../../helpers/stringHelpers.mjs";
3
+ export const searchProducts = async function searchProducts2({ term, slug, with: _with, productLimit }, { cached, bapiClient, withParams }) {
4
+ const categoryId = await getCategoryId(cached, bapiClient, slug);
5
+ return await cached(bapiClient.typeahead.suggestions, {
6
+ cacheKeyPrefix: `typeahead-suggestions-${term}`
7
+ })(term, {
8
+ productLimit,
9
+ categoryId,
10
+ with: _with ?? withParams?.search ?? MIN_WITH_PARAMS_SEARCH
11
+ });
12
+ };
13
+ const getCategoryId = async (cached, bapiClient, slug) => {
14
+ if (!slug) {
15
+ return;
16
+ }
17
+ const sanitizedPath = splitAndRemoveEmpty(slug);
18
+ const result = await cached(bapiClient.categories.getByPath, {
19
+ cacheKeyPrefix: `getByPath-categories-${sanitizedPath}`
20
+ })(sanitizedPath);
21
+ return result.id;
22
+ };
@@ -0,0 +1,274 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.updatePasswordByHash = exports.refreshAccessToken = exports.oauthRevokeToken = exports.oauthRegister = exports.oauthLogin = exports.oauthGuestLogin = exports.oauthForgetPassword = void 0;
7
+ var _axios = _interopRequireDefault(require("axios"));
8
+ var _jose = require("jose");
9
+ var _constants = require("../../constants/index.cjs");
10
+ var _rpc = require("../../utils/rpc.cjs");
11
+ var _hash = require("../../utils/hash.cjs");
12
+ var _user = require("../../utils/user.cjs");
13
+ var _user2 = require("../../rpc/methods/user.cjs");
14
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
15
+ class MissingCredentialsError extends Error {
16
+ constructor() {
17
+ super("[Token based Authentication] No credentials configured");
18
+ this.name = "MissingCredentialsError";
19
+ }
20
+ }
21
+ function getOAuthSettings(context) {
22
+ const clientId = context.oauth?.clientId ?? process.env.OAUTH_CLIENT_ID;
23
+ const clientSecret = context.oauth?.clientSecret ?? process.env.OAUTH_CLIENT_SECRET;
24
+ const apiHost = context.oauth?.apiHost ?? process.env.OAUTH_API_HOST;
25
+ if (!clientId || !clientSecret) {
26
+ throw new MissingCredentialsError();
27
+ }
28
+ const BASIC_AUTH_HASH = (0, _hash.encodeBase64)(`${clientId}:${clientSecret}`);
29
+ const axiosInstance2 = _axios.default.create({
30
+ baseURL: `${apiHost}/v1`,
31
+ headers: {
32
+ Authorization: `Basic ${BASIC_AUTH_HASH}`
33
+ }
34
+ });
35
+ return {
36
+ clientId,
37
+ clientSecret,
38
+ apiHost,
39
+ axiosInstance: axiosInstance2
40
+ };
41
+ }
42
+ const saveUserOnSession = async (accessToken, context) => {
43
+ const checkoutUrl = context.checkout.url;
44
+ const shopId = context.shopId;
45
+ const user = await (0, _user2.fetchUser)({
46
+ accessToken,
47
+ callback: ""
48
+ }, {
49
+ checkoutUrl,
50
+ shopId
51
+ });
52
+ context.updateUser(user);
53
+ };
54
+ const oauthLogin = async (login, context) => {
55
+ const shopId = context.shopId;
56
+ const {
57
+ axiosInstance: axiosInstance2
58
+ } = getOAuthSettings(context);
59
+ if (!login.email || !login.password) {
60
+ throw new Error("Login or password are missing, seems like validation has failed");
61
+ }
62
+ try {
63
+ const response = await axiosInstance2.post("/auth/login", {
64
+ ...login,
65
+ shop_id: shopId
66
+ });
67
+ context.updateTokens({
68
+ accessToken: response.data.access_token,
69
+ refreshToken: response.data.refresh_token
70
+ });
71
+ await saveUserOnSession(response.data.access_token, context);
72
+ const {
73
+ customerId
74
+ } = (0, _jose.decodeJwt)(response.data.access_token);
75
+ await Promise.all([(0, _user.mergeBaskets)(context.sessionId, await context.generateBasketKeyForUserId(customerId), _constants.DEFAULT_WITH_LISTING, context), (0, _user.mergeWishlists)(context.sessionId, await context.generateWishlistKeyForUserId(customerId), _constants.DEFAULT_WITH_LISTING, context)]);
76
+ await context.createUserBoundSession();
77
+ return {
78
+ oauth: response.data
79
+ };
80
+ } catch (error) {
81
+ const err = (0, _rpc.convertErrorForRpcCall)(error, [_constants.HttpStatusCode.INTERNAL_SERVER_ERROR, _constants.HttpStatusCode.BAD_REQUEST, _constants.HttpStatusCode.UNAUTHORIZED, _constants.HttpStatusCode.NOT_FOUND]);
82
+ if (err) {
83
+ throw err;
84
+ }
85
+ return {
86
+ oauth: null
87
+ };
88
+ }
89
+ };
90
+ exports.oauthLogin = oauthLogin;
91
+ const oauthRegister = async (register, context) => {
92
+ const shopId = context.shopId;
93
+ const {
94
+ axiosInstance: axiosInstance2
95
+ } = getOAuthSettings(context);
96
+ try {
97
+ const response = await axiosInstance2.post("/auth/register", {
98
+ ...register,
99
+ shop_id: shopId
100
+ });
101
+ context.updateTokens({
102
+ accessToken: response.data.access_token,
103
+ refreshToken: response.data.refresh_token
104
+ });
105
+ await saveUserOnSession(response.data.access_token, context);
106
+ const {
107
+ customerId
108
+ } = (0, _jose.decodeJwt)(response.data.access_token);
109
+ await Promise.all([(0, _user.mergeBaskets)(context.sessionId, await context.generateBasketKeyForUserId(customerId), _constants.DEFAULT_WITH_LISTING, context), (0, _user.mergeWishlists)(context.sessionId, await context.generateWishlistKeyForUserId(customerId), _constants.DEFAULT_WITH_LISTING, context)]);
110
+ await context.createUserBoundSession();
111
+ return {
112
+ oauth: response.data
113
+ };
114
+ } catch (error) {
115
+ const err = (0, _rpc.convertErrorForRpcCall)(error, [_constants.HttpStatusCode.BAD_REQUEST, _constants.HttpStatusCode.UNAUTHORIZED, _constants.HttpStatusCode.CONFLICT]);
116
+ if (err) {
117
+ throw err;
118
+ }
119
+ return {
120
+ oauth: null
121
+ };
122
+ }
123
+ };
124
+ exports.oauthRegister = oauthRegister;
125
+ const oauthGuestLogin = async (guest, context) => {
126
+ const shopId = context.shopId;
127
+ const {
128
+ axiosInstance: axiosInstance2
129
+ } = getOAuthSettings(context);
130
+ try {
131
+ const response = await axiosInstance2.post("/auth/login/guest", {
132
+ ...guest,
133
+ shop_id: shopId
134
+ });
135
+ context.updateTokens({
136
+ accessToken: response.data.access_token,
137
+ refreshToken: response.data.refresh_token
138
+ });
139
+ await saveUserOnSession(response.data.access_token, context);
140
+ const {
141
+ customerId
142
+ } = (0, _jose.decodeJwt)(response.data.access_token);
143
+ await Promise.all([(0, _user.mergeBaskets)(context.sessionId, await context.generateBasketKeyForUserId(customerId), _constants.DEFAULT_WITH_LISTING, context), (0, _user.mergeWishlists)(context.sessionId, await context.generateWishlistKeyForUserId(customerId), _constants.DEFAULT_WITH_LISTING, context)]);
144
+ await context.createUserBoundSession();
145
+ return {
146
+ oauth: response.data
147
+ };
148
+ } catch (error) {
149
+ const err = (0, _rpc.convertErrorForRpcCall)(error, [_constants.HttpStatusCode.BAD_REQUEST, _constants.HttpStatusCode.UNAUTHORIZED, _constants.HttpStatusCode.CONFLICT]);
150
+ if (err) {
151
+ throw err;
152
+ }
153
+ return {
154
+ oauth: null
155
+ };
156
+ }
157
+ };
158
+ exports.oauthGuestLogin = oauthGuestLogin;
159
+ const refreshAccessToken = async context => {
160
+ const refreshToken = context.refreshToken;
161
+ const {
162
+ axiosInstance: axiosInstance2
163
+ } = getOAuthSettings(context);
164
+ if (!refreshToken) {
165
+ throw new Error("No app refresh token provided");
166
+ }
167
+ try {
168
+ const response = await axiosInstance2.post("/oauth/token", {
169
+ grant_type: "refresh_token",
170
+ refresh_token: refreshToken
171
+ });
172
+ context.updateTokens({
173
+ accessToken: response.data.access_token,
174
+ refreshToken: response.data.refresh_token
175
+ });
176
+ return response.data;
177
+ } catch (error) {
178
+ const err = (0, _rpc.convertErrorForRpcCall)(error, [_constants.HttpStatusCode.BAD_REQUEST, _constants.HttpStatusCode.UNAUTHORIZED]);
179
+ if (err) {
180
+ throw err;
181
+ }
182
+ return null;
183
+ }
184
+ };
185
+ exports.refreshAccessToken = refreshAccessToken;
186
+ const oauthRevokeToken = async context => {
187
+ const accessToken = context.accessToken;
188
+ if (!accessToken) {
189
+ throw new Error("No app oauth authentication credentials");
190
+ }
191
+ const decodedAccessToken = (0, _jose.decodeJwt)(accessToken);
192
+ await context.destroySession();
193
+ try {
194
+ await axiosInstance.delete(`/oauth/tokens/${decodedAccessToken.jti}`, {
195
+ headers: {
196
+ Authorization: `Bearer ${accessToken}`
197
+ }
198
+ });
199
+ return {
200
+ result: true
201
+ };
202
+ } catch (error) {
203
+ const err = (0, _rpc.convertErrorForRpcCall)(error, [_constants.HttpStatusCode.BAD_REQUEST, _constants.HttpStatusCode.UNAUTHORIZED, _constants.HttpStatusCode.NOT_FOUND]);
204
+ if (err) {
205
+ throw err;
206
+ }
207
+ return {
208
+ result: false
209
+ };
210
+ }
211
+ };
212
+ exports.oauthRevokeToken = oauthRevokeToken;
213
+ const oauthForgetPassword = async ({
214
+ email
215
+ }, context) => {
216
+ const shopId = context.shopId;
217
+ const {
218
+ axiosInstance: axiosInstance2
219
+ } = getOAuthSettings(context);
220
+ try {
221
+ const resetUrl = new URL(context.auth.resetPasswordUrl);
222
+ if (!resetUrl.searchParams.has("hash")) {
223
+ resetUrl.searchParams.append("hash", "{hash}");
224
+ } else {
225
+ resetUrl.searchParams.set("hash", "{hash}");
226
+ }
227
+ await axiosInstance2.post("/auth/password/send-reset-email", {
228
+ email,
229
+ reset_url: decodeURI(resetUrl.toString()),
230
+ shop_id: shopId
231
+ });
232
+ return {
233
+ success: true
234
+ };
235
+ } catch (error) {
236
+ const err = (0, _rpc.convertErrorForRpcCall)(error, [_constants.HttpStatusCode.BAD_REQUEST, _constants.HttpStatusCode.NOT_FOUND, _constants.HttpStatusCode.UNAUTHORIZED, _constants.HttpStatusCode.FORBIDDEN]);
237
+ if (err) {
238
+ throw err;
239
+ }
240
+ return {
241
+ success: false
242
+ };
243
+ }
244
+ };
245
+ exports.oauthForgetPassword = oauthForgetPassword;
246
+ const updatePasswordByHash = async (passwordHash, context) => {
247
+ const shopId = context.shopId;
248
+ const {
249
+ axiosInstance: axiosInstance2
250
+ } = getOAuthSettings(context);
251
+ try {
252
+ const response = await axiosInstance2.put("/auth/password/update-by-hash", {
253
+ ...passwordHash,
254
+ shop_id: shopId
255
+ });
256
+ context.updateTokens({
257
+ accessToken: response.data.access_token,
258
+ refreshToken: response.data.refresh_token
259
+ });
260
+ await context.createUserBoundSession();
261
+ return {
262
+ oauth: response.data
263
+ };
264
+ } catch (error) {
265
+ const err = (0, _rpc.convertErrorForRpcCall)(error, [_constants.HttpStatusCode.BAD_REQUEST, _constants.HttpStatusCode.UNAUTHORIZED, _constants.HttpStatusCode.NOT_ACCEPTABLE]);
266
+ if (err) {
267
+ throw err;
268
+ }
269
+ return {
270
+ oauth: null
271
+ };
272
+ }
273
+ };
274
+ exports.updatePasswordByHash = updatePasswordByHash;
@@ -0,0 +1,20 @@
1
+ import { GuestRequest, LoginRequest, Oauth, RegisterRequest, RpcHandler, SendResetPasswordEmailRequest, UpdatePasswordByHashRequest } from '../../types';
2
+ export declare const oauthLogin: RpcHandler<LoginRequest, {
3
+ oauth: Oauth | null;
4
+ }>;
5
+ export declare const oauthRegister: RpcHandler<RegisterRequest, {
6
+ oauth: Oauth | null;
7
+ }>;
8
+ export declare const oauthGuestLogin: RpcHandler<GuestRequest, {
9
+ oauth: Oauth | null;
10
+ }>;
11
+ export declare const refreshAccessToken: RpcHandler<Oauth | null>;
12
+ export declare const oauthRevokeToken: RpcHandler<{
13
+ result: boolean;
14
+ }>;
15
+ export declare const oauthForgetPassword: RpcHandler<SendResetPasswordEmailRequest, {
16
+ success: boolean;
17
+ }>;
18
+ export declare const updatePasswordByHash: RpcHandler<UpdatePasswordByHashRequest, {
19
+ oauth: Oauth | null;
20
+ }>;