fix(platform): use settings kill-switch route

This commit is contained in:
root 2026-05-05 22:14:41 +00:00
parent 5ba315fd02
commit 6ed75bff2a
3 changed files with 105 additions and 19 deletions

View File

@ -1,16 +1,45 @@
import { createKillSwitchClient } from '@bytelyst/kill-switch-client';
import { createWebTelemetry } from '@bytelyst/telemetry-client'; import { createWebTelemetry } from '@bytelyst/telemetry-client';
import { createRNPlatformSDK } from '@bytelyst/react-native-platform-sdk'; import { createRNPlatformSDK } from '@bytelyst/react-native-platform-sdk';
import { getRuntimeEnvironment } from './runtime.js'; import { getRuntimeEnvironment } from './runtime.js';
import { productConfig } from './product.js'; import { productConfig } from './product.js';
import { createRequestId } from './request-id.js';
interface TradingKillSwitchResult {
disabled: boolean;
message: string | null;
}
function createRepoKillSwitchClient(baseUrl: string, productId: string, platform: 'web' | 'mobile') {
return {
async check(): Promise<TradingKillSwitchResult> {
try {
const response = await globalThis.fetch(
`${baseUrl}/settings/kill-switch?platform=${encodeURIComponent(platform)}`,
{
headers: {
'x-product-id': productId,
'x-request-id': createRequestId('kill-switch'),
},
}
);
if (!response.ok) return { disabled: false, message: null };
const data = await response.json() as { disabled?: boolean; message?: string | null };
return {
disabled: data.disabled ?? false,
message: data.message ?? null,
};
} catch {
return { disabled: false, message: null };
}
},
};
}
export function createTradingKillSwitchClient(platform: 'web' | 'mobile') { export function createTradingKillSwitchClient(platform: 'web' | 'mobile') {
const runtime = getRuntimeEnvironment(platform); const runtime = getRuntimeEnvironment(platform);
return createKillSwitchClient({ return createRepoKillSwitchClient(runtime.platformApiUrl, runtime.productId, platform);
baseUrl: runtime.platformApiUrl,
productId: runtime.productId,
platform,
});
} }
export function createTradingWebTelemetry() { export function createTradingWebTelemetry() {
@ -32,4 +61,3 @@ export function createTradingMobileSdk(getAccessToken: () => string | null) {
getAccessToken, getAccessToken,
}); });
} }

View File

@ -1,14 +1,43 @@
import { createKillSwitchClient } from '@bytelyst/kill-switch-client';
import { createRNPlatformSDK } from '@bytelyst/react-native-platform-sdk'; import { createRNPlatformSDK } from '@bytelyst/react-native-platform-sdk';
import { getRuntimeEnvironment } from './runtime.js'; import { getRuntimeEnvironment } from './runtime.js';
import { createRequestId } from './request-id.js';
interface TradingKillSwitchResult {
disabled: boolean;
message: string | null;
}
function createRepoKillSwitchClient(baseUrl: string, productId: string, platform: 'web' | 'mobile') {
return {
async check(): Promise<TradingKillSwitchResult> {
try {
const response = await globalThis.fetch(
`${baseUrl}/settings/kill-switch?platform=${encodeURIComponent(platform)}`,
{
headers: {
'x-product-id': productId,
'x-request-id': createRequestId('kill-switch'),
},
}
);
if (!response.ok) return { disabled: false, message: null };
const data = await response.json() as { disabled?: boolean; message?: string | null };
return {
disabled: data.disabled ?? false,
message: data.message ?? null,
};
} catch {
return { disabled: false, message: null };
}
},
};
}
export function createTradingKillSwitchClient(platform: 'web' | 'mobile') { export function createTradingKillSwitchClient(platform: 'web' | 'mobile') {
const runtime = getRuntimeEnvironment(platform); const runtime = getRuntimeEnvironment(platform);
return createKillSwitchClient({ return createRepoKillSwitchClient(runtime.platformApiUrl, runtime.productId, platform);
baseUrl: runtime.platformApiUrl,
productId: runtime.productId,
platform,
});
} }
export function createTradingMobileSdk(getAccessToken: () => string | null) { export function createTradingMobileSdk(getAccessToken: () => string | null) {

View File

@ -1,15 +1,44 @@
import { createKillSwitchClient } from '@bytelyst/kill-switch-client';
import { createWebTelemetry } from '@bytelyst/telemetry-client'; import { createWebTelemetry } from '@bytelyst/telemetry-client';
import { getRuntimeEnvironment } from './runtime.js'; import { getRuntimeEnvironment } from './runtime.js';
import { productConfig } from './product.js'; import { productConfig } from './product.js';
import { createRequestId } from './request-id.js';
interface TradingKillSwitchResult {
disabled: boolean;
message: string | null;
}
function createRepoKillSwitchClient(baseUrl: string, productId: string, platform: 'web' | 'mobile') {
return {
async check(): Promise<TradingKillSwitchResult> {
try {
const response = await globalThis.fetch(
`${baseUrl}/settings/kill-switch?platform=${encodeURIComponent(platform)}`,
{
headers: {
'x-product-id': productId,
'x-request-id': createRequestId('kill-switch'),
},
}
);
if (!response.ok) return { disabled: false, message: null };
const data = await response.json() as { disabled?: boolean; message?: string | null };
return {
disabled: data.disabled ?? false,
message: data.message ?? null,
};
} catch {
return { disabled: false, message: null };
}
},
};
}
export function createTradingKillSwitchClient(platform: 'web' | 'mobile') { export function createTradingKillSwitchClient(platform: 'web' | 'mobile') {
const runtime = getRuntimeEnvironment(platform); const runtime = getRuntimeEnvironment(platform);
return createKillSwitchClient({ return createRepoKillSwitchClient(runtime.platformApiUrl, runtime.productId, platform);
baseUrl: runtime.platformApiUrl,
productId: runtime.productId,
platform,
});
} }
export function createTradingWebTelemetry() { export function createTradingWebTelemetry() {