@sonic-commerce/storefront-types 0.23.3 → 0.24.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 CHANGED
@@ -1,6 +1,6 @@
1
1
  # @sonic-commerce/storefront-types
2
2
 
3
- TypeScript types for the Sonic Commerce storefront API (`/api/v1`).
3
+ TypeScript types for the Sonic Commerce storefront API (`/v1`).
4
4
 
5
5
  Types only — no runtime code, nothing to import at run time, nothing added to
6
6
  your bundle. Generated from the API's OpenAPI document, which is itself
@@ -20,13 +20,20 @@ npm i openapi-fetch
20
20
 
21
21
  ## Use
22
22
 
23
+ Every store is served from **one API host**. The store is named by the
24
+ `x-store-id` header, not by the hostname.
25
+
23
26
  ```ts
24
27
  import createClient from "openapi-fetch";
25
28
  import type { paths, Product } from "@sonic-commerce/storefront-types";
26
29
 
30
+ // Server-side only — the Store ID is not meant for a browser bundle.
27
31
  const api = createClient<paths>({
28
- baseUrl: "https://acme.example.com/api/v1",
29
- headers: { "x-publishable-key": process.env.PUBLISHABLE_KEY! },
32
+ baseUrl: "https://api.example.com/v1",
33
+ headers: {
34
+ "x-store-id": process.env.SONIC_STORE_ID!,
35
+ "x-publishable-key": process.env.PUBLISHABLE_KEY!,
36
+ },
30
37
  });
31
38
 
32
39
  // Path, query params and response are all typed and checked.
@@ -37,6 +44,27 @@ const { data, error } = await api.GET("/products", {
37
44
  const products: Product[] | undefined = data?.data;
38
45
  ```
39
46
 
47
+ | Header | Send it | What it is |
48
+ |---|---|---|
49
+ | `x-store-id` | every request | The Store ID (`K7M2-QX9P`), from the admin under Settings → Store details. Keep it on your server |
50
+ | `x-publishable-key` | every request | The client key issued in the admin |
51
+ | `x-shopper-ip` | login, registration, cart creation, password reset, order tracking | The shopper's IP address. These endpoints are rate-limited per shopper and answer `400` without it |
52
+ | `Idempotency-Key` | `POST /carts/{id}/complete` | A unique value you generate. A retry with the same key returns the first response instead of placing a second order |
53
+
54
+ ```ts
55
+ // Your server is the caller, so say which shopper it is acting for.
56
+ await api.POST("/carts", {
57
+ params: { header: { "x-shopper-ip": shopperIp } },
58
+ body: {},
59
+ });
60
+ ```
61
+
62
+ A missing or unknown Store ID or publishable key is answered `404 Not found`.
63
+
64
+ A store with its own **custom domain** can use `https://<that domain>/v1`
65
+ instead; there the hostname names the store and `x-store-id` / `x-shopper-ip`
66
+ are not needed. Per-store subdomains are not served.
67
+
40
68
  Every named schema in the spec is exported as a type alias — `Product`, `Cart`,
41
69
  `Order`, `Store`, `Category`, `Collection`, `AuthSession`, the request bodies,
42
70
  and so on — alongside the raw `paths`, `components` and `operations` that
@@ -65,14 +93,14 @@ const cart = data?.data as Cart | undefined; // shipping_total present
65
93
 
66
94
  ## Versioning
67
95
 
68
- The package version tracks the API version: `0.10.1` describes the `/api/v1`
69
- surface as of release 0.10.1.
96
+ The package version tracks the API version: `0.23.0` describes the `/v1`
97
+ surface as of release 0.23.0.
70
98
 
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:
99
+ While the API is pre-1.0, **breaking changes ship in a minor bump** (0.23 →
100
+ 0.24), per the project's versioning policy. Pin accordingly:
73
101
 
74
102
  ```jsonc
75
- { "devDependencies": { "@sonic-commerce/storefront-types": "~0.10.1" } }
103
+ { "devDependencies": { "@sonic-commerce/storefront-types": "~0.23.0" } }
76
104
  ```
77
105
 
78
106
  `~` accepts patches and stays off the next minor. Switch to `^` once the API
@@ -81,4 +109,4 @@ reaches 1.0.
81
109
  ## Other languages
82
110
 
83
111
  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.
112
+ `GET /v1/openapi.json`. Any generator that reads OpenAPI can target it.
package/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  // Generated by scripts/build.mjs from app/openapi/public-api.json — do not edit.
2
- // Spec version 0.23.3, 54 named schemas.
2
+ // Spec version 0.24.0, 54 named schemas.
3
3
 
4
4
  export type { paths, components, operations } from "./schema";
5
5
  import type { components } from "./schema";
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@sonic-commerce/storefront-types",
3
- "version": "0.23.3",
4
- "description": "TypeScript types for the Sonic Commerce storefront API (/api/v1).",
3
+ "version": "0.24.0",
4
+ "description": "TypeScript types for the Sonic Commerce storefront API (/v1).",
5
5
  "keywords": ["sonic-commerce", "openapi", "types", "storefront"],
6
6
  "license": "UNLICENSED",
7
7
  "repository": {