squarefi-bff-api-module 1.23.5 → 1.24.1
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.
- package/CHANGELOG.md +186 -0
- package/dist/api/auth.d.ts +3 -3
- package/dist/api/auth.js +1 -1
- package/dist/api/types/types.d.ts +10 -14
- package/dist/utils/apiClientFactory.js +21 -4
- package/dist/utils/tokensFactory.d.ts +4 -4
- package/dist/utils/tokensFactory.js +23 -6
- package/package.json +1 -1
- package/src/api/auth.ts +6 -6
- package/src/api/types/types.ts +13 -14
- package/src/utils/apiClientFactory.ts +22 -4
- package/src/utils/tokensFactory.ts +31 -10
package/CHANGELOG.md
CHANGED
|
@@ -5,6 +5,192 @@ All notable changes to this project will be documented in this file.
|
|
|
5
5
|
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
|
6
6
|
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
7
7
|
|
|
8
|
+
## [1.25.0] - 2025-07-23
|
|
9
|
+
|
|
10
|
+
### Changed
|
|
11
|
+
|
|
12
|
+
- Enhanced refresh token handling for Telegram sign-in methods in TMA
|
|
13
|
+
- Updated Telegram auth types to use request/response structures for improved type safety with optional refresh_token
|
|
14
|
+
|
|
15
|
+
### Added
|
|
16
|
+
|
|
17
|
+
- Improved Telegram authentication workflow with better token management
|
|
18
|
+
|
|
19
|
+
## [1.24.0] - 2025-07-23
|
|
20
|
+
|
|
21
|
+
### Changed
|
|
22
|
+
|
|
23
|
+
- Version release for accumulated features
|
|
24
|
+
|
|
25
|
+
## [1.23.5] - 2025-07-22
|
|
26
|
+
|
|
27
|
+
### Added
|
|
28
|
+
|
|
29
|
+
- Additional optional fields to meta for enhanced transaction details
|
|
30
|
+
|
|
31
|
+
## [1.23.4] - 2025-07-22
|
|
32
|
+
|
|
33
|
+
### Changed
|
|
34
|
+
|
|
35
|
+
- Made account_number, routing_number, and swift_bic optional in ExternalBankingData for improved flexibility
|
|
36
|
+
|
|
37
|
+
## [1.23.3] - 2025-07-22
|
|
38
|
+
|
|
39
|
+
### Added
|
|
40
|
+
|
|
41
|
+
- Optional state field to address type for improved address detail accuracy
|
|
42
|
+
|
|
43
|
+
## [1.23.2] - 2025-07-22
|
|
44
|
+
|
|
45
|
+
### Added
|
|
46
|
+
|
|
47
|
+
- Added state_id to address type for enhanced address details
|
|
48
|
+
|
|
49
|
+
## [1.23.1] - 2025-07-22
|
|
50
|
+
|
|
51
|
+
### Added
|
|
52
|
+
|
|
53
|
+
- States API endpoint and related types for fetching states by country_id
|
|
54
|
+
|
|
55
|
+
## [1.23.0] - 2025-07-22
|
|
56
|
+
|
|
57
|
+
### Fixed
|
|
58
|
+
|
|
59
|
+
- Updated Counterparty and related DTOs to require email and phone fields for improved data integrity
|
|
60
|
+
- Added note to orderRequests
|
|
61
|
+
|
|
62
|
+
## [1.22.13] - 2025-07-21
|
|
63
|
+
|
|
64
|
+
### Fixed
|
|
65
|
+
|
|
66
|
+
- Corrected Confirm.Request type to reference changeEmailConfirm operation for accurate API request handling
|
|
67
|
+
|
|
68
|
+
## [1.22.12] - 2025-07-20
|
|
69
|
+
|
|
70
|
+
### Added
|
|
71
|
+
|
|
72
|
+
- PROCESSING status to OrderStatuses enum for enhanced order tracking
|
|
73
|
+
|
|
74
|
+
## [1.22.11] - 2025-07-20
|
|
75
|
+
|
|
76
|
+
### Fixed
|
|
77
|
+
|
|
78
|
+
- Updated WithdrawCryptoRequest to include SEGREGATED_CRYPTO_TRANSFER in order_type for improved transaction handling
|
|
79
|
+
|
|
80
|
+
## [1.22.10] - 2025-07-20
|
|
81
|
+
|
|
82
|
+
### Added
|
|
83
|
+
|
|
84
|
+
- SEGREGATED_CRYPTO_TRANSFER to WalletTransactionRecordType enum for expanded transaction support
|
|
85
|
+
|
|
86
|
+
## [1.22.9] - 2025-07-20
|
|
87
|
+
|
|
88
|
+
### Added
|
|
89
|
+
|
|
90
|
+
- SEGREGATED_CRYPTO_TRANSFER order type and corresponding request/response types for enhanced order processing
|
|
91
|
+
|
|
92
|
+
## [1.22.8] - 2025-07-18
|
|
93
|
+
|
|
94
|
+
### Changed
|
|
95
|
+
|
|
96
|
+
- Streamlined user phone and email request types by leveraging OpenAPI operations for improved type safety and maintainability
|
|
97
|
+
|
|
98
|
+
## [1.22.7] - 2025-07-18
|
|
99
|
+
|
|
100
|
+
### Added
|
|
101
|
+
|
|
102
|
+
- wallet_id to pagination request in VirtualAccountPrograms Request
|
|
103
|
+
- wallet_id to issuing_programs request
|
|
104
|
+
|
|
105
|
+
## [1.22.6] - 2025-07-18
|
|
106
|
+
|
|
107
|
+
### Added
|
|
108
|
+
|
|
109
|
+
- Optional birth_date field to user types in API schema for enhanced user data handling
|
|
110
|
+
|
|
111
|
+
## [1.22.5] - 2025-07-18
|
|
112
|
+
|
|
113
|
+
### Changed
|
|
114
|
+
|
|
115
|
+
- Updated user and userData types to align with new API schema
|
|
116
|
+
- Enhanced type safety in user requests
|
|
117
|
+
|
|
118
|
+
## [1.22.4] - 2025-07-18
|
|
119
|
+
|
|
120
|
+
### Added
|
|
121
|
+
|
|
122
|
+
- New OrderTypeKycRail type and updated OrderInfo structure
|
|
123
|
+
|
|
124
|
+
### Changed
|
|
125
|
+
|
|
126
|
+
- Removed deprecated kyc_rails_id
|
|
127
|
+
|
|
128
|
+
## [1.22.3] - 2025-07-18
|
|
129
|
+
|
|
130
|
+
### Fixed
|
|
131
|
+
|
|
132
|
+
- Made limits property optional in card configuration for flexibility
|
|
133
|
+
|
|
134
|
+
## [1.22.2] - 2025-07-05
|
|
135
|
+
|
|
136
|
+
### Added
|
|
137
|
+
|
|
138
|
+
- Exported hooks from the hooks module for improved functionality
|
|
139
|
+
|
|
140
|
+
## [1.22.1] - 2025-07-04
|
|
141
|
+
|
|
142
|
+
### Added
|
|
143
|
+
|
|
144
|
+
- useCalc hook for enhanced calculation functionality
|
|
145
|
+
|
|
146
|
+
## [1.22.0] - 2025-07-04
|
|
147
|
+
|
|
148
|
+
### Fixed
|
|
149
|
+
|
|
150
|
+
- Renamed currency_id to from_currency_id in request parameters for clarity
|
|
151
|
+
|
|
152
|
+
## [1.21.9] - 2025-06-26
|
|
153
|
+
|
|
154
|
+
### Fixed
|
|
155
|
+
|
|
156
|
+
- Renamed currency parameters in Calc.CommonRequestParams to use IDs for improved clarity
|
|
157
|
+
|
|
158
|
+
## [1.21.8] - 2025-06-25
|
|
159
|
+
|
|
160
|
+
### Fixed
|
|
161
|
+
|
|
162
|
+
- Updated orderType request params to include to_currency
|
|
163
|
+
|
|
164
|
+
## [1.21.7] - 2025-06-24
|
|
165
|
+
|
|
166
|
+
### Added
|
|
167
|
+
|
|
168
|
+
- HIFI_CRYPTO_TRANSFER order type with request and response types for enhanced order processing
|
|
169
|
+
|
|
170
|
+
## [1.21.6] - 2025-06-24
|
|
171
|
+
|
|
172
|
+
### Added
|
|
173
|
+
|
|
174
|
+
- New wallet transaction record types for enhanced transaction handling
|
|
175
|
+
|
|
176
|
+
## [1.21.5] - 2025-06-24
|
|
177
|
+
|
|
178
|
+
### Added
|
|
179
|
+
|
|
180
|
+
- count property to TransactionsList interface for improved transaction data handling
|
|
181
|
+
|
|
182
|
+
## [1.21.4] - 2025-06-23
|
|
183
|
+
|
|
184
|
+
### Changed
|
|
185
|
+
|
|
186
|
+
- Refactored getAll method in issuing API to accept parameters as an object and updated types for improved flexibility
|
|
187
|
+
|
|
188
|
+
## [1.21.3] - 2025-06-23
|
|
189
|
+
|
|
190
|
+
### Added
|
|
191
|
+
|
|
192
|
+
- TBD_SWIFT_WITHDRAWAL order type with request and response types
|
|
193
|
+
|
|
8
194
|
## [1.21.2] - 2025-06-17
|
|
9
195
|
|
|
10
196
|
### Added
|
package/dist/api/auth.d.ts
CHANGED
|
@@ -14,14 +14,14 @@ export declare const auth: {
|
|
|
14
14
|
email: (data: API.Auth.SignIn.Email.OTP.Request) => Promise<API.Auth.Tokens>;
|
|
15
15
|
phone: ({ phone, ...data }: API.Auth.SignIn.Phone.OTP.Request) => Promise<API.Auth.Tokens>;
|
|
16
16
|
};
|
|
17
|
-
telegram: (data: API.Auth.Telegram.Signin) => Promise<API.Auth.
|
|
17
|
+
telegram: (data: API.Auth.Telegram.Signin.Request) => Promise<API.Auth.Telegram.Signin.Response>;
|
|
18
18
|
password: (email: string, password: string) => Promise<API.Auth.Tokens>;
|
|
19
19
|
};
|
|
20
20
|
signup: {
|
|
21
21
|
password: (email: string, password: string) => Promise<API.Auth.Tokens>;
|
|
22
|
-
telegram: (data: API.Auth.Telegram.Signup) => Promise<API.Auth.
|
|
22
|
+
telegram: (data: API.Auth.Telegram.Signup.Request) => Promise<API.Auth.Telegram.Signup.Response>;
|
|
23
23
|
};
|
|
24
24
|
refresh: {
|
|
25
|
-
refresh_token: (
|
|
25
|
+
refresh_token: (data: API.Auth.RefreshToken.Request) => Promise<API.Auth.RefreshToken.Response>;
|
|
26
26
|
};
|
|
27
27
|
};
|
package/dist/api/auth.js
CHANGED
|
@@ -52,6 +52,6 @@ exports.auth = {
|
|
|
52
52
|
telegram: (data) => apiClientFactory_1.apiClientV2.postRequest(exports.telegramSignUpPath, { data }),
|
|
53
53
|
},
|
|
54
54
|
refresh: {
|
|
55
|
-
refresh_token: (
|
|
55
|
+
refresh_token: (data) => apiClientFactory_1.apiClientV2.postRequest(exports.refreshTokenPath, { data }),
|
|
56
56
|
},
|
|
57
57
|
};
|
|
@@ -3,22 +3,18 @@ import { WalletType } from '../..';
|
|
|
3
3
|
import { components, operations } from './autogen/apiV2.types';
|
|
4
4
|
export declare namespace API {
|
|
5
5
|
namespace Auth {
|
|
6
|
+
namespace RefreshToken {
|
|
7
|
+
type Request = operations['AuthController_refreshToken']['requestBody']['content']['application/json'];
|
|
8
|
+
type Response = operations['AuthController_refreshToken']['responses']['200']['content']['application/json'];
|
|
9
|
+
}
|
|
6
10
|
namespace Telegram {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
init_data_raw: string;
|
|
11
|
+
namespace Signin {
|
|
12
|
+
type Request = operations['AuthTelegramController_signIn']['requestBody']['content']['application/json'];
|
|
13
|
+
type Response = operations['AuthTelegramController_signIn']['responses']['200']['content']['application/json'];
|
|
11
14
|
}
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
first_name: string;
|
|
16
|
-
last_name?: string;
|
|
17
|
-
hash: string;
|
|
18
|
-
init_data_raw: string;
|
|
19
|
-
referrer?: string;
|
|
20
|
-
invite_code?: string;
|
|
21
|
-
username: string;
|
|
15
|
+
namespace Signup {
|
|
16
|
+
type Request = operations['AuthTelegramController_signUp']['requestBody']['content']['application/json'];
|
|
17
|
+
type Response = operations['AuthTelegramController_signUp']['responses']['200']['content']['application/json'];
|
|
22
18
|
}
|
|
23
19
|
}
|
|
24
20
|
interface Tokens {
|
|
@@ -55,7 +55,7 @@ const createApiClient = ({ baseURL, isBearerToken, tenantId }) => {
|
|
|
55
55
|
let isTokenRefreshing = false;
|
|
56
56
|
let requestQueue = [];
|
|
57
57
|
instance.interceptors.response.use((response) => response, (error) => {
|
|
58
|
-
var _a, _b;
|
|
58
|
+
var _a, _b, _c, _d;
|
|
59
59
|
if (typeof window === 'undefined') {
|
|
60
60
|
return Promise.reject(error);
|
|
61
61
|
}
|
|
@@ -64,9 +64,25 @@ const createApiClient = ({ baseURL, isBearerToken, tenantId }) => {
|
|
|
64
64
|
const refreshToken = (0, storage_1.getFromLocalStorage)('refresh_token');
|
|
65
65
|
const isRetryRequest = failedRequest.headers['X-Retry-Request'];
|
|
66
66
|
const isRefreshTokenRequest = (_b = response === null || response === void 0 ? void 0 : response.config) === null || _b === void 0 ? void 0 : _b.url.includes(auth_1.refreshTokenPath);
|
|
67
|
-
const
|
|
68
|
-
const
|
|
69
|
-
const
|
|
67
|
+
const isTelegramSignInRequest = (_c = response === null || response === void 0 ? void 0 : response.config) === null || _c === void 0 ? void 0 : _c.url.includes(auth_1.telegramSignInPath);
|
|
68
|
+
const isTelegramSignUpRequest = (_d = response === null || response === void 0 ? void 0 : response.config) === null || _d === void 0 ? void 0 : _d.url.includes(auth_1.telegramSignUpPath);
|
|
69
|
+
const isRefreshNotRequired = !refreshToken && !(0, sdk_react_1.isTMA)();
|
|
70
|
+
const isLogoutNeccesary = isRefreshNotRequired ||
|
|
71
|
+
isTelegramSignInRequest ||
|
|
72
|
+
isTelegramSignUpRequest ||
|
|
73
|
+
isRefreshTokenRequest ||
|
|
74
|
+
isRetryRequest;
|
|
75
|
+
const isRefreshAvailable = !isTokenRefreshing && !isRefreshNotRequired;
|
|
76
|
+
console.log('isRefreshAvailable', isRefreshAvailable);
|
|
77
|
+
console.log('isLogoutNeccesary', isLogoutNeccesary);
|
|
78
|
+
console.log('isRetryRequest', isRetryRequest);
|
|
79
|
+
console.log('isTelegramSignInRequest', isTelegramSignInRequest);
|
|
80
|
+
console.log('isTelegramSignUpRequest', isTelegramSignUpRequest);
|
|
81
|
+
console.log('isRefreshTokenRequest', isRefreshTokenRequest);
|
|
82
|
+
console.log('isRefreshNotRequired', isRefreshNotRequired);
|
|
83
|
+
console.log('isTokenRefreshing', isTokenRefreshing);
|
|
84
|
+
console.log('refreshToken', refreshToken);
|
|
85
|
+
console.log('isTMA', (0, sdk_react_1.isTMA)());
|
|
70
86
|
if (isLogoutNeccesary) {
|
|
71
87
|
if (typeof window !== 'undefined') {
|
|
72
88
|
window.location.href = envLogoutURL;
|
|
@@ -76,6 +92,7 @@ const createApiClient = ({ baseURL, isBearerToken, tenantId }) => {
|
|
|
76
92
|
return Promise.reject(response);
|
|
77
93
|
}
|
|
78
94
|
if (isRefreshAvailable) {
|
|
95
|
+
isTokenRefreshing = true;
|
|
79
96
|
(0, tokensFactory_1.refreshTokens)()
|
|
80
97
|
.then((data) => {
|
|
81
98
|
if (data === null || data === void 0 ? void 0 : data.access_token) {
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
type
|
|
1
|
+
type ITokens = {
|
|
2
2
|
access_token: string;
|
|
3
|
-
refresh_token?: string;
|
|
3
|
+
refresh_token?: string | null;
|
|
4
4
|
};
|
|
5
|
-
export declare function setTokens({ access_token, refresh_token }:
|
|
5
|
+
export declare function setTokens({ access_token, refresh_token }: ITokens): void;
|
|
6
6
|
export declare function deleteTokens(): void;
|
|
7
|
-
export declare function refreshTokens(): Promise<
|
|
7
|
+
export declare function refreshTokens(): Promise<ITokens | null>;
|
|
8
8
|
export declare function getTokens(): {
|
|
9
9
|
access_token: string | null;
|
|
10
10
|
refresh_token: string | null;
|
|
@@ -13,6 +13,7 @@ exports.setTokens = setTokens;
|
|
|
13
13
|
exports.deleteTokens = deleteTokens;
|
|
14
14
|
exports.refreshTokens = refreshTokens;
|
|
15
15
|
exports.getTokens = getTokens;
|
|
16
|
+
const sdk_react_1 = require("@telegram-apps/sdk-react");
|
|
16
17
|
const storage_1 = require("./storage");
|
|
17
18
|
const auth_1 = require("../api/auth");
|
|
18
19
|
function setTokens({ access_token, refresh_token }) {
|
|
@@ -25,13 +26,29 @@ function deleteTokens() {
|
|
|
25
26
|
}
|
|
26
27
|
function refreshTokens() {
|
|
27
28
|
return __awaiter(this, void 0, void 0, function* () {
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
29
|
+
var _a;
|
|
30
|
+
const refresh_token = (0, storage_1.getFromLocalStorage)('refresh_token');
|
|
31
|
+
if (refresh_token) {
|
|
32
|
+
const refreshResponse = yield auth_1.auth.refresh.refresh_token({ refresh_token });
|
|
33
|
+
setTokens(refreshResponse);
|
|
34
|
+
return refreshResponse;
|
|
31
35
|
}
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
36
|
+
if ((0, sdk_react_1.isTMA)()) {
|
|
37
|
+
const tg_id = (_a = sdk_react_1.initData.user()) === null || _a === void 0 ? void 0 : _a.id;
|
|
38
|
+
const hash = sdk_react_1.initData.hash();
|
|
39
|
+
const init_data_raw = sdk_react_1.initData.raw();
|
|
40
|
+
if (!tg_id || !hash || !init_data_raw) {
|
|
41
|
+
return null;
|
|
42
|
+
}
|
|
43
|
+
const telegramSignInResponse = yield auth_1.auth.signin.telegram({
|
|
44
|
+
tg_id: tg_id.toString(),
|
|
45
|
+
hash,
|
|
46
|
+
init_data_raw,
|
|
47
|
+
});
|
|
48
|
+
setTokens(telegramSignInResponse);
|
|
49
|
+
return telegramSignInResponse;
|
|
50
|
+
}
|
|
51
|
+
return null;
|
|
35
52
|
});
|
|
36
53
|
}
|
|
37
54
|
function getTokens() {
|
package/package.json
CHANGED
package/src/api/auth.ts
CHANGED
|
@@ -31,8 +31,8 @@ export const auth = {
|
|
|
31
31
|
data: { phone: convertPhoneToSupabaseFormat(phone), ...data },
|
|
32
32
|
}),
|
|
33
33
|
},
|
|
34
|
-
telegram: (data: API.Auth.Telegram.Signin): Promise<API.Auth.
|
|
35
|
-
apiClientV2.postRequest<API.Auth.
|
|
34
|
+
telegram: (data: API.Auth.Telegram.Signin.Request): Promise<API.Auth.Telegram.Signin.Response> =>
|
|
35
|
+
apiClientV2.postRequest<API.Auth.Telegram.Signin.Response>(telegramSignInPath, { data }),
|
|
36
36
|
password: (
|
|
37
37
|
email: string,
|
|
38
38
|
password: string // check on backend V2
|
|
@@ -46,11 +46,11 @@ export const auth = {
|
|
|
46
46
|
apiClientV2.postRequest<API.Auth.Tokens>('/auth/sign-up/password/email', {
|
|
47
47
|
data: { email, password },
|
|
48
48
|
}),
|
|
49
|
-
telegram: (data: API.Auth.Telegram.Signup): Promise<API.Auth.
|
|
50
|
-
apiClientV2.postRequest<API.Auth.
|
|
49
|
+
telegram: (data: API.Auth.Telegram.Signup.Request): Promise<API.Auth.Telegram.Signup.Response> =>
|
|
50
|
+
apiClientV2.postRequest<API.Auth.Telegram.Signup.Response>(telegramSignUpPath, { data }),
|
|
51
51
|
},
|
|
52
52
|
refresh: {
|
|
53
|
-
refresh_token: (
|
|
54
|
-
apiClientV2.postRequest<API.Auth.
|
|
53
|
+
refresh_token: (data: API.Auth.RefreshToken.Request): Promise<API.Auth.RefreshToken.Response> =>
|
|
54
|
+
apiClientV2.postRequest<API.Auth.RefreshToken.Response>(refreshTokenPath, { data }),
|
|
55
55
|
},
|
|
56
56
|
};
|
package/src/api/types/types.ts
CHANGED
|
@@ -23,22 +23,21 @@ import { components, operations } from './autogen/apiV2.types';
|
|
|
23
23
|
|
|
24
24
|
export namespace API {
|
|
25
25
|
export namespace Auth {
|
|
26
|
+
export namespace RefreshToken {
|
|
27
|
+
export type Request = operations['AuthController_refreshToken']['requestBody']['content']['application/json'];
|
|
28
|
+
export type Response =
|
|
29
|
+
operations['AuthController_refreshToken']['responses']['200']['content']['application/json'];
|
|
30
|
+
}
|
|
26
31
|
export namespace Telegram {
|
|
27
|
-
export
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
32
|
+
export namespace Signin {
|
|
33
|
+
export type Request = operations['AuthTelegramController_signIn']['requestBody']['content']['application/json'];
|
|
34
|
+
export type Response =
|
|
35
|
+
operations['AuthTelegramController_signIn']['responses']['200']['content']['application/json'];
|
|
31
36
|
}
|
|
32
|
-
export
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
last_name?: string;
|
|
37
|
-
hash: string;
|
|
38
|
-
init_data_raw: string;
|
|
39
|
-
referrer?: string;
|
|
40
|
-
invite_code?: string;
|
|
41
|
-
username: string;
|
|
37
|
+
export namespace Signup {
|
|
38
|
+
export type Request = operations['AuthTelegramController_signUp']['requestBody']['content']['application/json'];
|
|
39
|
+
export type Response =
|
|
40
|
+
operations['AuthTelegramController_signUp']['responses']['200']['content']['application/json'];
|
|
42
41
|
}
|
|
43
42
|
}
|
|
44
43
|
|
|
@@ -67,10 +67,27 @@ export const createApiClient = ({ baseURL, isBearerToken, tenantId }: CreateApiC
|
|
|
67
67
|
const isRetryRequest = failedRequest.headers['X-Retry-Request'];
|
|
68
68
|
|
|
69
69
|
const isRefreshTokenRequest = response?.config?.url.includes(refreshTokenPath);
|
|
70
|
-
const
|
|
71
|
-
const
|
|
72
|
-
|
|
73
|
-
const
|
|
70
|
+
const isTelegramSignInRequest = response?.config?.url.includes(telegramSignInPath);
|
|
71
|
+
const isTelegramSignUpRequest = response?.config?.url.includes(telegramSignUpPath);
|
|
72
|
+
const isRefreshNotRequired = !refreshToken && !isTMA();
|
|
73
|
+
const isLogoutNeccesary =
|
|
74
|
+
isRefreshNotRequired ||
|
|
75
|
+
isTelegramSignInRequest ||
|
|
76
|
+
isTelegramSignUpRequest ||
|
|
77
|
+
isRefreshTokenRequest ||
|
|
78
|
+
isRetryRequest;
|
|
79
|
+
|
|
80
|
+
const isRefreshAvailable = !isTokenRefreshing && !isRefreshNotRequired;
|
|
81
|
+
console.log('isRefreshAvailable', isRefreshAvailable);
|
|
82
|
+
console.log('isLogoutNeccesary', isLogoutNeccesary);
|
|
83
|
+
console.log('isRetryRequest', isRetryRequest);
|
|
84
|
+
console.log('isTelegramSignInRequest', isTelegramSignInRequest);
|
|
85
|
+
console.log('isTelegramSignUpRequest', isTelegramSignUpRequest);
|
|
86
|
+
console.log('isRefreshTokenRequest', isRefreshTokenRequest);
|
|
87
|
+
console.log('isRefreshNotRequired', isRefreshNotRequired);
|
|
88
|
+
console.log('isTokenRefreshing', isTokenRefreshing);
|
|
89
|
+
console.log('refreshToken', refreshToken);
|
|
90
|
+
console.log('isTMA', isTMA());
|
|
74
91
|
|
|
75
92
|
if (isLogoutNeccesary) {
|
|
76
93
|
if (typeof window !== 'undefined') {
|
|
@@ -81,6 +98,7 @@ export const createApiClient = ({ baseURL, isBearerToken, tenantId }: CreateApiC
|
|
|
81
98
|
return Promise.reject(response);
|
|
82
99
|
}
|
|
83
100
|
if (isRefreshAvailable) {
|
|
101
|
+
isTokenRefreshing = true;
|
|
84
102
|
refreshTokens()
|
|
85
103
|
.then((data) => {
|
|
86
104
|
if (data?.access_token) {
|
|
@@ -1,13 +1,16 @@
|
|
|
1
|
+
import { initData, isTMA } from '@telegram-apps/sdk-react';
|
|
2
|
+
|
|
1
3
|
import { deleteFromLocalStorage, getFromLocalStorage, setToLocalStorage } from './storage';
|
|
2
4
|
|
|
3
5
|
import { auth } from '../api/auth';
|
|
6
|
+
import { API } from '../api/types/types';
|
|
4
7
|
|
|
5
|
-
type
|
|
8
|
+
type ITokens = {
|
|
6
9
|
access_token: string;
|
|
7
|
-
refresh_token?: string;
|
|
10
|
+
refresh_token?: string | null;
|
|
8
11
|
};
|
|
9
12
|
|
|
10
|
-
export function setTokens({ access_token, refresh_token }:
|
|
13
|
+
export function setTokens({ access_token, refresh_token }: ITokens) {
|
|
11
14
|
access_token && setToLocalStorage('access_token', access_token);
|
|
12
15
|
refresh_token && setToLocalStorage('refresh_token', refresh_token);
|
|
13
16
|
}
|
|
@@ -17,18 +20,36 @@ export function deleteTokens() {
|
|
|
17
20
|
deleteFromLocalStorage('refresh_token');
|
|
18
21
|
}
|
|
19
22
|
|
|
20
|
-
export async function refreshTokens() {
|
|
21
|
-
const
|
|
23
|
+
export async function refreshTokens(): Promise<ITokens | null> {
|
|
24
|
+
const refresh_token = getFromLocalStorage('refresh_token');
|
|
25
|
+
|
|
26
|
+
if (refresh_token) {
|
|
27
|
+
const refreshResponse = await auth.refresh.refresh_token({ refresh_token });
|
|
22
28
|
|
|
23
|
-
|
|
24
|
-
return
|
|
29
|
+
setTokens(refreshResponse);
|
|
30
|
+
return refreshResponse;
|
|
25
31
|
}
|
|
26
32
|
|
|
27
|
-
|
|
33
|
+
if (isTMA()) {
|
|
34
|
+
const tg_id = initData.user()?.id;
|
|
35
|
+
const hash = initData.hash();
|
|
36
|
+
const init_data_raw = initData.raw();
|
|
37
|
+
|
|
38
|
+
if (!tg_id || !hash || !init_data_raw) {
|
|
39
|
+
return null;
|
|
40
|
+
}
|
|
28
41
|
|
|
29
|
-
|
|
42
|
+
const telegramSignInResponse = await auth.signin.telegram({
|
|
43
|
+
tg_id: tg_id.toString(),
|
|
44
|
+
hash,
|
|
45
|
+
init_data_raw,
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
setTokens(telegramSignInResponse);
|
|
49
|
+
return telegramSignInResponse;
|
|
50
|
+
}
|
|
30
51
|
|
|
31
|
-
return
|
|
52
|
+
return null;
|
|
32
53
|
}
|
|
33
54
|
|
|
34
55
|
export function getTokens() {
|