@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 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`)
@@ -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,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AAQ,CAAC,IAAI,EAAE,CAAC;YACnC,OAAO,IAAe,CAAC;QACzB,CAAC;QAED,KAAK,CAAC,cAAc,CAAC,EAAU;YAC7B,MAAM,QAAQ,GAAG,MAAM,KAAK,CAAC,GAAG,IAAI,kBAAkB,OAAO,CAAC,OAAO,aAAa,EAAE,UAAU,OAAO,CAAC,KAAK,GAAG,OAAO,GAAG,MAAM,EAAE,EAAE,YAAY,CAAC,CAAA;YAC/I,MAAM,IAAI,GAAG,MAAM,QAAQ,CAAC,IAAI,EAAE,CAAC;YACnC,OAAO,IAAe,CAAC;QACzB,CAAC;QAED,KAAK,CAAC,eAAe;YACnB,MAAM,QAAQ,GAAG,MAAM,KAAK,CAAC,GAAG,IAAI,kBAAkB,OAAO,CAAC,OAAO,iBAAiB,MAAM,IAAI,IAAI,EAAE,EAAE,YAAY,CAAC,CAAA;YACrH,MAAM,IAAI,GAAG,MAAM,QAAQ,CAAC,IAAI,EAAE,CAAC;YACnC,OAAO,IAAoB,CAAC;QAC9B,CAAC;QAED,aAAa;YACX,OAAO,GAAG,IAAI,qBAAqB,CAAA;QACrC,CAAC;QAED,SAAS,CAAC,KAA4B;YACpC,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE,CAAC;gBAC9B,OAAO,GAAG,IAAI,kBAAkB,OAAO,CAAC,OAAO,WAAW,KAAK,EAAE,CAAC;YACpE,CAAC;iBAAM,CAAC;gBACN,OAAO,GAAG,IAAI,kBAAkB,OAAO,CAAC,OAAO,WAAW,KAAK,CAAC,GAAG,EAAE,CAAC;YACxE,CAAC;QACH,CAAC;KACF,CAAA;AACH,CAAC"}
@@ -0,0 +1,13 @@
1
+ /**
2
+ * Content Asset define reference to a Asset.
3
+ */
4
+ export interface ContentAsset {
5
+ /**
6
+ * Define the type of Asset
7
+ */
8
+ kind: 'ASSET';
9
+ /**
10
+ * Unique identifier for the asset.
11
+ */
12
+ uri: string;
13
+ }
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=content-asset.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"content-asset.js","sourceRoot":"","sources":["../../src/models/content-asset.ts"],"names":[],"mappings":""}
@@ -0,0 +1,4 @@
1
+ /**
2
+ * ContentData defined Object to connect all possible root Schemas.
3
+ */
4
+ export type ContentData = unknown;
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=content-data.js.map
@@ -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,2 @@
1
+ export {};
2
+ //# sourceMappingURL=content-metadata.js.map
@@ -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,2 @@
1
+ export {};
2
+ //# sourceMappingURL=content.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"content.js","sourceRoot":"","sources":["../../src/models/content.ts"],"names":[],"mappings":""}
@@ -0,0 +1,6 @@
1
+ export * from './content';
2
+ export * from './content-asset';
3
+ export * from './content-data';
4
+ export * from './content-metadata';
5
+ export * from './links';
6
+ export * from './translations';
@@ -0,0 +1,7 @@
1
+ export * from './content';
2
+ export * from './content-asset';
3
+ export * from './content-data';
4
+ export * from './content-metadata';
5
+ export * from './links';
6
+ export * from './translations';
7
+ //# sourceMappingURL=index.js.map
@@ -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,7 @@
1
+ import { ContentMetadata } from './content-metadata';
2
+ /**
3
+ * Key-Value Object. Where Key is Unique identifier for the Content object and Value is Content Metadata.
4
+ */
5
+ export interface Links {
6
+ [key: string]: ContentMetadata;
7
+ }
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=links.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"links.js","sourceRoot":"","sources":["../../src/models/links.ts"],"names":[],"mappings":""}
@@ -0,0 +1,6 @@
1
+ /**
2
+ * Key-Value Object. Where Key is Translation ID and Value is Translated Content
3
+ */
4
+ export interface Translations {
5
+ [key: string]: string;
6
+ }
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=translations.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"translations.js","sourceRoot":"","sources":["../../src/models/translations.ts"],"names":[],"mappings":""}
@@ -0,0 +1 @@
1
+ export declare function proxyURIFromEnv(): string | undefined;
package/dist/utils.js ADDED
@@ -0,0 +1,8 @@
1
+ export function proxyURIFromEnv() {
2
+ return (process.env.HTTPS_PROXY ||
3
+ process.env.https_proxy ||
4
+ process.env.HTTP_PROXY ||
5
+ process.env.http_proxy ||
6
+ undefined);
7
+ }
8
+ //# sourceMappingURL=utils.js.map
@@ -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
+ }