@jsb188/mday 1.1.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.
- package/package.json +142 -0
- package/src/constants/agentMemory.ts +166 -0
- package/src/constants/agentNote.ts +212 -0
- package/src/constants/aiChat.ts +10 -0
- package/src/constants/billing.ts +126 -0
- package/src/constants/campaign.ts +236 -0
- package/src/constants/contact.ts +72 -0
- package/src/constants/csvExport.ts +133 -0
- package/src/constants/dataTable.ts +22 -0
- package/src/constants/dataTableFieldTypes.generated.ts +59 -0
- package/src/constants/docAccess.ts +33 -0
- package/src/constants/dt.ts +234 -0
- package/src/constants/email.ts +146 -0
- package/src/constants/fieldDoc.ts +104 -0
- package/src/constants/graphqlReactivity.ts +196 -0
- package/src/constants/inboundContact.ts +8 -0
- package/src/constants/integration.ts +13 -0
- package/src/constants/log.ts +21 -0
- package/src/constants/logDisplay/README.md +88 -0
- package/src/constants/logDisplay/defaults.ts +39 -0
- package/src/constants/logDisplay/index.ts +27 -0
- package/src/constants/logDisplay/operations/arable.ts +16 -0
- package/src/constants/logDisplay/operations/farmersMarket.ts +10 -0
- package/src/constants/logDisplay/operations/foodManufacturing.ts +13 -0
- package/src/constants/logDisplay/shared/accounting.ts +13 -0
- package/src/constants/logDisplay/shared/interactions.ts +13 -0
- package/src/constants/logDisplay/shared/rackTemperatures.ts +42 -0
- package/src/constants/logTaxonomy.generated.ts +2199 -0
- package/src/constants/noteDoc.ts +77 -0
- package/src/constants/organization.ts +60 -0
- package/src/constants/pageRoute.ts +23 -0
- package/src/constants/qrCode.ts +30 -0
- package/src/constants/sheet.ts +132 -0
- package/src/constants/sms.ts +18 -0
- package/src/constants/square.ts +16 -0
- package/src/constants/storage.ts +85 -0
- package/src/constants/usage.ts +82 -0
- package/src/constants/workflowSteps.ts +60 -0
- package/src/schemas/editLogEntry.ts +879 -0
- package/src/schemas/inboundContact.ts +77 -0
- package/src/schemas/logsQuery.ts +93 -0
- package/src/types/account.d.ts +81 -0
- package/src/types/agentMemory.d.ts +100 -0
- package/src/types/agentNote.d.ts +441 -0
- package/src/types/billing.d.ts +537 -0
- package/src/types/campaign.d.ts +1533 -0
- package/src/types/contact.d.ts +15 -0
- package/src/types/csvExport.d.ts +213 -0
- package/src/types/dataAnalysis.d.ts +44 -0
- package/src/types/dataTable.d.ts +159 -0
- package/src/types/definitionElement.d.ts +35 -0
- package/src/types/docAccess.d.ts +96 -0
- package/src/types/dt.d.ts +257 -0
- package/src/types/email.d.ts +231 -0
- package/src/types/emailReplyReport.d.ts +76 -0
- package/src/types/fieldDoc.d.ts +702 -0
- package/src/types/fieldDocContract.d.ts +90 -0
- package/src/types/inboundContact.d.ts +65 -0
- package/src/types/integration.d.ts +42 -0
- package/src/types/log.d.ts +338 -0
- package/src/types/logDisplay.types.ts +85 -0
- package/src/types/organization.d.ts +350 -0
- package/src/types/pageRoute.d.ts +48 -0
- package/src/types/qrCode.d.ts +96 -0
- package/src/types/richText.d.ts +81 -0
- package/src/types/sheet.d.ts +847 -0
- package/src/types/sms.d.ts +38 -0
- package/src/types/storage.d.ts +481 -0
- package/src/types/usage.d.ts +106 -0
- package/src/types/workflow.d.ts +435 -0
- package/src/utils/agentMemory.ts +15 -0
- package/src/utils/agentNote.ts +850 -0
- package/src/utils/aiChat.ts +43 -0
- package/src/utils/aiChatWork.ts +64 -0
- package/src/utils/billing.ts +37 -0
- package/src/utils/campaign.ts +1173 -0
- package/src/utils/campaignAI.ts +72 -0
- package/src/utils/campaignAccess.ts +239 -0
- package/src/utils/campaignEmail.ts +601 -0
- package/src/utils/campaignEmailCompiler.ts +372 -0
- package/src/utils/campaignEmailImages.ts +60 -0
- package/src/utils/campaignEmailStyles.ts +544 -0
- package/src/utils/campaignLifecycle.ts +104 -0
- package/src/utils/campaignPreview.ts +285 -0
- package/src/utils/contact.ts +50 -0
- package/src/utils/csvExport.ts +19 -0
- package/src/utils/dataTable.ts +311 -0
- package/src/utils/dataTableFieldTypeRegistry.ts +106 -0
- package/src/utils/dataTableRelativeDate.ts +447 -0
- package/src/utils/definitionElement.ts +84 -0
- package/src/utils/docAccess.ts +383 -0
- package/src/utils/documentName.ts +53 -0
- package/src/utils/email.ts +379 -0
- package/src/utils/emailReplyReport.test.ts +187 -0
- package/src/utils/emailReplyReport.ts +143 -0
- package/src/utils/fieldDoc.ts +157 -0
- package/src/utils/fieldDocAnswers.ts +128 -0
- package/src/utils/fieldDocDefaults.ts +36 -0
- package/src/utils/fieldDocProgram.ts +36 -0
- package/src/utils/fieldDocSummary.ts +30 -0
- package/src/utils/log.ts +357 -0
- package/src/utils/logDisplay.helpers.ts +177 -0
- package/src/utils/logDisplay.ts +87 -0
- package/src/utils/logRegistryValue.ts +90 -0
- package/src/utils/logStoreRead.ts +262 -0
- package/src/utils/logTaxonomy.helpers.ts +17 -0
- package/src/utils/logTaxonomy.ts +76 -0
- package/src/utils/logTaxonomyDisplay.ts +395 -0
- package/src/utils/noteDoc.ts +609 -0
- package/src/utils/organization.ts +669 -0
- package/src/utils/pageRoute.ts +71 -0
- package/src/utils/qrCode.helpers.ts +189 -0
- package/src/utils/qrCode.test.ts +519 -0
- package/src/utils/qrCode.ts +273 -0
- package/src/utils/richTextHTML.ts +385 -0
- package/src/utils/sheet.ts +262 -0
- package/src/utils/sheetAxisMove.ts +616 -0
- package/src/utils/sheetBootstrap.ts +1402 -0
- package/src/utils/sheetCellLiteral.ts +101 -0
- package/src/utils/sheetCommand.ts +358 -0
- package/src/utils/sheetDesign.ts +705 -0
- package/src/utils/sheetExport.ts +186 -0
- package/src/utils/sheetFeatureReference.ts +183 -0
- package/src/utils/sheetFormulaArgs.ts +168 -0
- package/src/utils/sheetFormulaCompile.ts +475 -0
- package/src/utils/sheetFormulaConditionalAggregate.ts +254 -0
- package/src/utils/sheetFormulaCriteria.ts +656 -0
- package/src/utils/sheetFormulaDate.ts +444 -0
- package/src/utils/sheetFormulaEvaluation.ts +899 -0
- package/src/utils/sheetFormulaEvaluator.ts +997 -0
- package/src/utils/sheetFormulaFunctionHandlers.ts +403 -0
- package/src/utils/sheetFormulaLogical.ts +116 -0
- package/src/utils/sheetFormulaLookup.ts +488 -0
- package/src/utils/sheetFormulaMath.ts +48 -0
- package/src/utils/sheetFormulaParser.ts +729 -0
- package/src/utils/sheetFormulaRange.ts +330 -0
- package/src/utils/sheetFormulaReference.ts +703 -0
- package/src/utils/sheetFormulaReferenceAggregates.ts +313 -0
- package/src/utils/sheetFormulaReferenceDates.ts +237 -0
- package/src/utils/sheetFormulaReferenceLogical.ts +330 -0
- package/src/utils/sheetFormulaReferenceLookup.ts +341 -0
- package/src/utils/sheetFormulaReferenceMath.ts +95 -0
- package/src/utils/sheetFormulaReferenceRewrite.ts +220 -0
- package/src/utils/sheetFormulaReferenceText.ts +462 -0
- package/src/utils/sheetFormulaSyntax.ts +1027 -0
- package/src/utils/sheetFormulaText.ts +430 -0
- package/src/utils/sheetJournal.ts +200 -0
- package/src/utils/sheetNumberFormat.ts +1012 -0
- package/src/utils/sheetPreview.ts +68 -0
- package/src/utils/sheetSequence.ts +118 -0
- package/src/utils/sheetSnapshot.ts +739 -0
- package/src/utils/sheetStructureEdit.ts +914 -0
- package/src/utils/sheetStructureReferences.ts +389 -0
- package/src/utils/square.ts +32 -0
- package/src/utils/storage.ts +198 -0
- package/src/utils/table-route.ts +262 -0
- package/src/utils/time.ts +12 -0
- package/src/utils/workflow.ts +506 -0
- package/src/utils/workflowLogFingerprint.ts +302 -0
- package/src/utils/workflowLogRevisionSnapshot.ts +424 -0
- package/src/utils/workflowProgress.ts +280 -0
- package/src/utils/workflowTriggers.ts +61 -0
- package/tests/agentNote.test.ts +395 -0
- package/tests/campaignAI.test.ts +119 -0
- package/tests/campaignAccess.test.ts +239 -0
- package/tests/campaignEmail.test.ts +441 -0
- package/tests/campaignLifecycle.test.ts +134 -0
- package/tests/campaignPublication.test.ts +309 -0
- package/tests/dataTableFieldTypeRegistry.test.ts +111 -0
- package/tests/dataTableRelativeDate.test.ts +412 -0
- package/tests/docAccess.test.ts +525 -0
- package/tests/editLogEntry.test.ts +112 -0
- package/tests/email.test.ts +39 -0
- package/tests/fieldDocProgram.test.ts +114 -0
- package/tests/logDisplay.fixtures.ts +67 -0
- package/tests/logDisplay.test.ts +227 -0
- package/tests/noteDoc.test.ts +514 -0
- package/tests/richTextHTML.test.ts +185 -0
- package/tests/sheetAxisMove.test.ts +352 -0
- package/tests/sheetBootstrap.test.ts +1967 -0
- package/tests/sheetFeatureReference.test.ts +22 -0
- package/tests/sheetFormulaCriteria.test.ts +269 -0
- package/tests/sheetFormulaEvaluator.test.ts +468 -0
- package/tests/sheetFormulaFunctions.test.ts +538 -0
- package/tests/sheetFormulaLanguage.test.ts +361 -0
- package/tests/sheetFormulaParity.fixtures.ts +872 -0
- package/tests/sheetFormulaParity.test.ts +188 -0
- package/tests/sheetFormulaRange.test.ts +167 -0
- package/tests/sheetFormulaReference.test.ts +78 -0
- package/tests/sheetFormulaReferenceRewrite.test.ts +117 -0
- package/tests/sheetFormulaTextDate.test.ts +512 -0
- package/tests/sheetSequence.test.ts +22 -0
- package/tests/sheetSnapshot.test.ts +134 -0
- package/tests/sheetStructureEdit.test.ts +537 -0
- package/tests/sheetStructureReferences.test.ts +589 -0
- package/tests/workflowLifecycleStatus.test.ts +60 -0
- package/tests/workflowLogFingerprint.test.ts +203 -0
- package/tests/workflowLogRevisionSnapshot.test.ts +96 -0
- package/tests/workflowProgress.test.ts +180 -0
- package/tests/workflowTriggers.test.ts +29 -0
- package/tsconfig.json +12 -0
- package/vitest.config.ts +8 -0
|
@@ -0,0 +1,519 @@
|
|
|
1
|
+
import { strict as assert } from 'node:assert';
|
|
2
|
+
import { QR_CODE_LIMITS, QR_CODE_PAYLOAD_VERSION } from '../constants/qrCode.ts';
|
|
3
|
+
import type { QrCodeField, QrCodePayload, QrCodePayloadField } from '../types/qrCode.d.ts';
|
|
4
|
+
import {
|
|
5
|
+
assertQrCodeStringEncoding,
|
|
6
|
+
decodeQrCodeText,
|
|
7
|
+
encodeQrCodeText,
|
|
8
|
+
isQrCodePublicId,
|
|
9
|
+
QrCodeCodecError,
|
|
10
|
+
validateQrCodeFields,
|
|
11
|
+
validateQrCodePayload,
|
|
12
|
+
} from './qrCode.ts';
|
|
13
|
+
|
|
14
|
+
const FILE_CONSTANTS = {
|
|
15
|
+
origin: 'https://example.test',
|
|
16
|
+
publicId: 'AAAAAAAAAAAAAAAAAAAAAA',
|
|
17
|
+
otherPublicId: 'BBBBBBBBBBBBBBBBBBBBBQ',
|
|
18
|
+
organizationId: '00012345678901234567',
|
|
19
|
+
createdAt: '2026-10-28T20:00:00.123Z',
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
/*
|
|
23
|
+
* Build a minimal snapshot with caller-supplied field values.
|
|
24
|
+
*/
|
|
25
|
+
function makePayload(fields: QrCodeField[] = [{ key: 'product', kind: 'VALUE', value: 'Broccoli' }]): QrCodePayload {
|
|
26
|
+
return { v: 1, publicId: FILE_CONSTANTS.publicId, fields };
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/*
|
|
30
|
+
* Build a current snapshot with required immutable metadata and optional readable references.
|
|
31
|
+
*/
|
|
32
|
+
function makeV3Payload(
|
|
33
|
+
fields: QrCodePayloadField[] = [{ key: 'product', kind: 'VALUE', value: 'Broccoli' }],
|
|
34
|
+
): Extract<QrCodePayload, { v: 3 }> {
|
|
35
|
+
return {
|
|
36
|
+
v: QR_CODE_PAYLOAD_VERSION,
|
|
37
|
+
publicId: FILE_CONSTANTS.publicId,
|
|
38
|
+
organizationId: FILE_CONSTANTS.organizationId,
|
|
39
|
+
createdAt: FILE_CONSTANTS.createdAt,
|
|
40
|
+
fields,
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/*
|
|
45
|
+
* Encode unchecked JSON so malformed input can reach the decoder independently.
|
|
46
|
+
*/
|
|
47
|
+
function makeUncheckedText(value: unknown, publicId = FILE_CONSTANTS.publicId, version = 1): string {
|
|
48
|
+
const bytes = new TextEncoder().encode(JSON.stringify(value));
|
|
49
|
+
const encoded = btoa(String.fromCharCode(...bytes))
|
|
50
|
+
.replace(/\+/g, '-')
|
|
51
|
+
.replace(/\//g, '_')
|
|
52
|
+
.replace(/=+$/, '');
|
|
53
|
+
return `${FILE_CONSTANTS.origin}/q/${publicId}#v${version}.${encoded}`;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/*
|
|
57
|
+
* Assert a classified codec failure rather than accepting an unrelated exception.
|
|
58
|
+
*/
|
|
59
|
+
function assertCodecError(run: () => unknown, code: QrCodeCodecError['code']) {
|
|
60
|
+
assert.throws(run, (error: unknown) => error instanceof QrCodeCodecError && error.code === code);
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/*
|
|
64
|
+
* Descriptions obey the text limit and reject unsupported field properties.
|
|
65
|
+
*/
|
|
66
|
+
Deno.test('QR descriptions enforce 120 characters and reject unsupported label properties', () => {
|
|
67
|
+
const unsupported = makeUncheckedText({
|
|
68
|
+
...makePayload(),
|
|
69
|
+
fields: [{ key: 'product', label: 'Old label', kind: 'VALUE', value: 'Broccoli' }],
|
|
70
|
+
});
|
|
71
|
+
assertCodecError(() => decodeQrCodeText(unsupported), 'INVALID');
|
|
72
|
+
assert.equal(
|
|
73
|
+
validateQrCodeFields([{ key: 'product', description: 'x'.repeat(120), kind: 'VALUE', value: 'ok' }])[0].description?.length,
|
|
74
|
+
120,
|
|
75
|
+
);
|
|
76
|
+
assertCodecError(
|
|
77
|
+
() => validateQrCodeFields([{ key: 'product', description: 'x'.repeat(121), kind: 'VALUE', value: 'ok' }]),
|
|
78
|
+
'INVALID',
|
|
79
|
+
);
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
/*
|
|
83
|
+
* Unicode text, numbers and booleans survive the same link used for offline scans.
|
|
84
|
+
*/
|
|
85
|
+
Deno.test('QR links round-trip text, numbers and booleans without network access', () => {
|
|
86
|
+
const payload = makePayload([
|
|
87
|
+
{ key: 'product', description: '品目', kind: 'VALUE', value: '브로콜리 🥦' },
|
|
88
|
+
{ key: 'quantity', kind: 'VALUE', value: 1.5 },
|
|
89
|
+
{ key: 'organic', kind: 'VALUE', value: true },
|
|
90
|
+
{ key: 'extra', kind: 'VALUE', value: 'Québec' },
|
|
91
|
+
]);
|
|
92
|
+
const text = encodeQrCodeText(FILE_CONSTANTS.origin, payload);
|
|
93
|
+
assert.match(text, /^https:\/\/example\.test\/q\/AAAAAAAAAAAAAAAAAAAAAA#v1\.[A-Za-z0-9_-]+$/);
|
|
94
|
+
assert.deepEqual(decodeQrCodeText(text), payload);
|
|
95
|
+
assert.deepEqual(payload.fields[3], { key: 'extra', kind: 'VALUE', value: 'Québec' });
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
/*
|
|
99
|
+
* App references retain opaque IDs and frozen display names without numeric coercion.
|
|
100
|
+
*/
|
|
101
|
+
Deno.test('QR references preserve large ID strings and display-name snapshots', () => {
|
|
102
|
+
const payload = makePayload([
|
|
103
|
+
{
|
|
104
|
+
key: 'siteLocation',
|
|
105
|
+
kind: 'REFERENCE',
|
|
106
|
+
reference: { type: 'ORGANIZATION_SITE', id: '9223372036854775807' },
|
|
107
|
+
displayNameSnapshot: 'West Field',
|
|
108
|
+
},
|
|
109
|
+
{
|
|
110
|
+
key: 'childOrg',
|
|
111
|
+
kind: 'REFERENCE',
|
|
112
|
+
reference: { type: 'CHILD_ORGANIZATION', id: '00012345678901234567' },
|
|
113
|
+
displayNameSnapshot: 'Crew A',
|
|
114
|
+
},
|
|
115
|
+
]);
|
|
116
|
+
const text = encodeQrCodeText(FILE_CONSTANTS.origin, payload);
|
|
117
|
+
assert.deepEqual(decodeQrCodeText(text), payload);
|
|
118
|
+
assert.equal(encodeQrCodeText(FILE_CONSTANTS.origin, decodeQrCodeText(text)), text);
|
|
119
|
+
});
|
|
120
|
+
|
|
121
|
+
/*
|
|
122
|
+
* New payloads preserve typed readable references, including the two-segment form used by large database identities.
|
|
123
|
+
*/
|
|
124
|
+
Deno.test('QR v2 references round-trip readable site and organization IDs without modifying scalar IDs', () => {
|
|
125
|
+
const payload: QrCodePayload = {
|
|
126
|
+
v: 2,
|
|
127
|
+
publicId: FILE_CONSTANTS.publicId,
|
|
128
|
+
fields: [
|
|
129
|
+
{
|
|
130
|
+
key: 'siteLocation',
|
|
131
|
+
kind: 'REFERENCE',
|
|
132
|
+
reference: { type: 'ORGANIZATION_SITE', id: 'site–99999–92233720368548' },
|
|
133
|
+
displayNameSnapshot: 'West Field',
|
|
134
|
+
},
|
|
135
|
+
{
|
|
136
|
+
key: 'childOrg',
|
|
137
|
+
kind: 'REFERENCE',
|
|
138
|
+
reference: { type: 'CHILD_ORGANIZATION', id: 'org-123456' },
|
|
139
|
+
displayNameSnapshot: 'Crew A',
|
|
140
|
+
},
|
|
141
|
+
{ key: 'accountId', kind: 'VALUE', value: '123' },
|
|
142
|
+
],
|
|
143
|
+
};
|
|
144
|
+
assert.deepEqual(validateQrCodePayload(payload), payload);
|
|
145
|
+
const text = encodeQrCodeText(FILE_CONSTANTS.origin, payload);
|
|
146
|
+
assert.match(text, /#v2\.[A-Za-z0-9_-]+$/);
|
|
147
|
+
assert.deepEqual(decodeQrCodeText(text), payload);
|
|
148
|
+
assert.equal(encodeQrCodeText(FILE_CONSTANTS.origin, decodeQrCodeText(text)), text);
|
|
149
|
+
assertCodecError(() => validateQrCodeFields(payload.fields), 'INVALID');
|
|
150
|
+
});
|
|
151
|
+
|
|
152
|
+
/*
|
|
153
|
+
* Newly issued codes carry their organization and canonical creation time without changing any literal or reference values.
|
|
154
|
+
*/
|
|
155
|
+
Deno.test('QR v3 round-trips required organization and creation metadata with readable references', () => {
|
|
156
|
+
assert.equal(QR_CODE_PAYLOAD_VERSION, 3);
|
|
157
|
+
const payload = makeV3Payload([
|
|
158
|
+
{
|
|
159
|
+
key: 'siteLocation',
|
|
160
|
+
kind: 'REFERENCE',
|
|
161
|
+
reference: { type: 'ORGANIZATION_SITE', id: 'site–123456' },
|
|
162
|
+
displayNameSnapshot: 'West Field',
|
|
163
|
+
},
|
|
164
|
+
{ key: 'accountId', kind: 'VALUE', value: '123' },
|
|
165
|
+
]);
|
|
166
|
+
assert.deepEqual(validateQrCodePayload(payload), payload);
|
|
167
|
+
const text = encodeQrCodeText(FILE_CONSTANTS.origin, payload);
|
|
168
|
+
assert.match(text, /#v3\.[A-Za-z0-9_-]+$/);
|
|
169
|
+
assert.deepEqual(decodeQrCodeText(text), payload);
|
|
170
|
+
assert.equal(encodeQrCodeText(FILE_CONSTANTS.origin, decodeQrCodeText(text)), text);
|
|
171
|
+
assertCodecError(() => decodeQrCodeText(text.replace('#v3.', '#v2.')), 'INVALID');
|
|
172
|
+
assertCodecError(
|
|
173
|
+
() =>
|
|
174
|
+
validateQrCodePayload({
|
|
175
|
+
...payload,
|
|
176
|
+
fields: [{ ...payload.fields[0], reference: { type: 'ORGANIZATION_SITE', id: '123' } }],
|
|
177
|
+
}),
|
|
178
|
+
'INVALID',
|
|
179
|
+
);
|
|
180
|
+
});
|
|
181
|
+
|
|
182
|
+
/*
|
|
183
|
+
* Organization identity is a positive bounded GenericID string, never a readable ID or a coerced number.
|
|
184
|
+
*/
|
|
185
|
+
Deno.test('QR v3 requires a positive decimal organization GenericID and preserves leading zeros', () => {
|
|
186
|
+
for (const organizationId of [undefined, null, 123, '', '0', '000', '-1', '+1', '1.5', 'org–123456', '123\n', '1'.repeat(41)]) {
|
|
187
|
+
const payload = { ...makeV3Payload(), organizationId };
|
|
188
|
+
assertCodecError(() => validateQrCodePayload(payload), 'INVALID');
|
|
189
|
+
assertCodecError(() => decodeQrCodeText(makeUncheckedText(payload, FILE_CONSTANTS.publicId, 3)), 'INVALID');
|
|
190
|
+
}
|
|
191
|
+
for (const organizationId of ['1', FILE_CONSTANTS.organizationId, '9'.repeat(40)]) {
|
|
192
|
+
const payload = { ...makeV3Payload(), organizationId };
|
|
193
|
+
assert.deepEqual(validateQrCodePayload(payload), payload);
|
|
194
|
+
}
|
|
195
|
+
});
|
|
196
|
+
|
|
197
|
+
/*
|
|
198
|
+
* A canonical UTC timestamp cannot silently normalize an invalid calendar date or a different ISO representation.
|
|
199
|
+
*/
|
|
200
|
+
Deno.test('QR v3 creation timestamps require valid exact Date.toISOString output', () => {
|
|
201
|
+
for (const createdAt of [
|
|
202
|
+
undefined,
|
|
203
|
+
null,
|
|
204
|
+
123,
|
|
205
|
+
new Date(FILE_CONSTANTS.createdAt),
|
|
206
|
+
'',
|
|
207
|
+
'not a date',
|
|
208
|
+
'2026-02-30T20:00:00.123Z',
|
|
209
|
+
'2026-13-28T20:00:00.123Z',
|
|
210
|
+
'2026-10-28T24:00:00.000Z',
|
|
211
|
+
'2026-10-28T20:00:00Z',
|
|
212
|
+
'2026-10-28T20:00:00.123+00:00',
|
|
213
|
+
'2026-10-28T16:00:00.123-04:00',
|
|
214
|
+
'2026-10-28T20:00:00.1230Z',
|
|
215
|
+
'2026-10-28T20:00:00.123z',
|
|
216
|
+
]) {
|
|
217
|
+
assertCodecError(() => validateQrCodePayload({ ...makeV3Payload(), createdAt }), 'INVALID');
|
|
218
|
+
}
|
|
219
|
+
for (const createdAt of [FILE_CONSTANTS.createdAt, '2024-02-29T00:00:00.000Z', '+010000-01-01T00:00:00.000Z']) {
|
|
220
|
+
const payload = { ...makeV3Payload(), createdAt };
|
|
221
|
+
assert.deepEqual(decodeQrCodeText(encodeQrCodeText(FILE_CONSTANTS.origin, payload)), payload);
|
|
222
|
+
}
|
|
223
|
+
});
|
|
224
|
+
|
|
225
|
+
/*
|
|
226
|
+
* Metadata belongs only to v3; legacy snapshots keep their exact shape and unknown keys remain rejected.
|
|
227
|
+
*/
|
|
228
|
+
Deno.test('QR payload metadata follows strict version-specific envelope keys', () => {
|
|
229
|
+
for (const v of [1, 2] as const) {
|
|
230
|
+
const legacy = { ...makePayload(), v };
|
|
231
|
+
const text = encodeQrCodeText(FILE_CONSTANTS.origin, legacy);
|
|
232
|
+
assert.deepEqual(decodeQrCodeText(text), legacy);
|
|
233
|
+
assert.equal(encodeQrCodeText(FILE_CONSTANTS.origin, decodeQrCodeText(text)), text);
|
|
234
|
+
assertCodecError(() => validateQrCodePayload({ ...legacy, organizationId: FILE_CONSTANTS.organizationId }), 'INVALID');
|
|
235
|
+
assertCodecError(() => validateQrCodePayload({ ...legacy, createdAt: FILE_CONSTANTS.createdAt }), 'INVALID');
|
|
236
|
+
}
|
|
237
|
+
assertCodecError(() => validateQrCodePayload({ ...makeV3Payload(), qrCodeId: '123' }), 'INVALID');
|
|
238
|
+
});
|
|
239
|
+
|
|
240
|
+
/*
|
|
241
|
+
* Wire versions use different reference formats; neither may accept an untyped or mismatched ID.
|
|
242
|
+
*/
|
|
243
|
+
Deno.test('QR v2 rejects numeric IDs, mismatched prefixes and malformed readable references', () => {
|
|
244
|
+
const reference = {
|
|
245
|
+
key: 'siteLocation',
|
|
246
|
+
kind: 'REFERENCE',
|
|
247
|
+
reference: { type: 'ORGANIZATION_SITE', id: 'site–123456' },
|
|
248
|
+
displayNameSnapshot: 'West Field',
|
|
249
|
+
};
|
|
250
|
+
for (const id of [
|
|
251
|
+
'123456789012345',
|
|
252
|
+
123,
|
|
253
|
+
'org–123456',
|
|
254
|
+
'qr–123456',
|
|
255
|
+
'site-',
|
|
256
|
+
'site--123',
|
|
257
|
+
'site-123-',
|
|
258
|
+
'site-1-2-3',
|
|
259
|
+
'site-123\n',
|
|
260
|
+
`site-${'1'.repeat(40)}`,
|
|
261
|
+
]) {
|
|
262
|
+
const payload = {
|
|
263
|
+
v: 2,
|
|
264
|
+
publicId: FILE_CONSTANTS.publicId,
|
|
265
|
+
fields: [{ ...reference, reference: { type: 'ORGANIZATION_SITE', id } }],
|
|
266
|
+
};
|
|
267
|
+
assertCodecError(() => validateQrCodePayload(payload), 'INVALID');
|
|
268
|
+
assertCodecError(() => decodeQrCodeText(makeUncheckedText(payload, FILE_CONSTANTS.publicId, 2)), 'INVALID');
|
|
269
|
+
}
|
|
270
|
+
assertCodecError(() => validateQrCodePayload({ v: 1, publicId: FILE_CONSTANTS.publicId, fields: [reference] }), 'INVALID');
|
|
271
|
+
assertCodecError(
|
|
272
|
+
() => validateQrCodePayload({ v: 2, publicId: FILE_CONSTANTS.publicId, fields: [{ ...reference, key: 'childOrg' }] }),
|
|
273
|
+
'INVALID',
|
|
274
|
+
);
|
|
275
|
+
for (const dash of ['-', '‐', '‑', '‒', '–', '—', '―', '−']) {
|
|
276
|
+
const payload = {
|
|
277
|
+
v: 2,
|
|
278
|
+
publicId: FILE_CONSTANTS.publicId,
|
|
279
|
+
fields: [{ ...reference, reference: { type: 'ORGANIZATION_SITE', id: `site${dash}123456` } }],
|
|
280
|
+
};
|
|
281
|
+
assert.deepEqual(validateQrCodePayload(payload), payload);
|
|
282
|
+
}
|
|
283
|
+
});
|
|
284
|
+
|
|
285
|
+
/*
|
|
286
|
+
* Only canonical 16-byte public tokens can identify issued codes.
|
|
287
|
+
*/
|
|
288
|
+
Deno.test('QR public IDs require canonical 128-bit base64url tokens', () => {
|
|
289
|
+
assert.equal(isQrCodePublicId(FILE_CONSTANTS.publicId), true);
|
|
290
|
+
assert.equal(isQrCodePublicId(FILE_CONSTANTS.otherPublicId), true);
|
|
291
|
+
for (const invalid of [
|
|
292
|
+
'',
|
|
293
|
+
'short',
|
|
294
|
+
'AAAAAAAAAAAAAAAAAAAAAB',
|
|
295
|
+
'AAAAAAAAAAAAAAAAAAAAAA==',
|
|
296
|
+
`${FILE_CONSTANTS.publicId}\n`,
|
|
297
|
+
null,
|
|
298
|
+
123,
|
|
299
|
+
]) {
|
|
300
|
+
assert.equal(isQrCodePublicId(invalid), false);
|
|
301
|
+
}
|
|
302
|
+
});
|
|
303
|
+
|
|
304
|
+
/*
|
|
305
|
+
* References must use the approved entity kinds, string IDs, and captured names.
|
|
306
|
+
*/
|
|
307
|
+
Deno.test('QR field validation rejects malformed references and inconsistent envelope shapes', () => {
|
|
308
|
+
const reference = {
|
|
309
|
+
key: 'siteLocation',
|
|
310
|
+
kind: 'REFERENCE',
|
|
311
|
+
reference: { type: 'ORGANIZATION_SITE', id: '123' },
|
|
312
|
+
displayNameSnapshot: 'West Field',
|
|
313
|
+
};
|
|
314
|
+
for (const invalid of [
|
|
315
|
+
{ ...reference, displayNameSnapshot: '' },
|
|
316
|
+
{ ...reference, displayNameSnapshot: undefined },
|
|
317
|
+
{ ...reference, reference: { type: 'OTHER_TABLE', id: '123' } },
|
|
318
|
+
{ ...reference, reference: { type: 'ORGANIZATION_SITE', id: 123 } },
|
|
319
|
+
{ ...reference, reference: { type: 'ORGANIZATION_SITE', id: 'site-123' } },
|
|
320
|
+
{ ...reference, reference: { type: 'ORGANIZATION_SITE', id: '123\n' } },
|
|
321
|
+
{ ...reference, reference: { type: 'ORGANIZATION_SITE', id: '123', arbitrary: true } },
|
|
322
|
+
{ ...reference, value: 'unexpected' },
|
|
323
|
+
{ key: 'product', kind: 'VALUE', value: 'Broccoli', reference: reference.reference },
|
|
324
|
+
{ key: 'product', kind: 'OTHER', value: 'Broccoli' },
|
|
325
|
+
]) {
|
|
326
|
+
assertCodecError(() => validateQrCodeFields([invalid]), 'INVALID');
|
|
327
|
+
}
|
|
328
|
+
});
|
|
329
|
+
|
|
330
|
+
/*
|
|
331
|
+
* Reserved app fields retain typed IDs while custom field names remain unrestricted.
|
|
332
|
+
*/
|
|
333
|
+
Deno.test('QR app field keys require matching reference types without constraining custom keys', () => {
|
|
334
|
+
for (const key of ['siteLocation', 'childOrg']) {
|
|
335
|
+
assertCodecError(() => validateQrCodeFields([{ key, kind: 'VALUE', value: 'Display name only' }]), 'INVALID');
|
|
336
|
+
assertCodecError(() => validateQrCodeFields([{ key, kind: 'VALUE', value: '123' }]), 'INVALID');
|
|
337
|
+
const wrongType = key === 'siteLocation' ? 'CHILD_ORGANIZATION' : 'ORGANIZATION_SITE';
|
|
338
|
+
assertCodecError(
|
|
339
|
+
() => validateQrCodeFields([{ key, kind: 'REFERENCE', reference: { type: wrongType, id: '123' }, displayNameSnapshot: 'Name' }]),
|
|
340
|
+
'INVALID',
|
|
341
|
+
);
|
|
342
|
+
}
|
|
343
|
+
const fields: QrCodeField[] = [
|
|
344
|
+
{ key: 'siteLocationLabel', kind: 'VALUE', value: 'West Field' },
|
|
345
|
+
{ key: 'product', kind: 'VALUE', value: 'Broccoli' },
|
|
346
|
+
{ key: 'constructor', kind: 'VALUE', value: false },
|
|
347
|
+
{ key: '__proto__', kind: 'VALUE', value: 'safe text' },
|
|
348
|
+
{ key: 'warehouse', kind: 'REFERENCE', reference: { type: 'ORGANIZATION_SITE', id: '123' }, displayNameSnapshot: 'Warehouse' },
|
|
349
|
+
];
|
|
350
|
+
assert.deepEqual(validateQrCodeFields(fields), fields);
|
|
351
|
+
assert.deepEqual(decodeQrCodeText(encodeQrCodeText(FILE_CONSTANTS.origin, makePayload(fields))).fields, fields);
|
|
352
|
+
});
|
|
353
|
+
|
|
354
|
+
/*
|
|
355
|
+
* Field keys are unique, meaningful, and bounded before any JSON traversal.
|
|
356
|
+
*/
|
|
357
|
+
Deno.test('QR validation rejects duplicate, empty, and oversized field envelopes', () => {
|
|
358
|
+
for (const invalid of [
|
|
359
|
+
[],
|
|
360
|
+
null,
|
|
361
|
+
[{ key: ' ', kind: 'VALUE', value: null }],
|
|
362
|
+
[{ key: 'a'.repeat(QR_CODE_LIMITS.fieldKeyLength + 1), kind: 'VALUE', value: null }],
|
|
363
|
+
[
|
|
364
|
+
{ key: 'product', kind: 'VALUE', value: null },
|
|
365
|
+
{ key: 'product', kind: 'VALUE', value: 'Broccoli' },
|
|
366
|
+
],
|
|
367
|
+
]) {
|
|
368
|
+
assertCodecError(() => validateQrCodeFields(invalid), 'INVALID');
|
|
369
|
+
}
|
|
370
|
+
});
|
|
371
|
+
|
|
372
|
+
/*
|
|
373
|
+
* Non-JSON runtime values must not be silently dropped or coerced while creating codes.
|
|
374
|
+
*/
|
|
375
|
+
Deno.test('QR validation rejects undefined, nonfinite numbers, sparse arrays, and custom objects', () => {
|
|
376
|
+
for (const value of [undefined, NaN, Infinity, 1n, new Date(), [undefined], new Array(2), { value: undefined }]) {
|
|
377
|
+
assertCodecError(() => validateQrCodeFields([{ key: 'extra', kind: 'VALUE', value }]), 'INVALID');
|
|
378
|
+
}
|
|
379
|
+
});
|
|
380
|
+
|
|
381
|
+
/*
|
|
382
|
+
* Every stored or printed string must preserve its meaning through JSONB and UTF-8.
|
|
383
|
+
*/
|
|
384
|
+
Deno.test('QR validation rejects NUL and lone surrogates in values, object keys, and field text', () => {
|
|
385
|
+
for (const invalid of ['\0', '\ud800', '\udc00', 'a\ud800b', '\udc00\ud800']) {
|
|
386
|
+
assertCodecError(() => assertQrCodeStringEncoding(invalid), 'INVALID');
|
|
387
|
+
assertCodecError(() => validateQrCodeFields([{ key: 'extra', kind: 'VALUE', value: invalid }]), 'INVALID');
|
|
388
|
+
assertCodecError(() => validateQrCodeFields([{ key: 'extra', kind: 'VALUE', value: { [invalid]: 'x' } }]), 'INVALID');
|
|
389
|
+
assertCodecError(() => validateQrCodeFields([{ key: `key${invalid}`, kind: 'VALUE', value: null }]), 'INVALID');
|
|
390
|
+
assertCodecError(
|
|
391
|
+
() => validateQrCodeFields([{ key: 'extra', description: `Label${invalid}`, kind: 'VALUE', value: null }]),
|
|
392
|
+
'INVALID',
|
|
393
|
+
);
|
|
394
|
+
assertCodecError(
|
|
395
|
+
() =>
|
|
396
|
+
validateQrCodeFields([
|
|
397
|
+
{
|
|
398
|
+
key: 'siteLocation',
|
|
399
|
+
kind: 'REFERENCE',
|
|
400
|
+
reference: { type: 'ORGANIZATION_SITE', id: '123' },
|
|
401
|
+
displayNameSnapshot: `West${invalid}`,
|
|
402
|
+
},
|
|
403
|
+
]),
|
|
404
|
+
'INVALID',
|
|
405
|
+
);
|
|
406
|
+
assertCodecError(
|
|
407
|
+
() => decodeQrCodeText(makeUncheckedText(makePayload([{ key: 'extra', kind: 'VALUE', value: invalid }]))),
|
|
408
|
+
'INVALID',
|
|
409
|
+
);
|
|
410
|
+
}
|
|
411
|
+
assert.doesNotThrow(() => assertQrCodeStringEncoding('🥦\ud83d\ude00'));
|
|
412
|
+
assert.doesNotThrow(() => assertQrCodeStringEncoding('\\u0000'));
|
|
413
|
+
});
|
|
414
|
+
|
|
415
|
+
/*
|
|
416
|
+
* Structured values and null are rejected rather than retained as JSON field values.
|
|
417
|
+
*/
|
|
418
|
+
Deno.test('QR validation rejects JSON objects, arrays, null and cyclic values', () => {
|
|
419
|
+
const cyclic: Record<string, unknown> = {};
|
|
420
|
+
cyclic.self = cyclic;
|
|
421
|
+
for (const value of [{}, [], { nested: [true] }, null, cyclic]) {
|
|
422
|
+
assertCodecError(() => validateQrCodeFields([{ key: 'extra', kind: 'VALUE', value }]), 'INVALID');
|
|
423
|
+
}
|
|
424
|
+
assertCodecError(
|
|
425
|
+
() => validateQrCodeFields(new Array(QR_CODE_LIMITS.maxFields + 1).fill({ key: 'extra', kind: 'VALUE', value: '' })),
|
|
426
|
+
'TOO_LARGE',
|
|
427
|
+
);
|
|
428
|
+
});
|
|
429
|
+
|
|
430
|
+
/*
|
|
431
|
+
* Size validation includes the origin, path, and base64 overhead of the final scanned text.
|
|
432
|
+
*/
|
|
433
|
+
Deno.test('QR encoding and decoding enforce the final 2000-byte text limit', () => {
|
|
434
|
+
const fields: QrCodeField[] = Array.from({ length: 6 }, (_, index) => ({
|
|
435
|
+
key: `field${index}`,
|
|
436
|
+
kind: 'VALUE',
|
|
437
|
+
value: 'a'.repeat(230),
|
|
438
|
+
}));
|
|
439
|
+
assert.doesNotThrow(() => validateQrCodeFields(fields));
|
|
440
|
+
assertCodecError(() => encodeQrCodeText(FILE_CONSTANTS.origin, makePayload(fields)), 'TOO_LARGE');
|
|
441
|
+
assertCodecError(() => decodeQrCodeText('a'.repeat(QR_CODE_LIMITS.maxTextBytes + 1)), 'TOO_LARGE');
|
|
442
|
+
assertCodecError(() => validateQrCodeFields([{ key: 'extra', kind: 'VALUE', value: '🥦'.repeat(600) }]), 'TOO_LARGE');
|
|
443
|
+
const compact = makePayload([{ key: 'extra', kind: 'VALUE', value: 'a'.repeat(255) }]);
|
|
444
|
+
assert.deepEqual(decodeQrCodeText(encodeQrCodeText(FILE_CONSTANTS.origin, compact)), compact);
|
|
445
|
+
});
|
|
446
|
+
|
|
447
|
+
/*
|
|
448
|
+
* Version markers on both the URL and payload must agree with the supported contract.
|
|
449
|
+
*/
|
|
450
|
+
Deno.test('QR decoding rejects unknown fragment or payload versions', () => {
|
|
451
|
+
const text = encodeQrCodeText(FILE_CONSTANTS.origin, makePayload());
|
|
452
|
+
assertCodecError(() => decodeQrCodeText(text.replace('#v1.', '#v4.')), 'UNSUPPORTED_VERSION');
|
|
453
|
+
assertCodecError(() => decodeQrCodeText(makeUncheckedText({ ...makePayload(), v: 4 })), 'UNSUPPORTED_VERSION');
|
|
454
|
+
assertCodecError(() => decodeQrCodeText(text.replace('#v1.', '#v2.')), 'INVALID');
|
|
455
|
+
assertCodecError(() => decodeQrCodeText(makeUncheckedText({ ...makePayload(), v: 2 })), 'INVALID');
|
|
456
|
+
const current = encodeQrCodeText(FILE_CONSTANTS.origin, { ...makePayload(), v: 2 });
|
|
457
|
+
assertCodecError(() => decodeQrCodeText(current.replace('#v2.', '#v1.')), 'INVALID');
|
|
458
|
+
});
|
|
459
|
+
|
|
460
|
+
/*
|
|
461
|
+
* Online lookup identity cannot be substituted independently of the offline payload.
|
|
462
|
+
*/
|
|
463
|
+
Deno.test('QR decoding rejects public token mismatches and unexpected payload fields', () => {
|
|
464
|
+
assertCodecError(() => decodeQrCodeText(makeUncheckedText(makePayload(), FILE_CONSTANTS.otherPublicId)), 'INVALID');
|
|
465
|
+
assertCodecError(() => decodeQrCodeText(makeUncheckedText({ ...makePayload(), organizationId: '123' })), 'INVALID');
|
|
466
|
+
assertCodecError(() => decodeQrCodeText(makeUncheckedText({ ...makePayload(), publicId: 'short' })), 'INVALID');
|
|
467
|
+
});
|
|
468
|
+
|
|
469
|
+
/*
|
|
470
|
+
* Invalid base64, malformed JSON, and invalid UTF-8 never produce partially decoded values.
|
|
471
|
+
*/
|
|
472
|
+
Deno.test('QR decoding rejects malformed payload encodings', () => {
|
|
473
|
+
for (const fragment of ['A', 'AA=', '!!!!', 'e30', '_w', 'bm90LWpzb24', 'e31']) {
|
|
474
|
+
assertCodecError(() => decodeQrCodeText(`${FILE_CONSTANTS.origin}/q/${FILE_CONSTANTS.publicId}#v1.${fragment}`), 'INVALID');
|
|
475
|
+
}
|
|
476
|
+
});
|
|
477
|
+
|
|
478
|
+
/*
|
|
479
|
+
* Production links require HTTPS, while local development can use loopback HTTP.
|
|
480
|
+
*/
|
|
481
|
+
Deno.test('QR URLs reject credentials, queries, foreign paths, and insecure nonloopback origins', () => {
|
|
482
|
+
for (const origin of [
|
|
483
|
+
'https://user:secret@example.test',
|
|
484
|
+
'https://example.test/app',
|
|
485
|
+
'https://example.test?x=1',
|
|
486
|
+
'http://example.test',
|
|
487
|
+
]) {
|
|
488
|
+
assertCodecError(() => encodeQrCodeText(origin, makePayload()), 'INVALID');
|
|
489
|
+
}
|
|
490
|
+
for (const origin of ['http://localhost:3005', 'http://127.0.0.1:3005', 'http://[::1]:3005']) {
|
|
491
|
+
assert.deepEqual(decodeQrCodeText(encodeQrCodeText(origin, makePayload())), makePayload());
|
|
492
|
+
}
|
|
493
|
+
const text = encodeQrCodeText(FILE_CONSTANTS.origin, makePayload());
|
|
494
|
+
assertCodecError(() => decodeQrCodeText(text.replace('/q/', '/other/')), 'INVALID');
|
|
495
|
+
assertCodecError(() => decodeQrCodeText(text.replace('#v1.', '?tracking=1#v1.')), 'INVALID');
|
|
496
|
+
assertCodecError(() => decodeQrCodeText(` ${text}`), 'INVALID');
|
|
497
|
+
});
|
|
498
|
+
|
|
499
|
+
/*
|
|
500
|
+
* Text field limits are enforced independently of the aggregate QR capacity.
|
|
501
|
+
*/
|
|
502
|
+
Deno.test('QR text values accept 255 characters and reject 256', () => {
|
|
503
|
+
const payload = makePayload([{ key: 'notes', kind: 'VALUE', value: 'x'.repeat(255) }]);
|
|
504
|
+
assert.deepEqual(decodeQrCodeText(encodeQrCodeText(FILE_CONSTANTS.origin, payload)), payload);
|
|
505
|
+
assertCodecError(() => validateQrCodeFields([{ key: 'notes', kind: 'VALUE', value: 'x'.repeat(256) }]), 'TOO_LARGE');
|
|
506
|
+
});
|
|
507
|
+
|
|
508
|
+
/*
|
|
509
|
+
* Missing text is invalid, but zero and false remain meaningful scalar values.
|
|
510
|
+
*/
|
|
511
|
+
Deno.test('QR field values reject empty text while preserving zero and false', () => {
|
|
512
|
+
for (const value of ['', ' ', '\t\n', '\u00a0']) {
|
|
513
|
+
assertCodecError(() => validateQrCodeFields([{ key: 'value', kind: 'VALUE', value }]), 'INVALID');
|
|
514
|
+
}
|
|
515
|
+
for (const value of [0, false, ' padded text ']) {
|
|
516
|
+
const payload = makePayload([{ key: 'value', kind: 'VALUE', value }]);
|
|
517
|
+
assert.deepEqual(decodeQrCodeText(encodeQrCodeText(FILE_CONSTANTS.origin, payload)), payload);
|
|
518
|
+
}
|
|
519
|
+
});
|