mirror of
https://github.com/PR0M3TH3AN/bitvid.git
synced 2026-10-27 07:52:24 +00:00
Enforce platform override when Lightning fees are enabled
This commit is contained in:
1 parent
287d954823
commit
e6b465ccca
4 files changed
+81
-19
No files matched your search
+50
-14
@@ -3,16 +3,20 @@
|
||||
// Runtime validation helpers for instance-level configuration
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
import { ADMIN_SUPER_NPUB, PLATFORM_FEE_PERCENT } from "./instance-config.js";
|
||||
import {
|
||||
ADMIN_SUPER_NPUB,
|
||||
PLATFORM_FEE_PERCENT,
|
||||
PLATFORM_LUD16_OVERRIDE,
|
||||
} from "./instance-config.js";
|
||||
|
||||
function assertSuperAdminConfigured() {
|
||||
if (typeof ADMIN_SUPER_NPUB !== "string") {
|
||||
function assertSuperAdminConfigured(value) {
|
||||
if (typeof value !== "string") {
|
||||
throw new Error(
|
||||
"ADMIN_SUPER_NPUB must be a string exported from config/instance-config.js."
|
||||
);
|
||||
}
|
||||
|
||||
const trimmed = ADMIN_SUPER_NPUB.trim();
|
||||
const trimmed = value.trim();
|
||||
if (!trimmed) {
|
||||
throw new Error(
|
||||
"ADMIN_SUPER_NPUB is required. Populate it with the Super Admin npub in config/instance-config.js."
|
||||
@@ -24,26 +28,58 @@ function assertSuperAdminConfigured() {
|
||||
"ADMIN_SUPER_NPUB should be a bech32 npub (e.g., starting with 'npub')."
|
||||
);
|
||||
}
|
||||
return trimmed;
|
||||
}
|
||||
|
||||
function assertPlatformFeeInRange() {
|
||||
const value =
|
||||
typeof PLATFORM_FEE_PERCENT === "number"
|
||||
? PLATFORM_FEE_PERCENT
|
||||
: Number.parseFloat(PLATFORM_FEE_PERCENT);
|
||||
function assertPlatformFeeInRange(value) {
|
||||
const numericValue =
|
||||
typeof value === "number" ? value : Number.parseFloat(value);
|
||||
|
||||
if (!Number.isFinite(value)) {
|
||||
if (!Number.isFinite(numericValue)) {
|
||||
throw new Error(
|
||||
"PLATFORM_FEE_PERCENT must be a finite number between 0 and 100."
|
||||
);
|
||||
}
|
||||
|
||||
if (value < 0 || value > 100) {
|
||||
if (numericValue < 0 || numericValue > 100) {
|
||||
throw new Error("PLATFORM_FEE_PERCENT must be between 0 and 100 inclusive.");
|
||||
}
|
||||
|
||||
return numericValue;
|
||||
}
|
||||
|
||||
export function validateInstanceConfig() {
|
||||
assertSuperAdminConfigured();
|
||||
assertPlatformFeeInRange();
|
||||
function getPlatformLud16Override(value) {
|
||||
if (typeof value !== "string") {
|
||||
return "";
|
||||
}
|
||||
|
||||
return value.trim();
|
||||
}
|
||||
|
||||
function resolveConfig(overrides = {}) {
|
||||
return {
|
||||
adminSuperNpub:
|
||||
overrides.ADMIN_SUPER_NPUB ?? ADMIN_SUPER_NPUB,
|
||||
platformFeePercent:
|
||||
overrides.PLATFORM_FEE_PERCENT ?? PLATFORM_FEE_PERCENT,
|
||||
platformLud16Override:
|
||||
overrides.PLATFORM_LUD16_OVERRIDE ?? PLATFORM_LUD16_OVERRIDE,
|
||||
};
|
||||
}
|
||||
|
||||
export function validateInstanceConfig(overrides) {
|
||||
const config = resolveConfig(overrides);
|
||||
assertSuperAdminConfigured(config.adminSuperNpub);
|
||||
const platformFeePercent = assertPlatformFeeInRange(
|
||||
config.platformFeePercent
|
||||
);
|
||||
const trimmedOverride = getPlatformLud16Override(
|
||||
config.platformLud16Override
|
||||
);
|
||||
|
||||
if (platformFeePercent > 0 && !trimmedOverride) {
|
||||
throw new Error(
|
||||
"PLATFORM_FEE_PERCENT is positive but PLATFORM_LUD16_OVERRIDE is empty. Set PLATFORM_LUD16_OVERRIDE to the Lightning address that should receive the platform's split, or publish a lud16 value on the Super Admin profile so BitVid can route platform fees."
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user