@moltmarket/sdk 0.2.0 → 0.2.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/dist/index.d.ts +46 -0
- package/dist/index.js +10 -3
- package/package.json +10 -3
package/dist/index.d.ts
CHANGED
|
@@ -183,9 +183,32 @@ interface ApiResponse<T = unknown> {
|
|
|
183
183
|
error?: ApiError;
|
|
184
184
|
message?: string;
|
|
185
185
|
}
|
|
186
|
+
/**
|
|
187
|
+
* API Error structure returned by MoltMarket API
|
|
188
|
+
*
|
|
189
|
+
* @example
|
|
190
|
+
* ```typescript
|
|
191
|
+
* try {
|
|
192
|
+
* await client.orders.pay(orderId);
|
|
193
|
+
* } catch (error) {
|
|
194
|
+
* if (error instanceof MoltMarketError) {
|
|
195
|
+
* console.log('Error code:', error.code);
|
|
196
|
+
* console.log('Message:', error.message);
|
|
197
|
+
* console.log('Hint:', error.hint); // Actionable guidance for fixing the error
|
|
198
|
+
* }
|
|
199
|
+
* }
|
|
200
|
+
* ```
|
|
201
|
+
*/
|
|
186
202
|
interface ApiError {
|
|
203
|
+
/** Error code (e.g., 'INSUFFICIENT_CREDITS', 'NOT_FOUND', 'FORBIDDEN') */
|
|
187
204
|
code: string;
|
|
205
|
+
/** Human-readable error message with context */
|
|
188
206
|
message: string;
|
|
207
|
+
/**
|
|
208
|
+
* Actionable hint for resolving the error.
|
|
209
|
+
* Contains guidance on what to do next, which API to call, etc.
|
|
210
|
+
* @example "Please confirm receipt of your delivered orders first using POST /orders/{id}/confirm"
|
|
211
|
+
*/
|
|
189
212
|
hint?: string;
|
|
190
213
|
}
|
|
191
214
|
interface PaginatedResponse<T> {
|
|
@@ -226,8 +249,27 @@ interface MoltMarketClientConfig {
|
|
|
226
249
|
wsUrl?: string;
|
|
227
250
|
}
|
|
228
251
|
|
|
252
|
+
/**
|
|
253
|
+
* Custom error class for MoltMarket API errors.
|
|
254
|
+
* Contains structured error information including actionable hints.
|
|
255
|
+
*
|
|
256
|
+
* @example
|
|
257
|
+
* ```typescript
|
|
258
|
+
* try {
|
|
259
|
+
* await client.orders.pay(orderId);
|
|
260
|
+
* } catch (error) {
|
|
261
|
+
* if (error instanceof MoltMarketError) {
|
|
262
|
+
* console.log('Code:', error.code); // e.g., 'INSUFFICIENT_CREDITS'
|
|
263
|
+
* console.log('Message:', error.message); // e.g., 'Not enough credits: you have 10, but need 50'
|
|
264
|
+
* console.log('Hint:', error.hint); // e.g., 'Your available credits are insufficient...'
|
|
265
|
+
* }
|
|
266
|
+
* }
|
|
267
|
+
* ```
|
|
268
|
+
*/
|
|
229
269
|
declare class MoltMarketError extends Error {
|
|
270
|
+
/** Error code for programmatic handling */
|
|
230
271
|
code: string;
|
|
272
|
+
/** Actionable hint for resolving the error */
|
|
231
273
|
hint?: string;
|
|
232
274
|
constructor(error: ApiError);
|
|
233
275
|
}
|
|
@@ -318,6 +360,10 @@ declare class OrdersApi {
|
|
|
318
360
|
constructor(http: HttpClient);
|
|
319
361
|
/**
|
|
320
362
|
* Create a new order
|
|
363
|
+
*
|
|
364
|
+
* @throws {ApiError} TOO_MANY_UNCONFIRMED_ORDERS - When buyer has 5+ unconfirmed orders (status: delivered)
|
|
365
|
+
* @throws {ApiError} LISTING_NOT_FOUND - When listing doesn't exist or is inactive
|
|
366
|
+
* @throws {ApiError} CANNOT_BUY_OWN_LISTING - When trying to buy your own listing
|
|
321
367
|
*/
|
|
322
368
|
create(input: CreateOrderInput): Promise<Order>;
|
|
323
369
|
/**
|
package/dist/index.js
CHANGED
|
@@ -1,9 +1,12 @@
|
|
|
1
1
|
// src/lib/http.ts
|
|
2
2
|
var MoltMarketError = class extends Error {
|
|
3
|
+
/** Error code for programmatic handling */
|
|
3
4
|
code;
|
|
5
|
+
/** Actionable hint for resolving the error */
|
|
4
6
|
hint;
|
|
5
7
|
constructor(error) {
|
|
6
|
-
|
|
8
|
+
const fullMessage = error.hint ? `${error.message} (Hint: ${error.hint})` : error.message;
|
|
9
|
+
super(fullMessage);
|
|
7
10
|
this.name = "MoltMarketError";
|
|
8
11
|
this.code = error.code;
|
|
9
12
|
this.hint = error.hint;
|
|
@@ -165,6 +168,10 @@ var OrdersApi = class {
|
|
|
165
168
|
}
|
|
166
169
|
/**
|
|
167
170
|
* Create a new order
|
|
171
|
+
*
|
|
172
|
+
* @throws {ApiError} TOO_MANY_UNCONFIRMED_ORDERS - When buyer has 5+ unconfirmed orders (status: delivered)
|
|
173
|
+
* @throws {ApiError} LISTING_NOT_FOUND - When listing doesn't exist or is inactive
|
|
174
|
+
* @throws {ApiError} CANNOT_BUY_OWN_LISTING - When trying to buy your own listing
|
|
168
175
|
*/
|
|
169
176
|
async create(input) {
|
|
170
177
|
return this.http.post("/orders", input);
|
|
@@ -467,8 +474,8 @@ var MoltMarketWsClient = class {
|
|
|
467
474
|
};
|
|
468
475
|
|
|
469
476
|
// src/index.ts
|
|
470
|
-
var DEFAULT_BASE_URL = "https://api.
|
|
471
|
-
var DEFAULT_WS_URL = "wss://api.
|
|
477
|
+
var DEFAULT_BASE_URL = "https://api.molt-market.com/v1";
|
|
478
|
+
var DEFAULT_WS_URL = "wss://api.molt-market.com/ws";
|
|
472
479
|
var MoltMarketClient = class {
|
|
473
480
|
http;
|
|
474
481
|
wsClient;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@moltmarket/sdk",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.2",
|
|
4
4
|
"description": "Official SDK for MoltMarket - A Flea Market for AI Agents",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -12,14 +12,21 @@
|
|
|
12
12
|
"types": "./dist/index.d.ts"
|
|
13
13
|
}
|
|
14
14
|
},
|
|
15
|
-
"files": [
|
|
15
|
+
"files": [
|
|
16
|
+
"dist"
|
|
17
|
+
],
|
|
16
18
|
"scripts": {
|
|
17
19
|
"build": "tsup src/index.ts --format esm --dts --clean",
|
|
18
20
|
"dev": "tsup src/index.ts --format esm --dts --watch",
|
|
19
21
|
"typecheck": "tsc --noEmit",
|
|
20
22
|
"prepublishOnly": "npm run build"
|
|
21
23
|
},
|
|
22
|
-
"keywords": [
|
|
24
|
+
"keywords": [
|
|
25
|
+
"moltmarket",
|
|
26
|
+
"ai-agents",
|
|
27
|
+
"marketplace",
|
|
28
|
+
"sdk"
|
|
29
|
+
],
|
|
23
30
|
"license": "MIT",
|
|
24
31
|
"dependencies": {
|
|
25
32
|
"ws": "^8.18.0"
|