@myrjfa/state 1.1.0 → 1.1.2
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 +3 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -2
- package/dist/lib/actions/actions.d.ts +56 -7
- package/dist/lib/actions/actions.d.ts.map +1 -1
- package/dist/lib/actions/actions.js +50 -10
- package/dist/lib/actions/auth.d.ts +12 -2
- package/dist/lib/actions/auth.d.ts.map +1 -1
- package/dist/lib/actions/chat.d.ts +80 -11
- package/dist/lib/actions/chat.d.ts.map +1 -1
- package/dist/lib/actions/chat.js +81 -20
- package/dist/lib/actions/fetcher.d.ts +0 -3
- package/dist/lib/actions/fetcher.d.ts.map +1 -1
- package/dist/lib/actions/fetcher.js +44 -6
- package/dist/lib/{severActions.d.ts → actions/serverActions.d.ts} +1 -1
- package/dist/lib/actions/serverActions.d.ts.map +1 -0
- package/dist/lib/actions/{severActions.js → serverActions.js} +3 -0
- package/dist/lib/actions/user.d.ts +23 -0
- package/dist/lib/actions/user.d.ts.map +1 -0
- package/dist/lib/actions/user.js +55 -0
- package/dist/lib/authSessionManager.d.ts.map +1 -1
- package/dist/lib/authSessionManager.js +14 -7
- package/dist/lib/context/ChatContext.d.ts +7 -0
- package/dist/lib/context/ChatContext.d.ts.map +1 -1
- package/dist/lib/context/ChatContext.js +121 -11
- package/dist/lib/models/blog.d.ts +3 -2
- package/dist/lib/models/blog.d.ts.map +1 -1
- package/dist/lib/models/chat.d.ts +32 -7
- package/dist/lib/models/chat.d.ts.map +1 -1
- package/dist/lib/models/notifications.d.ts +94 -0
- package/dist/lib/models/notifications.d.ts.map +1 -0
- package/dist/lib/models/notifications.js +60 -0
- package/dist/lib/models/opportunities/freelance.d.ts +48 -20
- package/dist/lib/models/opportunities/freelance.d.ts.map +1 -1
- package/dist/lib/models/opportunities/internship.d.ts +48 -20
- package/dist/lib/models/opportunities/internship.d.ts.map +1 -1
- package/dist/lib/models/opportunities/job.d.ts +58 -30
- package/dist/lib/models/opportunities/job.d.ts.map +1 -1
- package/dist/lib/models/opportunities/opportunity.d.ts +61 -33
- package/dist/lib/models/opportunities/opportunity.d.ts.map +1 -1
- package/dist/lib/models/opportunities/opportunity.js +1 -0
- package/dist/lib/models/opportunities/volunteerJob.d.ts +48 -20
- package/dist/lib/models/opportunities/volunteerJob.d.ts.map +1 -1
- package/dist/lib/models/portfolio.d.ts +2 -2
- package/dist/lib/models/props.d.ts +21 -4
- package/dist/lib/models/props.d.ts.map +1 -1
- package/dist/lib/models/user.d.ts +19 -4
- package/dist/lib/models/user.d.ts.map +1 -1
- package/dist/lib/models/user.js +5 -0
- package/dist/lib/userAtom.d.ts +24 -4
- package/dist/lib/userAtom.d.ts.map +1 -1
- package/dist/lib/userAtom.js +13 -11
- package/dist/lib/utils/fileCompression.d.ts +16 -0
- package/dist/lib/utils/fileCompression.d.ts.map +1 -0
- package/dist/lib/utils/fileCompression.js +56 -0
- package/dist/lib/utils/socialMediaUrl.d.ts +25 -0
- package/dist/lib/utils/socialMediaUrl.d.ts.map +1 -0
- package/dist/lib/utils/socialMediaUrl.js +97 -0
- package/dist/lib/utils.js +4 -4
- package/package.json +3 -1
- package/dist/lib/actions/severActions.d.ts +0 -3
- package/dist/lib/actions/severActions.d.ts.map +0 -1
- 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/notfications.d.ts +0 -26
- package/dist/lib/models/notfications.d.ts.map +0 -1
- package/dist/lib/models/notfications.js +0 -46
- 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.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/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
|
-
}
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
import { z } from "zod";
|
|
2
|
-
export declare const NotifSchema: z.ZodObject<{
|
|
3
|
-
_id: z.ZodString;
|
|
4
|
-
userId: z.ZodString;
|
|
5
|
-
message: z.ZodString;
|
|
6
|
-
timestamp: z.ZodDate;
|
|
7
|
-
read: z.ZodBoolean;
|
|
8
|
-
url: z.ZodOptional<z.ZodString>;
|
|
9
|
-
}, "strict", z.ZodTypeAny, {
|
|
10
|
-
message: string;
|
|
11
|
-
_id: string;
|
|
12
|
-
userId: string;
|
|
13
|
-
timestamp: Date;
|
|
14
|
-
read: boolean;
|
|
15
|
-
url?: string | undefined;
|
|
16
|
-
}, {
|
|
17
|
-
message: string;
|
|
18
|
-
_id: string;
|
|
19
|
-
userId: string;
|
|
20
|
-
timestamp: Date;
|
|
21
|
-
read: boolean;
|
|
22
|
-
url?: string | undefined;
|
|
23
|
-
}>;
|
|
24
|
-
export type Notif = z.infer<typeof NotifSchema>;
|
|
25
|
-
export declare const sampleNotifications: Notif[];
|
|
26
|
-
//# sourceMappingURL=notfications.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"notfications.d.ts","sourceRoot":"","sources":["../../../src/lib/models/notfications.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,eAAO,MAAM,WAAW;;;;;;;;;;;;;;;;;;;;;EAOb,CAAC;AAEZ,MAAM,MAAM,KAAK,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,WAAW,CAAC,CAAC;AAEhD,eAAO,MAAM,mBAAmB,EAAE,KAAK,EAoCtC,CAAC"}
|
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
import { z } from "zod";
|
|
2
|
-
export const NotifSchema = z.object({
|
|
3
|
-
_id: z.string(),
|
|
4
|
-
userId: z.string(),
|
|
5
|
-
message: z.string(),
|
|
6
|
-
timestamp: z.date(),
|
|
7
|
-
read: z.boolean(),
|
|
8
|
-
url: z.string().optional(),
|
|
9
|
-
}).strict();
|
|
10
|
-
export const sampleNotifications = [
|
|
11
|
-
{
|
|
12
|
-
_id: "1",
|
|
13
|
-
userId: "chintu",
|
|
14
|
-
message: "Congrats, your application to Kerala Co is approved",
|
|
15
|
-
timestamp: new Date(Date.now() - 1000 * 60 * 10), // 10 minutes ago
|
|
16
|
-
read: false,
|
|
17
|
-
},
|
|
18
|
-
{
|
|
19
|
-
_id: "2",
|
|
20
|
-
userId: "chintu",
|
|
21
|
-
message: "Your application to Manali is pending",
|
|
22
|
-
timestamp: new Date(Date.now() - 1000 * 60 * 60), // 1 hour ago
|
|
23
|
-
read: false,
|
|
24
|
-
},
|
|
25
|
-
{
|
|
26
|
-
_id: "3",
|
|
27
|
-
userId: "chintu",
|
|
28
|
-
message: "You got a review from the host",
|
|
29
|
-
timestamp: new Date(Date.now() - 1000 * 60 * 60 * 5), // 5 hours ago
|
|
30
|
-
read: true,
|
|
31
|
-
},
|
|
32
|
-
{
|
|
33
|
-
_id: "4",
|
|
34
|
-
userId: "chintu",
|
|
35
|
-
message: "Reminder: Your trip to Goa starts in 2 days",
|
|
36
|
-
timestamp: new Date(Date.now() - 1000 * 60 * 60 * 24), // 1 day ago
|
|
37
|
-
read: false,
|
|
38
|
-
},
|
|
39
|
-
{
|
|
40
|
-
_id: "5",
|
|
41
|
-
userId: "chintu",
|
|
42
|
-
message: "Your payment for the Shimla stay is confirmed",
|
|
43
|
-
timestamp: new Date(Date.now() - 1000 * 60 * 60 * 24 * 2), // 2 days ago
|
|
44
|
-
read: true,
|
|
45
|
-
}
|
|
46
|
-
];
|