@certrev/cert-block 1.3.0 → 2.0.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 (88) hide show
  1. package/CHANGELOG.md +235 -0
  2. package/README.md +162 -9
  3. package/dist/builder/card-beacon.d.ts +73 -0
  4. package/dist/builder/card-beacon.d.ts.map +1 -0
  5. package/dist/builder/card-beacon.js +178 -0
  6. package/dist/builder/card-beacon.js.map +1 -0
  7. package/dist/builder/card-contract.d.ts +151 -0
  8. package/dist/builder/card-contract.d.ts.map +1 -0
  9. package/dist/builder/card-contract.js +286 -0
  10. package/dist/builder/card-contract.js.map +1 -0
  11. package/dist/builder/card-placement.d.ts +45 -0
  12. package/dist/builder/card-placement.d.ts.map +1 -0
  13. package/dist/builder/card-placement.js +193 -0
  14. package/dist/builder/card-placement.js.map +1 -0
  15. package/dist/builder/card-report.d.ts +49 -0
  16. package/dist/builder/card-report.d.ts.map +1 -0
  17. package/dist/builder/card-report.js +97 -0
  18. package/dist/builder/card-report.js.map +1 -0
  19. package/dist/builder/cert-review-card.d.ts +7 -5
  20. package/dist/builder/cert-review-card.d.ts.map +1 -1
  21. package/dist/builder/cert-review-card.js +202 -170
  22. package/dist/builder/cert-review-card.js.map +1 -1
  23. package/dist/builder/contract-card.d.ts +70 -0
  24. package/dist/builder/contract-card.d.ts.map +1 -0
  25. package/dist/builder/contract-card.js +191 -0
  26. package/dist/builder/contract-card.js.map +1 -0
  27. package/dist/builder/delivered-face.d.ts +9 -0
  28. package/dist/builder/delivered-face.d.ts.map +1 -1
  29. package/dist/builder/delivered-face.js +18 -5
  30. package/dist/builder/delivered-face.js.map +1 -1
  31. package/dist/builder/delivery-runtime.d.ts +27 -3
  32. package/dist/builder/delivery-runtime.d.ts.map +1 -1
  33. package/dist/builder/delivery-runtime.js +40 -4
  34. package/dist/builder/delivery-runtime.js.map +1 -1
  35. package/dist/builder/index.d.ts +7 -4
  36. package/dist/builder/index.d.ts.map +1 -1
  37. package/dist/builder/index.js +8 -4
  38. package/dist/builder/index.js.map +1 -1
  39. package/dist/builder/ssr-seed.d.ts +23 -4
  40. package/dist/builder/ssr-seed.d.ts.map +1 -1
  41. package/dist/builder/ssr-seed.js +29 -6
  42. package/dist/builder/ssr-seed.js.map +1 -1
  43. package/dist/builder/version.d.ts +3 -0
  44. package/dist/builder/version.d.ts.map +1 -0
  45. package/dist/builder/version.js +3 -0
  46. package/dist/builder/version.js.map +1 -0
  47. package/dist/index.d.ts +1 -0
  48. package/dist/index.d.ts.map +1 -1
  49. package/dist/index.js +2 -0
  50. package/dist/index.js.map +1 -1
  51. package/dist/reader/reader-css.generated.d.ts +1 -1
  52. package/dist/reader/reader-css.generated.d.ts.map +1 -1
  53. package/dist/reader/reader-css.generated.js +1 -1
  54. package/dist/reader/reader-css.generated.js.map +1 -1
  55. package/dist/reader/render.d.ts.map +1 -1
  56. package/dist/reader/render.js +71 -34
  57. package/dist/reader/render.js.map +1 -1
  58. package/dist/reader/tokens.d.ts +2 -0
  59. package/dist/reader/tokens.d.ts.map +1 -1
  60. package/dist/reader/tokens.js +28 -6
  61. package/dist/reader/tokens.js.map +1 -1
  62. package/dist/verify/get-verified-delivery.d.ts +32 -0
  63. package/dist/verify/get-verified-delivery.d.ts.map +1 -1
  64. package/dist/verify/get-verified-delivery.js +30 -5
  65. package/dist/verify/get-verified-delivery.js.map +1 -1
  66. package/dist/verify/key-set.d.ts +67 -0
  67. package/dist/verify/key-set.d.ts.map +1 -0
  68. package/dist/verify/key-set.js +190 -0
  69. package/dist/verify/key-set.js.map +1 -0
  70. package/package.json +115 -112
  71. package/src/builder/card-beacon.ts +201 -0
  72. package/src/builder/card-contract.ts +336 -0
  73. package/src/builder/card-placement.ts +208 -0
  74. package/src/builder/card-report.ts +126 -0
  75. package/src/builder/cert-review-card.tsx +285 -201
  76. package/src/builder/contract-card.tsx +216 -0
  77. package/src/builder/delivered-face.ts +18 -4
  78. package/src/builder/delivery-runtime.ts +46 -4
  79. package/src/builder/index.tsx +16 -4
  80. package/src/builder/ssr-seed.ts +37 -7
  81. package/src/builder/version.ts +2 -0
  82. package/src/index.ts +9 -0
  83. package/src/reader/reader-css.generated.ts +1 -1
  84. package/src/reader/reader.css +297 -2
  85. package/src/reader/render.ts +87 -38
  86. package/src/reader/tokens.ts +29 -6
  87. package/src/verify/get-verified-delivery.ts +54 -5
  88. package/src/verify/key-set.ts +225 -0
@@ -1,6 +1,7 @@
1
1
  /**
2
2
  * ─────────────────────────────────────────────────────────────────────────────
3
- * `renderReaderFace` — the certrev.com "reader" face, as the Builder card paints it (1.2.0)
3
+ * `renderReaderFace` — the certrev.com "reader" face, as the Builder card paints it (1.2.0; caught up to the portal's
4
+ * one face in 1.3.1)
4
5
  * ─────────────────────────────────────────────────────────────────────────────
5
6
  *
6
7
  * The same markup, byte for byte, as the Shopify `certrev-reader-{banner,memo,sidebar,pill}` snippets, which are the
@@ -12,6 +13,17 @@
12
13
  * It is a NEW face, selected only by a delivered render def that says `face: 'reader'` (see `envelopeCardHtml`).
13
14
  * Nothing in the legacy `renderCertBlock` is read or changed here.
14
15
  *
16
+ * Since 1.3.1 it also follows the portal's ONE FACE, as the Shopify snippets and the WordPress plugin paint it:
17
+ * - the def's `rung` (credentialed and named: no memo, bio or photo, so the memo card is not printed and the banner
18
+ * and sidebar are the memo-less card; named: no credential either; minimal: the band and the links only; any other
19
+ * value is the memo rung);
20
+ * - the sidebar's phone fold: the bio and the memo are printed twice, once as the card's own pair and once inside a
21
+ * closed `<details class="certrev-r-more">` (the stylesheet shows one or the other: 640px and under, the fold);
22
+ * - a TONED def (an ink, or a surface that is not white) adds `certrev-r-toned` to the root and `--cr-sf` / `--cr-ink`
23
+ * to its style (`tokens.ts`); a def with no design paints the memo-rung defaults;
24
+ * - the banner's author takes the same 42px face as the reviewer, and the credential date never breaks
25
+ * (`<span class="certrev-r-nw">`).
26
+ *
15
27
  * The facts are read exactly as the snippets read the same envelope:
16
28
  * - the card renders only with a reviewer name (the memo and sidebar too); the pill needs only a verify URL;
17
29
  * - the credential is each credential's `cardLabel` (else `abbreviation`), joined; the "Credential verified by CertREV"
@@ -55,7 +67,7 @@ import {
55
67
  textOr,
56
68
  } from './helpers.js'
57
69
  import { readerLogo } from './logo.js'
58
- import { readerTokens } from './tokens.js'
70
+ import { isTonedStyle, readerTokens } from './tokens.js'
59
71
 
60
72
  export type ReaderLayout = 'banner' | 'sidebar' | 'floating'
61
73
 
@@ -85,6 +97,8 @@ export interface ReaderFaceInput {
85
97
  */
86
98
 
87
99
  /** What every section of one render shares: the facts read once from the envelope and the def. */
100
+ type Rung = 'memo' | 'credentialed' | 'named' | 'minimal'
101
+
88
102
  interface Facts {
89
103
  readonly content: Rec
90
104
  readonly expert: Rec
@@ -92,13 +106,20 @@ interface Facts {
92
106
  readonly def: unknown
93
107
  readonly certId: string
94
108
  readonly ename: string
95
- /** Whether a photo may be painted: neither `reviewerPhoto` hidden nor `showExpertPhoto: false`. */
109
+ /** The def's rung: `memo` unless it says `minimal`, `named` or `credentialed` (any other value is the memo rung). */
110
+ readonly rung: Rung
111
+ /** The minimal rung: the band and the links, nothing else. */
112
+ readonly minimal: boolean
113
+ /** Whether a photo may be painted: neither `reviewerPhoto` hidden nor `showExpertPhoto: false`, and the memo rung. */
96
114
  readonly showPhoto: boolean
97
- /** The joined credential labels, '' when there are none. */
115
+ /** The joined credential labels, '' when there are none or the rung shows none (named, minimal). */
98
116
  readonly creds: string
99
117
  readonly hasCue: boolean
100
118
  readonly illus: boolean
101
- readonly noMemo: boolean
119
+ /** Whether the memo is printed: there is one, and the rung is the memo rung. */
120
+ readonly hasMemo: boolean
121
+ /** Whether the root carries `certrev-r-toned` (the token style says so). */
122
+ readonly toned: boolean
102
123
  readonly purl: string
103
124
  readonly vurl: string
104
125
  readonly style: string
@@ -112,7 +133,9 @@ function readFacts(input: ReaderFaceInput): Facts {
112
133
  const def = input.def
113
134
  const rd = rec(def)
114
135
 
115
- const showPhoto = disp.showExpertPhoto !== false && !contains(rd.hidden, 'reviewerPhoto')
136
+ const rung: Rung = rd.rung === 'minimal' || rd.rung === 'named' || rd.rung === 'credentialed' ? rd.rung : 'memo'
137
+ const minimal = rung === 'minimal'
138
+ const showPhoto = disp.showExpertPhoto !== false && !contains(rd.hidden, 'reviewerPhoto') && rung === 'memo'
116
139
 
117
140
  // POR-9738: each credential's cardLabel over its bare abbreviation, joined with ', ' (labels are not trimmed).
118
141
  const labels: string[] = []
@@ -133,11 +156,14 @@ function readFacts(input: ReaderFaceInput): Facts {
133
156
  def,
134
157
  certId: asText(input.certId),
135
158
  ename: textOr(expert.displayName),
159
+ rung,
160
+ minimal,
136
161
  showPhoto,
137
- creds: labels.join(', '),
162
+ creds: rung === 'named' || minimal ? '' : labels.join(', '),
138
163
  hasCue,
139
164
  illus: input.illustrative === true && !hasCue,
140
- noMemo: isBlank(content.memo),
165
+ hasMemo: !isBlank(content.memo) && rung === 'memo',
166
+ toned: isTonedStyle(style),
141
167
  purl: cleaned(safeUrl(expert.profileUrl)),
142
168
  vurl: cleaned(safeUrl(content.verifyUrl)),
143
169
  style,
@@ -147,7 +173,7 @@ function readFacts(input: ReaderFaceInput): Facts {
147
173
 
148
174
  /** The `<section>` open tag every reader section shares. `badge` is the `.certrev-badge` hook the revalidation reads. */
149
175
  function sectionOpen(f: Facts, badge: boolean, aria: string): string {
150
- const cls = badge ? 'certrev-reader certrev-badge' : 'certrev-reader'
176
+ const cls = `certrev-reader${badge ? ' certrev-badge' : ''}${f.toned ? ' certrev-r-toned' : ''}`
151
177
  // `{% if rd %}`: any def that is not nil/false stamps its version.
152
178
  const version = isTruthy(f.def) ? ` data-certrev-def-version="${esc(rec(f.def).v)}"` : ''
153
179
  return (
@@ -165,7 +191,7 @@ const anchor = (href: string, modal: string, label: string): string =>
165
191
  * name the wording stays one leaf.
166
192
  */
167
193
  function profileLabel(f: Facts): string {
168
- const first = cleaned(firstName(f.ename))
194
+ const first = f.minimal ? '' : cleaned(firstName(f.ename))
169
195
  return first !== '' ? `View <!-- -->${esc(first)}<!-- -->&rsquo;s profile` : 'View profile'
170
196
  }
171
197
 
@@ -194,15 +220,15 @@ const SCOPE = CERT_SCOPE_LINE
194
220
  * The muted credential line, empty when the reviewer has no displayed credential (so no "verified" claim prints).
195
221
  *
196
222
  * The banner's is the demo's three leaves in one `<em>`: the credential, " · ", and the attribution, which reads
197
- * "Credential verified by CertREV on {date}" or, with no date, just "Credential verified by CertREV". The spans carry
198
- * no style of their own. The sidebar names the credential in its bold line already, so its `<em>` is the attribution
199
- * alone.
223
+ * "Credential verified by CertREV on {date}" or, with no date, just "Credential verified by CertREV". The banner's date
224
+ * sits in its own `<span class="certrev-r-nw">`, which the stylesheet never lets break. The sidebar names the credential
225
+ * in its bold line already, so its `<em>` is the attribution alone, and its date is plain text.
200
226
  */
201
227
  function verifiedLine(f: Facts, withCredentials: boolean): string {
202
228
  if (f.creds === '') return ''
203
229
  const date = cleaned(isBlank(f.expert.credentialVerifiedAt) ? '' : longDate(f.expert.credentialVerifiedAt))
204
- const on = date !== '' ? ` on ${esc(date)}` : ''
205
- if (!withCredentials) return `<em>Credential verified by CertREV${on}</em>`
230
+ if (!withCredentials) return `<em>Credential verified by CertREV${date !== '' ? ` on ${esc(date)}` : ''}</em>`
231
+ const on = date !== '' ? ` on <span class="certrev-r-nw">${esc(date)}</span>` : ''
206
232
  return `<em><span>${esc(f.creds)}</span> · <span>Credential verified by CertREV${on}</span></em>`
207
233
  }
208
234
 
@@ -215,24 +241,34 @@ function bannerCard(f: Facts): string {
215
241
  const author = rec(f.content.author)
216
242
  const authorName = textOr(author.name)
217
243
  const authorTitle = textOr(author.title)
218
- const hasAuthor = f.disp.showAuthor !== false && authorName !== '' && authorName !== f.ename
219
- const avatar = (photo: unknown, name: string, size: 'sm' | ''): string =>
220
- readerFace({ photo, show: f.showPhoto, name, size, width: 84 })
244
+ const hasAuthor = f.disp.showAuthor !== false && authorName !== '' && authorName !== f.ename && !f.minimal
245
+ // Both bylines take the same 42px face, photo or initials, at every width.
246
+ const avatar = (photo: unknown, name: string): string =>
247
+ readerFace({ photo, show: f.showPhoto, name, size: '', width: 84 })
221
248
 
222
249
  const authorBy = hasAuthor
223
- ? `<div class="certrev-r-by">${avatar(author.photoUrl, authorName, 'sm')}<div>\n <b>${esc(authorName)}</b>` +
250
+ ? `<div class="certrev-r-by">${avatar(author.photoUrl, authorName)}<div>\n <b>${esc(authorName)}</b>` +
224
251
  `${authorTitle !== '' ? `<em>${esc(authorTitle)}</em>` : ''}<span class="certrev-r-role">Written by</span>\n </div>\n </div>`
225
252
  : ''
226
253
  const expertBy =
227
- `<div class="certrev-r-by">${avatar(f.expert.photoUrl, f.ename, '')}<div>\n <b>${esc(f.ename)}</b>` +
254
+ `<div class="certrev-r-by">${avatar(f.expert.photoUrl, f.ename)}<div>\n <b>${esc(f.ename)}</b>` +
228
255
  `${verifiedLine(f, true)}<span class="certrev-r-role on">Reviewed by</span>\n </div>\n </div>`
256
+ // The minimal rung is the band and the links: no bylines, no date, no cue, no scope line.
257
+ const bys = f.minimal
258
+ ? ''
259
+ : `<div class="certrev-r-bys${hasAuthor ? '' : ' solo'}">${authorBy}${expertBy}\n </div>`
229
260
 
230
261
  const certifiedAt = f.content.certifiedAt
231
- const certified = isBlank(certifiedAt) ? '' : cleaned(longDate(certifiedAt))
262
+ const certified = f.minimal || isBlank(certifiedAt) ? '' : cleaned(longDate(certifiedAt))
263
+ const hasCue = f.hasCue && !f.minimal
264
+ const illus = f.illus && !f.minimal
265
+ // Without a printed memo (none, or a rung that prints none) this card is the sole claim face and carries the scope line.
266
+ const noMemo = !f.hasMemo
267
+ const scopeOn = noMemo && !f.minimal
232
268
 
233
269
  // A memo-less article gets the profile and certificate row, so the certificate stays reachable.
234
270
  let links = ''
235
- if (f.noMemo && (f.purl !== '' || f.vurl !== '')) {
271
+ if (noMemo && (f.purl !== '' || f.vurl !== '')) {
236
272
  links =
237
273
  '<div class="certrev-r-links">' +
238
274
  (f.purl !== '' ? anchor(f.purl, '="expert"', profileLabel(f)) : '') +
@@ -240,8 +276,8 @@ function bannerCard(f: Facts): string {
240
276
  '</div>'
241
277
  }
242
278
 
243
- const hasFoot = certified !== '' || f.hasCue || f.illus
244
- const rule = hasFoot || f.noMemo ? '<div class="certrev-r-rule"></div>' : ''
279
+ const hasFoot = certified !== '' || hasCue || illus
280
+ const rule = hasFoot || scopeOn ? '<div class="certrev-r-rule"></div>' : ''
245
281
 
246
282
  let foot = ''
247
283
  if (hasFoot) {
@@ -249,29 +285,29 @@ function bannerCard(f: Facts): string {
249
285
  // span paints the mono cue and the date's own face.
250
286
  const when = certified !== '' ? `<span><em>Certified</em>${esc(certified)}</span>` : '<span></span>'
251
287
  let cue = ''
252
- if (f.hasCue) {
288
+ if (hasCue) {
253
289
  // The locked cue in plain words, as the demo's foot (judge round 6, E1): no link, so nothing underlines
254
290
  // "expert"; the reviewer's profile is the card's or the memo's "View … profile" link.
255
291
  cue = `<span>${COMPENSATED_EXPERT_CUE}</span>`
256
- } else if (f.illus) {
292
+ } else if (illus) {
257
293
  cue = '<span>Illustrative example</span>'
258
294
  }
259
295
  foot = `<div class="certrev-r-foot">${when}${cue}</div>`
260
296
  }
261
297
 
262
298
  // POR-9317: the memo card carries the scope line when there is a memo; with none this card is the sole claim face.
263
- const scope = f.noMemo ? `<div class="certrev-r-scope" data-ftc-disclosure data-ftc-line>${SCOPE}</div>` : ''
299
+ const scope = scopeOn ? `<div class="certrev-r-scope" data-ftc-disclosure data-ftc-line>${SCOPE}</div>` : ''
264
300
 
265
301
  return (
266
- `${sectionOpen(f, true, credentialAria(f))}\n <div class="certrev-r-card">\n` +
267
- ` <div class="certrev-r-cap">${readerLogo(f.fg === '#ffffff' ? 'white' : 'mono', 18, 'CertREV')}Expert reviewed &amp; certified</div>\n` +
268
- ` <div class="certrev-r-cap-body">\n <div class="certrev-r-bys${hasAuthor ? '' : ' solo'}">${authorBy}${expertBy}\n </div>` +
302
+ `${sectionOpen(f, true, f.minimal ? 'Expert reviewed' : credentialAria(f))}\n <div class="certrev-r-card">\n` +
303
+ ` <div class="certrev-r-cap">${readerLogo(f.fg === '#ffffff' ? 'white' : 'mono', 18, 'CertREV')}Expert reviewed${f.minimal ? '' : ' &amp; certified'}</div>\n` +
304
+ ` <div class="certrev-r-cap-body">\n ${bys}` +
269
305
  `${links}${rule}${foot}${scope}</div>\n </div>\n</section>`
270
306
  )
271
307
  }
272
308
 
273
309
  function bannerMemo(f: Facts): string {
274
- if (f.ename === '' || isBlank(f.content.memo)) return ''
310
+ if (f.ename === '' || !f.hasMemo) return ''
275
311
  const links =
276
312
  f.purl !== '' || f.vurl !== ''
277
313
  ? '<div class="certrev-r-links">' +
@@ -298,8 +334,6 @@ function bannerMemo(f: Facts): string {
298
334
 
299
335
  function sidebar(f: Facts): string {
300
336
  if (f.ename === '') return ''
301
- const bio = f.disp.showBio !== false && !isBlank(f.expert.bio) ? asText(f.expert.bio) : ''
302
- const avatar = readerFace({ photo: f.expert.photoUrl, show: f.showPhoto, name: f.ename, size: 'lg', width: 112 })
303
337
  const both = f.purl !== '' && f.vurl !== ''
304
338
  const links =
305
339
  f.purl !== '' || f.vurl !== ''
@@ -308,13 +342,28 @@ function sidebar(f: Facts): string {
308
342
  (f.vurl !== '' ? anchor(f.vurl, '', 'View Certificate') : '') +
309
343
  '</div>'
310
344
  : ''
345
+ const open =
346
+ `${sectionOpen(f, true, f.minimal ? 'Expert reviewed' : credentialAria(f))}\n <div class="certrev-r-side">\n` +
347
+ ` <div class="certrev-r-cap center">${readerLogo(f.fg === '#ffffff' ? 'white' : 'mono', 18, 'CertREV')}Expert reviewed</div>\n `
348
+ // The minimal rung is the band and the links: no body at all.
349
+ if (f.minimal) return `${open}${links}</div>\n</section>`
350
+
351
+ const bio = f.disp.showBio !== false && !isBlank(f.expert.bio) && f.rung === 'memo' ? asText(f.expert.bio) : ''
352
+ const avatar = readerFace({ photo: f.expert.photoUrl, show: f.showPhoto, name: f.ename, size: 'lg', width: 112 })
353
+ // The bio and the memo are printed twice: as the card's own pair, and again inside a closed <details> the stylesheet
354
+ // shows instead on a phone (640px and under; owner decision 3d0838a4, plugin 1.8.3). The disclosure and both links
355
+ // stay outside the fold. With no memo the toggle says "About the expert"; with neither bio nor memo there is no fold.
356
+ const fold =
357
+ `${bio !== '' ? `<p>${esc(bio)}</p>` : ''}` +
358
+ `${f.hasMemo ? `<blockquote>${esc(f.content.memo)}</blockquote>` : ''}`
359
+ const more =
360
+ fold !== ''
361
+ ? `<details class="certrev-r-more"><summary>${f.hasMemo ? 'Read the expert memo' : 'About the expert'}</summary>${fold}</details>`
362
+ : ''
311
363
  return (
312
- `${sectionOpen(f, true, credentialAria(f))}\n <div class="certrev-r-side">\n` +
313
- ` <div class="certrev-r-cap center">${readerLogo(f.fg === '#ffffff' ? 'white' : 'mono', 18, 'CertREV')}Expert reviewed</div>\n` +
314
- ` <div class="certrev-r-side-body">\n <div class="certrev-r-by">${avatar}<div>\n` +
364
+ `${open}<div class="certrev-r-side-body">\n <div class="certrev-r-by">${avatar}<div>\n` +
315
365
  ` <b>${esc(f.ename)}${f.creds !== '' ? `<!-- -->, <!-- -->${esc(f.creds)}` : ''}</b>${verifiedLine(f, false)}</div>\n </div>` +
316
- `${bio !== '' ? `<p>${esc(bio)}</p>` : ''}` +
317
- `${isBlank(f.content.memo) ? '' : `<blockquote>${esc(f.content.memo)}</blockquote>`}` +
366
+ `${fold}${more}` +
318
367
  `<div class="certrev-r-scope" data-ftc-disclosure data-ftc-line>${scopeLead(f)}${SCOPE}</div>\n </div>` +
319
368
  `${links}</div>\n</section>`
320
369
  )
@@ -1,24 +1,32 @@
1
1
  /**
2
- * `certrev-reader-tokens`: the four CSS custom properties a reader section carries on its root, from the render def.
2
+ * `certrev-reader-tokens`: the CSS custom properties a reader section carries on its root, from the render def.
3
3
  *
4
4
  * --cr-ba the accent the card cap and pill paint: the def's `barInk`, else its `accentColor`, else navy
5
5
  * --cr-ba-fg the ink on that accent: white, or `#141414` when the def baked it for the colour that painted
6
6
  * --cr-br the corner radius
7
7
  * --cr-bf the font stack for the brand's `fontSlot`
8
+ * --cr-sf (toned face only) the card surface, the def's `surface`
9
+ * --cr-ink (toned face only) the card ink, the def's `inkColor`
8
10
  *
9
11
  * The values land inside a double-quoted `style` attribute, and they are held to the allow-list the Liquid snippet and
10
12
  * the PHP twin's def parser hold them to: a colour is `#RGB` or `#RRGGBB`, a radius one non-negative px / rem / em / %
11
- * length or a bare `0`, and anything else paints the default (navy, 14px). A denylist of characters is not enough: a
13
+ * length or a bare `0`, and anything else paints the default (navy `#0a1b3f`, 12px: the design guide's memo-rung
14
+ * defaults, as the plugin and the hosted embed paint a face with no design). A denylist of characters is not enough: a
12
15
  * quote, a backslash, a comment opener or a bracket left in a value hides the `;` that ends it and swallows the
13
16
  * declarations after it. The variable names are the reader stylesheet's (`reader.css`), which `.certrev-reader`
14
17
  * declares defaults for.
18
+ *
19
+ * A face is TONED when the def sets an ink, or a surface that is not white (`#fff` / `#ffffff`, either case): only
20
+ * then are `--cr-sf` / `--cr-ink` written (each only when valid), and the section root gains `certrev-r-toned`
21
+ * (`isTonedStyle`, which reads the style string as the snippets do).
15
22
  */
16
23
  import { asText } from '../components/escape.js'
17
24
  import { esc, rec, textOr } from './helpers.js'
18
25
 
19
- /** The accent when the def has none: CertREV navy. */
20
- const DEFAULT_ACCENT = '#0A1B3F'
21
- const DEFAULT_RADIUS = '14px'
26
+ /** The accent when the def has none: the design guide's memo-rung default (CertREV navy). */
27
+ const DEFAULT_ACCENT = '#0a1b3f'
28
+ /** The corner when the def has none: the design guide's memo-rung default. */
29
+ const DEFAULT_RADIUS = '12px'
22
30
  /** The foreground the def bakes for a light accent; anything else is the white default. */
23
31
  const DARK_INK = '#141414'
24
32
 
@@ -71,6 +79,9 @@ export interface ReaderTokens {
71
79
  readonly fg: string
72
80
  }
73
81
 
82
+ /** Whether a root `style` is a toned face's: the snippets' `cr_style contains ';--cr-sf:' or ';--cr-ink:'`. */
83
+ export const isTonedStyle = (style: string): boolean => style.includes(';--cr-sf:') || style.includes(';--cr-ink:')
84
+
74
85
  export function readerTokens(def: unknown): ReaderTokens {
75
86
  const rd = rec(def)
76
87
  const tokens = rec(rd.tokens)
@@ -90,5 +101,17 @@ export function readerTokens(def: unknown): ReaderTokens {
90
101
 
91
102
  const br = radius(tokens.cornerRadius) || DEFAULT_RADIUS
92
103
  const bf = fontStack(asText(tokens.fontSlot))
93
- return { style: `--cr-ba:${esc(ba)};--cr-ba-fg:${fg};--cr-br:${esc(br)};--cr-bf:${bf}`, fg }
104
+
105
+ // A toned face: an ink, or a surface that is not white. `downcase` in the snippet; the digits are ASCII.
106
+ const surface = hexColour(tokens.surface)
107
+ const ink = hexColour(tokens.inkColor)
108
+ const surfaceLc = surface.toLowerCase()
109
+ const toned = ink !== '' || (surface !== '' && surfaceLc !== '#fff' && surfaceLc !== '#ffffff')
110
+
111
+ let style = `--cr-ba:${esc(ba)};--cr-ba-fg:${fg};--cr-br:${esc(br)};--cr-bf:${bf}`
112
+ if (toned) {
113
+ if (surface !== '') style += `;--cr-sf:${esc(surface)}`
114
+ if (ink !== '') style += `;--cr-ink:${esc(ink)}`
115
+ }
116
+ return { style, fg }
94
117
  }
@@ -42,9 +42,18 @@
42
42
  * beside it, and `settleDelivery` hands it out only on a `render` verdict. NOTHING HERE VOUCHES FOR IT: the signature
43
43
  * does not cover it. What binds it is the signed `payload.content.faceDigest` (cert-contract 0.6.0), and a caller
44
44
  * paints it only after hashing it against that digest, as the Builder card does (`src/builder/delivered-face.ts`).
45
+ *
46
+ * 2.0.0: the response may also carry the contract-1 CARD DOCUMENT as a third UNSIGNED sibling, `card` (CertREV's portal
47
+ * serves it only for a brand on contract 1). It is kept exactly as served when it is a JSON object (any other value,
48
+ * `null` included, is no card), cached beside the payload, and handed out only on a `render` verdict. Like `face`,
49
+ * NOTHING HERE VOUCHES FOR IT: the signed `payload.content.faceDigest` binds it (`contract: 1`, `doc`), and the Builder
50
+ * card prints it only after its shape check and digest check pass (`src/builder/card-contract.ts`). A read with no
51
+ * card is the 1.3.1 object exactly. The read is made with `credentials: 'omit'`: it never sends a cookie.
45
52
  */
46
53
 
54
+ import { cardDocumentDigest } from '../builder/card-contract.js'
47
55
  import type { CertChromeRenderDef } from '../builder/cert-chrome-data.js'
56
+ import { type DeliveredFaceHashes, hashDeliveredFace } from '../builder/delivered-face.js'
48
57
  import type {
49
58
  CertDeliveryArtifact,
50
59
  CertPayload,
@@ -81,12 +90,24 @@ export type CachedDelivery =
81
90
  readonly signature?: CertSignature
82
91
  /** 1.3.0: the unsigned face sibling, when the response carried a well-formed one; else absent. */
83
92
  readonly face?: DeliveredFace
93
+ /** 2.0.0: the unsigned card-document sibling as served, when it was a JSON object; else absent. */
94
+ readonly card?: Readonly<Record<string, unknown>>
95
+ /**
96
+ * 2.0.0: the digest of `card` (lowercase hex sha256 of its RFC 8785 bytes; null when it cannot be computed),
97
+ * computed once by the read that cached it; present whenever `card` is. UNVERIFIED like the card: the caller
98
+ * compares it with the signed binding.
99
+ */
100
+ readonly cardDigest?: string | null
101
+ /** 2.0.0: the two hashes of `face`, computed once by the read; present whenever `face` is (null: no WebCrypto). */
102
+ readonly faceHashes?: DeliveredFaceHashes | null
84
103
  }
85
104
  | {
86
105
  readonly kind: 'suppressed'
87
106
  readonly reason: CertSuppressReason
88
107
  /** 1.2.0: true when CertREV was not reached (no answer about the credential); see the module header. */
89
108
  readonly unreachable?: true
109
+ /** 2.0.1: the HTTP status, when CertREV answered with a non-OK status other than 404/410. */
110
+ readonly status?: number
90
111
  }
91
112
 
92
113
  /** The answer for one render: the verdict AT THIS RENDER'S CLOCK, and the def to paint it with. */
@@ -98,11 +119,23 @@ export interface VerifiedDelivery {
98
119
  readonly signature?: CertSignature
99
120
  /** 1.2.0: on a suppress verdict, true when CertREV was not reached; else undefined. */
100
121
  readonly unreachable?: true
122
+ /** 2.0.1: with `unreachable`, the HTTP status when CertREV answered with one (a 5xx, a 429, ...); else undefined. */
123
+ readonly status?: number
101
124
  /**
102
125
  * 1.3.0: on a `render` verdict, the server-rendered face served beside the artifact, when the response carried a
103
126
  * well-formed one; else undefined (never on a suppress verdict). UNVERIFIED: see `DeliveredFace`.
104
127
  */
105
128
  readonly face?: DeliveredFace
129
+ /**
130
+ * 2.0.0: on a `render` verdict, the card document served beside the artifact (a JSON object, exactly as served);
131
+ * else undefined. UNVERIFIED: print it only after `parseCardDocument` and the digest check of
132
+ * `src/builder/card-contract.ts`, against the verified payload's `faceDigest`.
133
+ */
134
+ readonly card?: Readonly<Record<string, unknown>>
135
+ /** 2.0.0: `card`'s digest as the read computed it, beside `card`; see `CachedDelivery`. */
136
+ readonly cardDigest?: string | null
137
+ /** 2.0.0: `face`'s hashes as the read computed them, beside `face`; see `CachedDelivery`. */
138
+ readonly faceHashes?: DeliveredFaceHashes | null
106
139
  }
107
140
 
108
141
  export interface GetVerifiedDeliveryOptions {
@@ -146,8 +179,13 @@ function suppressed(reason: CertSuppressReason): CachedDelivery {
146
179
  }
147
180
 
148
181
  /** A read that did not reach CertREV: the same least-wrong reason as before 1.2.0, marked `unreachable`. */
149
- function unreachable(): CachedDelivery {
150
- return { kind: 'suppressed', reason: 'unsupported_contract_version', unreachable: true }
182
+ function unreachable(status?: number): CachedDelivery {
183
+ return {
184
+ kind: 'suppressed',
185
+ reason: 'unsupported_contract_version',
186
+ unreachable: true,
187
+ ...(status === undefined ? {} : { status }),
188
+ }
151
189
  }
152
190
 
153
191
  const isUnreachable = (v: CachedDelivery): boolean => v.kind === 'suppressed' && v.unreachable === true
@@ -273,7 +311,7 @@ async function loadDelivery(opts: GetVerifiedDeliveryOptions): Promise<CachedDel
273
311
  res = await fetchWithDeadline(
274
312
  fetchImpl,
275
313
  deliveryUrl(opts.baseUrl, opts.platform, opts.externalId, opts.design),
276
- { headers: { accept: 'application/json' } },
314
+ { headers: { accept: 'application/json' }, credentials: 'omit' },
277
315
  opts.timeoutMs ?? DEFAULT_FETCH_TIMEOUT_MS,
278
316
  )
279
317
  } catch {
@@ -283,7 +321,7 @@ async function loadDelivery(opts: GetVerifiedDeliveryOptions): Promise<CachedDel
283
321
  // Nothing served for this placement: never certified, or withdrawn. A LIVE revocation is a 200
284
322
  // tombstone, so a 4xx here genuinely means "no credential for this subject".
285
323
  if (res.status === 404 || res.status === 410) return suppressed('subject_mismatch')
286
- if (!res.ok) return unreachable()
324
+ if (!res.ok) return unreachable(res.status)
287
325
  let body: unknown
288
326
  try {
289
327
  body = await res.json()
@@ -304,12 +342,19 @@ async function loadDelivery(opts: GetVerifiedDeliveryOptions): Promise<CachedDel
304
342
  // A `render` verdict came from an envelope (a tombstone never renders), so `signature` is the one just verified.
305
343
  const signature = isRecord(body.signature) ? (body.signature as unknown as CertSignature) : undefined
306
344
  const face = parseDeliveredFace(body.face)
345
+ const card = isRecord(body.card) ? body.card : undefined
346
+ // 2.0.0: the digests a render compares with the signed binding, computed here, once per read, so a render that waited
347
+ // for this read never waits a second time. Under React 19, `use` matches promises by their order in a render: a
348
+ // second suspension (on a digest) after the first (on this read) was handed this read's result, and the card failed.
349
+ const cardDigest = card ? await cardDocumentDigest(card) : undefined
350
+ const faceHashes = face ? await hashDeliveredFace(face) : undefined
307
351
  return {
308
352
  kind: 'verified',
309
353
  payload: verdict.payload,
310
354
  renderDef: parseRenderDef(body.renderDef),
311
355
  ...(signature ? { signature } : {}),
312
- ...(face ? { face } : {}),
356
+ ...(face ? { face, faceHashes } : {}),
357
+ ...(card ? { card, cardDigest } : {}),
313
358
  }
314
359
  }
315
360
 
@@ -320,6 +365,7 @@ export function settleDelivery(cached: CachedDelivery, context: RenderContext):
320
365
  verdict: { decision: 'suppress', reason: cached.reason },
321
366
  renderDef: null,
322
367
  ...(cached.unreachable ? { unreachable: true as const } : {}),
368
+ ...(cached.unreachable && cached.status !== undefined ? { status: cached.status } : {}),
323
369
  }
324
370
  }
325
371
  const verdict = renderVerdict(cached.payload, context)
@@ -329,6 +375,9 @@ export function settleDelivery(cached: CachedDelivery, context: RenderContext):
329
375
  renderDef: cached.renderDef,
330
376
  ...(cached.signature ? { signature: cached.signature } : {}),
331
377
  ...(cached.face ? { face: cached.face } : {}),
378
+ ...(cached.faceHashes !== undefined ? { faceHashes: cached.faceHashes } : {}),
379
+ ...(cached.card ? { card: cached.card } : {}),
380
+ ...(cached.cardDigest !== undefined ? { cardDigest: cached.cardDigest } : {}),
332
381
  }
333
382
  }
334
383