@spritz-finance/service-client 0.3.39 → 0.3.41
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.
|
@@ -1,5 +1,15 @@
|
|
|
1
1
|
export * as FeaturesClient from './featuresServiceClient';
|
|
2
|
+
import { ApiResponse } from '../types';
|
|
2
3
|
import { FeatureFlag, FeatureFlags } from './types';
|
|
4
|
+
export declare function updateFeatureFlag(input: {
|
|
5
|
+
key: FeatureFlag;
|
|
6
|
+
value: boolean;
|
|
7
|
+
}): Promise<import("axios").AxiosResponse<ApiResponse<boolean>, any>>;
|
|
3
8
|
export declare function getFeatureFlags(): Promise<import("../types").ApiFailure | import("../types").ApiSuccess<FeatureFlags>>;
|
|
4
9
|
export declare function isFeatureFlagEnabled(flag: FeatureFlag): Promise<boolean>;
|
|
5
|
-
export declare function isPaymentsEnabled(network?: string): Promise<boolean>;
|
|
10
|
+
export declare function isPaymentsEnabled(network?: string, allFlags?: FeatureFlags): Promise<boolean>;
|
|
11
|
+
/**
|
|
12
|
+
* Synchronously checks if a feature flag is enabled from a provided flags object.
|
|
13
|
+
* Use this when you already have the flags and want to avoid refetching them.
|
|
14
|
+
*/
|
|
15
|
+
export declare function isFeatureEnabled(flag: FeatureFlag, allFlags?: FeatureFlags): Promise<boolean>;
|
|
@@ -23,7 +23,7 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
23
23
|
return result;
|
|
24
24
|
};
|
|
25
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
-
exports.isPaymentsEnabled = exports.isFeatureFlagEnabled = exports.getFeatureFlags = exports.FeaturesClient = void 0;
|
|
26
|
+
exports.isFeatureEnabled = exports.isPaymentsEnabled = exports.isFeatureFlagEnabled = exports.getFeatureFlags = exports.updateFeatureFlag = exports.FeaturesClient = void 0;
|
|
27
27
|
exports.FeaturesClient = __importStar(require("./featuresServiceClient"));
|
|
28
28
|
const serviceClient_1 = require("../serviceClient");
|
|
29
29
|
const utils_1 = require("../utils");
|
|
@@ -53,10 +53,16 @@ const networkToFlag = (network) => {
|
|
|
53
53
|
return types_1.FeatureFlag.BtcPayments;
|
|
54
54
|
case 'dash':
|
|
55
55
|
return types_1.FeatureFlag.DashPayments;
|
|
56
|
+
case 'sui':
|
|
57
|
+
return types_1.FeatureFlag.SuiPayments;
|
|
56
58
|
default:
|
|
57
59
|
return null;
|
|
58
60
|
}
|
|
59
61
|
};
|
|
62
|
+
function updateFeatureFlag(input) {
|
|
63
|
+
return serviceClient_1.baseClient.post(`${FEATURES_ENDPOINT}/feature-flags`, input);
|
|
64
|
+
}
|
|
65
|
+
exports.updateFeatureFlag = updateFeatureFlag;
|
|
60
66
|
async function getFeatureFlags() {
|
|
61
67
|
return serviceClient_1.baseClient
|
|
62
68
|
.get(`${FEATURES_ENDPOINT}/feature-flags`)
|
|
@@ -72,17 +78,35 @@ async function isFeatureFlagEnabled(flag) {
|
|
|
72
78
|
return (_b = (_a = flags[flag]) === null || _a === void 0 ? void 0 : _a.value) !== null && _b !== void 0 ? _b : false;
|
|
73
79
|
}
|
|
74
80
|
exports.isFeatureFlagEnabled = isFeatureFlagEnabled;
|
|
75
|
-
async function
|
|
76
|
-
var _a, _b, _c;
|
|
81
|
+
async function getFlags() {
|
|
77
82
|
const response = await getFeatureFlags();
|
|
78
83
|
if ((0, utils_1.isApiError)(response))
|
|
84
|
+
return null;
|
|
85
|
+
return response.data;
|
|
86
|
+
}
|
|
87
|
+
async function isPaymentsEnabled(network, allFlags) {
|
|
88
|
+
var _a, _b, _c;
|
|
89
|
+
const flags = allFlags !== null && allFlags !== void 0 ? allFlags : (await getFlags());
|
|
90
|
+
if (!flags)
|
|
79
91
|
return false;
|
|
80
|
-
const flags = response.data;
|
|
81
92
|
if (!((_a = flags[types_1.FeatureFlag.PaymentsEnabled]) === null || _a === void 0 ? void 0 : _a.value))
|
|
82
93
|
return false;
|
|
83
94
|
if (!network)
|
|
84
95
|
return true;
|
|
85
96
|
const networkFlag = networkToFlag(network);
|
|
97
|
+
// this will default to true if we have not handled the network yet
|
|
86
98
|
return networkFlag ? (_c = (_b = flags[networkFlag]) === null || _b === void 0 ? void 0 : _b.value) !== null && _c !== void 0 ? _c : true : true;
|
|
87
99
|
}
|
|
88
100
|
exports.isPaymentsEnabled = isPaymentsEnabled;
|
|
101
|
+
/**
|
|
102
|
+
* Synchronously checks if a feature flag is enabled from a provided flags object.
|
|
103
|
+
* Use this when you already have the flags and want to avoid refetching them.
|
|
104
|
+
*/
|
|
105
|
+
async function isFeatureEnabled(flag, allFlags) {
|
|
106
|
+
var _a, _b;
|
|
107
|
+
const flags = allFlags !== null && allFlags !== void 0 ? allFlags : (await getFlags());
|
|
108
|
+
if (!flags)
|
|
109
|
+
return false;
|
|
110
|
+
return (_b = (_a = flags[flag]) === null || _a === void 0 ? void 0 : _a.value) !== null && _b !== void 0 ? _b : false;
|
|
111
|
+
}
|
|
112
|
+
exports.isFeatureEnabled = isFeatureEnabled;
|
package/lib/features/types.d.ts
CHANGED
|
@@ -20,6 +20,8 @@ export declare enum FeatureFlag {
|
|
|
20
20
|
TronPayments = "payments.network.tron",
|
|
21
21
|
BtcPayments = "payments.network.bitcoin",
|
|
22
22
|
DashPayments = "payments.network.dash",
|
|
23
|
+
SuiPayments = "payments.network.sui",
|
|
24
|
+
SuiMUSDPayments = "payments.token.sui.musd",
|
|
23
25
|
SpritzCardNoKycEnabled = "spritzCard.noKyc.enabled",
|
|
24
26
|
SpritzCardNoKycPayments = "spritzCard.noKyc.payments",
|
|
25
27
|
BinanceBridgeEnabled = "binanceBridge.enabled"
|
package/lib/features/types.js
CHANGED
|
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.FeatureFlag = void 0;
|
|
4
4
|
var FeatureFlag;
|
|
5
5
|
(function (FeatureFlag) {
|
|
6
|
+
// Payments
|
|
6
7
|
FeatureFlag["PaymentsEnabled"] = "payments.enabled";
|
|
7
8
|
FeatureFlag["EthereumPayments"] = "payments.network.ethereum";
|
|
8
9
|
FeatureFlag["PolygonPayments"] = "payments.network.polygon";
|
|
@@ -15,7 +16,12 @@ var FeatureFlag;
|
|
|
15
16
|
FeatureFlag["TronPayments"] = "payments.network.tron";
|
|
16
17
|
FeatureFlag["BtcPayments"] = "payments.network.bitcoin";
|
|
17
18
|
FeatureFlag["DashPayments"] = "payments.network.dash";
|
|
19
|
+
FeatureFlag["SuiPayments"] = "payments.network.sui";
|
|
20
|
+
// Token Specific
|
|
21
|
+
FeatureFlag["SuiMUSDPayments"] = "payments.token.sui.musd";
|
|
22
|
+
// Features
|
|
18
23
|
FeatureFlag["SpritzCardNoKycEnabled"] = "spritzCard.noKyc.enabled";
|
|
19
24
|
FeatureFlag["SpritzCardNoKycPayments"] = "spritzCard.noKyc.payments";
|
|
25
|
+
// Operations
|
|
20
26
|
FeatureFlag["BinanceBridgeEnabled"] = "binanceBridge.enabled";
|
|
21
27
|
})(FeatureFlag || (exports.FeatureFlag = FeatureFlag = {}));
|