edilkamin 1.7.3 → 1.8.0

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.
Files changed (77) hide show
  1. package/.github/workflows/cli-tests.yml +6 -0
  2. package/README.md +36 -3
  3. package/dist/cjs/package.json +95 -0
  4. package/dist/cjs/src/bluetooth-utils.d.ts +13 -0
  5. package/dist/cjs/src/bluetooth-utils.js +28 -0
  6. package/dist/cjs/src/bluetooth-utils.test.js +35 -0
  7. package/dist/cjs/src/bluetooth.d.ts +40 -0
  8. package/dist/cjs/src/bluetooth.js +107 -0
  9. package/dist/cjs/src/browser-bundle.test.js +64 -0
  10. package/dist/cjs/src/buffer-utils.js +78 -0
  11. package/dist/cjs/src/buffer-utils.test.js +186 -0
  12. package/dist/cjs/src/cli.js +253 -0
  13. package/dist/cjs/src/configureAmplify.test.js +42 -0
  14. package/dist/cjs/src/constants.js +9 -0
  15. package/dist/{esm → cjs/src}/index.d.ts +2 -1
  16. package/dist/cjs/src/index.js +24 -0
  17. package/dist/cjs/src/library.js +324 -0
  18. package/dist/cjs/src/library.test.js +547 -0
  19. package/dist/cjs/src/serial-utils.js +50 -0
  20. package/dist/cjs/src/serial-utils.test.js +50 -0
  21. package/dist/cjs/src/token-storage.js +119 -0
  22. package/dist/{esm → cjs/src}/types.d.ts +14 -1
  23. package/dist/cjs/src/types.js +2 -0
  24. package/dist/esm/package.json +95 -0
  25. package/dist/esm/src/bluetooth-utils.d.ts +13 -0
  26. package/dist/esm/src/bluetooth-utils.js +25 -0
  27. package/dist/esm/src/bluetooth-utils.test.d.ts +1 -0
  28. package/dist/esm/src/bluetooth-utils.test.js +33 -0
  29. package/dist/esm/src/bluetooth.d.ts +40 -0
  30. package/dist/esm/src/bluetooth.js +100 -0
  31. package/dist/esm/src/browser-bundle.test.d.ts +1 -0
  32. package/dist/esm/{browser-bundle.test.js → src/browser-bundle.test.js} +1 -1
  33. package/dist/esm/src/buffer-utils.d.ts +25 -0
  34. package/dist/esm/src/buffer-utils.test.d.ts +1 -0
  35. package/dist/esm/src/cli.d.ts +3 -0
  36. package/dist/esm/src/configureAmplify.test.d.ts +1 -0
  37. package/dist/esm/src/constants.d.ts +4 -0
  38. package/dist/esm/src/index.d.ts +7 -0
  39. package/dist/esm/{index.js → src/index.js} +1 -0
  40. package/dist/esm/src/library.d.ts +55 -0
  41. package/dist/esm/src/library.test.d.ts +1 -0
  42. package/dist/esm/src/serial-utils.d.ts +33 -0
  43. package/dist/esm/src/serial-utils.test.d.ts +1 -0
  44. package/dist/esm/src/token-storage.d.ts +14 -0
  45. package/dist/esm/src/types.d.ts +86 -0
  46. package/dist/esm/src/types.js +1 -0
  47. package/package.json +22 -11
  48. package/src/bluetooth-utils.test.ts +46 -0
  49. package/src/bluetooth-utils.ts +29 -0
  50. package/src/bluetooth.ts +115 -0
  51. package/src/browser-bundle.test.ts +1 -1
  52. package/src/index.ts +2 -0
  53. package/src/types.ts +15 -0
  54. package/tsconfig.cjs.json +2 -2
  55. package/tsconfig.json +3 -3
  56. /package/dist/{esm/browser-bundle.test.d.ts → cjs/src/bluetooth-utils.test.d.ts} +0 -0
  57. /package/dist/{esm/buffer-utils.test.d.ts → cjs/src/browser-bundle.test.d.ts} +0 -0
  58. /package/dist/{esm → cjs/src}/buffer-utils.d.ts +0 -0
  59. /package/dist/{esm/configureAmplify.test.d.ts → cjs/src/buffer-utils.test.d.ts} +0 -0
  60. /package/dist/{esm → cjs/src}/cli.d.ts +0 -0
  61. /package/dist/{esm/library.test.d.ts → cjs/src/configureAmplify.test.d.ts} +0 -0
  62. /package/dist/{esm → cjs/src}/constants.d.ts +0 -0
  63. /package/dist/{esm → cjs/src}/library.d.ts +0 -0
  64. /package/dist/{esm/serial-utils.test.d.ts → cjs/src/library.test.d.ts} +0 -0
  65. /package/dist/{esm → cjs/src}/serial-utils.d.ts +0 -0
  66. /package/dist/{esm/types.js → cjs/src/serial-utils.test.d.ts} +0 -0
  67. /package/dist/{esm → cjs/src}/token-storage.d.ts +0 -0
  68. /package/dist/esm/{buffer-utils.js → src/buffer-utils.js} +0 -0
  69. /package/dist/esm/{buffer-utils.test.js → src/buffer-utils.test.js} +0 -0
  70. /package/dist/esm/{cli.js → src/cli.js} +0 -0
  71. /package/dist/esm/{configureAmplify.test.js → src/configureAmplify.test.js} +0 -0
  72. /package/dist/esm/{constants.js → src/constants.js} +0 -0
  73. /package/dist/esm/{library.js → src/library.js} +0 -0
  74. /package/dist/esm/{library.test.js → src/library.test.js} +0 -0
  75. /package/dist/esm/{serial-utils.js → src/serial-utils.js} +0 -0
  76. /package/dist/esm/{serial-utils.test.js → src/serial-utils.test.js} +0 -0
  77. /package/dist/esm/{token-storage.js → src/token-storage.js} +0 -0
@@ -18,3 +18,9 @@ jobs:
18
18
  node-version: ${{ matrix.node-version }}
19
19
  - run: yarn install --no-ignore-optional
20
20
  - run: yarn cli --help
21
+ - run: yarn build
22
+ - run: node dist/cjs/src/cli.js --help
23
+ - name: Verify CLI binary
24
+ run: |
25
+ test -f dist/cjs/src/cli.js
26
+ grep -q "#!/usr/bin/env node" dist/cjs/src/cli.js
package/README.md CHANGED
@@ -115,6 +115,39 @@ const legacyApi = configure(OLD_API_URL);
115
115
 
116
116
  > **Note**: The legacy API uses AWS API Gateway and may be deprecated in the future.
117
117
 
118
+ ## Bluetooth Device Discovery
119
+
120
+ For automatic device discovery in web browsers, use the `edilkamin/bluetooth` subpath export.
121
+
122
+ ### Quick Example (Web)
123
+
124
+ ```javascript
125
+ import { scanForDevices } from "edilkamin/bluetooth";
126
+ import { deviceInfo, signIn } from "edilkamin";
127
+
128
+ // Scan for nearby stoves (requires user gesture)
129
+ const devices = await scanForDevices();
130
+ const { wifiMac } = devices[0];
131
+
132
+ // Use discovered MAC for API calls
133
+ const token = await signIn(username, password);
134
+ const info = await deviceInfo(token, wifiMac);
135
+ ```
136
+
137
+ ### MAC Address Helper
138
+
139
+ The core library includes a helper to convert BLE MAC to WiFi MAC:
140
+
141
+ ```javascript
142
+ import { bleToWifiMac } from "edilkamin";
143
+
144
+ // BLE MAC from Bluetooth scan
145
+ const bleMac = "A8:03:2A:FE:D5:0A";
146
+
147
+ // WiFi MAC for API calls (BLE - 2)
148
+ const wifiMac = bleToWifiMac(bleMac); // "a8032afed508"
149
+ ```
150
+
118
151
  ## Motivations
119
152
 
120
153
  - providing an open source web alternative
@@ -132,6 +165,6 @@ const legacyApi = configure(OLD_API_URL);
132
165
 
133
166
  ## Limitations
134
167
 
135
- It seems like there's no endpoint to list stoves associated to a user.
136
- The way the official app seem to work is by probing the stove via bluetooth.
137
- Then cache the stove MAC address to a local database for later use.
168
+ - **No server-side device listing**: The API doesn't provide an endpoint to list stoves associated to a user.
169
+ - **Bluetooth discovery available**: Use `edilkamin/bluetooth` for web browser device discovery, similar to the official app.
170
+ - **Manual MAC entry fallback**: For unsupported browsers or CLI, users can find the BLE MAC with different means and use `bleToWifiMac()` to calculate the WiFi MAC for API calls.
@@ -0,0 +1,95 @@
1
+ {
2
+ "name": "edilkamin",
3
+ "version": "1.8.0",
4
+ "description": "",
5
+ "main": "dist/cjs/src/index.js",
6
+ "module": "dist/esm/src/index.js",
7
+ "types": "dist/esm/src/index.d.ts",
8
+ "exports": {
9
+ ".": {
10
+ "import": {
11
+ "types": "./dist/esm/src/index.d.ts",
12
+ "default": "./dist/esm/src/index.js"
13
+ },
14
+ "require": {
15
+ "types": "./dist/cjs/src/index.d.ts",
16
+ "default": "./dist/cjs/src/index.js"
17
+ }
18
+ },
19
+ "./bluetooth": {
20
+ "import": {
21
+ "types": "./dist/esm/src/bluetooth.d.ts",
22
+ "default": "./dist/esm/src/bluetooth.js"
23
+ },
24
+ "require": {
25
+ "types": "./dist/cjs/src/bluetooth.d.ts",
26
+ "default": "./dist/cjs/src/bluetooth.js"
27
+ }
28
+ }
29
+ },
30
+ "scripts": {
31
+ "cli": "ts-node src/cli.ts",
32
+ "cli:debug": "node --inspect --require ts-node/register/transpile-only src/cli.ts",
33
+ "test": "nyc mocha --require ts-node/register src/*.test.ts",
34
+ "test:debug": "nyc mocha --require ts-node/register/transpile-only --inspect src/*.test.ts",
35
+ "lint:prettier": "prettier --check src docs .github *.json *.md *.mjs",
36
+ "format:prettier": "prettier --write src docs .github *.json *.md *.mjs",
37
+ "lint:eslint": "eslint src",
38
+ "format:eslint": "eslint --fix src",
39
+ "lint": "yarn lint:prettier && yarn lint:eslint",
40
+ "format": "yarn format:prettier && yarn format:eslint",
41
+ "build:cjs": "tsc -p tsconfig.cjs.json",
42
+ "build:esm": "tsc -p tsconfig.esm.json",
43
+ "build": "npm run build:cjs && npm run build:esm"
44
+ },
45
+ "repository": {
46
+ "type": "git",
47
+ "url": "git+https://github.com/AndreMiras/edilkamin.js.git"
48
+ },
49
+ "author": "Andre Miras",
50
+ "license": "MIT",
51
+ "bugs": {
52
+ "url": "https://github.com/AndreMiras/edilkamin.js/issues"
53
+ },
54
+ "homepage": "https://github.com/AndreMiras/edilkamin.js#readme",
55
+ "bin": {
56
+ "edilkamin": "dist/cjs/src/cli.js"
57
+ },
58
+ "nyc": {
59
+ "reporter": [
60
+ "html",
61
+ "lcov",
62
+ "text"
63
+ ]
64
+ },
65
+ "dependencies": {
66
+ "aws-amplify": "^6.10.0",
67
+ "pako": "^2.1.0"
68
+ },
69
+ "devDependencies": {
70
+ "@eslint/eslintrc": "^3.2.0",
71
+ "@eslint/js": "^9.16.0",
72
+ "@types/mocha": "^10.0.10",
73
+ "@types/node": "^25.0.2",
74
+ "@types/pako": "^2.0.4",
75
+ "@types/sinon": "^17.0.3",
76
+ "@types/web-bluetooth": "^0.0.21",
77
+ "@typescript-eslint/eslint-plugin": "^8.17.0",
78
+ "@typescript-eslint/parser": "^8.17.0",
79
+ "esbuild": "^0.27.1",
80
+ "eslint": "^9.16.0",
81
+ "eslint-config-prettier": "^10.1.8",
82
+ "eslint-plugin-prettier": "^5.2.1",
83
+ "eslint-plugin-simple-import-sort": "^12.1.1",
84
+ "mocha": "^11.7.5",
85
+ "nyc": "^17.1.0",
86
+ "prettier": "^3.7.4",
87
+ "sinon": "^19.0.2",
88
+ "ts-node": "^10.9.1",
89
+ "typedoc": "^0.28.15",
90
+ "typescript": "^5.7.2"
91
+ },
92
+ "optionalDependencies": {
93
+ "commander": "^14.0.2"
94
+ }
95
+ }
@@ -0,0 +1,13 @@
1
+ /**
2
+ * Converts a BLE MAC address to WiFi MAC address.
3
+ * The WiFi MAC is the BLE MAC minus 2 in hexadecimal.
4
+ *
5
+ * @param bleMac - BLE MAC address (with or without colons/dashes)
6
+ * @returns WiFi MAC address in lowercase without separators
7
+ *
8
+ * @example
9
+ * bleToWifiMac("A8:03:2A:FE:D5:0A") // returns "a8032afed508"
10
+ * bleToWifiMac("a8032afed50a") // returns "a8032afed508"
11
+ */
12
+ declare const bleToWifiMac: (bleMac: string) => string;
13
+ export { bleToWifiMac };
@@ -0,0 +1,28 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.bleToWifiMac = void 0;
4
+ /**
5
+ * Converts a BLE MAC address to WiFi MAC address.
6
+ * The WiFi MAC is the BLE MAC minus 2 in hexadecimal.
7
+ *
8
+ * @param bleMac - BLE MAC address (with or without colons/dashes)
9
+ * @returns WiFi MAC address in lowercase without separators
10
+ *
11
+ * @example
12
+ * bleToWifiMac("A8:03:2A:FE:D5:0A") // returns "a8032afed508"
13
+ * bleToWifiMac("a8032afed50a") // returns "a8032afed508"
14
+ */
15
+ const bleToWifiMac = (bleMac) => {
16
+ // Remove colons, dashes, and convert to lowercase
17
+ const normalized = bleMac.replace(/[:-]/g, "").toLowerCase();
18
+ // Validate MAC address format (12 hex characters)
19
+ if (!/^[0-9a-f]{12}$/.test(normalized)) {
20
+ throw new Error(`Invalid MAC address format: ${bleMac}`);
21
+ }
22
+ // Convert to number, subtract 2, convert back to hex
23
+ const bleValue = BigInt(`0x${normalized}`);
24
+ const wifiValue = bleValue - BigInt(2);
25
+ // Pad to 12 characters and return lowercase
26
+ return wifiValue.toString(16).padStart(12, "0");
27
+ };
28
+ exports.bleToWifiMac = bleToWifiMac;
@@ -0,0 +1,35 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const assert_1 = require("assert");
4
+ const bluetooth_utils_1 = require("./bluetooth-utils");
5
+ describe("bleToWifiMac", () => {
6
+ it("converts BLE MAC with colons to WiFi MAC", () => {
7
+ assert_1.strict.equal((0, bluetooth_utils_1.bleToWifiMac)("A8:03:2A:FE:D5:0A"), "a8032afed508");
8
+ });
9
+ it("converts BLE MAC without separators", () => {
10
+ assert_1.strict.equal((0, bluetooth_utils_1.bleToWifiMac)("a8032afed50a"), "a8032afed508");
11
+ });
12
+ it("converts BLE MAC with dashes", () => {
13
+ assert_1.strict.equal((0, bluetooth_utils_1.bleToWifiMac)("A8-03-2A-FE-D5-0A"), "a8032afed508");
14
+ });
15
+ it("handles lowercase input", () => {
16
+ assert_1.strict.equal((0, bluetooth_utils_1.bleToWifiMac)("a8:03:2a:fe:d5:0a"), "a8032afed508");
17
+ });
18
+ it("handles edge case where subtraction crosses byte boundary", () => {
19
+ // FF:FF:FF:FF:FF:01 - 2 = FF:FF:FF:FF:FE:FF
20
+ assert_1.strict.equal((0, bluetooth_utils_1.bleToWifiMac)("FF:FF:FF:FF:FF:01"), "fffffffffeff");
21
+ });
22
+ it("handles minimum value edge case", () => {
23
+ // 00:00:00:00:00:02 - 2 = 00:00:00:00:00:00
24
+ assert_1.strict.equal((0, bluetooth_utils_1.bleToWifiMac)("00:00:00:00:00:02"), "000000000000");
25
+ });
26
+ it("throws on invalid MAC format - too short", () => {
27
+ assert_1.strict.throws(() => (0, bluetooth_utils_1.bleToWifiMac)("A8:03:2A"), /Invalid MAC address format/);
28
+ });
29
+ it("throws on invalid MAC format - invalid characters", () => {
30
+ assert_1.strict.throws(() => (0, bluetooth_utils_1.bleToWifiMac)("G8:03:2A:FE:D5:0A"), /Invalid MAC address format/);
31
+ });
32
+ it("throws on empty string", () => {
33
+ assert_1.strict.throws(() => (0, bluetooth_utils_1.bleToWifiMac)(""), /Invalid MAC address format/);
34
+ });
35
+ });
@@ -0,0 +1,40 @@
1
+ import { DiscoveredDevice } from "./types";
2
+ /** Device name broadcast by Edilkamin stoves */
3
+ declare const EDILKAMIN_DEVICE_NAME = "EDILKAMIN_EP";
4
+ /** GATT Service UUID for Edilkamin devices (0xABF0) */
5
+ declare const EDILKAMIN_SERVICE_UUID = 44016;
6
+ /**
7
+ * Check if Web Bluetooth API is available in the current browser.
8
+ *
9
+ * @returns true if Web Bluetooth is supported
10
+ */
11
+ declare const isWebBluetoothSupported: () => boolean;
12
+ /**
13
+ * Scan for nearby Edilkamin stoves using the Web Bluetooth API.
14
+ *
15
+ * This function triggers the browser's Bluetooth device picker dialog,
16
+ * filtered to show only devices named "EDILKAMIN_EP".
17
+ *
18
+ * Note: Web Bluetooth requires:
19
+ * - HTTPS or localhost
20
+ * - User gesture (button click)
21
+ * - Chrome/Edge/Opera (not Firefox/Safari)
22
+ *
23
+ * @returns Promise resolving to array of discovered devices
24
+ * @throws Error if Web Bluetooth is not supported or user cancels
25
+ *
26
+ * @example
27
+ * const devices = await scanForDevices();
28
+ * console.log(devices[0].wifiMac); // Use this for API calls
29
+ */
30
+ declare const scanForDevices: () => Promise<DiscoveredDevice[]>;
31
+ /**
32
+ * Scan for devices with a custom filter.
33
+ * Advanced function for users who need more control over device selection.
34
+ *
35
+ * @param options - Web Bluetooth requestDevice options
36
+ * @returns Promise resolving to the selected BluetoothDevice
37
+ */
38
+ declare const scanWithOptions: (options: RequestDeviceOptions) => Promise<BluetoothDevice>;
39
+ export { EDILKAMIN_DEVICE_NAME, EDILKAMIN_SERVICE_UUID, isWebBluetoothSupported, scanForDevices, scanWithOptions, };
40
+ export type { DiscoveredDevice } from "./types";
@@ -0,0 +1,107 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.scanWithOptions = exports.scanForDevices = exports.isWebBluetoothSupported = exports.EDILKAMIN_SERVICE_UUID = exports.EDILKAMIN_DEVICE_NAME = void 0;
13
+ const bluetooth_utils_1 = require("./bluetooth-utils");
14
+ /** Device name broadcast by Edilkamin stoves */
15
+ const EDILKAMIN_DEVICE_NAME = "EDILKAMIN_EP";
16
+ exports.EDILKAMIN_DEVICE_NAME = EDILKAMIN_DEVICE_NAME;
17
+ /** GATT Service UUID for Edilkamin devices (0xABF0) */
18
+ const EDILKAMIN_SERVICE_UUID = 0xabf0;
19
+ exports.EDILKAMIN_SERVICE_UUID = EDILKAMIN_SERVICE_UUID;
20
+ /**
21
+ * Check if Web Bluetooth API is available in the current browser.
22
+ *
23
+ * @returns true if Web Bluetooth is supported
24
+ */
25
+ const isWebBluetoothSupported = () => {
26
+ return typeof navigator !== "undefined" && "bluetooth" in navigator;
27
+ };
28
+ exports.isWebBluetoothSupported = isWebBluetoothSupported;
29
+ /**
30
+ * Scan for nearby Edilkamin stoves using the Web Bluetooth API.
31
+ *
32
+ * This function triggers the browser's Bluetooth device picker dialog,
33
+ * filtered to show only devices named "EDILKAMIN_EP".
34
+ *
35
+ * Note: Web Bluetooth requires:
36
+ * - HTTPS or localhost
37
+ * - User gesture (button click)
38
+ * - Chrome/Edge/Opera (not Firefox/Safari)
39
+ *
40
+ * @returns Promise resolving to array of discovered devices
41
+ * @throws Error if Web Bluetooth is not supported or user cancels
42
+ *
43
+ * @example
44
+ * const devices = await scanForDevices();
45
+ * console.log(devices[0].wifiMac); // Use this for API calls
46
+ */
47
+ const scanForDevices = () => __awaiter(void 0, void 0, void 0, function* () {
48
+ if (!isWebBluetoothSupported()) {
49
+ throw new Error("Web Bluetooth API is not supported in this browser. " +
50
+ "Use Chrome, Edge, or Opera on desktop/Android. " +
51
+ "On iOS, use the Bluefy browser app.");
52
+ }
53
+ try {
54
+ // Request device - this opens the browser's device picker
55
+ const device = yield navigator.bluetooth.requestDevice({
56
+ filters: [{ name: EDILKAMIN_DEVICE_NAME }],
57
+ optionalServices: [EDILKAMIN_SERVICE_UUID],
58
+ });
59
+ // Extract BLE MAC from device ID if available
60
+ // Note: device.id format varies by platform, may need adjustment
61
+ const bleMac = device.id || "";
62
+ const name = device.name || EDILKAMIN_DEVICE_NAME;
63
+ // Calculate WiFi MAC for API calls
64
+ let wifiMac = "";
65
+ if (bleMac && /^[0-9a-f:-]{12,17}$/i.test(bleMac)) {
66
+ try {
67
+ wifiMac = (0, bluetooth_utils_1.bleToWifiMac)(bleMac);
68
+ }
69
+ catch (_a) {
70
+ // device.id may not be a valid MAC format on all platforms
71
+ wifiMac = "";
72
+ }
73
+ }
74
+ const discoveredDevice = {
75
+ bleMac,
76
+ wifiMac,
77
+ name,
78
+ // RSSI not directly available from requestDevice
79
+ };
80
+ return [discoveredDevice];
81
+ }
82
+ catch (error) {
83
+ if (error instanceof Error) {
84
+ if (error.name === "NotFoundError") {
85
+ // User cancelled the device picker
86
+ return [];
87
+ }
88
+ throw error;
89
+ }
90
+ throw new Error("Unknown error during Bluetooth scan");
91
+ }
92
+ });
93
+ exports.scanForDevices = scanForDevices;
94
+ /**
95
+ * Scan for devices with a custom filter.
96
+ * Advanced function for users who need more control over device selection.
97
+ *
98
+ * @param options - Web Bluetooth requestDevice options
99
+ * @returns Promise resolving to the selected BluetoothDevice
100
+ */
101
+ const scanWithOptions = (options) => __awaiter(void 0, void 0, void 0, function* () {
102
+ if (!isWebBluetoothSupported()) {
103
+ throw new Error("Web Bluetooth API is not supported in this browser.");
104
+ }
105
+ return navigator.bluetooth.requestDevice(options);
106
+ });
107
+ exports.scanWithOptions = scanWithOptions;
@@ -0,0 +1,64 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
36
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
37
+ return new (P || (P = Promise))(function (resolve, reject) {
38
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
39
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
40
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
41
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
42
+ });
43
+ };
44
+ Object.defineProperty(exports, "__esModule", { value: true });
45
+ const assert_1 = require("assert");
46
+ const esbuild = __importStar(require("esbuild"));
47
+ describe("browser-bundle", () => {
48
+ it("should bundle for browser without Node.js built-ins", () => __awaiter(void 0, void 0, void 0, function* () {
49
+ // This test verifies that the library can be bundled for browser environments
50
+ // without requiring Node.js built-in modules (fs, os, path).
51
+ // If this test fails, it means Node.js-only code has leaked into the main exports.
52
+ const result = yield esbuild.build({
53
+ entryPoints: ["dist/esm/src/index.js"],
54
+ platform: "browser",
55
+ bundle: true,
56
+ write: false,
57
+ // External dependencies that are expected (real deps + assert which is used for validation)
58
+ external: ["aws-amplify", "aws-amplify/*", "pako", "assert"],
59
+ logLevel: "silent",
60
+ });
61
+ // If we get here without error, the bundle succeeded
62
+ assert_1.strict.ok(result.outputFiles.length > 0, "Bundle should produce output");
63
+ }));
64
+ });
@@ -0,0 +1,78 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.processResponse = exports.isBuffer = exports.decompressBuffer = void 0;
7
+ const pako_1 = __importDefault(require("pako"));
8
+ /**
9
+ * Type guard to check if a value is a serialized Node.js Buffer.
10
+ * Node.js Buffers serialize to JSON as: {type: "Buffer", data: [...]}
11
+ *
12
+ * @param value - The value to check
13
+ * @returns True if the value is a Buffer-encoded object
14
+ */
15
+ const isBuffer = (value) => {
16
+ return (typeof value === "object" &&
17
+ value !== null &&
18
+ "type" in value &&
19
+ value.type === "Buffer" &&
20
+ "data" in value &&
21
+ Array.isArray(value.data));
22
+ };
23
+ exports.isBuffer = isBuffer;
24
+ /**
25
+ * Decompresses a Buffer-encoded gzip object and parses the resulting JSON.
26
+ *
27
+ * @param bufferObj - A serialized Buffer object containing gzip data
28
+ * @returns The decompressed and parsed JSON data, or the original object on failure
29
+ */
30
+ const decompressBuffer = (bufferObj) => {
31
+ try {
32
+ // Convert data array to Uint8Array for pako
33
+ const compressed = new Uint8Array(bufferObj.data);
34
+ // Decompress with gzip
35
+ const decompressed = pako_1.default.ungzip(compressed, { to: "string" });
36
+ // Parse JSON
37
+ return JSON.parse(decompressed);
38
+ }
39
+ catch (error) {
40
+ // Log warning but return original to maintain backward compatibility
41
+ console.warn("Failed to decompress buffer:", error);
42
+ return bufferObj;
43
+ }
44
+ };
45
+ exports.decompressBuffer = decompressBuffer;
46
+ /**
47
+ * Recursively processes an API response to decompress any Buffer-encoded fields.
48
+ * Handles nested objects and arrays, preserving structure while decompressing.
49
+ *
50
+ * @param data - The API response data to process
51
+ * @returns The processed data with all Buffer fields decompressed
52
+ */
53
+ const processResponse = (data) => {
54
+ if (data === null || data === undefined) {
55
+ return data;
56
+ }
57
+ // Check if this is a Buffer object
58
+ if (isBuffer(data)) {
59
+ const decompressed = decompressBuffer(data);
60
+ // Recursively process the decompressed result (may contain nested buffers)
61
+ return processResponse(decompressed);
62
+ }
63
+ // Recursively process arrays
64
+ if (Array.isArray(data)) {
65
+ return data.map((item) => processResponse(item));
66
+ }
67
+ // Recursively process objects
68
+ if (typeof data === "object") {
69
+ const processed = {};
70
+ for (const [key, value] of Object.entries(data)) {
71
+ processed[key] = processResponse(value);
72
+ }
73
+ return processed;
74
+ }
75
+ // Primitive value, return as-is
76
+ return data;
77
+ };
78
+ exports.processResponse = processResponse;