fix(platform): use settings kill-switch route
This commit is contained in:
parent
5ba315fd02
commit
6ed75bff2a
@ -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,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -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) {
|
||||||
|
|||||||
@ -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() {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user