@frontegg/rest-api 3.0.83 → 3.0.85
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/feature-flags/index.d.ts +10 -1
- package/feature-flags/index.js +39 -0
- package/feature-flags/interfaces.d.ts +3 -0
- package/fetch.js +11 -0
- package/index.js +1 -1
- package/interfaces.d.ts +8 -0
- package/node/feature-flags/index.js +47 -0
- package/node/fetch.js +11 -0
- package/node/index.js +1 -1
- package/package.json +1 -1
package/feature-flags/index.d.ts
CHANGED
|
@@ -1,2 +1,11 @@
|
|
|
1
|
-
import { IFeatureFlagsAttributes } from "./interfaces";
|
|
1
|
+
import { FronteggFeatureFlags, IFeatureFlagsAttributes } from "./interfaces";
|
|
2
|
+
export declare class FeatureFlags {
|
|
3
|
+
private _flags;
|
|
4
|
+
private static _instances;
|
|
5
|
+
static getInstance(name?: string): any;
|
|
6
|
+
static set(featureFlags?: FronteggFeatureFlags, name?: string): FeatureFlags;
|
|
7
|
+
static getFeatureFlags(flags: string[]): boolean[];
|
|
8
|
+
get flags(): Required<FronteggFeatureFlags>["flags"];
|
|
9
|
+
set(featureFlags?: FronteggFeatureFlags): void;
|
|
10
|
+
}
|
|
2
11
|
export declare function loadFeatureFlags(): Promise<IFeatureFlagsAttributes>;
|
package/feature-flags/index.js
CHANGED
|
@@ -1,5 +1,44 @@
|
|
|
1
|
+
import _extends from "@babel/runtime/helpers/esm/extends";
|
|
1
2
|
import { urls } from "../constants";
|
|
2
3
|
import { Get } from "../fetch";
|
|
4
|
+
const defaultFeatureFlags = {
|
|
5
|
+
flags: {}
|
|
6
|
+
};
|
|
7
|
+
export class FeatureFlags {
|
|
8
|
+
constructor() {
|
|
9
|
+
this._flags = defaultFeatureFlags.flags;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
static getInstance(name = "default") {
|
|
13
|
+
return this._instances[name];
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
static set(featureFlags, name = "default") {
|
|
17
|
+
const featureFlagsInstance = new FeatureFlags();
|
|
18
|
+
featureFlagsInstance.set(featureFlags);
|
|
19
|
+
FeatureFlags._instances[name] = featureFlagsInstance;
|
|
20
|
+
return featureFlagsInstance;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
static getFeatureFlags(flags) {
|
|
24
|
+
const featureFlagsInstance = this.getInstance();
|
|
25
|
+
return flags.map(flag => (featureFlagsInstance == null ? void 0 : featureFlagsInstance._flags[flag]) === "on");
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
get flags() {
|
|
29
|
+
var _this$flags;
|
|
30
|
+
|
|
31
|
+
return (_this$flags = this.flags) != null ? _this$flags : {};
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
set(featureFlags) {
|
|
35
|
+
var _defaultFeatureFlags$, _featureFlags$flags;
|
|
36
|
+
|
|
37
|
+
this._flags = _extends({}, (_defaultFeatureFlags$ = defaultFeatureFlags == null ? void 0 : defaultFeatureFlags.flags) != null ? _defaultFeatureFlags$ : {}, (_featureFlags$flags = featureFlags == null ? void 0 : featureFlags.flags) != null ? _featureFlags$flags : {});
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
}
|
|
41
|
+
FeatureFlags._instances = {};
|
|
3
42
|
export async function loadFeatureFlags() {
|
|
4
43
|
return Get(urls.featureFlags.v1);
|
|
5
44
|
}
|
package/fetch.js
CHANGED
|
@@ -98,6 +98,17 @@ async function getAdditionalHeaders(context) {
|
|
|
98
98
|
output = await context.additionalHeadersResolver();
|
|
99
99
|
}
|
|
100
100
|
|
|
101
|
+
if (context.tenantResolver) {
|
|
102
|
+
const resolvedTenantResult = await context.tenantResolver();
|
|
103
|
+
|
|
104
|
+
if (!!(resolvedTenantResult != null && resolvedTenantResult.tenant)) {
|
|
105
|
+
output.push({
|
|
106
|
+
key: 'frontegg-login-alias',
|
|
107
|
+
value: resolvedTenantResult.tenant
|
|
108
|
+
});
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
|
|
101
112
|
return output;
|
|
102
113
|
}
|
|
103
114
|
|
package/index.js
CHANGED
package/interfaces.d.ts
CHANGED
|
@@ -17,11 +17,19 @@ export interface KeyValuePair {
|
|
|
17
17
|
key: string;
|
|
18
18
|
value: string;
|
|
19
19
|
}
|
|
20
|
+
export interface ResolvedTenantResult {
|
|
21
|
+
tenant: string | null;
|
|
22
|
+
}
|
|
20
23
|
export declare type LogLevel = 'warn' | 'error';
|
|
21
24
|
export interface ContextOptions {
|
|
22
25
|
baseUrl: string | ((url: string) => string);
|
|
23
26
|
clientId?: string;
|
|
24
27
|
tokenResolver?: () => Promise<string> | string;
|
|
28
|
+
/**
|
|
29
|
+
* custom login header value
|
|
30
|
+
* @returns `{ tenant: string | null }`
|
|
31
|
+
*/
|
|
32
|
+
tenantResolver?: () => Promise<ResolvedTenantResult> | ResolvedTenantResult;
|
|
25
33
|
additionalQueryParamsResolver?: () => Promise<KeyValuePair[]> | KeyValuePair[];
|
|
26
34
|
additionalHeadersResolver?: () => Promise<KeyValuePair[]> | KeyValuePair[];
|
|
27
35
|
currentUserRoles?: string[];
|
|
@@ -1,14 +1,61 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
|
|
3
5
|
Object.defineProperty(exports, "__esModule", {
|
|
4
6
|
value: true
|
|
5
7
|
});
|
|
8
|
+
exports.FeatureFlags = void 0;
|
|
6
9
|
exports.loadFeatureFlags = loadFeatureFlags;
|
|
7
10
|
|
|
11
|
+
var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
|
|
12
|
+
|
|
8
13
|
var _constants = require("../constants");
|
|
9
14
|
|
|
10
15
|
var _fetch = require("../fetch");
|
|
11
16
|
|
|
17
|
+
const defaultFeatureFlags = {
|
|
18
|
+
flags: {}
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
class FeatureFlags {
|
|
22
|
+
constructor() {
|
|
23
|
+
this._flags = defaultFeatureFlags.flags;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
static getInstance(name = "default") {
|
|
27
|
+
return this._instances[name];
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
static set(featureFlags, name = "default") {
|
|
31
|
+
const featureFlagsInstance = new FeatureFlags();
|
|
32
|
+
featureFlagsInstance.set(featureFlags);
|
|
33
|
+
FeatureFlags._instances[name] = featureFlagsInstance;
|
|
34
|
+
return featureFlagsInstance;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
static getFeatureFlags(flags) {
|
|
38
|
+
const featureFlagsInstance = this.getInstance();
|
|
39
|
+
return flags.map(flag => (featureFlagsInstance == null ? void 0 : featureFlagsInstance._flags[flag]) === "on");
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
get flags() {
|
|
43
|
+
var _this$flags;
|
|
44
|
+
|
|
45
|
+
return (_this$flags = this.flags) != null ? _this$flags : {};
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
set(featureFlags) {
|
|
49
|
+
var _defaultFeatureFlags$, _featureFlags$flags;
|
|
50
|
+
|
|
51
|
+
this._flags = (0, _extends2.default)({}, (_defaultFeatureFlags$ = defaultFeatureFlags == null ? void 0 : defaultFeatureFlags.flags) != null ? _defaultFeatureFlags$ : {}, (_featureFlags$flags = featureFlags == null ? void 0 : featureFlags.flags) != null ? _featureFlags$flags : {});
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
exports.FeatureFlags = FeatureFlags;
|
|
57
|
+
FeatureFlags._instances = {};
|
|
58
|
+
|
|
12
59
|
async function loadFeatureFlags() {
|
|
13
60
|
return (0, _fetch.Get)(_constants.urls.featureFlags.v1);
|
|
14
61
|
}
|
package/node/fetch.js
CHANGED
|
@@ -111,6 +111,17 @@ async function getAdditionalHeaders(context) {
|
|
|
111
111
|
output = await context.additionalHeadersResolver();
|
|
112
112
|
}
|
|
113
113
|
|
|
114
|
+
if (context.tenantResolver) {
|
|
115
|
+
const resolvedTenantResult = await context.tenantResolver();
|
|
116
|
+
|
|
117
|
+
if (!!(resolvedTenantResult != null && resolvedTenantResult.tenant)) {
|
|
118
|
+
output.push({
|
|
119
|
+
key: 'frontegg-login-alias',
|
|
120
|
+
value: resolvedTenantResult.tenant
|
|
121
|
+
});
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
|
|
114
125
|
return output;
|
|
115
126
|
}
|
|
116
127
|
|
package/node/index.js
CHANGED