@alphabite/medusa-sdk 0.3.1 → 0.3.2
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 +233 -0
- package/dist/index.d.mts +22 -179
- package/dist/index.d.ts +22 -179
- package/dist/index.js +2 -1
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +2 -1
- package/dist/index.mjs.map +1 -0
- package/package.json +1 -1
package/README.md
ADDED
|
@@ -0,0 +1,233 @@
|
|
|
1
|
+
# ⚙️ Alphabite Medusa Client
|
|
2
|
+
|
|
3
|
+
[](https://www.npmjs.com/package/@alphabite/medusa-client)
|
|
4
|
+
[](https://www.npmjs.com/package/@alphabite/medusa-client)
|
|
5
|
+

|
|
6
|
+

|
|
7
|
+
|
|
8
|
+
> Drop-in replacement for `@medusajs/js-sdk` with plugin support for Wishlists, PayPal, Reviews, and more.
|
|
9
|
+
|
|
10
|
+
The **Alphabite Medusa Client** wraps the Medusa JS SDK and adds support for rich frontend integrations via plugin architecture.
|
|
11
|
+
|
|
12
|
+
---
|
|
13
|
+
|
|
14
|
+
## 📚 Table of Contents
|
|
15
|
+
|
|
16
|
+
- [📦 Installation](#-installation)
|
|
17
|
+
- [🚀 Usage](#-usage)
|
|
18
|
+
- [🔁 Drop-in Replacement](#-drop-in-replacement)
|
|
19
|
+
- [🔌 Plugin Injection](#-plugin-injection)
|
|
20
|
+
- [🔐 Auth Handling](#-auth-handling)
|
|
21
|
+
- [✅ Example: Wishlist Usage](#-example-wishlist-usage)
|
|
22
|
+
- [🧩 Plugins Included](#-plugins-included)
|
|
23
|
+
- [🧪 TypeScript Support](#-typescript-support)
|
|
24
|
+
- [📁 Folder Structure Tip](#-folder-structure-tip)
|
|
25
|
+
- [🤝 Contributing](#-contributing)
|
|
26
|
+
- [📝 License](#-license)
|
|
27
|
+
|
|
28
|
+
---
|
|
29
|
+
|
|
30
|
+
## 📦 Installation
|
|
31
|
+
|
|
32
|
+
```bash
|
|
33
|
+
npm install @alphabite/medusa-client
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
---
|
|
37
|
+
|
|
38
|
+
## 🚀 Usage
|
|
39
|
+
|
|
40
|
+
```ts
|
|
41
|
+
import {
|
|
42
|
+
AlphabiteMedusaClient,
|
|
43
|
+
wishlistPlugin,
|
|
44
|
+
paypalPlugin,
|
|
45
|
+
reviewsPlugin,
|
|
46
|
+
} from '@alphabite/medusa-client'
|
|
47
|
+
|
|
48
|
+
const sdk = new AlphabiteMedusaClient(
|
|
49
|
+
{
|
|
50
|
+
baseUrl: process.env.NEXT_PUBLIC_API_URL || 'http://localhost:8000/api',
|
|
51
|
+
debug: process.env.NODE_ENV === 'development',
|
|
52
|
+
publishableKey: process.env.NEXT_PUBLIC_MEDUSA_PUBLISHABLE_KEY,
|
|
53
|
+
},
|
|
54
|
+
[wishlistPlugin, paypalPlugin, reviewsPlugin],
|
|
55
|
+
|
|
56
|
+
// Optional options config to add a global getAuthHeader function for all endpoints
|
|
57
|
+
{
|
|
58
|
+
// supports async functions, for example a server action that fetches the token from headers
|
|
59
|
+
getAuthHeader: async () => {
|
|
60
|
+
const token = await getToken(); // your own function that returns the auth token
|
|
61
|
+
|
|
62
|
+
return {
|
|
63
|
+
authorization: `Bearer ${token}`,
|
|
64
|
+
}
|
|
65
|
+
},
|
|
66
|
+
}
|
|
67
|
+
)
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
---
|
|
71
|
+
|
|
72
|
+
## 🔁 Drop-in Replacement
|
|
73
|
+
|
|
74
|
+
To migrate from the default Medusa SDK:
|
|
75
|
+
|
|
76
|
+
```ts
|
|
77
|
+
// BEFORE
|
|
78
|
+
import Medusa from '@medusajs/js-sdk'
|
|
79
|
+
const sdk = new Medusa({
|
|
80
|
+
baseUrl: process.env.NEXT_PUBLIC_API_URL || 'http://localhost:8000/api',
|
|
81
|
+
debug: process.env.NODE_ENV === 'development',
|
|
82
|
+
publishableKey: process.env.NEXT_PUBLIC_MEDUSA_PUBLISHABLE_KEY,
|
|
83
|
+
})
|
|
84
|
+
|
|
85
|
+
// AFTER
|
|
86
|
+
import { AlphabiteMedusaClient, wishlistPlugin } from '@alphabite/medusa-client'
|
|
87
|
+
|
|
88
|
+
const sdk = new AlphabiteMedusaClient({
|
|
89
|
+
baseUrl: process.env.NEXT_PUBLIC_API_URL || 'http://localhost:8000/api',
|
|
90
|
+
debug: process.env.NODE_ENV === 'development',
|
|
91
|
+
publishableKey: process.env.NEXT_PUBLIC_MEDUSA_PUBLISHABLE_KEY,
|
|
92
|
+
},
|
|
93
|
+
[wishlistPlugin], {
|
|
94
|
+
// supports async functions, for example a server action that fetches the token from headers
|
|
95
|
+
getAuthHeader: async () => {
|
|
96
|
+
const token = await getToken(); // your own function that returns the auth token
|
|
97
|
+
|
|
98
|
+
return {
|
|
99
|
+
authorization: `Bearer ${token}`,
|
|
100
|
+
}
|
|
101
|
+
},
|
|
102
|
+
}
|
|
103
|
+
)
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
---
|
|
107
|
+
|
|
108
|
+
## 🔌 Plugin Injection
|
|
109
|
+
|
|
110
|
+
Pass an array of plugins as the second argument:
|
|
111
|
+
|
|
112
|
+
```ts
|
|
113
|
+
[wishlistPlugin]
|
|
114
|
+
```
|
|
115
|
+
|
|
116
|
+
Each plugin registers a namespace like:
|
|
117
|
+
|
|
118
|
+
```ts
|
|
119
|
+
sdk.alphabite.wishlist
|
|
120
|
+
```
|
|
121
|
+
|
|
122
|
+
---
|
|
123
|
+
|
|
124
|
+
## 🔐 Auth Handling
|
|
125
|
+
|
|
126
|
+
### 1. Global headers with `getAuthHeader`
|
|
127
|
+
|
|
128
|
+
```ts
|
|
129
|
+
const sdk = new AlphabiteMedusaClient(
|
|
130
|
+
{ baseUrl },
|
|
131
|
+
[wishlistPlugin],
|
|
132
|
+
{
|
|
133
|
+
// supports async function, for example a server action that fetches the token from headers
|
|
134
|
+
getAuthHeader: async () => {
|
|
135
|
+
const token = await getToken(); // your own function that returns the auth token
|
|
136
|
+
|
|
137
|
+
return {
|
|
138
|
+
authorization: `Bearer ${token}`,
|
|
139
|
+
}
|
|
140
|
+
},
|
|
141
|
+
}
|
|
142
|
+
)
|
|
143
|
+
```
|
|
144
|
+
|
|
145
|
+
### 2. Per-request headers
|
|
146
|
+
|
|
147
|
+
```ts
|
|
148
|
+
await sdk.alphabite.wishlist.create({ name: 'Favorites' }, {
|
|
149
|
+
'x-request-id': 'abc',
|
|
150
|
+
})
|
|
151
|
+
```
|
|
152
|
+
|
|
153
|
+
---
|
|
154
|
+
|
|
155
|
+
## ✅ Example: Wishlist Usage
|
|
156
|
+
|
|
157
|
+
```ts
|
|
158
|
+
await sdk.alphabite.wishlist.create({ name: 'My Sneakers' })
|
|
159
|
+
|
|
160
|
+
await sdk.alphabite.wishlist.addItem({
|
|
161
|
+
id: 'wishlist_id',
|
|
162
|
+
product_id: 'variant_id',
|
|
163
|
+
})
|
|
164
|
+
|
|
165
|
+
const { data: items } = await sdk.alphabite.wishlist.listItems({
|
|
166
|
+
id: 'wishlist_id',
|
|
167
|
+
})
|
|
168
|
+
```
|
|
169
|
+
|
|
170
|
+
---
|
|
171
|
+
|
|
172
|
+
## 🧩 Plugins Included
|
|
173
|
+
|
|
174
|
+
| Plugin | Namespace | Description |
|
|
175
|
+
|---------------|-------------------|-------------------------------------|
|
|
176
|
+
| `wishlist` | `sdk.alphabite.wishlist` | Multi-wishlist system |
|
|
177
|
+
|
|
178
|
+
---
|
|
179
|
+
|
|
180
|
+
## 🧪 TypeScript Support
|
|
181
|
+
|
|
182
|
+
Includes full types for every plugin endpoint:
|
|
183
|
+
- `Wishlist`, `WishlistItem`, `AddItemToWishlistInput`, etc.
|
|
184
|
+
- Fully typed SDK, request bodies, and responses
|
|
185
|
+
|
|
186
|
+
---
|
|
187
|
+
|
|
188
|
+
## 📁 Folder Structure Tip
|
|
189
|
+
|
|
190
|
+
Create a central instance:
|
|
191
|
+
|
|
192
|
+
```ts
|
|
193
|
+
// lib/sdk.ts
|
|
194
|
+
import {
|
|
195
|
+
AlphabiteMedusaClient,
|
|
196
|
+
wishlistPlugin,
|
|
197
|
+
} from '@alphabite/medusa-client'
|
|
198
|
+
|
|
199
|
+
export const sdk = new AlphabiteMedusaClient(
|
|
200
|
+
{ baseUrl: process.env.NEXT_PUBLIC_API_URL! },
|
|
201
|
+
[wishlistPlugin],
|
|
202
|
+
{
|
|
203
|
+
// supports async function, for example a server action that fetches the token from headers
|
|
204
|
+
getAuthHeader: async () => {
|
|
205
|
+
const token = await getToken(); // your own function that returns the auth token
|
|
206
|
+
|
|
207
|
+
return {
|
|
208
|
+
authorization: `Bearer ${token}`,
|
|
209
|
+
}
|
|
210
|
+
},
|
|
211
|
+
}
|
|
212
|
+
)
|
|
213
|
+
```
|
|
214
|
+
|
|
215
|
+
Use across your app:
|
|
216
|
+
|
|
217
|
+
```ts
|
|
218
|
+
import { sdk } from '@/lib/sdk'
|
|
219
|
+
|
|
220
|
+
await sdk.alphabite.wishlist.list({ limit: 10 })
|
|
221
|
+
```
|
|
222
|
+
|
|
223
|
+
---
|
|
224
|
+
|
|
225
|
+
## 🤝 Contributing
|
|
226
|
+
|
|
227
|
+
Want to build plugins or extend core support? PRs are welcome!
|
|
228
|
+
|
|
229
|
+
---
|
|
230
|
+
|
|
231
|
+
## 📝 License
|
|
232
|
+
|
|
233
|
+
MIT © Alphabite — extend and use freely.
|
package/dist/index.d.mts
CHANGED
|
@@ -1,28 +1,15 @@
|
|
|
1
|
-
import Medusa, {
|
|
2
|
-
import {
|
|
3
|
-
import { FindParams, RemoteQueryFunctionReturnPagination, PriceDTO, CustomerDTO, ProductDTO } from '@medusajs/types';
|
|
1
|
+
import Medusa, { Client } from '@medusajs/js-sdk';
|
|
2
|
+
import { BaseProduct } from '@medusajs/types/dist/http/product/common';
|
|
4
3
|
|
|
5
|
-
interface
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
}
|
|
14
|
-
interface PaginatedInput extends FindParams {
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
interface Wishlist {
|
|
18
|
-
id: string;
|
|
19
|
-
customer_id: string | null;
|
|
20
|
-
sales_channel_id: string;
|
|
21
|
-
created_at: string;
|
|
22
|
-
updated_at: string;
|
|
23
|
-
deleted_at: string | null;
|
|
24
|
-
items: WishlistItem[];
|
|
25
|
-
items_count: number;
|
|
4
|
+
interface WishlistOutput {
|
|
5
|
+
wishlist: {
|
|
6
|
+
id: string;
|
|
7
|
+
customer_id: string;
|
|
8
|
+
sales_channel_id: string;
|
|
9
|
+
items: WishlistItem[];
|
|
10
|
+
created_at: string;
|
|
11
|
+
updated_at: string;
|
|
12
|
+
};
|
|
26
13
|
}
|
|
27
14
|
interface WishlistItem {
|
|
28
15
|
id: string;
|
|
@@ -30,163 +17,19 @@ interface WishlistItem {
|
|
|
30
17
|
wishlist_id: string;
|
|
31
18
|
created_at: string;
|
|
32
19
|
updated_at: string;
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
product: Pick<BaseProduct, 'id' | 'thumbnail'>;
|
|
36
|
-
prices: PriceDTO[];
|
|
37
|
-
}) | null;
|
|
38
|
-
}
|
|
39
|
-
interface CreateWishlistInput {
|
|
40
|
-
name?: string;
|
|
41
|
-
sales_channel_id: string;
|
|
42
|
-
}
|
|
43
|
-
interface CreateWishlistOutput extends Wishlist {
|
|
44
|
-
}
|
|
45
|
-
interface AddItemToWishlistInput {
|
|
46
|
-
product_variant_id: string;
|
|
47
|
-
id: string;
|
|
48
|
-
}
|
|
49
|
-
interface AddItemToWishlistOutput extends WishlistItem {
|
|
50
|
-
}
|
|
51
|
-
interface ListWishlistsInput extends PaginatedInput {
|
|
52
|
-
items_fields?: string[];
|
|
53
|
-
}
|
|
54
|
-
interface ListWishlistsOutput extends PaginatedOutput<Wishlist> {
|
|
55
|
-
}
|
|
56
|
-
interface RetrieveWishlistInput {
|
|
57
|
-
id: string;
|
|
58
|
-
items_fields?: string[];
|
|
59
|
-
}
|
|
60
|
-
interface RetrieveWishlistOutput extends Wishlist {
|
|
61
|
-
}
|
|
62
|
-
interface ListItemsInput extends PaginatedInput {
|
|
63
|
-
id: string;
|
|
64
|
-
}
|
|
65
|
-
interface ListItemsOutput extends PaginatedOutput<WishlistItem> {
|
|
66
|
-
}
|
|
67
|
-
interface TotalItemsCountInput {
|
|
68
|
-
wishlist_id?: string;
|
|
69
|
-
}
|
|
70
|
-
interface TotalItemsCountOutput {
|
|
71
|
-
total_items_count: number;
|
|
72
|
-
}
|
|
73
|
-
interface TransferWishlistInput {
|
|
74
|
-
id: string;
|
|
75
|
-
}
|
|
76
|
-
interface TransferWishlistOutput {
|
|
77
|
-
id: string;
|
|
78
|
-
}
|
|
79
|
-
interface UpdateWishlistInput {
|
|
80
|
-
id: string;
|
|
81
|
-
name?: string;
|
|
82
|
-
}
|
|
83
|
-
interface UpdateWishlistOutput extends Omit<Wishlist, 'items'> {
|
|
84
|
-
}
|
|
85
|
-
interface RemoveItemFromWishlistInput {
|
|
86
|
-
wishlist_item_id: string;
|
|
87
|
-
id: string;
|
|
88
|
-
}
|
|
89
|
-
interface RemoveItemFromWishlistOutput {
|
|
90
|
-
id: string;
|
|
91
|
-
}
|
|
92
|
-
interface DeleteWishlistInput {
|
|
93
|
-
id: string;
|
|
94
|
-
}
|
|
95
|
-
interface DeleteWishlistOutput {
|
|
96
|
-
id: string;
|
|
20
|
+
variants: BaseProduct['variants'];
|
|
21
|
+
product: BaseProduct;
|
|
97
22
|
}
|
|
98
23
|
type WishlistEndpoints = {
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
listItems: (input: ListItemsInput, headers?: ClientHeaders) => Promise<ListItemsOutput>;
|
|
103
|
-
retrieve: (input: RetrieveWishlistInput, headers?: ClientHeaders) => Promise<RetrieveWishlistOutput>;
|
|
104
|
-
transfer: (input: TransferWishlistInput, headers?: ClientHeaders) => Promise<TransferWishlistOutput>;
|
|
105
|
-
update: (input: UpdateWishlistInput, headers?: ClientHeaders) => Promise<UpdateWishlistOutput>;
|
|
106
|
-
delete: (input: DeleteWishlistInput, headers?: ClientHeaders) => Promise<DeleteWishlistOutput>;
|
|
107
|
-
removeItem: (input: RemoveItemFromWishlistInput, headers?: ClientHeaders) => Promise<RemoveItemFromWishlistOutput>;
|
|
108
|
-
totalItemsCount: (input: TotalItemsCountInput, headers?: ClientHeaders) => Promise<TotalItemsCountOutput>;
|
|
109
|
-
};
|
|
110
|
-
declare const wishlistPlugin: Plugin<'wishlist', WishlistEndpoints>;
|
|
111
|
-
|
|
112
|
-
interface CreateClientTokenOutput {
|
|
113
|
-
client_token: string;
|
|
114
|
-
}
|
|
115
|
-
type PaypalEndpoints = {
|
|
116
|
-
createClientToken: (headers?: ClientHeaders) => Promise<CreateClientTokenOutput>;
|
|
24
|
+
list: () => Promise<WishlistOutput>;
|
|
25
|
+
add: (productId: string) => Promise<WishlistOutput>;
|
|
26
|
+
remove: (productId: string) => Promise<WishlistOutput>;
|
|
117
27
|
};
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
average: number;
|
|
122
|
-
counts: {
|
|
123
|
-
rating: number;
|
|
124
|
-
count: number;
|
|
125
|
-
}[];
|
|
126
|
-
product_id: string;
|
|
127
|
-
total_count: number;
|
|
128
|
-
}
|
|
129
|
-
interface Review {
|
|
130
|
-
title: string;
|
|
131
|
-
content: string;
|
|
132
|
-
rating: number;
|
|
133
|
-
id: string;
|
|
134
|
-
created_at: string;
|
|
135
|
-
image_urls: string[];
|
|
136
|
-
is_verified_purchase: boolean;
|
|
137
|
-
product_id: string;
|
|
138
|
-
customer: Pick<CustomerDTO, 'first_name' | 'last_name'>;
|
|
139
|
-
product?: Pick<ProductDTO, 'thumbnail' | 'title' | 'handle' | 'id'> & AggregateCounts;
|
|
140
|
-
}
|
|
141
|
-
interface CreateReviewInput {
|
|
142
|
-
content: string;
|
|
143
|
-
rating: number;
|
|
144
|
-
product_id: string;
|
|
145
|
-
image_base64s: string[];
|
|
146
|
-
title?: string;
|
|
147
|
-
}
|
|
148
|
-
interface CreateReviewOutput extends Review {
|
|
149
|
-
}
|
|
150
|
-
interface ListReviewsInput extends PaginatedInput {
|
|
151
|
-
product_ids?: string[];
|
|
152
|
-
my_reviews_only?: boolean;
|
|
153
|
-
verified_purchase_only?: boolean;
|
|
154
|
-
rating?: number;
|
|
155
|
-
include_product?: boolean;
|
|
156
|
-
}
|
|
157
|
-
interface ListReviewsOutput extends PaginatedOutput<Review> {
|
|
158
|
-
}
|
|
159
|
-
interface ListProductReviewsInput extends PaginatedInput {
|
|
160
|
-
product_id: string;
|
|
161
|
-
my_reviews_only?: boolean;
|
|
162
|
-
verified_purchase_only?: boolean;
|
|
163
|
-
sort?: 'created_at' | 'rating';
|
|
164
|
-
order?: 'asc' | 'desc';
|
|
165
|
-
rating?: number;
|
|
166
|
-
include_product?: boolean;
|
|
167
|
-
}
|
|
168
|
-
interface ListProductReviewsOutput extends PaginatedOutput<Review> {
|
|
169
|
-
}
|
|
170
|
-
interface DeleteReviewInput {
|
|
171
|
-
id: string;
|
|
172
|
-
}
|
|
173
|
-
interface DeleteReviewOutput {
|
|
174
|
-
id: string;
|
|
175
|
-
}
|
|
176
|
-
interface AggregateCountsInput {
|
|
177
|
-
product_id: string;
|
|
178
|
-
verified_purchase_only?: boolean;
|
|
179
|
-
}
|
|
180
|
-
interface AggregateCountsOutput extends AggregateCounts {
|
|
181
|
-
}
|
|
182
|
-
type ReviewsEndpoints = {
|
|
183
|
-
create: (input: CreateReviewInput, headers?: ClientHeaders) => Promise<CreateReviewOutput>;
|
|
184
|
-
list: (input: ListReviewsInput, headers?: ClientHeaders) => Promise<ListReviewsOutput>;
|
|
185
|
-
listProductReviews: (input: ListProductReviewsInput, headers?: ClientHeaders) => Promise<ListProductReviewsOutput>;
|
|
186
|
-
delete: (input: DeleteReviewInput, headers?: ClientHeaders) => Promise<DeleteReviewOutput>;
|
|
187
|
-
aggregateCounts: (input: AggregateCountsInput, headers?: ClientHeaders) => Promise<AggregateCountsOutput>;
|
|
28
|
+
type Plugin$1<Name extends string, Endpoints> = {
|
|
29
|
+
name: Name;
|
|
30
|
+
endpoints: (client: Client, options?: AlphabiteClientOptions) => Endpoints;
|
|
188
31
|
};
|
|
189
|
-
declare const
|
|
32
|
+
declare const wishlistPlugin: Plugin$1<'wishlist', WishlistEndpoints>;
|
|
190
33
|
|
|
191
34
|
type AlphabiteClientOptions = {
|
|
192
35
|
getAuthHeader?: () => Promise<Record<string, string>> | Record<string, string>;
|
|
@@ -198,10 +41,10 @@ type Plugin<Name extends string, Endpoints> = {
|
|
|
198
41
|
type PluginsToAlphabite<T extends readonly Plugin<any, any>[]> = {
|
|
199
42
|
[K in T[number] as K['name']]: ReturnType<K['endpoints']>;
|
|
200
43
|
};
|
|
201
|
-
declare class
|
|
44
|
+
declare class AlphabiteMedusaClient<TPlugins extends readonly Plugin<any, any>[], TOptions extends AlphabiteClientOptions = AlphabiteClientOptions> extends Medusa {
|
|
202
45
|
alphabite: PluginsToAlphabite<TPlugins>;
|
|
203
46
|
protected options?: TOptions;
|
|
204
47
|
constructor(medusaOptions: ConstructorParameters<typeof Medusa>[0], plugins: TPlugins, options?: TOptions);
|
|
205
48
|
}
|
|
206
49
|
|
|
207
|
-
export { type
|
|
50
|
+
export { type AlphabiteClientOptions, AlphabiteMedusaClient, type Plugin, type PluginsToAlphabite, type WishlistItem, type WishlistOutput, wishlistPlugin };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,28 +1,15 @@
|
|
|
1
|
-
import Medusa, {
|
|
2
|
-
import {
|
|
3
|
-
import { FindParams, RemoteQueryFunctionReturnPagination, PriceDTO, CustomerDTO, ProductDTO } from '@medusajs/types';
|
|
1
|
+
import Medusa, { Client } from '@medusajs/js-sdk';
|
|
2
|
+
import { BaseProduct } from '@medusajs/types/dist/http/product/common';
|
|
4
3
|
|
|
5
|
-
interface
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
}
|
|
14
|
-
interface PaginatedInput extends FindParams {
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
interface Wishlist {
|
|
18
|
-
id: string;
|
|
19
|
-
customer_id: string | null;
|
|
20
|
-
sales_channel_id: string;
|
|
21
|
-
created_at: string;
|
|
22
|
-
updated_at: string;
|
|
23
|
-
deleted_at: string | null;
|
|
24
|
-
items: WishlistItem[];
|
|
25
|
-
items_count: number;
|
|
4
|
+
interface WishlistOutput {
|
|
5
|
+
wishlist: {
|
|
6
|
+
id: string;
|
|
7
|
+
customer_id: string;
|
|
8
|
+
sales_channel_id: string;
|
|
9
|
+
items: WishlistItem[];
|
|
10
|
+
created_at: string;
|
|
11
|
+
updated_at: string;
|
|
12
|
+
};
|
|
26
13
|
}
|
|
27
14
|
interface WishlistItem {
|
|
28
15
|
id: string;
|
|
@@ -30,163 +17,19 @@ interface WishlistItem {
|
|
|
30
17
|
wishlist_id: string;
|
|
31
18
|
created_at: string;
|
|
32
19
|
updated_at: string;
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
product: Pick<BaseProduct, 'id' | 'thumbnail'>;
|
|
36
|
-
prices: PriceDTO[];
|
|
37
|
-
}) | null;
|
|
38
|
-
}
|
|
39
|
-
interface CreateWishlistInput {
|
|
40
|
-
name?: string;
|
|
41
|
-
sales_channel_id: string;
|
|
42
|
-
}
|
|
43
|
-
interface CreateWishlistOutput extends Wishlist {
|
|
44
|
-
}
|
|
45
|
-
interface AddItemToWishlistInput {
|
|
46
|
-
product_variant_id: string;
|
|
47
|
-
id: string;
|
|
48
|
-
}
|
|
49
|
-
interface AddItemToWishlistOutput extends WishlistItem {
|
|
50
|
-
}
|
|
51
|
-
interface ListWishlistsInput extends PaginatedInput {
|
|
52
|
-
items_fields?: string[];
|
|
53
|
-
}
|
|
54
|
-
interface ListWishlistsOutput extends PaginatedOutput<Wishlist> {
|
|
55
|
-
}
|
|
56
|
-
interface RetrieveWishlistInput {
|
|
57
|
-
id: string;
|
|
58
|
-
items_fields?: string[];
|
|
59
|
-
}
|
|
60
|
-
interface RetrieveWishlistOutput extends Wishlist {
|
|
61
|
-
}
|
|
62
|
-
interface ListItemsInput extends PaginatedInput {
|
|
63
|
-
id: string;
|
|
64
|
-
}
|
|
65
|
-
interface ListItemsOutput extends PaginatedOutput<WishlistItem> {
|
|
66
|
-
}
|
|
67
|
-
interface TotalItemsCountInput {
|
|
68
|
-
wishlist_id?: string;
|
|
69
|
-
}
|
|
70
|
-
interface TotalItemsCountOutput {
|
|
71
|
-
total_items_count: number;
|
|
72
|
-
}
|
|
73
|
-
interface TransferWishlistInput {
|
|
74
|
-
id: string;
|
|
75
|
-
}
|
|
76
|
-
interface TransferWishlistOutput {
|
|
77
|
-
id: string;
|
|
78
|
-
}
|
|
79
|
-
interface UpdateWishlistInput {
|
|
80
|
-
id: string;
|
|
81
|
-
name?: string;
|
|
82
|
-
}
|
|
83
|
-
interface UpdateWishlistOutput extends Omit<Wishlist, 'items'> {
|
|
84
|
-
}
|
|
85
|
-
interface RemoveItemFromWishlistInput {
|
|
86
|
-
wishlist_item_id: string;
|
|
87
|
-
id: string;
|
|
88
|
-
}
|
|
89
|
-
interface RemoveItemFromWishlistOutput {
|
|
90
|
-
id: string;
|
|
91
|
-
}
|
|
92
|
-
interface DeleteWishlistInput {
|
|
93
|
-
id: string;
|
|
94
|
-
}
|
|
95
|
-
interface DeleteWishlistOutput {
|
|
96
|
-
id: string;
|
|
20
|
+
variants: BaseProduct['variants'];
|
|
21
|
+
product: BaseProduct;
|
|
97
22
|
}
|
|
98
23
|
type WishlistEndpoints = {
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
listItems: (input: ListItemsInput, headers?: ClientHeaders) => Promise<ListItemsOutput>;
|
|
103
|
-
retrieve: (input: RetrieveWishlistInput, headers?: ClientHeaders) => Promise<RetrieveWishlistOutput>;
|
|
104
|
-
transfer: (input: TransferWishlistInput, headers?: ClientHeaders) => Promise<TransferWishlistOutput>;
|
|
105
|
-
update: (input: UpdateWishlistInput, headers?: ClientHeaders) => Promise<UpdateWishlistOutput>;
|
|
106
|
-
delete: (input: DeleteWishlistInput, headers?: ClientHeaders) => Promise<DeleteWishlistOutput>;
|
|
107
|
-
removeItem: (input: RemoveItemFromWishlistInput, headers?: ClientHeaders) => Promise<RemoveItemFromWishlistOutput>;
|
|
108
|
-
totalItemsCount: (input: TotalItemsCountInput, headers?: ClientHeaders) => Promise<TotalItemsCountOutput>;
|
|
109
|
-
};
|
|
110
|
-
declare const wishlistPlugin: Plugin<'wishlist', WishlistEndpoints>;
|
|
111
|
-
|
|
112
|
-
interface CreateClientTokenOutput {
|
|
113
|
-
client_token: string;
|
|
114
|
-
}
|
|
115
|
-
type PaypalEndpoints = {
|
|
116
|
-
createClientToken: (headers?: ClientHeaders) => Promise<CreateClientTokenOutput>;
|
|
24
|
+
list: () => Promise<WishlistOutput>;
|
|
25
|
+
add: (productId: string) => Promise<WishlistOutput>;
|
|
26
|
+
remove: (productId: string) => Promise<WishlistOutput>;
|
|
117
27
|
};
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
average: number;
|
|
122
|
-
counts: {
|
|
123
|
-
rating: number;
|
|
124
|
-
count: number;
|
|
125
|
-
}[];
|
|
126
|
-
product_id: string;
|
|
127
|
-
total_count: number;
|
|
128
|
-
}
|
|
129
|
-
interface Review {
|
|
130
|
-
title: string;
|
|
131
|
-
content: string;
|
|
132
|
-
rating: number;
|
|
133
|
-
id: string;
|
|
134
|
-
created_at: string;
|
|
135
|
-
image_urls: string[];
|
|
136
|
-
is_verified_purchase: boolean;
|
|
137
|
-
product_id: string;
|
|
138
|
-
customer: Pick<CustomerDTO, 'first_name' | 'last_name'>;
|
|
139
|
-
product?: Pick<ProductDTO, 'thumbnail' | 'title' | 'handle' | 'id'> & AggregateCounts;
|
|
140
|
-
}
|
|
141
|
-
interface CreateReviewInput {
|
|
142
|
-
content: string;
|
|
143
|
-
rating: number;
|
|
144
|
-
product_id: string;
|
|
145
|
-
image_base64s: string[];
|
|
146
|
-
title?: string;
|
|
147
|
-
}
|
|
148
|
-
interface CreateReviewOutput extends Review {
|
|
149
|
-
}
|
|
150
|
-
interface ListReviewsInput extends PaginatedInput {
|
|
151
|
-
product_ids?: string[];
|
|
152
|
-
my_reviews_only?: boolean;
|
|
153
|
-
verified_purchase_only?: boolean;
|
|
154
|
-
rating?: number;
|
|
155
|
-
include_product?: boolean;
|
|
156
|
-
}
|
|
157
|
-
interface ListReviewsOutput extends PaginatedOutput<Review> {
|
|
158
|
-
}
|
|
159
|
-
interface ListProductReviewsInput extends PaginatedInput {
|
|
160
|
-
product_id: string;
|
|
161
|
-
my_reviews_only?: boolean;
|
|
162
|
-
verified_purchase_only?: boolean;
|
|
163
|
-
sort?: 'created_at' | 'rating';
|
|
164
|
-
order?: 'asc' | 'desc';
|
|
165
|
-
rating?: number;
|
|
166
|
-
include_product?: boolean;
|
|
167
|
-
}
|
|
168
|
-
interface ListProductReviewsOutput extends PaginatedOutput<Review> {
|
|
169
|
-
}
|
|
170
|
-
interface DeleteReviewInput {
|
|
171
|
-
id: string;
|
|
172
|
-
}
|
|
173
|
-
interface DeleteReviewOutput {
|
|
174
|
-
id: string;
|
|
175
|
-
}
|
|
176
|
-
interface AggregateCountsInput {
|
|
177
|
-
product_id: string;
|
|
178
|
-
verified_purchase_only?: boolean;
|
|
179
|
-
}
|
|
180
|
-
interface AggregateCountsOutput extends AggregateCounts {
|
|
181
|
-
}
|
|
182
|
-
type ReviewsEndpoints = {
|
|
183
|
-
create: (input: CreateReviewInput, headers?: ClientHeaders) => Promise<CreateReviewOutput>;
|
|
184
|
-
list: (input: ListReviewsInput, headers?: ClientHeaders) => Promise<ListReviewsOutput>;
|
|
185
|
-
listProductReviews: (input: ListProductReviewsInput, headers?: ClientHeaders) => Promise<ListProductReviewsOutput>;
|
|
186
|
-
delete: (input: DeleteReviewInput, headers?: ClientHeaders) => Promise<DeleteReviewOutput>;
|
|
187
|
-
aggregateCounts: (input: AggregateCountsInput, headers?: ClientHeaders) => Promise<AggregateCountsOutput>;
|
|
28
|
+
type Plugin$1<Name extends string, Endpoints> = {
|
|
29
|
+
name: Name;
|
|
30
|
+
endpoints: (client: Client, options?: AlphabiteClientOptions) => Endpoints;
|
|
188
31
|
};
|
|
189
|
-
declare const
|
|
32
|
+
declare const wishlistPlugin: Plugin$1<'wishlist', WishlistEndpoints>;
|
|
190
33
|
|
|
191
34
|
type AlphabiteClientOptions = {
|
|
192
35
|
getAuthHeader?: () => Promise<Record<string, string>> | Record<string, string>;
|
|
@@ -198,10 +41,10 @@ type Plugin<Name extends string, Endpoints> = {
|
|
|
198
41
|
type PluginsToAlphabite<T extends readonly Plugin<any, any>[]> = {
|
|
199
42
|
[K in T[number] as K['name']]: ReturnType<K['endpoints']>;
|
|
200
43
|
};
|
|
201
|
-
declare class
|
|
44
|
+
declare class AlphabiteMedusaClient<TPlugins extends readonly Plugin<any, any>[], TOptions extends AlphabiteClientOptions = AlphabiteClientOptions> extends Medusa {
|
|
202
45
|
alphabite: PluginsToAlphabite<TPlugins>;
|
|
203
46
|
protected options?: TOptions;
|
|
204
47
|
constructor(medusaOptions: ConstructorParameters<typeof Medusa>[0], plugins: TPlugins, options?: TOptions);
|
|
205
48
|
}
|
|
206
49
|
|
|
207
|
-
export { type
|
|
50
|
+
export { type AlphabiteClientOptions, AlphabiteMedusaClient, type Plugin, type PluginsToAlphabite, type WishlistItem, type WishlistOutput, wishlistPlugin };
|
package/dist/index.js
CHANGED
|
@@ -1 +1,2 @@
|
|
|
1
|
-
'use strict';var
|
|
1
|
+
'use strict';var a=require('@medusajs/js-sdk');function _interopDefault(e){return e&&e.__esModule?e:{default:e}}var a__default=/*#__PURE__*/_interopDefault(a);var p={name:"wishlist",endpoints:(s,t)=>({list:async()=>s.fetch("/store/customers/me/wishlists",{method:"GET",headers:{...await t?.getAuthHeader?.()}}),add:async i=>s.fetch("/store/customers/me/wishlists/items",{method:"POST",body:JSON.stringify({product_id:i}),headers:{...await t?.getAuthHeader?.()}}),remove:async i=>s.fetch(`/store/customers/me/wishlists/items/${i}`,{method:"DELETE",headers:{...await t?.getAuthHeader?.()}})})};var r=class extends a__default.default{constructor(t,i,o){super(t),this.options=o;let e={};i.forEach(n=>{e[n.name]=n.endpoints(this,this.options);}),this.alphabite=e;}};exports.AlphabiteMedusaClient=r;exports.wishlistPlugin=p;//# sourceMappingURL=index.js.map
|
|
2
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/plugins/wishlist.ts","../src/index.ts"],"names":["wishlistPlugin","client","options","productId","AlphabiteMedusaClient","Medusa","medusaOptions","plugins","endpoints","plugin"],"mappings":"+JAoCO,IAAMA,CAAwD,CAAA,CACnE,IAAM,CAAA,UAAA,CACN,SAAW,CAAA,CAACC,CAAgBC,CAAAA,CAAAA,IAAsC,CAChE,IAAA,CAAM,SACJD,CAAO,CAAA,KAAA,CAAM,+BAAiC,CAAA,CAC5C,MAAQ,CAAA,KAAA,CACR,OAAS,CAAA,CACP,GAAI,MAAMC,CAAS,EAAA,aAAA,IACrB,CACF,CAAC,CACH,CAAA,GAAA,CAAK,MAAOC,CAAAA,EACVF,CAAO,CAAA,KAAA,CAAM,qCAAuC,CAAA,CAClD,MAAQ,CAAA,MAAA,CACR,IAAM,CAAA,IAAA,CAAK,SAAU,CAAA,CAAE,UAAYE,CAAAA,CAAU,CAAC,CAAA,CAC9C,OAAS,CAAA,CACP,GAAI,MAAMD,CAAS,EAAA,aAAA,IACrB,CACF,CAAC,CAAA,CACH,MAAQ,CAAA,MAAOC,GACbF,CAAO,CAAA,KAAA,CAAM,CAAuCE,oCAAAA,EAAAA,CAAS,CAAI,CAAA,CAAA,CAC/D,MAAQ,CAAA,QAAA,CACR,OAAS,CAAA,CACP,GAAI,MAAMD,CAAS,EAAA,aAAA,IACrB,CACF,CAAC,CACL,CACF,CAAA,EC9CaE,IAAAA,CAAAA,CAAN,cAGGC,kBAAO,CAIf,WAAA,CACEC,CACAC,CAAAA,CAAAA,CACAL,CACA,CAAA,CACA,MAAMI,CAAa,CAAA,CACnB,IAAK,CAAA,OAAA,CAAUJ,CACf,CAAA,IAAMM,CAAiB,CAAA,EACvBD,CAAAA,CAAAA,CAAQ,OAASE,CAAAA,CAAAA,EAAW,CAC1BD,CAAAA,CAAUC,CAAO,CAAA,IAAI,CAAIA,CAAAA,CAAAA,CAAO,SAAU,CAAA,IAAA,CAAM,IAAK,CAAA,OAAO,EAC9D,CAAC,CACD,CAAA,IAAA,CAAK,SAAYD,CAAAA,EACnB,CACF","file":"index.js","sourcesContent":["import { BaseProduct } from '@medusajs/types/dist/http/product/common'\r\nimport { Client } from '@medusajs/js-sdk'\r\nimport { AlphabiteClientOptions } from '..'\r\n\r\nexport interface WishlistOutput {\r\n wishlist: {\r\n id: string\r\n customer_id: string\r\n sales_channel_id: string\r\n items: WishlistItem[]\r\n created_at: string\r\n updated_at: string\r\n }\r\n}\r\n\r\nexport interface WishlistItem {\r\n id: string\r\n product_id: string\r\n wishlist_id: string\r\n created_at: string\r\n updated_at: string\r\n variants: BaseProduct['variants']\r\n product: BaseProduct\r\n}\r\n\r\ntype WishlistEndpoints = {\r\n list: () => Promise<WishlistOutput>\r\n add: (productId: string) => Promise<WishlistOutput>\r\n remove: (productId: string) => Promise<WishlistOutput>\r\n}\r\n\r\ntype Plugin<Name extends string, Endpoints> = {\r\n name: Name\r\n endpoints: (client: Client, options?: AlphabiteClientOptions) => Endpoints\r\n}\r\n\r\nexport const wishlistPlugin: Plugin<'wishlist', WishlistEndpoints> = {\r\n name: 'wishlist' as const,\r\n endpoints: (client: Client, options?: AlphabiteClientOptions) => ({\r\n list: async () =>\r\n client.fetch('/store/customers/me/wishlists', {\r\n method: 'GET',\r\n headers: {\r\n ...(await options?.getAuthHeader?.()),\r\n },\r\n }),\r\n add: async (productId: string) =>\r\n client.fetch('/store/customers/me/wishlists/items', {\r\n method: 'POST',\r\n body: JSON.stringify({ product_id: productId }),\r\n headers: {\r\n ...(await options?.getAuthHeader?.()),\r\n },\r\n }),\r\n remove: async (productId: string) =>\r\n client.fetch(`/store/customers/me/wishlists/items/${productId}`, {\r\n method: 'DELETE',\r\n headers: {\r\n ...(await options?.getAuthHeader?.()),\r\n },\r\n }),\r\n }),\r\n}\r\n","import Medusa from '@medusajs/js-sdk'\r\nexport * from './plugins'\r\n\r\nexport type AlphabiteClientOptions = {\r\n getAuthHeader?: () => Promise<Record<string, string>> | Record<string, string>\r\n}\r\n\r\nexport type Plugin<Name extends string, Endpoints> = {\r\n name: Name\r\n endpoints: (client: any, options?: AlphabiteClientOptions) => Endpoints\r\n}\r\n\r\nexport type PluginsToAlphabite<T extends readonly Plugin<any, any>[]> = {\r\n [K in T[number] as K['name']]: ReturnType<K['endpoints']>\r\n}\r\n\r\nexport class AlphabiteMedusaClient<\r\n TPlugins extends readonly Plugin<any, any>[],\r\n TOptions extends AlphabiteClientOptions = AlphabiteClientOptions,\r\n> extends Medusa {\r\n public alphabite: PluginsToAlphabite<TPlugins>\r\n protected options?: TOptions\r\n\r\n constructor(\r\n medusaOptions: ConstructorParameters<typeof Medusa>[0],\r\n plugins: TPlugins,\r\n options?: TOptions,\r\n ) {\r\n super(medusaOptions)\r\n this.options = options\r\n const endpoints: any = {}\r\n plugins.forEach((plugin) => {\r\n endpoints[plugin.name] = plugin.endpoints(this, this.options)\r\n })\r\n this.alphabite = endpoints\r\n }\r\n}\r\n"]}
|
package/dist/index.mjs
CHANGED
|
@@ -1 +1,2 @@
|
|
|
1
|
-
import
|
|
1
|
+
import a from'@medusajs/js-sdk';var p={name:"wishlist",endpoints:(s,t)=>({list:async()=>s.fetch("/store/customers/me/wishlists",{method:"GET",headers:{...await t?.getAuthHeader?.()}}),add:async i=>s.fetch("/store/customers/me/wishlists/items",{method:"POST",body:JSON.stringify({product_id:i}),headers:{...await t?.getAuthHeader?.()}}),remove:async i=>s.fetch(`/store/customers/me/wishlists/items/${i}`,{method:"DELETE",headers:{...await t?.getAuthHeader?.()}})})};var r=class extends a{constructor(t,i,o){super(t),this.options=o;let e={};i.forEach(n=>{e[n.name]=n.endpoints(this,this.options);}),this.alphabite=e;}};export{r as AlphabiteMedusaClient,p as wishlistPlugin};//# sourceMappingURL=index.mjs.map
|
|
2
|
+
//# sourceMappingURL=index.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/plugins/wishlist.ts","../src/index.ts"],"names":["wishlistPlugin","client","options","productId","AlphabiteMedusaClient","Medusa","medusaOptions","plugins","endpoints","plugin"],"mappings":"gCAoCO,IAAMA,CAAwD,CAAA,CACnE,IAAM,CAAA,UAAA,CACN,SAAW,CAAA,CAACC,CAAgBC,CAAAA,CAAAA,IAAsC,CAChE,IAAA,CAAM,SACJD,CAAO,CAAA,KAAA,CAAM,+BAAiC,CAAA,CAC5C,MAAQ,CAAA,KAAA,CACR,OAAS,CAAA,CACP,GAAI,MAAMC,CAAS,EAAA,aAAA,IACrB,CACF,CAAC,CACH,CAAA,GAAA,CAAK,MAAOC,CAAAA,EACVF,CAAO,CAAA,KAAA,CAAM,qCAAuC,CAAA,CAClD,MAAQ,CAAA,MAAA,CACR,IAAM,CAAA,IAAA,CAAK,SAAU,CAAA,CAAE,UAAYE,CAAAA,CAAU,CAAC,CAAA,CAC9C,OAAS,CAAA,CACP,GAAI,MAAMD,CAAS,EAAA,aAAA,IACrB,CACF,CAAC,CAAA,CACH,MAAQ,CAAA,MAAOC,GACbF,CAAO,CAAA,KAAA,CAAM,CAAuCE,oCAAAA,EAAAA,CAAS,CAAI,CAAA,CAAA,CAC/D,MAAQ,CAAA,QAAA,CACR,OAAS,CAAA,CACP,GAAI,MAAMD,CAAS,EAAA,aAAA,IACrB,CACF,CAAC,CACL,CACF,CAAA,EC9CaE,IAAAA,CAAAA,CAAN,cAGGC,CAAO,CAIf,WAAA,CACEC,CACAC,CAAAA,CAAAA,CACAL,CACA,CAAA,CACA,MAAMI,CAAa,CAAA,CACnB,IAAK,CAAA,OAAA,CAAUJ,CACf,CAAA,IAAMM,CAAiB,CAAA,EACvBD,CAAAA,CAAAA,CAAQ,OAASE,CAAAA,CAAAA,EAAW,CAC1BD,CAAAA,CAAUC,CAAO,CAAA,IAAI,CAAIA,CAAAA,CAAAA,CAAO,SAAU,CAAA,IAAA,CAAM,IAAK,CAAA,OAAO,EAC9D,CAAC,CACD,CAAA,IAAA,CAAK,SAAYD,CAAAA,EACnB,CACF","file":"index.mjs","sourcesContent":["import { BaseProduct } from '@medusajs/types/dist/http/product/common'\r\nimport { Client } from '@medusajs/js-sdk'\r\nimport { AlphabiteClientOptions } from '..'\r\n\r\nexport interface WishlistOutput {\r\n wishlist: {\r\n id: string\r\n customer_id: string\r\n sales_channel_id: string\r\n items: WishlistItem[]\r\n created_at: string\r\n updated_at: string\r\n }\r\n}\r\n\r\nexport interface WishlistItem {\r\n id: string\r\n product_id: string\r\n wishlist_id: string\r\n created_at: string\r\n updated_at: string\r\n variants: BaseProduct['variants']\r\n product: BaseProduct\r\n}\r\n\r\ntype WishlistEndpoints = {\r\n list: () => Promise<WishlistOutput>\r\n add: (productId: string) => Promise<WishlistOutput>\r\n remove: (productId: string) => Promise<WishlistOutput>\r\n}\r\n\r\ntype Plugin<Name extends string, Endpoints> = {\r\n name: Name\r\n endpoints: (client: Client, options?: AlphabiteClientOptions) => Endpoints\r\n}\r\n\r\nexport const wishlistPlugin: Plugin<'wishlist', WishlistEndpoints> = {\r\n name: 'wishlist' as const,\r\n endpoints: (client: Client, options?: AlphabiteClientOptions) => ({\r\n list: async () =>\r\n client.fetch('/store/customers/me/wishlists', {\r\n method: 'GET',\r\n headers: {\r\n ...(await options?.getAuthHeader?.()),\r\n },\r\n }),\r\n add: async (productId: string) =>\r\n client.fetch('/store/customers/me/wishlists/items', {\r\n method: 'POST',\r\n body: JSON.stringify({ product_id: productId }),\r\n headers: {\r\n ...(await options?.getAuthHeader?.()),\r\n },\r\n }),\r\n remove: async (productId: string) =>\r\n client.fetch(`/store/customers/me/wishlists/items/${productId}`, {\r\n method: 'DELETE',\r\n headers: {\r\n ...(await options?.getAuthHeader?.()),\r\n },\r\n }),\r\n }),\r\n}\r\n","import Medusa from '@medusajs/js-sdk'\r\nexport * from './plugins'\r\n\r\nexport type AlphabiteClientOptions = {\r\n getAuthHeader?: () => Promise<Record<string, string>> | Record<string, string>\r\n}\r\n\r\nexport type Plugin<Name extends string, Endpoints> = {\r\n name: Name\r\n endpoints: (client: any, options?: AlphabiteClientOptions) => Endpoints\r\n}\r\n\r\nexport type PluginsToAlphabite<T extends readonly Plugin<any, any>[]> = {\r\n [K in T[number] as K['name']]: ReturnType<K['endpoints']>\r\n}\r\n\r\nexport class AlphabiteMedusaClient<\r\n TPlugins extends readonly Plugin<any, any>[],\r\n TOptions extends AlphabiteClientOptions = AlphabiteClientOptions,\r\n> extends Medusa {\r\n public alphabite: PluginsToAlphabite<TPlugins>\r\n protected options?: TOptions\r\n\r\n constructor(\r\n medusaOptions: ConstructorParameters<typeof Medusa>[0],\r\n plugins: TPlugins,\r\n options?: TOptions,\r\n ) {\r\n super(medusaOptions)\r\n this.options = options\r\n const endpoints: any = {}\r\n plugins.forEach((plugin) => {\r\n endpoints[plugin.name] = plugin.endpoints(this, this.options)\r\n })\r\n this.alphabite = endpoints\r\n }\r\n}\r\n"]}
|