@fett/synology-api 0.0.1-beta.7 → 0.0.1-beta.9

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/lib/cjs/index.js CHANGED
@@ -76,7 +76,7 @@ __export(index_exports, {
76
76
  module.exports = __toCommonJS(index_exports);
77
77
 
78
78
  // src/core.ts
79
- var import_axios4 = __toESM(require("axios"));
79
+ var import_ky4 = __toESM(require("ky"));
80
80
 
81
81
  // src/types/apiInfo.ts
82
82
  var SynologyApiInfo = /* @__PURE__ */ ((SynologyApiInfo2) => {
@@ -122,7 +122,7 @@ function getSongList(params) {
122
122
  library: "all"
123
123
  }, params)
124
124
  });
125
- return res.data;
125
+ return res;
126
126
  });
127
127
  }
128
128
 
@@ -141,7 +141,7 @@ function getInfo() {
141
141
  method: "get"
142
142
  }
143
143
  });
144
- return res.data;
144
+ return res;
145
145
  });
146
146
  }
147
147
 
@@ -171,7 +171,7 @@ function getFileList() {
171
171
  folder_path: params.folder_path
172
172
  }, params)
173
173
  });
174
- return res.data;
174
+ return res;
175
175
  });
176
176
  }
177
177
  function getFileListShare() {
@@ -184,7 +184,7 @@ function getFileListShare() {
184
184
  onlywritable
185
185
  }, params)
186
186
  });
187
- return res.data;
187
+ return res;
188
188
  });
189
189
  }
190
190
 
@@ -242,7 +242,7 @@ Object.defineProperties(BaseSynologyApi.prototype, {
242
242
  });
243
243
 
244
244
  // src/helpers.ts
245
- var import_axios = __toESM(require("axios"));
245
+ var import_ky = __toESM(require("ky"));
246
246
 
247
247
  // src/constants.ts
248
248
  var GLOBAL_QUICK_CONNECT_URL = "https://global.quickconnect.cn/Serv.php";
@@ -272,7 +272,7 @@ var getServersFromServerInfo = (serverInfo) => __async(null, null, function* ()
272
272
  }
273
273
  });
274
274
  var getServerInfo = (quickConnectId) => __async(null, null, function* () {
275
- var _a, _b, _c, _d;
275
+ var _a, _b;
276
276
  const params = {
277
277
  version: 1,
278
278
  id: "dsm",
@@ -280,8 +280,8 @@ var getServerInfo = (quickConnectId) => __async(null, null, function* () {
280
280
  get_ca_fingerprints: true,
281
281
  command: "get_server_info"
282
282
  };
283
- const serverInfo = yield import_axios.default.post(GLOBAL_QUICK_CONNECT_URL, params);
284
- if (!((_b = (_a = serverInfo.data) == null ? void 0 : _a.service) == null ? void 0 : _b.relay_ip) && !((_d = (_c = serverInfo.data) == null ? void 0 : _c.service) == null ? void 0 : _d.relay_port)) {
283
+ const serverInfo = yield import_ky.default.post(GLOBAL_QUICK_CONNECT_URL, { json: params }).json();
284
+ if (!((_a = serverInfo == null ? void 0 : serverInfo.service) == null ? void 0 : _a.relay_ip) && !((_b = serverInfo == null ? void 0 : serverInfo.service) == null ? void 0 : _b.relay_port)) {
285
285
  const relayRequestParams = {
286
286
  version: 1,
287
287
  id: "dsm",
@@ -289,21 +289,16 @@ var getServerInfo = (quickConnectId) => __async(null, null, function* () {
289
289
  platform: "web",
290
290
  command: "request_tunnel"
291
291
  };
292
- const result = yield import_axios.default.post(
293
- `https://${serverInfo.data.env.control_host}/Serv.php`,
294
- relayRequestParams
295
- );
296
- return getServersFromServerInfo(result.data);
292
+ const result = yield import_ky.default.post(`https://${serverInfo.env.control_host}/Serv.php`, { json: relayRequestParams }).json();
293
+ return getServersFromServerInfo(result);
297
294
  } else {
298
- return getServersFromServerInfo(serverInfo.data);
295
+ return getServersFromServerInfo(serverInfo);
299
296
  }
300
297
  });
301
298
  var pingpang = (server) => __async(null, null, function* () {
302
299
  try {
303
- const result = yield import_axios.default.get(`${server}/${QUICK_CONNECT_PINGPANG_API}`, {
304
- timeout: 3e3
305
- });
306
- if (result.data.success) {
300
+ const result = yield import_ky.default.get(`${server}/${QUICK_CONNECT_PINGPANG_API}`).json();
301
+ if (result.success) {
307
302
  return true;
308
303
  } else {
309
304
  return false;
@@ -314,7 +309,7 @@ var pingpang = (server) => __async(null, null, function* () {
314
309
  });
315
310
 
316
311
  // src/modules/Api/Auth.ts
317
- var import_axios2 = __toESM(require("axios"));
312
+ var import_ky2 = __toESM(require("ky"));
318
313
  function login(core) {
319
314
  return __async(this, null, function* () {
320
315
  const params = {
@@ -326,11 +321,11 @@ function login(core) {
326
321
  format: "sid"
327
322
  };
328
323
  const url = `${core.baseUrl}entry.cgi`;
329
- const result = yield import_axios2.default.get(url, { params });
330
- if (!result.data.success) {
331
- throw new Error(result.data.error.message);
324
+ const result = yield import_ky2.default.get(url, { searchParams: params }).json();
325
+ if (!result.success) {
326
+ throw new Error(result.error.message);
332
327
  }
333
- return result.data;
328
+ return result;
334
329
  });
335
330
  }
336
331
  function logout(core) {
@@ -341,15 +336,15 @@ function logout(core) {
341
336
  method: "logout"
342
337
  };
343
338
  const url = `${core.baseUrl}entry.cgi`;
344
- const result = yield import_axios2.default.get(url, { params });
345
- if (!result.data.success) {
346
- throw new Error(result.data.error.message);
339
+ const result = yield import_ky2.default.get(url, { searchParams: params }).json();
340
+ if (!result.success) {
341
+ throw new Error(result.error.message);
347
342
  }
348
343
  });
349
344
  }
350
345
 
351
346
  // src/modules/Api/Info.ts
352
- var import_axios3 = __toESM(require("axios"));
347
+ var import_ky3 = __toESM(require("ky"));
353
348
  function getApiInfo(core) {
354
349
  return __async(this, null, function* () {
355
350
  const params = {
@@ -358,11 +353,11 @@ function getApiInfo(core) {
358
353
  method: "query"
359
354
  };
360
355
  const url = `${core.baseUrl}entry.cgi`;
361
- const result = yield import_axios3.default.get(url, { params });
362
- if (!result.data.success) {
363
- throw new Error(result.data.error.message);
356
+ const result = yield import_ky3.default.get(url, { searchParams: params }).json();
357
+ if (!result.success) {
358
+ throw new Error(result.error.message);
364
359
  }
365
- return result.data;
360
+ return result;
366
361
  });
367
362
  }
368
363
 
@@ -547,14 +542,14 @@ var SynologyApi = class extends BaseSynologyApi {
547
542
  }, params);
548
543
  let result = null;
549
544
  if (method === "get") {
550
- result = yield import_axios4.default.get(url, { params: externalParams, data, headers });
545
+ result = yield import_ky4.default.get(url, { searchParams: externalParams, headers }).json();
551
546
  }
552
547
  if (method === "post") {
553
- result = yield import_axios4.default.post(url, { params: externalParams, data, headers });
548
+ result = yield import_ky4.default.post(url, { searchParams: externalParams, json: data, headers }).json();
554
549
  }
555
550
  const apiKey = getApiKey(apiName);
556
551
  if (!isUndfined(apiKey)) {
557
- result.data = resWithErrorCode(apiKey, result.data);
552
+ result = resWithErrorCode(apiKey, result);
558
553
  }
559
554
  return result;
560
555
  });
@@ -714,7 +709,7 @@ var apiCmdRegister = () => {
714
709
  function loadCli() {
715
710
  return __async(this, null, function* () {
716
711
  const pkg = yield import_fs_extra2.default.readJSON(import_path2.default.join(__dirname, "../../package.json"));
717
- import_commander3.program.name("synology").usage("<command> [options]").description("synology api cli tool").version(pkg.version);
712
+ import_commander3.program.name("synology").usage("<command> [options]").description("synology api cli tool").version(pkg.version, "-v, --version", "output the version number");
718
713
  configCmdRegister();
719
714
  apiCmdRegister();
720
715
  import_commander3.program.parse(process.argv);
@@ -21,7 +21,7 @@ export function loadCli() {
21
21
  .name("synology")
22
22
  .usage("<command> [options]")
23
23
  .description("synology api cli tool")
24
- .version(pkg.version);
24
+ .version(pkg.version, "-v, --version", "output the version number");
25
25
  // register commands
26
26
  configCmdRegister();
27
27
  apiCmdRegister();
package/lib/esm/core.js CHANGED
@@ -8,7 +8,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
8
8
  });
9
9
  };
10
10
  // reference: https://kb.synology.com/zh-tw/DSM/tutorial/What_websites_does_Synology_NAS_connect_to_when_running_services_or_updating_software
11
- import axios from "axios";
11
+ import ky from "ky";
12
12
  import { BaseSynologyApi } from "./modules";
13
13
  import { isHttpUrl, getApiKey, isUndfined } from "./utils";
14
14
  import { getServerInfo } from "./helpers";
@@ -95,15 +95,15 @@ export class SynologyApi extends BaseSynologyApi {
95
95
  const externalParams = Object.assign({ api: apiName, version: api.maxVersion, _sid: this.authInfo.sid }, params);
96
96
  let result = null;
97
97
  if (method === "get") {
98
- result = yield axios.get(url, { params: externalParams, data, headers });
98
+ result = yield ky.get(url, { searchParams: externalParams, headers }).json();
99
99
  }
100
100
  if (method === "post") {
101
- result = yield axios.post(url, { params: externalParams, data, headers });
101
+ result = yield ky.post(url, { searchParams: externalParams, json: data, headers }).json();
102
102
  }
103
103
  // match error code msg
104
104
  const apiKey = getApiKey(apiName);
105
105
  if (!isUndfined(apiKey)) {
106
- result.data = resWithErrorCode(apiKey, result.data);
106
+ result = resWithErrorCode(apiKey, result);
107
107
  }
108
108
  return result;
109
109
  });
@@ -7,7 +7,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
7
7
  step((generator = generator.apply(thisArg, _arguments || [])).next());
8
8
  });
9
9
  };
10
- import axios from "axios";
10
+ import ky from "ky";
11
11
  import { GLOBAL_QUICK_CONNECT_URL, QUICK_CONNECT_PINGPANG_API } from "./constants";
12
12
  const getServersFromServerInfo = (serverInfo) => __awaiter(void 0, void 0, void 0, function* () {
13
13
  var _a, _b, _c, _d, _e, _f;
@@ -34,9 +34,8 @@ const getServersFromServerInfo = (serverInfo) => __awaiter(void 0, void 0, void
34
34
  }
35
35
  }
36
36
  });
37
- // get server ip
38
37
  export const getServerInfo = (quickConnectId) => __awaiter(void 0, void 0, void 0, function* () {
39
- var _a, _b, _c, _d;
38
+ var _a, _b;
40
39
  const params = {
41
40
  version: 1,
42
41
  id: "dsm",
@@ -44,8 +43,8 @@ export const getServerInfo = (quickConnectId) => __awaiter(void 0, void 0, void
44
43
  get_ca_fingerprints: true,
45
44
  command: "get_server_info",
46
45
  };
47
- const serverInfo = yield axios.post(GLOBAL_QUICK_CONNECT_URL, params);
48
- if (!((_b = (_a = serverInfo.data) === null || _a === void 0 ? void 0 : _a.service) === null || _b === void 0 ? void 0 : _b.relay_ip) && !((_d = (_c = serverInfo.data) === null || _c === void 0 ? void 0 : _c.service) === null || _d === void 0 ? void 0 : _d.relay_port)) {
46
+ const serverInfo = yield ky.post(GLOBAL_QUICK_CONNECT_URL, { json: params }).json();
47
+ if (!((_a = serverInfo === null || serverInfo === void 0 ? void 0 : serverInfo.service) === null || _a === void 0 ? void 0 : _a.relay_ip) && !((_b = serverInfo === null || serverInfo === void 0 ? void 0 : serverInfo.service) === null || _b === void 0 ? void 0 : _b.relay_port)) {
49
48
  const relayRequestParams = {
50
49
  version: 1,
51
50
  id: "dsm",
@@ -53,20 +52,22 @@ export const getServerInfo = (quickConnectId) => __awaiter(void 0, void 0, void
53
52
  platform: "web",
54
53
  command: "request_tunnel",
55
54
  };
56
- const result = yield axios.post(`https://${serverInfo.data.env.control_host}/Serv.php`, relayRequestParams);
57
- return getServersFromServerInfo(result.data);
55
+ const result = yield ky
56
+ .post(`https://${serverInfo.env.control_host}/Serv.php`, { json: relayRequestParams })
57
+ .json();
58
+ return getServersFromServerInfo(result);
58
59
  }
59
60
  else {
60
- return getServersFromServerInfo(serverInfo.data);
61
+ return getServersFromServerInfo(serverInfo);
61
62
  }
62
63
  });
63
64
  // pingpang
64
65
  export const pingpang = (server) => __awaiter(void 0, void 0, void 0, function* () {
65
66
  try {
66
- const result = yield axios.get(`${server}/${QUICK_CONNECT_PINGPANG_API}`, {
67
- timeout: 3000,
68
- });
69
- if (result.data.success) {
67
+ const result = yield ky
68
+ .get(`${server}/${QUICK_CONNECT_PINGPANG_API}`)
69
+ .json();
70
+ if (result.success) {
70
71
  return true;
71
72
  }
72
73
  else {
@@ -7,7 +7,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
7
7
  step((generator = generator.apply(thisArg, _arguments || [])).next());
8
8
  });
9
9
  };
10
- import axios from "axios";
10
+ import ky from "ky";
11
11
  import { SynologyApiInfo } from "../../types";
12
12
  export function login(core) {
13
13
  return __awaiter(this, void 0, void 0, function* () {
@@ -20,11 +20,11 @@ export function login(core) {
20
20
  format: "sid",
21
21
  };
22
22
  const url = `${core.baseUrl}entry.cgi`;
23
- const result = yield axios.get(url, { params });
24
- if (!result.data.success) {
25
- throw new Error(result.data.error.message);
23
+ const result = yield ky.get(url, { searchParams: params }).json();
24
+ if (!result.success) {
25
+ throw new Error(result.error.message);
26
26
  }
27
- return result.data;
27
+ return result;
28
28
  });
29
29
  }
30
30
  export function logout(core) {
@@ -35,9 +35,9 @@ export function logout(core) {
35
35
  method: "logout",
36
36
  };
37
37
  const url = `${core.baseUrl}entry.cgi`;
38
- const result = yield axios.get(url, { params });
39
- if (!result.data.success) {
40
- throw new Error(result.data.error.message);
38
+ const result = yield ky.get(url, { searchParams: params }).json();
39
+ if (!result.success) {
40
+ throw new Error(result.error.message);
41
41
  }
42
42
  });
43
43
  }
@@ -7,7 +7,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
7
7
  step((generator = generator.apply(thisArg, _arguments || [])).next());
8
8
  });
9
9
  };
10
- import axios from "axios";
10
+ import ky from "ky";
11
11
  import { SynologyApiInfo } from "../../types";
12
12
  export function getApiInfo(core) {
13
13
  return __awaiter(this, void 0, void 0, function* () {
@@ -17,10 +17,10 @@ export function getApiInfo(core) {
17
17
  method: "query",
18
18
  };
19
19
  const url = `${core.baseUrl}entry.cgi`;
20
- const result = yield axios.get(url, { params });
21
- if (!result.data.success) {
22
- throw new Error(result.data.error.message);
20
+ const result = yield ky.get(url, { searchParams: params }).json();
21
+ if (!result.success) {
22
+ throw new Error(result.error.message);
23
23
  }
24
- return result.data;
24
+ return result;
25
25
  });
26
26
  }
@@ -13,6 +13,6 @@ export function getSongList(params) {
13
13
  const res = yield this.run(AudioStationApi.Song, {
14
14
  params: Object.assign({ method: "list", library: "all" }, params),
15
15
  });
16
- return res.data;
16
+ return res;
17
17
  });
18
18
  }
@@ -15,6 +15,6 @@ export function getInfo() {
15
15
  method: "get",
16
16
  },
17
17
  });
18
- return res.data;
18
+ return res;
19
19
  });
20
20
  }
@@ -18,7 +18,7 @@ export function getFileList() {
18
18
  const res = yield this.run(FileStationApi.List, {
19
19
  params: Object.assign({ method: "list", additional: JSON.stringify(additional), filetype: filetype, folder_path: params.folder_path }, params),
20
20
  });
21
- return res.data;
21
+ return res;
22
22
  });
23
23
  }
24
24
  export function getFileListShare() {
@@ -27,6 +27,6 @@ export function getFileListShare() {
27
27
  const res = yield this.run(FileStationApi.List, {
28
28
  params: Object.assign({ method: "list_share", additional: JSON.stringify(additional), onlywritable: onlywritable }, params),
29
29
  });
30
- return res.data;
30
+ return res;
31
31
  });
32
32
  }
@@ -1,2 +1,19 @@
1
+ export type ServerInfo = {
2
+ env: {
3
+ control_host: string;
4
+ };
5
+ server: {
6
+ external: {
7
+ ip: string;
8
+ };
9
+ interface: {
10
+ ip: string;
11
+ }[];
12
+ };
13
+ service: {
14
+ relay_ip: string;
15
+ relay_port: number;
16
+ };
17
+ };
1
18
  export declare const getServerInfo: (quickConnectId: string) => Promise<string>;
2
19
  export declare const pingpang: (server: string) => Promise<boolean>;
@@ -1,3 +1,4 @@
1
+ import { SynologyApiResponse } from "../../types";
1
2
  import { SynologyApi } from "../../core";
2
- export declare function login(core: SynologyApi): Promise<any>;
3
+ export declare function login(core: SynologyApi): Promise<SynologyApiResponse>;
3
4
  export declare function logout(core: SynologyApi): Promise<void>;
@@ -1,2 +1,3 @@
1
+ import { SynologyApiResponse } from "../../types";
1
2
  import { SynologyApi } from "../../core";
2
- export declare function getApiInfo(core: SynologyApi): Promise<any>;
3
+ export declare function getApiInfo(core: SynologyApi): Promise<SynologyApiResponse>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fett/synology-api",
3
- "version": "0.0.1-beta.7",
3
+ "version": "0.0.1-beta.9",
4
4
  "description": "synology api for nodejs",
5
5
  "module": "./lib/esm/index.js",
6
6
  "main": "./lib/cjs/index.js",
@@ -9,7 +9,8 @@
9
9
  ".": {
10
10
  "require": "./lib/cjs/index.js",
11
11
  "import": "./lib/esm/index.js"
12
- }
12
+ },
13
+ "./browser": "./lib/esm/core.js"
13
14
  },
14
15
  "bin": {
15
16
  "synology": "./bin/syno",
@@ -64,10 +65,10 @@
64
65
  "vitest": "^3.1.3"
65
66
  },
66
67
  "dependencies": {
67
- "axios": "^1.9.0",
68
68
  "chalk": "^5.4.1",
69
69
  "commander": "^14.0.0",
70
70
  "fs-extra": "^11.3.0",
71
+ "ky": "^1.8.1",
71
72
  "ora": "^8.2.0"
72
73
  }
73
74
  }