@localess/client 3.0.1-dev.20260410071322 → 3.0.1-dev.20260412201733

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.
@@ -0,0 +1,29 @@
1
+ export interface ICache<V> {
2
+ set(key: string, value: V): void;
3
+ get(key: string): V | undefined;
4
+ has(key: string): boolean;
5
+ }
6
+ export declare class Cache<V> implements ICache<V> {
7
+ private cache;
8
+ set(key: string, value: V): void;
9
+ get(key: string): V | undefined;
10
+ has(key: string): boolean;
11
+ }
12
+ export declare class NoCache<V> implements ICache<V> {
13
+ set(key: string, value: V): void;
14
+ get(key: string): V | undefined;
15
+ has(key: string): boolean;
16
+ }
17
+ export declare class TTLCache<V> {
18
+ private ttlMs;
19
+ private cache;
20
+ /**
21
+ * Creates a TTLCache with a specified time-to-live (TTL) for each entry.
22
+ * default is 5 minutes (300000 ms).
23
+ * @param ttlMs
24
+ */
25
+ constructor(ttlMs?: number);
26
+ set(key: string, value: V): void;
27
+ get(key: string): V | undefined;
28
+ has(key: string): boolean;
29
+ }
@@ -0,0 +1,102 @@
1
+ import { Content, ContentAsset, ContentData, Links, Translations } from './models';
2
+ export type LocalessClientOptions = {
3
+ /**
4
+ * A fully qualified domain name with protocol (http/https) and port.
5
+ *
6
+ * Example: https://my-localess.web.app
7
+ */
8
+ origin: string;
9
+ /**
10
+ * Localess space ID can be found in the Localess Space settings
11
+ */
12
+ spaceId: string;
13
+ /**
14
+ * Localess API token can be found in the Localess Space settings
15
+ */
16
+ token: string;
17
+ /**
18
+ * Content version to fetch, leave empty for 'published' or 'draft' for the latest draft
19
+ */
20
+ version?: 'draft' | string;
21
+ /**
22
+ * Enable debug mode
23
+ */
24
+ debug?: boolean;
25
+ /**
26
+ * Cache TTL (time to live) for API responses. Default is 5 minutes (300000 ms).
27
+ * Set to false to disable caching.
28
+ */
29
+ cacheTTL?: number | false;
30
+ };
31
+ export type LinksFetchParams = {
32
+ /**
33
+ * Content Kind. FOLDER or DOCUMENT. If not provided, it will return all.
34
+ * @example 'DOCUMENT'
35
+ */
36
+ kind?: 'DOCUMENT' | 'FOLDER';
37
+ /**
38
+ * Content parent slug.
39
+ * @example 'legal/policy'
40
+ */
41
+ parentSlug?: string;
42
+ /**
43
+ * If **true**, exclude all sub slugs, otherwise include all content under current selected **parent slug**.
44
+ * @example false
45
+ */
46
+ excludeChildren?: boolean;
47
+ };
48
+ export type ContentFetchParams = {
49
+ /**
50
+ * Content version to fetch, leave empty for 'published' or 'draft' for the latest draft.
51
+ * Overrides the version set in the client options.
52
+ */
53
+ version?: 'draft';
54
+ /**
55
+ * Locale identifier (ISO 639-1) to fetch content in, leave empty for default locale.
56
+ *
57
+ * Example: en
58
+ */
59
+ locale?: string;
60
+ /**
61
+ * Resolve references in the content data. Default is false.
62
+ */
63
+ resolveReference?: boolean;
64
+ /**
65
+ * Resolve links in the content data. Default is false.
66
+ */
67
+ resolveLink?: boolean;
68
+ };
69
+ export interface LocalessClient {
70
+ /**
71
+ * Get all links
72
+ * @param params{LinksFetchParams} - Fetch parameters
73
+ * @returns {Promise<Links>}
74
+ */
75
+ getLinks(params?: LinksFetchParams): Promise<Links>;
76
+ /**
77
+ * Get content by SLUG
78
+ * @param slug{string} - Content SLUG
79
+ * @param params{ContentFetchParams} - Fetch parameters
80
+ * @returns {Promise<Content>}
81
+ */
82
+ getContentBySlug<T extends ContentData = ContentData>(slug: string, params?: ContentFetchParams): Promise<Content<T>>;
83
+ /**
84
+ * Get content by ID
85
+ * @param id{string} - Content ID
86
+ * @param params{ContentFetchParams} - Fetch parameters
87
+ * @returns {Promise<Content>}
88
+ */
89
+ getContentById<T extends ContentData = ContentData>(id: string, params?: ContentFetchParams): Promise<Content<T>>;
90
+ /**
91
+ * Get translations for the given locale
92
+ * @param locale{string} - Locale identifier (ISO 639-1)
93
+ */
94
+ getTranslations(locale: string): Promise<Translations>;
95
+ syncScriptUrl(): string;
96
+ assetLink(asset: ContentAsset | string): string;
97
+ }
98
+ /**
99
+ * Create a Localess API Client
100
+ * @param {LocalessClientOptions} options connection details
101
+ */
102
+ export declare function localessClient(options: LocalessClientOptions): LocalessClient;
@@ -0,0 +1,19 @@
1
+ import { ContentData, ContentDataSchema } from './models';
2
+ /**
3
+ * Adds Localess editable attributes to a content item.
4
+ * @param content
5
+ * @returns An object containing data-ll-id and data-ll-schema attributes.
6
+ */
7
+ export declare function localessEditable(content: ContentDataSchema): {
8
+ 'data-ll-id': string;
9
+ 'data-ll-schema': string;
10
+ };
11
+ /**
12
+ * Adds Localess editable field attribute to a specific field.
13
+ * Added type safety to ensure fieldName is a valid key of the content data excluding base schema fields.
14
+ * @param fieldName
15
+ * @returns An object containing data-ll-field attribute.
16
+ */
17
+ export declare function localessEditableField<T extends ContentData = ContentData>(fieldName: Exclude<keyof T, keyof ContentDataSchema>): {
18
+ 'data-ll-field': Exclude<keyof T, keyof ContentDataSchema>;
19
+ };
package/dist/index.d.ts CHANGED
@@ -1,318 +1,11 @@
1
- /**
2
- * Content Asset defines reference to an Asset.
3
- */
4
- 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
- }
14
-
15
- /**
16
- * Content Link define reference to a Link.
17
- */
18
- interface ContentLink {
19
- /**
20
- * Define the type of Link
21
- */
22
- kind: 'LINK';
23
- /**
24
- * Define the target of the link. _blank for the new tab and _self for the same tab.
25
- */
26
- target: '_blank' | '_self';
27
- /**
28
- * Define the type of Link. URL for external links and Content for internal links.
29
- */
30
- type: 'url' | 'content';
31
- /**
32
- * If the type is content, then it will be Content ID. Otherwise, it will be URL.
33
- */
34
- uri: string;
35
- }
36
-
37
- /**
38
- * Content RichText define content as JSON Object.
39
- */
40
- interface ContentRichText {
41
- /**
42
- * Define the type of Content Node
43
- */
44
- type?: string;
45
- /**
46
- * List of Content Nodes
47
- */
48
- content?: ContentRichText[];
49
- }
50
-
51
- /**
52
- * Content Reference defines reference to a Content.
53
- */
54
- interface ContentReference {
55
- /**
56
- * Define the type of REFERENCE
57
- */
58
- kind: 'REFERENCE';
59
- /**
60
- * Unique identifier for the Content Document.
61
- */
62
- uri: string;
63
- }
64
-
65
- type ContentDataField = any | string | string[] | number | boolean | ContentLink | ContentRichText | ContentData | ContentData[] | ContentAsset | ContentAsset[] | ContentReference | ContentReference[];
66
- /**
67
- * Content Data Schema related information.
68
- */
69
- interface ContentDataSchema {
70
- /**
71
- * Unique identifier of a component in a content.
72
- */
73
- _id: string;
74
- /**
75
- * Unique identifier for the Schema object.
76
- */
77
- _schema: string;
78
- }
79
- /**
80
- * ContentData defined Object to connect all possible root Schemas.
81
- */
82
- interface ContentData extends ContentDataSchema {
83
- /**
84
- * Other Schema-specific fields
85
- */
86
- [field: string]: ContentDataField | undefined;
87
- }
88
-
89
- /**
90
- * Content Metadata defines short information about a Content for navigation reason.
91
- */
92
- interface ContentMetadata {
93
- /**
94
- * Date and Time at which the Content was created.
95
- */
96
- createdAt: string;
97
- /**
98
- * Combination of SLUG and Parent SLUG of the Content
99
- */
100
- fullSlug: string;
101
- /**
102
- * Unique identifier for the object.
103
- */
104
- id: string;
105
- /**
106
- * Define the type of Content, whether it is a FOLDER or DOCUMENT.
107
- */
108
- kind: 'FOLDER' | 'DOCUMENT';
109
- /**
110
- * Name of the Content
111
- */
112
- name: string;
113
- /**
114
- * Parent SLUG of the Content
115
- */
116
- parentSlug: string;
117
- /**
118
- * Date and Time at which the Content was published.
119
- */
120
- publishedAt?: string;
121
- /**
122
- * SLUG of the Content
123
- */
124
- slug: string;
125
- /**
126
- * Date and Time at which the Content was updated.
127
- */
128
- updatedAt: string;
129
- }
130
-
131
- /**
132
- * Key-Value Object. Where Key is a Unique identifier for the Content object and Value is Content Metadata.
133
- */
134
- interface Links {
135
- [key: string]: ContentMetadata;
136
- }
137
-
138
- /**
139
- * Key-Value Object. Where Key is a Unique identifier for the Content object and Value is Content.
140
- */
141
- interface References {
142
- [key: string]: Content;
143
- }
144
-
145
- /**
146
- * Content defines a shared object for all possible Content Types.
147
- */
148
- interface Content<T extends ContentData = ContentData> extends ContentMetadata {
149
- /**
150
- * Content Data
151
- */
152
- data?: T;
153
- /**
154
- * All links used in the content.
155
- */
156
- links?: Links;
157
- /**
158
- * All references used in the content.
159
- */
160
- references?: References;
161
- }
162
-
163
- interface Locale {
164
- /**
165
- * Unique identifier for the Locale.
166
- */
167
- id: string;
168
- /**
169
- * Name of the Locale.
170
- */
171
- name: string;
172
- }
173
-
174
- /**
175
- * Key-Value Object. Where Key is Translation ID and Value is Translated Content
176
- */
177
- interface Translations {
178
- [key: string]: string;
179
- }
180
-
181
- type LocalessClientOptions = {
182
- /**
183
- * A fully qualified domain name with protocol (http/https) and port.
184
- *
185
- * Example: https://my-localess.web.app
186
- */
187
- origin: string;
188
- /**
189
- * Localess space ID can be found in the Localess Space settings
190
- */
191
- spaceId: string;
192
- /**
193
- * Localess API token can be found in the Localess Space settings
194
- */
195
- token: string;
196
- /**
197
- * Content version to fetch, leave empty for 'published' or 'draft' for the latest draft
198
- */
199
- version?: 'draft' | string;
200
- /**
201
- * Enable debug mode
202
- */
203
- debug?: boolean;
204
- /**
205
- * Cache TTL (time to live) for API responses. Default is 5 minutes (300000 ms).
206
- * Set to false to disable caching.
207
- */
208
- cacheTTL?: number | false;
209
- };
210
- type LinksFetchParams = {
211
- /**
212
- * Content Kind. FOLDER or DOCUMENT. If not provided, it will return all.
213
- * @example 'DOCUMENT'
214
- */
215
- kind?: 'DOCUMENT' | 'FOLDER';
216
- /**
217
- * Content parent slug.
218
- * @example 'legal/policy'
219
- */
220
- parentSlug?: string;
221
- /**
222
- * If **true**, exclude all sub slugs, otherwise include all content under current selected **parent slug**.
223
- * @example false
224
- */
225
- excludeChildren?: boolean;
226
- };
227
- type ContentFetchParams = {
228
- /**
229
- * Content version to fetch, leave empty for 'published' or 'draft' for the latest draft.
230
- * Overrides the version set in the client options.
231
- */
232
- version?: 'draft';
233
- /**
234
- * Locale identifier (ISO 639-1) to fetch content in, leave empty for default locale.
235
- *
236
- * Example: en
237
- */
238
- locale?: string;
239
- /**
240
- * Resolve references in the content data. Default is false.
241
- */
242
- resolveReference?: boolean;
243
- /**
244
- * Resolve links in the content data. Default is false.
245
- */
246
- resolveLink?: boolean;
247
- };
248
- interface LocalessClient {
249
- /**
250
- * Get all links
251
- * @param params{LinksFetchParams} - Fetch parameters
252
- * @returns {Promise<Links>}
253
- */
254
- getLinks(params?: LinksFetchParams): Promise<Links>;
255
- /**
256
- * Get content by SLUG
257
- * @param slug{string} - Content SLUG
258
- * @param params{ContentFetchParams} - Fetch parameters
259
- * @returns {Promise<Content>}
260
- */
261
- getContentBySlug<T extends ContentData = ContentData>(slug: string, params?: ContentFetchParams): Promise<Content<T>>;
262
- /**
263
- * Get content by ID
264
- * @param id{string} - Content ID
265
- * @param params{ContentFetchParams} - Fetch parameters
266
- * @returns {Promise<Content>}
267
- */
268
- getContentById<T extends ContentData = ContentData>(id: string, params?: ContentFetchParams): Promise<Content<T>>;
269
- /**
270
- * Get translations for the given locale
271
- * @param locale{string} - Locale identifier (ISO 639-1)
272
- */
273
- getTranslations(locale: string): Promise<Translations>;
274
- syncScriptUrl(): string;
275
- assetLink(asset: ContentAsset | string): string;
276
- }
277
- /**
278
- * Create a Localess API Client
279
- * @param {LocalessClientOptions} options connection details
280
- */
281
- declare function localessClient(options: LocalessClientOptions): LocalessClient;
282
-
283
- /**
284
- * Adds Localess editable attributes to a content item.
285
- * @param content
286
- * @returns An object containing data-ll-id and data-ll-schema attributes.
287
- */
288
- declare function localessEditable(content: ContentDataSchema): {
289
- 'data-ll-id': string;
290
- 'data-ll-schema': string;
291
- };
292
- /**
293
- * Adds Localess editable field attribute to a specific field.
294
- * Added type safety to ensure fieldName is a valid key of the content data excluding base schema fields.
295
- * @param fieldName
296
- * @returns An object containing data-ll-field attribute.
297
- */
298
- declare function localessEditableField<T extends ContentData = ContentData>(fieldName: Exclude<keyof T, keyof ContentDataSchema>): {
299
- 'data-ll-field': Exclude<keyof T, keyof ContentDataSchema>;
300
- };
301
-
302
- /**
303
- * Inject Localess Sync Script in Header
304
- * @param {string} origin A fully qualified domain name with protocol (http/https) and port.
305
- * @param {boolean} force Force Script Injection even if the application is not in Visual Editor.
306
- */
307
- declare function loadLocalessSync(origin: string, force?: boolean): void;
308
-
309
- declare const isBrowser: () => boolean;
310
- declare const isServer: () => boolean;
311
- declare const isIframe: () => boolean;
312
-
313
- type EventToAppType = 'save' | 'publish' | 'pong' | 'input' | 'change' | 'enterSchema' | 'hoverSchema';
314
- type EventCallback = (event: EventToApp) => void;
315
- type EventToApp = {
1
+ export * from './models';
2
+ export * from './client';
3
+ export * from './editable';
4
+ export * from './sync';
5
+ export { isBrowser, isServer, isIframe } from './utils';
6
+ export type EventToAppType = 'save' | 'publish' | 'pong' | 'input' | 'change' | 'enterSchema' | 'hoverSchema';
7
+ export type EventCallback = (event: EventToApp) => void;
8
+ export type EventToApp = {
316
9
  type: 'save' | 'publish' | 'pong';
317
10
  } | {
318
11
  type: 'input' | 'change';
@@ -323,7 +16,7 @@ type EventToApp = {
323
16
  schema: string;
324
17
  field?: string;
325
18
  };
326
- interface LocalessSync {
19
+ export interface LocalessSync {
327
20
  onChange: (callback: EventCallback) => void;
328
21
  on: (event: EventToAppType | EventToAppType[], callback: EventCallback) => void;
329
22
  }
@@ -332,5 +25,3 @@ declare global {
332
25
  localess?: LocalessSync;
333
26
  }
334
27
  }
335
-
336
- export { type Content, type ContentAsset, type ContentData, type ContentDataField, type ContentDataSchema, type ContentFetchParams, type ContentLink, type ContentMetadata, type ContentReference, type ContentRichText, type EventCallback, type EventToApp, type EventToAppType, type Links, type LinksFetchParams, type Locale, type LocalessClient, type LocalessClientOptions, type LocalessSync, type References, type Translations, isBrowser, isIframe, isServer, loadLocalessSync, localessClient, localessEditable, localessEditableField };