lunartools-sdk 1.0.2 → 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 CHANGED
@@ -3,22 +3,36 @@
3
3
  Official TypeScript/JavaScript SDK for the Lunar Tools API.
4
4
 
5
5
  ## Installation
6
- ```bash
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
- ```typescript
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
- clientId: 'your-client-id',
17
- accessToken: 'your-access-token'
27
+ apiKey: 'your-api-key-here'
18
28
  });
29
+ ```
19
30
 
20
- // Add product to inventory
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
- // Forward webhook to Discord
42
- const response = await client.webhook('https://www.lunartools.co/api/webhooks/YOUR_TOKEN_HERE',
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
- ```typescript
125
+
126
+ ```
65
127
  new Client(config: Config)
66
128
  ```
67
129
 
68
130
  **Config:**
69
- - `clientId` (string, required) - Your client ID from Lunar Tools
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
- #### `addProduct(product: AddProduct): Promise<void>`
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
- ```typescript
92
- await client.addProduct({
93
- name: 'Product Name',
94
- sku: 'SKU-123',
95
- qty: 10,
96
- value: 50.00
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
- #### `addOrder(order: AddOrder): Promise<void>`
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
- ```typescript
122
- await client.addOrder({
123
- name: 'Pokemon Cards',
124
- status: 'delivered',
125
- orderNumber: 'ORD-456',
126
- price: '99.99',
127
- retailer: 'eBay'
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
- #### `forwardWebhook(webhookUrl: string, payload: DiscordWebhookPayload): Promise<WebhookResponse>`
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` (DiscordWebhookPayload) - Discord webhook 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
- ```typescript
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
- ```typescript
166
- try {
167
- await client.addProduct({
168
- name: '',
169
- sku: 'SKU-123',
170
- qty: 5
171
- });
172
- } catch (error) {
173
- console.error(error.message);
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
- clientId: string;
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,35 +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
+ }
71
97
 
72
98
  declare class Client {
73
- private clientId;
74
- private accessToken;
99
+ private apiKey;
75
100
  private api;
76
101
  constructor(config: Config);
77
- /**
78
- * Add a new product to inventory
79
- * @param product - Product details
80
- * @throws Error if required fields are missing or invalid
81
- */
82
102
  addProduct(product: AddProduct): Promise<void>;
83
- /**
84
- * Add a new order
85
- * @param order - Order details
86
- * @throws Error if required fields are missing or invalid
87
- */
88
103
  addOrder(order: AddOrder): Promise<void>;
89
- /**
90
- * Forward webhook payload to Discord
91
- * @param webhookUrl - Full webhook URL (e.g., https://www.lunartools.co/api/webhooks/{token})
92
- * @param payload - Discord webhook payload
93
- * @returns Response with status and queue length
94
- * @throws Error if payload is invalid
95
- */
104
+ addProfile(profile: AddProfile): Promise<void>;
96
105
  webhook(webhookUrl: string, payload: Webhook): Promise<WebhookResponse>;
97
106
  private validateAddProduct;
98
107
  private validateAddOrder;
108
+ private validateAddProfile;
109
+ private validateAddress;
110
+ private validatePayment;
99
111
  private validateWebhookPayload;
100
112
  }
101
113
 
102
- export { type AddOrder, type AddProduct, type Author, Client, type Config, type Embed, type Field, type Footer, type Image, type Thumbnail, type Webhook, type WebhookResponse };
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
- clientId: string;
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,35 +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
+ }
71
97
 
72
98
  declare class Client {
73
- private clientId;
74
- private accessToken;
99
+ private apiKey;
75
100
  private api;
76
101
  constructor(config: Config);
77
- /**
78
- * Add a new product to inventory
79
- * @param product - Product details
80
- * @throws Error if required fields are missing or invalid
81
- */
82
102
  addProduct(product: AddProduct): Promise<void>;
83
- /**
84
- * Add a new order
85
- * @param order - Order details
86
- * @throws Error if required fields are missing or invalid
87
- */
88
103
  addOrder(order: AddOrder): Promise<void>;
89
- /**
90
- * Forward webhook payload to Discord
91
- * @param webhookUrl - Full webhook URL (e.g., https://www.lunartools.co/api/webhooks/{token})
92
- * @param payload - Discord webhook payload
93
- * @returns Response with status and queue length
94
- * @throws Error if payload is invalid
95
- */
104
+ addProfile(profile: AddProfile): Promise<void>;
96
105
  webhook(webhookUrl: string, payload: Webhook): Promise<WebhookResponse>;
97
106
  private validateAddProduct;
98
107
  private validateAddOrder;
108
+ private validateAddProfile;
109
+ private validateAddress;
110
+ private validatePayment;
99
111
  private validateWebhookPayload;
100
112
  }
101
113
 
102
- export { type AddOrder, type AddProduct, type Author, Client, type Config, type Embed, type Field, type Footer, type Image, type Thumbnail, type Webhook, type WebhookResponse };
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
@@ -38,51 +38,28 @@ module.exports = __toCommonJS(index_exports);
38
38
  var import_axios = __toESM(require("axios"));
39
39
  var Client = class {
40
40
  constructor(config) {
41
- this.clientId = config.clientId;
42
- this.accessToken = config.accessToken;
41
+ this.apiKey = config.apiKey;
43
42
  const baseUrl = config.baseUrl || "https://www.lunartools.co";
44
43
  this.api = import_axios.default.create({
45
44
  baseURL: baseUrl,
46
45
  headers: {
47
46
  "Content-Type": "application/json",
48
- "X-Client-ID": this.clientId,
49
- "X-Access-Token": this.accessToken
47
+ "x-api-key": this.apiKey
50
48
  }
51
49
  });
52
50
  }
53
- /**
54
- * Add a new product to inventory
55
- * @param product - Product details
56
- * @throws Error if required fields are missing or invalid
57
- */
58
51
  async addProduct(product) {
59
52
  this.validateAddProduct(product);
60
- await this.api.post("/sdk/add-order", {
61
- clientId: this.clientId,
62
- accessToken: this.accessToken,
63
- ...product
64
- });
53
+ await this.api.post("/api/sdk/add-product", product);
65
54
  }
66
- /**
67
- * Add a new order
68
- * @param order - Order details
69
- * @throws Error if required fields are missing or invalid
70
- */
71
55
  async addOrder(order) {
72
56
  this.validateAddOrder(order);
73
- await this.api.post("/sdk/add-order", {
74
- clientId: this.clientId,
75
- accessToken: this.accessToken,
76
- ...order
77
- });
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);
78
62
  }
79
- /**
80
- * Forward webhook payload to Discord
81
- * @param webhookUrl - Full webhook URL (e.g., https://www.lunartools.co/api/webhooks/{token})
82
- * @param payload - Discord webhook payload
83
- * @returns Response with status and queue length
84
- * @throws Error if payload is invalid
85
- */
86
63
  async webhook(webhookUrl, payload) {
87
64
  this.validateWebhookPayload(payload);
88
65
  const response = await import_axios.default.post(webhookUrl, payload, {
@@ -93,6 +70,9 @@ var Client = class {
93
70
  return response.data;
94
71
  }
95
72
  validateAddProduct(product) {
73
+ if (!product.token || product.token.trim() === "") {
74
+ throw new Error("User access token is required");
75
+ }
96
76
  if (!product.name || product.name.trim() === "") {
97
77
  throw new Error("Product name is required");
98
78
  }
@@ -113,6 +93,9 @@ var Client = class {
113
93
  }
114
94
  }
115
95
  validateAddOrder(order) {
96
+ if (!order.token || order.token.trim() === "") {
97
+ throw new Error("User access token is required");
98
+ }
116
99
  if (!order.name || order.name.trim() === "") {
117
100
  throw new Error("Order name is required");
118
101
  }
@@ -123,6 +106,33 @@ var Client = class {
123
106
  throw new Error("Order number is required");
124
107
  }
125
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
+ }
126
136
  validateWebhookPayload(payload) {
127
137
  if (!payload.content && (!payload.embeds || payload.embeds.length === 0)) {
128
138
  throw new Error("Webhook payload must contain either content or at least one embed");
package/dist/index.mjs CHANGED
@@ -2,51 +2,28 @@
2
2
  import axios from "axios";
3
3
  var Client = class {
4
4
  constructor(config) {
5
- this.clientId = config.clientId;
6
- this.accessToken = config.accessToken;
5
+ this.apiKey = config.apiKey;
7
6
  const baseUrl = config.baseUrl || "https://www.lunartools.co";
8
7
  this.api = axios.create({
9
8
  baseURL: baseUrl,
10
9
  headers: {
11
10
  "Content-Type": "application/json",
12
- "X-Client-ID": this.clientId,
13
- "X-Access-Token": this.accessToken
11
+ "x-api-key": this.apiKey
14
12
  }
15
13
  });
16
14
  }
17
- /**
18
- * Add a new product to inventory
19
- * @param product - Product details
20
- * @throws Error if required fields are missing or invalid
21
- */
22
15
  async addProduct(product) {
23
16
  this.validateAddProduct(product);
24
- await this.api.post("/sdk/add-order", {
25
- clientId: this.clientId,
26
- accessToken: this.accessToken,
27
- ...product
28
- });
17
+ await this.api.post("/api/sdk/add-product", product);
29
18
  }
30
- /**
31
- * Add a new order
32
- * @param order - Order details
33
- * @throws Error if required fields are missing or invalid
34
- */
35
19
  async addOrder(order) {
36
20
  this.validateAddOrder(order);
37
- await this.api.post("/sdk/add-order", {
38
- clientId: this.clientId,
39
- accessToken: this.accessToken,
40
- ...order
41
- });
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);
42
26
  }
43
- /**
44
- * Forward webhook payload to Discord
45
- * @param webhookUrl - Full webhook URL (e.g., https://www.lunartools.co/api/webhooks/{token})
46
- * @param payload - Discord webhook payload
47
- * @returns Response with status and queue length
48
- * @throws Error if payload is invalid
49
- */
50
27
  async webhook(webhookUrl, payload) {
51
28
  this.validateWebhookPayload(payload);
52
29
  const response = await axios.post(webhookUrl, payload, {
@@ -57,6 +34,9 @@ var Client = class {
57
34
  return response.data;
58
35
  }
59
36
  validateAddProduct(product) {
37
+ if (!product.token || product.token.trim() === "") {
38
+ throw new Error("User access token is required");
39
+ }
60
40
  if (!product.name || product.name.trim() === "") {
61
41
  throw new Error("Product name is required");
62
42
  }
@@ -77,6 +57,9 @@ var Client = class {
77
57
  }
78
58
  }
79
59
  validateAddOrder(order) {
60
+ if (!order.token || order.token.trim() === "") {
61
+ throw new Error("User access token is required");
62
+ }
80
63
  if (!order.name || order.name.trim() === "") {
81
64
  throw new Error("Order name is required");
82
65
  }
@@ -87,6 +70,33 @@ var Client = class {
87
70
  throw new Error("Order number is required");
88
71
  }
89
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
+ }
90
100
  validateWebhookPayload(payload) {
91
101
  if (!payload.content && (!payload.embeds || payload.embeds.length === 0)) {
92
102
  throw new Error("Webhook payload must contain either content or at least one embed");
package/package.json CHANGED
@@ -1,11 +1,11 @@
1
1
  {
2
2
  "name": "lunartools-sdk",
3
- "version": "1.0.2",
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": "UNLICENSED",
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": "^24.10.0",
38
+ "@types/node": "25.0.10",
39
39
  "tsup": "^8.0.0",
40
40
  "typescript": "^5.0.0"
41
41
  },