@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,5 +0,0 @@
1
- export declare class SinglePromise {
2
- run<T>(key: string, fn: () => Promise<T>): Promise<T>;
3
- private _runIdlePromise;
4
- private _fnPromiseMap;
5
- }
@@ -1,89 +0,0 @@
1
- "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
- var __generator = (this && this.__generator) || function (thisArg, body) {
12
- var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
13
- return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
14
- function verb(n) { return function (v) { return step([n, v]); }; }
15
- function step(op) {
16
- if (f) throw new TypeError("Generator is already executing.");
17
- while (_) try {
18
- if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
19
- if (y = 0, t) op = [op[0] & 2, t.value];
20
- switch (op[0]) {
21
- case 0: case 1: t = op; break;
22
- case 4: _.label++; return { value: op[1], done: false };
23
- case 5: _.label++; y = op[1]; op = [0]; continue;
24
- case 7: op = _.ops.pop(); _.trys.pop(); continue;
25
- default:
26
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
27
- if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
28
- if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
29
- if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
30
- if (t[2]) _.ops.pop();
31
- _.trys.pop(); continue;
32
- }
33
- op = body.call(thisArg, _);
34
- } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
35
- if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
36
- }
37
- };
38
- Object.defineProperty(exports, "__esModule", { value: true });
39
- exports.SinglePromise = void 0;
40
- var SinglePromise = (function () {
41
- function SinglePromise() {
42
- this._fnPromiseMap = new Map();
43
- }
44
- SinglePromise.prototype.run = function (key, fn) {
45
- return __awaiter(this, void 0, void 0, function () {
46
- var result;
47
- var _this = this;
48
- return __generator(this, function (_a) {
49
- result = this._fnPromiseMap.get(key);
50
- if (!result) {
51
- result = new Promise(function (resolve, reject) { return __awaiter(_this, void 0, void 0, function () {
52
- var fnResult, _a, error_1;
53
- return __generator(this, function (_b) {
54
- switch (_b.label) {
55
- case 0:
56
- _b.trys.push([0, 3, 4, 5]);
57
- return [4, this._runIdlePromise()];
58
- case 1:
59
- _b.sent();
60
- fnResult = fn();
61
- _a = resolve;
62
- return [4, fnResult];
63
- case 2:
64
- _a.apply(void 0, [_b.sent()]);
65
- return [3, 5];
66
- case 3:
67
- error_1 = _b.sent();
68
- reject(error_1);
69
- return [3, 5];
70
- case 4:
71
- this._fnPromiseMap.delete(key);
72
- return [7];
73
- case 5: return [2];
74
- }
75
- });
76
- }); });
77
- this._fnPromiseMap.set(key, result);
78
- }
79
- return [2, result];
80
- });
81
- });
82
- };
83
- SinglePromise.prototype._runIdlePromise = function () {
84
- return Promise.resolve();
85
- };
86
- return SinglePromise;
87
- }());
88
- exports.SinglePromise = SinglePromise;
89
- //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic2luZ2xlLXByb21pc2UuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi8uLi9zcmMvdXRpbHMvZnVuY3Rpb24vc2luZ2xlLXByb21pc2UudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6Ijs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7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iAgLyoqXG4gICAqIFJ1biBpZGxlIHByb21pc2UuXG4gICAqIEByZXR1cm4ge1Byb21pc2U8dm9pZD59XG4gICAqL1xuICBwcml2YXRlIF9ydW5JZGxlUHJvbWlzZSgpOiBQcm9taXNlPHZvaWQ+IHtcbiAgICByZXR1cm4gUHJvbWlzZS5yZXNvbHZlKCk7XG4gIH1cblxuICBwcml2YXRlIF9mblByb21pc2VNYXA6IE1hcDxzdHJpbmcsIFByb21pc2U8YW55Pj4gPSBuZXcgTWFwKCk7XG59XG4iXX0=
@@ -1 +0,0 @@
1
- export declare function uuidv4(): string;
@@ -1,12 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.uuidv4 = void 0;
4
- function uuidv4() {
5
- return 'xxxxxxxxxxxx4xxxyxxxxxxxxxxxxxxx'.replace(/[xy]/g, function (c) {
6
- var r = (Math.random() * 16) | 0;
7
- var v = c == 'x' ? r : (r & 0x3) | 0x8;
8
- return v.toString(16);
9
- });
10
- }
11
- exports.uuidv4 = uuidv4;
12
- //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoidXVpZC5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uL3NyYy91dGlscy91dWlkLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7OztBQUlBLFNBQWdCLE1BQU07SUFDcEIsT0FBTyxrQ0FBa0MsQ0FBQyxPQUFPLENBQUMsT0FBTyxFQUFFLFVBQUMsQ0FBQztRQUMzRCxJQUFNLENBQUMsR0FBRyxDQUFDLElBQUksQ0FBQyxNQUFNLEVBQUUsR0FBRyxFQUFFLENBQUMsR0FBRyxDQUFDLENBQUM7UUFDbkMsSUFBTSxDQUFDLEdBQUcsQ0FBQyxJQUFJLEdBQUcsQ0FBQyxDQUFDLENBQUMsQ0FBQyxDQUFDLENBQUMsQ0FBQyxDQUFDLENBQUMsR0FBRyxHQUFHLENBQUMsR0FBRyxHQUFHLENBQUM7UUFDekMsT0FBTyxDQUFDLENBQUMsUUFBUSxDQUFDLEVBQUUsQ0FBQyxDQUFDO0lBQ3hCLENBQUMsQ0FBQyxDQUFDO0FBQ0wsQ0FBQztBQU5ELHdCQU1DIiwic291cmNlc0NvbnRlbnQiOlsiLyoqXG4gKiBHZW5lcmF0ZSB1dWlkdjQgc3RyaW5nLlxuICogQHJldHVybiB7c3RyaW5nfVxuICovXG5leHBvcnQgZnVuY3Rpb24gdXVpZHY0KCk6IHN0cmluZyB7XG4gIHJldHVybiAneHh4eHh4eHh4eHh4NHh4eHl4eHh4eHh4eHh4eHh4eHgnLnJlcGxhY2UoL1t4eV0vZywgKGMpID0+IHtcbiAgICBjb25zdCByID0gKE1hdGgucmFuZG9tKCkgKiAxNikgfCAwO1xuICAgIGNvbnN0IHYgPSBjID09ICd4JyA/IHIgOiAociAmIDB4MykgfCAweDg7XG4gICAgcmV0dXJuIHYudG9TdHJpbmcoMTYpO1xuICB9KTtcbn1cbiJdfQ==
package/src/auth/apis.ts DELETED
@@ -1,484 +0,0 @@
1
- 'use strict';
2
-
3
- import {ApiUrls} from './consts';
4
- import {
5
- GetVerificationRequest,
6
- GetVerificationResponse,
7
- UserProfile,
8
- UserInfo,
9
- SignInRequest,
10
- SignUpRequest,
11
- VerifyRequest,
12
- VerifyResponse,
13
- GenProviderRedirectUriRequest,
14
- GenProviderRedirectUriResponse,
15
- GrantProviderTokenRequest,
16
- GrantProviderTokenResponse,
17
- PatchProviderTokenRequest,
18
- PatchProviderTokenResponse,
19
- SignInWithProviderRequest,
20
- BindWithProviderRequest,
21
- TransByProviderRequest,
22
- GrantTokenRequest,
23
- UserProfileProvider,
24
- UnbindProviderRequest,
25
- CheckPasswordrRequest,
26
- BindPhoneRequest,
27
- SetPasswordRequest,
28
- ChangeBindedProviderRequest,
29
- ChangeBindedProviderResponse,
30
- QueryUserProfileReq,
31
- } from './models';
32
- import {SimpleStorage, RequestFunction} from '../oauth2client/interface';
33
- import {OAuth2Client, defaultStorage} from '../oauth2client/oauth2client';
34
- import {Credentials} from '../oauth2client/models';
35
- import {Captcha} from '../captcha/captcha';
36
-
37
- export interface AuthOptions {
38
- apiOrigin: string;
39
- clientId: string;
40
- credentialsClient?: OAuth2Client;
41
- request?: RequestFunction;
42
- storage?: SimpleStorage;
43
- }
44
-
45
- /**
46
- * Auth
47
- */
48
- export class Auth {
49
- private _config: AuthOptions;
50
-
51
- /**
52
- * constructor
53
- * @param {AuthOptions} opts
54
- */
55
- constructor(opts: AuthOptions) {
56
- let request = opts.request;
57
- let oAuth2Client = opts.credentialsClient;
58
- if (!oAuth2Client) {
59
- const initOptions = {
60
- apiOrigin: opts.apiOrigin,
61
- clientId: opts.clientId,
62
- storage: opts.storage,
63
- };
64
- oAuth2Client = new OAuth2Client(initOptions);
65
- }
66
- if (!request) {
67
- const baseRequest = oAuth2Client.request.bind(oAuth2Client);
68
- const captcha = new Captcha({
69
- clientId: opts.clientId,
70
- request: baseRequest,
71
- storage: opts.storage,
72
- })
73
- request = captcha.request.bind(captcha)
74
- }
75
- this._config = {
76
- apiOrigin: opts.apiOrigin,
77
- clientId: opts.clientId,
78
- request: request,
79
- credentialsClient: oAuth2Client,
80
- storage: opts.storage || defaultStorage,
81
- };
82
- }
83
-
84
- /**
85
- * Sign in.
86
- * @param {SignInRequest} params A SignInRequest Object.
87
- * @return {Promise<Credentials>} A Promise<Credentials> object.
88
- */
89
- public async signIn(params: SignInRequest): Promise<Credentials> {
90
- params.client_id = this._config.clientId;
91
- const credentials: Credentials = await this._config.request<Credentials>(
92
- ApiUrls.AUTH_SIGN_IN_URL,
93
- {
94
- method: 'POST',
95
- body: params
96
- },
97
- );
98
- await this._config.credentialsClient.setCredentials(credentials);
99
- return Promise.resolve(credentials);
100
- }
101
-
102
- /**
103
- * Sign in Anonymously
104
- * @return {Promise<Credentials>} A Promise<Credentials> object.
105
- */
106
- public async signInAnonymously(): Promise<Credentials> {
107
- const credentials: Credentials = await this._config.request<Credentials>(
108
- ApiUrls.AUTH_SIGN_IN_ANONYMOUSLY_URL,
109
- {
110
- method: 'POST',
111
- body: {
112
- client_id: this._config.clientId
113
- }
114
- },
115
- );
116
- await this._config.credentialsClient.setCredentials(credentials);
117
- return Promise.resolve(credentials);
118
- }
119
-
120
- /**
121
- * Sign up.
122
- * @param {SignUpRequest} params A SignUpRequest Object.
123
- * @return {Promise<Credentials>} A Promise<Credentials> object.
124
- */
125
- protected async signUp(params: SignUpRequest): Promise<Credentials> {
126
- params.client_id = this._config.clientId;
127
- const data: Credentials = await this._config.request<Credentials>(
128
- ApiUrls.AUTH_SIGN_UP_URL,
129
- {
130
- method: 'POST',
131
- body: params,
132
- },
133
- );
134
- await this._config.credentialsClient.setCredentials(data);
135
- return Promise.resolve(data);
136
- }
137
-
138
- /**
139
- * Sign out.
140
- * @return {Object} A Promise<void> object.
141
- */
142
- public async signOut(): Promise<void> {
143
- const accessToken: string = await this._config.credentialsClient.getAccessToken();
144
- const data = await this._config.request<void>(ApiUrls.AUTH_REVOKE_URL, {
145
- method: 'POST',
146
- body: {
147
- client_id: this._config.clientId,
148
- token: accessToken,
149
- },
150
- });
151
- await this._config.credentialsClient.setCredentials();
152
- return Promise.resolve(data);
153
- }
154
-
155
- /**
156
- * Get the verification.
157
- * @param {GetVerificationRequest} params A GetVerificationRequest Object.
158
- * @return {Promise<GetVerificationResponse>} A Promise<GetVerificationResponse> object.
159
- */
160
- public async getVerification(
161
- params: GetVerificationRequest,
162
- ): Promise<GetVerificationResponse> {
163
- params.client_id = this._config.clientId;
164
- return this._config.request<GetVerificationResponse>(
165
- ApiUrls.VERIFICATION_URL,
166
- {
167
- method: 'POST',
168
- body: params,
169
- withCaptcha: true
170
- },
171
- );
172
- }
173
-
174
- /**
175
- * Verify the code
176
- * @param {VerifyRequest} params A VerifyRequest Object.
177
- * @return {Promise<VerifyResponse>} A Promise<VerifyResponse> object.
178
- */
179
- public async verify(params: VerifyRequest): Promise<VerifyResponse> {
180
- params.client_id = this._config.clientId;
181
- return this._config.request<VerifyResponse>(ApiUrls.VERIFY_URL, {
182
- method: 'POST',
183
- body: params,
184
- });
185
- }
186
-
187
- /**
188
- * Gen provider redirect uri.
189
- * @param {GenProviderRedirectUriRequest} params A GenProviderRedirectUriRequest object.
190
- * @return {Promise<GenProviderRedirectUriResponse>} A Promise<GenProviderRedirectUriResponse> object.
191
- */
192
- public async genProviderRedirectUri(
193
- params: GenProviderRedirectUriRequest,
194
- ): Promise<GenProviderRedirectUriResponse> {
195
- let url = `${ApiUrls.PROVIDER_URI_URL}?client_id=${
196
- this._config.clientId
197
- }&provider_id=${params.provider_id}&redirect_uri=${encodeURIComponent(
198
- params.provider_redirect_uri,
199
- )}&state=${params.state}`;
200
- const other_params = params.other_params;
201
- if (other_params) {
202
- if (
203
- typeof other_params.sign_out_uri === 'string' &&
204
- other_params.sign_out_uri.length > 0
205
- ) {
206
- url += `&other_params[sign_out_uri]=${other_params.sign_out_uri}`;
207
- }
208
- }
209
- return this._config.request<GenProviderRedirectUriResponse>(url, {
210
- method: 'GET',
211
- });
212
- }
213
-
214
- /**
215
- * Grant provider token.
216
- * @param {GrantProviderTokenRequest} params A GrantProviderTokenRequest object.
217
- * @return {Promise<GrantProviderTokenResponse>} A Promise<GrantProviderTokenResponse> object.
218
- */
219
- public async grantProviderToken(
220
- params: GrantProviderTokenRequest,
221
- ): Promise<GrantProviderTokenResponse> {
222
- params.client_id = this._config.clientId;
223
- return this._config.request<GrantProviderTokenResponse>(
224
- ApiUrls.PROVIDER_TOKEN_URL,
225
- {
226
- method: 'POST',
227
- body: params,
228
- },
229
- );
230
- }
231
-
232
- /**
233
- * Grant provider token.
234
- * @param {PatchProviderTokenRequest} params A PatchProviderTokenRequest object.
235
- * @return {Promise<PatchProviderTokenResponse>} A Promise<PatchProviderTokenResponse> object.
236
- */
237
- public async patchProviderToken(
238
- params: PatchProviderTokenRequest,
239
- ): Promise<PatchProviderTokenResponse> {
240
- params.client_id = this._config.clientId;
241
- return this._config.request<PatchProviderTokenResponse>(
242
- ApiUrls.PROVIDER_TOKEN_URL,
243
- {
244
- method: 'PATCH',
245
- body: params,
246
- },
247
- );
248
- }
249
-
250
- /**
251
- * Signin with provider request.
252
- * @param {SignInWithProviderRequest} params A SignInWithProviderRequest object.
253
- * @return {Promise<Credentials>} A Promise<Credentials> object.
254
- */
255
- public async signInWithProvider(
256
- params: SignInWithProviderRequest,
257
- ): Promise<Credentials> {
258
- params.client_id = this._config.clientId;
259
- const credentials: Credentials = await this._config.request<Credentials>(
260
- ApiUrls.AUTH_SIGN_IN_WITH_PROVIDER_URL,
261
- {
262
- method: 'POST',
263
- body: params,
264
- },
265
- );
266
- await this._config.credentialsClient.setCredentials(credentials);
267
- return Promise.resolve(credentials);
268
- }
269
-
270
- /**
271
- * Bind with provider
272
- * @param {BindWithProviderRequest} params A BindWithProviderRequest object.
273
- * @return {Promise<void>} A Promise<any> object.
274
- */
275
- public async bindWithProvider(
276
- params: BindWithProviderRequest,
277
- ): Promise<void> {
278
- params.client_id = this._config.clientId;
279
- return this._config.request<any>(ApiUrls.PROVIDER_BIND_URL, {
280
- method: 'POST',
281
- body: params,
282
- withCredentials: true,
283
- });
284
- }
285
-
286
- /**
287
- * Get the user profile.
288
- * @return {Promise<UserProfile>} A Promise<UserProfile> object.
289
- */
290
- public async getUserProfile(): Promise<UserProfile> {
291
- return this.getUserInfo();
292
- }
293
-
294
- /**
295
- * Get the user info.
296
- * @return {Promise<UserInfo>} A Promise<UserProfile> object.
297
- */
298
- public async getUserInfo(): Promise<UserInfo> {
299
- return this._config.request<UserInfo>(ApiUrls.USER_ME_URL, {
300
- method: 'GET',
301
- withCredentials: true,
302
- });
303
- }
304
-
305
- /**
306
- * hasLoginState check if has login state
307
- * @return {Promise<boolean>} A Promise<boolean> object.
308
- */
309
- public async hasLoginState(): Promise<boolean> {
310
- try {
311
- await this._config.credentialsClient.getAccessToken()
312
- return true
313
- } catch (error) {
314
- return false
315
- }
316
- }
317
-
318
- /**
319
- * Trans by provider.
320
- * @param {TransByProviderRequest} params A TransByProviderRequest object.
321
- * @return {Promise<Credentials>} A Promise<Credentials> object.
322
- */
323
- public async transByProvider(
324
- params: TransByProviderRequest,
325
- ): Promise<Credentials> {
326
- return this._config.request<Credentials>(
327
- ApiUrls.USER_TRANS_BY_PROVIDER_URL,
328
- {
329
- method: 'PATCH',
330
- body: params,
331
- withCredentials: true,
332
- },
333
- );
334
- }
335
-
336
- /**
337
- * Grant token.
338
- * @param {GrantTokenRequest} params A GrantTokenRequest object.
339
- * @return {Promise<Credentials>} A Promise<Credentials> object.
340
- */
341
- public async grantToken(params: GrantTokenRequest): Promise<Credentials> {
342
- params.client_id = this._config.clientId;
343
- return this._config.request<Credentials>(ApiUrls.AUTH_TOKEN_URL, {
344
- method: 'POST',
345
- body: params,
346
- });
347
- }
348
-
349
- /**
350
- * Get the provide list.
351
- * @return {Promise<UserProfileProvider>} A Promise<UserProfileProvider> object.
352
- */
353
- public async getProviders(): Promise<UserProfileProvider> {
354
- return this._config.request<UserProfileProvider>(ApiUrls.PROVIDER_LIST, {
355
- method: 'GET',
356
- withCredentials: true,
357
- });
358
- }
359
-
360
- /**
361
- * unbind provider.
362
- * @param {UnbindProviderRequest} params
363
- * @return {Promise<any>}
364
- */
365
- public async unbindProvider(params: UnbindProviderRequest): Promise<void> {
366
- params.client_id = this._config.clientId;
367
- return this._config.request<any>(
368
- `${ApiUrls.PROVIDER_UNBIND_URL}/${params.provider_id}`,
369
- {
370
- method: 'DELETE',
371
- withCredentials: true,
372
- },
373
- );
374
- }
375
-
376
- /**
377
- * check Password.
378
- * @param {CheckPasswordrRequest} params
379
- * @return {Promise<any>}
380
- */
381
- public async checkPassword(params: CheckPasswordrRequest): Promise<void> {
382
- return this._config.request<any>(`${ApiUrls.CHECK_PWD_URL}`, {
383
- method: 'POST',
384
- withCredentials: true,
385
- body: params,
386
- });
387
- }
388
-
389
- /**
390
- * check Password.
391
- * @param {CheckPasswordrRequest} params
392
- * @return {Promise<any>}
393
- */
394
- public async bindPhone(params: BindPhoneRequest): Promise<void> {
395
- return this._config.request<any>(`${ApiUrls.BIND_PHONE_URL}`, {
396
- method: 'PATCH',
397
- withCredentials: true,
398
- body: params,
399
- });
400
- }
401
-
402
- /**
403
- * Set Password.
404
- * @param {SetPasswordrRequest} params
405
- * @return {Promise<any>}
406
- */
407
- public async setPassword(params: SetPasswordRequest): Promise<void> {
408
- return this._config.request<any>(`${ApiUrls.AUTH_SET_PASSWORD}`, {
409
- method: 'PATCH',
410
- withCredentials: true,
411
- body: params,
412
- });
413
- }
414
-
415
- /**
416
- * Get the current user verification.
417
- * @param {GetVerificationRequest} params A GetVerificationRequest Object.
418
- * @return {Promise<GetVerificationResponse>} A Promise<GetVerificationResponse> object.
419
- */
420
- public async getCurUserVerification(
421
- params: GetVerificationRequest,
422
- ): Promise<GetVerificationResponse> {
423
- params.client_id = this._config.clientId;
424
- params.target = 'CUR_USER';
425
- return this._config.request<GetVerificationResponse>(
426
- ApiUrls.VERIFICATION_URL,
427
- {
428
- method: 'POST',
429
- body: params,
430
- withCredentials: true,
431
- withCaptcha: true
432
- },
433
- );
434
- }
435
-
436
- /**
437
- * change binded provider.
438
- * @param {GetVerificationRequest} params A GetVerificationRequest Object.
439
- * @return {Promise<GetVerificationResponse>} A Promise<GetVerificationResponse> object.
440
- */
441
- public async changeBindedProvider(
442
- params: ChangeBindedProviderRequest,
443
- ): Promise<ChangeBindedProviderResponse> {
444
- params.client_id = this._config.clientId;
445
- return this._config.request<ChangeBindedProviderResponse>(
446
- `${ApiUrls.PROVIDER_LIST}/${params.provider_id}/trans`,
447
- {
448
- method: 'POST',
449
- body: {
450
- provider_trans_token: params.trans_token,
451
- },
452
- withCredentials: true,
453
- },
454
- );
455
- }
456
-
457
- /**
458
- * Patch the user profile.
459
- * @param {UserProfile} params A UserProfile Object.
460
- * @return {Promise<UserProfile>} A Promise<UserProfile> object.
461
- */
462
- public async setUserProfile(params: UserProfile): Promise<UserProfile> {
463
- return this._config.request<UserProfile>(ApiUrls.USER_PRIFILE_URL, {
464
- method: 'PATCH',
465
- body: params,
466
- withCredentials: true,
467
- });
468
- }
469
-
470
- /**
471
- * Patch the user profile.
472
- * @param {QueryUserProfileReq} appended_params A QueryUserProfileReq Object.
473
- * @return {Promise<UserProfile>} A Promise<UserProfile> object.
474
- */
475
- public async queryUserProfile(
476
- appended_params: QueryUserProfileReq,
477
- ): Promise<UserProfile> {
478
- const url = `${ApiUrls.USER_QUERY_URL}${appended_params}`;
479
- return this._config.request<UserProfile>(url, {
480
- method: 'GET',
481
- withCredentials: true,
482
- });
483
- }
484
- }
@@ -1,30 +0,0 @@
1
- export enum ApiUrls {
2
- AUTH_SIGN_IN_URL = '/auth/v1/signin',
3
- AUTH_SIGN_IN_ANONYMOUSLY_URL = '/auth/v1/signin/anonymously',
4
- AUTH_SIGN_IN_WITH_PROVIDER_URL = '/auth/v1/signin/with/provider',
5
- AUTH_SIGN_UP_URL = '/auth/v1/signup',
6
- AUTH_TOKEN_URL = '/auth/v1/token',
7
- AUTH_REVOKE_URL = '/auth/v1/revoke',
8
- PROVIDER_BIND_URL = '/auth/v1/user/provider/bind',
9
- PROVIDER_TOKEN_URL = '/auth/v1/provider/token',
10
- PROVIDER_URI_URL = '/auth/v1/provider/uri',
11
- USER_ME_URL = '/auth/v1/user/me',
12
- USER_QUERY_URL = '/auth/v1/user/query',
13
- USER_PRIFILE_URL = '/auth/v1/user/profile',
14
- USER_TRANS_BY_PROVIDER_URL = '/auth/v1/user/trans/by/provider',
15
- VERIFICATION_URL = '/auth/v1/verification',
16
- VERIFY_URL = '/auth/v1/verification/verify',
17
- PROVIDER_LIST = '/auth/v1/user/provider',
18
- PROVIDER_UNBIND_URL = '/auth/v1/user/provider',
19
- CHECK_PWD_URL = '/auth/v1/user/sudo',
20
- BIND_PHONE_URL = '/auth/v1/user/contact',
21
- AUTH_SET_PASSWORD = '/auth/v1/user/password',
22
- }
23
-
24
- export enum VerificationUsages {
25
- REGISTER = 'REGISTER',
26
- SIGN_IN = 'SIGN_IN',
27
- PASSWORD_RESET = 'PASSWORD_RESET',
28
- EMAIL_ADDRESS_CHANGE = 'EMAIL_ADDRESS_CHANGE',
29
- PHONE_NUMBER_CHANGE = 'PHONE_NUMBER_CHANGE',
30
- }