@smartbills/react-hooks-sdk 0.0.2-alpha.16 → 0.0.2-alpha.19

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 (92) hide show
  1. package/dist/@types/index.d.ts +135 -6
  2. package/dist/cjs/apis/SBApiKeys.cjs +24 -0
  3. package/dist/cjs/apis/SBApiKeys.cjs.map +1 -0
  4. package/dist/cjs/apis/api-logs/LogsAPI.cjs +4 -5
  5. package/dist/cjs/apis/api-logs/LogsAPI.cjs.map +1 -1
  6. package/dist/cjs/apis/bank-accounts/BankAccountAPI.cjs +54 -0
  7. package/dist/cjs/apis/bank-accounts/BankAccountAPI.cjs.map +1 -0
  8. package/dist/cjs/apis/bank-transactions/BankTransactionAPI.cjs +162 -0
  9. package/dist/cjs/apis/bank-transactions/BankTransactionAPI.cjs.map +1 -0
  10. package/dist/cjs/apis/banks/BanksAPI.cjs +4 -4
  11. package/dist/cjs/apis/banks/BanksAPI.cjs.map +1 -1
  12. package/dist/cjs/apis/cards/CardSetupIntentsAPI.cjs +67 -0
  13. package/dist/cjs/apis/cards/CardSetupIntentsAPI.cjs.map +1 -0
  14. package/dist/cjs/apis/cards/CardsAPI.cjs +71 -0
  15. package/dist/cjs/apis/cards/CardsAPI.cjs.map +1 -0
  16. package/dist/cjs/apis/customers/CustomerAPI.cjs +117 -0
  17. package/dist/cjs/apis/customers/CustomerAPI.cjs.map +1 -0
  18. package/dist/cjs/apis/documents/DocumentsAPI.cjs +61 -0
  19. package/dist/cjs/apis/documents/DocumentsAPI.cjs.map +1 -0
  20. package/dist/cjs/apis/domains/DomainAPI.cjs +71 -0
  21. package/dist/cjs/apis/domains/DomainAPI.cjs.map +1 -0
  22. package/dist/cjs/apis/friends/FriendsAPI.cjs +47 -0
  23. package/dist/cjs/apis/friends/FriendsAPI.cjs.map +1 -0
  24. package/dist/cjs/apis/locations/LocationsAPI.cjs +94 -0
  25. package/dist/cjs/apis/locations/LocationsAPI.cjs.map +1 -0
  26. package/dist/cjs/apis/merchants/MerchantAPI.cjs +94 -0
  27. package/dist/cjs/apis/merchants/MerchantAPI.cjs.map +1 -0
  28. package/dist/cjs/apis/organizations/OrganizationsAPI.cjs +139 -0
  29. package/dist/cjs/apis/organizations/OrganizationsAPI.cjs.map +1 -0
  30. package/dist/cjs/apis/payment-methods/PaymentMethodsAPI.cjs +66 -0
  31. package/dist/cjs/apis/payment-methods/PaymentMethodsAPI.cjs.map +1 -0
  32. package/dist/cjs/apis/promo-codes/PromoCodesAPI.cjs +94 -0
  33. package/dist/cjs/apis/promo-codes/PromoCodesAPI.cjs.map +1 -0
  34. package/dist/cjs/apis/receipts/ReceiptAPI.cjs +4 -4
  35. package/dist/cjs/apis/receipts/ReceiptAPI.cjs.map +1 -1
  36. package/dist/cjs/apis/reviews/ReviewsAPI.cjs +1 -1
  37. package/dist/cjs/apis/reviews/ReviewsAPI.cjs.map +1 -1
  38. package/dist/cjs/apis/taxes/TaxesAPI.cjs +86 -0
  39. package/dist/cjs/apis/taxes/TaxesAPI.cjs.map +1 -0
  40. package/dist/cjs/apis/user/UserAPI.cjs +16 -0
  41. package/dist/cjs/apis/user/UserAPI.cjs.map +1 -0
  42. package/dist/cjs/apis/users/UsersAPI.cjs +30 -0
  43. package/dist/cjs/apis/users/UsersAPI.cjs.map +1 -0
  44. package/dist/cjs/index.cjs +83 -3
  45. package/dist/cjs/index.cjs.map +1 -1
  46. package/dist/esm/apis/SBApiKeys.mjs +24 -0
  47. package/dist/esm/apis/SBApiKeys.mjs.map +1 -0
  48. package/dist/esm/apis/api-logs/LogsAPI.mjs +5 -5
  49. package/dist/esm/apis/api-logs/LogsAPI.mjs.map +1 -1
  50. package/dist/esm/apis/bank-accounts/BankAccountAPI.mjs +50 -0
  51. package/dist/esm/apis/bank-accounts/BankAccountAPI.mjs.map +1 -0
  52. package/dist/esm/apis/bank-transactions/BankTransactionAPI.mjs +159 -0
  53. package/dist/esm/apis/bank-transactions/BankTransactionAPI.mjs.map +1 -0
  54. package/dist/esm/apis/banks/BanksAPI.mjs +4 -4
  55. package/dist/esm/apis/banks/BanksAPI.mjs.map +1 -1
  56. package/dist/esm/apis/cards/CardSetupIntentsAPI.mjs +62 -0
  57. package/dist/esm/apis/cards/CardSetupIntentsAPI.mjs.map +1 -0
  58. package/dist/esm/apis/cards/CardsAPI.mjs +65 -0
  59. package/dist/esm/apis/cards/CardsAPI.mjs.map +1 -0
  60. package/dist/esm/apis/customers/CustomerAPI.mjs +111 -0
  61. package/dist/esm/apis/customers/CustomerAPI.mjs.map +1 -0
  62. package/dist/esm/apis/documents/DocumentsAPI.mjs +56 -0
  63. package/dist/esm/apis/documents/DocumentsAPI.mjs.map +1 -0
  64. package/dist/esm/apis/domains/DomainAPI.mjs +66 -0
  65. package/dist/esm/apis/domains/DomainAPI.mjs.map +1 -0
  66. package/dist/esm/apis/friends/FriendsAPI.mjs +43 -0
  67. package/dist/esm/apis/friends/FriendsAPI.mjs.map +1 -0
  68. package/dist/esm/apis/locations/LocationsAPI.mjs +88 -0
  69. package/dist/esm/apis/locations/LocationsAPI.mjs.map +1 -0
  70. package/dist/esm/apis/merchants/MerchantAPI.mjs +88 -0
  71. package/dist/esm/apis/merchants/MerchantAPI.mjs.map +1 -0
  72. package/dist/esm/apis/organizations/OrganizationsAPI.mjs +130 -0
  73. package/dist/esm/apis/organizations/OrganizationsAPI.mjs.map +1 -0
  74. package/dist/esm/apis/payment-methods/PaymentMethodsAPI.mjs +60 -0
  75. package/dist/esm/apis/payment-methods/PaymentMethodsAPI.mjs.map +1 -0
  76. package/dist/esm/apis/promo-codes/PromoCodesAPI.mjs +88 -0
  77. package/dist/esm/apis/promo-codes/PromoCodesAPI.mjs.map +1 -0
  78. package/dist/esm/apis/receipts/ReceiptAPI.mjs +4 -4
  79. package/dist/esm/apis/receipts/ReceiptAPI.mjs.map +1 -1
  80. package/dist/esm/apis/reviews/ReviewsAPI.mjs +1 -1
  81. package/dist/esm/apis/reviews/ReviewsAPI.mjs.map +1 -1
  82. package/dist/esm/apis/taxes/TaxesAPI.mjs +80 -0
  83. package/dist/esm/apis/taxes/TaxesAPI.mjs.map +1 -0
  84. package/dist/esm/apis/user/UserAPI.mjs +14 -0
  85. package/dist/esm/apis/user/UserAPI.mjs.map +1 -0
  86. package/dist/esm/apis/users/UsersAPI.mjs +28 -0
  87. package/dist/esm/apis/users/UsersAPI.mjs.map +1 -0
  88. package/dist/esm/index.mjs +19 -3
  89. package/dist/esm/index.mjs.map +1 -1
  90. package/dist/umd/index.js +1242 -75
  91. package/dist/umd/index.js.map +1 -1
  92. package/package.json +4 -8
package/dist/umd/index.js CHANGED
@@ -19,21 +19,240 @@
19
19
  return context;
20
20
  };
21
21
 
22
- const LOGS_KEY = "LOGS";
22
+ var SBApiKeys;
23
+ (function (SBApiKeys) {
24
+ SBApiKeys["BankAccounts"] = "BANK_ACCOUNT";
25
+ SBApiKeys["BankAccountTransactions"] = "BANK_ACCOUNT_TRANSACTIONS";
26
+ SBApiKeys["BankTransactions"] = "BANK_TRANSACTIONS";
27
+ SBApiKeys["BankInstitutions"] = "BANK_INSTITUTIONS";
28
+ SBApiKeys["Cards"] = "CARDS";
29
+ SBApiKeys["CardSetupIntents"] = "CARDS_SETUP_INTENTS";
30
+ SBApiKeys["Documents"] = "DOCUMENTS";
31
+ SBApiKeys["Organizations"] = "ORGANIZATIONS";
32
+ SBApiKeys["Logs"] = "LOGS";
33
+ SBApiKeys["Locations"] = "LOCATIONS";
34
+ SBApiKeys["Merchants"] = "MERCHANTS";
35
+ SBApiKeys["PromoCodes"] = "PROMO_CODES";
36
+ SBApiKeys["Domains"] = "DOMAINS";
37
+ SBApiKeys["User"] = "USER";
38
+ SBApiKeys["Users"] = "USERS";
39
+ SBApiKeys["PaymentMethods"] = "PAYMENT_METHODS";
40
+ SBApiKeys["Taxes"] = "TAXES";
41
+ SBApiKeys["Friends"] = "FRIENDS";
42
+ })(SBApiKeys || (SBApiKeys = {}));
43
+
23
44
  const useGetLogById = (id, options, config) => {
24
45
  const client = useApiClient();
25
46
  return reactQuery.useQuery({
26
- queryKey: [LOGS_KEY, id],
47
+ queryKey: [SBApiKeys.Logs, id],
27
48
  queryFn: async () => await client.logs.getById(id, options, config)
28
49
  });
29
50
  };
30
51
  const useListLogs = (request, options, config) => {
31
52
  const client = useApiClient();
32
53
  return reactQuery.useQuery({
33
- queryKey: [LOGS_KEY, request],
34
- queryFn: async () => await client.logs.get(request, options, config)
54
+ queryKey: [SBApiKeys.Logs, request],
55
+ queryFn: async () => await client.logs.list(request, options, config)
56
+ });
57
+ };
58
+
59
+ const useGetBankAccountById = (id, options, config) => {
60
+ const client = useApiClient();
61
+ return reactQuery.useQuery({
62
+ queryKey: [SBApiKeys.BankAccounts, id],
63
+ queryFn: async () => {
64
+ return client.bankAccounts.getById(id, options, config);
65
+ }
66
+ });
67
+ };
68
+ const useGetBankAccounts = request => {
69
+ const client = useApiClient();
70
+ return reactQuery.useQuery({
71
+ queryKey: [SBApiKeys.BankAccounts, request],
72
+ queryFn: async request => {
73
+ return client.bankAccounts.get(request);
74
+ }
75
+ });
76
+ };
77
+ const useListBankAccountTransanctions = (id, request, options, config) => {
78
+ const client = useApiClient();
79
+ return reactQuery.useInfiniteQuery({
80
+ initialPageParam: request.page,
81
+ queryKey: [SBApiKeys.BankAccounts, id, request],
82
+ queryFn: async ({
83
+ pageParam = 1
84
+ }) => {
85
+ request.page = pageParam;
86
+ return client.bankAccounts.listTransactions(id, request, options, config);
87
+ },
88
+ getPreviousPageParam: firstPage => {
89
+ if (firstPage.metadata.currentPage === 1) {
90
+ return 1;
91
+ }
92
+ return firstPage.metadata.currentPage - 1;
93
+ },
94
+ getNextPageParam: lastPage => {
95
+ if (lastPage.metadata.currentPage === lastPage.metadata.pageCount) {
96
+ return undefined;
97
+ }
98
+ return lastPage.metadata.currentPage + 1;
99
+ }
100
+ });
101
+ };
102
+
103
+ const useListBankTransactions = request => {
104
+ const client = useApiClient();
105
+ return reactQuery.useInfiniteQuery({
106
+ initialPageParam: request.page,
107
+ queryKey: ["bankTransactions", request],
108
+ queryFn: async ({
109
+ pageParam = 1
110
+ }) => {
111
+ return client.bankTransactions.list({
112
+ ...request,
113
+ page: pageParam
114
+ });
115
+ },
116
+ getNextPageParam: lastPage => {
117
+ if (lastPage.metadata.currentPage === lastPage.metadata.pageCount) {
118
+ return undefined;
119
+ }
120
+ return lastPage.metadata.currentPage + 1;
121
+ }
122
+ });
123
+ };
124
+ const useGetBankTransaction = id => {
125
+ const client = useApiClient();
126
+ return reactQuery.useQuery({
127
+ queryKey: ["bankTransaction", id],
128
+ queryFn: async () => await client.bankTransactions.getById(id)
35
129
  });
36
130
  };
131
+ // export const useAssociateReceipt = () => {
132
+ // const client = useApiClient();
133
+ // return useMutation<
134
+ // SBReceipt,
135
+ // SBApiException,
136
+ // { id: number; receiptId: number }
137
+ // >({
138
+ // mutationFn: ({ id, receiptId }) => await,
139
+ // onSuccess: (_, { id, receiptId }) => {
140
+ // queryClient.invalidateQueries({
141
+ // queryKey: ["bankTransaction", id],
142
+ // });
143
+ // queryClient.invalidateQueries({ queryKey: ["receipt", receiptId] });
144
+ // },
145
+ // });
146
+ // };
147
+ // export const useLinkDocuments = () => {
148
+ // const client = useApiClient();
149
+ // return useMutation<
150
+ // SBDocument[],
151
+ // SBApiException,
152
+ // { id: number; documents: number[] }
153
+ // >({
154
+ // mutationFn: async({ id, documents }) => await client.bankAccounts,
155
+ // onSuccess: (_, { id }) => {
156
+ // queryClient.invalidateQueries({
157
+ // queryKey: ["bankTransaction", id],
158
+ // });
159
+ // queryClient.invalidateQueries({ queryKey: ["pendingDocuments"] });
160
+ // },
161
+ // });
162
+ // };
163
+ // export const useUnlinkDocument = () => {
164
+ // const client = useApiClient();
165
+ // return useMutation<SBDocument, SBApiException, { id: number; documentId: number }>({
166
+ // mutationFn: ({ id, documentId }) => {
167
+ // },
168
+ // onMutate: async ({ id, documentId }) => {
169
+ // await queryClient.cancelQueries({
170
+ // queryKey: ["bankTransaction", id],
171
+ // });
172
+ // const previousTransaction =
173
+ // queryClient.getQueryData<SBBankTransaction>([
174
+ // "bankTransaction",
175
+ // id,
176
+ // ]);
177
+ // queryClient.setQueryData<SBBankTransaction>(
178
+ // ["bankTransaction", id],
179
+ // (old) => {
180
+ // if (old) {
181
+ // return {
182
+ // ...old,
183
+ // documents: old.documents.filter(
184
+ // (doc) => doc.id !== documentId,
185
+ // ),
186
+ // };
187
+ // }
188
+ // return old;
189
+ // },
190
+ // );
191
+ // return { previousTransaction };
192
+ // },
193
+ // onError: (_, __, context) => {
194
+ // if (context?.previousTransaction) {
195
+ // queryClient.setQueryData(
196
+ // ["bankTransaction", context.previousTransaction.id],
197
+ // context.previousTransaction,
198
+ // );
199
+ // }
200
+ // },
201
+ // onSettled: (data, error, { id }) => {
202
+ // queryClient.invalidateQueries({
203
+ // queryKey: ["bankTransaction", id],
204
+ // });
205
+ // queryClient.invalidateQueries({ queryKey: ["pendingDocuments"] });
206
+ // },
207
+ // });
208
+ // };
209
+ // export const useRenameDocument = () => {
210
+ // const client = useApiClient();
211
+ // return useMutation<SBDocument, SBApiException>({
212
+ // mutationFn: (id: number, documentId, request) =>
213
+ // client.bankTransactions.renameDocument(id, documentId, request),
214
+ // onMutate: async ({ id, documentId, request }) => {
215
+ // await queryClient.cancelQueries({
216
+ // queryKey: ["bankTransaction", id],
217
+ // });
218
+ // const previousTransaction =
219
+ // queryClient.getQueryData<SBBankTransaction>([
220
+ // "bankTransaction",
221
+ // id,
222
+ // ]);
223
+ // queryClient.setQueryData<SBBankTransaction>(
224
+ // ["bankTransaction", id],
225
+ // (old) => {
226
+ // if (old) {
227
+ // const index = old.documents.findIndex(
228
+ // (doc) => doc.id === documentId,
229
+ // );
230
+ // if (index !== -1) {
231
+ // old.documents[index].name = request.name;
232
+ // }
233
+ // return old;
234
+ // }
235
+ // return old;
236
+ // },
237
+ // );
238
+ // return { previousTransaction };
239
+ // },
240
+ // onError: (_, __, context) => {
241
+ // if (context?.previousTransaction) {
242
+ // queryClient.setQueryData(
243
+ // ["bankTransaction", context.previousTransaction.id],
244
+ // context.previousTransaction,
245
+ // );
246
+ // }
247
+ // },
248
+ // onSettled: (data, error, { id }) => {
249
+ // queryClient.invalidateQueries({
250
+ // queryKey: ["bankTransaction", id],
251
+ // });
252
+ // queryClient.invalidateQueries({ queryKey: ["pendingDocuments"] });
253
+ // },
254
+ // });
255
+ // };
37
256
 
38
257
  const queryClient = new reactQuery.QueryClient();
39
258
  function SmartbillsSDKProvider({
@@ -52,30 +271,678 @@
52
271
  const BANK_TRANSACTIONS_KEY = "bankTransactions";
53
272
  const useGetBankById = id => {
54
273
  const client = useApiClient();
55
- return reactQuery.useQuery({
56
- queryKey: [BANKS_KEY, id],
57
- queryFn: async () => await client.banks.getById(id)
274
+ return reactQuery.useQuery({
275
+ queryKey: [BANKS_KEY, id],
276
+ queryFn: async () => await client.banks.getById(id)
277
+ });
278
+ };
279
+ const useGetBankAccountForBank = (id, accountId) => {
280
+ const client = useApiClient();
281
+ return reactQuery.useQuery({
282
+ queryKey: [BANK_ACCOUNTS_KEY, id, accountId],
283
+ queryFn: async () => await client.banks.getBankAccount(id, accountId)
284
+ });
285
+ };
286
+ const useGetBankAccountTransactions = (id, accountId, request) => {
287
+ const client = useApiClient();
288
+ return reactQuery.useInfiniteQuery({
289
+ initialPageParam: request.page,
290
+ queryKey: [BANK_TRANSACTIONS_KEY, id, accountId],
291
+ queryFn: async ({
292
+ pageParam = 1
293
+ }) => {
294
+ return await client.banks.listBankAccountTransactions(id, accountId, {
295
+ ...request,
296
+ page: pageParam
297
+ });
298
+ },
299
+ getNextPageParam: lastPage => {
300
+ if (lastPage.metadata.currentPage === lastPage.metadata.pageCount) {
301
+ return undefined;
302
+ }
303
+ return lastPage.metadata.currentPage + 1;
304
+ }
305
+ });
306
+ };
307
+ const useGetBankLinkToken = () => {
308
+ const client = useApiClient();
309
+ return reactQuery.useQuery({
310
+ queryKey: ["bankLinkToken"],
311
+ queryFn: async () => await client.banks.getBankLinkToken()
312
+ });
313
+ };
314
+ const useGetBankLink = () => {
315
+ const client = useApiClient();
316
+ return reactQuery.useQuery({
317
+ queryKey: ["bankLink"],
318
+ queryFn: async () => await client.banks.getBankLink()
319
+ });
320
+ };
321
+ const useGetBanks = request => {
322
+ const client = useApiClient();
323
+ return reactQuery.useQuery({
324
+ queryKey: [BANKS_KEY, request],
325
+ queryFn: async () => await client.banks.get(request)
326
+ });
327
+ };
328
+ const useCreateBank = () => {
329
+ const client = useApiClient();
330
+ return reactQuery.useMutation({
331
+ mutationFn: async request => await client.banks.create(request),
332
+ onSuccess: () => {
333
+ queryClient.invalidateQueries({
334
+ queryKey: [BANKS_KEY]
335
+ });
336
+ }
337
+ });
338
+ };
339
+ const useDeleteBank = id => {
340
+ const client = useApiClient();
341
+ return reactQuery.useMutation({
342
+ mutationFn: async () => await client.banks.delete(id),
343
+ onMutate: async () => {
344
+ await queryClient.cancelQueries({
345
+ queryKey: [BANKS_KEY]
346
+ });
347
+ const previousBanks = queryClient.getQueryData([BANKS_KEY]);
348
+ queryClient.setQueryData([BANKS_KEY], old => ({
349
+ ...old,
350
+ data: old.data.filter(bank => bank.id !== id)
351
+ }));
352
+ return {
353
+ previousBanks
354
+ };
355
+ },
356
+ onError: (err, _, context) => {
357
+ queryClient.setQueryData([BANKS_KEY], context?.previousBanks);
358
+ },
359
+ onSettled: () => {
360
+ queryClient.invalidateQueries({
361
+ queryKey: [BANKS_KEY]
362
+ });
363
+ }
364
+ });
365
+ };
366
+
367
+ const useCreateCard = () => {
368
+ const client = useApiClient();
369
+ return reactQuery.useMutation({
370
+ mutationFn: async (request, options, config) => {
371
+ return await client.cards.create(request, options, config);
372
+ },
373
+ onSuccess: () => {
374
+ queryClient.invalidateQueries({
375
+ queryKey: [SBApiKeys.Cards]
376
+ });
377
+ }
378
+ });
379
+ };
380
+ const useAttachCard = () => {
381
+ const client = useApiClient();
382
+ return reactQuery.useMutation({
383
+ mutationFn: async (request, options, config) => {
384
+ return await client.cards.attach(request, options, config);
385
+ },
386
+ onSuccess: (data, id) => {
387
+ queryClient.invalidateQueries({
388
+ queryKey: [SBApiKeys.Cards, id]
389
+ });
390
+ }
391
+ });
392
+ };
393
+ const useDetachCard = () => {
394
+ const client = useApiClient();
395
+ return reactQuery.useMutation({
396
+ mutationFn: async (id, options, config) => {
397
+ return await client.cards.detach(id, options, config);
398
+ },
399
+ onSuccess: (data, id) => {
400
+ queryClient.invalidateQueries({
401
+ queryKey: [SBApiKeys.Cards, id]
402
+ });
403
+ }
404
+ });
405
+ };
406
+ const useGetCards = (request, options, config) => {
407
+ const client = useApiClient();
408
+ return reactQuery.useQuery({
409
+ queryKey: [SBApiKeys.Cards],
410
+ queryFn: async () => {
411
+ return await client.cards.get(request, options, config);
412
+ }
413
+ });
414
+ };
415
+ const useGetCardById = (id, options, config) => {
416
+ const client = useApiClient();
417
+ return reactQuery.useQuery({
418
+ queryKey: [SBApiKeys.Cards, id],
419
+ queryFn: async () => {
420
+ return await client.cards.getById(id, options, config);
421
+ }
422
+ });
423
+ };
424
+
425
+ const useCreateCardSetupIntent = () => {
426
+ const client = useApiClient();
427
+ return reactQuery.useMutation({
428
+ mutationKey: [SBApiKeys.CardSetupIntents],
429
+ mutationFn: async ({
430
+ options,
431
+ config
432
+ }) => {
433
+ return await client.cards.createSetupIntent(options, config);
434
+ },
435
+ onSuccess: data => {
436
+ queryClient.invalidateQueries({
437
+ queryKey: [SBApiKeys.CardSetupIntents, data.id]
438
+ });
439
+ }
440
+ });
441
+ };
442
+ const useConfirmCardSetupIntent = () => {
443
+ const client = useApiClient();
444
+ return reactQuery.useMutation({
445
+ mutationKey: [SBApiKeys.CardSetupIntents],
446
+ mutationFn: async (id, options, config) => {
447
+ return await client.cards.confirmSetupIntent(id, options, config);
448
+ },
449
+ onSuccess: (data, id) => {
450
+ queryClient.invalidateQueries({
451
+ queryKey: [SBApiKeys.CardSetupIntents, id]
452
+ });
453
+ }
454
+ });
455
+ };
456
+ const useCancelCardSetupIntent = () => {
457
+ const client = useApiClient();
458
+ return reactQuery.useMutation({
459
+ mutationKey: [SBApiKeys.CardSetupIntents],
460
+ mutationFn: async (id, options, config) => {
461
+ return await client.cards.cancelSetupIntent(id, options, config);
462
+ },
463
+ onSuccess: (data, id) => {
464
+ queryClient.invalidateQueries({
465
+ queryKey: [SBApiKeys.CardSetupIntents, id]
466
+ });
467
+ }
468
+ });
469
+ };
470
+ const useGetCardSetupIntentById = id => {
471
+ const client = useApiClient();
472
+ return reactQuery.useQuery({
473
+ queryKey: [SBApiKeys.CardSetupIntents, id],
474
+ queryFn: async () => {
475
+ return await client.cards.getSetupIntent(id);
476
+ }
477
+ });
478
+ };
479
+
480
+ const useGetDocuments = (request, options, config) => {
481
+ const client = useApiClient();
482
+ return reactQuery.useQuery({
483
+ queryKey: [SBApiKeys.Documents, request],
484
+ queryFn: async () => {
485
+ return await client.documents.list(request, options, config);
486
+ }
487
+ });
488
+ };
489
+ const useGetDocument = (id, options, config) => {
490
+ const client = useApiClient();
491
+ return reactQuery.useQuery({
492
+ queryKey: [SBApiKeys.Documents, id],
493
+ queryFn: async () => {
494
+ return await client.documents.getById(id, options, config);
495
+ }
496
+ });
497
+ };
498
+ const useUploadDocument = () => {
499
+ const client = useApiClient();
500
+ return reactQuery.useMutation({
501
+ mutationFn: async ({
502
+ request,
503
+ options,
504
+ config
505
+ }) => {
506
+ return await client.documents.upload(request, options, config);
507
+ },
508
+ onSuccess: data => {
509
+ queryClient.invalidateQueries({
510
+ queryKey: [SBApiKeys.Documents, data.id]
511
+ });
512
+ }
513
+ });
514
+ };
515
+ const useDeleteDocument = () => {
516
+ const client = useApiClient();
517
+ return reactQuery.useMutation({
518
+ mutationFn: async id => {
519
+ return await client.documents.delete(id);
520
+ },
521
+ onSuccess: (data, id) => {
522
+ queryClient.invalidateQueries({
523
+ queryKey: [SBApiKeys.Documents, id]
524
+ });
525
+ }
526
+ });
527
+ };
528
+
529
+ const useGetFriends = (request, options) => {
530
+ const client = useApiClient();
531
+ return reactQuery.useQuery({
532
+ queryKey: [SBApiKeys.Friends, request],
533
+ queryFn: async () => {
534
+ return await client.friends.list(request, options);
535
+ }
536
+ });
537
+ };
538
+ const useListRecommandedFriends = (request, options, config) => {
539
+ const client = useApiClient();
540
+ return reactQuery.useQuery({
541
+ queryKey: [SBApiKeys.Friends, request],
542
+ queryFn: async () => {
543
+ return await client.friends.listRecommanded(request, options, config);
544
+ }
545
+ });
546
+ };
547
+ const useDeleteFriend = () => {
548
+ const client = useApiClient();
549
+ return reactQuery.useMutation({
550
+ mutationFn: async ({
551
+ id,
552
+ options,
553
+ config
554
+ }) => {
555
+ return await client.friends.delete(id, options, config);
556
+ },
557
+ onSuccess: (data, id) => {
558
+ queryClient.invalidateQueries({
559
+ queryKey: [SBApiKeys.Friends, id]
560
+ });
561
+ }
562
+ });
563
+ };
564
+
565
+ const useListMerchants = (request, options, config) => {
566
+ const client = useApiClient();
567
+ return reactQuery.useInfiniteQuery({
568
+ initialPageParam: 1,
569
+ queryKey: [SBApiKeys.Merchants, request],
570
+ queryFn: async ({
571
+ pageParam = 1
572
+ }) => {
573
+ return await client.merchants.list({
574
+ ...request,
575
+ page: pageParam
576
+ }, options, config);
577
+ },
578
+ getNextPageParam: lastPage => {
579
+ if (lastPage.metadata.currentPage === lastPage.metadata.pageCount) {
580
+ return undefined;
581
+ }
582
+ return lastPage.metadata.currentPage + 1;
583
+ }
584
+ });
585
+ };
586
+ const useGetMerchantById = (id, options, config) => {
587
+ const client = useApiClient();
588
+ return reactQuery.useQuery({
589
+ queryKey: [SBApiKeys.Merchants, id],
590
+ queryFn: async () => await client.merchants.getById(id, options, config)
591
+ });
592
+ };
593
+ const useCreateMerchant = () => {
594
+ const client = useApiClient();
595
+ return reactQuery.useMutation({
596
+ mutationFn: async (request, options, config) => {
597
+ return await client.merchants.create(request, options, config);
598
+ },
599
+ onSuccess: () => {
600
+ queryClient.invalidateQueries({
601
+ queryKey: [SBApiKeys.Merchants]
602
+ });
603
+ }
604
+ });
605
+ };
606
+ const useDeleteMerchant = () => {
607
+ const client = useApiClient();
608
+ return reactQuery.useMutation({
609
+ mutationKey: [SBApiKeys.Merchants],
610
+ mutationFn: async (id, options, config) => {
611
+ return await client.merchants.delete(id, options, config);
612
+ },
613
+ onSuccess: (_, id) => {
614
+ queryClient.invalidateQueries({
615
+ queryKey: [SBApiKeys.Merchants]
616
+ });
617
+ queryClient.invalidateQueries({
618
+ queryKey: [SBApiKeys.Merchants, id]
619
+ });
620
+ }
621
+ });
622
+ };
623
+ const useUpdateMerchant = () => {
624
+ const client = useApiClient();
625
+ return reactQuery.useMutation({
626
+ mutationKey: [SBApiKeys.Merchants],
627
+ mutationFn: async ({
628
+ id,
629
+ request,
630
+ options,
631
+ config
632
+ }) => {
633
+ return await client.merchants.update(id, request, options, config);
634
+ },
635
+ onSuccess: (_, id) => {
636
+ queryClient.invalidateQueries({
637
+ queryKey: [SBApiKeys.Merchants]
638
+ });
639
+ queryClient.invalidateQueries({
640
+ queryKey: [SBApiKeys.Merchants, id]
641
+ });
642
+ }
643
+ });
644
+ };
645
+
646
+ const CUSTOMER_KEY = "customers";
647
+ const useGetCustomerById = (id, options) => {
648
+ const client = useApiClient();
649
+ return reactQuery.useQuery({
650
+ queryKey: [CUSTOMER_KEY, id],
651
+ queryFn: async () => {
652
+ try {
653
+ return await client.customers.getById(id, options);
654
+ } catch (exception) {
655
+ throw exception;
656
+ }
657
+ }
658
+ });
659
+ };
660
+ const useListCustomers = (request, options) => {
661
+ const client = useApiClient();
662
+ return reactQuery.useInfiniteQuery({
663
+ queryKey: [CUSTOMER_KEY],
664
+ queryFn: async () => {
665
+ try {
666
+ return await client.customers.list(request, options);
667
+ } catch (exception) {
668
+ throw exception;
669
+ }
670
+ },
671
+ initialPageParam: 1,
672
+ getNextPageParam: (lastPage, allPages, lastPageParam) => {
673
+ if (lastPage.metadata.currentPage === lastPage.metadata.pageCount) {
674
+ return undefined;
675
+ }
676
+ return lastPageParam + 1;
677
+ },
678
+ getPreviousPageParam: (firstPage, allPages, firstPageParam) => {
679
+ if (firstPage.metadata.currentPage <= 1) {
680
+ return undefined;
681
+ }
682
+ return firstPageParam - 1;
683
+ }
684
+ });
685
+ };
686
+ const useCreateCustomer = (request, options) => {
687
+ const client = useApiClient();
688
+ return reactQuery.useMutation({
689
+ mutationKey: [CUSTOMER_KEY],
690
+ mutationFn: async () => {
691
+ try {
692
+ return await client.customers.create(request, options);
693
+ } catch (exception) {
694
+ throw exception;
695
+ }
696
+ },
697
+ onMutate: async Customer => {
698
+ await queryClient.cancelQueries({
699
+ queryKey: [CUSTOMER_KEY]
700
+ });
701
+ const previousTodos = queryClient.getQueryData([CUSTOMER_KEY]);
702
+ // queryClient.setQueryData([CUSTOMER_KEY], (old) => [...old, newTodo])
703
+ // Return a context object with the snapshotted value
704
+ return {
705
+ previousTodos
706
+ };
707
+ },
708
+ onError: (err, newTodo, context) => {
709
+ queryClient.setQueryData([CUSTOMER_KEY], context.previousTodos);
710
+ },
711
+ onSettled: () => {
712
+ queryClient.invalidateQueries({
713
+ queryKey: [CUSTOMER_KEY]
714
+ });
715
+ }
716
+ });
717
+ };
718
+ const useDeleteCustomer = (id, options) => {
719
+ const client = useApiClient();
720
+ return reactQuery.useMutation({
721
+ mutationKey: [CUSTOMER_KEY, id],
722
+ mutationFn: async () => {
723
+ try {
724
+ return await client.customers.delete(id, options);
725
+ } catch (exception) {
726
+ throw exception;
727
+ }
728
+ },
729
+ onMutate: async Customer => {
730
+ await queryClient.cancelQueries({
731
+ queryKey: [CUSTOMER_KEY]
732
+ });
733
+ const previousTodos = queryClient.getQueryData([CUSTOMER_KEY]);
734
+ // queryClient.setQueryData([CUSTOMER_KEY], (old) => [...old, newTodo])
735
+ // Return a context object with the snapshotted value
736
+ return {
737
+ previousTodos
738
+ };
739
+ },
740
+ onError: (err, newTodo, context) => {
741
+ queryClient.setQueryData([CUSTOMER_KEY], context.previousTodos);
742
+ },
743
+ onSettled: () => {
744
+ queryClient.invalidateQueries({
745
+ queryKey: [CUSTOMER_KEY]
746
+ });
747
+ }
748
+ });
749
+ };
750
+
751
+ const useGetDomains = (request, options, config) => {
752
+ const client = useApiClient();
753
+ return reactQuery.useInfiniteQuery({
754
+ initialPageParam: 1,
755
+ queryKey: [SBApiKeys.Domains, request],
756
+ queryFn: async ({
757
+ pageParam = 1
758
+ }) => {
759
+ return await client.domains.list({
760
+ ...request,
761
+ page: pageParam
762
+ }, options, config);
763
+ },
764
+ getNextPageParam: lastPage => {
765
+ if (lastPage.metadata.currentPage === lastPage.metadata.pageCount) {
766
+ return undefined;
767
+ }
768
+ return lastPage.metadata.currentPage + 1;
769
+ }
770
+ });
771
+ };
772
+ const useGetDomainById = (id, options, config) => {
773
+ const client = useApiClient();
774
+ return reactQuery.useQuery({
775
+ queryKey: [SBApiKeys.Domains, id],
776
+ queryFn: async () => await client.domains.getById(id, options, config)
777
+ });
778
+ };
779
+ const useCreateDomain = () => {
780
+ const client = useApiClient();
781
+ return reactQuery.useMutation({
782
+ mutationFn: async (request, options, config) => {
783
+ return await client.domains.create(request, options, config);
784
+ },
785
+ onSuccess: () => {
786
+ queryClient.invalidateQueries({
787
+ queryKey: [SBApiKeys.Domains]
788
+ });
789
+ }
790
+ });
791
+ };
792
+ const useDeleteDomain = () => {
793
+ const client = useApiClient();
794
+ return reactQuery.useMutation({
795
+ mutationKey: [SBApiKeys.Domains],
796
+ mutationFn: async (id, options, config) => {
797
+ return await client.domains.delete(id, options, config);
798
+ },
799
+ onSuccess: (_, id) => {
800
+ queryClient.invalidateQueries({
801
+ queryKey: [SBApiKeys.Domains]
802
+ });
803
+ queryClient.invalidateQueries({
804
+ queryKey: [SBApiKeys.Domains, id]
805
+ });
806
+ }
807
+ });
808
+ };
809
+
810
+ const useGetLocations = (request, options, config) => {
811
+ const client = useApiClient();
812
+ return reactQuery.useInfiniteQuery({
813
+ initialPageParam: 1,
814
+ queryKey: [SBApiKeys.Locations, request],
815
+ queryFn: async ({
816
+ pageParam = 1
817
+ }) => {
818
+ return await client.locations.list({
819
+ ...request,
820
+ page: pageParam
821
+ }, options, config);
822
+ },
823
+ getNextPageParam: lastPage => {
824
+ if (lastPage.metadata.currentPage === lastPage.metadata.pageCount) {
825
+ return undefined;
826
+ }
827
+ return lastPage.metadata.currentPage + 1;
828
+ }
829
+ });
830
+ };
831
+ const useGetLocationById = (id, options, config) => {
832
+ const client = useApiClient();
833
+ return reactQuery.useQuery({
834
+ queryKey: [SBApiKeys.Locations, id],
835
+ queryFn: async () => await client.locations.getById(id, options, config)
836
+ });
837
+ };
838
+ const useCreateLocation = () => {
839
+ const client = useApiClient();
840
+ return reactQuery.useMutation({
841
+ mutationFn: async (request, options, config) => {
842
+ return await client.locations.create(request, options, config);
843
+ },
844
+ onSuccess: () => {
845
+ queryClient.invalidateQueries({
846
+ queryKey: [SBApiKeys.Locations]
847
+ });
848
+ }
849
+ });
850
+ };
851
+ const useDeleteLocation = () => {
852
+ const client = useApiClient();
853
+ return reactQuery.useMutation({
854
+ mutationKey: [SBApiKeys.Locations],
855
+ mutationFn: async (id, options, config) => {
856
+ return await client.locations.delete(id, options, config);
857
+ },
858
+ onSuccess: (_, id) => {
859
+ queryClient.invalidateQueries({
860
+ queryKey: [SBApiKeys.Locations]
861
+ });
862
+ queryClient.invalidateQueries({
863
+ queryKey: [SBApiKeys.Locations, id]
864
+ });
865
+ }
866
+ });
867
+ };
868
+ const useUpdateLocation = () => {
869
+ const client = useApiClient();
870
+ return reactQuery.useMutation({
871
+ mutationKey: [SBApiKeys.Locations],
872
+ mutationFn: async ({
873
+ id,
874
+ request,
875
+ options,
876
+ config
877
+ }) => {
878
+ return await client.locations.update(id, request, options, config);
879
+ },
880
+ onSuccess: (_, id) => {
881
+ queryClient.invalidateQueries({
882
+ queryKey: [SBApiKeys.Locations]
883
+ });
884
+ queryClient.invalidateQueries({
885
+ queryKey: [SBApiKeys.Locations, id]
886
+ });
887
+ }
888
+ });
889
+ };
890
+
891
+ const useGetToken = () => {
892
+ const client = useApiClient();
893
+ return reactQuery.useMutation({
894
+ mutationFn: async request => {
895
+ try {
896
+ return await client.oauth.getToken(request);
897
+ } catch (error) {
898
+ throw error;
899
+ }
900
+ }
901
+ });
902
+ };
903
+ const useGetAuthorizationCode = () => {
904
+ const client = useApiClient();
905
+ return reactQuery.useMutation({
906
+ mutationFn: async request => {
907
+ try {
908
+ return await client.oauth.getAuthorizationCode(request);
909
+ } catch (error) {
910
+ throw error;
911
+ }
912
+ }
58
913
  });
59
914
  };
60
- const useGetBankAccountForBank = (id, accountId) => {
915
+ const useRefreshToken = () => {
61
916
  const client = useApiClient();
62
- return reactQuery.useQuery({
63
- queryKey: [BANK_ACCOUNTS_KEY, id, accountId],
64
- queryFn: async () => await client.banks.getBankAccount(id, accountId)
917
+ return reactQuery.useMutation({
918
+ mutationFn: async request => {
919
+ try {
920
+ return await client.oauth.refreshToken(request);
921
+ } catch (error) {
922
+ throw error;
923
+ }
924
+ }
65
925
  });
66
926
  };
67
- const useGetBankAccountTransactions = (id, accountId, request) => {
927
+
928
+ const useListOrganizations = (request, options, config) => {
68
929
  const client = useApiClient();
69
930
  return reactQuery.useInfiniteQuery({
70
- initialPageParam: request.page,
71
- queryKey: [BANK_TRANSACTIONS_KEY, id, accountId],
931
+ initialPageParam: 1,
932
+ queryKey: [SBApiKeys.Organizations, request],
72
933
  queryFn: async ({
73
934
  pageParam = 1
74
935
  }) => {
75
- return await client.banks.getBankAccountTransactions(id, accountId, {
936
+ return client.organizations.list({
76
937
  ...request,
77
938
  page: pageParam
78
- });
939
+ }, options, config);
940
+ },
941
+ getPreviousPageParam: firstPage => {
942
+ if (firstPage.metadata.currentPage === 1) {
943
+ return undefined;
944
+ }
945
+ return firstPage.metadata.currentPage - 1;
79
946
  },
80
947
  getNextPageParam: lastPage => {
81
948
  if (lastPage.metadata.currentPage === lastPage.metadata.pageCount) {
@@ -85,99 +952,232 @@
85
952
  }
86
953
  });
87
954
  };
88
- const useGetBankLinkToken = () => {
955
+ const useGetOrganizationById = id => {
89
956
  const client = useApiClient();
90
957
  return reactQuery.useQuery({
91
- queryKey: ["bankLinkToken"],
92
- queryFn: async () => await client.banks.getBankLinkToken()
958
+ queryKey: ["organization", id],
959
+ queryFn: async () => await client.organizations.getById(id)
93
960
  });
94
961
  };
95
- const useGetBankLink = () => {
962
+ const useCreateOrganization = () => {
963
+ const client = useApiClient();
964
+ return reactQuery.useMutation({
965
+ mutationFn: async request => {
966
+ return client.organizations.create(request);
967
+ },
968
+ onSuccess: () => {
969
+ queryClient.invalidateQueries({
970
+ queryKey: [SBApiKeys.Organizations]
971
+ });
972
+ }
973
+ });
974
+ };
975
+ const useUpdateOrganization = () => {
976
+ const client = useApiClient();
977
+ return reactQuery.useMutation({
978
+ mutationFn: async ({
979
+ id,
980
+ request
981
+ }) => {
982
+ return client.organizations.update(id, request);
983
+ },
984
+ onSuccess: (_, {
985
+ id
986
+ }) => {
987
+ queryClient.invalidateQueries({
988
+ queryKey: ["organization", id]
989
+ });
990
+ queryClient.invalidateQueries({
991
+ queryKey: [SBApiKeys.Organizations]
992
+ });
993
+ }
994
+ });
995
+ };
996
+ const useDeleteOrganization = () => {
997
+ const client = useApiClient();
998
+ return reactQuery.useMutation({
999
+ mutationFn: async id => {
1000
+ return client.organizations.delete(id);
1001
+ },
1002
+ onSuccess: (_, id) => {
1003
+ queryClient.invalidateQueries({
1004
+ queryKey: [SBApiKeys.Organizations]
1005
+ });
1006
+ queryClient.invalidateQueries({
1007
+ queryKey: ["organization", id]
1008
+ });
1009
+ }
1010
+ });
1011
+ };
1012
+ const useListOrganizationMembers = (organizationId, request) => {
96
1013
  const client = useApiClient();
97
1014
  return reactQuery.useQuery({
98
- queryKey: ["bankLink"],
99
- queryFn: async () => await client.banks.getBankLink()
1015
+ queryKey: ["organizationMembers", organizationId, request],
1016
+ queryFn: async () => {
1017
+ return client.organizations.listMembers(organizationId, request);
1018
+ }
100
1019
  });
101
1020
  };
102
- const useListBanks = request => {
1021
+ const useGetOrganizationMemberById = (organizationId, id) => {
103
1022
  const client = useApiClient();
104
1023
  return reactQuery.useQuery({
105
- queryKey: [BANKS_KEY, request],
106
- queryFn: async () => await client.banks.list(request)
1024
+ queryKey: ["organizationMember", organizationId, id],
1025
+ queryFn: async () => await client.organizations.getMemberById(organizationId, id)
107
1026
  });
108
1027
  };
109
- const useCreateBank = () => {
1028
+ const useDeleteOrganizationMember = () => {
110
1029
  const client = useApiClient();
111
1030
  return reactQuery.useMutation({
112
- mutationFn: async request => await client.banks.create(request),
113
- onSuccess: () => {
1031
+ mutationFn: async ({
1032
+ organizationId,
1033
+ id
1034
+ }) => {
1035
+ return client.organizations.deleteMember(organizationId, id);
1036
+ },
1037
+ onSuccess: (_, {
1038
+ organizationId,
1039
+ id
1040
+ }) => {
114
1041
  queryClient.invalidateQueries({
115
- queryKey: [BANKS_KEY]
1042
+ queryKey: ["organizationMembers", organizationId]
1043
+ });
1044
+ queryClient.invalidateQueries({
1045
+ queryKey: ["organizationMember", organizationId, id]
116
1046
  });
117
1047
  }
118
1048
  });
119
1049
  };
120
- const useDeleteBank = id => {
1050
+
1051
+ const useCreatePaymentMethod = () => {
121
1052
  const client = useApiClient();
122
1053
  return reactQuery.useMutation({
123
- mutationFn: async () => await client.banks.delete(id),
124
- onMutate: async () => {
125
- await queryClient.cancelQueries({
126
- queryKey: [BANKS_KEY]
127
- });
128
- const previousBanks = queryClient.getQueryData([BANKS_KEY]);
129
- queryClient.setQueryData([BANKS_KEY], old => ({
130
- ...old,
131
- data: old.data.filter(bank => bank.id !== id)
132
- }));
133
- return {
134
- previousBanks
135
- };
1054
+ mutationFn: async (request, options, config) => {
1055
+ return await client.paymentMethods.create(request, options, config);
136
1056
  },
137
- onError: (err, _, context) => {
138
- queryClient.setQueryData([BANKS_KEY], context?.previousBanks);
1057
+ onSuccess: () => {
1058
+ queryClient.invalidateQueries({
1059
+ queryKey: [SBApiKeys.PaymentMethods]
1060
+ });
1061
+ }
1062
+ });
1063
+ };
1064
+ const useGetPaymentMethods = (request, options, config) => {
1065
+ const client = useApiClient();
1066
+ return reactQuery.useQuery({
1067
+ queryKey: [SBApiKeys.PaymentMethods],
1068
+ queryFn: async () => {
1069
+ return await client.paymentMethods.get(request, options, config);
1070
+ }
1071
+ });
1072
+ };
1073
+ const useGetPaymentMethodById = (id, options, config) => {
1074
+ const client = useApiClient();
1075
+ return reactQuery.useQuery({
1076
+ queryKey: [SBApiKeys.PaymentMethods, id],
1077
+ queryFn: async () => {
1078
+ return await client.paymentMethods.getById(id, options, config);
1079
+ }
1080
+ });
1081
+ };
1082
+ const useDeletePaymentMethod = () => {
1083
+ const client = useApiClient();
1084
+ return reactQuery.useMutation({
1085
+ mutationFn: async (id, options, config) => {
1086
+ return await client.paymentMethods.delete(id, options, config);
139
1087
  },
140
- onSettled: () => {
1088
+ onSuccess: (data, id) => {
141
1089
  queryClient.invalidateQueries({
142
- queryKey: [BANKS_KEY]
1090
+ queryKey: [SBApiKeys.PaymentMethods, id]
143
1091
  });
144
1092
  }
145
1093
  });
146
1094
  };
147
-
148
- const useGetToken = () => {
1095
+ const useSetupPaymentMethod = () => {
149
1096
  const client = useApiClient();
150
1097
  return reactQuery.useMutation({
151
- mutationFn: async request => {
152
- try {
153
- return await client.oauth.getToken(request);
154
- } catch (error) {
155
- throw error;
1098
+ mutationFn: async (_, options, config) => {
1099
+ return await client.paymentMethods.setup(options, config);
1100
+ }
1101
+ });
1102
+ };
1103
+
1104
+ const useGetPromoCodes = (request, options, config) => {
1105
+ const client = useApiClient();
1106
+ return reactQuery.useInfiniteQuery({
1107
+ initialPageParam: 1,
1108
+ queryKey: [SBApiKeys.PromoCodes, request],
1109
+ queryFn: async ({
1110
+ pageParam = 1
1111
+ }) => {
1112
+ return await client.promoCodes.list({
1113
+ ...request,
1114
+ page: pageParam
1115
+ }, options, config);
1116
+ },
1117
+ getNextPageParam: lastPage => {
1118
+ if (lastPage.metadata.currentPage === lastPage.metadata.pageCount) {
1119
+ return undefined;
156
1120
  }
1121
+ return lastPage.metadata.currentPage + 1;
157
1122
  }
158
1123
  });
159
1124
  };
160
- const useGetAuthorizationCode = () => {
1125
+ const useGetPromoCodeById = (id, options, config) => {
1126
+ const client = useApiClient();
1127
+ return reactQuery.useQuery({
1128
+ queryKey: [SBApiKeys.PromoCodes, id],
1129
+ queryFn: async () => await client.promoCodes.getById(id, options, config)
1130
+ });
1131
+ };
1132
+ const useCreatePromoCode = () => {
161
1133
  const client = useApiClient();
162
1134
  return reactQuery.useMutation({
163
- mutationFn: async request => {
164
- try {
165
- return await client.oauth.getAuthorizationCode(request);
166
- } catch (error) {
167
- throw error;
168
- }
1135
+ mutationFn: async (request, options, config) => {
1136
+ return await client.promoCodes.create(request, options, config);
1137
+ },
1138
+ onSuccess: () => {
1139
+ queryClient.invalidateQueries({
1140
+ queryKey: [SBApiKeys.PromoCodes]
1141
+ });
169
1142
  }
170
1143
  });
171
1144
  };
172
- const useRefreshToken = () => {
1145
+ const useDeletePromoCode = () => {
173
1146
  const client = useApiClient();
174
1147
  return reactQuery.useMutation({
175
- mutationFn: async request => {
176
- try {
177
- return await client.oauth.refreshToken(request);
178
- } catch (error) {
179
- throw error;
180
- }
1148
+ mutationKey: [SBApiKeys.PromoCodes],
1149
+ mutationFn: async (id, options, config) => {
1150
+ return await client.promoCodes.delete(id, options, config);
1151
+ },
1152
+ onSuccess: (_, id) => {
1153
+ queryClient.invalidateQueries({
1154
+ queryKey: [SBApiKeys.PromoCodes]
1155
+ });
1156
+ queryClient.invalidateQueries({
1157
+ queryKey: [SBApiKeys.PromoCodes, id]
1158
+ });
1159
+ }
1160
+ });
1161
+ };
1162
+ const useUpdatePromoCode = () => {
1163
+ const client = useApiClient();
1164
+ return reactQuery.useMutation({
1165
+ mutationKey: [SBApiKeys.PromoCodes],
1166
+ mutationFn: async ({
1167
+ id,
1168
+ request,
1169
+ options,
1170
+ config
1171
+ }) => {
1172
+ return await client.promoCodes.update(id, request, options, config);
1173
+ },
1174
+ onSuccess: (_, id) => {
1175
+ queryClient.invalidateQueries({
1176
+ queryKey: [SBApiKeys.PromoCodes]
1177
+ });
1178
+ queryClient.invalidateQueries({
1179
+ queryKey: [SBApiKeys.PromoCodes, id]
1180
+ });
181
1181
  }
182
1182
  });
183
1183
  };
@@ -196,13 +1196,13 @@
196
1196
  }
197
1197
  });
198
1198
  };
199
- const useGetReceipts = (request, options) => {
1199
+ const useListReceipts = (request, options) => {
200
1200
  const client = useApiClient();
201
1201
  return reactQuery.useInfiniteQuery({
202
1202
  queryKey: [RECEIPTS_KEY],
203
1203
  queryFn: async () => {
204
1204
  try {
205
- return await client.receipts.get(request, options);
1205
+ return await client.receipts.list(request, options);
206
1206
  } catch (exception) {
207
1207
  throw exception;
208
1208
  }
@@ -215,7 +1215,7 @@
215
1215
  return lastPageParam + 1;
216
1216
  },
217
1217
  getPreviousPageParam: (firstPage, allPages, firstPageParam) => {
218
- if (firstPage.metadata.currentPage <= 1) {
1218
+ if (firstPage.metadata.currentPage == 1) {
219
1219
  return undefined;
220
1220
  }
221
1221
  return firstPageParam - 1;
@@ -265,7 +1265,7 @@
265
1265
  pageParam = 1
266
1266
  }) => {
267
1267
  try {
268
- return await client.reviews.get({
1268
+ return await client.reviews.list({
269
1269
  ...request,
270
1270
  page: pageParam
271
1271
  });
@@ -361,37 +1361,204 @@
361
1361
  });
362
1362
  };
363
1363
 
1364
+ const useListTaxes = (request, options, config) => {
1365
+ const client = useApiClient();
1366
+ return reactQuery.useQuery({
1367
+ queryKey: [SBApiKeys.Taxes],
1368
+ queryFn: async () => {
1369
+ return await client.taxes.list(request, options, config);
1370
+ }
1371
+ });
1372
+ };
1373
+ const useGetTaxById = (id, options, config) => {
1374
+ const client = useApiClient();
1375
+ return reactQuery.useQuery({
1376
+ queryKey: [SBApiKeys.Taxes, id],
1377
+ queryFn: async () => {
1378
+ return await client.taxes.getById(id, options, config);
1379
+ }
1380
+ });
1381
+ };
1382
+ const useCreateTax = () => {
1383
+ const client = useApiClient();
1384
+ return reactQuery.useMutation({
1385
+ mutationFn: async ({
1386
+ request,
1387
+ options,
1388
+ config
1389
+ }) => {
1390
+ return await client.taxes.create(request, options, config);
1391
+ },
1392
+ onSuccess: data => {
1393
+ queryClient.invalidateQueries({
1394
+ queryKey: [SBApiKeys.Taxes, data.id]
1395
+ });
1396
+ }
1397
+ });
1398
+ };
1399
+ const useDeleteTaxes = () => {
1400
+ const client = useApiClient();
1401
+ return reactQuery.useMutation({
1402
+ mutationFn: async ({
1403
+ id,
1404
+ options,
1405
+ config
1406
+ }) => {
1407
+ return await client.taxes.delete(id, options, config);
1408
+ },
1409
+ onSuccess: (_, request) => {
1410
+ queryClient.invalidateQueries({
1411
+ queryKey: [(SBApiKeys.Taxes, request.id)]
1412
+ });
1413
+ }
1414
+ });
1415
+ };
1416
+ const useUpdateTaxes = () => {
1417
+ const client = useApiClient();
1418
+ return reactQuery.useMutation({
1419
+ mutationFn: async ({
1420
+ id,
1421
+ request,
1422
+ options,
1423
+ config
1424
+ }) => {
1425
+ return await client.taxes.update(id, request, options, config);
1426
+ },
1427
+ onSuccess: (_, {
1428
+ id
1429
+ }) => {
1430
+ queryClient.invalidateQueries({
1431
+ queryKey: [SBApiKeys.Taxes, id]
1432
+ });
1433
+ }
1434
+ });
1435
+ };
1436
+
1437
+ const useGetCurrentUser = (options, config) => {
1438
+ const smartbillsClient = useApiClient();
1439
+ return reactQuery.useQuery({
1440
+ queryKey: [SBApiKeys.User],
1441
+ queryFn: async () => await smartbillsClient.user.get(options, config)
1442
+ });
1443
+ };
1444
+
1445
+ const useSearchUsers = (request, options, config) => {
1446
+ const client = useApiClient();
1447
+ return reactQuery.useInfiniteQuery({
1448
+ initialPageParam: 1,
1449
+ queryKey: [SBApiKeys.Users, request],
1450
+ queryFn: async ({
1451
+ pageParam = 1
1452
+ }) => {
1453
+ return await client.users.list({
1454
+ ...request,
1455
+ page: pageParam
1456
+ }, options, config);
1457
+ },
1458
+ getNextPageParam: lastPage => {
1459
+ if (lastPage.metadata.currentPage === lastPage.metadata.pageCount) {
1460
+ return undefined;
1461
+ }
1462
+ return lastPage.metadata.currentPage + 1;
1463
+ }
1464
+ });
1465
+ };
1466
+
364
1467
  exports.ApiClientProvider = ApiClientProvider;
365
1468
  exports.BANKS_KEY = BANKS_KEY;
366
1469
  exports.BANK_ACCOUNTS_KEY = BANK_ACCOUNTS_KEY;
367
1470
  exports.BANK_TRANSACTIONS_KEY = BANK_TRANSACTIONS_KEY;
368
- exports.LOGS_KEY = LOGS_KEY;
1471
+ exports.CUSTOMER_KEY = CUSTOMER_KEY;
369
1472
  exports.RECEIPTS_KEY = RECEIPTS_KEY;
370
1473
  exports.REVIEWS_KEY = REVIEWS_KEY;
371
1474
  exports.SmartbillsSDKProvider = SmartbillsSDKProvider;
372
1475
  exports.queryClient = queryClient;
373
1476
  exports.useApiClient = useApiClient;
1477
+ exports.useAttachCard = useAttachCard;
1478
+ exports.useCancelCardSetupIntent = useCancelCardSetupIntent;
1479
+ exports.useConfirmCardSetupIntent = useConfirmCardSetupIntent;
374
1480
  exports.useCreateBank = useCreateBank;
1481
+ exports.useCreateCard = useCreateCard;
1482
+ exports.useCreateCardSetupIntent = useCreateCardSetupIntent;
1483
+ exports.useCreateCustomer = useCreateCustomer;
1484
+ exports.useCreateDomain = useCreateDomain;
1485
+ exports.useCreateLocation = useCreateLocation;
1486
+ exports.useCreateMerchant = useCreateMerchant;
1487
+ exports.useCreateOrganization = useCreateOrganization;
1488
+ exports.useCreatePaymentMethod = useCreatePaymentMethod;
1489
+ exports.useCreatePromoCode = useCreatePromoCode;
375
1490
  exports.useCreateReview = useCreateReview;
1491
+ exports.useCreateTax = useCreateTax;
376
1492
  exports.useDeleteBank = useDeleteBank;
1493
+ exports.useDeleteCustomer = useDeleteCustomer;
1494
+ exports.useDeleteDocument = useDeleteDocument;
1495
+ exports.useDeleteDomain = useDeleteDomain;
1496
+ exports.useDeleteFriend = useDeleteFriend;
1497
+ exports.useDeleteLocation = useDeleteLocation;
1498
+ exports.useDeleteMerchant = useDeleteMerchant;
1499
+ exports.useDeleteOrganization = useDeleteOrganization;
1500
+ exports.useDeleteOrganizationMember = useDeleteOrganizationMember;
1501
+ exports.useDeletePaymentMethod = useDeletePaymentMethod;
1502
+ exports.useDeletePromoCode = useDeletePromoCode;
377
1503
  exports.useDeleteReceipt = useDeleteReceipt;
378
1504
  exports.useDeleteReview = useDeleteReview;
1505
+ exports.useDeleteTaxes = useDeleteTaxes;
1506
+ exports.useDetachCard = useDetachCard;
379
1507
  exports.useGetAuthorizationCode = useGetAuthorizationCode;
1508
+ exports.useGetBankAccountById = useGetBankAccountById;
380
1509
  exports.useGetBankAccountForBank = useGetBankAccountForBank;
381
1510
  exports.useGetBankAccountTransactions = useGetBankAccountTransactions;
1511
+ exports.useGetBankAccounts = useGetBankAccounts;
382
1512
  exports.useGetBankById = useGetBankById;
383
1513
  exports.useGetBankLink = useGetBankLink;
384
1514
  exports.useGetBankLinkToken = useGetBankLinkToken;
1515
+ exports.useGetBankTransaction = useGetBankTransaction;
1516
+ exports.useGetBanks = useGetBanks;
1517
+ exports.useGetCardById = useGetCardById;
1518
+ exports.useGetCardSetupIntentById = useGetCardSetupIntentById;
1519
+ exports.useGetCards = useGetCards;
1520
+ exports.useGetCurrentUser = useGetCurrentUser;
1521
+ exports.useGetCustomerById = useGetCustomerById;
1522
+ exports.useGetDocument = useGetDocument;
1523
+ exports.useGetDocuments = useGetDocuments;
1524
+ exports.useGetDomainById = useGetDomainById;
1525
+ exports.useGetDomains = useGetDomains;
1526
+ exports.useGetFriends = useGetFriends;
1527
+ exports.useGetLocationById = useGetLocationById;
1528
+ exports.useGetLocations = useGetLocations;
385
1529
  exports.useGetLogById = useGetLogById;
1530
+ exports.useGetMerchantById = useGetMerchantById;
1531
+ exports.useGetOrganizationById = useGetOrganizationById;
1532
+ exports.useGetOrganizationMemberById = useGetOrganizationMemberById;
1533
+ exports.useGetPaymentMethodById = useGetPaymentMethodById;
1534
+ exports.useGetPaymentMethods = useGetPaymentMethods;
1535
+ exports.useGetPromoCodeById = useGetPromoCodeById;
1536
+ exports.useGetPromoCodes = useGetPromoCodes;
386
1537
  exports.useGetReceiptById = useGetReceiptById;
387
- exports.useGetReceipts = useGetReceipts;
388
1538
  exports.useGetReviewById = useGetReviewById;
389
1539
  exports.useGetReviews = useGetReviews;
1540
+ exports.useGetTaxById = useGetTaxById;
390
1541
  exports.useGetToken = useGetToken;
391
- exports.useListBanks = useListBanks;
1542
+ exports.useListBankAccountTransanctions = useListBankAccountTransanctions;
1543
+ exports.useListBankTransactions = useListBankTransactions;
1544
+ exports.useListCustomers = useListCustomers;
392
1545
  exports.useListLogs = useListLogs;
1546
+ exports.useListMerchants = useListMerchants;
1547
+ exports.useListOrganizationMembers = useListOrganizationMembers;
1548
+ exports.useListOrganizations = useListOrganizations;
1549
+ exports.useListReceipts = useListReceipts;
1550
+ exports.useListRecommandedFriends = useListRecommandedFriends;
1551
+ exports.useListTaxes = useListTaxes;
393
1552
  exports.useRefreshToken = useRefreshToken;
1553
+ exports.useSearchUsers = useSearchUsers;
1554
+ exports.useSetupPaymentMethod = useSetupPaymentMethod;
1555
+ exports.useUpdateLocation = useUpdateLocation;
1556
+ exports.useUpdateMerchant = useUpdateMerchant;
1557
+ exports.useUpdateOrganization = useUpdateOrganization;
1558
+ exports.useUpdatePromoCode = useUpdatePromoCode;
394
1559
  exports.useUpdateReview = useUpdateReview;
1560
+ exports.useUpdateTaxes = useUpdateTaxes;
1561
+ exports.useUploadDocument = useUploadDocument;
395
1562
 
396
1563
  }));
397
1564
  //# sourceMappingURL=index.js.map