@bisondesk/core-sdk 1.0.341 → 1.0.342

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 (55) hide show
  1. package/lib/apis/crm.js.map +1 -1
  2. package/lib/apis/debtors.js.map +1 -1
  3. package/lib/apis/internet-vehicles.js.map +1 -1
  4. package/lib/apis/leasing-administration.js.map +1 -1
  5. package/lib/apis/leasing.js.map +1 -1
  6. package/lib/apis/opportunities.js.map +1 -1
  7. package/lib/apis/tenants.js.map +1 -1
  8. package/lib/apis/users.d.ts +5 -0
  9. package/lib/apis/users.d.ts.map +1 -1
  10. package/lib/apis/users.js +24 -0
  11. package/lib/apis/users.js.map +1 -1
  12. package/lib/apis/vehicles.js.map +1 -1
  13. package/lib/constants.js +6 -6
  14. package/lib/constants.js.map +1 -1
  15. package/lib/types/activities.js +2 -2
  16. package/lib/types/activities.js.map +1 -1
  17. package/lib/types/crm.js +3 -3
  18. package/lib/types/crm.js.map +1 -1
  19. package/lib/types/delivery-settings.js +1 -1
  20. package/lib/types/delivery-settings.js.map +1 -1
  21. package/lib/types/events.js +1 -1
  22. package/lib/types/events.js.map +1 -1
  23. package/lib/types/interests.js +1 -1
  24. package/lib/types/interests.js.map +1 -1
  25. package/lib/types/leasing-settings.js +1 -1
  26. package/lib/types/leasing-settings.js.map +1 -1
  27. package/lib/types/leasing.js +5 -5
  28. package/lib/types/leasing.js.map +1 -1
  29. package/lib/types/opportunities.js +8 -8
  30. package/lib/types/opportunities.js.map +1 -1
  31. package/lib/types/payments.js +1 -1
  32. package/lib/types/payments.js.map +1 -1
  33. package/lib/types/quotes.js +6 -6
  34. package/lib/types/quotes.js.map +1 -1
  35. package/lib/types/reservations.js +1 -1
  36. package/lib/types/reservations.js.map +1 -1
  37. package/lib/types/roi-ratings.js +1 -1
  38. package/lib/types/roi-ratings.js.map +1 -1
  39. package/lib/types/saved-filters.js +1 -1
  40. package/lib/types/saved-filters.js.map +1 -1
  41. package/lib/types/tenants.js +1 -1
  42. package/lib/types/tenants.js.map +1 -1
  43. package/lib/types/vehicles.js +7 -7
  44. package/lib/types/vehicles.js.map +1 -1
  45. package/lib/utils/forms.js.map +1 -1
  46. package/lib/utils/opportunities.js.map +1 -1
  47. package/lib/utils/search.js.map +1 -1
  48. package/lib/utils/tenants.js.map +1 -1
  49. package/lib/utils/vehicles.d.ts +3 -3
  50. package/lib/utils/vehicles.d.ts.map +1 -1
  51. package/lib/utils/vehicles.js.map +1 -1
  52. package/package.json +1 -1
  53. package/src/apis/users.ts +35 -1
  54. package/tsconfig.deploy.tsbuildinfo +1 -1
  55. package/tsconfig.tsbuildinfo +1 -1
package/src/apis/users.ts CHANGED
@@ -1,7 +1,8 @@
1
- import { TENANT_ID_ADMIN_HEADER } from '@bisondesk/commons-sdk/constants';
1
+ import { AppRoles, TENANT_ID_ADMIN_HEADER } from '@bisondesk/commons-sdk/constants';
2
2
  import { XError } from '@bisondesk/commons-sdk/errors';
3
3
  import { cleanHeaders, getAdminAuth } from '@bisondesk/commons-sdk/fetch';
4
4
  import fetch, { Response } from 'node-fetch';
5
+ import { URL } from 'url';
5
6
  import { User } from '../types/users.js';
6
7
 
7
8
  export const getUser = async (tenantId: string, userId: string): Promise<User | undefined> => {
@@ -20,3 +21,36 @@ export const getUser = async (tenantId: string, userId: string): Promise<User |
20
21
  const body = await response.text();
21
22
  throw new XError(response.statusText, { body, tenantId, userId });
22
23
  };
24
+
25
+ export const listUsers = async (
26
+ tenantId: string,
27
+ opts?: { roles?: AppRoles[]; includeInactive?: boolean }
28
+ ): Promise<User[]> => {
29
+ const auth = await getAdminAuth();
30
+
31
+ const url = new URL(`${process.env.CORE_API_ORIGIN}/api/users`);
32
+
33
+ if (opts?.roles) {
34
+ for (const role of opts.roles) {
35
+ url.searchParams.append('roles', role);
36
+ }
37
+ }
38
+
39
+ if (opts?.includeInactive) {
40
+ url.searchParams.append('includeInactive', opts.includeInactive.toString());
41
+ }
42
+
43
+ const response: Response = await fetch(url, {
44
+ headers: cleanHeaders({
45
+ Authorization: auth,
46
+ [TENANT_ID_ADMIN_HEADER]: tenantId,
47
+ }),
48
+ });
49
+
50
+ if (response.ok) {
51
+ return response.status === 200 ? (response.json() as any) : undefined;
52
+ }
53
+
54
+ const body = await response.text();
55
+ throw new XError(response.statusText, { body, tenantId, opts });
56
+ };