Skip to content

Commit 0733828

Browse files
authored
feat: add missing cart response properties (#361)
* feat: add cart and checkout order sdks * fix: nest display price properties correctly on order meta
1 parent e6d2b88 commit 0733828

File tree

15 files changed

+5665
-37
lines changed

15 files changed

+5665
-37
lines changed

.changeset/fifty-islands-judge.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@epcc-sdk/sdks-cart-checkout-order": patch
3+
---
4+
5+
add cart, checkout, order sdks

.changeset/flat-items-hug.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@epcc-sdk/sdks-shopper": patch
3+
---
4+
5+
nest display price properties correctly on order meta
Lines changed: 296 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,296 @@
1+
# @epcc-sdk/sdks-cart-checkout-order SDK
2+
3+
Below you’ll find instructions on how to install, set up, and use the client, along with a list of available operations.
4+
5+
## Features
6+
7+
- type-safe response data and errors
8+
- response data validation and transformation
9+
- access to the original request and response
10+
- granular request and response customization options
11+
- minimal learning curve thanks to extending the underlying technology
12+
13+
---
14+
15+
## Installation
16+
17+
```bash
18+
npm install @epcc-sdk/sdks-cart-checkout-order
19+
# or
20+
pnpm install @epcc-sdk/sdks-cart-checkout-order
21+
# or
22+
yarn add @epcc-sdk/sdks-cart-checkout-order
23+
```
24+
25+
---
26+
27+
## Client Usage
28+
29+
30+
Clients are responsible for sending the actual HTTP requests.
31+
32+
The Fetch client is built as a thin wrapper on top of Fetch API, extending its functionality. If you're already familiar with Fetch, configuring your client will feel like working directly with Fetch API.
33+
34+
You can configure the client in two ways:
35+
36+
- Configuring the internal `client` instance directly
37+
- Using the `createClient` function
38+
39+
**When using the operation function to make requests, by default the global client will be used unless another is provided.**
40+
41+
42+
### 1. Configure the internal `client` instance directly
43+
44+
This is the simpler approach. You can call the setConfig() method at the beginning of your application or anytime you need to update the client configuration. You can pass any Fetch API configuration option to setConfig(), and even your own Fetch implementation.
45+
46+
```ts
47+
import { client } from "@epcc-sdk/sdks-cart-checkout-order";
48+
49+
client.setConfig({
50+
// set default base url for requests
51+
baseUrl: 'https://euwest.api.elasticpath.com',
52+
53+
// set default headers for requests
54+
headers: {
55+
Authorization: 'Bearer YOUR_AUTH_TOKEN',
56+
},
57+
});
58+
```
59+
60+
The disadvantage of this approach is that your code may call the client instance before it's configured for the first time. Depending on your use case, you might need to use the second approach.
61+
62+
### 2. Using the `createClient` function
63+
64+
This is useful when you want to use a different instance of the client for different parts of your application or when you want to use different configurations for different parts of your application.
65+
66+
```ts
67+
import { createClient } from "@epcc-sdk/sdks-cart-checkout-order";
68+
69+
// Create the client with your API base URL.
70+
const client = createClient({
71+
// set default base url for requests
72+
baseUrl: "https://euwest.api.elasticpath.com",
73+
/**
74+
* Set default headers only for requests made by this client.
75+
*/
76+
headers: {
77+
"Custom-Header": 'My Value',
78+
},
79+
});
80+
```
81+
82+
You can also pass this instance to any SDK function through the client option. This will override the default instance from `import { client } from "@epcc-sdk/sdks-cart-checkout-order>".
83+
84+
```ts
85+
const response = await getACart({
86+
client: myClient,
87+
});
88+
```
89+
90+
### Direct configuration
91+
92+
Alternatively, you can pass the client configuration options to each SDK function. This is useful if you don't want to create a client instance for one-off use cases.
93+
94+
```ts
95+
const response = await getACart({
96+
baseUrl: 'https://example.com', // <-- override default configuration
97+
});
98+
```
99+
100+
## Interceptors (Middleware)
101+
102+
Interceptors (middleware) can be used to modify requests before they're sent or responses before they're returned to your application. They can be added with use and removed with eject. Below is an example request interceptor
103+
104+
```ts
105+
import { client } from "@epcc-sdk/sdks-cart-checkout-order";
106+
107+
// Supports async functions
108+
client.interceptors.request.use(async (request) => {
109+
// do something
110+
return request;
111+
});
112+
113+
client.interceptors.request.eject((request) => {
114+
// do something
115+
return request;
116+
});
117+
118+
```
119+
120+
and an example response interceptor
121+
122+
```ts
123+
import { client } from "@epcc-sdk/sdks-cart-checkout-order";
124+
125+
client.interceptors.response.use((response) => {
126+
// do something
127+
return response;
128+
});
129+
130+
client.interceptors.response.eject((response) => {
131+
// do something
132+
return response;
133+
});
134+
```
135+
136+
> **_Tip:_** To eject, you must provide a reference to the function that was passed to use().
137+
138+
## Authentication
139+
140+
We are working to provide helpers to handle auth easier for you but for now using an interceptor is the easiest method.
141+
142+
```ts
143+
import { client } from "@epcc-sdk/sdks-cart-checkout-order";
144+
145+
client.interceptors.request.use((request, options) => {
146+
request.headers.set('Authorization', 'Bearer MY_TOKEN');
147+
return request;
148+
});
149+
```
150+
151+
## Build URL
152+
153+
If you need to access the compiled URL, you can use the buildUrl() method. It's loosely typed by default to accept almost any value; in practice, you will want to pass a type hint.
154+
155+
```ts
156+
type FooData = {
157+
path: {
158+
fooId: number;
159+
};
160+
query?: {
161+
bar?: string;
162+
};
163+
url: '/foo/{fooId}';
164+
};
165+
166+
const url = client.buildUrl<FooData>({
167+
path: {
168+
fooId: 1,
169+
},
170+
query: {
171+
bar: 'baz',
172+
},
173+
url: '/foo/{fooId}',
174+
});
175+
console.log(url); // prints '/foo/1?bar=baz'
176+
```
177+
178+
179+
---
180+
181+
182+
183+
184+
185+
## Operation Usage
186+
The following examples demonstrate how to use the operation function to make requests.
187+
188+
```ts
189+
import { getACart } from "@epcc-sdk/sdks-cart-checkout-order";
190+
191+
const product = await getACart({
192+
// client: localClient, // optional if you have a client instance you want to use otherwise the global client will be used
193+
path: {
194+
...
195+
},
196+
query: {
197+
...
198+
},
199+
});
200+
```
201+
202+
---
203+
204+
205+
206+
## Available Operations
207+
208+
209+
210+
- **`getCarts`** (`GET /v2/carts`)
211+
212+
- **`createACart`** (`POST /v2/carts`)
213+
214+
- **`deleteACart`** (`DELETE /v2/carts/{cartID}`)
215+
216+
- **`getACart`** (`GET /v2/carts/{cartID}`)
217+
218+
- **`updateACart`** (`PUT /v2/carts/{cartID}`)
219+
220+
- **`deleteAllCartItems`** (`DELETE /v2/carts/{cartID}/items`)
221+
222+
- **`getCartItems`** (`GET /v2/carts/{cartID}/items`)
223+
224+
- **`manageCarts`** (`POST /v2/carts/{cartID}/items`)
225+
226+
- **`bulkUpdateItemsInCart`** (`PUT /v2/carts/{cartID}/items`)
227+
228+
- **`deleteACartItem`** (`DELETE /v2/carts/{cartID}/items/{cartitemID}`)
229+
230+
- **`updateACartItem`** (`PUT /v2/carts/{cartID}/items/{cartitemID}`)
231+
232+
- **`deleteAccountCartAssociation`** (`DELETE /v2/carts/{cartID}/relationships/accounts`)
233+
234+
- **`createAccountCartAssociation`** (`POST /v2/carts/{cartID}/relationships/accounts`)
235+
236+
- **`deleteCustomerCartAssociation`** (`DELETE /v2/carts/{cartID}/relationships/customers`)
237+
238+
- **`createCustomerCartAssociation`** (`POST /v2/carts/{cartID}/relationships/customers`)
239+
240+
- **`deleteAPromotionViaPromotionCode`** (`DELETE /v2/carts/{cartID}/discounts/{promoCode}`)
241+
242+
- **`addTaxItemToCart`** (`POST /v2/carts/{cartID}/items/{cartitemID}/taxes`)
243+
244+
- **`bulkDeleteTaxItemsFromCart`** (`DELETE /v2/carts/{cartID}/taxes`)
245+
246+
- **`bulkAddTaxItemsToCart`** (`POST /v2/carts/{cartID}/taxes`)
247+
248+
- **`deleteATaxItem`** (`DELETE /v2/carts/{cartID}/items/{cartitemID}/taxes/{taxitemID}`)
249+
250+
- **`updateATaxItem`** (`PUT /v2/carts/{cartID}/items/{cartitemID}/taxes/{taxitemID}`)
251+
252+
- **`bulkDeleteCustomDiscountsFromCart`** (`DELETE /v2/carts/{cartID}/custom-discounts`)
253+
254+
- **`bulkAddCustomDiscountsToCart`** (`POST /v2/carts/{cartID}/custom-discounts`)
255+
256+
- **`deleteCustomDiscountFromCart`** (`DELETE /v2/carts/{cartID}/custom-discounts/{customdiscountID}`)
257+
258+
- **`updateCustomDiscountForCart`** (`PUT /v2/carts/{cartID}/custom-discounts/{customdiscountID}`)
259+
260+
- **`addCustomDiscountToCartItem`** (`POST /v2/carts/{cartID}/items/{cartitemID}/custom-discounts`)
261+
262+
- **`deleteCustomDiscountFromCartItem`** (`DELETE /v2/carts/{cartID}/items/{cartitemID}/custom-discounts/{customdiscountID}`)
263+
264+
- **`updateCustomDiscountForCartItem`** (`PUT /v2/carts/{cartID}/items/{cartitemID}/custom-discounts/{customdiscountID}`)
265+
266+
- **`createCartPaymentIntent`** (`POST /v2/carts/{cartID}/payments`)
267+
268+
- **`checkoutApi`** (`POST /v2/carts/{cartID}/checkout`)
269+
270+
- **`getCustomerOrders`** (`GET /v2/orders`)
271+
272+
- **`getAnOrder`** (`GET /v2/orders/{orderID}`)
273+
274+
- **`updateAnOrder`** (`PUT /v2/orders/{orderID}`)
275+
276+
- **`getOrderItems`** (`GET /v2/orders/{orderID}/items`)
277+
278+
- **`anonymizeOrders`** (`POST /v2/orders/anonymize`)
279+
280+
- **`paymentSetup`** (`POST /v2/orders/{orderID}/payments`)
281+
282+
- **`confirmPayment`** (`POST /v2/orders/{orderID}/transactions/{transactionID}/confirm`)
283+
284+
- **`captureATransaction`** (`POST /v2/orders/{orderID}/transactions/{transactionID}/capture`)
285+
286+
- **`refundATransaction`** (`POST /v2/orders/{orderID}/transactions/{transactionID}/refund`)
287+
288+
- **`getOrderTransactions`** (`GET /v2/orders/{orderID}/transactions`)
289+
290+
- **`getATransaction`** (`GET /v2/orders/{orderID}/transactions/{transactionID}`)
291+
292+
- **`cancelATransaction`** (`POST /v2/orders/{orderID}/transactions/{transactionID}/cancel`)
293+
294+
295+
296+
---
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import { defaultPlugins, defineConfig } from "@hey-api/openapi-ts"
2+
import { defineConfig as defineReadmeConfig } from "../specs/heyapi/plugins"
3+
4+
export default defineConfig({
5+
client: "@hey-api/client-fetch",
6+
experimentalParser: true,
7+
input: "../specs/cart_checkout.yaml",
8+
output: { path: "src/client", format: "prettier" },
9+
plugins: [
10+
...defaultPlugins,
11+
{
12+
exportInlineEnums: true,
13+
name: "@hey-api/typescript",
14+
},
15+
{
16+
dates: true,
17+
name: "@hey-api/transformers",
18+
},
19+
defineReadmeConfig({
20+
name: "generate-readme",
21+
targetOperation: "getACart",
22+
}),
23+
],
24+
})
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
{
2+
"name": "@epcc-sdk/sdks-cart-checkout-order",
3+
"version": "0.0.0",
4+
"description": "",
5+
"main": "dist/index.js",
6+
"scripts": {
7+
"build": "pnpm openapi-ts && pnpm tsc:build",
8+
"tsc:build": "tsc -p tsconfig.node.json",
9+
"openapi-ts": "openapi-ts"
10+
},
11+
"exports": {
12+
".": {
13+
"types": "./dist/index.d.ts",
14+
"node": {
15+
"import": "./dist/index.js",
16+
"require": "./dist/index.js"
17+
},
18+
"default": "./dist/index.js"
19+
},
20+
"./package.json": "./package.json"
21+
},
22+
"files": [
23+
"dist/**"
24+
],
25+
"keywords": [],
26+
"publishConfig": {
27+
"access": "public"
28+
},
29+
"devDependencies": {
30+
"@hey-api/openapi-ts": "0.61.2",
31+
"typescript": "^5.5.3",
32+
"@types/ejs": "^3.1.5",
33+
"ejs": "^3.1.10"
34+
},
35+
"dependencies": {
36+
"@hey-api/client-fetch": "0.6.0"
37+
}
38+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
// This file is auto-generated by @hey-api/openapi-ts
2+
export * from "./types.gen"
3+
export * from "./sdk.gen"

0 commit comments

Comments
 (0)