Skip to main content
Version: v2

Migrate to v2

This guide lists the changes you need to make in your web app to move from v1 to v2 of the Web SDK.

The SDK no longer creates transactions: your backend does, and passes the result to your app. Before you update the SDK, update your backend as described in the Platform migration guide, in particular No proxy and Consent.

Installation, imports, dependencies​

Package installation​

The package name is unchanged: @microblink/platform-sdk, and you can still get it from NPM. Update it to v2:

npm install @microblink/platform-sdk@2

Changed import statements​

Vanilla JS
// v1
import { createIdvFlow } from '@microblink/platform-sdk/vanilla';

// v2
import { createPlatformSdk } from '@microblink/platform-sdk';
// note: no more "vanilla" in import statement
React
// v1
import { IdvFlow } from '@microblink/platform-sdk/react';

// v2
import { usePlatformSdk, PlatformFlowUI } from '@microblink/platform-sdk/react';

Fewer dependencies​

In v1, the SDK required react, react-dom, and styled-components as peer dependencies, even if you integrated with vanilla JS. In v2, it has no required peer dependencies; you only need react (version 18 or later) if you use the React entry point, and vite (version 5 or later) if you use the Vite plugin. If you integrate with vanilla JS, you can remove react, react-dom, and styled-components from your dependencies, unless your app needs them for other reasons.

Starting a verification​

In v1, the SDK created the transaction itself: you gave it a proxy URL, a workflow ID, and the end user's consent. In v2, your backend creates the transaction and gets back sdkConfiguration. You pass that value to the SDK as sessionToken, and that's the only required configuration field.

Vanilla JS
// Your own endpoint that calls POST /api/v2/transaction and returns sdkConfiguration.
const response = await fetch('/start-verification', { method: 'POST' });
const { sdkConfiguration } = await response.json();

const sdk = createPlatformSdk({
sessionToken: sdkConfiguration,
target: document.getElementById('idv-flow-div'),
});

sdk.onTransactionEnd((result) => {
console.log(result.transactionId, result.verificationStatus);
});

sdk.onAbort((info) => {
console.log('User aborted the flow on step', info.step);
});

In React, the IdvFlow component is replaced by the usePlatformSdk hook, which owns the session, and the PlatformFlowUI component, which renders our screens:

React
// sessionToken is the sdkConfiguration your backend returned.
function Verification({ sessionToken }) {
const sdk = usePlatformSdk({ sessionToken });

useEffect(() => {
if (sdk.currentStep === 'END' && sdk.state.verificationStatus) {
console.log(sdk.state.transactionId, sdk.state.verificationStatus);
}
}, [sdk.currentStep, sdk.state.verificationStatus]);

return <PlatformFlowUI config={sdk} />;
}

You pass your configuration to usePlatformSdk, and place PlatformFlowUI where the flow should appear. The hook reads its configuration only once, so render this component after you have the session token. React has no result callbacks; read the outcome from sdk.state instead.

Configuration fields​

The v2 configuration object has only these fields: sessionToken, runAddress, target, translations, theme, and resourcesPath. The same object is used by createPlatformSdk and usePlatformSdk.

v2 configuration object
{
sessionToken: '...',
runAddress: '...',
target: element,
resourcesPath: '/',
theme: {},
translations: {},
}

Here's what happened to v1 fields.

  • apiConfig is replaced by sessionToken. v1 had two formats (one for new transactions, one for resuming existing ones); v2 has only one, because your backend always creates the transaction first.
  • consentData is removed. The SDK no longer asks for consent: collect it in your app before the verification starts, and your backend sends it when it creates the transaction.
  • mode and enableD2D are removed. Device-to-device flows are configured in the Platform UI for the workflow, and this information comes to the SDK in the session token.
  • Related to the above, apiConfig.d2d.runAddress moves to the top-level runAddress field. Set it only if you host the D2D phone app yourself; if you omit it, and device-to-device is enabled for the transaction, the join link points to the Microblink-hosted page.

Visuals and translations​

  • themeOverride is renamed to theme, and has internal changes.
  • translationsOverride is renamed to translations, and has internal changes.

Callbacks​

  • onTransactionFinished, onAbort, and onError are no longer configuration fields. Instead, you subscribe to them on the SDK instance with sdk.onTransactionEnd(), sdk.onAbort(), and sdk.onError(). The result's status is renamed to verificationStatus.
  • onExit, already deprecated in v1, is removed.
  • startScreen, progressScreen, and endResultScreen are removed. You can now replace the screen for most steps, such as PROGRESS_OVERVIEW and END, with sdk.onStep() (vanilla JS), or by checking sdk.currentStep before rendering PlatformFlowUI (React). startScreen has no replacement, because v2 has no start screen. Camera steps can't be replaced.
  • onCardScanResult and scanTimeout are removed.

Positioning and resources​

  • target is unchanged. If you don't set it, the SDK renders in a full-screen overlay.
  • resourcesPath works as before, but its default has changed; see Serve WASM resources.

Serve WASM resources​

The camera steps still need their WebAssembly (WASM) and worker files served as static files, in a resources folder.

In v1, you copied the files from node_modules/@microblink/platform-sdk/dist/resources. In v2, they come from the packages of the individual scanning SDKs, so instead of copying them by hand, use the platform-web-sdk copy-resources command that comes with the SDK. Run it as part of your build, with your public output directory as the argument; it creates the resources folder inside it:

package.json
{
"scripts": {
"prebuild": "platform-web-sdk copy-resources public"
}
}

The files take about 130 MB in total. If your workflows don't use all camera steps, copy only the ones they use with --only, for example --only document,face:

  • document: document scanning and document verification, about 95 MB
  • card: card scanning, about 30 MB
  • face: face capture, about 5 MB

If a step's files are missing, that step fails when it starts the camera.

If you use Vite, you can use the SDK's plugin instead. It copies all files into public/resources on every dev and build run:

vite.config.ts
import { defineConfig } from 'vite';
import { scanResourcesPlugin } from '@microblink/platform-sdk/vite';

export default defineConfig({
plugins: [...scanResourcesPlugin()],
});

resourcesPath works as before, but its default has changed. In v1, the SDK loaded the files from /resources/ at the root of your site; in v2, it loads them from a resources/ folder next to the current page. For a page at https://example.com/app/verify, that's https://example.com/app/resources/. If you didn't set resourcesPath and your page isn't at the root of your site, set resourcesPath: '/' to keep loading the files from /resources/.

The files change with each SDK release. Unless their path contains the SDK version, cache them with revalidation (for example, with ETag) rather than as immutable.

Use a CDN​

To serve the files from a CDN, upload the resources folder as it is, and set resourcesPath to the URL of the folder that contains it. For example, if the files are in https://cdn.example.com/sdk/resources/, set resourcesPath: 'https://cdn.example.com/sdk/'. The trailing slash is optional: https://cdn.example.com/sdk loads from the same place.