@localess/client 3.0.7-dev.20260514090404 → 3.0.7
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/cache.d.ts +0 -16
- package/dist/client.d.ts +0 -16
- package/dist/index.js +1 -1
- package/dist/index.mjs +63 -101
- package/package.json +1 -1
package/dist/cache.d.ts
CHANGED
|
@@ -27,19 +27,3 @@ export declare class TTLCache<V> {
|
|
|
27
27
|
get(key: string): V | undefined;
|
|
28
28
|
has(key: string): boolean;
|
|
29
29
|
}
|
|
30
|
-
export declare class FileSystemCache<V> implements ICache<V> {
|
|
31
|
-
private dir;
|
|
32
|
-
private ttlMs;
|
|
33
|
-
/**
|
|
34
|
-
* Creates a FileSystemCache that persists entries as JSON files on disk.
|
|
35
|
-
* Shared across all processes that point to the same directory, making it
|
|
36
|
-
* suitable for Next.js parallel build workers.
|
|
37
|
-
* @param dir Directory to store cache files. Default: '.localess-cache'
|
|
38
|
-
* @param ttlMs Time-to-live in ms. Default: 5 minutes (300000 ms).
|
|
39
|
-
*/
|
|
40
|
-
constructor(dir?: string, ttlMs?: number);
|
|
41
|
-
private keyToPath;
|
|
42
|
-
set(key: string, value: V): void;
|
|
43
|
-
get(key: string): V | undefined;
|
|
44
|
-
has(key: string): boolean;
|
|
45
|
-
}
|
package/dist/client.d.ts
CHANGED
|
@@ -37,22 +37,6 @@ export type LocalessClientOptions = {
|
|
|
37
37
|
* cacheTTL: false // disabled
|
|
38
38
|
*/
|
|
39
39
|
cacheTTL?: number | false;
|
|
40
|
-
/**
|
|
41
|
-
* When `true`, uses a file-system cache instead of the default in-memory cache.
|
|
42
|
-
* All processes sharing the same working directory share the same cache, which makes it
|
|
43
|
-
* suitable for Next.js parallel build workers where each worker has its own memory space.
|
|
44
|
-
*
|
|
45
|
-
* Cache files are written to `.localess-cache/` in the current working directory.
|
|
46
|
-
* Add `.localess-cache/` to your `.gitignore`.
|
|
47
|
-
*
|
|
48
|
-
* `cacheTTL` still controls the TTL:
|
|
49
|
-
* - `cacheTTL: false` — caching is disabled; `fileSystemCache` is ignored
|
|
50
|
-
* - `cacheTTL: number` — file-system cache uses that TTL value (in seconds)
|
|
51
|
-
* - `cacheTTL` omitted — file-system cache uses the default 5 minutes TTL
|
|
52
|
-
*
|
|
53
|
-
* @default false
|
|
54
|
-
*/
|
|
55
|
-
fileSystemCache?: boolean;
|
|
56
40
|
};
|
|
57
41
|
export type LinksFetchParams = {
|
|
58
42
|
/**
|
package/dist/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});var e=
|
|
1
|
+
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});var e=class{cache=new Map;set(e,t){this.cache.set(e,t)}get(e){return this.cache.get(e)}has(e){return this.cache.has(e)}},t=class{set(e,t){}get(e){}has(e){return!1}},n=class{cache=new Map;constructor(e=3e5){this.ttlMs=e}set(e,t){this.cache.set(e,{value:t,expiresAt:Date.now()+this.ttlMs})}get(e){let t=this.cache.get(e);if(t){if(Date.now()>t.expiresAt){this.cache.delete(e);return}return t.value}}has(e){return this.get(e)!==void 0}},r=`\x1B[0m`,i=`\x1B[34m`,a=()=>typeof window<`u`,o=()=>typeof window>`u`,s=()=>a()&&window.self!==window.top,c=`${i}[Localess:Client]${r}`;function l(e){e.debug&&console.log(c,`Client Options : `,e);let r=e.origin.replace(/\/+$/,``),i={redirect:`follow`,headers:{"Content-Type":`application/json`,Accept:`application/json`,"X-Localess-Agent":`Localess-JS-Client`,"X-Localess-Agent-Version":`0.9.0`}},a=typeof e.cacheTTL==`number`?e.cacheTTL*1e3:void 0,o=e.cacheTTL===!1?new t:new n(a);return{async getLinks(t){e.debug&&console.log(c,`getLinks() params : `,JSON.stringify(t));let n=``;t?.kind&&(n=`&kind=${t.kind}`);let a=``;t?.parentSlug&&(a=`&parentSlug=${t.parentSlug}`);let s=``;t?.excludeChildren&&(s=`&excludeChildren=${t.excludeChildren}`);let l=`${r}/api/v1/spaces/${e.spaceId}/links?token=${e.token}${n}${a}${s}`;if(e.debug&&console.log(c,`getLinks fetch url : `,l),o.has(l))return e.debug&&console.log(c,`getLinks cache hit`),o.get(l);try{let t=await fetch(l,i);e.debug&&console.log(c,`getLinks status : `,t.status);let n=await t.json();return o.set(l,n),n}catch(e){return console.error(c,`getLinks error : `,e),{}}},async getContentBySlug(t,n){e.debug&&(console.log(c,`getContentBySlug() slug : `,t),console.log(c,`getContentBySlug() params : `,JSON.stringify(n)));let a=``;e?.version&&e.version==`draft`&&(a=`&version=${e.version}`),n?.version&&n.version==`draft`&&(a=`&version=${n.version}`);let s=n?.locale?`&locale=${n.locale}`:``,l=n?.resolveReference?`&resolveReference=${n.resolveReference}`:``,u=n?.resolveLink?`&resolveLink=${n.resolveLink}`:``,d=`${r}/api/v1/spaces/${e.spaceId}/contents/slugs/${t}?token=${e.token}${a}${s}${l}${u}`;if(e.debug&&console.log(c,`getContentBySlug fetch url : `,d),o.has(d))return e.debug&&console.log(c,`getContentBySlug cache hit`),o.get(d);try{let t=await fetch(d,i);e.debug&&console.log(c,`getContentBySlug status : `,t.status);let n=await t.json();return o.set(d,n),n}catch(e){return console.error(c,`getContentBySlug error : `,e),{}}},async getContentById(t,n){e.debug&&(console.log(c,`getContentById() id : `,t),console.log(c,`getContentById() params : `,JSON.stringify(n)));let a=``;e?.version&&e.version==`draft`&&(a=`&version=${e.version}`),n?.version&&n.version==`draft`&&(a=`&version=${n.version}`);let s=n?.locale?`&locale=${n.locale}`:``,l=n?.resolveReference?`&resolveReference=${n.resolveReference}`:``,u=n?.resolveLink?`&resolveLink=${n.resolveLink}`:``,d=`${r}/api/v1/spaces/${e.spaceId}/contents/${t}?token=${e.token}${a}${s}${l}${u}`;if(e.debug&&console.log(c,`getContentById fetch url : `,d),o.has(d))return e.debug&&console.log(c,`getContentById cache hit`),o.get(d);try{let t=await fetch(d,i);e.debug&&console.log(c,`getContentById status : `,t.status);let n=await t.json();return o.set(d,n),n}catch(e){return console.error(c,`getContentById error : `,e),{}}},async getTranslations(t){e.debug&&console.log(c,`getTranslations() locale : `,t);let n=`${r}/api/v1/spaces/${e.spaceId}/translations/${t}?token=${e.token}`;if(e.debug&&console.log(c,`getTranslations fetch url : `,n),o.has(n))return e.debug&&console.log(c,`getTranslations cache hit`),o.get(n);try{let t=await fetch(n,i);e.debug&&console.log(c,`getTranslations status : `,t.status);let r=await t.json();return o.set(n,r),r}catch(e){return console.error(c,`getTranslations error : `,e),{}}},syncScriptUrl(){return`${r}/scripts/sync-v1.js`},assetLink(t){return typeof t==`string`?`${r}/api/v1/spaces/${e.spaceId}/assets/${t}`:`${r}/api/v1/spaces/${e.spaceId}/assets/${t.uri}`}}}function u(e){return{"data-ll-id":e._id,"data-ll-schema":e._schema}}function d(e){return{"data-ll-field":e}}var f=`localess-js-sync`;async function p(e,t=!1){return new Promise((t,n)=>{if(o()){n(void 0);return}if(!s()){console.warn(`Localess Sync is loaded only in Visual Editor.`),n(void 0);return}if(window.localess!==void 0){n(void 0);return}if(document.getElementById(f)){n(void 0);return}let r=document.createElement(`script`);r.id=f,r.type=`text/javascript`,r.src=`${e}/scripts/sync-v1.js`,r.async=!0,r.onerror=e=>n(e),r.onload=e=>{console.info(`Localess Sync Script loaded`),t()},document.head.appendChild(r)})}exports.Cache=e,exports.NoCache=t,exports.TTLCache=n,exports.isBrowser=a,exports.isIframe=s,exports.isServer=o,exports.loadLocalessSync=p,exports.localessClient=l,exports.localessEditable=u,exports.localessEditableField=d;
|
package/dist/index.mjs
CHANGED
|
@@ -1,8 +1,5 @@
|
|
|
1
|
-
//#endregion
|
|
2
1
|
//#region src/cache.ts
|
|
3
|
-
var e =
|
|
4
|
-
t.exports = {};
|
|
5
|
-
})))(), t = class {
|
|
2
|
+
var e = class {
|
|
6
3
|
cache = /* @__PURE__ */ new Map();
|
|
7
4
|
set(e, t) {
|
|
8
5
|
this.cache.set(e, t);
|
|
@@ -13,13 +10,13 @@ var e = (/* @__PURE__ */ ((e, t) => () => (t || (e((t = { exports: {} }).exports
|
|
|
13
10
|
has(e) {
|
|
14
11
|
return this.cache.has(e);
|
|
15
12
|
}
|
|
16
|
-
},
|
|
13
|
+
}, t = class {
|
|
17
14
|
set(e, t) {}
|
|
18
15
|
get(e) {}
|
|
19
16
|
has(e) {
|
|
20
17
|
return !1;
|
|
21
18
|
}
|
|
22
|
-
},
|
|
19
|
+
}, n = class {
|
|
23
20
|
cache = /* @__PURE__ */ new Map();
|
|
24
21
|
constructor(e = 3e5) {
|
|
25
22
|
this.ttlMs = e;
|
|
@@ -43,45 +40,10 @@ var e = (/* @__PURE__ */ ((e, t) => () => (t || (e((t = { exports: {} }).exports
|
|
|
43
40
|
has(e) {
|
|
44
41
|
return this.get(e) !== void 0;
|
|
45
42
|
}
|
|
46
|
-
}, i =
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
this.dir = t, this.ttlMs = n, (0, e.existsSync)(t) || (0, e.mkdirSync)(t, { recursive: !0 });
|
|
51
|
-
}
|
|
52
|
-
keyToPath(t) {
|
|
53
|
-
let n = (0, e.createHash)("md5").update(t).digest("hex");
|
|
54
|
-
return (0, e.join)(this.dir, `${n}.json`);
|
|
55
|
-
}
|
|
56
|
-
set(t, n) {
|
|
57
|
-
try {
|
|
58
|
-
(0, e.writeFileSync)(this.keyToPath(t), JSON.stringify({
|
|
59
|
-
value: n,
|
|
60
|
-
expiresAt: Date.now() + this.ttlMs
|
|
61
|
-
}));
|
|
62
|
-
} catch {}
|
|
63
|
-
}
|
|
64
|
-
get(t) {
|
|
65
|
-
try {
|
|
66
|
-
let n = (0, e.readFileSync)(this.keyToPath(t), "utf-8"), r = JSON.parse(n);
|
|
67
|
-
if (Date.now() > r.expiresAt) {
|
|
68
|
-
try {
|
|
69
|
-
(0, e.unlinkSync)(this.keyToPath(t));
|
|
70
|
-
} catch {}
|
|
71
|
-
return;
|
|
72
|
-
}
|
|
73
|
-
return r.value;
|
|
74
|
-
} catch {
|
|
75
|
-
return;
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
has(e) {
|
|
79
|
-
return this.get(e) !== void 0;
|
|
80
|
-
}
|
|
81
|
-
}, a = "\x1B[0m", o = "\x1B[34m", s = () => typeof window < "u", c = () => typeof window > "u", l = () => s() && window.self !== window.top, u = `${o}[Localess:Client]${a}`;
|
|
82
|
-
function d(e) {
|
|
83
|
-
e.debug && console.log(u, "Client Options : ", e);
|
|
84
|
-
let t = e.origin.replace(/\/+$/, ""), a = {
|
|
43
|
+
}, r = "\x1B[0m", i = "\x1B[34m", a = () => typeof window < "u", o = () => typeof window > "u", s = () => a() && window.self !== window.top, c = `${i}[Localess:Client]${r}`;
|
|
44
|
+
function l(e) {
|
|
45
|
+
e.debug && console.log(c, "Client Options : ", e);
|
|
46
|
+
let r = e.origin.replace(/\/+$/, ""), i = {
|
|
85
47
|
redirect: "follow",
|
|
86
48
|
headers: {
|
|
87
49
|
"Content-Type": "application/json",
|
|
@@ -89,99 +51,99 @@ function d(e) {
|
|
|
89
51
|
"X-Localess-Agent": "Localess-JS-Client",
|
|
90
52
|
"X-Localess-Agent-Version": "0.9.0"
|
|
91
53
|
}
|
|
92
|
-
},
|
|
54
|
+
}, a = typeof e.cacheTTL == "number" ? e.cacheTTL * 1e3 : void 0, o = e.cacheTTL === !1 ? new t() : new n(a);
|
|
93
55
|
return {
|
|
94
|
-
async getLinks(
|
|
95
|
-
e.debug && console.log(
|
|
96
|
-
let
|
|
97
|
-
|
|
98
|
-
let
|
|
99
|
-
|
|
100
|
-
let
|
|
101
|
-
|
|
102
|
-
let
|
|
103
|
-
if (e.debug && console.log(
|
|
56
|
+
async getLinks(t) {
|
|
57
|
+
e.debug && console.log(c, "getLinks() params : ", JSON.stringify(t));
|
|
58
|
+
let n = "";
|
|
59
|
+
t?.kind && (n = `&kind=${t.kind}`);
|
|
60
|
+
let a = "";
|
|
61
|
+
t?.parentSlug && (a = `&parentSlug=${t.parentSlug}`);
|
|
62
|
+
let s = "";
|
|
63
|
+
t?.excludeChildren && (s = `&excludeChildren=${t.excludeChildren}`);
|
|
64
|
+
let l = `${r}/api/v1/spaces/${e.spaceId}/links?token=${e.token}${n}${a}${s}`;
|
|
65
|
+
if (e.debug && console.log(c, "getLinks fetch url : ", l), o.has(l)) return e.debug && console.log(c, "getLinks cache hit"), o.get(l);
|
|
104
66
|
try {
|
|
105
|
-
let t = await fetch(
|
|
106
|
-
e.debug && console.log(
|
|
67
|
+
let t = await fetch(l, i);
|
|
68
|
+
e.debug && console.log(c, "getLinks status : ", t.status);
|
|
107
69
|
let n = await t.json();
|
|
108
|
-
return
|
|
70
|
+
return o.set(l, n), n;
|
|
109
71
|
} catch (e) {
|
|
110
|
-
return console.error(
|
|
72
|
+
return console.error(c, "getLinks error : ", e), {};
|
|
111
73
|
}
|
|
112
74
|
},
|
|
113
|
-
async getContentBySlug(
|
|
114
|
-
e.debug && (console.log(
|
|
115
|
-
let
|
|
116
|
-
e?.version && e.version == "draft" && (
|
|
117
|
-
let
|
|
118
|
-
if (e.debug && console.log(
|
|
75
|
+
async getContentBySlug(t, n) {
|
|
76
|
+
e.debug && (console.log(c, "getContentBySlug() slug : ", t), console.log(c, "getContentBySlug() params : ", JSON.stringify(n)));
|
|
77
|
+
let a = "";
|
|
78
|
+
e?.version && e.version == "draft" && (a = `&version=${e.version}`), n?.version && n.version == "draft" && (a = `&version=${n.version}`);
|
|
79
|
+
let s = n?.locale ? `&locale=${n.locale}` : "", l = n?.resolveReference ? `&resolveReference=${n.resolveReference}` : "", u = n?.resolveLink ? `&resolveLink=${n.resolveLink}` : "", d = `${r}/api/v1/spaces/${e.spaceId}/contents/slugs/${t}?token=${e.token}${a}${s}${l}${u}`;
|
|
80
|
+
if (e.debug && console.log(c, "getContentBySlug fetch url : ", d), o.has(d)) return e.debug && console.log(c, "getContentBySlug cache hit"), o.get(d);
|
|
119
81
|
try {
|
|
120
|
-
let t = await fetch(d,
|
|
121
|
-
e.debug && console.log(
|
|
82
|
+
let t = await fetch(d, i);
|
|
83
|
+
e.debug && console.log(c, "getContentBySlug status : ", t.status);
|
|
122
84
|
let n = await t.json();
|
|
123
|
-
return
|
|
85
|
+
return o.set(d, n), n;
|
|
124
86
|
} catch (e) {
|
|
125
|
-
return console.error(
|
|
87
|
+
return console.error(c, "getContentBySlug error : ", e), {};
|
|
126
88
|
}
|
|
127
89
|
},
|
|
128
|
-
async getContentById(
|
|
129
|
-
e.debug && (console.log(
|
|
130
|
-
let
|
|
131
|
-
e?.version && e.version == "draft" && (
|
|
132
|
-
let
|
|
133
|
-
if (e.debug && console.log(
|
|
90
|
+
async getContentById(t, n) {
|
|
91
|
+
e.debug && (console.log(c, "getContentById() id : ", t), console.log(c, "getContentById() params : ", JSON.stringify(n)));
|
|
92
|
+
let a = "";
|
|
93
|
+
e?.version && e.version == "draft" && (a = `&version=${e.version}`), n?.version && n.version == "draft" && (a = `&version=${n.version}`);
|
|
94
|
+
let s = n?.locale ? `&locale=${n.locale}` : "", l = n?.resolveReference ? `&resolveReference=${n.resolveReference}` : "", u = n?.resolveLink ? `&resolveLink=${n.resolveLink}` : "", d = `${r}/api/v1/spaces/${e.spaceId}/contents/${t}?token=${e.token}${a}${s}${l}${u}`;
|
|
95
|
+
if (e.debug && console.log(c, "getContentById fetch url : ", d), o.has(d)) return e.debug && console.log(c, "getContentById cache hit"), o.get(d);
|
|
134
96
|
try {
|
|
135
|
-
let t = await fetch(d,
|
|
136
|
-
e.debug && console.log(
|
|
97
|
+
let t = await fetch(d, i);
|
|
98
|
+
e.debug && console.log(c, "getContentById status : ", t.status);
|
|
137
99
|
let n = await t.json();
|
|
138
|
-
return
|
|
100
|
+
return o.set(d, n), n;
|
|
139
101
|
} catch (e) {
|
|
140
|
-
return console.error(
|
|
102
|
+
return console.error(c, "getContentById error : ", e), {};
|
|
141
103
|
}
|
|
142
104
|
},
|
|
143
|
-
async getTranslations(
|
|
144
|
-
e.debug && console.log(
|
|
145
|
-
let
|
|
146
|
-
if (e.debug && console.log(
|
|
105
|
+
async getTranslations(t) {
|
|
106
|
+
e.debug && console.log(c, "getTranslations() locale : ", t);
|
|
107
|
+
let n = `${r}/api/v1/spaces/${e.spaceId}/translations/${t}?token=${e.token}`;
|
|
108
|
+
if (e.debug && console.log(c, "getTranslations fetch url : ", n), o.has(n)) return e.debug && console.log(c, "getTranslations cache hit"), o.get(n);
|
|
147
109
|
try {
|
|
148
|
-
let t = await fetch(
|
|
149
|
-
e.debug && console.log(
|
|
150
|
-
let
|
|
151
|
-
return
|
|
110
|
+
let t = await fetch(n, i);
|
|
111
|
+
e.debug && console.log(c, "getTranslations status : ", t.status);
|
|
112
|
+
let r = await t.json();
|
|
113
|
+
return o.set(n, r), r;
|
|
152
114
|
} catch (e) {
|
|
153
|
-
return console.error(
|
|
115
|
+
return console.error(c, "getTranslations error : ", e), {};
|
|
154
116
|
}
|
|
155
117
|
},
|
|
156
118
|
syncScriptUrl() {
|
|
157
|
-
return `${
|
|
119
|
+
return `${r}/scripts/sync-v1.js`;
|
|
158
120
|
},
|
|
159
|
-
assetLink(
|
|
160
|
-
return typeof
|
|
121
|
+
assetLink(t) {
|
|
122
|
+
return typeof t == "string" ? `${r}/api/v1/spaces/${e.spaceId}/assets/${t}` : `${r}/api/v1/spaces/${e.spaceId}/assets/${t.uri}`;
|
|
161
123
|
}
|
|
162
124
|
};
|
|
163
125
|
}
|
|
164
126
|
//#endregion
|
|
165
127
|
//#region src/editable.ts
|
|
166
|
-
function
|
|
128
|
+
function u(e) {
|
|
167
129
|
return {
|
|
168
130
|
"data-ll-id": e._id,
|
|
169
131
|
"data-ll-schema": e._schema
|
|
170
132
|
};
|
|
171
133
|
}
|
|
172
|
-
function
|
|
134
|
+
function d(e) {
|
|
173
135
|
return { "data-ll-field": e };
|
|
174
136
|
}
|
|
175
137
|
//#endregion
|
|
176
138
|
//#region src/sync.ts
|
|
177
|
-
var
|
|
178
|
-
async function
|
|
139
|
+
var f = "localess-js-sync";
|
|
140
|
+
async function p(e, t = !1) {
|
|
179
141
|
return new Promise((t, n) => {
|
|
180
|
-
if (
|
|
142
|
+
if (o()) {
|
|
181
143
|
n(void 0);
|
|
182
144
|
return;
|
|
183
145
|
}
|
|
184
|
-
if (!
|
|
146
|
+
if (!s()) {
|
|
185
147
|
console.warn("Localess Sync is loaded only in Visual Editor."), n(void 0);
|
|
186
148
|
return;
|
|
187
149
|
}
|
|
@@ -189,15 +151,15 @@ async function h(e, t = !1) {
|
|
|
189
151
|
n(void 0);
|
|
190
152
|
return;
|
|
191
153
|
}
|
|
192
|
-
if (document.getElementById(
|
|
154
|
+
if (document.getElementById(f)) {
|
|
193
155
|
n(void 0);
|
|
194
156
|
return;
|
|
195
157
|
}
|
|
196
158
|
let r = document.createElement("script");
|
|
197
|
-
r.id =
|
|
159
|
+
r.id = f, r.type = "text/javascript", r.src = `${e}/scripts/sync-v1.js`, r.async = !0, r.onerror = (e) => n(e), r.onload = (e) => {
|
|
198
160
|
console.info("Localess Sync Script loaded"), t();
|
|
199
161
|
}, document.head.appendChild(r);
|
|
200
162
|
});
|
|
201
163
|
}
|
|
202
164
|
//#endregion
|
|
203
|
-
export {
|
|
165
|
+
export { e as Cache, t as NoCache, n as TTLCache, a as isBrowser, s as isIframe, o as isServer, p as loadLocalessSync, l as localessClient, u as localessEditable, d as localessEditableField };
|