@localess/js-client 0.0.3-next.20240527-125924.0 → 0.0.4-next.20240527-184103.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 +16 -3
- package/dist/index.d.ts +36 -14
- package/dist/index.js +39 -17
- package/dist/index.js.map +1 -1
- package/dist/models/content-data.d.ts +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -10,6 +10,10 @@
|
|
|
10
10
|
|
|
11
11
|
This client SDK is designed to work with the Localess API. It provides a simple way to interact with the Localess API from your JavaScript or TypeScript application.
|
|
12
12
|
|
|
13
|
+
> **Important:**
|
|
14
|
+
> The Client is designed to be used on the server side only, as it requires your **Localess API Token** to be kept secret.
|
|
15
|
+
> Do not use this client in your frontend application, as it exposes your API Token to the public.
|
|
16
|
+
|
|
13
17
|
## Installation
|
|
14
18
|
|
|
15
19
|
### NPM
|
|
@@ -24,8 +28,17 @@ yarn add @localess/js-client@latest
|
|
|
24
28
|
|
|
25
29
|
## Usage
|
|
26
30
|
|
|
31
|
+
````ts
|
|
32
|
+
import {localessClient} from "@localess/js-client";
|
|
27
33
|
|
|
34
|
+
const llClient = localessClient({
|
|
35
|
+
origin: 'https://my-localess.web.app', // A fully qualified domain name with protocol (http/https) and port.
|
|
36
|
+
spaceId: 'I1LoVe2LocaLess4Rever', // Localess space ID, cna be found in the Localess Space settings
|
|
37
|
+
token: 'Baz00KaT0KeN8S3CureLL' // Localess API token, can be found in the Localess Space settings
|
|
38
|
+
});
|
|
28
39
|
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
40
|
+
llClient.getLinks() // Fetch all Content Links
|
|
41
|
+
llClient.getContentBySlug('docs/overview') // Fetch content by SLUG
|
|
42
|
+
llClient.getContentById('FRnIT7CUABoRCdSVVGGs') // Fetch content by ID
|
|
43
|
+
llClient.getTranslations('en') // Fetch translations by locale
|
|
44
|
+
````
|
package/dist/index.d.ts
CHANGED
|
@@ -4,19 +4,9 @@ export type LocalessClientOptions = {
|
|
|
4
4
|
/**
|
|
5
5
|
* A fully qualified domain name with protocol (http/https) and port.
|
|
6
6
|
*
|
|
7
|
-
* Example: https://localess
|
|
7
|
+
* Example: https://my-localess.web.app
|
|
8
8
|
*/
|
|
9
9
|
origin: string;
|
|
10
|
-
/**
|
|
11
|
-
* Content version to fetch, leave empty for 'published' or 'draft' for the latest draft
|
|
12
|
-
*/
|
|
13
|
-
version?: 'draft' | string;
|
|
14
|
-
/**
|
|
15
|
-
* Locale to fetch content in, leave empty for default locale
|
|
16
|
-
*
|
|
17
|
-
* Example: en
|
|
18
|
-
*/
|
|
19
|
-
locale?: string;
|
|
20
10
|
/**
|
|
21
11
|
* Localess space ID, cna be found in the Localess Space settings
|
|
22
12
|
*/
|
|
@@ -30,11 +20,43 @@ export type LocalessClientOptions = {
|
|
|
30
20
|
*/
|
|
31
21
|
debug?: boolean;
|
|
32
22
|
};
|
|
23
|
+
export type ContentFetchParams = {
|
|
24
|
+
/**
|
|
25
|
+
* Content version to fetch, leave empty for 'published' or 'draft' for the latest draft
|
|
26
|
+
*/
|
|
27
|
+
version?: 'draft' | 'published';
|
|
28
|
+
/**
|
|
29
|
+
* Locale identifier (ISO 639-1) to fetch content in, leave empty for default locale.
|
|
30
|
+
*
|
|
31
|
+
* Example: en
|
|
32
|
+
*/
|
|
33
|
+
locale?: string;
|
|
34
|
+
};
|
|
33
35
|
export declare function localessClient(options: LocalessClientOptions): {
|
|
36
|
+
/**
|
|
37
|
+
* Get all links
|
|
38
|
+
* @returns {Promise<Links>}
|
|
39
|
+
*/
|
|
34
40
|
getLinks(): Promise<Links>;
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
41
|
+
/**
|
|
42
|
+
* Get content by SLUG
|
|
43
|
+
* @param slug{string} - Content SLUG
|
|
44
|
+
* @param params{ContentFetchParams} - Fetch parameters
|
|
45
|
+
* @returns {Promise<Content>}
|
|
46
|
+
*/
|
|
47
|
+
getContentBySlug(slug: string, params?: ContentFetchParams): Promise<Content>;
|
|
48
|
+
/**
|
|
49
|
+
* Get content by ID
|
|
50
|
+
* @param id{string} - Content ID
|
|
51
|
+
* @param params{ContentFetchParams} - Fetch parameters
|
|
52
|
+
* @returns {Promise<Content>}
|
|
53
|
+
*/
|
|
54
|
+
getContentById(id: string, params?: ContentFetchParams): Promise<Content>;
|
|
55
|
+
/**
|
|
56
|
+
* Get translations for the given locale
|
|
57
|
+
* @param locale{string} - Locale identifier (ISO 639-1)
|
|
58
|
+
*/
|
|
59
|
+
getTranslations(locale: string): Promise<Translations>;
|
|
38
60
|
syncScriptUrl(): string;
|
|
39
61
|
assetLink(asset: ContentAsset | string): string;
|
|
40
62
|
};
|
package/dist/index.js
CHANGED
|
@@ -5,7 +5,7 @@ export * from './models';
|
|
|
5
5
|
const LOG_GROUP = `${FG_BLUE}[Localess]${RESET}`;
|
|
6
6
|
export function localessClient(options) {
|
|
7
7
|
if (options.debug) {
|
|
8
|
-
console.log(LOG_GROUP, 'Client Options :
|
|
8
|
+
console.log(LOG_GROUP, 'Client Options :', options);
|
|
9
9
|
}
|
|
10
10
|
const fetchOptions = {
|
|
11
11
|
redirect: 'follow',
|
|
@@ -13,65 +13,87 @@ export function localessClient(options) {
|
|
|
13
13
|
if (proxyURIFromEnv()) {
|
|
14
14
|
fetchOptions.agent = new ProxyAgent();
|
|
15
15
|
}
|
|
16
|
-
const version = options.version ? `&version=${options.version}` : '';
|
|
17
|
-
const locale = options.locale ? `&locale=${options.locale}` : '';
|
|
18
16
|
return {
|
|
17
|
+
/**
|
|
18
|
+
* Get all links
|
|
19
|
+
* @returns {Promise<Links>}
|
|
20
|
+
*/
|
|
19
21
|
async getLinks() {
|
|
20
22
|
if (options.debug) {
|
|
21
23
|
console.log(LOG_GROUP, 'getLinks()');
|
|
22
24
|
}
|
|
23
25
|
let url = `${options.origin}/api/v1/spaces/${options.spaceId}/links?token=${options.token}`;
|
|
24
26
|
if (options.debug) {
|
|
25
|
-
console.log(LOG_GROUP, 'getLinks url :
|
|
27
|
+
console.log(LOG_GROUP, 'getLinks url :', url);
|
|
26
28
|
}
|
|
27
29
|
const response = await fetch(url, fetchOptions);
|
|
28
30
|
if (options.debug) {
|
|
29
|
-
console.log(LOG_GROUP, 'getLinks status :
|
|
31
|
+
console.log(LOG_GROUP, 'getLinks status :', response.status);
|
|
30
32
|
}
|
|
31
33
|
const data = await response.json();
|
|
32
34
|
return data;
|
|
33
35
|
},
|
|
34
|
-
|
|
36
|
+
/**
|
|
37
|
+
* Get content by SLUG
|
|
38
|
+
* @param slug{string} - Content SLUG
|
|
39
|
+
* @param params{ContentFetchParams} - Fetch parameters
|
|
40
|
+
* @returns {Promise<Content>}
|
|
41
|
+
*/
|
|
42
|
+
async getContentBySlug(slug, params) {
|
|
35
43
|
if (options.debug) {
|
|
36
|
-
console.log(LOG_GROUP, 'getContentBySlug() slug :
|
|
44
|
+
console.log(LOG_GROUP, 'getContentBySlug() slug :', slug);
|
|
37
45
|
}
|
|
46
|
+
const version = params?.version == 'draft' ? `&version=${params.version}` : '';
|
|
47
|
+
const locale = params?.locale ? `&locale=${params.locale}` : '';
|
|
38
48
|
let url = `${options.origin}/api/v1/spaces/${options.spaceId}/contents/slugs/${slug}?token=${options.token}${version}${locale}`;
|
|
39
49
|
if (options.debug) {
|
|
40
|
-
console.log(LOG_GROUP, 'getContentBySlug url :
|
|
50
|
+
console.log(LOG_GROUP, 'getContentBySlug url :', url);
|
|
41
51
|
}
|
|
42
52
|
const response = await fetch(url, fetchOptions);
|
|
43
53
|
if (options.debug) {
|
|
44
|
-
console.log(LOG_GROUP, 'getContentBySlug status :
|
|
54
|
+
console.log(LOG_GROUP, 'getContentBySlug status :', response.status);
|
|
45
55
|
}
|
|
46
56
|
const data = await response.json();
|
|
47
57
|
return data;
|
|
48
58
|
},
|
|
49
|
-
|
|
59
|
+
/**
|
|
60
|
+
* Get content by ID
|
|
61
|
+
* @param id{string} - Content ID
|
|
62
|
+
* @param params{ContentFetchParams} - Fetch parameters
|
|
63
|
+
* @returns {Promise<Content>}
|
|
64
|
+
*/
|
|
65
|
+
async getContentById(id, params) {
|
|
50
66
|
if (options.debug) {
|
|
51
|
-
console.log(LOG_GROUP, 'getContentById() id :
|
|
67
|
+
console.log(LOG_GROUP, 'getContentById() id :', id);
|
|
52
68
|
}
|
|
69
|
+
const version = params?.version == 'draft' ? `&version=${params.version}` : '';
|
|
70
|
+
const locale = params?.locale ? `&locale=${params.locale}` : '';
|
|
53
71
|
let url = `${options.origin}/api/v1/spaces/${options.spaceId}/contents/${id}?token=${options.token}${version}${locale}`;
|
|
54
72
|
if (options.debug) {
|
|
55
|
-
console.log(LOG_GROUP, 'getContentById url :
|
|
73
|
+
console.log(LOG_GROUP, 'getContentById url :', url);
|
|
56
74
|
}
|
|
57
75
|
const response = await fetch(url, fetchOptions);
|
|
58
76
|
if (options.debug) {
|
|
59
|
-
console.log(LOG_GROUP, 'getContentById status :
|
|
77
|
+
console.log(LOG_GROUP, 'getContentById status :', response.status);
|
|
60
78
|
}
|
|
61
79
|
const data = await response.json();
|
|
62
80
|
return data;
|
|
63
81
|
},
|
|
64
|
-
|
|
82
|
+
/**
|
|
83
|
+
* Get translations for the given locale
|
|
84
|
+
* @param locale{string} - Locale identifier (ISO 639-1)
|
|
85
|
+
*/
|
|
86
|
+
async getTranslations(locale) {
|
|
65
87
|
if (options.debug) {
|
|
66
88
|
console.log(LOG_GROUP, 'getTranslations()');
|
|
67
89
|
}
|
|
68
|
-
let url = `${options.origin}/api/v1/spaces/${options.spaceId}/translations/${locale
|
|
90
|
+
let url = `${options.origin}/api/v1/spaces/${options.spaceId}/translations/${locale}`;
|
|
69
91
|
if (options.debug) {
|
|
70
|
-
console.log(LOG_GROUP, 'getTranslations url :
|
|
92
|
+
console.log(LOG_GROUP, 'getTranslations url :', url);
|
|
71
93
|
}
|
|
72
94
|
const response = await fetch(url, fetchOptions);
|
|
73
95
|
if (options.debug) {
|
|
74
|
-
console.log(LOG_GROUP, 'getTranslations status :
|
|
96
|
+
console.log(LOG_GROUP, 'getTranslations status :', response.status);
|
|
75
97
|
}
|
|
76
98
|
const data = await response.json();
|
|
77
99
|
return data;
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,UAAU,EAAC,MAAM,aAAa,CAAC;AACvC,OAAO,KAAoB,MAAM,YAAY,CAAC;AAE9C,OAAO,EAAC,OAAO,EAAE,eAAe,EAAE,KAAK,EAAC,MAAM,SAAS,CAAC;AAExD,cAAc,UAAU,CAAC;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,UAAU,EAAC,MAAM,aAAa,CAAC;AACvC,OAAO,KAAoB,MAAM,YAAY,CAAC;AAE9C,OAAO,EAAC,OAAO,EAAE,eAAe,EAAE,KAAK,EAAC,MAAM,SAAS,CAAC;AAExD,cAAc,UAAU,CAAC;AAoCzB,MAAM,SAAS,GAAG,GAAG,OAAO,aAAa,KAAK,EAAE,CAAA;AAEhD,MAAM,UAAU,cAAc,CAAC,OAA8B;IAC3D,IAAG,OAAO,CAAC,KAAK,EAAE,CAAC;QACjB,OAAO,CAAC,GAAG,CAAC,SAAS,EAAE,kBAAkB,EAAE,OAAO,CAAC,CAAC;IACtD,CAAC;IACD,MAAM,YAAY,GAAgB;QAChC,QAAQ,EAAE,QAAQ;KACnB,CAAC;IACF,IAAI,eAAe,EAAE,EAAE,CAAC;QACtB,YAAY,CAAC,KAAK,GAAG,IAAI,UAAU,EAAE,CAAC;IACxC,CAAC;IAED,OAAO;QAEL;;;WAGG;QACH,KAAK,CAAC,QAAQ;YACZ,IAAI,OAAO,CAAC,KAAK,EAAE,CAAC;gBAClB,OAAO,CAAC,GAAG,CAAC,SAAS,EAAE,YAAY,CAAC,CAAC;YACvC,CAAC;YACD,IAAI,GAAG,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