@cronvello/shop-sdk 0.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.
@@ -0,0 +1 @@
1
+ 335eed391a2786a4f7f010b056d2a6a5b49d9e1244960a15516a5d77b93693b5
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Niccas Williams
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,128 @@
1
+ # @cronvello/shop-sdk
2
+
3
+ The shared, typed integration layer for node-shop. It gives Node.js backends and Next.js apps the
4
+ same versioned API contract and the same request behavior instead of copying generated files or
5
+ maintaining one wrapper per application.
6
+
7
+ - Zero runtime dependencies, ESM and CommonJS, Node 20+
8
+ - Complete generated node-shop types and route catalog
9
+ - Strongly typed path parameters, query values, bodies, and response data
10
+ - Production URL built in, with explicit override or an async URL resolver
11
+ - Server and browser entry points with different secret-safety defaults
12
+ - Timeout, cancellation, bounded safe-method retries, envelope handling, and structured errors
13
+
14
+ ## Install
15
+
16
+ ```bash
17
+ npm install @cronvello/shop-sdk
18
+ ```
19
+
20
+ The initial `0.1.0` repository is configured as a private npm package (`restricted`). Only the npm
21
+ owner and explicitly granted collaborators can see or install it.
22
+
23
+ ## Node.js or a Next.js server
24
+
25
+ ```ts
26
+ import { createShopServerClient } from "@cronvello/shop-sdk/server";
27
+
28
+ const shop = createShopServerClient({
29
+ apiKey: process.env.NODE_SHOP_B2B_API_KEY,
30
+ });
31
+
32
+ const checkout = await shop.request("b2b_create_checkout_session", {
33
+ body: {
34
+ appId: "my-app",
35
+ lineItems: [{
36
+ name: "Pro",
37
+ unitAmountCents: 1900,
38
+ currency: "eur",
39
+ quantity: 1,
40
+ recurring: { interval: "month" },
41
+ }],
42
+ successUrl: "https://example.com/success",
43
+ cancelUrl: "https://example.com/cancel",
44
+ },
45
+ });
46
+ ```
47
+
48
+ `createShopServerClientFromEnv()` reads `NODE_SHOP_URL`, `NODE_SHOP_B2B_API_KEY`, and
49
+ `NODE_SHOP_CRON_SECRET`. `NODE_SHOP_URL` is optional: the SDK defaults to the current production
50
+ endpoint. For infrastructure that keeps the live URL in a database, pass an async resolver:
51
+
52
+ ```ts
53
+ const shop = createShopServerClient({
54
+ baseUrl: () => resolveLiveServiceUrl("node-shop"),
55
+ apiKey: () => secrets.get("node-shop"),
56
+ });
57
+ ```
58
+
59
+ The server adapter selects headers from each generated route's auth metadata. B2B routes receive
60
+ both the current `x-api-key` header and the legacy Bearer form used by some node-shop middleware.
61
+ Frontend JWT and cron routes use separate `frontendToken` and `cronSecret` providers. Composite
62
+ auth routes can be handled with the `headers(context)` callback.
63
+
64
+ ## Next.js client components or another browser
65
+
66
+ ```ts
67
+ import { createShopBrowserClient } from "@cronvello/shop-sdk/browser";
68
+
69
+ const shop = createShopBrowserClient({
70
+ headers: { "x-public-api-key": publicStorefrontKey },
71
+ });
72
+
73
+ const result = await shop.request("products_public_search", {
74
+ query: { query: "shirt", page: 1 },
75
+ });
76
+ ```
77
+
78
+ The browser adapter rejects non-public routes by default so a backend secret is not accidentally
79
+ shipped to a client bundle. Set `allowAuthenticatedRoutes` only when a short-lived user credential
80
+ is intentionally supplied by your application.
81
+
82
+ ## Contract-only imports
83
+
84
+ ```ts
85
+ import { apiRoutes, type Product, type ApiRouteKey } from "@cronvello/shop-sdk/contract";
86
+ ```
87
+
88
+ The raw OpenAPI document is exported as `@cronvello/shop-sdk/openapi.json`.
89
+
90
+ ## Errors and retries
91
+
92
+ Failed HTTP responses and successful HTTP envelopes with `success: false` throw `ShopApiError`.
93
+ It contains status, route key, method, path, request ID, and the parsed response body, but never
94
+ stores credentials. GET/HEAD/OPTIONS requests retry transient statuses twice by default with
95
+ bounded exponential backoff. Mutations are never retried unless `retryUnsafe: true` is set for a
96
+ known-idempotent call.
97
+
98
+ ```ts
99
+ import { ShopApiError } from "@cronvello/shop-sdk";
100
+
101
+ try {
102
+ await shop.request("products_public_search", { query: { page: 1 } });
103
+ } catch (error) {
104
+ if (error instanceof ShopApiError) {
105
+ console.error(error.status, error.routeKey, error.requestId);
106
+ }
107
+ }
108
+ ```
109
+
110
+ ## Updating the contract
111
+
112
+ node-shop remains the producer. From this repository, after regenerating node-shop's contract:
113
+
114
+ ```bash
115
+ npm run sync:contract
116
+ npm run check
117
+ ```
118
+
119
+ `sync:contract` copies only the generated contract snapshot, refuses incomplete input, and records
120
+ its SHA-256 in `CONTRACT_SHA256`. CI builds, tests, checks coverage, and verifies the exact package
121
+ archive. `npm run sync:contract:check` detects drift against a sibling `node-shop` checkout.
122
+
123
+ ## Publishing
124
+
125
+ Publication is tag-driven, matching the CronVello SDK pattern. Bump `package.json`, push the commit,
126
+ then push `vX.Y.Z`. The workflow verifies the tag and package versions before using npm trusted
127
+ publishing with `restricted` access. A manual workflow run performs a dry-run only. Private npm
128
+ packages require a paid npm user or organization account.