@hw-agconnect/cloud-server 1.0.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/README.md +258 -0
- package/auth-service/agconnect-auth.json +7 -0
- package/auth-service/auth.d.ts +48 -0
- package/auth-service/auth.js +1 -0
- package/auth-service/backend/auth-backend.d.ts +11 -0
- package/auth-service/backend/auth-backend.js +1 -0
- package/auth-service/entity/auth-access-token-impl.d.ts +67 -0
- package/auth-service/entity/auth-access-token-impl.js +1 -0
- package/auth-service/entity/auth-access-token.d.ts +54 -0
- package/auth-service/entity/auth-access-token.js +1 -0
- package/auth-service/entity/provider.d.ts +17 -0
- package/auth-service/entity/provider.js +1 -0
- package/auth-service/entity/token-provider-info.d.ts +18 -0
- package/auth-service/entity/token-provider-info.js +1 -0
- package/auth-service/entity/user-import-export-result.d.ts +33 -0
- package/auth-service/entity/user-import-export-result.js +1 -0
- package/auth-service/error/agc-auth-error-message.d.ts +39 -0
- package/auth-service/error/agc-auth-error-message.js +1 -0
- package/auth-service/error/agc-auth-error.d.ts +7 -0
- package/auth-service/error/agc-auth-error.js +1 -0
- package/auth-service/index.d.ts +13 -0
- package/auth-service/index.js +1 -0
- package/auth-service/jwt/agc-auth-jwt.d.ts +17 -0
- package/auth-service/jwt/agc-auth-jwt.js +1 -0
- package/auth-service/jwt/agc-auth-jwttoken.d.ts +10 -0
- package/auth-service/jwt/agc-auth-jwttoken.js +1 -0
- package/auth-service/jwt/agc-auth-public-keys-manager.d.ts +4 -0
- package/auth-service/jwt/agc-auth-public-keys-manager.js +1 -0
- package/auth-service/jwt/agc-auth-rsa-verifier.d.ts +6 -0
- package/auth-service/jwt/agc-auth-rsa-verifier.js +1 -0
- package/auth-service/jwt/rsa-key-pair.d.ts +15 -0
- package/auth-service/jwt/rsa-key-pair.js +1 -0
- package/auth-service/params/fileParams.d.ts +6 -0
- package/auth-service/params/fileParams.js +1 -0
- package/auth-service/params/index.d.ts +7 -0
- package/auth-service/params/index.js +1 -0
- package/auth-service/params/signParams.d.ts +9 -0
- package/auth-service/params/signParams.js +1 -0
- package/auth-service/params/tokenParams.d.ts +7 -0
- package/auth-service/params/tokenParams.js +1 -0
- package/auth-service/params/uidParams.d.ts +6 -0
- package/auth-service/params/uidParams.js +1 -0
- package/auth-service/request/export-user-list-req.d.ts +13 -0
- package/auth-service/request/export-user-list-req.js +1 -0
- package/auth-service/request/export-user-req.d.ts +13 -0
- package/auth-service/request/export-user-req.js +1 -0
- package/auth-service/request/import-export-user-info.d.ts +40 -0
- package/auth-service/request/import-export-user-info.js +1 -0
- package/auth-service/request/import-user-req.d.ts +14 -0
- package/auth-service/request/import-user-req.js +1 -0
- package/auth-service/request/provider-info.d.ts +20 -0
- package/auth-service/request/provider-info.js +1 -0
- package/auth-service/request/public-key-req.d.ts +9 -0
- package/auth-service/request/public-key-req.js +1 -0
- package/auth-service/request/revoke-token-req.d.ts +13 -0
- package/auth-service/request/revoke-token-req.js +1 -0
- package/auth-service/request/verify-token-req.d.ts +13 -0
- package/auth-service/request/verify-token-req.js +1 -0
- package/auth-service/response/auth-operate-rsp.d.ts +7 -0
- package/auth-service/response/auth-operate-rsp.js +1 -0
- package/auth-service/response/export-user-list-rsp.d.ts +13 -0
- package/auth-service/response/export-user-list-rsp.js +1 -0
- package/auth-service/response/export-user-rsp.d.ts +14 -0
- package/auth-service/response/export-user-rsp.js +1 -0
- package/auth-service/response/import-success-user.d.ts +11 -0
- package/auth-service/response/import-success-user.js +1 -0
- package/auth-service/response/import-user-rsp.d.ts +11 -0
- package/auth-service/response/import-user-rsp.js +1 -0
- package/auth-service/response/publickey-rsp.d.ts +9 -0
- package/auth-service/response/publickey-rsp.js +1 -0
- package/auth-service/response/token-info.d.ts +11 -0
- package/auth-service/response/token-info.js +1 -0
- package/auth-service/response/verify-token-rsp.d.ts +14 -0
- package/auth-service/response/verify-token-rsp.js +1 -0
- package/auth-service/service/agc-auth.d.ts +4 -0
- package/auth-service/service/agc-auth.js +1 -0
- package/auth-service/service/impl/agc-auth-service-impl.d.ts +46 -0
- package/auth-service/service/impl/agc-auth-service-impl.js +1 -0
- package/auth-service/service/impl/agc-auth-service.d.ts +54 -0
- package/auth-service/service/impl/agc-auth-service.js +1 -0
- package/auth-service/utils/auth-service-api-util.d.ts +11 -0
- package/auth-service/utils/auth-service-api-util.js +1 -0
- package/auth-service/utils/key-header-util.d.ts +19 -0
- package/auth-service/utils/key-header-util.js +1 -0
- package/cloud.d.ts +24 -0
- package/cloud.js +1 -0
- package/common-server/agc-client/agc-client.d.ts +41 -0
- package/common-server/agc-client/agc-client.js +1 -0
- package/common-server/agconnect-common.json +29 -0
- package/common-server/config/cloud-gw-url-util.d.ts +7 -0
- package/common-server/config/cloud-gw-url-util.js +1 -0
- package/common-server/config/configService.d.ts +12 -0
- package/common-server/config/configService.js +1 -0
- package/common-server/credential-service/access-token.d.ts +11 -0
- package/common-server/credential-service/access-token.js +1 -0
- package/common-server/credential-service/clientid-credential.d.ts +27 -0
- package/common-server/credential-service/clientid-credential.js +1 -0
- package/common-server/credential-service/credential-parser.d.ts +23 -0
- package/common-server/credential-service/credential-parser.js +1 -0
- package/common-server/credential-service/credential-service.d.ts +41 -0
- package/common-server/credential-service/credential-service.js +1 -0
- package/common-server/credential-service/credential-type.d.ts +7 -0
- package/common-server/credential-service/credential-type.js +1 -0
- package/common-server/error/error-message.d.ts +30 -0
- package/common-server/error/error-message.js +1 -0
- package/common-server/error/error.d.ts +36 -0
- package/common-server/error/error.js +1 -0
- package/common-server/http-client/base-response.d.ts +11 -0
- package/common-server/http-client/base-response.js +1 -0
- package/common-server/http-client/common-headers.d.ts +37 -0
- package/common-server/http-client/common-headers.js +1 -0
- package/common-server/http-client/connect-ret.d.ts +12 -0
- package/common-server/http-client/connect-ret.js +1 -0
- package/common-server/http-client/http-client.d.ts +5 -0
- package/common-server/http-client/http-client.js +1 -0
- package/common-server/http-client/http-clinet-api.d.ts +66 -0
- package/common-server/http-client/http-clinet-api.js +1 -0
- package/common-server/http-client/request-constructor.d.ts +8 -0
- package/common-server/http-client/request-constructor.js +1 -0
- package/common-server/index.d.ts +19 -0
- package/common-server/index.js +1 -0
- package/common-server/service/agc-service.d.ts +14 -0
- package/common-server/service/agc-service.js +1 -0
- package/common-server/service/service-factory.d.ts +9 -0
- package/common-server/service/service-factory.js +1 -0
- package/common-server/utils/utils.d.ts +4 -0
- package/common-server/utils/utils.js +1 -0
- package/database-service/CloudDB.d.ts +13 -0
- package/database-service/CloudDB.js +1 -0
- package/database-service/CloudDBCollection.d.ts +108 -0
- package/database-service/CloudDBCollection.js +1 -0
- package/database-service/agconnect-database.json +4 -0
- package/database-service/communicator/https/HttpsCommunicator.d.ts +69 -0
- package/database-service/communicator/https/HttpsCommunicator.js +1 -0
- package/database-service/communicator/https/RequestHeader.d.ts +13 -0
- package/database-service/communicator/https/RequestHeader.js +1 -0
- package/database-service/exception/AGConnectCloudDBException.d.ts +10 -0
- package/database-service/exception/AGConnectCloudDBException.js +1 -0
- package/database-service/exception/CloudDBErrorCode.d.ts +672 -0
- package/database-service/exception/CloudDBErrorCode.js +1 -0
- package/database-service/exception/ErrorCodeMessage.d.ts +1 -0
- package/database-service/exception/ErrorCodeMessage.js +1 -0
- package/database-service/index.d.ts +14 -0
- package/database-service/index.js +1 -0
- package/database-service/model/DatabaseConfig.d.ts +7 -0
- package/database-service/model/DatabaseConfig.js +1 -0
- package/database-service/model/index.d.ts +4 -0
- package/database-service/model/index.js +1 -0
- package/database-service/query/CloudDBZoneConfig.d.ts +23 -0
- package/database-service/query/CloudDBZoneConfig.js +1 -0
- package/database-service/query/CloudDBZoneObjectOperator.d.ts +39 -0
- package/database-service/query/CloudDBZoneObjectOperator.js +1 -0
- package/database-service/query/CloudDBZoneObjectOperatorConstraint.d.ts +127 -0
- package/database-service/query/CloudDBZoneObjectOperatorConstraint.js +1 -0
- package/database-service/query/CloudDBZoneQuery.d.ts +188 -0
- package/database-service/query/CloudDBZoneQuery.js +1 -0
- package/database-service/query/CloudDBZoneSnapshot.d.ts +16 -0
- package/database-service/query/CloudDBZoneSnapshot.js +1 -0
- package/database-service/request/CloudDBZoneGenericObject.d.ts +58 -0
- package/database-service/request/CloudDBZoneGenericObject.js +1 -0
- package/database-service/services/AGConnectCloudDB.d.ts +63 -0
- package/database-service/services/AGConnectCloudDB.js +1 -0
- package/database-service/services/CloudDBService.d.ts +75 -0
- package/database-service/services/CloudDBService.js +1 -0
- package/database-service/services/CloudDBZone.d.ts +254 -0
- package/database-service/services/CloudDBZone.js +1 -0
- package/database-service/services/Transaction.d.ts +73 -0
- package/database-service/services/Transaction.js +1 -0
- package/database-service/utils/AggregareType.d.ts +10 -0
- package/database-service/utils/AggregareType.js +1 -0
- package/database-service/utils/CloudDBSdkUtils.d.ts +30 -0
- package/database-service/utils/CloudDBSdkUtils.js +1 -0
- package/database-service/utils/ConditionType.d.ts +26 -0
- package/database-service/utils/ConditionType.js +1 -0
- package/database-service/utils/ConditionValidate.d.ts +40 -0
- package/database-service/utils/ConditionValidate.js +1 -0
- package/database-service/utils/Constant.d.ts +9 -0
- package/database-service/utils/Constant.js +1 -0
- package/database-service/utils/DataModelHelper.d.ts +28 -0
- package/database-service/utils/DataModelHelper.js +1 -0
- package/database-service/utils/FieldType.d.ts +18 -0
- package/database-service/utils/FieldType.js +1 -0
- package/database-service/utils/SchemaUtils.d.ts +24 -0
- package/database-service/utils/SchemaUtils.js +1 -0
- package/database-service/utils/Utils.d.ts +134 -0
- package/database-service/utils/Utils.js +1 -0
- package/function-service/cloudFunction.d.ts +10 -0
- package/function-service/cloudFunction.js +1 -0
- package/function-service/exception/AGCFunctionException.d.ts +7 -0
- package/function-service/exception/AGCFunctionException.js +1 -0
- package/function-service/exception/FunctionErrorCode.d.ts +26 -0
- package/function-service/exception/FunctionErrorCode.js +1 -0
- package/function-service/index.d.ts +8 -0
- package/function-service/index.js +1 -0
- package/function-service/params/functionParams.d.ts +9 -0
- package/function-service/params/functionParams.js +1 -0
- package/function-service/params/index.d.ts +4 -0
- package/function-service/params/index.js +1 -0
- package/function-service/server/AGCFunction.d.ts +20 -0
- package/function-service/server/AGCFunction.js +1 -0
- package/function-service/server/FunctionCallable.d.ts +40 -0
- package/function-service/server/FunctionCallable.js +1 -0
- package/function-service/server/FunctionResult.d.ts +8 -0
- package/function-service/server/FunctionResult.js +1 -0
- package/function-service/server/request/RequestHeaders.d.ts +10 -0
- package/function-service/server/request/RequestHeaders.js +1 -0
- package/function-service/util/HashUtil.d.ts +10 -0
- package/function-service/util/HashUtil.js +1 -0
- package/index.d.ts +7 -0
- package/index.js +1 -0
- package/package.json +58 -0
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Huawei Technologies Co., Ltd. 2023 All rights reserved.
|
|
3
|
+
*/
|
|
4
|
+
import { RSAKeyPair } from "../../jwt/rsa-key-pair";
|
|
5
|
+
import { UserImportExportResult } from "../../entity/user-import-export-result";
|
|
6
|
+
import { AGCAuthJwtToken } from "../../jwt/agc-auth-jwttoken";
|
|
7
|
+
import { AuthAccessToken } from "../../entity/auth-access-token";
|
|
8
|
+
export interface AGCAuthService {
|
|
9
|
+
/**
|
|
10
|
+
* according payload and privatekey generate self account JWT
|
|
11
|
+
*
|
|
12
|
+
* @param uid self account user id unique
|
|
13
|
+
* @param displayName user display name
|
|
14
|
+
* @param photoUrl user header photo url
|
|
15
|
+
* @param privateKey private key
|
|
16
|
+
* @return AGCAuthJwtToken includ jwt and expire time
|
|
17
|
+
*/
|
|
18
|
+
sign(uid: string, displayName: string, photoUrl: string, privateKey: string): AGCAuthJwtToken;
|
|
19
|
+
/**
|
|
20
|
+
* generate rsa pair key
|
|
21
|
+
* @return rsa pair key
|
|
22
|
+
*/
|
|
23
|
+
generateKey(): RSAKeyPair;
|
|
24
|
+
/**
|
|
25
|
+
* import user from firebase or agc
|
|
26
|
+
* @param filePath import file path
|
|
27
|
+
* @return import result
|
|
28
|
+
*/
|
|
29
|
+
importUserData(filePath: string): Promise<UserImportExportResult>;
|
|
30
|
+
/**
|
|
31
|
+
* export users of agc project
|
|
32
|
+
* @param filePath export user data to server path
|
|
33
|
+
* @return export result
|
|
34
|
+
*/
|
|
35
|
+
exportUserData(filePath: string): Promise<UserImportExportResult>;
|
|
36
|
+
/**
|
|
37
|
+
* revoke all refresh tokens for uid
|
|
38
|
+
* @param uid The user id for which tokens are revoked
|
|
39
|
+
*/
|
|
40
|
+
revokeRefreshTokens(uid: string): Promise<void>;
|
|
41
|
+
/**
|
|
42
|
+
* verifies auth access token
|
|
43
|
+
* <p>This method to verify that the token is valid,ensure that the token is correctly signed,
|
|
44
|
+
* has not expired
|
|
45
|
+
*
|
|
46
|
+
* <p> If {@code checkRevoked} is set to true, this method will check the access token
|
|
47
|
+
* has been revoke
|
|
48
|
+
*
|
|
49
|
+
* @param accessToken auth access token
|
|
50
|
+
* @param checkRevoked whether the token has expired
|
|
51
|
+
* @return user login info
|
|
52
|
+
*/
|
|
53
|
+
verifyAccessToken(accessToken: string, checkRevoked: boolean): Promise<AuthAccessToken>;
|
|
54
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Huawei Technologies Co., Ltd. 2023 All rights reserved.
|
|
3
|
+
*/
|
|
4
|
+
import { AGCClient } from "../../common-server";
|
|
5
|
+
export declare class AuthServiceApiUtil {
|
|
6
|
+
private static JWT_FIELD_SIZE;
|
|
7
|
+
static checkCredential(client: AGCClient): boolean;
|
|
8
|
+
static checkReadFilePath(filePath: string, client: AGCClient): boolean;
|
|
9
|
+
static checkWriteFilePath(filePath: string, client: AGCClient): boolean;
|
|
10
|
+
static checkAccessToken(accessToken: string, client: AGCClient): void;
|
|
11
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";var __importDefault=this&&this.__importDefault||function(r){return r&&r.__esModule?r:{default:r}};Object.defineProperty(exports,"__esModule",{value:!0}),exports.AuthServiceApiUtil=void 0;var agc_auth_error_1=require("../error/agc-auth-error"),agc_auth_error_message_1=require("../error/agc-auth-error-message"),fs_1=__importDefault(require("fs")),path_1=__importDefault(require("path")),AuthServiceApiUtil=function(){function r(){}return r.checkCredential=function(r){if(!r||!r.getCredential()||!r.getCredential().getProjectId())throw new agc_auth_error_1.AGCAuthError(agc_auth_error_message_1.AuthErrorCode.CLIENT_INITIALIZE_FAILED,"");if(!r.getCredential().getRegion())throw new agc_auth_error_1.AGCAuthError(agc_auth_error_message_1.AuthErrorCode.PROJECT_DO_NOT_SET_REGION,r.getName());return!0},r.checkReadFilePath=function(r,e){if(!r)throw new agc_auth_error_1.AGCAuthError(agc_auth_error_message_1.AuthErrorCode.INVALID_IMPORT_USER_FILE,e.getName());if(!fs_1.default.existsSync(r))throw new agc_auth_error_1.AGCAuthError(agc_auth_error_message_1.AuthErrorCode.INVALID_IMPORT_USER_FILE,e.getName());if(!fs_1.default.statSync(r).isFile())throw new agc_auth_error_1.AGCAuthError(agc_auth_error_message_1.AuthErrorCode.INVALID_IMPORT_USER_FILE,e.getName());try{fs_1.default.accessSync(r,fs_1.default.constants.R_OK)}catch(r){throw new agc_auth_error_1.AGCAuthError(agc_auth_error_message_1.AuthErrorCode.INVALID_ACCESS_IMPORT_USER_FILE,e.getName())}return!0},r.checkWriteFilePath=function(r,e){if(!r)throw new agc_auth_error_1.AGCAuthError(agc_auth_error_message_1.AuthErrorCode.EXPORT_USER_DATA_FILEPATH_IS_INVALID,e.getName());if(fs_1.default.existsSync(r)){if(!fs_1.default.statSync(r).isFile())throw new agc_auth_error_1.AGCAuthError(agc_auth_error_message_1.AuthErrorCode.EXPORT_USER_DATA_FILEPATH_IS_INVALID,e.getName());try{fs_1.default.accessSync(r,fs_1.default.constants.W_OK)}catch(r){throw new agc_auth_error_1.AGCAuthError(agc_auth_error_message_1.AuthErrorCode.INVALID_ACCESS_EXPORT_USER_FILE,e.getName())}}else{var _=path_1.default.join(r,"..");if(!fs_1.default.existsSync(_))throw new agc_auth_error_1.AGCAuthError(agc_auth_error_message_1.AuthErrorCode.EXPORT_USER_FILE_DIR_NOT_EXIST,e.getName())}return!0},r.checkAccessToken=function(e,_){if(!e)throw new agc_auth_error_1.AGCAuthError(agc_auth_error_message_1.AuthErrorCode.VERIFY_ACCESS_TOKEN_ACCESS_TOKEN_IS_NULL,_.getName());if(r.JWT_FIELD_SIZE!==e.split(".").length)throw new agc_auth_error_1.AGCAuthError(agc_auth_error_message_1.AuthErrorCode.ACCESS_TOKEN_INVALID_FORMAT,_.getName())},r.JWT_FIELD_SIZE=3,r}();exports.AuthServiceApiUtil=AuthServiceApiUtil;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Huawei Technologies Co., Ltd. 2023 All rights reserved.
|
|
3
|
+
*/
|
|
4
|
+
export declare class KeyHeaderUtil {
|
|
5
|
+
private static PUBLIC_KEY_BEGIN;
|
|
6
|
+
private static PUBLIC_KEY_END;
|
|
7
|
+
private static PRIVATE_KEY_BEGIN;
|
|
8
|
+
private static PRIVATE_KEY_END;
|
|
9
|
+
private static CERTIFICATE_BEGIN;
|
|
10
|
+
private static CERTIFICATE_END;
|
|
11
|
+
private static WRAP;
|
|
12
|
+
private static WRAP_EXP;
|
|
13
|
+
static addPublicKeyHeaderAndEnd(publicKey: string): string;
|
|
14
|
+
static addPrivateKeyHeaderAndEnd(privateKey: string): string;
|
|
15
|
+
static removePublicKeyHeaderAndEnd(publicKey: string): string;
|
|
16
|
+
static removePrivateKeyHeaderAndEnd(privateKey: string): string;
|
|
17
|
+
static decodePublicKey(publicKey: string): string;
|
|
18
|
+
static removeWrap(str: string): string;
|
|
19
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.KeyHeaderUtil=void 0;var KeyHeaderUtil=function(){function E(){}return E.addPublicKeyHeaderAndEnd=function(e){if(e){var r=e;return r.startsWith(E.PUBLIC_KEY_BEGIN)||(r=E.PUBLIC_KEY_BEGIN+E.WRAP+r),r.endsWith(E.PUBLIC_KEY_END)||(r=r+E.WRAP+E.PUBLIC_KEY_END),r}return e},E.addPrivateKeyHeaderAndEnd=function(e){if(e){var r=e;return r.startsWith(E.PRIVATE_KEY_BEGIN)||(r=E.PRIVATE_KEY_BEGIN+E.WRAP+r),r.endsWith(E.PRIVATE_KEY_END)||(r=r+E.WRAP+E.PRIVATE_KEY_END),r}return e},E.removePublicKeyHeaderAndEnd=function(e){if(e){var r=e;return r=r.replace(E.PUBLIC_KEY_BEGIN,"").replace(E.PUBLIC_KEY_END,"")}return e},E.removePrivateKeyHeaderAndEnd=function(e){if(e){var r=e;return r=r.replace(E.PRIVATE_KEY_BEGIN,"").replace(E.PRIVATE_KEY_END,"")}return e},E.decodePublicKey=function(e){return e?e.replace(E.CERTIFICATE_BEGIN,E.PUBLIC_KEY_BEGIN).replace(E.CERTIFICATE_END,E.PUBLIC_KEY_END):e},E.removeWrap=function(e){return e?e.replace(E.WRAP_EXP,""):e},E.PUBLIC_KEY_BEGIN="-----BEGIN PUBLIC KEY-----",E.PUBLIC_KEY_END="-----END PUBLIC KEY-----",E.PRIVATE_KEY_BEGIN="-----BEGIN PRIVATE KEY-----",E.PRIVATE_KEY_END="-----END PRIVATE KEY-----",E.CERTIFICATE_BEGIN="-----BEGIN CERTIFICATE-----",E.CERTIFICATE_END="-----END CERTIFICATE-----",E.WRAP="\n",E.WRAP_EXP=/\n/g,E}();exports.KeyHeaderUtil=KeyHeaderUtil;
|
package/cloud.d.ts
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Huawei Technologies Co., Ltd. 2023 All rights reserved.
|
|
3
|
+
*/
|
|
4
|
+
import { AGCError } from './common-server';
|
|
5
|
+
import { Auth } from "./auth-service/";
|
|
6
|
+
import { CloudFunction } from "./function-service";
|
|
7
|
+
import { CloudDB, DatabaseConfig } from './database-service/';
|
|
8
|
+
declare class Cloud {
|
|
9
|
+
private readonly name;
|
|
10
|
+
constructor(path?: string, name?: string, region?: string);
|
|
11
|
+
private getAGCClientInstance;
|
|
12
|
+
auth(): Auth;
|
|
13
|
+
database(config: DatabaseConfig): CloudDB;
|
|
14
|
+
function(): CloudFunction;
|
|
15
|
+
createInstance(path?: string, name?: string, region?: string): Cloud;
|
|
16
|
+
}
|
|
17
|
+
declare enum Region {
|
|
18
|
+
REGION_CN = "CN",
|
|
19
|
+
REGION_RU = "RU",
|
|
20
|
+
REGION_SG = "SG",
|
|
21
|
+
REGION_DE = "DE"
|
|
22
|
+
}
|
|
23
|
+
declare const cloud: Cloud;
|
|
24
|
+
export { cloud, Region, AGCError };
|
package/cloud.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.AGCError=exports.Region=exports.cloud=void 0;var common_server_1=require("./common-server");Object.defineProperty(exports,"AGCError",{enumerable:!0,get:function(){return common_server_1.AGCError}});var Region,auth_service_1=require("./auth-service/"),function_service_1=require("./function-service"),database_service_1=require("./database-service/"),Cloud=function(){function e(e,r,t){var n;void 0===r&&(r=common_server_1.AGCClient.DEFAULT_INSTANCE_NAME),this.name=r,e&&(n=common_server_1.CredentialParser.toCredential(e));try{common_server_1.AGCClient.getInstance(r)}catch(o){if(!process.env.AGC_CONFIG&&!e&&!process.env.PROJECT_CREDENTIAL)return;common_server_1.AGCClient.initialize(n,r,t)}}return e.prototype.getAGCClientInstance=function(){try{return common_server_1.AGCClient.getInstance(this.name)}catch(e){throw new Error("Please create instance with path or set environment variable AGC_CONFIG")}},e.prototype.auth=function(){return this.getAGCClientInstance(),new auth_service_1.Auth(this.name)},e.prototype.database=function(e){var r=this.getAGCClientInstance();return new database_service_1.CloudDB(r,e)},e.prototype.function=function(){return this.getAGCClientInstance(),new function_service_1.CloudFunction(this.name)},e.prototype.createInstance=function(r,t,n){return void 0===t&&(t=common_server_1.AGCClient.DEFAULT_INSTANCE_NAME),new e(r,t,n)},e}();!function(e){e.REGION_CN="CN",e.REGION_RU="RU",e.REGION_SG="SG",e.REGION_DE="DE"}(Region||(Region={})),exports.Region=Region;var cloud=new Cloud;exports.cloud=cloud;
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Huawei Technologies Co., Ltd. 2023 All rights reserved.
|
|
3
|
+
*/
|
|
4
|
+
import { CredentialService } from '../credential-service/credential-service';
|
|
5
|
+
export declare class AGCClient {
|
|
6
|
+
static INSTANCES: Map<string, AGCClient>;
|
|
7
|
+
static DEFAULT_INSTANCE_NAME: string;
|
|
8
|
+
private name;
|
|
9
|
+
private credential;
|
|
10
|
+
private constructor();
|
|
11
|
+
getName(): string;
|
|
12
|
+
getCredential(): CredentialService;
|
|
13
|
+
/**
|
|
14
|
+
* Initializes the AGCClient with the provided credential, name, and region.
|
|
15
|
+
* If no credential is provided, the default credential service will be used.
|
|
16
|
+
* If no name is provided, a default name will be used.
|
|
17
|
+
* If no region is provided, a default region will be used.
|
|
18
|
+
* @param credential - The credential service to be used for authentication.
|
|
19
|
+
* @param name - The name of the AGCClient instance.
|
|
20
|
+
* @param region - The region associated with the AGCClient instance.
|
|
21
|
+
* @returns None.
|
|
22
|
+
* @throws {AGCError} - If an invalid region is provided or if the AGCClient instance already exists with the same name.
|
|
23
|
+
*/
|
|
24
|
+
static initialize(credential?: CredentialService, name?: string, region?: string): void;
|
|
25
|
+
/**
|
|
26
|
+
* Retrieves the instance of AGCClient with the specified name.
|
|
27
|
+
* If an instance with the given name doesn't exist, an AGCError is thrown.
|
|
28
|
+
* @param name - The name of the AGCClient instance to retrieve.
|
|
29
|
+
* @returns {AGCClient} - The AGCClient instance with the specified name.
|
|
30
|
+
* @throws {AGCError} - If an instance with the given name doesn't exist.
|
|
31
|
+
*/
|
|
32
|
+
static getInstance(name?: string): AGCClient;
|
|
33
|
+
/**
|
|
34
|
+
* Retrieve the default instance of AGCClient. If the default instance is not initialized, initialize it.
|
|
35
|
+
* @returns The default AGCClient instance.
|
|
36
|
+
* @throws {AGCError} - if AGC_CONFIG environment variables is not set.
|
|
37
|
+
*/
|
|
38
|
+
static getDefaultInstance(): AGCClient;
|
|
39
|
+
private static overrideRegion;
|
|
40
|
+
private static judgeEnv;
|
|
41
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";var __importDefault=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(exports,"__esModule",{value:!0}),exports.AGCClient=void 0;var EnvType,Region,error_1=require("../error/error"),error_message_1=require("../error/error-message"),credential_parser_1=require("../credential-service/credential-parser"),configService_1=require("../config/configService"),path_1=__importDefault(require("path"));configService_1.ConfigService.loadCustomConfig(),configService_1.ConfigService.initialLoadServiceConfig("COMMON",path_1.default.join(__dirname,"../agconnect-common.json")),configService_1.ConfigService.startPollingTask(),function(e){e[e.BROWSER=0]="BROWSER",e[e.NODE_JS=1]="NODE_JS",e[e.UNKNOWN=2]="UNKNOWN"}(EnvType||(EnvType={})),function(e){e.REGION_CN="CN",e.REGION_RU="RU",e.REGION_SG="SG",e.REGION_DE="DE"}(Region||(Region={}));var envValue=function(){return"[object process]"===Object.prototype.toString.call(process)?EnvType.NODE_JS:"object"==typeof globalThis&&globalThis.globalThis===globalThis?EnvType.BROWSER:EnvType.UNKNOWN},AGCClient=function(){function e(e,r){this.name=e,this.credential=r}return e.prototype.getName=function(){return this.name},e.prototype.getCredential=function(){return this.credential},e.initialize=function(r,n,t){if(e.judgeEnv(),t&&t!==Region.REGION_CN&&t!==Region.REGION_DE&&t!==Region.REGION_RU&&t!==Region.REGION_SG)throw new error_1.AGCError(error_message_1.ErrorCodeConstant.INVALID_REGION);if(null!=n&&null!=n||(n=e.DEFAULT_INSTANCE_NAME),e.INSTANCES.has(n))throw new error_1.AGCError(error_message_1.ErrorCodeConstant.AGC_CLIENT_EXIST);var o=r;if(void 0===o)o=credential_parser_1.CredentialParser.toCredential();else if(!o)throw new error_1.AGCError(error_message_1.ErrorCodeConstant.AGC_CLIENT_CREDENTIAL);e.INSTANCES.set(n,new e(n,o)),t&&e.overrideRegion(n,t)},e.getInstance=function(r){if(void 0===r&&(r=e.DEFAULT_INSTANCE_NAME),!e.INSTANCES.has(r))throw new error_1.AGCError(error_message_1.ErrorCodeConstant.AGC_CLIENT_NOT_EXIST);return e.INSTANCES.get(r)},e.getDefaultInstance=function(){try{return e.getInstance()}catch(r){return e.initialize(),e.getInstance()}},e.overrideRegion=function(r,n){e.getInstance(r).getCredential().setRegion(n)},e.judgeEnv=function(){switch(envValue()){case EnvType.NODE_JS:return;case EnvType.BROWSER:case EnvType.UNKNOWN:default:throw new error_1.AGCError(error_message_1.ErrorCodeConstant.ENV_NOT_NODEJS)}},e.INSTANCES=new Map,e.DEFAULT_INSTANCE_NAME="default",e}();exports.AGCClient=AGCClient;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
{
|
|
2
|
+
"sdk_name": "cloud-server/common-server",
|
|
3
|
+
"sdk_version": "1.0.0",
|
|
4
|
+
"project_cloudgw_url": [
|
|
5
|
+
{
|
|
6
|
+
"region": "CN",
|
|
7
|
+
"url": "https://connect-api.cloud.huawei.com/",
|
|
8
|
+
"backupUrl": "https://connect-api.cloud.huawei.com.cn/"
|
|
9
|
+
},
|
|
10
|
+
{
|
|
11
|
+
"region": "RU",
|
|
12
|
+
"url": "https://connect-api-drru.cloud.huawei.com/",
|
|
13
|
+
"backupUrl": "https://connect-api-drru.cloud.huawei.com.cn/"
|
|
14
|
+
},
|
|
15
|
+
{
|
|
16
|
+
"region": "SG",
|
|
17
|
+
"url": "https://connect-api-dra.cloud.huawei.com/",
|
|
18
|
+
"backupUrl": "https://connect-api-dra.cloud.huawei.com.cn/"
|
|
19
|
+
},
|
|
20
|
+
{
|
|
21
|
+
"region": "DE",
|
|
22
|
+
"url": "https://connect-api-dre.cloud.huawei.com/",
|
|
23
|
+
"backupUrl": "https://connect-api-dre.cloud.huawei.com.cn/"
|
|
24
|
+
}
|
|
25
|
+
],
|
|
26
|
+
"team_cloudgw_url": "https://agc-api.cloud.huawei.com/",
|
|
27
|
+
"team_cloudgw_url_backup": "https://agc-api.cloud.huawei.com/",
|
|
28
|
+
"client_token_path": "api/oauth2/v1/token"
|
|
29
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export declare class CloudGwUrlUtil {
|
|
2
|
+
private static PROJECT_CLOUDGW_URL;
|
|
3
|
+
private static TEAM_CLOUDGW_URL;
|
|
4
|
+
private static TEAM_CLOUDGW_BACK_URL;
|
|
5
|
+
static checkUseBackUrl(err: any, enableBackurl?: boolean): boolean;
|
|
6
|
+
static getCloudgwUrlByRegion(region?: string, useBackup?: boolean): string;
|
|
7
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.CloudGwUrlUtil=void 0;var configService_1=require("./configService"),CloudGwUrlUtil=function(){function e(){}return e.checkUseBackUrl=function(e,r){return!!(r&&e.message&&(e.message.includes("ENOTFOUND")||e.message.includes("ECONNREFUSED")||e.message.includes("EHOSTUNREACH")))},e.getCloudgwUrlByRegion=function(r,i){if(r){var c=configService_1.ConfigService.getService("COMMON").getConfigValue(e.PROJECT_CLOUDGW_URL,[]);if(Array.isArray(c))for(var o=0;o<c.length;o++)if(c[o].region===r)return i?c[o].backupUrl:c[o].url}return i?configService_1.ConfigService.getService("COMMON").getConfigValue(e.TEAM_CLOUDGW_BACK_URL):configService_1.ConfigService.getService("COMMON").getConfigValue(e.TEAM_CLOUDGW_URL)},e.PROJECT_CLOUDGW_URL="project_cloudgw_url",e.TEAM_CLOUDGW_URL="team_cloudgw_url",e.TEAM_CLOUDGW_BACK_URL="team_cloudgw_back_url",e}();exports.CloudGwUrlUtil=CloudGwUrlUtil;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export declare class ConfigService {
|
|
2
|
+
static CONFIG_REGEX: string;
|
|
3
|
+
static POLLING_INTERVAL_IN_MILLISECONDS: number;
|
|
4
|
+
static priorInstance: ConfigService;
|
|
5
|
+
static INSTANCES: Map<string, ConfigService>;
|
|
6
|
+
private configMap;
|
|
7
|
+
static initialLoadServiceConfig(serviceName: string, configFilePath: string): void;
|
|
8
|
+
static loadCustomConfig(): void;
|
|
9
|
+
static getService(serviceName: string): ConfigService;
|
|
10
|
+
static startPollingTask(): void;
|
|
11
|
+
getConfigValue(key: string, defaultValue?: any): any;
|
|
12
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";var __values=this&&this.__values||function(r){var e="function"==typeof Symbol&&Symbol.iterator,t=e&&r[e],n=0;if(t)return t.call(r);if(r&&"number"==typeof r.length)return{next:function(){return r&&n>=r.length&&(r=void 0),{value:r&&r[n++],done:!r}}};throw new TypeError(e?"Object is not iterable.":"Symbol.iterator is not defined.")},__importDefault=this&&this.__importDefault||function(r){return r&&r.__esModule?r:{default:r}};Object.defineProperty(exports,"__esModule",{value:!0}),exports.ConfigService=void 0;var utils_1=require("../utils/utils"),error_1=require("../error/error"),error_message_1=require("../error/error-message"),fs_1=__importDefault(require("fs")),path_1=__importDefault(require("path")),ConfigService=function(){function r(){this.configMap=new Map}return r.initialLoadServiceConfig=function(e,t){var n,o;if((0,utils_1.voilidatePath)(t),!r.INSTANCES.has(e)){var a=new r;try{var i=fs_1.default.readFileSync(t,"utf8"),s=JSON.parse(i);try{for(var f=__values(Object.keys(s)),c=f.next();!c.done;c=f.next()){var l=c.value;a.configMap.set(l,s[l])}}catch(r){n={error:r}}finally{try{c&&!c.done&&(o=f.return)&&o.call(f)}finally{if(n)throw n.error}}r.INSTANCES.set(e,a)}catch(r){throw new error_1.AGCError(error_message_1.ErrorCodeConstant.LOAD_SERVICE_CONFIG_ERROR)}}},r.loadCustomConfig=function(){var e,t;try{var n=process.cwd(),o=fs_1.default.readdirSync(n);r.priorInstance.configMap.clear();for(var a=0;a<o.length;a++){var i=path_1.default.join(n,o[a]);if(fs_1.default.statSync(i).isFile()&&o[a].match(r.CONFIG_REGEX)){var s=fs_1.default.readFileSync(i,"utf8"),f=JSON.parse(s);try{for(var c=(e=void 0,__values(Object.keys(f))),l=c.next();!l.done;l=c.next()){var u=l.value;r.priorInstance.configMap.set(u,f[u])}}catch(r){e={error:r}}finally{try{l&&!l.done&&(t=c.return)&&t.call(c)}finally{if(e)throw e.error}}}}}catch(r){}},r.getService=function(e){return r.INSTANCES.has(e)?r.INSTANCES.get(e):r.priorInstance},r.startPollingTask=function(){setInterval((function(){r.loadCustomConfig()}),r.POLLING_INTERVAL_IN_MILLISECONDS)},r.prototype.getConfigValue=function(e,t){return r.priorInstance.configMap.has(e)?r.priorInstance.configMap.get(e):this.configMap.has(e)?this.configMap.get(e):t},r.CONFIG_REGEX="agconnect-[\\w]+.json",r.POLLING_INTERVAL_IN_MILLISECONDS=3e5,r.priorInstance=new r,r.INSTANCES=new Map,r}();exports.ConfigService=ConfigService;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Huawei Technologies Co., Ltd. 2023 All rights reserved.
|
|
3
|
+
*/
|
|
4
|
+
export declare class AccessToken {
|
|
5
|
+
private token;
|
|
6
|
+
private expirationTime;
|
|
7
|
+
private static TWO_MINUTES_EARLY;
|
|
8
|
+
constructor(token: string, expirationTime: number);
|
|
9
|
+
getToken(): string;
|
|
10
|
+
isValid(): boolean;
|
|
11
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.AccessToken=void 0;var AccessToken=function(){function e(e,t){this.token=e,this.expirationTime=t}return e.prototype.getToken=function(){return this.token},e.prototype.isValid=function(){var t=(new Date).getTime(),n=this.expirationTime-e.TWO_MINUTES_EARLY;return null!=this.token&&t<=n},e.TWO_MINUTES_EARLY=12e4,e}();exports.AccessToken=AccessToken;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Huawei Technologies Co., Ltd. 2023 All rights reserved.
|
|
3
|
+
*/
|
|
4
|
+
import { CredentialService } from './credential-service';
|
|
5
|
+
export declare class ClientIdCredential implements CredentialService {
|
|
6
|
+
private projectId;
|
|
7
|
+
private region;
|
|
8
|
+
private developerId;
|
|
9
|
+
private type;
|
|
10
|
+
private clientId;
|
|
11
|
+
private clientSecret;
|
|
12
|
+
private configurationVersion;
|
|
13
|
+
private accessToken;
|
|
14
|
+
private static CLIENT_TOKEN_PATH;
|
|
15
|
+
constructor(projectId: string, region: string, developerId: string, type: string, clientId: string, clientSecret: string, configurationVersion: string);
|
|
16
|
+
getProjectId(): string;
|
|
17
|
+
getRegion(): string;
|
|
18
|
+
getDeveloperId(): string;
|
|
19
|
+
getType(): string;
|
|
20
|
+
getClientId(): string;
|
|
21
|
+
getClientSecret(): string;
|
|
22
|
+
getConfigurationVersion(): string;
|
|
23
|
+
setRegion(region: string): void;
|
|
24
|
+
getAccessToken(): Promise<string>;
|
|
25
|
+
refreshAccessToken(): Promise<string>;
|
|
26
|
+
private getGWTokenUrl;
|
|
27
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";var __awaiter=this&&this.__awaiter||function(e,t,r,n){return new(r||(r=Promise))((function(i,o){function c(e){try{u(n.next(e))}catch(e){o(e)}}function s(e){try{u(n.throw(e))}catch(e){o(e)}}function u(e){var t;e.done?i(e.value):(t=e.value,t instanceof r?t:new r((function(e){e(t)}))).then(c,s)}u((n=n.apply(e,t||[])).next())}))},__generator=this&&this.__generator||function(e,t){var r,n,i,o,c={label:0,sent:function(){if(1&i[0])throw i[1];return i[1]},trys:[],ops:[]};return o={next:s(0),throw:s(1),return:s(2)},"function"==typeof Symbol&&(o[Symbol.iterator]=function(){return this}),o;function s(s){return function(u){return function(s){if(r)throw new TypeError("Generator is already executing.");for(;o&&(o=0,s[0]&&(c=0)),c;)try{if(r=1,n&&(i=2&s[0]?n.return:s[0]?n.throw||((i=n.return)&&i.call(n),0):n.next)&&!(i=i.call(n,s[1])).done)return i;switch(n=0,i&&(s=[2&s[0],i.value]),s[0]){case 0:case 1:i=s;break;case 4:return c.label++,{value:s[1],done:!1};case 5:c.label++,n=s[1],s=[0];continue;case 7:s=c.ops.pop(),c.trys.pop();continue;default:if(!(i=c.trys,(i=i.length>0&&i[i.length-1])||6!==s[0]&&2!==s[0])){c=0;continue}if(3===s[0]&&(!i||s[1]>i[0]&&s[1]<i[3])){c.label=s[1];break}if(6===s[0]&&c.label<i[1]){c.label=i[1],i=s;break}if(i&&c.label<i[2]){c.label=i[2],c.ops.push(s);break}i[2]&&c.ops.pop(),c.trys.pop();continue}s=t.call(e,c)}catch(e){s=[6,e],n=0}finally{r=i=0}if(5&s[0])throw s[1];return{value:s[0]?s[1]:void 0,done:!0}}([s,u])}}};Object.defineProperty(exports,"__esModule",{value:!0}),exports.ClientIdCredential=void 0;var http_client_1=require("../http-client/http-client"),access_token_1=require("./access-token"),error_1=require("../error/error"),cloud_gw_url_util_1=require("../config/cloud-gw-url-util"),configService_1=require("../config/configService"),error_message_1=require("../error/error-message"),ClientIdCredential=function(){function e(e,t,r,n,i,o,c){this.projectId="",this.region="",this.developerId="",this.type="",this.clientId="",this.clientSecret="",this.configurationVersion="",this.accessToken=null,this.projectId=e,this.region=t,this.developerId=r,this.type=n,this.clientId=i,this.clientSecret=o,this.configurationVersion=c}return e.prototype.getProjectId=function(){return this.projectId},e.prototype.getRegion=function(){return this.region},e.prototype.getDeveloperId=function(){return this.developerId},e.prototype.getType=function(){return this.type},e.prototype.getClientId=function(){return this.clientId},e.prototype.getClientSecret=function(){return this.clientSecret},e.prototype.getConfigurationVersion=function(){return this.configurationVersion},e.prototype.setRegion=function(e){this.region=e},e.prototype.getAccessToken=function(){return __awaiter(this,void 0,void 0,(function(){return __generator(this,(function(e){return null!=this.accessToken&&this.accessToken.isValid()?[2,Promise.resolve(this.accessToken.getToken())]:[2,this.refreshAccessToken()]}))}))},e.prototype.refreshAccessToken=function(){return __awaiter(this,void 0,void 0,(function(){var e,t,r,n,i,o,c=this;return __generator(this,(function(s){switch(s.label){case 0:return e=(0,http_client_1.getHttpClient)(),t={grant_type:"client_credentials",client_id:this.clientId,client_secret:this.clientSecret},r={},n={algorithm_type:1},i="",o=0,[4,e.post(this.getGWTokenUrl(),t,r,n).then((function(e){i=e.data.access_token,o=e.data.expires_in})).catch((function(s){return __awaiter(c,void 0,void 0,(function(){return __generator(this,(function(c){switch(c.label){case 0:return cloud_gw_url_util_1.CloudGwUrlUtil.checkUseBackUrl(s,!0)?[4,e.post(this.getGWTokenUrl(!0),t,r,n).then((function(e){i=e.data.access_token,o=e.data.expires_in})).catch((function(e){return Promise.reject(new error_1.AGCError(error_message_1.ErrorCodeConstant.REQUEST_TOKEN_FAILED,void 0,e.message?e.message:void 0))}))]:[3,2];case 1:return c.sent(),[3,3];case 2:return[2,Promise.reject(new error_1.AGCError(error_message_1.ErrorCodeConstant.REQUEST_TOKEN_FAILED,void 0,s.message?s.message:void 0))];case 3:return[2]}}))}))}))];case 1:return s.sent(),this.accessToken=new access_token_1.AccessToken(i,(new Date).getTime()+1e3*o),[2,Promise.resolve(i)]}}))}))},e.prototype.getGWTokenUrl=function(t){return cloud_gw_url_util_1.CloudGwUrlUtil.getCloudgwUrlByRegion(this.getRegion(),t)+configService_1.ConfigService.getService("COMMON").getConfigValue(e.CLIENT_TOKEN_PATH)},e.CLIENT_TOKEN_PATH="client_token_path",e}();exports.ClientIdCredential=ClientIdCredential;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Huawei Technologies Co., Ltd. 2023 All rights reserved.
|
|
3
|
+
*/
|
|
4
|
+
import { CredentialService } from './credential-service';
|
|
5
|
+
export interface UserDefinedGetClientSecret {
|
|
6
|
+
(): string;
|
|
7
|
+
}
|
|
8
|
+
export declare class CredentialParser {
|
|
9
|
+
private static AGC_CONFIG_ENV_VAR;
|
|
10
|
+
private static AGC_CREDENTIAL_ENV_VAR;
|
|
11
|
+
/**
|
|
12
|
+
* Converts the provided credential file or environment variable to a CredentialService object.
|
|
13
|
+
* If a filePath is provided, it reads the credential data from the file.
|
|
14
|
+
* If no filePath is provided, it checks for the 'AGC_CONFIG' and 'PROJECT_CREDENTIAL' environment variables.
|
|
15
|
+
* @param filePath - The path to the credential file.
|
|
16
|
+
* @param func - The user-defined function to retrieve the client secret.
|
|
17
|
+
* @returns A CredentialService object.
|
|
18
|
+
* @throws {AGCError} - If the JSON file is invalid, the 'AGC_CONFIG' is not set, or the 'PROJECT_CREDENTIAL' is not set.
|
|
19
|
+
*/
|
|
20
|
+
static toCredential(filePath?: string, func?: UserDefinedGetClientSecret): CredentialService;
|
|
21
|
+
static toCredentialWithContents(contents: string, func?: UserDefinedGetClientSecret): CredentialService;
|
|
22
|
+
private static checkJsonFile;
|
|
23
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";var __importDefault=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(exports,"__esModule",{value:!0}),exports.CredentialParser=void 0;var error_1=require("../error/error"),error_message_1=require("../error/error-message"),credential_type_1=require("./credential-type"),clientid_credential_1=require("./clientid-credential"),utils_1=require("../utils/utils"),fs_1=__importDefault(require("fs")),CredentialParser=function(){function e(){}return e.toCredential=function(r,t){var n;if(r)e.checkJsonFile(r),n=fs_1.default.readFileSync(r,"utf8");else{var i=process.env[e.AGC_CONFIG_ENV_VAR];if(null==i||null==i){var o=process.env[e.AGC_CREDENTIAL_ENV_VAR];if(o)return this.toCredentialWithContents(o,t);throw new error_1.AGCError(error_message_1.ErrorCodeConstant.CREDENTIAL_ENV_NOT_SET)}e.checkJsonFile(i),n=fs_1.default.readFileSync(i,"utf8")}return this.toCredentialWithContents(n,t)},e.toCredentialWithContents=function(e,r){var t,n=JSON.parse(e);if(null==n||null==n)throw new error_1.AGCError(error_message_1.ErrorCodeConstant.CREDENTIAL_PARSER);switch(n.type){case credential_type_1.CredentialType.TEAM_CLIENT_ID:return t=r?r():n.client_secret,new clientid_credential_1.ClientIdCredential("","",n.developer_id,n.type,n.client_id,t,n.configuration_version);case credential_type_1.CredentialType.PROJECT_CLIENT_ID:return t=r?r():n.client_secret,new clientid_credential_1.ClientIdCredential(n.project_id,n.region,n.developer_id,n.type,n.client_id,t,n.configuration_version);default:throw new error_1.AGCError(error_message_1.ErrorCodeConstant.CREDENTIAL_PARSER)}},e.checkJsonFile=function(e){try{(0,utils_1.voilidatePath)(e)}catch(e){throw e instanceof error_1.AGCError?new error_1.AGCError(error_message_1.ErrorCodeConstant.AGC_CLIENT_CREDENTIAL,void 0,void 0,e.getMessage()):new error_1.AGCError(error_message_1.ErrorCodeConstant.AGC_CLIENT_CREDENTIAL)}},e.AGC_CONFIG_ENV_VAR="AGC_CONFIG",e.AGC_CREDENTIAL_ENV_VAR="PROJECT_CREDENTIAL",e}();exports.CredentialParser=CredentialParser;
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Huawei Technologies Co., Ltd. 2023 All rights reserved.
|
|
3
|
+
*/
|
|
4
|
+
export interface CredentialService {
|
|
5
|
+
/**
|
|
6
|
+
* 获取项目ID
|
|
7
|
+
*
|
|
8
|
+
* @return 项目ID
|
|
9
|
+
*/
|
|
10
|
+
getProjectId(): string;
|
|
11
|
+
/**
|
|
12
|
+
* 获取Region
|
|
13
|
+
*
|
|
14
|
+
* @return 获取Region
|
|
15
|
+
*/
|
|
16
|
+
getRegion(): string;
|
|
17
|
+
/**
|
|
18
|
+
* 获取Client ID
|
|
19
|
+
*
|
|
20
|
+
* @return 获取Client ID
|
|
21
|
+
*/
|
|
22
|
+
getClientId(): string;
|
|
23
|
+
/**
|
|
24
|
+
* 获取开发者ID
|
|
25
|
+
*
|
|
26
|
+
* @return 获取开发者ID
|
|
27
|
+
*/
|
|
28
|
+
getDeveloperId(): string;
|
|
29
|
+
/**
|
|
30
|
+
* 获取clientSecret
|
|
31
|
+
*
|
|
32
|
+
* @return 获取clientSecret
|
|
33
|
+
*/
|
|
34
|
+
getClientSecret(): string;
|
|
35
|
+
/**
|
|
36
|
+
* 获取Token
|
|
37
|
+
*
|
|
38
|
+
* @return 获取Token
|
|
39
|
+
*/
|
|
40
|
+
getAccessToken(): Promise<string>;
|
|
41
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";var CredentialType;Object.defineProperty(exports,"__esModule",{value:!0}),exports.CredentialType=void 0,function(e){e.PROJECT_CLIENT_ID="project_client_id",e.TEAM_CLIENT_ID="team_client_id"}(CredentialType=exports.CredentialType||(exports.CredentialType={}));
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Huawei Technologies Co., Ltd. 2023 All rights reserved.
|
|
3
|
+
*/
|
|
4
|
+
import { ErrorCode } from './error';
|
|
5
|
+
/**
|
|
6
|
+
* Exception Definition Class.10000-10999
|
|
7
|
+
*/
|
|
8
|
+
export declare class ErrorCodeConstant {
|
|
9
|
+
static readonly FS_READ_FAIL: ErrorCode;
|
|
10
|
+
static readonly FS_WRITE_FAIL: ErrorCode;
|
|
11
|
+
static readonly URL_VALIDATE_FAIL: ErrorCode;
|
|
12
|
+
static readonly MTTHOD_NOT_EXSIT: ErrorCode;
|
|
13
|
+
static readonly URL_NOT_EXSIT: ErrorCode;
|
|
14
|
+
static readonly FILE_NOT_EXSIT: ErrorCode;
|
|
15
|
+
static readonly NOT_A_FILE: ErrorCode;
|
|
16
|
+
static readonly FILE_NO_READ_PERMISSION: ErrorCode;
|
|
17
|
+
static readonly ENV_NOT_NODEJS: ErrorCode;
|
|
18
|
+
static readonly CREDENTIAL_ENV_NOT_SET: ErrorCode;
|
|
19
|
+
static readonly LOAD_SERVICE_CONFIG_ERROR: ErrorCode;
|
|
20
|
+
static readonly LOAD_CUSTOM_CONFIG_ERROR: ErrorCode;
|
|
21
|
+
static readonly CREDENTIAL_PARSER: ErrorCode;
|
|
22
|
+
static readonly AGC_CLIENT_PARA: ErrorCode;
|
|
23
|
+
static readonly AGC_CLIENT_EXIST: ErrorCode;
|
|
24
|
+
static readonly AGC_CLIENT_CREDENTIAL: ErrorCode;
|
|
25
|
+
static readonly AGC_CLIENT_NOT_EXIST: ErrorCode;
|
|
26
|
+
static readonly INVALID_REGION: ErrorCode;
|
|
27
|
+
static readonly REQUEST_TOKEN_FAILED: ErrorCode;
|
|
28
|
+
static readonly CREATE_HTTP_CLIENT_REPONSE_TYPE: ErrorCode;
|
|
29
|
+
static toMessage(err: ErrorCode): string;
|
|
30
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.ErrorCodeConstant=void 0;var ErrorCodeConstant=function(){function e(){}return e.toMessage=function(e){return e.code+": "+e.message},e.FS_READ_FAIL={code:"10101",message:"fs read fail"},e.FS_WRITE_FAIL={code:"10102",message:"fs write fail"},e.URL_VALIDATE_FAIL={code:"10201",message:"url validate fail"},e.MTTHOD_NOT_EXSIT={code:"10202",message:"url method not exist"},e.URL_NOT_EXSIT={code:"10203",message:"url is not found, please check your url path"},e.FILE_NOT_EXSIT={code:"10204",message:"file not exist"},e.NOT_A_FILE={code:"10205",message:"path is not a file path"},e.FILE_NO_READ_PERMISSION={code:"10206",message:"no permission to read the file"},e.ENV_NOT_NODEJS={code:"10301",message:"Currently, only the nodejs environment is supported"},e.CREDENTIAL_ENV_NOT_SET={code:"10302",message:"no credential file path and AGC_CONFIG not set"},e.LOAD_SERVICE_CONFIG_ERROR={code:"10400",message:"load service config error"},e.LOAD_CUSTOM_CONFIG_ERROR={code:"10401",message:"load custom config error"},e.CREDENTIAL_PARSER={code:"10501",message:"parser credential fail"},e.AGC_CLIENT_PARA={code:"10601",message:"create agc client parameter error"},e.AGC_CLIENT_EXIST={code:"10602",message:"agc client name already exist"},e.AGC_CLIENT_CREDENTIAL={code:"10603",message:"agc client credential fail"},e.AGC_CLIENT_NOT_EXIST={code:"10604",message:"agc client name not exist"},e.INVALID_REGION={code:"10605",message:"init agc client with invalid region"},e.REQUEST_TOKEN_FAILED={code:"10606",message:"request access token failed"},e.CREATE_HTTP_CLIENT_REPONSE_TYPE={code:"10701",message:"create http client response type error. only support arraybuffer|blob|document|json|text|stream"},e}();exports.ErrorCodeConstant=ErrorCodeConstant;
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Huawei Technologies Co., Ltd. 2023 All rights reserved.
|
|
3
|
+
*/
|
|
4
|
+
export declare class AGCBaseError extends Error {
|
|
5
|
+
protected static readonly COLON = ": ";
|
|
6
|
+
protected static readonly COMMA = ", ";
|
|
7
|
+
protected static readonly DASH = "-";
|
|
8
|
+
private readonly defaultName;
|
|
9
|
+
/**
|
|
10
|
+
* constructor for exception extends father error
|
|
11
|
+
* @param {string} msg The error message.
|
|
12
|
+
* @param {string} name The AGCClient instance name.
|
|
13
|
+
* @param {string} suffix The service name.
|
|
14
|
+
* @constructor
|
|
15
|
+
*/
|
|
16
|
+
constructor(msg: string, name?: string, suffix?: string);
|
|
17
|
+
setName(value: string): void;
|
|
18
|
+
getName(): string;
|
|
19
|
+
}
|
|
20
|
+
export interface ErrorCode {
|
|
21
|
+
code: string;
|
|
22
|
+
message: string;
|
|
23
|
+
}
|
|
24
|
+
export declare class AGCError extends AGCBaseError {
|
|
25
|
+
private errorCode;
|
|
26
|
+
/**
|
|
27
|
+
* constructor for AGCErrorCode extends father error
|
|
28
|
+
* @param {ErrorCode} errorCode option for params for define errorName
|
|
29
|
+
* @param {string} name option attribute name about exception
|
|
30
|
+
* @return {new AGCBaseError()}
|
|
31
|
+
*
|
|
32
|
+
*/
|
|
33
|
+
constructor(errorCode: ErrorCode, name?: string, suffix?: string, msg?: string);
|
|
34
|
+
getCode(): string;
|
|
35
|
+
getMessage(): string;
|
|
36
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";var __extends=this&&this.__extends||function(){var r=function(e,t){return r=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(r,e){r.__proto__=e}||function(r,e){for(var t in e)Object.prototype.hasOwnProperty.call(e,t)&&(r[t]=e[t])},r(e,t)};return function(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Class extends value "+String(t)+" is not a constructor or null");function o(){this.constructor=e}r(e,t),e.prototype=null===t?Object.create(t):(o.prototype=t.prototype,new o)}}();Object.defineProperty(exports,"__esModule",{value:!0}),exports.AGCError=exports.AGCBaseError=void 0;var AGCBaseError=function(r){function e(t,o,n){var s=r.call(this,t)||this;return s.defaultName="AGCError",s.message=t,s.name=o||s.defaultName,n&&(s.name=s.name+e.DASH+n),s.__proto__=e.prototype,s}return __extends(e,r),e.prototype.setName=function(r){this.name=r},e.prototype.getName=function(){return this.name},e.COLON=": ",e.COMMA=", ",e.DASH="-",e}(Error);exports.AGCBaseError=AGCBaseError;var AGCError=function(r){function e(t,o,n,s){var a=this,i=t.code+e.COLON+t.message;return s&&(i=i+e.COMMA+s),(a=r.call(this,i,o,n)||this).__proto__=e.prototype,a.errorCode=t,s&&(a.errorCode.message=a.errorCode.message+e.COMMA+s),a}return __extends(e,r),e.prototype.getCode=function(){return this.errorCode.code},e.prototype.getMessage=function(){return this.errorCode.message},e}(AGCBaseError);exports.AGCError=AGCError;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Huawei Technologies Co., Ltd. 2023 All rights reserved.
|
|
3
|
+
*/
|
|
4
|
+
import { ConnectRet } from "./connect-ret";
|
|
5
|
+
export declare abstract class BaseResponse {
|
|
6
|
+
ret: ConnectRet;
|
|
7
|
+
isSuccess(): boolean;
|
|
8
|
+
getRet(): ConnectRet;
|
|
9
|
+
setRet(value: ConnectRet): void;
|
|
10
|
+
abstract constructResponse(response: any): void;
|
|
11
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.BaseResponse=void 0;var connect_ret_1=require("./connect-ret"),BaseResponse=function(){function e(){this.ret=new connect_ret_1.ConnectRet(0,"")}return e.prototype.isSuccess=function(){return null!=this.ret&&0===this.ret.getCode()},e.prototype.getRet=function(){return this.ret},e.prototype.setRet=function(e){this.ret=e},e}();exports.BaseResponse=BaseResponse;
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
export declare class CommonHeaders {
|
|
2
|
+
static DEFAULT_CONFIG: string;
|
|
3
|
+
static KEY_REQUEST_ID: string;
|
|
4
|
+
static KEY_USER_AGENT: string;
|
|
5
|
+
static SDK_NAME: string;
|
|
6
|
+
static SDK_VERSION: string;
|
|
7
|
+
static ALGORITHM_TYPE_NEW_JWT_TOKEN: string;
|
|
8
|
+
static SDK_PREFIX: string;
|
|
9
|
+
static USER_AGENT_PREFIX: string;
|
|
10
|
+
static KEY_AUTHORIZATION: string;
|
|
11
|
+
static VALUE_BEARER: string;
|
|
12
|
+
static KEY_HOST: string;
|
|
13
|
+
/**
|
|
14
|
+
* request id generator
|
|
15
|
+
*
|
|
16
|
+
* @return request id
|
|
17
|
+
*/
|
|
18
|
+
static generateRequestId(): string;
|
|
19
|
+
/**
|
|
20
|
+
* get user agent for server sdk
|
|
21
|
+
*
|
|
22
|
+
* @return user agent
|
|
23
|
+
*/
|
|
24
|
+
static getUserAgent(): string;
|
|
25
|
+
/**
|
|
26
|
+
* get sdk name
|
|
27
|
+
*
|
|
28
|
+
* @return sdk name
|
|
29
|
+
*/
|
|
30
|
+
static getSDKName(serviceName?: string): string;
|
|
31
|
+
/**
|
|
32
|
+
* get sdk version
|
|
33
|
+
*
|
|
34
|
+
* @return sdk version
|
|
35
|
+
*/
|
|
36
|
+
static getSDKVersion(): string;
|
|
37
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";var __createBinding=this&&this.__createBinding||(Object.create?function(e,t,r,n){void 0===n&&(n=r);var i=Object.getOwnPropertyDescriptor(t,r);i&&!("get"in i?!t.__esModule:i.writable||i.configurable)||(i={enumerable:!0,get:function(){return t[r]}}),Object.defineProperty(e,n,i)}:function(e,t,r,n){void 0===n&&(n=r),e[n]=t[r]}),__setModuleDefault=this&&this.__setModuleDefault||(Object.create?function(e,t){Object.defineProperty(e,"default",{enumerable:!0,value:t})}:function(e,t){e.default=t}),__importStar=this&&this.__importStar||function(e){if(e&&e.__esModule)return e;var t={};if(null!=e)for(var r in e)"default"!==r&&Object.prototype.hasOwnProperty.call(e,r)&&__createBinding(t,e,r);return __setModuleDefault(t,e),t};Object.defineProperty(exports,"__esModule",{value:!0}),exports.CommonHeaders=void 0;var UUID=__importStar(require("uuid")),configService_1=require("../config/configService"),CommonHeaders=function(){function e(){}return e.generateRequestId=function(){return UUID.v1().replace(/-/g,"")},e.getUserAgent=function(){return e.USER_AGENT_PREFIX+configService_1.ConfigService.getService("COMMON").getConfigValue(e.SDK_VERSION)},e.getSDKName=function(t){return t?e.SDK_PREFIX+t:e.SDK_PREFIX+configService_1.ConfigService.getService("COMMON").getConfigValue(e.SDK_NAME)},e.getSDKVersion=function(){return configService_1.ConfigService.getService("COMMON").getConfigValue(e.SDK_VERSION)},e.DEFAULT_CONFIG="agconnect-common",e.KEY_REQUEST_ID="X-Request-Id",e.KEY_USER_AGENT="User-Agent",e.SDK_NAME="sdk_name",e.SDK_VERSION="sdk_version",e.ALGORITHM_TYPE_NEW_JWT_TOKEN="1",e.SDK_PREFIX="node/",e.USER_AGENT_PREFIX="AGCServerSDK/",e.KEY_AUTHORIZATION="Authorization",e.VALUE_BEARER="Bearer ",e.KEY_HOST="Host",e}();exports.CommonHeaders=CommonHeaders;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Huawei Technologies Co., Ltd. 2023 All rights reserved.
|
|
3
|
+
*/
|
|
4
|
+
export declare class ConnectRet {
|
|
5
|
+
private code;
|
|
6
|
+
private msg;
|
|
7
|
+
constructor(code: number, msg: string);
|
|
8
|
+
getCode(): number;
|
|
9
|
+
setCode(value: number): void;
|
|
10
|
+
getMsg(): string;
|
|
11
|
+
setMsg(value: string): void;
|
|
12
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.ConnectRet=void 0;var ConnectRet=function(){function t(t,e){this.code=t,this.msg=e}return t.prototype.getCode=function(){return this.code},t.prototype.setCode=function(t){this.code=t},t.prototype.getMsg=function(){return this.msg},t.prototype.setMsg=function(t){this.msg=t},t}();exports.ConnectRet=ConnectRet;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.getHttpClient=void 0;var http_clinet_api_1=require("./http-clinet-api");function getHttpClient(t){return new http_clinet_api_1.HttpClientAPIImpl(t)}exports.getHttpClient=getHttpClient;
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Huawei Technologies Co., Ltd. 2023 All rights reserved.
|
|
3
|
+
*/
|
|
4
|
+
export interface HttpClientCfg {
|
|
5
|
+
timeout?: number;
|
|
6
|
+
responseType?: string;
|
|
7
|
+
maxBodyLength?: number;
|
|
8
|
+
maxContentLength?: number;
|
|
9
|
+
isEnableSSLCert?: boolean;
|
|
10
|
+
casFile?: string[];
|
|
11
|
+
commonHeaders?: {
|
|
12
|
+
[key: string]: string;
|
|
13
|
+
};
|
|
14
|
+
}
|
|
15
|
+
export interface HttpClientAPI {
|
|
16
|
+
/**
|
|
17
|
+
* This method is used to send a post request that calls the post request of Axios.
|
|
18
|
+
*
|
|
19
|
+
* @param {string} url
|
|
20
|
+
* @param {any} params
|
|
21
|
+
* @param {any} data
|
|
22
|
+
* @param {any} headers
|
|
23
|
+
* @return {Promise<any>} return
|
|
24
|
+
*/
|
|
25
|
+
post(url: string, data: any, params: any, headers: any): Promise<any>;
|
|
26
|
+
/**
|
|
27
|
+
* This method is used to send a get request that calls the get request of Axios.
|
|
28
|
+
*
|
|
29
|
+
* @param {string} url
|
|
30
|
+
* @param {any} params
|
|
31
|
+
* @param {any} headers
|
|
32
|
+
* @return {Promise<any>} return
|
|
33
|
+
*/
|
|
34
|
+
get(url: string, params: any, headers: any): Promise<any>;
|
|
35
|
+
/**
|
|
36
|
+
* This method is used to send a delete request that calls the delete request of Axios.
|
|
37
|
+
*
|
|
38
|
+
* @param {string} url
|
|
39
|
+
* @param {any} params
|
|
40
|
+
* @param {any} headers
|
|
41
|
+
* @return {Promise<any>} return
|
|
42
|
+
*/
|
|
43
|
+
delete(url: string, data: any, params: any, headers: any): Promise<any>;
|
|
44
|
+
/**
|
|
45
|
+
* This method is used to send a delete request that calls the delete request of Axios.
|
|
46
|
+
*
|
|
47
|
+
* @param {string} url
|
|
48
|
+
* @param {any} params
|
|
49
|
+
* @param {any} data
|
|
50
|
+
* @param {any} headers
|
|
51
|
+
* @return {Promise<any>} return
|
|
52
|
+
*/
|
|
53
|
+
put(url: string, data: any, params: any, headers: any): Promise<any>;
|
|
54
|
+
}
|
|
55
|
+
export declare class HttpClientAPIImpl implements HttpClientAPI {
|
|
56
|
+
private static DEFAULT_TIMEOUT;
|
|
57
|
+
private static DEFAULT_RESPONSE_TYPE;
|
|
58
|
+
private instance;
|
|
59
|
+
constructor(cfg?: HttpClientCfg);
|
|
60
|
+
post(url: string, data: any, params: any, headers: any): Promise<any>;
|
|
61
|
+
get(url: string, params: any, headers: any): Promise<any>;
|
|
62
|
+
delete(url: string, data: any, params: any, headers: any): Promise<any>;
|
|
63
|
+
put(url: string, data: any, params: any, headers: any): Promise<any>;
|
|
64
|
+
private getReponseType;
|
|
65
|
+
private send;
|
|
66
|
+
}
|