@clossys/writer 0.4.0 → 0.5.0
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/README.md +587 -2
- package/dist/approval-bypass.d.ts +120 -0
- package/dist/approval-bypass.d.ts.map +1 -0
- package/dist/approval-bypass.js +2318 -0
- package/dist/approval-bypass.js.map +1 -0
- package/dist/approval.d.ts +62 -0
- package/dist/approval.d.ts.map +1 -0
- package/dist/approval.js +421 -0
- package/dist/approval.js.map +1 -0
- package/dist/approve-cli.d.ts +82 -0
- package/dist/approve-cli.d.ts.map +1 -0
- package/dist/approve-cli.js +430 -0
- package/dist/approve-cli.js.map +1 -0
- package/dist/cli.d.ts +15 -0
- package/dist/cli.d.ts.map +1 -1
- package/dist/cli.js +48 -13
- package/dist/cli.js.map +1 -1
- package/dist/field-options.d.ts +59 -0
- package/dist/field-options.d.ts.map +1 -0
- package/dist/field-options.js +109 -0
- package/dist/field-options.js.map +1 -0
- package/dist/front-door.check.d.ts +2 -0
- package/dist/front-door.check.d.ts.map +1 -0
- package/dist/front-door.check.js +8 -0
- package/dist/front-door.check.js.map +1 -0
- package/dist/front-door.d.ts +82 -0
- package/dist/front-door.d.ts.map +1 -0
- package/dist/front-door.js +271 -0
- package/dist/front-door.js.map +1 -0
- package/dist/generated/advisor-plan-contract.generated.d.ts +3 -0
- package/dist/generated/advisor-plan-contract.generated.d.ts.map +1 -0
- package/dist/generated/advisor-plan-contract.generated.js +430 -0
- package/dist/generated/advisor-plan-contract.generated.js.map +1 -0
- package/dist/generated/contract-schema.generated.d.ts +97 -0
- package/dist/generated/contract-schema.generated.d.ts.map +1 -0
- package/dist/generated/contract-schema.generated.js +496 -0
- package/dist/generated/contract-schema.generated.js.map +1 -0
- package/dist/index.d.ts +14 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +24 -0
- package/dist/index.js.map +1 -1
- package/dist/messaging-kit.d.ts +113 -0
- package/dist/messaging-kit.d.ts.map +1 -0
- package/dist/messaging-kit.js +121 -0
- package/dist/messaging-kit.js.map +1 -0
- package/dist/passage.d.ts +2 -1
- package/dist/passage.d.ts.map +1 -1
- package/dist/passage.js +2 -1
- package/dist/passage.js.map +1 -1
- package/dist/plan-authority.d.ts +73 -0
- package/dist/plan-authority.d.ts.map +1 -0
- package/dist/plan-authority.js +126 -0
- package/dist/plan-authority.js.map +1 -0
- package/dist/plan-contract.d.ts +16 -0
- package/dist/plan-contract.d.ts.map +1 -0
- package/dist/plan-contract.js +33 -0
- package/dist/plan-contract.js.map +1 -0
- package/dist/plan-digest.d.ts +23 -0
- package/dist/plan-digest.d.ts.map +1 -0
- package/dist/plan-digest.js +82 -0
- package/dist/plan-digest.js.map +1 -0
- package/dist/plan-rules.d.ts +54 -0
- package/dist/plan-rules.d.ts.map +1 -0
- package/dist/plan-rules.js +145 -0
- package/dist/plan-rules.js.map +1 -0
- package/dist/resolve.d.ts +40 -6
- package/dist/resolve.d.ts.map +1 -1
- package/dist/resolve.js +144 -18
- package/dist/resolve.js.map +1 -1
- package/dist/scan.d.ts +32 -0
- package/dist/scan.d.ts.map +1 -1
- package/dist/scan.js +67 -6
- package/dist/scan.js.map +1 -1
- package/dist/schema.d.ts +1 -0
- package/dist/schema.d.ts.map +1 -1
- package/dist/schema.js +209 -5
- package/dist/schema.js.map +1 -1
- package/dist/site-identity.d.ts +88 -0
- package/dist/site-identity.d.ts.map +1 -0
- package/dist/site-identity.js +82 -0
- package/dist/site-identity.js.map +1 -0
- package/dist/types.d.ts +65 -7
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js +9 -7
- package/dist/types.js.map +1 -1
- package/package.json +7 -6
- package/skill/SKILL.md +2 -2
- package/src/approval-bypass.ts +2263 -0
- package/src/approval.ts +491 -0
- package/src/approve-cli.ts +474 -0
- package/src/cli.ts +46 -13
- package/src/field-options.ts +134 -0
- package/src/front-door.check.ts +10 -0
- package/src/front-door.ts +312 -0
- package/src/generated/advisor-plan-contract.generated.ts +430 -0
- package/src/generated/contract-schema.generated.ts +520 -0
- package/src/index.ts +97 -1
- package/src/messaging-kit.ts +195 -0
- package/src/passage.ts +2 -1
- package/src/plan-authority.ts +160 -0
- package/src/plan-contract.ts +45 -0
- package/src/plan-digest.ts +81 -0
- package/src/plan-rules.ts +179 -0
- package/src/resolve.ts +185 -19
- package/src/scan.ts +97 -6
- package/src/schema.ts +223 -5
- package/src/site-identity.ts +125 -0
- package/src/types.ts +72 -7
- package/templates/front-door.en.json +426 -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
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
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
|
-
*
|
|
32
|
-
*
|
|
33
|
-
*
|
|
34
|
-
*
|
|
35
|
-
*
|
|
36
|
-
*
|
|
37
|
-
*
|
|
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. */
|