@pallasoft/ps-core-components 2.32.0 → 2.34.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.
Files changed (85) hide show
  1. package/dist/analytics/index.d.ts +12 -0
  2. package/dist/analytics/index.js +28 -0
  3. package/dist/analytics/report-client-error.d.ts +1 -0
  4. package/dist/analytics/report-client-error.js +6 -0
  5. package/dist/components/ps-analytics-provider.d.ts +14 -0
  6. package/dist/components/ps-analytics-provider.js +72 -0
  7. package/dist/components/ps-client-error-reporter.d.ts +5 -0
  8. package/dist/components/ps-client-error-reporter.js +22 -0
  9. package/dist/components/ps-consent-banner.d.ts +11 -0
  10. package/dist/components/ps-consent-banner.js +21 -0
  11. package/dist/constants/ps-analytics-config.d.ts +19 -0
  12. package/dist/constants/ps-analytics-config.js +22 -0
  13. package/dist/constants/ps-client-error-config.d.ts +23 -0
  14. package/dist/constants/ps-client-error-config.js +17 -0
  15. package/dist/esm/analytics/index.js +12 -0
  16. package/dist/esm/analytics/report-client-error.js +2 -0
  17. package/dist/esm/components/ps-analytics-provider.js +68 -0
  18. package/dist/esm/components/ps-client-error-reporter.js +18 -0
  19. package/dist/esm/components/ps-consent-banner.js +17 -0
  20. package/dist/esm/constants/ps-analytics-config.js +19 -0
  21. package/dist/esm/constants/ps-client-error-config.js +14 -0
  22. package/dist/esm/hooks/use-consent.js +17 -0
  23. package/dist/esm/hooks/use-ps-debounced-revalidate.js +23 -0
  24. package/dist/esm/hooks/use-ps-live.js +34 -0
  25. package/dist/esm/index.js +5 -0
  26. package/dist/esm/interfaces/ps-live-handle.js +1 -0
  27. package/dist/esm/interfaces/ps-live-input.js +1 -0
  28. package/dist/esm/interfaces/ps-live-open-options.js +1 -0
  29. package/dist/esm/models/analytics-csp-input.js +1 -0
  30. package/dist/esm/models/analytics-csp-origins.js +1 -0
  31. package/dist/esm/models/ps-client-error-payload.js +1 -0
  32. package/dist/esm/models/ps-client-error-settings.js +1 -0
  33. package/dist/esm/models/ps-consent-api.js +1 -0
  34. package/dist/esm/models/ps-consent-choice.js +1 -0
  35. package/dist/esm/models/ps-consent-state.js +1 -0
  36. package/dist/esm/models/ps-gtag-window.js +1 -0
  37. package/dist/esm/services/analytics-csp-service.js +27 -0
  38. package/dist/esm/services/ps-analytics-key-service.js +8 -0
  39. package/dist/esm/services/ps-client-error-service.js +72 -0
  40. package/dist/esm/services/ps-consent-service.js +57 -0
  41. package/dist/esm/services/ps-google-analytics-service.js +41 -0
  42. package/dist/esm/services/ps-post-hog-service.js +18 -0
  43. package/dist/hooks/use-consent.d.ts +2 -0
  44. package/dist/hooks/use-consent.js +21 -0
  45. package/dist/hooks/use-ps-debounced-revalidate.d.ts +2 -0
  46. package/dist/hooks/use-ps-debounced-revalidate.js +27 -0
  47. package/dist/hooks/use-ps-live.d.ts +2 -0
  48. package/dist/hooks/use-ps-live.js +38 -0
  49. package/dist/index.d.ts +5 -0
  50. package/dist/index.js +5 -0
  51. package/dist/interfaces/ps-live-handle.d.ts +3 -0
  52. package/dist/interfaces/ps-live-handle.js +2 -0
  53. package/dist/interfaces/ps-live-input.d.ts +11 -0
  54. package/dist/interfaces/ps-live-input.js +2 -0
  55. package/dist/interfaces/ps-live-open-options.d.ts +7 -0
  56. package/dist/interfaces/ps-live-open-options.js +2 -0
  57. package/dist/models/analytics-csp-input.d.ts +7 -0
  58. package/dist/models/analytics-csp-input.js +2 -0
  59. package/dist/models/analytics-csp-origins.d.ts +5 -0
  60. package/dist/models/analytics-csp-origins.js +2 -0
  61. package/dist/models/ps-client-error-payload.d.ts +9 -0
  62. package/dist/models/ps-client-error-payload.js +2 -0
  63. package/dist/models/ps-client-error-settings.d.ts +4 -0
  64. package/dist/models/ps-client-error-settings.js +2 -0
  65. package/dist/models/ps-consent-api.d.ts +9 -0
  66. package/dist/models/ps-consent-api.js +2 -0
  67. package/dist/models/ps-consent-choice.d.ts +1 -0
  68. package/dist/models/ps-consent-choice.js +2 -0
  69. package/dist/models/ps-consent-state.d.ts +5 -0
  70. package/dist/models/ps-consent-state.js +2 -0
  71. package/dist/models/ps-gtag-window.d.ts +4 -0
  72. package/dist/models/ps-gtag-window.js +2 -0
  73. package/dist/services/analytics-csp-service.d.ts +7 -0
  74. package/dist/services/analytics-csp-service.js +31 -0
  75. package/dist/services/ps-analytics-key-service.d.ts +3 -0
  76. package/dist/services/ps-analytics-key-service.js +12 -0
  77. package/dist/services/ps-client-error-service.d.ts +14 -0
  78. package/dist/services/ps-client-error-service.js +76 -0
  79. package/dist/services/ps-consent-service.d.ts +15 -0
  80. package/dist/services/ps-consent-service.js +61 -0
  81. package/dist/services/ps-google-analytics-service.d.ts +6 -0
  82. package/dist/services/ps-google-analytics-service.js +45 -0
  83. package/dist/services/ps-post-hog-service.d.ts +4 -0
  84. package/dist/services/ps-post-hog-service.js +55 -0
  85. package/package.json +15 -1
@@ -0,0 +1,61 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.PsConsentService = void 0;
4
+ const ps_analytics_config_1 = require("../constants/ps-analytics-config");
5
+ class PsConsentService {
6
+ static snapshot(cookieName) {
7
+ const existing = this.states.get(cookieName);
8
+ if (existing)
9
+ return existing;
10
+ const state = { choice: this.readCookie(cookieName), isReopened: false };
11
+ this.states.set(cookieName, state);
12
+ return state;
13
+ }
14
+ static subscribe(listener) {
15
+ this.listeners.add(listener);
16
+ return () => {
17
+ this.listeners.delete(listener);
18
+ };
19
+ }
20
+ static choose(cookieName, choice) {
21
+ this.writeCookie(cookieName, choice);
22
+ this.states.set(cookieName, { choice, isReopened: false });
23
+ this.notify();
24
+ }
25
+ static reopen(cookieName) {
26
+ this.states.set(cookieName, { ...this.snapshot(cookieName), isReopened: true });
27
+ this.notify();
28
+ }
29
+ static reset() {
30
+ this.states.clear();
31
+ this.notify();
32
+ }
33
+ static notify() {
34
+ this.listeners.forEach((listener) => listener());
35
+ }
36
+ static readCookie(cookieName) {
37
+ if (typeof document === 'undefined')
38
+ return null;
39
+ const prefix = `${cookieName}=`;
40
+ const entry = document.cookie
41
+ .split(';')
42
+ .map((part) => part.trim())
43
+ .find((part) => part.startsWith(prefix));
44
+ const value = entry ? entry.slice(prefix.length) : '';
45
+ if (value === ps_analytics_config_1.PsAnalyticsConfig.consentGranted)
46
+ return ps_analytics_config_1.PsAnalyticsConfig.consentGranted;
47
+ if (value === ps_analytics_config_1.PsAnalyticsConfig.consentDenied)
48
+ return ps_analytics_config_1.PsAnalyticsConfig.consentDenied;
49
+ return null;
50
+ }
51
+ static writeCookie(cookieName, choice) {
52
+ if (typeof document === 'undefined')
53
+ return;
54
+ const secure = window.location.protocol === 'https:' ? '; Secure' : '';
55
+ document.cookie = `${cookieName}=${choice}; Path=/; Max-Age=${ps_analytics_config_1.PsAnalyticsConfig.consentMaxAgeSeconds}; SameSite=Lax${secure}`;
56
+ }
57
+ }
58
+ exports.PsConsentService = PsConsentService;
59
+ PsConsentService.serverState = { choice: null, isReopened: false };
60
+ PsConsentService.states = new Map();
61
+ PsConsentService.listeners = new Set();
@@ -0,0 +1,6 @@
1
+ export declare class PsGoogleAnalyticsService {
2
+ static load(id: string, tagManagerUrl: string, nonce?: string): void;
3
+ static configure(id: string, pathname: string, userId: string | null | undefined): void;
4
+ static clearUser(): void;
5
+ static disable(id: string): void;
6
+ }
@@ -0,0 +1,45 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.PsGoogleAnalyticsService = void 0;
4
+ const ps_analytics_config_1 = require("../constants/ps-analytics-config");
5
+ class PsGoogleAnalyticsService {
6
+ static load(id, tagManagerUrl, nonce) {
7
+ const target = window;
8
+ Reflect.set(window, `ga-disable-${id}`, false);
9
+ if (typeof target.gtag !== 'function') {
10
+ target.dataLayer = target.dataLayer ? target.dataLayer : [];
11
+ target.gtag = function gtag() {
12
+ target.dataLayer?.push(arguments);
13
+ };
14
+ target.gtag('js', new Date());
15
+ }
16
+ if (document.querySelector(`script[${ps_analytics_config_1.PsAnalyticsConfig.scriptAttribute}="${id}"]`))
17
+ return;
18
+ const script = document.createElement('script');
19
+ script.async = true;
20
+ script.src = `${tagManagerUrl.replace(/\/+$/, '')}${ps_analytics_config_1.PsAnalyticsConfig.tagManagerScriptPath}${encodeURIComponent(id)}`;
21
+ script.setAttribute(ps_analytics_config_1.PsAnalyticsConfig.scriptAttribute, id);
22
+ if (nonce)
23
+ script.setAttribute('nonce', nonce);
24
+ document.head.appendChild(script);
25
+ }
26
+ static configure(id, pathname, userId) {
27
+ const target = window;
28
+ if (typeof target.gtag !== 'function')
29
+ return;
30
+ target.gtag('config', id, {
31
+ send_page_view: false,
32
+ page_path: pathname,
33
+ ...(userId ? { user_id: userId } : {}),
34
+ });
35
+ }
36
+ static clearUser() {
37
+ const target = window;
38
+ if (typeof target.gtag === 'function')
39
+ target.gtag('set', { user_id: undefined });
40
+ }
41
+ static disable(id) {
42
+ Reflect.set(window, `ga-disable-${id}`, true);
43
+ }
44
+ }
45
+ exports.PsGoogleAnalyticsService = PsGoogleAnalyticsService;
@@ -0,0 +1,4 @@
1
+ import type { PostHog } from 'posthog-js';
2
+ export declare class PsPostHogService {
3
+ static load(key: string, apiHost: string | undefined): Promise<PostHog>;
4
+ }
@@ -0,0 +1,55 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ Object.defineProperty(exports, "__esModule", { value: true });
36
+ exports.PsPostHogService = void 0;
37
+ const ps_analytics_config_1 = require("../constants/ps-analytics-config");
38
+ class PsPostHogService {
39
+ static async load(key, apiHost) {
40
+ const module = await Promise.resolve().then(() => __importStar(require('posthog-js')));
41
+ const client = module.default;
42
+ client.init(key, {
43
+ ...(apiHost ? { api_host: apiHost } : {}),
44
+ defaults: ps_analytics_config_1.PsAnalyticsConfig.postHog.defaults,
45
+ autocapture: ps_analytics_config_1.PsAnalyticsConfig.postHog.autocapture,
46
+ capture_pageview: false,
47
+ capture_pageleave: ps_analytics_config_1.PsAnalyticsConfig.postHog.capturePageleave,
48
+ capture_exceptions: ps_analytics_config_1.PsAnalyticsConfig.postHog.captureExceptions,
49
+ person_profiles: ps_analytics_config_1.PsAnalyticsConfig.postHog.personProfiles,
50
+ });
51
+ client.opt_in_capturing();
52
+ return client;
53
+ }
54
+ }
55
+ exports.PsPostHogService = PsPostHogService;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pallasoft/ps-core-components",
3
- "version": "2.32.0",
3
+ "version": "2.34.0",
4
4
  "private": false,
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/esm/index.js",
@@ -12,6 +12,19 @@
12
12
  "module": "./dist/esm/index.js",
13
13
  "require": "./dist/index.js",
14
14
  "default": "./dist/index.js"
15
+ },
16
+ "./analytics": {
17
+ "types": "./dist/analytics/index.d.ts",
18
+ "module": "./dist/esm/analytics/index.js",
19
+ "require": "./dist/analytics/index.js",
20
+ "default": "./dist/analytics/index.js"
21
+ }
22
+ },
23
+ "typesVersions": {
24
+ "*": {
25
+ "analytics": [
26
+ "./dist/analytics/index.d.ts"
27
+ ]
15
28
  }
16
29
  },
17
30
  "files": [
@@ -41,6 +54,7 @@
41
54
  "@portabletext/react": "^3.2.4",
42
55
  "@portabletext/types": "^2.0.13",
43
56
  "@radix-ui/react-accordion": "^1.2.12",
57
+ "posthog-js": "^1.438.5",
44
58
  "react-infinite-scroll-component": "^6.1.1"
45
59
  },
46
60
  "peerDependencies": {