@myrjfa/state 1.1.1 → 2.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/index.d.ts +34 -18
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +34 -18
- package/dist/lib/actions/actions.d.ts +170 -170
- package/dist/lib/actions/actions.js +307 -307
- package/dist/lib/actions/auth.d.ts +20 -0
- package/dist/lib/actions/auth.d.ts.map +1 -1
- package/dist/lib/actions/booking.d.ts +30 -0
- package/dist/lib/actions/booking.d.ts.map +1 -0
- package/dist/lib/actions/booking.js +77 -0
- package/dist/lib/actions/fetcher.js +84 -84
- package/dist/lib/actions/severActions.js +2 -2
- package/dist/lib/authSessionManager.js +34 -34
- package/dist/lib/context/ChatContext.js +338 -338
- package/dist/lib/models/adventure.d.ts +75 -0
- package/dist/lib/models/adventure.d.ts.map +1 -0
- package/dist/lib/models/adventure.js +1 -0
- package/dist/lib/models/blog.d.ts +4 -4
- package/dist/lib/models/booking.d.ts +47 -0
- package/dist/lib/models/booking.d.ts.map +1 -0
- package/dist/lib/models/booking.js +1 -0
- package/dist/lib/models/guide.d.ts +43 -0
- package/dist/lib/models/guide.d.ts.map +1 -0
- package/dist/lib/models/guide.js +1 -0
- package/dist/lib/models/notfications.d.ts +93 -93
- package/dist/lib/models/opportunities/freelance.d.ts +74 -6
- package/dist/lib/models/opportunities/freelance.d.ts.map +1 -1
- package/dist/lib/models/opportunities/internship.d.ts +74 -6
- package/dist/lib/models/opportunities/internship.d.ts.map +1 -1
- package/dist/lib/models/opportunities/job.d.ts +74 -6
- package/dist/lib/models/opportunities/job.d.ts.map +1 -1
- package/dist/lib/models/opportunities/opportunity.d.ts +74 -6
- package/dist/lib/models/opportunities/opportunity.d.ts.map +1 -1
- package/dist/lib/models/opportunities/volunteerJob.d.ts +74 -6
- package/dist/lib/models/opportunities/volunteerJob.d.ts.map +1 -1
- package/dist/lib/models/package.d.ts +264 -0
- package/dist/lib/models/package.d.ts.map +1 -0
- package/dist/lib/models/package.js +58 -0
- package/dist/lib/models/portfolio.d.ts +42 -42
- package/dist/lib/models/props.d.ts +3 -0
- package/dist/lib/models/props.d.ts.map +1 -1
- package/dist/lib/models/props.js +36 -0
- package/dist/lib/models/rental.d.ts +85 -0
- package/dist/lib/models/rental.d.ts.map +1 -0
- package/dist/lib/models/rental.js +1 -0
- package/dist/lib/models/review.d.ts +1 -1
- package/dist/lib/models/review.d.ts.map +1 -1
- package/dist/lib/models/stay.d.ts +459 -0
- package/dist/lib/models/stay.d.ts.map +1 -0
- package/dist/lib/models/stay.js +214 -0
- package/dist/lib/models/tile.d.ts +53 -28
- package/dist/lib/models/tile.d.ts.map +1 -1
- package/dist/lib/models/user.d.ts +48 -0
- package/dist/lib/models/user.d.ts.map +1 -1
- package/dist/lib/models/user.js +10 -0
- package/dist/lib/userAtom.d.ts +238 -198
- package/dist/lib/userAtom.d.ts.map +1 -1
- package/dist/lib/userAtom.js +127 -127
- package/package.json +6 -1
- package/dist/lib/actions/property.d.ts +0 -77
- package/dist/lib/actions/property.d.ts.map +0 -1
- package/dist/lib/actions/property.js +0 -133
- package/dist/lib/actions.d.ts +0 -141
- package/dist/lib/actions.d.ts.map +0 -1
- package/dist/lib/actions.js +0 -307
- package/dist/lib/auth.d.ts +0 -150
- package/dist/lib/auth.d.ts.map +0 -1
- package/dist/lib/auth.js +0 -125
- package/dist/lib/fetcher.d.ts +0 -9
- package/dist/lib/fetcher.d.ts.map +0 -1
- package/dist/lib/fetcher.js +0 -84
- package/dist/lib/models/property.d.ts +0 -79
- package/dist/lib/models/property.d.ts.map +0 -1
- package/dist/lib/models/property.js +0 -134
- package/dist/lib/models/volunteerJob.d.ts +0 -398
- package/dist/lib/models/volunteerJob.d.ts.map +0 -1
- package/dist/lib/models/volunteerJob.js +0 -152
- package/dist/lib/severActions.d.ts +0 -3
- package/dist/lib/severActions.d.ts.map +0 -1
- package/dist/lib/severActions.js +0 -19
- package/dist/lib/socket.d.ts +0 -7
- package/dist/lib/socket.d.ts.map +0 -1
- package/dist/lib/socket.js +0 -22
- package/dist/lib/utils/socialMediaUrl.d.ts +0 -25
- package/dist/lib/utils/socialMediaUrl.d.ts.map +0 -1
- package/dist/lib/utils/socialMediaUrl.js +0 -97
package/dist/lib/actions.js
DELETED
|
@@ -1,307 +0,0 @@
|
|
|
1
|
-
import { del, get, patch, post } from "./fetcher";
|
|
2
|
-
// host
|
|
3
|
-
// user/host
|
|
4
|
-
export async function getCurrentUser() {
|
|
5
|
-
try {
|
|
6
|
-
const endpoint = `/users/me`;
|
|
7
|
-
const data = await get(endpoint);
|
|
8
|
-
// console.log(data.message);
|
|
9
|
-
return data?.data;
|
|
10
|
-
}
|
|
11
|
-
catch (error) {
|
|
12
|
-
console.error('Failed to fetch user details: ', error);
|
|
13
|
-
return null;
|
|
14
|
-
}
|
|
15
|
-
}
|
|
16
|
-
export async function userDetails(query, role) {
|
|
17
|
-
try {
|
|
18
|
-
if (role == "admin")
|
|
19
|
-
role = "user";
|
|
20
|
-
const endpoint = `/${role}s/other-${role}/${query}`;
|
|
21
|
-
const data = await get(endpoint);
|
|
22
|
-
return {
|
|
23
|
-
success: true,
|
|
24
|
-
user: data?.data,
|
|
25
|
-
message: data.message
|
|
26
|
-
};
|
|
27
|
-
}
|
|
28
|
-
catch (error) {
|
|
29
|
-
console.error('Failed to fetch user details: ', error);
|
|
30
|
-
return { success: false, user: null, status: error.status, error: error.message };
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
export async function subscribeToNewsLetter(email) {
|
|
34
|
-
try {
|
|
35
|
-
const endpoint = `/subscription/create`;
|
|
36
|
-
const data = await post(endpoint, { email: email });
|
|
37
|
-
return { success: true, message: data.message };
|
|
38
|
-
}
|
|
39
|
-
catch (error) {
|
|
40
|
-
console.error('Error subscribing to newsletter: ', error);
|
|
41
|
-
return {
|
|
42
|
-
success: false,
|
|
43
|
-
error: error.message,
|
|
44
|
-
};
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
export async function toggleUserWishlist(slug, tileType) {
|
|
48
|
-
try {
|
|
49
|
-
const endpoint = `/users/fav/${tileType}/toggle`;
|
|
50
|
-
const data = await post(endpoint, { id: slug });
|
|
51
|
-
return { success: true, message: data.message, wishlist: data.data };
|
|
52
|
-
}
|
|
53
|
-
catch (error) {
|
|
54
|
-
console.error(`Failed to add ${tileType} to wishlist: `, error);
|
|
55
|
-
return {
|
|
56
|
-
success: false,
|
|
57
|
-
error: error.message,
|
|
58
|
-
wishlist: []
|
|
59
|
-
};
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
// subscribe
|
|
63
|
-
export async function subscribeToCareersPage(email) {
|
|
64
|
-
try {
|
|
65
|
-
const endpoint = `/subscription/create-job`;
|
|
66
|
-
const data = await post(endpoint, { email: email });
|
|
67
|
-
return { success: true, message: data.message };
|
|
68
|
-
}
|
|
69
|
-
catch (error) {
|
|
70
|
-
console.error('Error subscribing to newsletter: ', error);
|
|
71
|
-
return {
|
|
72
|
-
success: false,
|
|
73
|
-
error: error.message,
|
|
74
|
-
};
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
export async function contactUs(email, name, subject, message) {
|
|
78
|
-
try {
|
|
79
|
-
const endpoint = `/contactUs`;
|
|
80
|
-
const data = await post(endpoint, { email: email, name: name, subject: subject, message: message });
|
|
81
|
-
return { success: true, message: data.message };
|
|
82
|
-
}
|
|
83
|
-
catch (error) {
|
|
84
|
-
console.error('Error contacting trippeaze: ', error);
|
|
85
|
-
return {
|
|
86
|
-
success: false,
|
|
87
|
-
error: error.message,
|
|
88
|
-
};
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
// resume
|
|
92
|
-
export async function saveUserResume(file) {
|
|
93
|
-
try {
|
|
94
|
-
const endpoint = `/users/resume-update`;
|
|
95
|
-
const formData = new FormData();
|
|
96
|
-
formData.append('resume', file);
|
|
97
|
-
const data = await patch(endpoint, formData);
|
|
98
|
-
return {
|
|
99
|
-
success: true,
|
|
100
|
-
message: data.message,
|
|
101
|
-
user: data.data,
|
|
102
|
-
};
|
|
103
|
-
}
|
|
104
|
-
catch (error) {
|
|
105
|
-
return { success: false, error: error.message, user: null };
|
|
106
|
-
}
|
|
107
|
-
}
|
|
108
|
-
export async function getUserContact(username, role) {
|
|
109
|
-
try {
|
|
110
|
-
const endpoint = `/${role}s/getUserContact/${username}`;
|
|
111
|
-
const data = await get(endpoint);
|
|
112
|
-
return {
|
|
113
|
-
success: true,
|
|
114
|
-
message: data.message,
|
|
115
|
-
details: data.data,
|
|
116
|
-
};
|
|
117
|
-
}
|
|
118
|
-
catch (error) {
|
|
119
|
-
return {
|
|
120
|
-
success: false,
|
|
121
|
-
error: error.message,
|
|
122
|
-
details: null,
|
|
123
|
-
};
|
|
124
|
-
}
|
|
125
|
-
}
|
|
126
|
-
// rating and reviews
|
|
127
|
-
export async function getReviewsById(id, type) {
|
|
128
|
-
try {
|
|
129
|
-
const endpoint = `/reviews/entity/${id}/${type}`;
|
|
130
|
-
const data = await get(endpoint);
|
|
131
|
-
// const data = { data: sampleReviews, message: "success" };
|
|
132
|
-
return {
|
|
133
|
-
success: true,
|
|
134
|
-
reviews: data.data,
|
|
135
|
-
message: data.message,
|
|
136
|
-
};
|
|
137
|
-
}
|
|
138
|
-
catch (error) {
|
|
139
|
-
console.error('Failed to get reviews: ', error);
|
|
140
|
-
return {
|
|
141
|
-
success: true,
|
|
142
|
-
reviews: [],
|
|
143
|
-
error: error.message,
|
|
144
|
-
};
|
|
145
|
-
}
|
|
146
|
-
}
|
|
147
|
-
export async function getRatingById(id, type) {
|
|
148
|
-
try {
|
|
149
|
-
const endpoint = `/reviews/entity/${id}`;
|
|
150
|
-
const data = await get(endpoint);
|
|
151
|
-
// const data = {
|
|
152
|
-
// data:
|
|
153
|
-
// [{
|
|
154
|
-
// slug: id[0] ?? "",
|
|
155
|
-
// rating: truncateDecimal(sampleReviews.reduce((acc, review) => acc + review.rating, 0) / sampleReviews.length, 1),
|
|
156
|
-
// ratingCount: sampleReviews.length,
|
|
157
|
-
// reviewCount: 100,
|
|
158
|
-
// }],
|
|
159
|
-
// message: "success"
|
|
160
|
-
// }
|
|
161
|
-
return {
|
|
162
|
-
success: true,
|
|
163
|
-
ratings: data.data,
|
|
164
|
-
message: data.message,
|
|
165
|
-
};
|
|
166
|
-
}
|
|
167
|
-
catch (error) {
|
|
168
|
-
console.error('Failed to get reviews: ', error);
|
|
169
|
-
return {
|
|
170
|
-
success: true,
|
|
171
|
-
ratings: [],
|
|
172
|
-
error: error.message,
|
|
173
|
-
};
|
|
174
|
-
}
|
|
175
|
-
}
|
|
176
|
-
export async function addReview(id, type, formData) {
|
|
177
|
-
try {
|
|
178
|
-
const endpoint = `/reviews/`;
|
|
179
|
-
const data = await post(endpoint, { reviewee: id, revieweeType: type, rating: formData.rating, comment: formData.comment });
|
|
180
|
-
return {
|
|
181
|
-
success: true,
|
|
182
|
-
review: data.data,
|
|
183
|
-
message: data.message,
|
|
184
|
-
};
|
|
185
|
-
}
|
|
186
|
-
catch (error) {
|
|
187
|
-
console.error('Failed to get reviews: ', error);
|
|
188
|
-
return {
|
|
189
|
-
success: false,
|
|
190
|
-
review: null,
|
|
191
|
-
error: error.message,
|
|
192
|
-
};
|
|
193
|
-
}
|
|
194
|
-
}
|
|
195
|
-
export async function editReview(id, formData) {
|
|
196
|
-
try {
|
|
197
|
-
const endpoint = `/reviews/${id}`;
|
|
198
|
-
const data = await patch(endpoint, { rating: formData.rating, comment: formData.comment });
|
|
199
|
-
return {
|
|
200
|
-
success: true,
|
|
201
|
-
review: data.data,
|
|
202
|
-
message: data.message,
|
|
203
|
-
};
|
|
204
|
-
}
|
|
205
|
-
catch (error) {
|
|
206
|
-
console.error('Failed to get reviews: ', error);
|
|
207
|
-
return {
|
|
208
|
-
success: false,
|
|
209
|
-
review: null,
|
|
210
|
-
error: error.message,
|
|
211
|
-
};
|
|
212
|
-
}
|
|
213
|
-
}
|
|
214
|
-
export async function deleteReview(id) {
|
|
215
|
-
try {
|
|
216
|
-
const endpoint = `/reviews/${id}`;
|
|
217
|
-
const data = await del(endpoint);
|
|
218
|
-
return {
|
|
219
|
-
success: true,
|
|
220
|
-
message: data.message,
|
|
221
|
-
};
|
|
222
|
-
}
|
|
223
|
-
catch (error) {
|
|
224
|
-
console.error('Failed to get reviews: ', error);
|
|
225
|
-
return {
|
|
226
|
-
success: false,
|
|
227
|
-
error: error.message,
|
|
228
|
-
};
|
|
229
|
-
}
|
|
230
|
-
}
|
|
231
|
-
// notifications
|
|
232
|
-
export async function getAllNotifications() {
|
|
233
|
-
try {
|
|
234
|
-
const endpoint = `/notification?all=true`;
|
|
235
|
-
const data = await get(endpoint);
|
|
236
|
-
return {
|
|
237
|
-
success: true,
|
|
238
|
-
message: data.message,
|
|
239
|
-
notifs: data.data.notifications,
|
|
240
|
-
unreadCount: data.data.unreadCount,
|
|
241
|
-
};
|
|
242
|
-
}
|
|
243
|
-
catch (error) {
|
|
244
|
-
console.error('Failed to fetch notifications: ', error);
|
|
245
|
-
return {
|
|
246
|
-
success: false,
|
|
247
|
-
error: error.message,
|
|
248
|
-
notifs: [],
|
|
249
|
-
unreadCount: 0,
|
|
250
|
-
};
|
|
251
|
-
}
|
|
252
|
-
}
|
|
253
|
-
export async function getNotifications(limit) {
|
|
254
|
-
try {
|
|
255
|
-
const endpoint = `/notification?limit=${limit}`;
|
|
256
|
-
const data = await get(endpoint);
|
|
257
|
-
return {
|
|
258
|
-
success: true,
|
|
259
|
-
message: data.message,
|
|
260
|
-
notifs: data.data.notifications,
|
|
261
|
-
unreadCount: data.data.unreadCount,
|
|
262
|
-
};
|
|
263
|
-
}
|
|
264
|
-
catch (error) {
|
|
265
|
-
console.error('Failed to fetch notifications: ', error);
|
|
266
|
-
return {
|
|
267
|
-
success: false,
|
|
268
|
-
error: error.message,
|
|
269
|
-
notifs: [],
|
|
270
|
-
unreadCount: 0,
|
|
271
|
-
};
|
|
272
|
-
}
|
|
273
|
-
}
|
|
274
|
-
export async function toggleNotification(id, read) {
|
|
275
|
-
try {
|
|
276
|
-
const endpoint = `/notfication/${id}`;
|
|
277
|
-
const data = await patch(endpoint, { isRead: read });
|
|
278
|
-
return {
|
|
279
|
-
success: true,
|
|
280
|
-
message: data.message,
|
|
281
|
-
};
|
|
282
|
-
}
|
|
283
|
-
catch (error) {
|
|
284
|
-
console.error('Failed to toggle notfication: ', error);
|
|
285
|
-
return {
|
|
286
|
-
success: false,
|
|
287
|
-
error: error.message,
|
|
288
|
-
};
|
|
289
|
-
}
|
|
290
|
-
}
|
|
291
|
-
export async function toggleAllNotification(read) {
|
|
292
|
-
try {
|
|
293
|
-
const endpoint = `/notfication/update/all`;
|
|
294
|
-
const data = await patch(endpoint, { isRead: read });
|
|
295
|
-
return {
|
|
296
|
-
success: true,
|
|
297
|
-
message: data.message,
|
|
298
|
-
};
|
|
299
|
-
}
|
|
300
|
-
catch (error) {
|
|
301
|
-
console.error('Failed to toggle all notfications: ', error);
|
|
302
|
-
return {
|
|
303
|
-
success: false,
|
|
304
|
-
error: error.message,
|
|
305
|
-
};
|
|
306
|
-
}
|
|
307
|
-
}
|
package/dist/lib/auth.d.ts
DELETED
|
@@ -1,150 +0,0 @@
|
|
|
1
|
-
export declare function signIn(formData: {
|
|
2
|
-
email: string;
|
|
3
|
-
password: string;
|
|
4
|
-
role: string;
|
|
5
|
-
}): Promise<{
|
|
6
|
-
user: {
|
|
7
|
-
username: string;
|
|
8
|
-
firstName: string;
|
|
9
|
-
lastName: string;
|
|
10
|
-
email: string;
|
|
11
|
-
password: string;
|
|
12
|
-
phoneNumber: string;
|
|
13
|
-
countryCode: string;
|
|
14
|
-
country: string;
|
|
15
|
-
gender: "male" | "female" | "other";
|
|
16
|
-
rating: number;
|
|
17
|
-
ratingCount: number;
|
|
18
|
-
reviewCount: number;
|
|
19
|
-
joinedDate: Date;
|
|
20
|
-
isActive: boolean;
|
|
21
|
-
lastActive: Date;
|
|
22
|
-
verifiedEmail: boolean;
|
|
23
|
-
verifiedMobile: boolean;
|
|
24
|
-
role: "host" | "user" | "admin" | "hr" | "sales";
|
|
25
|
-
location?: string | undefined;
|
|
26
|
-
pinCode?: string | undefined;
|
|
27
|
-
dob?: Date | undefined;
|
|
28
|
-
profilePic?: string | undefined;
|
|
29
|
-
blogsCount?: number | undefined;
|
|
30
|
-
userBio?: string | undefined;
|
|
31
|
-
userIdCard?: string | undefined;
|
|
32
|
-
watchHistory?: string[] | undefined;
|
|
33
|
-
accessToken?: string | undefined;
|
|
34
|
-
refreshToken?: string | undefined;
|
|
35
|
-
verifiedIdCard?: boolean | undefined;
|
|
36
|
-
socialLinks?: Record<string, string> | undefined;
|
|
37
|
-
userResume?: string | undefined;
|
|
38
|
-
skills?: {
|
|
39
|
-
skill: string;
|
|
40
|
-
skillExpertise: number;
|
|
41
|
-
}[] | undefined;
|
|
42
|
-
wishlist?: string[] | undefined;
|
|
43
|
-
favBlogs?: string[] | undefined;
|
|
44
|
-
favPackages?: string[] | undefined;
|
|
45
|
-
id?: string | undefined;
|
|
46
|
-
selfie?: string | undefined;
|
|
47
|
-
selfieAction?: string | undefined;
|
|
48
|
-
jobCount?: number | undefined;
|
|
49
|
-
travelPackageCount?: number | undefined;
|
|
50
|
-
gstNumber?: string | undefined;
|
|
51
|
-
panCard?: string | undefined;
|
|
52
|
-
verifiedBusiness?: "true" | "false" | "inProgress" | undefined;
|
|
53
|
-
};
|
|
54
|
-
message: string;
|
|
55
|
-
success?: undefined;
|
|
56
|
-
status?: undefined;
|
|
57
|
-
error?: undefined;
|
|
58
|
-
} | {
|
|
59
|
-
success: boolean;
|
|
60
|
-
status: any;
|
|
61
|
-
error: any;
|
|
62
|
-
user?: undefined;
|
|
63
|
-
message?: undefined;
|
|
64
|
-
}>;
|
|
65
|
-
export declare function logoutUser(role: string): Promise<{
|
|
66
|
-
success: boolean;
|
|
67
|
-
message?: string;
|
|
68
|
-
error?: string;
|
|
69
|
-
}>;
|
|
70
|
-
export declare function verifyEmailOtp(email: string, otp: string, role: "user" | "host"): Promise<{
|
|
71
|
-
user: {
|
|
72
|
-
username: string;
|
|
73
|
-
firstName: string;
|
|
74
|
-
lastName: string;
|
|
75
|
-
email: string;
|
|
76
|
-
password: string;
|
|
77
|
-
phoneNumber: string;
|
|
78
|
-
countryCode: string;
|
|
79
|
-
country: string;
|
|
80
|
-
gender: "male" | "female" | "other";
|
|
81
|
-
rating: number;
|
|
82
|
-
ratingCount: number;
|
|
83
|
-
reviewCount: number;
|
|
84
|
-
joinedDate: Date;
|
|
85
|
-
isActive: boolean;
|
|
86
|
-
lastActive: Date;
|
|
87
|
-
verifiedEmail: boolean;
|
|
88
|
-
verifiedMobile: boolean;
|
|
89
|
-
role: "host" | "user" | "admin" | "hr" | "sales";
|
|
90
|
-
location?: string | undefined;
|
|
91
|
-
pinCode?: string | undefined;
|
|
92
|
-
dob?: Date | undefined;
|
|
93
|
-
profilePic?: string | undefined;
|
|
94
|
-
blogsCount?: number | undefined;
|
|
95
|
-
userBio?: string | undefined;
|
|
96
|
-
userIdCard?: string | undefined;
|
|
97
|
-
watchHistory?: string[] | undefined;
|
|
98
|
-
accessToken?: string | undefined;
|
|
99
|
-
refreshToken?: string | undefined;
|
|
100
|
-
verifiedIdCard?: boolean | undefined;
|
|
101
|
-
socialLinks?: Record<string, string> | undefined;
|
|
102
|
-
userResume?: string | undefined;
|
|
103
|
-
skills?: {
|
|
104
|
-
skill: string;
|
|
105
|
-
skillExpertise: number;
|
|
106
|
-
}[] | undefined;
|
|
107
|
-
wishlist?: string[] | undefined;
|
|
108
|
-
favBlogs?: string[] | undefined;
|
|
109
|
-
favPackages?: string[] | undefined;
|
|
110
|
-
id?: string | undefined;
|
|
111
|
-
selfie?: string | undefined;
|
|
112
|
-
selfieAction?: string | undefined;
|
|
113
|
-
jobCount?: number | undefined;
|
|
114
|
-
travelPackageCount?: number | undefined;
|
|
115
|
-
gstNumber?: string | undefined;
|
|
116
|
-
panCard?: string | undefined;
|
|
117
|
-
verifiedBusiness?: "true" | "false" | "inProgress" | undefined;
|
|
118
|
-
};
|
|
119
|
-
message: string;
|
|
120
|
-
success?: undefined;
|
|
121
|
-
status?: undefined;
|
|
122
|
-
error?: undefined;
|
|
123
|
-
} | {
|
|
124
|
-
success: boolean;
|
|
125
|
-
status: any;
|
|
126
|
-
error: any;
|
|
127
|
-
user?: undefined;
|
|
128
|
-
message?: undefined;
|
|
129
|
-
}>;
|
|
130
|
-
export declare function sendPasswordResetEmail(email: string, role: string): Promise<{
|
|
131
|
-
success: boolean;
|
|
132
|
-
message?: string;
|
|
133
|
-
error?: string;
|
|
134
|
-
}>;
|
|
135
|
-
export declare function changePassword(password: string, oldPassword: string, role: string): Promise<{
|
|
136
|
-
success: boolean;
|
|
137
|
-
message?: string;
|
|
138
|
-
error?: string;
|
|
139
|
-
}>;
|
|
140
|
-
export declare function resetPassword(password: string, token: string, role: string): Promise<{
|
|
141
|
-
success: boolean;
|
|
142
|
-
message?: string;
|
|
143
|
-
error?: string;
|
|
144
|
-
}>;
|
|
145
|
-
export declare function validateSession(): Promise<{
|
|
146
|
-
success: boolean;
|
|
147
|
-
message?: string;
|
|
148
|
-
error?: string;
|
|
149
|
-
}>;
|
|
150
|
-
//# sourceMappingURL=auth.d.ts.map
|
package/dist/lib/auth.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"auth.d.ts","sourceRoot":"","sources":["../../src/lib/auth.ts"],"names":[],"mappings":"AAGA,wBAAsB,MAAM,CAAC,QAAQ,EAAE;IACnC,KAAK,EAAE,MAAM,CAAC;IACd,QAAQ,EAAE,MAAM,CAAC;IACjB,IAAI,EAAE,MAAM,CAAC;CAChB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAeA;AAED,wBAAsB,UAAU,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC;IAAE,OAAO,EAAE,OAAO,CAAC;IAAC,OAAO,CAAC,EAAE,MAAM,CAAC;IAAC,KAAK,CAAC,EAAE,MAAM,CAAA;CAAE,CAAC,CAa9G;AAED,wBAAsB,cAAc,CAAC,KAAK,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,MAAM;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAcrF;AAED,wBAAsB,sBAAsB,CAAC,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC;IAAE,OAAO,EAAE,OAAO,CAAC;IAAC,OAAO,CAAC,EAAE,MAAM,CAAC;IAAC,KAAK,CAAC,EAAE,MAAM,CAAA;CAAE,CAAC,CAgBzI;AAED,wBAAsB,cAAc,CAAC,QAAQ,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC;IAAE,OAAO,EAAE,OAAO,CAAC;IAAC,OAAO,CAAC,EAAE,MAAM,CAAC;IAAC,KAAK,CAAC,EAAE,MAAM,CAAA;CAAE,CAAC,CAgBzJ;AAED,wBAAsB,aAAa,CAAC,QAAQ,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC;IAAE,OAAO,EAAE,OAAO,CAAC;IAAC,OAAO,CAAC,EAAE,MAAM,CAAC;IAAC,KAAK,CAAC,EAAE,MAAM,CAAA;CAAE,CAAC,CAgBlJ;AAED,wBAAsB,eAAe,IAAI,OAAO,CAAC;IAAE,OAAO,EAAE,OAAO,CAAC;IAAC,OAAO,CAAC,EAAE,MAAM,CAAC;IAAC,KAAK,CAAC,EAAE,MAAM,CAAA;CAAE,CAAC,CAevG"}
|
package/dist/lib/auth.js
DELETED
|
@@ -1,125 +0,0 @@
|
|
|
1
|
-
import { get, patch, post } from "./fetcher";
|
|
2
|
-
export async function signIn(formData) {
|
|
3
|
-
try {
|
|
4
|
-
let endpoint = '/users/login';
|
|
5
|
-
if (formData.role === 'host')
|
|
6
|
-
endpoint = '/hosts/login';
|
|
7
|
-
const data = await post(endpoint, formData);
|
|
8
|
-
// console.log('Response:', data);
|
|
9
|
-
return {
|
|
10
|
-
user: data.data.user,
|
|
11
|
-
message: data.message,
|
|
12
|
-
};
|
|
13
|
-
}
|
|
14
|
-
catch (error) {
|
|
15
|
-
console.error(error.message);
|
|
16
|
-
return { success: false, status: error.status, error: error.message };
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
export async function logoutUser(role) {
|
|
20
|
-
try {
|
|
21
|
-
let endpoint = '/users/logout';
|
|
22
|
-
if (role === 'host')
|
|
23
|
-
endpoint = '/hosts/logout';
|
|
24
|
-
const response = await get(endpoint);
|
|
25
|
-
return {
|
|
26
|
-
success: true,
|
|
27
|
-
message: response.message
|
|
28
|
-
};
|
|
29
|
-
}
|
|
30
|
-
catch (error) {
|
|
31
|
-
console.error(error.message);
|
|
32
|
-
return { success: false, error: error.message };
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
export async function verifyEmailOtp(email, otp, role) {
|
|
36
|
-
try {
|
|
37
|
-
let endpoint = `/users/verify-otp`;
|
|
38
|
-
if (role === 'host')
|
|
39
|
-
endpoint = `/hosts/verify-otp`;
|
|
40
|
-
const data = await post(endpoint, { email: email, emailOtp: otp });
|
|
41
|
-
// console.log('Response:', data);
|
|
42
|
-
return {
|
|
43
|
-
user: data.data.user,
|
|
44
|
-
message: data.message,
|
|
45
|
-
};
|
|
46
|
-
}
|
|
47
|
-
catch (error) {
|
|
48
|
-
console.error(error.message);
|
|
49
|
-
return { success: false, status: error.status, error: error.message };
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
export async function sendPasswordResetEmail(email, role) {
|
|
53
|
-
try {
|
|
54
|
-
let endpoint = `/users/forgot-password`;
|
|
55
|
-
if (role === 'host')
|
|
56
|
-
endpoint = `/hosts/forgot-password`;
|
|
57
|
-
const data = await post(endpoint, { email: email });
|
|
58
|
-
return {
|
|
59
|
-
success: true,
|
|
60
|
-
message: data.message
|
|
61
|
-
};
|
|
62
|
-
}
|
|
63
|
-
catch (error) {
|
|
64
|
-
console.error('Error sending reset password:', error);
|
|
65
|
-
return {
|
|
66
|
-
success: false,
|
|
67
|
-
error: error.message,
|
|
68
|
-
};
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
export async function changePassword(password, oldPassword, role) {
|
|
72
|
-
try {
|
|
73
|
-
let endpoint = `/users/change-password`;
|
|
74
|
-
if (role === 'host')
|
|
75
|
-
endpoint = `/hosts/change-password`;
|
|
76
|
-
const data = await patch(endpoint, { oldPassword: oldPassword, password: password });
|
|
77
|
-
return {
|
|
78
|
-
success: true,
|
|
79
|
-
message: data.message
|
|
80
|
-
};
|
|
81
|
-
}
|
|
82
|
-
catch (error) {
|
|
83
|
-
console.error('Error changing password:', error);
|
|
84
|
-
return {
|
|
85
|
-
success: false,
|
|
86
|
-
error: error.message,
|
|
87
|
-
};
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
export async function resetPassword(password, token, role) {
|
|
91
|
-
try {
|
|
92
|
-
let endpoint = `/users/reset-password/${token}`;
|
|
93
|
-
if (role === 'host')
|
|
94
|
-
endpoint = `/hosts/reset-password/${token}`;
|
|
95
|
-
const data = await post(endpoint, { token: token, password: password });
|
|
96
|
-
return {
|
|
97
|
-
success: true,
|
|
98
|
-
message: data.message
|
|
99
|
-
};
|
|
100
|
-
}
|
|
101
|
-
catch (error) {
|
|
102
|
-
console.error('Error changing password:', error);
|
|
103
|
-
return {
|
|
104
|
-
success: false,
|
|
105
|
-
error: error.message,
|
|
106
|
-
};
|
|
107
|
-
}
|
|
108
|
-
}
|
|
109
|
-
export async function validateSession() {
|
|
110
|
-
try {
|
|
111
|
-
const endpoint = '/users/verifySession';
|
|
112
|
-
const data = await get(endpoint);
|
|
113
|
-
return {
|
|
114
|
-
success: true,
|
|
115
|
-
message: data.message
|
|
116
|
-
};
|
|
117
|
-
}
|
|
118
|
-
catch (error) {
|
|
119
|
-
console.error(error);
|
|
120
|
-
return {
|
|
121
|
-
success: false,
|
|
122
|
-
error: error.message,
|
|
123
|
-
};
|
|
124
|
-
}
|
|
125
|
-
}
|
package/dist/lib/fetcher.d.ts
DELETED
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
type FetchMethod = 'GET' | 'POST' | 'PUT' | 'DELETE' | 'PATCH';
|
|
2
|
-
export declare function refreshToken<T>(input: string, method: FetchMethod, body?: any): Promise<T>;
|
|
3
|
-
export declare function get<T>(url: string, includeAuth?: boolean): Promise<T>;
|
|
4
|
-
export declare function post<T>(url: string, body: any): Promise<T>;
|
|
5
|
-
export declare function put<T>(url: string, body: any): Promise<T>;
|
|
6
|
-
export declare function patch<T>(url: string, body: any): Promise<T>;
|
|
7
|
-
export declare function del<T>(url: string, body?: any): Promise<T>;
|
|
8
|
-
export {};
|
|
9
|
-
//# sourceMappingURL=fetcher.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"fetcher.d.ts","sourceRoot":"","sources":["../../src/lib/fetcher.ts"],"names":[],"mappings":"AAKA,KAAK,WAAW,GAAG,KAAK,GAAG,MAAM,GAAG,KAAK,GAAG,QAAQ,GAAG,OAAO,CAAC;AAsE/D,wBAAsB,YAAY,CAAC,CAAC,EAChC,KAAK,EAAE,MAAM,EACb,MAAM,EAAE,WAAW,EACnB,IAAI,CAAC,EAAE,GAAG,GACX,OAAO,CAAC,CAAC,CAAC,CAiBZ;AAID,wBAAsB,GAAG,CAAC,CAAC,EAAE,GAAG,EAAE,MAAM,EAAE,WAAW,GAAE,OAAc,cAEpE;AAED,wBAAsB,IAAI,CAAC,CAAC,EAAE,GAAG,EAAE,MAAM,EAAE,IAAI,EAAE,GAAG,cAEnD;AAED,wBAAsB,GAAG,CAAC,CAAC,EAAE,GAAG,EAAE,MAAM,EAAE,IAAI,EAAE,GAAG,cAElD;AAED,wBAAsB,KAAK,CAAC,CAAC,EAAE,GAAG,EAAE,MAAM,EAAE,IAAI,EAAE,GAAG,cAEpD;AAED,wBAAsB,GAAG,CAAC,CAAC,EAAE,GAAG,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,GAAG,cAEnD"}
|
package/dist/lib/fetcher.js
DELETED
|
@@ -1,84 +0,0 @@
|
|
|
1
|
-
import { ApiError } from "next/dist/server/api-utils";
|
|
2
|
-
import { getCookieHeader, getRole } from "./severActions";
|
|
3
|
-
const baseURL = process.env.NEXT_PUBLIC_API_URL;
|
|
4
|
-
async function customFetch(input, method, body, options = {}) {
|
|
5
|
-
const { includeAuth = false, retry = true } = options;
|
|
6
|
-
const url = `${baseURL}${input}`;
|
|
7
|
-
const isFormData = typeof FormData !== 'undefined' && body instanceof FormData;
|
|
8
|
-
let headers = isFormData
|
|
9
|
-
? { Accept: 'application/json' }
|
|
10
|
-
: { 'Content-Type': 'application/json', Accept: 'application/json' };
|
|
11
|
-
if (includeAuth) {
|
|
12
|
-
try {
|
|
13
|
-
const cookieHeader = await getCookieHeader();
|
|
14
|
-
headers = { ...headers, Cookie: cookieHeader };
|
|
15
|
-
}
|
|
16
|
-
catch (error) {
|
|
17
|
-
// If we can't get cookies (CSR context), credentials: 'include' will handle it
|
|
18
|
-
console.warn('Could not get cookies for auth header:', error);
|
|
19
|
-
}
|
|
20
|
-
}
|
|
21
|
-
const init = {
|
|
22
|
-
method,
|
|
23
|
-
credentials: 'include',
|
|
24
|
-
headers,
|
|
25
|
-
...(body ? { body: isFormData ? body : JSON.stringify(body) } : {}),
|
|
26
|
-
};
|
|
27
|
-
const response = await fetch(url, init);
|
|
28
|
-
if (response.ok) {
|
|
29
|
-
return response.status !== 204 ? (await response.json()) : {};
|
|
30
|
-
}
|
|
31
|
-
// Token refresh logic on 401 (only for authenticated requests)
|
|
32
|
-
if (response.status === 401 && retry && includeAuth && !input.includes('/login')) {
|
|
33
|
-
return await refreshToken(input, method, body);
|
|
34
|
-
}
|
|
35
|
-
// Error handling
|
|
36
|
-
let errorBody;
|
|
37
|
-
try {
|
|
38
|
-
errorBody = (await response.json());
|
|
39
|
-
}
|
|
40
|
-
catch (error) {
|
|
41
|
-
errorBody = {
|
|
42
|
-
statusCode: response.status,
|
|
43
|
-
error: typeof error === 'string' ? error : 'Unknown error',
|
|
44
|
-
};
|
|
45
|
-
}
|
|
46
|
-
throw new ApiError(errorBody.statusCode, errorBody.error);
|
|
47
|
-
}
|
|
48
|
-
// Token refresh function
|
|
49
|
-
export async function refreshToken(input, method, body) {
|
|
50
|
-
const role = await getRole();
|
|
51
|
-
try {
|
|
52
|
-
const roleForEndpoint = role == "admin" ? "user" : role;
|
|
53
|
-
const response = await fetch(`${baseURL}/${roleForEndpoint}s/refresh-token`, {
|
|
54
|
-
method: 'POST',
|
|
55
|
-
credentials: 'include',
|
|
56
|
-
});
|
|
57
|
-
const data = await response.json();
|
|
58
|
-
if (response.ok) {
|
|
59
|
-
return customFetch(input, method, body, { includeAuth: true, retry: false });
|
|
60
|
-
}
|
|
61
|
-
else {
|
|
62
|
-
throw { statusCode: 401, error: data.error };
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
catch (error) {
|
|
66
|
-
throw new ApiError(error.statusCode ?? 500, error.error);
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
// ✅ Sever-safe exported functions
|
|
70
|
-
export async function get(url, includeAuth = true) {
|
|
71
|
-
return customFetch(url, 'GET', undefined, { includeAuth });
|
|
72
|
-
}
|
|
73
|
-
export async function post(url, body) {
|
|
74
|
-
return customFetch(url, 'POST', body, { includeAuth: true });
|
|
75
|
-
}
|
|
76
|
-
export async function put(url, body) {
|
|
77
|
-
return customFetch(url, 'PUT', body, { includeAuth: true });
|
|
78
|
-
}
|
|
79
|
-
export async function patch(url, body) {
|
|
80
|
-
return customFetch(url, 'PATCH', body, { includeAuth: true });
|
|
81
|
-
}
|
|
82
|
-
export async function del(url, body) {
|
|
83
|
-
return customFetch(url, 'DELETE', body, { includeAuth: true });
|
|
84
|
-
}
|