@sonic-commerce/storefront-types 0.11.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 ADDED
@@ -0,0 +1,84 @@
1
+ # @sonic-commerce/storefront-types
2
+
3
+ TypeScript types for the Sonic Commerce storefront API (`/api/v1`).
4
+
5
+ Types only — no runtime code, nothing to import at run time, nothing added to
6
+ your bundle. Generated from the API's OpenAPI document, which is itself
7
+ generated from the Zod schemas that serialize every response, so these types
8
+ describe what the server actually sends.
9
+
10
+ ## Install
11
+
12
+ ```bash
13
+ npm i -D @sonic-commerce/storefront-types
14
+ npm i openapi-fetch
15
+ ```
16
+
17
+ [`openapi-fetch`](https://openapi-ts.dev/openapi-fetch/) (~6 kB) turns the
18
+ `paths` type into a checked client. It is optional — the named types work with
19
+ `fetch`, axios, or anything else.
20
+
21
+ ## Use
22
+
23
+ ```ts
24
+ import createClient from "openapi-fetch";
25
+ import type { paths, Product } from "@sonic-commerce/storefront-types";
26
+
27
+ const api = createClient<paths>({
28
+ baseUrl: "https://acme.example.com/api/v1",
29
+ headers: { "x-publishable-key": process.env.PUBLISHABLE_KEY! },
30
+ });
31
+
32
+ // Path, query params and response are all typed and checked.
33
+ const { data, error } = await api.GET("/products", {
34
+ params: { query: { limit: 20, sort: "-created_at" } },
35
+ });
36
+
37
+ const products: Product[] | undefined = data?.data;
38
+ ```
39
+
40
+ Every named schema in the spec is exported as a type alias — `Product`, `Cart`,
41
+ `Order`, `Store`, `Category`, `Collection`, `AuthSession`, the request bodies,
42
+ and so on — alongside the raw `paths`, `components` and `operations` that
43
+ `openapi-typescript` emits.
44
+
45
+ ```ts
46
+ import type { Cart, CartTotals, AddCartItemBody } from "@sonic-commerce/storefront-types";
47
+ ```
48
+
49
+ ### One openapi-fetch quirk
50
+
51
+ `openapi-fetch` (0.17.0, checked) drops properties typed as exactly `null` from
52
+ the response types it infers. Two fields are affected: `shipping_total` on
53
+ `CartTotals` and on `OrderTotals`, both deliberately `null` because shipping is
54
+ not modelled — an absent charge, not a zero one.
55
+
56
+ They are still there at run time. If you need them in the type, annotate with
57
+ the named schema rather than the inferred response:
58
+
59
+ ```ts
60
+ import type { Cart } from "@sonic-commerce/storefront-types";
61
+
62
+ const { data } = await api.GET("/carts/{id}", { params: { path: { id } } });
63
+ const cart = data?.data as Cart | undefined; // shipping_total present
64
+ ```
65
+
66
+ ## Versioning
67
+
68
+ The package version tracks the API version: `0.10.1` describes the `/api/v1`
69
+ surface as of release 0.10.1.
70
+
71
+ While the API is pre-1.0, **breaking changes ship in a minor bump** (0.10 →
72
+ 0.11), per the project's versioning policy. Pin accordingly:
73
+
74
+ ```jsonc
75
+ { "devDependencies": { "@sonic-commerce/storefront-types": "~0.10.1" } }
76
+ ```
77
+
78
+ `~` accepts patches and stays off the next minor. Switch to `^` once the API
79
+ reaches 1.0.
80
+
81
+ ## Other languages
82
+
83
+ The OpenAPI 3.1 document these types are generated from is served live at
84
+ `GET /api/v1/openapi.json`. Any generator that reads OpenAPI can target it.
@@ -0,0 +1,56 @@
1
+ // Generated by scripts/build.mjs from app/openapi/public-api.json — do not edit.
2
+ // Spec version 0.11.0, 50 named schemas.
3
+
4
+ export type { paths, components, operations } from "./schema";
5
+ import type { components } from "./schema";
6
+
7
+ export type AddCartItemBody = components["schemas"]["AddCartItemBody"];
8
+ export type AuthSession = components["schemas"]["AuthSession"];
9
+ export type Cart = components["schemas"]["Cart"];
10
+ export type CartAddress = components["schemas"]["CartAddress"];
11
+ export type CartAddressBody = components["schemas"]["CartAddressBody"];
12
+ export type CartCodeBody = components["schemas"]["CartCodeBody"];
13
+ export type CartDiscount = components["schemas"]["CartDiscount"];
14
+ export type CartGiftCard = components["schemas"]["CartGiftCard"];
15
+ export type CartTotals = components["schemas"]["CartTotals"];
16
+ export type Category = components["schemas"]["Category"];
17
+ export type CategorySummary = components["schemas"]["CategorySummary"];
18
+ export type CategoryTreeNode = components["schemas"]["CategoryTreeNode"];
19
+ export type Collection = components["schemas"]["Collection"];
20
+ export type Country = components["schemas"]["Country"];
21
+ export type CreateReturnBody = components["schemas"]["CreateReturnBody"];
22
+ export type Currency = components["schemas"]["Currency"];
23
+ export type Customer = components["schemas"]["Customer"];
24
+ export type CustomerAddress = components["schemas"]["CustomerAddress"];
25
+ export type Error = components["schemas"]["Error"];
26
+ export type LineItem = components["schemas"]["LineItem"];
27
+ export type LoginBody = components["schemas"]["LoginBody"];
28
+ export type Order = components["schemas"]["Order"];
29
+ export type OrderItem = components["schemas"]["OrderItem"];
30
+ export type OrderListItem = components["schemas"]["OrderListItem"];
31
+ export type OrderTaxLine = components["schemas"]["OrderTaxLine"];
32
+ export type OrderTotals = components["schemas"]["OrderTotals"];
33
+ export type OrderTracking = components["schemas"]["OrderTracking"];
34
+ export type PaginationMeta = components["schemas"]["PaginationMeta"];
35
+ export type PaymentMethod = components["schemas"]["PaymentMethod"];
36
+ export type Product = components["schemas"]["Product"];
37
+ export type ProductCategory = components["schemas"]["ProductCategory"];
38
+ export type ProductCollection = components["schemas"]["ProductCollection"];
39
+ export type ProductListItem = components["schemas"]["ProductListItem"];
40
+ export type ProductOption = components["schemas"]["ProductOption"];
41
+ export type ProductVariant = components["schemas"]["ProductVariant"];
42
+ export type Region = components["schemas"]["Region"];
43
+ export type RegionSummary = components["schemas"]["RegionSummary"];
44
+ export type RegisterBody = components["schemas"]["RegisterBody"];
45
+ export type Return = components["schemas"]["Return"];
46
+ export type ReturnItem = components["schemas"]["ReturnItem"];
47
+ export type RewardPoints = components["schemas"]["RewardPoints"];
48
+ export type SalesChannel = components["schemas"]["SalesChannel"];
49
+ export type Session = components["schemas"]["Session"];
50
+ export type SetCartCustomerBody = components["schemas"]["SetCartCustomerBody"];
51
+ export type SetCartRegionBody = components["schemas"]["SetCartRegionBody"];
52
+ export type Store = components["schemas"]["Store"];
53
+ export type TaxRate = components["schemas"]["TaxRate"];
54
+ export type TaxSummary = components["schemas"]["TaxSummary"];
55
+ export type UpdateCartItemBody = components["schemas"]["UpdateCartItemBody"];
56
+ export type VariantPrice = components["schemas"]["VariantPrice"];