@inneropen/marvin-sdk 1.0.3 → 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.
- package/dist/HttpClient-CLtgQGXH.d.cts +113 -0
- package/dist/HttpClient-CLtgQGXH.d.ts +113 -0
- package/dist/chunk-LQOFJMRJ.js +391 -0
- package/dist/index.cjs +350 -33
- package/dist/index.d.cts +102 -5
- package/dist/index.d.ts +102 -5
- package/dist/index.js +51 -97
- package/dist/platform.cjs +547 -0
- package/dist/platform.d.cts +2698 -0
- package/dist/platform.d.ts +2698 -0
- package/dist/platform.js +342 -0
- package/dist/types/index.d.cts +2 -0
- package/dist/types/index.d.ts +2 -0
- package/package.json +10 -3
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import { MarvinResource, MarvinEntry, MarvinAsset, MarvinCollection, MarvinEntryType, MarvinSite, GetResourcesOptions as GetResourcesOptions$1 } from './types/index.js';
|
|
2
2
|
export { GetAssetsOptions, GetEntriesOptions, MarvinPublishResponse } from './types/index.js';
|
|
3
|
+
import { H as HttpClient } from './HttpClient-CLtgQGXH.js';
|
|
4
|
+
export { A as AuthStrategy, B as BearerTokenAuth, a as HttpClientConfig, N as NoAuth, S as SessionAuth } from './HttpClient-CLtgQGXH.js';
|
|
3
5
|
|
|
4
6
|
/**
|
|
5
7
|
* Marvin SDK Configuration
|
|
@@ -16,14 +18,109 @@ interface MarvinConfig {
|
|
|
16
18
|
declare function createConfigFromEnv(overrides?: Partial<MarvinConfig>): MarvinConfig;
|
|
17
19
|
|
|
18
20
|
/**
|
|
19
|
-
*
|
|
21
|
+
* Base error class for all Marvin SDK errors
|
|
20
22
|
*/
|
|
23
|
+
declare class MarvinError extends Error {
|
|
24
|
+
readonly code?: string | undefined;
|
|
25
|
+
readonly statusCode?: number | undefined;
|
|
26
|
+
constructor(message: string, code?: string | undefined, statusCode?: number | undefined);
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* HTTP/API request errors
|
|
30
|
+
*/
|
|
31
|
+
declare class MarvinApiError extends MarvinError {
|
|
32
|
+
readonly statusCode: number;
|
|
33
|
+
readonly endpoint: string;
|
|
34
|
+
readonly responseBody?: string | undefined;
|
|
35
|
+
constructor(message: string, statusCode: number, endpoint: string, responseBody?: string | undefined);
|
|
36
|
+
static fromResponse(status: number, statusText: string, endpoint: string, body?: string): MarvinApiError;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Authentication/authorization errors
|
|
40
|
+
*/
|
|
41
|
+
declare class MarvinAuthError extends MarvinError {
|
|
42
|
+
constructor(message: string, statusCode?: number);
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Configuration errors
|
|
46
|
+
*/
|
|
47
|
+
declare class MarvinConfigError extends MarvinError {
|
|
48
|
+
constructor(message: string);
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Validation errors
|
|
52
|
+
*/
|
|
53
|
+
declare class MarvinValidationError extends MarvinError {
|
|
54
|
+
readonly field?: string | undefined;
|
|
55
|
+
constructor(message: string, field?: string | undefined);
|
|
56
|
+
}
|
|
21
57
|
|
|
22
|
-
|
|
23
|
-
|
|
58
|
+
/**
|
|
59
|
+
* Pagination response types and helpers
|
|
60
|
+
*/
|
|
61
|
+
interface PaginationMeta {
|
|
62
|
+
total?: number;
|
|
63
|
+
page?: number;
|
|
64
|
+
limit?: number;
|
|
65
|
+
offset?: number;
|
|
66
|
+
hasMore?: boolean;
|
|
67
|
+
}
|
|
68
|
+
interface PaginatedResponse<T> {
|
|
69
|
+
data: T[];
|
|
70
|
+
meta?: PaginationMeta;
|
|
71
|
+
}
|
|
72
|
+
interface PaginationParams {
|
|
73
|
+
limit?: number;
|
|
74
|
+
offset?: number;
|
|
75
|
+
page?: number;
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Create a paginated response
|
|
79
|
+
*/
|
|
80
|
+
declare function createPaginatedResponse<T>(data: T[], meta?: PaginationMeta): PaginatedResponse<T>;
|
|
81
|
+
/**
|
|
82
|
+
* Extract data from paginated response
|
|
83
|
+
*/
|
|
84
|
+
declare function extractData<T>(response: PaginatedResponse<T> | T[]): T[];
|
|
85
|
+
/**
|
|
86
|
+
* Check if response is paginated
|
|
87
|
+
*/
|
|
88
|
+
declare function isPaginatedResponse<T>(response: PaginatedResponse<T> | T[]): response is PaginatedResponse<T>;
|
|
89
|
+
/**
|
|
90
|
+
* Calculate pagination offset from page number
|
|
91
|
+
*/
|
|
92
|
+
declare function pageToOffset(page: number, limit: number): number;
|
|
93
|
+
/**
|
|
94
|
+
* Calculate page number from offset
|
|
95
|
+
*/
|
|
96
|
+
declare function offsetToPage(offset: number, limit: number): number;
|
|
97
|
+
|
|
98
|
+
/**
|
|
99
|
+
* Simple in-memory cache for SDK data
|
|
100
|
+
*/
|
|
101
|
+
declare class MarvinCache {
|
|
102
|
+
private duration;
|
|
103
|
+
private cache;
|
|
104
|
+
constructor(duration?: number);
|
|
105
|
+
get<T>(key: string): T | undefined;
|
|
106
|
+
set<T>(key: string, data: T): void;
|
|
107
|
+
has(key: string): boolean;
|
|
108
|
+
clear(): void;
|
|
109
|
+
delete(key: string): void;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
/**
|
|
113
|
+
* HTTP Client for Marvin Publishing API
|
|
114
|
+
*
|
|
115
|
+
* Wrapper around core HttpClient for Publishing API specifics
|
|
116
|
+
*/
|
|
117
|
+
|
|
118
|
+
declare class MarvinHttpClient extends HttpClient {
|
|
24
119
|
constructor(config: MarvinConfig);
|
|
120
|
+
/**
|
|
121
|
+
* Fetch endpoint (backward compatibility)
|
|
122
|
+
*/
|
|
25
123
|
fetch<T>(endpoint: string): Promise<T>;
|
|
26
|
-
buildQueryString(params: Record<string, string | number | undefined>): string;
|
|
27
124
|
}
|
|
28
125
|
|
|
29
126
|
/**
|
|
@@ -427,4 +524,4 @@ declare class MarvinClient {
|
|
|
427
524
|
*/
|
|
428
525
|
declare function createMarvinClient(config?: Partial<MarvinConfig>): MarvinClient;
|
|
429
526
|
|
|
430
|
-
export { Collection, Entry, GetResourcesOptions$1 as GetResourcesOptions, MarvinAsset, MarvinClient, MarvinCollection, type MarvinConfig, MarvinEntry, MarvinEntryType, MarvinResource, MarvinSite, Resource, Workspace, createConfigFromEnv, createMarvinClient };
|
|
527
|
+
export { Collection, Entry, GetResourcesOptions$1 as GetResourcesOptions, HttpClient, MarvinApiError, MarvinAsset, MarvinAuthError, MarvinCache, MarvinClient, MarvinCollection, type MarvinConfig, MarvinConfigError, MarvinEntry, MarvinEntryType, MarvinError, MarvinResource, MarvinSite, MarvinValidationError, type PaginatedResponse, type PaginationMeta, type PaginationParams, Resource, Workspace, createConfigFromEnv, createMarvinClient, createPaginatedResponse, extractData, isPaginatedResponse, offsetToPage, pageToOffset };
|
package/dist/index.js
CHANGED
|
@@ -1,23 +1,24 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
1
|
+
import {
|
|
2
|
+
BearerTokenAuth,
|
|
3
|
+
HttpClient,
|
|
4
|
+
MarvinApiError,
|
|
5
|
+
MarvinAuthError,
|
|
6
|
+
MarvinCache,
|
|
7
|
+
MarvinConfigError,
|
|
8
|
+
MarvinError,
|
|
9
|
+
MarvinValidationError,
|
|
10
|
+
NoAuth,
|
|
11
|
+
SessionAuth,
|
|
12
|
+
__esm,
|
|
13
|
+
__export,
|
|
14
|
+
__toCommonJS,
|
|
15
|
+
createPaginatedResponse,
|
|
16
|
+
extractData,
|
|
17
|
+
init_core,
|
|
18
|
+
isPaginatedResponse,
|
|
19
|
+
offsetToPage,
|
|
20
|
+
pageToOffset
|
|
21
|
+
} from "./chunk-LQOFJMRJ.js";
|
|
21
22
|
|
|
22
23
|
// src/client/config.ts
|
|
23
24
|
var config_exports = {};
|
|
@@ -57,82 +58,20 @@ var MarvinHttpClient;
|
|
|
57
58
|
var init_http = __esm({
|
|
58
59
|
"src/client/http.ts"() {
|
|
59
60
|
"use strict";
|
|
60
|
-
|
|
61
|
+
init_core();
|
|
62
|
+
MarvinHttpClient = class extends HttpClient {
|
|
61
63
|
constructor(config) {
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
const url = `${this.config.apiUrl}${endpoint}`;
|
|
67
|
-
try {
|
|
68
|
-
const response = await fetch(url, {
|
|
69
|
-
headers: {
|
|
70
|
-
"Authorization": `Bearer ${this.config.siteClientToken}`,
|
|
71
|
-
"Content-Type": "application/json"
|
|
72
|
-
}
|
|
73
|
-
});
|
|
74
|
-
if (!response.ok) {
|
|
75
|
-
const errorText = await response.text();
|
|
76
|
-
throw new Error(
|
|
77
|
-
`Marvin API error: ${response.status} ${response.statusText} at ${endpoint}
|
|
78
|
-
${errorText}`
|
|
79
|
-
);
|
|
80
|
-
}
|
|
81
|
-
return await response.json();
|
|
82
|
-
} catch (error) {
|
|
83
|
-
if (error instanceof Error) {
|
|
84
|
-
const safeMessage = error.message.replace(
|
|
85
|
-
this.config.siteClientToken,
|
|
86
|
-
"[REDACTED]"
|
|
87
|
-
);
|
|
88
|
-
throw new Error(safeMessage);
|
|
89
|
-
}
|
|
90
|
-
throw error;
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
buildQueryString(params) {
|
|
94
|
-
const filtered = Object.entries(params).filter(([_, value]) => value !== void 0).map(([key, value]) => `${key}=${encodeURIComponent(String(value))}`);
|
|
95
|
-
return filtered.length > 0 ? `?${filtered.join("&")}` : "";
|
|
96
|
-
}
|
|
97
|
-
};
|
|
98
|
-
}
|
|
99
|
-
});
|
|
100
|
-
|
|
101
|
-
// src/utils/cache.ts
|
|
102
|
-
var MarvinCache;
|
|
103
|
-
var init_cache = __esm({
|
|
104
|
-
"src/utils/cache.ts"() {
|
|
105
|
-
"use strict";
|
|
106
|
-
MarvinCache = class {
|
|
107
|
-
constructor(duration = 5 * 60 * 1e3) {
|
|
108
|
-
this.duration = duration;
|
|
109
|
-
}
|
|
110
|
-
duration;
|
|
111
|
-
cache = /* @__PURE__ */ new Map();
|
|
112
|
-
get(key) {
|
|
113
|
-
const entry = this.cache.get(key);
|
|
114
|
-
if (!entry) return void 0;
|
|
115
|
-
const age = Date.now() - entry.timestamp;
|
|
116
|
-
if (age > this.duration) {
|
|
117
|
-
this.cache.delete(key);
|
|
118
|
-
return void 0;
|
|
119
|
-
}
|
|
120
|
-
return entry.data;
|
|
121
|
-
}
|
|
122
|
-
set(key, data) {
|
|
123
|
-
this.cache.set(key, {
|
|
124
|
-
data,
|
|
125
|
-
timestamp: Date.now()
|
|
64
|
+
super({
|
|
65
|
+
baseUrl: config.apiUrl,
|
|
66
|
+
auth: new BearerTokenAuth(config.siteClientToken),
|
|
67
|
+
credentials: "same-origin"
|
|
126
68
|
});
|
|
127
69
|
}
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
this.
|
|
133
|
-
}
|
|
134
|
-
delete(key) {
|
|
135
|
-
this.cache.delete(key);
|
|
70
|
+
/**
|
|
71
|
+
* Fetch endpoint (backward compatibility)
|
|
72
|
+
*/
|
|
73
|
+
async fetch(endpoint) {
|
|
74
|
+
return this.get(endpoint);
|
|
136
75
|
}
|
|
137
76
|
};
|
|
138
77
|
}
|
|
@@ -330,8 +269,7 @@ var init_collection = __esm({
|
|
|
330
269
|
* Get all entries in this collection
|
|
331
270
|
*/
|
|
332
271
|
async entries() {
|
|
333
|
-
|
|
334
|
-
return this.http.fetch(endpoint);
|
|
272
|
+
return this.data.entries || [];
|
|
335
273
|
}
|
|
336
274
|
/**
|
|
337
275
|
* Get assets in this collection (future)
|
|
@@ -628,7 +566,7 @@ var init_marvin = __esm({
|
|
|
628
566
|
"use strict";
|
|
629
567
|
init_config();
|
|
630
568
|
init_http();
|
|
631
|
-
|
|
569
|
+
init_core();
|
|
632
570
|
init_workspace();
|
|
633
571
|
MarvinClient = class {
|
|
634
572
|
constructor(config) {
|
|
@@ -829,6 +767,7 @@ var init_marvin = __esm({
|
|
|
829
767
|
// src/index.ts
|
|
830
768
|
init_marvin();
|
|
831
769
|
init_config();
|
|
770
|
+
init_core();
|
|
832
771
|
init_workspace();
|
|
833
772
|
init_entry();
|
|
834
773
|
init_collection();
|
|
@@ -840,11 +779,26 @@ function createMarvinClient(config) {
|
|
|
840
779
|
return new MarvinClient2(finalConfig);
|
|
841
780
|
}
|
|
842
781
|
export {
|
|
782
|
+
BearerTokenAuth,
|
|
843
783
|
Collection,
|
|
844
784
|
Entry,
|
|
785
|
+
HttpClient,
|
|
786
|
+
MarvinApiError,
|
|
787
|
+
MarvinAuthError,
|
|
788
|
+
MarvinCache,
|
|
845
789
|
MarvinClient,
|
|
790
|
+
MarvinConfigError,
|
|
791
|
+
MarvinError,
|
|
792
|
+
MarvinValidationError,
|
|
793
|
+
NoAuth,
|
|
846
794
|
Resource,
|
|
795
|
+
SessionAuth,
|
|
847
796
|
Workspace,
|
|
848
797
|
createConfigFromEnv,
|
|
849
|
-
createMarvinClient
|
|
798
|
+
createMarvinClient,
|
|
799
|
+
createPaginatedResponse,
|
|
800
|
+
extractData,
|
|
801
|
+
isPaginatedResponse,
|
|
802
|
+
offsetToPage,
|
|
803
|
+
pageToOffset
|
|
850
804
|
};
|