@cloudbase/oauth 1.2.0-beta → 2.2.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 (125) hide show
  1. package/.eslintignore +2 -0
  2. package/.eslintrc +26 -0
  3. package/CHANGELOG.md +30 -0
  4. package/Dockerfile +15 -0
  5. package/README.md +183 -0
  6. package/_exmaple/assets/scripts/function/function.ts +99 -0
  7. package/_exmaple/assets/scripts/index.ts +101 -0
  8. package/_exmaple/assets/scripts/request.ts +11 -0
  9. package/_exmaple/index.html +15 -0
  10. package/_exmaple/package.json +33 -0
  11. package/_exmaple/tsconfig.json +71 -0
  12. package/_exmaple/typings.d.ts +0 -0
  13. package/_exmaple/webpack.config.js +42 -0
  14. package/dist/cjs/auth/apis.d.ts +55 -0
  15. package/dist/cjs/auth/apis.js +568 -0
  16. package/{auth → dist/cjs/auth}/consts.d.ts +9 -21
  17. package/dist/cjs/auth/consts.js +61 -0
  18. package/dist/cjs/auth/models.d.ts +354 -0
  19. package/dist/cjs/auth/models.js +3 -0
  20. package/dist/cjs/captcha/captcha.d.ts +35 -0
  21. package/dist/cjs/captcha/captcha.js +267 -0
  22. package/dist/cjs/index.d.ts +14 -0
  23. package/dist/cjs/index.js +63 -0
  24. package/{oauthclient → dist/cjs/oauth2client}/consts.d.ts +22 -1
  25. package/dist/cjs/oauth2client/consts.js +73 -0
  26. package/dist/cjs/oauth2client/interface.d.ts +15 -0
  27. package/dist/cjs/oauth2client/interface.js +10 -0
  28. package/dist/cjs/oauth2client/models.d.ts +47 -0
  29. package/dist/cjs/oauth2client/models.js +3 -0
  30. package/dist/cjs/oauth2client/oauth2client.d.ts +71 -0
  31. package/dist/cjs/oauth2client/oauth2client.js +640 -0
  32. package/dist/cjs/utils/function/single-promise.d.ts +5 -0
  33. package/dist/cjs/utils/function/single-promise.js +89 -0
  34. package/dist/cjs/utils/uuid.d.ts +1 -0
  35. package/dist/cjs/utils/uuid.js +12 -0
  36. package/dist/esm/auth/apis.d.ts +55 -0
  37. package/dist/esm/auth/apis.js +566 -0
  38. package/dist/esm/auth/consts.d.ts +54 -0
  39. package/dist/esm/auth/consts.js +58 -0
  40. package/dist/esm/auth/models.d.ts +354 -0
  41. package/dist/esm/auth/models.js +1 -0
  42. package/dist/esm/captcha/captcha.d.ts +35 -0
  43. package/dist/esm/captcha/captcha.js +264 -0
  44. package/dist/esm/index.d.ts +14 -0
  45. package/dist/esm/index.js +32 -0
  46. package/dist/esm/oauth2client/consts.d.ts +67 -0
  47. package/dist/esm/oauth2client/consts.js +70 -0
  48. package/dist/esm/oauth2client/interface.d.ts +15 -0
  49. package/dist/esm/oauth2client/interface.js +7 -0
  50. package/dist/esm/oauth2client/models.d.ts +47 -0
  51. package/dist/esm/oauth2client/models.js +1 -0
  52. package/dist/esm/oauth2client/oauth2client.d.ts +71 -0
  53. package/dist/esm/oauth2client/oauth2client.js +636 -0
  54. package/dist/esm/utils/function/single-promise.d.ts +5 -0
  55. package/dist/esm/utils/function/single-promise.js +86 -0
  56. package/dist/esm/utils/uuid.d.ts +1 -0
  57. package/dist/esm/utils/uuid.js +8 -0
  58. package/package.json +27 -14
  59. package/publish.sh +2 -0
  60. package/src/auth/apis.ts +642 -0
  61. package/src/auth/consts.ts +57 -0
  62. package/src/auth/models.ts +444 -0
  63. package/src/captcha/captcha.ts +222 -0
  64. package/src/index.ts +49 -0
  65. package/src/oauth2client/consts.ts +69 -0
  66. package/src/oauth2client/interface.ts +57 -0
  67. package/src/oauth2client/models.ts +61 -0
  68. package/src/oauth2client/oauth2client.ts +620 -0
  69. package/src/utils/function/single-promise.ts +40 -0
  70. package/src/utils/uuid.ts +11 -0
  71. package/tsconfig.esm.json +44 -0
  72. package/tsconfig.json +44 -0
  73. package/wiki/README.md +75 -0
  74. package/app/index.d.ts +0 -29
  75. package/app/index.js +0 -50
  76. package/app/index.js.map +0 -1
  77. package/app/internal.d.ts +0 -12
  78. package/app/internal.js +0 -25
  79. package/app/internal.js.map +0 -1
  80. package/app/openuri.d.ts +0 -20
  81. package/app/openuri.js +0 -106
  82. package/app/openuri.js.map +0 -1
  83. package/app/request.d.ts +0 -19
  84. package/app/request.js +0 -52
  85. package/app/request.js.map +0 -1
  86. package/app/storage.d.ts +0 -41
  87. package/app/storage.js +0 -35
  88. package/app/storage.js.map +0 -1
  89. package/auth/consts.js +0 -79
  90. package/auth/consts.js.map +0 -1
  91. package/auth/index.d.ts +0 -242
  92. package/auth/index.js +0 -550
  93. package/auth/index.js.map +0 -1
  94. package/auth/models.d.ts +0 -284
  95. package/auth/models.js +0 -4
  96. package/auth/models.js.map +0 -1
  97. package/captcha/index.d.ts +0 -45
  98. package/captcha/index.js +0 -135
  99. package/captcha/index.js.map +0 -1
  100. package/function/index.d.ts +0 -38
  101. package/function/index.js +0 -80
  102. package/function/index.js.map +0 -1
  103. package/index.d.ts +0 -8
  104. package/index.js +0 -17
  105. package/index.js.map +0 -1
  106. package/oauthclient/consts.js +0 -53
  107. package/oauthclient/consts.js.map +0 -1
  108. package/oauthclient/index.d.ts +0 -18
  109. package/oauthclient/index.js +0 -21
  110. package/oauthclient/index.js.map +0 -1
  111. package/oauthclient/interface.d.ts +0 -29
  112. package/oauthclient/interface.js +0 -10
  113. package/oauthclient/interface.js.map +0 -1
  114. package/oauthclient/models.d.ts +0 -40
  115. package/oauthclient/models.js +0 -3
  116. package/oauthclient/models.js.map +0 -1
  117. package/oauthclient/oauthclient.d.ts +0 -146
  118. package/oauthclient/oauthclient.js +0 -414
  119. package/oauthclient/oauthclient.js.map +0 -1
  120. package/utils/promise.d.ts +0 -18
  121. package/utils/promise.js +0 -48
  122. package/utils/promise.js.map +0 -1
  123. package/utils/uuid.d.ts +0 -5
  124. package/utils/uuid.js +0 -16
  125. package/utils/uuid.js.map +0 -1
@@ -0,0 +1,69 @@
1
+ export enum Syntax {
2
+ CLIENT_ID = 'client_id',
3
+ CLIENT_SECRET = 'client_secret',
4
+ RESPONSE_TYPE = 'response_type',
5
+ SCOPE = 'scope',
6
+ STATE = 'state',
7
+ REDIRECT_URI = 'redirect_uri',
8
+ ERROR = 'error',
9
+ ERROR_DESCRIPTION = 'error_description',
10
+ ERROR_URI = 'error_uri',
11
+ GRANT_TYPE = 'grant_type',
12
+ CODE = 'code',
13
+ ACCESS_TOKEN = 'access_token',
14
+ TOKEN_TYPE = 'token_type',
15
+ EXPIRES_IN = 'expires_in',
16
+ USERNAME = 'username',
17
+ PASSWORD = 'password',
18
+ REFRESH_TOKEN = 'refresh_token',
19
+ }
20
+
21
+ export enum ErrorType {
22
+ UNREACHABLE = 'unreachable',
23
+ LOCAL = 'local',
24
+ CANCELLED = 'cancelled',
25
+ UNKNOWN = 'unknown',
26
+ INVALID_ARGUMENT = 'invalid_argument',
27
+ DEADLINE_EXCEEDED = 'deadline_exceeded',
28
+ NOT_FOUND = 'not_found',
29
+ ALREADY_EXISTS = 'already_exists',
30
+ PERMISSION_DENIED = 'permission_denied',
31
+ UNAUTHENTICATED = 'unauthenticated',
32
+ RESOURCE_EXHAUSTED = 'resource_exhausted',
33
+ FAILED_PRECONDITION = 'failed_precondition',
34
+ ABORTED = 'aborted',
35
+ OUT_OF_RANGE = 'out_of_range',
36
+ UNIMPLEMENTED = 'unimplemented',
37
+ INTERNAL = 'internal',
38
+ UNAVAILABLE = 'unavailable',
39
+ DATA_LOSS = 'data_loss',
40
+ // CommonError
41
+ CAPTCHA_REQUIRED = 'captcha_required',
42
+ CAPTCHA_INVALID = 'captcha_invalid',
43
+ INVALID_PASSWORD = 'invalid_password',
44
+ INVALID_STATUS = 'invalid_status',
45
+ USER_PENDING = 'user_pending',
46
+ USER_BLOCKED = 'user_blocked',
47
+ INVALID_VERIFICATION_CODE = 'invalid_verification_code',
48
+ TWO_FACTOR_REQUIRED = 'two_factor_required',
49
+ INVALID_TWO_FACTOR = 'invalid_two_factor',
50
+ INVALID_TWO_FACTOR_RECOVERY = 'invalid_two_factor_recovery',
51
+ UNDER_REVIEW = 'under_review',
52
+ INVALID_REQUEST = 'invalid_request',
53
+ UNAUTHORIZED_CLIENT = 'unauthorized_client',
54
+ ACCESS_DENIED = 'access_denied',
55
+ UNSUPPORTED_RESPONSE_TYPE = 'unsupported_response_type',
56
+ INVALID_SCOPE = 'invalid_scope',
57
+ INVALID_GRANT = 'invalid_grant',
58
+ SERVER_ERROR = 'server_error',
59
+ TEMPORARILY_UNAVAILABLE = 'temporarily_unavailable',
60
+ INTERACTION_REQUIRED = 'interaction_required',
61
+ LOGIN_REQUIRED = 'login_required',
62
+ ACCOUNT_SELECTION_REQUIRED = 'account_selection_required',
63
+ CONSENT_REQUIRED = 'consent_required',
64
+ INVALID_REQUEST_URI = 'invalid_request_uri',
65
+ INVALID_REQUEST_OBJECT = 'invalid_request_object',
66
+ REQUEST_NOT_SUPPORTED = 'request_not_supported',
67
+ REQUEST_URI_NOT_SUPPORTED = 'request_uri_not_supported',
68
+ REGISTRATION_NOT_SUPPORTED = 'registration_not_supported',
69
+ }
@@ -0,0 +1,57 @@
1
+ import { Credentials, AuthClientRequestOptions } from './models';
2
+
3
+ /**
4
+ * the interface for the Oauth2Client
5
+ */
6
+ export abstract class AuthClient {
7
+ /**
8
+ * Sets the auth credentials.
9
+ */
10
+ abstract setCredentials(credentials?: Credentials): void;
11
+ /**
12
+ * Provides an alternative fetch api request implementation with auth credentials
13
+ * if options.withCredentials:true, the request will auto add Authorization: Bearer <AccessToken> in the request
14
+ * error:
15
+ * - unreachable, the network error or response is not json
16
+ * - unauthenticated: has no validate access token
17
+ */
18
+ abstract request: RequestFunction;
19
+
20
+ /**
21
+ * get the current accessToken from AuthClient, you can use this to detect login status
22
+ * error:
23
+ * - unauthenticated: has no validate access token
24
+ */
25
+ abstract getAccessToken(): Promise<string>;
26
+ }
27
+
28
+ export type RequestFunction = <T>(url: string, options?: AuthClientRequestOptions) => Promise<T>;
29
+
30
+ /** An interface of the Simple Web Storage API */
31
+ export interface SimpleStorage {
32
+ /**
33
+ * value = storage[key]
34
+ */
35
+ getItem: (key: string) => Promise<string | null>;
36
+ /**
37
+ * delete storage[key]
38
+ */
39
+ removeItem: (key: string) => Promise<void>;
40
+ /**
41
+ * storage[key] = value
42
+ */
43
+ setItem: (key: string, value: string) => Promise<void>;
44
+
45
+ /**
46
+ * value = storage[key]
47
+ */
48
+ getItemSync: (key: string) => string | null;
49
+ /**
50
+ * delete storage[key]
51
+ */
52
+ removeItemSync: (key: string) => void;
53
+ /**
54
+ * storage[key] = value
55
+ */
56
+ setItemSync: (key: string, value: string) => void;
57
+ }
@@ -0,0 +1,61 @@
1
+ import {SimpleStorage} from './interface';
2
+ import {ErrorType} from './consts';
3
+
4
+ /** Credentials **/
5
+ export interface Credentials {
6
+ token_type?: string | null;
7
+ access_token?: string | null;
8
+ refresh_token?: string | null;
9
+ scope?: string | null;
10
+ expires_in?: number | null;
11
+ expires_at?: Date | null;
12
+ sub?: string | null;
13
+ }
14
+
15
+ /** An Error For all concern **/
16
+ export interface ResponseError {
17
+ error: ErrorType;
18
+ error_description?: string | null;
19
+ error_uri?: string | null;
20
+ details?: any | null;
21
+ }
22
+
23
+ export interface RequestOptions {
24
+ body?: any | null;
25
+ headers?: any | null;
26
+ method?: string;
27
+
28
+ [key: string]: any;
29
+ }
30
+
31
+ export type RequestFunction = <T>(
32
+ url: string,
33
+ options?: RequestOptions,
34
+ ) => Promise<T>;
35
+
36
+ export interface AuthClientRequestOptions extends RequestOptions {
37
+ headers?: {
38
+ 'x-request-id'?: string;
39
+ [key: string]: any;
40
+ } | null;
41
+ withCredentials?: boolean;
42
+ retry?: number;
43
+
44
+ [key: string]: any;
45
+ }
46
+
47
+ export interface OAuth2ClientOptions {
48
+ devMode?: boolean;
49
+ apiOrigin: string;
50
+ clientId: string;
51
+ // default value is 1,min value is 0, max value is 5
52
+ retry?: number;
53
+ baseRequest?: <T>(url: string, options?: RequestOptions) => Promise<T>;
54
+ // Storage, default is localStorage, setItem(k, v), getItem(k),removeItem(k)
55
+ storage?: SimpleStorage;
56
+ clientSecret?: string;
57
+ refreshTokenFunc?: (refreshToken?: string) => Promise<Credentials>;
58
+ // set the token in url query instead of header
59
+ tokenInURL?: boolean;
60
+ headers?: { [key: string]: string };
61
+ }