@tgbotpress/plugin-energy 0.1.2 → 0.1.3
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/README.md +1 -1
- package/package.json +5 -1
- package/src/index.js +1 -1
- package/src/nl-api.d.ts +5 -0
- package/src/nl-api.js +19 -0
package/README.md
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
# @tgbotpress/plugin-energy
|
|
2
2
|
|
|
3
|
-
Energy management plugin package. The pure entries are `./units` for decimal energy amounts, `./poll` for wallet polling lower-bound timestamps,
|
|
3
|
+
Energy management plugin package. The pure entries are `./units` for decimal energy amounts, `./poll` for wallet polling lower-bound timestamps, `./demo-data` for clearly marked, read-only examples used by empty energy management pages, and `./nl-api` for the shared API-user route and recharge request contract. The examples are never written to the database or used by workers. Platform APIs, encrypted credentials, Tron polling, order workers and Telegram notifications remain host-owned until their transaction and key-management contracts are migrated.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tgbotpress/plugin-energy",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.3",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"registry": "https://registry.npmjs.org"
|
|
@@ -22,6 +22,10 @@
|
|
|
22
22
|
"types": "./src/demo-data.d.ts",
|
|
23
23
|
"import": "./src/demo-data.js"
|
|
24
24
|
},
|
|
25
|
+
"./nl-api": {
|
|
26
|
+
"types": "./src/nl-api.d.ts",
|
|
27
|
+
"import": "./src/nl-api.js"
|
|
28
|
+
},
|
|
25
29
|
"./units.js": {
|
|
26
30
|
"types": "./src/units.d.ts",
|
|
27
31
|
"import": "./src/units.js"
|
package/src/index.js
CHANGED
package/src/nl-api.d.ts
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export type NlApiRechargeAction = 'history' | 'create'
|
|
2
|
+
export type NlApiRechargeRequest = { action: 'history'; username: string; password: string } | { action: 'create'; username: string; password: string; amountTrx: number }
|
|
3
|
+
export declare const NL_API_DEFAULT_BASE_URL: string
|
|
4
|
+
export declare const NL_API_ENDPOINTS: Readonly<{ accountInfo: string; energyRental: string; rechargeOrders: string }>
|
|
5
|
+
export declare function createNlApiRechargeRequest(action: NlApiRechargeAction, username: string, password: string, amountTrx?: number): NlApiRechargeRequest
|
package/src/nl-api.js
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
export const NL_API_DEFAULT_BASE_URL = 'https://tgnl-home.hfz.pw'
|
|
2
|
+
|
|
3
|
+
export const NL_API_ENDPOINTS = Object.freeze({
|
|
4
|
+
accountInfo: '/v1/get_api_user_info',
|
|
5
|
+
energyRental: '/v1/delegate_tran',
|
|
6
|
+
rechargeOrders: '/v1/api-recharge-orders',
|
|
7
|
+
})
|
|
8
|
+
|
|
9
|
+
export function createNlApiRechargeRequest(action, username, password, amountTrx) {
|
|
10
|
+
if (action !== 'history' && action !== 'create') throw new TypeError('invalid NL-API recharge action')
|
|
11
|
+
if (typeof username !== 'string' || !username.trim() || typeof password !== 'string' || !password) {
|
|
12
|
+
throw new TypeError('NL-API username and password are required')
|
|
13
|
+
}
|
|
14
|
+
if (action === 'history') return { action, username: username.trim(), password }
|
|
15
|
+
if (!Number.isSafeInteger(amountTrx) || amountTrx < 1 || amountTrx > 1_000_000) {
|
|
16
|
+
throw new RangeError('NL-API recharge amount must be an integer from 1 to 1000000')
|
|
17
|
+
}
|
|
18
|
+
return { action, username: username.trim(), password, amountTrx }
|
|
19
|
+
}
|