@kash-88/alerts 1.1.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/package.json +59 -59
- package/readme.md +180 -50
- package/src/example/getAuthorizeLink.ts +2 -3
- package/src/example/getOauthToken.ts +3 -2
- package/src/example/getUser.ts +1 -2
- package/src/example/getUserChannel.ts +2 -3
- package/src/example/updateAccessToken.ts +4 -2
- package/dist/src/example/getAuthorizeLink.d.ts +0 -1
- package/dist/src/example/getAuthorizeLink.js +0 -11
- package/dist/src/example/getOauthToken.d.ts +0 -1
- package/dist/src/example/getOauthToken.js +0 -14
- package/dist/src/example/getUser.d.ts +0 -1
- package/dist/src/example/getUser.js +0 -12
- package/dist/src/example/getUserChannel.d.ts +0 -1
- package/dist/src/example/getUserChannel.js +0 -10
- package/dist/src/example/updateAccessToken.d.ts +0 -1
- package/dist/src/example/updateAccessToken.js +0 -14
- package/dist/src/example/wsExample.d.ts +0 -1
- package/dist/src/example/wsExample.js +0 -40
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,8 +1,7 @@
|
|
|
1
|
-
import "dotenv/config";
|
|
2
1
|
import { getAuthorizeLink } from "@kash-88/alerts";
|
|
3
2
|
|
|
4
|
-
const client_id =
|
|
5
|
-
const scope =
|
|
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"];
|
|
6
5
|
|
|
7
6
|
try {
|
|
8
7
|
const link = getAuthorizeLink({ client_id, scope });
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import "dotenv/config";
|
|
2
2
|
import { getOauthToken } from "@kash-88/alerts";
|
|
3
3
|
|
|
4
|
-
|
|
4
|
+
// Get on https://www.donationalerts.com/application/clients
|
|
5
|
+
const client_id = "YOUR_CLIENT_ID";
|
|
5
6
|
const client_secret = process.env.CLIENT_SECRET!;
|
|
6
|
-
const code =
|
|
7
|
+
const code = "CLIENT_CODE";
|
|
7
8
|
|
|
8
9
|
(async () => {
|
|
9
10
|
try {
|
package/src/example/getUser.ts
CHANGED
|
@@ -1,10 +1,9 @@
|
|
|
1
|
-
import "dotenv/config";
|
|
2
1
|
import { getUserChannel } from "@kash-88/alerts";
|
|
3
2
|
|
|
4
|
-
const
|
|
3
|
+
const user_id = "USER_ID";
|
|
5
4
|
|
|
6
5
|
try {
|
|
7
|
-
const channel = getUserChannel(
|
|
6
|
+
const channel = getUserChannel(user_id);
|
|
8
7
|
console.log("User channel:", channel);
|
|
9
8
|
} catch (error: any) {
|
|
10
9
|
console.error("Error:", error.message);
|
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
import "dotenv/config";
|
|
2
2
|
import { updateAccessToken } from "@kash-88/alerts";
|
|
3
3
|
|
|
4
|
-
|
|
4
|
+
// Get on https://www.donationalerts.com/application/clients
|
|
5
|
+
const client_id = "YOUR_CLIENT_ID";
|
|
5
6
|
const client_secret = process.env.CLIENT_SECRET!;
|
|
6
|
-
|
|
7
|
+
|
|
8
|
+
const refresh_token = "USER_REFRESH_TOKEN";
|
|
7
9
|
|
|
8
10
|
(async () => {
|
|
9
11
|
try {
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import "dotenv/config";
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import "dotenv/config";
|
|
2
|
-
import { getAuthorizeLink } from "../index.js";
|
|
3
|
-
const client_id = process.env.CLIENT_ID;
|
|
4
|
-
const scope = process.env.SCOPE ? process.env.SCOPE.split(",") : ["oauth-user-show"];
|
|
5
|
-
try {
|
|
6
|
-
const link = getAuthorizeLink({ client_id, scope });
|
|
7
|
-
console.log("Authorize link:", link);
|
|
8
|
-
}
|
|
9
|
-
catch (error) {
|
|
10
|
-
console.error("Error:", error.message);
|
|
11
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import "dotenv/config";
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import "dotenv/config";
|
|
2
|
-
import { getOauthToken } from "../index.js";
|
|
3
|
-
const client_id = process.env.CLIENT_ID;
|
|
4
|
-
const client_secret = process.env.CLIENT_SECRET;
|
|
5
|
-
const code = process.env.CODE;
|
|
6
|
-
(async () => {
|
|
7
|
-
try {
|
|
8
|
-
const token = await getOauthToken({ client_id, client_secret, code });
|
|
9
|
-
console.log("Oauth token:", token);
|
|
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 { getUser } from "../index.js";
|
|
3
|
-
const access_token = process.env.ACCESS_TOKEN;
|
|
4
|
-
(async () => {
|
|
5
|
-
try {
|
|
6
|
-
const user = await getUser(access_token);
|
|
7
|
-
console.log("User:", user);
|
|
8
|
-
}
|
|
9
|
-
catch (error) {
|
|
10
|
-
console.error("Error:", error.message);
|
|
11
|
-
}
|
|
12
|
-
})();
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import "dotenv/config";
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import "dotenv/config";
|
|
2
|
-
import { getUserChannel } from "../index.js";
|
|
3
|
-
const id = process.env.CLIENT_ID;
|
|
4
|
-
try {
|
|
5
|
-
const channel = getUserChannel(id);
|
|
6
|
-
console.log("User channel:", channel);
|
|
7
|
-
}
|
|
8
|
-
catch (error) {
|
|
9
|
-
console.error("Error:", error.message);
|
|
10
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import "dotenv/config";
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import "dotenv/config";
|
|
2
|
-
import { updateAccessToken } from "../index.js";
|
|
3
|
-
const client_id = process.env.CLIENT_ID;
|
|
4
|
-
const client_secret = process.env.CLIENT_SECRET;
|
|
5
|
-
const refresh_token = process.env.REFRESH_TOKEN;
|
|
6
|
-
(async () => {
|
|
7
|
-
try {
|
|
8
|
-
const token = await updateAccessToken({ client_id, client_secret, refresh_token });
|
|
9
|
-
console.log("Updated token:", token);
|
|
10
|
-
}
|
|
11
|
-
catch (error) {
|
|
12
|
-
console.error("Error:", error.message);
|
|
13
|
-
}
|
|
14
|
-
})();
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import "dotenv/config";
|
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
import "dotenv/config";
|
|
2
|
-
import { getUser, getUserChannel, CentrifugeClient } from "../index.js";
|
|
3
|
-
const access_token = process.env.ACCESS_TOKEN;
|
|
4
|
-
let isConnectToPrivate = false;
|
|
5
|
-
async function main() {
|
|
6
|
-
try {
|
|
7
|
-
const user = await getUser(access_token);
|
|
8
|
-
const channel = getUserChannel(user.id);
|
|
9
|
-
const socket_connection_token = String(process.env.SOCKET_CONNECTION_TOKEN);
|
|
10
|
-
const client = new CentrifugeClient({
|
|
11
|
-
channel,
|
|
12
|
-
socket_connection_token,
|
|
13
|
-
access_token
|
|
14
|
-
});
|
|
15
|
-
const ws = client.createConnection();
|
|
16
|
-
ws.on("open", async () => {
|
|
17
|
-
console.log("WebSocket соединение открыто");
|
|
18
|
-
client.confirmConnection(socket_connection_token);
|
|
19
|
-
});
|
|
20
|
-
ws.on("message", (message) => {
|
|
21
|
-
const srt = message.toString("utf8");
|
|
22
|
-
const json = JSON.parse(srt);
|
|
23
|
-
if (json.id = 1 && !isConnectToPrivate) {
|
|
24
|
-
isConnectToPrivate = true;
|
|
25
|
-
return client.connectPrivateToken(channel, json.result.client);
|
|
26
|
-
}
|
|
27
|
-
console.log(srt);
|
|
28
|
-
});
|
|
29
|
-
ws.on("close", () => {
|
|
30
|
-
console.log("WebSocket соединение закрыто");
|
|
31
|
-
});
|
|
32
|
-
ws.on("error", (err) => {
|
|
33
|
-
console.error("Ошибка WebSocket:", err);
|
|
34
|
-
});
|
|
35
|
-
}
|
|
36
|
-
catch (error) {
|
|
37
|
-
console.error("Ошибка:", error.message);
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
main();
|