@pol-studios/db 1.0.19 → 1.0.21
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/DataLayerContext-ZmLPYR_s.d.ts +825 -0
- package/dist/EntityPermissions-DwFt4tUd.d.ts +35 -0
- package/dist/FilterConfig-Bt2Ek74z.d.ts +99 -0
- package/dist/UserMetadataContext-B8gVWGMl.d.ts +35 -0
- package/dist/UserMetadataContext-DntmpK41.d.ts +33 -0
- package/dist/auth/context.d.ts +48 -0
- package/dist/auth/guards.d.ts +180 -0
- package/dist/auth/hooks.d.ts +312 -0
- package/dist/auth/index.d.ts +11 -0
- package/dist/client/index.d.ts +16 -0
- package/dist/core/index.d.ts +539 -0
- package/dist/database.types-ChFCG-4M.d.ts +8604 -0
- package/dist/executor-CB4KHyYG.d.ts +507 -0
- package/dist/gen/index.d.ts +1099 -0
- package/dist/hooks/index.d.ts +100 -0
- package/dist/index-BNKhgDdC.d.ts +433 -0
- package/dist/index.d.ts +33 -0
- package/dist/index.native.d.ts +793 -0
- package/dist/index.web.d.ts +321 -0
- package/dist/mutation/index.d.ts +58 -0
- package/dist/parser/index.d.ts +366 -0
- package/dist/powersync-bridge/index.d.ts +284 -0
- package/dist/query/index.d.ts +723 -0
- package/dist/realtime/index.d.ts +44 -0
- package/dist/select-query-parser-BwyHum1L.d.ts +352 -0
- package/dist/setupAuthContext-Kv-THH-h.d.ts +61 -0
- package/dist/types/index.d.ts +10 -0
- package/dist/types-CYr9JiUE.d.ts +62 -0
- package/dist/useBatchUpsert-9OYjibLh.d.ts +24 -0
- package/dist/useDbCount-Id14x_1P.d.ts +1082 -0
- package/dist/useDbQuery-C-TL8jY1.d.ts +19 -0
- package/dist/useReceiptAI-6HkRpRml.d.ts +58 -0
- package/dist/useResolveFeedback-Ca2rh_Bs.d.ts +997 -0
- package/dist/useSupabase-DvWVuHHE.d.ts +28 -0
- package/dist/with-auth/index.d.ts +704 -0
- package/package.json +61 -13
|
@@ -0,0 +1,704 @@
|
|
|
1
|
+
import { u as useSupabase } from '../useSupabase-DvWVuHHE.js';
|
|
2
|
+
import { P as ProfileStatus } from '../setupAuthContext-Kv-THH-h.js';
|
|
3
|
+
import * as _tanstack_react_query from '@tanstack/react-query';
|
|
4
|
+
import { useMutation, useQuery } from '@tanstack/react-query';
|
|
5
|
+
export { e as UserMetadataContextProvider, c as UserMetadataContextType, a as UserMetadataInsert, U as UserMetadataRow, b as UserMetadataUpdate, u as useLiveChangesIndicator, h as useSetUserMetadata, i as useUserMetadataState, g as useUserMetadataValue, d as userMetadataContext } from '../UserMetadataContext-B8gVWGMl.js';
|
|
6
|
+
import { UseQuerySingleReturn } from '@supabase-cache-helpers/postgrest-react-query';
|
|
7
|
+
import { T as Tables } from '../database.types-ChFCG-4M.js';
|
|
8
|
+
import 'react/jsx-runtime';
|
|
9
|
+
import '@supabase/supabase-js/dist/module/lib/types.js';
|
|
10
|
+
import 'react';
|
|
11
|
+
import '@supabase/supabase-js';
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Consent types supported by the system
|
|
15
|
+
*/
|
|
16
|
+
type ConsentType = "terms_of_service" | "privacy_policy" | "marketing" | "data_processing" | "cookies" | string;
|
|
17
|
+
/**
|
|
18
|
+
* A single consent record from the database
|
|
19
|
+
*/
|
|
20
|
+
interface ConsentRecord {
|
|
21
|
+
id: number;
|
|
22
|
+
userId: string;
|
|
23
|
+
consentType: ConsentType;
|
|
24
|
+
consentVersion: string;
|
|
25
|
+
consentGiven: boolean;
|
|
26
|
+
consentText: string | null;
|
|
27
|
+
ipAddress: string | null;
|
|
28
|
+
userAgent: string | null;
|
|
29
|
+
createdAt: string;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Summary of a user's consent status for each type
|
|
33
|
+
*/
|
|
34
|
+
interface ConsentSummary {
|
|
35
|
+
consentType: ConsentType;
|
|
36
|
+
consentGiven: boolean;
|
|
37
|
+
consentVersion: string;
|
|
38
|
+
consentedAt: string;
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Options for recording consent
|
|
42
|
+
*/
|
|
43
|
+
interface RecordConsentOptions {
|
|
44
|
+
/** Optional snapshot of the consent text shown to the user */
|
|
45
|
+
consentText?: string;
|
|
46
|
+
/** Optional IP address (usually captured server-side) */
|
|
47
|
+
ipAddress?: string;
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Return type for the useConsent hook
|
|
51
|
+
*/
|
|
52
|
+
interface UseConsentReturn {
|
|
53
|
+
/**
|
|
54
|
+
* Records a consent decision for a specific type and version
|
|
55
|
+
* @param type - The type of consent (e.g., 'terms_of_service', 'privacy_policy')
|
|
56
|
+
* @param version - The version of the document being consented to
|
|
57
|
+
* @param given - Whether consent is being given (true) or withdrawn (false)
|
|
58
|
+
* @param options - Optional additional data (consent text snapshot, IP address)
|
|
59
|
+
* @returns Promise resolving to the created consent record or null on error
|
|
60
|
+
*/
|
|
61
|
+
recordConsent: (type: ConsentType, version: string, given: boolean, options?: RecordConsentOptions) => Promise<ConsentRecord | null>;
|
|
62
|
+
/**
|
|
63
|
+
* Fetches all consent records for the current user
|
|
64
|
+
* @returns Array of consent records
|
|
65
|
+
*/
|
|
66
|
+
consents: ConsentRecord[];
|
|
67
|
+
/**
|
|
68
|
+
* Gets the latest consent status for each consent type
|
|
69
|
+
* @returns Array of consent summaries
|
|
70
|
+
*/
|
|
71
|
+
consentSummary: ConsentSummary[];
|
|
72
|
+
/**
|
|
73
|
+
* Records consent withdrawal for a specific type
|
|
74
|
+
* Creates a new consent record with consentGiven: false
|
|
75
|
+
* @param type - The type of consent to withdraw
|
|
76
|
+
* @param version - The version of the current document
|
|
77
|
+
* @returns Promise resolving to the created withdrawal record or null on error
|
|
78
|
+
*/
|
|
79
|
+
withdrawConsent: (type: ConsentType, version: string) => Promise<ConsentRecord | null>;
|
|
80
|
+
/**
|
|
81
|
+
* Checks if the user has active (non-withdrawn) consent for a type
|
|
82
|
+
* @param type - The consent type to check
|
|
83
|
+
* @returns boolean indicating if consent is currently active
|
|
84
|
+
*/
|
|
85
|
+
hasActiveConsent: (type: ConsentType) => boolean;
|
|
86
|
+
/**
|
|
87
|
+
* Gets the latest consent record for a specific type
|
|
88
|
+
* @param type - The consent type to look up
|
|
89
|
+
* @returns The latest consent record or undefined if none exists
|
|
90
|
+
*/
|
|
91
|
+
getLatestConsent: (type: ConsentType) => ConsentRecord | undefined;
|
|
92
|
+
/**
|
|
93
|
+
* Whether consent data is currently being loaded
|
|
94
|
+
*/
|
|
95
|
+
isLoading: boolean;
|
|
96
|
+
/**
|
|
97
|
+
* Any error that occurred while loading consents
|
|
98
|
+
*/
|
|
99
|
+
error: Error | null;
|
|
100
|
+
/**
|
|
101
|
+
* Refetch consent data from the server
|
|
102
|
+
*/
|
|
103
|
+
refetch: () => void;
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* Hook for managing GDPR-compliant consent records
|
|
107
|
+
*
|
|
108
|
+
* Provides functionality to:
|
|
109
|
+
* - Record new consent decisions
|
|
110
|
+
* - Fetch user's consent history
|
|
111
|
+
* - Withdraw consent
|
|
112
|
+
* - Check consent status
|
|
113
|
+
*
|
|
114
|
+
* @example
|
|
115
|
+
* ```tsx
|
|
116
|
+
* function ConsentManager() {
|
|
117
|
+
* const {
|
|
118
|
+
* recordConsent,
|
|
119
|
+
* withdrawConsent,
|
|
120
|
+
* hasActiveConsent,
|
|
121
|
+
* consentSummary,
|
|
122
|
+
* isLoading
|
|
123
|
+
* } = useConsent();
|
|
124
|
+
*
|
|
125
|
+
* const handleAcceptTerms = async () => {
|
|
126
|
+
* await recordConsent('terms_of_service', 'v1.0', true, {
|
|
127
|
+
* consentText: 'I agree to the Terms of Service...'
|
|
128
|
+
* });
|
|
129
|
+
* };
|
|
130
|
+
*
|
|
131
|
+
* const handleWithdrawMarketing = async () => {
|
|
132
|
+
* await withdrawConsent('marketing', 'v1.0');
|
|
133
|
+
* };
|
|
134
|
+
*
|
|
135
|
+
* if (isLoading) return <Spinner />;
|
|
136
|
+
*
|
|
137
|
+
* return (
|
|
138
|
+
* <div>
|
|
139
|
+
* {consentSummary.map(consent => (
|
|
140
|
+
* <div key={consent.consentType}>
|
|
141
|
+
* {consent.consentType}: {consent.consentGiven ? 'Accepted' : 'Declined'}
|
|
142
|
+
* </div>
|
|
143
|
+
* ))}
|
|
144
|
+
* </div>
|
|
145
|
+
* );
|
|
146
|
+
* }
|
|
147
|
+
* ```
|
|
148
|
+
*/
|
|
149
|
+
declare function useConsent(): UseConsentReturn;
|
|
150
|
+
/**
|
|
151
|
+
* Standalone function to record consent during registration
|
|
152
|
+
* Use this when the useConsent hook is not available (e.g., during sign-up flow)
|
|
153
|
+
*
|
|
154
|
+
* @param supabase - Supabase client instance
|
|
155
|
+
* @param userId - The user's ID
|
|
156
|
+
* @param type - Consent type
|
|
157
|
+
* @param version - Document version
|
|
158
|
+
* @param given - Whether consent is given
|
|
159
|
+
* @param options - Optional additional data
|
|
160
|
+
* @returns Promise resolving to the created record or null on error
|
|
161
|
+
*
|
|
162
|
+
* @example
|
|
163
|
+
* ```tsx
|
|
164
|
+
* // In registration handler
|
|
165
|
+
* const response = await supabase.auth.signUp({ email, password });
|
|
166
|
+
* if (response.data.user) {
|
|
167
|
+
* await recordConsentForUser(
|
|
168
|
+
* supabase,
|
|
169
|
+
* response.data.user.id,
|
|
170
|
+
* 'terms_of_service',
|
|
171
|
+
* 'v1.0',
|
|
172
|
+
* true,
|
|
173
|
+
* { consentText: 'I agree to the Terms of Service...' }
|
|
174
|
+
* );
|
|
175
|
+
* }
|
|
176
|
+
* ```
|
|
177
|
+
*/
|
|
178
|
+
declare function recordConsentForUser(supabase: ReturnType<typeof useSupabase>, userId: string, type: ConsentType, version: string, given: boolean, options?: RecordConsentOptions): Promise<ConsentRecord | null>;
|
|
179
|
+
|
|
180
|
+
/**
|
|
181
|
+
* Deletion request status
|
|
182
|
+
*/
|
|
183
|
+
type DeletionStatus = "pending" | "cancelled" | "completed";
|
|
184
|
+
/**
|
|
185
|
+
* Account deletion request details
|
|
186
|
+
*/
|
|
187
|
+
interface DeletionRequest {
|
|
188
|
+
id: number;
|
|
189
|
+
status: DeletionStatus;
|
|
190
|
+
requestedAt: string;
|
|
191
|
+
scheduledDeletionAt: string;
|
|
192
|
+
completedAt: string | null;
|
|
193
|
+
cancelledAt: string | null;
|
|
194
|
+
reason: string | null;
|
|
195
|
+
daysRemaining: number | null;
|
|
196
|
+
}
|
|
197
|
+
/**
|
|
198
|
+
* Response from get_deletion_status RPC
|
|
199
|
+
*/
|
|
200
|
+
interface DeletionStatusResponse {
|
|
201
|
+
hasRequest: boolean;
|
|
202
|
+
request: DeletionRequest | null;
|
|
203
|
+
}
|
|
204
|
+
/**
|
|
205
|
+
* Response from request_account_deletion RPC
|
|
206
|
+
*/
|
|
207
|
+
interface RequestDeletionResponse {
|
|
208
|
+
success: boolean;
|
|
209
|
+
error?: string;
|
|
210
|
+
requestId?: number;
|
|
211
|
+
requestedAt?: string;
|
|
212
|
+
scheduledDeletionAt?: string;
|
|
213
|
+
gracePeriodDays?: number;
|
|
214
|
+
message?: string;
|
|
215
|
+
existingRequest?: {
|
|
216
|
+
id: number;
|
|
217
|
+
requestedAt: string;
|
|
218
|
+
scheduledDeletionAt: string;
|
|
219
|
+
status: DeletionStatus;
|
|
220
|
+
};
|
|
221
|
+
}
|
|
222
|
+
/**
|
|
223
|
+
* Response from cancel_account_deletion RPC
|
|
224
|
+
*/
|
|
225
|
+
interface CancelDeletionResponse {
|
|
226
|
+
success: boolean;
|
|
227
|
+
error?: string;
|
|
228
|
+
requestId?: number;
|
|
229
|
+
cancelledAt?: string;
|
|
230
|
+
message?: string;
|
|
231
|
+
}
|
|
232
|
+
/**
|
|
233
|
+
* Hook for managing GDPR-compliant account deletion
|
|
234
|
+
*
|
|
235
|
+
* Provides functionality to:
|
|
236
|
+
* - Request account deletion (with 30-day grace period)
|
|
237
|
+
* - Cancel a pending deletion request
|
|
238
|
+
* - Check current deletion status
|
|
239
|
+
*
|
|
240
|
+
* @example
|
|
241
|
+
* ```tsx
|
|
242
|
+
* function AccountSettings() {
|
|
243
|
+
* const {
|
|
244
|
+
* deletionStatus,
|
|
245
|
+
* isLoading,
|
|
246
|
+
* isPendingDeletion,
|
|
247
|
+
* daysRemaining,
|
|
248
|
+
* requestDeletion,
|
|
249
|
+
* cancelDeletion,
|
|
250
|
+
* isRequesting,
|
|
251
|
+
* isCancelling
|
|
252
|
+
* } = useAccountDeletion();
|
|
253
|
+
*
|
|
254
|
+
* if (isLoading) return <Spinner />;
|
|
255
|
+
*
|
|
256
|
+
* if (isPendingDeletion) {
|
|
257
|
+
* return (
|
|
258
|
+
* <div>
|
|
259
|
+
* <p>Your account is scheduled for deletion in {daysRemaining} days</p>
|
|
260
|
+
* <button onClick={() => cancelDeletion()}>Cancel Deletion</button>
|
|
261
|
+
* </div>
|
|
262
|
+
* );
|
|
263
|
+
* }
|
|
264
|
+
*
|
|
265
|
+
* return (
|
|
266
|
+
* <button onClick={() => requestDeletion("No longer using the service")}>
|
|
267
|
+
* Delete My Account
|
|
268
|
+
* </button>
|
|
269
|
+
* );
|
|
270
|
+
* }
|
|
271
|
+
* ```
|
|
272
|
+
*/
|
|
273
|
+
declare function useAccountDeletion(): {
|
|
274
|
+
requestDeletion: (reason?: string) => Promise<RequestDeletionResponse>;
|
|
275
|
+
cancelDeletion: () => Promise<CancelDeletionResponse>;
|
|
276
|
+
refreshStatus: () => void;
|
|
277
|
+
isRequesting: boolean;
|
|
278
|
+
isCancelling: boolean;
|
|
279
|
+
requestError: Error;
|
|
280
|
+
cancelError: Error;
|
|
281
|
+
requestResult: RequestDeletionResponse;
|
|
282
|
+
cancelResult: CancelDeletionResponse;
|
|
283
|
+
/** Current deletion request (if any) */
|
|
284
|
+
deletionRequest: DeletionRequest;
|
|
285
|
+
/** Whether user has a pending deletion request */
|
|
286
|
+
isPendingDeletion: boolean;
|
|
287
|
+
/** Whether user has a cancelled deletion request */
|
|
288
|
+
isCancelledDeletion: boolean;
|
|
289
|
+
/** Whether user has a completed deletion (account anonymized) */
|
|
290
|
+
isCompletedDeletion: boolean;
|
|
291
|
+
/** Days remaining until deletion (null if not pending) */
|
|
292
|
+
daysRemaining: number;
|
|
293
|
+
/** Scheduled deletion date (null if not pending) */
|
|
294
|
+
scheduledDeletionAt: Date;
|
|
295
|
+
/** Original request date */
|
|
296
|
+
requestedAt: Date;
|
|
297
|
+
/** Date when request was cancelled */
|
|
298
|
+
cancelledAt: Date;
|
|
299
|
+
/** Reason provided for deletion */
|
|
300
|
+
reason: string;
|
|
301
|
+
deletionStatus: DeletionStatusResponse;
|
|
302
|
+
isLoading: boolean;
|
|
303
|
+
isError: boolean;
|
|
304
|
+
error: Error;
|
|
305
|
+
};
|
|
306
|
+
/**
|
|
307
|
+
* Type exports for consumers
|
|
308
|
+
*/
|
|
309
|
+
type UseAccountDeletionReturn = ReturnType<typeof useAccountDeletion>;
|
|
310
|
+
|
|
311
|
+
/**
|
|
312
|
+
* User status information from get_user_status RPC
|
|
313
|
+
*/
|
|
314
|
+
interface UserStatusInfo {
|
|
315
|
+
exists: boolean;
|
|
316
|
+
userId?: string;
|
|
317
|
+
status?: ProfileStatus;
|
|
318
|
+
archivedAt?: string | null;
|
|
319
|
+
archivedBy?: string | null;
|
|
320
|
+
isActive?: boolean;
|
|
321
|
+
}
|
|
322
|
+
/**
|
|
323
|
+
* Response from archive_user RPC
|
|
324
|
+
*/
|
|
325
|
+
interface ArchiveUserResponse {
|
|
326
|
+
success: boolean;
|
|
327
|
+
error?: string;
|
|
328
|
+
userId?: string;
|
|
329
|
+
archivedAt?: string;
|
|
330
|
+
archivedBy?: string;
|
|
331
|
+
message?: string;
|
|
332
|
+
}
|
|
333
|
+
/**
|
|
334
|
+
* Response from unarchive_user RPC
|
|
335
|
+
*/
|
|
336
|
+
interface UnarchiveUserResponse {
|
|
337
|
+
success: boolean;
|
|
338
|
+
error?: string;
|
|
339
|
+
userId?: string;
|
|
340
|
+
restoredAt?: string;
|
|
341
|
+
restoredBy?: string;
|
|
342
|
+
message?: string;
|
|
343
|
+
}
|
|
344
|
+
/**
|
|
345
|
+
* Hook for managing user profile status (archival)
|
|
346
|
+
*
|
|
347
|
+
* Provides functionality to:
|
|
348
|
+
* - Check a user's current status
|
|
349
|
+
* - Archive a user (admin only)
|
|
350
|
+
* - Unarchive/restore a user (admin only)
|
|
351
|
+
*
|
|
352
|
+
* @param targetUserId - Optional user ID to check. Defaults to current user.
|
|
353
|
+
*
|
|
354
|
+
* @example
|
|
355
|
+
* ```tsx
|
|
356
|
+
* // Check current user's status
|
|
357
|
+
* function MyProfile() {
|
|
358
|
+
* const { status, isArchived } = useUserStatus();
|
|
359
|
+
*
|
|
360
|
+
* if (isArchived) {
|
|
361
|
+
* return <p>Your account has been archived</p>;
|
|
362
|
+
* }
|
|
363
|
+
*
|
|
364
|
+
* return <p>Your account is active</p>;
|
|
365
|
+
* }
|
|
366
|
+
*
|
|
367
|
+
* // Admin managing another user
|
|
368
|
+
* function UserManagement({ userId }: { userId: string }) {
|
|
369
|
+
* const {
|
|
370
|
+
* status,
|
|
371
|
+
* isArchived,
|
|
372
|
+
* archiveUser,
|
|
373
|
+
* unarchiveUser,
|
|
374
|
+
* isArchiving,
|
|
375
|
+
* isUnarchiving
|
|
376
|
+
* } = useUserStatus(userId);
|
|
377
|
+
*
|
|
378
|
+
* return (
|
|
379
|
+
* <div>
|
|
380
|
+
* <p>Status: {status}</p>
|
|
381
|
+
* {isArchived ? (
|
|
382
|
+
* <button onClick={() => unarchiveUser(userId)} disabled={isUnarchiving}>
|
|
383
|
+
* Restore Access
|
|
384
|
+
* </button>
|
|
385
|
+
* ) : (
|
|
386
|
+
* <button onClick={() => archiveUser(userId)} disabled={isArchiving}>
|
|
387
|
+
* Archive User
|
|
388
|
+
* </button>
|
|
389
|
+
* )}
|
|
390
|
+
* </div>
|
|
391
|
+
* );
|
|
392
|
+
* }
|
|
393
|
+
* ```
|
|
394
|
+
*/
|
|
395
|
+
declare function useUserStatus(targetUserId?: string): {
|
|
396
|
+
archiveUser: (userId: string, reason?: string) => Promise<ArchiveUserResponse>;
|
|
397
|
+
unarchiveUser: (userId: string) => Promise<UnarchiveUserResponse>;
|
|
398
|
+
refreshStatus: () => void;
|
|
399
|
+
invalidateUserStatus: (userIdToInvalidate: string) => void;
|
|
400
|
+
isArchiving: boolean;
|
|
401
|
+
isUnarchiving: boolean;
|
|
402
|
+
archiveError: Error;
|
|
403
|
+
unarchiveError: Error;
|
|
404
|
+
archiveResult: ArchiveUserResponse;
|
|
405
|
+
unarchiveResult: UnarchiveUserResponse;
|
|
406
|
+
/** User exists in system */
|
|
407
|
+
exists: boolean;
|
|
408
|
+
/** Current profile status */
|
|
409
|
+
status: ProfileStatus | undefined;
|
|
410
|
+
/** Whether user profile is active */
|
|
411
|
+
isActive: boolean;
|
|
412
|
+
/** Whether user profile is archived */
|
|
413
|
+
isArchived: boolean;
|
|
414
|
+
/** Whether user profile is suspended */
|
|
415
|
+
isSuspended: boolean;
|
|
416
|
+
/** Timestamp when user was archived */
|
|
417
|
+
archivedAt: Date;
|
|
418
|
+
/** ID of admin who archived the user */
|
|
419
|
+
archivedBy: string;
|
|
420
|
+
statusData: UserStatusInfo;
|
|
421
|
+
isLoading: boolean;
|
|
422
|
+
isError: boolean;
|
|
423
|
+
error: Error;
|
|
424
|
+
};
|
|
425
|
+
/**
|
|
426
|
+
* Type exports for consumers
|
|
427
|
+
*/
|
|
428
|
+
type UseUserStatusReturn = ReturnType<typeof useUserStatus>;
|
|
429
|
+
|
|
430
|
+
/**
|
|
431
|
+
* GDPR Article 20 compliant personal data export metadata
|
|
432
|
+
*/
|
|
433
|
+
interface DataExportMetadata {
|
|
434
|
+
exportId: string;
|
|
435
|
+
exportedAt: string;
|
|
436
|
+
userId: string;
|
|
437
|
+
gdprArticle: string;
|
|
438
|
+
format: string;
|
|
439
|
+
version: string;
|
|
440
|
+
}
|
|
441
|
+
/**
|
|
442
|
+
* Profile data structure in export
|
|
443
|
+
*/
|
|
444
|
+
interface ExportedProfile {
|
|
445
|
+
id: string;
|
|
446
|
+
email: string;
|
|
447
|
+
firstName: string;
|
|
448
|
+
middleName: string;
|
|
449
|
+
lastName: string;
|
|
450
|
+
fullName: string;
|
|
451
|
+
phone: string;
|
|
452
|
+
profilePath: string | null;
|
|
453
|
+
metadata: Record<string, unknown> | null;
|
|
454
|
+
}
|
|
455
|
+
/**
|
|
456
|
+
* Access permission record
|
|
457
|
+
*/
|
|
458
|
+
interface ExportedAccessPermission {
|
|
459
|
+
accessKey: string;
|
|
460
|
+
source: "direct" | "group";
|
|
461
|
+
}
|
|
462
|
+
/**
|
|
463
|
+
* Group membership record
|
|
464
|
+
*/
|
|
465
|
+
interface ExportedGroupMembership {
|
|
466
|
+
groupId: number;
|
|
467
|
+
groupName: string;
|
|
468
|
+
groupDescription: string | null;
|
|
469
|
+
grantedAt: string;
|
|
470
|
+
grantedBy: string | null;
|
|
471
|
+
expiresAt: string | null;
|
|
472
|
+
}
|
|
473
|
+
/**
|
|
474
|
+
* User metadata key-value pair
|
|
475
|
+
*/
|
|
476
|
+
interface ExportedUserMetadata {
|
|
477
|
+
key: string;
|
|
478
|
+
value: string;
|
|
479
|
+
}
|
|
480
|
+
/**
|
|
481
|
+
* Device/push token information
|
|
482
|
+
*/
|
|
483
|
+
interface ExportedDevice {
|
|
484
|
+
deviceType: string | null;
|
|
485
|
+
deviceOS: string | null;
|
|
486
|
+
deviceOSVersion: string | null;
|
|
487
|
+
deviceModel: string | null;
|
|
488
|
+
platform: string | null;
|
|
489
|
+
appVersion: string | null;
|
|
490
|
+
isActive: boolean;
|
|
491
|
+
createdAt: string;
|
|
492
|
+
lastUsedAt: string | null;
|
|
493
|
+
}
|
|
494
|
+
/**
|
|
495
|
+
* Audit log entry
|
|
496
|
+
*/
|
|
497
|
+
interface ExportedAuditLogEntry {
|
|
498
|
+
schemaName: string;
|
|
499
|
+
tableName: string;
|
|
500
|
+
operation: string;
|
|
501
|
+
changeAt: string;
|
|
502
|
+
recordPrimaryKey: Record<string, unknown>;
|
|
503
|
+
}
|
|
504
|
+
/**
|
|
505
|
+
* Saved query record
|
|
506
|
+
*/
|
|
507
|
+
interface ExportedSavedQuery {
|
|
508
|
+
id: number;
|
|
509
|
+
title: string;
|
|
510
|
+
description: string | null;
|
|
511
|
+
categoryId: string;
|
|
512
|
+
schema: string;
|
|
513
|
+
table: string;
|
|
514
|
+
path: string;
|
|
515
|
+
visibility: string;
|
|
516
|
+
createdAt: string;
|
|
517
|
+
}
|
|
518
|
+
/**
|
|
519
|
+
* Comment record
|
|
520
|
+
*/
|
|
521
|
+
interface ExportedComment {
|
|
522
|
+
id: string;
|
|
523
|
+
message: string;
|
|
524
|
+
createdAt: string;
|
|
525
|
+
commentSectionId: string;
|
|
526
|
+
}
|
|
527
|
+
/**
|
|
528
|
+
* Notification record
|
|
529
|
+
*/
|
|
530
|
+
interface ExportedNotification {
|
|
531
|
+
title: string;
|
|
532
|
+
message: string;
|
|
533
|
+
link: string | null;
|
|
534
|
+
scheduledAt: string | null;
|
|
535
|
+
types: string[];
|
|
536
|
+
}
|
|
537
|
+
/**
|
|
538
|
+
* Recent activity section
|
|
539
|
+
*/
|
|
540
|
+
interface ExportedRecentActivity {
|
|
541
|
+
auditLog: ExportedAuditLogEntry[];
|
|
542
|
+
retentionPeriod: string;
|
|
543
|
+
}
|
|
544
|
+
/**
|
|
545
|
+
* Complete personal data export structure
|
|
546
|
+
* Follows GDPR Article 20 requirements for data portability
|
|
547
|
+
*/
|
|
548
|
+
interface PersonalDataExport {
|
|
549
|
+
exportMetadata: DataExportMetadata;
|
|
550
|
+
profile: ExportedProfile;
|
|
551
|
+
accessPermissions: ExportedAccessPermission[];
|
|
552
|
+
groupMemberships: ExportedGroupMembership[];
|
|
553
|
+
userMetadata: ExportedUserMetadata[];
|
|
554
|
+
devices: ExportedDevice[];
|
|
555
|
+
recentActivity: ExportedRecentActivity;
|
|
556
|
+
savedQueries: ExportedSavedQuery[];
|
|
557
|
+
comments: ExportedComment[];
|
|
558
|
+
notifications: ExportedNotification[];
|
|
559
|
+
}
|
|
560
|
+
/**
|
|
561
|
+
* Export request history record
|
|
562
|
+
*/
|
|
563
|
+
interface DataExportHistoryRecord {
|
|
564
|
+
id: string;
|
|
565
|
+
requestedAt: string;
|
|
566
|
+
completedAt: string | null;
|
|
567
|
+
status: "pending" | "processing" | "completed" | "failed";
|
|
568
|
+
downloadCount: number;
|
|
569
|
+
lastDownloadedAt: string | null;
|
|
570
|
+
expiresAt: string | null;
|
|
571
|
+
}
|
|
572
|
+
/**
|
|
573
|
+
* Hook return type
|
|
574
|
+
*/
|
|
575
|
+
interface UseDataExportReturn {
|
|
576
|
+
/** Trigger a personal data export */
|
|
577
|
+
exportMyData: () => Promise<PersonalDataExport>;
|
|
578
|
+
/** Export mutation state */
|
|
579
|
+
exportMutation: ReturnType<typeof useMutation<PersonalDataExport, Error, void>>;
|
|
580
|
+
/** Download data as JSON file */
|
|
581
|
+
downloadAsJson: (data: PersonalDataExport, filename?: string) => void;
|
|
582
|
+
/** Export history query */
|
|
583
|
+
historyQuery: ReturnType<typeof useQuery<DataExportHistoryRecord[], Error>>;
|
|
584
|
+
/** Get export history */
|
|
585
|
+
getExportHistory: () => DataExportHistoryRecord[];
|
|
586
|
+
/** Refresh export history */
|
|
587
|
+
refreshHistory: () => void;
|
|
588
|
+
/** Loading state for export */
|
|
589
|
+
isExporting: boolean;
|
|
590
|
+
/** Loading state for history */
|
|
591
|
+
isLoadingHistory: boolean;
|
|
592
|
+
}
|
|
593
|
+
/**
|
|
594
|
+
* Hook for GDPR Article 20 compliant personal data export
|
|
595
|
+
*
|
|
596
|
+
* @example
|
|
597
|
+
* ```tsx
|
|
598
|
+
* function DataExportButton() {
|
|
599
|
+
* const { exportMyData, downloadAsJson, isExporting } = useDataExport();
|
|
600
|
+
*
|
|
601
|
+
* const handleExport = async () => {
|
|
602
|
+
* const data = await exportMyData();
|
|
603
|
+
* downloadAsJson(data);
|
|
604
|
+
* };
|
|
605
|
+
*
|
|
606
|
+
* return (
|
|
607
|
+
* <button onClick={handleExport} disabled={isExporting}>
|
|
608
|
+
* {isExporting ? 'Preparing...' : 'Download My Data'}
|
|
609
|
+
* </button>
|
|
610
|
+
* );
|
|
611
|
+
* }
|
|
612
|
+
* ```
|
|
613
|
+
*/
|
|
614
|
+
declare function useDataExport(): UseDataExportReturn;
|
|
615
|
+
|
|
616
|
+
type TaskRequest = {
|
|
617
|
+
handlerId: string;
|
|
618
|
+
title: string;
|
|
619
|
+
description: string;
|
|
620
|
+
body?: any;
|
|
621
|
+
};
|
|
622
|
+
declare function useBackgroundTask(): {
|
|
623
|
+
startTask: (request: TaskRequest) => Promise<void>;
|
|
624
|
+
retryTask: (taskId: number) => Promise<any>;
|
|
625
|
+
cancelTask: (taskId: number) => Promise<void>;
|
|
626
|
+
};
|
|
627
|
+
|
|
628
|
+
declare function useUserMetadata(key: string): [
|
|
629
|
+
UseQuerySingleReturn<Tables<"UserMetadata"> | null>,
|
|
630
|
+
(value: string) => Promise<any>
|
|
631
|
+
];
|
|
632
|
+
|
|
633
|
+
/**
|
|
634
|
+
* Metadata to store in storage.objects.metadata
|
|
635
|
+
*/
|
|
636
|
+
interface StorageUploadMetadata {
|
|
637
|
+
processingStatus?: "None" | "Processing" | "Error";
|
|
638
|
+
contentType?: string;
|
|
639
|
+
contentHeight?: number;
|
|
640
|
+
contentWidth?: number;
|
|
641
|
+
originalFileName?: string;
|
|
642
|
+
}
|
|
643
|
+
type UploadInput = {
|
|
644
|
+
/** The file to upload */
|
|
645
|
+
file: File | Blob;
|
|
646
|
+
/** Optional custom filename (defaults to original file name) */
|
|
647
|
+
fileName?: string;
|
|
648
|
+
/** Optional directory prefix within the bucket */
|
|
649
|
+
directory?: string;
|
|
650
|
+
/** Optional custom metadata to store with the file */
|
|
651
|
+
metadata?: StorageUploadMetadata;
|
|
652
|
+
/** Progress callback */
|
|
653
|
+
onUploadProgress?: (bytesUploaded: number, bytesTotal: number) => void;
|
|
654
|
+
};
|
|
655
|
+
type UploadResult = {
|
|
656
|
+
/** The storage path (e.g., "14/abc-123.jpg") */
|
|
657
|
+
path: string;
|
|
658
|
+
/** The bucket ID */
|
|
659
|
+
bucketId: string;
|
|
660
|
+
/** Original filename */
|
|
661
|
+
originalFileName: string;
|
|
662
|
+
/** Content type from file */
|
|
663
|
+
contentType: string;
|
|
664
|
+
};
|
|
665
|
+
type UseStorageUploadOptions = {
|
|
666
|
+
/** The storage bucket ID - required */
|
|
667
|
+
bucketId: string;
|
|
668
|
+
};
|
|
669
|
+
/**
|
|
670
|
+
* Hook for uploading files to Supabase Storage with path-based references.
|
|
671
|
+
*
|
|
672
|
+
* Unlike useDbAttachmentUpload, this hook:
|
|
673
|
+
* - Does NOT create Attachment records
|
|
674
|
+
* - Returns the storage path for the caller to store
|
|
675
|
+
* - Sets metadata directly on storage.objects
|
|
676
|
+
*
|
|
677
|
+
* @example
|
|
678
|
+
* ```tsx
|
|
679
|
+
* import { BUCKETS } from "@pol-studios/db";
|
|
680
|
+
*
|
|
681
|
+
* const upload = useStorageUpload({ bucketId: BUCKETS.AVATARS });
|
|
682
|
+
*
|
|
683
|
+
* const handleUpload = async (file: File) => {
|
|
684
|
+
* const result = await upload.mutateAsync({ file });
|
|
685
|
+
* // Store result.path on the entity
|
|
686
|
+
* await updateProfile({ profilePath: result.path });
|
|
687
|
+
* };
|
|
688
|
+
* ```
|
|
689
|
+
*/
|
|
690
|
+
declare function useStorageUpload(options: UseStorageUploadOptions): ReturnType<typeof useMutation<UploadResult, Error, UploadInput>>;
|
|
691
|
+
/**
|
|
692
|
+
* Convenience hook that combines upload with entity update.
|
|
693
|
+
* Uploads the file and then updates the specified entity with the path.
|
|
694
|
+
*/
|
|
695
|
+
declare function useStorageUploadWithEntity<T extends Record<string, unknown>>(options: UseStorageUploadOptions & {
|
|
696
|
+
/** Field name on the entity to store the path */
|
|
697
|
+
pathField: string;
|
|
698
|
+
/** Function to update the entity after upload */
|
|
699
|
+
updateEntity: (entity: T, path: string) => Promise<void>;
|
|
700
|
+
}): _tanstack_react_query.UseMutationResult<UploadResult, Error, UploadInput & {
|
|
701
|
+
entity: T;
|
|
702
|
+
}, unknown>;
|
|
703
|
+
|
|
704
|
+
export { type ArchiveUserResponse, type CancelDeletionResponse, type ConsentRecord, type ConsentSummary, type ConsentType, type DataExportHistoryRecord, type DataExportMetadata, type DeletionRequest, type DeletionStatus, type DeletionStatusResponse, type ExportedAccessPermission, type ExportedAuditLogEntry, type ExportedComment, type ExportedDevice, type ExportedGroupMembership, type ExportedNotification, type ExportedProfile, type ExportedRecentActivity, type ExportedSavedQuery, type ExportedUserMetadata, type PersonalDataExport, type RecordConsentOptions, type RequestDeletionResponse, type StorageUploadMetadata, type TaskRequest, type UnarchiveUserResponse, type UseAccountDeletionReturn, type UseConsentReturn, type UseDataExportReturn, type UseUserStatusReturn, type UserStatusInfo, recordConsentForUser, useAccountDeletion, useBackgroundTask, useConsent, useDataExport, useStorageUpload, useStorageUploadWithEntity, useUserMetadata, useUserStatus };
|