@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.
- package/README.md +179 -14
- package/dist/{HttpClient-CLtgQGXH.d.cts → HttpClient-CdF3IHM1.d.cts} +49 -2
- package/dist/{HttpClient-CLtgQGXH.d.ts → HttpClient-CdF3IHM1.d.ts} +49 -2
- package/dist/chunk-R3EZI43S.js +855 -0
- package/dist/chunk-WJC4X7TB.js +738 -0
- package/dist/index-D5zkKa4N.d.cts +3394 -0
- package/dist/index-D5zkKa4N.d.ts +3394 -0
- package/dist/index.cjs +599 -213
- package/dist/index.d.cts +20 -544
- package/dist/index.d.ts +20 -544
- package/dist/index.js +27 -791
- package/dist/marvin-B_gJRxHK.d.cts +611 -0
- package/dist/marvin-C5tRQ2nD.d.ts +611 -0
- package/dist/platform.cjs +512 -69
- package/dist/platform.d.cts +141 -3381
- package/dist/platform.d.ts +141 -3381
- package/dist/platform.js +283 -59
- package/dist/publish.cjs +1355 -0
- package/dist/publish.d.cts +49 -0
- package/dist/publish.d.ts +49 -0
- package/dist/publish.js +75 -0
- package/dist/types/index.d.cts +1 -168
- package/dist/types/index.d.ts +1 -168
- package/package.json +11 -6
- package/dist/chunk-25F3IF6S.js +0 -396
|
@@ -0,0 +1,855 @@
|
|
|
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(raw) {
|
|
145
|
+
this.raw = raw;
|
|
146
|
+
}
|
|
147
|
+
raw;
|
|
148
|
+
get title() {
|
|
149
|
+
return this.raw.title;
|
|
150
|
+
}
|
|
151
|
+
get slug() {
|
|
152
|
+
return this.raw.slug;
|
|
153
|
+
}
|
|
154
|
+
get summary() {
|
|
155
|
+
return this.raw.summary;
|
|
156
|
+
}
|
|
157
|
+
get entryType() {
|
|
158
|
+
return this.raw.entryType;
|
|
159
|
+
}
|
|
160
|
+
get entryTypeInfo() {
|
|
161
|
+
return this.raw.entryTypeInfo;
|
|
162
|
+
}
|
|
163
|
+
get data() {
|
|
164
|
+
return this.raw.data;
|
|
165
|
+
}
|
|
166
|
+
get metadataJson() {
|
|
167
|
+
return this.raw.metadataJson;
|
|
168
|
+
}
|
|
169
|
+
get publishedAt() {
|
|
170
|
+
return this.raw.publishedAt;
|
|
171
|
+
}
|
|
172
|
+
get order() {
|
|
173
|
+
return this.raw.order;
|
|
174
|
+
}
|
|
175
|
+
get assets() {
|
|
176
|
+
return this.raw.assets;
|
|
177
|
+
}
|
|
178
|
+
get collections() {
|
|
179
|
+
return this.raw.collections;
|
|
180
|
+
}
|
|
181
|
+
get resources() {
|
|
182
|
+
return this.raw.resources;
|
|
183
|
+
}
|
|
184
|
+
field(key) {
|
|
185
|
+
return this.raw.data[key];
|
|
186
|
+
}
|
|
187
|
+
get fields() {
|
|
188
|
+
return this.raw.data;
|
|
189
|
+
}
|
|
190
|
+
toJSON() {
|
|
191
|
+
return this.raw;
|
|
192
|
+
}
|
|
193
|
+
};
|
|
194
|
+
}
|
|
195
|
+
});
|
|
196
|
+
|
|
197
|
+
// src/collections/collection.ts
|
|
198
|
+
var Collection;
|
|
199
|
+
var init_collection = __esm({
|
|
200
|
+
"src/collections/collection.ts"() {
|
|
201
|
+
"use strict";
|
|
202
|
+
Collection = class {
|
|
203
|
+
constructor(data) {
|
|
204
|
+
this.data = data;
|
|
205
|
+
}
|
|
206
|
+
data;
|
|
207
|
+
get name() {
|
|
208
|
+
return this.data.name;
|
|
209
|
+
}
|
|
210
|
+
get slug() {
|
|
211
|
+
return this.data.slug;
|
|
212
|
+
}
|
|
213
|
+
get description() {
|
|
214
|
+
return this.data.description;
|
|
215
|
+
}
|
|
216
|
+
get isSmart() {
|
|
217
|
+
return this.data.isSmart;
|
|
218
|
+
}
|
|
219
|
+
get smartRules() {
|
|
220
|
+
return this.data.smartRules;
|
|
221
|
+
}
|
|
222
|
+
get metadataJson() {
|
|
223
|
+
return this.data.metadataJson;
|
|
224
|
+
}
|
|
225
|
+
get entryCount() {
|
|
226
|
+
return this.data.entryCount;
|
|
227
|
+
}
|
|
228
|
+
get entries() {
|
|
229
|
+
return this.data.entries;
|
|
230
|
+
}
|
|
231
|
+
toJSON() {
|
|
232
|
+
return this.data;
|
|
233
|
+
}
|
|
234
|
+
};
|
|
235
|
+
}
|
|
236
|
+
});
|
|
237
|
+
|
|
238
|
+
// src/resources/resource.ts
|
|
239
|
+
var Resource;
|
|
240
|
+
var init_resource = __esm({
|
|
241
|
+
"src/resources/resource.ts"() {
|
|
242
|
+
"use strict";
|
|
243
|
+
Resource = class {
|
|
244
|
+
constructor(data) {
|
|
245
|
+
this.data = data;
|
|
246
|
+
}
|
|
247
|
+
data;
|
|
248
|
+
get name() {
|
|
249
|
+
return this.data.name;
|
|
250
|
+
}
|
|
251
|
+
get slug() {
|
|
252
|
+
return this.data.slug;
|
|
253
|
+
}
|
|
254
|
+
get resourceType() {
|
|
255
|
+
return this.data.resourceType;
|
|
256
|
+
}
|
|
257
|
+
get description() {
|
|
258
|
+
return this.data.description;
|
|
259
|
+
}
|
|
260
|
+
get externalId() {
|
|
261
|
+
return this.data.externalId;
|
|
262
|
+
}
|
|
263
|
+
get url() {
|
|
264
|
+
return this.data.url;
|
|
265
|
+
}
|
|
266
|
+
get metadataJson() {
|
|
267
|
+
return this.data.metadataJson;
|
|
268
|
+
}
|
|
269
|
+
get entries() {
|
|
270
|
+
return this.data.entries;
|
|
271
|
+
}
|
|
272
|
+
toJSON() {
|
|
273
|
+
return this.data;
|
|
274
|
+
}
|
|
275
|
+
};
|
|
276
|
+
}
|
|
277
|
+
});
|
|
278
|
+
|
|
279
|
+
// src/entries/entries.ts
|
|
280
|
+
var EntriesModule;
|
|
281
|
+
var init_entries = __esm({
|
|
282
|
+
"src/entries/entries.ts"() {
|
|
283
|
+
"use strict";
|
|
284
|
+
init_entry();
|
|
285
|
+
init_errors();
|
|
286
|
+
EntriesModule = class {
|
|
287
|
+
constructor(http, workspaceSlug) {
|
|
288
|
+
this.http = http;
|
|
289
|
+
this.workspaceSlug = workspaceSlug;
|
|
290
|
+
}
|
|
291
|
+
http;
|
|
292
|
+
workspaceSlug;
|
|
293
|
+
/**
|
|
294
|
+
* Get all published entries
|
|
295
|
+
*/
|
|
296
|
+
async list(options = {}) {
|
|
297
|
+
const queryString = this.http.buildQueryString({
|
|
298
|
+
entry_type: options.entryType,
|
|
299
|
+
collection: options.collection,
|
|
300
|
+
limit: options.limit,
|
|
301
|
+
offset: options.offset
|
|
302
|
+
});
|
|
303
|
+
const endpoint = `/api/publish/${this.workspaceSlug}/entries${queryString}`;
|
|
304
|
+
const response = await this.http.fetch(endpoint);
|
|
305
|
+
return response.data || [];
|
|
306
|
+
}
|
|
307
|
+
/**
|
|
308
|
+
* Get a single entry by slug
|
|
309
|
+
* Returns null if entry is not found (404)
|
|
310
|
+
*/
|
|
311
|
+
async get(slug) {
|
|
312
|
+
try {
|
|
313
|
+
const endpoint = `/api/publish/${this.workspaceSlug}/entries/${slug}`;
|
|
314
|
+
const data = await this.http.fetch(endpoint);
|
|
315
|
+
return new Entry(data);
|
|
316
|
+
} catch (error) {
|
|
317
|
+
if (error instanceof MarvinNotFoundError) {
|
|
318
|
+
return null;
|
|
319
|
+
}
|
|
320
|
+
throw error;
|
|
321
|
+
}
|
|
322
|
+
}
|
|
323
|
+
/**
|
|
324
|
+
* Convenience: Get all pages
|
|
325
|
+
*/
|
|
326
|
+
async pages(options) {
|
|
327
|
+
return this.list({ ...options, entryType: "page" });
|
|
328
|
+
}
|
|
329
|
+
/**
|
|
330
|
+
* Convenience: Get all blog posts
|
|
331
|
+
*/
|
|
332
|
+
async posts(options) {
|
|
333
|
+
return this.list({ ...options, entryType: "blog" });
|
|
334
|
+
}
|
|
335
|
+
/**
|
|
336
|
+
* Convenience: Get all projects
|
|
337
|
+
*/
|
|
338
|
+
async projects(options) {
|
|
339
|
+
return this.list({ ...options, entryType: "project" });
|
|
340
|
+
}
|
|
341
|
+
};
|
|
342
|
+
}
|
|
343
|
+
});
|
|
344
|
+
|
|
345
|
+
// src/collections/collections.ts
|
|
346
|
+
var CollectionsModule;
|
|
347
|
+
var init_collections = __esm({
|
|
348
|
+
"src/collections/collections.ts"() {
|
|
349
|
+
"use strict";
|
|
350
|
+
init_collection();
|
|
351
|
+
init_errors();
|
|
352
|
+
CollectionsModule = class {
|
|
353
|
+
constructor(http, workspaceSlug) {
|
|
354
|
+
this.http = http;
|
|
355
|
+
this.workspaceSlug = workspaceSlug;
|
|
356
|
+
}
|
|
357
|
+
http;
|
|
358
|
+
workspaceSlug;
|
|
359
|
+
/**
|
|
360
|
+
* Get all collections
|
|
361
|
+
*/
|
|
362
|
+
async list() {
|
|
363
|
+
const endpoint = `/api/publish/${this.workspaceSlug}/collections`;
|
|
364
|
+
const response = await this.http.fetch(endpoint);
|
|
365
|
+
return response.data || [];
|
|
366
|
+
}
|
|
367
|
+
/**
|
|
368
|
+
* Get a single collection by slug
|
|
369
|
+
* Returns null if collection is not found (404)
|
|
370
|
+
*/
|
|
371
|
+
async get(slug) {
|
|
372
|
+
try {
|
|
373
|
+
const endpoint = `/api/publish/${this.workspaceSlug}/collections/${slug}`;
|
|
374
|
+
const data = await this.http.fetch(endpoint);
|
|
375
|
+
return new Collection(data);
|
|
376
|
+
} catch (error) {
|
|
377
|
+
if (error instanceof MarvinNotFoundError) {
|
|
378
|
+
return null;
|
|
379
|
+
}
|
|
380
|
+
throw error;
|
|
381
|
+
}
|
|
382
|
+
}
|
|
383
|
+
/**
|
|
384
|
+
* Get entries in a collection
|
|
385
|
+
* Returns empty array if collection is not found
|
|
386
|
+
*/
|
|
387
|
+
async entries(slug) {
|
|
388
|
+
const collection = await this.get(slug);
|
|
389
|
+
if (!collection) {
|
|
390
|
+
return [];
|
|
391
|
+
}
|
|
392
|
+
return collection.entries;
|
|
393
|
+
}
|
|
394
|
+
/**
|
|
395
|
+
* Try multiple collection slugs in fallback order
|
|
396
|
+
* Returns the first collection that exists and has entries
|
|
397
|
+
*/
|
|
398
|
+
async fallback(slugs, options = {}) {
|
|
399
|
+
const { requireEntries = true } = options;
|
|
400
|
+
for (const slug of slugs) {
|
|
401
|
+
try {
|
|
402
|
+
const collection = await this.get(slug);
|
|
403
|
+
if (!collection) {
|
|
404
|
+
continue;
|
|
405
|
+
}
|
|
406
|
+
const entries = collection.entries;
|
|
407
|
+
if (!requireEntries || entries.length > 0) {
|
|
408
|
+
return entries;
|
|
409
|
+
}
|
|
410
|
+
} catch (error) {
|
|
411
|
+
continue;
|
|
412
|
+
}
|
|
413
|
+
}
|
|
414
|
+
return [];
|
|
415
|
+
}
|
|
416
|
+
};
|
|
417
|
+
}
|
|
418
|
+
});
|
|
419
|
+
|
|
420
|
+
// src/assets/assets.ts
|
|
421
|
+
var AssetsModule;
|
|
422
|
+
var init_assets = __esm({
|
|
423
|
+
"src/assets/assets.ts"() {
|
|
424
|
+
"use strict";
|
|
425
|
+
AssetsModule = class {
|
|
426
|
+
constructor(http, workspaceSlug) {
|
|
427
|
+
this.http = http;
|
|
428
|
+
this.workspaceSlug = workspaceSlug;
|
|
429
|
+
}
|
|
430
|
+
http;
|
|
431
|
+
workspaceSlug;
|
|
432
|
+
/**
|
|
433
|
+
* Get all published assets
|
|
434
|
+
*/
|
|
435
|
+
async list(options = {}) {
|
|
436
|
+
const queryString = this.http.buildQueryString({
|
|
437
|
+
type: options.type,
|
|
438
|
+
limit: options.limit,
|
|
439
|
+
offset: options.offset
|
|
440
|
+
});
|
|
441
|
+
const endpoint = `/api/publish/${this.workspaceSlug}/assets${queryString}`;
|
|
442
|
+
const response = await this.http.fetch(endpoint);
|
|
443
|
+
return response.data || [];
|
|
444
|
+
}
|
|
445
|
+
/**
|
|
446
|
+
* Get a single published asset by slug or ID
|
|
447
|
+
*/
|
|
448
|
+
async get(slugOrId) {
|
|
449
|
+
const endpoint = `/api/publish/${this.workspaceSlug}/assets/${slugOrId}`;
|
|
450
|
+
return this.http.fetch(endpoint);
|
|
451
|
+
}
|
|
452
|
+
/**
|
|
453
|
+
* Convenience: Get all images
|
|
454
|
+
*/
|
|
455
|
+
async images(options) {
|
|
456
|
+
return this.list({ ...options, type: "image" });
|
|
457
|
+
}
|
|
458
|
+
/**
|
|
459
|
+
* Convenience: Get all videos
|
|
460
|
+
*/
|
|
461
|
+
async videos(options) {
|
|
462
|
+
return this.list({ ...options, type: "video" });
|
|
463
|
+
}
|
|
464
|
+
/**
|
|
465
|
+
* Convenience: Get all documents
|
|
466
|
+
*/
|
|
467
|
+
async documents(options) {
|
|
468
|
+
return this.list({ ...options, type: "document" });
|
|
469
|
+
}
|
|
470
|
+
};
|
|
471
|
+
}
|
|
472
|
+
});
|
|
473
|
+
|
|
474
|
+
// src/resources/resources.ts
|
|
475
|
+
var ResourcesModule;
|
|
476
|
+
var init_resources = __esm({
|
|
477
|
+
"src/resources/resources.ts"() {
|
|
478
|
+
"use strict";
|
|
479
|
+
init_resource();
|
|
480
|
+
ResourcesModule = class {
|
|
481
|
+
constructor(http, workspaceSlug) {
|
|
482
|
+
this.http = http;
|
|
483
|
+
this.workspaceSlug = workspaceSlug;
|
|
484
|
+
}
|
|
485
|
+
http;
|
|
486
|
+
workspaceSlug;
|
|
487
|
+
/**
|
|
488
|
+
* Get all published resources
|
|
489
|
+
*/
|
|
490
|
+
async list(options = {}) {
|
|
491
|
+
const queryString = this.http.buildQueryString({
|
|
492
|
+
resource_type: options.resourceType,
|
|
493
|
+
limit: options.limit,
|
|
494
|
+
offset: options.offset
|
|
495
|
+
});
|
|
496
|
+
const endpoint = `/api/publish/${this.workspaceSlug}/resources${queryString}`;
|
|
497
|
+
const response = await this.http.fetch(endpoint);
|
|
498
|
+
return response.data || [];
|
|
499
|
+
}
|
|
500
|
+
/**
|
|
501
|
+
* Get a single resource by slug
|
|
502
|
+
*/
|
|
503
|
+
async get(slug) {
|
|
504
|
+
const endpoint = `/api/publish/${this.workspaceSlug}/resources/${slug}`;
|
|
505
|
+
const data = await this.http.fetch(endpoint);
|
|
506
|
+
return new Resource(data);
|
|
507
|
+
}
|
|
508
|
+
/**
|
|
509
|
+
* Get entry slugs that reference this resource
|
|
510
|
+
*/
|
|
511
|
+
async entries(slug) {
|
|
512
|
+
const resource = await this.get(slug);
|
|
513
|
+
return resource.entries;
|
|
514
|
+
}
|
|
515
|
+
};
|
|
516
|
+
}
|
|
517
|
+
});
|
|
518
|
+
|
|
519
|
+
// src/renderers/renderers.ts
|
|
520
|
+
var RenderersModule;
|
|
521
|
+
var init_renderers = __esm({
|
|
522
|
+
"src/renderers/renderers.ts"() {
|
|
523
|
+
"use strict";
|
|
524
|
+
RenderersModule = class {
|
|
525
|
+
constructor(http, workspaceSlug) {
|
|
526
|
+
this.http = http;
|
|
527
|
+
this.workspaceSlug = workspaceSlug;
|
|
528
|
+
}
|
|
529
|
+
http;
|
|
530
|
+
workspaceSlug;
|
|
531
|
+
async list() {
|
|
532
|
+
const endpoint = `/api/publish/${this.workspaceSlug}/entry-types`;
|
|
533
|
+
return this.http.fetch(endpoint);
|
|
534
|
+
}
|
|
535
|
+
};
|
|
536
|
+
}
|
|
537
|
+
});
|
|
538
|
+
|
|
539
|
+
// src/workspaces/workspace.ts
|
|
540
|
+
var Workspace;
|
|
541
|
+
var init_workspace = __esm({
|
|
542
|
+
"src/workspaces/workspace.ts"() {
|
|
543
|
+
"use strict";
|
|
544
|
+
init_entries();
|
|
545
|
+
init_collections();
|
|
546
|
+
init_assets();
|
|
547
|
+
init_resources();
|
|
548
|
+
init_renderers();
|
|
549
|
+
Workspace = class {
|
|
550
|
+
constructor(http, slug) {
|
|
551
|
+
this.http = http;
|
|
552
|
+
this._slug = slug;
|
|
553
|
+
this.entries = new EntriesModule(http, slug);
|
|
554
|
+
this.collections = new CollectionsModule(http, slug);
|
|
555
|
+
this.assets = new AssetsModule(http, slug);
|
|
556
|
+
this.resources = new ResourcesModule(http, slug);
|
|
557
|
+
this.renderers = new RenderersModule(http, slug);
|
|
558
|
+
}
|
|
559
|
+
http;
|
|
560
|
+
_site = null;
|
|
561
|
+
_slug;
|
|
562
|
+
entries;
|
|
563
|
+
collections;
|
|
564
|
+
assets;
|
|
565
|
+
resources;
|
|
566
|
+
renderers;
|
|
567
|
+
/**
|
|
568
|
+
* Get workspace slug
|
|
569
|
+
*/
|
|
570
|
+
get slug() {
|
|
571
|
+
return this._slug;
|
|
572
|
+
}
|
|
573
|
+
/**
|
|
574
|
+
* Get site configuration (cached after first load)
|
|
575
|
+
*/
|
|
576
|
+
get site() {
|
|
577
|
+
return this._site;
|
|
578
|
+
}
|
|
579
|
+
/**
|
|
580
|
+
* Load site configuration
|
|
581
|
+
*/
|
|
582
|
+
async loadSite() {
|
|
583
|
+
const endpoint = `/api/publish/${this._slug}/site`;
|
|
584
|
+
this._site = await this.http.fetch(endpoint);
|
|
585
|
+
return this._site;
|
|
586
|
+
}
|
|
587
|
+
/**
|
|
588
|
+
* Get workspace info (name and slug only)
|
|
589
|
+
*/
|
|
590
|
+
async getInfo() {
|
|
591
|
+
const endpoint = `/api/publish/${this._slug}`;
|
|
592
|
+
return this.http.fetch(endpoint);
|
|
593
|
+
}
|
|
594
|
+
};
|
|
595
|
+
}
|
|
596
|
+
});
|
|
597
|
+
|
|
598
|
+
// src/client/http.ts
|
|
599
|
+
var MarvinHttpClient;
|
|
600
|
+
var init_http = __esm({
|
|
601
|
+
"src/client/http.ts"() {
|
|
602
|
+
"use strict";
|
|
603
|
+
init_core();
|
|
604
|
+
MarvinHttpClient = class extends HttpClient {
|
|
605
|
+
constructor(config) {
|
|
606
|
+
super({
|
|
607
|
+
baseUrl: config.apiUrl,
|
|
608
|
+
auth: new BearerTokenAuth(config.siteClientToken),
|
|
609
|
+
credentials: "same-origin",
|
|
610
|
+
debug: config.debug,
|
|
611
|
+
logger: config.logger
|
|
612
|
+
});
|
|
613
|
+
}
|
|
614
|
+
/**
|
|
615
|
+
* Fetch endpoint (backward compatibility)
|
|
616
|
+
*/
|
|
617
|
+
async fetch(endpoint) {
|
|
618
|
+
return this.get(endpoint);
|
|
619
|
+
}
|
|
620
|
+
};
|
|
621
|
+
}
|
|
622
|
+
});
|
|
623
|
+
|
|
624
|
+
// src/client/marvin.ts
|
|
625
|
+
var marvin_exports = {};
|
|
626
|
+
__export(marvin_exports, {
|
|
627
|
+
MarvinClient: () => MarvinClient
|
|
628
|
+
});
|
|
629
|
+
var MarvinClient;
|
|
630
|
+
var init_marvin = __esm({
|
|
631
|
+
"src/client/marvin.ts"() {
|
|
632
|
+
"use strict";
|
|
633
|
+
init_config();
|
|
634
|
+
init_http();
|
|
635
|
+
init_core();
|
|
636
|
+
init_workspace();
|
|
637
|
+
MarvinClient = class {
|
|
638
|
+
http;
|
|
639
|
+
cache;
|
|
640
|
+
workspace;
|
|
641
|
+
initialized = false;
|
|
642
|
+
constructor(config) {
|
|
643
|
+
validateConfig(config);
|
|
644
|
+
this.http = new MarvinHttpClient(config);
|
|
645
|
+
this.cache = new MarvinCache(config.cacheDuration);
|
|
646
|
+
this.workspace = new Workspace(this.http, config.workspaceSlug);
|
|
647
|
+
if (config.autoInitialize) {
|
|
648
|
+
this.initialize();
|
|
649
|
+
}
|
|
650
|
+
}
|
|
651
|
+
/**
|
|
652
|
+
* Initialize the SDK
|
|
653
|
+
* Preloads site configuration and metadata
|
|
654
|
+
*/
|
|
655
|
+
async initialize() {
|
|
656
|
+
if (this.initialized) return;
|
|
657
|
+
try {
|
|
658
|
+
await this.workspace.loadSite();
|
|
659
|
+
this.initialized = true;
|
|
660
|
+
} catch (error) {
|
|
661
|
+
console.warn("Marvin SDK initialization warning:", error);
|
|
662
|
+
}
|
|
663
|
+
}
|
|
664
|
+
// ======================
|
|
665
|
+
// Workspace-First API
|
|
666
|
+
// ======================
|
|
667
|
+
/**
|
|
668
|
+
* Get the workspace object
|
|
669
|
+
*/
|
|
670
|
+
async getWorkspace() {
|
|
671
|
+
if (!this.initialized) {
|
|
672
|
+
await this.initialize();
|
|
673
|
+
}
|
|
674
|
+
return this.workspace;
|
|
675
|
+
}
|
|
676
|
+
/**
|
|
677
|
+
* Get site configuration (cached)
|
|
678
|
+
*/
|
|
679
|
+
get site() {
|
|
680
|
+
return this.workspace.site;
|
|
681
|
+
}
|
|
682
|
+
/**
|
|
683
|
+
* Get workspace info (name and slug)
|
|
684
|
+
*/
|
|
685
|
+
async getWorkspaceInfo() {
|
|
686
|
+
return this.workspace.getInfo();
|
|
687
|
+
}
|
|
688
|
+
/**
|
|
689
|
+
* Get entries module
|
|
690
|
+
*/
|
|
691
|
+
get entries() {
|
|
692
|
+
return this.workspace.entries;
|
|
693
|
+
}
|
|
694
|
+
/**
|
|
695
|
+
* Get collections module
|
|
696
|
+
*/
|
|
697
|
+
get collections() {
|
|
698
|
+
return this.workspace.collections;
|
|
699
|
+
}
|
|
700
|
+
/**
|
|
701
|
+
* Get assets module
|
|
702
|
+
*/
|
|
703
|
+
get assets() {
|
|
704
|
+
return this.workspace.assets;
|
|
705
|
+
}
|
|
706
|
+
/**
|
|
707
|
+
* Get resources module
|
|
708
|
+
*/
|
|
709
|
+
get resources() {
|
|
710
|
+
return this.workspace.resources;
|
|
711
|
+
}
|
|
712
|
+
/**
|
|
713
|
+
* Get renderers module
|
|
714
|
+
*/
|
|
715
|
+
get renderers() {
|
|
716
|
+
return this.workspace.renderers;
|
|
717
|
+
}
|
|
718
|
+
// ======================
|
|
719
|
+
// Convenience Methods
|
|
720
|
+
// ======================
|
|
721
|
+
/**
|
|
722
|
+
* Get a single entry by slug
|
|
723
|
+
*/
|
|
724
|
+
async entry(slug) {
|
|
725
|
+
return this.workspace.entries.get(slug);
|
|
726
|
+
}
|
|
727
|
+
/**
|
|
728
|
+
* Get a single collection by slug
|
|
729
|
+
*/
|
|
730
|
+
async collection(slug) {
|
|
731
|
+
return this.workspace.collections.get(slug);
|
|
732
|
+
}
|
|
733
|
+
/**
|
|
734
|
+
* Get all pages
|
|
735
|
+
*/
|
|
736
|
+
async pages(options) {
|
|
737
|
+
return this.workspace.entries.pages(options);
|
|
738
|
+
}
|
|
739
|
+
/**
|
|
740
|
+
* Get all blog posts
|
|
741
|
+
*/
|
|
742
|
+
async posts(options) {
|
|
743
|
+
return this.workspace.entries.posts(options);
|
|
744
|
+
}
|
|
745
|
+
/**
|
|
746
|
+
* Get all projects
|
|
747
|
+
*/
|
|
748
|
+
async projects(options) {
|
|
749
|
+
return this.workspace.entries.projects(options);
|
|
750
|
+
}
|
|
751
|
+
/**
|
|
752
|
+
* Get a single resource by slug
|
|
753
|
+
*/
|
|
754
|
+
async resource(slug) {
|
|
755
|
+
return this.workspace.resources.get(slug);
|
|
756
|
+
}
|
|
757
|
+
/**
|
|
758
|
+
* Try multiple collection slugs in fallback order
|
|
759
|
+
* Returns entries from the first collection that exists and has content
|
|
760
|
+
*/
|
|
761
|
+
async collectionFallback(slugs, options) {
|
|
762
|
+
return this.workspace.collections.fallback(slugs, options);
|
|
763
|
+
}
|
|
764
|
+
// ======================
|
|
765
|
+
// Backwards-Compatible Publishing API
|
|
766
|
+
// ======================
|
|
767
|
+
/**
|
|
768
|
+
* @deprecated Use workspace.site or marvin.site instead
|
|
769
|
+
*/
|
|
770
|
+
async getSite() {
|
|
771
|
+
return this.workspace.loadSite();
|
|
772
|
+
}
|
|
773
|
+
/**
|
|
774
|
+
* @deprecated Use workspace.entries.list() instead
|
|
775
|
+
*/
|
|
776
|
+
async getEntries(options) {
|
|
777
|
+
return this.workspace.entries.list(options);
|
|
778
|
+
}
|
|
779
|
+
/**
|
|
780
|
+
* @deprecated Use workspace.entries.get() instead
|
|
781
|
+
*/
|
|
782
|
+
async getEntry(slug) {
|
|
783
|
+
const entry = await this.workspace.entries.get(slug);
|
|
784
|
+
if (!entry) {
|
|
785
|
+
return null;
|
|
786
|
+
}
|
|
787
|
+
return entry.toJSON();
|
|
788
|
+
}
|
|
789
|
+
/**
|
|
790
|
+
* @deprecated Use workspace.collections.list() instead
|
|
791
|
+
*/
|
|
792
|
+
async getCollections() {
|
|
793
|
+
return this.workspace.collections.list();
|
|
794
|
+
}
|
|
795
|
+
/**
|
|
796
|
+
* @deprecated Use workspace.collections.get() instead
|
|
797
|
+
*/
|
|
798
|
+
async getCollection(slug) {
|
|
799
|
+
const collection = await this.workspace.collections.get(slug);
|
|
800
|
+
if (!collection) {
|
|
801
|
+
return null;
|
|
802
|
+
}
|
|
803
|
+
return collection.toJSON();
|
|
804
|
+
}
|
|
805
|
+
/**
|
|
806
|
+
* @deprecated Use workspace.collections.entries() instead
|
|
807
|
+
*/
|
|
808
|
+
async getCollectionEntries(slug) {
|
|
809
|
+
return this.workspace.collections.entries(slug);
|
|
810
|
+
}
|
|
811
|
+
/**
|
|
812
|
+
* @deprecated Use workspace.assets.list() instead
|
|
813
|
+
*/
|
|
814
|
+
async getAssets(options) {
|
|
815
|
+
return this.workspace.assets.list(options);
|
|
816
|
+
}
|
|
817
|
+
/**
|
|
818
|
+
* @deprecated Use workspace.resources.list() instead
|
|
819
|
+
*/
|
|
820
|
+
async getResources(options) {
|
|
821
|
+
return this.workspace.resources.list(options);
|
|
822
|
+
}
|
|
823
|
+
/**
|
|
824
|
+
* @deprecated Use workspace.resources.get() instead
|
|
825
|
+
*/
|
|
826
|
+
async getResource(slug) {
|
|
827
|
+
const resource = await this.workspace.resources.get(slug);
|
|
828
|
+
return resource.toJSON();
|
|
829
|
+
}
|
|
830
|
+
/**
|
|
831
|
+
* @deprecated Use workspace.resources.entries() instead
|
|
832
|
+
*/
|
|
833
|
+
async getResourceEntries(slug) {
|
|
834
|
+
return this.workspace.resources.entries(slug);
|
|
835
|
+
}
|
|
836
|
+
};
|
|
837
|
+
}
|
|
838
|
+
});
|
|
839
|
+
|
|
840
|
+
export {
|
|
841
|
+
createConfigFromEnv,
|
|
842
|
+
config_exports,
|
|
843
|
+
init_config,
|
|
844
|
+
Entry,
|
|
845
|
+
init_entry,
|
|
846
|
+
Collection,
|
|
847
|
+
init_collection,
|
|
848
|
+
Resource,
|
|
849
|
+
init_resource,
|
|
850
|
+
Workspace,
|
|
851
|
+
init_workspace,
|
|
852
|
+
MarvinClient,
|
|
853
|
+
marvin_exports,
|
|
854
|
+
init_marvin
|
|
855
|
+
};
|