├── .babelrc
├── .editorconfig
├── .gitignore
├── .npmrc
├── .prettierignore
├── .prettierrc
├── .vscode
└── settings.json
├── .yarnrc
├── LICENSE
├── README.md
├── global.d.ts
├── jest.config.js
├── lerna.json
├── package.json
├── packages
├── capi-web
│ ├── .npmignore
│ ├── README.md
│ ├── package.json
│ ├── src
│ │ └── index.ts
│ └── tsconfig.json
├── capi
│ ├── .npmignore
│ ├── README.md
│ ├── __tests__
│ │ └── index.test.ts
│ ├── package.json
│ ├── src
│ │ ├── factory.ts
│ │ ├── index.ts
│ │ └── utils.ts
│ └── tsconfig.json
├── cls
│ ├── .npmignore
│ ├── README.md
│ ├── __tests__
│ │ └── index.test.ts
│ ├── package.json
│ ├── src
│ │ ├── index.ts
│ │ ├── typings
│ │ │ └── index.ts
│ │ └── utils.ts
│ └── tsconfig.json
├── common
│ ├── .npmignore
│ ├── README.md
│ ├── __tests__
│ │ └── index.test.ts
│ ├── package.json
│ ├── src
│ │ ├── cropto.ts
│ │ ├── index.ts
│ │ └── logger.ts
│ └── tsconfig.json
├── faas
│ ├── .npmignore
│ ├── README.md
│ ├── __tests__
│ │ └── index.test.ts
│ ├── package.json
│ ├── src
│ │ ├── apis.ts
│ │ ├── constants.ts
│ │ ├── dayjs.ts
│ │ ├── index.ts
│ │ ├── monitor
│ │ │ ├── apis.ts
│ │ │ └── index.ts
│ │ ├── typings
│ │ │ └── index.ts
│ │ └── utils.ts
│ └── tsconfig.json
└── login
│ ├── .npmignore
│ ├── README.md
│ ├── __tests__
│ └── index.test.ts
│ ├── package.json
│ ├── src
│ ├── constant.ts
│ └── index.ts
│ └── tsconfig.json
├── scripts
├── bundle.ts
├── logger.ts
├── project.ts
├── publish.ts
└── tsconfig.json
├── tsconfig.base.json
├── tsconfig.json
└── tslint.json
/.babelrc:
--------------------------------------------------------------------------------
1 | {
2 | "presets": [
3 | [
4 | "@babel/env",
5 | {
6 | "modules": false,
7 | "targets": {
8 | "browsers": [
9 | ">0.25%"
10 | ]
11 | },
12 | "useBuiltIns": "usage"
13 | }
14 | ],
15 | "@babel/typescript"
16 | ],
17 | "env": {
18 | "development": {
19 | "plugins": [
20 | "@babel/transform-runtime"
21 | ]
22 | },
23 | "production": {
24 | "plugins": [
25 | "@babel/transform-runtime",
26 | "transform-remove-console"
27 | ]
28 | },
29 | "test": {
30 | "presets": [
31 | [
32 | "@babel/env",
33 | {
34 | "modules": "commonjs",
35 | "targets": {
36 | "node": "current"
37 | }
38 | }
39 | ],
40 | "@babel/typescript"
41 | ]
42 | }
43 | },
44 | "plugins": [
45 | "@babel/plugin-syntax-dynamic-import",
46 | "@babel/plugin-syntax-import-meta",
47 | "@babel/plugin-proposal-class-properties",
48 | "@babel/plugin-proposal-json-strings",
49 | [
50 | "@babel/plugin-proposal-decorators",
51 | {
52 | "legacy": true
53 | }
54 | ],
55 | "@babel/plugin-proposal-function-sent",
56 | "@babel/plugin-proposal-export-namespace-from",
57 | "@babel/plugin-proposal-numeric-separator",
58 | "@babel/plugin-proposal-throw-expressions",
59 | "@babel/plugin-proposal-export-default-from",
60 | "@babel/plugin-proposal-logical-assignment-operators",
61 | "@babel/plugin-proposal-optional-chaining",
62 | [
63 | "@babel/plugin-proposal-pipeline-operator",
64 | {
65 | "proposal": "minimal"
66 | }
67 | ],
68 | "@babel/plugin-proposal-nullish-coalescing-operator",
69 | "@babel/plugin-proposal-do-expressions"
70 | ]
71 | }
--------------------------------------------------------------------------------
/.editorconfig:
--------------------------------------------------------------------------------
1 | root = true
2 | [*]
3 | insert_final_newline = true
4 | [*.{js,ts}]
5 | indent_style = space
6 | indent_size = 2
7 | charset = utf-8
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | node_modules
2 | .DS_STORE
3 | lerna-debug.log
4 | yarn-error.log
5 | dist
6 | includes
7 | tsconfig.tsbuildinfo
8 | .env*
9 | coverage
10 | yarn.lock
11 | .rpt2_cache
12 |
--------------------------------------------------------------------------------
/.npmrc:
--------------------------------------------------------------------------------
1 | package-lock=false
2 |
--------------------------------------------------------------------------------
/.prettierignore:
--------------------------------------------------------------------------------
1 |
2 |
3 | # Development folders and files #
4 | #################################
5 | .tmp/
6 | node_modules/
7 | package.json
8 | .travis.yml
9 | dist
10 |
--------------------------------------------------------------------------------
/.prettierrc:
--------------------------------------------------------------------------------
1 | {
2 | "printWidth": 80,
3 | "singleQuote": true,
4 | "trailingComma": "all",
5 | "arrowParens": "always",
6 | "overrides": [
7 | {
8 | "files": "*.json",
9 | "options": {
10 | "parser": "json"
11 | }
12 | }
13 | ]
14 | }
15 |
--------------------------------------------------------------------------------
/.vscode/settings.json:
--------------------------------------------------------------------------------
1 | {
2 | "typescript.tsdk": "node_modules/typescript/lib"
3 | }
4 |
--------------------------------------------------------------------------------
/.yarnrc:
--------------------------------------------------------------------------------
1 | registry "https://registry.npmjs.org"
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2019 Yuga Sun
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # tencent-sdk
2 |
3 | Tencent Cloud SDK
4 |
5 | ## Packages
6 |
7 | | Package Name | Introduction | Npm Link |
8 | | ----------------------- | ------------------------------------------------------ | ----------------------------------------------------------- |
9 | | `@tencent-sdk/capi` | [@tencent-sdk/capi](./packages/capi/README.md) | [Link](https://www.npmjs.com/package/@tencent-sdk/capi) |
10 | | `@tencent-sdk/login` | [@tencent-sdk/login](./packages/login/README.md) | [Link](https://www.npmjs.com/package/@tencent-sdk/login) |
11 | | `@tencent-sdk/faas` | [@tencent-sdk/faas](./packages/faas/README.md) | [Link](https://www.npmjs.com/package/@tencent-sdk/faas) |
12 | | `@tencent-sdk/cls` | [@tencent-sdk/cls](./packages/cls/README.md) | [Link](https://www.npmjs.com/package/@tencent-sdk/cls) |
13 | | `@tencent-sdk/capi-web` | [@tencent-sdk/capi-web](./packages/capi-web/README.md) | [Link](https://www.npmjs.com/package/@tencent-sdk/capi-web) |
14 |
15 | ## License
16 |
17 | [MIT](./LICENSE)
18 |
--------------------------------------------------------------------------------
/global.d.ts:
--------------------------------------------------------------------------------
1 | declare namespace NodeJS {
2 | interface ProcessEnv {
3 | TENCENT_APP_ID: string;
4 | TENCENT_SECRET_ID: string;
5 | TENCENT_SECRET_KEY: string;
6 | TENCENT_SECRET_TOKEN?: string;
7 | }
8 | }
9 |
--------------------------------------------------------------------------------
/jest.config.js:
--------------------------------------------------------------------------------
1 | const { join } = require('path');
2 | require('dotenv').config({ path: join(__dirname, '.env.test') });
3 |
4 | const isCI = !!process.env.CI;
5 | const mod = process.env.MODULE;
6 |
7 | const config = {
8 | verbose: true,
9 | silent: isCI,
10 | transform: {
11 | '^.+\\.tsx?$': 'ts-jest',
12 | },
13 | globals: {
14 | 'ts-jest': {
15 | tsconfig: 'tsconfig.base.json',
16 | },
17 | },
18 | testTimeout: 60000,
19 | testEnvironment: 'node',
20 | testRegex: '/packages/.*/__tests__/.*\\.(test|spec)\\.(js|ts)$',
21 | testPathIgnorePatterns: ['/node_modules/', '/dist/', '/__tests__/fixtures/'],
22 | moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx', 'json', 'node'],
23 | };
24 |
25 | if (mod) {
26 | config.testRegex = `/${mod}/__tests__/.*\\.(test|spec)\\.(js|ts)$`;
27 | }
28 |
29 | module.exports = config;
30 |
--------------------------------------------------------------------------------
/lerna.json:
--------------------------------------------------------------------------------
1 | {
2 | "packages": ["packages/*"],
3 | "version": "independent",
4 | "useWorkspaces": true,
5 | "command": {
6 | "publish": {
7 | "allowBranch": ["master", "dev"],
8 | "message": "chore(release): lerna publish"
9 | }
10 | }
11 | }
12 |
--------------------------------------------------------------------------------
/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "tencent-sdk",
3 | "private": true,
4 | "scripts": {
5 | "bootstrap": "lerna bootstrap",
6 | "build": "ts-node -P scripts/tsconfig.json scripts/bundle.ts umd,esm",
7 | "test": "jest",
8 | "clean": "lerna clean --yes && lerna run clean",
9 | "release": "yarn run build && lerna publish --exact",
10 | "prettier": "prettier --check '**/*.{ts,tsx,md}' --config .prettierrc",
11 | "prettier:fix": "prettier --write '**/*.{ts,tsx,md}' --config .prettierrc"
12 | },
13 | "workspaces": [
14 | "packages/*"
15 | ],
16 | "husky": {
17 | "hooks": {
18 | "pre-commit": "lint-staged"
19 | }
20 | },
21 | "lint-staged": {
22 | "*.{ts,tsx,md}": [
23 | "prettier -c"
24 | ]
25 | },
26 | "devDependencies": {
27 | "@babel/cli": "^7.7.0",
28 | "@babel/core": "^7.7.2",
29 | "@babel/plugin-proposal-class-properties": "^7.7.0",
30 | "@babel/plugin-proposal-decorators": "^7.7.0",
31 | "@babel/plugin-proposal-do-expressions": "^7.6.0",
32 | "@babel/plugin-proposal-export-default-from": "^7.5.2",
33 | "@babel/plugin-proposal-export-namespace-from": "^7.5.2",
34 | "@babel/plugin-proposal-function-sent": "^7.7.0",
35 | "@babel/plugin-proposal-json-strings": "^7.2.0",
36 | "@babel/plugin-proposal-logical-assignment-operators": "^7.2.0",
37 | "@babel/plugin-proposal-nullish-coalescing-operator": "^7.4.4",
38 | "@babel/plugin-proposal-numeric-separator": "^7.2.0",
39 | "@babel/plugin-proposal-optional-chaining": "^7.6.0",
40 | "@babel/plugin-proposal-pipeline-operator": "^7.5.0",
41 | "@babel/plugin-proposal-throw-expressions": "^7.2.0",
42 | "@babel/plugin-syntax-dynamic-import": "^7.2.0",
43 | "@babel/plugin-syntax-import-meta": "^7.2.0",
44 | "@babel/plugin-transform-runtime": "^7.6.2",
45 | "@babel/polyfill": "^7.7.0",
46 | "@babel/preset-env": "^7.7.1",
47 | "@babel/preset-typescript": "^7.7.2",
48 | "@babel/runtime": "^7.7.2",
49 | "@types/node": "^12.12.6",
50 | "chalk": "^3.0.0",
51 | "cross-env": "^6.0.3",
52 | "dotenv": "^8.2.0",
53 | "fancy-log": "^1.3.3",
54 | "husky": "^3.0.9",
55 | "jest": "^26.6.3",
56 | "lerna": "^3.18.3",
57 | "lint-staged": "^9.5.0",
58 | "prettier": "^1.18.2",
59 | "rimraf": "^3.0.0",
60 | "rollup": "3.29.5",
61 | "rollup-plugin-alias": "^1.4.0",
62 | "rollup-plugin-commonjs": "8.4.1",
63 | "rollup-plugin-json": "^3.1.0",
64 | "rollup-plugin-node-builtins": "^2.1.2",
65 | "rollup-plugin-node-globals": "^1.4.0",
66 | "rollup-plugin-node-resolve": "^3.4.0",
67 | "rollup-plugin-typescript2": "0.17.1",
68 | "ts-jest": "^26.4.4",
69 | "ts-node": "^8.4.1",
70 | "tslint": "^5.20.1",
71 | "tslint-config-prettier": "^1.18.0",
72 | "typescript": "^4.1.2",
73 | "typescript-json-schema": "^0.44.1",
74 | "webpack": "^4.41.2",
75 | "webpack-command": "^0.5.0"
76 | },
77 | "license": "MIT"
78 | }
79 |
--------------------------------------------------------------------------------
/packages/capi-web/.npmignore:
--------------------------------------------------------------------------------
1 | node_modules
2 | *.map
3 | tsconfig.tsbuildinfo
4 | test
5 | src
6 | tsconfig.json
7 |
--------------------------------------------------------------------------------
/packages/capi-web/README.md:
--------------------------------------------------------------------------------
1 | ## Tencent Cound API For Browser
2 |
3 | Request tool for `iaas.cloud.tencent.com`, can only ussed in domain or subdomain of `cloud.tencent.com`
4 |
5 | ## Prepare
6 |
7 | Request tool for `iaas.cloud.tencent.com`, can only ussed in domain or subdomain of `cloud.tencent.com`
8 |
9 | Specify `document.domain` to `cloud.tencent.com`:
10 |
11 | ```html
12 |
15 | ```
16 |
17 | Import `jQuery`:
18 |
19 | ```html
20 |
21 |
22 | ```
23 |
24 | ## Usage
25 |
26 | Using by npm module:
27 |
28 | ```
29 | $ npm i @tencent-sdk/capi-wen --save
30 | ```
31 |
32 | ```js
33 | import { CapiRequest } from '@tencent-sdk/capi-web';
34 | const data = await CapiRequest({
35 | region: 'ap-guangzhou',
36 | serviceType: 'scf',
37 | action: 'ListFunctions',
38 | data: {
39 | Version: '2018-04-16',
40 | Namespace: 'default',
41 | Offset: 0,
42 | Limit: 20,
43 | },
44 | });
45 | ```
46 |
47 | Using by script:
48 |
49 | ```html
50 |
51 | ```
52 |
53 | ## License
54 |
--------------------------------------------------------------------------------
/packages/capi-web/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "@tencent-sdk/capi-web",
3 | "version": "0.1.4",
4 | "description": "Tencent cloud api sdk for browser",
5 | "main": "dist/index.js",
6 | "node": "dist/index.js",
7 | "browser": "dist/index.js",
8 | "module": "dist/index.esm.js",
9 | "jsnext:main": "dist/index.esm.js",
10 | "types": "dist/index.d.ts",
11 | "typings": "dist/index.d.ts",
12 | "publishConfig": {
13 | "access": "public"
14 | },
15 | "scripts": {
16 | "test": "ts-node test/index.spec.ts",
17 | "clean": "rimraf ./dist tsconfig.tsbuildinfo"
18 | },
19 | "keywords": [
20 | "tencent-clound",
21 | "api",
22 | "web",
23 | "browser"
24 | ],
25 | "author": "yugasun",
26 | "license": "MIT",
27 | "directories": {
28 | "test": "test"
29 | },
30 | "repository": {
31 | "type": "git",
32 | "url": "git+https://github.com/yugasun/tencent-sdk.git"
33 | },
34 | "bugs": {
35 | "url": "https://github.com/yugasun/tencent-sdk/issues"
36 | },
37 | "homepage": "https://github.com/yugasun/tencent-sdk#readme"
38 | }
39 |
--------------------------------------------------------------------------------
/packages/capi-web/src/index.ts:
--------------------------------------------------------------------------------
1 | interface CapiError {
2 | code?: string | number;
3 | Code?: string | number;
4 | cgwCode?: string | number;
5 | CgwCode?: string | number;
6 | Message?: string;
7 | }
8 |
9 | interface RequestData {
10 | Region?: string;
11 | Action?: string;
12 | Version?: string;
13 | }
14 | interface RequestParam {
15 | serviceType: string;
16 | action?: string;
17 | regionId?: number;
18 | data?: RequestData;
19 | }
20 |
21 | interface RequestOpts {
22 | isFormData?: string;
23 | clientTimeout?: number;
24 | }
25 |
26 | /**
27 | * whether is cam auth
28 | * @param {CapiError} e capi error
29 | */
30 | export function isCamRefused(e: CapiError): boolean {
31 | e = e || {};
32 | const code = (e.code || e.Code) + '';
33 | return (
34 | code === '4102' ||
35 | code === '42' ||
36 | code.indexOf('UnauthorizedOperation') !== -1 ||
37 | code.indexOf('CamNoAuth') !== -1
38 | );
39 | }
40 |
41 | /**
42 | * whether need login
43 | * @param {CapiError} e capi error
44 | */
45 | export function needLogin(e: CapiError): boolean {
46 | e = e || {};
47 | const code = (e.code || e.Code) + '';
48 | return code === 'VERIFY_LOGIN_FAILED';
49 | }
50 |
51 | /**
52 | * whther need auth
53 | * @param {CapiError} e capi error
54 | */
55 | export function noAuth(e: CapiError): boolean {
56 | e = e || {};
57 | const code = (e.code || e.Code || e.cgwCode || e.CgwCode) + '';
58 | return code === '800200';
59 | }
60 |
61 | const API_DOMAIN = `iaas.${location.hostname.substring(
62 | location.hostname.indexOf('.') + 1,
63 | )}`;
64 | const API_VERSION = '2017-03-12';
65 |
66 | const proxyReady = (id = 'qcbase-proxy'): Promise => {
67 | let iframe: any;
68 |
69 | return new Promise((resolve, reject) => {
70 | iframe = document.getElementById(id);
71 | if (iframe) {
72 | // iframe 中的 domain 可能还没生效
73 | try {
74 | if (iframe.contentWindow.postSend) {
75 | return resolve(iframe.contentWindow.postSend);
76 | }
77 | } catch (e) {}
78 | } else {
79 | iframe = document.createElement('iframe');
80 | iframe.id = id;
81 | iframe.style.display = 'none';
82 | iframe.src = `//${API_DOMAIN}/proxy.html`;
83 | document.body.appendChild(iframe);
84 | }
85 | iframe.addEventListener('load', () => {
86 | try {
87 | resolve(iframe.contentWindow.postSend);
88 | } catch (e) {
89 | reject(e);
90 | }
91 | });
92 | iframe.addEventListener('error', reject);
93 | });
94 | };
95 |
96 | async function request(
97 | url: string,
98 | params: RequestParam,
99 | opts?: RequestOpts,
100 | ): Promise {
101 | opts = opts || {};
102 | const postSend = await proxyReady();
103 | const data = await postSend(url, params, opts);
104 | return data;
105 | }
106 |
107 | /**
108 | * capi proxy request
109 | * @param {Object} data request data
110 | * @param {Object} opts request options
111 | * @return {Promise