gdc-common-utils-ts 2.3.23 → 2.3.24
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/dist/utils/consent.d.ts +16 -0
- package/dist/utils/consent.js +28 -2
- package/package.json +1 -1
package/dist/utils/consent.d.ts
CHANGED
|
@@ -53,6 +53,14 @@ export type BuildConsentClaimsSimpleInput = SubjectIdentifierInput & {
|
|
|
53
53
|
actions: string[];
|
|
54
54
|
consentIdentifier?: string;
|
|
55
55
|
consentDate?: string;
|
|
56
|
+
/**
|
|
57
|
+
* Upper bound for the grant, serialized as `Consent.period-end`. Access is
|
|
58
|
+
* inactive at and after this instant.
|
|
59
|
+
*
|
|
60
|
+
* Use an ISO 8601 date or date-time. A date-time with an explicit timezone
|
|
61
|
+
* is recommended when the caller offers access until a specific hour.
|
|
62
|
+
*/
|
|
63
|
+
periodEnd?: string;
|
|
56
64
|
decision?: 'permit' | 'deny';
|
|
57
65
|
/** Stable identifier/thread of the permission request that caused this decision. */
|
|
58
66
|
eventBasedOn?: string;
|
|
@@ -90,6 +98,14 @@ export declare function normalizePhone(value: string): string;
|
|
|
90
98
|
* @param value Raw identifier text.
|
|
91
99
|
*/
|
|
92
100
|
export declare function normalizeIdentifierToken(value: string): string;
|
|
101
|
+
/**
|
|
102
|
+
* Returns whether a Consent period boundary is an ISO 8601 calendar date or
|
|
103
|
+
* an absolute date-time carrying `Z` or an explicit numeric timezone.
|
|
104
|
+
*
|
|
105
|
+
* Date-only values remain supported for compatibility. Applications offering
|
|
106
|
+
* access until a specific hour should always send an absolute date-time.
|
|
107
|
+
*/
|
|
108
|
+
export declare function isValidConsentPeriodBoundary(value: string): boolean;
|
|
93
109
|
/**
|
|
94
110
|
* Parses a single canonical consent actor token into its resolved kind/value.
|
|
95
111
|
*
|
package/dist/utils/consent.js
CHANGED
|
@@ -24,6 +24,27 @@ export function normalizeIdentifierToken(value) {
|
|
|
24
24
|
function withPrefix(prefix, message) {
|
|
25
25
|
return prefix ? `${prefix} ${message}` : message;
|
|
26
26
|
}
|
|
27
|
+
/**
|
|
28
|
+
* Returns whether a Consent period boundary is an ISO 8601 calendar date or
|
|
29
|
+
* an absolute date-time carrying `Z` or an explicit numeric timezone.
|
|
30
|
+
*
|
|
31
|
+
* Date-only values remain supported for compatibility. Applications offering
|
|
32
|
+
* access until a specific hour should always send an absolute date-time.
|
|
33
|
+
*/
|
|
34
|
+
export function isValidConsentPeriodBoundary(value) {
|
|
35
|
+
const normalized = String(value || '').trim();
|
|
36
|
+
if (!/^\d{4}-\d{2}-\d{2}(?:T\d{2}:\d{2}(?::\d{2}(?:\.\d{1,9})?)?(?:Z|[+-]\d{2}:\d{2}))?$/.test(normalized)) {
|
|
37
|
+
return false;
|
|
38
|
+
}
|
|
39
|
+
const [year, month, day] = normalized.slice(0, 10).split('-').map(Number);
|
|
40
|
+
const calendarDate = new Date(Date.UTC(year, month - 1, day));
|
|
41
|
+
if (calendarDate.getUTCFullYear() !== year
|
|
42
|
+
|| calendarDate.getUTCMonth() !== month - 1
|
|
43
|
+
|| calendarDate.getUTCDate() !== day) {
|
|
44
|
+
return false;
|
|
45
|
+
}
|
|
46
|
+
return !Number.isNaN(Date.parse(normalized));
|
|
47
|
+
}
|
|
27
48
|
/**
|
|
28
49
|
* Parses a single canonical consent actor token into its resolved kind/value.
|
|
29
50
|
*
|
|
@@ -152,6 +173,10 @@ export function buildConsentClaimsSimple(input, options = {}) {
|
|
|
152
173
|
const actorIdentifier = resolveActorIdentifier(input.actor, { errorPrefix: options.errorPrefix });
|
|
153
174
|
const subjectIdentifier = resolveSubjectIdentifier(input, { errorPrefix: options.errorPrefix });
|
|
154
175
|
const consentDate = String(input.consentDate || '').trim() || new Date().toISOString().slice(0, 10);
|
|
176
|
+
const periodEnd = String(input.periodEnd || '').trim();
|
|
177
|
+
if (periodEnd && !isValidConsentPeriodBoundary(periodEnd)) {
|
|
178
|
+
throw new Error(withPrefix(options.errorPrefix, 'periodEnd must be a valid ISO 8601 date or date-time.'));
|
|
179
|
+
}
|
|
155
180
|
const consentIdentifier = String(input.consentIdentifier || '').trim() || String(options.consentIdentifierFactory?.() || '').trim();
|
|
156
181
|
if (!consentIdentifier) {
|
|
157
182
|
throw new Error(withPrefix(options.errorPrefix, 'consentIdentifier is required when no consentIdentifierFactory is provided.'));
|
|
@@ -165,6 +190,7 @@ export function buildConsentClaimsSimple(input, options = {}) {
|
|
|
165
190
|
[ClaimConsent.subject]: subjectIdentifier,
|
|
166
191
|
[ClaimConsent.identifier]: consentIdentifier,
|
|
167
192
|
[ClaimConsent.date]: consentDate,
|
|
193
|
+
...(periodEnd ? { [ClaimConsent.periodEnd]: periodEnd } : {}),
|
|
168
194
|
[ClaimConsent.purpose]: input.purpose,
|
|
169
195
|
[ClaimConsent.action]: (input.actions || []).join(','),
|
|
170
196
|
[ClaimConsent.actorIdentifier]: actorIdentifier,
|
|
@@ -504,9 +530,9 @@ export function isConsentRuleActive(rule, options = {}) {
|
|
|
504
530
|
: Date.now();
|
|
505
531
|
const periodStart = String(readConsentRuleClaim(rule, ClaimConsent.periodStart) || '').trim();
|
|
506
532
|
const periodEnd = String(readConsentRuleClaim(rule, ClaimConsent.periodEnd) || '').trim();
|
|
507
|
-
if (periodStart &&
|
|
533
|
+
if (periodStart && (Number.isNaN(Date.parse(periodStart)) || Date.parse(periodStart) > now))
|
|
508
534
|
return false;
|
|
509
|
-
if (periodEnd &&
|
|
535
|
+
if (periodEnd && (Number.isNaN(Date.parse(periodEnd)) || Date.parse(periodEnd) <= now))
|
|
510
536
|
return false;
|
|
511
537
|
return true;
|
|
512
538
|
}
|