@terreno/admin-frontend 0.30.0 → 56.0.0-beta.2

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.
Files changed (54) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +62 -2
  3. package/dist/AdminShell.d.ts +5 -0
  4. package/dist/AdminShell.js +100 -31
  5. package/dist/AdminShell.js.map +1 -1
  6. package/dist/ConsentHistory.d.ts +9 -0
  7. package/dist/ConsentHistory.js +61 -0
  8. package/dist/ConsentHistory.js.map +1 -0
  9. package/dist/generateConsentHistoryPdf.d.ts +2 -0
  10. package/dist/generateConsentHistoryPdf.js +225 -0
  11. package/dist/generateConsentHistoryPdf.js.map +1 -0
  12. package/dist/generateConsentPdf.js +75 -28
  13. package/dist/generateConsentPdf.js.map +1 -1
  14. package/dist/index.d.ts +3 -0
  15. package/dist/index.js +3 -0
  16. package/dist/index.js.map +1 -1
  17. package/dist/pdfUtils.d.ts +9 -0
  18. package/dist/pdfUtils.js +25 -0
  19. package/dist/pdfUtils.js.map +1 -0
  20. package/dist/useAdminBackgroundTask.js.map +1 -1
  21. package/dist/useConsentHistory.d.ts +63 -0
  22. package/dist/useConsentHistory.js +40 -0
  23. package/dist/useConsentHistory.js.map +1 -0
  24. package/package.json +13 -10
  25. package/src/AdminModelForm.test.tsx +1 -1
  26. package/src/AdminModelList.test.tsx +1 -1
  27. package/src/AdminModelTable.test.tsx +1 -1
  28. package/src/AdminPrimitiveArrayField.test.tsx +1 -1
  29. package/src/AdminScriptList.test.tsx +1 -1
  30. package/src/AdminShell.test.tsx +191 -0
  31. package/src/AdminShell.tsx +331 -144
  32. package/src/AdminVersionConfig.test.tsx +1 -1
  33. package/src/CheckboxListEditor.test.tsx +1 -1
  34. package/src/ConfigurationScreen.test.tsx +1 -1
  35. package/src/ConsentFormEditor.test.tsx +1 -1
  36. package/src/ConsentFormList.test.tsx +1 -1
  37. package/src/ConsentHistory.test.tsx +161 -0
  38. package/src/ConsentHistory.tsx +251 -0
  39. package/src/ConsentResponseViewer.test.tsx +1 -1
  40. package/src/DocumentStorageBrowser.test.tsx +1 -1
  41. package/src/LocaleContentEditor.test.tsx +1 -1
  42. package/src/generateConsentHistoryPdf.ts +259 -0
  43. package/src/generateConsentPdf.ts +96 -31
  44. package/src/index.tsx +3 -0
  45. package/src/isolated/AdminFieldRenderer.isolated.tsx +1 -1
  46. package/src/isolated/AdminNestedArrayField.isolated.tsx +1 -1
  47. package/src/isolated/AdminObjectPicker.isolated.tsx +1 -1
  48. package/src/isolated/AdminScriptRunModal.isolated.tsx +1 -1
  49. package/src/isolated/DocumentStorageBrowser.isolated.tsx +1 -1
  50. package/src/isolated/generateConsentPdf.isolated.ts +5 -0
  51. package/src/pdfUtils.ts +28 -0
  52. package/src/useAdminBackgroundTask.ts +1 -0
  53. package/src/useConsentHistory.test.ts +106 -0
  54. package/src/useConsentHistory.ts +94 -0
@@ -0,0 +1,94 @@
1
+ export interface ConsentHistoryEntry {
2
+ _id: string;
3
+ agreed: boolean;
4
+ agreedAt: string;
5
+ checkboxValues?: Record<string, boolean>;
6
+ contentSnapshot?: string;
7
+ form: {
8
+ captureSignature: boolean;
9
+ checkboxes: Array<{label: string; required: boolean; confirmationPrompt?: string}>;
10
+ slug: string;
11
+ title: string;
12
+ type: string;
13
+ version: number;
14
+ } | null;
15
+ formVersionSnapshot?: number;
16
+ ipAddress?: string;
17
+ locale?: string;
18
+ signature?: string;
19
+ signedAt?: string;
20
+ userAgent?: string;
21
+ }
22
+
23
+ interface ConsentHistoryResponse {
24
+ data?: ConsentHistoryEntry[];
25
+ }
26
+
27
+ interface ConsentHistoryQueryBuilder {
28
+ query: (options: {providesTags: string[]; query: () => string}) => unknown;
29
+ }
30
+
31
+ interface ConsentHistoryHookState {
32
+ data?: ConsentHistoryEntry[] | ConsentHistoryResponse;
33
+ error: unknown;
34
+ isLoading: boolean;
35
+ refetch: () => void | Promise<void>;
36
+ }
37
+
38
+ interface ConsentHistoryEnhancedApi {
39
+ useGetMyConsentsQuery: () => ConsentHistoryHookState;
40
+ }
41
+
42
+ interface ConsentHistoryApiWithTags {
43
+ injectEndpoints: (options: {
44
+ endpoints: (build: ConsentHistoryQueryBuilder) => {getMyConsents: unknown};
45
+ overrideExisting: boolean;
46
+ }) => ConsentHistoryEnhancedApi;
47
+ }
48
+
49
+ interface ConsentHistoryApi {
50
+ enhanceEndpoints: (options: {addTagTypes: string[]}) => ConsentHistoryApiWithTags;
51
+ }
52
+
53
+ /**
54
+ * Cache the enhanced api per (api, baseUrl). `injectEndpoints` logs a console
55
+ * error in development whenever an endpoint with the same name is re-injected
56
+ * (with `overrideExisting: false`), so calling it on every render of every
57
+ * consumer would flood the console. WeakMap-by-api lets the GC reclaim entries
58
+ * when the api object is unreachable.
59
+ */
60
+ const enhancedApiCache = new WeakMap<ConsentHistoryApi, Map<string, ConsentHistoryEnhancedApi>>();
61
+
62
+ const getEnhancedApi = (api: ConsentHistoryApi, base: string): ConsentHistoryEnhancedApi => {
63
+ let byBase = enhancedApiCache.get(api);
64
+ if (!byBase) {
65
+ byBase = new Map();
66
+ enhancedApiCache.set(api, byBase);
67
+ }
68
+ const cached = byBase.get(base);
69
+ if (cached) {
70
+ return cached;
71
+ }
72
+ const apiWithConsentTags = api.enhanceEndpoints({addTagTypes: ["MyConsents"]});
73
+ const enhanced = apiWithConsentTags.injectEndpoints({
74
+ endpoints: (build) => ({
75
+ getMyConsents: build.query({
76
+ providesTags: ["MyConsents"],
77
+ query: () => `${base}/consents/my`,
78
+ }),
79
+ }),
80
+ overrideExisting: false,
81
+ });
82
+ byBase.set(base, enhanced);
83
+ return enhanced;
84
+ };
85
+
86
+ export const useConsentHistory = (api: ConsentHistoryApi, baseUrl?: string) => {
87
+ const base = baseUrl || "";
88
+ const enhancedApi = getEnhancedApi(api, base);
89
+
90
+ const {data, isLoading, error, refetch} = enhancedApi.useGetMyConsentsQuery();
91
+ const entries: ConsentHistoryEntry[] = Array.isArray(data) ? data : (data?.data ?? []);
92
+
93
+ return {entries, error, isLoading, refetch};
94
+ };