@cookiemunch/sdk 0.5.1 → 0.7.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 +22 -0
- package/dist/chunk-OSVTQPQG.js +187 -0
- package/dist/chunk-OSVTQPQG.js.map +1 -0
- package/dist/consent.cjs +89 -2
- package/dist/consent.cjs.map +1 -1
- package/dist/consent.d.cts +83 -2
- package/dist/consent.d.ts +83 -2
- package/dist/consent.js +11 -3
- package/dist/index.cjs +415 -14
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +1268 -41
- package/dist/index.d.ts +1268 -41
- package/dist/index.js +332 -16
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/dist/chunk-G7ORTXTK.js +0 -104
- package/dist/chunk-G7ORTXTK.js.map +0 -1
package/dist/consent.d.ts
CHANGED
|
@@ -36,6 +36,11 @@ interface ServerConsent {
|
|
|
36
36
|
region: string;
|
|
37
37
|
/** The anonymous consent-receipt id tying this browser to the consent log. */
|
|
38
38
|
stamp: string;
|
|
39
|
+
/**
|
|
40
|
+
* `<kid>.<base64url>`: the API's Ed25519 signature over this decision, issued when the
|
|
41
|
+
* ledger recorded it. Absent on a decision no ledger holds (a hand-written cookie).
|
|
42
|
+
*/
|
|
43
|
+
sig?: string;
|
|
39
44
|
}
|
|
40
45
|
/** The site's consent policy, so the server applies the same rules the embed does. */
|
|
41
46
|
interface ReadConsentOptions {
|
|
@@ -52,6 +57,19 @@ interface ReadConsentOptions {
|
|
|
52
57
|
/** Clock for `expiryDays`, epoch ms. Default `Date.now()`. */
|
|
53
58
|
now?: number;
|
|
54
59
|
}
|
|
60
|
+
/** Where the platform's public signing keys come from, for signatures and consent tokens. */
|
|
61
|
+
interface KeySetOptions {
|
|
62
|
+
/** A key set you already hold (`{ keys: [...] }`). Skips the fetch. */
|
|
63
|
+
jwks?: JsonWebKeySet;
|
|
64
|
+
/** Default `https://api.cookiemunch.net/v1/partner/jwks.json`. */
|
|
65
|
+
jwksUrl?: string;
|
|
66
|
+
/** Injectable fetch. Default: the global one. */
|
|
67
|
+
fetch?: typeof fetch;
|
|
68
|
+
}
|
|
69
|
+
/** `readConsent` with `requireSigned: true`: only a decision the API signed counts. */
|
|
70
|
+
interface ReadSignedConsentOptions extends ReadConsentOptions, KeySetOptions {
|
|
71
|
+
requireSigned: true;
|
|
72
|
+
}
|
|
55
73
|
/** Anything we can pull a Cookie header off of. */
|
|
56
74
|
type ConsentSource = string | null | undefined | {
|
|
57
75
|
headers?: {
|
|
@@ -70,7 +88,10 @@ declare function parseConsentValue(raw: string): ServerConsent | null;
|
|
|
70
88
|
* `Request`. Returns null when there is no decision the embed would honour — no cookie, an
|
|
71
89
|
* unparseable one, or (with the options) one made under an older version or past expiry.
|
|
72
90
|
*/
|
|
73
|
-
declare function readConsent(source: ConsentSource, opts
|
|
91
|
+
declare function readConsent(source: ConsentSource, opts: ReadSignedConsentOptions): Promise<ServerConsent | null>;
|
|
92
|
+
declare function readConsent(source: ConsentSource, opts?: ReadConsentOptions & {
|
|
93
|
+
requireSigned?: false;
|
|
94
|
+
}): ServerConsent | null;
|
|
74
95
|
/**
|
|
75
96
|
* Read the visitor's consent from a request. The original spelling of {@link readConsent},
|
|
76
97
|
* kept for existing callers; the second argument is the cookie name.
|
|
@@ -84,5 +105,65 @@ type ConsentCategory = 'necessary' | 'preferences' | 'statistics' | 'marketing'
|
|
|
84
105
|
* categories (fail-closed / prior-blocking posture), matching the embed.
|
|
85
106
|
*/
|
|
86
107
|
declare function isAllowed(consent: ServerConsent | null, category: ConsentCategory): boolean;
|
|
108
|
+
declare const DEFAULT_JWKS_URL = "https://api.cookiemunch.net/v1/partner/jwks.json";
|
|
109
|
+
/** The fields of a decision its signature covers. */
|
|
110
|
+
interface SignableDecision {
|
|
111
|
+
stamp: string;
|
|
112
|
+
ver: number;
|
|
113
|
+
utc: number;
|
|
114
|
+
preferences: boolean;
|
|
115
|
+
statistics: boolean;
|
|
116
|
+
marketing: boolean;
|
|
117
|
+
custom?: Record<string, boolean> | undefined;
|
|
118
|
+
}
|
|
119
|
+
/**
|
|
120
|
+
* The exact line the API signs for a recorded decision. Identical to @cookiemunch/core's
|
|
121
|
+
* `consentSignaturePayload` (a server test pins the two together).
|
|
122
|
+
*/
|
|
123
|
+
declare function consentSignaturePayload(d: SignableDecision): string;
|
|
124
|
+
interface Jwk {
|
|
125
|
+
kty?: string;
|
|
126
|
+
crv?: string;
|
|
127
|
+
x?: string;
|
|
128
|
+
kid?: string;
|
|
129
|
+
alg?: string;
|
|
130
|
+
}
|
|
131
|
+
interface JsonWebKeySet {
|
|
132
|
+
keys: Jwk[];
|
|
133
|
+
}
|
|
134
|
+
/** Does the cookie's `sig` verify for this decision? False on anything malformed. */
|
|
135
|
+
declare function verifyDecisionSignature(consent: ServerConsent, opts?: KeySetOptions): Promise<boolean>;
|
|
136
|
+
/** What a consent token (`CookieMunch.getConsentToken()`) asserts. */
|
|
137
|
+
interface ConsentTokenClaims {
|
|
138
|
+
iss: string;
|
|
139
|
+
/** The decision's stamp. */
|
|
140
|
+
sub: string;
|
|
141
|
+
/** `cookiemunch:<cbid>`. */
|
|
142
|
+
aud: string;
|
|
143
|
+
token_use: 'consent';
|
|
144
|
+
cbid: string;
|
|
145
|
+
stamp: string;
|
|
146
|
+
/** Every category the decision answered, `necessary` included. */
|
|
147
|
+
choices: Record<string, boolean>;
|
|
148
|
+
ver: number;
|
|
149
|
+
/** When the decision was made, epoch ms. */
|
|
150
|
+
decidedAt: number;
|
|
151
|
+
cause?: string;
|
|
152
|
+
iat: number;
|
|
153
|
+
exp: number;
|
|
154
|
+
}
|
|
155
|
+
interface VerifyTokenOptions extends KeySetOptions {
|
|
156
|
+
/** Require the token to be for this site. */
|
|
157
|
+
cbid?: string;
|
|
158
|
+
/** Clock, epoch ms. Default `Date.now()`. */
|
|
159
|
+
now?: number;
|
|
160
|
+
/** Allowed clock skew, seconds. Default 30. */
|
|
161
|
+
leewaySeconds?: number;
|
|
162
|
+
}
|
|
163
|
+
/**
|
|
164
|
+
* Verify a consent token from `CookieMunch.getConsentToken()` (CMU-F06) against the published
|
|
165
|
+
* key set and return its claims. Throws on a bad signature, a wrong site, or an expired token.
|
|
166
|
+
*/
|
|
167
|
+
declare function verifyToken(token: string, opts?: VerifyTokenOptions): Promise<ConsentTokenClaims>;
|
|
87
168
|
|
|
88
|
-
export { CONSENT_COOKIE_NAME, type ConsentCategory, type ConsentSource, type ReadConsentOptions, type ServerConsent, getConsent, isAllowed, parseConsentValue, readConsent };
|
|
169
|
+
export { CONSENT_COOKIE_NAME, type ConsentCategory, type ConsentSource, type ConsentTokenClaims, DEFAULT_JWKS_URL, type JsonWebKeySet, type KeySetOptions, type ReadConsentOptions, type ReadSignedConsentOptions, type ServerConsent, type SignableDecision, type VerifyTokenOptions, consentSignaturePayload, getConsent, isAllowed, parseConsentValue, readConsent, verifyDecisionSignature, verifyToken };
|
package/dist/consent.js
CHANGED
|
@@ -1,15 +1,23 @@
|
|
|
1
1
|
import {
|
|
2
2
|
CONSENT_COOKIE_NAME,
|
|
3
|
+
DEFAULT_JWKS_URL,
|
|
4
|
+
consentSignaturePayload,
|
|
3
5
|
getConsent,
|
|
4
6
|
isAllowed,
|
|
5
7
|
parseConsentValue,
|
|
6
|
-
readConsent
|
|
7
|
-
|
|
8
|
+
readConsent,
|
|
9
|
+
verifyDecisionSignature,
|
|
10
|
+
verifyToken
|
|
11
|
+
} from "./chunk-OSVTQPQG.js";
|
|
8
12
|
export {
|
|
9
13
|
CONSENT_COOKIE_NAME,
|
|
14
|
+
DEFAULT_JWKS_URL,
|
|
15
|
+
consentSignaturePayload,
|
|
10
16
|
getConsent,
|
|
11
17
|
isAllowed,
|
|
12
18
|
parseConsentValue,
|
|
13
|
-
readConsent
|
|
19
|
+
readConsent,
|
|
20
|
+
verifyDecisionSignature,
|
|
21
|
+
verifyToken
|
|
14
22
|
};
|
|
15
23
|
//# sourceMappingURL=consent.js.map
|