@frontegg/rest-api 3.1.74 → 3.1.76-alpha.9502349697

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 (123) hide show
  1. package/BaseApiClient.d.ts +16 -0
  2. package/BaseApiClient.js +39 -0
  3. package/ContextHolder/index.d.ts +108 -27
  4. package/ContextHolder/index.js +155 -50
  5. package/FetchClient.d.ts +42 -0
  6. package/FetchClient.js +308 -0
  7. package/account-settings/index.d.ts +19 -7
  8. package/account-settings/index.js +23 -13
  9. package/applications/index.d.ts +49 -44
  10. package/applications/index.js +51 -37
  11. package/audits/index.d.ts +27 -15
  12. package/audits/index.js +27 -17
  13. package/auth/index.d.ts +817 -768
  14. package/auth/index.js +902 -721
  15. package/auth/secutiry-poilicy/index.d.ts +58 -102
  16. package/auth/secutiry-poilicy/index.js +122 -90
  17. package/auth/utils.d.ts +2 -2
  18. package/auth/utils.js +9 -8
  19. package/connectivity/index.d.ts +126 -27
  20. package/connectivity/index.js +147 -114
  21. package/directory/index.d.ts +31 -22
  22. package/directory/index.js +27 -15
  23. package/entitlements/index.d.ts +14 -8
  24. package/entitlements/index.js +12 -4
  25. package/feature-flags/index.d.ts +8 -2
  26. package/feature-flags/index.js +16 -8
  27. package/groups/index.d.ts +73 -49
  28. package/groups/index.js +64 -45
  29. package/impersonate/index.d.ts +15 -6
  30. package/impersonate/index.js +13 -5
  31. package/index.d.ts +154 -108
  32. package/index.js +109 -78
  33. package/interfaces.d.ts +10 -0
  34. package/metadata/index.d.ts +67 -7
  35. package/metadata/index.js +52 -32
  36. package/node/BaseApiClient.js +49 -0
  37. package/node/ContextHolder/index.js +155 -50
  38. package/node/FetchClient.js +326 -0
  39. package/node/account-settings/index.js +27 -16
  40. package/node/applications/index.js +51 -44
  41. package/node/audits/index.js +31 -20
  42. package/node/auth/index.js +768 -1035
  43. package/node/auth/secutiry-poilicy/index.js +125 -136
  44. package/node/auth/utils.js +9 -7
  45. package/node/connectivity/index.js +148 -187
  46. package/node/directory/index.js +29 -20
  47. package/node/entitlements/index.js +18 -5
  48. package/node/feature-flags/index.js +21 -9
  49. package/node/groups/index.js +65 -63
  50. package/node/impersonate/index.js +18 -5
  51. package/node/index.js +116 -71
  52. package/node/metadata/index.js +61 -52
  53. package/node/notifications/index.js +37 -27
  54. package/node/reports/index.js +78 -70
  55. package/node/roles/index.js +56 -51
  56. package/node/security-center/index.js +21 -9
  57. package/node/sub-tenants/index.js +90 -89
  58. package/node/subscriptions/index.js +69 -107
  59. package/node/subscriptions/invoices.js +25 -17
  60. package/node/subscriptions/managedSubscriptions.js +32 -27
  61. package/node/subscriptions/paymentMethods.js +27 -20
  62. package/node/subscriptions/paymentProviders.js +15 -6
  63. package/node/subscriptions/plans.js +17 -9
  64. package/node/subscriptions/providers/stripe/index.js +26 -21
  65. package/node/subscriptions/subscriptions.js +32 -27
  66. package/node/subscriptions/summaries.js +15 -6
  67. package/node/subscriptions/tenantConfiguration.js +17 -9
  68. package/node/subscriptions/vendorPublicConfigurations.js +15 -6
  69. package/node/teams/index.js +130 -138
  70. package/node/tenants/index.js +65 -60
  71. package/node/user-phone-numbers/index.js +32 -24
  72. package/node/users/index.js +58 -53
  73. package/node/vendor/index.js +17 -6
  74. package/notifications/index.d.ts +22 -16
  75. package/notifications/index.js +33 -22
  76. package/package.json +1 -1
  77. package/reports/index.d.ts +50 -44
  78. package/reports/index.js +75 -62
  79. package/roles/index.d.ts +44 -38
  80. package/roles/index.js +57 -41
  81. package/security-center/index.d.ts +14 -2
  82. package/security-center/index.js +15 -6
  83. package/sub-tenants/index.d.ts +57 -15
  84. package/sub-tenants/index.js +88 -68
  85. package/subscriptions/index.d.ts +56 -11
  86. package/subscriptions/index.js +58 -11
  87. package/subscriptions/invoices.d.ts +16 -13
  88. package/subscriptions/invoices.js +24 -14
  89. package/subscriptions/managedSubscriptions.d.ts +18 -15
  90. package/subscriptions/managedSubscriptions.js +33 -22
  91. package/subscriptions/paymentMethods.d.ts +16 -13
  92. package/subscriptions/paymentMethods.js +26 -17
  93. package/subscriptions/paymentProviders.d.ts +8 -5
  94. package/subscriptions/paymentProviders.js +11 -4
  95. package/subscriptions/plans.d.ts +11 -8
  96. package/subscriptions/plans.js +14 -6
  97. package/subscriptions/providers/stripe/index.d.ts +24 -21
  98. package/subscriptions/providers/stripe/index.js +27 -16
  99. package/subscriptions/subscriptions.d.ts +24 -21
  100. package/subscriptions/subscriptions.js +33 -22
  101. package/subscriptions/summaries.d.ts +7 -4
  102. package/subscriptions/summaries.js +10 -3
  103. package/subscriptions/tenantConfiguration.d.ts +6 -3
  104. package/subscriptions/tenantConfiguration.js +15 -7
  105. package/subscriptions/vendorPublicConfigurations.d.ts +5 -2
  106. package/subscriptions/vendorPublicConfigurations.js +11 -4
  107. package/teams/index.d.ts +35 -131
  108. package/teams/index.js +122 -93
  109. package/tenants/index.d.ts +25 -37
  110. package/tenants/index.js +62 -46
  111. package/tenants/interfaces.d.ts +2 -0
  112. package/user-phone-numbers/index.d.ts +32 -26
  113. package/user-phone-numbers/index.js +32 -19
  114. package/users/index.d.ts +21 -15
  115. package/users/index.js +60 -44
  116. package/vendor/index.d.ts +12 -6
  117. package/vendor/index.js +11 -4
  118. package/fetch.d.ts +0 -24
  119. package/fetch.js +0 -265
  120. package/node/fetch.js +0 -306
  121. package/node/subscriptions/providers/index.js +0 -18
  122. package/subscriptions/providers/index.d.ts +0 -1
  123. package/subscriptions/providers/index.js +0 -1
@@ -3,37 +3,45 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.createPhoneNumber = createPhoneNumber;
7
- exports.deletePhoneNumber = deletePhoneNumber;
8
- exports.getUserPhoneNumbers = getUserPhoneNumbers;
9
- exports.preVerifyPhoneNumber = preVerifyPhoneNumber;
10
- exports.verifyDeletePhoneNumber = verifyDeletePhoneNumber;
11
- exports.verifyPhoneNumber = verifyPhoneNumber;
6
+ exports.default = exports.PhoneNumbersApi = void 0;
12
7
 
13
8
  var _constants = require("../constants");
14
9
 
15
- var _fetch = require("../fetch");
10
+ var _BaseApiClient = require("../BaseApiClient");
16
11
 
17
- async function getUserPhoneNumbers(queryParams) {
18
- return (0, _fetch.Get)(`${_constants.urls.identity.phoneNumbers.v1}`, queryParams);
19
- }
12
+ class PhoneNumbersApi extends _BaseApiClient.BaseApiClient {
13
+ constructor(appName) {
14
+ super(appName);
20
15
 
21
- async function createPhoneNumber(body) {
22
- return (0, _fetch.Post)(`${_constants.urls.identity.phoneNumbers.v1}`, body);
23
- }
16
+ this.getUserPhoneNumbers = async queryParams => {
17
+ return this.get(`${_constants.urls.identity.phoneNumbers.v1}`, queryParams);
18
+ };
24
19
 
25
- async function deletePhoneNumber(phoneId) {
26
- return (0, _fetch.Delete)(`${_constants.urls.identity.phoneNumbers.v1}/${phoneId}`);
27
- }
20
+ this.createPhoneNumber = async body => {
21
+ return this.post(`${_constants.urls.identity.phoneNumbers.v1}`, body);
22
+ };
28
23
 
29
- async function preVerifyPhoneNumber(body) {
30
- return (0, _fetch.Post)(`${_constants.urls.identity.phoneNumbers.v1}/preverify`, body);
31
- }
24
+ this.deletePhoneNumber = async phoneId => {
25
+ return this.delete(`${_constants.urls.identity.phoneNumbers.v1}/${phoneId}`);
26
+ };
27
+
28
+ this.preVerifyPhoneNumber = async body => {
29
+ return this.post(`${_constants.urls.identity.phoneNumbers.v1}/preverify`, body);
30
+ };
31
+
32
+ this.verifyPhoneNumber = async body => {
33
+ return this.post(`${_constants.urls.identity.phoneNumbers.v1}/verify`, body);
34
+ };
35
+
36
+ this.verifyDeletePhoneNumber = async (phoneId, body) => {
37
+ return this.post(`${_constants.urls.identity.phoneNumbers.v1}/${phoneId}/delete/verify`, body);
38
+ };
39
+ }
32
40
 
33
- async function verifyPhoneNumber(body) {
34
- return (0, _fetch.Post)(`${_constants.urls.identity.phoneNumbers.v1}/verify`, body);
35
41
  }
36
42
 
37
- async function verifyDeletePhoneNumber(phoneId, body) {
38
- return (0, _fetch.Post)(`${_constants.urls.identity.phoneNumbers.v1}/${phoneId}/delete/verify`, body);
39
- }
43
+ exports.PhoneNumbersApi = PhoneNumbersApi;
44
+
45
+ var _default = new PhoneNumbersApi('default');
46
+
47
+ exports.default = _default;
@@ -5,70 +5,75 @@ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefau
5
5
  Object.defineProperty(exports, "__esModule", {
6
6
  value: true
7
7
  });
8
- exports.GetUserJwt = GetUserJwt;
9
- exports.getCurrentUserTenantsV1 = getCurrentUserTenantsV1;
10
- exports.getCurrentUserTenantsV3 = getCurrentUserTenantsV3;
11
- exports.getUsersGroups = getUsersGroups;
12
- exports.getUsersRoles = getUsersRoles;
13
- exports.getUsersV2 = getUsersV2;
14
- exports.getUsersV3 = getUsersV3;
15
- exports.sendResetBreachedPasswordEmails = sendResetBreachedPasswordEmails;
16
- exports.updateUserProfileV2 = updateUserProfileV2;
8
+ exports.default = exports.UsersApi = void 0;
17
9
 
18
10
  var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
19
11
 
20
- var _fetch = require("../fetch");
21
-
22
12
  var _constants = require("../constants");
23
13
 
24
- async function GetUserJwt(body) {
25
- return (0, _fetch.Post)(`${_constants.urls.identity.users.v3}/me/token`, body);
26
- }
14
+ var _BaseApiClient = require("../BaseApiClient");
27
15
 
28
- async function getUsersV2(queryParams, options) {
29
- return (0, _fetch.Get)(_constants.urls.identity.users.v2, queryParams, {
30
- headers: (0, _fetch.extractHeadersFromOptions)(options)
31
- });
32
- }
16
+ class UsersApi extends _BaseApiClient.BaseApiClient {
17
+ constructor(appName) {
18
+ super(appName);
33
19
 
34
- async function getUsersV3(queryParams, options) {
35
- return (0, _fetch.Get)(_constants.urls.identity.users.v3, queryParams, {
36
- headers: (0, _fetch.extractHeadersFromOptions)(options)
37
- });
38
- }
20
+ this.GetUserJwt = async body => {
21
+ return this.post(`${_constants.urls.identity.users.v3}/me/token`, body);
22
+ };
39
23
 
40
- async function getUsersRoles(queryParams, options) {
41
- return (0, _fetch.Get)(_constants.urls.identity.users.roles.v3, (0, _extends2.default)({}, queryParams, {
42
- ids: queryParams.ids.join(',')
43
- }), {
44
- headers: (0, _fetch.extractHeadersFromOptions)(options)
45
- });
46
- }
24
+ this.getUsersV2 = async (queryParams, options) => {
25
+ return this.get(_constants.urls.identity.users.v2, queryParams, {
26
+ headers: this.extractHeadersFromOptions(options)
27
+ });
28
+ };
47
29
 
48
- async function getUsersGroups(queryParams, options) {
49
- return (0, _fetch.Get)(_constants.urls.identity.users.groups.v3, (0, _extends2.default)({}, queryParams, {
50
- ids: queryParams.ids.join(",")
51
- }), {
52
- headers: (0, _fetch.extractHeadersFromOptions)(options)
53
- });
54
- }
30
+ this.getUsersV3 = async (queryParams, options) => {
31
+ return this.get(_constants.urls.identity.users.v3, queryParams, {
32
+ headers: this.extractHeadersFromOptions(options)
33
+ });
34
+ };
55
35
 
56
- async function getCurrentUserTenantsV3(options) {
57
- return (0, _fetch.Get)(_constants.urls.identity.users.tenants.me.v3, undefined, {
58
- headers: (0, _fetch.extractHeadersFromOptions)(options)
59
- });
60
- }
36
+ this.getUsersRoles = async (queryParams, options) => {
37
+ return this.get(_constants.urls.identity.users.roles.v3, (0, _extends2.default)({}, queryParams, {
38
+ ids: queryParams.ids.join(',')
39
+ }), {
40
+ headers: this.extractHeadersFromOptions(options)
41
+ });
42
+ };
61
43
 
62
- async function getCurrentUserTenantsV1(options) {
63
- return (0, _fetch.Get)(_constants.urls.identity.users.tenants.me.v1, undefined, {
64
- headers: (0, _fetch.extractHeadersFromOptions)(options)
65
- });
66
- }
44
+ this.getUsersGroups = async (queryParams, options) => {
45
+ return this.get(_constants.urls.identity.users.groups.v3, (0, _extends2.default)({}, queryParams, {
46
+ ids: queryParams.ids.join(',')
47
+ }), {
48
+ headers: this.extractHeadersFromOptions(options)
49
+ });
50
+ };
51
+
52
+ this.getCurrentUserTenantsV3 = async options => {
53
+ return this.get(_constants.urls.identity.users.tenants.me.v3, undefined, {
54
+ headers: this.extractHeadersFromOptions(options)
55
+ });
56
+ };
57
+
58
+ this.getCurrentUserTenantsV1 = async options => {
59
+ return this.get(_constants.urls.identity.users.tenants.me.v1, undefined, {
60
+ headers: this.extractHeadersFromOptions(options)
61
+ });
62
+ };
63
+
64
+ this.sendResetBreachedPasswordEmails = async () => {
65
+ return this.post(_constants.urls.identity.users.passwords.resetBreachedPasswords.v1);
66
+ };
67
+
68
+ this.updateUserProfileV2 = async body => {
69
+ return this.put(`${_constants.urls.identity.users.v2}/me`, body);
70
+ };
71
+ }
67
72
 
68
- async function sendResetBreachedPasswordEmails() {
69
- return (0, _fetch.Post)(_constants.urls.identity.users.passwords.resetBreachedPasswords.v1);
70
73
  }
71
74
 
72
- async function updateUserProfileV2(body) {
73
- return (0, _fetch.Put)(`${_constants.urls.identity.users.v2}/me`, body);
74
- }
75
+ exports.UsersApi = UsersApi;
76
+
77
+ var _default = new UsersApi('default');
78
+
79
+ exports.default = _default;
@@ -3,14 +3,25 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.getVendorPublicInfo = getVendorPublicInfo;
7
-
8
- var _fetch = require("../fetch");
6
+ exports.default = exports.VendorApi = void 0;
9
7
 
10
8
  var _constants = require("../constants");
11
9
 
12
- async function getVendorPublicInfo() {
13
- return (0, _fetch.Get)(`${_constants.urls.vendor}/public`);
10
+ var _BaseApiClient = require("../BaseApiClient");
11
+
12
+ class VendorApi extends _BaseApiClient.BaseApiClient {
13
+ constructor(appName) {
14
+ super(appName);
15
+
16
+ this.getVendorPublicInfo = async () => {
17
+ return this.get(`${_constants.urls.vendor}/public`);
18
+ };
19
+ }
20
+
14
21
  }
15
22
 
16
- ;
23
+ exports.VendorApi = VendorApi;
24
+
25
+ var _default = new VendorApi('default');
26
+
27
+ exports.default = _default;
@@ -1,17 +1,23 @@
1
1
  import { ILoadMessages, IMessage, IUpdateNotificationStatus, IUpdateNotificationIsPinned } from './interfaces';
2
- /**
3
- * get Notifications
4
- */
5
- export declare function getNotifications(params: ILoadMessages): Promise<Array<IMessage>>;
6
- /**
7
- * update Notification status
8
- */
9
- export declare function updateNotificationStatus(params: IUpdateNotificationStatus): Promise<void>;
10
- /**
11
- * update Notification pin status
12
- */
13
- export declare function updateNotificationIsPinned(params: IUpdateNotificationIsPinned): Promise<any>;
14
- /**
15
- * mark all notifications as read
16
- */
17
- export declare function markAllAsRead(): Promise<void>;
2
+ import { BaseApiClient } from '../BaseApiClient';
3
+ export declare class NotificationsApi extends BaseApiClient {
4
+ constructor(appName: string);
5
+ /**
6
+ * Get notifications
7
+ */
8
+ getNotifications: (params: ILoadMessages) => Promise<Array<IMessage>>;
9
+ /**
10
+ * Update notification status
11
+ */
12
+ updateNotificationStatus: (params: IUpdateNotificationStatus) => Promise<void>;
13
+ /**
14
+ * Update notification pin status
15
+ */
16
+ updateNotificationIsPinned: (params: IUpdateNotificationIsPinned) => Promise<any>;
17
+ /**
18
+ * Mark all notifications as read
19
+ */
20
+ markAllAsRead: () => Promise<void>;
21
+ }
22
+ declare const _default: NotificationsApi;
23
+ export default _default;
@@ -1,24 +1,35 @@
1
- import { Get, Post, Put } from '../fetch';
2
1
  import { urls } from '../constants';
3
- export async function getNotifications(params) {
4
- return Get(urls.notifications.v1, {
5
- params
6
- });
2
+ import { BaseApiClient } from '../BaseApiClient';
3
+ export class NotificationsApi extends BaseApiClient {
4
+ constructor(appName) {
5
+ super(appName);
6
+
7
+ this.getNotifications = async params => {
8
+ return this.get(urls.notifications.v1, {
9
+ params
10
+ });
11
+ };
12
+
13
+ this.updateNotificationStatus = async params => {
14
+ return this.put(`${urls.notifications.v1}/status`, {
15
+ params
16
+ });
17
+ };
18
+
19
+ this.updateNotificationIsPinned = async params => {
20
+ const {
21
+ notificationId,
22
+ pinStatus
23
+ } = params;
24
+ return this.put(`${urls.notifications.v1}/${pinStatus}`, {
25
+ notificationId
26
+ });
27
+ };
28
+
29
+ this.markAllAsRead = async () => {
30
+ return this.post(`${urls.notifications.v1}/status/mark-all-read`);
31
+ };
32
+ }
33
+
7
34
  }
8
- export async function updateNotificationStatus(params) {
9
- return Put(`${urls.notifications.v1}/status`, {
10
- params
11
- });
12
- }
13
- export async function updateNotificationIsPinned(params) {
14
- const {
15
- notificationId,
16
- pinStatus
17
- } = params;
18
- return Put(`${urls.notifications.v1}/${pinStatus}`, {
19
- notificationId
20
- });
21
- }
22
- export async function markAllAsRead() {
23
- return Post(`${urls.notifications.v1}/status/mark-all-read`);
24
- }
35
+ export default new NotificationsApi('default');
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@frontegg/rest-api",
3
- "version": "3.1.74",
3
+ "version": "3.1.76-alpha.9502349697",
4
4
  "main": "./node/index.js",
5
5
  "license": "MIT",
6
6
  "dependencies": {
@@ -1,45 +1,51 @@
1
1
  import { IDownloadReport, IGetReport, IGetReports, IRenderReport, IRenderReportResponse, IReportRecord, IScheduleReport, ISendReport } from './interfaces';
2
- /**
3
- * Get all active tenant reports from reports service by active vendor.
4
- * Optional: pass filters and sort options to reports.
5
- *
6
- * @returns list of reports objects
7
- */
8
- export declare function getReports(body: IGetReports): Promise<IReportRecord[]>;
9
- /**
10
- * Get report record by id.
11
- *
12
- * @returns list of report object
13
- * @throws exception if report not found.
14
- */
15
- export declare function getReport(body: IGetReport): Promise<IReportRecord>;
16
- /**
17
- * Render report by id.
18
- * Optional: pass data filters if exists to render report by specific data.
19
- *
20
- * @returns html content of the rendered reports
21
- * @throws exception if report not found or the data api unreached.
22
- */
23
- export declare function renderReport({ dataFilters, ...body }: IRenderReport): Promise<IRenderReportResponse>;
24
- /**
25
- * schedule report by providing cron expression and data filters.
26
- *
27
- * @returns the updated report object
28
- * @throws exception if report not found or the data api unreached.
29
- */
30
- export declare function scheduleReport({ templateId, dataFilters, ...body }: IScheduleReport): Promise<IReportRecord>;
31
- /**
32
- * download report as file in specific format.
33
- * this function will add a href element with url to trigger file download.
34
- * Optional: pass data filters if exists to generate report by specific data.
35
- *
36
- * @throws exception if report not found or the data api unreached.
37
- */
38
- export declare function downloadReport({ dataFilters, ...body }: IDownloadReport): Promise<void>;
39
- /**
40
- * send report to specific email address.
41
- * Optional: pass data filters if exists to send report by specific data.
42
- *
43
- * @throws exception if report not found or the data api unreached.
44
- */
45
- export declare function sendReport(body: ISendReport): Promise<void>;
2
+ import { BaseApiClient } from '../BaseApiClient';
3
+ export declare class ReportsApi extends BaseApiClient {
4
+ constructor(appName: string);
5
+ /**
6
+ * Get all active tenant reports from reports service by active vendor.
7
+ * Optional: pass filters and sort options to reports.
8
+ *
9
+ * @returns list of reports objects
10
+ */
11
+ getReports: (body: IGetReports) => Promise<IReportRecord[]>;
12
+ /**
13
+ * Get report record by id.
14
+ *
15
+ * @returns list of report object
16
+ * @throws exception if report not found.
17
+ */
18
+ getReport: (body: IGetReport) => Promise<IReportRecord>;
19
+ /**
20
+ * Render report by id.
21
+ * Optional: pass data filters if exists to render report by specific data.
22
+ *
23
+ * @returns html content of the rendered reports
24
+ * @throws exception if report not found or the data api unreached.
25
+ */
26
+ renderReport: ({ dataFilters, ...body }: IRenderReport) => Promise<IRenderReportResponse>;
27
+ /**
28
+ * Schedule report by providing cron expression and data filters.
29
+ *
30
+ * @returns the updated report object
31
+ * @throws exception if report not found or the data api unreached.
32
+ */
33
+ scheduleReport: ({ templateId, dataFilters, ...body }: IScheduleReport) => Promise<IReportRecord>;
34
+ /**
35
+ * Download report as file in specific format.
36
+ * This function will add a href element with url to trigger file download.
37
+ * Optional: pass data filters if exists to generate report by specific data.
38
+ *
39
+ * @throws exception if report not found or the data api unreached.
40
+ */
41
+ downloadReport: ({ dataFilters, ...body }: IDownloadReport) => Promise<void>;
42
+ /**
43
+ * Send report to specific email address.
44
+ * Optional: pass data filters if exists to send report by specific data.
45
+ *
46
+ * @throws exception if report not found or the data api unreached.
47
+ */
48
+ sendReport: (body: ISendReport) => Promise<void>;
49
+ }
50
+ declare const _default: ReportsApi;
51
+ export default _default;
package/reports/index.js CHANGED
@@ -3,73 +3,86 @@ import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWith
3
3
  const _excluded = ["dataFilters"],
4
4
  _excluded2 = ["templateId", "dataFilters"],
5
5
  _excluded3 = ["dataFilters"];
6
- import { Get, Post } from '../fetch';
7
6
  import { urls } from '../constants';
8
- export async function getReports(body) {
9
- return Get(`${urls.reports.service.v2}/tenant-reports`, body);
10
- }
11
- export async function getReport(body) {
12
- return Get(`${urls.reports.service.v2}/${body.id}/tenant-reports`);
13
- }
14
- export async function renderReport(_ref) {
15
- let {
16
- dataFilters
17
- } = _ref,
18
- body = _objectWithoutPropertiesLoose(_ref, _excluded);
7
+ import { BaseApiClient } from '../BaseApiClient';
8
+ export class ReportsApi extends BaseApiClient {
9
+ constructor(appName) {
10
+ super(appName);
19
11
 
20
- const html = await Get(`${urls.reports.trigger.v1}/preview-report`, _extends({}, body, {
21
- dataFilters: btoa(JSON.stringify(dataFilters || {})),
22
- responseType: 'html'
23
- }), {
24
- responseType: 'plain'
25
- });
26
- return {
27
- html
28
- };
29
- }
30
- export async function scheduleReport(_ref2) {
31
- let {
32
- templateId,
33
- dataFilters
34
- } = _ref2,
35
- body = _objectWithoutPropertiesLoose(_ref2, _excluded2);
12
+ this.getReports = async body => {
13
+ return this.get(`${urls.reports.service.v2}/tenant-reports`, body);
14
+ };
36
15
 
37
- return Post(`${urls.reports.service.v2}/${templateId}/tenant-reports`, _extends({}, body, {
38
- dataFilters: btoa(JSON.stringify(dataFilters || {}))
39
- }));
40
- }
41
- export async function downloadReport(_ref3) {
42
- let {
43
- dataFilters
44
- } = _ref3,
45
- body = _objectWithoutPropertiesLoose(_ref3, _excluded3);
16
+ this.getReport = async body => {
17
+ return this.get(`${urls.reports.service.v2}/${body.id}/tenant-reports`);
18
+ };
19
+
20
+ this.renderReport = async _ref => {
21
+ let {
22
+ dataFilters
23
+ } = _ref,
24
+ body = _objectWithoutPropertiesLoose(_ref, _excluded);
25
+
26
+ const html = await this.get(`${urls.reports.trigger.v1}/preview-report`, _extends({}, body, {
27
+ dataFilters: btoa(JSON.stringify(dataFilters || {})),
28
+ responseType: 'html'
29
+ }), {
30
+ responseType: 'plain'
31
+ });
32
+ return {
33
+ html
34
+ };
35
+ };
36
+
37
+ this.scheduleReport = async _ref2 => {
38
+ let {
39
+ templateId,
40
+ dataFilters
41
+ } = _ref2,
42
+ body = _objectWithoutPropertiesLoose(_ref2, _excluded2);
43
+
44
+ return this.post(`${urls.reports.service.v2}/${templateId}/tenant-reports`, _extends({}, body, {
45
+ dataFilters: btoa(JSON.stringify(dataFilters || {}))
46
+ }));
47
+ };
48
+
49
+ this.downloadReport = async _ref3 => {
50
+ let {
51
+ dataFilters
52
+ } = _ref3,
53
+ body = _objectWithoutPropertiesLoose(_ref3, _excluded3);
54
+
55
+ const blob = await this.get(`${urls.reports.trigger.v1}/preview-report`, _extends({}, body, {
56
+ dataFilters: btoa(JSON.stringify(dataFilters || {}))
57
+ }), {
58
+ responseType: 'blob'
59
+ });
60
+ let contentType = 'text/html';
61
+ let contentExt = 'html';
62
+
63
+ if (body.responseType === 'pdf') {
64
+ contentType = 'application/pdf';
65
+ contentExt = 'pdf';
66
+ } else if (body.responseType === 'image') {
67
+ contentType = 'image/jpeg';
68
+ contentExt = 'jpg';
69
+ }
46
70
 
47
- const blob = await Get(`${urls.reports.trigger.v1}/preview-report`, _extends({}, body, {
48
- dataFilters: btoa(JSON.stringify(dataFilters || {}))
49
- }), {
50
- responseType: 'blob'
51
- });
52
- let contentType = 'text/html';
53
- let contentExt = 'html';
71
+ const newBlob = new Blob([blob], {
72
+ type: contentType
73
+ });
74
+ const fileURL = URL.createObjectURL(newBlob);
75
+ const tempLink = document.createElement('a');
76
+ tempLink.href = fileURL;
77
+ tempLink.setAttribute('download', `report_${body.name || ''}.${contentExt}`);
78
+ tempLink.click();
79
+ setTimeout(tempLink.remove.bind(tempLink));
80
+ };
54
81
 
55
- if (body.responseType === 'pdf') {
56
- contentType = 'application/pdf';
57
- contentExt = 'pdf';
58
- } else if (body.responseType === 'image') {
59
- contentType = 'image/jpeg';
60
- contentExt = 'jpg';
82
+ this.sendReport = async body => {
83
+ return this.post(`${urls.reports.trigger.v1}/tenant-reports`, body);
84
+ };
61
85
  }
62
86
 
63
- const newBlob = new Blob([blob], {
64
- type: contentType
65
- });
66
- const fileURL = URL.createObjectURL(newBlob);
67
- const tempLink = document.createElement('a');
68
- tempLink.href = fileURL;
69
- tempLink.setAttribute('download', `report_${body.name || ''}.${contentExt}`);
70
- tempLink.click();
71
- setTimeout(tempLink.remove.bind(tempLink));
72
87
  }
73
- export async function sendReport(body) {
74
- return Post(`${urls.reports.trigger.v1}/tenant-reports`, body);
75
- }
88
+ export default new ReportsApi('default');