@inneropen/marvin-sdk 2.0.1 → 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,1015 @@
1
+ import {
2
+ BearerTokenAuth,
3
+ HttpClient,
4
+ MarvinCache,
5
+ MarvinNotFoundError,
6
+ __esm,
7
+ __export,
8
+ init_core,
9
+ init_errors
10
+ } from "./chunk-WJC4X7TB.js";
11
+
12
+ // src/client/config.ts
13
+ var config_exports = {};
14
+ __export(config_exports, {
15
+ createConfigFromEnv: () => createConfigFromEnv,
16
+ validateConfig: () => validateConfig
17
+ });
18
+ function validateConfig(config) {
19
+ const receivedKeys = Object.keys(config).join(", ");
20
+ if (!config.apiUrl) {
21
+ throw new Error(
22
+ `Missing required config: 'apiUrl'
23
+
24
+ The API URL is the base URL of your Marvin server.
25
+
26
+ Examples:
27
+ - Production: https://marvin.example.com
28
+ - Development: http://localhost:8080
29
+
30
+ Solutions:
31
+ 1. Set environment variable: MARVIN_API_URL=https://marvin.example.com
32
+ 2. Pass directly: createMarvinClient({ apiUrl: 'https://marvin.example.com' })
33
+
34
+ Received config keys: ${receivedKeys || "(none)"}`
35
+ );
36
+ }
37
+ if (!config.siteClientToken) {
38
+ throw new Error(
39
+ `Missing required config: 'siteClientToken'
40
+
41
+ The site client token provides read-only access to published content.
42
+
43
+ How to get it:
44
+ 1. Log into Marvin admin panel
45
+ 2. Navigate to: Settings \u2192 API Clients
46
+ 3. Copy the token for your workspace
47
+
48
+ Examples:
49
+ - site_client_abc123xyz
50
+ - sc_1234567890abcdef
51
+
52
+ Solutions:
53
+ 1. Set environment variable: MARVIN_SITE_CLIENT_TOKEN=site_client_abc123
54
+ 2. Pass directly: createMarvinClient({ siteClientToken: 'site_client_abc123' })
55
+
56
+ Received config keys: ${receivedKeys}`
57
+ );
58
+ }
59
+ if (!config.workspaceSlug) {
60
+ throw new Error(
61
+ `Missing required config: 'workspaceSlug'
62
+
63
+ The workspace slug identifies which workspace to access.
64
+
65
+ Examples:
66
+ - my-blog
67
+ - company-website
68
+ - acme-corp
69
+
70
+ How to find it:
71
+ 1. Check your workspace URL: https://marvin.example.com/workspace/[slug]
72
+ 2. Or find it in: Settings \u2192 General \u2192 Workspace Slug
73
+
74
+ Solutions:
75
+ 1. Set environment variable: MARVIN_WORKSPACE_SLUG=my-blog
76
+ 2. Pass directly: createMarvinClient({ workspaceSlug: 'my-blog' })
77
+
78
+ Received config keys: ${receivedKeys}`
79
+ );
80
+ }
81
+ if (config.apiUrl) {
82
+ try {
83
+ new URL(config.apiUrl);
84
+ } catch {
85
+ throw new Error(
86
+ `Invalid 'apiUrl' format: "${config.apiUrl}"
87
+
88
+ The API URL must be a valid HTTP or HTTPS URL.
89
+
90
+ Valid examples:
91
+ \u2713 https://marvin.example.com
92
+ \u2713 http://localhost:8080
93
+ \u2713 https://api.marvin.io
94
+
95
+ Invalid examples:
96
+ \u2717 marvin.example.com (missing protocol)
97
+ \u2717 ftp://marvin.example.com (wrong protocol)
98
+ \u2717 /api (not a full URL)`
99
+ );
100
+ }
101
+ const url = new URL(config.apiUrl);
102
+ if (!["http:", "https:"].includes(url.protocol)) {
103
+ throw new Error(
104
+ `Invalid 'apiUrl' protocol: "${url.protocol}"
105
+
106
+ Only HTTP and HTTPS protocols are supported.
107
+
108
+ Your URL: ${config.apiUrl}
109
+ Change to: ${config.apiUrl.replace(url.protocol, "https:")}`
110
+ );
111
+ }
112
+ }
113
+ }
114
+ function getEnv(key) {
115
+ if (typeof process !== "undefined" && process.env) {
116
+ return process.env[key];
117
+ }
118
+ return void 0;
119
+ }
120
+ function createConfigFromEnv(overrides) {
121
+ return {
122
+ apiUrl: overrides?.apiUrl || getEnv("MARVIN_API_URL") || "",
123
+ siteClientToken: overrides?.siteClientToken || getEnv("MARVIN_SITE_CLIENT_TOKEN") || "",
124
+ workspaceSlug: overrides?.workspaceSlug || getEnv("MARVIN_WORKSPACE_SLUG") || "",
125
+ autoInitialize: overrides?.autoInitialize ?? false,
126
+ cacheDuration: overrides?.cacheDuration ?? 5 * 60 * 1e3,
127
+ // 5 minutes
128
+ debug: overrides?.debug ?? getEnv("MARVIN_DEBUG") === "true",
129
+ logger: overrides?.logger ?? console
130
+ };
131
+ }
132
+ var init_config = __esm({
133
+ "src/client/config.ts"() {
134
+ "use strict";
135
+ }
136
+ });
137
+
138
+ // src/entries/entry.ts
139
+ var Entry;
140
+ var init_entry = __esm({
141
+ "src/entries/entry.ts"() {
142
+ "use strict";
143
+ Entry = class {
144
+ constructor(data, http, workspaceSlug) {
145
+ this.data = data;
146
+ this.http = http;
147
+ this.workspaceSlug = workspaceSlug;
148
+ }
149
+ data;
150
+ http;
151
+ workspaceSlug;
152
+ // Expose all entry data as properties
153
+ get id() {
154
+ return this.data.id;
155
+ }
156
+ get title() {
157
+ return this.data.title;
158
+ }
159
+ get slug() {
160
+ return this.data.slug;
161
+ }
162
+ get summary() {
163
+ return this.data.summary;
164
+ }
165
+ get description() {
166
+ return this.data.description;
167
+ }
168
+ /**
169
+ * @deprecated Use field('body') or dataJson instead. Will be removed in v3.0.0
170
+ */
171
+ get contentMarkdown() {
172
+ return this.data.contentMarkdown;
173
+ }
174
+ /**
175
+ * Schema-driven content data (replaces contentMarkdown in v2.0.0).
176
+ * Access specific fields using the field() helper method.
177
+ * @since 2.0.0
178
+ */
179
+ get dataJson() {
180
+ return this.data.dataJson;
181
+ }
182
+ get metadata() {
183
+ return this.data.metadata;
184
+ }
185
+ get status() {
186
+ return this.data.status;
187
+ }
188
+ get publishedAt() {
189
+ return this.data.publishedAt;
190
+ }
191
+ get createdAt() {
192
+ return this.data.createdAt;
193
+ }
194
+ get updatedAt() {
195
+ return this.data.updatedAt;
196
+ }
197
+ get entryTypeId() {
198
+ return this.data.entryTypeId;
199
+ }
200
+ get entryType() {
201
+ return this.data.entryType;
202
+ }
203
+ /**
204
+ * Get entry assets
205
+ */
206
+ get assets() {
207
+ return this.data.assets || [];
208
+ }
209
+ /**
210
+ * Get entry collections
211
+ */
212
+ get collections() {
213
+ return this.data.collections || [];
214
+ }
215
+ /**
216
+ * Get a specific field value from the entry's schema-driven content (dataJson).
217
+ *
218
+ * @param key - Field key as defined in the entry type's schema
219
+ * @returns The field value, or undefined if not present
220
+ * @since 2.0.0
221
+ *
222
+ * @example
223
+ * ```typescript
224
+ * const entry = await client.entries.get('my-entry');
225
+ * const body = entry.field('body'); // Get markdown body
226
+ * const difficulty = entry.field('difficulty'); // Get difficulty level
227
+ * const heroImage = entry.field('heroImage'); // Get hero image UUID
228
+ * ```
229
+ */
230
+ field(key) {
231
+ return this.data.dataJson?.[key];
232
+ }
233
+ /**
234
+ * Get all fields from the entry's schema-driven content.
235
+ * @since 2.0.0
236
+ */
237
+ get fields() {
238
+ return this.data.dataJson || {};
239
+ }
240
+ /**
241
+ * Get related entries (future)
242
+ */
243
+ async relatedEntries() {
244
+ throw new Error("Related entries not yet implemented");
245
+ }
246
+ /**
247
+ * Get raw entry data
248
+ */
249
+ toJSON() {
250
+ return this.data;
251
+ }
252
+ };
253
+ }
254
+ });
255
+
256
+ // src/collections/collection.ts
257
+ var Collection;
258
+ var init_collection = __esm({
259
+ "src/collections/collection.ts"() {
260
+ "use strict";
261
+ Collection = class {
262
+ constructor(data, http, workspaceSlug) {
263
+ this.data = data;
264
+ this.http = http;
265
+ this.workspaceSlug = workspaceSlug;
266
+ }
267
+ data;
268
+ http;
269
+ workspaceSlug;
270
+ // Expose all collection data as properties
271
+ get id() {
272
+ return this.data.id;
273
+ }
274
+ get name() {
275
+ return this.data.name;
276
+ }
277
+ get slug() {
278
+ return this.data.slug;
279
+ }
280
+ get description() {
281
+ return this.data.description;
282
+ }
283
+ get icon() {
284
+ return this.data.icon;
285
+ }
286
+ get color() {
287
+ return this.data.color;
288
+ }
289
+ get sortOrder() {
290
+ return this.data.sortOrder;
291
+ }
292
+ get isSmart() {
293
+ return this.data.isSmart;
294
+ }
295
+ get smartRules() {
296
+ return this.data.smartRules;
297
+ }
298
+ get createdAt() {
299
+ return this.data.createdAt;
300
+ }
301
+ get updatedAt() {
302
+ return this.data.updatedAt;
303
+ }
304
+ /**
305
+ * Get all entries in this collection
306
+ */
307
+ async entries() {
308
+ return this.data.entries || [];
309
+ }
310
+ /**
311
+ * Get assets in this collection (future)
312
+ */
313
+ async assets() {
314
+ throw new Error("Collection assets not yet implemented");
315
+ }
316
+ /**
317
+ * Get collection metadata (future)
318
+ */
319
+ async metadata() {
320
+ throw new Error("Collection metadata not yet implemented");
321
+ }
322
+ /**
323
+ * Get raw collection data
324
+ */
325
+ toJSON() {
326
+ return this.data;
327
+ }
328
+ };
329
+ }
330
+ });
331
+
332
+ // src/resources/resource.ts
333
+ var Resource;
334
+ var init_resource = __esm({
335
+ "src/resources/resource.ts"() {
336
+ "use strict";
337
+ Resource = class {
338
+ constructor(data, http, workspaceSlug) {
339
+ this.data = data;
340
+ this.http = http;
341
+ this.workspaceSlug = workspaceSlug;
342
+ }
343
+ data;
344
+ http;
345
+ workspaceSlug;
346
+ // Expose all resource data as properties
347
+ get id() {
348
+ return this.data.id;
349
+ }
350
+ get name() {
351
+ return this.data.name;
352
+ }
353
+ get slug() {
354
+ return this.data.slug;
355
+ }
356
+ get resourceType() {
357
+ return this.data.resourceType;
358
+ }
359
+ get description() {
360
+ return this.data.description;
361
+ }
362
+ get externalId() {
363
+ return this.data.externalId;
364
+ }
365
+ get url() {
366
+ return this.data.url;
367
+ }
368
+ get metadata() {
369
+ return this.data.metadata;
370
+ }
371
+ get createdAt() {
372
+ return this.data.createdAt;
373
+ }
374
+ get updatedAt() {
375
+ return this.data.updatedAt;
376
+ }
377
+ /**
378
+ * Get all entries that reference this resource
379
+ */
380
+ async entries() {
381
+ const endpoint = `/api/publish/${this.workspaceSlug}/resources/${this.data.slug}/entries`;
382
+ return this.http.fetch(endpoint);
383
+ }
384
+ /**
385
+ * Get assets related to this resource (future)
386
+ */
387
+ async assets() {
388
+ throw new Error("Resource assets not yet implemented");
389
+ }
390
+ /**
391
+ * Get raw resource data
392
+ */
393
+ toJSON() {
394
+ return this.data;
395
+ }
396
+ };
397
+ }
398
+ });
399
+
400
+ // src/entries/entries.ts
401
+ var EntriesModule;
402
+ var init_entries = __esm({
403
+ "src/entries/entries.ts"() {
404
+ "use strict";
405
+ init_entry();
406
+ init_errors();
407
+ EntriesModule = class {
408
+ constructor(http, workspaceSlug) {
409
+ this.http = http;
410
+ this.workspaceSlug = workspaceSlug;
411
+ }
412
+ http;
413
+ workspaceSlug;
414
+ /**
415
+ * Get all published entries
416
+ */
417
+ async list(options = {}) {
418
+ const queryString = this.http.buildQueryString({
419
+ entry_type: options.entryType,
420
+ collection: options.collection,
421
+ limit: options.limit,
422
+ offset: options.offset
423
+ // Don't send status - backend always returns published
424
+ });
425
+ const endpoint = `/api/publish/${this.workspaceSlug}/entries${queryString}`;
426
+ const response = await this.http.fetch(endpoint);
427
+ return response.data || [];
428
+ }
429
+ /**
430
+ * Get a single entry by slug
431
+ * Returns null if entry is not found (404)
432
+ */
433
+ async get(slug) {
434
+ try {
435
+ const endpoint = `/api/publish/${this.workspaceSlug}/entries/${slug}`;
436
+ const data = await this.http.fetch(endpoint);
437
+ return new Entry(data, this.http, this.workspaceSlug);
438
+ } catch (error) {
439
+ if (error instanceof MarvinNotFoundError) {
440
+ return null;
441
+ }
442
+ throw error;
443
+ }
444
+ }
445
+ /**
446
+ * Convenience: Get all pages
447
+ */
448
+ async pages(options) {
449
+ return this.list({ ...options, entryType: "page" });
450
+ }
451
+ /**
452
+ * Convenience: Get all blog posts
453
+ */
454
+ async posts(options) {
455
+ return this.list({ ...options, entryType: "blog" });
456
+ }
457
+ /**
458
+ * Convenience: Get all projects
459
+ */
460
+ async projects(options) {
461
+ return this.list({ ...options, entryType: "project" });
462
+ }
463
+ };
464
+ }
465
+ });
466
+
467
+ // src/collections/collections.ts
468
+ var CollectionsModule;
469
+ var init_collections = __esm({
470
+ "src/collections/collections.ts"() {
471
+ "use strict";
472
+ init_collection();
473
+ init_errors();
474
+ CollectionsModule = class {
475
+ constructor(http, workspaceSlug) {
476
+ this.http = http;
477
+ this.workspaceSlug = workspaceSlug;
478
+ }
479
+ http;
480
+ workspaceSlug;
481
+ /**
482
+ * Get all collections
483
+ */
484
+ async list() {
485
+ const endpoint = `/api/publish/${this.workspaceSlug}/collections`;
486
+ const response = await this.http.fetch(endpoint);
487
+ return response.data || [];
488
+ }
489
+ /**
490
+ * Get a single collection by slug
491
+ * Returns null if collection is not found (404)
492
+ */
493
+ async get(slug) {
494
+ try {
495
+ const endpoint = `/api/publish/${this.workspaceSlug}/collections/${slug}`;
496
+ const data = await this.http.fetch(endpoint);
497
+ return new Collection(data, this.http, this.workspaceSlug);
498
+ } catch (error) {
499
+ if (error instanceof MarvinNotFoundError) {
500
+ return null;
501
+ }
502
+ throw error;
503
+ }
504
+ }
505
+ /**
506
+ * Get entries in a collection
507
+ * Returns empty array if collection is not found
508
+ */
509
+ async entries(slug) {
510
+ const collection = await this.get(slug);
511
+ if (!collection) {
512
+ return [];
513
+ }
514
+ return collection.entries();
515
+ }
516
+ /**
517
+ * Try multiple collection slugs in fallback order
518
+ * Returns the first collection that exists and has entries
519
+ *
520
+ * @param slugs - Collection slugs to try in order
521
+ * @param options - Options for fallback behavior
522
+ * @returns Entries from the first matching collection, or empty array
523
+ *
524
+ * @example
525
+ * ```ts
526
+ * // Try bench-notes, then journal, then blog
527
+ * const entries = await collections.fallback(['bench-notes', 'journal', 'blog']);
528
+ * ```
529
+ */
530
+ async fallback(slugs, options = {}) {
531
+ const { requireEntries = true } = options;
532
+ for (const slug of slugs) {
533
+ try {
534
+ const collection = await this.get(slug);
535
+ if (!collection) {
536
+ continue;
537
+ }
538
+ const entries = await collection.entries();
539
+ if (!requireEntries || entries.length > 0) {
540
+ return entries;
541
+ }
542
+ } catch (error) {
543
+ continue;
544
+ }
545
+ }
546
+ return [];
547
+ }
548
+ };
549
+ }
550
+ });
551
+
552
+ // src/assets/assets.ts
553
+ var AssetsModule;
554
+ var init_assets = __esm({
555
+ "src/assets/assets.ts"() {
556
+ "use strict";
557
+ AssetsModule = class {
558
+ constructor(http, workspaceSlug) {
559
+ this.http = http;
560
+ this.workspaceSlug = workspaceSlug;
561
+ }
562
+ http;
563
+ workspaceSlug;
564
+ /**
565
+ * Get all published assets
566
+ */
567
+ async list(options = {}) {
568
+ const queryString = this.http.buildQueryString({
569
+ type: options.type,
570
+ limit: options.limit,
571
+ offset: options.offset
572
+ });
573
+ const endpoint = `/api/publish/${this.workspaceSlug}/assets${queryString}`;
574
+ const response = await this.http.fetch(endpoint);
575
+ return response.data || [];
576
+ }
577
+ /**
578
+ * Get a single published asset by slug or ID
579
+ */
580
+ async get(slugOrId) {
581
+ const endpoint = `/api/publish/${this.workspaceSlug}/assets/${slugOrId}`;
582
+ return this.http.fetch(endpoint);
583
+ }
584
+ /**
585
+ * Convenience: Get all images
586
+ */
587
+ async images(options) {
588
+ return this.list({ ...options, type: "image" });
589
+ }
590
+ /**
591
+ * Convenience: Get all videos
592
+ */
593
+ async videos(options) {
594
+ return this.list({ ...options, type: "video" });
595
+ }
596
+ /**
597
+ * Convenience: Get all documents
598
+ */
599
+ async documents(options) {
600
+ return this.list({ ...options, type: "document" });
601
+ }
602
+ };
603
+ }
604
+ });
605
+
606
+ // src/resources/resources.ts
607
+ var ResourcesModule;
608
+ var init_resources = __esm({
609
+ "src/resources/resources.ts"() {
610
+ "use strict";
611
+ init_resource();
612
+ ResourcesModule = class {
613
+ constructor(http, workspaceSlug) {
614
+ this.http = http;
615
+ this.workspaceSlug = workspaceSlug;
616
+ }
617
+ http;
618
+ workspaceSlug;
619
+ /**
620
+ * Get all published resources
621
+ */
622
+ async list(options = {}) {
623
+ const queryString = this.http.buildQueryString({
624
+ resource_type: options.resourceType,
625
+ limit: options.limit,
626
+ offset: options.offset
627
+ });
628
+ const endpoint = `/api/publish/${this.workspaceSlug}/resources${queryString}`;
629
+ const response = await this.http.fetch(endpoint);
630
+ return response.data || [];
631
+ }
632
+ /**
633
+ * Get a single resource by slug
634
+ */
635
+ async get(slug) {
636
+ const endpoint = `/api/publish/${this.workspaceSlug}/resources/${slug}`;
637
+ const data = await this.http.fetch(endpoint);
638
+ return new Resource(data, this.http, this.workspaceSlug);
639
+ }
640
+ /**
641
+ * Get entries that reference this resource
642
+ */
643
+ async entries(slug) {
644
+ const resource = await this.get(slug);
645
+ return resource.entries();
646
+ }
647
+ };
648
+ }
649
+ });
650
+
651
+ // src/renderers/renderers.ts
652
+ var RenderersModule;
653
+ var init_renderers = __esm({
654
+ "src/renderers/renderers.ts"() {
655
+ "use strict";
656
+ RenderersModule = class {
657
+ constructor(http, workspaceSlug) {
658
+ this.http = http;
659
+ this.workspaceSlug = workspaceSlug;
660
+ }
661
+ http;
662
+ workspaceSlug;
663
+ async list() {
664
+ const endpoint = `/api/publish/${this.workspaceSlug}/entry-types`;
665
+ return this.http.fetch(endpoint);
666
+ }
667
+ };
668
+ }
669
+ });
670
+
671
+ // src/workspaces/workspace.ts
672
+ var Workspace;
673
+ var init_workspace = __esm({
674
+ "src/workspaces/workspace.ts"() {
675
+ "use strict";
676
+ init_entries();
677
+ init_collections();
678
+ init_assets();
679
+ init_resources();
680
+ init_renderers();
681
+ Workspace = class {
682
+ constructor(http, slug) {
683
+ this.http = http;
684
+ this._slug = slug;
685
+ this.entries = new EntriesModule(http, slug);
686
+ this.collections = new CollectionsModule(http, slug);
687
+ this.assets = new AssetsModule(http, slug);
688
+ this.resources = new ResourcesModule(http, slug);
689
+ this.renderers = new RenderersModule(http, slug);
690
+ }
691
+ http;
692
+ _site = null;
693
+ _slug;
694
+ entries;
695
+ collections;
696
+ assets;
697
+ resources;
698
+ renderers;
699
+ /**
700
+ * Get workspace slug
701
+ */
702
+ get slug() {
703
+ return this._slug;
704
+ }
705
+ /**
706
+ * Get site configuration (cached after first load)
707
+ */
708
+ get site() {
709
+ return this._site;
710
+ }
711
+ /**
712
+ * Load site configuration
713
+ */
714
+ async loadSite() {
715
+ const endpoint = `/api/publish/${this._slug}/site`;
716
+ this._site = await this.http.fetch(endpoint);
717
+ return this._site;
718
+ }
719
+ /**
720
+ * Get workspace info (name and slug only)
721
+ */
722
+ async getInfo() {
723
+ const endpoint = `/api/publish/${this._slug}`;
724
+ return this.http.fetch(endpoint);
725
+ }
726
+ /**
727
+ * Get workspace settings (future)
728
+ */
729
+ async settings() {
730
+ throw new Error("Workspace settings not yet implemented");
731
+ }
732
+ };
733
+ }
734
+ });
735
+
736
+ // src/client/http.ts
737
+ var MarvinHttpClient;
738
+ var init_http = __esm({
739
+ "src/client/http.ts"() {
740
+ "use strict";
741
+ init_core();
742
+ MarvinHttpClient = class extends HttpClient {
743
+ constructor(config) {
744
+ super({
745
+ baseUrl: config.apiUrl,
746
+ auth: new BearerTokenAuth(config.siteClientToken),
747
+ credentials: "same-origin",
748
+ debug: config.debug,
749
+ logger: config.logger
750
+ });
751
+ }
752
+ /**
753
+ * Fetch endpoint (backward compatibility)
754
+ */
755
+ async fetch(endpoint) {
756
+ return this.get(endpoint);
757
+ }
758
+ };
759
+ }
760
+ });
761
+
762
+ // src/client/marvin.ts
763
+ var marvin_exports = {};
764
+ __export(marvin_exports, {
765
+ MarvinClient: () => MarvinClient
766
+ });
767
+ var MarvinClient;
768
+ var init_marvin = __esm({
769
+ "src/client/marvin.ts"() {
770
+ "use strict";
771
+ init_config();
772
+ init_http();
773
+ init_core();
774
+ init_workspace();
775
+ MarvinClient = class {
776
+ constructor(config) {
777
+ this.config = config;
778
+ validateConfig(config);
779
+ this.http = new MarvinHttpClient(config);
780
+ this.cache = new MarvinCache(config.cacheDuration);
781
+ this.workspace = new Workspace(this.http, config.workspaceSlug);
782
+ if (config.autoInitialize) {
783
+ this.initialize();
784
+ }
785
+ }
786
+ config;
787
+ http;
788
+ cache;
789
+ workspace;
790
+ initialized = false;
791
+ /**
792
+ * Initialize the SDK
793
+ * Preloads site configuration and metadata
794
+ */
795
+ async initialize() {
796
+ if (this.initialized) return;
797
+ try {
798
+ await this.workspace.loadSite();
799
+ this.initialized = true;
800
+ } catch (error) {
801
+ console.warn("Marvin SDK initialization warning:", error);
802
+ }
803
+ }
804
+ // ======================
805
+ // Workspace-First API
806
+ // ======================
807
+ /**
808
+ * Get the workspace object
809
+ */
810
+ async getWorkspace() {
811
+ if (!this.initialized) {
812
+ await this.initialize();
813
+ }
814
+ return this.workspace;
815
+ }
816
+ /**
817
+ * Get site configuration (cached)
818
+ */
819
+ get site() {
820
+ return this.workspace.site;
821
+ }
822
+ /**
823
+ * Get workspace info (name and slug)
824
+ */
825
+ async getWorkspaceInfo() {
826
+ return this.workspace.getInfo();
827
+ }
828
+ /**
829
+ * Get entries module
830
+ */
831
+ get entries() {
832
+ return this.workspace.entries;
833
+ }
834
+ /**
835
+ * Get collections module
836
+ */
837
+ get collections() {
838
+ return this.workspace.collections;
839
+ }
840
+ /**
841
+ * Get assets module
842
+ */
843
+ get assets() {
844
+ return this.workspace.assets;
845
+ }
846
+ /**
847
+ * Get resources module
848
+ */
849
+ get resources() {
850
+ return this.workspace.resources;
851
+ }
852
+ /**
853
+ * Get renderers module
854
+ */
855
+ get renderers() {
856
+ return this.workspace.renderers;
857
+ }
858
+ // ======================
859
+ // Convenience Methods
860
+ // ======================
861
+ /**
862
+ * Get a single entry by slug
863
+ */
864
+ async entry(slug) {
865
+ return this.workspace.entries.get(slug);
866
+ }
867
+ /**
868
+ * Get a single collection by slug
869
+ */
870
+ async collection(slug) {
871
+ return this.workspace.collections.get(slug);
872
+ }
873
+ /**
874
+ * Get all pages
875
+ */
876
+ async pages(options) {
877
+ return this.workspace.entries.pages(options);
878
+ }
879
+ /**
880
+ * Get all blog posts
881
+ */
882
+ async posts(options) {
883
+ return this.workspace.entries.posts(options);
884
+ }
885
+ /**
886
+ * Get all projects
887
+ */
888
+ async projects(options) {
889
+ return this.workspace.entries.projects(options);
890
+ }
891
+ /**
892
+ * Get a single resource by slug
893
+ */
894
+ async resource(slug) {
895
+ return this.workspace.resources.get(slug);
896
+ }
897
+ /**
898
+ * Try multiple collection slugs in fallback order
899
+ * Returns entries from the first collection that exists and has content
900
+ *
901
+ * @param slugs - Collection slugs to try in order
902
+ * @param options - Options for fallback behavior
903
+ * @returns Entries from the first matching collection, or empty array
904
+ *
905
+ * @example
906
+ * ```ts
907
+ * // Try bench-notes, then journal, then blog
908
+ * const entries = await client.collectionFallback(['bench-notes', 'journal', 'blog']);
909
+ * ```
910
+ */
911
+ async collectionFallback(slugs, options) {
912
+ return this.workspace.collections.fallback(slugs, options);
913
+ }
914
+ // ======================
915
+ // Backwards-Compatible Publishing API
916
+ // ======================
917
+ /**
918
+ * @deprecated Use workspace.site or marvin.site instead
919
+ * Get site configuration
920
+ */
921
+ async getSite() {
922
+ return this.workspace.loadSite();
923
+ }
924
+ /**
925
+ * @deprecated Use workspace.entries.list() instead
926
+ * Get all published entries
927
+ */
928
+ async getEntries(options) {
929
+ return this.workspace.entries.list(options);
930
+ }
931
+ /**
932
+ * @deprecated Use workspace.entries.get() instead
933
+ * Get a single published entry by slug
934
+ */
935
+ async getEntry(slug) {
936
+ const entry = await this.workspace.entries.get(slug);
937
+ if (!entry) {
938
+ return null;
939
+ }
940
+ return entry.toJSON();
941
+ }
942
+ /**
943
+ * @deprecated Use workspace.collections.list() instead
944
+ * Get all collections
945
+ */
946
+ async getCollections() {
947
+ return this.workspace.collections.list();
948
+ }
949
+ /**
950
+ * @deprecated Use workspace.collections.get() instead
951
+ * Get a single collection by slug
952
+ */
953
+ async getCollection(slug) {
954
+ const collection = await this.workspace.collections.get(slug);
955
+ if (!collection) {
956
+ return null;
957
+ }
958
+ return collection.toJSON();
959
+ }
960
+ /**
961
+ * @deprecated Use workspace.collections.entries() instead
962
+ * Get all entries in a collection
963
+ */
964
+ async getCollectionEntries(slug) {
965
+ return this.workspace.collections.entries(slug);
966
+ }
967
+ /**
968
+ * @deprecated Use workspace.assets.list() instead
969
+ * Get all published assets
970
+ */
971
+ async getAssets(options) {
972
+ return this.workspace.assets.list(options);
973
+ }
974
+ /**
975
+ * @deprecated Use workspace.resources.list() instead
976
+ * Get all published resources
977
+ */
978
+ async getResources(options) {
979
+ return this.workspace.resources.list(options);
980
+ }
981
+ /**
982
+ * @deprecated Use workspace.resources.get() instead
983
+ * Get a single resource by slug
984
+ */
985
+ async getResource(slug) {
986
+ const resource = await this.workspace.resources.get(slug);
987
+ return resource.toJSON();
988
+ }
989
+ /**
990
+ * @deprecated Use workspace.resources.entries() instead
991
+ * Get entries that reference a resource
992
+ */
993
+ async getResourceEntries(slug) {
994
+ return this.workspace.resources.entries(slug);
995
+ }
996
+ };
997
+ }
998
+ });
999
+
1000
+ export {
1001
+ createConfigFromEnv,
1002
+ config_exports,
1003
+ init_config,
1004
+ Entry,
1005
+ init_entry,
1006
+ Collection,
1007
+ init_collection,
1008
+ Resource,
1009
+ init_resource,
1010
+ Workspace,
1011
+ init_workspace,
1012
+ MarvinClient,
1013
+ marvin_exports,
1014
+ init_marvin
1015
+ };