lunartools-sdk 1.0.1 → 1.0.3
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 +272 -59
- package/dist/index.d.mts +45 -3
- package/dist/index.d.ts +45 -3
- package/dist/index.js +147 -0
- package/dist/index.mjs +128 -0
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -3,22 +3,36 @@
|
|
|
3
3
|
Official TypeScript/JavaScript SDK for the Lunar Tools API.
|
|
4
4
|
|
|
5
5
|
## Installation
|
|
6
|
-
|
|
6
|
+
|
|
7
|
+
```
|
|
7
8
|
npm install @lunartools/sdk
|
|
8
9
|
```
|
|
9
10
|
|
|
11
|
+
## Getting Started
|
|
12
|
+
|
|
13
|
+
### 1. Obtain Your API Key
|
|
14
|
+
Visit the [Lunar Tools Developer Portal](https://www.lunartools.co/developers) to generate your API key.
|
|
15
|
+
|
|
16
|
+
### 2. Get User Access Tokens
|
|
17
|
+
Each API call requires a user's access token. Users can find their access token in the Lunar Tools application under Settings > Developer.
|
|
18
|
+
|
|
10
19
|
## Usage
|
|
11
|
-
|
|
20
|
+
|
|
21
|
+
### Initialize the Client
|
|
22
|
+
|
|
23
|
+
```
|
|
12
24
|
import { Client } from '@lunartools/sdk';
|
|
13
25
|
|
|
14
|
-
// Initialize with your client credentials
|
|
15
26
|
const client = new Client({
|
|
16
|
-
|
|
17
|
-
accessToken: 'your-access-token'
|
|
27
|
+
apiKey: 'your-api-key-here'
|
|
18
28
|
});
|
|
29
|
+
```
|
|
19
30
|
|
|
20
|
-
|
|
31
|
+
### Add Product to Inventory
|
|
32
|
+
|
|
33
|
+
```
|
|
21
34
|
await client.addProduct({
|
|
35
|
+
token: 'user-access-token',
|
|
22
36
|
name: 'Charizard VMAX',
|
|
23
37
|
sku: 'SWSH-074',
|
|
24
38
|
qty: 5,
|
|
@@ -27,19 +41,66 @@ await client.addProduct({
|
|
|
27
41
|
size: 'Standard',
|
|
28
42
|
store: 'TCGPlayer'
|
|
29
43
|
});
|
|
44
|
+
```
|
|
30
45
|
|
|
46
|
+
### Add Order
|
|
47
|
+
|
|
48
|
+
```
|
|
31
49
|
await client.addOrder({
|
|
50
|
+
token: 'user-access-token',
|
|
32
51
|
name: 'Pokemon Booster Box',
|
|
33
52
|
status: 'shipped',
|
|
34
53
|
orderNumber: 'ORD-12345',
|
|
35
54
|
price: '120.00',
|
|
36
55
|
orderTotal: '132.00',
|
|
37
56
|
retailer: 'Amazon',
|
|
38
|
-
tracking: '1Z999AA10123456784'
|
|
57
|
+
tracking: '1Z999AA10123456784',
|
|
58
|
+
qty: '1'
|
|
39
59
|
});
|
|
60
|
+
```
|
|
40
61
|
|
|
41
|
-
|
|
42
|
-
|
|
62
|
+
### Add Profile Analytics
|
|
63
|
+
|
|
64
|
+
```
|
|
65
|
+
await client.addProfile({
|
|
66
|
+
token: 'user-access-token',
|
|
67
|
+
success: true,
|
|
68
|
+
billing: {
|
|
69
|
+
name: 'John Doe',
|
|
70
|
+
phone: '5551234567',
|
|
71
|
+
line1: '123 Main St',
|
|
72
|
+
line2: 'Apt 4B',
|
|
73
|
+
postCode: '10001',
|
|
74
|
+
city: 'New York',
|
|
75
|
+
state: 'NY',
|
|
76
|
+
country: 'United States'
|
|
77
|
+
},
|
|
78
|
+
shipping: {
|
|
79
|
+
name: 'John Doe',
|
|
80
|
+
phone: '5551234567',
|
|
81
|
+
line1: '123 Main St',
|
|
82
|
+
line2: 'Apt 4B',
|
|
83
|
+
postCode: '10001',
|
|
84
|
+
city: 'New York',
|
|
85
|
+
state: 'NY',
|
|
86
|
+
country: 'United States'
|
|
87
|
+
},
|
|
88
|
+
payment: {
|
|
89
|
+
name: 'John Doe',
|
|
90
|
+
type: 'Visa',
|
|
91
|
+
lastFour: '4242',
|
|
92
|
+
expMonth: '12',
|
|
93
|
+
expYear: '2025',
|
|
94
|
+
cvv: '123'
|
|
95
|
+
}
|
|
96
|
+
});
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
### Forward Webhook to Discord
|
|
100
|
+
|
|
101
|
+
```
|
|
102
|
+
const response = await client.webhook(
|
|
103
|
+
'https://www.lunartools.co/api/webhooks/YOUR_TOKEN_HERE',
|
|
43
104
|
{
|
|
44
105
|
content: 'New product in stock!',
|
|
45
106
|
embeds: [{
|
|
@@ -61,22 +122,23 @@ console.log(response); // { status: 'queued', queueLength: 1 }
|
|
|
61
122
|
## API Reference
|
|
62
123
|
|
|
63
124
|
### Constructor
|
|
64
|
-
|
|
125
|
+
|
|
126
|
+
```
|
|
65
127
|
new Client(config: Config)
|
|
66
128
|
```
|
|
67
129
|
|
|
68
130
|
**Config:**
|
|
69
|
-
- `
|
|
70
|
-
- `accessToken` (string, required) - Your access token from Lunar Tools
|
|
131
|
+
- `apiKey` (string, required) - Your API key from the Lunar Tools Developer Portal
|
|
71
132
|
- `baseUrl` (string, optional) - Custom API base URL (defaults to https://www.lunartools.co)
|
|
72
133
|
|
|
73
134
|
### Methods
|
|
74
135
|
|
|
75
|
-
####
|
|
136
|
+
#### addProduct(product: AddProduct): Promise<void>
|
|
76
137
|
|
|
77
|
-
Add a new product to inventory.
|
|
138
|
+
Add a new product to a user's inventory.
|
|
78
139
|
|
|
79
140
|
**Required fields:**
|
|
141
|
+
- `token` (string) - User's access token
|
|
80
142
|
- `name` (string) - Product name
|
|
81
143
|
- `sku` (string) - Product SKU
|
|
82
144
|
- `qty` (number) - Quantity
|
|
@@ -88,20 +150,23 @@ Add a new product to inventory.
|
|
|
88
150
|
- `spent` (number) - Amount spent
|
|
89
151
|
|
|
90
152
|
**Example:**
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
153
|
+
|
|
154
|
+
```
|
|
155
|
+
await client.addProduct({
|
|
156
|
+
token: 'user-access-token',
|
|
157
|
+
name: 'Product Name',
|
|
158
|
+
sku: 'SKU-123',
|
|
159
|
+
qty: 10,
|
|
160
|
+
value: 50.00
|
|
161
|
+
});
|
|
98
162
|
```
|
|
99
163
|
|
|
100
|
-
####
|
|
164
|
+
#### addOrder(order: AddOrder): Promise<void>
|
|
101
165
|
|
|
102
|
-
Add a new order.
|
|
166
|
+
Add a new order to a user's orders.
|
|
103
167
|
|
|
104
168
|
**Required fields:**
|
|
169
|
+
- `token` (string) - User's access token
|
|
105
170
|
- `name` (string) - Order name
|
|
106
171
|
- `status` (string) - Order status
|
|
107
172
|
- `orderNumber` (string) - Order number
|
|
@@ -109,7 +174,7 @@ Add a new order.
|
|
|
109
174
|
**Optional fields:**
|
|
110
175
|
- `image` (string) - Product image URL
|
|
111
176
|
- `tracking` (string) - Tracking number
|
|
112
|
-
- `date` (string) - Order date
|
|
177
|
+
- `date` (string) - Order date (format: MM/DD/YYYY, HH:MM:SS AM/PM)
|
|
113
178
|
- `qty` (string) - Quantity
|
|
114
179
|
- `price` (string) - Item price
|
|
115
180
|
- `orderTotal` (string) - Total order amount
|
|
@@ -118,23 +183,88 @@ Add a new order.
|
|
|
118
183
|
- `tags` (string) - Order tags
|
|
119
184
|
|
|
120
185
|
**Example:**
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
186
|
+
|
|
187
|
+
```
|
|
188
|
+
await client.addOrder({
|
|
189
|
+
token: 'user-access-token',
|
|
190
|
+
name: 'Pokemon Cards',
|
|
191
|
+
status: 'delivered',
|
|
192
|
+
orderNumber: 'ORD-456',
|
|
193
|
+
price: '99.99',
|
|
194
|
+
retailer: 'eBay'
|
|
195
|
+
});
|
|
196
|
+
```
|
|
197
|
+
|
|
198
|
+
#### addProfile(profile: AddProfile): Promise<void>
|
|
199
|
+
|
|
200
|
+
Add profile analytics data for tracking successful/declined checkouts.
|
|
201
|
+
|
|
202
|
+
**Required fields:**
|
|
203
|
+
- `token` (string) - User's access token
|
|
204
|
+
- `success` (boolean) - Whether the checkout was successful
|
|
205
|
+
- `billing` (Address) - Billing address information
|
|
206
|
+
- `shipping` (Address) - Shipping address information
|
|
207
|
+
- `payment` (Payment) - Payment information
|
|
208
|
+
|
|
209
|
+
**Address fields (all required):**
|
|
210
|
+
- `name` (string) - Full name
|
|
211
|
+
- `phone` (string) - Phone number
|
|
212
|
+
- `line1` (string) - Address line 1
|
|
213
|
+
- `line2` (string, optional) - Address line 2
|
|
214
|
+
- `postCode` (string) - Postal/ZIP code
|
|
215
|
+
- `city` (string) - City
|
|
216
|
+
- `state` (string) - State/province
|
|
217
|
+
- `country` (string) - Country
|
|
218
|
+
|
|
219
|
+
**Payment fields (all required):**
|
|
220
|
+
- `name` (string) - Name on card
|
|
221
|
+
- `type` (string) - Card type (e.g., Visa, Mastercard)
|
|
222
|
+
- `lastFour` (string) - Last 4 digits of card
|
|
223
|
+
- `expMonth` (string) - Expiration month (MM)
|
|
224
|
+
- `expYear` (string) - Expiration year (YYYY)
|
|
225
|
+
- `cvv` (string, optional) - CVV code
|
|
226
|
+
|
|
227
|
+
**Example:**
|
|
228
|
+
|
|
229
|
+
```
|
|
230
|
+
await client.addProfile({
|
|
231
|
+
token: 'user-access-token',
|
|
232
|
+
success: true,
|
|
233
|
+
billing: {
|
|
234
|
+
name: 'John Doe',
|
|
235
|
+
phone: '5551234567',
|
|
236
|
+
line1: '123 Main St',
|
|
237
|
+
postCode: '10001',
|
|
238
|
+
city: 'New York',
|
|
239
|
+
state: 'NY',
|
|
240
|
+
country: 'United States'
|
|
241
|
+
},
|
|
242
|
+
shipping: {
|
|
243
|
+
name: 'John Doe',
|
|
244
|
+
phone: '5551234567',
|
|
245
|
+
line1: '456 Oak Ave',
|
|
246
|
+
postCode: '10002',
|
|
247
|
+
city: 'Brooklyn',
|
|
248
|
+
state: 'NY',
|
|
249
|
+
country: 'United States'
|
|
250
|
+
},
|
|
251
|
+
payment: {
|
|
252
|
+
name: 'John Doe',
|
|
253
|
+
type: 'Visa',
|
|
254
|
+
lastFour: '4242',
|
|
255
|
+
expMonth: '12',
|
|
256
|
+
expYear: '2025'
|
|
257
|
+
}
|
|
258
|
+
});
|
|
129
259
|
```
|
|
130
260
|
|
|
131
|
-
####
|
|
261
|
+
#### webhook(webhookUrl: string, payload: Webhook): Promise<WebhookResponse>
|
|
132
262
|
|
|
133
|
-
Forward a webhook payload to Discord.
|
|
263
|
+
Forward a webhook payload to Discord via Lunar Tools.
|
|
134
264
|
|
|
135
265
|
**Parameters:**
|
|
136
266
|
- `webhookUrl` (string) - Full Lunar Tools webhook URL
|
|
137
|
-
- `payload` (
|
|
267
|
+
- `payload` (Webhook) - Discord webhook payload
|
|
138
268
|
|
|
139
269
|
**Payload structure:**
|
|
140
270
|
- `content` (string, optional) - Message content
|
|
@@ -143,37 +273,120 @@ Forward a webhook payload to Discord.
|
|
|
143
273
|
- `embeds` (Embed[], optional) - Array of embeds (max 10)
|
|
144
274
|
|
|
145
275
|
**Example:**
|
|
146
|
-
|
|
147
|
-
const response = await client.webhook('https://www.lunartools.co/api/webhooks/TOKEN',
|
|
148
|
-
{
|
|
149
|
-
content: 'Hello!',
|
|
150
|
-
embeds: [{
|
|
151
|
-
title: 'Alert',
|
|
152
|
-
description: 'Something happened',
|
|
153
|
-
color: 0xFF0000,
|
|
154
|
-
fields: [
|
|
155
|
-
{ name: 'Field 1', value: 'Value 1', inline: true }
|
|
156
|
-
]
|
|
157
|
-
}]
|
|
158
|
-
}
|
|
159
|
-
);
|
|
276
|
+
|
|
160
277
|
```
|
|
278
|
+
const response = await client.webhook(
|
|
279
|
+
'https://www.lunartools.co/api/webhooks/TOKEN',
|
|
280
|
+
{
|
|
281
|
+
content: 'Hello!',
|
|
282
|
+
embeds: [{
|
|
283
|
+
title: 'Alert',
|
|
284
|
+
description: 'Something happened',
|
|
285
|
+
color: 0xFF0000,
|
|
286
|
+
fields: [
|
|
287
|
+
{ name: 'Field 1', value: 'Value 1', inline: true }
|
|
288
|
+
]
|
|
289
|
+
}]
|
|
290
|
+
}
|
|
291
|
+
);
|
|
292
|
+
```
|
|
293
|
+
|
|
294
|
+
## Authentication
|
|
295
|
+
|
|
296
|
+
The SDK uses two-level authentication:
|
|
297
|
+
|
|
298
|
+
1. **API Key**: Your developer API key (passed in constructor)
|
|
299
|
+
- Obtain from: [Developer Portal](https://www.lunartools.co/developers)
|
|
300
|
+
- Used in `x-api-key` header for all requests
|
|
301
|
+
|
|
302
|
+
2. **User Access Token**: Individual user's access token (passed per request)
|
|
303
|
+
- Users find this in: Lunar Tools App > Settings > Developer
|
|
304
|
+
- Identifies which user's data to modify
|
|
161
305
|
|
|
162
306
|
## Error Handling
|
|
163
307
|
|
|
164
308
|
The SDK validates all inputs and throws descriptive errors:
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
309
|
+
|
|
310
|
+
```
|
|
311
|
+
try {
|
|
312
|
+
await client.addProduct({
|
|
313
|
+
token: 'user-access-token',
|
|
314
|
+
name: '',
|
|
315
|
+
sku: 'SKU-123',
|
|
316
|
+
qty: 5
|
|
317
|
+
});
|
|
318
|
+
} catch (error) {
|
|
319
|
+
console.error(error.message); // "Product name is required"
|
|
320
|
+
}
|
|
175
321
|
```
|
|
176
322
|
|
|
323
|
+
## Common Use Cases
|
|
324
|
+
|
|
325
|
+
### E-commerce Bot Integration
|
|
326
|
+
|
|
327
|
+
```
|
|
328
|
+
// After successful checkout
|
|
329
|
+
await client.addOrder({
|
|
330
|
+
token: userAccessToken,
|
|
331
|
+
name: productName,
|
|
332
|
+
status: 'confirmed',
|
|
333
|
+
orderNumber: orderNumber,
|
|
334
|
+
price: price,
|
|
335
|
+
orderTotal: total,
|
|
336
|
+
retailer: 'Nike',
|
|
337
|
+
tracking: trackingNumber
|
|
338
|
+
});
|
|
339
|
+
|
|
340
|
+
// Track profile analytics
|
|
341
|
+
await client.addProfile({
|
|
342
|
+
token: userAccessToken,
|
|
343
|
+
success: checkoutSuccessful,
|
|
344
|
+
billing: billingInfo,
|
|
345
|
+
shipping: shippingInfo,
|
|
346
|
+
payment: paymentInfo
|
|
347
|
+
});
|
|
348
|
+
```
|
|
349
|
+
|
|
350
|
+
### Inventory Management
|
|
351
|
+
|
|
352
|
+
```
|
|
353
|
+
// Add new inventory
|
|
354
|
+
await client.addProduct({
|
|
355
|
+
token: userAccessToken,
|
|
356
|
+
name: 'Limited Edition Sneakers',
|
|
357
|
+
sku: 'SNKR-001',
|
|
358
|
+
qty: 10,
|
|
359
|
+
value: 200.00,
|
|
360
|
+
spent: 150.00,
|
|
361
|
+
store: 'Footlocker'
|
|
362
|
+
});
|
|
363
|
+
```
|
|
364
|
+
|
|
365
|
+
### Discord Notifications
|
|
366
|
+
|
|
367
|
+
```
|
|
368
|
+
// Send success notification
|
|
369
|
+
await client.webhook(webhookUrl, {
|
|
370
|
+
embeds: [{
|
|
371
|
+
title: '✅ Checkout Success',
|
|
372
|
+
description: `Successfully checked out ${productName}`,
|
|
373
|
+
color: 0x00FF00,
|
|
374
|
+
fields: [
|
|
375
|
+
{ name: 'Order Number', value: orderNumber, inline: true },
|
|
376
|
+
{ name: 'Total', value: `$${total}`, inline: true }
|
|
377
|
+
],
|
|
378
|
+
timestamp: new Date().toISOString()
|
|
379
|
+
}]
|
|
380
|
+
});
|
|
381
|
+
```
|
|
382
|
+
|
|
383
|
+
## Support
|
|
384
|
+
|
|
385
|
+
For issues, questions, or feature requests:
|
|
386
|
+
- Discord: [Join our server](https://discord.gg/lunartools)
|
|
387
|
+
- Email: support@lunartools.co
|
|
388
|
+
- Documentation: [docs.lunartools.co](https://docs.lunartools.co)
|
|
389
|
+
|
|
177
390
|
## License
|
|
178
391
|
|
|
179
392
|
MIT
|
package/dist/index.d.mts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
interface Config {
|
|
2
|
-
|
|
3
|
-
accessToken: string;
|
|
2
|
+
apiKey: string;
|
|
4
3
|
baseUrl?: string;
|
|
5
4
|
}
|
|
6
5
|
interface Thumbnail {
|
|
@@ -46,6 +45,7 @@ interface WebhookResponse {
|
|
|
46
45
|
queueLength: number;
|
|
47
46
|
}
|
|
48
47
|
interface AddProduct {
|
|
48
|
+
token: string;
|
|
49
49
|
name: string;
|
|
50
50
|
sku: string;
|
|
51
51
|
qty: number;
|
|
@@ -55,6 +55,7 @@ interface AddProduct {
|
|
|
55
55
|
spent?: number;
|
|
56
56
|
}
|
|
57
57
|
interface AddOrder {
|
|
58
|
+
token: string;
|
|
58
59
|
name: string;
|
|
59
60
|
status: string;
|
|
60
61
|
orderNumber: string;
|
|
@@ -68,5 +69,46 @@ interface AddOrder {
|
|
|
68
69
|
retailer?: string;
|
|
69
70
|
tags?: string;
|
|
70
71
|
}
|
|
72
|
+
interface Address {
|
|
73
|
+
name: string;
|
|
74
|
+
phone: string;
|
|
75
|
+
line1: string;
|
|
76
|
+
line2?: string;
|
|
77
|
+
postCode: string;
|
|
78
|
+
city: string;
|
|
79
|
+
country: string;
|
|
80
|
+
state: string;
|
|
81
|
+
}
|
|
82
|
+
interface Payment {
|
|
83
|
+
name: string;
|
|
84
|
+
type: string;
|
|
85
|
+
lastFour: string;
|
|
86
|
+
expMonth: string;
|
|
87
|
+
expYear: string;
|
|
88
|
+
cvv?: string;
|
|
89
|
+
}
|
|
90
|
+
interface AddProfile {
|
|
91
|
+
token: string;
|
|
92
|
+
success: boolean;
|
|
93
|
+
billing: Address;
|
|
94
|
+
shipping: Address;
|
|
95
|
+
payment: Payment;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
declare class Client {
|
|
99
|
+
private apiKey;
|
|
100
|
+
private api;
|
|
101
|
+
constructor(config: Config);
|
|
102
|
+
addProduct(product: AddProduct): Promise<void>;
|
|
103
|
+
addOrder(order: AddOrder): Promise<void>;
|
|
104
|
+
addProfile(profile: AddProfile): Promise<void>;
|
|
105
|
+
webhook(webhookUrl: string, payload: Webhook): Promise<WebhookResponse>;
|
|
106
|
+
private validateAddProduct;
|
|
107
|
+
private validateAddOrder;
|
|
108
|
+
private validateAddProfile;
|
|
109
|
+
private validateAddress;
|
|
110
|
+
private validatePayment;
|
|
111
|
+
private validateWebhookPayload;
|
|
112
|
+
}
|
|
71
113
|
|
|
72
|
-
export type
|
|
114
|
+
export { type AddOrder, type AddProduct, type AddProfile, type Address, type Author, Client, type Config, type Embed, type Field, type Footer, type Image, type Payment, type Thumbnail, type Webhook, type WebhookResponse };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
interface Config {
|
|
2
|
-
|
|
3
|
-
accessToken: string;
|
|
2
|
+
apiKey: string;
|
|
4
3
|
baseUrl?: string;
|
|
5
4
|
}
|
|
6
5
|
interface Thumbnail {
|
|
@@ -46,6 +45,7 @@ interface WebhookResponse {
|
|
|
46
45
|
queueLength: number;
|
|
47
46
|
}
|
|
48
47
|
interface AddProduct {
|
|
48
|
+
token: string;
|
|
49
49
|
name: string;
|
|
50
50
|
sku: string;
|
|
51
51
|
qty: number;
|
|
@@ -55,6 +55,7 @@ interface AddProduct {
|
|
|
55
55
|
spent?: number;
|
|
56
56
|
}
|
|
57
57
|
interface AddOrder {
|
|
58
|
+
token: string;
|
|
58
59
|
name: string;
|
|
59
60
|
status: string;
|
|
60
61
|
orderNumber: string;
|
|
@@ -68,5 +69,46 @@ interface AddOrder {
|
|
|
68
69
|
retailer?: string;
|
|
69
70
|
tags?: string;
|
|
70
71
|
}
|
|
72
|
+
interface Address {
|
|
73
|
+
name: string;
|
|
74
|
+
phone: string;
|
|
75
|
+
line1: string;
|
|
76
|
+
line2?: string;
|
|
77
|
+
postCode: string;
|
|
78
|
+
city: string;
|
|
79
|
+
country: string;
|
|
80
|
+
state: string;
|
|
81
|
+
}
|
|
82
|
+
interface Payment {
|
|
83
|
+
name: string;
|
|
84
|
+
type: string;
|
|
85
|
+
lastFour: string;
|
|
86
|
+
expMonth: string;
|
|
87
|
+
expYear: string;
|
|
88
|
+
cvv?: string;
|
|
89
|
+
}
|
|
90
|
+
interface AddProfile {
|
|
91
|
+
token: string;
|
|
92
|
+
success: boolean;
|
|
93
|
+
billing: Address;
|
|
94
|
+
shipping: Address;
|
|
95
|
+
payment: Payment;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
declare class Client {
|
|
99
|
+
private apiKey;
|
|
100
|
+
private api;
|
|
101
|
+
constructor(config: Config);
|
|
102
|
+
addProduct(product: AddProduct): Promise<void>;
|
|
103
|
+
addOrder(order: AddOrder): Promise<void>;
|
|
104
|
+
addProfile(profile: AddProfile): Promise<void>;
|
|
105
|
+
webhook(webhookUrl: string, payload: Webhook): Promise<WebhookResponse>;
|
|
106
|
+
private validateAddProduct;
|
|
107
|
+
private validateAddOrder;
|
|
108
|
+
private validateAddProfile;
|
|
109
|
+
private validateAddress;
|
|
110
|
+
private validatePayment;
|
|
111
|
+
private validateWebhookPayload;
|
|
112
|
+
}
|
|
71
113
|
|
|
72
|
-
export type
|
|
114
|
+
export { type AddOrder, type AddProduct, type AddProfile, type Address, type Author, Client, type Config, type Embed, type Field, type Footer, type Image, type Payment, type Thumbnail, type Webhook, type WebhookResponse };
|
package/dist/index.js
CHANGED
|
@@ -1,8 +1,14 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
2
3
|
var __defProp = Object.defineProperty;
|
|
3
4
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
5
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
5
7
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
6
12
|
var __copyProps = (to, from, except, desc) => {
|
|
7
13
|
if (from && typeof from === "object" || typeof from === "function") {
|
|
8
14
|
for (let key of __getOwnPropNames(from))
|
|
@@ -11,8 +17,149 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
11
17
|
}
|
|
12
18
|
return to;
|
|
13
19
|
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
14
28
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
15
29
|
|
|
16
30
|
// src/index.ts
|
|
17
31
|
var index_exports = {};
|
|
32
|
+
__export(index_exports, {
|
|
33
|
+
Client: () => Client
|
|
34
|
+
});
|
|
18
35
|
module.exports = __toCommonJS(index_exports);
|
|
36
|
+
|
|
37
|
+
// src/client/client.ts
|
|
38
|
+
var import_axios = __toESM(require("axios"));
|
|
39
|
+
var Client = class {
|
|
40
|
+
constructor(config) {
|
|
41
|
+
this.apiKey = config.apiKey;
|
|
42
|
+
const baseUrl = config.baseUrl || "https://www.lunartools.co";
|
|
43
|
+
this.api = import_axios.default.create({
|
|
44
|
+
baseURL: baseUrl,
|
|
45
|
+
headers: {
|
|
46
|
+
"Content-Type": "application/json",
|
|
47
|
+
"x-api-key": this.apiKey
|
|
48
|
+
}
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
async addProduct(product) {
|
|
52
|
+
this.validateAddProduct(product);
|
|
53
|
+
await this.api.post("/api/sdk/add-product", product);
|
|
54
|
+
}
|
|
55
|
+
async addOrder(order) {
|
|
56
|
+
this.validateAddOrder(order);
|
|
57
|
+
await this.api.post("/api/sdk/add-order", order);
|
|
58
|
+
}
|
|
59
|
+
async addProfile(profile) {
|
|
60
|
+
this.validateAddProfile(profile);
|
|
61
|
+
await this.api.post("/api/sdk/add-profile", profile);
|
|
62
|
+
}
|
|
63
|
+
async webhook(webhookUrl, payload) {
|
|
64
|
+
this.validateWebhookPayload(payload);
|
|
65
|
+
const response = await import_axios.default.post(webhookUrl, payload, {
|
|
66
|
+
headers: {
|
|
67
|
+
"Content-Type": "application/json"
|
|
68
|
+
}
|
|
69
|
+
});
|
|
70
|
+
return response.data;
|
|
71
|
+
}
|
|
72
|
+
validateAddProduct(product) {
|
|
73
|
+
if (!product.token || product.token.trim() === "") {
|
|
74
|
+
throw new Error("User access token is required");
|
|
75
|
+
}
|
|
76
|
+
if (!product.name || product.name.trim() === "") {
|
|
77
|
+
throw new Error("Product name is required");
|
|
78
|
+
}
|
|
79
|
+
if (!product.sku || product.sku.trim() === "") {
|
|
80
|
+
throw new Error("Product SKU is required");
|
|
81
|
+
}
|
|
82
|
+
if (product.qty === void 0 || product.qty === null) {
|
|
83
|
+
throw new Error("Product quantity is required");
|
|
84
|
+
}
|
|
85
|
+
if (typeof product.qty !== "number" || product.qty < 0) {
|
|
86
|
+
throw new Error("Product quantity must be a non-negative number");
|
|
87
|
+
}
|
|
88
|
+
if (product.value !== void 0 && (typeof product.value !== "number" || product.value < 0)) {
|
|
89
|
+
throw new Error("Product value must be a non-negative number");
|
|
90
|
+
}
|
|
91
|
+
if (product.spent !== void 0 && (typeof product.spent !== "number" || product.spent < 0)) {
|
|
92
|
+
throw new Error("Product spent must be a non-negative number");
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
validateAddOrder(order) {
|
|
96
|
+
if (!order.token || order.token.trim() === "") {
|
|
97
|
+
throw new Error("User access token is required");
|
|
98
|
+
}
|
|
99
|
+
if (!order.name || order.name.trim() === "") {
|
|
100
|
+
throw new Error("Order name is required");
|
|
101
|
+
}
|
|
102
|
+
if (!order.status || order.status.trim() === "") {
|
|
103
|
+
throw new Error("Order status is required");
|
|
104
|
+
}
|
|
105
|
+
if (!order.orderNumber || order.orderNumber.trim() === "") {
|
|
106
|
+
throw new Error("Order number is required");
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
validateAddProfile(profile) {
|
|
110
|
+
if (!profile.token || profile.token.trim() === "") {
|
|
111
|
+
throw new Error("User access token is required");
|
|
112
|
+
}
|
|
113
|
+
if (!profile.billing || !profile.shipping || !profile.payment) {
|
|
114
|
+
throw new Error("Billing, shipping, and payment information are required");
|
|
115
|
+
}
|
|
116
|
+
this.validateAddress(profile.billing, "Billing");
|
|
117
|
+
this.validateAddress(profile.shipping, "Shipping");
|
|
118
|
+
this.validatePayment(profile.payment);
|
|
119
|
+
}
|
|
120
|
+
validateAddress(address, type) {
|
|
121
|
+
const required = ["name", "phone", "line1", "postCode", "city", "country", "state"];
|
|
122
|
+
for (const field of required) {
|
|
123
|
+
if (!address[field] || address[field].trim() === "") {
|
|
124
|
+
throw new Error(`${type} ${field} is required`);
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
validatePayment(payment) {
|
|
129
|
+
const required = ["name", "type", "lastFour", "expMonth", "expYear"];
|
|
130
|
+
for (const field of required) {
|
|
131
|
+
if (!payment[field] || payment[field].toString().trim() === "") {
|
|
132
|
+
throw new Error(`Payment ${field} is required`);
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
validateWebhookPayload(payload) {
|
|
137
|
+
if (!payload.content && (!payload.embeds || payload.embeds.length === 0)) {
|
|
138
|
+
throw new Error("Webhook payload must contain either content or at least one embed");
|
|
139
|
+
}
|
|
140
|
+
if (payload.embeds && payload.embeds.length > 10) {
|
|
141
|
+
throw new Error("Discord webhooks support a maximum of 10 embeds");
|
|
142
|
+
}
|
|
143
|
+
if (payload.embeds) {
|
|
144
|
+
payload.embeds.forEach((embed, index) => {
|
|
145
|
+
if (embed.fields && embed.fields.length > 25) {
|
|
146
|
+
throw new Error(`Embed ${index} exceeds the maximum of 25 fields`);
|
|
147
|
+
}
|
|
148
|
+
if (embed.fields) {
|
|
149
|
+
embed.fields.forEach((field, fieldIndex) => {
|
|
150
|
+
if (!field.name || field.name.trim() === "") {
|
|
151
|
+
throw new Error(`Embed ${index}, field ${fieldIndex}: name is required`);
|
|
152
|
+
}
|
|
153
|
+
if (!field.value || field.value.trim() === "") {
|
|
154
|
+
throw new Error(`Embed ${index}, field ${fieldIndex}: value is required`);
|
|
155
|
+
}
|
|
156
|
+
});
|
|
157
|
+
}
|
|
158
|
+
});
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
};
|
|
162
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
163
|
+
0 && (module.exports = {
|
|
164
|
+
Client
|
|
165
|
+
});
|
package/dist/index.mjs
CHANGED
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
// src/client/client.ts
|
|
2
|
+
import axios from "axios";
|
|
3
|
+
var Client = class {
|
|
4
|
+
constructor(config) {
|
|
5
|
+
this.apiKey = config.apiKey;
|
|
6
|
+
const baseUrl = config.baseUrl || "https://www.lunartools.co";
|
|
7
|
+
this.api = axios.create({
|
|
8
|
+
baseURL: baseUrl,
|
|
9
|
+
headers: {
|
|
10
|
+
"Content-Type": "application/json",
|
|
11
|
+
"x-api-key": this.apiKey
|
|
12
|
+
}
|
|
13
|
+
});
|
|
14
|
+
}
|
|
15
|
+
async addProduct(product) {
|
|
16
|
+
this.validateAddProduct(product);
|
|
17
|
+
await this.api.post("/api/sdk/add-product", product);
|
|
18
|
+
}
|
|
19
|
+
async addOrder(order) {
|
|
20
|
+
this.validateAddOrder(order);
|
|
21
|
+
await this.api.post("/api/sdk/add-order", order);
|
|
22
|
+
}
|
|
23
|
+
async addProfile(profile) {
|
|
24
|
+
this.validateAddProfile(profile);
|
|
25
|
+
await this.api.post("/api/sdk/add-profile", profile);
|
|
26
|
+
}
|
|
27
|
+
async webhook(webhookUrl, payload) {
|
|
28
|
+
this.validateWebhookPayload(payload);
|
|
29
|
+
const response = await axios.post(webhookUrl, payload, {
|
|
30
|
+
headers: {
|
|
31
|
+
"Content-Type": "application/json"
|
|
32
|
+
}
|
|
33
|
+
});
|
|
34
|
+
return response.data;
|
|
35
|
+
}
|
|
36
|
+
validateAddProduct(product) {
|
|
37
|
+
if (!product.token || product.token.trim() === "") {
|
|
38
|
+
throw new Error("User access token is required");
|
|
39
|
+
}
|
|
40
|
+
if (!product.name || product.name.trim() === "") {
|
|
41
|
+
throw new Error("Product name is required");
|
|
42
|
+
}
|
|
43
|
+
if (!product.sku || product.sku.trim() === "") {
|
|
44
|
+
throw new Error("Product SKU is required");
|
|
45
|
+
}
|
|
46
|
+
if (product.qty === void 0 || product.qty === null) {
|
|
47
|
+
throw new Error("Product quantity is required");
|
|
48
|
+
}
|
|
49
|
+
if (typeof product.qty !== "number" || product.qty < 0) {
|
|
50
|
+
throw new Error("Product quantity must be a non-negative number");
|
|
51
|
+
}
|
|
52
|
+
if (product.value !== void 0 && (typeof product.value !== "number" || product.value < 0)) {
|
|
53
|
+
throw new Error("Product value must be a non-negative number");
|
|
54
|
+
}
|
|
55
|
+
if (product.spent !== void 0 && (typeof product.spent !== "number" || product.spent < 0)) {
|
|
56
|
+
throw new Error("Product spent must be a non-negative number");
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
validateAddOrder(order) {
|
|
60
|
+
if (!order.token || order.token.trim() === "") {
|
|
61
|
+
throw new Error("User access token is required");
|
|
62
|
+
}
|
|
63
|
+
if (!order.name || order.name.trim() === "") {
|
|
64
|
+
throw new Error("Order name is required");
|
|
65
|
+
}
|
|
66
|
+
if (!order.status || order.status.trim() === "") {
|
|
67
|
+
throw new Error("Order status is required");
|
|
68
|
+
}
|
|
69
|
+
if (!order.orderNumber || order.orderNumber.trim() === "") {
|
|
70
|
+
throw new Error("Order number is required");
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
validateAddProfile(profile) {
|
|
74
|
+
if (!profile.token || profile.token.trim() === "") {
|
|
75
|
+
throw new Error("User access token is required");
|
|
76
|
+
}
|
|
77
|
+
if (!profile.billing || !profile.shipping || !profile.payment) {
|
|
78
|
+
throw new Error("Billing, shipping, and payment information are required");
|
|
79
|
+
}
|
|
80
|
+
this.validateAddress(profile.billing, "Billing");
|
|
81
|
+
this.validateAddress(profile.shipping, "Shipping");
|
|
82
|
+
this.validatePayment(profile.payment);
|
|
83
|
+
}
|
|
84
|
+
validateAddress(address, type) {
|
|
85
|
+
const required = ["name", "phone", "line1", "postCode", "city", "country", "state"];
|
|
86
|
+
for (const field of required) {
|
|
87
|
+
if (!address[field] || address[field].trim() === "") {
|
|
88
|
+
throw new Error(`${type} ${field} is required`);
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
validatePayment(payment) {
|
|
93
|
+
const required = ["name", "type", "lastFour", "expMonth", "expYear"];
|
|
94
|
+
for (const field of required) {
|
|
95
|
+
if (!payment[field] || payment[field].toString().trim() === "") {
|
|
96
|
+
throw new Error(`Payment ${field} is required`);
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
validateWebhookPayload(payload) {
|
|
101
|
+
if (!payload.content && (!payload.embeds || payload.embeds.length === 0)) {
|
|
102
|
+
throw new Error("Webhook payload must contain either content or at least one embed");
|
|
103
|
+
}
|
|
104
|
+
if (payload.embeds && payload.embeds.length > 10) {
|
|
105
|
+
throw new Error("Discord webhooks support a maximum of 10 embeds");
|
|
106
|
+
}
|
|
107
|
+
if (payload.embeds) {
|
|
108
|
+
payload.embeds.forEach((embed, index) => {
|
|
109
|
+
if (embed.fields && embed.fields.length > 25) {
|
|
110
|
+
throw new Error(`Embed ${index} exceeds the maximum of 25 fields`);
|
|
111
|
+
}
|
|
112
|
+
if (embed.fields) {
|
|
113
|
+
embed.fields.forEach((field, fieldIndex) => {
|
|
114
|
+
if (!field.name || field.name.trim() === "") {
|
|
115
|
+
throw new Error(`Embed ${index}, field ${fieldIndex}: name is required`);
|
|
116
|
+
}
|
|
117
|
+
if (!field.value || field.value.trim() === "") {
|
|
118
|
+
throw new Error(`Embed ${index}, field ${fieldIndex}: value is required`);
|
|
119
|
+
}
|
|
120
|
+
});
|
|
121
|
+
}
|
|
122
|
+
});
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
};
|
|
126
|
+
export {
|
|
127
|
+
Client
|
|
128
|
+
};
|
package/package.json
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "lunartools-sdk",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.3",
|
|
4
4
|
"description": "Official SDK for Lunar Tools API",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"module": "./dist/index.mjs",
|
|
7
7
|
"types": "./dist/index.d.ts",
|
|
8
|
-
"license": "
|
|
8
|
+
"license": "MIT",
|
|
9
9
|
"repository": {
|
|
10
10
|
"type": "git",
|
|
11
11
|
"url": "git+https://github.com/senpai0807/lunartools-sdk-js.git"
|
|
@@ -35,7 +35,7 @@
|
|
|
35
35
|
"axios": "^1.6.0"
|
|
36
36
|
},
|
|
37
37
|
"devDependencies": {
|
|
38
|
-
"@types/node": "
|
|
38
|
+
"@types/node": "25.0.10",
|
|
39
39
|
"tsup": "^8.0.0",
|
|
40
40
|
"typescript": "^5.0.0"
|
|
41
41
|
},
|