cloud189-sdk 1.0.6-alpha.5 → 1.0.7
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 +3 -0
- package/dist/CloudClient.d.ts +4 -0
- package/dist/CloudClient.js +60 -25
- package/dist/index.d.ts +2 -1
- package/dist/index.js +2 -5
- package/dist/log.d.ts +7 -23
- package/dist/log.js +8 -100
- package/dist/store/file-token-store.d.ts +1 -0
- package/dist/store/file-token-store.js +11 -0
- package/dist/types.d.ts +1 -0
- package/dist/util.d.ts +1 -0
- package/dist/util.js +3 -2
- package/package.json +10 -7
package/README.md
CHANGED
|
@@ -14,6 +14,9 @@
|
|
|
14
14
|
<a href="https://npmcharts.com/compare/cloud189-sdk?minimal=true">
|
|
15
15
|
<img src="http://img.shields.io/npm/dm/cloud189-sdk.svg">
|
|
16
16
|
</a>
|
|
17
|
+
<a href="https://coveralls.io/github/wes-lin/cloud189-sdk">
|
|
18
|
+
<img src="https://coveralls.io/repos/github/wes-lin/cloud189-sdk/badge.svg?branch=dev">
|
|
19
|
+
</a>
|
|
17
20
|
<a href="LICENSE">
|
|
18
21
|
<img src="https://img.shields.io/badge/License-MIT-yellow.svg">
|
|
19
22
|
</a>
|
package/dist/CloudClient.d.ts
CHANGED
|
@@ -55,6 +55,10 @@ export declare class CloudClient {
|
|
|
55
55
|
readonly session: ClientSession;
|
|
56
56
|
constructor(_options: ConfigurationOptions);
|
|
57
57
|
getSession(): Promise<TokenSession>;
|
|
58
|
+
/**
|
|
59
|
+
* 获取 sessionKey
|
|
60
|
+
* @returns sessionKey
|
|
61
|
+
*/
|
|
58
62
|
getSessionKey(): Promise<string>;
|
|
59
63
|
/**
|
|
60
64
|
* 获取 accessToken
|
package/dist/CloudClient.js
CHANGED
|
@@ -4,10 +4,16 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
|
|
|
4
4
|
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
5
5
|
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
6
6
|
};
|
|
7
|
+
var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
|
|
8
|
+
if (kind === "m") throw new TypeError("Private method is not writable");
|
|
9
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
|
|
10
|
+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
|
|
11
|
+
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
|
12
|
+
};
|
|
7
13
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
8
14
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
9
15
|
};
|
|
10
|
-
var _CloudAuthClient_builLoginForm, _CloudClient_instances, _CloudClient_valid, _CloudClient_getAccessTokenBySsKey;
|
|
16
|
+
var _CloudAuthClient_builLoginForm, _CloudClient_instances, _CloudClient_sessionKeyPromise, _CloudClient_accessTokenPromise, _CloudClient_valid, _CloudClient_getAccessTokenBySsKey;
|
|
11
17
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
18
|
exports.CloudClient = exports.CloudAuthClient = void 0;
|
|
13
19
|
const url_1 = __importDefault(require("url"));
|
|
@@ -56,7 +62,7 @@ class CloudAuthClient {
|
|
|
56
62
|
hooks: {
|
|
57
63
|
afterResponse: [
|
|
58
64
|
async (response, retryWithMergedOptions) => {
|
|
59
|
-
log_1.
|
|
65
|
+
log_1.logger.debug(`url: ${response.requestUrl}, response: ${response.body})}`);
|
|
60
66
|
(0, error_1.checkError)(response.body.toString());
|
|
61
67
|
return response;
|
|
62
68
|
}
|
|
@@ -104,7 +110,7 @@ class CloudAuthClient {
|
|
|
104
110
|
* 用户名密码登录
|
|
105
111
|
* */
|
|
106
112
|
async loginByPassword(username, password) {
|
|
107
|
-
log_1.
|
|
113
|
+
log_1.logger.debug('loginByPassword...');
|
|
108
114
|
try {
|
|
109
115
|
const res = await Promise.all([
|
|
110
116
|
//1.获取公钥
|
|
@@ -128,7 +134,7 @@ class CloudAuthClient {
|
|
|
128
134
|
return await this.getSessionForPC({ redirectURL: loginRes.toUrl });
|
|
129
135
|
}
|
|
130
136
|
catch (e) {
|
|
131
|
-
log_1.
|
|
137
|
+
log_1.logger.error(e);
|
|
132
138
|
throw e;
|
|
133
139
|
}
|
|
134
140
|
}
|
|
@@ -136,14 +142,14 @@ class CloudAuthClient {
|
|
|
136
142
|
* token登录
|
|
137
143
|
*/
|
|
138
144
|
async loginByAccessToken(accessToken) {
|
|
139
|
-
log_1.
|
|
145
|
+
log_1.logger.debug('loginByAccessToken...');
|
|
140
146
|
return await this.getSessionForPC({ accessToken });
|
|
141
147
|
}
|
|
142
148
|
/**
|
|
143
149
|
* sso登录
|
|
144
150
|
*/
|
|
145
151
|
async loginBySsoCooike(cookie) {
|
|
146
|
-
log_1.
|
|
152
|
+
log_1.logger.debug('loginBySsoCooike...');
|
|
147
153
|
const res = await this.request.get(`${const_1.WEB_URL}/api/portal/unifyLoginForPC.action`, {
|
|
148
154
|
searchParams: {
|
|
149
155
|
appId: const_1.AppID,
|
|
@@ -184,9 +190,11 @@ _CloudAuthClient_builLoginForm = new WeakMap();
|
|
|
184
190
|
class CloudClient {
|
|
185
191
|
constructor(_options) {
|
|
186
192
|
_CloudClient_instances.add(this);
|
|
193
|
+
_CloudClient_sessionKeyPromise.set(this, void 0);
|
|
194
|
+
_CloudClient_accessTokenPromise.set(this, void 0);
|
|
187
195
|
_CloudClient_valid.set(this, (options) => {
|
|
188
196
|
if (!options.token && (!options.username || !options.password)) {
|
|
189
|
-
log_1.
|
|
197
|
+
log_1.logger.error('valid');
|
|
190
198
|
throw new Error('Please provide username and password or token !');
|
|
191
199
|
}
|
|
192
200
|
});
|
|
@@ -241,18 +249,18 @@ class CloudClient {
|
|
|
241
249
|
],
|
|
242
250
|
afterResponse: [
|
|
243
251
|
async (response, retryWithMergedOptions) => {
|
|
244
|
-
log_1.
|
|
252
|
+
log_1.logger.debug(`url: ${response.requestUrl}, response: ${response.body}`);
|
|
245
253
|
if (response.statusCode === 400) {
|
|
246
254
|
const { errorCode, errorMsg } = JSON.parse(response.body.toString());
|
|
247
255
|
if (errorCode === 'InvalidAccessToken') {
|
|
248
|
-
log_1.
|
|
249
|
-
log_1.
|
|
256
|
+
log_1.logger.debug('InvalidAccessToken retry...');
|
|
257
|
+
log_1.logger.debug('Refresh AccessToken');
|
|
250
258
|
this.session.accessToken = '';
|
|
251
259
|
return retryWithMergedOptions({});
|
|
252
260
|
}
|
|
253
261
|
else if (errorCode === 'InvalidSessionKey') {
|
|
254
|
-
log_1.
|
|
255
|
-
log_1.
|
|
262
|
+
log_1.logger.debug('InvalidSessionKey retry...');
|
|
263
|
+
log_1.logger.debug('Refresh InvalidSessionKey');
|
|
256
264
|
this.session.sessionKey = '';
|
|
257
265
|
return retryWithMergedOptions({});
|
|
258
266
|
}
|
|
@@ -270,7 +278,7 @@ class CloudClient {
|
|
|
270
278
|
return await this.authClient.loginByAccessToken(accessToken);
|
|
271
279
|
}
|
|
272
280
|
catch (e) {
|
|
273
|
-
log_1.
|
|
281
|
+
log_1.logger.error(e);
|
|
274
282
|
}
|
|
275
283
|
}
|
|
276
284
|
if (refreshToken) {
|
|
@@ -278,12 +286,13 @@ class CloudClient {
|
|
|
278
286
|
const refreshTokenSession = await this.authClient.refreshToken(refreshToken);
|
|
279
287
|
await this.tokenStore.update({
|
|
280
288
|
accessToken: refreshTokenSession.accessToken,
|
|
289
|
+
refreshToken: refreshTokenSession.refreshToken,
|
|
281
290
|
expiresIn: new Date(Date.now() + refreshTokenSession.expiresIn * 1000).getTime()
|
|
282
291
|
});
|
|
283
292
|
return await this.authClient.loginByAccessToken(refreshTokenSession.accessToken);
|
|
284
293
|
}
|
|
285
294
|
catch (e) {
|
|
286
|
-
log_1.
|
|
295
|
+
log_1.logger.error(e);
|
|
287
296
|
}
|
|
288
297
|
}
|
|
289
298
|
if (this.ssonCookie) {
|
|
@@ -292,12 +301,12 @@ class CloudClient {
|
|
|
292
301
|
await this.tokenStore.update({
|
|
293
302
|
accessToken: loginToken.accessToken,
|
|
294
303
|
refreshToken: loginToken.refreshToken,
|
|
295
|
-
expiresIn: new Date(Date.now() +
|
|
304
|
+
expiresIn: new Date(Date.now() + 6 * 24 * 60 * 60 * 1000).getTime()
|
|
296
305
|
});
|
|
297
306
|
return loginToken;
|
|
298
307
|
}
|
|
299
308
|
catch (e) {
|
|
300
|
-
log_1.
|
|
309
|
+
log_1.logger.error(e);
|
|
301
310
|
}
|
|
302
311
|
}
|
|
303
312
|
if (this.username && this.password) {
|
|
@@ -306,31 +315,57 @@ class CloudClient {
|
|
|
306
315
|
await this.tokenStore.update({
|
|
307
316
|
accessToken: loginToken.accessToken,
|
|
308
317
|
refreshToken: loginToken.refreshToken,
|
|
309
|
-
expiresIn: new Date(Date.now() +
|
|
318
|
+
expiresIn: new Date(Date.now() + 6 * 24 * 60 * 60 * 1000).getTime()
|
|
310
319
|
});
|
|
311
320
|
return loginToken;
|
|
312
321
|
}
|
|
313
322
|
catch (e) {
|
|
314
|
-
log_1.
|
|
323
|
+
log_1.logger.error(e);
|
|
315
324
|
}
|
|
316
325
|
}
|
|
317
326
|
throw new Error('Can not get session.');
|
|
318
327
|
}
|
|
328
|
+
/**
|
|
329
|
+
* 获取 sessionKey
|
|
330
|
+
* @returns sessionKey
|
|
331
|
+
*/
|
|
319
332
|
async getSessionKey() {
|
|
320
|
-
if (
|
|
321
|
-
this.session.sessionKey
|
|
333
|
+
if (this.session.sessionKey) {
|
|
334
|
+
return this.session.sessionKey;
|
|
322
335
|
}
|
|
323
|
-
|
|
336
|
+
if (!__classPrivateFieldGet(this, _CloudClient_sessionKeyPromise, "f")) {
|
|
337
|
+
__classPrivateFieldSet(this, _CloudClient_sessionKeyPromise, this.getSession()
|
|
338
|
+
.then((result) => {
|
|
339
|
+
this.session.sessionKey = result.sessionKey;
|
|
340
|
+
return result;
|
|
341
|
+
})
|
|
342
|
+
.finally(() => {
|
|
343
|
+
__classPrivateFieldSet(this, _CloudClient_sessionKeyPromise, null, "f");
|
|
344
|
+
}), "f");
|
|
345
|
+
}
|
|
346
|
+
const result = await __classPrivateFieldGet(this, _CloudClient_sessionKeyPromise, "f");
|
|
347
|
+
return result.sessionKey;
|
|
324
348
|
}
|
|
325
349
|
/**
|
|
326
350
|
* 获取 accessToken
|
|
327
351
|
* @returns accessToken
|
|
328
352
|
*/
|
|
329
353
|
async getAccessToken() {
|
|
330
|
-
if (
|
|
331
|
-
this.session.accessToken
|
|
354
|
+
if (this.session.accessToken) {
|
|
355
|
+
return this.session.accessToken;
|
|
356
|
+
}
|
|
357
|
+
if (!__classPrivateFieldGet(this, _CloudClient_accessTokenPromise, "f")) {
|
|
358
|
+
__classPrivateFieldSet(this, _CloudClient_accessTokenPromise, __classPrivateFieldGet(this, _CloudClient_instances, "m", _CloudClient_getAccessTokenBySsKey).call(this)
|
|
359
|
+
.then((result) => {
|
|
360
|
+
this.session.accessToken = result.accessToken;
|
|
361
|
+
return result;
|
|
362
|
+
})
|
|
363
|
+
.finally(() => {
|
|
364
|
+
__classPrivateFieldSet(this, _CloudClient_accessTokenPromise, null, "f");
|
|
365
|
+
}), "f");
|
|
332
366
|
}
|
|
333
|
-
|
|
367
|
+
const result = await __classPrivateFieldGet(this, _CloudClient_accessTokenPromise, "f");
|
|
368
|
+
return result.accessToken;
|
|
334
369
|
}
|
|
335
370
|
/**
|
|
336
371
|
* 获取用户网盘存储容量信息
|
|
@@ -367,6 +402,6 @@ class CloudClient {
|
|
|
367
402
|
}
|
|
368
403
|
}
|
|
369
404
|
exports.CloudClient = CloudClient;
|
|
370
|
-
_CloudClient_valid = new WeakMap(), _CloudClient_instances = new WeakSet(), _CloudClient_getAccessTokenBySsKey = function _CloudClient_getAccessTokenBySsKey() {
|
|
405
|
+
_CloudClient_sessionKeyPromise = new WeakMap(), _CloudClient_accessTokenPromise = new WeakMap(), _CloudClient_valid = new WeakMap(), _CloudClient_instances = new WeakSet(), _CloudClient_getAccessTokenBySsKey = function _CloudClient_getAccessTokenBySsKey() {
|
|
371
406
|
return this.request.get(`${const_1.WEB_URL}/api/open/oauth2/getAccessTokenBySsKey.action`).json();
|
|
372
407
|
};
|
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -14,10 +14,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
14
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
exports.FileTokenStore = exports.MemoryStore = exports.Store = void 0;
|
|
18
17
|
__exportStar(require("./CloudClient"), exports);
|
|
19
18
|
__exportStar(require("./types"), exports);
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
Object.defineProperty(exports, "MemoryStore", { enumerable: true, get: function () { return store_1.MemoryStore; } });
|
|
23
|
-
Object.defineProperty(exports, "FileTokenStore", { enumerable: true, get: function () { return store_1.FileTokenStore; } });
|
|
19
|
+
__exportStar(require("./store"), exports);
|
|
20
|
+
__exportStar(require("./log"), exports);
|
package/dist/log.d.ts
CHANGED
|
@@ -1,23 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
export
|
|
8
|
-
export declare const PADDING = 2;
|
|
9
|
-
export declare class Logger {
|
|
10
|
-
protected readonly stream: WritableStream;
|
|
11
|
-
constructor(stream: WritableStream);
|
|
12
|
-
messageTransformer: (message: string, level: LogLevel) => string;
|
|
13
|
-
get isDebugEnabled(): boolean;
|
|
14
|
-
info(messageOrFields: Fields | null | string, message?: string): void;
|
|
15
|
-
error(messageOrFields: Fields | null | string, message?: string): void;
|
|
16
|
-
warn(messageOrFields: Fields | null | string, message?: string): void;
|
|
17
|
-
debug(messageOrFields: Fields | null | string, message?: string): void;
|
|
18
|
-
private doLog;
|
|
19
|
-
private _doLog;
|
|
20
|
-
static createMessage(message: string, fields: Fields | null, level: LogLevel, color: (it: string) => string, messagePadding?: number): string;
|
|
21
|
-
log(message: string): void;
|
|
22
|
-
}
|
|
23
|
-
export declare const log: Logger;
|
|
1
|
+
import { Logger } from '@netdrive-sdk/log';
|
|
2
|
+
/**
|
|
3
|
+
* 日志记录
|
|
4
|
+
* @public
|
|
5
|
+
*/
|
|
6
|
+
declare const logger: Logger;
|
|
7
|
+
export { logger };
|
package/dist/log.js
CHANGED
|
@@ -1,102 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.
|
|
7
|
-
const
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
this.messageTransformer = (it) => it;
|
|
15
|
-
}
|
|
16
|
-
get isDebugEnabled() {
|
|
17
|
-
return exports.debug;
|
|
18
|
-
}
|
|
19
|
-
info(messageOrFields, message) {
|
|
20
|
-
this.doLog(message, messageOrFields, 'info');
|
|
21
|
-
}
|
|
22
|
-
error(messageOrFields, message) {
|
|
23
|
-
this.doLog(message, messageOrFields, 'error');
|
|
24
|
-
}
|
|
25
|
-
warn(messageOrFields, message) {
|
|
26
|
-
this.doLog(message, messageOrFields, 'warn');
|
|
27
|
-
}
|
|
28
|
-
debug(messageOrFields, message) {
|
|
29
|
-
if (this.isDebugEnabled) {
|
|
30
|
-
this.doLog(message, messageOrFields, 'debug');
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
doLog(message, messageOrFields, level) {
|
|
34
|
-
if (message === undefined) {
|
|
35
|
-
this._doLog(messageOrFields, null, level);
|
|
36
|
-
}
|
|
37
|
-
else {
|
|
38
|
-
this._doLog(message, messageOrFields, level);
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
_doLog(message, fields, level) {
|
|
42
|
-
// noinspection SuspiciousInstanceOfGuard
|
|
43
|
-
if (message instanceof Error) {
|
|
44
|
-
message = message.stack || message.toString();
|
|
45
|
-
}
|
|
46
|
-
else {
|
|
47
|
-
message = message.toString();
|
|
48
|
-
}
|
|
49
|
-
const levelIndicator = level === 'error' ? '⨯' : '•';
|
|
50
|
-
const color = LEVEL_TO_COLOR[level];
|
|
51
|
-
this.stream.write(`${' '.repeat(exports.PADDING)}${color(levelIndicator)} `);
|
|
52
|
-
this.stream.write(Logger.createMessage(this.messageTransformer(message, level), fields, level, color, exports.PADDING + 2 /* level indicator and space */));
|
|
53
|
-
this.stream.write('\n');
|
|
54
|
-
}
|
|
55
|
-
static createMessage(message, fields, level, color, messagePadding = 0) {
|
|
56
|
-
if (fields == null) {
|
|
57
|
-
return message;
|
|
58
|
-
}
|
|
59
|
-
const fieldPadding = ' '.repeat(Math.max(2, 16 - message.length));
|
|
60
|
-
let text = (level === 'error' ? color(message) : message) + fieldPadding;
|
|
61
|
-
const fieldNames = Object.keys(fields);
|
|
62
|
-
let counter = 0;
|
|
63
|
-
for (const name of fieldNames) {
|
|
64
|
-
let fieldValue = fields[name];
|
|
65
|
-
let valuePadding = null;
|
|
66
|
-
// Remove unnecessary line breaks
|
|
67
|
-
if (fieldValue != null && typeof fieldValue === 'string' && fieldValue.includes('\n')) {
|
|
68
|
-
valuePadding = ' '.repeat(messagePadding + message.length + fieldPadding.length + 2);
|
|
69
|
-
fieldValue = fieldValue.replace(/\n\s*\n/g, `\n${valuePadding}`);
|
|
70
|
-
}
|
|
71
|
-
else if (Array.isArray(fieldValue)) {
|
|
72
|
-
fieldValue = JSON.stringify(fieldValue);
|
|
73
|
-
}
|
|
74
|
-
text += `${color(name)}=${fieldValue}`;
|
|
75
|
-
if (++counter !== fieldNames.length) {
|
|
76
|
-
if (valuePadding == null) {
|
|
77
|
-
text += ' ';
|
|
78
|
-
}
|
|
79
|
-
else {
|
|
80
|
-
text += '\n' + valuePadding;
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
return text;
|
|
85
|
-
}
|
|
86
|
-
log(message) {
|
|
87
|
-
if (printer == null) {
|
|
88
|
-
this.stream.write(`${message}\n`);
|
|
89
|
-
}
|
|
90
|
-
else {
|
|
91
|
-
printer(message);
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
exports.Logger = Logger;
|
|
96
|
-
const LEVEL_TO_COLOR = {
|
|
97
|
-
info: chalk_1.default.blue,
|
|
98
|
-
warn: chalk_1.default.yellow,
|
|
99
|
-
error: chalk_1.default.red,
|
|
100
|
-
debug: chalk_1.default.white
|
|
101
|
-
};
|
|
102
|
-
exports.log = new Logger(process.stdout);
|
|
3
|
+
exports.logger = void 0;
|
|
4
|
+
const log_1 = require("@netdrive-sdk/log");
|
|
5
|
+
/**
|
|
6
|
+
* 日志记录
|
|
7
|
+
* @public
|
|
8
|
+
*/
|
|
9
|
+
const logger = new log_1.Logger();
|
|
10
|
+
exports.logger = logger;
|
|
@@ -27,11 +27,15 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
|
|
|
27
27
|
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
28
28
|
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
29
29
|
};
|
|
30
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
31
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
32
|
+
};
|
|
30
33
|
var _FileTokenStore_instances, _FileTokenStore_loadFromFile, _FileTokenStore_saveToFile;
|
|
31
34
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
32
35
|
exports.FileTokenStore = void 0;
|
|
33
36
|
const fs = __importStar(require("node:fs"));
|
|
34
37
|
const promisesFs = __importStar(require("node:fs/promises"));
|
|
38
|
+
const path_1 = __importDefault(require("path"));
|
|
35
39
|
const memstore_1 = require("./memstore");
|
|
36
40
|
/**
|
|
37
41
|
* @public
|
|
@@ -44,11 +48,18 @@ class FileTokenStore extends memstore_1.MemoryStore {
|
|
|
44
48
|
if (!filePath) {
|
|
45
49
|
throw new Error('Unknown file for read/write token');
|
|
46
50
|
}
|
|
51
|
+
this.ensureTokenDirectory(filePath);
|
|
47
52
|
const dataJson = __classPrivateFieldGet(this, _FileTokenStore_instances, "m", _FileTokenStore_loadFromFile).call(this, filePath);
|
|
48
53
|
if (dataJson) {
|
|
49
54
|
super.update(dataJson);
|
|
50
55
|
}
|
|
51
56
|
}
|
|
57
|
+
ensureTokenDirectory(filePath) {
|
|
58
|
+
const dir = path_1.default.dirname(filePath);
|
|
59
|
+
if (!fs.existsSync(dir)) {
|
|
60
|
+
fs.mkdirSync(dir, { recursive: true });
|
|
61
|
+
}
|
|
62
|
+
}
|
|
52
63
|
update(token) {
|
|
53
64
|
super.update(token);
|
|
54
65
|
return __classPrivateFieldGet(this, _FileTokenStore_instances, "m", _FileTokenStore_saveToFile).call(this, this.filePath, this.store);
|
package/dist/types.d.ts
CHANGED
package/dist/util.d.ts
CHANGED
package/dist/util.js
CHANGED
|
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.rsaEncrypt = exports.getSignature = void 0;
|
|
6
|
+
exports.rsaEncrypt = exports.getSignature = exports.sortParameter = void 0;
|
|
7
7
|
const crypto_1 = __importDefault(require("crypto"));
|
|
8
8
|
const sortParameter = (data) => {
|
|
9
9
|
if (!data) {
|
|
@@ -13,8 +13,9 @@ const sortParameter = (data) => {
|
|
|
13
13
|
e.sort((a, b) => (a > b ? 1 : a < b ? -1 : 0));
|
|
14
14
|
return e.join('&');
|
|
15
15
|
};
|
|
16
|
+
exports.sortParameter = sortParameter;
|
|
16
17
|
const getSignature = (data) => {
|
|
17
|
-
const parameter = sortParameter(data);
|
|
18
|
+
const parameter = (0, exports.sortParameter)(data);
|
|
18
19
|
return crypto_1.default.createHash('md5').update(parameter).digest('hex');
|
|
19
20
|
};
|
|
20
21
|
exports.getSignature = getSignature;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "cloud189-sdk",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.7",
|
|
4
4
|
"description": "基于node.js的第三方天翼云盘SDK",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"types": "./dist/index.d.ts",
|
|
@@ -10,25 +10,25 @@
|
|
|
10
10
|
"!__tests__"
|
|
11
11
|
],
|
|
12
12
|
"scripts": {
|
|
13
|
-
"start": "node ./
|
|
14
|
-
"debug": "CLOUD189_VERBOSE=1 npm run start",
|
|
13
|
+
"start": "node ./example/app.js",
|
|
15
14
|
"build": "tsc",
|
|
16
15
|
"docs:build": "npm run build && cd docs && npm run build",
|
|
17
16
|
"docs:dev": "npm run build && cd docs && npm run dev",
|
|
18
|
-
"test": "mocha",
|
|
19
|
-
"coverage": "nyc npm run test"
|
|
17
|
+
"test": "node --security-revert=CVE-2023-46809 ./node_modules/mocha/bin/mocha",
|
|
18
|
+
"coverage": "nyc npm run test",
|
|
19
|
+
"coveralls": "nyc report --reporter=text-lcov > coverage/lcov.info"
|
|
20
20
|
},
|
|
21
21
|
"author": "wes lin",
|
|
22
22
|
"repository": {
|
|
23
23
|
"type": "git",
|
|
24
|
-
"url": "https://github.com/wes-lin/cloud189-sdk.git"
|
|
24
|
+
"url": "git+https://github.com/wes-lin/cloud189-sdk.git"
|
|
25
25
|
},
|
|
26
26
|
"keywords": [
|
|
27
27
|
"天翼网盘sdk"
|
|
28
28
|
],
|
|
29
29
|
"license": "MIT",
|
|
30
30
|
"dependencies": {
|
|
31
|
-
"
|
|
31
|
+
"@netdrive-sdk/log": "1.0.0",
|
|
32
32
|
"got": "11.8.2"
|
|
33
33
|
},
|
|
34
34
|
"engines": {
|
|
@@ -38,12 +38,15 @@
|
|
|
38
38
|
"@types/chai": "^4.3.16",
|
|
39
39
|
"@types/mocha": "^10.0.6",
|
|
40
40
|
"@types/node": "^20.12.13",
|
|
41
|
+
"@types/sinon": "^17.0.4",
|
|
41
42
|
"@typescript-eslint/parser": "^6.17.0",
|
|
42
43
|
"chai": "4.4.1",
|
|
44
|
+
"coveralls": "^3.1.1",
|
|
43
45
|
"mocha": "^10.4.0",
|
|
44
46
|
"nock": "14.0.0-beta.7",
|
|
45
47
|
"nyc": "^15.1.0",
|
|
46
48
|
"prettier": "^3.3.2",
|
|
49
|
+
"sinon": "^20.0.0",
|
|
47
50
|
"ts-node": "^10.9.2",
|
|
48
51
|
"typescript": "4.9.5"
|
|
49
52
|
}
|