@burdenoff/microfe-workspaces 2026.601.1 → 2026.601.3
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/hooks/useMemberMutations.js +36 -24
- package/dist/hooks/useMemberMutations.js.map +1 -1
- package/dist/hooks/useProjectMutations.js +19 -15
- package/dist/hooks/useProjectMutations.js.map +1 -1
- package/dist/hooks/useWorkspaceMutations.js +19 -11
- package/dist/hooks/useWorkspaceMutations.js.map +1 -1
- package/package.json +1 -1
|
@@ -6,7 +6,17 @@ import { useMutation as m, useQueryClient as h } from "@tanstack/react-query";
|
|
|
6
6
|
import { print as g } from "graphql";
|
|
7
7
|
import { graphqlFetch as _ } from "@burdenoff/fe-libs/shared/graphql";
|
|
8
8
|
//#region src/hooks/useMemberMutations.ts
|
|
9
|
-
|
|
9
|
+
function v(e, t) {
|
|
10
|
+
e.invalidateQueries({ queryKey: ["workspaceMembers"] }), e.invalidateQueries({ queryKey: ["workspaceMembersInfinite"] }), e.invalidateQueries({ queryKey: ["userWorkspaces"] }), e.invalidateQueries({ queryKey: ["myWorkspaces"] }), e.invalidateQueries({ queryKey: ["dashboard", "global"] }), t && (e.invalidateQueries({ queryKey: ["workspaceMembers", t] }), e.invalidateQueries({ queryKey: ["workspaceMembersInfinite", t] }), e.invalidateQueries({ queryKey: [
|
|
11
|
+
"dashboard",
|
|
12
|
+
"workspace",
|
|
13
|
+
t
|
|
14
|
+
] }));
|
|
15
|
+
}
|
|
16
|
+
function y(e, t, n) {
|
|
17
|
+
e.invalidateQueries({ queryKey: ["workspaceInvitations"] }), e.invalidateQueries({ queryKey: ["myPendingInvitations"] }), t && e.invalidateQueries({ queryKey: ["invitation", t] }), n && e.invalidateQueries({ queryKey: ["workspaceInvitations", n] });
|
|
18
|
+
}
|
|
19
|
+
var b = () => {
|
|
10
20
|
let { authToken: t, workspaceId: r } = e(), i = h(), { emit: a } = f();
|
|
11
21
|
return m({
|
|
12
22
|
mutationFn: async (e) => {
|
|
@@ -22,7 +32,7 @@ var v = () => {
|
|
|
22
32
|
return i.data.addWorkspaceMember;
|
|
23
33
|
},
|
|
24
34
|
onSuccess: (e) => {
|
|
25
|
-
|
|
35
|
+
v(i, e.workspaceId), a("workspace-member.added", {
|
|
26
36
|
memberId: e.id,
|
|
27
37
|
workspaceId: e.workspaceId,
|
|
28
38
|
userId: e.userId,
|
|
@@ -38,7 +48,7 @@ var v = () => {
|
|
|
38
48
|
});
|
|
39
49
|
}
|
|
40
50
|
});
|
|
41
|
-
},
|
|
51
|
+
}, x = (t) => {
|
|
42
52
|
let { authToken: n, workspaceId: r } = e(), i = h(), { emit: a } = f(), o = t || r;
|
|
43
53
|
return m({
|
|
44
54
|
mutationFn: async (e) => {
|
|
@@ -54,7 +64,7 @@ var v = () => {
|
|
|
54
64
|
return t.data.removeWorkspaceMember;
|
|
55
65
|
},
|
|
56
66
|
onSuccess: (e, t) => {
|
|
57
|
-
|
|
67
|
+
v(i, o), a("workspace-member.removed", {
|
|
58
68
|
memberId: t,
|
|
59
69
|
source: "microfe-workspaces"
|
|
60
70
|
});
|
|
@@ -68,7 +78,7 @@ var v = () => {
|
|
|
68
78
|
});
|
|
69
79
|
}
|
|
70
80
|
});
|
|
71
|
-
},
|
|
81
|
+
}, S = (t) => {
|
|
72
82
|
let { authToken: n, workspaceId: r } = e(), i = h(), { emit: a } = f(), o = t || r;
|
|
73
83
|
return m({
|
|
74
84
|
mutationFn: async (e) => {
|
|
@@ -84,7 +94,7 @@ var v = () => {
|
|
|
84
94
|
return t.data.removeUserFromWorkspace;
|
|
85
95
|
},
|
|
86
96
|
onSuccess: (e, t) => {
|
|
87
|
-
i
|
|
97
|
+
v(i, o), i.invalidateQueries({ queryKey: ["userWorkspaces", t] }), a("workspace-member.removed", {
|
|
88
98
|
userId: t,
|
|
89
99
|
source: "microfe-workspaces"
|
|
90
100
|
});
|
|
@@ -98,7 +108,7 @@ var v = () => {
|
|
|
98
108
|
});
|
|
99
109
|
}
|
|
100
110
|
});
|
|
101
|
-
},
|
|
111
|
+
}, C = (t) => {
|
|
102
112
|
let { authToken: n, workspaceId: r } = e(), i = h(), { emit: o } = f(), s = t || r;
|
|
103
113
|
return m({
|
|
104
114
|
mutationFn: async (e) => {
|
|
@@ -115,7 +125,7 @@ var v = () => {
|
|
|
115
125
|
},
|
|
116
126
|
onSuccess: (e) => {
|
|
117
127
|
let t = e.workspaceId ?? s;
|
|
118
|
-
|
|
128
|
+
y(i, e.id, t), o("workspace-invitation.created", {
|
|
119
129
|
invitationId: e.id,
|
|
120
130
|
workspaceId: e.workspaceId,
|
|
121
131
|
email: e.email,
|
|
@@ -131,7 +141,7 @@ var v = () => {
|
|
|
131
141
|
});
|
|
132
142
|
}
|
|
133
143
|
});
|
|
134
|
-
},
|
|
144
|
+
}, w = () => {
|
|
135
145
|
let { authToken: t, workspaceId: n } = e(), r = h(), { emit: i } = f();
|
|
136
146
|
return m({
|
|
137
147
|
mutationFn: async ({ id: e, input: r }) => {
|
|
@@ -150,7 +160,7 @@ var v = () => {
|
|
|
150
160
|
return i.data.updateInvitation;
|
|
151
161
|
},
|
|
152
162
|
onSuccess: (e) => {
|
|
153
|
-
r.
|
|
163
|
+
y(r, e.id, e.workspaceId), i("workspace-invitation.updated", {
|
|
154
164
|
invitationId: e.id,
|
|
155
165
|
workspaceId: e.workspaceId,
|
|
156
166
|
source: "microfe-workspaces"
|
|
@@ -165,7 +175,7 @@ var v = () => {
|
|
|
165
175
|
});
|
|
166
176
|
}
|
|
167
177
|
});
|
|
168
|
-
},
|
|
178
|
+
}, T = () => {
|
|
169
179
|
let { authToken: n, workspaceId: r } = e(), i = h(), { emit: a } = f();
|
|
170
180
|
return m({
|
|
171
181
|
mutationFn: async (e) => {
|
|
@@ -181,7 +191,7 @@ var v = () => {
|
|
|
181
191
|
return i.data.acceptInvitation;
|
|
182
192
|
},
|
|
183
193
|
onSuccess: (e) => {
|
|
184
|
-
i
|
|
194
|
+
y(i, e.id, e.workspaceId), v(i, e.workspaceId), a("workspace-invitation.accepted", {
|
|
185
195
|
invitationId: e.id,
|
|
186
196
|
workspaceId: e.workspaceId,
|
|
187
197
|
source: "microfe-workspaces"
|
|
@@ -196,7 +206,7 @@ var v = () => {
|
|
|
196
206
|
});
|
|
197
207
|
}
|
|
198
208
|
});
|
|
199
|
-
},
|
|
209
|
+
}, E = () => {
|
|
200
210
|
let { authToken: t, workspaceId: n } = e(), r = h(), { emit: i } = f();
|
|
201
211
|
return m({
|
|
202
212
|
mutationFn: async (e) => {
|
|
@@ -212,7 +222,7 @@ var v = () => {
|
|
|
212
222
|
return r.data.rejectInvitation;
|
|
213
223
|
},
|
|
214
224
|
onSuccess: (e) => {
|
|
215
|
-
r.
|
|
225
|
+
y(r, e.id, e.workspaceId), i("workspace-invitation.rejected", {
|
|
216
226
|
invitationId: e.id,
|
|
217
227
|
workspaceId: e.workspaceId,
|
|
218
228
|
source: "microfe-workspaces"
|
|
@@ -227,7 +237,7 @@ var v = () => {
|
|
|
227
237
|
});
|
|
228
238
|
}
|
|
229
239
|
});
|
|
230
|
-
},
|
|
240
|
+
}, D = (t) => {
|
|
231
241
|
let { authToken: n, workspaceId: r } = e(), a = h(), { emit: o } = f(), s = t || r;
|
|
232
242
|
return m({
|
|
233
243
|
mutationFn: async (e) => {
|
|
@@ -243,7 +253,7 @@ var v = () => {
|
|
|
243
253
|
return t.data.cancelInvitation;
|
|
244
254
|
},
|
|
245
255
|
onSuccess: (e) => {
|
|
246
|
-
a.
|
|
256
|
+
y(a, e.id, e.workspaceId ?? s), o("workspace-invitation.cancelled", {
|
|
247
257
|
invitationId: e.id,
|
|
248
258
|
workspaceId: e.workspaceId,
|
|
249
259
|
source: "microfe-workspaces"
|
|
@@ -258,7 +268,7 @@ var v = () => {
|
|
|
258
268
|
});
|
|
259
269
|
}
|
|
260
270
|
});
|
|
261
|
-
},
|
|
271
|
+
}, O = (t) => {
|
|
262
272
|
let { authToken: n, workspaceId: r } = e(), i = h(), { emit: a } = f(), o = t || r;
|
|
263
273
|
return m({
|
|
264
274
|
mutationFn: async (e) => {
|
|
@@ -274,7 +284,7 @@ var v = () => {
|
|
|
274
284
|
return t.data.resendInvitation;
|
|
275
285
|
},
|
|
276
286
|
onSuccess: (e) => {
|
|
277
|
-
i.
|
|
287
|
+
y(i, e.id, e.workspaceId ?? o), a("workspace-invitation.resent", {
|
|
278
288
|
invitationId: e.id,
|
|
279
289
|
workspaceId: e.workspaceId,
|
|
280
290
|
source: "microfe-workspaces"
|
|
@@ -289,7 +299,7 @@ var v = () => {
|
|
|
289
299
|
});
|
|
290
300
|
}
|
|
291
301
|
});
|
|
292
|
-
},
|
|
302
|
+
}, k = () => {
|
|
293
303
|
let { authToken: t, workspaceId: n } = e(), r = h(), { emit: i } = f();
|
|
294
304
|
return m({
|
|
295
305
|
mutationFn: async (e) => {
|
|
@@ -305,7 +315,7 @@ var v = () => {
|
|
|
305
315
|
return r.data.deleteInvitation;
|
|
306
316
|
},
|
|
307
317
|
onSuccess: (e, t) => {
|
|
308
|
-
r
|
|
318
|
+
y(r, t, n), i("workspace-invitation.deleted", {
|
|
309
319
|
invitationId: t,
|
|
310
320
|
source: "microfe-workspaces"
|
|
311
321
|
});
|
|
@@ -319,7 +329,7 @@ var v = () => {
|
|
|
319
329
|
});
|
|
320
330
|
}
|
|
321
331
|
});
|
|
322
|
-
},
|
|
332
|
+
}, A = () => {
|
|
323
333
|
let { authToken: t, workspaceId: n } = e(), i = h();
|
|
324
334
|
return m({
|
|
325
335
|
mutationFn: async (e) => {
|
|
@@ -334,12 +344,14 @@ var v = () => {
|
|
|
334
344
|
if (i.errors?.length) throw Error(i.errors[0]?.message || "GraphQL error");
|
|
335
345
|
return i.data.bulkCreateInvitations;
|
|
336
346
|
},
|
|
337
|
-
onSuccess: () => {
|
|
338
|
-
i.invalidateQueries({ queryKey: ["workspaceInvitations"] });
|
|
347
|
+
onSuccess: (e) => {
|
|
348
|
+
i.invalidateQueries({ queryKey: ["workspaceInvitations"] }), i.invalidateQueries({ queryKey: ["myPendingInvitations"] });
|
|
349
|
+
let t = new Set(e.map((e) => e.workspaceId).filter(Boolean));
|
|
350
|
+
for (let e of t) i.invalidateQueries({ queryKey: ["workspaceInvitations", e] });
|
|
339
351
|
}
|
|
340
352
|
});
|
|
341
353
|
};
|
|
342
354
|
//#endregion
|
|
343
|
-
export {
|
|
355
|
+
export { T as useAcceptInvitation, b as useAddWorkspaceMember, A as useBulkCreateInvitations, D as useCancelInvitation, C as useCreateInvitation, k as useDeleteInvitation, E as useRejectInvitation, S as useRemoveUserFromWorkspace, x as useRemoveWorkspaceMember, O as useResendInvitation, w as useUpdateInvitation };
|
|
344
356
|
|
|
345
357
|
//# sourceMappingURL=useMemberMutations.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useMemberMutations.js","names":[],"sources":["../../src/hooks/useMemberMutations.ts"],"sourcesContent":["import { useMutation, useQueryClient } from '@tanstack/react-query';\nimport { print } from 'graphql';\nimport { graphqlFetch } from '@burdenoff/fe-libs/shared/graphql';\nimport { useWorkspacesContext } from '../providers/WorkspacesProvider';\nimport {\n AddWorkspaceMemberDocument,\n RemoveWorkspaceMemberDocument,\n RemoveUserFromWorkspaceDocument,\n CreateInvitationDocument,\n UpdateInvitationDocument,\n AcceptInvitationDocument,\n RejectInvitationDocument,\n CancelInvitationDocument,\n ResendInvitationDocument,\n DeleteInvitationDocument,\n BulkCreateInvitationsDocument,\n} from '../generated/wspace-operations';\nimport type {\n WorkspaceMember,\n WorkspaceInvitation,\n AddWorkspaceMemberInput,\n CreateInvitationInput,\n UpdateInvitationInput,\n} from '../types';\nimport { useWorkspacesEventEmitter } from './useWorkspacesEventEmitter';\nimport { safeTelemetryError } from '../utils/telemetryError';\n\n/**\n * Hook to add a member to a workspace\n * Requires x-workspace-id header for workspace context\n */\nexport const useAddWorkspaceMember = () => {\n const { authToken, workspaceId } = useWorkspacesContext();\n const queryClient = useQueryClient();\n const { emit } = useWorkspacesEventEmitter();\n\n return useMutation({\n mutationFn: async (input: AddWorkspaceMemberInput): Promise<WorkspaceMember> => {\n const result = await graphqlFetch<{ addWorkspaceMember: WorkspaceMember }>({\n gateway: 'workspace',\n authToken: authToken || undefined,\n query: print(AddWorkspaceMemberDocument),\n variables: { input },\n workspaceId: workspaceId || undefined,\n workspaceToken: true, // Auto-read from profile context for x-workspace-id header\n });\n\n if (result.errors?.length) {\n throw new Error(result.errors[0]?.message || 'GraphQL error');\n }\n\n return result.data!.addWorkspaceMember;\n },\n onSuccess: (data) => {\n queryClient.invalidateQueries({ queryKey: ['workspaceMembers', data.workspaceId] });\n queryClient.invalidateQueries({\n queryKey: ['workspaceMembersInfinite', data.workspaceId],\n });\n queryClient.invalidateQueries({ queryKey: ['userWorkspaces'] });\n emit('workspace-member.added', {\n memberId: data.id,\n workspaceId: data.workspaceId,\n userId: data.userId,\n source: 'microfe-workspaces',\n });\n },\n onError: (err, input) => {\n emit('workspace-member.add_failed', {\n workspaceId: workspaceId || undefined,\n userId: input?.userId,\n source: 'microfe-workspaces',\n errorMessage: safeTelemetryError(err),\n });\n },\n });\n};\n\n/**\n * Hook to remove a member from a workspace by member ID\n */\nexport const useRemoveWorkspaceMember = (workspaceIdOverride?: string) => {\n const { authToken, workspaceId } = useWorkspacesContext();\n const queryClient = useQueryClient();\n const { emit } = useWorkspacesEventEmitter();\n const effectiveWorkspaceId = workspaceIdOverride || workspaceId;\n\n return useMutation({\n mutationFn: async (id: string): Promise<boolean> => {\n const result = await graphqlFetch<{ removeWorkspaceMember: boolean }>({\n gateway: 'workspace',\n authToken: authToken || undefined,\n query: print(RemoveWorkspaceMemberDocument),\n variables: { id },\n workspaceId: effectiveWorkspaceId || undefined,\n workspaceToken: true, // Required by gateway RBAC for wspace-scoped operations\n });\n\n if (result.errors?.length) {\n throw new Error(result.errors[0]?.message || 'GraphQL error');\n }\n\n return result.data!.removeWorkspaceMember;\n },\n onSuccess: (_, id) => {\n queryClient.invalidateQueries({ queryKey: ['workspaceMembers'] });\n queryClient.invalidateQueries({ queryKey: ['workspaceMembersInfinite'] });\n queryClient.invalidateQueries({ queryKey: ['userWorkspaces'] });\n emit('workspace-member.removed', { memberId: id, source: 'microfe-workspaces' });\n },\n onError: (err, id) => {\n emit('workspace-member.remove_failed', {\n memberId: id,\n workspaceId: effectiveWorkspaceId || undefined,\n source: 'microfe-workspaces',\n errorMessage: safeTelemetryError(err),\n });\n },\n });\n};\n\n/**\n * Hook to remove a user from a workspace\n * Requires x-workspace-id header for workspace context\n */\nexport const useRemoveUserFromWorkspace = (workspaceIdOverride?: string) => {\n const { authToken, workspaceId } = useWorkspacesContext();\n const queryClient = useQueryClient();\n const { emit } = useWorkspacesEventEmitter();\n const effectiveWorkspaceId = workspaceIdOverride || workspaceId;\n\n return useMutation({\n mutationFn: async (userId: string): Promise<boolean> => {\n const result = await graphqlFetch<{ removeUserFromWorkspace: boolean }>({\n gateway: 'workspace',\n authToken: authToken || undefined,\n query: print(RemoveUserFromWorkspaceDocument),\n variables: { userId },\n workspaceId: effectiveWorkspaceId || undefined,\n workspaceToken: true, // Auto-read from profile context for x-workspace-id header\n });\n\n if (result.errors?.length) {\n throw new Error(result.errors[0]?.message || 'GraphQL error');\n }\n\n return result.data!.removeUserFromWorkspace;\n },\n onSuccess: (_, userId) => {\n queryClient.invalidateQueries({ queryKey: ['workspaceMembers'] });\n queryClient.invalidateQueries({ queryKey: ['workspaceMembersInfinite'] });\n queryClient.invalidateQueries({ queryKey: ['userWorkspaces', userId] });\n emit('workspace-member.removed', { userId, source: 'microfe-workspaces' });\n },\n onError: (err, userId) => {\n emit('workspace-member.remove_failed', {\n userId,\n workspaceId: effectiveWorkspaceId || undefined,\n source: 'microfe-workspaces',\n errorMessage: safeTelemetryError(err),\n });\n },\n });\n};\n\n/**\n * NOTE: The updateWorkspaceMemberRoles mutation has been removed from the backend.\n * Role management is now handled via invitations - when creating an invitation,\n * you can specify roleIds that will be assigned when the invitation is accepted.\n *\n * Use CreateInvitationInput.roleIds to assign roles to new members.\n */\n\n/**\n * Hook to create a workspace invitation\n * Uses x-workspace-id header as fallback when input.workspaceId is not provided\n */\nexport const useCreateInvitation = (workspaceIdOverride?: string) => {\n const { authToken, workspaceId } = useWorkspacesContext();\n const queryClient = useQueryClient();\n const { emit } = useWorkspacesEventEmitter();\n const effectiveWorkspaceId = workspaceIdOverride || workspaceId;\n\n return useMutation({\n mutationFn: async (input: CreateInvitationInput): Promise<WorkspaceInvitation> => {\n const result = await graphqlFetch<{ createInvitation: WorkspaceInvitation }>({\n gateway: 'workspace',\n authToken: authToken || undefined,\n query: print(CreateInvitationDocument),\n variables: { input },\n workspaceId: input.workspaceId || effectiveWorkspaceId || undefined,\n workspaceToken: true, // Auto-read from profile context for x-workspace-id header fallback\n });\n\n if (result.errors?.length) {\n throw new Error(result.errors[0]?.message || 'GraphQL error');\n }\n\n return result.data!.createInvitation;\n },\n onSuccess: (data) => {\n const wsId = data.workspaceId ?? effectiveWorkspaceId;\n if (wsId) {\n queryClient.invalidateQueries({ queryKey: ['workspaceInvitations', wsId] });\n }\n emit('workspace-invitation.created', {\n invitationId: data.id,\n workspaceId: data.workspaceId,\n email: data.email,\n source: 'microfe-workspaces',\n });\n },\n onError: (err, input) => {\n emit('workspace-invitation.create_failed', {\n workspaceId: input?.workspaceId || effectiveWorkspaceId || undefined,\n email: input?.email,\n source: 'microfe-workspaces',\n errorMessage: safeTelemetryError(err),\n });\n },\n });\n};\n\n/**\n * Hook to update an invitation\n */\nexport const useUpdateInvitation = () => {\n const { authToken, workspaceId } = useWorkspacesContext();\n const queryClient = useQueryClient();\n const { emit } = useWorkspacesEventEmitter();\n\n return useMutation({\n mutationFn: async ({\n id,\n input,\n }: {\n id: string;\n input: UpdateInvitationInput;\n }): Promise<WorkspaceInvitation> => {\n const result = await graphqlFetch<{ updateInvitation: WorkspaceInvitation }>({\n gateway: 'workspace',\n authToken: authToken || undefined,\n query: print(UpdateInvitationDocument),\n variables: { id, input },\n workspaceId: workspaceId || undefined,\n workspaceToken: true, // Required by gateway RBAC for wspace-scoped operations\n });\n\n if (result.errors?.length) {\n throw new Error(result.errors[0]?.message || 'GraphQL error');\n }\n\n return result.data!.updateInvitation;\n },\n onSuccess: (data) => {\n queryClient.invalidateQueries({ queryKey: ['workspaceInvitations'] });\n emit('workspace-invitation.updated', {\n invitationId: data.id,\n workspaceId: data.workspaceId,\n source: 'microfe-workspaces',\n });\n },\n onError: (err, variables) => {\n emit('workspace-invitation.update_failed', {\n invitationId: variables?.id,\n workspaceId: workspaceId || undefined,\n source: 'microfe-workspaces',\n errorMessage: safeTelemetryError(err),\n });\n },\n });\n};\n\n/**\n * Hook to accept an invitation\n */\nexport const useAcceptInvitation = () => {\n const { authToken, workspaceId } = useWorkspacesContext();\n const queryClient = useQueryClient();\n const { emit } = useWorkspacesEventEmitter();\n\n return useMutation({\n mutationFn: async (id: string): Promise<WorkspaceInvitation> => {\n const result = await graphqlFetch<{ acceptInvitation: WorkspaceInvitation }>({\n gateway: 'workspace',\n authToken: authToken || undefined,\n query: print(AcceptInvitationDocument),\n variables: { id },\n workspaceId: workspaceId || undefined,\n workspaceToken: true, // Required by gateway RBAC for wspace-scoped operations\n });\n\n if (result.errors?.length) {\n throw new Error(result.errors[0]?.message || 'GraphQL error');\n }\n\n return result.data!.acceptInvitation;\n },\n onSuccess: (data) => {\n queryClient.invalidateQueries({ queryKey: ['workspaceInvitations'] });\n queryClient.invalidateQueries({ queryKey: ['myPendingInvitations'] });\n queryClient.invalidateQueries({ queryKey: ['workspaceMembers'] });\n queryClient.invalidateQueries({ queryKey: ['userWorkspaces'] });\n queryClient.invalidateQueries({ queryKey: ['myWorkspaces'] });\n emit('workspace-invitation.accepted', {\n invitationId: data.id,\n workspaceId: data.workspaceId,\n source: 'microfe-workspaces',\n });\n },\n onError: (err, id) => {\n emit('workspace-invitation.accept_failed', {\n invitationId: id,\n workspaceId: workspaceId || undefined,\n source: 'microfe-workspaces',\n errorMessage: safeTelemetryError(err),\n });\n },\n });\n};\n\n/**\n * Hook to reject an invitation\n */\nexport const useRejectInvitation = () => {\n const { authToken, workspaceId } = useWorkspacesContext();\n const queryClient = useQueryClient();\n const { emit } = useWorkspacesEventEmitter();\n\n return useMutation({\n mutationFn: async (id: string): Promise<WorkspaceInvitation> => {\n const result = await graphqlFetch<{ rejectInvitation: WorkspaceInvitation }>({\n gateway: 'workspace',\n authToken: authToken || undefined,\n query: print(RejectInvitationDocument),\n variables: { id },\n workspaceId: workspaceId || undefined,\n workspaceToken: true, // Required by gateway RBAC for wspace-scoped operations\n });\n\n if (result.errors?.length) {\n throw new Error(result.errors[0]?.message || 'GraphQL error');\n }\n\n return result.data!.rejectInvitation;\n },\n onSuccess: (data) => {\n queryClient.invalidateQueries({ queryKey: ['workspaceInvitations'] });\n queryClient.invalidateQueries({ queryKey: ['myPendingInvitations'] });\n emit('workspace-invitation.rejected', {\n invitationId: data.id,\n workspaceId: data.workspaceId,\n source: 'microfe-workspaces',\n });\n },\n onError: (err, id) => {\n emit('workspace-invitation.reject_failed', {\n invitationId: id,\n workspaceId: workspaceId || undefined,\n source: 'microfe-workspaces',\n errorMessage: safeTelemetryError(err),\n });\n },\n });\n};\n\n/**\n * Hook to cancel an invitation\n */\nexport const useCancelInvitation = (workspaceIdOverride?: string) => {\n const { authToken, workspaceId } = useWorkspacesContext();\n const queryClient = useQueryClient();\n const { emit } = useWorkspacesEventEmitter();\n const effectiveWorkspaceId = workspaceIdOverride || workspaceId;\n\n return useMutation({\n mutationFn: async (id: string): Promise<WorkspaceInvitation> => {\n const result = await graphqlFetch<{ cancelInvitation: WorkspaceInvitation }>({\n gateway: 'workspace',\n authToken: authToken || undefined,\n query: print(CancelInvitationDocument),\n variables: { id },\n workspaceId: effectiveWorkspaceId || undefined,\n workspaceToken: true, // Required by gateway RBAC for wspace-scoped operations\n });\n\n if (result.errors?.length) {\n throw new Error(result.errors[0]?.message || 'GraphQL error');\n }\n\n return result.data!.cancelInvitation;\n },\n onSuccess: (data) => {\n queryClient.invalidateQueries({ queryKey: ['workspaceInvitations'] });\n emit('workspace-invitation.cancelled', {\n invitationId: data.id,\n workspaceId: data.workspaceId,\n source: 'microfe-workspaces',\n });\n },\n onError: (err, id) => {\n emit('workspace-invitation.cancel_failed', {\n invitationId: id,\n workspaceId: effectiveWorkspaceId || undefined,\n source: 'microfe-workspaces',\n errorMessage: safeTelemetryError(err),\n });\n },\n });\n};\n\n/**\n * Hook to resend an invitation\n */\nexport const useResendInvitation = (workspaceIdOverride?: string) => {\n const { authToken, workspaceId } = useWorkspacesContext();\n const queryClient = useQueryClient();\n const { emit } = useWorkspacesEventEmitter();\n const effectiveWorkspaceId = workspaceIdOverride || workspaceId;\n\n return useMutation({\n mutationFn: async (id: string): Promise<WorkspaceInvitation> => {\n const result = await graphqlFetch<{ resendInvitation: WorkspaceInvitation }>({\n gateway: 'workspace',\n authToken: authToken || undefined,\n query: print(ResendInvitationDocument),\n variables: { id },\n workspaceId: effectiveWorkspaceId || undefined,\n workspaceToken: true, // Required by gateway RBAC for wspace-scoped operations\n });\n\n if (result.errors?.length) {\n throw new Error(result.errors[0]?.message || 'GraphQL error');\n }\n\n return result.data!.resendInvitation;\n },\n onSuccess: (data) => {\n queryClient.invalidateQueries({ queryKey: ['workspaceInvitations'] });\n emit('workspace-invitation.resent', {\n invitationId: data.id,\n workspaceId: data.workspaceId,\n source: 'microfe-workspaces',\n });\n },\n onError: (err, id) => {\n emit('workspace-invitation.resend_failed', {\n invitationId: id,\n workspaceId: effectiveWorkspaceId || undefined,\n source: 'microfe-workspaces',\n errorMessage: safeTelemetryError(err),\n });\n },\n });\n};\n\n/**\n * Hook to delete an invitation\n */\nexport const useDeleteInvitation = () => {\n const { authToken, workspaceId } = useWorkspacesContext();\n const queryClient = useQueryClient();\n const { emit } = useWorkspacesEventEmitter();\n\n return useMutation({\n mutationFn: async (id: string): Promise<boolean> => {\n const result = await graphqlFetch<{ deleteInvitation: boolean }>({\n gateway: 'workspace',\n authToken: authToken || undefined,\n query: print(DeleteInvitationDocument),\n variables: { id },\n workspaceId: workspaceId || undefined,\n workspaceToken: true, // Required by gateway RBAC for wspace-scoped operations\n });\n\n if (result.errors?.length) {\n throw new Error(result.errors[0]?.message || 'GraphQL error');\n }\n\n return result.data!.deleteInvitation;\n },\n onSuccess: (_, id) => {\n queryClient.invalidateQueries({ queryKey: ['workspaceInvitations'] });\n emit('workspace-invitation.deleted', { invitationId: id, source: 'microfe-workspaces' });\n },\n onError: (err, id) => {\n emit('workspace-invitation.delete_failed', {\n invitationId: id,\n workspaceId: workspaceId || undefined,\n source: 'microfe-workspaces',\n errorMessage: safeTelemetryError(err),\n });\n },\n });\n};\n\n/**\n * Hook to bulk create invitations\n * Uses x-workspace-id header as fallback when inputs[].workspaceId is not provided\n */\nexport const useBulkCreateInvitations = () => {\n const { authToken, workspaceId } = useWorkspacesContext();\n const queryClient = useQueryClient();\n\n return useMutation({\n mutationFn: async (inputs: CreateInvitationInput[]): Promise<WorkspaceInvitation[]> => {\n const result = await graphqlFetch<{ bulkCreateInvitations: WorkspaceInvitation[] }>({\n gateway: 'workspace',\n authToken: authToken || undefined,\n query: print(BulkCreateInvitationsDocument),\n variables: { inputs },\n workspaceId: inputs[0]?.workspaceId || workspaceId || undefined,\n workspaceToken: true, // Auto-read from profile context for x-workspace-id header fallback\n });\n\n if (result.errors?.length) {\n throw new Error(result.errors[0]?.message || 'GraphQL error');\n }\n\n return result.data!.bulkCreateInvitations;\n },\n onSuccess: () => {\n queryClient.invalidateQueries({ queryKey: ['workspaceInvitations'] });\n },\n });\n};\n"],"mappings":";;;;;;;;AA+BA,IAAa,UAA8B;CACzC,IAAM,EAAE,cAAW,mBAAgB,GAAsB,EACnD,IAAc,GAAgB,EAC9B,EAAE,YAAS,GAA2B;AAE5C,QAAO,EAAY;EACjB,YAAY,OAAO,MAA6D;GAC9E,IAAM,IAAS,MAAM,EAAsD;IACzE,SAAS;IACT,WAAW,KAAa,KAAA;IACxB,OAAO,EAAM,EAA2B;I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D,SAAS;IACT,WAAW,KAAa,KAAA;IACxB,OAAO,EAAM,EAAyB;IACtC,WAAW,EAAE,OAAI;IACjB,aAAa,KAAe,KAAA;IAC5B,gBAAgB;IACjB,CAAC;AAEF,OAAI,EAAO,QAAQ,OACjB,OAAU,MAAM,EAAO,OAAO,IAAI,WAAW,gBAAgB;AAG/D,UAAO,EAAO,KAAM;;EAEtB,YAAY,GAAG,MAAO;AAEpB,GADA,EAAY,kBAAkB,EAAE,UAAU,CAAC,uBAAuB,EAAE,CAAC,EACrE,EAAK,gCAAgC;IAAE,cAAc;IAAI,QAAQ;IAAsB,CAAC;;EAE1F,UAAU,GAAK,MAAO;AACpB,KAAK,sCAAsC;IACzC,cAAc;IACd,aAAa,KAAe,KAAA;IAC5B,QAAQ;IACR,cAAc,EAAmB,EAAI;IACtC,CAAC;;EAEL,CAAC;GAOS,UAAiC;CAC5C,IAAM,EAAE,cAAW,mBAAgB,GAAsB,EACnD,IAAc,GAAgB;AAEpC,QAAO,EAAY;EACjB,YAAY,OAAO,MAAoE;GACrF,IAAM,IAAS,MAAM,EAA+D;IAClF,SAAS;IACT,WAAW,KAAa,KAAA;IACxB,OAAO,EAAM,EAA8B;IAC3C,WAAW,EAAE,WAAQ;IACrB,aAAa,EAAO,IAAI,eAAe,KAAe,KAAA;IACtD,gBAAgB;IACjB,CAAC;AAEF,OAAI,EAAO,QAAQ,OACjB,OAAU,MAAM,EAAO,OAAO,IAAI,WAAW,gBAAgB;AAG/D,UAAO,EAAO,KAAM;;EAEtB,iBAAiB;AACf,KAAY,kBAAkB,EAAE,UAAU,CAAC,uBAAuB,EAAE,CAAC;;EAExE,CAAC"}
|
|
1
|
+
{"version":3,"file":"useMemberMutations.js","names":[],"sources":["../../src/hooks/useMemberMutations.ts"],"sourcesContent":["import { useMutation, useQueryClient, type QueryClient } from '@tanstack/react-query';\nimport { print } from 'graphql';\nimport { graphqlFetch } from '@burdenoff/fe-libs/shared/graphql';\nimport { useWorkspacesContext } from '../providers/WorkspacesProvider';\nimport {\n AddWorkspaceMemberDocument,\n RemoveWorkspaceMemberDocument,\n RemoveUserFromWorkspaceDocument,\n CreateInvitationDocument,\n UpdateInvitationDocument,\n AcceptInvitationDocument,\n RejectInvitationDocument,\n CancelInvitationDocument,\n ResendInvitationDocument,\n DeleteInvitationDocument,\n BulkCreateInvitationsDocument,\n} from '../generated/wspace-operations';\nimport type {\n WorkspaceMember,\n WorkspaceInvitation,\n AddWorkspaceMemberInput,\n CreateInvitationInput,\n UpdateInvitationInput,\n} from '../types';\nimport { useWorkspacesEventEmitter } from './useWorkspacesEventEmitter';\nimport { safeTelemetryError } from '../utils/telemetryError';\n\nfunction invalidateMemberViews(queryClient: QueryClient, workspaceId?: string | null) {\n queryClient.invalidateQueries({ queryKey: ['workspaceMembers'] });\n queryClient.invalidateQueries({ queryKey: ['workspaceMembersInfinite'] });\n queryClient.invalidateQueries({ queryKey: ['userWorkspaces'] });\n queryClient.invalidateQueries({ queryKey: ['myWorkspaces'] });\n queryClient.invalidateQueries({ queryKey: ['dashboard', 'global'] });\n if (workspaceId) {\n queryClient.invalidateQueries({ queryKey: ['workspaceMembers', workspaceId] });\n queryClient.invalidateQueries({ queryKey: ['workspaceMembersInfinite', workspaceId] });\n queryClient.invalidateQueries({ queryKey: ['dashboard', 'workspace', workspaceId] });\n }\n}\n\nfunction invalidateInvitationViews(\n queryClient: QueryClient,\n invitationId?: string,\n workspaceId?: string | null\n) {\n queryClient.invalidateQueries({ queryKey: ['workspaceInvitations'] });\n queryClient.invalidateQueries({ queryKey: ['myPendingInvitations'] });\n if (invitationId) {\n queryClient.invalidateQueries({ queryKey: ['invitation', invitationId] });\n }\n if (workspaceId) {\n queryClient.invalidateQueries({ queryKey: ['workspaceInvitations', workspaceId] });\n }\n}\n\n/**\n * Hook to add a member to a workspace\n * Requires x-workspace-id header for workspace context\n */\nexport const useAddWorkspaceMember = () => {\n const { authToken, workspaceId } = useWorkspacesContext();\n const queryClient = useQueryClient();\n const { emit } = useWorkspacesEventEmitter();\n\n return useMutation({\n mutationFn: async (input: AddWorkspaceMemberInput): Promise<WorkspaceMember> => {\n const result = await graphqlFetch<{ addWorkspaceMember: WorkspaceMember }>({\n gateway: 'workspace',\n authToken: authToken || undefined,\n query: print(AddWorkspaceMemberDocument),\n variables: { input },\n workspaceId: workspaceId || undefined,\n workspaceToken: true, // Auto-read from profile context for x-workspace-id header\n });\n\n if (result.errors?.length) {\n throw new Error(result.errors[0]?.message || 'GraphQL error');\n }\n\n return result.data!.addWorkspaceMember;\n },\n onSuccess: (data) => {\n invalidateMemberViews(queryClient, data.workspaceId);\n emit('workspace-member.added', {\n memberId: data.id,\n workspaceId: data.workspaceId,\n userId: data.userId,\n source: 'microfe-workspaces',\n });\n },\n onError: (err, input) => {\n emit('workspace-member.add_failed', {\n workspaceId: workspaceId || undefined,\n userId: input?.userId,\n source: 'microfe-workspaces',\n errorMessage: safeTelemetryError(err),\n });\n },\n });\n};\n\n/**\n * Hook to remove a member from a workspace by member ID\n */\nexport const useRemoveWorkspaceMember = (workspaceIdOverride?: string) => {\n const { authToken, workspaceId } = useWorkspacesContext();\n const queryClient = useQueryClient();\n const { emit } = useWorkspacesEventEmitter();\n const effectiveWorkspaceId = workspaceIdOverride || workspaceId;\n\n return useMutation({\n mutationFn: async (id: string): Promise<boolean> => {\n const result = await graphqlFetch<{ removeWorkspaceMember: boolean }>({\n gateway: 'workspace',\n authToken: authToken || undefined,\n query: print(RemoveWorkspaceMemberDocument),\n variables: { id },\n workspaceId: effectiveWorkspaceId || undefined,\n workspaceToken: true, // Required by gateway RBAC for wspace-scoped operations\n });\n\n if (result.errors?.length) {\n throw new Error(result.errors[0]?.message || 'GraphQL error');\n }\n\n return result.data!.removeWorkspaceMember;\n },\n onSuccess: (_, id) => {\n invalidateMemberViews(queryClient, effectiveWorkspaceId);\n emit('workspace-member.removed', { memberId: id, source: 'microfe-workspaces' });\n },\n onError: (err, id) => {\n emit('workspace-member.remove_failed', {\n memberId: id,\n workspaceId: effectiveWorkspaceId || undefined,\n source: 'microfe-workspaces',\n errorMessage: safeTelemetryError(err),\n });\n },\n });\n};\n\n/**\n * Hook to remove a user from a workspace\n * Requires x-workspace-id header for workspace context\n */\nexport const useRemoveUserFromWorkspace = (workspaceIdOverride?: string) => {\n const { authToken, workspaceId } = useWorkspacesContext();\n const queryClient = useQueryClient();\n const { emit } = useWorkspacesEventEmitter();\n const effectiveWorkspaceId = workspaceIdOverride || workspaceId;\n\n return useMutation({\n mutationFn: async (userId: string): Promise<boolean> => {\n const result = await graphqlFetch<{ removeUserFromWorkspace: boolean }>({\n gateway: 'workspace',\n authToken: authToken || undefined,\n query: print(RemoveUserFromWorkspaceDocument),\n variables: { userId },\n workspaceId: effectiveWorkspaceId || undefined,\n workspaceToken: true, // Auto-read from profile context for x-workspace-id header\n });\n\n if (result.errors?.length) {\n throw new Error(result.errors[0]?.message || 'GraphQL error');\n }\n\n return result.data!.removeUserFromWorkspace;\n },\n onSuccess: (_, userId) => {\n invalidateMemberViews(queryClient, effectiveWorkspaceId);\n queryClient.invalidateQueries({ queryKey: ['userWorkspaces', userId] });\n emit('workspace-member.removed', { userId, source: 'microfe-workspaces' });\n },\n onError: (err, userId) => {\n emit('workspace-member.remove_failed', {\n userId,\n workspaceId: effectiveWorkspaceId || undefined,\n source: 'microfe-workspaces',\n errorMessage: safeTelemetryError(err),\n });\n },\n });\n};\n\n/**\n * NOTE: The updateWorkspaceMemberRoles mutation has been removed from the backend.\n * Role management is now handled via invitations - when creating an invitation,\n * you can specify roleIds that will be assigned when the invitation is accepted.\n *\n * Use CreateInvitationInput.roleIds to assign roles to new members.\n */\n\n/**\n * Hook to create a workspace invitation\n * Uses x-workspace-id header as fallback when input.workspaceId is not provided\n */\nexport const useCreateInvitation = (workspaceIdOverride?: string) => {\n const { authToken, workspaceId } = useWorkspacesContext();\n const queryClient = useQueryClient();\n const { emit } = useWorkspacesEventEmitter();\n const effectiveWorkspaceId = workspaceIdOverride || workspaceId;\n\n return useMutation({\n mutationFn: async (input: CreateInvitationInput): Promise<WorkspaceInvitation> => {\n const result = await graphqlFetch<{ createInvitation: WorkspaceInvitation }>({\n gateway: 'workspace',\n authToken: authToken || undefined,\n query: print(CreateInvitationDocument),\n variables: { input },\n workspaceId: input.workspaceId || effectiveWorkspaceId || undefined,\n workspaceToken: true, // Auto-read from profile context for x-workspace-id header fallback\n });\n\n if (result.errors?.length) {\n throw new Error(result.errors[0]?.message || 'GraphQL error');\n }\n\n return result.data!.createInvitation;\n },\n onSuccess: (data) => {\n const wsId = data.workspaceId ?? effectiveWorkspaceId;\n invalidateInvitationViews(queryClient, data.id, wsId);\n emit('workspace-invitation.created', {\n invitationId: data.id,\n workspaceId: data.workspaceId,\n email: data.email,\n source: 'microfe-workspaces',\n });\n },\n onError: (err, input) => {\n emit('workspace-invitation.create_failed', {\n workspaceId: input?.workspaceId || effectiveWorkspaceId || undefined,\n email: input?.email,\n source: 'microfe-workspaces',\n errorMessage: safeTelemetryError(err),\n });\n },\n });\n};\n\n/**\n * Hook to update an invitation\n */\nexport const useUpdateInvitation = () => {\n const { authToken, workspaceId } = useWorkspacesContext();\n const queryClient = useQueryClient();\n const { emit } = useWorkspacesEventEmitter();\n\n return useMutation({\n mutationFn: async ({\n id,\n input,\n }: {\n id: string;\n input: UpdateInvitationInput;\n }): Promise<WorkspaceInvitation> => {\n const result = await graphqlFetch<{ updateInvitation: WorkspaceInvitation }>({\n gateway: 'workspace',\n authToken: authToken || undefined,\n query: print(UpdateInvitationDocument),\n variables: { id, input },\n workspaceId: workspaceId || undefined,\n workspaceToken: true, // Required by gateway RBAC for wspace-scoped operations\n });\n\n if (result.errors?.length) {\n throw new Error(result.errors[0]?.message || 'GraphQL error');\n }\n\n return result.data!.updateInvitation;\n },\n onSuccess: (data) => {\n invalidateInvitationViews(queryClient, data.id, data.workspaceId);\n emit('workspace-invitation.updated', {\n invitationId: data.id,\n workspaceId: data.workspaceId,\n source: 'microfe-workspaces',\n });\n },\n onError: (err, variables) => {\n emit('workspace-invitation.update_failed', {\n invitationId: variables?.id,\n workspaceId: workspaceId || undefined,\n source: 'microfe-workspaces',\n errorMessage: safeTelemetryError(err),\n });\n },\n });\n};\n\n/**\n * Hook to accept an invitation\n */\nexport const useAcceptInvitation = () => {\n const { authToken, workspaceId } = useWorkspacesContext();\n const queryClient = useQueryClient();\n const { emit } = useWorkspacesEventEmitter();\n\n return useMutation({\n mutationFn: async (id: string): Promise<WorkspaceInvitation> => {\n const result = await graphqlFetch<{ acceptInvitation: WorkspaceInvitation }>({\n gateway: 'workspace',\n authToken: authToken || undefined,\n query: print(AcceptInvitationDocument),\n variables: { id },\n workspaceId: workspaceId || undefined,\n workspaceToken: true, // Required by gateway RBAC for wspace-scoped operations\n });\n\n if (result.errors?.length) {\n throw new Error(result.errors[0]?.message || 'GraphQL error');\n }\n\n return result.data!.acceptInvitation;\n },\n onSuccess: (data) => {\n invalidateInvitationViews(queryClient, data.id, data.workspaceId);\n invalidateMemberViews(queryClient, data.workspaceId);\n emit('workspace-invitation.accepted', {\n invitationId: data.id,\n workspaceId: data.workspaceId,\n source: 'microfe-workspaces',\n });\n },\n onError: (err, id) => {\n emit('workspace-invitation.accept_failed', {\n invitationId: id,\n workspaceId: workspaceId || undefined,\n source: 'microfe-workspaces',\n errorMessage: safeTelemetryError(err),\n });\n },\n });\n};\n\n/**\n * Hook to reject an invitation\n */\nexport const useRejectInvitation = () => {\n const { authToken, workspaceId } = useWorkspacesContext();\n const queryClient = useQueryClient();\n const { emit } = useWorkspacesEventEmitter();\n\n return useMutation({\n mutationFn: async (id: string): Promise<WorkspaceInvitation> => {\n const result = await graphqlFetch<{ rejectInvitation: WorkspaceInvitation }>({\n gateway: 'workspace',\n authToken: authToken || undefined,\n query: print(RejectInvitationDocument),\n variables: { id },\n workspaceId: workspaceId || undefined,\n workspaceToken: true, // Required by gateway RBAC for wspace-scoped operations\n });\n\n if (result.errors?.length) {\n throw new Error(result.errors[0]?.message || 'GraphQL error');\n }\n\n return result.data!.rejectInvitation;\n },\n onSuccess: (data) => {\n invalidateInvitationViews(queryClient, data.id, data.workspaceId);\n emit('workspace-invitation.rejected', {\n invitationId: data.id,\n workspaceId: data.workspaceId,\n source: 'microfe-workspaces',\n });\n },\n onError: (err, id) => {\n emit('workspace-invitation.reject_failed', {\n invitationId: id,\n workspaceId: workspaceId || undefined,\n source: 'microfe-workspaces',\n errorMessage: safeTelemetryError(err),\n });\n },\n });\n};\n\n/**\n * Hook to cancel an invitation\n */\nexport const useCancelInvitation = (workspaceIdOverride?: string) => {\n const { authToken, workspaceId } = useWorkspacesContext();\n const queryClient = useQueryClient();\n const { emit } = useWorkspacesEventEmitter();\n const effectiveWorkspaceId = workspaceIdOverride || workspaceId;\n\n return useMutation({\n mutationFn: async (id: string): Promise<WorkspaceInvitation> => {\n const result = await graphqlFetch<{ cancelInvitation: WorkspaceInvitation }>({\n gateway: 'workspace',\n authToken: authToken || undefined,\n query: print(CancelInvitationDocument),\n variables: { id },\n workspaceId: effectiveWorkspaceId || undefined,\n workspaceToken: true, // Required by gateway RBAC for wspace-scoped operations\n });\n\n if (result.errors?.length) {\n throw new Error(result.errors[0]?.message || 'GraphQL error');\n }\n\n return result.data!.cancelInvitation;\n },\n onSuccess: (data) => {\n invalidateInvitationViews(queryClient, data.id, data.workspaceId ?? effectiveWorkspaceId);\n emit('workspace-invitation.cancelled', {\n invitationId: data.id,\n workspaceId: data.workspaceId,\n source: 'microfe-workspaces',\n });\n },\n onError: (err, id) => {\n emit('workspace-invitation.cancel_failed', {\n invitationId: id,\n workspaceId: effectiveWorkspaceId || undefined,\n source: 'microfe-workspaces',\n errorMessage: safeTelemetryError(err),\n });\n },\n });\n};\n\n/**\n * Hook to resend an invitation\n */\nexport const useResendInvitation = (workspaceIdOverride?: string) => {\n const { authToken, workspaceId } = useWorkspacesContext();\n const queryClient = useQueryClient();\n const { emit } = useWorkspacesEventEmitter();\n const effectiveWorkspaceId = workspaceIdOverride || workspaceId;\n\n return useMutation({\n mutationFn: async (id: string): Promise<WorkspaceInvitation> => {\n const result = await graphqlFetch<{ resendInvitation: WorkspaceInvitation }>({\n gateway: 'workspace',\n authToken: authToken || undefined,\n query: print(ResendInvitationDocument),\n variables: { id },\n workspaceId: effectiveWorkspaceId || undefined,\n workspaceToken: true, // Required by gateway RBAC for wspace-scoped operations\n });\n\n if (result.errors?.length) {\n throw new Error(result.errors[0]?.message || 'GraphQL error');\n }\n\n return result.data!.resendInvitation;\n },\n onSuccess: (data) => {\n invalidateInvitationViews(queryClient, data.id, data.workspaceId ?? effectiveWorkspaceId);\n emit('workspace-invitation.resent', {\n invitationId: data.id,\n workspaceId: data.workspaceId,\n source: 'microfe-workspaces',\n });\n },\n onError: (err, id) => {\n emit('workspace-invitation.resend_failed', {\n invitationId: id,\n workspaceId: effectiveWorkspaceId || undefined,\n source: 'microfe-workspaces',\n errorMessage: safeTelemetryError(err),\n });\n },\n });\n};\n\n/**\n * Hook to delete an invitation\n */\nexport const useDeleteInvitation = () => {\n const { authToken, workspaceId } = useWorkspacesContext();\n const queryClient = useQueryClient();\n const { emit } = useWorkspacesEventEmitter();\n\n return useMutation({\n mutationFn: async (id: string): Promise<boolean> => {\n const result = await graphqlFetch<{ deleteInvitation: boolean }>({\n gateway: 'workspace',\n authToken: authToken || undefined,\n query: print(DeleteInvitationDocument),\n variables: { id },\n workspaceId: workspaceId || undefined,\n workspaceToken: true, // Required by gateway RBAC for wspace-scoped operations\n });\n\n if (result.errors?.length) {\n throw new Error(result.errors[0]?.message || 'GraphQL error');\n }\n\n return result.data!.deleteInvitation;\n },\n onSuccess: (_, id) => {\n invalidateInvitationViews(queryClient, id, workspaceId);\n emit('workspace-invitation.deleted', { invitationId: id, source: 'microfe-workspaces' });\n },\n onError: (err, id) => {\n emit('workspace-invitation.delete_failed', {\n invitationId: id,\n workspaceId: workspaceId || undefined,\n source: 'microfe-workspaces',\n errorMessage: safeTelemetryError(err),\n });\n },\n });\n};\n\n/**\n * Hook to bulk create invitations\n * Uses x-workspace-id header as fallback when inputs[].workspaceId is not provided\n */\nexport const useBulkCreateInvitations = () => {\n const { authToken, workspaceId } = useWorkspacesContext();\n const queryClient = useQueryClient();\n\n return useMutation({\n mutationFn: async (inputs: CreateInvitationInput[]): Promise<WorkspaceInvitation[]> => {\n const result = await graphqlFetch<{ bulkCreateInvitations: WorkspaceInvitation[] }>({\n gateway: 'workspace',\n authToken: authToken || undefined,\n query: print(BulkCreateInvitationsDocument),\n variables: { inputs },\n workspaceId: inputs[0]?.workspaceId || workspaceId || undefined,\n workspaceToken: true, // Auto-read from profile context for x-workspace-id header fallback\n });\n\n if (result.errors?.length) {\n throw new Error(result.errors[0]?.message || 'GraphQL error');\n }\n\n return result.data!.bulkCreateInvitations;\n },\n onSuccess: (invitations) => {\n queryClient.invalidateQueries({ queryKey: ['workspaceInvitations'] });\n queryClient.invalidateQueries({ queryKey: ['myPendingInvitations'] });\n const workspaceIds = new Set(\n invitations.map((invitation) => invitation.workspaceId).filter(Boolean)\n );\n for (const wsId of workspaceIds) {\n queryClient.invalidateQueries({ queryKey: ['workspaceInvitations', wsId] });\n }\n },\n });\n};\n"],"mappings":";;;;;;;;AA2BA,SAAS,EAAsB,GAA0B,GAA6B;AAMpF,CALA,EAAY,kBAAkB,EAAE,UAAU,CAAC,mBAAmB,EAAE,CAAC,EACjE,EAAY,kBAAkB,EAAE,UAAU,CAAC,2BAA2B,EAAE,CAAC,EACzE,EAAY,kBAAkB,EAAE,UAAU,CAAC,iBAAiB,EAAE,CAAC,EAC/D,EAAY,kBAAkB,EAAE,UAAU,CAAC,eAAe,EAAE,CAAC,EAC7D,EAAY,kBAAkB,EAAE,UAAU,CAAC,aAAa,SAAS,EAAE,CAAC,EAChE,MACF,EAAY,kBAAkB,EAAE,UAAU,CAAC,oBAAoB,EAAY,EAAE,CAAC,EAC9E,EAAY,kBAAkB,EAAE,UAAU,CAAC,4BAA4B,EAAY,EAAE,CAAC,EACtF,EAAY,kBAAkB,EAAE,UAAU;EAAC;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;AAG/D,UAAO,EAAO,KAAM;;EAEtB,YAAY,GAAG,MAAO;AAEpB,GADA,EAA0B,GAAa,GAAI,EAAY,EACvD,EAAK,gCAAgC;IAAE,cAAc;IAAI,QAAQ;IAAsB,CAAC;;EAE1F,UAAU,GAAK,MAAO;AACpB,KAAK,sCAAsC;IACzC,cAAc;IACd,aAAa,KAAe,KAAA;IAC5B,QAAQ;IACR,cAAc,EAAmB,EAAI;IACtC,CAAC;;EAEL,CAAC;GAOS,UAAiC;CAC5C,IAAM,EAAE,cAAW,mBAAgB,GAAsB,EACnD,IAAc,GAAgB;AAEpC,QAAO,EAAY;EACjB,YAAY,OAAO,MAAoE;GACrF,IAAM,IAAS,MAAM,EAA+D;IAClF,SAAS;IACT,WAAW,KAAa,KAAA;IACxB,OAAO,EAAM,EAA8B;IAC3C,WAAW,EAAE,WAAQ;IACrB,aAAa,EAAO,IAAI,eAAe,KAAe,KAAA;IACtD,gBAAgB;IACjB,CAAC;AAEF,OAAI,EAAO,QAAQ,OACjB,OAAU,MAAM,EAAO,OAAO,IAAI,WAAW,gBAAgB;AAG/D,UAAO,EAAO,KAAM;;EAEtB,YAAY,MAAgB;AAE1B,GADA,EAAY,kBAAkB,EAAE,UAAU,CAAC,uBAAuB,EAAE,CAAC,EACrE,EAAY,kBAAkB,EAAE,UAAU,CAAC,uBAAuB,EAAE,CAAC;GACrE,IAAM,IAAe,IAAI,IACvB,EAAY,KAAK,MAAe,EAAW,YAAY,CAAC,OAAO,QAAQ,CACxE;AACD,QAAK,IAAM,KAAQ,EACjB,GAAY,kBAAkB,EAAE,UAAU,CAAC,wBAAwB,EAAK,EAAE,CAAC;;EAGhF,CAAC"}
|
|
@@ -4,7 +4,11 @@ import { safeTelemetryError as n } from "../utils/telemetryError.js";
|
|
|
4
4
|
import { useMutation as r, useQueryClient as i } from "@tanstack/react-query";
|
|
5
5
|
import { graphqlFetch as a } from "@burdenoff/fe-libs/shared/graphql";
|
|
6
6
|
//#region src/hooks/useProjectMutations.ts
|
|
7
|
-
var o = "\n mutation CreateProject($input: CreateProjectInput!) {\n createProject(input: $input) {\n id\n name\n key\n workspaceId\n creatorId\n status\n tags\n createdAt\n }\n }\n", s = "\n mutation UpdateProject($id: ID!, $input: UpdateProjectInput!) {\n updateProject(id: $id, input: $input) {\n id\n name\n key\n status\n config\n tags\n archived\n updatedAt\n }\n }\n", c = "\n mutation DeleteProject($id: ID!) {\n deleteProject(id: $id)\n }\n", l = "\n mutation ArchiveProject($id: ID!) {\n archiveProject(id: $id) {\n id\n archived\n updatedAt\n }\n }\n", u = "\n mutation UnarchiveProject($id: ID!) {\n unarchiveProject(id: $id) {\n id\n archived\n updatedAt\n }\n }\n", d = "\n mutation AssignProjectTag($input: AssignTagInput!) {\n assignTag(input: $input) {\n id\n tagId\n entityType\n entityId\n source\n assignedById\n createdAt\n validFrom\n validTo\n metadata\n }\n }\n", f = "\n query GetProjectTagAssignments($entityType: String!, $entityId: ID!) {\n getEntityTags(entityType: $entityType, entityId: $entityId) {\n id\n tagId\n }\n }\n", p = "\n mutation RemoveTagAssignment($id: ID!) {\n removeTagAssignment(id: $id)\n }\n"
|
|
7
|
+
var o = "\n mutation CreateProject($input: CreateProjectInput!) {\n createProject(input: $input) {\n id\n name\n key\n workspaceId\n creatorId\n status\n tags\n createdAt\n }\n }\n", s = "\n mutation UpdateProject($id: ID!, $input: UpdateProjectInput!) {\n updateProject(id: $id, input: $input) {\n id\n name\n key\n status\n config\n tags\n archived\n updatedAt\n }\n }\n", c = "\n mutation DeleteProject($id: ID!) {\n deleteProject(id: $id)\n }\n", l = "\n mutation ArchiveProject($id: ID!) {\n archiveProject(id: $id) {\n id\n archived\n updatedAt\n }\n }\n", u = "\n mutation UnarchiveProject($id: ID!) {\n unarchiveProject(id: $id) {\n id\n archived\n updatedAt\n }\n }\n", d = "\n mutation AssignProjectTag($input: AssignTagInput!) {\n assignTag(input: $input) {\n id\n tagId\n entityType\n entityId\n source\n assignedById\n createdAt\n validFrom\n validTo\n metadata\n }\n }\n", f = "\n query GetProjectTagAssignments($entityType: String!, $entityId: ID!) {\n getEntityTags(entityType: $entityType, entityId: $entityId) {\n id\n tagId\n }\n }\n", p = "\n mutation RemoveTagAssignment($id: ID!) {\n removeTagAssignment(id: $id)\n }\n";
|
|
8
|
+
function m(e) {
|
|
9
|
+
e.invalidateQueries({ queryKey: ["projects"] }), e.invalidateQueries({ queryKey: ["project"] }), e.invalidateQueries({ queryKey: ["myProjects"] }), e.invalidateQueries({ queryKey: ["dashboard", "projects"] });
|
|
10
|
+
}
|
|
11
|
+
var h = (s) => {
|
|
8
12
|
let { authToken: c, onProjectCreate: l, workspaceId: u } = e(), d = i(), { emit: f } = t(), p = s || u;
|
|
9
13
|
return r({
|
|
10
14
|
mutationFn: async (e) => {
|
|
@@ -20,7 +24,7 @@ var o = "\n mutation CreateProject($input: CreateProjectInput!) {\n createPr
|
|
|
20
24
|
return t.data.createProject;
|
|
21
25
|
},
|
|
22
26
|
onSuccess: (e) => {
|
|
23
|
-
|
|
27
|
+
m(d), f("project.created", {
|
|
24
28
|
projectId: e.id,
|
|
25
29
|
workspaceId: e.workspaceId,
|
|
26
30
|
source: "microfe-workspaces"
|
|
@@ -34,7 +38,7 @@ var o = "\n mutation CreateProject($input: CreateProjectInput!) {\n createPr
|
|
|
34
38
|
});
|
|
35
39
|
}
|
|
36
40
|
});
|
|
37
|
-
},
|
|
41
|
+
}, g = (o) => {
|
|
38
42
|
let { authToken: c, workspaceId: l } = e(), u = i(), { emit: d } = t(), f = o || l;
|
|
39
43
|
return r({
|
|
40
44
|
mutationFn: async ({ id: e, input: t }) => {
|
|
@@ -53,7 +57,7 @@ var o = "\n mutation CreateProject($input: CreateProjectInput!) {\n createPr
|
|
|
53
57
|
return n.data.updateProject;
|
|
54
58
|
},
|
|
55
59
|
onSuccess: (e) => {
|
|
56
|
-
|
|
60
|
+
m(u), d("project.updated", {
|
|
57
61
|
projectId: e.id,
|
|
58
62
|
workspaceId: e.workspaceId,
|
|
59
63
|
source: "microfe-workspaces"
|
|
@@ -68,7 +72,7 @@ var o = "\n mutation CreateProject($input: CreateProjectInput!) {\n createPr
|
|
|
68
72
|
});
|
|
69
73
|
}
|
|
70
74
|
});
|
|
71
|
-
},
|
|
75
|
+
}, _ = (o) => {
|
|
72
76
|
let { authToken: s, workspaceId: c } = e(), l = i(), { emit: u } = t(), f = o || c;
|
|
73
77
|
return r({
|
|
74
78
|
mutationFn: async (e) => {
|
|
@@ -106,7 +110,7 @@ var o = "\n mutation CreateProject($input: CreateProjectInput!) {\n createPr
|
|
|
106
110
|
};
|
|
107
111
|
},
|
|
108
112
|
onSuccess: (e, t) => {
|
|
109
|
-
|
|
113
|
+
m(l), u("project.updated", {
|
|
110
114
|
projectId: t.entityId,
|
|
111
115
|
workspaceId: f || void 0,
|
|
112
116
|
source: "microfe-workspaces"
|
|
@@ -121,7 +125,7 @@ var o = "\n mutation CreateProject($input: CreateProjectInput!) {\n createPr
|
|
|
121
125
|
});
|
|
122
126
|
}
|
|
123
127
|
});
|
|
124
|
-
},
|
|
128
|
+
}, v = (o) => {
|
|
125
129
|
let { authToken: s, workspaceId: c } = e(), l = i(), { emit: u } = t(), d = o || c;
|
|
126
130
|
return r({
|
|
127
131
|
mutationFn: async (e) => {
|
|
@@ -154,7 +158,7 @@ var o = "\n mutation CreateProject($input: CreateProjectInput!) {\n createPr
|
|
|
154
158
|
return n.data?.removeTagAssignment ?? !1;
|
|
155
159
|
},
|
|
156
160
|
onSuccess: (e, t) => {
|
|
157
|
-
|
|
161
|
+
m(l), u("project.updated", {
|
|
158
162
|
projectId: t.entityId,
|
|
159
163
|
workspaceId: d || void 0,
|
|
160
164
|
source: "microfe-workspaces"
|
|
@@ -169,7 +173,7 @@ var o = "\n mutation CreateProject($input: CreateProjectInput!) {\n createPr
|
|
|
169
173
|
});
|
|
170
174
|
}
|
|
171
175
|
});
|
|
172
|
-
},
|
|
176
|
+
}, y = (o) => {
|
|
173
177
|
let { authToken: s, workspaceId: l } = e(), u = i(), { emit: d } = t(), f = o || l;
|
|
174
178
|
return r({
|
|
175
179
|
mutationFn: async (e) => {
|
|
@@ -185,7 +189,7 @@ var o = "\n mutation CreateProject($input: CreateProjectInput!) {\n createPr
|
|
|
185
189
|
return t.data.deleteProject;
|
|
186
190
|
},
|
|
187
191
|
onSuccess: (e, t) => {
|
|
188
|
-
|
|
192
|
+
m(u), d("project.deleted", {
|
|
189
193
|
projectId: t,
|
|
190
194
|
source: "microfe-workspaces"
|
|
191
195
|
});
|
|
@@ -199,7 +203,7 @@ var o = "\n mutation CreateProject($input: CreateProjectInput!) {\n createPr
|
|
|
199
203
|
});
|
|
200
204
|
}
|
|
201
205
|
});
|
|
202
|
-
},
|
|
206
|
+
}, b = (o) => {
|
|
203
207
|
let { authToken: s, workspaceId: c } = e(), u = i(), { emit: d } = t(), f = o || c;
|
|
204
208
|
return r({
|
|
205
209
|
mutationFn: async (e) => {
|
|
@@ -215,7 +219,7 @@ var o = "\n mutation CreateProject($input: CreateProjectInput!) {\n createPr
|
|
|
215
219
|
return t.data.archiveProject;
|
|
216
220
|
},
|
|
217
221
|
onSuccess: (e) => {
|
|
218
|
-
|
|
222
|
+
m(u), d("project.archived", {
|
|
219
223
|
projectId: e.id,
|
|
220
224
|
workspaceId: e.workspaceId,
|
|
221
225
|
source: "microfe-workspaces"
|
|
@@ -230,7 +234,7 @@ var o = "\n mutation CreateProject($input: CreateProjectInput!) {\n createPr
|
|
|
230
234
|
});
|
|
231
235
|
}
|
|
232
236
|
});
|
|
233
|
-
},
|
|
237
|
+
}, x = (o) => {
|
|
234
238
|
let { authToken: s, workspaceId: c } = e(), l = i(), { emit: d } = t(), f = o || c;
|
|
235
239
|
return r({
|
|
236
240
|
mutationFn: async (e) => {
|
|
@@ -246,7 +250,7 @@ var o = "\n mutation CreateProject($input: CreateProjectInput!) {\n createPr
|
|
|
246
250
|
return t.data.unarchiveProject;
|
|
247
251
|
},
|
|
248
252
|
onSuccess: (e) => {
|
|
249
|
-
|
|
253
|
+
m(l), d("project.unarchived", {
|
|
250
254
|
projectId: e.id,
|
|
251
255
|
workspaceId: e.workspaceId,
|
|
252
256
|
source: "microfe-workspaces"
|
|
@@ -263,6 +267,6 @@ var o = "\n mutation CreateProject($input: CreateProjectInput!) {\n createPr
|
|
|
263
267
|
});
|
|
264
268
|
};
|
|
265
269
|
//#endregion
|
|
266
|
-
export {
|
|
270
|
+
export { b as useArchiveProject, h as useCreateProject, y as useDeleteProject, _ as useTagProject, x as useUnarchiveProject, v as useUntagProject, g as useUpdateProject };
|
|
267
271
|
|
|
268
272
|
//# sourceMappingURL=useProjectMutations.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useProjectMutations.js","names":[],"sources":["../../src/hooks/useProjectMutations.ts"],"sourcesContent":["import { useMutation, useQueryClient } from '@tanstack/react-query';\nimport { graphqlFetch } from '@burdenoff/fe-libs/shared/graphql';\nimport { useWorkspacesContext } from '../providers/WorkspacesProvider';\nimport type {\n CreateProjectInput,\n UpdateProjectInput,\n Project,\n ProjectTagAssignment,\n} from '../types';\nimport { useWorkspacesEventEmitter } from './useWorkspacesEventEmitter';\nimport { safeTelemetryError } from '../utils/telemetryError';\n\nconst CREATE_PROJECT_MUTATION = `\n mutation CreateProject($input: CreateProjectInput!) {\n createProject(input: $input) {\n id\n name\n key\n workspaceId\n creatorId\n status\n tags\n createdAt\n }\n }\n`;\n\nconst UPDATE_PROJECT_MUTATION = `\n mutation UpdateProject($id: ID!, $input: UpdateProjectInput!) {\n updateProject(id: $id, input: $input) {\n id\n name\n key\n status\n config\n tags\n archived\n updatedAt\n }\n }\n`;\n\nconst DELETE_PROJECT_MUTATION = `\n mutation DeleteProject($id: ID!) {\n deleteProject(id: $id)\n }\n`;\n\nconst ARCHIVE_PROJECT_MUTATION = `\n mutation ArchiveProject($id: ID!) {\n archiveProject(id: $id) {\n id\n archived\n updatedAt\n }\n }\n`;\n\nconst UNARCHIVE_PROJECT_MUTATION = `\n mutation UnarchiveProject($id: ID!) {\n unarchiveProject(id: $id) {\n id\n archived\n updatedAt\n }\n }\n`;\n\nconst TAG_PROJECT_MUTATION = `\n mutation AssignProjectTag($input: AssignTagInput!) {\n assignTag(input: $input) {\n id\n tagId\n entityType\n entityId\n source\n assignedById\n createdAt\n validFrom\n validTo\n metadata\n }\n }\n`;\n\nconst GET_PROJECT_TAG_ASSIGNMENTS_QUERY = `\n query GetProjectTagAssignments($entityType: String!, $entityId: ID!) {\n getEntityTags(entityType: $entityType, entityId: $entityId) {\n id\n tagId\n }\n }\n`;\n\nconst REMOVE_TAG_ASSIGNMENT_MUTATION = `\n mutation RemoveTagAssignment($id: ID!) {\n removeTagAssignment(id: $id)\n }\n`;\n\n/**\n * Hook to create a new project\n */\nexport const useCreateProject = (workspaceIdOverride?: string) => {\n const { authToken, onProjectCreate, workspaceId } = useWorkspacesContext();\n const queryClient = useQueryClient();\n const { emit } = useWorkspacesEventEmitter();\n const effectiveWorkspaceId = workspaceIdOverride || workspaceId;\n\n return useMutation({\n mutationFn: async (input: CreateProjectInput): Promise<Project> => {\n const result = await graphqlFetch<{ createProject: Project }>({\n gateway: 'workspace',\n authToken: authToken || undefined,\n query: CREATE_PROJECT_MUTATION,\n variables: { input },\n workspaceId: effectiveWorkspaceId || undefined,\n workspaceToken: true, // Auto-read from profile context for x-workspace-id header (required by gateway RBAC)\n });\n\n if (result.errors?.length) {\n throw new Error(result.errors[0]?.message || 'GraphQL error');\n }\n\n return result.data!.createProject;\n },\n onSuccess: (project) => {\n queryClient.invalidateQueries({ queryKey: ['projects'] });\n queryClient.invalidateQueries({ queryKey: ['myProjects'] });\n emit('project.created', {\n projectId: project.id,\n workspaceId: project.workspaceId,\n source: 'microfe-workspaces',\n });\n if (onProjectCreate) {\n onProjectCreate(project);\n }\n },\n onError: (err) => {\n emit('project.create_failed', {\n workspaceId: effectiveWorkspaceId || undefined,\n source: 'microfe-workspaces',\n errorMessage: safeTelemetryError(err),\n });\n },\n });\n};\n\n/**\n * Hook to update an existing project\n */\nexport const useUpdateProject = (workspaceIdOverride?: string) => {\n const { authToken, workspaceId } = useWorkspacesContext();\n const queryClient = useQueryClient();\n const { emit } = useWorkspacesEventEmitter();\n const effectiveWorkspaceId = workspaceIdOverride || workspaceId;\n\n return useMutation({\n mutationFn: async ({\n id,\n input,\n }: {\n id: string;\n input: UpdateProjectInput;\n }): Promise<Project> => {\n const result = await graphqlFetch<{ updateProject: Project }>({\n gateway: 'workspace',\n authToken: authToken || undefined,\n query: UPDATE_PROJECT_MUTATION,\n variables: { id, input },\n workspaceId: effectiveWorkspaceId || undefined,\n workspaceToken: true, // Auto-read from profile context for x-workspace-id header (required by gateway RBAC)\n });\n\n if (result.errors?.length) {\n throw new Error(result.errors[0]?.message || 'GraphQL error');\n }\n\n return result.data!.updateProject;\n },\n onSuccess: (project) => {\n queryClient.invalidateQueries({ queryKey: ['projects'] });\n queryClient.invalidateQueries({ queryKey: ['project', project.id] });\n queryClient.invalidateQueries({ queryKey: ['myProjects'] });\n emit('project.updated', {\n projectId: project.id,\n workspaceId: project.workspaceId,\n source: 'microfe-workspaces',\n });\n },\n onError: (err, variables) => {\n emit('project.update_failed', {\n projectId: variables?.id,\n workspaceId: effectiveWorkspaceId || undefined,\n source: 'microfe-workspaces',\n errorMessage: safeTelemetryError(err),\n });\n },\n });\n};\n\n/**\n * Hook to assign a structured tag to a project.\n */\nexport const useTagProject = (workspaceIdOverride?: string) => {\n const { authToken, workspaceId } = useWorkspacesContext();\n const queryClient = useQueryClient();\n const { emit } = useWorkspacesEventEmitter();\n const effectiveWorkspaceId = workspaceIdOverride || workspaceId;\n\n return useMutation({\n mutationFn: async (input: {\n entityId: string;\n tagId: string;\n }): Promise<ProjectTagAssignment> => {\n const result = await graphqlFetch<{\n assignTag: {\n id: string;\n tagId: string;\n entityType: string;\n entityId: string;\n source: string;\n assignedById?: string | null;\n createdAt?: string | null;\n validFrom?: string | null;\n validTo?: string | null;\n metadata?: Record<string, unknown> | null;\n };\n }>({\n gateway: 'workspace',\n authToken: authToken || undefined,\n query: TAG_PROJECT_MUTATION,\n variables: {\n input: {\n tagId: input.tagId,\n entityType: 'WORKSPACE_PROJECT',\n entityId: input.entityId,\n source: 'MANUAL',\n context: {\n workspaceId: effectiveWorkspaceId,\n projectId: input.entityId,\n },\n },\n },\n workspaceId: effectiveWorkspaceId || undefined,\n workspaceToken: true,\n });\n\n if (result.errors?.length) {\n throw new Error(result.errors[0]?.message || 'GraphQL error');\n }\n\n if (!result.data?.assignTag) {\n throw new Error('GraphQL error');\n }\n\n return {\n id: result.data.assignTag.id,\n tagId: result.data.assignTag.tagId,\n entityType: result.data.assignTag.entityType,\n entityId: result.data.assignTag.entityId,\n source: result.data.assignTag.source,\n assignedBy: result.data.assignTag.assignedById ?? null,\n assignedAt: result.data.assignTag.createdAt ?? null,\n validFrom: result.data.assignTag.validFrom ?? null,\n validTo: result.data.assignTag.validTo ?? null,\n metadata: result.data.assignTag.metadata ?? null,\n tag: null,\n };\n },\n onSuccess: (_assignment, input) => {\n queryClient.invalidateQueries({ queryKey: ['projects'] });\n queryClient.invalidateQueries({ queryKey: ['project'] });\n queryClient.invalidateQueries({ queryKey: ['myProjects'] });\n emit('project.updated', {\n projectId: input.entityId,\n workspaceId: effectiveWorkspaceId || undefined,\n source: 'microfe-workspaces',\n });\n },\n onError: (err, input) => {\n emit('project.update_failed', {\n projectId: input.entityId,\n workspaceId: effectiveWorkspaceId || undefined,\n source: 'microfe-workspaces',\n errorMessage: safeTelemetryError(err),\n });\n },\n });\n};\n\n/**\n * Hook to remove a structured tag from a project.\n */\nexport const useUntagProject = (workspaceIdOverride?: string) => {\n const { authToken, workspaceId } = useWorkspacesContext();\n const queryClient = useQueryClient();\n const { emit } = useWorkspacesEventEmitter();\n const effectiveWorkspaceId = workspaceIdOverride || workspaceId;\n\n return useMutation({\n mutationFn: async (input: {\n entityId: string;\n tagId: string;\n assignmentId?: string;\n }): Promise<boolean> => {\n let assignmentId = input.assignmentId;\n\n if (!assignmentId) {\n const lookup = await graphqlFetch<{\n getEntityTags: Array<{\n id: string;\n tagId: string;\n }>;\n }>({\n gateway: 'workspace',\n authToken: authToken || undefined,\n query: GET_PROJECT_TAG_ASSIGNMENTS_QUERY,\n variables: {\n entityType: 'WORKSPACE_PROJECT',\n entityId: input.entityId,\n },\n workspaceId: effectiveWorkspaceId || undefined,\n workspaceToken: true,\n });\n\n if (lookup.errors?.length) {\n throw new Error(lookup.errors[0]?.message || 'GraphQL error');\n }\n\n assignmentId = lookup.data?.getEntityTags.find((entry) => entry.tagId === input.tagId)?.id;\n }\n\n if (!assignmentId) {\n return false;\n }\n\n const result = await graphqlFetch<{ removeTagAssignment: boolean }>({\n gateway: 'workspace',\n authToken: authToken || undefined,\n query: REMOVE_TAG_ASSIGNMENT_MUTATION,\n variables: { id: assignmentId },\n workspaceId: effectiveWorkspaceId || undefined,\n workspaceToken: true,\n });\n\n if (result.errors?.length) {\n throw new Error(result.errors[0]?.message || 'GraphQL error');\n }\n\n return result.data?.removeTagAssignment ?? false;\n },\n onSuccess: (_ok, input) => {\n queryClient.invalidateQueries({ queryKey: ['projects'] });\n queryClient.invalidateQueries({ queryKey: ['project'] });\n queryClient.invalidateQueries({ queryKey: ['myProjects'] });\n emit('project.updated', {\n projectId: input.entityId,\n workspaceId: effectiveWorkspaceId || undefined,\n source: 'microfe-workspaces',\n });\n },\n onError: (err, input) => {\n emit('project.update_failed', {\n projectId: input.entityId,\n workspaceId: effectiveWorkspaceId || undefined,\n source: 'microfe-workspaces',\n errorMessage: safeTelemetryError(err),\n });\n },\n });\n};\n\n/**\n * Hook to delete a project\n */\nexport const useDeleteProject = (workspaceIdOverride?: string) => {\n const { authToken, workspaceId } = useWorkspacesContext();\n const queryClient = useQueryClient();\n const { emit } = useWorkspacesEventEmitter();\n const effectiveWorkspaceId = workspaceIdOverride || workspaceId;\n\n return useMutation({\n mutationFn: async (id: string): Promise<boolean> => {\n const result = await graphqlFetch<{ deleteProject: boolean }>({\n gateway: 'workspace',\n authToken: authToken || undefined,\n query: DELETE_PROJECT_MUTATION,\n variables: { id },\n workspaceId: effectiveWorkspaceId || undefined,\n workspaceToken: true, // Auto-read from profile context for x-workspace-id header (required by gateway RBAC)\n });\n\n if (result.errors?.length) {\n throw new Error(result.errors[0]?.message || 'GraphQL error');\n }\n\n return result.data!.deleteProject;\n },\n onSuccess: (_, id) => {\n queryClient.invalidateQueries({ queryKey: ['projects'] });\n queryClient.invalidateQueries({ queryKey: ['project', id] });\n queryClient.invalidateQueries({ queryKey: ['myProjects'] });\n emit('project.deleted', { projectId: id, source: 'microfe-workspaces' });\n },\n onError: (err, id) => {\n emit('project.delete_failed', {\n projectId: id,\n workspaceId: effectiveWorkspaceId || undefined,\n source: 'microfe-workspaces',\n errorMessage: safeTelemetryError(err),\n });\n },\n });\n};\n\n/**\n * Hook to archive a project\n */\nexport const useArchiveProject = (workspaceIdOverride?: string) => {\n const { authToken, workspaceId } = useWorkspacesContext();\n const queryClient = useQueryClient();\n const { emit } = useWorkspacesEventEmitter();\n const effectiveWorkspaceId = workspaceIdOverride || workspaceId;\n\n return useMutation({\n mutationFn: async (id: string): Promise<Project> => {\n const result = await graphqlFetch<{ archiveProject: Project }>({\n gateway: 'workspace',\n authToken: authToken || undefined,\n query: ARCHIVE_PROJECT_MUTATION,\n variables: { id },\n workspaceId: effectiveWorkspaceId || undefined,\n workspaceToken: true, // Auto-read from profile context for x-workspace-id header (required by gateway RBAC)\n });\n\n if (result.errors?.length) {\n throw new Error(result.errors[0]?.message || 'GraphQL error');\n }\n\n return result.data!.archiveProject;\n },\n onSuccess: (project) => {\n queryClient.invalidateQueries({ queryKey: ['projects'] });\n queryClient.invalidateQueries({ queryKey: ['project', project.id] });\n queryClient.invalidateQueries({ queryKey: ['myProjects'] });\n emit('project.archived', {\n projectId: project.id,\n workspaceId: project.workspaceId,\n source: 'microfe-workspaces',\n });\n },\n onError: (err, id) => {\n emit('project.archive_failed', {\n projectId: id,\n workspaceId: effectiveWorkspaceId || undefined,\n source: 'microfe-workspaces',\n errorMessage: safeTelemetryError(err),\n });\n },\n });\n};\n\n/**\n * Hook to unarchive a project\n */\nexport const useUnarchiveProject = (workspaceIdOverride?: string) => {\n const { authToken, workspaceId } = useWorkspacesContext();\n const queryClient = useQueryClient();\n const { emit } = useWorkspacesEventEmitter();\n const effectiveWorkspaceId = workspaceIdOverride || workspaceId;\n\n return useMutation({\n mutationFn: async (id: string): Promise<Project> => {\n const result = await graphqlFetch<{ unarchiveProject: Project }>({\n gateway: 'workspace',\n authToken: authToken || undefined,\n query: UNARCHIVE_PROJECT_MUTATION,\n variables: { id },\n workspaceId: effectiveWorkspaceId || undefined,\n workspaceToken: true, // Auto-read from profile context for x-workspace-id header (required by gateway RBAC)\n });\n\n if (result.errors?.length) {\n throw new Error(result.errors[0]?.message || 'GraphQL error');\n }\n\n return result.data!.unarchiveProject;\n },\n onSuccess: (project) => {\n queryClient.invalidateQueries({ queryKey: ['projects'] });\n queryClient.invalidateQueries({ queryKey: ['project', project.id] });\n queryClient.invalidateQueries({ queryKey: ['myProjects'] });\n emit('project.unarchived', {\n projectId: project.id,\n workspaceId: project.workspaceId,\n source: 'microfe-workspaces',\n });\n },\n onError: (err, id) => {\n emit('project.unarchive_failed', {\n projectId: id,\n workspaceId: effectiveWorkspaceId || undefined,\n source: 'microfe-workspaces',\n errorMessage: safeTelemetryError(err),\n });\n },\n });\n};\n"],"mappings":";;;;;;AAYA,IAAM,IAA0B,+NAe1B,IAA0B,4OAe1B,IAA0B,6EAM1B,IAA2B,mIAU3B,IAA6B,uIAU7B,IAAuB,sQAiBvB,IAAoC,sLASpC,IAAiC,yFAS1B,KAAoB,MAAiC;CAChE,IAAM,EAAE,cAAW,oBAAiB,mBAAgB,GAAsB,EACpE,IAAc,GAAgB,EAC9B,EAAE,YAAS,GAA2B,EACtC,IAAuB,KAAuB;AAEpD,QAAO,EAAY;EACjB,YAAY,OAAO,MAAgD;GACjE,IAAM,IAAS,MAAM,EAAyC;IA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,KAAwB,KAAA;IACrC,gBAAgB;IACjB,CAAC;AAEF,OAAI,EAAO,QAAQ,OACjB,OAAU,MAAM,EAAO,OAAO,IAAI,WAAW,gBAAgB;AAG/D,UAAO,EAAO,KAAM;;EAEtB,YAAY,MAAY;AAItB,GAHA,EAAY,kBAAkB,EAAE,UAAU,CAAC,WAAW,EAAE,CAAC,EACzD,EAAY,kBAAkB,EAAE,UAAU,CAAC,WAAW,EAAQ,GAAG,EAAE,CAAC,EACpE,EAAY,kBAAkB,EAAE,UAAU,CAAC,aAAa,EAAE,CAAC,EAC3D,EAAK,sBAAsB;IACzB,WAAW,EAAQ;IACnB,aAAa,EAAQ;IACrB,QAAQ;IACT,CAAC;;EAEJ,UAAU,GAAK,MAAO;AACpB,KAAK,4BAA4B;IAC/B,WAAW;IACX,aAAa,KAAwB,KAAA;IACrC,QAAQ;IACR,cAAc,EAAmB,EAAI;IACtC,CAAC;;EAEL,CAAC"}
|
|
1
|
+
{"version":3,"file":"useProjectMutations.js","names":[],"sources":["../../src/hooks/useProjectMutations.ts"],"sourcesContent":["import { useMutation, useQueryClient, type QueryClient } from '@tanstack/react-query';\nimport { graphqlFetch } from '@burdenoff/fe-libs/shared/graphql';\nimport { useWorkspacesContext } from '../providers/WorkspacesProvider';\nimport type {\n CreateProjectInput,\n UpdateProjectInput,\n Project,\n ProjectTagAssignment,\n} from '../types';\nimport { useWorkspacesEventEmitter } from './useWorkspacesEventEmitter';\nimport { safeTelemetryError } from '../utils/telemetryError';\n\nconst CREATE_PROJECT_MUTATION = `\n mutation CreateProject($input: CreateProjectInput!) {\n createProject(input: $input) {\n id\n name\n key\n workspaceId\n creatorId\n status\n tags\n createdAt\n }\n }\n`;\n\nconst UPDATE_PROJECT_MUTATION = `\n mutation UpdateProject($id: ID!, $input: UpdateProjectInput!) {\n updateProject(id: $id, input: $input) {\n id\n name\n key\n status\n config\n tags\n archived\n updatedAt\n }\n }\n`;\n\nconst DELETE_PROJECT_MUTATION = `\n mutation DeleteProject($id: ID!) {\n deleteProject(id: $id)\n }\n`;\n\nconst ARCHIVE_PROJECT_MUTATION = `\n mutation ArchiveProject($id: ID!) {\n archiveProject(id: $id) {\n id\n archived\n updatedAt\n }\n }\n`;\n\nconst UNARCHIVE_PROJECT_MUTATION = `\n mutation UnarchiveProject($id: ID!) {\n unarchiveProject(id: $id) {\n id\n archived\n updatedAt\n }\n }\n`;\n\nconst TAG_PROJECT_MUTATION = `\n mutation AssignProjectTag($input: AssignTagInput!) {\n assignTag(input: $input) {\n id\n tagId\n entityType\n entityId\n source\n assignedById\n createdAt\n validFrom\n validTo\n metadata\n }\n }\n`;\n\nconst GET_PROJECT_TAG_ASSIGNMENTS_QUERY = `\n query GetProjectTagAssignments($entityType: String!, $entityId: ID!) {\n getEntityTags(entityType: $entityType, entityId: $entityId) {\n id\n tagId\n }\n }\n`;\n\nconst REMOVE_TAG_ASSIGNMENT_MUTATION = `\n mutation RemoveTagAssignment($id: ID!) {\n removeTagAssignment(id: $id)\n }\n`;\n\nfunction invalidateProjectViews(queryClient: QueryClient) {\n queryClient.invalidateQueries({ queryKey: ['projects'] });\n queryClient.invalidateQueries({ queryKey: ['project'] });\n queryClient.invalidateQueries({ queryKey: ['myProjects'] });\n queryClient.invalidateQueries({ queryKey: ['dashboard', 'projects'] });\n}\n\n/**\n * Hook to create a new project\n */\nexport const useCreateProject = (workspaceIdOverride?: string) => {\n const { authToken, onProjectCreate, workspaceId } = useWorkspacesContext();\n const queryClient = useQueryClient();\n const { emit } = useWorkspacesEventEmitter();\n const effectiveWorkspaceId = workspaceIdOverride || workspaceId;\n\n return useMutation({\n mutationFn: async (input: CreateProjectInput): Promise<Project> => {\n const result = await graphqlFetch<{ createProject: Project }>({\n gateway: 'workspace',\n authToken: authToken || undefined,\n query: CREATE_PROJECT_MUTATION,\n variables: { input },\n workspaceId: effectiveWorkspaceId || undefined,\n workspaceToken: true, // Auto-read from profile context for x-workspace-id header (required by gateway RBAC)\n });\n\n if (result.errors?.length) {\n throw new Error(result.errors[0]?.message || 'GraphQL error');\n }\n\n return result.data!.createProject;\n },\n onSuccess: (project) => {\n invalidateProjectViews(queryClient);\n emit('project.created', {\n projectId: project.id,\n workspaceId: project.workspaceId,\n source: 'microfe-workspaces',\n });\n if (onProjectCreate) {\n onProjectCreate(project);\n }\n },\n onError: (err) => {\n emit('project.create_failed', {\n workspaceId: effectiveWorkspaceId || undefined,\n source: 'microfe-workspaces',\n errorMessage: safeTelemetryError(err),\n });\n },\n });\n};\n\n/**\n * Hook to update an existing project\n */\nexport const useUpdateProject = (workspaceIdOverride?: string) => {\n const { authToken, workspaceId } = useWorkspacesContext();\n const queryClient = useQueryClient();\n const { emit } = useWorkspacesEventEmitter();\n const effectiveWorkspaceId = workspaceIdOverride || workspaceId;\n\n return useMutation({\n mutationFn: async ({\n id,\n input,\n }: {\n id: string;\n input: UpdateProjectInput;\n }): Promise<Project> => {\n const result = await graphqlFetch<{ updateProject: Project }>({\n gateway: 'workspace',\n authToken: authToken || undefined,\n query: UPDATE_PROJECT_MUTATION,\n variables: { id, input },\n workspaceId: effectiveWorkspaceId || undefined,\n workspaceToken: true, // Auto-read from profile context for x-workspace-id header (required by gateway RBAC)\n });\n\n if (result.errors?.length) {\n throw new Error(result.errors[0]?.message || 'GraphQL error');\n }\n\n return result.data!.updateProject;\n },\n onSuccess: (project) => {\n invalidateProjectViews(queryClient);\n emit('project.updated', {\n projectId: project.id,\n workspaceId: project.workspaceId,\n source: 'microfe-workspaces',\n });\n },\n onError: (err, variables) => {\n emit('project.update_failed', {\n projectId: variables?.id,\n workspaceId: effectiveWorkspaceId || undefined,\n source: 'microfe-workspaces',\n errorMessage: safeTelemetryError(err),\n });\n },\n });\n};\n\n/**\n * Hook to assign a structured tag to a project.\n */\nexport const useTagProject = (workspaceIdOverride?: string) => {\n const { authToken, workspaceId } = useWorkspacesContext();\n const queryClient = useQueryClient();\n const { emit } = useWorkspacesEventEmitter();\n const effectiveWorkspaceId = workspaceIdOverride || workspaceId;\n\n return useMutation({\n mutationFn: async (input: {\n entityId: string;\n tagId: string;\n }): Promise<ProjectTagAssignment> => {\n const result = await graphqlFetch<{\n assignTag: {\n id: string;\n tagId: string;\n entityType: string;\n entityId: string;\n source: string;\n assignedById?: string | null;\n createdAt?: string | null;\n validFrom?: string | null;\n validTo?: string | null;\n metadata?: Record<string, unknown> | null;\n };\n }>({\n gateway: 'workspace',\n authToken: authToken || undefined,\n query: TAG_PROJECT_MUTATION,\n variables: {\n input: {\n tagId: input.tagId,\n entityType: 'WORKSPACE_PROJECT',\n entityId: input.entityId,\n source: 'MANUAL',\n context: {\n workspaceId: effectiveWorkspaceId,\n projectId: input.entityId,\n },\n },\n },\n workspaceId: effectiveWorkspaceId || undefined,\n workspaceToken: true,\n });\n\n if (result.errors?.length) {\n throw new Error(result.errors[0]?.message || 'GraphQL error');\n }\n\n if (!result.data?.assignTag) {\n throw new Error('GraphQL error');\n }\n\n return {\n id: result.data.assignTag.id,\n tagId: result.data.assignTag.tagId,\n entityType: result.data.assignTag.entityType,\n entityId: result.data.assignTag.entityId,\n source: result.data.assignTag.source,\n assignedBy: result.data.assignTag.assignedById ?? null,\n assignedAt: result.data.assignTag.createdAt ?? null,\n validFrom: result.data.assignTag.validFrom ?? null,\n validTo: result.data.assignTag.validTo ?? null,\n metadata: result.data.assignTag.metadata ?? null,\n tag: null,\n };\n },\n onSuccess: (_assignment, input) => {\n invalidateProjectViews(queryClient);\n emit('project.updated', {\n projectId: input.entityId,\n workspaceId: effectiveWorkspaceId || undefined,\n source: 'microfe-workspaces',\n });\n },\n onError: (err, input) => {\n emit('project.update_failed', {\n projectId: input.entityId,\n workspaceId: effectiveWorkspaceId || undefined,\n source: 'microfe-workspaces',\n errorMessage: safeTelemetryError(err),\n });\n },\n });\n};\n\n/**\n * Hook to remove a structured tag from a project.\n */\nexport const useUntagProject = (workspaceIdOverride?: string) => {\n const { authToken, workspaceId } = useWorkspacesContext();\n const queryClient = useQueryClient();\n const { emit } = useWorkspacesEventEmitter();\n const effectiveWorkspaceId = workspaceIdOverride || workspaceId;\n\n return useMutation({\n mutationFn: async (input: {\n entityId: string;\n tagId: string;\n assignmentId?: string;\n }): Promise<boolean> => {\n let assignmentId = input.assignmentId;\n\n if (!assignmentId) {\n const lookup = await graphqlFetch<{\n getEntityTags: Array<{\n id: string;\n tagId: string;\n }>;\n }>({\n gateway: 'workspace',\n authToken: authToken || undefined,\n query: GET_PROJECT_TAG_ASSIGNMENTS_QUERY,\n variables: {\n entityType: 'WORKSPACE_PROJECT',\n entityId: input.entityId,\n },\n workspaceId: effectiveWorkspaceId || undefined,\n workspaceToken: true,\n });\n\n if (lookup.errors?.length) {\n throw new Error(lookup.errors[0]?.message || 'GraphQL error');\n }\n\n assignmentId = lookup.data?.getEntityTags.find((entry) => entry.tagId === input.tagId)?.id;\n }\n\n if (!assignmentId) {\n return false;\n }\n\n const result = await graphqlFetch<{ removeTagAssignment: boolean }>({\n gateway: 'workspace',\n authToken: authToken || undefined,\n query: REMOVE_TAG_ASSIGNMENT_MUTATION,\n variables: { id: assignmentId },\n workspaceId: effectiveWorkspaceId || undefined,\n workspaceToken: true,\n });\n\n if (result.errors?.length) {\n throw new Error(result.errors[0]?.message || 'GraphQL error');\n }\n\n return result.data?.removeTagAssignment ?? false;\n },\n onSuccess: (_ok, input) => {\n invalidateProjectViews(queryClient);\n emit('project.updated', {\n projectId: input.entityId,\n workspaceId: effectiveWorkspaceId || undefined,\n source: 'microfe-workspaces',\n });\n },\n onError: (err, input) => {\n emit('project.update_failed', {\n projectId: input.entityId,\n workspaceId: effectiveWorkspaceId || undefined,\n source: 'microfe-workspaces',\n errorMessage: safeTelemetryError(err),\n });\n },\n });\n};\n\n/**\n * Hook to delete a project\n */\nexport const useDeleteProject = (workspaceIdOverride?: string) => {\n const { authToken, workspaceId } = useWorkspacesContext();\n const queryClient = useQueryClient();\n const { emit } = useWorkspacesEventEmitter();\n const effectiveWorkspaceId = workspaceIdOverride || workspaceId;\n\n return useMutation({\n mutationFn: async (id: string): Promise<boolean> => {\n const result = await graphqlFetch<{ deleteProject: boolean }>({\n gateway: 'workspace',\n authToken: authToken || undefined,\n query: DELETE_PROJECT_MUTATION,\n variables: { id },\n workspaceId: effectiveWorkspaceId || undefined,\n workspaceToken: true, // Auto-read from profile context for x-workspace-id header (required by gateway RBAC)\n });\n\n if (result.errors?.length) {\n throw new Error(result.errors[0]?.message || 'GraphQL error');\n }\n\n return result.data!.deleteProject;\n },\n onSuccess: (_, id) => {\n invalidateProjectViews(queryClient);\n emit('project.deleted', { projectId: id, source: 'microfe-workspaces' });\n },\n onError: (err, id) => {\n emit('project.delete_failed', {\n projectId: id,\n workspaceId: effectiveWorkspaceId || undefined,\n source: 'microfe-workspaces',\n errorMessage: safeTelemetryError(err),\n });\n },\n });\n};\n\n/**\n * Hook to archive a project\n */\nexport const useArchiveProject = (workspaceIdOverride?: string) => {\n const { authToken, workspaceId } = useWorkspacesContext();\n const queryClient = useQueryClient();\n const { emit } = useWorkspacesEventEmitter();\n const effectiveWorkspaceId = workspaceIdOverride || workspaceId;\n\n return useMutation({\n mutationFn: async (id: string): Promise<Project> => {\n const result = await graphqlFetch<{ archiveProject: Project }>({\n gateway: 'workspace',\n authToken: authToken || undefined,\n query: ARCHIVE_PROJECT_MUTATION,\n variables: { id },\n workspaceId: effectiveWorkspaceId || undefined,\n workspaceToken: true, // Auto-read from profile context for x-workspace-id header (required by gateway RBAC)\n });\n\n if (result.errors?.length) {\n throw new Error(result.errors[0]?.message || 'GraphQL error');\n }\n\n return result.data!.archiveProject;\n },\n onSuccess: (project) => {\n invalidateProjectViews(queryClient);\n emit('project.archived', {\n projectId: project.id,\n workspaceId: project.workspaceId,\n source: 'microfe-workspaces',\n });\n },\n onError: (err, id) => {\n emit('project.archive_failed', {\n projectId: id,\n workspaceId: effectiveWorkspaceId || undefined,\n source: 'microfe-workspaces',\n errorMessage: safeTelemetryError(err),\n });\n },\n });\n};\n\n/**\n * Hook to unarchive a project\n */\nexport const useUnarchiveProject = (workspaceIdOverride?: string) => {\n const { authToken, workspaceId } = useWorkspacesContext();\n const queryClient = useQueryClient();\n const { emit } = useWorkspacesEventEmitter();\n const effectiveWorkspaceId = workspaceIdOverride || workspaceId;\n\n return useMutation({\n mutationFn: async (id: string): Promise<Project> => {\n const result = await graphqlFetch<{ unarchiveProject: Project }>({\n gateway: 'workspace',\n authToken: authToken || undefined,\n query: UNARCHIVE_PROJECT_MUTATION,\n variables: { id },\n workspaceId: effectiveWorkspaceId || undefined,\n workspaceToken: true, // Auto-read from profile context for x-workspace-id header (required by gateway RBAC)\n });\n\n if (result.errors?.length) {\n throw new Error(result.errors[0]?.message || 'GraphQL error');\n }\n\n return result.data!.unarchiveProject;\n },\n onSuccess: (project) => {\n invalidateProjectViews(queryClient);\n emit('project.unarchived', {\n projectId: project.id,\n workspaceId: project.workspaceId,\n source: 'microfe-workspaces',\n });\n },\n onError: (err, id) => {\n emit('project.unarchive_failed', {\n projectId: id,\n workspaceId: effectiveWorkspaceId || undefined,\n source: 'microfe-workspaces',\n errorMessage: safeTelemetryError(err),\n });\n },\n });\n};\n"],"mappings":";;;;;;AAYA,IAAM,IAA0B,+NAe1B,IAA0B,4OAe1B,IAA0B,6EAM1B,IAA2B,mIAU3B,IAA6B,uIAU7B,IAAuB,sQAiBvB,IAAoC,sLASpC,IAAiC;AAMvC,SAAS,EAAuB,GAA0B;AAIxD,CAHA,EAAY,kBAAkB,EAAE,UAAU,CAAC,WAAW,EAAE,CAAC,EACzD,EAAY,kBAAkB,EAAE,UAAU,CAAC,UAAU,EAAE,CAAC,EACxD,EAAY,kBAAkB,EAAE,UAAU,CAAC,aAAa,EAAE,CAAC,EAC3D,EAAY,kBAAkB,EAAE,UAAU,CAAC,aAAa,WAAW,EAAE,CAAC;;AAMxE,IAAa,KAAoB,MAAiC;CAChE,IAAM,EAAE,cAAW,oBAAiB,mBAAgB,GAAsB,EACpE,IAAc,GAAgB,EAC9B,EAAE,YAAS,GAA2B,EACtC,IAAuB,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J,UAAU,GAAK,MAAO;AACpB,KAAK,0BAA0B;IAC7B,WAAW;IACX,aAAa,KAAwB,KAAA;IACrC,QAAQ;IACR,cAAc,EAAmB,EAAI;IACtC,CAAC;;EAEL,CAAC;GAMS,KAAuB,MAAiC;CACnE,IAAM,EAAE,cAAW,mBAAgB,GAAsB,EACnD,IAAc,GAAgB,EAC9B,EAAE,YAAS,GAA2B,EACtC,IAAuB,KAAuB;AAEpD,QAAO,EAAY;EACjB,YAAY,OAAO,MAAiC;GAClD,IAAM,IAAS,MAAM,EAA4C;IAC/D,SAAS;IACT,WAAW,KAAa,KAAA;IACxB,OAAO;IACP,WAAW,EAAE,OAAI;IACjB,aAAa,KAAwB,KAAA;IACrC,gBAAgB;IACjB,CAAC;AAEF,OAAI,EAAO,QAAQ,OACjB,OAAU,MAAM,EAAO,OAAO,IAAI,WAAW,gBAAgB;AAG/D,UAAO,EAAO,KAAM;;EAEtB,YAAY,MAAY;AAEtB,GADA,EAAuB,EAAY,EACnC,EAAK,sBAAsB;IACzB,WAAW,EAAQ;IACnB,aAAa,EAAQ;IACrB,QAAQ;IACT,CAAC;;EAEJ,UAAU,GAAK,MAAO;AACpB,KAAK,4BAA4B;IAC/B,WAAW;IACX,aAAa,KAAwB,KAAA;IACrC,QAAQ;IACR,cAAc,EAAmB,EAAI;IACtC,CAAC;;EAEL,CAAC"}
|
|
@@ -6,7 +6,15 @@ import { useMutation as s, useQueryClient as c } from "@tanstack/react-query";
|
|
|
6
6
|
import { print as l } from "graphql";
|
|
7
7
|
import { graphqlFetch as u } from "@burdenoff/fe-libs/shared/graphql";
|
|
8
8
|
//#region src/hooks/useWorkspaceMutations.ts
|
|
9
|
-
var d = "\n mutation CreateGlobalWorkspace($input: CreateWorkspaceInput!) {\n createWorkspace(input: $input) {\n id\n name\n slug\n type\n status\n tenantId\n organizationId\n createdAt\n }\n }\n"
|
|
9
|
+
var d = "\n mutation CreateGlobalWorkspace($input: CreateWorkspaceInput!) {\n createWorkspace(input: $input) {\n id\n name\n slug\n type\n status\n tenantId\n organizationId\n createdAt\n }\n }\n";
|
|
10
|
+
function f(e, t) {
|
|
11
|
+
e.invalidateQueries({ queryKey: ["workspaces"] }), t && (e.invalidateQueries({ queryKey: ["workspace", t] }), e.invalidateQueries({ queryKey: [
|
|
12
|
+
"dashboard",
|
|
13
|
+
"workspace",
|
|
14
|
+
t
|
|
15
|
+
] })), e.invalidateQueries({ queryKey: ["myWorkspaces"] }), e.invalidateQueries({ queryKey: ["myTenants"] }), e.invalidateQueries({ queryKey: ["myOrganizations"] }), e.invalidateQueries({ queryKey: ["dashboard", "global"] });
|
|
16
|
+
}
|
|
17
|
+
var p = () => {
|
|
10
18
|
let { authToken: t, onWorkspaceCreate: n } = e(), r = c(), { emit: i } = a();
|
|
11
19
|
return s({
|
|
12
20
|
mutationFn: async (e) => {
|
|
@@ -20,7 +28,7 @@ var d = "\n mutation CreateGlobalWorkspace($input: CreateWorkspaceInput!) {\n
|
|
|
20
28
|
return n.data.createWorkspace;
|
|
21
29
|
},
|
|
22
30
|
onSuccess: (e) => {
|
|
23
|
-
|
|
31
|
+
f(r, e.id), i("workspace.created", {
|
|
24
32
|
workspaceId: e.id,
|
|
25
33
|
source: "microfe-workspaces"
|
|
26
34
|
}), n && n(e);
|
|
@@ -32,7 +40,7 @@ var d = "\n mutation CreateGlobalWorkspace($input: CreateWorkspaceInput!) {\n
|
|
|
32
40
|
});
|
|
33
41
|
}
|
|
34
42
|
});
|
|
35
|
-
},
|
|
43
|
+
}, m = () => {
|
|
36
44
|
let { authToken: t } = e(), n = c(), { emit: r } = a();
|
|
37
45
|
return s({
|
|
38
46
|
mutationFn: async ({ id: e, input: n }) => {
|
|
@@ -50,7 +58,7 @@ var d = "\n mutation CreateGlobalWorkspace($input: CreateWorkspaceInput!) {\n
|
|
|
50
58
|
return r.data.updateWorkspace;
|
|
51
59
|
},
|
|
52
60
|
onSuccess: (e) => {
|
|
53
|
-
|
|
61
|
+
f(n, e.id), r("workspace.updated", {
|
|
54
62
|
workspaceId: e.id,
|
|
55
63
|
source: "microfe-workspaces"
|
|
56
64
|
});
|
|
@@ -63,7 +71,7 @@ var d = "\n mutation CreateGlobalWorkspace($input: CreateWorkspaceInput!) {\n
|
|
|
63
71
|
});
|
|
64
72
|
}
|
|
65
73
|
});
|
|
66
|
-
},
|
|
74
|
+
}, h = () => {
|
|
67
75
|
let { authToken: t } = e(), r = c(), { emit: i } = a();
|
|
68
76
|
return s({
|
|
69
77
|
mutationFn: async (e) => {
|
|
@@ -78,7 +86,7 @@ var d = "\n mutation CreateGlobalWorkspace($input: CreateWorkspaceInput!) {\n
|
|
|
78
86
|
return r.data.deleteWorkspace;
|
|
79
87
|
},
|
|
80
88
|
onSuccess: (e, t) => {
|
|
81
|
-
|
|
89
|
+
f(r, t), i("workspace.deleted", {
|
|
82
90
|
workspaceId: t,
|
|
83
91
|
source: "microfe-workspaces"
|
|
84
92
|
});
|
|
@@ -91,7 +99,7 @@ var d = "\n mutation CreateGlobalWorkspace($input: CreateWorkspaceInput!) {\n
|
|
|
91
99
|
});
|
|
92
100
|
}
|
|
93
101
|
});
|
|
94
|
-
},
|
|
102
|
+
}, g = () => {
|
|
95
103
|
let { authToken: n } = e(), r = c(), { emit: i } = a();
|
|
96
104
|
return s({
|
|
97
105
|
mutationFn: async (e) => {
|
|
@@ -106,7 +114,7 @@ var d = "\n mutation CreateGlobalWorkspace($input: CreateWorkspaceInput!) {\n
|
|
|
106
114
|
return r.data.updateWorkspace;
|
|
107
115
|
},
|
|
108
116
|
onSuccess: (e) => {
|
|
109
|
-
|
|
117
|
+
f(r, e.id), i("workspace.archived", {
|
|
110
118
|
workspaceId: e.id,
|
|
111
119
|
source: "microfe-workspaces"
|
|
112
120
|
});
|
|
@@ -119,7 +127,7 @@ var d = "\n mutation CreateGlobalWorkspace($input: CreateWorkspaceInput!) {\n
|
|
|
119
127
|
});
|
|
120
128
|
}
|
|
121
129
|
});
|
|
122
|
-
},
|
|
130
|
+
}, _ = () => {
|
|
123
131
|
let { authToken: t } = e(), n = c(), { emit: i } = a();
|
|
124
132
|
return s({
|
|
125
133
|
mutationFn: async (e) => {
|
|
@@ -134,7 +142,7 @@ var d = "\n mutation CreateGlobalWorkspace($input: CreateWorkspaceInput!) {\n
|
|
|
134
142
|
return n.data.updateWorkspace;
|
|
135
143
|
},
|
|
136
144
|
onSuccess: (e) => {
|
|
137
|
-
|
|
145
|
+
f(n, e.id), i("workspace.reactivated", {
|
|
138
146
|
workspaceId: e.id,
|
|
139
147
|
source: "microfe-workspaces"
|
|
140
148
|
});
|
|
@@ -149,6 +157,6 @@ var d = "\n mutation CreateGlobalWorkspace($input: CreateWorkspaceInput!) {\n
|
|
|
149
157
|
});
|
|
150
158
|
};
|
|
151
159
|
//#endregion
|
|
152
|
-
export {
|
|
160
|
+
export { g as useArchiveWorkspace, p as useCreateWorkspace, h as useDeleteWorkspace, _ as useReactivateWorkspace, m as useUpdateWorkspace };
|
|
153
161
|
|
|
154
162
|
//# sourceMappingURL=useWorkspaceMutations.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useWorkspaceMutations.js","names":[],"sources":["../../src/hooks/useWorkspaceMutations.ts"],"sourcesContent":["import { useMutation, useQueryClient } from '@tanstack/react-query';\nimport { print } from 'graphql';\nimport { graphqlFetch } from '@burdenoff/fe-libs/shared/graphql';\nimport { useWorkspacesContext } from '../providers/WorkspacesProvider';\nimport { useWorkspacesEventEmitter } from './useWorkspacesEventEmitter';\nimport {\n UpdateWorkspaceDocument,\n DeleteWorkspaceDocument,\n ArchiveWorkspaceDocument,\n ReactivateWorkspaceDocument,\n} from '../generated/wspace-operations';\nimport type { CreateWorkspaceInput, UpdateWorkspaceInput, Workspace } from '../types';\nimport { safeTelemetryError } from '../utils/telemetryError';\n\n/**\n * GraphQL mutation to create workspace via global-tenant-svc\n * This creates workspace in global layer, which then syncs to wspace layer\n */\nconst CREATE_GLOBAL_WORKSPACE = `\n mutation CreateGlobalWorkspace($input: CreateWorkspaceInput!) {\n createWorkspace(input: $input) {\n id\n name\n slug\n type\n status\n tenantId\n organizationId\n createdAt\n }\n }\n`;\n\n/**\n * Hook to create a new workspace\n *\n * Creates workspace via global-tenant-svc (global gateway), which then\n * automatically syncs to wspace-workspace-svc. This ensures proper\n * tenant/org hierarchy management in the global layer.\n *\n * Required input fields:\n * - tenantId: Select from myTenants query\n * - organizationId: Select from myOrganizations query\n * - name: Display name\n * - slug: URL-friendly identifier (unique within tenant)\n */\nexport const useCreateWorkspace = () => {\n const { authToken, onWorkspaceCreate } = useWorkspacesContext();\n const queryClient = useQueryClient();\n const { emit } = useWorkspacesEventEmitter();\n\n return useMutation({\n mutationFn: async (input: CreateWorkspaceInput): Promise<Workspace> => {\n // Call global gateway for workspace creation\n const result = await graphqlFetch<{ createWorkspace: Workspace }>({\n gateway: 'global', // Use global gateway, not workspace gateway\n authToken: authToken || undefined,\n query: CREATE_GLOBAL_WORKSPACE,\n variables: { input },\n });\n\n if (result.errors?.length) {\n throw new Error(result.errors[0]?.message || 'Failed to create workspace');\n }\n\n return result.data!.createWorkspace;\n },\n onSuccess: (workspace) => {\n // Invalidate both global and workspace layer queries\n queryClient.invalidateQueries({ queryKey: ['workspaces'] });\n queryClient.invalidateQueries({ queryKey: ['myWorkspaces'] });\n queryClient.invalidateQueries({ queryKey: ['myTenants'] });\n queryClient.invalidateQueries({ queryKey: ['myOrganizations'] });\n emit('workspace.created', { workspaceId: workspace.id, source: 'microfe-workspaces' });\n if (onWorkspaceCreate) {\n onWorkspaceCreate(workspace);\n }\n },\n onError: (err) => {\n emit('workspace.create_failed', {\n source: 'microfe-workspaces',\n errorMessage: safeTelemetryError(err),\n });\n },\n });\n};\n\n/**\n * Hook to update an existing workspace\n */\nexport const useUpdateWorkspace = () => {\n const { authToken } = useWorkspacesContext();\n const queryClient = useQueryClient();\n const { emit } = useWorkspacesEventEmitter();\n\n return useMutation({\n mutationFn: async ({\n id,\n input,\n }: {\n id: string;\n input: UpdateWorkspaceInput;\n }): Promise<Workspace> => {\n const result = await graphqlFetch<{ updateWorkspace: Workspace }>({\n gateway: 'workspace',\n authToken: authToken || undefined,\n query: print(UpdateWorkspaceDocument),\n variables: { id, input },\n workspaceToken: true, // Required by gateway RBAC for wspace-scoped operations\n });\n\n if (result.errors?.length) {\n throw new Error(result.errors[0]?.message || 'GraphQL error');\n }\n\n return result.data!.updateWorkspace;\n },\n onSuccess: (workspace) => {\n queryClient.invalidateQueries({ queryKey: ['workspaces'] });\n queryClient.invalidateQueries({ queryKey: ['workspace', workspace.id] });\n queryClient.invalidateQueries({ queryKey: ['myWorkspaces'] });\n emit('workspace.updated', { workspaceId: workspace.id, source: 'microfe-workspaces' });\n },\n onError: (err, variables) => {\n emit('workspace.update_failed', {\n workspaceId: variables?.id,\n source: 'microfe-workspaces',\n errorMessage: safeTelemetryError(err),\n });\n },\n });\n};\n\n/**\n * Hook to delete a workspace\n */\nexport const useDeleteWorkspace = () => {\n const { authToken } = useWorkspacesContext();\n const queryClient = useQueryClient();\n const { emit } = useWorkspacesEventEmitter();\n\n return useMutation({\n mutationFn: async (id: string): Promise<boolean> => {\n const result = await graphqlFetch<{ deleteWorkspace: boolean }>({\n gateway: 'workspace',\n authToken: authToken || undefined,\n query: print(DeleteWorkspaceDocument),\n variables: { id },\n workspaceToken: true, // Required by gateway RBAC for wspace-scoped operations\n });\n\n if (result.errors?.length) {\n throw new Error(result.errors[0]?.message || 'GraphQL error');\n }\n\n return result.data!.deleteWorkspace;\n },\n onSuccess: (_, id) => {\n queryClient.invalidateQueries({ queryKey: ['workspaces'] });\n queryClient.invalidateQueries({ queryKey: ['workspace', id] });\n queryClient.invalidateQueries({ queryKey: ['myWorkspaces'] });\n emit('workspace.deleted', { workspaceId: id, source: 'microfe-workspaces' });\n },\n onError: (err, id) => {\n emit('workspace.delete_failed', {\n workspaceId: id,\n source: 'microfe-workspaces',\n errorMessage: safeTelemetryError(err),\n });\n },\n });\n};\n\n/**\n * Hook to archive a workspace\n */\nexport const useArchiveWorkspace = () => {\n const { authToken } = useWorkspacesContext();\n const queryClient = useQueryClient();\n const { emit } = useWorkspacesEventEmitter();\n\n return useMutation({\n mutationFn: async (id: string): Promise<Workspace> => {\n const result = await graphqlFetch<{ updateWorkspace: Workspace }>({\n gateway: 'workspace',\n authToken: authToken || undefined,\n query: print(ArchiveWorkspaceDocument),\n variables: { id },\n workspaceToken: true, // Required by gateway RBAC for wspace-scoped operations\n });\n\n if (result.errors?.length) {\n throw new Error(result.errors[0]?.message || 'GraphQL error');\n }\n\n return result.data!.updateWorkspace;\n },\n onSuccess: (workspace) => {\n queryClient.invalidateQueries({ queryKey: ['workspaces'] });\n queryClient.invalidateQueries({ queryKey: ['workspace', workspace.id] });\n queryClient.invalidateQueries({ queryKey: ['myWorkspaces'] });\n emit('workspace.archived', { workspaceId: workspace.id, source: 'microfe-workspaces' });\n },\n onError: (err, id) => {\n emit('workspace.archive_failed', {\n workspaceId: id,\n source: 'microfe-workspaces',\n errorMessage: safeTelemetryError(err),\n });\n },\n });\n};\n\n/**\n * Hook to reactivate an archived workspace\n */\nexport const useReactivateWorkspace = () => {\n const { authToken } = useWorkspacesContext();\n const queryClient = useQueryClient();\n const { emit } = useWorkspacesEventEmitter();\n\n return useMutation({\n mutationFn: async (id: string): Promise<Workspace> => {\n const result = await graphqlFetch<{ updateWorkspace: Workspace }>({\n gateway: 'workspace',\n authToken: authToken || undefined,\n query: print(ReactivateWorkspaceDocument),\n variables: { id },\n workspaceToken: true, // Required by gateway RBAC for wspace-scoped operations\n });\n\n if (result.errors?.length) {\n throw new Error(result.errors[0]?.message || 'GraphQL error');\n }\n\n return result.data!.updateWorkspace;\n },\n onSuccess: (workspace) => {\n queryClient.invalidateQueries({ queryKey: ['workspaces'] });\n queryClient.invalidateQueries({ queryKey: ['workspace', workspace.id] });\n queryClient.invalidateQueries({ queryKey: ['myWorkspaces'] });\n emit('workspace.reactivated', { workspaceId: workspace.id, source: 'microfe-workspaces' });\n },\n onError: (err, id) => {\n emit('workspace.reactivate_failed', {\n workspaceId: id,\n source: 'microfe-workspaces',\n errorMessage: safeTelemetryError(err),\n });\n },\n });\n};\n"],"mappings":";;;;;;;;AAkBA,IAAM,IAA0B,8OA4BnB,UAA2B;CACtC,IAAM,EAAE,cAAW,yBAAsB,GAAsB,EACzD,IAAc,GAAgB,EAC9B,EAAE,YAAS,GAA2B;AAE5C,QAAO,EAAY;EACjB,YAAY,OAAO,MAAoD;GAErE,IAAM,IAAS,MAAM,EAA6C;IAChE,SAAS;IACT,WAAW,KAAa,KAAA;IACxB,OAAO;IACP,WAAW,EAAE,UAAO;IACrB,CAAC;AAEF,OAAI,EAAO,QAAQ,OACjB,OAAU,MAAM,EAAO,OAAO,IAAI,WAAW,6BAA6B;AAG5E,UAAO,EAAO,KAAM;;EAEtB,YAAY,MAAc;AAOxB,GALA,EAAY,kBAAkB,EAAE,UAAU,CAAC,aAAa,EAAE,CAAC,EAC3D,EAAY,kBAAkB,EAAE,UAAU,CAAC,eAAe,EAAE,CAAC,EAC7D,EAAY,kBAAkB,EAAE,UAAU,CAAC,YAAY,EAAE,CAAC,EAC1D,EAAY,kBAAkB,EAAE,UAAU,CAAC,kBAAkB,EAAE,CAAC,EAChE,EAAK,qBAAqB;IAAE,aAAa,EAAU;IAAI,QAAQ;IAAsB,CAAC,EAClF,KACF,EAAkB,EAAU;;EAGhC,UAAU,MAAQ;AAChB,KAAK,2BAA2B;IAC9B,QAAQ;IACR,cAAc,EAAmB,EAAI;IACtC,CAAC;;EAEL,CAAC;GAMS,UAA2B;CACtC,IAAM,EAAE,iBAAc,GAAsB,EACtC,IAAc,GAAgB,EAC9B,EAAE,YAAS,GAA2B;AAE5C,QAAO,EAAY;EACjB,YAAY,OAAO,EACjB,OACA,eAIwB;GACxB,IAAM,IAAS,MAAM,EAA6C;IAChE,SAAS;IACT,WAAW,KAAa,KAAA;IACxB,OAAO,EAAM,EAAwB;IACrC,WAAW;KAAE;KAAI;KAAO;IACxB,gBAA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AY,MAAc;AAIxB,GAHA,EAAY,kBAAkB,EAAE,UAAU,CAAC,aAAa,EAAE,CAAC,EAC3D,EAAY,kBAAkB,EAAE,UAAU,CAAC,aAAa,EAAU,GAAG,EAAE,CAAC,EACxE,EAAY,kBAAkB,EAAE,UAAU,CAAC,eAAe,EAAE,CAAC,EAC7D,EAAK,yBAAyB;IAAE,aAAa,EAAU;IAAI,QAAQ;IAAsB,CAAC;;EAE5F,UAAU,GAAK,MAAO;AACpB,KAAK,+BAA+B;IAClC,aAAa;IACb,QAAQ;IACR,cAAc,EAAmB,EAAI;IACtC,CAAC;;EAEL,CAAC"}
|
|
1
|
+
{"version":3,"file":"useWorkspaceMutations.js","names":[],"sources":["../../src/hooks/useWorkspaceMutations.ts"],"sourcesContent":["import { useMutation, useQueryClient, type QueryClient } from '@tanstack/react-query';\nimport { print } from 'graphql';\nimport { graphqlFetch } from '@burdenoff/fe-libs/shared/graphql';\nimport { useWorkspacesContext } from '../providers/WorkspacesProvider';\nimport { useWorkspacesEventEmitter } from './useWorkspacesEventEmitter';\nimport {\n UpdateWorkspaceDocument,\n DeleteWorkspaceDocument,\n ArchiveWorkspaceDocument,\n ReactivateWorkspaceDocument,\n} from '../generated/wspace-operations';\nimport type { CreateWorkspaceInput, UpdateWorkspaceInput, Workspace } from '../types';\nimport { safeTelemetryError } from '../utils/telemetryError';\n\n/**\n * GraphQL mutation to create workspace via global-tenant-svc\n * This creates workspace in global layer, which then syncs to wspace layer\n */\nconst CREATE_GLOBAL_WORKSPACE = `\n mutation CreateGlobalWorkspace($input: CreateWorkspaceInput!) {\n createWorkspace(input: $input) {\n id\n name\n slug\n type\n status\n tenantId\n organizationId\n createdAt\n }\n }\n`;\n\nfunction invalidateWorkspaceViews(queryClient: QueryClient, workspaceId?: string) {\n queryClient.invalidateQueries({ queryKey: ['workspaces'] });\n if (workspaceId) {\n queryClient.invalidateQueries({ queryKey: ['workspace', workspaceId] });\n queryClient.invalidateQueries({ queryKey: ['dashboard', 'workspace', workspaceId] });\n }\n queryClient.invalidateQueries({ queryKey: ['myWorkspaces'] });\n queryClient.invalidateQueries({ queryKey: ['myTenants'] });\n queryClient.invalidateQueries({ queryKey: ['myOrganizations'] });\n queryClient.invalidateQueries({ queryKey: ['dashboard', 'global'] });\n}\n\n/**\n * Hook to create a new workspace\n *\n * Creates workspace via global-tenant-svc (global gateway), which then\n * automatically syncs to wspace-workspace-svc. This ensures proper\n * tenant/org hierarchy management in the global layer.\n *\n * Required input fields:\n * - tenantId: Select from myTenants query\n * - organizationId: Select from myOrganizations query\n * - name: Display name\n * - slug: URL-friendly identifier (unique within tenant)\n */\nexport const useCreateWorkspace = () => {\n const { authToken, onWorkspaceCreate } = useWorkspacesContext();\n const queryClient = useQueryClient();\n const { emit } = useWorkspacesEventEmitter();\n\n return useMutation({\n mutationFn: async (input: CreateWorkspaceInput): Promise<Workspace> => {\n // Call global gateway for workspace creation\n const result = await graphqlFetch<{ createWorkspace: Workspace }>({\n gateway: 'global', // Use global gateway, not workspace gateway\n authToken: authToken || undefined,\n query: CREATE_GLOBAL_WORKSPACE,\n variables: { input },\n });\n\n if (result.errors?.length) {\n throw new Error(result.errors[0]?.message || 'Failed to create workspace');\n }\n\n return result.data!.createWorkspace;\n },\n onSuccess: (workspace) => {\n // Invalidate both global and workspace layer queries\n invalidateWorkspaceViews(queryClient, workspace.id);\n emit('workspace.created', { workspaceId: workspace.id, source: 'microfe-workspaces' });\n if (onWorkspaceCreate) {\n onWorkspaceCreate(workspace);\n }\n },\n onError: (err) => {\n emit('workspace.create_failed', {\n source: 'microfe-workspaces',\n errorMessage: safeTelemetryError(err),\n });\n },\n });\n};\n\n/**\n * Hook to update an existing workspace\n */\nexport const useUpdateWorkspace = () => {\n const { authToken } = useWorkspacesContext();\n const queryClient = useQueryClient();\n const { emit } = useWorkspacesEventEmitter();\n\n return useMutation({\n mutationFn: async ({\n id,\n input,\n }: {\n id: string;\n input: UpdateWorkspaceInput;\n }): Promise<Workspace> => {\n const result = await graphqlFetch<{ updateWorkspace: Workspace }>({\n gateway: 'workspace',\n authToken: authToken || undefined,\n query: print(UpdateWorkspaceDocument),\n variables: { id, input },\n workspaceToken: true, // Required by gateway RBAC for wspace-scoped operations\n });\n\n if (result.errors?.length) {\n throw new Error(result.errors[0]?.message || 'GraphQL error');\n }\n\n return result.data!.updateWorkspace;\n },\n onSuccess: (workspace) => {\n invalidateWorkspaceViews(queryClient, workspace.id);\n emit('workspace.updated', { workspaceId: workspace.id, source: 'microfe-workspaces' });\n },\n onError: (err, variables) => {\n emit('workspace.update_failed', {\n workspaceId: variables?.id,\n source: 'microfe-workspaces',\n errorMessage: safeTelemetryError(err),\n });\n },\n });\n};\n\n/**\n * Hook to delete a workspace\n */\nexport const useDeleteWorkspace = () => {\n const { authToken } = useWorkspacesContext();\n const queryClient = useQueryClient();\n const { emit } = useWorkspacesEventEmitter();\n\n return useMutation({\n mutationFn: async (id: string): Promise<boolean> => {\n const result = await graphqlFetch<{ deleteWorkspace: boolean }>({\n gateway: 'workspace',\n authToken: authToken || undefined,\n query: print(DeleteWorkspaceDocument),\n variables: { id },\n workspaceToken: true, // Required by gateway RBAC for wspace-scoped operations\n });\n\n if (result.errors?.length) {\n throw new Error(result.errors[0]?.message || 'GraphQL error');\n }\n\n return result.data!.deleteWorkspace;\n },\n onSuccess: (_, id) => {\n invalidateWorkspaceViews(queryClient, id);\n emit('workspace.deleted', { workspaceId: id, source: 'microfe-workspaces' });\n },\n onError: (err, id) => {\n emit('workspace.delete_failed', {\n workspaceId: id,\n source: 'microfe-workspaces',\n errorMessage: safeTelemetryError(err),\n });\n },\n });\n};\n\n/**\n * Hook to archive a workspace\n */\nexport const useArchiveWorkspace = () => {\n const { authToken } = useWorkspacesContext();\n const queryClient = useQueryClient();\n const { emit } = useWorkspacesEventEmitter();\n\n return useMutation({\n mutationFn: async (id: string): Promise<Workspace> => {\n const result = await graphqlFetch<{ updateWorkspace: Workspace }>({\n gateway: 'workspace',\n authToken: authToken || undefined,\n query: print(ArchiveWorkspaceDocument),\n variables: { id },\n workspaceToken: true, // Required by gateway RBAC for wspace-scoped operations\n });\n\n if (result.errors?.length) {\n throw new Error(result.errors[0]?.message || 'GraphQL error');\n }\n\n return result.data!.updateWorkspace;\n },\n onSuccess: (workspace) => {\n invalidateWorkspaceViews(queryClient, workspace.id);\n emit('workspace.archived', { workspaceId: workspace.id, source: 'microfe-workspaces' });\n },\n onError: (err, id) => {\n emit('workspace.archive_failed', {\n workspaceId: id,\n source: 'microfe-workspaces',\n errorMessage: safeTelemetryError(err),\n });\n },\n });\n};\n\n/**\n * Hook to reactivate an archived workspace\n */\nexport const useReactivateWorkspace = () => {\n const { authToken } = useWorkspacesContext();\n const queryClient = useQueryClient();\n const { emit } = useWorkspacesEventEmitter();\n\n return useMutation({\n mutationFn: async (id: string): Promise<Workspace> => {\n const result = await graphqlFetch<{ updateWorkspace: Workspace }>({\n gateway: 'workspace',\n authToken: authToken || undefined,\n query: print(ReactivateWorkspaceDocument),\n variables: { id },\n workspaceToken: true, // Required by gateway RBAC for wspace-scoped operations\n });\n\n if (result.errors?.length) {\n throw new Error(result.errors[0]?.message || 'GraphQL error');\n }\n\n return result.data!.updateWorkspace;\n },\n onSuccess: (workspace) => {\n invalidateWorkspaceViews(queryClient, workspace.id);\n emit('workspace.reactivated', { workspaceId: workspace.id, source: 'microfe-workspaces' });\n },\n onError: (err, id) => {\n emit('workspace.reactivate_failed', {\n workspaceId: id,\n source: 'microfe-workspaces',\n errorMessage: safeTelemetryError(err),\n });\n },\n });\n};\n"],"mappings":";;;;;;;;AAkBA,IAAM,IAA0B;AAehC,SAAS,EAAyB,GAA0B,GAAsB;AAShF,CARA,EAAY,kBAAkB,EAAE,UAAU,CAAC,aAAa,EAAE,CAAC,EACvD,MACF,EAAY,kBAAkB,EAAE,UAAU,CAAC,aAAa,EAAY,EAAE,CAAC,EACvE,EAAY,kBAAkB,EAAE,UAAU;EAAC;EAAa;EAAa;EAAY,EAAE,CAAC,GAEtF,EA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