@thorprovider/types 5.7.9 → 5.7.10
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/AGENTS.md +1 -1
- package/README.md +0 -8
- package/dist/index.d.mts +144 -373
- package/dist/index.d.ts +144 -373
- package/dist/index.js +138 -0
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +125 -0
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -2
- package/src/admin/DropshippingAdmin.ts +57 -0
- package/src/cart.ts +0 -40
- package/src/collection.ts +0 -10
- package/src/commerce-provider.ts +0 -36
- package/src/index.ts +18 -30
- package/src/provider.ts +178 -14
- package/src/storefront.ts +32 -5
- package/.turbo/turbo-build.log +0 -18
- package/.turbo/turbo-type-check.log +0 -0
- package/dist/.tsbuildinfo +0 -1
- package/publish.log +0 -60
- package/src/catalog.ts +0 -210
- package/src/commerce.ts +0 -88
package/src/catalog.ts
DELETED
|
@@ -1,210 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @thorprovider/types — Canonical catalog query, truthful results, and facet support.
|
|
3
|
-
*
|
|
4
|
-
* Type-only module: no runtime code, constants, or schemas. These types are shared by
|
|
5
|
-
* the URL boundary, the runtime commerce bridge, and the adapters so every product
|
|
6
|
-
* listing asks the backend one well-formed question and reports truthfully what was
|
|
7
|
-
* applied. Validation (Zod) lives in `@thorprovider/runtime/contracts`; translation to
|
|
8
|
-
* backend parameters lives in the adapters.
|
|
9
|
-
*
|
|
10
|
-
* E2 `storefront-catalog-search-filters`. The canonical URL parameter contract is:
|
|
11
|
-
* `q` (text), the route category scope plus `categories`/`collections`, `sort`
|
|
12
|
-
* (`featured` | `name` | `newest`), `page`/`pageSize`, and the optional requested
|
|
13
|
-
* facets `priceMin`/`priceMax`/`inStock`/`attr.<name>`.
|
|
14
|
-
*/
|
|
15
|
-
|
|
16
|
-
import type { Product } from './product';
|
|
17
|
-
|
|
18
|
-
/**
|
|
19
|
-
* Canonical, backend-verified sort keys.
|
|
20
|
-
*
|
|
21
|
-
* Only these three are verified against Medusa v2: `featured` (server default),
|
|
22
|
-
* `name` (translated to `title`), and `newest` (translated to `-created_at`). Global
|
|
23
|
-
* price ordering and rating are not verified and are rejected by the boundary as a
|
|
24
|
-
* typed unsupported-query error. An adapter advertises the subset it can actually
|
|
25
|
-
* apply; the listing never offers a sort the backend cannot perform.
|
|
26
|
-
*/
|
|
27
|
-
export type CatalogSortKey = 'featured' | 'name' | 'newest';
|
|
28
|
-
|
|
29
|
-
/**
|
|
30
|
-
* Canonical catalog query crossing the URL boundary, the runtime bridge, and the
|
|
31
|
-
* adapters.
|
|
32
|
-
*
|
|
33
|
-
* Fields mirror the fixed, lowercase URL namespace. They are optional because
|
|
34
|
-
* documented defaults (`sort` = `featured`, `page` = `1`, `pageSize` = the chosen
|
|
35
|
-
* target default) are resolved by the URL boundary and apply only to absent
|
|
36
|
-
* parameters, never to invalid present values.
|
|
37
|
-
*/
|
|
38
|
-
export interface CatalogQuery {
|
|
39
|
-
/** Free-text term (`q`). Trimmed, bounded, and empty treated as absent. */
|
|
40
|
-
text?: string;
|
|
41
|
-
/**
|
|
42
|
-
* Category scope supplied by the route path (`/categorias/[[...slug]]`). The route
|
|
43
|
-
* scope is always retained, even when both optional features are removed.
|
|
44
|
-
*/
|
|
45
|
-
categoryScope?: string;
|
|
46
|
-
/**
|
|
47
|
-
* Category handles requested by the `category-filters` feature. The effective
|
|
48
|
-
* scope is `categoryScope ∩ categories`; an empty intersection is a valid
|
|
49
|
-
* zero-result query, never an invalid-query error.
|
|
50
|
-
*/
|
|
51
|
-
categories?: string[];
|
|
52
|
-
/** Collection handles requested by the `category-filters` feature. */
|
|
53
|
-
collections?: string[];
|
|
54
|
-
/** Canonical sort key; defaults are resolved at the URL boundary, not here. */
|
|
55
|
-
sort?: CatalogSortKey;
|
|
56
|
-
/** 1-based page; bounds are enforced at the URL boundary. */
|
|
57
|
-
page?: number;
|
|
58
|
-
/** Page size; bounds are enforced at the URL boundary. */
|
|
59
|
-
pageSize?: number;
|
|
60
|
-
/** Minimum price in major units; honored only when the price facet is demonstrated. */
|
|
61
|
-
priceMin?: number;
|
|
62
|
-
/** Maximum price in major units; honored only when the price facet is demonstrated. */
|
|
63
|
-
priceMax?: number;
|
|
64
|
-
/** In-stock only; honored only when demonstrated, otherwise a typed unsupported error. */
|
|
65
|
-
inStock?: boolean;
|
|
66
|
-
/** Requested attribute filters keyed by attribute name (`attr.<name>`). */
|
|
67
|
-
attributes?: Record<string, string[]>;
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
/**
|
|
71
|
-
* Filters the backend actually applied to a successful result.
|
|
72
|
-
*
|
|
73
|
-
* A result is reported as success only when every requested filter appears here.
|
|
74
|
-
*/
|
|
75
|
-
export interface CatalogAppliedFilters {
|
|
76
|
-
/** Text term applied within the current scope. */
|
|
77
|
-
text?: string;
|
|
78
|
-
/** Category handles applied (the effective intersected scope). */
|
|
79
|
-
categories?: string[];
|
|
80
|
-
/** Collection handles applied. */
|
|
81
|
-
collections?: string[];
|
|
82
|
-
/** Minimum price applied. */
|
|
83
|
-
priceMin?: number;
|
|
84
|
-
/** Maximum price applied. */
|
|
85
|
-
priceMax?: number;
|
|
86
|
-
/** In-stock constraint applied. */
|
|
87
|
-
inStock?: boolean;
|
|
88
|
-
/** Attribute filters applied, keyed by attribute name. */
|
|
89
|
-
attributes?: Record<string, string[]>;
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
/**
|
|
93
|
-
* Canonical filter identifiers used by the support descriptor.
|
|
94
|
-
*
|
|
95
|
-
* `attr.<name>` covers backend-advertised filterable attributes.
|
|
96
|
-
*/
|
|
97
|
-
export type CatalogFacetId =
|
|
98
|
-
| 'categories'
|
|
99
|
-
| 'collections'
|
|
100
|
-
| 'price'
|
|
101
|
-
| 'inStock'
|
|
102
|
-
| `attr.${string}`;
|
|
103
|
-
|
|
104
|
-
/**
|
|
105
|
-
* Real-endpoint demonstration source for an offered facet.
|
|
106
|
-
*
|
|
107
|
-
* Records the actual backend endpoint demonstrated with the applied query for the
|
|
108
|
-
* current scope, not a capability flag or returned facet metadata.
|
|
109
|
-
*/
|
|
110
|
-
export interface CatalogFacetDemonstrationSource {
|
|
111
|
-
/** Real backend endpoint demonstrated with the applied query (e.g. `/store/products`). */
|
|
112
|
-
endpoint: string;
|
|
113
|
-
/** The query and scope the endpoint was demonstrated with. */
|
|
114
|
-
appliedQuery?: CatalogQuery;
|
|
115
|
-
/** Store/scope the demonstration applies to. */
|
|
116
|
-
scope?: string;
|
|
117
|
-
/** ISO-8601 timestamp of when support was demonstrated. */
|
|
118
|
-
demonstratedAt?: string;
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
/**
|
|
122
|
-
* Truthful facet support descriptor: which filters the backend has demonstrated
|
|
123
|
-
* (offered) versus which are undemonstrated and held, plus the demonstration source
|
|
124
|
-
* for each offered filter.
|
|
125
|
-
*
|
|
126
|
-
* Contains no counts or ranges. Facet option counts and numeric ranges come only from
|
|
127
|
-
* backend data returned for the current query and are never synthesized here.
|
|
128
|
-
*/
|
|
129
|
-
export interface FacetSupport {
|
|
130
|
-
/** Filters demonstrated against the real endpoint for the current scope. */
|
|
131
|
-
offered: CatalogFacetId[];
|
|
132
|
-
/** Filters not demonstrated; held and diagnosed, never silently offered. */
|
|
133
|
-
held: CatalogFacetId[];
|
|
134
|
-
/** Real-endpoint demonstration source per offered filter, keyed by filter id. */
|
|
135
|
-
demonstrations?: Record<string, CatalogFacetDemonstrationSource>;
|
|
136
|
-
/** Diagnostic reason per held filter, keyed by filter id. */
|
|
137
|
-
heldReasons?: Record<string, string>;
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
/**
|
|
141
|
-
* Truthful catalog result for a fully applied query.
|
|
142
|
-
*
|
|
143
|
-
* When any requested filter cannot be applied, the query MUST return a typed
|
|
144
|
-
* unsupported-query error (defined in `@thorprovider/runtime/contracts`) instead of
|
|
145
|
-
* this shape; a partial result is never labelled success. `total` is present only
|
|
146
|
-
* when the backend supplies it and is never manufactured.
|
|
147
|
-
*/
|
|
148
|
-
export interface CatalogResults {
|
|
149
|
-
/** Matching products for the requested scope, sort, and page. */
|
|
150
|
-
products: Product[];
|
|
151
|
-
/** Total matches supplied by the backend; absent when the backend returns none. */
|
|
152
|
-
total?: number;
|
|
153
|
-
/** Filters the backend actually applied. */
|
|
154
|
-
appliedFilters: CatalogAppliedFilters;
|
|
155
|
-
/** Facet support descriptor for the query and scope. */
|
|
156
|
-
facetSupport?: FacetSupport;
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
/**
|
|
160
|
-
* Adapter-seam typed failure code for a canonical catalog query.
|
|
161
|
-
*
|
|
162
|
-
* `unsupported-query` is the code an adapter returns when a requested filter
|
|
163
|
-
* cannot be applied to the backend. `invalid-query` and `unmounted-capability`
|
|
164
|
-
* are produced by the URL boundary (`@thorprovider/runtime/contracts`); the
|
|
165
|
-
* adapter seam mirrors them so the runtime bridge can surface either shape
|
|
166
|
-
* without a translation layer.
|
|
167
|
-
*/
|
|
168
|
-
export type CatalogQueryFailureCode =
|
|
169
|
-
| 'invalid-query'
|
|
170
|
-
| 'unsupported-query'
|
|
171
|
-
| 'unmounted-capability';
|
|
172
|
-
|
|
173
|
-
/**
|
|
174
|
-
* Compact, structured repair metadata: the raw parameter names a host must drop
|
|
175
|
-
* to reach a valid query. Structurally identical to the URL boundary's repair.
|
|
176
|
-
*/
|
|
177
|
-
export interface CatalogQueryFailureRepair {
|
|
178
|
-
/** Raw URL parameter names to remove (exactly the offending fields). */
|
|
179
|
-
remove: string[];
|
|
180
|
-
}
|
|
181
|
-
|
|
182
|
-
/**
|
|
183
|
-
* Typed catalog-query failure returned across the adapter seam.
|
|
184
|
-
*
|
|
185
|
-
* Structurally identical to `CatalogQueryError` in
|
|
186
|
-
* `@thorprovider/runtime/contracts`, so the two are mutually assignable and the
|
|
187
|
-
* runtime bridge can pass one through as the other. `fields` names the
|
|
188
|
-
* offending raw parameters; `feature` is present only for
|
|
189
|
-
* `unmounted-capability`.
|
|
190
|
-
*/
|
|
191
|
-
export interface CatalogQueryFailure {
|
|
192
|
-
code: CatalogQueryFailureCode;
|
|
193
|
-
fields: string[];
|
|
194
|
-
message: string;
|
|
195
|
-
repair: CatalogQueryFailureRepair;
|
|
196
|
-
feature?: 'catalog-search' | 'category-filters';
|
|
197
|
-
}
|
|
198
|
-
|
|
199
|
-
/**
|
|
200
|
-
* Discriminated outcome of a canonical catalog query against a provider.
|
|
201
|
-
*
|
|
202
|
-
* A provider returns `{ ok: true, results }` **only** when every requested
|
|
203
|
-
* filter was applied. When any requested filter cannot be applied it returns
|
|
204
|
-
* `{ ok: false, error }` with `code: 'unsupported-query'` naming the
|
|
205
|
-
* unappliable fields; a partial result is never returned as success and a
|
|
206
|
-
* requested filter is never silently dropped.
|
|
207
|
-
*/
|
|
208
|
-
export type CatalogQueryOutcome =
|
|
209
|
-
| { ok: true; results: CatalogResults }
|
|
210
|
-
| { ok: false; error: CatalogQueryFailure };
|
package/src/commerce.ts
DELETED
|
@@ -1,88 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @thorprovider/types — Commerce contracts (type-only)
|
|
3
|
-
*
|
|
4
|
-
* Single-tenant, guest-only commerce shapes owned once by this module.
|
|
5
|
-
* Validation lives in `@thorprovider/runtime/contracts` (pure Zod); this
|
|
6
|
-
* module exports types only and emits no runtime values.
|
|
7
|
-
*
|
|
8
|
-
* Canonical product/variant/Money/cart/order shapes are NOT redefined here —
|
|
9
|
-
* they stay owned by `./common`, `./product`, `./cart` and `./order`.
|
|
10
|
-
*
|
|
11
|
-
* @module commerce
|
|
12
|
-
*/
|
|
13
|
-
|
|
14
|
-
import type { Money } from './common';
|
|
15
|
-
|
|
16
|
-
/**
|
|
17
|
-
* The validated single-store context — the multitenancy seam.
|
|
18
|
-
*
|
|
19
|
-
* Declares store identity, sales channel, region, and currency once and is
|
|
20
|
-
* validated at the boundary before any commerce call. Multitenancy is
|
|
21
|
-
* post-MVP; a future tenancy layer varies these values without redefining
|
|
22
|
-
* the commerce shapes.
|
|
23
|
-
*/
|
|
24
|
-
export interface StoreContext {
|
|
25
|
-
/** Stable store identity. */
|
|
26
|
-
storeId: string;
|
|
27
|
-
|
|
28
|
-
/** Sales channel the store is scoped to (Medusa `sales_channel_id`). */
|
|
29
|
-
salesChannelId: string;
|
|
30
|
-
|
|
31
|
-
/** Backend region that supplies currency, countries and shipping. */
|
|
32
|
-
regionId: string;
|
|
33
|
-
|
|
34
|
-
/** ISO 4217 currency code from the validated context — never hardcoded. */
|
|
35
|
-
currencyCode: string;
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
/**
|
|
39
|
-
* Issued guest shopper identity, scoped to a store.
|
|
40
|
-
*
|
|
41
|
-
* Backed by a cookie the Next host owns; it maps to a persisted backend guest
|
|
42
|
-
* cart so a reload reattaches to the same cart and two shoppers stay isolated.
|
|
43
|
-
*/
|
|
44
|
-
export interface ShopperIdentity {
|
|
45
|
-
/** Opaque shopper identity issued by the host cookie. */
|
|
46
|
-
shopperId: string;
|
|
47
|
-
|
|
48
|
-
/** Store the identity is scoped to. */
|
|
49
|
-
storeId: string;
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
/**
|
|
53
|
-
* A persisted backend guest cart session bound to a shopper identity.
|
|
54
|
-
*/
|
|
55
|
-
export interface CartSession {
|
|
56
|
-
/** Backend cart identifier. */
|
|
57
|
-
cartId: string;
|
|
58
|
-
|
|
59
|
-
/** Owning shopper identity. */
|
|
60
|
-
shopperId: string;
|
|
61
|
-
|
|
62
|
-
/** Store the session is scoped to. */
|
|
63
|
-
storeId: string;
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
/**
|
|
67
|
-
* Safe, buyer/store-authorized order receipt projection.
|
|
68
|
-
*
|
|
69
|
-
* A minimal recoverable subset of the canonical `Order` (`./order`), used by
|
|
70
|
-
* the guest receipt protocol. Access is authorized for the buyer or the
|
|
71
|
-
* store; it is never granted by possession of a bare public order id.
|
|
72
|
-
*/
|
|
73
|
-
export interface OrderReceipt {
|
|
74
|
-
/** Backend order identifier. */
|
|
75
|
-
orderId: string;
|
|
76
|
-
|
|
77
|
-
/** Human-readable order number. */
|
|
78
|
-
orderNumber: string;
|
|
79
|
-
|
|
80
|
-
/** Buyer email the order was placed with. */
|
|
81
|
-
email: string;
|
|
82
|
-
|
|
83
|
-
/** Order total in major units. */
|
|
84
|
-
total: Money;
|
|
85
|
-
|
|
86
|
-
/** ISO 8601 creation timestamp. */
|
|
87
|
-
createdAt: string;
|
|
88
|
-
}
|