@lukoweb/apitogo-module-user-panel 0.2.83 → 0.2.85

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lukoweb/apitogo-module-user-panel",
3
- "version": "0.2.83",
3
+ "version": "0.2.85",
4
4
  "type": "module",
5
5
  "exports": {
6
6
  ".": "./src/index.tsx"
@@ -14,7 +14,7 @@
14
14
  "devDependencies": {
15
15
  "@types/react": "19.2.14",
16
16
  "@types/react-dom": "19.2.3",
17
- "@lukoweb/apitogo": "0.2.83",
17
+ "@lukoweb/apitogo": "0.2.85",
18
18
  "react": "19.2.4",
19
19
  "react-dom": "19.2.4",
20
20
  "react-router": "7.13.1",
@@ -7,6 +7,7 @@ import {
7
7
  import {
8
8
  changeAccountPassword,
9
9
  deleteAccount,
10
+ downloadAccountData,
10
11
  fetchAccountMe,
11
12
  resolveDevPortalApiBaseUrl,
12
13
  updateAccountProfile,
@@ -91,3 +92,20 @@ export function useDeleteAccount() {
91
92
  },
92
93
  });
93
94
  }
95
+
96
+ export function useDownloadAccountData() {
97
+ const auth = useAuth();
98
+ const apiBaseUrl = resolveDevPortalApiBaseUrl(
99
+ auth.providerData as { type: "dev-portal"; apiBaseUrl: string } | null,
100
+ );
101
+
102
+ return useMutation({
103
+ mutationFn: () => {
104
+ if (!apiBaseUrl) {
105
+ throw new Error("Dev portal API is not configured.");
106
+ }
107
+
108
+ return downloadAccountData(apiBaseUrl);
109
+ },
110
+ });
111
+ }
@@ -15,6 +15,7 @@ import {
15
15
  useAccountMe,
16
16
  useChangeAccountPassword,
17
17
  useDeleteAccount,
18
+ useDownloadAccountData,
18
19
  useUpdateAccountProfile,
19
20
  } from "../hooks/useAccountSettings.js";
20
21
 
@@ -28,6 +29,7 @@ export const SettingsPage = ({ content }: SettingsPageProps) => {
28
29
  const updateProfile = useUpdateAccountProfile();
29
30
  const changePassword = useChangeAccountPassword();
30
31
  const deleteAccountMutation = useDeleteAccount();
32
+ const downloadData = useDownloadAccountData();
31
33
 
32
34
  const [displayName, setDisplayName] = useState("");
33
35
  const [currentPassword, setCurrentPassword] = useState("");
@@ -199,6 +201,32 @@ export const SettingsPage = ({ content }: SettingsPageProps) => {
199
201
  </Card>
200
202
  ) : null}
201
203
 
204
+ <Card>
205
+ <CardHeader>
206
+ <CardTitle>Your data</CardTitle>
207
+ </CardHeader>
208
+ <CardContent className="space-y-4">
209
+ <p className="text-sm text-muted-foreground">
210
+ Download a copy of the personal data this portal stores about you:
211
+ your profile, sign-in methods, plans and API access.
212
+ </p>
213
+ {downloadData.isError ? (
214
+ <p className="text-sm text-destructive">
215
+ {downloadData.error instanceof Error
216
+ ? downloadData.error.message
217
+ : "Unable to download your data."}
218
+ </p>
219
+ ) : null}
220
+ <Button
221
+ variant="outline"
222
+ disabled={downloadData.isPending}
223
+ onClick={() => downloadData.mutate()}
224
+ >
225
+ Download my data
226
+ </Button>
227
+ </CardContent>
228
+ </Card>
229
+
202
230
  <Card className="border-destructive/40">
203
231
  <CardHeader>
204
232
  <CardTitle className="text-destructive">Danger zone</CardTitle>
@@ -123,3 +123,30 @@ export async function deleteAccount(
123
123
  );
124
124
  }
125
125
  }
126
+
127
+ /** Downloads everything the dev portal stores about the signed-in user as a JSON file (GDPR access request). */
128
+ export async function downloadAccountData(apiBaseUrl: string): Promise<void> {
129
+ const response = await fetch(`${apiBaseUrl}/api/v1/account/export`, {
130
+ method: "GET",
131
+ headers: { Accept: "application/json" },
132
+ credentials: "include",
133
+ });
134
+
135
+ if (!response.ok) {
136
+ throw new Error(
137
+ await readErrorMessage(response, "Unable to download your data."),
138
+ );
139
+ }
140
+
141
+ const blob = new Blob([JSON.stringify(await response.json(), null, 2)], {
142
+ type: "application/json",
143
+ });
144
+ const url = URL.createObjectURL(blob);
145
+ const link = document.createElement("a");
146
+ link.href = url;
147
+ link.download = "account-data.json";
148
+ document.body.appendChild(link);
149
+ link.click();
150
+ link.remove();
151
+ URL.revokeObjectURL(url);
152
+ }