@inneropen/marvin-sdk 1.0.2 → 1.3.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,547 @@
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
+
311
+ // src/platform/resources.ts
312
+ var ResourcesModule = class {
313
+ constructor(http) {
314
+ this.http = http;
315
+ }
316
+ http;
317
+ /**
318
+ * List all resources
319
+ */
320
+ async list() {
321
+ return this.http.get("/api/platform/resources");
322
+ }
323
+ /**
324
+ * Get a single resource by ID
325
+ */
326
+ async get(id) {
327
+ return this.http.get(`/api/platform/resources/${id}`);
328
+ }
329
+ /**
330
+ * Create a new resource
331
+ */
332
+ async create(data) {
333
+ return this.http.post("/api/platform/resources", data);
334
+ }
335
+ /**
336
+ * Update a resource
337
+ */
338
+ async update(id, data) {
339
+ return this.http.patch(`/api/platform/resources/${id}`, data);
340
+ }
341
+ /**
342
+ * Delete a resource
343
+ */
344
+ async delete(id) {
345
+ return this.http.delete(`/api/platform/resources/${id}`);
346
+ }
347
+ };
348
+
349
+ // src/platform/assets.ts
350
+ var AssetsModule = class {
351
+ constructor(http) {
352
+ this.http = http;
353
+ }
354
+ http;
355
+ /**
356
+ * List all assets
357
+ */
358
+ async list() {
359
+ return this.http.get("/api/platform/assets");
360
+ }
361
+ /**
362
+ * Get a single asset by ID
363
+ */
364
+ async get(id) {
365
+ return this.http.get(`/api/platform/assets/${id}`);
366
+ }
367
+ /**
368
+ * Create a new asset
369
+ */
370
+ async create(data) {
371
+ return this.http.post("/api/platform/assets", data);
372
+ }
373
+ /**
374
+ * Update an asset
375
+ */
376
+ async update(id, data) {
377
+ return this.http.patch(`/api/platform/assets/${id}`, data);
378
+ }
379
+ /**
380
+ * Delete an asset
381
+ */
382
+ async delete(id) {
383
+ return this.http.delete(`/api/platform/assets/${id}`);
384
+ }
385
+ };
386
+
387
+ // src/platform/apiClients.ts
388
+ var APIClientsModule = class {
389
+ constructor(http) {
390
+ this.http = http;
391
+ }
392
+ http;
393
+ /**
394
+ * List all API clients
395
+ */
396
+ async list() {
397
+ return this.http.get("/api/platform/api-clients");
398
+ }
399
+ /**
400
+ * Get a single API client by ID
401
+ */
402
+ async get(id) {
403
+ return this.http.get(`/api/platform/api-clients/${id}`);
404
+ }
405
+ /**
406
+ * Create a new API client (returns client with token)
407
+ */
408
+ async create(data) {
409
+ return this.http.post("/api/platform/api-clients", data);
410
+ }
411
+ /**
412
+ * Update an API client
413
+ */
414
+ async update(id, data) {
415
+ return this.http.patch(`/api/platform/api-clients/${id}`, data);
416
+ }
417
+ /**
418
+ * Delete an API client
419
+ */
420
+ async delete(id) {
421
+ return this.http.delete(`/api/platform/api-clients/${id}`);
422
+ }
423
+ /**
424
+ * Rotate API client token (generates new token, invalidates old one)
425
+ */
426
+ async rotateToken(id) {
427
+ return this.http.post(
428
+ `/api/platform/api-clients/${id}/rotate-token`,
429
+ {}
430
+ );
431
+ }
432
+ /**
433
+ * Preview API client token (show token prefix and metadata without revealing full token)
434
+ */
435
+ async preview(id) {
436
+ return this.http.get(`/api/platform/api-clients/${id}/preview`);
437
+ }
438
+ };
439
+
440
+ // src/platform/entryTypes.ts
441
+ var EntryTypesModule = class {
442
+ constructor(http) {
443
+ this.http = http;
444
+ }
445
+ http;
446
+ /**
447
+ * List all entry types
448
+ */
449
+ async list() {
450
+ return this.http.get("/api/platform/entry-types");
451
+ }
452
+ /**
453
+ * Get a single entry type by ID
454
+ */
455
+ async get(id) {
456
+ return this.http.get(`/api/platform/entry-types/${id}`);
457
+ }
458
+ };
459
+
460
+ // src/platform/workspaceMembers.ts
461
+ var WorkspaceMembersModule = class {
462
+ constructor(http) {
463
+ this.http = http;
464
+ }
465
+ http;
466
+ /**
467
+ * List all members of a workspace
468
+ */
469
+ async list(workspaceId) {
470
+ return this.http.get(
471
+ `/api/platform/workspaces/${workspaceId}/members`
472
+ );
473
+ }
474
+ /**
475
+ * Get a specific workspace member
476
+ */
477
+ async get(workspaceId, userId) {
478
+ return this.http.get(
479
+ `/api/platform/workspaces/${workspaceId}/members/${userId}`
480
+ );
481
+ }
482
+ /**
483
+ * Add a user to a workspace with a specific role
484
+ */
485
+ async add(workspaceId, data) {
486
+ return this.http.post(
487
+ `/api/platform/workspaces/${workspaceId}/members`,
488
+ data
489
+ );
490
+ }
491
+ /**
492
+ * Update a workspace member's role
493
+ */
494
+ async updateRole(workspaceId, userId, data) {
495
+ return this.http.put(
496
+ `/api/platform/workspaces/${workspaceId}/members/${userId}`,
497
+ data
498
+ );
499
+ }
500
+ /**
501
+ * Remove a user from a workspace
502
+ */
503
+ async remove(workspaceId, userId) {
504
+ return this.http.delete(`/api/platform/workspaces/${workspaceId}/members/${userId}`);
505
+ }
506
+ };
507
+
508
+ // src/platform/client.ts
509
+ var PlatformClient = class extends HttpClient {
510
+ entries;
511
+ collections;
512
+ resources;
513
+ assets;
514
+ apiClients;
515
+ entryTypes;
516
+ workspaceMembers;
517
+ constructor(config) {
518
+ const httpConfig = {
519
+ baseUrl: config.apiUrl,
520
+ auth: new SessionAuth(config.userToken),
521
+ credentials: config.credentials || "include"
522
+ };
523
+ super(httpConfig);
524
+ this.entries = new EntriesModule(this);
525
+ this.collections = new CollectionsModule(this);
526
+ this.resources = new ResourcesModule(this);
527
+ this.assets = new AssetsModule(this);
528
+ this.apiClients = new APIClientsModule(this);
529
+ this.entryTypes = new EntryTypesModule(this);
530
+ this.workspaceMembers = new WorkspaceMembersModule(this);
531
+ }
532
+ };
533
+ function createPlatformClient(config) {
534
+ return new PlatformClient(config);
535
+ }
536
+ // Annotate the CommonJS export names for ESM import in node:
537
+ 0 && (module.exports = {
538
+ APIClientsModule,
539
+ AssetsModule,
540
+ CollectionsModule,
541
+ EntriesModule,
542
+ EntryTypesModule,
543
+ PlatformClient,
544
+ ResourcesModule,
545
+ WorkspaceMembersModule,
546
+ createPlatformClient
547
+ });