@jini-ai/cms-forms 0.6.15-rc.1 → 0.6.15

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/dist/forms.js CHANGED
@@ -198,6 +198,9 @@ export function validateSubmissionPayload(input) {
198
198
  else if (resolved.kind === "accepted") {
199
199
  data[field.id] = resolved.value;
200
200
  }
201
+ else {
202
+ // An absent optional field does not create a stored answer.
203
+ }
201
204
  }
202
205
  if (fieldErrors.length > 0)
203
206
  return { valid: false, fieldErrors };
@@ -1,7 +1,8 @@
1
1
  // Domain behavior owns its event contract; reading a host manifest back would invert dependency flow.
2
2
  const FORM_SUBMISSION_RECEIVED_TOPIC = "form.submission.received";
3
3
  export async function registerFormNotifySubscriber(deps) {
4
- return deps.bus.subscribe({ eventName: FORM_SUBMISSION_RECEIVED_TOPIC,
4
+ return deps.bus.subscribe({
5
+ eventName: FORM_SUBMISSION_RECEIVED_TOPIC,
5
6
  handler: async (event) => {
6
7
  try {
7
8
  const { workspaceId, formDefinitionId, submissionId } = event.payload;
@@ -13,42 +14,15 @@ export async function registerFormNotifySubscriber(deps) {
13
14
  if (!submission)
14
15
  return;
15
16
  for (const recipient of definition.notify.recipients) {
16
- try {
17
- const result = await deps.mailer.send({
18
- message: {
19
- workspaceId,
20
- to: { email: recipient },
21
- from: deps.sender,
22
- subject: `New submission: ${definition.name}`,
23
- text: JSON.stringify(submission.data),
24
- },
25
- options: {
26
- // Include the recipient so a shared dedup ledger never suppresses a sibling send.
27
- idempotencyKey: `forms:notify:${submissionId}:${recipient}`,
28
- workspaceId,
29
- sourceContext: { module: "forms", ref: formDefinitionId },
30
- purpose: "transactional",
31
- // Background notifications use the host mailer's durable-outbox readiness gate,
32
- // rather than the interactive send lane, when production delivery requires it.
33
- lane: "notification",
34
- }
35
- });
36
- if (!result.ok) {
37
- warn(deps.logger, `[forms:notify] mail send failed for submission '${submissionId}' recipient '${recipient}': ${result.errorCode} (${result.message})`);
38
- }
39
- }
40
- catch (err) {
41
- // A send failure is terminal for this delivery: log, never retry inline or alter
42
- // the persisted submission, and continue so the other recipients can still receive it.
43
- warn(deps.logger, `[forms:notify] mail send threw for submission '${submissionId}' recipient '${recipient}':`, err);
44
- }
17
+ await sendNotification({ deps, definition, submission, recipient, payload: { workspaceId, formDefinitionId, submissionId } });
45
18
  }
46
19
  }
47
20
  catch (err) {
48
21
  // Repository failures must not escape the bus's subscriber loop and break sibling handlers.
49
22
  warn(deps.logger, "[forms:notify] subscriber failed:", err);
50
23
  }
51
- } });
24
+ }
25
+ });
52
26
  }
53
27
  /** Failure reporting is isolated too: a logger cannot interrupt sibling event subscribers. */
54
28
  function warn(logger, message, error) {
@@ -57,4 +31,36 @@ function warn(logger, message, error) {
57
31
  }
58
32
  catch { /* Host logging failure is terminal. */ }
59
33
  }
34
+ /** One recipient's delivery failure is terminal and cannot interrupt sibling recipients. */
35
+ async function sendNotification({ deps, definition, submission, recipient, payload: { workspaceId, formDefinitionId, submissionId } }) {
36
+ try {
37
+ const result = await deps.mailer.send({
38
+ message: {
39
+ workspaceId,
40
+ to: { email: recipient },
41
+ from: deps.sender,
42
+ subject: `New submission: ${definition.name}`,
43
+ text: JSON.stringify(submission.data),
44
+ },
45
+ options: {
46
+ // Include the recipient so a shared dedup ledger never suppresses a sibling send.
47
+ idempotencyKey: `forms:notify:${submissionId}:${recipient}`,
48
+ workspaceId,
49
+ sourceContext: { module: "forms", ref: formDefinitionId },
50
+ purpose: "transactional",
51
+ // Background notifications use the host mailer's durable-outbox readiness gate,
52
+ // rather than the interactive send lane, when production delivery requires it.
53
+ lane: "notification",
54
+ }
55
+ });
56
+ if (!result.ok) {
57
+ warn(deps.logger, `[forms:notify] mail send failed for submission '${submissionId}' recipient '${recipient}': ${result.errorCode} (${result.message})`);
58
+ }
59
+ }
60
+ catch (err) {
61
+ // A send failure is terminal for this delivery: log, never retry inline or alter
62
+ // the persisted submission, and continue so the other recipients can still receive it.
63
+ warn(deps.logger, `[forms:notify] mail send threw for submission '${submissionId}' recipient '${recipient}':`, err);
64
+ }
65
+ }
60
66
  //# sourceMappingURL=notify-subscriber.js.map
@@ -3,7 +3,7 @@ import { FormDefinitionNotFoundError, FormFieldValidationError } from "./errors.
3
3
  import { validateFieldDescriptors } from "./forms.js";
4
4
  // Export validation bounds so host tool schemas can share them rather than drift from the service.
5
5
  export const MAX_NOTIFY_RECIPIENTS = 10;
6
- const EMAIL_PATTERN = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
6
+ const EMAIL_PATTERN = /^[^\s@]+@([^\s@]+)$/;
7
7
  export const SLUG_PATTERN = /^[a-z0-9][a-z0-9-]{0,63}$/;
8
8
  const MIN_NAME_LENGTH = 1;
9
9
  export const MAX_NAME_LENGTH = 200;
@@ -13,42 +13,55 @@ function defaultNotify() {
13
13
  function validateNotify(notify) {
14
14
  const resolved = notify ?? defaultNotify();
15
15
  if (!Array.isArray(resolved.recipients)) {
16
- throw new FormFieldValidationError({ message: "notify.recipients must be an array", fieldErrors: [
16
+ throw new FormFieldValidationError({
17
+ message: "notify.recipients must be an array", fieldErrors: [
17
18
  { field: "notify.recipients", reason: "must be an array" },
18
- ] });
19
+ ]
20
+ });
19
21
  }
20
22
  if (typeof resolved.enabled !== "boolean") {
21
- throw new FormFieldValidationError({ message: "notify.enabled must be a boolean", fieldErrors: [
23
+ throw new FormFieldValidationError({
24
+ message: "notify.enabled must be a boolean", fieldErrors: [
22
25
  { field: "notify.enabled", reason: "must be a boolean" },
23
- ] });
26
+ ]
27
+ });
24
28
  }
25
29
  if (resolved.recipients.length > MAX_NOTIFY_RECIPIENTS) {
26
30
  throw new FormFieldValidationError({ message: `notify.recipients may not exceed ${MAX_NOTIFY_RECIPIENTS} addresses`, fieldErrors: [{ field: "notify.recipients", reason: `at most ${MAX_NOTIFY_RECIPIENTS} recipients are allowed` }] });
27
31
  }
28
32
  for (const recipient of resolved.recipients) {
29
- if (!EMAIL_PATTERN.test(recipient)) {
30
- throw new FormFieldValidationError({ message: `'${recipient}' is not a valid email address`, fieldErrors: [
33
+ const address = EMAIL_PATTERN.exec(recipient);
34
+ if (!address || !address[1].slice(1, -1).includes(".")) {
35
+ throw new FormFieldValidationError({
36
+ message: `'${recipient}' is not a valid email address`, fieldErrors: [
31
37
  { field: "notify.recipients", reason: `'${recipient}' is not a valid email address` },
32
- ] });
38
+ ]
39
+ });
33
40
  }
34
41
  }
35
42
  return resolved;
36
43
  }
37
44
  function validateNameAndSlug(name, slug, reservedSlugs) {
38
45
  if (name.length < MIN_NAME_LENGTH || name.length > MAX_NAME_LENGTH) {
39
- throw new FormFieldValidationError({ message: `name must be ${MIN_NAME_LENGTH}-${MAX_NAME_LENGTH} characters`, fieldErrors: [
46
+ throw new FormFieldValidationError({
47
+ message: `name must be ${MIN_NAME_LENGTH}-${MAX_NAME_LENGTH} characters`, fieldErrors: [
40
48
  { field: "name", reason: `must be ${MIN_NAME_LENGTH}-${MAX_NAME_LENGTH} characters` },
41
- ] });
49
+ ]
50
+ });
42
51
  }
43
52
  if (!SLUG_PATTERN.test(slug)) {
44
- throw new FormFieldValidationError({ message: "slug must match ^[a-z0-9][a-z0-9-]{0,63}$", fieldErrors: [
53
+ throw new FormFieldValidationError({
54
+ message: "slug must match ^[a-z0-9][a-z0-9-]{0,63}$", fieldErrors: [
45
55
  { field: "slug", reason: "must match ^[a-z0-9][a-z0-9-]{0,63}$" },
46
- ] });
56
+ ]
57
+ });
47
58
  }
48
59
  if (reservedSlugs.has(slug)) {
49
- throw new FormFieldValidationError({ message: `slug '${slug}' is reserved`, fieldErrors: [
60
+ throw new FormFieldValidationError({
61
+ message: `slug '${slug}' is reserved`, fieldErrors: [
50
62
  { field: "slug", reason: `'${slug}' is reserved by the host` },
51
- ] });
63
+ ]
64
+ });
52
65
  }
53
66
  }
54
67
  function assertValidFields(fields) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jini-ai/cms-forms",
3
- "version": "0.6.15-rc.1",
3
+ "version": "0.6.15",
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.6.15-rc.1",
41
- "@jini-ai/core": "^0.6.15-rc.1"
40
+ "@jini-ai/core": "^0.6.15",
41
+ "@jini-ai/cms": "^0.6.15"
42
42
  },
43
43
  "devDependencies": {
44
44
  "vitest": "^2.1.0",