Files
sendico/frontend/pshared/lib/config/web.dart
2025-12-09 21:02:37 +03:00

82 lines
3.0 KiB
Dart
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import 'dart:ui';
import 'dart:js_interop';
import 'package:pshared/config/common.dart';
/// Bind to the global JS `appConfig` (if it exists).
@JS()
external AppConfig? get appConfig;
/// A staticInterop class for the JS object returned by `appConfig`.
@JS()
@staticInterop
class AppConfig {}
/// Extension methods to expose each property on `AppConfig`.
extension AppConfigExtension on AppConfig {
external String? get apiProto;
external String? get apiHost;
external String? get apiEndpoint;
external String? get amplitudeSecret;
external String? get amplitudeServerZone;
external String? get posthogApiKey;
external String? get posthogHost;
external String? get defaultLocale;
external String? get wsProto;
external String? get wsEndpoint;
external int? get defaultDimensionLength;
external String? get themeColor;
external String? get clientId;
}
class Constants extends CommonConstants {
static const String _clientIdWeb = 'com.profee.pay.web-4b6e8a0f-9b5c-4f57-b3a6-3c456e9bb2cd';
// Just re-expose these from CommonConstants:
static Locale get defaultLocale => CommonConstants.defaultLocale;
static String get clientId => _clientIdWeb;
static String get accessTokenStorageKey => CommonConstants.accessTokenStorageKey;
static String get refreshTokenStorageKey => CommonConstants.refreshTokenStorageKey;
static String get currentOrgKey => CommonConstants.currentOrgKey;
static String get apiUrl => CommonConstants.apiUrl;
static String get serviceUrl => CommonConstants.serviceUrl;
static String get posthogApiKey => CommonConstants.posthogApiKey;
static String get posthogHost => CommonConstants.posthogHost;
static int get defaultDimensionLength => CommonConstants.defaultDimensionLength;
static String get deviceIdStorageKey => CommonConstants.deviceIdStorageKey;
static String get nilObjectRef => CommonConstants.nilObjectRef;
static Color get themeColor => CommonConstants.themeColor;
static Future<void> initialize() async {
// Try to grab the JS `appConfig` if it exists:
final config = appConfig;
if (config != null) {
// Build a Dart Map from the JS objects properties:
final configJson = <String, dynamic>{
'apiProto': config.apiProto,
'apiHost': config.apiHost,
'apiEndpoint': config.apiEndpoint,
'amplitudeSecret': config.amplitudeSecret,
'amplitudeServerZone': config.amplitudeServerZone,
'posthogApiKey': config.posthogApiKey,
'posthogHost': config.posthogHost,
'defaultLocale': config.defaultLocale,
'wsProto': config.wsProto,
'wsEndpoint': config.wsEndpoint,
'defaultDimensionLength': config.defaultDimensionLength,
'themeColor': config.themeColor,
// If the JS side didnt supply a clientId, fall back to our Dart constant
'clientId': config.clientId ?? _clientIdWeb,
};
CommonConstants.applyConfiguration(configJson);
} else {
// No appConfig on JS side → just use the default Dart client ID.
CommonConstants.clientId = _clientIdWeb;
}
}
}