@scalemule/news-publication 0.0.13 → 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.
@@ -2,27 +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_CONSENT_HUB_URL = "https://bayareachronicle.com/consent-bridge.html";
13
- var NETWORK_CONSENT_STORAGE_KEY = "sm_network_consent_status";
14
- var DEFAULT_PREFERENCES_REJECTED = {
15
- essential: true,
16
- performance: false,
17
- functional: false,
18
- advertising: false
19
- };
20
- var DEFAULT_PREFERENCES_ACCEPTED = {
21
- essential: true,
22
- performance: true,
23
- functional: true,
24
- advertising: true
25
- };
8
+ async function recordConsentToCompliance(record, options) {
9
+ return compliance.recordConsentToCompliance(record, options);
10
+ }
26
11
  var COOKIE_CATEGORIES = [
27
12
  {
28
13
  id: "essential",
@@ -131,169 +116,6 @@ var COOKIE_CATEGORIES = [
131
116
  ]
132
117
  }
133
118
  ];
134
- var memoryConsent = null;
135
- function readCookie(name) {
136
- if (typeof document === "undefined") return null;
137
- const match = document.cookie.match(new RegExp("(?:^|; )" + name.replace(/([.$?*|{}()[\]\\/+^])/g, "\\$1") + "=([^;]*)"));
138
- return match ? decodeURIComponent(match[1]) : null;
139
- }
140
- function writeCookie(name, value, maxAgeSeconds) {
141
- if (typeof document === "undefined") return;
142
- const secure = typeof location !== "undefined" && location.protocol === "https:" ? "; Secure" : "";
143
- document.cookie = `${name}=${encodeURIComponent(value)}; Path=/; Max-Age=${maxAgeSeconds}; SameSite=Lax${secure}`;
144
- }
145
- function getCookieConsent() {
146
- if (typeof window === "undefined") return memoryConsent;
147
- try {
148
- const raw = readCookie(COOKIE_CONSENT_KEY) || readCookie(COOKIE_CONSENT_BACKUP_KEY);
149
- if (raw) {
150
- const parsed = JSON.parse(raw);
151
- if (parsed && parsed.version === 1 && parsed.preferences) {
152
- memoryConsent = parsed;
153
- return parsed;
154
- }
155
- }
156
- const stored = window.localStorage?.getItem(COOKIE_CONSENT_KEY);
157
- if (stored) {
158
- const parsed = JSON.parse(stored);
159
- if (parsed && parsed.version === 1 && parsed.preferences) {
160
- memoryConsent = parsed;
161
- return parsed;
162
- }
163
- }
164
- } catch {
165
- }
166
- return memoryConsent;
167
- }
168
- function setNetworkConsentHub(status, hubUrl = DEFAULT_CONSENT_HUB_URL) {
169
- if (typeof window === "undefined") return;
170
- try {
171
- const hubOrigin = new URL(hubUrl).origin;
172
- if (window.location.origin === hubOrigin) {
173
- try {
174
- if (status) {
175
- window.localStorage?.setItem(NETWORK_CONSENT_STORAGE_KEY, status);
176
- }
177
- } catch {
178
- }
179
- return;
180
- }
181
- let iframe = null;
182
- let timer = null;
183
- const cleanup = () => {
184
- if (timer !== null) window.clearTimeout(timer);
185
- window.removeEventListener("message", onMessage);
186
- if (iframe && iframe.parentNode) {
187
- try {
188
- iframe.parentNode.removeChild(iframe);
189
- } catch {
190
- }
191
- }
192
- };
193
- const sendSet = () => {
194
- try {
195
- iframe?.contentWindow?.postMessage({ type: "SM_CONSENT_SET", status }, hubOrigin);
196
- } catch {
197
- }
198
- };
199
- const onMessage = (event) => {
200
- if (event.origin !== hubOrigin) return;
201
- const data = event.data;
202
- if (!data || typeof data !== "object") return;
203
- if (data.type === "SM_CONSENT_SAVED") {
204
- cleanup();
205
- } else if (data.type === "SM_CONSENT_BRIDGE_READY") {
206
- sendSet();
207
- }
208
- };
209
- window.addEventListener("message", onMessage);
210
- timer = window.setTimeout(cleanup, 2500);
211
- try {
212
- iframe = document.createElement("iframe");
213
- iframe.src = hubUrl;
214
- iframe.style.position = "absolute";
215
- iframe.style.width = "0";
216
- iframe.style.height = "0";
217
- iframe.style.border = "0";
218
- iframe.style.display = "none";
219
- iframe.style.visibility = "hidden";
220
- iframe.setAttribute("aria-hidden", "true");
221
- iframe.setAttribute("tabindex", "-1");
222
- iframe.onload = () => {
223
- sendSet();
224
- };
225
- iframe.onerror = cleanup;
226
- const target = document.body || document.documentElement;
227
- target.appendChild(iframe);
228
- } catch {
229
- cleanup();
230
- }
231
- } catch {
232
- }
233
- }
234
- function setCookieConsent(preferences, source = "settings_save") {
235
- const mergedPreferences = {
236
- essential: true,
237
- performance: Boolean(preferences.performance),
238
- functional: Boolean(preferences.functional),
239
- advertising: Boolean(preferences.advertising)
240
- };
241
- let anonymous_id;
242
- if (typeof window !== "undefined") {
243
- try {
244
- anonymous_id = window.localStorage?.getItem("napsite_visitor_v1") || void 0;
245
- } catch {
246
- }
247
- }
248
- const record = {
249
- version: 1,
250
- preferences: mergedPreferences,
251
- timestamp: (/* @__PURE__ */ new Date()).toISOString(),
252
- anonymous_id,
253
- source
254
- };
255
- memoryConsent = record;
256
- const serialized = JSON.stringify(record);
257
- writeCookie(COOKIE_CONSENT_KEY, serialized, COOKIE_CONSENT_MAX_AGE_SECONDS);
258
- writeCookie(COOKIE_CONSENT_BACKUP_KEY, serialized, COOKIE_CONSENT_MAX_AGE_SECONDS);
259
- if (typeof window !== "undefined") {
260
- try {
261
- window.localStorage?.setItem(COOKIE_CONSENT_KEY, serialized);
262
- } catch {
263
- }
264
- const networkStatus = mergedPreferences.performance || mergedPreferences.advertising ? "accepted" : "rejected";
265
- setNetworkConsentHub(networkStatus);
266
- window.dispatchEvent(new CustomEvent(COOKIE_CONSENT_EVENT, { detail: record }));
267
- }
268
- return record;
269
- }
270
- async function recordConsentToCompliance(record, options) {
271
- if (typeof window === "undefined") return;
272
- const endpoint = options?.endpoint || "/api/compliance/consent";
273
- try {
274
- const payload = {
275
- consent_type: "cookie_policy",
276
- granted: record.preferences.performance || record.preferences.advertising,
277
- preferences: record.preferences,
278
- source: record.source,
279
- anonymous_id: record.anonymous_id,
280
- timestamp: record.timestamp,
281
- url: window.location.href,
282
- user_agent: window.navigator.userAgent
283
- };
284
- if (typeof navigator.sendBeacon === "function") {
285
- navigator.sendBeacon(endpoint, new Blob([JSON.stringify(payload)], { type: "application/json" }));
286
- } else {
287
- await fetch(endpoint, {
288
- method: "POST",
289
- headers: { "content-type": "application/json" },
290
- body: JSON.stringify(payload),
291
- keepalive: true
292
- });
293
- }
294
- } catch {
295
- }
296
- }
297
119
  function CookieSettingsView({
298
120
  publicationName = "This Publication",
299
121
  region,
@@ -301,8 +123,8 @@ function CookieSettingsView({
301
123
  publicationSlug
302
124
  }) {
303
125
  const [preferences, setPreferences] = react.useState(() => {
304
- const existing = getCookieConsent();
305
- return existing ? existing.preferences : { ...DEFAULT_PREFERENCES_ACCEPTED };
126
+ const existing = compliance.getCookieConsent();
127
+ return existing ? existing.preferences : { ...compliance.DEFAULT_PREFERENCES_ACCEPTED };
306
128
  });
307
129
  const [expandedCategories, setExpandedCategories] = react.useState({
308
130
  essential: false,
@@ -313,7 +135,7 @@ function CookieSettingsView({
313
135
  const [saveSuccess, setSaveSuccess] = react.useState(false);
314
136
  const [lastSavedTime, setLastSavedTime] = react.useState(null);
315
137
  react.useEffect(() => {
316
- const existing = getCookieConsent();
138
+ const existing = compliance.getCookieConsent();
317
139
  if (existing) {
318
140
  setPreferences(existing.preferences);
319
141
  setLastSavedTime(new Date(existing.timestamp).toLocaleTimeString([], { hour: "numeric", minute: "2-digit" }));
@@ -334,29 +156,35 @@ function CookieSettingsView({
334
156
  }));
335
157
  };
336
158
  const handleSave = () => {
337
- const record = setCookieConsent(preferences, "settings_save");
159
+ const record = compliance.setCookieConsent(preferences, "settings_save");
338
160
  setSaveSuccess(true);
339
161
  setLastSavedTime(new Date(record.timestamp).toLocaleTimeString([], { hour: "numeric", minute: "2-digit" }));
340
162
  void recordConsentToCompliance(record, {
341
- endpoint: complianceEndpoint});
163
+ endpoint: complianceEndpoint,
164
+ publicationSlug
165
+ });
342
166
  window.scrollTo({ top: 0, behavior: "smooth" });
343
167
  };
344
168
  const handleAcceptAll = () => {
345
- setPreferences({ ...DEFAULT_PREFERENCES_ACCEPTED });
346
- 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");
347
171
  setSaveSuccess(true);
348
172
  setLastSavedTime(new Date(record.timestamp).toLocaleTimeString([], { hour: "numeric", minute: "2-digit" }));
349
173
  void recordConsentToCompliance(record, {
350
- endpoint: complianceEndpoint});
174
+ endpoint: complianceEndpoint,
175
+ publicationSlug
176
+ });
351
177
  window.scrollTo({ top: 0, behavior: "smooth" });
352
178
  };
353
179
  const handleRejectAll = () => {
354
- setPreferences({ ...DEFAULT_PREFERENCES_REJECTED });
355
- 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");
356
182
  setSaveSuccess(true);
357
183
  setLastSavedTime(new Date(record.timestamp).toLocaleTimeString([], { hour: "numeric", minute: "2-digit" }));
358
184
  void recordConsentToCompliance(record, {
359
- endpoint: complianceEndpoint});
185
+ endpoint: complianceEndpoint,
186
+ publicationSlug
187
+ });
360
188
  window.scrollTo({ top: 0, behavior: "smooth" });
361
189
  };
362
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-FUUL2PSF.js';
3
- import './chunk-L5OE6DND.js';
2
+ export { CookieSettingsView } from './chunk-WZ3NQRQO.js';
3
+ import './chunk-QWK6G2UF.js';