@wbsuite/react-hooks 1.0.214 → 1.0.216

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 (308) hide show
  1. package/cjs/hooks/useAgents/index.d.ts +2 -0
  2. package/cjs/hooks/useAgents/index.js +32 -0
  3. package/cjs/hooks/useApps/index.d.ts +2 -0
  4. package/cjs/hooks/useApps/index.js +32 -0
  5. package/cjs/hooks/useArticles/index.d.ts +5 -0
  6. package/cjs/hooks/useArticles/index.js +45 -0
  7. package/cjs/hooks/useAttributes/index.d.ts +2 -0
  8. package/cjs/hooks/useAttributes/index.js +52 -0
  9. package/cjs/hooks/useAttributesGroups/index.d.ts +3 -0
  10. package/cjs/hooks/useAttributesGroups/index.js +47 -0
  11. package/cjs/hooks/useAutomations/index.d.ts +2 -0
  12. package/cjs/hooks/useAutomations/index.js +32 -0
  13. package/cjs/hooks/useBackend/get.d.ts +2 -0
  14. package/cjs/hooks/useBackend/get.js +52 -0
  15. package/cjs/hooks/useBackend/index.d.ts +17 -0
  16. package/cjs/hooks/useBackend/index.js +22 -0
  17. package/cjs/hooks/useBackend/list.d.ts +2 -0
  18. package/cjs/hooks/useBackend/list.js +55 -0
  19. package/cjs/hooks/useBackend/post.d.ts +2 -0
  20. package/cjs/hooks/useBackend/post.js +52 -0
  21. package/cjs/hooks/useBackend/put.d.ts +2 -0
  22. package/cjs/hooks/useBackend/put.js +52 -0
  23. package/cjs/hooks/useCampaigns/index.d.ts +2 -0
  24. package/cjs/hooks/useCampaigns/index.js +35 -0
  25. package/cjs/hooks/useCategories/index.d.ts +3 -0
  26. package/cjs/hooks/useCategories/index.js +37 -0
  27. package/cjs/hooks/useChats/index.d.ts +3 -0
  28. package/cjs/hooks/useChats/index.js +37 -0
  29. package/cjs/hooks/useContactGroups/index.d.ts +3 -0
  30. package/cjs/hooks/useContactGroups/index.js +57 -0
  31. package/cjs/hooks/useContacts/index.d.ts +3 -0
  32. package/cjs/hooks/useContacts/index.js +52 -0
  33. package/cjs/hooks/useCurrencies/index.d.ts +3 -0
  34. package/cjs/hooks/useCurrencies/index.js +37 -0
  35. package/cjs/hooks/useCustomers/index.d.ts +3 -0
  36. package/cjs/hooks/useCustomers/index.js +52 -0
  37. package/cjs/hooks/useDocuments/index.d.ts +10 -0
  38. package/cjs/hooks/useDocuments/index.js +145 -0
  39. package/cjs/hooks/useDomains/index.d.ts +2 -0
  40. package/cjs/hooks/useDomains/index.js +32 -0
  41. package/cjs/hooks/useEmailTemplates/index.d.ts +2 -0
  42. package/cjs/hooks/useEmailTemplates/index.js +37 -0
  43. package/cjs/hooks/useEntityStatuses/index.d.ts +2 -0
  44. package/cjs/hooks/useEntityStatuses/index.js +34 -0
  45. package/cjs/hooks/useFormSubmissions/index.d.ts +2 -0
  46. package/cjs/hooks/useFormSubmissions/index.js +9 -0
  47. package/cjs/hooks/useForms/index.d.ts +2 -0
  48. package/cjs/hooks/useForms/index.js +37 -0
  49. package/cjs/hooks/useIntegrations/index.d.ts +2 -0
  50. package/cjs/hooks/useIntegrations/index.js +39 -0
  51. package/cjs/hooks/useInvites/index.d.ts +2 -0
  52. package/cjs/hooks/useInvites/index.js +47 -0
  53. package/cjs/hooks/useLabels/index.d.ts +3 -0
  54. package/cjs/hooks/useLabels/index.js +32 -0
  55. package/cjs/hooks/useLanguages/index.d.ts +5 -0
  56. package/cjs/hooks/useLanguages/index.js +39 -0
  57. package/cjs/hooks/useLeads/index.d.ts +30 -0
  58. package/cjs/hooks/useLeads/index.js +113 -0
  59. package/cjs/hooks/useMedia/index.d.ts +2 -0
  60. package/cjs/hooks/useMedia/index.js +34 -0
  61. package/cjs/hooks/useOrders/index.d.ts +2 -0
  62. package/cjs/hooks/useOrders/index.js +76 -0
  63. package/cjs/hooks/usePaths/index.d.ts +2 -0
  64. package/cjs/hooks/usePaths/index.js +37 -0
  65. package/cjs/hooks/usePermissions/index.d.ts +2 -0
  66. package/cjs/hooks/usePermissions/index.js +47 -0
  67. package/cjs/hooks/useProducts/index.d.ts +2 -0
  68. package/cjs/hooks/useProducts/index.js +52 -0
  69. package/cjs/hooks/useProfile/index.d.ts +3 -0
  70. package/cjs/hooks/useProfile/index.js +57 -0
  71. package/cjs/hooks/useRenting/index.d.ts +47 -0
  72. package/cjs/hooks/useRenting/index.js +52 -0
  73. package/cjs/hooks/useRoles/index.d.ts +2 -0
  74. package/cjs/hooks/useRoles/index.js +32 -0
  75. package/cjs/hooks/useRoom/index.d.ts +3 -0
  76. package/cjs/hooks/useRoom/index.js +55 -0
  77. package/cjs/hooks/useRotations/index.d.ts +2 -0
  78. package/cjs/hooks/useRotations/index.js +37 -0
  79. package/cjs/hooks/useSiteConfig/index.d.ts +5 -0
  80. package/cjs/hooks/useSiteConfig/index.js +33 -0
  81. package/cjs/hooks/useStatuses/index.d.ts +2 -0
  82. package/cjs/hooks/useStatuses/index.js +32 -0
  83. package/cjs/hooks/useStock/index.d.ts +20 -0
  84. package/cjs/hooks/useStock/index.js +51 -0
  85. package/cjs/hooks/useStores/index.d.ts +3 -0
  86. package/cjs/hooks/useStores/index.js +62 -0
  87. package/cjs/hooks/useSubscriptions/index.d.ts +2 -0
  88. package/cjs/hooks/useSubscriptions/index.js +37 -0
  89. package/cjs/hooks/useTable/index.d.ts +3 -0
  90. package/cjs/hooks/useTable/index.js +34 -0
  91. package/cjs/hooks/useTeams/index.d.ts +5 -0
  92. package/cjs/hooks/useTeams/index.js +52 -0
  93. package/cjs/hooks/useTickets/index.d.ts +3 -0
  94. package/cjs/hooks/useTickets/index.js +47 -0
  95. package/cjs/hooks/useTransactions/index.d.ts +8 -0
  96. package/cjs/hooks/useTransactions/index.js +61 -0
  97. package/cjs/hooks/useTranslations/index.d.ts +5 -0
  98. package/cjs/hooks/useTranslations/index.js +42 -0
  99. package/cjs/hooks/useUserConnections/index.d.ts +2 -0
  100. package/cjs/hooks/useUserConnections/index.js +53 -0
  101. package/cjs/hooks/useUserSubscriptions/index.d.ts +6 -0
  102. package/cjs/hooks/useUserSubscriptions/index.js +47 -0
  103. package/cjs/hooks/useUsers/index.d.ts +17 -0
  104. package/cjs/hooks/useUsers/index.js +141 -0
  105. package/cjs/hooks/useWBSuite/index.d.ts +2 -0
  106. package/cjs/hooks/useWBSuite/index.js +39 -0
  107. package/cjs/hooks/useWebsites/index.d.ts +2 -0
  108. package/cjs/hooks/useWebsites/index.js +77 -0
  109. package/{src/index.ts → cjs/index.d.ts} +1 -1
  110. package/cjs/index.js +119 -0
  111. package/cjs/models/Requestor.d.ts +24 -0
  112. package/cjs/models/Requestor.js +53 -0
  113. package/{src/next/utils/index.ts → cjs/next/utils/index.d.ts} +1 -1
  114. package/cjs/next/utils/index.js +6 -0
  115. package/cjs/next/utils/wrapAsync.d.ts +1 -0
  116. package/cjs/next/utils/wrapAsync.js +54 -0
  117. package/cjs/utils/authWithApiKey.d.ts +4 -0
  118. package/cjs/utils/authWithApiKey.js +8 -0
  119. package/cjs/utils/authWithToken.d.ts +4 -0
  120. package/cjs/utils/authWithToken.js +8 -0
  121. package/cjs/utils/index.d.ts +11 -0
  122. package/cjs/utils/index.js +19 -0
  123. package/esm/hooks/useAgents/index.d.ts +2 -0
  124. package/esm/hooks/useAgents/index.js +28 -0
  125. package/esm/hooks/useApps/index.d.ts +2 -0
  126. package/esm/hooks/useApps/index.js +28 -0
  127. package/esm/hooks/useArticles/index.d.ts +5 -0
  128. package/esm/hooks/useArticles/index.js +40 -0
  129. package/esm/hooks/useAttributes/index.d.ts +2 -0
  130. package/esm/hooks/useAttributes/index.js +48 -0
  131. package/esm/hooks/useAttributesGroups/index.d.ts +3 -0
  132. package/esm/hooks/useAttributesGroups/index.js +43 -0
  133. package/esm/hooks/useAutomations/index.d.ts +2 -0
  134. package/esm/hooks/useAutomations/index.js +28 -0
  135. package/esm/hooks/useBackend/get.d.ts +2 -0
  136. package/esm/hooks/useBackend/get.js +48 -0
  137. package/esm/hooks/useBackend/index.d.ts +17 -0
  138. package/esm/hooks/useBackend/index.js +18 -0
  139. package/esm/hooks/useBackend/list.d.ts +2 -0
  140. package/esm/hooks/useBackend/list.js +51 -0
  141. package/esm/hooks/useBackend/post.d.ts +2 -0
  142. package/esm/hooks/useBackend/post.js +48 -0
  143. package/esm/hooks/useBackend/put.d.ts +2 -0
  144. package/esm/hooks/useBackend/put.js +48 -0
  145. package/esm/hooks/useCampaigns/index.d.ts +2 -0
  146. package/esm/hooks/useCampaigns/index.js +31 -0
  147. package/esm/hooks/useCategories/index.d.ts +3 -0
  148. package/esm/hooks/useCategories/index.js +33 -0
  149. package/esm/hooks/useChats/index.d.ts +3 -0
  150. package/esm/hooks/useChats/index.js +33 -0
  151. package/esm/hooks/useContactGroups/index.d.ts +3 -0
  152. package/esm/hooks/useContactGroups/index.js +53 -0
  153. package/esm/hooks/useContacts/index.d.ts +3 -0
  154. package/esm/hooks/useContacts/index.js +48 -0
  155. package/esm/hooks/useCurrencies/index.d.ts +3 -0
  156. package/esm/hooks/useCurrencies/index.js +33 -0
  157. package/esm/hooks/useCustomers/index.d.ts +3 -0
  158. package/esm/hooks/useCustomers/index.js +48 -0
  159. package/esm/hooks/useDocuments/index.d.ts +10 -0
  160. package/esm/hooks/useDocuments/index.js +141 -0
  161. package/esm/hooks/useDomains/index.d.ts +2 -0
  162. package/esm/hooks/useDomains/index.js +28 -0
  163. package/esm/hooks/useEmailTemplates/index.d.ts +2 -0
  164. package/esm/hooks/useEmailTemplates/index.js +33 -0
  165. package/esm/hooks/useEntityStatuses/index.d.ts +2 -0
  166. package/esm/hooks/useEntityStatuses/index.js +30 -0
  167. package/esm/hooks/useFormSubmissions/index.d.ts +2 -0
  168. package/esm/hooks/useFormSubmissions/index.js +5 -0
  169. package/esm/hooks/useForms/index.d.ts +2 -0
  170. package/esm/hooks/useForms/index.js +33 -0
  171. package/esm/hooks/useIntegrations/index.d.ts +2 -0
  172. package/esm/hooks/useIntegrations/index.js +35 -0
  173. package/esm/hooks/useInvites/index.d.ts +2 -0
  174. package/esm/hooks/useInvites/index.js +43 -0
  175. package/esm/hooks/useLabels/index.d.ts +3 -0
  176. package/esm/hooks/useLabels/index.js +28 -0
  177. package/esm/hooks/useLanguages/index.d.ts +5 -0
  178. package/esm/hooks/useLanguages/index.js +35 -0
  179. package/esm/hooks/useLeads/index.d.ts +30 -0
  180. package/esm/hooks/useLeads/index.js +109 -0
  181. package/esm/hooks/useMedia/index.d.ts +2 -0
  182. package/esm/hooks/useMedia/index.js +30 -0
  183. package/esm/hooks/useOrders/index.d.ts +2 -0
  184. package/esm/hooks/useOrders/index.js +72 -0
  185. package/esm/hooks/usePaths/index.d.ts +2 -0
  186. package/esm/hooks/usePaths/index.js +33 -0
  187. package/esm/hooks/usePermissions/index.d.ts +2 -0
  188. package/esm/hooks/usePermissions/index.js +43 -0
  189. package/esm/hooks/useProducts/index.d.ts +2 -0
  190. package/esm/hooks/useProducts/index.js +48 -0
  191. package/esm/hooks/useProfile/index.d.ts +3 -0
  192. package/esm/hooks/useProfile/index.js +53 -0
  193. package/esm/hooks/useRenting/index.d.ts +47 -0
  194. package/esm/hooks/useRenting/index.js +48 -0
  195. package/esm/hooks/useRoles/index.d.ts +2 -0
  196. package/esm/hooks/useRoles/index.js +28 -0
  197. package/esm/hooks/useRoom/index.d.ts +3 -0
  198. package/esm/hooks/useRoom/index.js +51 -0
  199. package/esm/hooks/useRotations/index.d.ts +2 -0
  200. package/esm/hooks/useRotations/index.js +33 -0
  201. package/esm/hooks/useSiteConfig/index.d.ts +5 -0
  202. package/esm/hooks/useSiteConfig/index.js +29 -0
  203. package/esm/hooks/useStatuses/index.d.ts +2 -0
  204. package/esm/hooks/useStatuses/index.js +28 -0
  205. package/esm/hooks/useStock/index.d.ts +20 -0
  206. package/esm/hooks/useStock/index.js +47 -0
  207. package/esm/hooks/useStores/index.d.ts +3 -0
  208. package/esm/hooks/useStores/index.js +58 -0
  209. package/esm/hooks/useSubscriptions/index.d.ts +2 -0
  210. package/esm/hooks/useSubscriptions/index.js +33 -0
  211. package/esm/hooks/useTable/index.d.ts +3 -0
  212. package/esm/hooks/useTable/index.js +30 -0
  213. package/esm/hooks/useTeams/index.d.ts +5 -0
  214. package/esm/hooks/useTeams/index.js +48 -0
  215. package/esm/hooks/useTickets/index.d.ts +3 -0
  216. package/esm/hooks/useTickets/index.js +43 -0
  217. package/esm/hooks/useTransactions/index.d.ts +8 -0
  218. package/esm/hooks/useTransactions/index.js +57 -0
  219. package/esm/hooks/useTranslations/index.d.ts +5 -0
  220. package/esm/hooks/useTranslations/index.js +38 -0
  221. package/esm/hooks/useUserConnections/index.d.ts +2 -0
  222. package/esm/hooks/useUserConnections/index.js +49 -0
  223. package/esm/hooks/useUserSubscriptions/index.d.ts +6 -0
  224. package/esm/hooks/useUserSubscriptions/index.js +43 -0
  225. package/esm/hooks/useUsers/index.d.ts +17 -0
  226. package/esm/hooks/useUsers/index.js +137 -0
  227. package/esm/hooks/useWBSuite/index.d.ts +2 -0
  228. package/esm/hooks/useWBSuite/index.js +35 -0
  229. package/esm/hooks/useWebsites/index.d.ts +2 -0
  230. package/esm/hooks/useWebsites/index.js +73 -0
  231. package/esm/index.d.ts +51 -0
  232. package/esm/index.js +52 -0
  233. package/esm/models/Requestor.d.ts +24 -0
  234. package/esm/models/Requestor.js +47 -0
  235. package/esm/next/utils/index.d.ts +2 -0
  236. package/esm/next/utils/index.js +3 -0
  237. package/esm/next/utils/wrapAsync.d.ts +1 -0
  238. package/esm/next/utils/wrapAsync.js +50 -0
  239. package/esm/utils/authWithApiKey.d.ts +4 -0
  240. package/esm/utils/authWithApiKey.js +4 -0
  241. package/esm/utils/authWithToken.d.ts +4 -0
  242. package/esm/utils/authWithToken.js +4 -0
  243. package/esm/utils/index.d.ts +11 -0
  244. package/esm/utils/index.js +3 -0
  245. package/package.json +1 -1
  246. package/README.md +0 -66
  247. package/docs/USAGE.md +0 -107
  248. package/eslint.config.js +0 -12
  249. package/src/hooks/useAgents/index.ts +0 -10
  250. package/src/hooks/useApps/index.ts +0 -10
  251. package/src/hooks/useArticles/index.ts +0 -18
  252. package/src/hooks/useAttributes/index.ts +0 -18
  253. package/src/hooks/useAttributesGroups/index.ts +0 -17
  254. package/src/hooks/useAutomations/index.ts +0 -10
  255. package/src/hooks/useBackend/get.ts +0 -6
  256. package/src/hooks/useBackend/index.ts +0 -40
  257. package/src/hooks/useBackend/list.ts +0 -6
  258. package/src/hooks/useBackend/post.ts +0 -6
  259. package/src/hooks/useBackend/put.ts +0 -6
  260. package/src/hooks/useCampaigns/index.ts +0 -11
  261. package/src/hooks/useCategories/index.ts +0 -13
  262. package/src/hooks/useChats/index.ts +0 -13
  263. package/src/hooks/useContactGroups/index.ts +0 -28
  264. package/src/hooks/useContacts/index.ts +0 -21
  265. package/src/hooks/useCurrencies/index.ts +0 -14
  266. package/src/hooks/useCustomers/index.ts +0 -21
  267. package/src/hooks/useDocuments/index.ts +0 -86
  268. package/src/hooks/useDomains/index.ts +0 -10
  269. package/src/hooks/useEmailTemplates/index.ts +0 -13
  270. package/src/hooks/useEntityStatuses/index.ts +0 -13
  271. package/src/hooks/useFormSubmissions/index.ts +0 -6
  272. package/src/hooks/useForms/index.ts +0 -16
  273. package/src/hooks/useIntegrations/index.ts +0 -15
  274. package/src/hooks/useInvites/index.ts +0 -19
  275. package/src/hooks/useLabels/index.ts +0 -13
  276. package/src/hooks/useLanguages/index.ts +0 -16
  277. package/src/hooks/useLeads/index.ts +0 -149
  278. package/src/hooks/useMedia/index.ts +0 -13
  279. package/src/hooks/useOrders/index.ts +0 -74
  280. package/src/hooks/usePaths/index.ts +0 -16
  281. package/src/hooks/usePermissions/index.ts +0 -16
  282. package/src/hooks/useProducts/index.ts +0 -18
  283. package/src/hooks/useProfile/index.ts +0 -20
  284. package/src/hooks/useRenting/index.ts +0 -57
  285. package/src/hooks/useRoles/index.ts +0 -10
  286. package/src/hooks/useRoom/index.ts +0 -20
  287. package/src/hooks/useRotations/index.ts +0 -13
  288. package/src/hooks/useSiteConfig/index.ts +0 -13
  289. package/src/hooks/useStatuses/index.ts +0 -10
  290. package/src/hooks/useStock/index.ts +0 -48
  291. package/src/hooks/useStores/index.ts +0 -23
  292. package/src/hooks/useSubscriptions/index.ts +0 -17
  293. package/src/hooks/useTable/index.ts +0 -15
  294. package/src/hooks/useTeams/index.ts +0 -29
  295. package/src/hooks/useTickets/index.ts +0 -17
  296. package/src/hooks/useTransactions/index.ts +0 -43
  297. package/src/hooks/useTranslations/index.ts +0 -20
  298. package/src/hooks/useUserConnections/index.ts +0 -18
  299. package/src/hooks/useUserSubscriptions/index.ts +0 -28
  300. package/src/hooks/useUsers/index.ts +0 -57
  301. package/src/hooks/useWBSuite/index.ts +0 -29
  302. package/src/hooks/useWebsites/index.ts +0 -34
  303. package/src/models/Requestor.ts +0 -67
  304. package/src/next/utils/wrapAsync.ts +0 -2
  305. package/src/utils/authWithApiKey.ts +0 -3
  306. package/src/utils/authWithToken.ts +0 -3
  307. package/src/utils/index.ts +0 -7
  308. package/tsconfig.json +0 -20
@@ -1,17 +0,0 @@
1
- import { BackendHook, useBackend } from '../useBackend';
2
- import { Chat } from '@wb/types/chats/chats.model';
3
- import { RequestorOptions } from 'models/Requestor';
4
-
5
- export const useTickets: BackendHook<Chat> = (auth?: RequestorOptions['auth']) => {
6
- const { requestor, ...endpoints } = useBackend('tickets', { auth });
7
- return {
8
- requestor,
9
- ...endpoints,
10
- resolve: (ticketId: string) =>
11
- requestor.makeRequest.post(`tickets/${ticketId}/resolve`).then(({ data }) => data),
12
- addComment: (ticketId: string, note: { text: string, extra: Record<string, unknown> }) =>
13
- requestor.makeRequest.post(`tickets/${ticketId}/comment`, note).then(({ data }) => data),
14
- commentHistory: (ticketId: string) =>
15
- requestor.makeRequest.post(`tickets/${ticketId}/comment/history`).then(({ data }) => data),
16
- };
17
- };
@@ -1,43 +0,0 @@
1
- import { CustomResponse } from '@wb/types/custom-response/custom-response.model';
2
- import { BackendHook, useBackend } from '../useBackend';
3
- import { RequestorOptions } from 'models/Requestor';
4
-
5
- type EntityTypes = 'renting' | 'order';
6
-
7
- export const useTransactions: BackendHook<
8
- Record<string, string>,
9
- any,
10
- {
11
- listPaymentMethods: () => Promise<CustomResponse<Record<string, unknown>[]>>;
12
- getPublicPayment: (
13
- entity: EntityTypes,
14
- entityId: string,
15
- method: string
16
- ) => Promise<CustomResponse<Record<string, unknown>[]>>;
17
- }
18
- > = (auth?: RequestorOptions['auth']) => {
19
- const { requestor, ...rest } = useBackend('transactions', { auth });
20
- return {
21
- ...rest,
22
- requestor,
23
- listPaymentMethods: () => {
24
- return requestor.makeRequest.get(`transactions/methods`).then(({ data }) => data);
25
- },
26
- getPayment: (entity: EntityTypes, entityId: string, method: string, amount?: number) => {
27
- return requestor.makeRequest
28
- .post(`transactions/${method}/${entity}/${entityId}`, { amount })
29
- .then(({ data }) => data);
30
- },
31
- getPublicPayment: (entity: EntityTypes, entityId: string, method: string, amount?: number) => {
32
- return requestor.makeRequest
33
- .post(`transactions/public/${method}/${entity}/${entityId}`, { amount })
34
- .then(({ data }) => data);
35
- },
36
- cancelPayment: (transactionId: string) => {
37
- return requestor.makeRequest.post(`transactions/cancel/${transactionId}`).then(({ data }) => data);
38
- },
39
- completePayment: (transactionId: string) => {
40
- return requestor.makeRequest.post(`transactions/complete/${transactionId}`).then(({ data }) => data);
41
- },
42
- };
43
- };
@@ -1,20 +0,0 @@
1
- import { RequestorOptions } from 'models/Requestor';
2
- import { BackendHook, useBackend } from '../useBackend';
3
-
4
- export const useTranslations: BackendHook<
5
- Record<string, string>,
6
- any,
7
- { getJson: () => Promise<Record<string, unknown>>; getProductJson: () => Promise<Record<string, unknown>> }
8
- > = (auth?: RequestorOptions['auth']) => {
9
- const { requestor, ...rest } = useBackend('translations', { auth });
10
- return {
11
- ...rest,
12
- requestor,
13
- getJson: () => {
14
- return requestor.makeRequest.get(`translations/getAll`).then(({ data }) => data);
15
- },
16
- getProductJson: () => {
17
- return requestor.makeRequest.get(`translations/product/getAll`).then(({ data }) => data);
18
- },
19
- };
20
- };
@@ -1,18 +0,0 @@
1
- import { BackendHook, useBackend } from '../useBackend';
2
- import { RequestorOptions } from 'models/Requestor';
3
-
4
- export const useUserConnection: BackendHook = (auth?: RequestorOptions['auth']) => {
5
- const { requestor, ...endpoints } = useBackend('user-connections', { auth });
6
- return {
7
- requestor,
8
- ...endpoints,
9
- create: (data) =>
10
- requestor.makeRequest.post(`user-connections`, data).then(({ data }) => data),
11
- update: (id: any, data: any) =>
12
- requestor.makeRequest.put(`user-connections/${id}`, data).then(({ data }) => data),
13
- delete: (id: string) =>
14
- requestor.makeRequest.delete(`user-connections/${id}`).then(({ data }) => data),
15
- searchContactExternalId: (searchValue: string, { userConnectionIds }: { userConnectionIds?: string[] }) =>
16
- requestor.makeRequest.get(`user-connections/search/contact/${searchValue}`, { params: { userConnectionIds } }).then(({ data }) => data),
17
- };
18
- };
@@ -1,28 +0,0 @@
1
-
2
- import { BackendHook, useBackend } from '../useBackend';
3
- import { RequestorOptions } from 'models/Requestor';
4
-
5
- export const useUserSubscriptions: BackendHook<
6
- Record<string, string>,
7
- any,
8
- {
9
- subscribe: (subscriptionId: string, subscriptionDetails: Record<string, unknown>) => Promise<void>;
10
- requestPayment: (userSubscriptionId: string, data: Record<string, unknown>) => Promise<void>;
11
- cancel: (userSubscriptionId: string) => Promise<void>;
12
- }
13
- > = (auth?: RequestorOptions['auth']) => {
14
- const { requestor, ...rest } = useBackend('user-subscriptions', { auth });
15
- return {
16
- ...rest,
17
- requestor,
18
- subscribe: (subscriptionId: string, subscriptionDetails: Record<string, unknown>) => {
19
- return requestor.makeRequest.post(`user-subscriptions/${subscriptionId}`, subscriptionDetails).then(({ data }) => data);
20
- },
21
- requestPayment: (userSubscriptionId: string, data: Record<string, unknown>) => {
22
- return requestor.makeRequest.post(`user-subscriptions/payment/request/${userSubscriptionId}`, data).then(({ data }) => data);
23
- },
24
- cancel: (userSubscriptionId: string) => {
25
- return requestor.makeRequest.post(`user-subscriptions/${userSubscriptionId}/cancel`).then(({ data }) => data);
26
- }
27
- };
28
- };
@@ -1,57 +0,0 @@
1
- import { BackendHook, useBackend } from '../useBackend';
2
- import { CustomResponse } from '@wb/types/custom-response/custom-response.model';
3
- import { RequestorOptions } from 'models/Requestor';
4
-
5
- type LoginResponse = CustomResponse<{ user: unknown; token: { access_token: string; expires_in: number; token_type: string } }>;
6
- type LoginFunction = (
7
- username: string,
8
- password: string
9
- ) => Promise<LoginResponse>;
10
-
11
- export const useUsers: BackendHook<
12
- any,
13
- any,
14
- {
15
- login: LoginFunction;
16
- getSession: () => Promise<LoginResponse>
17
- restartSession: (token: string) => Promise<LoginResponse> | Promise<CustomResponse>
18
- }
19
- > = (auth?: RequestorOptions['auth']) => {
20
- const { requestor, ...endpoints } = useBackend('users', { auth });
21
- return {
22
- ...endpoints,
23
- requestor,
24
- login: async (username: string, password: string) => {
25
- const { data: response } = await requestor.makeRequest.post<LoginResponse>('users/login', { username, password });
26
- return response;
27
- },
28
- getSession: async () => {
29
- const { data: response } = await requestor.makeRequest.get<LoginResponse>('users/login');
30
- return response;
31
- },
32
- restartSession: async () => {
33
- try {
34
- const { data: response } = await requestor.makeRequest.get<LoginResponse>('users/login')
35
- return response;
36
- } catch(err) {
37
- return { success: false, data: null };
38
- }
39
- },
40
- getPermissions: async () => {
41
- return requestor.makeRequest.get<LoginResponse>('users/permissions').then(({ data }) => data);
42
- },
43
- getUserSummary: async (userId: string) => {
44
- const { data: response } = await requestor.makeRequest.get<LoginResponse>(`users/${userId}/profile`).then(({ data }) => data);
45
- return response;
46
- },
47
- logout: async () => {
48
- return requestor.makeRequest.post<LoginResponse>('users/logout').then(({ data }) => data);
49
- },
50
- updateStore: (userId: string, stores: string[]) => {
51
- return requestor.makeRequest.put(`users/${userId}/stores`, { stores }).then(({ data }) => data);
52
- },
53
- updateRoles: (userId: string, roles: string[]) => {
54
- return requestor.makeRequest.put(`users/${userId}/roles`, { roles }).then(({ data }) => data);
55
- }
56
- };
57
- };
@@ -1,29 +0,0 @@
1
- import { WBBackendConfig } from '@wb/types/backendConfig/backendConfig';
2
-
3
- const process = (globalThis as any).process || {};
4
-
5
- const DEFAULTS = {
6
- apiURL: process?.env?.WB_API_URL || 'https://api.wbsuite.app/api/v2',
7
- publicURL: process?.env?.WB_PUBLIC_URL || 'https://api.wbsuite.app/public',
8
- };
9
-
10
- (globalThis as any).WBSUITE_CONFIG;
11
- (globalThis as any).initialized = false;
12
-
13
- export const useWBSuite = (wbsuiteConfiguration: Partial<WBBackendConfig> = {}) => {
14
- if (!(globalThis as any).initialized) {
15
- (globalThis as any).initialized = true;
16
- (globalThis as any).WBSUITE_CONFIG = {
17
- ...DEFAULTS,
18
- ...Object.fromEntries(
19
- Object.entries({
20
- ...wbsuiteConfiguration,
21
- }).filter(([, value]) => value !== undefined && value !== null)
22
- ),
23
- };
24
- return true;
25
- } else {
26
- console.warn('Configuration skipped since it was already configured');
27
- return false;
28
- }
29
- };
@@ -1,34 +0,0 @@
1
- import { RequestorOptions } from 'models/Requestor';
2
- import { BackendHook, useBackend } from '../useBackend';
3
-
4
- export const useWebsites: BackendHook<Record<string, string>, any> = (auth?: RequestorOptions['auth']) => {
5
- const { requestor, ...rest } = useBackend('websites', { auth });
6
- return {
7
- ...rest,
8
- requestor,
9
- getProductSiteById: (siteId: string) => {
10
- return requestor.makeRequest.get(`websites/product/${siteId}`).then(({ data }) => data);
11
- },
12
- getPublicById: (siteId: string) => {
13
- return requestor.makeRequest.get(`websites/${siteId}/public`).then(({ data }) => data);
14
- },
15
- resetApiKey: (siteId: string) => {
16
- return requestor.makeRequest.put(`websites/${siteId}/apiKey`).then(({ data }) => data);
17
- },
18
- expireApiKey: (siteId: string) => {
19
- return requestor.makeRequest.delete(`websites/${siteId}/apiKey`).then(({ data }) => data);
20
- },
21
- getIntegrationDetails: (siteId: string) => {
22
- return requestor.makeRequest.get(`websites/${siteId}/integrate`).then(({ data }) => data);
23
- },
24
- addDomain: (siteId: string, origin: string) => {
25
- return requestor.makeRequest.post(`websites/${siteId}/domain`, { origin }).then(({ data }) => data);
26
- },
27
- removeDomain: (siteId: string) => {
28
- return requestor.makeRequest.delete(`websites/${siteId}/domain`).then(({ data }) => data);
29
- },
30
- duplicateSite: (siteId: string, overrides: { name?: string; description?: string }) => {
31
- return requestor.makeRequest.post(`websites/${siteId}/duplicate`, overrides).then(({ data }) => data);
32
- },
33
- };
34
- };
@@ -1,67 +0,0 @@
1
- import { WBBackendConfig } from '@wb/types/backendConfig/backendConfig';
2
- import axios, { AxiosInstance, AxiosResponse, InternalAxiosRequestConfig } from 'axios';
3
- import { useWBSuite } from '../hooks/useWBSuite';
4
-
5
- type Validator = (isCreate: boolean, body: any) => boolean;
6
-
7
- export type RequestorOptions = {
8
- auth:
9
- | { type: 'token' | 'apiKey' } & (
10
- | { type: 'token'; token: string }
11
- | { type: 'apiKey'; apiKey: string }
12
- );
13
- };
14
-
15
- export class Requestor {
16
- makeRequest: AxiosInstance;
17
- validateWith?: Validator;
18
-
19
- constructor(
20
- config: Partial<WBBackendConfig>,
21
- validator?: Validator,
22
- opts: Partial<RequestorOptions> = {}
23
- ) {
24
- if (!config) {
25
- useWBSuite();
26
- }
27
- this.makeRequest = axios.create({ baseURL: config?.apiURL ?? (globalThis as any).WBSUITE_CONFIG?.apiURL });
28
- this.validateWith = validator;
29
- this.makeRequest.interceptors.request.use((requestConfig: InternalAxiosRequestConfig) => {
30
- if ((opts.auth?.type === 'apiKey' && opts.auth.apiKey) || config?.apiKey) {
31
- requestConfig.headers['x-api-key'] = (opts.auth?.type === 'apiKey' && opts.auth.apiKey) || config?.apiKey;
32
- }
33
- if (opts.auth?.type === 'token' && opts.auth.token) {
34
- delete requestConfig.headers['x-api-key'];
35
- requestConfig.headers.Authorization = `Bearer ${opts.auth?.type === 'token' && opts.auth.token}`;
36
- }
37
- return requestConfig;
38
- });
39
- if (config?.environment === 'development') {
40
- this.makeRequest.interceptors.response.use(
41
- (response: AxiosResponse) => {
42
- console.log(
43
- `${new Date().toISOString()} [INFO] --- ${response.request.host} ${response.status} ${JSON.stringify(
44
- response.data
45
- )}`
46
- );
47
- return response;
48
- },
49
- (response: AxiosResponse) => {
50
- console.error(
51
- `${new Date().toISOString()} [ERROR] --- ${response.request.host} ${response.status} ${JSON.stringify(
52
- response.data
53
- )}`
54
- );
55
- return Promise.reject(response);
56
- }
57
- );
58
- }
59
- }
60
-
61
- public get validate() {
62
- return {
63
- create: (body: any) => this.validateWith?.(true, body) ?? true,
64
- edit: (body: any) => this.validateWith?.(false, body) ?? true,
65
- };
66
- }
67
- }
@@ -1,2 +0,0 @@
1
- // eslint-disable-next-line
2
- export const wrapAsync = async (fn: Function, ...args: any[]) => { return await fn(...args) };
@@ -1,3 +0,0 @@
1
- export const authWithApiKey = (apiKey: string) => {
2
- return { type: 'apiKey', apiKey };
3
- };
@@ -1,3 +0,0 @@
1
- export const authWithToken = (token: string) => {
2
- return { type: 'token', token };
3
- };
@@ -1,7 +0,0 @@
1
- export * from './authWithApiKey';
2
- export * from './authWithToken';
3
-
4
- export type WebSuiteAuth = | { type: 'token' | 'apiKey' | 'siteApiKey' } & (
5
- | { type: 'token'; token: string }
6
- | { type: 'apiKey'; apiKey: string }
7
- )
package/tsconfig.json DELETED
@@ -1,20 +0,0 @@
1
- {
2
- "compilerOptions": {
3
- "module": "esnext",
4
- "moduleResolution": "node" /* Specify module resolution strategy: 'node' (Node.js) or 'classic' (TypeScript pre-1.6). */,
5
- "lib": ["es6", "dom", "es2016", "es2017", "es2020"],
6
- "target": "es5",
7
- "outDir": "./dist/react-hooks/esm" /* Redirect output structure to the directory. */,
8
- "baseUrl": "./src" /* Base directory to resolve non-absolute module names. */,
9
- "declaration": true /* Concatenate and emit output to single file. */,
10
- "strict": true /* Enable all strict type-checking options. */,
11
- "esModuleInterop": true /* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */,
12
- "inlineSourceMap": true /* Emit a single file with source maps instead of having a separate file. */,
13
- "inlineSources": true /* Emit the source alongside the sourcemaps within a single file; requires '--inlineSourceMap' or '--sourceMap' to be set. */,
14
- "skipLibCheck": true /* Skip type checking of declaration files. */,
15
- "forceConsistentCasingInFileNames": true /* Disallow inconsistently-cased references to the same file. */,
16
- "allowSyntheticDefaultImports": true
17
- },
18
- "include": ["src/**/*.ts", "eslint.config.js"],
19
- "exclude": ["node_modules", "dist"]
20
- }