@lavitre/apps 1.62.0 → 1.62.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -174,7 +174,7 @@ const stop = watchNfcTags(
174
174
  },
175
175
  {
176
176
  reader: (name) => name.includes('PICC'), // optional: by PC/SC reader name
177
- onUnavailable: () => console.log('no NFC here'), // web/PWA, companion, no `nfc` authorization, native Vitre 26.11.0 or older
177
+ onUnavailable: () => console.log('no NFC here'), // web/PWA, companion, no `nfc` authorization, native Vitre 26.11.2 or older
178
178
  },
179
179
  )
180
180
  ```
@@ -178,7 +178,7 @@ export type NfcEvent = ({
178
178
  };
179
179
  /**
180
180
  * NFC bridge exposed to apps at `window.laVitreNative.nfc`, on a native Vitre
181
- * released after 26.11.0 (26.11.0 and older do not have it). It reports badges and tags put on a USB NFC reader (any PC/SC
181
+ * 26.11.3 or later (26.11.2 and older do not have it). It reports badges and tags put on a USB NFC reader (any PC/SC
182
182
  * contactless reader: ACS ACR122U / ACR1252U, Identiv, HID Omnikey…).
183
183
  *
184
184
  * ⚠️ **Conditioned on the app manifest.** Injected **only** when the app
@@ -215,7 +215,7 @@ export type LaVitreNative = {
215
215
  serialport?: SerialPortBridge;
216
216
  /**
217
217
  * NFC tags on a USB reader. Present **only** when the app holds the `nfc`
218
- * authorization, on a native Vitre released after 26.11.0 — otherwise `undefined`.
218
+ * authorization, on a native Vitre 26.11.3 or later — otherwise `undefined`.
219
219
  * See {@link NfcBridge} and {@link watchNfcTags}.
220
220
  */
221
221
  nfc?: NfcBridge;
@@ -261,7 +261,7 @@ export type WatchNfcTagsOptions = {
261
261
  waitMs?: number;
262
262
  /**
263
263
  * Called once when the bridge never showed up: not a native Vitre, no `nfc`
264
- * authorization in the manifest, or a native Vitre without the bridge (26.11.0
264
+ * authorization in the manifest, or a native Vitre without the bridge (26.11.2
265
265
  * and older).
266
266
  */
267
267
  onUnavailable?: () => void;
@@ -1 +1 @@
1
- {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M,GAAG,WAAW,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,IAAI,EAAE,CAAA;IACnD,OAAO,MAAM,GAAG,IAAI,WAAW,CAAC,OAAO,CAAC,CAAC,MAAM,CAAC,MAAM,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAA;AAC7E,CAAC,CAAA;AAED;;;GAGG;AACH,MAAM,CAAC,MAAM,QAAQ,GAAG,CACtB,MAAkB,EACqB,EAAE;IACzC,IAAI,MAAM,CAAC,GAAG,KAAK,CAAC,IAAI,MAAM,CAAC,IAAI,KAAK,GAAG,IAAI,MAAM,CAAC,OAAO,CAAC,MAAM,KAAK,CAAC;QACxE,OAAO,IAAI,CAAA;IACb,MAAM,MAAM,GAAG,MAAM,CAAC,OAAO,CAAC,CAAC,CAAC,CAAA;IAChC,MAAM,UAAU,GAAG,MAAM,GAAG,IAAI,CAAA;IAChC,IAAI,CAAC,GAAG,UAAU,GAAG,MAAM,CAAC,OAAO,CAAC,MAAM;QAAE,OAAO,IAAI,CAAA;IACvD,MAAM,IAAI,GAAG,KAAK,CAAC,MAAM,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC,EAAE,CAAC,GAAG,UAAU,CAAC,CAAC,CAAA;IAC9D,MAAM,IAAI,GAAG,IAAI,WAAW,CAAC,MAAM,GAAG,IAAI,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,MAAM,CACvE,MAAM,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC,GAAG,UAAU,CAAC,CACxC,CAAA;IACD,OAAO,EAAE,IAAI,EAAE,IAAI,EAAE,CAAA;AACvB,CAAC,CAAA","sourcesContent":["export type StartProcessArgs = {\n path: string\n args: string[]\n ignoreFormatPath?: boolean\n hidden?: boolean\n}\n\nexport type Capture = {\n startCapture: (options: {\n outputFile: string\n audioInput: string\n }) => Promise<void>\n stopCurrentCapture: () => void\n}\n\nexport type ReadBinaryArgs = {\n path: string\n bufferSize?: number\n position?: number\n}\n\nexport type BinaryChunkResult = {\n buffer: ArrayBufferLike\n read: number\n fileSize: number\n position: number\n}\n\nexport type DownloadProgress = {\n /** Bytes written to disk so far. */\n received: number\n /** Total bytes, when the server advertises a `Content-Length`. */\n total?: number\n}\n\nexport type DownloadFileArgs = {\n /** Source URL to fetch. */\n url: string\n /**\n * Destination path inside the app sandbox (e.g. `~/media/cover.png`). The\n * native bridge resolves it through the app path formatter, so it is scoped\n * to `<vitre-data>/apps/<appId>/...` — it cannot escape the app storage.\n */\n path: string\n /** Optional extra request headers. */\n headers?: Record<string, string>\n /** Optional progress callback fired as bytes are streamed to disk. */\n progress?: (progress: DownloadProgress) => void\n}\n\nexport type FileInfoType = 'file' | 'directory'\n\nexport type FileInfo = {\n name: string\n path: string\n type: FileInfoType\n}\nexport type Process = {\n startProcess: (args: StartProcessArgs) => void\n}\n\n/**\n * Native file I/O for the app, exposed at `window.laVitreNative.io`.\n *\n * ⚠️ **Conditioned on the app manifest.** This bridge is injected **only** when\n * the app declares a storage authorization:\n * - **`appsStorage`** — paths are confined to the app's own storage folder\n * (absolute paths, the `~~/` parent escape and `../` traversal are rejected).\n * This is what most apps want.\n * - **`fullStorage`** — unrestricted filesystem access. Use only when strictly\n * necessary.\n *\n * With neither authorization, `laVitreNative.io` is `undefined` — always\n * feature-detect (`laVitreNative?.io`) before use. It is also `undefined` off a\n * native Vitre (`laVitreNative` itself is `null` on web/PWA and the companion,\n * see {@link isNativeHost}). The host adds it shortly after the page starts\n * (an authorization round trip), so a check at load time can miss it.\n *\n * Paths use a `~/` prefix for the app's sandbox root, e.g. `~/data/x.json`; the\n * file written there is served by the Vitre's local web server at\n * {@link getLocalAppStorageUrl}`(appId, 'data/x.json')`.\n */\nexport type IO = {\n readFile: (path: string) => string\n /** True if a file exists at `path` (resolved inside the app sandbox). */\n fileExists: (path: string) => boolean\n /**\n * Write a file to the app sandbox.\n *\n * - Pass a `string` for text content (written as UTF-8).\n * - Pass an `ArrayBuffer` (or any `ArrayBufferLike`) for binary content — the\n * raw bytes are written as-is. Do **not** base64-encode binary data. For a\n * typed array, pass its `.buffer` (e.g. `new Uint8Array(...).buffer`, or\n * `await blob.arrayBuffer()`).\n */\n writeFile: (path: string, content: string | ArrayBufferLike) => void\n list: (path: string) => FileInfo[]\n createFolder: (path: string) => void\n formatPath: (path: string) => string\n deleteFile: (path: string) => void\n readBinaryFileBuffer: (args: ReadBinaryArgs) => Promise<BinaryChunkResult>\n /**\n * Download a URL straight into a file in the app sandbox. Binary-safe: the\n * response body is streamed to disk natively, so nothing is buffered in JS\n * (ideal for large media). Node-style callback `(error, bytesWritten)`.\n *\n * Prefer {@link downloadFileToAppStorage} for a promise-based API.\n */\n downloadFile: (\n args: DownloadFileArgs,\n callback: (error: string | null, bytesWritten: number | null) => void,\n ) => void\n}\n\n/** A serial port as enumerated by `serialport.getSerialPortsWithDescription()`. */\nexport type SerialPortInfo = {\n /** OS port name, e.g. `\"COM3\"`. */\n port: string\n /** Human-readable device caption reported by the OS. */\n description: string\n /**\n * USB vendor id (decimal), or `null` for non-USB ports (e.g. a built-in\n * motherboard serial). Same shape as `navigator.serial` `getInfo()`, so it\n * can be matched against `requestSerialPortAccess` / `requestPort` filters.\n */\n usbVendorId: number | null\n /** USB product id (decimal), or `null` for non-USB ports. */\n usbProductId: number | null\n}\n\n/**\n * Serial-port bridge exposed to apps at `window.laVitreNative.serialport`.\n *\n * ⚠️ **Conditioned on the app manifest.** This bridge is injected **only** when\n * the app declares the `webSerial` authorization in its manifest. For apps it\n * is intentionally read-only: it exposes **only** `getSerialPortsWithDescription`\n * (port enumeration). Opening / reading / writing a port is done through the\n * standard `navigator.serial` Web Serial API (gated by the same authorization),\n * not through this bridge.\n *\n * Always feature-detect before use — the whole object is `undefined` when the\n * app is not authorized:\n *\n * ```ts\n * const sp = laVitreNative?.serialport\n * if (!sp) return // app lacks the `webSerial` authorization\n * const ports = sp.getSerialPortsWithDescription()\n * ```\n */\nexport type SerialPortBridge = {\n getSerialPortsWithDescription: () => SerialPortInfo[]\n}\n\n/** A tag on an NFC reader. Both values are upper-case hex, no separator. */\nexport type NfcTag = {\n /**\n * The tag's UID (4, 7 or 10 bytes: `\"AD9B6846\"`), or `null` when the reader\n * would not give it.\n */\n uid: string | null\n /** The ATR the reader built for the tag (identifies its type: MIFARE, NTAG, DESFire…). */\n atr: string\n /**\n * The tag's NDEF message as read on arrival, records not split: pass it to\n * {@link parseNdefMessage}. Added 1.62.\n * - `null`: the tag holds no NDEF message (never formatted, e.g. a factory\n * MIFARE Classic badge) or it could not be read (lifted mid-read, larger\n * than 4 KB, a tag type the Vitre does not read).\n * - `''`: formatted for NDEF, empty message.\n * - absent: a native Vitre that does not read NDEF (the first releases with\n * `nfc`).\n *\n * Read: NFC Forum Type 2 (Ultralight, NTAG21x), Type 4 (DESFire, ISO 14443-4\n * cards), MIFARE Classic 1K/4K formatted with a MAD and the public NDEF keys.\n */\n ndef?: string | null\n}\n\n/** A PC/SC reader as listed by `nfc.getReaders()`. */\nexport type NfcReader = {\n /** PC/SC reader name, e.g. `\"ACS ACR122U PICC Interface 0\"`. */\n name: string\n /** The tag on it right now, `null` if none. */\n tag: NfcTag | null\n}\n\n/** What `nfc.addTagHandler` reports. */\nexport type NfcEvent =\n | ({ type: 'tagPresent'; reader: string } & NfcTag)\n | { type: 'tagRemoved' | 'readerAdded' | 'readerRemoved'; reader: string }\n\n/**\n * NFC bridge exposed to apps at `window.laVitreNative.nfc`, on a native Vitre\n * released after 26.11.0 (26.11.0 and older do not have it). It reports badges and tags put on a USB NFC reader (any PC/SC\n * contactless reader: ACS ACR122U / ACR1252U, Identiv, HID Omnikey…).\n *\n * ⚠️ **Conditioned on the app manifest.** Injected **only** when the app\n * declares the `nfc` authorization, and only on a native (Windows) Vitre: no\n * browser API reaches these readers, so there is none on web/PWA or the\n * companion. It arrives shortly after load (an authorization round trip):\n * prefer {@link watchNfcTags}, which waits for it.\n *\n * Read-only: the UID and the ATR, never a channel to send commands to the\n * card. Contact smart cards and virtual ones (Windows Hello) are not reported.\n * Every reader of the machine is listed; pick yours by name if there are\n * several.\n */\nexport type NfcBridge = {\n getReaders: () => NfcReader[]\n /** Returns an id for {@link NfcBridge.removeTagHandler}. */\n addTagHandler: (handler: (event: NfcEvent) => void) => string\n removeTagHandler: (id: string) => void\n}\n\nexport type LaVitreNative = {\n process: Process\n /**\n * File I/O. Present **only** when the app holds the `appsStorage` (sandboxed)\n * or `fullStorage` (unrestricted) authorization — otherwise `undefined`.\n * Feature-detect before calling. See {@link IO}.\n */\n io?: IO\n capture: Capture\n /**\n * Serial-port enumeration. Present **only** when the app holds the\n * `webSerial` authorization in its manifest — otherwise `undefined`.\n * Feature-detect before calling. See {@link SerialPortBridge}.\n */\n serialport?: SerialPortBridge\n /**\n * NFC tags on a USB reader. Present **only** when the app holds the `nfc`\n * authorization, on a native Vitre released after 26.11.0 — otherwise `undefined`.\n * See {@link NfcBridge} and {@link watchNfcTags}.\n */\n nfc?: NfcBridge\n}\n\n/** The native bridge, `null` off a native Vitre (the host leaves the property unset). */\nexport const laVitreNative = ((window as any).laVitreNative ??\n null) as LaVitreNative | null\n\n/**\n * Where the app runs:\n * - `native`: the desktop Vitre (CEF shell). It injects `window.laVitreNative`\n * into every app frame before any script runs, whatever the app manifest —\n * only its members depend on the platform and on the authorizations.\n * - `web`: a Vitre in a browser or installed as a PWA, the companion, or any\n * page outside la Vitre. No native bridge.\n */\nexport type HostEnvironment = 'native' | 'web'\n\n/** True on a native (desktop) Vitre, where `laVitreNative` is available. Added 1.53. */\nexport const isNativeHost = (): boolean =>\n typeof window !== 'undefined' && (window as any).laVitreNative != null\n\n/** `native` on a native (desktop) Vitre, `web` everywhere else. See {@link HostEnvironment}. Added 1.53. */\nexport const getHostEnvironment = (): HostEnvironment =>\n isNativeHost() ? 'native' : 'web'\n\nexport const getLocalAppStorageUrl = (appId: string, relativePath: string) =>\n `https://${appId}.local.app.lavit.re/${relativePath}`\n\n/**\n * Promise wrapper around {@link IO.downloadFile}. Resolves to the number of\n * bytes written, rejects with the native error.\n *\n * ```ts\n * import { laVitreNative, downloadFileToAppStorage } from '@lavitre/apps/Native'\n * if (laVitreNative)\n * await downloadFileToAppStorage(laVitreNative.io, {\n * url: 'https://storage.lavit.re/apps/my-app/cover.png',\n * path: '~/media/cover.png',\n * progress: ({ received, total }) => console.log(received, total),\n * })\n * ```\n */\nexport const downloadFileToAppStorage = (\n io: IO,\n args: DownloadFileArgs,\n): Promise<number> =>\n new Promise<number>((resolve, reject) =>\n io.downloadFile(args, (error, bytesWritten) =>\n error ? reject(new Error(error)) : resolve(bytesWritten ?? 0),\n ),\n )\n\nexport type WatchNfcTagsOptions = {\n /** Keep only the readers this accepts (by PC/SC name). Default: every reader. */\n reader?: (name: string) => boolean\n /**\n * How long to wait for `laVitreNative.nfc`, which the host adds shortly after\n * load. Default 10 000 ms.\n */\n waitMs?: number\n /**\n * Called once when the bridge never showed up: not a native Vitre, no `nfc`\n * authorization in the manifest, or a native Vitre without the bridge (26.11.0\n * and older).\n */\n onUnavailable?: () => void\n}\n\nconst nfcBridgeNow = (): NfcBridge | undefined =>\n typeof window === 'undefined'\n ? undefined\n : ((window as any).laVitreNative?.nfc ?? undefined)\n\n/**\n * Follow the tags put on and lifted from the NFC readers. Added 1.60.\n *\n * - Waits for `laVitreNative.nfc` (see {@link WatchNfcTagsOptions.waitMs}).\n * - A tag already on a reader when watching starts is reported as `tagPresent`.\n * - A `tagPresent` repeated for a tag already reported is dropped.\n * - The handler is never called before `watchNfcTags` has returned, so it can\n * always call the returned `stop()`. An exception it throws is logged with\n * `console.error` and does not stop the watch (since 1.60.1).\n *\n * ```ts\n * import { watchNfcTags } from '@lavitre/apps/Native'\n * const stop = watchNfcTags(\n * (e) => { if (e.type === 'tagPresent') console.log('badge', e.uid) },\n * { onUnavailable: () => console.log('no NFC on this Vitre') },\n * )\n * // later: stop()\n * ```\n *\n * Returns a function that stops watching (and stops waiting).\n */\nexport const watchNfcTags = (\n handler: (event: NfcEvent) => void,\n options: WatchNfcTagsOptions = {},\n): (() => void) => {\n const accepts = options.reader ?? (() => true)\n const waitMs = options.waitMs ?? 10_000\n const tagOn = new Map<string, string | null>() // reader → uid of the tag reported on it\n let stopped = false\n let detach: (() => void) | undefined\n let timer: ReturnType<typeof setTimeout> | undefined\n\n const deliver = (event: NfcEvent) => {\n if (stopped || !accepts(event.reader)) return\n if (event.type === 'tagPresent') {\n if (tagOn.has(event.reader) && tagOn.get(event.reader) === event.uid)\n return\n tagOn.set(event.reader, event.uid)\n } else if (event.type === 'tagRemoved' || event.type === 'readerRemoved') {\n if (event.type === 'tagRemoved' && !tagOn.has(event.reader)) return\n tagOn.delete(event.reader)\n }\n try {\n handler(event)\n } catch (error) {\n console.error('[@lavitre/apps] watchNfcTags handler threw', error)\n }\n }\n\n const attach = (nfc: NfcBridge) => {\n // Handler first: the replay below cannot miss an arrival in between, and\n // `deliver` drops the duplicate if both see the same tag.\n const id = nfc.addTagHandler(deliver)\n detach = () => nfc.removeTagHandler(id)\n for (const reader of nfc.getReaders()) {\n if (reader.tag)\n deliver({ type: 'tagPresent', reader: reader.name, ...reader.tag })\n }\n }\n\n const startedAt = Date.now()\n const poll = () => {\n if (stopped) return\n const nfc = nfcBridgeNow()\n if (nfc) {\n attach(nfc)\n } else if (Date.now() - startedAt >= waitMs) {\n options.onUnavailable?.()\n } else {\n timer = setTimeout(poll, 200)\n }\n }\n // Not synchronously: with the bridge already there and a tag on a reader,\n // the replay would call the handler before the caller holds `stop`.\n queueMicrotask(poll)\n\n return () => {\n stopped = true\n if (timer !== undefined) clearTimeout(timer)\n detach?.()\n detach = undefined\n }\n}\n\n// ---------------------------------------------------------------------------\n// NDEF (1.62)\n// ---------------------------------------------------------------------------\n\n/** One record of an NDEF message (NFC Forum NDEF 1.0). Chunked records come back joined. */\nexport type NdefRecord = {\n /**\n * Type Name Format: 0 empty, 1 NFC Forum well-known (`type` `T` text, `U` URI…),\n * 2 MIME type (`type` e.g. `text/vcard`), 3 absolute URI, 4 NFC Forum external\n * (`type` e.g. `example.com:badge`), 5 unknown.\n */\n tnf: number\n /** The record type, read as ASCII. */\n type: string\n /** The record id, read as ASCII, `''` when none. */\n id: string\n payload: Uint8Array\n}\n\nconst hexToBytes = (hex: string): Uint8Array | null => {\n if (hex.length % 2 !== 0 || !/^[0-9a-fA-F]*$/.test(hex)) return null\n const bytes = new Uint8Array(hex.length / 2)\n for (let i = 0; i < bytes.length; i++)\n bytes[i] = Number.parseInt(hex.slice(2 * i, 2 * i + 2), 16)\n return bytes\n}\n\nconst ascii = (bytes: Uint8Array): string => String.fromCharCode(...bytes)\n\n/**\n * Split an NDEF message ({@link NfcTag.ndef}) into its records. `[]` for an\n * empty message; `null` when the bytes are not a well-formed message (bad hex,\n * a record running past the end, a broken chunk sequence). Added 1.62.\n *\n * ```ts\n * const records = e.ndef ? parseNdefMessage(e.ndef) : null\n * const url = records?.map(ndefUri).find((u) => u)\n * ```\n */\nexport const parseNdefMessage = (hex: string): NdefRecord[] | null => {\n const bytes = hexToBytes(hex)\n if (!bytes) return null\n const records: NdefRecord[] = []\n let chunk: { record: NdefRecord; parts: Uint8Array[] } | null = null\n let i = 0\n while (i < bytes.length) {\n const header = bytes[i]\n const messageEnd = (header & 0x40) !== 0\n const chunked = (header & 0x20) !== 0\n const short = (header & 0x10) !== 0\n const hasId = (header & 0x08) !== 0\n const tnf = header & 0x07\n let at = i + 1\n if (at >= bytes.length) return null\n const typeLength = bytes[at++]\n let payloadLength: number\n if (short) {\n if (at >= bytes.length) return null\n payloadLength = bytes[at++]\n } else {\n if (at + 4 > bytes.length) return null\n payloadLength =\n ((bytes[at] << 24) |\n (bytes[at + 1] << 16) |\n (bytes[at + 2] << 8) |\n bytes[at + 3]) >>>\n 0\n at += 4\n }\n let idLength = 0\n if (hasId) {\n if (at >= bytes.length) return null\n idLength = bytes[at++]\n }\n const end = at + typeLength + idLength + payloadLength\n if (end > bytes.length) return null\n const type = ascii(bytes.subarray(at, at + typeLength))\n const id = ascii(\n bytes.subarray(at + typeLength, at + typeLength + idLength),\n )\n const payload = bytes.slice(at + typeLength + idLength, end)\n\n if (chunk) {\n // A middle or last chunk: TNF \"unchanged\" (6), no type.\n if (tnf !== 6 || typeLength !== 0) return null\n chunk.parts.push(payload)\n if (!chunked) {\n const total = chunk.parts.reduce((n, p) => n + p.length, 0)\n const joined = new Uint8Array(total)\n let offset = 0\n for (const part of chunk.parts) {\n joined.set(part, offset)\n offset += part.length\n }\n records.push({ ...chunk.record, payload: joined })\n chunk = null\n }\n } else if (chunked) {\n chunk = { record: { tnf, type, id, payload }, parts: [payload] }\n } else {\n if (tnf === 6) return null\n records.push({ tnf, type, id, payload })\n }\n\n i = end\n if (messageEnd) break\n }\n\n return chunk ? null : records\n}\n\n/** URI identifier codes of the NFC Forum URI record (RTD-URI), 0x00–0x23. */\nconst uriPrefixes = [\n '',\n 'http://www.',\n 'https://www.',\n 'http://',\n 'https://',\n 'tel:',\n 'mailto:',\n 'ftp://anonymous:anonymous@',\n 'ftp://ftp.',\n 'ftps://',\n 'sftp://',\n 'smb://',\n 'nfs://',\n 'ftp://',\n 'dav://',\n 'news:',\n 'telnet://',\n 'imap:',\n 'rtsp://',\n 'urn:',\n 'pop:',\n 'sip:',\n 'sips:',\n 'tftp:',\n 'btspp://',\n 'btl2cap://',\n 'btgoep://',\n 'tcpobex://',\n 'irdaobex://',\n 'file://',\n 'urn:epc:id:',\n 'urn:epc:tag:',\n 'urn:epc:pat:',\n 'urn:epc:raw:',\n 'urn:epc:',\n 'urn:nfc:',\n]\n\n/**\n * The URI of a URI record (well-known `U`, or an absolute-URI record), `null`\n * for any other record. Added 1.62.\n */\nexport const ndefUri = (record: NdefRecord): string | null => {\n if (record.tnf === 3) return record.type\n if (record.tnf !== 1 || record.type !== 'U' || record.payload.length === 0)\n return null\n const prefix = uriPrefixes[record.payload[0]] ?? ''\n return prefix + new TextDecoder('utf-8').decode(record.payload.subarray(1))\n}\n\n/**\n * The text and language of a Text record (well-known `T`), `null` for any\n * other record. Added 1.62.\n */\nexport const ndefText = (\n record: NdefRecord,\n): { text: string; lang: string } | null => {\n if (record.tnf !== 1 || record.type !== 'T' || record.payload.length === 0)\n return null\n const status = record.payload[0]\n const langLength = status & 0x3f\n if (1 + langLength > record.payload.length) return null\n const lang = ascii(record.payload.subarray(1, 1 + langLength))\n const text = new TextDecoder(status & 0x80 ? 'utf-16be' : 'utf-8').decode(\n record.payload.subarray(1 + langLength),\n )\n return { text, lang }\n}\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../Native/index.ts"],"names":[],"mappings":"AA6OA,yFAAyF;AACzF,MAAM,CAAC,MAAM,aAAa,GAAG,CAAE,MAAc,CAAC,aAAa;IACzD,IAAI,CAAyB,CAAA;AAY/B,wFAAwF;AACxF,MAAM,CAAC,MAAM,YAAY,GAAG,GAAY,EAAE,CACxC,OAAO,MAAM,KAAK,WAAW,IAAK,MAAc,CAAC,aAAa,IAAI,IAAI,CAAA;AAExE,4GAA4G;AAC5G,MAAM,CAAC,MAAM,kBAAkB,GAAG,GAAoB,EAAE,CACtD,YAAY,EAAE,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,KAAK,CAAA;AAEnC,MAAM,CAAC,MAAM,qBAAqB,GAAG,CAAC,KAAa,EAAE,YAAoB,EAAE,EAAE,CAC3E,WAAW,KAAK,uBAAuB,YAAY,EAAE,CAAA;AAEvD;;;;;;;;;;;;;GAaG;AACH,MAAM,CAAC,MAAM,wBAAwB,GAAG,CACtC,EAAM,EACN,IAAsB,EACL,EAAE,CACnB,IAAI,OAAO,CAAS,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE,CACtC,EAAE,CAAC,YAAY,CAAC,IAAI,EAAE,CAAC,KAAK,EAAE,YAAY,EAAE,EAAE,CAC5C,KAAK,CAAC,CAAC,CAAC,MAAM,CAAC,IAAI,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,O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AC,CAAC,MAAM,CACvE,MAAM,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC,GAAG,UAAU,CAAC,CACxC,CAAA;IACD,OAAO,EAAE,IAAI,EAAE,IAAI,EAAE,CAAA;AACvB,CAAC,CAAA","sourcesContent":["export type StartProcessArgs = {\n path: string\n args: string[]\n ignoreFormatPath?: boolean\n hidden?: boolean\n}\n\nexport type Capture = {\n startCapture: (options: {\n outputFile: string\n audioInput: string\n }) => Promise<void>\n stopCurrentCapture: () => void\n}\n\nexport type ReadBinaryArgs = {\n path: string\n bufferSize?: number\n position?: number\n}\n\nexport type BinaryChunkResult = {\n buffer: ArrayBufferLike\n read: number\n fileSize: number\n position: number\n}\n\nexport type DownloadProgress = {\n /** Bytes written to disk so far. */\n received: number\n /** Total bytes, when the server advertises a `Content-Length`. */\n total?: number\n}\n\nexport type DownloadFileArgs = {\n /** Source URL to fetch. */\n url: string\n /**\n * Destination path inside the app sandbox (e.g. `~/media/cover.png`). The\n * native bridge resolves it through the app path formatter, so it is scoped\n * to `<vitre-data>/apps/<appId>/...` — it cannot escape the app storage.\n */\n path: string\n /** Optional extra request headers. */\n headers?: Record<string, string>\n /** Optional progress callback fired as bytes are streamed to disk. */\n progress?: (progress: DownloadProgress) => void\n}\n\nexport type FileInfoType = 'file' | 'directory'\n\nexport type FileInfo = {\n name: string\n path: string\n type: FileInfoType\n}\nexport type Process = {\n startProcess: (args: StartProcessArgs) => void\n}\n\n/**\n * Native file I/O for the app, exposed at `window.laVitreNative.io`.\n *\n * ⚠️ **Conditioned on the app manifest.** This bridge is injected **only** when\n * the app declares a storage authorization:\n * - **`appsStorage`** — paths are confined to the app's own storage folder\n * (absolute paths, the `~~/` parent escape and `../` traversal are rejected).\n * This is what most apps want.\n * - **`fullStorage`** — unrestricted filesystem access. Use only when strictly\n * necessary.\n *\n * With neither authorization, `laVitreNative.io` is `undefined` — always\n * feature-detect (`laVitreNative?.io`) before use. It is also `undefined` off a\n * native Vitre (`laVitreNative` itself is `null` on web/PWA and the companion,\n * see {@link isNativeHost}). The host adds it shortly after the page starts\n * (an authorization round trip), so a check at load time can miss it.\n *\n * Paths use a `~/` prefix for the app's sandbox root, e.g. `~/data/x.json`; the\n * file written there is served by the Vitre's local web server at\n * {@link getLocalAppStorageUrl}`(appId, 'data/x.json')`.\n */\nexport type IO = {\n readFile: (path: string) => string\n /** True if a file exists at `path` (resolved inside the app sandbox). */\n fileExists: (path: string) => boolean\n /**\n * Write a file to the app sandbox.\n *\n * - Pass a `string` for text content (written as UTF-8).\n * - Pass an `ArrayBuffer` (or any `ArrayBufferLike`) for binary content — the\n * raw bytes are written as-is. Do **not** base64-encode binary data. For a\n * typed array, pass its `.buffer` (e.g. `new Uint8Array(...).buffer`, or\n * `await blob.arrayBuffer()`).\n */\n writeFile: (path: string, content: string | ArrayBufferLike) => void\n list: (path: string) => FileInfo[]\n createFolder: (path: string) => void\n formatPath: (path: string) => string\n deleteFile: (path: string) => void\n readBinaryFileBuffer: (args: ReadBinaryArgs) => Promise<BinaryChunkResult>\n /**\n * Download a URL straight into a file in the app sandbox. Binary-safe: the\n * response body is streamed to disk natively, so nothing is buffered in JS\n * (ideal for large media). Node-style callback `(error, bytesWritten)`.\n *\n * Prefer {@link downloadFileToAppStorage} for a promise-based API.\n */\n downloadFile: (\n args: DownloadFileArgs,\n callback: (error: string | null, bytesWritten: number | null) => void,\n ) => void\n}\n\n/** A serial port as enumerated by `serialport.getSerialPortsWithDescription()`. */\nexport type SerialPortInfo = {\n /** OS port name, e.g. `\"COM3\"`. */\n port: string\n /** Human-readable device caption reported by the OS. */\n description: string\n /**\n * USB vendor id (decimal), or `null` for non-USB ports (e.g. a built-in\n * motherboard serial). Same shape as `navigator.serial` `getInfo()`, so it\n * can be matched against `requestSerialPortAccess` / `requestPort` filters.\n */\n usbVendorId: number | null\n /** USB product id (decimal), or `null` for non-USB ports. */\n usbProductId: number | null\n}\n\n/**\n * Serial-port bridge exposed to apps at `window.laVitreNative.serialport`.\n *\n * ⚠️ **Conditioned on the app manifest.** This bridge is injected **only** when\n * the app declares the `webSerial` authorization in its manifest. For apps it\n * is intentionally read-only: it exposes **only** `getSerialPortsWithDescription`\n * (port enumeration). Opening / reading / writing a port is done through the\n * standard `navigator.serial` Web Serial API (gated by the same authorization),\n * not through this bridge.\n *\n * Always feature-detect before use — the whole object is `undefined` when the\n * app is not authorized:\n *\n * ```ts\n * const sp = laVitreNative?.serialport\n * if (!sp) return // app lacks the `webSerial` authorization\n * const ports = sp.getSerialPortsWithDescription()\n * ```\n */\nexport type SerialPortBridge = {\n getSerialPortsWithDescription: () => SerialPortInfo[]\n}\n\n/** A tag on an NFC reader. Both values are upper-case hex, no separator. */\nexport type NfcTag = {\n /**\n * The tag's UID (4, 7 or 10 bytes: `\"AD9B6846\"`), or `null` when the reader\n * would not give it.\n */\n uid: string | null\n /** The ATR the reader built for the tag (identifies its type: MIFARE, NTAG, DESFire…). */\n atr: string\n /**\n * The tag's NDEF message as read on arrival, records not split: pass it to\n * {@link parseNdefMessage}. Added 1.62.\n * - `null`: the tag holds no NDEF message (never formatted, e.g. a factory\n * MIFARE Classic badge) or it could not be read (lifted mid-read, larger\n * than 4 KB, a tag type the Vitre does not read).\n * - `''`: formatted for NDEF, empty message.\n * - absent: a native Vitre that does not read NDEF (the first releases with\n * `nfc`).\n *\n * Read: NFC Forum Type 2 (Ultralight, NTAG21x), Type 4 (DESFire, ISO 14443-4\n * cards), MIFARE Classic 1K/4K formatted with a MAD and the public NDEF keys.\n */\n ndef?: string | null\n}\n\n/** A PC/SC reader as listed by `nfc.getReaders()`. */\nexport type NfcReader = {\n /** PC/SC reader name, e.g. `\"ACS ACR122U PICC Interface 0\"`. */\n name: string\n /** The tag on it right now, `null` if none. */\n tag: NfcTag | null\n}\n\n/** What `nfc.addTagHandler` reports. */\nexport type NfcEvent =\n | ({ type: 'tagPresent'; reader: string } & NfcTag)\n | { type: 'tagRemoved' | 'readerAdded' | 'readerRemoved'; reader: string }\n\n/**\n * NFC bridge exposed to apps at `window.laVitreNative.nfc`, on a native Vitre\n * 26.11.3 or later (26.11.2 and older do not have it). It reports badges and tags put on a USB NFC reader (any PC/SC\n * contactless reader: ACS ACR122U / ACR1252U, Identiv, HID Omnikey…).\n *\n * ⚠️ **Conditioned on the app manifest.** Injected **only** when the app\n * declares the `nfc` authorization, and only on a native (Windows) Vitre: no\n * browser API reaches these readers, so there is none on web/PWA or the\n * companion. It arrives shortly after load (an authorization round trip):\n * prefer {@link watchNfcTags}, which waits for it.\n *\n * Read-only: the UID and the ATR, never a channel to send commands to the\n * card. Contact smart cards and virtual ones (Windows Hello) are not reported.\n * Every reader of the machine is listed; pick yours by name if there are\n * several.\n */\nexport type NfcBridge = {\n getReaders: () => NfcReader[]\n /** Returns an id for {@link NfcBridge.removeTagHandler}. */\n addTagHandler: (handler: (event: NfcEvent) => void) => string\n removeTagHandler: (id: string) => void\n}\n\nexport type LaVitreNative = {\n process: Process\n /**\n * File I/O. Present **only** when the app holds the `appsStorage` (sandboxed)\n * or `fullStorage` (unrestricted) authorization — otherwise `undefined`.\n * Feature-detect before calling. See {@link IO}.\n */\n io?: IO\n capture: Capture\n /**\n * Serial-port enumeration. Present **only** when the app holds the\n * `webSerial` authorization in its manifest — otherwise `undefined`.\n * Feature-detect before calling. See {@link SerialPortBridge}.\n */\n serialport?: SerialPortBridge\n /**\n * NFC tags on a USB reader. Present **only** when the app holds the `nfc`\n * authorization, on a native Vitre 26.11.3 or later — otherwise `undefined`.\n * See {@link NfcBridge} and {@link watchNfcTags}.\n */\n nfc?: NfcBridge\n}\n\n/** The native bridge, `null` off a native Vitre (the host leaves the property unset). */\nexport const laVitreNative = ((window as any).laVitreNative ??\n null) as LaVitreNative | null\n\n/**\n * Where the app runs:\n * - `native`: the desktop Vitre (CEF shell). It injects `window.laVitreNative`\n * into every app frame before any script runs, whatever the app manifest —\n * only its members depend on the platform and on the authorizations.\n * - `web`: a Vitre in a browser or installed as a PWA, the companion, or any\n * page outside la Vitre. No native bridge.\n */\nexport type HostEnvironment = 'native' | 'web'\n\n/** True on a native (desktop) Vitre, where `laVitreNative` is available. Added 1.53. */\nexport const isNativeHost = (): boolean =>\n typeof window !== 'undefined' && (window as any).laVitreNative != null\n\n/** `native` on a native (desktop) Vitre, `web` everywhere else. See {@link HostEnvironment}. Added 1.53. */\nexport const getHostEnvironment = (): HostEnvironment =>\n isNativeHost() ? 'native' : 'web'\n\nexport const getLocalAppStorageUrl = (appId: string, relativePath: string) =>\n `https://${appId}.local.app.lavit.re/${relativePath}`\n\n/**\n * Promise wrapper around {@link IO.downloadFile}. Resolves to the number of\n * bytes written, rejects with the native error.\n *\n * ```ts\n * import { laVitreNative, downloadFileToAppStorage } from '@lavitre/apps/Native'\n * if (laVitreNative)\n * await downloadFileToAppStorage(laVitreNative.io, {\n * url: 'https://storage.lavit.re/apps/my-app/cover.png',\n * path: '~/media/cover.png',\n * progress: ({ received, total }) => console.log(received, total),\n * })\n * ```\n */\nexport const downloadFileToAppStorage = (\n io: IO,\n args: DownloadFileArgs,\n): Promise<number> =>\n new Promise<number>((resolve, reject) =>\n io.downloadFile(args, (error, bytesWritten) =>\n error ? reject(new Error(error)) : resolve(bytesWritten ?? 0),\n ),\n )\n\nexport type WatchNfcTagsOptions = {\n /** Keep only the readers this accepts (by PC/SC name). Default: every reader. */\n reader?: (name: string) => boolean\n /**\n * How long to wait for `laVitreNative.nfc`, which the host adds shortly after\n * load. Default 10 000 ms.\n */\n waitMs?: number\n /**\n * Called once when the bridge never showed up: not a native Vitre, no `nfc`\n * authorization in the manifest, or a native Vitre without the bridge (26.11.2\n * and older).\n */\n onUnavailable?: () => void\n}\n\nconst nfcBridgeNow = (): NfcBridge | undefined =>\n typeof window === 'undefined'\n ? undefined\n : ((window as any).laVitreNative?.nfc ?? undefined)\n\n/**\n * Follow the tags put on and lifted from the NFC readers. Added 1.60.\n *\n * - Waits for `laVitreNative.nfc` (see {@link WatchNfcTagsOptions.waitMs}).\n * - A tag already on a reader when watching starts is reported as `tagPresent`.\n * - A `tagPresent` repeated for a tag already reported is dropped.\n * - The handler is never called before `watchNfcTags` has returned, so it can\n * always call the returned `stop()`. An exception it throws is logged with\n * `console.error` and does not stop the watch (since 1.60.1).\n *\n * ```ts\n * import { watchNfcTags } from '@lavitre/apps/Native'\n * const stop = watchNfcTags(\n * (e) => { if (e.type === 'tagPresent') console.log('badge', e.uid) },\n * { onUnavailable: () => console.log('no NFC on this Vitre') },\n * )\n * // later: stop()\n * ```\n *\n * Returns a function that stops watching (and stops waiting).\n */\nexport const watchNfcTags = (\n handler: (event: NfcEvent) => void,\n options: WatchNfcTagsOptions = {},\n): (() => void) => {\n const accepts = options.reader ?? (() => true)\n const waitMs = options.waitMs ?? 10_000\n const tagOn = new Map<string, string | null>() // reader → uid of the tag reported on it\n let stopped = false\n let detach: (() => void) | undefined\n let timer: ReturnType<typeof setTimeout> | undefined\n\n const deliver = (event: NfcEvent) => {\n if (stopped || !accepts(event.reader)) return\n if (event.type === 'tagPresent') {\n if (tagOn.has(event.reader) && tagOn.get(event.reader) === event.uid)\n return\n tagOn.set(event.reader, event.uid)\n } else if (event.type === 'tagRemoved' || event.type === 'readerRemoved') {\n if (event.type === 'tagRemoved' && !tagOn.has(event.reader)) return\n tagOn.delete(event.reader)\n }\n try {\n handler(event)\n } catch (error) {\n console.error('[@lavitre/apps] watchNfcTags handler threw', error)\n }\n }\n\n const attach = (nfc: NfcBridge) => {\n // Handler first: the replay below cannot miss an arrival in between, and\n // `deliver` drops the duplicate if both see the same tag.\n const id = nfc.addTagHandler(deliver)\n detach = () => nfc.removeTagHandler(id)\n for (const reader of nfc.getReaders()) {\n if (reader.tag)\n deliver({ type: 'tagPresent', reader: reader.name, ...reader.tag })\n }\n }\n\n const startedAt = Date.now()\n const poll = () => {\n if (stopped) return\n const nfc = nfcBridgeNow()\n if (nfc) {\n attach(nfc)\n } else if (Date.now() - startedAt >= waitMs) {\n options.onUnavailable?.()\n } else {\n timer = setTimeout(poll, 200)\n }\n }\n // Not synchronously: with the bridge already there and a tag on a reader,\n // the replay would call the handler before the caller holds `stop`.\n queueMicrotask(poll)\n\n return () => {\n stopped = true\n if (timer !== undefined) clearTimeout(timer)\n detach?.()\n detach = undefined\n }\n}\n\n// ---------------------------------------------------------------------------\n// NDEF (1.62)\n// ---------------------------------------------------------------------------\n\n/** One record of an NDEF message (NFC Forum NDEF 1.0). Chunked records come back joined. */\nexport type NdefRecord = {\n /**\n * Type Name Format: 0 empty, 1 NFC Forum well-known (`type` `T` text, `U` URI…),\n * 2 MIME type (`type` e.g. `text/vcard`), 3 absolute URI, 4 NFC Forum external\n * (`type` e.g. `example.com:badge`), 5 unknown.\n */\n tnf: number\n /** The record type, read as ASCII. */\n type: string\n /** The record id, read as ASCII, `''` when none. */\n id: string\n payload: Uint8Array\n}\n\nconst hexToBytes = (hex: string): Uint8Array | null => {\n if (hex.length % 2 !== 0 || !/^[0-9a-fA-F]*$/.test(hex)) return null\n const bytes = new Uint8Array(hex.length / 2)\n for (let i = 0; i < bytes.length; i++)\n bytes[i] = Number.parseInt(hex.slice(2 * i, 2 * i + 2), 16)\n return bytes\n}\n\nconst ascii = (bytes: Uint8Array): string => String.fromCharCode(...bytes)\n\n/**\n * Split an NDEF message ({@link NfcTag.ndef}) into its records. `[]` for an\n * empty message; `null` when the bytes are not a well-formed message (bad hex,\n * a record running past the end, a broken chunk sequence). Added 1.62.\n *\n * ```ts\n * const records = e.ndef ? parseNdefMessage(e.ndef) : null\n * const url = records?.map(ndefUri).find((u) => u)\n * ```\n */\nexport const parseNdefMessage = (hex: string): NdefRecord[] | null => {\n const bytes = hexToBytes(hex)\n if (!bytes) return null\n const records: NdefRecord[] = []\n let chunk: { record: NdefRecord; parts: Uint8Array[] } | null = null\n let i = 0\n while (i < bytes.length) {\n const header = bytes[i]\n const messageEnd = (header & 0x40) !== 0\n const chunked = (header & 0x20) !== 0\n const short = (header & 0x10) !== 0\n const hasId = (header & 0x08) !== 0\n const tnf = header & 0x07\n let at = i + 1\n if (at >= bytes.length) return null\n const typeLength = bytes[at++]\n let payloadLength: number\n if (short) {\n if (at >= bytes.length) return null\n payloadLength = bytes[at++]\n } else {\n if (at + 4 > bytes.length) return null\n payloadLength =\n ((bytes[at] << 24) |\n (bytes[at + 1] << 16) |\n (bytes[at + 2] << 8) |\n bytes[at + 3]) >>>\n 0\n at += 4\n }\n let idLength = 0\n if (hasId) {\n if (at >= bytes.length) return null\n idLength = bytes[at++]\n }\n const end = at + typeLength + idLength + payloadLength\n if (end > bytes.length) return null\n const type = ascii(bytes.subarray(at, at + typeLength))\n const id = ascii(\n bytes.subarray(at + typeLength, at + typeLength + idLength),\n )\n const payload = bytes.slice(at + typeLength + idLength, end)\n\n if (chunk) {\n // A middle or last chunk: TNF \"unchanged\" (6), no type.\n if (tnf !== 6 || typeLength !== 0) return null\n chunk.parts.push(payload)\n if (!chunked) {\n const total = chunk.parts.reduce((n, p) => n + p.length, 0)\n const joined = new Uint8Array(total)\n let offset = 0\n for (const part of chunk.parts) {\n joined.set(part, offset)\n offset += part.length\n }\n records.push({ ...chunk.record, payload: joined })\n chunk = null\n }\n } else if (chunked) {\n chunk = { record: { tnf, type, id, payload }, parts: [payload] }\n } else {\n if (tnf === 6) return null\n records.push({ tnf, type, id, payload })\n }\n\n i = end\n if (messageEnd) break\n }\n\n return chunk ? null : records\n}\n\n/** URI identifier codes of the NFC Forum URI record (RTD-URI), 0x00–0x23. */\nconst uriPrefixes = [\n '',\n 'http://www.',\n 'https://www.',\n 'http://',\n 'https://',\n 'tel:',\n 'mailto:',\n 'ftp://anonymous:anonymous@',\n 'ftp://ftp.',\n 'ftps://',\n 'sftp://',\n 'smb://',\n 'nfs://',\n 'ftp://',\n 'dav://',\n 'news:',\n 'telnet://',\n 'imap:',\n 'rtsp://',\n 'urn:',\n 'pop:',\n 'sip:',\n 'sips:',\n 'tftp:',\n 'btspp://',\n 'btl2cap://',\n 'btgoep://',\n 'tcpobex://',\n 'irdaobex://',\n 'file://',\n 'urn:epc:id:',\n 'urn:epc:tag:',\n 'urn:epc:pat:',\n 'urn:epc:raw:',\n 'urn:epc:',\n 'urn:nfc:',\n]\n\n/**\n * The URI of a URI record (well-known `U`, or an absolute-URI record), `null`\n * for any other record. Added 1.62.\n */\nexport const ndefUri = (record: NdefRecord): string | null => {\n if (record.tnf === 3) return record.type\n if (record.tnf !== 1 || record.type !== 'U' || record.payload.length === 0)\n return null\n const prefix = uriPrefixes[record.payload[0]] ?? ''\n return prefix + new TextDecoder('utf-8').decode(record.payload.subarray(1))\n}\n\n/**\n * The text and language of a Text record (well-known `T`), `null` for any\n * other record. Added 1.62.\n */\nexport const ndefText = (\n record: NdefRecord,\n): { text: string; lang: string } | null => {\n if (record.tnf !== 1 || record.type !== 'T' || record.payload.length === 0)\n return null\n const status = record.payload[0]\n const langLength = status & 0x3f\n if (1 + langLength > record.payload.length) return null\n const lang = ascii(record.payload.subarray(1, 1 + langLength))\n const text = new TextDecoder(status & 0x80 ? 'utf-16be' : 'utf-8').decode(\n record.payload.subarray(1 + langLength),\n )\n return { text, lang }\n}\n"]}
package/dist/Version.d.ts CHANGED
@@ -1 +1 @@
1
- export declare const apiVersion = "1.62.0";
1
+ export declare const apiVersion = "1.62.1";
package/dist/Version.js CHANGED
@@ -1,2 +1,2 @@
1
- export const apiVersion = '1.62.0';
1
+ export const apiVersion = '1.62.1';
2
2
  //# sourceMappingURL=Version.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"Version.js","sourceRoot":"","sources":["../Version.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,UAAU,GAAG,QAAQ,CAAA","sourcesContent":["export const apiVersion = '1.62.0'"]}
1
+ {"version":3,"file":"Version.js","sourceRoot":"","sources":["../Version.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,UAAU,GAAG,QAAQ,CAAA","sourcesContent":["export const apiVersion = '1.62.1'"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lavitre/apps",
3
- "version": "1.62.0",
3
+ "version": "1.62.1",
4
4
  "description": "TypeScript SDK for building la Vitre apps (connector, frames, companion, CRDT sync)",
5
5
  "license": "MIT",
6
6
  "type": "module",