@storepecker/storefront-core 2.3.0 → 2.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (31) hide show
  1. package/dist/api/index.cjs +78 -74
  2. package/dist/api/index.d.cts +6 -1
  3. package/dist/api/index.d.ts +6 -1
  4. package/dist/api/index.js +6 -6
  5. package/dist/checkout/index.cjs +23 -23
  6. package/dist/checkout/index.js +3 -3
  7. package/dist/{chunk-BHOXJGIE.js → chunk-27MTKBJL.js} +1 -1
  8. package/dist/chunk-3SYYP3XV.js +121 -0
  9. package/dist/{chunk-XLQAALMU.cjs → chunk-65Z7I5UP.cjs} +10 -10
  10. package/dist/{chunk-N3ZCCKXV.cjs → chunk-665CNTEX.cjs} +5 -5
  11. package/dist/{chunk-A67PCF55.cjs → chunk-6BVTMDR2.cjs} +17 -17
  12. package/dist/{chunk-7R2V4C7Q.js → chunk-AFM4IJVE.js} +1 -1
  13. package/dist/{chunk-FMHR5ABF.cjs → chunk-CV6DWPYF.cjs} +28 -28
  14. package/dist/chunk-ECHV2JSY.cjs +130 -0
  15. package/dist/{chunk-G3R7ZVAG.cjs → chunk-RDUT4W3B.cjs} +7 -7
  16. package/dist/{chunk-GHABOHLA.js → chunk-VWFZZFZL.js} +1 -1
  17. package/dist/{chunk-C7ZJZEEN.js → chunk-WYXT5AAG.js} +1 -1
  18. package/dist/{chunk-QBRME5AG.js → chunk-X35IATPX.js} +1 -1
  19. package/dist/{chunk-KKQKHG26.cjs → chunk-Y46EHRJQ.cjs} +3 -3
  20. package/dist/{chunk-ERLBPVFK.js → chunk-YEJZYH55.js} +1 -1
  21. package/dist/{chunk-SABICUTC.cjs → chunk-Z4DBCDAH.cjs} +6 -6
  22. package/dist/{chunk-YY77CUWX.js → chunk-ZGMLOLTC.js} +1 -1
  23. package/dist/components/index.cjs +4 -4
  24. package/dist/components/index.js +3 -3
  25. package/dist/hooks/index.cjs +31 -31
  26. package/dist/hooks/index.js +8 -8
  27. package/dist/store/index.cjs +8 -8
  28. package/dist/store/index.js +3 -3
  29. package/package.json +1 -1
  30. package/dist/chunk-JWKDXFS4.js +0 -61
  31. package/dist/chunk-ZO2HREQL.cjs +0 -69
@@ -0,0 +1,121 @@
1
+ import { auth_default } from './chunk-WEMNXIRS.js';
2
+ import { getPublicApiEndpoint, getStoreId } from './chunk-JQMLHRWL.js';
3
+ import axios from 'axios';
4
+ import { getCookie } from 'typescript-cookie';
5
+ import { jwtDecode } from 'jwt-decode';
6
+
7
+ var _instance = null;
8
+ var _isRefreshing = false;
9
+ var _refreshQueue = [];
10
+ var _onSessionExpired = null;
11
+ function setSessionExpiredCallback(cb) {
12
+ _onSessionExpired = cb;
13
+ }
14
+ function isTokenExpiringSoon(token) {
15
+ try {
16
+ const decoded = jwtDecode(token);
17
+ if (!decoded?.exp) return false;
18
+ const expiresAt = decoded.exp * 1e3;
19
+ return Date.now() > expiresAt - 6e4;
20
+ } catch {
21
+ return false;
22
+ }
23
+ }
24
+ async function refreshAccessToken(instance) {
25
+ const refresh = auth_default.getRefreshToken();
26
+ if (!refresh) return null;
27
+ try {
28
+ const response = await instance.post("/api/token/refresh/", { refresh });
29
+ const { access, refresh: newRefresh } = response.data;
30
+ auth_default.setAccessToken(access);
31
+ auth_default.setRefreshToken(newRefresh);
32
+ return access;
33
+ } catch {
34
+ return null;
35
+ }
36
+ }
37
+ function queuedRefresh(instance) {
38
+ if (_isRefreshing) {
39
+ return new Promise((resolve, reject) => {
40
+ _refreshQueue.push({ resolve, reject });
41
+ });
42
+ }
43
+ _isRefreshing = true;
44
+ return refreshAccessToken(instance).then((token) => {
45
+ _isRefreshing = false;
46
+ if (token) {
47
+ _refreshQueue.forEach((req) => req.resolve(token));
48
+ } else {
49
+ auth_default.removeTokens();
50
+ _onSessionExpired?.();
51
+ _refreshQueue.forEach(
52
+ (req) => req.reject(new Error("Session expired"))
53
+ );
54
+ }
55
+ _refreshQueue = [];
56
+ return token;
57
+ });
58
+ }
59
+ function createInstance() {
60
+ const baseURL = getPublicApiEndpoint();
61
+ if (!baseURL) {
62
+ throw new Error("Missing API endpoint. Call initConfig() first.");
63
+ }
64
+ axios.defaults.withCredentials = true;
65
+ const instance = axios.create({
66
+ baseURL,
67
+ withCredentials: true
68
+ });
69
+ const onRequestSuccess = async (config) => {
70
+ const csrftoken = getCookie("csrftoken");
71
+ let token = auth_default.getAccessToken();
72
+ if (token && isTokenExpiringSoon(token) && !config.url?.includes("/api/token/refresh/")) {
73
+ const newToken = await queuedRefresh(instance);
74
+ if (newToken) token = newToken;
75
+ }
76
+ config.headers["X-CSRFToken"] = csrftoken;
77
+ if (token) config.headers["Authorization"] = `Bearer ${token}`;
78
+ const storeId = getStoreId();
79
+ if (storeId) config.headers[""] = `Store ${storeId}`;
80
+ return config;
81
+ };
82
+ const onRequestFail = (error) => {
83
+ return Promise.reject(error);
84
+ };
85
+ instance.interceptors.request.use(onRequestSuccess, onRequestFail);
86
+ const onResponseSuccess = (response) => {
87
+ return response;
88
+ };
89
+ const onResponseFail = async (error) => {
90
+ const originalRequest = error.config;
91
+ if (error.response?.status === 401 && originalRequest && !originalRequest.url?.includes("/api/token/refresh/") && !originalRequest._retried) {
92
+ originalRequest._retried = true;
93
+ const newToken = await queuedRefresh(instance);
94
+ if (newToken) {
95
+ originalRequest.headers["Authorization"] = `Bearer ${newToken}`;
96
+ return instance(originalRequest);
97
+ }
98
+ return Promise.reject(error);
99
+ }
100
+ return Promise.reject(error);
101
+ };
102
+ instance.interceptors.response.use(onResponseSuccess, onResponseFail);
103
+ return instance;
104
+ }
105
+ function getHttpService() {
106
+ if (!_instance) {
107
+ _instance = createInstance();
108
+ }
109
+ return _instance;
110
+ }
111
+ function resetHttpService() {
112
+ _instance = null;
113
+ }
114
+ var httpService = new Proxy({}, {
115
+ get(_target, prop) {
116
+ return getHttpService()[prop];
117
+ }
118
+ });
119
+ var http_service_default = httpService;
120
+
121
+ export { getHttpService, http_service_default, resetHttpService, setSessionExpiredCallback };
@@ -1,6 +1,6 @@
1
1
  'use strict';
2
2
 
3
- var chunkFMHR5ABF_cjs = require('./chunk-FMHR5ABF.cjs');
3
+ var chunkCV6DWPYF_cjs = require('./chunk-CV6DWPYF.cjs');
4
4
  var chunkK44JZ5NL_cjs = require('./chunk-K44JZ5NL.cjs');
5
5
  var chunkN3CTXRFT_cjs = require('./chunk-N3CTXRFT.cjs');
6
6
  var axios = require('axios');
@@ -65,7 +65,7 @@ function openRazorpayCheckout(order, callbacks) {
65
65
  async function handleRazorpaySuccess(data, order, callbacks) {
66
66
  try {
67
67
  callbacks.onPaymentStart?.();
68
- await chunkFMHR5ABF_cjs.razorpayOrderSuccess(data);
68
+ await chunkCV6DWPYF_cjs.razorpayOrderSuccess(data);
69
69
  chunkK44JZ5NL_cjs.pixelEvents.purchase(order);
70
70
  chunkK44JZ5NL_cjs.pixelEvents.checkoutCompleted(order);
71
71
  callbacks.onCartReset();
@@ -78,7 +78,7 @@ async function handleRazorpaySuccess(data, order, callbacks) {
78
78
  }
79
79
  async function handleRazorpayFail(order, callbacks) {
80
80
  try {
81
- await chunkFMHR5ABF_cjs.razorpayOrderFail({
81
+ await chunkCV6DWPYF_cjs.razorpayOrderFail({
82
82
  order_id: order.id,
83
83
  razorpay_order_id: order.razorpay_order_id
84
84
  });
@@ -110,9 +110,9 @@ async function handleCODPayment(order, callbacks, options) {
110
110
  callbacks.onPaymentStart?.();
111
111
  chunkK44JZ5NL_cjs.pixelEvents.initiateCheckout(order, "cod");
112
112
  if (options?.isPublic) {
113
- await chunkFMHR5ABF_cjs.publicMakeCODOrder(order.order_number);
113
+ await chunkCV6DWPYF_cjs.publicMakeCODOrder(order.order_number);
114
114
  } else {
115
- await chunkFMHR5ABF_cjs.makeCODOrder(order.id);
115
+ await chunkCV6DWPYF_cjs.makeCODOrder(order.id);
116
116
  }
117
117
  chunkK44JZ5NL_cjs.pixelEvents.purchase(order);
118
118
  chunkK44JZ5NL_cjs.pixelEvents.checkoutCompleted(order);
@@ -140,7 +140,7 @@ function handleStripePayment(order, callbacks) {
140
140
  async function handleStripeSuccess(order, paymentIntentId, callbacks) {
141
141
  try {
142
142
  callbacks.onPaymentStart?.();
143
- await chunkFMHR5ABF_cjs.stripeOrderSuccess({
143
+ await chunkCV6DWPYF_cjs.stripeOrderSuccess({
144
144
  order_id: order.id,
145
145
  payment_intent_id: paymentIntentId
146
146
  });
@@ -174,12 +174,12 @@ function processPayment(order, paymentMethod, callbacks, options) {
174
174
  handlePhonepePayment(order, callbacks);
175
175
  }
176
176
  async function fetchAvailableCoupons() {
177
- const response = await chunkFMHR5ABF_cjs.getCoupons();
177
+ const response = await chunkCV6DWPYF_cjs.getCoupons();
178
178
  return response.data;
179
179
  }
180
180
  async function fetchAppliedCoupon() {
181
181
  try {
182
- const response = await chunkFMHR5ABF_cjs.getAppliedCoupon();
182
+ const response = await chunkCV6DWPYF_cjs.getAppliedCoupon();
183
183
  return response.data || null;
184
184
  } catch {
185
185
  return null;
@@ -187,7 +187,7 @@ async function fetchAppliedCoupon() {
187
187
  }
188
188
  async function applyCheckoutCoupon(code, callbacks) {
189
189
  try {
190
- const response = await chunkFMHR5ABF_cjs.applyCoupon(code);
190
+ const response = await chunkCV6DWPYF_cjs.applyCoupon(code);
191
191
  if (response.data?.coupon) {
192
192
  await callbacks.onCartRefresh();
193
193
  return response.data.coupon;
@@ -201,7 +201,7 @@ async function applyCheckoutCoupon(code, callbacks) {
201
201
  }
202
202
  }
203
203
  async function removeCheckoutCoupon(couponCode, callbacks) {
204
- await chunkFMHR5ABF_cjs.removeCoupon(couponCode);
204
+ await chunkCV6DWPYF_cjs.removeCoupon(couponCode);
205
205
  await callbacks.onCartRefresh();
206
206
  }
207
207
 
@@ -1,6 +1,6 @@
1
1
  'use strict';
2
2
 
3
- var chunkG3R7ZVAG_cjs = require('./chunk-G3R7ZVAG.cjs');
3
+ var chunkRDUT4W3B_cjs = require('./chunk-RDUT4W3B.cjs');
4
4
  var chunk4CVKE6CC_cjs = require('./chunk-4CVKE6CC.cjs');
5
5
  var chunk47XTPPII_cjs = require('./chunk-47XTPPII.cjs');
6
6
  var react = require('react');
@@ -35,12 +35,12 @@ function useAddressForm(options = {}) {
35
35
  const payload = chunk47XTPPII_cjs.buildSubmitPayload(values, selectedCountry, states);
36
36
  let response;
37
37
  if (isEditing) {
38
- response = await chunkG3R7ZVAG_cjs.updateAddress({
38
+ response = await chunkRDUT4W3B_cjs.updateAddress({
39
39
  ...payload,
40
40
  address_id: address.id
41
41
  });
42
42
  } else {
43
- response = await chunkG3R7ZVAG_cjs.addAddress(payload);
43
+ response = await chunkRDUT4W3B_cjs.addAddress(payload);
44
44
  }
45
45
  if (response) {
46
46
  formik$1.resetForm();
@@ -57,7 +57,7 @@ function useAddressForm(options = {}) {
57
57
  react.useEffect(() => {
58
58
  const fetchCountries = async () => {
59
59
  try {
60
- const response = await chunkG3R7ZVAG_cjs.getCountries();
60
+ const response = await chunkRDUT4W3B_cjs.getCountries();
61
61
  const sortedCountries = response?.data?.sort((a, b) => {
62
62
  if (a.id === defaultCountryId) return -1;
63
63
  if (b.id === defaultCountryId) return 1;
@@ -88,7 +88,7 @@ function useAddressForm(options = {}) {
88
88
  if (!selectedCountry) return;
89
89
  const fetchStates = async () => {
90
90
  try {
91
- const response = await chunkG3R7ZVAG_cjs.getSubdivisions(selectedCountry.id);
91
+ const response = await chunkRDUT4W3B_cjs.getSubdivisions(selectedCountry.id);
92
92
  setStates(response.data.results);
93
93
  } catch (error) {
94
94
  console.error(error);
@@ -1,13 +1,13 @@
1
1
  'use strict';
2
2
 
3
3
  var chunkSMHJRNCR_cjs = require('./chunk-SMHJRNCR.cjs');
4
- var chunkZO2HREQL_cjs = require('./chunk-ZO2HREQL.cjs');
4
+ var chunkECHV2JSY_cjs = require('./chunk-ECHV2JSY.cjs');
5
5
  var chunkBBRXE57K_cjs = require('./chunk-BBRXE57K.cjs');
6
6
 
7
7
  // src/api/cart.ts
8
8
  async function getCart(url, addressId) {
9
9
  const localCart = chunkSMHJRNCR_cjs.cart_default.get();
10
- return chunkBBRXE57K_cjs.auth_default.getUserDetails() ? (await chunkZO2HREQL_cjs.http_service_default.get(url, { params: { address_id: addressId } })).data : localCart || {
10
+ return chunkBBRXE57K_cjs.auth_default.getUserDetails() ? (await chunkECHV2JSY_cjs.http_service_default.get(url, { params: { address_id: addressId } })).data : localCart || {
11
11
  product_variants: [],
12
12
  total_amount: 0,
13
13
  total_quantity: 0,
@@ -23,20 +23,20 @@ async function getCart(url, addressId) {
23
23
  };
24
24
  }
25
25
  async function addToCart(product, customizationInputs) {
26
- return chunkZO2HREQL_cjs.http_service_default.post("/customer/cart/", {
26
+ return chunkECHV2JSY_cjs.http_service_default.post("/customer/cart/", {
27
27
  action: "add",
28
28
  cart_items: product,
29
29
  customization_inputs: customizationInputs
30
30
  });
31
31
  }
32
32
  async function removeFromCart(product) {
33
- return chunkZO2HREQL_cjs.http_service_default.post("/customer/cart/", {
33
+ return chunkECHV2JSY_cjs.http_service_default.post("/customer/cart/", {
34
34
  action: "remove",
35
35
  cart_items: product
36
36
  });
37
37
  }
38
38
  async function updateCart(product) {
39
- return chunkZO2HREQL_cjs.http_service_default.post("/customer/cart/", {
39
+ return chunkECHV2JSY_cjs.http_service_default.post("/customer/cart/", {
40
40
  action: "update",
41
41
  cart_items: product
42
42
  });
@@ -44,43 +44,43 @@ async function updateCart(product) {
44
44
 
45
45
  // src/api/product.ts
46
46
  async function getProductList(url, filter) {
47
- const response = await chunkZO2HREQL_cjs.http_service_default.get(url, {
47
+ const response = await chunkECHV2JSY_cjs.http_service_default.get(url, {
48
48
  params: filter
49
49
  });
50
50
  return response.data;
51
51
  }
52
52
  async function getProducts(filter) {
53
- return chunkZO2HREQL_cjs.http_service_default.get("/inventory/products/", {
53
+ return chunkECHV2JSY_cjs.http_service_default.get("/inventory/products/", {
54
54
  params: { ...filter }
55
55
  });
56
56
  }
57
57
  async function getProductDetail(url, slug) {
58
- const response = await chunkZO2HREQL_cjs.http_service_default.get(url, {
58
+ const response = await chunkECHV2JSY_cjs.http_service_default.get(url, {
59
59
  params: { variant_slug: slug }
60
60
  });
61
61
  return response.data;
62
62
  }
63
63
  async function getProductCategories(url) {
64
- return await chunkZO2HREQL_cjs.http_service_default.get(url);
64
+ return await chunkECHV2JSY_cjs.http_service_default.get(url);
65
65
  }
66
66
  async function getDigitalProductDownloadLink(variantId) {
67
- return chunkZO2HREQL_cjs.http_service_default.get("/inventory/digital_product/download/", {
67
+ return chunkECHV2JSY_cjs.http_service_default.get("/inventory/digital_product/download/", {
68
68
  params: { variant_id: variantId }
69
69
  });
70
70
  }
71
71
  async function updateDigitalProductDownloadLinkCount(variantId, downloadLink) {
72
- return chunkZO2HREQL_cjs.http_service_default.post("/inventory/digital_product/download/", {
72
+ return chunkECHV2JSY_cjs.http_service_default.post("/inventory/digital_product/download/", {
73
73
  variant_id: variantId,
74
74
  download_link: downloadLink
75
75
  });
76
76
  }
77
77
  async function getCategories(responseType = "flat") {
78
- return await chunkZO2HREQL_cjs.http_service_default.get("/inventory/categories/", {
78
+ return await chunkECHV2JSY_cjs.http_service_default.get("/inventory/categories/", {
79
79
  params: { response_structure: responseType }
80
80
  });
81
81
  }
82
82
  async function getProductDetailBySlug(url, slug) {
83
- const response = await chunkZO2HREQL_cjs.http_service_default.get(url, {
83
+ const response = await chunkECHV2JSY_cjs.http_service_default.get(url, {
84
84
  params: { variant_slug: slug }
85
85
  });
86
86
  const product = response.data;
@@ -96,18 +96,18 @@ async function getProductDetailBySlug(url, slug) {
96
96
  return product;
97
97
  }
98
98
  async function notifyProductStock(userDetails) {
99
- return chunkZO2HREQL_cjs.http_service_default.post("/utils/customer/notify-me/", userDetails);
99
+ return chunkECHV2JSY_cjs.http_service_default.post("/utils/customer/notify-me/", userDetails);
100
100
  }
101
101
 
102
102
  // src/api/wishlist.ts
103
103
  async function getWishlist(url) {
104
- return await chunkZO2HREQL_cjs.http_service_default.get(url);
104
+ return await chunkECHV2JSY_cjs.http_service_default.get(url);
105
105
  }
106
106
  async function addWishlist(productDetails) {
107
- return chunkZO2HREQL_cjs.http_service_default.post("/customer/wishlist/", productDetails);
107
+ return chunkECHV2JSY_cjs.http_service_default.post("/customer/wishlist/", productDetails);
108
108
  }
109
109
  async function removeFromWishlist(product_variants) {
110
- return chunkZO2HREQL_cjs.http_service_default.post("/customer/wishlist/", {
110
+ return chunkECHV2JSY_cjs.http_service_default.post("/customer/wishlist/", {
111
111
  action: "remove",
112
112
  product_variants
113
113
  });
@@ -1,4 +1,4 @@
1
- import { updateAddress, addAddress, getCountries, getSubdivisions } from './chunk-YY77CUWX.js';
1
+ import { updateAddress, addAddress, getCountries, getSubdivisions } from './chunk-ZGMLOLTC.js';
2
2
  import { getCache, getAddressMeta } from './chunk-YUPBTD4M.js';
3
3
  import { addressFormInitialValues, IP_API_CACHE_KEY, addressValidationSchema, buildSubmitPayload } from './chunk-B7FOXIZN.js';
4
4
  import { useState, useEffect, useMemo, useCallback } from 'react';
@@ -1,43 +1,43 @@
1
1
  'use strict';
2
2
 
3
- var chunkZO2HREQL_cjs = require('./chunk-ZO2HREQL.cjs');
3
+ var chunkECHV2JSY_cjs = require('./chunk-ECHV2JSY.cjs');
4
4
 
5
5
  // src/api/coupon.ts
6
6
  async function getCoupons() {
7
- return chunkZO2HREQL_cjs.http_service_default.get("/coupon/available/");
7
+ return chunkECHV2JSY_cjs.http_service_default.get("/coupon/available/");
8
8
  }
9
9
  async function applyCoupon(couponCode) {
10
- return chunkZO2HREQL_cjs.http_service_default.post("/coupon/use/", { coupon_code: couponCode });
10
+ return chunkECHV2JSY_cjs.http_service_default.post("/coupon/use/", { coupon_code: couponCode });
11
11
  }
12
12
  async function getAppliedCoupon() {
13
- return chunkZO2HREQL_cjs.http_service_default.get("/coupon/use/");
13
+ return chunkECHV2JSY_cjs.http_service_default.get("/coupon/use/");
14
14
  }
15
15
  async function removeCoupon(couponCode) {
16
- return chunkZO2HREQL_cjs.http_service_default.delete("/coupon/use/");
16
+ return chunkECHV2JSY_cjs.http_service_default.delete("/coupon/use/");
17
17
  }
18
18
 
19
19
  // src/api/orders.ts
20
20
  async function getOrders(url) {
21
- const response = await chunkZO2HREQL_cjs.http_service_default.get(url);
21
+ const response = await chunkECHV2JSY_cjs.http_service_default.get(url);
22
22
  return response.data;
23
23
  }
24
24
  async function getOrderDetails(orderId) {
25
- return chunkZO2HREQL_cjs.http_service_default.get("/customer/order/", {
25
+ return chunkECHV2JSY_cjs.http_service_default.get("/customer/order/", {
26
26
  params: { order_id: orderId }
27
27
  });
28
28
  }
29
29
  async function getOrderDetailsByNumber(orderNumber) {
30
- return chunkZO2HREQL_cjs.http_service_default.get("/customer/order/", {
30
+ return chunkECHV2JSY_cjs.http_service_default.get("/customer/order/", {
31
31
  params: { order_number: orderNumber }
32
32
  });
33
33
  }
34
34
  async function getPublicOrderDetailsByNumber(orderNumber) {
35
- return chunkZO2HREQL_cjs.http_service_default.get("/customer/public_order/", {
35
+ return chunkECHV2JSY_cjs.http_service_default.get("/customer/public_order/", {
36
36
  params: { order_number: orderNumber }
37
37
  });
38
38
  }
39
39
  async function placeOrder(address_id, redirect, isCod, stripeRedirect, tabbyRedirect) {
40
- return chunkZO2HREQL_cjs.http_service_default.post("/customer/order/", {
40
+ return chunkECHV2JSY_cjs.http_service_default.post("/customer/order/", {
41
41
  address_id,
42
42
  phonepe_redirect_url: redirect,
43
43
  is_cod: isCod,
@@ -46,7 +46,7 @@ async function placeOrder(address_id, redirect, isCod, stripeRedirect, tabbyRedi
46
46
  });
47
47
  }
48
48
  async function publicPlaceOrder(address, redirect, orderDetails, stripeRedirect, tabbyRedirect) {
49
- return chunkZO2HREQL_cjs.http_service_default.post("/customer/public_order/", {
49
+ return chunkECHV2JSY_cjs.http_service_default.post("/customer/public_order/", {
50
50
  address,
51
51
  phonepe_redirect_url: redirect,
52
52
  stripe_redirect_url: stripeRedirect,
@@ -55,30 +55,30 @@ async function publicPlaceOrder(address, redirect, orderDetails, stripeRedirect,
55
55
  });
56
56
  }
57
57
  async function updateOrder(orderDetails) {
58
- return chunkZO2HREQL_cjs.http_service_default.patch("/customer/order/", orderDetails);
58
+ return chunkECHV2JSY_cjs.http_service_default.patch("/customer/order/", orderDetails);
59
59
  }
60
60
  async function razorpayPublicOrderSuccess(orderDetails) {
61
- return chunkZO2HREQL_cjs.http_service_default.post("/payment/public-razorpay-order-success/", orderDetails);
61
+ return chunkECHV2JSY_cjs.http_service_default.post("/payment/public-razorpay-order-success/", orderDetails);
62
62
  }
63
63
  async function razorpayOrderSuccess(orderDetails) {
64
- return chunkZO2HREQL_cjs.http_service_default.post("/payment/razorpay-order-success/", orderDetails);
64
+ return chunkECHV2JSY_cjs.http_service_default.post("/payment/razorpay-order-success/", orderDetails);
65
65
  }
66
66
  async function razorpayOrderFail(orderDetails) {
67
- return chunkZO2HREQL_cjs.http_service_default.post("/payment/razorpay-order-fail/", orderDetails);
67
+ return chunkECHV2JSY_cjs.http_service_default.post("/payment/razorpay-order-fail/", orderDetails);
68
68
  }
69
69
  async function phonepePublicOrderSuccess(orderDetails) {
70
- return chunkZO2HREQL_cjs.http_service_default.post("/payment/public-phonepe-order-success/", orderDetails);
70
+ return chunkECHV2JSY_cjs.http_service_default.post("/payment/public-phonepe-order-success/", orderDetails);
71
71
  }
72
72
  async function phonepeOrderSuccess(orderDetails) {
73
- return chunkZO2HREQL_cjs.http_service_default.post("/payment/phonepe-order-success/", orderDetails);
73
+ return chunkECHV2JSY_cjs.http_service_default.post("/payment/phonepe-order-success/", orderDetails);
74
74
  }
75
75
  async function checkPhonepePaymentStatus(transactionId) {
76
- return chunkZO2HREQL_cjs.http_service_default.get("/payment/phonepe-order-success/", {
76
+ return chunkECHV2JSY_cjs.http_service_default.get("/payment/phonepe-order-success/", {
77
77
  params: { phonepe_transaction_id: transactionId }
78
78
  });
79
79
  }
80
80
  async function getStripePaymentStatus(stripeCheckoutSessionId, order_number, payment_link_id) {
81
- return chunkZO2HREQL_cjs.http_service_default.get("/payment/stripe-payment-status/", {
81
+ return chunkECHV2JSY_cjs.http_service_default.get("/payment/stripe-payment-status/", {
82
82
  params: {
83
83
  checkout_session_id: stripeCheckoutSessionId,
84
84
  order_number,
@@ -87,7 +87,7 @@ async function getStripePaymentStatus(stripeCheckoutSessionId, order_number, pay
87
87
  });
88
88
  }
89
89
  async function getStripePaymentStatusPublic(stripeCheckoutSessionId, order_number, payment_link_id) {
90
- return chunkZO2HREQL_cjs.http_service_default.get("/payment/public-stripe-payment-status/", {
90
+ return chunkECHV2JSY_cjs.http_service_default.get("/payment/public-stripe-payment-status/", {
91
91
  params: {
92
92
  checkout_session_id: stripeCheckoutSessionId,
93
93
  order_number,
@@ -96,28 +96,28 @@ async function getStripePaymentStatusPublic(stripeCheckoutSessionId, order_numbe
96
96
  });
97
97
  }
98
98
  async function stripePublicOrderSuccess(orderDetails) {
99
- return chunkZO2HREQL_cjs.http_service_default.post("/payment/public-stripe-order-success/", orderDetails);
99
+ return chunkECHV2JSY_cjs.http_service_default.post("/payment/public-stripe-order-success/", orderDetails);
100
100
  }
101
101
  async function stripeOrderSuccess(orderDetails) {
102
- return chunkZO2HREQL_cjs.http_service_default.post("/payment/stripe-order-success/", orderDetails);
102
+ return chunkECHV2JSY_cjs.http_service_default.post("/payment/stripe-order-success/", orderDetails);
103
103
  }
104
104
  async function stripeOrderFail(orderDetails) {
105
- return chunkZO2HREQL_cjs.http_service_default.post("/payment/stripe-order-fail/", orderDetails);
105
+ return chunkECHV2JSY_cjs.http_service_default.post("/payment/stripe-order-fail/", orderDetails);
106
106
  }
107
107
  async function makeCODOrder(orderId) {
108
- return chunkZO2HREQL_cjs.http_service_default.post("/customer/order_cod/", { order_id: orderId });
108
+ return chunkECHV2JSY_cjs.http_service_default.post("/customer/order_cod/", { order_id: orderId });
109
109
  }
110
110
  async function publicMakeCODOrder(orderNumber) {
111
- return chunkZO2HREQL_cjs.http_service_default.post("/customer/public_order_cod/", { order_number: orderNumber });
111
+ return chunkECHV2JSY_cjs.http_service_default.post("/customer/public_order_cod/", { order_number: orderNumber });
112
112
  }
113
113
  async function updateOrderCustomization(customizationInput) {
114
- return chunkZO2HREQL_cjs.http_service_default.post("/customer/product_personalize/", customizationInput);
114
+ return chunkECHV2JSY_cjs.http_service_default.post("/customer/product_personalize/", customizationInput);
115
115
  }
116
116
  async function uploadCustomizationImage(uploadForm) {
117
- return chunkZO2HREQL_cjs.http_service_default.post("/utils/upload_image", uploadForm);
117
+ return chunkECHV2JSY_cjs.http_service_default.post("/utils/upload_image", uploadForm);
118
118
  }
119
119
  async function verifyTabbyPayment(orderNumber) {
120
- return chunkZO2HREQL_cjs.http_service_default.get("/payment/tabby-payment-status/", {
120
+ return chunkECHV2JSY_cjs.http_service_default.get("/payment/tabby-payment-status/", {
121
121
  params: { order_number: orderNumber }
122
122
  });
123
123
  }
@@ -0,0 +1,130 @@
1
+ 'use strict';
2
+
3
+ var chunkBBRXE57K_cjs = require('./chunk-BBRXE57K.cjs');
4
+ var chunkN3CTXRFT_cjs = require('./chunk-N3CTXRFT.cjs');
5
+ var axios = require('axios');
6
+ var typescriptCookie = require('typescript-cookie');
7
+ var jwtDecode = require('jwt-decode');
8
+
9
+ function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
10
+
11
+ var axios__default = /*#__PURE__*/_interopDefault(axios);
12
+
13
+ var _instance = null;
14
+ var _isRefreshing = false;
15
+ var _refreshQueue = [];
16
+ var _onSessionExpired = null;
17
+ function setSessionExpiredCallback(cb) {
18
+ _onSessionExpired = cb;
19
+ }
20
+ function isTokenExpiringSoon(token) {
21
+ try {
22
+ const decoded = jwtDecode.jwtDecode(token);
23
+ if (!decoded?.exp) return false;
24
+ const expiresAt = decoded.exp * 1e3;
25
+ return Date.now() > expiresAt - 6e4;
26
+ } catch {
27
+ return false;
28
+ }
29
+ }
30
+ async function refreshAccessToken(instance) {
31
+ const refresh = chunkBBRXE57K_cjs.auth_default.getRefreshToken();
32
+ if (!refresh) return null;
33
+ try {
34
+ const response = await instance.post("/api/token/refresh/", { refresh });
35
+ const { access, refresh: newRefresh } = response.data;
36
+ chunkBBRXE57K_cjs.auth_default.setAccessToken(access);
37
+ chunkBBRXE57K_cjs.auth_default.setRefreshToken(newRefresh);
38
+ return access;
39
+ } catch {
40
+ return null;
41
+ }
42
+ }
43
+ function queuedRefresh(instance) {
44
+ if (_isRefreshing) {
45
+ return new Promise((resolve, reject) => {
46
+ _refreshQueue.push({ resolve, reject });
47
+ });
48
+ }
49
+ _isRefreshing = true;
50
+ return refreshAccessToken(instance).then((token) => {
51
+ _isRefreshing = false;
52
+ if (token) {
53
+ _refreshQueue.forEach((req) => req.resolve(token));
54
+ } else {
55
+ chunkBBRXE57K_cjs.auth_default.removeTokens();
56
+ _onSessionExpired?.();
57
+ _refreshQueue.forEach(
58
+ (req) => req.reject(new Error("Session expired"))
59
+ );
60
+ }
61
+ _refreshQueue = [];
62
+ return token;
63
+ });
64
+ }
65
+ function createInstance() {
66
+ const baseURL = chunkN3CTXRFT_cjs.getPublicApiEndpoint();
67
+ if (!baseURL) {
68
+ throw new Error("Missing API endpoint. Call initConfig() first.");
69
+ }
70
+ axios__default.default.defaults.withCredentials = true;
71
+ const instance = axios__default.default.create({
72
+ baseURL,
73
+ withCredentials: true
74
+ });
75
+ const onRequestSuccess = async (config) => {
76
+ const csrftoken = typescriptCookie.getCookie("csrftoken");
77
+ let token = chunkBBRXE57K_cjs.auth_default.getAccessToken();
78
+ if (token && isTokenExpiringSoon(token) && !config.url?.includes("/api/token/refresh/")) {
79
+ const newToken = await queuedRefresh(instance);
80
+ if (newToken) token = newToken;
81
+ }
82
+ config.headers["X-CSRFToken"] = csrftoken;
83
+ if (token) config.headers["Authorization"] = `Bearer ${token}`;
84
+ const storeId = chunkN3CTXRFT_cjs.getStoreId();
85
+ if (storeId) config.headers[""] = `Store ${storeId}`;
86
+ return config;
87
+ };
88
+ const onRequestFail = (error) => {
89
+ return Promise.reject(error);
90
+ };
91
+ instance.interceptors.request.use(onRequestSuccess, onRequestFail);
92
+ const onResponseSuccess = (response) => {
93
+ return response;
94
+ };
95
+ const onResponseFail = async (error) => {
96
+ const originalRequest = error.config;
97
+ if (error.response?.status === 401 && originalRequest && !originalRequest.url?.includes("/api/token/refresh/") && !originalRequest._retried) {
98
+ originalRequest._retried = true;
99
+ const newToken = await queuedRefresh(instance);
100
+ if (newToken) {
101
+ originalRequest.headers["Authorization"] = `Bearer ${newToken}`;
102
+ return instance(originalRequest);
103
+ }
104
+ return Promise.reject(error);
105
+ }
106
+ return Promise.reject(error);
107
+ };
108
+ instance.interceptors.response.use(onResponseSuccess, onResponseFail);
109
+ return instance;
110
+ }
111
+ function getHttpService() {
112
+ if (!_instance) {
113
+ _instance = createInstance();
114
+ }
115
+ return _instance;
116
+ }
117
+ function resetHttpService() {
118
+ _instance = null;
119
+ }
120
+ var httpService = new Proxy({}, {
121
+ get(_target, prop) {
122
+ return getHttpService()[prop];
123
+ }
124
+ });
125
+ var http_service_default = httpService;
126
+
127
+ exports.getHttpService = getHttpService;
128
+ exports.http_service_default = http_service_default;
129
+ exports.resetHttpService = resetHttpService;
130
+ exports.setSessionExpiredCallback = setSessionExpiredCallback;