@asstio-dev/storefront 0.46.0 → 0.47.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 +21 -2
- package/dist/account/browser.d.ts +65 -3
- package/dist/account/browser.js +79 -5
- package/dist/account/cookies.d.ts +10 -0
- package/dist/account/cookies.js +7 -0
- package/dist/account/index.d.ts +7 -1
- package/dist/account/index.js +9 -8
- package/dist/account/next.d.ts +103 -2
- package/dist/account/next.js +236 -4
- package/dist/analytics/events.d.ts +3 -1
- package/dist/analytics/events.js +3 -1
- package/dist/consent/codec.d.ts +141 -0
- package/dist/consent/codec.js +239 -0
- package/dist/consent/coordinator.d.ts +107 -0
- package/dist/consent/coordinator.js +608 -0
- package/dist/consent/index.d.ts +8 -0
- package/dist/consent/index.js +8 -0
- package/dist/consent/notice.d.ts +10 -0
- package/dist/consent/notice.js +11 -0
- package/dist/consent/server.d.ts +36 -0
- package/dist/consent/server.js +45 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +1 -0
- package/dist/schema.d.ts +2145 -170
- package/package.json +12 -3
- package/src/schema.d.ts +2145 -170
|
@@ -0,0 +1,239 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The consent cookie codec (shopper-state spec §7.4, S36): the **one** parser and comparison for the browser coordinator and
|
|
3
|
+
* for SSR (round-11 note 3). Pure: no DOM, no Node, no I/O.
|
|
4
|
+
*
|
|
5
|
+
* - `__Host-sf_consent` holds `"1." + base64url(JSON)` of a `ConsentCookie`: the locked shape (written under the `sf-consent`
|
|
6
|
+
* Web Lock) or the fallback value a lockless withdrawal blind-writes (nothing granted on this device).
|
|
7
|
+
* - `__Host-sf_consent_off` holds `"1." + <decimal ms> + "." + <16 hex mark>`: the latest refusal (a lockless withdrawal or an
|
|
8
|
+
* erasure). Every refusal writes a **fresh, never reused** random mark. A grant records the mark it observed when it was decided
|
|
9
|
+
* (`off`, absent when there was no refusal cookie), and counts only while that mark is still the current one **and** its decision
|
|
10
|
+
* time `at` is later than the refusal time (`grantedFor`); a lock holder folds every other grant into `withdrawn` (`fold`). The mark
|
|
11
|
+
* makes the rule race-safe: two lockless refusals can land in any order (an older time may overwrite a newer one), but a grant
|
|
12
|
+
* decided before either of them never observed the mark that ends up in the cookie, so it never counts again (review #1).
|
|
13
|
+
*
|
|
14
|
+
* Anything that does not parse is not granted, for every purpose and every reader.
|
|
15
|
+
*/
|
|
16
|
+
import { cookieSecurity } from "../account/cookies.js";
|
|
17
|
+
export const PURPOSES = ["measurement", "personalization"];
|
|
18
|
+
/** At most this many `unsynced` entries; a further key is not stored (`withEntry`). */
|
|
19
|
+
export const MAX_UNSYNCED = 8;
|
|
20
|
+
/** The coordinator's transport timeout: an `AbortSignal` on every `put`; a timed-out `put` is `not_saved`. */
|
|
21
|
+
export const PUT_TIMEOUT_MS = 30_000;
|
|
22
|
+
/** A `pending` marker is abandoned once `now - startedAt > PENDING_TTL_MS` (twice `PUT_TIMEOUT_MS`). */
|
|
23
|
+
export const PENDING_TTL_MS = 2 * PUT_TIMEOUT_MS;
|
|
24
|
+
/** The encoded main cookie's upper bound; with its name and attributes it stays below 4096. */
|
|
25
|
+
export const MAX_CONSENT_COOKIE_LENGTH = 3000;
|
|
26
|
+
/** The locked shape's sequence range is `[0, 2^40 - 1]`; a fallback `fence` is `S + 2^40` (PL6, S36). */
|
|
27
|
+
export const SEQ_LIMIT = 2 ** 40;
|
|
28
|
+
/** The main cookie's base name (the `__Host-` prefix is dropped on http://localhost, as for every SDK cookie). */
|
|
29
|
+
export const CONSENT_COOKIE = "sf_consent";
|
|
30
|
+
/** The refusal-time cookie's base name. */
|
|
31
|
+
export const CONSENT_OFF_COOKIE = "sf_consent_off";
|
|
32
|
+
/** The main cookie lives 12 months. */
|
|
33
|
+
export const CONSENT_COOKIE_SECONDS = 365 * 24 * 3600;
|
|
34
|
+
/** The refusal cookie lives 400 days, the browser maximum (PL6). */
|
|
35
|
+
export const CONSENT_OFF_COOKIE_SECONDS = 400 * 24 * 3600;
|
|
36
|
+
/** The two consent cookie names for the frontend's origin. */
|
|
37
|
+
export function consentCookieNames(origin) {
|
|
38
|
+
const secure = origin === undefined ? true : cookieSecurity(origin).secure;
|
|
39
|
+
const prefix = secure ? "__Host-" : "";
|
|
40
|
+
return { consent: prefix + CONSENT_COOKIE, off: prefix + CONSENT_OFF_COOKIE };
|
|
41
|
+
}
|
|
42
|
+
export class ConsentCookieTooLarge extends Error {
|
|
43
|
+
length;
|
|
44
|
+
constructor(length) {
|
|
45
|
+
super(`The encoded consent cookie is ${length} characters, above ${MAX_CONSENT_COOKIE_LENGTH}.`);
|
|
46
|
+
this.length = length;
|
|
47
|
+
this.name = "ConsentCookieTooLarge";
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
export const isFallback = (c) => c.fallback === true;
|
|
51
|
+
const HEX32 = /^[0-9a-f]{32}$/;
|
|
52
|
+
const SITE = /^[a-z0-9][a-z0-9-]{0,39}$/;
|
|
53
|
+
const ENTRY_OWNER = /^(t\.[0-9a-f]{16}|a\.[0-9a-f]{32})$/;
|
|
54
|
+
const PENDING_OWNER = /^(t\.[0-9a-f]{16}|a\.[0-9a-f]{32}|none)$/;
|
|
55
|
+
const BASE64URL = /^[A-Za-z0-9_-]+$/;
|
|
56
|
+
const MARK = /^[0-9a-f]{16}$/;
|
|
57
|
+
const REFUSAL = /^1\.([1-9][0-9]{0,15})\.([0-9a-f]{16})$/;
|
|
58
|
+
const isObject = (v) => typeof v === "object" && v !== null && !Array.isArray(v);
|
|
59
|
+
const isSeq = (v) => Number.isSafeInteger(v) && v >= 0 && v < SEQ_LIMIT;
|
|
60
|
+
const isTime = (v) => Number.isSafeInteger(v) && v > 0;
|
|
61
|
+
const isCount = (v) => Number.isSafeInteger(v) && v >= 0;
|
|
62
|
+
const isPurpose = (v) => v === "measurement" || v === "personalization";
|
|
63
|
+
const isMark = (v) => typeof v === "string" && MARK.test(v);
|
|
64
|
+
function encode(text) {
|
|
65
|
+
let binary = "";
|
|
66
|
+
for (const byte of new TextEncoder().encode(text))
|
|
67
|
+
binary += String.fromCharCode(byte);
|
|
68
|
+
return btoa(binary).replace(/\+/g, "-").replace(/\//g, "_").replace(/=+$/, "");
|
|
69
|
+
}
|
|
70
|
+
function decode(text) {
|
|
71
|
+
if (!BASE64URL.test(text))
|
|
72
|
+
throw new Error("not base64url");
|
|
73
|
+
const binary = atob(text.replace(/-/g, "+").replace(/_/g, "/"));
|
|
74
|
+
return new TextDecoder("utf-8", { fatal: true }).decode(Uint8Array.from(binary, (c) => c.charCodeAt(0)));
|
|
75
|
+
}
|
|
76
|
+
function validEntry(e) {
|
|
77
|
+
return isObject(e) && typeof e.site === "string" && SITE.test(e.site) && isPurpose(e.purpose)
|
|
78
|
+
&& typeof e.owner === "string" && ENTRY_OWNER.test(e.owner) && typeof e.device === "string" && HEX32.test(e.device) && isSeq(e.seq);
|
|
79
|
+
}
|
|
80
|
+
function validState(s) {
|
|
81
|
+
if (!isObject(s) || (s.state !== "granted" && s.state !== "withdrawn" && s.state !== "unset") || !isSeq(s.seq) || !isTime(s.at))
|
|
82
|
+
return false;
|
|
83
|
+
if (s.off !== undefined && (s.state !== "granted" || !isMark(s.off)))
|
|
84
|
+
return false;
|
|
85
|
+
if (s.pending === undefined)
|
|
86
|
+
return true;
|
|
87
|
+
const p = s.pending;
|
|
88
|
+
return isObject(p) && isSeq(p.seq) && isTime(p.at) && typeof p.owner === "string" && PENDING_OWNER.test(p.owner) && isTime(p.startedAt)
|
|
89
|
+
&& (p.off === undefined || isMark(p.off));
|
|
90
|
+
}
|
|
91
|
+
function validShared(c) {
|
|
92
|
+
return c.v === 1 && typeof c.device === "string" && HEX32.test(c.device)
|
|
93
|
+
&& Array.isArray(c.unsynced) && c.unsynced.length <= MAX_UNSYNCED && c.unsynced.every(validEntry) && isCount(c.overflow);
|
|
94
|
+
}
|
|
95
|
+
function validPurposes(p) {
|
|
96
|
+
return isObject(p) && Object.entries(p).every(([k, s]) => isPurpose(k) && validState(s));
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* The main cookie's value back, or null for a missing value and for **any** shape error: a missing `"1."` prefix, bad base64url or
|
|
100
|
+
* JSON, an unknown `v`, a device that is not 32 lowercase hex, a sequence outside `[0, 2^40 - 1]` (locked shape) or a fence outside
|
|
101
|
+
* `[2^40, 2^41 - 1]` (fallback), a time that is not a positive integer, an unknown purpose, a bad site, an `unsynced` owner that is
|
|
102
|
+
* not `t.<16 hex>`/`a.<32 hex>`, a `pending.owner` that is not one of those or `none`, an `off` mark that is not 16 lowercase hex
|
|
103
|
+
* (or one on a state that is not `granted`), more than `MAX_UNSYNCED` entries.
|
|
104
|
+
*/
|
|
105
|
+
export function parseConsent(raw) {
|
|
106
|
+
if (!raw || !raw.startsWith("1."))
|
|
107
|
+
return null;
|
|
108
|
+
let value;
|
|
109
|
+
try {
|
|
110
|
+
value = JSON.parse(decode(raw.slice(2)));
|
|
111
|
+
}
|
|
112
|
+
catch {
|
|
113
|
+
return null;
|
|
114
|
+
}
|
|
115
|
+
if (!isObject(value) || !validShared(value))
|
|
116
|
+
return null;
|
|
117
|
+
const unsynced = value.unsynced.map((e) => ({ site: e.site, purpose: e.purpose, owner: e.owner, device: e.device, seq: e.seq }));
|
|
118
|
+
if (value.fallback !== undefined) {
|
|
119
|
+
if (value.fallback !== true || !Number.isSafeInteger(value.fence) || value.fence < SEQ_LIMIT
|
|
120
|
+
|| value.fence >= 2 * SEQ_LIMIT || !isTime(value.fencedAt))
|
|
121
|
+
return null;
|
|
122
|
+
return { v: 1, fallback: true, device: value.device, fence: value.fence, fencedAt: value.fencedAt, unsynced, overflow: value.overflow };
|
|
123
|
+
}
|
|
124
|
+
if (!isSeq(value.seq) || !isTime(value.at) || !validPurposes(value.purposes) || (value.ref !== null && typeof value.ref !== "string"))
|
|
125
|
+
return null;
|
|
126
|
+
const purposes = {};
|
|
127
|
+
for (const [k, s] of Object.entries(value.purposes)) {
|
|
128
|
+
const pending = s.pending
|
|
129
|
+
? { pending: { seq: s.pending.seq, at: s.pending.at, owner: s.pending.owner, startedAt: s.pending.startedAt, ...(s.pending.off !== undefined ? { off: s.pending.off } : {}) } }
|
|
130
|
+
: {};
|
|
131
|
+
purposes[k] = { state: s.state, seq: s.seq, at: s.at, ...(s.off !== undefined ? { off: s.off } : {}), ...pending };
|
|
132
|
+
}
|
|
133
|
+
return { v: 1, device: value.device, seq: value.seq, purposes, ref: value.ref, at: value.at, unsynced, overflow: value.overflow };
|
|
134
|
+
}
|
|
135
|
+
/**
|
|
136
|
+
* The refusal cookie's value back: `{ at, mark }`, `"malformed"` for a present value that is not
|
|
137
|
+
* `"1." + <positive integer ms> + "." + <16 lowercase hex>`, null when absent.
|
|
138
|
+
*/
|
|
139
|
+
export function parseRefusal(raw) {
|
|
140
|
+
if (raw === undefined)
|
|
141
|
+
return null;
|
|
142
|
+
const m = REFUSAL.exec(raw);
|
|
143
|
+
const at = m ? Number(m[1]) : NaN;
|
|
144
|
+
return m && Number.isSafeInteger(at) ? { at, mark: m[2] } : "malformed";
|
|
145
|
+
}
|
|
146
|
+
/** The refusal cookie's value for a refusal. Every refusal passes a fresh random `mark` (16 lowercase hex), never a reused one. */
|
|
147
|
+
export function serializeRefusal(r) {
|
|
148
|
+
if (!isTime(r.at))
|
|
149
|
+
throw new RangeError(`A refusal time must be a positive integer, got ${r.at}.`);
|
|
150
|
+
if (!isMark(r.mark))
|
|
151
|
+
throw new RangeError("A refusal mark is 16 lowercase hex digits.");
|
|
152
|
+
return `1.${r.at}.${r.mark}`;
|
|
153
|
+
}
|
|
154
|
+
/** The mark of a refusal cookie, or undefined when there is none (null) — and for a malformed one, which blocks every grant anyway. */
|
|
155
|
+
export function refusalMark(off) {
|
|
156
|
+
return off !== null && off !== "malformed" ? off.mark : undefined;
|
|
157
|
+
}
|
|
158
|
+
/**
|
|
159
|
+
* True when the refusal cookie blocks a grant decided at `at` that observed refusal mark `mark` (undefined: no refusal cookie then):
|
|
160
|
+
* a malformed refusal; a current mark other than the observed one (absent ↔ absent); or a decision not later than the refusal time.
|
|
161
|
+
*/
|
|
162
|
+
export function refusalBlocks(off, at, mark) {
|
|
163
|
+
if (off === "malformed")
|
|
164
|
+
return true;
|
|
165
|
+
if (off === null)
|
|
166
|
+
return mark !== undefined;
|
|
167
|
+
return off.mark !== mark || at <= off.at;
|
|
168
|
+
}
|
|
169
|
+
/** The main cookie's value. Throws `ConsentCookieTooLarge` above `MAX_CONSENT_COOKIE_LENGTH` characters. */
|
|
170
|
+
export function serializeConsent(c) {
|
|
171
|
+
const value = "1." + encode(JSON.stringify(c));
|
|
172
|
+
if (value.length > MAX_CONSENT_COOKIE_LENGTH)
|
|
173
|
+
throw new ConsentCookieTooLarge(value.length);
|
|
174
|
+
return value;
|
|
175
|
+
}
|
|
176
|
+
const sameKey = (a, b) => a.site === b.site && a.purpose === b.purpose && a.owner === b.owner;
|
|
177
|
+
/**
|
|
178
|
+
* Stores a withdrawal's `unsynced` entry. The same `(site, purpose, owner)` key replaces the old entry (a newer decision supersedes
|
|
179
|
+
* it); a new key is appended while fewer than `MAX_UNSYNCED` exist. At capacity nothing is dropped: the cookie comes back with
|
|
180
|
+
* `overflow + 1` and `stored: false` (the refusal itself is already in `purposes`; the caller reports `not_saved`).
|
|
181
|
+
*/
|
|
182
|
+
export function withEntry(c, entry) {
|
|
183
|
+
const copy = { ...entry };
|
|
184
|
+
const at = c.unsynced.findIndex((e) => sameKey(e, entry));
|
|
185
|
+
if (at >= 0)
|
|
186
|
+
return { cookie: { ...c, unsynced: c.unsynced.map((e, i) => (i === at ? copy : e)) }, stored: true };
|
|
187
|
+
if (c.unsynced.length < MAX_UNSYNCED)
|
|
188
|
+
return { cookie: { ...c, unsynced: [...c.unsynced, copy] }, stored: true };
|
|
189
|
+
return { cookie: { ...c, overflow: c.overflow + 1 }, stored: false };
|
|
190
|
+
}
|
|
191
|
+
/**
|
|
192
|
+
* Removes the entries `pred` selects — only for the spec's reasons: an acknowledgement (match the full identity), a grant of the same
|
|
193
|
+
* `(site, purpose, owner)` when it is allocated, the adoption of that token, `404 SHOPPER_TOKEN_UNKNOWN` for that token. Freeing
|
|
194
|
+
* room resets `overflow` to 0.
|
|
195
|
+
*/
|
|
196
|
+
export function withoutEntries(c, pred) {
|
|
197
|
+
const kept = c.unsynced.filter((e) => !pred(e));
|
|
198
|
+
return kept.length === c.unsynced.length ? c : { ...c, unsynced: kept, overflow: 0 };
|
|
199
|
+
}
|
|
200
|
+
/**
|
|
201
|
+
* The one comparison (S30, S36): granted iff the cookie is the locked shape, the purpose is `granted`, the refusal mark it observed
|
|
202
|
+
* is still the current one (no refusal cookie then and now, or the same mark), and its decision time is later than the refusal time.
|
|
203
|
+
* A fallback value, a missing or unparsable cookie, a malformed refusal, another mark → false.
|
|
204
|
+
*/
|
|
205
|
+
export function grantedFor(c, off, purpose) {
|
|
206
|
+
if (c === null || isFallback(c))
|
|
207
|
+
return false;
|
|
208
|
+
const s = c.purposes[purpose];
|
|
209
|
+
if (s?.state !== "granted")
|
|
210
|
+
return false;
|
|
211
|
+
return !refusalBlocks(off, s.at, s.off);
|
|
212
|
+
}
|
|
213
|
+
/**
|
|
214
|
+
* Folds the refusal into the main cookie (round-11 notes 1, 2; review #1): every `granted` purpose the refusal blocks
|
|
215
|
+
* (`refusalBlocks`: decided at or before it, or under another mark; every one when the refusal is malformed) becomes `withdrawn`,
|
|
216
|
+
* keeping its `seq` and `at` (its mark is dropped); a `pending` grant the refusal blocks loses its `pending`. Nothing else changes,
|
|
217
|
+
* so a later loss of the refusal cookie cannot revive a grant.
|
|
218
|
+
*/
|
|
219
|
+
export function fold(c, off) {
|
|
220
|
+
if (isFallback(c))
|
|
221
|
+
return c;
|
|
222
|
+
const purposes = {};
|
|
223
|
+
let changed = false;
|
|
224
|
+
for (const [k, s] of Object.entries(c.purposes)) {
|
|
225
|
+
let next = s;
|
|
226
|
+
if (s.state === "granted" && refusalBlocks(off, s.at, s.off)) {
|
|
227
|
+
const { off: _mark, ...rest } = next;
|
|
228
|
+
next = { ...rest, state: "withdrawn" };
|
|
229
|
+
}
|
|
230
|
+
if (s.pending && refusalBlocks(off, s.pending.at, s.pending.off)) {
|
|
231
|
+
const { pending: _dropped, ...rest } = next;
|
|
232
|
+
next = rest;
|
|
233
|
+
}
|
|
234
|
+
if (next !== s)
|
|
235
|
+
changed = true;
|
|
236
|
+
purposes[k] = next;
|
|
237
|
+
}
|
|
238
|
+
return changed ? { ...c, purposes } : c;
|
|
239
|
+
}
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The consent coordinator (shopper-state spec S36, §7.3–§7.5): the browser's **one writer** of `__Host-sf_consent`.
|
|
3
|
+
*
|
|
4
|
+
* - A withdrawal is local first: `effective()` refuses it synchronously at `set()`, the cookie says `withdrawn` with an `unsynced`
|
|
5
|
+
* entry before the `PUT` goes, and no answer ever restores a grant.
|
|
6
|
+
* - A grant reaches the cookie only after the server applied it **and** it is still the device's latest decision for the purpose.
|
|
7
|
+
* - Every cookie change runs inside the `sf-consent` Web Lock with no `await` but cookie reads and writes; every network call is
|
|
8
|
+
* outside it. Without a lock (absent, or rejected twice) the coordinator submits no grant and never reads-modifies-writes: a
|
|
9
|
+
* withdrawal blind-writes a fresh refusal (time + never-reused mark) and the fallback value and sends one fenced `PUT`.
|
|
10
|
+
* - A grant carries the refusal mark it observed when it was decided; it counts only while that mark is still the current one and
|
|
11
|
+
* its decision time is later than the refusal time (`refusalBlocks`), so no ordering of lockless refusals can revive it.
|
|
12
|
+
*
|
|
13
|
+
* Browser-only: it throws when `window` is undefined and no `cookies` jar is injected.
|
|
14
|
+
*/
|
|
15
|
+
import type { AccountResult } from "../account/index.js";
|
|
16
|
+
import type { components } from "../schema";
|
|
17
|
+
import { type Purpose, type UnsyncedEntry } from "./codec.js";
|
|
18
|
+
export type ConsentPutBody = components["schemas"]["ConsentPutRequest"];
|
|
19
|
+
type ConsentAnswer = Omit<components["schemas"]["ConsentAnswerDto"], "shopper"> & {
|
|
20
|
+
shopper: {
|
|
21
|
+
owner: string | null;
|
|
22
|
+
expiresAt: string | null;
|
|
23
|
+
};
|
|
24
|
+
};
|
|
25
|
+
/** What the transport gives back: the server action's result (the API answer + `shopper.owner`), or a local `owner_mismatch`. */
|
|
26
|
+
export type TransportAnswer = AccountResult<ConsentAnswer> | {
|
|
27
|
+
ok: false;
|
|
28
|
+
local: "owner_mismatch";
|
|
29
|
+
};
|
|
30
|
+
/**
|
|
31
|
+
* The frontend's wrapper around the `consent.put` server action. `owner` is the decision's captured owner, never "whoever is signed
|
|
32
|
+
* in now"; `mayMint` is true only for a fresh decision captured with owner `none`. The coordinator aborts `signal` at
|
|
33
|
+
* `PUT_TIMEOUT_MS` and also stops waiting itself, so a transport that ignores the signal still ends as `not_saved`.
|
|
34
|
+
*/
|
|
35
|
+
export type ConsentTransport = {
|
|
36
|
+
put(body: ConsentPutBody, owner: string, opts: {
|
|
37
|
+
mayMint?: boolean;
|
|
38
|
+
signal: AbortSignal;
|
|
39
|
+
}): Promise<TransportAnswer>;
|
|
40
|
+
};
|
|
41
|
+
/** `document.cookie` semantics: a read gives the current value or undefined; a write may be silently rejected by the browser. */
|
|
42
|
+
export interface CookieJar {
|
|
43
|
+
get(name: string): string | undefined;
|
|
44
|
+
/** `maxAgeSeconds` 0 deletes. May return a promise (the coordinator awaits it). */
|
|
45
|
+
set(name: string, value: string, maxAgeSeconds: number): void | Promise<void>;
|
|
46
|
+
}
|
|
47
|
+
export type ConsentDecision = "granted" | "withdrawn";
|
|
48
|
+
export type SetStatus = "saved" | "not_saved" | "consent_unavailable" | "storage_failed" | "refused_meanwhile";
|
|
49
|
+
/** The decision's overall status (the worst of its purposes) and each named purpose's own. */
|
|
50
|
+
export type SetResult = {
|
|
51
|
+
status: SetStatus;
|
|
52
|
+
purposes: Partial<Record<Purpose, SetStatus>>;
|
|
53
|
+
};
|
|
54
|
+
/** The account's current record (`GET /v1/me/consents` `current`). */
|
|
55
|
+
export type AccountConsentRecord = Partial<Record<Purpose, string>>;
|
|
56
|
+
export interface ConsentCoordinator {
|
|
57
|
+
/**
|
|
58
|
+
* Records a decision. A withdrawal is refused by `effective()` synchronously, before this returns its promise; the promise only
|
|
59
|
+
* reports the server round trip (up to `PUT_TIMEOUT_MS` per request, plus re-sends). Frontends must not block the UI on it.
|
|
60
|
+
* A grant needs `notice` (the rendered notice's `ref`); a grant without it is `not_saved` and nothing is sent for it.
|
|
61
|
+
*/
|
|
62
|
+
set(purposes: Partial<Record<Purpose, ConsentDecision>>, notice?: {
|
|
63
|
+
ref: string;
|
|
64
|
+
}): Promise<SetResult>;
|
|
65
|
+
/** The S30 truth table, read from both cookies on every call. */
|
|
66
|
+
effective(): Record<Purpose, boolean>;
|
|
67
|
+
/**
|
|
68
|
+
* The owner later decisions capture (PL9); a decision already invoked keeps its own. `null` (an action's `shopper.owner` when the
|
|
69
|
+
* account lookup failed: unresolved) is ignored, so the established owner stays; pass every action's owner through unchanged.
|
|
70
|
+
*/
|
|
71
|
+
setOwner(owner: string | null): void;
|
|
72
|
+
/** The account's current record and whether a session exists. It can only deny. */
|
|
73
|
+
setAccount(record: AccountConsentRecord | null, signedIn: boolean): void;
|
|
74
|
+
/** Drops the cached account record (sign-in, sign-out, principal switch): nothing is granted until `setAccount`. */
|
|
75
|
+
invalidate(): void;
|
|
76
|
+
unsynced(): {
|
|
77
|
+
entries: UnsyncedEntry[];
|
|
78
|
+
overflow: number;
|
|
79
|
+
};
|
|
80
|
+
/** Replays every `unsynced` entry of this site with its own owner, device and seq. */
|
|
81
|
+
start(): Promise<void>;
|
|
82
|
+
/** Replays the `t.` entries of this site while the shopper token still exists (call before sign-out). */
|
|
83
|
+
beforeSignOut(): Promise<void>;
|
|
84
|
+
/**
|
|
85
|
+
* After `DELETE /v1/shopper`: this page refuses every purpose at once (synchronously), a fresh refusal is written to the refusal
|
|
86
|
+
* cookie (so no grant decided or answered before the erasure can count again, in any tab or SSR), then the main consent cookie is
|
|
87
|
+
* deleted. Locked or lockless alike. A later fresh grant counts as usual.
|
|
88
|
+
*/
|
|
89
|
+
erased(): Promise<void>;
|
|
90
|
+
/** At the adoption of a shopper token: its entries are dropped (S35). */
|
|
91
|
+
adopted(tokenOwner: string): Promise<void>;
|
|
92
|
+
}
|
|
93
|
+
export type ConsentCoordinatorOptions = {
|
|
94
|
+
site: string;
|
|
95
|
+
/** `consentOwner()` as the page rendered it: `a.<account>`, `t.<token hash prefix>` or `none`. */
|
|
96
|
+
owner: string;
|
|
97
|
+
transport: ConsentTransport;
|
|
98
|
+
/** Defaults to `navigator.locks`; null = no Web Locks (fail closed). */
|
|
99
|
+
locks?: LockManager | null;
|
|
100
|
+
/** Defaults to `document.cookie`. */
|
|
101
|
+
cookies?: CookieJar;
|
|
102
|
+
now?: () => number;
|
|
103
|
+
random?: (n: number) => Uint8Array;
|
|
104
|
+
};
|
|
105
|
+
/** The browser's consent coordinator (S36). Throws when `window` is undefined and no `cookies` jar is injected. */
|
|
106
|
+
export declare function createConsentCoordinator(opts: ConsentCoordinatorOptions): ConsentCoordinator;
|
|
107
|
+
export {};
|