@blotoutio/providers-blotout-consent-sdk 1.45.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/package.json ADDED
@@ -0,0 +1,41 @@
1
+ {
2
+ "name": "@blotoutio/providers-blotout-consent-sdk",
3
+ "version": "1.45.0",
4
+ "description": "Blotout Consent Banner SDK for EdgeTag",
5
+ "author": "Blotout",
6
+ "license": "MIT",
7
+ "homepage": "https://github.com/blotoutio/edgetag-sdk",
8
+ "publishConfig": {
9
+ "access": "public"
10
+ },
11
+ "main": "./index.cjs.js",
12
+ "module": "./index.mjs",
13
+ "types": "./index.d.ts",
14
+ "exports": {
15
+ ".": {
16
+ "require": "./index.cjs.js",
17
+ "import": "./index.mjs",
18
+ "default": "./index.js"
19
+ },
20
+ "./stores/shopify/index.js": {
21
+ "require": "./stores/shopify/index.cjs.js",
22
+ "import": "./stores/shopify/index.mjs",
23
+ "default": "./stores/shopify/index.js"
24
+ }
25
+ },
26
+ "repository": {
27
+ "type": "git",
28
+ "url": "git+https://github.com/blotoutio/edgetag-sdk.git"
29
+ },
30
+ "files": [
31
+ "package.json",
32
+ "README.md",
33
+ "index.js",
34
+ "index.cjs.js",
35
+ "index.mjs",
36
+ "index.d.ts",
37
+ "stores/shopify/index.js",
38
+ "stores/shopify/index.cjs.js",
39
+ "stores/shopify/index.mjs"
40
+ ]
41
+ }
@@ -0,0 +1,157 @@
1
+ 'use strict';
2
+
3
+ const canLog = () => {
4
+ try {
5
+ return localStorage.getItem('edgeTagDebug') === '1';
6
+ }
7
+ catch {
8
+ return false;
9
+ }
10
+ };
11
+ const prefix = `[EdgeTag]`;
12
+ const logger = {
13
+ log: (...args) => {
14
+ if (canLog()) {
15
+ console.log(prefix, ...args);
16
+ }
17
+ },
18
+ error: (...args) => {
19
+ if (canLog()) {
20
+ console.error(prefix, ...args);
21
+ }
22
+ },
23
+ info: (...args) => {
24
+ if (canLog()) {
25
+ console.info(prefix, ...args);
26
+ }
27
+ },
28
+ trace: (...args) => {
29
+ if (canLog()) {
30
+ console.trace(prefix, ...args);
31
+ }
32
+ },
33
+ };
34
+
35
+ var _a$1;
36
+ const registryKey = Symbol.for('blotout-consent');
37
+ if (typeof window != 'undefined') {
38
+ (_a$1 = window[registryKey]) !== null && _a$1 !== void 0 ? _a$1 : (window[registryKey] = {});
39
+ }
40
+
41
+ const LOAD_TIMEOUT_MS = 5000;
42
+ /**
43
+ * Loads Shopify Customer Privacy API if available.
44
+ * Returns `null` when Shopify APIs are unavailable, timed out, or fail to load.
45
+ */
46
+ const loadCustomerPrivacyApi = () => new Promise((resolve) => {
47
+ var _a, _b;
48
+ if ((_a = window.Shopify) === null || _a === void 0 ? void 0 : _a.customerPrivacy) {
49
+ resolve(window.Shopify.customerPrivacy);
50
+ return;
51
+ }
52
+ if (!((_b = window.Shopify) === null || _b === void 0 ? void 0 : _b.loadFeatures)) {
53
+ logger.info('Shopify.loadFeatures is not available');
54
+ resolve(null);
55
+ return;
56
+ }
57
+ let settled = false;
58
+ const timeout = setTimeout(() => {
59
+ if (settled) {
60
+ return;
61
+ }
62
+ settled = true;
63
+ logger.info('Timed out loading Shopify Customer Privacy API');
64
+ resolve(null);
65
+ }, LOAD_TIMEOUT_MS);
66
+ window.Shopify.loadFeatures([{ name: 'consent-tracking-api', version: '0.1' }], (error) => {
67
+ var _a, _b;
68
+ clearTimeout(timeout);
69
+ if (settled) {
70
+ return;
71
+ }
72
+ settled = true;
73
+ if (error) {
74
+ logger.error('Failed to load Shopify Customer Privacy API:', error);
75
+ resolve(null);
76
+ return;
77
+ }
78
+ resolve((_b = (_a = window.Shopify) === null || _a === void 0 ? void 0 : _a.customerPrivacy) !== null && _b !== void 0 ? _b : null);
79
+ });
80
+ });
81
+
82
+ /**
83
+ * Maps blotout-consent ConsentPreferences to Shopify Customer Privacy API payload.
84
+ *
85
+ * Shopify recognizes: analytics, marketing, preferences, sale_of_data
86
+ * Blotout categories: necessary, functional, analytics, marketing, performance
87
+ *
88
+ * - `analytics` maps directly
89
+ * - `marketing` maps directly
90
+ * - `preferences` maps to functional
91
+ * - `sale_of_data` is true when either marketing or analytics is granted
92
+ */
93
+ const toShopifyConsent = (preferences) => ({
94
+ analytics: preferences.analytics,
95
+ marketing: preferences.marketing,
96
+ preferences: preferences.functional,
97
+ sale_of_data: preferences.marketing,
98
+ });
99
+
100
+ var _a, _b;
101
+ var _c;
102
+ const createShopifyStoreApi = () => {
103
+ let privacyApiRef = null;
104
+ let loading = null;
105
+ const ensurePrivacyApi = () => {
106
+ if (privacyApiRef) {
107
+ return Promise.resolve(privacyApiRef);
108
+ }
109
+ if (!loading) {
110
+ loading = loadCustomerPrivacyApi()
111
+ .then((api) => {
112
+ privacyApiRef = api;
113
+ loading = null;
114
+ return api;
115
+ })
116
+ .catch((err) => {
117
+ loading = null;
118
+ throw err;
119
+ });
120
+ }
121
+ return loading;
122
+ };
123
+ return {
124
+ async setConsentTracking(preferences) {
125
+ const api = await ensurePrivacyApi();
126
+ if (!api) {
127
+ logger.info('Shopify Customer Privacy API not available, skipping consent sync');
128
+ return;
129
+ }
130
+ const payload = toShopifyConsent(preferences);
131
+ await new Promise((resolve, reject) => {
132
+ let resolved = false;
133
+ const timeout = setTimeout(() => {
134
+ resolved = true;
135
+ reject(new Error('setTrackingConsent timed out'));
136
+ }, 10000);
137
+ api.setTrackingConsent(payload, () => {
138
+ if (resolved) {
139
+ return;
140
+ }
141
+ resolved = true;
142
+ clearTimeout(timeout);
143
+ logger.info('Consent synced to Shopify Customer Privacy API');
144
+ resolve();
145
+ });
146
+ });
147
+ },
148
+ isAvailable() {
149
+ var _a, _b;
150
+ return !!((_a = window.Shopify) === null || _a === void 0 ? void 0 : _a.customerPrivacy) || !!((_b = window.Shopify) === null || _b === void 0 ? void 0 : _b.loadFeatures);
151
+ },
152
+ };
153
+ };
154
+ if (typeof window !== 'undefined') {
155
+ (_a = window[registryKey]) !== null && _a !== void 0 ? _a : (window[registryKey] = {});
156
+ (_b = (_c = window[registryKey]).storeAPIFactory) !== null && _b !== void 0 ? _b : (_c.storeAPIFactory = createShopifyStoreApi);
157
+ }
@@ -0,0 +1,160 @@
1
+ (function () {
2
+ 'use strict';
3
+
4
+ const canLog = () => {
5
+ try {
6
+ return localStorage.getItem('edgeTagDebug') === '1';
7
+ }
8
+ catch {
9
+ return false;
10
+ }
11
+ };
12
+ const prefix = `[EdgeTag]`;
13
+ const logger = {
14
+ log: (...args) => {
15
+ if (canLog()) {
16
+ console.log(prefix, ...args);
17
+ }
18
+ },
19
+ error: (...args) => {
20
+ if (canLog()) {
21
+ console.error(prefix, ...args);
22
+ }
23
+ },
24
+ info: (...args) => {
25
+ if (canLog()) {
26
+ console.info(prefix, ...args);
27
+ }
28
+ },
29
+ trace: (...args) => {
30
+ if (canLog()) {
31
+ console.trace(prefix, ...args);
32
+ }
33
+ },
34
+ };
35
+
36
+ var _a$1;
37
+ const registryKey = Symbol.for('blotout-consent');
38
+ if (typeof window != 'undefined') {
39
+ (_a$1 = window[registryKey]) !== null && _a$1 !== void 0 ? _a$1 : (window[registryKey] = {});
40
+ }
41
+
42
+ const LOAD_TIMEOUT_MS = 5000;
43
+ /**
44
+ * Loads Shopify Customer Privacy API if available.
45
+ * Returns `null` when Shopify APIs are unavailable, timed out, or fail to load.
46
+ */
47
+ const loadCustomerPrivacyApi = () => new Promise((resolve) => {
48
+ var _a, _b;
49
+ if ((_a = window.Shopify) === null || _a === void 0 ? void 0 : _a.customerPrivacy) {
50
+ resolve(window.Shopify.customerPrivacy);
51
+ return;
52
+ }
53
+ if (!((_b = window.Shopify) === null || _b === void 0 ? void 0 : _b.loadFeatures)) {
54
+ logger.info('Shopify.loadFeatures is not available');
55
+ resolve(null);
56
+ return;
57
+ }
58
+ let settled = false;
59
+ const timeout = setTimeout(() => {
60
+ if (settled) {
61
+ return;
62
+ }
63
+ settled = true;
64
+ logger.info('Timed out loading Shopify Customer Privacy API');
65
+ resolve(null);
66
+ }, LOAD_TIMEOUT_MS);
67
+ window.Shopify.loadFeatures([{ name: 'consent-tracking-api', version: '0.1' }], (error) => {
68
+ var _a, _b;
69
+ clearTimeout(timeout);
70
+ if (settled) {
71
+ return;
72
+ }
73
+ settled = true;
74
+ if (error) {
75
+ logger.error('Failed to load Shopify Customer Privacy API:', error);
76
+ resolve(null);
77
+ return;
78
+ }
79
+ resolve((_b = (_a = window.Shopify) === null || _a === void 0 ? void 0 : _a.customerPrivacy) !== null && _b !== void 0 ? _b : null);
80
+ });
81
+ });
82
+
83
+ /**
84
+ * Maps blotout-consent ConsentPreferences to Shopify Customer Privacy API payload.
85
+ *
86
+ * Shopify recognizes: analytics, marketing, preferences, sale_of_data
87
+ * Blotout categories: necessary, functional, analytics, marketing, performance
88
+ *
89
+ * - `analytics` maps directly
90
+ * - `marketing` maps directly
91
+ * - `preferences` maps to functional
92
+ * - `sale_of_data` is true when either marketing or analytics is granted
93
+ */
94
+ const toShopifyConsent = (preferences) => ({
95
+ analytics: preferences.analytics,
96
+ marketing: preferences.marketing,
97
+ preferences: preferences.functional,
98
+ sale_of_data: preferences.marketing,
99
+ });
100
+
101
+ var _a, _b;
102
+ var _c;
103
+ const createShopifyStoreApi = () => {
104
+ let privacyApiRef = null;
105
+ let loading = null;
106
+ const ensurePrivacyApi = () => {
107
+ if (privacyApiRef) {
108
+ return Promise.resolve(privacyApiRef);
109
+ }
110
+ if (!loading) {
111
+ loading = loadCustomerPrivacyApi()
112
+ .then((api) => {
113
+ privacyApiRef = api;
114
+ loading = null;
115
+ return api;
116
+ })
117
+ .catch((err) => {
118
+ loading = null;
119
+ throw err;
120
+ });
121
+ }
122
+ return loading;
123
+ };
124
+ return {
125
+ async setConsentTracking(preferences) {
126
+ const api = await ensurePrivacyApi();
127
+ if (!api) {
128
+ logger.info('Shopify Customer Privacy API not available, skipping consent sync');
129
+ return;
130
+ }
131
+ const payload = toShopifyConsent(preferences);
132
+ await new Promise((resolve, reject) => {
133
+ let resolved = false;
134
+ const timeout = setTimeout(() => {
135
+ resolved = true;
136
+ reject(new Error('setTrackingConsent timed out'));
137
+ }, 10000);
138
+ api.setTrackingConsent(payload, () => {
139
+ if (resolved) {
140
+ return;
141
+ }
142
+ resolved = true;
143
+ clearTimeout(timeout);
144
+ logger.info('Consent synced to Shopify Customer Privacy API');
145
+ resolve();
146
+ });
147
+ });
148
+ },
149
+ isAvailable() {
150
+ var _a, _b;
151
+ return !!((_a = window.Shopify) === null || _a === void 0 ? void 0 : _a.customerPrivacy) || !!((_b = window.Shopify) === null || _b === void 0 ? void 0 : _b.loadFeatures);
152
+ },
153
+ };
154
+ };
155
+ if (typeof window !== 'undefined') {
156
+ (_a = window[registryKey]) !== null && _a !== void 0 ? _a : (window[registryKey] = {});
157
+ (_b = (_c = window[registryKey]).storeAPIFactory) !== null && _b !== void 0 ? _b : (_c.storeAPIFactory = createShopifyStoreApi);
158
+ }
159
+
160
+ })();
@@ -0,0 +1,155 @@
1
+ const canLog = () => {
2
+ try {
3
+ return localStorage.getItem('edgeTagDebug') === '1';
4
+ }
5
+ catch {
6
+ return false;
7
+ }
8
+ };
9
+ const prefix = `[EdgeTag]`;
10
+ const logger = {
11
+ log: (...args) => {
12
+ if (canLog()) {
13
+ console.log(prefix, ...args);
14
+ }
15
+ },
16
+ error: (...args) => {
17
+ if (canLog()) {
18
+ console.error(prefix, ...args);
19
+ }
20
+ },
21
+ info: (...args) => {
22
+ if (canLog()) {
23
+ console.info(prefix, ...args);
24
+ }
25
+ },
26
+ trace: (...args) => {
27
+ if (canLog()) {
28
+ console.trace(prefix, ...args);
29
+ }
30
+ },
31
+ };
32
+
33
+ var _a$1;
34
+ const registryKey = Symbol.for('blotout-consent');
35
+ if (typeof window != 'undefined') {
36
+ (_a$1 = window[registryKey]) !== null && _a$1 !== void 0 ? _a$1 : (window[registryKey] = {});
37
+ }
38
+
39
+ const LOAD_TIMEOUT_MS = 5000;
40
+ /**
41
+ * Loads Shopify Customer Privacy API if available.
42
+ * Returns `null` when Shopify APIs are unavailable, timed out, or fail to load.
43
+ */
44
+ const loadCustomerPrivacyApi = () => new Promise((resolve) => {
45
+ var _a, _b;
46
+ if ((_a = window.Shopify) === null || _a === void 0 ? void 0 : _a.customerPrivacy) {
47
+ resolve(window.Shopify.customerPrivacy);
48
+ return;
49
+ }
50
+ if (!((_b = window.Shopify) === null || _b === void 0 ? void 0 : _b.loadFeatures)) {
51
+ logger.info('Shopify.loadFeatures is not available');
52
+ resolve(null);
53
+ return;
54
+ }
55
+ let settled = false;
56
+ const timeout = setTimeout(() => {
57
+ if (settled) {
58
+ return;
59
+ }
60
+ settled = true;
61
+ logger.info('Timed out loading Shopify Customer Privacy API');
62
+ resolve(null);
63
+ }, LOAD_TIMEOUT_MS);
64
+ window.Shopify.loadFeatures([{ name: 'consent-tracking-api', version: '0.1' }], (error) => {
65
+ var _a, _b;
66
+ clearTimeout(timeout);
67
+ if (settled) {
68
+ return;
69
+ }
70
+ settled = true;
71
+ if (error) {
72
+ logger.error('Failed to load Shopify Customer Privacy API:', error);
73
+ resolve(null);
74
+ return;
75
+ }
76
+ resolve((_b = (_a = window.Shopify) === null || _a === void 0 ? void 0 : _a.customerPrivacy) !== null && _b !== void 0 ? _b : null);
77
+ });
78
+ });
79
+
80
+ /**
81
+ * Maps blotout-consent ConsentPreferences to Shopify Customer Privacy API payload.
82
+ *
83
+ * Shopify recognizes: analytics, marketing, preferences, sale_of_data
84
+ * Blotout categories: necessary, functional, analytics, marketing, performance
85
+ *
86
+ * - `analytics` maps directly
87
+ * - `marketing` maps directly
88
+ * - `preferences` maps to functional
89
+ * - `sale_of_data` is true when either marketing or analytics is granted
90
+ */
91
+ const toShopifyConsent = (preferences) => ({
92
+ analytics: preferences.analytics,
93
+ marketing: preferences.marketing,
94
+ preferences: preferences.functional,
95
+ sale_of_data: preferences.marketing,
96
+ });
97
+
98
+ var _a, _b;
99
+ var _c;
100
+ const createShopifyStoreApi = () => {
101
+ let privacyApiRef = null;
102
+ let loading = null;
103
+ const ensurePrivacyApi = () => {
104
+ if (privacyApiRef) {
105
+ return Promise.resolve(privacyApiRef);
106
+ }
107
+ if (!loading) {
108
+ loading = loadCustomerPrivacyApi()
109
+ .then((api) => {
110
+ privacyApiRef = api;
111
+ loading = null;
112
+ return api;
113
+ })
114
+ .catch((err) => {
115
+ loading = null;
116
+ throw err;
117
+ });
118
+ }
119
+ return loading;
120
+ };
121
+ return {
122
+ async setConsentTracking(preferences) {
123
+ const api = await ensurePrivacyApi();
124
+ if (!api) {
125
+ logger.info('Shopify Customer Privacy API not available, skipping consent sync');
126
+ return;
127
+ }
128
+ const payload = toShopifyConsent(preferences);
129
+ await new Promise((resolve, reject) => {
130
+ let resolved = false;
131
+ const timeout = setTimeout(() => {
132
+ resolved = true;
133
+ reject(new Error('setTrackingConsent timed out'));
134
+ }, 10000);
135
+ api.setTrackingConsent(payload, () => {
136
+ if (resolved) {
137
+ return;
138
+ }
139
+ resolved = true;
140
+ clearTimeout(timeout);
141
+ logger.info('Consent synced to Shopify Customer Privacy API');
142
+ resolve();
143
+ });
144
+ });
145
+ },
146
+ isAvailable() {
147
+ var _a, _b;
148
+ return !!((_a = window.Shopify) === null || _a === void 0 ? void 0 : _a.customerPrivacy) || !!((_b = window.Shopify) === null || _b === void 0 ? void 0 : _b.loadFeatures);
149
+ },
150
+ };
151
+ };
152
+ if (typeof window !== 'undefined') {
153
+ (_a = window[registryKey]) !== null && _a !== void 0 ? _a : (window[registryKey] = {});
154
+ (_b = (_c = window[registryKey]).storeAPIFactory) !== null && _b !== void 0 ? _b : (_c.storeAPIFactory = createShopifyStoreApi);
155
+ }