c15t 1.2.0-canary.8 → 1.2.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.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,18 @@
1
1
  # c15t
2
2
 
3
+ ## 1.2.0
4
+
5
+ ### Minor Changes
6
+
7
+ - [#224](https://github.com/c15t/c15t/pull/224) [`838a9b5`](https://github.com/c15t/c15t/commit/838a9b52c31326899ec3c903e43bf7bc31a6490f) Thanks [@BurnedChris](https://github.com/BurnedChris)! - Refactored backend to be a new orpc client / server
8
+
9
+ ### Patch Changes
10
+
11
+ - [#222](https://github.com/c15t/c15t/pull/222) [`b1de2ba`](https://github.com/c15t/c15t/commit/b1de2baccd63295d49fb2868f63659f5ff48a9ce) Thanks [@KayleeWilliams](https://github.com/KayleeWilliams)! - fix(core, react): added "common" translations, removed widget translations
12
+
13
+ - Updated dependencies [[`838a9b5`](https://github.com/c15t/c15t/commit/838a9b52c31326899ec3c903e43bf7bc31a6490f)]:
14
+ - @c15t/backend@1.2.0
15
+
3
16
  ## 1.1.4
4
17
 
5
18
  ### Patch Changes
package/dist/index.cjs CHANGED
@@ -856,6 +856,109 @@ function hasConsentFor(consentType, consents, honorDoNotTrack) {
856
856
  function consent_utils_hasConsented(consentInfo) {
857
857
  return null !== consentInfo;
858
858
  }
859
+ const getCookie = (name)=>{
860
+ if ('undefined' == typeof document) return null;
861
+ const value = `; ${document.cookie}`;
862
+ const parts = value.split(`; ${name}=`);
863
+ if (2 === parts.length) {
864
+ const cookieValue = parts.pop()?.split(';').shift();
865
+ return cookieValue ? decodeURIComponent(cookieValue) : null;
866
+ }
867
+ return null;
868
+ };
869
+ function getConsentBannerCookie(config) {
870
+ if ('undefined' == typeof document) return null;
871
+ const cookie = getCookie('show-consent-banner');
872
+ if (!cookie) return null;
873
+ try {
874
+ const cookieData = JSON.parse(cookie);
875
+ const { get } = config;
876
+ const { callbacks, setDetectedCountry } = get();
877
+ updateStoreWithBannerData(cookieData, config, true);
878
+ if (cookieData.location?.countryCode) {
879
+ setDetectedCountry(cookieData.location.countryCode);
880
+ if (cookieData.location.regionCode) callbacks.onLocationDetected?.({
881
+ countryCode: cookieData.location.countryCode,
882
+ regionCode: cookieData.location.regionCode
883
+ });
884
+ }
885
+ return cookieData;
886
+ } catch (error) {
887
+ console.warn('Failed to parse consent banner cookie:', error);
888
+ return null;
889
+ }
890
+ }
891
+ function checkLocalStorageAccess(set) {
892
+ try {
893
+ if (window.localStorage) {
894
+ window.localStorage.setItem('c15t-storage-test-key', 'test');
895
+ window.localStorage.removeItem('c15t-storage-test-key');
896
+ return true;
897
+ }
898
+ } catch (error) {
899
+ console.warn('localStorage not available, skipping consent banner:', error);
900
+ set({
901
+ isLoadingConsentInfo: false,
902
+ showPopup: false
903
+ });
904
+ }
905
+ return false;
906
+ }
907
+ function updateStoreWithBannerData(data, { set, get }, hasLocalStorageAccess) {
908
+ const { consentInfo } = get();
909
+ set({
910
+ locationInfo: {
911
+ countryCode: data.location?.countryCode ?? '',
912
+ regionCode: data.location?.regionCode ?? ''
913
+ },
914
+ jurisdictionInfo: data.jurisdiction,
915
+ isLoadingConsentInfo: false,
916
+ ...null === consentInfo ? {
917
+ showPopup: data.showConsentBanner && hasLocalStorageAccess
918
+ } : {}
919
+ });
920
+ }
921
+ async function fetchConsentBannerInfo(config) {
922
+ const { get, set, manager } = config;
923
+ const { hasConsented, callbacks, consentInfo } = get();
924
+ if ('undefined' == typeof window || hasConsented()) return void set({
925
+ isLoadingConsentInfo: false
926
+ });
927
+ const hasLocalStorageAccess = checkLocalStorageAccess(set);
928
+ if (!hasLocalStorageAccess) return;
929
+ const cookieData = getConsentBannerCookie(config);
930
+ if (cookieData) return cookieData;
931
+ set({
932
+ isLoadingConsentInfo: true
933
+ });
934
+ try {
935
+ const { data, error } = await manager.showConsentBanner({
936
+ onError: callbacks.onError ? (context)=>{
937
+ if (callbacks.onError) callbacks.onError(context.error?.message || 'Unknown error');
938
+ } : void 0
939
+ });
940
+ if (error) throw new Error(`Failed to fetch consent banner info: ${error.message}`);
941
+ if (!data) return void set({
942
+ isLoadingConsentInfo: false,
943
+ ...null === consentInfo && hasLocalStorageAccess ? {
944
+ showPopup: true
945
+ } : {}
946
+ });
947
+ updateStoreWithBannerData(data, config, hasLocalStorageAccess);
948
+ return data;
949
+ } catch (error) {
950
+ console.error('Error fetching consent banner information:', error);
951
+ set({
952
+ isLoadingConsentInfo: false
953
+ });
954
+ const errorMessage = error instanceof Error ? error.message : 'Unknown error fetching consent banner information';
955
+ callbacks.onError?.(errorMessage);
956
+ set({
957
+ showPopup: false
958
+ });
959
+ return;
960
+ }
961
+ }
859
962
  const DEFAULT_DOMAIN_CONSENT_MAP = {
860
963
  'www.google-analytics.com': 'measurement',
861
964
  'analytics.google.com': 'measurement',
@@ -1091,27 +1194,19 @@ function createTrackingBlocker(config = {}, initialConsents) {
1091
1194
  };
1092
1195
  }
1093
1196
  const enTranslations = {
1094
- cookieBanner: {
1095
- title: 'We value your privacy',
1096
- description: 'This site uses cookies to improve your browsing experience, analyze site traffic, and show personalized content.',
1197
+ common: {
1097
1198
  acceptAll: 'Accept All',
1098
1199
  rejectAll: 'Reject All',
1099
- customize: 'Customize'
1200
+ customize: 'Customize',
1201
+ save: 'Save Settings'
1202
+ },
1203
+ cookieBanner: {
1204
+ title: 'We value your privacy',
1205
+ description: 'This site uses cookies to improve your browsing experience, analyze site traffic, and show personalized content.'
1100
1206
  },
1101
1207
  consentManagerDialog: {
1102
1208
  title: 'Privacy Settings',
1103
- description: 'Customize your privacy settings here. You can choose which types of cookies and tracking technologies you allow.',
1104
- save: 'Save Settings',
1105
- acceptAll: 'Accept All',
1106
- rejectAll: 'Reject All',
1107
- close: 'Close'
1108
- },
1109
- consentManagerWidget: {
1110
- title: 'Privacy Preferences',
1111
- description: 'Manage your privacy settings',
1112
- save: 'Save Settings',
1113
- acceptAll: 'Accept All',
1114
- rejectAll: 'Reject All'
1209
+ description: 'Customize your privacy settings here. You can choose which types of cookies and tracking technologies you allow.'
1115
1210
  },
1116
1211
  consentTypes: {
1117
1212
  necessary: {
@@ -1363,74 +1458,11 @@ const createConsentManagerStore = (manager, options = {})=>{
1363
1458
  setLocationInfo: (location)=>set({
1364
1459
  locationInfo: location
1365
1460
  }),
1366
- fetchConsentBannerInfo: async ()=>{
1367
- const { callbacks, setDetectedCountry, consentInfo, hasConsented } = get();
1368
- if ('undefined' == typeof window) return;
1369
- if (hasConsented()) return void set({
1370
- isLoadingConsentInfo: false
1371
- });
1372
- let hasLocalStorageAccess = true;
1373
- try {
1374
- if (window.localStorage) {
1375
- window.localStorage.setItem('c15t-storage-test-key', 'test');
1376
- window.localStorage.removeItem('c15t-storage-test-key');
1377
- }
1378
- } catch (error) {
1379
- hasLocalStorageAccess = false;
1380
- console.warn('localStorage not available, skipping consent banner:', error);
1381
- set({
1382
- isLoadingConsentInfo: false,
1383
- showPopup: false
1384
- });
1385
- return;
1386
- }
1387
- set({
1388
- isLoadingConsentInfo: true
1389
- });
1390
- try {
1391
- const { data, error } = await manager.showConsentBanner({
1392
- onError: callbacks.onError
1393
- });
1394
- if (error) throw new Error(`Failed to fetch consent banner info: ${error.message}`);
1395
- if (!data) return void set({
1396
- isLoadingConsentInfo: false,
1397
- ...null === consentInfo && hasLocalStorageAccess ? {
1398
- showPopup: true
1399
- } : {}
1400
- });
1401
- set({
1402
- locationInfo: data.location?.countryCode && data.location?.regionCode ? {
1403
- countryCode: data.location.countryCode,
1404
- regionCode: data.location.regionCode
1405
- } : {
1406
- countryCode: '',
1407
- regionCode: ''
1408
- },
1409
- jurisdictionInfo: data.jurisdiction,
1410
- isLoadingConsentInfo: false,
1411
- ...null === consentInfo ? {
1412
- showPopup: data.showConsentBanner && hasLocalStorageAccess
1413
- } : {}
1414
- });
1415
- if (data.location?.countryCode) setDetectedCountry(data.location.countryCode);
1416
- if (data.location?.countryCode && data.location?.regionCode) callbacks.onLocationDetected?.({
1417
- countryCode: data.location.countryCode,
1418
- regionCode: data.location.regionCode
1419
- });
1420
- return data;
1421
- } catch (error) {
1422
- console.error('Error fetching consent banner information:', error);
1423
- set({
1424
- isLoadingConsentInfo: false
1425
- });
1426
- const errorMessage = error instanceof Error ? error.message : 'Unknown error fetching consent banner information';
1427
- callbacks.onError?.(errorMessage);
1428
- set({
1429
- showPopup: false
1430
- });
1431
- return;
1432
- }
1433
- },
1461
+ fetchConsentBannerInfo: ()=>fetchConsentBannerInfo({
1462
+ manager,
1463
+ get,
1464
+ set
1465
+ }),
1434
1466
  getDisplayedConsents: ()=>{
1435
1467
  const { gdprTypes, consentTypes } = get();
1436
1468
  return consentTypes.filter((consent)=>gdprTypes.includes(consent.name));
@@ -1463,7 +1495,7 @@ function deepMergeTranslations(base, override) {
1463
1495
  const sections = [
1464
1496
  'cookieBanner',
1465
1497
  'consentManagerDialog',
1466
- 'consentManagerWidget',
1498
+ 'common',
1467
1499
  'consentTypes'
1468
1500
  ];
1469
1501
  return sections.reduce((result, section)=>{
package/dist/index.d.ts CHANGED
@@ -119,7 +119,7 @@ export type { CallbackFunction, Callbacks } from './types/callbacks';
119
119
  * - Consent manager dialog translations
120
120
  * - Consent manager widget translations
121
121
  */
122
- export type { ConsentManagerDialogTranslations, ConsentManagerWidgetTranslations, ConsentTypeTranslations, ConsentTypesTranslations, CookieBannerTranslations, TranslationConfig, Translations, } from './types/translations';
122
+ export type { ConsentManagerDialogTranslations, CommonTranslations, ConsentTypeTranslations, ConsentTypesTranslations, CookieBannerTranslations, TranslationConfig, Translations, } from './types/translations';
123
123
  /**
124
124
  * @module
125
125
  * Client Types
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AACH,YAAY,EACX,gBAAgB,EAChB,kBAAkB,EAClB,qBAAqB,EACrB,YAAY,EACZ,iBAAiB,EACjB,gBAAgB,EAChB,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,EAAE,eAAe,EAAE,gBAAgB,EAAE,MAAM,eAAe,CAAC"}
package/dist/index.js CHANGED
@@ -816,6 +816,109 @@ function hasConsentFor(consentType, consents, honorDoNotTrack) {
816
816
  function consent_utils_hasConsented(consentInfo) {
817
817
  return null !== consentInfo;
818
818
  }
819
+ const getCookie = (name)=>{
820
+ if ('undefined' == typeof document) return null;
821
+ const value = `; ${document.cookie}`;
822
+ const parts = value.split(`; ${name}=`);
823
+ if (2 === parts.length) {
824
+ const cookieValue = parts.pop()?.split(';').shift();
825
+ return cookieValue ? decodeURIComponent(cookieValue) : null;
826
+ }
827
+ return null;
828
+ };
829
+ function getConsentBannerCookie(config) {
830
+ if ('undefined' == typeof document) return null;
831
+ const cookie = getCookie('show-consent-banner');
832
+ if (!cookie) return null;
833
+ try {
834
+ const cookieData = JSON.parse(cookie);
835
+ const { get } = config;
836
+ const { callbacks, setDetectedCountry } = get();
837
+ updateStoreWithBannerData(cookieData, config, true);
838
+ if (cookieData.location?.countryCode) {
839
+ setDetectedCountry(cookieData.location.countryCode);
840
+ if (cookieData.location.regionCode) callbacks.onLocationDetected?.({
841
+ countryCode: cookieData.location.countryCode,
842
+ regionCode: cookieData.location.regionCode
843
+ });
844
+ }
845
+ return cookieData;
846
+ } catch (error) {
847
+ console.warn('Failed to parse consent banner cookie:', error);
848
+ return null;
849
+ }
850
+ }
851
+ function checkLocalStorageAccess(set) {
852
+ try {
853
+ if (window.localStorage) {
854
+ window.localStorage.setItem('c15t-storage-test-key', 'test');
855
+ window.localStorage.removeItem('c15t-storage-test-key');
856
+ return true;
857
+ }
858
+ } catch (error) {
859
+ console.warn('localStorage not available, skipping consent banner:', error);
860
+ set({
861
+ isLoadingConsentInfo: false,
862
+ showPopup: false
863
+ });
864
+ }
865
+ return false;
866
+ }
867
+ function updateStoreWithBannerData(data, { set, get }, hasLocalStorageAccess) {
868
+ const { consentInfo } = get();
869
+ set({
870
+ locationInfo: {
871
+ countryCode: data.location?.countryCode ?? '',
872
+ regionCode: data.location?.regionCode ?? ''
873
+ },
874
+ jurisdictionInfo: data.jurisdiction,
875
+ isLoadingConsentInfo: false,
876
+ ...null === consentInfo ? {
877
+ showPopup: data.showConsentBanner && hasLocalStorageAccess
878
+ } : {}
879
+ });
880
+ }
881
+ async function fetchConsentBannerInfo(config) {
882
+ const { get, set, manager } = config;
883
+ const { hasConsented, callbacks, consentInfo } = get();
884
+ if ('undefined' == typeof window || hasConsented()) return void set({
885
+ isLoadingConsentInfo: false
886
+ });
887
+ const hasLocalStorageAccess = checkLocalStorageAccess(set);
888
+ if (!hasLocalStorageAccess) return;
889
+ const cookieData = getConsentBannerCookie(config);
890
+ if (cookieData) return cookieData;
891
+ set({
892
+ isLoadingConsentInfo: true
893
+ });
894
+ try {
895
+ const { data, error } = await manager.showConsentBanner({
896
+ onError: callbacks.onError ? (context)=>{
897
+ if (callbacks.onError) callbacks.onError(context.error?.message || 'Unknown error');
898
+ } : void 0
899
+ });
900
+ if (error) throw new Error(`Failed to fetch consent banner info: ${error.message}`);
901
+ if (!data) return void set({
902
+ isLoadingConsentInfo: false,
903
+ ...null === consentInfo && hasLocalStorageAccess ? {
904
+ showPopup: true
905
+ } : {}
906
+ });
907
+ updateStoreWithBannerData(data, config, hasLocalStorageAccess);
908
+ return data;
909
+ } catch (error) {
910
+ console.error('Error fetching consent banner information:', error);
911
+ set({
912
+ isLoadingConsentInfo: false
913
+ });
914
+ const errorMessage = error instanceof Error ? error.message : 'Unknown error fetching consent banner information';
915
+ callbacks.onError?.(errorMessage);
916
+ set({
917
+ showPopup: false
918
+ });
919
+ return;
920
+ }
921
+ }
819
922
  const DEFAULT_DOMAIN_CONSENT_MAP = {
820
923
  'www.google-analytics.com': 'measurement',
821
924
  'analytics.google.com': 'measurement',
@@ -1051,27 +1154,19 @@ function createTrackingBlocker(config = {}, initialConsents) {
1051
1154
  };
1052
1155
  }
1053
1156
  const enTranslations = {
1054
- cookieBanner: {
1055
- title: 'We value your privacy',
1056
- description: 'This site uses cookies to improve your browsing experience, analyze site traffic, and show personalized content.',
1157
+ common: {
1057
1158
  acceptAll: 'Accept All',
1058
1159
  rejectAll: 'Reject All',
1059
- customize: 'Customize'
1160
+ customize: 'Customize',
1161
+ save: 'Save Settings'
1162
+ },
1163
+ cookieBanner: {
1164
+ title: 'We value your privacy',
1165
+ description: 'This site uses cookies to improve your browsing experience, analyze site traffic, and show personalized content.'
1060
1166
  },
1061
1167
  consentManagerDialog: {
1062
1168
  title: 'Privacy Settings',
1063
- description: 'Customize your privacy settings here. You can choose which types of cookies and tracking technologies you allow.',
1064
- save: 'Save Settings',
1065
- acceptAll: 'Accept All',
1066
- rejectAll: 'Reject All',
1067
- close: 'Close'
1068
- },
1069
- consentManagerWidget: {
1070
- title: 'Privacy Preferences',
1071
- description: 'Manage your privacy settings',
1072
- save: 'Save Settings',
1073
- acceptAll: 'Accept All',
1074
- rejectAll: 'Reject All'
1169
+ description: 'Customize your privacy settings here. You can choose which types of cookies and tracking technologies you allow.'
1075
1170
  },
1076
1171
  consentTypes: {
1077
1172
  necessary: {
@@ -1323,74 +1418,11 @@ const createConsentManagerStore = (manager, options = {})=>{
1323
1418
  setLocationInfo: (location)=>set({
1324
1419
  locationInfo: location
1325
1420
  }),
1326
- fetchConsentBannerInfo: async ()=>{
1327
- const { callbacks, setDetectedCountry, consentInfo, hasConsented } = get();
1328
- if ('undefined' == typeof window) return;
1329
- if (hasConsented()) return void set({
1330
- isLoadingConsentInfo: false
1331
- });
1332
- let hasLocalStorageAccess = true;
1333
- try {
1334
- if (window.localStorage) {
1335
- window.localStorage.setItem('c15t-storage-test-key', 'test');
1336
- window.localStorage.removeItem('c15t-storage-test-key');
1337
- }
1338
- } catch (error) {
1339
- hasLocalStorageAccess = false;
1340
- console.warn('localStorage not available, skipping consent banner:', error);
1341
- set({
1342
- isLoadingConsentInfo: false,
1343
- showPopup: false
1344
- });
1345
- return;
1346
- }
1347
- set({
1348
- isLoadingConsentInfo: true
1349
- });
1350
- try {
1351
- const { data, error } = await manager.showConsentBanner({
1352
- onError: callbacks.onError
1353
- });
1354
- if (error) throw new Error(`Failed to fetch consent banner info: ${error.message}`);
1355
- if (!data) return void set({
1356
- isLoadingConsentInfo: false,
1357
- ...null === consentInfo && hasLocalStorageAccess ? {
1358
- showPopup: true
1359
- } : {}
1360
- });
1361
- set({
1362
- locationInfo: data.location?.countryCode && data.location?.regionCode ? {
1363
- countryCode: data.location.countryCode,
1364
- regionCode: data.location.regionCode
1365
- } : {
1366
- countryCode: '',
1367
- regionCode: ''
1368
- },
1369
- jurisdictionInfo: data.jurisdiction,
1370
- isLoadingConsentInfo: false,
1371
- ...null === consentInfo ? {
1372
- showPopup: data.showConsentBanner && hasLocalStorageAccess
1373
- } : {}
1374
- });
1375
- if (data.location?.countryCode) setDetectedCountry(data.location.countryCode);
1376
- if (data.location?.countryCode && data.location?.regionCode) callbacks.onLocationDetected?.({
1377
- countryCode: data.location.countryCode,
1378
- regionCode: data.location.regionCode
1379
- });
1380
- return data;
1381
- } catch (error) {
1382
- console.error('Error fetching consent banner information:', error);
1383
- set({
1384
- isLoadingConsentInfo: false
1385
- });
1386
- const errorMessage = error instanceof Error ? error.message : 'Unknown error fetching consent banner information';
1387
- callbacks.onError?.(errorMessage);
1388
- set({
1389
- showPopup: false
1390
- });
1391
- return;
1392
- }
1393
- },
1421
+ fetchConsentBannerInfo: ()=>fetchConsentBannerInfo({
1422
+ manager,
1423
+ get,
1424
+ set
1425
+ }),
1394
1426
  getDisplayedConsents: ()=>{
1395
1427
  const { gdprTypes, consentTypes } = get();
1396
1428
  return consentTypes.filter((consent)=>gdprTypes.includes(consent.name));
@@ -1423,7 +1455,7 @@ function deepMergeTranslations(base, override) {
1423
1455
  const sections = [
1424
1456
  'cookieBanner',
1425
1457
  'consentManagerDialog',
1426
- 'consentManagerWidget',
1458
+ 'common',
1427
1459
  'consentTypes'
1428
1460
  ];
1429
1461
  return sections.reduce((result, section)=>{
@@ -0,0 +1,35 @@
1
+ /**
2
+ * Utility functions for managing cookies
3
+ */
4
+ /**
5
+ * Sets a cookie with the specified name, value and options
6
+ *
7
+ * @param name - The name of the cookie
8
+ * @param value - The value to store in the cookie
9
+ * @param options - Cookie options including expiry, path, etc.
10
+ */
11
+ export declare const setCookie: (name: string, value: string, options?: {
12
+ days?: number;
13
+ path?: string;
14
+ domain?: string;
15
+ secure?: boolean;
16
+ sameSite?: "Strict" | "Lax" | "None";
17
+ }) => void;
18
+ /**
19
+ * Gets a cookie value by name
20
+ *
21
+ * @param name - The name of the cookie to retrieve
22
+ * @returns The cookie value or null if not found
23
+ */
24
+ export declare const getCookie: (name: string) => string | null;
25
+ /**
26
+ * Removes a cookie by name
27
+ *
28
+ * @param name - The name of the cookie to remove
29
+ * @param options - Cookie options for path and domain
30
+ */
31
+ export declare const removeCookie: (name: string, options?: {
32
+ path?: string;
33
+ domain?: string;
34
+ }) => void;
35
+ //# sourceMappingURL=cookie-utils.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cookie-utils.d.ts","sourceRoot":"","sources":["../../src/libs/cookie-utils.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH;;;;;;GAMG;AACH,eAAO,MAAM,SAAS,GACrB,MAAM,MAAM,EACZ,OAAO,MAAM,EACb,UAAS;IACR,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,QAAQ,CAAC,EAAE,QAAQ,GAAG,KAAK,GAAG,MAAM,CAAC;CAChC,SA0BN,CAAC;AAEF;;;;;GAKG;AACH,eAAO,MAAM,SAAS,GAAI,MAAM,MAAM,KAAG,MAAM,GAAG,IAcjD,CAAC;AAEF;;;;;GAKG;AACH,eAAO,MAAM,YAAY,GACxB,MAAM,MAAM,EACZ,UAAS;IAAE,IAAI,CAAC,EAAE,MAAM,CAAC;IAAC,MAAM,CAAC,EAAE,MAAM,CAAA;CAAO,SAMhD,CAAC"}
@@ -0,0 +1,25 @@
1
+ /**
2
+ * @packageDocumentation
3
+ * Handles fetching and processing consent banner information.
4
+ */
5
+ import type { StoreApi } from 'zustand/vanilla';
6
+ import type { ConsentManagerInterface } from '../client/client-factory';
7
+ import type { PrivacyConsentState } from '../store.type';
8
+ import type { ConsentBannerResponse } from '../types/compliance';
9
+ /**
10
+ * Configuration for fetching consent banner information
11
+ */
12
+ interface FetchConsentBannerConfig {
13
+ manager: ConsentManagerInterface;
14
+ get: StoreApi<PrivacyConsentState>['getState'];
15
+ set: StoreApi<PrivacyConsentState>['setState'];
16
+ }
17
+ /**
18
+ * Fetches consent banner information from the API and updates the store.
19
+ *
20
+ * @param config - Configuration object containing store and manager instances
21
+ * @returns A promise that resolves with the consent banner response when the fetch is complete
22
+ */
23
+ export declare function fetchConsentBannerInfo(config: FetchConsentBannerConfig): Promise<ConsentBannerResponse | undefined>;
24
+ export {};
25
+ //# sourceMappingURL=fetch-consent-banner.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"fetch-consent-banner.d.ts","sourceRoot":"","sources":["../../src/libs/fetch-consent-banner.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AAChD,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,0BAA0B,CAAC;AACxE,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,eAAe,CAAC;AACzD,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,qBAAqB,CAAC;AAGjE;;GAEG;AACH,UAAU,wBAAwB;IACjC,OAAO,EAAE,uBAAuB,CAAC;IACjC,GAAG,EAAE,QAAQ,CAAC,mBAAmB,CAAC,CAAC,UAAU,CAAC,CAAC;IAC/C,GAAG,EAAE,QAAQ,CAAC,mBAAmB,CAAC,CAAC,UAAU,CAAC,CAAC;CAC/C;AAsFD;;;;;GAKG;AACH,wBAAsB,sBAAsB,CAC3C,MAAM,EAAE,wBAAwB,GAC9B,OAAO,CAAC,qBAAqB,GAAG,SAAS,CAAC,CA+E5C"}
@@ -1 +1 @@
1
- {"version":3,"file":"store.d.ts","sourceRoot":"","sources":["../src/store.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAIH,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,yBAAyB,CAAC;AAOvE,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,yBAAyB,CAAC;AAErE,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,cAAc,CAAC;AACxD,OAAO,KAAK,EACX,kBAAkB,EAGlB,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAAE,KAAK,eAAe,EAAgB,MAAM,cAAc,CAAC;AAClE,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAC;AAoD9D;;;;;;;;GAQG;AACH,MAAM,WAAW,YAAY;IAC5B;;;OAGG;IACH,SAAS,CAAC,EAAE,MAAM,CAAC;IAEnB;;OAEG;IACH,gBAAgB,CAAC,EAAE,eAAe,EAAE,CAAC;IAErC;;OAEG;IACH,yBAAyB,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,kBAAkB,CAAC,CAAC,CAAC;IAExE;;OAEG;IACH,qBAAqB,CAAC,EAAE,qBAAqB,CAAC;IAE9C;;;OAGG;IACH,eAAe,CAAC,EAAE,OAAO,CAAC;IAE1B;;OAEG;IACH,iBAAiB,CAAC,EAAE,iBAAiB,CAAC;CACtC;AAGD,MAAM,WAAW,WAChB,SAAQ,IAAI,CAAC,YAAY,EAAE,uBAAuB,CAAC;CAAG;AAEvD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAyCG;AACH,eAAO,MAAM,yBAAyB,GACrC,SAAS,uBAAuB,EAChC,UAAS,YAAiB,4DA+gB1B,CAAC"}
1
+ {"version":3,"file":"store.d.ts","sourceRoot":"","sources":["../src/store.ts"],"names":[],"mappings":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"","sources":["../../src/translations/en.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,uBAAuB,CAAC;AAElE,eAAO,MAAM,cAAc,EAAE,oBA4C5B,CAAC"}
@@ -111,6 +111,6 @@ export type { CallbackFunction, Callbacks } from './callbacks';
111
111
  * - Consent manager dialog translations
112
112
  * - Consent manager widget translations
113
113
  */
114
- export type { ConsentManagerDialogTranslations, ConsentManagerWidgetTranslations, ConsentTypeTranslations, ConsentTypesTranslations, CookieBannerTranslations, TranslationConfig, Translations, } from './translations';
114
+ export type { ConsentManagerDialogTranslations, CommonTranslations, ConsentTypeTranslations, ConsentTypesTranslations, CookieBannerTranslations, TranslationConfig, Translations, } from './translations';
115
115
  export * from './compliance';
116
116
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/types/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AACH,YAAY,EACX,gBAAgB,EAChB,kBAAkB,EAClB,qBAAqB,EACrB,YAAY,EACZ,iBAAiB,EACjB,gBAAgB,EAChB,YAAY,EACZ,cAAc,EACd,eAAe,GACf,MAAM,cAAc,CAAC;AAEtB;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,OAAO,EAAE,KAAK,eAAe,EAAE,KAAK,WAAW,EAAE,YAAY,EAAE,MAAM,QAAQ,CAAC;AAE9E;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAqCG;AACH,YAAY,EAAE,gBAAgB,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAE/D;;;;;;;;;;;GAWG;AAEH,YAAY,EACX,gCAAgC,EAChC,gCAAgC,EAChC,uBAAuB,EACvB,wBAAwB,EACxB,wBAAwB,EACxB,iBAAiB,EACjB,YAAY,GACZ,MAAM,gBAAgB,CAAC;AAExB,cAAc,cAAc,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/types/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AACH,YAAY,EACX,gBAAgB,EAChB,kBAAkB,EAClB,qBAAqB,EACrB,YAAY,EACZ,iBAAiB,EACjB,gBAAgB,EAChB,YAAY,EACZ,cAAc,EACd,eAAe,GACf,MAAM,cAAc,CAAC;AAEtB;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,OAAO,EAAE,KAAK,eAAe,EAAE,KAAK,WAAW,EAAE,YAAY,EAAE,MAAM,QAAQ,CAAC;AAE9E;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAqCG;AACH,YAAY,EAAE,gBAAgB,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAE/D;;;;;;;;;;;GAWG;AAEH,YAAY,EACX,gCAAgC,EAChC,kBAAkB,EAClB,uBAAuB,EACvB,wBAAwB,EACxB,wBAAwB,EACxB,iBAAiB,EACjB,YAAY,GACZ,MAAM,gBAAgB,CAAC;AAExB,cAAc,cAAc,CAAC"}
@@ -1,29 +1,21 @@
1
1
  import type { ConsentType } from './gdpr';
2
- export interface CookieBannerTranslations {
3
- title: string;
4
- description: string;
2
+ export interface CommonTranslations {
5
3
  acceptAll: string;
6
4
  rejectAll: string;
7
5
  customize: string;
6
+ save: string;
8
7
  }
9
- export interface ConsentManagerDialogTranslations {
8
+ export interface CookieBannerTranslations {
10
9
  title: string;
11
10
  description: string;
12
- save: string;
13
- acceptAll: string;
14
- rejectAll: string;
15
- close: string;
16
11
  }
17
- export interface ConsentTypeTranslations {
12
+ export interface ConsentManagerDialogTranslations {
18
13
  title: string;
19
14
  description: string;
20
15
  }
21
- export interface ConsentManagerWidgetTranslations {
16
+ export interface ConsentTypeTranslations {
22
17
  title: string;
23
18
  description: string;
24
- save: string;
25
- acceptAll: string;
26
- rejectAll: string;
27
19
  }
28
20
  /**
29
21
  * Maps consent type names to their respective translations.
@@ -33,15 +25,15 @@ export type ConsentTypesTranslations = {
33
25
  [key in ConsentType['name']]: ConsentTypeTranslations;
34
26
  };
35
27
  export interface CompleteTranslations {
28
+ common: CommonTranslations;
36
29
  cookieBanner: CookieBannerTranslations;
37
30
  consentManagerDialog: ConsentManagerDialogTranslations;
38
- consentManagerWidget: ConsentManagerWidgetTranslations;
39
31
  consentTypes: ConsentTypesTranslations;
40
32
  }
41
33
  export interface Translations {
34
+ common: Partial<CommonTranslations>;
42
35
  cookieBanner: Partial<CookieBannerTranslations>;
43
36
  consentManagerDialog: Partial<ConsentManagerDialogTranslations>;
44
- consentManagerWidget: Partial<ConsentManagerWidgetTranslations>;
45
37
  consentTypes: Partial<ConsentTypesTranslations>;
46
38
  }
47
39
  export interface TranslationConfig {