Bridge library
SDK @synchra24/app and web Bridge add-ons: artifacts, events, and compatibility.
Machine translation
TypeScript SDK for hybrid applications that open inside the Synchra mobile app.24 via WebView.
The package wraps native bridge Synchra and provides a Promise-based API for invoking application features: requests to authorized APIs, provider context, theme, geo-location, file and media selection, file retrieval from S3, QR scanner, user selection, calendar, time selection, snackbar, and modal confirmation window.
Built-in web engine and mobile SDK
In the embedded web service, the object synchra created by the engine. Its capabilities differ from the mobile bridge and are not determined by the version of the npm package alone. Web Extension emitEvent it uses existing service events; it does not register events from JavaScript. The camera and other native methods remain mobile capabilities. Do not transfer examples between modes without checking the method support.
Embedded Service Variables
The built-in engine loads the service variables before running your JavaScript. This is an extension of the built-in SDK in a web service, widget, or mobile WebView, and not a promise of a method in an arbitrary installed version of the npm package.
const config = synchra.getVariable('settings'); // значение сразу, без await
const info = synchra.getVariableInfo('settings'); // копия записи с is_set и revision
await synchra.setVariable('settings', { enabled: true }, { revision: info.revision });
Definitions are created by the administrator in the tab Variables shared access is limited to a specific service of one company. An unspecified value is returned as undefined, JSON null — how null; unknown name causes an error. A successful write updates the local snapshot; changes to other instances appear the next time you open it. In the preview, the entry is local. Definitions without values are sent to the store. The full scenario, rights, limits, and API are described in list of embedded services.
Sending an embedded Web Service event
// Внутри async-обработчика после isSynchraIntegrated() === true.
const requestKey = crypto.randomUUID();
const result = await synchra.emitEvent('report_ready', { report_id: '125' }, { requestKey });
name: the local technical name of an already registered and enabled event;payload: JSON object up to 32 KB;options.requestKey: an optional key for a single operation; save it when it is repeated. Without it, each call is considered a new operation.;- result:
{ event_id, duplicate }when joining the queue. This is not the result of automation; - in the preview:
{ preview: true, accepted: false, message }, without launching; - access errors are possible, 409 when the key is repeated with other data, 429 when the load is limited, and 503 when reception is temporarily unavailable.
Identical key and data are deduplicated for at least 24 hours. Do not pass the full code in the first argument. custom.service_ID.report_ready: it is generated by the server and uses an automation trigger. The method is not yet available in the mobile bridge; updating the npm package by itself does not change this.
Registration, an example with state processing, limits and rights are described in the article. "Creating a service in the web version".
Embedded Service Execution environment
The built-in engine complements the SDK with the method synchra.getRuntime(), which synchronously returns web or mobile. Availability ReactNativeWebView it is not an environment check: the web engine also uses a compatible transport. Calls to native actions on the web return
{runtime: 'web', supported: false, ignored: true} without starting the phone function. For an external application with its own SDK version, use
window.getSynchraRuntime?.() ?? 'web'; the mobile app implements this feature.
Switch Allow in the web version, the publication, the branching example, and the connection of a web transport for an external service are described in Service management.
Installation
npm install @synchra24/app
import { SynchraApp } from "@synchra24/app";
const synchra = new SynchraApp("SERVICE_TOKEN");
SERVICE_TOKEN - an internal service token created in Synchra.24. The native application verifies this token with each bridge call.
Quick start
const synchra = new SynchraApp("SERVICE_TOKEN");
const integrated = await synchra.isSynchraIntegrated();
if (!integrated) {
console.log("Приложение открыто не внутри Synchra.24 или токен невалиден.");
}
const provider = await synchra.getProviderContext();
const theme = synchra.getSynchraTheme();
await synchra.showSnackbar({
message: `Provider ID: ${provider.provider_id}`,
type: "success",
});
console.log(theme?.active);
console.log(theme?.current.controlPrimary);
getSynchraTheme() retains the same color role names on both platforms. In current The mobile application transmits mobile colors, and the browser transmits the actual colors of the web interface. Use onSynchraThemeChange to update the design without restarting, and do not fix the mobile HEX colors in the web service.
Creating a client
const synchra = new SynchraApp(token, {
responseTimeout: 60000,
});
Parameters:
responseTimeout- timeout for waiting for a response from native bridge in milliseconds. By default60000.
When the instance is no longer needed, you can remove listeners and reject pending requests.:
synchra.destroy();
Mistakes
Most methods return Promise. If the native application returns an error, the Promise will be rejected after Error(message).
try {
const position = await synchra.getGeoPosition();
} catch (error) {
console.error(error);
}
Method isSynchraIntegrated() it is specially made safe: it returns false if the bridge is unavailable or the token has failed verification.
Checking the integration
Checks that the application is open inside Synchra.24 and the service token is valid.
const integrated = await synchra.isSynchraIntegrated();
Returns:
boolean;
Application Theme
Synchra transmits the color theme directly to the service via a WebView in the application or a web container in the browser, so reading the theme is synchronous and does not require a bridge request. The color roles have the same names, but the values correspond to the current platform. On the web current It takes into account the actual CSS colors of the interface, including translucent panels and accents.; themes It contains the basic palettes of the platform with the actual colors of the active theme.
const theme = synchra.getSynchraTheme();
Returns:
{
active: 'light' | 'dark';
current: Record<string, string>;
themes: {
light: Record<string, string>;
dark: Record<string, string>;
};
} | null
Subscription to change the theme:
const unsubscribe = synchra.onSynchraThemeChange((theme) => {
document.body.style.background = theme.current.primary;
});
unsubscribe();
The legacy bridge of the active theme is also available.:
const activeTheme = await synchra.getThemeState();
const unsubscribeAppearance = synchra.onThemeAppearance((theme) => {
console.log(theme);
});
API requests
Executes requests allowed by the Open API through the Synchra native application.
const response = await synchra.requestApi<{ parameters: { name: string } }>({
method: "GET",
path: "providers/parameters",
query: {
key: "value",
},
});
console.log(response.result.parameters.name);
Payload:
{
method: 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE';
path: string;
body?: Record<string, unknown>;
query?: Record<string, unknown>;
apiVersion?: number;
form?: Record<string, unknown> | { name: string; value: unknown }[];
}
apiVersion allows you to call not only /api/v1, but also other versions of the API. If you send apiVersion: 2, the request will be sent to /api/v2/....
form it is needed for multipart/form-data queries. Since bridge is serialized via postMessage, in form You need to pass a regular JSON-compatible object or an array of fields, and the native layer will assemble it itself. FormData.
Example of a multipart request:
await synchra.requestApi({
method: "POST",
path: "reports/create",
apiVersion: 1,
form: {
title: "Отчет",
published: true,
tags: ["daily", "shift"],
},
});
Provider Context
Returns the current context of the Synchra provider without the provider token.
const provider = await synchra.getProviderContext();
console.log(provider.provider_id);
console.log(provider.profile_id);
console.log(provider.role.permissions);
console.log(provider.bucketName);
The Provider token is not returned by this method.
User Selection
Opens the native user selection widget.
const result = await synchra.selectUsers({
users: [25],
all_users: true,
});
console.log(result.users);
Payload:
{
users?: number[];
all_users?: boolean;
}
Returns:
{
users: number[];
}
Geographic location
Requests the user's current location through the native application.
const position = await synchra.getGeoPosition();
console.log(position.latitude, position.longitude);
Returns:
{
latitude: number;
longitude: number;
altitude: number | null;
accuracy: number | null;
altitude_accuracy: number | null;
heading: number | null;
speed: number | null;
timestamp: number;
}
Photos from the camera
Opens the native camera and returns the photo. By default, the file is uploaded to the Synchra storage, and the response includes file, bucket and base64.
const photo = await synchra.takePhoto({
use_front_camera: false,
upload: true,
});
console.log(photo.file);
console.log(photo.bucket);
console.log(photo.base64);
If you only need base64, the download can be disabled:
const photo = await synchra.takePhoto({
upload: false,
});
console.log(photo.file); // null
console.log(photo.bucket); // null
console.log(photo.base64);
Returns:
{
file: string | null;
bucket: string | null;
base64: string;
name: string;
type: string;
}
Photos from the gallery
Opens native-select a photo from the gallery. The response format is the same as takePhoto().
const photo = await synchra.pickPhoto({
upload: false,
});
File Selection
Opens the native file picker. The response returns local_uri to access the selected file. If necessary, it is additionally uploaded to the Synchra storage.
const file = await synchra.pickFile({
upload: true,
});
console.log(file.file);
console.log(file.bucket);
console.log(file.local_uri);
console.log(file.name);
console.log(file.size);
If you only need a local file without uploading to Synchra, you can disable the download.:
const file = await synchra.pickFile({
upload: false,
});
Returns:
{
file: string | null;
bucket: string | null;
local_uri: string;
name: string;
type: string;
size: number;
}
QR scanner
Opens the native QR scanner.
const qr = await synchra.scanQr();
console.log(qr.value);
console.log(qr.type);
Returns:
{
value: string;
type?: string;
}
Getting an image from S3
Retrieves the file from S3 via the native application. Returns the local path by default. local_uri because it is noticeably easier for bridge and better suited for large images.
const image = await synchra.getS3Image({
file: "avatar.jpg",
});
console.log(image.local_uri);
If you need it exactly base64, you can explicitly request it:
const image = await synchra.getS3Image({
file: "avatar.jpg",
response_type: "base64",
});
Returns:
{
file: string;
local_uri: string | null;
base64: string | null;
response_type: "local_uri" | "base64";
source_url: string;
}
Getting a file from S3
It works the same way as getting an image, but it is intended for any files.
const file = await synchra.getS3File({
file: "docs/report.pdf",
});
console.log(file.local_uri);
For both methods, the storage is determined automatically for the selected company. You do not need to transfer it separately.
Navigation on internal screens
Allows you to open Synchra's internal screens from a hybrid application.
await synchra.navigate({
action: "navigate",
screen: "Tasks",
});
With parameters:
await synchra.navigate({
action: "navigate",
screen: "TaskCard",
params: {
number: "123",
},
});
Supported actions:
navigatepushreplacego_backpop_to_top
An example of going back:
await synchra.navigate({
action: "go_back",
});
Returns:
{
success: boolean;
action: "navigate" | "push" | "replace" | "go_back" | "pop_to_top";
screen: string | null;
}
If you specify an unknown screen, native bridge returns an error. screen not found.
Date selection
Opens the native date picker to select a single date.
const result = await synchra.selectDate({
date: "2026-04-21",
});
console.log(result.date);
Returns:
{
date: string | null; // YYYY-MM-DD
}
Selecting a date range
Opens the native date range picker.
const range = await synchra.selectDateRange({
start_date: "2026-04-01",
end_date: "2026-04-21",
});
console.log(range.start_date, range.end_date);
Returns:
{
start_date: string | null;
end_date: string | null;
}
Choosing the time
Opens the native time picker.
const time = await synchra.selectTime({
time: "09:30",
});
console.log(time.time);
console.log(time.hours);
console.log(time.minutes);
You can transfer either to the payload time, or hours/minutes.
Returns:
{
time: string; // HH:mm
hours: number;
minutes: number;
}
Snackbar
Shows native snackbar Synchra.
await synchra.showSnackbar({
message: "Сохранено",
type: "success",
timeout: 4000,
});
Available types:
successerrorwarnempty
Returns:
{
shown: boolean;
}
Modal window
Opens the Synchra native modal window with two buttons.
const result = await synchra.openModal({
title: "Подтверждение",
text: "Продолжить действие?",
primary_button_text: "Продолжить",
secondary_button_text: "Отмена",
});
if (result.action === "primary") {
// Нажата первая кнопка
}
if (result.action === "secondary") {
// Нажата вторая кнопка
}
if (result.action === "dismiss") {
// Окно закрыто нажатием по фону
}
Returns:
{
action: "primary" | "secondary" | "dismiss";
}
TypeScript
The package comes with TypeScript declarations. You can import the payload and response types:
import type {
SynchraProviderContext,
SynchraPickedFilePayload,
SynchraThemePayload,
} from "@synchra24/app";
Running outside Synchra
Most bridge methods require window.ReactNativeWebView. When calling outside of the Synchra mobile app, they will throw an error. For secure runtime verification, use isSynchraIntegrated().
const integrated = await synchra.isSynchraIntegrated();
if (!integrated) {
// Показать fallback UI для обычного браузера.
}
Development
Install Dependencies:
npm install
Check the types:
npm run typecheck
Assemble a package:
npm run build
Check the content of the publication:
npm pack --dry-run
The npm package includes only dist, README.md and package.json.
Publication
Before publishing, you need to make sure that the Synchra native application supports the same bridge events as the SDK.
npm publish
For public publication of the scoped package:
npm publish --access public