@clossys/writer 0.4.0 → 0.5.1

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.
Files changed (119) hide show
  1. package/README.md +592 -2
  2. package/dist/approval-bypass.d.ts +120 -0
  3. package/dist/approval-bypass.d.ts.map +1 -0
  4. package/dist/approval-bypass.js +2318 -0
  5. package/dist/approval-bypass.js.map +1 -0
  6. package/dist/approval.d.ts +62 -0
  7. package/dist/approval.d.ts.map +1 -0
  8. package/dist/approval.js +421 -0
  9. package/dist/approval.js.map +1 -0
  10. package/dist/approve-cli.d.ts +82 -0
  11. package/dist/approve-cli.d.ts.map +1 -0
  12. package/dist/approve-cli.js +430 -0
  13. package/dist/approve-cli.js.map +1 -0
  14. package/dist/cli.d.ts +15 -0
  15. package/dist/cli.d.ts.map +1 -1
  16. package/dist/cli.js +48 -13
  17. package/dist/cli.js.map +1 -1
  18. package/dist/field-options.d.ts +59 -0
  19. package/dist/field-options.d.ts.map +1 -0
  20. package/dist/field-options.js +109 -0
  21. package/dist/field-options.js.map +1 -0
  22. package/dist/front-door-browser.d.ts +5 -0
  23. package/dist/front-door-browser.d.ts.map +1 -0
  24. package/dist/front-door-browser.js +30 -0
  25. package/dist/front-door-browser.js.map +1 -0
  26. package/dist/front-door-core.d.ts +45 -0
  27. package/dist/front-door-core.d.ts.map +1 -0
  28. package/dist/front-door-core.js +224 -0
  29. package/dist/front-door-core.js.map +1 -0
  30. package/dist/front-door.check.d.ts +2 -0
  31. package/dist/front-door.check.d.ts.map +1 -0
  32. package/dist/front-door.check.js +8 -0
  33. package/dist/front-door.check.js.map +1 -0
  34. package/dist/front-door.d.ts +46 -0
  35. package/dist/front-door.d.ts.map +1 -0
  36. package/dist/front-door.js +61 -0
  37. package/dist/front-door.js.map +1 -0
  38. package/dist/generated/advisor-plan-contract.generated.d.ts +3 -0
  39. package/dist/generated/advisor-plan-contract.generated.d.ts.map +1 -0
  40. package/dist/generated/advisor-plan-contract.generated.js +430 -0
  41. package/dist/generated/advisor-plan-contract.generated.js.map +1 -0
  42. package/dist/generated/contract-schema.generated.d.ts +97 -0
  43. package/dist/generated/contract-schema.generated.d.ts.map +1 -0
  44. package/dist/generated/contract-schema.generated.js +496 -0
  45. package/dist/generated/contract-schema.generated.js.map +1 -0
  46. package/dist/index.d.ts +14 -2
  47. package/dist/index.d.ts.map +1 -1
  48. package/dist/index.js +24 -0
  49. package/dist/index.js.map +1 -1
  50. package/dist/messaging-kit.d.ts +113 -0
  51. package/dist/messaging-kit.d.ts.map +1 -0
  52. package/dist/messaging-kit.js +121 -0
  53. package/dist/messaging-kit.js.map +1 -0
  54. package/dist/passage.d.ts +2 -1
  55. package/dist/passage.d.ts.map +1 -1
  56. package/dist/passage.js +2 -1
  57. package/dist/passage.js.map +1 -1
  58. package/dist/plan-authority.d.ts +73 -0
  59. package/dist/plan-authority.d.ts.map +1 -0
  60. package/dist/plan-authority.js +126 -0
  61. package/dist/plan-authority.js.map +1 -0
  62. package/dist/plan-contract.d.ts +16 -0
  63. package/dist/plan-contract.d.ts.map +1 -0
  64. package/dist/plan-contract.js +33 -0
  65. package/dist/plan-contract.js.map +1 -0
  66. package/dist/plan-digest.d.ts +23 -0
  67. package/dist/plan-digest.d.ts.map +1 -0
  68. package/dist/plan-digest.js +82 -0
  69. package/dist/plan-digest.js.map +1 -0
  70. package/dist/plan-rules.d.ts +54 -0
  71. package/dist/plan-rules.d.ts.map +1 -0
  72. package/dist/plan-rules.js +145 -0
  73. package/dist/plan-rules.js.map +1 -0
  74. package/dist/resolve.d.ts +40 -6
  75. package/dist/resolve.d.ts.map +1 -1
  76. package/dist/resolve.js +144 -18
  77. package/dist/resolve.js.map +1 -1
  78. package/dist/scan.d.ts +32 -0
  79. package/dist/scan.d.ts.map +1 -1
  80. package/dist/scan.js +67 -6
  81. package/dist/scan.js.map +1 -1
  82. package/dist/schema.d.ts +1 -0
  83. package/dist/schema.d.ts.map +1 -1
  84. package/dist/schema.js +209 -5
  85. package/dist/schema.js.map +1 -1
  86. package/dist/site-identity.d.ts +88 -0
  87. package/dist/site-identity.d.ts.map +1 -0
  88. package/dist/site-identity.js +82 -0
  89. package/dist/site-identity.js.map +1 -0
  90. package/dist/types.d.ts +65 -7
  91. package/dist/types.d.ts.map +1 -1
  92. package/dist/types.js +9 -7
  93. package/dist/types.js.map +1 -1
  94. package/package.json +11 -6
  95. package/skill/SKILL.md +2 -2
  96. package/src/approval-bypass.ts +2263 -0
  97. package/src/approval.ts +491 -0
  98. package/src/approve-cli.ts +474 -0
  99. package/src/cli.ts +46 -13
  100. package/src/field-options.ts +134 -0
  101. package/src/front-door-browser.ts +31 -0
  102. package/src/front-door-core.ts +265 -0
  103. package/src/front-door.check.ts +10 -0
  104. package/src/front-door.ts +65 -0
  105. package/src/generated/advisor-plan-contract.generated.ts +430 -0
  106. package/src/generated/contract-schema.generated.ts +520 -0
  107. package/src/index.ts +97 -1
  108. package/src/messaging-kit.ts +195 -0
  109. package/src/passage.ts +2 -1
  110. package/src/plan-authority.ts +160 -0
  111. package/src/plan-contract.ts +45 -0
  112. package/src/plan-digest.ts +81 -0
  113. package/src/plan-rules.ts +179 -0
  114. package/src/resolve.ts +185 -19
  115. package/src/scan.ts +97 -6
  116. package/src/schema.ts +223 -5
  117. package/src/site-identity.ts +125 -0
  118. package/src/types.ts +72 -7
  119. package/templates/front-door.en.json +423 -0
package/src/schema.ts CHANGED
@@ -34,6 +34,8 @@ import type {
34
34
  CopyRecord,
35
35
  CopySource,
36
36
  } from "./types.js";
37
+ import { COPY_FINGERPRINT_ALGORITHM } from "./fingerprint.js";
38
+ import { isDelegateScopeItem, isEntryInDelegateScope } from "./approval.js";
37
39
 
38
40
  function isPlainObject(value: unknown): value is Record<string, unknown> {
39
41
  return typeof value === "object" && value !== null && !Array.isArray(value);
@@ -383,6 +385,207 @@ function validateTranslationShape(value: unknown, path: string): CopyFinding[] {
383
385
  return findings;
384
386
  }
385
387
 
388
+ /**
389
+ * `YYYY-MM-DDTHH:MM:SS(.sss)?Z` — the one ISO 8601 UTC shape this package
390
+ * accepts for `approvedAt`/`expiresAt`. Also requires `Date.parse` to
391
+ * actually accept it, so a string that merely matches the pattern but names
392
+ * an impossible date (e.g. a bad month) is still rejected.
393
+ */
394
+ const ISO_UTC_TIMESTAMP_RE = /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(\.\d{3})?Z$/;
395
+
396
+ export function isIsoUtcTimestamp(value: unknown): value is string {
397
+ if (typeof value !== "string" || !ISO_UTC_TIMESTAMP_RE.test(value)) return false;
398
+ const year = Number(value.slice(0, 4));
399
+ const month = Number(value.slice(5, 7));
400
+ const day = Number(value.slice(8, 10));
401
+ const parsed = Date.parse(value);
402
+ if (Number.isNaN(parsed)) return false;
403
+ const utc = new Date(parsed);
404
+ return utc.getUTCFullYear() === year && utc.getUTCMonth() + 1 === month && utc.getUTCDate() === day;
405
+ }
406
+
407
+ /** `textFingerprint` shape: a `sha256` hex digest — 64 lowercase hex characters. */
408
+ const COPY_FINGERPRINT_RE = /^[0-9a-f]{64}$/;
409
+
410
+ /**
411
+ * Validates a `CopyRegistryEntry.approval` field, when present. `undefined`
412
+ * is always valid, on any entry — an entry with no approval record keeps
413
+ * resolving exactly as it did before this field existed. Staleness (does
414
+ * `textFingerprint` still match the entry's current `text`) and expiry
415
+ * against "now" are runtime concerns for the resolver (`resolve.ts`) and
416
+ * `assessCopyApprovals` (`approval.ts`), never shape findings here: a
417
+ * registry with a stale or expired record is still a well-formed
418
+ * `CopyRegistry`.
419
+ */
420
+ function validateApprovalShape(value: unknown, entryStatus: unknown, entryId: unknown, path: string): CopyFinding[] {
421
+ if (value === undefined) return [];
422
+ if (!isPlainObject(value)) {
423
+ return [
424
+ {
425
+ rule: "approval-shape",
426
+ severity: "error",
427
+ message: `${path} must be an object when present, got ${JSON.stringify(value)}.`,
428
+ path,
429
+ },
430
+ ];
431
+ }
432
+
433
+ const approvedBy = value.approvedBy;
434
+ const approvedAt = value.approvedAt;
435
+ const textFingerprint = value.textFingerprint;
436
+ const fingerprintAlgorithm = value.fingerprintAlgorithm;
437
+ const delegate = value.delegate;
438
+ const pendingOwnerReview = value.pendingOwnerReview;
439
+ const expiresAt = value.expiresAt;
440
+
441
+ const findings: CopyFinding[] = [];
442
+
443
+ if (entryStatus !== "approved") {
444
+ findings.push({
445
+ rule: "approval-status-mismatch",
446
+ severity: "error",
447
+ message: `${path} is present but the entry's status is ${JSON.stringify(entryStatus)}, not "approved".`,
448
+ path,
449
+ });
450
+ }
451
+
452
+ const isDelegateRecord = approvedBy === "delegate";
453
+
454
+ if (approvedBy !== "owner" && approvedBy !== "delegate") {
455
+ findings.push({
456
+ rule: "approval-approved-by",
457
+ severity: "error",
458
+ message: `${path}.approvedBy must be "owner" or "delegate", got ${JSON.stringify(approvedBy)}.`,
459
+ path: `${path}.approvedBy`,
460
+ });
461
+ }
462
+
463
+ if (!isIsoUtcTimestamp(approvedAt)) {
464
+ findings.push({
465
+ rule: "approval-approved-at-shape",
466
+ severity: "error",
467
+ message: `${path}.approvedAt must be an ISO 8601 UTC timestamp, got ${JSON.stringify(approvedAt)}.`,
468
+ path: `${path}.approvedAt`,
469
+ });
470
+ }
471
+
472
+ if (typeof textFingerprint !== "string" || !COPY_FINGERPRINT_RE.test(textFingerprint)) {
473
+ findings.push({
474
+ rule: "approval-fingerprint-shape",
475
+ severity: "error",
476
+ message: `${path}.textFingerprint must be a 64-character lowercase hex string, got ${JSON.stringify(textFingerprint)}.`,
477
+ path: `${path}.textFingerprint`,
478
+ });
479
+ }
480
+
481
+ if (fingerprintAlgorithm !== COPY_FINGERPRINT_ALGORITHM) {
482
+ findings.push({
483
+ rule: "approval-fingerprint-shape",
484
+ severity: "error",
485
+ message: `${path}.fingerprintAlgorithm must be ${JSON.stringify(COPY_FINGERPRINT_ALGORITHM)}, got ${JSON.stringify(fingerprintAlgorithm)}.`,
486
+ path: `${path}.fingerprintAlgorithm`,
487
+ });
488
+ }
489
+
490
+ if (isDelegateRecord && delegate === undefined) {
491
+ findings.push({
492
+ rule: "approval-delegate-required",
493
+ severity: "error",
494
+ message: `${path}.delegate is required when approvedBy is "delegate".`,
495
+ path: `${path}.delegate`,
496
+ });
497
+ }
498
+
499
+ if (approvedBy === "owner") {
500
+ (["delegate", "pendingOwnerReview", "expiresAt"] as const).forEach((field) => {
501
+ if (value[field] !== undefined) {
502
+ findings.push({
503
+ rule: "approval-delegate-forbidden",
504
+ severity: "error",
505
+ message: `${path}.${field} is forbidden when approvedBy is "owner".`,
506
+ path: `${path}.${field}`,
507
+ });
508
+ }
509
+ });
510
+ }
511
+
512
+ // The remaining checks (scope shape, scope membership, pendingOwnerReview,
513
+ // expiresAt) only make sense on an actual delegate record — on an owner
514
+ // record any of these fields is already reported above as forbidden, and
515
+ // shape-checking a field that should not exist would only add noise.
516
+ if (!isDelegateRecord) return findings;
517
+
518
+ let scopeIsValid = false;
519
+ if (!isPlainObject(delegate)) {
520
+ if (delegate !== undefined) {
521
+ findings.push({
522
+ rule: "approval-delegate-scope-shape",
523
+ severity: "error",
524
+ message: `${path}.delegate must be an object, got ${JSON.stringify(delegate)}.`,
525
+ path: `${path}.delegate`,
526
+ });
527
+ }
528
+ } else {
529
+ const delegateId = delegate.id;
530
+ const scope = delegate.scope;
531
+ const idIsValid = isNonEmptyString(delegateId);
532
+ const scopeIsArrayOfItems = Array.isArray(scope) && scope.length > 0 && scope.every((item) => isDelegateScopeItem(item));
533
+ if (!idIsValid || !scopeIsArrayOfItems) {
534
+ findings.push({
535
+ rule: "approval-delegate-scope-shape",
536
+ severity: "error",
537
+ message: `${path}.delegate must have a non-empty string id and a non-empty array scope of well-formed namespace items, got ${JSON.stringify(delegate)}.`,
538
+ path: `${path}.delegate`,
539
+ });
540
+ } else {
541
+ scopeIsValid = true;
542
+ }
543
+
544
+ if (scopeIsValid && typeof entryId === "string" && !isEntryInDelegateScope(entryId, scope as string[])) {
545
+ findings.push({
546
+ rule: "approval-outside-delegate-scope",
547
+ severity: "error",
548
+ message: `${path}.delegate scope ${JSON.stringify(scope)} does not cover entry id ${JSON.stringify(entryId)}.`,
549
+ path: `${path}.delegate`,
550
+ });
551
+ }
552
+ }
553
+
554
+ if (typeof pendingOwnerReview !== "boolean") {
555
+ findings.push({
556
+ rule: "approval-pending-review-shape",
557
+ severity: "error",
558
+ message: `${path}.pendingOwnerReview must be a boolean when approvedBy is "delegate", got ${JSON.stringify(pendingOwnerReview)}.`,
559
+ path: `${path}.pendingOwnerReview`,
560
+ });
561
+ }
562
+
563
+ let expiresAtIsValid = false;
564
+ if (expiresAt !== undefined) {
565
+ if (!isIsoUtcTimestamp(expiresAt)) {
566
+ findings.push({
567
+ rule: "approval-expires-at-shape",
568
+ severity: "error",
569
+ message: `${path}.expiresAt must be an ISO 8601 UTC timestamp when present, got ${JSON.stringify(expiresAt)}.`,
570
+ path: `${path}.expiresAt`,
571
+ });
572
+ } else {
573
+ expiresAtIsValid = true;
574
+ }
575
+ }
576
+
577
+ if (expiresAtIsValid && isIsoUtcTimestamp(approvedAt) && Date.parse(expiresAt as string) <= Date.parse(approvedAt)) {
578
+ findings.push({
579
+ rule: "approval-expires-before-approved",
580
+ severity: "error",
581
+ message: `${path}.expiresAt ${JSON.stringify(expiresAt)} must be strictly after ${path}.approvedAt ${JSON.stringify(approvedAt)}.`,
582
+ path: `${path}.expiresAt`,
583
+ });
584
+ }
585
+
586
+ return findings;
587
+ }
588
+
386
589
  /**
387
590
  * Validates the stronger registry shape used to resolve `CopyRef`s. A plain
388
591
  * `CopyRecord` deliberately remains valid for source scanning and voice
@@ -456,6 +659,7 @@ export function validateCopyRegistryShape(value: unknown): CopyFinding[] {
456
659
  });
457
660
  }
458
661
  findings.push(...validateTranslationShape(entry.translation, `entries.${i}.translation`));
662
+ findings.push(...validateApprovalShape(entry.approval, entry.status, entry.id, `entries.${i}.approval`));
459
663
  });
460
664
  }
461
665
 
@@ -496,11 +700,25 @@ function buildCopyRecord(value: Record<string, unknown>): CopyRecord {
496
700
 
497
701
  function buildCopyRegistry(value: Record<string, unknown>): CopyRegistry {
498
702
  const record = buildCopyRecord(value);
499
- const entries = (value.entries as Array<Record<string, unknown>>).map((entry) => ({
500
- ...record.entries.find((item) => item.id === entry.id)!,
501
- status: entry.status as CopyEntryStatus,
502
- translation: entry.translation as CopyRegistryEntry["translation"],
503
- })) as CopyRegistryEntry[];
703
+ const entries = (value.entries as Array<Record<string, unknown>>).map((entry) => {
704
+ const built: CopyRegistryEntry = {
705
+ ...record.entries.find((item) => item.id === entry.id)!,
706
+ status: entry.status as CopyEntryStatus,
707
+ translation: entry.translation as CopyRegistryEntry["translation"],
708
+ };
709
+ // Only copy `approval` when the input entry actually has one — an
710
+ // `approval: undefined` key would still make `"approval" in entry` true,
711
+ // breaking the "no record at all" case `resolve.ts` and `approval.ts`
712
+ // both depend on. Copied defensively (a fresh `delegate.scope` array) so
713
+ // the parsed registry never aliases the caller's own input object.
714
+ if (entry.approval !== undefined) {
715
+ const approval = entry.approval as CopyRegistryEntry["approval"];
716
+ built.approval = approval?.delegate
717
+ ? { ...approval, delegate: { ...approval.delegate, scope: [...approval.delegate.scope] } }
718
+ : { ...approval! };
719
+ }
720
+ return built;
721
+ });
504
722
 
505
723
  return {
506
724
  ...record,
@@ -0,0 +1,125 @@
1
+ /**
2
+ * The site-identity copy kind: a site's name and tagline, resolved from a
3
+ * `CopyRegistry` under two reserved entry ids.
4
+ *
5
+ * A page-metadata consumer needs exactly two short strings — what the site
6
+ * is called and one line about it — and needs them to carry the same
7
+ * approval evidence as any other rendered copy. This module does not add a
8
+ * second approval path for them. It asks `resolveCopyRef` for
9
+ * `"site.name"` and `"site.tagline"`, so whatever that resolver refuses
10
+ * (a draft entry, an approval record that no longer matches its text, an
11
+ * expired delegate approval, a delegate approval on `"production"` without
12
+ * the caller's opt-in, a locale mismatch, an unknown id, an invalid
13
+ * registry or options object) is refused here for the same reason.
14
+ *
15
+ * On top of that resolver this module adds two refusals of its own,
16
+ * because a name and a tagline are literal text rather than templates: an
17
+ * entry that declares placeholders (or whose text the resolver would
18
+ * rewrite), and a resolved text that is blank after trimming.
19
+ *
20
+ * The result is all-or-nothing. Both fields are always attempted so a
21
+ * caller sees every problem at once, but `identity` and `resolutions` are
22
+ * present only when both fields resolved — there is no partial identity.
23
+ * Nothing here throws for any input; malformed input yields a result with
24
+ * `complete: false` and an issue. Nothing here reads a brand-facts record
25
+ * or consumes the result; wiring it into a page-metadata builder is a
26
+ * separate change.
27
+ *
28
+ * No real copy ships here. The ids are reserved names; the words are the
29
+ * consumer's own.
30
+ */
31
+
32
+ import { prepareOptions, resolveField } from "./field-options.js";
33
+ import type { FieldLabels } from "./field-options.js";
34
+ import type { CopyResolveIssue, CopyResolveIssueReason, CopyResolveOptions } from "./resolve.js";
35
+ import type { CopyRegistry, CopyResolution } from "./types.js";
36
+
37
+ /** Reserved copy id for the site's name. */
38
+ export const SITE_NAME_COPY_ID = "site.name";
39
+
40
+ /** Reserved copy id for the site's tagline. */
41
+ export const SITE_TAGLINE_COPY_ID = "site.tagline";
42
+
43
+ /** Both reserved site-identity copy ids, name first. */
44
+ export const SITE_IDENTITY_COPY_IDS = [SITE_NAME_COPY_ID, SITE_TAGLINE_COPY_ID] as const;
45
+
46
+ /** Which half of the site identity an issue is about. */
47
+ export type SiteIdentityField = "name" | "tagline";
48
+
49
+ /**
50
+ * Every reason `resolveSiteIdentity` can report: whatever `resolveCopyRef`
51
+ * refuses, plus the two refusals specific to site identity.
52
+ * `"site-identity-blank"` means the resolved text was empty after trimming;
53
+ * `"site-identity-placeholder"` means the entry declares placeholders or
54
+ * its text is one the resolver would rewrite.
55
+ */
56
+ export type SiteIdentityIssueReason = CopyResolveIssueReason | "site-identity-blank" | "site-identity-placeholder";
57
+
58
+ /** One reason a site identity could not be resolved, tagged with its field. */
59
+ export interface SiteIdentityIssue extends Omit<CopyResolveIssue, "reason"> {
60
+ reason: SiteIdentityIssueReason;
61
+ field: SiteIdentityField;
62
+ }
63
+
64
+ /**
65
+ * The outcome of `resolveSiteIdentity`. `identity` and `resolutions` are
66
+ * present only when `complete` is `true`; `issues` is empty exactly then.
67
+ */
68
+ export interface SiteIdentityResolution {
69
+ complete: boolean;
70
+ identity?: { name: string; tagline: string };
71
+ resolutions?: { name: CopyResolution; tagline: CopyResolution };
72
+ issues: SiteIdentityIssue[];
73
+ }
74
+
75
+ /** `CopyResolveOptions` plus the requested locale, which is a ref field for the underlying resolver. */
76
+ export type SiteIdentityOptions = CopyResolveOptions & { locale?: string };
77
+
78
+ const FIELDS: readonly { field: SiteIdentityField; id: string }[] = [
79
+ { field: "name", id: SITE_NAME_COPY_ID },
80
+ { field: "tagline", id: SITE_TAGLINE_COPY_ID },
81
+ ];
82
+
83
+ const LABELS: FieldLabels<"site-identity-placeholder" | "site-identity-blank"> = {
84
+ optionsSubject: "Site identity",
85
+ entrySubject: (id) => `Site identity "${id}"`,
86
+ placeholderReason: "site-identity-placeholder",
87
+ blankReason: "site-identity-blank",
88
+ };
89
+
90
+ /**
91
+ * Resolves the site's name and tagline from `registry`, under
92
+ * `"site.name"` and `"site.tagline"`. Both are attempted on every call and
93
+ * every issue is reported, tagged with its `field`; `identity` and
94
+ * `resolutions` are returned only when both resolved.
95
+ *
96
+ * `options` are `resolveCopyRef`'s (`target`, `acceptDelegateInProduction`,
97
+ * `now`) plus an optional `locale`, which is forwarded as the ref's locale
98
+ * rather than as an option. Malformed options (including a blank or
99
+ * non-string `locale`) produce an `"invalid-options"` issue per field. Pure
100
+ * apart from the clock read that `now` defaults to; the registry is not
101
+ * modified and no input makes this throw.
102
+ */
103
+ export function resolveSiteIdentity(
104
+ registry: CopyRegistry | unknown,
105
+ options?: SiteIdentityOptions | unknown,
106
+ ): SiteIdentityResolution {
107
+ const prepared = prepareOptions(options);
108
+ const issues: SiteIdentityIssue[] = [];
109
+ const resolved: Partial<Record<SiteIdentityField, CopyResolution>> = {};
110
+ for (const { field, id } of FIELDS) {
111
+ const outcome = resolveField(registry, field, id, prepared, LABELS);
112
+ issues.push(...outcome.issues);
113
+ if (outcome.resolution) resolved[field] = outcome.resolution;
114
+ }
115
+
116
+ const name = resolved.name;
117
+ const tagline = resolved.tagline;
118
+ if (issues.length > 0 || !name || !tagline) return { complete: false, issues };
119
+ return {
120
+ complete: true,
121
+ identity: { name: name.text, tagline: tagline.text },
122
+ resolutions: { name, tagline },
123
+ issues: [],
124
+ };
125
+ }
package/src/types.ts CHANGED
@@ -28,13 +28,15 @@
28
28
  * This file ships no example content of anyone's real copy. Every field
29
29
  * here is either required-and-generic or a structural placeholder —
30
30
  * filling in an actual product's actual sentences is a consumer's job.
31
- * See "The single most important constraint" in the README: this package
32
- * is to `@clossys/writer/voice` what `@example/ui` is to
33
- * `@example/ui/tokens` — a vocabulary layer over a contract layer,
34
- * never a source of real words. If a doc comment, a test fixture, or a
35
- * README example in this package ever reads like something a product
36
- * would actually show a user, that is a bug in this package, not a
37
- * feature of it.
31
+ * The one exemption is the shipped US English front-door defaults
32
+ * (`front-door.ts`, `FRONT_DOOR_COPY_EN`, and the README's "Front-door
33
+ * copy" section): a closed, reserved set of ids, owned by this package, whose
34
+ * words ship as data so every sign-in surface need not carry its own. Outside
35
+ * that set this package is to `@clossys/writer/voice` what `@example/ui` is
36
+ * to `@example/ui/tokens` — a vocabulary layer over a contract layer, never a
37
+ * source of real words. If a doc comment, a test fixture, or a README example
38
+ * outside the front-door set ever reads like something a product would
39
+ * actually show a user, that is a bug in this package, not a feature of it.
38
40
  */
39
41
 
40
42
  // ---------------------------------------------------------------------------
@@ -222,6 +224,47 @@ export interface CopyTranslationProvenance {
222
224
  reviewedBy?: string;
223
225
  }
224
226
 
227
+ // ---------------------------------------------------------------------------
228
+ // CopyApproval — who approved an entry, and exactly which text they approved
229
+ // ---------------------------------------------------------------------------
230
+
231
+ /** Who recorded an approval: the copy owner, or a delegate acting for them. */
232
+ export type CopyApprover = "owner" | "delegate";
233
+
234
+ /**
235
+ * The delegate an approval was recorded by, and the entry-id namespaces they
236
+ * may approve. `id` is an opaque identifier, never a personal name. Each
237
+ * `scope` item is a dot-separated namespace with no wildcard; an entry is in
238
+ * scope when its id equals an item or starts with `item + "."`.
239
+ */
240
+ export interface CopyDelegateScope {
241
+ id: string;
242
+ scope: string[];
243
+ }
244
+
245
+ /**
246
+ * The recorded approval of one registry entry, written by
247
+ * `writer-check approve` rather than by hand. `textFingerprint` pins the
248
+ * approval to the exact text that was approved: once `text` changes, the
249
+ * record no longer matches and the resolver refuses the entry
250
+ * (`approval-stale`) until it is approved again.
251
+ */
252
+ export interface CopyApproval {
253
+ approvedBy: CopyApprover;
254
+ /** ISO 8601 UTC timestamp of the approval. */
255
+ approvedAt: string;
256
+ /** `computeCopyFingerprint(entry.text)` at the moment of approval. */
257
+ textFingerprint: string;
258
+ /** The algorithm `textFingerprint` was computed with — `COPY_FINGERPRINT_ALGORITHM`. */
259
+ fingerprintAlgorithm: string;
260
+ /** Required when `approvedBy` is `"delegate"`; forbidden for `"owner"`. */
261
+ delegate?: CopyDelegateScope;
262
+ /** Required when `approvedBy` is `"delegate"`; forbidden for `"owner"`. */
263
+ pendingOwnerReview?: boolean;
264
+ /** Delegate records only: ISO 8601 UTC expiry, strictly after `approvedAt`. */
265
+ expiresAt?: string;
266
+ }
267
+
225
268
  /** A `CopyEntry` that is eligible to participate in a rendered registry. */
226
269
  export interface CopyRegistryEntry extends CopyEntry {
227
270
  status: CopyEntryStatus;
@@ -238,6 +281,12 @@ export interface CopyRegistryEntry extends CopyEntry {
238
281
  * never collapsed into one signal.
239
282
  */
240
283
  translation?: CopyTranslationProvenance;
284
+ /**
285
+ * The approval record, present only on an `approved` entry that has one.
286
+ * Optional: an `approved` entry without a record keeps resolving exactly
287
+ * as it did before this field existed. See `CopyApproval`.
288
+ */
289
+ approval?: CopyApproval;
241
290
  }
242
291
 
243
292
  // ---------------------------------------------------------------------------
@@ -268,6 +317,20 @@ export interface CopyRegistry extends CopyRecord {
268
317
  entries: CopyRegistryEntry[];
269
318
  }
270
319
 
320
+ /** The approval facts a resolution carries (`CopyResolution.approval`). */
321
+ export type CopyResolutionApproval =
322
+ | { approvedBy: "owner"; pendingOwnerReview: false }
323
+ | {
324
+ approvedBy: "delegate";
325
+ pendingOwnerReview: boolean;
326
+ /**
327
+ * Present only when this delegate-approved entry resolved on "production"
328
+ * because the `approvalPlan` authorized it: that plan's canonical digest.
329
+ * Absent when `acceptDelegateInProduction` authorized it, and on "preview".
330
+ */
331
+ authorizingPlanDigest?: string;
332
+ };
333
+
271
334
  /** A successful, fully traced resolution of one copy reference. */
272
335
  export interface CopyResolution {
273
336
  ref: CopyRef;
@@ -277,6 +340,8 @@ export interface CopyResolution {
277
340
  locale: CopyLocale;
278
341
  source: CopySource;
279
342
  entryId: CopyEntryId;
343
+ /** Present only when the resolved entry carries an approval record. */
344
+ approval?: CopyResolutionApproval;
280
345
  }
281
346
 
282
347
  /** Resolver shape for callers that need rendered audience text. */