@viewrium/sdk 0.1.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/README.md +144 -0
- package/dist/index.cjs +449 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +350 -0
- package/dist/index.d.ts +350 -0
- package/dist/index.js +438 -0
- package/dist/index.js.map +1 -0
- package/package.json +52 -0
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,350 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Typed error hierarchy for the Viewrium SDK.
|
|
3
|
+
*
|
|
4
|
+
* All API-originated failures inherit from `ViewriumError`. Network-level
|
|
5
|
+
* failures (connection reset, DNS) bubble up as the underlying fetch error
|
|
6
|
+
* unchanged.
|
|
7
|
+
*/
|
|
8
|
+
declare class ViewriumError extends Error {
|
|
9
|
+
readonly statusCode: number | undefined;
|
|
10
|
+
readonly responseBody: unknown;
|
|
11
|
+
constructor(message: string, options?: {
|
|
12
|
+
statusCode?: number;
|
|
13
|
+
responseBody?: unknown;
|
|
14
|
+
});
|
|
15
|
+
}
|
|
16
|
+
declare class AuthError extends ViewriumError {
|
|
17
|
+
constructor(message: string, options?: {
|
|
18
|
+
statusCode?: number;
|
|
19
|
+
responseBody?: unknown;
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
declare class NotFoundError extends ViewriumError {
|
|
23
|
+
constructor(message: string, options?: {
|
|
24
|
+
statusCode?: number;
|
|
25
|
+
responseBody?: unknown;
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
declare class ValidationError extends ViewriumError {
|
|
29
|
+
constructor(message: string, options?: {
|
|
30
|
+
statusCode?: number;
|
|
31
|
+
responseBody?: unknown;
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
declare class RateLimitError extends ViewriumError {
|
|
35
|
+
readonly retryAfter: number | undefined;
|
|
36
|
+
constructor(message: string, options?: {
|
|
37
|
+
statusCode?: number;
|
|
38
|
+
responseBody?: unknown;
|
|
39
|
+
retryAfter?: number;
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
declare class APIError extends ViewriumError {
|
|
43
|
+
constructor(message: string, options?: {
|
|
44
|
+
statusCode?: number;
|
|
45
|
+
responseBody?: unknown;
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* Public types for the Viewrium SDK.
|
|
51
|
+
*
|
|
52
|
+
* Response shapes mirror the backend JSON contract (snake_case). Request
|
|
53
|
+
* param interfaces use camelCase; the SDK maps camelCase → snake_case on
|
|
54
|
+
* the wire.
|
|
55
|
+
*/
|
|
56
|
+
interface ViewriumOptions {
|
|
57
|
+
/** Override the API key. Defaults to the value passed to `new Viewrium(...)`. */
|
|
58
|
+
apiKey?: string;
|
|
59
|
+
/** Base URL. Defaults to `process.env.VIEWRIUM_API_BASE` or `https://api.viewrium.com`. */
|
|
60
|
+
apiBase?: string;
|
|
61
|
+
/** Per-request timeout in milliseconds. Default 60_000. */
|
|
62
|
+
timeoutMs?: number;
|
|
63
|
+
/** Retries on 429 / 5xx. Default 3. */
|
|
64
|
+
maxRetries?: number;
|
|
65
|
+
/** Override `globalThis.fetch` (test seams / custom transports). */
|
|
66
|
+
fetch?: typeof fetch;
|
|
67
|
+
}
|
|
68
|
+
type SizeUnit = "cm" | "in";
|
|
69
|
+
type ModelStatus = "uploading" | "processing" | "queueing" | "successful" | "failed" | "expired";
|
|
70
|
+
type SourceType = "scan" | "upload" | "image";
|
|
71
|
+
type UsageEventType = "generation.created" | "generation.completed" | "generation.failed" | "view" | "ar_enter" | "ar_session_ended";
|
|
72
|
+
interface Model {
|
|
73
|
+
id: string;
|
|
74
|
+
project_id: string | null;
|
|
75
|
+
custom_id: string | null;
|
|
76
|
+
title: string | null;
|
|
77
|
+
description: string | null;
|
|
78
|
+
price: number | null;
|
|
79
|
+
currency: string | null;
|
|
80
|
+
status: ModelStatus;
|
|
81
|
+
source_type: SourceType | null;
|
|
82
|
+
model_url: string | null;
|
|
83
|
+
thumbnail_url: string | null;
|
|
84
|
+
height: number | null;
|
|
85
|
+
width: number | null;
|
|
86
|
+
depth: number | null;
|
|
87
|
+
scale_factor: number | null;
|
|
88
|
+
tags: string[];
|
|
89
|
+
metadata: Record<string, unknown>;
|
|
90
|
+
display_enabled: boolean;
|
|
91
|
+
created_at: string;
|
|
92
|
+
completed_at: string | null;
|
|
93
|
+
[key: string]: unknown;
|
|
94
|
+
}
|
|
95
|
+
interface ModelListResponse {
|
|
96
|
+
data: Model[];
|
|
97
|
+
limit: number;
|
|
98
|
+
offset: number;
|
|
99
|
+
}
|
|
100
|
+
interface ModelEvent {
|
|
101
|
+
id: string;
|
|
102
|
+
event_type: UsageEventType;
|
|
103
|
+
timestamp: string;
|
|
104
|
+
metadata: Record<string, unknown>;
|
|
105
|
+
}
|
|
106
|
+
interface ModelEventListResponse {
|
|
107
|
+
data: ModelEvent[];
|
|
108
|
+
limit: number;
|
|
109
|
+
offset: number;
|
|
110
|
+
}
|
|
111
|
+
interface DeletedResponse {
|
|
112
|
+
id: string;
|
|
113
|
+
deleted: true;
|
|
114
|
+
}
|
|
115
|
+
interface ApiKey {
|
|
116
|
+
id: string;
|
|
117
|
+
name: string | null;
|
|
118
|
+
key_type: "secret" | "publishable";
|
|
119
|
+
key_prefix: string;
|
|
120
|
+
last_used_at: string | null;
|
|
121
|
+
revoked_at: string | null;
|
|
122
|
+
created_at: string;
|
|
123
|
+
}
|
|
124
|
+
/** Returned by `apiKeys.create` - `key` is plaintext, shown once. */
|
|
125
|
+
interface ApiKeyWithSecret extends Omit<ApiKey, "last_used_at" | "revoked_at"> {
|
|
126
|
+
key: string;
|
|
127
|
+
}
|
|
128
|
+
interface ApiKeyListResponse {
|
|
129
|
+
data: ApiKey[];
|
|
130
|
+
}
|
|
131
|
+
interface RevokedResponse {
|
|
132
|
+
id: string;
|
|
133
|
+
revoked: true;
|
|
134
|
+
}
|
|
135
|
+
interface UsageSummary {
|
|
136
|
+
org_id: string;
|
|
137
|
+
plan_tier: "free" | "pro" | "enterprise";
|
|
138
|
+
since: string | null;
|
|
139
|
+
until: string | null;
|
|
140
|
+
counts: Partial<Record<UsageEventType, number>>;
|
|
141
|
+
}
|
|
142
|
+
interface TagSummary {
|
|
143
|
+
tag: string;
|
|
144
|
+
count: number;
|
|
145
|
+
}
|
|
146
|
+
interface TagListResponse {
|
|
147
|
+
data: TagSummary[];
|
|
148
|
+
}
|
|
149
|
+
interface ModelCreateParams {
|
|
150
|
+
customId?: string;
|
|
151
|
+
title?: string;
|
|
152
|
+
description?: string;
|
|
153
|
+
/** Provide one of `images` (URL list) or `sourceUrl` - not both. */
|
|
154
|
+
images?: string[];
|
|
155
|
+
/** Product page URL. Server extracts candidate images. */
|
|
156
|
+
sourceUrl?: string;
|
|
157
|
+
height?: number;
|
|
158
|
+
sizeUnit?: SizeUnit;
|
|
159
|
+
tags?: string[];
|
|
160
|
+
price?: number;
|
|
161
|
+
currency?: string;
|
|
162
|
+
metadata?: Record<string, unknown>;
|
|
163
|
+
displayEnabled?: boolean;
|
|
164
|
+
}
|
|
165
|
+
interface ModelCreateFromImagesParams {
|
|
166
|
+
title?: string;
|
|
167
|
+
customId?: string;
|
|
168
|
+
description?: string;
|
|
169
|
+
height?: number;
|
|
170
|
+
sizeUnit?: SizeUnit;
|
|
171
|
+
tags?: string[];
|
|
172
|
+
displayEnabled?: boolean;
|
|
173
|
+
}
|
|
174
|
+
interface ModelCreateFromVideoParams extends ModelCreateFromImagesParams {
|
|
175
|
+
}
|
|
176
|
+
interface ModelUpdateParams {
|
|
177
|
+
customId?: string;
|
|
178
|
+
title?: string;
|
|
179
|
+
description?: string;
|
|
180
|
+
price?: number;
|
|
181
|
+
currency?: string;
|
|
182
|
+
height?: number;
|
|
183
|
+
sizeUnit?: SizeUnit;
|
|
184
|
+
tags?: string[];
|
|
185
|
+
metadata?: Record<string, unknown>;
|
|
186
|
+
displayEnabled?: boolean;
|
|
187
|
+
}
|
|
188
|
+
interface ModelListParams {
|
|
189
|
+
tag?: string;
|
|
190
|
+
tags?: string[] | string;
|
|
191
|
+
customId?: string;
|
|
192
|
+
status?: ModelStatus;
|
|
193
|
+
limit?: number;
|
|
194
|
+
offset?: number;
|
|
195
|
+
}
|
|
196
|
+
interface ModelListEventsParams {
|
|
197
|
+
limit?: number;
|
|
198
|
+
offset?: number;
|
|
199
|
+
}
|
|
200
|
+
interface ApiKeyCreateParams {
|
|
201
|
+
name?: string;
|
|
202
|
+
/**
|
|
203
|
+
* Type of key to create. Defaults to `"secret"`.
|
|
204
|
+
* - `"secret"` (sk_*): server-only, authenticates /v1/* calls.
|
|
205
|
+
* - `"publishable"` (pk_*): client-safe, used by the embed tag. Origin
|
|
206
|
+
* restrictions inherit from the project's allowed_domains.
|
|
207
|
+
*/
|
|
208
|
+
keyType?: "secret" | "publishable";
|
|
209
|
+
}
|
|
210
|
+
interface UsageRetrieveParams {
|
|
211
|
+
/** ISO 8601 lower bound (inclusive). */
|
|
212
|
+
since?: string;
|
|
213
|
+
/** ISO 8601 upper bound (inclusive). */
|
|
214
|
+
until?: string;
|
|
215
|
+
}
|
|
216
|
+
/**
|
|
217
|
+
* A file passed to multipart endpoints.
|
|
218
|
+
*
|
|
219
|
+
* - In Node: a path string (SDK reads it via `fs.readFile`) or a `Blob`/`File`.
|
|
220
|
+
* - In browsers / edge runtimes: `Blob` / `File` (native).
|
|
221
|
+
* - Anywhere: a `{ data, filename, contentType? }` record with raw bytes.
|
|
222
|
+
*/
|
|
223
|
+
type FileInput = string | Blob | {
|
|
224
|
+
data: Uint8Array | ArrayBuffer | Blob;
|
|
225
|
+
filename?: string;
|
|
226
|
+
contentType?: string;
|
|
227
|
+
};
|
|
228
|
+
|
|
229
|
+
/**
|
|
230
|
+
* Models resource - 3D models (backed by the `scans` table).
|
|
231
|
+
*
|
|
232
|
+
* Mirrors the 8 `/v1/models*` endpoints. camelCase param names are mapped
|
|
233
|
+
* to the snake_case wire contract on the way out; response shapes pass
|
|
234
|
+
* through as-is.
|
|
235
|
+
*/
|
|
236
|
+
|
|
237
|
+
declare class ModelsResource {
|
|
238
|
+
private readonly client;
|
|
239
|
+
constructor(client: Viewrium);
|
|
240
|
+
create(params: ModelCreateParams): Promise<Model>;
|
|
241
|
+
createFromImages(images: FileInput[], params?: ModelCreateFromImagesParams): Promise<Model>;
|
|
242
|
+
createFromVideo(video: FileInput, params?: ModelCreateFromVideoParams): Promise<Model>;
|
|
243
|
+
retrieve(modelId: string): Promise<Model>;
|
|
244
|
+
list(params?: ModelListParams): Promise<ModelListResponse>;
|
|
245
|
+
modify(modelId: string, params: ModelUpdateParams): Promise<Model>;
|
|
246
|
+
delete(modelId: string): Promise<DeletedResponse>;
|
|
247
|
+
listEvents(modelId: string, params?: ModelListEventsParams): Promise<ModelEventListResponse>;
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
/**
|
|
251
|
+
* Api keys resource.
|
|
252
|
+
*
|
|
253
|
+
* Creates secret (`sk_*`) or publishable (`pk_*`) keys. pk keys inherit
|
|
254
|
+
* origin restrictions from their project's `allowed_domains`. The plaintext
|
|
255
|
+
* key is returned ONCE from `create()`; store it securely on your side.
|
|
256
|
+
*/
|
|
257
|
+
|
|
258
|
+
declare class ApiKeysResource {
|
|
259
|
+
private readonly client;
|
|
260
|
+
constructor(client: Viewrium);
|
|
261
|
+
create(params?: ApiKeyCreateParams): Promise<ApiKeyWithSecret>;
|
|
262
|
+
list(): Promise<ApiKeyListResponse>;
|
|
263
|
+
delete(keyId: string): Promise<RevokedResponse>;
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
/**
|
|
267
|
+
* Usage resource.
|
|
268
|
+
*
|
|
269
|
+
* Returns aggregated event counts for the caller's organization. Internal
|
|
270
|
+
* service events (rodin / gemini / scrape / convert / store) are never
|
|
271
|
+
* exposed here.
|
|
272
|
+
*/
|
|
273
|
+
|
|
274
|
+
declare class UsageResource {
|
|
275
|
+
private readonly client;
|
|
276
|
+
constructor(client: Viewrium);
|
|
277
|
+
retrieve(params?: UsageRetrieveParams): Promise<UsageSummary>;
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
/**
|
|
281
|
+
* Tags resource.
|
|
282
|
+
*
|
|
283
|
+
* Lists unique tags across the caller's organization with per-tag model
|
|
284
|
+
* counts. Tags are created implicitly when assigned to a model; there is
|
|
285
|
+
* no POST /v1/tags endpoint.
|
|
286
|
+
*/
|
|
287
|
+
|
|
288
|
+
declare class TagsResource {
|
|
289
|
+
private readonly client;
|
|
290
|
+
constructor(client: Viewrium);
|
|
291
|
+
list(): Promise<TagListResponse>;
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
/**
|
|
295
|
+
* Viewrium client.
|
|
296
|
+
*
|
|
297
|
+
* Instantiate once per api key:
|
|
298
|
+
*
|
|
299
|
+
* const viewrium = new Viewrium(process.env.VIEWRIUM_API_KEY!);
|
|
300
|
+
* const model = await viewrium.models.create({ images: [...] });
|
|
301
|
+
*
|
|
302
|
+
* The client uses `globalThis.fetch` by default (Node 18+, browsers, edge
|
|
303
|
+
* runtimes all provide it). Pass `fetch` in options for custom transports
|
|
304
|
+
* or testing.
|
|
305
|
+
*/
|
|
306
|
+
|
|
307
|
+
interface RequestOptions {
|
|
308
|
+
method: string;
|
|
309
|
+
path: string;
|
|
310
|
+
query?: Record<string, unknown>;
|
|
311
|
+
json?: unknown;
|
|
312
|
+
body?: BodyInit;
|
|
313
|
+
headers?: Record<string, string>;
|
|
314
|
+
/** Override per-request timeout in ms. */
|
|
315
|
+
timeoutMs?: number;
|
|
316
|
+
}
|
|
317
|
+
declare class Viewrium {
|
|
318
|
+
readonly models: ModelsResource;
|
|
319
|
+
readonly apiKeys: ApiKeysResource;
|
|
320
|
+
readonly usage: UsageResource;
|
|
321
|
+
readonly tags: TagsResource;
|
|
322
|
+
private readonly apiKey;
|
|
323
|
+
private readonly apiBase;
|
|
324
|
+
private readonly timeoutMs;
|
|
325
|
+
private readonly maxRetries;
|
|
326
|
+
private readonly fetchImpl;
|
|
327
|
+
constructor(apiKey?: string, options?: ViewriumOptions);
|
|
328
|
+
/** Low-level request. Resources delegate here. */
|
|
329
|
+
request<T = unknown>(options: RequestOptions): Promise<T>;
|
|
330
|
+
private buildUrl;
|
|
331
|
+
private buildHeaders;
|
|
332
|
+
private buildBody;
|
|
333
|
+
}
|
|
334
|
+
|
|
335
|
+
/**
|
|
336
|
+
* Official JavaScript / TypeScript SDK for the Viewrium API.
|
|
337
|
+
*
|
|
338
|
+
* import Viewrium from "@viewrium/sdk";
|
|
339
|
+
*
|
|
340
|
+
* const viewrium = new Viewrium(process.env.VIEWRIUM_API_KEY!);
|
|
341
|
+
*
|
|
342
|
+
* const model = await viewrium.models.create({
|
|
343
|
+
* customId: "sku-1",
|
|
344
|
+
* images: ["https://example.com/img1.jpg"],
|
|
345
|
+
* height: 90,
|
|
346
|
+
* tags: ["chair", "summer-2026"],
|
|
347
|
+
* });
|
|
348
|
+
*/
|
|
349
|
+
|
|
350
|
+
export { APIError, type ApiKey, type ApiKeyCreateParams, type ApiKeyListResponse, type ApiKeyWithSecret, ApiKeysResource, AuthError, type DeletedResponse, type FileInput, type Model, type ModelCreateFromImagesParams, type ModelCreateFromVideoParams, type ModelCreateParams, type ModelEvent, type ModelEventListResponse, type ModelListEventsParams, type ModelListParams, type ModelListResponse, type ModelStatus, type ModelUpdateParams, ModelsResource, NotFoundError, RateLimitError, type RequestOptions, type RevokedResponse, type SizeUnit, type SourceType, type TagListResponse, type TagSummary, TagsResource, type UsageEventType, UsageResource, type UsageRetrieveParams, type UsageSummary, ValidationError, Viewrium, ViewriumError, type ViewriumOptions, Viewrium as default };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,350 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Typed error hierarchy for the Viewrium SDK.
|
|
3
|
+
*
|
|
4
|
+
* All API-originated failures inherit from `ViewriumError`. Network-level
|
|
5
|
+
* failures (connection reset, DNS) bubble up as the underlying fetch error
|
|
6
|
+
* unchanged.
|
|
7
|
+
*/
|
|
8
|
+
declare class ViewriumError extends Error {
|
|
9
|
+
readonly statusCode: number | undefined;
|
|
10
|
+
readonly responseBody: unknown;
|
|
11
|
+
constructor(message: string, options?: {
|
|
12
|
+
statusCode?: number;
|
|
13
|
+
responseBody?: unknown;
|
|
14
|
+
});
|
|
15
|
+
}
|
|
16
|
+
declare class AuthError extends ViewriumError {
|
|
17
|
+
constructor(message: string, options?: {
|
|
18
|
+
statusCode?: number;
|
|
19
|
+
responseBody?: unknown;
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
declare class NotFoundError extends ViewriumError {
|
|
23
|
+
constructor(message: string, options?: {
|
|
24
|
+
statusCode?: number;
|
|
25
|
+
responseBody?: unknown;
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
declare class ValidationError extends ViewriumError {
|
|
29
|
+
constructor(message: string, options?: {
|
|
30
|
+
statusCode?: number;
|
|
31
|
+
responseBody?: unknown;
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
declare class RateLimitError extends ViewriumError {
|
|
35
|
+
readonly retryAfter: number | undefined;
|
|
36
|
+
constructor(message: string, options?: {
|
|
37
|
+
statusCode?: number;
|
|
38
|
+
responseBody?: unknown;
|
|
39
|
+
retryAfter?: number;
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
declare class APIError extends ViewriumError {
|
|
43
|
+
constructor(message: string, options?: {
|
|
44
|
+
statusCode?: number;
|
|
45
|
+
responseBody?: unknown;
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* Public types for the Viewrium SDK.
|
|
51
|
+
*
|
|
52
|
+
* Response shapes mirror the backend JSON contract (snake_case). Request
|
|
53
|
+
* param interfaces use camelCase; the SDK maps camelCase → snake_case on
|
|
54
|
+
* the wire.
|
|
55
|
+
*/
|
|
56
|
+
interface ViewriumOptions {
|
|
57
|
+
/** Override the API key. Defaults to the value passed to `new Viewrium(...)`. */
|
|
58
|
+
apiKey?: string;
|
|
59
|
+
/** Base URL. Defaults to `process.env.VIEWRIUM_API_BASE` or `https://api.viewrium.com`. */
|
|
60
|
+
apiBase?: string;
|
|
61
|
+
/** Per-request timeout in milliseconds. Default 60_000. */
|
|
62
|
+
timeoutMs?: number;
|
|
63
|
+
/** Retries on 429 / 5xx. Default 3. */
|
|
64
|
+
maxRetries?: number;
|
|
65
|
+
/** Override `globalThis.fetch` (test seams / custom transports). */
|
|
66
|
+
fetch?: typeof fetch;
|
|
67
|
+
}
|
|
68
|
+
type SizeUnit = "cm" | "in";
|
|
69
|
+
type ModelStatus = "uploading" | "processing" | "queueing" | "successful" | "failed" | "expired";
|
|
70
|
+
type SourceType = "scan" | "upload" | "image";
|
|
71
|
+
type UsageEventType = "generation.created" | "generation.completed" | "generation.failed" | "view" | "ar_enter" | "ar_session_ended";
|
|
72
|
+
interface Model {
|
|
73
|
+
id: string;
|
|
74
|
+
project_id: string | null;
|
|
75
|
+
custom_id: string | null;
|
|
76
|
+
title: string | null;
|
|
77
|
+
description: string | null;
|
|
78
|
+
price: number | null;
|
|
79
|
+
currency: string | null;
|
|
80
|
+
status: ModelStatus;
|
|
81
|
+
source_type: SourceType | null;
|
|
82
|
+
model_url: string | null;
|
|
83
|
+
thumbnail_url: string | null;
|
|
84
|
+
height: number | null;
|
|
85
|
+
width: number | null;
|
|
86
|
+
depth: number | null;
|
|
87
|
+
scale_factor: number | null;
|
|
88
|
+
tags: string[];
|
|
89
|
+
metadata: Record<string, unknown>;
|
|
90
|
+
display_enabled: boolean;
|
|
91
|
+
created_at: string;
|
|
92
|
+
completed_at: string | null;
|
|
93
|
+
[key: string]: unknown;
|
|
94
|
+
}
|
|
95
|
+
interface ModelListResponse {
|
|
96
|
+
data: Model[];
|
|
97
|
+
limit: number;
|
|
98
|
+
offset: number;
|
|
99
|
+
}
|
|
100
|
+
interface ModelEvent {
|
|
101
|
+
id: string;
|
|
102
|
+
event_type: UsageEventType;
|
|
103
|
+
timestamp: string;
|
|
104
|
+
metadata: Record<string, unknown>;
|
|
105
|
+
}
|
|
106
|
+
interface ModelEventListResponse {
|
|
107
|
+
data: ModelEvent[];
|
|
108
|
+
limit: number;
|
|
109
|
+
offset: number;
|
|
110
|
+
}
|
|
111
|
+
interface DeletedResponse {
|
|
112
|
+
id: string;
|
|
113
|
+
deleted: true;
|
|
114
|
+
}
|
|
115
|
+
interface ApiKey {
|
|
116
|
+
id: string;
|
|
117
|
+
name: string | null;
|
|
118
|
+
key_type: "secret" | "publishable";
|
|
119
|
+
key_prefix: string;
|
|
120
|
+
last_used_at: string | null;
|
|
121
|
+
revoked_at: string | null;
|
|
122
|
+
created_at: string;
|
|
123
|
+
}
|
|
124
|
+
/** Returned by `apiKeys.create` - `key` is plaintext, shown once. */
|
|
125
|
+
interface ApiKeyWithSecret extends Omit<ApiKey, "last_used_at" | "revoked_at"> {
|
|
126
|
+
key: string;
|
|
127
|
+
}
|
|
128
|
+
interface ApiKeyListResponse {
|
|
129
|
+
data: ApiKey[];
|
|
130
|
+
}
|
|
131
|
+
interface RevokedResponse {
|
|
132
|
+
id: string;
|
|
133
|
+
revoked: true;
|
|
134
|
+
}
|
|
135
|
+
interface UsageSummary {
|
|
136
|
+
org_id: string;
|
|
137
|
+
plan_tier: "free" | "pro" | "enterprise";
|
|
138
|
+
since: string | null;
|
|
139
|
+
until: string | null;
|
|
140
|
+
counts: Partial<Record<UsageEventType, number>>;
|
|
141
|
+
}
|
|
142
|
+
interface TagSummary {
|
|
143
|
+
tag: string;
|
|
144
|
+
count: number;
|
|
145
|
+
}
|
|
146
|
+
interface TagListResponse {
|
|
147
|
+
data: TagSummary[];
|
|
148
|
+
}
|
|
149
|
+
interface ModelCreateParams {
|
|
150
|
+
customId?: string;
|
|
151
|
+
title?: string;
|
|
152
|
+
description?: string;
|
|
153
|
+
/** Provide one of `images` (URL list) or `sourceUrl` - not both. */
|
|
154
|
+
images?: string[];
|
|
155
|
+
/** Product page URL. Server extracts candidate images. */
|
|
156
|
+
sourceUrl?: string;
|
|
157
|
+
height?: number;
|
|
158
|
+
sizeUnit?: SizeUnit;
|
|
159
|
+
tags?: string[];
|
|
160
|
+
price?: number;
|
|
161
|
+
currency?: string;
|
|
162
|
+
metadata?: Record<string, unknown>;
|
|
163
|
+
displayEnabled?: boolean;
|
|
164
|
+
}
|
|
165
|
+
interface ModelCreateFromImagesParams {
|
|
166
|
+
title?: string;
|
|
167
|
+
customId?: string;
|
|
168
|
+
description?: string;
|
|
169
|
+
height?: number;
|
|
170
|
+
sizeUnit?: SizeUnit;
|
|
171
|
+
tags?: string[];
|
|
172
|
+
displayEnabled?: boolean;
|
|
173
|
+
}
|
|
174
|
+
interface ModelCreateFromVideoParams extends ModelCreateFromImagesParams {
|
|
175
|
+
}
|
|
176
|
+
interface ModelUpdateParams {
|
|
177
|
+
customId?: string;
|
|
178
|
+
title?: string;
|
|
179
|
+
description?: string;
|
|
180
|
+
price?: number;
|
|
181
|
+
currency?: string;
|
|
182
|
+
height?: number;
|
|
183
|
+
sizeUnit?: SizeUnit;
|
|
184
|
+
tags?: string[];
|
|
185
|
+
metadata?: Record<string, unknown>;
|
|
186
|
+
displayEnabled?: boolean;
|
|
187
|
+
}
|
|
188
|
+
interface ModelListParams {
|
|
189
|
+
tag?: string;
|
|
190
|
+
tags?: string[] | string;
|
|
191
|
+
customId?: string;
|
|
192
|
+
status?: ModelStatus;
|
|
193
|
+
limit?: number;
|
|
194
|
+
offset?: number;
|
|
195
|
+
}
|
|
196
|
+
interface ModelListEventsParams {
|
|
197
|
+
limit?: number;
|
|
198
|
+
offset?: number;
|
|
199
|
+
}
|
|
200
|
+
interface ApiKeyCreateParams {
|
|
201
|
+
name?: string;
|
|
202
|
+
/**
|
|
203
|
+
* Type of key to create. Defaults to `"secret"`.
|
|
204
|
+
* - `"secret"` (sk_*): server-only, authenticates /v1/* calls.
|
|
205
|
+
* - `"publishable"` (pk_*): client-safe, used by the embed tag. Origin
|
|
206
|
+
* restrictions inherit from the project's allowed_domains.
|
|
207
|
+
*/
|
|
208
|
+
keyType?: "secret" | "publishable";
|
|
209
|
+
}
|
|
210
|
+
interface UsageRetrieveParams {
|
|
211
|
+
/** ISO 8601 lower bound (inclusive). */
|
|
212
|
+
since?: string;
|
|
213
|
+
/** ISO 8601 upper bound (inclusive). */
|
|
214
|
+
until?: string;
|
|
215
|
+
}
|
|
216
|
+
/**
|
|
217
|
+
* A file passed to multipart endpoints.
|
|
218
|
+
*
|
|
219
|
+
* - In Node: a path string (SDK reads it via `fs.readFile`) or a `Blob`/`File`.
|
|
220
|
+
* - In browsers / edge runtimes: `Blob` / `File` (native).
|
|
221
|
+
* - Anywhere: a `{ data, filename, contentType? }` record with raw bytes.
|
|
222
|
+
*/
|
|
223
|
+
type FileInput = string | Blob | {
|
|
224
|
+
data: Uint8Array | ArrayBuffer | Blob;
|
|
225
|
+
filename?: string;
|
|
226
|
+
contentType?: string;
|
|
227
|
+
};
|
|
228
|
+
|
|
229
|
+
/**
|
|
230
|
+
* Models resource - 3D models (backed by the `scans` table).
|
|
231
|
+
*
|
|
232
|
+
* Mirrors the 8 `/v1/models*` endpoints. camelCase param names are mapped
|
|
233
|
+
* to the snake_case wire contract on the way out; response shapes pass
|
|
234
|
+
* through as-is.
|
|
235
|
+
*/
|
|
236
|
+
|
|
237
|
+
declare class ModelsResource {
|
|
238
|
+
private readonly client;
|
|
239
|
+
constructor(client: Viewrium);
|
|
240
|
+
create(params: ModelCreateParams): Promise<Model>;
|
|
241
|
+
createFromImages(images: FileInput[], params?: ModelCreateFromImagesParams): Promise<Model>;
|
|
242
|
+
createFromVideo(video: FileInput, params?: ModelCreateFromVideoParams): Promise<Model>;
|
|
243
|
+
retrieve(modelId: string): Promise<Model>;
|
|
244
|
+
list(params?: ModelListParams): Promise<ModelListResponse>;
|
|
245
|
+
modify(modelId: string, params: ModelUpdateParams): Promise<Model>;
|
|
246
|
+
delete(modelId: string): Promise<DeletedResponse>;
|
|
247
|
+
listEvents(modelId: string, params?: ModelListEventsParams): Promise<ModelEventListResponse>;
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
/**
|
|
251
|
+
* Api keys resource.
|
|
252
|
+
*
|
|
253
|
+
* Creates secret (`sk_*`) or publishable (`pk_*`) keys. pk keys inherit
|
|
254
|
+
* origin restrictions from their project's `allowed_domains`. The plaintext
|
|
255
|
+
* key is returned ONCE from `create()`; store it securely on your side.
|
|
256
|
+
*/
|
|
257
|
+
|
|
258
|
+
declare class ApiKeysResource {
|
|
259
|
+
private readonly client;
|
|
260
|
+
constructor(client: Viewrium);
|
|
261
|
+
create(params?: ApiKeyCreateParams): Promise<ApiKeyWithSecret>;
|
|
262
|
+
list(): Promise<ApiKeyListResponse>;
|
|
263
|
+
delete(keyId: string): Promise<RevokedResponse>;
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
/**
|
|
267
|
+
* Usage resource.
|
|
268
|
+
*
|
|
269
|
+
* Returns aggregated event counts for the caller's organization. Internal
|
|
270
|
+
* service events (rodin / gemini / scrape / convert / store) are never
|
|
271
|
+
* exposed here.
|
|
272
|
+
*/
|
|
273
|
+
|
|
274
|
+
declare class UsageResource {
|
|
275
|
+
private readonly client;
|
|
276
|
+
constructor(client: Viewrium);
|
|
277
|
+
retrieve(params?: UsageRetrieveParams): Promise<UsageSummary>;
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
/**
|
|
281
|
+
* Tags resource.
|
|
282
|
+
*
|
|
283
|
+
* Lists unique tags across the caller's organization with per-tag model
|
|
284
|
+
* counts. Tags are created implicitly when assigned to a model; there is
|
|
285
|
+
* no POST /v1/tags endpoint.
|
|
286
|
+
*/
|
|
287
|
+
|
|
288
|
+
declare class TagsResource {
|
|
289
|
+
private readonly client;
|
|
290
|
+
constructor(client: Viewrium);
|
|
291
|
+
list(): Promise<TagListResponse>;
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
/**
|
|
295
|
+
* Viewrium client.
|
|
296
|
+
*
|
|
297
|
+
* Instantiate once per api key:
|
|
298
|
+
*
|
|
299
|
+
* const viewrium = new Viewrium(process.env.VIEWRIUM_API_KEY!);
|
|
300
|
+
* const model = await viewrium.models.create({ images: [...] });
|
|
301
|
+
*
|
|
302
|
+
* The client uses `globalThis.fetch` by default (Node 18+, browsers, edge
|
|
303
|
+
* runtimes all provide it). Pass `fetch` in options for custom transports
|
|
304
|
+
* or testing.
|
|
305
|
+
*/
|
|
306
|
+
|
|
307
|
+
interface RequestOptions {
|
|
308
|
+
method: string;
|
|
309
|
+
path: string;
|
|
310
|
+
query?: Record<string, unknown>;
|
|
311
|
+
json?: unknown;
|
|
312
|
+
body?: BodyInit;
|
|
313
|
+
headers?: Record<string, string>;
|
|
314
|
+
/** Override per-request timeout in ms. */
|
|
315
|
+
timeoutMs?: number;
|
|
316
|
+
}
|
|
317
|
+
declare class Viewrium {
|
|
318
|
+
readonly models: ModelsResource;
|
|
319
|
+
readonly apiKeys: ApiKeysResource;
|
|
320
|
+
readonly usage: UsageResource;
|
|
321
|
+
readonly tags: TagsResource;
|
|
322
|
+
private readonly apiKey;
|
|
323
|
+
private readonly apiBase;
|
|
324
|
+
private readonly timeoutMs;
|
|
325
|
+
private readonly maxRetries;
|
|
326
|
+
private readonly fetchImpl;
|
|
327
|
+
constructor(apiKey?: string, options?: ViewriumOptions);
|
|
328
|
+
/** Low-level request. Resources delegate here. */
|
|
329
|
+
request<T = unknown>(options: RequestOptions): Promise<T>;
|
|
330
|
+
private buildUrl;
|
|
331
|
+
private buildHeaders;
|
|
332
|
+
private buildBody;
|
|
333
|
+
}
|
|
334
|
+
|
|
335
|
+
/**
|
|
336
|
+
* Official JavaScript / TypeScript SDK for the Viewrium API.
|
|
337
|
+
*
|
|
338
|
+
* import Viewrium from "@viewrium/sdk";
|
|
339
|
+
*
|
|
340
|
+
* const viewrium = new Viewrium(process.env.VIEWRIUM_API_KEY!);
|
|
341
|
+
*
|
|
342
|
+
* const model = await viewrium.models.create({
|
|
343
|
+
* customId: "sku-1",
|
|
344
|
+
* images: ["https://example.com/img1.jpg"],
|
|
345
|
+
* height: 90,
|
|
346
|
+
* tags: ["chair", "summer-2026"],
|
|
347
|
+
* });
|
|
348
|
+
*/
|
|
349
|
+
|
|
350
|
+
export { APIError, type ApiKey, type ApiKeyCreateParams, type ApiKeyListResponse, type ApiKeyWithSecret, ApiKeysResource, AuthError, type DeletedResponse, type FileInput, type Model, type ModelCreateFromImagesParams, type ModelCreateFromVideoParams, type ModelCreateParams, type ModelEvent, type ModelEventListResponse, type ModelListEventsParams, type ModelListParams, type ModelListResponse, type ModelStatus, type ModelUpdateParams, ModelsResource, NotFoundError, RateLimitError, type RequestOptions, type RevokedResponse, type SizeUnit, type SourceType, type TagListResponse, type TagSummary, TagsResource, type UsageEventType, UsageResource, type UsageRetrieveParams, type UsageSummary, ValidationError, Viewrium, ViewriumError, type ViewriumOptions, Viewrium as default };
|