@burdenoff/microfe-workspaces 2026.510.50 → 2026.511.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/generated/wspace-operations.d.ts +91 -0
- package/dist/generated/wspace-operations.d.ts.map +1 -1
- package/dist/generated/wspace-operations.js +79 -51
- package/dist/generated/wspace-operations.js.map +1 -1
- package/dist/hooks/useMemberMutations.d.ts.map +1 -1
- package/dist/hooks/useMemberMutations.js +141 -60
- package/dist/hooks/useMemberMutations.js.map +1 -1
- package/dist/hooks/useProjectMutations.d.ts.map +1 -1
- package/dist/hooks/useProjectMutations.js +84 -44
- package/dist/hooks/useProjectMutations.js.map +1 -1
- package/dist/hooks/useWorkspaceMutations.d.ts.map +1 -1
- package/dist/hooks/useWorkspaceMutations.js +64 -29
- package/dist/hooks/useWorkspaceMutations.js.map +1 -1
- package/dist/hooks/useWorkspacesEventEmitter.d.ts +5 -1
- package/dist/hooks/useWorkspacesEventEmitter.d.ts.map +1 -1
- package/dist/hooks/useWorkspacesEventEmitter.js +8 -7
- package/dist/hooks/useWorkspacesEventEmitter.js.map +1 -1
- package/dist/hooks/useWorkspacesPageView.d.ts +27 -0
- package/dist/hooks/useWorkspacesPageView.d.ts.map +1 -0
- package/dist/hooks/useWorkspacesPageView.js +29 -0
- package/dist/hooks/useWorkspacesPageView.js.map +1 -0
- package/dist/pages/ActivityListPage.d.ts.map +1 -1
- package/dist/pages/ActivityListPage.js +59 -56
- package/dist/pages/ActivityListPage.js.map +1 -1
- package/dist/pages/CreateWorkspacePage.d.ts.map +1 -1
- package/dist/pages/CreateWorkspacePage.js +104 -104
- package/dist/pages/CreateWorkspacePage.js.map +1 -1
- package/dist/pages/InviteAcceptancePage.d.ts.map +1 -1
- package/dist/pages/InviteAcceptancePage.js +197 -216
- package/dist/pages/InviteAcceptancePage.js.map +1 -1
- package/dist/pages/MembersListPage.d.ts.map +1 -1
- package/dist/pages/MembersListPage.js +142 -138
- package/dist/pages/MembersListPage.js.map +1 -1
- package/dist/pages/ProjectDetailPage.d.ts.map +1 -1
- package/dist/pages/ProjectDetailPage.js +181 -176
- package/dist/pages/ProjectDetailPage.js.map +1 -1
- package/dist/pages/ProjectsListPage.d.ts.map +1 -1
- package/dist/pages/ProjectsListPage.js +175 -171
- package/dist/pages/ProjectsListPage.js.map +1 -1
- package/dist/pages/WorkspaceDetailPage.d.ts.map +1 -1
- package/dist/pages/WorkspaceDetailPage.js +104 -101
- package/dist/pages/WorkspaceDetailPage.js.map +1 -1
- package/dist/pages/WorkspaceSettingsPage.d.ts.map +1 -1
- package/dist/pages/WorkspaceSettingsPage.js +182 -137
- package/dist/pages/WorkspaceSettingsPage.js.map +1 -1
- package/dist/pages/WorkspacesListPage.d.ts.map +1 -1
- package/dist/pages/WorkspacesListPage.js +77 -77
- package/dist/pages/WorkspacesListPage.js.map +1 -1
- package/dist/pages/dashboard/DashboardCustomizer.d.ts.map +1 -1
- package/dist/pages/dashboard/DashboardCustomizer.js +53 -55
- package/dist/pages/dashboard/DashboardCustomizer.js.map +1 -1
- package/dist/pages/dashboard/DashboardGrid.d.ts.map +1 -1
- package/dist/pages/dashboard/DashboardGrid.js +33 -36
- package/dist/pages/dashboard/DashboardGrid.js.map +1 -1
- package/dist/pages/dashboard/DashboardPage.d.ts.map +1 -1
- package/dist/pages/dashboard/DashboardPage.js +67 -65
- package/dist/pages/dashboard/DashboardPage.js.map +1 -1
- package/dist/pages/dashboard/WidgetWrapper.d.ts.map +1 -1
- package/dist/pages/dashboard/WidgetWrapper.js +3 -6
- package/dist/pages/dashboard/WidgetWrapper.js.map +1 -1
- package/dist/utils/i18n.d.ts +13 -0
- package/dist/utils/i18n.d.ts.map +1 -0
- package/dist/utils/i18n.js +12 -0
- package/dist/utils/i18n.js.map +1 -0
- package/dist/utils/telemetryError.d.ts +2 -0
- package/dist/utils/telemetryError.d.ts.map +1 -0
- package/dist/utils/telemetryError.js +28 -0
- package/dist/utils/telemetryError.js.map +1 -0
- package/package.json +9 -4
|
@@ -1,127 +1,167 @@
|
|
|
1
1
|
import { useWorkspacesContext as e } from "../providers/WorkspacesProvider.js";
|
|
2
2
|
import { useWorkspacesEventEmitter as t } from "./useWorkspacesEventEmitter.js";
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
3
|
+
import { safeTelemetryError as n } from "../utils/telemetryError.js";
|
|
4
|
+
import { useMutation as r, useQueryClient as i } from "@tanstack/react-query";
|
|
5
|
+
import { graphqlFetch as a } from "@burdenoff/fe-libs/shared/graphql";
|
|
5
6
|
//#region src/hooks/useProjectMutations.ts
|
|
6
|
-
var
|
|
7
|
-
let { authToken:
|
|
8
|
-
return
|
|
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 = (s) => {
|
|
8
|
+
let { authToken: c, onProjectCreate: l, workspaceId: u } = e(), d = i(), { emit: f } = t(), p = s || u;
|
|
9
|
+
return r({
|
|
9
10
|
mutationFn: async (e) => {
|
|
10
|
-
let t = await
|
|
11
|
+
let t = await a({
|
|
11
12
|
gateway: "workspace",
|
|
12
|
-
authToken:
|
|
13
|
-
query:
|
|
13
|
+
authToken: c || void 0,
|
|
14
|
+
query: o,
|
|
14
15
|
variables: { input: e },
|
|
15
|
-
workspaceId:
|
|
16
|
+
workspaceId: p || void 0,
|
|
16
17
|
workspaceToken: !0
|
|
17
18
|
});
|
|
18
19
|
if (t.errors?.length) throw Error(t.errors[0]?.message || "GraphQL error");
|
|
19
20
|
return t.data.createProject;
|
|
20
21
|
},
|
|
21
22
|
onSuccess: (e) => {
|
|
22
|
-
|
|
23
|
+
d.invalidateQueries({ queryKey: ["projects"] }), d.invalidateQueries({ queryKey: ["myProjects"] }), f("project.created", {
|
|
23
24
|
projectId: e.id,
|
|
24
25
|
workspaceId: e.workspaceId,
|
|
25
26
|
source: "microfe-workspaces"
|
|
26
|
-
}),
|
|
27
|
+
}), l && l(e);
|
|
28
|
+
},
|
|
29
|
+
onError: (e) => {
|
|
30
|
+
f("project.create_failed", {
|
|
31
|
+
workspaceId: p || void 0,
|
|
32
|
+
source: "microfe-workspaces",
|
|
33
|
+
errorMessage: n(e)
|
|
34
|
+
});
|
|
27
35
|
}
|
|
28
36
|
});
|
|
29
|
-
},
|
|
30
|
-
let { authToken:
|
|
31
|
-
return
|
|
37
|
+
}, f = (o) => {
|
|
38
|
+
let { authToken: c, workspaceId: l } = e(), u = i(), { emit: d } = t(), f = o || l;
|
|
39
|
+
return r({
|
|
32
40
|
mutationFn: async ({ id: e, input: t }) => {
|
|
33
|
-
let n = await
|
|
41
|
+
let n = await a({
|
|
34
42
|
gateway: "workspace",
|
|
35
|
-
authToken:
|
|
36
|
-
query:
|
|
43
|
+
authToken: c || void 0,
|
|
44
|
+
query: s,
|
|
37
45
|
variables: {
|
|
38
46
|
id: e,
|
|
39
47
|
input: t
|
|
40
48
|
},
|
|
41
|
-
workspaceId:
|
|
49
|
+
workspaceId: f || void 0,
|
|
42
50
|
workspaceToken: !0
|
|
43
51
|
});
|
|
44
52
|
if (n.errors?.length) throw Error(n.errors[0]?.message || "GraphQL error");
|
|
45
53
|
return n.data.updateProject;
|
|
46
54
|
},
|
|
47
55
|
onSuccess: (e) => {
|
|
48
|
-
|
|
56
|
+
u.invalidateQueries({ queryKey: ["projects"] }), u.invalidateQueries({ queryKey: ["project", e.id] }), u.invalidateQueries({ queryKey: ["myProjects"] }), d("project.updated", {
|
|
49
57
|
projectId: e.id,
|
|
50
58
|
workspaceId: e.workspaceId,
|
|
51
59
|
source: "microfe-workspaces"
|
|
52
60
|
});
|
|
61
|
+
},
|
|
62
|
+
onError: (e, t) => {
|
|
63
|
+
d("project.update_failed", {
|
|
64
|
+
projectId: t?.id,
|
|
65
|
+
workspaceId: f || void 0,
|
|
66
|
+
source: "microfe-workspaces",
|
|
67
|
+
errorMessage: n(e)
|
|
68
|
+
});
|
|
53
69
|
}
|
|
54
70
|
});
|
|
55
|
-
},
|
|
56
|
-
let { authToken:
|
|
57
|
-
return
|
|
71
|
+
}, p = (o) => {
|
|
72
|
+
let { authToken: s, workspaceId: l } = e(), u = i(), { emit: d } = t(), f = o || l;
|
|
73
|
+
return r({
|
|
58
74
|
mutationFn: async (e) => {
|
|
59
|
-
let t = await
|
|
75
|
+
let t = await a({
|
|
60
76
|
gateway: "workspace",
|
|
61
|
-
authToken:
|
|
62
|
-
query:
|
|
77
|
+
authToken: s || void 0,
|
|
78
|
+
query: c,
|
|
63
79
|
variables: { id: e },
|
|
64
|
-
workspaceId:
|
|
80
|
+
workspaceId: f || void 0,
|
|
65
81
|
workspaceToken: !0
|
|
66
82
|
});
|
|
67
83
|
if (t.errors?.length) throw Error(t.errors[0]?.message || "GraphQL error");
|
|
68
84
|
return t.data.deleteProject;
|
|
69
85
|
},
|
|
70
86
|
onSuccess: (e, t) => {
|
|
71
|
-
|
|
87
|
+
u.invalidateQueries({ queryKey: ["projects"] }), u.invalidateQueries({ queryKey: ["project", t] }), u.invalidateQueries({ queryKey: ["myProjects"] }), d("project.deleted", {
|
|
72
88
|
projectId: t,
|
|
73
89
|
source: "microfe-workspaces"
|
|
74
90
|
});
|
|
91
|
+
},
|
|
92
|
+
onError: (e, t) => {
|
|
93
|
+
d("project.delete_failed", {
|
|
94
|
+
projectId: t,
|
|
95
|
+
workspaceId: f || void 0,
|
|
96
|
+
source: "microfe-workspaces",
|
|
97
|
+
errorMessage: n(e)
|
|
98
|
+
});
|
|
75
99
|
}
|
|
76
100
|
});
|
|
77
|
-
},
|
|
78
|
-
let { authToken:
|
|
79
|
-
return
|
|
101
|
+
}, m = (o) => {
|
|
102
|
+
let { authToken: s, workspaceId: c } = e(), u = i(), { emit: d } = t(), f = o || c;
|
|
103
|
+
return r({
|
|
80
104
|
mutationFn: async (e) => {
|
|
81
|
-
let t = await
|
|
105
|
+
let t = await a({
|
|
82
106
|
gateway: "workspace",
|
|
83
|
-
authToken:
|
|
84
|
-
query:
|
|
107
|
+
authToken: s || void 0,
|
|
108
|
+
query: l,
|
|
85
109
|
variables: { id: e },
|
|
86
|
-
workspaceId:
|
|
110
|
+
workspaceId: f || void 0,
|
|
87
111
|
workspaceToken: !0
|
|
88
112
|
});
|
|
89
113
|
if (t.errors?.length) throw Error(t.errors[0]?.message || "GraphQL error");
|
|
90
114
|
return t.data.archiveProject;
|
|
91
115
|
},
|
|
92
116
|
onSuccess: (e) => {
|
|
93
|
-
|
|
117
|
+
u.invalidateQueries({ queryKey: ["projects"] }), u.invalidateQueries({ queryKey: ["project", e.id] }), u.invalidateQueries({ queryKey: ["myProjects"] }), d("project.archived", {
|
|
94
118
|
projectId: e.id,
|
|
95
119
|
workspaceId: e.workspaceId,
|
|
96
120
|
source: "microfe-workspaces"
|
|
97
121
|
});
|
|
122
|
+
},
|
|
123
|
+
onError: (e, t) => {
|
|
124
|
+
d("project.archive_failed", {
|
|
125
|
+
projectId: t,
|
|
126
|
+
workspaceId: f || void 0,
|
|
127
|
+
source: "microfe-workspaces",
|
|
128
|
+
errorMessage: n(e)
|
|
129
|
+
});
|
|
98
130
|
}
|
|
99
131
|
});
|
|
100
|
-
},
|
|
101
|
-
let { authToken:
|
|
102
|
-
return
|
|
132
|
+
}, h = (o) => {
|
|
133
|
+
let { authToken: s, workspaceId: c } = e(), l = i(), { emit: d } = t(), f = o || c;
|
|
134
|
+
return r({
|
|
103
135
|
mutationFn: async (e) => {
|
|
104
|
-
let t = await
|
|
136
|
+
let t = await a({
|
|
105
137
|
gateway: "workspace",
|
|
106
|
-
authToken:
|
|
107
|
-
query:
|
|
138
|
+
authToken: s || void 0,
|
|
139
|
+
query: u,
|
|
108
140
|
variables: { id: e },
|
|
109
|
-
workspaceId:
|
|
141
|
+
workspaceId: f || void 0,
|
|
110
142
|
workspaceToken: !0
|
|
111
143
|
});
|
|
112
144
|
if (t.errors?.length) throw Error(t.errors[0]?.message || "GraphQL error");
|
|
113
145
|
return t.data.unarchiveProject;
|
|
114
146
|
},
|
|
115
147
|
onSuccess: (e) => {
|
|
116
|
-
|
|
148
|
+
l.invalidateQueries({ queryKey: ["projects"] }), l.invalidateQueries({ queryKey: ["project", e.id] }), l.invalidateQueries({ queryKey: ["myProjects"] }), d("project.unarchived", {
|
|
117
149
|
projectId: e.id,
|
|
118
150
|
workspaceId: e.workspaceId,
|
|
119
151
|
source: "microfe-workspaces"
|
|
120
152
|
});
|
|
153
|
+
},
|
|
154
|
+
onError: (e, t) => {
|
|
155
|
+
d("project.unarchive_failed", {
|
|
156
|
+
projectId: t,
|
|
157
|
+
workspaceId: f || void 0,
|
|
158
|
+
source: "microfe-workspaces",
|
|
159
|
+
errorMessage: n(e)
|
|
160
|
+
});
|
|
121
161
|
}
|
|
122
162
|
});
|
|
123
163
|
};
|
|
124
164
|
//#endregion
|
|
125
|
-
export {
|
|
165
|
+
export { m as useArchiveProject, d as useCreateProject, p as useDeleteProject, h as useUnarchiveProject, f as useUpdateProject };
|
|
126
166
|
|
|
127
167
|
//# 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 { CreateProjectInput, UpdateProjectInput, Project } from '../types';\nimport { useWorkspacesEventEmitter } from './useWorkspacesEventEmitter';\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\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 });\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 });\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 });\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 });\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 });\n};\n"],"mappings":";;;;;AAMA,IAAM,IAA0B,+NAe1B,IAA0B,4OAe1B,IAA0B,6EAM1B,IAA2B,mIAU3B,IAA6B,uIAatB,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;IAC5D,SAAS;IACT,WAAW,KAAa,KAAA;IACxB,OAAO;IACP,WAAW,EAAE,UAAO;IACpB,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;AAQtB,GAPA,EAAY,kBAAkB,EAAE,UAAU,CAAC,WAAW,EAAE,CAAC,EACzD,EAAY,kBAAkB,EAAE,UAAU,CAAC,aAAa,EAAE,CAAC,EAC3D,EAAK,mBAAmB;IACtB,WAAW,EAAQ;IACnB,aAAa,EAAQ;IACrB,QAAQ;IACT,CAAC,EACE,KACF,EAAgB,EAAQ;;EAG7B,CAAC;GAMS,KAAoB,MAAiC;CAChE,IAAM,EAAE,cAAW,mBAAgB,GAAsB,EACnD,IAAc,GAAgB,EAC9B,EAAE,YAAS,GAA2B,EACtC,IAAuB,KAAuB;AAEpD,QAAO,EAAY;EACjB,YAAY,OAAO,EACjB,OACA,eAI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ItB,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;;EAEL,CAAC"}
|
|
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 { CreateProjectInput, UpdateProjectInput, Project } 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\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 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":";;;;;;AAOA,IAAM,IAA0B,+NAe1B,IAA0B,4OAe1B,IAA0B,6EAM1B,IAA2B,mIAU3B,IAA6B,uIAatB,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;IAC5D,SAAS;IACT,WAAW,KAAa,KAAA;IACxB,OAAO;IACP,WAAW,EAAE,UAAO;IACpB,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;AAQtB,GAPA,EAAY,kBAAkB,EAAE,UAAU,CAAC,WAAW,EAAE,CAAC,EACzD,EAAY,kBAAkB,EAAE,UAAU,CAAC,aAAa,EAAE,CAAC,EAC3D,EAAK,mBAAmB;IACtB,WAAW,EAAQ;IACnB,aAAa,EAAQ;IACrB,QAAQ;IACT,CAAC,EACE,KACF,EAAgB,EAAQ;;EAG5B,UAAU,MAAQ;AAChB,KAAK,yBAAyB;IAC5B,aAAa,KAAwB,KAAA;IACrC,QAAQ;IACR,cAAc,EAAmB,EAAI;IACtC,CAAC;;EAEL,CAAC;GAMS,KAAoB,MAAiC;CAChE,IAAM,EAAE,cAAW,mBAAgB,GAAsB,EACnD,IAAc,GAAgB,EAC9B,EAAE,YAAS,GAA2B,EACtC,IAAuB,KAAuB;AAEpD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AAC;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;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 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useWorkspaceMutations.d.ts","sourceRoot":"","sources":["../../src/hooks/useWorkspaceMutations.ts"],"names":[],"mappings":"AAWA,OAAO,KAAK,EAAE,oBAAoB,EAAE,oBAAoB,EAAE,SAAS,EAAE,MAAM,UAAU,CAAC;
|
|
1
|
+
{"version":3,"file":"useWorkspaceMutations.d.ts","sourceRoot":"","sources":["../../src/hooks/useWorkspaceMutations.ts"],"names":[],"mappings":"AAWA,OAAO,KAAK,EAAE,oBAAoB,EAAE,oBAAoB,EAAE,SAAS,EAAE,MAAM,UAAU,CAAC;AAsBtF;;;;;;;;;;;;GAYG;AACH,eAAO,MAAM,kBAAkB,0GAuC9B,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,kBAAkB;QAUrB,MAAM;WACH,oBAAoB;WA8BhC,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,kBAAkB,0FAmC9B,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,mBAAmB,4FAmC/B,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,sBAAsB,4FAmClC,CAAC"}
|
|
@@ -1,18 +1,19 @@
|
|
|
1
1
|
import { useWorkspacesContext as e } from "../providers/WorkspacesProvider.js";
|
|
2
2
|
import { ArchiveWorkspaceDocument as t, DeleteWorkspaceDocument as n, ReactivateWorkspaceDocument as r, UpdateWorkspaceDocument as i } from "../generated/wspace-operations.js";
|
|
3
3
|
import { useWorkspacesEventEmitter as a } from "./useWorkspacesEventEmitter.js";
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
4
|
+
import { safeTelemetryError as o } from "../utils/telemetryError.js";
|
|
5
|
+
import { useMutation as s, useQueryClient as c } from "@tanstack/react-query";
|
|
6
|
+
import { print as l } from "graphql";
|
|
7
|
+
import { graphqlFetch as u } from "@burdenoff/fe-libs/shared/graphql";
|
|
7
8
|
//#region src/hooks/useWorkspaceMutations.ts
|
|
8
|
-
var
|
|
9
|
-
let { authToken: t, onWorkspaceCreate: n } = e(), r =
|
|
10
|
-
return
|
|
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", f = () => {
|
|
10
|
+
let { authToken: t, onWorkspaceCreate: n } = e(), r = c(), { emit: i } = a();
|
|
11
|
+
return s({
|
|
11
12
|
mutationFn: async (e) => {
|
|
12
|
-
let n = await
|
|
13
|
+
let n = await u({
|
|
13
14
|
gateway: "global",
|
|
14
15
|
authToken: t || void 0,
|
|
15
|
-
query:
|
|
16
|
+
query: d,
|
|
16
17
|
variables: { input: e }
|
|
17
18
|
});
|
|
18
19
|
if (n.errors?.length) throw Error(n.errors[0]?.message || "Failed to create workspace");
|
|
@@ -23,16 +24,22 @@ var u = "\n mutation CreateGlobalWorkspace($input: CreateWorkspaceInput!) {\n
|
|
|
23
24
|
workspaceId: e.id,
|
|
24
25
|
source: "microfe-workspaces"
|
|
25
26
|
}), n && n(e);
|
|
27
|
+
},
|
|
28
|
+
onError: (e) => {
|
|
29
|
+
i("workspace.create_failed", {
|
|
30
|
+
source: "microfe-workspaces",
|
|
31
|
+
errorMessage: o(e)
|
|
32
|
+
});
|
|
26
33
|
}
|
|
27
34
|
});
|
|
28
|
-
},
|
|
29
|
-
let { authToken: t } = e(), n =
|
|
30
|
-
return
|
|
35
|
+
}, p = () => {
|
|
36
|
+
let { authToken: t } = e(), n = c(), { emit: r } = a();
|
|
37
|
+
return s({
|
|
31
38
|
mutationFn: async ({ id: e, input: n }) => {
|
|
32
|
-
let r = await
|
|
39
|
+
let r = await u({
|
|
33
40
|
gateway: "workspace",
|
|
34
41
|
authToken: t || void 0,
|
|
35
|
-
query:
|
|
42
|
+
query: l(i),
|
|
36
43
|
variables: {
|
|
37
44
|
id: e,
|
|
38
45
|
input: n
|
|
@@ -47,16 +54,23 @@ var u = "\n mutation CreateGlobalWorkspace($input: CreateWorkspaceInput!) {\n
|
|
|
47
54
|
workspaceId: e.id,
|
|
48
55
|
source: "microfe-workspaces"
|
|
49
56
|
});
|
|
57
|
+
},
|
|
58
|
+
onError: (e, t) => {
|
|
59
|
+
r("workspace.update_failed", {
|
|
60
|
+
workspaceId: t?.id,
|
|
61
|
+
source: "microfe-workspaces",
|
|
62
|
+
errorMessage: o(e)
|
|
63
|
+
});
|
|
50
64
|
}
|
|
51
65
|
});
|
|
52
|
-
},
|
|
53
|
-
let { authToken: t } = e(), r =
|
|
54
|
-
return
|
|
66
|
+
}, m = () => {
|
|
67
|
+
let { authToken: t } = e(), r = c(), { emit: i } = a();
|
|
68
|
+
return s({
|
|
55
69
|
mutationFn: async (e) => {
|
|
56
|
-
let r = await
|
|
70
|
+
let r = await u({
|
|
57
71
|
gateway: "workspace",
|
|
58
72
|
authToken: t || void 0,
|
|
59
|
-
query:
|
|
73
|
+
query: l(n),
|
|
60
74
|
variables: { id: e },
|
|
61
75
|
workspaceToken: !0
|
|
62
76
|
});
|
|
@@ -68,16 +82,23 @@ var u = "\n mutation CreateGlobalWorkspace($input: CreateWorkspaceInput!) {\n
|
|
|
68
82
|
workspaceId: t,
|
|
69
83
|
source: "microfe-workspaces"
|
|
70
84
|
});
|
|
85
|
+
},
|
|
86
|
+
onError: (e, t) => {
|
|
87
|
+
i("workspace.delete_failed", {
|
|
88
|
+
workspaceId: t,
|
|
89
|
+
source: "microfe-workspaces",
|
|
90
|
+
errorMessage: o(e)
|
|
91
|
+
});
|
|
71
92
|
}
|
|
72
93
|
});
|
|
73
|
-
},
|
|
74
|
-
let { authToken: n } = e(), r =
|
|
75
|
-
return
|
|
94
|
+
}, h = () => {
|
|
95
|
+
let { authToken: n } = e(), r = c(), { emit: i } = a();
|
|
96
|
+
return s({
|
|
76
97
|
mutationFn: async (e) => {
|
|
77
|
-
let r = await
|
|
98
|
+
let r = await u({
|
|
78
99
|
gateway: "workspace",
|
|
79
100
|
authToken: n || void 0,
|
|
80
|
-
query:
|
|
101
|
+
query: l(t),
|
|
81
102
|
variables: { id: e },
|
|
82
103
|
workspaceToken: !0
|
|
83
104
|
});
|
|
@@ -89,16 +110,23 @@ var u = "\n mutation CreateGlobalWorkspace($input: CreateWorkspaceInput!) {\n
|
|
|
89
110
|
workspaceId: e.id,
|
|
90
111
|
source: "microfe-workspaces"
|
|
91
112
|
});
|
|
113
|
+
},
|
|
114
|
+
onError: (e, t) => {
|
|
115
|
+
i("workspace.archive_failed", {
|
|
116
|
+
workspaceId: t,
|
|
117
|
+
source: "microfe-workspaces",
|
|
118
|
+
errorMessage: o(e)
|
|
119
|
+
});
|
|
92
120
|
}
|
|
93
121
|
});
|
|
94
|
-
},
|
|
95
|
-
let { authToken: t } = e(), n =
|
|
96
|
-
return
|
|
122
|
+
}, g = () => {
|
|
123
|
+
let { authToken: t } = e(), n = c(), { emit: i } = a();
|
|
124
|
+
return s({
|
|
97
125
|
mutationFn: async (e) => {
|
|
98
|
-
let n = await
|
|
126
|
+
let n = await u({
|
|
99
127
|
gateway: "workspace",
|
|
100
128
|
authToken: t || void 0,
|
|
101
|
-
query:
|
|
129
|
+
query: l(r),
|
|
102
130
|
variables: { id: e },
|
|
103
131
|
workspaceToken: !0
|
|
104
132
|
});
|
|
@@ -110,10 +138,17 @@ var u = "\n mutation CreateGlobalWorkspace($input: CreateWorkspaceInput!) {\n
|
|
|
110
138
|
workspaceId: e.id,
|
|
111
139
|
source: "microfe-workspaces"
|
|
112
140
|
});
|
|
141
|
+
},
|
|
142
|
+
onError: (e, t) => {
|
|
143
|
+
i("workspace.reactivate_failed", {
|
|
144
|
+
workspaceId: t,
|
|
145
|
+
source: "microfe-workspaces",
|
|
146
|
+
errorMessage: o(e)
|
|
147
|
+
});
|
|
113
148
|
}
|
|
114
149
|
});
|
|
115
150
|
};
|
|
116
151
|
//#endregion
|
|
117
|
-
export {
|
|
152
|
+
export { h as useArchiveWorkspace, f as useCreateWorkspace, m as useDeleteWorkspace, g as useReactivateWorkspace, p as useUpdateWorkspace };
|
|
118
153
|
|
|
119
154
|
//# 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';\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 });\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 });\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 });\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 });\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 });\n};\n"],"mappings":";;;;;;;AAiBA,IAAM,IAA0B,8OA4BnB,UAA2B;CACtC,IAAM,EAAE,cAAW,yBAAsB,GAAsB,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,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,sBAAsB;IAAE,aAAa,EAAU;IAAI,QAAQ;IAAsB,CAAC;;EAE1F,CAAC;GAMS,UAA+B;CAC1C,IAAM,EAAE,iBAAc,GAAsB,EACtC,IAAc,GAAgB,EAC9B,EAAE,YAAS,GAA2B;AAE5C,QAAO,EAAY;EACjB,YAAY,OAAO,MAAmC;GACpD,IAAM,IAAS,MAAM,EAA6C;IAChE,SAAS;IACT,WAAW,KAAa,KAAA;IACxB,OAAO,EAAM,EAA4B;IACzC,WAAW,EAAE,OAAI;IACjB,gBAAgB;IACjB,CAAC;AAEF,OAAI,EAAO,QAAQ,OACjB,OAAU,MAAM,EAAO,OAAO,IAAI,WAAW,gBAAgB;AAG/D,UAAO,EAAO,KAAM;;EAEtB,YAAY,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;;EAE7F,CAAC"}
|
|
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,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AM,EAA6C;IAChE,SAAS;IACT,WAAW,KAAa,KAAA;IACxB,OAAO,EAAM,EAA4B;IACzC,WAAW,EAAE,OAAI;IACjB,gBAAgB;IACjB,CAAC;AAEF,OAAI,EAAO,QAAQ,OACjB,OAAU,MAAM,EAAO,OAAO,IAAI,WAAW,gBAAgB;AAG/D,UAAO,EAAO,KAAM;;EAEtB,YAAY,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,4 +1,4 @@
|
|
|
1
|
-
export type WorkspacesDomainEvent = 'workspace.created' | 'workspace.updated' | 'workspace.deleted' | 'workspace.archived' | 'workspace.reactivated' | 'project.created' | 'project.updated' | 'project.deleted' | 'project.archived' | 'project.unarchived' | 'workspace-member.added' | 'workspace-member.removed' | 'workspace-member.role-updated' | 'workspace-invitation.created' | 'workspace-invitation.accepted' | 'workspace-invitation.rejected' | 'workspace-invitation.cancelled' | 'workspace-invitation.resent' | 'workspace-invitation.deleted' | 'workspace-activity.appended';
|
|
1
|
+
export type WorkspacesDomainEvent = 'workspace.created' | 'workspace.updated' | 'workspace.deleted' | 'workspace.archived' | 'workspace.reactivated' | 'project.created' | 'project.updated' | 'project.deleted' | 'project.archived' | 'project.unarchived' | 'workspace-member.added' | 'workspace-member.removed' | 'workspace-member.role-updated' | 'workspace-invitation.created' | 'workspace-invitation.updated' | 'workspace-invitation.accepted' | 'workspace-invitation.rejected' | 'workspace-invitation.cancelled' | 'workspace-invitation.resent' | 'workspace-invitation.deleted' | 'workspace-activity.appended' | 'workspace.create_failed' | 'workspace.update_failed' | 'workspace.delete_failed' | 'workspace.archive_failed' | 'workspace.reactivate_failed' | 'project.create_failed' | 'project.update_failed' | 'project.delete_failed' | 'project.archive_failed' | 'project.unarchive_failed' | 'workspace-member.add_failed' | 'workspace-member.remove_failed' | 'workspace-member.role-update_failed' | 'workspace-invitation.create_failed' | 'workspace-invitation.update_failed' | 'workspace-invitation.accept_failed' | 'workspace-invitation.reject_failed' | 'workspace-invitation.cancel_failed' | 'workspace-invitation.resend_failed' | 'workspace-invitation.delete_failed' | 'workspaces.page.viewed';
|
|
2
2
|
export interface WorkspacesEventPayload {
|
|
3
3
|
workspaceId?: string;
|
|
4
4
|
projectId?: string;
|
|
@@ -7,6 +7,10 @@ export interface WorkspacesEventPayload {
|
|
|
7
7
|
userId?: string;
|
|
8
8
|
email?: string;
|
|
9
9
|
source?: string;
|
|
10
|
+
page?: string;
|
|
11
|
+
durationMs?: number;
|
|
12
|
+
errorCode?: string;
|
|
13
|
+
errorMessage?: string;
|
|
10
14
|
}
|
|
11
15
|
export declare function useWorkspacesEventEmitter(): {
|
|
12
16
|
emit: (event: WorkspacesDomainEvent, payload?: WorkspacesEventPayload) => void;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useWorkspacesEventEmitter.d.ts","sourceRoot":"","sources":["../../src/hooks/useWorkspacesEventEmitter.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"useWorkspacesEventEmitter.d.ts","sourceRoot":"","sources":["../../src/hooks/useWorkspacesEventEmitter.ts"],"names":[],"mappings":"AAcA,MAAM,MAAM,qBAAqB,GAE7B,mBAAmB,GACnB,mBAAmB,GACnB,mBAAmB,GACnB,oBAAoB,GACpB,uBAAuB,GACvB,iBAAiB,GACjB,iBAAiB,GACjB,iBAAiB,GACjB,kBAAkB,GAClB,oBAAoB,GACpB,wBAAwB,GACxB,0BAA0B,GAC1B,+BAA+B,GAC/B,8BAA8B,GAC9B,8BAA8B,GAC9B,+BAA+B,GAC/B,+BAA+B,GAC/B,gCAAgC,GAChC,6BAA6B,GAC7B,8BAA8B,GAC9B,6BAA6B,GAE7B,yBAAyB,GACzB,yBAAyB,GACzB,yBAAyB,GACzB,0BAA0B,GAC1B,6BAA6B,GAC7B,uBAAuB,GACvB,uBAAuB,GACvB,uBAAuB,GACvB,wBAAwB,GACxB,0BAA0B,GAC1B,6BAA6B,GAC7B,gCAAgC,GAChC,qCAAqC,GACrC,oCAAoC,GACpC,oCAAoC,GACpC,oCAAoC,GACpC,oCAAoC,GACpC,oCAAoC,GACpC,oCAAoC,GACpC,oCAAoC,GAGpC,wBAAwB,CAAC;AAE7B,MAAM,WAAW,sBAAsB;IACrC,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,MAAM,CAAC,EAAE,MAAM,CAAC;IAEhB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,YAAY,CAAC,EAAE,MAAM,CAAC;CACvB;AAED,wBAAgB,yBAAyB,IAAI;IAC3C,IAAI,EAAE,CAAC,KAAK,EAAE,qBAAqB,EAAE,OAAO,CAAC,EAAE,sBAAsB,KAAK,IAAI,CAAC;CAChF,CAyBA"}
|
|
@@ -1,14 +1,15 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { useCallback as e } from "react";
|
|
2
|
+
import { useEventBus as t } from "@burdenoff/fe-libs/shared/events";
|
|
2
3
|
//#region src/hooks/useWorkspacesEventEmitter.ts
|
|
3
|
-
function
|
|
4
|
-
let
|
|
5
|
-
return { emit: (e, t = {}) => {
|
|
4
|
+
function n() {
|
|
5
|
+
let n = t();
|
|
6
|
+
return { emit: e((e, t = {}) => {
|
|
6
7
|
try {
|
|
7
|
-
n(e, t);
|
|
8
|
+
n.emit(e, t);
|
|
8
9
|
} catch {}
|
|
9
|
-
} };
|
|
10
|
+
}, [n]) };
|
|
10
11
|
}
|
|
11
12
|
//#endregion
|
|
12
|
-
export {
|
|
13
|
+
export { n as useWorkspacesEventEmitter };
|
|
13
14
|
|
|
14
15
|
//# sourceMappingURL=useWorkspacesEventEmitter.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useWorkspacesEventEmitter.js","names":[],"sources":["../../src/hooks/useWorkspacesEventEmitter.ts"],"sourcesContent":["/**\n * Workspaces-domain event emitter. Emits lifecycle events to the host shell's\n * event bus per `~/products/infra/infra-specs/microfrontends/47-FRONTEND-EVENT-BUS.md`.\n *\n * The MFE never sinks directly to Rybbit/audit — it goes through the bus.\n *\n * The fe-libs `EventBus.emit` is statically typed against `BurdenoffEventName`\n * which doesn't list our workspaces-domain names. The runtime bus is dynamic,\n * so the cast loses autocomplete but is sound.\n */\nimport { useEventBus } from '@burdenoff/fe-libs/shared/events';\n\nexport type WorkspacesDomainEvent =\n | 'workspace.created'\n | 'workspace.updated'\n | 'workspace.deleted'\n | 'workspace.archived'\n | 'workspace.reactivated'\n | 'project.created'\n | 'project.updated'\n | 'project.deleted'\n | 'project.archived'\n | 'project.unarchived'\n | 'workspace-member.added'\n | 'workspace-member.removed'\n | 'workspace-member.role-updated'\n | 'workspace-invitation.created'\n | 'workspace-invitation.accepted'\n | 'workspace-invitation.rejected'\n | 'workspace-invitation.cancelled'\n | 'workspace-invitation.resent'\n | 'workspace-invitation.deleted'\n | 'workspace-activity.appended';\n\nexport interface WorkspacesEventPayload {\n workspaceId?: string;\n projectId?: string;\n memberId?: string;\n invitationId?: string;\n userId?: string;\n email?: string;\n source?: string;\n}\n\nexport function useWorkspacesEventEmitter(): {\n emit: (event: WorkspacesDomainEvent, payload?: WorkspacesEventPayload) => void;\n} {\n const bus = useEventBus();\n
|
|
1
|
+
{"version":3,"file":"useWorkspacesEventEmitter.js","names":[],"sources":["../../src/hooks/useWorkspacesEventEmitter.ts"],"sourcesContent":["/**\n * Workspaces-domain event emitter. Emits lifecycle events to the host shell's\n * event bus per `~/products/infra/infra-specs/microfrontends/47-FRONTEND-EVENT-BUS.md`.\n *\n * The MFE never sinks directly to Rybbit/audit — it goes through the bus.\n *\n * The fe-libs `EventBus.emit` is statically typed against `BurdenoffEventName`\n * which doesn't list our workspaces-domain names. The runtime bus is dynamic,\n * so the cast loses autocomplete but is sound.\n */\nimport { useCallback } from 'react';\n\nimport { useEventBus } from '@burdenoff/fe-libs/shared/events';\n\nexport type WorkspacesDomainEvent =\n // Lifecycle (success)\n | 'workspace.created'\n | 'workspace.updated'\n | 'workspace.deleted'\n | 'workspace.archived'\n | 'workspace.reactivated'\n | 'project.created'\n | 'project.updated'\n | 'project.deleted'\n | 'project.archived'\n | 'project.unarchived'\n | 'workspace-member.added'\n | 'workspace-member.removed'\n | 'workspace-member.role-updated'\n | 'workspace-invitation.created'\n | 'workspace-invitation.updated'\n | 'workspace-invitation.accepted'\n | 'workspace-invitation.rejected'\n | 'workspace-invitation.cancelled'\n | 'workspace-invitation.resent'\n | 'workspace-invitation.deleted'\n | 'workspace-activity.appended'\n // Failure / observability — forwarded to OtelBrowserSink + audit sink\n | 'workspace.create_failed'\n | 'workspace.update_failed'\n | 'workspace.delete_failed'\n | 'workspace.archive_failed'\n | 'workspace.reactivate_failed'\n | 'project.create_failed'\n | 'project.update_failed'\n | 'project.delete_failed'\n | 'project.archive_failed'\n | 'project.unarchive_failed'\n | 'workspace-member.add_failed'\n | 'workspace-member.remove_failed'\n | 'workspace-member.role-update_failed'\n | 'workspace-invitation.create_failed'\n | 'workspace-invitation.update_failed'\n | 'workspace-invitation.accept_failed'\n | 'workspace-invitation.reject_failed'\n | 'workspace-invitation.cancel_failed'\n | 'workspace-invitation.resend_failed'\n | 'workspace-invitation.delete_failed'\n // Module-scoped (plural) — describes a navigation event into the module,\n // not an action on a single resource.\n | 'workspaces.page.viewed';\n\nexport interface WorkspacesEventPayload {\n workspaceId?: string;\n projectId?: string;\n memberId?: string;\n invitationId?: string;\n userId?: string;\n email?: string;\n source?: string;\n // Observability fields (no PII per SRE guide §7)\n page?: string;\n durationMs?: number;\n errorCode?: string;\n errorMessage?: string;\n}\n\nexport function useWorkspacesEventEmitter(): {\n emit: (event: WorkspacesDomainEvent, payload?: WorkspacesEventPayload) => void;\n} {\n const bus = useEventBus();\n // Memoize the emit callback so consumers (notably `useWorkspacesPageView`)\n // can put it in effect dep arrays without firing on every render.\n const emit = useCallback(\n (event: WorkspacesDomainEvent, payload: WorkspacesEventPayload = {}) => {\n try {\n type DynamicEmit = (e: string, p: unknown) => void;\n (bus as unknown as { emit: DynamicEmit }).emit(event, payload);\n } catch (err) {\n // Bus failures must not break workspace operations — but in dev we\n // surface the error so a wrong event shape doesn't disappear silently.\n if (import.meta.env?.DEV) {\n // eslint-disable-next-line no-console\n console.warn('[useWorkspacesEventEmitter] event bus emit failed', {\n event,\n payload,\n err,\n });\n }\n }\n },\n [bus]\n );\n return { emit };\n}\n"],"mappings":";;;AA6EA,SAAgB,IAEd;CACA,IAAM,IAAM,GAAa;AAuBzB,QAAO,EAAE,MApBI,GACV,GAA8B,IAAkC,EAAE,KAAK;AACtE,MAAI;AAED,KAAyC,KAAK,GAAO,EAAQ;UAClD;IAahB,CAAC,EAAI,CACN,EACc"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
interface PageViewExtra {
|
|
2
|
+
/**
|
|
3
|
+
* Workspace context for the page. `undefined` / `null` / `''` are all
|
|
4
|
+
* treated as "unresolved" when `requireParams` is true so that
|
|
5
|
+
* `useParams()`'s `string | undefined` initial render doesn't fire
|
|
6
|
+
* a phantom event with missing context.
|
|
7
|
+
*/
|
|
8
|
+
workspaceId?: string | null;
|
|
9
|
+
projectId?: string | null;
|
|
10
|
+
/**
|
|
11
|
+
* Set to `true` on routes that include `:workspaceId` / `:projectId`
|
|
12
|
+
* in the path. The hook then skips the emit until **every value
|
|
13
|
+
* supplied in `extra`** resolves to a non-empty string. Anything you
|
|
14
|
+
* don't pass to `extra` is treated as "not applicable to this page"
|
|
15
|
+
* — the hook ignores it.
|
|
16
|
+
*/
|
|
17
|
+
requireParams?: boolean;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Emit a `workspaces.page.viewed` event when a top-level workspaces page mounts
|
|
21
|
+
* (and again when its `page` / `workspaceId` / `projectId` context changes).
|
|
22
|
+
* The event is forwarded by the shell's bus to OtelBrowserSink / RybbitSink /
|
|
23
|
+
* BackendAuditSink — the MFE never sinks directly.
|
|
24
|
+
*/
|
|
25
|
+
export declare function useWorkspacesPageView(page: string, extra?: PageViewExtra): void;
|
|
26
|
+
export {};
|
|
27
|
+
//# sourceMappingURL=useWorkspacesPageView.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useWorkspacesPageView.d.ts","sourceRoot":"","sources":["../../src/hooks/useWorkspacesPageView.ts"],"names":[],"mappings":"AAIA,UAAU,aAAa;IACrB;;;;;OAKG;IACH,WAAW,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAC5B,SAAS,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAC1B;;;;;;OAMG;IACH,aAAa,CAAC,EAAE,OAAO,CAAC;CACzB;AAKD;;;;;GAKG;AACH,wBAAgB,qBAAqB,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,aAAa,GAAG,IAAI,CAgD/E"}
|