@cloudbase/oauth 1.2.1-beta → 2.0.0-beta.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
@@ -1 +0,0 @@
1
- {"version":3,"file":"consts.js","sourceRoot":"","sources":["../../src/oauthclient/consts.ts"],"names":[],"mappings":";;;AAAA,IAAY,MAkBX;AAlBD,WAAY,MAAM;IACd,iCAAuB,CAAA;IACvB,yCAA+B,CAAA;IAC/B,yCAA+B,CAAA;IAC/B,yBAAe,CAAA;IACf,yBAAe,CAAA;IACf,uCAA6B,CAAA;IAC7B,yBAAe,CAAA;IACf,iDAAuC,CAAA;IACvC,iCAAuB,CAAA;IACvB,mCAAyB,CAAA;IACzB,uBAAa,CAAA;IACb,uCAA6B,CAAA;IAC7B,mCAAyB,CAAA;IACzB,mCAAyB,CAAA;IACzB,+BAAqB,CAAA;IACrB,+BAAqB,CAAA;IACrB,yCAA+B,CAAA;AACnC,CAAC,EAlBW,MAAM,GAAN,cAAM,KAAN,cAAM,QAkBjB;AAED,IAAY,SA2BX;AA3BD,WAAY,SAAS;IACjB,wCAA2B,CAAA;IAC3B,4BAAe,CAAA;IACf,oCAAuB,CAAA;IACvB,gCAAmB,CAAA;IACnB,kDAAqC,CAAA;IACrC,oDAAuC,CAAA;IACvC,oCAAuB,CAAA;IACvB,8CAAiC,CAAA;IACjC,oDAAuC,CAAA;IACvC,gDAAmC,CAAA;IACnC,sDAAyC,CAAA;IACzC,wDAA2C,CAAA;IAC3C,gCAAmB,CAAA;IACnB,0CAA6B,CAAA;IAC7B,4CAA+B,CAAA;IAC/B,kCAAqB,CAAA;IACrB,wCAA2B,CAAA;IAC3B,oCAAuB,CAAA;IACvB,cAAc;IACd,4CAA+B,CAAA;IAC/B,oEAAuD,CAAA;IACvD,4CAA+B,CAAA;IAC/B,4CAA+B,CAAA;IAC/B,0CAA6B,CAAA;IAC7B,gEAAmD,CAAA;IACnD,0DAA6C,CAAA;AACjD,CAAC,EA3BW,SAAS,GAAT,iBAAS,KAAT,iBAAS,QA2BpB"}
@@ -1,18 +0,0 @@
1
- import { App } from "../app";
2
- import { Credentials as credentials, ResponseError as responseError } from './models';
3
- import { AuthClient as authClient, RequestFn as requestFn } from "./interface";
4
- export { ErrorType } from './consts';
5
- export interface InitOptions {
6
- request?: RequestFn;
7
- retry?: number;
8
- refreshTokenFunc?: (refreshToken?: string) => Promise<Credentials>;
9
- tokenInURL?: boolean;
10
- headers?: {
11
- [key: string]: string;
12
- };
13
- }
14
- export declare function getOAuthClient(app: App, opts?: InitOptions): authClient;
15
- export declare type Credentials = credentials;
16
- export declare type AuthClient = authClient;
17
- export declare type RequestFn = requestFn;
18
- export declare type ResponseError = responseError;
@@ -1,21 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getOAuthClient = exports.ErrorType = void 0;
4
- const internal_1 = require("../app/internal");
5
- const oauthclient_1 = require("./oauthclient");
6
- var consts_1 = require("./consts");
7
- Object.defineProperty(exports, "ErrorType", { enumerable: true, get: function () { return consts_1.ErrorType; } });
8
- function getOAuthClient(app, opts) {
9
- return internal_1._getComponent(app, "oauthclient", () => {
10
- const appOpts = app.options;
11
- const oauthOpts = {
12
- clientId: appOpts.clientId,
13
- clientSecret: appOpts.clientSecret,
14
- request: appOpts.request,
15
- storage: appOpts.storage,
16
- };
17
- return (new oauthclient_1.OAuth2Client(oauthOpts));
18
- });
19
- }
20
- exports.getOAuthClient = getOAuthClient;
21
- //# sourceMappingURL=index.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/oauthclient/index.ts"],"names":[],"mappings":";;;AACA,8CAA8C;AAC9C,+CAA2C;AAG3C,mCAAmC;AAA3B,mGAAA,SAAS,OAAA;AAUjB,SAAgB,cAAc,CAAC,GAAQ,EAAE,IAAkB;IACvD,OAAO,wBAAa,CAAa,GAAG,EAAE,aAAa,EAAE,GAAe,EAAE;QAClE,MAAM,OAAO,GAAG,GAAG,CAAC,OAAO,CAAA;QAC3B,MAAM,SAAS,GAAG;YACd,QAAQ,EAAE,OAAO,CAAC,QAAQ;YAC1B,YAAY,EAAE,OAAO,CAAC,YAAY;YAClC,OAAO,EAAE,OAAO,CAAC,OAAO;YACxB,OAAO,EAAE,OAAO,CAAC,OAAO;SAC3B,CAAA;QACD,OAAO,CAAC,IAAI,0BAAY,CAAC,SAAS,CAAC,CAAC,CAAA;IACxC,CAAC,CAAC,CAAC;AACP,CAAC;AAXD,wCAWC"}
@@ -1,29 +0,0 @@
1
- import { Credentials, AuthClientRequestOptions } from './models';
2
- /**
3
- * the interface for the Oauth2Client
4
- */
5
- export declare abstract class AuthClient {
6
- /**
7
- * Sets the auth credentials.
8
- */
9
- abstract setCredentials(credentials?: Credentials): void;
10
- /**
11
- * Provides an alternative fetch api request implementation with auth credentials
12
- * if options.withCredentials:true, the request will auto add Authorization: Bearer <AccessToken> in the request
13
- * error:
14
- * - unreachable, the network error or response is not json
15
- * - unauthenticated: has no validate access token
16
- */
17
- abstract request: RequestFn;
18
- /**
19
- * get the current accessToken from AuthClient, you can use this to detect login status
20
- * error:
21
- * - unauthenticated: has no validate access token
22
- */
23
- abstract getAccessToken(): Promise<string>;
24
- /**
25
- * get the current token scope
26
- */
27
- abstract getScope(): Promise<string>;
28
- }
29
- export declare type RequestFn = <T>(url: string, options?: AuthClientRequestOptions) => Promise<T>;
@@ -1,10 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.AuthClient = void 0;
4
- /**
5
- * the interface for the Oauth2Client
6
- */
7
- class AuthClient {
8
- }
9
- exports.AuthClient = AuthClient;
10
- //# sourceMappingURL=interface.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"interface.js","sourceRoot":"","sources":["../../src/oauthclient/interface.ts"],"names":[],"mappings":";;;AAEA;;GAEG;AACH,MAAsB,UAAU;CA0B/B;AA1BD,gCA0BC"}
@@ -1,40 +0,0 @@
1
- import { RequestFn, RequestOptions, Storage } from "../app";
2
- import { ErrorType } from './consts';
3
- export interface Credentials {
4
- token_type?: string;
5
- access_token?: string;
6
- refresh_token?: string;
7
- scope?: string;
8
- expires_in?: number;
9
- expires_at?: Date;
10
- sub?: string;
11
- }
12
- export interface ResponseError {
13
- error: ErrorType;
14
- error_description?: string;
15
- error_uri?: string;
16
- details?: any;
17
- request_id?: string;
18
- }
19
- export interface AuthClientRequestOptions extends RequestOptions {
20
- headers?: {
21
- 'x-request-id'?: string;
22
- [key: string]: any;
23
- };
24
- withCredentials?: boolean;
25
- withBasicAuth?: boolean;
26
- retry?: number;
27
- [key: string]: any;
28
- }
29
- export interface OAuth2ClientOptions {
30
- clientId: string;
31
- storage: Storage;
32
- request: RequestFn;
33
- clientSecret?: string;
34
- retry?: number;
35
- refreshTokenFunc?: (refreshToken?: string) => Promise<Credentials>;
36
- tokenInURL?: boolean;
37
- headers?: {
38
- [key: string]: string;
39
- };
40
- }
@@ -1,3 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- //# sourceMappingURL=models.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"models.js","sourceRoot":"","sources":["../../src/oauthclient/models.ts"],"names":[],"mappings":""}
@@ -1,146 +0,0 @@
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;
8
- error_uri?: string;
9
- details?: any;
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 _promiseOnce;
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>}
44
- */
45
- getCredentials(): Promise<Credentials>;
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 _promiseOnce;
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
- * getScope return a validate access token
86
- */
87
- getScope(): Promise<string>;
88
- /**
89
- * request http like simple fetch api, exp:request('/v1/user/me', {withCredentials:true})
90
- * @param {string} url
91
- * @param {AuthClientRequestOptions} options
92
- */
93
- request<T>(url: string, options?: AuthClientRequestOptions): Promise<T>;
94
- /**
95
- * Check retry value.
96
- * @param {number} retry
97
- * @return {number}
98
- */
99
- private _checkRetry;
100
- /**
101
- * Format retry value.
102
- * @param {number} retry
103
- * @param {number} defaultVale
104
- * @return {number}
105
- */
106
- private _formatRetry;
107
- /**
108
- * Sleep.
109
- * @param {number} ms
110
- * @return {Promise<void>}
111
- */
112
- private _sleep;
113
- /**
114
- * Refresh expired token.
115
- * @param {Credentials} credentials
116
- * @return {Promise<Credentials>}
117
- */
118
- private _refreshToken;
119
- /**
120
- * anonymous signIn
121
- * @param {Credentials} credentials
122
- * @return {Promise<Credentials>}
123
- */
124
- private _anonymousSignIn;
125
- /**
126
- * Default refresh token function.
127
- * @param {string} refreshToken
128
- * @return {Promise<Credentials>}
129
- */
130
- private _defaultRefreshTokenFunc;
131
- /**
132
- * Get credentials.
133
- */
134
- private _getCredentials;
135
- /**
136
- * Get deviceId
137
- */
138
- private _getDeviceId;
139
- /**
140
- * Generate unAuthenticated error.
141
- * @param {string} err
142
- * @return {Promise<T>}
143
- */
144
- private _unAuthenticatedError;
145
- }
146
- export {};