@sleekcms/client 2.2.0 → 2.2.2
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/README.md +3 -1
- package/index.cjs +14 -5
- package/index.d.cts +2 -0
- package/index.d.ts +2 -0
- package/index.mjs +14 -5
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @sleekcms/client
|
|
2
2
|
|
|
3
3
|
Official JavaScript/TypeScript client for [SleekCMS](https://sleekcms.com) - a headless CMS that lets you manage content and deliver it via API.
|
|
4
4
|
|
|
5
|
+
Sign in at [sleekcms.com](https://sleekcms.com), create your content models, add your content, then grab your site token and use this library to integrate content in your apps.
|
|
6
|
+
|
|
5
7
|
## Installation
|
|
6
8
|
|
|
7
9
|
```bash
|
package/index.cjs
CHANGED
|
@@ -38,9 +38,9 @@ module.exports = __toCommonJS(index_exports);
|
|
|
38
38
|
var jmespath = __toESM(require("jmespath"), 1);
|
|
39
39
|
function getBaseUrl(token, devEnv) {
|
|
40
40
|
let [env, siteId, ...rest] = token.split("-");
|
|
41
|
-
if (devEnv === "production") return `https
|
|
42
|
-
else if (devEnv === "development") return `https
|
|
43
|
-
else if (devEnv === "localhost") return `http://localhost:9001/${
|
|
41
|
+
if (devEnv === "production") return `https://pub.sleekcms.com/${siteId}`;
|
|
42
|
+
else if (devEnv === "development") return `https://pub.sleekcms.net/${siteId}`;
|
|
43
|
+
else if (devEnv === "localhost") return `http://localhost:9001/localhost/${siteId}`;
|
|
44
44
|
else throw new Error(`[SleekCMS] Unknown devEnv: ${devEnv}`);
|
|
45
45
|
}
|
|
46
46
|
function applyJmes(data, query) {
|
|
@@ -49,7 +49,7 @@ function applyJmes(data, query) {
|
|
|
49
49
|
}
|
|
50
50
|
function getUrl({ siteToken, env, search: search2, lang, devEnv = "production" }) {
|
|
51
51
|
const baseUrl = getBaseUrl(siteToken, devEnv).replace(/\/$/, "");
|
|
52
|
-
const url = new URL(`${baseUrl}/${env}`);
|
|
52
|
+
const url = new URL(`${baseUrl}/${env ?? "latest"}`);
|
|
53
53
|
if (search2) url.searchParams.append("search", search2);
|
|
54
54
|
if (lang) url.searchParams.append("lang", lang);
|
|
55
55
|
return url.toString();
|
|
@@ -281,6 +281,13 @@ function createAsyncClient(options) {
|
|
|
281
281
|
const list = lists[name];
|
|
282
282
|
return Array.isArray(list) ? list : null;
|
|
283
283
|
}
|
|
284
|
+
async function _getEnvTag() {
|
|
285
|
+
let resp = await fetchEnvTag({ siteToken, env });
|
|
286
|
+
return resp;
|
|
287
|
+
}
|
|
288
|
+
function _getFetchUrl() {
|
|
289
|
+
return getUrl(options);
|
|
290
|
+
}
|
|
284
291
|
return {
|
|
285
292
|
getContent,
|
|
286
293
|
getPages,
|
|
@@ -288,7 +295,9 @@ function createAsyncClient(options) {
|
|
|
288
295
|
getEntry,
|
|
289
296
|
getSlugs,
|
|
290
297
|
getImage,
|
|
291
|
-
getList
|
|
298
|
+
getList,
|
|
299
|
+
_getFetchUrl,
|
|
300
|
+
_getEnvTag
|
|
292
301
|
};
|
|
293
302
|
}
|
|
294
303
|
// Annotate the CommonJS export names for ESM import in node:
|
package/index.d.cts
CHANGED
|
@@ -55,6 +55,8 @@ interface SleekAsyncClient {
|
|
|
55
55
|
getSlugs(path: string): Promise<string[]>;
|
|
56
56
|
getImage(name: string): Promise<Image | null>;
|
|
57
57
|
getList(name: string): Promise<List | null>;
|
|
58
|
+
_getFetchUrl(): string;
|
|
59
|
+
_getEnvTag(): Promise<string>;
|
|
58
60
|
}
|
|
59
61
|
|
|
60
62
|
declare function createClient(options: ClientOptions): Promise<SleekClient>;
|
package/index.d.ts
CHANGED
|
@@ -55,6 +55,8 @@ interface SleekAsyncClient {
|
|
|
55
55
|
getSlugs(path: string): Promise<string[]>;
|
|
56
56
|
getImage(name: string): Promise<Image | null>;
|
|
57
57
|
getList(name: string): Promise<List | null>;
|
|
58
|
+
_getFetchUrl(): string;
|
|
59
|
+
_getEnvTag(): Promise<string>;
|
|
58
60
|
}
|
|
59
61
|
|
|
60
62
|
declare function createClient(options: ClientOptions): Promise<SleekClient>;
|
package/index.mjs
CHANGED
|
@@ -2,9 +2,9 @@
|
|
|
2
2
|
import * as jmespath from "jmespath";
|
|
3
3
|
function getBaseUrl(token, devEnv) {
|
|
4
4
|
let [env, siteId, ...rest] = token.split("-");
|
|
5
|
-
if (devEnv === "production") return `https
|
|
6
|
-
else if (devEnv === "development") return `https
|
|
7
|
-
else if (devEnv === "localhost") return `http://localhost:9001/${
|
|
5
|
+
if (devEnv === "production") return `https://pub.sleekcms.com/${siteId}`;
|
|
6
|
+
else if (devEnv === "development") return `https://pub.sleekcms.net/${siteId}`;
|
|
7
|
+
else if (devEnv === "localhost") return `http://localhost:9001/localhost/${siteId}`;
|
|
8
8
|
else throw new Error(`[SleekCMS] Unknown devEnv: ${devEnv}`);
|
|
9
9
|
}
|
|
10
10
|
function applyJmes(data, query) {
|
|
@@ -13,7 +13,7 @@ function applyJmes(data, query) {
|
|
|
13
13
|
}
|
|
14
14
|
function getUrl({ siteToken, env, search: search2, lang, devEnv = "production" }) {
|
|
15
15
|
const baseUrl = getBaseUrl(siteToken, devEnv).replace(/\/$/, "");
|
|
16
|
-
const url = new URL(`${baseUrl}/${env}`);
|
|
16
|
+
const url = new URL(`${baseUrl}/${env ?? "latest"}`);
|
|
17
17
|
if (search2) url.searchParams.append("search", search2);
|
|
18
18
|
if (lang) url.searchParams.append("lang", lang);
|
|
19
19
|
return url.toString();
|
|
@@ -245,6 +245,13 @@ function createAsyncClient(options) {
|
|
|
245
245
|
const list = lists[name];
|
|
246
246
|
return Array.isArray(list) ? list : null;
|
|
247
247
|
}
|
|
248
|
+
async function _getEnvTag() {
|
|
249
|
+
let resp = await fetchEnvTag({ siteToken, env });
|
|
250
|
+
return resp;
|
|
251
|
+
}
|
|
252
|
+
function _getFetchUrl() {
|
|
253
|
+
return getUrl(options);
|
|
254
|
+
}
|
|
248
255
|
return {
|
|
249
256
|
getContent,
|
|
250
257
|
getPages,
|
|
@@ -252,7 +259,9 @@ function createAsyncClient(options) {
|
|
|
252
259
|
getEntry,
|
|
253
260
|
getSlugs,
|
|
254
261
|
getImage,
|
|
255
|
-
getList
|
|
262
|
+
getList,
|
|
263
|
+
_getFetchUrl,
|
|
264
|
+
_getEnvTag
|
|
256
265
|
};
|
|
257
266
|
}
|
|
258
267
|
export {
|