@inneropen/marvin-sdk 2.0.0 → 3.0.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.
@@ -0,0 +1,666 @@
1
+ import { PublishedEntryType, MarvinResource, MarvinEntry, MarvinAsset, MarvinCollection, MarvinEntryType, MarvinSite, GetResourcesOptions as GetResourcesOptions$1 } from './types/index.cjs';
2
+ import { H as HttpClient } from './HttpClient-CdF3IHM1.cjs';
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
+ private http;
216
+ private workspaceSlug;
217
+ constructor(data: MarvinResource, http: MarvinHttpClient, workspaceSlug: string);
218
+ get id(): string;
219
+ get name(): string;
220
+ get slug(): string;
221
+ get resourceType(): string | undefined;
222
+ get description(): string | undefined;
223
+ get externalId(): string | undefined;
224
+ get url(): string | undefined;
225
+ get metadata(): Record<string, unknown> | undefined;
226
+ get createdAt(): string;
227
+ get updatedAt(): string;
228
+ /**
229
+ * Get all entries that reference this resource
230
+ */
231
+ entries(): Promise<MarvinEntry[]>;
232
+ /**
233
+ * Get assets related to this resource (future)
234
+ */
235
+ assets(): Promise<MarvinAsset[]>;
236
+ /**
237
+ * Get raw resource data
238
+ */
239
+ toJSON(): MarvinResource;
240
+ }
241
+
242
+ /**
243
+ * Resources Module - Manage resources
244
+ */
245
+
246
+ interface GetResourcesOptions {
247
+ resourceType?: string;
248
+ limit?: number;
249
+ offset?: number;
250
+ }
251
+ declare class ResourcesModule {
252
+ private http;
253
+ private workspaceSlug;
254
+ constructor(http: MarvinHttpClient, workspaceSlug: string);
255
+ /**
256
+ * Get all published resources
257
+ */
258
+ list(options?: GetResourcesOptions): Promise<MarvinResource[]>;
259
+ /**
260
+ * Get a single resource by slug
261
+ */
262
+ get(slug: string): Promise<Resource>;
263
+ /**
264
+ * Get entries that reference this resource
265
+ */
266
+ entries(slug: string): Promise<MarvinEntry[]>;
267
+ }
268
+
269
+ /**
270
+ * Assets Module - Manage assets
271
+ */
272
+
273
+ interface GetAssetsOptions {
274
+ type?: string;
275
+ limit?: number;
276
+ offset?: number;
277
+ }
278
+ declare class AssetsModule {
279
+ private http;
280
+ private workspaceSlug;
281
+ constructor(http: MarvinHttpClient, workspaceSlug: string);
282
+ /**
283
+ * Get all published assets
284
+ */
285
+ list(options?: GetAssetsOptions): Promise<MarvinAsset[]>;
286
+ /**
287
+ * Get a single published asset by slug or ID
288
+ */
289
+ get(slugOrId: string): Promise<MarvinAsset>;
290
+ /**
291
+ * Convenience: Get all images
292
+ */
293
+ images(options?: Omit<GetAssetsOptions, 'type'>): Promise<MarvinAsset[]>;
294
+ /**
295
+ * Convenience: Get all videos
296
+ */
297
+ videos(options?: Omit<GetAssetsOptions, 'type'>): Promise<MarvinAsset[]>;
298
+ /**
299
+ * Convenience: Get all documents
300
+ */
301
+ documents(options?: Omit<GetAssetsOptions, 'type'>): Promise<MarvinAsset[]>;
302
+ }
303
+
304
+ /**
305
+ * Collection - Rich object representing a single collection
306
+ */
307
+
308
+ declare class Collection {
309
+ private data;
310
+ private http;
311
+ private workspaceSlug;
312
+ constructor(data: MarvinCollection, http: MarvinHttpClient, workspaceSlug: string);
313
+ get id(): string;
314
+ get name(): string;
315
+ get slug(): string;
316
+ get description(): string | undefined;
317
+ get icon(): string | undefined;
318
+ get color(): string | undefined;
319
+ get sortOrder(): number;
320
+ get isSmart(): boolean;
321
+ get smartRules(): Record<string, unknown> | undefined;
322
+ get createdAt(): string;
323
+ get updatedAt(): string;
324
+ /**
325
+ * Get all entries in this collection
326
+ */
327
+ entries(): Promise<MarvinEntry[]>;
328
+ /**
329
+ * Get assets in this collection (future)
330
+ */
331
+ assets(): Promise<MarvinAsset[]>;
332
+ /**
333
+ * Get collection metadata (future)
334
+ */
335
+ metadata(): Promise<any>;
336
+ /**
337
+ * Get raw collection data
338
+ */
339
+ toJSON(): MarvinCollection;
340
+ }
341
+
342
+ /**
343
+ * Collections Module - Manage collections
344
+ */
345
+
346
+ declare class CollectionsModule {
347
+ private http;
348
+ private workspaceSlug;
349
+ constructor(http: MarvinHttpClient, workspaceSlug: string);
350
+ /**
351
+ * Get all collections
352
+ */
353
+ list(): Promise<MarvinCollection[]>;
354
+ /**
355
+ * Get a single collection by slug
356
+ * Returns null if collection is not found (404)
357
+ */
358
+ get(slug: string): Promise<Collection | null>;
359
+ /**
360
+ * Get entries in a collection
361
+ * Returns empty array if collection is not found
362
+ */
363
+ entries(slug: string): Promise<MarvinEntry[]>;
364
+ /**
365
+ * Try multiple collection slugs in fallback order
366
+ * Returns the first collection that exists and has entries
367
+ *
368
+ * @param slugs - Collection slugs to try in order
369
+ * @param options - Options for fallback behavior
370
+ * @returns Entries from the first matching collection, or empty array
371
+ *
372
+ * @example
373
+ * ```ts
374
+ * // Try bench-notes, then journal, then blog
375
+ * const entries = await collections.fallback(['bench-notes', 'journal', 'blog']);
376
+ * ```
377
+ */
378
+ fallback(slugs: string[], options?: {
379
+ requireEntries?: boolean;
380
+ }): Promise<MarvinEntry[]>;
381
+ }
382
+
383
+ declare class Entry {
384
+ private data;
385
+ private http;
386
+ private workspaceSlug;
387
+ constructor(data: MarvinEntry, http: MarvinHttpClient, workspaceSlug: string);
388
+ get id(): string;
389
+ get title(): string;
390
+ get slug(): string;
391
+ get summary(): string | undefined;
392
+ get description(): string | undefined;
393
+ /**
394
+ * @deprecated Use field('body') or dataJson instead. Will be removed in v3.0.0
395
+ */
396
+ get contentMarkdown(): string | undefined;
397
+ /**
398
+ * Schema-driven content data (replaces contentMarkdown in v2.0.0).
399
+ * Access specific fields using the field() helper method.
400
+ * @since 2.0.0
401
+ */
402
+ get dataJson(): Record<string, unknown> | undefined;
403
+ get metadata(): Record<string, unknown> | undefined;
404
+ get status(): string;
405
+ get publishedAt(): string | undefined;
406
+ get createdAt(): string;
407
+ get updatedAt(): string;
408
+ get entryTypeId(): string;
409
+ get entryType(): MarvinEntryType | undefined;
410
+ /**
411
+ * Get entry assets
412
+ */
413
+ get assets(): MarvinAsset[];
414
+ /**
415
+ * Get entry collections
416
+ */
417
+ get collections(): MarvinCollection[];
418
+ /**
419
+ * Get a specific field value from the entry's schema-driven content (dataJson).
420
+ *
421
+ * @param key - Field key as defined in the entry type's schema
422
+ * @returns The field value, or undefined if not present
423
+ * @since 2.0.0
424
+ *
425
+ * @example
426
+ * ```typescript
427
+ * const entry = await client.entries.get('my-entry');
428
+ * const body = entry.field('body'); // Get markdown body
429
+ * const difficulty = entry.field('difficulty'); // Get difficulty level
430
+ * const heroImage = entry.field('heroImage'); // Get hero image UUID
431
+ * ```
432
+ */
433
+ field<T = unknown>(key: string): T | undefined;
434
+ /**
435
+ * Get all fields from the entry's schema-driven content.
436
+ * @since 2.0.0
437
+ */
438
+ get fields(): Record<string, unknown>;
439
+ /**
440
+ * Get related entries (future)
441
+ */
442
+ relatedEntries(): Promise<MarvinEntry[]>;
443
+ /**
444
+ * Get raw entry data
445
+ */
446
+ toJSON(): MarvinEntry;
447
+ }
448
+
449
+ /**
450
+ * Entries Module - Manage entries
451
+ */
452
+
453
+ interface GetEntriesOptions {
454
+ entryType?: string;
455
+ collection?: string;
456
+ limit?: number;
457
+ offset?: number;
458
+ status?: string;
459
+ }
460
+ declare class EntriesModule {
461
+ private http;
462
+ private workspaceSlug;
463
+ constructor(http: MarvinHttpClient, workspaceSlug: string);
464
+ /**
465
+ * Get all published entries
466
+ */
467
+ list(options?: GetEntriesOptions): Promise<MarvinEntry[]>;
468
+ /**
469
+ * Get a single entry by slug
470
+ * Returns null if entry is not found (404)
471
+ */
472
+ get(slug: string): Promise<Entry | null>;
473
+ /**
474
+ * Convenience: Get all pages
475
+ */
476
+ pages(options?: Omit<GetEntriesOptions, 'entryType'>): Promise<MarvinEntry[]>;
477
+ /**
478
+ * Convenience: Get all blog posts
479
+ */
480
+ posts(options?: Omit<GetEntriesOptions, 'entryType'>): Promise<MarvinEntry[]>;
481
+ /**
482
+ * Convenience: Get all projects
483
+ */
484
+ projects(options?: Omit<GetEntriesOptions, 'entryType'>): Promise<MarvinEntry[]>;
485
+ }
486
+
487
+ /**
488
+ * Workspace - First-class object representing a Marvin workspace
489
+ */
490
+
491
+ declare class Workspace {
492
+ private http;
493
+ private _site;
494
+ private _slug;
495
+ entries: EntriesModule;
496
+ collections: CollectionsModule;
497
+ assets: AssetsModule;
498
+ resources: ResourcesModule;
499
+ renderers: RenderersModule;
500
+ constructor(http: MarvinHttpClient, slug: string);
501
+ /**
502
+ * Get workspace slug
503
+ */
504
+ get slug(): string;
505
+ /**
506
+ * Get site configuration (cached after first load)
507
+ */
508
+ get site(): MarvinSite | null;
509
+ /**
510
+ * Load site configuration
511
+ */
512
+ loadSite(): Promise<MarvinSite>;
513
+ /**
514
+ * Get workspace info (name and slug only)
515
+ */
516
+ getInfo(): Promise<{
517
+ slug: string;
518
+ name: string;
519
+ }>;
520
+ /**
521
+ * Get workspace settings (future)
522
+ */
523
+ settings(): Promise<any>;
524
+ }
525
+
526
+ declare class MarvinClient {
527
+ private config;
528
+ private http;
529
+ private cache;
530
+ private workspace;
531
+ private initialized;
532
+ constructor(config: MarvinConfig);
533
+ /**
534
+ * Initialize the SDK
535
+ * Preloads site configuration and metadata
536
+ */
537
+ initialize(): Promise<void>;
538
+ /**
539
+ * Get the workspace object
540
+ */
541
+ getWorkspace(): Promise<Workspace>;
542
+ /**
543
+ * Get site configuration (cached)
544
+ */
545
+ get site(): MarvinSite | null;
546
+ /**
547
+ * Get workspace info (name and slug)
548
+ */
549
+ getWorkspaceInfo(): Promise<{
550
+ slug: string;
551
+ name: string;
552
+ }>;
553
+ /**
554
+ * Get entries module
555
+ */
556
+ get entries(): EntriesModule;
557
+ /**
558
+ * Get collections module
559
+ */
560
+ get collections(): CollectionsModule;
561
+ /**
562
+ * Get assets module
563
+ */
564
+ get assets(): AssetsModule;
565
+ /**
566
+ * Get resources module
567
+ */
568
+ get resources(): ResourcesModule;
569
+ /**
570
+ * Get renderers module
571
+ */
572
+ get renderers(): RenderersModule;
573
+ /**
574
+ * Get a single entry by slug
575
+ */
576
+ entry(slug: string): Promise<Entry | null>;
577
+ /**
578
+ * Get a single collection by slug
579
+ */
580
+ collection(slug: string): Promise<Collection | null>;
581
+ /**
582
+ * Get all pages
583
+ */
584
+ pages(options?: GetEntriesOptions): Promise<MarvinEntry[]>;
585
+ /**
586
+ * Get all blog posts
587
+ */
588
+ posts(options?: GetEntriesOptions): Promise<MarvinEntry[]>;
589
+ /**
590
+ * Get all projects
591
+ */
592
+ projects(options?: GetEntriesOptions): Promise<MarvinEntry[]>;
593
+ /**
594
+ * Get a single resource by slug
595
+ */
596
+ resource(slug: string): Promise<Resource>;
597
+ /**
598
+ * Try multiple collection slugs in fallback order
599
+ * Returns entries from the first collection that exists and has content
600
+ *
601
+ * @param slugs - Collection slugs to try in order
602
+ * @param options - Options for fallback behavior
603
+ * @returns Entries from the first matching collection, or empty array
604
+ *
605
+ * @example
606
+ * ```ts
607
+ * // Try bench-notes, then journal, then blog
608
+ * const entries = await client.collectionFallback(['bench-notes', 'journal', 'blog']);
609
+ * ```
610
+ */
611
+ collectionFallback(slugs: string[], options?: {
612
+ requireEntries?: boolean;
613
+ }): Promise<MarvinEntry[]>;
614
+ /**
615
+ * @deprecated Use workspace.site or marvin.site instead
616
+ * Get site configuration
617
+ */
618
+ getSite(): Promise<MarvinSite>;
619
+ /**
620
+ * @deprecated Use workspace.entries.list() instead
621
+ * Get all published entries
622
+ */
623
+ getEntries(options?: GetEntriesOptions): Promise<MarvinEntry[]>;
624
+ /**
625
+ * @deprecated Use workspace.entries.get() instead
626
+ * Get a single published entry by slug
627
+ */
628
+ getEntry(slug: string): Promise<MarvinEntry | null>;
629
+ /**
630
+ * @deprecated Use workspace.collections.list() instead
631
+ * Get all collections
632
+ */
633
+ getCollections(): Promise<MarvinCollection[]>;
634
+ /**
635
+ * @deprecated Use workspace.collections.get() instead
636
+ * Get a single collection by slug
637
+ */
638
+ getCollection(slug: string): Promise<MarvinCollection | null>;
639
+ /**
640
+ * @deprecated Use workspace.collections.entries() instead
641
+ * Get all entries in a collection
642
+ */
643
+ getCollectionEntries(slug: string): Promise<MarvinEntry[]>;
644
+ /**
645
+ * @deprecated Use workspace.assets.list() instead
646
+ * Get all published assets
647
+ */
648
+ getAssets(options?: GetAssetsOptions): Promise<MarvinAsset[]>;
649
+ /**
650
+ * @deprecated Use workspace.resources.list() instead
651
+ * Get all published resources
652
+ */
653
+ getResources(options?: GetResourcesOptions$1): Promise<MarvinResource[]>;
654
+ /**
655
+ * @deprecated Use workspace.resources.get() instead
656
+ * Get a single resource by slug
657
+ */
658
+ getResource(slug: string): Promise<MarvinResource>;
659
+ /**
660
+ * @deprecated Use workspace.resources.entries() instead
661
+ * Get entries that reference a resource
662
+ */
663
+ getResourceEntries(slug: string): Promise<MarvinEntry[]>;
664
+ }
665
+
666
+ 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 };