@localess/js-client 0.3.2-next.20250108-112722.0 → 0.3.2-next.20250109-090340.0
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.mts +272 -0
- package/dist/index.d.ts +260 -9
- package/dist/index.js +215 -5
- package/dist/index.mjs +186 -0
- package/package.json +8 -11
- package/dist/cjs/client.d.ts +0 -88
- package/dist/cjs/client.js +0 -165
- package/dist/cjs/client.js.map +0 -1
- package/dist/cjs/editable.d.ts +0 -5
- package/dist/cjs/editable.js +0 -11
- package/dist/cjs/editable.js.map +0 -1
- package/dist/cjs/index.d.ts +0 -21
- package/dist/cjs/index.js +0 -21
- package/dist/cjs/index.js.map +0 -1
- package/dist/cjs/models/content-asset.d.ts +0 -13
- package/dist/cjs/models/content-asset.js +0 -3
- package/dist/cjs/models/content-asset.js.map +0 -1
- package/dist/cjs/models/content-data.d.ts +0 -27
- package/dist/cjs/models/content-data.js +0 -3
- package/dist/cjs/models/content-data.js.map +0 -1
- package/dist/cjs/models/content-link.d.ts +0 -21
- package/dist/cjs/models/content-link.js +0 -3
- package/dist/cjs/models/content-link.js.map +0 -1
- package/dist/cjs/models/content-metadata.d.ts +0 -41
- package/dist/cjs/models/content-metadata.js +0 -3
- package/dist/cjs/models/content-metadata.js.map +0 -1
- package/dist/cjs/models/content-reference.d.ts +0 -13
- package/dist/cjs/models/content-reference.js +0 -3
- package/dist/cjs/models/content-reference.js.map +0 -1
- package/dist/cjs/models/content-rich-text.d.ts +0 -13
- package/dist/cjs/models/content-rich-text.js +0 -3
- package/dist/cjs/models/content-rich-text.js.map +0 -1
- package/dist/cjs/models/content.d.ts +0 -11
- package/dist/cjs/models/content.js +0 -3
- package/dist/cjs/models/content.js.map +0 -1
- package/dist/cjs/models/index.d.ts +0 -9
- package/dist/cjs/models/index.js +0 -26
- package/dist/cjs/models/index.js.map +0 -1
- package/dist/cjs/models/links.d.ts +0 -7
- package/dist/cjs/models/links.js +0 -3
- package/dist/cjs/models/links.js.map +0 -1
- package/dist/cjs/models/translations.d.ts +0 -6
- package/dist/cjs/models/translations.js +0 -3
- package/dist/cjs/models/translations.js.map +0 -1
- package/dist/cjs/sync.d.ts +0 -6
- package/dist/cjs/sync.js +0 -32
- package/dist/cjs/sync.js.map +0 -1
- package/dist/cjs/utils.d.ts +0 -40
- package/dist/cjs/utils.js +0 -51
- package/dist/cjs/utils.js.map +0 -1
- package/dist/client.d.ts +0 -88
- package/dist/client.js +0 -161
- package/dist/client.js.map +0 -1
- package/dist/editable.d.ts +0 -5
- package/dist/editable.js +0 -7
- package/dist/editable.js.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/models/content-asset.d.ts +0 -13
- package/dist/models/content-asset.js +0 -2
- package/dist/models/content-asset.js.map +0 -1
- package/dist/models/content-data.d.ts +0 -27
- package/dist/models/content-data.js +0 -2
- package/dist/models/content-data.js.map +0 -1
- package/dist/models/content-link.d.ts +0 -21
- package/dist/models/content-link.js +0 -2
- package/dist/models/content-link.js.map +0 -1
- package/dist/models/content-metadata.d.ts +0 -41
- package/dist/models/content-metadata.js +0 -2
- package/dist/models/content-metadata.js.map +0 -1
- package/dist/models/content-reference.d.ts +0 -13
- package/dist/models/content-reference.js +0 -2
- package/dist/models/content-reference.js.map +0 -1
- package/dist/models/content-rich-text.d.ts +0 -13
- package/dist/models/content-rich-text.js +0 -2
- package/dist/models/content-rich-text.js.map +0 -1
- package/dist/models/content.d.ts +0 -11
- package/dist/models/content.js +0 -2
- package/dist/models/content.js.map +0 -1
- package/dist/models/index.d.ts +0 -9
- package/dist/models/index.js +0 -10
- package/dist/models/index.js.map +0 -1
- package/dist/models/links.d.ts +0 -7
- package/dist/models/links.js +0 -2
- package/dist/models/links.js.map +0 -1
- package/dist/models/translations.d.ts +0 -6
- package/dist/models/translations.js +0 -2
- package/dist/models/translations.js.map +0 -1
- package/dist/sync.d.ts +0 -6
- package/dist/sync.js +0 -28
- package/dist/sync.js.map +0 -1
- package/dist/utils.d.ts +0 -40
- package/dist/utils.js +0 -47
- package/dist/utils.js.map +0 -1
package/dist/index.js
CHANGED
|
@@ -1,5 +1,215 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/index.ts
|
|
21
|
+
var index_exports = {};
|
|
22
|
+
__export(index_exports, {
|
|
23
|
+
llEditable: () => llEditable,
|
|
24
|
+
loadLocalessSync: () => loadLocalessSync,
|
|
25
|
+
localessClient: () => localessClient
|
|
26
|
+
});
|
|
27
|
+
module.exports = __toCommonJS(index_exports);
|
|
28
|
+
|
|
29
|
+
// src/utils.ts
|
|
30
|
+
var RESET = "\x1B[0m";
|
|
31
|
+
var FG_BLUE = "\x1B[34m";
|
|
32
|
+
|
|
33
|
+
// src/client.ts
|
|
34
|
+
var LOG_GROUP = `${FG_BLUE}[Localess:Client]${RESET}`;
|
|
35
|
+
function localessClient(options) {
|
|
36
|
+
if (options.debug) {
|
|
37
|
+
console.log(LOG_GROUP, "Client Options : ", options);
|
|
38
|
+
}
|
|
39
|
+
const fetchOptions = {
|
|
40
|
+
redirect: "follow",
|
|
41
|
+
headers: {
|
|
42
|
+
"Content-Type": "application/json",
|
|
43
|
+
"Accept": "application/json",
|
|
44
|
+
"X-Localess-Agent": "Localess-JS-Client",
|
|
45
|
+
"X-Localess-Agent-Version": "0.3.0"
|
|
46
|
+
}
|
|
47
|
+
};
|
|
48
|
+
return {
|
|
49
|
+
/**
|
|
50
|
+
* Get all links
|
|
51
|
+
* @param params{LinksFetchParams} - Fetch parameters
|
|
52
|
+
* @returns {Promise<Links>}
|
|
53
|
+
*/
|
|
54
|
+
async getLinks(params) {
|
|
55
|
+
if (options.debug) {
|
|
56
|
+
console.log(LOG_GROUP, "getLinks() params : " + params);
|
|
57
|
+
}
|
|
58
|
+
let kind = "";
|
|
59
|
+
if (params?.kind) {
|
|
60
|
+
kind = `&kind=${params.kind}`;
|
|
61
|
+
}
|
|
62
|
+
let parentSlug = "";
|
|
63
|
+
if (params?.parentSlug) {
|
|
64
|
+
parentSlug = `&parentSlug=${params.parentSlug}`;
|
|
65
|
+
}
|
|
66
|
+
let excludeChildren = "";
|
|
67
|
+
if (params?.excludeChildren) {
|
|
68
|
+
excludeChildren = `&excludeChildren=${params.excludeChildren}`;
|
|
69
|
+
}
|
|
70
|
+
let url = `${options.origin}/api/v1/spaces/${options.spaceId}/links?token=${options.token}${kind}${parentSlug}${excludeChildren}`;
|
|
71
|
+
if (options.debug) {
|
|
72
|
+
console.log(LOG_GROUP, "getLinks fetch url : ", url);
|
|
73
|
+
}
|
|
74
|
+
try {
|
|
75
|
+
const response = await fetch(url, fetchOptions);
|
|
76
|
+
if (options.debug) {
|
|
77
|
+
console.log(LOG_GROUP, "getLinks status : ", response.status);
|
|
78
|
+
}
|
|
79
|
+
const data = await response.json();
|
|
80
|
+
return data;
|
|
81
|
+
} catch (error) {
|
|
82
|
+
console.error(LOG_GROUP, "getLinks error : ", error);
|
|
83
|
+
return {};
|
|
84
|
+
}
|
|
85
|
+
},
|
|
86
|
+
/**
|
|
87
|
+
* Get content by SLUG
|
|
88
|
+
* @param slug{string} - Content SLUG
|
|
89
|
+
* @param params{ContentFetchParams} - Fetch parameters
|
|
90
|
+
* @returns {Promise<Content>}
|
|
91
|
+
*/
|
|
92
|
+
async getContentBySlug(slug, params) {
|
|
93
|
+
if (options.debug) {
|
|
94
|
+
console.log(LOG_GROUP, "getContentBySlug() slug : ", slug);
|
|
95
|
+
console.log(LOG_GROUP, "getContentBySlug() params : ", params);
|
|
96
|
+
}
|
|
97
|
+
let version = "";
|
|
98
|
+
if (options?.version && options.version == "draft") {
|
|
99
|
+
version = `&version=${options.version}`;
|
|
100
|
+
}
|
|
101
|
+
if (params?.version && params.version == "draft") {
|
|
102
|
+
version = `&version=${params.version}`;
|
|
103
|
+
}
|
|
104
|
+
const locale = params?.locale ? `&locale=${params.locale}` : "";
|
|
105
|
+
let url = `${options.origin}/api/v1/spaces/${options.spaceId}/contents/slugs/${slug}?token=${options.token}${version}${locale}`;
|
|
106
|
+
if (options.debug) {
|
|
107
|
+
console.log(LOG_GROUP, "getContentBySlug fetch url : ", url);
|
|
108
|
+
}
|
|
109
|
+
try {
|
|
110
|
+
const response = await fetch(url, fetchOptions);
|
|
111
|
+
if (options.debug) {
|
|
112
|
+
console.log(LOG_GROUP, "getContentBySlug status : ", response.status);
|
|
113
|
+
}
|
|
114
|
+
const data = await response.json();
|
|
115
|
+
return data;
|
|
116
|
+
} catch (error) {
|
|
117
|
+
console.error(LOG_GROUP, "getContentBySlug error : ", error);
|
|
118
|
+
return {};
|
|
119
|
+
}
|
|
120
|
+
},
|
|
121
|
+
/**
|
|
122
|
+
* Get content by ID
|
|
123
|
+
* @param id{string} - Content ID
|
|
124
|
+
* @param params{ContentFetchParams} - Fetch parameters
|
|
125
|
+
* @returns {Promise<Content>}
|
|
126
|
+
*/
|
|
127
|
+
async getContentById(id, params) {
|
|
128
|
+
if (options.debug) {
|
|
129
|
+
console.log(LOG_GROUP, "getContentById() id : ", id);
|
|
130
|
+
console.log(LOG_GROUP, "getContentById() params : ", params);
|
|
131
|
+
}
|
|
132
|
+
let version = "";
|
|
133
|
+
if (options?.version && options.version == "draft") {
|
|
134
|
+
version = `&version=${options.version}`;
|
|
135
|
+
}
|
|
136
|
+
if (params?.version && params.version == "draft") {
|
|
137
|
+
version = `&version=${params.version}`;
|
|
138
|
+
}
|
|
139
|
+
const locale = params?.locale ? `&locale=${params.locale}` : "";
|
|
140
|
+
let url = `${options.origin}/api/v1/spaces/${options.spaceId}/contents/${id}?token=${options.token}${version}${locale}`;
|
|
141
|
+
if (options.debug) {
|
|
142
|
+
console.log(LOG_GROUP, "getContentById fetch url : ", url);
|
|
143
|
+
}
|
|
144
|
+
const response = await fetch(url, fetchOptions);
|
|
145
|
+
if (options.debug) {
|
|
146
|
+
console.log(LOG_GROUP, "getContentById status : ", response.status);
|
|
147
|
+
}
|
|
148
|
+
const data = await response.json();
|
|
149
|
+
return data;
|
|
150
|
+
},
|
|
151
|
+
/**
|
|
152
|
+
* Get translations for the given locale
|
|
153
|
+
* @param locale{string} - Locale identifier (ISO 639-1)
|
|
154
|
+
*/
|
|
155
|
+
async getTranslations(locale) {
|
|
156
|
+
if (options.debug) {
|
|
157
|
+
console.log(LOG_GROUP, "getTranslations() locale : ", locale);
|
|
158
|
+
}
|
|
159
|
+
let url = `${options.origin}/api/v1/spaces/${options.spaceId}/translations/${locale}`;
|
|
160
|
+
if (options.debug) {
|
|
161
|
+
console.log(LOG_GROUP, "getTranslations fetch url : ", url);
|
|
162
|
+
}
|
|
163
|
+
const response = await fetch(url, fetchOptions);
|
|
164
|
+
if (options.debug) {
|
|
165
|
+
console.log(LOG_GROUP, "getTranslations status : ", response.status);
|
|
166
|
+
}
|
|
167
|
+
const data = await response.json();
|
|
168
|
+
return data;
|
|
169
|
+
},
|
|
170
|
+
syncScriptUrl() {
|
|
171
|
+
return `${options.origin}/scripts/sync-v1.js`;
|
|
172
|
+
},
|
|
173
|
+
assetLink(asset) {
|
|
174
|
+
if (typeof asset === "string") {
|
|
175
|
+
return `${options.origin}/api/v1/spaces/${options.spaceId}/assets/${asset}`;
|
|
176
|
+
} else {
|
|
177
|
+
return `${options.origin}/api/v1/spaces/${options.spaceId}/assets/${asset.uri}`;
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
};
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
// src/editable.ts
|
|
184
|
+
function llEditable(content) {
|
|
185
|
+
return {
|
|
186
|
+
"data-ll-id": content._id,
|
|
187
|
+
"data-ll-schema": content.schema
|
|
188
|
+
};
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
// src/sync.ts
|
|
192
|
+
var JS_SYNC_ID = "localess-js-sync";
|
|
193
|
+
function loadLocalessSync(origin, force = false) {
|
|
194
|
+
const isServer = typeof window === "undefined";
|
|
195
|
+
if (isServer) return;
|
|
196
|
+
if (window.top === window.self) return;
|
|
197
|
+
const isSyncLoaded = typeof window.localess !== "undefined";
|
|
198
|
+
if (isSyncLoaded) return;
|
|
199
|
+
const scriptEl = document.getElementById(JS_SYNC_ID);
|
|
200
|
+
if (scriptEl) return;
|
|
201
|
+
const script = document.createElement("script");
|
|
202
|
+
script.id = JS_SYNC_ID;
|
|
203
|
+
script.type = "text/javascript";
|
|
204
|
+
script.src = `${origin}/scripts/sync-v1.js`;
|
|
205
|
+
script.async = true;
|
|
206
|
+
script.onerror = (error) => console.error(error);
|
|
207
|
+
script.onload = (event) => console.info("Localess Sync Script loaded");
|
|
208
|
+
document.head.appendChild(script);
|
|
209
|
+
}
|
|
210
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
211
|
+
0 && (module.exports = {
|
|
212
|
+
llEditable,
|
|
213
|
+
loadLocalessSync,
|
|
214
|
+
localessClient
|
|
215
|
+
});
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,186 @@
|
|
|
1
|
+
// src/utils.ts
|
|
2
|
+
var RESET = "\x1B[0m";
|
|
3
|
+
var FG_BLUE = "\x1B[34m";
|
|
4
|
+
|
|
5
|
+
// src/client.ts
|
|
6
|
+
var LOG_GROUP = `${FG_BLUE}[Localess:Client]${RESET}`;
|
|
7
|
+
function localessClient(options) {
|
|
8
|
+
if (options.debug) {
|
|
9
|
+
console.log(LOG_GROUP, "Client Options : ", options);
|
|
10
|
+
}
|
|
11
|
+
const fetchOptions = {
|
|
12
|
+
redirect: "follow",
|
|
13
|
+
headers: {
|
|
14
|
+
"Content-Type": "application/json",
|
|
15
|
+
"Accept": "application/json",
|
|
16
|
+
"X-Localess-Agent": "Localess-JS-Client",
|
|
17
|
+
"X-Localess-Agent-Version": "0.3.0"
|
|
18
|
+
}
|
|
19
|
+
};
|
|
20
|
+
return {
|
|
21
|
+
/**
|
|
22
|
+
* Get all links
|
|
23
|
+
* @param params{LinksFetchParams} - Fetch parameters
|
|
24
|
+
* @returns {Promise<Links>}
|
|
25
|
+
*/
|
|
26
|
+
async getLinks(params) {
|
|
27
|
+
if (options.debug) {
|
|
28
|
+
console.log(LOG_GROUP, "getLinks() params : " + params);
|
|
29
|
+
}
|
|
30
|
+
let kind = "";
|
|
31
|
+
if (params?.kind) {
|
|
32
|
+
kind = `&kind=${params.kind}`;
|
|
33
|
+
}
|
|
34
|
+
let parentSlug = "";
|
|
35
|
+
if (params?.parentSlug) {
|
|
36
|
+
parentSlug = `&parentSlug=${params.parentSlug}`;
|
|
37
|
+
}
|
|
38
|
+
let excludeChildren = "";
|
|
39
|
+
if (params?.excludeChildren) {
|
|
40
|
+
excludeChildren = `&excludeChildren=${params.excludeChildren}`;
|
|
41
|
+
}
|
|
42
|
+
let url = `${options.origin}/api/v1/spaces/${options.spaceId}/links?token=${options.token}${kind}${parentSlug}${excludeChildren}`;
|
|
43
|
+
if (options.debug) {
|
|
44
|
+
console.log(LOG_GROUP, "getLinks fetch url : ", url);
|
|
45
|
+
}
|
|
46
|
+
try {
|
|
47
|
+
const response = await fetch(url, fetchOptions);
|
|
48
|
+
if (options.debug) {
|
|
49
|
+
console.log(LOG_GROUP, "getLinks status : ", response.status);
|
|
50
|
+
}
|
|
51
|
+
const data = await response.json();
|
|
52
|
+
return data;
|
|
53
|
+
} catch (error) {
|
|
54
|
+
console.error(LOG_GROUP, "getLinks error : ", error);
|
|
55
|
+
return {};
|
|
56
|
+
}
|
|
57
|
+
},
|
|
58
|
+
/**
|
|
59
|
+
* Get content by SLUG
|
|
60
|
+
* @param slug{string} - Content SLUG
|
|
61
|
+
* @param params{ContentFetchParams} - Fetch parameters
|
|
62
|
+
* @returns {Promise<Content>}
|
|
63
|
+
*/
|
|
64
|
+
async getContentBySlug(slug, params) {
|
|
65
|
+
if (options.debug) {
|
|
66
|
+
console.log(LOG_GROUP, "getContentBySlug() slug : ", slug);
|
|
67
|
+
console.log(LOG_GROUP, "getContentBySlug() params : ", params);
|
|
68
|
+
}
|
|
69
|
+
let version = "";
|
|
70
|
+
if (options?.version && options.version == "draft") {
|
|
71
|
+
version = `&version=${options.version}`;
|
|
72
|
+
}
|
|
73
|
+
if (params?.version && params.version == "draft") {
|
|
74
|
+
version = `&version=${params.version}`;
|
|
75
|
+
}
|
|
76
|
+
const locale = params?.locale ? `&locale=${params.locale}` : "";
|
|
77
|
+
let url = `${options.origin}/api/v1/spaces/${options.spaceId}/contents/slugs/${slug}?token=${options.token}${version}${locale}`;
|
|
78
|
+
if (options.debug) {
|
|
79
|
+
console.log(LOG_GROUP, "getContentBySlug fetch url : ", url);
|
|
80
|
+
}
|
|
81
|
+
try {
|
|
82
|
+
const response = await fetch(url, fetchOptions);
|
|
83
|
+
if (options.debug) {
|
|
84
|
+
console.log(LOG_GROUP, "getContentBySlug status : ", response.status);
|
|
85
|
+
}
|
|
86
|
+
const data = await response.json();
|
|
87
|
+
return data;
|
|
88
|
+
} catch (error) {
|
|
89
|
+
console.error(LOG_GROUP, "getContentBySlug error : ", error);
|
|
90
|
+
return {};
|
|
91
|
+
}
|
|
92
|
+
},
|
|
93
|
+
/**
|
|
94
|
+
* Get content by ID
|
|
95
|
+
* @param id{string} - Content ID
|
|
96
|
+
* @param params{ContentFetchParams} - Fetch parameters
|
|
97
|
+
* @returns {Promise<Content>}
|
|
98
|
+
*/
|
|
99
|
+
async getContentById(id, params) {
|
|
100
|
+
if (options.debug) {
|
|
101
|
+
console.log(LOG_GROUP, "getContentById() id : ", id);
|
|
102
|
+
console.log(LOG_GROUP, "getContentById() params : ", params);
|
|
103
|
+
}
|
|
104
|
+
let version = "";
|
|
105
|
+
if (options?.version && options.version == "draft") {
|
|
106
|
+
version = `&version=${options.version}`;
|
|
107
|
+
}
|
|
108
|
+
if (params?.version && params.version == "draft") {
|
|
109
|
+
version = `&version=${params.version}`;
|
|
110
|
+
}
|
|
111
|
+
const locale = params?.locale ? `&locale=${params.locale}` : "";
|
|
112
|
+
let url = `${options.origin}/api/v1/spaces/${options.spaceId}/contents/${id}?token=${options.token}${version}${locale}`;
|
|
113
|
+
if (options.debug) {
|
|
114
|
+
console.log(LOG_GROUP, "getContentById fetch url : ", url);
|
|
115
|
+
}
|
|
116
|
+
const response = await fetch(url, fetchOptions);
|
|
117
|
+
if (options.debug) {
|
|
118
|
+
console.log(LOG_GROUP, "getContentById status : ", response.status);
|
|
119
|
+
}
|
|
120
|
+
const data = await response.json();
|
|
121
|
+
return data;
|
|
122
|
+
},
|
|
123
|
+
/**
|
|
124
|
+
* Get translations for the given locale
|
|
125
|
+
* @param locale{string} - Locale identifier (ISO 639-1)
|
|
126
|
+
*/
|
|
127
|
+
async getTranslations(locale) {
|
|
128
|
+
if (options.debug) {
|
|
129
|
+
console.log(LOG_GROUP, "getTranslations() locale : ", locale);
|
|
130
|
+
}
|
|
131
|
+
let url = `${options.origin}/api/v1/spaces/${options.spaceId}/translations/${locale}`;
|
|
132
|
+
if (options.debug) {
|
|
133
|
+
console.log(LOG_GROUP, "getTranslations fetch url : ", url);
|
|
134
|
+
}
|
|
135
|
+
const response = await fetch(url, fetchOptions);
|
|
136
|
+
if (options.debug) {
|
|
137
|
+
console.log(LOG_GROUP, "getTranslations status : ", response.status);
|
|
138
|
+
}
|
|
139
|
+
const data = await response.json();
|
|
140
|
+
return data;
|
|
141
|
+
},
|
|
142
|
+
syncScriptUrl() {
|
|
143
|
+
return `${options.origin}/scripts/sync-v1.js`;
|
|
144
|
+
},
|
|
145
|
+
assetLink(asset) {
|
|
146
|
+
if (typeof asset === "string") {
|
|
147
|
+
return `${options.origin}/api/v1/spaces/${options.spaceId}/assets/${asset}`;
|
|
148
|
+
} else {
|
|
149
|
+
return `${options.origin}/api/v1/spaces/${options.spaceId}/assets/${asset.uri}`;
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
};
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
// src/editable.ts
|
|
156
|
+
function llEditable(content) {
|
|
157
|
+
return {
|
|
158
|
+
"data-ll-id": content._id,
|
|
159
|
+
"data-ll-schema": content.schema
|
|
160
|
+
};
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
// src/sync.ts
|
|
164
|
+
var JS_SYNC_ID = "localess-js-sync";
|
|
165
|
+
function loadLocalessSync(origin, force = false) {
|
|
166
|
+
const isServer = typeof window === "undefined";
|
|
167
|
+
if (isServer) return;
|
|
168
|
+
if (window.top === window.self) return;
|
|
169
|
+
const isSyncLoaded = typeof window.localess !== "undefined";
|
|
170
|
+
if (isSyncLoaded) return;
|
|
171
|
+
const scriptEl = document.getElementById(JS_SYNC_ID);
|
|
172
|
+
if (scriptEl) return;
|
|
173
|
+
const script = document.createElement("script");
|
|
174
|
+
script.id = JS_SYNC_ID;
|
|
175
|
+
script.type = "text/javascript";
|
|
176
|
+
script.src = `${origin}/scripts/sync-v1.js`;
|
|
177
|
+
script.async = true;
|
|
178
|
+
script.onerror = (error) => console.error(error);
|
|
179
|
+
script.onload = (event) => console.info("Localess Sync Script loaded");
|
|
180
|
+
document.head.appendChild(script);
|
|
181
|
+
}
|
|
182
|
+
export {
|
|
183
|
+
llEditable,
|
|
184
|
+
loadLocalessSync,
|
|
185
|
+
localessClient
|
|
186
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@localess/js-client",
|
|
3
|
-
"version": "0.3.2-next.
|
|
3
|
+
"version": "0.3.2-next.20250109-090340.0",
|
|
4
4
|
"description": "Universal JavaScript/TypeScript SDK for Localess's API.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"localess",
|
|
@@ -16,18 +16,15 @@
|
|
|
16
16
|
"files": [
|
|
17
17
|
"dist"
|
|
18
18
|
],
|
|
19
|
-
"main": "dist/
|
|
20
|
-
"module": "dist/index.
|
|
19
|
+
"main": "dist/index.js",
|
|
20
|
+
"module": "dist/index.mjs",
|
|
21
21
|
"types": "dist/index.d.ts",
|
|
22
22
|
"exports": {
|
|
23
23
|
".": {
|
|
24
|
-
"import": "./dist/index.js",
|
|
25
|
-
"require": "./dist/cjs/index.js",
|
|
26
24
|
"types": "./dist/index.d.ts",
|
|
27
|
-
"
|
|
28
|
-
"
|
|
29
|
-
}
|
|
30
|
-
"./models": "./dist/models/index.d.ts"
|
|
25
|
+
"import": "./dist/index.mjs",
|
|
26
|
+
"require": "./dist/index.js"
|
|
27
|
+
}
|
|
31
28
|
},
|
|
32
29
|
"repository": {
|
|
33
30
|
"type": "git",
|
|
@@ -40,12 +37,12 @@
|
|
|
40
37
|
"build": "npm run build:tsc && npm run build:cjs",
|
|
41
38
|
"build:tsc": "tsc -p tsconfig.json",
|
|
42
39
|
"build:cjs": "tsc -p tsconfig.cjs.json",
|
|
43
|
-
"build:tsup": "tsup
|
|
40
|
+
"build:tsup": "tsup src/index.ts --format cjs,esm --dts"
|
|
44
41
|
},
|
|
45
42
|
"license": "MIT",
|
|
46
|
-
"dependencies": {},
|
|
47
43
|
"devDependencies": {
|
|
48
44
|
"@types/node": "^20.12.12",
|
|
45
|
+
"tsup": "^8.3.5",
|
|
49
46
|
"typescript": "^5.0.0"
|
|
50
47
|
},
|
|
51
48
|
"engines": {
|
package/dist/cjs/client.d.ts
DELETED
|
@@ -1,88 +0,0 @@
|
|
|
1
|
-
import { Content, ContentAsset, Links, Translations } from "./models";
|
|
2
|
-
export type LocalessClientOptions = {
|
|
3
|
-
/**
|
|
4
|
-
* A fully qualified domain name with protocol (http/https) and port.
|
|
5
|
-
*
|
|
6
|
-
* Example: https://my-localess.web.app
|
|
7
|
-
*/
|
|
8
|
-
origin: string;
|
|
9
|
-
/**
|
|
10
|
-
* Localess space ID, cna be found in the Localess Space settings
|
|
11
|
-
*/
|
|
12
|
-
spaceId: string;
|
|
13
|
-
/**
|
|
14
|
-
* Localess API token, can be found in the Localess Space settings
|
|
15
|
-
*/
|
|
16
|
-
token: string;
|
|
17
|
-
/**
|
|
18
|
-
* Content version to fetch, leave empty for 'published' or 'draft' for the latest draft
|
|
19
|
-
*/
|
|
20
|
-
version?: 'draft' | string;
|
|
21
|
-
/**
|
|
22
|
-
* Enable debug mode
|
|
23
|
-
*/
|
|
24
|
-
debug?: boolean;
|
|
25
|
-
};
|
|
26
|
-
export type LinksFetchParams = {
|
|
27
|
-
/**
|
|
28
|
-
* Content Kind. FOLDER or DOCUMENT. If not provided, it will return all.
|
|
29
|
-
* @example 'DOCUMENT'
|
|
30
|
-
*/
|
|
31
|
-
kind?: 'DOCUMENT' | 'FOLDER';
|
|
32
|
-
/**
|
|
33
|
-
* Content parent slug.
|
|
34
|
-
* @example 'legal/policy'
|
|
35
|
-
*/
|
|
36
|
-
parentSlug?: string;
|
|
37
|
-
/**
|
|
38
|
-
* If **true**, exclude all sub slugs, otherwise include all content under current selected **parent slug**.
|
|
39
|
-
* @example false
|
|
40
|
-
*/
|
|
41
|
-
excludeChildren?: boolean;
|
|
42
|
-
};
|
|
43
|
-
export type ContentFetchParams = {
|
|
44
|
-
/**
|
|
45
|
-
* Content version to fetch, leave empty for 'published' or 'draft' for the latest draft.
|
|
46
|
-
* Overrides the version set in the client options.
|
|
47
|
-
*/
|
|
48
|
-
version?: 'draft' | string;
|
|
49
|
-
/**
|
|
50
|
-
* Locale identifier (ISO 639-1) to fetch content in, leave empty for default locale.
|
|
51
|
-
*
|
|
52
|
-
* Example: en
|
|
53
|
-
*/
|
|
54
|
-
locale?: string;
|
|
55
|
-
};
|
|
56
|
-
/**
|
|
57
|
-
* Create a Localess API Client
|
|
58
|
-
* @param {LocalessClientOptions} options connection details
|
|
59
|
-
*/
|
|
60
|
-
export declare function localessClient(options: LocalessClientOptions): {
|
|
61
|
-
/**
|
|
62
|
-
* Get all links
|
|
63
|
-
* @param params{LinksFetchParams} - Fetch parameters
|
|
64
|
-
* @returns {Promise<Links>}
|
|
65
|
-
*/
|
|
66
|
-
getLinks(params?: LinksFetchParams): Promise<Links>;
|
|
67
|
-
/**
|
|
68
|
-
* Get content by SLUG
|
|
69
|
-
* @param slug{string} - Content SLUG
|
|
70
|
-
* @param params{ContentFetchParams} - Fetch parameters
|
|
71
|
-
* @returns {Promise<Content>}
|
|
72
|
-
*/
|
|
73
|
-
getContentBySlug(slug: string, params?: ContentFetchParams): Promise<Content>;
|
|
74
|
-
/**
|
|
75
|
-
* Get content by ID
|
|
76
|
-
* @param id{string} - Content ID
|
|
77
|
-
* @param params{ContentFetchParams} - Fetch parameters
|
|
78
|
-
* @returns {Promise<Content>}
|
|
79
|
-
*/
|
|
80
|
-
getContentById(id: string, params?: ContentFetchParams): Promise<Content>;
|
|
81
|
-
/**
|
|
82
|
-
* Get translations for the given locale
|
|
83
|
-
* @param locale{string} - Locale identifier (ISO 639-1)
|
|
84
|
-
*/
|
|
85
|
-
getTranslations(locale: string): Promise<Translations>;
|
|
86
|
-
syncScriptUrl(): string;
|
|
87
|
-
assetLink(asset: ContentAsset | string): string;
|
|
88
|
-
};
|