@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.
Files changed (250) hide show
  1. package/.cursor/rules/apcheki_sdk.mdc +90 -0
  2. package/README.md +136 -0
  3. package/dist/api/abstract.d.ts +21 -0
  4. package/dist/api/abstract.js +125 -0
  5. package/dist/api/bookmarks.d.ts +28 -0
  6. package/dist/api/bookmarks.js +121 -0
  7. package/dist/api/chat.d.ts +30 -0
  8. package/dist/api/chat.js +118 -0
  9. package/dist/api/content.d.ts +154 -0
  10. package/dist/api/content.js +237 -0
  11. package/dist/api/geoIp.d.ts +8 -0
  12. package/dist/api/geoIp.js +14 -0
  13. package/dist/api/index.d.ts +27 -0
  14. package/dist/api/index.js +31 -0
  15. package/dist/api/payment.d.ts +54 -0
  16. package/dist/api/payment.js +90 -0
  17. package/dist/api/promocode.d.ts +9 -0
  18. package/dist/api/promocode.js +22 -0
  19. package/dist/api/push.d.ts +54 -0
  20. package/dist/api/push.js +99 -0
  21. package/dist/api/receipt.d.ts +34 -0
  22. package/dist/api/receipt.js +60 -0
  23. package/dist/api/stat.d.ts +21 -0
  24. package/dist/api/stat.js +75 -0
  25. package/dist/api/survey.d.ts +82 -0
  26. package/dist/api/survey.js +122 -0
  27. package/dist/api/user.d.ts +80 -0
  28. package/dist/api/user.js +167 -0
  29. package/dist/eventBus/abstract.d.ts +4 -0
  30. package/dist/eventBus/abstract.js +29 -0
  31. package/dist/eventBus/userLogin.d.ts +5 -0
  32. package/dist/eventBus/userLogin.js +11 -0
  33. package/dist/eventBus/userLogout.d.ts +4 -0
  34. package/dist/eventBus/userLogout.js +11 -0
  35. package/dist/http/apiError.d.ts +4 -0
  36. package/dist/http/apiError.js +10 -0
  37. package/dist/http/apiRoute.d.ts +98 -0
  38. package/dist/http/apiRoute.js +197 -0
  39. package/dist/index.d.ts +2 -0
  40. package/dist/index.js +7 -0
  41. package/dist/interfaces/BannerType.d.ts +5 -0
  42. package/dist/interfaces/BannerType.js +7 -0
  43. package/dist/interfaces/apiStatEvents.d.ts +1 -0
  44. package/dist/interfaces/apiStatEvents.js +18 -0
  45. package/dist/interfaces/diplomaStatus.d.ts +8 -0
  46. package/dist/interfaces/diplomaStatus.js +9 -0
  47. package/dist/interfaces/iAppStore.d.ts +1 -0
  48. package/dist/interfaces/iAppStore.js +2 -0
  49. package/dist/interfaces/iAppVersionCheck.d.ts +5 -0
  50. package/dist/interfaces/iAppVersionCheck.js +2 -0
  51. package/dist/interfaces/iArticle.d.ts +15 -0
  52. package/dist/interfaces/iArticle.js +2 -0
  53. package/dist/interfaces/iBalance.d.ts +6 -0
  54. package/dist/interfaces/iBalance.js +2 -0
  55. package/dist/interfaces/iBank.d.ts +4 -0
  56. package/dist/interfaces/iBank.js +2 -0
  57. package/dist/interfaces/iBanner.d.ts +6 -0
  58. package/dist/interfaces/iBanner.js +2 -0
  59. package/dist/interfaces/iBookmark.d.ts +3 -0
  60. package/dist/interfaces/iBookmark.js +2 -0
  61. package/dist/interfaces/iBrand.d.ts +6 -0
  62. package/dist/interfaces/iBrand.js +2 -0
  63. package/dist/interfaces/iCatalog.d.ts +50 -0
  64. package/dist/interfaces/iCatalog.js +2 -0
  65. package/dist/interfaces/iCatalogNode.d.ts +3 -0
  66. package/dist/interfaces/iCatalogNode.js +2 -0
  67. package/dist/interfaces/iCatalogPreview.d.ts +17 -0
  68. package/dist/interfaces/iCatalogPreview.js +2 -0
  69. package/dist/interfaces/iCity.d.ts +4 -0
  70. package/dist/interfaces/iCity.js +2 -0
  71. package/dist/interfaces/iContentItem.d.ts +7 -0
  72. package/dist/interfaces/iContentItem.js +2 -0
  73. package/dist/interfaces/iEnv.d.ts +6 -0
  74. package/dist/interfaces/iEnv.js +2 -0
  75. package/dist/interfaces/iFilter.d.ts +11 -0
  76. package/dist/interfaces/iFilter.js +2 -0
  77. package/dist/interfaces/iGetNodeListProps.d.ts +8 -0
  78. package/dist/interfaces/iGetNodeListProps.js +2 -0
  79. package/dist/interfaces/iInstruction.d.ts +6 -0
  80. package/dist/interfaces/iInstruction.js +2 -0
  81. package/dist/interfaces/iIntro.d.ts +6 -0
  82. package/dist/interfaces/iIntro.js +2 -0
  83. package/dist/interfaces/iMessage.d.ts +25 -0
  84. package/dist/interfaces/iMessage.js +2 -0
  85. package/dist/interfaces/iNode.d.ts +26 -0
  86. package/dist/interfaces/iNode.js +2 -0
  87. package/dist/interfaces/iNodeTree.d.ts +14 -0
  88. package/dist/interfaces/iNodeTree.js +2 -0
  89. package/dist/interfaces/iPagingItems.d.ts +9 -0
  90. package/dist/interfaces/iPagingItems.js +2 -0
  91. package/dist/interfaces/iPayment.d.ts +20 -0
  92. package/dist/interfaces/iPayment.js +2 -0
  93. package/dist/interfaces/iPush.d.ts +14 -0
  94. package/dist/interfaces/iPush.js +2 -0
  95. package/dist/interfaces/iQuestion.d.ts +7 -0
  96. package/dist/interfaces/iQuestion.js +2 -0
  97. package/dist/interfaces/iReceipt.d.ts +20 -0
  98. package/dist/interfaces/iReceipt.js +2 -0
  99. package/dist/interfaces/iReceiptAddProps.d.ts +8 -0
  100. package/dist/interfaces/iReceiptAddProps.js +2 -0
  101. package/dist/interfaces/iReceiptProduct.d.ts +7 -0
  102. package/dist/interfaces/iReceiptProduct.js +2 -0
  103. package/dist/interfaces/iSearchParams.d.ts +11 -0
  104. package/dist/interfaces/iSearchParams.js +2 -0
  105. package/dist/interfaces/iShop.d.ts +6 -0
  106. package/dist/interfaces/iShop.js +2 -0
  107. package/dist/interfaces/iShopAddress.d.ts +5 -0
  108. package/dist/interfaces/iShopAddress.js +2 -0
  109. package/dist/interfaces/iSorter.d.ts +7 -0
  110. package/dist/interfaces/iSorter.js +2 -0
  111. package/dist/interfaces/iSpecialization.d.ts +4 -0
  112. package/dist/interfaces/iSpecialization.js +2 -0
  113. package/dist/interfaces/iStatView.d.ts +4 -0
  114. package/dist/interfaces/iStatView.js +2 -0
  115. package/dist/interfaces/iStorage.d.ts +5 -0
  116. package/dist/interfaces/iStorage.js +2 -0
  117. package/dist/interfaces/iStories.d.ts +13 -0
  118. package/dist/interfaces/iStories.js +2 -0
  119. package/dist/interfaces/iSubstance.d.ts +4 -0
  120. package/dist/interfaces/iSubstance.js +2 -0
  121. package/dist/interfaces/iSurvey.d.ts +36 -0
  122. package/dist/interfaces/iSurvey.js +2 -0
  123. package/dist/interfaces/iSurveyQuestion.d.ts +11 -0
  124. package/dist/interfaces/iSurveyQuestion.js +2 -0
  125. package/dist/interfaces/iSymptoms.d.ts +4 -0
  126. package/dist/interfaces/iSymptoms.js +2 -0
  127. package/dist/interfaces/iTestQuestion.d.ts +20 -0
  128. package/dist/interfaces/iTestQuestion.js +2 -0
  129. package/dist/interfaces/iTestResult.d.ts +17 -0
  130. package/dist/interfaces/iTestResult.js +2 -0
  131. package/dist/interfaces/iText.d.ts +3 -0
  132. package/dist/interfaces/iText.js +2 -0
  133. package/dist/interfaces/iUser.d.ts +35 -0
  134. package/dist/interfaces/iUser.js +2 -0
  135. package/dist/interfaces/iUserData.d.ts +10 -0
  136. package/dist/interfaces/iUserData.js +2 -0
  137. package/dist/interfaces/iUserEditProps.d.ts +20 -0
  138. package/dist/interfaces/iUserEditProps.js +2 -0
  139. package/dist/interfaces/iUserStat.d.ts +7 -0
  140. package/dist/interfaces/iUserStat.js +2 -0
  141. package/dist/interfaces/iUserSurvey.d.ts +21 -0
  142. package/dist/interfaces/iUserSurvey.js +11 -0
  143. package/dist/interfaces/iUserTokens.d.ts +4 -0
  144. package/dist/interfaces/iUserTokens.js +2 -0
  145. package/dist/interfaces/intRange.d.ts +3 -0
  146. package/dist/interfaces/intRange.js +2 -0
  147. package/dist/interfaces/itemType.d.ts +9 -0
  148. package/dist/interfaces/itemType.js +11 -0
  149. package/dist/interfaces/paymentStatus.d.ts +7 -0
  150. package/dist/interfaces/paymentStatus.js +9 -0
  151. package/dist/interfaces/paymentType.d.ts +5 -0
  152. package/dist/interfaces/paymentType.js +7 -0
  153. package/dist/interfaces/payoutType.d.ts +5 -0
  154. package/dist/interfaces/payoutType.js +7 -0
  155. package/dist/interfaces/pushStatus.d.ts +6 -0
  156. package/dist/interfaces/pushStatus.js +8 -0
  157. package/dist/interfaces/receiptStatus.d.ts +7 -0
  158. package/dist/interfaces/receiptStatus.js +9 -0
  159. package/dist/interfaces/testStatus.d.ts +6 -0
  160. package/dist/interfaces/testStatus.js +7 -0
  161. package/dist/interfaces/userRole.d.ts +6 -0
  162. package/dist/interfaces/userRole.js +14 -0
  163. package/dist/interfaces/userStatEvent.d.ts +5 -0
  164. package/dist/interfaces/userStatEvent.js +7 -0
  165. package/dist/interfaces/viewEventType.d.ts +13 -0
  166. package/dist/interfaces/viewEventType.js +19 -0
  167. package/dist/service/webSocketClient.d.ts +21 -0
  168. package/dist/service/webSocketClient.js +87 -0
  169. package/dist/storage/default.d.ts +2 -0
  170. package/dist/storage/default.js +8 -0
  171. package/dist/storage/user.d.ts +21 -0
  172. package/dist/storage/user.js +107 -0
  173. package/dist/utils/queryString.d.ts +3 -0
  174. package/dist/utils/queryString.js +21 -0
  175. package/package.json +31 -0
  176. package/src/api/abstract.ts +136 -0
  177. package/src/api/bookmarks.ts +109 -0
  178. package/src/api/chat.ts +127 -0
  179. package/src/api/content.ts +258 -0
  180. package/src/api/geoIp.ts +12 -0
  181. package/src/api/index.ts +38 -0
  182. package/src/api/payment.ts +105 -0
  183. package/src/api/promocode.ts +18 -0
  184. package/src/api/push.ts +102 -0
  185. package/src/api/stat.ts +74 -0
  186. package/src/api/survey.ts +164 -0
  187. package/src/api/user.ts +176 -0
  188. package/src/eventBus/abstract.ts +33 -0
  189. package/src/eventBus/userLogin.ts +13 -0
  190. package/src/eventBus/userLogout.ts +12 -0
  191. package/src/http/apiError.ts +9 -0
  192. package/src/http/apiRoute.ts +234 -0
  193. package/src/index.ts +2 -0
  194. package/src/interfaces/BannerType.ts +6 -0
  195. package/src/interfaces/apiStatEvents.ts +18 -0
  196. package/src/interfaces/diplomaStatus.ts +10 -0
  197. package/src/interfaces/iAppStore.ts +1 -0
  198. package/src/interfaces/iArticle.ts +12 -0
  199. package/src/interfaces/iBalance.ts +6 -0
  200. package/src/interfaces/iBank.ts +4 -0
  201. package/src/interfaces/iBanner.ts +6 -0
  202. package/src/interfaces/iBookmark.ts +3 -0
  203. package/src/interfaces/iCity.ts +4 -0
  204. package/src/interfaces/iContentItem.ts +6 -0
  205. package/src/interfaces/iEnv.ts +6 -0
  206. package/src/interfaces/iFilter.ts +16 -0
  207. package/src/interfaces/iGetNodeListProps.ts +9 -0
  208. package/src/interfaces/iInstruction.ts +6 -0
  209. package/src/interfaces/iIntro.ts +6 -0
  210. package/src/interfaces/iMessage.ts +25 -0
  211. package/src/interfaces/iNode.ts +24 -0
  212. package/src/interfaces/iNodeTree.ts +14 -0
  213. package/src/interfaces/iPagingItems.ts +8 -0
  214. package/src/interfaces/iPayment.ts +28 -0
  215. package/src/interfaces/iPush.ts +15 -0
  216. package/src/interfaces/iQuestion.ts +4 -0
  217. package/src/interfaces/iSearchParams.ts +12 -0
  218. package/src/interfaces/iSorter.ts +10 -0
  219. package/src/interfaces/iSpecialization.ts +4 -0
  220. package/src/interfaces/iStatView.ts +4 -0
  221. package/src/interfaces/iStorage.ts +5 -0
  222. package/src/interfaces/iStories.ts +10 -0
  223. package/src/interfaces/iSubstance.ts +4 -0
  224. package/src/interfaces/iSurvey.ts +38 -0
  225. package/src/interfaces/iSurveyQuestion.ts +15 -0
  226. package/src/interfaces/iSymptoms.ts +4 -0
  227. package/src/interfaces/iTestQuestion.ts +21 -0
  228. package/src/interfaces/iTestResult.ts +20 -0
  229. package/src/interfaces/iText.ts +3 -0
  230. package/src/interfaces/iUser.ts +37 -0
  231. package/src/interfaces/iUserData.ts +10 -0
  232. package/src/interfaces/iUserEditProps.ts +16 -0
  233. package/src/interfaces/iUserStat.ts +8 -0
  234. package/src/interfaces/iUserSurvey.ts +23 -0
  235. package/src/interfaces/iUserTokens.ts +4 -0
  236. package/src/interfaces/intRange.ts +5 -0
  237. package/src/interfaces/itemType.ts +10 -0
  238. package/src/interfaces/paymentStatus.ts +8 -0
  239. package/src/interfaces/paymentType.ts +6 -0
  240. package/src/interfaces/payoutType.ts +6 -0
  241. package/src/interfaces/pushStatus.ts +7 -0
  242. package/src/interfaces/testStatus.ts +8 -0
  243. package/src/interfaces/userRole.ts +13 -0
  244. package/src/interfaces/userStatEvent.ts +6 -0
  245. package/src/interfaces/viewEventType.ts +17 -0
  246. package/src/service/webSocketClient.ts +94 -0
  247. package/src/storage/default.ts +7 -0
  248. package/src/storage/user.ts +109 -0
  249. package/src/utils/queryString.ts +22 -0
  250. 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,7 @@
1
+ import { iStorage } from "../interfaces/iStorage";
2
+
3
+ export const storageDefault: iStorage = {
4
+ set: async (key, data) => localStorage.setItem(key, data),
5
+ get: async (key) => localStorage.getItem(key),
6
+ remove: async (key) => localStorage.removeItem(key),
7
+ }
@@ -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
+ }