@inneropen/marvin-sdk 2.0.1 → 3.0.1

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,611 @@
1
+ import { k as PublishedEntryType, h as MarvinResource, M as MarvinAsset, c as MarvinCollection, e as MarvinEntryListItem, j as PublishedCollectionSummary, d as MarvinEntry, P as PublishedAssetRead, l as PublishedResourceRead, i as MarvinSite, m as components, b as GetResourcesOptions$1 } from './index-D5zkKa4N.js';
2
+ import { H as HttpClient } from './HttpClient-CdF3IHM1.js';
3
+
4
+ /**
5
+ * Marvin SDK Configuration
6
+ */
7
+ interface MarvinConfig {
8
+ apiUrl: string;
9
+ siteClientToken: string;
10
+ workspaceSlug: string;
11
+ /** Enable automatic initialization on client creation */
12
+ autoInitialize?: boolean;
13
+ /** Cache duration in milliseconds (default: 5 minutes) */
14
+ cacheDuration?: number;
15
+ /** Enable debug logging for HTTP requests and responses */
16
+ debug?: boolean;
17
+ /** Custom logger function (defaults to console) */
18
+ logger?: {
19
+ log: (message: string, ...args: unknown[]) => void;
20
+ warn: (message: string, ...args: unknown[]) => void;
21
+ error: (message: string, ...args: unknown[]) => void;
22
+ };
23
+ }
24
+ declare function createConfigFromEnv(overrides?: Partial<MarvinConfig>): MarvinConfig;
25
+
26
+ /**
27
+ * Base error class for all Marvin SDK errors
28
+ */
29
+ declare class MarvinError extends Error {
30
+ readonly code?: string | undefined;
31
+ readonly statusCode?: number | undefined;
32
+ constructor(message: string, code?: string | undefined, statusCode?: number | undefined);
33
+ }
34
+ /**
35
+ * HTTP/API request errors
36
+ */
37
+ declare class MarvinApiError extends MarvinError {
38
+ readonly statusCode: number;
39
+ readonly endpoint: string;
40
+ readonly responseBody?: string | undefined;
41
+ constructor(message: string, statusCode: number, endpoint: string, responseBody?: string | undefined);
42
+ static fromResponse(status: number, statusText: string, endpoint: string, body?: string): MarvinApiError;
43
+ }
44
+ /**
45
+ * Authentication/authorization errors
46
+ */
47
+ declare class MarvinAuthError extends MarvinError {
48
+ constructor(message: string, statusCode?: number);
49
+ }
50
+ /**
51
+ * Configuration errors
52
+ */
53
+ declare class MarvinConfigError extends MarvinError {
54
+ constructor(message: string);
55
+ }
56
+ /**
57
+ * Validation errors
58
+ */
59
+ declare class MarvinValidationError extends MarvinError {
60
+ readonly field?: string | undefined;
61
+ constructor(message: string, field?: string | undefined);
62
+ }
63
+ /**
64
+ * Resource not found errors (404)
65
+ */
66
+ declare class MarvinNotFoundError extends MarvinError {
67
+ readonly endpoint: string;
68
+ constructor(message: string, endpoint: string);
69
+ }
70
+ /**
71
+ * Network/connectivity errors
72
+ */
73
+ declare class MarvinNetworkError extends MarvinError {
74
+ readonly originalError?: Error | undefined;
75
+ constructor(message: string, originalError?: Error | undefined);
76
+ }
77
+ /**
78
+ * Server errors (5xx)
79
+ */
80
+ declare class MarvinServerError extends MarvinError {
81
+ readonly endpoint: string;
82
+ constructor(message: string, statusCode: number, endpoint: string);
83
+ }
84
+
85
+ /**
86
+ * Pagination response types and helpers
87
+ */
88
+ interface PaginationMeta {
89
+ total?: number;
90
+ page?: number;
91
+ limit?: number;
92
+ offset?: number;
93
+ hasMore?: boolean;
94
+ }
95
+ interface PaginatedResponse<T> {
96
+ data: T[];
97
+ meta?: PaginationMeta;
98
+ }
99
+ interface PaginationParams {
100
+ limit?: number;
101
+ offset?: number;
102
+ page?: number;
103
+ }
104
+ /**
105
+ * Create a paginated response
106
+ */
107
+ declare function createPaginatedResponse<T>(data: T[], meta?: PaginationMeta): PaginatedResponse<T>;
108
+ /**
109
+ * Extract data from paginated response
110
+ */
111
+ declare function extractData<T>(response: PaginatedResponse<T> | T[]): T[];
112
+ /**
113
+ * Check if response is paginated
114
+ */
115
+ declare function isPaginatedResponse<T>(response: PaginatedResponse<T> | T[]): response is PaginatedResponse<T>;
116
+ /**
117
+ * Calculate pagination offset from page number
118
+ */
119
+ declare function pageToOffset(page: number, limit: number): number;
120
+ /**
121
+ * Calculate page number from offset
122
+ */
123
+ declare function offsetToPage(offset: number, limit: number): number;
124
+
125
+ /**
126
+ * Simple in-memory cache for SDK data
127
+ *
128
+ * Stores data with automatic expiration based on timestamp.
129
+ * Thread-safe in single-threaded environments (browser/Node.js).
130
+ */
131
+ declare class MarvinCache {
132
+ private duration;
133
+ private maxEntries;
134
+ private cache;
135
+ constructor(duration?: number, maxEntries?: number);
136
+ /**
137
+ * Get cached data by key
138
+ * Returns undefined if not found or expired
139
+ */
140
+ get<T = unknown>(key: string): T | undefined;
141
+ /**
142
+ * Set cached data with optional tags for invalidation
143
+ */
144
+ set<T = unknown>(key: string, data: T, tags?: string[]): void;
145
+ /**
146
+ * Check if key exists and is not expired
147
+ */
148
+ has(key: string): boolean;
149
+ /**
150
+ * Clear all cached entries
151
+ */
152
+ clear(): void;
153
+ /**
154
+ * Delete a specific cache entry
155
+ */
156
+ delete(key: string): void;
157
+ /**
158
+ * Invalidate all cache entries with a specific tag
159
+ * Useful for invalidating related data after mutations
160
+ *
161
+ * @example
162
+ * ```typescript
163
+ * // Cache entries with tags
164
+ * cache.set('entry:1', data, ['entries', 'entry:1']);
165
+ * cache.set('entries:list', data, ['entries']);
166
+ *
167
+ * // Invalidate all entries
168
+ * cache.invalidateByTag('entries');
169
+ * ```
170
+ */
171
+ invalidateByTag(tag: string): number;
172
+ /**
173
+ * Get cache statistics
174
+ */
175
+ getStats(): {
176
+ size: number;
177
+ maxEntries: number;
178
+ oldestEntry: number | null;
179
+ newestEntry: number | null;
180
+ };
181
+ /**
182
+ * Remove expired entries (garbage collection)
183
+ * Returns number of entries removed
184
+ */
185
+ prune(): number;
186
+ }
187
+
188
+ /**
189
+ * HTTP Client for Marvin Publishing API
190
+ *
191
+ * Wrapper around core HttpClient for Publishing API specifics
192
+ */
193
+
194
+ declare class MarvinHttpClient extends HttpClient {
195
+ constructor(config: MarvinConfig);
196
+ /**
197
+ * Fetch endpoint (backward compatibility)
198
+ */
199
+ fetch<T>(endpoint: string): Promise<T>;
200
+ }
201
+
202
+ declare class RenderersModule {
203
+ private http;
204
+ private workspaceSlug;
205
+ constructor(http: MarvinHttpClient, workspaceSlug: string);
206
+ list(): Promise<PublishedEntryType[]>;
207
+ }
208
+
209
+ /**
210
+ * Resource - Rich object representing a single resource
211
+ */
212
+
213
+ declare class Resource {
214
+ private data;
215
+ constructor(data: MarvinResource);
216
+ get name(): string;
217
+ get slug(): string;
218
+ get resourceType(): string;
219
+ get description(): string | null | undefined;
220
+ get externalId(): string | null | undefined;
221
+ get url(): string | null | undefined;
222
+ get metadataJson(): {
223
+ [key: string]: unknown;
224
+ } | null | undefined;
225
+ get entries(): string[];
226
+ toJSON(): MarvinResource;
227
+ }
228
+
229
+ /**
230
+ * Resources Module - Manage resources
231
+ */
232
+
233
+ interface GetResourcesOptions {
234
+ resourceType?: string;
235
+ limit?: number;
236
+ offset?: number;
237
+ }
238
+ declare class ResourcesModule {
239
+ private http;
240
+ private workspaceSlug;
241
+ constructor(http: MarvinHttpClient, workspaceSlug: string);
242
+ /**
243
+ * Get all published resources
244
+ */
245
+ list(options?: GetResourcesOptions): Promise<MarvinResource[]>;
246
+ /**
247
+ * Get a single resource by slug
248
+ */
249
+ get(slug: string): Promise<Resource>;
250
+ /**
251
+ * Get entry slugs that reference this resource
252
+ */
253
+ entries(slug: string): Promise<string[]>;
254
+ }
255
+
256
+ /**
257
+ * Assets Module - Manage assets
258
+ */
259
+
260
+ interface GetAssetsOptions {
261
+ type?: string;
262
+ limit?: number;
263
+ offset?: number;
264
+ }
265
+ declare class AssetsModule {
266
+ private http;
267
+ private workspaceSlug;
268
+ constructor(http: MarvinHttpClient, workspaceSlug: string);
269
+ /**
270
+ * Get all published assets
271
+ */
272
+ list(options?: GetAssetsOptions): Promise<MarvinAsset[]>;
273
+ /**
274
+ * Get a single published asset by slug or ID
275
+ */
276
+ get(slugOrId: string): Promise<MarvinAsset>;
277
+ /**
278
+ * Convenience: Get all images
279
+ */
280
+ images(options?: Omit<GetAssetsOptions, 'type'>): Promise<MarvinAsset[]>;
281
+ /**
282
+ * Convenience: Get all videos
283
+ */
284
+ videos(options?: Omit<GetAssetsOptions, 'type'>): Promise<MarvinAsset[]>;
285
+ /**
286
+ * Convenience: Get all documents
287
+ */
288
+ documents(options?: Omit<GetAssetsOptions, 'type'>): Promise<MarvinAsset[]>;
289
+ }
290
+
291
+ /**
292
+ * Collection - Rich object representing a single collection
293
+ */
294
+
295
+ declare class Collection {
296
+ private data;
297
+ constructor(data: MarvinCollection);
298
+ get name(): string;
299
+ get slug(): string;
300
+ get description(): string | null | undefined;
301
+ get isSmart(): boolean;
302
+ get smartRules(): {
303
+ [key: string]: unknown;
304
+ } | null | undefined;
305
+ get metadataJson(): {
306
+ [key: string]: unknown;
307
+ } | null | undefined;
308
+ get entryCount(): number;
309
+ get entries(): MarvinEntryListItem[];
310
+ toJSON(): MarvinCollection;
311
+ }
312
+
313
+ /**
314
+ * Collections Module - Manage collections
315
+ */
316
+
317
+ declare class CollectionsModule {
318
+ private http;
319
+ private workspaceSlug;
320
+ constructor(http: MarvinHttpClient, workspaceSlug: string);
321
+ /**
322
+ * Get all collections
323
+ */
324
+ list(): Promise<PublishedCollectionSummary[]>;
325
+ /**
326
+ * Get a single collection by slug
327
+ * Returns null if collection is not found (404)
328
+ */
329
+ get(slug: string): Promise<Collection | null>;
330
+ /**
331
+ * Get entries in a collection
332
+ * Returns empty array if collection is not found
333
+ */
334
+ entries(slug: string): Promise<MarvinEntryListItem[]>;
335
+ /**
336
+ * Try multiple collection slugs in fallback order
337
+ * Returns the first collection that exists and has entries
338
+ */
339
+ fallback(slugs: string[], options?: {
340
+ requireEntries?: boolean;
341
+ }): Promise<MarvinEntryListItem[]>;
342
+ }
343
+
344
+ /**
345
+ * Entry - Rich object representing a single entry
346
+ */
347
+
348
+ declare class Entry {
349
+ private raw;
350
+ constructor(raw: MarvinEntry);
351
+ get title(): string;
352
+ get slug(): string;
353
+ get summary(): string | null | undefined;
354
+ get entryType(): string;
355
+ get entryTypeInfo(): {
356
+ slug: string;
357
+ renderer?: string | null;
358
+ package?: string | null;
359
+ version?: string | null;
360
+ config?: {
361
+ [key: string]: unknown;
362
+ } | null;
363
+ publishable: boolean;
364
+ submittable: boolean;
365
+ routable: boolean;
366
+ } | null | undefined;
367
+ get data(): {
368
+ [key: string]: unknown;
369
+ };
370
+ get metadataJson(): {
371
+ [key: string]: unknown;
372
+ } | null | undefined;
373
+ get publishedAt(): string | null | undefined;
374
+ get order(): number | null | undefined;
375
+ get assets(): PublishedAssetRead[];
376
+ get collections(): PublishedCollectionSummary[];
377
+ get resources(): PublishedResourceRead[];
378
+ field<T = unknown>(key: string): T | undefined;
379
+ get fields(): Record<string, unknown>;
380
+ toJSON(): MarvinEntry;
381
+ }
382
+
383
+ /**
384
+ * Entries Module - Manage entries
385
+ */
386
+
387
+ interface GetEntriesOptions {
388
+ entryType?: string;
389
+ collection?: string;
390
+ limit?: number;
391
+ offset?: number;
392
+ status?: string;
393
+ }
394
+ declare class EntriesModule {
395
+ private http;
396
+ private workspaceSlug;
397
+ constructor(http: MarvinHttpClient, workspaceSlug: string);
398
+ /**
399
+ * Get all published entries
400
+ */
401
+ list(options?: GetEntriesOptions): Promise<MarvinEntryListItem[]>;
402
+ /**
403
+ * Get a single entry by slug
404
+ * Returns null if entry is not found (404)
405
+ */
406
+ get(slug: string): Promise<Entry | null>;
407
+ /**
408
+ * Convenience: Get all pages
409
+ */
410
+ pages(options?: Omit<GetEntriesOptions, 'entryType'>): Promise<MarvinEntryListItem[]>;
411
+ /**
412
+ * Convenience: Get all blog posts
413
+ */
414
+ posts(options?: Omit<GetEntriesOptions, 'entryType'>): Promise<MarvinEntryListItem[]>;
415
+ /**
416
+ * Convenience: Get all projects
417
+ */
418
+ projects(options?: Omit<GetEntriesOptions, 'entryType'>): Promise<MarvinEntryListItem[]>;
419
+ }
420
+
421
+ /**
422
+ * Workspace - First-class object representing a Marvin workspace
423
+ */
424
+
425
+ declare class Workspace {
426
+ private http;
427
+ private _site;
428
+ private _slug;
429
+ entries: EntriesModule;
430
+ collections: CollectionsModule;
431
+ assets: AssetsModule;
432
+ resources: ResourcesModule;
433
+ renderers: RenderersModule;
434
+ constructor(http: MarvinHttpClient, slug: string);
435
+ /**
436
+ * Get workspace slug
437
+ */
438
+ get slug(): string;
439
+ /**
440
+ * Get site configuration (cached after first load)
441
+ */
442
+ get site(): MarvinSite | null;
443
+ /**
444
+ * Load site configuration
445
+ */
446
+ loadSite(): Promise<MarvinSite>;
447
+ /**
448
+ * Get workspace info (name and slug only)
449
+ */
450
+ getInfo(): Promise<{
451
+ slug: string;
452
+ name: string;
453
+ }>;
454
+ }
455
+
456
+ declare class MarvinClient {
457
+ private http;
458
+ private cache;
459
+ private workspace;
460
+ private initialized;
461
+ constructor(config: MarvinConfig);
462
+ /**
463
+ * Initialize the SDK
464
+ * Preloads site configuration and metadata
465
+ */
466
+ initialize(): Promise<void>;
467
+ /**
468
+ * Get the workspace object
469
+ */
470
+ getWorkspace(): Promise<Workspace>;
471
+ /**
472
+ * Get site configuration (cached)
473
+ */
474
+ get site(): MarvinSite | null;
475
+ /**
476
+ * Get workspace info (name and slug)
477
+ */
478
+ getWorkspaceInfo(): Promise<{
479
+ slug: string;
480
+ name: string;
481
+ }>;
482
+ /**
483
+ * Get entries module
484
+ */
485
+ get entries(): EntriesModule;
486
+ /**
487
+ * Get collections module
488
+ */
489
+ get collections(): CollectionsModule;
490
+ /**
491
+ * Get assets module
492
+ */
493
+ get assets(): AssetsModule;
494
+ /**
495
+ * Get resources module
496
+ */
497
+ get resources(): ResourcesModule;
498
+ /**
499
+ * Get renderers module
500
+ */
501
+ get renderers(): RenderersModule;
502
+ /**
503
+ * Get a single entry by slug
504
+ */
505
+ entry(slug: string): Promise<Entry | null>;
506
+ /**
507
+ * Get a single collection by slug
508
+ */
509
+ collection(slug: string): Promise<Collection | null>;
510
+ /**
511
+ * Get all pages
512
+ */
513
+ pages(options?: GetEntriesOptions): Promise<{
514
+ slug: string;
515
+ title: string;
516
+ entryType: string;
517
+ entryTypeInfo?: components["schemas"]["PublishedEntryTypeInfo"] | null;
518
+ summary?: string | null;
519
+ publishedAt?: string | null;
520
+ status: string;
521
+ collections: string[];
522
+ assetSlugs: string[];
523
+ resourceSlugs: string[];
524
+ order?: number | null;
525
+ }[]>;
526
+ /**
527
+ * Get all blog posts
528
+ */
529
+ posts(options?: GetEntriesOptions): Promise<{
530
+ slug: string;
531
+ title: string;
532
+ entryType: string;
533
+ entryTypeInfo?: components["schemas"]["PublishedEntryTypeInfo"] | null;
534
+ summary?: string | null;
535
+ publishedAt?: string | null;
536
+ status: string;
537
+ collections: string[];
538
+ assetSlugs: string[];
539
+ resourceSlugs: string[];
540
+ order?: number | null;
541
+ }[]>;
542
+ /**
543
+ * Get all projects
544
+ */
545
+ projects(options?: GetEntriesOptions): Promise<{
546
+ slug: string;
547
+ title: string;
548
+ entryType: string;
549
+ entryTypeInfo?: components["schemas"]["PublishedEntryTypeInfo"] | null;
550
+ summary?: string | null;
551
+ publishedAt?: string | null;
552
+ status: string;
553
+ collections: string[];
554
+ assetSlugs: string[];
555
+ resourceSlugs: string[];
556
+ order?: number | null;
557
+ }[]>;
558
+ /**
559
+ * Get a single resource by slug
560
+ */
561
+ resource(slug: string): Promise<Resource>;
562
+ /**
563
+ * Try multiple collection slugs in fallback order
564
+ * Returns entries from the first collection that exists and has content
565
+ */
566
+ collectionFallback(slugs: string[], options?: {
567
+ requireEntries?: boolean;
568
+ }): Promise<MarvinEntryListItem[]>;
569
+ /**
570
+ * @deprecated Use workspace.site or marvin.site instead
571
+ */
572
+ getSite(): Promise<MarvinSite>;
573
+ /**
574
+ * @deprecated Use workspace.entries.list() instead
575
+ */
576
+ getEntries(options?: GetEntriesOptions): Promise<MarvinEntryListItem[]>;
577
+ /**
578
+ * @deprecated Use workspace.entries.get() instead
579
+ */
580
+ getEntry(slug: string): Promise<MarvinEntry | null>;
581
+ /**
582
+ * @deprecated Use workspace.collections.list() instead
583
+ */
584
+ getCollections(): Promise<PublishedCollectionSummary[]>;
585
+ /**
586
+ * @deprecated Use workspace.collections.get() instead
587
+ */
588
+ getCollection(slug: string): Promise<MarvinCollection | null>;
589
+ /**
590
+ * @deprecated Use workspace.collections.entries() instead
591
+ */
592
+ getCollectionEntries(slug: string): Promise<MarvinEntryListItem[]>;
593
+ /**
594
+ * @deprecated Use workspace.assets.list() instead
595
+ */
596
+ getAssets(options?: GetAssetsOptions): Promise<MarvinAsset[]>;
597
+ /**
598
+ * @deprecated Use workspace.resources.list() instead
599
+ */
600
+ getResources(options?: GetResourcesOptions$1): Promise<MarvinResource[]>;
601
+ /**
602
+ * @deprecated Use workspace.resources.get() instead
603
+ */
604
+ getResource(slug: string): Promise<MarvinResource>;
605
+ /**
606
+ * @deprecated Use workspace.resources.entries() instead
607
+ */
608
+ getResourceEntries(slug: string): Promise<string[]>;
609
+ }
610
+
611
+ export { Collection as C, Entry as E, type MarvinConfig as M, type PaginatedResponse as P, Resource as R, Workspace as W, MarvinClient as a, MarvinApiError as b, MarvinAuthError as c, MarvinCache as d, MarvinConfigError as e, MarvinError as f, MarvinNetworkError as g, MarvinNotFoundError as h, MarvinServerError as i, MarvinValidationError as j, type PaginationMeta as k, type PaginationParams as l, createConfigFromEnv as m, createPaginatedResponse as n, extractData as o, isPaginatedResponse as p, offsetToPage as q, pageToOffset as r };