Detect features

Check whether a feature is switched on in this app build before you show its UI.

Check one feature

Ask whether this build has a feature switched on. has is true only then — the right check before you show the UI.

import { createBdkNative } from "@thebdk/native/browser";

const bdk = createBdkNative();

if (await bdk.capabilities.has("media")) {
  showPhotoPicker();
}

Read the full map

Read every feature this build reports — enabled, available, and config per id — plus platform and the app version. Pass timeoutMs to wait that many milliseconds. get resolves null when the answer isn't known: a plain browser, an older app build, or a slow start. null is not off.

Don't treat null as off. Wait for bdk.ready() and call get again.

let caps = await bdk.capabilities.get();

if (!caps) {
  await bdk.ready(3000);
  caps = await bdk.capabilities.get();
}

if (!caps) {
  // Still unknown — not off.
} else {
  const media = caps.features.media;
  console.log(caps.platform, caps.app?.versionName, media);
}

Interpret the states

enabled, available, and a null map are three different answers.

  • Missing from features, or enabled is not true — not in this build. Hide the UI.
  • enabled is true and available is false — in this build, but unusable on this device right now.
  • get() returned null — unknown. Don't treat it as off. Wait for bdk.ready() and try again.

When a feature is off

Legacy commands return NativeCommandResult; use !result.triggered and subscribe before calls whose data arrives on events. A browser tab returns pending, while a runtime without window returns skipped. Envelope helpers return { ok: true, ... } or { ok: false, code, message }; use isBdkError(result) or !result.ok, not triggered. New iap.* and health.* helpers can also return a bare command result: check "ok" in result first. Read each helper’s result type; do not apply one check to all methods.

Return from the action or render the web path when the capability is unavailable. Do not continue into the native call.

async function pickPhotos() {
  const result = await bdk.media.pickPhotos();

  if (!result.ok) {
    if (result.code === "common/feature_disabled") {
      // This build doesn't have it.
      return;
    }
    console.error(result.code, result.message);
    return;
  }
}
// Call pickPhotos() from the photo action.