@remnawave/xtls-sdk 0.1.2 → 0.1.5

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.
@@ -3,6 +3,5 @@ export interface IAddSourceIpRule {
3
3
  ip: string;
4
4
  outbound: string;
5
5
  append: boolean;
6
- inbound?: string;
7
6
  }
8
7
  //# sourceMappingURL=add-source-ip-rule.interface.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"add-source-ip-rule.interface.d.ts","sourceRoot":"","sources":["../../../../src/router/interfaces/add-source-ip-rule.interface.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,gBAAgB;IAC7B,OAAO,EAAE,MAAM,CAAC;IAChB,EAAE,EAAE,MAAM,CAAC;IACX,QAAQ,EAAE,MAAM,CAAC;IACjB,MAAM,EAAE,OAAO,CAAC;IAChB,OAAO,CAAC,EAAE,MAAM,CAAC;CACpB"}
1
+ {"version":3,"file":"add-source-ip-rule.interface.d.ts","sourceRoot":"","sources":["../../../../src/router/interfaces/add-source-ip-rule.interface.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,gBAAgB;IAC7B,OAAO,EAAE,MAAM,CAAC;IAChB,EAAE,EAAE,MAAM,CAAC;IACX,QAAQ,EAAE,MAAM,CAAC;IACjB,MAAM,EAAE,OAAO,CAAC;CACnB"}
@@ -22,7 +22,6 @@ export declare class RouterService {
22
22
  * @param dto.outbound - Outbound tag to route matched traffic
23
23
  * @param dto.ip - Source IP address to match
24
24
  * @param dto.append - Whether to append the rule or replace existing rules
25
- * @param dto.inbound - Optional inbound tag to match
26
25
  * @returns Promise resolving to response indicating success or failure
27
26
  */
28
27
  addSrcIpRule(dto: IAddSourceIpRule): Promise<ISdkResponse<AddSourceIpRuleResponseModel>>;
@@ -1 +1 @@
1
- {"version":3,"file":"router.service.d.ts","sourceRoot":"","sources":["../../../src/router/router.service.ts"],"names":[],"mappings":"AAAA,OAAO,EAAgB,OAAO,EAAE,MAAM,WAAW,CAAC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;;;;;OAKG;IACU,mBAAmB,CAC5B,GAAG,EAAE,oBAAoB,GAC1B,OAAO,CAAC,YAAY,CAAC,gCAAgC,CAAC,CAAC;CAqB7D"}
@@ -11,6 +11,7 @@ const config_1 = require("../xray-protos/app/router/config");
11
11
  const models_1 = require("./models");
12
12
  const router_errors_1 = require("../common/errors/router/router.errors");
13
13
  const remove_rule_by_rule_tag_1 = require("./models/remove-rule-by-rule-tag");
14
+ const ipaddr_js_1 = __importDefault(require("ipaddr.js"));
14
15
  /**
15
16
  * Service for managing routing rules in XRAY/XTLS
16
17
  * RoutingService is required (enable on XRay Config) to add/remove routing rules.
@@ -31,21 +32,30 @@ class RouterService {
31
32
  * @param dto.outbound - Outbound tag to route matched traffic
32
33
  * @param dto.ip - Source IP address to match
33
34
  * @param dto.append - Whether to append the rule or replace existing rules
34
- * @param dto.inbound - Optional inbound tag to match
35
35
  * @returns Promise resolving to response indicating success or failure
36
36
  */
37
37
  async addSrcIpRule(dto) {
38
38
  try {
39
- const routingRule = {
40
- ruleTag: dto.ruleTag,
41
- outboundTag: dto.outbound,
42
- source: [dto.ip],
43
- inboundTag: dto.inbound ? [dto.inbound] : [''],
44
- type: 'field',
45
- };
39
+ const ip = ipaddr_js_1.default.parse(dto.ip);
40
+ const prefix = ip.kind() === 'ipv6' ? 128 : 32;
46
41
  await this.client.addRule({
47
42
  config: (0, create_typed_message_1.default)(config_1.Config, {
48
- rule: [routingRule],
43
+ rule: [
44
+ {
45
+ ruleTag: dto.ruleTag,
46
+ tag: dto.outbound,
47
+ sourceGeoip: [
48
+ config_1.GeoIP.fromPartial({
49
+ cidr: [
50
+ config_1.CIDR.fromPartial({
51
+ ip: new Uint8Array(ip.toByteArray()),
52
+ prefix,
53
+ }),
54
+ ],
55
+ }),
56
+ ],
57
+ },
58
+ ],
49
59
  }),
50
60
  shouldAppend: dto.append,
51
61
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@remnawave/xtls-sdk",
3
- "version": "0.1.2",
3
+ "version": "0.1.5",
4
4
  "description": "A Typescript SDK for XRAY (XTLS) Core GRPC Api",
5
5
  "main": "build/index.js",
6
6
  "types": "build/index.d.ts",
@@ -39,13 +39,14 @@
39
39
  "vmess"
40
40
  ],
41
41
  "dependencies": {
42
+ "ipaddr.js": "2.2.0",
42
43
  "long": "^5.2.3",
43
44
  "nice-grpc": "^2.1.10",
44
45
  "protobufjs": "^7.4.0",
45
- "tar": "^7.4.3",
46
46
  "@bufbuild/protobuf": "^2.2.2"
47
47
  },
48
48
  "devDependencies": {
49
+ "tar": "^7.4.3",
49
50
  "@types/jest": "^29.5.2",
50
51
  "@types/node": "^22.9.0",
51
52
  "grpc-tools": "^1.12.4",