Skip to content

API Quick Reference

Module Methods

ModuleMethodReturn TypeDescription
healthcheck()Promise<HealthResponse>Health check
whoamicheck()Promise<WhoAmIResponse>Current login status
benefitscheck()Promise<BenefitsResponse>Entitlement validation
benefitsrefreshBenefit()Promise<BenefitsResponse>Force-refresh benefit cache
printerslist()Promise<PrintersResponse>Printer list
templateslist()Promise<TemplatesListResponse>Template list
templatesschema(template)Promise<TemplateSchemaResponse>Template field definitions
templatesjson(templateIds)Promise<TemplatesJsonResponse>Batch-fetch template JSON
templatesrefreshTemplates(...)overloadForce template-cache sync
printexecute(request)Promise<PrintResponse>Execute print
preflightrun(options?)Promise<PreflightResult>Preflight orchestration
launchtrigger()voidTrigger TopBridge App launch
launchensureRunning(fn, options?)Promise<T>Launch + retry orchestration
printerSetupload()Promise<PrinterSetupLoadResult>Options + installed printers
printerSetupconfigure(req, opts?)Promise<ConfigureResult>Save protocol config (may await BPAC)
printerSetupgetOptions() / listInstalled() / getBpacStatus()Promise<SdkResponse<...>>Read setup dictionaries / status
printerSetupaddCharset() / deleteCharset() / addFont() / deleteFont()Promise<SdkResponse<...>>Charset / font CRUD
printerSetupreset(printerName)Promise<ResetPrinterResult>Clear protocol config (no default-printer change)
sessionkickSession(sessionIds)Promise<KickSessionResponse>Kick sessions to clear SessionBlocked
clientconnect() / close() / getConnectionState()Shared connection lifecycle
client.eventson(name, handler) / off(name, handler)unsubscribe / voidPush + connection events

TIP

printerSetup and events deep guides are coming. For the session-limit flow, see the interactive Session Management example. For everything else, use this table plus the migration guide.

TopBridgeClientConfig

FieldTypeDefaultDescription
source'Core-SDK' | 'React-SDK' | 'Nextjs-SDK''Core-SDK'SDK source identifier
debugbooleanfalseEnable console logging
loggerLoggerSilent (no-op)Custom logger
wssEnabledbooleanfalseUse fixed WSS endpoint
timeouts.healthnumber (ms)3000Health check timeout
timeouts.preflightnumber (ms)10000Preflight / template query timeout
timeouts.printnumber (ms)60000Print timeout
timeouts.printerSetupnumber (ms)10000Printer setup timeout
timeouts.refreshnumber (ms)30000Force-refresh timeout
typescript
import type { TopBridgeClientConfig } from '@appzgatenz/label-print-topbridge-js'

const client = new TopBridgeClient({
  debug: true,
  timeouts: { health: 5000, print: 120000, refresh: 45000 },
})

PrintExecuteRequest

typescript
interface PrintExecuteRequest {
  template: string             // Template ID or Code
  printer: string              // Printer name
  products: PrintProductInput[] // Product data array
}

PrintProductInput

typescript
interface PrintProductInput {
  [key: string]: string | number | Record<string, string | number | undefined> | undefined
  copies?: number  // Print copies, range [1, 9999], default 1
}

SyncedPrinter

typescript
interface SyncedPrinter {
  name: string               // Printer name (used as printer parameter)
  isDefault: boolean         // Whether this is the default printer
  protocol?: 'TSPL' | 'ZPL' // Label protocol
}

Event names (client.events)

EventPayloadDescription
printerPrinterEventPrinter / BPAC related push
templateTemplateEventTemplate change push
userUserEventUser / login related push
openConnectionLifecycleEventShared connection opened
reconnectConnectionLifecycleEventShared connection reconnected
closeConnectionLifecycleEventShared connection closed
errorConnectionLifecycleEventShared connection error
typescript
const off = client.events.on('printer', (event) => {
  console.log(event)
})
// later
off()
// or
client.events.off('printer', handler)

Session limiting & force-refresh

typescript
// Session-limit unblock: catch SESSION_LIMIT_EXCEEDED, kick stale sessions, retry.
try {
  await client.templates.list()
} catch (err) {
  if (err instanceof TopBridgeSessionError) {
    // err.sessions[] — render a picker; isCurrent marks this device (don't kick it)
    const toKick = (err.sessions ?? []).filter((s) => !s.isCurrent).map((s) => s.id)
    const result = await client.session.kickSession(toKick)
    if (result.data.withinLimit) {
      await client.templates.list() // block cleared — no re-login needed
    }
  }
}

// Force-refresh benefit cache (after purchase/upgrade); throws TopBridgeQuotaError if invalid.
const benefits = await client.benefits.refreshBenefit()

// Force-sync templates — full mode (no args) vs by-ID mode (validates loggedAccount).
await client.templates.refreshTemplates()
await client.templates.refreshTemplates({
  templateIds: ['tpl-1', 'tpl-2'],  // single string also accepted
  loggedAccount: 'user@example.com', // must match the current TopBridge login
})
APIKey behavior
session.kickSession(ids)Stateless passthrough; withinLimit === true → block cleared; per-session failures land in failedSessionIds (never SESSION_NOT_FOUND)
benefits.refreshBenefit()Bypasses local cache; same shape as check(); isValid === false throws TopBridgeQuotaError
templates.refreshTemplates()Full sync (no args) vs by-ID sync ({ templateIds, loggedAccount }); ACCOUNT_MISMATCH when the account differs

Printer protocol options

printerSetup.getOptions() returns a protocol dictionary for rendering a dropdown:

typescript
interface PrinterOptionsData {
  TSPL: { label: string; charsets: PrinterCharsetOption[] }
  ZPL: { label: string; charsets: PrinterCharsetOption[] }
  BPAC: { label: string; sdkInstalled: boolean; paperColors: BpacOption[]; fonts: BpacOption[] }
  UNKNOWN: { label: string } // unconfigured printer sentinel
}

UNKNOWN is the sentinel for an unconfigured printer — render it alongside TSPL/ZPL/BPAC so the dropdown always offers a valid choice. Each protocol's label is display-ready text. reset(printerName) returns a printer to this UNKNOWN state.

Response Types

TypeKey Fields
HealthResponsetype: 'pong', isRunning: true, data.isLoggedIn, data.version?, data.networkStatus?
WhoAmIResponsedata.isLoggedIn, data.loggedAccount?, data.userId?
BenefitsResponsedata.isValid, data.remainingPrints, data.expiresAt, data.reason, data.hasPrintBenefit, data.hasSessionBenefit
PrintersResponsedata.count, data.defaultPrinter, data.printers[]
TemplatesListResponsedata.count, data.templates[]
TemplateSchemaResponsedata.fields[], data.code, data.name
TemplatesJsonResponsebatch template JSON payload
PrintResponsemessage, data.printedCopies, data.jobId, data.templateName, data.userId?, details?, warnings?
KickSessionResponsedata.withinLimit, data.kickedSessionIds[], data.failedSessionIds[], data.sessions[]
PreflightResulthealth, benefits, printers
ConfigureResultprinter configure result (may include BPAC install outcome)

SdkResponse<T>

typescript
interface SdkResponse<T> {
  status: 'ok' | 'warning'
  requestId?: string
  data: T
  message: string
  details?: unknown
  warnings?: SdkWarning[]
}
StatusBehavior
'ok'Succeeded. Use data.
'warning'Succeeded with hints. data is usable.
(error)Throws a TopBridgeError subclass.

Export List

typescript
// Classes
import { TopBridgeClient, LaunchModule, PrinterSetupModule } from '@appzgatenz/label-print-topbridge-js'

// Error classes (1 base + 13 subclasses)
import {
  TopBridgeError,
  TopBridgeConnectionError,
  TopBridgeAuthError,
  TopBridgeVersionError,
  TopBridgeQuotaError,
  TopBridgePrintError,
  TopBridgeConfigError,
  TopBridgeValidationError,
  TopBridgePrinterError,
  TopBridgeTemplateError,
  TopBridgeNetworkError,
  TopBridgeSourceError,
  TopBridgePrinterSetupError,
  TopBridgeSessionError,
} from '@appzgatenz/label-print-topbridge-js'

// Types (import on demand)
import type {
  TopBridgeClientConfig,
  TopBridgeSource,
  Logger,
  SdkWarning,
  V2WarningCode,
  SdkEvents,
  HealthResponse,
  WhoAmIResponse,
  BenefitsResponse,
  PrintersResponse,
  SyncedPrinter,
  TemplatesListResponse,
  TemplateSchemaResponse,
  TemplatesJsonResponse,
  PrintResponse,
  PrintExecuteRequest,
  PrintProductInput,
  PreflightResult,
  PreflightOptions,
  EnsureRunningOptions,
  PrinterSetupLoadResult,
  ConfigureResult,
  ConfigureOptions,
  KickSessionResponse,
  SessionInfo,
  SdkEventMap,
  ConnectionState,
  PrinterSetupErrorCode,
} from '@appzgatenz/label-print-topbridge-js'