@localess/js-client 0.0.4-next.20240527-195458.0 → 0.0.4-next.20240527-202257.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/dist/index.d.ts CHANGED
@@ -1,126 +1,6 @@
1
- /**
2
- * ContentData defined Object to connect all possible root Schemas.
3
- */
4
- type ContentData = any;
5
-
6
- /**
7
- * Content define shared object for all possible Content Types.
8
- */
9
- interface Content {
10
- /**
11
- * Date and Time at which the Content was created.
12
- */
13
- createdAt: string;
14
- data?: ContentData;
15
- /**
16
- * Combination of SLUG and Parent SLUG of the Content
17
- */
18
- fullSlug: string;
19
- /**
20
- * Unique identifier for the object.
21
- */
22
- id: string;
23
- /**
24
- * Define the type of Content, whether it is a FOLDER or DOCUMENT.
25
- */
26
- kind: 'FOLDER' | 'DOCUMENT';
27
- /**
28
- * Locale unique identifier (ISO 639-1).
29
- */
30
- locale?: string;
31
- /**
32
- * Name of the Content
33
- */
34
- name: string;
35
- /**
36
- * Parent SLUG of the Content
37
- */
38
- parentSlug: string;
39
- /**
40
- * Date and Time at which the Content was published.
41
- */
42
- publishedAt?: string;
43
- /**
44
- * SLUG of the Content
45
- */
46
- slug: string;
47
- /**
48
- * Date and Time at which the Content was updated.
49
- */
50
- updatedAt: string;
51
- }
52
-
53
- /**
54
- * Content Asset define reference to a Asset.
55
- */
56
- interface ContentAsset {
57
- /**
58
- * Define the type of Asset
59
- */
60
- kind: 'ASSET';
61
- /**
62
- * Unique identifier for the asset.
63
- */
64
- uri: string;
65
- }
66
-
67
- /**
68
- * Content Metadata define short information about a Content for navigation reason.
69
- */
70
- interface ContentMetadata {
71
- /**
72
- * Date and Time at which the Content was created.
73
- */
74
- createdAt: string;
75
- /**
76
- * Combination of SLUG and Parent SLUG of the Content
77
- */
78
- fullSlug: string;
79
- /**
80
- * Unique identifier for the object.
81
- */
82
- id: string;
83
- /**
84
- * Define the type of Content, whether it is a FOLDER or DOCUMENT.
85
- */
86
- kind: 'FOLDER' | 'DOCUMENT';
87
- /**
88
- * Name of the Content
89
- */
90
- name: string;
91
- /**
92
- * Parent SLUG of the Content
93
- */
94
- parentSlug: string;
95
- /**
96
- * Date and Time at which the Content was published.
97
- */
98
- publishedAt?: string;
99
- /**
100
- * SLUG of the Content
101
- */
102
- slug: string;
103
- /**
104
- * Date and Time at which the Content was updated.
105
- */
106
- updatedAt: string;
107
- }
108
-
109
- /**
110
- * Key-Value Object. Where Key is Unique identifier for the Content object and Value is Content Metadata.
111
- */
112
- interface Links {
113
- [key: string]: ContentMetadata;
114
- }
115
-
116
- /**
117
- * Key-Value Object. Where Key is Translation ID and Value is Translated Content
118
- */
119
- interface Translations {
120
- [key: string]: string;
121
- }
122
-
123
- type LocalessClientOptions = {
1
+ import { Content, ContentAsset, Links, Translations } from "./models";
2
+ export * from './models';
3
+ export type LocalessClientOptions = {
124
4
  /**
125
5
  * A fully qualified domain name with protocol (http/https) and port.
126
6
  *
@@ -140,7 +20,7 @@ type LocalessClientOptions = {
140
20
  */
141
21
  debug?: boolean;
142
22
  };
143
- type ContentFetchParams = {
23
+ export type ContentFetchParams = {
144
24
  /**
145
25
  * Content version to fetch, leave empty for 'published' or 'draft' for the latest draft
146
26
  */
@@ -152,7 +32,7 @@ type ContentFetchParams = {
152
32
  */
153
33
  locale?: string;
154
34
  };
155
- declare function localessClient(options: LocalessClientOptions): {
35
+ export declare function localessClient(options: LocalessClientOptions): {
156
36
  /**
157
37
  * Get all links
158
38
  * @returns {Promise<Links>}
@@ -196,5 +76,3 @@ declare global {
196
76
  localess?: LocalessSync;
197
77
  }
198
78
  }
199
-
200
- export { type Content, type ContentAsset, type ContentData, type ContentFetchParams, type ContentMetadata, type Links, type LocalessClientOptions, type Translations, localessClient };
package/dist/index.js CHANGED
@@ -1 +1,114 @@
1
- "use strict";var m=Object.create;var x=Object.defineProperty;var E=Object.getOwnPropertyDescriptor;var B=Object.getOwnPropertyNames;var d=Object.getPrototypeOf,T=Object.prototype.hasOwnProperty;var R=(t,o)=>{for(var e in o)x(t,e,{get:o[e],enumerable:!0})},g=(t,o,e,n)=>{if(o&&typeof o=="object"||typeof o=="function")for(let s of B(o))!T.call(t,s)&&s!==e&&x(t,s,{get:()=>o[s],enumerable:!(n=E(o,s))||n.enumerable});return t};var I=(t,o,e)=>(e=t!=null?m(d(t)):{},g(o||!t||!t.__esModule?x(e,"default",{value:t,enumerable:!0}):e,t)),v=t=>g(x({},"__esModule",{value:!0}),t);var y={};R(y,{localessClient:()=>f});module.exports=v(y);var u=require("proxy-agent"),l=I(require("node-fetch"));function p(){return process.env.HTTPS_PROXY||process.env.https_proxy||process.env.HTTP_PROXY||process.env.http_proxy||void 0}var b="\x1B[0m";var G="\x1B[34m";var r=`${G}[Localess]${b}`;function f(t){t.debug&&console.log(r,"Client Options :",t);let o={redirect:"follow"};return p()&&(o.agent=new u.ProxyAgent),{async getLinks(){t.debug&&console.log(r,"getLinks()");let e=`${t.origin}/api/v1/spaces/${t.spaceId}/links?token=${t.token}`;t.debug&&console.log(r,"getLinks url :",e);let n=await(0,l.default)(e,o);return t.debug&&console.log(r,"getLinks status :",n.status),await n.json()},async getContentBySlug(e,n){t.debug&&console.log(r,"getContentBySlug() slug :",e);let s=n?.version=="draft"?`&version=${n.version}`:"",i=n?.locale?`&locale=${n.locale}`:"",c=`${t.origin}/api/v1/spaces/${t.spaceId}/contents/slugs/${e}?token=${t.token}${s}${i}`;t.debug&&console.log(r,"getContentBySlug url :",c);let a=await(0,l.default)(c,o);return t.debug&&console.log(r,"getContentBySlug status :",a.status),await a.json()},async getContentById(e,n){t.debug&&console.log(r,"getContentById() id :",e);let s=n?.version=="draft"?`&version=${n.version}`:"",i=n?.locale?`&locale=${n.locale}`:"",c=`${t.origin}/api/v1/spaces/${t.spaceId}/contents/${e}?token=${t.token}${s}${i}`;t.debug&&console.log(r,"getContentById url :",c);let a=await(0,l.default)(c,o);return t.debug&&console.log(r,"getContentById status :",a.status),await a.json()},async getTranslations(e){t.debug&&console.log(r,"getTranslations()");let n=`${t.origin}/api/v1/spaces/${t.spaceId}/translations/${e}`;t.debug&&console.log(r,"getTranslations url :",n);let s=await(0,l.default)(n,o);return t.debug&&console.log(r,"getTranslations status :",s.status),await s.json()},syncScriptUrl(){return`${t.origin}/scripts/sync-v1.js`},assetLink(e){return typeof e=="string"?`${t.origin}/api/v1/spaces/${t.spaceId}/assets/${e}`:`${t.origin}/api/v1/spaces/${t.spaceId}/assets/${e.uri}`}}}0&&(module.exports={localessClient});
1
+ import { ProxyAgent } from 'proxy-agent';
2
+ import fetch from 'node-fetch';
3
+ import { FG_BLUE, proxyURIFromEnv, RESET } from "./utils";
4
+ export * from './models';
5
+ const LOG_GROUP = `${FG_BLUE}[Localess]${RESET}`;
6
+ export function localessClient(options) {
7
+ if (options.debug) {
8
+ console.log(LOG_GROUP, 'Client Options :', options);
9
+ }
10
+ const fetchOptions = {
11
+ redirect: 'follow',
12
+ };
13
+ if (proxyURIFromEnv()) {
14
+ fetchOptions.agent = new ProxyAgent();
15
+ }
16
+ return {
17
+ /**
18
+ * Get all links
19
+ * @returns {Promise<Links>}
20
+ */
21
+ async getLinks() {
22
+ if (options.debug) {
23
+ console.log(LOG_GROUP, 'getLinks()');
24
+ }
25
+ let url = `${options.origin}/api/v1/spaces/${options.spaceId}/links?token=${options.token}`;
26
+ if (options.debug) {
27
+ console.log(LOG_GROUP, 'getLinks url :', url);
28
+ }
29
+ const response = await fetch(url, fetchOptions);
30
+ if (options.debug) {
31
+ console.log(LOG_GROUP, 'getLinks status :', response.status);
32
+ }
33
+ const data = await response.json();
34
+ return data;
35
+ },
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) {
43
+ if (options.debug) {
44
+ console.log(LOG_GROUP, 'getContentBySlug() slug :', slug);
45
+ }
46
+ const version = params?.version == 'draft' ? `&version=${params.version}` : '';
47
+ const locale = params?.locale ? `&locale=${params.locale}` : '';
48
+ let url = `${options.origin}/api/v1/spaces/${options.spaceId}/contents/slugs/${slug}?token=${options.token}${version}${locale}`;
49
+ if (options.debug) {
50
+ console.log(LOG_GROUP, 'getContentBySlug url :', url);
51
+ }
52
+ const response = await fetch(url, fetchOptions);
53
+ if (options.debug) {
54
+ console.log(LOG_GROUP, 'getContentBySlug status :', response.status);
55
+ }
56
+ const data = await response.json();
57
+ return data;
58
+ },
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) {
66
+ if (options.debug) {
67
+ console.log(LOG_GROUP, 'getContentById() id :', id);
68
+ }
69
+ const version = params?.version == 'draft' ? `&version=${params.version}` : '';
70
+ const locale = params?.locale ? `&locale=${params.locale}` : '';
71
+ let url = `${options.origin}/api/v1/spaces/${options.spaceId}/contents/${id}?token=${options.token}${version}${locale}`;
72
+ if (options.debug) {
73
+ console.log(LOG_GROUP, 'getContentById url :', url);
74
+ }
75
+ const response = await fetch(url, fetchOptions);
76
+ if (options.debug) {
77
+ console.log(LOG_GROUP, 'getContentById status :', response.status);
78
+ }
79
+ const data = await response.json();
80
+ return data;
81
+ },
82
+ /**
83
+ * Get translations for the given locale
84
+ * @param locale{string} - Locale identifier (ISO 639-1)
85
+ */
86
+ async getTranslations(locale) {
87
+ if (options.debug) {
88
+ console.log(LOG_GROUP, 'getTranslations()');
89
+ }
90
+ let url = `${options.origin}/api/v1/spaces/${options.spaceId}/translations/${locale}`;
91
+ if (options.debug) {
92
+ console.log(LOG_GROUP, 'getTranslations url :', url);
93
+ }
94
+ const response = await fetch(url, fetchOptions);
95
+ if (options.debug) {
96
+ console.log(LOG_GROUP, 'getTranslations status :', response.status);
97
+ }
98
+ const data = await response.json();
99
+ return data;
100
+ },
101
+ syncScriptUrl() {
102
+ return `${options.origin}/scripts/sync-v1.js`;
103
+ },
104
+ assetLink(asset) {
105
+ if (typeof asset === 'string') {
106
+ return `${options.origin}/api/v1/spaces/${options.spaceId}/assets/${asset}`;
107
+ }
108
+ else {
109
+ return `${options.origin}/api/v1/spaces/${options.spaceId}/assets/${asset.uri}`;
110
+ }
111
+ }
112
+ };
113
+ }
114
+ //# 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;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,GAAG,GAAG,OAAO,CAAC,MAAM,kBAAkB,OAAO,CAAC,OAAO,gBAAgB,OAAO,CAAC,KAAK,EAAE,CAAC;YAC5F,IAAI,OAAO,CAAC,KAAK,EAAE,CAAC;gBAClB,OAAO,CAAC,GAAG,CAAC,SAAS,E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/**
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 = any;
@@ -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,40 @@
1
+ export declare function proxyURIFromEnv(): string | undefined;
2
+ export declare const RESET = "\u001B[0m";
3
+ export declare const BRIGHT = "\u001B[1m";
4
+ export declare const DIM = "\u001B[2m";
5
+ export declare const UNDERSCORE = "\u001B[4m";
6
+ export declare const BLINK = "\u001B[5m";
7
+ export declare const REVERSE = "\u001B[7m";
8
+ export declare const HIDDEN = "\u001B[8m";
9
+ export declare const FG_BLACK = "\u001B[30m";
10
+ export declare const FG_RED = "\u001B[31m";
11
+ export declare const FG_GREEN = "\u001B[32m";
12
+ export declare const FG_YELLOW = "\u001B[33m";
13
+ export declare const FG_BLUE = "\u001B[34m";
14
+ export declare const FG_MAGENTA = "\u001B[35m";
15
+ export declare const FG_CYAN = "\u001B[36m";
16
+ export declare const FG_WHITE = "\u001B[37m";
17
+ export declare const FG_GRAY = "\u001B[90m";
18
+ export declare const FG_BRIGHT_RED = "\u001B[91m";
19
+ export declare const FG_BRIGHT_GREEN = "\u001B[92m";
20
+ export declare const FG_BRIGHT_YELLOW = "\u001B[93m";
21
+ export declare const FG_BRIGHT_BLUE = "\u001B[94m";
22
+ export declare const FG_BRIGHT_MAGENTA = "\u001B[95m";
23
+ export declare const FG_BRIGHT_CYAN = "\u001B[96m";
24
+ export declare const FG_BRIGHT_WHITE = "\u001B[97m";
25
+ export declare const BG_BLACK = "\u001B[40m";
26
+ export declare const BG_RED = "\u001B[41m";
27
+ export declare const BG_GREEN = "\u001B[42m";
28
+ export declare const BG_YELLOW = "\u001B[43m";
29
+ export declare const BG_BLUE = "\u001B[44m";
30
+ export declare const BG_MAGENTA = "\u001B[45m";
31
+ export declare const BG_CYAN = "\u001B[46m";
32
+ export declare const BG_WHITE = "\u001B[47m";
33
+ export declare const BG_GRAY = "\u001B[100m";
34
+ export declare const BG_BRIGHT_RED = "\u001B[101m";
35
+ export declare const BG_BRIGHT_GREEN = "\u001B[102m";
36
+ export declare const BG_BRIGHT_YELLOW = "\u001B[103m";
37
+ export declare const BG_BRIGHT_BLUE = "\u001B[104m";
38
+ export declare const BG_BRIGHT_MAGENTA = "\u001B[105m";
39
+ export declare const BG_BRIGHT_CYAN = "\u001B[106m";
40
+ export declare const BG_BRIGHT_WHITE = "\u001B[107m";
package/dist/utils.js ADDED
@@ -0,0 +1,47 @@
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
+ export const RESET = "\x1b[0m";
9
+ export const BRIGHT = "\x1b[1m";
10
+ export const DIM = "\x1b[2m";
11
+ export const UNDERSCORE = "\x1b[4m";
12
+ export const BLINK = "\x1b[5m";
13
+ export const REVERSE = "\x1b[7m";
14
+ export const HIDDEN = "\x1b[8m";
15
+ export const FG_BLACK = "\x1b[30m";
16
+ export const FG_RED = "\x1b[31m";
17
+ export const FG_GREEN = "\x1b[32m";
18
+ export const FG_YELLOW = "\x1b[33m";
19
+ export const FG_BLUE = "\x1b[34m";
20
+ export const FG_MAGENTA = "\x1b[35m";
21
+ export const FG_CYAN = "\x1b[36m";
22
+ export const FG_WHITE = "\x1b[37m";
23
+ export const FG_GRAY = "\x1b[90m";
24
+ export const FG_BRIGHT_RED = "\x1b[91m";
25
+ export const FG_BRIGHT_GREEN = "\x1b[92m";
26
+ export const FG_BRIGHT_YELLOW = "\x1b[93m";
27
+ export const FG_BRIGHT_BLUE = "\x1b[94m";
28
+ export const FG_BRIGHT_MAGENTA = "\x1b[95m";
29
+ export const FG_BRIGHT_CYAN = "\x1b[96m";
30
+ export const FG_BRIGHT_WHITE = "\x1b[97m";
31
+ export const BG_BLACK = "\x1b[40m";
32
+ export const BG_RED = "\x1b[41m";
33
+ export const BG_GREEN = "\x1b[42m";
34
+ export const BG_YELLOW = "\x1b[43m";
35
+ export const BG_BLUE = "\x1b[44m";
36
+ export const BG_MAGENTA = "\x1b[45m";
37
+ export const BG_CYAN = "\x1b[46m";
38
+ export const BG_WHITE = "\x1b[47m";
39
+ export const BG_GRAY = "\x1b[100m";
40
+ export const BG_BRIGHT_RED = "\x1b[101m";
41
+ export const BG_BRIGHT_GREEN = "\x1b[102m";
42
+ export const BG_BRIGHT_YELLOW = "\x1b[103m";
43
+ export const BG_BRIGHT_BLUE = "\x1b[104m";
44
+ export const BG_BRIGHT_MAGENTA = "\x1b[105m";
45
+ export const BG_BRIGHT_CYAN = "\x1b[106m";
46
+ export const BG_BRIGHT_WHITE = "\x1b[107m";
47
+ //# 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;AAGD,MAAM,CAAC,MAAM,KAAK,GAAG,SAAS,CAA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MAAM,CAAC,MAAM,SAAS,GAAG,UAAU,CAAA;AACnC,MAAM,CAAC,MAAM,OAAO,GAAG,UAAU,CAAA;AACjC,MAAM,CAAC,MAAM,UAAU,GAAG,UAAU,CAAA;AACpC,MAAM,CAAC,MAAM,OAAO,GAAG,UAAU,CAAA;AACjC,MAAM,CAAC,MAAM,QAAQ,GAAG,UAAU,CAAA;AAClC,MAAM,CAAC,MAAM,OAAO,GAAG,WAAW,CAAA;AAElC,MAAM,CAAC,MAAM,aAAa,GAAG,WAAW,CAAA;AACxC,MAAM,CAAC,MAAM,eAAe,GAAG,WAAW,CAAA;AAC1C,MAAM,CAAC,MAAM,gBAAgB,GAAG,WAAW,CAAA;AAC3C,MAAM,CAAC,MAAM,cAAc,GAAG,WAAW,CAAA;AACzC,MAAM,CAAC,MAAM,iBAAiB,GAAG,WAAW,CAAA;AAC5C,MAAM,CAAC,MAAM,cAAc,GAAG,WAAW,CAAA;AACzC,MAAM,CAAC,MAAM,eAAe,GAAG,WAAW,CAAA"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@localess/js-client",
3
- "version": "0.0.4-next.20240527-195458.0",
3
+ "version": "0.0.4-next.20240527-202257.0",
4
4
  "description": "Universal JavaScript/TypeScript SDK for Localess's API.",
5
5
  "keywords": [
6
6
  "localess",
@@ -13,14 +13,11 @@
13
13
  "author": "Lessify",
14
14
  "homepage": "https://localess.org",
15
15
  "sideEffects": false,
16
+ "main": "./dist/index.js",
17
+ "types": "./dist/index.d.ts",
16
18
  "files": [
17
19
  "dist"
18
20
  ],
19
- "exports": {
20
- "types": "./dist/index.d.ts",
21
- "require": "./dist/index.js",
22
- "import": "./dist/index.mjs"
23
- },
24
21
  "repository": {
25
22
  "type": "git",
26
23
  "url": "git+https://github.com/Lessify/localess-js-client.git"
@@ -29,7 +26,7 @@
29
26
  "url": "https://github.com/Lessify/localess-js-client/issues"
30
27
  },
31
28
  "scripts": {
32
- "build": "tsup-node --env.NODE_ENV production",
29
+ "build": "tsc -p tsconfig.json",
33
30
  "build:tsc": "tsc -p tsconfig.json",
34
31
  "build:tsup": "tsup-node --env.NODE_ENV production"
35
32
  },
package/dist/index.d.mts DELETED
@@ -1,200 +0,0 @@
1
- /**
2
- * ContentData defined Object to connect all possible root Schemas.
3
- */
4
- type ContentData = any;
5
-
6
- /**
7
- * Content define shared object for all possible Content Types.
8
- */
9
- interface Content {
10
- /**
11
- * Date and Time at which the Content was created.
12
- */
13
- createdAt: string;
14
- data?: ContentData;
15
- /**
16
- * Combination of SLUG and Parent SLUG of the Content
17
- */
18
- fullSlug: string;
19
- /**
20
- * Unique identifier for the object.
21
- */
22
- id: string;
23
- /**
24
- * Define the type of Content, whether it is a FOLDER or DOCUMENT.
25
- */
26
- kind: 'FOLDER' | 'DOCUMENT';
27
- /**
28
- * Locale unique identifier (ISO 639-1).
29
- */
30
- locale?: string;
31
- /**
32
- * Name of the Content
33
- */
34
- name: string;
35
- /**
36
- * Parent SLUG of the Content
37
- */
38
- parentSlug: string;
39
- /**
40
- * Date and Time at which the Content was published.
41
- */
42
- publishedAt?: string;
43
- /**
44
- * SLUG of the Content
45
- */
46
- slug: string;
47
- /**
48
- * Date and Time at which the Content was updated.
49
- */
50
- updatedAt: string;
51
- }
52
-
53
- /**
54
- * Content Asset define reference to a Asset.
55
- */
56
- interface ContentAsset {
57
- /**
58
- * Define the type of Asset
59
- */
60
- kind: 'ASSET';
61
- /**
62
- * Unique identifier for the asset.
63
- */
64
- uri: string;
65
- }
66
-
67
- /**
68
- * Content Metadata define short information about a Content for navigation reason.
69
- */
70
- interface ContentMetadata {
71
- /**
72
- * Date and Time at which the Content was created.
73
- */
74
- createdAt: string;
75
- /**
76
- * Combination of SLUG and Parent SLUG of the Content
77
- */
78
- fullSlug: string;
79
- /**
80
- * Unique identifier for the object.
81
- */
82
- id: string;
83
- /**
84
- * Define the type of Content, whether it is a FOLDER or DOCUMENT.
85
- */
86
- kind: 'FOLDER' | 'DOCUMENT';
87
- /**
88
- * Name of the Content
89
- */
90
- name: string;
91
- /**
92
- * Parent SLUG of the Content
93
- */
94
- parentSlug: string;
95
- /**
96
- * Date and Time at which the Content was published.
97
- */
98
- publishedAt?: string;
99
- /**
100
- * SLUG of the Content
101
- */
102
- slug: string;
103
- /**
104
- * Date and Time at which the Content was updated.
105
- */
106
- updatedAt: string;
107
- }
108
-
109
- /**
110
- * Key-Value Object. Where Key is Unique identifier for the Content object and Value is Content Metadata.
111
- */
112
- interface Links {
113
- [key: string]: ContentMetadata;
114
- }
115
-
116
- /**
117
- * Key-Value Object. Where Key is Translation ID and Value is Translated Content
118
- */
119
- interface Translations {
120
- [key: string]: string;
121
- }
122
-
123
- type LocalessClientOptions = {
124
- /**
125
- * A fully qualified domain name with protocol (http/https) and port.
126
- *
127
- * Example: https://my-localess.web.app
128
- */
129
- origin: string;
130
- /**
131
- * Localess space ID, cna be found in the Localess Space settings
132
- */
133
- spaceId: string;
134
- /**
135
- * Localess API token, can be found in the Localess Space settings
136
- */
137
- token: string;
138
- /**
139
- * Enable debug mode
140
- */
141
- debug?: boolean;
142
- };
143
- type ContentFetchParams = {
144
- /**
145
- * Content version to fetch, leave empty for 'published' or 'draft' for the latest draft
146
- */
147
- version?: 'draft' | string;
148
- /**
149
- * Locale identifier (ISO 639-1) to fetch content in, leave empty for default locale.
150
- *
151
- * Example: en
152
- */
153
- locale?: string;
154
- };
155
- declare function localessClient(options: LocalessClientOptions): {
156
- /**
157
- * Get all links
158
- * @returns {Promise<Links>}
159
- */
160
- getLinks(): Promise<Links>;
161
- /**
162
- * Get content by SLUG
163
- * @param slug{string} - Content SLUG
164
- * @param params{ContentFetchParams} - Fetch parameters
165
- * @returns {Promise<Content>}
166
- */
167
- getContentBySlug(slug: string, params?: ContentFetchParams): Promise<Content>;
168
- /**
169
- * Get content by ID
170
- * @param id{string} - Content ID
171
- * @param params{ContentFetchParams} - Fetch parameters
172
- * @returns {Promise<Content>}
173
- */
174
- getContentById(id: string, params?: ContentFetchParams): Promise<Content>;
175
- /**
176
- * Get translations for the given locale
177
- * @param locale{string} - Locale identifier (ISO 639-1)
178
- */
179
- getTranslations(locale: string): Promise<Translations>;
180
- syncScriptUrl(): string;
181
- assetLink(asset: ContentAsset | string): string;
182
- };
183
- declare global {
184
- type EventType = 'input' | 'save' | 'publish' | 'change';
185
- type EventCallback = (event: EventToApp) => void;
186
- type EventToApp = {
187
- type: 'save' | 'publish';
188
- } | {
189
- type: 'input' | 'change';
190
- data: any;
191
- };
192
- interface LocalessSync {
193
- on: (event: EventType | EventType[], callback: EventCallback) => void;
194
- }
195
- interface Window {
196
- localess?: LocalessSync;
197
- }
198
- }
199
-
200
- export { type Content, type ContentAsset, type ContentData, type ContentFetchParams, type ContentMetadata, type Links, type LocalessClientOptions, type Translations, localessClient };
package/dist/index.mjs DELETED
@@ -1 +0,0 @@
1
- import{ProxyAgent as G}from"proxy-agent";import i from"node-fetch";function x(){return process.env.HTTPS_PROXY||process.env.https_proxy||process.env.HTTP_PROXY||process.env.http_proxy||void 0}var g="\x1B[0m";var p="\x1B[34m";var o=`${p}[Localess]${g}`;function d(t){t.debug&&console.log(o,"Client Options :",t);let r={redirect:"follow"};return x()&&(r.agent=new G),{async getLinks(){t.debug&&console.log(o,"getLinks()");let n=`${t.origin}/api/v1/spaces/${t.spaceId}/links?token=${t.token}`;t.debug&&console.log(o,"getLinks url :",n);let e=await i(n,r);return t.debug&&console.log(o,"getLinks status :",e.status),await e.json()},async getContentBySlug(n,e){t.debug&&console.log(o,"getContentBySlug() slug :",n);let s=e?.version=="draft"?`&version=${e.version}`:"",l=e?.locale?`&locale=${e.locale}`:"",c=`${t.origin}/api/v1/spaces/${t.spaceId}/contents/slugs/${n}?token=${t.token}${s}${l}`;t.debug&&console.log(o,"getContentBySlug url :",c);let a=await i(c,r);return t.debug&&console.log(o,"getContentBySlug status :",a.status),await a.json()},async getContentById(n,e){t.debug&&console.log(o,"getContentById() id :",n);let s=e?.version=="draft"?`&version=${e.version}`:"",l=e?.locale?`&locale=${e.locale}`:"",c=`${t.origin}/api/v1/spaces/${t.spaceId}/contents/${n}?token=${t.token}${s}${l}`;t.debug&&console.log(o,"getContentById url :",c);let a=await i(c,r);return t.debug&&console.log(o,"getContentById status :",a.status),await a.json()},async getTranslations(n){t.debug&&console.log(o,"getTranslations()");let e=`${t.origin}/api/v1/spaces/${t.spaceId}/translations/${n}`;t.debug&&console.log(o,"getTranslations url :",e);let s=await i(e,r);return t.debug&&console.log(o,"getTranslations status :",s.status),await s.json()},syncScriptUrl(){return`${t.origin}/scripts/sync-v1.js`},assetLink(n){return typeof n=="string"?`${t.origin}/api/v1/spaces/${t.spaceId}/assets/${n}`:`${t.origin}/api/v1/spaces/${t.spaceId}/assets/${n.uri}`}}}export{d as localessClient};