Skip to content

Commit 5f1e842

Browse files
committed
Revert "fix: read me generation"
This reverts commit bcca69f.
1 parent bcca69f commit 5f1e842

File tree

2 files changed

+86
-190
lines changed

2 files changed

+86
-190
lines changed

packages/sdks/shopper/README.md

Lines changed: 86 additions & 103 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# @epcc-sdk/sdks-shopper SDK
22

3-
Below youll find instructions on how to install, set up, and use the client, along with a list of available operations.
3+
Below you'll find instructions on how to install, set up, and use the client, along with a list of available operations.
44

55
## Features
66

@@ -26,7 +26,6 @@ yarn add @epcc-sdk/sdks-shopper
2626

2727
## Client Usage
2828

29-
3029
Clients are responsible for sending the actual HTTP requests.
3130

3231
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.
@@ -38,23 +37,22 @@ You can configure the client in two ways:
3837

3938
**When using the operation function to make requests, by default the global client will be used unless another is provided.**
4039

41-
4240
### 1. Configure the internal `client` instance directly
4341

4442
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.
4543

4644
```ts
47-
import { client } from "@epcc-sdk/sdks-shopper";
45+
import { client } from "@epcc-sdk/sdks-shopper"
4846

4947
client.setConfig({
50-
// set default base url for requests
51-
baseUrl: 'https://euwest.api.elasticpath.com',
48+
// set default base url for requests
49+
baseUrl: "https://euwest.api.elasticpath.com",
5250

53-
// set default headers for requests
54-
headers: {
55-
Authorization: 'Bearer YOUR_AUTH_TOKEN',
56-
},
57-
});
51+
// set default headers for requests
52+
headers: {
53+
Authorization: "Bearer YOUR_AUTH_TOKEN",
54+
},
55+
})
5856
```
5957

6058
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.
@@ -64,27 +62,27 @@ The disadvantage of this approach is that your code may call the client instance
6462
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.
6563

6664
```ts
67-
import { createClient } from "@epcc-sdk/sdks-shopper";
65+
import { createClient } from "@epcc-sdk/sdks-shopper"
6866

6967
// Create the client with your API base URL.
7068
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-
});
69+
// set default base url for requests
70+
baseUrl: "https://euwest.api.elasticpath.com",
71+
/**
72+
* Set default headers only for requests made by this client.
73+
*/
74+
headers: {
75+
"Custom-Header": "My Value",
76+
},
77+
})
8078
```
8179

8280
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-shopper>".
8381

8482
```ts
8583
const response = await getByContextProduct({
86-
client: myClient,
87-
});
84+
client: myClient,
85+
})
8886
```
8987

9088
### Direct configuration
@@ -93,44 +91,43 @@ Alternatively, you can pass the client configuration options to each SDK functio
9391

9492
```ts
9593
const response = await getByContextProduct({
96-
baseUrl: 'https://example.com', // <-- override default configuration
97-
});
94+
baseUrl: "https://example.com", // <-- override default configuration
95+
})
9896
```
9997

10098
## Interceptors (Middleware)
10199

102100
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
103101

104102
```ts
105-
import { client } from "@epcc-sdk/sdks-shopper";
103+
import { client } from "@epcc-sdk/sdks-shopper"
106104

107105
// Supports async functions
108106
client.interceptors.request.use(async (request) => {
109-
// do something
110-
return request;
111-
});
107+
// do something
108+
return request
109+
})
112110

113111
client.interceptors.request.eject((request) => {
114-
// do something
115-
return request;
116-
});
117-
112+
// do something
113+
return request
114+
})
118115
```
119116

120117
and an example response interceptor
121118

122119
```ts
123-
import { client } from "@epcc-sdk/sdks-shopper";
120+
import { client } from "@epcc-sdk/sdks-shopper"
124121

125122
client.interceptors.response.use((response) => {
126-
// do something
127-
return response;
128-
});
123+
// do something
124+
return response
125+
})
129126

130127
client.interceptors.response.eject((response) => {
131-
// do something
132-
return response;
133-
});
128+
// do something
129+
return response
130+
})
134131
```
135132

136133
> **_Tip:_** To eject, you must provide a reference to the function that was passed to use().
@@ -140,69 +137,14 @@ client.interceptors.response.eject((response) => {
140137
We are working to provide helpers to handle auth easier for you but for now using an interceptor is the easiest method.
141138

142139
```ts
143-
import { client } from "@epcc-sdk/sdks-shopper";
140+
import { client } from "@epcc-sdk/sdks-shopper"
144141

145142
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 { getByContextProduct } from "@epcc-sdk/sdks-shopper";
190-
191-
const product = await getByContextProduct({
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-
});
143+
request.headers.set("Authorization", "Bearer MY_TOKEN")
144+
return request
145+
})
200146
```
201147

202-
---
203-
204-
205-
206148
### Local Storage Authentication Interceptor
207149

208150
The SDK provides a built-in local storage authentication interceptor that automatically handles token management:
@@ -242,6 +184,49 @@ This interceptor:
242184

243185
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.
244186

187+
```ts
188+
type FooData = {
189+
path: {
190+
fooId: number
191+
}
192+
query?: {
193+
bar?: string
194+
}
195+
url: "/foo/{fooId}"
196+
}
197+
198+
const url = client.buildUrl<FooData>({
199+
path: {
200+
fooId: 1,
201+
},
202+
query: {
203+
bar: "baz",
204+
},
205+
url: "/foo/{fooId}",
206+
})
207+
console.log(url) // prints '/foo/1?bar=baz'
208+
```
209+
210+
## Operation Usage
211+
212+
The following examples demonstrate how to use the operation function to make requests.
213+
214+
```ts
215+
import { getByContextProduct } from "@epcc-sdk/sdks-shopper";
216+
217+
const product = await getByContextProduct({
218+
// client: localClient, // optional if you have a client instance you want to use otherwise the global client will be used
219+
path: {
220+
...
221+
},
222+
query: {
223+
...
224+
},
225+
});
226+
```
227+
228+
---
229+
245230
## Utilities
246231

247232
The SDK provides a set of utility functions that simplify common tasks when building a storefront.
@@ -290,9 +275,9 @@ const cartId = getCartId({
290275

291276
Use this utility when you need to quickly check if a cart exists or need to pass the current cart ID to operations.
292277

293-
## Available Operations
294-
278+
---
295279

280+
## Available Operations
296281

297282
- **`getByContextRelease`** (`GET /catalog`)
298283

@@ -548,6 +533,4 @@ Use this utility when you need to quickly check if a cart exists or need to pass
548533

549534
- **`getAFile`** (`GET /v2/files/{fileID}`)
550535

551-
552-
553536
---

packages/sdks/specs/heyapi/readme-gen/readmeTemplate.ejs

Lines changed: 0 additions & 87 deletions
Original file line numberDiff line numberDiff line change
@@ -32,93 +32,6 @@ yarn add <%= name %>
3232

3333
<%- include('partials/usageOperationTemplate') %>
3434

35-
### Local Storage Authentication Interceptor
36-
37-
The SDK provides a built-in local storage authentication interceptor that automatically handles token management:
38-
39-
```ts
40-
import { client } from "@epcc-sdk/sdks-shopper"
41-
import { createAuthLocalStorageInterceptor } from "@epcc-sdk/sdks-shopper"
42-
43-
// Add the interceptor to handle authentication automatically
44-
client.interceptors.request.use(
45-
createAuthLocalStorageInterceptor({
46-
clientId: "YOUR_CLIENT_ID", // Required
47-
autoRefresh: true, // Optional, defaults to true
48-
autoStoreCredentials: true, // Optional, defaults to true
49-
storageKey: "my-custom-storage-key", // Optional, defaults to a predefined key
50-
}),
51-
)
52-
```
53-
54-
This interceptor:
55-
56-
- Stores authentication tokens in localStorage
57-
- Automatically refreshes tokens when they expire
58-
- Creates a new token if one doesn't exist
59-
- Adds the Authorization header to each request
60-
61-
#### Configuration Options
62-
63-
| Option | Type | Default | Description |
64-
| -------------------- | ------- | ------------ | ----------------------------------------------- |
65-
| clientId | string | (required) | Your storefront client ID |
66-
| autoRefresh | boolean | true | Automatically refresh tokens when they expire |
67-
| autoStoreCredentials | boolean | true | Automatically store credentials in localStorage |
68-
| storageKey | string | (predefined) | Custom localStorage key for storing credentials |
69-
70-
## Build URL
71-
72-
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.
73-
74-
## Utilities
75-
76-
The SDK provides a set of utility functions that simplify common tasks when building a storefront.
77-
78-
### Cart Initialization
79-
80-
The `initializeCart` utility creates or retrieves a cart ID for the current shopper session:
81-
82-
```ts
83-
import { initializeCart } from "@epcc-sdk/sdks-shopper/utils"
84-
85-
// Initialize cart with default storage key
86-
const cartId = await initializeCart()
87-
88-
// Or with a custom storage key
89-
const cartId = await initializeCart({
90-
storageKey: "my-custom-cart-key",
91-
})
92-
```
93-
94-
#### How it works:
95-
96-
1. Checks localStorage for an existing cart ID
97-
2. If a cart ID exists, returns it immediately
98-
3. If no cart ID exists, creates a new cart via the API
99-
4. Stores the new cart ID in localStorage for future use
100-
5. Returns the cart ID as a string
101-
102-
This utility is useful for implementing guest checkout flows and ensuring the shopper always has an active cart.
103-
104-
### Cart ID Retrieval
105-
106-
The `getCartId` utility provides a simple way to retrieve the current cart ID from localStorage:
107-
108-
```ts
109-
import { getCartId } from "@epcc-sdk/sdks-shopper/utils"
110-
111-
// Get cart ID using default storage key
112-
const cartId = getCartId()
113-
114-
// Or with a custom storage key
115-
const cartId = getCartId({
116-
storageKey: "my-custom-cart-key",
117-
})
118-
```
119-
120-
Use this utility when you need to quickly check if a cart exists or need to pass the current cart ID to operations.
121-
12235
## Available Operations
12336

12437
<%- include('partials/operationList') %>

0 commit comments

Comments
 (0)