@sudobility/entity_client 0.0.8 → 0.0.9
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/package.json +15 -21
- package/dist/hooks/index.cjs +0 -30
- package/dist/hooks/useCurrentEntity.cjs +0 -69
- package/dist/hooks/useEntities.cjs +0 -113
- package/dist/hooks/useEntityMembers.cjs +0 -77
- package/dist/hooks/useInvitations.cjs +0 -132
- package/dist/index.cjs +0 -58
- package/dist/network/EntityClient.cjs +0 -158
- package/dist/network/index.cjs +0 -9
package/package.json
CHANGED
|
@@ -1,30 +1,27 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sudobility/entity_client",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.9",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Frontend client library for entity/organization management",
|
|
6
|
-
"main": "
|
|
7
|
-
"
|
|
8
|
-
"
|
|
9
|
-
|
|
10
|
-
".": {
|
|
11
|
-
"import": "./dist/index.js",
|
|
12
|
-
"require": "./dist/index.cjs",
|
|
13
|
-
"types": "./dist/index.d.ts"
|
|
14
|
-
}
|
|
6
|
+
"main": "dist/index.js",
|
|
7
|
+
"types": "dist/index.d.ts",
|
|
8
|
+
"publishConfig": {
|
|
9
|
+
"access": "public"
|
|
15
10
|
},
|
|
11
|
+
"files": [
|
|
12
|
+
"dist/**/*"
|
|
13
|
+
],
|
|
16
14
|
"scripts": {
|
|
17
|
-
"build": "
|
|
18
|
-
"build:
|
|
19
|
-
"
|
|
20
|
-
"
|
|
21
|
-
"
|
|
15
|
+
"build": "bunx tsc -p tsconfig.build.json",
|
|
16
|
+
"build:watch": "bunx tsc --watch",
|
|
17
|
+
"clean": "rm -rf dist",
|
|
18
|
+
"prepublishOnly": "bun run clean && bun run build",
|
|
19
|
+
"test": "vitest run",
|
|
20
|
+
"test:watch": "vitest",
|
|
22
21
|
"typecheck": "bunx tsc --noEmit",
|
|
23
22
|
"lint": "bunx eslint src",
|
|
24
23
|
"lint:fix": "bunx eslint src --fix",
|
|
25
|
-
"format": "bunx prettier --write \"src/**/*.{ts,tsx,js,jsx,json}\""
|
|
26
|
-
"test": "vitest run",
|
|
27
|
-
"test:watch": "vitest"
|
|
24
|
+
"format": "bunx prettier --write \"src/**/*.{ts,tsx,js,jsx,json}\""
|
|
28
25
|
},
|
|
29
26
|
"peerDependencies": {
|
|
30
27
|
"react": "^18.0.0 || ^19.0.0",
|
|
@@ -48,9 +45,6 @@
|
|
|
48
45
|
"react": "^19.0.0",
|
|
49
46
|
"typescript": "^5.9.3"
|
|
50
47
|
},
|
|
51
|
-
"files": [
|
|
52
|
-
"dist/**/*"
|
|
53
|
-
],
|
|
54
48
|
"keywords": [
|
|
55
49
|
"entity",
|
|
56
50
|
"organization",
|
package/dist/hooks/index.cjs
DELETED
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/**
|
|
3
|
-
* @fileoverview Hook Exports
|
|
4
|
-
*/
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.CurrentEntityProvider = exports.useCurrentEntity = exports.invitationKeys = exports.useDeclineInvitation = exports.useAcceptInvitation = exports.useCancelInvitation = exports.useCreateInvitation = exports.useEntityInvitations = exports.useMyInvitations = exports.memberKeys = exports.useRemoveMember = exports.useUpdateMemberRole = exports.useEntityMembers = exports.entityKeys = exports.useDeleteEntity = exports.useUpdateEntity = exports.useCreateEntity = exports.useEntity = exports.useEntities = void 0;
|
|
7
|
-
var useEntities_1 = require("./useEntities");
|
|
8
|
-
Object.defineProperty(exports, "useEntities", { enumerable: true, get: function () { return useEntities_1.useEntities; } });
|
|
9
|
-
Object.defineProperty(exports, "useEntity", { enumerable: true, get: function () { return useEntities_1.useEntity; } });
|
|
10
|
-
Object.defineProperty(exports, "useCreateEntity", { enumerable: true, get: function () { return useEntities_1.useCreateEntity; } });
|
|
11
|
-
Object.defineProperty(exports, "useUpdateEntity", { enumerable: true, get: function () { return useEntities_1.useUpdateEntity; } });
|
|
12
|
-
Object.defineProperty(exports, "useDeleteEntity", { enumerable: true, get: function () { return useEntities_1.useDeleteEntity; } });
|
|
13
|
-
Object.defineProperty(exports, "entityKeys", { enumerable: true, get: function () { return useEntities_1.entityKeys; } });
|
|
14
|
-
var useEntityMembers_1 = require("./useEntityMembers");
|
|
15
|
-
Object.defineProperty(exports, "useEntityMembers", { enumerable: true, get: function () { return useEntityMembers_1.useEntityMembers; } });
|
|
16
|
-
Object.defineProperty(exports, "useUpdateMemberRole", { enumerable: true, get: function () { return useEntityMembers_1.useUpdateMemberRole; } });
|
|
17
|
-
Object.defineProperty(exports, "useRemoveMember", { enumerable: true, get: function () { return useEntityMembers_1.useRemoveMember; } });
|
|
18
|
-
Object.defineProperty(exports, "memberKeys", { enumerable: true, get: function () { return useEntityMembers_1.memberKeys; } });
|
|
19
|
-
var useInvitations_1 = require("./useInvitations");
|
|
20
|
-
Object.defineProperty(exports, "useMyInvitations", { enumerable: true, get: function () { return useInvitations_1.useMyInvitations; } });
|
|
21
|
-
Object.defineProperty(exports, "useEntityInvitations", { enumerable: true, get: function () { return useInvitations_1.useEntityInvitations; } });
|
|
22
|
-
Object.defineProperty(exports, "useCreateInvitation", { enumerable: true, get: function () { return useInvitations_1.useCreateInvitation; } });
|
|
23
|
-
Object.defineProperty(exports, "useCancelInvitation", { enumerable: true, get: function () { return useInvitations_1.useCancelInvitation; } });
|
|
24
|
-
Object.defineProperty(exports, "useAcceptInvitation", { enumerable: true, get: function () { return useInvitations_1.useAcceptInvitation; } });
|
|
25
|
-
Object.defineProperty(exports, "useDeclineInvitation", { enumerable: true, get: function () { return useInvitations_1.useDeclineInvitation; } });
|
|
26
|
-
Object.defineProperty(exports, "invitationKeys", { enumerable: true, get: function () { return useInvitations_1.invitationKeys; } });
|
|
27
|
-
var useCurrentEntity_1 = require("./useCurrentEntity");
|
|
28
|
-
Object.defineProperty(exports, "useCurrentEntity", { enumerable: true, get: function () { return useCurrentEntity_1.useCurrentEntity; } });
|
|
29
|
-
Object.defineProperty(exports, "CurrentEntityProvider", { enumerable: true, get: function () { return useCurrentEntity_1.CurrentEntityProvider; } });
|
|
30
|
-
//# sourceMappingURL=index.js.map
|
|
@@ -1,69 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.CurrentEntityProvider = CurrentEntityProvider;
|
|
4
|
-
exports.useCurrentEntity = useCurrentEntity;
|
|
5
|
-
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
6
|
-
/**
|
|
7
|
-
* @fileoverview Current Entity Context Hook
|
|
8
|
-
* @description React context and hook for managing current entity selection
|
|
9
|
-
*/
|
|
10
|
-
const react_1 = require("react");
|
|
11
|
-
const useEntities_1 = require("./useEntities");
|
|
12
|
-
const CurrentEntityContext = (0, react_1.createContext)(null);
|
|
13
|
-
/**
|
|
14
|
-
* Storage key for persisting selected entity.
|
|
15
|
-
*/
|
|
16
|
-
const STORAGE_KEY = 'currentEntitySlug';
|
|
17
|
-
/**
|
|
18
|
-
* Provider component for current entity context.
|
|
19
|
-
*/
|
|
20
|
-
function CurrentEntityProvider({ client, children, defaultEntitySlug, }) {
|
|
21
|
-
const [selectedSlug, setSelectedSlug] = (0, react_1.useState)(() => {
|
|
22
|
-
// Try to restore from storage
|
|
23
|
-
if (typeof window !== 'undefined') {
|
|
24
|
-
return localStorage.getItem(STORAGE_KEY) || defaultEntitySlug || null;
|
|
25
|
-
}
|
|
26
|
-
return defaultEntitySlug || null;
|
|
27
|
-
});
|
|
28
|
-
const { data: entities = [], isLoading, error, refetch, } = (0, useEntities_1.useEntities)(client);
|
|
29
|
-
// Determine current entity
|
|
30
|
-
const currentEntity = entities.find(e => e.entitySlug === selectedSlug) || entities[0] || null;
|
|
31
|
-
// Persist selection
|
|
32
|
-
(0, react_1.useEffect)(() => {
|
|
33
|
-
if (currentEntity && typeof window !== 'undefined') {
|
|
34
|
-
localStorage.setItem(STORAGE_KEY, currentEntity.entitySlug);
|
|
35
|
-
}
|
|
36
|
-
}, [currentEntity]);
|
|
37
|
-
// Auto-select first entity if none selected
|
|
38
|
-
(0, react_1.useEffect)(() => {
|
|
39
|
-
if (!selectedSlug && entities.length > 0) {
|
|
40
|
-
setSelectedSlug(entities[0].entitySlug);
|
|
41
|
-
}
|
|
42
|
-
}, [entities, selectedSlug]);
|
|
43
|
-
const selectEntity = (0, react_1.useCallback)((entitySlug) => {
|
|
44
|
-
setSelectedSlug(entitySlug);
|
|
45
|
-
}, []);
|
|
46
|
-
const refresh = (0, react_1.useCallback)(() => {
|
|
47
|
-
refetch();
|
|
48
|
-
}, [refetch]);
|
|
49
|
-
const value = {
|
|
50
|
-
currentEntity,
|
|
51
|
-
entities,
|
|
52
|
-
isLoading,
|
|
53
|
-
error: error,
|
|
54
|
-
selectEntity,
|
|
55
|
-
refresh,
|
|
56
|
-
};
|
|
57
|
-
return ((0, jsx_runtime_1.jsx)(CurrentEntityContext.Provider, { value: value, children: children }));
|
|
58
|
-
}
|
|
59
|
-
/**
|
|
60
|
-
* Hook to access current entity context.
|
|
61
|
-
*/
|
|
62
|
-
function useCurrentEntity() {
|
|
63
|
-
const context = (0, react_1.useContext)(CurrentEntityContext);
|
|
64
|
-
if (!context) {
|
|
65
|
-
throw new Error('useCurrentEntity must be used within CurrentEntityProvider');
|
|
66
|
-
}
|
|
67
|
-
return context;
|
|
68
|
-
}
|
|
69
|
-
//# sourceMappingURL=useCurrentEntity.js.map
|
|
@@ -1,113 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/**
|
|
3
|
-
* @fileoverview Entity Hooks
|
|
4
|
-
* @description React Query hooks for entity management
|
|
5
|
-
*/
|
|
6
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
-
exports.entityKeys = void 0;
|
|
8
|
-
exports.useEntities = useEntities;
|
|
9
|
-
exports.useEntity = useEntity;
|
|
10
|
-
exports.useCreateEntity = useCreateEntity;
|
|
11
|
-
exports.useUpdateEntity = useUpdateEntity;
|
|
12
|
-
exports.useDeleteEntity = useDeleteEntity;
|
|
13
|
-
const react_query_1 = require("@tanstack/react-query");
|
|
14
|
-
/**
|
|
15
|
-
* Query keys for entity-related queries.
|
|
16
|
-
*/
|
|
17
|
-
exports.entityKeys = {
|
|
18
|
-
all: ['entities'],
|
|
19
|
-
lists: () => [...exports.entityKeys.all, 'list'],
|
|
20
|
-
list: () => [...exports.entityKeys.lists()],
|
|
21
|
-
details: () => [...exports.entityKeys.all, 'detail'],
|
|
22
|
-
detail: (slug) => [...exports.entityKeys.details(), slug],
|
|
23
|
-
};
|
|
24
|
-
/**
|
|
25
|
-
* Hook to list all entities for the current user.
|
|
26
|
-
*/
|
|
27
|
-
function useEntities(client) {
|
|
28
|
-
return (0, react_query_1.useQuery)({
|
|
29
|
-
queryKey: exports.entityKeys.list(),
|
|
30
|
-
queryFn: async () => {
|
|
31
|
-
const response = await client.listEntities();
|
|
32
|
-
if (!response.success || !response.data) {
|
|
33
|
-
throw new Error(response.error || 'Failed to fetch entities');
|
|
34
|
-
}
|
|
35
|
-
return response.data;
|
|
36
|
-
},
|
|
37
|
-
});
|
|
38
|
-
}
|
|
39
|
-
/**
|
|
40
|
-
* Hook to get a single entity by slug.
|
|
41
|
-
*/
|
|
42
|
-
function useEntity(client, entitySlug) {
|
|
43
|
-
return (0, react_query_1.useQuery)({
|
|
44
|
-
queryKey: entitySlug ? exports.entityKeys.detail(entitySlug) : ['disabled'],
|
|
45
|
-
queryFn: async () => {
|
|
46
|
-
if (!entitySlug)
|
|
47
|
-
return null;
|
|
48
|
-
const response = await client.getEntity(entitySlug);
|
|
49
|
-
if (!response.success || !response.data) {
|
|
50
|
-
throw new Error(response.error || 'Failed to fetch entity');
|
|
51
|
-
}
|
|
52
|
-
return response.data;
|
|
53
|
-
},
|
|
54
|
-
enabled: !!entitySlug,
|
|
55
|
-
});
|
|
56
|
-
}
|
|
57
|
-
/**
|
|
58
|
-
* Hook to create a new organization entity.
|
|
59
|
-
*/
|
|
60
|
-
function useCreateEntity(client) {
|
|
61
|
-
const queryClient = (0, react_query_1.useQueryClient)();
|
|
62
|
-
return (0, react_query_1.useMutation)({
|
|
63
|
-
mutationFn: async (request) => {
|
|
64
|
-
const response = await client.createEntity(request);
|
|
65
|
-
if (!response.success || !response.data) {
|
|
66
|
-
throw new Error(response.error || 'Failed to create entity');
|
|
67
|
-
}
|
|
68
|
-
return response.data;
|
|
69
|
-
},
|
|
70
|
-
onSuccess: () => {
|
|
71
|
-
queryClient.invalidateQueries({ queryKey: exports.entityKeys.lists() });
|
|
72
|
-
},
|
|
73
|
-
});
|
|
74
|
-
}
|
|
75
|
-
/**
|
|
76
|
-
* Hook to update an entity.
|
|
77
|
-
*/
|
|
78
|
-
function useUpdateEntity(client) {
|
|
79
|
-
const queryClient = (0, react_query_1.useQueryClient)();
|
|
80
|
-
return (0, react_query_1.useMutation)({
|
|
81
|
-
mutationFn: async ({ entitySlug, request, }) => {
|
|
82
|
-
const response = await client.updateEntity(entitySlug, request);
|
|
83
|
-
if (!response.success || !response.data) {
|
|
84
|
-
throw new Error(response.error || 'Failed to update entity');
|
|
85
|
-
}
|
|
86
|
-
return response.data;
|
|
87
|
-
},
|
|
88
|
-
onSuccess: (_, variables) => {
|
|
89
|
-
queryClient.invalidateQueries({
|
|
90
|
-
queryKey: exports.entityKeys.detail(variables.entitySlug),
|
|
91
|
-
});
|
|
92
|
-
queryClient.invalidateQueries({ queryKey: exports.entityKeys.lists() });
|
|
93
|
-
},
|
|
94
|
-
});
|
|
95
|
-
}
|
|
96
|
-
/**
|
|
97
|
-
* Hook to delete an entity.
|
|
98
|
-
*/
|
|
99
|
-
function useDeleteEntity(client) {
|
|
100
|
-
const queryClient = (0, react_query_1.useQueryClient)();
|
|
101
|
-
return (0, react_query_1.useMutation)({
|
|
102
|
-
mutationFn: async (entitySlug) => {
|
|
103
|
-
const response = await client.deleteEntity(entitySlug);
|
|
104
|
-
if (!response.success) {
|
|
105
|
-
throw new Error(response.error || 'Failed to delete entity');
|
|
106
|
-
}
|
|
107
|
-
},
|
|
108
|
-
onSuccess: () => {
|
|
109
|
-
queryClient.invalidateQueries({ queryKey: exports.entityKeys.lists() });
|
|
110
|
-
},
|
|
111
|
-
});
|
|
112
|
-
}
|
|
113
|
-
//# sourceMappingURL=useEntities.js.map
|
|
@@ -1,77 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/**
|
|
3
|
-
* @fileoverview Entity Member Hooks
|
|
4
|
-
* @description React Query hooks for entity member management
|
|
5
|
-
*/
|
|
6
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
-
exports.memberKeys = void 0;
|
|
8
|
-
exports.useEntityMembers = useEntityMembers;
|
|
9
|
-
exports.useUpdateMemberRole = useUpdateMemberRole;
|
|
10
|
-
exports.useRemoveMember = useRemoveMember;
|
|
11
|
-
const react_query_1 = require("@tanstack/react-query");
|
|
12
|
-
const useEntities_1 = require("./useEntities");
|
|
13
|
-
/**
|
|
14
|
-
* Query keys for member-related queries.
|
|
15
|
-
*/
|
|
16
|
-
exports.memberKeys = {
|
|
17
|
-
all: (entitySlug) => [...useEntities_1.entityKeys.detail(entitySlug), 'members'],
|
|
18
|
-
list: (entitySlug) => [...exports.memberKeys.all(entitySlug), 'list'],
|
|
19
|
-
};
|
|
20
|
-
/**
|
|
21
|
-
* Hook to list members of an entity.
|
|
22
|
-
*/
|
|
23
|
-
function useEntityMembers(client, entitySlug) {
|
|
24
|
-
return (0, react_query_1.useQuery)({
|
|
25
|
-
queryKey: entitySlug ? exports.memberKeys.list(entitySlug) : ['disabled'],
|
|
26
|
-
queryFn: async () => {
|
|
27
|
-
if (!entitySlug)
|
|
28
|
-
return [];
|
|
29
|
-
const response = await client.listMembers(entitySlug);
|
|
30
|
-
if (!response.success || !response.data) {
|
|
31
|
-
throw new Error(response.error || 'Failed to fetch members');
|
|
32
|
-
}
|
|
33
|
-
return response.data;
|
|
34
|
-
},
|
|
35
|
-
enabled: !!entitySlug,
|
|
36
|
-
});
|
|
37
|
-
}
|
|
38
|
-
/**
|
|
39
|
-
* Hook to update a member's role.
|
|
40
|
-
*/
|
|
41
|
-
function useUpdateMemberRole(client) {
|
|
42
|
-
const queryClient = (0, react_query_1.useQueryClient)();
|
|
43
|
-
return (0, react_query_1.useMutation)({
|
|
44
|
-
mutationFn: async ({ entitySlug, memberId, role, }) => {
|
|
45
|
-
const response = await client.updateMemberRole(entitySlug, memberId, role);
|
|
46
|
-
if (!response.success || !response.data) {
|
|
47
|
-
throw new Error(response.error || 'Failed to update member role');
|
|
48
|
-
}
|
|
49
|
-
return response.data;
|
|
50
|
-
},
|
|
51
|
-
onSuccess: (_, variables) => {
|
|
52
|
-
queryClient.invalidateQueries({
|
|
53
|
-
queryKey: exports.memberKeys.list(variables.entitySlug),
|
|
54
|
-
});
|
|
55
|
-
},
|
|
56
|
-
});
|
|
57
|
-
}
|
|
58
|
-
/**
|
|
59
|
-
* Hook to remove a member from an entity.
|
|
60
|
-
*/
|
|
61
|
-
function useRemoveMember(client) {
|
|
62
|
-
const queryClient = (0, react_query_1.useQueryClient)();
|
|
63
|
-
return (0, react_query_1.useMutation)({
|
|
64
|
-
mutationFn: async ({ entitySlug, memberId, }) => {
|
|
65
|
-
const response = await client.removeMember(entitySlug, memberId);
|
|
66
|
-
if (!response.success) {
|
|
67
|
-
throw new Error(response.error || 'Failed to remove member');
|
|
68
|
-
}
|
|
69
|
-
},
|
|
70
|
-
onSuccess: (_, variables) => {
|
|
71
|
-
queryClient.invalidateQueries({
|
|
72
|
-
queryKey: exports.memberKeys.list(variables.entitySlug),
|
|
73
|
-
});
|
|
74
|
-
},
|
|
75
|
-
});
|
|
76
|
-
}
|
|
77
|
-
//# sourceMappingURL=useEntityMembers.js.map
|
|
@@ -1,132 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/**
|
|
3
|
-
* @fileoverview Invitation Hooks
|
|
4
|
-
* @description React Query hooks for entity invitation management
|
|
5
|
-
*/
|
|
6
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
-
exports.invitationKeys = void 0;
|
|
8
|
-
exports.useMyInvitations = useMyInvitations;
|
|
9
|
-
exports.useEntityInvitations = useEntityInvitations;
|
|
10
|
-
exports.useCreateInvitation = useCreateInvitation;
|
|
11
|
-
exports.useCancelInvitation = useCancelInvitation;
|
|
12
|
-
exports.useAcceptInvitation = useAcceptInvitation;
|
|
13
|
-
exports.useDeclineInvitation = useDeclineInvitation;
|
|
14
|
-
const react_query_1 = require("@tanstack/react-query");
|
|
15
|
-
const useEntities_1 = require("./useEntities");
|
|
16
|
-
/**
|
|
17
|
-
* Query keys for invitation-related queries.
|
|
18
|
-
*/
|
|
19
|
-
exports.invitationKeys = {
|
|
20
|
-
all: ['invitations'],
|
|
21
|
-
myList: () => [...exports.invitationKeys.all, 'my'],
|
|
22
|
-
entityList: (entitySlug) => [...useEntities_1.entityKeys.detail(entitySlug), 'invitations'],
|
|
23
|
-
};
|
|
24
|
-
/**
|
|
25
|
-
* Hook to list pending invitations for the current user.
|
|
26
|
-
*/
|
|
27
|
-
function useMyInvitations(client) {
|
|
28
|
-
return (0, react_query_1.useQuery)({
|
|
29
|
-
queryKey: exports.invitationKeys.myList(),
|
|
30
|
-
queryFn: async () => {
|
|
31
|
-
const response = await client.listMyInvitations();
|
|
32
|
-
if (!response.success || !response.data) {
|
|
33
|
-
throw new Error(response.error || 'Failed to fetch invitations');
|
|
34
|
-
}
|
|
35
|
-
return response.data;
|
|
36
|
-
},
|
|
37
|
-
});
|
|
38
|
-
}
|
|
39
|
-
/**
|
|
40
|
-
* Hook to list invitations for an entity.
|
|
41
|
-
*/
|
|
42
|
-
function useEntityInvitations(client, entitySlug) {
|
|
43
|
-
return (0, react_query_1.useQuery)({
|
|
44
|
-
queryKey: entitySlug ? exports.invitationKeys.entityList(entitySlug) : ['disabled'],
|
|
45
|
-
queryFn: async () => {
|
|
46
|
-
if (!entitySlug)
|
|
47
|
-
return [];
|
|
48
|
-
const response = await client.listEntityInvitations(entitySlug);
|
|
49
|
-
if (!response.success || !response.data) {
|
|
50
|
-
throw new Error(response.error || 'Failed to fetch invitations');
|
|
51
|
-
}
|
|
52
|
-
return response.data;
|
|
53
|
-
},
|
|
54
|
-
enabled: !!entitySlug,
|
|
55
|
-
});
|
|
56
|
-
}
|
|
57
|
-
/**
|
|
58
|
-
* Hook to create an invitation.
|
|
59
|
-
*/
|
|
60
|
-
function useCreateInvitation(client) {
|
|
61
|
-
const queryClient = (0, react_query_1.useQueryClient)();
|
|
62
|
-
return (0, react_query_1.useMutation)({
|
|
63
|
-
mutationFn: async ({ entitySlug, request, }) => {
|
|
64
|
-
const response = await client.createInvitation(entitySlug, request);
|
|
65
|
-
if (!response.success || !response.data) {
|
|
66
|
-
throw new Error(response.error || 'Failed to create invitation');
|
|
67
|
-
}
|
|
68
|
-
return response.data;
|
|
69
|
-
},
|
|
70
|
-
onSuccess: (_, variables) => {
|
|
71
|
-
queryClient.invalidateQueries({
|
|
72
|
-
queryKey: exports.invitationKeys.entityList(variables.entitySlug),
|
|
73
|
-
});
|
|
74
|
-
},
|
|
75
|
-
});
|
|
76
|
-
}
|
|
77
|
-
/**
|
|
78
|
-
* Hook to cancel an invitation.
|
|
79
|
-
*/
|
|
80
|
-
function useCancelInvitation(client) {
|
|
81
|
-
const queryClient = (0, react_query_1.useQueryClient)();
|
|
82
|
-
return (0, react_query_1.useMutation)({
|
|
83
|
-
mutationFn: async ({ entitySlug, invitationId, }) => {
|
|
84
|
-
const response = await client.cancelInvitation(entitySlug, invitationId);
|
|
85
|
-
if (!response.success) {
|
|
86
|
-
throw new Error(response.error || 'Failed to cancel invitation');
|
|
87
|
-
}
|
|
88
|
-
},
|
|
89
|
-
onSuccess: (_, variables) => {
|
|
90
|
-
queryClient.invalidateQueries({
|
|
91
|
-
queryKey: exports.invitationKeys.entityList(variables.entitySlug),
|
|
92
|
-
});
|
|
93
|
-
},
|
|
94
|
-
});
|
|
95
|
-
}
|
|
96
|
-
/**
|
|
97
|
-
* Hook to accept an invitation.
|
|
98
|
-
*/
|
|
99
|
-
function useAcceptInvitation(client) {
|
|
100
|
-
const queryClient = (0, react_query_1.useQueryClient)();
|
|
101
|
-
return (0, react_query_1.useMutation)({
|
|
102
|
-
mutationFn: async (token) => {
|
|
103
|
-
const response = await client.acceptInvitation(token);
|
|
104
|
-
if (!response.success) {
|
|
105
|
-
throw new Error(response.error || 'Failed to accept invitation');
|
|
106
|
-
}
|
|
107
|
-
},
|
|
108
|
-
onSuccess: () => {
|
|
109
|
-
// Invalidate both my invitations and entity list
|
|
110
|
-
queryClient.invalidateQueries({ queryKey: exports.invitationKeys.myList() });
|
|
111
|
-
queryClient.invalidateQueries({ queryKey: useEntities_1.entityKeys.lists() });
|
|
112
|
-
},
|
|
113
|
-
});
|
|
114
|
-
}
|
|
115
|
-
/**
|
|
116
|
-
* Hook to decline an invitation.
|
|
117
|
-
*/
|
|
118
|
-
function useDeclineInvitation(client) {
|
|
119
|
-
const queryClient = (0, react_query_1.useQueryClient)();
|
|
120
|
-
return (0, react_query_1.useMutation)({
|
|
121
|
-
mutationFn: async (token) => {
|
|
122
|
-
const response = await client.declineInvitation(token);
|
|
123
|
-
if (!response.success) {
|
|
124
|
-
throw new Error(response.error || 'Failed to decline invitation');
|
|
125
|
-
}
|
|
126
|
-
},
|
|
127
|
-
onSuccess: () => {
|
|
128
|
-
queryClient.invalidateQueries({ queryKey: exports.invitationKeys.myList() });
|
|
129
|
-
},
|
|
130
|
-
});
|
|
131
|
-
}
|
|
132
|
-
//# sourceMappingURL=useInvitations.js.map
|
package/dist/index.cjs
DELETED
|
@@ -1,58 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/**
|
|
3
|
-
* @fileoverview Entity Client Library
|
|
4
|
-
* @description Frontend client and React hooks for entity/organization management
|
|
5
|
-
*
|
|
6
|
-
* @example
|
|
7
|
-
* ```typescript
|
|
8
|
-
* import {
|
|
9
|
-
* EntityClient,
|
|
10
|
-
* useEntities,
|
|
11
|
-
* useCurrentEntity,
|
|
12
|
-
* CurrentEntityProvider,
|
|
13
|
-
* } from '@sudobility/entity_client';
|
|
14
|
-
*
|
|
15
|
-
* // Create client
|
|
16
|
-
* const client = new EntityClient({
|
|
17
|
-
* baseUrl: 'https://api.example.com/api/v1',
|
|
18
|
-
* getAuthToken: async () => firebase.currentUser?.getIdToken() ?? null,
|
|
19
|
-
* });
|
|
20
|
-
*
|
|
21
|
-
* // Use in React component
|
|
22
|
-
* function EntityList() {
|
|
23
|
-
* const { data: entities, isLoading } = useEntities(client);
|
|
24
|
-
* // ...
|
|
25
|
-
* }
|
|
26
|
-
* ```
|
|
27
|
-
*/
|
|
28
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
|
-
exports.CurrentEntityProvider = exports.useCurrentEntity = exports.invitationKeys = exports.useDeclineInvitation = exports.useAcceptInvitation = exports.useCancelInvitation = exports.useCreateInvitation = exports.useEntityInvitations = exports.useMyInvitations = exports.memberKeys = exports.useRemoveMember = exports.useUpdateMemberRole = exports.useEntityMembers = exports.entityKeys = exports.useDeleteEntity = exports.useUpdateEntity = exports.useCreateEntity = exports.useEntity = exports.useEntities = exports.EntityClient = void 0;
|
|
30
|
-
// Network exports
|
|
31
|
-
var network_1 = require("./network");
|
|
32
|
-
Object.defineProperty(exports, "EntityClient", { enumerable: true, get: function () { return network_1.EntityClient; } });
|
|
33
|
-
// Hook exports
|
|
34
|
-
var hooks_1 = require("./hooks");
|
|
35
|
-
// Entity hooks
|
|
36
|
-
Object.defineProperty(exports, "useEntities", { enumerable: true, get: function () { return hooks_1.useEntities; } });
|
|
37
|
-
Object.defineProperty(exports, "useEntity", { enumerable: true, get: function () { return hooks_1.useEntity; } });
|
|
38
|
-
Object.defineProperty(exports, "useCreateEntity", { enumerable: true, get: function () { return hooks_1.useCreateEntity; } });
|
|
39
|
-
Object.defineProperty(exports, "useUpdateEntity", { enumerable: true, get: function () { return hooks_1.useUpdateEntity; } });
|
|
40
|
-
Object.defineProperty(exports, "useDeleteEntity", { enumerable: true, get: function () { return hooks_1.useDeleteEntity; } });
|
|
41
|
-
Object.defineProperty(exports, "entityKeys", { enumerable: true, get: function () { return hooks_1.entityKeys; } });
|
|
42
|
-
// Member hooks
|
|
43
|
-
Object.defineProperty(exports, "useEntityMembers", { enumerable: true, get: function () { return hooks_1.useEntityMembers; } });
|
|
44
|
-
Object.defineProperty(exports, "useUpdateMemberRole", { enumerable: true, get: function () { return hooks_1.useUpdateMemberRole; } });
|
|
45
|
-
Object.defineProperty(exports, "useRemoveMember", { enumerable: true, get: function () { return hooks_1.useRemoveMember; } });
|
|
46
|
-
Object.defineProperty(exports, "memberKeys", { enumerable: true, get: function () { return hooks_1.memberKeys; } });
|
|
47
|
-
// Invitation hooks
|
|
48
|
-
Object.defineProperty(exports, "useMyInvitations", { enumerable: true, get: function () { return hooks_1.useMyInvitations; } });
|
|
49
|
-
Object.defineProperty(exports, "useEntityInvitations", { enumerable: true, get: function () { return hooks_1.useEntityInvitations; } });
|
|
50
|
-
Object.defineProperty(exports, "useCreateInvitation", { enumerable: true, get: function () { return hooks_1.useCreateInvitation; } });
|
|
51
|
-
Object.defineProperty(exports, "useCancelInvitation", { enumerable: true, get: function () { return hooks_1.useCancelInvitation; } });
|
|
52
|
-
Object.defineProperty(exports, "useAcceptInvitation", { enumerable: true, get: function () { return hooks_1.useAcceptInvitation; } });
|
|
53
|
-
Object.defineProperty(exports, "useDeclineInvitation", { enumerable: true, get: function () { return hooks_1.useDeclineInvitation; } });
|
|
54
|
-
Object.defineProperty(exports, "invitationKeys", { enumerable: true, get: function () { return hooks_1.invitationKeys; } });
|
|
55
|
-
// Context
|
|
56
|
-
Object.defineProperty(exports, "useCurrentEntity", { enumerable: true, get: function () { return hooks_1.useCurrentEntity; } });
|
|
57
|
-
Object.defineProperty(exports, "CurrentEntityProvider", { enumerable: true, get: function () { return hooks_1.CurrentEntityProvider; } });
|
|
58
|
-
//# sourceMappingURL=index.js.map
|
|
@@ -1,158 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/**
|
|
3
|
-
* @fileoverview Entity API Client
|
|
4
|
-
* @description HTTP client for entity/organization API endpoints
|
|
5
|
-
*/
|
|
6
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
-
exports.EntityClient = void 0;
|
|
8
|
-
/**
|
|
9
|
-
* HTTP client for entity management APIs.
|
|
10
|
-
*/
|
|
11
|
-
class EntityClient {
|
|
12
|
-
constructor(config) {
|
|
13
|
-
this.config = config;
|
|
14
|
-
}
|
|
15
|
-
/**
|
|
16
|
-
* Make an authenticated API request.
|
|
17
|
-
*/
|
|
18
|
-
async request(path, options = {}) {
|
|
19
|
-
const token = await this.config.getAuthToken();
|
|
20
|
-
if (!token) {
|
|
21
|
-
return { success: false, error: 'Not authenticated' };
|
|
22
|
-
}
|
|
23
|
-
const url = `${this.config.baseUrl}${path}`;
|
|
24
|
-
const headers = {
|
|
25
|
-
'Content-Type': 'application/json',
|
|
26
|
-
Authorization: `Bearer ${token}`,
|
|
27
|
-
...options.headers,
|
|
28
|
-
};
|
|
29
|
-
try {
|
|
30
|
-
const response = await fetch(url, {
|
|
31
|
-
...options,
|
|
32
|
-
headers,
|
|
33
|
-
});
|
|
34
|
-
const data = await response.json();
|
|
35
|
-
return data;
|
|
36
|
-
}
|
|
37
|
-
catch (error) {
|
|
38
|
-
return { success: false, error: error.message };
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
// =============================================================================
|
|
42
|
-
// Entity CRUD
|
|
43
|
-
// =============================================================================
|
|
44
|
-
/**
|
|
45
|
-
* List all entities for the current user.
|
|
46
|
-
*/
|
|
47
|
-
async listEntities() {
|
|
48
|
-
return this.request('/entities');
|
|
49
|
-
}
|
|
50
|
-
/**
|
|
51
|
-
* Create a new organization entity.
|
|
52
|
-
*/
|
|
53
|
-
async createEntity(request) {
|
|
54
|
-
return this.request('/entities', {
|
|
55
|
-
method: 'POST',
|
|
56
|
-
body: JSON.stringify(request),
|
|
57
|
-
});
|
|
58
|
-
}
|
|
59
|
-
/**
|
|
60
|
-
* Get entity by slug.
|
|
61
|
-
*/
|
|
62
|
-
async getEntity(entitySlug) {
|
|
63
|
-
return this.request(`/entities/${entitySlug}`);
|
|
64
|
-
}
|
|
65
|
-
/**
|
|
66
|
-
* Update entity.
|
|
67
|
-
*/
|
|
68
|
-
async updateEntity(entitySlug, request) {
|
|
69
|
-
return this.request(`/entities/${entitySlug}`, {
|
|
70
|
-
method: 'PUT',
|
|
71
|
-
body: JSON.stringify(request),
|
|
72
|
-
});
|
|
73
|
-
}
|
|
74
|
-
/**
|
|
75
|
-
* Delete entity (organizations only).
|
|
76
|
-
*/
|
|
77
|
-
async deleteEntity(entitySlug) {
|
|
78
|
-
return this.request(`/entities/${entitySlug}`, {
|
|
79
|
-
method: 'DELETE',
|
|
80
|
-
});
|
|
81
|
-
}
|
|
82
|
-
// =============================================================================
|
|
83
|
-
// Member Management
|
|
84
|
-
// =============================================================================
|
|
85
|
-
/**
|
|
86
|
-
* List members of an entity.
|
|
87
|
-
*/
|
|
88
|
-
async listMembers(entitySlug) {
|
|
89
|
-
return this.request(`/entities/${entitySlug}/members`);
|
|
90
|
-
}
|
|
91
|
-
/**
|
|
92
|
-
* Update a member's role.
|
|
93
|
-
*/
|
|
94
|
-
async updateMemberRole(entitySlug, memberId, role) {
|
|
95
|
-
return this.request(`/entities/${entitySlug}/members/${memberId}`, {
|
|
96
|
-
method: 'PUT',
|
|
97
|
-
body: JSON.stringify({ role }),
|
|
98
|
-
});
|
|
99
|
-
}
|
|
100
|
-
/**
|
|
101
|
-
* Remove a member from the entity.
|
|
102
|
-
*/
|
|
103
|
-
async removeMember(entitySlug, memberId) {
|
|
104
|
-
return this.request(`/entities/${entitySlug}/members/${memberId}`, {
|
|
105
|
-
method: 'DELETE',
|
|
106
|
-
});
|
|
107
|
-
}
|
|
108
|
-
// =============================================================================
|
|
109
|
-
// Invitation Management
|
|
110
|
-
// =============================================================================
|
|
111
|
-
/**
|
|
112
|
-
* List invitations for an entity.
|
|
113
|
-
*/
|
|
114
|
-
async listEntityInvitations(entitySlug) {
|
|
115
|
-
return this.request(`/entities/${entitySlug}/invitations`);
|
|
116
|
-
}
|
|
117
|
-
/**
|
|
118
|
-
* Create an invitation.
|
|
119
|
-
*/
|
|
120
|
-
async createInvitation(entitySlug, request) {
|
|
121
|
-
return this.request(`/entities/${entitySlug}/invitations`, {
|
|
122
|
-
method: 'POST',
|
|
123
|
-
body: JSON.stringify(request),
|
|
124
|
-
});
|
|
125
|
-
}
|
|
126
|
-
/**
|
|
127
|
-
* Cancel an invitation.
|
|
128
|
-
*/
|
|
129
|
-
async cancelInvitation(entitySlug, invitationId) {
|
|
130
|
-
return this.request(`/entities/${entitySlug}/invitations/${invitationId}`, {
|
|
131
|
-
method: 'DELETE',
|
|
132
|
-
});
|
|
133
|
-
}
|
|
134
|
-
/**
|
|
135
|
-
* List pending invitations for the current user.
|
|
136
|
-
*/
|
|
137
|
-
async listMyInvitations() {
|
|
138
|
-
return this.request('/invitations');
|
|
139
|
-
}
|
|
140
|
-
/**
|
|
141
|
-
* Accept an invitation.
|
|
142
|
-
*/
|
|
143
|
-
async acceptInvitation(token) {
|
|
144
|
-
return this.request(`/invitations/${token}/accept`, {
|
|
145
|
-
method: 'POST',
|
|
146
|
-
});
|
|
147
|
-
}
|
|
148
|
-
/**
|
|
149
|
-
* Decline an invitation.
|
|
150
|
-
*/
|
|
151
|
-
async declineInvitation(token) {
|
|
152
|
-
return this.request(`/invitations/${token}/decline`, {
|
|
153
|
-
method: 'POST',
|
|
154
|
-
});
|
|
155
|
-
}
|
|
156
|
-
}
|
|
157
|
-
exports.EntityClient = EntityClient;
|
|
158
|
-
//# sourceMappingURL=EntityClient.js.map
|
package/dist/network/index.cjs
DELETED
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/**
|
|
3
|
-
* @fileoverview Network Exports
|
|
4
|
-
*/
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.EntityClient = void 0;
|
|
7
|
-
var EntityClient_1 = require("./EntityClient");
|
|
8
|
-
Object.defineProperty(exports, "EntityClient", { enumerable: true, get: function () { return EntityClient_1.EntityClient; } });
|
|
9
|
-
//# sourceMappingURL=index.js.map
|