cookie-prefs 0.2.0 → 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 +20 -1
- package/dist/index.d.cts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +20 -1
- package/dist/react/index.d.cts +1 -1
- package/dist/react/index.d.ts +1 -1
- package/dist/{types-BITLlZeg.d.cts → types-DHcC7bDq.d.cts} +9 -2
- package/dist/{types-BITLlZeg.d.ts → types-DHcC7bDq.d.ts} +9 -2
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -145,10 +145,21 @@ var bind = (key, def, prefix, options) => {
|
|
|
145
145
|
});
|
|
146
146
|
}
|
|
147
147
|
};
|
|
148
|
+
let rejected = false;
|
|
149
|
+
let insecure = false;
|
|
148
150
|
const write = (value) => {
|
|
149
151
|
try {
|
|
150
152
|
document.cookie = serialize(attrs, value);
|
|
151
153
|
post();
|
|
154
|
+
if (typeof process == "object" && process.env.NODE_ENV != "production" && !rejected && value != null) {
|
|
155
|
+
const text = value.toWellFormed?.() ?? value;
|
|
156
|
+
if (rawOf(document.cookie, name) !== text) {
|
|
157
|
+
rejected = true;
|
|
158
|
+
console.warn(
|
|
159
|
+
`cookie-prefs: ${key}.set() wrote a cookie that does not read back: the browser dropped it, or another cookie named ${name} hides it. Browsers drop a cookie whose name and value exceed 4096 bytes (here ${name.length + encodeURIComponent(text).length}), one with a __Host- prefix, SameSite=None or Partitioned but no Secure, and one for a domain or path this page is not on.`
|
|
160
|
+
);
|
|
161
|
+
}
|
|
162
|
+
}
|
|
152
163
|
} catch {
|
|
153
164
|
}
|
|
154
165
|
check();
|
|
@@ -178,7 +189,15 @@ var bind = (key, def, prefix, options) => {
|
|
|
178
189
|
};
|
|
179
190
|
},
|
|
180
191
|
read,
|
|
181
|
-
toCookie: (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
|
+
}
|
|
182
201
|
};
|
|
183
202
|
if (targets)
|
|
184
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-
|
|
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-
|
|
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-
|
|
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-
|
|
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
|
@@ -143,10 +143,21 @@ var bind = (key, def, prefix, options) => {
|
|
|
143
143
|
});
|
|
144
144
|
}
|
|
145
145
|
};
|
|
146
|
+
let rejected = false;
|
|
147
|
+
let insecure = false;
|
|
146
148
|
const write = (value) => {
|
|
147
149
|
try {
|
|
148
150
|
document.cookie = serialize(attrs, value);
|
|
149
151
|
post();
|
|
152
|
+
if (typeof process == "object" && process.env.NODE_ENV != "production" && !rejected && value != null) {
|
|
153
|
+
const text = value.toWellFormed?.() ?? value;
|
|
154
|
+
if (rawOf(document.cookie, name) !== text) {
|
|
155
|
+
rejected = true;
|
|
156
|
+
console.warn(
|
|
157
|
+
`cookie-prefs: ${key}.set() wrote a cookie that does not read back: the browser dropped it, or another cookie named ${name} hides it. Browsers drop a cookie whose name and value exceed 4096 bytes (here ${name.length + encodeURIComponent(text).length}), one with a __Host- prefix, SameSite=None or Partitioned but no Secure, and one for a domain or path this page is not on.`
|
|
158
|
+
);
|
|
159
|
+
}
|
|
160
|
+
}
|
|
150
161
|
} catch {
|
|
151
162
|
}
|
|
152
163
|
check();
|
|
@@ -176,7 +187,15 @@ var bind = (key, def, prefix, options) => {
|
|
|
176
187
|
};
|
|
177
188
|
},
|
|
178
189
|
read,
|
|
179
|
-
toCookie: (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
|
+
}
|
|
180
199
|
};
|
|
181
200
|
if (targets)
|
|
182
201
|
Object.defineProperty(handle, REFLECTION, {
|
package/dist/react/index.d.cts
CHANGED
package/dist/react/index.d.ts
CHANGED
|
@@ -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 */
|
|
@@ -186,7 +188,12 @@ interface Pref<T, V = T> {
|
|
|
186
188
|
* shared with every other reader: treat json and custom values as read-only.
|
|
187
189
|
*/
|
|
188
190
|
get(): V;
|
|
189
|
-
/**
|
|
191
|
+
/**
|
|
192
|
+
* Write the cookie in the browser and notify subscribers in this and other tabs. No-op
|
|
193
|
+
* on the server. Browsers silently drop a cookie they do not accept (name and value
|
|
194
|
+
* over 4096 bytes, `SameSite=None` without `Secure`): the value then stays as it was,
|
|
195
|
+
* and in development `set()` warns once per pref.
|
|
196
|
+
*/
|
|
190
197
|
set(value: T | ((prev: V) => T)): void;
|
|
191
198
|
/** Delete the cookie, so the value goes back to the default. No-op on the server. */
|
|
192
199
|
reset(): void;
|
|
@@ -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 */
|
|
@@ -186,7 +188,12 @@ interface Pref<T, V = T> {
|
|
|
186
188
|
* shared with every other reader: treat json and custom values as read-only.
|
|
187
189
|
*/
|
|
188
190
|
get(): V;
|
|
189
|
-
/**
|
|
191
|
+
/**
|
|
192
|
+
* Write the cookie in the browser and notify subscribers in this and other tabs. No-op
|
|
193
|
+
* on the server. Browsers silently drop a cookie they do not accept (name and value
|
|
194
|
+
* over 4096 bytes, `SameSite=None` without `Secure`): the value then stays as it was,
|
|
195
|
+
* and in development `set()` warns once per pref.
|
|
196
|
+
*/
|
|
190
197
|
set(value: T | ((prev: V) => T)): void;
|
|
191
198
|
/** Delete the cookie, so the value goes back to the default. No-op on the server. */
|
|
192
199
|
reset(): void;
|