@cloudbase/oauth 0.0.5-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 (86) 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 -25
  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/oauthclient/oauthclient.js +399 -0
  47. package/oauthclient/oauthclient.js.map +1 -0
  48. package/package.json +29 -33
  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 -44
  58. package/dist/auth/apis.js +0 -448
  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 -9
  64. package/dist/index.js +0 -234
  65. package/dist/oauth2client/consts.js +0 -73
  66. package/dist/oauth2client/interface.d.ts +0 -15
  67. package/dist/oauth2client/interface.js +0 -10
  68. package/dist/oauth2client/models.js +0 -3
  69. package/dist/oauth2client/oauth2client.d.ts +0 -70
  70. package/dist/oauth2client/oauth2client.js +0 -618
  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 -507
  76. package/src/auth/consts.ts +0 -30
  77. package/src/auth/models.ts +0 -178
  78. package/src/captcha/captcha.ts +0 -217
  79. package/src/index.ts +0 -162
  80. package/src/oauth2client/consts.ts +0 -69
  81. package/src/oauth2client/interface.ts +0 -57
  82. package/src/oauth2client/models.ts +0 -61
  83. package/src/oauth2client/oauth2client.ts +0 -606
  84. package/src/utils/function/single-promise.ts +0 -40
  85. package/src/utils/uuid.ts +0 -11
  86. package/tsconfig.json +0 -44
package/CHANGELOG.md ADDED
@@ -0,0 +1,30 @@
1
+ ## 更新日志
2
+
3
+
4
+ ### 1.3.3beta
5
+
6
+ 1. 三方登录开放 `provider_access_token` 和 `provider_id_token`
7
+
8
+
9
+ ### 1.2.3
10
+
11
+ 1. OAuth2Client 增加 hasCredentials 方法,判断是否存在 credentials(不校验有限性也不触发 refresh token)
12
+ 2. 增加 LocalCredentials 管理 credentials, 简化 OAuth2Client 代码逻辑
13
+
14
+ ### 1.1.3
15
+
16
+ 1. 修复 getAccessToken 方法获取不到 refresh 之后的 token 的 bug
17
+ 2. 增加 SinglePromise 模块
18
+
19
+ ### 1.0.12
20
+
21
+ 1. 添加 ErrorType enum
22
+
23
+ ### 1.0.11
24
+
25
+ 1. OAuth2Client 中 refresh token,如果请求返回的 error 为 invalid_grant 时,删除本地 token
26
+ 2. OAuth2Client 中,对 defaultRequest 的 options 数据进行拷贝,避免修改了传入的参数数据
27
+
28
+ ### 1.0.9
29
+
30
+ 1. 代码格式化
package/README.md CHANGED
@@ -1,4 +1,4 @@
1
- # Oauth
1
+ # xbase-sdk
2
2
 
3
3
  提供 oauth2 的登录相关功能。
4
4
 
@@ -13,9 +13,141 @@ Auth 登录相关模块
13
13
  ### 初始化对象
14
14
 
15
15
  ```typescript
16
- const authOptions = {
17
- apiOrigin: '服务域名',
18
- clientId: '客户端ID',
16
+ import {initializeApp} from '@clodbasesdk/oauth/app';
17
+ import {getAuth} from '@clodbasesdk/oauth/auth';
18
+ export const config = {
19
+ env: 'env-4gh5dh6nf62145a9'
19
20
  };
20
- const auth = new Auth(authOptions);
21
+ const app = initializeApp(config)
22
+ const auth = getAuth(app)
23
+ // 调用API
24
+ const loginState = await auth.hasLoginState()
21
25
  ```
26
+
27
+ ### 账号登录
28
+
29
+ ```typescript
30
+ auth.signIn({
31
+ username: 'test',
32
+ password: 'test',
33
+ });
34
+ ```
35
+
36
+ ### 手机验证码登录/注册
37
+
38
+ ```typescript
39
+ const phoneNumber = '10012341234';
40
+ // 短信验证码
41
+ const verificationCode = '******';
42
+ const verification = await auth.getVerification({
43
+ phone_number: '+86 ' + phoneNumber,
44
+ target: 'ANY',
45
+ });
46
+
47
+ let verifyResult = await auth.verify({
48
+ verification_code: verificationCode,
49
+ verification_id: verification ? verification.verification_id : '',
50
+ });
51
+ let isUser = verification ? verification.is_user : false;
52
+
53
+ let result;
54
+ if (isUser) {
55
+ result = await auth.signIn({
56
+ username: '+86 ' + phoneNumber,
57
+ verification_code: verificationCode,
58
+ verification_token: verifyResult.verification_token,
59
+ });
60
+ } else {
61
+ result = await auth.signUp({
62
+ phone_number: '+86 ' + phoneNumber,
63
+ password: '*******',
64
+ verification_code: verificationCode,
65
+ verification_token: verifyResult.verification_token,
66
+ local: 'zh-cn',
67
+ name: '100****1234',
68
+ });
69
+ }
70
+ ```
71
+
72
+ ### 错误处理
73
+
74
+ ```typescript
75
+ try {
76
+ await auth.verify({
77
+ verification_code: verificationCode,
78
+ verification_id: verification ? verification.verification_id : '',
79
+ });
80
+ } catch (error) {
81
+ if (error && error.error_uri === '/v1/auth/verification/verify') {
82
+ switch (error.error) {
83
+ case 'not_found': {
84
+ result = i18n.translate('error', 'User Not Found');
85
+ break;
86
+ }
87
+ case 'invalid_password': {
88
+ if (error.details !== undefined && error.details.length > 0) {
89
+ result =
90
+ i18n.translate('error', 'Certification failed, you still have') +
91
+ error.details[0].limit_remaining +
92
+ i18n.translate('error', 'chances. You can also') +
93
+ '' +
94
+ i18n.translate('error', 'Reset Login Password') +
95
+ '</a>';
96
+ } else {
97
+ result = i18n.translate('error', 'Password does not match');
98
+ }
99
+ break;
100
+ }
101
+ case 'user_pending': {
102
+ result = i18n.translate('error', 'The account is not activated');
103
+ break;
104
+ }
105
+ case 'user_blocked': {
106
+ result = i18n.translate('error', 'Account has been disabled');
107
+ break;
108
+ }
109
+ case 'invalid_status': {
110
+ if (error.details !== undefined && error.details.length > 0) {
111
+ let s = error.details[0].retry_delay;
112
+ s = s.substring(0, s.length - 1);
113
+ s = parseInt(s);
114
+ result =
115
+ i18n.translate(
116
+ 'error',
117
+ 'The password input error has reached the upper limit and the account will be locked ',
118
+ ) +
119
+ (s < 3600
120
+ ? s / 60 + i18n.translate('error', 'minute')
121
+ : s / 3600 + i18n.translate('error', 'hour'));
122
+ } else {
123
+ result = i18n.translate(
124
+ 'error',
125
+ 'Account has been temporarily locked',
126
+ );
127
+ }
128
+ break;
129
+ }
130
+ case 'invalid_two_factor': {
131
+ result = i18n.translate(
132
+ 'error',
133
+ 'Secondary authentication code does not match or has expired',
134
+ );
135
+ break;
136
+ }
137
+ case 'invalid_two_factor_recovery': {
138
+ result = i18n.translate(
139
+ 'error',
140
+ 'Recovery code does not match or has expired',
141
+ );
142
+ break;
143
+ }
144
+ default: {
145
+ result = i18n.translate('error', 'unknown');
146
+ break;
147
+ }
148
+ }
149
+ }
150
+ }
151
+ ```
152
+
153
+ ## [更新日志](./CHANGELOG.md)
package/app/index.d.ts ADDED
@@ -0,0 +1,28 @@
1
+ import { RequestFn as requestFn, RequestOptions as requestOptions } from "./request";
2
+ import { OpenURIWithCallback as openURIWithCallback } from "./openuri";
3
+ import { Storage as storage } from "./storage";
4
+ export interface Options {
5
+ env: string;
6
+ region?: string;
7
+ apiOrigin?: string;
8
+ clientId?: string;
9
+ clientSecret?: string;
10
+ request?: requestFn;
11
+ storage?: storage;
12
+ openURIWithCallback?: openURIWithCallback;
13
+ }
14
+ export declare function initializeApp(options: Options): App;
15
+ export interface App {
16
+ readonly options: Options;
17
+ }
18
+ export declare class AppImpl implements App {
19
+ private readonly _options;
20
+ private readonly _container;
21
+ constructor(options: Options);
22
+ get options(): Options;
23
+ get container(): Map<string, any>;
24
+ }
25
+ export declare type RequestFn = requestFn;
26
+ export declare type RequestOptions = requestOptions;
27
+ export declare type OpenURIWithCallback = openURIWithCallback;
28
+ export declare type Storage = storage;
package/app/index.js ADDED
@@ -0,0 +1,54 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.AppImpl = exports.initializeApp = void 0;
4
+ const request_1 = require("./request");
5
+ const openuri_1 = require("./openuri");
6
+ const storage_1 = require("./storage");
7
+ function initializeApp(options) {
8
+ return new AppImpl(options);
9
+ }
10
+ exports.initializeApp = initializeApp;
11
+ class AppImpl {
12
+ constructor(options) {
13
+ this._container = new Map();
14
+ if (!options.region) {
15
+ options.region = 'ap-shanghai';
16
+ }
17
+ if (!options.apiOrigin) {
18
+ options.apiOrigin = `https://${options.env}.${options.region}.tcb-api.tencentcloudapi.com`;
19
+ }
20
+ let storageEnv = options.env;
21
+ if (!options.clientId) {
22
+ options.clientId = '';
23
+ }
24
+ else {
25
+ storageEnv = options.clientId;
26
+ }
27
+ if (!options.storage) {
28
+ options.storage = new storage_1.DefaultStorage({ env: storageEnv });
29
+ }
30
+ if (!options.openURIWithCallback) {
31
+ options.openURIWithCallback = openuri_1.defaultOpenURIWithCallback;
32
+ }
33
+ let baseRequest = options.request;
34
+ if (!baseRequest) {
35
+ baseRequest = request_1.defaultRequest;
36
+ }
37
+ const apiOrigin = options.apiOrigin;
38
+ options.request = async (url, options) => {
39
+ if (url.startsWith('/')) {
40
+ url = apiOrigin + url;
41
+ }
42
+ return baseRequest(url, options);
43
+ };
44
+ this._options = options;
45
+ }
46
+ get options() {
47
+ return this._options;
48
+ }
49
+ get container() {
50
+ return this._container;
51
+ }
52
+ }
53
+ exports.AppImpl = AppImpl;
54
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/app/index.ts"],"names":[],"mappings":";;;AAAA,uCAAmG;AACnG,uCAAiG;AACjG,uCAA6D;AAe7D,SAAgB,aAAa,CACzB,OAAgB;IAEhB,OAAO,IAAI,OAAO,CAAC,OAAO,CAAC,CAAC;AAChC,CAAC;AAJD,sCAIC;AAMD,MAAa,OAAO;IAIhB,YAAY,OAAgB;QAFX,eAAU,GAAG,IAAI,GAAG,EAAe,CAAC;QAGjD,IAAI,CAAC,OAAO,CAAC,MAAM,EAAE;YACjB,OAAO,CAAC,MAAM,GAAG,aAAa,CAAA;SACjC;QACD,IAAI,CAAC,OAAO,CAAC,SAAS,EAAE;Y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+ * @param creator - new T
7
+ *
8
+ * @returns the provider for the service with the matching name
9
+ *
10
+ * @internal
11
+ */
12
+ export declare function _getComponent<T>(app: App, name: string, creator: () => T): T;
@@ -0,0 +1,25 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports._getComponent = void 0;
4
+ /**
5
+ *
6
+ * @param app - App instance
7
+ * @param name - service name
8
+ * @param creator - new T
9
+ *
10
+ * @returns the provider for the service with the matching name
11
+ *
12
+ * @internal
13
+ */
14
+ function _getComponent(app, name, creator) {
15
+ const container = app.container;
16
+ let component = container.get(name);
17
+ if (component) {
18
+ return component;
19
+ }
20
+ component = creator();
21
+ container.set(name, component);
22
+ return component;
23
+ }
24
+ exports._getComponent = _getComponent;
25
+ //# sourceMappingURL=internal.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"internal.js","sourceRoot":"","sources":["../../src/app/internal.ts"],"names":[],"mappings":";;;AAEA;;;;;;;;;GASG;AACH,SAAgB,aAAa,CACzB,GAAQ,EACR,IAAY,EACZ,OAAgB;IAEhB,MAAM,SAAS,GAAI,GAAe,CAAC,SAAS,CAAA;IAC5C,IAAI,SAAS,GAAG,SAAS,CAAC,GAAG,CAAC,IAAI,CAAC,CAAA;IACnC,IAAI,SAAS,EAAE;QACX,OAAO,SAAc,CAAA;KACxB;IACD,SAAS,GAAG,OAAO,EAAE,CAAA;IACrB,SAAS,CAAC,GAAG,CAAC,IAAI,EAAE,SAAS,CAAC,CAAA;IAC9B,OAAO,SAAS,CAAA;AACpB,CAAC;AAbD,sCAaC"}
@@ -0,0 +1,20 @@
1
+ export declare type OpenURIWithCallback = (url: string, opts?: OpenURIOptions) => Promise<{
2
+ [key: string]: string;
3
+ }>;
4
+ export interface OpenURIOptions {
5
+ width: string;
6
+ height: string;
7
+ }
8
+ /**
9
+ * default use iframe to open url can return callback
10
+ * for example : open https://example.com/callback?rediret_uri=http://127.0.0.1:8080/
11
+ * the it is done, it will callback http://127.0.0.1:8080/?data1=x&data2=3
12
+ *
13
+ * for example : open https://example.com/callback?rediret_uri=http://127.0.0.1:8080/?__iframe==on
14
+ * window.addEventListener('message', function(e) {
15
+ console.log(e)
16
+ alert('data from domain2 ---> ' + e.data);
17
+ }, false);
18
+ *
19
+ */
20
+ export declare const defaultOpenURIWithCallback: OpenURIWithCallback;
package/app/openuri.js ADDED
@@ -0,0 +1,104 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.defaultOpenURIWithCallback = void 0;
4
+ /**
5
+ * default use iframe to open url can return callback
6
+ * for example : open https://example.com/callback?rediret_uri=http://127.0.0.1:8080/
7
+ * the it is done, it will callback http://127.0.0.1:8080/?data1=x&data2=3
8
+ *
9
+ * for example : open https://example.com/callback?rediret_uri=http://127.0.0.1:8080/?__iframe==on
10
+ * window.addEventListener('message', function(e) {
11
+ console.log(e)
12
+ alert('data from domain2 ---> ' + e.data);
13
+ }, false);
14
+ *
15
+ */
16
+ exports.defaultOpenURIWithCallback = (url, opts) => {
17
+ let iframeTag = '__iframe';
18
+ if (window.location.search.indexOf(iframeTag) > 0) {
19
+ document.body.style.display = 'none';
20
+ }
21
+ if (!opts) {
22
+ opts = {
23
+ width: '355px',
24
+ height: '355px'
25
+ };
26
+ }
27
+ if (document.getElementById('_iframe_panel_wrap') === null) {
28
+ var elementDiv = document.createElement('div');
29
+ elementDiv.style.cssText =
30
+ '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;';
31
+ elementDiv.setAttribute('id', '_iframe_panel_wrap');
32
+ document.body.appendChild(elementDiv);
33
+ }
34
+ const target = document.getElementById('_iframe_panel_wrap'), iframe = document.createElement('iframe');
35
+ target.innerHTML = '';
36
+ const openURL = new URL(url);
37
+ const redirectUri = openURL.searchParams.get('redirect_uri');
38
+ if (redirectUri) {
39
+ const redirectUrl = new URL(redirectUri);
40
+ redirectUrl.searchParams.append(iframeTag, "on");
41
+ openURL.searchParams.set('redirect_uri', redirectUrl.href);
42
+ url = openURL.href;
43
+ }
44
+ iframe.setAttribute('src', url);
45
+ iframe.setAttribute('id', '_iframe_panel_wrap_iframe');
46
+ iframe.style.cssText = `min-width:${opts.width};display:block;height:${opts.height};margin:0 auto;background-color: rgb(255, 255, 255);border: none;`;
47
+ target.appendChild(iframe);
48
+ target.style.display = 'block';
49
+ let callBack = new Callback();
50
+ // handle callback from iframe post message
51
+ window.addEventListener('message', e => {
52
+ if (e.origin == openURL.origin && callBack.callFunc) {
53
+ target.style.display = 'none';
54
+ const data = JSON.parse(e.data);
55
+ try {
56
+ callBack.callFunc(data);
57
+ }
58
+ catch (e) {
59
+ }
60
+ }
61
+ }, false);
62
+ return new Promise((resolve, reject) => {
63
+ callBack.callFunc = data => {
64
+ if (data.error) {
65
+ return reject(data);
66
+ }
67
+ return resolve(data);
68
+ };
69
+ // handle callback from iframe redirect uri
70
+ iframe.onload = () => {
71
+ try {
72
+ var windowLocation = window.location;
73
+ var iframeLocation = iframe.contentWindow.location;
74
+ if (iframeLocation.host +
75
+ iframeLocation.pathname ===
76
+ windowLocation.host +
77
+ windowLocation.pathname) {
78
+ target.style.display = 'none';
79
+ const iframeUrlParams = new URLSearchParams(iframeLocation.search);
80
+ const data = {};
81
+ iframeUrlParams.forEach((v, k) => {
82
+ data[k] = v;
83
+ });
84
+ if (data.error) {
85
+ return reject({
86
+ error: iframeUrlParams.get('error'),
87
+ error_description: iframeUrlParams.get('error_description')
88
+ });
89
+ }
90
+ return resolve(data);
91
+ }
92
+ else {
93
+ target.style.display = 'block';
94
+ }
95
+ }
96
+ catch (error) {
97
+ target.style.display = 'block';
98
+ }
99
+ };
100
+ });
101
+ };
102
+ class Callback {
103
+ }
104
+ //# sourceMappingURL=openuri.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"openuri.js","sourceRoot":"","sources":["../../src/app/openuri.ts"],"names":[],"mappings":";;;AAOA;;;;;;;;;;;GAWG;A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AI,cAAc,GAAG,MAAM,CAAC,QAAQ,CAAC;gBACrC,IAAI,cAAc,GAAG,MAAM,CAAC,aAAa,CAAC,QAAQ,CAAC;gBACnD,IACI,cAAc,CAAC,IAAI;oBACnB,cAAc,CAAC,QAAQ;oBACvB,cAAc,CAAC,IAAI;wBACnB,cAAc,CAAC,QAAQ,EACzB;oBACE,MAAM,CAAC,KAAK,CAAC,OAAO,GAAG,MAAM,CAAC;oBAC9B,MAAM,eAAe,GAAG,IAAI,eAAe,CAAC,cAAc,CAAC,MAAM,CAAC,CAAC;oBACnE,MAAM,IAAI,GAA8B,EAAE,CAAC;oBAC3C,eAAe,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE;wBAC7B,IAAI,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC;oBAChB,CAAC,CAAC,CAAA;oBACF,IAAI,IAAI,CAAC,KAAK,EAAE;wBACZ,OAAO,MAAM,CAAC;4BACV,KAAK,EAAE,eAAe,CAAC,GAAG,CAAC,OAAO,CAAC;4BACnC,iBAAiB,EAAE,eAAe,CAAC,GAAG,CAAC,mBAAmB,CAAC;yBAC9D,CAAC,CAAA;qBACL;oBACD,OAAO,OAAO,CAAC,IAAI,CAAC,CAAA;iBACvB;qBAAM;oBACH,MAAM,CAAC,KAAK,CAAC,OAAO,GAAG,OAAO,CAAC;iBAClC;aACJ;YAAC,OAAO,KAAK,EAAE;gBACZ,MAAM,CAAC,KAAK,CAAC,OAAO,GAAG,OAAO,CAAC;aAClC;QACL,CAAC,CAAC;IACN,CAAC,CAAC,CAAA;AACN,CAAC,CAAA;AAGD,MAAM,QAAQ;CAEb"}
@@ -0,0 +1,18 @@
1
+ export interface RequestOptions {
2
+ body?: any | null;
3
+ headers?: any | null;
4
+ method?: string;
5
+ [key: string]: any;
6
+ }
7
+ export declare enum ErrorType {
8
+ UNREACHABLE = "unreachable"
9
+ }
10
+ export declare type RequestFn = <T>(url: string, options?: RequestOptions) => Promise<T>;
11
+ /** An Error For all concern **/
12
+ export interface ResponseError {
13
+ error: string;
14
+ error_description?: string | null;
15
+ error_uri?: string | null;
16
+ details?: any | null;
17
+ }
18
+ export declare const defaultRequest: RequestFn;
package/app/request.js ADDED
@@ -0,0 +1,44 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.defaultRequest = exports.ErrorType = void 0;
4
+ var ErrorType;
5
+ (function (ErrorType) {
6
+ ErrorType["UNREACHABLE"] = "unreachable";
7
+ })(ErrorType = exports.ErrorType || (exports.ErrorType = {}));
8
+ exports.defaultRequest = async (url, options) => {
9
+ let result = null;
10
+ let responseError = null;
11
+ try {
12
+ // Objects must be copied to prevent modification of data such as body.
13
+ const copyOptions = Object.assign({}, options);
14
+ if (!copyOptions.method) {
15
+ copyOptions.method = 'GET';
16
+ }
17
+ if (copyOptions.body && typeof copyOptions.body !== 'string') {
18
+ copyOptions.body = JSON.stringify(copyOptions.body);
19
+ }
20
+ const responseResult = await fetch(url, copyOptions);
21
+ const jsonResponse = await responseResult.json();
22
+ if (responseResult.status >= 400) {
23
+ responseError = jsonResponse;
24
+ responseError.error_uri = new URL(url).pathname;
25
+ }
26
+ else {
27
+ result = jsonResponse;
28
+ }
29
+ }
30
+ catch (error) {
31
+ responseError = {
32
+ error: ErrorType.UNREACHABLE,
33
+ error_description: error.message,
34
+ error_uri: new URL(url).pathname,
35
+ };
36
+ }
37
+ if (responseError) {
38
+ throw responseError;
39
+ }
40
+ else {
41
+ return result;
42
+ }
43
+ };
44
+ //# sourceMappingURL=request.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"request.js","sourceRoot":"","sources":["../../src/app/request.ts"],"names":[],"mappings":";;;AAQA,IAAY,SAEX;AAFD,WAAY,SAAS;IACjB,wCAA2B,CAAA;AAC/B,CAAC,EAFW,SAAS,GAAT,iBAAS,KAAT,iBAAS,QAEpB;AAYY,QAAA,cAAc,GAAc,KAAK,EAC1C,GAAW,EACX,OAAwB,EACd,EAAE;IACZ,IAAI,MAAM,GAAa,IAAI,CAAC;IAC5B,IAAI,aAAa,GAAyB,IAAI,CAAC;IAC/C,IAAI;QACA,uEAAuE;QACvE,MAAM,WAAW,GAAG,MAAM,CAAC,MAAM,CAAC,EAAE,EAAE,OAAO,CAAC,CAAC;QAC/C,IAAI,CAAC,WAAW,CAAC,MAAM,EAAE;YACrB,WAAW,CAAC,MAAM,GAAG,KAAK,CAAC;SAC9B;QACD,IAAI,WAAW,CAAC,IAAI,IAAI,OAAO,WAAW,CAAC,IAAI,KAAK,QAAQ,EAAE;YAC1D,WAAW,CAAC,IAAI,GAAG,IAAI,CAAC,SAAS,CAAC,WAAW,CAAC,IAAI,CAAC,CAAC;SACvD;QACD,MAAM,cAAc,GAAa,MAAM,KAAK,CAAC,GAAG,EAAE,WAAW,CAAC,CAAC;QAC/D,MAAM,YAAY,GAAG,MAAM,cAAc,CAAC,IAAI,EAAE,CAAC;QACjD,IAAI,cAAc,CAAC,MAAM,IAAI,GAAG,EAAE;YAC9B,aAAa,GAAG,YAA6B,CAAC;YAC9C,aAAa,CAAC,SAAS,GAAG,IAAI,GAAG,CAAC,GAAG,CAAC,CAAC,QAAQ,CAAC;SACnD;aAAM;YACH,MAAM,GAAG,YAAiB,CAAC;SAC9B;KACJ;IAAC,OAAO,KAAK,EAAE;QACZ,aAAa,GAAG;YACZ,KAAK,EAAE,SAAS,CAAC,WAAW;YAC5B,iBAAiB,EAAE,KAAK,CAAC,OAAO;YAChC,SAAS,EAAE,IAAI,GAAG,CAAC,GAAG,CAAC,CAAC,QAAQ;SACnC,CAAC;KACL;IACD,IAAI,aAAa,EAAE;QACf,MAAM,aAAa,CAAC;KACvB;SAAM;QACH,OAAO,MAAM,CAAC;KACjB;AACL,CAAC,CAAC"}
@@ -0,0 +1,41 @@
1
+ /** An interface of the Simple Web Storage API */
2
+ export interface Storage {
3
+ /**
4
+ * value = storage[key]
5
+ */
6
+ getItem(key: string): Promise<string | null>;
7
+ /**
8
+ * delete storage[key]
9
+ */
10
+ removeItem(key: string): Promise<void>;
11
+ /**
12
+ * storage[key] = value
13
+ */
14
+ setItem(key: string, value: string): Promise<void>;
15
+ }
16
+ export interface StorageOptions {
17
+ env: string;
18
+ }
19
+ /**
20
+ * Default Storage.
21
+ */
22
+ export declare class DefaultStorage implements Storage {
23
+ private readonly _env;
24
+ constructor(opts: StorageOptions);
25
+ /**
26
+ * Get item.
27
+ * @param {string} key
28
+ */
29
+ getItem(key: string): Promise<string | null>;
30
+ /**
31
+ * Remove item.
32
+ * @param {string} key
33
+ */
34
+ removeItem(key: string): Promise<void>;
35
+ /**
36
+ * Set item.
37
+ * @param {string} key
38
+ * @param {string} value
39
+ */
40
+ setItem(key: string, value: string): Promise<void>;
41
+ }
package/app/storage.js ADDED
@@ -0,0 +1,35 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.DefaultStorage = void 0;
4
+ /**
5
+ * Default Storage.
6
+ */
7
+ class DefaultStorage {
8
+ constructor(opts) {
9
+ this._env = opts.env;
10
+ }
11
+ /**
12
+ * Get item.
13
+ * @param {string} key
14
+ */
15
+ async getItem(key) {
16
+ return localStorage.getItem(key + this._env);
17
+ }
18
+ /**
19
+ * Remove item.
20
+ * @param {string} key
21
+ */
22
+ async removeItem(key) {
23
+ return localStorage.removeItem(key + this._env);
24
+ }
25
+ /**
26
+ * Set item.
27
+ * @param {string} key
28
+ * @param {string} value
29
+ */
30
+ async setItem(key, value) {
31
+ return localStorage.setItem(key + this._env, value);
32
+ }
33
+ }
34
+ exports.DefaultStorage = DefaultStorage;
35
+ //# sourceMappingURL=storage.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"storage.js","sourceRoot":"","sources":["../../src/app/storage.ts"],"names":[],"mappings":";;;AAuBA;;GAEG;AACH,MAAa,cAAc;IAGvB,YAAY,IAAoB;QAC5B,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC,GAAG,CAAA;IACxB,CAAC;IAED;;;OAGG;IACH,KAAK,CAAC,OAAO,CAAC,GAAW;QACrB,OAAO,YAAY,CAAC,OAAO,CAAC,GAAG,GAAG,IAAI,CAAC,IAAI,CAAC,CAAC;IACjD,CAAC;IAED;;;OAGG;IACH,KAAK,CAAC,UAAU,CAAC,GAAW;QACxB,OAAO,YAAY,CAAC,UAAU,CAAC,GAAG,GAAG,IAAI,CAAC,IAAI,CAAC,CAAC;IACpD,CAAC;IAED;;;;OAIG;IACH,KAAK,CAAC,OAAO,CAAC,GAAW,EAAE,KAAa;QACpC,OAAO,YAAY,CAAC,OAAO,CAAC,GAAG,GAAG,IAAI,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC;IACxD,CAAC;CACJ;AA/BD,wCA+BC"}
@@ -16,7 +16,7 @@ export declare enum ApiUrls {
16
16
  VERIFY_URL = "/auth/v1/verification/verify",
17
17
  PROVIDER_LIST = "/auth/v1/user/provider",
18
18
  PROVIDER_UNBIND_URL = "/auth/v1/user/provider",
19
- CHECK_PWD_URL = "/auth/v1/user/sudo",
19
+ SUDO_URL = "/auth/v1/user/sudo",
20
20
  BIND_PHONE_URL = "/auth/v1/user/contact",
21
21
  AUTH_SET_PASSWORD = "/auth/v1/user/password"
22
22
  }
@@ -27,3 +27,23 @@ export declare enum VerificationUsages {
27
27
  EMAIL_ADDRESS_CHANGE = "EMAIL_ADDRESS_CHANGE",
28
28
  PHONE_NUMBER_CHANGE = "PHONE_NUMBER_CHANGE"
29
29
  }
30
+ export declare enum ErrorType {
31
+ INVALID_ARGUMENT = "invalid_argument",
32
+ DEADLINE_EXCEEDED = "deadline_exceeded",
33
+ NOT_FOUND = "not_found",
34
+ ALREADY_EXISTS = "already_exists",
35
+ PERMISSION_DENIED = "permission_denied",
36
+ ABORTED = "aborted",
37
+ OUT_OF_RANGE = "out_of_range",
38
+ UNIMPLEMENTED = "unimplemented",
39
+ INTERNAL = "internal",
40
+ UNAVAILABLE = "unavailable",
41
+ DATA_LOSS = "data_loss",
42
+ CAPTCHA_REQUIRED = "captcha_required",
43
+ CAPTCHA_INVALID = "captcha_invalid",
44
+ INVALID_PASSWORD = "invalid_password",
45
+ PASSWORD_NOT_SET = "password_not_set",
46
+ INVALID_STATUS = "invalid_status",
47
+ USER_PENDING = "user_pending",
48
+ USER_BLOCKED = "user_blocked"
49
+ }