@localess/js-client 0.0.3-20240526-114112.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 +31 -0
- package/dist/index.d.ts +34 -0
- package/dist/index.js +49 -0
- package/dist/index.js.map +1 -0
- package/dist/models/content-asset.d.ts +13 -0
- package/dist/models/content-asset.js +2 -0
- package/dist/models/content-asset.js.map +1 -0
- package/dist/models/content-data.d.ts +4 -0
- package/dist/models/content-data.js +2 -0
- package/dist/models/content-data.js.map +1 -0
- package/dist/models/content-metadata.d.ts +41 -0
- package/dist/models/content-metadata.js +2 -0
- package/dist/models/content-metadata.js.map +1 -0
- package/dist/models/content.d.ts +47 -0
- package/dist/models/content.js +2 -0
- package/dist/models/content.js.map +1 -0
- package/dist/models/index.d.ts +6 -0
- package/dist/models/index.js +7 -0
- package/dist/models/index.js.map +1 -0
- package/dist/models/links.d.ts +7 -0
- package/dist/models/links.js +2 -0
- package/dist/models/links.js.map +1 -0
- package/dist/models/translations.d.ts +6 -0
- package/dist/models/translations.js +2 -0
- package/dist/models/translations.js.map +1 -0
- package/dist/utils.d.ts +1 -0
- package/dist/utils.js +8 -0
- package/dist/utils.js.map +1 -0
- package/package.json +43 -0
package/README.md
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
<br/>
|
|
2
|
+
<br/>
|
|
3
|
+
<img src="https://github.com/Lessify/localess/wiki/img/logo-adaptive.svg" alt="logo">
|
|
4
|
+
<br/>
|
|
5
|
+
<br/>
|
|
6
|
+
|
|
7
|
+
----
|
|
8
|
+
|
|
9
|
+
# Localess JavaScript / TypeScript Client SDK
|
|
10
|
+
|
|
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
|
+
|
|
13
|
+
## Installation
|
|
14
|
+
|
|
15
|
+
### NPM
|
|
16
|
+
````bash
|
|
17
|
+
npm install @localess/js-client@latest
|
|
18
|
+
````
|
|
19
|
+
|
|
20
|
+
### Yarn
|
|
21
|
+
````bash
|
|
22
|
+
yarn add @localess/js-client@latest
|
|
23
|
+
````
|
|
24
|
+
|
|
25
|
+
## Usage
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
[comment]: <> (`npm init --scope=localess`)
|
|
30
|
+
[comment]: <> (`npm run build`)
|
|
31
|
+
[comment]: <> (`npm publish --access public dist`)
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { Content, ContentAsset, Links, Translations } from "./models";
|
|
2
|
+
export * from './models';
|
|
3
|
+
export type LocalessClientOptions = {
|
|
4
|
+
domain: string;
|
|
5
|
+
version?: 'draft';
|
|
6
|
+
location?: string;
|
|
7
|
+
spaceId: string;
|
|
8
|
+
token: string;
|
|
9
|
+
secure?: boolean;
|
|
10
|
+
};
|
|
11
|
+
export declare function localessClient(options: LocalessClientOptions): {
|
|
12
|
+
getLinks(): Promise<Links>;
|
|
13
|
+
getContentBySlug(slug: string): Promise<Content>;
|
|
14
|
+
getContentById(id: string): Promise<Content>;
|
|
15
|
+
getTranslations(): Promise<Translations>;
|
|
16
|
+
syncScriptUrl(): string;
|
|
17
|
+
assetLink(asset: ContentAsset | string): string;
|
|
18
|
+
};
|
|
19
|
+
declare global {
|
|
20
|
+
type EventType = 'input' | 'save' | 'publish' | 'change';
|
|
21
|
+
type EventCallback = (event: EventToApp) => void;
|
|
22
|
+
type EventToApp = {
|
|
23
|
+
type: 'save' | 'publish';
|
|
24
|
+
} | {
|
|
25
|
+
type: 'input' | 'change';
|
|
26
|
+
data: any;
|
|
27
|
+
};
|
|
28
|
+
interface LocalessSync {
|
|
29
|
+
on: (event: EventType | EventType[], callback: EventCallback) => void;
|
|
30
|
+
}
|
|
31
|
+
interface Window {
|
|
32
|
+
localess?: LocalessSync;
|
|
33
|
+
}
|
|
34
|
+
}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { ProxyAgent } from 'proxy-agent';
|
|
2
|
+
import fetch from 'node-fetch';
|
|
3
|
+
import { proxyURIFromEnv } from "./utils";
|
|
4
|
+
export * from './models';
|
|
5
|
+
export function localessClient(options) {
|
|
6
|
+
const fetchOptions = {
|
|
7
|
+
redirect: 'follow',
|
|
8
|
+
};
|
|
9
|
+
if (proxyURIFromEnv()) {
|
|
10
|
+
fetchOptions.agent = new ProxyAgent();
|
|
11
|
+
}
|
|
12
|
+
const host = `${options.secure ? 'https' : 'http'}://${options.domain}`;
|
|
13
|
+
const version = options.version ? `&version=${options.version}` : '';
|
|
14
|
+
const locale = options.location ? `&location=${options.location}` : '';
|
|
15
|
+
return {
|
|
16
|
+
async getLinks() {
|
|
17
|
+
const response = await fetch(`${host}/api/v1/spaces/${options.spaceId}/links?token=${options.token}`, fetchOptions);
|
|
18
|
+
const data = await response.json();
|
|
19
|
+
return data;
|
|
20
|
+
},
|
|
21
|
+
async getContentBySlug(slug) {
|
|
22
|
+
const response = await fetch(`${host}/api/v1/spaces/${options.spaceId}/contents/slugs/${slug}?token=${options.token}${version}${locale}`, fetchOptions);
|
|
23
|
+
const data = await response.json();
|
|
24
|
+
return data;
|
|
25
|
+
},
|
|
26
|
+
async getContentById(id) {
|
|
27
|
+
const response = await fetch(`${host}/api/v1/spaces/${options.spaceId}/contents/${id}?token=${options.token}${version}${locale}`, fetchOptions);
|
|
28
|
+
const data = await response.json();
|
|
29
|
+
return data;
|
|
30
|
+
},
|
|
31
|
+
async getTranslations() {
|
|
32
|
+
const response = await fetch(`${host}/api/v1/spaces/${options.spaceId}/translations/${locale || 'en'}`, fetchOptions);
|
|
33
|
+
const data = await response.json();
|
|
34
|
+
return data;
|
|
35
|
+
},
|
|
36
|
+
syncScriptUrl() {
|
|
37
|
+
return `${host}/scripts/sync-v1.js`;
|
|
38
|
+
},
|
|
39
|
+
assetLink(asset) {
|
|
40
|
+
if (typeof asset === 'string') {
|
|
41
|
+
return `${host}/api/v1/spaces/${options.spaceId}/assets/${asset}`;
|
|
42
|
+
}
|
|
43
|
+
else {
|
|
44
|
+
return `${host}/api/v1/spaces/${options.spaceId}/assets/${asset.uri}`;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +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;AAC9C,OAAO,EAAC,eAAe,EAAC,MAAM,SAAS,CAAC;AAGxC,cAAc,UAAU,CAAC;AAWzB,MAAM,UAAU,cAAc,CAAC,OAA8B;IAC3D,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;IACD,MAAM,IAAI,GAAG,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,MAAM,OAAO,CAAC,MAAM,EAAE,CAAC;IACxE,MAAM,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC,CAAC,YAAY,OAAO,CAAC,OAAO,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;IACrE,MAAM,MAAM,GAAG,OAAO,CAAC,QAAQ,CAAC,CAAC,CAAC,aAAa,OAAO,CAAC,QAAQ,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;IACvE,OAAO;QAEL,KAAK,CAAC,QAAQ;YACZ,MAAM,QAAQ,GAAG,MAAM,KAAK,CAAC,GAAG,IAAI,kBAAkB,OAAO,CAAC,OAAO,gBAAgB,OAAO,CAAC,KAAK,EAAE,EAAE,YAAY,CAAC,CAAA;YACnH,MAAM,IAAI,GAAG,MAAM,QAAQ,CAAC,I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AC,GAAG,EAAE,CAAC;YACxE,CAAC;QACH,CAAC;KACF,CAAA;AACH,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"content-asset.js","sourceRoot":"","sources":["../../src/models/content-asset.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"content-data.js","sourceRoot":"","sources":["../../src/models/content-data.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Content Metadata define short information about a Content for navigation reason.
|
|
3
|
+
*/
|
|
4
|
+
export interface ContentMetadata {
|
|
5
|
+
/**
|
|
6
|
+
* Date and Time at which the Content was created.
|
|
7
|
+
*/
|
|
8
|
+
createdAt: string;
|
|
9
|
+
/**
|
|
10
|
+
* Combination of SLUG and Parent SLUG of the Content
|
|
11
|
+
*/
|
|
12
|
+
fullSlug: string;
|
|
13
|
+
/**
|
|
14
|
+
* Unique identifier for the object.
|
|
15
|
+
*/
|
|
16
|
+
id: string;
|
|
17
|
+
/**
|
|
18
|
+
* Define the type of Content, whether it is a FOLDER or DOCUMENT.
|
|
19
|
+
*/
|
|
20
|
+
kind: 'FOLDER' | 'DOCUMENT';
|
|
21
|
+
/**
|
|
22
|
+
* Name of the Content
|
|
23
|
+
*/
|
|
24
|
+
name: string;
|
|
25
|
+
/**
|
|
26
|
+
* Parent SLUG of the Content
|
|
27
|
+
*/
|
|
28
|
+
parentSlug: string;
|
|
29
|
+
/**
|
|
30
|
+
* Date and Time at which the Content was published.
|
|
31
|
+
*/
|
|
32
|
+
publishedAt?: string;
|
|
33
|
+
/**
|
|
34
|
+
* SLUG of the Content
|
|
35
|
+
*/
|
|
36
|
+
slug: string;
|
|
37
|
+
/**
|
|
38
|
+
* Date and Time at which the Content was updated.
|
|
39
|
+
*/
|
|
40
|
+
updatedAt: string;
|
|
41
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"content-metadata.js","sourceRoot":"","sources":["../../src/models/content-metadata.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { ContentData } from './content-data';
|
|
2
|
+
/**
|
|
3
|
+
* Content define shared object for all possible Content Types.
|
|
4
|
+
*/
|
|
5
|
+
export interface Content {
|
|
6
|
+
/**
|
|
7
|
+
* Date and Time at which the Content was created.
|
|
8
|
+
*/
|
|
9
|
+
createdAt: string;
|
|
10
|
+
data?: ContentData;
|
|
11
|
+
/**
|
|
12
|
+
* Combination of SLUG and Parent SLUG of the Content
|
|
13
|
+
*/
|
|
14
|
+
fullSlug: string;
|
|
15
|
+
/**
|
|
16
|
+
* Unique identifier for the object.
|
|
17
|
+
*/
|
|
18
|
+
id: string;
|
|
19
|
+
/**
|
|
20
|
+
* Define the type of Content, whether it is a FOLDER or DOCUMENT.
|
|
21
|
+
*/
|
|
22
|
+
kind: 'FOLDER' | 'DOCUMENT';
|
|
23
|
+
/**
|
|
24
|
+
* Locale unique identifier (ISO 639-1).
|
|
25
|
+
*/
|
|
26
|
+
locale?: string;
|
|
27
|
+
/**
|
|
28
|
+
* Name of the Content
|
|
29
|
+
*/
|
|
30
|
+
name: string;
|
|
31
|
+
/**
|
|
32
|
+
* Parent SLUG of the Content
|
|
33
|
+
*/
|
|
34
|
+
parentSlug: string;
|
|
35
|
+
/**
|
|
36
|
+
* Date and Time at which the Content was published.
|
|
37
|
+
*/
|
|
38
|
+
publishedAt?: string;
|
|
39
|
+
/**
|
|
40
|
+
* SLUG of the Content
|
|
41
|
+
*/
|
|
42
|
+
slug: string;
|
|
43
|
+
/**
|
|
44
|
+
* Date and Time at which the Content was updated.
|
|
45
|
+
*/
|
|
46
|
+
updatedAt: string;
|
|
47
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"content.js","sourceRoot":"","sources":["../../src/models/content.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/models/index.ts"],"names":[],"mappings":"AAAA,cAAc,WAAW,CAAC;AAC1B,cAAc,iBAAiB,CAAC;AAChC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,oBAAoB,CAAC;AACnC,cAAc,SAAS,CAAC;AACxB,cAAc,gBAAgB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"links.js","sourceRoot":"","sources":["../../src/models/links.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"translations.js","sourceRoot":"","sources":["../../src/models/translations.ts"],"names":[],"mappings":""}
|
package/dist/utils.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function proxyURIFromEnv(): string | undefined;
|
package/dist/utils.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAAA,MAAM,UAAU,eAAe;IAC7B,OAAO,CACL,OAAO,CAAC,GAAG,CAAC,WAAW;QACvB,OAAO,CAAC,GAAG,CAAC,WAAW;QACvB,OAAO,CAAC,GAAG,CAAC,UAAU;QACtB,OAAO,CAAC,GAAG,CAAC,UAAU;QACtB,SAAS,CACV,CAAC;AACJ,CAAC"}
|
package/package.json
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@localess/js-client",
|
|
3
|
+
"version": "0.0.3-20240526-114112.0",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"description": "Universal JavaScript/TypeScript SDK for Localess's API.",
|
|
6
|
+
"keywords": [
|
|
7
|
+
"localess",
|
|
8
|
+
"sdk",
|
|
9
|
+
"api",
|
|
10
|
+
"client",
|
|
11
|
+
"javascript",
|
|
12
|
+
"typescript"
|
|
13
|
+
],
|
|
14
|
+
"author": "Alex Cibotari <alexandru.cibotari@gmail.com>",
|
|
15
|
+
"homepage": "https://localess.org",
|
|
16
|
+
"main": "./dist/index.ts",
|
|
17
|
+
"types": "./dist/index.d.ts",
|
|
18
|
+
"files": [
|
|
19
|
+
"dist"
|
|
20
|
+
],
|
|
21
|
+
"repository": {
|
|
22
|
+
"type": "git",
|
|
23
|
+
"url": "git+https://github.com/Lessify/localess-js-client.git"
|
|
24
|
+
},
|
|
25
|
+
"bugs": {
|
|
26
|
+
"url": "https://github.com/Lessify/localess-js-client/issues"
|
|
27
|
+
},
|
|
28
|
+
"scripts": {
|
|
29
|
+
"build": "tsc -p tsconfig.json"
|
|
30
|
+
},
|
|
31
|
+
"license": "MIT",
|
|
32
|
+
"dependencies": {
|
|
33
|
+
"node-fetch": "^3.0.0",
|
|
34
|
+
"proxy-agent": "^6.0.0"
|
|
35
|
+
},
|
|
36
|
+
"devDependencies": {
|
|
37
|
+
"@types/node": "^20.12.12",
|
|
38
|
+
"typescript": "^5.0.0"
|
|
39
|
+
},
|
|
40
|
+
"engines": {
|
|
41
|
+
"node": ">= 18.0.0"
|
|
42
|
+
}
|
|
43
|
+
}
|