@jayfong/x-server 2.12.6 → 2.12.14

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.
File without changes
@@ -1,247 +1,26 @@
1
1
  "use strict";
2
2
 
3
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
4
-
5
3
  exports.__esModule = true;
6
- exports.RequestService = exports.RequestFormUrlencoded = exports.RequestFormStream = exports.RequestFormData = void 0;
7
-
8
- var _formData = _interopRequireDefault(require("form-data"));
9
-
10
- var _formstream = _interopRequireDefault(require("formstream"));
11
-
12
- var _got = _interopRequireDefault(require("got"));
13
-
14
- var _vtils = require("vtils");
15
-
16
- var _proxyAgent = require("proxy-agent");
17
-
18
- class RequestFormUrlencoded extends URLSearchParams {}
19
-
20
- exports.RequestFormUrlencoded = RequestFormUrlencoded;
21
-
22
- class RequestFormData extends _formData.default {
23
- constructor(cb) {
24
- super();
25
-
26
- if (cb) {
27
- cb(this);
28
- }
29
- }
30
-
31
- }
32
-
33
- exports.RequestFormData = RequestFormData;
34
-
35
- class RequestFormStream extends _formstream.default {
36
- constructor(cb) {
37
- super();
38
-
39
- if (cb) {
40
- cb(this);
41
- }
42
- }
43
-
44
- }
45
-
46
- exports.RequestFormStream = RequestFormStream;
47
-
48
- class RequestService {
49
- static getGotOptions(options, responseType) {
50
- var _gotOptions$headers, _userAgent, _gotOptions$headers$_, _options$userAgent;
51
-
52
- const gotOptions = {
53
- url: options.url,
54
- responseType: responseType === 'stream' ? undefined : responseType,
55
- rejectUnauthorized: false,
56
- isStream: responseType === 'stream'
57
- };
58
-
59
- if (options.headers) {
60
- gotOptions.headers = options.headers;
61
- }
62
-
63
- if (options.followRedirect != null) {
64
- gotOptions.followRedirect = options.followRedirect;
65
- }
66
-
67
- if (options.timeoutMs) {
68
- gotOptions.timeout = options.timeoutMs;
69
- }
70
-
71
- if (options.proxyUrl) {
72
- const proxyAgent = new _proxyAgent.ProxyAgent({
73
- getProxyForUrl: () => options.proxyUrl
74
- });
75
- gotOptions.agent = {
76
- http: proxyAgent,
77
- https: proxyAgent,
78
- http2: proxyAgent
79
- };
80
- }
81
-
82
- if (options.cookieJar) {
83
- gotOptions.cookieJar = options.cookieJar;
84
- } // 头处理
85
-
86
-
87
- gotOptions.headers = (0, _vtils.mapKeys)(gotOptions.headers || {}, (v, k) => k.toLowerCase());
88
- (_gotOptions$headers$_ = (_gotOptions$headers = gotOptions.headers)[_userAgent = 'user-agent']) != null ? _gotOptions$headers$_ : _gotOptions$headers[_userAgent] = (_options$userAgent = options.userAgent) != null ? _options$userAgent : 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.127 Safari/537.36';
89
-
90
- if (options.autoReferer && gotOptions.headers['referer'] == null) {
91
- gotOptions.headers['referer'] = options.url;
92
- }
93
-
94
- return gotOptions;
95
- }
96
-
97
- static getRaw(options, responseType) {
98
- let url = options.url;
99
-
100
- if (options.data) {
101
- const _url = new URL(url);
102
-
103
- Object.keys(options.data).forEach(key => {
104
- _url.searchParams.set(key, options.data[key]);
105
- });
106
- url = _url.toString();
107
- }
108
-
109
- options.url = url;
110
- const res = (0, _got.default)({
111
- method: 'GET',
112
- ...this.getGotOptions(options, responseType || 'buffer')
113
- });
114
-
115
- if (responseType === 'stream') {
116
- return res;
117
- }
118
-
119
- return res.then(res => ({
120
- status: res.statusCode,
121
- headers: res.headers,
122
- data: res.body
123
- }));
124
- }
125
-
126
- static postRaw(options, responseType) {
127
- const gotOptions = this.getGotOptions(options, responseType || 'buffer');
128
-
129
- if (responseType === 'stream' && options.data instanceof _formstream.default) {
130
- gotOptions.headers = options.data.headers(gotOptions.headers);
131
- }
132
-
133
- const res = (0, _got.default)({
134
- method: 'POST',
135
- ...(options.data == null ? {
136
- body: ''
137
- } : options.data instanceof _formData.default ? {
138
- body: options.data
139
- } : options.data instanceof URLSearchParams ? {
140
- form: options.data
141
- } : options.data instanceof _formstream.default ? {} : {
142
- json: options.data
143
- }),
144
- ...gotOptions
145
- });
146
-
147
- if (responseType === 'stream' && options.data instanceof _formstream.default) {
148
- options.data.pipe(res);
149
- }
150
-
151
- if (responseType === 'stream') {
152
- return res;
153
- }
154
-
155
- return res.then(res => ({
156
- status: res.statusCode,
157
- headers: res.headers,
158
- data: res.body
159
- }));
160
- }
161
-
162
- static async getText(options) {
163
- return this.getRaw(options, 'text');
164
- }
165
-
166
- static async postText(options) {
167
- return this.postRaw(options, 'text');
168
- }
169
-
170
- static async get(options) {
171
- return this.getRaw(options, 'json');
172
- }
173
-
174
- static async post(options) {
175
- return this.postRaw(options, 'json');
176
- }
177
-
178
- static getStream(options) {
179
- return this.getRaw(options, 'stream');
180
- }
181
-
182
- static postStream(options) {
183
- return this.postRaw(options, 'stream');
184
- }
185
-
186
- static isTimeoutError(err) {
187
- return err instanceof _got.default.TimeoutError;
188
- }
189
-
190
- constructor(options) {
191
- this.options = options;
4
+ var _exportNames = {
5
+ RequestService: true
6
+ };
7
+ exports.RequestService = void 0;
8
+
9
+ var _xRequest = require("@jayfong/x-request");
10
+
11
+ Object.keys(_xRequest).forEach(function (key) {
12
+ if (key === "default" || key === "__esModule") return;
13
+ if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
14
+ if (key in exports && exports[key] === _xRequest[key]) return;
15
+ exports[key] = _xRequest[key];
16
+ });
17
+
18
+ class RequestService extends _xRequest.XRequest {
19
+ constructor(...args) {
20
+ super(...args);
192
21
  this.serviceName = 'request';
193
22
  }
194
23
 
195
- getRaw(options, responseType) {
196
- var _this$options;
197
-
198
- return RequestService.getRaw({ ...this.options,
199
- ...options,
200
- headers: { ...((_this$options = this.options) == null ? void 0 : _this$options.headers),
201
- ...options.headers
202
- }
203
- }, responseType);
204
- }
205
-
206
- postRaw(options, responseType) {
207
- var _this$options2;
208
-
209
- return RequestService.postRaw({ ...this.options,
210
- ...options,
211
- headers: { ...((_this$options2 = this.options) == null ? void 0 : _this$options2.headers),
212
- ...options.headers
213
- }
214
- }, responseType);
215
- }
216
-
217
- async getText(options) {
218
- return this.getRaw(options, 'text');
219
- }
220
-
221
- async postText(options) {
222
- return this.postRaw(options, 'text');
223
- }
224
-
225
- async get(options) {
226
- return this.getRaw(options, 'json');
227
- }
228
-
229
- async post(options) {
230
- return this.postRaw(options, 'json');
231
- }
232
-
233
- getStream(options) {
234
- return this.getRaw(options, 'stream');
235
- }
236
-
237
- postStream(options) {
238
- return this.postRaw(options, 'stream');
239
- }
240
-
241
- isTimeoutError(err) {
242
- return RequestService.isTimeoutError(err);
243
- }
244
-
245
24
  }
246
25
 
247
26
  exports.RequestService = RequestService;
@@ -1,114 +1,8 @@
1
- /// <reference types="node" />
2
- import FormData from 'form-data';
3
- import FormStream from 'formstream';
4
- import Request from 'got/dist/source/core';
5
1
  import { BaseService } from './base';
6
- import { CookieJar } from 'tough-cookie';
7
- import { OmitStrict } from 'vtils/types';
8
- export interface RequestServiceOptions {
9
- /**
10
- * 请求地址
11
- */
12
- url: string;
13
- /**
14
- * 代理地址
15
- */
16
- proxyUrl?: string;
17
- /**
18
- * 超时毫秒数
19
- */
20
- timeoutMs?: number;
21
- /**
22
- * 头
23
- */
24
- headers?: Record<string, any>;
25
- /**
26
- * 是否跟随跳转
27
- *
28
- * @default true
29
- */
30
- followRedirect?: boolean;
31
- /**
32
- * COOKIE 容器
33
- */
34
- cookieJar?: CookieJar;
35
- /**
36
- * 用户代理
37
- *
38
- * @default "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.127 Safari/537.36"
39
- */
40
- userAgent?: string;
41
- /**
42
- * 是否自动设置来源地址,设为 true 后若未手动设置来源页则将把请求地址设为来源地址
43
- *
44
- * @default false
45
- */
46
- autoReferer?: boolean;
47
- }
48
- export interface RequestServiceResponse<T> {
49
- status: number;
50
- headers: Record<string, any>;
51
- data: T;
52
- }
53
- export interface RequestServiceGetOptions extends RequestServiceOptions {
54
- data?: Record<string, any>;
55
- }
56
- export interface RequestServicePostOptions extends RequestServiceOptions {
57
- data?: Record<string, any> | FormData | URLSearchParams;
58
- }
59
- export interface RequestServiceGetStreamOptions extends RequestServiceOptions {
60
- data?: Record<string, any>;
61
- }
62
- export interface RequestServicePostStreamOptions extends RequestServiceOptions {
63
- data?: Record<string, any> | FormData | URLSearchParams | FormStream;
64
- }
65
- export declare class RequestFormUrlencoded extends URLSearchParams {
66
- }
67
- export declare class RequestFormData extends FormData {
68
- constructor(cb?: (formData: FormData) => FormData);
69
- }
70
- export declare class RequestFormStream extends FormStream {
71
- constructor(cb?: (formStream: FormStream) => FormStream);
72
- }
73
- export declare class RequestService implements BaseService {
74
- private options?;
2
+ import { XRequest } from '@jayfong/x-request';
3
+ export * from '@jayfong/x-request';
4
+ export declare class RequestService extends XRequest implements BaseService {
75
5
  serviceName: string;
76
- private static getGotOptions;
77
- static getRaw(options: RequestServiceGetStreamOptions): Promise<RequestServiceResponse<Buffer>>;
78
- static getRaw(options: RequestServiceGetStreamOptions, responseType: 'buffer'): Promise<RequestServiceResponse<Buffer>>;
79
- static getRaw(options: RequestServiceGetStreamOptions, responseType: 'text'): Promise<RequestServiceResponse<string>>;
80
- static getRaw<T>(options: RequestServiceGetStreamOptions, responseType: 'json'): Promise<RequestServiceResponse<T>>;
81
- static getRaw(options: RequestServiceGetStreamOptions, responseType: 'stream'): Request;
82
- static postRaw(options: RequestServicePostOptions): Promise<RequestServiceResponse<Buffer>>;
83
- static postRaw(options: RequestServicePostOptions, responseType: 'buffer'): Promise<RequestServiceResponse<Buffer>>;
84
- static postRaw(options: RequestServicePostOptions, responseType: 'text'): Promise<RequestServiceResponse<string>>;
85
- static postRaw<T>(options: RequestServicePostOptions, responseType: 'json'): Promise<RequestServiceResponse<T>>;
86
- static postRaw(options: RequestServicePostOptions, responseType: 'stream'): Request;
87
- static getText(options: RequestServiceGetStreamOptions): Promise<RequestServiceResponse<string>>;
88
- static postText(options: RequestServicePostOptions): Promise<RequestServiceResponse<string>>;
89
- static get<T>(options: RequestServiceGetStreamOptions): Promise<RequestServiceResponse<T>>;
90
- static post<T>(options: RequestServicePostOptions): Promise<RequestServiceResponse<T>>;
91
- static getStream(options: RequestServiceGetOptions): Request;
92
- static postStream(options: RequestServicePostStreamOptions): Request;
93
- static isTimeoutError(err: any): boolean;
94
- constructor(options?: OmitStrict<RequestServiceOptions, 'url'>);
95
- getRaw(options: RequestServiceGetStreamOptions): Promise<RequestServiceResponse<Buffer>>;
96
- getRaw(options: RequestServiceGetStreamOptions, responseType: 'buffer'): Promise<RequestServiceResponse<Buffer>>;
97
- getRaw(options: RequestServiceGetStreamOptions, responseType: 'text'): Promise<RequestServiceResponse<string>>;
98
- getRaw<T>(options: RequestServiceGetStreamOptions, responseType: 'json'): Promise<RequestServiceResponse<T>>;
99
- getRaw(options: RequestServiceGetStreamOptions, responseType: 'stream'): Request;
100
- postRaw(options: RequestServicePostOptions): Promise<RequestServiceResponse<Buffer>>;
101
- postRaw(options: RequestServicePostOptions, responseType: 'buffer'): Promise<RequestServiceResponse<Buffer>>;
102
- postRaw(options: RequestServicePostOptions, responseType: 'text'): Promise<RequestServiceResponse<string>>;
103
- postRaw<T>(options: RequestServicePostOptions, responseType: 'json'): Promise<RequestServiceResponse<T>>;
104
- postRaw(options: RequestServicePostOptions, responseType: 'stream'): Request;
105
- getText(options: RequestServiceGetStreamOptions): Promise<RequestServiceResponse<string>>;
106
- postText(options: RequestServicePostOptions): Promise<RequestServiceResponse<string>>;
107
- get<T>(options: RequestServiceGetStreamOptions): Promise<RequestServiceResponse<T>>;
108
- post<T>(options: RequestServicePostOptions): Promise<RequestServiceResponse<T>>;
109
- getStream(options: RequestServiceGetOptions): Request;
110
- postStream(options: RequestServicePostStreamOptions): Request;
111
- isTimeoutError(err: any): boolean;
112
6
  }
113
7
  declare module '../x' {
114
8
  interface X {
@@ -1,224 +1,9 @@
1
- import FormData from 'form-data';
2
- import FormStream from 'formstream';
3
- import got from 'got';
4
- import { mapKeys } from 'vtils';
5
- import { ProxyAgent } from 'proxy-agent';
6
- export class RequestFormUrlencoded extends URLSearchParams {}
7
- export class RequestFormData extends FormData {
8
- constructor(cb) {
9
- super();
10
-
11
- if (cb) {
12
- cb(this);
13
- }
14
- }
15
-
16
- }
17
- export class RequestFormStream extends FormStream {
18
- constructor(cb) {
19
- super();
20
-
21
- if (cb) {
22
- cb(this);
23
- }
24
- }
25
-
26
- }
27
- export class RequestService {
28
- static getGotOptions(options, responseType) {
29
- var _gotOptions$headers, _userAgent, _gotOptions$headers$_, _options$userAgent;
30
-
31
- const gotOptions = {
32
- url: options.url,
33
- responseType: responseType === 'stream' ? undefined : responseType,
34
- rejectUnauthorized: false,
35
- isStream: responseType === 'stream'
36
- };
37
-
38
- if (options.headers) {
39
- gotOptions.headers = options.headers;
40
- }
41
-
42
- if (options.followRedirect != null) {
43
- gotOptions.followRedirect = options.followRedirect;
44
- }
45
-
46
- if (options.timeoutMs) {
47
- gotOptions.timeout = options.timeoutMs;
48
- }
49
-
50
- if (options.proxyUrl) {
51
- const proxyAgent = new ProxyAgent({
52
- getProxyForUrl: () => options.proxyUrl
53
- });
54
- gotOptions.agent = {
55
- http: proxyAgent,
56
- https: proxyAgent,
57
- http2: proxyAgent
58
- };
59
- }
60
-
61
- if (options.cookieJar) {
62
- gotOptions.cookieJar = options.cookieJar;
63
- } // 头处理
64
-
65
-
66
- gotOptions.headers = mapKeys(gotOptions.headers || {}, (v, k) => k.toLowerCase());
67
- (_gotOptions$headers$_ = (_gotOptions$headers = gotOptions.headers)[_userAgent = 'user-agent']) != null ? _gotOptions$headers$_ : _gotOptions$headers[_userAgent] = (_options$userAgent = options.userAgent) != null ? _options$userAgent : 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.127 Safari/537.36';
68
-
69
- if (options.autoReferer && gotOptions.headers['referer'] == null) {
70
- gotOptions.headers['referer'] = options.url;
71
- }
72
-
73
- return gotOptions;
74
- }
75
-
76
- static getRaw(options, responseType) {
77
- let url = options.url;
78
-
79
- if (options.data) {
80
- const _url = new URL(url);
81
-
82
- Object.keys(options.data).forEach(key => {
83
- _url.searchParams.set(key, options.data[key]);
84
- });
85
- url = _url.toString();
86
- }
87
-
88
- options.url = url;
89
- const res = got({
90
- method: 'GET',
91
- ...this.getGotOptions(options, responseType || 'buffer')
92
- });
93
-
94
- if (responseType === 'stream') {
95
- return res;
96
- }
97
-
98
- return res.then(res => ({
99
- status: res.statusCode,
100
- headers: res.headers,
101
- data: res.body
102
- }));
103
- }
104
-
105
- static postRaw(options, responseType) {
106
- const gotOptions = this.getGotOptions(options, responseType || 'buffer');
107
-
108
- if (responseType === 'stream' && options.data instanceof FormStream) {
109
- gotOptions.headers = options.data.headers(gotOptions.headers);
110
- }
111
-
112
- const res = got({
113
- method: 'POST',
114
- ...(options.data == null ? {
115
- body: ''
116
- } : options.data instanceof FormData ? {
117
- body: options.data
118
- } : options.data instanceof URLSearchParams ? {
119
- form: options.data
120
- } : options.data instanceof FormStream ? {} : {
121
- json: options.data
122
- }),
123
- ...gotOptions
124
- });
125
-
126
- if (responseType === 'stream' && options.data instanceof FormStream) {
127
- options.data.pipe(res);
128
- }
129
-
130
- if (responseType === 'stream') {
131
- return res;
132
- }
133
-
134
- return res.then(res => ({
135
- status: res.statusCode,
136
- headers: res.headers,
137
- data: res.body
138
- }));
139
- }
140
-
141
- static async getText(options) {
142
- return this.getRaw(options, 'text');
143
- }
144
-
145
- static async postText(options) {
146
- return this.postRaw(options, 'text');
147
- }
148
-
149
- static async get(options) {
150
- return this.getRaw(options, 'json');
151
- }
152
-
153
- static async post(options) {
154
- return this.postRaw(options, 'json');
155
- }
156
-
157
- static getStream(options) {
158
- return this.getRaw(options, 'stream');
159
- }
160
-
161
- static postStream(options) {
162
- return this.postRaw(options, 'stream');
163
- }
164
-
165
- static isTimeoutError(err) {
166
- return err instanceof got.TimeoutError;
167
- }
168
-
169
- constructor(options) {
170
- this.options = options;
1
+ import { XRequest } from '@jayfong/x-request';
2
+ export * from '@jayfong/x-request';
3
+ export class RequestService extends XRequest {
4
+ constructor(...args) {
5
+ super(...args);
171
6
  this.serviceName = 'request';
172
7
  }
173
8
 
174
- getRaw(options, responseType) {
175
- var _this$options;
176
-
177
- return RequestService.getRaw({ ...this.options,
178
- ...options,
179
- headers: { ...((_this$options = this.options) == null ? void 0 : _this$options.headers),
180
- ...options.headers
181
- }
182
- }, responseType);
183
- }
184
-
185
- postRaw(options, responseType) {
186
- var _this$options2;
187
-
188
- return RequestService.postRaw({ ...this.options,
189
- ...options,
190
- headers: { ...((_this$options2 = this.options) == null ? void 0 : _this$options2.headers),
191
- ...options.headers
192
- }
193
- }, responseType);
194
- }
195
-
196
- async getText(options) {
197
- return this.getRaw(options, 'text');
198
- }
199
-
200
- async postText(options) {
201
- return this.postRaw(options, 'text');
202
- }
203
-
204
- async get(options) {
205
- return this.getRaw(options, 'json');
206
- }
207
-
208
- async post(options) {
209
- return this.postRaw(options, 'json');
210
- }
211
-
212
- getStream(options) {
213
- return this.getRaw(options, 'stream');
214
- }
215
-
216
- postStream(options) {
217
- return this.postRaw(options, 'stream');
218
- }
219
-
220
- isTimeoutError(err) {
221
- return RequestService.isTimeoutError(err);
222
- }
223
-
224
9
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jayfong/x-server",
3
- "version": "2.12.6",
3
+ "version": "2.12.14",
4
4
  "license": "ISC",
5
5
  "sideEffects": false,
6
6
  "main": "lib/_cjs/index.js",
@@ -13,19 +13,10 @@
13
13
  "lib"
14
14
  ],
15
15
  "scripts": {
16
- "bootstrap": "tyn --frozen-lockfile",
17
16
  "build": "haoma compile",
18
17
  "build_test_pkg": "tyn build && rm -rf ./lib_test && mkdir -p ./lib_test && cp -r ./lib ./lib_test/lib && cp ./package.json ./lib_test/package.json && cd ./tests/app && tyn add file:../../lib_test",
19
- "dev": "rm -rf lib && tsc -w -p ./tsconfig.build.json",
20
- "release": "source proxy-use-trojan.sh && tyn test && standard-version -a && tyn build && npm publish && haoma run ./scripts/publish_client_helper_package.ts && git push --follow-tags origin master",
21
18
  "test": "tsc --noEmit -p ./tsconfig.build.json && jest \"$(pwd)/src/\"",
22
- "test_all": "tsc --noEmit -p ./tsconfig.build.json && jest",
23
- "updeps": "tnpx npm-check-updates --target minor --upgrade"
24
- },
25
- "husky": {
26
- "hooks": {
27
- "post-merge": "tyn bootstrap"
28
- }
19
+ "test_all": "tsc --noEmit -p ./tsconfig.build.json && jest"
29
20
  },
30
21
  "dependencies": {
31
22
  "@fastify/cors": "^8.3.0",
@@ -54,10 +45,7 @@
54
45
  "exit-hook": "^2.2.1",
55
46
  "fast-xml-parser": "^4.2.5",
56
47
  "fastify": "^4.19.2",
57
- "form-data": "^4.0.0",
58
- "formstream": "^1.2.0",
59
48
  "fs-extra": "^10.0.1",
60
- "get-port": "^7.0.0",
61
49
  "globby": "^11",
62
50
  "got": "^11.8.2",
63
51
  "http-errors": "^2.0.0",
@@ -71,17 +59,16 @@
71
59
  "nodemailer": "^6.7.3",
72
60
  "pino-pretty": "^10.0.1",
73
61
  "prisma": "^4.8.0",
74
- "proxy-agent": "^6.2.2",
75
62
  "select-run": "^1.1.2",
76
63
  "supports-color": "^8",
77
64
  "svg-captcha": "^1.4.0",
78
- "tough-cookie": "^4.1.3",
79
65
  "ts-morph": "^12.2.0",
80
66
  "utf-8-validate": "^5.0.9",
81
67
  "vscode-generate-index-standalone": "^1.7.1",
82
68
  "vtils": "^4.85.3",
83
69
  "yaml": "^2.3.1",
84
- "yargs": "^17.4.1"
70
+ "yargs": "^17.4.1",
71
+ "@jayfong/x-request": "^2.12.14"
85
72
  },
86
73
  "devDependencies": {
87
74
  "@types/debug": "^4.1.7",
@@ -90,20 +77,10 @@
90
77
  "@types/json-schema": "^7.0.11",
91
78
  "@types/lz-string": "^1.3.34",
92
79
  "axios": "^1.4.0",
93
- "eslint": "^7.32.0",
94
- "haoma": "^3.6.4",
95
- "husky": "^4.3.8",
96
80
  "ioredis-mock": "^8.7.0",
97
- "jest": "^27.5.1",
98
81
  "json-xml-parse": "^1.2.4",
99
- "lint-staged": "^10.5.4",
100
82
  "node-fetch": "^3.3.1",
101
- "npm-check-updates": "^12.5.9",
102
- "prettier": "^2.8.8",
103
- "proxy": "^2.1.1",
104
- "standard-version": "^9.3.2",
105
- "typescript": "^5.1.6",
106
- "typescript-snapshots-plugin": "^1.7.0"
83
+ "npm-check-updates": "^12.5.9"
107
84
  },
108
85
  "publishConfig": {
109
86
  "access": "public"
package/README.md DELETED
@@ -1,51 +0,0 @@
1
- # x-server
2
-
3
- X 服务端。
4
-
5
- ## 技术栈
6
-
7
- - [fastify v3](https://github.com/fastify/fastify)
8
- - [prisma v3](https://github.com/prisma/prisma)
9
-
10
- ## 特性
11
-
12
- - 通过 `cache` 支持 redis 缓存
13
- - 通过 `jwt` 支持用户认证
14
- - 通过 `captcha` 支持验证码
15
- - 通过 `defineHandler` 支持 POST、GET、POST、FILE、WS、XML 请求
16
- - 通过 `defineTask` 支持定时任务
17
-
18
- ## 命令
19
-
20
- ### xs dev
21
-
22
- 开始开发
23
-
24
- - `-i aaa -i bbb`: 额外需要生成的索引文件
25
- - `-npc xxx@bbbb`: npc 地址及密钥,格式:地址@密钥
26
-
27
- ### xs build
28
-
29
- 构建
30
-
31
- - `-e aaa -e bbb`: 不应该被打的包
32
-
33
- ### xs deploy
34
-
35
- 部署
36
-
37
- ### xs api
38
-
39
- 生成 API
40
-
41
- ### xs prisma
42
-
43
- prisma 代理,主要为了注入环境变量
44
-
45
- - `-p false`: 是否生产模式
46
-
47
- ### xs run
48
-
49
- 执行 package.json 里的脚本
50
-
51
- - `-p false`: 是否生产模式
@@ -1,26 +0,0 @@
1
- "use strict";
2
-
3
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
4
-
5
- exports.__esModule = true;
6
- exports.processXServerResponse = processXServerResponse;
7
-
8
- var _lzString = _interopRequireDefault(require("lz-string"));
9
-
10
- var _vtils = require("vtils");
11
-
12
- // _#
13
- const obfuscateKey = [90, 30].map(v => String.fromCharCode(v + 5)).join('');
14
-
15
- function processXServerResponse(data) {
16
- // 处理混淆
17
- if (data && typeof data === 'object' && data[obfuscateKey] != null) {
18
- try {
19
- data = JSON.parse(_lzString.default.decompress(data[obfuscateKey]));
20
- } catch {}
21
- } // 处理数组打包
22
-
23
-
24
- data = _vtils.DataPacker.unpackIfNeeded(data);
25
- return data;
26
- }
@@ -1 +0,0 @@
1
- "use strict";
@@ -1 +0,0 @@
1
- export declare function processXServerResponse<T>(data: any): T;
@@ -1,16 +0,0 @@
1
- import LZString from 'lz-string';
2
- import { DataPacker } from 'vtils'; // _#
3
-
4
- const obfuscateKey = [90, 30].map(v => String.fromCharCode(v + 5)).join('');
5
- export function processXServerResponse(data) {
6
- // 处理混淆
7
- if (data && typeof data === 'object' && data[obfuscateKey] != null) {
8
- try {
9
- data = JSON.parse(LZString.decompress(data[obfuscateKey]));
10
- } catch {}
11
- } // 处理数组打包
12
-
13
-
14
- data = DataPacker.unpackIfNeeded(data);
15
- return data;
16
- }
@@ -1,49 +0,0 @@
1
- /// <reference types="node" />
2
- /// <reference types="node" />
3
- declare module 'formstream' {
4
- import { Stream, Readable } from 'stream';
5
- class FormStream extends Stream {
6
- /**
7
- * Add a normal field to the form.
8
- *
9
- * @param name Name of field
10
- * @param value Value of field
11
- */
12
- field(name: string, value: string): this;
13
- /**
14
- * Add a local file to be uploaded to the form.
15
- *
16
- * @param name Name of file field
17
- * @param filepath Local path of the file to be uploaded
18
- * @param filename Name of the file (will be the base name of filepath if empty)
19
- * @param filesize Size of the file (will not generate Content-Length header if not specified)
20
- */
21
- file(name: string, filepath: string, filename?: string, filesize?: number): this;
22
- /**
23
- * Add a buffer as a file to upload.
24
- *
25
- * @param name Name of field
26
- * @param buffer The buffer to be uploaded
27
- * @param filename The file name that tells the remote server
28
- * @param contentType Content-Type (aka. MIME Type) of content (will be infered with filename if empty)
29
- */
30
- buffer(name: string, buffer: Buffer, filename: string, contentType?: string): this;
31
- /**
32
- * Add a readable stream as a file to upload. Event 'error' will be emitted if an error occured.
33
- *
34
- * @param name Name of field
35
- * @param stream A readable stream to be piped
36
- * @param filename The file name that tells the remote server
37
- * @param contentType Content-Type (aka. MIME Type) of content (will be infered with filename if empty)
38
- * @param size Size of the stream (will not generate Content-Length header if not specified)
39
- */
40
- stream(name: string, stream: Readable, filename: string, contentType?: string, size?: number): this;
41
- /**
42
- * Get headers for the request.
43
- *
44
- * @param additionalHeaders Additional headers
45
- */
46
- headers(additionalHeaders?: Record<string, any>): Record<string, any>;
47
- }
48
- export = FormStream;
49
- }
File without changes