@inneropen/marvin-sdk 1.0.3 → 1.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,559 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/platform.ts
21
+ var platform_exports = {};
22
+ __export(platform_exports, {
23
+ APIClientsModule: () => APIClientsModule,
24
+ AssetsModule: () => AssetsModule,
25
+ CollectionsModule: () => CollectionsModule,
26
+ EntriesModule: () => EntriesModule,
27
+ EntryTypesModule: () => EntryTypesModule,
28
+ PlatformClient: () => PlatformClient,
29
+ ResourcesModule: () => ResourcesModule,
30
+ WorkspaceMembersModule: () => WorkspaceMembersModule,
31
+ createPlatformClient: () => createPlatformClient
32
+ });
33
+ module.exports = __toCommonJS(platform_exports);
34
+
35
+ // src/core/errors/MarvinError.ts
36
+ var MarvinError = class _MarvinError extends Error {
37
+ constructor(message, code, statusCode) {
38
+ super(message);
39
+ this.code = code;
40
+ this.statusCode = statusCode;
41
+ this.name = "MarvinError";
42
+ Object.setPrototypeOf(this, _MarvinError.prototype);
43
+ }
44
+ code;
45
+ statusCode;
46
+ };
47
+ var MarvinApiError = class _MarvinApiError extends MarvinError {
48
+ constructor(message, statusCode, endpoint, responseBody) {
49
+ super(message, "API_ERROR", statusCode);
50
+ this.statusCode = statusCode;
51
+ this.endpoint = endpoint;
52
+ this.responseBody = responseBody;
53
+ this.name = "MarvinApiError";
54
+ Object.setPrototypeOf(this, _MarvinApiError.prototype);
55
+ }
56
+ statusCode;
57
+ endpoint;
58
+ responseBody;
59
+ static fromResponse(status, statusText, endpoint, body) {
60
+ const message = `Marvin API error: ${status} ${statusText} at ${endpoint}${body ? `
61
+ ${body}` : ""}`;
62
+ return new _MarvinApiError(message, status, endpoint, body);
63
+ }
64
+ };
65
+
66
+ // src/core/http/HttpClient.ts
67
+ var HttpClient = class {
68
+ baseUrl;
69
+ auth;
70
+ defaultHeaders;
71
+ credentials;
72
+ timeout;
73
+ constructor(config) {
74
+ this.baseUrl = config.baseUrl;
75
+ this.auth = config.auth;
76
+ this.defaultHeaders = config.defaultHeaders || {};
77
+ this.credentials = config.credentials || "same-origin";
78
+ this.timeout = config.timeout || 3e4;
79
+ }
80
+ /**
81
+ * Build full URL from endpoint
82
+ */
83
+ buildUrl(endpoint) {
84
+ const base = this.baseUrl.replace(/\/$/, "");
85
+ const path = endpoint.replace(/^\//, "");
86
+ return `${base}/${path}`;
87
+ }
88
+ /**
89
+ * Build headers for request
90
+ */
91
+ buildHeaders(additionalHeaders) {
92
+ const headers = new Headers({
93
+ "Content-Type": "application/json",
94
+ ...this.defaultHeaders,
95
+ ...additionalHeaders
96
+ });
97
+ this.auth.injectAuth(headers);
98
+ return headers;
99
+ }
100
+ /**
101
+ * Build query string from params
102
+ */
103
+ buildQueryString(params) {
104
+ const filtered = Object.entries(params).filter(([_, value]) => value !== void 0).map(([key, value]) => `${encodeURIComponent(key)}=${encodeURIComponent(String(value))}`);
105
+ return filtered.length > 0 ? `?${filtered.join("&")}` : "";
106
+ }
107
+ /**
108
+ * Perform HTTP request
109
+ */
110
+ async request(method, endpoint, options) {
111
+ const url = this.buildUrl(endpoint) + (options?.params ? this.buildQueryString(options.params) : "");
112
+ const headers = this.buildHeaders(options?.headers);
113
+ const controller = new AbortController();
114
+ const timeoutId = setTimeout(() => controller.abort(), this.timeout);
115
+ try {
116
+ const response = await fetch(url, {
117
+ method,
118
+ headers,
119
+ body: options?.body ? JSON.stringify(options.body) : void 0,
120
+ credentials: this.credentials,
121
+ signal: controller.signal
122
+ });
123
+ clearTimeout(timeoutId);
124
+ if (response.status === 401 && this.auth.handleUnauthorized) {
125
+ await this.auth.handleUnauthorized();
126
+ }
127
+ if (!response.ok) {
128
+ const errorText = await response.text().catch(() => "");
129
+ throw MarvinApiError.fromResponse(
130
+ response.status,
131
+ response.statusText,
132
+ endpoint,
133
+ errorText
134
+ );
135
+ }
136
+ const contentType = response.headers.get("content-type");
137
+ if (!contentType || !contentType.includes("application/json")) {
138
+ return void 0;
139
+ }
140
+ return await response.json();
141
+ } catch (error) {
142
+ clearTimeout(timeoutId);
143
+ if (error instanceof MarvinApiError) {
144
+ throw error;
145
+ }
146
+ if (error instanceof Error) {
147
+ if (error.name === "AbortError") {
148
+ throw new MarvinApiError(
149
+ `Request timeout after ${this.timeout}ms`,
150
+ 408,
151
+ endpoint
152
+ );
153
+ }
154
+ throw new MarvinApiError(error.message, 0, endpoint);
155
+ }
156
+ throw error;
157
+ }
158
+ }
159
+ /**
160
+ * GET request
161
+ */
162
+ async get(endpoint, params) {
163
+ return this.request("GET", endpoint, { params });
164
+ }
165
+ /**
166
+ * POST request
167
+ */
168
+ async post(endpoint, body) {
169
+ return this.request("POST", endpoint, { body });
170
+ }
171
+ /**
172
+ * PUT request
173
+ */
174
+ async put(endpoint, body) {
175
+ return this.request("PUT", endpoint, { body });
176
+ }
177
+ /**
178
+ * PATCH request
179
+ */
180
+ async patch(endpoint, body) {
181
+ return this.request("PATCH", endpoint, { body });
182
+ }
183
+ /**
184
+ * DELETE request
185
+ */
186
+ async delete(endpoint) {
187
+ return this.request("DELETE", endpoint);
188
+ }
189
+ };
190
+
191
+ // src/core/auth/AuthStrategy.ts
192
+ var SessionAuth = class {
193
+ constructor(sessionToken, onUnauthorized) {
194
+ this.sessionToken = sessionToken;
195
+ this.onUnauthorized = onUnauthorized;
196
+ }
197
+ sessionToken;
198
+ onUnauthorized;
199
+ injectAuth(headers) {
200
+ if (this.sessionToken) {
201
+ headers.set("Authorization", `Bearer ${this.sessionToken}`);
202
+ }
203
+ }
204
+ async handleUnauthorized() {
205
+ if (this.onUnauthorized) {
206
+ await this.onUnauthorized();
207
+ }
208
+ }
209
+ getDescription() {
210
+ return this.sessionToken ? "Session authentication (explicit token)" : "Session authentication (cookies)";
211
+ }
212
+ };
213
+
214
+ // src/platform/entries.ts
215
+ var EntriesModule = class {
216
+ constructor(http) {
217
+ this.http = http;
218
+ }
219
+ http;
220
+ /**
221
+ * List all entries
222
+ */
223
+ async list() {
224
+ return this.http.get("/api/platform/entries");
225
+ }
226
+ /**
227
+ * Get a single entry by ID
228
+ */
229
+ async get(id) {
230
+ return this.http.get(`/api/platform/entries/${id}`);
231
+ }
232
+ /**
233
+ * Create a new entry
234
+ */
235
+ async create(data) {
236
+ return this.http.post("/api/platform/entries", data);
237
+ }
238
+ /**
239
+ * Update an entry
240
+ */
241
+ async update(id, data) {
242
+ return this.http.patch(`/api/platform/entries/${id}`, data);
243
+ }
244
+ /**
245
+ * Delete an entry
246
+ */
247
+ async delete(id) {
248
+ return this.http.delete(`/api/platform/entries/${id}`);
249
+ }
250
+ /**
251
+ * Get collections that this entry belongs to
252
+ */
253
+ async listCollections(entryId) {
254
+ return this.http.get(`/api/platform/entries/${entryId}/collections`);
255
+ }
256
+ /**
257
+ * Add entry to a collection
258
+ */
259
+ async addToCollection(entryId, collectionId) {
260
+ return this.http.post(
261
+ `/api/platform/entries/${entryId}/collections/${collectionId}`,
262
+ {}
263
+ );
264
+ }
265
+ /**
266
+ * Remove entry from a collection
267
+ */
268
+ async removeFromCollection(entryId, collectionId) {
269
+ return this.http.delete(`/api/platform/entries/${entryId}/collections/${collectionId}`);
270
+ }
271
+ };
272
+
273
+ // src/platform/collections.ts
274
+ var CollectionsModule = class {
275
+ constructor(http) {
276
+ this.http = http;
277
+ }
278
+ http;
279
+ /**
280
+ * List all collections
281
+ */
282
+ async list() {
283
+ return this.http.get("/api/platform/collections");
284
+ }
285
+ /**
286
+ * Get a single collection by ID
287
+ */
288
+ async get(id) {
289
+ return this.http.get(`/api/platform/collections/${id}`);
290
+ }
291
+ /**
292
+ * Create a new collection
293
+ */
294
+ async create(data) {
295
+ return this.http.post("/api/platform/collections", data);
296
+ }
297
+ /**
298
+ * Update a collection
299
+ */
300
+ async update(id, data) {
301
+ return this.http.patch(`/api/platform/collections/${id}`, data);
302
+ }
303
+ /**
304
+ * Delete a collection
305
+ */
306
+ async delete(id) {
307
+ return this.http.delete(`/api/platform/collections/${id}`);
308
+ }
309
+ /**
310
+ * Get entries in a collection
311
+ */
312
+ async getEntries(id) {
313
+ return this.http.get(`/api/platform/collections/${id}/entries`);
314
+ }
315
+ };
316
+
317
+ // src/platform/resources.ts
318
+ var ResourcesModule = class {
319
+ constructor(http) {
320
+ this.http = http;
321
+ }
322
+ http;
323
+ /**
324
+ * List all resources
325
+ */
326
+ async list() {
327
+ return this.http.get("/api/platform/resources");
328
+ }
329
+ /**
330
+ * Get a single resource by ID
331
+ */
332
+ async get(id) {
333
+ return this.http.get(`/api/platform/resources/${id}`);
334
+ }
335
+ /**
336
+ * Create a new resource
337
+ */
338
+ async create(data) {
339
+ return this.http.post("/api/platform/resources", data);
340
+ }
341
+ /**
342
+ * Update a resource
343
+ */
344
+ async update(id, data) {
345
+ return this.http.patch(`/api/platform/resources/${id}`, data);
346
+ }
347
+ /**
348
+ * Delete a resource
349
+ */
350
+ async delete(id) {
351
+ return this.http.delete(`/api/platform/resources/${id}`);
352
+ }
353
+ /**
354
+ * Get entries that reference this resource
355
+ */
356
+ async getEntries(id) {
357
+ return this.http.get(`/api/platform/resources/${id}/entries`);
358
+ }
359
+ };
360
+
361
+ // src/platform/assets.ts
362
+ var AssetsModule = class {
363
+ constructor(http) {
364
+ this.http = http;
365
+ }
366
+ http;
367
+ /**
368
+ * List all assets
369
+ */
370
+ async list() {
371
+ return this.http.get("/api/platform/assets");
372
+ }
373
+ /**
374
+ * Get a single asset by ID
375
+ */
376
+ async get(id) {
377
+ return this.http.get(`/api/platform/assets/${id}`);
378
+ }
379
+ /**
380
+ * Create a new asset
381
+ */
382
+ async create(data) {
383
+ return this.http.post("/api/platform/assets", data);
384
+ }
385
+ /**
386
+ * Update an asset
387
+ */
388
+ async update(id, data) {
389
+ return this.http.patch(`/api/platform/assets/${id}`, data);
390
+ }
391
+ /**
392
+ * Delete an asset
393
+ */
394
+ async delete(id) {
395
+ return this.http.delete(`/api/platform/assets/${id}`);
396
+ }
397
+ };
398
+
399
+ // src/platform/apiClients.ts
400
+ var APIClientsModule = class {
401
+ constructor(http) {
402
+ this.http = http;
403
+ }
404
+ http;
405
+ /**
406
+ * List all API clients
407
+ */
408
+ async list() {
409
+ return this.http.get("/api/platform/api-clients");
410
+ }
411
+ /**
412
+ * Get a single API client by ID
413
+ */
414
+ async get(id) {
415
+ return this.http.get(`/api/platform/api-clients/${id}`);
416
+ }
417
+ /**
418
+ * Create a new API client (returns client with token)
419
+ */
420
+ async create(data) {
421
+ return this.http.post("/api/platform/api-clients", data);
422
+ }
423
+ /**
424
+ * Update an API client
425
+ */
426
+ async update(id, data) {
427
+ return this.http.patch(`/api/platform/api-clients/${id}`, data);
428
+ }
429
+ /**
430
+ * Delete an API client
431
+ */
432
+ async delete(id) {
433
+ return this.http.delete(`/api/platform/api-clients/${id}`);
434
+ }
435
+ /**
436
+ * Rotate API client token (generates new token, invalidates old one)
437
+ */
438
+ async rotateToken(id) {
439
+ return this.http.post(
440
+ `/api/platform/api-clients/${id}/rotate-token`,
441
+ {}
442
+ );
443
+ }
444
+ /**
445
+ * Preview API client token (show token prefix and metadata without revealing full token)
446
+ */
447
+ async preview(id) {
448
+ return this.http.get(`/api/platform/api-clients/${id}/preview`);
449
+ }
450
+ };
451
+
452
+ // src/platform/entryTypes.ts
453
+ var EntryTypesModule = class {
454
+ constructor(http) {
455
+ this.http = http;
456
+ }
457
+ http;
458
+ /**
459
+ * List all entry types
460
+ */
461
+ async list() {
462
+ return this.http.get("/api/platform/entry-types");
463
+ }
464
+ /**
465
+ * Get a single entry type by ID
466
+ */
467
+ async get(id) {
468
+ return this.http.get(`/api/platform/entry-types/${id}`);
469
+ }
470
+ };
471
+
472
+ // src/platform/workspaceMembers.ts
473
+ var WorkspaceMembersModule = class {
474
+ constructor(http) {
475
+ this.http = http;
476
+ }
477
+ http;
478
+ /**
479
+ * List all members of a workspace
480
+ */
481
+ async list(workspaceId) {
482
+ return this.http.get(
483
+ `/api/platform/workspaces/${workspaceId}/members`
484
+ );
485
+ }
486
+ /**
487
+ * Get a specific workspace member
488
+ */
489
+ async get(workspaceId, userId) {
490
+ return this.http.get(
491
+ `/api/platform/workspaces/${workspaceId}/members/${userId}`
492
+ );
493
+ }
494
+ /**
495
+ * Add a user to a workspace with a specific role
496
+ */
497
+ async add(workspaceId, data) {
498
+ return this.http.post(
499
+ `/api/platform/workspaces/${workspaceId}/members`,
500
+ data
501
+ );
502
+ }
503
+ /**
504
+ * Update a workspace member's role
505
+ */
506
+ async updateRole(workspaceId, userId, data) {
507
+ return this.http.put(
508
+ `/api/platform/workspaces/${workspaceId}/members/${userId}`,
509
+ data
510
+ );
511
+ }
512
+ /**
513
+ * Remove a user from a workspace
514
+ */
515
+ async remove(workspaceId, userId) {
516
+ return this.http.delete(`/api/platform/workspaces/${workspaceId}/members/${userId}`);
517
+ }
518
+ };
519
+
520
+ // src/platform/client.ts
521
+ var PlatformClient = class extends HttpClient {
522
+ entries;
523
+ collections;
524
+ resources;
525
+ assets;
526
+ apiClients;
527
+ entryTypes;
528
+ workspaceMembers;
529
+ constructor(config) {
530
+ const httpConfig = {
531
+ baseUrl: config.apiUrl,
532
+ auth: new SessionAuth(config.userToken),
533
+ credentials: config.credentials || "include"
534
+ };
535
+ super(httpConfig);
536
+ this.entries = new EntriesModule(this);
537
+ this.collections = new CollectionsModule(this);
538
+ this.resources = new ResourcesModule(this);
539
+ this.assets = new AssetsModule(this);
540
+ this.apiClients = new APIClientsModule(this);
541
+ this.entryTypes = new EntryTypesModule(this);
542
+ this.workspaceMembers = new WorkspaceMembersModule(this);
543
+ }
544
+ };
545
+ function createPlatformClient(config) {
546
+ return new PlatformClient(config);
547
+ }
548
+ // Annotate the CommonJS export names for ESM import in node:
549
+ 0 && (module.exports = {
550
+ APIClientsModule,
551
+ AssetsModule,
552
+ CollectionsModule,
553
+ EntriesModule,
554
+ EntryTypesModule,
555
+ PlatformClient,
556
+ ResourcesModule,
557
+ WorkspaceMembersModule,
558
+ createPlatformClient
559
+ });