@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,258 @@
1
+ import { apiRouteBannerGetRand, apiRouteCheckAppVersion, apiRouteEnv, apiRouteGetCloudVersion, apiRouteItemById, apiRouteList, apiRouteNode, apiRouteNodeTree } from "../http/apiRoute"
2
+ import { iArticle } from "../interfaces/iArticle"
3
+ import { iBank } from "../interfaces/iBank"
4
+ import { iBanner } from "../interfaces/iBanner"
5
+ import { BannerType, BannerTypeKeys } from "../interfaces/BannerType"
6
+ import { iCity } from "../interfaces/iCity"
7
+ import { iContentItem } from "../interfaces/iContentItem"
8
+ import { iFilter } from "../interfaces/iFilter"
9
+ import { iInstruction } from "../interfaces/iInstruction"
10
+ import { iNode } from "../interfaces/iNode"
11
+ import { iNodeTree } from "../interfaces/iNodeTree"
12
+ import { iPagingItems } from "../interfaces/iPagingItems"
13
+ import { iSearchParams } from "../interfaces/iSearchParams"
14
+ import { iText } from "../interfaces/iText"
15
+ import { ApiAbstract } from "./abstract"
16
+ import { iStories } from "../interfaces/iStories"
17
+ import { iEnv } from "../interfaces/iEnv"
18
+ import { iIntro } from "../interfaces/iIntro"
19
+ import { iAppStore } from "../interfaces/iAppStore"
20
+ import { iSpecialization } from "../interfaces/iSpecialization"
21
+
22
+ export class ApiContent extends ApiAbstract {
23
+ /**
24
+ * получение настроек, включая размер реферальных вознаграждений
25
+ */
26
+ async getEnv() {
27
+ return this.fetcher<iEnv>({ route: apiRouteEnv })
28
+ }
29
+ /**
30
+ * проверка актуальности версии приложения
31
+ * @param {number} params.appStore - магазин приложения "App Store" или "Google Play"
32
+ * @param {boolean} params.appVersion - версия приложения, например 1.0.0
33
+ */
34
+ async checkAppVersion({ appStore, appVersion }: { appStore: iAppStore, appVersion: string }) {
35
+ return this.fetcher<{ isActual: boolean }>({ route: apiRouteCheckAppVersion(appStore, appVersion) })
36
+ }
37
+ /**
38
+ * получение версии приложения для конкретной операционной системы
39
+ * @param {string} os - операционная система "ios" или "android"
40
+ */
41
+ async getCloudVersion(appStore: iAppStore) {
42
+ return this.fetcher<any>({ route: apiRouteGetCloudVersion(appStore) })
43
+ }
44
+ /**
45
+ * получение дерева категорий. не обязательный параметр
46
+ * @param {string} parent id категории от которой строится вложенность
47
+ */
48
+ async getNodeTree(parent?: number) {
49
+ return this.fetcher<iNodeTree[]>({ route: apiRouteNodeTree(parent) })
50
+ }
51
+ /**
52
+ * получение раздела
53
+ */
54
+ private async getNodeByCode<T>(nodeCode: string) {
55
+ return this.fetcher<iNode<T>>({
56
+ route: apiRouteNode(nodeCode)
57
+ })
58
+ }
59
+ /**
60
+ * получение списка статей
61
+ */
62
+ async getArticleList<Keys extends keyof iArticle>({
63
+ select,
64
+ page = 1,//отсчет страниц с первой, чтобы не было путаницы
65
+ filters,
66
+ sorters,
67
+ perPage = 10,
68
+ }: iSearchParams<iArticle, Keys>) {
69
+ return this.fetcher<iPagingItems<Pick<iArticle, Keys> & { url?: string }>>({
70
+ route: apiRouteList({
71
+ nodeCode: "articles",
72
+ page,
73
+ select,
74
+ filters,
75
+ sorters,
76
+ perPage,
77
+ })
78
+ })
79
+ }
80
+ /**
81
+ * получение одной статьи
82
+ */
83
+ async getArticleOne({ id }: { id: number }) {
84
+ return this.fetcher<iContentItem<iArticle>>({
85
+ route: apiRouteItemById("articles", id)
86
+ })
87
+ }
88
+ /**
89
+ * политика конфиденциальности
90
+ */
91
+ async getPolicy() {
92
+ return this.getNodeByCode<iText>("policy")
93
+ }
94
+ /**
95
+ * оферта
96
+ */
97
+ async getTerms() {
98
+ return this.getNodeByCode<iText>("terms")
99
+ }
100
+ /**
101
+ * Правила программы лояльности
102
+ */
103
+ async getLoyalty() {
104
+ return this.getNodeByCode<iText>("loyalty")
105
+ }
106
+ /**
107
+ * как получить деньги
108
+ */
109
+ async getInstruction() {
110
+ return await this.fetcher<iPagingItems<iInstruction>>({
111
+ route: apiRouteList({
112
+ nodeCode: "instruction",
113
+ select: ["id", "title", "text", "image"],
114
+ sorters: ["sorter asc"],
115
+ perPage: 100,
116
+ })
117
+ })
118
+
119
+ }
120
+ /**
121
+ * Согласие на обработку персональных данных
122
+ */
123
+ async getAgreement() {
124
+ return this.getNodeByCode<iText>("agreement")
125
+ }
126
+ /**
127
+ * банки для выбора при запросе на вывод средств
128
+ * @param {number} props.page - страница. Отсчет страниц с первой, чтобы не было путаницы
129
+ * @param {string} props.searchTitle - поисковая строка по началу названия банка
130
+ */
131
+ async getBanks({ page, searchTitle }: { page: number, searchTitle?: string }) {
132
+ const filters: iFilter<iBank> = {}
133
+ if (searchTitle?.length) filters.title = [searchTitle + "%"]
134
+ return await this.fetcher<iPagingItems<iInstruction>>({
135
+ route: apiRouteList({
136
+ nodeCode: "bank",
137
+ select: ["id", "title"],
138
+ sorters: ["sorter asc", "title asc"],
139
+ perPage: 10,
140
+ filters,
141
+ page
142
+ })
143
+ })
144
+ }
145
+ /**
146
+ * получение списка специализаций врачей
147
+ * @param {number} props.page - страница. Отсчет страниц с первой, чтобы не было путаницы
148
+ * @param {string} props.searchTitle - поисковая строка по началу названия банка
149
+ */
150
+ async getSpecializationList({ page, searchTitle }: { page: number, searchTitle?: string }) {
151
+ const filters: iFilter<iSpecialization> = {}
152
+ if (searchTitle?.length) filters.title = [searchTitle + "%"]
153
+ return await this.fetcher<iPagingItems<iInstruction>>({
154
+ route: apiRouteList({
155
+ nodeCode: "specialization",
156
+ select: ["id", "title"],
157
+ sorters: ["sorter asc", "title asc"],
158
+ perPage: 10,
159
+ filters,
160
+ page
161
+ })
162
+ })
163
+ }
164
+ /**
165
+ * поиск города
166
+ * @param {number} props.page - страница. Отсчет страниц с первой, чтобы не было путаницы
167
+ * @param {string} props.searchTitle - поисковая строка по началу названия банка
168
+ */
169
+ async getCityList({ page, searchTitle }: { page: number, searchTitle?: string }) {
170
+ const filters: iFilter<iCity> = {}
171
+ if (searchTitle?.length) filters.title = [searchTitle + "%"]
172
+ return await this.fetcher<iPagingItems<iCity>>({
173
+ route: apiRouteList({
174
+ nodeCode: "city",
175
+ select: ["id", "title"],
176
+ sorters: ["sorter asc"],
177
+ perPage: 20,
178
+ filters,
179
+ page
180
+ })
181
+ })
182
+ }
183
+ /**
184
+ * получение одного города
185
+ */
186
+ async getCityOne({ id }: { id: number }) {
187
+ return this.fetcher<iContentItem<iArticle>>({
188
+ route: apiRouteItemById("city", id)
189
+ })
190
+ }
191
+ /**
192
+ * баннер
193
+ * @param {number} props.type - тип баннера
194
+ */
195
+ async getBannerRand({ type, signal }: { type: typeof BannerType[BannerTypeKeys], signal?: AbortSignal }) {
196
+ return await this.fetcher<{ item: iBanner | undefined }>({
197
+ route: apiRouteBannerGetRand(type),
198
+ options: { addToken: true, signal }
199
+ })
200
+ }
201
+ /**
202
+ * получение списка сторисов
203
+ */
204
+ async getStoriesList<Keys extends keyof iStories>({
205
+ select,
206
+ page = 1,//отсчет страниц с первой, чтобы не было путаницы
207
+ perPage = 10,
208
+ }: iSearchParams<iStories, Keys>): Promise<iPagingItems<Pick<iStories, Keys>>> {
209
+ const data = await this.fetcher<iPagingItems<Pick<iStories, Keys> & { sku: { id: number, title: string } | null }>>({
210
+ route: apiRouteList({
211
+ nodeCode: "stories",
212
+ page,
213
+ select,
214
+ perPage,
215
+ }),
216
+ options: { addToken: true }
217
+ })
218
+ return {
219
+ ...data,
220
+ items: data.items.map(it => ({
221
+ ...it,
222
+ sku: it?.sku
223
+ ? { id: it.sku.id, title: it.sku.title }
224
+ : null
225
+ }))
226
+ }
227
+ }
228
+ /**
229
+ * получение одного сториса
230
+ */
231
+ async getStoriesOne({ id }: { id: number }): Promise<iContentItem<iStories>> {
232
+ const data = await this.fetcher<iContentItem<iStories>>({
233
+ route: apiRouteItemById("stories", id)
234
+ })
235
+ return {
236
+ ...data,
237
+ item: {
238
+ ...data.item,
239
+ sku: data.item?.sku
240
+ ? { id: data.item.sku.id, title: data.item.sku.title }
241
+ : null
242
+ }
243
+ }
244
+ }
245
+ /**
246
+ * получение списка интро (приветственная инструкция)
247
+ */
248
+ async getIntro() {
249
+ return this.fetcher<iPagingItems<iIntro>>({
250
+ route: apiRouteList({
251
+ nodeCode: "intro",
252
+ select: ["id", "title", "image"],
253
+ sorters: ["sorter asc"],
254
+ perPage: 50,
255
+ })
256
+ })
257
+ }
258
+ }
@@ -0,0 +1,12 @@
1
+ import { apiRouteGeoDetect } from "../http/apiRoute";
2
+ import { iCity } from "../interfaces/iCity";
3
+ import { ApiAbstract } from "./abstract";
4
+
5
+ export class ApiGeoIp extends ApiAbstract {
6
+ /**
7
+ * определение города по ip
8
+ */
9
+ async detect() {
10
+ return this.fetcher<iCity>({ route: apiRouteGeoDetect })
11
+ }
12
+ }
@@ -0,0 +1,38 @@
1
+ import { iStorage } from "../interfaces/iStorage";
2
+ import { storageDefault } from "../storage/default";
3
+ import { UserStorage } from "../storage/user";
4
+ import { ApiBookmarks } from "./bookmarks";
5
+ import { ApiChat } from "./chat";
6
+ import { ApiContent } from "./content";
7
+ import { ApiGeoIp } from "./geoIp";
8
+ import { ApiPayment } from "./payment";
9
+ import { ApiPromocode } from "./promocode";
10
+ import { ApiPush } from "./push";
11
+ import { ApiSurvey } from "./survey";
12
+ import { ApiStat } from "./stat";
13
+ import { ApiUser } from "./user";
14
+
15
+ export function createClient({
16
+ host,
17
+ wsHost,
18
+ storage
19
+ }: {
20
+ host: string,
21
+ wsHost: string,
22
+ storage?: iStorage
23
+ }) {
24
+ const userStorage = new UserStorage(storage || storageDefault)
25
+ const constructorProps = { host, wsHost, userStorage }
26
+ return {
27
+ user: new ApiUser(constructorProps),
28
+ content: new ApiContent(constructorProps),
29
+ geoIp: new ApiGeoIp(constructorProps),
30
+ survey: new ApiSurvey(constructorProps),
31
+ payment: new ApiPayment(constructorProps),
32
+ stat: new ApiStat(constructorProps),
33
+ chat: new ApiChat(constructorProps),
34
+ bookmarks: new ApiBookmarks(constructorProps),
35
+ push: new ApiPush(constructorProps),
36
+ promocode: new ApiPromocode(constructorProps),
37
+ }
38
+ }
@@ -0,0 +1,105 @@
1
+ import { ApiAbstract } from "./abstract"
2
+ import {
3
+ apiRoutePaymentAdd,
4
+ apiRoutePaymentBalance,
5
+ apiRoutePaymentList,
6
+ apiRoutePaymentVerificationUrl,
7
+ apiRoutePaymentVerificationStatus
8
+ } from "../http/apiRoute"
9
+ import { iPagingItems } from "../interfaces/iPagingItems"
10
+ import { iPayment } from "../interfaces/iPayment"
11
+ import { PayoutType } from "../interfaces/payoutType"
12
+ import { ApiError } from "../http/apiError"
13
+ import { iBalance } from "../interfaces/iBalance"
14
+
15
+ export class ApiPayment extends ApiAbstract {
16
+ /**
17
+ * добавление запроса на выплату по системе быстрых платежей
18
+ * * @param {number} props.sum - сумма выплаты
19
+ * * @param {number} props.bank - id банка из справочника content.getBanks
20
+ */
21
+ async addSBP(props: { sum: number, bank: number }) {
22
+ if (!await this.userStorage.isAuth()) throw new ApiError(401, "Пользователь не авторизован")
23
+ const data = await this.fetcher<{ payment: iPayment }>({
24
+ route: apiRoutePaymentAdd,
25
+ postBody: { ...props, type: PayoutType.sbp },
26
+ options: { addToken: true }
27
+ })
28
+ return data.payment
29
+ }
30
+ /**
31
+ * добавление запроса на выплату по номеру карты
32
+ * * @param {number} props.sum - сумма выплаты
33
+ * * @param {number} props.card_number - номер карты
34
+ */
35
+ async addCard(props: { sum: number, card_number: number }) {
36
+ if (!await this.userStorage.isAuth()) throw new ApiError(401, "Пользователь не авторизован")
37
+ const data = await this.fetcher<{ payment: iPayment }>({
38
+ route: apiRoutePaymentAdd,
39
+ postBody: { ...props, type: PayoutType.card },
40
+ options: { addToken: true }
41
+ })
42
+ return data.payment
43
+ }
44
+ /**
45
+ * список начислений
46
+ * * @param {number} page - отсчет страниц с первой, чтобы не было путаницы
47
+ */
48
+ async getList<Keys extends keyof iPayment>({
49
+ page = 1,
50
+ select,
51
+ }: {
52
+ page: number
53
+ select: Keys[],
54
+ }) {
55
+ if (!await this.userStorage.isAuth()) throw new ApiError(401, "Пользователь не авторизован")
56
+ return await this.fetcher<iPagingItems<Pick<iPayment, Keys>>>({
57
+ route: apiRoutePaymentList({
58
+ page,
59
+ sorters: ["id desc"],
60
+ select
61
+ }),
62
+ options: { addToken: true }
63
+ })
64
+ }
65
+ /**
66
+ * баланс пользователя
67
+ */
68
+ async balance() {
69
+ if (!await this.userStorage.isAuth()) throw new ApiError(401, "Пользователь не авторизован")
70
+ return await this.fetcher<iBalance>({
71
+ route: apiRoutePaymentBalance,
72
+ options: { addToken: true }
73
+ })
74
+ }
75
+
76
+ /**
77
+ * Получить URL для верификации в SolarStaff
78
+ * Необходимо для получения выплат
79
+ */
80
+ async getVerificationUrl() {
81
+ if (!await this.userStorage.isAuth()) throw new ApiError(401, "Пользователь не авторизован")
82
+ return await this.fetcher<{
83
+ url: string,
84
+ verified: boolean
85
+ }>({
86
+ route: apiRoutePaymentVerificationUrl,
87
+ options: { addToken: true }
88
+ })
89
+ }
90
+
91
+ /**
92
+ * Проверить статус верификации пользователя в SolarStaff
93
+ */
94
+ async checkVerificationStatus() {
95
+ if (!await this.userStorage.isAuth()) throw new ApiError(401, "Пользователь не авторизован")
96
+ return await this.fetcher<{
97
+ verified: boolean,
98
+ status: "not_started" | "pending" | "active" | "blocked",
99
+ message: string
100
+ }>({
101
+ route: apiRoutePaymentVerificationStatus,
102
+ options: { addToken: true }
103
+ })
104
+ }
105
+ }
@@ -0,0 +1,18 @@
1
+ import { ApiAbstract } from "./abstract";
2
+ import { apiRoutePromocodeActivate } from "../http/apiRoute";
3
+ import { ApiError } from "../http/apiError";
4
+
5
+ export class ApiPromocode extends ApiAbstract {
6
+ /**
7
+ * активация промокода
8
+ */
9
+ async activate(code: string) {
10
+ if (!await this.userStorage.isAuth()) throw new ApiError(401, "Пользователь не авторизован")
11
+ const { sum } = await this.fetcher<{ sum: number }>({
12
+ route: apiRoutePromocodeActivate,
13
+ postBody: { code },
14
+ options: { addToken: true }
15
+ })
16
+ return { sum }
17
+ }
18
+ }
@@ -0,0 +1,102 @@
1
+ import { ApiAbstract } from "./abstract";
2
+ import { apiRoutePushCountNew, apiRoutePushIsSubscribed, apiRoutePushList, apiRoutePushRegister, apiRoutePushUnsubscribe, apiRoutePushView, apiRoutePushViewAll } from "../http/apiRoute";
3
+ import { iPagingItems } from "../interfaces/iPagingItems";
4
+ import { ApiError } from "../http/apiError";
5
+ import { iPush } from "../interfaces/iPush";
6
+ import { iFilter } from "../interfaces/iFilter";
7
+ import { iAppStore } from "../interfaces/iAppStore";
8
+
9
+ export class ApiPush extends ApiAbstract {
10
+ /**
11
+ * список пушей
12
+ * * @param {number} page - отсчет страниц с первой, чтобы не было путаницы
13
+ */
14
+ async getList<Keys extends keyof iPush>({
15
+ page = 1,
16
+ filters,
17
+ select,
18
+ }: {
19
+ page: number
20
+ filters?: iFilter<iPush>,
21
+ select: Keys[],
22
+ }) {
23
+ if (!await this.userStorage.isAuth()) throw new ApiError(401, "Пользователь не авторизован")
24
+ return await this.fetcher<iPagingItems<Pick<iPush, Keys>>>({
25
+ route: apiRoutePushList({
26
+ page,
27
+ filters,
28
+ sorters: ["id desc"],
29
+ select
30
+ }),
31
+ options: { addToken: true }
32
+ })
33
+ }
34
+ /**
35
+ * количество непрочитанных пушей
36
+ */
37
+ async countNew() {
38
+ if (!await this.userStorage.isAuth()) throw new ApiError(401, "Пользователь не авторизован")
39
+ return await this.fetcher<{ totalItems: number }>({
40
+ route: apiRoutePushCountNew,
41
+ options: { addToken: true }
42
+ })
43
+ }
44
+ /**
45
+ * Пометить пуш просмотренным
46
+ * * @param {number} props.pushId - id пуша
47
+ */
48
+ async view({ pushId }: { pushId: number }) {
49
+ if (!await this.userStorage.isAuth()) throw new ApiError(401, "Пользователь не авторизован")
50
+ await this.fetcher({
51
+ route: apiRoutePushView,
52
+ postBody: { id: pushId },
53
+ options: { addToken: true }
54
+ })
55
+ }
56
+ /**
57
+ * Пометить все пуши просмотренными
58
+ */
59
+ async viewAll() {
60
+ if (!await this.userStorage.isAuth()) throw new ApiError(401, "Пользователь не авторизован")
61
+ await this.fetcher({
62
+ route: apiRoutePushViewAll,
63
+ postBody: { view: true },
64
+ options: { addToken: true }
65
+ })
66
+ }
67
+
68
+ /**
69
+ * добавления токена для пуш уведомления
70
+ * * @param {number} props.token - сумма выплаты
71
+ * * @param {number} props.appStore - магазин приложений
72
+ */
73
+ async register(props: { token: string, appStore: iAppStore }) {
74
+ if (!await this.userStorage.isAuth()) throw new ApiError(401, "Пользователь не авторизован")
75
+ await this.fetcher({
76
+ route: apiRoutePushRegister,
77
+ postBody: props,
78
+ options: { addToken: true }
79
+ })
80
+ }
81
+ /**
82
+ * отписка от пуш уведомлений
83
+ */
84
+ async unsubscribe() {
85
+ if (!await this.userStorage.isAuth()) throw new ApiError(401, "Пользователь не авторизован")
86
+ await this.fetcher({
87
+ route: apiRoutePushUnsubscribe,
88
+ postBody: { unsubscribe: 1 },
89
+ options: { addToken: true }
90
+ })
91
+ }
92
+ /**
93
+ * статус подписки на пуш уведомления
94
+ */
95
+ async isSubscribed() {
96
+ if (!await this.userStorage.isAuth()) throw new ApiError(401, "Пользователь не авторизован")
97
+ return await this.fetcher<{ subscribed: boolean }>({
98
+ route: apiRoutePushIsSubscribed,
99
+ options: { addToken: true }
100
+ })
101
+ }
102
+ }
@@ -0,0 +1,74 @@
1
+ import { ApiAbstract } from "./abstract";
2
+ import { apiRouteStatAdd, apiRouteStatGet, apiRouteViewAdd } from "../http/apiRoute";
3
+ import { UserStatEvent } from "../interfaces/userStatEvent";
4
+ import { iUserStat } from "../interfaces/iUserStat";
5
+ import { ApiError } from "../http/apiError";
6
+ import { ItemType } from "../interfaces/itemType";
7
+ import { ViewEventType } from "../interfaces/viewEventType";
8
+ import { apiStatEvents } from "../interfaces/apiStatEvents";
9
+
10
+ export class ApiStat extends ApiAbstract {
11
+ /**
12
+ * добавление события открытия товара, бренда, статьи
13
+ * @param {number} props.itemId - id элемента
14
+ * @param {AddViewEvent} props.event - тип события
15
+ */
16
+ async add({
17
+ itemId,
18
+ event,
19
+ }: {
20
+ itemId: number,
21
+ event: typeof apiStatEvents[number],
22
+ }) {
23
+ if (typeof itemId != "number" || itemId <= 0) throw new ApiError(400, "ApiStat не корректный id элемента")
24
+ if (!apiStatEvents.includes(event)) throw new ApiError(400, "ApiStat Не правильный тип статистики")
25
+ const itemType = ItemType[event.split("/")[0] as keyof typeof ItemType]
26
+ const eventType = ViewEventType[event.split("/")[1] as keyof typeof ViewEventType]
27
+ if (!itemType) throw new ApiError(400, `ApiStat Не верный тип элемента ${event.split("/")[0]} - ${itemType}`)
28
+ if (!eventType) throw new ApiError(400, `ApiStat Не верный тип события ${event.split("/")[1]} - ${eventType}`)
29
+ //повышаем кэшбек - просмотр презентации
30
+ if (itemType == ItemType.CATALOG_SKU && eventType == ViewEventType.PRESENTATION_SUCCESS) {
31
+ await this.fetcher({
32
+ route: apiRouteStatAdd,
33
+ postBody: {
34
+ sku: itemId,
35
+ event: UserStatEvent.presentation
36
+ },
37
+ options: { addToken: true }
38
+ })
39
+ }
40
+ //повышаем кэшбек - квиз
41
+ if (itemType == ItemType.CATALOG_SKU && eventType == ViewEventType.QUESTIONS_SUCCESS) {
42
+ await this.fetcher({
43
+ route: apiRouteStatAdd,
44
+ postBody: {
45
+ sku: itemId,
46
+ event: UserStatEvent.quiz
47
+ },
48
+ options: { addToken: true }
49
+ })
50
+ }
51
+ await this.fetcher({
52
+ route: apiRouteViewAdd,
53
+ postBody: {
54
+ itemType,
55
+ itemId,
56
+ eventType
57
+ },
58
+ options: { addToken: true }
59
+ })
60
+ }
61
+ /**
62
+ * получения события просмотра презентации или прохождения квиза
63
+ * @param {number} props.sku - массив id акции (не товара) до 50 элементов.
64
+ */
65
+ async getEvent(props: { sku: number[] }) {
66
+ if (!await this.userStorage.isAuth()) throw new ApiError(401, "Пользователь не авторизован")
67
+ const data = await this.fetcher<{ items: iUserStat[] }>({
68
+ route: apiRouteStatGet,
69
+ postBody: props,
70
+ options: { addToken: true }
71
+ })
72
+ return data.items
73
+ }
74
+ }