cookie-prefs 0.2.1 → 0.2.3
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 +30 -11
- package/dist/index.d.cts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +30 -11
- package/dist/react/index.d.cts +1 -1
- package/dist/react/index.d.ts +1 -1
- package/dist/{types-C5uwWL7s.d.cts → types-DHcC7bDq.d.cts} +3 -1
- package/dist/{types-C5uwWL7s.d.ts → types-DHcC7bDq.d.ts} +3 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -91,10 +91,14 @@ var bind = (key, def, prefix, options) => {
|
|
|
91
91
|
[...enums].map(([raw, v]) => [raw, merge({ [v]: v }, def.m)[v]])
|
|
92
92
|
) : def.k;
|
|
93
93
|
const parse = enums ? (raw) => enums.get(raw) : def.p;
|
|
94
|
-
|
|
95
|
-
if (
|
|
96
|
-
|
|
97
|
-
|
|
94
|
+
try {
|
|
95
|
+
if (process.env.NODE_ENV != "production") {
|
|
96
|
+
if (!name) throw TypeError(`cookie-prefs: ${key} needs a non-empty cookie name`);
|
|
97
|
+
if (targets?.includes("class") && Object.values({ ...kind }).some((c) => !/^[^\t\n\f\r ]+$/.test(c)))
|
|
98
|
+
throw TypeError(`cookie-prefs: ${key}.reflect('class') needs non-empty classes without whitespace`);
|
|
99
|
+
}
|
|
100
|
+
} catch (e) {
|
|
101
|
+
if (/^cookie-prefs/.test(e.message)) throw e;
|
|
98
102
|
}
|
|
99
103
|
const cache = /* @__PURE__ */ new Map();
|
|
100
104
|
const listeners = /* @__PURE__ */ new Set();
|
|
@@ -120,11 +124,14 @@ var bind = (key, def, prefix, options) => {
|
|
|
120
124
|
return read(document.cookie);
|
|
121
125
|
} catch {
|
|
122
126
|
}
|
|
123
|
-
|
|
124
|
-
warned
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
127
|
+
try {
|
|
128
|
+
if (process.env.NODE_ENV != "production" && !warned) {
|
|
129
|
+
warned = true;
|
|
130
|
+
console.warn(
|
|
131
|
+
`cookie-prefs: ${key}.get() cannot read document.cookie here and returns the default. On the server use read() or getPrefs().`
|
|
132
|
+
);
|
|
133
|
+
}
|
|
134
|
+
} catch {
|
|
128
135
|
}
|
|
129
136
|
return fallback;
|
|
130
137
|
};
|
|
@@ -146,11 +153,12 @@ var bind = (key, def, prefix, options) => {
|
|
|
146
153
|
}
|
|
147
154
|
};
|
|
148
155
|
let rejected = false;
|
|
156
|
+
let insecure = false;
|
|
149
157
|
const write = (value) => {
|
|
150
158
|
try {
|
|
151
159
|
document.cookie = serialize(attrs, value);
|
|
152
160
|
post();
|
|
153
|
-
if (
|
|
161
|
+
if (process.env.NODE_ENV != "production" && !rejected && value != null) {
|
|
154
162
|
const text = value.toWellFormed?.() ?? value;
|
|
155
163
|
if (rawOf(document.cookie, name) !== text) {
|
|
156
164
|
rejected = true;
|
|
@@ -188,7 +196,18 @@ var bind = (key, def, prefix, options) => {
|
|
|
188
196
|
};
|
|
189
197
|
},
|
|
190
198
|
read,
|
|
191
|
-
toCookie: (value) =>
|
|
199
|
+
toCookie: (value) => {
|
|
200
|
+
try {
|
|
201
|
+
if (process.env.NODE_ENV != "production" && typeof document == "undefined" && !insecure && !attrs.secure && (attrs.sameSite == "none" || /^__(Host|Secure)-/i.test(name))) {
|
|
202
|
+
insecure = true;
|
|
203
|
+
console.warn(
|
|
204
|
+
`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().`
|
|
205
|
+
);
|
|
206
|
+
}
|
|
207
|
+
} catch {
|
|
208
|
+
}
|
|
209
|
+
return { ...attrs, value: def.s(value) };
|
|
210
|
+
}
|
|
192
211
|
};
|
|
193
212
|
if (targets)
|
|
194
213
|
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
|
@@ -89,10 +89,14 @@ var bind = (key, def, prefix, options) => {
|
|
|
89
89
|
[...enums].map(([raw, v]) => [raw, merge({ [v]: v }, def.m)[v]])
|
|
90
90
|
) : def.k;
|
|
91
91
|
const parse = enums ? (raw) => enums.get(raw) : def.p;
|
|
92
|
-
|
|
93
|
-
if (
|
|
94
|
-
|
|
95
|
-
|
|
92
|
+
try {
|
|
93
|
+
if (process.env.NODE_ENV != "production") {
|
|
94
|
+
if (!name) throw TypeError(`cookie-prefs: ${key} needs a non-empty cookie name`);
|
|
95
|
+
if (targets?.includes("class") && Object.values({ ...kind }).some((c) => !/^[^\t\n\f\r ]+$/.test(c)))
|
|
96
|
+
throw TypeError(`cookie-prefs: ${key}.reflect('class') needs non-empty classes without whitespace`);
|
|
97
|
+
}
|
|
98
|
+
} catch (e) {
|
|
99
|
+
if (/^cookie-prefs/.test(e.message)) throw e;
|
|
96
100
|
}
|
|
97
101
|
const cache = /* @__PURE__ */ new Map();
|
|
98
102
|
const listeners = /* @__PURE__ */ new Set();
|
|
@@ -118,11 +122,14 @@ var bind = (key, def, prefix, options) => {
|
|
|
118
122
|
return read(document.cookie);
|
|
119
123
|
} catch {
|
|
120
124
|
}
|
|
121
|
-
|
|
122
|
-
warned
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
125
|
+
try {
|
|
126
|
+
if (process.env.NODE_ENV != "production" && !warned) {
|
|
127
|
+
warned = true;
|
|
128
|
+
console.warn(
|
|
129
|
+
`cookie-prefs: ${key}.get() cannot read document.cookie here and returns the default. On the server use read() or getPrefs().`
|
|
130
|
+
);
|
|
131
|
+
}
|
|
132
|
+
} catch {
|
|
126
133
|
}
|
|
127
134
|
return fallback;
|
|
128
135
|
};
|
|
@@ -144,11 +151,12 @@ var bind = (key, def, prefix, options) => {
|
|
|
144
151
|
}
|
|
145
152
|
};
|
|
146
153
|
let rejected = false;
|
|
154
|
+
let insecure = false;
|
|
147
155
|
const write = (value) => {
|
|
148
156
|
try {
|
|
149
157
|
document.cookie = serialize(attrs, value);
|
|
150
158
|
post();
|
|
151
|
-
if (
|
|
159
|
+
if (process.env.NODE_ENV != "production" && !rejected && value != null) {
|
|
152
160
|
const text = value.toWellFormed?.() ?? value;
|
|
153
161
|
if (rawOf(document.cookie, name) !== text) {
|
|
154
162
|
rejected = true;
|
|
@@ -186,7 +194,18 @@ var bind = (key, def, prefix, options) => {
|
|
|
186
194
|
};
|
|
187
195
|
},
|
|
188
196
|
read,
|
|
189
|
-
toCookie: (value) =>
|
|
197
|
+
toCookie: (value) => {
|
|
198
|
+
try {
|
|
199
|
+
if (process.env.NODE_ENV != "production" && typeof document == "undefined" && !insecure && !attrs.secure && (attrs.sameSite == "none" || /^__(Host|Secure)-/i.test(name))) {
|
|
200
|
+
insecure = true;
|
|
201
|
+
console.warn(
|
|
202
|
+
`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().`
|
|
203
|
+
);
|
|
204
|
+
}
|
|
205
|
+
} catch {
|
|
206
|
+
}
|
|
207
|
+
return { ...attrs, value: def.s(value) };
|
|
208
|
+
}
|
|
190
209
|
};
|
|
191
210
|
if (targets)
|
|
192
211
|
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 */
|
|
@@ -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 */
|