cloud189-sdk 1.0.9 → 1.0.10-beta.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/dist/const.d.ts DELETED
@@ -1,15 +0,0 @@
1
- export declare const WEB_URL = "https://cloud.189.cn";
2
- export declare const AUTH_URL = "https://open.e.189.cn";
3
- export declare const API_URL = "https://api.cloud.189.cn";
4
- export declare const UPLOAD_URL = "https://upload.cloud.189.cn";
5
- export declare const AccountType = "02";
6
- export declare const AppID = "8025431004";
7
- export declare const ClientType = "10020";
8
- export declare const ReturnURL = "https://m.cloud.189.cn/zhuanti/2020/loginErrorPc/index.html";
9
- export declare const UserAgent = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.88 Safari/537.36";
10
- export declare const clientSuffix: () => {
11
- clientType: string;
12
- version: string;
13
- channelId: string;
14
- rand: number;
15
- };
package/dist/const.js DELETED
@@ -1,20 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.clientSuffix = exports.UserAgent = exports.ReturnURL = exports.ClientType = exports.AppID = exports.AccountType = exports.UPLOAD_URL = exports.API_URL = exports.AUTH_URL = exports.WEB_URL = void 0;
4
- exports.WEB_URL = 'https://cloud.189.cn';
5
- exports.AUTH_URL = 'https://open.e.189.cn';
6
- exports.API_URL = 'https://api.cloud.189.cn';
7
- exports.UPLOAD_URL = 'https://upload.cloud.189.cn';
8
- exports.AccountType = '02';
9
- exports.AppID = '8025431004';
10
- exports.ClientType = '10020';
11
- exports.ReturnURL = 'https://m.cloud.189.cn/zhuanti/2020/loginErrorPc/index.html';
12
- exports.UserAgent = 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.88 Safari/537.36';
13
- const Version = '6.2', PC = 'TELEPC', ChannelID = 'web_cloud.189.cn';
14
- const clientSuffix = () => ({
15
- clientType: PC,
16
- version: Version,
17
- channelId: ChannelID,
18
- rand: Date.now()
19
- });
20
- exports.clientSuffix = clientSuffix;
package/dist/error.d.ts DELETED
@@ -1,5 +0,0 @@
1
- export declare class InvalidRefreshTokenError extends Error {
2
- }
3
- export declare class AuthApiError extends Error {
4
- }
5
- export declare const checkError: (response: any) => void;
package/dist/error.js DELETED
@@ -1,30 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.checkError = exports.AuthApiError = exports.InvalidRefreshTokenError = void 0;
4
- class InvalidRefreshTokenError extends Error {
5
- }
6
- exports.InvalidRefreshTokenError = InvalidRefreshTokenError;
7
- class AuthApiError extends Error {
8
- }
9
- exports.AuthApiError = AuthApiError;
10
- const checkError = (response) => {
11
- let res;
12
- try {
13
- res = JSON.parse(response);
14
- }
15
- catch (e) {
16
- return;
17
- }
18
- // auth
19
- if ('result' in res && 'msg' in res) {
20
- switch (res.result) {
21
- case 0:
22
- return;
23
- case -117:
24
- throw new InvalidRefreshTokenError(res.msg);
25
- default:
26
- throw new AuthApiError(res.msg);
27
- }
28
- }
29
- };
30
- exports.checkError = checkError;
@@ -1,2 +0,0 @@
1
- import { Response } from 'got';
2
- export declare const checkErrorHook: (response: Response, _retryWithMergedOptions: any) => Response<unknown>;
@@ -1,9 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.checkErrorHook = void 0;
4
- const error_1 = require("../error");
5
- const checkErrorHook = (response, _retryWithMergedOptions) => {
6
- (0, error_1.checkError)(response.body.toString());
7
- return response;
8
- };
9
- exports.checkErrorHook = checkErrorHook;
@@ -1,3 +0,0 @@
1
- import { logHook } from './logHook';
2
- import { checkErrorHook } from './checkErrorHook';
3
- export { logHook, checkErrorHook };
@@ -1,7 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.checkErrorHook = exports.logHook = void 0;
4
- const logHook_1 = require("./logHook");
5
- Object.defineProperty(exports, "logHook", { enumerable: true, get: function () { return logHook_1.logHook; } });
6
- const checkErrorHook_1 = require("./checkErrorHook");
7
- Object.defineProperty(exports, "checkErrorHook", { enumerable: true, get: function () { return checkErrorHook_1.checkErrorHook; } });
@@ -1,2 +0,0 @@
1
- import { Response } from 'got';
2
- export declare const logHook: (response: Response, _retryWithMergedOptions: any) => Response<unknown>;
@@ -1,9 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.logHook = void 0;
4
- const log_1 = require("../log");
5
- const logHook = (response, _retryWithMergedOptions) => {
6
- log_1.logger.debug(`url: ${response.requestUrl}, response: ${response.body})}`);
7
- return response;
8
- };
9
- exports.logHook = logHook;
package/dist/index.d.ts DELETED
@@ -1,5 +0,0 @@
1
- export * from './CloudClient';
2
- export * from './CloudAuthClient';
3
- export * from './types';
4
- export * from './store';
5
- export * from './log';
package/dist/index.js DELETED
@@ -1,21 +0,0 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
- };
16
- Object.defineProperty(exports, "__esModule", { value: true });
17
- __exportStar(require("./CloudClient"), exports);
18
- __exportStar(require("./CloudAuthClient"), exports);
19
- __exportStar(require("./types"), exports);
20
- __exportStar(require("./store"), exports);
21
- __exportStar(require("./log"), exports);
package/dist/log.d.ts DELETED
@@ -1,7 +0,0 @@
1
- import { Logger } from '@netdrive-sdk/log';
2
- /**
3
- * 日志记录
4
- * @public
5
- */
6
- declare const logger: Logger;
7
- export { logger };
package/dist/log.js DELETED
@@ -1,10 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
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;
@@ -1,7 +0,0 @@
1
- import { NormalizedOptions } from 'got';
2
- export declare const signatureAccesstoken: (options: NormalizedOptions, accessToken: string) => void;
3
- export declare const signatureAppKey: (options: NormalizedOptions, appkey: string) => void;
4
- export declare const signatureUpload: (options: NormalizedOptions, rsaKey: {
5
- pubKey: string;
6
- pkId: string;
7
- }, sessionKey: string) => void;
package/dist/signature.js DELETED
@@ -1,55 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.signatureUpload = exports.signatureAppKey = exports.signatureAccesstoken = void 0;
7
- const url_1 = __importDefault(require("url"));
8
- const util_1 = require("./util");
9
- const log_1 = require("./log");
10
- const signatureAccesstoken = (options, accessToken) => {
11
- const time = String(Date.now());
12
- const { query } = url_1.default.parse(options.url.toString(), true);
13
- const signature = (0, util_1.getSignature)(Object.assign(Object.assign({}, (options.method === 'GET' ? query : options.json || options.form)), { Timestamp: time, AccessToken: accessToken }));
14
- options.headers['Sign-Type'] = '1';
15
- options.headers['Signature'] = signature;
16
- options.headers['Timestamp'] = time;
17
- options.headers['Accesstoken'] = accessToken;
18
- };
19
- exports.signatureAccesstoken = signatureAccesstoken;
20
- const signatureAppKey = (options, appkey) => {
21
- const time = String(Date.now());
22
- const { query } = url_1.default.parse(options.url.toString(), true);
23
- const signature = (0, util_1.getSignature)(Object.assign(Object.assign({}, (options.method === 'GET' ? query : options.json || options.form)), { Timestamp: time, AppKey: appkey }));
24
- options.headers['Sign-Type'] = '1';
25
- options.headers['Signature'] = signature;
26
- options.headers['Timestamp'] = time;
27
- options.headers['AppKey'] = appkey;
28
- };
29
- exports.signatureAppKey = signatureAppKey;
30
- const signatureUpload = (options, rsaKey, sessionKey) => {
31
- const time = String(Date.now());
32
- const { query } = url_1.default.parse(options.url.toString(), true);
33
- const requestID = (0, util_1.randomString)('xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx');
34
- const uuid = (0, util_1.randomString)('xxxxxxxxxxxx4xxxyxxxxxxxxxxxxxxx').slice(0, (16 + 16 * Math.random()) | 0);
35
- log_1.logger.debug(`upload query: ${JSON.stringify(query)}`);
36
- const params = (0, util_1.aesECBEncrypt)(query, uuid.substring(0, 16));
37
- const data = {
38
- SessionKey: sessionKey,
39
- Operate: 'GET',
40
- RequestURI: options.url.pathname,
41
- Date: time,
42
- params
43
- };
44
- const encryptionText = (0, util_1.rsaEncrypt)(rsaKey.pubKey, uuid, 'base64');
45
- options.headers['X-Request-Date'] = time;
46
- options.headers['X-Request-ID'] = requestID;
47
- options.headers['SessionKey'] = sessionKey;
48
- options.headers['EncryptionText'] = encryptionText;
49
- options.headers['PkId'] = rsaKey.pkId;
50
- options.headers['Signature'] = (0, util_1.hmacSha1)(data, uuid);
51
- options.url.search = '';
52
- options.url.hash = '';
53
- options.url.searchParams.set('params', params);
54
- };
55
- exports.signatureUpload = signatureUpload;
@@ -1,15 +0,0 @@
1
- import { MemoryStore } from './memstore';
2
- /**
3
- * @public
4
- */
5
- export declare class FileTokenStore extends MemoryStore {
6
- #private;
7
- filePath: string;
8
- constructor(filePath: string);
9
- private ensureTokenDirectory;
10
- update(token: {
11
- accessToken: string;
12
- refreshToken?: string;
13
- expiresIn?: number;
14
- }): Promise<void>;
15
- }
@@ -1,89 +0,0 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __importStar = (this && this.__importStar) || function (mod) {
19
- if (mod && mod.__esModule) return mod;
20
- var result = {};
21
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
- __setModuleDefault(result, mod);
23
- return result;
24
- };
25
- var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
26
- if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
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
- return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
29
- };
30
- var __importDefault = (this && this.__importDefault) || function (mod) {
31
- return (mod && mod.__esModule) ? mod : { "default": mod };
32
- };
33
- var _FileTokenStore_instances, _FileTokenStore_loadFromFile, _FileTokenStore_saveToFile;
34
- Object.defineProperty(exports, "__esModule", { value: true });
35
- exports.FileTokenStore = void 0;
36
- const fs = __importStar(require("node:fs"));
37
- const promisesFs = __importStar(require("node:fs/promises"));
38
- const path_1 = __importDefault(require("path"));
39
- const memstore_1 = require("./memstore");
40
- /**
41
- * @public
42
- */
43
- class FileTokenStore extends memstore_1.MemoryStore {
44
- constructor(filePath) {
45
- super();
46
- _FileTokenStore_instances.add(this);
47
- this.filePath = filePath;
48
- if (!filePath) {
49
- throw new Error('Unknown file for read/write token');
50
- }
51
- this.ensureTokenDirectory(filePath);
52
- const dataJson = __classPrivateFieldGet(this, _FileTokenStore_instances, "m", _FileTokenStore_loadFromFile).call(this, filePath);
53
- if (dataJson) {
54
- super.update(dataJson);
55
- }
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
- }
63
- update(token) {
64
- super.update(token);
65
- return __classPrivateFieldGet(this, _FileTokenStore_instances, "m", _FileTokenStore_saveToFile).call(this, this.filePath, this.store);
66
- }
67
- }
68
- exports.FileTokenStore = FileTokenStore;
69
- _FileTokenStore_instances = new WeakSet(), _FileTokenStore_loadFromFile = function _FileTokenStore_loadFromFile(filePath) {
70
- let data = null;
71
- if (fs.existsSync(filePath)) {
72
- data = fs.readFileSync(filePath, {
73
- encoding: 'utf-8'
74
- });
75
- }
76
- if (data) {
77
- try {
78
- return JSON.parse(data);
79
- }
80
- catch (e) {
81
- throw new Error(`Could not parse token file ${filePath}. Please ensure it is not corrupted.`);
82
- }
83
- }
84
- return null;
85
- }, _FileTokenStore_saveToFile = function _FileTokenStore_saveToFile(filePath, data) {
86
- return promisesFs.writeFile(filePath, JSON.stringify(data), {
87
- encoding: 'utf-8'
88
- });
89
- };
@@ -1,3 +0,0 @@
1
- export * from './store';
2
- export * from './memstore';
3
- export * from './file-token-store';
@@ -1,19 +0,0 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
- };
16
- Object.defineProperty(exports, "__esModule", { value: true });
17
- __exportStar(require("./store"), exports);
18
- __exportStar(require("./memstore"), exports);
19
- __exportStar(require("./file-token-store"), exports);
@@ -1,22 +0,0 @@
1
- import { Store } from './store';
2
- /**
3
- * @public
4
- */
5
- export declare class MemoryStore extends Store {
6
- store: {
7
- accessToken: string;
8
- refreshToken: string;
9
- expiresIn: number;
10
- };
11
- constructor();
12
- get(): {
13
- accessToken: string;
14
- refreshToken: string;
15
- expiresIn: number;
16
- };
17
- update(token: {
18
- accessToken: string;
19
- refreshToken?: string;
20
- expiresIn?: number;
21
- }): void;
22
- }
@@ -1,29 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.MemoryStore = void 0;
4
- const store_1 = require("./store");
5
- /**
6
- * @public
7
- */
8
- class MemoryStore extends store_1.Store {
9
- constructor() {
10
- super();
11
- this.store = {
12
- accessToken: '',
13
- refreshToken: '',
14
- expiresIn: 0
15
- };
16
- }
17
- get() {
18
- return this.store;
19
- }
20
- update(token) {
21
- var _a, _b;
22
- this.store = {
23
- accessToken: token.accessToken,
24
- refreshToken: (_a = token.refreshToken) !== null && _a !== void 0 ? _a : this.store.refreshToken,
25
- expiresIn: (_b = token.expiresIn) !== null && _b !== void 0 ? _b : this.store.expiresIn
26
- };
27
- }
28
- }
29
- exports.MemoryStore = MemoryStore;
@@ -1,20 +0,0 @@
1
- /**
2
- * @public
3
- */
4
- export declare abstract class Store {
5
- constructor();
6
- abstract get(): {
7
- accessToken: string;
8
- refreshToken: string;
9
- expiresIn: number;
10
- } | Promise<{
11
- accessToken: string;
12
- refreshToken: string;
13
- expiresIn: number;
14
- }>;
15
- abstract update(token: {
16
- accessToken: string;
17
- refreshToken?: string;
18
- expiresIn?: number;
19
- }): void | Promise<void>;
20
- }
@@ -1,10 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.Store = void 0;
4
- /**
5
- * @public
6
- */
7
- class Store {
8
- constructor() { }
9
- }
10
- exports.Store = Store;