@jini-ai/cms-forms 0.2.2 → 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 CHANGED
@@ -1,5 +1,10 @@
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
+
3
8
  ## 0.2.2 — 2026-10-04
4
9
 
5
10
  - Authored checkbox values (`checkboxValue`).
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>;
@@ -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;
@@ -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, event enqueue, then background dispatch. Persistence and enqueue remain separate awaited effects, matching the source contract. */
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
- await deps.submissionRepo.create(submission);
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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jini-ai/cms-forms",
3
- "version": "0.2.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/cms": "^0.4.2",
41
- "@jini-ai/core": "^0.4.0"
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",