Skip to content

Environment and configuration

Get current runtime environment information.

const env = await SuperSDK.getEnv();
console.log(env);
// {
// webviewId: "a1b2c3d4",
// versionName: "1.0.0",
// versionCode: 1010203,
// channel: "local_test",
// spid: "ab12cd34", // Replace with the real spid issued by the console
// environment: "prod",
// deviceId: "xxx-xxx-xxx",
// platform: "android",
// osVersion: "14",
// deviceModel: "Pixel 8",
// wappVersion: "1.0.0", // Current WApp (offline package) version; non-offline package pages are ""
// wappBuildTime: 1740198896 // Offline package build time (second-level timestamp), 0 for non-offline package pages
// }

setAPIEnvironment(environment) / getAPIEnvironment()

Section titled “setAPIEnvironment(environment) / getAPIEnvironment()”

The project environment corresponds to the env in the top bar of the console (e.g., prod / staging), which determines the environment for pulling settings and reporting analytics.

// Web fallback mode: Switch project environment at runtime (initFallback must be called first).
await SuperSDK.setAPIEnvironment('staging');
// After switching, the env parameter in the getHostSettings request and the reportEvent
// Both basic_data.env and the X-Super-API-ENV header use the new value;
// Settings request cache is isolated by environment; switching back to the old environment restores the original cache.
// Read the current project environment (Promise<string>; resolve "prod" when the web is uninitialized)
const env = await SuperSDK.getAPIEnvironment();

Rules:

  • Value must be 1–10 lowercase letters or digits (^[a-z0-9]{1,10}$). Invalid values are rejected with INVALID_ARGUMENT and the state remains unchanged. If initFallback has not been called in the web environment, set is rejected with NOT_INITIALIZED.
  • Before switching, it will attempt to flush pending tracking events in the old environment, then update the value.
  • In-app (App Internal): setAPIEnvironment always rejects UNSUPPORTED — the in-app environment is controlled by the native host app via SuperSDK.setAPIEnvironment (Android) / SuperSDKManager.setAPIEnvironment (iOS); getAPIEnvironment passes through the current native value via getEnv.
  • The environment field of initFallback(config) remains the initial environment for web mode.

Get the host app name.

const appName = await SuperSDK.getAppName();
// "MyApp"

Get the host app icon (Base64 format).

const iconBase64 = await SuperSDK.getAppIcon();
// "data:image/png;base64,iVBOR..."
// Can be directly used in <img src="...">

Retrieve host app configuration information. configName is the configuration name; if not provided, the request sent to the client will not include the configName parameter.

const hostSettings = await SuperSDK.getHostSettings();
const featureSettings = await SuperSDK.getHostSettings('feature_flags');
// { code: 'SUCCESS', msg: '', data: { ... } } is consistent with the server-side settings response format.

Parameter: configName (string, optional) — Configuration name; if not provided, the request will not include the configName parameter. Return value: Promise<Object> — the host app’s cloud control response object. On success, it returns { code, msg, data }, where data contains the configuration content. In non-end environments, it resolves to an empty object {} and never rejects.

Retrieve host-specific configuration by key.

const config = await SuperSDK.getHostSettingsByKey('feature_flags');
const config = await SuperSDK.getHostSettingsByKey('enabled', 'feature_flags');

Parameter: key (string) — The key of the configuration item. Parameter: configName (string, optional) — Configuration name; if not provided, the request will not include the configName parameter. Return value: Promise<*> — the host app configuration value corresponding to this key; the client-side first checks the response root object, and if not found, falls back to checking data[key]. In non-client environments, it resolves to null.