@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
package/readme.md
CHANGED
|
@@ -1,50 +1,90 @@
|
|
|
1
1
|
<div align="center">
|
|
2
|
+
<a href="https://www.donationalerts.com/apidoc"><img src="./readme/donationAlerts.png" alt="Donation Alerts Logo" width="400"></a>
|
|
3
|
+
</div>
|
|
2
4
|
|
|
3
|
-
|
|
4
|
-
A lightweight library for easy integration with the DonationAlerts API: authorization, token management, and user info in a few lines.
|
|
5
|
+
<div align="center">
|
|
5
6
|
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
[](https://www.npmjs.com/package/@kash-88/alerts/v/latest)
|
|
7
|
+
# DonationAlerts SDK
|
|
8
|
+
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.
|
|
9
9
|
|
|
10
|
-
</div>
|
|
11
10
|
|
|
12
|
-
|
|
11
|
+
<p></p>
|
|
12
|
+
|
|
13
|
+
[](https://www.npmjs.com/package/@kash-88/alerts)
|
|
14
|
+
[](https://www.npmjs.com/package/@kash-88/alerts)
|
|
15
|
+
[](https://www.npmjs.com/package/@kash-88/alerts)
|
|
16
|
+
[](https://github.com/kash-ts/alerts-SDK)
|
|
17
|
+
|
|
18
|
+
</div>
|
|
13
19
|
|
|
14
20
|
## Installation
|
|
15
|
-
Using npm:
|
|
16
21
|
|
|
17
22
|
```bash
|
|
18
23
|
$ npm install @kash-88/alerts
|
|
19
24
|
```
|
|
20
25
|
|
|
21
|
-
|
|
26
|
+
## Available functions (methods)
|
|
27
|
+
| Function | Purpose |
|
|
28
|
+
|-------------------------------------------------------|--------------------------------------------------|
|
|
29
|
+
| [getAuthorizeLink](#getAuthorizeLink) | Generate OAuth authorization link. |
|
|
30
|
+
| [getOauthToken](#getOauthToken) | Exchange code for oauth token and refresh_token. |
|
|
31
|
+
| [updateOauthToken](#updateOauthToken) | Refresh oauth token using refresh token. |
|
|
32
|
+
| [getUser](#getUser) | Fetch user profile by oauth token. |
|
|
33
|
+
| [getUserChannel](#getUserChannel) | Get user channel by id. |
|
|
34
|
+
| [getPrivateToken](#getPrivateToken) | Get private token for channel subscription. |
|
|
35
|
+
| [getDonationsAlerts](#getDonationsAlerts) | Fetch user donation alerts list. |
|
|
36
|
+
| [getExternal](#getExternal) | Generate random external ID. |
|
|
37
|
+
| [createCustomAlerts](#createCustomAlerts) | Send a custom alert to the authorized user. |
|
|
38
|
+
| [generateSignature](#generateSignature) | Generate SHA256 request signature. |
|
|
39
|
+
| [createMerchandise](#createMerchandise) | Create a new merchandise. |
|
|
40
|
+
| [updateMerchandise](#updateMerchandise) | Update an existing merchandise. |
|
|
41
|
+
| [updateOrCreateMerchandise](#updateOrCreateMerchandise) | Update or create a merchandise. |
|
|
42
|
+
| [getUserDataFromPromocode](#getUserDataFromPromocode) | Get user ID from an advertising promocode. |
|
|
43
|
+
| [sendSaleAlert](#sendSaleAlert) | Send a merchandise sale alert. |
|
|
44
|
+
| [WebServer](#WebServer) | WebSocket client for Centrifugo. |
|
|
22
45
|
|
|
23
|
-
|
|
24
|
-
$ yarn add @kash-88/alerts
|
|
25
|
-
```
|
|
46
|
+
---
|
|
26
47
|
|
|
27
|
-
|
|
48
|
+
## createCustomAlerts (Async)
|
|
49
|
+
**Purpose:** Отправка кастомного оповещения для пользователя
|
|
28
50
|
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
51
|
+
- **Params:**
|
|
52
|
+
- `access_token: string` — User access token
|
|
53
|
+
- `external_id: string` — Unique alert identifier (up to 32 characters)
|
|
54
|
+
- `header: string` — Alert title (up to 255 characters)
|
|
55
|
+
- `message: string` — Alert message (up to 300 characters)
|
|
56
|
+
- `is_shown: 0 | 1` — Whether or not notifications will be displayed
|
|
57
|
+
- `image_url?: string | null` — URL of the image that will be shown along with the notification
|
|
58
|
+
- `sound_url?: string | null` — URL of the sound that will be played along with notifications
|
|
59
|
+
- **Endpoint:** https://www.donationalerts.com/api/v1/custom_alert
|
|
60
|
+
- **API Docs:** [Send Custom Alerts](https://www.donationalerts.com/apidoc#api_v1__custom_alerts__send_custom_alerts)
|
|
32
61
|
|
|
33
|
-
|
|
62
|
+
**Example:**
|
|
63
|
+
```js
|
|
64
|
+
/**
|
|
65
|
+
* Notes:
|
|
66
|
+
* - You can generate external_id using the getExternal() function.
|
|
67
|
+
*/
|
|
34
68
|
|
|
35
|
-
|
|
36
|
-
$ bun add @kash-88/alerts
|
|
37
|
-
```
|
|
69
|
+
import { createCustomAlerts, getExternal } from "@kash-88/alerts";
|
|
38
70
|
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
71
|
+
const access_token = "ACCESS_TOKEN";
|
|
72
|
+
const external_id = getExternal();
|
|
73
|
+
const header = "Header alerts";
|
|
74
|
+
const message = "Message alerts";
|
|
75
|
+
const is_shown = 1;
|
|
76
|
+
const image_url = null;
|
|
77
|
+
const sound_url = null;
|
|
78
|
+
|
|
79
|
+
(async () => {
|
|
80
|
+
try {
|
|
81
|
+
const token = await createCustomAlerts(access_token, external_id, header, message, is_shown, image_url, sound_url);
|
|
82
|
+
console.log("Result:", token);
|
|
83
|
+
} catch (error) {
|
|
84
|
+
console.error("Error:", error.message);
|
|
85
|
+
}
|
|
86
|
+
})();
|
|
87
|
+
```
|
|
48
88
|
|
|
49
89
|
---
|
|
50
90
|
|
|
@@ -52,50 +92,63 @@ $ bun add @kash-88/alerts
|
|
|
52
92
|
**Purpose:** Generate OAuth authorization link for DonationAlerts.
|
|
53
93
|
|
|
54
94
|
- **Params:**
|
|
55
|
-
- `client_id: string` — Your
|
|
56
|
-
- `
|
|
95
|
+
- `client_id: string` — Your client (application) ID
|
|
96
|
+
- `redirect_uri: string` — The URL where users will be sent after authorization
|
|
97
|
+
- `scopes: OAuthScope[]` — Array of access scopes
|
|
98
|
+
- `type: "code" | "token"` — Type response oauth token
|
|
57
99
|
- **Endpoint:** https://www.donationalerts.com/oauth/authorize
|
|
58
100
|
- **API Docs:** [Authorization Request](https://www.donationalerts.com/apidoc#authorization__authorization_code__authorization_request)
|
|
59
101
|
|
|
60
102
|
**Example:**
|
|
61
103
|
```js
|
|
62
|
-
|
|
104
|
+
/**
|
|
105
|
+
* Notes:
|
|
106
|
+
* - You can get CLIENT_ID at https://www.donationalerts.com/application/clients.
|
|
107
|
+
* - You can find the list of scopes at https://www.donationalerts.com/apidoc#authorization__scopes.
|
|
108
|
+
*/
|
|
109
|
+
|
|
110
|
+
import { getAuthorizeLink, OAuthScope } from "@kash-88/alerts";
|
|
63
111
|
|
|
64
|
-
const client_id = "
|
|
65
|
-
const
|
|
112
|
+
const client_id = "CLIENT_ID";
|
|
113
|
+
const redirect_uri = "https://example.com/callback";
|
|
114
|
+
const scopes = [OAuthScope.UserShow];
|
|
115
|
+
const type = "code"; // Or "token"
|
|
66
116
|
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
console.log("Authorize link:", link);
|
|
70
|
-
} catch (error) {
|
|
71
|
-
console.error("Error:", error.message);
|
|
72
|
-
}
|
|
117
|
+
const link = getAuthorizeLink(client_id, redirect_uri, scopes, type);
|
|
118
|
+
console.log("Authorize link:", link);
|
|
73
119
|
```
|
|
74
120
|
|
|
75
121
|
---
|
|
76
122
|
|
|
77
123
|
## getOauthToken (Async)
|
|
78
|
-
**Purpose:** Exchange
|
|
124
|
+
**Purpose:** Exchange Authorization code for OAuth token and Refresh token.
|
|
79
125
|
|
|
80
126
|
- **Params:**
|
|
81
|
-
- `client_id: string` — Your
|
|
82
|
-
- `client_secret: string` — Your
|
|
83
|
-
- `
|
|
127
|
+
- `client_id: string` — Your client (application) ID
|
|
128
|
+
- `client_secret: string` — Your client (application) secret
|
|
129
|
+
- `redirect_uri: string` — The URL where users will be sent after authorization
|
|
130
|
+
- `code: string` — User authorization code
|
|
84
131
|
- **Endpoint:** https://www.donationalerts.com/oauth/token
|
|
85
132
|
- **API Docs:** [Getting Access Token](https://www.donationalerts.com/apidoc#authorization__authorization_code__getting_access_token)
|
|
86
133
|
|
|
87
134
|
**Example:**
|
|
88
135
|
```js
|
|
136
|
+
/**
|
|
137
|
+
* Notes:
|
|
138
|
+
* - You can get CLIENT_ID and CLIENT_TOKEN at https://www.donationalerts.com/application/clients.
|
|
139
|
+
* - USER_CODE is the authorization code returned after the user authorizes your app via the link from getAuthorizeLink() with type="code".
|
|
140
|
+
*/
|
|
141
|
+
|
|
89
142
|
import { getOauthToken } from "@kash-88/alerts";
|
|
90
143
|
|
|
91
|
-
|
|
92
|
-
const
|
|
93
|
-
const
|
|
144
|
+
const client_id = "CLIENT_ID";
|
|
145
|
+
const client_secret = "CLIENT_SECRET";
|
|
146
|
+
const redirect_uri = "https://example.com/callback";
|
|
94
147
|
const code = "USER_CODE";
|
|
95
148
|
|
|
96
149
|
(async () => {
|
|
97
150
|
try {
|
|
98
|
-
const token = await getOauthToken(
|
|
151
|
+
const token = await getOauthToken(client_id, client_secret, redirect_uri, code);
|
|
99
152
|
console.log("Oauth token:", token);
|
|
100
153
|
} catch (error) {
|
|
101
154
|
console.error("Error:", error.message);
|
|
@@ -105,23 +158,66 @@ const code = "USER_CODE";
|
|
|
105
158
|
|
|
106
159
|
---
|
|
107
160
|
|
|
161
|
+
## getPrivateToken (Async)
|
|
162
|
+
**Purpose:** Get a Private token for subscribing to a DonationAlerts channel via Centrifuge.
|
|
163
|
+
|
|
164
|
+
- **Params:**
|
|
165
|
+
- `channel: string` — User channel
|
|
166
|
+
- `uuidv4_client_id: string` — UUID v4 client ID
|
|
167
|
+
- `access_token: string` — User access token
|
|
168
|
+
- **Endpoint:** https://www.donationalerts.com/api/v1/centrifuge/subscribe
|
|
169
|
+
- **API Docs:** —
|
|
170
|
+
|
|
171
|
+
**Example:**
|
|
172
|
+
```js
|
|
173
|
+
/**
|
|
174
|
+
* Notes:
|
|
175
|
+
* - This function is intended to be used together with WebSocket.
|
|
176
|
+
* - You can get USER_CHANNEL using getUserChannel().
|
|
177
|
+
* - You receive client ID when you establish the WebSocket connection.
|
|
178
|
+
* - You can obtain the user access_token using getOauthToken().
|
|
179
|
+
*/
|
|
180
|
+
|
|
181
|
+
import { getPrivateToken } from "@kash-88/alerts";
|
|
182
|
+
|
|
183
|
+
const channel = "USER_CHANNEL";
|
|
184
|
+
const client = "UUIDv4_CLIENT_ID";
|
|
185
|
+
const access_token = "ACCESS_TOKEN";
|
|
186
|
+
|
|
187
|
+
(async () => {
|
|
188
|
+
try {
|
|
189
|
+
const token = await getPrivateToken(channel, client, access_token);
|
|
190
|
+
console.log("Private token:", token);
|
|
191
|
+
} catch (error) {
|
|
192
|
+
console.error("Error getting private token:", error.message);
|
|
193
|
+
}
|
|
194
|
+
})();
|
|
195
|
+
```
|
|
196
|
+
|
|
197
|
+
---
|
|
198
|
+
|
|
108
199
|
## getUser (Async)
|
|
109
|
-
**Purpose:** Fetch user profile information by
|
|
200
|
+
**Purpose:** Fetch user profile information by OAuth token.
|
|
110
201
|
|
|
111
202
|
- **Params:**
|
|
112
|
-
- `access_token: string` — User
|
|
203
|
+
- `access_token: string` — User access token
|
|
113
204
|
- **Endpoint:** https://www.donationalerts.com/api/v1/user/oauth
|
|
114
205
|
- **API Docs:** [User Info](https://www.donationalerts.com/apidoc#api_v1__users)
|
|
115
206
|
|
|
116
207
|
**Example:**
|
|
117
208
|
```js
|
|
209
|
+
/**
|
|
210
|
+
* Notes:
|
|
211
|
+
* - You can obtain ACCESS_TOKEN by calling getOauthToken() after the user authorizes your app.
|
|
212
|
+
*/
|
|
213
|
+
|
|
118
214
|
import { getUser } from "@kash-88/alerts";
|
|
119
215
|
|
|
120
|
-
const
|
|
216
|
+
const access_token = "ACCESS_TOKEN";
|
|
121
217
|
|
|
122
218
|
(async () => {
|
|
123
219
|
try {
|
|
124
|
-
const user = await getUser(
|
|
220
|
+
const user = await getUser(access_token);
|
|
125
221
|
console.log("User data:", user);
|
|
126
222
|
} catch (error) {
|
|
127
223
|
console.error("Error:", error.message);
|
|
@@ -132,15 +228,21 @@ const user_access_token = "USER_ACCESS_TOKEN";
|
|
|
132
228
|
---
|
|
133
229
|
|
|
134
230
|
## getUserChannel (Sync)
|
|
135
|
-
**Purpose:** Get user channel by
|
|
231
|
+
**Purpose:** Get user channel by user id for WebSocket.
|
|
136
232
|
|
|
137
233
|
- **Params:**
|
|
138
|
-
- `user_id: string` — User ID
|
|
234
|
+
- `user_id: string | number` — User ID
|
|
139
235
|
- **Endpoint:** —
|
|
140
236
|
- **API Docs:** —
|
|
141
237
|
|
|
142
238
|
**Example:**
|
|
143
239
|
```js
|
|
240
|
+
/**
|
|
241
|
+
* Notes:
|
|
242
|
+
* - This function is intended to be used together with WebSocket.
|
|
243
|
+
* - You can get USER_ID using getUser().
|
|
244
|
+
*/
|
|
245
|
+
|
|
144
246
|
import { getUserChannel } from "@kash-88/alerts";
|
|
145
247
|
|
|
146
248
|
const user_id = "USER_ID";
|
|
@@ -151,30 +253,35 @@ console.log("User channel:", channel);
|
|
|
151
253
|
|
|
152
254
|
---
|
|
153
255
|
|
|
154
|
-
##
|
|
155
|
-
**Purpose:** Refresh
|
|
256
|
+
## updateOauthToken (Async)
|
|
257
|
+
**Purpose:** Refresh Access token using Refresh token.
|
|
156
258
|
|
|
157
259
|
- **Params:**
|
|
158
|
-
- `client_id: string` — Your
|
|
159
|
-
- `
|
|
160
|
-
- `refresh_token: string` —
|
|
260
|
+
- `client_id: string` — Your client (application) ID
|
|
261
|
+
- `client_token: string` — Your client (application) token
|
|
262
|
+
- `refresh_token: string` — User refresh token
|
|
263
|
+
- `scopes: OAuthScope[]` — Array of access scopes
|
|
161
264
|
- **Endpoint:** https://www.donationalerts.com/oauth/token
|
|
162
265
|
- **API Docs:** [Refreshing Access Tokens](https://www.donationalerts.com/apidoc#authorization__authorization_code__refreshing_access_tokens)
|
|
163
266
|
|
|
164
267
|
**Example:**
|
|
165
268
|
```js
|
|
166
|
-
|
|
167
|
-
|
|
269
|
+
/**
|
|
270
|
+
* Notes:
|
|
271
|
+
* - You can get CLIENT_ID and CLIENT_TOKEN at https://www.donationalerts.com/application/clients.
|
|
272
|
+
* - You can obtain REFRESH_TOKEN from the response of getOauthToken().
|
|
273
|
+
*/
|
|
168
274
|
|
|
169
|
-
|
|
170
|
-
const client_id = "YOUR_CLIENT_ID";
|
|
171
|
-
const client_secret = process.env.CLIENT_SECRET!;
|
|
275
|
+
import { updateOauthToken, OAuthScope } from "@kash-88/alerts";
|
|
172
276
|
|
|
173
|
-
const
|
|
277
|
+
const client_id = "CLIENT_ID";
|
|
278
|
+
const client_token = "CLIENT_TOKEN";
|
|
279
|
+
const refresh_token = "REFRESH_TOKEN";
|
|
280
|
+
const scopes = [OAuthScope.UserShow, OAuthScope.DonationSubscribe];
|
|
174
281
|
|
|
175
282
|
(async () => {
|
|
176
283
|
try {
|
|
177
|
-
const token = await
|
|
284
|
+
const token = await updateOauthToken(client_id, client_token, refresh_token, scopes);
|
|
178
285
|
console.log("Oauth token:", token);
|
|
179
286
|
} catch (error) {
|
|
180
287
|
console.error("Error:", error.message);
|
|
@@ -184,29 +291,343 @@ const refresh_token = "USER_REFRESH_TOKEN";
|
|
|
184
291
|
|
|
185
292
|
---
|
|
186
293
|
|
|
187
|
-
##
|
|
188
|
-
**Purpose:**
|
|
294
|
+
## getDonationsAlerts (Async)
|
|
295
|
+
**Purpose:** Fetch user donation alerts list.
|
|
189
296
|
|
|
190
297
|
- **Params:**
|
|
191
|
-
- `
|
|
192
|
-
- `
|
|
193
|
-
|
|
194
|
-
- **
|
|
195
|
-
- **API Docs:** —
|
|
298
|
+
- `access_token: string` — User access token
|
|
299
|
+
- `page?: number | string` — Page number for pagination (default: 1)
|
|
300
|
+
- **Endpoint:** https://www.donationalerts.com/api/v1/alerts/donations
|
|
301
|
+
- **API Docs:** [Donation Alerts List](https://www.donationalerts.com/apidoc#api_v1__donations__donation_alerts_list)
|
|
196
302
|
|
|
197
303
|
**Example:**
|
|
198
304
|
```js
|
|
199
|
-
import {
|
|
305
|
+
import { getDonationsAlerts } from "@kash-88/alerts";
|
|
200
306
|
|
|
201
|
-
const
|
|
202
|
-
const uuidv4_client_id = "UUIDv4_CLIENT_ID"; // WebSocket client UUID
|
|
203
|
-
const access_token = "USER_ACCESS_TOKEN";
|
|
307
|
+
const access_token = "ACCESS_TOKEN";
|
|
204
308
|
|
|
205
309
|
(async () => {
|
|
206
310
|
try {
|
|
207
|
-
const
|
|
208
|
-
console.log("
|
|
311
|
+
const donations = await getDonationsAlerts(access_token, 1);
|
|
312
|
+
console.log("Donations:", donations);
|
|
209
313
|
} catch (error) {
|
|
210
|
-
console.error("Error
|
|
314
|
+
console.error("Error:", error.message);
|
|
211
315
|
}
|
|
212
|
-
})();
|
|
316
|
+
})();
|
|
317
|
+
```
|
|
318
|
+
|
|
319
|
+
---
|
|
320
|
+
|
|
321
|
+
## getExternal (Sync)
|
|
322
|
+
**Purpose:** Generate a random 32-character external ID.
|
|
323
|
+
|
|
324
|
+
- **Params:** None
|
|
325
|
+
- **Returns:** `string` — 32 random alphanumeric characters
|
|
326
|
+
|
|
327
|
+
**Example:**
|
|
328
|
+
```js
|
|
329
|
+
import { getExternal } from "@kash-88/alerts";
|
|
330
|
+
|
|
331
|
+
const external_id = getExternal();
|
|
332
|
+
console.log("External ID:", external_id);
|
|
333
|
+
```
|
|
334
|
+
|
|
335
|
+
---
|
|
336
|
+
|
|
337
|
+
## generateSignature (Sync)
|
|
338
|
+
**Purpose:** Generate a SHA256 request signature for Merchandise API.
|
|
339
|
+
|
|
340
|
+
- **Params:**
|
|
341
|
+
- `params: Record<string, string | number>` — Request parameters
|
|
342
|
+
- `client_secret: string` — API client secret key
|
|
343
|
+
- **Returns:** `string` — SHA256 hex digest signature
|
|
344
|
+
- **API Docs:** [Request Signatures](https://www.donationalerts.com/apidoc#introduction__http_api_requests__request_signatures)
|
|
345
|
+
|
|
346
|
+
**Example:**
|
|
347
|
+
```js
|
|
348
|
+
import { generateSignature } from "@kash-88/alerts";
|
|
349
|
+
|
|
350
|
+
const params = { foo: "xyz", bar: "abc" };
|
|
351
|
+
const client_secret = "CLIENT_SECRET";
|
|
352
|
+
const signature = generateSignature(params, client_secret);
|
|
353
|
+
console.log("Signature:", signature);
|
|
354
|
+
```
|
|
355
|
+
|
|
356
|
+
---
|
|
357
|
+
|
|
358
|
+
## createMerchandise (Async)
|
|
359
|
+
**Purpose:** Create a new merchandise.
|
|
360
|
+
|
|
361
|
+
- **Params:**
|
|
362
|
+
- `access_token: string` — User access token
|
|
363
|
+
- `client_secret: string` — API client secret key for signature
|
|
364
|
+
- `merchant_identifier: string` — Merchant's ID on DonationAlerts
|
|
365
|
+
- `merchandise_identifier: string` — Up to 16 characters long unique merchandise ID
|
|
366
|
+
- `title: Record<string, string>` — Object with merchandise titles in different locales (en_US required)
|
|
367
|
+
- `currency: string` — Currency code (EUR, USD, RUB, BRL, TRY)
|
|
368
|
+
- `price_user: number` — Revenue added to streamer for each sale
|
|
369
|
+
- `price_service: number` — Revenue added to DonationAlerts for each sale
|
|
370
|
+
- `is_active?: number` — 0 or 1 (default: 0)
|
|
371
|
+
- `is_percentage?: number` — 0 or 1 (default: 0)
|
|
372
|
+
- `url?: string` — URL to merchandise's web page
|
|
373
|
+
- `img_url?: string` — URL to merchandise's image
|
|
374
|
+
- `end_at_ts?: number` — Unix timestamp when merchandise becomes inactive
|
|
375
|
+
- **Endpoint:** https://www.donationalerts.com/api/v1/merchandise
|
|
376
|
+
- **API Docs:** [Create Merchandise](https://www.donationalerts.com/apidoc#api_v1__merchandises__create_merchandise)
|
|
377
|
+
|
|
378
|
+
**Example:**
|
|
379
|
+
```js
|
|
380
|
+
import { createMerchandise } from "@kash-88/alerts";
|
|
381
|
+
|
|
382
|
+
const access_token = "ACCESS_TOKEN";
|
|
383
|
+
const client_secret = "CLIENT_SECRET";
|
|
384
|
+
|
|
385
|
+
(async () => {
|
|
386
|
+
try {
|
|
387
|
+
const merchandise = await createMerchandise(
|
|
388
|
+
access_token,
|
|
389
|
+
client_secret,
|
|
390
|
+
"MERCHANT_ID",
|
|
391
|
+
"MERCH_ID",
|
|
392
|
+
{ en_US: "Product Name", ru_RU: "Название товара" },
|
|
393
|
+
"USD",
|
|
394
|
+
30,
|
|
395
|
+
15,
|
|
396
|
+
1,
|
|
397
|
+
0,
|
|
398
|
+
"https://example.com/product",
|
|
399
|
+
"https://example.com/image.png"
|
|
400
|
+
);
|
|
401
|
+
console.log("Merchandise:", merchandise);
|
|
402
|
+
} catch (error) {
|
|
403
|
+
console.error("Error:", error.message);
|
|
404
|
+
}
|
|
405
|
+
})();
|
|
406
|
+
```
|
|
407
|
+
|
|
408
|
+
---
|
|
409
|
+
|
|
410
|
+
## updateMerchandise (Async)
|
|
411
|
+
**Purpose:** Update an existing merchandise by its DonationAlerts ID.
|
|
412
|
+
|
|
413
|
+
- **Params:**
|
|
414
|
+
- `access_token: string` — User access token
|
|
415
|
+
- `client_secret: string` — API client secret key for signature
|
|
416
|
+
- `merchandise_id: number` — Unique merchandise ID on DonationAlerts
|
|
417
|
+
- `title: Record<string, string>` — Object with merchandise titles in different locales (en_US required)
|
|
418
|
+
- `currency: string` — Currency code (EUR, USD, RUB, BRL, TRY)
|
|
419
|
+
- `price_user: number` — Revenue added to streamer for each sale
|
|
420
|
+
- `price_service: number` — Revenue added to DonationAlerts for each sale
|
|
421
|
+
- `is_active?: number` — 0 or 1 (default: 0)
|
|
422
|
+
- `is_percentage?: number` — 0 or 1 (default: 0)
|
|
423
|
+
- `url?: string` — URL to merchandise's web page
|
|
424
|
+
- `img_url?: string` — URL to merchandise's image
|
|
425
|
+
- `end_at_ts?: number` — Unix timestamp when merchandise becomes inactive
|
|
426
|
+
- **Endpoint:** https://www.donationalerts.com/api/v1/merchandise/{id}
|
|
427
|
+
- **API Docs:** [Update Merchandise](https://www.donationalerts.com/apidoc#api_v1__merchandises__update_merchandise)
|
|
428
|
+
|
|
429
|
+
**Example:**
|
|
430
|
+
```js
|
|
431
|
+
import { updateMerchandise } from "@kash-88/alerts";
|
|
432
|
+
|
|
433
|
+
const access_token = "ACCESS_TOKEN";
|
|
434
|
+
const client_secret = "CLIENT_SECRET";
|
|
435
|
+
|
|
436
|
+
(async () => {
|
|
437
|
+
try {
|
|
438
|
+
const merchandise = await updateMerchandise(
|
|
439
|
+
access_token,
|
|
440
|
+
client_secret,
|
|
441
|
+
3,
|
|
442
|
+
{ en_US: "Updated Product", ru_RU: "Обновлённый товар" },
|
|
443
|
+
"USD",
|
|
444
|
+
35,
|
|
445
|
+
15,
|
|
446
|
+
1
|
|
447
|
+
);
|
|
448
|
+
console.log("Updated merchandise:", merchandise);
|
|
449
|
+
} catch (error) {
|
|
450
|
+
console.error("Error:", error.message);
|
|
451
|
+
}
|
|
452
|
+
})();
|
|
453
|
+
```
|
|
454
|
+
|
|
455
|
+
---
|
|
456
|
+
|
|
457
|
+
## updateOrCreateMerchandise (Async)
|
|
458
|
+
**Purpose:** Update or create a merchandise by merchant and merchandise identifiers.
|
|
459
|
+
|
|
460
|
+
- **Params:**
|
|
461
|
+
- `access_token: string` — User access token
|
|
462
|
+
- `client_secret: string` — API client secret key for signature
|
|
463
|
+
- `merchant_identifier: string` — Merchant's ID on DonationAlerts
|
|
464
|
+
- `merchandise_identifier: string` — Up to 16 characters long unique merchandise ID
|
|
465
|
+
- `title: Record<string, string>` — Object with merchandise titles in different locales (en_US required)
|
|
466
|
+
- `currency: string` — Currency code (EUR, USD, RUB, BRL, TRY)
|
|
467
|
+
- `price_user: number` — Revenue added to streamer for each sale
|
|
468
|
+
- `price_service: number` — Revenue added to DonationAlerts for each sale
|
|
469
|
+
- `is_active?: number` — 0 or 1 (default: 0)
|
|
470
|
+
- `is_percentage?: number` — 0 or 1 (default: 0)
|
|
471
|
+
- `url?: string` — URL to merchandise's web page
|
|
472
|
+
- `img_url?: string` — URL to merchandise's image
|
|
473
|
+
- `end_at_ts?: number` — Unix timestamp when merchandise becomes inactive
|
|
474
|
+
- **Endpoint:** https://www.donationalerts.com/api/v1/merchandise/{merchant}/{merch_id}
|
|
475
|
+
- **API Docs:** [Update or Create Merchandise](https://www.donationalerts.com/apidoc#api_v1__merchandises__update_or_create_merchandise)
|
|
476
|
+
|
|
477
|
+
**Example:**
|
|
478
|
+
```js
|
|
479
|
+
import { updateOrCreateMerchandise } from "@kash-88/alerts";
|
|
480
|
+
|
|
481
|
+
const access_token = "ACCESS_TOKEN";
|
|
482
|
+
const client_secret = "CLIENT_SECRET";
|
|
483
|
+
|
|
484
|
+
(async () => {
|
|
485
|
+
try {
|
|
486
|
+
const merchandise = await updateOrCreateMerchandise(
|
|
487
|
+
access_token,
|
|
488
|
+
client_secret,
|
|
489
|
+
"MERCHANT_ID",
|
|
490
|
+
"MERCH_ID",
|
|
491
|
+
{ en_US: "Product Name" },
|
|
492
|
+
"USD",
|
|
493
|
+
30,
|
|
494
|
+
15,
|
|
495
|
+
1
|
|
496
|
+
);
|
|
497
|
+
console.log("Merchandise:", merchandise);
|
|
498
|
+
} catch (error) {
|
|
499
|
+
console.error("Error:", error.message);
|
|
500
|
+
}
|
|
501
|
+
})();
|
|
502
|
+
```
|
|
503
|
+
|
|
504
|
+
---
|
|
505
|
+
|
|
506
|
+
## getUserDataFromPromocode (Async)
|
|
507
|
+
**Purpose:** Get user ID from an advertising promocode.
|
|
508
|
+
|
|
509
|
+
- **Params:**
|
|
510
|
+
- `access_token: string` — User access token
|
|
511
|
+
- `client_secret: string` — API client secret key for signature
|
|
512
|
+
- `promocode: string` — User promocode
|
|
513
|
+
- **Endpoint:** https://www.donationalerts.com/api/v1/merchandise/user
|
|
514
|
+
- **API Docs:** [Get User Data from Promocode](https://www.donationalerts.com/apidoc#api_v1__merchandises__update_or_create_merchandise__get_user_data_from_promocode)
|
|
515
|
+
|
|
516
|
+
**Example:**
|
|
517
|
+
```js
|
|
518
|
+
import { getUserDataFromPromocode } from "@kash-88/alerts";
|
|
519
|
+
|
|
520
|
+
const access_token = "ACCESS_TOKEN";
|
|
521
|
+
const client_secret = "CLIENT_SECRET";
|
|
522
|
+
|
|
523
|
+
(async () => {
|
|
524
|
+
try {
|
|
525
|
+
const userId = await getUserDataFromPromocode(access_token, client_secret, "test123");
|
|
526
|
+
console.log("User ID:", userId);
|
|
527
|
+
} catch (error) {
|
|
528
|
+
console.error("Error:", error.message);
|
|
529
|
+
}
|
|
530
|
+
})();
|
|
531
|
+
```
|
|
532
|
+
|
|
533
|
+
---
|
|
534
|
+
|
|
535
|
+
## sendSaleAlert (Async)
|
|
536
|
+
**Purpose:** Send a merchandise sale alert.
|
|
537
|
+
|
|
538
|
+
- **Params:**
|
|
539
|
+
- `access_token: string` — User access token
|
|
540
|
+
- `client_secret: string` — API client secret key for signature
|
|
541
|
+
- `user_id: number` — DonationAlerts user ID to which the sale is referenced
|
|
542
|
+
- `external_id: string` — Up to 32 characters long unique sale ID
|
|
543
|
+
- `merchant_identifier: string` — Merchant's ID on DonationAlerts
|
|
544
|
+
- `merchandise_identifier: string` — Merchant's merchandise ID that was bought
|
|
545
|
+
- `amount: number` — Grand total of the sale
|
|
546
|
+
- `currency: string` — Currency code (EUR, USD, RUB, BRL, TRY)
|
|
547
|
+
- `bought_amount?: number` — Total number of bought items (default: 1)
|
|
548
|
+
- `username?: string` — Name of the customer
|
|
549
|
+
- `message?: string` — Message sent by the customer
|
|
550
|
+
- **Endpoint:** https://www.donationalerts.com/api/v1/merchandise_sale
|
|
551
|
+
- **API Docs:** [Send Sale Alerts](https://www.donationalerts.com/apidoc#api_v1__merchandise_sale_notifications__send_sale_alerts)
|
|
552
|
+
|
|
553
|
+
**Example:**
|
|
554
|
+
```js
|
|
555
|
+
import { sendSaleAlert, getExternal } from "@kash-88/alerts";
|
|
556
|
+
|
|
557
|
+
const access_token = "ACCESS_TOKEN";
|
|
558
|
+
const client_secret = "CLIENT_SECRET";
|
|
559
|
+
|
|
560
|
+
(async () => {
|
|
561
|
+
try {
|
|
562
|
+
const sale = await sendSaleAlert(
|
|
563
|
+
access_token,
|
|
564
|
+
client_secret,
|
|
565
|
+
3,
|
|
566
|
+
getExternal(),
|
|
567
|
+
"MERCHANT_ID",
|
|
568
|
+
"MERCH_ID",
|
|
569
|
+
100,
|
|
570
|
+
"RUB",
|
|
571
|
+
2,
|
|
572
|
+
"John",
|
|
573
|
+
"Test message"
|
|
574
|
+
);
|
|
575
|
+
console.log("Sale alert:", sale);
|
|
576
|
+
} catch (error) {
|
|
577
|
+
console.error("Error:", error.message);
|
|
578
|
+
}
|
|
579
|
+
})();
|
|
580
|
+
```
|
|
581
|
+
|
|
582
|
+
---
|
|
583
|
+
|
|
584
|
+
## WebServer (CentrifugeClient)
|
|
585
|
+
**Purpose:** WebSocket client for real-time donation alerts via Centrifugo.
|
|
586
|
+
|
|
587
|
+
- **Constructor params:**
|
|
588
|
+
- `access_token: string` — User access token
|
|
589
|
+
- `channels?: string[]` — Custom channels to subscribe to (defaults to donation channel)
|
|
590
|
+
- `autoReconnect?: boolean` — Automatically reconnect on connection close (default: false)
|
|
591
|
+
- **Events:**
|
|
592
|
+
- `open` — Connection opened
|
|
593
|
+
- `message` — Message received from server
|
|
594
|
+
- `close` — Connection closed (code, reason)
|
|
595
|
+
- `error` — Error occurred
|
|
596
|
+
- `reconnect` — Reconnecting after disconnection
|
|
597
|
+
- **Methods:**
|
|
598
|
+
- `authorization()` — Authorize and subscribe to channels (call after `open` event)
|
|
599
|
+
- `createNewConnection()` — Create a new WebSocket connection
|
|
600
|
+
- `sendMessage(message: string)` — Send a message through the WebSocket
|
|
601
|
+
- **Endpoint:** wss://centrifugo.donationalerts.com/connection/websocket
|
|
602
|
+
- **API Docs:** [Centrifugo](https://www.donationalerts.com/apidoc#centrifugo)
|
|
603
|
+
|
|
604
|
+
**Example:**
|
|
605
|
+
```js
|
|
606
|
+
import { WebServer, OAuthScope, getUserChannel } from "@kash-88/alerts";
|
|
607
|
+
|
|
608
|
+
const ws = new WebServer({
|
|
609
|
+
access_token: "ACCESS_TOKEN",
|
|
610
|
+
autoReconnect: true
|
|
611
|
+
});
|
|
612
|
+
|
|
613
|
+
ws.on("open", async () => {
|
|
614
|
+
console.log("WebSocket connected");
|
|
615
|
+
await ws.authorization();
|
|
616
|
+
});
|
|
617
|
+
|
|
618
|
+
ws.on("message", (data) => {
|
|
619
|
+
console.log("Message:", data);
|
|
620
|
+
});
|
|
621
|
+
|
|
622
|
+
ws.on("close", (code, reason) => {
|
|
623
|
+
console.log(`Closed: ${code} ${reason}`);
|
|
624
|
+
});
|
|
625
|
+
|
|
626
|
+
ws.on("error", (error) => {
|
|
627
|
+
console.error("Error:", error);
|
|
628
|
+
});
|
|
629
|
+
|
|
630
|
+
ws.on("reconnect", () => {
|
|
631
|
+
console.log("Reconnecting...");
|
|
632
|
+
});
|
|
633
|
+
```
|