@kash-88/alerts 1.0.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.
Files changed (62) hide show
  1. package/dist/example/getAuthorizeLink.d.ts +1 -0
  2. package/dist/example/getAuthorizeLink.js +13 -0
  3. package/dist/example/getOauthToken.d.ts +1 -0
  4. package/dist/example/getOauthToken.js +16 -0
  5. package/dist/example/getUser.d.ts +1 -0
  6. package/dist/example/getUser.js +14 -0
  7. package/dist/example/getUserChannel.d.ts +1 -0
  8. package/dist/example/getUserChannel.js +12 -0
  9. package/dist/example/updateAccessToken.d.ts +1 -0
  10. package/dist/example/updateAccessToken.js +16 -0
  11. package/dist/example/wsExample.d.ts +1 -0
  12. package/dist/example/wsExample.js +42 -0
  13. package/dist/src/example/getAuthorizeLink.d.ts +1 -0
  14. package/dist/src/example/getAuthorizeLink.js +13 -0
  15. package/dist/src/example/getOauthToken.d.ts +1 -0
  16. package/dist/src/example/getOauthToken.js +16 -0
  17. package/dist/src/example/getUser.d.ts +1 -0
  18. package/dist/src/example/getUser.js +14 -0
  19. package/dist/src/example/getUserChannel.d.ts +1 -0
  20. package/dist/src/example/getUserChannel.js +12 -0
  21. package/dist/src/example/updateAccessToken.d.ts +1 -0
  22. package/dist/src/example/updateAccessToken.js +16 -0
  23. package/dist/src/example/wsExample.d.ts +1 -0
  24. package/dist/src/example/wsExample.js +42 -0
  25. package/dist/src/func/getAuthorizeLink.d.ts +18 -0
  26. package/dist/src/func/getAuthorizeLink.js +29 -0
  27. package/dist/src/func/getOauthToken.d.ts +27 -0
  28. package/dist/src/func/getOauthToken.js +42 -0
  29. package/dist/src/func/getPrivateToken.d.ts +29 -0
  30. package/dist/src/func/getPrivateToken.js +46 -0
  31. package/dist/src/func/getUser.d.ts +23 -0
  32. package/dist/src/func/getUser.js +38 -0
  33. package/dist/src/func/getUserChannel.d.ts +19 -0
  34. package/dist/src/func/getUserChannel.js +32 -0
  35. package/dist/src/func/updateAccessToken.d.ts +24 -0
  36. package/dist/src/func/updateAccessToken.js +39 -0
  37. package/dist/src/index.d.ts +9 -0
  38. package/dist/src/index.js +9 -0
  39. package/dist/src/types.d.ts +33 -0
  40. package/dist/src/types.js +1 -0
  41. package/dist/src/utils.d.ts +21 -0
  42. package/dist/src/utils.js +48 -0
  43. package/dist/src/ws/CentrifugeClient.d.ts +31 -0
  44. package/dist/src/ws/CentrifugeClient.js +71 -0
  45. package/package.json +59 -0
  46. package/readme.md +82 -0
  47. package/src/example/getAuthorizeLink.ts +15 -0
  48. package/src/example/getOauthToken.ts +18 -0
  49. package/src/example/getUser.ts +16 -0
  50. package/src/example/getUserChannel.ts +14 -0
  51. package/src/example/updateAccessToken.ts +18 -0
  52. package/src/example/wsExample.ts +52 -0
  53. package/src/func/getAuthorizeLink.ts +33 -0
  54. package/src/func/getOauthToken.ts +46 -0
  55. package/src/func/getPrivateToken.ts +53 -0
  56. package/src/func/getUser.ts +42 -0
  57. package/src/func/getUserChannel.ts +34 -0
  58. package/src/func/updateAccessToken.ts +43 -0
  59. package/src/index.ts +19 -0
  60. package/src/types.ts +38 -0
  61. package/src/utils.ts +56 -0
  62. package/src/ws/CentrifugeClient.ts +108 -0
@@ -0,0 +1 @@
1
+ import 'dotenv/config';
@@ -0,0 +1,13 @@
1
+ import 'dotenv/config';
2
+ import { getAuthorizeLink } from '../src/index';
3
+ import { checkEnv } from '../src/utils';
4
+ checkEnv(['CLIENT_ID', 'SCOPE']);
5
+ const client_id = process.env.CLIENT_ID;
6
+ const scope = process.env.SCOPE ? process.env.SCOPE.split(',') : ['oauth-user-show'];
7
+ try {
8
+ const link = getAuthorizeLink({ client_id, scope });
9
+ console.log('Authorize link:', link);
10
+ }
11
+ catch (error) {
12
+ console.error('Error:', error.message);
13
+ }
@@ -0,0 +1 @@
1
+ import 'dotenv/config';
@@ -0,0 +1,16 @@
1
+ import 'dotenv/config';
2
+ import { getOauthToken } from '../src/index';
3
+ import { checkEnv } from '../src/utils';
4
+ checkEnv(['CLIENT_ID', 'CLIENT_SECRET', 'CODE']);
5
+ const client_id = process.env.CLIENT_ID;
6
+ const client_secret = process.env.CLIENT_SECRET;
7
+ const code = process.env.CODE;
8
+ (async () => {
9
+ try {
10
+ const token = await getOauthToken({ client_id, client_secret, code });
11
+ console.log('Oauth token:', token);
12
+ }
13
+ catch (error) {
14
+ console.error('Error:', error.message);
15
+ }
16
+ })();
@@ -0,0 +1 @@
1
+ import 'dotenv/config';
@@ -0,0 +1,14 @@
1
+ import 'dotenv/config';
2
+ import { getUser } from '../src/index';
3
+ import { checkEnv } from '../src/utils';
4
+ checkEnv(['ACCESS_TOKEN']);
5
+ const access_token = process.env.ACCESS_TOKEN;
6
+ (async () => {
7
+ try {
8
+ const user = await getUser(access_token);
9
+ console.log('User:', user);
10
+ }
11
+ catch (error) {
12
+ console.error('Error:', error.message);
13
+ }
14
+ })();
@@ -0,0 +1 @@
1
+ import 'dotenv/config';
@@ -0,0 +1,12 @@
1
+ import 'dotenv/config';
2
+ import { getUserChannel } from '../src/index';
3
+ import { checkEnv } from '../src/utils';
4
+ checkEnv(['CLIENT_ID']);
5
+ const id = process.env.CLIENT_ID;
6
+ try {
7
+ const channel = getUserChannel(id);
8
+ console.log('User channel:', channel);
9
+ }
10
+ catch (error) {
11
+ console.error('Error:', error.message);
12
+ }
@@ -0,0 +1 @@
1
+ import 'dotenv/config';
@@ -0,0 +1,16 @@
1
+ import 'dotenv/config';
2
+ import { updateAccessToken } from '../src/index';
3
+ import { checkEnv } from '../src/utils';
4
+ checkEnv(['CLIENT_ID', 'CLIENT_SECRET', 'REFRESH_TOKEN']);
5
+ const client_id = process.env.CLIENT_ID;
6
+ const client_secret = process.env.CLIENT_SECRET;
7
+ const refresh_token = process.env.REFRESH_TOKEN;
8
+ (async () => {
9
+ try {
10
+ const token = await updateAccessToken({ client_id, client_secret, refresh_token });
11
+ console.log('Updated token:', token);
12
+ }
13
+ catch (error) {
14
+ console.error('Error:', error.message);
15
+ }
16
+ })();
@@ -0,0 +1 @@
1
+ import 'dotenv/config';
@@ -0,0 +1,42 @@
1
+ import 'dotenv/config';
2
+ import { getUser, getUserChannel, CentrifugeClient } from '../src/index';
3
+ import { checkEnv } from '../src/utils';
4
+ checkEnv(['CLIENT_ID', 'ACCESS_TOKEN', 'SOCKET_CONNECTION_TOKEN']);
5
+ const access_token = process.env.ACCESS_TOKEN;
6
+ let isConnectToPrivate = false;
7
+ async function main() {
8
+ try {
9
+ const user = await getUser(access_token);
10
+ const channel = getUserChannel(user.id);
11
+ const socket_connection_token = String(process.env.SOCKET_CONNECTION_TOKEN);
12
+ const client = new CentrifugeClient({
13
+ channel,
14
+ socket_connection_token,
15
+ access_token
16
+ });
17
+ const ws = client.createConnection();
18
+ ws.on('open', async () => {
19
+ console.log('WebSocket соединение открыто');
20
+ client.confirmConnection(socket_connection_token);
21
+ });
22
+ ws.on('message', (message) => {
23
+ const srt = message.toString('utf8');
24
+ const json = JSON.parse(srt);
25
+ if (json.id = 1 && !isConnectToPrivate) {
26
+ isConnectToPrivate = true;
27
+ return client.connectPrivateToken(channel, json.result.client);
28
+ }
29
+ console.log(srt);
30
+ });
31
+ ws.on('close', () => {
32
+ console.log('WebSocket соединение закрыто');
33
+ });
34
+ ws.on('error', (err) => {
35
+ console.error('Ошибка WebSocket:', err);
36
+ });
37
+ }
38
+ catch (error) {
39
+ console.error('Ошибка:', error.message);
40
+ }
41
+ }
42
+ main();
@@ -0,0 +1 @@
1
+ import "dotenv/config";
@@ -0,0 +1,13 @@
1
+ import "dotenv/config";
2
+ import { getAuthorizeLink } from "../index";
3
+ import { checkEnv } from "../utils";
4
+ checkEnv(["CLIENT_ID", "SCOPE"]);
5
+ const client_id = process.env.CLIENT_ID;
6
+ const scope = process.env.SCOPE ? process.env.SCOPE.split(",") : ["oauth-user-show"];
7
+ try {
8
+ const link = getAuthorizeLink({ client_id, scope });
9
+ console.log("Authorize link:", link);
10
+ }
11
+ catch (error) {
12
+ console.error("Error:", error.message);
13
+ }
@@ -0,0 +1 @@
1
+ import "dotenv/config";
@@ -0,0 +1,16 @@
1
+ import "dotenv/config";
2
+ import { getOauthToken } from "../index";
3
+ import { checkEnv } from "../utils";
4
+ checkEnv(["CLIENT_ID", "CLIENT_SECRET", "CODE"]);
5
+ const client_id = process.env.CLIENT_ID;
6
+ const client_secret = process.env.CLIENT_SECRET;
7
+ const code = process.env.CODE;
8
+ (async () => {
9
+ try {
10
+ const token = await getOauthToken({ client_id, client_secret, code });
11
+ console.log("Oauth token:", token);
12
+ }
13
+ catch (error) {
14
+ console.error("Error:", error.message);
15
+ }
16
+ })();
@@ -0,0 +1 @@
1
+ import "dotenv/config";
@@ -0,0 +1,14 @@
1
+ import "dotenv/config";
2
+ import { getUser } from "../index";
3
+ import { checkEnv } from "../utils";
4
+ checkEnv(["ACCESS_TOKEN"]);
5
+ const access_token = process.env.ACCESS_TOKEN;
6
+ (async () => {
7
+ try {
8
+ const user = await getUser(access_token);
9
+ console.log("User:", user);
10
+ }
11
+ catch (error) {
12
+ console.error("Error:", error.message);
13
+ }
14
+ })();
@@ -0,0 +1 @@
1
+ import "dotenv/config";
@@ -0,0 +1,12 @@
1
+ import "dotenv/config";
2
+ import { getUserChannel } from "../index";
3
+ import { checkEnv } from "../utils";
4
+ checkEnv(["CLIENT_ID"]);
5
+ const id = process.env.CLIENT_ID;
6
+ try {
7
+ const channel = getUserChannel(id);
8
+ console.log("User channel:", channel);
9
+ }
10
+ catch (error) {
11
+ console.error("Error:", error.message);
12
+ }
@@ -0,0 +1 @@
1
+ import "dotenv/config";
@@ -0,0 +1,16 @@
1
+ import "dotenv/config";
2
+ import { updateAccessToken } from "../index";
3
+ import { checkEnv } from "../utils";
4
+ checkEnv(["CLIENT_ID", "CLIENT_SECRET", "REFRESH_TOKEN"]);
5
+ const client_id = process.env.CLIENT_ID;
6
+ const client_secret = process.env.CLIENT_SECRET;
7
+ const refresh_token = process.env.REFRESH_TOKEN;
8
+ (async () => {
9
+ try {
10
+ const token = await updateAccessToken({ client_id, client_secret, refresh_token });
11
+ console.log("Updated token:", token);
12
+ }
13
+ catch (error) {
14
+ console.error("Error:", error.message);
15
+ }
16
+ })();
@@ -0,0 +1 @@
1
+ import "dotenv/config";
@@ -0,0 +1,42 @@
1
+ import "dotenv/config";
2
+ import { getUser, getUserChannel, CentrifugeClient } from "../index";
3
+ import { checkEnv } from "../utils";
4
+ checkEnv(["CLIENT_ID", "ACCESS_TOKEN", "SOCKET_CONNECTION_TOKEN"]);
5
+ const access_token = process.env.ACCESS_TOKEN;
6
+ let isConnectToPrivate = false;
7
+ async function main() {
8
+ try {
9
+ const user = await getUser(access_token);
10
+ const channel = getUserChannel(user.id);
11
+ const socket_connection_token = String(process.env.SOCKET_CONNECTION_TOKEN);
12
+ const client = new CentrifugeClient({
13
+ channel,
14
+ socket_connection_token,
15
+ access_token
16
+ });
17
+ const ws = client.createConnection();
18
+ ws.on("open", async () => {
19
+ console.log("WebSocket соединение открыто");
20
+ client.confirmConnection(socket_connection_token);
21
+ });
22
+ ws.on("message", (message) => {
23
+ const srt = message.toString("utf8");
24
+ const json = JSON.parse(srt);
25
+ if (json.id = 1 && !isConnectToPrivate) {
26
+ isConnectToPrivate = true;
27
+ return client.connectPrivateToken(channel, json.result.client);
28
+ }
29
+ console.log(srt);
30
+ });
31
+ ws.on("close", () => {
32
+ console.log("WebSocket соединение закрыто");
33
+ });
34
+ ws.on("error", (err) => {
35
+ console.error("Ошибка WebSocket:", err);
36
+ });
37
+ }
38
+ catch (error) {
39
+ console.error("Ошибка:", error.message);
40
+ }
41
+ }
42
+ main();
@@ -0,0 +1,18 @@
1
+ import { GetAuthorizeLinkData } from "../types";
2
+ /**
3
+ * Generates an authorization link for the DonationAlerts API.
4
+ *
5
+ * @example
6
+ * import { getAuthorizeLink } from "@kash.88/alerts";
7
+ *
8
+ * const authLink = getAuthorizeLink({
9
+ * client_id: "YOUR_CLIENT_ID",
10
+ * scope: ["oauth-user-show"]
11
+ * });
12
+ * console.log(authLink);
13
+ *
14
+ * @param {GetAuthorizeLinkData} data - The data for generating the link.
15
+ * @returns {string} The authorization URL.
16
+ * @see {@link https://www.donationalerts.com/apidoc#authorization__authorization_code__authorization_request}
17
+ */
18
+ export default function getAuthorizeLink(data: GetAuthorizeLinkData): string;
@@ -0,0 +1,29 @@
1
+ import { validateDataObject } from "../utils";
2
+ /**
3
+ * Generates an authorization link for the DonationAlerts API.
4
+ *
5
+ * @example
6
+ * import { getAuthorizeLink } from "@kash.88/alerts";
7
+ *
8
+ * const authLink = getAuthorizeLink({
9
+ * client_id: "YOUR_CLIENT_ID",
10
+ * scope: ["oauth-user-show"]
11
+ * });
12
+ * console.log(authLink);
13
+ *
14
+ * @param {GetAuthorizeLinkData} data - The data for generating the link.
15
+ * @returns {string} The authorization URL.
16
+ * @see {@link https://www.donationalerts.com/apidoc#authorization__authorization_code__authorization_request}
17
+ */
18
+ export default function getAuthorizeLink(data) {
19
+ try {
20
+ validateDataObject(data, ["client_id", "scope"]);
21
+ if (!Array.isArray(data.scope)) {
22
+ throw new Error("You must provide \"scope\" as an array in the data object.");
23
+ }
24
+ return `https://www.donationalerts.com/oauth/authorize?client_id=${data.client_id}&response_type=code&scope=${data.scope.join("%20")}`;
25
+ }
26
+ catch (error) {
27
+ throw new Error(error?.response?.data?.error_description || error?.message || error);
28
+ }
29
+ }
@@ -0,0 +1,27 @@
1
+ import { GetOauthData, OauthToken } from "../types";
2
+ /**
3
+ * Exchanges an authorization code for an access token.
4
+ *
5
+ * @example
6
+ * import { getOauthToken } from "@kash.88/alerts";
7
+ *
8
+ * // The "code" is received after the user authorizes your application
9
+ * // via the link generated by "getAuthorizeLink".
10
+ *
11
+ * try {
12
+ * const tokenData = await getOauthToken({
13
+ * client_id: "YOUR_CLIENT_ID",
14
+ * client_secret: "YOUR_CLIENT_SECRET",
15
+ * code: "AUTHORIZATION_CODE"
16
+ * });
17
+ *
18
+ * console.log(tokenData.access_token);
19
+ * } catch (error) {
20
+ * console.error("Error getting Oauth token:", error.response.data);
21
+ * }
22
+ *
23
+ * @param {GetOauthData} data - The data for the token request.
24
+ * @returns {Promise<OauthToken>} A promise that resolves to the token data from the API.
25
+ * @see {@link https://www.donationalerts.com/apidoc#authorization__authorization_code__getting_access_token}
26
+ */
27
+ export default function getOauthToken(data: GetOauthData): Promise<OauthToken>;
@@ -0,0 +1,42 @@
1
+ import axios from "axios";
2
+ import { validateDataObject } from "../utils";
3
+ /**
4
+ * Exchanges an authorization code for an access token.
5
+ *
6
+ * @example
7
+ * import { getOauthToken } from "@kash.88/alerts";
8
+ *
9
+ * // The "code" is received after the user authorizes your application
10
+ * // via the link generated by "getAuthorizeLink".
11
+ *
12
+ * try {
13
+ * const tokenData = await getOauthToken({
14
+ * client_id: "YOUR_CLIENT_ID",
15
+ * client_secret: "YOUR_CLIENT_SECRET",
16
+ * code: "AUTHORIZATION_CODE"
17
+ * });
18
+ *
19
+ * console.log(tokenData.access_token);
20
+ * } catch (error) {
21
+ * console.error("Error getting Oauth token:", error.response.data);
22
+ * }
23
+ *
24
+ * @param {GetOauthData} data - The data for the token request.
25
+ * @returns {Promise<OauthToken>} A promise that resolves to the token data from the API.
26
+ * @see {@link https://www.donationalerts.com/apidoc#authorization__authorization_code__getting_access_token}
27
+ */
28
+ export default async function getOauthToken(data) {
29
+ try {
30
+ validateDataObject(data, ["client_id", "client_secret", "code"]);
31
+ const response = await axios.post("https://www.donationalerts.com/oauth/token", {
32
+ grant_type: "authorization_code",
33
+ client_id: data.client_id,
34
+ client_secret: data.client_secret,
35
+ code: data.code
36
+ });
37
+ return response.data;
38
+ }
39
+ catch (error) {
40
+ throw new Error(error?.response?.data?.error_description || error?.message || error);
41
+ }
42
+ }
@@ -0,0 +1,29 @@
1
+ import { GetPrivateToken } from "../types";
2
+ /**
3
+ * Gets a private token for subscribing to a DonationAlerts channel via Centrifuge.
4
+ *
5
+ * @example
6
+ * import { connectPrivateToken } from "../index";
7
+ *
8
+ * // The "channel" can be obtained using the "getUserChannel" function,
9
+ * // and the "uuidv4_client_id" is provided during authentication in WebSocket (ws).
10
+ *
11
+ * try {
12
+ * const token = await connectPrivateToken({
13
+ * channel: "USER_CHANNEL",
14
+ * uuidv4_client_id: "USER_uuid_ID",
15
+ * access_token: "USER_ACCESS_TOKEN"
16
+ * });
17
+ *
18
+ * console.log(token);
19
+ * } catch (error) {
20
+ * console.error("Error getting Oauth token:", error.response.data);
21
+ * }
22
+ *
23
+ * @param {Object} params - Parameters for getting the token.
24
+ * @param {string} params.channel - Channel name to subscribe.
25
+ * @param {string} params.uuidv4_client_id - UUID v4 client ID.
26
+ * @param {string} params.access_token - OAuth access token of the user.
27
+ * @returns {Promise<string>} - Token for channel subscription.
28
+ */
29
+ export declare function getPrivateToken(data: GetPrivateToken): Promise<string>;
@@ -0,0 +1,46 @@
1
+ import axios from "axios";
2
+ import { validateDataObject } from "../utils";
3
+ /**
4
+ * Gets a private token for subscribing to a DonationAlerts channel via Centrifuge.
5
+ *
6
+ * @example
7
+ * import { connectPrivateToken } from "../index";
8
+ *
9
+ * // The "channel" can be obtained using the "getUserChannel" function,
10
+ * // and the "uuidv4_client_id" is provided during authentication in WebSocket (ws).
11
+ *
12
+ * try {
13
+ * const token = await connectPrivateToken({
14
+ * channel: "USER_CHANNEL",
15
+ * uuidv4_client_id: "USER_uuid_ID",
16
+ * access_token: "USER_ACCESS_TOKEN"
17
+ * });
18
+ *
19
+ * console.log(token);
20
+ * } catch (error) {
21
+ * console.error("Error getting Oauth token:", error.response.data);
22
+ * }
23
+ *
24
+ * @param {Object} params - Parameters for getting the token.
25
+ * @param {string} params.channel - Channel name to subscribe.
26
+ * @param {string} params.uuidv4_client_id - UUID v4 client ID.
27
+ * @param {string} params.access_token - OAuth access token of the user.
28
+ * @returns {Promise<string>} - Token for channel subscription.
29
+ */
30
+ export async function getPrivateToken(data) {
31
+ try {
32
+ validateDataObject(data, ["channel", "uuidv4_client_id", "access_token"]);
33
+ const response = await axios.post("https://www.donationalerts.com/api/v1/centrifuge/subscribe", {
34
+ channels: [data.channel],
35
+ client: data.uuidv4_client_id
36
+ }, {
37
+ headers: {
38
+ "Authorization": `Bearer ${data.access_token}`
39
+ }
40
+ });
41
+ return response.data.channels[0].token;
42
+ }
43
+ catch (error) {
44
+ throw new Error(error?.response?.data?.error_description || error?.message || error);
45
+ }
46
+ }
@@ -0,0 +1,23 @@
1
+ import { User } from "../types";
2
+ /**
3
+ * Fetches the profile information for the authenticated user.
4
+ *
5
+ * @example
6
+ * import { getUser } from "@kash.88/alerts";
7
+ *
8
+ * // Get an access_token using getOauthToken or updateAccessToken
9
+ *
10
+ * try {
11
+ * const accessToken = "USER_ACCESS_TOKEN";
12
+ * const user = await getUser(accessToken);
13
+ *
14
+ * console.log(user);
15
+ * } catch (error) {
16
+ * console.error("Error fetching user:", error.response.data);
17
+ * }
18
+ *
19
+ * @param {string} access_token - The access token for authentication.
20
+ * @returns {Promise<User>} A promise that resolves to the user profile data.
21
+ * @see {@link https://www.donationalerts.com/apidoc#api_v1__users__user_profile_information}
22
+ */
23
+ export default function getUser(access_token: string): Promise<User>;
@@ -0,0 +1,38 @@
1
+ import axios from "axios";
2
+ /**
3
+ * Fetches the profile information for the authenticated user.
4
+ *
5
+ * @example
6
+ * import { getUser } from "@kash.88/alerts";
7
+ *
8
+ * // Get an access_token using getOauthToken or updateAccessToken
9
+ *
10
+ * try {
11
+ * const accessToken = "USER_ACCESS_TOKEN";
12
+ * const user = await getUser(accessToken);
13
+ *
14
+ * console.log(user);
15
+ * } catch (error) {
16
+ * console.error("Error fetching user:", error.response.data);
17
+ * }
18
+ *
19
+ * @param {string} access_token - The access token for authentication.
20
+ * @returns {Promise<User>} A promise that resolves to the user profile data.
21
+ * @see {@link https://www.donationalerts.com/apidoc#api_v1__users__user_profile_information}
22
+ */
23
+ export default async function getUser(access_token) {
24
+ try {
25
+ if (!access_token) {
26
+ throw new Error("You must provide \"access_token\" as a non-empty string.");
27
+ }
28
+ const response = await axios.get("https://www.donationalerts.com/api/v1/user/oauth", {
29
+ headers: {
30
+ Authorization: `Bearer ${access_token}`
31
+ }
32
+ });
33
+ return response.data.data;
34
+ }
35
+ catch (error) {
36
+ throw new Error(error?.response?.data?.error_description || error?.message || error);
37
+ }
38
+ }
@@ -0,0 +1,19 @@
1
+ /**
2
+ * Fetches the profile information for the authenticated user.
3
+ *
4
+ * @example
5
+ * import { getUserChannel } from "@kash.88/alerts";
6
+ *
7
+ * // The "id" can be obtained using the "getUser" function,
8
+ *
9
+ * try {
10
+ * const userId = "USER_ID";
11
+ * const channelId = getUserChannel(userId);
12
+ * } catch (error) {
13
+ * console.error("Error generating channel ID:", error.message);
14
+ * }
15
+ *
16
+ * @param {string|number} id - The user ID for which to generate the channel identifier.
17
+ * @returns {string} The donation alert channel identifier in the format "$alerts:donation_{id}".
18
+ */
19
+ export default function getUserChannel(id: string | number): string;
@@ -0,0 +1,32 @@
1
+ /**
2
+ * Fetches the profile information for the authenticated user.
3
+ *
4
+ * @example
5
+ * import { getUserChannel } from "@kash.88/alerts";
6
+ *
7
+ * // The "id" can be obtained using the "getUser" function,
8
+ *
9
+ * try {
10
+ * const userId = "USER_ID";
11
+ * const channelId = getUserChannel(userId);
12
+ * } catch (error) {
13
+ * console.error("Error generating channel ID:", error.message);
14
+ * }
15
+ *
16
+ * @param {string|number} id - The user ID for which to generate the channel identifier.
17
+ * @returns {string} The donation alert channel identifier in the format "$alerts:donation_{id}".
18
+ */
19
+ export default function getUserChannel(id) {
20
+ try {
21
+ if (typeof id !== "string" && typeof id !== "number") {
22
+ throw new Error("You must provide \"id\" as a string or number.");
23
+ }
24
+ if (id === null || id === undefined || id === "") {
25
+ throw new Error("You must provide a non-empty \"id\".");
26
+ }
27
+ return `$alerts:donation_${id}`;
28
+ }
29
+ catch (error) {
30
+ throw new Error(error?.response?.data?.error_description || error?.message || error);
31
+ }
32
+ }
@@ -0,0 +1,24 @@
1
+ import { UpdateTokenData, OauthToken } from "../types";
2
+ /**
3
+ * Refreshes an access token using a refresh token.
4
+ *
5
+ * @example
6
+ * import { updateAccessToken } from "@kash.88/alerts";
7
+ *
8
+ * try {
9
+ * const tokenData = await updateAccessToken({
10
+ * client_id: "YOUR_CLIENT_ID",
11
+ * client_secret: "YOUR_CLIENT_SECRET",
12
+ * refresh_token: "USER_REFRESH_TOKEN"
13
+ * });
14
+ *
15
+ * console.log(tokenData.access_token);
16
+ * } catch (error) {
17
+ * console.error("Error updating access token:", error.response.data);
18
+ * }
19
+ *
20
+ * @param {UpdateTokenData} data - The data for the token refresh request.
21
+ * @returns {Promise<OauthToken>} A promise that resolves to the new token data from the API.
22
+ * @see {@link https://www.donationalerts.com/apidoc#authorization__authorization_code__getting_access_token}
23
+ */
24
+ export default function updateAccessToken(data: UpdateTokenData): Promise<OauthToken>;