@myrjfa/state 1.0.7 → 1.0.8
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 +9 -4
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +9 -4
- package/dist/lib/QueryProvider.d.ts +1 -1
- package/dist/lib/QueryProvider.d.ts.map +1 -1
- package/dist/lib/actions/actions.d.ts +141 -0
- package/dist/lib/actions/actions.d.ts.map +1 -0
- package/dist/lib/actions/actions.js +307 -0
- package/dist/lib/actions/auth.d.ts +150 -0
- package/dist/lib/actions/auth.d.ts.map +1 -0
- package/dist/lib/actions/auth.js +125 -0
- package/dist/lib/actions/chat.d.ts +48 -0
- package/dist/lib/actions/chat.d.ts.map +1 -0
- package/dist/lib/actions/chat.js +303 -0
- package/dist/lib/actions/fetcher.d.ts +9 -0
- package/dist/lib/actions/fetcher.d.ts.map +1 -0
- package/dist/lib/actions/fetcher.js +84 -0
- package/dist/lib/actions/severActions.d.ts +3 -0
- package/dist/lib/actions/severActions.d.ts.map +1 -0
- package/dist/lib/actions/severActions.js +19 -0
- package/dist/lib/actions/socket.d.ts +7 -0
- package/dist/lib/actions/socket.d.ts.map +1 -0
- package/dist/lib/actions/socket.js +22 -0
- package/dist/lib/actions.d.ts +3 -3
- package/dist/lib/actions.d.ts.map +1 -1
- package/dist/lib/actions.js +2 -2
- package/dist/lib/authSessionManager.js +1 -1
- package/dist/lib/context/ChatContext.d.ts +25 -0
- package/dist/lib/context/ChatContext.d.ts.map +1 -0
- package/dist/lib/context/ChatContext.js +229 -0
- package/dist/lib/hooks/useChatSocket.d.ts +6 -0
- package/dist/lib/hooks/useChatSocket.d.ts.map +1 -0
- package/dist/lib/hooks/useChatSocket.js +35 -0
- package/dist/lib/models/chat.d.ts +122 -0
- package/dist/lib/models/chat.d.ts.map +1 -0
- package/dist/lib/models/chat.js +1 -0
- package/dist/lib/models/props.d.ts.map +1 -1
- package/dist/lib/models/props.js +1 -0
- package/dist/lib/socket.d.ts +7 -0
- package/dist/lib/socket.d.ts.map +1 -0
- package/dist/lib/socket.js +22 -0
- package/dist/lib/userAtom.js +2 -2
- package/package.json +4 -2
|
@@ -0,0 +1,125 @@
|
|
|
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
|
+
}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { Message } from "../models/chat";
|
|
2
|
+
export declare const chatApi: {
|
|
3
|
+
getConversations: () => Promise<any[]>;
|
|
4
|
+
getConversation: (id: string) => Promise<any>;
|
|
5
|
+
createConversation: (data: any) => Promise<any>;
|
|
6
|
+
updateConversation: (id: string, data: any) => Promise<any>;
|
|
7
|
+
deleteConversation: (id: string) => Promise<any>;
|
|
8
|
+
addParticipants: (id: string, userIds: string[]) => Promise<any>;
|
|
9
|
+
removeParticipant: (convId: string, userId: string) => Promise<any>;
|
|
10
|
+
updateParticipant: (convId: string, userId: string, data: any) => Promise<any>;
|
|
11
|
+
getMessages: (convId: string, params?: {
|
|
12
|
+
limit?: number;
|
|
13
|
+
before?: string;
|
|
14
|
+
}) => Promise<Message[]>;
|
|
15
|
+
getMessage: (convId: string, id: string) => Promise<{
|
|
16
|
+
error: string;
|
|
17
|
+
data: Message;
|
|
18
|
+
} | {
|
|
19
|
+
error: unknown;
|
|
20
|
+
data: null;
|
|
21
|
+
}>;
|
|
22
|
+
sendMessage: (convId: string, data: any) => Promise<any>;
|
|
23
|
+
editMessage: (id: string, text: string) => Promise<any>;
|
|
24
|
+
addMessageReaction: (id: string, emoji: string) => Promise<any>;
|
|
25
|
+
deleteMessage: (id: string) => Promise<any>;
|
|
26
|
+
addReaction: (id: string, emoji: string) => Promise<any>;
|
|
27
|
+
removeReaction: (id: string) => Promise<any>;
|
|
28
|
+
markRead: (convId: string, messageIds: string[]) => Promise<any>;
|
|
29
|
+
getMilestones: (convId: string) => Promise<any[]>;
|
|
30
|
+
createMilestone: (convId: string, data: any) => Promise<any>;
|
|
31
|
+
toggleMilestone: (id: string, note?: string) => Promise<any>;
|
|
32
|
+
updateMilestone: (id: string, data: any) => Promise<any>;
|
|
33
|
+
deleteMilestone: (id: string) => Promise<any>;
|
|
34
|
+
getExpenses: (convId: string) => Promise<any[]>;
|
|
35
|
+
createExpense: (convId: string, data: any) => Promise<any>;
|
|
36
|
+
updateExpense: (id: string, data: any) => Promise<any>;
|
|
37
|
+
settleSplit: (id: string, targetUserId: string) => Promise<any>;
|
|
38
|
+
deleteExpense: (id: string) => Promise<any>;
|
|
39
|
+
getBalances: (convId: string) => Promise<any>;
|
|
40
|
+
uploadFiles: (formData: FormData) => Promise<{
|
|
41
|
+
error: string;
|
|
42
|
+
data: any;
|
|
43
|
+
} | {
|
|
44
|
+
error: unknown;
|
|
45
|
+
data: null;
|
|
46
|
+
}>;
|
|
47
|
+
};
|
|
48
|
+
//# sourceMappingURL=chat.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"chat.d.ts","sourceRoot":"","sources":["../../../src/lib/actions/chat.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,gBAAgB,CAAC;AAKzC,eAAO,MAAM,OAAO;;0BAWY,MAAM;+BASD,GAAG;6BASL,MAAM,QAAQ,GAAG;6BASjB,MAAM;0BAST,MAAM,WAAW,MAAM,EAAE;gCASnB,MAAM,UAAU,MAAM;gCAStB,MAAM,UAAU,MAAM,QAAQ,GAAG;0BAWvC,MAAM,WAAW;QAAE,KAAK,CAAC,EAAE,MAAM,CAAC;QAAC,MAAM,CAAC,EAAE,MAAM,CAAA;KAAE;yBAYrD,MAAM,MAAM,MAAM;eAED,MAAM;cAAQ,OAAO;;;;;0BAOrC,MAAM,QAAQ,GAAG;sBASrB,MAAM,QAAQ,MAAM;6BASb,MAAM,SAAS,MAAM;wBAS1B,MAAM;sBASR,MAAM,SAAS,MAAM;yBASlB,MAAM;uBASR,MAAM,cAAc,MAAM,EAAE;4BAWvB,MAAM;8BASJ,MAAM,QAAQ,GAAG;0BASrB,MAAM,SAAS,MAAM;0BASrB,MAAM,QAAQ,GAAG;0BASjB,MAAM;0BAWN,MAAM;4BASJ,MAAM,QAAQ,GAAG;wBASrB,MAAM,QAAQ,GAAG;sBASnB,MAAM,gBAAgB,MAAM;wBAS1B,MAAM;0BASJ,MAAM;4BASJ,QAAQ;eAEO,MAAM;cAAQ,GAAG;;;;;CAOjE,CAAC"}
|
|
@@ -0,0 +1,303 @@
|
|
|
1
|
+
import { get, post, patch, del } from "./fetcher";
|
|
2
|
+
const BASE_PATH = "/chat";
|
|
3
|
+
export const chatApi = {
|
|
4
|
+
// Conversations
|
|
5
|
+
getConversations: async () => {
|
|
6
|
+
try {
|
|
7
|
+
const response = await get(`${BASE_PATH}/conversations`);
|
|
8
|
+
return response.data;
|
|
9
|
+
}
|
|
10
|
+
catch (error) {
|
|
11
|
+
console.error(error);
|
|
12
|
+
return [];
|
|
13
|
+
}
|
|
14
|
+
},
|
|
15
|
+
getConversation: async (id) => {
|
|
16
|
+
try {
|
|
17
|
+
const response = await get(`${BASE_PATH}/conversations/${id}`);
|
|
18
|
+
return response.data;
|
|
19
|
+
}
|
|
20
|
+
catch (error) {
|
|
21
|
+
console.error(error);
|
|
22
|
+
return null;
|
|
23
|
+
}
|
|
24
|
+
},
|
|
25
|
+
createConversation: async (data) => {
|
|
26
|
+
try {
|
|
27
|
+
const response = await post(`${BASE_PATH}/conversations`, data);
|
|
28
|
+
return response.data;
|
|
29
|
+
}
|
|
30
|
+
catch (error) {
|
|
31
|
+
console.error(error);
|
|
32
|
+
return null;
|
|
33
|
+
}
|
|
34
|
+
},
|
|
35
|
+
updateConversation: async (id, data) => {
|
|
36
|
+
try {
|
|
37
|
+
const response = await patch(`${BASE_PATH}/conversations/${id}`, data);
|
|
38
|
+
return response.data;
|
|
39
|
+
}
|
|
40
|
+
catch (error) {
|
|
41
|
+
console.error(error);
|
|
42
|
+
return null;
|
|
43
|
+
}
|
|
44
|
+
},
|
|
45
|
+
deleteConversation: async (id) => {
|
|
46
|
+
try {
|
|
47
|
+
const response = await del(`${BASE_PATH}/conversations/${id}`);
|
|
48
|
+
return response.data;
|
|
49
|
+
}
|
|
50
|
+
catch (error) {
|
|
51
|
+
console.error(error);
|
|
52
|
+
return null;
|
|
53
|
+
}
|
|
54
|
+
},
|
|
55
|
+
addParticipants: async (id, userIds) => {
|
|
56
|
+
try {
|
|
57
|
+
const response = await post(`${BASE_PATH}/conversations/${id}/participants`, { userIds });
|
|
58
|
+
return response.data;
|
|
59
|
+
}
|
|
60
|
+
catch (error) {
|
|
61
|
+
console.error(error);
|
|
62
|
+
return null;
|
|
63
|
+
}
|
|
64
|
+
},
|
|
65
|
+
removeParticipant: async (convId, userId) => {
|
|
66
|
+
try {
|
|
67
|
+
const response = await del(`${BASE_PATH}/conversations/${convId}/participants/${userId}`);
|
|
68
|
+
return response.data;
|
|
69
|
+
}
|
|
70
|
+
catch (error) {
|
|
71
|
+
console.error(error);
|
|
72
|
+
return null;
|
|
73
|
+
}
|
|
74
|
+
},
|
|
75
|
+
updateParticipant: async (convId, userId, data) => {
|
|
76
|
+
try {
|
|
77
|
+
const response = await patch(`${BASE_PATH}/conversations/${convId}/participants/${userId}`, data);
|
|
78
|
+
return response.data;
|
|
79
|
+
}
|
|
80
|
+
catch (error) {
|
|
81
|
+
console.error(error);
|
|
82
|
+
return null;
|
|
83
|
+
}
|
|
84
|
+
},
|
|
85
|
+
// Messages
|
|
86
|
+
getMessages: async (convId, params) => {
|
|
87
|
+
try {
|
|
88
|
+
const qs = new URLSearchParams();
|
|
89
|
+
if (params?.limit)
|
|
90
|
+
qs.set("limit", String(params.limit));
|
|
91
|
+
if (params?.before)
|
|
92
|
+
qs.set("before", params.before);
|
|
93
|
+
const response = await get(`${BASE_PATH}/conversations/${convId}/messages?${qs.toString()}`);
|
|
94
|
+
return response.data;
|
|
95
|
+
}
|
|
96
|
+
catch (error) {
|
|
97
|
+
console.error(error);
|
|
98
|
+
return [];
|
|
99
|
+
}
|
|
100
|
+
},
|
|
101
|
+
getMessage: async (convId, id) => {
|
|
102
|
+
try {
|
|
103
|
+
const response = await get(`${BASE_PATH}/conversations/${convId}/messages${id}`);
|
|
104
|
+
return response;
|
|
105
|
+
}
|
|
106
|
+
catch (error) {
|
|
107
|
+
console.error(error);
|
|
108
|
+
return { error: error, data: null };
|
|
109
|
+
}
|
|
110
|
+
},
|
|
111
|
+
sendMessage: async (convId, data) => {
|
|
112
|
+
try {
|
|
113
|
+
const response = await post(`${BASE_PATH}/conversations/${convId}/messages`, data);
|
|
114
|
+
return response.data;
|
|
115
|
+
}
|
|
116
|
+
catch (error) {
|
|
117
|
+
console.error(error);
|
|
118
|
+
return null;
|
|
119
|
+
}
|
|
120
|
+
},
|
|
121
|
+
editMessage: async (id, text) => {
|
|
122
|
+
try {
|
|
123
|
+
const response = await patch(`${BASE_PATH}/messages/${id}`, { text });
|
|
124
|
+
return response.data;
|
|
125
|
+
}
|
|
126
|
+
catch (error) {
|
|
127
|
+
console.error(error);
|
|
128
|
+
return null;
|
|
129
|
+
}
|
|
130
|
+
},
|
|
131
|
+
addMessageReaction: async (id, emoji) => {
|
|
132
|
+
try {
|
|
133
|
+
const response = await patch(`${BASE_PATH}/messages/${id}/reactions`, { emoji });
|
|
134
|
+
return response.data;
|
|
135
|
+
}
|
|
136
|
+
catch (error) {
|
|
137
|
+
console.error(error);
|
|
138
|
+
return null;
|
|
139
|
+
}
|
|
140
|
+
},
|
|
141
|
+
deleteMessage: async (id) => {
|
|
142
|
+
try {
|
|
143
|
+
const response = await del(`${BASE_PATH}/messages/${id}`);
|
|
144
|
+
return response.data;
|
|
145
|
+
}
|
|
146
|
+
catch (error) {
|
|
147
|
+
console.error(error);
|
|
148
|
+
return null;
|
|
149
|
+
}
|
|
150
|
+
},
|
|
151
|
+
addReaction: async (id, emoji) => {
|
|
152
|
+
try {
|
|
153
|
+
const response = await post(`${BASE_PATH}/messages/${id}/reactions`, { emoji });
|
|
154
|
+
return response.data;
|
|
155
|
+
}
|
|
156
|
+
catch (error) {
|
|
157
|
+
console.error(error);
|
|
158
|
+
return null;
|
|
159
|
+
}
|
|
160
|
+
},
|
|
161
|
+
removeReaction: async (id) => {
|
|
162
|
+
try {
|
|
163
|
+
const response = await del(`${BASE_PATH}/messages/${id}/reactions`);
|
|
164
|
+
return response.data;
|
|
165
|
+
}
|
|
166
|
+
catch (error) {
|
|
167
|
+
console.error(error);
|
|
168
|
+
return null;
|
|
169
|
+
}
|
|
170
|
+
},
|
|
171
|
+
markRead: async (convId, messageIds) => {
|
|
172
|
+
try {
|
|
173
|
+
const response = await post(`${BASE_PATH}/conversations/${convId}/messages/read`, { messageIds });
|
|
174
|
+
return response.data;
|
|
175
|
+
}
|
|
176
|
+
catch (error) {
|
|
177
|
+
console.error(error);
|
|
178
|
+
return null;
|
|
179
|
+
}
|
|
180
|
+
},
|
|
181
|
+
// Milestones
|
|
182
|
+
getMilestones: async (convId) => {
|
|
183
|
+
try {
|
|
184
|
+
const response = await get(`${BASE_PATH}/conversations/${convId}/milestones`);
|
|
185
|
+
return response.data;
|
|
186
|
+
}
|
|
187
|
+
catch (error) {
|
|
188
|
+
console.error(error);
|
|
189
|
+
return [];
|
|
190
|
+
}
|
|
191
|
+
},
|
|
192
|
+
createMilestone: async (convId, data) => {
|
|
193
|
+
try {
|
|
194
|
+
const response = await post(`${BASE_PATH}/conversations/${convId}/milestones`, data);
|
|
195
|
+
return response.data;
|
|
196
|
+
}
|
|
197
|
+
catch (error) {
|
|
198
|
+
console.error(error);
|
|
199
|
+
return null;
|
|
200
|
+
}
|
|
201
|
+
},
|
|
202
|
+
toggleMilestone: async (id, note) => {
|
|
203
|
+
try {
|
|
204
|
+
const response = await patch(`${BASE_PATH}/milestones/${id}/toggle`, { note });
|
|
205
|
+
return response.data;
|
|
206
|
+
}
|
|
207
|
+
catch (error) {
|
|
208
|
+
console.error(error);
|
|
209
|
+
return null;
|
|
210
|
+
}
|
|
211
|
+
},
|
|
212
|
+
updateMilestone: async (id, data) => {
|
|
213
|
+
try {
|
|
214
|
+
const response = await patch(`${BASE_PATH}/milestones/${id}`, data);
|
|
215
|
+
return response.data;
|
|
216
|
+
}
|
|
217
|
+
catch (error) {
|
|
218
|
+
console.error(error);
|
|
219
|
+
return null;
|
|
220
|
+
}
|
|
221
|
+
},
|
|
222
|
+
deleteMilestone: async (id) => {
|
|
223
|
+
try {
|
|
224
|
+
const response = await del(`${BASE_PATH}/milestones/${id}`);
|
|
225
|
+
return response.data;
|
|
226
|
+
}
|
|
227
|
+
catch (error) {
|
|
228
|
+
console.error(error);
|
|
229
|
+
return null;
|
|
230
|
+
}
|
|
231
|
+
},
|
|
232
|
+
// Expenses
|
|
233
|
+
getExpenses: async (convId) => {
|
|
234
|
+
try {
|
|
235
|
+
const response = await get(`${BASE_PATH}/conversations/${convId}/expenses`);
|
|
236
|
+
return response.data;
|
|
237
|
+
}
|
|
238
|
+
catch (error) {
|
|
239
|
+
console.error(error);
|
|
240
|
+
return [];
|
|
241
|
+
}
|
|
242
|
+
},
|
|
243
|
+
createExpense: async (convId, data) => {
|
|
244
|
+
try {
|
|
245
|
+
const response = await post(`${BASE_PATH}/conversations/${convId}/expenses`, data);
|
|
246
|
+
return response.data;
|
|
247
|
+
}
|
|
248
|
+
catch (error) {
|
|
249
|
+
console.error(error);
|
|
250
|
+
return null;
|
|
251
|
+
}
|
|
252
|
+
},
|
|
253
|
+
updateExpense: async (id, data) => {
|
|
254
|
+
try {
|
|
255
|
+
const response = await patch(`${BASE_PATH}/expenses/${id}`, data);
|
|
256
|
+
return response.data;
|
|
257
|
+
}
|
|
258
|
+
catch (error) {
|
|
259
|
+
console.error(error);
|
|
260
|
+
return null;
|
|
261
|
+
}
|
|
262
|
+
},
|
|
263
|
+
settleSplit: async (id, targetUserId) => {
|
|
264
|
+
try {
|
|
265
|
+
const response = await post(`${BASE_PATH}/expenses/${id}/settle`, { targetUserId });
|
|
266
|
+
return response.data;
|
|
267
|
+
}
|
|
268
|
+
catch (error) {
|
|
269
|
+
console.error(error);
|
|
270
|
+
return null;
|
|
271
|
+
}
|
|
272
|
+
},
|
|
273
|
+
deleteExpense: async (id) => {
|
|
274
|
+
try {
|
|
275
|
+
const response = await del(`${BASE_PATH}/expenses/${id}`);
|
|
276
|
+
return response.data;
|
|
277
|
+
}
|
|
278
|
+
catch (error) {
|
|
279
|
+
console.error(error);
|
|
280
|
+
return null;
|
|
281
|
+
}
|
|
282
|
+
},
|
|
283
|
+
getBalances: async (convId) => {
|
|
284
|
+
try {
|
|
285
|
+
const response = await get(`${BASE_PATH}/conversations/${convId}/balances`);
|
|
286
|
+
return response.data;
|
|
287
|
+
}
|
|
288
|
+
catch (error) {
|
|
289
|
+
console.error(error);
|
|
290
|
+
return null;
|
|
291
|
+
}
|
|
292
|
+
},
|
|
293
|
+
uploadFiles: async (formData) => {
|
|
294
|
+
try {
|
|
295
|
+
const response = await post(`${BASE_PATH}/upload`, formData);
|
|
296
|
+
return response;
|
|
297
|
+
}
|
|
298
|
+
catch (error) {
|
|
299
|
+
console.error(error);
|
|
300
|
+
return { error: error, data: null };
|
|
301
|
+
}
|
|
302
|
+
},
|
|
303
|
+
};
|
|
@@ -0,0 +1,9 @@
|
|
|
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
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fetcher.d.ts","sourceRoot":"","sources":["../../../src/lib/actions/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"}
|
|
@@ -0,0 +1,84 @@
|
|
|
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
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"severActions.d.ts","sourceRoot":"","sources":["../../../src/lib/actions/severActions.ts"],"names":[],"mappings":"AAKA,wBAAsB,eAAe,IAAI,OAAO,CAAC,MAAM,CAAC,CAKvD;AAED,wBAAsB,OAAO,IAAI,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,CAQtD"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
'use server';
|
|
2
|
+
import { cookies } from 'next/headers';
|
|
3
|
+
import { validRoles } from '../utils';
|
|
4
|
+
export async function getCookieHeader() {
|
|
5
|
+
const cookieStore = await cookies();
|
|
6
|
+
return Array.from(cookieStore)
|
|
7
|
+
.map(([name, cookie]) => `${name}=${cookie.value}`)
|
|
8
|
+
.join('; ');
|
|
9
|
+
}
|
|
10
|
+
export async function getRole() {
|
|
11
|
+
try {
|
|
12
|
+
const role = (await cookies()).get("role")?.value ?? null;
|
|
13
|
+
return (role && validRoles.includes(role)) ? role : null;
|
|
14
|
+
}
|
|
15
|
+
catch (err) {
|
|
16
|
+
console.error('Invalid token', err);
|
|
17
|
+
return null;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { Socket } from "socket.io-client";
|
|
2
|
+
import { type PrimitiveAtom } from "jotai";
|
|
3
|
+
export declare const socketAtom: PrimitiveAtom<Socket | null>;
|
|
4
|
+
export declare const isConnectedAtom: PrimitiveAtom<boolean>;
|
|
5
|
+
export declare const getSocket: () => Socket;
|
|
6
|
+
export declare const disconnectSocket: () => void;
|
|
7
|
+
//# sourceMappingURL=socket.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"socket.d.ts","sourceRoot":"","sources":["../../../src/lib/actions/socket.ts"],"names":[],"mappings":"AAAA,OAAO,EAAM,MAAM,EAAE,MAAM,kBAAkB,CAAC;AAC9C,OAAO,EAAQ,KAAK,aAAa,EAAE,MAAM,OAAO,CAAC;AAMjD,eAAO,MAAM,UAAU,EAAE,aAAa,CAAC,MAAM,GAAG,IAAI,CAA6B,CAAC;AAClF,eAAO,MAAM,eAAe,EAAE,aAAa,CAAC,OAAO,CAAwB,CAAC;AAE5E,eAAO,MAAM,SAAS,QAAO,MAS5B,CAAC;AAEF,eAAO,MAAM,gBAAgB,YAK5B,CAAA"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { io } from "socket.io-client";
|
|
2
|
+
import { atom } from "jotai";
|
|
3
|
+
const SOCKET_URL = process.env.NEXT_PUBLIC_BACKEND_URL;
|
|
4
|
+
let socket = null;
|
|
5
|
+
export const socketAtom = atom(null);
|
|
6
|
+
export const isConnectedAtom = atom(false);
|
|
7
|
+
export const getSocket = () => {
|
|
8
|
+
if (!socket) {
|
|
9
|
+
socket = io(SOCKET_URL, {
|
|
10
|
+
autoConnect: false,
|
|
11
|
+
withCredentials: true,
|
|
12
|
+
transports: ["websocket", "polling"],
|
|
13
|
+
});
|
|
14
|
+
}
|
|
15
|
+
return socket;
|
|
16
|
+
};
|
|
17
|
+
export const disconnectSocket = () => {
|
|
18
|
+
if (socket?.connected) {
|
|
19
|
+
socket.disconnect();
|
|
20
|
+
}
|
|
21
|
+
socket = null;
|
|
22
|
+
};
|
package/dist/lib/actions.d.ts
CHANGED
|
@@ -2,7 +2,7 @@ import { Review, reviewTargetType, reviewType } from "./models/review";
|
|
|
2
2
|
import { tileType } from "./models/tile";
|
|
3
3
|
import { User } from "./models/user";
|
|
4
4
|
export declare function getCurrentUser(): Promise<User | null>;
|
|
5
|
-
export declare function userDetails(
|
|
5
|
+
export declare function userDetails(query: string, role: "user" | "host" | "admin"): Promise<{
|
|
6
6
|
success: boolean;
|
|
7
7
|
user: User | null;
|
|
8
8
|
message?: string;
|
|
@@ -84,9 +84,9 @@ export declare function getAllNotifications(): Promise<{
|
|
|
84
84
|
success: boolean;
|
|
85
85
|
message: string;
|
|
86
86
|
notifs: {
|
|
87
|
-
message: string;
|
|
88
87
|
_id: string;
|
|
89
88
|
userId: string;
|
|
89
|
+
message: string;
|
|
90
90
|
timestamp: Date;
|
|
91
91
|
read: boolean;
|
|
92
92
|
url?: string | undefined;
|
|
@@ -104,9 +104,9 @@ export declare function getNotifications(limit: number): Promise<{
|
|
|
104
104
|
success: boolean;
|
|
105
105
|
message: string;
|
|
106
106
|
notifs: {
|
|
107
|
-
message: string;
|
|
108
107
|
_id: string;
|
|
109
108
|
userId: string;
|
|
109
|
+
message: string;
|
|
110
110
|
timestamp: Date;
|
|
111
111
|
read: boolean;
|
|
112
112
|
url?: string | undefined;
|