@lana-commerce/core 11.0.0

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 (972) hide show
  1. package/CHANGELOG.md +531 -0
  2. package/cjs/actionLock.js +31 -0
  3. package/cjs/addEmptyListItem.js +7 -0
  4. package/cjs/aggregateOptions.js +178 -0
  5. package/cjs/analytics.js +90 -0
  6. package/cjs/analyticsProductData.js +33 -0
  7. package/cjs/arrayToDict.js +12 -0
  8. package/cjs/asyncModuleWrapper.js +52 -0
  9. package/cjs/averageReviewScore.js +45 -0
  10. package/cjs/buildconfig.js +16 -0
  11. package/cjs/cachedLoader.js +36 -0
  12. package/cjs/canonicalVariantURL.js +2 -0
  13. package/cjs/cartOperation.js +132 -0
  14. package/cjs/categorySEO.js +20 -0
  15. package/cjs/commonTypes.js +2 -0
  16. package/cjs/compact.js +8 -0
  17. package/cjs/configLoader.js +69 -0
  18. package/cjs/controlledQueue.js +46 -0
  19. package/cjs/convertImageURL.js +19 -0
  20. package/cjs/dataLoader.js +185 -0
  21. package/cjs/defaultVariant.js +30 -0
  22. package/cjs/effector/clearOnChangeAfterDelay.js +17 -0
  23. package/cjs/effector/combineEvery.js +8 -0
  24. package/cjs/effector/combineSome.js +8 -0
  25. package/cjs/effector/debounced.js +18 -0
  26. package/cjs/effector/form.js +168 -0
  27. package/cjs/effector/hideOnChangeAfterDelay.js +17 -0
  28. package/cjs/effector/requestResponse.js +30 -0
  29. package/cjs/effector/requestResponseMulti.js +51 -0
  30. package/cjs/effector/restoreNamed.js +8 -0
  31. package/cjs/effector/split.js +29 -0
  32. package/cjs/effector/validator.js +33 -0
  33. package/cjs/effector/wrapSignInRequired.js +13 -0
  34. package/cjs/exceptions.js +6 -0
  35. package/cjs/fetchAllItems.js +56 -0
  36. package/cjs/file.js +83 -0
  37. package/cjs/fileWebsocket.js +83 -0
  38. package/cjs/filterFunc.js +48 -0
  39. package/cjs/filterFuncBrand.js +12 -0
  40. package/cjs/filterFuncCategory.js +12 -0
  41. package/cjs/filterFuncContentBlock.js +19 -0
  42. package/cjs/filterFuncCustomer.js +161 -0
  43. package/cjs/filterFuncDataFeed.js +54 -0
  44. package/cjs/filterFuncOrder.js +334 -0
  45. package/cjs/filterFuncPreprocess.js +14 -0
  46. package/cjs/filterFuncProduct.js +70 -0
  47. package/cjs/filterFuncPurchaseOrder.js +126 -0
  48. package/cjs/filterFuncSupplier.js +36 -0
  49. package/cjs/filterFuncTransfer.js +135 -0
  50. package/cjs/formatAbbrevNumber.js +21 -0
  51. package/cjs/formatCurrency.js +47 -0
  52. package/cjs/formatToJSX.js +123 -0
  53. package/cjs/fulfillmentNumber.js +7 -0
  54. package/cjs/generateRandomToken.js +12 -0
  55. package/cjs/generateUUID.js +10 -0
  56. package/cjs/generated/codes.js +47 -0
  57. package/cjs/genericFile.js +73 -0
  58. package/cjs/getSalesChannelID.js +13 -0
  59. package/cjs/getSessionID.js +13 -0
  60. package/cjs/getTimezone.js +12 -0
  61. package/cjs/graphql/fragments/Branding.js +3 -0
  62. package/cjs/graphql/fragments/BrandingField.js +3 -0
  63. package/cjs/graphql/fragments/CartCustomItem.js +3 -0
  64. package/cjs/graphql/fragments/CartOrder.js +3 -0
  65. package/cjs/graphql/fragments/CartVariant.js +3 -0
  66. package/cjs/graphql/fragments/CartVariantFull.js +3 -0
  67. package/cjs/graphql/fragments/Category.js +3 -0
  68. package/cjs/graphql/fragments/CommonCartVariant.js +3 -0
  69. package/cjs/graphql/fragments/Currency.js +3 -0
  70. package/cjs/graphql/fragments/CurrencyPrice.js +3 -0
  71. package/cjs/graphql/fragments/CustomField.js +3 -0
  72. package/cjs/graphql/fragments/CustomFieldObjects.js +3 -0
  73. package/cjs/graphql/fragments/Customer.js +3 -0
  74. package/cjs/graphql/fragments/CustomerBalance.js +3 -0
  75. package/cjs/graphql/fragments/CustomerBalanceHistory.js +3 -0
  76. package/cjs/graphql/fragments/CustomerFavorite.js +3 -0
  77. package/cjs/graphql/fragments/CustomerFavoriteShort.js +3 -0
  78. package/cjs/graphql/fragments/CustomerOAuthProvider.js +3 -0
  79. package/cjs/graphql/fragments/CustomerOrderBrief.js +3 -0
  80. package/cjs/graphql/fragments/CustomerOrderFulfillment.js +3 -0
  81. package/cjs/graphql/fragments/CustomerOrderFull.js +3 -0
  82. package/cjs/graphql/fragments/CustomerPaymentSource.js +3 -0
  83. package/cjs/graphql/fragments/CustomerReturnBrief.js +3 -0
  84. package/cjs/graphql/fragments/CustomerReturnFull.js +3 -0
  85. package/cjs/graphql/fragments/CustomerReturnPolicy.js +3 -0
  86. package/cjs/graphql/fragments/CustomerSubscriptionBrief.js +3 -0
  87. package/cjs/graphql/fragments/CustomerSubscriptionFull.js +3 -0
  88. package/cjs/graphql/fragments/File.js +3 -0
  89. package/cjs/graphql/fragments/FileForUpload.js +3 -0
  90. package/cjs/graphql/fragments/FileNoFallback.js +3 -0
  91. package/cjs/graphql/fragments/FullAddress.js +3 -0
  92. package/cjs/graphql/fragments/Gateway.js +3 -0
  93. package/cjs/graphql/fragments/GatewayManual.js +3 -0
  94. package/cjs/graphql/fragments/GatewayPaypal.js +3 -0
  95. package/cjs/graphql/fragments/GatewayStripe.js +3 -0
  96. package/cjs/graphql/fragments/GatewayTest.js +3 -0
  97. package/cjs/graphql/fragments/IPAndUAInfo.js +3 -0
  98. package/cjs/graphql/fragments/InfoCountry.js +3 -0
  99. package/cjs/graphql/fragments/InfoCountryDedupField.js +3 -0
  100. package/cjs/graphql/fragments/InfoCurrency.js +3 -0
  101. package/cjs/graphql/fragments/InfoProvince.js +3 -0
  102. package/cjs/graphql/fragments/KeyValue.js +3 -0
  103. package/cjs/graphql/fragments/LineItemField.js +3 -0
  104. package/cjs/graphql/fragments/MediaFile.js +3 -0
  105. package/cjs/graphql/fragments/MinCurrencyPrice.js +3 -0
  106. package/cjs/graphql/fragments/ProductField.js +3 -0
  107. package/cjs/graphql/fragments/ProductFieldSet.js +3 -0
  108. package/cjs/graphql/fragments/ProductFlat.js +3 -0
  109. package/cjs/graphql/fragments/ProductQuestion.js +3 -0
  110. package/cjs/graphql/fragments/ProductQuestionAnswer.js +3 -0
  111. package/cjs/graphql/fragments/ProductQuestionPage.js +3 -0
  112. package/cjs/graphql/fragments/ProductReview.js +3 -0
  113. package/cjs/graphql/fragments/ProductReviewAnswer.js +3 -0
  114. package/cjs/graphql/fragments/ProductReviewAverageScore.js +3 -0
  115. package/cjs/graphql/fragments/ProductReviewPage.js +3 -0
  116. package/cjs/graphql/fragments/ProductReviewScore.js +3 -0
  117. package/cjs/graphql/fragments/ProductReviewSurveyAnswer.js +3 -0
  118. package/cjs/graphql/fragments/ProductSearchOptionAgg.js +3 -0
  119. package/cjs/graphql/fragments/ProductSearchResult.js +3 -0
  120. package/cjs/graphql/fragments/ReturnReason.js +3 -0
  121. package/cjs/graphql/fragments/ReviewDimension.js +3 -0
  122. package/cjs/graphql/fragments/ReviewDimensionSet.js +3 -0
  123. package/cjs/graphql/fragments/ReviewImagePage.js +3 -0
  124. package/cjs/graphql/fragments/ReviewQuestionProduct.js +3 -0
  125. package/cjs/graphql/fragments/ReviewSettings.js +3 -0
  126. package/cjs/graphql/fragments/SearchProduct.js +3 -0
  127. package/cjs/graphql/fragments/Shop.js +3 -0
  128. package/cjs/graphql/fragments/SubscriptionPlan.js +3 -0
  129. package/cjs/graphql/fragments/SurveyQuestion.js +3 -0
  130. package/cjs/graphql/fragments/TieredPricing.js +3 -0
  131. package/cjs/graphql/fragments/TieredPricingTier.js +3 -0
  132. package/cjs/graphql/fragments/VariantOption.js +3 -0
  133. package/cjs/graphql/operations/ApplyGiftCardMutation.js +3 -0
  134. package/cjs/graphql/operations/AuthRequestMutation.js +3 -0
  135. package/cjs/graphql/operations/CancelOrderMutation.js +3 -0
  136. package/cjs/graphql/operations/CancelSubscriptionMutation.js +3 -0
  137. package/cjs/graphql/operations/ConnectOAuth2Mutation.js +3 -0
  138. package/cjs/graphql/operations/CreateCartMutation.js +26 -0
  139. package/cjs/graphql/operations/CreateFavoriteMutation.js +22 -0
  140. package/cjs/graphql/operations/CreateFileMutation.js +6 -0
  141. package/cjs/graphql/operations/CreatePaymentSourceMutation.js +6 -0
  142. package/cjs/graphql/operations/CreateProductQuestionAnswerMutation.js +3 -0
  143. package/cjs/graphql/operations/CreateProductQuestionMutation.js +8 -0
  144. package/cjs/graphql/operations/CreateProductReviewMutation.js +18 -0
  145. package/cjs/graphql/operations/CreateReturnMutation.js +22 -0
  146. package/cjs/graphql/operations/DeleteFavoriteMutation.js +3 -0
  147. package/cjs/graphql/operations/DeletePaymentSourceMutation.js +3 -0
  148. package/cjs/graphql/operations/DeleteProductQuestionAnswerMutation.js +3 -0
  149. package/cjs/graphql/operations/DeleteProductQuestionMutation.js +3 -0
  150. package/cjs/graphql/operations/DeleteProductReviewMutation.js +3 -0
  151. package/cjs/graphql/operations/DisconnectOAuth2Mutation.js +3 -0
  152. package/cjs/graphql/operations/EditSubscriptionMutation.js +3 -0
  153. package/cjs/graphql/operations/FileUploadedMutation.js +6 -0
  154. package/cjs/graphql/operations/FlagQuestionAnswerMutation.js +3 -0
  155. package/cjs/graphql/operations/FlagQuestionMutation.js +3 -0
  156. package/cjs/graphql/operations/FlagReviewAnswerMutation.js +3 -0
  157. package/cjs/graphql/operations/FlagReviewMutation.js +3 -0
  158. package/cjs/graphql/operations/GetBrandingQuery.js +10 -0
  159. package/cjs/graphql/operations/GetCartQuery.js +26 -0
  160. package/cjs/graphql/operations/GetCustomerAddressesPageDataQuery.js +16 -0
  161. package/cjs/graphql/operations/GetCustomerBalanceHistoryPageQuery.js +6 -0
  162. package/cjs/graphql/operations/GetCustomerBalanceQuery.js +8 -0
  163. package/cjs/graphql/operations/GetCustomerInfoQuery.js +10 -0
  164. package/cjs/graphql/operations/GetCustomerQuery.js +8 -0
  165. package/cjs/graphql/operations/GetFavoritesQuery.js +22 -0
  166. package/cjs/graphql/operations/GetFileStatusQuery.js +6 -0
  167. package/cjs/graphql/operations/GetGatewaysQuery.js +14 -0
  168. package/cjs/graphql/operations/GetInfoCurrenciesQuery.js +6 -0
  169. package/cjs/graphql/operations/GetLastCartQuery.js +26 -0
  170. package/cjs/graphql/operations/GetOrderQuery.js +30 -0
  171. package/cjs/graphql/operations/GetOrdersPageQuery.js +24 -0
  172. package/cjs/graphql/operations/GetPaymentMethodsPageDataQuery.js +18 -0
  173. package/cjs/graphql/operations/GetProductQuestionsPageQuery.js +10 -0
  174. package/cjs/graphql/operations/GetProductReviewImagesPageQuery.js +8 -0
  175. package/cjs/graphql/operations/GetProductReviewsPageQuery.js +20 -0
  176. package/cjs/graphql/operations/GetProvincesQuery.js +6 -0
  177. package/cjs/graphql/operations/GetQuestionQuery.js +8 -0
  178. package/cjs/graphql/operations/GetReturnCreationInfoQuery.js +36 -0
  179. package/cjs/graphql/operations/GetReturnQuery.js +28 -0
  180. package/cjs/graphql/operations/GetReturnsPageQuery.js +22 -0
  181. package/cjs/graphql/operations/GetReviewDimensionsQuery.js +6 -0
  182. package/cjs/graphql/operations/GetReviewQuery.js +18 -0
  183. package/cjs/graphql/operations/GetReviewSettingsQuery.js +12 -0
  184. package/cjs/graphql/operations/GetShopCurrenciesQuery.js +6 -0
  185. package/cjs/graphql/operations/GetShopQuery.js +8 -0
  186. package/cjs/graphql/operations/GetSubscriptionQuery.js +36 -0
  187. package/cjs/graphql/operations/GetSubscriptionsPageQuery.js +22 -0
  188. package/cjs/graphql/operations/GetVariantPageQuery.js +20 -0
  189. package/cjs/graphql/operations/LoadProductNoCustomerQuery.js +62 -0
  190. package/cjs/graphql/operations/LoadProductQuery.js +66 -0
  191. package/cjs/graphql/operations/ModifyCartMutation.js +26 -0
  192. package/cjs/graphql/operations/ModifyCustomerMutation.js +8 -0
  193. package/cjs/graphql/operations/ModifyFavoriteMutation.js +22 -0
  194. package/cjs/graphql/operations/ModifyProductQuestionAnswerMutation.js +3 -0
  195. package/cjs/graphql/operations/ModifyProductQuestionMutation.js +8 -0
  196. package/cjs/graphql/operations/ModifyProductReviewMutation.js +18 -0
  197. package/cjs/graphql/operations/NewPasswordMutation.js +3 -0
  198. package/cjs/graphql/operations/PauseSubscriptionMutation.js +3 -0
  199. package/cjs/graphql/operations/ResetPasswordMutation.js +3 -0
  200. package/cjs/graphql/operations/ResumeSubscriptionMutation.js +3 -0
  201. package/cjs/graphql/operations/SearchProductsAdvancedQuery.js +24 -0
  202. package/cjs/graphql/operations/SearchProductsQuery.js +20 -0
  203. package/cjs/graphql/operations/SearchQuestionsQuery.js +8 -0
  204. package/cjs/graphql/operations/SearchReviewsQuery.js +18 -0
  205. package/cjs/graphql/operations/SignInMutation.js +3 -0
  206. package/cjs/graphql/operations/SignInViaEmailCompleteMutation.js +3 -0
  207. package/cjs/graphql/operations/SignInViaEmailInitMutation.js +3 -0
  208. package/cjs/graphql/operations/SignUpMutation.js +3 -0
  209. package/cjs/graphql/operations/SkipNextSubscriptionMutation.js +3 -0
  210. package/cjs/graphql/operations/UploadFileMutation.js +3 -0
  211. package/cjs/graphql/operations/VerifyCodeMutation.js +3 -0
  212. package/cjs/graphql/operations/VoteQuestionAnswerMutation.js +3 -0
  213. package/cjs/graphql/operations/VoteQuestionMutation.js +3 -0
  214. package/cjs/graphql/operations/VoteReviewAnswerMutation.js +3 -0
  215. package/cjs/graphql/operations/VoteReviewMutation.js +3 -0
  216. package/cjs/graphql/types.js +2 -0
  217. package/cjs/hierarchicalSearchOption.js +42 -0
  218. package/cjs/idgen.js +8 -0
  219. package/cjs/ignoreQueue.js +50 -0
  220. package/cjs/imageAltProps.js +13 -0
  221. package/cjs/invoiceFormat.js +59 -0
  222. package/cjs/isShippingRequired.js +20 -0
  223. package/cjs/isoStripTrailingZeros.js +7 -0
  224. package/cjs/json/commerce.js +10 -0
  225. package/cjs/json/commerceFileUpload.js +57 -0
  226. package/cjs/json/commerceTypes.js +2 -0
  227. package/cjs/json/common.js +320 -0
  228. package/cjs/json/fetchAllItems.js +61 -0
  229. package/cjs/json/mutator.js +957 -0
  230. package/cjs/json/storefront.js +10 -0
  231. package/cjs/json/storefrontTypes.js +2 -0
  232. package/cjs/lastValue.js +17 -0
  233. package/cjs/lineItemPrice.js +111 -0
  234. package/cjs/loadJWT.js +25 -0
  235. package/cjs/mapInvalidInput.js +33 -0
  236. package/cjs/mapResponseData.js +16 -0
  237. package/cjs/mapResponseMultiData.js +14 -0
  238. package/cjs/meanBy.js +15 -0
  239. package/cjs/media.js +16 -0
  240. package/cjs/modules/advancedSearch.js +127 -0
  241. package/cjs/modules/cart.js +708 -0
  242. package/cjs/modules/config/defaultAdvancedSearchGraphQLConfig.js +8 -0
  243. package/cjs/modules/config/defaultCartGraphQLConfig.js +14 -0
  244. package/cjs/modules/config/defaultProductGraphQLConfig.js +48 -0
  245. package/cjs/modules/config/defaultSearchGraphQLConfig.js +8 -0
  246. package/cjs/modules/customer.js +2174 -0
  247. package/cjs/modules/helpers/cartInitOption.js +22 -0
  248. package/cjs/modules/helpers/cookieConsent.js +33 -0
  249. package/cjs/modules/helpers/customerOauth2.js +64 -0
  250. package/cjs/modules/helpers/getOAuth2Hook.js +52 -0
  251. package/cjs/modules/helpers/hookUpAnalytics.js +49 -0
  252. package/cjs/modules/helpers/loadJWT.js +23 -0
  253. package/cjs/modules/helpers/misc.js +58 -0
  254. package/cjs/modules/imageDialog.js +78 -0
  255. package/cjs/modules/persist.js +55 -0
  256. package/cjs/modules/popupMessage.js +21 -0
  257. package/cjs/modules/product.js +1261 -0
  258. package/cjs/modules/recentlyVisitedProducts.js +72 -0
  259. package/cjs/modules/search.js +102 -0
  260. package/cjs/multiResponseToResponse.js +22 -0
  261. package/cjs/nonNull.js +10 -0
  262. package/cjs/oauthState.js +40 -0
  263. package/cjs/orderShippingAddress.js +7 -0
  264. package/cjs/package.json +3 -0
  265. package/cjs/pender.js +16 -0
  266. package/cjs/percentageOff.js +7 -0
  267. package/cjs/popupConnectQueue.js +62 -0
  268. package/cjs/preact/components/SixDigitInput.js +167 -0
  269. package/cjs/preact/effector.js +74 -0
  270. package/cjs/preact/transition/CSSTransition.js +55 -0
  271. package/cjs/preact/transition/Transition.js +104 -0
  272. package/cjs/preact/translateLocalStatic.js +31 -0
  273. package/cjs/productFiltering.js +173 -0
  274. package/cjs/productSEO.js +51 -0
  275. package/cjs/productSorting.js +93 -0
  276. package/cjs/promiseAll.js +18 -0
  277. package/cjs/promiseLimit.js +38 -0
  278. package/cjs/rdsToInitialScores.js +32 -0
  279. package/cjs/react/components/Portal.js +7 -0
  280. package/cjs/react/components/RootCloseWrapper.js +41 -0
  281. package/cjs/react/components/SixDigitInput.js +167 -0
  282. package/cjs/react/contains.js +14 -0
  283. package/cjs/react/popperBinder.js +70 -0
  284. package/cjs/react/rootClose.js +112 -0
  285. package/cjs/react/translateLocalStatic.js +32 -0
  286. package/cjs/react/useAsyncCachedValue.js +14 -0
  287. package/cjs/refreshTimeout.js +25 -0
  288. package/cjs/remoteAuth.js +59 -0
  289. package/cjs/request.js +348 -0
  290. package/cjs/requestDetails.js +76 -0
  291. package/cjs/rfc3339Normalize.js +10 -0
  292. package/cjs/script.js +172 -0
  293. package/cjs/seo.js +2 -0
  294. package/cjs/shopDomain.js +8 -0
  295. package/cjs/shopLinks.js +63 -0
  296. package/cjs/slate.js +376 -0
  297. package/cjs/sleep.js +10 -0
  298. package/cjs/splitBy.js +21 -0
  299. package/cjs/splitName.js +28 -0
  300. package/cjs/stripZeros.js +13 -0
  301. package/cjs/stripeError.js +65 -0
  302. package/cjs/tailSplit.js +12 -0
  303. package/cjs/tieredPrice.js +32 -0
  304. package/cjs/timeIt.js +15 -0
  305. package/cjs/toMajor.js +8 -0
  306. package/cjs/toMinor.js +8 -0
  307. package/cjs/trace.js +37 -0
  308. package/cjs/translateLocale.js +12 -0
  309. package/cjs/traverse.js +14 -0
  310. package/cjs/truncate.js +21 -0
  311. package/cjs/typedLocalStorage.js +30 -0
  312. package/cjs/variantImage.js +26 -0
  313. package/cjs/variantImageURL.js +13 -0
  314. package/cjs/variantImages.js +19 -0
  315. package/cjs/variantInventory.js +43 -0
  316. package/cjs/variantOptions.js +21 -0
  317. package/cjs/variantPrice.js +96 -0
  318. package/cjs/variantPriceCommerce.js +29 -0
  319. package/cjs/variantTitle.js +9 -0
  320. package/cjs/variantTitleFull.js +11 -0
  321. package/cjs/variantURL.js +9 -0
  322. package/cjs/vendor/popper/index.d.ts +160 -0
  323. package/cjs/vendor/popper/index.js +2657 -0
  324. package/cjs/vendor/popper/index.js.map +1 -0
  325. package/cjs/vendor/popper/package.json +3 -0
  326. package/cjs/websocket.js +179 -0
  327. package/esm/actionLock.js +24 -0
  328. package/esm/addEmptyListItem.js +3 -0
  329. package/esm/aggregateOptions.js +169 -0
  330. package/esm/analytics.js +91 -0
  331. package/esm/analyticsProductData.js +28 -0
  332. package/esm/arrayToDict.js +8 -0
  333. package/esm/asyncModuleWrapper.js +47 -0
  334. package/esm/averageReviewScore.js +40 -0
  335. package/esm/buildconfig.js +13 -0
  336. package/esm/cachedLoader.js +32 -0
  337. package/esm/canonicalVariantURL.js +1 -0
  338. package/esm/cartOperation.js +126 -0
  339. package/esm/categorySEO.js +16 -0
  340. package/esm/commonTypes.js +1 -0
  341. package/esm/compact.js +4 -0
  342. package/esm/configLoader.js +61 -0
  343. package/esm/controlledQueue.js +38 -0
  344. package/esm/convertImageURL.js +15 -0
  345. package/esm/dataLoader.js +192 -0
  346. package/esm/defaultVariant.js +25 -0
  347. package/esm/effector/clearOnChangeAfterDelay.js +13 -0
  348. package/esm/effector/combineEvery.js +4 -0
  349. package/esm/effector/combineSome.js +4 -0
  350. package/esm/effector/debounced.js +14 -0
  351. package/esm/effector/form.js +166 -0
  352. package/esm/effector/hideOnChangeAfterDelay.js +13 -0
  353. package/esm/effector/requestResponse.js +24 -0
  354. package/esm/effector/requestResponseMulti.js +47 -0
  355. package/esm/effector/restoreNamed.js +4 -0
  356. package/esm/effector/split.js +25 -0
  357. package/esm/effector/validator.js +28 -0
  358. package/esm/effector/wrapSignInRequired.js +9 -0
  359. package/esm/exceptions.js +2 -0
  360. package/esm/fetchAllItems.js +44 -0
  361. package/esm/file.js +67 -0
  362. package/esm/fileWebsocket.js +75 -0
  363. package/esm/filterFunc.js +43 -0
  364. package/esm/filterFuncBrand.js +9 -0
  365. package/esm/filterFuncCategory.js +9 -0
  366. package/esm/filterFuncContentBlock.js +16 -0
  367. package/esm/filterFuncCustomer.js +153 -0
  368. package/esm/filterFuncDataFeed.js +50 -0
  369. package/esm/filterFuncOrder.js +325 -0
  370. package/esm/filterFuncPreprocess.js +9 -0
  371. package/esm/filterFuncProduct.js +66 -0
  372. package/esm/filterFuncPurchaseOrder.js +122 -0
  373. package/esm/filterFuncSupplier.js +31 -0
  374. package/esm/filterFuncTransfer.js +130 -0
  375. package/esm/formatAbbrevNumber.js +16 -0
  376. package/esm/formatCurrency.js +42 -0
  377. package/esm/formatToJSX.js +118 -0
  378. package/esm/fulfillmentNumber.js +3 -0
  379. package/esm/generateRandomToken.js +8 -0
  380. package/esm/generateUUID.js +6 -0
  381. package/esm/generated/codes.js +44 -0
  382. package/esm/genericFile.js +65 -0
  383. package/esm/getSalesChannelID.js +9 -0
  384. package/esm/getSessionID.js +9 -0
  385. package/esm/getTimezone.js +8 -0
  386. package/esm/graphql/fragments/Branding.js +1 -0
  387. package/esm/graphql/fragments/BrandingField.js +1 -0
  388. package/esm/graphql/fragments/CartCustomItem.js +1 -0
  389. package/esm/graphql/fragments/CartOrder.js +1 -0
  390. package/esm/graphql/fragments/CartVariant.js +1 -0
  391. package/esm/graphql/fragments/CartVariantFull.js +1 -0
  392. package/esm/graphql/fragments/Category.js +1 -0
  393. package/esm/graphql/fragments/CommonCartVariant.js +1 -0
  394. package/esm/graphql/fragments/Currency.js +1 -0
  395. package/esm/graphql/fragments/CurrencyPrice.js +1 -0
  396. package/esm/graphql/fragments/CustomField.js +1 -0
  397. package/esm/graphql/fragments/CustomFieldObjects.js +1 -0
  398. package/esm/graphql/fragments/Customer.js +1 -0
  399. package/esm/graphql/fragments/CustomerBalance.js +1 -0
  400. package/esm/graphql/fragments/CustomerBalanceHistory.js +1 -0
  401. package/esm/graphql/fragments/CustomerFavorite.js +1 -0
  402. package/esm/graphql/fragments/CustomerFavoriteShort.js +1 -0
  403. package/esm/graphql/fragments/CustomerOAuthProvider.js +1 -0
  404. package/esm/graphql/fragments/CustomerOrderBrief.js +1 -0
  405. package/esm/graphql/fragments/CustomerOrderFulfillment.js +1 -0
  406. package/esm/graphql/fragments/CustomerOrderFull.js +1 -0
  407. package/esm/graphql/fragments/CustomerPaymentSource.js +1 -0
  408. package/esm/graphql/fragments/CustomerReturnBrief.js +1 -0
  409. package/esm/graphql/fragments/CustomerReturnFull.js +1 -0
  410. package/esm/graphql/fragments/CustomerReturnPolicy.js +1 -0
  411. package/esm/graphql/fragments/CustomerSubscriptionBrief.js +1 -0
  412. package/esm/graphql/fragments/CustomerSubscriptionFull.js +1 -0
  413. package/esm/graphql/fragments/File.js +1 -0
  414. package/esm/graphql/fragments/FileForUpload.js +1 -0
  415. package/esm/graphql/fragments/FileNoFallback.js +1 -0
  416. package/esm/graphql/fragments/FullAddress.js +1 -0
  417. package/esm/graphql/fragments/Gateway.js +1 -0
  418. package/esm/graphql/fragments/GatewayManual.js +1 -0
  419. package/esm/graphql/fragments/GatewayPaypal.js +1 -0
  420. package/esm/graphql/fragments/GatewayStripe.js +1 -0
  421. package/esm/graphql/fragments/GatewayTest.js +1 -0
  422. package/esm/graphql/fragments/IPAndUAInfo.js +1 -0
  423. package/esm/graphql/fragments/InfoCountry.js +1 -0
  424. package/esm/graphql/fragments/InfoCountryDedupField.js +1 -0
  425. package/esm/graphql/fragments/InfoCurrency.js +1 -0
  426. package/esm/graphql/fragments/InfoProvince.js +1 -0
  427. package/esm/graphql/fragments/KeyValue.js +1 -0
  428. package/esm/graphql/fragments/LineItemField.js +1 -0
  429. package/esm/graphql/fragments/MediaFile.js +1 -0
  430. package/esm/graphql/fragments/MinCurrencyPrice.js +1 -0
  431. package/esm/graphql/fragments/ProductField.js +1 -0
  432. package/esm/graphql/fragments/ProductFieldSet.js +1 -0
  433. package/esm/graphql/fragments/ProductFlat.js +1 -0
  434. package/esm/graphql/fragments/ProductQuestion.js +1 -0
  435. package/esm/graphql/fragments/ProductQuestionAnswer.js +1 -0
  436. package/esm/graphql/fragments/ProductQuestionPage.js +1 -0
  437. package/esm/graphql/fragments/ProductReview.js +1 -0
  438. package/esm/graphql/fragments/ProductReviewAnswer.js +1 -0
  439. package/esm/graphql/fragments/ProductReviewAverageScore.js +1 -0
  440. package/esm/graphql/fragments/ProductReviewPage.js +1 -0
  441. package/esm/graphql/fragments/ProductReviewScore.js +1 -0
  442. package/esm/graphql/fragments/ProductReviewSurveyAnswer.js +1 -0
  443. package/esm/graphql/fragments/ProductSearchOptionAgg.js +1 -0
  444. package/esm/graphql/fragments/ProductSearchResult.js +1 -0
  445. package/esm/graphql/fragments/ReturnReason.js +1 -0
  446. package/esm/graphql/fragments/ReviewDimension.js +1 -0
  447. package/esm/graphql/fragments/ReviewDimensionSet.js +1 -0
  448. package/esm/graphql/fragments/ReviewImagePage.js +1 -0
  449. package/esm/graphql/fragments/ReviewQuestionProduct.js +1 -0
  450. package/esm/graphql/fragments/ReviewSettings.js +1 -0
  451. package/esm/graphql/fragments/SearchProduct.js +1 -0
  452. package/esm/graphql/fragments/Shop.js +1 -0
  453. package/esm/graphql/fragments/SubscriptionPlan.js +1 -0
  454. package/esm/graphql/fragments/SurveyQuestion.js +1 -0
  455. package/esm/graphql/fragments/TieredPricing.js +1 -0
  456. package/esm/graphql/fragments/TieredPricingTier.js +1 -0
  457. package/esm/graphql/fragments/VariantOption.js +1 -0
  458. package/esm/graphql/operations/ApplyGiftCardMutation.js +1 -0
  459. package/esm/graphql/operations/AuthRequestMutation.js +1 -0
  460. package/esm/graphql/operations/CancelOrderMutation.js +1 -0
  461. package/esm/graphql/operations/CancelSubscriptionMutation.js +1 -0
  462. package/esm/graphql/operations/ConnectOAuth2Mutation.js +1 -0
  463. package/esm/graphql/operations/CreateCartMutation.js +23 -0
  464. package/esm/graphql/operations/CreateFavoriteMutation.js +19 -0
  465. package/esm/graphql/operations/CreateFileMutation.js +3 -0
  466. package/esm/graphql/operations/CreatePaymentSourceMutation.js +3 -0
  467. package/esm/graphql/operations/CreateProductQuestionAnswerMutation.js +1 -0
  468. package/esm/graphql/operations/CreateProductQuestionMutation.js +5 -0
  469. package/esm/graphql/operations/CreateProductReviewMutation.js +15 -0
  470. package/esm/graphql/operations/CreateReturnMutation.js +19 -0
  471. package/esm/graphql/operations/DeleteFavoriteMutation.js +1 -0
  472. package/esm/graphql/operations/DeletePaymentSourceMutation.js +1 -0
  473. package/esm/graphql/operations/DeleteProductQuestionAnswerMutation.js +1 -0
  474. package/esm/graphql/operations/DeleteProductQuestionMutation.js +1 -0
  475. package/esm/graphql/operations/DeleteProductReviewMutation.js +1 -0
  476. package/esm/graphql/operations/DisconnectOAuth2Mutation.js +1 -0
  477. package/esm/graphql/operations/EditSubscriptionMutation.js +1 -0
  478. package/esm/graphql/operations/FileUploadedMutation.js +3 -0
  479. package/esm/graphql/operations/FlagQuestionAnswerMutation.js +1 -0
  480. package/esm/graphql/operations/FlagQuestionMutation.js +1 -0
  481. package/esm/graphql/operations/FlagReviewAnswerMutation.js +1 -0
  482. package/esm/graphql/operations/FlagReviewMutation.js +1 -0
  483. package/esm/graphql/operations/GetBrandingQuery.js +7 -0
  484. package/esm/graphql/operations/GetCartQuery.js +23 -0
  485. package/esm/graphql/operations/GetCustomerAddressesPageDataQuery.js +13 -0
  486. package/esm/graphql/operations/GetCustomerBalanceHistoryPageQuery.js +3 -0
  487. package/esm/graphql/operations/GetCustomerBalanceQuery.js +5 -0
  488. package/esm/graphql/operations/GetCustomerInfoQuery.js +7 -0
  489. package/esm/graphql/operations/GetCustomerQuery.js +5 -0
  490. package/esm/graphql/operations/GetFavoritesQuery.js +19 -0
  491. package/esm/graphql/operations/GetFileStatusQuery.js +3 -0
  492. package/esm/graphql/operations/GetGatewaysQuery.js +11 -0
  493. package/esm/graphql/operations/GetInfoCurrenciesQuery.js +3 -0
  494. package/esm/graphql/operations/GetLastCartQuery.js +23 -0
  495. package/esm/graphql/operations/GetOrderQuery.js +27 -0
  496. package/esm/graphql/operations/GetOrdersPageQuery.js +21 -0
  497. package/esm/graphql/operations/GetPaymentMethodsPageDataQuery.js +15 -0
  498. package/esm/graphql/operations/GetProductQuestionsPageQuery.js +7 -0
  499. package/esm/graphql/operations/GetProductReviewImagesPageQuery.js +5 -0
  500. package/esm/graphql/operations/GetProductReviewsPageQuery.js +17 -0
  501. package/esm/graphql/operations/GetProvincesQuery.js +3 -0
  502. package/esm/graphql/operations/GetQuestionQuery.js +5 -0
  503. package/esm/graphql/operations/GetReturnCreationInfoQuery.js +33 -0
  504. package/esm/graphql/operations/GetReturnQuery.js +25 -0
  505. package/esm/graphql/operations/GetReturnsPageQuery.js +19 -0
  506. package/esm/graphql/operations/GetReviewDimensionsQuery.js +3 -0
  507. package/esm/graphql/operations/GetReviewQuery.js +15 -0
  508. package/esm/graphql/operations/GetReviewSettingsQuery.js +9 -0
  509. package/esm/graphql/operations/GetShopCurrenciesQuery.js +3 -0
  510. package/esm/graphql/operations/GetShopQuery.js +5 -0
  511. package/esm/graphql/operations/GetSubscriptionQuery.js +33 -0
  512. package/esm/graphql/operations/GetSubscriptionsPageQuery.js +19 -0
  513. package/esm/graphql/operations/GetVariantPageQuery.js +17 -0
  514. package/esm/graphql/operations/LoadProductNoCustomerQuery.js +59 -0
  515. package/esm/graphql/operations/LoadProductQuery.js +63 -0
  516. package/esm/graphql/operations/ModifyCartMutation.js +23 -0
  517. package/esm/graphql/operations/ModifyCustomerMutation.js +5 -0
  518. package/esm/graphql/operations/ModifyFavoriteMutation.js +19 -0
  519. package/esm/graphql/operations/ModifyProductQuestionAnswerMutation.js +1 -0
  520. package/esm/graphql/operations/ModifyProductQuestionMutation.js +5 -0
  521. package/esm/graphql/operations/ModifyProductReviewMutation.js +15 -0
  522. package/esm/graphql/operations/NewPasswordMutation.js +1 -0
  523. package/esm/graphql/operations/PauseSubscriptionMutation.js +1 -0
  524. package/esm/graphql/operations/ResetPasswordMutation.js +1 -0
  525. package/esm/graphql/operations/ResumeSubscriptionMutation.js +1 -0
  526. package/esm/graphql/operations/SearchProductsAdvancedQuery.js +21 -0
  527. package/esm/graphql/operations/SearchProductsQuery.js +17 -0
  528. package/esm/graphql/operations/SearchQuestionsQuery.js +5 -0
  529. package/esm/graphql/operations/SearchReviewsQuery.js +15 -0
  530. package/esm/graphql/operations/SignInMutation.js +1 -0
  531. package/esm/graphql/operations/SignInViaEmailCompleteMutation.js +1 -0
  532. package/esm/graphql/operations/SignInViaEmailInitMutation.js +1 -0
  533. package/esm/graphql/operations/SignUpMutation.js +1 -0
  534. package/esm/graphql/operations/SkipNextSubscriptionMutation.js +1 -0
  535. package/esm/graphql/operations/UploadFileMutation.js +1 -0
  536. package/esm/graphql/operations/VerifyCodeMutation.js +1 -0
  537. package/esm/graphql/operations/VoteQuestionAnswerMutation.js +1 -0
  538. package/esm/graphql/operations/VoteQuestionMutation.js +1 -0
  539. package/esm/graphql/operations/VoteReviewAnswerMutation.js +1 -0
  540. package/esm/graphql/operations/VoteReviewMutation.js +1 -0
  541. package/esm/graphql/types.js +1 -0
  542. package/esm/hierarchicalSearchOption.js +43 -0
  543. package/esm/idgen.js +4 -0
  544. package/esm/ignoreQueue.js +45 -0
  545. package/esm/imageAltProps.js +9 -0
  546. package/esm/invoiceFormat.js +54 -0
  547. package/esm/isShippingRequired.js +16 -0
  548. package/esm/isoStripTrailingZeros.js +3 -0
  549. package/esm/json/commerce.js +3 -0
  550. package/esm/json/commerceFileUpload.js +43 -0
  551. package/esm/json/commerceTypes.js +1 -0
  552. package/esm/json/common.js +309 -0
  553. package/esm/json/fetchAllItems.js +51 -0
  554. package/esm/json/mutator.js +952 -0
  555. package/esm/json/storefront.js +3 -0
  556. package/esm/json/storefrontTypes.js +1 -0
  557. package/esm/lastValue.js +12 -0
  558. package/esm/lineItemPrice.js +106 -0
  559. package/esm/loadJWT.js +20 -0
  560. package/esm/mapInvalidInput.js +27 -0
  561. package/esm/mapResponseData.js +11 -0
  562. package/esm/mapResponseMultiData.js +10 -0
  563. package/esm/meanBy.js +11 -0
  564. package/esm/media.js +12 -0
  565. package/esm/modules/advancedSearch.js +132 -0
  566. package/esm/modules/cart.js +699 -0
  567. package/esm/modules/config/defaultAdvancedSearchGraphQLConfig.js +4 -0
  568. package/esm/modules/config/defaultCartGraphQLConfig.js +10 -0
  569. package/esm/modules/config/defaultProductGraphQLConfig.js +44 -0
  570. package/esm/modules/config/defaultSearchGraphQLConfig.js +4 -0
  571. package/esm/modules/customer.js +2198 -0
  572. package/esm/modules/helpers/cartInitOption.js +18 -0
  573. package/esm/modules/helpers/cookieConsent.js +29 -0
  574. package/esm/modules/helpers/customerOauth2.js +53 -0
  575. package/esm/modules/helpers/getOAuth2Hook.js +48 -0
  576. package/esm/modules/helpers/hookUpAnalytics.js +44 -0
  577. package/esm/modules/helpers/loadJWT.js +18 -0
  578. package/esm/modules/helpers/misc.js +49 -0
  579. package/esm/modules/imageDialog.js +71 -0
  580. package/esm/modules/persist.js +49 -0
  581. package/esm/modules/popupMessage.js +17 -0
  582. package/esm/modules/product.js +1278 -0
  583. package/esm/modules/recentlyVisitedProducts.js +70 -0
  584. package/esm/modules/search.js +103 -0
  585. package/esm/multiResponseToResponse.js +18 -0
  586. package/esm/nonNull.js +6 -0
  587. package/esm/oauthState.js +35 -0
  588. package/esm/orderShippingAddress.js +3 -0
  589. package/esm/package.json +3 -0
  590. package/esm/pender.js +11 -0
  591. package/esm/percentageOff.js +3 -0
  592. package/esm/popupConnectQueue.js +55 -0
  593. package/esm/preact/components/SixDigitInput.js +159 -0
  594. package/esm/preact/effector.js +69 -0
  595. package/esm/preact/transition/CSSTransition.js +47 -0
  596. package/esm/preact/transition/Transition.js +100 -0
  597. package/esm/preact/translateLocalStatic.js +26 -0
  598. package/esm/productFiltering.js +164 -0
  599. package/esm/productSEO.js +46 -0
  600. package/esm/productSorting.js +89 -0
  601. package/esm/promiseAll.js +11 -0
  602. package/esm/promiseLimit.js +32 -0
  603. package/esm/rdsToInitialScores.js +27 -0
  604. package/esm/react/components/Portal.js +2 -0
  605. package/esm/react/components/RootCloseWrapper.js +33 -0
  606. package/esm/react/components/SixDigitInput.js +158 -0
  607. package/esm/react/contains.js +10 -0
  608. package/esm/react/popperBinder.js +71 -0
  609. package/esm/react/rootClose.js +106 -0
  610. package/esm/react/translateLocalStatic.js +26 -0
  611. package/esm/react/useAsyncCachedValue.js +10 -0
  612. package/esm/refreshTimeout.js +21 -0
  613. package/esm/remoteAuth.js +52 -0
  614. package/esm/request.js +323 -0
  615. package/esm/requestDetails.js +69 -0
  616. package/esm/rfc3339Normalize.js +6 -0
  617. package/esm/script.js +157 -0
  618. package/esm/seo.js +1 -0
  619. package/esm/shopDomain.js +4 -0
  620. package/esm/shopLinks.js +47 -0
  621. package/esm/slate.js +364 -0
  622. package/esm/sleep.js +3 -0
  623. package/esm/splitBy.js +17 -0
  624. package/esm/splitName.js +22 -0
  625. package/esm/stripZeros.js +9 -0
  626. package/esm/stripeError.js +53 -0
  627. package/esm/tailSplit.js +8 -0
  628. package/esm/tieredPrice.js +28 -0
  629. package/esm/timeIt.js +8 -0
  630. package/esm/toMajor.js +4 -0
  631. package/esm/toMinor.js +4 -0
  632. package/esm/trace.js +37 -0
  633. package/esm/translateLocale.js +7 -0
  634. package/esm/traverse.js +10 -0
  635. package/esm/truncate.js +17 -0
  636. package/esm/typedLocalStorage.js +24 -0
  637. package/esm/variantImage.js +22 -0
  638. package/esm/variantImageURL.js +9 -0
  639. package/esm/variantImages.js +15 -0
  640. package/esm/variantInventory.js +38 -0
  641. package/esm/variantOptions.js +15 -0
  642. package/esm/variantPrice.js +92 -0
  643. package/esm/variantPriceCommerce.js +25 -0
  644. package/esm/variantTitle.js +5 -0
  645. package/esm/variantTitleFull.js +7 -0
  646. package/esm/variantURL.js +5 -0
  647. package/esm/vendor/popper/index.d.ts +160 -0
  648. package/esm/vendor/popper/index.js +2657 -0
  649. package/esm/vendor/popper/index.js.map +1 -0
  650. package/esm/vendor/popper/package.json +3 -0
  651. package/esm/websocket.js +169 -0
  652. package/package.json +92 -0
  653. package/types/actionLock.d.ts +7 -0
  654. package/types/addEmptyListItem.d.ts +2 -0
  655. package/types/aggregateOptions.d.ts +33 -0
  656. package/types/analytics.d.ts +23 -0
  657. package/types/analyticsProductData.d.ts +38 -0
  658. package/types/arrayToDict.d.ts +2 -0
  659. package/types/asyncModuleWrapper.d.ts +13 -0
  660. package/types/averageReviewScore.d.ts +28 -0
  661. package/types/buildconfig.d.ts +13 -0
  662. package/types/cachedLoader.d.ts +10 -0
  663. package/types/canonicalVariantURL.d.ts +12 -0
  664. package/types/cartOperation.d.ts +28 -0
  665. package/types/categorySEO.d.ts +17 -0
  666. package/types/commonTypes.d.ts +10 -0
  667. package/types/compact.d.ts +1 -0
  668. package/types/configLoader.d.ts +53 -0
  669. package/types/controlledQueue.d.ts +17 -0
  670. package/types/convertImageURL.d.ts +9 -0
  671. package/types/dataLoader.d.ts +301 -0
  672. package/types/defaultVariant.d.ts +9 -0
  673. package/types/effector/clearOnChangeAfterDelay.d.ts +2 -0
  674. package/types/effector/combineEvery.d.ts +2 -0
  675. package/types/effector/combineSome.d.ts +2 -0
  676. package/types/effector/debounced.d.ts +2 -0
  677. package/types/effector/form.d.ts +74 -0
  678. package/types/effector/hideOnChangeAfterDelay.d.ts +6 -0
  679. package/types/effector/requestResponse.d.ts +9 -0
  680. package/types/effector/requestResponseMulti.d.ts +7 -0
  681. package/types/effector/restoreNamed.d.ts +2 -0
  682. package/types/effector/split.d.ts +7 -0
  683. package/types/effector/validator.d.ts +14 -0
  684. package/types/effector/wrapSignInRequired.d.ts +2 -0
  685. package/types/exceptions.d.ts +2 -0
  686. package/types/fetchAllItems.d.ts +25 -0
  687. package/types/file.d.ts +4 -0
  688. package/types/fileWebsocket.d.ts +6 -0
  689. package/types/filterFunc.d.ts +8 -0
  690. package/types/filterFuncBrand.d.ts +3 -0
  691. package/types/filterFuncCategory.d.ts +3 -0
  692. package/types/filterFuncContentBlock.d.ts +3 -0
  693. package/types/filterFuncCustomer.d.ts +3 -0
  694. package/types/filterFuncDataFeed.d.ts +8 -0
  695. package/types/filterFuncOrder.d.ts +3 -0
  696. package/types/filterFuncPreprocess.d.ts +2 -0
  697. package/types/filterFuncProduct.d.ts +3 -0
  698. package/types/filterFuncPurchaseOrder.d.ts +3 -0
  699. package/types/filterFuncSupplier.d.ts +3 -0
  700. package/types/filterFuncTransfer.d.ts +3 -0
  701. package/types/formatAbbrevNumber.d.ts +6 -0
  702. package/types/formatCurrency.d.ts +44 -0
  703. package/types/formatToJSX.d.ts +24 -0
  704. package/types/fulfillmentNumber.d.ts +1 -0
  705. package/types/generateRandomToken.d.ts +1 -0
  706. package/types/generateUUID.d.ts +1 -0
  707. package/types/generated/codes.d.ts +234 -0
  708. package/types/genericFile.d.ts +57 -0
  709. package/types/getSalesChannelID.d.ts +1 -0
  710. package/types/getSessionID.d.ts +1 -0
  711. package/types/getTimezone.d.ts +1 -0
  712. package/types/graphql/fragments/Branding.d.ts +2 -0
  713. package/types/graphql/fragments/BrandingField.d.ts +2 -0
  714. package/types/graphql/fragments/CartCustomItem.d.ts +2 -0
  715. package/types/graphql/fragments/CartOrder.d.ts +2 -0
  716. package/types/graphql/fragments/CartVariant.d.ts +2 -0
  717. package/types/graphql/fragments/CartVariantFull.d.ts +2 -0
  718. package/types/graphql/fragments/Category.d.ts +2 -0
  719. package/types/graphql/fragments/CommonCartVariant.d.ts +2 -0
  720. package/types/graphql/fragments/Currency.d.ts +2 -0
  721. package/types/graphql/fragments/CurrencyPrice.d.ts +2 -0
  722. package/types/graphql/fragments/CustomField.d.ts +2 -0
  723. package/types/graphql/fragments/CustomFieldObjects.d.ts +2 -0
  724. package/types/graphql/fragments/Customer.d.ts +2 -0
  725. package/types/graphql/fragments/CustomerBalance.d.ts +2 -0
  726. package/types/graphql/fragments/CustomerBalanceHistory.d.ts +2 -0
  727. package/types/graphql/fragments/CustomerFavorite.d.ts +2 -0
  728. package/types/graphql/fragments/CustomerFavoriteShort.d.ts +2 -0
  729. package/types/graphql/fragments/CustomerOAuthProvider.d.ts +2 -0
  730. package/types/graphql/fragments/CustomerOrderBrief.d.ts +2 -0
  731. package/types/graphql/fragments/CustomerOrderFulfillment.d.ts +2 -0
  732. package/types/graphql/fragments/CustomerOrderFull.d.ts +2 -0
  733. package/types/graphql/fragments/CustomerPaymentSource.d.ts +2 -0
  734. package/types/graphql/fragments/CustomerReturnBrief.d.ts +2 -0
  735. package/types/graphql/fragments/CustomerReturnFull.d.ts +2 -0
  736. package/types/graphql/fragments/CustomerReturnPolicy.d.ts +2 -0
  737. package/types/graphql/fragments/CustomerSubscriptionBrief.d.ts +2 -0
  738. package/types/graphql/fragments/CustomerSubscriptionFull.d.ts +2 -0
  739. package/types/graphql/fragments/File.d.ts +2 -0
  740. package/types/graphql/fragments/FileForUpload.d.ts +2 -0
  741. package/types/graphql/fragments/FileNoFallback.d.ts +2 -0
  742. package/types/graphql/fragments/FullAddress.d.ts +2 -0
  743. package/types/graphql/fragments/Gateway.d.ts +2 -0
  744. package/types/graphql/fragments/GatewayManual.d.ts +2 -0
  745. package/types/graphql/fragments/GatewayPaypal.d.ts +2 -0
  746. package/types/graphql/fragments/GatewayStripe.d.ts +2 -0
  747. package/types/graphql/fragments/GatewayTest.d.ts +2 -0
  748. package/types/graphql/fragments/IPAndUAInfo.d.ts +2 -0
  749. package/types/graphql/fragments/InfoCountry.d.ts +2 -0
  750. package/types/graphql/fragments/InfoCountryDedupField.d.ts +2 -0
  751. package/types/graphql/fragments/InfoCurrency.d.ts +2 -0
  752. package/types/graphql/fragments/InfoProvince.d.ts +2 -0
  753. package/types/graphql/fragments/KeyValue.d.ts +2 -0
  754. package/types/graphql/fragments/LineItemField.d.ts +2 -0
  755. package/types/graphql/fragments/MediaFile.d.ts +2 -0
  756. package/types/graphql/fragments/MinCurrencyPrice.d.ts +2 -0
  757. package/types/graphql/fragments/ProductField.d.ts +2 -0
  758. package/types/graphql/fragments/ProductFieldSet.d.ts +2 -0
  759. package/types/graphql/fragments/ProductFlat.d.ts +2 -0
  760. package/types/graphql/fragments/ProductQuestion.d.ts +2 -0
  761. package/types/graphql/fragments/ProductQuestionAnswer.d.ts +2 -0
  762. package/types/graphql/fragments/ProductQuestionPage.d.ts +2 -0
  763. package/types/graphql/fragments/ProductReview.d.ts +2 -0
  764. package/types/graphql/fragments/ProductReviewAnswer.d.ts +2 -0
  765. package/types/graphql/fragments/ProductReviewAverageScore.d.ts +2 -0
  766. package/types/graphql/fragments/ProductReviewPage.d.ts +2 -0
  767. package/types/graphql/fragments/ProductReviewScore.d.ts +2 -0
  768. package/types/graphql/fragments/ProductReviewSurveyAnswer.d.ts +2 -0
  769. package/types/graphql/fragments/ProductSearchOptionAgg.d.ts +2 -0
  770. package/types/graphql/fragments/ProductSearchResult.d.ts +2 -0
  771. package/types/graphql/fragments/ReturnReason.d.ts +2 -0
  772. package/types/graphql/fragments/ReviewDimension.d.ts +2 -0
  773. package/types/graphql/fragments/ReviewDimensionSet.d.ts +2 -0
  774. package/types/graphql/fragments/ReviewImagePage.d.ts +2 -0
  775. package/types/graphql/fragments/ReviewQuestionProduct.d.ts +2 -0
  776. package/types/graphql/fragments/ReviewSettings.d.ts +2 -0
  777. package/types/graphql/fragments/SearchProduct.d.ts +2 -0
  778. package/types/graphql/fragments/Shop.d.ts +2 -0
  779. package/types/graphql/fragments/SubscriptionPlan.d.ts +2 -0
  780. package/types/graphql/fragments/SurveyQuestion.d.ts +2 -0
  781. package/types/graphql/fragments/TieredPricing.d.ts +2 -0
  782. package/types/graphql/fragments/TieredPricingTier.d.ts +2 -0
  783. package/types/graphql/fragments/VariantOption.d.ts +2 -0
  784. package/types/graphql/operations/ApplyGiftCardMutation.d.ts +3 -0
  785. package/types/graphql/operations/AuthRequestMutation.d.ts +3 -0
  786. package/types/graphql/operations/CancelOrderMutation.d.ts +3 -0
  787. package/types/graphql/operations/CancelSubscriptionMutation.d.ts +3 -0
  788. package/types/graphql/operations/ConnectOAuth2Mutation.d.ts +3 -0
  789. package/types/graphql/operations/CreateCartMutation.d.ts +3 -0
  790. package/types/graphql/operations/CreateFavoriteMutation.d.ts +3 -0
  791. package/types/graphql/operations/CreateFileMutation.d.ts +3 -0
  792. package/types/graphql/operations/CreatePaymentSourceMutation.d.ts +3 -0
  793. package/types/graphql/operations/CreateProductQuestionAnswerMutation.d.ts +3 -0
  794. package/types/graphql/operations/CreateProductQuestionMutation.d.ts +3 -0
  795. package/types/graphql/operations/CreateProductReviewMutation.d.ts +3 -0
  796. package/types/graphql/operations/CreateReturnMutation.d.ts +3 -0
  797. package/types/graphql/operations/DeleteFavoriteMutation.d.ts +3 -0
  798. package/types/graphql/operations/DeletePaymentSourceMutation.d.ts +3 -0
  799. package/types/graphql/operations/DeleteProductQuestionAnswerMutation.d.ts +3 -0
  800. package/types/graphql/operations/DeleteProductQuestionMutation.d.ts +3 -0
  801. package/types/graphql/operations/DeleteProductReviewMutation.d.ts +3 -0
  802. package/types/graphql/operations/DisconnectOAuth2Mutation.d.ts +3 -0
  803. package/types/graphql/operations/EditSubscriptionMutation.d.ts +3 -0
  804. package/types/graphql/operations/FileUploadedMutation.d.ts +3 -0
  805. package/types/graphql/operations/FlagQuestionAnswerMutation.d.ts +3 -0
  806. package/types/graphql/operations/FlagQuestionMutation.d.ts +3 -0
  807. package/types/graphql/operations/FlagReviewAnswerMutation.d.ts +3 -0
  808. package/types/graphql/operations/FlagReviewMutation.d.ts +3 -0
  809. package/types/graphql/operations/GetBrandingQuery.d.ts +3 -0
  810. package/types/graphql/operations/GetCartQuery.d.ts +3 -0
  811. package/types/graphql/operations/GetCustomerAddressesPageDataQuery.d.ts +3 -0
  812. package/types/graphql/operations/GetCustomerBalanceHistoryPageQuery.d.ts +3 -0
  813. package/types/graphql/operations/GetCustomerBalanceQuery.d.ts +3 -0
  814. package/types/graphql/operations/GetCustomerInfoQuery.d.ts +3 -0
  815. package/types/graphql/operations/GetCustomerQuery.d.ts +3 -0
  816. package/types/graphql/operations/GetFavoritesQuery.d.ts +3 -0
  817. package/types/graphql/operations/GetFileStatusQuery.d.ts +3 -0
  818. package/types/graphql/operations/GetGatewaysQuery.d.ts +3 -0
  819. package/types/graphql/operations/GetInfoCurrenciesQuery.d.ts +3 -0
  820. package/types/graphql/operations/GetLastCartQuery.d.ts +3 -0
  821. package/types/graphql/operations/GetOrderQuery.d.ts +3 -0
  822. package/types/graphql/operations/GetOrdersPageQuery.d.ts +3 -0
  823. package/types/graphql/operations/GetPaymentMethodsPageDataQuery.d.ts +3 -0
  824. package/types/graphql/operations/GetProductQuestionsPageQuery.d.ts +3 -0
  825. package/types/graphql/operations/GetProductReviewImagesPageQuery.d.ts +3 -0
  826. package/types/graphql/operations/GetProductReviewsPageQuery.d.ts +3 -0
  827. package/types/graphql/operations/GetProvincesQuery.d.ts +3 -0
  828. package/types/graphql/operations/GetQuestionQuery.d.ts +3 -0
  829. package/types/graphql/operations/GetReturnCreationInfoQuery.d.ts +3 -0
  830. package/types/graphql/operations/GetReturnQuery.d.ts +3 -0
  831. package/types/graphql/operations/GetReturnsPageQuery.d.ts +3 -0
  832. package/types/graphql/operations/GetReviewDimensionsQuery.d.ts +3 -0
  833. package/types/graphql/operations/GetReviewQuery.d.ts +3 -0
  834. package/types/graphql/operations/GetReviewSettingsQuery.d.ts +3 -0
  835. package/types/graphql/operations/GetShopCurrenciesQuery.d.ts +3 -0
  836. package/types/graphql/operations/GetShopQuery.d.ts +3 -0
  837. package/types/graphql/operations/GetSubscriptionQuery.d.ts +3 -0
  838. package/types/graphql/operations/GetSubscriptionsPageQuery.d.ts +3 -0
  839. package/types/graphql/operations/GetVariantPageQuery.d.ts +3 -0
  840. package/types/graphql/operations/LoadProductNoCustomerQuery.d.ts +3 -0
  841. package/types/graphql/operations/LoadProductQuery.d.ts +3 -0
  842. package/types/graphql/operations/ModifyCartMutation.d.ts +3 -0
  843. package/types/graphql/operations/ModifyCustomerMutation.d.ts +3 -0
  844. package/types/graphql/operations/ModifyFavoriteMutation.d.ts +3 -0
  845. package/types/graphql/operations/ModifyProductQuestionAnswerMutation.d.ts +3 -0
  846. package/types/graphql/operations/ModifyProductQuestionMutation.d.ts +3 -0
  847. package/types/graphql/operations/ModifyProductReviewMutation.d.ts +3 -0
  848. package/types/graphql/operations/NewPasswordMutation.d.ts +3 -0
  849. package/types/graphql/operations/PauseSubscriptionMutation.d.ts +3 -0
  850. package/types/graphql/operations/ResetPasswordMutation.d.ts +3 -0
  851. package/types/graphql/operations/ResumeSubscriptionMutation.d.ts +3 -0
  852. package/types/graphql/operations/SearchProductsAdvancedQuery.d.ts +3 -0
  853. package/types/graphql/operations/SearchProductsQuery.d.ts +3 -0
  854. package/types/graphql/operations/SearchQuestionsQuery.d.ts +3 -0
  855. package/types/graphql/operations/SearchReviewsQuery.d.ts +3 -0
  856. package/types/graphql/operations/SignInMutation.d.ts +3 -0
  857. package/types/graphql/operations/SignInViaEmailCompleteMutation.d.ts +3 -0
  858. package/types/graphql/operations/SignInViaEmailInitMutation.d.ts +3 -0
  859. package/types/graphql/operations/SignUpMutation.d.ts +3 -0
  860. package/types/graphql/operations/SkipNextSubscriptionMutation.d.ts +3 -0
  861. package/types/graphql/operations/UploadFileMutation.d.ts +3 -0
  862. package/types/graphql/operations/VerifyCodeMutation.d.ts +3 -0
  863. package/types/graphql/operations/VoteQuestionAnswerMutation.d.ts +3 -0
  864. package/types/graphql/operations/VoteQuestionMutation.d.ts +3 -0
  865. package/types/graphql/operations/VoteReviewAnswerMutation.d.ts +3 -0
  866. package/types/graphql/operations/VoteReviewMutation.d.ts +3 -0
  867. package/types/graphql/types.d.ts +2471 -0
  868. package/types/hierarchicalSearchOption.d.ts +14 -0
  869. package/types/idgen.d.ts +1 -0
  870. package/types/ignoreQueue.d.ts +10 -0
  871. package/types/imageAltProps.d.ts +11 -0
  872. package/types/invoiceFormat.d.ts +32 -0
  873. package/types/isShippingRequired.d.ts +14 -0
  874. package/types/isoStripTrailingZeros.d.ts +1 -0
  875. package/types/json/commerce.d.ts +3 -0
  876. package/types/json/commerceFileUpload.d.ts +20 -0
  877. package/types/json/commerceTypes.d.ts +15422 -0
  878. package/types/json/common.d.ts +81 -0
  879. package/types/json/fetchAllItems.d.ts +15 -0
  880. package/types/json/mutator.d.ts +238 -0
  881. package/types/json/storefront.d.ts +3 -0
  882. package/types/json/storefrontTypes.d.ts +5059 -0
  883. package/types/lastValue.d.ts +10 -0
  884. package/types/lineItemPrice.d.ts +18 -0
  885. package/types/loadJWT.d.ts +1 -0
  886. package/types/mapInvalidInput.d.ts +15 -0
  887. package/types/mapResponseData.d.ts +3 -0
  888. package/types/mapResponseMultiData.d.ts +2 -0
  889. package/types/meanBy.d.ts +1 -0
  890. package/types/media.d.ts +3 -0
  891. package/types/modules/advancedSearch.d.ts +78 -0
  892. package/types/modules/cart.d.ts +263 -0
  893. package/types/modules/config/defaultAdvancedSearchGraphQLConfig.d.ts +3 -0
  894. package/types/modules/config/defaultCartGraphQLConfig.d.ts +6 -0
  895. package/types/modules/config/defaultProductGraphQLConfig.d.ts +23 -0
  896. package/types/modules/config/defaultSearchGraphQLConfig.d.ts +3 -0
  897. package/types/modules/customer.d.ts +624 -0
  898. package/types/modules/helpers/cartInitOption.d.ts +2 -0
  899. package/types/modules/helpers/cookieConsent.d.ts +4 -0
  900. package/types/modules/helpers/customerOauth2.d.ts +19 -0
  901. package/types/modules/helpers/getOAuth2Hook.d.ts +22 -0
  902. package/types/modules/helpers/hookUpAnalytics.d.ts +21 -0
  903. package/types/modules/helpers/loadJWT.d.ts +1 -0
  904. package/types/modules/helpers/misc.d.ts +14 -0
  905. package/types/modules/imageDialog.d.ts +31 -0
  906. package/types/modules/persist.d.ts +13 -0
  907. package/types/modules/popupMessage.d.ts +9 -0
  908. package/types/modules/product.d.ts +320 -0
  909. package/types/modules/recentlyVisitedProducts.d.ts +25 -0
  910. package/types/modules/search.d.ts +54 -0
  911. package/types/multiResponseToResponse.d.ts +2 -0
  912. package/types/nonNull.d.ts +1 -0
  913. package/types/oauthState.d.ts +3 -0
  914. package/types/orderShippingAddress.d.ts +6 -0
  915. package/types/pender.d.ts +5 -0
  916. package/types/percentageOff.d.ts +1 -0
  917. package/types/popupConnectQueue.d.ts +41 -0
  918. package/types/preact/components/SixDigitInput.d.ts +28 -0
  919. package/types/preact/effector.d.ts +8 -0
  920. package/types/preact/transition/CSSTransition.d.ts +8 -0
  921. package/types/preact/transition/Transition.d.ts +30 -0
  922. package/types/preact/translateLocalStatic.d.ts +4 -0
  923. package/types/productFiltering.d.ts +58 -0
  924. package/types/productSEO.d.ts +59 -0
  925. package/types/productSorting.d.ts +35 -0
  926. package/types/promiseAll.d.ts +5 -0
  927. package/types/promiseLimit.d.ts +13 -0
  928. package/types/rdsToInitialScores.d.ts +26 -0
  929. package/types/react/components/Portal.d.ts +2 -0
  930. package/types/react/components/RootCloseWrapper.d.ts +18 -0
  931. package/types/react/components/SixDigitInput.d.ts +27 -0
  932. package/types/react/contains.d.ts +1 -0
  933. package/types/react/popperBinder.d.ts +23 -0
  934. package/types/react/rootClose.d.ts +18 -0
  935. package/types/react/translateLocalStatic.d.ts +4 -0
  936. package/types/react/useAsyncCachedValue.d.ts +2 -0
  937. package/types/refreshTimeout.d.ts +5 -0
  938. package/types/remoteAuth.d.ts +14 -0
  939. package/types/request.d.ts +104 -0
  940. package/types/requestDetails.d.ts +16 -0
  941. package/types/rfc3339Normalize.d.ts +1 -0
  942. package/types/script.d.ts +36 -0
  943. package/types/seo.d.ts +5 -0
  944. package/types/shopDomain.d.ts +7 -0
  945. package/types/shopLinks.d.ts +14 -0
  946. package/types/slate.d.ts +47 -0
  947. package/types/sleep.d.ts +1 -0
  948. package/types/splitBy.d.ts +1 -0
  949. package/types/splitName.d.ts +2 -0
  950. package/types/stripZeros.d.ts +1 -0
  951. package/types/stripeError.d.ts +14 -0
  952. package/types/tailSplit.d.ts +1 -0
  953. package/types/tieredPrice.d.ts +2 -0
  954. package/types/timeIt.d.ts +1 -0
  955. package/types/toMajor.d.ts +8 -0
  956. package/types/toMinor.d.ts +8 -0
  957. package/types/trace.d.ts +17 -0
  958. package/types/translateLocale.d.ts +2 -0
  959. package/types/traverse.d.ts +1 -0
  960. package/types/truncate.d.ts +7 -0
  961. package/types/typedLocalStorage.d.ts +3 -0
  962. package/types/variantImage.d.ts +16 -0
  963. package/types/variantImageURL.d.ts +25 -0
  964. package/types/variantImages.d.ts +11 -0
  965. package/types/variantInventory.d.ts +14 -0
  966. package/types/variantOptions.d.ts +18 -0
  967. package/types/variantPrice.d.ts +37 -0
  968. package/types/variantPriceCommerce.d.ts +26 -0
  969. package/types/variantTitle.d.ts +7 -0
  970. package/types/variantTitleFull.d.ts +11 -0
  971. package/types/variantURL.d.ts +7 -0
  972. package/types/websocket.d.ts +33 -0
@@ -0,0 +1,2174 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.createCustomer = exports.isSamePageParam = exports.createVariantMap = void 0;
4
+ const tslib_1 = require("tslib");
5
+ const jwt_decode_1 = tslib_1.__importDefault(require("jwt-decode"));
6
+ const effector_1 = require("effector");
7
+ const ApplyGiftCardMutation_js_1 = tslib_1.__importDefault(require("../graphql/operations/ApplyGiftCardMutation.js"));
8
+ const CancelOrderMutation_js_1 = tslib_1.__importDefault(require("../graphql/operations/CancelOrderMutation.js"));
9
+ const CancelSubscriptionMutation_js_1 = tslib_1.__importDefault(require("../graphql/operations/CancelSubscriptionMutation.js"));
10
+ const ConnectOAuth2Mutation_js_1 = tslib_1.__importDefault(require("../graphql/operations/ConnectOAuth2Mutation.js"));
11
+ const CreateFavoriteMutation_js_1 = tslib_1.__importDefault(require("../graphql/operations/CreateFavoriteMutation.js"));
12
+ const CreatePaymentSourceMutation_js_1 = tslib_1.__importDefault(require("../graphql/operations/CreatePaymentSourceMutation.js"));
13
+ const CreateReturnMutation_js_1 = tslib_1.__importDefault(require("../graphql/operations/CreateReturnMutation.js"));
14
+ const DeleteFavoriteMutation_js_1 = tslib_1.__importDefault(require("../graphql/operations/DeleteFavoriteMutation.js"));
15
+ const DeletePaymentSourceMutation_js_1 = tslib_1.__importDefault(require("../graphql/operations/DeletePaymentSourceMutation.js"));
16
+ const DisconnectOAuth2Mutation_js_1 = tslib_1.__importDefault(require("../graphql/operations/DisconnectOAuth2Mutation.js"));
17
+ const EditSubscriptionMutation_js_1 = tslib_1.__importDefault(require("../graphql/operations/EditSubscriptionMutation.js"));
18
+ const GetCustomerAddressesPageDataQuery_js_1 = tslib_1.__importDefault(require("../graphql/operations/GetCustomerAddressesPageDataQuery.js"));
19
+ const GetCustomerBalanceHistoryPageQuery_js_1 = tslib_1.__importDefault(require("../graphql/operations/GetCustomerBalanceHistoryPageQuery.js"));
20
+ const GetCustomerBalanceQuery_js_1 = tslib_1.__importDefault(require("../graphql/operations/GetCustomerBalanceQuery.js"));
21
+ const GetCustomerInfoQuery_js_1 = tslib_1.__importDefault(require("../graphql/operations/GetCustomerInfoQuery.js"));
22
+ const GetCustomerQuery_js_1 = tslib_1.__importDefault(require("../graphql/operations/GetCustomerQuery.js"));
23
+ const GetFavoritesQuery_js_1 = tslib_1.__importDefault(require("../graphql/operations/GetFavoritesQuery.js"));
24
+ const GetOrderQuery_js_1 = tslib_1.__importDefault(require("../graphql/operations/GetOrderQuery.js"));
25
+ const GetOrdersPageQuery_js_1 = tslib_1.__importDefault(require("../graphql/operations/GetOrdersPageQuery.js"));
26
+ const GetPaymentMethodsPageDataQuery_js_1 = tslib_1.__importDefault(require("../graphql/operations/GetPaymentMethodsPageDataQuery.js"));
27
+ const GetProvincesQuery_js_1 = tslib_1.__importDefault(require("../graphql/operations/GetProvincesQuery.js"));
28
+ const GetReturnCreationInfoQuery_js_1 = tslib_1.__importDefault(require("../graphql/operations/GetReturnCreationInfoQuery.js"));
29
+ const GetReturnQuery_js_1 = tslib_1.__importDefault(require("../graphql/operations/GetReturnQuery.js"));
30
+ const GetReturnsPageQuery_js_1 = tslib_1.__importDefault(require("../graphql/operations/GetReturnsPageQuery.js"));
31
+ const GetSubscriptionQuery_js_1 = tslib_1.__importDefault(require("../graphql/operations/GetSubscriptionQuery.js"));
32
+ const GetSubscriptionsPageQuery_js_1 = tslib_1.__importDefault(require("../graphql/operations/GetSubscriptionsPageQuery.js"));
33
+ const ModifyCustomerMutation_js_1 = tslib_1.__importDefault(require("../graphql/operations/ModifyCustomerMutation.js"));
34
+ const ModifyFavoriteMutation_js_1 = tslib_1.__importDefault(require("../graphql/operations/ModifyFavoriteMutation.js"));
35
+ const NewPasswordMutation_js_1 = tslib_1.__importDefault(require("../graphql/operations/NewPasswordMutation.js"));
36
+ const PauseSubscriptionMutation_js_1 = tslib_1.__importDefault(require("../graphql/operations/PauseSubscriptionMutation.js"));
37
+ const ResetPasswordMutation_js_1 = tslib_1.__importDefault(require("../graphql/operations/ResetPasswordMutation.js"));
38
+ const ResumeSubscriptionMutation_js_1 = tslib_1.__importDefault(require("../graphql/operations/ResumeSubscriptionMutation.js"));
39
+ const SignInMutation_js_1 = tslib_1.__importDefault(require("../graphql/operations/SignInMutation.js"));
40
+ const SignInViaEmailCompleteMutation_js_1 = tslib_1.__importDefault(require("../graphql/operations/SignInViaEmailCompleteMutation.js"));
41
+ const SignInViaEmailInitMutation_js_1 = tslib_1.__importDefault(require("../graphql/operations/SignInViaEmailInitMutation.js"));
42
+ const SignUpMutation_js_1 = tslib_1.__importDefault(require("../graphql/operations/SignUpMutation.js"));
43
+ const SkipNextSubscriptionMutation_js_1 = tslib_1.__importDefault(require("../graphql/operations/SkipNextSubscriptionMutation.js"));
44
+ const VerifyCodeMutation_js_1 = tslib_1.__importDefault(require("../graphql/operations/VerifyCodeMutation.js"));
45
+ const codes_js_1 = require("../generated/codes.js");
46
+ const request_js_1 = require("../request.js");
47
+ const mapInvalidInput_js_1 = require("../mapInvalidInput.js");
48
+ const stripeError_js_1 = require("../stripeError.js");
49
+ const validator_js_1 = require("../effector/validator.js");
50
+ const addEmptyListItem_js_1 = require("../addEmptyListItem.js");
51
+ const combineEvery_js_1 = require("../effector/combineEvery.js");
52
+ const combineSome_js_1 = require("../effector/combineSome.js");
53
+ const compact_js_1 = require("../compact.js");
54
+ const form_js_1 = require("../effector/form.js");
55
+ const persist_js_1 = require("./persist.js");
56
+ const generateRandomToken_js_1 = require("../generateRandomToken.js");
57
+ const getTimezone_js_1 = require("../getTimezone.js");
58
+ const lastValue_js_1 = require("../lastValue.js");
59
+ const mapResponseData_js_1 = require("../mapResponseData.js");
60
+ const multiResponseToResponse_js_1 = require("../multiResponseToResponse.js");
61
+ const nonNull_js_1 = require("../nonNull.js");
62
+ const requestResponse_js_1 = require("../effector/requestResponse.js");
63
+ const split_js_1 = require("../effector/split.js");
64
+ function getCustomerInfo(shopID, id, opts) {
65
+ return tslib_1.__awaiter(this, void 0, void 0, function* () {
66
+ if (!(opts === null || opts === void 0 ? void 0 : opts.authToken))
67
+ return null;
68
+ const resp = yield (0, request_js_1.requestMulti)(GetCustomerInfoQuery_js_1.default)({ shopID, id }, opts);
69
+ if (resp.kind === "data_or_error" && resp.data) {
70
+ const { customer, favorites } = resp.data;
71
+ if (customer && favorites) {
72
+ return {
73
+ customer: customer[0],
74
+ favorites: (0, compact_js_1.compact)(favorites.map((f) => f.variant
75
+ ? {
76
+ id: f.id,
77
+ variantID: f.variant.id,
78
+ inventoryNotification: f.inventory_notification,
79
+ priceNotification: f.price_notification,
80
+ }
81
+ : undefined)),
82
+ };
83
+ }
84
+ }
85
+ return null;
86
+ });
87
+ }
88
+ function createVariantMap(order) {
89
+ const out = {};
90
+ for (const li of order.line_items) {
91
+ if (!li.variant)
92
+ continue;
93
+ out[li.variant.id] = li.variant;
94
+ if (li.variant.type === "bundle" && li.variant.bundle_line_items.length > 0) {
95
+ for (const bli of li.variant.bundle_line_items) {
96
+ if (!bli.variant)
97
+ continue;
98
+ out[bli.variant.id] = bli.variant;
99
+ }
100
+ }
101
+ }
102
+ return out;
103
+ }
104
+ exports.createVariantMap = createVariantMap;
105
+ //===================================================================================================================
106
+ //===================================================================================================================
107
+ //===================================================================================================================
108
+ function formToBillingDetails(form) {
109
+ return {
110
+ name: form.name,
111
+ address: {
112
+ line1: form.address,
113
+ line2: "",
114
+ city: form.city,
115
+ postal_code: form.zip,
116
+ country: form.country,
117
+ state: form.province,
118
+ },
119
+ };
120
+ }
121
+ //===================================================================================================================
122
+ //===================================================================================================================
123
+ //===================================================================================================================
124
+ function createAvailableProvincesLogic(binding, validators) {
125
+ // note that logic is only correct if fields start with these values: [], "", ""
126
+ const availableProvinces = (0, effector_1.createStore)([]);
127
+ const country = (0, form_js_1.createStringField)("country", "", validators);
128
+ const province = (0, form_js_1.createStringField)("province", "", validators);
129
+ const clearProvince = (0, effector_1.createEvent)();
130
+ // really clear province, this ignores initialValue
131
+ province.value.on(clearProvince, () => "");
132
+ province.touched.reset(clearProvince);
133
+ // once "availableProvinces" changes, check if "province" is valid, if not -> clear "province"
134
+ (0, effector_1.guard)({
135
+ source: availableProvinces,
136
+ filter: (0, effector_1.combine)(province.value, availableProvinces, (province, availableProvinces) => !availableProvinces.find((p) => p.code === province)),
137
+ target: clearProvince,
138
+ });
139
+ // "getProvincesFx" and its logic
140
+ const getProvincesFx = (0, effector_1.createEffect)((0, lastValue_js_1.lastValue)((p) => tslib_1.__awaiter(this, void 0, void 0, function* () {
141
+ const { shopID, opts } = p.config;
142
+ return (0, request_js_1.request)(GetProvincesQuery_js_1.default)({ shopID, countryCode: p.data }, opts);
143
+ })));
144
+ {
145
+ const getProvincesLastValue = getProvincesFx.doneData.filterMap((v) => v.kind === "resolved" ? v.value : undefined);
146
+ const getProvincesResult = (0, requestResponse_js_1.requestResponseSplit)(getProvincesLastValue);
147
+ // success, apply "availableProvinces"
148
+ availableProvinces.on(getProvincesResult.data, (_, v) => v);
149
+ // failure, reset "availableProvinces" and report error
150
+ availableProvinces.reset(getProvincesResult.error);
151
+ (0, effector_1.forward)({
152
+ from: getProvincesResult.error,
153
+ to: binding.unexpectedError,
154
+ });
155
+ }
156
+ // on "country" changes
157
+ // 1. if "country" is empty
158
+ // -> clear "availableProvinces"
159
+ // -> clear "province" field
160
+ // 2. if "country" is not empty
161
+ // -> run "getProvincesFx", it will change "availableProvinces" once resolved
162
+ const countryChanged = (0, effector_1.sample)(binding.internalConfig, country.value.updates, (config, data) => ({
163
+ config,
164
+ data,
165
+ }));
166
+ availableProvinces.reset(country.value.updates.filterMap((v) => (!v ? true : undefined)));
167
+ (0, effector_1.guard)({
168
+ source: countryChanged,
169
+ filter: (v) => !!v.data,
170
+ target: getProvincesFx,
171
+ });
172
+ (0, effector_1.guard)({
173
+ source: countryChanged,
174
+ filter: (v) => !v.data,
175
+ target: clearProvince,
176
+ });
177
+ return {
178
+ availableProvinces,
179
+ country,
180
+ province,
181
+ };
182
+ }
183
+ function isSamePageParam(a, b) {
184
+ // TODO: probably I can just remove CommonPageParam part and do a deep comparison
185
+ if (a.kind === "order" && b.kind === "order") {
186
+ return a.orderID === b.orderID;
187
+ }
188
+ else if (a.kind === "create_return" && b.kind === "create_return") {
189
+ return a.orderID === b.orderID;
190
+ }
191
+ else if (a.kind === "subscription" && b.kind === "subscription") {
192
+ return a.subscriptionID === b.subscriptionID;
193
+ }
194
+ else if (a.kind === "return" && b.kind === "return") {
195
+ return a.returnID === b.returnID;
196
+ }
197
+ else if (a.kind === "confirm" && b.kind === "confirm") {
198
+ return a.token === b.token;
199
+ }
200
+ else {
201
+ return a.kind === b.kind;
202
+ }
203
+ }
204
+ exports.isSamePageParam = isSamePageParam;
205
+ function defineInit(binding, fn) {
206
+ const event = (0, effector_1.createEvent)();
207
+ const load = (0, effector_1.createEvent)();
208
+ const loadFx = (0, effector_1.createEffect)((p) => fn(p.config, p.param));
209
+ const loadParam = load.map((p) => p.param);
210
+ const { initPageSuccess: success, initPageFailure: failure } = splitRequestResponseData(loadFx.doneData);
211
+ (0, effector_1.guard)({
212
+ source: (0, effector_1.sample)(binding.internalConfig, load, (config, param) => ({ config, param })),
213
+ filter: binding.everythingIdle,
214
+ target: loadFx,
215
+ });
216
+ (0, effector_1.forward)({
217
+ from: success,
218
+ to: event,
219
+ });
220
+ (0, effector_1.forward)({
221
+ from: failure,
222
+ to: binding.unexpectedError,
223
+ });
224
+ return {
225
+ event,
226
+ load,
227
+ loaded: (0, effector_1.sample)(loadParam, success),
228
+ pending: loadFx.pending,
229
+ };
230
+ }
231
+ function defineInitBlank(binding) {
232
+ return defineInit(binding, () => tslib_1.__awaiter(this, void 0, void 0, function* () { return ({ kind: "data", data: null }); }));
233
+ }
234
+ //===================================================================================================================
235
+ //===================================================================================================================
236
+ //===================================================================================================================
237
+ function splitRequestResponseData(source) {
238
+ const initPageSuccess = (0, effector_1.createEvent)();
239
+ const initPageFailure = (0, effector_1.createEvent)();
240
+ (0, split_js_1.splitMap)(source)
241
+ .map((v) => (v.kind === "data" ? v.data : undefined), initPageSuccess)
242
+ .fallback(initPageFailure);
243
+ return { initPageSuccess, initPageFailure };
244
+ }
245
+ //===================================================================================================================
246
+ //===================================================================================================================
247
+ //===================================================================================================================
248
+ // pages you're not allowed to be in, while being logged in
249
+ const disallowedAuthPages = {
250
+ signup: true,
251
+ signin: true,
252
+ };
253
+ // it's not allowed to store these pages as lastAuthPage
254
+ const disallowedLastAuthPages = Object.assign(Object.assign({}, disallowedAuthPages), { reset_password: true, order: true, create_return: true, subscription: true, return: true, confirm: true });
255
+ // only pages you're allowed to be in, while NOT being logged in
256
+ const allowedNoAuthPages = {
257
+ signup: true,
258
+ signin: true,
259
+ confirm: true,
260
+ reset_password: true,
261
+ };
262
+ function shouldRedirect(jwt, pp, lastAuthPage) {
263
+ if (jwt) {
264
+ if (disallowedAuthPages[pp.kind]) {
265
+ return lastAuthPage
266
+ ? Object.assign(Object.assign({}, lastAuthPage), { action: pp.action === "pop" ? "pop_redirect" : "push_redirect" }) : { kind: "orders", action: pp.action === "pop" ? "pop_redirect" : "push_redirect" };
267
+ }
268
+ }
269
+ else {
270
+ if (!allowedNoAuthPages[pp.kind]) {
271
+ return { kind: "signin", action: pp.action === "pop" ? "pop_redirect" : "push_redirect" };
272
+ }
273
+ }
274
+ }
275
+ //===================================================================================================================
276
+ //===================================================================================================================
277
+ //===================================================================================================================
278
+ function createFormToggleState(binding, form) {
279
+ const toggleForReal = (0, effector_1.createEvent)();
280
+ const toggleFormVisibility = (0, effector_1.createEvent)();
281
+ const isFormVisible = (0, effector_1.createStore)(false);
282
+ // form ui logic
283
+ {
284
+ (0, effector_1.guard)({
285
+ source: toggleFormVisibility,
286
+ filter: binding.everythingIdle,
287
+ target: toggleForReal,
288
+ });
289
+ // toggle form visibility
290
+ isFormVisible.on(toggleForReal, (v) => !v);
291
+ // when form visibility changes, on false => true transition reset the form also
292
+ (0, effector_1.forward)({
293
+ from: isFormVisible.updates.filterMap((v) => v || undefined),
294
+ to: form.reset,
295
+ });
296
+ }
297
+ return {
298
+ toggleFormVisibility,
299
+ isFormVisible,
300
+ };
301
+ }
302
+ function handleFormFailure(c, ...prefixMaps) {
303
+ const source = c.source || (0, effector_1.createEvent)();
304
+ (0, effector_1.sample)({
305
+ source,
306
+ clock: c.form.errorPropagationFailed,
307
+ target: c.unexpectedError,
308
+ });
309
+ (0, split_js_1.splitMap)(source)
310
+ .map((e) => (0, mapInvalidInput_js_1.mapInvalidInput)(e, ...prefixMaps), c.form.propagateErrors)
311
+ .fallback(c.unexpectedError);
312
+ return source;
313
+ }
314
+ //===================================================================================================================
315
+ //===================================================================================================================
316
+ //===================================================================================================================
317
+ function createSignupPageGraph(binding) {
318
+ const init = defineInitBlank(binding);
319
+ const form = (0, form_js_1.createForm)({
320
+ name: (0, form_js_1.createStringField)("name", "", [validator_js_1.validNonEmpty, validator_js_1.validMaxLength250]),
321
+ email: (0, form_js_1.createStringField)("email", "", [validator_js_1.validNonEmpty, validator_js_1.validEmail, validator_js_1.validMaxLength250]),
322
+ password: (0, form_js_1.createStringField)("password", "", [validator_js_1.validNonEmpty]),
323
+ accepts_marketing: (0, form_js_1.createBooleanField)("accepts_marketing", false),
324
+ });
325
+ (0, effector_1.forward)({
326
+ from: init.event,
327
+ to: form.reset,
328
+ });
329
+ const signupFx = (0, effector_1.createEffect)((p) => tslib_1.__awaiter(this, void 0, void 0, function* () {
330
+ const { shopID, opts } = p.config;
331
+ return (0, request_js_1.request)(SignUpMutation_js_1.default)({ shopID, data: p.data }, opts);
332
+ }));
333
+ (0, effector_1.guard)({
334
+ source: (0, effector_1.sample)(binding.internalConfig, form.submitted, (config, data) => ({
335
+ config,
336
+ data: Object.assign(Object.assign({}, data), { timezone_hint: (0, getTimezone_js_1.getTimezone)() }),
337
+ })),
338
+ filter: binding.everythingIdle,
339
+ target: signupFx,
340
+ });
341
+ const { data: signupData, error: signupError } = (0, requestResponse_js_1.requestResponseSplit)(signupFx.doneData);
342
+ // success
343
+ (0, effector_1.forward)({
344
+ from: signupData.filterMap((v) => v[0].token || undefined),
345
+ to: binding.setJWT,
346
+ });
347
+ // failure
348
+ handleFormFailure({ source: signupError, form, unexpectedError: binding.unexpectedError }, { from: "[0]." });
349
+ return {
350
+ init,
351
+ form,
352
+ somethingIsPending: (0, combineSome_js_1.combineSome)(init.pending, signupFx.pending),
353
+ };
354
+ }
355
+ //===================================================================================================================
356
+ //===================================================================================================================
357
+ //===================================================================================================================
358
+ function createResetPasswordPageGraph(binding) {
359
+ const init = defineInitBlank(binding);
360
+ // forms, we use shared fields here
361
+ const resetPasswordForm = (0, form_js_1.createFormWithCustomError)({
362
+ email: (0, form_js_1.createStringField)("email", "", [validator_js_1.validNonEmpty, validator_js_1.validEmail, validator_js_1.validMaxLength250]),
363
+ }, null);
364
+ const verifyCodeForm = (0, form_js_1.createFormWithCustomError)({
365
+ code: (0, form_js_1.createStringField)("code", "", [validator_js_1.validNonEmpty]),
366
+ }, null);
367
+ const newPasswordForm = (0, form_js_1.createForm)({
368
+ password: (0, form_js_1.createStringField)("password", "", [validator_js_1.validNonEmpty]),
369
+ });
370
+ const setStep = (0, effector_1.createEvent)();
371
+ const currentStep = (0, effector_1.restore)(setStep, { kind: "step1", form: resetPasswordForm });
372
+ (0, effector_1.forward)({
373
+ from: init.event,
374
+ to: [resetPasswordForm.reset, verifyCodeForm.reset, newPasswordForm.reset],
375
+ });
376
+ currentStep.reset(init.event);
377
+ // API requests
378
+ const noAuthConfig = binding.internalConfig.map((v) => (Object.assign(Object.assign({}, v), { opts: Object.assign(Object.assign({}, v.opts), { authToken: undefined }) })));
379
+ const resetPasswordFx = (0, effector_1.createEffect)((p) => tslib_1.__awaiter(this, void 0, void 0, function* () {
380
+ const { shopID, opts } = p.config;
381
+ return (0, request_js_1.request)(ResetPasswordMutation_js_1.default)({ shopID, data: p.data }, opts);
382
+ }));
383
+ const verifyCodeFx = (0, effector_1.createEffect)((p) => tslib_1.__awaiter(this, void 0, void 0, function* () {
384
+ const { shopID, opts } = p.config;
385
+ return (0, request_js_1.request)(VerifyCodeMutation_js_1.default)({ shopID, data: p.data }, opts);
386
+ }));
387
+ const newPasswordFx = (0, effector_1.createEffect)((p) => tslib_1.__awaiter(this, void 0, void 0, function* () {
388
+ const { shopID, opts } = p.config;
389
+ return (0, request_js_1.request)(NewPasswordMutation_js_1.default)({ shopID, data: p.data }, opts);
390
+ }));
391
+ // wire each form to its own API request
392
+ const step2Submitted = (0, effector_1.sample)(resetPasswordForm.submitted, verifyCodeForm.submitted, (a, b) => (Object.assign(Object.assign({}, a), b)));
393
+ const step3Submitted = (0, effector_1.sample)(step2Submitted, newPasswordForm.submitted, (a, b) => (Object.assign(Object.assign({}, a), b)));
394
+ (0, effector_1.guard)({
395
+ source: (0, effector_1.sample)(noAuthConfig, resetPasswordForm.submitted, (config, data) => ({ config, data })),
396
+ filter: binding.everythingIdle,
397
+ target: resetPasswordFx,
398
+ });
399
+ (0, effector_1.guard)({
400
+ source: (0, effector_1.sample)(noAuthConfig, step2Submitted, (config, data) => ({ config, data })),
401
+ filter: binding.everythingIdle,
402
+ target: verifyCodeFx,
403
+ });
404
+ (0, effector_1.guard)({
405
+ source: (0, effector_1.sample)(noAuthConfig, step3Submitted, (config, data) => ({ config, data })),
406
+ filter: binding.everythingIdle,
407
+ target: newPasswordFx,
408
+ });
409
+ // split API response results
410
+ const resetPasswordResult = (0, requestResponse_js_1.requestResponseSplit)(resetPasswordFx.doneData);
411
+ const verifyCodeResult = (0, requestResponse_js_1.requestResponseSplit)(verifyCodeFx.doneData);
412
+ const newPasswordResult = (0, requestResponse_js_1.requestResponseSplit)(newPasswordFx.doneData);
413
+ // SUCCESS
414
+ {
415
+ // form 1 => form 2
416
+ (0, effector_1.forward)({
417
+ from: resetPasswordResult.data.map(() => ({ kind: "step2", form: verifyCodeForm })),
418
+ to: setStep,
419
+ });
420
+ // form 2 => form 3
421
+ (0, effector_1.forward)({
422
+ from: verifyCodeResult.data.map(() => ({ kind: "step3", form: newPasswordForm })),
423
+ to: setStep,
424
+ });
425
+ // form 3 => drop auth, go to signin page
426
+ (0, effector_1.forward)({
427
+ from: newPasswordResult.data.map(() => ""),
428
+ to: binding.setJWT,
429
+ });
430
+ (0, effector_1.forward)({
431
+ from: newPasswordResult.data.map(() => ({ kind: "signin", action: "push" })),
432
+ to: binding.goTo,
433
+ });
434
+ }
435
+ // FAILURE
436
+ {
437
+ // form 1
438
+ (0, split_js_1.splitMap)(resetPasswordResult.error)
439
+ .map((e) => { var _a; return e.kind === "error" && ((_a = e.error.apiError) === null || _a === void 0 ? void 0 : _a.code) === codes_js_1.ErrorCode.TryAgainLater ? "try_again_later" : undefined; }, resetPasswordForm.setError)
440
+ .fallback(handleFormFailure({ form: resetPasswordForm, unexpectedError: binding.unexpectedError }));
441
+ // form 2
442
+ (0, split_js_1.splitMap)(verifyCodeResult.error)
443
+ .map((e) => { var _a; return (e.kind === "error" && ((_a = e.error.apiError) === null || _a === void 0 ? void 0 : _a.code) === codes_js_1.ErrorCode.NotFound ? "not_found" : undefined); }, verifyCodeForm.setError)
444
+ .fallback(handleFormFailure({ form: verifyCodeForm, unexpectedError: binding.unexpectedError }));
445
+ // form 3
446
+ handleFormFailure({
447
+ source: newPasswordResult.error,
448
+ form: newPasswordForm,
449
+ unexpectedError: binding.unexpectedError,
450
+ });
451
+ }
452
+ return {
453
+ init,
454
+ currentStep,
455
+ somethingIsPending: (0, combineSome_js_1.combineSome)(init.pending, resetPasswordFx.pending, verifyCodeFx.pending, newPasswordFx.pending),
456
+ };
457
+ }
458
+ //===================================================================================================================
459
+ //===================================================================================================================
460
+ //===================================================================================================================
461
+ function createPaymentMethodsPageGraph(binding) {
462
+ const init = defineInit(binding, (config, _p) => tslib_1.__awaiter(this, void 0, void 0, function* () {
463
+ const { shopID, opts } = config;
464
+ const jwt = (0, jwt_decode_1.default)((0, nonNull_js_1.nonNull)(opts === null || opts === void 0 ? void 0 : opts.authToken, "auth token"));
465
+ return (0, multiResponseToResponse_js_1.multiResponseToResponse)(yield (0, request_js_1.requestMulti)(GetPaymentMethodsPageDataQuery_js_1.default)({ shopID, customerID: jwt.customer_id }, opts), (v) => {
466
+ const { countries, storefrontPaymentSources, storefrontCustomers, analyticsGeoip } = v;
467
+ return countries && storefrontPaymentSources && storefrontCustomers && analyticsGeoip
468
+ ? {
469
+ availableCountries: (0, addEmptyListItem_js_1.addEmptyListItem)(countries.map((v) => ({ value: v.code, label: v.name }))),
470
+ customer: storefrontCustomers[0],
471
+ paymentMethods: storefrontPaymentSources,
472
+ geoip: analyticsGeoip,
473
+ }
474
+ : undefined;
475
+ });
476
+ }));
477
+ const pageData = (0, effector_1.createStore)(null);
478
+ pageData.on(init.event, (_, v) => v);
479
+ const { availableProvinces, country, province } = createAvailableProvincesLogic(binding, []);
480
+ const setStripeElement = (0, effector_1.createEvent)();
481
+ const stripeElement = (0, effector_1.restore)(setStripeElement, null).reset(init.event);
482
+ const form = (0, form_js_1.createForm)({
483
+ name: (0, form_js_1.createStringField)("name", "", []),
484
+ address: (0, form_js_1.createStringField)("address", "", []),
485
+ city: (0, form_js_1.createStringField)("city", "", []),
486
+ zip: (0, form_js_1.createStringField)("zip", "", []),
487
+ country,
488
+ province,
489
+ as_default: (0, form_js_1.createBooleanField)("as_default", false),
490
+ });
491
+ const formToggleState = createFormToggleState(binding, form);
492
+ formToggleState.isFormVisible.reset(init.event);
493
+ (0, effector_1.forward)({
494
+ from: init.event,
495
+ to: form.reset,
496
+ });
497
+ (0, effector_1.forward)({
498
+ from: init.event.map((v) => {
499
+ var _a, _b, _c, _d;
500
+ const dbid = v.customer.default_billing_address_id;
501
+ const dsid = v.customer.default_shipping_address_id;
502
+ const addrs = v.customer.addresses;
503
+ const addr = addrs.find((a) => a.id === dbid) || addrs.find((a) => a.id === dsid) || addrs.find(() => true);
504
+ if (addr) {
505
+ return {
506
+ name: addr.name,
507
+ address: addr.address1,
508
+ city: addr.city,
509
+ zip: addr.zip,
510
+ country: ((_a = addr.country) === null || _a === void 0 ? void 0 : _a.code) || "",
511
+ province: ((_b = addr.province) === null || _b === void 0 ? void 0 : _b.code) || "",
512
+ };
513
+ }
514
+ else {
515
+ return {
516
+ name: "",
517
+ address: "",
518
+ city: "",
519
+ zip: "",
520
+ country: ((_c = v.geoip.country) === null || _c === void 0 ? void 0 : _c.code) || "",
521
+ province: ((_d = v.geoip.province) === null || _d === void 0 ? void 0 : _d.code) || "",
522
+ };
523
+ }
524
+ }),
525
+ to: form.init,
526
+ });
527
+ const additionalFormSubmitData = (0, effector_1.combine)(stripeElement, binding.internalConfig, (stripeElement, config) => ({
528
+ stripeElement,
529
+ config,
530
+ }));
531
+ const addPaymentMethodFx = (0, effector_1.createEffect)((p) => tslib_1.__awaiter(this, void 0, void 0, function* () {
532
+ const { shopID, opts } = p.config;
533
+ const jwt = (0, jwt_decode_1.default)((0, nonNull_js_1.nonNull)(opts === null || opts === void 0 ? void 0 : opts.authToken, "auth token"));
534
+ if (!p.config.stripePromise)
535
+ return { kind: "custom_error", text: "stripePromise is not defined in config" };
536
+ if (!p.data.stripeElement)
537
+ return { kind: "custom_error", text: "stripeElement is not set" };
538
+ const stripe = yield p.config.stripePromise;
539
+ if (!stripe)
540
+ return { kind: "custom_error", text: "failed loading stripe library" };
541
+ const result = yield stripe.createPaymentMethod({
542
+ type: "card",
543
+ card: p.data.stripeElement,
544
+ billing_details: p.data.billingDetails,
545
+ });
546
+ if (result.error)
547
+ return {
548
+ kind: "custom_error",
549
+ text: "createPaymentMethod error: " + result.error.message || "\n" + JSON.stringify(result.error, null, 2),
550
+ };
551
+ const payment_method = result.paymentMethod.id;
552
+ const resp = yield (0, request_js_1.request)(CreatePaymentSourceMutation_js_1.default)({ shopID, data: { payment_method } }, opts);
553
+ if (resp.kind !== "data")
554
+ return resp;
555
+ const default_payment_source_id = resp.data[0].id;
556
+ if (p.data.asDefault) {
557
+ const resp = yield (0, request_js_1.request)(ModifyCustomerMutation_js_1.default)({ shopID, id: jwt.customer_id, data: { default_payment_source_id } }, opts);
558
+ if (resp.kind !== "data")
559
+ return resp;
560
+ }
561
+ return { kind: "data", data: true };
562
+ }));
563
+ const deletePaymentMethodFx = (0, effector_1.createEffect)((p) => tslib_1.__awaiter(this, void 0, void 0, function* () {
564
+ const { shopID, opts } = p.config;
565
+ return (0, request_js_1.request)(DeletePaymentSourceMutation_js_1.default)({ shopID, id: p.data }, opts);
566
+ }));
567
+ function initStripeField() {
568
+ const setInvalid = (0, effector_1.createEvent)();
569
+ const setComplete = (0, effector_1.createEvent)();
570
+ const setAPIError = (0, effector_1.createEvent)();
571
+ const touched = (0, effector_1.createStore)(false).reset(init.event).reset(form.reset);
572
+ const complete = (0, effector_1.restore)(setComplete, false).reset(init.event).reset(form.reset);
573
+ const invalid = (0, effector_1.restore)(setInvalid, null).reset(init.event).reset(form.reset);
574
+ const apiError = (0, effector_1.restore)(setAPIError, null).reset(init.event).reset(form.reset);
575
+ const error = (0, effector_1.combine)(touched, invalid, complete, apiError, (touched, invalid, complete, apiError) => {
576
+ if (apiError)
577
+ return apiError;
578
+ if (invalid)
579
+ return invalid;
580
+ if (touched && !complete)
581
+ return "incomplete";
582
+ return null;
583
+ });
584
+ return {
585
+ setAPIError,
586
+ setInvalid,
587
+ setComplete,
588
+ touched,
589
+ complete,
590
+ invalid,
591
+ apiError,
592
+ error,
593
+ };
594
+ }
595
+ const stripeNumber = initStripeField();
596
+ const stripeExpiry = initStripeField();
597
+ const stripeCVC = initStripeField();
598
+ const stripeComplete = (0, combineEvery_js_1.combineEvery)(stripeNumber.complete, stripeExpiry.complete, stripeCVC.complete);
599
+ (0, effector_1.forward)({
600
+ from: form.submit.map(() => true),
601
+ to: [stripeNumber.touched, stripeExpiry.touched, stripeCVC.touched],
602
+ });
603
+ (0, effector_1.guard)({
604
+ source: (0, effector_1.sample)(additionalFormSubmitData, form.submitted, (adata, data) => ({
605
+ config: adata.config,
606
+ data: {
607
+ billingDetails: formToBillingDetails(data),
608
+ asDefault: data.as_default,
609
+ stripeElement: adata.stripeElement,
610
+ },
611
+ })),
612
+ filter: (0, effector_1.combine)(binding.everythingIdle, stripeComplete, (a, b) => a && b),
613
+ target: addPaymentMethodFx,
614
+ });
615
+ const addPaymentMethodResult = (0, requestResponse_js_1.requestResponseSplit)(addPaymentMethodFx.doneData);
616
+ // success
617
+ (0, effector_1.forward)({
618
+ from: addPaymentMethodResult.data,
619
+ to: binding.reloadPage,
620
+ });
621
+ // failure
622
+ (0, effector_1.forward)({
623
+ // reset api errors "first"
624
+ from: addPaymentMethodResult.error.map(() => null),
625
+ to: [stripeNumber.setAPIError, stripeExpiry.setAPIError, stripeCVC.setAPIError],
626
+ });
627
+ (0, split_js_1.splitMap)(addPaymentMethodResult.error)
628
+ .map(stripeError_js_1.matchNumberErrorFromRR, stripeNumber.setAPIError)
629
+ .map(stripeError_js_1.matchExpiryErrorFromRR, stripeExpiry.setAPIError)
630
+ .map(stripeError_js_1.matchCVCErrorFromRR, stripeCVC.setAPIError)
631
+ .fallback(handleFormFailure({ form, unexpectedError: binding.unexpectedError }));
632
+ const deletePaymentMethodResult = (0, requestResponse_js_1.requestResponseSplit)(deletePaymentMethodFx.doneData);
633
+ // success
634
+ (0, effector_1.forward)({
635
+ from: deletePaymentMethodResult.data,
636
+ to: binding.reloadPage,
637
+ });
638
+ // failure
639
+ (0, effector_1.forward)({
640
+ from: deletePaymentMethodResult.error,
641
+ to: binding.unexpectedError,
642
+ });
643
+ const deletePaymentMethod = (0, effector_1.createEvent)();
644
+ (0, effector_1.guard)({
645
+ source: (0, effector_1.sample)(binding.internalConfig, deletePaymentMethod, (config, data) => ({ config, data })),
646
+ filter: binding.everythingIdle,
647
+ target: deletePaymentMethodFx,
648
+ });
649
+ return Object.assign(Object.assign({ init,
650
+ form }, formToggleState), { pageData, availableProvinces: availableProvinces.map((v) => (0, addEmptyListItem_js_1.addEmptyListItem)(v.map((v) => ({ value: v.code, label: v.name })))), somethingIsPending: (0, combineSome_js_1.combineSome)(init.pending, addPaymentMethodFx.pending, deletePaymentMethodFx.pending), setStripeElement,
651
+ stripeNumber,
652
+ stripeExpiry,
653
+ stripeCVC,
654
+ deletePaymentMethod });
655
+ }
656
+ //===================================================================================================================
657
+ //===================================================================================================================
658
+ //===================================================================================================================
659
+ function createOrdersPageGraph(binding) {
660
+ const init = defineInit(binding, (config, _p) => tslib_1.__awaiter(this, void 0, void 0, function* () {
661
+ const { shopID, opts } = config;
662
+ return (0, mapResponseData_js_1.mapResponseData)(yield (0, request_js_1.request)(GetOrdersPageQuery_js_1.default)({ shopID, lastKey: "" }, opts), (v) => ({
663
+ orders: v.items,
664
+ lastKey: v.last_key,
665
+ }));
666
+ }));
667
+ const getPageFx = (0, effector_1.createEffect)((p) => tslib_1.__awaiter(this, void 0, void 0, function* () {
668
+ const { shopID, opts } = p.config;
669
+ return (0, request_js_1.request)(GetOrdersPageQuery_js_1.default)({ shopID, lastKey: p.data }, opts);
670
+ }));
671
+ const loadMore = (0, effector_1.createEvent)();
672
+ // init orders and last key stores from API response
673
+ const orders = (0, effector_1.createStore)([]);
674
+ const lastKey = (0, effector_1.createStore)("");
675
+ orders.on(init.event, (_, v) => v.orders);
676
+ lastKey.on(init.event, (_, v) => v.lastKey);
677
+ // on loadMore, sample lastKey and fetch next page (if not already pending)
678
+ (0, effector_1.guard)({
679
+ source: (0, effector_1.sample)(binding.internalConfig, (0, effector_1.sample)(lastKey, loadMore), (config, data) => ({ config, data })),
680
+ filter: binding.everythingIdle,
681
+ target: getPageFx,
682
+ });
683
+ const { data: getPageData, error: getPageError } = (0, requestResponse_js_1.requestResponseSplit)(getPageFx.doneData);
684
+ // success: propagate new data to stores (note, last key is only applied when it's there)
685
+ orders.on(getPageData.map((v) => v.items), (orders, newOrders) => [...orders, ...newOrders]);
686
+ lastKey.on(getPageData.filterMap((v) => v.last_key || undefined), (_, v) => v);
687
+ // error: report unexpected error
688
+ (0, effector_1.forward)({ from: getPageError, to: binding.unexpectedError });
689
+ return {
690
+ init,
691
+ orders,
692
+ loadMore,
693
+ somethingIsPending: (0, combineSome_js_1.combineSome)(init.pending, getPageFx.pending),
694
+ };
695
+ }
696
+ //===================================================================================================================
697
+ //===================================================================================================================
698
+ //===================================================================================================================
699
+ function createSubscriptionsPageGraph(binding) {
700
+ const init = defineInit(binding, (config, _p) => tslib_1.__awaiter(this, void 0, void 0, function* () {
701
+ const { shopID, opts } = config;
702
+ return (0, mapResponseData_js_1.mapResponseData)(yield (0, request_js_1.request)(GetSubscriptionsPageQuery_js_1.default)({ shopID, lastKey: "" }, opts), (v) => ({
703
+ subscriptions: v.items,
704
+ lastKey: v.last_key,
705
+ }));
706
+ }));
707
+ const getPageFx = (0, effector_1.createEffect)((p) => tslib_1.__awaiter(this, void 0, void 0, function* () {
708
+ const { shopID, opts } = p.config;
709
+ return (0, request_js_1.request)(GetSubscriptionsPageQuery_js_1.default)({ shopID, lastKey: p.data }, opts);
710
+ }));
711
+ const loadMore = (0, effector_1.createEvent)();
712
+ // init subscriptions and last key stores from API response
713
+ const subscriptions = (0, effector_1.createStore)([]);
714
+ const lastKey = (0, effector_1.createStore)("");
715
+ subscriptions.on(init.event, (_, v) => v.subscriptions);
716
+ lastKey.on(init.event, (_, v) => v.lastKey);
717
+ // on loadMore, sample lastKey and fetch next page (if not already pending)
718
+ (0, effector_1.guard)({
719
+ source: (0, effector_1.sample)(binding.internalConfig, (0, effector_1.sample)(lastKey, loadMore), (config, data) => ({ config, data })),
720
+ filter: binding.everythingIdle,
721
+ target: getPageFx,
722
+ });
723
+ const { data: getPageData, error: getPageError } = (0, requestResponse_js_1.requestResponseSplit)(getPageFx.doneData);
724
+ // success: propagate new data to stores (note, last key is only applied when it's there)
725
+ subscriptions.on(getPageData.map((v) => v.items), (subscriptions, newSubscriptions) => [...subscriptions, ...newSubscriptions]);
726
+ lastKey.on(getPageData.filterMap((v) => v.last_key || undefined), (_, v) => v);
727
+ // error: report unexpected error
728
+ (0, effector_1.forward)({ from: getPageError, to: binding.unexpectedError });
729
+ return {
730
+ init,
731
+ subscriptions,
732
+ loadMore,
733
+ somethingIsPending: (0, combineSome_js_1.combineSome)(init.pending, getPageFx.pending),
734
+ };
735
+ }
736
+ //===================================================================================================================
737
+ //===================================================================================================================
738
+ //===================================================================================================================
739
+ function createReturnsPageGraph(binding) {
740
+ const init = defineInit(binding, (config, _p) => tslib_1.__awaiter(this, void 0, void 0, function* () {
741
+ const { shopID, opts } = config;
742
+ return (0, mapResponseData_js_1.mapResponseData)(yield (0, request_js_1.request)(GetReturnsPageQuery_js_1.default)({ shopID, lastKey: "" }, opts), (v) => ({
743
+ returns: v.items,
744
+ lastKey: v.last_key,
745
+ }));
746
+ }));
747
+ const getPageFx = (0, effector_1.createEffect)((p) => tslib_1.__awaiter(this, void 0, void 0, function* () {
748
+ const { shopID, opts } = p.config;
749
+ return (0, request_js_1.request)(GetReturnsPageQuery_js_1.default)({ shopID, lastKey: p.data }, opts);
750
+ }));
751
+ const loadMore = (0, effector_1.createEvent)();
752
+ // init returns and last key stores from API response
753
+ const returns = (0, effector_1.createStore)([]);
754
+ const lastKey = (0, effector_1.createStore)("");
755
+ returns.on(init.event, (_, v) => v.returns);
756
+ lastKey.on(init.event, (_, v) => v.lastKey);
757
+ // on loadMore, sample lastKey and fetch next page (if not already pending)
758
+ (0, effector_1.guard)({
759
+ source: (0, effector_1.sample)(binding.internalConfig, (0, effector_1.sample)(lastKey, loadMore), (config, data) => ({ config, data })),
760
+ filter: binding.everythingIdle,
761
+ target: getPageFx,
762
+ });
763
+ const { data: getPageData, error: getPageError } = (0, requestResponse_js_1.requestResponseSplit)(getPageFx.doneData);
764
+ // success: propagate new data to stores (note, last key is only applied when it's there)
765
+ returns.on(getPageData.map((v) => v.items), (returns, newReturns) => [...returns, ...newReturns]);
766
+ lastKey.on(getPageData.filterMap((v) => v.last_key || undefined), (_, v) => v);
767
+ // error: report unexpected error
768
+ (0, effector_1.forward)({ from: getPageError, to: binding.unexpectedError });
769
+ return {
770
+ init,
771
+ returns,
772
+ loadMore,
773
+ somethingIsPending: (0, combineSome_js_1.combineSome)(init.pending, getPageFx.pending),
774
+ };
775
+ }
776
+ //===================================================================================================================
777
+ //===================================================================================================================
778
+ //===================================================================================================================
779
+ function createFavoritesPageGraph(binding) {
780
+ const init = defineInit(binding, (config, _p) => tslib_1.__awaiter(this, void 0, void 0, function* () {
781
+ const { shopID, opts } = config;
782
+ return (0, mapResponseData_js_1.mapResponseData)(yield (0, request_js_1.request)(GetFavoritesQuery_js_1.default)({ shopID }, opts), (v) => ({
783
+ favorites: v.sort((a, b) => a.created_at.localeCompare(b.created_at)),
784
+ }));
785
+ }));
786
+ const favorites = (0, effector_1.createStore)([]);
787
+ favorites.on(init.event, (_, v) => v.favorites);
788
+ (0, effector_1.forward)({
789
+ from: init.event.map((v) => (0, compact_js_1.compact)(v.favorites.map((v) => v.variant
790
+ ? {
791
+ id: v.id,
792
+ variantID: v.variant.id,
793
+ inventoryNotification: v.inventory_notification,
794
+ priceNotification: v.price_notification,
795
+ }
796
+ : null))),
797
+ to: binding.setFavorites,
798
+ });
799
+ const addFavoriteFx = (0, effector_1.createEffect)((p) => tslib_1.__awaiter(this, void 0, void 0, function* () {
800
+ const { shopID, opts } = p.config;
801
+ return (0, request_js_1.request)(CreateFavoriteMutation_js_1.default)({ shopID, data: p.data }, opts);
802
+ }));
803
+ const addFavoriteResult = (0, requestResponse_js_1.requestResponseSplit)(addFavoriteFx.doneData);
804
+ // success
805
+ (0, effector_1.forward)({
806
+ from: addFavoriteResult.data.map(() => "favorites"),
807
+ to: binding.reloadPageIfActive,
808
+ });
809
+ (0, effector_1.forward)({
810
+ from: addFavoriteFx.done.filterMap((v) => v.result.kind === "data"
811
+ ? {
812
+ id: v.result.data[0].id,
813
+ variantID: v.params.data.variant_id,
814
+ inventoryNotification: v.result.data[0].inventory_notification,
815
+ priceNotification: v.result.data[0].price_notification,
816
+ }
817
+ : undefined),
818
+ to: binding.addFavoriteToInfo,
819
+ });
820
+ (0, effector_1.forward)({
821
+ from: addFavoriteResult.data.map(() => "favorite_added"),
822
+ to: binding.message,
823
+ });
824
+ // failure
825
+ (0, effector_1.forward)({
826
+ from: addFavoriteResult.error,
827
+ to: binding.unexpectedError,
828
+ });
829
+ const deleteFavoriteFx = (0, effector_1.createEffect)((p) => tslib_1.__awaiter(this, void 0, void 0, function* () {
830
+ const { shopID, opts } = p.config;
831
+ return (0, request_js_1.request)(DeleteFavoriteMutation_js_1.default)({ shopID, id: p.data }, opts);
832
+ }));
833
+ const deleteFavoriteResult = (0, requestResponse_js_1.requestResponseSplit)(deleteFavoriteFx.doneData);
834
+ // success
835
+ (0, effector_1.forward)({
836
+ from: deleteFavoriteResult.data.map(() => "favorites"),
837
+ to: binding.reloadPageIfActive,
838
+ });
839
+ (0, effector_1.forward)({
840
+ from: deleteFavoriteFx.done.filterMap((v) => (v.result.kind === "data" ? v.params.data : undefined)),
841
+ to: binding.removeFavoriteFromInfo,
842
+ });
843
+ (0, effector_1.forward)({
844
+ from: deleteFavoriteResult.data.map(() => "favorite_deleted"),
845
+ to: binding.message,
846
+ });
847
+ // failure
848
+ (0, effector_1.forward)({
849
+ from: deleteFavoriteResult.error,
850
+ to: binding.unexpectedError,
851
+ });
852
+ const modifyFavoriteFx = (0, effector_1.createEffect)((p) => tslib_1.__awaiter(this, void 0, void 0, function* () {
853
+ const { shopID, opts } = p.config;
854
+ return (0, request_js_1.request)(ModifyFavoriteMutation_js_1.default)({ shopID, id: p.data[0], data: p.data[1] }, opts);
855
+ }));
856
+ const modifyFavoriteResult = (0, requestResponse_js_1.requestResponseSplit)(modifyFavoriteFx.doneData);
857
+ // success
858
+ (0, effector_1.forward)({
859
+ from: modifyFavoriteResult.data.map(() => "favorites"),
860
+ to: binding.reloadPageIfActive,
861
+ });
862
+ (0, effector_1.forward)({
863
+ from: modifyFavoriteFx.done.filterMap((v) => {
864
+ var _a;
865
+ return v.result.kind === "data"
866
+ ? {
867
+ id: v.result.data[0].id,
868
+ variantID: ((_a = v.result.data[0].variant) === null || _a === void 0 ? void 0 : _a.id) || "",
869
+ inventoryNotification: v.result.data[0].inventory_notification,
870
+ priceNotification: v.result.data[0].price_notification,
871
+ }
872
+ : undefined;
873
+ }),
874
+ to: binding.modifyFavoriteInInfo,
875
+ });
876
+ (0, effector_1.forward)({
877
+ from: modifyFavoriteResult.data.map(() => "favorite_modified"),
878
+ to: binding.message,
879
+ });
880
+ // failure
881
+ (0, effector_1.forward)({
882
+ from: modifyFavoriteResult.error,
883
+ to: binding.unexpectedError,
884
+ });
885
+ const deleteFavorite = (0, effector_1.createEvent)();
886
+ (0, effector_1.guard)({
887
+ source: (0, effector_1.sample)(binding.internalConfig, deleteFavorite, (config, data) => ({ config, data })),
888
+ filter: binding.everythingIdle,
889
+ target: deleteFavoriteFx,
890
+ });
891
+ const addFavorite = (0, effector_1.createEvent)();
892
+ const addFavoriteEx = (0, effector_1.createEvent)();
893
+ (0, effector_1.guard)({
894
+ source: (0, effector_1.sample)(binding.internalConfig, addFavorite, (config, variant_id) => ({
895
+ config,
896
+ data: { variant_id },
897
+ })),
898
+ filter: binding.everythingIdle,
899
+ target: addFavoriteFx,
900
+ });
901
+ (0, effector_1.guard)({
902
+ source: (0, effector_1.sample)(binding.internalConfig, addFavoriteEx, (config, data) => ({ config, data })),
903
+ filter: binding.everythingIdle,
904
+ target: addFavoriteFx,
905
+ });
906
+ const modifyFavorite = (0, effector_1.createEvent)();
907
+ (0, effector_1.guard)({
908
+ source: (0, effector_1.sample)(binding.internalConfig, modifyFavorite, (config, data) => ({ config, data })),
909
+ filter: binding.everythingIdle,
910
+ target: modifyFavoriteFx,
911
+ });
912
+ return {
913
+ init,
914
+ favorites,
915
+ addFavorite,
916
+ addFavoriteEx,
917
+ modifyFavorite,
918
+ deleteFavorite,
919
+ somethingIsPending: (0, combineSome_js_1.combineSome)(init.pending, addFavoriteFx.pending, modifyFavoriteFx.pending, deleteFavoriteFx.pending),
920
+ };
921
+ }
922
+ //===================================================================================================================
923
+ //===================================================================================================================
924
+ //===================================================================================================================
925
+ function addressToAPI(addr) {
926
+ const { country, province, latitude, longitude } = addr, apiAddr = tslib_1.__rest(addr, ["country", "province", "latitude", "longitude"]);
927
+ return Object.assign(Object.assign({}, apiAddr), { country: addr.country ? addr.country.code : "", province: addr.province ? addr.province.code : "" });
928
+ }
929
+ function createAddressesPageGraph(binding) {
930
+ const init = defineInit(binding, (config, _p) => tslib_1.__awaiter(this, void 0, void 0, function* () {
931
+ const { shopID, opts } = config;
932
+ const jwt = (0, jwt_decode_1.default)((0, nonNull_js_1.nonNull)(opts === null || opts === void 0 ? void 0 : opts.authToken, "auth token"));
933
+ return (0, multiResponseToResponse_js_1.multiResponseToResponse)(yield (0, request_js_1.requestMulti)(GetCustomerAddressesPageDataQuery_js_1.default)({ shopID, customerID: jwt.customer_id }, opts), (v) => {
934
+ var _a, _b;
935
+ const { analyticsGeoip, countries, storefrontCustomers } = v;
936
+ if (!analyticsGeoip || !countries || !storefrontCustomers) {
937
+ return undefined;
938
+ }
939
+ let geoCountryCode = ((_a = analyticsGeoip.country) === null || _a === void 0 ? void 0 : _a.code) || "";
940
+ let geoProvinceCode = ((_b = analyticsGeoip.province) === null || _b === void 0 ? void 0 : _b.code) || "";
941
+ if (!countries.find((v) => v.code === geoCountryCode)) {
942
+ geoCountryCode = "";
943
+ geoProvinceCode = "";
944
+ }
945
+ return {
946
+ availableCountries: (0, addEmptyListItem_js_1.addEmptyListItem)(countries.map((v) => ({ value: v.code, label: v.name }))),
947
+ customer: storefrontCustomers[0],
948
+ geoCountryCode,
949
+ geoProvinceCode,
950
+ };
951
+ });
952
+ }));
953
+ const { availableProvinces, country, province } = createAvailableProvincesLogic(binding, [validator_js_1.validNonEmpty]);
954
+ const form = (0, form_js_1.createForm)({
955
+ id: (0, form_js_1.createStringField)("id", "", []),
956
+ name: (0, form_js_1.createStringField)("name", "", [validator_js_1.validNonEmpty, validator_js_1.validMaxLength160]),
957
+ address1: (0, form_js_1.createStringField)("address1", "", [validator_js_1.validNonEmpty, validator_js_1.validMaxLength190]),
958
+ address2: (0, form_js_1.createStringField)("address2", "", [validator_js_1.validMaxLength190]),
959
+ city: (0, form_js_1.createStringField)("city", "", [validator_js_1.validNonEmpty, validator_js_1.validMaxLength80]),
960
+ zip: (0, form_js_1.createStringField)("zip", "", [validator_js_1.validNonEmpty, validator_js_1.validMaxLength32]),
961
+ country,
962
+ province,
963
+ default_shipping: (0, form_js_1.createBooleanField)("default_shipping", false),
964
+ default_billing: (0, form_js_1.createBooleanField)("default_billing", false),
965
+ });
966
+ // prefill country/province with geoip data
967
+ (0, effector_1.forward)({
968
+ from: init.event.map((v) => v.geoCountryCode),
969
+ to: form.country.setInitialValue,
970
+ });
971
+ (0, effector_1.forward)({
972
+ from: init.event.map((v) => v.geoProvinceCode),
973
+ to: form.province.setInitialValue,
974
+ });
975
+ const modifyCustomerFx = (0, effector_1.createEffect)((p) => tslib_1.__awaiter(this, void 0, void 0, function* () {
976
+ const { shopID, opts } = p.config;
977
+ const jwt = (0, jwt_decode_1.default)((0, nonNull_js_1.nonNull)(opts === null || opts === void 0 ? void 0 : opts.authToken, "auth token"));
978
+ return (0, request_js_1.request)(ModifyCustomerMutation_js_1.default)({ shopID, id: jwt.customer_id, data: p.data }, opts);
979
+ }));
980
+ const modifyCustomerResult = (0, requestResponse_js_1.requestResponseSplitFirst)(modifyCustomerFx.doneData);
981
+ // success
982
+ (0, effector_1.forward)({
983
+ from: modifyCustomerResult.data,
984
+ to: binding.reloadPage,
985
+ });
986
+ // failure
987
+ handleFormFailure({ source: modifyCustomerResult.error, form, unexpectedError: binding.unexpectedError });
988
+ const pageData = (0, effector_1.createStore)(null);
989
+ pageData.on(init.event, (_, v) => v);
990
+ // show form for a particular address
991
+ const isFormVisible = (0, effector_1.createStore)(false);
992
+ const addressEditIndex = (0, effector_1.createStore)(-1);
993
+ const showFormFor = (0, effector_1.createEvent)();
994
+ const toggleFormVisibility = (0, effector_1.createEvent)();
995
+ const formVisibilityChanged = (0, effector_1.createEvent)();
996
+ (0, effector_1.guard)({
997
+ source: showFormFor.map((index) => ({ visible: true, index })),
998
+ filter: binding.everythingIdle,
999
+ target: formVisibilityChanged,
1000
+ });
1001
+ (0, effector_1.guard)({
1002
+ source: (0, effector_1.sample)(isFormVisible, toggleFormVisibility, (v) => ({ visible: !v, index: -1 })),
1003
+ filter: binding.everythingIdle,
1004
+ target: formVisibilityChanged,
1005
+ });
1006
+ (0, effector_1.forward)({
1007
+ from: (0, effector_1.sample)(addressEditIndex, init.event, (index) => ({ visible: false, index })),
1008
+ to: formVisibilityChanged,
1009
+ });
1010
+ (0, effector_1.forward)({
1011
+ from: formVisibilityChanged.map((v) => v.visible),
1012
+ to: isFormVisible,
1013
+ });
1014
+ (0, effector_1.forward)({
1015
+ from: formVisibilityChanged.filterMap((v) => (v.visible ? v.index : undefined)),
1016
+ to: addressEditIndex,
1017
+ });
1018
+ (0, effector_1.forward)({
1019
+ from: (0, effector_1.sample)(pageData, formVisibilityChanged.filterMap((v) => (v.visible ? v : undefined)), (pageData, { index }) => {
1020
+ var _a, _b;
1021
+ const empty = {
1022
+ id: "",
1023
+ name: "",
1024
+ address1: "",
1025
+ address2: "",
1026
+ city: "",
1027
+ zip: "",
1028
+ country: "",
1029
+ province: "",
1030
+ default_shipping: false,
1031
+ default_billing: false,
1032
+ };
1033
+ if (index === -1)
1034
+ return empty;
1035
+ const c = pageData === null || pageData === void 0 ? void 0 : pageData.customer;
1036
+ if (!c)
1037
+ return empty;
1038
+ const a = c.addresses[index];
1039
+ if (!a)
1040
+ return empty;
1041
+ return {
1042
+ id: a.id,
1043
+ name: a.name,
1044
+ address1: a.address1,
1045
+ address2: a.address2,
1046
+ city: a.city,
1047
+ zip: a.zip,
1048
+ country: ((_a = a.country) === null || _a === void 0 ? void 0 : _a.code) || "",
1049
+ province: ((_b = a.province) === null || _b === void 0 ? void 0 : _b.code) || "",
1050
+ default_shipping: a.id === c.default_shipping_address_id,
1051
+ default_billing: a.id === c.default_billing_address_id,
1052
+ };
1053
+ }),
1054
+ to: form.init,
1055
+ });
1056
+ const formSubmit = (0, effector_1.sample)((0, effector_1.combine)({ pageData, addressEditIndex }), form.submitted, ({ pageData, addressEditIndex }, data) => {
1057
+ if (addressEditIndex === -1) {
1058
+ const addresses = (pageData === null || pageData === void 0 ? void 0 : pageData.customer.addresses) || [];
1059
+ const { default_billing, default_shipping } = data, apiData = tslib_1.__rest(data, ["default_billing", "default_shipping"]);
1060
+ return {
1061
+ addresses: [
1062
+ ...addresses.map(addressToAPI),
1063
+ Object.assign(Object.assign({}, apiData), { phone: "", company: "" }),
1064
+ ],
1065
+ default_billing_address_id: default_billing ? "first" : undefined,
1066
+ default_shipping_address_id: default_shipping ? "first" : undefined,
1067
+ };
1068
+ }
1069
+ else {
1070
+ const { default_billing, default_shipping } = data, apiData = tslib_1.__rest(data, ["default_billing", "default_shipping"]);
1071
+ const addresses = [...((pageData === null || pageData === void 0 ? void 0 : pageData.customer.addresses) || [])].map(addressToAPI);
1072
+ addresses[addressEditIndex] = Object.assign(Object.assign({}, apiData), { phone: "", company: "" });
1073
+ const prevDB = (pageData === null || pageData === void 0 ? void 0 : pageData.customer.default_billing_address_id) === apiData.id;
1074
+ const prevDS = (pageData === null || pageData === void 0 ? void 0 : pageData.customer.default_shipping_address_id) === apiData.id;
1075
+ return {
1076
+ addresses,
1077
+ default_billing_address_id: default_billing !== prevDB ? (default_billing ? apiData.id : "") : undefined,
1078
+ default_shipping_address_id: default_shipping !== prevDS ? (default_shipping ? apiData.id : "") : undefined,
1079
+ };
1080
+ }
1081
+ });
1082
+ (0, effector_1.guard)({
1083
+ source: (0, effector_1.sample)(binding.internalConfig, formSubmit, (config, data) => ({ config, data })),
1084
+ filter: binding.everythingIdle,
1085
+ target: modifyCustomerFx,
1086
+ });
1087
+ const deleteAddress = (0, effector_1.createEvent)();
1088
+ const deleteAddressValid = (0, effector_1.sample)(pageData, deleteAddress, (pageData, idx) => {
1089
+ const addressesLength = (pageData === null || pageData === void 0 ? void 0 : pageData.customer.addresses.length) || 0;
1090
+ return idx >= 0 && idx < addressesLength ? idx : undefined;
1091
+ }).filterMap((v) => v);
1092
+ const deleteAddressSubmit = (0, effector_1.sample)(pageData, deleteAddressValid, (pageData, idx) => {
1093
+ const dbid = (pageData === null || pageData === void 0 ? void 0 : pageData.customer.default_billing_address_id) || "";
1094
+ const dsid = (pageData === null || pageData === void 0 ? void 0 : pageData.customer.default_shipping_address_id) || "";
1095
+ const addresses = pageData === null || pageData === void 0 ? void 0 : pageData.customer.addresses.filter((_, aidx) => aidx !== idx).map(addressToAPI);
1096
+ return {
1097
+ addresses,
1098
+ default_billing_address_id: (addresses === null || addresses === void 0 ? void 0 : addresses.some((a) => a.id === dbid)) ? dbid : "",
1099
+ default_shipping_address_id: (addresses === null || addresses === void 0 ? void 0 : addresses.some((a) => a.id === dsid)) ? dsid : "",
1100
+ };
1101
+ });
1102
+ const makeDefault = (0, effector_1.createEvent)();
1103
+ const makeDefaultValid = (0, effector_1.sample)(pageData, makeDefault, (pageData, idx) => {
1104
+ const addresses = pageData === null || pageData === void 0 ? void 0 : pageData.customer.addresses;
1105
+ return addresses && idx >= 0 && idx < addresses.length ? addresses[idx].id : undefined;
1106
+ }).filterMap((v) => v);
1107
+ const makeDefaultSubmit = makeDefaultValid.map((id) => {
1108
+ return {
1109
+ default_billing_address_id: id,
1110
+ default_shipping_address_id: id,
1111
+ };
1112
+ });
1113
+ (0, effector_1.guard)({
1114
+ source: (0, effector_1.sample)(binding.internalConfig, deleteAddressSubmit, (config, data) => ({ config, data })),
1115
+ filter: binding.everythingIdle,
1116
+ target: modifyCustomerFx,
1117
+ });
1118
+ (0, effector_1.guard)({
1119
+ source: (0, effector_1.sample)(binding.internalConfig, makeDefaultSubmit, (config, data) => ({ config, data })),
1120
+ filter: binding.everythingIdle,
1121
+ target: modifyCustomerFx,
1122
+ });
1123
+ return {
1124
+ init,
1125
+ form,
1126
+ showFormFor,
1127
+ toggleFormVisibility,
1128
+ isFormVisible,
1129
+ addressEditIndex,
1130
+ pageData,
1131
+ availableProvinces: availableProvinces.map((v) => (0, addEmptyListItem_js_1.addEmptyListItem)(v.map((v) => ({ value: v.code, label: v.name })))),
1132
+ deleteAddress,
1133
+ makeDefault,
1134
+ somethingIsPending: (0, combineSome_js_1.combineSome)(init.pending, modifyCustomerFx.pending),
1135
+ };
1136
+ }
1137
+ //===================================================================================================================
1138
+ //===================================================================================================================
1139
+ //===================================================================================================================
1140
+ function createOrderPageGraph(binding) {
1141
+ const init = defineInit(binding, (config, p) => tslib_1.__awaiter(this, void 0, void 0, function* () {
1142
+ const { shopID, opts } = config;
1143
+ return (0, mapResponseData_js_1.mapResponseData)(yield (0, request_js_1.request)(GetOrderQuery_js_1.default)({ shopID, id: p.param.orderID }, opts), (v) => ({
1144
+ order: v[0],
1145
+ }));
1146
+ }));
1147
+ const order = (0, effector_1.createStore)(null).on(init.event, (_, v) => v.order);
1148
+ const cancelOrderFx = (0, effector_1.createEffect)((p) => tslib_1.__awaiter(this, void 0, void 0, function* () {
1149
+ const { shopID, opts } = p.config;
1150
+ return (0, request_js_1.request)(CancelOrderMutation_js_1.default)({ shopID, id: p.data }, opts);
1151
+ }));
1152
+ const cancelOrderResult = (0, requestResponse_js_1.requestResponseSplit)(cancelOrderFx.doneData);
1153
+ // success
1154
+ (0, effector_1.forward)({
1155
+ from: cancelOrderResult.data,
1156
+ to: binding.reloadPage,
1157
+ });
1158
+ // failure
1159
+ (0, effector_1.forward)({
1160
+ from: cancelOrderResult.error,
1161
+ to: binding.unexpectedError,
1162
+ });
1163
+ const cancelOrder = (0, effector_1.createEvent)();
1164
+ const canCancelOrder = order.map((o) => o !== null && o.on_hold && !o.canceled_at);
1165
+ (0, effector_1.guard)({
1166
+ source: (0, effector_1.sample)((0, effector_1.combine)({ config: binding.internalConfig, order }), cancelOrder, ({ config, order }) => ({
1167
+ config,
1168
+ data: (order === null || order === void 0 ? void 0 : order.id) || "",
1169
+ })),
1170
+ filter: (0, combineEvery_js_1.combineEvery)(binding.everythingIdle, canCancelOrder),
1171
+ target: cancelOrderFx,
1172
+ });
1173
+ return {
1174
+ init,
1175
+ order,
1176
+ cancelOrder,
1177
+ canCancelOrder,
1178
+ somethingIsPending: (0, combineSome_js_1.combineSome)(init.pending, cancelOrderFx.pending),
1179
+ };
1180
+ }
1181
+ //===================================================================================================================
1182
+ //===================================================================================================================
1183
+ //===================================================================================================================
1184
+ function createSubscriptionPageGraph(binding) {
1185
+ const init = defineInit(binding, (config, p) => tslib_1.__awaiter(this, void 0, void 0, function* () {
1186
+ const { shopID, opts } = config;
1187
+ const jwt = (0, jwt_decode_1.default)((0, nonNull_js_1.nonNull)(opts === null || opts === void 0 ? void 0 : opts.authToken, "auth token"));
1188
+ return (0, multiResponseToResponse_js_1.multiResponseToResponse)(yield (0, request_js_1.requestMulti)(GetSubscriptionQuery_js_1.default)({ shopID, subscriptionID: p.param.subscriptionID, customerID: jwt.customer_id }, opts), (v) => {
1189
+ var _a;
1190
+ if (!v.storefrontSubscriptions || !v.storefrontCustomers)
1191
+ return undefined;
1192
+ return {
1193
+ customer: (_a = v.storefrontCustomers) === null || _a === void 0 ? void 0 : _a[0],
1194
+ paymentMethods: v.storefrontPaymentSources || [],
1195
+ subscription: v.storefrontSubscriptions[0],
1196
+ };
1197
+ }, true);
1198
+ }));
1199
+ const subscription = (0, effector_1.createStore)(null).on(init.event, (_, v) => v.subscription);
1200
+ const customer = (0, effector_1.createStore)(null).on(init.event, (_, v) => v.customer);
1201
+ const paymentMethods = (0, effector_1.createStore)([]).on(init.event, (_, v) => v.paymentMethods);
1202
+ const form = (0, form_js_1.createForm)({
1203
+ billing_address: (0, form_js_1.createEnumField)("billing_address", "origin_order", []),
1204
+ billing_address_id: (0, form_js_1.createStringField)("billing_address_id", "", []),
1205
+ shipping_address: (0, form_js_1.createEnumField)("shipping_address", "origin_order", []),
1206
+ shipping_address_id: (0, form_js_1.createStringField)("shipping_address_id", "", []),
1207
+ payment_source: (0, form_js_1.createEnumField)("payment_source", "origin_order", []),
1208
+ payment_source_id: (0, form_js_1.createStringField)("payment_source_id", "", []),
1209
+ });
1210
+ (0, effector_1.forward)({
1211
+ from: init.event.map((v) => {
1212
+ const s = v.subscription;
1213
+ return {
1214
+ billing_address: (s === null || s === void 0 ? void 0 : s.billing_address) || "origin_order",
1215
+ billing_address_id: (s === null || s === void 0 ? void 0 : s.billing_address_id) || "",
1216
+ shipping_address: (s === null || s === void 0 ? void 0 : s.shipping_address) || "origin_order",
1217
+ shipping_address_id: (s === null || s === void 0 ? void 0 : s.shipping_address_id) || "",
1218
+ payment_source: (s === null || s === void 0 ? void 0 : s.payment_source) || "origin_order",
1219
+ payment_source_id: (s === null || s === void 0 ? void 0 : s.payment_source_id) || "",
1220
+ };
1221
+ }),
1222
+ to: form.init,
1223
+ });
1224
+ const cancel = (0, effector_1.createEvent)();
1225
+ const pause = (0, effector_1.createEvent)();
1226
+ const resume = (0, effector_1.createEvent)();
1227
+ const skipNext = (0, effector_1.createEvent)();
1228
+ const editFx = (0, effector_1.createEffect)((p) => tslib_1.__awaiter(this, void 0, void 0, function* () {
1229
+ const { shopID, opts } = p.config;
1230
+ return (0, request_js_1.request)(EditSubscriptionMutation_js_1.default)({ shopID, subscriptionID: p.data[0], data: p.data[1] }, opts);
1231
+ }));
1232
+ const cancelFx = (0, effector_1.createEffect)((p) => tslib_1.__awaiter(this, void 0, void 0, function* () {
1233
+ const { shopID, opts } = p.config;
1234
+ return (0, request_js_1.request)(CancelSubscriptionMutation_js_1.default)({ shopID, subscriptionID: p.data }, opts);
1235
+ }));
1236
+ const pauseFx = (0, effector_1.createEffect)((p) => tslib_1.__awaiter(this, void 0, void 0, function* () {
1237
+ const { shopID, opts } = p.config;
1238
+ return (0, request_js_1.request)(PauseSubscriptionMutation_js_1.default)({ shopID, subscriptionID: p.data }, opts);
1239
+ }));
1240
+ const resumeFx = (0, effector_1.createEffect)((p) => tslib_1.__awaiter(this, void 0, void 0, function* () {
1241
+ const { shopID, opts } = p.config;
1242
+ return (0, request_js_1.request)(ResumeSubscriptionMutation_js_1.default)({ shopID, subscriptionID: p.data }, opts);
1243
+ }));
1244
+ const skipNextFx = (0, effector_1.createEffect)((p) => tslib_1.__awaiter(this, void 0, void 0, function* () {
1245
+ const { shopID, opts } = p.config;
1246
+ return (0, request_js_1.request)(SkipNextSubscriptionMutation_js_1.default)({ shopID, subscriptionID: p.data }, opts);
1247
+ }));
1248
+ const configAndSubscription = (0, effector_1.combine)({ config: binding.internalConfig, subscription });
1249
+ const connectEventToFx = (ev, fx) => {
1250
+ (0, effector_1.guard)({
1251
+ source: (0, effector_1.sample)(configAndSubscription, ev, (cas) => {
1252
+ var _a;
1253
+ return ({
1254
+ config: cas.config,
1255
+ data: ((_a = cas.subscription) === null || _a === void 0 ? void 0 : _a.id) || "",
1256
+ });
1257
+ }),
1258
+ filter: binding.everythingIdle,
1259
+ target: fx,
1260
+ });
1261
+ };
1262
+ connectEventToFx(cancel, cancelFx);
1263
+ connectEventToFx(pause, pauseFx);
1264
+ connectEventToFx(resume, resumeFx);
1265
+ connectEventToFx(skipNext, skipNextFx);
1266
+ const cancelResult = (0, requestResponse_js_1.requestResponseSplit)(cancelFx.doneData);
1267
+ const pauseResult = (0, requestResponse_js_1.requestResponseSplit)(pauseFx.doneData);
1268
+ const resumeResult = (0, requestResponse_js_1.requestResponseSplit)(resumeFx.doneData);
1269
+ const skipNextResult = (0, requestResponse_js_1.requestResponseSplit)(skipNextFx.doneData);
1270
+ // success
1271
+ (0, effector_1.forward)({ from: cancelResult.data, to: binding.reloadPage });
1272
+ (0, effector_1.forward)({ from: pauseResult.data, to: binding.reloadPage });
1273
+ (0, effector_1.forward)({ from: resumeResult.data, to: binding.reloadPage });
1274
+ (0, effector_1.forward)({ from: skipNextResult.data, to: binding.reloadPage });
1275
+ // failure
1276
+ (0, effector_1.forward)({ from: cancelResult.error, to: binding.unexpectedError });
1277
+ (0, effector_1.forward)({ from: pauseResult.error, to: binding.unexpectedError });
1278
+ (0, effector_1.forward)({ from: resumeResult.error, to: binding.unexpectedError });
1279
+ (0, effector_1.forward)({ from: skipNextResult.error, to: binding.unexpectedError });
1280
+ const editResult = (0, requestResponse_js_1.requestResponseSplit)(editFx.doneData);
1281
+ // success
1282
+ (0, effector_1.forward)({
1283
+ from: editResult.data,
1284
+ to: binding.reloadPage,
1285
+ });
1286
+ // failure
1287
+ handleFormFailure({ source: editResult.error, form, unexpectedError: binding.unexpectedError });
1288
+ const formSubmit = (0, effector_1.sample)(subscription, form.submitted, (subscription, data) => {
1289
+ const r = [(subscription === null || subscription === void 0 ? void 0 : subscription.id) || "", data];
1290
+ return r;
1291
+ });
1292
+ (0, effector_1.guard)({
1293
+ source: (0, effector_1.sample)(binding.internalConfig, formSubmit, (config, data) => ({ config, data })),
1294
+ filter: binding.everythingIdle,
1295
+ target: editFx,
1296
+ });
1297
+ const setBillingAddressValueAndID = (0, effector_1.createEvent)();
1298
+ const setShippingAddressValueAndID = (0, effector_1.createEvent)();
1299
+ const setPaymentSourceValueAndID = (0, effector_1.createEvent)();
1300
+ (0, effector_1.forward)({ from: setBillingAddressValueAndID.map((v) => v[0]), to: form.billing_address.change });
1301
+ (0, effector_1.forward)({ from: setBillingAddressValueAndID.map((v) => v[1]), to: form.billing_address_id.change });
1302
+ (0, effector_1.forward)({ from: setShippingAddressValueAndID.map((v) => v[0]), to: form.shipping_address.change });
1303
+ (0, effector_1.forward)({ from: setShippingAddressValueAndID.map((v) => v[1]), to: form.shipping_address_id.change });
1304
+ (0, effector_1.forward)({ from: setPaymentSourceValueAndID.map((v) => v[0]), to: form.payment_source.change });
1305
+ (0, effector_1.forward)({ from: setPaymentSourceValueAndID.map((v) => v[1]), to: form.payment_source_id.change });
1306
+ return {
1307
+ init,
1308
+ form,
1309
+ subscription,
1310
+ customer,
1311
+ paymentMethods,
1312
+ cancel,
1313
+ pause,
1314
+ resume,
1315
+ skipNext,
1316
+ somethingIsPending: (0, combineSome_js_1.combineSome)(init.pending, editFx.pending, cancelFx.pending, pauseFx.pending, resumeFx.pending, skipNextFx.pending),
1317
+ setBillingAddressValueAndID,
1318
+ setShippingAddressValueAndID,
1319
+ setPaymentSourceValueAndID,
1320
+ };
1321
+ }
1322
+ //===================================================================================================================
1323
+ //===================================================================================================================
1324
+ //===================================================================================================================
1325
+ function createReturnPageGraph(binding) {
1326
+ const init = defineInit(binding, (config, p) => tslib_1.__awaiter(this, void 0, void 0, function* () {
1327
+ const { shopID, opts } = config;
1328
+ return (0, multiResponseToResponse_js_1.multiResponseToResponse)(yield (0, request_js_1.requestMulti)(GetReturnQuery_js_1.default)({ shopID, id: p.param.returnID }, opts), (v) => {
1329
+ const { returnReasons: reasons, storefrontReturns } = v;
1330
+ return storefrontReturns
1331
+ ? {
1332
+ reasons: reasons || [],
1333
+ ret: storefrontReturns[0],
1334
+ }
1335
+ : undefined;
1336
+ });
1337
+ }));
1338
+ const data = (0, effector_1.createStore)(null).on(init.event, (_, v) => v);
1339
+ return {
1340
+ init,
1341
+ data,
1342
+ somethingIsPending: init.pending,
1343
+ };
1344
+ }
1345
+ function createCreateReturnPageGraph(binding) {
1346
+ const init = defineInit(binding, (config, p) => tslib_1.__awaiter(this, void 0, void 0, function* () {
1347
+ const { shopID, opts } = config;
1348
+ return (0, multiResponseToResponse_js_1.multiResponseToResponse)(yield (0, request_js_1.requestMulti)(GetReturnCreationInfoQuery_js_1.default)({ shopID, id: p.param.orderID }, opts), (v) => {
1349
+ const { storefrontOrderFulfillments: fulfillments, storefrontOrders: orders, storefrontReturnsFindPolicy: policy, returnReasons: reasons, } = v;
1350
+ return fulfillments && orders
1351
+ ? {
1352
+ fulfillments,
1353
+ order: orders[0],
1354
+ policy: policy || null,
1355
+ reasons: reasons || [],
1356
+ }
1357
+ : undefined;
1358
+ }, true);
1359
+ }));
1360
+ const ret = (0, effector_1.createStore)(null);
1361
+ ret.on(init.event, () => null);
1362
+ const refundToCustomerBalance = (0, effector_1.createStore)(false);
1363
+ refundToCustomerBalance.on(init.event, (ov, v) => {
1364
+ const p = v.policy;
1365
+ if (!p)
1366
+ return ov;
1367
+ if (p.refund_option === "customer_balance")
1368
+ return true;
1369
+ return false;
1370
+ });
1371
+ const setRefundToCustomerBalance = (0, effector_1.createEvent)();
1372
+ refundToCustomerBalance.on(setRefundToCustomerBalance, (_, v) => v);
1373
+ const shippingOptionIndex = (0, effector_1.createStore)(0);
1374
+ shippingOptionIndex.reset(init.event);
1375
+ const info = (0, effector_1.createStore)(null);
1376
+ info.on(init.event, (_, v) => v);
1377
+ const setShippingOptionIndex = (0, effector_1.createEvent)();
1378
+ shippingOptionIndex.on((0, effector_1.sample)(info, setShippingOptionIndex, (info, idx) => {
1379
+ const p = info === null || info === void 0 ? void 0 : info.policy;
1380
+ if (!p)
1381
+ return undefined;
1382
+ return Math.max(0, Math.min(idx, p.shipping_options.length - 1));
1383
+ }), (_, v) => v);
1384
+ const items = (0, effector_1.createStore)([]);
1385
+ items.on(init.event, (_, v) => {
1386
+ const vmap = createVariantMap(v.order);
1387
+ return v.fulfillments.map((f) => f.line_items.map((fli) => {
1388
+ const v = vmap[fli.variant_id];
1389
+ const p = v === null || v === void 0 ? void 0 : v.product;
1390
+ const quantity = Math.max(0, (p === null || p === void 0 ? void 0 : p.return_mode) === "not_allowed" ? 0 : fli.quantity - fli.returned);
1391
+ return {
1392
+ selected: false,
1393
+ quantity,
1394
+ maxQuantity: quantity,
1395
+ reason: null,
1396
+ };
1397
+ }));
1398
+ });
1399
+ const updateItem = (0, effector_1.createEvent)();
1400
+ items.on(updateItem, (old, [i, j, v]) => {
1401
+ const newItem = Object.assign({}, old[i][j]);
1402
+ if (v.selected !== undefined)
1403
+ newItem.selected = v.selected;
1404
+ if (v.quantity !== undefined) {
1405
+ newItem.quantity = Math.max(0, Math.min(v.quantity, newItem.maxQuantity));
1406
+ }
1407
+ if (v.reason !== undefined)
1408
+ newItem.reason = v.reason;
1409
+ const newItems = [...old];
1410
+ newItems[i] = [...old[i]];
1411
+ newItems[i][j] = newItem;
1412
+ return newItems;
1413
+ });
1414
+ const submit = (0, effector_1.createEvent)();
1415
+ const createReturnFx = (0, effector_1.createEffect)((p) => tslib_1.__awaiter(this, void 0, void 0, function* () {
1416
+ const { shopID, opts } = p.config;
1417
+ return (0, request_js_1.request)(CreateReturnMutation_js_1.default)({ shopID, data: p.data }, opts);
1418
+ }));
1419
+ const preparedData = (0, effector_1.combine)({ config: binding.internalConfig, items, info, refundToCustomerBalance, shippingOptionIndex }, ({ config, items, info, refundToCustomerBalance, shippingOptionIndex }) => {
1420
+ if (!info || !info.policy)
1421
+ return null;
1422
+ const lineItems = [];
1423
+ info.fulfillments.forEach((f, i) => {
1424
+ f.line_items.forEach((fli, j) => {
1425
+ const item = items[i][j];
1426
+ if (!item.selected)
1427
+ return;
1428
+ if (item.quantity <= 0)
1429
+ return;
1430
+ lineItems.push({
1431
+ fulfillment_id: f.id,
1432
+ line_item_id: fli.line_item_id,
1433
+ reason: item.reason || "other_reason",
1434
+ return_quantity: item.quantity,
1435
+ variant_id: fli.variant_id,
1436
+ });
1437
+ });
1438
+ });
1439
+ if (lineItems.length === 0)
1440
+ return null;
1441
+ const data = {
1442
+ order_id: info.order.id,
1443
+ return_policy_id: info.policy.id,
1444
+ shipping_option_index: shippingOptionIndex,
1445
+ customer_balance: refundToCustomerBalance,
1446
+ line_items: lineItems,
1447
+ };
1448
+ return { config, data };
1449
+ });
1450
+ const canSubmit = preparedData.map((v) => !!v);
1451
+ const submitted = (0, effector_1.sample)(preparedData, submit).filterMap((v) => v || undefined);
1452
+ (0, effector_1.guard)({
1453
+ source: submitted,
1454
+ filter: binding.everythingIdle,
1455
+ target: createReturnFx,
1456
+ });
1457
+ const createReturnResult = (0, requestResponse_js_1.requestResponseSplitFirst)(createReturnFx.doneData);
1458
+ // success
1459
+ (0, effector_1.forward)({
1460
+ from: createReturnResult.data,
1461
+ to: ret,
1462
+ });
1463
+ // failure
1464
+ (0, effector_1.forward)({
1465
+ from: createReturnResult.error,
1466
+ to: binding.unexpectedError,
1467
+ });
1468
+ return {
1469
+ init,
1470
+ ret,
1471
+ info,
1472
+ items,
1473
+ updateItem,
1474
+ setRefundToCustomerBalance,
1475
+ refundToCustomerBalance,
1476
+ setShippingOptionIndex,
1477
+ shippingOptionIndex,
1478
+ submit,
1479
+ canSubmit,
1480
+ somethingIsPending: (0, combineSome_js_1.combineSome)(init.pending, createReturnFx.pending),
1481
+ };
1482
+ }
1483
+ //===================================================================================================================
1484
+ //===================================================================================================================
1485
+ //===================================================================================================================
1486
+ function createStoreCreditPageGraph(binding) {
1487
+ const init = defineInit(binding, (config, p) => tslib_1.__awaiter(this, void 0, void 0, function* () {
1488
+ const { shopID, currency, opts } = config;
1489
+ return (0, multiResponseToResponse_js_1.multiResponseToResponse)(yield (0, request_js_1.requestMulti)(GetCustomerBalanceQuery_js_1.default)({ shopID, currency }, opts), (v) => {
1490
+ const { storefrontCustomerBalance: customerBalance, storefrontCustomerBalanceHistory: history } = v;
1491
+ return customerBalance && history
1492
+ ? {
1493
+ customerBalance,
1494
+ history,
1495
+ currency,
1496
+ resetSuccess: p.previousPageKind !== "store_credit",
1497
+ }
1498
+ : undefined;
1499
+ });
1500
+ }));
1501
+ const getPageFx = (0, effector_1.createEffect)((p) => tslib_1.__awaiter(this, void 0, void 0, function* () {
1502
+ const { shopID, opts } = p.config;
1503
+ return (0, mapResponseData_js_1.mapResponseData)(yield (0, request_js_1.request)(GetCustomerBalanceHistoryPageQuery_js_1.default)(Object.assign({ shopID }, p.data), opts), (data) => {
1504
+ return Object.assign(Object.assign({}, data), { isFirstPage: p.data.lastKey === "", currency: p.data.currency });
1505
+ });
1506
+ }));
1507
+ const setCurrency = (0, effector_1.createEvent)();
1508
+ const loadMore = (0, effector_1.createEvent)();
1509
+ const redeemedGiftCard = (0, effector_1.createEvent)();
1510
+ const customerBalance = (0, effector_1.createStore)(null).on(init.event, (_, v) => v.customerBalance);
1511
+ const history = (0, effector_1.createStore)([]);
1512
+ const lastKey = (0, effector_1.createStore)("");
1513
+ const historyCurrency = (0, effector_1.createStore)("");
1514
+ const currency = (0, effector_1.createStore)("");
1515
+ history.on(init.event, (_, v) => v.history.items);
1516
+ lastKey.on(init.event, (_, v) => v.history.last_key);
1517
+ historyCurrency.on(init.event, (_, v) => v.currency);
1518
+ currency.on(init.event, (_, v) => v.currency);
1519
+ // on currency change and if it's some new currency, reload history
1520
+ {
1521
+ const currencyChangeAccepted = (0, effector_1.guard)({
1522
+ source: (0, effector_1.guard)({
1523
+ source: (0, effector_1.sample)(historyCurrency, setCurrency, (historyCurrency, currency) => ({ historyCurrency, currency })),
1524
+ filter: (source) => source.currency !== source.historyCurrency,
1525
+ }),
1526
+ filter: binding.everythingIdle,
1527
+ });
1528
+ (0, effector_1.forward)({
1529
+ from: (0, effector_1.sample)(binding.internalConfig, currencyChangeAccepted, (config, v) => ({
1530
+ config,
1531
+ data: { lastKey: "", currency: v.currency },
1532
+ })),
1533
+ to: getPageFx,
1534
+ });
1535
+ (0, effector_1.forward)({
1536
+ from: currencyChangeAccepted.map((v) => v.currency),
1537
+ to: currency,
1538
+ });
1539
+ }
1540
+ // on loadMore, sample lastKey, currency and fetch next page (if not already pending)
1541
+ (0, effector_1.guard)({
1542
+ source: (0, effector_1.sample)((0, effector_1.combine)({ config: binding.internalConfig, lastKey, historyCurrency }), loadMore, (s) => ({
1543
+ config: s.config,
1544
+ data: { lastKey: s.lastKey, currency: s.historyCurrency },
1545
+ })),
1546
+ filter: binding.everythingIdle,
1547
+ target: getPageFx,
1548
+ });
1549
+ const { data: getPageData, error: getPageError } = (0, requestResponse_js_1.requestResponseSplit)(getPageFx.doneData);
1550
+ // success: propagate new data to stores (note, last key is only applied when it's there)
1551
+ history.on(getPageData, (history, p) => (p.isFirstPage ? p.items : [...history, ...p.items]));
1552
+ lastKey.on(getPageData.filterMap((v) => v.last_key || undefined), (_, v) => v);
1553
+ historyCurrency.on(getPageData.map((v) => v.currency), (_, v) => v);
1554
+ // error: report unexpected error
1555
+ (0, effector_1.forward)({ from: getPageError, to: binding.unexpectedError });
1556
+ // form
1557
+ const form = (0, form_js_1.createFormWithCustomError)({
1558
+ gift_card_code: (0, form_js_1.createStringField)("gift_card_code", "", [validator_js_1.validNonEmpty]),
1559
+ }, null);
1560
+ const formToggleState = createFormToggleState(binding, form);
1561
+ formToggleState.isFormVisible.reset(init.event);
1562
+ (0, effector_1.forward)({
1563
+ from: init.event,
1564
+ to: form.reset,
1565
+ });
1566
+ // create apply gift card effect and wire it to form
1567
+ const applyGiftCardFx = (0, effector_1.createEffect)((p) => tslib_1.__awaiter(this, void 0, void 0, function* () {
1568
+ const { shopID, opts } = p.config;
1569
+ return (0, request_js_1.request)(ApplyGiftCardMutation_js_1.default)({ shopID, data: p.data }, opts);
1570
+ }));
1571
+ (0, effector_1.guard)({
1572
+ source: (0, effector_1.sample)(binding.internalConfig, form.submitted, (config, data) => ({ config, data })),
1573
+ filter: binding.everythingIdle,
1574
+ target: applyGiftCardFx,
1575
+ });
1576
+ const applyGiftCardResult = (0, requestResponse_js_1.requestResponseSplit)(applyGiftCardFx.doneData);
1577
+ // success
1578
+ (0, effector_1.forward)({
1579
+ from: applyGiftCardResult.data,
1580
+ to: binding.reloadPage,
1581
+ });
1582
+ (0, effector_1.forward)({
1583
+ from: applyGiftCardResult.data,
1584
+ to: redeemedGiftCard,
1585
+ });
1586
+ (0, effector_1.forward)({
1587
+ from: applyGiftCardResult.data.map(() => false),
1588
+ to: formToggleState.isFormVisible,
1589
+ });
1590
+ // failure
1591
+ (0, split_js_1.splitMap)(applyGiftCardResult.error)
1592
+ .map((e) => { var _a; return (e.kind === "error" && ((_a = e.error.apiError) === null || _a === void 0 ? void 0 : _a.code) === codes_js_1.ErrorCode.NotFound ? "not_found" : undefined); }, form.setError)
1593
+ .fallback(handleFormFailure({ form, unexpectedError: binding.unexpectedError }));
1594
+ return Object.assign(Object.assign({ init,
1595
+ form }, formToggleState), { customerBalance, somethingIsPending: (0, combineSome_js_1.combineSome)(init.pending, applyGiftCardFx.pending, getPageFx.pending), redeemedGiftCard,
1596
+ setCurrency,
1597
+ currency,
1598
+ loadMore,
1599
+ historyCurrency,
1600
+ history });
1601
+ }
1602
+ //===================================================================================================================
1603
+ //===================================================================================================================
1604
+ //===================================================================================================================
1605
+ function createProfilePageGraph(binding) {
1606
+ const init = defineInit(binding, (config, _p) => tslib_1.__awaiter(this, void 0, void 0, function* () {
1607
+ const { shopID, opts } = config;
1608
+ const jwt = (0, jwt_decode_1.default)((0, nonNull_js_1.nonNull)(opts === null || opts === void 0 ? void 0 : opts.authToken, "auth token"));
1609
+ return (0, mapResponseData_js_1.mapResponseData)(yield (0, request_js_1.request)(GetCustomerQuery_js_1.default)({ shopID, id: jwt.customer_id }, opts), (v) => ({
1610
+ customer: v[0],
1611
+ }));
1612
+ }));
1613
+ const form = (0, form_js_1.createForm)({
1614
+ name: (0, form_js_1.createStringField)("name", "", [validator_js_1.validNonEmpty, validator_js_1.validMaxLength250]),
1615
+ display_name: (0, form_js_1.createStringField)("display_name", "", [validator_js_1.validMaxLength250]),
1616
+ mobile: (0, form_js_1.createStringField)("mobile", "", []),
1617
+ mobile_notifications: (0, form_js_1.createBooleanField)("mobile_notifications", false),
1618
+ accepts_marketing: (0, form_js_1.createBooleanField)("accepts_marketing", false),
1619
+ });
1620
+ (0, effector_1.forward)({
1621
+ from: init.event.map((v) => ({
1622
+ name: v.customer.name,
1623
+ display_name: v.customer.display_name,
1624
+ mobile: v.customer.mobile,
1625
+ mobile_notifications: v.customer.mobile_notifications,
1626
+ accepts_marketing: v.customer.accepts_marketing,
1627
+ })),
1628
+ to: form.init,
1629
+ });
1630
+ // submit form API call
1631
+ const saveFx = (0, effector_1.createEffect)((p) => tslib_1.__awaiter(this, void 0, void 0, function* () {
1632
+ const { shopID, opts } = p.config;
1633
+ const jwt = (0, jwt_decode_1.default)((0, nonNull_js_1.nonNull)(opts === null || opts === void 0 ? void 0 : opts.authToken, "auth token"));
1634
+ return (0, request_js_1.request)(ModifyCustomerMutation_js_1.default)({ shopID, id: jwt.customer_id, data: p.data }, opts);
1635
+ }));
1636
+ (0, effector_1.guard)({
1637
+ source: (0, effector_1.sample)(binding.internalConfig, form.submitted, (config, data) => ({ config, data })),
1638
+ filter: binding.everythingIdle,
1639
+ target: saveFx,
1640
+ });
1641
+ const { data: saveData, error: saveError } = (0, requestResponse_js_1.requestResponseSplit)(saveFx.doneData);
1642
+ // success
1643
+ (0, effector_1.forward)({ from: saveData, to: binding.reloadPage });
1644
+ // failure
1645
+ handleFormFailure({ source: saveError, form, unexpectedError: binding.unexpectedError }, { from: "[0]." });
1646
+ return {
1647
+ init,
1648
+ form,
1649
+ somethingIsPending: (0, combineSome_js_1.combineSome)(init.pending, saveFx.pending),
1650
+ };
1651
+ }
1652
+ //===================================================================================================================
1653
+ //===================================================================================================================
1654
+ //===================================================================================================================
1655
+ function createSigninPageGraph(binding) {
1656
+ const init = defineInitBlank(binding);
1657
+ const setSignInMode = (0, effector_1.createEvent)();
1658
+ const signInMode = (0, effector_1.restore)(setSignInMode, "email-otp-init");
1659
+ const form = (0, form_js_1.createFormWithCustomError)({
1660
+ email: (0, form_js_1.createStringField)("email", "", [validator_js_1.validNonEmpty, validator_js_1.validEmail, validator_js_1.validMaxLength250]),
1661
+ password: (0, form_js_1.createStringField)("password", "", [validator_js_1.validNonEmpty]),
1662
+ }, null);
1663
+ const formOTPInit = (0, form_js_1.createFormWithCustomError)({
1664
+ email: (0, form_js_1.createStringField)("email", "", [validator_js_1.validNonEmpty, validator_js_1.validEmail, validator_js_1.validMaxLength250]),
1665
+ }, null);
1666
+ const formOTPComplete = (0, form_js_1.createFormWithCustomError)({
1667
+ code: (0, form_js_1.createStringField)("code", "", [validator_js_1.validNonEmpty, validator_js_1.validMaxLength250]),
1668
+ }, null);
1669
+ (0, effector_1.forward)({
1670
+ from: init.event,
1671
+ to: [form.reset, formOTPInit.reset, formOTPComplete.reset],
1672
+ });
1673
+ signInMode.reset(init.event);
1674
+ const signinFx = (0, effector_1.createEffect)((p) => tslib_1.__awaiter(this, void 0, void 0, function* () {
1675
+ const { shopID, opts } = p.config;
1676
+ return (0, request_js_1.request)(SignInMutation_js_1.default)({ shopID, data: p.data }, opts);
1677
+ }));
1678
+ (0, effector_1.guard)({
1679
+ source: (0, effector_1.sample)(binding.internalConfig, form.submitted, (config, data) => ({ config, data })),
1680
+ filter: binding.everythingIdle,
1681
+ target: signinFx,
1682
+ });
1683
+ const signInViaEmailInitFx = (0, effector_1.createEffect)((p) => tslib_1.__awaiter(this, void 0, void 0, function* () {
1684
+ const { shopID, opts } = p.config;
1685
+ return (0, request_js_1.request)(SignInViaEmailInitMutation_js_1.default)({ shopID, data: p.data }, opts);
1686
+ }));
1687
+ (0, effector_1.guard)({
1688
+ source: (0, effector_1.sample)(binding.internalConfig, formOTPInit.submitted, (config, data) => ({
1689
+ config,
1690
+ data: Object.assign(Object.assign({}, data), { timezone_hint: (0, getTimezone_js_1.getTimezone)() }),
1691
+ })),
1692
+ filter: binding.everythingIdle,
1693
+ target: signInViaEmailInitFx,
1694
+ });
1695
+ const signInViaEmailCompleteFx = (0, effector_1.createEffect)((p) => tslib_1.__awaiter(this, void 0, void 0, function* () {
1696
+ const { shopID, opts } = p.config;
1697
+ return (0, request_js_1.request)(SignInViaEmailCompleteMutation_js_1.default)({ shopID, data: p.data }, opts);
1698
+ }));
1699
+ (0, effector_1.guard)({
1700
+ source: (0, effector_1.sample)((0, effector_1.combine)({ config: binding.internalConfig, email: formOTPInit.email.value }), formOTPComplete.submitted, ({ config, email }, data) => ({ config, data: Object.assign(Object.assign({}, data), { email }) })),
1701
+ filter: binding.everythingIdle,
1702
+ target: signInViaEmailCompleteFx,
1703
+ });
1704
+ // email/password form
1705
+ {
1706
+ const { data: signinData } = (0, requestResponse_js_1.requestResponseSplit)(signinFx.doneData);
1707
+ // success
1708
+ (0, effector_1.forward)({
1709
+ from: signinData.filterMap((v) => v.token || undefined),
1710
+ to: binding.setJWT,
1711
+ });
1712
+ // failure
1713
+ (0, split_js_1.splitMap)(signinFx.done)
1714
+ .map((e) => {
1715
+ var _a;
1716
+ return e.result.kind === "error" && ((_a = e.result.error.apiError) === null || _a === void 0 ? void 0 : _a.code) === codes_js_1.ErrorCode.Unauthorized
1717
+ ? e.params.data.email
1718
+ ? "unauthorized"
1719
+ : "unauthorized_oauth"
1720
+ : undefined;
1721
+ }, form.setError)
1722
+ .map((e) => (e.result.kind !== "data" ? e.result : undefined), handleFormFailure({ form, unexpectedError: binding.unexpectedError }));
1723
+ }
1724
+ // OTP init form
1725
+ {
1726
+ const { data, error } = (0, requestResponse_js_1.requestResponseSplit)(signInViaEmailInitFx.doneData);
1727
+ // success
1728
+ (0, effector_1.forward)({
1729
+ from: data.map(() => "email-otp-complete"),
1730
+ to: setSignInMode,
1731
+ });
1732
+ // failure
1733
+ (0, split_js_1.splitMap)(error)
1734
+ .map((e) => { var _a; return e.kind === "error" && ((_a = e.error.apiError) === null || _a === void 0 ? void 0 : _a.code) === codes_js_1.ErrorCode.TryAgainLater ? "try_again_later" : undefined; }, formOTPInit.setError)
1735
+ .fallback(handleFormFailure({ form: formOTPInit, unexpectedError: binding.unexpectedError }));
1736
+ }
1737
+ // OTP complete form
1738
+ {
1739
+ const { data, error } = (0, requestResponse_js_1.requestResponseSplit)(signInViaEmailCompleteFx.doneData);
1740
+ // success
1741
+ (0, effector_1.forward)({
1742
+ from: data.filterMap((v) => v.token || undefined),
1743
+ to: binding.setJWT,
1744
+ });
1745
+ // failure
1746
+ (0, split_js_1.splitMap)(error)
1747
+ .map((e) => { var _a; return (e.kind === "error" && ((_a = e.error.apiError) === null || _a === void 0 ? void 0 : _a.code) === codes_js_1.ErrorCode.NotFound ? "unauthorized" : undefined); }, formOTPComplete.setError)
1748
+ .fallback(handleFormFailure({ form: formOTPComplete, unexpectedError: binding.unexpectedError }));
1749
+ }
1750
+ // oauth flow
1751
+ const oauth2Click = (0, effector_1.createEvent)();
1752
+ (0, effector_1.guard)({
1753
+ source: oauth2Click.map((kind) => ({ kind, route: "signin" })),
1754
+ filter: binding.everythingIdle,
1755
+ target: binding.oauth2.requestFx,
1756
+ });
1757
+ (0, effector_1.guard)({
1758
+ source: (0, effector_1.sample)(binding.internalConfig, binding.oauth2.requestFx.doneData.filterMap((r) => r.route === "signin" && r.response.kind === "success"
1759
+ ? { oauth_provider: r.kind, oauth_code: r.response.code, timezone_hint: (0, getTimezone_js_1.getTimezone)() }
1760
+ : r.route === "signin" && r.response.kind === "success_oauth1"
1761
+ ? {
1762
+ oauth_provider: r.kind,
1763
+ oauth_token: r.response.token,
1764
+ oauth_verifier: r.response.verifier,
1765
+ timezone_hint: (0, getTimezone_js_1.getTimezone)(),
1766
+ }
1767
+ : undefined), (config, data) => ({ config, data })),
1768
+ filter: binding.everythingIdle,
1769
+ target: signinFx,
1770
+ });
1771
+ return {
1772
+ init,
1773
+ form,
1774
+ formOTPInit,
1775
+ formOTPComplete,
1776
+ signInMode,
1777
+ setSignInMode,
1778
+ oauth2Click,
1779
+ somethingIsPending: (0, combineSome_js_1.combineSome)(init.pending, signinFx.pending),
1780
+ };
1781
+ }
1782
+ function createOAuth2RequestGraph(config) {
1783
+ var _a;
1784
+ const cancelFuncs = [];
1785
+ const cancel = (0, effector_1.createEvent)();
1786
+ cancel.watch(() => {
1787
+ for (const c of cancelFuncs) {
1788
+ c();
1789
+ }
1790
+ });
1791
+ const requestFx = (0, effector_1.createEffect)((req) => tslib_1.__awaiter(this, void 0, void 0, function* () {
1792
+ const randomToken = (0, generateRandomToken_js_1.generateRandomToken)();
1793
+ if (!config.oauth2)
1794
+ return { kind: req.kind, route: req.route, response: { kind: "failure" } };
1795
+ const [requestPromise, cancelFunc] = config.oauth2.request({ kind: req.kind, randomToken });
1796
+ cancelFuncs.push(cancelFunc);
1797
+ const r = yield requestPromise;
1798
+ {
1799
+ // TODO: is it safe?
1800
+ const i = cancelFuncs.findIndex((f) => f === cancelFunc);
1801
+ if (i !== -1) {
1802
+ cancelFuncs.splice(i, 1);
1803
+ }
1804
+ }
1805
+ return { kind: req.kind, route: req.route, response: r };
1806
+ }));
1807
+ const providers = (0, effector_1.createStore)([...(((_a = config.oauth2) === null || _a === void 0 ? void 0 : _a.providers) || [])]);
1808
+ return {
1809
+ providers,
1810
+ cancel,
1811
+ requestFx,
1812
+ };
1813
+ }
1814
+ //===================================================================================================================
1815
+ //===================================================================================================================
1816
+ //===================================================================================================================
1817
+ // not really a part of any page, but somewhat follows page graph conventions, except it doesn't have init.
1818
+ function createOAuth2UtilsGraph(binding) {
1819
+ const ROUTE = "connect";
1820
+ const connectOAuth2 = (0, effector_1.createEvent)();
1821
+ const disconnectOAuth2 = (0, effector_1.createEvent)();
1822
+ const connectFx = (0, effector_1.createEffect)((p) => tslib_1.__awaiter(this, void 0, void 0, function* () {
1823
+ const { shopID, opts } = p.config;
1824
+ return (0, request_js_1.request)(ConnectOAuth2Mutation_js_1.default)(Object.assign({ shopID }, p.data), opts);
1825
+ }));
1826
+ const disconnectFx = (0, effector_1.createEffect)((p) => tslib_1.__awaiter(this, void 0, void 0, function* () {
1827
+ const { shopID, opts } = p.config;
1828
+ return (0, request_js_1.request)(DisconnectOAuth2Mutation_js_1.default)({ shopID }, opts);
1829
+ }));
1830
+ // connect flow
1831
+ {
1832
+ (0, effector_1.guard)({
1833
+ source: connectOAuth2.map((kind) => ({ kind, route: ROUTE })),
1834
+ filter: binding.everythingIdle,
1835
+ target: binding.oauth2.requestFx,
1836
+ });
1837
+ (0, effector_1.guard)({
1838
+ source: (0, effector_1.sample)(binding.internalConfig, binding.oauth2.requestFx.doneData.filterMap((r) => r.route === ROUTE && r.response.kind === "success"
1839
+ ? { provider: r.kind, code: r.response.code }
1840
+ : r.route === ROUTE && r.response.kind === "success_oauth1"
1841
+ ? { provider: r.kind, token: r.response.token, verifier: r.response.verifier }
1842
+ : undefined), (config, data) => ({ config, data })),
1843
+ filter: binding.everythingIdle,
1844
+ target: connectFx,
1845
+ });
1846
+ const { data: connectData, error: connectError } = (0, requestResponse_js_1.requestResponseSplit)(connectFx.doneData);
1847
+ // success
1848
+ (0, effector_1.forward)({
1849
+ from: connectData,
1850
+ to: binding.fetchCustomerInfoNow,
1851
+ });
1852
+ (0, effector_1.forward)({
1853
+ from: connectData.map(() => "oauth2_connected"),
1854
+ to: binding.message,
1855
+ });
1856
+ // failure
1857
+ (0, effector_1.forward)({
1858
+ from: connectError,
1859
+ to: binding.unexpectedError,
1860
+ });
1861
+ }
1862
+ // disconnect flow
1863
+ {
1864
+ (0, effector_1.guard)({
1865
+ source: (0, effector_1.sample)(binding.internalConfig, disconnectOAuth2, (config, data) => ({ config, data })),
1866
+ filter: binding.everythingIdle,
1867
+ target: disconnectFx,
1868
+ });
1869
+ const { data: disconnectData, error: disconnectError } = (0, requestResponse_js_1.requestResponseSplit)(disconnectFx.doneData);
1870
+ // success
1871
+ (0, effector_1.forward)({
1872
+ from: disconnectData,
1873
+ to: binding.fetchCustomerInfoNow,
1874
+ });
1875
+ (0, effector_1.forward)({
1876
+ from: disconnectData.map(() => "oauth2_disconnected"),
1877
+ to: binding.message,
1878
+ });
1879
+ // failure
1880
+ (0, effector_1.forward)({
1881
+ from: disconnectError,
1882
+ to: binding.unexpectedError,
1883
+ });
1884
+ }
1885
+ return {
1886
+ connectOAuth2,
1887
+ disconnectOAuth2,
1888
+ somethingIsPending: (0, combineSome_js_1.combineSome)(connectFx.pending, disconnectFx.pending),
1889
+ };
1890
+ }
1891
+ function createCustomer(config, init) {
1892
+ var _a;
1893
+ const currency = config.currency || (0, effector_1.createStore)(config.shopCurrency);
1894
+ const oauth2 = createOAuth2RequestGraph(config);
1895
+ const setCustomerInfo = (0, effector_1.createEvent)();
1896
+ const customerInfo = (0, effector_1.createStore)(null).on(setCustomerInfo, (_, v) => v);
1897
+ const everythingIdle = (0, effector_1.createStore)(true);
1898
+ const internalConfig = (0, effector_1.combine)({
1899
+ jwt: config.jwt,
1900
+ locale: config.locale,
1901
+ currency,
1902
+ }, ({ jwt, locale, currency }) => ({
1903
+ shopID: config.shopID,
1904
+ oauth2: config.oauth2,
1905
+ stripePromise: config.stripePromise,
1906
+ currency,
1907
+ opts: Object.assign(Object.assign({}, config.opts), { authToken: jwt, locale }),
1908
+ }));
1909
+ const getCustomerInfoFx = (0, effector_1.createEffect)((cfg) => tslib_1.__awaiter(this, void 0, void 0, function* () {
1910
+ var _b;
1911
+ const { shopID, opts } = cfg;
1912
+ let customerID = "";
1913
+ try {
1914
+ customerID = ((_b = (0, jwt_decode_1.default)((0, nonNull_js_1.nonNull)(opts === null || opts === void 0 ? void 0 : opts.authToken, "auth token"))) === null || _b === void 0 ? void 0 : _b.customer_id) || "";
1915
+ }
1916
+ catch (_c) {
1917
+ // do nothing
1918
+ }
1919
+ return getCustomerInfo(shopID, customerID, opts);
1920
+ }));
1921
+ (0, effector_1.forward)({
1922
+ from: getCustomerInfoFx.doneData,
1923
+ to: customerInfo,
1924
+ });
1925
+ (0, effector_1.forward)({
1926
+ from: internalConfig,
1927
+ to: getCustomerInfoFx,
1928
+ });
1929
+ const fetchCustomerInfoNow = (0, effector_1.createEvent)();
1930
+ (0, effector_1.forward)({
1931
+ from: (0, effector_1.sample)(internalConfig, fetchCustomerInfoNow),
1932
+ to: getCustomerInfoFx,
1933
+ });
1934
+ const unexpectedError = (0, effector_1.createEvent)();
1935
+ const setJWT = (0, effector_1.createEvent)();
1936
+ const setFavorites = (0, effector_1.createEvent)();
1937
+ const addFavoriteToInfo = (0, effector_1.createEvent)();
1938
+ const modifyFavoriteInInfo = (0, effector_1.createEvent)();
1939
+ const removeFavoriteFromInfo = (0, effector_1.createEvent)();
1940
+ const reloadPage = (0, effector_1.createEvent)();
1941
+ const reloadPageIfActive = (0, effector_1.createEvent)();
1942
+ const internalGoTo = (0, effector_1.createEvent)();
1943
+ const externalGoTo = (0, effector_1.createEvent)();
1944
+ const message = (0, effector_1.createEvent)();
1945
+ const binding = {
1946
+ everythingIdle,
1947
+ internalConfig,
1948
+ unexpectedError,
1949
+ setJWT,
1950
+ setFavorites,
1951
+ addFavoriteToInfo,
1952
+ modifyFavoriteInInfo,
1953
+ removeFavoriteFromInfo,
1954
+ reloadPage,
1955
+ reloadPageIfActive,
1956
+ goTo: internalGoTo,
1957
+ message,
1958
+ fetchCustomerInfoNow,
1959
+ oauth2,
1960
+ };
1961
+ config.jwt.on(setJWT, (_, v) => v);
1962
+ customerInfo.on(setFavorites, (pv, favorites) => {
1963
+ if (!pv)
1964
+ return null;
1965
+ return Object.assign(Object.assign({}, pv), { favorites });
1966
+ });
1967
+ customerInfo.on(addFavoriteToInfo, (pv, v) => {
1968
+ if (!pv)
1969
+ return null;
1970
+ if (pv.favorites.find((f) => f.id === v.id))
1971
+ return pv;
1972
+ return Object.assign(Object.assign({}, pv), { favorites: [...pv.favorites, v] });
1973
+ });
1974
+ customerInfo.on(modifyFavoriteInInfo, (pv, v) => {
1975
+ if (!pv)
1976
+ return null;
1977
+ const newFavs = [...pv.favorites];
1978
+ const idx = newFavs.findIndex((f) => f.id === v.id);
1979
+ if (idx !== -1) {
1980
+ newFavs[idx] = Object.assign(Object.assign({}, newFavs[idx]), v);
1981
+ }
1982
+ return Object.assign(Object.assign({}, pv), { favorites: newFavs });
1983
+ });
1984
+ customerInfo.on(removeFavoriteFromInfo, (pv, v) => {
1985
+ if (!pv)
1986
+ return null;
1987
+ return Object.assign(Object.assign({}, pv), { favorites: pv.favorites.filter((f) => f.id !== v) });
1988
+ });
1989
+ // on locale changes, reload the page
1990
+ (0, effector_1.forward)({
1991
+ from: config.locale.updates,
1992
+ to: reloadPage,
1993
+ });
1994
+ const pages = {
1995
+ signin: createSigninPageGraph(binding),
1996
+ signup: createSignupPageGraph(binding),
1997
+ resetPassword: createResetPasswordPageGraph(binding),
1998
+ addresses: createAddressesPageGraph(binding),
1999
+ favorites: createFavoritesPageGraph(binding),
2000
+ orders: createOrdersPageGraph(binding),
2001
+ subscriptions: createSubscriptionsPageGraph(binding),
2002
+ returns: createReturnsPageGraph(binding),
2003
+ order: createOrderPageGraph(binding),
2004
+ subscription: createSubscriptionPageGraph(binding),
2005
+ return: createReturnPageGraph(binding),
2006
+ createReturn: createCreateReturnPageGraph(binding),
2007
+ storeCredit: createStoreCreditPageGraph(binding),
2008
+ profile: createProfilePageGraph(binding),
2009
+ paymentMethods: createPaymentMethodsPageGraph(binding),
2010
+ };
2011
+ const oauth2Utils = createOAuth2UtilsGraph(binding);
2012
+ const currentPage = (0, effector_1.createStore)(null);
2013
+ const loadPage = (0, effector_1.createEvent)();
2014
+ const loadPageExt = (0, effector_1.sample)(currentPage, loadPage, (p, param) => ({
2015
+ previousPageKind: (p === null || p === void 0 ? void 0 : p.kind) || null,
2016
+ param,
2017
+ }));
2018
+ const loadSignin = loadPageExt.filterMap((v) => (v.param.kind === "signin" ? Object.assign(Object.assign({}, v), { param: v.param }) : undefined));
2019
+ const loadSignup = loadPageExt.filterMap((v) => (v.param.kind === "signup" ? Object.assign(Object.assign({}, v), { param: v.param }) : undefined));
2020
+ const loadResetPassword = loadPageExt.filterMap((v) => v.param.kind === "reset_password" ? Object.assign(Object.assign({}, v), { param: v.param }) : undefined);
2021
+ const loadAddresses = loadPageExt.filterMap((v) => v.param.kind === "addresses" ? Object.assign(Object.assign({}, v), { param: v.param }) : undefined);
2022
+ const loadFavorites = loadPageExt.filterMap((v) => v.param.kind === "favorites" ? Object.assign(Object.assign({}, v), { param: v.param }) : undefined);
2023
+ const loadOrders = loadPageExt.filterMap((v) => (v.param.kind === "orders" ? Object.assign(Object.assign({}, v), { param: v.param }) : undefined));
2024
+ const loadSubscriptions = loadPageExt.filterMap((v) => v.param.kind === "subscriptions" ? Object.assign(Object.assign({}, v), { param: v.param }) : undefined);
2025
+ const loadReturns = loadPageExt.filterMap((v) => (v.param.kind === "returns" ? Object.assign(Object.assign({}, v), { param: v.param }) : undefined));
2026
+ const loadOrder = loadPageExt.filterMap((v) => (v.param.kind === "order" ? Object.assign(Object.assign({}, v), { param: v.param }) : undefined));
2027
+ const loadSubscription = loadPageExt.filterMap((v) => v.param.kind === "subscription" ? Object.assign(Object.assign({}, v), { param: v.param }) : undefined);
2028
+ const loadReturn = loadPageExt.filterMap((v) => (v.param.kind === "return" ? Object.assign(Object.assign({}, v), { param: v.param }) : undefined));
2029
+ const loadCreateReturn = loadPageExt.filterMap((v) => v.param.kind === "create_return" ? Object.assign(Object.assign({}, v), { param: v.param }) : undefined);
2030
+ const loadStoreCredit = loadPageExt.filterMap((v) => v.param.kind === "store_credit" ? Object.assign(Object.assign({}, v), { param: v.param }) : undefined);
2031
+ const loadProfile = loadPageExt.filterMap((v) => (v.param.kind === "profile" ? Object.assign(Object.assign({}, v), { param: v.param }) : undefined));
2032
+ const loadPaymentMethods = loadPageExt.filterMap((v) => v.param.kind === "payment_methods" ? Object.assign(Object.assign({}, v), { param: v.param }) : undefined);
2033
+ (0, effector_1.forward)({ from: loadSignin, to: pages.signin.init.load });
2034
+ (0, effector_1.forward)({ from: loadSignup, to: pages.signup.init.load });
2035
+ (0, effector_1.forward)({ from: loadResetPassword, to: pages.resetPassword.init.load });
2036
+ (0, effector_1.forward)({ from: loadAddresses, to: pages.addresses.init.load });
2037
+ (0, effector_1.forward)({ from: loadFavorites, to: pages.favorites.init.load });
2038
+ (0, effector_1.forward)({ from: loadOrders, to: pages.orders.init.load });
2039
+ (0, effector_1.forward)({ from: loadSubscriptions, to: pages.subscriptions.init.load });
2040
+ (0, effector_1.forward)({ from: loadReturns, to: pages.returns.init.load });
2041
+ (0, effector_1.forward)({ from: loadOrder, to: pages.order.init.load });
2042
+ (0, effector_1.forward)({ from: loadSubscription, to: pages.subscription.init.load });
2043
+ (0, effector_1.forward)({ from: loadReturn, to: pages.return.init.load });
2044
+ (0, effector_1.forward)({ from: loadCreateReturn, to: pages.createReturn.init.load });
2045
+ (0, effector_1.forward)({ from: loadStoreCredit, to: pages.storeCredit.init.load });
2046
+ (0, effector_1.forward)({ from: loadProfile, to: pages.profile.init.load });
2047
+ (0, effector_1.forward)({ from: loadPaymentMethods, to: pages.paymentMethods.init.load });
2048
+ const lastAuthPage = (0, effector_1.createStore)(null);
2049
+ lastAuthPage.on(externalGoTo.filter({ fn: (pp) => pp === null || !disallowedLastAuthPages[pp.kind] }), (_, v) => v);
2050
+ const jwtAndCurrentPage = (0, effector_1.combine)(config.jwt, currentPage);
2051
+ const jwtAndCurrentPageAndLastAuthPage = (0, effector_1.combine)(config.jwt, currentPage, lastAuthPage);
2052
+ (0, effector_1.forward)({
2053
+ from: [
2054
+ pages.signin.init.loaded,
2055
+ pages.signup.init.loaded,
2056
+ pages.resetPassword.init.loaded,
2057
+ pages.addresses.init.loaded,
2058
+ pages.favorites.init.loaded,
2059
+ pages.orders.init.loaded,
2060
+ pages.subscriptions.init.loaded,
2061
+ pages.returns.init.loaded,
2062
+ pages.order.init.loaded,
2063
+ pages.subscription.init.loaded,
2064
+ pages.return.init.loaded,
2065
+ pages.createReturn.init.loaded,
2066
+ pages.storeCredit.init.loaded,
2067
+ pages.profile.init.loaded,
2068
+ pages.paymentMethods.init.loaded,
2069
+ ],
2070
+ to: currentPage,
2071
+ });
2072
+ const somethingPending = (0, combineSome_js_1.combineSome)(pages.signin.somethingIsPending, pages.signup.somethingIsPending, pages.resetPassword.somethingIsPending, pages.addresses.somethingIsPending, pages.favorites.somethingIsPending, pages.orders.somethingIsPending, pages.subscriptions.somethingIsPending, pages.returns.somethingIsPending, pages.order.somethingIsPending, pages.subscription.somethingIsPending, pages.return.somethingIsPending, pages.createReturn.somethingIsPending, pages.storeCredit.somethingIsPending, pages.profile.somethingIsPending, pages.paymentMethods.somethingIsPending, oauth2Utils.somethingIsPending);
2073
+ (0, effector_1.forward)({
2074
+ from: somethingPending.map((v) => !v),
2075
+ to: everythingIdle,
2076
+ });
2077
+ const logout = (0, effector_1.createEvent)();
2078
+ // goTo triggers loadPage, but with possible redirect based on jwt
2079
+ (0, effector_1.sample)({
2080
+ source: config.jwt,
2081
+ clock: internalGoTo,
2082
+ fn: (jwt, pageParam) => shouldRedirect(jwt, pageParam) || pageParam,
2083
+ target: loadPage,
2084
+ });
2085
+ // on page reload, just "goTo" "currentPage"
2086
+ (0, effector_1.forward)({
2087
+ from: (0, effector_1.sample)(currentPage, reloadPage).filterMap((v) => v || undefined),
2088
+ to: internalGoTo,
2089
+ });
2090
+ // optional page reload
2091
+ (0, effector_1.forward)({
2092
+ from: (0, effector_1.sample)(currentPage, reloadPageIfActive, (currentPage, target) => ({ currentPage, target })).filterMap(({ currentPage, target }) => ((currentPage === null || currentPage === void 0 ? void 0 : currentPage.kind) === target ? currentPage : undefined)),
2093
+ to: internalGoTo,
2094
+ });
2095
+ // Based on "jwt"/"currentPage" state, kick us out from pages we're not allowed to be in.
2096
+ // It's unlikely that we get here due to "currentPage" changes, because goToFx also handles this.
2097
+ // However, when "jwt" changes, we might end up being on a wrong page.
2098
+ (0, effector_1.forward)({
2099
+ from: jwtAndCurrentPageAndLastAuthPage.updates.filterMap(([jwt, currentPage, lastAuthPage]) => currentPage ? shouldRedirect(jwt, currentPage, lastAuthPage) : undefined),
2100
+ to: internalGoTo,
2101
+ });
2102
+ // expose only "logout" via API
2103
+ (0, effector_1.guard)({
2104
+ source: logout.map(() => ""),
2105
+ filter: everythingIdle,
2106
+ target: setJWT,
2107
+ });
2108
+ (0, effector_1.guard)({
2109
+ source: logout.map(() => ({ kind: "signin", action: "push" })),
2110
+ filter: everythingIdle,
2111
+ target: internalGoTo,
2112
+ });
2113
+ // start with signin page (will be redirected for logged in customer)
2114
+ if (init.kind === "goto") {
2115
+ internalGoTo(init.dest);
2116
+ }
2117
+ else if (init.kind === "default") {
2118
+ internalGoTo({ kind: "signin", action: "push" });
2119
+ }
2120
+ {
2121
+ const cfg = internalConfig.getState();
2122
+ let persistLoaded = false;
2123
+ if (config.persist) {
2124
+ const VERSION = 1;
2125
+ const { load, save, onChange, maxAgeMs } = config.persist;
2126
+ const realMaxAgeMs = Math.max(maxAgeMs !== null && maxAgeMs !== void 0 ? maxAgeMs : 0, 0) || 1800000;
2127
+ {
2128
+ const ci = (0, persist_js_1.deserialize)(load(), VERSION, realMaxAgeMs);
2129
+ if (ci !== undefined) {
2130
+ setCustomerInfo(ci);
2131
+ persistLoaded = true;
2132
+ }
2133
+ }
2134
+ customerInfo.updates.watch((data) => {
2135
+ save((0, persist_js_1.serialize)(data, VERSION));
2136
+ });
2137
+ onChange((data) => {
2138
+ const ci = (0, persist_js_1.deserialize)(data, VERSION, realMaxAgeMs);
2139
+ if (ci !== undefined) {
2140
+ setCustomerInfo(ci);
2141
+ }
2142
+ });
2143
+ }
2144
+ if (((_a = cfg.opts) === null || _a === void 0 ? void 0 : _a.authToken) && !persistLoaded) {
2145
+ fetchCustomerInfoNow();
2146
+ }
2147
+ }
2148
+ (0, effector_1.forward)({
2149
+ from: externalGoTo,
2150
+ to: internalGoTo,
2151
+ });
2152
+ // customerMenuVisible helper
2153
+ const customerLoggedIn = jwtAndCurrentPage.map(([jwt, currentPage]) => jwt !== "" && currentPage && currentPage.kind !== "signin" && currentPage.kind !== "signup");
2154
+ return {
2155
+ message,
2156
+ logout,
2157
+ currentPage,
2158
+ customerLoggedIn,
2159
+ customerInfo,
2160
+ goTo: externalGoTo,
2161
+ unexpectedError,
2162
+ reloadPage,
2163
+ pages,
2164
+ somethingPending,
2165
+ oauth2: {
2166
+ cancel: oauth2.cancel,
2167
+ pending: oauth2.requestFx.pending,
2168
+ providers: oauth2.providers,
2169
+ connect: oauth2Utils.connectOAuth2,
2170
+ disconnect: oauth2Utils.disconnectOAuth2,
2171
+ },
2172
+ };
2173
+ }
2174
+ exports.createCustomer = createCustomer;