@sevenfold/setto-client 0.37.0 → 0.37.1
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.
|
@@ -26,6 +26,16 @@ export interface LanguageRoute {
|
|
|
26
26
|
/** The path with the prefix removed, always starting with `/`. */
|
|
27
27
|
rest: string;
|
|
28
28
|
}
|
|
29
|
+
/**
|
|
30
|
+
* The address to navigate to, or null when it would leave this origin.
|
|
31
|
+
*
|
|
32
|
+
* A second lock behind `normalise`: whatever the routing above returns, the
|
|
33
|
+
* language switch and the first-visit redirect only ever go somewhere on the
|
|
34
|
+
* site they started on. Resolved by the URL parser itself rather than by a
|
|
35
|
+
* check on the string, so it agrees with the browser about what the address
|
|
36
|
+
* means.
|
|
37
|
+
*/
|
|
38
|
+
export declare function sameOriginUrl(target: string, origin: string): string | null;
|
|
29
39
|
/**
|
|
30
40
|
* Read the language out of a path.
|
|
31
41
|
*
|
|
@@ -1,3 +1,7 @@
|
|
|
1
|
+
/** True for a single key segment that may be read or written. */
|
|
2
|
+
export declare function isSafeSegment(segment: string): boolean;
|
|
3
|
+
/** True when every segment of a dotted key may be read or written. */
|
|
4
|
+
export declare function isSafeKey(key: string): boolean;
|
|
1
5
|
/** Reads a dotted key path from a nested object. */
|
|
2
6
|
export declare function getNested(obj: unknown, key: string): unknown;
|
|
3
7
|
/** Sets a dotted key path on a nested object (mutates in place). */
|
package/dist/setto-client.js
CHANGED
|
@@ -20929,22 +20929,33 @@ function createApi(args) {
|
|
|
20929
20929
|
}
|
|
20930
20930
|
};
|
|
20931
20931
|
}
|
|
20932
|
+
const UNSAFE_SEGMENTS = /* @__PURE__ */ new Set(["__proto__", "prototype", "constructor"]);
|
|
20933
|
+
function isSafeSegment(segment) {
|
|
20934
|
+
return !UNSAFE_SEGMENTS.has(segment);
|
|
20935
|
+
}
|
|
20936
|
+
function isSafeKey(key) {
|
|
20937
|
+
return key.split(".").every(isSafeSegment);
|
|
20938
|
+
}
|
|
20932
20939
|
function getNested(obj, key) {
|
|
20933
20940
|
if (!obj || typeof obj !== "object") return void 0;
|
|
20941
|
+
if (!isSafeKey(key)) return void 0;
|
|
20934
20942
|
const parts = key.split(".");
|
|
20935
20943
|
let cur = obj;
|
|
20936
20944
|
for (const part of parts) {
|
|
20937
20945
|
if (!cur || typeof cur !== "object") return void 0;
|
|
20946
|
+
if (!Object.prototype.hasOwnProperty.call(cur, part)) return void 0;
|
|
20938
20947
|
cur = cur[part];
|
|
20939
20948
|
}
|
|
20940
20949
|
return cur;
|
|
20941
20950
|
}
|
|
20942
20951
|
function deleteNested(obj, key) {
|
|
20952
|
+
if (!isSafeKey(key)) return;
|
|
20943
20953
|
const parts = key.split(".");
|
|
20944
20954
|
const chain = [obj];
|
|
20945
20955
|
let cur = obj;
|
|
20946
20956
|
for (let i = 0; i < parts.length - 1; i++) {
|
|
20947
20957
|
const part = parts[i];
|
|
20958
|
+
if (!Object.prototype.hasOwnProperty.call(cur, part)) return;
|
|
20948
20959
|
const next = cur[part];
|
|
20949
20960
|
if (!next || typeof next !== "object") return;
|
|
20950
20961
|
cur = next;
|
|
@@ -20959,7 +20970,7 @@ function deleteNested(obj, key) {
|
|
|
20959
20970
|
function collectKeysUnder(obj, prefix) {
|
|
20960
20971
|
const base = getNested(obj, prefix);
|
|
20961
20972
|
if (!base || typeof base !== "object" || Array.isArray(base)) return [];
|
|
20962
|
-
return Object.keys(base).sort(compareListKeys);
|
|
20973
|
+
return Object.keys(base).filter(isSafeSegment).sort(compareListKeys);
|
|
20963
20974
|
}
|
|
20964
20975
|
function compareListKeys(a, b) {
|
|
20965
20976
|
const na = Number(a);
|
|
@@ -21030,6 +21041,7 @@ class I18nStore {
|
|
|
21030
21041
|
* If the value is set back to the original, the draft entry is cleared.
|
|
21031
21042
|
*/
|
|
21032
21043
|
set(key, lng, value) {
|
|
21044
|
+
if (!isSafeKey(key)) return;
|
|
21033
21045
|
const id = `${lng}::${key}`;
|
|
21034
21046
|
const existing = this.drafts.get(id);
|
|
21035
21047
|
const resource = this.i18n.getResource(lng, this.ns, key);
|
|
@@ -21049,6 +21061,7 @@ class I18nStore {
|
|
|
21049
21061
|
* deletion counts as a change and reverts cleanly.
|
|
21050
21062
|
*/
|
|
21051
21063
|
delete(key, lng) {
|
|
21064
|
+
if (!isSafeKey(key)) return;
|
|
21052
21065
|
const id = `${lng}::${key}`;
|
|
21053
21066
|
const existing = this.drafts.get(id);
|
|
21054
21067
|
const resource = this.i18n.getResource(lng, this.ns, key);
|
|
@@ -21212,7 +21225,7 @@ class I18nStore {
|
|
|
21212
21225
|
const walk2 = (value, path2) => {
|
|
21213
21226
|
if (value && typeof value === "object") {
|
|
21214
21227
|
for (const [k, v] of Object.entries(value)) {
|
|
21215
|
-
walk2(v, `${path2}.${k}`);
|
|
21228
|
+
if (isSafeSegment(k)) walk2(v, `${path2}.${k}`);
|
|
21216
21229
|
}
|
|
21217
21230
|
} else if (value !== void 0) {
|
|
21218
21231
|
out.push(path2);
|
|
@@ -21245,8 +21258,16 @@ class I18nStore {
|
|
|
21245
21258
|
}
|
|
21246
21259
|
}
|
|
21247
21260
|
function normalise(pathname) {
|
|
21248
|
-
const
|
|
21249
|
-
return
|
|
21261
|
+
const collapsed = `/${pathname}`.replace(/[\\/]+/g, "/");
|
|
21262
|
+
return collapsed.length > 1 && collapsed.endsWith("/") ? collapsed.slice(0, -1) : collapsed;
|
|
21263
|
+
}
|
|
21264
|
+
function sameOriginUrl(target, origin) {
|
|
21265
|
+
try {
|
|
21266
|
+
const url = new URL(target, origin);
|
|
21267
|
+
return url.origin === origin ? url.href : null;
|
|
21268
|
+
} catch {
|
|
21269
|
+
return null;
|
|
21270
|
+
}
|
|
21250
21271
|
}
|
|
21251
21272
|
function languageFromPath(pathname, languages, primary = languages[0] ?? DEFAULT_LANGUAGE) {
|
|
21252
21273
|
const path2 = normalise(pathname);
|
|
@@ -21276,7 +21297,8 @@ function alternateLinks(origin, pathname, languages, primary = languages[0] ?? D
|
|
|
21276
21297
|
return links;
|
|
21277
21298
|
}
|
|
21278
21299
|
function isReservedPath(pathname) {
|
|
21279
|
-
|
|
21300
|
+
const path2 = normalise(pathname);
|
|
21301
|
+
return path2 === "/setto" || path2.startsWith("/setto/");
|
|
21280
21302
|
}
|
|
21281
21303
|
function redirectForVisitor(pathname, languages, browserLanguages, stored, primary = languages[0] ?? DEFAULT_LANGUAGE) {
|
|
21282
21304
|
if (languages.length < 2) return null;
|
|
@@ -36789,8 +36811,14 @@ function SettoProvider({ config, children }) {
|
|
|
36789
36811
|
readStoredLanguage()
|
|
36790
36812
|
);
|
|
36791
36813
|
if (redirect && redirect !== window.location.pathname) {
|
|
36792
|
-
|
|
36793
|
-
|
|
36814
|
+
const url = sameOriginUrl(
|
|
36815
|
+
redirect + window.location.search + window.location.hash,
|
|
36816
|
+
window.location.origin
|
|
36817
|
+
);
|
|
36818
|
+
if (url) {
|
|
36819
|
+
window.location.replace(url);
|
|
36820
|
+
return;
|
|
36821
|
+
}
|
|
36794
36822
|
}
|
|
36795
36823
|
const { language } = languageFromPath(window.location.pathname, languages);
|
|
36796
36824
|
if (language !== i18n.language) void i18n.changeLanguage(language);
|
|
@@ -36941,7 +36969,8 @@ function SettoLanguages({ languages: given, inline = false }) {
|
|
|
36941
36969
|
if (tag === current) return;
|
|
36942
36970
|
storeLanguage(tag);
|
|
36943
36971
|
const target = pathForLanguage(window.location.pathname, tag, languages);
|
|
36944
|
-
|
|
36972
|
+
const url = sameOriginUrl(target + window.location.search + window.location.hash, window.location.origin);
|
|
36973
|
+
if (url) window.location.assign(url);
|
|
36945
36974
|
};
|
|
36946
36975
|
return /* @__PURE__ */ jsxs("div", { ref, style: inline ? inlineWrapStyle : floatingWrapStyle, children: [
|
|
36947
36976
|
/* @__PURE__ */ jsxs(
|