@alphabite/medusa-sdk 0.4.0 → 0.5.1
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 +235 -233
- package/package.json +5 -5
package/README.md
CHANGED
|
@@ -1,233 +1,235 @@
|
|
|
1
|
-
# ⚙️ Alphabite Medusa
|
|
2
|
-
|
|
3
|
-
[
|
|
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-
|
|
34
|
-
```
|
|
35
|
-
|
|
36
|
-
---
|
|
37
|
-
|
|
38
|
-
## 🚀 Usage
|
|
39
|
-
|
|
40
|
-
```ts
|
|
41
|
-
import {
|
|
42
|
-
|
|
43
|
-
wishlistPlugin,
|
|
44
|
-
paypalPlugin,
|
|
45
|
-
reviewsPlugin,
|
|
46
|
-
} from '@alphabite/medusa-
|
|
47
|
-
|
|
48
|
-
const sdk = new
|
|
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 {
|
|
87
|
-
|
|
88
|
-
const sdk = new
|
|
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
|
|
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
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
{
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
1
|
+
# ⚙️ Alphabite Medusa Sdk
|
|
2
|
+
|
|
3
|
+
[](https://www.npmjs.com/package/@alphabite/medusa-sdk)
|
|
4
|
+
[](https://www.npmjs.com/package/@alphabite/medusa-sdk)
|
|
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 Sdk** 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-sdk
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
---
|
|
37
|
+
|
|
38
|
+
## 🚀 Usage
|
|
39
|
+
|
|
40
|
+
```ts
|
|
41
|
+
import {
|
|
42
|
+
AlphabiteMedusaSdk,
|
|
43
|
+
wishlistPlugin,
|
|
44
|
+
paypalPlugin,
|
|
45
|
+
reviewsPlugin,
|
|
46
|
+
} from '@alphabite/medusa-sdk'
|
|
47
|
+
|
|
48
|
+
const sdk = new AlphabiteMedusaSdk(
|
|
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 { AlphabiteMedusaSdk, wishlistPlugin } from '@alphabite/medusa-sdk'
|
|
87
|
+
|
|
88
|
+
const sdk = new AlphabiteMedusaSdk({
|
|
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 AlphabiteMedusaSdk(
|
|
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
|
+
| `reviews` | `sdk.alphabite.reviews` | Reviews |
|
|
178
|
+
| `paypal` | `sdk.alphabite.paypal` | Paypal |
|
|
179
|
+
|
|
180
|
+
---
|
|
181
|
+
|
|
182
|
+
## 🧪 TypeScript Support
|
|
183
|
+
|
|
184
|
+
Includes full types for every plugin endpoint:
|
|
185
|
+
- `Wishlist`, `WishlistItem`, `AddItemToWishlistInput`, etc.
|
|
186
|
+
- Fully typed SDK, request bodies, and responses
|
|
187
|
+
|
|
188
|
+
---
|
|
189
|
+
|
|
190
|
+
## 📁 Folder Structure Tip
|
|
191
|
+
|
|
192
|
+
Create a central instance:
|
|
193
|
+
|
|
194
|
+
```ts
|
|
195
|
+
// lib/sdk.ts
|
|
196
|
+
import {
|
|
197
|
+
AlphabiteMedusaSdk,
|
|
198
|
+
wishlistPlugin,
|
|
199
|
+
} from '@alphabite/medusa-sdk'
|
|
200
|
+
|
|
201
|
+
export const sdk = new AlphabiteMedusaSdk(
|
|
202
|
+
{ baseUrl: process.env.NEXT_PUBLIC_API_URL! },
|
|
203
|
+
[wishlistPlugin],
|
|
204
|
+
{
|
|
205
|
+
// supports async function, for example a server action that fetches the token from headers
|
|
206
|
+
getAuthHeader: async () => {
|
|
207
|
+
const token = await getToken(); // your own function that returns the auth token
|
|
208
|
+
|
|
209
|
+
return {
|
|
210
|
+
authorization: `Bearer ${token}`,
|
|
211
|
+
}
|
|
212
|
+
},
|
|
213
|
+
}
|
|
214
|
+
)
|
|
215
|
+
```
|
|
216
|
+
|
|
217
|
+
Use across your app:
|
|
218
|
+
|
|
219
|
+
```ts
|
|
220
|
+
import { sdk } from '@/lib/sdk'
|
|
221
|
+
|
|
222
|
+
await sdk.alphabite.wishlist.list({ limit: 10 })
|
|
223
|
+
```
|
|
224
|
+
|
|
225
|
+
---
|
|
226
|
+
|
|
227
|
+
## 🤝 Contributing
|
|
228
|
+
|
|
229
|
+
Want to build plugins or extend core support? PRs are welcome!
|
|
230
|
+
|
|
231
|
+
---
|
|
232
|
+
|
|
233
|
+
## 📝 License
|
|
234
|
+
|
|
235
|
+
MIT © Alphabite — extend and use freely.
|
package/package.json
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@alphabite/medusa-sdk",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.5.1",
|
|
4
4
|
"description": "Extended Medusa utility sdk client, that adds Alphabite's plugins endpoints",
|
|
5
5
|
"author": "Alphabite",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"bugs": {
|
|
8
|
-
"url": "https://github.com/alphabite-soft/medusa-
|
|
8
|
+
"url": "https://github.com/alphabite-soft/medusa-sdk/issues"
|
|
9
9
|
},
|
|
10
|
-
"homepage": "https://github.com/alphabite-soft/medusa-
|
|
10
|
+
"homepage": "https://github.com/alphabite-soft/medusa-sdk#readme",
|
|
11
11
|
"main": "dist/index.js",
|
|
12
12
|
"module": "dist/index.mjs",
|
|
13
13
|
"types": "dist/index.d.ts",
|
|
@@ -23,7 +23,7 @@
|
|
|
23
23
|
},
|
|
24
24
|
"keywords": [
|
|
25
25
|
"medusa client",
|
|
26
|
-
"alphabite medusa
|
|
26
|
+
"alphabite medusa sdk",
|
|
27
27
|
"medusa v2",
|
|
28
28
|
"medusa other"
|
|
29
29
|
],
|
|
@@ -43,7 +43,7 @@
|
|
|
43
43
|
},
|
|
44
44
|
"repository": {
|
|
45
45
|
"type": "git",
|
|
46
|
-
"url": "git+ssh://git@github.com/alphabite-soft/medusa-
|
|
46
|
+
"url": "git+ssh://git@github.com/alphabite-soft/medusa-sdk.git"
|
|
47
47
|
},
|
|
48
48
|
"packageManager": "yarn@1.22.22+sha1.ac34549e6aa8e7ead463a7407e1c7390f61a6610"
|
|
49
49
|
}
|