@kash-88/alerts 1.2.1 → 1.3.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/dist/src/Function/createCustomAlerts.d.ts +16 -0
- package/dist/src/Function/createCustomAlerts.js +51 -0
- package/dist/src/Function/createMerchandise.d.ts +22 -0
- package/dist/src/Function/createMerchandise.js +82 -0
- package/dist/src/Function/generateSignature.d.ts +13 -0
- package/dist/src/Function/generateSignature.js +18 -0
- package/dist/src/Function/getAuthorizeLink.d.ts +13 -0
- package/dist/src/Function/getAuthorizeLink.js +27 -0
- package/dist/src/Function/getDonationsAlerts.d.ts +11 -0
- package/dist/src/Function/getDonationsAlerts.js +30 -0
- package/dist/src/Function/getExternal.d.ts +6 -0
- package/dist/src/Function/getExternal.js +27 -0
- package/dist/src/Function/getOauthToken.d.ts +13 -0
- package/dist/src/Function/getOauthToken.js +44 -0
- package/dist/src/Function/getPrivateToken.d.ts +10 -0
- package/dist/src/Function/getPrivateToken.js +40 -0
- package/dist/src/Function/getUser.d.ts +10 -0
- package/dist/src/Function/getUser.js +26 -0
- package/dist/src/Function/getUserChannel.d.ts +8 -0
- package/dist/src/Function/getUserChannel.js +13 -0
- package/dist/src/Function/getUserDataFromPromocode.d.ts +11 -0
- package/dist/src/Function/getUserDataFromPromocode.js +39 -0
- package/dist/src/Function/sendSaleAlert.d.ts +20 -0
- package/dist/src/Function/sendSaleAlert.js +81 -0
- package/dist/src/Function/updateMerchandise.d.ts +21 -0
- package/dist/src/Function/updateMerchandise.js +76 -0
- package/dist/src/Function/updateOauthToken.d.ts +13 -0
- package/dist/src/Function/updateOauthToken.js +44 -0
- package/dist/src/Function/updateOrCreateMerchandise.d.ts +22 -0
- package/dist/src/Function/updateOrCreateMerchandise.js +80 -0
- package/dist/src/Types/CustomAlerts.d.ts +12 -0
- package/dist/src/Types/DonationsAlerts.d.ts +31 -0
- package/dist/src/Types/DonationsAlerts.js +1 -0
- package/dist/src/Types/Merchandise.d.ts +18 -0
- package/dist/src/Types/Merchandise.js +1 -0
- package/dist/src/Types/MerchandiseSale.d.ts +14 -0
- package/dist/src/Types/MerchandiseSale.js +1 -0
- package/dist/src/Types/OAuthScope.d.ts +9 -0
- package/dist/src/Types/OAuthScope.js +10 -0
- package/dist/src/Types/OAuthToken.d.ts +7 -0
- package/dist/src/Types/OAuthToken.js +1 -0
- package/dist/src/Types/User.d.ts +9 -0
- package/dist/src/Types/User.js +1 -0
- package/dist/src/Types/index.d.ts +8 -0
- package/dist/src/Types/index.js +2 -0
- package/dist/src/WebSocket/CentrifugeClient.d.ts +71 -0
- package/dist/src/WebSocket/CentrifugeClient.js +216 -0
- package/dist/src/index.d.ts +18 -9
- package/dist/src/index.js +18 -9
- package/dist/src/utils.d.ts +5 -13
- package/dist/src/utils.js +16 -32
- package/package.json +22 -18
- package/readme.md +502 -81
- package/src/Function/createCustomAlerts.ts +65 -0
- package/src/Function/createMerchandise.ts +105 -0
- package/src/Function/generateSignature.ts +23 -0
- package/src/Function/getAuthorizeLink.ts +37 -0
- package/src/Function/getDonationsAlerts.ts +37 -0
- package/src/Function/getExternal.ts +31 -0
- package/src/Function/getOauthToken.ts +54 -0
- package/src/Function/getPrivateToken.ts +50 -0
- package/src/Function/getUser.ts +32 -0
- package/src/Function/getUserChannel.ts +17 -0
- package/src/Function/getUserDataFromPromocode.ts +51 -0
- package/src/Function/sendSaleAlert.ts +103 -0
- package/src/Function/updateMerchandise.ts +98 -0
- package/src/Function/updateOauthToken.ts +54 -0
- package/src/Function/updateOrCreateMerchandise.ts +103 -0
- package/src/Types/CustomAlerts.ts +13 -0
- package/src/Types/DonationsAlerts.ts +32 -0
- package/src/Types/Merchandise.ts +19 -0
- package/src/Types/MerchandiseSale.ts +15 -0
- package/src/Types/OAuthScope.ts +10 -0
- package/src/Types/OAuthToken.ts +8 -0
- package/src/Types/User.ts +10 -0
- package/src/Types/index.ts +17 -0
- package/src/WebSocket/CentrifugeClient.ts +271 -0
- package/src/index.ts +25 -6
- package/src/utils.ts +22 -44
- package/dist/src/func/getAuthorizeLink.d.ts +0 -18
- package/dist/src/func/getAuthorizeLink.js +0 -29
- package/dist/src/func/getOauthToken.d.ts +0 -27
- package/dist/src/func/getOauthToken.js +0 -42
- package/dist/src/func/getPrivateToken.d.ts +0 -29
- package/dist/src/func/getPrivateToken.js +0 -46
- package/dist/src/func/getUser.d.ts +0 -23
- package/dist/src/func/getUser.js +0 -38
- package/dist/src/func/getUserChannel.d.ts +0 -19
- package/dist/src/func/getUserChannel.js +0 -32
- package/dist/src/func/updateAccessToken.d.ts +0 -24
- package/dist/src/func/updateAccessToken.js +0 -39
- package/dist/src/types.d.ts +0 -33
- package/dist/src/ws/CentrifugeClient.d.ts +0 -31
- package/dist/src/ws/CentrifugeClient.js +0 -71
- package/src/example/getAuthorizeLink.ts +0 -11
- package/src/example/getOauthToken.ts +0 -16
- package/src/example/getUser.ts +0 -12
- package/src/example/getUserChannel.ts +0 -10
- package/src/example/updateAccessToken.ts +0 -17
- package/src/example/wsExample.ts +0 -50
- package/src/func/getAuthorizeLink.ts +0 -33
- package/src/func/getOauthToken.ts +0 -46
- package/src/func/getPrivateToken.ts +0 -53
- package/src/func/getUser.ts +0 -42
- package/src/func/getUserChannel.ts +0 -34
- package/src/func/updateAccessToken.ts +0 -43
- package/src/types.ts +0 -38
- package/src/ws/CentrifugeClient.ts +0 -108
- /package/dist/src/{types.js → Types/CustomAlerts.js} +0 -0
|
@@ -0,0 +1,216 @@
|
|
|
1
|
+
import getPrivateToken from "../Function/getPrivateToken.js";
|
|
2
|
+
import getUser from "../Function/getUser.js";
|
|
3
|
+
import getUserChannel from "../Function/getUserChannel.js";
|
|
4
|
+
import { formatAxiosError } from "../utils.js";
|
|
5
|
+
import { WebSocket } from "ws";
|
|
6
|
+
import { EventEmitter } from "events";
|
|
7
|
+
/**
|
|
8
|
+
* Class for interacting with Centrifuge donationalerts
|
|
9
|
+
*
|
|
10
|
+
* @param {WSClientOptions} options - Connection options
|
|
11
|
+
* @param {string} options.access_token - User access token
|
|
12
|
+
* @param {string[]} [options.channels] - Custom channels to subscribe to (defaults to donation channel)
|
|
13
|
+
* @param {boolean} [options.autoReconnect=false] - Automatically reconnect on connection close
|
|
14
|
+
*/
|
|
15
|
+
export default class CentrifugeClient extends EventEmitter {
|
|
16
|
+
constructor(options) {
|
|
17
|
+
super();
|
|
18
|
+
this.access_token = options.access_token;
|
|
19
|
+
this.channels = options.channels ?? [];
|
|
20
|
+
this.autoReconnect = options.autoReconnect ?? false;
|
|
21
|
+
this.isAuthorized = false;
|
|
22
|
+
this.reconnectTimer = null;
|
|
23
|
+
this.isReconnecting = false;
|
|
24
|
+
this.authMessageHandler = null;
|
|
25
|
+
this.WebSocket = null;
|
|
26
|
+
this.user = null;
|
|
27
|
+
this.userPromise = this.getUser(this.access_token).catch((error) => {
|
|
28
|
+
this.emit("error", error);
|
|
29
|
+
throw error;
|
|
30
|
+
});
|
|
31
|
+
this.createNewConnection();
|
|
32
|
+
this.setupEvent();
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Obtain user data
|
|
36
|
+
*
|
|
37
|
+
* @param {string} access_token - User access token
|
|
38
|
+
* @returns {Promise<User>} User data
|
|
39
|
+
*/
|
|
40
|
+
async getUser(access_token) {
|
|
41
|
+
try {
|
|
42
|
+
this.user = await getUser(access_token);
|
|
43
|
+
return this.user;
|
|
44
|
+
}
|
|
45
|
+
catch (error) {
|
|
46
|
+
throw new Error(formatAxiosError(error));
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Get channels to subscribe to
|
|
51
|
+
*
|
|
52
|
+
* @returns {Promise<string[]>} Array of channel identifiers
|
|
53
|
+
*/
|
|
54
|
+
async getChannels() {
|
|
55
|
+
if (!this.user?.id)
|
|
56
|
+
this.user = await (this.userPromise ?? this.getUser(this.access_token));
|
|
57
|
+
if (!this.user?.id)
|
|
58
|
+
throw new Error("Failed to get channels due to missing user ID");
|
|
59
|
+
if (this.channels.length > 0)
|
|
60
|
+
return this.channels;
|
|
61
|
+
return [getUserChannel(this.user.id)];
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Create a new WebSocket connection
|
|
65
|
+
*/
|
|
66
|
+
createNewConnection() {
|
|
67
|
+
try {
|
|
68
|
+
if (this.WebSocket)
|
|
69
|
+
return;
|
|
70
|
+
this.WebSocket = new WebSocket("wss://centrifugo.donationalerts.com/connection/websocket");
|
|
71
|
+
}
|
|
72
|
+
catch (error) {
|
|
73
|
+
throw new Error(error?.message || error);
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Forward events through a TypedEmitter
|
|
78
|
+
*/
|
|
79
|
+
setupEvent() {
|
|
80
|
+
if (!this.WebSocket) {
|
|
81
|
+
this.createNewConnection();
|
|
82
|
+
if (!this.WebSocket)
|
|
83
|
+
throw new Error("WebSocket connection failed");
|
|
84
|
+
}
|
|
85
|
+
const ws = this.WebSocket;
|
|
86
|
+
ws.on('open', () => {
|
|
87
|
+
this.emit("open");
|
|
88
|
+
});
|
|
89
|
+
ws.on('close', (code, reason) => {
|
|
90
|
+
this.isAuthorized = false;
|
|
91
|
+
this.emit("close", code, reason);
|
|
92
|
+
if (this.autoReconnect) {
|
|
93
|
+
this.WebSocket = null;
|
|
94
|
+
if (this.reconnectTimer)
|
|
95
|
+
clearTimeout(this.reconnectTimer);
|
|
96
|
+
this.isReconnecting = true;
|
|
97
|
+
this.reconnectTimer = setTimeout(() => {
|
|
98
|
+
this.isReconnecting = false;
|
|
99
|
+
this.createNewConnection();
|
|
100
|
+
this.setupEvent();
|
|
101
|
+
this.emit("reconnect");
|
|
102
|
+
}, 5000);
|
|
103
|
+
}
|
|
104
|
+
});
|
|
105
|
+
ws.on('message', (rawMessage) => {
|
|
106
|
+
try {
|
|
107
|
+
const message = JSON.parse(rawMessage.toString());
|
|
108
|
+
this.emit("message", message);
|
|
109
|
+
}
|
|
110
|
+
catch (error) {
|
|
111
|
+
this.emit("error", new Error(`Failed to parse WebSocket message: ${error?.message || error}`));
|
|
112
|
+
}
|
|
113
|
+
});
|
|
114
|
+
ws.on('error', (error) => {
|
|
115
|
+
this.emit("error", error);
|
|
116
|
+
});
|
|
117
|
+
}
|
|
118
|
+
/**
|
|
119
|
+
* Authorize WebSocket and subscribe to selected channels
|
|
120
|
+
*/
|
|
121
|
+
async authorization() {
|
|
122
|
+
if (this.isReconnecting) {
|
|
123
|
+
throw new Error("Reconnection is in progress, please wait for the 'reconnect' event");
|
|
124
|
+
}
|
|
125
|
+
if (!this.WebSocket)
|
|
126
|
+
this.createNewConnection();
|
|
127
|
+
if (!this.WebSocket)
|
|
128
|
+
throw new Error("WebSocket connection failed");
|
|
129
|
+
if (this.WebSocket.readyState !== WebSocket.OPEN) {
|
|
130
|
+
throw new Error("WebSocket connection is not open. Call authorization() after the 'open' event");
|
|
131
|
+
}
|
|
132
|
+
if (!this.user)
|
|
133
|
+
this.user = await (this.userPromise ?? this.getUser(this.access_token));
|
|
134
|
+
if (!this.user?.socket_connection_token)
|
|
135
|
+
throw new Error("Failed to log in due to receiving socket connection token");
|
|
136
|
+
if (this.authMessageHandler) {
|
|
137
|
+
this.WebSocket?.removeListener('message', this.authMessageHandler);
|
|
138
|
+
}
|
|
139
|
+
const handleAuthResponse = async (rawMessage) => {
|
|
140
|
+
try {
|
|
141
|
+
const json = JSON.parse(rawMessage.toString());
|
|
142
|
+
if (json.id === 1) {
|
|
143
|
+
this.authMessageHandler = null;
|
|
144
|
+
this.WebSocket?.removeListener('message', handleAuthResponse);
|
|
145
|
+
if (!json.result?.client) {
|
|
146
|
+
this.emit("error", new Error("Authorization failed: missing client ID in response"));
|
|
147
|
+
return;
|
|
148
|
+
}
|
|
149
|
+
const channels = await this.getChannels();
|
|
150
|
+
for (let i = 0; i < channels.length; i++) {
|
|
151
|
+
const channel = channels[i];
|
|
152
|
+
const privateToken = await getPrivateToken(channel, json.result.client, this.access_token);
|
|
153
|
+
this.sendMessage(JSON.stringify({
|
|
154
|
+
id: 2 + i,
|
|
155
|
+
method: 1,
|
|
156
|
+
params: {
|
|
157
|
+
channel,
|
|
158
|
+
token: privateToken
|
|
159
|
+
}
|
|
160
|
+
}));
|
|
161
|
+
}
|
|
162
|
+
this.isAuthorized = true;
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
catch (error) {
|
|
166
|
+
this.authMessageHandler = null;
|
|
167
|
+
this.WebSocket?.removeListener('message', handleAuthResponse);
|
|
168
|
+
this.emit("error", new Error(`Authorization failed: ${error?.message || error}`));
|
|
169
|
+
}
|
|
170
|
+
};
|
|
171
|
+
this.authMessageHandler = handleAuthResponse;
|
|
172
|
+
this.WebSocket.on('message', handleAuthResponse);
|
|
173
|
+
this.sendMessage(JSON.stringify({
|
|
174
|
+
params: {
|
|
175
|
+
token: this.user.socket_connection_token
|
|
176
|
+
},
|
|
177
|
+
id: 1
|
|
178
|
+
}));
|
|
179
|
+
}
|
|
180
|
+
/**
|
|
181
|
+
* Send a message through the WebSocket connection
|
|
182
|
+
*
|
|
183
|
+
* @param {string} message - JSON-encoded message to send
|
|
184
|
+
*/
|
|
185
|
+
sendMessage(message) {
|
|
186
|
+
try {
|
|
187
|
+
if (!this.WebSocket)
|
|
188
|
+
return;
|
|
189
|
+
if (this.WebSocket.readyState !== WebSocket.OPEN)
|
|
190
|
+
return;
|
|
191
|
+
this.WebSocket.send(message);
|
|
192
|
+
}
|
|
193
|
+
catch (error) {
|
|
194
|
+
throw new Error(error?.message || error);
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
/**
|
|
198
|
+
* Close the WebSocket connection and stop auto-reconnect
|
|
199
|
+
*/
|
|
200
|
+
close() {
|
|
201
|
+
this.autoReconnect = false;
|
|
202
|
+
if (this.reconnectTimer) {
|
|
203
|
+
clearTimeout(this.reconnectTimer);
|
|
204
|
+
this.reconnectTimer = null;
|
|
205
|
+
}
|
|
206
|
+
if (this.WebSocket) {
|
|
207
|
+
if (this.authMessageHandler) {
|
|
208
|
+
this.WebSocket.removeListener('message', this.authMessageHandler);
|
|
209
|
+
this.authMessageHandler = null;
|
|
210
|
+
}
|
|
211
|
+
this.WebSocket.close();
|
|
212
|
+
this.WebSocket = null;
|
|
213
|
+
}
|
|
214
|
+
this.isAuthorized = false;
|
|
215
|
+
}
|
|
216
|
+
}
|
package/dist/src/index.d.ts
CHANGED
|
@@ -1,9 +1,18 @@
|
|
|
1
|
-
import getAuthorizeLink from "./
|
|
2
|
-
import getOauthToken from "./
|
|
3
|
-
import getUser from "./
|
|
4
|
-
import
|
|
5
|
-
import getUserChannel from "./
|
|
6
|
-
import
|
|
7
|
-
import
|
|
8
|
-
|
|
9
|
-
|
|
1
|
+
import getAuthorizeLink from "./Function/getAuthorizeLink.js";
|
|
2
|
+
import getOauthToken from "./Function/getOauthToken.js";
|
|
3
|
+
import getUser from "./Function/getUser.js";
|
|
4
|
+
import updateOauthToken from "./Function/updateOauthToken.js";
|
|
5
|
+
import getUserChannel from "./Function/getUserChannel.js";
|
|
6
|
+
import getPrivateToken from "./Function/getPrivateToken.js";
|
|
7
|
+
import getDonationsAlerts from "./Function/getDonationsAlerts.js";
|
|
8
|
+
import getExternal from "./Function/getExternal.js";
|
|
9
|
+
import createCustomAlerts from "./Function/createCustomAlerts.js";
|
|
10
|
+
import generateSignature from "./Function/generateSignature.js";
|
|
11
|
+
import createMerchandise from "./Function/createMerchandise.js";
|
|
12
|
+
import updateMerchandise from "./Function/updateMerchandise.js";
|
|
13
|
+
import updateOrCreateMerchandise from "./Function/updateOrCreateMerchandise.js";
|
|
14
|
+
import getUserDataFromPromocode from "./Function/getUserDataFromPromocode.js";
|
|
15
|
+
import sendSaleAlert from "./Function/sendSaleAlert.js";
|
|
16
|
+
import WebServer from "./WebSocket/CentrifugeClient.js";
|
|
17
|
+
import { OAuthScope } from "./Types/index.js";
|
|
18
|
+
export { getAuthorizeLink, getOauthToken, getUser, updateOauthToken, getUserChannel, getExternal, getPrivateToken, getDonationsAlerts, createCustomAlerts, generateSignature, createMerchandise, updateMerchandise, updateOrCreateMerchandise, getUserDataFromPromocode, sendSaleAlert, WebServer, OAuthScope };
|
package/dist/src/index.js
CHANGED
|
@@ -1,9 +1,18 @@
|
|
|
1
|
-
import getAuthorizeLink from "./
|
|
2
|
-
import getOauthToken from "./
|
|
3
|
-
import getUser from "./
|
|
4
|
-
import
|
|
5
|
-
import getUserChannel from "./
|
|
6
|
-
import
|
|
7
|
-
import
|
|
8
|
-
|
|
9
|
-
|
|
1
|
+
import getAuthorizeLink from "./Function/getAuthorizeLink.js";
|
|
2
|
+
import getOauthToken from "./Function/getOauthToken.js";
|
|
3
|
+
import getUser from "./Function/getUser.js";
|
|
4
|
+
import updateOauthToken from "./Function/updateOauthToken.js";
|
|
5
|
+
import getUserChannel from "./Function/getUserChannel.js";
|
|
6
|
+
import getPrivateToken from "./Function/getPrivateToken.js";
|
|
7
|
+
import getDonationsAlerts from "./Function/getDonationsAlerts.js";
|
|
8
|
+
import getExternal from "./Function/getExternal.js";
|
|
9
|
+
import createCustomAlerts from "./Function/createCustomAlerts.js";
|
|
10
|
+
import generateSignature from "./Function/generateSignature.js";
|
|
11
|
+
import createMerchandise from "./Function/createMerchandise.js";
|
|
12
|
+
import updateMerchandise from "./Function/updateMerchandise.js";
|
|
13
|
+
import updateOrCreateMerchandise from "./Function/updateOrCreateMerchandise.js";
|
|
14
|
+
import getUserDataFromPromocode from "./Function/getUserDataFromPromocode.js";
|
|
15
|
+
import sendSaleAlert from "./Function/sendSaleAlert.js";
|
|
16
|
+
import WebServer from "./WebSocket/CentrifugeClient.js";
|
|
17
|
+
import { OAuthScope } from "./Types/index.js";
|
|
18
|
+
export { getAuthorizeLink, getOauthToken, getUser, updateOauthToken, getUserChannel, getExternal, getPrivateToken, getDonationsAlerts, createCustomAlerts, generateSignature, createMerchandise, updateMerchandise, updateOrCreateMerchandise, getUserDataFromPromocode, sendSaleAlert, WebServer, OAuthScope };
|
package/dist/src/utils.d.ts
CHANGED
|
@@ -1,15 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
3
|
-
*
|
|
4
|
-
* @
|
|
5
|
-
* @
|
|
2
|
+
* Format an axios error into a readable error message.
|
|
3
|
+
*
|
|
4
|
+
* @param {any} error - The error thrown by axios or any other source
|
|
5
|
+
* @returns {string} A formatted error message
|
|
6
6
|
*/
|
|
7
|
-
|
|
8
|
-
* Validates that the provided data is an object and contains the required keys.
|
|
9
|
-
* For each required key, it also validates that the value is a string or a number.
|
|
10
|
-
* @param {unknown} data - The data object to validate.
|
|
11
|
-
* @param {string[]} requiredKeys - An array of keys that must be present in the data object.
|
|
12
|
-
* @throws {Error} If validation fails.
|
|
13
|
-
* @private
|
|
14
|
-
*/
|
|
15
|
-
export declare function validateDataObject(data: unknown, requiredKeys: string[]): asserts data is Record<string, string | number | string[]>;
|
|
7
|
+
export declare function formatAxiosError(error: any): string;
|
package/dist/src/utils.js
CHANGED
|
@@ -1,37 +1,21 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
3
|
-
*
|
|
4
|
-
* @
|
|
5
|
-
* @
|
|
2
|
+
* Format an axios error into a readable error message.
|
|
3
|
+
*
|
|
4
|
+
* @param {any} error - The error thrown by axios or any other source
|
|
5
|
+
* @returns {string} A formatted error message
|
|
6
6
|
*/
|
|
7
|
-
function
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
* @private
|
|
17
|
-
*/
|
|
18
|
-
export function validateDataObject(data, requiredKeys) {
|
|
19
|
-
if (!isObject(data)) {
|
|
20
|
-
throw new Error("You must provide data as an object.");
|
|
7
|
+
export function formatAxiosError(error) {
|
|
8
|
+
if (error?.response?.data?.error_description) {
|
|
9
|
+
return error.response.data.error_description;
|
|
10
|
+
}
|
|
11
|
+
if (error?.response?.data?.message) {
|
|
12
|
+
return error.response.data.message;
|
|
13
|
+
}
|
|
14
|
+
if (error?.response?.data?.error) {
|
|
15
|
+
return error.response.data.error;
|
|
21
16
|
}
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
throw new Error(`You must provide "${key}" in the data object.`);
|
|
25
|
-
}
|
|
26
|
-
const value = data[key];
|
|
27
|
-
if (key === "scope") {
|
|
28
|
-
if (!Array.isArray(value)) {
|
|
29
|
-
throw new Error(`"${key}" must be an array of strings.`);
|
|
30
|
-
}
|
|
31
|
-
continue;
|
|
32
|
-
}
|
|
33
|
-
if (typeof value !== "string" && typeof value !== "number") {
|
|
34
|
-
throw new Error(`"${key}" must be a string or a number.`);
|
|
35
|
-
}
|
|
17
|
+
if (error?.message) {
|
|
18
|
+
return error.message;
|
|
36
19
|
}
|
|
20
|
+
return String(error);
|
|
37
21
|
}
|
package/package.json
CHANGED
|
@@ -1,47 +1,50 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kash-88/alerts",
|
|
3
|
-
"version": "1.
|
|
4
|
-
"description": "A
|
|
3
|
+
"version": "1.3.0",
|
|
4
|
+
"description": "A library for seamless integration with the DonationAlerts API. It provides a comprehensive set of tools for authorization, user token management, retrieving account data, and handling various other API interactions.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"keywords": [
|
|
7
7
|
"DonationAlerts",
|
|
8
8
|
"DonationAlerts API",
|
|
9
|
-
"DonationAlerts SDK"
|
|
9
|
+
"DonationAlerts SDK",
|
|
10
|
+
"DonationAlerts WebSocket",
|
|
11
|
+
"DA API",
|
|
12
|
+
"DA SDK",
|
|
13
|
+
"DA WebSocket"
|
|
10
14
|
],
|
|
11
15
|
"publishConfig": {
|
|
12
16
|
"registry": "https://npm.pkg.github.com/",
|
|
13
17
|
"access": "public"
|
|
14
18
|
},
|
|
15
|
-
"homepage": "https://github.com/kash-
|
|
19
|
+
"homepage": "https://github.com/kash-ts/alerts-SDK#readme",
|
|
16
20
|
"bugs": {
|
|
17
|
-
"url": "https://github.com/kash-
|
|
21
|
+
"url": "https://github.com/kash-ts/alerts-SDK/issues"
|
|
18
22
|
},
|
|
19
23
|
"main": "dist/src/index.js",
|
|
20
24
|
"types": "dist/src/index.d.ts",
|
|
21
25
|
"exports": {
|
|
22
26
|
".": {
|
|
23
|
-
"
|
|
24
|
-
"
|
|
27
|
+
"types": "./dist/src/index.d.ts",
|
|
28
|
+
"import": "./dist/src/index.js"
|
|
25
29
|
}
|
|
26
30
|
},
|
|
27
31
|
"files": [
|
|
28
32
|
"dist",
|
|
29
|
-
"src"
|
|
30
|
-
"ws"
|
|
33
|
+
"src"
|
|
31
34
|
],
|
|
32
35
|
"repository": {
|
|
33
36
|
"type": "git",
|
|
34
|
-
"url": "git+https://github.com/kash-
|
|
37
|
+
"url": "git+https://github.com/kash-ts/alerts-SDK.git"
|
|
35
38
|
},
|
|
36
|
-
"license": "
|
|
37
|
-
"author": "kash
|
|
39
|
+
"license": "MIT",
|
|
40
|
+
"author": "kash-ts",
|
|
38
41
|
"scripts": {
|
|
39
42
|
"publish:github": "npm publish",
|
|
40
43
|
"build": "tsc && tsc-alias",
|
|
41
44
|
"prepublishOnly": "npm run build",
|
|
42
|
-
"publish:npm-
|
|
43
|
-
"publish:npm-dev": "npm publish
|
|
44
|
-
"publish:npm-beta": "npm publish
|
|
45
|
+
"publish:npm-latest": "npm publish --@kash-88:registry=https://registry.npmjs.org/ --tag latest",
|
|
46
|
+
"publish:npm-dev": "npm publish --@kash-88:registry=https://registry.npmjs.org/ --tag dev",
|
|
47
|
+
"publish:npm-beta": "npm publish --@kash-88:registry=https://registry.npmjs.org/ --tag beta"
|
|
45
48
|
},
|
|
46
49
|
"dependencies": {
|
|
47
50
|
"axios": "^1.10.0",
|
|
@@ -51,9 +54,10 @@
|
|
|
51
54
|
"devDependencies": {
|
|
52
55
|
"@types/node": "^20.12.12",
|
|
53
56
|
"@types/ws": "^8.5.10",
|
|
57
|
+
"dotenv": "^16.4.5",
|
|
58
|
+
"readline-sync": "^1.4.10",
|
|
54
59
|
"ts-node": "^10.9.2",
|
|
55
60
|
"tsc-alias": "^1.8.16",
|
|
56
|
-
"
|
|
57
|
-
"typescript": "^5.4.5"
|
|
61
|
+
"typescript": "^5.9.3"
|
|
58
62
|
}
|
|
59
|
-
}
|
|
63
|
+
}
|