@privacykit/web 1.2.0 → 1.2.2

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/index.js CHANGED
@@ -19,6 +19,34 @@ export function initPrivacyKit(options = {}) {
19
19
  if (typeof document === "undefined") {
20
20
  return;
21
21
  }
22
+ if (!window.PrivacyKit) {
23
+ const readyQueue = [];
24
+ const consentChangedQueue = [];
25
+ window.addEventListener('privacykit:ready', () => {
26
+ const pk = window.PrivacyKit;
27
+ for (const cb of consentChangedQueue) {
28
+ pk?.onConsentChanged(cb);
29
+ }
30
+ consentChangedQueue.length = 0;
31
+ for (const cb of readyQueue) {
32
+ cb();
33
+ }
34
+ readyQueue.length = 0;
35
+ }, { once: true });
36
+ window.PrivacyKit = {
37
+ _pk_queue: { readyQueue, consentChangedQueue },
38
+ onReady(cb) {
39
+ readyQueue.push(cb);
40
+ return () => { readyQueue.splice(readyQueue.indexOf(cb), 1); };
41
+ },
42
+ onConsentChanged(cb) {
43
+ consentChangedQueue.push(cb);
44
+ return () => { consentChangedQueue.splice(consentChangedQueue.indexOf(cb), 1); };
45
+ },
46
+ hasConsent: () => false,
47
+ readConsent: () => null,
48
+ };
49
+ }
22
50
  const cdnBaseUrl = options.cdnBaseUrl ?? DEFAULT_CDN_BASE_URL;
23
51
  const version = options.version ?? DEFAULT_VERSION;
24
52
  const baseUrl = `${cdnBaseUrl}/${version}`;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@privacykit/web",
3
- "version": "1.2.0",
3
+ "version": "1.2.2",
4
4
  "description": "Developer-friendly GDPR consent management with real enforcement.",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./index.d.ts",
@@ -27,9 +27,10 @@
27
27
  "access": "public"
28
28
  },
29
29
  "scripts": {
30
- "sync-types": "cp ../privacykit-sdk/public/privacykit.d.ts ./privacykit.d.ts",
30
+ "fix-type": "sed -i '' 's/PrivacyKit?: PrivacyKitGlobalApi/PrivacyKit: PrivacyKitGlobalApi/' ./privacykit.d.ts",
31
+ "sync-types": "cp ../privacykit-sdk/public/privacykit.d.ts ./privacykit.d.ts && npm run fix-type",
31
32
  "build": "npx tsc",
32
- "publish:patch": "npm run sync-types && npm run build && npm version patch && npm publish",
33
- "publish:minor": "npm run sync-types && npm run build && npm version minor && npm publish"
33
+ "publish:patch": "npm run build && npm login && npm version patch && npm publish",
34
+ "publish:minor": "npm run build && npm login && npm version minor && npm publish"
34
35
  }
35
36
  }
package/privacykit.d.ts CHANGED
@@ -243,7 +243,7 @@ declare global {
243
243
  }
244
244
 
245
245
  interface Window {
246
- PrivacyKit?: PrivacyKitGlobalApi;
246
+ PrivacyKit: PrivacyKitGlobalApi;
247
247
  }
248
248
 
249
249
  interface HTMLElementTagNameMap {