@bisondesk/core-sdk 1.0.23-B → 1.0.23

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 (225) hide show
  1. package/lib/constants.d.ts +0 -77
  2. package/lib/constants.d.ts.map +1 -1
  3. package/lib/constants.js +1 -924
  4. package/lib/constants.js.map +1 -1
  5. package/lib/types/crm.d.ts +30 -103
  6. package/lib/types/crm.d.ts.map +1 -1
  7. package/lib/types/crm.js +0 -16
  8. package/lib/types/crm.js.map +1 -1
  9. package/lib/types/definitions.d.ts +13 -15
  10. package/lib/types/definitions.d.ts.map +1 -1
  11. package/lib/types/fields.d.ts +25 -26
  12. package/lib/types/fields.d.ts.map +1 -1
  13. package/lib/types/fields.js +0 -4
  14. package/lib/types/fields.js.map +1 -1
  15. package/lib/types/interests.d.ts +25 -0
  16. package/lib/types/interests.d.ts.map +1 -0
  17. package/lib/types/{settings.js → interests.js} +1 -1
  18. package/lib/types/interests.js.map +1 -0
  19. package/lib/types/picklists.d.ts +4 -15
  20. package/lib/types/picklists.d.ts.map +1 -1
  21. package/lib/types/search.d.ts +4 -26
  22. package/lib/types/search.d.ts.map +1 -1
  23. package/lib/types/search.js.map +1 -1
  24. package/lib/types/storage.d.ts +11 -1
  25. package/lib/types/storage.d.ts.map +1 -1
  26. package/lib/types/storage.js +0 -15
  27. package/lib/types/storage.js.map +1 -1
  28. package/lib/types/tenants.d.ts +9 -32
  29. package/lib/types/tenants.d.ts.map +1 -1
  30. package/lib/types/tenants.js +0 -11
  31. package/lib/types/tenants.js.map +1 -1
  32. package/lib/types/users.d.ts +3 -11
  33. package/lib/types/users.d.ts.map +1 -1
  34. package/lib/types/utils.d.ts +0 -20
  35. package/lib/types/utils.d.ts.map +1 -1
  36. package/lib/types/utils.js +0 -6
  37. package/lib/types/utils.js.map +1 -1
  38. package/lib/types/vehicles.d.ts +92 -406
  39. package/lib/types/vehicles.d.ts.map +1 -1
  40. package/lib/types/vehicles.js +1 -54
  41. package/lib/types/vehicles.js.map +1 -1
  42. package/package.json +6 -8
  43. package/src/constants.ts +1 -930
  44. package/src/types/crm.ts +30 -118
  45. package/src/types/definitions.ts +12 -19
  46. package/src/types/fields.ts +31 -72
  47. package/src/types/interests.ts +24 -0
  48. package/src/types/picklists.ts +7 -26
  49. package/src/types/search.ts +4 -34
  50. package/src/types/storage.ts +12 -1
  51. package/src/types/tenants.ts +11 -37
  52. package/src/types/users.ts +3 -17
  53. package/src/types/utils.ts +0 -25
  54. package/src/types/vehicles.ts +93 -461
  55. package/tsconfig.tsbuildinfo +2995 -1
  56. package/lib/apis/crm.d.ts +0 -39
  57. package/lib/apis/crm.d.ts.map +0 -1
  58. package/lib/apis/crm.js +0 -201
  59. package/lib/apis/crm.js.map +0 -1
  60. package/lib/apis/documents.d.ts +0 -4
  61. package/lib/apis/documents.d.ts.map +0 -1
  62. package/lib/apis/documents.js +0 -47
  63. package/lib/apis/documents.js.map +0 -1
  64. package/lib/apis/internet-vehicles.d.ts +0 -3
  65. package/lib/apis/internet-vehicles.d.ts.map +0 -1
  66. package/lib/apis/internet-vehicles.js +0 -27
  67. package/lib/apis/internet-vehicles.js.map +0 -1
  68. package/lib/apis/leasing-administration.d.ts +0 -8
  69. package/lib/apis/leasing-administration.d.ts.map +0 -1
  70. package/lib/apis/leasing-administration.js +0 -49
  71. package/lib/apis/leasing-administration.js.map +0 -1
  72. package/lib/apis/leasing.d.ts +0 -19
  73. package/lib/apis/leasing.d.ts.map +0 -1
  74. package/lib/apis/leasing.js +0 -168
  75. package/lib/apis/leasing.js.map +0 -1
  76. package/lib/apis/opportunities.d.ts +0 -9
  77. package/lib/apis/opportunities.d.ts.map +0 -1
  78. package/lib/apis/opportunities.js +0 -94
  79. package/lib/apis/opportunities.js.map +0 -1
  80. package/lib/apis/picklists.d.ts +0 -5
  81. package/lib/apis/picklists.d.ts.map +0 -1
  82. package/lib/apis/picklists.js +0 -44
  83. package/lib/apis/picklists.js.map +0 -1
  84. package/lib/apis/tenants.d.ts +0 -7
  85. package/lib/apis/tenants.d.ts.map +0 -1
  86. package/lib/apis/tenants.js +0 -80
  87. package/lib/apis/tenants.js.map +0 -1
  88. package/lib/apis/users.d.ts +0 -3
  89. package/lib/apis/users.d.ts.map +0 -1
  90. package/lib/apis/users.js +0 -26
  91. package/lib/apis/users.js.map +0 -1
  92. package/lib/apis/utils.d.ts +0 -9
  93. package/lib/apis/utils.d.ts.map +0 -1
  94. package/lib/apis/utils.js +0 -23
  95. package/lib/apis/utils.js.map +0 -1
  96. package/lib/apis/vehicles.d.ts +0 -18
  97. package/lib/apis/vehicles.d.ts.map +0 -1
  98. package/lib/apis/vehicles.js +0 -159
  99. package/lib/apis/vehicles.js.map +0 -1
  100. package/lib/ddb-entities.d.ts +0 -2
  101. package/lib/ddb-entities.d.ts.map +0 -1
  102. package/lib/ddb-entities.js +0 -5
  103. package/lib/ddb-entities.js.map +0 -1
  104. package/lib/types/activities.d.ts +0 -38
  105. package/lib/types/activities.d.ts.map +0 -1
  106. package/lib/types/activities.js +0 -16
  107. package/lib/types/activities.js.map +0 -1
  108. package/lib/types/documents.d.ts +0 -105
  109. package/lib/types/documents.d.ts.map +0 -1
  110. package/lib/types/documents.js +0 -3
  111. package/lib/types/documents.js.map +0 -1
  112. package/lib/types/internet-vehicles.d.ts +0 -64
  113. package/lib/types/internet-vehicles.d.ts.map +0 -1
  114. package/lib/types/internet-vehicles.js +0 -3
  115. package/lib/types/internet-vehicles.js.map +0 -1
  116. package/lib/types/leads.d.ts +0 -134
  117. package/lib/types/leads.d.ts.map +0 -1
  118. package/lib/types/leads.js +0 -3
  119. package/lib/types/leads.js.map +0 -1
  120. package/lib/types/leasing-administration.d.ts +0 -107
  121. package/lib/types/leasing-administration.d.ts.map +0 -1
  122. package/lib/types/leasing-administration.js +0 -3
  123. package/lib/types/leasing-administration.js.map +0 -1
  124. package/lib/types/leasing-search.d.ts +0 -22
  125. package/lib/types/leasing-search.d.ts.map +0 -1
  126. package/lib/types/leasing-search.js +0 -3
  127. package/lib/types/leasing-search.js.map +0 -1
  128. package/lib/types/leasing-settings.d.ts +0 -113
  129. package/lib/types/leasing-settings.d.ts.map +0 -1
  130. package/lib/types/leasing-settings.js +0 -10
  131. package/lib/types/leasing-settings.js.map +0 -1
  132. package/lib/types/leasing.d.ts +0 -322
  133. package/lib/types/leasing.d.ts.map +0 -1
  134. package/lib/types/leasing.js +0 -24
  135. package/lib/types/leasing.js.map +0 -1
  136. package/lib/types/machines.d.ts +0 -38
  137. package/lib/types/machines.d.ts.map +0 -1
  138. package/lib/types/machines.js +0 -3
  139. package/lib/types/machines.js.map +0 -1
  140. package/lib/types/opportunities.d.ts +0 -448
  141. package/lib/types/opportunities.d.ts.map +0 -1
  142. package/lib/types/opportunities.js +0 -68
  143. package/lib/types/opportunities.js.map +0 -1
  144. package/lib/types/payments.d.ts +0 -38
  145. package/lib/types/payments.d.ts.map +0 -1
  146. package/lib/types/payments.js +0 -9
  147. package/lib/types/payments.js.map +0 -1
  148. package/lib/types/quotes.d.ts +0 -173
  149. package/lib/types/quotes.d.ts.map +0 -1
  150. package/lib/types/quotes.js +0 -26
  151. package/lib/types/quotes.js.map +0 -1
  152. package/lib/types/recently-viewed.d.ts +0 -33
  153. package/lib/types/recently-viewed.d.ts.map +0 -1
  154. package/lib/types/recently-viewed.js +0 -3
  155. package/lib/types/recently-viewed.js.map +0 -1
  156. package/lib/types/saved-filters.d.ts +0 -20
  157. package/lib/types/saved-filters.d.ts.map +0 -1
  158. package/lib/types/saved-filters.js +0 -3
  159. package/lib/types/saved-filters.js.map +0 -1
  160. package/lib/types/settings.d.ts +0 -50
  161. package/lib/types/settings.d.ts.map +0 -1
  162. package/lib/types/settings.js.map +0 -1
  163. package/lib/types/templates.d.ts +0 -35
  164. package/lib/types/templates.d.ts.map +0 -1
  165. package/lib/types/templates.js +0 -9
  166. package/lib/types/templates.js.map +0 -1
  167. package/lib/types/website.d.ts +0 -24
  168. package/lib/types/website.d.ts.map +0 -1
  169. package/lib/types/website.js +0 -3
  170. package/lib/types/website.js.map +0 -1
  171. package/lib/utils/forms.d.ts +0 -6
  172. package/lib/utils/forms.d.ts.map +0 -1
  173. package/lib/utils/forms.js +0 -33
  174. package/lib/utils/forms.js.map +0 -1
  175. package/lib/utils/leasing.d.ts +0 -3
  176. package/lib/utils/leasing.d.ts.map +0 -1
  177. package/lib/utils/leasing.js +0 -10
  178. package/lib/utils/leasing.js.map +0 -1
  179. package/lib/utils/slug.d.ts +0 -3
  180. package/lib/utils/slug.d.ts.map +0 -1
  181. package/lib/utils/slug.js +0 -23
  182. package/lib/utils/slug.js.map +0 -1
  183. package/lib/utils/tenants.d.ts +0 -4
  184. package/lib/utils/tenants.d.ts.map +0 -1
  185. package/lib/utils/tenants.js +0 -16
  186. package/lib/utils/tenants.js.map +0 -1
  187. package/lib/utils/vehicles.d.ts +0 -12
  188. package/lib/utils/vehicles.d.ts.map +0 -1
  189. package/lib/utils/vehicles.js +0 -73
  190. package/lib/utils/vehicles.js.map +0 -1
  191. package/src/apis/crm.ts +0 -302
  192. package/src/apis/documents.ts +0 -54
  193. package/src/apis/internet-vehicles.ts +0 -23
  194. package/src/apis/leasing-administration.ts +0 -70
  195. package/src/apis/leasing.ts +0 -257
  196. package/src/apis/opportunities.ts +0 -133
  197. package/src/apis/picklists.ts +0 -50
  198. package/src/apis/tenants.ts +0 -100
  199. package/src/apis/users.ts +0 -22
  200. package/src/apis/utils.ts +0 -23
  201. package/src/apis/vehicles.ts +0 -229
  202. package/src/ddb-entities.ts +0 -1
  203. package/src/environment.d.ts +0 -6
  204. package/src/types/activities.ts +0 -41
  205. package/src/types/documents.ts +0 -110
  206. package/src/types/internet-vehicles.ts +0 -67
  207. package/src/types/leads.ts +0 -144
  208. package/src/types/leasing-administration.ts +0 -131
  209. package/src/types/leasing-search.ts +0 -24
  210. package/src/types/leasing-settings.ts +0 -111
  211. package/src/types/leasing.ts +0 -360
  212. package/src/types/machines.ts +0 -40
  213. package/src/types/opportunities.ts +0 -496
  214. package/src/types/payments.ts +0 -40
  215. package/src/types/quotes.ts +0 -186
  216. package/src/types/recently-viewed.ts +0 -45
  217. package/src/types/saved-filters.ts +0 -21
  218. package/src/types/settings.ts +0 -51
  219. package/src/types/templates.ts +0 -40
  220. package/src/types/website.ts +0 -28
  221. package/src/utils/forms.ts +0 -32
  222. package/src/utils/leasing.ts +0 -14
  223. package/src/utils/slug.ts +0 -19
  224. package/src/utils/tenants.ts +0 -14
  225. package/src/utils/vehicles.ts +0 -92
@@ -1,257 +0,0 @@
1
- import {
2
- SERVICE_ID_ADMIN_HEADER,
3
- TENANT_ID_ADMIN_HEADER,
4
- } from '@bisondesk/commons-sdk/lib/constants';
5
- import { XError } from '@bisondesk/commons-sdk/lib/errors';
6
- import fetch, { Response } from 'node-fetch';
7
- import {
8
- AmortizationDocs,
9
- AmortizationTable,
10
- LeasingConditions,
11
- LeasingContract,
12
- NewLeasingConditions,
13
- } from '../types/leasing';
14
- import { cleanHeaders, getAdminAuth } from './utils';
15
-
16
- export const listLeasingClients = async (
17
- tenantId: string,
18
- offset: number,
19
- limit: number,
20
- opts?: { serviceId: string }
21
- ): Promise<string[]> => {
22
- const auth = await getAdminAuth();
23
- const response: Response = await fetch(
24
- `${process.env.CORE_API_ORIGIN}/api/leasing/contracts/clients?offset=${offset}&limit=${limit}`,
25
- {
26
- headers: cleanHeaders({
27
- Authorization: auth,
28
- [TENANT_ID_ADMIN_HEADER]: tenantId,
29
- [SERVICE_ID_ADMIN_HEADER]: opts?.serviceId,
30
- }),
31
- }
32
- );
33
-
34
- if (response.ok) {
35
- return response.status === 200 ? (response.json() as any) : undefined;
36
- }
37
-
38
- const body = await response.text();
39
- throw new XError(response.statusText, { tenantId, offset, limit });
40
- };
41
-
42
- export const getLeasingConditions = async (
43
- tenantId: string,
44
- conditionsId: string
45
- ): Promise<LeasingConditions | undefined> => {
46
- const auth = await getAdminAuth();
47
- const response: Response = await fetch(
48
- `${process.env.CORE_API_ORIGIN}/api/leasing/conditions/${conditionsId}`,
49
- {
50
- headers: {
51
- Authorization: auth,
52
- [TENANT_ID_ADMIN_HEADER]: tenantId,
53
- },
54
- }
55
- );
56
-
57
- if (response.ok) {
58
- return response.status === 200 ? (response.json() as any) : undefined;
59
- }
60
-
61
- const body = await response.text();
62
- throw new XError(response.statusText, { tenantId, conditionsId, body });
63
- };
64
-
65
- export const createLeasingConditions = async (
66
- tenantId: string,
67
- conditions: NewLeasingConditions
68
- ): Promise<LeasingConditions> => {
69
- const auth = await getAdminAuth();
70
- const response: Response = await fetch(`${process.env.CORE_API_ORIGIN}/api/leasing/conditions`, {
71
- method: 'POST',
72
- headers: {
73
- 'Content-Type': 'application/json',
74
- Authorization: auth,
75
- [TENANT_ID_ADMIN_HEADER]: tenantId,
76
- },
77
- body: JSON.stringify(conditions),
78
- });
79
-
80
- if (response.status === 200) {
81
- return response.json() as any;
82
- }
83
-
84
- const body = await response.text();
85
- throw new XError(response.statusText, { tenantId, conditions, body });
86
- };
87
-
88
- export const getLeasingContractByNumber = async (
89
- tenantId: string,
90
- contractNumber: string
91
- ): Promise<LeasingContract | undefined> => {
92
- const auth = await getAdminAuth();
93
- const response: Response = await fetch(
94
- `${process.env.CORE_API_ORIGIN}/api/leasing/contracts/number/${contractNumber}`,
95
- {
96
- headers: {
97
- Authorization: auth,
98
- [TENANT_ID_ADMIN_HEADER]: tenantId,
99
- },
100
- }
101
- );
102
-
103
- if (response.ok) {
104
- return response.status === 200 ? (response.json() as any) : undefined;
105
- }
106
-
107
- const body = await response.text();
108
- throw new XError(response.statusText, { tenantId, contractNumber, body });
109
- };
110
-
111
- export const getLeasingContract = async (
112
- tenantId: string,
113
- contractId: string
114
- ): Promise<LeasingContract | undefined> => {
115
- const auth = await getAdminAuth();
116
- const response: Response = await fetch(
117
- `${process.env.CORE_API_ORIGIN}/api/leasing/contracts/${contractId}`,
118
- {
119
- headers: {
120
- Authorization: auth,
121
- [TENANT_ID_ADMIN_HEADER]: tenantId,
122
- },
123
- }
124
- );
125
-
126
- if (response.ok) {
127
- return response.status === 200 ? (response.json() as any) : undefined;
128
- }
129
-
130
- const body = await response.text();
131
- throw new XError(response.statusText, { tenantId, contractId, body });
132
- };
133
-
134
- export const findLeasingContracts = async (
135
- tenantId: string,
136
- clientId: string,
137
- vehicleId: string
138
- ): Promise<LeasingContract[]> => {
139
- const auth = await getAdminAuth();
140
- const response: Response = await fetch(
141
- `${process.env.CORE_API_ORIGIN}/api/leasing/contracts/find?clientId=${clientId}&vehicleId=${vehicleId}`,
142
- {
143
- headers: {
144
- Authorization: auth,
145
- [TENANT_ID_ADMIN_HEADER]: tenantId,
146
- },
147
- }
148
- );
149
-
150
- if (response.status === 200) {
151
- return response.json() as any;
152
- }
153
-
154
- const body = await response.text();
155
- throw new XError(response.statusText, { tenantId, clientId, vehicleId, body });
156
- };
157
-
158
- export const upsertLeasingContract = async (
159
- tenantId: string,
160
- contract: LeasingContract
161
- ): Promise<LeasingContract> => {
162
- const auth = await getAdminAuth();
163
- const response: Response = await fetch(`${process.env.CORE_API_ORIGIN}/api/leasing/contracts`, {
164
- method: 'POST',
165
- headers: {
166
- 'Content-Type': 'application/json',
167
- Authorization: auth,
168
- [TENANT_ID_ADMIN_HEADER]: tenantId,
169
- },
170
- body: JSON.stringify(contract),
171
- });
172
-
173
- if (response.status === 200) {
174
- return response.json() as any;
175
- }
176
-
177
- const body = await response.text();
178
- throw new XError(response.statusText, { tenantId, contract, body });
179
- };
180
-
181
- export const computeFinanceDocLeasingAmounts = async (
182
- tenantId: string,
183
- contractId: string,
184
- documentId: string
185
- ): Promise<
186
- | {
187
- totalAmountExcl: string;
188
- totalCapital: string;
189
- totalInterest: string;
190
- totalOthers: string;
191
- }
192
- | undefined
193
- > => {
194
- const auth = await getAdminAuth();
195
- const response: Response = await fetch(
196
- `${process.env.CORE_API_ORIGIN}/api/leasing/doc/${documentId}/amounts`,
197
- {
198
- headers: {
199
- Authorization: auth,
200
- [TENANT_ID_ADMIN_HEADER]: tenantId,
201
- },
202
- }
203
- );
204
-
205
- if (response.status === 200) {
206
- return response.json() as any;
207
- }
208
-
209
- const body = await response.text();
210
- throw new XError(response.statusText, { tenantId, contractId, body });
211
- };
212
-
213
- export const getLeasingAmortizations = async (
214
- tenantId: string,
215
- contractId: string
216
- ): Promise<AmortizationTable | undefined> => {
217
- const auth = await getAdminAuth();
218
- const response: Response = await fetch(
219
- `${process.env.CORE_API_ORIGIN}/api/leasing/contracts/${contractId}/amortization`,
220
- {
221
- headers: {
222
- Authorization: auth,
223
- [TENANT_ID_ADMIN_HEADER]: tenantId,
224
- },
225
- }
226
- );
227
-
228
- if (response.status === 200) {
229
- return response.json() as any;
230
- }
231
-
232
- const body = await response.text();
233
- throw new XError(response.statusText, { tenantId, contractId, body });
234
- };
235
-
236
- export const listAmortizationDocsByContract = async (
237
- tenantId: string,
238
- contractId: string
239
- ): Promise<AmortizationDocs[]> => {
240
- const auth = await getAdminAuth();
241
- const response: Response = await fetch(
242
- `${process.env.CORE_API_ORIGIN}/api/leasing/contracts/${contractId}/amortization/docs`,
243
- {
244
- headers: {
245
- Authorization: auth,
246
- [TENANT_ID_ADMIN_HEADER]: tenantId,
247
- },
248
- }
249
- );
250
-
251
- if (response.status === 200) {
252
- return response.json() as any;
253
- }
254
-
255
- const body = await response.text();
256
- throw new XError(response.statusText, { tenantId, contractId, body });
257
- };
@@ -1,133 +0,0 @@
1
- import { TENANT_ID_ADMIN_HEADER } from '@bisondesk/commons-sdk/lib/constants';
2
- import { XError } from '@bisondesk/commons-sdk/lib/errors';
3
- import fetch, { Response } from 'node-fetch';
4
- import { AmortizationTable, AmortizationTableRequest } from '../types/leasing';
5
- import { LeasingQuoteParams } from '../types/leasing-settings';
6
- import {
7
- NewOpportunity,
8
- Opportunity,
9
- OpportunityBFF,
10
- OpportunityUpdate,
11
- } from '../types/opportunities';
12
- import { cleanHeaders, getAdminAuth } from './utils';
13
-
14
- export const getOpportunityBff = async (
15
- tenantId: string,
16
- opportunityId: string
17
- ): Promise<OpportunityBFF | undefined> => {
18
- const auth = await getAdminAuth();
19
- const response: Response = await fetch(
20
- `${process.env.CORE_API_ORIGIN}/api/opportunities/${opportunityId}/bff`,
21
- {
22
- headers: cleanHeaders({
23
- Authorization: auth,
24
- [TENANT_ID_ADMIN_HEADER]: tenantId,
25
- }),
26
- }
27
- );
28
-
29
- if (response.ok) {
30
- return response.status === 200 ? (response.json() as any) : undefined;
31
- }
32
-
33
- const body = await response.text();
34
- throw new XError(response.statusText, { body, tenantId, opportunityId });
35
- };
36
-
37
- export const updateOpportunity = async (
38
- tenantId: string,
39
- opportunity: OpportunityUpdate,
40
- opportunityId: string
41
- ): Promise<OpportunityBFF | undefined> => {
42
- const auth = await getAdminAuth();
43
- const response: Response = await fetch(
44
- `${process.env.CORE_API_ORIGIN}/api/opportunities/${opportunityId}`,
45
- {
46
- method: 'PATCH',
47
- headers: cleanHeaders({
48
- Authorization: auth,
49
- [TENANT_ID_ADMIN_HEADER]: tenantId,
50
- }),
51
- body: JSON.stringify(opportunity),
52
- }
53
- );
54
-
55
- if (response.ok) {
56
- return response.status === 200 ? (response.json() as any) : undefined;
57
- }
58
-
59
- const body = await response.text();
60
- throw new XError(response.statusText, { body, tenantId, opportunityId });
61
- };
62
-
63
- export const createOpportunity = async (
64
- tenantId: string,
65
- opportunity: NewOpportunity
66
- ): Promise<Opportunity> => {
67
- const auth = await getAdminAuth();
68
- const response: Response = await fetch(`${process.env.CORE_API_ORIGIN}/api/opportunities`, {
69
- method: 'POST',
70
- headers: cleanHeaders({
71
- Authorization: auth,
72
- [TENANT_ID_ADMIN_HEADER]: tenantId,
73
- 'Content-Type': 'application/json',
74
- }),
75
- body: JSON.stringify(opportunity),
76
- });
77
-
78
- if (response.ok) {
79
- return response.status === 200 ? (response.json() as any) : undefined;
80
- }
81
-
82
- const body = await response.text();
83
- throw new XError(response.statusText, { body, tenantId, opportunity });
84
- };
85
-
86
- export const getLeasingQuoteParams = async (
87
- tenantId: string,
88
- settingId: string
89
- ): Promise<LeasingQuoteParams | undefined> => {
90
- const auth = await getAdminAuth();
91
- const response: Response = await fetch(
92
- `${process.env.CORE_API_ORIGIN}/api/leasing/administration/settings/quote-params/${settingId}`,
93
- {
94
- headers: cleanHeaders({
95
- Authorization: auth,
96
- [TENANT_ID_ADMIN_HEADER]: tenantId,
97
- }),
98
- }
99
- );
100
-
101
- if (response.ok) {
102
- return response.status === 200 ? (response.json() as any) : undefined;
103
- }
104
-
105
- const body = await response.text();
106
- throw new XError(response.statusText, { body, tenantId, settingId });
107
- };
108
-
109
- export const computeAmortizationTable = async (
110
- tenantId: string,
111
- input: AmortizationTableRequest
112
- ): Promise<AmortizationTable | undefined> => {
113
- const auth = await getAdminAuth();
114
- const response: Response = await fetch(
115
- `${process.env.CORE_API_ORIGIN}/api/leasing/amortization-table`,
116
- {
117
- method: 'POST',
118
- headers: cleanHeaders({
119
- Authorization: auth,
120
- 'Content-Type': 'application/json',
121
- [TENANT_ID_ADMIN_HEADER]: tenantId,
122
- }),
123
- body: JSON.stringify(input),
124
- }
125
- );
126
-
127
- if (response.ok) {
128
- return response.status === 200 ? response.json() : undefined;
129
- }
130
-
131
- const body = await response.text();
132
- throw new XError(response.statusText, { body, tenantId, input });
133
- };
@@ -1,50 +0,0 @@
1
- import { XError } from '@bisondesk/commons-sdk/lib/errors';
2
- import { Option } from '@bisondesk/commons-sdk/lib/types';
3
- import fetch, { Response } from 'node-fetch';
4
- import {
5
- AdHocPicklistRequest,
6
- AdHocPicklistValueDisplay,
7
- PicklistOptionsRequest,
8
- } from '../types/picklists';
9
- import { cleanHeaders, getAdminAuth } from './utils';
10
-
11
- export const getMultiplePicklistValues = async (
12
- request: AdHocPicklistRequest
13
- ): Promise<AdHocPicklistValueDisplay> => {
14
- const auth = await getAdminAuth();
15
- const response: Response = await fetch(`${process.env.CORE_API_ORIGIN}/api/picklists/bulk/read`, {
16
- method: 'POST',
17
- headers: {
18
- Authorization: auth,
19
- 'Content-Type': 'application/json',
20
- },
21
- body: JSON.stringify(request),
22
- });
23
-
24
- if (response.ok) {
25
- return response.json() as any;
26
- }
27
-
28
- const body = await response.text();
29
- throw new XError(response.statusText, { body });
30
- };
31
-
32
- export const getPicklistOptions = async (req: PicklistOptionsRequest): Promise<Option[]> => {
33
- const auth = await getAdminAuth();
34
-
35
- const response: Response = await fetch(`${process.env.CORE_API_ORIGIN}/api/picklists/options`, {
36
- method: 'POST',
37
- headers: cleanHeaders({
38
- Authorization: auth,
39
- 'Content-Type': 'application/json',
40
- }),
41
- body: JSON.stringify(req),
42
- });
43
-
44
- if (response.ok) {
45
- return response.json() as any;
46
- }
47
-
48
- const body = await response.text();
49
- throw new XError(response.statusText, { body, req });
50
- };
@@ -1,100 +0,0 @@
1
- import { XError } from '@bisondesk/commons-sdk/lib/errors';
2
- import fetch, { Response } from 'node-fetch';
3
- import { Tenant, TenantSyncSettings } from '../types/tenants';
4
- import { getAdminAuth } from './utils';
5
-
6
- export const listTenants = async (): Promise<Tenant[]> => {
7
- const auth = await getAdminAuth();
8
- const response: Response = await fetch(`${process.env.CORE_API_ORIGIN}/admin/tenants`, {
9
- headers: {
10
- Authorization: auth,
11
- },
12
- });
13
-
14
- if (response.ok) {
15
- return response.json() as any;
16
- }
17
-
18
- const body = await response.text();
19
- throw new XError(response.statusText, { body });
20
- };
21
-
22
- export const listTenantsSyncSettings = async (): Promise<TenantSyncSettings[]> => {
23
- const auth = await getAdminAuth();
24
- const response: Response = await fetch(
25
- `${process.env.CORE_API_ORIGIN}/admin/tenants/settings/sync`,
26
- {
27
- headers: {
28
- Authorization: auth,
29
- },
30
- }
31
- );
32
-
33
- if (response.ok) {
34
- return response.json() as any;
35
- }
36
-
37
- const body = await response.text();
38
- throw new XError(response.statusText, { body });
39
- };
40
-
41
- export const getTenant = async (tenantId: string): Promise<Tenant | undefined> => {
42
- const auth = await getAdminAuth();
43
- const response: Response = await fetch(
44
- `${process.env.CORE_API_ORIGIN}/admin/tenants/${tenantId}`,
45
- {
46
- headers: {
47
- Authorization: auth,
48
- },
49
- }
50
- );
51
-
52
- if (response.ok) {
53
- return response.status === 200 ? (response.json() as any) : undefined;
54
- }
55
-
56
- const body = await response.text();
57
- throw new XError(response.statusText, { body });
58
- };
59
-
60
- export const getTenantByHyperdmsId = async (
61
- hyperdmsTenantId: string
62
- ): Promise<Tenant | undefined> => {
63
- const auth = await getAdminAuth();
64
- const response: Response = await fetch(
65
- `${process.env.CORE_API_ORIGIN}/admin/tenants/hyperdms/${hyperdmsTenantId}`,
66
- {
67
- headers: {
68
- Authorization: auth,
69
- },
70
- }
71
- );
72
-
73
- if (response.ok) {
74
- return response.status === 200 ? (response.json() as any) : undefined;
75
- }
76
-
77
- const body = await response.text();
78
- throw new XError(response.statusText, { body });
79
- };
80
-
81
- export const getTenantByHyperportalId = async (
82
- hyperportalTenantId: string
83
- ): Promise<Tenant | undefined> => {
84
- const auth = await getAdminAuth();
85
- const response: Response = await fetch(
86
- `${process.env.CORE_API_ORIGIN}/admin/tenants/hyperportal/${hyperportalTenantId}`,
87
- {
88
- headers: {
89
- Authorization: auth,
90
- },
91
- }
92
- );
93
-
94
- if (response.ok) {
95
- return response.status === 200 ? (response.json() as any) : undefined;
96
- }
97
-
98
- const body = await response.text();
99
- throw new XError(response.statusText, { body });
100
- };
package/src/apis/users.ts DELETED
@@ -1,22 +0,0 @@
1
- import { TENANT_ID_ADMIN_HEADER } from '@bisondesk/commons-sdk/lib/constants';
2
- import { XError } from '@bisondesk/commons-sdk/lib/errors';
3
- import fetch, { Response } from 'node-fetch';
4
- import { User } from '../types/users';
5
- import { cleanHeaders, getAdminAuth } from './utils';
6
-
7
- export const getUser = async (tenantId: string, userId: string): Promise<User | undefined> => {
8
- const auth = await getAdminAuth();
9
- const response: Response = await fetch(`${process.env.CORE_API_ORIGIN}/api/users/${userId}`, {
10
- headers: cleanHeaders({
11
- Authorization: auth,
12
- [TENANT_ID_ADMIN_HEADER]: tenantId,
13
- }),
14
- });
15
-
16
- if (response.ok) {
17
- return response.status === 200 ? (response.json() as any) : undefined;
18
- }
19
-
20
- const body = await response.text();
21
- throw new XError(response.statusText, { body, tenantId, userId });
22
- };
package/src/apis/utils.ts DELETED
@@ -1,23 +0,0 @@
1
- import { TENANT_ID_ADMIN_HEADER } from '@bisondesk/commons-sdk/lib/constants';
2
- import { InvalidArgumentsError } from '@bisondesk/commons-sdk/lib/errors';
3
- import type { HeadersInit } from 'node-fetch';
4
-
5
- export const getAdminAuth = async (): Promise<string> => {
6
- if (!process.env.ADMIN_KEY) {
7
- return '';
8
- }
9
-
10
- return `AdminKey ${process.env.ADMIN_KEY}`;
11
- };
12
-
13
- export const getTenantIdHeader = (headers: { [name: string]: unknown }): string => {
14
- const tenantId = headers[TENANT_ID_ADMIN_HEADER];
15
- if (!tenantId || typeof tenantId !== 'string') {
16
- throw new InvalidArgumentsError('Missing or invalid tenantId');
17
- }
18
-
19
- return tenantId;
20
- };
21
-
22
- export const cleanHeaders = (headers: { [key: string]: string | undefined }): HeadersInit =>
23
- Object.entries(headers).filter((h): h is [string, string] => h[1] != null);