@sleekcms/client 2.2.1 → 2.3.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/README.md +7 -5
- package/index.cjs +11 -11
- package/index.d.cts +5 -5
- package/index.d.ts +5 -5
- package/index.mjs +11 -11
- 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
|
|
@@ -211,12 +213,12 @@ const logo = client.getImage('logo');
|
|
|
211
213
|
// { url: 'https://...', alt: '...', ... }
|
|
212
214
|
```
|
|
213
215
|
|
|
214
|
-
### `
|
|
216
|
+
### `getOptionSet(name)`
|
|
215
217
|
|
|
216
|
-
Get a
|
|
218
|
+
Get a option set (array of label/value pairs).
|
|
217
219
|
|
|
218
220
|
```typescript
|
|
219
|
-
const categories = client.
|
|
221
|
+
const categories = client.getOptionSet('categories');
|
|
220
222
|
// [{ label: 'Tech', value: 'tech' }, ...]
|
|
221
223
|
```
|
|
222
224
|
|
|
@@ -325,7 +327,7 @@ import type {
|
|
|
325
327
|
Page,
|
|
326
328
|
Entry,
|
|
327
329
|
Image,
|
|
328
|
-
|
|
330
|
+
Options
|
|
329
331
|
} from '@sleekcms/client';
|
|
330
332
|
```
|
|
331
333
|
|
package/index.cjs
CHANGED
|
@@ -209,11 +209,11 @@ async function createClient(options) {
|
|
|
209
209
|
if (!name) return null;
|
|
210
210
|
return data.images ? data.images[name] : null;
|
|
211
211
|
}
|
|
212
|
-
function
|
|
212
|
+
function getOptionSet(name) {
|
|
213
213
|
if (!name) return null;
|
|
214
|
-
const
|
|
215
|
-
const
|
|
216
|
-
return Array.isArray(
|
|
214
|
+
const options2 = data.options ?? {};
|
|
215
|
+
const optionSet = options2[name];
|
|
216
|
+
return Array.isArray(optionSet) ? optionSet : null;
|
|
217
217
|
}
|
|
218
218
|
return {
|
|
219
219
|
getContent,
|
|
@@ -222,7 +222,7 @@ async function createClient(options) {
|
|
|
222
222
|
getEntry,
|
|
223
223
|
getSlugs,
|
|
224
224
|
getImage,
|
|
225
|
-
|
|
225
|
+
getOptionSet
|
|
226
226
|
};
|
|
227
227
|
}
|
|
228
228
|
function createAsyncClient(options) {
|
|
@@ -274,12 +274,12 @@ function createAsyncClient(options) {
|
|
|
274
274
|
const images = await fetchSiteContent({ siteToken, env: tag ?? env, search: "images", lang, cache });
|
|
275
275
|
return images ? images[name] : null;
|
|
276
276
|
}
|
|
277
|
-
async function
|
|
277
|
+
async function getOptionSet(name) {
|
|
278
278
|
if (cdn && !tag) tag = await fetchEnvTag({ siteToken, env });
|
|
279
|
-
if (syncClient) return syncClient.
|
|
280
|
-
const
|
|
281
|
-
const
|
|
282
|
-
return Array.isArray(
|
|
279
|
+
if (syncClient) return syncClient.getOptionSet(name);
|
|
280
|
+
const options2 = await fetchSiteContent({ siteToken, env: tag ?? env, search: "options", lang, cache });
|
|
281
|
+
const optionSet = options2[name];
|
|
282
|
+
return Array.isArray(optionSet) ? optionSet : null;
|
|
283
283
|
}
|
|
284
284
|
async function _getEnvTag() {
|
|
285
285
|
let resp = await fetchEnvTag({ siteToken, env });
|
|
@@ -295,7 +295,7 @@ function createAsyncClient(options) {
|
|
|
295
295
|
getEntry,
|
|
296
296
|
getSlugs,
|
|
297
297
|
getImage,
|
|
298
|
-
|
|
298
|
+
getOptionSet,
|
|
299
299
|
_getFetchUrl,
|
|
300
300
|
_getEnvTag
|
|
301
301
|
};
|
package/index.d.cts
CHANGED
|
@@ -7,7 +7,7 @@ type Image = {
|
|
|
7
7
|
url: string;
|
|
8
8
|
[key: string]: unknown;
|
|
9
9
|
};
|
|
10
|
-
type
|
|
10
|
+
type Options = Array<{
|
|
11
11
|
label: string;
|
|
12
12
|
value: string;
|
|
13
13
|
}>;
|
|
@@ -17,7 +17,7 @@ interface SleekSiteContent {
|
|
|
17
17
|
};
|
|
18
18
|
pages?: Array<Page>;
|
|
19
19
|
images?: Record<string, Image>;
|
|
20
|
-
|
|
20
|
+
options?: Record<string, Options>;
|
|
21
21
|
config?: {
|
|
22
22
|
title?: string;
|
|
23
23
|
};
|
|
@@ -45,7 +45,7 @@ interface SleekClient {
|
|
|
45
45
|
getEntry(handle: string): Entry | Entry[] | null;
|
|
46
46
|
getSlugs(path: string): string[];
|
|
47
47
|
getImage(name: string): Image | null;
|
|
48
|
-
|
|
48
|
+
getOptionSet(name: string): Options | null;
|
|
49
49
|
}
|
|
50
50
|
interface SleekAsyncClient {
|
|
51
51
|
getContent(query?: string): Promise<SleekSiteContent>;
|
|
@@ -54,7 +54,7 @@ interface SleekAsyncClient {
|
|
|
54
54
|
getEntry(handle: string): Promise<Entry | Entry[] | null>;
|
|
55
55
|
getSlugs(path: string): Promise<string[]>;
|
|
56
56
|
getImage(name: string): Promise<Image | null>;
|
|
57
|
-
|
|
57
|
+
getOptionSet(name: string): Promise<Options | null>;
|
|
58
58
|
_getFetchUrl(): string;
|
|
59
59
|
_getEnvTag(): Promise<string>;
|
|
60
60
|
}
|
|
@@ -62,4 +62,4 @@ interface SleekAsyncClient {
|
|
|
62
62
|
declare function createClient(options: ClientOptions): Promise<SleekClient>;
|
|
63
63
|
declare function createAsyncClient(options: ClientOptions): SleekAsyncClient | any;
|
|
64
64
|
|
|
65
|
-
export { type AsyncCacheAdapter, type ClientOptions, type Entry, type Image, type
|
|
65
|
+
export { type AsyncCacheAdapter, type ClientOptions, type Entry, type Image, type Options, type Page, type SleekAsyncClient, type SleekClient, type SleekSiteContent, type SyncCacheAdapter, createAsyncClient, createClient };
|
package/index.d.ts
CHANGED
|
@@ -7,7 +7,7 @@ type Image = {
|
|
|
7
7
|
url: string;
|
|
8
8
|
[key: string]: unknown;
|
|
9
9
|
};
|
|
10
|
-
type
|
|
10
|
+
type Options = Array<{
|
|
11
11
|
label: string;
|
|
12
12
|
value: string;
|
|
13
13
|
}>;
|
|
@@ -17,7 +17,7 @@ interface SleekSiteContent {
|
|
|
17
17
|
};
|
|
18
18
|
pages?: Array<Page>;
|
|
19
19
|
images?: Record<string, Image>;
|
|
20
|
-
|
|
20
|
+
options?: Record<string, Options>;
|
|
21
21
|
config?: {
|
|
22
22
|
title?: string;
|
|
23
23
|
};
|
|
@@ -45,7 +45,7 @@ interface SleekClient {
|
|
|
45
45
|
getEntry(handle: string): Entry | Entry[] | null;
|
|
46
46
|
getSlugs(path: string): string[];
|
|
47
47
|
getImage(name: string): Image | null;
|
|
48
|
-
|
|
48
|
+
getOptionSet(name: string): Options | null;
|
|
49
49
|
}
|
|
50
50
|
interface SleekAsyncClient {
|
|
51
51
|
getContent(query?: string): Promise<SleekSiteContent>;
|
|
@@ -54,7 +54,7 @@ interface SleekAsyncClient {
|
|
|
54
54
|
getEntry(handle: string): Promise<Entry | Entry[] | null>;
|
|
55
55
|
getSlugs(path: string): Promise<string[]>;
|
|
56
56
|
getImage(name: string): Promise<Image | null>;
|
|
57
|
-
|
|
57
|
+
getOptionSet(name: string): Promise<Options | null>;
|
|
58
58
|
_getFetchUrl(): string;
|
|
59
59
|
_getEnvTag(): Promise<string>;
|
|
60
60
|
}
|
|
@@ -62,4 +62,4 @@ interface SleekAsyncClient {
|
|
|
62
62
|
declare function createClient(options: ClientOptions): Promise<SleekClient>;
|
|
63
63
|
declare function createAsyncClient(options: ClientOptions): SleekAsyncClient | any;
|
|
64
64
|
|
|
65
|
-
export { type AsyncCacheAdapter, type ClientOptions, type Entry, type Image, type
|
|
65
|
+
export { type AsyncCacheAdapter, type ClientOptions, type Entry, type Image, type Options, type Page, type SleekAsyncClient, type SleekClient, type SleekSiteContent, type SyncCacheAdapter, createAsyncClient, createClient };
|
package/index.mjs
CHANGED
|
@@ -173,11 +173,11 @@ async function createClient(options) {
|
|
|
173
173
|
if (!name) return null;
|
|
174
174
|
return data.images ? data.images[name] : null;
|
|
175
175
|
}
|
|
176
|
-
function
|
|
176
|
+
function getOptionSet(name) {
|
|
177
177
|
if (!name) return null;
|
|
178
|
-
const
|
|
179
|
-
const
|
|
180
|
-
return Array.isArray(
|
|
178
|
+
const options2 = data.options ?? {};
|
|
179
|
+
const optionSet = options2[name];
|
|
180
|
+
return Array.isArray(optionSet) ? optionSet : null;
|
|
181
181
|
}
|
|
182
182
|
return {
|
|
183
183
|
getContent,
|
|
@@ -186,7 +186,7 @@ async function createClient(options) {
|
|
|
186
186
|
getEntry,
|
|
187
187
|
getSlugs,
|
|
188
188
|
getImage,
|
|
189
|
-
|
|
189
|
+
getOptionSet
|
|
190
190
|
};
|
|
191
191
|
}
|
|
192
192
|
function createAsyncClient(options) {
|
|
@@ -238,12 +238,12 @@ function createAsyncClient(options) {
|
|
|
238
238
|
const images = await fetchSiteContent({ siteToken, env: tag ?? env, search: "images", lang, cache });
|
|
239
239
|
return images ? images[name] : null;
|
|
240
240
|
}
|
|
241
|
-
async function
|
|
241
|
+
async function getOptionSet(name) {
|
|
242
242
|
if (cdn && !tag) tag = await fetchEnvTag({ siteToken, env });
|
|
243
|
-
if (syncClient) return syncClient.
|
|
244
|
-
const
|
|
245
|
-
const
|
|
246
|
-
return Array.isArray(
|
|
243
|
+
if (syncClient) return syncClient.getOptionSet(name);
|
|
244
|
+
const options2 = await fetchSiteContent({ siteToken, env: tag ?? env, search: "options", lang, cache });
|
|
245
|
+
const optionSet = options2[name];
|
|
246
|
+
return Array.isArray(optionSet) ? optionSet : null;
|
|
247
247
|
}
|
|
248
248
|
async function _getEnvTag() {
|
|
249
249
|
let resp = await fetchEnvTag({ siteToken, env });
|
|
@@ -259,7 +259,7 @@ function createAsyncClient(options) {
|
|
|
259
259
|
getEntry,
|
|
260
260
|
getSlugs,
|
|
261
261
|
getImage,
|
|
262
|
-
|
|
262
|
+
getOptionSet,
|
|
263
263
|
_getFetchUrl,
|
|
264
264
|
_getEnvTag
|
|
265
265
|
};
|