@frontegg/rest-api 3.1.76-alpha.9502349697 → 3.1.76-alpha.9762981322
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.
- package/ContextHolder/index.d.ts +30 -108
- package/ContextHolder/index.js +57 -153
- package/account-settings/index.d.ts +7 -19
- package/account-settings/index.js +13 -23
- package/applications/index.d.ts +44 -49
- package/applications/index.js +37 -51
- package/audits/index.d.ts +15 -27
- package/audits/index.js +17 -27
- package/auth/index.d.ts +768 -817
- package/auth/index.js +721 -902
- package/auth/secutiry-poilicy/index.d.ts +102 -58
- package/auth/secutiry-poilicy/index.js +90 -122
- package/auth/utils.d.ts +2 -2
- package/auth/utils.js +8 -9
- package/connectivity/index.d.ts +27 -126
- package/connectivity/index.js +114 -147
- package/directory/index.d.ts +22 -31
- package/directory/index.js +15 -27
- package/entitlements/index.d.ts +8 -14
- package/entitlements/index.js +4 -12
- package/feature-flags/index.d.ts +2 -8
- package/feature-flags/index.js +8 -16
- package/fetch.d.ts +24 -0
- package/fetch.js +265 -0
- package/groups/index.d.ts +49 -73
- package/groups/index.js +45 -64
- package/impersonate/index.d.ts +6 -15
- package/impersonate/index.js +5 -13
- package/index.d.ts +108 -154
- package/index.js +78 -109
- package/interfaces.d.ts +0 -10
- package/metadata/index.d.ts +7 -67
- package/metadata/index.js +32 -52
- package/node/ContextHolder/index.js +57 -153
- package/node/account-settings/index.js +16 -27
- package/node/applications/index.js +44 -51
- package/node/audits/index.js +20 -31
- package/node/auth/index.js +1035 -768
- package/node/auth/secutiry-poilicy/index.js +136 -125
- package/node/auth/utils.js +7 -9
- package/node/connectivity/index.js +187 -148
- package/node/directory/index.js +20 -29
- package/node/entitlements/index.js +5 -18
- package/node/feature-flags/index.js +9 -21
- package/node/fetch.js +306 -0
- package/node/groups/index.js +63 -65
- package/node/impersonate/index.js +5 -18
- package/node/index.js +71 -116
- package/node/metadata/index.js +52 -61
- package/node/notifications/index.js +27 -37
- package/node/reports/index.js +70 -78
- package/node/roles/index.js +51 -56
- package/node/security-center/index.js +9 -21
- package/node/sub-tenants/index.js +89 -90
- package/node/subscriptions/index.js +107 -69
- package/node/subscriptions/invoices.js +17 -25
- package/node/subscriptions/managedSubscriptions.js +27 -32
- package/node/subscriptions/paymentMethods.js +20 -27
- package/node/subscriptions/paymentProviders.js +6 -15
- package/node/subscriptions/plans.js +9 -17
- package/node/subscriptions/providers/index.js +18 -0
- package/node/subscriptions/providers/stripe/index.js +21 -26
- package/node/subscriptions/subscriptions.js +27 -32
- package/node/subscriptions/summaries.js +6 -15
- package/node/subscriptions/tenantConfiguration.js +9 -17
- package/node/subscriptions/vendorPublicConfigurations.js +6 -15
- package/node/teams/index.js +138 -130
- package/node/tenants/index.js +60 -65
- package/node/user-phone-numbers/index.js +24 -32
- package/node/users/index.js +53 -58
- package/node/vendor/index.js +6 -17
- package/notifications/index.d.ts +16 -22
- package/notifications/index.js +22 -33
- package/package.json +1 -1
- package/reports/index.d.ts +44 -50
- package/reports/index.js +62 -75
- package/roles/index.d.ts +38 -44
- package/roles/index.js +41 -57
- package/security-center/index.d.ts +2 -14
- package/security-center/index.js +6 -15
- package/sub-tenants/index.d.ts +15 -57
- package/sub-tenants/index.js +68 -88
- package/subscriptions/index.d.ts +11 -56
- package/subscriptions/index.js +11 -58
- package/subscriptions/invoices.d.ts +13 -16
- package/subscriptions/invoices.js +14 -24
- package/subscriptions/managedSubscriptions.d.ts +15 -18
- package/subscriptions/managedSubscriptions.js +22 -33
- package/subscriptions/paymentMethods.d.ts +13 -16
- package/subscriptions/paymentMethods.js +17 -26
- package/subscriptions/paymentProviders.d.ts +5 -8
- package/subscriptions/paymentProviders.js +4 -11
- package/subscriptions/plans.d.ts +8 -11
- package/subscriptions/plans.js +6 -14
- package/subscriptions/providers/index.d.ts +1 -0
- package/subscriptions/providers/index.js +1 -0
- package/subscriptions/providers/stripe/index.d.ts +21 -24
- package/subscriptions/providers/stripe/index.js +16 -27
- package/subscriptions/subscriptions.d.ts +21 -24
- package/subscriptions/subscriptions.js +22 -33
- package/subscriptions/summaries.d.ts +4 -7
- package/subscriptions/summaries.js +3 -10
- package/subscriptions/tenantConfiguration.d.ts +3 -6
- package/subscriptions/tenantConfiguration.js +7 -15
- package/subscriptions/vendorPublicConfigurations.d.ts +2 -5
- package/subscriptions/vendorPublicConfigurations.js +4 -11
- package/teams/index.d.ts +131 -35
- package/teams/index.js +93 -122
- package/tenants/index.d.ts +37 -25
- package/tenants/index.js +46 -62
- package/user-phone-numbers/index.d.ts +26 -32
- package/user-phone-numbers/index.js +19 -32
- package/users/index.d.ts +15 -21
- package/users/index.js +44 -60
- package/vendor/index.d.ts +6 -12
- package/vendor/index.js +4 -11
- package/BaseApiClient.d.ts +0 -16
- package/BaseApiClient.js +0 -39
- package/FetchClient.d.ts +0 -42
- package/FetchClient.js +0 -308
- package/node/BaseApiClient.js +0 -49
- package/node/FetchClient.js +0 -326
package/users/index.js
CHANGED
|
@@ -1,62 +1,46 @@
|
|
|
1
1
|
import _extends from "@babel/runtime/helpers/esm/extends";
|
|
2
|
+
import { extractHeadersFromOptions, Get, Post, Put } from '../fetch';
|
|
2
3
|
import { urls } from '../constants';
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
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');
|
|
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
|
+
}
|
package/vendor/index.d.ts
CHANGED
|
@@ -1,12 +1,6 @@
|
|
|
1
|
-
import { IVendorPublicInfoResponse } from
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
* @returns {Promise<IVendorPublicInfoResponse>}
|
|
8
|
-
*/
|
|
9
|
-
getVendorPublicInfo: () => Promise<IVendorPublicInfoResponse>;
|
|
10
|
-
}
|
|
11
|
-
declare const _default: VendorApi;
|
|
12
|
-
export default _default;
|
|
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>;
|
package/vendor/index.js
CHANGED
|
@@ -1,13 +1,6 @@
|
|
|
1
|
+
import { Get } from '../fetch';
|
|
1
2
|
import { urls } from '../constants';
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
constructor(appName) {
|
|
5
|
-
super(appName);
|
|
6
|
-
|
|
7
|
-
this.getVendorPublicInfo = async () => {
|
|
8
|
-
return this.get(`${urls.vendor}/public`);
|
|
9
|
-
};
|
|
10
|
-
}
|
|
11
|
-
|
|
3
|
+
export async function getVendorPublicInfo() {
|
|
4
|
+
return Get(`${urls.vendor}/public`);
|
|
12
5
|
}
|
|
13
|
-
|
|
6
|
+
;
|
package/BaseApiClient.d.ts
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import { FetchClient } from './FetchClient';
|
|
2
|
-
import { RequestOptions, UserJwtOptions } from './interfaces';
|
|
3
|
-
export declare class BaseApiClient {
|
|
4
|
-
protected appName: string;
|
|
5
|
-
protected fetchClient: FetchClient;
|
|
6
|
-
protected constructor(appName: string);
|
|
7
|
-
protected get: <T>(url: string, params?: any, opts?: Pick<RequestOptions, "body" | "params" | "contentType" | "responseType" | "headers" | "credentials"> | undefined) => Promise<T>;
|
|
8
|
-
protected post: <T>(url: string, body?: any, opts?: Pick<RequestOptions, "body" | "params" | "contentType" | "responseType" | "headers" | "credentials"> | undefined) => Promise<T>;
|
|
9
|
-
protected patch: <T>(url: string, body?: any, opts?: Pick<RequestOptions, "body" | "params" | "contentType" | "responseType" | "headers" | "credentials"> | undefined) => Promise<T>;
|
|
10
|
-
protected put: <T>(url: string, body?: any, opts?: Pick<RequestOptions, "body" | "params" | "contentType" | "responseType" | "headers" | "credentials"> | undefined) => Promise<T>;
|
|
11
|
-
protected delete: <T>(url: string, body?: any, opts?: Pick<RequestOptions, "body" | "params" | "contentType" | "responseType" | "headers" | "credentials"> | undefined) => Promise<T>;
|
|
12
|
-
protected postDownload: <T>(url: string, body?: any, params?: any, opts?: Pick<RequestOptions, "body" | "params" | "contentType" | "responseType" | "headers" | "credentials"> | undefined) => Promise<T>;
|
|
13
|
-
protected extractHeadersFromOptions: (options?: UserJwtOptions) => {
|
|
14
|
-
Authorization?: string;
|
|
15
|
-
};
|
|
16
|
-
}
|
package/BaseApiClient.js
DELETED
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
import { FetchClient } from './FetchClient';
|
|
2
|
-
export class BaseApiClient {
|
|
3
|
-
constructor(appName) {
|
|
4
|
-
this.appName = void 0;
|
|
5
|
-
this.fetchClient = void 0;
|
|
6
|
-
|
|
7
|
-
this.get = async (url, params, opts) => {
|
|
8
|
-
return this.fetchClient.get(url, params, opts);
|
|
9
|
-
};
|
|
10
|
-
|
|
11
|
-
this.post = async (url, body, opts) => {
|
|
12
|
-
return this.fetchClient.post(url, body, opts);
|
|
13
|
-
};
|
|
14
|
-
|
|
15
|
-
this.patch = async (url, body, opts) => {
|
|
16
|
-
return this.fetchClient.patch(url, body, opts);
|
|
17
|
-
};
|
|
18
|
-
|
|
19
|
-
this.put = async (url, body, opts) => {
|
|
20
|
-
return this.fetchClient.put(url, body, opts);
|
|
21
|
-
};
|
|
22
|
-
|
|
23
|
-
this.delete = async (url, body, opts) => {
|
|
24
|
-
return this.fetchClient.delete(url, body, opts);
|
|
25
|
-
};
|
|
26
|
-
|
|
27
|
-
this.postDownload = async (url, body, params, opts) => {
|
|
28
|
-
return this.fetchClient.postDownload(url, body, params, opts);
|
|
29
|
-
};
|
|
30
|
-
|
|
31
|
-
this.extractHeadersFromOptions = (options = {}) => {
|
|
32
|
-
return this.fetchClient.extractHeadersFromOptions(options);
|
|
33
|
-
};
|
|
34
|
-
|
|
35
|
-
this.appName = appName;
|
|
36
|
-
this.fetchClient = new FetchClient(appName);
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
}
|
package/FetchClient.d.ts
DELETED
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
import { ContextOptions, RequestOptions, UserJwtOptions } from './interfaces';
|
|
2
|
-
/**
|
|
3
|
-
* FetchClient is a class that wrap around the fetch API to make requests.
|
|
4
|
-
* It is used by the BaseApiClient to make requests to the server
|
|
5
|
-
*/
|
|
6
|
-
export declare class FetchClient {
|
|
7
|
-
private appName;
|
|
8
|
-
constructor(appName: string);
|
|
9
|
-
private getFronteggContext;
|
|
10
|
-
private prepareUrl;
|
|
11
|
-
private buildQueryParams;
|
|
12
|
-
private getAdditionalQueryParams;
|
|
13
|
-
private getAdditionalHeaders;
|
|
14
|
-
private buildRequestHeaders;
|
|
15
|
-
sendRequest: (opts: RequestOptions) => Promise<any>;
|
|
16
|
-
get: (url: string, params?: any, opts?: Pick<RequestOptions, "body" | "params" | "contentType" | "responseType" | "headers" | "credentials"> | undefined) => Promise<any>;
|
|
17
|
-
post: (url: string, body?: any, opts?: Pick<RequestOptions, "body" | "params" | "contentType" | "responseType" | "headers" | "credentials"> | undefined) => Promise<any>;
|
|
18
|
-
patch: (url: string, body?: any, opts?: Pick<RequestOptions, "body" | "params" | "contentType" | "responseType" | "headers" | "credentials"> | undefined) => Promise<any>;
|
|
19
|
-
put: (url: string, body?: any, opts?: Pick<RequestOptions, "body" | "params" | "contentType" | "responseType" | "headers" | "credentials"> | undefined) => Promise<any>;
|
|
20
|
-
delete: (url: string, body?: any, opts?: Pick<RequestOptions, "body" | "params" | "contentType" | "responseType" | "headers" | "credentials"> | undefined) => Promise<any>;
|
|
21
|
-
postDownload: (url: string, body?: any, params?: any, opts?: any) => Promise<any>;
|
|
22
|
-
extractHeadersFromOptions: (options?: UserJwtOptions) => {
|
|
23
|
-
Authorization?: string;
|
|
24
|
-
};
|
|
25
|
-
/** @deprecated use getContextBaseUrl instead */
|
|
26
|
-
static getBaseUrl: (context: ContextOptions, url: string, withFronteggPrefix?: boolean) => string;
|
|
27
|
-
/** @deprecated use getContextBaseUrl instead */
|
|
28
|
-
getBaseUrl: (context: ContextOptions, url: string, withFronteggPrefix?: boolean) => string;
|
|
29
|
-
getContextBaseUrl: (url: string, withFronteggPrefix?: boolean) => string;
|
|
30
|
-
static getMetadataHeaders: (context: ContextOptions) => Record<string, string>;
|
|
31
|
-
/** @deprecated - use getContextMetadataHeaders instead */
|
|
32
|
-
getMetadataHeaders: (context: ContextOptions) => Record<string, string>;
|
|
33
|
-
getContextMetadataHeaders: () => Record<string, string>;
|
|
34
|
-
static getScopedTenant: () => string | null;
|
|
35
|
-
}
|
|
36
|
-
declare const _default: FetchClient;
|
|
37
|
-
/**
|
|
38
|
-
* import FetchClient and use it to make requests to the server for specific application
|
|
39
|
-
* @param appName - the application name to make requests for
|
|
40
|
-
* @deprecated - use FetchClient directly
|
|
41
|
-
*/
|
|
42
|
-
export default _default;
|
package/FetchClient.js
DELETED
|
@@ -1,308 +0,0 @@
|
|
|
1
|
-
import _extends from "@babel/runtime/helpers/esm/extends";
|
|
2
|
-
import { ContextHolder } from './ContextHolder';
|
|
3
|
-
import { FronteggApiError } from './error';
|
|
4
|
-
import { GENERIC_ERROR_MESSAGE } from './constants';
|
|
5
|
-
import { fronteggHeaders } from './interfaces';
|
|
6
|
-
export class FetchClient {
|
|
7
|
-
constructor(appName) {
|
|
8
|
-
this.appName = void 0;
|
|
9
|
-
|
|
10
|
-
this.getFronteggContext = () => {
|
|
11
|
-
return ContextHolder.for(this.appName);
|
|
12
|
-
};
|
|
13
|
-
|
|
14
|
-
this.prepareUrl = async (url, params) => {
|
|
15
|
-
const context = this.getFronteggContext().getContext();
|
|
16
|
-
const baseUrl = this.getContextBaseUrl(url);
|
|
17
|
-
const paramsToSend = await this.buildQueryParams(context, params);
|
|
18
|
-
let finalUrl = url.startsWith('http') ? url : `${baseUrl}${url}`;
|
|
19
|
-
const hasKeys = Object.keys(paramsToSend).length > 0;
|
|
20
|
-
|
|
21
|
-
if (paramsToSend && hasKeys) {
|
|
22
|
-
const urlParams = new URLSearchParams(paramsToSend);
|
|
23
|
-
finalUrl += `?${urlParams}`;
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
return finalUrl;
|
|
27
|
-
};
|
|
28
|
-
|
|
29
|
-
this.buildQueryParams = async (context, params) => {
|
|
30
|
-
if (!params) {
|
|
31
|
-
params = {};
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
const additionalQueryParams = await this.getAdditionalQueryParams(context);
|
|
35
|
-
|
|
36
|
-
for (const queryParam of additionalQueryParams) {
|
|
37
|
-
params[queryParam.key] = queryParam.value;
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
const keys = Object.keys(params);
|
|
41
|
-
|
|
42
|
-
for (const key of keys) {
|
|
43
|
-
const value = params[key];
|
|
44
|
-
params[key] = typeof value === 'object' ? JSON.stringify(value) : value;
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
return params;
|
|
48
|
-
};
|
|
49
|
-
|
|
50
|
-
this.getAdditionalQueryParams = async context => {
|
|
51
|
-
let output = [];
|
|
52
|
-
|
|
53
|
-
if (context.additionalQueryParamsResolver) {
|
|
54
|
-
output = await context.additionalQueryParamsResolver();
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
return output;
|
|
58
|
-
};
|
|
59
|
-
|
|
60
|
-
this.getAdditionalHeaders = async context => {
|
|
61
|
-
let output = [];
|
|
62
|
-
|
|
63
|
-
if (context.additionalHeadersResolver) {
|
|
64
|
-
output = await context.additionalHeadersResolver();
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
if (context.tenantResolver) {
|
|
68
|
-
const resolvedTenantResult = await context.tenantResolver();
|
|
69
|
-
|
|
70
|
-
if (!!(resolvedTenantResult != null && resolvedTenantResult.tenant)) {
|
|
71
|
-
output.push({
|
|
72
|
-
key: 'frontegg-login-alias',
|
|
73
|
-
value: resolvedTenantResult.tenant
|
|
74
|
-
});
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
if (context.appId) {
|
|
79
|
-
output.push({
|
|
80
|
-
key: 'frontegg-requested-application-id',
|
|
81
|
-
value: context.appId
|
|
82
|
-
});
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
return output;
|
|
86
|
-
};
|
|
87
|
-
|
|
88
|
-
this.buildRequestHeaders = async contentType => {
|
|
89
|
-
var _context$tokenResolve;
|
|
90
|
-
|
|
91
|
-
const fronteggContext = this.getFronteggContext();
|
|
92
|
-
const context = fronteggContext.getContext();
|
|
93
|
-
const headers = FetchClient.getMetadataHeaders(context);
|
|
94
|
-
const authToken = await ((_context$tokenResolve = context == null ? void 0 : context.tokenResolver) != null ? _context$tokenResolve : fronteggContext.getAccessToken)();
|
|
95
|
-
const requestSource = fronteggContext.getRequestSource();
|
|
96
|
-
const scopedTenant = FetchClient.getScopedTenant();
|
|
97
|
-
|
|
98
|
-
if (contentType) {
|
|
99
|
-
headers[fronteggHeaders.contentType] = contentType;
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
if (requestSource) {
|
|
103
|
-
headers[fronteggHeaders.source] = requestSource;
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
if (authToken) {
|
|
107
|
-
headers.Authorization = `Bearer ${authToken}`;
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
if (scopedTenant) {
|
|
111
|
-
headers[fronteggHeaders.scopedTenant] = scopedTenant;
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
for (const additionalHeader of await this.getAdditionalHeaders(context)) {
|
|
115
|
-
headers[`${additionalHeader.key}`] = `${additionalHeader.value}`;
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
return headers;
|
|
119
|
-
};
|
|
120
|
-
|
|
121
|
-
this.sendRequest = async opts => {
|
|
122
|
-
var _opts$method, _ref, _opts$credentials;
|
|
123
|
-
|
|
124
|
-
const context = this.getFronteggContext().getContext();
|
|
125
|
-
const headers = await this.buildRequestHeaders(opts.contentType);
|
|
126
|
-
const url = await this.prepareUrl(opts.url, opts.params);
|
|
127
|
-
const response = await fetch(url, {
|
|
128
|
-
body: opts.body ? opts.contentType === 'application/json' ? JSON.stringify(opts.body) : opts.body : null,
|
|
129
|
-
method: (_opts$method = opts.method) != null ? _opts$method : 'GET',
|
|
130
|
-
headers: _extends({}, headers, opts.headers),
|
|
131
|
-
credentials: (_ref = (_opts$credentials = opts.credentials) != null ? _opts$credentials : context.requestCredentials) != null ? _ref : 'same-origin'
|
|
132
|
-
});
|
|
133
|
-
|
|
134
|
-
if (response.status === 302) {
|
|
135
|
-
window.location.href = await response.text();
|
|
136
|
-
return new Promise(() => {});
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
if (!response.ok) {
|
|
140
|
-
var _context$logLevel, _context$logLevel2;
|
|
141
|
-
|
|
142
|
-
if (response.status === 413) {
|
|
143
|
-
throw new FronteggApiError('Error request is too large', response.status);
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
let errorMessage;
|
|
147
|
-
let isJsonResponse = true;
|
|
148
|
-
|
|
149
|
-
try {
|
|
150
|
-
errorMessage = await response.text();
|
|
151
|
-
errorMessage = JSON.parse(errorMessage);
|
|
152
|
-
} catch (e) {
|
|
153
|
-
isJsonResponse = false;
|
|
154
|
-
}
|
|
155
|
-
|
|
156
|
-
if (errorMessage.errors) {
|
|
157
|
-
errorMessage = errorMessage.errors.join(', ');
|
|
158
|
-
} else if (typeof errorMessage !== 'string') {
|
|
159
|
-
errorMessage = `Error ${response.status} - ${response.statusText}`;
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
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);
|
|
163
|
-
throw new FronteggApiError(isJsonResponse ? errorMessage : GENERIC_ERROR_MESSAGE, response.status);
|
|
164
|
-
}
|
|
165
|
-
|
|
166
|
-
if (!opts.responseType || opts.responseType === 'json') {
|
|
167
|
-
try {
|
|
168
|
-
return await response.json();
|
|
169
|
-
} catch (e) {
|
|
170
|
-
return {};
|
|
171
|
-
}
|
|
172
|
-
} else if (opts.responseType === 'blob') {
|
|
173
|
-
const {
|
|
174
|
-
outputFileName
|
|
175
|
-
} = opts.params;
|
|
176
|
-
return await response.blob().then(blob => URL.createObjectURL(blob)).then(url => {
|
|
177
|
-
const tempLink = document.createElement('a');
|
|
178
|
-
tempLink.href = url;
|
|
179
|
-
tempLink.setAttribute('download', outputFileName || 'output');
|
|
180
|
-
tempLink.click();
|
|
181
|
-
});
|
|
182
|
-
} else {
|
|
183
|
-
return await response.text();
|
|
184
|
-
}
|
|
185
|
-
};
|
|
186
|
-
|
|
187
|
-
this.get = async (url, params, opts) => this.sendRequest(_extends({
|
|
188
|
-
url,
|
|
189
|
-
method: 'GET',
|
|
190
|
-
contentType: 'application/json',
|
|
191
|
-
params
|
|
192
|
-
}, opts));
|
|
193
|
-
|
|
194
|
-
this.post = async (url, body, opts) => this.sendRequest(_extends({
|
|
195
|
-
url,
|
|
196
|
-
method: 'POST',
|
|
197
|
-
contentType: 'application/json',
|
|
198
|
-
body
|
|
199
|
-
}, opts));
|
|
200
|
-
|
|
201
|
-
this.patch = async (url, body, opts) => this.sendRequest(_extends({
|
|
202
|
-
url,
|
|
203
|
-
method: 'PATCH',
|
|
204
|
-
contentType: 'application/json',
|
|
205
|
-
body
|
|
206
|
-
}, opts));
|
|
207
|
-
|
|
208
|
-
this.put = async (url, body, opts) => this.sendRequest(_extends({
|
|
209
|
-
url,
|
|
210
|
-
method: 'PUT',
|
|
211
|
-
contentType: 'application/json',
|
|
212
|
-
body
|
|
213
|
-
}, opts));
|
|
214
|
-
|
|
215
|
-
this.delete = async (url, body, opts) => this.sendRequest(_extends({
|
|
216
|
-
url,
|
|
217
|
-
method: 'DELETE',
|
|
218
|
-
contentType: 'application/json',
|
|
219
|
-
body
|
|
220
|
-
}, opts));
|
|
221
|
-
|
|
222
|
-
this.postDownload = async (url, body, params, opts) => this.sendRequest(_extends({
|
|
223
|
-
url,
|
|
224
|
-
method: 'POST',
|
|
225
|
-
contentType: 'application/json',
|
|
226
|
-
responseType: 'blob',
|
|
227
|
-
body,
|
|
228
|
-
params
|
|
229
|
-
}, opts));
|
|
230
|
-
|
|
231
|
-
this.extractHeadersFromOptions = (options = {}) => _extends({}, options.jwt ? {
|
|
232
|
-
Authorization: options.jwt
|
|
233
|
-
} : {});
|
|
234
|
-
|
|
235
|
-
this.getBaseUrl = (context, url, withFronteggPrefix = true) => {
|
|
236
|
-
return FetchClient.getBaseUrl(context, url, withFronteggPrefix);
|
|
237
|
-
};
|
|
238
|
-
|
|
239
|
-
this.getContextBaseUrl = (url, withFronteggPrefix = true) => {
|
|
240
|
-
const context = this.getFronteggContext().getContext();
|
|
241
|
-
return this.getBaseUrl(context, url, withFronteggPrefix);
|
|
242
|
-
};
|
|
243
|
-
|
|
244
|
-
this.getMetadataHeaders = context => {
|
|
245
|
-
return FetchClient.getMetadataHeaders(context);
|
|
246
|
-
};
|
|
247
|
-
|
|
248
|
-
this.getContextMetadataHeaders = () => {
|
|
249
|
-
const context = this.getFronteggContext().getContext();
|
|
250
|
-
return FetchClient.getMetadataHeaders(context);
|
|
251
|
-
};
|
|
252
|
-
|
|
253
|
-
this.appName = appName;
|
|
254
|
-
}
|
|
255
|
-
|
|
256
|
-
}
|
|
257
|
-
|
|
258
|
-
FetchClient.getBaseUrl = (context, url, withFronteggPrefix = true) => {
|
|
259
|
-
let baseUrl;
|
|
260
|
-
|
|
261
|
-
if (typeof context.baseUrl === 'function') {
|
|
262
|
-
baseUrl = context.baseUrl(url);
|
|
263
|
-
} else {
|
|
264
|
-
baseUrl = context.baseUrl;
|
|
265
|
-
}
|
|
266
|
-
|
|
267
|
-
const prefix = context.urlPrefix || 'frontegg';
|
|
268
|
-
const removePrefix = prefix === 'frontegg' && !withFronteggPrefix;
|
|
269
|
-
|
|
270
|
-
if (!baseUrl.endsWith('/')) {
|
|
271
|
-
baseUrl += '/';
|
|
272
|
-
}
|
|
273
|
-
|
|
274
|
-
if (!baseUrl.endsWith(prefix) && !removePrefix) {
|
|
275
|
-
baseUrl += prefix;
|
|
276
|
-
}
|
|
277
|
-
|
|
278
|
-
return baseUrl;
|
|
279
|
-
};
|
|
280
|
-
|
|
281
|
-
FetchClient.getMetadataHeaders = context => {
|
|
282
|
-
var _context$metadataHead, _context$metadataHead2;
|
|
283
|
-
|
|
284
|
-
const headers = {};
|
|
285
|
-
|
|
286
|
-
if (context != null && (_context$metadataHead = context.metadataHeaders) != null && _context$metadataHead.fronteggSdkVersion) {
|
|
287
|
-
headers[fronteggHeaders.fronteggSdkVersion] = context.metadataHeaders.fronteggSdkVersion;
|
|
288
|
-
}
|
|
289
|
-
|
|
290
|
-
if (context != null && (_context$metadataHead2 = context.metadataHeaders) != null && _context$metadataHead2.framework) {
|
|
291
|
-
headers[fronteggHeaders.frameWork] = context.metadataHeaders.framework;
|
|
292
|
-
}
|
|
293
|
-
|
|
294
|
-
return headers;
|
|
295
|
-
};
|
|
296
|
-
|
|
297
|
-
FetchClient.getScopedTenant = () => {
|
|
298
|
-
const urlParams = new URLSearchParams(window.location.search);
|
|
299
|
-
const scopedTenant = urlParams.get('tenantId');
|
|
300
|
-
|
|
301
|
-
if (scopedTenant) {
|
|
302
|
-
return scopedTenant;
|
|
303
|
-
}
|
|
304
|
-
|
|
305
|
-
return null;
|
|
306
|
-
};
|
|
307
|
-
|
|
308
|
-
export default new FetchClient('default');
|
package/node/BaseApiClient.js
DELETED
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.BaseApiClient = void 0;
|
|
7
|
-
|
|
8
|
-
var _FetchClient = require("./FetchClient");
|
|
9
|
-
|
|
10
|
-
class BaseApiClient {
|
|
11
|
-
constructor(appName) {
|
|
12
|
-
this.appName = void 0;
|
|
13
|
-
this.fetchClient = void 0;
|
|
14
|
-
|
|
15
|
-
this.get = async (url, params, opts) => {
|
|
16
|
-
return this.fetchClient.get(url, params, opts);
|
|
17
|
-
};
|
|
18
|
-
|
|
19
|
-
this.post = async (url, body, opts) => {
|
|
20
|
-
return this.fetchClient.post(url, body, opts);
|
|
21
|
-
};
|
|
22
|
-
|
|
23
|
-
this.patch = async (url, body, opts) => {
|
|
24
|
-
return this.fetchClient.patch(url, body, opts);
|
|
25
|
-
};
|
|
26
|
-
|
|
27
|
-
this.put = async (url, body, opts) => {
|
|
28
|
-
return this.fetchClient.put(url, body, opts);
|
|
29
|
-
};
|
|
30
|
-
|
|
31
|
-
this.delete = async (url, body, opts) => {
|
|
32
|
-
return this.fetchClient.delete(url, body, opts);
|
|
33
|
-
};
|
|
34
|
-
|
|
35
|
-
this.postDownload = async (url, body, params, opts) => {
|
|
36
|
-
return this.fetchClient.postDownload(url, body, params, opts);
|
|
37
|
-
};
|
|
38
|
-
|
|
39
|
-
this.extractHeadersFromOptions = (options = {}) => {
|
|
40
|
-
return this.fetchClient.extractHeadersFromOptions(options);
|
|
41
|
-
};
|
|
42
|
-
|
|
43
|
-
this.appName = appName;
|
|
44
|
-
this.fetchClient = new _FetchClient.FetchClient(appName);
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
exports.BaseApiClient = BaseApiClient;
|