@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
@@ -0,0 +1,142 @@
1
+ import { ErrorType } from './consts';
2
+ import { AuthClient } from './interface';
3
+ import { Storage } from "../app";
4
+ import { Credentials, ResponseError, OAuth2ClientOptions, AuthClientRequestOptions } from './models';
5
+ export interface ToResponseErrorOptions {
6
+ error?: ErrorType;
7
+ error_description?: string | null;
8
+ error_uri?: string | null;
9
+ details?: any | null;
10
+ }
11
+ export declare const toResponseError: (error: ResponseError | Error, options?: ToResponseErrorOptions) => ResponseError;
12
+ /**
13
+ * Generate request id.
14
+ * @return {string}
15
+ */
16
+ export declare function generateRequestId(): string;
17
+ interface LocalCredentialsOptions {
18
+ tokenSectionName: string;
19
+ storage: Storage;
20
+ }
21
+ /**
22
+ * Local credentials.
23
+ * Local credentials, with memory cache and storage cache.
24
+ * If the memory cache expires, the storage cache is automatically loaded.
25
+ */
26
+ export declare class LocalCredentials {
27
+ private _tokenSectionName;
28
+ private _storage;
29
+ private _credentials;
30
+ private _singlePromise;
31
+ /**
32
+ * constructor
33
+ * @param {LocalCredentialsOptions} options
34
+ */
35
+ constructor(options: LocalCredentialsOptions);
36
+ /**
37
+ * setCredentials Provides an alternative fetch api request implementation with auth credentials
38
+ * @param {Credentials} credentials
39
+ */
40
+ setCredentials(credentials?: Credentials): Promise<void>;
41
+ /**
42
+ * Get credentials.
43
+ * @return {Promise<Credentials | null>}
44
+ */
45
+ getCredentials(): Promise<Credentials | null>;
46
+ /**
47
+ * Get storage credentials.
48
+ */
49
+ private _getStorageCredentials;
50
+ }
51
+ /**
52
+ * OAuth2Client
53
+ */
54
+ export declare class OAuth2Client implements AuthClient {
55
+ private static _defaultRetry;
56
+ private static _minRetry;
57
+ private static _maxRetry;
58
+ private static _retryInterval;
59
+ private _retry;
60
+ private _baseRequest;
61
+ private _basicAuth?;
62
+ private _localCredentials;
63
+ private _storage;
64
+ private _deviceID?;
65
+ private _tokenInURL?;
66
+ private _refreshTokenFunc;
67
+ private _headers?;
68
+ private _singlePromise;
69
+ /**
70
+ * constructor
71
+ * @param {OAuth2ClientOptions} options
72
+ */
73
+ constructor(options: OAuth2ClientOptions);
74
+ /**
75
+ * setCredentials Provides an alternative fetch api request implementation with auth credentials
76
+ * @param {Credentials} credentials
77
+ * @return {Promise<void>}
78
+ */
79
+ setCredentials(credentials?: Credentials): Promise<void>;
80
+ /**
81
+ * getAccessToken return a validate access token
82
+ */
83
+ getAccessToken(): Promise<string>;
84
+ /**
85
+ * request http like simple fetch api, exp:request('/v1/user/me', {withCredentials:true})
86
+ * @param {string} url
87
+ * @param {AuthClientRequestOptions} options
88
+ */
89
+ request<T>(url: string, options?: AuthClientRequestOptions): Promise<T>;
90
+ /**
91
+ * Check retry value.
92
+ * @param {number} retry
93
+ * @return {number}
94
+ */
95
+ private _checkRetry;
96
+ /**
97
+ * Format retry value.
98
+ * @param {number} retry
99
+ * @param {number} defaultVale
100
+ * @return {number}
101
+ */
102
+ private _formatRetry;
103
+ /**
104
+ * Sleep.
105
+ * @param {number} ms
106
+ * @return {Promise<void>}
107
+ */
108
+ private _sleep;
109
+ /**
110
+ * Refresh expired token.
111
+ * @param {Credentials} credentials
112
+ * @return {Promise<Credentials>}
113
+ */
114
+ private _refreshToken;
115
+ /**
116
+ * anonymous signIn
117
+ * @param {Credentials} credentials
118
+ * @return {Promise<Credentials>}
119
+ */
120
+ private _anonymousSignIn;
121
+ /**
122
+ * Default refresh token function.
123
+ * @param {string} refreshToken
124
+ * @return {Promise<Credentials>}
125
+ */
126
+ private _defaultRefreshTokenFunc;
127
+ /**
128
+ * Get credentials.
129
+ */
130
+ private _getCredentials;
131
+ /**
132
+ * Get deviceId
133
+ */
134
+ private _getDeviceId;
135
+ /**
136
+ * Generate unAuthenticated error.
137
+ * @param {string} err
138
+ * @return {Promise<T>}
139
+ */
140
+ private _unAuthenticatedError;
141
+ }
142
+ export {};