@up-im/medotvet_sdk 0.0.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/.cursor/rules/apcheki_sdk.mdc +90 -0
- package/README.md +136 -0
- package/dist/api/abstract.d.ts +21 -0
- package/dist/api/abstract.js +125 -0
- package/dist/api/bookmarks.d.ts +28 -0
- package/dist/api/bookmarks.js +121 -0
- package/dist/api/chat.d.ts +30 -0
- package/dist/api/chat.js +118 -0
- package/dist/api/content.d.ts +154 -0
- package/dist/api/content.js +237 -0
- package/dist/api/geoIp.d.ts +8 -0
- package/dist/api/geoIp.js +14 -0
- package/dist/api/index.d.ts +27 -0
- package/dist/api/index.js +31 -0
- package/dist/api/payment.d.ts +54 -0
- package/dist/api/payment.js +90 -0
- package/dist/api/promocode.d.ts +9 -0
- package/dist/api/promocode.js +22 -0
- package/dist/api/push.d.ts +54 -0
- package/dist/api/push.js +99 -0
- package/dist/api/receipt.d.ts +34 -0
- package/dist/api/receipt.js +60 -0
- package/dist/api/stat.d.ts +21 -0
- package/dist/api/stat.js +75 -0
- package/dist/api/survey.d.ts +82 -0
- package/dist/api/survey.js +122 -0
- package/dist/api/user.d.ts +80 -0
- package/dist/api/user.js +167 -0
- package/dist/eventBus/abstract.d.ts +4 -0
- package/dist/eventBus/abstract.js +29 -0
- package/dist/eventBus/userLogin.d.ts +5 -0
- package/dist/eventBus/userLogin.js +11 -0
- package/dist/eventBus/userLogout.d.ts +4 -0
- package/dist/eventBus/userLogout.js +11 -0
- package/dist/http/apiError.d.ts +4 -0
- package/dist/http/apiError.js +10 -0
- package/dist/http/apiRoute.d.ts +98 -0
- package/dist/http/apiRoute.js +197 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +7 -0
- package/dist/interfaces/BannerType.d.ts +5 -0
- package/dist/interfaces/BannerType.js +7 -0
- package/dist/interfaces/apiStatEvents.d.ts +1 -0
- package/dist/interfaces/apiStatEvents.js +18 -0
- package/dist/interfaces/diplomaStatus.d.ts +8 -0
- package/dist/interfaces/diplomaStatus.js +9 -0
- package/dist/interfaces/iAppStore.d.ts +1 -0
- package/dist/interfaces/iAppStore.js +2 -0
- package/dist/interfaces/iAppVersionCheck.d.ts +5 -0
- package/dist/interfaces/iAppVersionCheck.js +2 -0
- package/dist/interfaces/iArticle.d.ts +15 -0
- package/dist/interfaces/iArticle.js +2 -0
- package/dist/interfaces/iBalance.d.ts +6 -0
- package/dist/interfaces/iBalance.js +2 -0
- package/dist/interfaces/iBank.d.ts +4 -0
- package/dist/interfaces/iBank.js +2 -0
- package/dist/interfaces/iBanner.d.ts +6 -0
- package/dist/interfaces/iBanner.js +2 -0
- package/dist/interfaces/iBookmark.d.ts +3 -0
- package/dist/interfaces/iBookmark.js +2 -0
- package/dist/interfaces/iBrand.d.ts +6 -0
- package/dist/interfaces/iBrand.js +2 -0
- package/dist/interfaces/iCatalog.d.ts +50 -0
- package/dist/interfaces/iCatalog.js +2 -0
- package/dist/interfaces/iCatalogNode.d.ts +3 -0
- package/dist/interfaces/iCatalogNode.js +2 -0
- package/dist/interfaces/iCatalogPreview.d.ts +17 -0
- package/dist/interfaces/iCatalogPreview.js +2 -0
- package/dist/interfaces/iCity.d.ts +4 -0
- package/dist/interfaces/iCity.js +2 -0
- package/dist/interfaces/iContentItem.d.ts +7 -0
- package/dist/interfaces/iContentItem.js +2 -0
- package/dist/interfaces/iEnv.d.ts +6 -0
- package/dist/interfaces/iEnv.js +2 -0
- package/dist/interfaces/iFilter.d.ts +11 -0
- package/dist/interfaces/iFilter.js +2 -0
- package/dist/interfaces/iGetNodeListProps.d.ts +8 -0
- package/dist/interfaces/iGetNodeListProps.js +2 -0
- package/dist/interfaces/iInstruction.d.ts +6 -0
- package/dist/interfaces/iInstruction.js +2 -0
- package/dist/interfaces/iIntro.d.ts +6 -0
- package/dist/interfaces/iIntro.js +2 -0
- package/dist/interfaces/iMessage.d.ts +25 -0
- package/dist/interfaces/iMessage.js +2 -0
- package/dist/interfaces/iNode.d.ts +26 -0
- package/dist/interfaces/iNode.js +2 -0
- package/dist/interfaces/iNodeTree.d.ts +14 -0
- package/dist/interfaces/iNodeTree.js +2 -0
- package/dist/interfaces/iPagingItems.d.ts +9 -0
- package/dist/interfaces/iPagingItems.js +2 -0
- package/dist/interfaces/iPayment.d.ts +20 -0
- package/dist/interfaces/iPayment.js +2 -0
- package/dist/interfaces/iPush.d.ts +14 -0
- package/dist/interfaces/iPush.js +2 -0
- package/dist/interfaces/iQuestion.d.ts +7 -0
- package/dist/interfaces/iQuestion.js +2 -0
- package/dist/interfaces/iReceipt.d.ts +20 -0
- package/dist/interfaces/iReceipt.js +2 -0
- package/dist/interfaces/iReceiptAddProps.d.ts +8 -0
- package/dist/interfaces/iReceiptAddProps.js +2 -0
- package/dist/interfaces/iReceiptProduct.d.ts +7 -0
- package/dist/interfaces/iReceiptProduct.js +2 -0
- package/dist/interfaces/iSearchParams.d.ts +11 -0
- package/dist/interfaces/iSearchParams.js +2 -0
- package/dist/interfaces/iShop.d.ts +6 -0
- package/dist/interfaces/iShop.js +2 -0
- package/dist/interfaces/iShopAddress.d.ts +5 -0
- package/dist/interfaces/iShopAddress.js +2 -0
- package/dist/interfaces/iSorter.d.ts +7 -0
- package/dist/interfaces/iSorter.js +2 -0
- package/dist/interfaces/iSpecialization.d.ts +4 -0
- package/dist/interfaces/iSpecialization.js +2 -0
- package/dist/interfaces/iStatView.d.ts +4 -0
- package/dist/interfaces/iStatView.js +2 -0
- package/dist/interfaces/iStorage.d.ts +5 -0
- package/dist/interfaces/iStorage.js +2 -0
- package/dist/interfaces/iStories.d.ts +13 -0
- package/dist/interfaces/iStories.js +2 -0
- package/dist/interfaces/iSubstance.d.ts +4 -0
- package/dist/interfaces/iSubstance.js +2 -0
- package/dist/interfaces/iSurvey.d.ts +36 -0
- package/dist/interfaces/iSurvey.js +2 -0
- package/dist/interfaces/iSurveyQuestion.d.ts +11 -0
- package/dist/interfaces/iSurveyQuestion.js +2 -0
- package/dist/interfaces/iSymptoms.d.ts +4 -0
- package/dist/interfaces/iSymptoms.js +2 -0
- package/dist/interfaces/iTestQuestion.d.ts +20 -0
- package/dist/interfaces/iTestQuestion.js +2 -0
- package/dist/interfaces/iTestResult.d.ts +17 -0
- package/dist/interfaces/iTestResult.js +2 -0
- package/dist/interfaces/iText.d.ts +3 -0
- package/dist/interfaces/iText.js +2 -0
- package/dist/interfaces/iUser.d.ts +35 -0
- package/dist/interfaces/iUser.js +2 -0
- package/dist/interfaces/iUserData.d.ts +10 -0
- package/dist/interfaces/iUserData.js +2 -0
- package/dist/interfaces/iUserEditProps.d.ts +20 -0
- package/dist/interfaces/iUserEditProps.js +2 -0
- package/dist/interfaces/iUserStat.d.ts +7 -0
- package/dist/interfaces/iUserStat.js +2 -0
- package/dist/interfaces/iUserSurvey.d.ts +21 -0
- package/dist/interfaces/iUserSurvey.js +11 -0
- package/dist/interfaces/iUserTokens.d.ts +4 -0
- package/dist/interfaces/iUserTokens.js +2 -0
- package/dist/interfaces/intRange.d.ts +3 -0
- package/dist/interfaces/intRange.js +2 -0
- package/dist/interfaces/itemType.d.ts +9 -0
- package/dist/interfaces/itemType.js +11 -0
- package/dist/interfaces/paymentStatus.d.ts +7 -0
- package/dist/interfaces/paymentStatus.js +9 -0
- package/dist/interfaces/paymentType.d.ts +5 -0
- package/dist/interfaces/paymentType.js +7 -0
- package/dist/interfaces/payoutType.d.ts +5 -0
- package/dist/interfaces/payoutType.js +7 -0
- package/dist/interfaces/pushStatus.d.ts +6 -0
- package/dist/interfaces/pushStatus.js +8 -0
- package/dist/interfaces/receiptStatus.d.ts +7 -0
- package/dist/interfaces/receiptStatus.js +9 -0
- package/dist/interfaces/testStatus.d.ts +6 -0
- package/dist/interfaces/testStatus.js +7 -0
- package/dist/interfaces/userRole.d.ts +6 -0
- package/dist/interfaces/userRole.js +14 -0
- package/dist/interfaces/userStatEvent.d.ts +5 -0
- package/dist/interfaces/userStatEvent.js +7 -0
- package/dist/interfaces/viewEventType.d.ts +13 -0
- package/dist/interfaces/viewEventType.js +19 -0
- package/dist/service/webSocketClient.d.ts +21 -0
- package/dist/service/webSocketClient.js +87 -0
- package/dist/storage/default.d.ts +2 -0
- package/dist/storage/default.js +8 -0
- package/dist/storage/user.d.ts +21 -0
- package/dist/storage/user.js +107 -0
- package/dist/utils/queryString.d.ts +3 -0
- package/dist/utils/queryString.js +21 -0
- package/package.json +31 -0
- package/src/api/abstract.ts +136 -0
- package/src/api/bookmarks.ts +109 -0
- package/src/api/chat.ts +127 -0
- package/src/api/content.ts +258 -0
- package/src/api/geoIp.ts +12 -0
- package/src/api/index.ts +38 -0
- package/src/api/payment.ts +105 -0
- package/src/api/promocode.ts +18 -0
- package/src/api/push.ts +102 -0
- package/src/api/stat.ts +74 -0
- package/src/api/survey.ts +164 -0
- package/src/api/user.ts +176 -0
- package/src/eventBus/abstract.ts +33 -0
- package/src/eventBus/userLogin.ts +13 -0
- package/src/eventBus/userLogout.ts +12 -0
- package/src/http/apiError.ts +9 -0
- package/src/http/apiRoute.ts +234 -0
- package/src/index.ts +2 -0
- package/src/interfaces/BannerType.ts +6 -0
- package/src/interfaces/apiStatEvents.ts +18 -0
- package/src/interfaces/diplomaStatus.ts +10 -0
- package/src/interfaces/iAppStore.ts +1 -0
- package/src/interfaces/iArticle.ts +12 -0
- package/src/interfaces/iBalance.ts +6 -0
- package/src/interfaces/iBank.ts +4 -0
- package/src/interfaces/iBanner.ts +6 -0
- package/src/interfaces/iBookmark.ts +3 -0
- package/src/interfaces/iCity.ts +4 -0
- package/src/interfaces/iContentItem.ts +6 -0
- package/src/interfaces/iEnv.ts +6 -0
- package/src/interfaces/iFilter.ts +16 -0
- package/src/interfaces/iGetNodeListProps.ts +9 -0
- package/src/interfaces/iInstruction.ts +6 -0
- package/src/interfaces/iIntro.ts +6 -0
- package/src/interfaces/iMessage.ts +25 -0
- package/src/interfaces/iNode.ts +24 -0
- package/src/interfaces/iNodeTree.ts +14 -0
- package/src/interfaces/iPagingItems.ts +8 -0
- package/src/interfaces/iPayment.ts +28 -0
- package/src/interfaces/iPush.ts +15 -0
- package/src/interfaces/iQuestion.ts +4 -0
- package/src/interfaces/iSearchParams.ts +12 -0
- package/src/interfaces/iSorter.ts +10 -0
- package/src/interfaces/iSpecialization.ts +4 -0
- package/src/interfaces/iStatView.ts +4 -0
- package/src/interfaces/iStorage.ts +5 -0
- package/src/interfaces/iStories.ts +10 -0
- package/src/interfaces/iSubstance.ts +4 -0
- package/src/interfaces/iSurvey.ts +38 -0
- package/src/interfaces/iSurveyQuestion.ts +15 -0
- package/src/interfaces/iSymptoms.ts +4 -0
- package/src/interfaces/iTestQuestion.ts +21 -0
- package/src/interfaces/iTestResult.ts +20 -0
- package/src/interfaces/iText.ts +3 -0
- package/src/interfaces/iUser.ts +37 -0
- package/src/interfaces/iUserData.ts +10 -0
- package/src/interfaces/iUserEditProps.ts +16 -0
- package/src/interfaces/iUserStat.ts +8 -0
- package/src/interfaces/iUserSurvey.ts +23 -0
- package/src/interfaces/iUserTokens.ts +4 -0
- package/src/interfaces/intRange.ts +5 -0
- package/src/interfaces/itemType.ts +10 -0
- package/src/interfaces/paymentStatus.ts +8 -0
- package/src/interfaces/paymentType.ts +6 -0
- package/src/interfaces/payoutType.ts +6 -0
- package/src/interfaces/pushStatus.ts +7 -0
- package/src/interfaces/testStatus.ts +8 -0
- package/src/interfaces/userRole.ts +13 -0
- package/src/interfaces/userStatEvent.ts +6 -0
- package/src/interfaces/viewEventType.ts +17 -0
- package/src/service/webSocketClient.ts +94 -0
- package/src/storage/default.ts +7 -0
- package/src/storage/user.ts +109 -0
- package/src/utils/queryString.ts +22 -0
- package/tsconfig.json +27 -0
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
type OpenCallback = () => Promise<void>;
|
|
2
|
+
type MessageCallback = (message: string) => void;
|
|
3
|
+
|
|
4
|
+
export class WebSocketClient {
|
|
5
|
+
private url: string;
|
|
6
|
+
private websocket: WebSocket | null;
|
|
7
|
+
private reconnectInterval: number;
|
|
8
|
+
private reconnectAttempts: number;
|
|
9
|
+
private maxReconnectAttempts: number;
|
|
10
|
+
private isReconnecting: boolean = false
|
|
11
|
+
private sendMessageBuffer: string[] = []
|
|
12
|
+
private openCallback: OpenCallback | null = null
|
|
13
|
+
private messageCallback: MessageCallback | null = null
|
|
14
|
+
|
|
15
|
+
constructor(url: string, reconnectInterval = 1000, maxReconnectAttempts = 1000) {
|
|
16
|
+
this.url = url;
|
|
17
|
+
this.websocket = null;
|
|
18
|
+
this.reconnectInterval = reconnectInterval;
|
|
19
|
+
this.reconnectAttempts = 0;
|
|
20
|
+
this.maxReconnectAttempts = maxReconnectAttempts;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
connect() {
|
|
24
|
+
this.websocket = new WebSocket(this.url);
|
|
25
|
+
|
|
26
|
+
this.websocket.onopen = async () => {
|
|
27
|
+
console.log('Connected to WebSocket server');
|
|
28
|
+
this.reconnectAttempts = 0;
|
|
29
|
+
if (this.openCallback) await this.openCallback();//auth
|
|
30
|
+
this.send();//send MessageBuffer
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
this.websocket.onmessage = (event: MessageEvent<string>) => {
|
|
34
|
+
console.log('Received message:', event.data);
|
|
35
|
+
if (this.messageCallback) this.messageCallback(event.data);
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
this.websocket.onerror = (event) => {
|
|
39
|
+
console.error('WebSocket error:', event);
|
|
40
|
+
this.reconnect();
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
this.websocket.onclose = (event) => {
|
|
44
|
+
console.log('WebSocket connection closed:', event);
|
|
45
|
+
if (event.code != 3001) this.reconnect();
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
private reconnect() {
|
|
50
|
+
if (this.isReconnecting) return
|
|
51
|
+
this.isReconnecting = true
|
|
52
|
+
if (this.reconnectAttempts < this.maxReconnectAttempts) {
|
|
53
|
+
this.reconnectAttempts++;
|
|
54
|
+
console.log(`Reconnecting... attempt ${this.reconnectAttempts}`);
|
|
55
|
+
setTimeout(() => {
|
|
56
|
+
this.isReconnecting = false
|
|
57
|
+
this.connect()
|
|
58
|
+
}, this.reconnectInterval);
|
|
59
|
+
} else {
|
|
60
|
+
this.isReconnecting = false
|
|
61
|
+
console.error('Max reconnect attempts reached');
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
public send(message?: string, priority?: boolean) {
|
|
66
|
+
if (message && priority) this.sendMessageBuffer.unshift(message)
|
|
67
|
+
if (message && !priority) this.sendMessageBuffer.push(message)
|
|
68
|
+
if (this.websocket && this.websocket.readyState === WebSocket.OPEN) {
|
|
69
|
+
while (this.sendMessageBuffer.length) {
|
|
70
|
+
this.websocket.send(this.sendMessageBuffer.shift()!);
|
|
71
|
+
}
|
|
72
|
+
} else {
|
|
73
|
+
console.log('WebSocket is not open. reconnect');
|
|
74
|
+
this.reconnect();
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
// Устанавливаем callback для открытия соединения
|
|
79
|
+
public onOpen(callback: OpenCallback) {
|
|
80
|
+
this.openCallback = callback;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
// Устанавливаем callback для обработки входящих сообщений
|
|
84
|
+
public onMessage(callback: MessageCallback) {
|
|
85
|
+
this.messageCallback = callback;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
// Закрытие WebSocket соединения
|
|
89
|
+
public close() {
|
|
90
|
+
if (this.websocket && this.websocket.readyState === WebSocket.OPEN) {
|
|
91
|
+
this.websocket.close(3001, "Manual disconnect");
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
}
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
import { jwtDecode } from "jwt-decode"
|
|
2
|
+
import { iStorage } from "../interfaces/iStorage"
|
|
3
|
+
import { iUserData } from "../interfaces/iUserData"
|
|
4
|
+
import { storageDefault } from "./default"
|
|
5
|
+
import { eventBusUserLogout } from "../eventBus/userLogout"
|
|
6
|
+
|
|
7
|
+
export class UserStorage {
|
|
8
|
+
protected storage: iStorage
|
|
9
|
+
private user: iUserData | null = null// = user
|
|
10
|
+
private accessToken: string | null = null
|
|
11
|
+
private accessTokenExp: number | null = null//строк действия accessToken
|
|
12
|
+
private localTimeDiff: number = 0//смещение локального времени в браузере
|
|
13
|
+
|
|
14
|
+
constructor(storage?: iStorage) {
|
|
15
|
+
this.storage = storage || storageDefault
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
async getUser() {
|
|
19
|
+
if (this.user) return this.user
|
|
20
|
+
if (typeof window === 'undefined') return null//SSR
|
|
21
|
+
const userStorage = await this.storage.get('user')
|
|
22
|
+
if (typeof userStorage != "string" && userStorage !== null && userStorage !== undefined) {
|
|
23
|
+
throw new Error("Из storage получено некорректное значение пользователя. Должно быть строкой или null")
|
|
24
|
+
}
|
|
25
|
+
if (userStorage) {
|
|
26
|
+
const userStorageDecoded = JSON.parse(userStorage)
|
|
27
|
+
// check exp
|
|
28
|
+
if (this.getCurrentTime() < userStorageDecoded.exp * 1000) {//тут срок refreshToken
|
|
29
|
+
this.user = userStorageDecoded
|
|
30
|
+
return this.user
|
|
31
|
+
} else {//закончился срок refreshToken
|
|
32
|
+
await this.clearUser()
|
|
33
|
+
await eventBusUserLogout.broadcast()
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
return null
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
async setUser(accessToken: string, refreshToken: string) {
|
|
40
|
+
this.user = jwtDecode(refreshToken)
|
|
41
|
+
await this.storage.set('accessToken', accessToken)
|
|
42
|
+
await this.storage.set('refreshToken', refreshToken)
|
|
43
|
+
await this.storage.set('user', JSON.stringify(this.user))
|
|
44
|
+
return this.user
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
async saveUser({ firstname, lastname }: { firstname?: string, lastname?: string }) {
|
|
48
|
+
if (this.user) {
|
|
49
|
+
if (firstname) this.user.firstname = firstname
|
|
50
|
+
if (lastname) this.user.lastname = lastname
|
|
51
|
+
await this.storage.set('user', JSON.stringify(this.user))
|
|
52
|
+
}
|
|
53
|
+
return this.user
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
async clearUser() {
|
|
57
|
+
await this.storage.remove('accessToken')
|
|
58
|
+
await this.storage.remove('refreshToken')
|
|
59
|
+
await this.storage.remove('user')
|
|
60
|
+
this.user = null
|
|
61
|
+
this.accessToken = null
|
|
62
|
+
this.accessTokenExp = null
|
|
63
|
+
this.localTimeDiff = 0
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
private getCurrentTime() {
|
|
67
|
+
return Date.now() + this.localTimeDiff
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
async getAccessToken(): Promise<string | null> {
|
|
71
|
+
if (typeof window === 'undefined') return null//SSR
|
|
72
|
+
|
|
73
|
+
//кэш с проверкой срока действия
|
|
74
|
+
if (this.accessToken && this.accessTokenExp && this.localTimeDiff && this.getCurrentTime() < this.accessTokenExp * 1000) {
|
|
75
|
+
return this.accessToken
|
|
76
|
+
}
|
|
77
|
+
//создаем кэш
|
|
78
|
+
this.accessToken = await this.storage.get('accessToken')
|
|
79
|
+
if (typeof this.accessToken != "string" && this.accessToken !== null && this.accessToken !== undefined) {
|
|
80
|
+
throw new Error("Из storage получено некорректное значение accessToken. Должно быть строкой или null")
|
|
81
|
+
}
|
|
82
|
+
if (!this.accessToken) return null;//токена нет
|
|
83
|
+
const accessTokenDecoded: iUserData | null = jwtDecode(this.accessToken)
|
|
84
|
+
this.localTimeDiff = accessTokenDecoded?.localTimeDiff ?? 0
|
|
85
|
+
this.accessTokenExp = accessTokenDecoded?.exp ?? null
|
|
86
|
+
if (accessTokenDecoded?.exp && this.getCurrentTime() < accessTokenDecoded.exp * 1000) {
|
|
87
|
+
return this.accessToken
|
|
88
|
+
}
|
|
89
|
+
return null
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
async getRefreshToken(): Promise<string | null> {
|
|
93
|
+
if (typeof window === 'undefined') return null//SSR
|
|
94
|
+
|
|
95
|
+
const refreshTokenData = await this.getUser()//возвращает раскодированный refreshToken и проверяет его дату
|
|
96
|
+
if (refreshTokenData) {
|
|
97
|
+
const refreshToken = await this.storage.get('refreshToken')
|
|
98
|
+
if (typeof refreshToken != "string" && refreshToken !== null && refreshToken !== undefined) {
|
|
99
|
+
throw new Error("Из storage получено некорректное значение refreshToken. Должно быть строкой или null")
|
|
100
|
+
}
|
|
101
|
+
if (refreshToken) return refreshToken
|
|
102
|
+
}
|
|
103
|
+
return null
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
async isAuth() {
|
|
107
|
+
return !!(await this.getUser())
|
|
108
|
+
}
|
|
109
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
export function queryString(initialObj: { [key: string] : any} ) {
|
|
2
|
+
const reducer = (obj: { [key: string] : any}, parentPrefix: string | null = null) => (prev:any, key:string) => {
|
|
3
|
+
const val = obj[key];
|
|
4
|
+
key = encodeURIComponent(key);
|
|
5
|
+
const prefix = parentPrefix ? `${parentPrefix}[${key}]` : key;
|
|
6
|
+
|
|
7
|
+
if (val == null || typeof val === 'function') {
|
|
8
|
+
prev.push(`${prefix}=`);
|
|
9
|
+
return prev;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
if (['number', 'boolean', 'string'].includes(typeof val)) {
|
|
13
|
+
prev.push(`${prefix}=${encodeURIComponent(val)}`);
|
|
14
|
+
return prev;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
prev.push(Object.keys(val).reduce(reducer(val, prefix), []).join('&'));
|
|
18
|
+
return prev;
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
return Object.keys(initialObj).reduce(reducer(initialObj), []).join('&');
|
|
22
|
+
}
|
package/tsconfig.json
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"target": "es2021",
|
|
4
|
+
"module": "NodeNext",
|
|
5
|
+
"declaration": true,
|
|
6
|
+
"outDir": "./dist",
|
|
7
|
+
"noEmit": false,
|
|
8
|
+
"strict": true,
|
|
9
|
+
"noImplicitAny": true,
|
|
10
|
+
"strictNullChecks": true,
|
|
11
|
+
"strictFunctionTypes": true,
|
|
12
|
+
"strictBindCallApply": true,
|
|
13
|
+
"strictPropertyInitialization": true,
|
|
14
|
+
"noImplicitThis": true,
|
|
15
|
+
"alwaysStrict": true,
|
|
16
|
+
"noUnusedLocals": true,
|
|
17
|
+
"noUnusedParameters": true,
|
|
18
|
+
"noImplicitReturns": true,
|
|
19
|
+
"noFallthroughCasesInSwitch": true,
|
|
20
|
+
"noUncheckedIndexedAccess": true,
|
|
21
|
+
"noImplicitOverride": true,
|
|
22
|
+
"noPropertyAccessFromIndexSignature": true,
|
|
23
|
+
"esModuleInterop": true,
|
|
24
|
+
"forceConsistentCasingInFileNames": true,
|
|
25
|
+
"skipLibCheck": true
|
|
26
|
+
}
|
|
27
|
+
}
|