Skip to main content

SDK 1.0.0

Quick start

This page takes you from zero to a mini app that talks to the i-Catholic app. You need a web project that uses a bundler (Vite, esbuild, ...) and Node. The SDK has no runtime dependencies and ships as ESM only. The root package never imports React, so Vue, Svelte or plain JavaScript all work; you need React 18 or later only if you want the hooks.

Three things to remember before you read the example below:

  1. getSDK() returns null outside the app (in a desktop browser). Always check for null before every call, or use the mock bridge during development.
  2. Call sdk.ready() as soon as your first screen has rendered, so the app removes its loading screen. After 15 seconds, the app shows Mini app took too long to load.
  3. Permissions are requested per mini app; always handle PERMISSION_DENIED (Lifecycle and permissions).
npm install @i-catholic/mini-app-sdk
EntryContentsNeeds React
@i-catholic/mini-app-sdktypes, getSDK, events, errors, earnPoints, scanQr, parseICatholicQrno
@i-catholic/mini-app-sdk/reactuseSDK, useTheme, useUser, usePoints, useSafeAreayes (>= 18, optional peer)

The root entry never imports React. Vanilla JS, Vue, Svelte or any other stack can use it without installing React.

The package has no runtime dependencies and ships ESM only.

Quick start​

import { getSDK, getSDKErrorCode, whenNativeReady } from '@i-catholic/mini-app-sdk'

// 1. Subscribe to the launch event as early as possible (module top level).
const ready = whenNativeReady().catch(() => null) // rejects outside the app

const sdk = getSDK() // null outside the i-Catholic app — guard every call

async function main() {
renderApp()

if (!sdk) return // running in a desktop browser: show a fallback, or use a mock (see below)

// 2. Tell the host your first screen is painted, so it removes its loading overlay.
sdk.ready()

// 3. Use the bridge.
try {
const user = await sdk.getUser() // asks the user for `user.profile` the first time
sdk.showToast({ title: `Xin chào ${user?.name ?? ''}`, action: 'success' })
} catch (e) {
if (getSDKErrorCode(e) === 'PERMISSION_DENIED') {
// the user refused — carry on without the profile
}
}

// 4. Opened from a share link? Route to it.
const launch = await ready
if (launch?.deepLinkPath) openRoute(launch.deepLinkPath)
}

main()