@localess/js-client 0.3.2-next.20250108-112722.0 → 0.3.2-next.20250109-090340.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.
Files changed (93) hide show
  1. package/dist/index.d.mts +272 -0
  2. package/dist/index.d.ts +260 -9
  3. package/dist/index.js +215 -5
  4. package/dist/index.mjs +186 -0
  5. package/package.json +8 -11
  6. package/dist/cjs/client.d.ts +0 -88
  7. package/dist/cjs/client.js +0 -165
  8. package/dist/cjs/client.js.map +0 -1
  9. package/dist/cjs/editable.d.ts +0 -5
  10. package/dist/cjs/editable.js +0 -11
  11. package/dist/cjs/editable.js.map +0 -1
  12. package/dist/cjs/index.d.ts +0 -21
  13. package/dist/cjs/index.js +0 -21
  14. package/dist/cjs/index.js.map +0 -1
  15. package/dist/cjs/models/content-asset.d.ts +0 -13
  16. package/dist/cjs/models/content-asset.js +0 -3
  17. package/dist/cjs/models/content-asset.js.map +0 -1
  18. package/dist/cjs/models/content-data.d.ts +0 -27
  19. package/dist/cjs/models/content-data.js +0 -3
  20. package/dist/cjs/models/content-data.js.map +0 -1
  21. package/dist/cjs/models/content-link.d.ts +0 -21
  22. package/dist/cjs/models/content-link.js +0 -3
  23. package/dist/cjs/models/content-link.js.map +0 -1
  24. package/dist/cjs/models/content-metadata.d.ts +0 -41
  25. package/dist/cjs/models/content-metadata.js +0 -3
  26. package/dist/cjs/models/content-metadata.js.map +0 -1
  27. package/dist/cjs/models/content-reference.d.ts +0 -13
  28. package/dist/cjs/models/content-reference.js +0 -3
  29. package/dist/cjs/models/content-reference.js.map +0 -1
  30. package/dist/cjs/models/content-rich-text.d.ts +0 -13
  31. package/dist/cjs/models/content-rich-text.js +0 -3
  32. package/dist/cjs/models/content-rich-text.js.map +0 -1
  33. package/dist/cjs/models/content.d.ts +0 -11
  34. package/dist/cjs/models/content.js +0 -3
  35. package/dist/cjs/models/content.js.map +0 -1
  36. package/dist/cjs/models/index.d.ts +0 -9
  37. package/dist/cjs/models/index.js +0 -26
  38. package/dist/cjs/models/index.js.map +0 -1
  39. package/dist/cjs/models/links.d.ts +0 -7
  40. package/dist/cjs/models/links.js +0 -3
  41. package/dist/cjs/models/links.js.map +0 -1
  42. package/dist/cjs/models/translations.d.ts +0 -6
  43. package/dist/cjs/models/translations.js +0 -3
  44. package/dist/cjs/models/translations.js.map +0 -1
  45. package/dist/cjs/sync.d.ts +0 -6
  46. package/dist/cjs/sync.js +0 -32
  47. package/dist/cjs/sync.js.map +0 -1
  48. package/dist/cjs/utils.d.ts +0 -40
  49. package/dist/cjs/utils.js +0 -51
  50. package/dist/cjs/utils.js.map +0 -1
  51. package/dist/client.d.ts +0 -88
  52. package/dist/client.js +0 -161
  53. package/dist/client.js.map +0 -1
  54. package/dist/editable.d.ts +0 -5
  55. package/dist/editable.js +0 -7
  56. package/dist/editable.js.map +0 -1
  57. package/dist/index.js.map +0 -1
  58. package/dist/models/content-asset.d.ts +0 -13
  59. package/dist/models/content-asset.js +0 -2
  60. package/dist/models/content-asset.js.map +0 -1
  61. package/dist/models/content-data.d.ts +0 -27
  62. package/dist/models/content-data.js +0 -2
  63. package/dist/models/content-data.js.map +0 -1
  64. package/dist/models/content-link.d.ts +0 -21
  65. package/dist/models/content-link.js +0 -2
  66. package/dist/models/content-link.js.map +0 -1
  67. package/dist/models/content-metadata.d.ts +0 -41
  68. package/dist/models/content-metadata.js +0 -2
  69. package/dist/models/content-metadata.js.map +0 -1
  70. package/dist/models/content-reference.d.ts +0 -13
  71. package/dist/models/content-reference.js +0 -2
  72. package/dist/models/content-reference.js.map +0 -1
  73. package/dist/models/content-rich-text.d.ts +0 -13
  74. package/dist/models/content-rich-text.js +0 -2
  75. package/dist/models/content-rich-text.js.map +0 -1
  76. package/dist/models/content.d.ts +0 -11
  77. package/dist/models/content.js +0 -2
  78. package/dist/models/content.js.map +0 -1
  79. package/dist/models/index.d.ts +0 -9
  80. package/dist/models/index.js +0 -10
  81. package/dist/models/index.js.map +0 -1
  82. package/dist/models/links.d.ts +0 -7
  83. package/dist/models/links.js +0 -2
  84. package/dist/models/links.js.map +0 -1
  85. package/dist/models/translations.d.ts +0 -6
  86. package/dist/models/translations.js +0 -2
  87. package/dist/models/translations.js.map +0 -1
  88. package/dist/sync.d.ts +0 -6
  89. package/dist/sync.js +0 -28
  90. package/dist/sync.js.map +0 -1
  91. package/dist/utils.d.ts +0 -40
  92. package/dist/utils.js +0 -47
  93. package/dist/utils.js.map +0 -1
@@ -0,0 +1,272 @@
1
+ /**
2
+ * Content Asset define reference to a 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 new tab and _self for 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 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 define 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 define 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
+ * Content define shared object for all possible Content Types.
133
+ */
134
+ interface Content extends ContentMetadata {
135
+ /**
136
+ * Content Data
137
+ */
138
+ data?: ContentData;
139
+ }
140
+
141
+ /**
142
+ * Key-Value Object. Where Key is Unique identifier for the Content object and Value is Content Metadata.
143
+ */
144
+ interface Links {
145
+ [key: string]: ContentMetadata;
146
+ }
147
+
148
+ /**
149
+ * Key-Value Object. Where Key is Translation ID and Value is Translated Content
150
+ */
151
+ interface Translations {
152
+ [key: string]: string;
153
+ }
154
+
155
+ type LocalessClientOptions = {
156
+ /**
157
+ * A fully qualified domain name with protocol (http/https) and port.
158
+ *
159
+ * Example: https://my-localess.web.app
160
+ */
161
+ origin: string;
162
+ /**
163
+ * Localess space ID, cna be found in the Localess Space settings
164
+ */
165
+ spaceId: string;
166
+ /**
167
+ * Localess API token, can be found in the Localess Space settings
168
+ */
169
+ token: string;
170
+ /**
171
+ * Content version to fetch, leave empty for 'published' or 'draft' for the latest draft
172
+ */
173
+ version?: 'draft' | string;
174
+ /**
175
+ * Enable debug mode
176
+ */
177
+ debug?: boolean;
178
+ };
179
+ type LinksFetchParams = {
180
+ /**
181
+ * Content Kind. FOLDER or DOCUMENT. If not provided, it will return all.
182
+ * @example 'DOCUMENT'
183
+ */
184
+ kind?: 'DOCUMENT' | 'FOLDER';
185
+ /**
186
+ * Content parent slug.
187
+ * @example 'legal/policy'
188
+ */
189
+ parentSlug?: string;
190
+ /**
191
+ * If **true**, exclude all sub slugs, otherwise include all content under current selected **parent slug**.
192
+ * @example false
193
+ */
194
+ excludeChildren?: boolean;
195
+ };
196
+ type ContentFetchParams = {
197
+ /**
198
+ * Content version to fetch, leave empty for 'published' or 'draft' for the latest draft.
199
+ * Overrides the version set in the client options.
200
+ */
201
+ version?: 'draft' | string;
202
+ /**
203
+ * Locale identifier (ISO 639-1) to fetch content in, leave empty for default locale.
204
+ *
205
+ * Example: en
206
+ */
207
+ locale?: string;
208
+ };
209
+ /**
210
+ * Create a Localess API Client
211
+ * @param {LocalessClientOptions} options connection details
212
+ */
213
+ declare function localessClient(options: LocalessClientOptions): {
214
+ /**
215
+ * Get all links
216
+ * @param params{LinksFetchParams} - Fetch parameters
217
+ * @returns {Promise<Links>}
218
+ */
219
+ getLinks(params?: LinksFetchParams): Promise<Links>;
220
+ /**
221
+ * Get content by SLUG
222
+ * @param slug{string} - Content SLUG
223
+ * @param params{ContentFetchParams} - Fetch parameters
224
+ * @returns {Promise<Content>}
225
+ */
226
+ getContentBySlug(slug: string, params?: ContentFetchParams): Promise<Content>;
227
+ /**
228
+ * Get content by ID
229
+ * @param id{string} - Content ID
230
+ * @param params{ContentFetchParams} - Fetch parameters
231
+ * @returns {Promise<Content>}
232
+ */
233
+ getContentById(id: string, params?: ContentFetchParams): Promise<Content>;
234
+ /**
235
+ * Get translations for the given locale
236
+ * @param locale{string} - Locale identifier (ISO 639-1)
237
+ */
238
+ getTranslations(locale: string): Promise<Translations>;
239
+ syncScriptUrl(): string;
240
+ assetLink(asset: ContentAsset | string): string;
241
+ };
242
+
243
+ declare function llEditable(content: ContentDataSchema): {
244
+ 'data-ll-id': string;
245
+ 'data-ll-schema': string;
246
+ };
247
+
248
+ /**
249
+ * Inject Localess Sync Script in Header
250
+ * @param {string} origin A fully qualified domain name with protocol (http/https) and port.
251
+ * @param {boolean} force Force Script Injection even if the application is not in Visual Editor.
252
+ */
253
+ declare function loadLocalessSync(origin: string, force?: boolean): void;
254
+
255
+ type EventType = 'input' | 'save' | 'publish' | 'change';
256
+ type EventCallback = (event: EventToApp) => void;
257
+ type EventToApp = {
258
+ type: 'save' | 'publish';
259
+ } | {
260
+ type: 'input' | 'change';
261
+ data: ContentData;
262
+ };
263
+ interface LocalessSync {
264
+ on: (event: EventType | EventType[], callback: EventCallback) => void;
265
+ }
266
+ declare global {
267
+ interface Window {
268
+ localess?: LocalessSync;
269
+ }
270
+ }
271
+
272
+ 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 EventType, type Links, type LinksFetchParams, type LocalessClientOptions, type LocalessSync, type Translations, llEditable, loadLocalessSync, localessClient };
package/dist/index.d.ts CHANGED
@@ -1,17 +1,266 @@
1
- import { ContentData } from "./models";
2
- export * from './models';
3
- export * from './client';
4
- export * from './editable';
5
- export * from './sync';
6
- export type EventType = 'input' | 'save' | 'publish' | 'change';
7
- export type EventCallback = (event: EventToApp) => void;
8
- export type EventToApp = {
1
+ /**
2
+ * Content Asset define reference to a 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 new tab and _self for 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 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 define 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 define 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
+ * Content define shared object for all possible Content Types.
133
+ */
134
+ interface Content extends ContentMetadata {
135
+ /**
136
+ * Content Data
137
+ */
138
+ data?: ContentData;
139
+ }
140
+
141
+ /**
142
+ * Key-Value Object. Where Key is Unique identifier for the Content object and Value is Content Metadata.
143
+ */
144
+ interface Links {
145
+ [key: string]: ContentMetadata;
146
+ }
147
+
148
+ /**
149
+ * Key-Value Object. Where Key is Translation ID and Value is Translated Content
150
+ */
151
+ interface Translations {
152
+ [key: string]: string;
153
+ }
154
+
155
+ type LocalessClientOptions = {
156
+ /**
157
+ * A fully qualified domain name with protocol (http/https) and port.
158
+ *
159
+ * Example: https://my-localess.web.app
160
+ */
161
+ origin: string;
162
+ /**
163
+ * Localess space ID, cna be found in the Localess Space settings
164
+ */
165
+ spaceId: string;
166
+ /**
167
+ * Localess API token, can be found in the Localess Space settings
168
+ */
169
+ token: string;
170
+ /**
171
+ * Content version to fetch, leave empty for 'published' or 'draft' for the latest draft
172
+ */
173
+ version?: 'draft' | string;
174
+ /**
175
+ * Enable debug mode
176
+ */
177
+ debug?: boolean;
178
+ };
179
+ type LinksFetchParams = {
180
+ /**
181
+ * Content Kind. FOLDER or DOCUMENT. If not provided, it will return all.
182
+ * @example 'DOCUMENT'
183
+ */
184
+ kind?: 'DOCUMENT' | 'FOLDER';
185
+ /**
186
+ * Content parent slug.
187
+ * @example 'legal/policy'
188
+ */
189
+ parentSlug?: string;
190
+ /**
191
+ * If **true**, exclude all sub slugs, otherwise include all content under current selected **parent slug**.
192
+ * @example false
193
+ */
194
+ excludeChildren?: boolean;
195
+ };
196
+ type ContentFetchParams = {
197
+ /**
198
+ * Content version to fetch, leave empty for 'published' or 'draft' for the latest draft.
199
+ * Overrides the version set in the client options.
200
+ */
201
+ version?: 'draft' | string;
202
+ /**
203
+ * Locale identifier (ISO 639-1) to fetch content in, leave empty for default locale.
204
+ *
205
+ * Example: en
206
+ */
207
+ locale?: string;
208
+ };
209
+ /**
210
+ * Create a Localess API Client
211
+ * @param {LocalessClientOptions} options connection details
212
+ */
213
+ declare function localessClient(options: LocalessClientOptions): {
214
+ /**
215
+ * Get all links
216
+ * @param params{LinksFetchParams} - Fetch parameters
217
+ * @returns {Promise<Links>}
218
+ */
219
+ getLinks(params?: LinksFetchParams): Promise<Links>;
220
+ /**
221
+ * Get content by SLUG
222
+ * @param slug{string} - Content SLUG
223
+ * @param params{ContentFetchParams} - Fetch parameters
224
+ * @returns {Promise<Content>}
225
+ */
226
+ getContentBySlug(slug: string, params?: ContentFetchParams): Promise<Content>;
227
+ /**
228
+ * Get content by ID
229
+ * @param id{string} - Content ID
230
+ * @param params{ContentFetchParams} - Fetch parameters
231
+ * @returns {Promise<Content>}
232
+ */
233
+ getContentById(id: string, params?: ContentFetchParams): Promise<Content>;
234
+ /**
235
+ * Get translations for the given locale
236
+ * @param locale{string} - Locale identifier (ISO 639-1)
237
+ */
238
+ getTranslations(locale: string): Promise<Translations>;
239
+ syncScriptUrl(): string;
240
+ assetLink(asset: ContentAsset | string): string;
241
+ };
242
+
243
+ declare function llEditable(content: ContentDataSchema): {
244
+ 'data-ll-id': string;
245
+ 'data-ll-schema': string;
246
+ };
247
+
248
+ /**
249
+ * Inject Localess Sync Script in Header
250
+ * @param {string} origin A fully qualified domain name with protocol (http/https) and port.
251
+ * @param {boolean} force Force Script Injection even if the application is not in Visual Editor.
252
+ */
253
+ declare function loadLocalessSync(origin: string, force?: boolean): void;
254
+
255
+ type EventType = 'input' | 'save' | 'publish' | 'change';
256
+ type EventCallback = (event: EventToApp) => void;
257
+ type EventToApp = {
9
258
  type: 'save' | 'publish';
10
259
  } | {
11
260
  type: 'input' | 'change';
12
261
  data: ContentData;
13
262
  };
14
- export interface LocalessSync {
263
+ interface LocalessSync {
15
264
  on: (event: EventType | EventType[], callback: EventCallback) => void;
16
265
  }
17
266
  declare global {
@@ -19,3 +268,5 @@ declare global {
19
268
  localess?: LocalessSync;
20
269
  }
21
270
  }
271
+
272
+ 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 EventType, type Links, type LinksFetchParams, type LocalessClientOptions, type LocalessSync, type Translations, llEditable, loadLocalessSync, localessClient };