@cloudbase/oauth 0.0.2-alpha.0 → 0.1.1-alpha

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 (85) hide show
  1. package/CHANGELOG.md +30 -0
  2. package/README.md +137 -5
  3. package/app/index.d.ts +28 -0
  4. package/app/index.js +54 -0
  5. package/app/index.js.map +1 -0
  6. package/app/internal.d.ts +12 -0
  7. package/app/internal.js +25 -0
  8. package/app/internal.js.map +1 -0
  9. package/app/openuri.d.ts +20 -0
  10. package/app/openuri.js +104 -0
  11. package/app/openuri.js.map +1 -0
  12. package/app/request.d.ts +18 -0
  13. package/app/request.js +44 -0
  14. package/app/request.js.map +1 -0
  15. package/app/storage.d.ts +41 -0
  16. package/app/storage.js +35 -0
  17. package/app/storage.js.map +1 -0
  18. package/{dist/auth → auth}/consts.d.ts +21 -1
  19. package/auth/consts.js +57 -0
  20. package/auth/consts.js.map +1 -0
  21. package/auth/index.d.ts +193 -0
  22. package/auth/index.js +403 -0
  23. package/auth/index.js.map +1 -0
  24. package/{dist/auth → auth}/models.d.ts +35 -22
  25. package/auth/models.js +3 -0
  26. package/auth/models.js.map +1 -0
  27. package/captcha/index.d.ts +45 -0
  28. package/captcha/index.js +133 -0
  29. package/captcha/index.js.map +1 -0
  30. package/index.d.ts +8 -0
  31. package/index.js +17 -0
  32. package/index.js.map +1 -0
  33. package/{dist/oauth2client → oauthclient}/consts.d.ts +1 -22
  34. package/oauthclient/consts.js +53 -0
  35. package/oauthclient/consts.js.map +1 -0
  36. package/oauthclient/index.d.ts +18 -0
  37. package/oauthclient/index.js +21 -0
  38. package/oauthclient/index.js.map +1 -0
  39. package/oauthclient/interface.d.ts +25 -0
  40. package/oauthclient/interface.js +10 -0
  41. package/oauthclient/interface.js.map +1 -0
  42. package/{dist/oauth2client → oauthclient}/models.d.ts +5 -13
  43. package/oauthclient/models.js +3 -0
  44. package/oauthclient/models.js.map +1 -0
  45. package/oauthclient/oauthclient.d.ts +142 -0
  46. package/{src/oauth2client/oauth2client.ts → oauthclient/oauthclient.js} +113 -265
  47. package/oauthclient/oauthclient.js.map +1 -0
  48. package/package.json +20 -19
  49. package/utils/single-promise.d.ts +18 -0
  50. package/utils/single-promise.js +48 -0
  51. package/utils/single-promise.js.map +1 -0
  52. package/utils/uuid.d.ts +5 -0
  53. package/utils/uuid.js +16 -0
  54. package/utils/uuid.js.map +1 -0
  55. package/.eslintignore +0 -2
  56. package/.eslintrc +0 -26
  57. package/dist/auth/apis.d.ts +0 -40
  58. package/dist/auth/apis.js +0 -422
  59. package/dist/auth/consts.js +0 -35
  60. package/dist/auth/models.js +0 -3
  61. package/dist/captcha/captcha.d.ts +0 -35
  62. package/dist/captcha/captcha.js +0 -262
  63. package/dist/index.d.ts +0 -7
  64. package/dist/index.js +0 -38
  65. package/dist/oauth2client/consts.js +0 -73
  66. package/dist/oauth2client/interface.d.ts +0 -12
  67. package/dist/oauth2client/interface.js +0 -10
  68. package/dist/oauth2client/models.js +0 -3
  69. package/dist/oauth2client/oauth2client.d.ts +0 -64
  70. package/dist/oauth2client/oauth2client.js +0 -585
  71. package/dist/utils/function/single-promise.d.ts +0 -5
  72. package/dist/utils/function/single-promise.js +0 -89
  73. package/dist/utils/uuid.d.ts +0 -1
  74. package/dist/utils/uuid.js +0 -12
  75. package/src/auth/apis.ts +0 -484
  76. package/src/auth/consts.ts +0 -30
  77. package/src/auth/models.ts +0 -175
  78. package/src/captcha/captcha.ts +0 -217
  79. package/src/index.ts +0 -24
  80. package/src/oauth2client/consts.ts +0 -69
  81. package/src/oauth2client/interface.ts +0 -44
  82. package/src/oauth2client/models.ts +0 -61
  83. package/src/utils/function/single-promise.ts +0 -40
  84. package/src/utils/uuid.ts +0 -11
  85. package/tsconfig.json +0 -44
package/package.json CHANGED
@@ -1,30 +1,31 @@
1
1
  {
2
2
  "name": "@cloudbase/oauth",
3
- "version": "0.0.2-alpha.0",
4
- "description": "cloudbase javascript sdk auth componets",
3
+ "version": "0.1.1-alpha",
4
+ "description": "auth apis for cloudbase",
5
+ "author": "xbase",
5
6
  "main": "./dist/index.js",
6
- "module": "dist/esm/index.js",
7
- "publishConfig": {
8
- "access": "public"
7
+ "types": "./dist/index.d.ts",
8
+ "typesVersions": {
9
+ ">=4.1": {
10
+ "*": [
11
+ "ts4.1/*"
12
+ ]
13
+ }
9
14
  },
15
+ "license": "MIT",
10
16
  "scripts": {
11
17
  "eslint": "eslint \"{src,__tests__}/**/*.ts\"",
12
18
  "eslint:fix": "eslint --fix \"{src,__tests__}/**/*.ts\"",
13
- "clean": "rimraf dist",
19
+ "clean": "rm -rf dist",
14
20
  "compile": "tsc",
15
- "build": "yarn clean && yarn compile"
21
+ "build": "yarn clean && yarn compile && cp package.json dist/ && cp *.md dist/"
16
22
  },
17
- "license": "MIT",
18
- "devDependencies": {
19
- "@typescript-eslint/eslint-plugin": "^2.24.0",
20
- "@typescript-eslint/parser": "^2.24.0",
21
- "eslint": "^6.8.0",
22
- "eslint-config-google": "^0.14.0",
23
- "eslint-config-prettier": "^6.10.0",
24
- "eslint-plugin-prettier": "^3.1.2",
25
- "prettier": "^1.19.1",
26
- "rimraf": "^3.0.0",
27
- "typescript": "^3.8.3"
23
+ "engines": {
24
+ "node": "^12.14.1 || >=14.0.0"
28
25
  },
29
- "gitHead": "c462902b6702463670d27acb88ebccf93dbd51cd"
26
+ "devDependencies": {
27
+ "@typescript-eslint/eslint-plugin": "^4.30.0",
28
+ "@typescript-eslint/parser": "^4.30.0",
29
+ "eslint": "^7.32.0"
30
+ }
30
31
  }
@@ -0,0 +1,18 @@
1
+ /**
2
+ * Single Promise
3
+ */
4
+ export declare class SinglePromise {
5
+ /**
6
+ * Run single promise.
7
+ * @param {string} key
8
+ * @param {Function} fn
9
+ * @return {Promise<T>}
10
+ */
11
+ run<T>(key: string, fn: () => Promise<T>): Promise<T>;
12
+ /**
13
+ * Run idle promise.
14
+ * @return {Promise<void>}
15
+ */
16
+ private _runIdlePromise;
17
+ private _fnPromiseMap;
18
+ }
@@ -0,0 +1,48 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.SinglePromise = void 0;
4
+ /**
5
+ * Single Promise
6
+ */
7
+ class SinglePromise {
8
+ constructor() {
9
+ this._fnPromiseMap = new Map();
10
+ }
11
+ /**
12
+ * Run single promise.
13
+ * @param {string} key
14
+ * @param {Function} fn
15
+ * @return {Promise<T>}
16
+ */
17
+ async run(key, fn) {
18
+ let result = this._fnPromiseMap.get(key);
19
+ if (!result) {
20
+ result = new Promise(async (resolve, reject) => {
21
+ try {
22
+ // The idle promise must be run to prevent _fnPromiseMap from
23
+ // storing the current promise function.
24
+ await this._runIdlePromise();
25
+ const fnResult = fn();
26
+ resolve(await fnResult);
27
+ }
28
+ catch (error) {
29
+ reject(error);
30
+ }
31
+ finally {
32
+ this._fnPromiseMap.delete(key);
33
+ }
34
+ });
35
+ this._fnPromiseMap.set(key, result);
36
+ }
37
+ return result;
38
+ }
39
+ /**
40
+ * Run idle promise.
41
+ * @return {Promise<void>}
42
+ */
43
+ _runIdlePromise() {
44
+ return Promise.resolve();
45
+ }
46
+ }
47
+ exports.SinglePromise = SinglePromise;
48
+ //# sourceMappingURL=single-promise.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"single-promise.js","sourceRoot":"","sources":["../../src/utils/single-promise.ts"],"names":[],"mappings":";;;AAAA;;GAEG;AACH,MAAa,aAAa;IAA1B;QAoCY,kBAAa,GAA8B,IAAI,GAAG,EAAE,CAAC;IACjE,CAAC;IApCG;;;;;OAKG;IACH,KAAK,CAAC,GAAG,CAAI,GAAW,EAAE,EAAoB;QAC1C,IAAI,MAAM,GAAiB,IAAI,CAAC,aAAa,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;QACvD,IAAI,CAAC,MAAM,EAAE;YACT,MAAM,GAAG,IAAI,OAAO,CAAM,KAAK,EAAE,OAAO,EAAE,MAAM,EAAE,EAAE;gBAChD,IAAI;oBACA,6DAA6D;oBAC7D,wCAAwC;oBACxC,MAAM,IAAI,CAAC,eAAe,EAAE,CAAC;oBAC7B,MAAM,QAAQ,GAAe,EAAE,EAAE,CAAC;oBAClC,OAAO,CAAC,MAAM,QAAQ,CAAC,CAAC;iBAC3B;gBAAC,OAAO,KAAK,EAAE;oBACZ,MAAM,CAAC,KAAK,CAAC,CAAC;iBACjB;wBAAS;oBACN,IAAI,CAAC,aAAa,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;iBAClC;YACL,CAAC,CAAC,CAAC;YACH,IAAI,CAAC,aAAa,CAAC,GAAG,CAAC,GAAG,EAAE,MAAM,CAAC,CAAC;SACvC;QACD,OAAO,MAAM,CAAC;IAClB,CAAC;IAED;;;OAGG;IACK,eAAe;QACnB,OAAO,OAAO,CAAC,OAAO,EAAE,CAAC;IAC7B,CAAC;CAGJ;AArCD,sCAqCC"}
@@ -0,0 +1,5 @@
1
+ /**
2
+ * Generate uuidv4 string.
3
+ * @return {string}
4
+ */
5
+ export declare function uuidv4(): string;
package/utils/uuid.js ADDED
@@ -0,0 +1,16 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.uuidv4 = void 0;
4
+ /**
5
+ * Generate uuidv4 string.
6
+ * @return {string}
7
+ */
8
+ function uuidv4() {
9
+ return 'xxxxxxxxxxxx4xxxyxxxxxxxxxxxxxxx'.replace(/[xy]/g, (c) => {
10
+ const r = (Math.random() * 16) | 0;
11
+ const v = c == 'x' ? r : (r & 0x3) | 0x8;
12
+ return v.toString(16);
13
+ });
14
+ }
15
+ exports.uuidv4 = uuidv4;
16
+ //# sourceMappingURL=uuid.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"uuid.js","sourceRoot":"","sources":["../../src/utils/uuid.ts"],"names":[],"mappings":";;;AAAA;;;GAGG;AACH,SAAgB,MAAM;IAClB,OAAO,kCAAkC,CAAC,OAAO,CAAC,OAAO,EAAE,CAAC,CAAC,EAAE,EAAE;QAC7D,MAAM,CAAC,GAAG,CAAC,IAAI,CAAC,MAAM,EAAE,GAAG,EAAE,CAAC,GAAG,CAAC,CAAC;QACnC,MAAM,CAAC,GAAG,CAAC,IAAI,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,GAAG,CAAC,GAAG,GAAG,CAAC;QACzC,OAAO,CAAC,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC;IAC1B,CAAC,CAAC,CAAC;AACP,CAAC;AAND,wBAMC"}
package/.eslintignore DELETED
@@ -1,2 +0,0 @@
1
- dist/
2
- node_modules/
package/.eslintrc DELETED
@@ -1,26 +0,0 @@
1
- {
2
- "extends": [
3
- "eslint-config-alloy/typescript"
4
- ],
5
- "rules": {
6
- "indent": [
7
- "error",
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
- }
@@ -1,40 +0,0 @@
1
- import { GetVerificationRequest, GetVerificationResponse, UserProfile, UserInfo, SignInRequest, SignUpRequest, VerifyRequest, VerifyResponse, GenProviderRedirectUriRequest, GenProviderRedirectUriResponse, GrantProviderTokenRequest, GrantProviderTokenResponse, PatchProviderTokenRequest, PatchProviderTokenResponse, SignInWithProviderRequest, BindWithProviderRequest, TransByProviderRequest, GrantTokenRequest, UserProfileProvider, UnbindProviderRequest, CheckPasswordrRequest, BindPhoneRequest, SetPasswordRequest, ChangeBindedProviderRequest, ChangeBindedProviderResponse, QueryUserProfileReq } from './models';
2
- import { SimpleStorage, RequestFunction } from '../oauth2client/interface';
3
- import { OAuth2Client } from '../oauth2client/oauth2client';
4
- import { Credentials } from '../oauth2client/models';
5
- export interface AuthOptions {
6
- apiOrigin: string;
7
- clientId: string;
8
- credentialsClient?: OAuth2Client;
9
- request?: RequestFunction;
10
- storage?: SimpleStorage;
11
- }
12
- export declare class Auth {
13
- private _config;
14
- constructor(opts: AuthOptions);
15
- signIn(params: SignInRequest): Promise<Credentials>;
16
- signInAnonymously(): Promise<Credentials>;
17
- protected signUp(params: SignUpRequest): Promise<Credentials>;
18
- signOut(): Promise<void>;
19
- getVerification(params: GetVerificationRequest): Promise<GetVerificationResponse>;
20
- verify(params: VerifyRequest): Promise<VerifyResponse>;
21
- genProviderRedirectUri(params: GenProviderRedirectUriRequest): Promise<GenProviderRedirectUriResponse>;
22
- grantProviderToken(params: GrantProviderTokenRequest): Promise<GrantProviderTokenResponse>;
23
- patchProviderToken(params: PatchProviderTokenRequest): Promise<PatchProviderTokenResponse>;
24
- signInWithProvider(params: SignInWithProviderRequest): Promise<Credentials>;
25
- bindWithProvider(params: BindWithProviderRequest): Promise<void>;
26
- getUserProfile(): Promise<UserProfile>;
27
- getUserInfo(): Promise<UserInfo>;
28
- hasLoginState(): Promise<boolean>;
29
- transByProvider(params: TransByProviderRequest): Promise<Credentials>;
30
- grantToken(params: GrantTokenRequest): Promise<Credentials>;
31
- getProviders(): Promise<UserProfileProvider>;
32
- unbindProvider(params: UnbindProviderRequest): Promise<void>;
33
- checkPassword(params: CheckPasswordrRequest): Promise<void>;
34
- bindPhone(params: BindPhoneRequest): Promise<void>;
35
- setPassword(params: SetPasswordRequest): Promise<void>;
36
- getCurUserVerification(params: GetVerificationRequest): Promise<GetVerificationResponse>;
37
- changeBindedProvider(params: ChangeBindedProviderRequest): Promise<ChangeBindedProviderResponse>;
38
- setUserProfile(params: UserProfile): Promise<UserProfile>;
39
- queryUserProfile(appended_params: QueryUserProfileReq): Promise<UserProfile>;
40
- }