@certrev/cert-block 1.2.0-canary.7 → 1.2.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/CHANGELOG.md +120 -63
- package/README.md +116 -21
- package/dist/builder/card-reader-css.d.ts +14 -0
- package/dist/builder/card-reader-css.d.ts.map +1 -0
- package/dist/builder/card-reader-css.js +17 -0
- package/dist/builder/card-reader-css.js.map +1 -0
- package/dist/builder/cert-review-card.d.ts +8 -0
- package/dist/builder/cert-review-card.d.ts.map +1 -1
- package/dist/builder/cert-review-card.js +234 -41
- package/dist/builder/cert-review-card.js.map +1 -1
- package/dist/builder/delivery-runtime.d.ts +15 -1
- package/dist/builder/delivery-runtime.d.ts.map +1 -1
- package/dist/builder/delivery-runtime.js +31 -3
- package/dist/builder/delivery-runtime.js.map +1 -1
- package/dist/builder/ssr-seed.d.ts +155 -0
- package/dist/builder/ssr-seed.d.ts.map +1 -0
- package/dist/builder/ssr-seed.js +278 -0
- package/dist/builder/ssr-seed.js.map +1 -0
- package/dist/verify/cache.d.ts +39 -2
- package/dist/verify/cache.d.ts.map +1 -1
- package/dist/verify/cache.js +61 -12
- package/dist/verify/cache.js.map +1 -1
- package/dist/verify/get-verified-delivery.d.ts +28 -3
- package/dist/verify/get-verified-delivery.d.ts.map +1 -1
- package/dist/verify/get-verified-delivery.js +46 -9
- package/dist/verify/get-verified-delivery.js.map +1 -1
- package/package.json +112 -112
- package/src/builder/card-reader-css.ts +19 -0
- package/src/builder/cert-review-card.tsx +308 -56
- package/src/builder/delivery-runtime.ts +33 -3
- package/src/builder/ssr-seed.ts +343 -0
- package/src/verify/cache.ts +87 -11
- package/src/verify/get-verified-delivery.ts +77 -11
package/dist/verify/cache.js
CHANGED
|
@@ -11,6 +11,13 @@
|
|
|
11
11
|
* ONE fetch, not N.
|
|
12
12
|
* 3. Negative-caches failures briefly so a hard-down origin doesn't get hammered, while
|
|
13
13
|
* still recovering quickly (short negative TTL).
|
|
14
|
+
* 4. (1.2.0, opt-in through `staleMs`) STALE-WHILE-REVALIDATE and STALE-IF-ERROR: a positive
|
|
15
|
+
* entry past its TTL but inside the stale window is served at once while ONE background
|
|
16
|
+
* refresh replaces it; a refresh that only failed to reach the origin (`isTransient`)
|
|
17
|
+
* keeps the stale entry instead of overwriting it. So an origin that is slow or briefly
|
|
18
|
+
* down costs the page nothing it already had. A definitive answer (a revocation, say)
|
|
19
|
+
* replaces the entry the moment the refresh lands. With the default `staleMs` of 0 an
|
|
20
|
+
* expired entry is gone, exactly as before 1.2.0.
|
|
14
21
|
*
|
|
15
22
|
* It is deliberately tiny + dependency-free (a Map + timestamps) so it runs in any server
|
|
16
23
|
* runtime (Node, edge, workerd). For multi-instance deployments this is per-instance L1 and
|
|
@@ -23,21 +30,47 @@ export class TtlCache {
|
|
|
23
30
|
ttlMs;
|
|
24
31
|
negativeTtlMs;
|
|
25
32
|
maxEntries;
|
|
33
|
+
staleMs;
|
|
34
|
+
inflightMaxMs;
|
|
26
35
|
now;
|
|
27
36
|
constructor(opts = {}) {
|
|
28
37
|
this.ttlMs = opts.ttlMs ?? 60_000;
|
|
29
38
|
this.negativeTtlMs = opts.negativeTtlMs ?? 5_000;
|
|
30
39
|
this.maxEntries = opts.maxEntries ?? 1000;
|
|
40
|
+
this.staleMs = opts.staleMs !== undefined && opts.staleMs > 0 ? opts.staleMs : 0;
|
|
41
|
+
this.inflightMaxMs = opts.inflightMaxMs ?? Number.POSITIVE_INFINITY;
|
|
31
42
|
this.now = opts.now ?? Date.now;
|
|
32
43
|
}
|
|
33
|
-
/**
|
|
34
|
-
|
|
44
|
+
/** The entry while it may still be served (fresh, or positive and inside the stale window); prunes it past that. */
|
|
45
|
+
servable(key) {
|
|
35
46
|
const e = this.store.get(key);
|
|
36
47
|
if (!e)
|
|
37
48
|
return undefined;
|
|
38
|
-
|
|
39
|
-
|
|
49
|
+
const now = this.now();
|
|
50
|
+
if (e.expiresAt > now)
|
|
51
|
+
return e;
|
|
52
|
+
if (!e.negative && now < e.expiresAt + this.staleMs)
|
|
53
|
+
return e;
|
|
54
|
+
this.store.delete(key);
|
|
55
|
+
return undefined;
|
|
56
|
+
}
|
|
57
|
+
/** Read a live (non-expired) entry, or undefined. Never serves a stale one; prunes an entry past its stale window. */
|
|
58
|
+
peek(key) {
|
|
59
|
+
const e = this.servable(key);
|
|
60
|
+
return e && e.expiresAt > this.now() ? e.value : undefined;
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* The synchronous stale-while-revalidate read: a fresh value; or a positive entry past its TTL but inside the stale
|
|
64
|
+
* window, returned at once while this starts (or joins) ONE background refresh through `loader`; else undefined,
|
|
65
|
+
* and the caller loads (`getOrLoad`). The refresh caches as `getOrLoad` does, with the same arguments; its failure
|
|
66
|
+
* is swallowed (the stale value was already served, and a thrown loader is never cached).
|
|
67
|
+
*/
|
|
68
|
+
peekOrRefresh(key, loader, isNegative, positiveTtlMs, isTransient) {
|
|
69
|
+
const e = this.servable(key);
|
|
70
|
+
if (!e)
|
|
40
71
|
return undefined;
|
|
72
|
+
if (e.expiresAt <= this.now()) {
|
|
73
|
+
this.load(key, loader, isNegative, positiveTtlMs, isTransient).catch(() => undefined);
|
|
41
74
|
}
|
|
42
75
|
return e.value;
|
|
43
76
|
}
|
|
@@ -54,23 +87,39 @@ export class TtlCache {
|
|
|
54
87
|
* It deliberately does NOT apply to a negative result: a caller asking for a 10-minute
|
|
55
88
|
* positive TTL is asking for fewer origin reads, not for a transient failure to be
|
|
56
89
|
* remembered for ten minutes (see the negative-TTL rationale in the module header).
|
|
90
|
+
*
|
|
91
|
+
* 1.2.0: inside the stale window (`staleMs`) an expired positive entry is returned at once and refreshed in the
|
|
92
|
+
* background (`peekOrRefresh`). `isTransient(value)` marks a result that says only "the origin was not reached"
|
|
93
|
+
* (a timeout, a 5xx): when a servable positive entry exists, such a result is NOT cached over it and the caller
|
|
94
|
+
* gets that entry's value instead (stale-if-error). With no entry to keep, it is cached as `isNegative` says.
|
|
57
95
|
*/
|
|
58
|
-
async getOrLoad(key, loader, isNegative, positiveTtlMs) {
|
|
59
|
-
const
|
|
60
|
-
if (
|
|
61
|
-
return
|
|
96
|
+
async getOrLoad(key, loader, isNegative, positiveTtlMs, isTransient) {
|
|
97
|
+
const served = this.peekOrRefresh(key, loader, isNegative, positiveTtlMs, isTransient);
|
|
98
|
+
if (served !== undefined)
|
|
99
|
+
return served;
|
|
100
|
+
return this.load(key, loader, isNegative, positiveTtlMs, isTransient);
|
|
101
|
+
}
|
|
102
|
+
/** Single-flight load and cache (joins an unsettled load younger than `inflightMaxMs`). */
|
|
103
|
+
load(key, loader, isNegative, positiveTtlMs, isTransient) {
|
|
62
104
|
const existing = this.inflight.get(key);
|
|
63
|
-
if (existing)
|
|
64
|
-
return existing;
|
|
105
|
+
if (existing && this.now() - existing.startedAt < this.inflightMaxMs)
|
|
106
|
+
return existing.promise;
|
|
65
107
|
const promise = (async () => {
|
|
66
108
|
const value = await loader();
|
|
109
|
+
if (isTransient?.(value)) {
|
|
110
|
+
const kept = this.servable(key);
|
|
111
|
+
if (kept && !kept.negative)
|
|
112
|
+
return kept.value;
|
|
113
|
+
}
|
|
67
114
|
const negative = isNegative ? isNegative(value) : false;
|
|
68
115
|
this.set(key, value, negative, negative ? undefined : positiveTtlMs);
|
|
69
116
|
return value;
|
|
70
117
|
})().finally(() => {
|
|
71
|
-
this.
|
|
118
|
+
// Only this load's own slot: a newer load that replaced an abandoned one keeps its place.
|
|
119
|
+
if (this.inflight.get(key)?.promise === promise)
|
|
120
|
+
this.inflight.delete(key);
|
|
72
121
|
});
|
|
73
|
-
this.inflight.set(key, promise);
|
|
122
|
+
this.inflight.set(key, { promise, startedAt: this.now() });
|
|
74
123
|
return promise;
|
|
75
124
|
}
|
|
76
125
|
/** Insert/overwrite an entry. `ttlMsOverride` replaces the TTL this write would otherwise
|
package/dist/verify/cache.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cache.js","sourceRoot":"","sources":["../../src/verify/cache.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"cache.js","sourceRoot":"","sources":["../../src/verify/cache.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AAoCH,MAAM,OAAO,QAAQ;IACH,KAAK,GAAG,IAAI,GAAG,EAAoB,CAAA;IACnC,QAAQ,GAAG,IAAI,GAAG,EAAuB,CAAA;IACzC,KAAK,CAAQ;IACb,aAAa,CAAQ;IACrB,UAAU,CAAQ;IAClB,OAAO,CAAQ;IACf,aAAa,CAAQ;IACrB,GAAG,CAAc;IAElC,YAAY,OAAwB,EAAE;QACrC,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC,KAAK,IAAI,MAAM,CAAA;QACjC,IAAI,CAAC,aAAa,GAAG,IAAI,CAAC,aAAa,IAAI,KAAK,CAAA;QAChD,IAAI,CAAC,UAAU,GAAG,IAAI,CAAC,UAAU,IAAI,IAAI,CAAA;QACzC,IAAI,CAAC,OAAO,GAAG,IAAI,CAAC,OAAO,KAAK,SAAS,IAAI,IAAI,CAAC,OAAO,GAAG,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,CAAA;QAChF,IAAI,CAAC,aAAa,GAAG,IAAI,CAAC,aAAa,IAAI,MAAM,CAAC,iBAAiB,CAAA;QACnE,IAAI,CAAC,GAAG,GAAG,IAAI,CAAC,GAAG,IAAI,IAAI,CAAC,GAAG,CAAA;IAChC,CAAC;IAED,oHAAoH;IAC5G,QAAQ,CAAC,GAAW;QAC3B,MAAM,CAAC,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,GAAG,CAAC,CAAA;QAC7B,IAAI,CAAC,CAAC;YAAE,OAAO,SAAS,CAAA;QACxB,MAAM,GAAG,GAAG,IAAI,CAAC,GAAG,EAAE,CAAA;QACtB,IAAI,CAAC,CAAC,SAAS,GAAG,GAAG;YAAE,OAAO,CAAC,C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G,IAAI,IAAI,CAAC,KAAK,CAAC,IAAI,EAAE,EAAE,CAAC;YACrC,IAAI,GAAG,CAAC,UAAU,CAAC,MAAM,CAAC;gBAAE,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,GAAG,CAAC,CAAA;QACnD,CAAC;IACF,CAAC;IAED,KAAK;QACJ,IAAI,CAAC,KAAK,CAAC,KAAK,EAAE,CAAA;QAClB,IAAI,CAAC,QAAQ,CAAC,KAAK,EAAE,CAAA;IACtB,CAAC;IAED,IAAI,IAAI;QACP,OAAO,IAAI,CAAC,KAAK,CAAC,IAAI,CAAA;IACvB,CAAC;CACD"}
|
|
@@ -29,24 +29,42 @@
|
|
|
29
29
|
* `peekVerifiedDelivery` is the synchronous read of the same cache: a React component suspends on
|
|
30
30
|
* `getVerifiedDelivery` once, then reads the settled value without a second promise (which is what
|
|
31
31
|
* keeps a streaming SSR render from suspending forever on a fresh promise every retry).
|
|
32
|
+
*
|
|
33
|
+
* 1.2.0: a suppressed read that only failed to REACH CertREV (the fetch threw or hit its deadline, a 5xx or other
|
|
34
|
+
* non-OK status but 404/410, a body that is not JSON or not an object) is marked `unreachable`. It says nothing
|
|
35
|
+
* about the credential, so a cache with a stale window keeps a verified entry over it (stale-if-error), and the
|
|
36
|
+
* card paints its options face instead of nothing. A definitive answer (404/410, a key or signature that does not
|
|
37
|
+
* verify, a revoked, expired or mismatched artifact) is never `unreachable`. `readVerifiedDelivery` is the
|
|
38
|
+
* synchronous read that also serves a stale entry while refreshing it.
|
|
32
39
|
*/
|
|
33
40
|
import type { CertChromeRenderDef } from '../builder/cert-chrome-data.js';
|
|
34
|
-
import type { CertPayload, CertSuppressReason, CertVerdict, RenderContext, ResolvePublicKeyByKid } from '../contract/kernel.js';
|
|
41
|
+
import type { CertPayload, CertSignature, CertSuppressReason, CertVerdict, RenderContext, ResolvePublicKeyByKid } from '../contract/kernel.js';
|
|
35
42
|
import { TtlCache } from './cache.js';
|
|
36
|
-
/**
|
|
43
|
+
/**
|
|
44
|
+
* What one Delivery read settles to, as cached: a verified payload + its def (and, from 1.2.0, the signature it
|
|
45
|
+
* verified with, so a server render can hand the signed envelope to the browser), or the reason not.
|
|
46
|
+
*/
|
|
37
47
|
export type CachedDelivery = {
|
|
38
48
|
readonly kind: 'verified';
|
|
39
49
|
readonly payload: CertPayload;
|
|
40
50
|
readonly renderDef: CertChromeRenderDef | null;
|
|
51
|
+
/** Absent only in a cache filled by hand (a test, a custom cache); a read always keeps it. */
|
|
52
|
+
readonly signature?: CertSignature;
|
|
41
53
|
} | {
|
|
42
54
|
readonly kind: 'suppressed';
|
|
43
55
|
readonly reason: CertSuppressReason;
|
|
56
|
+
/** 1.2.0: true when CertREV was not reached (no answer about the credential); see the module header. */
|
|
57
|
+
readonly unreachable?: true;
|
|
44
58
|
};
|
|
45
59
|
/** The answer for one render: the verdict AT THIS RENDER'S CLOCK, and the def to paint it with. */
|
|
46
60
|
export interface VerifiedDelivery {
|
|
47
61
|
readonly verdict: CertVerdict;
|
|
48
62
|
/** The brand's render def, or null (no def resolved, a malformed one, or a suppress verdict). */
|
|
49
63
|
readonly renderDef: CertChromeRenderDef | null;
|
|
64
|
+
/** The verified envelope's signature, on a `render` verdict whose read kept it; else undefined. */
|
|
65
|
+
readonly signature?: CertSignature;
|
|
66
|
+
/** 1.2.0: on a suppress verdict, true when CertREV was not reached; else undefined. */
|
|
67
|
+
readonly unreachable?: true;
|
|
50
68
|
}
|
|
51
69
|
export interface GetVerifiedDeliveryOptions {
|
|
52
70
|
/** Base URL of the CertREV app that serves the Delivery API, e.g. 'https://portal.certrev.com'. */
|
|
@@ -62,7 +80,7 @@ export interface GetVerifiedDeliveryOptions {
|
|
|
62
80
|
readonly cache?: TtlCache<CachedDelivery>;
|
|
63
81
|
/** TTL in ms for a VERIFIED read (default: the cache's positive TTL, 60_000 on the shared one). */
|
|
64
82
|
readonly ttlMs?: number;
|
|
65
|
-
/** Deadline in ms for the fetch (default `DEFAULT_FETCH_TIMEOUT_MS`, 3s). */
|
|
83
|
+
/** Deadline in ms for the fetch (default `DEFAULT_FETCH_TIMEOUT_MS`, 3s; the Builder card's runtime passes 8s). */
|
|
66
84
|
readonly timeoutMs?: number;
|
|
67
85
|
/**
|
|
68
86
|
* 1.2.0-canary.5: read one saved design version instead of the brand's live def. CertREV's own canary
|
|
@@ -118,6 +136,13 @@ export declare function settleDelivery(cached: CachedDelivery, context: RenderCo
|
|
|
118
136
|
* `context.now`, the payload is unrevoked, unexpired and for this placement.
|
|
119
137
|
*/
|
|
120
138
|
export declare function getVerifiedDelivery(opts: GetVerifiedDeliveryOptions): Promise<VerifiedDelivery>;
|
|
139
|
+
/**
|
|
140
|
+
* 1.2.0, the synchronous read a render uses: the settled answer for a fresh cached read; or, inside the cache's
|
|
141
|
+
* stale window, the stale read's answer at once while ONE background refresh (the same fetch `getVerifiedDelivery`
|
|
142
|
+
* makes) replaces it; else `undefined`, and the caller awaits `getVerifiedDelivery`. The verdict is still settled
|
|
143
|
+
* at `context.now`, so a stale payload that has expired or been revoked in its own fields still suppresses.
|
|
144
|
+
*/
|
|
145
|
+
export declare function readVerifiedDelivery(opts: GetVerifiedDeliveryOptions): VerifiedDelivery | undefined;
|
|
121
146
|
/**
|
|
122
147
|
* The synchronous read: the settled answer when a fresh read is cached, else `undefined` (the
|
|
123
148
|
* caller then awaits `getVerifiedDelivery`). Never fetches.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"get-verified-delivery.d.ts","sourceRoot":"","sources":["../../src/verify/get-verified-delivery.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"get-verified-delivery.d.ts","sourceRoot":"","sources":["../../src/verify/get-verified-delivery.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAsCG;AAEH,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,gCAAgC,CAAA;AACzE,OAAO,KAAK,EAEX,WAAW,EACX,aAAa,EACb,kBAAk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;GAIG;AACH,wBAAsB,mBAAmB,CAAC,IAAI,EAAE,0BAA0B,GAAG,OAAO,CAAC,gBAAgB,CAAC,CAUrG;AAED;;;;;GAKG;AACH,wBAAgB,oBAAoB,CAAC,IAAI,EAAE,0BAA0B,GAAG,gBAAgB,GAAG,SAAS,CAUnG;AAED;;;GAGG;AACH,wBAAgB,oBAAoB,CACnC,IAAI,EAAE,IAAI,CAAC,0BAA0B,EAAE,SAAS,GAAG,UAAU,GAAG,YAAY,GAAG,SAAS,GAAG,OAAO,GAAG,QAAQ,CAAC,GAC5G,gBAAgB,GAAG,SAAS,CAG9B;AAED,gHAAgH;AAChH,wBAAgB,kBAAkB,CACjC,IAAI,EAAE,IAAI,CAAC,0BAA0B,EAAE,SAAS,GAAG,UAAU,GAAG,YAAY,GAAG,SAAS,GAAG,QAAQ,CAAC,EACpG,KAAK,GAAE,QAAQ,CAAC,cAAc,CAAuB,GACnD,IAAI,CAEN;AAED,OAAO,EAAE,mBAAmB,EAAE,CAAA"}
|
|
@@ -29,6 +29,13 @@
|
|
|
29
29
|
* `peekVerifiedDelivery` is the synchronous read of the same cache: a React component suspends on
|
|
30
30
|
* `getVerifiedDelivery` once, then reads the settled value without a second promise (which is what
|
|
31
31
|
* keeps a streaming SSR render from suspending forever on a fresh promise every retry).
|
|
32
|
+
*
|
|
33
|
+
* 1.2.0: a suppressed read that only failed to REACH CertREV (the fetch threw or hit its deadline, a 5xx or other
|
|
34
|
+
* non-OK status but 404/410, a body that is not JSON or not an object) is marked `unreachable`. It says nothing
|
|
35
|
+
* about the credential, so a cache with a stale window keeps a verified entry over it (stale-if-error), and the
|
|
36
|
+
* card paints its options face instead of nothing. A definitive answer (404/410, a key or signature that does not
|
|
37
|
+
* verify, a revoked, expired or mismatched artifact) is never `unreachable`. `readVerifiedDelivery` is the
|
|
38
|
+
* synchronous read that also serves a stale entry while refreshing it.
|
|
32
39
|
*/
|
|
33
40
|
import { renderVerdict, verifyArtifact } from '../contract/kernel.js';
|
|
34
41
|
import { TtlCache } from './cache.js';
|
|
@@ -38,6 +45,11 @@ const sharedDeliveryCache = new TtlCache({ ttlMs: 60_000, negativeTtlMs: 5_000 }
|
|
|
38
45
|
function suppressed(reason) {
|
|
39
46
|
return { kind: 'suppressed', reason };
|
|
40
47
|
}
|
|
48
|
+
/** A read that did not reach CertREV: the same least-wrong reason as before 1.2.0, marked `unreachable`. */
|
|
49
|
+
function unreachable() {
|
|
50
|
+
return { kind: 'suppressed', reason: 'unsupported_contract_version', unreachable: true };
|
|
51
|
+
}
|
|
52
|
+
const isUnreachable = (v) => v.kind === 'suppressed' && v.unreachable === true;
|
|
41
53
|
/** The Delivery route; a design pin adds `?design=<v>` and, with a brand, `&designBrand=<brand>`. */
|
|
42
54
|
export function deliveryUrl(baseUrl, platform, externalId, design) {
|
|
43
55
|
const base = baseUrl.replace(/\/+$/, '');
|
|
@@ -151,23 +163,23 @@ async function loadDelivery(opts) {
|
|
|
151
163
|
}
|
|
152
164
|
catch {
|
|
153
165
|
// Unreachable, DNS/TLS, or the deadline. Same least-wrong member as getVerifiedEnvelope.
|
|
154
|
-
return
|
|
166
|
+
return unreachable();
|
|
155
167
|
}
|
|
156
168
|
// Nothing served for this placement: never certified, or withdrawn. A LIVE revocation is a 200
|
|
157
169
|
// tombstone, so a 4xx here genuinely means "no credential for this subject".
|
|
158
170
|
if (res.status === 404 || res.status === 410)
|
|
159
171
|
return suppressed('subject_mismatch');
|
|
160
172
|
if (!res.ok)
|
|
161
|
-
return
|
|
173
|
+
return unreachable();
|
|
162
174
|
let body;
|
|
163
175
|
try {
|
|
164
176
|
body = await res.json();
|
|
165
177
|
}
|
|
166
178
|
catch {
|
|
167
|
-
return
|
|
179
|
+
return unreachable();
|
|
168
180
|
}
|
|
169
181
|
if (!isRecord(body))
|
|
170
|
-
return
|
|
182
|
+
return unreachable();
|
|
171
183
|
let verdict;
|
|
172
184
|
try {
|
|
173
185
|
// `verifyArtifact`, so a tombstone verifies as itself and reports 'revoked'. The kernel reads
|
|
@@ -180,14 +192,28 @@ async function loadDelivery(opts) {
|
|
|
180
192
|
}
|
|
181
193
|
if (verdict.decision !== 'render')
|
|
182
194
|
return suppressed(verdict.reason);
|
|
183
|
-
|
|
195
|
+
// A `render` verdict came from an envelope (a tombstone never renders), so `signature` is the one just verified.
|
|
196
|
+
const signature = isRecord(body.signature) ? body.signature : undefined;
|
|
197
|
+
return {
|
|
198
|
+
kind: 'verified',
|
|
199
|
+
payload: verdict.payload,
|
|
200
|
+
renderDef: parseRenderDef(body.renderDef),
|
|
201
|
+
...(signature ? { signature } : {}),
|
|
202
|
+
};
|
|
184
203
|
}
|
|
185
204
|
/** Apply the render-time policy to a cached read: lifecycle + subject at THIS render's clock. */
|
|
186
205
|
export function settleDelivery(cached, context) {
|
|
187
|
-
if (cached.kind === 'suppressed')
|
|
188
|
-
return {
|
|
206
|
+
if (cached.kind === 'suppressed') {
|
|
207
|
+
return {
|
|
208
|
+
verdict: { decision: 'suppress', reason: cached.reason },
|
|
209
|
+
renderDef: null,
|
|
210
|
+
...(cached.unreachable ? { unreachable: true } : {}),
|
|
211
|
+
};
|
|
212
|
+
}
|
|
189
213
|
const verdict = renderVerdict(cached.payload, context);
|
|
190
|
-
|
|
214
|
+
if (verdict.decision !== 'render')
|
|
215
|
+
return { verdict, renderDef: null };
|
|
216
|
+
return { verdict, renderDef: cached.renderDef, ...(cached.signature ? { signature: cached.signature } : {}) };
|
|
191
217
|
}
|
|
192
218
|
/**
|
|
193
219
|
* Fetch (if needed), verify, cache, and settle one Delivery read for one placement. FAIL-CLOSED:
|
|
@@ -196,9 +222,20 @@ export function settleDelivery(cached, context) {
|
|
|
196
222
|
*/
|
|
197
223
|
export async function getVerifiedDelivery(opts) {
|
|
198
224
|
const cache = opts.cache ?? sharedDeliveryCache;
|
|
199
|
-
const cached = await cache.getOrLoad(deliveryCacheKey(opts), () => loadDelivery(opts), (v) => v.kind === 'suppressed', opts.ttlMs);
|
|
225
|
+
const cached = await cache.getOrLoad(deliveryCacheKey(opts), () => loadDelivery(opts), (v) => v.kind === 'suppressed', opts.ttlMs, isUnreachable);
|
|
200
226
|
return settleDelivery(cached, opts.context);
|
|
201
227
|
}
|
|
228
|
+
/**
|
|
229
|
+
* 1.2.0, the synchronous read a render uses: the settled answer for a fresh cached read; or, inside the cache's
|
|
230
|
+
* stale window, the stale read's answer at once while ONE background refresh (the same fetch `getVerifiedDelivery`
|
|
231
|
+
* makes) replaces it; else `undefined`, and the caller awaits `getVerifiedDelivery`. The verdict is still settled
|
|
232
|
+
* at `context.now`, so a stale payload that has expired or been revoked in its own fields still suppresses.
|
|
233
|
+
*/
|
|
234
|
+
export function readVerifiedDelivery(opts) {
|
|
235
|
+
const cache = opts.cache ?? sharedDeliveryCache;
|
|
236
|
+
const cached = cache.peekOrRefresh(deliveryCacheKey(opts), () => loadDelivery(opts), (v) => v.kind === 'suppressed', opts.ttlMs, isUnreachable);
|
|
237
|
+
return cached === undefined ? undefined : settleDelivery(cached, opts.context);
|
|
238
|
+
}
|
|
202
239
|
/**
|
|
203
240
|
* The synchronous read: the settled answer when a fresh read is cached, else `undefined` (the
|
|
204
241
|
* caller then awaits `getVerifiedDelivery`). Never fetches.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"get-verified-delivery.js","sourceRoot":"","sources":["../../src/verify/get-verified-delivery.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"get-verified-delivery.js","sourceRoot":"","sources":["../../src/verify/get-verified-delivery.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAsCG;AAYH,OAAO,EAAE,aAAa,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAA;AACrE,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAA;AACrC,OAAO,EAAE,wBAAwB,EAAE,iBAAiB,EAAE,MAAM,0BAA0B,CAAA;AAiEtF,kFAAkF;AAClF,MAAM,mBAAmB,GAAG,IA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
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
}
|
|
2
|
+
"name": "@certrev/cert-block",
|
|
3
|
+
"version": "1.2.0",
|
|
4
|
+
"description": "Headless render edge for the CertREV CertDeliveryEnvelope: SSR-safe React cert components, a framework-agnostic <certrev-badge> Web Component, a schema.org JSON-LD projector, and a fail-closed verify layer over the shared VerdictKernel.",
|
|
5
|
+
"repository": {
|
|
6
|
+
"type": "git",
|
|
7
|
+
"url": "git+https://github.com/CertREV/cert-kit.git",
|
|
8
|
+
"directory": "packages/cert-block"
|
|
9
|
+
},
|
|
10
|
+
"homepage": "https://github.com/CertREV/cert-kit/tree/HEAD/packages/cert-block#readme",
|
|
11
|
+
"bugs": {
|
|
12
|
+
"url": "https://github.com/CertREV/cert-kit/issues"
|
|
13
|
+
},
|
|
14
|
+
"type": "module",
|
|
15
|
+
"main": "./dist/index.js",
|
|
16
|
+
"types": "./dist/index.d.ts",
|
|
17
|
+
"exports": {
|
|
18
|
+
".": {
|
|
19
|
+
"types": "./dist/index.d.ts",
|
|
20
|
+
"default": "./dist/index.js"
|
|
21
|
+
},
|
|
22
|
+
"./builder": {
|
|
23
|
+
"types": "./dist/builder/index.d.ts",
|
|
24
|
+
"default": "./dist/builder/index.js"
|
|
25
|
+
},
|
|
26
|
+
"./builder/face": {
|
|
27
|
+
"types": "./dist/builder/envelope-face.d.ts",
|
|
28
|
+
"default": "./dist/builder/envelope-face.js"
|
|
29
|
+
},
|
|
30
|
+
"./reader": {
|
|
31
|
+
"types": "./dist/reader/index.d.ts",
|
|
32
|
+
"default": "./dist/reader/index.js"
|
|
33
|
+
},
|
|
34
|
+
"./reader.css": "./src/reader/reader.css",
|
|
35
|
+
"./webcomponent": {
|
|
36
|
+
"types": "./dist/webcomponent/certrev-badge.d.ts",
|
|
37
|
+
"default": "./dist/webcomponent/certrev-badge.js"
|
|
38
|
+
},
|
|
39
|
+
"./fixtures": {
|
|
40
|
+
"types": "./dist/contract/fixtures.d.ts",
|
|
41
|
+
"default": "./dist/contract/fixtures.js"
|
|
42
|
+
},
|
|
43
|
+
"./modal": {
|
|
44
|
+
"types": "./dist/modal/index.d.ts",
|
|
45
|
+
"default": "./dist/modal/index.js"
|
|
46
|
+
},
|
|
47
|
+
"./modal/placement": {
|
|
48
|
+
"types": "./dist/modal/placement.d.ts",
|
|
49
|
+
"default": "./dist/modal/placement.js"
|
|
50
|
+
},
|
|
51
|
+
"./modal/certrev-cert.js": "./dist/modal/certrev-cert.js"
|
|
52
|
+
},
|
|
53
|
+
"files": [
|
|
54
|
+
"dist",
|
|
55
|
+
"src",
|
|
56
|
+
"!src/**/__tests__",
|
|
57
|
+
"!src/**/*.test.ts",
|
|
58
|
+
"!src/**/*.test.tsx",
|
|
59
|
+
"README.md",
|
|
60
|
+
"CHANGELOG.md"
|
|
61
|
+
],
|
|
62
|
+
"publishConfig": {
|
|
63
|
+
"registry": "https://registry.npmjs.org",
|
|
64
|
+
"access": "public"
|
|
65
|
+
},
|
|
66
|
+
"publishTargets": [
|
|
67
|
+
"npmjs",
|
|
68
|
+
"github-packages"
|
|
69
|
+
],
|
|
70
|
+
"dependencies": {
|
|
71
|
+
"@certrev/cert-contract": "^0.5.0"
|
|
72
|
+
},
|
|
73
|
+
"peerDependencies": {
|
|
74
|
+
"react": ">=18.0.0"
|
|
75
|
+
},
|
|
76
|
+
"peerDependenciesMeta": {
|
|
77
|
+
"react": {
|
|
78
|
+
"optional": false
|
|
79
|
+
}
|
|
80
|
+
},
|
|
81
|
+
"devDependencies": {
|
|
82
|
+
"@testing-library/react": "^16.1.0",
|
|
83
|
+
"@types/node": "^20.0.0",
|
|
84
|
+
"@types/react": "^18.3.0",
|
|
85
|
+
"@types/react-dom": "^18.3.0",
|
|
86
|
+
"jsdom": "^25.0.0",
|
|
87
|
+
"react": "^18.3.1",
|
|
88
|
+
"react-dom": "^18.3.1",
|
|
89
|
+
"typescript": "^6.0.3",
|
|
90
|
+
"vitest": "^4.1.5"
|
|
91
|
+
},
|
|
92
|
+
"keywords": [
|
|
93
|
+
"certrev",
|
|
94
|
+
"certification",
|
|
95
|
+
"react",
|
|
96
|
+
"server-components",
|
|
97
|
+
"hydrogen",
|
|
98
|
+
"shopify",
|
|
99
|
+
"json-ld",
|
|
100
|
+
"schema-org",
|
|
101
|
+
"web-component",
|
|
102
|
+
"ed25519",
|
|
103
|
+
"ssr"
|
|
104
|
+
],
|
|
105
|
+
"license": "MIT",
|
|
106
|
+
"scripts": {
|
|
107
|
+
"build": "tsc && pnpm build:modal-bundle",
|
|
108
|
+
"build:modal-bundle": "pnpm dlx esbuild@0.27.7 src/modal/certrev-cert.entry.ts --bundle --minify --target=es2020 --format=iife --legal-comments=none --tsconfig-raw='{\"compilerOptions\":{\"target\":\"ES2017\",\"module\":\"esnext\",\"strict\":true}}' --banner:js='/* biome-ignore-all format: generated cert-badge bundle, see @certrev/cert-block src/modal/ */ /* biome-ignore-all lint: generated cert-badge bundle, see @certrev/cert-block src/modal/ */' --outfile=dist/modal/certrev-cert.js",
|
|
109
|
+
"refresh:reader": "node scripts/refresh-reader.mjs",
|
|
110
|
+
"typecheck": "tsc --noEmit",
|
|
111
|
+
"test": "vitest run"
|
|
112
|
+
}
|
|
113
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The reader stylesheet as the Builder card inlines it (1.2.0): `READER_CSS` without its remote `@font-face` rules.
|
|
3
|
+
*
|
|
4
|
+
* The portal's reader CSS loads its faces from `https://assets.certrev.com/fonts/…`. A storefront whose CSP
|
|
5
|
+
* `font-src` does not name that origin (e.l.f.'s live policy names `'self' data:` and a list of font CDNs, no
|
|
6
|
+
* CertREV origin) refuses each load and logs a violation, and the text falls back anyway. So the card ships only the
|
|
7
|
+
* `local()` fallback faces (Arial or Times New Roman under each family's metric overrides), which need no CSP at all:
|
|
8
|
+
* the face looks the same as it does on a page that blocks the remote fonts, with nothing refused. The portal and the
|
|
9
|
+
* Shopify reader keep `READER_CSS` unchanged.
|
|
10
|
+
*
|
|
11
|
+
* INTERNAL: not on the package `exports` map.
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
import { READER_CSS } from '../reader/reader-css.generated.js'
|
|
15
|
+
|
|
16
|
+
/** One `@font-face { … }` rule whose body has a `url(`; the reader CSS has no nested braces inside a face rule. */
|
|
17
|
+
const REMOTE_FONT_FACE = /@font-face\s*\{[^{}]*\burl\([^{}]*\}\s*/g
|
|
18
|
+
|
|
19
|
+
export const CARD_READER_CSS = READER_CSS.replace(REMOTE_FONT_FACE, '')
|