@xedo/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.
- package/LICENSE +21 -0
- package/README.md +147 -0
- package/dist/index.cjs +573 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +362 -0
- package/dist/index.d.ts +362 -0
- package/dist/index.js +537 -0
- package/dist/index.js.map +1 -0
- package/package.json +63 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Xedo
|
|
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,147 @@
|
|
|
1
|
+
# @xedo/sdk
|
|
2
|
+
|
|
3
|
+
Official Node.js / TypeScript SDK for the **Xedo Developer API v1** — a typed,
|
|
4
|
+
ergonomic client for products, collections, orders & checkout. Server-side,
|
|
5
|
+
MIT licensed.
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install @xedo/sdk
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
> Requires **Node ≥ 18** (native `fetch`).
|
|
12
|
+
|
|
13
|
+
## Quickstart
|
|
14
|
+
|
|
15
|
+
```ts
|
|
16
|
+
import { Xedo } from '@xedo/sdk';
|
|
17
|
+
|
|
18
|
+
const xedo = new Xedo({ apiKey: process.env.XEDO_API_KEY! }); // xdk_live_… or xdk_test_…
|
|
19
|
+
|
|
20
|
+
await xedo.ping(); // validate the key
|
|
21
|
+
const { data, total } = await xedo.products.list({ perPage: 20 });
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
## ⚠️ Server-side only
|
|
25
|
+
|
|
26
|
+
The SDK sends your `xdk_live_…` key as a Bearer token. **Never import it into a
|
|
27
|
+
browser bundle** — your key would be exposed to anyone. Call it from a server:
|
|
28
|
+
Next.js Server Components / Route Handlers, Express, workers, scripts. The
|
|
29
|
+
constructor throws if it detects a browser environment (override only if you
|
|
30
|
+
truly know what you are doing via `dangerouslyAllowBrowser`).
|
|
31
|
+
|
|
32
|
+
## Configuration
|
|
33
|
+
|
|
34
|
+
```ts
|
|
35
|
+
const xedo = new Xedo({
|
|
36
|
+
apiKey: process.env.XEDO_API_KEY!,
|
|
37
|
+
baseUrl: 'https://systems.xedoapp.com/marketplace', // default
|
|
38
|
+
maxRetries: 4, // auto-retry on 429 (default)
|
|
39
|
+
timeoutMs: 30000, // per-request timeout
|
|
40
|
+
fetch: customFetch, // optional injection (tests, edge)
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
xedo.environment; // 'test' | 'live' | 'unknown' (from key prefix)
|
|
44
|
+
xedo.lastRateLimit; // { limit, remaining, reset } from the last call
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
## Resources
|
|
48
|
+
|
|
49
|
+
| Resource | Methods |
|
|
50
|
+
|---|---|
|
|
51
|
+
| `xedo.ping()` | validate the key → `{ marketplaceId, timestamp }` |
|
|
52
|
+
| `xedo.products` | `list`, `listAll`, `retrieve`, `retrieveBySlug` |
|
|
53
|
+
| `xedo.collections` | `list`, `listAll`, `retrieve`, `retrieveBySlug` |
|
|
54
|
+
| `xedo.orders` | `list`, `listAll`, `retrieve`, `invoice` (PDF) |
|
|
55
|
+
| `xedo.carts` | `list`, `listAll`, `retrieve`, `preview`, `create`, `pay`, `createAndPay` |
|
|
56
|
+
|
|
57
|
+
### Pagination
|
|
58
|
+
|
|
59
|
+
`list()` returns `{ data, total, start, end }`. `listAll()` is an async iterator
|
|
60
|
+
that walks every page for you:
|
|
61
|
+
|
|
62
|
+
```ts
|
|
63
|
+
const { data, total } = await xedo.orders.list({ page: 1, perPage: 50 });
|
|
64
|
+
|
|
65
|
+
for await (const order of xedo.orders.listAll()) {
|
|
66
|
+
// …
|
|
67
|
+
}
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
### Checkout
|
|
71
|
+
|
|
72
|
+
```ts
|
|
73
|
+
// Stateless totals — nothing is persisted.
|
|
74
|
+
const totals = await xedo.carts.preview({
|
|
75
|
+
items: [{ publicProductId: 'PRD-XPK39ZQA01', quantity: 2 }],
|
|
76
|
+
delivery: { deliveryType: 'DELIVERY', deliveryAreaId: 11 },
|
|
77
|
+
paymentMethod: 'external_wallet',
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
// Create the cart and get a hosted checkout URL. createAndPay() also retries
|
|
81
|
+
// once if the payment provider was unreachable (502 PAYMENT_INIT_FAILED).
|
|
82
|
+
const { checkoutUrl } = await xedo.carts.createAndPay({
|
|
83
|
+
customer: { firstName: 'Jean', lastName: 'Kouassi', email: 'jean@example.com', phone: '+225 07 12 34 56 78' },
|
|
84
|
+
items: [{ publicProductId: 'PRD-XPK39ZQA01', quantity: 2 }],
|
|
85
|
+
delivery: { deliveryType: 'DELIVERY', deliveryAreaId: 11 },
|
|
86
|
+
paymentMethod: 'external_wallet',
|
|
87
|
+
returnUrl: 'https://my-shop.com/after-checkout', // HTTPS required
|
|
88
|
+
meta: { internalOrderId: 'ORD-12345' }, // echoed back in cart/order responses
|
|
89
|
+
});
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
The `meta` field is your correlation hook: store your own identifiers in it and
|
|
93
|
+
they come back unchanged on every cart/order response.
|
|
94
|
+
|
|
95
|
+
### Invoices
|
|
96
|
+
|
|
97
|
+
```ts
|
|
98
|
+
const pdf = await xedo.orders.invoice('ORD-XPK39ZQA01'); // ArrayBuffer (404 if not generated yet)
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
## Error handling
|
|
102
|
+
|
|
103
|
+
Every `success: false` response throws a typed error. **Route on `error.code`**
|
|
104
|
+
(stable), never on `error.message` (French, may change).
|
|
105
|
+
|
|
106
|
+
```ts
|
|
107
|
+
import { XedoNotFoundError, XedoStockError, XedoError } from '@xedo/sdk';
|
|
108
|
+
|
|
109
|
+
try {
|
|
110
|
+
await xedo.carts.create(input);
|
|
111
|
+
} catch (err) {
|
|
112
|
+
if (err instanceof XedoStockError) console.log(err.errors); // per-product detail
|
|
113
|
+
else if (err instanceof XedoNotFoundError) console.log(err.code);
|
|
114
|
+
else if (err instanceof XedoError) console.log(err.code, err.status);
|
|
115
|
+
else throw err;
|
|
116
|
+
}
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
| Class | Codes | HTTP |
|
|
120
|
+
|---|---|---|
|
|
121
|
+
| `XedoAuthError` | `MISSING_DEVELOPER_API_KEY`, `INVALID_DEVELOPER_API_KEY` | 401 |
|
|
122
|
+
| `XedoValidationError` | `BAD_REQUEST`, `INVALID_PAYMENT_METHOD`, `SPLIT_PAYMENT_NOT_ENABLED`, `COMBINATION_PRODUCT_MISMATCH` | 400 |
|
|
123
|
+
| `XedoNotFoundError` | `PRODUCT_NOT_FOUND`, `COMBINATION_NOT_FOUND`, `DELIVERY_AREA_NOT_FOUND`, `CART_NOT_FOUND`, `NOT_FOUND` | 404 |
|
|
124
|
+
| `XedoStockError` | `INSUFFICIENT_STOCK` (detail in `errors`) | 422 |
|
|
125
|
+
| `XedoConflictError` | `CART_NOT_RETRYABLE` | 409 |
|
|
126
|
+
| `XedoRateLimitError` | `RATE_LIMITED` (exposes `retryAfter`) | 429 |
|
|
127
|
+
| `XedoPaymentInitError` | `PAYMENT_INIT_FAILED` (exposes `cartPublicId`) | 502 |
|
|
128
|
+
| `XedoConnectionError` | timeout / network / malformed response | 0 |
|
|
129
|
+
|
|
130
|
+
`429` responses are retried automatically (respecting `Retry-After`, then
|
|
131
|
+
exponential backoff + jitter, up to `maxRetries`). `POST /v1/carts` is **never**
|
|
132
|
+
auto-retried on `5xx` — the cart may already exist; use `pay()` / `createAndPay()`.
|
|
133
|
+
|
|
134
|
+
## Development
|
|
135
|
+
|
|
136
|
+
```bash
|
|
137
|
+
npm install
|
|
138
|
+
npm run generate # regenerate src/types/generated.ts from openapi.json
|
|
139
|
+
npm run lint
|
|
140
|
+
npm run typecheck
|
|
141
|
+
npm test # vitest + msw
|
|
142
|
+
npm run build # ESM + CJS + .d.ts (tsup)
|
|
143
|
+
```
|
|
144
|
+
|
|
145
|
+
## License
|
|
146
|
+
|
|
147
|
+
MIT
|