@conloca/content-api-client 0.1.14 → 0.1.16

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,94 @@
1
+ import type { AssetEntry, AssetUsage, BatchResult, ContentEntry, ContentListResult, ContentManifest, CreateContentInput, CreateResult, DataContext, DeleteResult, ErrorCode, FolderListing, FolderTreeNode, GitCommitResult, GitPullResult, GitPushResult, GitStatus, GlobalFilters, LocalizedEntry, MDXCompileResponse, MoveResult, SitesConfig, UpdateLocaleInput, UpdateResult } from '@conloca/content-api';
2
+ export interface ContentAPIClientOptions {
3
+ baseUrl?: string;
4
+ fetch?: typeof fetch;
5
+ }
6
+ export declare class ContentAPIClient {
7
+ private baseUrl;
8
+ private fetch;
9
+ constructor(options?: ContentAPIClientOptions);
10
+ private encodeAssetPath;
11
+ private fetchAPI;
12
+ getContent(id: string): Promise<ContentEntry | null>;
13
+ getLocalized(id: string, locale: string): Promise<LocalizedEntry | null>;
14
+ createContent(data: CreateContentInput): Promise<CreateResult>;
15
+ updateLocalized(input: UpdateLocaleInput): Promise<UpdateResult>;
16
+ deleteContent(id: string, etag: string): Promise<DeleteResult>;
17
+ deleteLocalized(input: {
18
+ id: string;
19
+ locale: string;
20
+ etag: string;
21
+ }): Promise<DeleteResult>;
22
+ getSitePages(site: string, locale?: string): Promise<ContentListResult>;
23
+ getPageByPathname(site: string, pathname: string, locale?: string): Promise<ContentManifest | null>;
24
+ isPathnameAvailable(site: string, pathname: string, excludeId?: string): Promise<boolean>;
25
+ movePage(site: string, id: string, pathname: string, locale: string, etag: string): Promise<MoveResult>;
26
+ getBlocks(collection?: string, locale?: string): Promise<ContentListResult>;
27
+ getBlockByName(name: string, collection?: string, locale?: string): Promise<ContentManifest | null>;
28
+ compileMDX(mdxContent: string): Promise<MDXCompileResponse>;
29
+ getData(collection?: string, locale?: string): Promise<ContentListResult>;
30
+ getDataByName(name: string, collection: string, locale?: string): Promise<ContentManifest | null>;
31
+ isDataNameAvailable(name: string, collection: string, excludeId?: string): Promise<boolean>;
32
+ getDataCollections(): Promise<string[]>;
33
+ getDataContext(pageId: string): Promise<{
34
+ dataContext: DataContext;
35
+ }>;
36
+ listAllContent(filters?: GlobalFilters): Promise<ContentListResult>;
37
+ findUntranslatedContent(targetLocale: string, excludeSites?: string[], includeUnpublished?: boolean): Promise<ContentListResult>;
38
+ getSitesConfig(): Promise<SitesConfig>;
39
+ batchUpdate(operations: UpdateLocaleInput[]): Promise<BatchResult>;
40
+ getGitStatus(): Promise<GitStatus>;
41
+ commitChanges(message?: string): Promise<GitCommitResult>;
42
+ pushChanges(): Promise<GitPushResult>;
43
+ pullChanges(): Promise<GitPullResult>;
44
+ listAssets(): Promise<{
45
+ assets: AssetEntry[];
46
+ }>;
47
+ getAsset(filename: string): Promise<AssetEntry | null>;
48
+ uploadAsset(formData: FormData): Promise<AssetEntry>;
49
+ importAssetUrl(url: string, alt?: string, folder?: string): Promise<AssetEntry>;
50
+ deleteAsset(filename: string): Promise<{
51
+ success: boolean;
52
+ }>;
53
+ listFolder(path?: string): Promise<FolderListing>;
54
+ createFolder(path: string): Promise<void>;
55
+ updateAssetMetadata(filename: string, updates: {
56
+ alt?: string;
57
+ tags?: string[];
58
+ }): Promise<AssetEntry>;
59
+ getAssetUsage(filename: string): Promise<AssetUsage[]>;
60
+ moveAssets(filenames: string[], sourceFolder: string, targetFolder: string): Promise<{
61
+ success: boolean;
62
+ moved?: number;
63
+ error?: string;
64
+ }>;
65
+ getFolderTree(): Promise<{
66
+ tree: FolderTreeNode[];
67
+ }>;
68
+ getCurrentUser(): Promise<{
69
+ authenticated: boolean;
70
+ user?: {
71
+ email: string;
72
+ sub: string;
73
+ };
74
+ }>;
75
+ }
76
+ export declare class APIClientError extends Error {
77
+ code: ErrorCode;
78
+ details?: any;
79
+ constructor(message: string, code: ErrorCode, details?: any);
80
+ }
81
+ export declare class StaleWriteError extends APIClientError {
82
+ data: {
83
+ code: ErrorCode;
84
+ message: string;
85
+ currentEtag?: string;
86
+ };
87
+ constructor(data: {
88
+ code: ErrorCode;
89
+ message: string;
90
+ currentEtag?: string;
91
+ });
92
+ get currentEtag(): string | undefined;
93
+ }
94
+ //# sourceMappingURL=client.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAEV,UAAU,EACV,UAAU,EACV,WAAW,EACX,YAAY,EACZ,iBAAiB,EACjB,eAAe,EACf,kBAAkB,EAClB,YAAY,EACZ,WAAW,EACX,YAAY,EACZ,SAAS,EACT,aAAa,EACb,cAAc,EACd,eAAe,EACf,aAAa,EACb,aAAa,EACb,SAAS,EACT,aAAa,EACb,cAAc,EACd,kBAAkB,EAClB,UAAU,EACV,WAAW,EACX,iBAAiB,EACjB,YAAY,EACb,MAAM,sBAAsB,CAAC;AAG9B,MAAM,WAAW,uBAAuB;IACtC,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,KAAK,CAAC,EAAE,OAAO,KAAK,CAAC;CACtB;AAED,qBAAa,gBAAgB;IAC3B,OAAO,CAAC,OAAO,CAAS;IACxB,OAAO,CAAC,KAAK,CAAe;IAE5B,YAAY,OAAO,GAAE,uBAA4B,EAWhD;IAED,OAAO,CAAC,eAAe;YAOT,QAAQ;IAgDhB,UAAU,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,YAAY,GAAG,IAAI,CAAC,CAczD;IAEK,YAAY,CAAC,EAAE,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,cAAc,GAAG,IAAI,CAAC,CAc7E;IAEK,aAAa,CAAC,IAAI,EAAE,kBAAkB,GAAG,OAAO,CAAC,YAAY,CAAC,CAKnE;IAEK,eAAe,CAAC,KAAK,EAAE,iBAAiB,GAAG,OAAO,CAAC,YAAY,CAAC,CAOrE;IAEK,aAAa,CAAC,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE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G;IAHtB,YACE,OAAO,EAAE,MAAM,EACR,IAAI,EAAE,SAAS,EACf,OAAO,CAAC,EAAE,GAAG,EAIrB;CACF;AAGD,qBAAa,eAAgB,SAAQ,cAAc;IAC9B,IAAI,EAAE;QAAE,IAAI,EAAE,SAAS,CAAC;QAAC,OAAO,EAAE,MAAM,CAAC;QAAC,WAAW,CAAC,EAAE,MAAM,CAAA;KAAE;IAAnF,YAAmB,IAAI,EAAE;QAAE,IAAI,EAAE,SAAS,CAAC;QAAC,OAAO,EAAE,MAAM,CAAC;QAAC,WAAW,CAAC,EAAE,MAAM,CAAA;KAAE,EAGlF;IAED,IAAI,WAAW,IAAI,MAAM,GAAG,SAAS,CAEpC;CACF"}
package/dist/client.js ADDED
@@ -0,0 +1,434 @@
1
+ import { ErrorCodes } from '@conloca/content-api';
2
+ export class ContentAPIClient {
3
+ baseUrl;
4
+ fetch;
5
+ constructor(options = {}) {
6
+ // Bind fetch to maintain its context
7
+ if (options.fetch) {
8
+ this.fetch = options.fetch;
9
+ }
10
+ else if (typeof globalThis !== 'undefined' && globalThis.fetch) {
11
+ // Use globalThis for better compatibility
12
+ this.fetch = globalThis.fetch.bind(globalThis);
13
+ }
14
+ else {
15
+ this.fetch = fetch;
16
+ }
17
+ this.baseUrl = options.baseUrl || '/__conloca/api';
18
+ }
19
+ encodeAssetPath(filename) {
20
+ return filename
21
+ .split('/')
22
+ .map((s) => encodeURIComponent(s))
23
+ .join('/');
24
+ }
25
+ async fetchAPI(url, options) {
26
+ const response = await this.fetch(url, {
27
+ ...options,
28
+ headers: {
29
+ 'Content-Type': 'application/json',
30
+ ...options?.headers,
31
+ },
32
+ });
33
+ if (!response.ok) {
34
+ let errorData;
35
+ try {
36
+ errorData = await response.json();
37
+ }
38
+ catch {
39
+ // If JSON parsing fails, throw generic error
40
+ throw new Error(`API error: ${response.status} ${response.statusText}`);
41
+ }
42
+ // Check if it's an APIError format
43
+ if (errorData?.error?.code) {
44
+ const apiError = errorData;
45
+ // Special handling for stale writes
46
+ if (apiError.error.code === ErrorCodes.STALE_WRITE) {
47
+ throw new StaleWriteError({
48
+ code: apiError.error.code,
49
+ message: apiError.error.message,
50
+ currentEtag: apiError.error.details?.currentEtag,
51
+ });
52
+ }
53
+ // Create a proper error with code and details
54
+ const error = new APIClientError(apiError.error.message, apiError.error.code, apiError.error.details);
55
+ throw error;
56
+ }
57
+ // Fallback for non-standard error responses
58
+ throw new Error(`API error: ${response.status} ${response.statusText}`);
59
+ }
60
+ return (await response.json());
61
+ }
62
+ // Core content operations
63
+ async getContent(id) {
64
+ try {
65
+ const response = await this.fetch(`${this.baseUrl}/content/${id}`);
66
+ if (response.status === 404) {
67
+ return null;
68
+ }
69
+ if (!response.ok) {
70
+ throw new Error(`Failed to fetch content: ${response.statusText}`);
71
+ }
72
+ return (await response.json());
73
+ }
74
+ catch (error) {
75
+ console.error('Error fetching content:', error);
76
+ throw error;
77
+ }
78
+ }
79
+ async getLocalized(id, locale) {
80
+ try {
81
+ const response = await this.fetch(`${this.baseUrl}/content/${id}/${locale}`);
82
+ if (response.status === 404) {
83
+ return null;
84
+ }
85
+ if (!response.ok) {
86
+ throw new Error(`Failed to fetch localized content: ${response.statusText}`);
87
+ }
88
+ return (await response.json());
89
+ }
90
+ catch (error) {
91
+ console.error('Error fetching localized content:', error);
92
+ throw error;
93
+ }
94
+ }
95
+ async createContent(data) {
96
+ return this.fetchAPI(`${this.baseUrl}/content`, {
97
+ method: 'POST',
98
+ body: JSON.stringify(data),
99
+ });
100
+ }
101
+ async updateLocalized(input) {
102
+ const { id, locale, data, etag } = input;
103
+ const params = new URLSearchParams({ locale, etag });
104
+ return this.fetchAPI(`${this.baseUrl}/content/${id}?${params}`, {
105
+ method: 'PUT',
106
+ body: JSON.stringify(data),
107
+ });
108
+ }
109
+ async deleteContent(id, etag) {
110
+ return this.fetchAPI(`${this.baseUrl}/content/${id}`, {
111
+ method: 'DELETE',
112
+ headers: {
113
+ 'If-Match': etag,
114
+ },
115
+ });
116
+ }
117
+ async deleteLocalized(input) {
118
+ return this.fetchAPI(`${this.baseUrl}/content/${input.id}?locale=${input.locale}`, {
119
+ method: 'DELETE',
120
+ headers: {
121
+ 'If-Match': input.etag,
122
+ },
123
+ });
124
+ }
125
+ // Site operations
126
+ async getSitePages(site, locale) {
127
+ const url = locale ? `${this.baseUrl}/${site}/pages?locale=${locale}` : `${this.baseUrl}/${site}/pages`;
128
+ return this.fetchAPI(url);
129
+ }
130
+ async getPageByPathname(site, pathname, locale) {
131
+ try {
132
+ const url = locale
133
+ ? `${this.baseUrl}/sites/${site}/pathname${pathname}?locale=${locale}`
134
+ : `${this.baseUrl}/sites/${site}/pathname${pathname}`;
135
+ const response = await this.fetch(url);
136
+ if (response.status === 404) {
137
+ return null;
138
+ }
139
+ if (!response.ok) {
140
+ throw new Error(`Failed to fetch page: ${response.statusText}`);
141
+ }
142
+ return (await response.json());
143
+ }
144
+ catch (error) {
145
+ console.error('Error fetching page by pathname:', error);
146
+ throw error;
147
+ }
148
+ }
149
+ async isPathnameAvailable(site, pathname, excludeId) {
150
+ const params = new URLSearchParams({
151
+ pathname,
152
+ ...(excludeId && { excludeId }),
153
+ });
154
+ const response = await this.fetch(`${this.baseUrl}/${site}/pathname-available?${params}`);
155
+ if (!response.ok) {
156
+ throw new Error(`Failed to check pathname availability: ${response.statusText}`);
157
+ }
158
+ const data = (await response.json());
159
+ return data.available;
160
+ }
161
+ async movePage(site, id, pathname, locale, etag) {
162
+ return this.fetchAPI(`${this.baseUrl}/${site}/move`, {
163
+ method: 'POST',
164
+ body: JSON.stringify({ id, pathname, locale, etag }),
165
+ });
166
+ }
167
+ // Block operations
168
+ async getBlocks(collection, locale) {
169
+ const params = new URLSearchParams();
170
+ if (collection)
171
+ params.set('collection', collection);
172
+ if (locale)
173
+ params.set('locale', locale);
174
+ const url = `${this.baseUrl}/blocks${params.toString() ? `?${params}` : ''}`;
175
+ return this.fetchAPI(url);
176
+ }
177
+ async getBlockByName(name, collection, locale) {
178
+ try {
179
+ const params = new URLSearchParams();
180
+ if (collection)
181
+ params.set('collection', collection);
182
+ if (locale)
183
+ params.set('locale', locale);
184
+ const url = `${this.baseUrl}/blocks/${name}${params.toString() ? `?${params}` : ''}`;
185
+ const response = await this.fetch(url);
186
+ if (response.status === 404) {
187
+ return null;
188
+ }
189
+ if (!response.ok) {
190
+ throw new Error(`Failed to fetch block: ${response.statusText}`);
191
+ }
192
+ return (await response.json());
193
+ }
194
+ catch (error) {
195
+ console.error('Error fetching block by name:', error);
196
+ throw error;
197
+ }
198
+ }
199
+ async compileMDX(mdxContent) {
200
+ return this.fetchAPI(`${this.baseUrl}/mdx/compile`, {
201
+ method: 'POST',
202
+ body: JSON.stringify({ mdxContent }),
203
+ });
204
+ }
205
+ // Data operations
206
+ async getData(collection, locale) {
207
+ const params = new URLSearchParams();
208
+ if (collection)
209
+ params.set('collection', collection);
210
+ if (locale)
211
+ params.set('locale', locale);
212
+ const url = `${this.baseUrl}/data${params.toString() ? `?${params}` : ''}`;
213
+ return this.fetchAPI(url);
214
+ }
215
+ async getDataByName(name, collection, locale) {
216
+ try {
217
+ const params = new URLSearchParams();
218
+ params.set('collection', collection);
219
+ if (locale)
220
+ params.set('locale', locale);
221
+ const url = `${this.baseUrl}/data/${name}?${params}`;
222
+ const response = await this.fetch(url);
223
+ if (response.status === 404) {
224
+ return null;
225
+ }
226
+ if (!response.ok) {
227
+ throw new Error(`Failed to fetch data entry: ${response.statusText}`);
228
+ }
229
+ return (await response.json());
230
+ }
231
+ catch (error) {
232
+ console.error('Error fetching data entry by name:', error);
233
+ throw error;
234
+ }
235
+ }
236
+ async isDataNameAvailable(name, collection, excludeId) {
237
+ const params = new URLSearchParams({
238
+ name,
239
+ collection,
240
+ ...(excludeId && { excludeId }),
241
+ });
242
+ const response = await this.fetch(`${this.baseUrl}/data/name-available?${params}`);
243
+ if (!response.ok) {
244
+ throw new Error(`Failed to check data name availability: ${response.statusText}`);
245
+ }
246
+ const data = (await response.json());
247
+ return data.available;
248
+ }
249
+ async getDataCollections() {
250
+ const response = await this.fetchAPI(`${this.baseUrl}/data/collections`);
251
+ return response.collections;
252
+ }
253
+ // Data context operations
254
+ async getDataContext(pageId) {
255
+ return this.fetchAPI(`${this.baseUrl}/data-context?pageId=${pageId}`);
256
+ }
257
+ // Global operations
258
+ async listAllContent(filters) {
259
+ const params = new URLSearchParams();
260
+ if (filters?.site)
261
+ params.set('site', filters.site);
262
+ if (filters?.collection)
263
+ params.set('collection', filters.collection);
264
+ if (filters?.locales?.length)
265
+ params.set('locales', filters.locales.join(','));
266
+ if (filters?.type)
267
+ params.set('type', filters.type);
268
+ if (filters?.published !== undefined)
269
+ params.set('published', String(filters.published));
270
+ if (filters?.kind)
271
+ params.set('kind', filters.kind);
272
+ if (filters?.localization)
273
+ params.set('localization', filters.localization);
274
+ if (filters?.missingLocales?.length)
275
+ params.set('missingLocales', filters.missingLocales.join(','));
276
+ const url = `${this.baseUrl}/content${params.toString() ? `?${params}` : ''}`;
277
+ return this.fetchAPI(url);
278
+ }
279
+ async findUntranslatedContent(targetLocale, excludeSites, includeUnpublished) {
280
+ const params = new URLSearchParams();
281
+ if (excludeSites?.length)
282
+ params.set('excludeSites', excludeSites.join(','));
283
+ if (includeUnpublished)
284
+ params.set('includeUnpublished', 'true');
285
+ const url = `${this.baseUrl}/untranslated/${targetLocale}${params.toString() ? `?${params}` : ''}`;
286
+ return this.fetchAPI(url);
287
+ }
288
+ async getSitesConfig() {
289
+ return this.fetchAPI(`${this.baseUrl}/sites`);
290
+ }
291
+ // Batch operations
292
+ async batchUpdate(operations) {
293
+ return this.fetchAPI(`${this.baseUrl}/content/batch`, {
294
+ method: 'POST',
295
+ body: JSON.stringify({ operations }),
296
+ });
297
+ }
298
+ // Git operations
299
+ async getGitStatus() {
300
+ return this.fetchAPI(`${this.baseUrl}/git/status`);
301
+ }
302
+ async commitChanges(message) {
303
+ return this.fetchAPI(`${this.baseUrl}/git/commit`, {
304
+ method: 'POST',
305
+ body: JSON.stringify(message ? { message } : {}),
306
+ });
307
+ }
308
+ async pushChanges() {
309
+ return this.fetchAPI(`${this.baseUrl}/git/push`, {
310
+ method: 'POST',
311
+ body: JSON.stringify({}),
312
+ });
313
+ }
314
+ async pullChanges() {
315
+ return this.fetchAPI(`${this.baseUrl}/git/pull`, {
316
+ method: 'POST',
317
+ body: JSON.stringify({}),
318
+ });
319
+ }
320
+ // Asset operations
321
+ async listAssets() {
322
+ return this.fetchAPI(`${this.baseUrl}/assets`);
323
+ }
324
+ async getAsset(filename) {
325
+ try {
326
+ const response = await this.fetch(`${this.baseUrl}/assets/meta/${this.encodeAssetPath(filename)}`);
327
+ if (response.status === 404) {
328
+ return null;
329
+ }
330
+ if (!response.ok) {
331
+ throw new Error(`Failed to fetch asset: ${response.statusText}`);
332
+ }
333
+ return (await response.json());
334
+ }
335
+ catch (error) {
336
+ console.error('Error fetching asset:', error);
337
+ throw error;
338
+ }
339
+ }
340
+ async uploadAsset(formData) {
341
+ const response = await this.fetch(`${this.baseUrl}/assets/upload`, {
342
+ method: 'POST',
343
+ body: formData,
344
+ // No Content-Type header — browser sets multipart boundary automatically
345
+ });
346
+ if (!response.ok) {
347
+ let errorData;
348
+ try {
349
+ errorData = (await response.json());
350
+ }
351
+ catch {
352
+ // ignore
353
+ }
354
+ throw new Error(errorData?.error?.message || `Upload failed: ${response.status} ${response.statusText}`);
355
+ }
356
+ return (await response.json());
357
+ }
358
+ async importAssetUrl(url, alt, folder) {
359
+ return this.fetchAPI(`${this.baseUrl}/assets/import-url`, {
360
+ method: 'POST',
361
+ body: JSON.stringify({ url, alt, folder }),
362
+ });
363
+ }
364
+ async deleteAsset(filename) {
365
+ return this.fetchAPI(`${this.baseUrl}/assets/meta/${this.encodeAssetPath(filename)}`, {
366
+ method: 'DELETE',
367
+ });
368
+ }
369
+ // Folder operations
370
+ async listFolder(path = '/') {
371
+ const params = new URLSearchParams({ path });
372
+ return this.fetchAPI(`${this.baseUrl}/assets/folders?${params}`);
373
+ }
374
+ async createFolder(path) {
375
+ await this.fetch(`${this.baseUrl}/assets/folders`, {
376
+ method: 'POST',
377
+ headers: { 'Content-Type': 'application/json' },
378
+ body: JSON.stringify({ path }),
379
+ });
380
+ }
381
+ // Asset metadata operations
382
+ async updateAssetMetadata(filename, updates) {
383
+ return this.fetchAPI(`${this.baseUrl}/assets/meta/${this.encodeAssetPath(filename)}`, {
384
+ method: 'PATCH',
385
+ body: JSON.stringify(updates),
386
+ });
387
+ }
388
+ // Asset usage tracking
389
+ async getAssetUsage(filename) {
390
+ return this.fetchAPI(`${this.baseUrl}/assets/usage/${this.encodeAssetPath(filename)}`);
391
+ }
392
+ // Move assets between folders
393
+ async moveAssets(filenames, sourceFolder, targetFolder) {
394
+ return this.fetchAPI(`${this.baseUrl}/assets/move`, {
395
+ method: 'POST',
396
+ body: JSON.stringify({ filenames, sourceFolder, targetFolder }),
397
+ });
398
+ }
399
+ // Get folder tree structure
400
+ async getFolderTree() {
401
+ return this.fetchAPI(`${this.baseUrl}/assets/folder-tree`);
402
+ }
403
+ // Auth operations
404
+ async getCurrentUser() {
405
+ const response = await this.fetch(`${this.baseUrl}/auth/user`);
406
+ if (!response.ok) {
407
+ return { authenticated: false };
408
+ }
409
+ return response.json();
410
+ }
411
+ }
412
+ // Custom error for API responses
413
+ export class APIClientError extends Error {
414
+ code;
415
+ details;
416
+ constructor(message, code, details) {
417
+ super(message);
418
+ this.code = code;
419
+ this.details = details;
420
+ this.name = 'APIClientError';
421
+ }
422
+ }
423
+ // Custom error for stale writes
424
+ export class StaleWriteError extends APIClientError {
425
+ data;
426
+ constructor(data) {
427
+ super(data.message, data.code, { currentEtag: data.currentEtag });
428
+ this.data = data;
429
+ this.name = 'StaleWriteError';
430
+ }
431
+ get currentEtag() {
432
+ return this.details?.currentEtag;
433
+ }
434
+ }
@@ -0,0 +1,139 @@
1
+ import type { AssetEntry, AssetUsage, ContentEntry, ContentListResult, ContentManifest, CreateContentInput, DataContext, FolderListing, FolderTreeNode, GitCommitResult, GitPullResult, GitPushResult, GitStatus, GlobalFilters, LocalizedEntry, MDXCompileResponse, SitesConfig, UpdateLocaleInput } from '@conloca/content-api';
2
+ import { APIClientError, ContentAPIClient, StaleWriteError } from './client';
3
+ export declare function getContentAPIClient(): ContentAPIClient;
4
+ export declare function setContentAPIClient(client: ContentAPIClient): void;
5
+ export declare function useContent(id: string): import("@tanstack/react-query").UseQueryResult<NoInfer<ContentEntry | null>, Error>;
6
+ export declare function useLocalizedContent(id: string, locale: string): import("@tanstack/react-query").UseQueryResult<NoInfer<LocalizedEntry | null>, Error>;
7
+ export interface UseCompileMDXOptions {
8
+ mdxContent: string | null;
9
+ cacheKey?: string;
10
+ }
11
+ export declare function useCompileMDX({ mdxContent, cacheKey }: UseCompileMDXOptions): import("@tanstack/react-query").UseQueryResult<NoInfer<MDXCompileResponse>, Error>;
12
+ export declare function useCreateContent(): import("@tanstack/react-query").UseMutationResult<import("@conloca/content-api").CreateResult | {
13
+ success: boolean;
14
+ id?: string;
15
+ etag?: string;
16
+ created?: Date;
17
+ reason?: 'already_exists' | 'write_error' | 'invalid_name' | 'invalid_pathname' | 'name_taken' | 'pathname_taken' | 'pathname_in_redirects' | 'metadata_too_large';
18
+ error?: Error;
19
+ existingId?: string;
20
+ fullContent: ContentEntry | null;
21
+ }, Error, CreateContentInput, unknown>;
22
+ export declare function useUpdateLocalized(): import("@tanstack/react-query").UseMutationResult<import("@conloca/content-api").UpdateResult | {
23
+ success: boolean;
24
+ etag?: string;
25
+ modified?: Date;
26
+ reason?: 'not_found' | 'stale_write' | 'write_error';
27
+ error?: Error;
28
+ currentEtag?: string;
29
+ conflictDetails?: {
30
+ metaChanged: boolean;
31
+ contentChanged: boolean;
32
+ currentMeta?: import("@conloca/content-api").ContentMeta;
33
+ currentContent?: import("@conloca/content-api").ContentData;
34
+ localContent?: import("@conloca/content-api").ContentData;
35
+ };
36
+ updatedContent: LocalizedEntry | null;
37
+ }, Error, UpdateLocaleInput, unknown>;
38
+ interface DeleteContentArgs {
39
+ id: string;
40
+ etag: string;
41
+ locale?: string;
42
+ }
43
+ export declare function useDeleteContent(): import("@tanstack/react-query").UseMutationResult<import("@conloca/content-api").DeleteResult, Error, DeleteContentArgs, unknown>;
44
+ interface DeleteLocalizedArgs {
45
+ id: string;
46
+ locale: string;
47
+ etag: string;
48
+ }
49
+ export declare function useDeleteLocalized(): import("@tanstack/react-query").UseMutationResult<import("@conloca/content-api").DeleteResult, Error, DeleteLocalizedArgs, unknown>;
50
+ export declare function useSitePages(site: string, locale?: string): import("@tanstack/react-query").UseQueryResult<NoInfer<ContentListResult>, Error>;
51
+ export declare function usePageByPathname(site: string, pathname: string, locale?: string): import("@tanstack/react-query").UseQueryResult<NoInfer<ContentManifest | null>, Error>;
52
+ export declare function usePathnameAvailability(site: string, pathname: string, excludeId?: string): import("@tanstack/react-query").UseQueryResult<NoInfer<{
53
+ available: boolean;
54
+ }>, Error>;
55
+ interface MovePageArgs {
56
+ site: string;
57
+ id: string;
58
+ pathname: string;
59
+ locale?: string;
60
+ etag: string;
61
+ }
62
+ export declare function useMovePage(): import("@tanstack/react-query").UseMutationResult<import("@conloca/content-api").MoveResult, Error, MovePageArgs, unknown>;
63
+ export declare function useBlocks(collection?: string, locale?: string): import("@tanstack/react-query").UseQueryResult<NoInfer<ContentListResult>, Error>;
64
+ export declare function useBlockByName(name: string, collection?: string, locale?: string): import("@tanstack/react-query").UseQueryResult<NoInfer<ContentManifest | null>, Error>;
65
+ export declare function useData(collection?: string, locale?: string): import("@tanstack/react-query").UseQueryResult<NoInfer<ContentListResult>, Error>;
66
+ export declare function useDataByName(name: string, collection: string, locale?: string): import("@tanstack/react-query").UseQueryResult<NoInfer<ContentManifest | null>, Error>;
67
+ export declare function useDataNameAvailability(name: string, collection: string, excludeId?: string): import("@tanstack/react-query").UseQueryResult<NoInfer<{
68
+ available: boolean;
69
+ }>, Error>;
70
+ export declare function useDataCollections(): import("@tanstack/react-query").UseQueryResult<NoInfer<string[]>, Error>;
71
+ export declare function useDataContext(pageId?: string): import("@tanstack/react-query").UseQueryResult<NoInfer<{
72
+ dataContext: DataContext;
73
+ }>, Error>;
74
+ export declare function useAllContent(filters?: GlobalFilters): import("@tanstack/react-query").UseQueryResult<NoInfer<ContentListResult>, Error>;
75
+ export declare function useUntranslatedContent(targetLocale: string, excludeSites?: string[], includeUnpublished?: boolean): import("@tanstack/react-query").UseQueryResult<NoInfer<ContentListResult>, Error>;
76
+ export declare function useSitesConfig(): import("@tanstack/react-query").UseQueryResult<NoInfer<SitesConfig>, Error>;
77
+ export declare function useCurrentUser(): import("@tanstack/react-query").UseQueryResult<NoInfer<{
78
+ authenticated: boolean;
79
+ user?: {
80
+ email: string;
81
+ sub: string;
82
+ };
83
+ }>, Error>;
84
+ export declare function useBatchUpdate(): import("@tanstack/react-query").UseMutationResult<import("@conloca/content-api").BatchResult | {
85
+ operations: import("@conloca/content-api").BatchOperationResult[];
86
+ success: boolean;
87
+ failed: number;
88
+ updated: number;
89
+ updatedContents: {
90
+ index: number;
91
+ content: LocalizedEntry;
92
+ }[];
93
+ }, Error, UpdateLocaleInput[], unknown>;
94
+ export declare function useGitStatus(): import("@tanstack/react-query").UseQueryResult<NoInfer<GitStatus>, Error>;
95
+ export declare function useCommitChanges(): import("@tanstack/react-query").UseMutationResult<GitCommitResult, Error, string | undefined, unknown>;
96
+ export declare function usePushChanges(): import("@tanstack/react-query").UseMutationResult<GitPushResult, Error, void, unknown>;
97
+ export declare function usePullChanges(): import("@tanstack/react-query").UseMutationResult<GitPullResult, Error, void, unknown>;
98
+ export declare function useAssets(): import("@tanstack/react-query").UseQueryResult<NoInfer<{
99
+ assets: AssetEntry[];
100
+ }>, Error>;
101
+ export declare function useAsset(filename: string): import("@tanstack/react-query").UseQueryResult<NoInfer<AssetEntry | null>, Error>;
102
+ export declare function useUploadAsset(): import("@tanstack/react-query").UseMutationResult<AssetEntry, Error, FormData, unknown>;
103
+ export declare function useImportAssetUrl(): import("@tanstack/react-query").UseMutationResult<AssetEntry, Error, {
104
+ url: string;
105
+ alt?: string;
106
+ folder?: string;
107
+ }, unknown>;
108
+ export declare function useDeleteAsset(): import("@tanstack/react-query").UseMutationResult<{
109
+ success: boolean;
110
+ }, Error, string, unknown>;
111
+ export declare function useBulkDeleteAssets(): import("@tanstack/react-query").UseMutationResult<{
112
+ successCount: number;
113
+ failCount: number;
114
+ }, Error, string[], unknown>;
115
+ export declare function useAssetFolders(path?: string): import("@tanstack/react-query").UseQueryResult<NoInfer<FolderListing>, Error>;
116
+ export declare function useCreateFolder(): import("@tanstack/react-query").UseMutationResult<void, Error, string, unknown>;
117
+ export declare function useUpdateAssetMetadata(): import("@tanstack/react-query").UseMutationResult<AssetEntry, Error, {
118
+ filename: string;
119
+ updates: {
120
+ alt?: string;
121
+ tags?: string[];
122
+ };
123
+ }, unknown>;
124
+ export declare function useAssetUsage(filename: string | null): import("@tanstack/react-query").UseQueryResult<NoInfer<AssetUsage[]>, Error>;
125
+ export declare function useFolderTree(): import("@tanstack/react-query").UseQueryResult<NoInfer<{
126
+ tree: FolderTreeNode[];
127
+ }>, Error>;
128
+ export declare function useMoveAssets(): import("@tanstack/react-query").UseMutationResult<{
129
+ success: boolean;
130
+ moved?: number;
131
+ error?: string;
132
+ }, Error, {
133
+ filenames: string[];
134
+ sourceFolder: string;
135
+ targetFolder: string;
136
+ }, unknown>;
137
+ export type { GitCommitResult, GitPullResult, GitPushResult, GitStatus };
138
+ export { APIClientError, ContentAPIClient, StaleWriteError };
139
+ //# sourceMappingURL=hooks.d.ts.map