@peax/consent-core 0.6.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/LICENSE +201 -0
- package/README.md +207 -0
- package/dist/ConsentEnforcementError-Bn_ayWJI.js +16 -0
- package/dist/assertStorageIdentifier-BQuj-9bp.js +7 -0
- package/dist/createConsentIframe-Bw-cl--m.js +93 -0
- package/dist/createConsentRequestScope-D7U8uK6m.js +58 -0
- package/dist/createConsentScript-C_4ecSTX.js +102 -0
- package/dist/createDomGuard-CuIEC0HP.js +101 -0
- package/dist/enforcement/axios.d.ts +222 -0
- package/dist/enforcement/axios.js +92 -0
- package/dist/enforcement/fetch.d.ts +222 -0
- package/dist/enforcement/fetch.js +40 -0
- package/dist/enforcement/iframe.d.ts +245 -0
- package/dist/enforcement/iframe.js +2 -0
- package/dist/enforcement/integration.d.ts +230 -0
- package/dist/enforcement/integration.js +181 -0
- package/dist/enforcement/markup.d.ts +214 -0
- package/dist/enforcement/markup.js +300 -0
- package/dist/enforcement/posthog.d.ts +68 -0
- package/dist/enforcement/posthog.js +96 -0
- package/dist/enforcement/request-rules.d.ts +248 -0
- package/dist/enforcement/request-rules.js +434 -0
- package/dist/enforcement/script.d.ts +240 -0
- package/dist/enforcement/script.js +2 -0
- package/dist/index.d.ts +258 -0
- package/dist/index.js +445 -0
- package/dist/storage/localforage.d.ts +23 -0
- package/dist/storage/localforage.js +26 -0
- package/dist/storage/sync.d.ts +278 -0
- package/dist/storage/sync.js +370 -0
- package/dist/storage.d.ts +77 -0
- package/dist/storage.js +207 -0
- package/dist/validate-D16G7mdG.js +15 -0
- package/package.json +128 -0
|
@@ -0,0 +1,240 @@
|
|
|
1
|
+
import * as z from 'zod/mini';
|
|
2
|
+
|
|
3
|
+
/** Disjoint category/use decisions for one scope actually presented to the user. */
|
|
4
|
+
declare type BatchCommand = z.infer<typeof consentDecisionsCommandSchema>;
|
|
5
|
+
|
|
6
|
+
/** Records choices only for category members in userConsentedPolicy, not future members. */
|
|
7
|
+
declare type CategoryConsentCommand = z.infer<typeof categoryConsentCommandSchema>;
|
|
8
|
+
|
|
9
|
+
declare const categoryConsentCommandSchema: z.ZodMiniReadonly<z.ZodMiniObject<{
|
|
10
|
+
userConsentedPolicy: z.ZodMiniReadonly<z.ZodMiniObject<{
|
|
11
|
+
purposes: z.ZodMiniReadonly<z.ZodMiniArray<z.ZodMiniReadonly<z.ZodMiniObject<{
|
|
12
|
+
id: z.ZodMiniString<string>;
|
|
13
|
+
title: z.ZodMiniString<string>;
|
|
14
|
+
description: z.ZodMiniString<string>;
|
|
15
|
+
}, z.core.$strict>>>>;
|
|
16
|
+
uses: z.ZodMiniReadonly<z.ZodMiniArray<z.ZodMiniReadonly<z.ZodMiniObject<{
|
|
17
|
+
id: z.ZodMiniString<string>;
|
|
18
|
+
serviceId: z.ZodMiniString<string>;
|
|
19
|
+
categoryId: z.ZodMiniString<string>;
|
|
20
|
+
purposeId: z.ZodMiniString<string>;
|
|
21
|
+
consentVersion: z.ZodMiniInt;
|
|
22
|
+
}, z.core.$strict>>>>;
|
|
23
|
+
}, z.core.$strict>>;
|
|
24
|
+
categoryId: z.ZodMiniString<string>;
|
|
25
|
+
decision: z.ZodMiniEnum<{
|
|
26
|
+
granted: "granted";
|
|
27
|
+
denied: "denied";
|
|
28
|
+
}>;
|
|
29
|
+
}, z.core.$strict>>;
|
|
30
|
+
|
|
31
|
+
/** userConsentedPolicy is the scope shown for this decision, including a denial. */
|
|
32
|
+
declare type ConsentDecisionCommand = z.infer<typeof consentDecisionCommandSchema>;
|
|
33
|
+
|
|
34
|
+
declare const consentDecisionCommandSchema: z.ZodMiniReadonly<z.ZodMiniObject<{
|
|
35
|
+
userConsentedPolicy: z.ZodMiniReadonly<z.ZodMiniObject<{
|
|
36
|
+
purposes: z.ZodMiniReadonly<z.ZodMiniArray<z.ZodMiniReadonly<z.ZodMiniObject<{
|
|
37
|
+
id: z.ZodMiniString<string>;
|
|
38
|
+
title: z.ZodMiniString<string>;
|
|
39
|
+
description: z.ZodMiniString<string>;
|
|
40
|
+
}, z.core.$strict>>>>;
|
|
41
|
+
uses: z.ZodMiniReadonly<z.ZodMiniArray<z.ZodMiniReadonly<z.ZodMiniObject<{
|
|
42
|
+
id: z.ZodMiniString<string>;
|
|
43
|
+
serviceId: z.ZodMiniString<string>;
|
|
44
|
+
categoryId: z.ZodMiniString<string>;
|
|
45
|
+
purposeId: z.ZodMiniString<string>;
|
|
46
|
+
consentVersion: z.ZodMiniInt;
|
|
47
|
+
}, z.core.$strict>>>>;
|
|
48
|
+
}, z.core.$strict>>;
|
|
49
|
+
useId: z.ZodMiniString<string>;
|
|
50
|
+
decision: z.ZodMiniEnum<{
|
|
51
|
+
granted: "granted";
|
|
52
|
+
denied: "denied";
|
|
53
|
+
}>;
|
|
54
|
+
}, z.core.$strict>>;
|
|
55
|
+
|
|
56
|
+
declare type ConsentDecisionsCommand = Readonly<Omit<BatchCommand, 'decisions'> & {
|
|
57
|
+
decisions: readonly ExclusiveTarget<BatchCommand['decisions'][number]>[];
|
|
58
|
+
}>;
|
|
59
|
+
|
|
60
|
+
declare const consentDecisionsCommandSchema: z.ZodMiniReadonly<z.ZodMiniObject<{
|
|
61
|
+
userConsentedPolicy: z.ZodMiniReadonly<z.ZodMiniObject<{
|
|
62
|
+
purposes: z.ZodMiniReadonly<z.ZodMiniArray<z.ZodMiniReadonly<z.ZodMiniObject<{
|
|
63
|
+
id: z.ZodMiniString<string>;
|
|
64
|
+
title: z.ZodMiniString<string>;
|
|
65
|
+
description: z.ZodMiniString<string>;
|
|
66
|
+
}, z.core.$strict>>>>;
|
|
67
|
+
uses: z.ZodMiniReadonly<z.ZodMiniArray<z.ZodMiniReadonly<z.ZodMiniObject<{
|
|
68
|
+
id: z.ZodMiniString<string>;
|
|
69
|
+
serviceId: z.ZodMiniString<string>;
|
|
70
|
+
categoryId: z.ZodMiniString<string>;
|
|
71
|
+
purposeId: z.ZodMiniString<string>;
|
|
72
|
+
consentVersion: z.ZodMiniInt;
|
|
73
|
+
}, z.core.$strict>>>>;
|
|
74
|
+
}, z.core.$strict>>;
|
|
75
|
+
decisions: z.ZodMiniReadonly<z.ZodMiniArray<z.ZodMiniUnion<readonly [z.ZodMiniReadonly<z.ZodMiniObject<{
|
|
76
|
+
useId: z.ZodMiniString<string>;
|
|
77
|
+
decision: z.ZodMiniEnum<{
|
|
78
|
+
granted: "granted";
|
|
79
|
+
denied: "denied";
|
|
80
|
+
}>;
|
|
81
|
+
}, z.core.$strict>>, z.ZodMiniReadonly<z.ZodMiniObject<{
|
|
82
|
+
categoryId: z.ZodMiniString<string>;
|
|
83
|
+
decision: z.ZodMiniEnum<{
|
|
84
|
+
granted: "granted";
|
|
85
|
+
denied: "denied";
|
|
86
|
+
}>;
|
|
87
|
+
}, z.core.$strict>>]>>>;
|
|
88
|
+
}, z.core.$strict>>;
|
|
89
|
+
|
|
90
|
+
declare type ConsentDeniedReason = 'unknown-use' | 'undecided' | 'denied' | 'consent-version-mismatch';
|
|
91
|
+
|
|
92
|
+
/**
|
|
93
|
+
* Shared shape for enforcement guard errors. Only the concrete classes are public: each subpath
|
|
94
|
+
* exports exactly one of them, so consumers keep their own `instanceof` and literal `name` type.
|
|
95
|
+
*/
|
|
96
|
+
declare abstract class ConsentEnforcementError<Reason extends string> extends Error {
|
|
97
|
+
readonly useId: string;
|
|
98
|
+
readonly reason: Reason;
|
|
99
|
+
constructor(message: string, useId: string, reason: Reason);
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
declare type ConsentEvaluation = Readonly<{
|
|
103
|
+
allowed: true;
|
|
104
|
+
}> | Readonly<{
|
|
105
|
+
allowed: false;
|
|
106
|
+
reason: ConsentDeniedReason;
|
|
107
|
+
}>;
|
|
108
|
+
|
|
109
|
+
declare type ConsentPolicy = z.infer<typeof consentPolicySchema>;
|
|
110
|
+
|
|
111
|
+
declare const consentPolicySchema: z.ZodMiniReadonly<z.ZodMiniObject<{
|
|
112
|
+
purposes: z.ZodMiniReadonly<z.ZodMiniArray<z.ZodMiniReadonly<z.ZodMiniObject<{
|
|
113
|
+
id: z.ZodMiniString<string>;
|
|
114
|
+
title: z.ZodMiniString<string>;
|
|
115
|
+
description: z.ZodMiniString<string>;
|
|
116
|
+
}, z.core.$strict>>>>;
|
|
117
|
+
uses: z.ZodMiniReadonly<z.ZodMiniArray<z.ZodMiniReadonly<z.ZodMiniObject<{
|
|
118
|
+
id: z.ZodMiniString<string>;
|
|
119
|
+
serviceId: z.ZodMiniString<string>;
|
|
120
|
+
categoryId: z.ZodMiniString<string>;
|
|
121
|
+
purposeId: z.ZodMiniString<string>;
|
|
122
|
+
consentVersion: z.ZodMiniInt;
|
|
123
|
+
}, z.core.$strict>>>>;
|
|
124
|
+
}, z.core.$strict>>;
|
|
125
|
+
|
|
126
|
+
/** A current use with no decision or a grant for a different consent version. */
|
|
127
|
+
declare type ConsentRequirement = Readonly<{
|
|
128
|
+
useId: string;
|
|
129
|
+
categoryId: string;
|
|
130
|
+
/** The version required by the current policy for this use. */
|
|
131
|
+
consentVersion: number;
|
|
132
|
+
reason: 'undecided' | 'consent-version-mismatch';
|
|
133
|
+
}>;
|
|
134
|
+
|
|
135
|
+
/** In-memory runtime; methods can be passed as callbacks without binding. */
|
|
136
|
+
declare type ConsentRuntime = Readonly<{
|
|
137
|
+
getSnapshot: () => ConsentSnapshot;
|
|
138
|
+
evaluate: (useId: string) => ConsentEvaluation;
|
|
139
|
+
/** Includes undecided uses and version-mismatched grants, not explicit denials. */
|
|
140
|
+
getMismatchedConsent: () => readonly ConsentRequirement[];
|
|
141
|
+
/**
|
|
142
|
+
* Replace all choices from trusted persistence, preserving unknown uses and recorded versions.
|
|
143
|
+
* Validation checks structure, not evidence of user consent; use decision methods for new choices.
|
|
144
|
+
* Does not replace policy, renew versions or perform I/O. Effective changes notify existing guards.
|
|
145
|
+
*/
|
|
146
|
+
restoreState: (state: unknown) => ValidationResult<ConsentSnapshot>;
|
|
147
|
+
setConsentDecision: (command: ConsentDecisionCommand) => ValidationResult<ConsentSnapshot>;
|
|
148
|
+
setCategoryConsent: (command: CategoryConsentCommand) => ValidationResult<ConsentSnapshot>;
|
|
149
|
+
/** Validates all targets before one commit; observer errors can throw after that commit. */
|
|
150
|
+
setConsentDecisions: (command: ConsentDecisionsCommand) => ValidationResult<ConsentSnapshot>;
|
|
151
|
+
updatePolicy: (currentAppPolicy: unknown) => ValidationResult<ConsentSnapshot>;
|
|
152
|
+
subscribe: (listener: () => void) => () => void;
|
|
153
|
+
}>;
|
|
154
|
+
|
|
155
|
+
export declare type ConsentScript = Readonly<{
|
|
156
|
+
/** Throws synchronously if blocked; each permitted call creates one owned script. */
|
|
157
|
+
load: (options: ConsentScriptLoadOptions) => ConsentScriptHandle;
|
|
158
|
+
dispose: () => void;
|
|
159
|
+
}>;
|
|
160
|
+
|
|
161
|
+
export declare class ConsentScriptError extends ConsentEnforcementError<ConsentScriptErrorReason> {
|
|
162
|
+
readonly name = "ConsentScriptError";
|
|
163
|
+
constructor(useId: string, reason: ConsentScriptErrorReason);
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
export declare type ConsentScriptErrorReason = ConsentDeniedReason | 'disposed' | 'removed' | 'load-error';
|
|
167
|
+
|
|
168
|
+
export declare type ConsentScriptHandle = Readonly<{
|
|
169
|
+
element: HTMLScriptElement;
|
|
170
|
+
/** Native load completion, not proof of SDK initialization or ongoing consent. */
|
|
171
|
+
ready: Promise<void>;
|
|
172
|
+
/** Removes this node. Cannot undo execution or guarantee cancellation of its download. */
|
|
173
|
+
remove: () => void;
|
|
174
|
+
}>;
|
|
175
|
+
|
|
176
|
+
export declare type ConsentScriptLoadOptions = Readonly<{
|
|
177
|
+
/** External HTTP(S) URL, relative to the parent's document when needed. No inline scripts. */
|
|
178
|
+
src: string;
|
|
179
|
+
/** Defaults to document.head; must be connected. */
|
|
180
|
+
parent?: HTMLElement;
|
|
181
|
+
type?: 'classic' | 'module';
|
|
182
|
+
/** Defaults to true, like native dynamically inserted scripts. */
|
|
183
|
+
async?: boolean;
|
|
184
|
+
nonce?: string;
|
|
185
|
+
integrity?: string;
|
|
186
|
+
crossOrigin?: 'anonymous' | 'use-credentials';
|
|
187
|
+
referrerPolicy?: ReferrerPolicy;
|
|
188
|
+
}>;
|
|
189
|
+
|
|
190
|
+
export declare type ConsentScriptOptions = Readonly<{
|
|
191
|
+
consent: Pick<ConsentRuntime, 'evaluate' | 'subscribe'>;
|
|
192
|
+
useId: string;
|
|
193
|
+
}>;
|
|
194
|
+
|
|
195
|
+
/** One active app policy and recorded choices; not a history of policies shown to users. */
|
|
196
|
+
declare type ConsentSnapshot = Readonly<{
|
|
197
|
+
currentAppPolicy: ConsentPolicy;
|
|
198
|
+
state: ConsentState;
|
|
199
|
+
}>;
|
|
200
|
+
|
|
201
|
+
declare type ConsentState = z.infer<typeof consentStateSchema>;
|
|
202
|
+
|
|
203
|
+
declare const consentStateSchema: z.ZodMiniReadonly<z.ZodMiniObject<{
|
|
204
|
+
choices: z.ZodMiniReadonly<z.ZodMiniArray<z.ZodMiniReadonly<z.ZodMiniObject<{
|
|
205
|
+
useId: z.ZodMiniString<string>;
|
|
206
|
+
consentVersion: z.ZodMiniInt;
|
|
207
|
+
decision: z.ZodMiniEnum<{
|
|
208
|
+
granted: "granted";
|
|
209
|
+
denied: "denied";
|
|
210
|
+
}>;
|
|
211
|
+
}, z.core.$strict>>>>;
|
|
212
|
+
}, z.core.$strict>>;
|
|
213
|
+
|
|
214
|
+
/** External-script insertion guard, not a sandbox or an SDK shutdown mechanism. */
|
|
215
|
+
export declare function createConsentScript({ consent, useId }: ConsentScriptOptions): ConsentScript;
|
|
216
|
+
|
|
217
|
+
declare type ExclusiveTarget<T> = T extends {
|
|
218
|
+
useId: string;
|
|
219
|
+
} ? T & {
|
|
220
|
+
readonly categoryId?: never;
|
|
221
|
+
} : T & {
|
|
222
|
+
readonly useId?: never;
|
|
223
|
+
};
|
|
224
|
+
|
|
225
|
+
/** A validation issue without a copy of the rejected input. */
|
|
226
|
+
declare type ValidationIssue = Readonly<{
|
|
227
|
+
code: string;
|
|
228
|
+
path: readonly (string | number)[];
|
|
229
|
+
message: string;
|
|
230
|
+
}>;
|
|
231
|
+
|
|
232
|
+
declare type ValidationResult<T> = Readonly<{
|
|
233
|
+
success: true;
|
|
234
|
+
data: T;
|
|
235
|
+
}> | Readonly<{
|
|
236
|
+
success: false;
|
|
237
|
+
issues: readonly ValidationIssue[];
|
|
238
|
+
}>;
|
|
239
|
+
|
|
240
|
+
export { }
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,258 @@
|
|
|
1
|
+
import * as z from 'zod/mini';
|
|
2
|
+
|
|
3
|
+
/** Disjoint category/use decisions for one scope actually presented to the user. */
|
|
4
|
+
declare type BatchCommand = z.infer<typeof consentDecisionsCommandSchema>;
|
|
5
|
+
|
|
6
|
+
/** Records choices only for category members in userConsentedPolicy, not future members. */
|
|
7
|
+
export declare type CategoryConsentCommand = z.infer<typeof categoryConsentCommandSchema>;
|
|
8
|
+
|
|
9
|
+
declare const categoryConsentCommandSchema: z.ZodMiniReadonly<z.ZodMiniObject<{
|
|
10
|
+
userConsentedPolicy: z.ZodMiniReadonly<z.ZodMiniObject<{
|
|
11
|
+
purposes: z.ZodMiniReadonly<z.ZodMiniArray<z.ZodMiniReadonly<z.ZodMiniObject<{
|
|
12
|
+
id: z.ZodMiniString<string>;
|
|
13
|
+
title: z.ZodMiniString<string>;
|
|
14
|
+
description: z.ZodMiniString<string>;
|
|
15
|
+
}, z.core.$strict>>>>;
|
|
16
|
+
uses: z.ZodMiniReadonly<z.ZodMiniArray<z.ZodMiniReadonly<z.ZodMiniObject<{
|
|
17
|
+
id: z.ZodMiniString<string>;
|
|
18
|
+
serviceId: z.ZodMiniString<string>;
|
|
19
|
+
categoryId: z.ZodMiniString<string>;
|
|
20
|
+
purposeId: z.ZodMiniString<string>;
|
|
21
|
+
consentVersion: z.ZodMiniInt;
|
|
22
|
+
}, z.core.$strict>>>>;
|
|
23
|
+
}, z.core.$strict>>;
|
|
24
|
+
categoryId: z.ZodMiniString<string>;
|
|
25
|
+
decision: z.ZodMiniEnum<{
|
|
26
|
+
granted: "granted";
|
|
27
|
+
denied: "denied";
|
|
28
|
+
}>;
|
|
29
|
+
}, z.core.$strict>>;
|
|
30
|
+
|
|
31
|
+
/** An explicit decision; absence of a choice means undecided. */
|
|
32
|
+
export declare type ConsentChoice = z.infer<typeof consentChoiceSchema>;
|
|
33
|
+
|
|
34
|
+
declare const consentChoiceSchema: z.ZodMiniReadonly<z.ZodMiniObject<{
|
|
35
|
+
useId: z.ZodMiniString<string>;
|
|
36
|
+
consentVersion: z.ZodMiniInt;
|
|
37
|
+
decision: z.ZodMiniEnum<{
|
|
38
|
+
granted: "granted";
|
|
39
|
+
denied: "denied";
|
|
40
|
+
}>;
|
|
41
|
+
}, z.core.$strict>>;
|
|
42
|
+
|
|
43
|
+
export declare type ConsentDecision = z.infer<typeof consentDecisionSchema>;
|
|
44
|
+
|
|
45
|
+
/** userConsentedPolicy is the scope shown for this decision, including a denial. */
|
|
46
|
+
export declare type ConsentDecisionCommand = z.infer<typeof consentDecisionCommandSchema>;
|
|
47
|
+
|
|
48
|
+
declare const consentDecisionCommandSchema: z.ZodMiniReadonly<z.ZodMiniObject<{
|
|
49
|
+
userConsentedPolicy: z.ZodMiniReadonly<z.ZodMiniObject<{
|
|
50
|
+
purposes: z.ZodMiniReadonly<z.ZodMiniArray<z.ZodMiniReadonly<z.ZodMiniObject<{
|
|
51
|
+
id: z.ZodMiniString<string>;
|
|
52
|
+
title: z.ZodMiniString<string>;
|
|
53
|
+
description: z.ZodMiniString<string>;
|
|
54
|
+
}, z.core.$strict>>>>;
|
|
55
|
+
uses: z.ZodMiniReadonly<z.ZodMiniArray<z.ZodMiniReadonly<z.ZodMiniObject<{
|
|
56
|
+
id: z.ZodMiniString<string>;
|
|
57
|
+
serviceId: z.ZodMiniString<string>;
|
|
58
|
+
categoryId: z.ZodMiniString<string>;
|
|
59
|
+
purposeId: z.ZodMiniString<string>;
|
|
60
|
+
consentVersion: z.ZodMiniInt;
|
|
61
|
+
}, z.core.$strict>>>>;
|
|
62
|
+
}, z.core.$strict>>;
|
|
63
|
+
useId: z.ZodMiniString<string>;
|
|
64
|
+
decision: z.ZodMiniEnum<{
|
|
65
|
+
granted: "granted";
|
|
66
|
+
denied: "denied";
|
|
67
|
+
}>;
|
|
68
|
+
}, z.core.$strict>>;
|
|
69
|
+
|
|
70
|
+
declare const consentDecisionSchema: z.ZodMiniEnum<{
|
|
71
|
+
granted: "granted";
|
|
72
|
+
denied: "denied";
|
|
73
|
+
}>;
|
|
74
|
+
|
|
75
|
+
export declare type ConsentDecisionsCommand = Readonly<Omit<BatchCommand, 'decisions'> & {
|
|
76
|
+
decisions: readonly ExclusiveTarget<BatchCommand['decisions'][number]>[];
|
|
77
|
+
}>;
|
|
78
|
+
|
|
79
|
+
declare const consentDecisionsCommandSchema: z.ZodMiniReadonly<z.ZodMiniObject<{
|
|
80
|
+
userConsentedPolicy: z.ZodMiniReadonly<z.ZodMiniObject<{
|
|
81
|
+
purposes: z.ZodMiniReadonly<z.ZodMiniArray<z.ZodMiniReadonly<z.ZodMiniObject<{
|
|
82
|
+
id: z.ZodMiniString<string>;
|
|
83
|
+
title: z.ZodMiniString<string>;
|
|
84
|
+
description: z.ZodMiniString<string>;
|
|
85
|
+
}, z.core.$strict>>>>;
|
|
86
|
+
uses: z.ZodMiniReadonly<z.ZodMiniArray<z.ZodMiniReadonly<z.ZodMiniObject<{
|
|
87
|
+
id: z.ZodMiniString<string>;
|
|
88
|
+
serviceId: z.ZodMiniString<string>;
|
|
89
|
+
categoryId: z.ZodMiniString<string>;
|
|
90
|
+
purposeId: z.ZodMiniString<string>;
|
|
91
|
+
consentVersion: z.ZodMiniInt;
|
|
92
|
+
}, z.core.$strict>>>>;
|
|
93
|
+
}, z.core.$strict>>;
|
|
94
|
+
decisions: z.ZodMiniReadonly<z.ZodMiniArray<z.ZodMiniUnion<readonly [z.ZodMiniReadonly<z.ZodMiniObject<{
|
|
95
|
+
useId: z.ZodMiniString<string>;
|
|
96
|
+
decision: z.ZodMiniEnum<{
|
|
97
|
+
granted: "granted";
|
|
98
|
+
denied: "denied";
|
|
99
|
+
}>;
|
|
100
|
+
}, z.core.$strict>>, z.ZodMiniReadonly<z.ZodMiniObject<{
|
|
101
|
+
categoryId: z.ZodMiniString<string>;
|
|
102
|
+
decision: z.ZodMiniEnum<{
|
|
103
|
+
granted: "granted";
|
|
104
|
+
denied: "denied";
|
|
105
|
+
}>;
|
|
106
|
+
}, z.core.$strict>>]>>>;
|
|
107
|
+
}, z.core.$strict>>;
|
|
108
|
+
|
|
109
|
+
declare type ConsentDeniedReason = 'unknown-use' | 'undecided' | 'denied' | 'consent-version-mismatch';
|
|
110
|
+
|
|
111
|
+
export declare type ConsentEvaluation = Readonly<{
|
|
112
|
+
allowed: true;
|
|
113
|
+
}> | Readonly<{
|
|
114
|
+
allowed: false;
|
|
115
|
+
reason: ConsentDeniedReason;
|
|
116
|
+
}>;
|
|
117
|
+
|
|
118
|
+
export declare type ConsentPolicy = z.infer<typeof consentPolicySchema>;
|
|
119
|
+
|
|
120
|
+
declare const consentPolicySchema: z.ZodMiniReadonly<z.ZodMiniObject<{
|
|
121
|
+
purposes: z.ZodMiniReadonly<z.ZodMiniArray<z.ZodMiniReadonly<z.ZodMiniObject<{
|
|
122
|
+
id: z.ZodMiniString<string>;
|
|
123
|
+
title: z.ZodMiniString<string>;
|
|
124
|
+
description: z.ZodMiniString<string>;
|
|
125
|
+
}, z.core.$strict>>>>;
|
|
126
|
+
uses: z.ZodMiniReadonly<z.ZodMiniArray<z.ZodMiniReadonly<z.ZodMiniObject<{
|
|
127
|
+
id: z.ZodMiniString<string>;
|
|
128
|
+
serviceId: z.ZodMiniString<string>;
|
|
129
|
+
categoryId: z.ZodMiniString<string>;
|
|
130
|
+
purposeId: z.ZodMiniString<string>;
|
|
131
|
+
consentVersion: z.ZodMiniInt;
|
|
132
|
+
}, z.core.$strict>>>>;
|
|
133
|
+
}, z.core.$strict>>;
|
|
134
|
+
|
|
135
|
+
/** An app-defined reason for processing, reusable across service uses. */
|
|
136
|
+
export declare type ConsentPurpose = z.infer<typeof consentPurposeSchema>;
|
|
137
|
+
|
|
138
|
+
declare const consentPurposeSchema: z.ZodMiniReadonly<z.ZodMiniObject<{
|
|
139
|
+
id: z.ZodMiniString<string>;
|
|
140
|
+
title: z.ZodMiniString<string>;
|
|
141
|
+
description: z.ZodMiniString<string>;
|
|
142
|
+
}, z.core.$strict>>;
|
|
143
|
+
|
|
144
|
+
/** A current use with no decision or a grant for a different consent version. */
|
|
145
|
+
export declare type ConsentRequirement = Readonly<{
|
|
146
|
+
useId: string;
|
|
147
|
+
categoryId: string;
|
|
148
|
+
/** The version required by the current policy for this use. */
|
|
149
|
+
consentVersion: number;
|
|
150
|
+
reason: 'undecided' | 'consent-version-mismatch';
|
|
151
|
+
}>;
|
|
152
|
+
|
|
153
|
+
/** In-memory runtime; methods can be passed as callbacks without binding. */
|
|
154
|
+
export declare type ConsentRuntime = Readonly<{
|
|
155
|
+
getSnapshot: () => ConsentSnapshot;
|
|
156
|
+
evaluate: (useId: string) => ConsentEvaluation;
|
|
157
|
+
/** Includes undecided uses and version-mismatched grants, not explicit denials. */
|
|
158
|
+
getMismatchedConsent: () => readonly ConsentRequirement[];
|
|
159
|
+
/**
|
|
160
|
+
* Replace all choices from trusted persistence, preserving unknown uses and recorded versions.
|
|
161
|
+
* Validation checks structure, not evidence of user consent; use decision methods for new choices.
|
|
162
|
+
* Does not replace policy, renew versions or perform I/O. Effective changes notify existing guards.
|
|
163
|
+
*/
|
|
164
|
+
restoreState: (state: unknown) => ValidationResult<ConsentSnapshot>;
|
|
165
|
+
setConsentDecision: (command: ConsentDecisionCommand) => ValidationResult<ConsentSnapshot>;
|
|
166
|
+
setCategoryConsent: (command: CategoryConsentCommand) => ValidationResult<ConsentSnapshot>;
|
|
167
|
+
/** Validates all targets before one commit; observer errors can throw after that commit. */
|
|
168
|
+
setConsentDecisions: (command: ConsentDecisionsCommand) => ValidationResult<ConsentSnapshot>;
|
|
169
|
+
updatePolicy: (currentAppPolicy: unknown) => ValidationResult<ConsentSnapshot>;
|
|
170
|
+
subscribe: (listener: () => void) => () => void;
|
|
171
|
+
}>;
|
|
172
|
+
|
|
173
|
+
/** One active app policy and recorded choices; not a history of policies shown to users. */
|
|
174
|
+
export declare type ConsentSnapshot = Readonly<{
|
|
175
|
+
currentAppPolicy: ConsentPolicy;
|
|
176
|
+
state: ConsentState;
|
|
177
|
+
}>;
|
|
178
|
+
|
|
179
|
+
export declare type ConsentState = z.infer<typeof consentStateSchema>;
|
|
180
|
+
|
|
181
|
+
declare const consentStateSchema: z.ZodMiniReadonly<z.ZodMiniObject<{
|
|
182
|
+
choices: z.ZodMiniReadonly<z.ZodMiniArray<z.ZodMiniReadonly<z.ZodMiniObject<{
|
|
183
|
+
useId: z.ZodMiniString<string>;
|
|
184
|
+
consentVersion: z.ZodMiniInt;
|
|
185
|
+
decision: z.ZodMiniEnum<{
|
|
186
|
+
granted: "granted";
|
|
187
|
+
denied: "denied";
|
|
188
|
+
}>;
|
|
189
|
+
}, z.core.$strict>>>>;
|
|
190
|
+
}, z.core.$strict>>;
|
|
191
|
+
|
|
192
|
+
/** An optional use declared by the app, independent of user choices. */
|
|
193
|
+
export declare type ConsentUse = z.infer<typeof consentUseSchema>;
|
|
194
|
+
|
|
195
|
+
declare const consentUseSchema: z.ZodMiniReadonly<z.ZodMiniObject<{
|
|
196
|
+
id: z.ZodMiniString<string>;
|
|
197
|
+
serviceId: z.ZodMiniString<string>;
|
|
198
|
+
categoryId: z.ZodMiniString<string>;
|
|
199
|
+
purposeId: z.ZodMiniString<string>;
|
|
200
|
+
consentVersion: z.ZodMiniInt;
|
|
201
|
+
}, z.core.$strict>>;
|
|
202
|
+
|
|
203
|
+
/** Creates an isolated runtime from decoded data; invalid input creates no instance. */
|
|
204
|
+
export declare function createConsent(input: unknown): ValidationResult<ConsentRuntime>;
|
|
205
|
+
|
|
206
|
+
export declare type CreateConsentOptions = z.infer<typeof createConsentOptionsSchema>;
|
|
207
|
+
|
|
208
|
+
declare const createConsentOptionsSchema: z.ZodMiniReadonly<z.ZodMiniObject<{
|
|
209
|
+
currentAppPolicy: z.ZodMiniReadonly<z.ZodMiniObject<{
|
|
210
|
+
purposes: z.ZodMiniReadonly<z.ZodMiniArray<z.ZodMiniReadonly<z.ZodMiniObject<{
|
|
211
|
+
id: z.ZodMiniString<string>;
|
|
212
|
+
title: z.ZodMiniString<string>;
|
|
213
|
+
description: z.ZodMiniString<string>;
|
|
214
|
+
}, z.core.$strict>>>>;
|
|
215
|
+
uses: z.ZodMiniReadonly<z.ZodMiniArray<z.ZodMiniReadonly<z.ZodMiniObject<{
|
|
216
|
+
id: z.ZodMiniString<string>;
|
|
217
|
+
serviceId: z.ZodMiniString<string>;
|
|
218
|
+
categoryId: z.ZodMiniString<string>;
|
|
219
|
+
purposeId: z.ZodMiniString<string>;
|
|
220
|
+
consentVersion: z.ZodMiniInt;
|
|
221
|
+
}, z.core.$strict>>>>;
|
|
222
|
+
}, z.core.$strict>>;
|
|
223
|
+
initialState: z.ZodMiniReadonly<z.ZodMiniObject<{
|
|
224
|
+
choices: z.ZodMiniReadonly<z.ZodMiniArray<z.ZodMiniReadonly<z.ZodMiniObject<{
|
|
225
|
+
useId: z.ZodMiniString<string>;
|
|
226
|
+
consentVersion: z.ZodMiniInt;
|
|
227
|
+
decision: z.ZodMiniEnum<{
|
|
228
|
+
granted: "granted";
|
|
229
|
+
denied: "denied";
|
|
230
|
+
}>;
|
|
231
|
+
}, z.core.$strict>>>>;
|
|
232
|
+
}, z.core.$strict>>;
|
|
233
|
+
}, z.core.$strict>>;
|
|
234
|
+
|
|
235
|
+
declare type ExclusiveTarget<T> = T extends {
|
|
236
|
+
useId: string;
|
|
237
|
+
} ? T & {
|
|
238
|
+
readonly categoryId?: never;
|
|
239
|
+
} : T & {
|
|
240
|
+
readonly useId?: never;
|
|
241
|
+
};
|
|
242
|
+
|
|
243
|
+
/** A validation issue without a copy of the rejected input. */
|
|
244
|
+
export declare type ValidationIssue = Readonly<{
|
|
245
|
+
code: string;
|
|
246
|
+
path: readonly (string | number)[];
|
|
247
|
+
message: string;
|
|
248
|
+
}>;
|
|
249
|
+
|
|
250
|
+
export declare type ValidationResult<T> = Readonly<{
|
|
251
|
+
success: true;
|
|
252
|
+
data: T;
|
|
253
|
+
}> | Readonly<{
|
|
254
|
+
success: false;
|
|
255
|
+
issues: readonly ValidationIssue[];
|
|
256
|
+
}>;
|
|
257
|
+
|
|
258
|
+
export { }
|