@pmate/bridge 0.1.8 → 0.1.9

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pmate/bridge",
3
- "version": "0.1.8",
3
+ "version": "0.1.9",
4
4
  "files": [
5
5
  "src",
6
6
  "global.d.ts"
package/src/index.ts CHANGED
@@ -3,6 +3,8 @@ export * from "./SafeAreaVarsProvider"
3
3
  export * from "./hooks"
4
4
  export {
5
5
  openApp,
6
+ getPendingAppOpen,
7
+ onAppOpenRequested,
6
8
  cancelAlarm,
7
9
  cancelAllAlarms,
8
10
  connectBluetoothDevice,
package/src/internal.ts CHANGED
@@ -253,5 +253,26 @@ export async function openApp(options: import("./types").OpenAppOptions): Promis
253
253
  if ((url.protocol !== "https:" && !(local && url.protocol === "http:")) || url.username || url.password) {
254
254
  return Promise.reject(new Error("App URL must use HTTPS (or loopback HTTP) without credentials"))
255
255
  }
256
- return requireBridge<import("./types").OpenAppResult>("container.openApp", { url: url.href })
256
+ const notificationId = options.notificationId
257
+ if (notificationId !== undefined && (!notificationId || notificationId.length > 512)) throw new Error("Invalid notification ID")
258
+ const result = await requireBridge<import("./types").OpenAppResult>("container.openApp", { url: url.href, ...(notificationId === undefined ? {} : { notificationId }) })
259
+ if (result?.opened !== true) throw new Error("Native app opening was not confirmed")
260
+ return result
261
+ }
262
+
263
+ /** Available only to a native host's designated launcher. Older hosts reject it. */
264
+ export async function getPendingAppOpen(): Promise<import("./types").AppOpenIntent | null> {
265
+ const result = await requireBridge<import("./types").AppOpenIntent | null>("container.getPendingAppOpen")
266
+ if (result === null) return null
267
+ if (!result || typeof result.appId !== "string" || !result.appId || result.appId.length > 128
268
+ || typeof result.notificationId !== "string" || !result.notificationId || result.notificationId.length > 512
269
+ || typeof result.origin !== "string" || result.origin.length > 2048) throw new Error("Invalid application notification")
270
+ const origin = new URL(result.origin)
271
+ if (origin.protocol !== "https:" || origin.username || origin.password || origin.pathname !== "/" || origin.search || origin.hash) throw new Error("Invalid application notification origin")
272
+ return { appId: result.appId, notificationId: result.notificationId, origin: origin.origin }
273
+ }
274
+
275
+ /** A hint to re-read the pending intent; the event itself never supplies a URL to open. */
276
+ export function onAppOpenRequested(handler: () => void): () => void {
277
+ return hasWindow() ? (window as PmateWindow).PmateBridge?.on?.("container.appOpenRequested", handler) ?? (() => {}) : () => {}
257
278
  }
package/src/types.ts CHANGED
@@ -209,5 +209,7 @@ export interface BluetoothDataEvent {
209
209
  }
210
210
 
211
211
  /** Opens a separate native WebView. The caller resolves the app URL via the apps API. */
212
- export interface OpenAppOptions { url: string }
212
+ export interface OpenAppOptions { url: string; notificationId?: string }
213
213
  export interface OpenAppResult { opened: true }
214
+ /** Destination only; notification content is delivered to the target app after authentication. */
215
+ export interface AppOpenIntent { appId: string; notificationId: string; origin: string }