@vectoriox/iox-ui 5.4.0 → 5.4.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.
@@ -55,6 +55,12 @@ declare const CONSENT_DEFAULTS_DENIED: Readonly<Record<(typeof CONSENT_MODE_PARA
55
55
  declare function toConsentModeSignals(decision: ConsentDecision | null | undefined): Record<string, ConsentModeSignal>;
56
56
  /** The inline `<head>` bootstrap (basic mode, D-C2): defaults denied before anything loads. */
57
57
  declare function consentModeBootstrapJs(): string;
58
+ /**
59
+ * The gated injection, as HTML (C2). Emitted by the SSR server ONLY when the request's cookie
60
+ * grants analytics AND the org has a measurementId — the bootstrap above is unconditional, this
61
+ * is not. Order inside: consent UPDATE before the loader, config after it.
62
+ */
63
+ declare function analyticsInjectionHtml(measurementId: string, decision: ConsentDecision): string;
58
64
 
59
- export { CONSENT_COOKIE_NAME, CONSENT_DEFAULTS_DENIED, CONSENT_MODE_PARAMS, ConsentCategory, consentModeBootstrapJs, cookieAttributes, decode, emptyDecision, encode, hasConsent, isExpired, needsPrompt, toConsentModeSignals };
65
+ export { CONSENT_COOKIE_NAME, CONSENT_DEFAULTS_DENIED, CONSENT_MODE_PARAMS, ConsentCategory, analyticsInjectionHtml, consentModeBootstrapJs, cookieAttributes, decode, emptyDecision, encode, hasConsent, isExpired, needsPrompt, toConsentModeSignals };
60
66
  export type { ConsentDecision, ConsentModeSignal };
@@ -120,6 +120,22 @@ function consentModeBootstrapJs() {
120
120
  return "window.dataLayer=window.dataLayer||[];function gtag(){dataLayer.push(arguments);}" +
121
121
  `gtag('consent','default',${JSON.stringify(CONSENT_DEFAULTS_DENIED)});`;
122
122
  }
123
+ /**
124
+ * The gated injection, as HTML (C2). Emitted by the SSR server ONLY when the request's cookie
125
+ * grants analytics AND the org has a measurementId — the bootstrap above is unconditional, this
126
+ * is not. Order inside: consent UPDATE before the loader, config after it.
127
+ */
128
+ function analyticsInjectionHtml(measurementId, decision) {
129
+ const id = (measurementId ?? '').trim();
130
+ if (!id || !/^[A-Za-z0-9-]+$/.test(id))
131
+ return '';
132
+ if (!hasConsent(decision, ConsentCategory.Analytics))
133
+ return '';
134
+ const signals = JSON.stringify(toConsentModeSignals(decision));
135
+ return `<script>gtag('consent','update',${signals});</script>` +
136
+ `<script async src="https://www.googletagmanager.com/gtag/js?id=${id}"></script>` +
137
+ `<script>gtag('js',new Date());gtag('config','${id}');</script>`;
138
+ }
123
139
 
124
140
  /**
125
141
  * @vectoriox/iox-ui/consent-core — the shared, FRAMEWORK-FREE core of visitor consent.
@@ -137,5 +153,5 @@ function consentModeBootstrapJs() {
137
153
  * Generated bundle index. Do not edit.
138
154
  */
139
155
 
140
- export { CONSENT_COOKIE_NAME, CONSENT_DEFAULTS_DENIED, CONSENT_MODE_PARAMS, ConsentCategory, consentModeBootstrapJs, cookieAttributes, decode, emptyDecision, encode, hasConsent, isExpired, needsPrompt, toConsentModeSignals };
156
+ export { CONSENT_COOKIE_NAME, CONSENT_DEFAULTS_DENIED, CONSENT_MODE_PARAMS, ConsentCategory, analyticsInjectionHtml, consentModeBootstrapJs, cookieAttributes, decode, emptyDecision, encode, hasConsent, isExpired, needsPrompt, toConsentModeSignals };
141
157
  //# sourceMappingURL=vectoriox-iox-ui-consent-core.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"vectoriox-iox-ui-consent-core.mjs","sources":["../../../projects/iox-ui/src/consent-core/consent.model.ts","../../../projects/iox-ui/src/consent-core/storage.ts","../../../projects/iox-ui/src/consent-core/consent-mode.ts","../../../projects/iox-ui/src/consent-core/public-api.ts","../../../projects/iox-ui/src/consent-core/vectoriox-iox-ui-consent-core.ts"],"sourcesContent":["/**\n * The visitor-consent vocabulary (consent plan C1). Framework-free for the same forced reason as\n * forms-core/seo-core/actions-core: iox-cms consumes it under plain Node, the engine at SSR time,\n * the builder for design-time preview — ONE implementation of what a decision is.\n */\n\nexport enum ConsentCategory {\n /** Always on, never user-controllable — the site working at all. */\n Necessary = 'necessary',\n Analytics = 'analytics',\n Marketing = 'marketing',\n}\n\n/** A visitor's recorded decision. `necessary` is implied true and never stored as false. */\nexport interface ConsentDecision {\n categories: Partial<Record<ConsentCategory, boolean>>;\n /** Bumping the org's policy version invalidates every prior decision. */\n policyVersion: string;\n /** ISO timestamp of the decision. */\n decidedAt: string;\n anonymousId: string;\n}\n\n/** A fresh \"nothing granted\" decision skeleton — used when a visitor must be asked. */\nexport function emptyDecision(anonymousId: string, policyVersion: string, now: Date = new Date()): ConsentDecision {\n return {\n categories: { [ConsentCategory.Necessary]: true },\n policyVersion,\n decidedAt: now.toISOString(),\n anonymousId,\n };\n}\n\n/** `null` (no decision yet) grants nothing; `necessary` is always granted. */\nexport function hasConsent(decision: ConsentDecision | null | undefined, category: ConsentCategory): boolean {\n if (category === ConsentCategory.Necessary) return true;\n if (!decision) return false;\n return decision.categories?.[category] === true;\n}\n\n/** A decision older than `maxMonths` no longer counts (default re-ask: 12 months, D-C6). */\nexport function isExpired(decision: ConsentDecision, now: Date, maxMonths: number): boolean {\n const decided = new Date(decision.decidedAt);\n if (Number.isNaN(decided.getTime())) return true;\n const expiry = new Date(decided);\n expiry.setMonth(expiry.getMonth() + maxMonths);\n return now >= expiry;\n}\n\n/**\n * The function the dead fork got wrong: **a recorded \"no\" is a decision.** The banner shows only\n * when there is no decision, the decision expired, or the policy version moved on — never because\n * the visitor declined.\n */\nexport function needsPrompt(\n decision: ConsentDecision | null | undefined,\n policyVersion: string,\n now: Date = new Date(),\n maxMonths = 12,\n): boolean {\n if (!decision) return true;\n if (decision.policyVersion !== policyVersion) return true;\n return isExpired(decision, now, maxMonths);\n}\n","import { ConsentCategory, ConsentDecision } from './consent.model';\n\n/** First-party cookie name — the visitor's browser carries the proof (D-C1). */\nexport const CONSENT_COOKIE_NAME = 'iox-consent';\n\n/** Cookie payload. Versioned so a future shape change can read old cookies tolerantly. */\nexport function encode(decision: ConsentDecision): string {\n return JSON.stringify({ v: 1, ...decision });\n}\n\n/**\n * Tolerant by contract: bad JSON, a foreign shape, a tampered cookie — all read as `null`\n * (\"no decision\"), never a throw and never a guess. The old fork threw its way to a re-prompt.\n */\nexport function decode(raw: string | null | undefined): ConsentDecision | null {\n if (!raw) return null;\n try {\n const parsed = JSON.parse(raw);\n if (!parsed || typeof parsed !== 'object') return null;\n if (typeof parsed.anonymousId !== 'string' || !parsed.anonymousId) return null;\n if (typeof parsed.policyVersion !== 'string') return null;\n if (!parsed.categories || typeof parsed.categories !== 'object' || Array.isArray(parsed.categories)) return null;\n const categories: Partial<Record<ConsentCategory, boolean>> = {};\n for (const [k, v] of Object.entries(parsed.categories)) {\n categories[k as ConsentCategory] = v === true;\n }\n categories[ConsentCategory.Necessary] = true;\n return {\n categories,\n policyVersion: parsed.policyVersion,\n decidedAt: typeof parsed.decidedAt === 'string' ? parsed.decidedAt : '',\n anonymousId: parsed.anonymousId,\n };\n } catch {\n return null;\n }\n}\n\n/** `Set-Cookie` attributes for the decision: a NECESSARY cookie, 12 months, first-party. */\nexport function cookieAttributes(maxMonths = 12): string {\n const maxAge = Math.floor(maxMonths * 30.44 * 24 * 60 * 60);\n return `Path=/; Max-Age=${maxAge}; SameSite=Lax; Secure`;\n}\n","import { ConsentCategory, ConsentDecision, hasConsent } from './consent.model';\n\n/**\n * Google Consent Mode v2 (consent plan §4): four parameters, mandatory for EEA/UK measurement\n * since March 2024. Our categories map onto them; `necessary` maps to none.\n */\nexport type ConsentModeSignal = 'granted' | 'denied';\n\nexport const CONSENT_MODE_PARAMS = [\n 'analytics_storage', 'ad_storage', 'ad_user_data', 'ad_personalization',\n] as const;\n\n/** What the SSR head declares BEFORE any tag can load (invariant I1): everything denied. */\nexport const CONSENT_DEFAULTS_DENIED: Readonly<Record<(typeof CONSENT_MODE_PARAMS)[number], ConsentModeSignal>> =\n Object.freeze({\n analytics_storage: 'denied',\n ad_storage: 'denied',\n ad_user_data: 'denied',\n ad_personalization: 'denied',\n });\n\n/** A decision → the four v2 signals. `null` (undecided) is indistinguishable from denied. */\nexport function toConsentModeSignals(decision: ConsentDecision | null | undefined): Record<string, ConsentModeSignal> {\n const analytics: ConsentModeSignal = hasConsent(decision ?? null, ConsentCategory.Analytics) ? 'granted' : 'denied';\n const marketing: ConsentModeSignal = hasConsent(decision ?? null, ConsentCategory.Marketing) ? 'granted' : 'denied';\n return {\n analytics_storage: analytics,\n ad_storage: marketing,\n ad_user_data: marketing,\n ad_personalization: marketing,\n };\n}\n\n/** The inline `<head>` bootstrap (basic mode, D-C2): defaults denied before anything loads. */\nexport function consentModeBootstrapJs(): string {\n return \"window.dataLayer=window.dataLayer||[];function gtag(){dataLayer.push(arguments);}\" +\n `gtag('consent','default',${JSON.stringify(CONSENT_DEFAULTS_DENIED)});`;\n}\n","/**\n * @vectoriox/iox-ui/consent-core — the shared, FRAMEWORK-FREE core of visitor consent.\n *\n * What a decision IS (`needsPrompt`: a recorded \"no\" is a decision), how it travels (a tolerant\n * first-party cookie), and what it tells Google (Consent Mode v2 signals, denied-by-default).\n * Consumed by the SSR engine (the gate, C2), the builder (banner preview, C3) and iox-cms (the\n * optional per-org log, C4) — the fourth entry point on the forms-core pattern, replacing the\n * dead byte-identical fork C0 deleted.\n * ⚠️ Consumers wire the usual trio — ng-package raw-ts assets, jest moduleNameMapper, tsconfig\n * paths — or `nest start` dies with ERR_REQUIRE_ESM while jest and build both pass.\n */\nexport * from './consent.model';\nexport * from './storage';\nexport * from './consent-mode';\n","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './public-api';\n"],"names":[],"mappings":"AAAA;;;;AAIG;IAES;AAAZ,CAAA,UAAY,eAAe,EAAA;;AAEvB,IAAA,eAAA,CAAA,WAAA,CAAA,GAAA,WAAuB;AACvB,IAAA,eAAA,CAAA,WAAA,CAAA,GAAA,WAAuB;AACvB,IAAA,eAAA,CAAA,WAAA,CAAA,GAAA,WAAuB;AAC3B,CAAC,EALW,eAAe,KAAf,eAAe,GAAA,EAAA,CAAA,CAAA;AAiB3B;AACM,SAAU,a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-core.mjs","sources":["../../../projects/iox-ui/src/consent-core/consent.model.ts","../../../projects/iox-ui/src/consent-core/storage.ts","../../../projects/iox-ui/src/consent-core/consent-mode.ts","../../../projects/iox-ui/src/consent-core/public-api.ts","../../../projects/iox-ui/src/consent-core/vectoriox-iox-ui-consent-core.ts"],"sourcesContent":["/**\n * The visitor-consent vocabulary (consent plan C1). Framework-free for the same forced reason as\n * forms-core/seo-core/actions-core: iox-cms consumes it under plain Node, the engine at SSR time,\n * the builder for design-time preview — ONE implementation of what a decision is.\n */\n\nexport enum ConsentCategory {\n /** Always on, never user-controllable — the site working at all. */\n Necessary = 'necessary',\n Analytics = 'analytics',\n Marketing = 'marketing',\n}\n\n/** A visitor's recorded decision. `necessary` is implied true and never stored as false. */\nexport interface ConsentDecision {\n categories: Partial<Record<ConsentCategory, boolean>>;\n /** Bumping the org's policy version invalidates every prior decision. */\n policyVersion: string;\n /** ISO timestamp of the decision. */\n decidedAt: string;\n anonymousId: string;\n}\n\n/** A fresh \"nothing granted\" decision skeleton — used when a visitor must be asked. */\nexport function emptyDecision(anonymousId: string, policyVersion: string, now: Date = new Date()): ConsentDecision {\n return {\n categories: { [ConsentCategory.Necessary]: true },\n policyVersion,\n decidedAt: now.toISOString(),\n anonymousId,\n };\n}\n\n/** `null` (no decision yet) grants nothing; `necessary` is always granted. */\nexport function hasConsent(decision: ConsentDecision | null | undefined, category: ConsentCategory): boolean {\n if (category === ConsentCategory.Necessary) return true;\n if (!decision) return false;\n return decision.categories?.[category] === true;\n}\n\n/** A decision older than `maxMonths` no longer counts (default re-ask: 12 months, D-C6). */\nexport function isExpired(decision: ConsentDecision, now: Date, maxMonths: number): boolean {\n const decided = new Date(decision.decidedAt);\n if (Number.isNaN(decided.getTime())) return true;\n const expiry = new Date(decided);\n expiry.setMonth(expiry.getMonth() + maxMonths);\n return now >= expiry;\n}\n\n/**\n * The function the dead fork got wrong: **a recorded \"no\" is a decision.** The banner shows only\n * when there is no decision, the decision expired, or the policy version moved on — never because\n * the visitor declined.\n */\nexport function needsPrompt(\n decision: ConsentDecision | null | undefined,\n policyVersion: string,\n now: Date = new Date(),\n maxMonths = 12,\n): boolean {\n if (!decision) return true;\n if (decision.policyVersion !== policyVersion) return true;\n return isExpired(decision, now, maxMonths);\n}\n","import { ConsentCategory, ConsentDecision } from './consent.model';\n\n/** First-party cookie name — the visitor's browser carries the proof (D-C1). */\nexport const CONSENT_COOKIE_NAME = 'iox-consent';\n\n/** Cookie payload. Versioned so a future shape change can read old cookies tolerantly. */\nexport function encode(decision: ConsentDecision): string {\n return JSON.stringify({ v: 1, ...decision });\n}\n\n/**\n * Tolerant by contract: bad JSON, a foreign shape, a tampered cookie — all read as `null`\n * (\"no decision\"), never a throw and never a guess. The old fork threw its way to a re-prompt.\n */\nexport function decode(raw: string | null | undefined): ConsentDecision | null {\n if (!raw) return null;\n try {\n const parsed = JSON.parse(raw);\n if (!parsed || typeof parsed !== 'object') return null;\n if (typeof parsed.anonymousId !== 'string' || !parsed.anonymousId) return null;\n if (typeof parsed.policyVersion !== 'string') return null;\n if (!parsed.categories || typeof parsed.categories !== 'object' || Array.isArray(parsed.categories)) return null;\n const categories: Partial<Record<ConsentCategory, boolean>> = {};\n for (const [k, v] of Object.entries(parsed.categories)) {\n categories[k as ConsentCategory] = v === true;\n }\n categories[ConsentCategory.Necessary] = true;\n return {\n categories,\n policyVersion: parsed.policyVersion,\n decidedAt: typeof parsed.decidedAt === 'string' ? parsed.decidedAt : '',\n anonymousId: parsed.anonymousId,\n };\n } catch {\n return null;\n }\n}\n\n/** `Set-Cookie` attributes for the decision: a NECESSARY cookie, 12 months, first-party. */\nexport function cookieAttributes(maxMonths = 12): string {\n const maxAge = Math.floor(maxMonths * 30.44 * 24 * 60 * 60);\n return `Path=/; Max-Age=${maxAge}; SameSite=Lax; Secure`;\n}\n","import { ConsentCategory, ConsentDecision, hasConsent } from './consent.model';\n\n/**\n * Google Consent Mode v2 (consent plan §4): four parameters, mandatory for EEA/UK measurement\n * since March 2024. Our categories map onto them; `necessary` maps to none.\n */\nexport type ConsentModeSignal = 'granted' | 'denied';\n\nexport const CONSENT_MODE_PARAMS = [\n 'analytics_storage', 'ad_storage', 'ad_user_data', 'ad_personalization',\n] as const;\n\n/** What the SSR head declares BEFORE any tag can load (invariant I1): everything denied. */\nexport const CONSENT_DEFAULTS_DENIED: Readonly<Record<(typeof CONSENT_MODE_PARAMS)[number], ConsentModeSignal>> =\n Object.freeze({\n analytics_storage: 'denied',\n ad_storage: 'denied',\n ad_user_data: 'denied',\n ad_personalization: 'denied',\n });\n\n/** A decision → the four v2 signals. `null` (undecided) is indistinguishable from denied. */\nexport function toConsentModeSignals(decision: ConsentDecision | null | undefined): Record<string, ConsentModeSignal> {\n const analytics: ConsentModeSignal = hasConsent(decision ?? null, ConsentCategory.Analytics) ? 'granted' : 'denied';\n const marketing: ConsentModeSignal = hasConsent(decision ?? null, ConsentCategory.Marketing) ? 'granted' : 'denied';\n return {\n analytics_storage: analytics,\n ad_storage: marketing,\n ad_user_data: marketing,\n ad_personalization: marketing,\n };\n}\n\n/** The inline `<head>` bootstrap (basic mode, D-C2): defaults denied before anything loads. */\nexport function consentModeBootstrapJs(): string {\n return \"window.dataLayer=window.dataLayer||[];function gtag(){dataLayer.push(arguments);}\" +\n `gtag('consent','default',${JSON.stringify(CONSENT_DEFAULTS_DENIED)});`;\n}\n\n/**\n * The gated injection, as HTML (C2). Emitted by the SSR server ONLY when the request's cookie\n * grants analytics AND the org has a measurementId — the bootstrap above is unconditional, this\n * is not. Order inside: consent UPDATE before the loader, config after it.\n */\nexport function analyticsInjectionHtml(measurementId: string, decision: ConsentDecision): string {\n const id = (measurementId ?? '').trim();\n if (!id || !/^[A-Za-z0-9-]+$/.test(id)) return '';\n if (!hasConsent(decision, ConsentCategory.Analytics)) return '';\n const signals = JSON.stringify(toConsentModeSignals(decision));\n return `<script>gtag('consent','update',${signals});</script>` +\n `<script async src=\"https://www.googletagmanager.com/gtag/js?id=${id}\"></script>` +\n `<script>gtag('js',new Date());gtag('config','${id}');</script>`;\n}\n","/**\n * @vectoriox/iox-ui/consent-core — the shared, FRAMEWORK-FREE core of visitor consent.\n *\n * What a decision IS (`needsPrompt`: a recorded \"no\" is a decision), how it travels (a tolerant\n * first-party cookie), and what it tells Google (Consent Mode v2 signals, denied-by-default).\n * Consumed by the SSR engine (the gate, C2), the builder (banner preview, C3) and iox-cms (the\n * optional per-org log, C4) — the fourth entry point on the forms-core pattern, replacing the\n * dead byte-identical fork C0 deleted.\n * ⚠️ Consumers wire the usual trio — ng-package raw-ts assets, jest moduleNameMapper, tsconfig\n * paths — or `nest start` dies with ERR_REQUIRE_ESM while jest and build both pass.\n */\nexport * from './consent.model';\nexport * from './storage';\nexport * from './consent-mode';\n","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './public-api';\n"],"names":[],"mappings":"AAAA;;;;AAIG;IAES;AAAZ,CAAA,UAAY,eAAe,EAAA;;AAEvB,IAAA,eAAA,CAAA,WAAA,CAAA,GAAA,WAAuB;AACvB,IAAA,eAAA,CAAA,WAAA,CAAA,GAAA,WAAuB;AACvB,IAAA,eAAA,CAAA,WAAA,CAAA,GAAA,WAAuB;AAC3B,CAAC,EALW,eAAe,KAAf,eAAe,GAAA,EAAA,CAAA,CAAA;AAiB3B;AACM,SAAU,aAAa,CAAC,WAAmB,EAAE,aAAqB,EAAE,GAAA,GAAY,IAAI,IAAI,EAAE,EAAA;IAC5F,OAAO;QACH,UAAU,EAAE,EAAE,CAAC,eAAe,CAAC,SAAS,GAAG,IAAI,EAAE;QACjD,aAAa;AACb,QAAA,SAAS,EAAE,GAAG,CAAC,WAAW,EAAE;QAC5B,WAAW;KACd;AACL;AAEA;AACM,SAAU,UAAU,CAAC,QAA4C,EAAE,QAAyB,EAAA;AAC9F,IAAA,IAAI,QAAQ,KAAK,eAAe,CAAC,SAAS;AAAE,QAAA,OAAO,IAAI;AACvD,IAAA,IAAI,CAAC,QAAQ;AAAE,QAAA,OAAO,KAAK;I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AE,CAAA,WAAA,CAAa;QACjF,CAAA,6CAAA,EAAgD,EAAE,cAAc;AACxE;;ACpDA;;;;;;;;;;AAUG;;ACVH;;AAEG;;;;"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vectoriox/iox-ui",
3
- "version": "5.4.0",
3
+ "version": "5.4.1",
4
4
  "peerDependencies": {
5
5
  "@angular/common": ">=20.0.0",
6
6
  "@angular/core": ">=20.0.0",
@@ -36,3 +36,18 @@ export function consentModeBootstrapJs(): string {
36
36
  return "window.dataLayer=window.dataLayer||[];function gtag(){dataLayer.push(arguments);}" +
37
37
  `gtag('consent','default',${JSON.stringify(CONSENT_DEFAULTS_DENIED)});`;
38
38
  }
39
+
40
+ /**
41
+ * The gated injection, as HTML (C2). Emitted by the SSR server ONLY when the request's cookie
42
+ * grants analytics AND the org has a measurementId — the bootstrap above is unconditional, this
43
+ * is not. Order inside: consent UPDATE before the loader, config after it.
44
+ */
45
+ export function analyticsInjectionHtml(measurementId: string, decision: ConsentDecision): string {
46
+ const id = (measurementId ?? '').trim();
47
+ if (!id || !/^[A-Za-z0-9-]+$/.test(id)) return '';
48
+ if (!hasConsent(decision, ConsentCategory.Analytics)) return '';
49
+ const signals = JSON.stringify(toConsentModeSignals(decision));
50
+ return `<script>gtag('consent','update',${signals});</script>` +
51
+ `<script async src="https://www.googletagmanager.com/gtag/js?id=${id}"></script>` +
52
+ `<script>gtag('js',new Date());gtag('config','${id}');</script>`;
53
+ }