@cloudbase/oauth 2.4.5-beta.0 → 2.5.1-beta.0
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/.eslintrc.js +15 -0
- package/dist/cjs/auth/apis.d.ts +3 -3
- package/dist/cjs/auth/apis.js +69 -69
- package/dist/cjs/captcha/captcha.d.ts +9 -9
- package/dist/cjs/captcha/captcha.js +43 -46
- package/dist/cjs/index.d.ts +3 -3
- package/dist/cjs/index.js +6 -6
- package/dist/cjs/oauth2client/interface.d.ts +1 -1
- package/dist/cjs/oauth2client/interface.js +1 -1
- package/dist/cjs/oauth2client/models.js +1 -1
- package/dist/cjs/oauth2client/oauth2client.d.ts +31 -31
- package/dist/cjs/oauth2client/oauth2client.js +229 -229
- package/dist/cjs/utils/function/single-promise.d.ts +2 -2
- package/dist/cjs/utils/function/single-promise.js +40 -33
- package/dist/cjs/utils/uuid.js +2 -2
- package/dist/esm/auth/apis.d.ts +3 -3
- package/dist/esm/auth/apis.js +69 -69
- package/dist/esm/captcha/captcha.d.ts +9 -9
- package/dist/esm/captcha/captcha.js +44 -47
- package/dist/esm/index.d.ts +3 -3
- package/dist/esm/index.js +5 -5
- package/dist/esm/oauth2client/interface.d.ts +1 -1
- package/dist/esm/oauth2client/interface.js +1 -1
- package/dist/esm/oauth2client/models.js +1 -1
- package/dist/esm/oauth2client/oauth2client.d.ts +31 -31
- package/dist/esm/oauth2client/oauth2client.js +229 -229
- package/dist/esm/utils/function/single-promise.d.ts +2 -2
- package/dist/esm/utils/function/single-promise.js +40 -33
- package/dist/esm/utils/uuid.js +2 -2
- package/package.json +13 -6
- package/src/auth/apis.ts +135 -158
- package/src/captcha/captcha.ts +71 -78
- package/src/index.ts +13 -14
- package/src/oauth2client/interface.ts +5 -5
- package/src/oauth2client/models.ts +38 -38
- package/src/oauth2client/oauth2client.ts +255 -268
- package/src/utils/function/single-promise.ts +22 -21
- package/src/utils/uuid.ts +4 -4
- package/.eslintrc +0 -26
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
* Single Promise
|
|
3
3
|
*/
|
|
4
4
|
export class SinglePromise {
|
|
5
|
+
private fnPromiseMap: Map<string, Promise<any>> = new Map()
|
|
5
6
|
/**
|
|
6
7
|
* Run single promise.
|
|
7
8
|
* @param {string} key
|
|
@@ -9,32 +10,32 @@ export class SinglePromise {
|
|
|
9
10
|
* @return {Promise<T>}
|
|
10
11
|
*/
|
|
11
12
|
async run<T>(key: string, fn: () => Promise<T>): Promise<T> {
|
|
12
|
-
let result: Promise<any> = this.
|
|
13
|
-
if (!result) {
|
|
14
|
-
result = new Promise<any>(
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
13
|
+
let result: Promise<any> = this.fnPromiseMap.get(key)
|
|
14
|
+
if (!(await result)) {
|
|
15
|
+
result = new Promise<any>((resolve, reject) => {
|
|
16
|
+
(async () => {
|
|
17
|
+
try {
|
|
18
|
+
// The idle promise must be run to prevent _fnPromiseMap from
|
|
19
|
+
// storing the current promise function.
|
|
20
|
+
await this.runIdlePromise()
|
|
21
|
+
const fnResult: Promise<T> = fn()
|
|
22
|
+
resolve(await fnResult)
|
|
23
|
+
} catch (error) {
|
|
24
|
+
reject(error)
|
|
25
|
+
} finally {
|
|
26
|
+
this.fnPromiseMap.delete(key)
|
|
27
|
+
}
|
|
28
|
+
})()
|
|
29
|
+
})
|
|
30
|
+
this.fnPromiseMap.set(key, result)
|
|
28
31
|
}
|
|
29
|
-
return result
|
|
32
|
+
return result
|
|
30
33
|
}
|
|
31
34
|
/**
|
|
32
35
|
* Run idle promise.
|
|
33
36
|
* @return {Promise<void>}
|
|
34
37
|
*/
|
|
35
|
-
private
|
|
36
|
-
return Promise.resolve()
|
|
38
|
+
private runIdlePromise(): Promise<void> {
|
|
39
|
+
return Promise.resolve()
|
|
37
40
|
}
|
|
38
|
-
|
|
39
|
-
private _fnPromiseMap: Map<string, Promise<any>> = new Map();
|
|
40
41
|
}
|
package/src/utils/uuid.ts
CHANGED
|
@@ -4,8 +4,8 @@
|
|
|
4
4
|
*/
|
|
5
5
|
export function uuidv4(): string {
|
|
6
6
|
return 'xxxxxxxxxxxx4xxxyxxxxxxxxxxxxxxx'.replace(/[xy]/g, (c) => {
|
|
7
|
-
const r = (Math.random() * 16) | 0
|
|
8
|
-
const v = c
|
|
9
|
-
return v.toString(16)
|
|
10
|
-
})
|
|
7
|
+
const r = (Math.random() * 16) | 0
|
|
8
|
+
const v = c === 'x' ? r : (r & 0x3) | 0x8
|
|
9
|
+
return v.toString(16)
|
|
10
|
+
})
|
|
11
11
|
}
|
package/.eslintrc
DELETED
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"extends": [
|
|
3
|
-
"eslint-config-alloy/typescript"
|
|
4
|
-
],
|
|
5
|
-
"rules": {
|
|
6
|
-
"indent": [
|
|
7
|
-
"warn",
|
|
8
|
-
2
|
|
9
|
-
],
|
|
10
|
-
"guard-for-in": 0,
|
|
11
|
-
"no-param-reassign": 0,
|
|
12
|
-
"no-undefined": 0,
|
|
13
|
-
"@typescript-eslint/explicit-member-accessibility": 0,
|
|
14
|
-
"@typescript-eslint/no-loss-of-precision": 0,
|
|
15
|
-
"@typescript-eslint/no-duplicate-imports": 0,
|
|
16
|
-
"@typescript-eslint/consistent-type-assertions": 0,
|
|
17
|
-
"@typescript-eslint/member-ordering": 0
|
|
18
|
-
},
|
|
19
|
-
"parserOptions": {
|
|
20
|
-
"ecmaVersion": 6,
|
|
21
|
-
"sourceType": "module",
|
|
22
|
-
"ecmaFeatures": {
|
|
23
|
-
"modules": true
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
}
|