@frontegg/rest-api 3.1.73 → 3.1.74-alpha.9436511986

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 (125) hide show
  1. package/BaseApiClient.d.ts +16 -0
  2. package/BaseApiClient.js +39 -0
  3. package/ContextHolder/index.d.ts +81 -24
  4. package/ContextHolder/index.js +55 -43
  5. package/FetchClient.d.ts +35 -0
  6. package/FetchClient.js +286 -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 +764 -768
  14. package/auth/index.js +875 -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 +10 -9
  19. package/connectivity/index.d.ts +125 -26
  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 +174 -108
  32. package/index.js +108 -79
  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 +59 -44
  38. package/node/FetchClient.js +311 -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 +746 -1036
  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 +127 -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 +83 -73
  58. package/node/sub-tenants/interfaces.js +10 -1
  59. package/node/subscriptions/index.js +79 -107
  60. package/node/subscriptions/invoices.js +25 -17
  61. package/node/subscriptions/managedSubscriptions.js +32 -27
  62. package/node/subscriptions/paymentMethods.js +27 -20
  63. package/node/subscriptions/paymentProviders.js +15 -6
  64. package/node/subscriptions/plans.js +17 -9
  65. package/node/subscriptions/providers/stripe/index.js +26 -21
  66. package/node/subscriptions/subscriptions.js +32 -27
  67. package/node/subscriptions/summaries.js +15 -6
  68. package/node/subscriptions/tenantConfiguration.js +17 -9
  69. package/node/subscriptions/vendorPublicConfigurations.js +15 -6
  70. package/node/teams/index.js +130 -138
  71. package/node/tenants/index.js +65 -60
  72. package/node/user-phone-numbers/index.js +32 -24
  73. package/node/users/index.js +58 -53
  74. package/node/vendor/index.js +17 -6
  75. package/notifications/index.d.ts +22 -16
  76. package/notifications/index.js +33 -22
  77. package/package.json +1 -1
  78. package/reports/index.d.ts +50 -44
  79. package/reports/index.js +75 -62
  80. package/roles/index.d.ts +44 -38
  81. package/roles/index.js +57 -41
  82. package/security-center/index.d.ts +14 -2
  83. package/security-center/index.js +15 -6
  84. package/sub-tenants/index.d.ts +57 -14
  85. package/sub-tenants/index.js +88 -61
  86. package/sub-tenants/interfaces.d.ts +8 -0
  87. package/sub-tenants/interfaces.js +7 -1
  88. package/subscriptions/index.d.ts +56 -11
  89. package/subscriptions/index.js +68 -11
  90. package/subscriptions/invoices.d.ts +16 -13
  91. package/subscriptions/invoices.js +24 -14
  92. package/subscriptions/managedSubscriptions.d.ts +18 -15
  93. package/subscriptions/managedSubscriptions.js +33 -22
  94. package/subscriptions/paymentMethods.d.ts +16 -13
  95. package/subscriptions/paymentMethods.js +26 -17
  96. package/subscriptions/paymentProviders.d.ts +8 -5
  97. package/subscriptions/paymentProviders.js +11 -4
  98. package/subscriptions/plans.d.ts +11 -8
  99. package/subscriptions/plans.js +14 -6
  100. package/subscriptions/providers/stripe/index.d.ts +24 -21
  101. package/subscriptions/providers/stripe/index.js +27 -16
  102. package/subscriptions/subscriptions.d.ts +24 -21
  103. package/subscriptions/subscriptions.js +33 -22
  104. package/subscriptions/summaries.d.ts +7 -4
  105. package/subscriptions/summaries.js +10 -3
  106. package/subscriptions/tenantConfiguration.d.ts +6 -3
  107. package/subscriptions/tenantConfiguration.js +15 -7
  108. package/subscriptions/vendorPublicConfigurations.d.ts +5 -2
  109. package/subscriptions/vendorPublicConfigurations.js +11 -4
  110. package/teams/index.d.ts +35 -131
  111. package/teams/index.js +122 -93
  112. package/tenants/index.d.ts +25 -37
  113. package/tenants/index.js +63 -47
  114. package/user-phone-numbers/index.d.ts +32 -26
  115. package/user-phone-numbers/index.js +32 -19
  116. package/users/index.d.ts +21 -15
  117. package/users/index.js +60 -44
  118. package/vendor/index.d.ts +12 -6
  119. package/vendor/index.js +11 -4
  120. package/fetch.d.ts +0 -24
  121. package/fetch.js +0 -265
  122. package/node/fetch.js +0 -306
  123. package/node/subscriptions/providers/index.js +0 -18
  124. package/subscriptions/providers/index.d.ts +0 -1
  125. package/subscriptions/providers/index.js +0 -1
@@ -1,20 +1,33 @@
1
- import { urls } from "../constants";
2
- import { Delete, Get, Post } from "../fetch";
3
- export async function getUserPhoneNumbers(queryParams) {
4
- return Get(`${urls.identity.phoneNumbers.v1}`, queryParams);
1
+ import { urls } from '../constants';
2
+ import { BaseApiClient } from '../BaseApiClient';
3
+ export class PhoneNumbersApi extends BaseApiClient {
4
+ constructor(appName) {
5
+ super(appName);
6
+
7
+ this.getUserPhoneNumbers = async queryParams => {
8
+ return this.get(`${urls.identity.phoneNumbers.v1}`, queryParams);
9
+ };
10
+
11
+ this.createPhoneNumber = async body => {
12
+ return this.post(`${urls.identity.phoneNumbers.v1}`, body);
13
+ };
14
+
15
+ this.deletePhoneNumber = async phoneId => {
16
+ return this.delete(`${urls.identity.phoneNumbers.v1}/${phoneId}`);
17
+ };
18
+
19
+ this.preVerifyPhoneNumber = async body => {
20
+ return this.post(`${urls.identity.phoneNumbers.v1}/preverify`, body);
21
+ };
22
+
23
+ this.verifyPhoneNumber = async body => {
24
+ return this.post(`${urls.identity.phoneNumbers.v1}/verify`, body);
25
+ };
26
+
27
+ this.verifyDeletePhoneNumber = async (phoneId, body) => {
28
+ return this.post(`${urls.identity.phoneNumbers.v1}/${phoneId}/delete/verify`, body);
29
+ };
30
+ }
31
+
5
32
  }
6
- export async function createPhoneNumber(body) {
7
- return Post(`${urls.identity.phoneNumbers.v1}`, body);
8
- }
9
- export async function deletePhoneNumber(phoneId) {
10
- return Delete(`${urls.identity.phoneNumbers.v1}/${phoneId}`);
11
- }
12
- export async function preVerifyPhoneNumber(body) {
13
- return Post(`${urls.identity.phoneNumbers.v1}/preverify`, body);
14
- }
15
- export async function verifyPhoneNumber(body) {
16
- return Post(`${urls.identity.phoneNumbers.v1}/verify`, body);
17
- }
18
- export async function verifyDeletePhoneNumber(phoneId, body) {
19
- return Post(`${urls.identity.phoneNumbers.v1}/${phoneId}/delete/verify`, body);
20
- }
33
+ export default new PhoneNumbersApi('default');
package/users/index.d.ts CHANGED
@@ -1,17 +1,23 @@
1
1
  import { GetCurrentUserTenantsResponse, GetUserGroupsParams, GetUserGroupsResponse, GetUserJwtRequestDto, GetUserJwtResponseDto, GetUserRolesResponse, GetUsersRolesParams, IGetUsersV2Response, ISearchUserQueryParamsV2, ISearchUserQueryParamsV3, IUpdateUserDto, IUserProfile, IUsersV3Data } from './interfaces';
2
2
  import { FronteggPaginationWrapper, UserJwtOptions } from '../interfaces';
3
- export declare function GetUserJwt(body: GetUserJwtRequestDto): Promise<GetUserJwtResponseDto>;
4
- export declare function getUsersV2(queryParams: ISearchUserQueryParamsV2, options?: UserJwtOptions): Promise<FronteggPaginationWrapper<IGetUsersV2Response>>;
5
- export declare function getUsersV3(queryParams: ISearchUserQueryParamsV3, options?: UserJwtOptions): Promise<FronteggPaginationWrapper<IUsersV3Data>>;
6
- export declare function getUsersRoles(queryParams: GetUsersRolesParams, options?: UserJwtOptions): Promise<GetUserRolesResponse[]>;
7
- export declare function getUsersGroups(queryParams: GetUserGroupsParams, options?: UserJwtOptions): Promise<GetUserGroupsResponse[]>;
8
- /**
9
- * get user tenant and user tenants by user active tenant
10
- */
11
- export declare function getCurrentUserTenantsV3(options?: UserJwtOptions): Promise<GetCurrentUserTenantsResponse>;
12
- /**
13
- * get user tenant and user tenants by context tenant
14
- */
15
- export declare function getCurrentUserTenantsV1(options?: UserJwtOptions): Promise<GetCurrentUserTenantsResponse>;
16
- export declare function sendResetBreachedPasswordEmails(): Promise<void>;
17
- export declare function updateUserProfileV2(body: Partial<IUpdateUserDto>): Promise<IUserProfile>;
3
+ import { BaseApiClient } from '../BaseApiClient';
4
+ export declare class UsersApi extends BaseApiClient {
5
+ constructor(appName: string);
6
+ GetUserJwt: (body: GetUserJwtRequestDto) => Promise<GetUserJwtResponseDto>;
7
+ getUsersV2: (queryParams: ISearchUserQueryParamsV2, options?: UserJwtOptions | undefined) => Promise<FronteggPaginationWrapper<IGetUsersV2Response>>;
8
+ getUsersV3: (queryParams: ISearchUserQueryParamsV3, options?: UserJwtOptions | undefined) => Promise<FronteggPaginationWrapper<IUsersV3Data>>;
9
+ getUsersRoles: (queryParams: GetUsersRolesParams, options?: UserJwtOptions | undefined) => Promise<GetUserRolesResponse[]>;
10
+ getUsersGroups: (queryParams: GetUserGroupsParams, options?: UserJwtOptions | undefined) => Promise<GetUserGroupsResponse[]>;
11
+ /**
12
+ * get user tenant and user tenants by user active tenant
13
+ */
14
+ getCurrentUserTenantsV3: (options?: UserJwtOptions | undefined) => Promise<GetCurrentUserTenantsResponse>;
15
+ /**
16
+ * get user tenant and user tenants by context tenant
17
+ */
18
+ getCurrentUserTenantsV1: (options?: UserJwtOptions | undefined) => Promise<GetCurrentUserTenantsResponse>;
19
+ sendResetBreachedPasswordEmails: () => Promise<void>;
20
+ updateUserProfileV2: (body: Partial<IUpdateUserDto>) => Promise<IUserProfile>;
21
+ }
22
+ declare const _default: UsersApi;
23
+ export default _default;
package/users/index.js CHANGED
@@ -1,46 +1,62 @@
1
1
  import _extends from "@babel/runtime/helpers/esm/extends";
2
- import { extractHeadersFromOptions, Get, Post, Put } from '../fetch';
3
2
  import { urls } from '../constants';
4
- export async function GetUserJwt(body) {
5
- return Post(`${urls.identity.users.v3}/me/token`, body);
6
- }
7
- export async function getUsersV2(queryParams, options) {
8
- return Get(urls.identity.users.v2, queryParams, {
9
- headers: extractHeadersFromOptions(options)
10
- });
11
- }
12
- export async function getUsersV3(queryParams, options) {
13
- return Get(urls.identity.users.v3, queryParams, {
14
- headers: extractHeadersFromOptions(options)
15
- });
16
- }
17
- export async function getUsersRoles(queryParams, options) {
18
- return Get(urls.identity.users.roles.v3, _extends({}, queryParams, {
19
- ids: queryParams.ids.join(',')
20
- }), {
21
- headers: extractHeadersFromOptions(options)
22
- });
23
- }
24
- export async function getUsersGroups(queryParams, options) {
25
- return Get(urls.identity.users.groups.v3, _extends({}, queryParams, {
26
- ids: queryParams.ids.join(",")
27
- }), {
28
- headers: extractHeadersFromOptions(options)
29
- });
30
- }
31
- export async function getCurrentUserTenantsV3(options) {
32
- return Get(urls.identity.users.tenants.me.v3, undefined, {
33
- headers: extractHeadersFromOptions(options)
34
- });
35
- }
36
- export async function getCurrentUserTenantsV1(options) {
37
- return Get(urls.identity.users.tenants.me.v1, undefined, {
38
- headers: extractHeadersFromOptions(options)
39
- });
40
- }
41
- export async function sendResetBreachedPasswordEmails() {
42
- return Post(urls.identity.users.passwords.resetBreachedPasswords.v1);
43
- }
44
- export async function updateUserProfileV2(body) {
45
- return Put(`${urls.identity.users.v2}/me`, body);
46
- }
3
+ import { BaseApiClient } from '../BaseApiClient';
4
+ export class UsersApi extends BaseApiClient {
5
+ constructor(appName) {
6
+ super(appName);
7
+
8
+ this.GetUserJwt = async body => {
9
+ return this.post(`${urls.identity.users.v3}/me/token`, body);
10
+ };
11
+
12
+ this.getUsersV2 = async (queryParams, options) => {
13
+ return this.get(urls.identity.users.v2, queryParams, {
14
+ headers: this.extractHeadersFromOptions(options)
15
+ });
16
+ };
17
+
18
+ this.getUsersV3 = async (queryParams, options) => {
19
+ return this.get(urls.identity.users.v3, queryParams, {
20
+ headers: this.extractHeadersFromOptions(options)
21
+ });
22
+ };
23
+
24
+ this.getUsersRoles = async (queryParams, options) => {
25
+ return this.get(urls.identity.users.roles.v3, _extends({}, queryParams, {
26
+ ids: queryParams.ids.join(',')
27
+ }), {
28
+ headers: this.extractHeadersFromOptions(options)
29
+ });
30
+ };
31
+
32
+ this.getUsersGroups = async (queryParams, options) => {
33
+ return this.get(urls.identity.users.groups.v3, _extends({}, queryParams, {
34
+ ids: queryParams.ids.join(',')
35
+ }), {
36
+ headers: this.extractHeadersFromOptions(options)
37
+ });
38
+ };
39
+
40
+ this.getCurrentUserTenantsV3 = async options => {
41
+ return this.get(urls.identity.users.tenants.me.v3, undefined, {
42
+ headers: this.extractHeadersFromOptions(options)
43
+ });
44
+ };
45
+
46
+ this.getCurrentUserTenantsV1 = async options => {
47
+ return this.get(urls.identity.users.tenants.me.v1, undefined, {
48
+ headers: this.extractHeadersFromOptions(options)
49
+ });
50
+ };
51
+
52
+ this.sendResetBreachedPasswordEmails = async () => {
53
+ return this.post(urls.identity.users.passwords.resetBreachedPasswords.v1);
54
+ };
55
+
56
+ this.updateUserProfileV2 = async body => {
57
+ return this.put(`${urls.identity.users.v2}/me`, body);
58
+ };
59
+ }
60
+
61
+ }
62
+ export default new UsersApi('default');
package/vendor/index.d.ts CHANGED
@@ -1,6 +1,12 @@
1
- import { IVendorPublicInfoResponse } from "./interfaces";
2
- /**
3
- * provide vendor public info by providing the vendor context.
4
- * @return IVendorPublicInfoResponse
5
- */
6
- export declare function getVendorPublicInfo(): Promise<IVendorPublicInfoResponse>;
1
+ import { IVendorPublicInfoResponse } from './interfaces';
2
+ import { BaseApiClient } from '../BaseApiClient';
3
+ export declare class VendorApi extends BaseApiClient {
4
+ constructor(appName: string);
5
+ /**
6
+ * Provide vendor public info by providing the vendor context.
7
+ * @returns {Promise<IVendorPublicInfoResponse>}
8
+ */
9
+ getVendorPublicInfo: () => Promise<IVendorPublicInfoResponse>;
10
+ }
11
+ declare const _default: VendorApi;
12
+ export default _default;
package/vendor/index.js CHANGED
@@ -1,6 +1,13 @@
1
- import { Get } from '../fetch';
2
1
  import { urls } from '../constants';
3
- export async function getVendorPublicInfo() {
4
- return Get(`${urls.vendor}/public`);
2
+ import { BaseApiClient } from '../BaseApiClient';
3
+ export class VendorApi extends BaseApiClient {
4
+ constructor(appName) {
5
+ super(appName);
6
+
7
+ this.getVendorPublicInfo = async () => {
8
+ return this.get(`${urls.vendor}/public`);
9
+ };
10
+ }
11
+
5
12
  }
6
- ;
13
+ export default new VendorApi('default');
package/fetch.d.ts DELETED
@@ -1,24 +0,0 @@
1
- import { ContextOptions, UserJwtOptions } from './interfaces';
2
- interface RequestOptions {
3
- url: string;
4
- method: 'GET' | 'POST' | 'PATCH' | 'PUT' | 'DELETE';
5
- body?: any;
6
- params?: any;
7
- contentType?: string;
8
- responseType?: 'json' | 'plain' | 'blob';
9
- headers?: Record<string, string>;
10
- credentials?: RequestCredentials;
11
- }
12
- export declare function getBaseUrl(context: ContextOptions, url: string, withFronteggPrefix?: boolean): string;
13
- export declare function getMetadataHeaders(context: ContextOptions): Record<string, string>;
14
- export declare function getScopedTenant(): string | null;
15
- export declare const Get: (url: string, params?: any, opts?: Pick<RequestOptions, "body" | "params" | "contentType" | "responseType" | "headers" | "credentials"> | undefined) => Promise<any>;
16
- export declare const Post: (url: string, body?: any, opts?: Pick<RequestOptions, "body" | "params" | "contentType" | "responseType" | "headers" | "credentials"> | undefined) => Promise<any>;
17
- export declare const Patch: (url: string, body?: any, opts?: Pick<RequestOptions, "body" | "params" | "contentType" | "responseType" | "headers" | "credentials"> | undefined) => Promise<any>;
18
- export declare const Put: (url: string, body?: any, opts?: Pick<RequestOptions, "body" | "params" | "contentType" | "responseType" | "headers" | "credentials"> | undefined) => Promise<any>;
19
- export declare const Delete: (url: string, body?: any, opts?: Pick<RequestOptions, "body" | "params" | "contentType" | "responseType" | "headers" | "credentials"> | undefined) => Promise<any>;
20
- export declare const PostDownload: (url: string, body?: any, params?: any, opts?: any) => Promise<any>;
21
- export declare const extractHeadersFromOptions: (options?: UserJwtOptions) => {
22
- Authorization?: string;
23
- };
24
- export {};
package/fetch.js DELETED
@@ -1,265 +0,0 @@
1
- import _extends from "@babel/runtime/helpers/esm/extends";
2
- import { ContextHolder } from './ContextHolder';
3
- import { fronteggHeaders } from './interfaces';
4
- import { FronteggApiError } from './error';
5
- import { GENERIC_ERROR_MESSAGE } from './constants';
6
- export function getBaseUrl(context, url, withFronteggPrefix = true) {
7
- let baseUrl;
8
-
9
- if (typeof context.baseUrl === 'function') {
10
- baseUrl = context.baseUrl(url);
11
- } else {
12
- baseUrl = context.baseUrl;
13
- }
14
-
15
- const prefix = context.urlPrefix || 'frontegg';
16
- const removePrefix = prefix === 'frontegg' && !withFronteggPrefix;
17
-
18
- if (!baseUrl.endsWith('/')) {
19
- baseUrl += '/';
20
- }
21
-
22
- if (!baseUrl.endsWith(prefix) && !removePrefix) {
23
- baseUrl += prefix;
24
- }
25
-
26
- return baseUrl;
27
- }
28
-
29
- async function prepareUrl(context, url, params) {
30
- const baseUrl = getBaseUrl(context, url);
31
- const paramsToSend = await buildQueryParams(context, params);
32
- let finalUrl = url.startsWith('http') ? url : `${baseUrl}${url}`;
33
- const hasKeys = Object.keys(paramsToSend).length > 0;
34
-
35
- if (paramsToSend && hasKeys) {
36
- const urlParams = new URLSearchParams(paramsToSend);
37
- finalUrl += `?${urlParams}`;
38
- }
39
-
40
- return finalUrl;
41
- }
42
-
43
- export function getMetadataHeaders(context) {
44
- var _context$metadataHead, _context$metadataHead2;
45
-
46
- const headers = {};
47
-
48
- if (context != null && (_context$metadataHead = context.metadataHeaders) != null && _context$metadataHead.fronteggSdkVersion) {
49
- headers[fronteggHeaders.fronteggSdkVersion] = context.metadataHeaders.fronteggSdkVersion;
50
- }
51
-
52
- if (context != null && (_context$metadataHead2 = context.metadataHeaders) != null && _context$metadataHead2.framework) {
53
- headers[fronteggHeaders.frameWork] = context.metadataHeaders.framework;
54
- }
55
-
56
- return headers;
57
- }
58
- export function getScopedTenant() {
59
- const urlParams = new URLSearchParams(window.location.search);
60
- const scopedTenant = urlParams.get('tenantId');
61
-
62
- if (scopedTenant) {
63
- return scopedTenant;
64
- }
65
-
66
- return null;
67
- }
68
-
69
- async function buildRequestHeaders(context, contentType) {
70
- var _context$tokenResolve;
71
-
72
- const headers = getMetadataHeaders(context);
73
- const authToken = await ((_context$tokenResolve = context == null ? void 0 : context.tokenResolver) != null ? _context$tokenResolve : ContextHolder.getAccessToken)();
74
- const requestSource = ContextHolder.getRequestSource();
75
- const scopedTenant = getScopedTenant();
76
-
77
- if (contentType) {
78
- headers[fronteggHeaders.contentType] = contentType;
79
- }
80
-
81
- if (requestSource) {
82
- headers[fronteggHeaders.source] = requestSource;
83
- }
84
-
85
- if (authToken) {
86
- headers.Authorization = `Bearer ${authToken}`;
87
- }
88
-
89
- if (scopedTenant) {
90
- headers[fronteggHeaders.scopedTenant] = scopedTenant;
91
- }
92
-
93
- for (const additionalHeader of await getAdditionalHeaders(context)) {
94
- headers[`${additionalHeader.key}`] = `${additionalHeader.value}`;
95
- }
96
-
97
- return headers;
98
- }
99
-
100
- async function buildQueryParams(context, params) {
101
- if (!params) {
102
- params = {};
103
- }
104
-
105
- const additionalQueryParams = await getAdditionalQueryParams(context);
106
-
107
- for (const queryParam of additionalQueryParams) {
108
- params[queryParam.key] = queryParam.value;
109
- }
110
-
111
- const keys = Object.keys(params);
112
-
113
- for (const key of keys) {
114
- const value = params[key];
115
- params[key] = typeof value === 'object' ? JSON.stringify(value) : value;
116
- }
117
-
118
- return params;
119
- }
120
-
121
- async function getAdditionalQueryParams(context) {
122
- let output = [];
123
-
124
- if (context.additionalQueryParamsResolver) {
125
- output = await context.additionalQueryParamsResolver();
126
- }
127
-
128
- return output;
129
- }
130
-
131
- async function getAdditionalHeaders(context) {
132
- let output = [];
133
-
134
- if (context.additionalHeadersResolver) {
135
- output = await context.additionalHeadersResolver();
136
- }
137
-
138
- if (context.tenantResolver) {
139
- const resolvedTenantResult = await context.tenantResolver();
140
-
141
- if (!!(resolvedTenantResult != null && resolvedTenantResult.tenant)) {
142
- output.push({
143
- key: 'frontegg-login-alias',
144
- value: resolvedTenantResult.tenant
145
- });
146
- }
147
- }
148
-
149
- if (context.appId) {
150
- output.push({
151
- key: 'frontegg-requested-application-id',
152
- value: context.appId
153
- });
154
- }
155
-
156
- return output;
157
- }
158
-
159
- const sendRequest = async opts => {
160
- var _opts$method, _ref, _opts$credentials;
161
-
162
- const context = ContextHolder.getContext();
163
- const headers = await buildRequestHeaders(context, opts.contentType);
164
- const url = await prepareUrl(context, opts.url, opts.params);
165
- const response = await fetch(url, {
166
- body: opts.body ? opts.contentType === 'application/json' ? JSON.stringify(opts.body) : opts.body : null,
167
- method: (_opts$method = opts.method) != null ? _opts$method : 'GET',
168
- headers: _extends({}, headers, opts.headers),
169
- credentials: (_ref = (_opts$credentials = opts.credentials) != null ? _opts$credentials : context.requestCredentials) != null ? _ref : 'same-origin'
170
- });
171
-
172
- if (response.status === 302) {
173
- window.location.href = await response.text();
174
- return new Promise(() => {});
175
- }
176
-
177
- if (!response.ok) {
178
- var _context$logLevel, _context$logLevel2;
179
-
180
- if (response.status === 413) {
181
- throw new FronteggApiError('Error request is too large', response.status);
182
- }
183
-
184
- let errorMessage;
185
- let isJsonResponse = true;
186
-
187
- try {
188
- errorMessage = await response.text();
189
- errorMessage = JSON.parse(errorMessage);
190
- } catch (e) {
191
- isJsonResponse = false;
192
- }
193
-
194
- if (errorMessage.errors) {
195
- errorMessage = errorMessage.errors.join(', ');
196
- } else if (typeof errorMessage !== 'string') {
197
- errorMessage = `Error ${response.status} - ${response.statusText}`;
198
- }
199
-
200
- if (response.status >= 400 && response.status < 500 && ['warn'].includes((_context$logLevel = context.logLevel) != null ? _context$logLevel : '')) console.warn(errorMessage);else if (response.status === 500 && ['warn', 'error'].includes((_context$logLevel2 = context.logLevel) != null ? _context$logLevel2 : '')) console.error(errorMessage);
201
- throw new FronteggApiError(isJsonResponse ? errorMessage : GENERIC_ERROR_MESSAGE, response.status);
202
- }
203
-
204
- if (!opts.responseType || opts.responseType === 'json') {
205
- try {
206
- return await response.json();
207
- } catch (e) {
208
- return {};
209
- }
210
- } else if (opts.responseType === 'blob') {
211
- const {
212
- outputFileName
213
- } = opts.params;
214
- return await response.blob().then(blob => URL.createObjectURL(blob)).then(url => {
215
- const tempLink = document.createElement('a');
216
- tempLink.href = url;
217
- tempLink.setAttribute('download', outputFileName || 'output');
218
- tempLink.click();
219
- });
220
- } else {
221
- return await response.text();
222
- }
223
- };
224
-
225
- export const Get = async (url, params, opts) => sendRequest(_extends({
226
- url,
227
- method: 'GET',
228
- contentType: 'application/json',
229
- params
230
- }, opts));
231
- export const Post = async (url, body, opts) => sendRequest(_extends({
232
- url,
233
- method: 'POST',
234
- contentType: 'application/json',
235
- body
236
- }, opts));
237
- export const Patch = async (url, body, opts) => sendRequest(_extends({
238
- url,
239
- method: 'PATCH',
240
- contentType: 'application/json',
241
- body
242
- }, opts));
243
- export const Put = async (url, body, opts) => sendRequest(_extends({
244
- url,
245
- method: 'PUT',
246
- contentType: 'application/json',
247
- body
248
- }, opts));
249
- export const Delete = async (url, body, opts) => sendRequest(_extends({
250
- url,
251
- method: 'DELETE',
252
- contentType: 'application/json',
253
- body
254
- }, opts));
255
- export const PostDownload = async (url, body, params, opts) => sendRequest(_extends({
256
- url,
257
- method: 'POST',
258
- contentType: 'application/json',
259
- responseType: 'blob',
260
- body,
261
- params
262
- }, opts));
263
- export const extractHeadersFromOptions = (options = {}) => _extends({}, options.jwt ? {
264
- Authorization: options.jwt
265
- } : {});