@dustid/dust-go-connect 0.1.3 → 0.1.4

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.
@@ -1,5 +1,5 @@
1
1
  import { Dispatcher } from './dispatcher';
2
- import { DustGoConnector } from './types';
2
+ import { type DustGoConnector } from './types';
3
3
  export declare class ChromeWebViewDustGoConnector extends Dispatcher implements DustGoConnector {
4
4
  static detected: boolean;
5
5
  constructor();
@@ -1,4 +1,4 @@
1
- import type { EventType, ScanCallback, ScanEvent } from "./types";
1
+ import type { EventType, ScanCallback, ScanEvent } from './types';
2
2
  export declare class Dispatcher {
3
3
  private callbacks;
4
4
  /**
@@ -37,6 +37,7 @@ export declare class Dispatcher {
37
37
  * For "scan" events, this should include a `data` string and optionally `metadata`.
38
38
  * */
39
39
  dispatchEvent(event: EventType, data: {
40
+ type?: string;
40
41
  data: string;
41
42
  metadata?: Record<string, any>;
42
43
  }): void;
package/lib/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- import { ChromeWebView, DustGoConnector, ReactNativeWebView, ScanPayload } from "./types";
2
- export { DustGoConnector, ScanEvent, ScanPayload } from "./types";
1
+ import type { ChromeWebView, DustGoConnector, ReactNativeWebView, ScanPayload } from './types';
2
+ export type { DustGoConnector, ScanEvent, ScanPayload } from './types';
3
3
  declare global {
4
4
  interface Window {
5
5
  dustGoConnector?: DustGoConnector;
package/lib/index.js CHANGED
@@ -1,37 +1 @@
1
- var _a;
2
- import { ChromeWebViewDustGoConnector } from "./chromeWebView";
3
- import { ReactNativeWebViewDustGoConnector } from "./reactNativeWebView";
4
- /**
5
- * Presents the scanner, and awaits a scan.
6
- * Rejects if scanner is hidden.
7
- * */
8
- export const scanAsync = () => {
9
- return new Promise((resolve, reject) => {
10
- if (!window.dustGoConnector) {
11
- reject("DUST Go connector is not present");
12
- return;
13
- }
14
- const id = Math.random().toString(36).substring(2, 15);
15
- const connector = window.dustGoConnector;
16
- connector.showScanner();
17
- const res = (val) => {
18
- switch (val.type) {
19
- case "scan":
20
- resolve(val.payload);
21
- break;
22
- case "hide":
23
- reject("Scanner was hidden");
24
- break;
25
- }
26
- connector.remove(id);
27
- };
28
- connector.add(id, res);
29
- });
30
- };
31
- if (ReactNativeWebViewDustGoConnector.detected) {
32
- globalThis.window.dustGoConnector = new ReactNativeWebViewDustGoConnector();
33
- }
34
- else if (ChromeWebViewDustGoConnector.detected) {
35
- globalThis.window.dustGoConnector = new ChromeWebViewDustGoConnector();
36
- }
37
- export const connector = (_a = globalThis.window) === null || _a === void 0 ? void 0 : _a.dustGoConnector;
1
+ class w{callbacks=new Map;add(o,e){this.callbacks.set(o,e)}has(o){return this.callbacks.has(o)}clear(){this.callbacks.clear()}remove(o){if(!o&&!this.callbacks.size)return;if(!o){this.callbacks.clear();return}this.callbacks.delete(o)}dispatch(o){this.callbacks.forEach((e)=>{e(o)})}dispatchEvent(o,e){switch(o){case"scan":this.dispatch({type:"scan",payload:{type:"dust",data:e.data,metadata:e.metadata||{}}});break;case"hide":case"show":this.dispatch({type:o});break;default:throw Error(`Unknown event type: ${o}`)}}}class r extends w{static detected=Boolean(globalThis.window?.chrome?.webview);constructor(){if(!globalThis.window?.chrome?.webview)throw Error("Could not init ChromeWebViewDustGoConnector");super()}rewriteRedirect(o){return o}showScanner(){globalThis.window?.chrome?.webview?.postMessage("show")}hideScanner(){globalThis.window?.chrome?.webview?.postMessage("hide")}}class i extends w{appId;static detected=Boolean(globalThis.window?.ReactNativeWebView);constructor(){if(!globalThis.window?.ReactNativeWebView)throw Error("Could not init ReactNativeWebViewDustGoConnector");let o=globalThis.window?.ReactNativeWebView.injectedObjectJson(),e=JSON.parse(o??"{}");if(!("appId"in e)||typeof e.appId!=="string")throw Error("Could not validate injected JSON");super();this.appId=e.appId}rewriteRedirect(o){return new URL(o.href.replace(o.protocol,`${this.appId}:`))}showScanner(){globalThis.window?.ReactNativeWebView?.postMessage("show")}hideScanner(){globalThis.window?.ReactNativeWebView?.postMessage("hide")}}var a=()=>{return new Promise((o,e)=>{if(!window.dustGoConnector){e("DUST Go connector is not present");return}let n=Math.random().toString(36).substring(2,15),s=window.dustGoConnector;s.showScanner();let p=(t)=>{switch(t.type){case"scan":o(t.payload);break;case"hide":e("Scanner was hidden");break}s.remove(n)};s.add(n,p)})};if(i.detected)globalThis.window.dustGoConnector=new i;else if(r.detected)globalThis.window.dustGoConnector=new r;var C=globalThis.window?.dustGoConnector;export{a as scanAsync,C as connector};
@@ -1,5 +1,5 @@
1
1
  import { Dispatcher } from './dispatcher';
2
- import { DustGoConnector } from './types';
2
+ import type { DustGoConnector } from './types';
3
3
  export declare class ReactNativeWebViewDustGoConnector extends Dispatcher implements DustGoConnector {
4
4
  private appId;
5
5
  static detected: boolean;
package/lib/types.d.ts CHANGED
@@ -7,18 +7,72 @@ export type ReactNativeWebView = {
7
7
  postMessage(val: string): void;
8
8
  injectedObjectJson(): string | undefined;
9
9
  };
10
- export type EventType = "scan" | "hide" | "show";
10
+ export type EventType = 'scan' | 'hide' | 'show';
11
+ export declare const ScanSettings: import("arktype/internal/variants/object.ts").ObjectType<{
12
+ brand?: string | null | undefined;
13
+ deviceName?: string | null | undefined;
14
+ deviceType?: "DESKTOP" | "PHONE" | "TABLET" | "TV" | "UNKNOWN" | null | undefined;
15
+ modelId?: string | null | undefined;
16
+ modelName?: string | null | undefined;
17
+ osName?: string | null | undefined;
18
+ osVersion?: string | null | undefined;
19
+ osBuildId?: string | null | undefined;
20
+ appId?: string | null | undefined;
21
+ appName?: string | null | undefined;
22
+ appVersion?: string | null | undefined;
23
+ build?: string | null | undefined;
24
+ zoom?: number | ((In: string) => import("arktype/internal/attributes.ts").To<number>) | null | undefined;
25
+ focusMode?: string | null | undefined;
26
+ focusX?: number | ((In: string) => import("arktype/internal/attributes.ts").To<number>) | null | undefined;
27
+ focusY?: number | ((In: string) => import("arktype/internal/attributes.ts").To<number>) | null | undefined;
28
+ focusSetPoint?: number | ((In: string) => import("arktype/internal/attributes.ts").To<number>) | null | undefined;
29
+ focusDepth?: number | ((In: string) => import("arktype/internal/attributes.ts").To<number>) | null | undefined;
30
+ lensPosition?: number | ((In: string) => import("arktype/internal/attributes.ts").To<number>) | null | undefined;
31
+ autoFocusRangeRestriction?: "none" | "near" | "far" | null | undefined;
32
+ exposureDuration?: number | ((In: string) => import("arktype/internal/attributes.ts").To<number>) | null | undefined;
33
+ iso?: number | ((In: string) => import("arktype/internal/attributes.ts").To<number>) | null | undefined;
34
+ exposureValue?: number | ((In: string) => import("arktype/internal/attributes.ts").To<number>) | null | undefined;
35
+ flashMode?: "auto" | "off" | "on" | "torch" | null | undefined;
36
+ latitude?: number | ((In: string) => import("arktype/internal/attributes.ts").To<number>) | null | undefined;
37
+ longitude?: number | ((In: string) => import("arktype/internal/attributes.ts").To<number>) | null | undefined;
38
+ accuracy?: number | ((In: string) => import("arktype/internal/attributes.ts").To<number>) | null | undefined;
39
+ tapToFocusCount?: number | ((In: string) => import("arktype/internal/attributes.ts").To<number>) | null | undefined;
40
+ }, {}>;
41
+ export type ScanSettings = typeof ScanSettings.infer;
42
+ export declare const EnrollMetadata: import("arktype/internal/variants/object.ts").ObjectType<{
43
+ latitude?: number | ((In: string) => import("arktype/internal/attributes.ts").To<number>) | null | undefined;
44
+ longitude?: number | ((In: string) => import("arktype/internal/attributes.ts").To<number>) | null | undefined;
45
+ accuracy?: number | ((In: string) => import("arktype/internal/attributes.ts").To<number>) | null | undefined;
46
+ }, {}>;
47
+ export type EnrollMetadata = typeof EnrollMetadata.infer;
11
48
  export type ScanPayload = {
49
+ type: 'dust';
50
+ data: string;
51
+ metadata?: ScanSettings;
52
+ } | {
53
+ type: 'qr';
54
+ data: string;
55
+ metadata?: Record<string, any>;
56
+ } | {
57
+ type: 'barcode';
58
+ data: string;
59
+ metadata?: Record<string, any>;
60
+ } | {
61
+ type: 'data_matrix';
62
+ data: string;
63
+ metadata?: Record<string, any>;
64
+ } | {
65
+ type: 'nfc';
12
66
  data: string;
13
67
  metadata?: Record<string, any>;
14
68
  };
15
69
  export type ScanEvent = {
16
- type: "scan";
70
+ type: 'scan';
17
71
  payload: ScanPayload;
18
72
  } | {
19
- type: "hide";
73
+ type: 'hide';
20
74
  } | {
21
- type: "show";
75
+ type: 'show';
22
76
  };
23
77
  export type ScanCallback = (event: ScanEvent) => void;
24
78
  export interface DustGoConnector {
package/package.json CHANGED
@@ -1,34 +1,30 @@
1
1
  {
2
2
  "name": "@dustid/dust-go-connect",
3
- "version": "0.1.3",
4
- "description": "A library for connecting a fronten application to the DUST GO react native application",
3
+ "version": "0.1.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": [
7
7
  "lib/**/*"
8
8
  ],
9
+ "type": "module",
9
10
  "scripts": {
10
- "build": "tsc --project tsconfig.build.json",
11
+ "build": "bun build --minify --target node ./src/index.ts --outdir=./lib && bun run build:declaration",
12
+ "build:declaration": "tsc --emitDeclarationOnly --project tsconfig.types.json",
11
13
  "clean": "rm -rf ./lib/",
12
14
  "cm": "cz",
13
- "lint": "eslint ./src/ --fix",
15
+ "lint": "bun biome lint --fix --unsafe",
14
16
  "semantic-release": "semantic-release",
15
- "typedoc": "typedoc",
16
17
  "test:watch": "jest --watch",
17
18
  "test": "jest --coverage",
18
19
  "typecheck": "tsc --noEmit"
19
20
  },
20
21
  "license": "MIT",
21
22
  "author": {
22
- "name": "Tristan Sweeney",
23
- "email": "",
24
- "url": "https://github.com/sweeneytr"
23
+ "name": "Daniel Capecci",
24
+ "email": "dcapecci@dustidentity.com",
25
+ "url": ""
25
26
  },
26
27
  "contributors": [
27
- {
28
- "name": "Daniel Capecci",
29
- "email": "dcapecci@dustidentity.com",
30
- "url": ""
31
- },
32
28
  {
33
29
  "name": "Chris Mcgee",
34
30
  "email": "",
@@ -51,23 +47,24 @@
51
47
  ],
52
48
  "homepage": "https://go.dustid.io",
53
49
  "devDependencies": {
54
- "@biomejs/biome": "^2.1.1",
50
+ "@biomejs/biome": "^2.2.6",
55
51
  "@ryansonshine/commitizen": "^4.2.8",
56
52
  "@ryansonshine/cz-conventional-changelog": "^3.3.4",
57
53
  "@types/jest": "^27.5.2",
58
- "@types/node": "^12.20.11",
59
- "@typescript-eslint/eslint-plugin": "^4.22.0",
60
- "@typescript-eslint/parser": "^4.22.0",
54
+ "@types/node": "^12.20.55",
55
+ "@typescript-eslint/eslint-plugin": "^4.33.0",
56
+ "@typescript-eslint/parser": "^4.33.0",
57
+ "bun-types": "^1.3.0",
61
58
  "conventional-changelog-conventionalcommits": "^5.0.0",
62
59
  "husky": "^6.0.0",
63
- "jest": "^27.2.0",
64
- "lint-staged": "^13.2.1",
65
- "semantic-release": "^21.0.1",
66
- "ts-jest": "^27.0.5",
67
- "ts-node": "^10.2.1",
68
- "typedoc": "^0.26.6",
69
- "typedoc-plugin-markdown": "^4.2.5",
70
- "typescript": "^4.2.4"
60
+ "jest": "^27.5.1",
61
+ "lint-staged": "^13.3.0",
62
+ "semantic-release": "^21.1.2",
63
+ "ts-jest": "^27.1.5",
64
+ "ts-node": "^10.9.2",
65
+ "typedoc": "^0.26.11",
66
+ "typedoc-plugin-markdown": "^4.9.0",
67
+ "typescript": "^5.9.3"
71
68
  },
72
69
  "config": {
73
70
  "commitizen": {
@@ -121,5 +118,8 @@
121
118
  "@semantic-release/npm",
122
119
  "@semantic-release/github"
123
120
  ]
121
+ },
122
+ "dependencies": {
123
+ "arktype": "^2.1.23"
124
124
  }
125
125
  }
@@ -1,23 +0,0 @@
1
- var _a, _b;
2
- import { Dispatcher } from './dispatcher';
3
- export class ChromeWebViewDustGoConnector extends Dispatcher {
4
- constructor() {
5
- var _a, _b;
6
- if (!((_b = (_a = globalThis.window) === null || _a === void 0 ? void 0 : _a.chrome) === null || _b === void 0 ? void 0 : _b.webview)) {
7
- throw new Error('Could not init ChromeWebViewDustGoConnector');
8
- }
9
- super();
10
- }
11
- rewriteRedirect(url) {
12
- return url;
13
- }
14
- showScanner() {
15
- var _a, _b, _c;
16
- (_c = (_b = (_a = globalThis.window) === null || _a === void 0 ? void 0 : _a.chrome) === null || _b === void 0 ? void 0 : _b.webview) === null || _c === void 0 ? void 0 : _c.postMessage('show');
17
- }
18
- hideScanner() {
19
- var _a, _b, _c;
20
- (_c = (_b = (_a = globalThis.window) === null || _a === void 0 ? void 0 : _a.chrome) === null || _b === void 0 ? void 0 : _b.webview) === null || _c === void 0 ? void 0 : _c.postMessage('hide');
21
- }
22
- }
23
- ChromeWebViewDustGoConnector.detected = Boolean((_b = (_a = globalThis.window) === null || _a === void 0 ? void 0 : _a.chrome) === null || _b === void 0 ? void 0 : _b.webview);
package/lib/dispatcher.js DELETED
@@ -1,77 +0,0 @@
1
- export class Dispatcher {
2
- constructor() {
3
- this.callbacks = new Map();
4
- }
5
- /**
6
- * Adds an event listener for the specified event type and id.
7
- * * @param id - A unique identifier for the event listener. This allows multiple listeners for the same event type.
8
- * * @param cb - The callback function to be called when the event is dispatched. The type of the callback depends on the event type:
9
- * */
10
- add(id, cb) {
11
- this.callbacks.set(id, cb);
12
- }
13
- /**
14
- * Checks if an event listener exists for the specified event type and id.
15
- * */
16
- has(id) {
17
- return this.callbacks.has(id);
18
- }
19
- /**
20
- * Remove all event listeners.
21
- */
22
- clear() {
23
- this.callbacks.clear();
24
- }
25
- /**
26
- * Removes an event listener for the specified event type and id.
27
- *
28
- * @param event - The type of event to stop listening for, either "scan", "show", or "hide".
29
- * @param id - The unique identifier for the event listener to be removed. If not provided, all listeners for the specified event type are removed.
30
- * if no id is provided, all listeners for that event type are removed.
31
- * */
32
- remove(id) {
33
- if (!id && !this.callbacks.size) {
34
- return;
35
- }
36
- if (!id) {
37
- this.callbacks.clear();
38
- return;
39
- }
40
- this.callbacks.delete(id);
41
- }
42
- /**
43
- * Fires the specified event, calling all registered callbacks for that event type.
44
- * */
45
- dispatch(event) {
46
- this.callbacks.forEach((cb) => {
47
- cb(event);
48
- });
49
- }
50
- /**
51
- * @deprecated
52
- * This keeps compatibility with the previous dispatch API.
53
- * Still currently used by the `dust-go` react native package.
54
- *
55
- * @param event - The type of event to dispatch, either "scan", "show", or "hide".
56
- * @param data - The data to be passed to the event listeners.
57
- * For "scan" events, this should include a `data` string and optionally `metadata`.
58
- * */
59
- dispatchEvent(event, data) {
60
- switch (event) {
61
- case "scan":
62
- this.dispatch({
63
- type: "scan",
64
- payload: data,
65
- });
66
- break;
67
- case "hide":
68
- case "show":
69
- this.dispatch({
70
- type: event,
71
- });
72
- break;
73
- default:
74
- throw new Error(`Unknown event type: ${event}`);
75
- }
76
- }
77
- }
@@ -1,29 +0,0 @@
1
- var _a;
2
- import { Dispatcher } from './dispatcher';
3
- export class ReactNativeWebViewDustGoConnector extends Dispatcher {
4
- constructor() {
5
- var _a, _b;
6
- if (!((_a = globalThis.window) === null || _a === void 0 ? void 0 : _a.ReactNativeWebView)) {
7
- throw new Error('Could not init ReactNativeWebViewDustGoConnector');
8
- }
9
- const raw = (_b = globalThis.window) === null || _b === void 0 ? void 0 : _b.ReactNativeWebView.injectedObjectJson();
10
- const parsed = JSON.parse(raw !== null && raw !== void 0 ? raw : '{}');
11
- if (!('appId' in parsed) || !(typeof parsed.appId === 'string')) {
12
- throw new Error('Could not validate injected JSON');
13
- }
14
- super();
15
- this.appId = parsed.appId;
16
- }
17
- rewriteRedirect(url) {
18
- return new URL(url.href.replace(url.protocol, `${this.appId}:`));
19
- }
20
- showScanner() {
21
- var _a, _b;
22
- (_b = (_a = globalThis.window) === null || _a === void 0 ? void 0 : _a.ReactNativeWebView) === null || _b === void 0 ? void 0 : _b.postMessage('show');
23
- }
24
- hideScanner() {
25
- var _a, _b;
26
- (_b = (_a = globalThis.window) === null || _a === void 0 ? void 0 : _a.ReactNativeWebView) === null || _b === void 0 ? void 0 : _b.postMessage('hide');
27
- }
28
- }
29
- ReactNativeWebViewDustGoConnector.detected = Boolean((_a = globalThis.window) === null || _a === void 0 ? void 0 : _a.ReactNativeWebView);
package/lib/types.js DELETED
@@ -1 +0,0 @@
1
- export {};