@remnawave/xtls-sdk 0.11.0 → 0.11.1
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/build/index.d.ts
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { Channel, ChannelOptions, ChannelCredentials } from 'nice-grpc';
|
|
2
|
+
import { HandlerService } from './src/handler/handler.service';
|
|
3
|
+
import { RouterService } from './src/router/router.service';
|
|
4
|
+
import { StatsService } from './src/stats/stats.service';
|
|
5
|
+
export interface XtlsApiOptions {
|
|
6
|
+
connectionUrl: string;
|
|
7
|
+
options?: ChannelOptions;
|
|
8
|
+
credentials?: ChannelCredentials;
|
|
9
|
+
}
|
|
10
|
+
export declare class XtlsApi {
|
|
11
|
+
readonly channel: Channel;
|
|
12
|
+
readonly stats: StatsService;
|
|
13
|
+
readonly handler: HandlerService;
|
|
14
|
+
readonly router: RouterService;
|
|
15
|
+
constructor({ connectionUrl, options, credentials }: XtlsApiOptions);
|
|
16
|
+
}
|
|
17
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAiB,OAAO,EAAE,cAAc,EAAE,kBAAkB,EAAE,MAAM,WAAW,CAAC;AAEvF,OAAO,EAAE,cAAc,EAAE,MAAM,+BAA+B,CAAC;AAC/D,OAAO,EAAE,aAAa,EAAE,MAAM,6BAA6B,CAAC;AAC5D,OAAO,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAC;AAEzD,MAAM,WAAW,cAAc;IAC3B,aAAa,EAAE,MAAM,CAAC;IACtB,OAAO,CAAC,EAAE,cAAc,CAAC;IACzB,WAAW,CAAC,EAAE,kBAAkB,CAAC;CACpC;AAED,qBAAa,OAAO;IAChB,SAAgB,OAAO,EAAE,OAAO,CAAC;IACjC,SAAgB,KAAK,EAAE,YAAY,CAAC;IACpC,SAAgB,OAAO,EAAE,cAAc,CAAC;IACxC,SAAgB,MAAM,EAAE,aAAa,CAAC;gBAE1B,EAAE,aAAa,EAAE,OAAO,EAAE,WAAW,EAAE,EAAE,cAAc;CAStE"}
|
package/build/index.js
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.XtlsApi = void 0;
|
|
4
|
+
const nice_grpc_1 = require("nice-grpc");
|
|
5
|
+
const handler_service_1 = require("./src/handler/handler.service");
|
|
6
|
+
const router_service_1 = require("./src/router/router.service");
|
|
7
|
+
const stats_service_1 = require("./src/stats/stats.service");
|
|
8
|
+
class XtlsApi {
|
|
9
|
+
constructor({ connectionUrl, options, credentials }) {
|
|
10
|
+
this.channel = (0, nice_grpc_1.createChannel)(connectionUrl, credentials, {
|
|
11
|
+
...options,
|
|
12
|
+
});
|
|
13
|
+
this.stats = new stats_service_1.StatsService(this.channel);
|
|
14
|
+
this.handler = new handler_service_1.HandlerService(this.channel);
|
|
15
|
+
this.router = new router_service_1.RouterService(this.channel);
|
|
16
|
+
return this;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
exports.XtlsApi = XtlsApi;
|
package/package.json
CHANGED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"export-protos.d.ts","sourceRoot":"","sources":["../../scripts/export-protos.ts"],"names":[],"mappings":""}
|
|
@@ -1,132 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/* eslint-disable no-console */
|
|
3
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
4
|
-
if (k2 === undefined) k2 = k;
|
|
5
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
6
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
7
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
8
|
-
}
|
|
9
|
-
Object.defineProperty(o, k2, desc);
|
|
10
|
-
}) : (function(o, m, k, k2) {
|
|
11
|
-
if (k2 === undefined) k2 = k;
|
|
12
|
-
o[k2] = m[k];
|
|
13
|
-
}));
|
|
14
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
15
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
16
|
-
}) : function(o, v) {
|
|
17
|
-
o["default"] = v;
|
|
18
|
-
});
|
|
19
|
-
var __importStar = (this && this.__importStar) || (function () {
|
|
20
|
-
var ownKeys = function(o) {
|
|
21
|
-
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
22
|
-
var ar = [];
|
|
23
|
-
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
24
|
-
return ar;
|
|
25
|
-
};
|
|
26
|
-
return ownKeys(o);
|
|
27
|
-
};
|
|
28
|
-
return function (mod) {
|
|
29
|
-
if (mod && mod.__esModule) return mod;
|
|
30
|
-
var result = {};
|
|
31
|
-
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
32
|
-
__setModuleDefault(result, mod);
|
|
33
|
-
return result;
|
|
34
|
-
};
|
|
35
|
-
})();
|
|
36
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
37
|
-
const node_child_process_1 = require("node:child_process");
|
|
38
|
-
const node_util_1 = require("node:util");
|
|
39
|
-
const path = __importStar(require("node:path"));
|
|
40
|
-
const fs = __importStar(require("node:fs"));
|
|
41
|
-
const tar = __importStar(require("tar"));
|
|
42
|
-
const VERSION = '26.2.6';
|
|
43
|
-
const TEMP_DIR = path.join(__dirname, 'temp-xray-core');
|
|
44
|
-
const TARGET_URL = `https://github.com/XTLS/Xray-core/archive/refs/tags/v${VERSION}.tar.gz`;
|
|
45
|
-
const PROTO_DIR = path.join(__dirname, '../src/xray-protos');
|
|
46
|
-
const execAsync = (0, node_util_1.promisify)(node_child_process_1.exec);
|
|
47
|
-
async function downloadTarGz(url, dest) {
|
|
48
|
-
const response = await fetch(url);
|
|
49
|
-
if (!response.ok)
|
|
50
|
-
throw new Error(`Failed to download file: ${response.statusText}`);
|
|
51
|
-
const buffer = await response.arrayBuffer();
|
|
52
|
-
fs.writeFileSync(dest, new Uint8Array(buffer));
|
|
53
|
-
console.log(`Core extracted to ${dest}`);
|
|
54
|
-
}
|
|
55
|
-
async function extractProtoFiles(tarPath) {
|
|
56
|
-
await tar.x({
|
|
57
|
-
file: tarPath,
|
|
58
|
-
cwd: TEMP_DIR,
|
|
59
|
-
strip: 1,
|
|
60
|
-
});
|
|
61
|
-
console.log('Core extracted');
|
|
62
|
-
const protoFiles = findProtoFiles(TEMP_DIR);
|
|
63
|
-
return protoFiles;
|
|
64
|
-
}
|
|
65
|
-
function findProtoFiles(dir, fileList = []) {
|
|
66
|
-
const files = fs.readdirSync(dir);
|
|
67
|
-
for (const file of files) {
|
|
68
|
-
const filePath = path.join(dir, file);
|
|
69
|
-
const stat = fs.statSync(filePath);
|
|
70
|
-
if (stat.isDirectory()) {
|
|
71
|
-
findProtoFiles(filePath, fileList);
|
|
72
|
-
}
|
|
73
|
-
else if (path.extname(file) === '.proto') {
|
|
74
|
-
fileList.push(filePath);
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
return fileList;
|
|
78
|
-
}
|
|
79
|
-
async function generateTsFromProto(protoFile) {
|
|
80
|
-
try {
|
|
81
|
-
console.log(protoFile);
|
|
82
|
-
const dir = path.join(__dirname, '../src/xray-protos');
|
|
83
|
-
const command = [
|
|
84
|
-
'protoc',
|
|
85
|
-
`--plugin=./node_modules/.bin/protoc-gen-ts_proto`,
|
|
86
|
-
`--ts_proto_out=${dir}`,
|
|
87
|
-
`--ts_proto_opt=outputServices=generic-definitions,useExactTypes=false`,
|
|
88
|
-
`--ts_proto_opt=outputServices=nice-grpc`,
|
|
89
|
-
`--ts_proto_opt=outputTypeRegistry=true`,
|
|
90
|
-
`--ts_proto_opt=outputEncodeMethods=true`,
|
|
91
|
-
`--ts_proto_opt=outputJsonMethods=true`,
|
|
92
|
-
`--ts_proto_opt=lowerCaseServiceMethods=true`,
|
|
93
|
-
`--proto_path=${path.join(__dirname, '../scripts/temp-xray-core')}`,
|
|
94
|
-
protoFile,
|
|
95
|
-
].join(' ');
|
|
96
|
-
console.log(`Generating TypeScript for: ${protoFile}`);
|
|
97
|
-
const { stdout, stderr } = await execAsync(command);
|
|
98
|
-
if (stderr) {
|
|
99
|
-
console.error(`Error for ${protoFile}:`, stderr);
|
|
100
|
-
}
|
|
101
|
-
if (stdout) {
|
|
102
|
-
console.log(`Output for ${protoFile}:`, stdout);
|
|
103
|
-
}
|
|
104
|
-
}
|
|
105
|
-
catch (error) {
|
|
106
|
-
console.error(`Failed to generate TypeScript for ${protoFile}:`, error);
|
|
107
|
-
}
|
|
108
|
-
}
|
|
109
|
-
async function main() {
|
|
110
|
-
try {
|
|
111
|
-
if (!fs.existsSync(TEMP_DIR)) {
|
|
112
|
-
fs.mkdirSync(TEMP_DIR);
|
|
113
|
-
}
|
|
114
|
-
if (!fs.existsSync(PROTO_DIR)) {
|
|
115
|
-
fs.mkdirSync(PROTO_DIR, { recursive: true });
|
|
116
|
-
}
|
|
117
|
-
const tarPath = path.join(TEMP_DIR, `xray-core-${VERSION}.tar.gz`);
|
|
118
|
-
await downloadTarGz(TARGET_URL, tarPath);
|
|
119
|
-
const protoFiles = await extractProtoFiles(tarPath);
|
|
120
|
-
for (const protoFile of protoFiles) {
|
|
121
|
-
await generateTsFromProto(protoFile);
|
|
122
|
-
}
|
|
123
|
-
}
|
|
124
|
-
catch (error) {
|
|
125
|
-
console.error('Произошла ошибка:', error);
|
|
126
|
-
}
|
|
127
|
-
finally {
|
|
128
|
-
fs.rmSync(TEMP_DIR, { recursive: true, force: true });
|
|
129
|
-
console.log('Temp directory removed');
|
|
130
|
-
}
|
|
131
|
-
}
|
|
132
|
-
main();
|