Kaizen
Browse modulesPeripheralsperipherals/serverFunctions

Function: toPeripheralDevice()

function toPeripheralDevice(row: {
  connectionKind: string;
  createdAt: Date;
  createdBy: string | null;
  deletedAt: Date | null;
  deletedBy: string | null;
  deviceType: string;
  drawerPin: number | null;
  host: string | null;
  id: string;
  make: string | null;
  metadata: JsonValue;
  model: string | null;
  name: string;
  organizationId: string;
  paperWidthChars: number | null;
  port: number | null;
  printerLanguage: string | null;
  qzPrinterName: string | null;
  stationId: string | null;
  status: string;
  statusUpdatedAt: Date;
  statusUpdatedBy: string | null;
  storeId: string | null;
  updatedAt: Date;
  updatedBy: string | null;
  usbProductId: number | null;
  usbSerialNumber: string | null;
  usbVendorId: number | null;
}): {
  connection:   | {
     kind: "webusb";
     usbProductId: number;
     usbSerialNumber?: string | null;
     usbVendorId: number;
   }
     | {
     host: string;
     kind: "network";
     port: number;
   }
     | {
     kind: "qz";
     printerName: string;
   };
  deviceType: "receipt_printer" | "cash_drawer" | "barcode_scanner";
  drawerPin?: 2 | 5 | null;
  id: string;
  make?: string | null;
  metadata?: Record<string, unknown> | null;
  model?: string | null;
  name: string;
  organizationId: string;
  paperWidthChars?: 32 | 35 | 42 | 44 | 48 | null;
  printerLanguage?: "esc-pos" | "star-prnt" | "star-line" | null;
  stationId?: string | null;
  status: "active" | "inactive";
  storeId?: string | null;
};

Defined in: server/peripherals/models.ts:113

Map a Prisma row to the shared, Zod-validated PeripheralDevice shape (flat columns → nested connection config). Throws INVALID_CONFIG when a row is internally inconsistent (e.g. network kind with no host).

Parameters

ParameterType
row{ connectionKind: string; createdAt: Date; createdBy: string | null; deletedAt: Date | null; deletedBy: string | null; deviceType: string; drawerPin: number | null; host: string | null; id: string; make: string | null; metadata: JsonValue; model: string | null; name: string; organizationId: string; paperWidthChars: number | null; port: number | null; printerLanguage: string | null; qzPrinterName: string | null; stationId: string | null; status: string; statusUpdatedAt: Date; statusUpdatedBy: string | null; storeId: string | null; updatedAt: Date; updatedBy: string | null; usbProductId: number | null; usbSerialNumber: string | null; usbVendorId: number | null; }
row.connectionKindstring
row.createdAtDate
row.createdBystring | null
row.deletedAtDate | null
row.deletedBystring | null
row.deviceTypestring
row.drawerPinnumber | null
row.hoststring | null
row.idstring
row.makestring | null
row.metadataJsonValue
row.modelstring | null
row.namestring
row.organizationIdstring
row.paperWidthCharsnumber | null
row.portnumber | null
row.printerLanguagestring | null
row.qzPrinterNamestring | null
row.stationIdstring | null
row.statusstring
row.statusUpdatedAtDate
row.statusUpdatedBystring | null
row.storeIdstring | null
row.updatedAtDate
row.updatedBystring | null
row.usbProductIdnumber | null
row.usbSerialNumberstring | null
row.usbVendorIdnumber | null

Returns

connection

connection: 
  | {
  kind: "webusb";
  usbProductId: number;
  usbSerialNumber?: string | null;
  usbVendorId: number;
}
  | {
  host: string;
  kind: "network";
  port: number;
}
  | {
  kind: "qz";
  printerName: string;
} = connectionConfigSchema;

Union Members

Type Literal
{
  kind: "webusb";
  usbProductId: number;
  usbSerialNumber?: string | null;
  usbVendorId: number;
}
kind
kind: "webusb";
usbProductId
usbProductId: number;
usbSerialNumber?
optional usbSerialNumber?: string | null;

Distinguishes identical printers on the same station.

usbVendorId
usbVendorId: number;

Type Literal
{
  host: string;
  kind: "network";
  port: number;
}
host
host: string;
kind
kind: "network";
port
port: number;

Raw-socket printing port; 9100 is the near-universal default.


Type Literal
{
  kind: "qz";
  printerName: string;
}
kind
kind: "qz";
printerName
printerName: string;

OS printer name as QZ Tray reports it.

deviceType

deviceType: "receipt_printer" | "cash_drawer" | "barcode_scanner" = peripheralDeviceTypeSchema;

drawerPin?

optional drawerPin?: 2 | 5 | null;

Drawer-kick pin — on printer rows (drawer wired to the printer) or standalone cash_drawer rows.

id

id: string;

make?

optional make?: string | null;

metadata?

optional metadata?: Record<string, unknown> | null;

model?

optional model?: string | null;

name

name: string;

organizationId

organizationId: string;

paperWidthChars?

optional paperWidthChars?: 32 | 35 | 42 | 44 | 48 | null;

Character columns at the printer's default font.

printerLanguage?

optional printerLanguage?: "esc-pos" | "star-prnt" | "star-line" | null;

Required for receipt printers; meaningless for scanners.

stationId?

optional stationId?: string | null;

status

status: "active" | "inactive" = peripheralDeviceStatusSchema;

storeId?

optional storeId?: string | null;

On this page