@scalemule/news-publication 0.0.12 → 0.0.14

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 (33) hide show
  1. package/dist/{chunk-EKQXS63J.js → chunk-5YQYJ2L2.js} +29 -5
  2. package/dist/chunk-QWK6G2UF.js +117 -0
  3. package/dist/{chunk-ZSA6YQBV.js → chunk-WZ3NQRQO.js} +1 -1
  4. package/dist/compliance.cjs +19 -0
  5. package/dist/compliance.d.cts +2 -0
  6. package/dist/compliance.d.ts +2 -0
  7. package/dist/compliance.js +2 -0
  8. package/dist/cookie-consent-banner.cjs +44 -213
  9. package/dist/cookie-consent-banner.d.cts +3 -1
  10. package/dist/cookie-consent-banner.d.ts +3 -1
  11. package/dist/cookie-consent-banner.js +2 -2
  12. package/dist/cookie-settings-view.cjs +21 -123
  13. package/dist/cookie-settings-view.js +2 -2
  14. package/dist/index.cjs +147 -287
  15. package/dist/index.d.cts +14 -102
  16. package/dist/index.d.ts +14 -102
  17. package/dist/index.js +3 -3
  18. package/dist/{marketplace-CpGWPbFk.d.ts → marketplace-29i5w4LS.d.cts} +1 -1
  19. package/dist/{marketplace-CpGWPbFk.d.cts → marketplace-29i5w4LS.d.ts} +1 -1
  20. package/dist/marketplace-view.d.cts +1 -1
  21. package/dist/marketplace-view.d.ts +1 -1
  22. package/dist/{meet-5Ym5bxfh.d.cts → meet-RWmfj3I3.d.cts} +1 -1
  23. package/dist/{meet-5Ym5bxfh.d.ts → meet-RWmfj3I3.d.ts} +1 -1
  24. package/dist/meet-forms.d.cts +1 -1
  25. package/dist/meet-forms.d.ts +1 -1
  26. package/dist/meet-view.d.cts +1 -1
  27. package/dist/meet-view.d.ts +1 -1
  28. package/dist/snapshot-file.d.cts +1 -1
  29. package/dist/snapshot-file.d.ts +1 -1
  30. package/dist/{snapshot-BS4hn1dk.d.ts → snapshot-sHgQHuAF.d.cts} +1 -1
  31. package/dist/{snapshot-BS4hn1dk.d.cts → snapshot-sHgQHuAF.d.ts} +1 -1
  32. package/package.json +12 -2
  33. package/dist/chunk-CWZWU4HE.js +0 -354
@@ -2,25 +2,12 @@
2
2
  'use strict';
3
3
 
4
4
  var react = require('react');
5
+ var compliance = require('@scalemule/compliance');
5
6
  var jsxRuntime = require('react/jsx-runtime');
6
7
 
7
- // src/cookies.ts
8
- var COOKIE_CONSENT_KEY = "sm_cookie_consent_v1";
9
- var COOKIE_CONSENT_BACKUP_KEY = "napsite_cookie_consent_v1";
10
- var COOKIE_CONSENT_EVENT = "scalemule-cookie-consent-change";
11
- var COOKIE_CONSENT_MAX_AGE_SECONDS = 365 * 24 * 60 * 60;
12
- var DEFAULT_PREFERENCES_REJECTED = {
13
- essential: true,
14
- performance: false,
15
- functional: false,
16
- advertising: false
17
- };
18
- var DEFAULT_PREFERENCES_ACCEPTED = {
19
- essential: true,
20
- performance: true,
21
- functional: true,
22
- advertising: true
23
- };
8
+ async function recordConsentToCompliance(record, options) {
9
+ return compliance.recordConsentToCompliance(record, options);
10
+ }
24
11
  var COOKIE_CATEGORIES = [
25
12
  {
26
13
  id: "essential",
@@ -129,101 +116,6 @@ var COOKIE_CATEGORIES = [
129
116
  ]
130
117
  }
131
118
  ];
132
- var memoryConsent = null;
133
- function readCookie(name) {
134
- if (typeof document === "undefined") return null;
135
- const match = document.cookie.match(new RegExp("(?:^|; )" + name.replace(/([.$?*|{}()[\]\\/+^])/g, "\\$1") + "=([^;]*)"));
136
- return match ? decodeURIComponent(match[1]) : null;
137
- }
138
- function writeCookie(name, value, maxAgeSeconds) {
139
- if (typeof document === "undefined") return;
140
- const secure = typeof location !== "undefined" && location.protocol === "https:" ? "; Secure" : "";
141
- document.cookie = `${name}=${encodeURIComponent(value)}; Path=/; Max-Age=${maxAgeSeconds}; SameSite=Lax${secure}`;
142
- }
143
- function getCookieConsent() {
144
- if (typeof window === "undefined") return memoryConsent;
145
- try {
146
- const raw = readCookie(COOKIE_CONSENT_KEY) || readCookie(COOKIE_CONSENT_BACKUP_KEY);
147
- if (raw) {
148
- const parsed = JSON.parse(raw);
149
- if (parsed && parsed.version === 1 && parsed.preferences) {
150
- memoryConsent = parsed;
151
- return parsed;
152
- }
153
- }
154
- const stored = window.localStorage?.getItem(COOKIE_CONSENT_KEY);
155
- if (stored) {
156
- const parsed = JSON.parse(stored);
157
- if (parsed && parsed.version === 1 && parsed.preferences) {
158
- memoryConsent = parsed;
159
- return parsed;
160
- }
161
- }
162
- } catch {
163
- }
164
- return memoryConsent;
165
- }
166
- function setCookieConsent(preferences, source = "settings_save") {
167
- const mergedPreferences = {
168
- essential: true,
169
- performance: Boolean(preferences.performance),
170
- functional: Boolean(preferences.functional),
171
- advertising: Boolean(preferences.advertising)
172
- };
173
- let anonymous_id;
174
- if (typeof window !== "undefined") {
175
- try {
176
- anonymous_id = window.localStorage?.getItem("napsite_visitor_v1") || void 0;
177
- } catch {
178
- }
179
- }
180
- const record = {
181
- version: 1,
182
- preferences: mergedPreferences,
183
- timestamp: (/* @__PURE__ */ new Date()).toISOString(),
184
- anonymous_id,
185
- source
186
- };
187
- memoryConsent = record;
188
- const serialized = JSON.stringify(record);
189
- writeCookie(COOKIE_CONSENT_KEY, serialized, COOKIE_CONSENT_MAX_AGE_SECONDS);
190
- writeCookie(COOKIE_CONSENT_BACKUP_KEY, serialized, COOKIE_CONSENT_MAX_AGE_SECONDS);
191
- if (typeof window !== "undefined") {
192
- try {
193
- window.localStorage?.setItem(COOKIE_CONSENT_KEY, serialized);
194
- } catch {
195
- }
196
- window.dispatchEvent(new CustomEvent(COOKIE_CONSENT_EVENT, { detail: record }));
197
- }
198
- return record;
199
- }
200
- async function recordConsentToCompliance(record, options) {
201
- if (typeof window === "undefined") return;
202
- const endpoint = options?.endpoint || "/api/compliance/consent";
203
- try {
204
- const payload = {
205
- consent_type: "cookie_policy",
206
- granted: record.preferences.performance || record.preferences.advertising,
207
- preferences: record.preferences,
208
- source: record.source,
209
- anonymous_id: record.anonymous_id,
210
- timestamp: record.timestamp,
211
- url: window.location.href,
212
- user_agent: window.navigator.userAgent
213
- };
214
- if (typeof navigator.sendBeacon === "function") {
215
- navigator.sendBeacon(endpoint, new Blob([JSON.stringify(payload)], { type: "application/json" }));
216
- } else {
217
- await fetch(endpoint, {
218
- method: "POST",
219
- headers: { "content-type": "application/json" },
220
- body: JSON.stringify(payload),
221
- keepalive: true
222
- });
223
- }
224
- } catch {
225
- }
226
- }
227
119
  function CookieSettingsView({
228
120
  publicationName = "This Publication",
229
121
  region,
@@ -231,8 +123,8 @@ function CookieSettingsView({
231
123
  publicationSlug
232
124
  }) {
233
125
  const [preferences, setPreferences] = react.useState(() => {
234
- const existing = getCookieConsent();
235
- return existing ? existing.preferences : { ...DEFAULT_PREFERENCES_ACCEPTED };
126
+ const existing = compliance.getCookieConsent();
127
+ return existing ? existing.preferences : { ...compliance.DEFAULT_PREFERENCES_ACCEPTED };
236
128
  });
237
129
  const [expandedCategories, setExpandedCategories] = react.useState({
238
130
  essential: false,
@@ -243,7 +135,7 @@ function CookieSettingsView({
243
135
  const [saveSuccess, setSaveSuccess] = react.useState(false);
244
136
  const [lastSavedTime, setLastSavedTime] = react.useState(null);
245
137
  react.useEffect(() => {
246
- const existing = getCookieConsent();
138
+ const existing = compliance.getCookieConsent();
247
139
  if (existing) {
248
140
  setPreferences(existing.preferences);
249
141
  setLastSavedTime(new Date(existing.timestamp).toLocaleTimeString([], { hour: "numeric", minute: "2-digit" }));
@@ -264,29 +156,35 @@ function CookieSettingsView({
264
156
  }));
265
157
  };
266
158
  const handleSave = () => {
267
- const record = setCookieConsent(preferences, "settings_save");
159
+ const record = compliance.setCookieConsent(preferences, "settings_save");
268
160
  setSaveSuccess(true);
269
161
  setLastSavedTime(new Date(record.timestamp).toLocaleTimeString([], { hour: "numeric", minute: "2-digit" }));
270
162
  void recordConsentToCompliance(record, {
271
- endpoint: complianceEndpoint});
163
+ endpoint: complianceEndpoint,
164
+ publicationSlug
165
+ });
272
166
  window.scrollTo({ top: 0, behavior: "smooth" });
273
167
  };
274
168
  const handleAcceptAll = () => {
275
- setPreferences({ ...DEFAULT_PREFERENCES_ACCEPTED });
276
- const record = setCookieConsent(DEFAULT_PREFERENCES_ACCEPTED, "settings_save");
169
+ setPreferences({ ...compliance.DEFAULT_PREFERENCES_ACCEPTED });
170
+ const record = compliance.setCookieConsent(compliance.DEFAULT_PREFERENCES_ACCEPTED, "settings_save");
277
171
  setSaveSuccess(true);
278
172
  setLastSavedTime(new Date(record.timestamp).toLocaleTimeString([], { hour: "numeric", minute: "2-digit" }));
279
173
  void recordConsentToCompliance(record, {
280
- endpoint: complianceEndpoint});
174
+ endpoint: complianceEndpoint,
175
+ publicationSlug
176
+ });
281
177
  window.scrollTo({ top: 0, behavior: "smooth" });
282
178
  };
283
179
  const handleRejectAll = () => {
284
- setPreferences({ ...DEFAULT_PREFERENCES_REJECTED });
285
- const record = setCookieConsent(DEFAULT_PREFERENCES_REJECTED, "settings_save");
180
+ setPreferences({ ...compliance.DEFAULT_PREFERENCES_REJECTED });
181
+ const record = compliance.setCookieConsent(compliance.DEFAULT_PREFERENCES_REJECTED, "settings_save");
286
182
  setSaveSuccess(true);
287
183
  setLastSavedTime(new Date(record.timestamp).toLocaleTimeString([], { hour: "numeric", minute: "2-digit" }));
288
184
  void recordConsentToCompliance(record, {
289
- endpoint: complianceEndpoint});
185
+ endpoint: complianceEndpoint,
186
+ publicationSlug
187
+ });
290
188
  window.scrollTo({ top: 0, behavior: "smooth" });
291
189
  };
292
190
  return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "sm-cookie-settings-container", children: [
@@ -1,3 +1,3 @@
1
1
  "use client";
2
- export { CookieSettingsView } from './chunk-ZSA6YQBV.js';
3
- import './chunk-CWZWU4HE.js';
2
+ export { CookieSettingsView } from './chunk-WZ3NQRQO.js';
3
+ import './chunk-QWK6G2UF.js';