@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
@@ -1,175 +0,0 @@
1
- interface BaseRequest {
2
- client_id?: string;
3
- }
4
-
5
- export interface SignInRequest extends BaseRequest {
6
- username?: string;
7
- password?: string;
8
- verification_code?: string;
9
- verification_token?: string;
10
- }
11
-
12
- export interface SignInWithProviderRequest extends BaseRequest {
13
- provider_token: string;
14
- }
15
-
16
- export interface SignUpRequest extends BaseRequest {
17
- phone_number?: string;
18
- email?: string;
19
-
20
- verification_code?: string;
21
- verification_token?: string;
22
- provider_token?: string;
23
-
24
- password?: string;
25
- name?: string;
26
- gender?: string;
27
- picture?: string;
28
- locale?: string;
29
- }
30
-
31
- export interface GetVerificationRequest extends BaseRequest {
32
- phone_number?: string;
33
- email?: string;
34
- target?: string | 'ANY';
35
- usage?: string;
36
- }
37
-
38
- export interface GetVerificationResponse {
39
- verification_id?: string;
40
- is_user?: boolean | false;
41
- }
42
-
43
- export interface VerifyResponse {
44
- verification_token?: string;
45
- }
46
-
47
- export interface VerifyRequest extends BaseRequest {
48
- verification_code: string;
49
- verification_id?: string;
50
- }
51
-
52
- export interface ProviderBindRequest {
53
- provider_token: string;
54
- }
55
-
56
- export interface GrantProviderTokenRequest extends BaseRequest {
57
- provider_id: string;
58
- provider_redirect_uri?: string;
59
- provider_code?: string;
60
- provider_access_token?: string;
61
- provider_id_token?: string;
62
- }
63
-
64
- export interface GrantProviderTokenResponse {
65
- provider_token: string;
66
- expires_in: number;
67
- }
68
-
69
- export interface PatchProviderTokenRequest extends BaseRequest {
70
- provider_token: string;
71
- provider_params: {
72
- encryptedData: string;
73
- iv: string;
74
- };
75
- }
76
-
77
- export interface PatchProviderTokenResponse {
78
- provider_token: string;
79
- expires_in: number;
80
- provider_profile: ProviderProfile;
81
- }
82
-
83
- export interface GenProviderRedirectUriRequest {
84
- provider_id: string;
85
- provider_redirect_uri: string;
86
- state: string;
87
- other_params?: {
88
- sign_out_uri?: string;
89
- };
90
- }
91
-
92
- export interface GenProviderRedirectUriResponse {
93
- uri: string;
94
- signout_uri?: string;
95
- }
96
-
97
- export interface BindWithProviderRequest extends BaseRequest {
98
- provider_token: string;
99
- }
100
-
101
- export interface BindWithProviderRequest {
102
- provider_token: string;
103
- }
104
-
105
- export interface UserProfileProvider {
106
- id?: string;
107
- provider_user_id?: string;
108
- name?: string;
109
- }
110
-
111
- export interface UserProfile {
112
- name?: string;
113
- picture?: string;
114
- username?: string;
115
- email?: string;
116
- email_verified?: boolean;
117
- phone_number?: string;
118
- providers?: [UserProfileProvider];
119
- gender?: string;
120
- birthdate?: string;
121
- zoneinfo?: string;
122
- locale?: string;
123
- created_from?: string;
124
- }
125
-
126
- export type UserInfo = UserProfile;
127
-
128
- export interface ProviderProfile {
129
- provider_id: string;
130
- phone_number?: string;
131
- }
132
-
133
- export interface TransByProviderRequest {
134
- provider_token: string;
135
- }
136
-
137
- export interface GrantTokenRequest extends BaseRequest {
138
- client_secret?: string;
139
- code?: string;
140
- grant_type?: string;
141
- redirect_uri?: string;
142
- nonce?: string;
143
- refresh_token?: string;
144
- scope?: string;
145
- }
146
-
147
- export interface UnbindProviderRequest extends BaseRequest {
148
- provider_id: string;
149
- }
150
-
151
- export interface CheckPasswordrRequest extends BaseRequest {
152
- password: string;
153
- }
154
-
155
- export interface BindPhoneRequest extends BaseRequest {
156
- phone_number: string;
157
- sudo_token: string;
158
- verification_token: string;
159
- }
160
-
161
- export interface SetPasswordRequest extends BaseRequest {
162
- new_password: string;
163
- sudo_token: string;
164
- }
165
-
166
- export interface ChangeBindedProviderRequest extends BaseRequest {
167
- trans_token: string;
168
- provider_id: string;
169
- }
170
-
171
- export type ChangeBindedProviderResponse = BaseRequest
172
-
173
- export interface QueryUserProfileReq extends BaseRequest {
174
- appended_params: string;
175
- }
@@ -1,217 +0,0 @@
1
- import {SimpleStorage, RequestFunction} from '../oauth2client/interface';
2
- import {AuthClientRequestOptions} from "../oauth2client/models";
3
- import {defaultStorage} from "../oauth2client/oauth2client";
4
-
5
- export interface CaptchaOptions {
6
- clientId: string
7
- request: RequestFunction;
8
- storage: SimpleStorage;
9
- // 打开网页并通过URL回调获取 CaptchaToken,针对不通的平台,该函数可以自定义实现, 默认集成浏览器端认证
10
- openURIWithCallback?: OpenURIWithCallbackFuction;
11
- }
12
-
13
- type OpenURIWithCallbackFuction = (url: string) => Promise<CaptchaToken>;
14
-
15
- export interface CaptchaToken {
16
- captcha_token: string
17
- expires_in: number
18
- expires_at?: Date | null;
19
- }
20
-
21
- export interface CaptchaRequestOptions extends AuthClientRequestOptions {
22
- withCaptcha?: boolean;
23
- }
24
-
25
- export interface GetCaptchaResponse {
26
- captcha_token?: string
27
- expires_in?: number
28
- url?: string
29
- }
30
-
31
- const GET_CAPTCHA_URL = '/auth/v1/captcha/init'
32
-
33
- export class Captcha {
34
- private _config: CaptchaOptions;
35
- private _tokenSectionName: string;
36
-
37
- /**
38
- * constructor
39
- * @param {CaptchaOptions} opts
40
- */
41
- constructor(opts: CaptchaOptions) {
42
- if (!opts.openURIWithCallback) {
43
- opts.openURIWithCallback = this._getDefaultOpenURIWithCallback()
44
- }
45
- if (!opts.storage) {
46
- opts.storage = defaultStorage
47
- }
48
- this._config = opts
49
- this._tokenSectionName = 'captcha_' + opts.clientId
50
- }
51
-
52
- /**
53
- * request http like simple fetch api, exp:request('/v1/user/me', {withCredentials:true})
54
- * @param {string} url
55
- * @param {AuthClientRequestOptions} options
56
- */
57
- public async request<T>(
58
- url: string,
59
- options?: CaptchaRequestOptions,
60
- ): Promise<T> {
61
- if (!options) {
62
- options = {};
63
- }
64
- if (!options.method) {
65
- options.method = 'GET'
66
- }
67
- const state = options.method + ":" + url
68
- let reqURL = url;
69
- if (options.withCaptcha) {
70
- reqURL = await this._appendCaptchaTokenToURL(url, state, false);
71
- }
72
- try {
73
- return this._config.request<T>(reqURL, options)
74
- } catch (err) {
75
- if (err.error === 'captcha_required' || err.error === 'captcha_invalid') {
76
- url = await this._appendCaptchaTokenToURL(url, state, err.error === 'captcha_invalid')
77
- return this._config.request<T>(url, options)
78
- } else {
79
- return Promise.reject(err)
80
- }
81
- }
82
- }
83
-
84
- private _getDefaultOpenURIWithCallback(): OpenURIWithCallbackFuction {
85
- if (window.location.search.indexOf('__captcha') > 0) {
86
- document.body.style.display = 'none';
87
- }
88
- if (document.getElementById('captcha_panel_wrap') === null) {
89
- var elementDiv = document.createElement('div');
90
- elementDiv.style.cssText =
91
- 'background-color: rgba(0, 0, 0, 0.7);position: fixed;left: 0px;right: 0px;top: 0px;bottom: 0px;padding: 9vw 0 0 0;display: none;z-index:100;';
92
- elementDiv.setAttribute('id', 'captcha_panel_wrap');
93
- document.body.appendChild(elementDiv);
94
- }
95
- return this._defaultOpenURIWithCallback
96
- }
97
-
98
- /**
99
- * 默认通过浏览器打开网页并获取回调
100
- */
101
- private async _defaultOpenURIWithCallback(url: string): Promise<CaptchaToken> {
102
- const target = document.getElementById('captcha_panel_wrap'),
103
- iframe = document.createElement('iframe')
104
- target.innerHTML = '';
105
- iframe.setAttribute('src', url)
106
- iframe.setAttribute('id', 'review-panel-iframe')
107
- iframe.style.cssText = 'min-width:355px;display:block;height:355px;margin:0 auto;background-color: rgb(255, 255, 255);border: none;';
108
- target.appendChild(iframe);
109
- target.style.display = 'block';
110
- return new Promise<CaptchaToken>((resolve, reject) => {
111
- iframe.onload = function () {
112
- try {
113
- var windowLocation = window.location;
114
- var iframeLocation = iframe.contentWindow.location;
115
- if (
116
- iframeLocation.host +
117
- iframeLocation.pathname ===
118
- windowLocation.host +
119
- windowLocation.pathname
120
- ) {
121
- target.style.display = 'none';
122
- const iframeUrlParams = new URLSearchParams(iframeLocation.search);
123
- const captchToken = iframeUrlParams.get('captcha_token');
124
- if (captchToken) {
125
- return resolve({
126
- captcha_token: captchToken,
127
- expires_in: Number(iframeUrlParams.get('expires_in'))
128
- })
129
- }
130
- return reject({
131
- error: iframeUrlParams.get('error'),
132
- error_description: iframeUrlParams.get('error_description')
133
- })
134
- } else {
135
- target.style.display = 'block';
136
- }
137
- } catch (error) {
138
- target.style.display = 'block';
139
- }
140
- };
141
- })
142
- }
143
- /**
144
- * _getCaptchaToken 获取captchaToken
145
- */
146
- private async _getCaptchaToken(forceNewToken: boolean, state: string): Promise<string> {
147
- if (!forceNewToken) {
148
- // 如果本地存在,则直接返回
149
- const captchaToken = await this._findCaptchaToken()
150
- if (captchaToken) {
151
- return captchaToken
152
- }
153
- }
154
- const redirectURL = window.location.origin + window.location.pathname + "?__captcha=on"
155
- const captchaTokenResp = await this._config.request<GetCaptchaResponse>(GET_CAPTCHA_URL, {
156
- method: 'POST',
157
- body: {
158
- client_id: this._config.clientId,
159
- redirect_uri: redirectURL,
160
- state: state
161
- },
162
- withCredentials: false,
163
- })
164
- if (captchaTokenResp.captcha_token) {
165
- const captchaToken = {
166
- captcha_token: captchaTokenResp.captcha_token,
167
- expires_in: captchaTokenResp.expires_in,
168
- }
169
- this._saveCaptchaToken(captchaToken)
170
- return captchaTokenResp.captcha_token
171
- }
172
- const captchaToken = await this._config.openURIWithCallback(captchaTokenResp.url)
173
- this._saveCaptchaToken(captchaToken)
174
- return captchaToken.captcha_token
175
- }
176
-
177
- private async _appendCaptchaTokenToURL(url: string, state: string, forceNewToken: boolean): Promise<string> {
178
- const captchaToken = await this._getCaptchaToken(forceNewToken, state);
179
- if (url.indexOf("?") > 0) {
180
- url += "&captcha_token=" + captchaToken
181
- } else {
182
- url += "?captcha_token=" + captchaToken
183
- }
184
- return url
185
- }
186
-
187
- private async _saveCaptchaToken(token: CaptchaToken) {
188
- token.expires_at = new Date(
189
- Date.now() + (token.expires_in - 10) * 1000,
190
- );
191
- const tokenStr: string = JSON.stringify(token);
192
- await this._config.storage.setItem(this._tokenSectionName, tokenStr);
193
- }
194
-
195
- private async _findCaptchaToken(): Promise<string> {
196
- const tokenStr: string = await this._config.storage.getItem(
197
- this._tokenSectionName,
198
- );
199
- if (tokenStr !== undefined && tokenStr !== null) {
200
- try {
201
- const captchaToken = JSON.parse(tokenStr);
202
- if (captchaToken && captchaToken.expires_at) {
203
- captchaToken.expires_at = new Date(captchaToken.expires_at);
204
- }
205
- const isExpired = captchaToken.expires_at < new Date();
206
- if (isExpired) {
207
- return null
208
- }
209
- return captchaToken.captcha_token
210
- } catch (error) {
211
- await this._config.storage.removeItem(this._tokenSectionName);
212
- return null
213
- }
214
- }
215
- return null
216
- }
217
- }
package/src/index.ts DELETED
@@ -1,24 +0,0 @@
1
- export {Syntax, ErrorType} from './oauth2client/consts';
2
-
3
- export {
4
- defaultStorage,
5
- defaultRequest,
6
- ToResponseErrorOptions,
7
- toResponseError,
8
- generateRequestId,
9
- OAuth2Client,
10
- } from './oauth2client/oauth2client';
11
-
12
- export {AuthClient, SimpleStorage} from './oauth2client/interface';
13
-
14
- export {
15
- Credentials,
16
- ResponseError,
17
- OAuth2ClientOptions,
18
- AuthClientRequestOptions,
19
- } from './oauth2client/models';
20
-
21
- export {AuthOptions, Auth} from './auth/apis';
22
-
23
- import * as authModels from './auth/models';
24
- export {authModels};
@@ -1,69 +0,0 @@
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
- }
@@ -1,44 +0,0 @@
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
- }
@@ -1,61 +0,0 @@
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
- }
@@ -1,40 +0,0 @@
1
- /**
2
- * Single Promise
3
- */
4
- export class SinglePromise {
5
- /**
6
- * Run single promise.
7
- * @param {string} key
8
- * @param {Function} fn
9
- * @return {Promise<T>}
10
- */
11
- 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);
28
- }
29
- return result;
30
- }
31
- /**
32
- * Run idle promise.
33
- * @return {Promise<void>}
34
- */
35
- private _runIdlePromise(): Promise<void> {
36
- return Promise.resolve();
37
- }
38
-
39
- private _fnPromiseMap: Map<string, Promise<any>> = new Map();
40
- }
package/src/utils/uuid.ts DELETED
@@ -1,11 +0,0 @@
1
- /**
2
- * Generate uuidv4 string.
3
- * @return {string}
4
- */
5
- export function uuidv4(): string {
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
- });
11
- }
package/tsconfig.json DELETED
@@ -1,44 +0,0 @@
1
- {
2
- "compileOnSave": true,
3
- "compilerOptions": {
4
- "allowSyntheticDefaultImports": true,
5
- "declaration": true,
6
- "esModuleInterop": true,
7
- "experimentalDecorators": true,
8
- "emitDecoratorMetadata": true,
9
- "module": "commonjs",
10
- "noFallthroughCasesInSwitch": true,
11
- "noUnusedLocals": true,
12
- "noUnusedParameters": true,
13
- "outDir": "dist",
14
- "rootDir": "src",
15
- "pretty": true,
16
- "noImplicitAny": false,
17
- "removeComments": true,
18
- "skipLibCheck": true,
19
- "strictBindCallApply": true,
20
- "declarationMap": false,
21
- "inlineSourceMap": true,
22
- "inlineSources": true,
23
- "target": "es5",
24
- "moduleResolution": "node",
25
- "typeRoots": [
26
- "node_modules/@types"
27
- ],
28
- "types": [
29
- "node"
30
- ],
31
- "lib": [
32
- "es2015",
33
- "dom"
34
- ]
35
- },
36
- "include": [
37
- "src/**/*.ts",
38
- "package.json"
39
- ],
40
- "exclude": [
41
- "node_modules",
42
- "dist"
43
- ]
44
- }