@localess/client 3.0.5-dev.20260428203008 → 3.0.5-dev.20260501214755
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.d.ts +2 -2
- package/dist/index.js +1 -1
- package/dist/index.mjs +55 -55
- package/dist/models/content-data.d.ts +1 -1
- package/package.json +2 -2
package/dist/index.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
export * from './models';
|
|
2
1
|
export * from './client';
|
|
3
2
|
export * from './editable';
|
|
3
|
+
export * from './models';
|
|
4
4
|
export * from './sync';
|
|
5
|
-
export { isBrowser,
|
|
5
|
+
export { isBrowser, isIframe, isServer } from './utils';
|
|
6
6
|
export type EventToAppType = 'save' | 'publish' | 'pong' | 'input' | 'change' | 'enterSchema' | 'hoverSchema';
|
|
7
7
|
export type EventCallback = (event: EventToApp) => void;
|
|
8
8
|
export type EventToApp = {
|
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{set(e,t){}get(e){}has(e){return!1}},t=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}},n=`\x1B[0m`,r=`\x1B[34m`,i=()=>typeof window<`u`,a=()=>typeof window>`u`,o=()=>i()&&window.self!==window.top,s=`${r}[Localess:Client]${n}`;function c(n){n.debug&&console.log(s,`Client Options : `,n);let r=n.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=n.cacheTTL===!1?new e:new t(n.cacheTTL);return{async getLinks(e){n.debug&&console.log(s,`getLinks() params : `,JSON.stringify(e));let t=``;e?.kind&&(t=`&kind=${e.kind}`);let o=``;e?.parentSlug&&(o=`&parentSlug=${e.parentSlug}`);let c=``;e?.excludeChildren&&(c=`&excludeChildren=${e.excludeChildren}`);let l=`${r}/api/v1/spaces/${n.spaceId}/links?token=${n.token}${t}${o}${c}`;if(n.debug&&console.log(s,`getLinks fetch url : `,l),a.has(l))return n.debug&&console.log(s,`getLinks cache hit`),a.get(l);try{let e=await fetch(l,i);n.debug&&console.log(s,`getLinks status : `,e.status);let t=await e.json();return a.set(l,t),t}catch(e){return console.error(s,`getLinks error : `,e),{}}},async getContentBySlug(e,t){n.debug&&(console.log(s,`getContentBySlug() slug : `,e),console.log(s,`getContentBySlug() params : `,JSON.stringify(t)));let o=``;n?.version&&n.version==`draft`&&(o=`&version=${n.version}`),t?.version&&t.version==`draft`&&(o=`&version=${t.version}`);let c=t?.locale?`&locale=${t.locale}`:``,l=t?.resolveReference?`&resolveReference=${t.resolveReference}`:``,u=t?.resolveLink?`&resolveLink=${t.resolveLink}`:``,d=`${r}/api/v1/spaces/${n.spaceId}/contents/slugs/${e}?token=${n.token}${o}${c}${l}${u}`;if(n.debug&&console.log(s,`getContentBySlug fetch url : `,d),a.has(d))return n.debug&&console.log(s,`getContentBySlug cache hit`),a.get(d);try{let e=await fetch(d,i);n.debug&&console.log(s,`getContentBySlug status : `,e.status);let t=await e.json();return a.set(d,t),t}catch(e){return console.error(s,`getContentBySlug error : `,e),{}}},async getContentById(e,t){n.debug&&(console.log(s,`getContentById() id : `,e),console.log(s,`getContentById() params : `,JSON.stringify(t)));let o=``;n?.version&&n.version==`draft`&&(o=`&version=${n.version}`),t?.version&&t.version==`draft`&&(o=`&version=${t.version}`);let c=t?.locale?`&locale=${t.locale}`:``,l=t?.resolveReference?`&resolveReference=${t.resolveReference}`:``,u=t?.resolveLink?`&resolveLink=${t.resolveLink}`:``,d=`${r}/api/v1/spaces/${n.spaceId}/contents/${e}?token=${n.token}${o}${c}${l}${u}`;if(n.debug&&console.log(s,`getContentById fetch url : `,d),a.has(d))return n.debug&&console.log(s,`getContentById cache hit`),a.get(d);try{let e=await fetch(d,i);n.debug&&console.log(s,`getContentById status : `,e.status);let t=await e.json();return a.set(d,t),t}catch(e){return console.error(s,`getContentById error : `,e),{}}},async getTranslations(e){n.debug&&console.log(s,`getTranslations() locale : `,e);let t=`${r}/api/v1/spaces/${n.spaceId}/translations/${e}?token=${n.token}`;if(n.debug&&console.log(s,`getTranslations fetch url : `,t),a.has(t))return n.debug&&console.log(s,`getTranslations cache hit`),a.get(t);try{let e=await fetch(t,i);n.debug&&console.log(s,`getTranslations status : `,e.status);let r=await e.json();return a.set(t,r),r}catch(e){return console.error(s,`getTranslations error : `,e),{}}},syncScriptUrl(){return`${r}/scripts/sync-v1.js`},assetLink(e){return typeof e==`string`?`${r}/api/v1/spaces/${n.spaceId}/assets/${e}`:`${r}/api/v1/spaces/${n.spaceId}/assets/${e.uri}`}}}function l(e){return{"data-ll-id":e._id,"data-ll-schema":e._schema}}function u(e){return{"data-ll-field":e}}var d=`localess-js-sync`;async function f(e,t=!1){return new Promise((t,n)=>{if(a()){n(void 0);return}if(!o()){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(d)){n(void 0);return}let r=document.createElement(`script`);r.id=d,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.isBrowser=i,exports.isIframe=o,exports.isServer=a,exports.loadLocalessSync=f,exports.localessClient=c,exports.localessEditable=l,exports.localessEditableField=u;
|
package/dist/index.mjs
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
//#region src/
|
|
2
|
-
var e =
|
|
1
|
+
//#region src/cache.ts
|
|
2
|
+
var e = class {
|
|
3
3
|
set(e, t) {}
|
|
4
4
|
get(e) {}
|
|
5
5
|
has(e) {
|
|
6
6
|
return !1;
|
|
7
7
|
}
|
|
8
|
-
},
|
|
8
|
+
}, t = class {
|
|
9
9
|
cache = /* @__PURE__ */ new Map();
|
|
10
10
|
constructor(e = 3e5) {
|
|
11
11
|
this.ttlMs = e;
|
|
@@ -29,10 +29,10 @@ var e = "\x1B[0m", t = "\x1B[34m", n = () => typeof window < "u", r = () => type
|
|
|
29
29
|
has(e) {
|
|
30
30
|
return this.get(e) !== void 0;
|
|
31
31
|
}
|
|
32
|
-
}, s = `${
|
|
33
|
-
function c(
|
|
34
|
-
|
|
35
|
-
let
|
|
32
|
+
}, n = "\x1B[0m", r = "\x1B[34m", i = () => typeof window < "u", a = () => typeof window > "u", o = () => i() && window.self !== window.top, s = `${r}[Localess:Client]${n}`;
|
|
33
|
+
function c(n) {
|
|
34
|
+
n.debug && console.log(s, "Client Options : ", n);
|
|
35
|
+
let r = n.origin.replace(/\/+$/, ""), i = {
|
|
36
36
|
redirect: "follow",
|
|
37
37
|
headers: {
|
|
38
38
|
"Content-Type": "application/json",
|
|
@@ -40,75 +40,75 @@ function c(e) {
|
|
|
40
40
|
"X-Localess-Agent": "Localess-JS-Client",
|
|
41
41
|
"X-Localess-Agent-Version": "0.9.0"
|
|
42
42
|
}
|
|
43
|
-
},
|
|
43
|
+
}, a = n.cacheTTL === !1 ? new e() : new t(n.cacheTTL);
|
|
44
44
|
return {
|
|
45
|
-
async getLinks(
|
|
46
|
-
|
|
47
|
-
let
|
|
48
|
-
|
|
45
|
+
async getLinks(e) {
|
|
46
|
+
n.debug && console.log(s, "getLinks() params : ", JSON.stringify(e));
|
|
47
|
+
let t = "";
|
|
48
|
+
e?.kind && (t = `&kind=${e.kind}`);
|
|
49
49
|
let o = "";
|
|
50
|
-
|
|
50
|
+
e?.parentSlug && (o = `&parentSlug=${e.parentSlug}`);
|
|
51
51
|
let c = "";
|
|
52
|
-
|
|
53
|
-
let l = `${
|
|
54
|
-
if (
|
|
52
|
+
e?.excludeChildren && (c = `&excludeChildren=${e.excludeChildren}`);
|
|
53
|
+
let l = `${r}/api/v1/spaces/${n.spaceId}/links?token=${n.token}${t}${o}${c}`;
|
|
54
|
+
if (n.debug && console.log(s, "getLinks fetch url : ", l), a.has(l)) return n.debug && console.log(s, "getLinks cache hit"), a.get(l);
|
|
55
55
|
try {
|
|
56
|
-
let
|
|
57
|
-
|
|
58
|
-
let
|
|
59
|
-
return
|
|
56
|
+
let e = await fetch(l, i);
|
|
57
|
+
n.debug && console.log(s, "getLinks status : ", e.status);
|
|
58
|
+
let t = await e.json();
|
|
59
|
+
return a.set(l, t), t;
|
|
60
60
|
} catch (e) {
|
|
61
61
|
return console.error(s, "getLinks error : ", e), {};
|
|
62
62
|
}
|
|
63
63
|
},
|
|
64
|
-
async getContentBySlug(
|
|
65
|
-
|
|
64
|
+
async getContentBySlug(e, t) {
|
|
65
|
+
n.debug && (console.log(s, "getContentBySlug() slug : ", e), console.log(s, "getContentBySlug() params : ", JSON.stringify(t)));
|
|
66
66
|
let o = "";
|
|
67
|
-
|
|
68
|
-
let c =
|
|
69
|
-
if (
|
|
67
|
+
n?.version && n.version == "draft" && (o = `&version=${n.version}`), t?.version && t.version == "draft" && (o = `&version=${t.version}`);
|
|
68
|
+
let c = t?.locale ? `&locale=${t.locale}` : "", l = t?.resolveReference ? `&resolveReference=${t.resolveReference}` : "", u = t?.resolveLink ? `&resolveLink=${t.resolveLink}` : "", d = `${r}/api/v1/spaces/${n.spaceId}/contents/slugs/${e}?token=${n.token}${o}${c}${l}${u}`;
|
|
69
|
+
if (n.debug && console.log(s, "getContentBySlug fetch url : ", d), a.has(d)) return n.debug && console.log(s, "getContentBySlug cache hit"), a.get(d);
|
|
70
70
|
try {
|
|
71
|
-
let
|
|
72
|
-
|
|
73
|
-
let
|
|
74
|
-
return
|
|
71
|
+
let e = await fetch(d, i);
|
|
72
|
+
n.debug && console.log(s, "getContentBySlug status : ", e.status);
|
|
73
|
+
let t = await e.json();
|
|
74
|
+
return a.set(d, t), t;
|
|
75
75
|
} catch (e) {
|
|
76
76
|
return console.error(s, "getContentBySlug error : ", e), {};
|
|
77
77
|
}
|
|
78
78
|
},
|
|
79
|
-
async getContentById(
|
|
80
|
-
|
|
79
|
+
async getContentById(e, t) {
|
|
80
|
+
n.debug && (console.log(s, "getContentById() id : ", e), console.log(s, "getContentById() params : ", JSON.stringify(t)));
|
|
81
81
|
let o = "";
|
|
82
|
-
|
|
83
|
-
let c =
|
|
84
|
-
if (
|
|
82
|
+
n?.version && n.version == "draft" && (o = `&version=${n.version}`), t?.version && t.version == "draft" && (o = `&version=${t.version}`);
|
|
83
|
+
let c = t?.locale ? `&locale=${t.locale}` : "", l = t?.resolveReference ? `&resolveReference=${t.resolveReference}` : "", u = t?.resolveLink ? `&resolveLink=${t.resolveLink}` : "", d = `${r}/api/v1/spaces/${n.spaceId}/contents/${e}?token=${n.token}${o}${c}${l}${u}`;
|
|
84
|
+
if (n.debug && console.log(s, "getContentById fetch url : ", d), a.has(d)) return n.debug && console.log(s, "getContentById cache hit"), a.get(d);
|
|
85
85
|
try {
|
|
86
|
-
let
|
|
87
|
-
|
|
88
|
-
let
|
|
89
|
-
return
|
|
86
|
+
let e = await fetch(d, i);
|
|
87
|
+
n.debug && console.log(s, "getContentById status : ", e.status);
|
|
88
|
+
let t = await e.json();
|
|
89
|
+
return a.set(d, t), t;
|
|
90
90
|
} catch (e) {
|
|
91
91
|
return console.error(s, "getContentById error : ", e), {};
|
|
92
92
|
}
|
|
93
93
|
},
|
|
94
|
-
async getTranslations(
|
|
95
|
-
|
|
96
|
-
let
|
|
97
|
-
if (
|
|
94
|
+
async getTranslations(e) {
|
|
95
|
+
n.debug && console.log(s, "getTranslations() locale : ", e);
|
|
96
|
+
let t = `${r}/api/v1/spaces/${n.spaceId}/translations/${e}?token=${n.token}`;
|
|
97
|
+
if (n.debug && console.log(s, "getTranslations fetch url : ", t), a.has(t)) return n.debug && console.log(s, "getTranslations cache hit"), a.get(t);
|
|
98
98
|
try {
|
|
99
|
-
let
|
|
100
|
-
|
|
101
|
-
let
|
|
102
|
-
return
|
|
99
|
+
let e = await fetch(t, i);
|
|
100
|
+
n.debug && console.log(s, "getTranslations status : ", e.status);
|
|
101
|
+
let r = await e.json();
|
|
102
|
+
return a.set(t, r), r;
|
|
103
103
|
} catch (e) {
|
|
104
104
|
return console.error(s, "getTranslations error : ", e), {};
|
|
105
105
|
}
|
|
106
106
|
},
|
|
107
107
|
syncScriptUrl() {
|
|
108
|
-
return `${
|
|
108
|
+
return `${r}/scripts/sync-v1.js`;
|
|
109
109
|
},
|
|
110
|
-
assetLink(
|
|
111
|
-
return typeof
|
|
110
|
+
assetLink(e) {
|
|
111
|
+
return typeof e == "string" ? `${r}/api/v1/spaces/${n.spaceId}/assets/${e}` : `${r}/api/v1/spaces/${n.spaceId}/assets/${e.uri}`;
|
|
112
112
|
}
|
|
113
113
|
};
|
|
114
114
|
}
|
|
@@ -128,11 +128,11 @@ function u(e) {
|
|
|
128
128
|
var d = "localess-js-sync";
|
|
129
129
|
async function f(e, t = !1) {
|
|
130
130
|
return new Promise((t, n) => {
|
|
131
|
-
if (
|
|
131
|
+
if (a()) {
|
|
132
132
|
n(void 0);
|
|
133
133
|
return;
|
|
134
134
|
}
|
|
135
|
-
if (!
|
|
135
|
+
if (!o()) {
|
|
136
136
|
console.warn("Localess Sync is loaded only in Visual Editor."), n(void 0);
|
|
137
137
|
return;
|
|
138
138
|
}
|
|
@@ -144,11 +144,11 @@ async function f(e, t = !1) {
|
|
|
144
144
|
n(void 0);
|
|
145
145
|
return;
|
|
146
146
|
}
|
|
147
|
-
let
|
|
148
|
-
|
|
147
|
+
let r = document.createElement("script");
|
|
148
|
+
r.id = d, r.type = "text/javascript", r.src = `${e}/scripts/sync-v1.js`, r.async = !0, r.onerror = (e) => n(e), r.onload = (e) => {
|
|
149
149
|
console.info("Localess Sync Script loaded"), t();
|
|
150
|
-
}, document.head.appendChild(
|
|
150
|
+
}, document.head.appendChild(r);
|
|
151
151
|
});
|
|
152
152
|
}
|
|
153
153
|
//#endregion
|
|
154
|
-
export {
|
|
154
|
+
export { i as isBrowser, o as isIframe, a as isServer, f as loadLocalessSync, c as localessClient, l as localessEditable, u as localessEditableField };
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { ContentAsset } from './content-asset';
|
|
2
2
|
import { ContentLink } from './content-link';
|
|
3
|
-
import { ContentRichText } from './content-rich-text';
|
|
4
3
|
import { ContentReference } from './content-reference';
|
|
4
|
+
import { ContentRichText } from './content-rich-text';
|
|
5
5
|
export type ContentDataField = any | string | string[] | number | boolean | ContentLink | ContentRichText | ContentData | ContentData[] | ContentAsset | ContentAsset[] | ContentReference | ContentReference[];
|
|
6
6
|
/**
|
|
7
7
|
* Content Data Schema related information.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@localess/client",
|
|
3
|
-
"version": "3.0.5-dev.
|
|
3
|
+
"version": "3.0.5-dev.20260501214755",
|
|
4
4
|
"description": "Universal JavaScript/TypeScript SDK for Localess's API.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"localess",
|
|
@@ -43,7 +43,7 @@
|
|
|
43
43
|
"@types/node": "^20",
|
|
44
44
|
"typescript": "^5.0.0",
|
|
45
45
|
"vite": "^8.0.10",
|
|
46
|
-
"vite-plugin-dts": "^
|
|
46
|
+
"vite-plugin-dts": "^5.0.0"
|
|
47
47
|
},
|
|
48
48
|
"engines": {
|
|
49
49
|
"node": ">= 20.0.0"
|