@kash-88/alerts 1.0.0 → 1.2.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/dist/src/func/getAuthorizeLink.d.ts +1 -1
- package/dist/src/func/getAuthorizeLink.js +1 -1
- package/dist/src/func/getOauthToken.d.ts +1 -1
- package/dist/src/func/getOauthToken.js +1 -1
- package/dist/src/func/getPrivateToken.d.ts +2 -2
- package/dist/src/func/getPrivateToken.js +2 -2
- package/dist/src/func/getUser.d.ts +1 -1
- package/dist/src/func/updateAccessToken.d.ts +1 -1
- package/dist/src/func/updateAccessToken.js +1 -1
- package/dist/src/index.d.ts +8 -8
- package/dist/src/index.js +8 -8
- package/dist/src/utils.d.ts +0 -6
- package/dist/src/utils.js +0 -11
- package/dist/src/ws/CentrifugeClient.js +1 -1
- package/package.json +59 -59
- package/readme.md +180 -50
- package/src/example/getAuthorizeLink.ts +2 -6
- package/src/example/getOauthToken.ts +3 -5
- package/src/example/getUser.ts +1 -5
- package/src/example/getUserChannel.ts +2 -6
- package/src/example/updateAccessToken.ts +4 -5
- package/src/example/wsExample.ts +0 -2
- package/src/index.ts +7 -7
- package/src/utils.ts +1 -13
- package/dist/example/getAuthorizeLink.d.ts +0 -1
- package/dist/example/getAuthorizeLink.js +0 -13
- package/dist/example/getOauthToken.d.ts +0 -1
- package/dist/example/getOauthToken.js +0 -16
- package/dist/example/getUser.d.ts +0 -1
- package/dist/example/getUser.js +0 -14
- package/dist/example/getUserChannel.d.ts +0 -1
- package/dist/example/getUserChannel.js +0 -12
- package/dist/example/updateAccessToken.d.ts +0 -1
- package/dist/example/updateAccessToken.js +0 -16
- package/dist/example/wsExample.d.ts +0 -1
- package/dist/example/wsExample.js +0 -42
- package/dist/src/example/getAuthorizeLink.d.ts +0 -1
- package/dist/src/example/getAuthorizeLink.js +0 -13
- package/dist/src/example/getOauthToken.d.ts +0 -1
- package/dist/src/example/getOauthToken.js +0 -16
- package/dist/src/example/getUser.d.ts +0 -1
- package/dist/src/example/getUser.js +0 -14
- package/dist/src/example/getUserChannel.d.ts +0 -1
- package/dist/src/example/getUserChannel.js +0 -12
- package/dist/src/example/updateAccessToken.d.ts +0 -1
- package/dist/src/example/updateAccessToken.js +0 -16
- package/dist/src/example/wsExample.d.ts +0 -1
- package/dist/src/example/wsExample.js +0 -42
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { GetPrivateToken } from "../types";
|
|
1
|
+
import { GetPrivateToken } from "../types.js";
|
|
2
2
|
/**
|
|
3
3
|
* Gets a private token for subscribing to a DonationAlerts channel via Centrifuge.
|
|
4
4
|
*
|
|
5
5
|
* @example
|
|
6
|
-
* import { connectPrivateToken } from "../index";
|
|
6
|
+
* import { connectPrivateToken } from "../index.js";
|
|
7
7
|
*
|
|
8
8
|
* // The "channel" can be obtained using the "getUserChannel" function,
|
|
9
9
|
* // and the "uuidv4_client_id" is provided during authentication in WebSocket (ws).
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import axios from "axios";
|
|
2
|
-
import { validateDataObject } from "../utils";
|
|
2
|
+
import { validateDataObject } from "../utils.js";
|
|
3
3
|
/**
|
|
4
4
|
* Gets a private token for subscribing to a DonationAlerts channel via Centrifuge.
|
|
5
5
|
*
|
|
6
6
|
* @example
|
|
7
|
-
* import { connectPrivateToken } from "../index";
|
|
7
|
+
* import { connectPrivateToken } from "../index.js";
|
|
8
8
|
*
|
|
9
9
|
* // The "channel" can be obtained using the "getUserChannel" function,
|
|
10
10
|
* // and the "uuidv4_client_id" is provided during authentication in WebSocket (ws).
|
package/dist/src/index.d.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import getAuthorizeLink from "./func/getAuthorizeLink";
|
|
2
|
-
import getOauthToken from "./func/getOauthToken";
|
|
3
|
-
import getUser from "./func/getUser";
|
|
4
|
-
import updateAccessToken from "./func/updateAccessToken";
|
|
5
|
-
import getUserChannel from "./func/getUserChannel";
|
|
6
|
-
import { getPrivateToken } from "./func/getPrivateToken";
|
|
7
|
-
import CentrifugeClient from "./ws/CentrifugeClient";
|
|
8
|
-
export * from "./types";
|
|
1
|
+
import getAuthorizeLink from "./func/getAuthorizeLink.js";
|
|
2
|
+
import getOauthToken from "./func/getOauthToken.js";
|
|
3
|
+
import getUser from "./func/getUser.js";
|
|
4
|
+
import updateAccessToken from "./func/updateAccessToken.js";
|
|
5
|
+
import getUserChannel from "./func/getUserChannel.js";
|
|
6
|
+
import { getPrivateToken } from "./func/getPrivateToken.js";
|
|
7
|
+
import CentrifugeClient from "./ws/CentrifugeClient.js";
|
|
8
|
+
export * from "./types.js";
|
|
9
9
|
export { getAuthorizeLink, getOauthToken, getUser, updateAccessToken, getUserChannel, getPrivateToken, CentrifugeClient };
|
package/dist/src/index.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import getAuthorizeLink from "./func/getAuthorizeLink";
|
|
2
|
-
import getOauthToken from "./func/getOauthToken";
|
|
3
|
-
import getUser from "./func/getUser";
|
|
4
|
-
import updateAccessToken from "./func/updateAccessToken";
|
|
5
|
-
import getUserChannel from "./func/getUserChannel";
|
|
6
|
-
import { getPrivateToken } from "./func/getPrivateToken";
|
|
7
|
-
import CentrifugeClient from "./ws/CentrifugeClient";
|
|
8
|
-
export * from "./types";
|
|
1
|
+
import getAuthorizeLink from "./func/getAuthorizeLink.js";
|
|
2
|
+
import getOauthToken from "./func/getOauthToken.js";
|
|
3
|
+
import getUser from "./func/getUser.js";
|
|
4
|
+
import updateAccessToken from "./func/updateAccessToken.js";
|
|
5
|
+
import getUserChannel from "./func/getUserChannel.js";
|
|
6
|
+
import { getPrivateToken } from "./func/getPrivateToken.js";
|
|
7
|
+
import CentrifugeClient from "./ws/CentrifugeClient.js";
|
|
8
|
+
export * from "./types.js";
|
|
9
9
|
export { getAuthorizeLink, getOauthToken, getUser, updateAccessToken, getUserChannel, getPrivateToken, CentrifugeClient };
|
package/dist/src/utils.d.ts
CHANGED
|
@@ -13,9 +13,3 @@
|
|
|
13
13
|
* @private
|
|
14
14
|
*/
|
|
15
15
|
export declare function validateDataObject(data: unknown, requiredKeys: string[]): asserts data is Record<string, string | number | string[]>;
|
|
16
|
-
/**
|
|
17
|
-
* Checks if required environment variables are present.
|
|
18
|
-
* Throws an error with a clear message if any variable is missing.
|
|
19
|
-
* @param {string[]} keys - List of required environment variable names.
|
|
20
|
-
*/
|
|
21
|
-
export declare function checkEnv(keys: string[]): void;
|
package/dist/src/utils.js
CHANGED
|
@@ -35,14 +35,3 @@ export function validateDataObject(data, requiredKeys) {
|
|
|
35
35
|
}
|
|
36
36
|
}
|
|
37
37
|
}
|
|
38
|
-
/**
|
|
39
|
-
* Checks if required environment variables are present.
|
|
40
|
-
* Throws an error with a clear message if any variable is missing.
|
|
41
|
-
* @param {string[]} keys - List of required environment variable names.
|
|
42
|
-
*/
|
|
43
|
-
export function checkEnv(keys) {
|
|
44
|
-
const missing = keys.filter((key) => !process.env[key]);
|
|
45
|
-
if (missing.length > 0) {
|
|
46
|
-
throw new Error(`Missing required environment variables: ${missing.join(", ")}`);
|
|
47
|
-
}
|
|
48
|
-
}
|
package/package.json
CHANGED
|
@@ -1,59 +1,59 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "@kash-88/alerts",
|
|
3
|
-
"version": "1.
|
|
4
|
-
"description": "DonationAlerts API
|
|
5
|
-
"type": "module",
|
|
6
|
-
"keywords": [
|
|
7
|
-
"DonationAlerts",
|
|
8
|
-
"DonationAlerts API",
|
|
9
|
-
"DonationAlerts SDK"
|
|
10
|
-
],
|
|
11
|
-
"publishConfig": {
|
|
12
|
-
"registry": "https://npm.pkg.github.com/",
|
|
13
|
-
"access": "public"
|
|
14
|
-
},
|
|
15
|
-
"homepage": "https://github.com/kash-88/alerts-SDK#readme",
|
|
16
|
-
"bugs": {
|
|
17
|
-
"url": "https://github.com/kash-88/alerts-SDK/issues"
|
|
18
|
-
},
|
|
19
|
-
"main": "dist/src/index.js",
|
|
20
|
-
"types": "dist/src/index.d.ts",
|
|
21
|
-
"exports": {
|
|
22
|
-
".": {
|
|
23
|
-
"import": "./dist/src/index.js",
|
|
24
|
-
"require": "./dist/src/index.js"
|
|
25
|
-
}
|
|
26
|
-
},
|
|
27
|
-
"files": [
|
|
28
|
-
"dist",
|
|
29
|
-
"src",
|
|
30
|
-
"ws"
|
|
31
|
-
],
|
|
32
|
-
"repository": {
|
|
33
|
-
"type": "git",
|
|
34
|
-
"url": "git+https://github.com/kash-88/alerts-SDK.git"
|
|
35
|
-
},
|
|
36
|
-
"license": "ISC",
|
|
37
|
-
"author": "kash.88",
|
|
38
|
-
"scripts": {
|
|
39
|
-
"publish:github": "npm publish",
|
|
40
|
-
"build": "tsc && tsc-alias",
|
|
41
|
-
"prepublishOnly": "npm run build",
|
|
42
|
-
"publish:npm-laster": "npm publish --registry=https://registry.npmjs.org/ --tag latest",
|
|
43
|
-
"publish:npm-dev": "npm publish --registry=https://registry.npmjs.org/ --tag Dev",
|
|
44
|
-
"publish:npm-beta": "npm publish --registry=https://registry.npmjs.org/ --tag Beta"
|
|
45
|
-
},
|
|
46
|
-
"dependencies": {
|
|
47
|
-
"axios": "^1.10.0",
|
|
48
|
-
"typed-emitter": "^2.1.0",
|
|
49
|
-
"ws": "^8.17.0"
|
|
50
|
-
},
|
|
51
|
-
"devDependencies": {
|
|
52
|
-
"@types/node": "^20.12.12",
|
|
53
|
-
"@types/ws": "^8.5.10",
|
|
54
|
-
"ts-node": "^10.9.2",
|
|
55
|
-
"tsc-alias": "^1.8.16",
|
|
56
|
-
"tsconfig-paths": "^4.2.0",
|
|
57
|
-
"typescript": "^5.4.5"
|
|
58
|
-
}
|
|
59
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"name": "@kash-88/alerts",
|
|
3
|
+
"version": "1.2.0",
|
|
4
|
+
"description": "A lightweight library for easy integration with the DonationAlerts API: authorization, token management, and user info in a few lines.",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"keywords": [
|
|
7
|
+
"DonationAlerts",
|
|
8
|
+
"DonationAlerts API",
|
|
9
|
+
"DonationAlerts SDK"
|
|
10
|
+
],
|
|
11
|
+
"publishConfig": {
|
|
12
|
+
"registry": "https://npm.pkg.github.com/",
|
|
13
|
+
"access": "public"
|
|
14
|
+
},
|
|
15
|
+
"homepage": "https://github.com/kash-88/alerts-SDK#readme",
|
|
16
|
+
"bugs": {
|
|
17
|
+
"url": "https://github.com/kash-88/alerts-SDK/issues"
|
|
18
|
+
},
|
|
19
|
+
"main": "dist/src/index.js",
|
|
20
|
+
"types": "dist/src/index.d.ts",
|
|
21
|
+
"exports": {
|
|
22
|
+
".": {
|
|
23
|
+
"import": "./dist/src/index.js",
|
|
24
|
+
"require": "./dist/src/index.js"
|
|
25
|
+
}
|
|
26
|
+
},
|
|
27
|
+
"files": [
|
|
28
|
+
"dist",
|
|
29
|
+
"src",
|
|
30
|
+
"ws"
|
|
31
|
+
],
|
|
32
|
+
"repository": {
|
|
33
|
+
"type": "git",
|
|
34
|
+
"url": "git+https://github.com/kash-88/alerts-SDK.git"
|
|
35
|
+
},
|
|
36
|
+
"license": "ISC",
|
|
37
|
+
"author": "kash.88",
|
|
38
|
+
"scripts": {
|
|
39
|
+
"publish:github": "npm publish",
|
|
40
|
+
"build": "tsc && tsc-alias",
|
|
41
|
+
"prepublishOnly": "npm run build",
|
|
42
|
+
"publish:npm-laster": "npm publish --registry=https://registry.npmjs.org/ --tag latest",
|
|
43
|
+
"publish:npm-dev": "npm publish --registry=https://registry.npmjs.org/ --tag Dev",
|
|
44
|
+
"publish:npm-beta": "npm publish --registry=https://registry.npmjs.org/ --tag Beta"
|
|
45
|
+
},
|
|
46
|
+
"dependencies": {
|
|
47
|
+
"axios": "^1.10.0",
|
|
48
|
+
"typed-emitter": "^2.1.0",
|
|
49
|
+
"ws": "^8.17.0"
|
|
50
|
+
},
|
|
51
|
+
"devDependencies": {
|
|
52
|
+
"@types/node": "^20.12.12",
|
|
53
|
+
"@types/ws": "^8.5.10",
|
|
54
|
+
"ts-node": "^10.9.2",
|
|
55
|
+
"tsc-alias": "^1.8.16",
|
|
56
|
+
"tsconfig-paths": "^4.2.0",
|
|
57
|
+
"typescript": "^5.4.5"
|
|
58
|
+
}
|
|
59
|
+
}
|
package/readme.md
CHANGED
|
@@ -1,82 +1,212 @@
|
|
|
1
|
+
<div align="center">
|
|
2
|
+
|
|
1
3
|
# DonationAlerts API
|
|
2
|
-
A
|
|
4
|
+
A lightweight library for easy integration with the DonationAlerts API: authorization, token management, and user info in a few lines.
|
|
5
|
+
|
|
6
|
+
[](https://www.npmjs.com/package/@kash-88/alerts/v/latest)
|
|
7
|
+
[](https://www.npmjs.com/package/@kash-88/alerts/v/latests)
|
|
8
|
+
[](https://www.npmjs.com/package/@kash-88/alerts/v/latest)
|
|
9
|
+
|
|
10
|
+
</div>
|
|
11
|
+
|
|
12
|
+
Available in: [RU](https://github.com/kash-88/alerts-SDC/readme-ru.md), **EN**
|
|
3
13
|
|
|
4
14
|
## Installation
|
|
15
|
+
Using npm:
|
|
16
|
+
|
|
5
17
|
```bash
|
|
6
18
|
$ npm install @kash-88/alerts
|
|
7
19
|
```
|
|
8
20
|
|
|
9
|
-
|
|
21
|
+
Using yarn:
|
|
22
|
+
|
|
23
|
+
```bash
|
|
24
|
+
$ yarn add @kash-88/alerts
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
Using pnpm:
|
|
28
|
+
|
|
29
|
+
```bash
|
|
30
|
+
$ pnpm add @kash-88/alerts
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
Using bun:
|
|
34
|
+
|
|
35
|
+
```bash
|
|
36
|
+
$ bun add @kash-88/alerts
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
## Available Methods (Quick Overview)
|
|
40
|
+
| Function | Purpose |
|
|
41
|
+
|---------------------|--------------------------------------------------------------|
|
|
42
|
+
| getAuthorizeLink | Generate OAuth authorization link |
|
|
43
|
+
| getOauthToken | Exchange code for access_token and refresh_token |
|
|
44
|
+
| getUser | Fetch user profile by access_token |
|
|
45
|
+
| getUserChannel | Get user channel by user_id |
|
|
46
|
+
| updateAccessToken | Refresh access_token using refresh_token |
|
|
47
|
+
| getPrivateToken | Get private token for channel subscription |
|
|
48
|
+
|
|
49
|
+
---
|
|
10
50
|
|
|
11
|
-
## (Sync)
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
51
|
+
## getAuthorizeLink (Sync)
|
|
52
|
+
**Purpose:** Generate OAuth authorization link for DonationAlerts.
|
|
53
|
+
|
|
54
|
+
- **Params:**
|
|
55
|
+
- `client_id: string` — Your app"s client ID
|
|
56
|
+
- `scope: string[]` — Array of access scopes
|
|
57
|
+
- **Endpoint:** https://www.donationalerts.com/oauth/authorize
|
|
58
|
+
- **API Docs:** [Authorization Request](https://www.donationalerts.com/apidoc#authorization__authorization_code__authorization_request)
|
|
59
|
+
|
|
60
|
+
**Example:**
|
|
17
61
|
```js
|
|
18
|
-
import { getAuthorizeLink } from
|
|
62
|
+
import { getAuthorizeLink } from "@kash-88/alerts";
|
|
19
63
|
|
|
20
|
-
const
|
|
21
|
-
|
|
22
|
-
scope: ['oauth-user-show'] // https://www.donationalerts.com/apidoc#authorization__scopes
|
|
23
|
-
});
|
|
64
|
+
const client_id = "YOUR_CLIENT_ID"; // Get on https://www.donationalerts.com/application/clients
|
|
65
|
+
const scope = ["oauth-user-show"];
|
|
24
66
|
|
|
25
|
-
|
|
67
|
+
try {
|
|
68
|
+
const link = getAuthorizeLink({ client_id, scope });
|
|
69
|
+
console.log("Authorize link:", link);
|
|
70
|
+
} catch (error) {
|
|
71
|
+
console.error("Error:", error.message);
|
|
72
|
+
}
|
|
26
73
|
```
|
|
27
74
|
|
|
28
75
|
---
|
|
29
76
|
|
|
30
|
-
## (Async)
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
77
|
+
## getOauthToken (Async)
|
|
78
|
+
**Purpose:** Exchange authorization code for access_token and refresh_token.
|
|
79
|
+
|
|
80
|
+
- **Params:**
|
|
81
|
+
- `client_id: string` — Your app's client ID
|
|
82
|
+
- `client_secret: string` — Your app's client secret
|
|
83
|
+
- `code: string` — Authorization code
|
|
84
|
+
- **Endpoint:** https://www.donationalerts.com/oauth/token
|
|
85
|
+
- **API Docs:** [Getting Access Token](https://www.donationalerts.com/apidoc#authorization__authorization_code__getting_access_token)
|
|
86
|
+
|
|
87
|
+
**Example:**
|
|
36
88
|
```js
|
|
37
|
-
import { getOauthToken } from
|
|
89
|
+
import { getOauthToken } from "@kash-88/alerts";
|
|
90
|
+
|
|
91
|
+
// Get on https://www.donationalerts.com/application/clients
|
|
92
|
+
const client_id = "YOUR_CLIENT_ID";
|
|
93
|
+
const client_secret = process.env.CLIENT_SECRET!;
|
|
94
|
+
const code = "USER_CODE";
|
|
95
|
+
|
|
96
|
+
(async () => {
|
|
97
|
+
try {
|
|
98
|
+
const token = await getOauthToken({ client_id, client_secret, code });
|
|
99
|
+
console.log("Oauth token:", token);
|
|
100
|
+
} catch (error) {
|
|
101
|
+
console.error("Error:", error.message);
|
|
102
|
+
}
|
|
103
|
+
})();
|
|
104
|
+
```
|
|
38
105
|
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
});
|
|
106
|
+
---
|
|
107
|
+
|
|
108
|
+
## getUser (Async)
|
|
109
|
+
**Purpose:** Fetch user profile information by access_token.
|
|
44
110
|
|
|
45
|
-
|
|
111
|
+
- **Params:**
|
|
112
|
+
- `access_token: string` — User's access token
|
|
113
|
+
- **Endpoint:** https://www.donationalerts.com/api/v1/user/oauth
|
|
114
|
+
- **API Docs:** [User Info](https://www.donationalerts.com/apidoc#api_v1__users)
|
|
115
|
+
|
|
116
|
+
**Example:**
|
|
117
|
+
```js
|
|
118
|
+
import { getUser } from "@kash-88/alerts";
|
|
119
|
+
|
|
120
|
+
const user_access_token = "USER_ACCESS_TOKEN";
|
|
121
|
+
|
|
122
|
+
(async () => {
|
|
123
|
+
try {
|
|
124
|
+
const user = await getUser(user_access_token);
|
|
125
|
+
console.log("User data:", user);
|
|
126
|
+
} catch (error) {
|
|
127
|
+
console.error("Error:", error.message);
|
|
128
|
+
}
|
|
129
|
+
})();
|
|
46
130
|
```
|
|
47
131
|
|
|
48
132
|
---
|
|
49
133
|
|
|
50
|
-
## (
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
134
|
+
## getUserChannel (Sync)
|
|
135
|
+
**Purpose:** Get user channel by user_id.
|
|
136
|
+
|
|
137
|
+
- **Params:**
|
|
138
|
+
- `user_id: string` — User ID
|
|
139
|
+
- **Endpoint:** —
|
|
140
|
+
- **API Docs:** —
|
|
141
|
+
|
|
142
|
+
**Example:**
|
|
56
143
|
```js
|
|
57
|
-
import {
|
|
144
|
+
import { getUserChannel } from "@kash-88/alerts";
|
|
58
145
|
|
|
59
|
-
const
|
|
60
|
-
client_id: 'YOUR_CLIENT_ID',
|
|
61
|
-
client_secret: 'YOUR_CLIENT_SECRET',
|
|
62
|
-
refresh_token: 'USER_REFRESH_TOKEN'
|
|
63
|
-
});
|
|
146
|
+
const user_id = "USER_ID";
|
|
64
147
|
|
|
65
|
-
|
|
148
|
+
const channel = getUserChannel(user_id);
|
|
149
|
+
console.log("User channel:", channel);
|
|
66
150
|
```
|
|
67
151
|
|
|
68
152
|
---
|
|
69
153
|
|
|
70
|
-
## (Async)
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
154
|
+
## updateAccessToken (Async)
|
|
155
|
+
**Purpose:** Refresh access_token using refresh_token.
|
|
156
|
+
|
|
157
|
+
- **Params:**
|
|
158
|
+
- `client_id: string` — Your app's client ID
|
|
159
|
+
- `client_secret: string` — Your app's client secret
|
|
160
|
+
- `refresh_token: string` — Refresh token
|
|
161
|
+
- **Endpoint:** https://www.donationalerts.com/oauth/token
|
|
162
|
+
- **API Docs:** [Refreshing Access Tokens](https://www.donationalerts.com/apidoc#authorization__authorization_code__refreshing_access_tokens)
|
|
163
|
+
|
|
164
|
+
**Example:**
|
|
76
165
|
```js
|
|
77
|
-
import
|
|
166
|
+
import "dotenv/config";
|
|
167
|
+
import { getOauthToken } from "@kash-88/alerts";
|
|
168
|
+
|
|
169
|
+
// Get on https://www.donationalerts.com/application/clients
|
|
170
|
+
const client_id = "YOUR_CLIENT_ID";
|
|
171
|
+
const client_secret = process.env.CLIENT_SECRET!;
|
|
172
|
+
|
|
173
|
+
const refresh_token = "USER_REFRESH_TOKEN";
|
|
174
|
+
|
|
175
|
+
(async () => {
|
|
176
|
+
try {
|
|
177
|
+
const token = await getOauthToken({ client_id, client_secret, refresh_token });
|
|
178
|
+
console.log("Oauth token:", token);
|
|
179
|
+
} catch (error) {
|
|
180
|
+
console.error("Error:", error.message);
|
|
181
|
+
}
|
|
182
|
+
})();
|
|
183
|
+
```
|
|
78
184
|
|
|
79
|
-
|
|
185
|
+
---
|
|
186
|
+
|
|
187
|
+
## getPrivateToken (Async)
|
|
188
|
+
**Purpose:** Get a private token for subscribing to a DonationAlerts channel via Centrifuge.
|
|
80
189
|
|
|
81
|
-
|
|
82
|
-
|
|
190
|
+
- **Params:**
|
|
191
|
+
- `channel: string` — Channel name to subscribe
|
|
192
|
+
- `uuidv4_client_id: string` — UUID v4 client ID (used in WebSocket connection)
|
|
193
|
+
- `access_token: string` — User's OAuth access token
|
|
194
|
+
- **Endpoint:** https://www.donationalerts.com/api/v1/centrifuge/subscribe
|
|
195
|
+
- **API Docs:** —
|
|
196
|
+
|
|
197
|
+
**Example:**
|
|
198
|
+
```js
|
|
199
|
+
import { getPrivateToken } from "@kash-88/alerts";
|
|
200
|
+
|
|
201
|
+
const channel = "USER_CHANNEL"; // Get via getUserChannel
|
|
202
|
+
const uuidv4_client_id = "UUIDv4_CLIENT_ID"; // WebSocket client UUID
|
|
203
|
+
const access_token = "USER_ACCESS_TOKEN";
|
|
204
|
+
|
|
205
|
+
(async () => {
|
|
206
|
+
try {
|
|
207
|
+
const token = await getPrivateToken({ channel, uuidv4_client_id, access_token });
|
|
208
|
+
console.log("Private token:", token);
|
|
209
|
+
} catch (error) {
|
|
210
|
+
console.error("Error getting private token:", error.message);
|
|
211
|
+
}
|
|
212
|
+
})();
|
|
@@ -1,11 +1,7 @@
|
|
|
1
|
-
import "dotenv/config";
|
|
2
1
|
import { getAuthorizeLink } from "@kash-88/alerts";
|
|
3
|
-
import { checkEnv } from "@utils";
|
|
4
2
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
const client_id = process.env.CLIENT_ID!;
|
|
8
|
-
const scope = process.env.SCOPE ? process.env.SCOPE.split(",") : ["oauth-user-show"];
|
|
3
|
+
const client_id = "YOUR_CLIENT_ID"; // Get on https://www.donationalerts.com/application/clients
|
|
4
|
+
const scope = ["oauth-user-show", "oauth-donation-subscribe", "oauth-donation-index", "oauth-custom_alert-store", "oauth-goal-subscribe", "oauth-poll-subscribe"];
|
|
9
5
|
|
|
10
6
|
try {
|
|
11
7
|
const link = getAuthorizeLink({ client_id, scope });
|
|
@@ -1,12 +1,10 @@
|
|
|
1
1
|
import "dotenv/config";
|
|
2
2
|
import { getOauthToken } from "@kash-88/alerts";
|
|
3
|
-
import { checkEnv } from "@utils";
|
|
4
3
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
const client_id = process.env.CLIENT_ID!;
|
|
4
|
+
// Get on https://www.donationalerts.com/application/clients
|
|
5
|
+
const client_id = "YOUR_CLIENT_ID";
|
|
8
6
|
const client_secret = process.env.CLIENT_SECRET!;
|
|
9
|
-
const code =
|
|
7
|
+
const code = "CLIENT_CODE";
|
|
10
8
|
|
|
11
9
|
(async () => {
|
|
12
10
|
try {
|
package/src/example/getUser.ts
CHANGED
|
@@ -1,10 +1,6 @@
|
|
|
1
|
-
import "dotenv/config";
|
|
2
1
|
import { getUser } from "@kash-88/alerts";
|
|
3
|
-
import { checkEnv } from "@utils";
|
|
4
2
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
const access_token = process.env.ACCESS_TOKEN!;
|
|
3
|
+
const access_token = 'USER_ACCESS_TOKEN';
|
|
8
4
|
|
|
9
5
|
(async () => {
|
|
10
6
|
try {
|
|
@@ -1,13 +1,9 @@
|
|
|
1
|
-
import "dotenv/config";
|
|
2
1
|
import { getUserChannel } from "@kash-88/alerts";
|
|
3
|
-
import { checkEnv } from "@utils";
|
|
4
2
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
const id = process.env.CLIENT_ID!;
|
|
3
|
+
const user_id = "USER_ID";
|
|
8
4
|
|
|
9
5
|
try {
|
|
10
|
-
const channel = getUserChannel(
|
|
6
|
+
const channel = getUserChannel(user_id);
|
|
11
7
|
console.log("User channel:", channel);
|
|
12
8
|
} catch (error: any) {
|
|
13
9
|
console.error("Error:", error.message);
|
|
@@ -1,12 +1,11 @@
|
|
|
1
1
|
import "dotenv/config";
|
|
2
2
|
import { updateAccessToken } from "@kash-88/alerts";
|
|
3
|
-
import { checkEnv } from "@utils";
|
|
4
3
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
const client_id = process.env.CLIENT_ID!;
|
|
4
|
+
// Get on https://www.donationalerts.com/application/clients
|
|
5
|
+
const client_id = "YOUR_CLIENT_ID";
|
|
8
6
|
const client_secret = process.env.CLIENT_SECRET!;
|
|
9
|
-
|
|
7
|
+
|
|
8
|
+
const refresh_token = "USER_REFRESH_TOKEN";
|
|
10
9
|
|
|
11
10
|
(async () => {
|
|
12
11
|
try {
|
package/src/example/wsExample.ts
CHANGED
|
@@ -1,9 +1,7 @@
|
|
|
1
1
|
import "dotenv/config";
|
|
2
2
|
|
|
3
3
|
import { getUser, getUserChannel, CentrifugeClient } from "@kash-88/alerts";
|
|
4
|
-
import { checkEnv } from "@utils";
|
|
5
4
|
|
|
6
|
-
checkEnv(["CLIENT_ID", "ACCESS_TOKEN", "SOCKET_CONNECTION_TOKEN"]);
|
|
7
5
|
const access_token = process.env.ACCESS_TOKEN!;
|
|
8
6
|
let isConnectToPrivate = false;
|
|
9
7
|
|
package/src/index.ts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import getAuthorizeLink from "@function/getAuthorizeLink";
|
|
2
|
-
import getOauthToken from "@function/getOauthToken";
|
|
3
|
-
import getUser from "@function/getUser";
|
|
4
|
-
import updateAccessToken from "@function/updateAccessToken";
|
|
5
|
-
import getUserChannel from "@function/getUserChannel";
|
|
6
|
-
import { getPrivateToken } from "@function/getPrivateToken";
|
|
7
|
-
import CentrifugeClient from "@ws/CentrifugeClient";
|
|
1
|
+
import getAuthorizeLink from "@function/getAuthorizeLink.js";
|
|
2
|
+
import getOauthToken from "@function/getOauthToken.js";
|
|
3
|
+
import getUser from "@function/getUser.js";
|
|
4
|
+
import updateAccessToken from "@function/updateAccessToken.js";
|
|
5
|
+
import getUserChannel from "@function/getUserChannel.js";
|
|
6
|
+
import { getPrivateToken } from "@function/getPrivateToken.js";
|
|
7
|
+
import CentrifugeClient from "@ws/CentrifugeClient.js";
|
|
8
8
|
|
|
9
9
|
export * from "@type";
|
|
10
10
|
|
package/src/utils.ts
CHANGED
|
@@ -41,16 +41,4 @@ export function validateDataObject(data: unknown, requiredKeys: string[]): asser
|
|
|
41
41
|
throw new Error(`"${key}" must be a string or a number.`);
|
|
42
42
|
}
|
|
43
43
|
}
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
/**
|
|
47
|
-
* Checks if required environment variables are present.
|
|
48
|
-
* Throws an error with a clear message if any variable is missing.
|
|
49
|
-
* @param {string[]} keys - List of required environment variable names.
|
|
50
|
-
*/
|
|
51
|
-
export function checkEnv(keys: string[]): void {
|
|
52
|
-
const missing = keys.filter((key) => !process.env[key]);
|
|
53
|
-
if (missing.length > 0) {
|
|
54
|
-
throw new Error(`Missing required environment variables: ${missing.join(", ")}`);
|
|
55
|
-
}
|
|
56
|
-
}
|
|
44
|
+
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import 'dotenv/config';
|
|
@@ -1,13 +0,0 @@
|
|
|
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
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import 'dotenv/config';
|
|
@@ -1,16 +0,0 @@
|
|
|
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
|
-
})();
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import 'dotenv/config';
|
package/dist/example/getUser.js
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
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
|
-
})();
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import 'dotenv/config';
|
|
@@ -1,12 +0,0 @@
|
|
|
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
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import 'dotenv/config';
|
|
@@ -1,16 +0,0 @@
|
|
|
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
|
-
})();
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import 'dotenv/config';
|
|
@@ -1,42 +0,0 @@
|
|
|
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();
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import "dotenv/config";
|
|
@@ -1,13 +0,0 @@
|
|
|
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
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import "dotenv/config";
|
|
@@ -1,16 +0,0 @@
|
|
|
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
|
-
})();
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import "dotenv/config";
|
|
@@ -1,14 +0,0 @@
|
|
|
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
|
-
})();
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import "dotenv/config";
|
|
@@ -1,12 +0,0 @@
|
|
|
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
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import "dotenv/config";
|
|
@@ -1,16 +0,0 @@
|
|
|
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
|
-
})();
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import "dotenv/config";
|
|
@@ -1,42 +0,0 @@
|
|
|
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();
|