@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.
Files changed (39) hide show
  1. package/.eslintrc.js +15 -0
  2. package/dist/cjs/auth/apis.d.ts +3 -3
  3. package/dist/cjs/auth/apis.js +69 -69
  4. package/dist/cjs/captcha/captcha.d.ts +9 -9
  5. package/dist/cjs/captcha/captcha.js +43 -46
  6. package/dist/cjs/index.d.ts +3 -3
  7. package/dist/cjs/index.js +6 -6
  8. package/dist/cjs/oauth2client/interface.d.ts +1 -1
  9. package/dist/cjs/oauth2client/interface.js +1 -1
  10. package/dist/cjs/oauth2client/models.js +1 -1
  11. package/dist/cjs/oauth2client/oauth2client.d.ts +31 -31
  12. package/dist/cjs/oauth2client/oauth2client.js +229 -229
  13. package/dist/cjs/utils/function/single-promise.d.ts +2 -2
  14. package/dist/cjs/utils/function/single-promise.js +40 -33
  15. package/dist/cjs/utils/uuid.js +2 -2
  16. package/dist/esm/auth/apis.d.ts +3 -3
  17. package/dist/esm/auth/apis.js +69 -69
  18. package/dist/esm/captcha/captcha.d.ts +9 -9
  19. package/dist/esm/captcha/captcha.js +44 -47
  20. package/dist/esm/index.d.ts +3 -3
  21. package/dist/esm/index.js +5 -5
  22. package/dist/esm/oauth2client/interface.d.ts +1 -1
  23. package/dist/esm/oauth2client/interface.js +1 -1
  24. package/dist/esm/oauth2client/models.js +1 -1
  25. package/dist/esm/oauth2client/oauth2client.d.ts +31 -31
  26. package/dist/esm/oauth2client/oauth2client.js +229 -229
  27. package/dist/esm/utils/function/single-promise.d.ts +2 -2
  28. package/dist/esm/utils/function/single-promise.js +40 -33
  29. package/dist/esm/utils/uuid.js +2 -2
  30. package/package.json +13 -6
  31. package/src/auth/apis.ts +135 -158
  32. package/src/captcha/captcha.ts +71 -78
  33. package/src/index.ts +13 -14
  34. package/src/oauth2client/interface.ts +5 -5
  35. package/src/oauth2client/models.ts +38 -38
  36. package/src/oauth2client/oauth2client.ts +255 -268
  37. package/src/utils/function/single-promise.ts +22 -21
  38. package/src/utils/uuid.ts +4 -4
  39. 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._fnPromiseMap.get(key);
13
- if (!result) {
14
- result = new Promise<any>(async (resolve, reject) => {
15
- try {
16
- // The idle promise must be run to prevent _fnPromiseMap from
17
- // storing the current promise function.
18
- await this._runIdlePromise();
19
- const fnResult: Promise<T> = fn();
20
- resolve(await fnResult);
21
- } catch (error) {
22
- reject(error);
23
- } finally {
24
- this._fnPromiseMap.delete(key);
25
- }
26
- });
27
- this._fnPromiseMap.set(key, result);
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 _runIdlePromise(): Promise<void> {
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 == 'x' ? r : (r & 0x3) | 0x8;
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
- }