gdc-common-utils-ts 2.3.22 → 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 +37 -3
- 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,
|
|
@@ -230,8 +256,16 @@ function normalizeConsentRoleValue(value) {
|
|
|
230
256
|
if (!trimmed || trimmed === '*')
|
|
231
257
|
return trimmed;
|
|
232
258
|
const [system, code] = trimmed.includes('|') ? trimmed.split('|', 2) : ['', trimmed];
|
|
259
|
+
const normalizedSystem = system.trim().toLowerCase();
|
|
260
|
+
const canonicalSystem = [
|
|
261
|
+
'isco-08',
|
|
262
|
+
'org.ilo.isco',
|
|
263
|
+
'org.ilo.isco-08',
|
|
264
|
+
].includes(normalizedSystem)
|
|
265
|
+
? 'org.ilo.isco-08'
|
|
266
|
+
: normalizedSystem;
|
|
233
267
|
return system
|
|
234
|
-
? `${
|
|
268
|
+
? `${canonicalSystem}|${code.trim().toLowerCase()}`
|
|
235
269
|
: trimmed.toLowerCase();
|
|
236
270
|
}
|
|
237
271
|
function parseNormalizedConsentRole(value) {
|
|
@@ -496,9 +530,9 @@ export function isConsentRuleActive(rule, options = {}) {
|
|
|
496
530
|
: Date.now();
|
|
497
531
|
const periodStart = String(readConsentRuleClaim(rule, ClaimConsent.periodStart) || '').trim();
|
|
498
532
|
const periodEnd = String(readConsentRuleClaim(rule, ClaimConsent.periodEnd) || '').trim();
|
|
499
|
-
if (periodStart &&
|
|
533
|
+
if (periodStart && (Number.isNaN(Date.parse(periodStart)) || Date.parse(periodStart) > now))
|
|
500
534
|
return false;
|
|
501
|
-
if (periodEnd &&
|
|
535
|
+
if (periodEnd && (Number.isNaN(Date.parse(periodEnd)) || Date.parse(periodEnd) <= now))
|
|
502
536
|
return false;
|
|
503
537
|
return true;
|
|
504
538
|
}
|