@dustid/dust-go-connect 0.1.6 → 0.1.8
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 +9 -5
- package/lib/chromeWebView.d.ts +3 -1
- package/lib/dispatcher.d.ts +2 -2
- package/lib/index.d.ts +10 -2
- package/lib/index.js +1 -1
- package/lib/reactNativeWebView.d.ts +8 -2
- package/lib/types.d.ts +63 -12
- package/package.json +5 -7
package/README.md
CHANGED
|
@@ -62,20 +62,24 @@ webview isn't paused while the scanner is presented.
|
|
|
62
62
|
```typescript
|
|
63
63
|
type ScanPayload =
|
|
64
64
|
| {
|
|
65
|
-
type: '
|
|
65
|
+
type: 'DUST'
|
|
66
66
|
data: string
|
|
67
67
|
metadata?: ScanSettings
|
|
68
68
|
}
|
|
69
69
|
| {
|
|
70
|
-
type: '
|
|
70
|
+
type: 'QR'
|
|
71
71
|
data: string
|
|
72
72
|
metadata?: Record<string, any>
|
|
73
73
|
}
|
|
74
|
-
| { type: '
|
|
75
|
-
| { type: '
|
|
76
|
-
| { type: '
|
|
74
|
+
| { type: 'BARCODE'; data: string; metadata?: Record<string, any> }
|
|
75
|
+
| { type: 'DATA_MATRIX'; data: string; metadata?: Record<string, any> }
|
|
76
|
+
| { type: 'NFC'; data: string; metadata?: Record<string, any> }
|
|
77
77
|
```
|
|
78
78
|
|
|
79
|
+
`ScanSettings` can include optional Android Dragon capture fields:
|
|
80
|
+
`captureSource`, `usbVendorId`, `usbProductId`, `usbDeviceName`,
|
|
81
|
+
`androidCameraId`, `dragonBackend`, and `dragonErrorCode`.
|
|
82
|
+
|
|
79
83
|
| Scan Events |
|
|
80
84
|
| --------------------------------------- |
|
|
81
85
|
| `{ type: 'scan', payload: ScanPayload}` |
|
package/lib/chromeWebView.d.ts
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
import { Dispatcher } from './dispatcher';
|
|
2
|
-
import { type DustGoConnector } from './types';
|
|
2
|
+
import { type AuthSessionResult, type DustGoConnector } from './types';
|
|
3
3
|
export declare class ChromeWebViewDustGoConnector extends Dispatcher implements DustGoConnector {
|
|
4
4
|
static detected: boolean;
|
|
5
5
|
constructor();
|
|
6
|
+
get appScheme(): string;
|
|
6
7
|
rewriteRedirect(url: URL): URL;
|
|
8
|
+
openAuthSession(): Promise<AuthSessionResult>;
|
|
7
9
|
showScanner(): void;
|
|
8
10
|
hideScanner(): void;
|
|
9
11
|
}
|
package/lib/dispatcher.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { EventType, ScanCallback
|
|
1
|
+
import type { ConnectorEvent, EventType, ScanCallback } from './types';
|
|
2
2
|
export declare class Dispatcher {
|
|
3
3
|
private callbacks;
|
|
4
4
|
/**
|
|
@@ -26,7 +26,7 @@ export declare class Dispatcher {
|
|
|
26
26
|
/**
|
|
27
27
|
* Fires the specified event, calling all registered callbacks for that event type.
|
|
28
28
|
* */
|
|
29
|
-
dispatch(event:
|
|
29
|
+
dispatch(event: ConnectorEvent): void;
|
|
30
30
|
/**
|
|
31
31
|
* @deprecated
|
|
32
32
|
* This keeps compatibility with the previous dispatch API.
|
package/lib/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type { ChromeWebView, DustGoConnector, ReactNativeWebView, ScanPayload } from './types';
|
|
2
|
-
export type { DustGoConnector, ScanEvent, ScanPayload } from './types';
|
|
1
|
+
import type { AuthSessionResult, ChromeWebView, DustGoConnector, ReactNativeWebView, ScanPayload } from './types';
|
|
2
|
+
export type { AuthSessionResult, AuthSessionResultEvent, ConnectorEvent, DustGoConnector, OpenAuthSessionMessage, ScanEvent, ScanPayload, } from './types';
|
|
3
3
|
declare global {
|
|
4
4
|
interface Window {
|
|
5
5
|
dustGoConnector?: DustGoConnector;
|
|
@@ -12,4 +12,12 @@ declare global {
|
|
|
12
12
|
* Rejects if scanner is hidden.
|
|
13
13
|
* */
|
|
14
14
|
export declare const scanAsync: () => Promise<ScanPayload>;
|
|
15
|
+
/**
|
|
16
|
+
* Opens an authentication URL in the system browser via the native app.
|
|
17
|
+
* Returns a promise that resolves with the auth session result.
|
|
18
|
+
*
|
|
19
|
+
* @param url - The authentication URL to open (must be HTTPS).
|
|
20
|
+
* @param redirectUrl - The callback URL the auth server will redirect to.
|
|
21
|
+
*/
|
|
22
|
+
export declare const openAuthSessionAsync: (url: string, redirectUrl?: string) => Promise<AuthSessionResult>;
|
|
15
23
|
export declare const connector: DustGoConnector | undefined;
|
package/lib/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
class
|
|
1
|
+
class t{callbacks=new Map;add(e,s){this.callbacks.set(e,s)}has(e){return this.callbacks.has(e)}clear(){this.callbacks.clear()}remove(e){if(!e&&!this.callbacks.size)return;if(!e){this.callbacks.clear();return}this.callbacks.delete(e)}dispatch(e){if(e.type==="authSessionResult")return;this.callbacks.forEach((s)=>{s(e)})}dispatchEvent(e,s){switch(e){case"scan":{let o=(s.type??"DUST").toUpperCase(),i=o==="QR"||o==="BARCODE"||o==="DATA_MATRIX"||o==="NFC"?o:"DUST";this.dispatch({type:"scan",payload:{type:i,data:s.data,metadata:s.metadata||{}}})}break;case"hide":case"show":this.dispatch({type:e});break;default:throw Error(`Unknown event type: ${e}`)}}}class n extends t{static detected=Boolean(globalThis.window?.chrome?.webview);constructor(){if(!globalThis.window?.chrome?.webview)throw Error("Could not init ChromeWebViewDustGoConnector");super()}get appScheme(){return""}rewriteRedirect(e){return e}openAuthSession(){return Promise.resolve({type:"error",message:"Not supported in Chrome WebView"})}showScanner(){globalThis.window?.chrome?.webview?.postMessage("show")}hideScanner(){globalThis.window?.chrome?.webview?.postMessage("hide")}}class r extends t{_appScheme="dustgo";pendingAuthSessions=new Map;static detected=Boolean(globalThis.window?.ReactNativeWebView?.postMessage);constructor(){if(!globalThis.window?.ReactNativeWebView?.postMessage)throw Error("Could not init ReactNativeWebViewDustGoConnector");super();let e=this.readInjectedBridgeConfig();this._appScheme=e.appScheme??e.appId??this._appScheme}get appScheme(){return this.getResolvedAppScheme()}rewriteRedirect(e){let s=this.getResolvedAppScheme();return new URL(e.href.replace(e.protocol,`${s}:`))}openAuthSession(e,s){let o=Math.random().toString(36).substring(2,15),i=s??`${this.appScheme}://auth-callback`;return new Promise((p)=>{this.pendingAuthSessions.set(o,{resolve:p}),globalThis.window?.ReactNativeWebView?.postMessage(JSON.stringify({type:"openAuthSession",id:o,url:e,redirectUrl:i}))})}dispatch(e){if(e.type==="authSessionResult"){let s=this.pendingAuthSessions.get(e.id);if(s)s.resolve(e.result),this.pendingAuthSessions.delete(e.id);return}super.dispatch(e)}getResolvedAppScheme(){let e=this.readInjectedBridgeConfig();return e.appScheme??e.appId??this._appScheme}showScanner(){globalThis.window?.ReactNativeWebView?.postMessage("show")}hideScanner(){globalThis.window?.ReactNativeWebView?.postMessage("hide")}readInjectedBridgeConfig(){try{let e=globalThis.window?.ReactNativeWebView?.injectedObjectJson?.();if(!e)return{};let s=JSON.parse(e);return{appId:typeof s.appId==="string"?s.appId:void 0,appScheme:typeof s.appScheme==="string"?s.appScheme:void 0}}catch{return{}}}}var d=()=>{return new Promise((e,s)=>{if(!window.dustGoConnector){s("DUST Go connector is not present");return}let o=Math.random().toString(36).substring(2,15),i=window.dustGoConnector;i.showScanner();let p=(h)=>{switch(h.type){case"scan":e(h.payload);break;case"hide":s("Scanner was hidden");break}i.remove(o)};i.add(o,p)})},l=(e,s)=>{if(!window.dustGoConnector)return Promise.resolve({type:"error",message:"DUST Go connector is not present"});return window.dustGoConnector.openAuthSession(e,s)};if(r.detected)globalThis.window.dustGoConnector=new r;else if(n.detected)globalThis.window.dustGoConnector=new n;var R=globalThis.window?.dustGoConnector;export{d as scanAsync,l as openAuthSessionAsync,R as connector};
|
|
@@ -1,10 +1,16 @@
|
|
|
1
1
|
import { Dispatcher } from './dispatcher';
|
|
2
|
-
import type { DustGoConnector } from './types';
|
|
2
|
+
import type { AuthSessionResult, ConnectorEvent, DustGoConnector } from './types';
|
|
3
3
|
export declare class ReactNativeWebViewDustGoConnector extends Dispatcher implements DustGoConnector {
|
|
4
|
-
private
|
|
4
|
+
private _appScheme;
|
|
5
|
+
private pendingAuthSessions;
|
|
5
6
|
static detected: boolean;
|
|
6
7
|
constructor();
|
|
8
|
+
get appScheme(): string;
|
|
7
9
|
rewriteRedirect(url: URL): URL;
|
|
10
|
+
openAuthSession(url: string, redirectUrl?: string): Promise<AuthSessionResult>;
|
|
11
|
+
dispatch(event: ConnectorEvent): void;
|
|
12
|
+
private getResolvedAppScheme;
|
|
8
13
|
showScanner(): void;
|
|
9
14
|
hideScanner(): void;
|
|
15
|
+
private readInjectedBridgeConfig;
|
|
10
16
|
}
|
package/lib/types.d.ts
CHANGED
|
@@ -5,10 +5,11 @@ export type ChromeWebView = {
|
|
|
5
5
|
};
|
|
6
6
|
export type ReactNativeWebView = {
|
|
7
7
|
postMessage(val: string): void;
|
|
8
|
-
injectedObjectJson(): string | undefined;
|
|
8
|
+
injectedObjectJson?(): string | undefined;
|
|
9
9
|
};
|
|
10
10
|
export type EventType = 'scan' | 'hide' | 'show';
|
|
11
11
|
export type ScanSettings = {
|
|
12
|
+
deviceId?: string | null;
|
|
12
13
|
brand?: string | null;
|
|
13
14
|
deviceName?: string | null;
|
|
14
15
|
deviceType?: 'DESKTOP' | 'PHONE' | 'TABLET' | 'TV' | 'UNKNOWN' | null;
|
|
@@ -37,32 +38,46 @@ export type ScanSettings = {
|
|
|
37
38
|
longitude?: number | null;
|
|
38
39
|
accuracy?: number | null;
|
|
39
40
|
tapToFocusCount?: number | null;
|
|
41
|
+
captureSource?: 'INTERNAL_CAMERA' | 'EXTERNAL_CAMERA' | 'DRAGON_UVC' | null;
|
|
42
|
+
usbVendorId?: number | null;
|
|
43
|
+
usbProductId?: number | null;
|
|
44
|
+
usbDeviceName?: string | null;
|
|
45
|
+
androidCameraId?: string | null;
|
|
46
|
+
cameraId?: string | null;
|
|
47
|
+
selectedLens?: string | null;
|
|
48
|
+
dragonBackend?: 'camera2_external' | 'uvc_native' | 'none' | null;
|
|
49
|
+
dragonErrorCode?: string | null;
|
|
50
|
+
calibrationVersion?: string | null;
|
|
51
|
+
calibrationId?: string | null;
|
|
52
|
+
calibrationConfidence?: number | null;
|
|
53
|
+
calibrationZoom?: number | null;
|
|
40
54
|
};
|
|
55
|
+
export type ScanMetadata = ScanSettings & Record<string, any>;
|
|
41
56
|
export type EnrollMetadata = {
|
|
42
57
|
latitude?: number;
|
|
43
58
|
longitude?: number;
|
|
44
59
|
accuracy?: number;
|
|
45
60
|
};
|
|
46
61
|
export type ScanPayload = {
|
|
47
|
-
type: '
|
|
62
|
+
type: 'DUST';
|
|
48
63
|
data: string;
|
|
49
|
-
metadata?:
|
|
64
|
+
metadata?: ScanMetadata;
|
|
50
65
|
} | {
|
|
51
|
-
type: '
|
|
66
|
+
type: 'QR';
|
|
52
67
|
data: string;
|
|
53
|
-
metadata?:
|
|
68
|
+
metadata?: ScanMetadata;
|
|
54
69
|
} | {
|
|
55
|
-
type: '
|
|
70
|
+
type: 'BARCODE';
|
|
56
71
|
data: string;
|
|
57
|
-
metadata?:
|
|
72
|
+
metadata?: ScanMetadata;
|
|
58
73
|
} | {
|
|
59
|
-
type: '
|
|
74
|
+
type: 'DATA_MATRIX';
|
|
60
75
|
data: string;
|
|
61
|
-
metadata?:
|
|
76
|
+
metadata?: ScanMetadata;
|
|
62
77
|
} | {
|
|
63
|
-
type: '
|
|
78
|
+
type: 'NFC';
|
|
64
79
|
data: string;
|
|
65
|
-
metadata?:
|
|
80
|
+
metadata?: ScanMetadata;
|
|
66
81
|
};
|
|
67
82
|
export type ScanEvent = {
|
|
68
83
|
type: 'scan';
|
|
@@ -72,16 +87,52 @@ export type ScanEvent = {
|
|
|
72
87
|
} | {
|
|
73
88
|
type: 'show';
|
|
74
89
|
};
|
|
90
|
+
export type AuthSessionResult = {
|
|
91
|
+
type: 'success';
|
|
92
|
+
url: string;
|
|
93
|
+
} | {
|
|
94
|
+
type: 'cancel';
|
|
95
|
+
} | {
|
|
96
|
+
type: 'error';
|
|
97
|
+
message: string;
|
|
98
|
+
};
|
|
99
|
+
export type AuthSessionResultEvent = {
|
|
100
|
+
type: 'authSessionResult';
|
|
101
|
+
id: string;
|
|
102
|
+
result: AuthSessionResult;
|
|
103
|
+
};
|
|
104
|
+
/** Union of all events the connector can dispatch. */
|
|
105
|
+
export type ConnectorEvent = ScanEvent | AuthSessionResultEvent;
|
|
106
|
+
export type OpenAuthSessionMessage = {
|
|
107
|
+
type: 'openAuthSession';
|
|
108
|
+
id: string;
|
|
109
|
+
url: string;
|
|
110
|
+
redirectUrl: string;
|
|
111
|
+
};
|
|
75
112
|
export type ScanCallback = (event: ScanEvent) => void;
|
|
76
113
|
export interface DustGoConnector {
|
|
77
114
|
showScanner(): void;
|
|
78
115
|
hideScanner(): void;
|
|
116
|
+
/** The custom URL scheme of the host app (e.g. `"dustgo"`). */
|
|
117
|
+
readonly appScheme: string;
|
|
79
118
|
/**
|
|
119
|
+
* @deprecated Use {@link openAuthSession} instead for OAuth/OIDC flows.
|
|
120
|
+
*
|
|
80
121
|
* Rewrites the URL protocol for redirection on different platforms.
|
|
81
122
|
*
|
|
82
123
|
* e.g. `https://example.com/scan?data=123` to `dustgo://example.com/scan?data=123`
|
|
83
124
|
* */
|
|
84
125
|
rewriteRedirect(url: URL): URL;
|
|
126
|
+
/**
|
|
127
|
+
* Opens a URL in the system browser for authentication purposes.
|
|
128
|
+
* The native app opens the URL as-is (no modification).
|
|
129
|
+
* Returns a promise that resolves with the auth session result.
|
|
130
|
+
*
|
|
131
|
+
* @param url - The authentication URL to open (must be HTTPS).
|
|
132
|
+
* @param redirectUrl - The callback URL the auth server will redirect to.
|
|
133
|
+
* Defaults to `${appScheme}://auth-callback` if not provided.
|
|
134
|
+
*/
|
|
135
|
+
openAuthSession(url: string, redirectUrl?: string): Promise<AuthSessionResult>;
|
|
85
136
|
/**
|
|
86
137
|
* Adds an event listener for the specified event type and id.
|
|
87
138
|
* @param id - A unique identifier for the event listener. This allows multiple listeners for the same event type.
|
|
@@ -107,7 +158,7 @@ export interface DustGoConnector {
|
|
|
107
158
|
/**
|
|
108
159
|
* Fires the specified event, calling all registered callbacks for that event type.
|
|
109
160
|
* */
|
|
110
|
-
dispatch(event:
|
|
161
|
+
dispatch(event: ConnectorEvent): void;
|
|
111
162
|
/**
|
|
112
163
|
* @deprecated
|
|
113
164
|
* This keeps compatibility with the previous dispatch API.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dustid/dust-go-connect",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.8",
|
|
4
4
|
"description": "A library for connecting a frontend application to the DUST GO react native application",
|
|
5
5
|
"main": "./lib/index.js",
|
|
6
6
|
"files": [
|
|
@@ -47,14 +47,12 @@
|
|
|
47
47
|
],
|
|
48
48
|
"homepage": "https://go.dustid.io",
|
|
49
49
|
"devDependencies": {
|
|
50
|
-
"@biomejs/biome": "^2.
|
|
50
|
+
"@biomejs/biome": "^2.4.4",
|
|
51
51
|
"@ryansonshine/commitizen": "^4.2.8",
|
|
52
52
|
"@ryansonshine/cz-conventional-changelog": "^3.3.4",
|
|
53
53
|
"@types/jest": "^27.5.2",
|
|
54
54
|
"@types/node": "^12.20.55",
|
|
55
|
-
"
|
|
56
|
-
"@typescript-eslint/parser": "^4.33.0",
|
|
57
|
-
"bun-types": "^1.3.0",
|
|
55
|
+
"bun-types": "^1.3.9",
|
|
58
56
|
"conventional-changelog-conventionalcommits": "^5.0.0",
|
|
59
57
|
"husky": "^6.0.0",
|
|
60
58
|
"jest": "^27.5.1",
|
|
@@ -63,7 +61,7 @@
|
|
|
63
61
|
"ts-jest": "^27.1.5",
|
|
64
62
|
"ts-node": "^10.9.2",
|
|
65
63
|
"typedoc": "^0.26.11",
|
|
66
|
-
"typedoc-plugin-markdown": "^4.
|
|
64
|
+
"typedoc-plugin-markdown": "^4.10.0",
|
|
67
65
|
"typescript": "^5.9.3"
|
|
68
66
|
},
|
|
69
67
|
"config": {
|
|
@@ -72,7 +70,7 @@
|
|
|
72
70
|
}
|
|
73
71
|
},
|
|
74
72
|
"lint-staged": {
|
|
75
|
-
"*.ts": "
|
|
73
|
+
"*.ts": "bun biome lint --fix --unsafe"
|
|
76
74
|
},
|
|
77
75
|
"release": {
|
|
78
76
|
"branches": [
|