viewrium 2.2.0__tar.gz → 2.4.0__tar.gz
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.
- {viewrium-2.2.0 → viewrium-2.4.0}/PKG-INFO +2 -3
- {viewrium-2.2.0 → viewrium-2.4.0}/README.md +1 -2
- {viewrium-2.2.0 → viewrium-2.4.0}/package.json +2 -1
- {viewrium-2.2.0 → viewrium-2.4.0}/pyproject.toml +1 -1
- {viewrium-2.2.0 → viewrium-2.4.0}/src/viewrium/__init__.py +5 -7
- {viewrium-2.2.0 → viewrium-2.4.0}/src/viewrium/_client.py +24 -21
- {viewrium-2.2.0 → viewrium-2.4.0}/src/viewrium/_models.py +57 -32
- {viewrium-2.2.0 → viewrium-2.4.0}/tests/test_client.py +60 -0
- {viewrium-2.2.0 → viewrium-2.4.0}/tests/test_import.py +1 -1
- viewrium-2.4.0/tests/test_schema_drift.py +137 -0
- viewrium-2.4.0/turbo.json +16 -0
- {viewrium-2.2.0 → viewrium-2.4.0}/uv.lock +1 -1
- viewrium-2.2.0/turbo.json +0 -10
- {viewrium-2.2.0 → viewrium-2.4.0}/.gitignore +0 -0
- {viewrium-2.2.0 → viewrium-2.4.0}/.python-version +0 -0
- {viewrium-2.2.0 → viewrium-2.4.0}/LICENSE +0 -0
- {viewrium-2.2.0 → viewrium-2.4.0}/src/viewrium/_errors.py +0 -0
- {viewrium-2.2.0 → viewrium-2.4.0}/src/viewrium/py.typed +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.5
|
|
2
2
|
Name: viewrium
|
|
3
|
-
Version: 2.
|
|
3
|
+
Version: 2.4.0
|
|
4
4
|
Summary: Official Python client for the Viewrium API: AR and 3D product visualization for furniture retailers.
|
|
5
5
|
Project-URL: Homepage, https://www.viewrium.com
|
|
6
6
|
Project-URL: Documentation, https://www.viewrium.com/docs/sdks/python
|
|
@@ -167,11 +167,10 @@ See [How generation works](https://www.viewrium.com/docs/generation) and
|
|
|
167
167
|
|
|
168
168
|
| Resource | Methods |
|
|
169
169
|
|---|---|
|
|
170
|
-
| `client.products` | `create`, `list`, `retrieve`, `update`, `delete`, `batch_delete`, `publish`, `tags`, `review`, `update_image`, `update_model`, `rescale`, `create_ticket`, `order`, `export` |
|
|
170
|
+
| `client.products` | `create`, `list`, `retrieve`, `retrieve_by_custom_id`, `update`, `delete`, `batch_delete`, `publish`, `tags`, `review`, `update_image`, `update_model`, `rescale`, `create_ticket`, `order`, `export` |
|
|
171
171
|
| `client.api_keys` | `list`, `create`, `revoke` |
|
|
172
172
|
| `client.usage` | `get` |
|
|
173
173
|
| `client.webhooks` | `list`, `create`, `retrieve`, `update`, `delete`, `list_deliveries` |
|
|
174
|
-
| `client.projects` | `list`, `retrieve` |
|
|
175
174
|
| `client.beacon` | `send` |
|
|
176
175
|
| `client` | `health()` |
|
|
177
176
|
|
|
@@ -141,11 +141,10 @@ See [How generation works](https://www.viewrium.com/docs/generation) and
|
|
|
141
141
|
|
|
142
142
|
| Resource | Methods |
|
|
143
143
|
|---|---|
|
|
144
|
-
| `client.products` | `create`, `list`, `retrieve`, `update`, `delete`, `batch_delete`, `publish`, `tags`, `review`, `update_image`, `update_model`, `rescale`, `create_ticket`, `order`, `export` |
|
|
144
|
+
| `client.products` | `create`, `list`, `retrieve`, `retrieve_by_custom_id`, `update`, `delete`, `batch_delete`, `publish`, `tags`, `review`, `update_image`, `update_model`, `rescale`, `create_ticket`, `order`, `export` |
|
|
145
145
|
| `client.api_keys` | `list`, `create`, `revoke` |
|
|
146
146
|
| `client.usage` | `get` |
|
|
147
147
|
| `client.webhooks` | `list`, `create`, `retrieve`, `update`, `delete`, `list_deliveries` |
|
|
148
|
-
| `client.projects` | `list`, `retrieve` |
|
|
149
148
|
| `client.beacon` | `send` |
|
|
150
149
|
| `client` | `health()` |
|
|
151
150
|
|
|
@@ -20,7 +20,6 @@ from ._client import (
|
|
|
20
20
|
ApiKeysResource,
|
|
21
21
|
BeaconResource,
|
|
22
22
|
ProductsResource,
|
|
23
|
-
ProjectsResource,
|
|
24
23
|
UsageResource,
|
|
25
24
|
Viewrium,
|
|
26
25
|
WebhooksResource,
|
|
@@ -94,8 +93,6 @@ from ._models import (
|
|
|
94
93
|
ProductSummary,
|
|
95
94
|
ProductUpdateRequest,
|
|
96
95
|
ProductWarning,
|
|
97
|
-
Project,
|
|
98
|
-
ProjectListResponse,
|
|
99
96
|
PublicProduct,
|
|
100
97
|
ReviewStatus,
|
|
101
98
|
ShadowContact,
|
|
@@ -115,6 +112,8 @@ from ._models import (
|
|
|
115
112
|
UsageEventType,
|
|
116
113
|
UsageProductTotals,
|
|
117
114
|
UsageResponse,
|
|
115
|
+
ViewerDesktopMode,
|
|
116
|
+
ViewerMobileMode,
|
|
118
117
|
WarningKind,
|
|
119
118
|
WebhookDelivery,
|
|
120
119
|
WebhookDeliveryListResponse,
|
|
@@ -127,7 +126,7 @@ from ._models import (
|
|
|
127
126
|
WidthAxis,
|
|
128
127
|
)
|
|
129
128
|
|
|
130
|
-
__version__ = "2.
|
|
129
|
+
__version__ = "2.4.0"
|
|
131
130
|
|
|
132
131
|
__all__ = [
|
|
133
132
|
"__version__",
|
|
@@ -137,7 +136,6 @@ __all__ = [
|
|
|
137
136
|
"ApiKeysResource",
|
|
138
137
|
"UsageResource",
|
|
139
138
|
"WebhooksResource",
|
|
140
|
-
"ProjectsResource",
|
|
141
139
|
"BeaconResource",
|
|
142
140
|
# errors
|
|
143
141
|
"ViewriumError",
|
|
@@ -171,6 +169,8 @@ __all__ = [
|
|
|
171
169
|
"PaintingEdge",
|
|
172
170
|
"PaintingDimensionsOf",
|
|
173
171
|
"PaintingRebuildStatus",
|
|
172
|
+
"ViewerDesktopMode",
|
|
173
|
+
"ViewerMobileMode",
|
|
174
174
|
# requests
|
|
175
175
|
"ProductCreateRequest",
|
|
176
176
|
"ProductDraft",
|
|
@@ -237,7 +237,5 @@ __all__ = [
|
|
|
237
237
|
"WebhookEndpointCreateResponse",
|
|
238
238
|
"WebhookDelivery",
|
|
239
239
|
"WebhookDeliveryListResponse",
|
|
240
|
-
"Project",
|
|
241
|
-
"ProjectListResponse",
|
|
242
240
|
"HealthResponse",
|
|
243
241
|
]
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
"""The synchronous Viewrium client and its resource namespaces.
|
|
2
2
|
|
|
3
3
|
Method shapes mirror ``@viewrium/sdk`` (one ``products.create`` entrypoint, ``products.list`` /
|
|
4
|
-
``retrieve`` / ``
|
|
5
|
-
``
|
|
6
|
-
``
|
|
7
|
-
publishable key) sent as ``Authorization: Bearer``.
|
|
4
|
+
``retrieve`` / ``retrieve_by_custom_id`` / ``update`` / ``delete`` / ``batch_delete`` /
|
|
5
|
+
``publish`` / ``tags`` / ``review`` / ``update_image`` / ``update_model`` / ``rescale`` /
|
|
6
|
+
``order`` / ``export``, plus ``api_keys``, ``usage``, ``webhooks``, ``beacon``).
|
|
7
|
+
Auth is an ``sk_`` secret key (or ``pk_`` publishable key) sent as ``Authorization: Bearer``.
|
|
8
8
|
"""
|
|
9
9
|
|
|
10
10
|
from __future__ import annotations
|
|
@@ -43,8 +43,6 @@ from ._models import (
|
|
|
43
43
|
ProductReviewResponse,
|
|
44
44
|
ProductSortField,
|
|
45
45
|
ProductUpdateRequest,
|
|
46
|
-
Project,
|
|
47
|
-
ProjectListResponse,
|
|
48
46
|
ReviewStatus,
|
|
49
47
|
SortOrder,
|
|
50
48
|
TagsResponse,
|
|
@@ -139,7 +137,6 @@ class Viewrium:
|
|
|
139
137
|
self.api_keys = ApiKeysResource(self)
|
|
140
138
|
self.usage = UsageResource(self)
|
|
141
139
|
self.webhooks = WebhooksResource(self)
|
|
142
|
-
self.projects = ProjectsResource(self)
|
|
143
140
|
self.beacon = BeaconResource(self)
|
|
144
141
|
|
|
145
142
|
def health(self) -> HealthResponse:
|
|
@@ -255,6 +252,14 @@ class ProductsResource:
|
|
|
255
252
|
allow-listed public projection instead, and only for a published product."""
|
|
256
253
|
return self._client.request("GET", f"/v1/products/{product_id}", Product)
|
|
257
254
|
|
|
255
|
+
def retrieve_by_custom_id(self, custom_id: str, *, org_id: str | None = None) -> Product:
|
|
256
|
+
"""GET /v1/products/lookup?custom_id=... - one product by your own ``custom_id``
|
|
257
|
+
(unique per org), within the key's org; a session passes ``org_id`` unless it has one
|
|
258
|
+
org. Answers what ``retrieve`` answers - a ``pk_`` key gets the public projection, and
|
|
259
|
+
only for a published product - so mint its tickets with the returned ``id``."""
|
|
260
|
+
params: Params = {"custom_id": custom_id, "org_id": org_id}
|
|
261
|
+
return self._client.request("GET", "/v1/products/lookup", Product, params=params)
|
|
262
|
+
|
|
258
263
|
def update(self, product_id: str, request: ProductUpdateRequest) -> Product:
|
|
259
264
|
"""PATCH /v1/products/{id} - the customer's fields, the user-set status and the
|
|
260
265
|
publish toggle. 409 on a ``custom_id`` another product in the org already holds. On a
|
|
@@ -327,6 +332,17 @@ class ProductsResource:
|
|
|
327
332
|
"POST", f"/v1/products/{product_id}/tickets", Ticket, json=_body(request)
|
|
328
333
|
)
|
|
329
334
|
|
|
335
|
+
def qr(self, product_id: str, *, guide: bool = False, size: int = 1024) -> bytes:
|
|
336
|
+
"""GET /v1/products/{id}/qr - the product's QR code as a square PNG, ``size`` px on a
|
|
337
|
+
side (256-2048), as bytes. The code encodes the product's ``viewer_url`` and carries the
|
|
338
|
+
Viewrium mark. ``guide=True`` renders the whole "View in your room" card with its three
|
|
339
|
+
steps; the default is the minimal "View in your room" + code + "Powered by Viewrium".
|
|
340
|
+
Answered before the product is published too, but the link opens only once it is."""
|
|
341
|
+
params: Params = {"guide": guide, "size": size}
|
|
342
|
+
return self._client.request_bytes(
|
|
343
|
+
"GET", f"/v1/products/{product_id}/qr", params=params
|
|
344
|
+
).content
|
|
345
|
+
|
|
330
346
|
def order(self, product_id: str, request: ProductOrderRequest) -> ProductOrderParked:
|
|
331
347
|
"""POST /v1/products/{id}/order - order the missing half. It PARKS: commit the
|
|
332
348
|
returned token with ``create``."""
|
|
@@ -392,7 +408,6 @@ class UsageResource:
|
|
|
392
408
|
org_id: str | None = None,
|
|
393
409
|
scope: ListScope | None = None,
|
|
394
410
|
product_id: str | None = None,
|
|
395
|
-
project_id: str | None = None,
|
|
396
411
|
model_id: str | None = None,
|
|
397
412
|
event_type: UsageEventType | None = None,
|
|
398
413
|
granularity: Literal["hour", "day"] | None = None,
|
|
@@ -403,7 +418,7 @@ class UsageResource:
|
|
|
403
418
|
|
|
404
419
|
Scope: one org (``org_id``, or the principal's only org), every org a session reaches
|
|
405
420
|
(``scope=ListScope.ALL``), or one product (``product_id``, which needs no ``org_id``).
|
|
406
|
-
``
|
|
421
|
+
``model_id`` is the v1 scan-era filter.
|
|
407
422
|
|
|
408
423
|
``start`` / ``end`` are arbitrary - any window, not a preset - and default to the last
|
|
409
424
|
30 days. ``granularity`` buckets by hour or day. Org-internal traffic (an org's own
|
|
@@ -421,7 +436,6 @@ class UsageResource:
|
|
|
421
436
|
"org_id": org_id,
|
|
422
437
|
"scope": scope,
|
|
423
438
|
"product_id": product_id,
|
|
424
|
-
"project_id": project_id,
|
|
425
439
|
"model_id": model_id,
|
|
426
440
|
"event_type": event_type,
|
|
427
441
|
"granularity": granularity,
|
|
@@ -467,17 +481,6 @@ class WebhooksResource:
|
|
|
467
481
|
)
|
|
468
482
|
|
|
469
483
|
|
|
470
|
-
class ProjectsResource:
|
|
471
|
-
def __init__(self, client: Viewrium) -> None:
|
|
472
|
-
self._client = client
|
|
473
|
-
|
|
474
|
-
def list(self) -> ProjectListResponse:
|
|
475
|
-
return self._client.request("GET", "/v1/projects", ProjectListResponse)
|
|
476
|
-
|
|
477
|
-
def retrieve(self, project_id: str) -> Project:
|
|
478
|
-
return self._client.request("GET", f"/v1/projects/{project_id}", Project)
|
|
479
|
-
|
|
480
|
-
|
|
481
484
|
class BeaconResource:
|
|
482
485
|
def __init__(self, client: Viewrium) -> None:
|
|
483
486
|
self._client = client
|
|
@@ -135,14 +135,25 @@ class UsageEventType(StrEnum):
|
|
|
135
135
|
|
|
136
136
|
|
|
137
137
|
class WebhookEventType(StrEnum):
|
|
138
|
-
"""
|
|
139
|
-
|
|
140
|
-
|
|
138
|
+
"""The events an endpoint subscribes to. Every product event's ``data`` is the product's
|
|
139
|
+
public snapshot plus the event's own fields; ``product.deleted`` carries only ``id`` and
|
|
140
|
+
``custom_id``, ``export.ready`` only ids and counts. No payload carries a model file URL.
|
|
141
|
+
|
|
142
|
+
``model.ready`` / ``model.failed`` are DEPRECATED scan-era names: still accepted on an
|
|
143
|
+
endpoint, never sent."""
|
|
141
144
|
|
|
142
145
|
MODEL_READY = "model.ready"
|
|
143
146
|
MODEL_FAILED = "model.failed"
|
|
147
|
+
PRODUCT_CREATED = "product.created"
|
|
148
|
+
PRODUCT_GENERATING = "product.generating"
|
|
144
149
|
PRODUCT_COMPLETED = "product.completed"
|
|
145
150
|
PRODUCT_FAILED = "product.failed"
|
|
151
|
+
PRODUCT_REVIEWED = "product.reviewed"
|
|
152
|
+
PRODUCT_PUBLISHED = "product.published"
|
|
153
|
+
PRODUCT_UNPUBLISHED = "product.unpublished"
|
|
154
|
+
PRODUCT_UPDATED = "product.updated"
|
|
155
|
+
PRODUCT_DELETED = "product.deleted"
|
|
156
|
+
EXPORT_READY = "export.ready"
|
|
146
157
|
|
|
147
158
|
|
|
148
159
|
class DimensionUnit(StrEnum):
|
|
@@ -173,6 +184,26 @@ class PaintingEdge(StrEnum):
|
|
|
173
184
|
STRETCH = "stretch"
|
|
174
185
|
|
|
175
186
|
|
|
187
|
+
class ViewerDesktopMode(StrEnum):
|
|
188
|
+
"""How the embed shows a product on a desktop (``viewer_desktop``): the inline ``viewer``,
|
|
189
|
+
a ``qr`` code that opens it on a phone, a ``button``, or ``hidden``. The element's
|
|
190
|
+
``desktop`` attribute overrides it."""
|
|
191
|
+
|
|
192
|
+
VIEWER = "viewer"
|
|
193
|
+
QR = "qr"
|
|
194
|
+
BUTTON = "button"
|
|
195
|
+
HIDDEN = "hidden"
|
|
196
|
+
|
|
197
|
+
|
|
198
|
+
class ViewerMobileMode(StrEnum):
|
|
199
|
+
"""The same on a phone (``viewer_mobile``): ``viewer``, ``button`` or ``hidden`` - no
|
|
200
|
+
``qr``. The element's ``mobile`` attribute overrides it."""
|
|
201
|
+
|
|
202
|
+
VIEWER = "viewer"
|
|
203
|
+
BUTTON = "button"
|
|
204
|
+
HIDDEN = "hidden"
|
|
205
|
+
|
|
206
|
+
|
|
176
207
|
class PaintingDimensionsOf(StrEnum):
|
|
177
208
|
"""Which rectangle a painting's width x height describe: the ``canvas`` (default) or the
|
|
178
209
|
frame's outer edge (``frame``, only with the ``frame`` edge)."""
|
|
@@ -323,6 +354,9 @@ class ProductUpdateRequest(_Base):
|
|
|
323
354
|
status: ProductStatus | None = None
|
|
324
355
|
published: bool | None = None
|
|
325
356
|
painting: PaintingUpdate | None = None
|
|
357
|
+
#: How the embed shows the product (the element's ``desktop`` / ``mobile`` attributes win).
|
|
358
|
+
viewer_desktop: ViewerDesktopMode | None = None
|
|
359
|
+
viewer_mobile: ViewerMobileMode | None = None
|
|
326
360
|
|
|
327
361
|
|
|
328
362
|
class ProductPublishRequest(_Base):
|
|
@@ -474,9 +508,8 @@ class ProductFilters(_Base):
|
|
|
474
508
|
|
|
475
509
|
class ApiKeyCreateRequest(_Base):
|
|
476
510
|
key_type: KeyType
|
|
477
|
-
# Session-created keys bind to an org
|
|
511
|
+
# Session-created keys bind to an org.
|
|
478
512
|
org_id: str | None = None
|
|
479
|
-
project_id: str | None = None
|
|
480
513
|
name: str | None = None
|
|
481
514
|
scopes: list[str] = Field(default_factory=list)
|
|
482
515
|
|
|
@@ -486,7 +519,6 @@ class WebhookEndpointCreateRequest(_Base):
|
|
|
486
519
|
events: list[WebhookEventType]
|
|
487
520
|
description: str | None = None
|
|
488
521
|
org_id: str | None = None
|
|
489
|
-
project_id: str | None = None
|
|
490
522
|
|
|
491
523
|
|
|
492
524
|
class WebhookEndpointUpdateRequest(_Base):
|
|
@@ -584,7 +616,7 @@ class PaintingInspection(_Base):
|
|
|
584
616
|
|
|
585
617
|
|
|
586
618
|
class ProductCost(_Base):
|
|
587
|
-
"""The priced bundle, in CREDITS (1 credit = $
|
|
619
|
+
"""The priced bundle, in CREDITS (1 credit = $1.00): 1 per deliverable image, a flat 10 for
|
|
588
620
|
a model. Internal 3D gap-fills never enter the maths."""
|
|
589
621
|
|
|
590
622
|
images: int
|
|
@@ -798,6 +830,9 @@ class ProductSummary(_Base):
|
|
|
798
830
|
owner: ProductOwner | None = None
|
|
799
831
|
created_at: datetime
|
|
800
832
|
updated_at: datetime | None = None
|
|
833
|
+
#: The product's hosted viewer page - what its QR code (``products.qr``) encodes. It opens
|
|
834
|
+
#: only while the product is published.
|
|
835
|
+
viewer_url: str | None = None
|
|
801
836
|
|
|
802
837
|
|
|
803
838
|
class Product(ProductSummary):
|
|
@@ -822,6 +857,8 @@ class Product(ProductSummary):
|
|
|
822
857
|
open_request_count: int = 0
|
|
823
858
|
#: A painting's settings (form ``painting``); null for every other product.
|
|
824
859
|
painting: PaintingSettings | None = None
|
|
860
|
+
viewer_desktop: ViewerDesktopMode = ViewerDesktopMode.VIEWER
|
|
861
|
+
viewer_mobile: ViewerMobileMode = ViewerMobileMode.VIEWER
|
|
825
862
|
|
|
826
863
|
|
|
827
864
|
class PublicProduct(_Base):
|
|
@@ -835,6 +872,9 @@ class PublicProduct(_Base):
|
|
|
835
872
|
model_status: AssetStatus | None = None
|
|
836
873
|
wall_mounted: bool = False
|
|
837
874
|
painting: PaintingSettings | None = None
|
|
875
|
+
#: How the embed shows it; the element's ``desktop`` / ``mobile`` attributes override these.
|
|
876
|
+
viewer_desktop: ViewerDesktopMode = ViewerDesktopMode.VIEWER
|
|
877
|
+
viewer_mobile: ViewerMobileMode = ViewerMobileMode.VIEWER
|
|
838
878
|
|
|
839
879
|
|
|
840
880
|
class Ticket(_Base):
|
|
@@ -857,9 +897,9 @@ class ProductListResponse(_Base):
|
|
|
857
897
|
class ProductBatchResponse(_Base):
|
|
858
898
|
"""Per-id outcome; 200 even when some ids were missing."""
|
|
859
899
|
|
|
860
|
-
affected: list[str]
|
|
861
|
-
not_found: list[str]
|
|
862
|
-
forbidden: list[str]
|
|
900
|
+
affected: list[str]
|
|
901
|
+
not_found: list[str]
|
|
902
|
+
forbidden: list[str]
|
|
863
903
|
|
|
864
904
|
|
|
865
905
|
class ProductReviewResponse(_Base):
|
|
@@ -882,9 +922,7 @@ class ProductExportQueued(_Base):
|
|
|
882
922
|
|
|
883
923
|
class ApiKey(_Base):
|
|
884
924
|
id: str
|
|
885
|
-
#
|
|
886
|
-
org_id: str | None = None
|
|
887
|
-
project_id: str | None = None
|
|
925
|
+
org_id: str | None = None # a key binds to its org
|
|
888
926
|
key_type: KeyType
|
|
889
927
|
key_prefix: str
|
|
890
928
|
name: str | None = None
|
|
@@ -937,15 +975,15 @@ class UsageProductTotals(_Base):
|
|
|
937
975
|
|
|
938
976
|
product_id: str
|
|
939
977
|
title: str | None = None
|
|
940
|
-
totals: dict[str, int]
|
|
978
|
+
totals: dict[str, int]
|
|
941
979
|
|
|
942
980
|
|
|
943
981
|
class UsageResponse(_Base):
|
|
944
982
|
start: datetime
|
|
945
983
|
end: datetime
|
|
946
984
|
granularity: Literal["hour", "day"]
|
|
947
|
-
buckets: list[UsageBucket]
|
|
948
|
-
totals: dict[str, int]
|
|
985
|
+
buckets: list[UsageBucket]
|
|
986
|
+
totals: dict[str, int]
|
|
949
987
|
#: event_type -> duration aggregate over the whole window. Only ever keyed by
|
|
950
988
|
#: ``ar_session_ended``; the key is absent when nothing in the window carried one.
|
|
951
989
|
durations: dict[str, UsageDuration] = Field(default_factory=dict)
|
|
@@ -965,9 +1003,7 @@ class TagsResponse(_Base):
|
|
|
965
1003
|
|
|
966
1004
|
class WebhookEndpoint(_Base):
|
|
967
1005
|
id: str
|
|
968
|
-
#
|
|
969
|
-
org_id: str | None = None
|
|
970
|
-
project_id: str | None = None
|
|
1006
|
+
org_id: str | None = None # an endpoint binds to its org
|
|
971
1007
|
url: str
|
|
972
1008
|
description: str | None = None
|
|
973
1009
|
events: list[WebhookEventType]
|
|
@@ -996,6 +1032,8 @@ class WebhookDelivery(_Base):
|
|
|
996
1032
|
succeeded_at: datetime | None = None
|
|
997
1033
|
last_attempt_at: datetime | None = None
|
|
998
1034
|
last_error: str | None = None
|
|
1035
|
+
# When the next retry is due; None once it succeeded or its six attempts ran out.
|
|
1036
|
+
next_attempt_at: datetime | None = None
|
|
999
1037
|
payload_json: dict[str, Any] | None = None
|
|
1000
1038
|
|
|
1001
1039
|
|
|
@@ -1005,19 +1043,6 @@ class WebhookDeliveryListResponse(_Base):
|
|
|
1005
1043
|
offset: int
|
|
1006
1044
|
|
|
1007
1045
|
|
|
1008
|
-
class Project(_Base):
|
|
1009
|
-
id: str
|
|
1010
|
-
org_id: str
|
|
1011
|
-
name: str
|
|
1012
|
-
allowed_domains: list[str] = Field(default_factory=list)
|
|
1013
|
-
always_generate: bool = False
|
|
1014
|
-
created_at: datetime
|
|
1015
|
-
|
|
1016
|
-
|
|
1017
|
-
class ProjectListResponse(_Base):
|
|
1018
|
-
data: list[Project]
|
|
1019
|
-
|
|
1020
|
-
|
|
1021
1046
|
class HealthResponse(_Base):
|
|
1022
1047
|
status: str = "ok"
|
|
1023
1048
|
version: str | None = None
|
|
@@ -41,6 +41,8 @@ from viewrium import (
|
|
|
41
41
|
TicketKind,
|
|
42
42
|
TicketRequest,
|
|
43
43
|
UnprocessableEntityError,
|
|
44
|
+
ViewerDesktopMode,
|
|
45
|
+
ViewerMobileMode,
|
|
44
46
|
Viewrium,
|
|
45
47
|
ViewriumError,
|
|
46
48
|
WidthAxis,
|
|
@@ -271,6 +273,25 @@ def test_the_public_projection_carries_a_paintings_settings() -> None:
|
|
|
271
273
|
assert product.painting is not None
|
|
272
274
|
assert product.painting.depth_cm == 2.0
|
|
273
275
|
assert product.painting.rebuild is None
|
|
276
|
+
# Absent from an older API's response: the default the embed always had.
|
|
277
|
+
assert product.viewer_desktop is ViewerDesktopMode.VIEWER
|
|
278
|
+
assert product.viewer_mobile is ViewerMobileMode.VIEWER
|
|
279
|
+
|
|
280
|
+
|
|
281
|
+
def test_update_sends_the_embed_display_modes_and_reads_them_back() -> None:
|
|
282
|
+
body = {**PRODUCT_JSON, "viewer_desktop": "qr", "viewer_mobile": "button"}
|
|
283
|
+
client, rec = make_client(httpx.Response(200, json=body))
|
|
284
|
+
product = client.products.update(
|
|
285
|
+
"p1",
|
|
286
|
+
ProductUpdateRequest(
|
|
287
|
+
viewer_desktop=ViewerDesktopMode.QR, viewer_mobile=ViewerMobileMode.BUTTON
|
|
288
|
+
),
|
|
289
|
+
)
|
|
290
|
+
|
|
291
|
+
assert rec.request is not None
|
|
292
|
+
assert json.loads(rec.request.content) == {"viewer_desktop": "qr", "viewer_mobile": "button"}
|
|
293
|
+
assert product.viewer_desktop is ViewerDesktopMode.QR
|
|
294
|
+
assert product.viewer_mobile is ViewerMobileMode.BUTTON
|
|
274
295
|
|
|
275
296
|
|
|
276
297
|
def test_rescale_posts_to_the_products_own_model_and_parses_the_achieved_size() -> None:
|
|
@@ -396,6 +417,32 @@ def test_products_export_answers_a_queued_export() -> None:
|
|
|
396
417
|
assert result.to_finish == 15 and result.notify_email == "a@example.com"
|
|
397
418
|
|
|
398
419
|
|
|
420
|
+
def test_products_qr_returns_the_png_bytes() -> None:
|
|
421
|
+
client, rec = make_client(
|
|
422
|
+
httpx.Response(200, content=b"\x89PNG\r\n", headers={"content-type": "image/png"})
|
|
423
|
+
)
|
|
424
|
+
png = client.products.qr("p1", guide=True, size=512)
|
|
425
|
+
|
|
426
|
+
assert png == b"\x89PNG\r\n"
|
|
427
|
+
assert rec.request is not None
|
|
428
|
+
assert rec.request.url.path == "/v1/products/p1/qr"
|
|
429
|
+
assert rec.request.url.params["guide"] == "true"
|
|
430
|
+
assert rec.request.url.params["size"] == "512"
|
|
431
|
+
|
|
432
|
+
|
|
433
|
+
def test_products_qr_defaults_to_the_minimal_1024_square() -> None:
|
|
434
|
+
client, rec = make_client(httpx.Response(200, content=b"\x89PNG"))
|
|
435
|
+
client.products.qr("p1")
|
|
436
|
+
|
|
437
|
+
assert rec.request is not None
|
|
438
|
+
assert rec.request.url.params["guide"] == "false"
|
|
439
|
+
assert rec.request.url.params["size"] == "1024"
|
|
440
|
+
|
|
441
|
+
|
|
442
|
+
def test_product_carries_its_viewer_url() -> None:
|
|
443
|
+
assert Product.model_fields["viewer_url"].default is None
|
|
444
|
+
|
|
445
|
+
|
|
399
446
|
def test_usage_group_by_product_ranks_and_names_them() -> None:
|
|
400
447
|
body = {
|
|
401
448
|
"start": "2026-09-01T00:00:00Z",
|
|
@@ -432,6 +479,19 @@ def test_tags_reads_the_catalogs_own_tag_route() -> None:
|
|
|
432
479
|
assert rec.request.url.params.get("scope") == "all"
|
|
433
480
|
|
|
434
481
|
|
|
482
|
+
def test_retrieve_by_custom_id_sends_the_custom_id_as_a_query_param() -> None:
|
|
483
|
+
client, rec = make_client(httpx.Response(200, json=PRODUCT_JSON))
|
|
484
|
+
product = client.products.retrieve_by_custom_id("SKU/12 a&b")
|
|
485
|
+
|
|
486
|
+
assert product.id == PRODUCT_JSON["id"]
|
|
487
|
+
|
|
488
|
+
assert rec.request is not None
|
|
489
|
+
assert rec.request.method == "GET"
|
|
490
|
+
assert rec.request.url.path == "/v1/products/lookup"
|
|
491
|
+
assert rec.request.url.params.get("custom_id") == "SKU/12 a&b"
|
|
492
|
+
assert "org_id" not in rec.request.url.params
|
|
493
|
+
|
|
494
|
+
|
|
435
495
|
def test_beacon_send_uses_pk_key() -> None:
|
|
436
496
|
client, rec = make_client(httpx.Response(204), api_key="pk_live_1")
|
|
437
497
|
client.beacon.send(BeaconRequest(model_id="p1", event_type=BeaconEventType.VIEW))
|
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
"""Drift guard: the hand-written models in `viewrium._models` against the API's public OpenAPI
|
|
2
|
+
schema (`apps/api/openapi.json`, the file the JS SDK is generated from).
|
|
3
|
+
|
|
4
|
+
Every public component schema must have a Python counterpart with the same field names and the
|
|
5
|
+
same requiredness (an object), or the same values (an enum). Names differ where the SDK chose a
|
|
6
|
+
friendlier class name (`SCHEMA_TO_MODEL`); anything the SDK deliberately does differently is in
|
|
7
|
+
an allow-list below, each entry with its reason. A new API field fails this test until the SDK
|
|
8
|
+
mirrors it or the difference is allow-listed on purpose.
|
|
9
|
+
|
|
10
|
+
It runs as part of `test` and again as the package's `check` task, which CI runs on every PR
|
|
11
|
+
(unlike `test`, which CI runs only for affected packages).
|
|
12
|
+
"""
|
|
13
|
+
|
|
14
|
+
from __future__ import annotations
|
|
15
|
+
|
|
16
|
+
import json
|
|
17
|
+
from enum import StrEnum
|
|
18
|
+
from pathlib import Path
|
|
19
|
+
from typing import Any
|
|
20
|
+
|
|
21
|
+
import pytest
|
|
22
|
+
from pydantic import BaseModel
|
|
23
|
+
|
|
24
|
+
import viewrium
|
|
25
|
+
from viewrium import _models
|
|
26
|
+
|
|
27
|
+
OPENAPI_PATH = Path(__file__).resolve().parents[3] / "apps" / "api" / "openapi.json"
|
|
28
|
+
|
|
29
|
+
# OpenAPI component name -> `viewrium._models` class name, where they differ.
|
|
30
|
+
SCHEMA_TO_MODEL: dict[str, str] = {
|
|
31
|
+
"ApiKeyResponse": "ApiKey",
|
|
32
|
+
"ModelPlanResponse": "ModelPlan",
|
|
33
|
+
"ProductExportQueuedResponse": "ProductExportQueued",
|
|
34
|
+
"ProductImageResponse": "ProductImage",
|
|
35
|
+
"ProductModelResponse": "ProductModel",
|
|
36
|
+
"ProductOrderParkedResponse": "ProductOrderParked",
|
|
37
|
+
"ProductParkedResponse": "ProductParked",
|
|
38
|
+
"ProductResponse": "Product",
|
|
39
|
+
"ProductSourceResponse": "ProductSource",
|
|
40
|
+
"PublicProductResponse": "PublicProduct",
|
|
41
|
+
"TicketResponse": "Ticket",
|
|
42
|
+
"WebhookDeliveryResponse": "WebhookDelivery",
|
|
43
|
+
"WebhookEndpointResponse": "WebhookEndpoint",
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
# Component schemas with no Python model, on purpose.
|
|
47
|
+
UNMODELLED: dict[str, str] = {
|
|
48
|
+
"ErrorEnvelope": "parsed into the ViewriumError hierarchy (_errors.py), not a model",
|
|
49
|
+
"ErrorDetail": "parsed into the ViewriumError hierarchy (_errors.py), not a model",
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
# (component, field) pairs whose requiredness differs on purpose.
|
|
53
|
+
REQUIREDNESS_EXCEPTIONS: dict[tuple[str, str], str] = {}
|
|
54
|
+
|
|
55
|
+
# (component, field) pairs present on one side only, on purpose.
|
|
56
|
+
FIELD_EXCEPTIONS: dict[tuple[str, str], str] = {}
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
def _schemas() -> dict[str, dict[str, Any]]:
|
|
60
|
+
document = json.loads(OPENAPI_PATH.read_text(encoding="utf-8"))
|
|
61
|
+
schemas: dict[str, dict[str, Any]] = document["components"]["schemas"]
|
|
62
|
+
return schemas
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
SCHEMAS = _schemas()
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
def _model_for(name: str) -> type[Any] | None:
|
|
69
|
+
found = getattr(_models, SCHEMA_TO_MODEL.get(name, name), None)
|
|
70
|
+
return found if isinstance(found, type) else None
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
@pytest.mark.parametrize("name", sorted(SCHEMAS))
|
|
74
|
+
def test_every_public_schema_has_a_python_counterpart(name: str) -> None:
|
|
75
|
+
if name in UNMODELLED:
|
|
76
|
+
return
|
|
77
|
+
model = _model_for(name)
|
|
78
|
+
assert model is not None, (
|
|
79
|
+
f"OpenAPI schema {name!r} has no model in viewrium._models "
|
|
80
|
+
f"(add one, map it in SCHEMA_TO_MODEL, or allow-list it in UNMODELLED with a reason)"
|
|
81
|
+
)
|
|
82
|
+
# The docs' object pages name every model as `viewrium.<Name>`.
|
|
83
|
+
assert getattr(viewrium, model.__name__, None) is model, (
|
|
84
|
+
f"{model.__name__} is not exported from the viewrium package"
|
|
85
|
+
)
|
|
86
|
+
|
|
87
|
+
|
|
88
|
+
@pytest.mark.parametrize("name", sorted(n for n, s in SCHEMAS.items() if "enum" in s))
|
|
89
|
+
def test_enum_values_match(name: str) -> None:
|
|
90
|
+
model = _model_for(name)
|
|
91
|
+
if model is None:
|
|
92
|
+
pytest.skip("reported by test_every_public_schema_has_a_python_counterpart")
|
|
93
|
+
assert issubclass(model, StrEnum), f"{name}: expected a StrEnum, got {model!r}"
|
|
94
|
+
assert {m.value for m in model} == set(SCHEMAS[name]["enum"]), f"{name}: enum values differ"
|
|
95
|
+
|
|
96
|
+
|
|
97
|
+
@pytest.mark.parametrize("name", sorted(n for n, s in SCHEMAS.items() if "properties" in s))
|
|
98
|
+
def test_object_fields_and_requiredness_match(name: str) -> None:
|
|
99
|
+
if name in UNMODELLED:
|
|
100
|
+
return
|
|
101
|
+
model = _model_for(name)
|
|
102
|
+
if model is None:
|
|
103
|
+
pytest.skip("reported by test_every_public_schema_has_a_python_counterpart")
|
|
104
|
+
assert issubclass(model, BaseModel), f"{name}: expected a pydantic model, got {model!r}"
|
|
105
|
+
schema = SCHEMAS[name]
|
|
106
|
+
api_fields = set(schema["properties"])
|
|
107
|
+
py_fields = set(model.model_fields)
|
|
108
|
+
one_sided = {f for f in api_fields ^ py_fields if (name, f) not in FIELD_EXCEPTIONS}
|
|
109
|
+
assert not one_sided, (
|
|
110
|
+
f"{name} vs {model.__name__}: only in the API {sorted(api_fields - py_fields)}, "
|
|
111
|
+
f"only in the SDK {sorted(py_fields - api_fields)}"
|
|
112
|
+
)
|
|
113
|
+
api_required = set(schema.get("required", []))
|
|
114
|
+
mismatched = sorted(
|
|
115
|
+
f
|
|
116
|
+
for f in api_fields & py_fields
|
|
117
|
+
if (f in api_required) != model.model_fields[f].is_required()
|
|
118
|
+
and (name, f) not in REQUIREDNESS_EXCEPTIONS
|
|
119
|
+
)
|
|
120
|
+
assert not mismatched, (
|
|
121
|
+
f"{name} vs {model.__name__}: requiredness differs for {mismatched} "
|
|
122
|
+
f"(API required: {sorted(api_required & set(mismatched))})"
|
|
123
|
+
)
|
|
124
|
+
|
|
125
|
+
|
|
126
|
+
def test_allow_lists_name_real_entries() -> None:
|
|
127
|
+
"""A stale allow-list entry hides nothing and would let the next real drift through."""
|
|
128
|
+
for name in UNMODELLED:
|
|
129
|
+
assert name in SCHEMAS, f"UNMODELLED names {name!r}, which the schema no longer has"
|
|
130
|
+
for name in SCHEMA_TO_MODEL:
|
|
131
|
+
assert name in SCHEMAS, f"SCHEMA_TO_MODEL maps {name!r}, which the schema no longer has"
|
|
132
|
+
for name, field in REQUIREDNESS_EXCEPTIONS:
|
|
133
|
+
assert field in SCHEMAS.get(name, {}).get("properties", {}), (
|
|
134
|
+
f"REQUIREDNESS_EXCEPTIONS names {name}.{field}, which the schema no longer has"
|
|
135
|
+
)
|
|
136
|
+
for name, _field in FIELD_EXCEPTIONS:
|
|
137
|
+
assert name in SCHEMAS, f"FIELD_EXCEPTIONS names {name!r}, which the schema no longer has"
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "https://turborepo.dev/schema.json",
|
|
3
|
+
"extends": ["//"],
|
|
4
|
+
"tags": ["package"],
|
|
5
|
+
"tasks": {
|
|
6
|
+
"build": {
|
|
7
|
+
"outputs": []
|
|
8
|
+
},
|
|
9
|
+
"test": {
|
|
10
|
+
"inputs": ["$TURBO_DEFAULT$", "$TURBO_ROOT$/apps/api/openapi.json"]
|
|
11
|
+
},
|
|
12
|
+
"check": {
|
|
13
|
+
"inputs": ["$TURBO_DEFAULT$", "$TURBO_ROOT$/apps/api/openapi.json"]
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
}
|
viewrium-2.2.0/turbo.json
DELETED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|