@localess/client 3.2.1 → 3.2.2-dev.20260611122555
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/SKILL.md +11 -2
- package/dist/client.d.ts +9 -1
- package/dist/index.js +1 -1
- package/dist/index.mjs +9 -7
- package/package.json +1 -1
package/SKILL.md
CHANGED
|
@@ -74,6 +74,9 @@ const links = await client.getLinks({
|
|
|
74
74
|
const t = await client.getTranslations('en');
|
|
75
75
|
// t: { [key: string]: string }
|
|
76
76
|
// Usage: t['common.submit'] => 'Submit'
|
|
77
|
+
|
|
78
|
+
// Fetch draft translations
|
|
79
|
+
const t = await client.getTranslations('en', { version: 'draft' });
|
|
77
80
|
```
|
|
78
81
|
|
|
79
82
|
### Asset URL
|
|
@@ -113,7 +116,7 @@ SVG files are always passed through unchanged. `w`/`h`/`f` are ignored for SVG.
|
|
|
113
116
|
|
|
114
117
|
---
|
|
115
118
|
|
|
116
|
-
## Content Fetch Parameters
|
|
119
|
+
## Content Fetch Parameters (`ContentFetchParams`)
|
|
117
120
|
|
|
118
121
|
| Parameter | Type | Default | Description |
|
|
119
122
|
|--------------------|------------------------|-------------|-------------------------------------------|
|
|
@@ -122,6 +125,12 @@ SVG files are always passed through unchanged. `w`/`h`/`f` are ignored for SVG.
|
|
|
122
125
|
| `resolveReference` | `boolean` | `false` | Inline referenced content objects |
|
|
123
126
|
| `resolveLink` | `boolean` | `false` | Inline linked content metadata |
|
|
124
127
|
|
|
128
|
+
## Translation Fetch Parameters (`TranslationFetchParams`)
|
|
129
|
+
|
|
130
|
+
| Parameter | Type | Default | Description |
|
|
131
|
+
|-----------|------------------------|-------------|-------------------------------------------|
|
|
132
|
+
| `version` | `'draft' \| undefined` | `undefined` | `'draft'` for preview, omit for published |
|
|
133
|
+
|
|
125
134
|
---
|
|
126
135
|
|
|
127
136
|
## Caching
|
|
@@ -320,7 +329,7 @@ export { isBrowser, isServer, isIframe } // Environment utilities
|
|
|
320
329
|
export { buildAssetQueryString } // Asset query string serialiser
|
|
321
330
|
export type {
|
|
322
331
|
LocalessClient, LocalessClientOptions,
|
|
323
|
-
ContentFetchParams, LinksFetchParams,
|
|
332
|
+
ContentFetchParams, LinksFetchParams, TranslationFetchParams,
|
|
324
333
|
Content, ContentData, ContentDataSchema, ContentDataField,
|
|
325
334
|
ContentMetadata, ContentAsset, ContentLink,
|
|
326
335
|
ContentRichText, ContentReference,
|
package/dist/client.d.ts
CHANGED
|
@@ -55,6 +55,13 @@ export type LinksFetchParams = {
|
|
|
55
55
|
*/
|
|
56
56
|
excludeChildren?: boolean;
|
|
57
57
|
};
|
|
58
|
+
export type TranslationFetchParams = {
|
|
59
|
+
/**
|
|
60
|
+
* Translation version to fetch, leave empty for 'published' or 'draft' for the latest draft.
|
|
61
|
+
* Overrides the version set in the client options.
|
|
62
|
+
*/
|
|
63
|
+
version?: 'draft';
|
|
64
|
+
};
|
|
58
65
|
export type ContentFetchParams = {
|
|
59
66
|
/**
|
|
60
67
|
* Content version to fetch, leave empty for 'published' or 'draft' for the latest draft.
|
|
@@ -107,8 +114,9 @@ export interface LocalessClient {
|
|
|
107
114
|
/**
|
|
108
115
|
* Get translations for the given locale
|
|
109
116
|
* @param locale{string} - Locale identifier (ISO 639-1)
|
|
117
|
+
* @param params{TranslationFetchParams} - Fetch parameters
|
|
110
118
|
*/
|
|
111
|
-
getTranslations(locale: string): Promise<Translations>;
|
|
119
|
+
getTranslations(locale: string, params?: TranslationFetchParams): Promise<Translations>;
|
|
112
120
|
syncScriptUrl(): string;
|
|
113
121
|
assetLink(asset: ContentAsset | string, params?: AssetTransformParams): string;
|
|
114
122
|
}
|
package/dist/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
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;function c(e){if(!e)return``;let t=[];return e.w!==void 0&&t.push(`w=${e.w}`),e.h!==void 0&&t.push(`h=${e.h}`),e.q!==void 0&&t.push(`q=${e.q}`),e.f!==void 0&&t.push(`f=${e.f}`),e.download&&t.push(`download`),e.thumbnail&&t.push(`thumbnail`),t.join(`&`)}var l=`${i}[Localess:Client]${r}`;function u(e){e.debug&&console.log(l,`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(l,`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 c=`${r}/api/v1/spaces/${e.spaceId}/links?token=${e.token}${n}${a}${s}`;if(e.debug&&console.log(l,`getLinks fetch url : `,c),o.has(c))return e.debug&&console.log(l,`getLinks cache hit`),o.get(c);try{let t=await fetch(c,i);e.debug&&console.log(l,`getLinks status : `,t.status);let n=await t.json();return o.set(c,n),n}catch(e){return console.error(l,`getLinks error : `,e),{}}},async getContentBySlug(t,n){e.debug&&(console.log(l,`getContentBySlug() slug : `,t),console.log(l,`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}`:``,c=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}${c}${u}`;if(e.debug&&console.log(l,`getContentBySlug fetch url : `,d),o.has(d))return e.debug&&console.log(l,`getContentBySlug cache hit`),o.get(d);try{let t=await fetch(d,i);e.debug&&console.log(l,`getContentBySlug status : `,t.status);let n=await t.json();return o.set(d,n),n}catch(e){return console.error(l,`getContentBySlug error : `,e),{}}},async getContentById(t,n){e.debug&&(console.log(l,`getContentById() id : `,t),console.log(l,`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}`:``,c=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}${c}${u}`;if(e.debug&&console.log(l,`getContentById fetch url : `,d),o.has(d))return e.debug&&console.log(l,`getContentById cache hit`),o.get(d);try{let t=await fetch(d,i);e.debug&&console.log(l,`getContentById status : `,t.status);let n=await t.json();return o.set(d,n),n}catch(e){return console.error(l,`getContentById error : `,e),{}}},async getTranslations(t){e.debug&&console.log(l,`getTranslations() locale : `,t);let n=`${r}/api/v1/spaces/${e.spaceId}/translations/${t}?token=${e.token}`;if(e.debug&&console.log(l,`getTranslations fetch url : `,
|
|
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;function c(e){if(!e)return``;let t=[];return e.w!==void 0&&t.push(`w=${e.w}`),e.h!==void 0&&t.push(`h=${e.h}`),e.q!==void 0&&t.push(`q=${e.q}`),e.f!==void 0&&t.push(`f=${e.f}`),e.download&&t.push(`download`),e.thumbnail&&t.push(`thumbnail`),t.join(`&`)}var l=`${i}[Localess:Client]${r}`;function u(e){e.debug&&console.log(l,`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(l,`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 c=`${r}/api/v1/spaces/${e.spaceId}/links?token=${e.token}${n}${a}${s}`;if(e.debug&&console.log(l,`getLinks fetch url : `,c),o.has(c))return e.debug&&console.log(l,`getLinks cache hit`),o.get(c);try{let t=await fetch(c,i);e.debug&&console.log(l,`getLinks status : `,t.status);let n=await t.json();return o.set(c,n),n}catch(e){return console.error(l,`getLinks error : `,e),{}}},async getContentBySlug(t,n){e.debug&&(console.log(l,`getContentBySlug() slug : `,t),console.log(l,`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}`:``,c=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}${c}${u}`;if(e.debug&&console.log(l,`getContentBySlug fetch url : `,d),o.has(d))return e.debug&&console.log(l,`getContentBySlug cache hit`),o.get(d);try{let t=await fetch(d,i);e.debug&&console.log(l,`getContentBySlug status : `,t.status);let n=await t.json();return o.set(d,n),n}catch(e){return console.error(l,`getContentBySlug error : `,e),{}}},async getContentById(t,n){e.debug&&(console.log(l,`getContentById() id : `,t),console.log(l,`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}`:``,c=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}${c}${u}`;if(e.debug&&console.log(l,`getContentById fetch url : `,d),o.has(d))return e.debug&&console.log(l,`getContentById cache hit`),o.get(d);try{let t=await fetch(d,i);e.debug&&console.log(l,`getContentById status : `,t.status);let n=await t.json();return o.set(d,n),n}catch(e){return console.error(l,`getContentById error : `,e),{}}},async getTranslations(t,n){e.debug&&(console.log(l,`getTranslations() locale : `,t),console.log(l,`getTranslations() 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=`${r}/api/v1/spaces/${e.spaceId}/translations/${t}?token=${e.token}${a}`;if(e.debug&&console.log(l,`getTranslations fetch url : `,s),o.has(s))return e.debug&&console.log(l,`getTranslations cache hit`),o.get(s);try{let t=await fetch(s,i);e.debug&&console.log(l,`getTranslations status : `,t.status);let n=await t.json();return o.set(s,n),n}catch(e){return console.error(l,`getTranslations error : `,e),{}}},syncScriptUrl(){return`${r}/scripts/sync-v1.js`},assetLink(t,n){let i=typeof t==`string`?t:t.uri,a=`${r}/api/v1/spaces/${e.spaceId}/assets/${i}`,o=c(n);return o?`${a}?${o}`:a}}}function d(e){return{"data-ll-id":e._id,"data-ll-schema":e._schema}}function f(e){return{"data-ll-field":e}}var p=`localess-js-sync`;async function m(e,t=!1){return new Promise((t,n)=>{if(o()){t();return}if(!s()){console.warn(`Localess Sync is loaded only in Visual Editor.`),t();return}if(window.localess!==void 0){t();return}if(document.getElementById(p)){t();return}let r=document.createElement(`script`);r.id=p,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.buildAssetQueryString=c,exports.isBrowser=a,exports.isIframe=s,exports.isServer=o,exports.loadLocalessSync=m,exports.localessClient=u,exports.localessEditable=d,exports.localessEditableField=f;
|
package/dist/index.mjs
CHANGED
|
@@ -110,15 +110,17 @@ function u(e) {
|
|
|
110
110
|
return console.error(l, "getContentById error : ", e), {};
|
|
111
111
|
}
|
|
112
112
|
},
|
|
113
|
-
async getTranslations(t) {
|
|
114
|
-
e.debug && console.log(l, "getTranslations() locale : ", t);
|
|
115
|
-
let
|
|
116
|
-
|
|
113
|
+
async getTranslations(t, n) {
|
|
114
|
+
e.debug && (console.log(l, "getTranslations() locale : ", t), console.log(l, "getTranslations() params : ", JSON.stringify(n)));
|
|
115
|
+
let a = "";
|
|
116
|
+
e?.version && e.version == "draft" && (a = `&version=${e.version}`), n?.version && n.version == "draft" && (a = `&version=${n.version}`);
|
|
117
|
+
let s = `${r}/api/v1/spaces/${e.spaceId}/translations/${t}?token=${e.token}${a}`;
|
|
118
|
+
if (e.debug && console.log(l, "getTranslations fetch url : ", s), o.has(s)) return e.debug && console.log(l, "getTranslations cache hit"), o.get(s);
|
|
117
119
|
try {
|
|
118
|
-
let t = await fetch(
|
|
120
|
+
let t = await fetch(s, i);
|
|
119
121
|
e.debug && console.log(l, "getTranslations status : ", t.status);
|
|
120
|
-
let
|
|
121
|
-
return o.set(
|
|
122
|
+
let n = await t.json();
|
|
123
|
+
return o.set(s, n), n;
|
|
122
124
|
} catch (e) {
|
|
123
125
|
return console.error(l, "getTranslations error : ", e), {};
|
|
124
126
|
}
|