c15t 1.6.0 → 1.7.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 +30 -0
- package/dist/index.cjs +658 -98
- package/dist/index.d.ts +4 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +632 -93
- package/dist/libs/fetch-consent-banner.d.ts +2 -0
- package/dist/libs/fetch-consent-banner.d.ts.map +1 -1
- package/dist/libs/gtm.d.ts +7 -0
- package/dist/libs/gtm.d.ts.map +1 -1
- package/dist/libs/has.d.ts +9 -0
- package/dist/libs/has.d.ts.map +1 -1
- package/dist/libs/iframe-blocker/core.d.ts +90 -0
- package/dist/libs/iframe-blocker/core.d.ts.map +1 -0
- package/dist/libs/iframe-blocker/index.d.ts +3 -0
- package/dist/libs/iframe-blocker/index.d.ts.map +1 -0
- package/dist/libs/iframe-blocker/store.d.ts +35 -0
- package/dist/libs/iframe-blocker/store.d.ts.map +1 -0
- package/dist/libs/iframe-blocker/types.d.ts +26 -0
- package/dist/libs/iframe-blocker/types.d.ts.map +1 -0
- package/dist/libs/save-consents.d.ts +3 -0
- package/dist/libs/save-consents.d.ts.map +1 -1
- package/dist/libs/script-loader/core.d.ts +117 -0
- package/dist/libs/script-loader/core.d.ts.map +1 -0
- package/dist/libs/script-loader/index.d.ts +10 -0
- package/dist/libs/script-loader/index.d.ts.map +1 -0
- package/dist/libs/script-loader/store.d.ts +58 -0
- package/dist/libs/script-loader/store.d.ts.map +1 -0
- package/dist/libs/script-loader/types.d.ts +160 -0
- package/dist/libs/script-loader/types.d.ts.map +1 -0
- package/dist/libs/script-loader/utils.d.ts +56 -0
- package/dist/libs/script-loader/utils.d.ts.map +1 -0
- package/dist/libs/tracking-blocker.d.ts +53 -4
- package/dist/libs/tracking-blocker.d.ts.map +1 -1
- package/dist/store.d.ts +38 -3
- package/dist/store.d.ts.map +1 -1
- package/dist/store.initial-state.d.ts +1 -8
- package/dist/store.initial-state.d.ts.map +1 -1
- package/dist/store.type.d.ts +52 -0
- package/dist/store.type.d.ts.map +1 -1
- package/dist/types/callbacks.d.ts +21 -0
- package/dist/types/callbacks.d.ts.map +1 -1
- package/dist/types/compliance.d.ts +2 -0
- package/dist/types/compliance.d.ts.map +1 -1
- package/dist/types/gdpr.d.ts +23 -0
- package/dist/types/gdpr.d.ts.map +1 -1
- package/dist/types/index.d.ts +1 -29
- package/dist/types/index.d.ts.map +1 -1
- package/dist/version.d.ts +1 -1
- package/package.json +3 -3
|
@@ -7,6 +7,7 @@ import { type TranslationConfig } from '@c15t/translations';
|
|
|
7
7
|
import type { StoreApi } from 'zustand/vanilla';
|
|
8
8
|
import type { ConsentManagerInterface } from '../client/client-factory';
|
|
9
9
|
import type { PrivacyConsentState } from '../store.type';
|
|
10
|
+
import type { createTrackingBlocker } from './tracking-blocker';
|
|
10
11
|
type ConsentBannerResponse = ContractsOutputs['consent']['showBanner'];
|
|
11
12
|
/**
|
|
12
13
|
* Configuration for fetching consent banner information
|
|
@@ -17,6 +18,7 @@ interface FetchConsentBannerConfig {
|
|
|
17
18
|
initialTranslationConfig?: Partial<TranslationConfig>;
|
|
18
19
|
get: StoreApi<PrivacyConsentState>['getState'];
|
|
19
20
|
set: StoreApi<PrivacyConsentState>['setState'];
|
|
21
|
+
trackingBlocker?: ReturnType<typeof createTrackingBlocker> | null;
|
|
20
22
|
}
|
|
21
23
|
/**
|
|
22
24
|
* Fetches consent banner information from the API and updates the store.
|
|
@@ -1 +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,gBAAgB,EAAE,MAAM,yBAAyB,CAAC;AAChE,OAAO,EAEN,KAAK,iBAAiB,EACtB,MAAM,oBAAoB,CAAC;AAC5B,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AAChD,OAAO,KA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gtm.d.ts
CHANGED
|
@@ -11,6 +11,9 @@ interface GTMConsentConfiguration {
|
|
|
11
11
|
functionality_storage: 'granted' | 'denied';
|
|
12
12
|
security_storage: 'granted' | 'denied';
|
|
13
13
|
}
|
|
14
|
+
/**
|
|
15
|
+
* @deprecated use the new script loader instead
|
|
16
|
+
*/
|
|
14
17
|
interface Options {
|
|
15
18
|
/**
|
|
16
19
|
* Your Google Tag Manager container ID. Begins with 'GTM-'.
|
|
@@ -49,6 +52,7 @@ declare global {
|
|
|
49
52
|
* @returns GTM-compatible consent configuration
|
|
50
53
|
*
|
|
51
54
|
* @see {@link CONSENT_STATE_TO_GTM_MAPPING} for the mapping logic
|
|
55
|
+
* @deprecated use the new script loader instead
|
|
52
56
|
*/
|
|
53
57
|
export declare function mapConsentStateToGTM(consentState: ConsentState): GTMConsentConfiguration;
|
|
54
58
|
/**
|
|
@@ -59,6 +63,7 @@ export declare function mapConsentStateToGTM(consentState: ConsentState): GTMCon
|
|
|
59
63
|
* @throws {Error} When GTM container ID is empty or invalid
|
|
60
64
|
*
|
|
61
65
|
* @internal This function should be called before loading the GTM script
|
|
66
|
+
* @deprecated use the new script loader instead
|
|
62
67
|
*/
|
|
63
68
|
export declare function initializeGTMDataLayer(gtm: Options): void;
|
|
64
69
|
/**
|
|
@@ -69,6 +74,7 @@ export declare function initializeGTMDataLayer(gtm: Options): void;
|
|
|
69
74
|
* @throws {Error} When script injection fails
|
|
70
75
|
*
|
|
71
76
|
* @see {@link initializeGTMDataLayer} - Should be called before this function
|
|
77
|
+
* @deprecated use the new script loader instead
|
|
72
78
|
*/
|
|
73
79
|
export declare function createGTMScript(gtm: Options): void;
|
|
74
80
|
/**
|
|
@@ -87,6 +93,7 @@ export declare function setupGTM(gtm: Options): void;
|
|
|
87
93
|
* Updates the Google Tag Manager consent configuration
|
|
88
94
|
*
|
|
89
95
|
* @param consentState - The consent state to update
|
|
96
|
+
* @deprecated use the new script loader instead
|
|
90
97
|
*/
|
|
91
98
|
export declare function updateGTMConsent(consentState: ConsentState): void;
|
|
92
99
|
export {};
|
package/dist/libs/gtm.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"gtm.d.ts","sourceRoot":"","sources":["../../src/libs/gtm.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAmB,YAAY,EAAE,MAAM,UAAU,CAAC;AAE9D;;GAEG;AACH,UAAU,uBAAuB;IAChC,UAAU,EAAE,SAAS,GAAG,QAAQ,CAAC;IACjC,kBAAkB,EAAE,SAAS,GAAG,QAAQ,CAAC;IACzC,YAAY,EAAE,SAAS,GAAG,QAAQ,CAAC;IACnC,iBAAiB,EAAE,SAAS,GAAG,QAAQ,CAAC;IACxC,uBAAuB,EAAE,SAAS,GAAG,QAAQ,CAAC;IAC9C,qBAAqB,EAAE,SAAS,GAAG,QAAQ,CAAC;IAC5C,gBAAgB,EAAE,SAAS,GAAG,QAAQ,CAAC;CACvC;AAED,UAAU,OAAO;IAChB;;OAEG;IACH,EAAE,EAAE,MAAM,CAAC;IACX;;;;;;;;;OASG;IACH,eAAe,CAAC,EAAE,MAAM,CAAC;IAEzB;;OAEG;IACH,YAAY,CAAC,EAAE,YAAY,CAAC;CAC5B;AAED,MAAM,MAAM,gBAAgB,GAAG,IAAI,CAAC,OAAO,EAAE,cAAc,CAAC,CAAC;AAE7D;;GAEG;AACH,OAAO,CAAC,MAAM,CAAC;IACd,UAAU,MAAM;QACf,SAAS,EAAE,OAAO,EAAE,CAAC;QACrB,IAAI,EAAE,CAAC,GAAG,IAAI,EAAE,OAAO,EAAE,KAAK,IAAI,CAAC;KACnC;CACD;AA0BD
|
|
1
|
+
{"version":3,"file":"gtm.d.ts","sourceRoot":"","sources":["../../src/libs/gtm.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAmB,YAAY,EAAE,MAAM,UAAU,CAAC;AAE9D;;GAEG;AACH,UAAU,uBAAuB;IAChC,UAAU,EAAE,SAAS,GAAG,QAAQ,CAA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99
99
|
export declare function has<CategoryType extends AllConsentNames>(condition: HasCondition<CategoryType>, consents: ConsentState): boolean;
|
|
100
|
+
/**
|
|
101
|
+
* Extracts all consent category names from a {@link HasCondition}.
|
|
102
|
+
*
|
|
103
|
+
* @typeParam CategoryType - The type of consent categories
|
|
104
|
+
* @param condition - The condition to extract categories from
|
|
105
|
+
* @returns An array of unique consent category names
|
|
106
|
+
* @public
|
|
107
|
+
*/
|
|
108
|
+
export declare function extractConsentNamesFromCondition<CategoryType extends AllConsentNames>(condition: HasCondition<CategoryType>): CategoryType[];
|
|
100
109
|
//# sourceMappingURL=has.d.ts.map
|
package/dist/libs/has.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"has.d.ts","sourceRoot":"","sources":["../../src/libs/has.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AAE9D;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;AACH,MAAM,MAAM,YAAY,CAAC,YAAY,IAClC,YAAY,GACZ;IAAE,GAAG,EAAE,YAAY,CAAC,YAAY,CAAC,GAAG,YAAY,CAAC,YAAY,CAAC,EAAE,CAAA;CAAE,GAClE;IAAE,EAAE,EAAE,YAAY,CAAC,YAAY,CAAC,GAAG,YAAY,CAAC,YAAY,CAAC,EAAE,CAAA;CAAE,GACjE;IAAE,GAAG,EAAE,YAAY,CAAC,YAAY,CAAC,CAAA;CAAE,CAAC;AAsIvC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA0DG;AACH,wBAAgB,GAAG,CAAC,YAAY,SAAS,eAAe,EACvD,SAAS,EAAE,YAAY,CAAC,YAAY,CAAC,EACrC,QAAQ,EAAE,YAAY,GACpB,OAAO,CAET"}
|
|
1
|
+
{"version":3,"file":"has.d.ts","sourceRoot":"","sources":["../../src/libs/has.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AAE9D;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;AACH,MAAM,MAAM,YAAY,CAAC,YAAY,IAClC,YAAY,GACZ;IAAE,GAAG,EAAE,YAAY,CAAC,YAAY,CAAC,GAAG,YAAY,CAAC,YAAY,CAAC,EAAE,CAAA;CAAE,GAClE;IAAE,EAAE,EAAE,YAAY,CAAC,YAAY,CAAC,GAAG,YAAY,CAAC,YAAY,CAAC,EAAE,CAAA;CAAE,GACjE;IAAE,GAAG,EAAE,YAAY,CAAC,YAAY,CAAC,CAAA;CAAE,CAAC;AAsIvC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA0DG;AACH,wBAAgB,GAAG,CAAC,YAAY,SAAS,eAAe,EACvD,SAAS,EAAE,YAAY,CAAC,YAAY,CAAC,EACrC,QAAQ,EAAE,YAAY,GACpB,OAAO,CAET;AAED;;;;;;;GAOG;AACH,wBAAgB,gCAAgC,CAC/C,YAAY,SAAS,eAAe,EACnC,SAAS,EAAE,YAAY,CAAC,YAAY,CAAC,GAAG,YAAY,EAAE,CAwBvD"}
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @packageDocumentation
|
|
3
|
+
* Implements automatic blocking of iframes until user consent is granted.
|
|
4
|
+
*
|
|
5
|
+
* This module processes existing iframe elements on the page and manages their loading
|
|
6
|
+
* based on consent settings. It supports both lazy loading (data-src) and immediate
|
|
7
|
+
* loading (src) patterns.
|
|
8
|
+
*
|
|
9
|
+
* The iframe blocker only checks for the `category` data attribute on iframe elements.
|
|
10
|
+
* Iframes without a category attribute are always allowed to load.
|
|
11
|
+
*
|
|
12
|
+
* This is a headless implementation that does not render any DOM elements.
|
|
13
|
+
* It only manages the src/data-src attributes of existing iframe elements.
|
|
14
|
+
*/
|
|
15
|
+
import type { AllConsentNames, ConsentState } from '../../types';
|
|
16
|
+
import type { IframeBlocker, IframeBlockerConfig } from './types';
|
|
17
|
+
/**
|
|
18
|
+
* Creates an iframe blocker instance that handles blocking of iframes based on consent
|
|
19
|
+
*
|
|
20
|
+
* @param config - Configuration options for the iframe blocker
|
|
21
|
+
* @param initialConsents - Initial consent state (optional)
|
|
22
|
+
* @returns Iframe blocker instance with management methods
|
|
23
|
+
*
|
|
24
|
+
* @example
|
|
25
|
+
* ```ts
|
|
26
|
+
* const blocker = createIframeBlocker({
|
|
27
|
+
* disableAutomaticBlocking: false
|
|
28
|
+
* });
|
|
29
|
+
*
|
|
30
|
+
* // Update consents
|
|
31
|
+
* blocker.updateConsents({ marketing: true });
|
|
32
|
+
*
|
|
33
|
+
* // Clean up
|
|
34
|
+
* blocker.destroy();
|
|
35
|
+
* ```
|
|
36
|
+
*/
|
|
37
|
+
export declare function createIframeBlocker(config?: IframeBlockerConfig, initialConsents?: ConsentState): IframeBlocker;
|
|
38
|
+
/**
|
|
39
|
+
* Extracts consent categories from all iframes with data-category attributes on the page.
|
|
40
|
+
* Returns an array of unique category names found in iframes.
|
|
41
|
+
*
|
|
42
|
+
* @returns Array of consent category names found in iframes
|
|
43
|
+
*
|
|
44
|
+
* @example
|
|
45
|
+
* ```typescript
|
|
46
|
+
* // <iframe data-category="marketing" />
|
|
47
|
+
* // <iframe data-category="measurement" />
|
|
48
|
+
* const categories = getIframeConsentCategories();
|
|
49
|
+
* // Returns: ['marketing', 'measurement']
|
|
50
|
+
* ```
|
|
51
|
+
*/
|
|
52
|
+
export declare function getIframeConsentCategories(): AllConsentNames[];
|
|
53
|
+
/**
|
|
54
|
+
* Processes all iframes on the page based on current consent state.
|
|
55
|
+
* This is a pure function following the script loader pattern.
|
|
56
|
+
*
|
|
57
|
+
* @param consents - Current consent state
|
|
58
|
+
*
|
|
59
|
+
* @example
|
|
60
|
+
* ```typescript
|
|
61
|
+
* // Process all iframes with current consents
|
|
62
|
+
* processAllIframes({ marketing: true, necessary: true });
|
|
63
|
+
*
|
|
64
|
+
* // After consent changes, process again
|
|
65
|
+
* processAllIframes({ marketing: false, necessary: true });
|
|
66
|
+
* ```
|
|
67
|
+
*/
|
|
68
|
+
export declare function processAllIframes(consents: ConsentState): void;
|
|
69
|
+
/**
|
|
70
|
+
* Creates and starts a MutationObserver to watch for dynamically added iframes.
|
|
71
|
+
* The observer will automatically process new iframes based on the provided consent getter.
|
|
72
|
+
* It also triggers category discovery when new iframes with data-category are added.
|
|
73
|
+
*
|
|
74
|
+
* @param getConsents - Function to get current consent state
|
|
75
|
+
* @param onCategoriesDiscovered - Optional callback when new categories are discovered
|
|
76
|
+
* @returns The active MutationObserver instance
|
|
77
|
+
*
|
|
78
|
+
* @example
|
|
79
|
+
* ```typescript
|
|
80
|
+
* const observer = setupIframeObserver(
|
|
81
|
+
* () => store.getState().consents,
|
|
82
|
+
* (categories) => store.getState().updateConsentCategories(categories)
|
|
83
|
+
* );
|
|
84
|
+
*
|
|
85
|
+
* // Later, clean up
|
|
86
|
+
* observer.disconnect();
|
|
87
|
+
* ```
|
|
88
|
+
*/
|
|
89
|
+
export declare function setupIframeObserver(getConsents: () => ConsentState, onCategoriesDiscovered?: (categories: AllConsentNames[]) => void): MutationObserver;
|
|
90
|
+
//# sourceMappingURL=core.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"core.d.ts","sourceRoot":"","sources":["../../../src/libs/iframe-blocker/core.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAEH,OAAO,KAAK,EAAE,eAAe,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAGjE,OAAO,KAAK,EAAE,aAAa,EAAE,mBAAmB,EAAE,MAAM,SAAS,CAAC;AA+ElE;;;;;;;;;;;;;;;;;;;GAmBG;AACH,wBAAgB,mBAAmB,CAClC,MAAM,GAAE,mBAAwB,EAChC,eAAe,CAAC,EAAE,YAAY,GAC5B,aAAa,CAgFf;AAED;;;;;;;;;;;;;GAaG;AACH,wBAAgB,0BAA0B,IAAI,eAAe,EAAE,CA0B9D;AAED;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,iBAAiB,CAAC,QAAQ,EAAE,YAAY,GAAG,IAAI,CAU9D;AAED;;;;;;;;;;;;;;;;;;;GAmBG;AACH,wBAAgB,mBAAmB,CAClC,WAAW,EAAE,MAAM,YAAY,EAC/B,sBAAsB,CAAC,EAAE,CAAC,UAAU,EAAE,eAAe,EAAE,KAAK,IAAI,GAC9D,gBAAgB,CAiDlB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/libs/iframe-blocker/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACN,mBAAmB,EACnB,0BAA0B,EAC1B,iBAAiB,EACjB,mBAAmB,GACnB,MAAM,QAAQ,CAAC;AAChB,YAAY,EAAE,aAAa,EAAE,mBAAmB,EAAE,MAAM,SAAS,CAAC"}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import type { PrivacyConsentState } from '../../store.type';
|
|
2
|
+
/**
|
|
3
|
+
* Creates an iframe manager that integrates with the main consent store.
|
|
4
|
+
* Follows the script loader pattern with pure functions and state management.
|
|
5
|
+
*
|
|
6
|
+
* @param get - The store's `getState` method
|
|
7
|
+
* @param set - The store's `setState` method
|
|
8
|
+
* @returns An object with iframe management methods to be spread into the store
|
|
9
|
+
*
|
|
10
|
+
* @internal
|
|
11
|
+
*/
|
|
12
|
+
export declare function createIframeManager(get: () => PrivacyConsentState, _set: (partial: Partial<PrivacyConsentState>) => void): {
|
|
13
|
+
/**
|
|
14
|
+
* Initializes the iframe blocker and starts monitoring iframes.
|
|
15
|
+
* Processes existing iframes, sets up observer, and discovers consent categories.
|
|
16
|
+
*
|
|
17
|
+
* @throws {Error} When called in a non-browser environment (document is undefined)
|
|
18
|
+
*/
|
|
19
|
+
initializeIframeBlocker: () => void;
|
|
20
|
+
/**
|
|
21
|
+
* Updates iframe consent state and reprocesses all iframes.
|
|
22
|
+
* Pure function approach - just calls processAllIframes with current consents.
|
|
23
|
+
*
|
|
24
|
+
* @throws {Error} When called in a non-browser environment (document is undefined)
|
|
25
|
+
*/
|
|
26
|
+
updateIframeConsents: () => void;
|
|
27
|
+
/**
|
|
28
|
+
* Destroys the iframe blocker and cleans up the observer.
|
|
29
|
+
* Resets the active state in the store.
|
|
30
|
+
*
|
|
31
|
+
* @throws {Error} When called in a non-browser environment (document is undefined)
|
|
32
|
+
*/
|
|
33
|
+
destroyIframeBlocker: () => void;
|
|
34
|
+
};
|
|
35
|
+
//# sourceMappingURL=store.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"store.d.ts","sourceRoot":"","sources":["../../../src/libs/iframe-blocker/store.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,kBAAkB,CAAC;AAO5D;;;;;;;;;GASG;AACH,wBAAgB,mBAAmB,CAClC,GAAG,EAAE,MAAM,mBAAmB,EAC9B,IAAI,EAAE,CAAC,OAAO,EAAE,OAAO,CAAC,mBAAmB,CAAC,KAAK,IAAI;IAQpD;;;;;OAKG;;IAsDH;;;;;OAKG;;IAsBH;;;;;OAKG;;EA4BJ"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import type { ConsentState } from '../../types';
|
|
2
|
+
/**
|
|
3
|
+
* Configuration for iframe blocking behavior
|
|
4
|
+
*/
|
|
5
|
+
export interface IframeBlockerConfig {
|
|
6
|
+
/** Whether to disable automatic iframe blocking (defaults to false) */
|
|
7
|
+
disableAutomaticBlocking?: boolean;
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* Interface for the iframe blocker instance
|
|
11
|
+
*/
|
|
12
|
+
export interface IframeBlocker {
|
|
13
|
+
/**
|
|
14
|
+
* Updates the consents and processes iframes accordingly
|
|
15
|
+
*/
|
|
16
|
+
updateConsents: (newConsents: Partial<ConsentState>) => void;
|
|
17
|
+
/**
|
|
18
|
+
* Processes all iframes on the page based on current consent state
|
|
19
|
+
*/
|
|
20
|
+
processIframes: () => void;
|
|
21
|
+
/**
|
|
22
|
+
* Destroys the iframe blocker and restores original behavior
|
|
23
|
+
*/
|
|
24
|
+
destroy: () => void;
|
|
25
|
+
}
|
|
26
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/libs/iframe-blocker/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAEhD;;GAEG;AACH,MAAM,WAAW,mBAAmB;IACnC,uEAAuE;IACvE,wBAAwB,CAAC,EAAE,OAAO,CAAC;CACnC;AAED;;GAEG;AACH,MAAM,WAAW,aAAa;IAC7B;;OAEG;IACH,cAAc,EAAE,CAAC,WAAW,EAAE,OAAO,CAAC,YAAY,CAAC,KAAK,IAAI,CAAC;IAE7D;;OAEG;IACH,cAAc,EAAE,MAAM,IAAI,CAAC;IAE3B;;OAEG;IACH,OAAO,EAAE,MAAM,IAAI,CAAC;CACpB"}
|
|
@@ -7,6 +7,9 @@ interface SaveConsentsProps {
|
|
|
7
7
|
type: 'necessary' | 'all' | 'custom';
|
|
8
8
|
get: StoreApi<PrivacyConsentState>['getState'];
|
|
9
9
|
set: StoreApi<PrivacyConsentState>['setState'];
|
|
10
|
+
/**
|
|
11
|
+
* @deprecated This method is deprecated and will be removed in the next major version. Use the new script loader instead.
|
|
12
|
+
*/
|
|
10
13
|
trackingBlocker: ReturnType<typeof createTrackingBlocker> | null;
|
|
11
14
|
}
|
|
12
15
|
export declare function saveConsents({ manager, type, get, set, trackingBlocker, }: SaveConsentsProps): Promise<void>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"save-consents.d.ts","sourceRoot":"","sources":["../../src/libs/save-consents.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAA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AC,OAAO,qBAAqB,CAAC,GAAG,IAAI,CAAC;CACjE;AAED,wBAAsB,YAAY,CAAC,EAClC,OAAO,EACP,IAAI,EACJ,GAAG,EACH,GAAG,EACH,eAAe,GACf,EAAE,iBAAiB,iBAyFnB"}
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
import type { ConsentState } from '../../types/compliance';
|
|
2
|
+
import type { Script, ScriptUpdateResult } from './types';
|
|
3
|
+
/**
|
|
4
|
+
* Loads scripts based on user consent settings.
|
|
5
|
+
*
|
|
6
|
+
* @param scripts - Array of script configurations to potentially load
|
|
7
|
+
* @param consents - Current user consent state
|
|
8
|
+
* @param scriptIdMap - Map of anonymized script IDs to original IDs
|
|
9
|
+
* @returns Array of script IDs that were loaded
|
|
10
|
+
*
|
|
11
|
+
* @throws {Error} When a script with the same ID is already loaded
|
|
12
|
+
*
|
|
13
|
+
* @remarks
|
|
14
|
+
* The loading process follows these steps:
|
|
15
|
+
* 1. Check if the script has consent to load (skipped if alwaysLoad is true)
|
|
16
|
+
* 2. Check if the script is already loaded
|
|
17
|
+
* 3. Create the script element with all specified attributes
|
|
18
|
+
* 4. Apply ID anonymization if enabled (default behavior)
|
|
19
|
+
* 5. Execute the `onBeforeLoad` callback if provided
|
|
20
|
+
* 6. Add the script to the document
|
|
21
|
+
* 7. Track the loaded script
|
|
22
|
+
*
|
|
23
|
+
* Scripts with `alwaysLoad: true` will bypass consent checks and load immediately.
|
|
24
|
+
* This is useful for scripts like Google Tag Manager that manage their own consent.
|
|
25
|
+
*
|
|
26
|
+
* When anonymizeId is enabled (default), script elements will use randomly generated IDs
|
|
27
|
+
* instead of the original script IDs prefixed with 'c15t-script-'.
|
|
28
|
+
*
|
|
29
|
+
* @public
|
|
30
|
+
*/
|
|
31
|
+
export declare function loadScripts(scripts: Script[], consents: ConsentState, scriptIdMap?: Record<string, string>): string[];
|
|
32
|
+
/**
|
|
33
|
+
* Unloads scripts that no longer have consent.
|
|
34
|
+
*
|
|
35
|
+
* @param scripts - Array of script configurations to check
|
|
36
|
+
* @param consents - Current user consent state
|
|
37
|
+
* @param scriptIdMap - Map of anonymized script IDs to original IDs
|
|
38
|
+
* @returns Array of script IDs that were unloaded
|
|
39
|
+
*
|
|
40
|
+
* @remarks
|
|
41
|
+
* The unloading process follows these steps:
|
|
42
|
+
* 1. Check if the script is loaded
|
|
43
|
+
* 2. Skip if script has alwaysLoad enabled (these scripts are never unloaded)
|
|
44
|
+
* 3. Check if the script no longer has consent
|
|
45
|
+
* 4. Execute the `onDelete` callback if provided
|
|
46
|
+
* 5. Remove the script from the document
|
|
47
|
+
* 6. Remove the script from tracking
|
|
48
|
+
*
|
|
49
|
+
* Scripts with `alwaysLoad: true` will never be unloaded, even if consent is revoked.
|
|
50
|
+
*
|
|
51
|
+
* @public
|
|
52
|
+
*/
|
|
53
|
+
export declare function unloadScripts(scripts: Script[], consents: ConsentState, scriptIdMap?: Record<string, string>): string[];
|
|
54
|
+
/**
|
|
55
|
+
* Updates scripts based on current consent state, loading new scripts and unloading revoked ones.
|
|
56
|
+
*
|
|
57
|
+
* @param scripts - Array of script configurations to manage
|
|
58
|
+
* @param consents - Current user consent state
|
|
59
|
+
* @param scriptIdMap - Map of anonymized script IDs to original IDs
|
|
60
|
+
* @returns Object containing arrays of loaded and unloaded script IDs
|
|
61
|
+
*
|
|
62
|
+
* @remarks
|
|
63
|
+
* When anonymizeId is enabled (default), script elements will use randomly generated IDs
|
|
64
|
+
* instead of the original script IDs prefixed with 'c15t-script-'.
|
|
65
|
+
*
|
|
66
|
+
* @public
|
|
67
|
+
*/
|
|
68
|
+
export declare function updateScripts(scripts: Script[], consents: ConsentState, scriptIdMap?: Record<string, string>): ScriptUpdateResult;
|
|
69
|
+
/**
|
|
70
|
+
* Checks if a script is currently loaded.
|
|
71
|
+
*
|
|
72
|
+
* @param scriptId - ID of the script to check
|
|
73
|
+
* @returns True if the script is loaded, false otherwise
|
|
74
|
+
*
|
|
75
|
+
* @public
|
|
76
|
+
*/
|
|
77
|
+
export declare function isScriptLoaded(scriptId: string): boolean;
|
|
78
|
+
/**
|
|
79
|
+
* Gets all currently loaded script IDs.
|
|
80
|
+
*
|
|
81
|
+
* @returns Array of loaded script IDs
|
|
82
|
+
*
|
|
83
|
+
* @public
|
|
84
|
+
*/
|
|
85
|
+
export declare function getLoadedScriptIds(): string[];
|
|
86
|
+
/**
|
|
87
|
+
* Removes all loaded scripts from the DOM and clears the tracking.
|
|
88
|
+
*
|
|
89
|
+
* @param scripts - Optional array of script configurations to check for onDelete callbacks
|
|
90
|
+
* @param consents - Optional consent state to pass to onDelete callbacks
|
|
91
|
+
* @param scriptIdMap - Map of anonymized script IDs to original IDs
|
|
92
|
+
* @returns Array of script IDs that were unloaded
|
|
93
|
+
*
|
|
94
|
+
* @remarks
|
|
95
|
+
* If the scripts parameter is provided, the function will call the onDelete callback
|
|
96
|
+
* for each script that is being removed. If consents is also provided, it will be passed
|
|
97
|
+
* to the onDelete callbacks.
|
|
98
|
+
*
|
|
99
|
+
* Scripts with `alwaysLoad: true` will be skipped and remain loaded.
|
|
100
|
+
*
|
|
101
|
+
* @public
|
|
102
|
+
*/
|
|
103
|
+
export declare function clearAllScripts(scripts?: Script[], consents?: ConsentState, scriptIdMap?: Record<string, string>): string[];
|
|
104
|
+
/**
|
|
105
|
+
* Reloads a script by first removing it and then loading it again.
|
|
106
|
+
* Useful for updating scripts to newer versions.
|
|
107
|
+
*
|
|
108
|
+
* @param scriptId - ID of the script to reload
|
|
109
|
+
* @param scripts - Array of script configurations
|
|
110
|
+
* @param consents - Current user consent state
|
|
111
|
+
* @param scriptIdMap - Map of anonymized script IDs to original IDs
|
|
112
|
+
* @returns True if the script was reloaded, false otherwise
|
|
113
|
+
*
|
|
114
|
+
* @public
|
|
115
|
+
*/
|
|
116
|
+
export declare function reloadScript(scriptId: string, scripts: Script[], consents: ConsentState, scriptIdMap?: Record<string, string>): boolean;
|
|
117
|
+
//# sourceMappingURL=core.d.ts.map
|
|
@@ -0,0 +1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,QAAQ,EAAE,YAAY,EACtB,WAAW,GAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAM,GACtC,OAAO,CAgET"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Script loader module for managing scripts based on user consent.
|
|
3
|
+
*
|
|
4
|
+
* @packageDocumentation
|
|
5
|
+
*/
|
|
6
|
+
export { clearAllScripts, getLoadedScriptIds, isScriptLoaded, loadScripts, reloadScript, unloadScripts, updateScripts, } from './core';
|
|
7
|
+
export { createScriptManager } from './store';
|
|
8
|
+
export type { Script, ScriptCallbackInfo, ScriptUpdateResult } from './types';
|
|
9
|
+
export { generateRandomScriptId } from './utils';
|
|
10
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/libs/script-loader/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EACN,eAAe,EACf,kBAAkB,EAClB,cAAc,EACd,WAAW,EACX,YAAY,EACZ,aAAa,EACb,aAAa,GACb,MAAM,QAAQ,CAAC;AAEhB,OAAO,EAAE,mBAAmB,EAAE,MAAM,SAAS,CAAC;AAE9C,YAAY,EAAE,MAAM,EAAE,kBAAkB,EAAE,kBAAkB,EAAE,MAAM,SAAS,CAAC;AAE9E,OAAO,EAAE,sBAAsB,EAAE,MAAM,SAAS,CAAC"}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import type { PrivacyConsentState } from '../../store.type';
|
|
2
|
+
import type { createTrackingBlocker } from '../tracking-blocker';
|
|
3
|
+
import type { Script } from './types';
|
|
4
|
+
/**
|
|
5
|
+
* Creates script management functions for the consent manager store.
|
|
6
|
+
*
|
|
7
|
+
* @param getState - Function to get the current state from the store
|
|
8
|
+
* @param setState - Function to update the state in the store
|
|
9
|
+
* @param trackingBlocker - Optional tracking blocker instance to destroy when scripts are added
|
|
10
|
+
* @returns Object containing script management functions
|
|
11
|
+
* @internal
|
|
12
|
+
*/
|
|
13
|
+
export declare function createScriptManager(getState: () => PrivacyConsentState, setState: (partial: Partial<PrivacyConsentState>) => void, trackingBlocker?: ReturnType<typeof createTrackingBlocker> | null): {
|
|
14
|
+
/**
|
|
15
|
+
* Updates scripts based on current consent state.
|
|
16
|
+
* Loads scripts that have consent and aren't loaded yet.
|
|
17
|
+
* Unloads scripts that no longer have consent.
|
|
18
|
+
* @returns Object containing arrays of loaded and unloaded script IDs
|
|
19
|
+
*/
|
|
20
|
+
updateScripts: () => import("./types").ScriptUpdateResult;
|
|
21
|
+
/**
|
|
22
|
+
* Adds multiple script configurations to the store.
|
|
23
|
+
*
|
|
24
|
+
* @param scripts - Array of script configurations to add
|
|
25
|
+
*
|
|
26
|
+
* @remarks
|
|
27
|
+
* When scripts are added, the tracking blocker is automatically destroyed
|
|
28
|
+
* to prevent conflicts between the two systems.
|
|
29
|
+
*/
|
|
30
|
+
setScripts: (scripts: Script[]) => void;
|
|
31
|
+
/**
|
|
32
|
+
* Removes a script configuration from the store.
|
|
33
|
+
*
|
|
34
|
+
* @param scriptId - ID of the script to remove
|
|
35
|
+
*/
|
|
36
|
+
removeScript: (scriptId: string) => void;
|
|
37
|
+
/**
|
|
38
|
+
* Reloads a specific script.
|
|
39
|
+
*
|
|
40
|
+
* @param scriptId - ID of the script to reload
|
|
41
|
+
* @returns True if the script was reloaded, false otherwise
|
|
42
|
+
*/
|
|
43
|
+
reloadScript: (scriptId: string) => boolean;
|
|
44
|
+
/**
|
|
45
|
+
* Checks if a script is currently loaded.
|
|
46
|
+
*
|
|
47
|
+
* @param scriptId - ID of the script to check
|
|
48
|
+
* @returns True if the script is loaded, false otherwise
|
|
49
|
+
*/
|
|
50
|
+
isScriptLoaded: (scriptId: string) => boolean;
|
|
51
|
+
/**
|
|
52
|
+
* Gets all currently loaded script IDs.
|
|
53
|
+
*
|
|
54
|
+
* @returns Array of loaded script IDs
|
|
55
|
+
*/
|
|
56
|
+
getLoadedScriptIds: () => string[];
|
|
57
|
+
};
|
|
58
|
+
//# sourceMappingURL=store.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"store.d.ts","sourceRoot":"","sources":["../../../src/libs/script-loader/store.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,kBAAkB,CAAC;AAE5D,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,qBAAqB,CAAC;AAOjE,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,SAAS,CAAC;AAQtC;;;;;;;;GAQG;AACH,wBAAgB,mBAAmB,CAClC,QAAQ,EAAE,MAAM,mBAAmB,EACnC,QAAQ,EAAE,CAAC,OAAO,EAAE,OAAO,CAAC,mBAAmB,CAAC,KAAK,IAAI,EACzD,eAAe,CAAC,EAAE,UAAU,CAAC,OAAO,qBAAqB,CAAC,GAAG,IAAI;IAyBhE;;;;;OAKG;;IAGH;;;;;;;;OAQG;0BACmB,MAAM,EAAE;IAkC9B;;;;OAIG;6BACsB,MAAM;IAgD/B;;;;;OAKG;6BACsB,MAAM;IAU/B;;;;;OAKG;+BACwB,MAAM;IAIjC;;;;OAIG;;EAKJ"}
|
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
import type { ConsentState } from '../../types/compliance';
|
|
2
|
+
import type { AllConsentNames } from '../../types/gdpr';
|
|
3
|
+
import type { HasCondition } from '../has';
|
|
4
|
+
/**
|
|
5
|
+
* Information passed to script callbacks
|
|
6
|
+
*
|
|
7
|
+
* @public
|
|
8
|
+
*/
|
|
9
|
+
export interface ScriptCallbackInfo {
|
|
10
|
+
/** The original script ID */
|
|
11
|
+
id: string;
|
|
12
|
+
/** The actual DOM element ID used (anonymized if enabled) */
|
|
13
|
+
elementId: string;
|
|
14
|
+
/** Has consent */
|
|
15
|
+
hasConsent: boolean;
|
|
16
|
+
/** The current consent state */
|
|
17
|
+
consents: ConsentState;
|
|
18
|
+
/**
|
|
19
|
+
* The script element (for load/error callbacks)
|
|
20
|
+
* Will be undefined for callback-only scripts
|
|
21
|
+
*/
|
|
22
|
+
element?: HTMLScriptElement;
|
|
23
|
+
/** Error information (for error callbacks) */
|
|
24
|
+
error?: Error;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Represents a script to be loaded based on consent conditions.
|
|
28
|
+
*
|
|
29
|
+
* Scripts can be one of three types:
|
|
30
|
+
* 1. Standard scripts - These load an external JavaScript file via a script tag
|
|
31
|
+
* 2. Text-based scripts - These contain inline JavaScript code that gets executed directly
|
|
32
|
+
* 3. Callback-only scripts - These don't add a script tag to the DOM but still execute callbacks
|
|
33
|
+
* based on consent state changes (useful for controlling existing libraries)
|
|
34
|
+
*
|
|
35
|
+
* @public
|
|
36
|
+
*/
|
|
37
|
+
export interface Script {
|
|
38
|
+
/** Unique identifier for the script */
|
|
39
|
+
id: string;
|
|
40
|
+
/** URL of the script to load */
|
|
41
|
+
src?: string;
|
|
42
|
+
/** Inline JavaScript code to execute */
|
|
43
|
+
textContent?: string;
|
|
44
|
+
/** Consent category or condition required to load this script */
|
|
45
|
+
category: HasCondition<AllConsentNames>;
|
|
46
|
+
/**
|
|
47
|
+
* Whether this is a callback-only script that doesn't need to load an external resource.
|
|
48
|
+
* When true, no script tag will be added to the DOM, only callbacks will be executed.
|
|
49
|
+
*
|
|
50
|
+
* This is useful for:
|
|
51
|
+
* - Managing consent for libraries already loaded on the page
|
|
52
|
+
* - Enabling/disabling tracking features based on consent changes
|
|
53
|
+
* - Running custom code when consent status changes without loading external scripts
|
|
54
|
+
*
|
|
55
|
+
* Example use cases:
|
|
56
|
+
* - Enabling/disabling Posthog tracking
|
|
57
|
+
* - Configuring Google Analytics consent mode
|
|
58
|
+
* - Managing cookie consent for embedded content
|
|
59
|
+
*
|
|
60
|
+
* @default false
|
|
61
|
+
*/
|
|
62
|
+
callbackOnly?: boolean;
|
|
63
|
+
/**
|
|
64
|
+
* Whether the script should persist after consent is revoked.
|
|
65
|
+
* @default false
|
|
66
|
+
*/
|
|
67
|
+
persistAfterConsentRevoked?: boolean;
|
|
68
|
+
/**
|
|
69
|
+
* Whether the script should always load regardless of consent state.
|
|
70
|
+
*
|
|
71
|
+
* This is useful for scripts like Google Tag Manager or PostHog that manage
|
|
72
|
+
* their own consent state internally. The script will load immediately and
|
|
73
|
+
* never be unloaded based on consent changes.
|
|
74
|
+
*
|
|
75
|
+
* Note: When using this option, you are responsible for ensuring the script
|
|
76
|
+
* itself respects user consent preferences through its own consent management.
|
|
77
|
+
*
|
|
78
|
+
* @default false
|
|
79
|
+
*
|
|
80
|
+
* @example
|
|
81
|
+
* ```ts
|
|
82
|
+
* const gtmScript: Script = {
|
|
83
|
+
* id: 'google-tag-manager',
|
|
84
|
+
* src: 'https://www.googletagmanager.com/gtm.js?id=GTM-XXXX',
|
|
85
|
+
* category: 'measurement', // Category is still required but won't gate loading
|
|
86
|
+
* alwaysLoad: true, // GTM will always load and manage its own consent
|
|
87
|
+
* };
|
|
88
|
+
* ```
|
|
89
|
+
*/
|
|
90
|
+
alwaysLoad?: boolean;
|
|
91
|
+
/** Priority hint for browser resource loading */
|
|
92
|
+
fetchPriority?: 'high' | 'low' | 'auto';
|
|
93
|
+
/** Additional attributes to add to the script element */
|
|
94
|
+
attributes?: Record<string, string>;
|
|
95
|
+
/** Whether to use async loading */
|
|
96
|
+
async?: boolean;
|
|
97
|
+
/** Whether to defer script loading */
|
|
98
|
+
defer?: boolean;
|
|
99
|
+
/** Content Security Policy nonce */
|
|
100
|
+
nonce?: string;
|
|
101
|
+
/**
|
|
102
|
+
* Whether to use an anonymized ID for the script element, this helps ensure the script is not blocked by ad blockers
|
|
103
|
+
* @default true
|
|
104
|
+
*/
|
|
105
|
+
anonymizeId?: boolean;
|
|
106
|
+
/**
|
|
107
|
+
* Callback executed before the script is loaded
|
|
108
|
+
* @param info - Information about the script and current consent state
|
|
109
|
+
*/
|
|
110
|
+
onBeforeLoad?: (info: ScriptCallbackInfo) => void;
|
|
111
|
+
/**
|
|
112
|
+
* Callback executed when the script loads successfully
|
|
113
|
+
* @param info - Information about the script and current consent state
|
|
114
|
+
*/
|
|
115
|
+
onLoad?: (info: ScriptCallbackInfo) => void;
|
|
116
|
+
/**
|
|
117
|
+
* Callback executed when the script is being unloaded/removed
|
|
118
|
+
* @param info - Information about the script and current consent state
|
|
119
|
+
*/
|
|
120
|
+
onDelete?: (info: ScriptCallbackInfo) => void;
|
|
121
|
+
/**
|
|
122
|
+
* Callback executed if the script fails to load
|
|
123
|
+
* @param info - Information about the script, error, and current consent state
|
|
124
|
+
*/
|
|
125
|
+
onError?: (info: ScriptCallbackInfo) => void;
|
|
126
|
+
/**
|
|
127
|
+
* Callback executed whenever the consent store is changed.
|
|
128
|
+
* This callback only applies to scripts already loaded.
|
|
129
|
+
*
|
|
130
|
+
* @param info - Information about the script and current consent state
|
|
131
|
+
*
|
|
132
|
+
* @example
|
|
133
|
+
* ```ts
|
|
134
|
+
* const script: Script = {
|
|
135
|
+
* id: 'analytics',
|
|
136
|
+
* src: 'https://analytics.example.com/script.js',
|
|
137
|
+
* category: 'analytics',
|
|
138
|
+
* onConsentChange: ({ consents }) => {
|
|
139
|
+
* // React to consent changes
|
|
140
|
+
* if (consents.analytics) {
|
|
141
|
+
* console.log('Analytics consent granted');
|
|
142
|
+
* }
|
|
143
|
+
* }
|
|
144
|
+
* };
|
|
145
|
+
* ```
|
|
146
|
+
*/
|
|
147
|
+
onConsentChange?: (info: ScriptCallbackInfo) => void;
|
|
148
|
+
}
|
|
149
|
+
/**
|
|
150
|
+
* Result of updating scripts
|
|
151
|
+
*
|
|
152
|
+
* @public
|
|
153
|
+
*/
|
|
154
|
+
export interface ScriptUpdateResult {
|
|
155
|
+
/** Array of script IDs that were loaded */
|
|
156
|
+
loaded: string[];
|
|
157
|
+
/** Array of script IDs that were unloaded */
|
|
158
|
+
unloaded: string[];
|
|
159
|
+
}
|
|
160
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @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