From 82e23925c0ad3ab6394f17ef4de526e8cce7f534 Mon Sep 17 00:00:00 2001 From: kevz Date: Wed, 4 Mar 2026 14:39:47 +0800 Subject: [PATCH 1/4] Add masterlock plugin --- package.json | 2 +- src/index.ts | 2 + src/plugins/masterlock.ts | 67 +++++++++++++++++++++++++ src/types/masterlock.ts | 103 ++++++++++++++++++++++++++++++++++++++ 4 files changed, 173 insertions(+), 1 deletion(-) create mode 100644 src/plugins/masterlock.ts create mode 100644 src/types/masterlock.ts diff --git a/package.json b/package.json index 0f4fccd..30d6b99 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "median-js-bridge", - "version": "2.13.4", + "version": "2.13.5", "description": "Median bridge and utilities for JS web frameworks", "main": "dist/index.js", "types": "dist/index.d.ts", diff --git a/src/index.ts b/src/index.ts index cde09f4..031d553 100644 --- a/src/index.ts +++ b/src/index.ts @@ -6,6 +6,7 @@ import { ShareToAppData } from './plugins/share.js'; import { createTempFunctionName, setMedianCallback, setSubscription } from './utils.js'; import { HealthBridge as HealthBridgeType } from './types/healthBridge.js'; +import { MasterLock as MasterLockType } from './types/masterlock.js'; namespace Median { /////////////////////////////// @@ -188,4 +189,5 @@ export default Median; /////////////////////////////// export declare namespace Types { export import HealthBridge = HealthBridgeType; + export import MasterLock = MasterLockType; } diff --git a/src/plugins/masterlock.ts b/src/plugins/masterlock.ts new file mode 100644 index 0000000..f805571 --- /dev/null +++ b/src/plugins/masterlock.ts @@ -0,0 +1,67 @@ +import { MasterLock } from '../types/masterlock'; +import { addCallbackFunction, addCommand, addCommandCallback } from '../utils.js'; + +const masterlock = { + initialize: function (params: MasterLock.InitializeParams) { + return addCommandCallback('median://masterlock/initialize', params); + }, + scan: function (params: MasterLock.ScanParams) { + const parameters: Record = {}; + if (params?.onScanStart) { + parameters.onScanStart = addCallbackFunction(params?.onScanStart, true); + } + if (params?.onScanStop) { + parameters.onScanStop = addCallbackFunction(params?.onScanStop, true); + } + if (params?.onDeviceDiscover) { + parameters.onDeviceDiscover = addCallbackFunction(params?.onDeviceDiscover, true); + } + addCommand('median://masterlock/scan', parameters); + }, + unlock: function (params: MasterLock.UnlockParams) { + return addCommandCallback('median://masterlock/unlock', params); + }, + permissionGranted: function () { + return addCommandCallback('median://masterlock/permissionGranted'); + }, + updateFirmware: function (params: MasterLock.UpdateFirmwareParams) { + return addCommandCallback('median://masterlock/updateFirmware', params); + }, + firmwareUpdate: { + addListener: async function (callback: (status: MasterLock.FirmwareUpdateStatus) => void) { + const listenerIdCallback = addCallbackFunction(callback, true); + const result = await addCommandCallback( + 'median://masterlock/firmwareUpdate/addListener', + { listenerIdCallback } + ); + if (!result || !result.listenerId) { + throw 'Invalid listenerId response'; + } else { + return result.listenerId; + } + }, + removeListener: function (listenerId: string) { + addCommand('median://masterlock/firmwareUpdate/removeListener', { listenerId }); + }, + }, + lockReset: function (params: MasterLock.LockResetParams) { + return addCommandCallback('median://masterlock/lockReset', params); + }, + getDeadboltHandedness: function (params: MasterLock.GetDeadBoltHandednessParams) { + return addCommandCallback( + 'median://masterlock/getDeadboltHandedness', + params + ); + }, + setDeadboltHandedness: function (params: MasterLock.SetDeadBoltHandednessParams) { + return addCommandCallback( + 'median://masterlock/setDeadboltHandedness', + params + ); + }, + relock: function (params: MasterLock.RelockParams) { + return addCommandCallback('median://masterlock/relock', params); + }, +}; + +export default masterlock; diff --git a/src/types/masterlock.ts b/src/types/masterlock.ts new file mode 100644 index 0000000..47e3f8b --- /dev/null +++ b/src/types/masterlock.ts @@ -0,0 +1,103 @@ +export namespace MasterLock { + export type InitializeParams = { + license: string; + }; + + export type InitializeResponse = { + success: boolean; + }; + + export type ScanParams = { + onScanStart?: () => void; + onScanStop?: () => void; + onDeviceDiscover?: () => void; + timeout?: number; + }; + + export type UnlockParams = { + accessProfile: string; + deviceId: string; + firmwareVersion: number | string; + mechanism: "primary" | "secondary"; + timeout?: number; + }; + + export type UnlockResponse = { + success: boolean; + }; + + export type PermissionResponse = { + granted: boolean; + }; + + export type UpdateFirmwareParams = { + accessProfile: string; + deviceId: string; + firmwareVersion: number | string; + targetFirmwareVersion: number | string; + timeout?: number; + }; + + export type UpdateFirmwareResponse = { + success: boolean; + }; + + export type FirmwareUpdateStatus = { + deviceId: string; + state: string; + } + + export type FirmwareUpdateAddListenerResponse = { + listenerId: string; + }; + + export type LockResetParams = { + accessProfile: string; + deviceId: string; + firmwareVersion: number | string; + timeout?: number; + }; + + export type LockResetResponse = { + success: boolean; + }; + + export type GetDeadBoltHandednessParams = { + accessProfile: string; + deviceId: string; + firmwareVersion: number | string; + timeout?: number; + }; + + export type GetDeadBoltHandednessResponse = { + deviceId: string; + handedness: "left" | "right"; + success: boolean; + }; + + export type SetDeadBoltHandednessParams = { + accessProfile: string; + deviceId: string; + firmwareVersion: number | string; + handedness: "left" | "right"; + timeout?: number; + }; + + export type SetDeadBoltHandednessResponse = { + deviceId: string; + handedness: "left" | "right"; + success: boolean; + }; + + export type RelockParams = { + accessProfile: string; + deviceId: string; + firmwareVersion: number | string; + timeout?: number; + }; + + export type RelockResponse = { + deviceId: string; + success: boolean; + }; +} From 2dee5c977702e4ffc19052b636bd4de8e3a3b0cc Mon Sep 17 00:00:00 2001 From: kevz Date: Wed, 4 Mar 2026 14:44:22 +0800 Subject: [PATCH 2/4] Export masterlock --- .gitignore | 1 + src/index.ts | 1 + src/plugins/index.ts | 1 + 3 files changed, 3 insertions(+) diff --git a/.gitignore b/.gitignore index ac626ff..4fc2b9b 100644 --- a/.gitignore +++ b/.gitignore @@ -3,3 +3,4 @@ node_modules dist/ build/ .idea +median-js-bridge-*.tgz \ No newline at end of file diff --git a/src/index.ts b/src/index.ts index 031d553..a062f1d 100644 --- a/src/index.ts +++ b/src/index.ts @@ -112,6 +112,7 @@ namespace Median { export const keychainSwift = plugins.keychainSwift; export const klaviyo = plugins.klaviyo; export const localpreferences = plugins.localpreferences; + export const masterlock = plugins.masterlock; export const modal = plugins.modal; export const moengage = plugins.moengage; export const moxo = plugins.moxo; diff --git a/src/plugins/index.ts b/src/plugins/index.ts index f61b3f7..344461a 100644 --- a/src/plugins/index.ts +++ b/src/plugins/index.ts @@ -33,6 +33,7 @@ export { default as kaltura } from './kaltura.js'; export { default as keychainSwift } from './keychainSwift.js'; export { default as klaviyo } from './klaviyo.js'; export { default as localpreferences } from './localSettings.js'; +export { default as masterlock } from './masterlock.js'; export { default as modal } from './modal.js'; export { default as moengage } from './moengage.js'; export { default as moxo } from './moxo.js'; From eaf733c0ce8f7571688c4f5cd054f45b4f9a9db1 Mon Sep 17 00:00:00 2001 From: kevz Date: Wed, 4 Mar 2026 19:57:37 +0800 Subject: [PATCH 3/4] Update imports --- src/plugins/healthBridge.ts | 2 +- src/plugins/masterlock.ts | 2 +- src/utils.ts | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/plugins/healthBridge.ts b/src/plugins/healthBridge.ts index 0569f09..a662ff3 100644 --- a/src/plugins/healthBridge.ts +++ b/src/plugins/healthBridge.ts @@ -1,4 +1,4 @@ -import { HealthBridge } from '../types/healthBridge'; +import { HealthBridge } from '../types/healthBridge.js'; import { addCommandCallback } from '../utils.js'; /** diff --git a/src/plugins/masterlock.ts b/src/plugins/masterlock.ts index f805571..98dc893 100644 --- a/src/plugins/masterlock.ts +++ b/src/plugins/masterlock.ts @@ -1,4 +1,4 @@ -import { MasterLock } from '../types/masterlock'; +import { MasterLock } from '../types/masterlock.js'; import { addCallbackFunction, addCommand, addCommandCallback } from '../utils.js'; const masterlock = { diff --git a/src/utils.ts b/src/utils.ts index 97c1993..02ee453 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -1,4 +1,4 @@ -import { AnyData } from './types'; +import { AnyData } from './types/index.js'; interface JSBridgeType { postMessage?: (data: string) => void; From c2b2e075ff79f8d0f15bb7c09c4dad8fa30fcb11 Mon Sep 17 00:00:00 2001 From: kevz Date: Wed, 4 Mar 2026 20:06:45 +0800 Subject: [PATCH 4/4] Update exporting of types --- src/index.ts | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/src/index.ts b/src/index.ts index a062f1d..ac39b29 100644 --- a/src/index.ts +++ b/src/index.ts @@ -5,9 +5,6 @@ import { InAppPurchaseInfoReadyData } from './plugins/iap.js'; import { ShareToAppData } from './plugins/share.js'; import { createTempFunctionName, setMedianCallback, setSubscription } from './utils.js'; -import { HealthBridge as HealthBridgeType } from './types/healthBridge.js'; -import { MasterLock as MasterLockType } from './types/masterlock.js'; - namespace Median { /////////////////////////////// // Internal // @@ -188,7 +185,5 @@ export default Median; /////////////////////////////// // Types // /////////////////////////////// -export declare namespace Types { - export import HealthBridge = HealthBridgeType; - export import MasterLock = MasterLockType; -} +export { HealthBridge } from './types/healthBridge.js'; +export { MasterLock } from './types/masterlock.js';