@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,81 @@
|
|
|
1
|
+
import axios from "axios";
|
|
2
|
+
import generateSignature from "./generateSignature.js";
|
|
3
|
+
import { formatAxiosError } from "../utils.js";
|
|
4
|
+
/**
|
|
5
|
+
* Send a merchandise sale alert.
|
|
6
|
+
*
|
|
7
|
+
* @param {string} access_token - User access token
|
|
8
|
+
* @param {string} client_secret - API client secret key for signature
|
|
9
|
+
* @param {number} user_id - DonationAlerts user ID to which the sale is referenced
|
|
10
|
+
* @param {string} external_id - Up to 32 characters long unique sale ID
|
|
11
|
+
* @param {string} merchant_identifier - Merchant's ID on DonationAlerts
|
|
12
|
+
* @param {string} merchandise_identifier - Merchant's merchandise ID that was bought
|
|
13
|
+
* @param {number} amount - Grand total of the sale
|
|
14
|
+
* @param {string} currency - Currency code (EUR, USD, RUB, BRL, TRY)
|
|
15
|
+
* @param {number} [bought_amount=1] - Total number of bought items
|
|
16
|
+
* @param {string} [username] - Name of the customer
|
|
17
|
+
* @param {string} [message] - Message sent by the customer
|
|
18
|
+
*
|
|
19
|
+
* @returns {Promise<MerchandiseSale>} Created merchandise sale alert data
|
|
20
|
+
* @see {@link https://www.donationalerts.com/apidoc#api_v1__merchandise_sale_notifications__send_sale_alerts}
|
|
21
|
+
*/
|
|
22
|
+
export default async function sendSaleAlert(access_token, client_secret, user_id, external_id, merchant_identifier, merchandise_identifier, amount, currency, bought_amount = 1, username, message) {
|
|
23
|
+
if (!access_token || typeof access_token !== "string") {
|
|
24
|
+
throw new Error("access_token must be a non-empty string");
|
|
25
|
+
}
|
|
26
|
+
if (!client_secret || typeof client_secret !== "string") {
|
|
27
|
+
throw new Error("client_secret must be a non-empty string");
|
|
28
|
+
}
|
|
29
|
+
if (typeof user_id !== "number" || user_id <= 0) {
|
|
30
|
+
throw new Error("user_id must be a positive number");
|
|
31
|
+
}
|
|
32
|
+
if (!external_id || typeof external_id !== "string") {
|
|
33
|
+
throw new Error("external_id must be a non-empty string");
|
|
34
|
+
}
|
|
35
|
+
if (!merchant_identifier || typeof merchant_identifier !== "string") {
|
|
36
|
+
throw new Error("merchant_identifier must be a non-empty string");
|
|
37
|
+
}
|
|
38
|
+
if (!merchandise_identifier || typeof merchandise_identifier !== "string") {
|
|
39
|
+
throw new Error("merchandise_identifier must be a non-empty string");
|
|
40
|
+
}
|
|
41
|
+
if (typeof amount !== "number" || amount <= 0) {
|
|
42
|
+
throw new Error("amount must be a positive number");
|
|
43
|
+
}
|
|
44
|
+
if (!currency || typeof currency !== "string") {
|
|
45
|
+
throw new Error("currency must be a non-empty string");
|
|
46
|
+
}
|
|
47
|
+
if (typeof bought_amount !== "number" || bought_amount <= 0) {
|
|
48
|
+
throw new Error("bought_amount must be a positive number");
|
|
49
|
+
}
|
|
50
|
+
try {
|
|
51
|
+
const params = {
|
|
52
|
+
user_id,
|
|
53
|
+
external_id,
|
|
54
|
+
merchant_identifier,
|
|
55
|
+
merchandise_identifier,
|
|
56
|
+
amount,
|
|
57
|
+
currency,
|
|
58
|
+
bought_amount
|
|
59
|
+
};
|
|
60
|
+
if (username)
|
|
61
|
+
params.username = username;
|
|
62
|
+
if (message)
|
|
63
|
+
params.message = message;
|
|
64
|
+
const signature = generateSignature(params, client_secret);
|
|
65
|
+
params.signature = signature;
|
|
66
|
+
const formData = new URLSearchParams();
|
|
67
|
+
for (const [key, value] of Object.entries(params)) {
|
|
68
|
+
formData.append(key, String(value));
|
|
69
|
+
}
|
|
70
|
+
const response = await axios.post("https://www.donationalerts.com/api/v1/merchandise_sale", formData, {
|
|
71
|
+
headers: {
|
|
72
|
+
Authorization: `Bearer ${access_token}`,
|
|
73
|
+
"Content-Type": "application/x-www-form-urlencoded"
|
|
74
|
+
}
|
|
75
|
+
});
|
|
76
|
+
return response.data.data;
|
|
77
|
+
}
|
|
78
|
+
catch (error) {
|
|
79
|
+
throw new Error(formatAxiosError(error));
|
|
80
|
+
}
|
|
81
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { Merchandise } from "../Types/index.js";
|
|
2
|
+
/**
|
|
3
|
+
* Update an existing merchandise by its DonationAlerts ID.
|
|
4
|
+
*
|
|
5
|
+
* @param {string} access_token - User access token
|
|
6
|
+
* @param {string} client_secret - API client secret key for signature
|
|
7
|
+
* @param {number} merchandise_id - Unique merchandise ID on DonationAlerts
|
|
8
|
+
* @param {Record<string, string>} title - Object with merchandise titles in different locales (en_US required)
|
|
9
|
+
* @param {string} currency - Currency code (EUR, USD, RUB, BRL, TRY)
|
|
10
|
+
* @param {number} price_user - Revenue added to streamer for each sale
|
|
11
|
+
* @param {number} price_service - Revenue added to DonationAlerts for each sale
|
|
12
|
+
* @param {number} [is_active=0] - 0 or 1, whether merchandise is available for purchase
|
|
13
|
+
* @param {number} [is_percentage=0] - 0 or 1, whether prices are percentages or absolute amounts
|
|
14
|
+
* @param {string} [url] - URL to merchandise's web page
|
|
15
|
+
* @param {string} [img_url] - URL to merchandise's image
|
|
16
|
+
* @param {number} [end_at_ts] - Unix timestamp when merchandise becomes inactive
|
|
17
|
+
*
|
|
18
|
+
* @returns {Promise<Merchandise>} Updated merchandise data
|
|
19
|
+
* @see {@link https://www.donationalerts.com/apidoc#api_v1__merchandises__update_merchandise}
|
|
20
|
+
*/
|
|
21
|
+
export default function updateMerchandise(access_token: string, client_secret: string, merchandise_id: number, title: Record<string, string>, currency: string, price_user: number, price_service: number, is_active?: number, is_percentage?: number, url?: string, img_url?: string, end_at_ts?: number): Promise<Merchandise>;
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import axios from "axios";
|
|
2
|
+
import generateSignature from "./generateSignature.js";
|
|
3
|
+
import { formatAxiosError } from "../utils.js";
|
|
4
|
+
/**
|
|
5
|
+
* Update an existing merchandise by its DonationAlerts ID.
|
|
6
|
+
*
|
|
7
|
+
* @param {string} access_token - User access token
|
|
8
|
+
* @param {string} client_secret - API client secret key for signature
|
|
9
|
+
* @param {number} merchandise_id - Unique merchandise ID on DonationAlerts
|
|
10
|
+
* @param {Record<string, string>} title - Object with merchandise titles in different locales (en_US required)
|
|
11
|
+
* @param {string} currency - Currency code (EUR, USD, RUB, BRL, TRY)
|
|
12
|
+
* @param {number} price_user - Revenue added to streamer for each sale
|
|
13
|
+
* @param {number} price_service - Revenue added to DonationAlerts for each sale
|
|
14
|
+
* @param {number} [is_active=0] - 0 or 1, whether merchandise is available for purchase
|
|
15
|
+
* @param {number} [is_percentage=0] - 0 or 1, whether prices are percentages or absolute amounts
|
|
16
|
+
* @param {string} [url] - URL to merchandise's web page
|
|
17
|
+
* @param {string} [img_url] - URL to merchandise's image
|
|
18
|
+
* @param {number} [end_at_ts] - Unix timestamp when merchandise becomes inactive
|
|
19
|
+
*
|
|
20
|
+
* @returns {Promise<Merchandise>} Updated merchandise data
|
|
21
|
+
* @see {@link https://www.donationalerts.com/apidoc#api_v1__merchandises__update_merchandise}
|
|
22
|
+
*/
|
|
23
|
+
export default async function updateMerchandise(access_token, client_secret, merchandise_id, title, currency, price_user, price_service, is_active = 0, is_percentage = 0, url, img_url, end_at_ts) {
|
|
24
|
+
if (!access_token || typeof access_token !== "string") {
|
|
25
|
+
throw new Error("access_token must be a non-empty string");
|
|
26
|
+
}
|
|
27
|
+
if (!client_secret || typeof client_secret !== "string") {
|
|
28
|
+
throw new Error("client_secret must be a non-empty string");
|
|
29
|
+
}
|
|
30
|
+
if (typeof merchandise_id !== "number" || merchandise_id <= 0) {
|
|
31
|
+
throw new Error("merchandise_id must be a positive number");
|
|
32
|
+
}
|
|
33
|
+
if (!title || Object.keys(title).length === 0) {
|
|
34
|
+
throw new Error("title must be a non-empty object");
|
|
35
|
+
}
|
|
36
|
+
if (!currency || typeof currency !== "string") {
|
|
37
|
+
throw new Error("currency must be a non-empty string");
|
|
38
|
+
}
|
|
39
|
+
if (typeof price_user !== "number" || typeof price_service !== "number") {
|
|
40
|
+
throw new Error("price_user and price_service must be numbers");
|
|
41
|
+
}
|
|
42
|
+
try {
|
|
43
|
+
const params = {
|
|
44
|
+
currency,
|
|
45
|
+
price_user,
|
|
46
|
+
price_service,
|
|
47
|
+
is_active,
|
|
48
|
+
is_percentage
|
|
49
|
+
};
|
|
50
|
+
for (const [locale, value] of Object.entries(title)) {
|
|
51
|
+
params[`title[${locale}]`] = value;
|
|
52
|
+
}
|
|
53
|
+
if (url)
|
|
54
|
+
params.url = url;
|
|
55
|
+
if (img_url)
|
|
56
|
+
params.img_url = img_url;
|
|
57
|
+
if (end_at_ts !== undefined)
|
|
58
|
+
params.end_at_ts = end_at_ts;
|
|
59
|
+
const signature = generateSignature(params, client_secret);
|
|
60
|
+
params.signature = signature;
|
|
61
|
+
const formData = new URLSearchParams();
|
|
62
|
+
for (const [key, value] of Object.entries(params)) {
|
|
63
|
+
formData.append(key, String(value));
|
|
64
|
+
}
|
|
65
|
+
const response = await axios.put(`https://www.donationalerts.com/api/v1/merchandise/${merchandise_id}`, formData, {
|
|
66
|
+
headers: {
|
|
67
|
+
Authorization: `Bearer ${access_token}`,
|
|
68
|
+
"Content-Type": "application/x-www-form-urlencoded"
|
|
69
|
+
}
|
|
70
|
+
});
|
|
71
|
+
return response.data.data;
|
|
72
|
+
}
|
|
73
|
+
catch (error) {
|
|
74
|
+
throw new Error(formatAxiosError(error));
|
|
75
|
+
}
|
|
76
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { OAuthToken, OAuthScope } from "../Types/index.js";
|
|
2
|
+
/**
|
|
3
|
+
* Refresh Access token using Refresh token.
|
|
4
|
+
*
|
|
5
|
+
* @param {string} client_id - Your client (application) ID
|
|
6
|
+
* @param {string} client_secret - Your client (application) secret
|
|
7
|
+
* @param {string} refresh_token - User refresh token
|
|
8
|
+
* @param {OAuthScope[]} scopes - Array of access scopes
|
|
9
|
+
*
|
|
10
|
+
* @returns {Promise<OAuthToken>} A promise that resolves to the new token data from the API.
|
|
11
|
+
* @see {@link https://www.donationalerts.com/apidoc#authorization__authorization_code__getting_access_token}
|
|
12
|
+
*/
|
|
13
|
+
export default function updateOauthToken(client_id: string, client_secret: string, refresh_token: string, scopes: OAuthScope[]): Promise<OAuthToken>;
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import axios from "axios";
|
|
2
|
+
import { formatAxiosError } from "../utils.js";
|
|
3
|
+
/**
|
|
4
|
+
* Refresh Access token using Refresh token.
|
|
5
|
+
*
|
|
6
|
+
* @param {string} client_id - Your client (application) ID
|
|
7
|
+
* @param {string} client_secret - Your client (application) secret
|
|
8
|
+
* @param {string} refresh_token - User refresh token
|
|
9
|
+
* @param {OAuthScope[]} scopes - Array of access scopes
|
|
10
|
+
*
|
|
11
|
+
* @returns {Promise<OAuthToken>} A promise that resolves to the new token data from the API.
|
|
12
|
+
* @see {@link https://www.donationalerts.com/apidoc#authorization__authorization_code__getting_access_token}
|
|
13
|
+
*/
|
|
14
|
+
export default async function updateOauthToken(client_id, client_secret, refresh_token, scopes) {
|
|
15
|
+
if (!client_id || typeof client_id !== "string") {
|
|
16
|
+
throw new Error("client_id must be a non-empty string");
|
|
17
|
+
}
|
|
18
|
+
if (!client_secret || typeof client_secret !== "string") {
|
|
19
|
+
throw new Error("client_secret must be a non-empty string");
|
|
20
|
+
}
|
|
21
|
+
if (!refresh_token || typeof refresh_token !== "string") {
|
|
22
|
+
throw new Error("refresh_token must be a non-empty string");
|
|
23
|
+
}
|
|
24
|
+
if (!Array.isArray(scopes) || scopes.length === 0) {
|
|
25
|
+
throw new Error("scopes must be a non-empty array");
|
|
26
|
+
}
|
|
27
|
+
try {
|
|
28
|
+
const formData = new URLSearchParams();
|
|
29
|
+
formData.append("grant_type", "refresh_token");
|
|
30
|
+
formData.append("refresh_token", refresh_token);
|
|
31
|
+
formData.append("client_id", client_id);
|
|
32
|
+
formData.append("client_secret", client_secret);
|
|
33
|
+
formData.append("scope", Array.from(new Set(scopes)).join(" "));
|
|
34
|
+
const response = await axios.post("https://www.donationalerts.com/oauth/token", formData, {
|
|
35
|
+
headers: {
|
|
36
|
+
"Content-Type": "application/x-www-form-urlencoded"
|
|
37
|
+
}
|
|
38
|
+
});
|
|
39
|
+
return response.data;
|
|
40
|
+
}
|
|
41
|
+
catch (error) {
|
|
42
|
+
throw new Error(formatAxiosError(error));
|
|
43
|
+
}
|
|
44
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { Merchandise } from "../Types/index.js";
|
|
2
|
+
/**
|
|
3
|
+
* Update or create a merchandise by merchant and merchandise identifiers.
|
|
4
|
+
*
|
|
5
|
+
* @param {string} access_token - User access token
|
|
6
|
+
* @param {string} client_secret - API client secret key for signature
|
|
7
|
+
* @param {string} merchant_identifier - Merchant's ID on DonationAlerts
|
|
8
|
+
* @param {string} merchandise_identifier - Up to 16 characters long unique merchandise ID
|
|
9
|
+
* @param {Record<string, string>} title - Object with merchandise titles in different locales (en_US required)
|
|
10
|
+
* @param {string} currency - Currency code (EUR, USD, RUB, BRL, TRY)
|
|
11
|
+
* @param {number} price_user - Revenue added to streamer for each sale
|
|
12
|
+
* @param {number} price_service - Revenue added to DonationAlerts for each sale
|
|
13
|
+
* @param {number} [is_active=0] - 0 or 1, whether merchandise is available for purchase
|
|
14
|
+
* @param {number} [is_percentage=0] - 0 or 1, whether prices are percentages or absolute amounts
|
|
15
|
+
* @param {string} [url] - URL to merchandise's web page
|
|
16
|
+
* @param {string} [img_url] - URL to merchandise's image
|
|
17
|
+
* @param {number} [end_at_ts] - Unix timestamp when merchandise becomes inactive
|
|
18
|
+
*
|
|
19
|
+
* @returns {Promise<Merchandise>} Updated or created merchandise data
|
|
20
|
+
* @see {@link https://www.donationalerts.com/apidoc#api_v1__merchandises__update_or_create_merchandise}
|
|
21
|
+
*/
|
|
22
|
+
export default function updateOrCreateMerchandise(access_token: string, client_secret: string, merchant_identifier: string, merchandise_identifier: string, title: Record<string, string>, currency: string, price_user: number, price_service: number, is_active?: number, is_percentage?: number, url?: string, img_url?: string, end_at_ts?: number): Promise<Merchandise>;
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import axios from "axios";
|
|
2
|
+
import generateSignature from "./generateSignature.js";
|
|
3
|
+
import { formatAxiosError } from "../utils.js";
|
|
4
|
+
/**
|
|
5
|
+
* Update or create a merchandise by merchant and merchandise identifiers.
|
|
6
|
+
*
|
|
7
|
+
* @param {string} access_token - User access token
|
|
8
|
+
* @param {string} client_secret - API client secret key for signature
|
|
9
|
+
* @param {string} merchant_identifier - Merchant's ID on DonationAlerts
|
|
10
|
+
* @param {string} merchandise_identifier - Up to 16 characters long unique merchandise ID
|
|
11
|
+
* @param {Record<string, string>} title - Object with merchandise titles in different locales (en_US required)
|
|
12
|
+
* @param {string} currency - Currency code (EUR, USD, RUB, BRL, TRY)
|
|
13
|
+
* @param {number} price_user - Revenue added to streamer for each sale
|
|
14
|
+
* @param {number} price_service - Revenue added to DonationAlerts for each sale
|
|
15
|
+
* @param {number} [is_active=0] - 0 or 1, whether merchandise is available for purchase
|
|
16
|
+
* @param {number} [is_percentage=0] - 0 or 1, whether prices are percentages or absolute amounts
|
|
17
|
+
* @param {string} [url] - URL to merchandise's web page
|
|
18
|
+
* @param {string} [img_url] - URL to merchandise's image
|
|
19
|
+
* @param {number} [end_at_ts] - Unix timestamp when merchandise becomes inactive
|
|
20
|
+
*
|
|
21
|
+
* @returns {Promise<Merchandise>} Updated or created merchandise data
|
|
22
|
+
* @see {@link https://www.donationalerts.com/apidoc#api_v1__merchandises__update_or_create_merchandise}
|
|
23
|
+
*/
|
|
24
|
+
export default async function updateOrCreateMerchandise(access_token, client_secret, merchant_identifier, merchandise_identifier, title, currency, price_user, price_service, is_active = 0, is_percentage = 0, url, img_url, end_at_ts) {
|
|
25
|
+
if (!access_token || typeof access_token !== "string") {
|
|
26
|
+
throw new Error("access_token must be a non-empty string");
|
|
27
|
+
}
|
|
28
|
+
if (!client_secret || typeof client_secret !== "string") {
|
|
29
|
+
throw new Error("client_secret must be a non-empty string");
|
|
30
|
+
}
|
|
31
|
+
if (!merchant_identifier || typeof merchant_identifier !== "string") {
|
|
32
|
+
throw new Error("merchant_identifier must be a non-empty string");
|
|
33
|
+
}
|
|
34
|
+
if (!merchandise_identifier || typeof merchandise_identifier !== "string") {
|
|
35
|
+
throw new Error("merchandise_identifier must be a non-empty string");
|
|
36
|
+
}
|
|
37
|
+
if (!title || Object.keys(title).length === 0) {
|
|
38
|
+
throw new Error("title must be a non-empty object");
|
|
39
|
+
}
|
|
40
|
+
if (!currency || typeof currency !== "string") {
|
|
41
|
+
throw new Error("currency must be a non-empty string");
|
|
42
|
+
}
|
|
43
|
+
if (typeof price_user !== "number" || typeof price_service !== "number") {
|
|
44
|
+
throw new Error("price_user and price_service must be numbers");
|
|
45
|
+
}
|
|
46
|
+
try {
|
|
47
|
+
const params = {
|
|
48
|
+
currency,
|
|
49
|
+
price_user,
|
|
50
|
+
price_service,
|
|
51
|
+
is_active,
|
|
52
|
+
is_percentage
|
|
53
|
+
};
|
|
54
|
+
for (const [locale, value] of Object.entries(title)) {
|
|
55
|
+
params[`title[${locale}]`] = value;
|
|
56
|
+
}
|
|
57
|
+
if (url)
|
|
58
|
+
params.url = url;
|
|
59
|
+
if (img_url)
|
|
60
|
+
params.img_url = img_url;
|
|
61
|
+
if (end_at_ts !== undefined)
|
|
62
|
+
params.end_at_ts = end_at_ts;
|
|
63
|
+
const signature = generateSignature(params, client_secret);
|
|
64
|
+
params.signature = signature;
|
|
65
|
+
const formData = new URLSearchParams();
|
|
66
|
+
for (const [key, value] of Object.entries(params)) {
|
|
67
|
+
formData.append(key, String(value));
|
|
68
|
+
}
|
|
69
|
+
const response = await axios.put(`https://www.donationalerts.com/api/v1/merchandise/${merchant_identifier}/${merchandise_identifier}`, formData, {
|
|
70
|
+
headers: {
|
|
71
|
+
Authorization: `Bearer ${access_token}`,
|
|
72
|
+
"Content-Type": "application/x-www-form-urlencoded"
|
|
73
|
+
}
|
|
74
|
+
});
|
|
75
|
+
return response.data.data;
|
|
76
|
+
}
|
|
77
|
+
catch (error) {
|
|
78
|
+
throw new Error(formatAxiosError(error));
|
|
79
|
+
}
|
|
80
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
interface CustomAlerts {
|
|
2
|
+
id: number;
|
|
3
|
+
external_id: string | null;
|
|
4
|
+
header: string | null;
|
|
5
|
+
message: string | null;
|
|
6
|
+
image_url: string | null;
|
|
7
|
+
sound_url: string | null;
|
|
8
|
+
is_shown: 0 | 1;
|
|
9
|
+
created_at: string;
|
|
10
|
+
shown_at: string | null;
|
|
11
|
+
}
|
|
12
|
+
export default CustomAlerts;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
interface DonationsAlerts {
|
|
2
|
+
data: {
|
|
3
|
+
id: number;
|
|
4
|
+
name: string;
|
|
5
|
+
username: string;
|
|
6
|
+
message: string;
|
|
7
|
+
message_type: string;
|
|
8
|
+
amount: number;
|
|
9
|
+
currency: string;
|
|
10
|
+
is_shown: number;
|
|
11
|
+
created_at: string;
|
|
12
|
+
shown_at: string | null;
|
|
13
|
+
amount_in_user_currency?: number;
|
|
14
|
+
}[];
|
|
15
|
+
links: {
|
|
16
|
+
first: string;
|
|
17
|
+
last: string;
|
|
18
|
+
prev: string | null;
|
|
19
|
+
next: string | null;
|
|
20
|
+
};
|
|
21
|
+
meta: {
|
|
22
|
+
current_page: number;
|
|
23
|
+
from: number;
|
|
24
|
+
last_page: number;
|
|
25
|
+
path: string;
|
|
26
|
+
per_page: number;
|
|
27
|
+
to: number;
|
|
28
|
+
total: number;
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
export default DonationsAlerts;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
interface Merchandise {
|
|
2
|
+
id: number;
|
|
3
|
+
merchant: {
|
|
4
|
+
identifier: string;
|
|
5
|
+
name: string;
|
|
6
|
+
};
|
|
7
|
+
identifier: string;
|
|
8
|
+
title: Record<string, string>;
|
|
9
|
+
is_active: 0 | 1;
|
|
10
|
+
is_percentage: 0 | 1;
|
|
11
|
+
currency: string;
|
|
12
|
+
price_user: number;
|
|
13
|
+
price_service: number;
|
|
14
|
+
url: string | null;
|
|
15
|
+
img_url: string | null;
|
|
16
|
+
end_at: string | null;
|
|
17
|
+
}
|
|
18
|
+
export default Merchandise;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
interface MerchandiseSale {
|
|
2
|
+
id: number;
|
|
3
|
+
name: string;
|
|
4
|
+
external_id: string;
|
|
5
|
+
username: string | null;
|
|
6
|
+
message: string | null;
|
|
7
|
+
amount: number;
|
|
8
|
+
currency: string;
|
|
9
|
+
bought_amount: number;
|
|
10
|
+
is_shown: number;
|
|
11
|
+
created_at: string;
|
|
12
|
+
shown_at: string | null;
|
|
13
|
+
}
|
|
14
|
+
export default MerchandiseSale;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
declare enum OAuthScope {
|
|
2
|
+
UserShow = "oauth-user-show",
|
|
3
|
+
DonationSubscribe = "oauth-donation-subscribe",
|
|
4
|
+
DonationIndex = "oauth-donation-index",
|
|
5
|
+
CustomAlertStore = "oauth-custom_alert-store",
|
|
6
|
+
GoalSubscribe = "oauth-goal-subscribe",
|
|
7
|
+
PollSubscribe = "oauth-poll-subscribe"
|
|
8
|
+
}
|
|
9
|
+
export default OAuthScope;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
var OAuthScope;
|
|
2
|
+
(function (OAuthScope) {
|
|
3
|
+
OAuthScope["UserShow"] = "oauth-user-show";
|
|
4
|
+
OAuthScope["DonationSubscribe"] = "oauth-donation-subscribe";
|
|
5
|
+
OAuthScope["DonationIndex"] = "oauth-donation-index";
|
|
6
|
+
OAuthScope["CustomAlertStore"] = "oauth-custom_alert-store";
|
|
7
|
+
OAuthScope["GoalSubscribe"] = "oauth-goal-subscribe";
|
|
8
|
+
OAuthScope["PollSubscribe"] = "oauth-poll-subscribe";
|
|
9
|
+
})(OAuthScope || (OAuthScope = {}));
|
|
10
|
+
export default OAuthScope;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import CustomAlerts from "./CustomAlerts.js";
|
|
2
|
+
import DonationsAlerts from "./DonationsAlerts.js";
|
|
3
|
+
import Merchandise from "./Merchandise.js";
|
|
4
|
+
import MerchandiseSale from "./MerchandiseSale.js";
|
|
5
|
+
import OAuthScope from "./OAuthScope.js";
|
|
6
|
+
import OAuthToken from "./OAuthToken.js";
|
|
7
|
+
import User from "./User.js";
|
|
8
|
+
export { CustomAlerts, DonationsAlerts, Merchandise, MerchandiseSale, OAuthScope, OAuthToken, User };
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import TypedEmitter from "typed-emitter";
|
|
2
|
+
interface WSClientOptions {
|
|
3
|
+
access_token: string;
|
|
4
|
+
channels?: string[];
|
|
5
|
+
autoReconnect?: boolean;
|
|
6
|
+
}
|
|
7
|
+
type MessageEvents = {
|
|
8
|
+
open: () => void;
|
|
9
|
+
message: (data: any) => void;
|
|
10
|
+
close: (code: number, reason: Buffer) => void;
|
|
11
|
+
error: (error: Error) => void;
|
|
12
|
+
reconnect: () => void;
|
|
13
|
+
};
|
|
14
|
+
declare const CentrifugeClient_base: new () => TypedEmitter<MessageEvents>;
|
|
15
|
+
/**
|
|
16
|
+
* Class for interacting with Centrifuge donationalerts
|
|
17
|
+
*
|
|
18
|
+
* @param {WSClientOptions} options - Connection options
|
|
19
|
+
* @param {string} options.access_token - User access token
|
|
20
|
+
* @param {string[]} [options.channels] - Custom channels to subscribe to (defaults to donation channel)
|
|
21
|
+
* @param {boolean} [options.autoReconnect=false] - Automatically reconnect on connection close
|
|
22
|
+
*/
|
|
23
|
+
export default class CentrifugeClient extends CentrifugeClient_base {
|
|
24
|
+
private WebSocket;
|
|
25
|
+
private user;
|
|
26
|
+
private userPromise;
|
|
27
|
+
private access_token;
|
|
28
|
+
private channels;
|
|
29
|
+
private autoReconnect;
|
|
30
|
+
private isAuthorized;
|
|
31
|
+
private reconnectTimer;
|
|
32
|
+
private isReconnecting;
|
|
33
|
+
private authMessageHandler;
|
|
34
|
+
constructor(options: WSClientOptions);
|
|
35
|
+
/**
|
|
36
|
+
* Obtain user data
|
|
37
|
+
*
|
|
38
|
+
* @param {string} access_token - User access token
|
|
39
|
+
* @returns {Promise<User>} User data
|
|
40
|
+
*/
|
|
41
|
+
private getUser;
|
|
42
|
+
/**
|
|
43
|
+
* Get channels to subscribe to
|
|
44
|
+
*
|
|
45
|
+
* @returns {Promise<string[]>} Array of channel identifiers
|
|
46
|
+
*/
|
|
47
|
+
private getChannels;
|
|
48
|
+
/**
|
|
49
|
+
* Create a new WebSocket connection
|
|
50
|
+
*/
|
|
51
|
+
createNewConnection(): void;
|
|
52
|
+
/**
|
|
53
|
+
* Forward events through a TypedEmitter
|
|
54
|
+
*/
|
|
55
|
+
private setupEvent;
|
|
56
|
+
/**
|
|
57
|
+
* Authorize WebSocket and subscribe to selected channels
|
|
58
|
+
*/
|
|
59
|
+
authorization(): Promise<void>;
|
|
60
|
+
/**
|
|
61
|
+
* Send a message through the WebSocket connection
|
|
62
|
+
*
|
|
63
|
+
* @param {string} message - JSON-encoded message to send
|
|
64
|
+
*/
|
|
65
|
+
sendMessage(message: string): void;
|
|
66
|
+
/**
|
|
67
|
+
* Close the WebSocket connection and stop auto-reconnect
|
|
68
|
+
*/
|
|
69
|
+
close(): void;
|
|
70
|
+
}
|
|
71
|
+
export {};
|