@thebdk/native
v0.1.3
Published
Platform-agnostic JavaScript SDK for BDK Native apps.
Readme
@thebdk/native
JavaScript/TypeScript SDK for using BDK Native app features from browser apps and Node.js backends.
Full docs: https://docs.thebdk.com
Install
npm install @thebdk/nativeBrowser Quick Start
import { createBdkNative } from "@thebdk/native/browser";
const bdk = createBdkNative();
await bdk.ready(3000);
await bdk.ui.showBanner({
title: "Saved",
description: "Your changes were saved."
});
await bdk.navigation.openLink({
link: "https://example.com/account",
view: "website"
});
await bdk.media.capturePhoto();
await bdk.media.pickPhotos({ limit: 5 });
await bdk.location.getCurrentPosition();
await bdk.permissions.ask("camera");
await bdk.share.text({ text_content: "Hello from BDK Native" });
await bdk.share.files(["https://example.com/report.pdf"]);Browser Events
bdk.on("deviceInfo", (deviceInfo) => {
console.log(deviceInfo.deviceOS, deviceInfo.bdkRelease);
});
bdk.on("photoCaptured", (photo) => {
console.log(photo.fileUrl, photo.contentType);
});
bdk.on("purchaseSuccess", (purchase) => {
console.log(purchase.platform, purchase.data);
});Namespaced Helpers
await bdk.app.removeLoading();
await bdk.ui.showAlert({ title: "Heads up", description: "Please try again." });
await bdk.navigation.openLink({ link: "https://example.com", view: "website" });
await bdk.media.pickPhoto();
await bdk.media.scanBarcode();
bdk.deeplink.onReceived((link) => console.log(link.id, link.form));
await bdk.location.getLocation();
await bdk.permissions.ask("location");
await bdk.auth.authenticateBiometrics();
await bdk.auth.signIn({ url: authorizeUrl });
await bdk.iap.purchaseIos({ id: "pro_monthly", type: "subscription" });
await bdk.iap.purchaseAndroid({ id: "pro_monthly", type: "subscription" });
const products = await bdk.iap.products(["pro_monthly"]);
const firstOutcome = await bdk.iap.purchaseAndWait({ id: "pro_monthly" });
await bdk.share.image("https://example.com/image.png");
await bdk.share.send({ items: [{ type: "text", text: "Hello" }] });
await bdk.notifications.status();
await bdk.push.getDataMessages();
bdk.share.onReceived((share) => console.log(share.shareId));
await bdk.health.read({ type: "steps" });
await bdk.nfc.read();
await bdk.device.vibrate();Server Quick Start
import { sendPushNotification } from "@thebdk/native/server/onesignal";
await sendPushNotification({
title: "New message",
message: "You have a new update.",
playerIds: ["player-id"]
});import { verifyIosReceipt, verifyAndroidReceipt } from "@thebdk/native/server/iap";
await verifyIosReceipt({
receipt: "base64-receipt"
});
await verifyAndroidReceipt({
packageName: "com.example.app",
productId: "pro_monthly",
purchaseToken: "purchase-token",
productType: "subscription"
});Import Entry Points
import { createBdkNative } from "@thebdk/native";
import { createBdkNative as createBrowserBdkNative } from "@thebdk/native/browser";
import { sendPushNotification } from "@thebdk/native/server/onesignal";
import { verifyIosReceipt, verifyAndroidReceipt } from "@thebdk/native/server/iap";
import { createBranchLink } from "@thebdk/native/server/branch";
import { createChottuLink } from "@thebdk/native/server/chottulink";
import { createFirebaseDynamicLink } from "@thebdk/native/server/firebase-dynamic-links";The combined server entry point is also available:
import {
sendPushNotification,
verifyIosReceipt,
verifyAndroidReceipt
} from "@thebdk/native/server";CDN
<script src="https://cdn.jsdelivr.net/npm/@thebdk/native/dist/cdn/bdk-native.global.js"></script>
<script>
const bdk = BdkNative.createBdkNative();
</script>