@jini-ai/cms-forms 0.2.1 → 0.2.3
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/CHANGELOG.md +10 -0
- package/dist/forms.js +13 -3
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/ports.d.ts +6 -0
- package/dist/submission-ip-retention.d.ts +30 -0
- package/dist/submission-ip-retention.js +27 -0
- package/dist/submit-service.d.ts +3 -1
- package/dist/submit-service.js +9 -4
- package/dist/types.d.ts +4 -1
- package/package.json +3 -3
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,15 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.2.3 — 2026-10-05
|
|
4
|
+
|
|
5
|
+
- `submitForm` takes an optional `transaction` port (`SubmissionTransactionPort`): the submission row and its `form.submission.received` event are written inside it, so a failed enqueue rolls the row back instead of leaving a stored submission that never notifies. Dispatch starts only after it commits. Without the port the two writes run back to back, as before.
|
|
6
|
+
- Requires `@jini-ai/cms` ^0.5.0 and `@jini-ai/core` ^0.4.1 (the versions released alongside it).
|
|
7
|
+
|
|
8
|
+
## 0.2.2 — 2026-10-04
|
|
9
|
+
|
|
10
|
+
- Authored checkbox values (`checkboxValue`).
|
|
11
|
+
- `sweepExpiredSubmissionIps` clears form-submitter IP addresses after 90 days.
|
|
12
|
+
|
|
3
13
|
## 0.2.1 — 2026-10-04
|
|
4
14
|
|
|
5
15
|
- `@jini-ai/cms` and `@jini-ai/core` are caret ranges (`^0.4.1`, `^0.4.0`) instead of exact pins, so a host on a newer patch of either resolves a single copy without an override.
|
package/dist/forms.js
CHANGED
|
@@ -59,6 +59,14 @@ function maxLengthErrors(descriptor, label) {
|
|
|
59
59
|
}
|
|
60
60
|
return [];
|
|
61
61
|
}
|
|
62
|
+
function checkboxValueErrors(descriptor, label) {
|
|
63
|
+
if (descriptor.checkboxValue === undefined)
|
|
64
|
+
return [];
|
|
65
|
+
if (descriptor.type !== "checkbox" || typeof descriptor.checkboxValue !== "string") {
|
|
66
|
+
return [{ field: label, reason: "checkboxValue must be a string on a checkbox field" }];
|
|
67
|
+
}
|
|
68
|
+
return [];
|
|
69
|
+
}
|
|
62
70
|
// HTML-escaped class names are inert; only their length is bounded. Check type defensively
|
|
63
71
|
// because real inputs include parsed request bodies, regardless of the descriptor's static type.
|
|
64
72
|
function classNameErrors(descriptor, label) {
|
|
@@ -120,7 +128,7 @@ export function validateFieldDescriptors({ fields }) {
|
|
|
120
128
|
const claimedIds = new Set();
|
|
121
129
|
for (const descriptor of fields) {
|
|
122
130
|
const label = descriptor.id || "(unknown)";
|
|
123
|
-
fieldErrors.push(...fieldIdErrors(descriptor, label, claimedIds), ...fieldTypeErrors(descriptor, label), ...labelLengthErrors(descriptor, label), ...maxLengthErrors(descriptor, label), ...classNameErrors(descriptor, label), ...attributeErrors(descriptor, label));
|
|
131
|
+
fieldErrors.push(...fieldIdErrors(descriptor, label, claimedIds), ...fieldTypeErrors(descriptor, label), ...labelLengthErrors(descriptor, label), ...maxLengthErrors(descriptor, label), ...checkboxValueErrors(descriptor, label), ...classNameErrors(descriptor, label), ...attributeErrors(descriptor, label));
|
|
124
132
|
}
|
|
125
133
|
if (fieldErrors.length > 0)
|
|
126
134
|
return { valid: false, fieldErrors };
|
|
@@ -153,7 +161,9 @@ function resolveTextValue(field, value) {
|
|
|
153
161
|
// only JSON booleans would reject every checked checkbox when client JavaScript is disabled.
|
|
154
162
|
// An unticked native checkbox omits its key; submission resolution treats that as absence.
|
|
155
163
|
const HTML_CHECKBOX_ON_VALUE = "on";
|
|
156
|
-
function resolveCheckboxValue(value) {
|
|
164
|
+
function resolveCheckboxValue(field, value) {
|
|
165
|
+
if (field.checkboxValue !== undefined && typeof value === "string")
|
|
166
|
+
return { kind: "accepted", value };
|
|
157
167
|
if (typeof value === "boolean")
|
|
158
168
|
return { kind: "accepted", value };
|
|
159
169
|
if (value === HTML_CHECKBOX_ON_VALUE)
|
|
@@ -167,7 +177,7 @@ function resolveSubmittedValue(field, value) {
|
|
|
167
177
|
return field.required ? { kind: "rejected", reason: "required" } : { kind: "absent" };
|
|
168
178
|
}
|
|
169
179
|
if (field.type === "checkbox")
|
|
170
|
-
return resolveCheckboxValue(value);
|
|
180
|
+
return resolveCheckboxValue(field, value);
|
|
171
181
|
return resolveTextValue(field, value);
|
|
172
182
|
}
|
|
173
183
|
/**
|
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
package/dist/ports.d.ts
CHANGED
|
@@ -65,6 +65,12 @@ export interface RateLimiterPort {
|
|
|
65
65
|
export interface FormOutboxPort {
|
|
66
66
|
enqueue(event: import("@jini-ai/cms/core").DomainEvent): Promise<void>;
|
|
67
67
|
}
|
|
68
|
+
/**
|
|
69
|
+
* Runs `work` as one unit of persistence: commit when it resolves, roll back when it throws. A host
|
|
70
|
+
* binds its database transaction here so an accepted submission's row and its outbox event are
|
|
71
|
+
* written together; a submission stored without its event would never notify anyone.
|
|
72
|
+
*/
|
|
73
|
+
export type SubmissionTransactionPort = <T>(work: () => Promise<T>) => Promise<T>;
|
|
68
74
|
/** Bound to the host's outbox/bus/clock; dispatch is kicked off without awaiting delivery. */
|
|
69
75
|
export interface OutboxDispatcherPort {
|
|
70
76
|
dispatch(required: Record<string, never>): Promise<void>;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Submission metadata retention, independent of databases and host scheduling.
|
|
3
|
+
* Answers and submission identity are never deleted by this maintenance operation.
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* Owner decision 2026-10-04: retain form submitter IPs for 90 days for abuse investigation,
|
|
7
|
+
* then remove them automatically. Matches the privacy wording: "IP addresses on form
|
|
8
|
+
* submissions are deleted after 90 days"; this is not expiry of the submission itself.
|
|
9
|
+
*/
|
|
10
|
+
export declare const SUBMISSION_IP_RETENTION_DAYS = 90;
|
|
11
|
+
export interface SubmissionIpRetentionPort {
|
|
12
|
+
/**
|
|
13
|
+
* Clear only sourceIp to NULL for at most limit rows submitted at/before the ISO UTC cutoff.
|
|
14
|
+
* Include all workspaces and Trash rows. Perform one atomic guarded update; return actual
|
|
15
|
+
* affected rows, excluding already-NULL values. Concurrent passes must be idempotent.
|
|
16
|
+
*/
|
|
17
|
+
clearExpiredIps(required: {
|
|
18
|
+
submittedBeforeOrAt: string;
|
|
19
|
+
}, optional?: {
|
|
20
|
+
limit?: number;
|
|
21
|
+
}): Promise<number>;
|
|
22
|
+
}
|
|
23
|
+
/** A complete pass, using bounded updates and one fixed cutoff even across multiple batches. */
|
|
24
|
+
export declare function sweepExpiredSubmissionIps({ now, repo }: {
|
|
25
|
+
now: number;
|
|
26
|
+
repo: SubmissionIpRetentionPort;
|
|
27
|
+
}, { batchSize }?: {
|
|
28
|
+
batchSize?: number;
|
|
29
|
+
}): Promise<number>;
|
|
30
|
+
//# sourceMappingURL=submission-ip-retention.d.ts.map
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Submission metadata retention, independent of databases and host scheduling.
|
|
3
|
+
* Answers and submission identity are never deleted by this maintenance operation.
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* Owner decision 2026-10-04: retain form submitter IPs for 90 days for abuse investigation,
|
|
7
|
+
* then remove them automatically. Matches the privacy wording: "IP addresses on form
|
|
8
|
+
* submissions are deleted after 90 days"; this is not expiry of the submission itself.
|
|
9
|
+
*/
|
|
10
|
+
export const SUBMISSION_IP_RETENTION_DAYS = 90;
|
|
11
|
+
/** A complete pass, using bounded updates and one fixed cutoff even across multiple batches. */
|
|
12
|
+
export async function sweepExpiredSubmissionIps({ now, repo }, { batchSize = 500 } = {}) {
|
|
13
|
+
const cutoff = now - SUBMISSION_IP_RETENTION_DAYS * 24 * 60 * 60 * 1000;
|
|
14
|
+
if (!Number.isFinite(now) || !Number.isFinite(new Date(cutoff).getTime()))
|
|
15
|
+
throw new RangeError("submission IP sweep needs a valid timestamp");
|
|
16
|
+
if (!Number.isSafeInteger(batchSize) || batchSize <= 0)
|
|
17
|
+
throw new RangeError("submission IP sweep batchSize must be a positive integer");
|
|
18
|
+
const submittedBeforeOrAt = new Date(cutoff).toISOString();
|
|
19
|
+
let total = 0;
|
|
20
|
+
let cleared;
|
|
21
|
+
do {
|
|
22
|
+
cleared = await repo.clearExpiredIps({ submittedBeforeOrAt }, { limit: batchSize });
|
|
23
|
+
total += cleared;
|
|
24
|
+
} while (cleared === batchSize);
|
|
25
|
+
return total;
|
|
26
|
+
}
|
|
27
|
+
//# sourceMappingURL=submission-ip-retention.js.map
|
package/dist/submit-service.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { Logger } from "@jini-ai/core/primitives";
|
|
2
|
-
import type { RateLimiterPort, FormOutboxPort, OutboxDispatcherPort } from "./ports.js";
|
|
2
|
+
import type { RateLimiterPort, FormOutboxPort, OutboxDispatcherPort, SubmissionTransactionPort } from "./ports.js";
|
|
3
3
|
import type { Clock, IdGenerator, UUID } from "@jini-ai/core/primitives";
|
|
4
4
|
import type { FormDefinitionRepoPort, FormSubmissionRepoPort } from "./ports.js";
|
|
5
5
|
export interface SubmitFormDeps {
|
|
@@ -11,6 +11,8 @@ export interface SubmitFormDeps {
|
|
|
11
11
|
clock: Clock;
|
|
12
12
|
idGen: IdGenerator;
|
|
13
13
|
rateLimiter: RateLimiterPort;
|
|
14
|
+
/** Omitted: the two writes run back to back with no rollback between them. */
|
|
15
|
+
transaction?: SubmissionTransactionPort;
|
|
14
16
|
}
|
|
15
17
|
export interface SubmitFormInput {
|
|
16
18
|
workspaceId: UUID;
|
package/dist/submit-service.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { nowIso as kernelNowIso } from "@jini-ai/core/primitives";
|
|
2
|
-
/** Anonymous submission path: active lookup, honeypot, validation, rate check, persistence
|
|
2
|
+
/** Anonymous submission path: active lookup, honeypot, validation, rate check, persistence + event enqueue in one host transaction, then background dispatch. */
|
|
3
3
|
import { buildFormsRateLimitKey } from "./rate-limit-key.js";
|
|
4
4
|
import { FormDefinitionNotFoundError, FormRateLimitExceededError, FormSubmissionValidationError, } from "./errors.js";
|
|
5
5
|
import { isHoneypotTripped, validateSubmissionPayload } from "./forms.js";
|
|
@@ -38,15 +38,20 @@ export async function submitForm(required) {
|
|
|
38
38
|
sourceIp: input.sourceIp,
|
|
39
39
|
submittedAt: now,
|
|
40
40
|
};
|
|
41
|
-
|
|
42
|
-
// Only a persisted accepted submission gets this event; honeypot discards emit nothing.
|
|
43
|
-
await deps.outbox.enqueue({
|
|
41
|
+
const event = {
|
|
44
42
|
id: deps.idGen.newId(),
|
|
45
43
|
name: "form.submission.received",
|
|
46
44
|
occurredAt: now,
|
|
47
45
|
workspaceId: input.workspaceId,
|
|
48
46
|
aggregateId: submissionId,
|
|
49
47
|
payload: { workspaceId: input.workspaceId, formDefinitionId: definition.id, submissionId },
|
|
48
|
+
};
|
|
49
|
+
// Only a persisted accepted submission gets this event; honeypot discards emit nothing. Row and
|
|
50
|
+
// event commit together: a failed enqueue must not leave a stored submission nobody is told about.
|
|
51
|
+
const transaction = deps.transaction ?? ((work) => work());
|
|
52
|
+
await transaction(async () => {
|
|
53
|
+
await deps.submissionRepo.create(submission);
|
|
54
|
+
await deps.outbox.enqueue(event);
|
|
50
55
|
});
|
|
51
56
|
// Dispatch failures cannot affect an accepted submission or create an unhandled rejection.
|
|
52
57
|
// Never await delivery here: a subscriber sends mail, so awaiting it would reintroduce the
|
package/dist/types.d.ts
CHANGED
|
@@ -7,6 +7,8 @@ export interface FieldDescriptor {
|
|
|
7
7
|
type: FieldType;
|
|
8
8
|
required: boolean;
|
|
9
9
|
maxLength?: number | null;
|
|
10
|
+
/** Presence distinguishes an authored checkbox value (even "") from the native boolean default. */
|
|
11
|
+
checkboxValue?: string;
|
|
10
12
|
/** Length-bounded and HTML-escaped at rendering; class names are inert after escaping. */
|
|
11
13
|
className?: string;
|
|
12
14
|
/** Attribute names require a closed allowlist: escaping a name cannot make it safe.
|
|
@@ -36,7 +38,8 @@ export interface FormSubmissionRecord {
|
|
|
36
38
|
workspaceId: UUID;
|
|
37
39
|
formDefinitionId: UUID;
|
|
38
40
|
data: Record<string, string | boolean>;
|
|
39
|
-
|
|
41
|
+
/** Cleared by metadata retention; answers and the submission itself remain. */
|
|
42
|
+
sourceIp: string | null;
|
|
40
43
|
submittedAt: string;
|
|
41
44
|
}
|
|
42
45
|
export interface FormSubmissionPage {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jini-ai/cms-forms",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.3",
|
|
4
4
|
"description": "Framework-free configurable form validation, audited definitions, anonymous submissions and notification services with injected host ports.",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"repository": {
|
|
@@ -37,8 +37,8 @@
|
|
|
37
37
|
"!dist/**/*.map"
|
|
38
38
|
],
|
|
39
39
|
"dependencies": {
|
|
40
|
-
"@jini-ai/
|
|
41
|
-
"@jini-ai/
|
|
40
|
+
"@jini-ai/cms": "^0.5.0",
|
|
41
|
+
"@jini-ai/core": "^0.4.1"
|
|
42
42
|
},
|
|
43
43
|
"devDependencies": {
|
|
44
44
|
"vitest": "^2.1.0",
|