lunartools-sdk 1.0.0 → 1.0.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.mts +31 -1
- package/dist/index.d.ts +31 -1
- package/dist/index.js +137 -0
- package/dist/index.mjs +118 -0
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -69,4 +69,34 @@ interface AddOrder {
|
|
|
69
69
|
tags?: string;
|
|
70
70
|
}
|
|
71
71
|
|
|
72
|
-
|
|
72
|
+
declare class Client {
|
|
73
|
+
private clientId;
|
|
74
|
+
private accessToken;
|
|
75
|
+
private api;
|
|
76
|
+
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
|
+
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
|
+
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
|
+
*/
|
|
96
|
+
webhook(webhookUrl: string, payload: Webhook): Promise<WebhookResponse>;
|
|
97
|
+
private validateAddProduct;
|
|
98
|
+
private validateAddOrder;
|
|
99
|
+
private validateWebhookPayload;
|
|
100
|
+
}
|
|
101
|
+
|
|
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 };
|
package/dist/index.d.ts
CHANGED
|
@@ -69,4 +69,34 @@ interface AddOrder {
|
|
|
69
69
|
tags?: string;
|
|
70
70
|
}
|
|
71
71
|
|
|
72
|
-
|
|
72
|
+
declare class Client {
|
|
73
|
+
private clientId;
|
|
74
|
+
private accessToken;
|
|
75
|
+
private api;
|
|
76
|
+
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
|
+
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
|
+
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
|
+
*/
|
|
96
|
+
webhook(webhookUrl: string, payload: Webhook): Promise<WebhookResponse>;
|
|
97
|
+
private validateAddProduct;
|
|
98
|
+
private validateAddOrder;
|
|
99
|
+
private validateWebhookPayload;
|
|
100
|
+
}
|
|
101
|
+
|
|
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 };
|
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,139 @@ 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.clientId = config.clientId;
|
|
42
|
+
this.accessToken = config.accessToken;
|
|
43
|
+
const baseUrl = config.baseUrl || "https://www.lunartools.co";
|
|
44
|
+
this.api = import_axios.default.create({
|
|
45
|
+
baseURL: baseUrl,
|
|
46
|
+
headers: {
|
|
47
|
+
"Content-Type": "application/json",
|
|
48
|
+
"X-Client-ID": this.clientId,
|
|
49
|
+
"X-Access-Token": this.accessToken
|
|
50
|
+
}
|
|
51
|
+
});
|
|
52
|
+
}
|
|
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
|
+
async addProduct(product) {
|
|
59
|
+
this.validateAddProduct(product);
|
|
60
|
+
await this.api.post("/sdk/add-order", {
|
|
61
|
+
clientId: this.clientId,
|
|
62
|
+
accessToken: this.accessToken,
|
|
63
|
+
...product
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Add a new order
|
|
68
|
+
* @param order - Order details
|
|
69
|
+
* @throws Error if required fields are missing or invalid
|
|
70
|
+
*/
|
|
71
|
+
async addOrder(order) {
|
|
72
|
+
this.validateAddOrder(order);
|
|
73
|
+
await this.api.post("/sdk/add-order", {
|
|
74
|
+
clientId: this.clientId,
|
|
75
|
+
accessToken: this.accessToken,
|
|
76
|
+
...order
|
|
77
|
+
});
|
|
78
|
+
}
|
|
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
|
+
async webhook(webhookUrl, payload) {
|
|
87
|
+
this.validateWebhookPayload(payload);
|
|
88
|
+
const response = await import_axios.default.post(webhookUrl, payload, {
|
|
89
|
+
headers: {
|
|
90
|
+
"Content-Type": "application/json"
|
|
91
|
+
}
|
|
92
|
+
});
|
|
93
|
+
return response.data;
|
|
94
|
+
}
|
|
95
|
+
validateAddProduct(product) {
|
|
96
|
+
if (!product.name || product.name.trim() === "") {
|
|
97
|
+
throw new Error("Product name is required");
|
|
98
|
+
}
|
|
99
|
+
if (!product.sku || product.sku.trim() === "") {
|
|
100
|
+
throw new Error("Product SKU is required");
|
|
101
|
+
}
|
|
102
|
+
if (product.qty === void 0 || product.qty === null) {
|
|
103
|
+
throw new Error("Product quantity is required");
|
|
104
|
+
}
|
|
105
|
+
if (typeof product.qty !== "number" || product.qty < 0) {
|
|
106
|
+
throw new Error("Product quantity must be a non-negative number");
|
|
107
|
+
}
|
|
108
|
+
if (product.value !== void 0 && (typeof product.value !== "number" || product.value < 0)) {
|
|
109
|
+
throw new Error("Product value must be a non-negative number");
|
|
110
|
+
}
|
|
111
|
+
if (product.spent !== void 0 && (typeof product.spent !== "number" || product.spent < 0)) {
|
|
112
|
+
throw new Error("Product spent must be a non-negative number");
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
validateAddOrder(order) {
|
|
116
|
+
if (!order.name || order.name.trim() === "") {
|
|
117
|
+
throw new Error("Order name is required");
|
|
118
|
+
}
|
|
119
|
+
if (!order.status || order.status.trim() === "") {
|
|
120
|
+
throw new Error("Order status is required");
|
|
121
|
+
}
|
|
122
|
+
if (!order.orderNumber || order.orderNumber.trim() === "") {
|
|
123
|
+
throw new Error("Order number is required");
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
validateWebhookPayload(payload) {
|
|
127
|
+
if (!payload.content && (!payload.embeds || payload.embeds.length === 0)) {
|
|
128
|
+
throw new Error("Webhook payload must contain either content or at least one embed");
|
|
129
|
+
}
|
|
130
|
+
if (payload.embeds && payload.embeds.length > 10) {
|
|
131
|
+
throw new Error("Discord webhooks support a maximum of 10 embeds");
|
|
132
|
+
}
|
|
133
|
+
if (payload.embeds) {
|
|
134
|
+
payload.embeds.forEach((embed, index) => {
|
|
135
|
+
if (embed.fields && embed.fields.length > 25) {
|
|
136
|
+
throw new Error(`Embed ${index} exceeds the maximum of 25 fields`);
|
|
137
|
+
}
|
|
138
|
+
if (embed.fields) {
|
|
139
|
+
embed.fields.forEach((field, fieldIndex) => {
|
|
140
|
+
if (!field.name || field.name.trim() === "") {
|
|
141
|
+
throw new Error(`Embed ${index}, field ${fieldIndex}: name is required`);
|
|
142
|
+
}
|
|
143
|
+
if (!field.value || field.value.trim() === "") {
|
|
144
|
+
throw new Error(`Embed ${index}, field ${fieldIndex}: value is required`);
|
|
145
|
+
}
|
|
146
|
+
});
|
|
147
|
+
}
|
|
148
|
+
});
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
};
|
|
152
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
153
|
+
0 && (module.exports = {
|
|
154
|
+
Client
|
|
155
|
+
});
|
package/dist/index.mjs
CHANGED
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
// src/client/client.ts
|
|
2
|
+
import axios from "axios";
|
|
3
|
+
var Client = class {
|
|
4
|
+
constructor(config) {
|
|
5
|
+
this.clientId = config.clientId;
|
|
6
|
+
this.accessToken = config.accessToken;
|
|
7
|
+
const baseUrl = config.baseUrl || "https://www.lunartools.co";
|
|
8
|
+
this.api = axios.create({
|
|
9
|
+
baseURL: baseUrl,
|
|
10
|
+
headers: {
|
|
11
|
+
"Content-Type": "application/json",
|
|
12
|
+
"X-Client-ID": this.clientId,
|
|
13
|
+
"X-Access-Token": this.accessToken
|
|
14
|
+
}
|
|
15
|
+
});
|
|
16
|
+
}
|
|
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
|
+
async addProduct(product) {
|
|
23
|
+
this.validateAddProduct(product);
|
|
24
|
+
await this.api.post("/sdk/add-order", {
|
|
25
|
+
clientId: this.clientId,
|
|
26
|
+
accessToken: this.accessToken,
|
|
27
|
+
...product
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Add a new order
|
|
32
|
+
* @param order - Order details
|
|
33
|
+
* @throws Error if required fields are missing or invalid
|
|
34
|
+
*/
|
|
35
|
+
async addOrder(order) {
|
|
36
|
+
this.validateAddOrder(order);
|
|
37
|
+
await this.api.post("/sdk/add-order", {
|
|
38
|
+
clientId: this.clientId,
|
|
39
|
+
accessToken: this.accessToken,
|
|
40
|
+
...order
|
|
41
|
+
});
|
|
42
|
+
}
|
|
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
|
+
async webhook(webhookUrl, payload) {
|
|
51
|
+
this.validateWebhookPayload(payload);
|
|
52
|
+
const response = await axios.post(webhookUrl, payload, {
|
|
53
|
+
headers: {
|
|
54
|
+
"Content-Type": "application/json"
|
|
55
|
+
}
|
|
56
|
+
});
|
|
57
|
+
return response.data;
|
|
58
|
+
}
|
|
59
|
+
validateAddProduct(product) {
|
|
60
|
+
if (!product.name || product.name.trim() === "") {
|
|
61
|
+
throw new Error("Product name is required");
|
|
62
|
+
}
|
|
63
|
+
if (!product.sku || product.sku.trim() === "") {
|
|
64
|
+
throw new Error("Product SKU is required");
|
|
65
|
+
}
|
|
66
|
+
if (product.qty === void 0 || product.qty === null) {
|
|
67
|
+
throw new Error("Product quantity is required");
|
|
68
|
+
}
|
|
69
|
+
if (typeof product.qty !== "number" || product.qty < 0) {
|
|
70
|
+
throw new Error("Product quantity must be a non-negative number");
|
|
71
|
+
}
|
|
72
|
+
if (product.value !== void 0 && (typeof product.value !== "number" || product.value < 0)) {
|
|
73
|
+
throw new Error("Product value must be a non-negative number");
|
|
74
|
+
}
|
|
75
|
+
if (product.spent !== void 0 && (typeof product.spent !== "number" || product.spent < 0)) {
|
|
76
|
+
throw new Error("Product spent must be a non-negative number");
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
validateAddOrder(order) {
|
|
80
|
+
if (!order.name || order.name.trim() === "") {
|
|
81
|
+
throw new Error("Order name is required");
|
|
82
|
+
}
|
|
83
|
+
if (!order.status || order.status.trim() === "") {
|
|
84
|
+
throw new Error("Order status is required");
|
|
85
|
+
}
|
|
86
|
+
if (!order.orderNumber || order.orderNumber.trim() === "") {
|
|
87
|
+
throw new Error("Order number is required");
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
validateWebhookPayload(payload) {
|
|
91
|
+
if (!payload.content && (!payload.embeds || payload.embeds.length === 0)) {
|
|
92
|
+
throw new Error("Webhook payload must contain either content or at least one embed");
|
|
93
|
+
}
|
|
94
|
+
if (payload.embeds && payload.embeds.length > 10) {
|
|
95
|
+
throw new Error("Discord webhooks support a maximum of 10 embeds");
|
|
96
|
+
}
|
|
97
|
+
if (payload.embeds) {
|
|
98
|
+
payload.embeds.forEach((embed, index) => {
|
|
99
|
+
if (embed.fields && embed.fields.length > 25) {
|
|
100
|
+
throw new Error(`Embed ${index} exceeds the maximum of 25 fields`);
|
|
101
|
+
}
|
|
102
|
+
if (embed.fields) {
|
|
103
|
+
embed.fields.forEach((field, fieldIndex) => {
|
|
104
|
+
if (!field.name || field.name.trim() === "") {
|
|
105
|
+
throw new Error(`Embed ${index}, field ${fieldIndex}: name is required`);
|
|
106
|
+
}
|
|
107
|
+
if (!field.value || field.value.trim() === "") {
|
|
108
|
+
throw new Error(`Embed ${index}, field ${fieldIndex}: value is required`);
|
|
109
|
+
}
|
|
110
|
+
});
|
|
111
|
+
}
|
|
112
|
+
});
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
};
|
|
116
|
+
export {
|
|
117
|
+
Client
|
|
118
|
+
};
|