@myrjfa/state 2.1.3 → 2.1.5
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/lib/actions/actions.d.ts +10 -8
- package/dist/lib/actions/actions.d.ts.map +1 -1
- package/dist/lib/actions/actions.js +13 -5
- package/dist/lib/actions/fetcher.d.ts.map +1 -1
- package/dist/lib/actions/fetcher.js +31 -29
- package/dist/lib/authSessionManager.d.ts.map +1 -1
- package/dist/lib/authSessionManager.js +12 -18
- package/dist/lib/models/notifications.d.ts +20 -15
- package/dist/lib/models/notifications.d.ts.map +1 -1
- package/dist/lib/models/notifications.js +4 -1
- package/dist/lib/models/opportunities/freelance.d.ts +82 -82
- package/dist/lib/models/opportunities/internship.d.ts +82 -82
- package/dist/lib/models/opportunities/job.d.ts +82 -82
- package/dist/lib/models/opportunities/opportunity.d.ts +82 -82
- package/dist/lib/models/opportunities/volunteerJob.d.ts +82 -82
- package/dist/lib/models/props.d.ts +13 -2
- package/dist/lib/models/props.d.ts.map +1 -1
- package/dist/lib/models/props.js +20 -0
- package/dist/lib/userAtom.d.ts +48 -48
- package/package.json +1 -1
|
@@ -93,16 +93,18 @@ export declare function getAllNotifications(): Promise<{
|
|
|
93
93
|
success: boolean;
|
|
94
94
|
message: string;
|
|
95
95
|
notifs: {
|
|
96
|
-
_id: string;
|
|
97
96
|
message: string;
|
|
97
|
+
_id: string;
|
|
98
98
|
read: boolean;
|
|
99
|
-
type?: "new_message" | "milestone_completed" | "expense_added" | "group_invite" | "mention" | "application_received" | "application_status" | "application_shortlisted" | "id_verification_request" | "id_verified" | "id_rejected" | "package_enquiry" | "package_approval" | "package_denial" | "package_rating" | "package_review" | "opportunity_assigned" | "opportunity_approval" | "opportunity_denial" | "opportunity_rating" | "opportunity_review" | "blog_like" | "blog_comment" | "blog_posted" | "blog_approval" | "blog_denial" | "system" | "general" | undefined;
|
|
99
|
+
type?: "new_message" | "milestone_completed" | "expense_added" | "group_invite" | "mention" | "application_received" | "application_status" | "application_shortlisted" | "id_verification_request" | "id_verified" | "id_rejected" | "package_enquiry" | "package_approval" | "package_denial" | "package_rating" | "package_review" | "opportunity_assigned" | "opportunity_approval" | "opportunity_denial" | "opportunity_rating" | "opportunity_review" | "blog_like" | "blog_comment" | "blog_posted" | "blog_approval" | "blog_denial" | "booking_confirmed" | "system" | "general" | undefined;
|
|
100
100
|
userId?: string | undefined;
|
|
101
101
|
timestamp?: any;
|
|
102
102
|
link?: string | undefined;
|
|
103
|
-
category?: "opportunity" | "package" | "blog" | "system" | "general" | "chat" | "application" | "account" | undefined;
|
|
103
|
+
category?: "opportunity" | "package" | "blog" | "system" | "general" | "chat" | "application" | "account" | "booking" | undefined;
|
|
104
104
|
metadata?: {
|
|
105
105
|
status?: string | undefined;
|
|
106
|
+
title?: string | undefined;
|
|
107
|
+
rating?: number | undefined;
|
|
106
108
|
conversationId?: string | undefined;
|
|
107
109
|
messageId?: string | undefined;
|
|
108
110
|
senderId?: string | undefined;
|
|
@@ -112,7 +114,6 @@ export declare function getAllNotifications(): Promise<{
|
|
|
112
114
|
expenseId?: string | undefined;
|
|
113
115
|
referenceId?: string | undefined;
|
|
114
116
|
referenceType?: string | undefined;
|
|
115
|
-
title?: string | undefined;
|
|
116
117
|
} | undefined;
|
|
117
118
|
}[];
|
|
118
119
|
unreadCount: number;
|
|
@@ -128,16 +129,18 @@ export declare function getNotifications(limit: number): Promise<{
|
|
|
128
129
|
success: boolean;
|
|
129
130
|
message: string;
|
|
130
131
|
notifs: {
|
|
131
|
-
_id: string;
|
|
132
132
|
message: string;
|
|
133
|
+
_id: string;
|
|
133
134
|
read: boolean;
|
|
134
|
-
type?: "new_message" | "milestone_completed" | "expense_added" | "group_invite" | "mention" | "application_received" | "application_status" | "application_shortlisted" | "id_verification_request" | "id_verified" | "id_rejected" | "package_enquiry" | "package_approval" | "package_denial" | "package_rating" | "package_review" | "opportunity_assigned" | "opportunity_approval" | "opportunity_denial" | "opportunity_rating" | "opportunity_review" | "blog_like" | "blog_comment" | "blog_posted" | "blog_approval" | "blog_denial" | "system" | "general" | undefined;
|
|
135
|
+
type?: "new_message" | "milestone_completed" | "expense_added" | "group_invite" | "mention" | "application_received" | "application_status" | "application_shortlisted" | "id_verification_request" | "id_verified" | "id_rejected" | "package_enquiry" | "package_approval" | "package_denial" | "package_rating" | "package_review" | "opportunity_assigned" | "opportunity_approval" | "opportunity_denial" | "opportunity_rating" | "opportunity_review" | "blog_like" | "blog_comment" | "blog_posted" | "blog_approval" | "blog_denial" | "booking_confirmed" | "system" | "general" | undefined;
|
|
135
136
|
userId?: string | undefined;
|
|
136
137
|
timestamp?: any;
|
|
137
138
|
link?: string | undefined;
|
|
138
|
-
category?: "opportunity" | "package" | "blog" | "system" | "general" | "chat" | "application" | "account" | undefined;
|
|
139
|
+
category?: "opportunity" | "package" | "blog" | "system" | "general" | "chat" | "application" | "account" | "booking" | undefined;
|
|
139
140
|
metadata?: {
|
|
140
141
|
status?: string | undefined;
|
|
142
|
+
title?: string | undefined;
|
|
143
|
+
rating?: number | undefined;
|
|
141
144
|
conversationId?: string | undefined;
|
|
142
145
|
messageId?: string | undefined;
|
|
143
146
|
senderId?: string | undefined;
|
|
@@ -147,7 +150,6 @@ export declare function getNotifications(limit: number): Promise<{
|
|
|
147
150
|
expenseId?: string | undefined;
|
|
148
151
|
referenceId?: string | undefined;
|
|
149
152
|
referenceType?: string | undefined;
|
|
150
|
-
title?: string | undefined;
|
|
151
153
|
} | undefined;
|
|
152
154
|
}[];
|
|
153
155
|
unreadCount: number;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"actions.d.ts","sourceRoot":"","sources":["../../../src/lib/actions/actions.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,MAAM,EAAE,gBAAgB,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AACxE,OAAO,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAC1C,OAAO,EAAE,IAAI,EAAE,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,CAAC,CAiBzJ;AAED,wBAAsB,YAAY,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC;IAAE,OAAO,EAAE,OAAO,CAAC;IAAC,OAAO,CAAC,EAAE,MAAM,CAAC;IAAC,KAAK,CAAC,EAAE,MAAM,CAAA;CAAE,CAAC,CAe9G;AAGD,wBAAsB,mBAAmB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAmBxC;AAED,wBAAsB,gBAAgB,CAAC,KAAK,EAAE,MAAM;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAmBnD;AAED,wBAAsB,kBAAkB,CAAC,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE,OAAO;;;;;;;;GAejE;AAED,wBAAsB,qBAAqB,CAAC,IAAI,EAAE,OAAO;;;;;;;;GAexD;AAGD,wBAAsB,SAAS,CAAC,OAAO,EAAE;IACrC,QAAQ,EAAE,MAAM,CAAC;IACjB,UAAU,CAAC,EAAE,QAAQ,CAAC;IACtB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,WAAW,CAAC,EAAE,MAAM,CAAC;CACxB,GAAG,OAAO,CAAC,IAAI,CAAC,CAMhB;AAGD,wBAAsB,qBAAqB,CAAC,IAAI,EAAE,QAAQ,GAAG,OAAO,CAAC;IAAE,OAAO,EAAE,OAAO,CAAC;IAAC,KAAK,CAAC,EAAE,MAAM,CAAA;CAAE,CAAC,CAgBzG"}
|
|
@@ -12,7 +12,9 @@ export async function getCurrentUser() {
|
|
|
12
12
|
if (error && typeof error === 'object' && ('$$typeof' in error || error.digest === 'DYNAMIC_SERVER_USAGE')) {
|
|
13
13
|
throw error; // Re-throw Next.js PPR bail-out
|
|
14
14
|
}
|
|
15
|
-
|
|
15
|
+
if (error?.statusCode !== 401) {
|
|
16
|
+
console.error('Failed to fetch user details: ', error);
|
|
17
|
+
}
|
|
16
18
|
return null;
|
|
17
19
|
}
|
|
18
20
|
}
|
|
@@ -332,12 +334,18 @@ export async function callAlert(payload) {
|
|
|
332
334
|
// Non-fatal — silently ignore
|
|
333
335
|
}
|
|
334
336
|
}
|
|
335
|
-
// #6 —
|
|
337
|
+
// #6 — Interest request for any listing type
|
|
336
338
|
export async function submitInterestRequest(data) {
|
|
337
339
|
try {
|
|
338
|
-
const
|
|
339
|
-
|
|
340
|
-
: '/packages/interest'
|
|
340
|
+
const endpointMap = {
|
|
341
|
+
opportunity: '/newHostPost/interest',
|
|
342
|
+
package: '/packages/interest',
|
|
343
|
+
stay: '/stays/interest',
|
|
344
|
+
adventure: '/adventures/interest',
|
|
345
|
+
event: '/events/interest',
|
|
346
|
+
rental: '/rentals/interest',
|
|
347
|
+
};
|
|
348
|
+
const endpoint = endpointMap[data.type] ?? '/interest';
|
|
341
349
|
await post(endpoint, data);
|
|
342
350
|
return { success: true };
|
|
343
351
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fetcher.d.ts","sourceRoot":"","sources":["../../../src/lib/actions/fetcher.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"fetcher.d.ts","sourceRoot":"","sources":["../../../src/lib/actions/fetcher.ts"],"names":[],"mappings":"AAsKA,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"}
|
|
@@ -80,41 +80,43 @@ async function customFetch(input, method, body, options = {}) {
|
|
|
80
80
|
}
|
|
81
81
|
throw new ApiError(errorBody.statusCode, errorBody.error);
|
|
82
82
|
}
|
|
83
|
+
// Single in-flight refresh promise — prevents concurrent 401s from firing multiple refresh calls
|
|
84
|
+
let refreshPromise = null;
|
|
83
85
|
// Token refresh function — internal only, not exported
|
|
84
86
|
async function refreshToken(input, method, body) {
|
|
85
87
|
const role = await getRole();
|
|
86
88
|
// Map role to the correct refresh endpoint; fall back to 'user' if role is unavailable
|
|
87
89
|
const roleForEndpoint = (!role || role === "admin") ? "user" : role;
|
|
90
|
+
// Deduplicate: if a refresh is already in flight, wait for it rather than firing a second one
|
|
91
|
+
if (!refreshPromise) {
|
|
92
|
+
refreshPromise = (async () => {
|
|
93
|
+
const refreshHeaders = {};
|
|
94
|
+
// Always include device ID so backend can match the device record
|
|
95
|
+
const deviceId = getOrCreateDeviceId();
|
|
96
|
+
if (deviceId)
|
|
97
|
+
refreshHeaders['X-Device-Id'] = deviceId;
|
|
98
|
+
try {
|
|
99
|
+
const cookieHeader = await getCookieHeader();
|
|
100
|
+
if (cookieHeader)
|
|
101
|
+
refreshHeaders['Cookie'] = cookieHeader;
|
|
102
|
+
}
|
|
103
|
+
catch {
|
|
104
|
+
// CSR or static context — credentials:'include' handles cookie forwarding to backend
|
|
105
|
+
}
|
|
106
|
+
const response = await fetch(`${baseURL}/${roleForEndpoint}s/refresh-token`, {
|
|
107
|
+
method: 'POST',
|
|
108
|
+
credentials: 'include',
|
|
109
|
+
headers: refreshHeaders,
|
|
110
|
+
});
|
|
111
|
+
if (!response.ok) {
|
|
112
|
+
const data = await response.json();
|
|
113
|
+
throw { statusCode: response.status, error: data.error || data.message || 'Session expired' };
|
|
114
|
+
}
|
|
115
|
+
})().finally(() => { refreshPromise = null; });
|
|
116
|
+
}
|
|
88
117
|
try {
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
// In SSR, try to forward all cookies from the incoming request; in CSR, credentials:'include'
|
|
92
|
-
// sends them directly from the browser to the backend.
|
|
93
|
-
const refreshHeaders = {};
|
|
94
|
-
// Always include device ID so backend can match the device record
|
|
95
|
-
const deviceId = getOrCreateDeviceId();
|
|
96
|
-
if (deviceId)
|
|
97
|
-
refreshHeaders['X-Device-Id'] = deviceId;
|
|
98
|
-
try {
|
|
99
|
-
const cookieHeader = await getCookieHeader();
|
|
100
|
-
if (cookieHeader)
|
|
101
|
-
refreshHeaders['Cookie'] = cookieHeader;
|
|
102
|
-
}
|
|
103
|
-
catch {
|
|
104
|
-
// CSR or static context — credentials:'include' handles cookie forwarding to backend
|
|
105
|
-
}
|
|
106
|
-
const response = await fetch(`${baseURL}/${roleForEndpoint}s/refresh-token`, {
|
|
107
|
-
method: 'POST',
|
|
108
|
-
credentials: 'include',
|
|
109
|
-
headers: refreshHeaders,
|
|
110
|
-
});
|
|
111
|
-
const data = await response.json();
|
|
112
|
-
if (response.ok) {
|
|
113
|
-
return customFetch(input, method, body, { includeAuth: true, retry: false });
|
|
114
|
-
}
|
|
115
|
-
else {
|
|
116
|
-
throw { statusCode: response.status, error: data.error || data.message || 'Session expired' };
|
|
117
|
-
}
|
|
118
|
+
await refreshPromise;
|
|
119
|
+
return customFetch(input, method, body, { includeAuth: true, retry: false });
|
|
118
120
|
}
|
|
119
121
|
catch (error) {
|
|
120
122
|
if (error && typeof error === 'object' && ('$$typeof' in error || error.digest === 'DYNAMIC_SERVER_USAGE')) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"authSessionManager.d.ts","sourceRoot":"","sources":["../../src/lib/authSessionManager.tsx"],"names":[],"mappings":"AAQA,MAAM,CAAC,OAAO,UAAU,kBAAkB,
|
|
1
|
+
{"version":3,"file":"authSessionManager.d.ts","sourceRoot":"","sources":["../../src/lib/authSessionManager.tsx"],"names":[],"mappings":"AAQA,MAAM,CAAC,OAAO,UAAU,kBAAkB,SA+BzC"}
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
import { useAtom } from 'jotai'; // Import useSetAtom
|
|
3
3
|
import { useEffect } from 'react';
|
|
4
4
|
import { useQuery } from '@tanstack/react-query';
|
|
5
|
-
import { initializeAuthSessionAtom } from './userAtom'; // Import the atom itself
|
|
5
|
+
import { initializeAuthSessionAtom, resetAuthState } from './userAtom'; // Import the atom itself
|
|
6
6
|
import { validateSession } from './actions/auth';
|
|
7
7
|
export default function AuthSessionManager() {
|
|
8
8
|
const [, initializeAuthSession] = useAtom(initializeAuthSessionAtom);
|
|
@@ -11,31 +11,25 @@ export default function AuthSessionManager() {
|
|
|
11
11
|
initializeAuthSession();
|
|
12
12
|
}, [initializeAuthSession]);
|
|
13
13
|
// --- Continuous Background Re-validation ---
|
|
14
|
-
const {
|
|
14
|
+
const { error } = useQuery({
|
|
15
15
|
queryKey: ['session'],
|
|
16
16
|
queryFn: validateSession,
|
|
17
|
-
// --- Configuration for a seamless experience ---
|
|
18
17
|
refetchOnWindowFocus: true,
|
|
19
18
|
refetchOnReconnect: true,
|
|
20
|
-
retry
|
|
21
|
-
|
|
19
|
+
// Never retry on 401 — both tokens are gone, retrying just spams the backend
|
|
20
|
+
retry: (failureCount, err) => {
|
|
21
|
+
if (err?.statusCode === 401)
|
|
22
22
|
return false;
|
|
23
23
|
return failureCount < 2;
|
|
24
24
|
},
|
|
25
25
|
staleTime: 15 * 60 * 1000,
|
|
26
26
|
});
|
|
27
|
-
//
|
|
28
|
-
//
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
// useEffect(() => {
|
|
35
|
-
// if (isError) {
|
|
36
|
-
// console.log("Session validation failed. Logging out.");
|
|
37
|
-
// resetAuthState();
|
|
38
|
-
// }
|
|
39
|
-
// }, [isError, resetAuthState]);
|
|
27
|
+
// Clear auth state only when the backend explicitly says the session is invalid (401).
|
|
28
|
+
// Network errors or 5xx (backend down) are ignored to avoid false logouts.
|
|
29
|
+
useEffect(() => {
|
|
30
|
+
if (error?.statusCode === 401) {
|
|
31
|
+
resetAuthState();
|
|
32
|
+
}
|
|
33
|
+
}, [error]);
|
|
40
34
|
return null;
|
|
41
35
|
}
|
|
@@ -6,8 +6,8 @@ export declare const NotifSchema: z.ZodObject<{
|
|
|
6
6
|
timestamp: z.ZodAny;
|
|
7
7
|
read: z.ZodBoolean;
|
|
8
8
|
link: z.ZodOptional<z.ZodString>;
|
|
9
|
-
type: z.ZodOptional<z.ZodEnum<["new_message", "milestone_completed", "expense_added", "group_invite", "mention", "application_received", "application_status", "application_shortlisted", "id_verification_request", "id_verified", "id_rejected", "package_enquiry", "package_approval", "package_denial", "package_rating", "package_review", "opportunity_assigned", "opportunity_approval", "opportunity_denial", "opportunity_rating", "opportunity_review", "blog_like", "blog_comment", "blog_posted", "blog_approval", "blog_denial", "system", "general"]>>;
|
|
10
|
-
category: z.ZodOptional<z.ZodEnum<["chat", "application", "opportunity", "package", "blog", "account", "system", "general"]>>;
|
|
9
|
+
type: z.ZodOptional<z.ZodEnum<["new_message", "milestone_completed", "expense_added", "group_invite", "mention", "application_received", "application_status", "application_shortlisted", "id_verification_request", "id_verified", "id_rejected", "package_enquiry", "package_approval", "package_denial", "package_rating", "package_review", "opportunity_assigned", "opportunity_approval", "opportunity_denial", "opportunity_rating", "opportunity_review", "blog_like", "blog_comment", "blog_posted", "blog_approval", "blog_denial", "booking_confirmed", "system", "general"]>>;
|
|
10
|
+
category: z.ZodOptional<z.ZodEnum<["chat", "application", "opportunity", "package", "blog", "account", "system", "general", "booking"]>>;
|
|
11
11
|
metadata: z.ZodOptional<z.ZodObject<{
|
|
12
12
|
conversationId: z.ZodOptional<z.ZodString>;
|
|
13
13
|
messageId: z.ZodOptional<z.ZodString>;
|
|
@@ -20,9 +20,8 @@ export declare const NotifSchema: z.ZodObject<{
|
|
|
20
20
|
referenceType: z.ZodOptional<z.ZodString>;
|
|
21
21
|
status: z.ZodOptional<z.ZodString>;
|
|
22
22
|
title: z.ZodOptional<z.ZodString>;
|
|
23
|
+
rating: z.ZodOptional<z.ZodNumber>;
|
|
23
24
|
}, "strip", z.ZodTypeAny, {
|
|
24
|
-
status?: string | undefined;
|
|
25
|
-
title?: string | undefined;
|
|
26
25
|
conversationId?: string | undefined;
|
|
27
26
|
messageId?: string | undefined;
|
|
28
27
|
senderId?: string | undefined;
|
|
@@ -32,9 +31,10 @@ export declare const NotifSchema: z.ZodObject<{
|
|
|
32
31
|
expenseId?: string | undefined;
|
|
33
32
|
referenceId?: string | undefined;
|
|
34
33
|
referenceType?: string | undefined;
|
|
35
|
-
}, {
|
|
36
34
|
status?: string | undefined;
|
|
37
35
|
title?: string | undefined;
|
|
36
|
+
rating?: number | undefined;
|
|
37
|
+
}, {
|
|
38
38
|
conversationId?: string | undefined;
|
|
39
39
|
messageId?: string | undefined;
|
|
40
40
|
senderId?: string | undefined;
|
|
@@ -44,19 +44,20 @@ export declare const NotifSchema: z.ZodObject<{
|
|
|
44
44
|
expenseId?: string | undefined;
|
|
45
45
|
referenceId?: string | undefined;
|
|
46
46
|
referenceType?: string | undefined;
|
|
47
|
+
status?: string | undefined;
|
|
48
|
+
title?: string | undefined;
|
|
49
|
+
rating?: number | undefined;
|
|
47
50
|
}>>;
|
|
48
51
|
}, "strip", z.ZodTypeAny, {
|
|
49
|
-
message: string;
|
|
50
52
|
_id: string;
|
|
53
|
+
message: string;
|
|
51
54
|
read: boolean;
|
|
52
|
-
type?: "new_message" | "milestone_completed" | "expense_added" | "group_invite" | "mention" | "application_received" | "application_status" | "application_shortlisted" | "id_verification_request" | "id_verified" | "id_rejected" | "package_enquiry" | "package_approval" | "package_denial" | "package_rating" | "package_review" | "opportunity_assigned" | "opportunity_approval" | "opportunity_denial" | "opportunity_rating" | "opportunity_review" | "blog_like" | "blog_comment" | "blog_posted" | "blog_approval" | "blog_denial" | "system" | "general" | undefined;
|
|
53
55
|
userId?: string | undefined;
|
|
54
56
|
timestamp?: any;
|
|
55
57
|
link?: string | undefined;
|
|
56
|
-
|
|
58
|
+
type?: "new_message" | "milestone_completed" | "expense_added" | "group_invite" | "mention" | "application_received" | "application_status" | "application_shortlisted" | "id_verification_request" | "id_verified" | "id_rejected" | "package_enquiry" | "package_approval" | "package_denial" | "package_rating" | "package_review" | "opportunity_assigned" | "opportunity_approval" | "opportunity_denial" | "opportunity_rating" | "opportunity_review" | "blog_like" | "blog_comment" | "blog_posted" | "blog_approval" | "blog_denial" | "booking_confirmed" | "system" | "general" | undefined;
|
|
59
|
+
category?: "system" | "general" | "chat" | "application" | "opportunity" | "package" | "blog" | "account" | "booking" | undefined;
|
|
57
60
|
metadata?: {
|
|
58
|
-
status?: string | undefined;
|
|
59
|
-
title?: string | undefined;
|
|
60
61
|
conversationId?: string | undefined;
|
|
61
62
|
messageId?: string | undefined;
|
|
62
63
|
senderId?: string | undefined;
|
|
@@ -66,19 +67,20 @@ export declare const NotifSchema: z.ZodObject<{
|
|
|
66
67
|
expenseId?: string | undefined;
|
|
67
68
|
referenceId?: string | undefined;
|
|
68
69
|
referenceType?: string | undefined;
|
|
70
|
+
status?: string | undefined;
|
|
71
|
+
title?: string | undefined;
|
|
72
|
+
rating?: number | undefined;
|
|
69
73
|
} | undefined;
|
|
70
74
|
}, {
|
|
71
|
-
message: string;
|
|
72
75
|
_id: string;
|
|
76
|
+
message: string;
|
|
73
77
|
read: boolean;
|
|
74
|
-
type?: "new_message" | "milestone_completed" | "expense_added" | "group_invite" | "mention" | "application_received" | "application_status" | "application_shortlisted" | "id_verification_request" | "id_verified" | "id_rejected" | "package_enquiry" | "package_approval" | "package_denial" | "package_rating" | "package_review" | "opportunity_assigned" | "opportunity_approval" | "opportunity_denial" | "opportunity_rating" | "opportunity_review" | "blog_like" | "blog_comment" | "blog_posted" | "blog_approval" | "blog_denial" | "system" | "general" | undefined;
|
|
75
78
|
userId?: string | undefined;
|
|
76
79
|
timestamp?: any;
|
|
77
80
|
link?: string | undefined;
|
|
78
|
-
|
|
81
|
+
type?: "new_message" | "milestone_completed" | "expense_added" | "group_invite" | "mention" | "application_received" | "application_status" | "application_shortlisted" | "id_verification_request" | "id_verified" | "id_rejected" | "package_enquiry" | "package_approval" | "package_denial" | "package_rating" | "package_review" | "opportunity_assigned" | "opportunity_approval" | "opportunity_denial" | "opportunity_rating" | "opportunity_review" | "blog_like" | "blog_comment" | "blog_posted" | "blog_approval" | "blog_denial" | "booking_confirmed" | "system" | "general" | undefined;
|
|
82
|
+
category?: "system" | "general" | "chat" | "application" | "opportunity" | "package" | "blog" | "account" | "booking" | undefined;
|
|
79
83
|
metadata?: {
|
|
80
|
-
status?: string | undefined;
|
|
81
|
-
title?: string | undefined;
|
|
82
84
|
conversationId?: string | undefined;
|
|
83
85
|
messageId?: string | undefined;
|
|
84
86
|
senderId?: string | undefined;
|
|
@@ -88,6 +90,9 @@ export declare const NotifSchema: z.ZodObject<{
|
|
|
88
90
|
expenseId?: string | undefined;
|
|
89
91
|
referenceId?: string | undefined;
|
|
90
92
|
referenceType?: string | undefined;
|
|
93
|
+
status?: string | undefined;
|
|
94
|
+
title?: string | undefined;
|
|
95
|
+
rating?: number | undefined;
|
|
91
96
|
} | undefined;
|
|
92
97
|
}>;
|
|
93
98
|
export type Notif = z.infer<typeof NotifSchema>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"notifications.d.ts","sourceRoot":"","sources":["../../../src/lib/models/notifications.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,eAAO,MAAM,WAAW
|
|
1
|
+
{"version":3,"file":"notifications.d.ts","sourceRoot":"","sources":["../../../src/lib/models/notifications.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,eAAO,MAAM,WAAW;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EA6DtB,CAAC;AAEH,MAAM,MAAM,KAAK,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,WAAW,CAAC,CAAC"}
|
|
@@ -39,11 +39,13 @@ export const NotifSchema = z.object({
|
|
|
39
39
|
"blog_posted",
|
|
40
40
|
"blog_approval",
|
|
41
41
|
"blog_denial",
|
|
42
|
+
// Booking
|
|
43
|
+
"booking_confirmed",
|
|
42
44
|
// Generic
|
|
43
45
|
"system",
|
|
44
46
|
"general"
|
|
45
47
|
]).optional(),
|
|
46
|
-
category: z.enum(["chat", "application", "opportunity", "package", "blog", "account", "system", "general"]).optional(),
|
|
48
|
+
category: z.enum(["chat", "application", "opportunity", "package", "blog", "account", "system", "general", "booking"]).optional(),
|
|
47
49
|
metadata: z.object({
|
|
48
50
|
conversationId: z.string().optional(),
|
|
49
51
|
messageId: z.string().optional(),
|
|
@@ -56,5 +58,6 @@ export const NotifSchema = z.object({
|
|
|
56
58
|
referenceType: z.string().optional(),
|
|
57
59
|
status: z.string().optional(),
|
|
58
60
|
title: z.string().optional(),
|
|
61
|
+
rating: z.number().optional(),
|
|
59
62
|
}).optional(),
|
|
60
63
|
});
|