@viewrium/sdk 0.1.0 → 2.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/LICENSE +202 -0
- package/README.md +194 -87
- package/dist/index.cjs +295 -409
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +3505 -320
- package/dist/index.d.ts +3505 -320
- package/dist/index.js +257 -400
- package/dist/index.js.map +1 -1
- package/package.json +33 -23
package/LICENSE
ADDED
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
|
|
2
|
+
Apache License
|
|
3
|
+
Version 2.0, January 2004
|
|
4
|
+
http://www.apache.org/licenses/
|
|
5
|
+
|
|
6
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
7
|
+
|
|
8
|
+
1. Definitions.
|
|
9
|
+
|
|
10
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
11
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
12
|
+
|
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
14
|
+
the copyright owner that is granting the License.
|
|
15
|
+
|
|
16
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
17
|
+
other entities that control, are controlled by, or are under common
|
|
18
|
+
control with that entity. For the purposes of this definition,
|
|
19
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
20
|
+
direction or management of such entity, whether by contract or
|
|
21
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
22
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
23
|
+
|
|
24
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
25
|
+
exercising permissions granted by this License.
|
|
26
|
+
|
|
27
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
28
|
+
including but not limited to software source code, documentation
|
|
29
|
+
source, and configuration files.
|
|
30
|
+
|
|
31
|
+
"Object" form shall mean any form resulting from mechanical
|
|
32
|
+
transformation or translation of a Source form, including but
|
|
33
|
+
not limited to compiled object code, generated documentation,
|
|
34
|
+
and conversions to other media types.
|
|
35
|
+
|
|
36
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
37
|
+
Object form, made available under the License, as indicated by a
|
|
38
|
+
copyright notice that is included in or attached to the work
|
|
39
|
+
(an example is provided in the Appendix below).
|
|
40
|
+
|
|
41
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
42
|
+
form, that is based on (or derived from) the Work and for which the
|
|
43
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
44
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
45
|
+
of this License, Derivative Works shall not include works that remain
|
|
46
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
47
|
+
the Work and Derivative Works thereof.
|
|
48
|
+
|
|
49
|
+
"Contribution" shall mean any work of authorship, including
|
|
50
|
+
the original version of the Work and any modifications or additions
|
|
51
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
52
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
53
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
54
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
55
|
+
means any form of electronic, verbal, or written communication sent
|
|
56
|
+
to the Licensor or its representatives, including but not limited to
|
|
57
|
+
communication on electronic mailing lists, source code control systems,
|
|
58
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
59
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
60
|
+
excluding communication that is conspicuously marked or otherwise
|
|
61
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
62
|
+
|
|
63
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
64
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
65
|
+
subsequently incorporated within the Work.
|
|
66
|
+
|
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
70
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
71
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
72
|
+
Work and such Derivative Works in Source or Object form.
|
|
73
|
+
|
|
74
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
79
|
+
where such license applies only to those patent claims licensable
|
|
80
|
+
by such Contributor that are necessarily infringed by their
|
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
83
|
+
institute patent litigation against any entity (including a
|
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
86
|
+
or contributory patent infringement, then any patent licenses
|
|
87
|
+
granted to You under this License for that Work shall terminate
|
|
88
|
+
as of the date such litigation is filed.
|
|
89
|
+
|
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
91
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
92
|
+
modifications, and in Source or Object form, provided that You
|
|
93
|
+
meet the following conditions:
|
|
94
|
+
|
|
95
|
+
(a) You must give any other recipients of the Work or
|
|
96
|
+
Derivative Works a copy of this License; and
|
|
97
|
+
|
|
98
|
+
(b) You must cause any modified files to carry prominent notices
|
|
99
|
+
stating that You changed the files; and
|
|
100
|
+
|
|
101
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
102
|
+
that You distribute, all copyright, patent, trademark, and
|
|
103
|
+
attribution notices from the Source form of the Work,
|
|
104
|
+
excluding those notices that do not pertain to any part of
|
|
105
|
+
the Derivative Works; and
|
|
106
|
+
|
|
107
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
108
|
+
distribution, then any Derivative Works that You distribute must
|
|
109
|
+
include a readable copy of the attribution notices contained
|
|
110
|
+
within such NOTICE file, excluding those notices that do not
|
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
|
112
|
+
of the following places: within a NOTICE text file distributed
|
|
113
|
+
as part of the Derivative Works; within the Source form or
|
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
|
115
|
+
within a display generated by the Derivative Works, if and
|
|
116
|
+
wherever such third-party notices normally appear. The contents
|
|
117
|
+
of the NOTICE file are for informational purposes only and
|
|
118
|
+
do not modify the License. You may add Your own attribution
|
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
121
|
+
that such additional attribution notices cannot be construed
|
|
122
|
+
as modifying the License.
|
|
123
|
+
|
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
|
125
|
+
may provide additional or different license terms and conditions
|
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
129
|
+
the conditions stated in this License.
|
|
130
|
+
|
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
134
|
+
this License, without any additional terms or conditions.
|
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
136
|
+
the terms of any separate license agreement you may have executed
|
|
137
|
+
with Licensor regarding such Contributions.
|
|
138
|
+
|
|
139
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
141
|
+
except as required for reasonable and customary use in describing the
|
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
143
|
+
|
|
144
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
|
153
|
+
|
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
158
|
+
liable to You for damages, including any direct, indirect, special,
|
|
159
|
+
incidental, or consequential damages of any character arising as a
|
|
160
|
+
result of this License or out of the use or inability to use the
|
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
163
|
+
other commercial damages or losses), even if such Contributor
|
|
164
|
+
has been advised of the possibility of such damages.
|
|
165
|
+
|
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
169
|
+
or other liability obligations and/or rights consistent with this
|
|
170
|
+
License. However, in accepting such obligations, You may act only
|
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
175
|
+
of your accepting any such warranty or additional liability.
|
|
176
|
+
|
|
177
|
+
END OF TERMS AND CONDITIONS
|
|
178
|
+
|
|
179
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
180
|
+
|
|
181
|
+
To apply the Apache License to your work, attach the following
|
|
182
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
183
|
+
replaced with your own identifying information. (Don't include
|
|
184
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
185
|
+
comment syntax for the file format. We also recommend that a
|
|
186
|
+
file or class name and description of purpose be included on the
|
|
187
|
+
same "printed page" as the copyright notice for easier
|
|
188
|
+
identification within third-party archives.
|
|
189
|
+
|
|
190
|
+
Copyright 2026 Viewrium, Inc.
|
|
191
|
+
|
|
192
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
193
|
+
you may not use this file except in compliance with the License.
|
|
194
|
+
You may obtain a copy of the License at
|
|
195
|
+
|
|
196
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
197
|
+
|
|
198
|
+
Unless required by applicable law or agreed to in writing, software
|
|
199
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
200
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
201
|
+
See the License for the specific language governing permissions and
|
|
202
|
+
limitations under the License.
|
package/README.md
CHANGED
|
@@ -1,144 +1,251 @@
|
|
|
1
1
|
# @viewrium/sdk
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
The official JavaScript/TypeScript SDK for the [Viewrium](https://www.viewrium.com) API.
|
|
4
|
+
|
|
5
|
+
Viewrium is AR and 3D product visualization for furniture retailers: it turns product photos, a
|
|
6
|
+
video, a product page URL or an existing 3D file into catalog images, a GLB model and an
|
|
7
|
+
embeddable 3D/AR viewer. This package is a typed client for the Viewrium `/v1` REST API: create
|
|
8
|
+
products, review and publish them, export images, manage webhooks and API keys, and read usage
|
|
9
|
+
analytics.
|
|
10
|
+
|
|
11
|
+
- Documentation: https://www.viewrium.com/docs
|
|
12
|
+
- SDK reference: https://www.viewrium.com/docs/sdks/javascript
|
|
13
|
+
- Dashboard: https://www.viewrium.com
|
|
4
14
|
|
|
5
15
|
## Install
|
|
6
16
|
|
|
7
17
|
```bash
|
|
8
18
|
npm install @viewrium/sdk
|
|
9
|
-
# or
|
|
10
|
-
pnpm add @viewrium/sdk
|
|
11
|
-
# or
|
|
12
|
-
yarn add @viewrium/sdk
|
|
13
19
|
```
|
|
14
20
|
|
|
15
|
-
|
|
21
|
+
The package ships ESM and CommonJS builds with self-contained type declarations. It runs anywhere
|
|
22
|
+
there is a `fetch`: Node 18+, Bun, Deno, edge runtimes and the browser.
|
|
16
23
|
|
|
17
|
-
##
|
|
24
|
+
## Authentication
|
|
25
|
+
|
|
26
|
+
Every request is authenticated with an API key, sent as `Authorization: Bearer <key>`. The SDK
|
|
27
|
+
sets the header for you.
|
|
28
|
+
|
|
29
|
+
- **Secret keys (`sk_`)** are for servers. They can do everything their scopes allow. Never ship
|
|
30
|
+
one to a browser, a mobile app or a public repository.
|
|
31
|
+
- **Publishable keys (`pk_`)** are safe in a browser but are origin-gated and limited to reading a
|
|
32
|
+
single published product, minting its model ticket and sending analytics beacons. An
|
|
33
|
+
organization with no allowed domains configured has its publishable keys refused everywhere. They power the
|
|
34
|
+
[`<viewrium-viewer>` embed](https://www.viewrium.com/docs/embed); use the embed, not this SDK, to
|
|
35
|
+
show a model on a storefront.
|
|
36
|
+
|
|
37
|
+
Create keys in the dashboard under **Settings -> Advanced -> API keys**. A secret key is shown
|
|
38
|
+
exactly once, on create. See [Authentication](https://www.viewrium.com/docs/authentication) for
|
|
39
|
+
scopes.
|
|
18
40
|
|
|
19
41
|
```ts
|
|
20
|
-
import Viewrium from "@viewrium/sdk";
|
|
42
|
+
import { Viewrium } from "@viewrium/sdk";
|
|
21
43
|
|
|
22
|
-
const
|
|
44
|
+
const client = new Viewrium({ apiKey: process.env.VIEWRIUM_API_KEY! });
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
Options:
|
|
23
48
|
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
49
|
+
```ts
|
|
50
|
+
const client = new Viewrium({
|
|
51
|
+
apiKey: "sk_live_...",
|
|
52
|
+
baseUrl: "https://api.viewrium.com", // default; trailing slash stripped
|
|
53
|
+
fetch: customFetch, // optional; defaults to globalThis.fetch
|
|
29
54
|
});
|
|
55
|
+
```
|
|
30
56
|
|
|
31
|
-
|
|
57
|
+
`createViewrium({ apiKey })` is equivalent to `new Viewrium({ apiKey })`.
|
|
32
58
|
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
59
|
+
## Quickstart
|
|
60
|
+
|
|
61
|
+
`products.create` is the single generation entrypoint. Supply exactly one source: `image_urls`,
|
|
62
|
+
`video_url`, `source_url` (a product page) or `model_url` (an existing 3D file). Sources are URLs
|
|
63
|
+
that Viewrium fetches, so they must be publicly reachable.
|
|
38
64
|
|
|
39
|
-
|
|
65
|
+
A fresh request **parks**: nothing is written, and you get back the plan, the 3D model verdict, the
|
|
66
|
+
price in credits and a `resume_token`. Posting the token back commits the quote and starts the run.
|
|
40
67
|
|
|
41
68
|
```ts
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
69
|
+
import { Viewrium } from "@viewrium/sdk";
|
|
70
|
+
|
|
71
|
+
const client = new Viewrium({ apiKey: process.env.VIEWRIUM_API_KEY! });
|
|
72
|
+
|
|
73
|
+
// 1. Quote
|
|
74
|
+
const quote = await client.products.create({
|
|
75
|
+
image_urls: [
|
|
76
|
+
"https://cdn.example.com/chair-front.jpg",
|
|
77
|
+
"https://cdn.example.com/chair-side.jpg",
|
|
78
|
+
],
|
|
79
|
+
draft: { title: "Oak dining chair", custom_id: "sku-oak-chair", dimensions: { height: 92 } },
|
|
46
80
|
});
|
|
81
|
+
if (quote.status !== "parked") throw new Error("unexpected: already committed");
|
|
82
|
+
console.log(quote.cost.total_credits, quote.plan?.length, quote.model.allowed);
|
|
83
|
+
|
|
84
|
+
// 2. Commit
|
|
85
|
+
const committed = await client.products.create({ resume_token: quote.resume_token });
|
|
86
|
+
if (committed.status === "parked") throw new Error("a resume always commits");
|
|
87
|
+
|
|
88
|
+
// 3. Wait for the run (prefer webhooks in production)
|
|
89
|
+
let product = await client.products.retrieve(committed.id);
|
|
90
|
+
while (product.display_status === "generating") {
|
|
91
|
+
await new Promise((r) => setTimeout(r, 5000));
|
|
92
|
+
product = await client.products.retrieve(product.id);
|
|
93
|
+
}
|
|
94
|
+
console.log(product.display_status, product.model?.status);
|
|
95
|
+
|
|
96
|
+
// 4. Publish
|
|
97
|
+
await client.products.update(product.id, { published: true });
|
|
47
98
|
```
|
|
48
99
|
|
|
49
|
-
|
|
100
|
+
A resume may still edit the `draft` (title, price, tags, dimensions). It may not change the order
|
|
101
|
+
or the overrides: the quote is immutable, and changing what gets generated means a new request.
|
|
102
|
+
A `resume_token` expires after 7 days. A `model_url` source never parks; it commits straight away.
|
|
103
|
+
|
|
104
|
+
See [How generation works](https://www.viewrium.com/docs/generation) and
|
|
105
|
+
[the quote and commit guide](https://www.viewrium.com/docs/guides/quote-and-commit).
|
|
50
106
|
|
|
51
107
|
## Resources
|
|
52
108
|
|
|
53
109
|
| Resource | Methods |
|
|
54
110
|
|---|---|
|
|
55
|
-
| `
|
|
56
|
-
| `
|
|
57
|
-
| `
|
|
58
|
-
| `
|
|
111
|
+
| `client.products` | `create`, `list`, `retrieve`, `update`, `delete`, `batchDelete`, `publish`, `tags`, `review`, `updateImage`, `updateModel`, `rescale`, `createTicket`, `order`, `export` |
|
|
112
|
+
| `client.apiKeys` | `list`, `create`, `revoke` |
|
|
113
|
+
| `client.usage` | `get` |
|
|
114
|
+
| `client.webhooks` | `list`, `create`, `retrieve`, `update`, `delete`, `listDeliveries` |
|
|
115
|
+
| `client.projects` | `list`, `retrieve` |
|
|
116
|
+
| `client.beacon` | `send` |
|
|
117
|
+
| `client` | `health()` |
|
|
118
|
+
|
|
119
|
+
Request and response types (`ProductCreateParams`, `ProductCreateResult`, `ProductParked`,
|
|
120
|
+
`Product`, `PlannedView`, `ModelPlan`, `ProductCost`, `Usage`, `WebhookEndpoint`, and so on) are
|
|
121
|
+
exported and derived from the API's OpenAPI schema.
|
|
59
122
|
|
|
60
|
-
|
|
123
|
+
### Showing a model: tickets
|
|
61
124
|
|
|
62
|
-
|
|
125
|
+
No response carries a URL for a 3D model file - not the product, not a webhook. The only way to a
|
|
126
|
+
model's bytes is a **ticket**: a single-use URL that serves the GLB once and expires within a
|
|
127
|
+
minute (60 s for `view`, 30 s for `ar`). Mint one right before the viewer loads, from the server,
|
|
128
|
+
and hand the URL straight to the page; never store it.
|
|
63
129
|
|
|
64
130
|
```ts
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
//
|
|
68
|
-
const model = await viewrium.models.createFromImages(
|
|
69
|
-
["./chair-front.jpg", "./chair-side.jpg", "./chair-back.jpg"],
|
|
70
|
-
{ customId: "sku-1", height: 90, tags: ["chair"] },
|
|
71
|
-
);
|
|
72
|
-
|
|
73
|
-
// Anywhere: Blob/File (from a browser `<input type=file>` or `fetch` response)
|
|
74
|
-
const response = await fetch("https://example.com/chair.mp4");
|
|
75
|
-
const blob = await response.blob();
|
|
76
|
-
const model2 = await viewrium.models.createFromVideo(blob, {
|
|
77
|
-
customId: "sku-2",
|
|
78
|
-
height: 92,
|
|
131
|
+
const ticket = await client.products.createTicket(productId, {
|
|
132
|
+
kind: "view",
|
|
133
|
+
origin: "https://shop.example.com", // the page that will load the model; an allowed domain
|
|
79
134
|
});
|
|
135
|
+
// ticket.url -> the page's viewer `src`; ticket.expires_at -> when it stops working
|
|
80
136
|
```
|
|
81
137
|
|
|
82
|
-
|
|
138
|
+
A `view` ticket streams only to a request from its `origin`. An `ar` ticket is for Android's Scene
|
|
139
|
+
Viewer, which downloads the file outside the page: mint it on the AR tap. Minting is rate limited
|
|
140
|
+
per IP and per product (429).
|
|
83
141
|
|
|
84
|
-
|
|
142
|
+
### Listing and filtering
|
|
85
143
|
|
|
86
144
|
```ts
|
|
87
|
-
await
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
145
|
+
const page = await client.products.list({
|
|
146
|
+
status: ["published"],
|
|
147
|
+
tag: ["chairs"],
|
|
148
|
+
q: "oak",
|
|
149
|
+
limit: 50,
|
|
150
|
+
sort: "created_at",
|
|
151
|
+
order: "desc",
|
|
91
152
|
});
|
|
153
|
+
for (const product of page.data) {
|
|
154
|
+
console.log(product.id, product.title, product.display_status);
|
|
155
|
+
}
|
|
92
156
|
```
|
|
93
157
|
|
|
158
|
+
`products.tags` and `products.export` take the same filters.
|
|
159
|
+
|
|
160
|
+
### Exporting images
|
|
161
|
+
|
|
162
|
+
`products.export` resolves to a ZIP of finished images as a `Blob` (the 3D model is never
|
|
163
|
+
included). When more images need finishing than one request can do, it resolves to a queued answer
|
|
164
|
+
instead: the images are finished in the background, a download link is emailed, and the same call
|
|
165
|
+
returns the archive once they are done.
|
|
166
|
+
|
|
167
|
+
```ts
|
|
168
|
+
const archive = await client.products.export({ tag: ["chairs"] });
|
|
169
|
+
if (archive instanceof Blob) {
|
|
170
|
+
// write it out
|
|
171
|
+
} else {
|
|
172
|
+
console.log(`finishing ${archive.to_finish} images; a link goes to ${archive.notify_email}`);
|
|
173
|
+
}
|
|
174
|
+
```
|
|
175
|
+
|
|
176
|
+
### Analytics
|
|
177
|
+
|
|
178
|
+
```ts
|
|
179
|
+
const usage = await client.usage.get({
|
|
180
|
+
start: "2026-06-01T00:00:00Z",
|
|
181
|
+
end: "2026-09-01T00:00:00Z",
|
|
182
|
+
granularity: "day",
|
|
183
|
+
group_by: "product",
|
|
184
|
+
});
|
|
185
|
+
for (const row of usage.by_product ?? []) {
|
|
186
|
+
console.log(row.title, row.totals);
|
|
187
|
+
}
|
|
188
|
+
```
|
|
189
|
+
|
|
190
|
+
Traffic from your own team is excluded unless you pass `include_internal: true`.
|
|
191
|
+
|
|
94
192
|
## Errors
|
|
95
193
|
|
|
194
|
+
Non-2xx responses throw a `ViewriumError` subclass. Every error exposes `status`, `code`,
|
|
195
|
+
`message` and `details` from the API's error envelope.
|
|
196
|
+
|
|
96
197
|
```ts
|
|
97
198
|
import {
|
|
98
|
-
ViewriumError,
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
RateLimitError,
|
|
103
|
-
|
|
199
|
+
ViewriumError,
|
|
200
|
+
AuthenticationError,
|
|
201
|
+
PaymentRequiredError,
|
|
202
|
+
ConflictError,
|
|
203
|
+
RateLimitError,
|
|
204
|
+
ConnectionError,
|
|
104
205
|
} from "@viewrium/sdk";
|
|
105
206
|
|
|
106
207
|
try {
|
|
107
|
-
await
|
|
208
|
+
await client.products.create({ image_urls: ["https://cdn.example.com/chair.jpg"] });
|
|
108
209
|
} catch (err) {
|
|
109
|
-
if (err instanceof
|
|
110
|
-
//
|
|
210
|
+
if (err instanceof AuthenticationError) {
|
|
211
|
+
// 401: missing or invalid key
|
|
212
|
+
} else if (err instanceof PaymentRequiredError) {
|
|
213
|
+
// 402: the plan does not allow this; err.details.reason says why
|
|
214
|
+
} else if (err instanceof ConflictError) {
|
|
215
|
+
// 409: e.g. a duplicate custom_id or a replayed resume_token
|
|
111
216
|
} else if (err instanceof RateLimitError) {
|
|
112
|
-
|
|
113
|
-
} else {
|
|
114
|
-
|
|
217
|
+
// 429: rate limited, or code "quota_exceeded" when credits run out
|
|
218
|
+
} else if (err instanceof ConnectionError) {
|
|
219
|
+
// the request never reached the API
|
|
220
|
+
} else if (err instanceof ViewriumError) {
|
|
221
|
+
console.log(err.status, err.code, err.message, err.details);
|
|
115
222
|
}
|
|
116
223
|
}
|
|
117
224
|
```
|
|
118
225
|
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
226
|
+
| HTTP | Error |
|
|
227
|
+
|---|---|
|
|
228
|
+
| 400 | `BadRequestError` |
|
|
229
|
+
| 401 | `AuthenticationError` |
|
|
230
|
+
| 402 | `PaymentRequiredError` |
|
|
231
|
+
| 403 | `PermissionError` |
|
|
232
|
+
| 404 | `NotFoundError` |
|
|
233
|
+
| 409 | `ConflictError` |
|
|
234
|
+
| 422 | `UnprocessableEntityError` |
|
|
235
|
+
| 429 | `RateLimitError` |
|
|
236
|
+
| 5xx | `ServerError` |
|
|
237
|
+
| none | `ConnectionError` |
|
|
238
|
+
|
|
239
|
+
The SDK does not retry. On a `RateLimitError`, back off and retry with an exponential delay.
|
|
240
|
+
|
|
241
|
+
## Links
|
|
242
|
+
|
|
243
|
+
- [Quickstart](https://www.viewrium.com/docs/quickstart)
|
|
244
|
+
- [JavaScript SDK reference](https://www.viewrium.com/docs/sdks/javascript)
|
|
245
|
+
- [Webhooks](https://www.viewrium.com/docs/webhooks)
|
|
246
|
+
- [API reference](https://www.viewrium.com/docs/api-reference)
|
|
247
|
+
- Support: support@viewrium.com
|
|
141
248
|
|
|
142
249
|
## License
|
|
143
250
|
|
|
144
|
-
Apache
|
|
251
|
+
Apache-2.0
|