usb 3.0.0-alpha.1 → 3.0.0-alpha.3

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
@@ -1,93 +1,190 @@
1
- # `@napi-rs/package-template`
1
+ # USB Library for Node.JS
2
2
 
3
- npm run clean
4
- npm i
5
- npm run build:all
3
+ [![Build Status](https://github.com/node-usb/node-usb-rs/workflows/ci/badge.svg)](https://github.com/node-usb/node-usb-rs/actions)
4
+ [![npm](https://img.shields.io/npm/dm/usb.svg)](https://www.npmjs.com/package/usb)
5
+ [![Licence MIT](https://img.shields.io/badge/licence-MIT-blue.svg)](http://opensource.org/licenses/MIT)
6
+
7
+ Node.JS library for communicating with USB devices.
8
+
9
+ This is a complete rewrite in rust using [@kevinmehall](https://github.com/kevinmehall)'s excellent [nusb library](https://docs.rs/nusb/latest/nusb) and [napi-rs](https://napi.rs/).
10
+
11
+ # Prerequisites
6
12
 
13
+ [Node.js >= v12.22.0](https://nodejs.org), which includes `npm`.
7
14
 
15
+ ## Windows
8
16
 
9
- ![https://github.com/napi-rs/package-template/actions](https://github.com/napi-rs/package-template/workflows/CI/badge.svg)
17
+ On Windows, if you get a `NOT_SUPPORTED` error when attempting to open your device, it's possible your device doesn't have a WinUSB driver to use.
10
18
 
11
- > Template project for writing node packages with napi-rs.
19
+ You can install one using [Zadig](http://zadig.akeo.ie/).
20
+
21
+ ## Linux
22
+
23
+ You may need to modify your udev and permission rules in order to access your desired device. Along the lines of:
24
+
25
+ ```code
26
+ SUBSYSTEM=="usb", ATTR{idVendor}=="USB-VENDOR-ID", ATTR{idProduct}=="USB-PRODUCT-ID", MODE="0660", GROUP="GROUP-YOUR-USER-IS-IN"
27
+ ```
12
28
 
13
- # Usage
29
+ # Installation
14
30
 
15
- 1. Click **Use this template**.
16
- 2. **Clone** your project.
17
- 3. Run `yarn install` to install dependencies.
18
- 4. Run `yarn napi rename -n [@your-scope/package-name] -b [binary-name]` command under the project folder to rename your package.
31
+ Native modules are bundled as separate optional packages, so installation should be as simple as installing the package.
19
32
 
20
- ## Install this test package
33
+ With `npm`:
21
34
 
22
35
  ```bash
23
- yarn add @napi-rs/package-template
36
+ npm install usb
24
37
  ```
25
38
 
26
- ## Ability
39
+ With `yarn`:
27
40
 
28
- ### Build
41
+ ```bash
42
+ yarn add usb
43
+ ```
29
44
 
30
- After `yarn build/npm run build` command, you can see `package-template.[darwin|win32|linux].node` file in project root. This is the native addon built from [lib.rs](./src/lib.rs).
45
+ # License
46
+ [MIT](LICENSE.md)
31
47
 
32
- ### Test
48
+ # Limitations
49
+ Does not support:
33
50
 
34
- With [ava](https://github.com/avajs/ava), run `yarn test/npm run test` to testing native addon. You can also switch to another testing framework if you want.
51
+ - Isochronous transfers
35
52
 
36
- ### CI
53
+ # Getting Started
54
+ Use the following examples to kickstart your development. Once you have a desired device, use the APIs below to interact with it.
37
55
 
38
- With GitHub Actions, each commit and pull request will be built and tested automatically in [`node@20`, `@node22`] x [`macOS`, `Linux`, `Windows`] matrix. You will never be afraid of the native addon broken in these platforms.
56
+ ## APIs
57
+ Since `v3.0.0`, the `node-usb` library supports the WebUSB API which follows the [WebUSB Specification](https://wicg.github.io/webusb/)
39
58
 
40
- ### Release
59
+ Convenience methods also exist to easily list or find devices.
41
60
 
42
- Release native package is very difficult in old days. Native packages may ask developers who use it to install `build toolchain` like `gcc/llvm`, `node-gyp` or something more.
61
+ Full auto-generated API documentation can be seen here:
43
62
 
44
- With `GitHub actions`, we can easily prebuild a `binary` for major platforms. And with `N-API`, we should never be afraid of **ABI Compatible**.
63
+ https://node-usb.github.io/node-usb-rs/
45
64
 
46
- The other problem is how to deliver prebuild `binary` to users. Downloading it in `postinstall` script is a common way that most packages do it right now. The problem with this solution is it introduced many other packages to download binary that has not been used by `runtime codes`. The other problem is some users may not easily download the binary from `GitHub/CDN` if they are behind a private network (But in most cases, they have a private NPM mirror).
65
+ ## Electron
66
+ Please refer to the maintained example for using `node-usb` in electron:
47
67
 
48
- In this package, we choose a better way to solve this problem. We release different `npm packages` for different platforms. And add it to `optionalDependencies` before releasing the `Major` package to npm.
68
+ https://github.com/node-usb/node-usb-example-electron
49
69
 
50
- `NPM` will choose which native package should download from `registry` automatically. You can see [npm](./npm) dir for details. And you can also run `yarn add @napi-rs/package-template` to see how it works.
70
+ If using a packaging system for electron, ensure the `node-usb` library does not get recompiled as the correct binaries are already shipped with the package. For example, for [electron-builder](https://www.electron.build/), use these settings:
51
71
 
52
- ## Develop requirements
72
+ - buildDependenciesFromSource: true
73
+ - nodeGypRebuild: false
74
+ - npmRebuild: false
53
75
 
54
- - Install the latest `Rust`
55
- - Install `Node.js@10+` which fully supported `Node-API`
56
- - Install `yarn@1.x`
76
+ ## Convenience Functions
57
77
 
58
- ## Test in local
78
+ ### getDeviceList()
79
+ Return a list of `USB` objects for the USB devices attached to the system.
59
80
 
60
- - yarn
61
- - yarn build
62
- - yarn test
81
+ ### findByIds(vid, pid)
82
+ Convenience method to get the first device with the specified VID and PID, or `undefined` if no such device is present.
63
83
 
64
- And you will see:
84
+ ### findBySerialNumber(serialNumber)
85
+ Convenience method to get the device with the specified serial number, or `undefined` if no such device is present.
65
86
 
66
- ```bash
67
- $ ava --verbose
87
+ ## WebUSB
68
88
 
69
- sync function from native code
70
- ✔ sleep function from native code (201ms)
71
-
89
+ Please refer to the WebUSB specification which be found here:
72
90
 
73
- 2 tests passed
74
- ✨ Done in 1.12s.
75
- ```
91
+ https://wicg.github.io/webusb/
92
+
93
+ ### Implementation Status
94
+
95
+ #### Architectures and Operating Systems
96
+
97
+ - i686-pc-windows-msvc
98
+ - x86_64-apple-darwin
99
+ - x86_64-pc-windows-msvc
100
+ - x86_64-unknown-linux-gnu
101
+ - x86_64-unknown-linux-musl
102
+ - aarch64-apple-darwin
103
+ - aarch64-pc-windows-msvc
104
+ - aarch64-unknown-linux-gnu
105
+ - aarch64-unknown-linux-musl
106
+ - armv7-unknown-linux-gnueabihf
76
107
 
77
- ## Release package
108
+ #### USB
78
109
 
79
- Ensure you have set your **NPM_TOKEN** in the `GitHub` project setting.
110
+ - [x] getDevices()
111
+ - [x] requestDevice()
80
112
 
81
- In `Settings -> Secrets`, add **NPM_TOKEN** into it.
113
+ #### USBDevice
82
114
 
83
- When you want to release the package:
115
+ ##### WebUSB Features
116
+
117
+ - [x] usbVersionMajor
118
+ - [x] usbVersionMinor
119
+ - [x] usbVersionSubminor
120
+ - [x] deviceClass
121
+ - [x] deviceSubclass
122
+ - [x] deviceProtocol
123
+ - [x] vendorId
124
+ - [x] productId
125
+ - [x] deviceVersionMajor
126
+ - [x] deviceVersionMinor
127
+ - [x] deviceVersionSubminor
128
+ - [x] manufacturerName
129
+ - [x] productName
130
+ - [x] serialNumber
131
+ - [x] configuration
132
+ - [x] configurations
133
+ - [x] opened
134
+ - [x] open()
135
+ - [x] close()
136
+ - [x] selectConfiguration()
137
+ - [x] claimInterface()
138
+ - [x] releaseInterface()
139
+ - [x] selectAlternateInterface()
140
+ - [x] controlTransferIn()
141
+ - [x] controlTransferOut()
142
+ - [x] transferIn()
143
+ - [x] transferOut()
144
+ - [x] clearHalt()
145
+ - [x] reset()
146
+ - [x] forget()
147
+ - [ ] isochronousTransferIn()
148
+ - [ ] isochronousTransferOut()
149
+
150
+ ##### Extended Features
151
+
152
+ - [x] bus
153
+ - [x] address
154
+ - [x] ports
155
+ - [x] speed
156
+ - [x] detachKernelDriver() (Linux only)
157
+ - [x] attachKernelDriver() (Linux only)
158
+
159
+ #### Events
160
+
161
+ - [x] connect
162
+ - [x] disconnect
163
+
164
+ # Development
165
+ The library is based on native rust bindings wrapping the [nusb](https://docs.rs/nusb/latest/nusb) crate.
166
+
167
+ Ensure you have a working rust environment, instructions for setting this up are avalable at https://rust-lang.org/tools/install/
168
+
169
+ ## Setup
84
170
 
85
171
  ```bash
86
- npm version [<newversion> | major | minor | patch | premajor | preminor | prepatch | prerelease [--preid=<prerelease-id>] | from-git]
172
+ git clone https://github.com/node-usb/node-usb-rs
173
+ ```
174
+
175
+ ## Building
176
+ The package can be built as follows:
87
177
 
88
- git push
178
+ ```bash
179
+ npm install
180
+ npm run build:all
89
181
  ```
90
182
 
91
- GitHub actions will do the rest job for you.
183
+ ## Testing
184
+ To execute the unit tests, Run:
185
+
186
+ ```bash
187
+ npm run full-test
188
+ ```
92
189
 
93
- > WARN: Don't run `npm publish` manually.
190
+ Some tests require an [attached STM32F103 Microprocessor USB device with specific firmware](https://github.com/node-usb/node-usb-test-firmware).
package/dist/index.d.ts CHANGED
@@ -1,5 +1,4 @@
1
- import { Emitter } from '../index.js';
2
- import { EventEmitter } from 'events';
1
+ import { UsbDevice, Emitter } from '../index.js';
3
2
  /**
4
3
  * USB Options
5
4
  */
@@ -7,7 +6,7 @@ interface USBOptions {
7
6
  /**
8
7
  * Optional `device found` callback function to allow the user to select a device
9
8
  */
10
- devicesFound?: (devices: USBDevice[]) => Promise<USBDevice | void>;
9
+ devicesFound?: (devices: UsbDevice[]) => Promise<UsbDevice | void>;
11
10
  /**
12
11
  * Optional array of preconfigured allowed devices
13
12
  */
@@ -20,38 +19,44 @@ interface USBOptions {
20
19
  * Optional timeout (in milliseconds) to use for the device control transfers
21
20
  */
22
21
  deviceTimeout?: number;
23
- /**
24
- * Optional flag to enable/disable automatic kernal driver detaching (defaults to true)
25
- */
26
- autoDetachKernelDriver?: boolean;
27
22
  }
28
- declare class WebUSB implements USB {
23
+ interface WebUSB {
24
+ addEventListener(type: "connect" | "disconnect", listener: (this: this, ev: USBConnectionEvent) => any, useCapture?: boolean): void;
25
+ addEventListener(type: string, listener: EventListenerOrEventListenerObject | null, options?: boolean | AddEventListenerOptions): void;
26
+ removeEventListener(type: "connect" | "disconnect", callback: (this: this, ev: USBConnectionEvent) => any, useCapture?: boolean): void;
27
+ removeEventListener(type: string, callback: EventListenerOrEventListenerObject | null, options?: EventListenerOptions | boolean): void;
28
+ }
29
+ /**
30
+ * WebUSB class
31
+ *
32
+ * ### Events
33
+ *
34
+ * | Name | Event | Description |
35
+ * | ---- | ----- | ----------- |
36
+ * | `connect` | {@link USBConnectionEvent} | Device connected |
37
+ * | `disconnect` | {@link USBConnectionEvent} | Device disconnected |
38
+ */
39
+ declare class WebUSB extends EventTarget implements USB {
29
40
  private options;
30
41
  protected nativeEmitter: Emitter;
31
- protected emitter: EventEmitter<any>;
32
42
  protected authorisedDevices: Set<USBDeviceFilter>;
33
- protected knownDevices: Map<string, USBDevice>;
43
+ protected knownDevices: Map<string, UsbDevice>;
34
44
  constructor(options?: USBOptions);
35
45
  private _onconnect;
36
46
  set onconnect(fn: (ev: USBConnectionEvent) => void);
37
47
  private _ondisconnect;
38
48
  set ondisconnect(fn: (ev: USBConnectionEvent) => void);
39
- addEventListener(type: 'connect' | 'disconnect', listener: (this: this, ev: USBConnectionEvent) => void): void;
40
- addEventListener(type: 'connect' | 'disconnect', listener: EventListener): void;
41
- removeEventListener(type: 'connect' | 'disconnect', callback: (this: this, ev: USBConnectionEvent) => void): void;
42
- removeEventListener(type: 'connect' | 'disconnect', callback: EventListener): void;
43
- dispatchEvent(_event: Event): boolean;
44
49
  /**
45
50
  * Requests a single Web USB device
46
51
  * @param options The options to use when scanning
47
52
  * @returns Promise containing the selected device
48
53
  */
49
- requestDevice(options?: USBDeviceRequestOptions): Promise<USBDevice>;
54
+ requestDevice(options?: USBDeviceRequestOptions): Promise<UsbDevice>;
50
55
  /**
51
56
  * Gets all allowed Web USB devices which are connected
52
57
  * @returns Promise containing an array of devices
53
58
  */
54
- getDevices(): Promise<USBDevice[]>;
59
+ getDevices(): Promise<UsbDevice[]>;
55
60
  private loadDevices;
56
61
  private quickFilter;
57
62
  private filterDevice;
@@ -60,17 +65,20 @@ declare class WebUSB implements USB {
60
65
  /**
61
66
  * Convenience method to get an array of all connected devices.
62
67
  */
63
- declare const getDeviceList: () => Promise<USBDevice[]>;
68
+ declare const getDeviceList: () => Promise<UsbDevice[]>;
64
69
  /**
65
70
  * Convenience method to get the first device with the specified VID and PID, or `undefined` if no such device is present.
66
71
  * @param vid
67
72
  * @param pid
68
73
  */
69
- declare const findByIds: (vid: number, pid: number) => Promise<USBDevice | undefined>;
74
+ declare const findByIds: (vid: number, pid: number) => Promise<UsbDevice | undefined>;
70
75
  /**
71
76
  * Convenience method to get the device with the specified serial number, or `undefined` if no such device is present.
72
77
  * @param serialNumber
73
78
  */
74
- declare const findBySerialNumber: (serialNumber: string) => Promise<USBDevice | undefined>;
79
+ declare const findBySerialNumber: (serialNumber: string) => Promise<UsbDevice | undefined>;
80
+ /**
81
+ * Default WebUSB object (mimics navigator.usb)
82
+ */
75
83
  declare const webusb: WebUSB | USB;
76
84
  export { webusb, WebUSB, USBOptions, getDeviceList, findByIds, findBySerialNumber, };
package/dist/index.js CHANGED
@@ -2,132 +2,125 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.findBySerialNumber = exports.findByIds = exports.getDeviceList = exports.WebUSB = exports.webusb = void 0;
4
4
  const index_js_1 = require("../index.js");
5
- const events_1 = require("events");
5
+ /**
6
+ * Hidden
7
+ */
8
+ const DEFAULT_TIMEOUT = 1000;
9
+ /**
10
+ * Hidden
11
+ */
12
+ const toUint8Array = (data) => {
13
+ if (data instanceof ArrayBuffer) {
14
+ return new Uint8Array(data);
15
+ }
16
+ // ArrayBufferView
17
+ return new Uint8Array(data.buffer, data.byteOffset, data.byteLength);
18
+ };
19
+ /**
20
+ * Hidden
21
+ */
22
+ index_js_1.UsbDevice.prototype.controlTransferIn = async function (setup, length, timeout = DEFAULT_TIMEOUT) {
23
+ const res = await this.nativeControlTransferIn(setup, timeout, length);
24
+ return {
25
+ data: res ? new DataView(res.buffer) : undefined,
26
+ status: res ? 'ok' : 'stall',
27
+ };
28
+ };
29
+ /**
30
+ * Hidden
31
+ */
32
+ index_js_1.UsbDevice.prototype.controlTransferOut = async function (setup, data, timeout = DEFAULT_TIMEOUT) {
33
+ const res = await this.nativeControlTransferOut(setup, timeout, toUint8Array(data));
34
+ return {
35
+ bytesWritten: res,
36
+ status: res >= 0 ? 'ok' : 'stall',
37
+ };
38
+ };
39
+ /**
40
+ * Hidden
41
+ */
42
+ index_js_1.UsbDevice.prototype.transferIn = async function (endpointNumber, length, timeout = DEFAULT_TIMEOUT) {
43
+ const res = await this.nativeTransferIn(endpointNumber, timeout, length);
44
+ return {
45
+ data: res ? new DataView(res.buffer) : undefined,
46
+ status: res ? 'ok' : 'stall',
47
+ };
48
+ };
49
+ /**
50
+ * Hidden
51
+ */
52
+ index_js_1.UsbDevice.prototype.transferOut = async function (endpointNumber, data, timeout = DEFAULT_TIMEOUT) {
53
+ const res = await this.nativeTransferOut(endpointNumber, timeout, toUint8Array(data));
54
+ return {
55
+ bytesWritten: res,
56
+ status: res >= 0 ? 'ok' : 'stall',
57
+ };
58
+ };
59
+ /**
60
+ * Hidden
61
+ */
62
+ index_js_1.UsbDevice.prototype.isochronousTransferIn = async function (_endpointNumber, _packetLengths) {
63
+ throw new Error('isochronousTransferIn error: method not implemented');
64
+ };
65
+ /**
66
+ * Hidden
67
+ */
68
+ index_js_1.UsbDevice.prototype.isochronousTransferOut = async function (_endpointNumber, _data, _packetLengths) {
69
+ throw new Error('isochronousTransferOut error: method not implemented');
70
+ };
6
71
  class NamedError extends Error {
7
72
  constructor(message, name) {
8
73
  super(message);
9
74
  this.name = name;
10
75
  }
11
76
  }
12
- const augmentDevice = (device) => {
13
- const toUint8Array = (data) => {
14
- if (data instanceof ArrayBuffer) {
15
- return new Uint8Array(data);
16
- }
17
- // ArrayBufferView
18
- return new Uint8Array(data.buffer, data.byteOffset, data.byteLength);
19
- };
20
- Object.defineProperty(device, 'controlTransferIn', {
21
- enumerable: false,
22
- configurable: false,
23
- value: async function (setup, length) {
24
- const res = await this.nativeControlTransferIn(setup, length);
25
- return {
26
- data: res ? new DataView(res.buffer) : undefined,
27
- status: res ? 'ok' : 'stall',
28
- };
29
- },
30
- });
31
- Object.defineProperty(device, 'controlTransferOut', {
32
- enumerable: false,
33
- configurable: false,
34
- value: async function (setup, data) {
35
- const res = await this.nativeControlTransferOut(setup, toUint8Array(data));
36
- return {
37
- bytesWritten: res,
38
- status: res >= 0 ? 'ok' : 'stall',
39
- };
40
- },
41
- });
42
- Object.defineProperty(device, 'transferIn', {
43
- enumerable: false,
44
- configurable: false,
45
- value: async function (endpointNumber, length) {
46
- const res = await this.nativeTransferIn(endpointNumber, length);
47
- return {
48
- data: res ? new DataView(res.buffer) : undefined,
49
- status: res ? 'ok' : 'stall',
50
- };
51
- },
52
- });
53
- Object.defineProperty(device, 'transferOut', {
54
- enumerable: false,
55
- configurable: false,
56
- value: async function (endpointNumber, data) {
57
- const res = await this.nativeTransferOut(endpointNumber, toUint8Array(data));
58
- return {
59
- bytesWritten: res,
60
- status: res >= 0 ? 'ok' : 'stall',
61
- };
62
- },
63
- });
64
- return device;
65
- };
66
- class WebUSB {
77
+ class ConnectionEvent extends Event {
78
+ constructor(type, eventInitDict) {
79
+ super(type, eventInitDict);
80
+ this.eventInitDict = eventInitDict;
81
+ }
82
+ get device() {
83
+ return this.eventInitDict.device;
84
+ }
85
+ }
86
+ /**
87
+ * WebUSB class
88
+ *
89
+ * ### Events
90
+ *
91
+ * | Name | Event | Description |
92
+ * | ---- | ----- | ----------- |
93
+ * | `connect` | {@link USBConnectionEvent} | Device connected |
94
+ * | `disconnect` | {@link USBConnectionEvent} | Device disconnected |
95
+ */
96
+ class WebUSB extends EventTarget {
67
97
  constructor(options = {}) {
98
+ super();
68
99
  this.options = options;
69
100
  this.nativeEmitter = new index_js_1.Emitter();
70
- this.emitter = new events_1.EventEmitter();
71
101
  this.authorisedDevices = new Set();
72
102
  this.knownDevices = new Map();
73
103
  const deviceConnectCallback = async (device) => {
74
- const webDevice = augmentDevice(device);
75
- this.knownDevices.set(device.handle, webDevice);
104
+ this.knownDevices.set(device.handle, device);
76
105
  // When connected, emit an event if it is an allowed device
77
- if (webDevice && this.isAuthorisedDevice(webDevice)) {
78
- const event = {
79
- type: 'connect',
80
- device: webDevice
81
- };
82
- this.emitter.emit('connect', event);
106
+ if (device && this.isAuthorisedDevice(device)) {
107
+ this.dispatchEvent(new ConnectionEvent('connect', { device }));
83
108
  }
84
109
  };
85
110
  const deviceDisconnectCallback = async (handle) => {
86
111
  // When disconnected, emit an event if the device was a known allowed device
87
112
  if (this.knownDevices.has(handle)) {
88
- const webDevice = this.knownDevices.get(handle);
89
- if (webDevice && this.isAuthorisedDevice(webDevice)) {
90
- const event = {
91
- type: 'disconnect',
92
- device: webDevice
93
- };
94
- this.emitter.emit('disconnect', event);
113
+ const device = this.knownDevices.get(handle);
114
+ if (device && this.isAuthorisedDevice(device)) {
115
+ this.dispatchEvent(new ConnectionEvent('disconnect', { device }));
95
116
  }
96
117
  this.knownDevices.delete(handle);
97
118
  }
98
119
  };
99
- this.emitter.on('newListener', async (event) => {
100
- const listenerCount = this.emitter.listenerCount(event);
101
- if (listenerCount !== 0) {
102
- return;
103
- }
104
- if (event === 'connect') {
105
- this.nativeEmitter.addAttach(deviceConnectCallback);
106
- }
107
- else if (event === 'disconnect') {
108
- // Ensure we know the current devices
109
- this.knownDevices.clear();
110
- const devices = await (0, index_js_1.nativeGetDeviceList)();
111
- devices.forEach(device => {
112
- this.knownDevices.set(device.handle, augmentDevice(device));
113
- });
114
- this.nativeEmitter.addDetach(deviceDisconnectCallback);
115
- }
116
- });
117
- this.emitter.on('removeListener', event => {
118
- const listenerCount = this.emitter.listenerCount(event);
119
- if (listenerCount !== 0) {
120
- return;
121
- }
122
- if (event === 'connect') {
123
- this.nativeEmitter.removeAttach(deviceConnectCallback);
124
- }
125
- else if (event === 'disconnect') {
126
- this.knownDevices.clear();
127
- this.nativeEmitter.removeDetach(deviceDisconnectCallback);
128
- }
129
- });
130
120
  this.nativeEmitter.start();
121
+ this.nativeEmitter.addAttach(deviceConnectCallback);
122
+ this.nativeEmitter.addDetach(deviceDisconnectCallback);
123
+ getDeviceList().then(devices => devices.forEach(device => this.knownDevices.set(device.handle, device)));
131
124
  }
132
125
  set onconnect(fn) {
133
126
  if (this._onconnect) {
@@ -149,16 +142,6 @@ class WebUSB {
149
142
  this.addEventListener('disconnect', this._ondisconnect);
150
143
  }
151
144
  }
152
- addEventListener(type, listener) {
153
- this.emitter.addListener(type, listener);
154
- }
155
- removeEventListener(type, callback) {
156
- this.emitter.removeListener(type, callback);
157
- }
158
- dispatchEvent(_event) {
159
- // Don't dispatch from here
160
- return false;
161
- }
162
145
  /**
163
146
  * Requests a single Web USB device
164
147
  * @param options The options to use when scanning
@@ -325,7 +308,7 @@ exports.WebUSB = WebUSB;
325
308
  */
326
309
  const getDeviceList = async () => {
327
310
  const devices = await (0, index_js_1.nativeGetDeviceList)();
328
- return devices.map(device => augmentDevice(device));
311
+ return devices;
329
312
  };
330
313
  exports.getDeviceList = getDeviceList;
331
314
  /**
@@ -335,7 +318,7 @@ exports.getDeviceList = getDeviceList;
335
318
  */
336
319
  const findByIds = async (vid, pid) => {
337
320
  const device = await (0, index_js_1.nativeFindByIds)(vid, pid);
338
- return device ? augmentDevice(device) : undefined;
321
+ return device;
339
322
  };
340
323
  exports.findByIds = findByIds;
341
324
  /**
@@ -344,9 +327,12 @@ exports.findByIds = findByIds;
344
327
  */
345
328
  const findBySerialNumber = async (serialNumber) => {
346
329
  const device = await (0, index_js_1.nativeFindBySerialNumber)(serialNumber);
347
- return device ? augmentDevice(device) : undefined;
330
+ return device;
348
331
  };
349
332
  exports.findBySerialNumber = findBySerialNumber;
333
+ /**
334
+ * Default WebUSB object (mimics navigator.usb)
335
+ */
350
336
  const webusb = typeof navigator !== 'undefined' && navigator.usb ? navigator.usb : new WebUSB();
351
337
  exports.webusb = webusb;
352
338
  //# sourceMappingURL=index.js.map
package/index.d.ts CHANGED
@@ -1,5 +1,38 @@
1
- /* auto-generated by NAPI-RS */
2
- /* eslint-disable */
1
+ export type USBSpeed = 'low' | 'full' | 'high' | 'super' | 'superPlus';
2
+
3
+ export declare interface UsbDevice extends USBDevice {
4
+ /**
5
+ * The USB bus the device is connected to (e.g. `1-1`, `2-3.4`, etc.)
6
+ */
7
+ bus: string;
8
+
9
+ /**
10
+ * The USB address the device is connected to
11
+ */
12
+ address: number;
13
+
14
+ /**
15
+ * The USB port numbers the device is connected through (e.g. `[1]`, `[3, 4]`, etc.)
16
+ */
17
+ ports: Array<number>
18
+
19
+ /**
20
+ * The USB speed of the device (e.g. `Low`, `Full`, `High`, `Super`, `SuperPlus` or `undefined` if unknown)
21
+ */
22
+ speed?: USBSpeed;
23
+
24
+ /**
25
+ * Detaches the kernel driver from the specified interface number (Linux only)
26
+ * @param interfaceNumber
27
+ */
28
+ detachKernelDriver(interfaceNumber: number): Promise<void>;
29
+
30
+ /**
31
+ * Attaches the kernel driver for the specified interface number (Linux only)
32
+ * @param interfaceNumber
33
+ */
34
+ attachKernelDriver(interfaceNumber: number): Promise<void>;
35
+ }
3
36
  export declare class Emitter {
4
37
  constructor()
5
38
  start(): Promise<void>
@@ -21,13 +54,17 @@ export declare class UsbDevice {
21
54
  deviceClass: number
22
55
  deviceSubclass: number
23
56
  deviceProtocol: number
24
- manufacturerName?: string
25
- productName?: string
26
- serialNumber?: string
57
+ bus: string
58
+ address: number
59
+ ports: Array<number>
60
+ speed?: USBSpeed
27
61
  get handle(): string
62
+ get manufacturerName(): string | null
63
+ get productName(): string | null
64
+ get serialNumber(): string | null
28
65
  get opened(): boolean
66
+ get configuration(): USBConfiguration
29
67
  get configurations(): Array<USBConfiguration>
30
- get configuration(): USBConfiguration | null
31
68
  open(): Promise<void>
32
69
  close(): Promise<void>
33
70
  forget(): Promise<void>
@@ -36,13 +73,15 @@ export declare class UsbDevice {
36
73
  claimInterface(interfaceNumber: number): Promise<void>
37
74
  releaseInterface(interfaceNumber: number): Promise<void>
38
75
  selectAlternateInterface(interfaceNumber: number, alternateSetting: number): Promise<void>
39
- nativeControlTransferIn(setup: USBControlTransferParameters, length: number): Promise<Uint8Array | null>
40
- nativeControlTransferOut(setup: USBControlTransferParameters, data?: Uint8Array | undefined | null): Promise<number>
41
- nativeTransferIn(endpointNumber: number, length: number): Promise<Uint8Array | null>
42
- nativeTransferOut(endpointNumber: number, data: Uint8Array): Promise<number>
43
- isochronousTransferIn(endpointNumber: number, packetLengths: Array<number>): Promise<USBIsochronousInTransferResult>
44
- isochronousTransferOut(endpointNumber: number, data: Uint8Array, packetLengths: Array<number>): Promise<USBIsochronousOutTransferResult>
76
+ nativeControlTransferIn(setup: USBControlTransferParameters, timeout: number, length: number): Promise<Uint8Array | null>
77
+ nativeControlTransferOut(setup: USBControlTransferParameters, timeout: number, data?: Uint8Array | undefined | null): Promise<number>
78
+ nativeTransferIn(endpointNumber: number, timeout: number, length: number): Promise<Uint8Array | null>
79
+ nativeTransferOut(endpointNumber: number, timeout: number, data: Uint8Array): Promise<number>
80
+ nativeIsochronousTransferIn(endpointNumber: number, packetLengths: Array<number>): Promise<USBIsochronousInTransferResult>
81
+ nativeIsochronousTransferOut(endpointNumber: number, data: Uint8Array, packetLengths: Array<number>): Promise<USBIsochronousOutTransferResult>
45
82
  clearHalt(direction: USBDirection, endpointNumber: number): Promise<void>
83
+ detachKernelDriver(interfaceNumber: number): Promise<void>
84
+ attachKernelDriver(interfaceNumber: number): Promise<void>
46
85
  }
47
86
 
48
87
  export declare function nativeFindByIds(vendorId: number, productId: number): Promise<UsbDevice>
@@ -51,19 +90,19 @@ export declare function nativeFindBySerialNumber(serialNumber: string): Promise<
51
90
 
52
91
  export declare function nativeGetDeviceList(): Promise<Array<UsbDevice>>
53
92
 
54
- export interface USBAlternateInterface {
93
+ export interface UsbAlternateInterface {
55
94
  alternateSetting: number
56
95
  interfaceClass: number
57
96
  interfaceSubclass: number
58
97
  interfaceProtocol: number
59
98
  interfaceName?: string
60
- endpoints: Array<USBEndpoint>
99
+ endpoints: Array<UsbEndpoint>
61
100
  }
62
101
 
63
- export interface USBConfiguration {
102
+ export interface UsbConfiguration {
64
103
  configurationValue: number
65
104
  configurationName?: string
66
- interfaces: Array<USBInterface>
105
+ interfaces: Array<UsbInterface>
67
106
  }
68
107
 
69
108
  export interface USBControlTransferParameters {
@@ -74,16 +113,16 @@ export interface USBControlTransferParameters {
74
113
  index: number
75
114
  }
76
115
 
77
- export interface USBEndpoint {
116
+ export interface UsbEndpoint {
78
117
  endpointNumber: number
79
118
  direction: USBDirection
80
119
  type: USBEndpointType
81
120
  packetSize: number
82
121
  }
83
122
 
84
- export interface USBInterface {
123
+ export interface UsbInterface {
85
124
  interfaceNumber: number
86
125
  claimed: boolean
87
- alternate: USBAlternateInterface
88
- alternates: Array<USBAlternateInterface>
126
+ alternate: UsbAlternateInterface
127
+ alternates: Array<UsbAlternateInterface>
89
128
  }
package/index.js CHANGED
@@ -77,8 +77,8 @@ function requireNative() {
77
77
  try {
78
78
  const binding = require('@node-usb/usb-android-arm64')
79
79
  const bindingPackageVersion = require('@node-usb/usb-android-arm64/package.json').version
80
- if (bindingPackageVersion !== '3.0.0-alpha.1' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
81
- throw new Error(`Native binding package version mismatch, expected 3.0.0-alpha.1 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
80
+ if (bindingPackageVersion !== '3.0.0-alpha.3' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
81
+ throw new Error(`Native binding package version mismatch, expected 3.0.0-alpha.3 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
82
82
  }
83
83
  return binding
84
84
  } catch (e) {
@@ -93,8 +93,8 @@ function requireNative() {
93
93
  try {
94
94
  const binding = require('@node-usb/usb-android-arm-eabi')
95
95
  const bindingPackageVersion = require('@node-usb/usb-android-arm-eabi/package.json').version
96
- if (bindingPackageVersion !== '3.0.0-alpha.1' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
97
- throw new Error(`Native binding package version mismatch, expected 3.0.0-alpha.1 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
96
+ if (bindingPackageVersion !== '3.0.0-alpha.3' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
97
+ throw new Error(`Native binding package version mismatch, expected 3.0.0-alpha.3 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
98
98
  }
99
99
  return binding
100
100
  } catch (e) {
@@ -114,8 +114,8 @@ function requireNative() {
114
114
  try {
115
115
  const binding = require('@node-usb/usb-win32-x64-gnu')
116
116
  const bindingPackageVersion = require('@node-usb/usb-win32-x64-gnu/package.json').version
117
- if (bindingPackageVersion !== '3.0.0-alpha.1' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
118
- throw new Error(`Native binding package version mismatch, expected 3.0.0-alpha.1 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
117
+ if (bindingPackageVersion !== '3.0.0-alpha.3' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
118
+ throw new Error(`Native binding package version mismatch, expected 3.0.0-alpha.3 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
119
119
  }
120
120
  return binding
121
121
  } catch (e) {
@@ -130,8 +130,8 @@ function requireNative() {
130
130
  try {
131
131
  const binding = require('@node-usb/usb-win32-x64-msvc')
132
132
  const bindingPackageVersion = require('@node-usb/usb-win32-x64-msvc/package.json').version
133
- if (bindingPackageVersion !== '3.0.0-alpha.1' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
134
- throw new Error(`Native binding package version mismatch, expected 3.0.0-alpha.1 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
133
+ if (bindingPackageVersion !== '3.0.0-alpha.3' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
134
+ throw new Error(`Native binding package version mismatch, expected 3.0.0-alpha.3 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
135
135
  }
136
136
  return binding
137
137
  } catch (e) {
@@ -147,8 +147,8 @@ function requireNative() {
147
147
  try {
148
148
  const binding = require('@node-usb/usb-win32-ia32-msvc')
149
149
  const bindingPackageVersion = require('@node-usb/usb-win32-ia32-msvc/package.json').version
150
- if (bindingPackageVersion !== '3.0.0-alpha.1' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
151
- throw new Error(`Native binding package version mismatch, expected 3.0.0-alpha.1 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
150
+ if (bindingPackageVersion !== '3.0.0-alpha.3' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
151
+ throw new Error(`Native binding package version mismatch, expected 3.0.0-alpha.3 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
152
152
  }
153
153
  return binding
154
154
  } catch (e) {
@@ -163,8 +163,8 @@ function requireNative() {
163
163
  try {
164
164
  const binding = require('@node-usb/usb-win32-arm64-msvc')
165
165
  const bindingPackageVersion = require('@node-usb/usb-win32-arm64-msvc/package.json').version
166
- if (bindingPackageVersion !== '3.0.0-alpha.1' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
167
- throw new Error(`Native binding package version mismatch, expected 3.0.0-alpha.1 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
166
+ if (bindingPackageVersion !== '3.0.0-alpha.3' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
167
+ throw new Error(`Native binding package version mismatch, expected 3.0.0-alpha.3 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
168
168
  }
169
169
  return binding
170
170
  } catch (e) {
@@ -182,8 +182,8 @@ function requireNative() {
182
182
  try {
183
183
  const binding = require('@node-usb/usb-darwin-universal')
184
184
  const bindingPackageVersion = require('@node-usb/usb-darwin-universal/package.json').version
185
- if (bindingPackageVersion !== '3.0.0-alpha.1' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
186
- throw new Error(`Native binding package version mismatch, expected 3.0.0-alpha.1 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
185
+ if (bindingPackageVersion !== '3.0.0-alpha.3' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
186
+ throw new Error(`Native binding package version mismatch, expected 3.0.0-alpha.3 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
187
187
  }
188
188
  return binding
189
189
  } catch (e) {
@@ -198,8 +198,8 @@ function requireNative() {
198
198
  try {
199
199
  const binding = require('@node-usb/usb-darwin-x64')
200
200
  const bindingPackageVersion = require('@node-usb/usb-darwin-x64/package.json').version
201
- if (bindingPackageVersion !== '3.0.0-alpha.1' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
202
- throw new Error(`Native binding package version mismatch, expected 3.0.0-alpha.1 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
201
+ if (bindingPackageVersion !== '3.0.0-alpha.3' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
202
+ throw new Error(`Native binding package version mismatch, expected 3.0.0-alpha.3 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
203
203
  }
204
204
  return binding
205
205
  } catch (e) {
@@ -214,8 +214,8 @@ function requireNative() {
214
214
  try {
215
215
  const binding = require('@node-usb/usb-darwin-arm64')
216
216
  const bindingPackageVersion = require('@node-usb/usb-darwin-arm64/package.json').version
217
- if (bindingPackageVersion !== '3.0.0-alpha.1' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
218
- throw new Error(`Native binding package version mismatch, expected 3.0.0-alpha.1 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
217
+ if (bindingPackageVersion !== '3.0.0-alpha.3' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
218
+ throw new Error(`Native binding package version mismatch, expected 3.0.0-alpha.3 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
219
219
  }
220
220
  return binding
221
221
  } catch (e) {
@@ -234,8 +234,8 @@ function requireNative() {
234
234
  try {
235
235
  const binding = require('@node-usb/usb-freebsd-x64')
236
236
  const bindingPackageVersion = require('@node-usb/usb-freebsd-x64/package.json').version
237
- if (bindingPackageVersion !== '3.0.0-alpha.1' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
238
- throw new Error(`Native binding package version mismatch, expected 3.0.0-alpha.1 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
237
+ if (bindingPackageVersion !== '3.0.0-alpha.3' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
238
+ throw new Error(`Native binding package version mismatch, expected 3.0.0-alpha.3 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
239
239
  }
240
240
  return binding
241
241
  } catch (e) {
@@ -250,8 +250,8 @@ function requireNative() {
250
250
  try {
251
251
  const binding = require('@node-usb/usb-freebsd-arm64')
252
252
  const bindingPackageVersion = require('@node-usb/usb-freebsd-arm64/package.json').version
253
- if (bindingPackageVersion !== '3.0.0-alpha.1' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
254
- throw new Error(`Native binding package version mismatch, expected 3.0.0-alpha.1 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
253
+ if (bindingPackageVersion !== '3.0.0-alpha.3' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
254
+ throw new Error(`Native binding package version mismatch, expected 3.0.0-alpha.3 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
255
255
  }
256
256
  return binding
257
257
  } catch (e) {
@@ -271,8 +271,8 @@ function requireNative() {
271
271
  try {
272
272
  const binding = require('@node-usb/usb-linux-x64-musl')
273
273
  const bindingPackageVersion = require('@node-usb/usb-linux-x64-musl/package.json').version
274
- if (bindingPackageVersion !== '3.0.0-alpha.1' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
275
- throw new Error(`Native binding package version mismatch, expected 3.0.0-alpha.1 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
274
+ if (bindingPackageVersion !== '3.0.0-alpha.3' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
275
+ throw new Error(`Native binding package version mismatch, expected 3.0.0-alpha.3 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
276
276
  }
277
277
  return binding
278
278
  } catch (e) {
@@ -287,8 +287,8 @@ function requireNative() {
287
287
  try {
288
288
  const binding = require('@node-usb/usb-linux-x64-gnu')
289
289
  const bindingPackageVersion = require('@node-usb/usb-linux-x64-gnu/package.json').version
290
- if (bindingPackageVersion !== '3.0.0-alpha.1' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
291
- throw new Error(`Native binding package version mismatch, expected 3.0.0-alpha.1 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
290
+ if (bindingPackageVersion !== '3.0.0-alpha.3' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
291
+ throw new Error(`Native binding package version mismatch, expected 3.0.0-alpha.3 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
292
292
  }
293
293
  return binding
294
294
  } catch (e) {
@@ -305,8 +305,8 @@ function requireNative() {
305
305
  try {
306
306
  const binding = require('@node-usb/usb-linux-arm64-musl')
307
307
  const bindingPackageVersion = require('@node-usb/usb-linux-arm64-musl/package.json').version
308
- if (bindingPackageVersion !== '3.0.0-alpha.1' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
309
- throw new Error(`Native binding package version mismatch, expected 3.0.0-alpha.1 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
308
+ if (bindingPackageVersion !== '3.0.0-alpha.3' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
309
+ throw new Error(`Native binding package version mismatch, expected 3.0.0-alpha.3 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
310
310
  }
311
311
  return binding
312
312
  } catch (e) {
@@ -321,8 +321,8 @@ function requireNative() {
321
321
  try {
322
322
  const binding = require('@node-usb/usb-linux-arm64-gnu')
323
323
  const bindingPackageVersion = require('@node-usb/usb-linux-arm64-gnu/package.json').version
324
- if (bindingPackageVersion !== '3.0.0-alpha.1' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
325
- throw new Error(`Native binding package version mismatch, expected 3.0.0-alpha.1 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
324
+ if (bindingPackageVersion !== '3.0.0-alpha.3' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
325
+ throw new Error(`Native binding package version mismatch, expected 3.0.0-alpha.3 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
326
326
  }
327
327
  return binding
328
328
  } catch (e) {
@@ -339,8 +339,8 @@ function requireNative() {
339
339
  try {
340
340
  const binding = require('@node-usb/usb-linux-arm-musleabihf')
341
341
  const bindingPackageVersion = require('@node-usb/usb-linux-arm-musleabihf/package.json').version
342
- if (bindingPackageVersion !== '3.0.0-alpha.1' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
343
- throw new Error(`Native binding package version mismatch, expected 3.0.0-alpha.1 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
342
+ if (bindingPackageVersion !== '3.0.0-alpha.3' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
343
+ throw new Error(`Native binding package version mismatch, expected 3.0.0-alpha.3 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
344
344
  }
345
345
  return binding
346
346
  } catch (e) {
@@ -355,8 +355,8 @@ function requireNative() {
355
355
  try {
356
356
  const binding = require('@node-usb/usb-linux-arm-gnueabihf')
357
357
  const bindingPackageVersion = require('@node-usb/usb-linux-arm-gnueabihf/package.json').version
358
- if (bindingPackageVersion !== '3.0.0-alpha.1' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
359
- throw new Error(`Native binding package version mismatch, expected 3.0.0-alpha.1 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
358
+ if (bindingPackageVersion !== '3.0.0-alpha.3' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
359
+ throw new Error(`Native binding package version mismatch, expected 3.0.0-alpha.3 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
360
360
  }
361
361
  return binding
362
362
  } catch (e) {
@@ -373,8 +373,8 @@ function requireNative() {
373
373
  try {
374
374
  const binding = require('@node-usb/usb-linux-loong64-musl')
375
375
  const bindingPackageVersion = require('@node-usb/usb-linux-loong64-musl/package.json').version
376
- if (bindingPackageVersion !== '3.0.0-alpha.1' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
377
- throw new Error(`Native binding package version mismatch, expected 3.0.0-alpha.1 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
376
+ if (bindingPackageVersion !== '3.0.0-alpha.3' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
377
+ throw new Error(`Native binding package version mismatch, expected 3.0.0-alpha.3 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
378
378
  }
379
379
  return binding
380
380
  } catch (e) {
@@ -389,8 +389,8 @@ function requireNative() {
389
389
  try {
390
390
  const binding = require('@node-usb/usb-linux-loong64-gnu')
391
391
  const bindingPackageVersion = require('@node-usb/usb-linux-loong64-gnu/package.json').version
392
- if (bindingPackageVersion !== '3.0.0-alpha.1' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
393
- throw new Error(`Native binding package version mismatch, expected 3.0.0-alpha.1 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
392
+ if (bindingPackageVersion !== '3.0.0-alpha.3' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
393
+ throw new Error(`Native binding package version mismatch, expected 3.0.0-alpha.3 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
394
394
  }
395
395
  return binding
396
396
  } catch (e) {
@@ -407,8 +407,8 @@ function requireNative() {
407
407
  try {
408
408
  const binding = require('@node-usb/usb-linux-riscv64-musl')
409
409
  const bindingPackageVersion = require('@node-usb/usb-linux-riscv64-musl/package.json').version
410
- if (bindingPackageVersion !== '3.0.0-alpha.1' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
411
- throw new Error(`Native binding package version mismatch, expected 3.0.0-alpha.1 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
410
+ if (bindingPackageVersion !== '3.0.0-alpha.3' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
411
+ throw new Error(`Native binding package version mismatch, expected 3.0.0-alpha.3 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
412
412
  }
413
413
  return binding
414
414
  } catch (e) {
@@ -423,8 +423,8 @@ function requireNative() {
423
423
  try {
424
424
  const binding = require('@node-usb/usb-linux-riscv64-gnu')
425
425
  const bindingPackageVersion = require('@node-usb/usb-linux-riscv64-gnu/package.json').version
426
- if (bindingPackageVersion !== '3.0.0-alpha.1' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
427
- throw new Error(`Native binding package version mismatch, expected 3.0.0-alpha.1 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
426
+ if (bindingPackageVersion !== '3.0.0-alpha.3' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
427
+ throw new Error(`Native binding package version mismatch, expected 3.0.0-alpha.3 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
428
428
  }
429
429
  return binding
430
430
  } catch (e) {
@@ -440,8 +440,8 @@ function requireNative() {
440
440
  try {
441
441
  const binding = require('@node-usb/usb-linux-ppc64-gnu')
442
442
  const bindingPackageVersion = require('@node-usb/usb-linux-ppc64-gnu/package.json').version
443
- if (bindingPackageVersion !== '3.0.0-alpha.1' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
444
- throw new Error(`Native binding package version mismatch, expected 3.0.0-alpha.1 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
443
+ if (bindingPackageVersion !== '3.0.0-alpha.3' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
444
+ throw new Error(`Native binding package version mismatch, expected 3.0.0-alpha.3 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
445
445
  }
446
446
  return binding
447
447
  } catch (e) {
@@ -456,8 +456,8 @@ function requireNative() {
456
456
  try {
457
457
  const binding = require('@node-usb/usb-linux-s390x-gnu')
458
458
  const bindingPackageVersion = require('@node-usb/usb-linux-s390x-gnu/package.json').version
459
- if (bindingPackageVersion !== '3.0.0-alpha.1' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
460
- throw new Error(`Native binding package version mismatch, expected 3.0.0-alpha.1 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
459
+ if (bindingPackageVersion !== '3.0.0-alpha.3' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
460
+ throw new Error(`Native binding package version mismatch, expected 3.0.0-alpha.3 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
461
461
  }
462
462
  return binding
463
463
  } catch (e) {
@@ -476,8 +476,8 @@ function requireNative() {
476
476
  try {
477
477
  const binding = require('@node-usb/usb-openharmony-arm64')
478
478
  const bindingPackageVersion = require('@node-usb/usb-openharmony-arm64/package.json').version
479
- if (bindingPackageVersion !== '3.0.0-alpha.1' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
480
- throw new Error(`Native binding package version mismatch, expected 3.0.0-alpha.1 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
479
+ if (bindingPackageVersion !== '3.0.0-alpha.3' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
480
+ throw new Error(`Native binding package version mismatch, expected 3.0.0-alpha.3 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
481
481
  }
482
482
  return binding
483
483
  } catch (e) {
@@ -492,8 +492,8 @@ function requireNative() {
492
492
  try {
493
493
  const binding = require('@node-usb/usb-openharmony-x64')
494
494
  const bindingPackageVersion = require('@node-usb/usb-openharmony-x64/package.json').version
495
- if (bindingPackageVersion !== '3.0.0-alpha.1' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
496
- throw new Error(`Native binding package version mismatch, expected 3.0.0-alpha.1 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
495
+ if (bindingPackageVersion !== '3.0.0-alpha.3' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
496
+ throw new Error(`Native binding package version mismatch, expected 3.0.0-alpha.3 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
497
497
  }
498
498
  return binding
499
499
  } catch (e) {
@@ -508,8 +508,8 @@ function requireNative() {
508
508
  try {
509
509
  const binding = require('@node-usb/usb-openharmony-arm')
510
510
  const bindingPackageVersion = require('@node-usb/usb-openharmony-arm/package.json').version
511
- if (bindingPackageVersion !== '3.0.0-alpha.1' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
512
- throw new Error(`Native binding package version mismatch, expected 3.0.0-alpha.1 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
511
+ if (bindingPackageVersion !== '3.0.0-alpha.3' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
512
+ throw new Error(`Native binding package version mismatch, expected 3.0.0-alpha.3 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
513
513
  }
514
514
  return binding
515
515
  } catch (e) {
package/package.json CHANGED
@@ -2,14 +2,14 @@
2
2
  "name": "usb",
3
3
  "description": "Library to access USB devices",
4
4
  "license": "MIT",
5
- "version": "3.0.0-alpha.1",
5
+ "version": "3.0.0-alpha.3",
6
6
  "main": "dist/index.js",
7
7
  "engines": {
8
8
  "node": ">= 12.22.0 < 13 || >= 14.17.0 < 15 || >= 15.12.0 < 16 || >= 16.0.0"
9
9
  },
10
10
  "repository": {
11
11
  "type": "git",
12
- "url": "https://github.com/node-usb/node-usb.git"
12
+ "url": "https://github.com/node-usb/node-usb-rs.git"
13
13
  },
14
14
  "publishConfig": {
15
15
  "registry": "https://registry.npmjs.org/",
@@ -49,21 +49,23 @@
49
49
  "prepublishOnly": "napi prepublish -t npm",
50
50
  "preversion": "napi build --platform && git add .",
51
51
  "version": "napi version",
52
- "create-npm-dirs": "napi create-npm-dirs"
52
+ "create-npm-dirs": "napi create-npm-dirs",
53
+ "docs": "typedoc"
53
54
  },
54
55
  "dependencies": {
55
56
  "@types/w3c-web-usb": "^1.0.13"
56
57
  },
57
58
  "devDependencies": {
58
59
  "@napi-rs/cli": "^3.2.0",
59
- "@types/node": "^25.0.10",
60
60
  "coffeescript": "^2.7.0",
61
61
  "mocha": "^11.7.5",
62
+ "typedoc": "^0.28.16",
62
63
  "typescript": "^5.9.3"
63
64
  },
64
65
  "napi": {
65
66
  "binaryName": "usb",
66
67
  "packageName": "@node-usb/usb",
68
+ "dtsHeaderFile": "./header.d.ts",
67
69
  "targets": [
68
70
  "x86_64-pc-windows-msvc",
69
71
  "x86_64-apple-darwin",
@@ -82,15 +84,15 @@
82
84
  "index.js"
83
85
  ],
84
86
  "optionalDependencies": {
85
- "@node-usb/usb-win32-x64-msvc": "3.0.0-alpha.1",
86
- "@node-usb/usb-darwin-x64": "3.0.0-alpha.1",
87
- "@node-usb/usb-linux-x64-gnu": "3.0.0-alpha.1",
88
- "@node-usb/usb-linux-x64-musl": "3.0.0-alpha.1",
89
- "@node-usb/usb-linux-arm64-gnu": "3.0.0-alpha.1",
90
- "@node-usb/usb-win32-ia32-msvc": "3.0.0-alpha.1",
91
- "@node-usb/usb-linux-arm-gnueabihf": "3.0.0-alpha.1",
92
- "@node-usb/usb-darwin-arm64": "3.0.0-alpha.1",
93
- "@node-usb/usb-linux-arm64-musl": "3.0.0-alpha.1",
94
- "@node-usb/usb-win32-arm64-msvc": "3.0.0-alpha.1"
87
+ "@node-usb/usb-win32-x64-msvc": "3.0.0-alpha.3",
88
+ "@node-usb/usb-darwin-x64": "3.0.0-alpha.3",
89
+ "@node-usb/usb-linux-x64-gnu": "3.0.0-alpha.3",
90
+ "@node-usb/usb-linux-x64-musl": "3.0.0-alpha.3",
91
+ "@node-usb/usb-linux-arm64-gnu": "3.0.0-alpha.3",
92
+ "@node-usb/usb-win32-ia32-msvc": "3.0.0-alpha.3",
93
+ "@node-usb/usb-linux-arm-gnueabihf": "3.0.0-alpha.3",
94
+ "@node-usb/usb-darwin-arm64": "3.0.0-alpha.3",
95
+ "@node-usb/usb-linux-arm64-musl": "3.0.0-alpha.3",
96
+ "@node-usb/usb-win32-arm64-msvc": "3.0.0-alpha.3"
95
97
  }
96
98
  }