@asstio-dev/storefront 0.49.0 → 0.51.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.
- package/README.md +3 -1
- package/dist/consent/codec.d.ts +36 -10
- package/dist/consent/codec.js +130 -34
- package/dist/consent/coordinator.js +28 -10
- package/dist/consent/index.d.ts +1 -1
- package/dist/consent/index.js +1 -1
- package/dist/schema.d.ts +33 -2
- package/package.json +2 -2
- package/src/schema.d.ts +33 -2
package/README.md
CHANGED
|
@@ -815,7 +815,9 @@ Guest favorites, stock watches and the device's consent live in five entries (sh
|
|
|
815
815
|
is `null` when the account lookup failed: keep your current owner (`coordinator.setOwner(null)` ignores it).
|
|
816
816
|
- `@asstio-dev/storefront/consent` — `createConsentCoordinator({ site, owner, transport })`, the browser's one writer of
|
|
817
817
|
the consent cookies: a withdrawal takes effect at once, a grant only after the server recorded it. Its transport is
|
|
818
|
-
`{ put: locked.consent.put }`. Gate every measurement or
|
|
818
|
+
`{ put: locked.consent.put }`. Gate every measurement, personalization or ad tag on `coordinator.effective()`.
|
|
819
|
+
`advertising` means ad-platform measurement: storing ad click identifiers on the device, sending conversions to ad
|
|
820
|
+
platforms, and the frontend's own ad tags (Consent Mode `ad_storage`, `ad_user_data`, `ad_personalization`).
|
|
819
821
|
- `@asstio-dev/storefront/consent/server` — `readConsentCookie(cookies)` (the same answer for SSR) and
|
|
820
822
|
`consentOwner(cookies, session)`.
|
|
821
823
|
- `@asstio-dev/storefront/shopper` — the watch types `ShopperWatch` (owner projection) and `RecipientWatch`, the union
|
package/dist/consent/codec.d.ts
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
|
-
export type Purpose = "measurement" | "personalization";
|
|
1
|
+
export type Purpose = "measurement" | "personalization" | "advertising";
|
|
2
2
|
export declare const PURPOSES: readonly Purpose[];
|
|
3
|
-
/** At most this many `unsynced` entries; a further key is not stored (`withEntry`). */
|
|
3
|
+
/** At most this many `unsynced` entries (known and foreign together); a further key is not stored (`withEntry`). */
|
|
4
4
|
export declare const MAX_UNSYNCED = 8;
|
|
5
|
+
/** A parsed cookie may hold up to this many `unsynced` entries (known and foreign), so a newer SDK's fuller cookie still reads. */
|
|
6
|
+
export declare const MAX_UNSYNCED_READ = 16;
|
|
5
7
|
/** The coordinator's transport timeout: an `AbortSignal` on every `put`; a timed-out `put` is `not_saved`. */
|
|
6
8
|
export declare const PUT_TIMEOUT_MS = 30000;
|
|
7
9
|
/** A `pending` marker is abandoned once `now - startedAt > PENDING_TTL_MS` (twice `PUT_TIMEOUT_MS`). */
|
|
@@ -63,6 +65,10 @@ export type LockedConsentCookie = {
|
|
|
63
65
|
at: number;
|
|
64
66
|
unsynced: UnsyncedEntry[];
|
|
65
67
|
overflow: number;
|
|
68
|
+
/** Each unknown (foreign) purpose's state object as read; never granted, written back after the known ones. Absent when none. */
|
|
69
|
+
foreignPurposes?: Record<string, Record<string, unknown>>;
|
|
70
|
+
/** Each `unsynced` entry with an unknown purpose, as read; written back after the known ones. Absent when none. */
|
|
71
|
+
foreignUnsynced?: Record<string, unknown>[];
|
|
66
72
|
};
|
|
67
73
|
export type FallbackConsentCookie = {
|
|
68
74
|
v: 1;
|
|
@@ -72,6 +78,8 @@ export type FallbackConsentCookie = {
|
|
|
72
78
|
fencedAt: number;
|
|
73
79
|
unsynced: UnsyncedEntry[];
|
|
74
80
|
overflow: number;
|
|
81
|
+
/** Each `unsynced` entry with an unknown purpose, as read; written back after the known ones. Absent when none. */
|
|
82
|
+
foreignUnsynced?: Record<string, unknown>[];
|
|
75
83
|
};
|
|
76
84
|
export type ConsentCookie = LockedConsentCookie | FallbackConsentCookie;
|
|
77
85
|
/** What `parseRefusal` gives: the latest refusal's time and mark, `"malformed"` (deny every grant), or null (no refusal cookie). */
|
|
@@ -87,9 +95,16 @@ export declare const isFallback: (c: ConsentCookie) => c is FallbackConsentCooki
|
|
|
87
95
|
/**
|
|
88
96
|
* The main cookie's value back, or null for a missing value and for **any** shape error: a missing `"1."` prefix, bad base64url or
|
|
89
97
|
* 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
|
|
90
|
-
* `[2^40, 2^41 - 1]` (fallback), a time that is not a positive integer,
|
|
98
|
+
* `[2^40, 2^41 - 1]` (fallback), a time that is not a positive integer, a bad site, an `unsynced` owner that is
|
|
91
99
|
* 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
|
|
92
|
-
* (or one on a state that is not `granted`), more than `
|
|
100
|
+
* (or one on a state that is not `granted`), more than `MAX_UNSYNCED_READ` entries (known and foreign together).
|
|
101
|
+
*
|
|
102
|
+
* Unknown purposes (a newer SDK's): a `purposes` key in `PURPOSES` is validated as above; a key matching
|
|
103
|
+
* `^[a-z][a-z0-9_]{0,29}$` that is not in `PURPOSES`, whose value is a JSON object, is foreign and kept as read in
|
|
104
|
+
* `foreignPurposes`; any other key or a non-object value makes the cookie null. An `unsynced` entry whose `purpose` is in
|
|
105
|
+
* `PURPOSES` is validated as above; one whose `purpose` matches the pattern and is not in `PURPOSES`, with a valid site, owner,
|
|
106
|
+
* device and seq, is foreign and kept as read in `foreignUnsynced`; anything else makes the cookie null. Wire members named
|
|
107
|
+
* `foreignPurposes` or `foreignUnsynced` are never read: the cookie is built member by member.
|
|
93
108
|
*/
|
|
94
109
|
export declare function parseConsent(raw: string | undefined): ConsentCookie | null;
|
|
95
110
|
/**
|
|
@@ -109,11 +124,16 @@ export declare function refusalMark(off: Refusal): string | undefined;
|
|
|
109
124
|
* a malformed refusal; a current mark other than the observed one (absent ↔ absent); or a decision not later than the refusal time.
|
|
110
125
|
*/
|
|
111
126
|
export declare function refusalBlocks(off: Refusal, at: number, mark: string | undefined): boolean;
|
|
112
|
-
/**
|
|
127
|
+
/**
|
|
128
|
+
* The main cookie's value. The wire members are written one by one, in the order today's SDK writes them; the foreign purposes
|
|
129
|
+
* follow the known ones in `purposes` (a foreign key that is a known purpose is skipped: the known state wins), the foreign entries
|
|
130
|
+
* follow the known ones in `unsynced` (one whose `purpose` is known is skipped). `foreignPurposes`/`foreignUnsynced` are never
|
|
131
|
+
* written by those names. Throws `ConsentCookieTooLarge` above `MAX_CONSENT_COOKIE_LENGTH` characters.
|
|
132
|
+
*/
|
|
113
133
|
export declare function serializeConsent(c: ConsentCookie): string;
|
|
114
134
|
/**
|
|
115
135
|
* Stores a withdrawal's `unsynced` entry. The same `(site, purpose, owner)` key replaces the old entry (a newer decision supersedes
|
|
116
|
-
* it); a new key is appended while fewer than `MAX_UNSYNCED` exist. At capacity nothing is dropped: the cookie comes back with
|
|
136
|
+
* it); a new key is appended while fewer than `MAX_UNSYNCED` exist (known and foreign together). At capacity nothing is dropped: the cookie comes back with
|
|
117
137
|
* `overflow + 1` and `stored: false` (the refusal itself is already in `purposes`; the caller reports `not_saved`).
|
|
118
138
|
*/
|
|
119
139
|
export declare function withEntry<C extends ConsentCookie>(c: C, entry: UnsyncedEntry): {
|
|
@@ -121,11 +141,16 @@ export declare function withEntry<C extends ConsentCookie>(c: C, entry: Unsynced
|
|
|
121
141
|
stored: boolean;
|
|
122
142
|
};
|
|
123
143
|
/**
|
|
124
|
-
* Removes the entries `pred` selects — only for the spec's reasons: an acknowledgement (match the full identity), a grant of
|
|
125
|
-
* `(site, purpose, owner)` when it is allocated
|
|
126
|
-
*
|
|
144
|
+
* Removes the known entries `pred` selects — only for the spec's reasons: an acknowledgement (match the full identity), a grant of
|
|
145
|
+
* the same `(site, purpose, owner)` when it is allocated. Foreign entries are never touched (the adoption of a token and
|
|
146
|
+
* `404 SHOPPER_TOKEN_UNKNOWN` for it drop known and foreign entries alike through `withoutOwner`). Overflow resets to 0 only when the entries left (known and foreign) are fewer than `MAX_UNSYNCED`.
|
|
127
147
|
*/
|
|
128
148
|
export declare function withoutEntries<C extends ConsentCookie>(c: C, pred: (e: UnsyncedEntry) => boolean): C;
|
|
149
|
+
/**
|
|
150
|
+
* Removes every entry of `owner` on `site`, known and foreign (the adoption of that token, `404 SHOPPER_TOKEN_UNKNOWN` for it).
|
|
151
|
+
* Returns `c` itself when nothing is dropped; overflow follows `withoutEntries`.
|
|
152
|
+
*/
|
|
153
|
+
export declare function withoutOwner<C extends ConsentCookie>(c: C, site: string, owner: string): C;
|
|
129
154
|
/**
|
|
130
155
|
* The one comparison (S30, S36): granted iff the cookie is the locked shape, the purpose is `granted`, the refusal mark it observed
|
|
131
156
|
* 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.
|
|
@@ -136,6 +161,7 @@ export declare function grantedFor(c: ConsentCookie | null, off: Refusal, purpos
|
|
|
136
161
|
* Folds the refusal into the main cookie (round-11 notes 1, 2; review #1): every `granted` purpose the refusal blocks
|
|
137
162
|
* (`refusalBlocks`: decided at or before it, or under another mark; every one when the refusal is malformed) becomes `withdrawn`,
|
|
138
163
|
* keeping its `seq` and `at` (its mark is dropped); a `pending` grant the refusal blocks loses its `pending`. Nothing else changes,
|
|
139
|
-
* so a later loss of the refusal cookie cannot revive a grant.
|
|
164
|
+
* so a later loss of the refusal cookie cannot revive a grant. A foreign purpose state of today's shape (`validState`, extra
|
|
165
|
+
* members allowed and kept) folds the same way; one of another shape is kept verbatim. Returns `c` itself when nothing changes.
|
|
140
166
|
*/
|
|
141
167
|
export declare function fold<C extends ConsentCookie>(c: C, off: Refusal): C;
|
package/dist/consent/codec.js
CHANGED
|
@@ -11,12 +11,15 @@
|
|
|
11
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
12
|
* decided before either of them never observed the mark that ends up in the cookie, so it never counts again (review #1).
|
|
13
13
|
*
|
|
14
|
-
* Anything that does not parse is not granted
|
|
14
|
+
* Anything that does not parse is not granted; an unknown purpose that is well-formed is kept and never granted (a refusal still
|
|
15
|
+
* folds it).
|
|
15
16
|
*/
|
|
16
17
|
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`). */
|
|
18
|
+
export const PURPOSES = ["measurement", "personalization", "advertising"];
|
|
19
|
+
/** At most this many `unsynced` entries (known and foreign together); a further key is not stored (`withEntry`). */
|
|
19
20
|
export const MAX_UNSYNCED = 8;
|
|
21
|
+
/** A parsed cookie may hold up to this many `unsynced` entries (known and foreign), so a newer SDK's fuller cookie still reads. */
|
|
22
|
+
export const MAX_UNSYNCED_READ = 16;
|
|
20
23
|
/** The coordinator's transport timeout: an `AbortSignal` on every `put`; a timed-out `put` is `not_saved`. */
|
|
21
24
|
export const PUT_TIMEOUT_MS = 30_000;
|
|
22
25
|
/** A `pending` marker is abandoned once `now - startedAt > PENDING_TTL_MS` (twice `PUT_TIMEOUT_MS`). */
|
|
@@ -55,11 +58,14 @@ const PENDING_OWNER = /^(t\.[0-9a-f]{16}|a\.[0-9a-f]{32}|none)$/;
|
|
|
55
58
|
const BASE64URL = /^[A-Za-z0-9_-]+$/;
|
|
56
59
|
const MARK = /^[0-9a-f]{16}$/;
|
|
57
60
|
const REFUSAL = /^1\.([1-9][0-9]{0,15})\.([0-9a-f]{16})$/;
|
|
61
|
+
/** A well-formed purpose name a newer SDK may write. */
|
|
62
|
+
const PURPOSE_NAME = /^[a-z][a-z0-9_]{0,29}$/;
|
|
58
63
|
const isObject = (v) => typeof v === "object" && v !== null && !Array.isArray(v);
|
|
59
64
|
const isSeq = (v) => Number.isSafeInteger(v) && v >= 0 && v < SEQ_LIMIT;
|
|
60
65
|
const isTime = (v) => Number.isSafeInteger(v) && v > 0;
|
|
61
66
|
const isCount = (v) => Number.isSafeInteger(v) && v >= 0;
|
|
62
|
-
const isPurpose = (v) => v === "measurement" || v === "personalization";
|
|
67
|
+
const isPurpose = (v) => v === "measurement" || v === "personalization" || v === "advertising";
|
|
68
|
+
const isForeignName = (v) => typeof v === "string" && PURPOSE_NAME.test(v) && !isPurpose(v);
|
|
63
69
|
const isMark = (v) => typeof v === "string" && MARK.test(v);
|
|
64
70
|
function encode(text) {
|
|
65
71
|
let binary = "";
|
|
@@ -73,10 +79,18 @@ function decode(text) {
|
|
|
73
79
|
const binary = atob(text.replace(/-/g, "+").replace(/_/g, "/"));
|
|
74
80
|
return new TextDecoder("utf-8", { fatal: true }).decode(Uint8Array.from(binary, (c) => c.charCodeAt(0)));
|
|
75
81
|
}
|
|
76
|
-
|
|
77
|
-
|
|
82
|
+
/** Today's entry checks except the purpose. */
|
|
83
|
+
function validEntryKey(e) {
|
|
84
|
+
return isObject(e) && typeof e.site === "string" && SITE.test(e.site)
|
|
78
85
|
&& typeof e.owner === "string" && ENTRY_OWNER.test(e.owner) && typeof e.device === "string" && HEX32.test(e.device) && isSeq(e.seq);
|
|
79
86
|
}
|
|
87
|
+
function validEntry(e) {
|
|
88
|
+
return validEntryKey(e) && isPurpose(e.purpose);
|
|
89
|
+
}
|
|
90
|
+
/** An entry a newer SDK wrote for a purpose this one does not know: well-formed name, today's key checks. */
|
|
91
|
+
function validForeignEntry(e) {
|
|
92
|
+
return validEntryKey(e) && isForeignName(e.purpose);
|
|
93
|
+
}
|
|
80
94
|
function validState(s) {
|
|
81
95
|
if (!isObject(s) || (s.state !== "granted" && s.state !== "withdrawn" && s.state !== "unset") || !isSeq(s.seq) || !isTime(s.at))
|
|
82
96
|
return false;
|
|
@@ -90,17 +104,25 @@ function validState(s) {
|
|
|
90
104
|
}
|
|
91
105
|
function validShared(c) {
|
|
92
106
|
return c.v === 1 && typeof c.device === "string" && HEX32.test(c.device)
|
|
93
|
-
&& Array.isArray(c.unsynced) && c.unsynced.length <=
|
|
107
|
+
&& Array.isArray(c.unsynced) && c.unsynced.length <= MAX_UNSYNCED_READ && c.unsynced.every((e) => validEntry(e) || validForeignEntry(e))
|
|
108
|
+
&& isCount(c.overflow);
|
|
94
109
|
}
|
|
95
110
|
function validPurposes(p) {
|
|
96
|
-
return isObject(p) && Object.entries(p).every(([k, s]) => isPurpose(k) && validState(s));
|
|
111
|
+
return isObject(p) && Object.entries(p).every(([k, s]) => (isPurpose(k) && validState(s)) || (isForeignName(k) && isObject(s)));
|
|
97
112
|
}
|
|
98
113
|
/**
|
|
99
114
|
* 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
115
|
* 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,
|
|
116
|
+
* `[2^40, 2^41 - 1]` (fallback), a time that is not a positive integer, a bad site, an `unsynced` owner that is
|
|
102
117
|
* 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 `
|
|
118
|
+
* (or one on a state that is not `granted`), more than `MAX_UNSYNCED_READ` entries (known and foreign together).
|
|
119
|
+
*
|
|
120
|
+
* Unknown purposes (a newer SDK's): a `purposes` key in `PURPOSES` is validated as above; a key matching
|
|
121
|
+
* `^[a-z][a-z0-9_]{0,29}$` that is not in `PURPOSES`, whose value is a JSON object, is foreign and kept as read in
|
|
122
|
+
* `foreignPurposes`; any other key or a non-object value makes the cookie null. An `unsynced` entry whose `purpose` is in
|
|
123
|
+
* `PURPOSES` is validated as above; one whose `purpose` matches the pattern and is not in `PURPOSES`, with a valid site, owner,
|
|
124
|
+
* device and seq, is foreign and kept as read in `foreignUnsynced`; anything else makes the cookie null. Wire members named
|
|
125
|
+
* `foreignPurposes` or `foreignUnsynced` are never read: the cookie is built member by member.
|
|
104
126
|
*/
|
|
105
127
|
export function parseConsent(raw) {
|
|
106
128
|
if (!raw || !raw.startsWith("1."))
|
|
@@ -114,23 +136,40 @@ export function parseConsent(raw) {
|
|
|
114
136
|
}
|
|
115
137
|
if (!isObject(value) || !validShared(value))
|
|
116
138
|
return null;
|
|
117
|
-
const
|
|
139
|
+
const entries = value.unsynced;
|
|
140
|
+
const unsynced = entries.filter(validEntry).map((e) => ({ site: e.site, purpose: e.purpose, owner: e.owner, device: e.device, seq: e.seq }));
|
|
141
|
+
const foreignEntries = entries.filter((e) => !validEntry(e));
|
|
142
|
+
const foreignUnsynced = foreignEntries.length > 0 ? { foreignUnsynced: foreignEntries } : {};
|
|
118
143
|
if (value.fallback !== undefined) {
|
|
119
144
|
if (value.fallback !== true || !Number.isSafeInteger(value.fence) || value.fence < SEQ_LIMIT
|
|
120
145
|
|| value.fence >= 2 * SEQ_LIMIT || !isTime(value.fencedAt))
|
|
121
146
|
return null;
|
|
122
|
-
return {
|
|
147
|
+
return {
|
|
148
|
+
v: 1, fallback: true, device: value.device, fence: value.fence, fencedAt: value.fencedAt, unsynced,
|
|
149
|
+
overflow: value.overflow, ...foreignUnsynced,
|
|
150
|
+
};
|
|
123
151
|
}
|
|
124
152
|
if (!isSeq(value.seq) || !isTime(value.at) || !validPurposes(value.purposes) || (value.ref !== null && typeof value.ref !== "string"))
|
|
125
153
|
return null;
|
|
126
154
|
const purposes = {};
|
|
127
|
-
|
|
155
|
+
const foreign = [];
|
|
156
|
+
for (const [k, v] of Object.entries(value.purposes)) {
|
|
157
|
+
if (!isPurpose(k)) {
|
|
158
|
+
foreign.push([k, v]);
|
|
159
|
+
continue;
|
|
160
|
+
}
|
|
161
|
+
const s = v;
|
|
128
162
|
const pending = s.pending
|
|
129
163
|
? { 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
164
|
: {};
|
|
131
165
|
purposes[k] = { state: s.state, seq: s.seq, at: s.at, ...(s.off !== undefined ? { off: s.off } : {}), ...pending };
|
|
132
166
|
}
|
|
133
|
-
return {
|
|
167
|
+
return {
|
|
168
|
+
v: 1, device: value.device, seq: value.seq, purposes, ref: value.ref, at: value.at, unsynced,
|
|
169
|
+
overflow: value.overflow,
|
|
170
|
+
...(foreign.length > 0 ? { foreignPurposes: Object.fromEntries(foreign) } : {}),
|
|
171
|
+
...foreignUnsynced,
|
|
172
|
+
};
|
|
134
173
|
}
|
|
135
174
|
/**
|
|
136
175
|
* The refusal cookie's value back: `{ at, mark }`, `"malformed"` for a present value that is not
|
|
@@ -166,9 +205,26 @@ export function refusalBlocks(off, at, mark) {
|
|
|
166
205
|
return mark !== undefined;
|
|
167
206
|
return off.mark !== mark || at <= off.at;
|
|
168
207
|
}
|
|
169
|
-
/** The
|
|
208
|
+
/** The wire `unsynced`: the known entries, then the foreign ones whose `purpose` is not a known purpose. */
|
|
209
|
+
const wireUnsynced = (c) => [...c.unsynced, ...(c.foreignUnsynced ?? []).filter((e) => !isPurpose(e.purpose))];
|
|
210
|
+
/**
|
|
211
|
+
* The main cookie's value. The wire members are written one by one, in the order today's SDK writes them; the foreign purposes
|
|
212
|
+
* follow the known ones in `purposes` (a foreign key that is a known purpose is skipped: the known state wins), the foreign entries
|
|
213
|
+
* follow the known ones in `unsynced` (one whose `purpose` is known is skipped). `foreignPurposes`/`foreignUnsynced` are never
|
|
214
|
+
* written by those names. Throws `ConsentCookieTooLarge` above `MAX_CONSENT_COOKIE_LENGTH` characters.
|
|
215
|
+
*/
|
|
170
216
|
export function serializeConsent(c) {
|
|
171
|
-
const
|
|
217
|
+
const wire = isFallback(c)
|
|
218
|
+
? { v: c.v, fallback: c.fallback, device: c.device, fence: c.fence, fencedAt: c.fencedAt, unsynced: wireUnsynced(c), overflow: c.overflow }
|
|
219
|
+
: {
|
|
220
|
+
v: c.v, device: c.device, seq: c.seq,
|
|
221
|
+
purposes: Object.fromEntries([
|
|
222
|
+
...Object.entries(c.purposes),
|
|
223
|
+
...Object.entries(c.foreignPurposes ?? {}).filter(([k]) => !isPurpose(k)),
|
|
224
|
+
]),
|
|
225
|
+
ref: c.ref, at: c.at, unsynced: wireUnsynced(c), overflow: c.overflow,
|
|
226
|
+
};
|
|
227
|
+
const value = "1." + encode(JSON.stringify(wire));
|
|
172
228
|
if (value.length > MAX_CONSENT_COOKIE_LENGTH)
|
|
173
229
|
throw new ConsentCookieTooLarge(value.length);
|
|
174
230
|
return value;
|
|
@@ -176,7 +232,7 @@ export function serializeConsent(c) {
|
|
|
176
232
|
const sameKey = (a, b) => a.site === b.site && a.purpose === b.purpose && a.owner === b.owner;
|
|
177
233
|
/**
|
|
178
234
|
* 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
|
|
235
|
+
* it); a new key is appended while fewer than `MAX_UNSYNCED` exist (known and foreign together). At capacity nothing is dropped: the cookie comes back with
|
|
180
236
|
* `overflow + 1` and `stored: false` (the refusal itself is already in `purposes`; the caller reports `not_saved`).
|
|
181
237
|
*/
|
|
182
238
|
export function withEntry(c, entry) {
|
|
@@ -184,18 +240,37 @@ export function withEntry(c, entry) {
|
|
|
184
240
|
const at = c.unsynced.findIndex((e) => sameKey(e, entry));
|
|
185
241
|
if (at >= 0)
|
|
186
242
|
return { cookie: { ...c, unsynced: c.unsynced.map((e, i) => (i === at ? copy : e)) }, stored: true };
|
|
187
|
-
if (c.unsynced.length < MAX_UNSYNCED)
|
|
243
|
+
if (c.unsynced.length + (c.foreignUnsynced?.length ?? 0) < MAX_UNSYNCED)
|
|
188
244
|
return { cookie: { ...c, unsynced: [...c.unsynced, copy] }, stored: true };
|
|
189
245
|
return { cookie: { ...c, overflow: c.overflow + 1 }, stored: false };
|
|
190
246
|
}
|
|
191
247
|
/**
|
|
192
|
-
* Removes the entries `pred` selects — only for the spec's reasons: an acknowledgement (match the full identity), a grant of
|
|
193
|
-
* `(site, purpose, owner)` when it is allocated
|
|
194
|
-
*
|
|
248
|
+
* Removes the known entries `pred` selects — only for the spec's reasons: an acknowledgement (match the full identity), a grant of
|
|
249
|
+
* the same `(site, purpose, owner)` when it is allocated. Foreign entries are never touched (the adoption of a token and
|
|
250
|
+
* `404 SHOPPER_TOKEN_UNKNOWN` for it drop known and foreign entries alike through `withoutOwner`). Overflow resets to 0 only when the entries left (known and foreign) are fewer than `MAX_UNSYNCED`.
|
|
195
251
|
*/
|
|
196
252
|
export function withoutEntries(c, pred) {
|
|
197
253
|
const kept = c.unsynced.filter((e) => !pred(e));
|
|
198
|
-
return kept.length === c.unsynced.length ? c :
|
|
254
|
+
return kept.length === c.unsynced.length ? c : withLeft(c, kept, c.foreignUnsynced);
|
|
255
|
+
}
|
|
256
|
+
/**
|
|
257
|
+
* Removes every entry of `owner` on `site`, known and foreign (the adoption of that token, `404 SHOPPER_TOKEN_UNKNOWN` for it).
|
|
258
|
+
* Returns `c` itself when nothing is dropped; overflow follows `withoutEntries`.
|
|
259
|
+
*/
|
|
260
|
+
export function withoutOwner(c, site, owner) {
|
|
261
|
+
const ofOwner = (e) => e.site === site && e.owner === owner;
|
|
262
|
+
const kept = c.unsynced.filter((e) => !ofOwner(e));
|
|
263
|
+
const foreign = c.foreignUnsynced?.filter((e) => !ofOwner(e));
|
|
264
|
+
if (kept.length === c.unsynced.length && foreign?.length === c.foreignUnsynced?.length)
|
|
265
|
+
return c;
|
|
266
|
+
return withLeft(c, kept, foreign);
|
|
267
|
+
}
|
|
268
|
+
function withLeft(c, unsynced, foreign) {
|
|
269
|
+
const { foreignUnsynced: _old, ...rest } = c;
|
|
270
|
+
const left = unsynced.length + (foreign?.length ?? 0);
|
|
271
|
+
return {
|
|
272
|
+
...rest, unsynced, overflow: left < MAX_UNSYNCED ? 0 : c.overflow, ...(foreign && foreign.length > 0 ? { foreignUnsynced: foreign } : {}),
|
|
273
|
+
};
|
|
199
274
|
}
|
|
200
275
|
/**
|
|
201
276
|
* The one comparison (S30, S36): granted iff the cookie is the locked shape, the purpose is `granted`, the refusal mark it observed
|
|
@@ -214,26 +289,47 @@ export function grantedFor(c, off, purpose) {
|
|
|
214
289
|
* Folds the refusal into the main cookie (round-11 notes 1, 2; review #1): every `granted` purpose the refusal blocks
|
|
215
290
|
* (`refusalBlocks`: decided at or before it, or under another mark; every one when the refusal is malformed) becomes `withdrawn`,
|
|
216
291
|
* 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.
|
|
292
|
+
* so a later loss of the refusal cookie cannot revive a grant. A foreign purpose state of today's shape (`validState`, extra
|
|
293
|
+
* members allowed and kept) folds the same way; one of another shape is kept verbatim. Returns `c` itself when nothing changes.
|
|
218
294
|
*/
|
|
219
295
|
export function fold(c, off) {
|
|
220
296
|
if (isFallback(c))
|
|
221
297
|
return c;
|
|
298
|
+
const locked = c;
|
|
222
299
|
const purposes = {};
|
|
223
300
|
let changed = false;
|
|
224
|
-
for (const [k, s] of Object.entries(
|
|
225
|
-
|
|
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
|
-
}
|
|
301
|
+
for (const [k, s] of Object.entries(locked.purposes)) {
|
|
302
|
+
const next = foldState(s, off);
|
|
234
303
|
if (next !== s)
|
|
235
304
|
changed = true;
|
|
236
305
|
purposes[k] = next;
|
|
237
306
|
}
|
|
238
|
-
|
|
307
|
+
let foreignPurposes = locked.foreignPurposes;
|
|
308
|
+
if (foreignPurposes) {
|
|
309
|
+
let foreignChanged = false;
|
|
310
|
+
const folded = Object.entries(foreignPurposes).map(([k, s]) => {
|
|
311
|
+
const next = validState(s) ? foldState(s, off) : s;
|
|
312
|
+
if (next !== s)
|
|
313
|
+
foreignChanged = true;
|
|
314
|
+
return [k, next];
|
|
315
|
+
});
|
|
316
|
+
if (foreignChanged) {
|
|
317
|
+
foreignPurposes = Object.fromEntries(folded);
|
|
318
|
+
changed = true;
|
|
319
|
+
}
|
|
320
|
+
}
|
|
321
|
+
return changed ? { ...c, purposes, ...(foreignPurposes ? { foreignPurposes } : {}) } : c;
|
|
322
|
+
}
|
|
323
|
+
/** One state under a refusal: `s` itself when the refusal blocks nothing in it. Extra members of a foreign state are kept. */
|
|
324
|
+
function foldState(s, off) {
|
|
325
|
+
let next = s;
|
|
326
|
+
if (s.state === "granted" && refusalBlocks(off, s.at, s.off)) {
|
|
327
|
+
const { off: _mark, ...rest } = next;
|
|
328
|
+
next = { ...rest, state: "withdrawn" };
|
|
329
|
+
}
|
|
330
|
+
if (s.pending && refusalBlocks(off, s.pending.at, s.pending.off)) {
|
|
331
|
+
const { pending: _dropped, ...rest } = next;
|
|
332
|
+
next = rest;
|
|
333
|
+
}
|
|
334
|
+
return next;
|
|
239
335
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { CONSENT_COOKIE_SECONDS, CONSENT_OFF_COOKIE_SECONDS, ConsentCookieTooLarge, consentCookieNames, fold, grantedFor, isFallback, parseConsent, parseRefusal, PENDING_TTL_MS, PURPOSES, PUT_TIMEOUT_MS, refusalBlocks, refusalMark, SEQ_LIMIT, serializeConsent, serializeRefusal, withEntry, withoutEntries, } from "./codec.js";
|
|
1
|
+
import { CONSENT_COOKIE_SECONDS, CONSENT_OFF_COOKIE_SECONDS, ConsentCookieTooLarge, consentCookieNames, fold, grantedFor, isFallback, parseConsent, parseRefusal, PENDING_TTL_MS, PURPOSES, PUT_TIMEOUT_MS, refusalBlocks, refusalMark, SEQ_LIMIT, serializeConsent, serializeRefusal, withEntry, withoutEntries, withoutOwner, } from "./codec.js";
|
|
2
2
|
const LOCK_NAME = "sf-consent";
|
|
3
3
|
const RESEND_BACKOFF_MS = [1_000, 4_000, 16_000];
|
|
4
4
|
const TOKEN_GONE = new Set(["SHOPPER_TOKEN_UNKNOWN", "SHOPPER_TOKEN_ADOPTED"]);
|
|
@@ -170,10 +170,10 @@ class Coordinator {
|
|
|
170
170
|
await this.commit(prepared);
|
|
171
171
|
return { statuses, sent: null, capacity };
|
|
172
172
|
}
|
|
173
|
-
let c = prepared ?? this.fresh([], 0);
|
|
173
|
+
let c = prepared ?? this.fresh({ unsynced: [], overflow: 0 });
|
|
174
174
|
let seq = c.seq + 1;
|
|
175
175
|
if (seq >= SEQ_LIMIT - 1) {
|
|
176
|
-
c = this.fresh(c
|
|
176
|
+
c = this.fresh(c);
|
|
177
177
|
seq = 1;
|
|
178
178
|
}
|
|
179
179
|
c = { ...c, seq, at: d.decidedAt, purposes: { ...c.purposes } };
|
|
@@ -335,7 +335,7 @@ class Coordinator {
|
|
|
335
335
|
const answer = outcome.answer;
|
|
336
336
|
if (!answer.ok) {
|
|
337
337
|
if ("status" in answer && TOKEN_GONE.has(answer.problem.code) && id.owner.startsWith("t.")) {
|
|
338
|
-
await this.locked(() => this.
|
|
338
|
+
await this.locked(() => this.dropOwner(id.owner));
|
|
339
339
|
}
|
|
340
340
|
return "not_saved";
|
|
341
341
|
}
|
|
@@ -369,7 +369,7 @@ class Coordinator {
|
|
|
369
369
|
let c = this.prepare(parsed, this.readOff());
|
|
370
370
|
let seq = c.seq + 1;
|
|
371
371
|
if (seq >= SEQ_LIMIT - 1) {
|
|
372
|
-
c = this.fresh(c
|
|
372
|
+
c = this.fresh(c);
|
|
373
373
|
seq = 1;
|
|
374
374
|
}
|
|
375
375
|
const next = { ...id, device: c.device, seq };
|
|
@@ -401,6 +401,7 @@ class Coordinator {
|
|
|
401
401
|
const offWritten = await this.writeRefusal(d.decidedAt);
|
|
402
402
|
const value = {
|
|
403
403
|
v: 1, fallback: true, device, fence, fencedAt, unsynced: read?.unsynced ?? [], overflow: read?.overflow ?? 0,
|
|
404
|
+
...(read?.foreignUnsynced ? { foreignUnsynced: read.foreignUnsynced } : {}),
|
|
404
405
|
};
|
|
405
406
|
let raw = null;
|
|
406
407
|
try {
|
|
@@ -478,7 +479,7 @@ class Coordinator {
|
|
|
478
479
|
await clear();
|
|
479
480
|
}
|
|
480
481
|
async adopted(tokenOwner) {
|
|
481
|
-
await this.locked(() => this.
|
|
482
|
+
await this.locked(() => this.dropOwner(tokenOwner));
|
|
482
483
|
}
|
|
483
484
|
// ---- lock and cookie helpers ---------------------------------------------------------------------------------------------
|
|
484
485
|
/** Runs `fn` under the `sf-consent` lock: one retry of a rejected request, then `{ ok: false }`. */
|
|
@@ -529,14 +530,21 @@ class Coordinator {
|
|
|
529
530
|
const now = this.jar.get(this.names.off);
|
|
530
531
|
return now === value || (now !== priorRaw && parseRefusal(now) !== null && parseRefusal(now) !== "malformed");
|
|
531
532
|
}
|
|
532
|
-
|
|
533
|
-
|
|
533
|
+
/**
|
|
534
|
+
* A new device generation: it keeps the known and foreign `unsynced` entries of `from` (they still need their replay or another
|
|
535
|
+
* SDK's); every purpose state, known and foreign, is dropped.
|
|
536
|
+
*/
|
|
537
|
+
fresh(from) {
|
|
538
|
+
return {
|
|
539
|
+
v: 1, device: hex(this.random(16)), seq: 0, purposes: {}, ref: null, at: this.now(), unsynced: from.unsynced.map((e) => ({ ...e })),
|
|
540
|
+
overflow: from.overflow, ...(from.foreignUnsynced?.length ? { foreignUnsynced: from.foreignUnsynced.map((e) => ({ ...e })) } : {}),
|
|
541
|
+
};
|
|
534
542
|
}
|
|
535
543
|
/** What every lock holder does first: drop abandoned markers, recover from a fallback value (new generation), fold. */
|
|
536
544
|
prepare(parsed, off) {
|
|
537
545
|
if (parsed === null)
|
|
538
546
|
return null;
|
|
539
|
-
const c = isFallback(parsed) ? this.fresh(parsed
|
|
547
|
+
const c = isFallback(parsed) ? this.fresh(parsed) : this.dropAbandoned(parsed);
|
|
540
548
|
return fold(c, off);
|
|
541
549
|
}
|
|
542
550
|
dropAbandoned(c) {
|
|
@@ -564,7 +572,7 @@ class Coordinator {
|
|
|
564
572
|
await this.jar.set(this.names.consent, raw, CONSENT_COOKIE_SECONDS);
|
|
565
573
|
return { result: this.jar.get(this.names.consent) === raw ? "ok" : "rejected", cookie };
|
|
566
574
|
}
|
|
567
|
-
/** Under the lock: drops this site's entries `pred` selects (an acknowledgement
|
|
575
|
+
/** Under the lock: drops this site's entries `pred` selects (an acknowledgement by the entry's full identity). */
|
|
568
576
|
async dropEntries(pred) {
|
|
569
577
|
const parsed = parseConsent(this.jar.get(this.names.consent));
|
|
570
578
|
if (!parsed)
|
|
@@ -574,6 +582,16 @@ class Coordinator {
|
|
|
574
582
|
if (c !== parsed)
|
|
575
583
|
await this.commit(c);
|
|
576
584
|
}
|
|
585
|
+
/** Under the lock: drops every entry of `owner` on this site, known and foreign (an adoption of that token, its `404`). */
|
|
586
|
+
async dropOwner(owner) {
|
|
587
|
+
const parsed = parseConsent(this.jar.get(this.names.consent));
|
|
588
|
+
if (!parsed)
|
|
589
|
+
return;
|
|
590
|
+
let c = isFallback(parsed) ? parsed : this.dropAbandoned(parsed);
|
|
591
|
+
c = withoutOwner(c, this.site, owner);
|
|
592
|
+
if (c !== parsed)
|
|
593
|
+
await this.commit(c);
|
|
594
|
+
}
|
|
577
595
|
/** Sends one `PUT` outside the lock; a throw, a rejection or `PUT_TIMEOUT_MS` without an answer is `failed`. */
|
|
578
596
|
async submit(body, owner, mayMint) {
|
|
579
597
|
const controller = new AbortController();
|
package/dist/consent/index.d.ts
CHANGED
|
@@ -3,6 +3,6 @@
|
|
|
3
3
|
* coordinator (shopper-state spec §7.4, S36). The codec and the notice helper work in the browser and on the server;
|
|
4
4
|
* `createConsentCoordinator` throws without `window`. The server readers are in `@asstio-dev/storefront/consent/server`.
|
|
5
5
|
*/
|
|
6
|
-
export { CONSENT_COOKIE, CONSENT_COOKIE_SECONDS, CONSENT_OFF_COOKIE, CONSENT_OFF_COOKIE_SECONDS, ConsentCookieTooLarge, consentCookieNames, fold, grantedFor, isFallback, MAX_CONSENT_COOKIE_LENGTH, MAX_UNSYNCED, parseConsent, parseRefusal, PENDING_TTL_MS, PURPOSES, refusalBlocks, refusalMark, PUT_TIMEOUT_MS, SEQ_LIMIT, serializeConsent, serializeRefusal, withEntry, withoutEntries, type ConsentCookie, type FallbackConsentCookie, type LockedConsentCookie, type Purpose, type PurposeState, type Refusal, type UnsyncedEntry, } from "./codec.js";
|
|
6
|
+
export { CONSENT_COOKIE, CONSENT_COOKIE_SECONDS, CONSENT_OFF_COOKIE, CONSENT_OFF_COOKIE_SECONDS, ConsentCookieTooLarge, consentCookieNames, fold, grantedFor, isFallback, MAX_CONSENT_COOKIE_LENGTH, MAX_UNSYNCED, MAX_UNSYNCED_READ, parseConsent, parseRefusal, PENDING_TTL_MS, PURPOSES, refusalBlocks, refusalMark, PUT_TIMEOUT_MS, SEQ_LIMIT, serializeConsent, serializeRefusal, withEntry, withoutEntries, withoutOwner, type ConsentCookie, type FallbackConsentCookie, type LockedConsentCookie, type Purpose, type PurposeState, type Refusal, type UnsyncedEntry, } from "./codec.js";
|
|
7
7
|
export { consentNotice, type ConsentNoticeDto } from "./notice.js";
|
|
8
8
|
export { createConsentCoordinator, type AccountConsentRecord, type ConsentCoordinator, type ConsentCoordinatorOptions, type ConsentDecision, type ConsentPutBody, type ConsentTransport, type CookieJar, type SetResult, type SetStatus, type TransportAnswer, } from "./coordinator.js";
|
package/dist/consent/index.js
CHANGED
|
@@ -3,6 +3,6 @@
|
|
|
3
3
|
* coordinator (shopper-state spec §7.4, S36). The codec and the notice helper work in the browser and on the server;
|
|
4
4
|
* `createConsentCoordinator` throws without `window`. The server readers are in `@asstio-dev/storefront/consent/server`.
|
|
5
5
|
*/
|
|
6
|
-
export { CONSENT_COOKIE, CONSENT_COOKIE_SECONDS, CONSENT_OFF_COOKIE, CONSENT_OFF_COOKIE_SECONDS, ConsentCookieTooLarge, consentCookieNames, fold, grantedFor, isFallback, MAX_CONSENT_COOKIE_LENGTH, MAX_UNSYNCED, parseConsent, parseRefusal, PENDING_TTL_MS, PURPOSES, refusalBlocks, refusalMark, PUT_TIMEOUT_MS, SEQ_LIMIT, serializeConsent, serializeRefusal, withEntry, withoutEntries, } from "./codec.js";
|
|
6
|
+
export { CONSENT_COOKIE, CONSENT_COOKIE_SECONDS, CONSENT_OFF_COOKIE, CONSENT_OFF_COOKIE_SECONDS, ConsentCookieTooLarge, consentCookieNames, fold, grantedFor, isFallback, MAX_CONSENT_COOKIE_LENGTH, MAX_UNSYNCED, MAX_UNSYNCED_READ, parseConsent, parseRefusal, PENDING_TTL_MS, PURPOSES, refusalBlocks, refusalMark, PUT_TIMEOUT_MS, SEQ_LIMIT, serializeConsent, serializeRefusal, withEntry, withoutEntries, withoutOwner, } from "./codec.js";
|
|
7
7
|
export { consentNotice } from "./notice.js";
|
|
8
8
|
export { createConsentCoordinator, } from "./coordinator.js";
|
package/dist/schema.d.ts
CHANGED
|
@@ -429,7 +429,7 @@ export interface paths {
|
|
|
429
429
|
};
|
|
430
430
|
/** The account's current consent and the first history page, adopted guest tokens' events included as provenance device. */
|
|
431
431
|
get: operations["GetMyConsents"];
|
|
432
|
-
/** Record the account's consent decision (measurement, personalization), ordered per device by order.seq. */
|
|
432
|
+
/** Record the account's consent decision (measurement, personalization, advertising), ordered per device by order.seq. */
|
|
433
433
|
put: operations["PutMyConsents"];
|
|
434
434
|
post?: never;
|
|
435
435
|
delete?: never;
|
|
@@ -738,7 +738,7 @@ export interface paths {
|
|
|
738
738
|
};
|
|
739
739
|
/** The guest token's current consent and the first history page. */
|
|
740
740
|
get: operations["GetShopperConsents"];
|
|
741
|
-
/** Record the guest token's consent decision (measurement, personalization), ordered per device by order.seq. */
|
|
741
|
+
/** Record the guest token's consent decision (measurement, personalization, advertising), ordered per device by order.seq. */
|
|
742
742
|
put: operations["PutShopperConsents"];
|
|
743
743
|
post?: never;
|
|
744
744
|
delete?: never;
|
|
@@ -1063,6 +1063,19 @@ export interface components {
|
|
|
1063
1063
|
scope: null | string;
|
|
1064
1064
|
token: null | string;
|
|
1065
1065
|
};
|
|
1066
|
+
CardVariantDto: {
|
|
1067
|
+
attributes: components["schemas"]["AttributeDto"][];
|
|
1068
|
+
hasOwnImages: boolean;
|
|
1069
|
+
id: string;
|
|
1070
|
+
image: null | components["schemas"]["MediaDescriptorDto"];
|
|
1071
|
+
name: null | string;
|
|
1072
|
+
offer: components["schemas"]["OfferDto"];
|
|
1073
|
+
selectedOptions: {
|
|
1074
|
+
[key: string]: string;
|
|
1075
|
+
};
|
|
1076
|
+
sku: string;
|
|
1077
|
+
url: null | string;
|
|
1078
|
+
};
|
|
1066
1079
|
CartCodeDto: {
|
|
1067
1080
|
code: string;
|
|
1068
1081
|
promotion: components["schemas"]["PromotionRefDto"];
|
|
@@ -1325,6 +1338,7 @@ export interface components {
|
|
|
1325
1338
|
shopper: null | components["schemas"]["ShopperMintDto"];
|
|
1326
1339
|
};
|
|
1327
1340
|
ConsentCurrentDto: {
|
|
1341
|
+
advertising: string;
|
|
1328
1342
|
measurement: string;
|
|
1329
1343
|
personalization: string;
|
|
1330
1344
|
};
|
|
@@ -1756,6 +1770,7 @@ export interface components {
|
|
|
1756
1770
|
};
|
|
1757
1771
|
PriceBasisDto: {
|
|
1758
1772
|
currency: string;
|
|
1773
|
+
scope: string;
|
|
1759
1774
|
source: string;
|
|
1760
1775
|
tax: components["schemas"]["DisplayBasisDto"];
|
|
1761
1776
|
};
|
|
@@ -1790,6 +1805,9 @@ export interface components {
|
|
|
1790
1805
|
collections: string[];
|
|
1791
1806
|
id: string;
|
|
1792
1807
|
image: null | components["schemas"]["MediaDescriptorDto"];
|
|
1808
|
+
matchedVariant?: null | components["schemas"]["CardVariantDto"];
|
|
1809
|
+
/** Format: int32 */
|
|
1810
|
+
matchedVariantCount?: number | null | string;
|
|
1793
1811
|
name: string;
|
|
1794
1812
|
offer: components["schemas"]["OfferDto"];
|
|
1795
1813
|
/** @description Preview keys only: why the card stands where it does (reason pinned, keepVisible or base). Absent otherwise. */
|
|
@@ -1803,6 +1821,9 @@ export interface components {
|
|
|
1803
1821
|
/** Format: date-time */
|
|
1804
1822
|
updatedAt: string;
|
|
1805
1823
|
url: string;
|
|
1824
|
+
/** Format: int32 */
|
|
1825
|
+
variantCount?: number | null | string;
|
|
1826
|
+
variants?: components["schemas"]["CardVariantDto"][] | null;
|
|
1806
1827
|
};
|
|
1807
1828
|
ProductDto: {
|
|
1808
1829
|
alternates: components["schemas"]["AlternateDto"][];
|
|
@@ -4413,6 +4434,10 @@ export interface operations {
|
|
|
4413
4434
|
};
|
|
4414
4435
|
/** @description Where a search came from, for measurement only: typed, suggestion, recent or other. It never changes the answer. Anything else is ignored with an ORIGIN_UNKNOWN warning. */
|
|
4415
4436
|
origin?: "other" | "recent" | "suggestion" | "typed";
|
|
4437
|
+
/** @description Comma list of what the cards carry beyond the product: variants (each card's variants visible here, at most 12, by position, with variantCount) and matchedVariant (with a variant-level filter in effect: the cheapest variant that matches every variant-level filter, with matchedVariantCount). Unknown members are ignored with an INCLUDE_UNKNOWN warning. */
|
|
4438
|
+
include?: string;
|
|
4439
|
+
/** @description What the price filter, the price sort and the price facet act on. product (default): the product's from-price. matchedVariant: with a variant-level filter in effect, the price of the cheapest variant matching every variant-level filter (implies include=matchedVariant). The response's priceBasis.scope says what was applied; without a variant-level filter it is product. Anything else is ignored with a PRICE_SCOPE_UNKNOWN warning. */
|
|
4440
|
+
priceScope?: "matchedVariant" | "product";
|
|
4416
4441
|
};
|
|
4417
4442
|
header: {
|
|
4418
4443
|
/** @description Publishable, preview or secret site key. Required on every request; secret keys are server-side only. */
|
|
@@ -6123,6 +6148,10 @@ export interface operations {
|
|
|
6123
6148
|
};
|
|
6124
6149
|
/** @description Where a search came from, for measurement only: typed, suggestion, recent or other. It never changes the answer. Anything else is ignored with an ORIGIN_UNKNOWN warning. */
|
|
6125
6150
|
origin?: "other" | "recent" | "suggestion" | "typed";
|
|
6151
|
+
/** @description Comma list of what the cards carry beyond the product: variants (each card's variants visible here, at most 12, by position, with variantCount) and matchedVariant (with a variant-level filter in effect: the cheapest variant that matches every variant-level filter, with matchedVariantCount). Unknown members are ignored with an INCLUDE_UNKNOWN warning. */
|
|
6152
|
+
include?: string;
|
|
6153
|
+
/** @description What the price filter, the price sort and the price facet act on. product (default): the product's from-price. matchedVariant: with a variant-level filter in effect, the price of the cheapest variant matching every variant-level filter (implies include=matchedVariant). The response's priceBasis.scope says what was applied; without a variant-level filter it is product. Anything else is ignored with a PRICE_SCOPE_UNKNOWN warning. */
|
|
6154
|
+
priceScope?: "matchedVariant" | "product";
|
|
6126
6155
|
/** @description Narrow to a collection by slug path or id. An unknown one is answered with a COLLECTION_UNKNOWN warning, not a 404. */
|
|
6127
6156
|
collection?: string;
|
|
6128
6157
|
};
|
|
@@ -6304,6 +6333,8 @@ export interface operations {
|
|
|
6304
6333
|
filter?: {
|
|
6305
6334
|
[key: string]: string;
|
|
6306
6335
|
};
|
|
6336
|
+
/** @description The price scope of the listing the panel belongs to (see /products): with matchedVariant and a variant-level filter, a price filter in the context holds on the matched variant, as it does in that listing. */
|
|
6337
|
+
priceScope?: "matchedVariant" | "product";
|
|
6307
6338
|
};
|
|
6308
6339
|
header: {
|
|
6309
6340
|
/** @description Publishable, preview or secret site key. Required on every request; secret keys are server-side only. */
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@asstio-dev/storefront",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.51.1",
|
|
4
4
|
"description": "Typed client for the Asstio Storefront API (generated from OpenAPI).",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -53,7 +53,7 @@
|
|
|
53
53
|
"test:browser": "playwright test -c browser/playwright.config.ts",
|
|
54
54
|
"check": "npm run generate && npm run typecheck-examples && npm test && git diff --exit-code -- src/schema.d.ts && test -z \"$(git status --porcelain -- src/schema.d.ts)\"",
|
|
55
55
|
"smoke": "node --input-type=module -e \"import(\\\"./dist/index.js\\\").then(m => { for (const f of [\\\"createStorefrontClient\\\", \\\"filterQuery\\\", \\\"encodeFilterValues\\\", \\\"decodeFilterValues\\\", \\\"pictureSources\\\", \\\"mediaUrl\\\", \\\"formatImage\\\", \\\"styleToCss\\\", \\\"startCheckout\\\", \\\"syncCheckout\\\", \\\"completeCheckout\\\", \\\"getCheckoutStatus\\\", \\\"liveShippingFor\\\", \\\"getOrder\\\", \\\"awaitCompletion\\\", \\\"mountCheckout\\\", \\\"productJsonLd\\\", \\\"gtinJsonLd\\\", \\\"breadcrumbJsonLd\\\", \\\"productHead\\\", \\\"collectionHead\\\", \\\"brandHead\\\", \\\"toNextMetadata\\\", \\\"sitemapEntries\\\", \\\"toNextSitemap\\\", \\\"jsonLdScript\\\", \\\"SeoError\\\", \\\"productFacts\\\", \\\"toGa4Item\\\", \\\"toGa4Ecommerce\\\", \\\"longestCategory\\\", \\\"AnalyticsError\\\", \\\"trackSearchEvents\\\", \\\"variantUrl\\\", \\\"readVariantParam\\\", \\\"variantQueryForApi\\\", \\\"redirectTarget\\\", \\\"displayPrice\\\", \\\"isPriceVisible\\\", \\\"isBuyable\\\", \\\"requireBinding\\\", \\\"hreflangFor\\\", \\\"isCheckoutContextMismatch\\\", \\\"consentNotice\\\"]) if (typeof m[f] !== \\\"function\\\") throw new Error(\\\"missing export \\\" + f) })\" && npm run smoke:account && npm run smoke:consent && npm run smoke:shopper",
|
|
56
|
-
"smoke:consent": "node --input-type=module -e \"const checks = { \\\"./dist/consent/index.js\\\": [\\\"parseConsent\\\", \\\"parseRefusal\\\", \\\"serializeConsent\\\", \\\"serializeRefusal\\\", \\\"ConsentCookieTooLarge\\\", \\\"withEntry\\\", \\\"withoutEntries\\\", \\\"grantedFor\\\", \\\"fold\\\", \\\"refusalBlocks\\\", \\\"refusalMark\\\", \\\"isFallback\\\", \\\"consentCookieNames\\\", \\\"consentNotice\\\", \\\"createConsentCoordinator\\\"], \\\"./dist/consent/server.js\\\": [\\\"readConsentCookie\\\", \\\"consentOwner\\\", \\\"tokenOwner\\\", \\\"accountOwner\\\"] }; for (const [file, names] of Object.entries(checks)) { const m = await import(file); for (const f of names) if (typeof m[f] !== \\\"function\\\") throw new Error(\\\"missing export \\\" + f + \\\" in \\\" + file); } const c = await import(\\\"./dist/consent/index.js\\\"); for (const n of [\\\"MAX_UNSYNCED\\\", \\\"PENDING_TTL_MS\\\", \\\"PUT_TIMEOUT_MS\\\"]) if (typeof c[n] !== \\\"number\\\") throw new Error(\\\"missing constant \\\" + n);\"",
|
|
56
|
+
"smoke:consent": "node --input-type=module -e \"const checks = { \\\"./dist/consent/index.js\\\": [\\\"parseConsent\\\", \\\"parseRefusal\\\", \\\"serializeConsent\\\", \\\"serializeRefusal\\\", \\\"ConsentCookieTooLarge\\\", \\\"withEntry\\\", \\\"withoutEntries\\\", \\\"withoutOwner\\\", \\\"grantedFor\\\", \\\"fold\\\", \\\"refusalBlocks\\\", \\\"refusalMark\\\", \\\"isFallback\\\", \\\"consentCookieNames\\\", \\\"consentNotice\\\", \\\"createConsentCoordinator\\\"], \\\"./dist/consent/server.js\\\": [\\\"readConsentCookie\\\", \\\"consentOwner\\\", \\\"tokenOwner\\\", \\\"accountOwner\\\"] }; for (const [file, names] of Object.entries(checks)) { const m = await import(file); for (const f of names) if (typeof m[f] !== \\\"function\\\") throw new Error(\\\"missing export \\\" + f + \\\" in \\\" + file); } const c = await import(\\\"./dist/consent/index.js\\\"); for (const n of [\\\"MAX_UNSYNCED\\\", \\\"MAX_UNSYNCED_READ\\\", \\\"PENDING_TTL_MS\\\", \\\"PUT_TIMEOUT_MS\\\"]) if (typeof c[n] !== \\\"number\\\") throw new Error(\\\"missing constant \\\" + n);\"",
|
|
57
57
|
"smoke:shopper": "node --input-type=module -e \"import(\\\"./dist/shopper/index.js\\\").then(m => { if (typeof m.cancelWatchByToken !== \\\"function\\\") throw new Error(\\\"missing export cancelWatchByToken\\\") })\"",
|
|
58
58
|
"smoke:account": "node --input-type=module -e \"const checks = { \\\"./dist/account/index.js\\\": [\\\"createShopperClient\\\", \\\"startSignIn\\\", \\\"verifySignIn\\\", \\\"signOut\\\", \\\"switchPrincipal\\\", \\\"getSession\\\", \\\"getMe\\\", \\\"getMyCompany\\\", \\\"linkChallengeId\\\", \\\"linkToken\\\", \\\"sessionCookie\\\", \\\"signInCookie\\\", \\\"cartCookie\\\", \\\"browserCartCookie\\\", \\\"copyBrowserCart\\\", \\\"CopyBrowserCartError\\\", \\\"cookieSecurity\\\", \\\"readSignInCookie\\\", \\\"serializeCookie\\\", \\\"shopperCookie\\\", \\\"accountResult\\\", \\\"shopperIpFrom\\\", \\\"assertSameOrigin\\\", \\\"safeReturnPath\\\", \\\"CrossOriginError\\\"], \\\"./dist/account/browser.js\\\": [\\\"readLinkFragment\\\", \\\"withShopperLock\\\"], \\\"./dist/account/next.js\\\": [\\\"startSignInAction\\\", \\\"verifySignInAction\\\", \\\"signOutAction\\\", \\\"switchPrincipalAction\\\", \\\"shopperClient\\\", \\\"copyBrowserCartAction\\\", \\\"shopperActions\\\"] }; for (const [file, names] of Object.entries(checks)) { const m = await import(file); for (const f of names) if (typeof m[f] !== \\\"function\\\") throw new Error(\\\"missing export \\\" + f + \\\" in \\\" + file); }\""
|
|
59
59
|
},
|
package/src/schema.d.ts
CHANGED
|
@@ -429,7 +429,7 @@ export interface paths {
|
|
|
429
429
|
};
|
|
430
430
|
/** The account's current consent and the first history page, adopted guest tokens' events included as provenance device. */
|
|
431
431
|
get: operations["GetMyConsents"];
|
|
432
|
-
/** Record the account's consent decision (measurement, personalization), ordered per device by order.seq. */
|
|
432
|
+
/** Record the account's consent decision (measurement, personalization, advertising), ordered per device by order.seq. */
|
|
433
433
|
put: operations["PutMyConsents"];
|
|
434
434
|
post?: never;
|
|
435
435
|
delete?: never;
|
|
@@ -738,7 +738,7 @@ export interface paths {
|
|
|
738
738
|
};
|
|
739
739
|
/** The guest token's current consent and the first history page. */
|
|
740
740
|
get: operations["GetShopperConsents"];
|
|
741
|
-
/** Record the guest token's consent decision (measurement, personalization), ordered per device by order.seq. */
|
|
741
|
+
/** Record the guest token's consent decision (measurement, personalization, advertising), ordered per device by order.seq. */
|
|
742
742
|
put: operations["PutShopperConsents"];
|
|
743
743
|
post?: never;
|
|
744
744
|
delete?: never;
|
|
@@ -1063,6 +1063,19 @@ export interface components {
|
|
|
1063
1063
|
scope: null | string;
|
|
1064
1064
|
token: null | string;
|
|
1065
1065
|
};
|
|
1066
|
+
CardVariantDto: {
|
|
1067
|
+
attributes: components["schemas"]["AttributeDto"][];
|
|
1068
|
+
hasOwnImages: boolean;
|
|
1069
|
+
id: string;
|
|
1070
|
+
image: null | components["schemas"]["MediaDescriptorDto"];
|
|
1071
|
+
name: null | string;
|
|
1072
|
+
offer: components["schemas"]["OfferDto"];
|
|
1073
|
+
selectedOptions: {
|
|
1074
|
+
[key: string]: string;
|
|
1075
|
+
};
|
|
1076
|
+
sku: string;
|
|
1077
|
+
url: null | string;
|
|
1078
|
+
};
|
|
1066
1079
|
CartCodeDto: {
|
|
1067
1080
|
code: string;
|
|
1068
1081
|
promotion: components["schemas"]["PromotionRefDto"];
|
|
@@ -1325,6 +1338,7 @@ export interface components {
|
|
|
1325
1338
|
shopper: null | components["schemas"]["ShopperMintDto"];
|
|
1326
1339
|
};
|
|
1327
1340
|
ConsentCurrentDto: {
|
|
1341
|
+
advertising: string;
|
|
1328
1342
|
measurement: string;
|
|
1329
1343
|
personalization: string;
|
|
1330
1344
|
};
|
|
@@ -1756,6 +1770,7 @@ export interface components {
|
|
|
1756
1770
|
};
|
|
1757
1771
|
PriceBasisDto: {
|
|
1758
1772
|
currency: string;
|
|
1773
|
+
scope: string;
|
|
1759
1774
|
source: string;
|
|
1760
1775
|
tax: components["schemas"]["DisplayBasisDto"];
|
|
1761
1776
|
};
|
|
@@ -1790,6 +1805,9 @@ export interface components {
|
|
|
1790
1805
|
collections: string[];
|
|
1791
1806
|
id: string;
|
|
1792
1807
|
image: null | components["schemas"]["MediaDescriptorDto"];
|
|
1808
|
+
matchedVariant?: null | components["schemas"]["CardVariantDto"];
|
|
1809
|
+
/** Format: int32 */
|
|
1810
|
+
matchedVariantCount?: number | null | string;
|
|
1793
1811
|
name: string;
|
|
1794
1812
|
offer: components["schemas"]["OfferDto"];
|
|
1795
1813
|
/** @description Preview keys only: why the card stands where it does (reason pinned, keepVisible or base). Absent otherwise. */
|
|
@@ -1803,6 +1821,9 @@ export interface components {
|
|
|
1803
1821
|
/** Format: date-time */
|
|
1804
1822
|
updatedAt: string;
|
|
1805
1823
|
url: string;
|
|
1824
|
+
/** Format: int32 */
|
|
1825
|
+
variantCount?: number | null | string;
|
|
1826
|
+
variants?: components["schemas"]["CardVariantDto"][] | null;
|
|
1806
1827
|
};
|
|
1807
1828
|
ProductDto: {
|
|
1808
1829
|
alternates: components["schemas"]["AlternateDto"][];
|
|
@@ -4413,6 +4434,10 @@ export interface operations {
|
|
|
4413
4434
|
};
|
|
4414
4435
|
/** @description Where a search came from, for measurement only: typed, suggestion, recent or other. It never changes the answer. Anything else is ignored with an ORIGIN_UNKNOWN warning. */
|
|
4415
4436
|
origin?: "other" | "recent" | "suggestion" | "typed";
|
|
4437
|
+
/** @description Comma list of what the cards carry beyond the product: variants (each card's variants visible here, at most 12, by position, with variantCount) and matchedVariant (with a variant-level filter in effect: the cheapest variant that matches every variant-level filter, with matchedVariantCount). Unknown members are ignored with an INCLUDE_UNKNOWN warning. */
|
|
4438
|
+
include?: string;
|
|
4439
|
+
/** @description What the price filter, the price sort and the price facet act on. product (default): the product's from-price. matchedVariant: with a variant-level filter in effect, the price of the cheapest variant matching every variant-level filter (implies include=matchedVariant). The response's priceBasis.scope says what was applied; without a variant-level filter it is product. Anything else is ignored with a PRICE_SCOPE_UNKNOWN warning. */
|
|
4440
|
+
priceScope?: "matchedVariant" | "product";
|
|
4416
4441
|
};
|
|
4417
4442
|
header: {
|
|
4418
4443
|
/** @description Publishable, preview or secret site key. Required on every request; secret keys are server-side only. */
|
|
@@ -6123,6 +6148,10 @@ export interface operations {
|
|
|
6123
6148
|
};
|
|
6124
6149
|
/** @description Where a search came from, for measurement only: typed, suggestion, recent or other. It never changes the answer. Anything else is ignored with an ORIGIN_UNKNOWN warning. */
|
|
6125
6150
|
origin?: "other" | "recent" | "suggestion" | "typed";
|
|
6151
|
+
/** @description Comma list of what the cards carry beyond the product: variants (each card's variants visible here, at most 12, by position, with variantCount) and matchedVariant (with a variant-level filter in effect: the cheapest variant that matches every variant-level filter, with matchedVariantCount). Unknown members are ignored with an INCLUDE_UNKNOWN warning. */
|
|
6152
|
+
include?: string;
|
|
6153
|
+
/** @description What the price filter, the price sort and the price facet act on. product (default): the product's from-price. matchedVariant: with a variant-level filter in effect, the price of the cheapest variant matching every variant-level filter (implies include=matchedVariant). The response's priceBasis.scope says what was applied; without a variant-level filter it is product. Anything else is ignored with a PRICE_SCOPE_UNKNOWN warning. */
|
|
6154
|
+
priceScope?: "matchedVariant" | "product";
|
|
6126
6155
|
/** @description Narrow to a collection by slug path or id. An unknown one is answered with a COLLECTION_UNKNOWN warning, not a 404. */
|
|
6127
6156
|
collection?: string;
|
|
6128
6157
|
};
|
|
@@ -6304,6 +6333,8 @@ export interface operations {
|
|
|
6304
6333
|
filter?: {
|
|
6305
6334
|
[key: string]: string;
|
|
6306
6335
|
};
|
|
6336
|
+
/** @description The price scope of the listing the panel belongs to (see /products): with matchedVariant and a variant-level filter, a price filter in the context holds on the matched variant, as it does in that listing. */
|
|
6337
|
+
priceScope?: "matchedVariant" | "product";
|
|
6307
6338
|
};
|
|
6308
6339
|
header: {
|
|
6309
6340
|
/** @description Publishable, preview or secret site key. Required on every request; secret keys are server-side only. */
|