@inneropen/marvin-sdk 2.0.0-next.18 → 2.0.0-next.3

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