@storepecker/storefront-core 1.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.
- package/dist/address-DQEZzyUG.d.cts +19 -0
- package/dist/address-DQEZzyUG.d.ts +19 -0
- package/dist/api/index.cjs +367 -0
- package/dist/api/index.d.cts +127 -0
- package/dist/api/index.d.ts +127 -0
- package/dist/api/index.js +131 -0
- package/dist/booking-ClX-dhX7.d.ts +131 -0
- package/dist/booking-Drl7-IL7.d.cts +131 -0
- package/dist/cart-DVrn8hD0.d.cts +367 -0
- package/dist/cart-DVrn8hD0.d.ts +367 -0
- package/dist/checkout/index.cjs +228 -0
- package/dist/checkout/index.d.cts +251 -0
- package/dist/checkout/index.d.ts +251 -0
- package/dist/checkout/index.js +122 -0
- package/dist/chunk-4CVKE6CC.cjs +312 -0
- package/dist/chunk-4MJMNIAB.js +123 -0
- package/dist/chunk-57ZBPAXU.js +114 -0
- package/dist/chunk-7MQOVWLW.js +40 -0
- package/dist/chunk-7UH6REGV.js +12 -0
- package/dist/chunk-A6IO3HIN.cjs +151 -0
- package/dist/chunk-CFF632IQ.cjs +100 -0
- package/dist/chunk-CSISWBZZ.js +121 -0
- package/dist/chunk-E7WPE3PV.js +98 -0
- package/dist/chunk-FLBJKM6G.js +83 -0
- package/dist/chunk-GB3HW6DM.js +61 -0
- package/dist/chunk-GH75WUO2.cjs +42 -0
- package/dist/chunk-GQTO5ZE2.cjs +96 -0
- package/dist/chunk-JHGXIIBZ.cjs +37 -0
- package/dist/chunk-JQMLHRWL.js +21 -0
- package/dist/chunk-K44JZ5NL.cjs +212 -0
- package/dist/chunk-K5B62JZO.cjs +154 -0
- package/dist/chunk-KWKHHRRJ.cjs +15 -0
- package/dist/chunk-LBGIUNM6.js +30 -0
- package/dist/chunk-LC5ZAUKL.cjs +220 -0
- package/dist/chunk-N3CTXRFT.cjs +30 -0
- package/dist/chunk-QCQCFYYR.js +206 -0
- package/dist/chunk-QM73PI5L.cjs +218 -0
- package/dist/chunk-RCXQJ6XC.cjs +131 -0
- package/dist/chunk-UM24VDYB.js +216 -0
- package/dist/chunk-UXLUE3HW.cjs +69 -0
- package/dist/chunk-WFDKKOO7.js +210 -0
- package/dist/chunk-YUPBTD4M.js +289 -0
- package/dist/components/index.cjs +576 -0
- package/dist/components/index.css +329 -0
- package/dist/components/index.d.cts +58 -0
- package/dist/components/index.d.ts +58 -0
- package/dist/components/index.js +569 -0
- package/dist/coupons-C7iJ-1cy.d.cts +37 -0
- package/dist/coupons-CnfTKL1i.d.ts +37 -0
- package/dist/hooks/index.cjs +381 -0
- package/dist/hooks/index.d.cts +123 -0
- package/dist/hooks/index.d.ts +123 -0
- package/dist/hooks/index.js +364 -0
- package/dist/index-DTyIuLuI.d.cts +18 -0
- package/dist/index-DTyIuLuI.d.ts +18 -0
- package/dist/index.cjs +14 -0
- package/dist/index.d.cts +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/models/index.cjs +2 -0
- package/dist/models/index.d.cts +53 -0
- package/dist/models/index.d.ts +53 -0
- package/dist/models/index.js +1 -0
- package/dist/orders-CkUzv5Xh.d.ts +159 -0
- package/dist/orders-D0oC9ugD.d.cts +159 -0
- package/dist/phonepe-D7vn-9SR.d.cts +27 -0
- package/dist/phonepe-D7vn-9SR.d.ts +27 -0
- package/dist/store/index.cjs +149 -0
- package/dist/store/index.d.cts +46 -0
- package/dist/store/index.d.ts +46 -0
- package/dist/store/index.js +141 -0
- package/dist/useAddressForm-C-Uzug4d.d.ts +42 -0
- package/dist/useAddressForm-DgkCP1nG.d.cts +42 -0
- package/dist/utils/index.cjs +535 -0
- package/dist/utils/index.d.cts +507 -0
- package/dist/utils/index.d.ts +507 -0
- package/dist/utils/index.js +342 -0
- package/dist/wishlist-BzhnCAQD.d.ts +41 -0
- package/dist/wishlist-CBCZD66Y.d.cts +41 -0
- package/package.json +134 -0
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
import { f as SLICE_STATUS } from './cart-DVrn8hD0.cjs';
|
|
2
|
+
|
|
3
|
+
declare namespace Category {
|
|
4
|
+
interface Root {
|
|
5
|
+
id: number;
|
|
6
|
+
name: string;
|
|
7
|
+
photo: string;
|
|
8
|
+
slug: string;
|
|
9
|
+
description: string;
|
|
10
|
+
children?: Root[];
|
|
11
|
+
}
|
|
12
|
+
interface CategoriesState {
|
|
13
|
+
data: Root[];
|
|
14
|
+
status: SLICE_STATUS;
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
declare namespace Order {
|
|
19
|
+
interface Root {
|
|
20
|
+
id: number;
|
|
21
|
+
store: number;
|
|
22
|
+
customer: number;
|
|
23
|
+
total_amount: number;
|
|
24
|
+
paid_amount: number;
|
|
25
|
+
purchased_at: string;
|
|
26
|
+
purchased_products: PurchasedProduct[];
|
|
27
|
+
order_status: OrderStatus;
|
|
28
|
+
order_number: number;
|
|
29
|
+
payment_method: any;
|
|
30
|
+
shipping_address: string;
|
|
31
|
+
shipping_city: string;
|
|
32
|
+
shipping_state: string;
|
|
33
|
+
shipping_country: string;
|
|
34
|
+
shipping_zip: string;
|
|
35
|
+
tracking_id: any;
|
|
36
|
+
tracking_url: any;
|
|
37
|
+
delivery_date?: string;
|
|
38
|
+
delivered_at: any;
|
|
39
|
+
cancelled_at: any;
|
|
40
|
+
returned_at: any;
|
|
41
|
+
customer_details: CustomerDetails;
|
|
42
|
+
customer_name: string;
|
|
43
|
+
customer_phone: string;
|
|
44
|
+
}
|
|
45
|
+
interface OrderResponse {
|
|
46
|
+
currentPage: number;
|
|
47
|
+
totalPages: number;
|
|
48
|
+
results: Root[];
|
|
49
|
+
}
|
|
50
|
+
interface VariantAttributes {
|
|
51
|
+
size: {
|
|
52
|
+
name: string;
|
|
53
|
+
value: string;
|
|
54
|
+
};
|
|
55
|
+
color?: {
|
|
56
|
+
name: string;
|
|
57
|
+
value: string;
|
|
58
|
+
};
|
|
59
|
+
Color?: {
|
|
60
|
+
name: string;
|
|
61
|
+
value: string;
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
interface CustomerDetails {
|
|
65
|
+
name: string;
|
|
66
|
+
phone: string;
|
|
67
|
+
}
|
|
68
|
+
type OrderStatus = "pending" | "confirmed" | "packed" | "shipped" | "delivered" | "cancelled" | "failed" | "paid";
|
|
69
|
+
interface OrderSummary {
|
|
70
|
+
id: number;
|
|
71
|
+
store: number;
|
|
72
|
+
customer: number;
|
|
73
|
+
total_amount: number;
|
|
74
|
+
paid_amount: number;
|
|
75
|
+
purchased_at: string;
|
|
76
|
+
purchased_products: PurchasedProduct[];
|
|
77
|
+
order_status: string;
|
|
78
|
+
order_number: number;
|
|
79
|
+
payment_method: any;
|
|
80
|
+
shipping_address: string;
|
|
81
|
+
shipping_city: string;
|
|
82
|
+
shipping_state: string;
|
|
83
|
+
shipping_country: string;
|
|
84
|
+
shipping_zip: string;
|
|
85
|
+
tracking_id: any;
|
|
86
|
+
tracking_url: any;
|
|
87
|
+
delivery_date: any;
|
|
88
|
+
delivered_at: any;
|
|
89
|
+
cancelled_at: any;
|
|
90
|
+
returned_at: any;
|
|
91
|
+
customer_email: string;
|
|
92
|
+
customer_name: string;
|
|
93
|
+
customer_phone: string;
|
|
94
|
+
shipped_at: any;
|
|
95
|
+
confirmed_at: any;
|
|
96
|
+
refunded_at: any;
|
|
97
|
+
store_address: string;
|
|
98
|
+
store_city: string;
|
|
99
|
+
store_state: string;
|
|
100
|
+
store_country: string;
|
|
101
|
+
store_zip: string;
|
|
102
|
+
cart_count: number;
|
|
103
|
+
razorpay_public_token: string;
|
|
104
|
+
razorpay_order_id: string;
|
|
105
|
+
razorpay_order_status: string;
|
|
106
|
+
razorpay_order_amount: number;
|
|
107
|
+
razorpay_order_currency: string;
|
|
108
|
+
razorpay_payment_id: string;
|
|
109
|
+
razorpay_signature: string;
|
|
110
|
+
store_color_scheme: {
|
|
111
|
+
primary: string;
|
|
112
|
+
secondary: string;
|
|
113
|
+
};
|
|
114
|
+
store_logo: string;
|
|
115
|
+
store_name: string;
|
|
116
|
+
shipping_amount: number;
|
|
117
|
+
phonepe_redirect_url: string;
|
|
118
|
+
stripe_client_secret: string;
|
|
119
|
+
stripe_payment_intent_id: string;
|
|
120
|
+
stripe_publishable_key: string;
|
|
121
|
+
total_coupon_discount: number;
|
|
122
|
+
stripe_payment_link_url: string;
|
|
123
|
+
tabby_redirect_url?: string;
|
|
124
|
+
}
|
|
125
|
+
interface PurchasedProduct {
|
|
126
|
+
product_id: number;
|
|
127
|
+
product_name: string;
|
|
128
|
+
product_variant_id: number;
|
|
129
|
+
product_variant_slug: string;
|
|
130
|
+
product_variant_name: string;
|
|
131
|
+
product_variant_sku: string;
|
|
132
|
+
quantity: number;
|
|
133
|
+
variant_price: number;
|
|
134
|
+
tax_percentage: number;
|
|
135
|
+
total_tax_price: number;
|
|
136
|
+
total_price: number;
|
|
137
|
+
variant_attributes: VariantAttributes;
|
|
138
|
+
product_variant_photo: any;
|
|
139
|
+
is_digital: boolean;
|
|
140
|
+
discount_amount: number;
|
|
141
|
+
}
|
|
142
|
+
interface StripePaymentStatus {
|
|
143
|
+
order_id: number;
|
|
144
|
+
order_status: string;
|
|
145
|
+
payment_link_id: string;
|
|
146
|
+
payment_link_url: string;
|
|
147
|
+
checkout_session_id: string;
|
|
148
|
+
status: string;
|
|
149
|
+
payment_status: string;
|
|
150
|
+
session_status: string;
|
|
151
|
+
amount_total: number;
|
|
152
|
+
currency: string;
|
|
153
|
+
customer_email: string | null;
|
|
154
|
+
payment_intent: string;
|
|
155
|
+
payment_link: string;
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
export { Category as C, Order as O };
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
interface PhonePe {
|
|
2
|
+
success: boolean;
|
|
3
|
+
code: "BAD_REQUEST" | "AUTHORIZATION_FAILED" | "INTERNAL_SERVER_ERROR" | "TRANSACTION_NOT_FOUND" | "PAYMENT_ERROR" | "PAYMENT_PENDING" | "PAYMENT_DECLINED" | "TIMED_OUT" | "PAYMENT_SUCCESS";
|
|
4
|
+
message: string;
|
|
5
|
+
data: Data;
|
|
6
|
+
}
|
|
7
|
+
interface Data {
|
|
8
|
+
merchantId: string;
|
|
9
|
+
merchantTransactionId: string;
|
|
10
|
+
transactionId: string;
|
|
11
|
+
amount: number;
|
|
12
|
+
state: string;
|
|
13
|
+
responseCode: string;
|
|
14
|
+
paymentInstrument: PaymentInstrument;
|
|
15
|
+
}
|
|
16
|
+
interface PaymentInstrument {
|
|
17
|
+
type: string;
|
|
18
|
+
cardType: string;
|
|
19
|
+
pgTransactionId: string;
|
|
20
|
+
bankTransactionId: any;
|
|
21
|
+
pgAuthorizationCode: any;
|
|
22
|
+
arn: string;
|
|
23
|
+
bankId: any;
|
|
24
|
+
brn: string;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export type { Data as D, PaymentInstrument as P, PhonePe as a };
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
interface PhonePe {
|
|
2
|
+
success: boolean;
|
|
3
|
+
code: "BAD_REQUEST" | "AUTHORIZATION_FAILED" | "INTERNAL_SERVER_ERROR" | "TRANSACTION_NOT_FOUND" | "PAYMENT_ERROR" | "PAYMENT_PENDING" | "PAYMENT_DECLINED" | "TIMED_OUT" | "PAYMENT_SUCCESS";
|
|
4
|
+
message: string;
|
|
5
|
+
data: Data;
|
|
6
|
+
}
|
|
7
|
+
interface Data {
|
|
8
|
+
merchantId: string;
|
|
9
|
+
merchantTransactionId: string;
|
|
10
|
+
transactionId: string;
|
|
11
|
+
amount: number;
|
|
12
|
+
state: string;
|
|
13
|
+
responseCode: string;
|
|
14
|
+
paymentInstrument: PaymentInstrument;
|
|
15
|
+
}
|
|
16
|
+
interface PaymentInstrument {
|
|
17
|
+
type: string;
|
|
18
|
+
cardType: string;
|
|
19
|
+
pgTransactionId: string;
|
|
20
|
+
bankTransactionId: any;
|
|
21
|
+
pgAuthorizationCode: any;
|
|
22
|
+
arn: string;
|
|
23
|
+
bankId: any;
|
|
24
|
+
brn: string;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export type { Data as D, PaymentInstrument as P, PhonePe as a };
|
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var chunkGH75WUO2_cjs = require('../chunk-GH75WUO2.cjs');
|
|
4
|
+
var chunkRCXQJ6XC_cjs = require('../chunk-RCXQJ6XC.cjs');
|
|
5
|
+
var chunkCFF632IQ_cjs = require('../chunk-CFF632IQ.cjs');
|
|
6
|
+
require('../chunk-UXLUE3HW.cjs');
|
|
7
|
+
var chunkGQTO5ZE2_cjs = require('../chunk-GQTO5ZE2.cjs');
|
|
8
|
+
require('../chunk-N3CTXRFT.cjs');
|
|
9
|
+
var zustand = require('zustand');
|
|
10
|
+
var typescriptCookie = require('typescript-cookie');
|
|
11
|
+
|
|
12
|
+
var getInitialState = () => ({
|
|
13
|
+
user: null,
|
|
14
|
+
status: "idle" /* IDLE */,
|
|
15
|
+
isAuthenticated: typeof window !== "undefined" ? !!typescriptCookie.getCookie(chunkGQTO5ZE2_cjs.USER_CRED_TOKEN) : false
|
|
16
|
+
});
|
|
17
|
+
var useAuthStore = zustand.create((set, get) => ({
|
|
18
|
+
...getInitialState(),
|
|
19
|
+
fetchUser: () => set({ status: "loading" /* LOADING */ }),
|
|
20
|
+
fetchUserSuccess: (user) => set({ user, status: "success" /* SUCCESS */, isAuthenticated: true }),
|
|
21
|
+
fetchUserFailure: (error) => set({ status: "failure" /* FAILURE */, isAuthenticated: false, error }),
|
|
22
|
+
setAuthenticated: () => set({ isAuthenticated: true }),
|
|
23
|
+
resetUser: () => set(getInitialState()),
|
|
24
|
+
logoutUser: () => {
|
|
25
|
+
try {
|
|
26
|
+
chunkGQTO5ZE2_cjs.auth_default.removeTokens();
|
|
27
|
+
set(getInitialState());
|
|
28
|
+
} catch {
|
|
29
|
+
set({ status: "failure" /* FAILURE */, isAuthenticated: false, error: "Something went wrong" });
|
|
30
|
+
}
|
|
31
|
+
},
|
|
32
|
+
loadCurrentUser: (user, referer, redirect = true, preventRefreshAfterLogin) => {
|
|
33
|
+
set({ status: "loading" /* LOADING */ });
|
|
34
|
+
setTimeout(async () => {
|
|
35
|
+
try {
|
|
36
|
+
set({ user, status: "success" /* SUCCESS */, isAuthenticated: true });
|
|
37
|
+
const localCartItems = chunkCFF632IQ_cjs.cart_default.get();
|
|
38
|
+
if (localCartItems) {
|
|
39
|
+
const response = await chunkRCXQJ6XC_cjs.addToCart(
|
|
40
|
+
Object.entries(localCartItems.products_quantity).map(
|
|
41
|
+
([key, value]) => ({
|
|
42
|
+
variant_id: parseInt(key),
|
|
43
|
+
quantity: value
|
|
44
|
+
})
|
|
45
|
+
)
|
|
46
|
+
);
|
|
47
|
+
if (response) {
|
|
48
|
+
chunkCFF632IQ_cjs.cart_default.clear();
|
|
49
|
+
chunkGH75WUO2_cjs.useCartStore.getState().fetchCart();
|
|
50
|
+
setTimeout(() => {
|
|
51
|
+
if (!preventRefreshAfterLogin) {
|
|
52
|
+
if (redirect) {
|
|
53
|
+
window.location.href = referer;
|
|
54
|
+
} else {
|
|
55
|
+
window.location.reload();
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
}, 500);
|
|
59
|
+
}
|
|
60
|
+
} else {
|
|
61
|
+
if (!preventRefreshAfterLogin) {
|
|
62
|
+
if (redirect) {
|
|
63
|
+
window.location.href = referer;
|
|
64
|
+
} else {
|
|
65
|
+
window.location.reload();
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
} catch {
|
|
70
|
+
localStorage.removeItem("userExists");
|
|
71
|
+
set({
|
|
72
|
+
status: "failure" /* FAILURE */,
|
|
73
|
+
isAuthenticated: false,
|
|
74
|
+
error: "Something went wrong while fetching user"
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
}, 1e3);
|
|
78
|
+
}
|
|
79
|
+
}));
|
|
80
|
+
var loginUser = async (user) => {
|
|
81
|
+
const { access, refresh, ...userData } = user;
|
|
82
|
+
localStorage.setItem(chunkGQTO5ZE2_cjs.USER_CREDENTIALS, JSON.stringify(userData));
|
|
83
|
+
chunkGQTO5ZE2_cjs.auth_default.setAccessToken(access);
|
|
84
|
+
chunkGQTO5ZE2_cjs.auth_default.setRefreshToken(refresh);
|
|
85
|
+
};
|
|
86
|
+
var initialState = {
|
|
87
|
+
wishlist_count: 0,
|
|
88
|
+
product_variants: []
|
|
89
|
+
};
|
|
90
|
+
var useWishlistStore = zustand.create((set) => ({
|
|
91
|
+
...initialState,
|
|
92
|
+
setWishlist: (wishlist) => set(wishlist),
|
|
93
|
+
resetWishlist: () => set(initialState),
|
|
94
|
+
syncWishlist: async () => {
|
|
95
|
+
try {
|
|
96
|
+
const response = await chunkRCXQJ6XC_cjs.getWishlist("/customer/wishlist/");
|
|
97
|
+
if (response) {
|
|
98
|
+
set({
|
|
99
|
+
wishlist_count: response.wishlist_count,
|
|
100
|
+
product_variants: response.product_variants
|
|
101
|
+
});
|
|
102
|
+
}
|
|
103
|
+
} catch {
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
}));
|
|
107
|
+
var initialState2 = {
|
|
108
|
+
data: [],
|
|
109
|
+
status: "loading" /* LOADING */,
|
|
110
|
+
hasMore: false,
|
|
111
|
+
filter: {
|
|
112
|
+
page: 1,
|
|
113
|
+
page_size: 10
|
|
114
|
+
}
|
|
115
|
+
};
|
|
116
|
+
var useProductStore = zustand.create((set, get) => ({
|
|
117
|
+
...initialState2,
|
|
118
|
+
fetchProducts: async (filter) => {
|
|
119
|
+
set((state) => ({
|
|
120
|
+
status: "loading" /* LOADING */,
|
|
121
|
+
data: filter.page === 1 ? [] : state.data
|
|
122
|
+
}));
|
|
123
|
+
try {
|
|
124
|
+
const response = await chunkRCXQJ6XC_cjs.getProducts({ ...filter });
|
|
125
|
+
if (response.data) {
|
|
126
|
+
const { results, ...meta } = response.data;
|
|
127
|
+
set((state) => ({
|
|
128
|
+
status: "idle" /* IDLE */,
|
|
129
|
+
filter,
|
|
130
|
+
meta,
|
|
131
|
+
hasMore: !!meta.next,
|
|
132
|
+
data: !filter.page || filter.page === 1 ? results : [...state.data, ...results]
|
|
133
|
+
}));
|
|
134
|
+
}
|
|
135
|
+
} catch {
|
|
136
|
+
set({ status: "idle" /* IDLE */ });
|
|
137
|
+
}
|
|
138
|
+
},
|
|
139
|
+
setGatePasses: (products) => set({ data: products })
|
|
140
|
+
}));
|
|
141
|
+
|
|
142
|
+
Object.defineProperty(exports, "useCartStore", {
|
|
143
|
+
enumerable: true,
|
|
144
|
+
get: function () { return chunkGH75WUO2_cjs.useCartStore; }
|
|
145
|
+
});
|
|
146
|
+
exports.loginUser = loginUser;
|
|
147
|
+
exports.useAuthStore = useAuthStore;
|
|
148
|
+
exports.useProductStore = useProductStore;
|
|
149
|
+
exports.useWishlistStore = useWishlistStore;
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import * as zustand from 'zustand';
|
|
2
|
+
import { b as CartState, C as Cart, d as Product } from '../cart-DVrn8hD0.cjs';
|
|
3
|
+
import { U as User, W as Wishlist } from '../wishlist-CBCZD66Y.cjs';
|
|
4
|
+
import 'react-toastify';
|
|
5
|
+
|
|
6
|
+
interface CartStore extends CartState {
|
|
7
|
+
setCart: (cart: Cart.Root) => void;
|
|
8
|
+
resetCart: () => void;
|
|
9
|
+
resetCartCount: () => void;
|
|
10
|
+
syncCart: () => Promise<void>;
|
|
11
|
+
fetchCart: (addressId?: number) => Promise<void>;
|
|
12
|
+
}
|
|
13
|
+
declare const useCartStore: zustand.UseBoundStore<zustand.StoreApi<CartStore>>;
|
|
14
|
+
|
|
15
|
+
interface AuthState {
|
|
16
|
+
user: User.LoginUserData | null;
|
|
17
|
+
status: string;
|
|
18
|
+
isAuthenticated: boolean;
|
|
19
|
+
error?: string;
|
|
20
|
+
}
|
|
21
|
+
interface AuthStore extends AuthState {
|
|
22
|
+
fetchUser: () => void;
|
|
23
|
+
fetchUserSuccess: (user: User.LoginUserData) => void;
|
|
24
|
+
fetchUserFailure: (error: string) => void;
|
|
25
|
+
setAuthenticated: () => void;
|
|
26
|
+
resetUser: () => void;
|
|
27
|
+
logoutUser: () => void;
|
|
28
|
+
loadCurrentUser: (user: User.LoginUserData, referer: string, redirect?: boolean, preventRefreshAfterLogin?: boolean) => void;
|
|
29
|
+
}
|
|
30
|
+
declare const useAuthStore: zustand.UseBoundStore<zustand.StoreApi<AuthStore>>;
|
|
31
|
+
declare const loginUser: (user: User.LoginUserData) => Promise<void>;
|
|
32
|
+
|
|
33
|
+
interface WishlistStore extends Wishlist.Root {
|
|
34
|
+
setWishlist: (wishlist: Wishlist.Root) => void;
|
|
35
|
+
resetWishlist: () => void;
|
|
36
|
+
syncWishlist: () => Promise<void>;
|
|
37
|
+
}
|
|
38
|
+
declare const useWishlistStore: zustand.UseBoundStore<zustand.StoreApi<WishlistStore>>;
|
|
39
|
+
|
|
40
|
+
interface ProductStore extends Product.ProductState {
|
|
41
|
+
fetchProducts: (filter: Product.ProductFilter) => Promise<void>;
|
|
42
|
+
setGatePasses: (products: Product.ProductList[]) => void;
|
|
43
|
+
}
|
|
44
|
+
declare const useProductStore: zustand.UseBoundStore<zustand.StoreApi<ProductStore>>;
|
|
45
|
+
|
|
46
|
+
export { loginUser, useAuthStore, useCartStore, useProductStore, useWishlistStore };
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import * as zustand from 'zustand';
|
|
2
|
+
import { b as CartState, C as Cart, d as Product } from '../cart-DVrn8hD0.js';
|
|
3
|
+
import { U as User, W as Wishlist } from '../wishlist-BzhnCAQD.js';
|
|
4
|
+
import 'react-toastify';
|
|
5
|
+
|
|
6
|
+
interface CartStore extends CartState {
|
|
7
|
+
setCart: (cart: Cart.Root) => void;
|
|
8
|
+
resetCart: () => void;
|
|
9
|
+
resetCartCount: () => void;
|
|
10
|
+
syncCart: () => Promise<void>;
|
|
11
|
+
fetchCart: (addressId?: number) => Promise<void>;
|
|
12
|
+
}
|
|
13
|
+
declare const useCartStore: zustand.UseBoundStore<zustand.StoreApi<CartStore>>;
|
|
14
|
+
|
|
15
|
+
interface AuthState {
|
|
16
|
+
user: User.LoginUserData | null;
|
|
17
|
+
status: string;
|
|
18
|
+
isAuthenticated: boolean;
|
|
19
|
+
error?: string;
|
|
20
|
+
}
|
|
21
|
+
interface AuthStore extends AuthState {
|
|
22
|
+
fetchUser: () => void;
|
|
23
|
+
fetchUserSuccess: (user: User.LoginUserData) => void;
|
|
24
|
+
fetchUserFailure: (error: string) => void;
|
|
25
|
+
setAuthenticated: () => void;
|
|
26
|
+
resetUser: () => void;
|
|
27
|
+
logoutUser: () => void;
|
|
28
|
+
loadCurrentUser: (user: User.LoginUserData, referer: string, redirect?: boolean, preventRefreshAfterLogin?: boolean) => void;
|
|
29
|
+
}
|
|
30
|
+
declare const useAuthStore: zustand.UseBoundStore<zustand.StoreApi<AuthStore>>;
|
|
31
|
+
declare const loginUser: (user: User.LoginUserData) => Promise<void>;
|
|
32
|
+
|
|
33
|
+
interface WishlistStore extends Wishlist.Root {
|
|
34
|
+
setWishlist: (wishlist: Wishlist.Root) => void;
|
|
35
|
+
resetWishlist: () => void;
|
|
36
|
+
syncWishlist: () => Promise<void>;
|
|
37
|
+
}
|
|
38
|
+
declare const useWishlistStore: zustand.UseBoundStore<zustand.StoreApi<WishlistStore>>;
|
|
39
|
+
|
|
40
|
+
interface ProductStore extends Product.ProductState {
|
|
41
|
+
fetchProducts: (filter: Product.ProductFilter) => Promise<void>;
|
|
42
|
+
setGatePasses: (products: Product.ProductList[]) => void;
|
|
43
|
+
}
|
|
44
|
+
declare const useProductStore: zustand.UseBoundStore<zustand.StoreApi<ProductStore>>;
|
|
45
|
+
|
|
46
|
+
export { loginUser, useAuthStore, useCartStore, useProductStore, useWishlistStore };
|
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
import { useCartStore } from '../chunk-7MQOVWLW.js';
|
|
2
|
+
export { useCartStore } from '../chunk-7MQOVWLW.js';
|
|
3
|
+
import { addToCart, getWishlist, getProducts } from '../chunk-57ZBPAXU.js';
|
|
4
|
+
import { cart_default } from '../chunk-E7WPE3PV.js';
|
|
5
|
+
import '../chunk-GB3HW6DM.js';
|
|
6
|
+
import { auth_default, USER_CRED_TOKEN, USER_CREDENTIALS } from '../chunk-FLBJKM6G.js';
|
|
7
|
+
import '../chunk-JQMLHRWL.js';
|
|
8
|
+
import { create } from 'zustand';
|
|
9
|
+
import { getCookie } from 'typescript-cookie';
|
|
10
|
+
|
|
11
|
+
var getInitialState = () => ({
|
|
12
|
+
user: null,
|
|
13
|
+
status: "idle" /* IDLE */,
|
|
14
|
+
isAuthenticated: typeof window !== "undefined" ? !!getCookie(USER_CRED_TOKEN) : false
|
|
15
|
+
});
|
|
16
|
+
var useAuthStore = create((set, get) => ({
|
|
17
|
+
...getInitialState(),
|
|
18
|
+
fetchUser: () => set({ status: "loading" /* LOADING */ }),
|
|
19
|
+
fetchUserSuccess: (user) => set({ user, status: "success" /* SUCCESS */, isAuthenticated: true }),
|
|
20
|
+
fetchUserFailure: (error) => set({ status: "failure" /* FAILURE */, isAuthenticated: false, error }),
|
|
21
|
+
setAuthenticated: () => set({ isAuthenticated: true }),
|
|
22
|
+
resetUser: () => set(getInitialState()),
|
|
23
|
+
logoutUser: () => {
|
|
24
|
+
try {
|
|
25
|
+
auth_default.removeTokens();
|
|
26
|
+
set(getInitialState());
|
|
27
|
+
} catch {
|
|
28
|
+
set({ status: "failure" /* FAILURE */, isAuthenticated: false, error: "Something went wrong" });
|
|
29
|
+
}
|
|
30
|
+
},
|
|
31
|
+
loadCurrentUser: (user, referer, redirect = true, preventRefreshAfterLogin) => {
|
|
32
|
+
set({ status: "loading" /* LOADING */ });
|
|
33
|
+
setTimeout(async () => {
|
|
34
|
+
try {
|
|
35
|
+
set({ user, status: "success" /* SUCCESS */, isAuthenticated: true });
|
|
36
|
+
const localCartItems = cart_default.get();
|
|
37
|
+
if (localCartItems) {
|
|
38
|
+
const response = await addToCart(
|
|
39
|
+
Object.entries(localCartItems.products_quantity).map(
|
|
40
|
+
([key, value]) => ({
|
|
41
|
+
variant_id: parseInt(key),
|
|
42
|
+
quantity: value
|
|
43
|
+
})
|
|
44
|
+
)
|
|
45
|
+
);
|
|
46
|
+
if (response) {
|
|
47
|
+
cart_default.clear();
|
|
48
|
+
useCartStore.getState().fetchCart();
|
|
49
|
+
setTimeout(() => {
|
|
50
|
+
if (!preventRefreshAfterLogin) {
|
|
51
|
+
if (redirect) {
|
|
52
|
+
window.location.href = referer;
|
|
53
|
+
} else {
|
|
54
|
+
window.location.reload();
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
}, 500);
|
|
58
|
+
}
|
|
59
|
+
} else {
|
|
60
|
+
if (!preventRefreshAfterLogin) {
|
|
61
|
+
if (redirect) {
|
|
62
|
+
window.location.href = referer;
|
|
63
|
+
} else {
|
|
64
|
+
window.location.reload();
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
} catch {
|
|
69
|
+
localStorage.removeItem("userExists");
|
|
70
|
+
set({
|
|
71
|
+
status: "failure" /* FAILURE */,
|
|
72
|
+
isAuthenticated: false,
|
|
73
|
+
error: "Something went wrong while fetching user"
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
}, 1e3);
|
|
77
|
+
}
|
|
78
|
+
}));
|
|
79
|
+
var loginUser = async (user) => {
|
|
80
|
+
const { access, refresh, ...userData } = user;
|
|
81
|
+
localStorage.setItem(USER_CREDENTIALS, JSON.stringify(userData));
|
|
82
|
+
auth_default.setAccessToken(access);
|
|
83
|
+
auth_default.setRefreshToken(refresh);
|
|
84
|
+
};
|
|
85
|
+
var initialState = {
|
|
86
|
+
wishlist_count: 0,
|
|
87
|
+
product_variants: []
|
|
88
|
+
};
|
|
89
|
+
var useWishlistStore = create((set) => ({
|
|
90
|
+
...initialState,
|
|
91
|
+
setWishlist: (wishlist) => set(wishlist),
|
|
92
|
+
resetWishlist: () => set(initialState),
|
|
93
|
+
syncWishlist: async () => {
|
|
94
|
+
try {
|
|
95
|
+
const response = await getWishlist("/customer/wishlist/");
|
|
96
|
+
if (response) {
|
|
97
|
+
set({
|
|
98
|
+
wishlist_count: response.wishlist_count,
|
|
99
|
+
product_variants: response.product_variants
|
|
100
|
+
});
|
|
101
|
+
}
|
|
102
|
+
} catch {
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
}));
|
|
106
|
+
var initialState2 = {
|
|
107
|
+
data: [],
|
|
108
|
+
status: "loading" /* LOADING */,
|
|
109
|
+
hasMore: false,
|
|
110
|
+
filter: {
|
|
111
|
+
page: 1,
|
|
112
|
+
page_size: 10
|
|
113
|
+
}
|
|
114
|
+
};
|
|
115
|
+
var useProductStore = create((set, get) => ({
|
|
116
|
+
...initialState2,
|
|
117
|
+
fetchProducts: async (filter) => {
|
|
118
|
+
set((state) => ({
|
|
119
|
+
status: "loading" /* LOADING */,
|
|
120
|
+
data: filter.page === 1 ? [] : state.data
|
|
121
|
+
}));
|
|
122
|
+
try {
|
|
123
|
+
const response = await getProducts({ ...filter });
|
|
124
|
+
if (response.data) {
|
|
125
|
+
const { results, ...meta } = response.data;
|
|
126
|
+
set((state) => ({
|
|
127
|
+
status: "idle" /* IDLE */,
|
|
128
|
+
filter,
|
|
129
|
+
meta,
|
|
130
|
+
hasMore: !!meta.next,
|
|
131
|
+
data: !filter.page || filter.page === 1 ? results : [...state.data, ...results]
|
|
132
|
+
}));
|
|
133
|
+
}
|
|
134
|
+
} catch {
|
|
135
|
+
set({ status: "idle" /* IDLE */ });
|
|
136
|
+
}
|
|
137
|
+
},
|
|
138
|
+
setGatePasses: (products) => set({ data: products })
|
|
139
|
+
}));
|
|
140
|
+
|
|
141
|
+
export { loginUser, useAuthStore, useProductStore, useWishlistStore };
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { ChangeEvent } from 'react';
|
|
2
|
+
import { useFormik } from 'formik';
|
|
3
|
+
import { A as Address } from './address-DQEZzyUG.js';
|
|
4
|
+
|
|
5
|
+
interface UseAddressFormOptions {
|
|
6
|
+
/** Existing address for edit mode. When provided, form prefills from this address. */
|
|
7
|
+
address?: Address;
|
|
8
|
+
/** Called after successful add/update. */
|
|
9
|
+
onSuccess?: (address: Address, isEditing: boolean) => void;
|
|
10
|
+
/** Called on submission error. */
|
|
11
|
+
onError?: (error: unknown) => void;
|
|
12
|
+
/** Cache key for IP geolocation data. Default: "ip_geolocation_data" */
|
|
13
|
+
locationCacheKey?: string;
|
|
14
|
+
/** Default country ID when no IP data or edit address is available. Default: 105 (India) */
|
|
15
|
+
defaultCountryId?: number;
|
|
16
|
+
}
|
|
17
|
+
interface UseAddressFormReturn {
|
|
18
|
+
formik: ReturnType<typeof useFormik<any>>;
|
|
19
|
+
countries: CountryModel.Country[];
|
|
20
|
+
supportedCountries: CountryModel.Country[];
|
|
21
|
+
states: CountryModel.State1[];
|
|
22
|
+
selectedCountry: CountryModel.Country | null;
|
|
23
|
+
countryCodeOptions: Array<{
|
|
24
|
+
value: string;
|
|
25
|
+
label: string;
|
|
26
|
+
country: CountryModel.Country;
|
|
27
|
+
}>;
|
|
28
|
+
addressMeta: {
|
|
29
|
+
regionLabel: string;
|
|
30
|
+
postalLabel: string;
|
|
31
|
+
hasPostal: boolean;
|
|
32
|
+
} | null;
|
|
33
|
+
handlePhoneCountryChange: (value: string | number) => void;
|
|
34
|
+
handleCountryCodeChange: (value: string | number) => void;
|
|
35
|
+
handleStateChange: (e: ChangeEvent<HTMLSelectElement>) => void;
|
|
36
|
+
handlePhoneChange: (e: ChangeEvent<HTMLInputElement>) => void;
|
|
37
|
+
isSubmitting: boolean;
|
|
38
|
+
isEditing: boolean;
|
|
39
|
+
}
|
|
40
|
+
declare function useAddressForm(options?: UseAddressFormOptions): UseAddressFormReturn;
|
|
41
|
+
|
|
42
|
+
export { type UseAddressFormOptions as U, type UseAddressFormReturn as a, useAddressForm as u };
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { ChangeEvent } from 'react';
|
|
2
|
+
import { useFormik } from 'formik';
|
|
3
|
+
import { A as Address } from './address-DQEZzyUG.cjs';
|
|
4
|
+
|
|
5
|
+
interface UseAddressFormOptions {
|
|
6
|
+
/** Existing address for edit mode. When provided, form prefills from this address. */
|
|
7
|
+
address?: Address;
|
|
8
|
+
/** Called after successful add/update. */
|
|
9
|
+
onSuccess?: (address: Address, isEditing: boolean) => void;
|
|
10
|
+
/** Called on submission error. */
|
|
11
|
+
onError?: (error: unknown) => void;
|
|
12
|
+
/** Cache key for IP geolocation data. Default: "ip_geolocation_data" */
|
|
13
|
+
locationCacheKey?: string;
|
|
14
|
+
/** Default country ID when no IP data or edit address is available. Default: 105 (India) */
|
|
15
|
+
defaultCountryId?: number;
|
|
16
|
+
}
|
|
17
|
+
interface UseAddressFormReturn {
|
|
18
|
+
formik: ReturnType<typeof useFormik<any>>;
|
|
19
|
+
countries: CountryModel.Country[];
|
|
20
|
+
supportedCountries: CountryModel.Country[];
|
|
21
|
+
states: CountryModel.State1[];
|
|
22
|
+
selectedCountry: CountryModel.Country | null;
|
|
23
|
+
countryCodeOptions: Array<{
|
|
24
|
+
value: string;
|
|
25
|
+
label: string;
|
|
26
|
+
country: CountryModel.Country;
|
|
27
|
+
}>;
|
|
28
|
+
addressMeta: {
|
|
29
|
+
regionLabel: string;
|
|
30
|
+
postalLabel: string;
|
|
31
|
+
hasPostal: boolean;
|
|
32
|
+
} | null;
|
|
33
|
+
handlePhoneCountryChange: (value: string | number) => void;
|
|
34
|
+
handleCountryCodeChange: (value: string | number) => void;
|
|
35
|
+
handleStateChange: (e: ChangeEvent<HTMLSelectElement>) => void;
|
|
36
|
+
handlePhoneChange: (e: ChangeEvent<HTMLInputElement>) => void;
|
|
37
|
+
isSubmitting: boolean;
|
|
38
|
+
isEditing: boolean;
|
|
39
|
+
}
|
|
40
|
+
declare function useAddressForm(options?: UseAddressFormOptions): UseAddressFormReturn;
|
|
41
|
+
|
|
42
|
+
export { type UseAddressFormOptions as U, type UseAddressFormReturn as a, useAddressForm as u };
|