@myrjfa/state 1.0.8 → 1.1.1

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.
Files changed (39) hide show
  1. package/dist/index.d.ts +18 -17
  2. package/dist/index.d.ts.map +1 -1
  3. package/dist/index.js +18 -17
  4. package/dist/lib/actions/actions.d.ts +170 -140
  5. package/dist/lib/actions/actions.d.ts.map +1 -1
  6. package/dist/lib/actions/actions.js +307 -307
  7. package/dist/lib/actions/chat.d.ts +80 -11
  8. package/dist/lib/actions/chat.d.ts.map +1 -1
  9. package/dist/lib/actions/chat.js +81 -20
  10. package/dist/lib/actions/fetcher.js +84 -84
  11. package/dist/lib/actions/property.d.ts +77 -0
  12. package/dist/lib/actions/property.d.ts.map +1 -0
  13. package/dist/lib/actions/property.js +133 -0
  14. package/dist/lib/actions/user.d.ts +23 -0
  15. package/dist/lib/actions/user.d.ts.map +1 -0
  16. package/dist/lib/actions/user.js +55 -0
  17. package/dist/lib/authSessionManager.js +34 -34
  18. package/dist/lib/context/ChatContext.d.ts +8 -1
  19. package/dist/lib/context/ChatContext.d.ts.map +1 -1
  20. package/dist/lib/context/ChatContext.js +338 -229
  21. package/dist/lib/models/chat.d.ts +32 -7
  22. package/dist/lib/models/chat.d.ts.map +1 -1
  23. package/dist/lib/models/notfications.d.ts +93 -25
  24. package/dist/lib/models/notfications.d.ts.map +1 -1
  25. package/dist/lib/models/notfications.js +55 -41
  26. package/dist/lib/models/portfolio.d.ts +42 -42
  27. package/dist/lib/models/property.d.ts +79 -0
  28. package/dist/lib/models/property.d.ts.map +1 -0
  29. package/dist/lib/models/property.js +134 -0
  30. package/dist/lib/models/tile.d.ts +28 -28
  31. package/dist/lib/userAtom.d.ts +198 -198
  32. package/dist/lib/userAtom.js +127 -127
  33. package/dist/lib/utils/fileCompression.d.ts +16 -0
  34. package/dist/lib/utils/fileCompression.d.ts.map +1 -0
  35. package/dist/lib/utils/fileCompression.js +56 -0
  36. package/dist/lib/utils/socialMediaUrl.d.ts +25 -0
  37. package/dist/lib/utils/socialMediaUrl.d.ts.map +1 -0
  38. package/dist/lib/utils/socialMediaUrl.js +97 -0
  39. package/package.json +1 -1
@@ -0,0 +1,133 @@
1
+ import { del, get, patch, post } from "./fetcher";
2
+ // ─── CRUD ──────────────────────────────────────────────────────────────────
3
+ export async function createProperty(formData) {
4
+ try {
5
+ const data = await post(`/properties`, formData);
6
+ return { success: true, property: data?.data?.property, message: data?.message };
7
+ }
8
+ catch (error) {
9
+ return { success: false, error: error?.message || "Failed to create property" };
10
+ }
11
+ }
12
+ export async function getMyProperties() {
13
+ try {
14
+ const data = await get(`/properties`);
15
+ return { success: true, properties: data?.data?.properties ?? [] };
16
+ }
17
+ catch (error) {
18
+ return { success: false, error: error?.message || "Failed to fetch properties" };
19
+ }
20
+ }
21
+ export async function getPropertyById(propertyId) {
22
+ try {
23
+ const data = await get(`/properties/${propertyId}`);
24
+ return { success: true, property: data?.data?.property };
25
+ }
26
+ catch (error) {
27
+ return { success: false, error: error?.message || "Failed to fetch property" };
28
+ }
29
+ }
30
+ export async function updateProperty(propertyId, formData) {
31
+ try {
32
+ const data = await patch(`/properties/${propertyId}`, formData);
33
+ return { success: true, property: data?.data?.property, message: data?.message };
34
+ }
35
+ catch (error) {
36
+ return { success: false, error: error?.message || "Failed to update property" };
37
+ }
38
+ }
39
+ export async function deleteProperty(propertyId) {
40
+ try {
41
+ const data = await del(`/properties/${propertyId}`);
42
+ return { success: true, message: data?.message };
43
+ }
44
+ catch (error) {
45
+ return { success: false, error: error?.message || "Failed to delete property" };
46
+ }
47
+ }
48
+ // ─── Status lifecycle ──────────────────────────────────────────────────────
49
+ /** Host submits for review (draft/rejected → pending_review) */
50
+ export async function submitPropertyForReview(propertyId) {
51
+ try {
52
+ const data = await patch(`/properties/${propertyId}`, { status: "pending_review" });
53
+ return { success: true, message: data?.message };
54
+ }
55
+ catch (error) {
56
+ return { success: false, error: error?.message || "Failed to submit property for review" };
57
+ }
58
+ }
59
+ /** Host withdraws a pending submission back to draft */
60
+ export async function withdrawPropertySubmission(propertyId) {
61
+ try {
62
+ const data = await patch(`/properties/${propertyId}`, { status: "draft" });
63
+ return { success: true, message: data?.message };
64
+ }
65
+ catch (error) {
66
+ return { success: false, error: error?.message || "Failed to withdraw submission" };
67
+ }
68
+ }
69
+ /** Host deactivates an active property */
70
+ export async function deactivateProperty(propertyId) {
71
+ try {
72
+ const data = await patch(`/properties/${propertyId}`, { status: "inactive" });
73
+ return { success: true, message: data?.message };
74
+ }
75
+ catch (error) {
76
+ return { success: false, error: error?.message || "Failed to deactivate property" };
77
+ }
78
+ }
79
+ /** Admin-only: approve, reject, or suspend a property */
80
+ export async function adminUpdatePropertyStatus(propertyId, status, adminNote) {
81
+ try {
82
+ const data = await patch(`/admin/properties/${propertyId}/status`, {
83
+ status,
84
+ adminNote,
85
+ });
86
+ return { success: true, message: data?.message };
87
+ }
88
+ catch (error) {
89
+ return { success: false, error: error?.message || "Failed to update property status" };
90
+ }
91
+ }
92
+ /** Admin: get all pending_review properties */
93
+ export async function getPendingProperties() {
94
+ try {
95
+ const data = await get(`/admin/properties/pending`);
96
+ return { success: true, properties: data?.data?.properties ?? [] };
97
+ }
98
+ catch (error) {
99
+ return { success: false, error: error?.message || "Failed to fetch pending properties" };
100
+ }
101
+ }
102
+ // ─── Managers ──────────────────────────────────────────────────────────────
103
+ export async function addPropertyManager(propertyId, username, managerRole, permissions) {
104
+ try {
105
+ const data = await post(`/properties/${propertyId}/managers`, {
106
+ username,
107
+ managerRole,
108
+ permissions,
109
+ });
110
+ return { success: true, message: data?.message };
111
+ }
112
+ catch (error) {
113
+ return { success: false, error: error?.message || "Failed to add manager" };
114
+ }
115
+ }
116
+ export async function updatePropertyManager(propertyId, managerId, updates) {
117
+ try {
118
+ const data = await patch(`/properties/${propertyId}/managers/${managerId}`, updates);
119
+ return { success: true, message: data?.message };
120
+ }
121
+ catch (error) {
122
+ return { success: false, error: error?.message || "Failed to update manager" };
123
+ }
124
+ }
125
+ export async function removePropertyManager(propertyId, managerId) {
126
+ try {
127
+ const data = await del(`/properties/${propertyId}/managers/${managerId}`);
128
+ return { success: true, message: data?.message };
129
+ }
130
+ catch (error) {
131
+ return { success: false, error: error?.message || "Failed to remove manager" };
132
+ }
133
+ }
@@ -0,0 +1,23 @@
1
+ export declare const userApi: {
2
+ blockUser: (userId: string, role: string) => Promise<{
3
+ error: string;
4
+ data: any;
5
+ } | {
6
+ error: unknown;
7
+ data: null;
8
+ }>;
9
+ unblockUser: (userId: string, role: string) => Promise<{
10
+ error: string;
11
+ data: any;
12
+ } | {
13
+ error: unknown;
14
+ data: null;
15
+ }>;
16
+ getBlockedUsers: () => Promise<any[]>;
17
+ getBlockerUsers: () => Promise<any[]>;
18
+ checkIfBlocked: (userId: string, role: string) => Promise<{
19
+ isBlocked: boolean;
20
+ hasBlocked: boolean;
21
+ }>;
22
+ };
23
+ //# sourceMappingURL=user.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"user.d.ts","sourceRoot":"","sources":["../../../src/lib/actions/user.ts"],"names":[],"mappings":"AAIA,eAAO,MAAM,OAAO;wBAEU,MAAM,QAAQ,MAAM;eAED,MAAM;cAAQ,GAAG;;;;;0BAQlC,MAAM,QAAQ,MAAM;eAEH,MAAM;cAAQ,GAAG;;;;;;;6BA4B/B,MAAM,QAAQ,MAAM;mBAEoB,OAAO;oBAAc,OAAO;;CAOtG,CAAC"}
@@ -0,0 +1,55 @@
1
+ import { get, post } from "./fetcher";
2
+ const BASE_PATH = "/users";
3
+ export const userApi = {
4
+ // Block Management
5
+ blockUser: async (userId, role) => {
6
+ try {
7
+ const response = await post(`${BASE_PATH}/block/${role}/${userId}`, {});
8
+ return response;
9
+ }
10
+ catch (error) {
11
+ console.error(error);
12
+ return { error: error, data: null };
13
+ }
14
+ },
15
+ unblockUser: async (userId, role) => {
16
+ try {
17
+ const response = await post(`${BASE_PATH}/unblock/${role}/${userId}`, {});
18
+ return response;
19
+ }
20
+ catch (error) {
21
+ console.error(error);
22
+ return { error: error, data: null };
23
+ }
24
+ },
25
+ getBlockedUsers: async () => {
26
+ try {
27
+ const response = await get(`${BASE_PATH}/blocked`);
28
+ return response.data;
29
+ }
30
+ catch (error) {
31
+ console.error(error);
32
+ return [];
33
+ }
34
+ },
35
+ getBlockerUsers: async () => {
36
+ try {
37
+ const response = await get(`${BASE_PATH}/blockers`);
38
+ return response.data;
39
+ }
40
+ catch (error) {
41
+ console.error(error);
42
+ return [];
43
+ }
44
+ },
45
+ checkIfBlocked: async (userId, role) => {
46
+ try {
47
+ const response = await get(`${BASE_PATH}/blocked/${role}/${userId}`);
48
+ return response.data;
49
+ }
50
+ catch (error) {
51
+ console.error(error);
52
+ return { isBlocked: false, hasBlocked: false };
53
+ }
54
+ },
55
+ };
@@ -1,34 +1,34 @@
1
- 'use client';
2
- import { useAtom } from 'jotai'; // Import useSetAtom
3
- import { useEffect } from 'react';
4
- import { useQuery } from '@tanstack/react-query';
5
- import { initializeAuthSessionAtom, resetAuthState } from './userAtom'; // Import the atom itself
6
- import { validateSession } from './actions/auth';
7
- export default function AuthSessionManager() {
8
- const [, initializeAuthSession] = useAtom(initializeAuthSessionAtom);
9
- // --- Initial Session Load ---
10
- useEffect(() => {
11
- initializeAuthSession();
12
- }, [initializeAuthSession]);
13
- // --- Continuous Background Re-validation ---
14
- const { isError } = useQuery({
15
- queryKey: ['session'],
16
- queryFn: validateSession,
17
- // --- Configuration for a seamless experience ---
18
- refetchOnWindowFocus: true,
19
- refetchOnReconnect: true,
20
- retry: (failureCount, error) => {
21
- if (error.response?.status === 401)
22
- return false;
23
- return failureCount < 2;
24
- },
25
- staleTime: 15 * 60 * 1000,
26
- });
27
- useEffect(() => {
28
- if (isError) {
29
- console.log("Session validation failed. Logging out.");
30
- resetAuthState();
31
- }
32
- }, [isError, resetAuthState]);
33
- return null;
34
- }
1
+ 'use client';
2
+ import { useAtom } from 'jotai'; // Import useSetAtom
3
+ import { useEffect } from 'react';
4
+ import { useQuery } from '@tanstack/react-query';
5
+ import { initializeAuthSessionAtom, resetAuthState } from './userAtom'; // Import the atom itself
6
+ import { validateSession } from './actions/auth';
7
+ export default function AuthSessionManager() {
8
+ const [, initializeAuthSession] = useAtom(initializeAuthSessionAtom);
9
+ // --- Initial Session Load ---
10
+ useEffect(() => {
11
+ initializeAuthSession();
12
+ }, [initializeAuthSession]);
13
+ // --- Continuous Background Re-validation ---
14
+ const { isError } = useQuery({
15
+ queryKey: ['session'],
16
+ queryFn: validateSession,
17
+ // --- Configuration for a seamless experience ---
18
+ refetchOnWindowFocus: true,
19
+ refetchOnReconnect: true,
20
+ retry: (failureCount, error) => {
21
+ if (error.response?.status === 401)
22
+ return false;
23
+ return failureCount < 2;
24
+ },
25
+ staleTime: 15 * 60 * 1000,
26
+ });
27
+ useEffect(() => {
28
+ if (isError) {
29
+ console.log("Session validation failed. Logging out.");
30
+ resetAuthState();
31
+ }
32
+ }, [isError, resetAuthState]);
33
+ return null;
34
+ }
@@ -1,6 +1,7 @@
1
1
  import React from "react";
2
2
  import type { Socket } from "socket.io-client";
3
3
  import type { Conversation, Message } from "../models/chat";
4
+ import type { Notif } from "../models/notfications";
4
5
  interface ChatContextType {
5
6
  socket: Socket | null;
6
7
  isConnected: boolean;
@@ -13,9 +14,15 @@ interface ChatContextType {
13
14
  onlineUsers: Set<string>;
14
15
  refreshConversations: () => Promise<void>;
15
16
  sendMessage: (conversationId: string, text: string, files?: File[], replyTo?: string) => Promise<void>;
17
+ createPoll: (conversationId: string, question: string, options: string[], allowMultiple: boolean) => void;
18
+ votePoll: (pollId: string, optionIndex: number) => void;
16
19
  editMessage: (messageId: string, text: string) => void;
17
- addMessageReaction: (messageId: string, reaction: string) => void;
20
+ toggleMessageReaction: (messageId: string, reaction?: string) => void;
18
21
  deleteMessage: (messageId: string) => void;
22
+ markRead: (conversationId: string, unreadIds: string[]) => void;
23
+ unreadNotificationCount: number;
24
+ notifications: Notif[];
25
+ clearNotifications: () => void;
19
26
  }
20
27
  export declare function useChatContext(): ChatContextType;
21
28
  export declare function ChatProvider({ children }: {
@@ -1 +1 @@
1
- {"version":3,"file":"ChatContext.d.ts","sourceRoot":"","sources":["../../../src/lib/context/ChatContext.tsx"],"names":[],"mappings":"AAEA,OAAO,KAA8E,MAAM,OAAO,CAAC;AACnG,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAC;AAE/C,OAAO,KAAK,EAAE,YAAY,EAAE,OAAO,EAAE,MAAM,gBAAgB,CAAC;AAK5D,UAAU,eAAe;IACrB,MAAM,EAAE,MAAM,GAAG,IAAI,CAAC;IACtB,WAAW,EAAE,OAAO,CAAC;IACrB,aAAa,EAAE,YAAY,EAAE,CAAC;IAC9B,kBAAkB,EAAE,YAAY,GAAG,IAAI,CAAC;IACxC,qBAAqB,EAAE,CAAC,IAAI,EAAE,YAAY,GAAG,IAAI,KAAK,IAAI,CAAC;IAC3D,QAAQ,EAAE,OAAO,EAAE,CAAC;IACpB,WAAW,EAAE,KAAK,CAAC,QAAQ,CAAC,KAAK,CAAC,cAAc,CAAC,OAAO,EAAE,CAAC,CAAC,CAAC;IAC7D,WAAW,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,EAAE,CAAC,CAAC;IACnC,WAAW,EAAE,GAAG,CAAC,MAAM,CAAC,CAAC;IACzB,oBAAoB,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC;IAC1C,WAAW,EAAE,CAAC,cAAc,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,IAAI,EAAE,EAAE,OAAO,CAAC,EAAE,MAAM,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;IACvG,WAAW,EAAE,CAAC,SAAS,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,KAAK,IAAI,CAAC;IACvD,kBAAkB,EAAE,CAAC,SAAS,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,KAAK,IAAI,CAAC;IAClE,aAAa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