@terreno/ui 0.31.0 → 56.0.0-beta.0
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/LICENSE +203 -21
- package/dist/ActionSheet.d.ts +1 -1
- package/dist/Avatar.js +1 -4
- package/dist/Avatar.js.map +1 -1
- package/dist/Box.js +45 -9
- package/dist/Box.js.map +1 -1
- package/dist/Common.d.ts +21 -39
- package/dist/Common.js.map +1 -1
- package/dist/ConflictSheet.d.ts +53 -0
- package/dist/ConflictSheet.js +132 -0
- package/dist/ConflictSheet.js.map +1 -0
- package/dist/DateTimeActionSheet.d.ts +2 -1
- package/dist/DecimalRangeActionSheet.d.ts +1 -1
- package/dist/EmojiSelector.d.ts +1 -1
- package/dist/ErrorPage.d.ts +1 -1
- package/dist/HeightActionSheet.d.ts +1 -1
- package/dist/Hyperlink.d.ts +2 -1
- package/dist/Hyperlink.js +2 -1
- package/dist/Hyperlink.js.map +1 -1
- package/dist/Image.d.ts +1 -1
- package/dist/ImageBackground.d.ts +1 -1
- package/dist/MobileAddressAutoComplete.d.ts +1 -1
- package/dist/NumberPickerActionSheet.d.ts +1 -1
- package/dist/Page.d.ts +3 -3
- package/dist/PickerSelect.d.ts +1 -1
- package/dist/SidebarNavigation.js +1 -1
- package/dist/SidebarNavigation.js.map +1 -1
- package/dist/SidebarNavigation.native.js +1 -1
- package/dist/SidebarNavigation.native.js.map +1 -1
- package/dist/SplitPage.d.ts +1 -1
- package/dist/SplitPage.js +1 -4
- package/dist/SplitPage.js.map +1 -1
- package/dist/SplitPage.native.d.ts +1 -1
- package/dist/SyncStatusBanner.d.ts +46 -0
- package/dist/SyncStatusBanner.js +29 -0
- package/dist/SyncStatusBanner.js.map +1 -0
- package/dist/Theme.d.ts +1 -1
- package/dist/Theme.js +0 -1
- package/dist/Theme.js.map +1 -1
- package/dist/Toast.d.ts +9 -1
- package/dist/Toast.js +20 -7
- package/dist/Toast.js.map +1 -1
- package/dist/ToastNotifications.js +23 -1
- package/dist/ToastNotifications.js.map +1 -1
- package/dist/UnifiedAddressAutoComplete.d.ts +1 -1
- package/dist/Unifier.js +1 -1
- package/dist/Unifier.js.map +1 -1
- package/dist/conflictFieldDiff.d.ts +14 -0
- package/dist/conflictFieldDiff.js +62 -0
- package/dist/conflictFieldDiff.js.map +1 -0
- package/dist/icons/OfflineIcon.d.ts +1 -1
- package/dist/icons/OnlineIcon.d.ts +1 -1
- package/dist/icons/OutOfficeIcon.d.ts +1 -1
- package/dist/index.d.ts +5 -3
- package/dist/index.js +5 -3
- package/dist/index.js.map +1 -1
- package/dist/pdfHtmlTemplate.d.ts +30 -0
- package/dist/pdfHtmlTemplate.js +170 -0
- package/dist/pdfHtmlTemplate.js.map +1 -0
- package/dist/table/TableTitle.js +1 -3
- package/dist/table/TableTitle.js.map +1 -1
- package/dist/useAppLaunchOrForeground.d.ts +9 -0
- package/dist/useAppLaunchOrForeground.js +27 -0
- package/dist/useAppLaunchOrForeground.js.map +1 -0
- package/package.json +45 -39
- package/src/ActionSheet.test.tsx +37 -80
- package/src/Box.test.tsx +39 -9
- package/src/Box.tsx +46 -7
- package/src/Common.ts +21 -50
- package/src/ConflictSheet.test.tsx +461 -0
- package/src/ConflictSheet.tsx +399 -0
- package/src/ConsentNavigator.test.tsx +8 -6
- package/src/DateTimeField.test.tsx +0 -36
- package/src/Hyperlink.tsx +1 -1
- package/src/PickerSelect.test.tsx +12 -23
- package/src/SidebarNavigation.native.tsx +1 -1
- package/src/SidebarNavigation.tsx +1 -1
- package/src/SyncStatusBanner.test.tsx +204 -0
- package/src/SyncStatusBanner.tsx +148 -0
- package/src/TerrenoProvider.test.tsx +3 -4
- package/src/Theme.tsx +0 -1
- package/src/Toast.test.tsx +60 -0
- package/src/Toast.tsx +46 -1
- package/src/ToastNotifications.test.tsx +82 -0
- package/src/ToastNotifications.tsx +25 -1
- package/src/Unifier.ts +1 -1
- package/src/__snapshots__/AiSuggestionBox.test.tsx.snap +0 -3
- package/src/__snapshots__/Body.test.tsx.snap +0 -16
- package/src/__snapshots__/Box.test.tsx.snap +4 -13
- package/src/__snapshots__/Card.test.tsx.snap +0 -1
- package/src/__snapshots__/Page.test.tsx.snap +0 -84
- package/src/__snapshots__/SplitPage.test.tsx.snap +24 -120
- package/src/__snapshots__/TapToEdit.test.tsx.snap +5 -16
- package/src/__snapshots__/Toast.test.tsx.snap +4 -2
- package/src/bunSetup.ts +21 -6
- package/src/conflictFieldDiff.test.ts +26 -0
- package/src/conflictFieldDiff.ts +78 -0
- package/src/index.tsx +5 -3
- package/src/login/__snapshots__/LoginScreen.test.tsx.snap +0 -9
- package/src/pdfHtmlTemplate.ts +219 -0
- package/src/signUp/__snapshots__/OAuthButtons.test.tsx.snap +0 -1
- package/src/signUp/__snapshots__/PasswordRequirements.test.tsx.snap +2 -16
- package/src/signUp/__snapshots__/SignUpScreen.test.tsx.snap +1 -17
- package/src/signUp/__snapshots__/Swiper.test.tsx.snap +0 -1
- package/src/table/__snapshots__/Table.test.tsx.snap +22 -87
- package/src/table/__snapshots__/TableHeader.test.tsx.snap +10 -50
- package/src/table/__snapshots__/TableHeaderCell.test.tsx.snap +10 -84
- package/src/table/__snapshots__/TableRow.test.tsx.snap +12 -77
- package/src/useAppLaunchOrForeground.test.tsx +54 -0
- package/src/useAppLaunchOrForeground.ts +30 -0
- package/dist/ConsentHistory.d.ts +0 -9
- package/dist/ConsentHistory.js +0 -70
- package/dist/ConsentHistory.js.map +0 -1
- package/dist/EditableCard.d.ts +0 -3
- package/dist/EditableCard.js +0 -23
- package/dist/EditableCard.js.map +0 -1
- package/dist/generateConsentHistoryPdf.d.ts +0 -2
- package/dist/generateConsentHistoryPdf.js +0 -185
- package/dist/generateConsentHistoryPdf.js.map +0 -1
- package/dist/useConsentHistory.d.ts +0 -63
- package/dist/useConsentHistory.js +0 -40
- package/dist/useConsentHistory.js.map +0 -1
- package/src/ConsentHistory.test.tsx +0 -224
- package/src/ConsentHistory.tsx +0 -249
- package/src/DraggableList.test.tsx +0 -377
- package/src/EditableCard.test.tsx +0 -69
- package/src/EditableCard.tsx +0 -73
- package/src/SidebarNavigation.test.tsx +0 -339
- package/src/__snapshots__/EditableCard.test.tsx.snap +0 -242
- package/src/generateConsentHistoryPdf.test.ts +0 -253
- package/src/generateConsentHistoryPdf.ts +0 -211
- package/src/useConsentHistory.test.ts +0 -106
- package/src/useConsentHistory.ts +0 -94
|
@@ -1,253 +0,0 @@
|
|
|
1
|
-
import {beforeEach, describe, expect, it, mock} from "bun:test";
|
|
2
|
-
|
|
3
|
-
import type {ConsentHistoryEntry} from "./useConsentHistory";
|
|
4
|
-
|
|
5
|
-
interface PdfCall {
|
|
6
|
-
args: unknown[];
|
|
7
|
-
method: string;
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
interface MockDoc {
|
|
11
|
-
calls: PdfCall[];
|
|
12
|
-
savedFilename?: string;
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
let docs: MockDoc[] = [];
|
|
16
|
-
let addImageShouldThrow = false;
|
|
17
|
-
|
|
18
|
-
class MockJsPdf {
|
|
19
|
-
calls: PdfCall[] = [];
|
|
20
|
-
savedFilename?: string;
|
|
21
|
-
|
|
22
|
-
constructor(..._args: unknown[]) {
|
|
23
|
-
docs.push(this as unknown as MockDoc);
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
private record(method: string, args: unknown[]): void {
|
|
27
|
-
this.calls.push({args, method});
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
setFontSize(...args: unknown[]): void {
|
|
31
|
-
this.record("setFontSize", args);
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
setFont(...args: unknown[]): void {
|
|
35
|
-
this.record("setFont", args);
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
setDrawColor(...args: unknown[]): void {
|
|
39
|
-
this.record("setDrawColor", args);
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
setTextColor(...args: unknown[]): void {
|
|
43
|
-
this.record("setTextColor", args);
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
text(...args: unknown[]): void {
|
|
47
|
-
this.record("text", args);
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
line(...args: unknown[]): void {
|
|
51
|
-
this.record("line", args);
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
addPage(...args: unknown[]): void {
|
|
55
|
-
this.record("addPage", args);
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
addImage(...args: unknown[]): void {
|
|
59
|
-
this.record("addImage", args);
|
|
60
|
-
if (addImageShouldThrow) {
|
|
61
|
-
throw new Error("cannot embed image");
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
splitTextToSize(textValue: string, ..._rest: unknown[]): string[] {
|
|
66
|
-
this.record("splitTextToSize", [textValue]);
|
|
67
|
-
return String(textValue).split("\n");
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
save(...args: unknown[]): void {
|
|
71
|
-
this.record("save", args);
|
|
72
|
-
this.savedFilename = String(args[0]);
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
mock.module("jspdf", () => ({jsPDF: MockJsPdf}));
|
|
77
|
-
|
|
78
|
-
const {generateConsentHistoryPdf} = await import("./generateConsentHistoryPdf");
|
|
79
|
-
|
|
80
|
-
const lastDoc = (): MockDoc => docs[docs.length - 1]!;
|
|
81
|
-
|
|
82
|
-
const textStrings = (doc: MockDoc): string[] =>
|
|
83
|
-
doc.calls.filter((c) => c.method === "text").map((c) => String(c.args[0]));
|
|
84
|
-
|
|
85
|
-
const wasCalled = (doc: MockDoc, method: string): boolean =>
|
|
86
|
-
doc.calls.some((c) => c.method === method);
|
|
87
|
-
|
|
88
|
-
const baseEntry: ConsentHistoryEntry = {
|
|
89
|
-
_id: "response-1",
|
|
90
|
-
agreed: true,
|
|
91
|
-
agreedAt: "2024-01-15T10:30:00.000Z",
|
|
92
|
-
form: {
|
|
93
|
-
captureSignature: true,
|
|
94
|
-
checkboxes: [
|
|
95
|
-
{label: "I agree to the terms", required: true},
|
|
96
|
-
{label: "I consent to data use", required: false},
|
|
97
|
-
],
|
|
98
|
-
slug: "privacy-policy",
|
|
99
|
-
title: "Privacy Policy",
|
|
100
|
-
type: "consent",
|
|
101
|
-
version: 3,
|
|
102
|
-
},
|
|
103
|
-
};
|
|
104
|
-
|
|
105
|
-
describe("generateConsentHistoryPdf", () => {
|
|
106
|
-
beforeEach(() => {
|
|
107
|
-
docs = [];
|
|
108
|
-
addImageShouldThrow = false;
|
|
109
|
-
});
|
|
110
|
-
|
|
111
|
-
it("renders a complete consent record with every section", async () => {
|
|
112
|
-
const entry: ConsentHistoryEntry = {
|
|
113
|
-
...baseEntry,
|
|
114
|
-
checkboxValues: {"0": true, "1": false, "2": true},
|
|
115
|
-
contentSnapshot: "First line of the snapshot\nSecond line of the snapshot",
|
|
116
|
-
formVersionSnapshot: 3,
|
|
117
|
-
ipAddress: "203.0.113.7",
|
|
118
|
-
locale: "en-US",
|
|
119
|
-
signature: "data:image/png;base64,AAAA",
|
|
120
|
-
signedAt: "2024-01-15T10:31:00.000Z",
|
|
121
|
-
userAgent: "Mozilla/5.0",
|
|
122
|
-
};
|
|
123
|
-
|
|
124
|
-
await generateConsentHistoryPdf(entry);
|
|
125
|
-
|
|
126
|
-
const doc = lastDoc();
|
|
127
|
-
const texts = textStrings(doc);
|
|
128
|
-
expect(texts).toContain("Consent Record");
|
|
129
|
-
expect(texts).toContain("Privacy Policy");
|
|
130
|
-
expect(texts).toContain("Response Details");
|
|
131
|
-
expect(texts).toContain("Checkbox Responses");
|
|
132
|
-
expect(texts).toContain("Audit Trail");
|
|
133
|
-
expect(texts).toContain("Signature");
|
|
134
|
-
expect(texts).toContain("Content Snapshot");
|
|
135
|
-
// Known checkbox labels render with their check state.
|
|
136
|
-
expect(texts).toContain("[x] I agree to the terms");
|
|
137
|
-
expect(texts).toContain("[ ] I consent to data use");
|
|
138
|
-
// Unknown checkbox index falls back to a generated label.
|
|
139
|
-
expect(texts).toContain("[x] Checkbox 2");
|
|
140
|
-
// Agreed decision.
|
|
141
|
-
expect(texts.some((t) => t === "Agreed")).toBe(true);
|
|
142
|
-
// Snapshot lines are split and rendered individually.
|
|
143
|
-
expect(texts).toContain("First line of the snapshot");
|
|
144
|
-
expect(texts).toContain("Second line of the snapshot");
|
|
145
|
-
// Image embedded as PNG.
|
|
146
|
-
const image = doc.calls.find((c) => c.method === "addImage");
|
|
147
|
-
expect(image?.args[1]).toBe("PNG");
|
|
148
|
-
// Footer includes the response id.
|
|
149
|
-
expect(texts.some((t) => t.includes("Response ID: response-1"))).toBe(true);
|
|
150
|
-
// Saved with a slug-based filename.
|
|
151
|
-
expect(doc.savedFilename).toContain("consent-privacy-policy-");
|
|
152
|
-
expect(doc.savedFilename?.endsWith(".pdf")).toBe(true);
|
|
153
|
-
});
|
|
154
|
-
|
|
155
|
-
it("handles a minimal declined entry with no optional sections", async () => {
|
|
156
|
-
const entry: ConsentHistoryEntry = {
|
|
157
|
-
_id: "",
|
|
158
|
-
agreed: false,
|
|
159
|
-
agreedAt: "",
|
|
160
|
-
form: null,
|
|
161
|
-
};
|
|
162
|
-
|
|
163
|
-
await generateConsentHistoryPdf(entry);
|
|
164
|
-
|
|
165
|
-
const doc = lastDoc();
|
|
166
|
-
const texts = textStrings(doc);
|
|
167
|
-
expect(texts).toContain("Unknown Form");
|
|
168
|
-
expect(texts.some((t) => t === "Declined")).toBe(true);
|
|
169
|
-
expect(texts).not.toContain("Checkbox Responses");
|
|
170
|
-
expect(texts).not.toContain("Audit Trail");
|
|
171
|
-
expect(texts).not.toContain("Signature");
|
|
172
|
-
expect(texts).not.toContain("Content Snapshot");
|
|
173
|
-
expect(wasCalled(doc, "addImage")).toBe(false);
|
|
174
|
-
// No _id means no response-id footer line.
|
|
175
|
-
expect(texts.some((t) => t.includes("Response ID:"))).toBe(false);
|
|
176
|
-
// Falls back to "response" in the filename when there is no slug.
|
|
177
|
-
expect(doc.savedFilename).toContain("consent-response-");
|
|
178
|
-
});
|
|
179
|
-
|
|
180
|
-
it("embeds a JPEG signature when the data URI is not PNG", async () => {
|
|
181
|
-
const entry: ConsentHistoryEntry = {
|
|
182
|
-
...baseEntry,
|
|
183
|
-
signature: "data:image/jpeg;base64,BBBB",
|
|
184
|
-
};
|
|
185
|
-
|
|
186
|
-
await generateConsentHistoryPdf(entry);
|
|
187
|
-
|
|
188
|
-
const doc = lastDoc();
|
|
189
|
-
const image = doc.calls.find((c) => c.method === "addImage");
|
|
190
|
-
expect(image?.args[1]).toBe("JPEG");
|
|
191
|
-
});
|
|
192
|
-
|
|
193
|
-
it("falls back to a placeholder when the signature image cannot be embedded", async () => {
|
|
194
|
-
addImageShouldThrow = true;
|
|
195
|
-
const entry: ConsentHistoryEntry = {
|
|
196
|
-
...baseEntry,
|
|
197
|
-
signature: "data:image/png;base64,CCCC",
|
|
198
|
-
};
|
|
199
|
-
|
|
200
|
-
await generateConsentHistoryPdf(entry);
|
|
201
|
-
|
|
202
|
-
const doc = lastDoc();
|
|
203
|
-
const texts = textStrings(doc);
|
|
204
|
-
expect(texts).toContain("(Signature image could not be embedded)");
|
|
205
|
-
});
|
|
206
|
-
|
|
207
|
-
it("adds pages when content overflows the page height", async () => {
|
|
208
|
-
const manyLines = Array.from({length: 200}, (_v, i) => `Line ${i}`).join("\n");
|
|
209
|
-
const entry: ConsentHistoryEntry = {
|
|
210
|
-
...baseEntry,
|
|
211
|
-
contentSnapshot: manyLines,
|
|
212
|
-
};
|
|
213
|
-
|
|
214
|
-
await generateConsentHistoryPdf(entry);
|
|
215
|
-
|
|
216
|
-
const doc = lastDoc();
|
|
217
|
-
expect(wasCalled(doc, "addPage")).toBe(true);
|
|
218
|
-
});
|
|
219
|
-
|
|
220
|
-
it("uses the audit-trail form version when the form has no version", async () => {
|
|
221
|
-
const entry: ConsentHistoryEntry = {
|
|
222
|
-
_id: "id-2",
|
|
223
|
-
agreed: true,
|
|
224
|
-
agreedAt: "2024-01-15T10:30:00.000Z",
|
|
225
|
-
form: null,
|
|
226
|
-
formVersionSnapshot: 7,
|
|
227
|
-
};
|
|
228
|
-
|
|
229
|
-
await generateConsentHistoryPdf(entry);
|
|
230
|
-
|
|
231
|
-
const doc = lastDoc();
|
|
232
|
-
const texts = textStrings(doc);
|
|
233
|
-
// formVersion resolves from formVersionSnapshot in Response Details...
|
|
234
|
-
expect(texts).toContain("Audit Trail");
|
|
235
|
-
// ...and the snapshot version shows up as a value.
|
|
236
|
-
expect(texts.some((t) => t === "7")).toBe(true);
|
|
237
|
-
});
|
|
238
|
-
|
|
239
|
-
it("renders raw invalid dates and skips empty dates via formatDate", async () => {
|
|
240
|
-
const entry: ConsentHistoryEntry = {
|
|
241
|
-
...baseEntry,
|
|
242
|
-
agreedAt: "not-a-real-date",
|
|
243
|
-
signedAt: "",
|
|
244
|
-
};
|
|
245
|
-
|
|
246
|
-
await generateConsentHistoryPdf(entry);
|
|
247
|
-
|
|
248
|
-
const doc = lastDoc();
|
|
249
|
-
const texts = textStrings(doc);
|
|
250
|
-
// Invalid date string is passed through unchanged.
|
|
251
|
-
expect(texts).toContain("not-a-real-date");
|
|
252
|
-
});
|
|
253
|
-
});
|
|
@@ -1,211 +0,0 @@
|
|
|
1
|
-
import {jsPDF} from "jspdf";
|
|
2
|
-
import {DateTime} from "luxon";
|
|
3
|
-
|
|
4
|
-
import type {ConsentHistoryEntry} from "./useConsentHistory";
|
|
5
|
-
|
|
6
|
-
const PAGE_WIDTH = 210;
|
|
7
|
-
const MARGIN_LEFT = 20;
|
|
8
|
-
const MARGIN_RIGHT = 20;
|
|
9
|
-
const CONTENT_WIDTH = PAGE_WIDTH - MARGIN_LEFT - MARGIN_RIGHT;
|
|
10
|
-
const PAGE_HEIGHT = 297;
|
|
11
|
-
const MARGIN_BOTTOM = 20;
|
|
12
|
-
|
|
13
|
-
const formatDate = (value: unknown): string => {
|
|
14
|
-
if (!value) {
|
|
15
|
-
return "";
|
|
16
|
-
}
|
|
17
|
-
const dt = DateTime.fromISO(String(value));
|
|
18
|
-
if (!dt.isValid) {
|
|
19
|
-
return String(value);
|
|
20
|
-
}
|
|
21
|
-
return dt.toLocaleString(DateTime.DATETIME_FULL);
|
|
22
|
-
};
|
|
23
|
-
|
|
24
|
-
const ensureSpace = (doc: jsPDF, y: number, needed: number): number => {
|
|
25
|
-
if (y + needed > PAGE_HEIGHT - MARGIN_BOTTOM) {
|
|
26
|
-
doc.addPage();
|
|
27
|
-
return 20;
|
|
28
|
-
}
|
|
29
|
-
return y;
|
|
30
|
-
};
|
|
31
|
-
|
|
32
|
-
export const generateConsentHistoryPdf = async (entry: ConsentHistoryEntry): Promise<void> => {
|
|
33
|
-
const doc = new jsPDF({format: "a4", orientation: "portrait", unit: "mm"});
|
|
34
|
-
|
|
35
|
-
const formTitle = entry.form?.title ?? "Unknown Form";
|
|
36
|
-
const formSlug = entry.form?.slug ?? "";
|
|
37
|
-
const formType = entry.form?.type ?? "";
|
|
38
|
-
const formVersion = entry.form?.version ?? entry.formVersionSnapshot;
|
|
39
|
-
|
|
40
|
-
let y = 20;
|
|
41
|
-
|
|
42
|
-
// Title
|
|
43
|
-
doc.setFontSize(18);
|
|
44
|
-
doc.setFont("helvetica", "bold");
|
|
45
|
-
doc.text("Consent Record", MARGIN_LEFT, y);
|
|
46
|
-
y += 10;
|
|
47
|
-
|
|
48
|
-
// Form title
|
|
49
|
-
doc.setFontSize(14);
|
|
50
|
-
doc.setFont("helvetica", "normal");
|
|
51
|
-
doc.text(formTitle, MARGIN_LEFT, y);
|
|
52
|
-
y += 10;
|
|
53
|
-
|
|
54
|
-
// Separator
|
|
55
|
-
doc.setDrawColor(200, 200, 200);
|
|
56
|
-
doc.line(MARGIN_LEFT, y, PAGE_WIDTH - MARGIN_RIGHT, y);
|
|
57
|
-
y += 8;
|
|
58
|
-
|
|
59
|
-
// Helper to add a labeled field
|
|
60
|
-
const addField = (label: string, value: string) => {
|
|
61
|
-
y = ensureSpace(doc, y, 8);
|
|
62
|
-
doc.setFontSize(9);
|
|
63
|
-
doc.setFont("helvetica", "bold");
|
|
64
|
-
doc.setTextColor(100, 100, 100);
|
|
65
|
-
doc.text(label, MARGIN_LEFT, y);
|
|
66
|
-
doc.setFont("helvetica", "normal");
|
|
67
|
-
doc.setTextColor(0, 0, 0);
|
|
68
|
-
doc.setFontSize(10);
|
|
69
|
-
doc.text(value, MARGIN_LEFT + 45, y);
|
|
70
|
-
y += 6;
|
|
71
|
-
};
|
|
72
|
-
|
|
73
|
-
// Response Details
|
|
74
|
-
doc.setFontSize(12);
|
|
75
|
-
doc.setFont("helvetica", "bold");
|
|
76
|
-
doc.setTextColor(0, 0, 0);
|
|
77
|
-
doc.text("Response Details", MARGIN_LEFT, y);
|
|
78
|
-
y += 8;
|
|
79
|
-
|
|
80
|
-
if (formSlug) {
|
|
81
|
-
addField("Form Slug:", formSlug);
|
|
82
|
-
}
|
|
83
|
-
if (formType) {
|
|
84
|
-
addField("Form Type:", formType);
|
|
85
|
-
}
|
|
86
|
-
if (formVersion !== undefined) {
|
|
87
|
-
addField("Form Version:", String(formVersion));
|
|
88
|
-
}
|
|
89
|
-
addField("Decision:", entry.agreed ? "Agreed" : "Declined");
|
|
90
|
-
if (entry.agreedAt) {
|
|
91
|
-
addField("Agreed At:", formatDate(entry.agreedAt));
|
|
92
|
-
}
|
|
93
|
-
if (entry.locale) {
|
|
94
|
-
addField("Locale:", entry.locale);
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
y += 4;
|
|
98
|
-
|
|
99
|
-
// Checkbox Values
|
|
100
|
-
const checkboxEntries =
|
|
101
|
-
entry.checkboxValues && typeof entry.checkboxValues === "object"
|
|
102
|
-
? Object.entries(entry.checkboxValues)
|
|
103
|
-
: [];
|
|
104
|
-
|
|
105
|
-
if (checkboxEntries.length > 0) {
|
|
106
|
-
y = ensureSpace(doc, y, 12 + checkboxEntries.length * 6);
|
|
107
|
-
doc.setFontSize(12);
|
|
108
|
-
doc.setFont("helvetica", "bold");
|
|
109
|
-
doc.setTextColor(0, 0, 0);
|
|
110
|
-
doc.text("Checkbox Responses", MARGIN_LEFT, y);
|
|
111
|
-
y += 8;
|
|
112
|
-
|
|
113
|
-
for (const [index, checked] of checkboxEntries) {
|
|
114
|
-
y = ensureSpace(doc, y, 6);
|
|
115
|
-
doc.setFontSize(10);
|
|
116
|
-
doc.setFont("helvetica", "normal");
|
|
117
|
-
const label = entry.form?.checkboxes?.[Number(index)]?.label;
|
|
118
|
-
const checkmark = checked ? "[x]" : "[ ]";
|
|
119
|
-
doc.text(`${checkmark} ${label ?? `Checkbox ${index}`}`, MARGIN_LEFT + 4, y);
|
|
120
|
-
y += 6;
|
|
121
|
-
}
|
|
122
|
-
y += 4;
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
// Audit Trail
|
|
126
|
-
const hasAuditTrail = entry.ipAddress || entry.userAgent || entry.formVersionSnapshot;
|
|
127
|
-
|
|
128
|
-
if (hasAuditTrail) {
|
|
129
|
-
y = ensureSpace(doc, y, 20);
|
|
130
|
-
doc.setFontSize(12);
|
|
131
|
-
doc.setFont("helvetica", "bold");
|
|
132
|
-
doc.setTextColor(0, 0, 0);
|
|
133
|
-
doc.text("Audit Trail", MARGIN_LEFT, y);
|
|
134
|
-
y += 8;
|
|
135
|
-
|
|
136
|
-
if (entry.ipAddress) {
|
|
137
|
-
addField("IP Address:", entry.ipAddress);
|
|
138
|
-
}
|
|
139
|
-
if (entry.userAgent) {
|
|
140
|
-
addField("User Agent:", entry.userAgent);
|
|
141
|
-
}
|
|
142
|
-
if (entry.formVersionSnapshot !== undefined) {
|
|
143
|
-
addField("Form Version:", String(entry.formVersionSnapshot));
|
|
144
|
-
}
|
|
145
|
-
if (entry.signedAt) {
|
|
146
|
-
addField("Signed At:", formatDate(entry.signedAt));
|
|
147
|
-
}
|
|
148
|
-
y += 4;
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
// Signature
|
|
152
|
-
if (entry.signature) {
|
|
153
|
-
y = ensureSpace(doc, y, 50);
|
|
154
|
-
doc.setFontSize(12);
|
|
155
|
-
doc.setFont("helvetica", "bold");
|
|
156
|
-
doc.setTextColor(0, 0, 0);
|
|
157
|
-
doc.text("Signature", MARGIN_LEFT, y);
|
|
158
|
-
y += 6;
|
|
159
|
-
|
|
160
|
-
try {
|
|
161
|
-
const format = entry.signature.includes("image/png") ? "PNG" : "JPEG";
|
|
162
|
-
doc.addImage(entry.signature, format, MARGIN_LEFT, y, 80, 30);
|
|
163
|
-
y += 34;
|
|
164
|
-
} catch {
|
|
165
|
-
doc.setFontSize(10);
|
|
166
|
-
doc.setFont("helvetica", "italic");
|
|
167
|
-
doc.text("(Signature image could not be embedded)", MARGIN_LEFT, y);
|
|
168
|
-
y += 6;
|
|
169
|
-
}
|
|
170
|
-
y += 4;
|
|
171
|
-
}
|
|
172
|
-
|
|
173
|
-
// Content Snapshot
|
|
174
|
-
if (entry.contentSnapshot) {
|
|
175
|
-
y = ensureSpace(doc, y, 20);
|
|
176
|
-
doc.setFontSize(12);
|
|
177
|
-
doc.setFont("helvetica", "bold");
|
|
178
|
-
doc.setTextColor(0, 0, 0);
|
|
179
|
-
doc.text("Content Snapshot", MARGIN_LEFT, y);
|
|
180
|
-
y += 8;
|
|
181
|
-
|
|
182
|
-
doc.setFontSize(9);
|
|
183
|
-
doc.setFont("helvetica", "normal");
|
|
184
|
-
doc.setTextColor(50, 50, 50);
|
|
185
|
-
|
|
186
|
-
const lines = doc.splitTextToSize(entry.contentSnapshot, CONTENT_WIDTH);
|
|
187
|
-
for (const line of lines) {
|
|
188
|
-
y = ensureSpace(doc, y, 5);
|
|
189
|
-
doc.text(line, MARGIN_LEFT, y);
|
|
190
|
-
y += 4;
|
|
191
|
-
}
|
|
192
|
-
}
|
|
193
|
-
|
|
194
|
-
// Footer
|
|
195
|
-
y = ensureSpace(doc, y, 20);
|
|
196
|
-
y += 8;
|
|
197
|
-
doc.setDrawColor(200, 200, 200);
|
|
198
|
-
doc.line(MARGIN_LEFT, y, PAGE_WIDTH - MARGIN_RIGHT, y);
|
|
199
|
-
y += 6;
|
|
200
|
-
doc.setFontSize(8);
|
|
201
|
-
doc.setFont("helvetica", "italic");
|
|
202
|
-
doc.setTextColor(150, 150, 150);
|
|
203
|
-
doc.text(`Generated ${DateTime.now().toLocaleString(DateTime.DATETIME_FULL)}`, MARGIN_LEFT, y);
|
|
204
|
-
if (entry._id) {
|
|
205
|
-
doc.text(`Response ID: ${entry._id}`, PAGE_WIDTH - MARGIN_RIGHT, y, {align: "right"});
|
|
206
|
-
}
|
|
207
|
-
|
|
208
|
-
// Download
|
|
209
|
-
const filename = `consent-${formSlug || "response"}-${DateTime.now().toFormat("yyyy-MM-dd")}.pdf`;
|
|
210
|
-
doc.save(filename);
|
|
211
|
-
};
|
|
@@ -1,106 +0,0 @@
|
|
|
1
|
-
import {describe, expect, it, mock} from "bun:test";
|
|
2
|
-
import {renderHook} from "@testing-library/react-native";
|
|
3
|
-
|
|
4
|
-
import type {ConsentHistoryEntry} from "./useConsentHistory";
|
|
5
|
-
import {useConsentHistory} from "./useConsentHistory";
|
|
6
|
-
|
|
7
|
-
type ConsentHistoryApi = Parameters<typeof useConsentHistory>[0];
|
|
8
|
-
|
|
9
|
-
interface MockQueryDef {
|
|
10
|
-
query: () => string;
|
|
11
|
-
providesTags: string[];
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
interface MockInjectOpts {
|
|
15
|
-
endpoints: (build: {query: (def: MockQueryDef) => string}) => Record<string, unknown>;
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
describe("useConsentHistory", () => {
|
|
19
|
-
const buildApi = (queryResult: {data?: unknown; error?: unknown; isLoading?: boolean}) => {
|
|
20
|
-
const refetch = mock(() => {});
|
|
21
|
-
const useGetMyConsentsQuery = mock(() => ({
|
|
22
|
-
data: queryResult.data,
|
|
23
|
-
error: queryResult.error,
|
|
24
|
-
isLoading: queryResult.isLoading ?? false,
|
|
25
|
-
refetch,
|
|
26
|
-
}));
|
|
27
|
-
const api = {
|
|
28
|
-
enhanceEndpoints: mock((opts: {addTagTypes: string[]}) => {
|
|
29
|
-
expect(opts.addTagTypes).toContain("MyConsents");
|
|
30
|
-
return {
|
|
31
|
-
injectEndpoints: mock((injectOpts: MockInjectOpts) => {
|
|
32
|
-
const build = {
|
|
33
|
-
query: mock((def: MockQueryDef) => {
|
|
34
|
-
// Exercise the URL builder so the closure captures `base`
|
|
35
|
-
const url = def.query();
|
|
36
|
-
expect(url).toContain("/consents/my");
|
|
37
|
-
return "my-consents-query";
|
|
38
|
-
}),
|
|
39
|
-
};
|
|
40
|
-
injectOpts.endpoints(build);
|
|
41
|
-
return {useGetMyConsentsQuery};
|
|
42
|
-
}),
|
|
43
|
-
};
|
|
44
|
-
}),
|
|
45
|
-
};
|
|
46
|
-
return {api, refetch};
|
|
47
|
-
};
|
|
48
|
-
|
|
49
|
-
it("returns an array of entries when response is an array", () => {
|
|
50
|
-
const {api} = buildApi({
|
|
51
|
-
data: [{_id: "1", agreed: true} as unknown as ConsentHistoryEntry],
|
|
52
|
-
});
|
|
53
|
-
const {result} = renderHook(() => useConsentHistory(api as unknown as ConsentHistoryApi));
|
|
54
|
-
expect(Array.isArray(result.current.entries)).toBe(true);
|
|
55
|
-
expect(result.current.entries).toHaveLength(1);
|
|
56
|
-
});
|
|
57
|
-
|
|
58
|
-
it("unwraps .data property when response is object shape", () => {
|
|
59
|
-
const {api} = buildApi({
|
|
60
|
-
data: {data: [{_id: "2", agreed: false} as unknown as ConsentHistoryEntry]},
|
|
61
|
-
});
|
|
62
|
-
const {result} = renderHook(() =>
|
|
63
|
-
useConsentHistory(api as unknown as ConsentHistoryApi, "/api")
|
|
64
|
-
);
|
|
65
|
-
expect(Array.isArray(result.current.entries)).toBe(true);
|
|
66
|
-
expect(result.current.entries).toHaveLength(1);
|
|
67
|
-
});
|
|
68
|
-
|
|
69
|
-
it("returns empty array when no data is present", () => {
|
|
70
|
-
const {api} = buildApi({data: undefined, isLoading: true});
|
|
71
|
-
const {result} = renderHook(() => useConsentHistory(api as unknown as ConsentHistoryApi));
|
|
72
|
-
expect(result.current.entries).toEqual([]);
|
|
73
|
-
expect(result.current.isLoading).toBe(true);
|
|
74
|
-
});
|
|
75
|
-
|
|
76
|
-
it("surfaces error from the query hook", () => {
|
|
77
|
-
const {api} = buildApi({data: undefined, error: "boom"});
|
|
78
|
-
const {result} = renderHook(() => useConsentHistory(api as unknown as ConsentHistoryApi));
|
|
79
|
-
expect(result.current.error).toBe("boom");
|
|
80
|
-
});
|
|
81
|
-
|
|
82
|
-
it("injects the my-consents endpoint only once per (api, baseUrl)", () => {
|
|
83
|
-
let injectCallCount = 0;
|
|
84
|
-
const refetch = mock(() => {});
|
|
85
|
-
const useGetMyConsentsQuery = mock(() => ({
|
|
86
|
-
data: undefined,
|
|
87
|
-
error: undefined,
|
|
88
|
-
isLoading: false,
|
|
89
|
-
refetch,
|
|
90
|
-
}));
|
|
91
|
-
const api = {
|
|
92
|
-
enhanceEndpoints: () => ({
|
|
93
|
-
injectEndpoints: () => {
|
|
94
|
-
injectCallCount += 1;
|
|
95
|
-
return {useGetMyConsentsQuery};
|
|
96
|
-
},
|
|
97
|
-
}),
|
|
98
|
-
};
|
|
99
|
-
const {rerender} = renderHook(() => useConsentHistory(api as unknown as ConsentHistoryApi));
|
|
100
|
-
rerender(undefined);
|
|
101
|
-
rerender(undefined);
|
|
102
|
-
// The hook reuses the cached enhanced api after the first render so the
|
|
103
|
-
// dev-mode RTK warning about re-injecting endpoints never fires.
|
|
104
|
-
expect(injectCallCount).toBe(1);
|
|
105
|
-
});
|
|
106
|
-
});
|
package/src/useConsentHistory.ts
DELETED
|
@@ -1,94 +0,0 @@
|
|
|
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
|
-
};
|