cookie-prefs 0.2.1 → 0.2.2

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/dist/index.cjs CHANGED
@@ -146,6 +146,7 @@ var bind = (key, def, prefix, options) => {
146
146
  }
147
147
  };
148
148
  let rejected = false;
149
+ let insecure = false;
149
150
  const write = (value) => {
150
151
  try {
151
152
  document.cookie = serialize(attrs, value);
@@ -188,7 +189,15 @@ var bind = (key, def, prefix, options) => {
188
189
  };
189
190
  },
190
191
  read,
191
- toCookie: (value) => ({ ...attrs, value: def.s(value) })
192
+ toCookie: (value) => {
193
+ if (typeof process == "object" && process.env.NODE_ENV != "production" && typeof document == "undefined" && !insecure && !attrs.secure && (attrs.sameSite == "none" || /^__(Host|Secure)-/i.test(name))) {
194
+ insecure = true;
195
+ console.warn(
196
+ `cookie-prefs: ${key}.toCookie() builds a cookie that browsers drop: SameSite=None and the __Host- and __Secure- name prefixes need Secure. Set secure: true in .options() or definePrefs().`
197
+ );
198
+ }
199
+ return { ...attrs, value: def.s(value) };
200
+ }
192
201
  };
193
202
  if (targets)
194
203
  Object.defineProperty(handle, REFLECTION, {
package/dist/index.d.cts CHANGED
@@ -1,5 +1,5 @@
1
- import { E as EnumPrefBuilder, S as ScalarPrefBuilder, P as PrefBuilder, a as PrefCodec, b as PrefShape, c as PrefsOptions, d as Prefs, e as PrefsRecord, C as CookieSource, f as PrefValues, g as PrefsSnapshot } from './types-C5uwWL7s.cjs';
2
- export { A as AnyPref, h as AnyPrefBuilder, i as CookieGetter, j as CookieInit, k as CookieOptions, l as CookieSameSite, m as EnumReflectTarget, n as Pref, o as PrefOptions, p as PrefSetter, q as PrefTypes, r as PrefValue, R as ReflectTarget } from './types-C5uwWL7s.cjs';
1
+ import { E as EnumPrefBuilder, S as ScalarPrefBuilder, P as PrefBuilder, a as PrefCodec, b as PrefShape, c as PrefsOptions, d as Prefs, e as PrefsRecord, C as CookieSource, f as PrefValues, g as PrefsSnapshot } from './types-DHcC7bDq.cjs';
2
+ export { A as AnyPref, h as AnyPrefBuilder, i as CookieGetter, j as CookieInit, k as CookieOptions, l as CookieSameSite, m as EnumReflectTarget, n as Pref, o as PrefOptions, p as PrefSetter, q as PrefTypes, r as PrefValue, R as ReflectTarget } from './types-DHcC7bDq.cjs';
3
3
 
4
4
  /**
5
5
  * Structural copy of the Standard Schema v1 interface (https://standardschema.dev, MIT).
package/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- import { E as EnumPrefBuilder, S as ScalarPrefBuilder, P as PrefBuilder, a as PrefCodec, b as PrefShape, c as PrefsOptions, d as Prefs, e as PrefsRecord, C as CookieSource, f as PrefValues, g as PrefsSnapshot } from './types-C5uwWL7s.js';
2
- export { A as AnyPref, h as AnyPrefBuilder, i as CookieGetter, j as CookieInit, k as CookieOptions, l as CookieSameSite, m as EnumReflectTarget, n as Pref, o as PrefOptions, p as PrefSetter, q as PrefTypes, r as PrefValue, R as ReflectTarget } from './types-C5uwWL7s.js';
1
+ import { E as EnumPrefBuilder, S as ScalarPrefBuilder, P as PrefBuilder, a as PrefCodec, b as PrefShape, c as PrefsOptions, d as Prefs, e as PrefsRecord, C as CookieSource, f as PrefValues, g as PrefsSnapshot } from './types-DHcC7bDq.js';
2
+ export { A as AnyPref, h as AnyPrefBuilder, i as CookieGetter, j as CookieInit, k as CookieOptions, l as CookieSameSite, m as EnumReflectTarget, n as Pref, o as PrefOptions, p as PrefSetter, q as PrefTypes, r as PrefValue, R as ReflectTarget } from './types-DHcC7bDq.js';
3
3
 
4
4
  /**
5
5
  * Structural copy of the Standard Schema v1 interface (https://standardschema.dev, MIT).
package/dist/index.js CHANGED
@@ -144,6 +144,7 @@ var bind = (key, def, prefix, options) => {
144
144
  }
145
145
  };
146
146
  let rejected = false;
147
+ let insecure = false;
147
148
  const write = (value) => {
148
149
  try {
149
150
  document.cookie = serialize(attrs, value);
@@ -186,7 +187,15 @@ var bind = (key, def, prefix, options) => {
186
187
  };
187
188
  },
188
189
  read,
189
- toCookie: (value) => ({ ...attrs, value: def.s(value) })
190
+ toCookie: (value) => {
191
+ if (typeof process == "object" && process.env.NODE_ENV != "production" && typeof document == "undefined" && !insecure && !attrs.secure && (attrs.sameSite == "none" || /^__(Host|Secure)-/i.test(name))) {
192
+ insecure = true;
193
+ console.warn(
194
+ `cookie-prefs: ${key}.toCookie() builds a cookie that browsers drop: SameSite=None and the __Host- and __Secure- name prefixes need Secure. Set secure: true in .options() or definePrefs().`
195
+ );
196
+ }
197
+ return { ...attrs, value: def.s(value) };
198
+ }
190
199
  };
191
200
  if (targets)
192
201
  Object.defineProperty(handle, REFLECTION, {
@@ -1,5 +1,5 @@
1
1
  import { ReactNode, ReactElement } from 'react';
2
- import { p as PrefSetter } from '../types-C5uwWL7s.cjs';
2
+ import { p as PrefSetter } from '../types-DHcC7bDq.cjs';
3
3
  import { PrefsSnapshot, PrefsRecord, PrefTypes, Pref, PrefValues } from '../index.cjs';
4
4
 
5
5
  /**
@@ -1,5 +1,5 @@
1
1
  import { ReactNode, ReactElement } from 'react';
2
- import { p as PrefSetter } from '../types-C5uwWL7s.js';
2
+ import { p as PrefSetter } from '../types-DHcC7bDq.js';
3
3
  import { PrefsSnapshot, PrefsRecord, PrefTypes, Pref, PrefValues } from '../index.js';
4
4
 
5
5
  /**
@@ -18,7 +18,9 @@ interface CookieOptions {
18
18
  sameSite?: CookieSameSite | undefined;
19
19
  /**
20
20
  * Send only over HTTPS. When unset, browser writes add `Secure` on `https:` pages
21
- * and `toCookie()` omits it.
21
+ * and `toCookie()` omits it. Set it for `sameSite: 'none'` and for a `__Host-` or
22
+ * `__Secure-` name written on the server: browsers drop those cookies without it
23
+ * (`toCookie()` warns in development).
22
24
  */
23
25
  secure?: boolean | undefined;
24
26
  /** CHIPS partitioned cookie. @default false */
@@ -18,7 +18,9 @@ interface CookieOptions {
18
18
  sameSite?: CookieSameSite | undefined;
19
19
  /**
20
20
  * Send only over HTTPS. When unset, browser writes add `Secure` on `https:` pages
21
- * and `toCookie()` omits it.
21
+ * and `toCookie()` omits it. Set it for `sameSite: 'none'` and for a `__Host-` or
22
+ * `__Secure-` name written on the server: browsers drop those cookies without it
23
+ * (`toCookie()` warns in development).
22
24
  */
23
25
  secure?: boolean | undefined;
24
26
  /** CHIPS partitioned cookie. @default false */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cookie-prefs",
3
- "version": "0.2.1",
3
+ "version": "0.2.2",
4
4
  "description": "Typed cookie-backed user preference state for React and Next.js",
5
5
  "keywords": [
6
6
  "react",