@dustid/dust-go-connect 0.1.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.
- package/LICENSE +21 -0
- package/README.md +108 -0
- package/package.json +113 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2023 Ryan Sonshine
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
# @dustid/dust-go-connect
|
|
2
|
+
|
|
3
|
+
> DUST Go is a prototyping platform that allows developers to create
|
|
4
|
+
> mobile webapps that leverage DUST Identity's platform-dependent
|
|
5
|
+
> functionality without requiring an upfront investment into mobile
|
|
6
|
+
> toolchains.
|
|
7
|
+
|
|
8
|
+
## Install
|
|
9
|
+
|
|
10
|
+
```bash
|
|
11
|
+
npm install @dustid/dust-go-connect
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
## Usage
|
|
15
|
+
|
|
16
|
+
```typescript
|
|
17
|
+
// NOTE: connector will be undefined if running outside DUST Go
|
|
18
|
+
import { connector } from @dustid/dust-go';
|
|
19
|
+
|
|
20
|
+
const scans: {data: string, metadata: Record<string, unknownn>}[] = [];
|
|
21
|
+
|
|
22
|
+
connector?.add("unique-id-for-this-listener", (event: ScanEvent) => {
|
|
23
|
+
if (event.type === 'scan') scans.push(event.payload)
|
|
24
|
+
if (event.type === 'hide') // do something
|
|
25
|
+
if (event.type === 'show') // do something
|
|
26
|
+
});
|
|
27
|
+
connector?.showScanner();
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
# API
|
|
31
|
+
|
|
32
|
+
## High Level API
|
|
33
|
+
|
|
34
|
+
`scanAsync()` Presents the scanner, and awaits a scan.
|
|
35
|
+
Rejects if scanner is hidden.
|
|
36
|
+
|
|
37
|
+
```typescript
|
|
38
|
+
// scanAsync(): Promise<ScanPayload>
|
|
39
|
+
const scan = await scanAsync();
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
## DUST Go Connector
|
|
43
|
+
|
|
44
|
+
This is more low level, but more flexible.
|
|
45
|
+
|
|
46
|
+
```typescript
|
|
47
|
+
connector.showScanner(): void
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
Shows the scanner modal over the main webview.
|
|
51
|
+
|
|
52
|
+
```typescript
|
|
53
|
+
connector.hideScanner(): void
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
Hides the scanner modal, returning to the main webview.
|
|
57
|
+
Note, this can be called even while the webview is in the "background", the
|
|
58
|
+
webview isn't paused while the scanner is presented.
|
|
59
|
+
|
|
60
|
+
### Events
|
|
61
|
+
|
|
62
|
+
```typescript
|
|
63
|
+
type ScanPayload = { data: string; metadata?: Record<string, string> };
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
| Scan Events |
|
|
67
|
+
| --------------------------------------- |
|
|
68
|
+
| `{ type: 'scan', payload: ScanPayload}` |
|
|
69
|
+
| `{ type: 'show' }` |
|
|
70
|
+
| `{ type: 'hide' }` |
|
|
71
|
+
|
|
72
|
+
```typescript
|
|
73
|
+
connector.dispatch(event: ScanEvent): void
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
Add a listener with a unique identifier.
|
|
77
|
+
|
|
78
|
+
```typescript
|
|
79
|
+
connector.add(id: string, cb: (event: ScanEvent) => void): void
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
Remove the listener with the provided identifier.
|
|
83
|
+
|
|
84
|
+
```typescript
|
|
85
|
+
connector.remove(id: string): void
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
Check if a listener has been added for the given id
|
|
89
|
+
|
|
90
|
+
```typescript
|
|
91
|
+
connector.has(id: string): boolean
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
Remove all event listeners
|
|
95
|
+
|
|
96
|
+
```typescript
|
|
97
|
+
connector.clear();
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
### Auth
|
|
101
|
+
|
|
102
|
+
On some platforms, it's necessary to rewrite the redirects from the app to the OAuth2
|
|
103
|
+
server to work around platform limitations. It's recommended to always wrap those
|
|
104
|
+
redirects with this call, and let the connector no-op when no workaround is required.
|
|
105
|
+
|
|
106
|
+
```typescript
|
|
107
|
+
connector.rewriteRedirect(url: URL): URL
|
|
108
|
+
```
|
package/package.json
ADDED
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@dustid/dust-go-connect",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "A library for connecting a fronten application to the DUST GO react natie application",
|
|
5
|
+
"main": "./lib/index.js",
|
|
6
|
+
"files": [
|
|
7
|
+
"lib/**/*"
|
|
8
|
+
],
|
|
9
|
+
"scripts": {
|
|
10
|
+
"build": "tsc --project tsconfig.build.json",
|
|
11
|
+
"clean": "rm -rf ./lib/",
|
|
12
|
+
"cm": "cz",
|
|
13
|
+
"lint": "eslint ./src/ --fix",
|
|
14
|
+
"semantic-release": "semantic-release",
|
|
15
|
+
"typedoc": "typedoc",
|
|
16
|
+
"test:watch": "jest --watch",
|
|
17
|
+
"test": "jest --coverage",
|
|
18
|
+
"typecheck": "tsc --noEmit"
|
|
19
|
+
},
|
|
20
|
+
"license": "MIT",
|
|
21
|
+
"author": {
|
|
22
|
+
"name": "Tristan Sweeney",
|
|
23
|
+
"email": "",
|
|
24
|
+
"url": "https://github.com/sweeneytr"
|
|
25
|
+
},
|
|
26
|
+
"engines": {
|
|
27
|
+
"node": ">=12.0"
|
|
28
|
+
},
|
|
29
|
+
"keywords": [
|
|
30
|
+
"boilerplate",
|
|
31
|
+
"template",
|
|
32
|
+
"typescript",
|
|
33
|
+
"vscode",
|
|
34
|
+
"jest",
|
|
35
|
+
"husky",
|
|
36
|
+
"commitizen",
|
|
37
|
+
"semantic-release",
|
|
38
|
+
"codecov"
|
|
39
|
+
],
|
|
40
|
+
"homepage": "https://go.dustid.io",
|
|
41
|
+
"devDependencies": {
|
|
42
|
+
"@biomejs/biome": "^2.1.1",
|
|
43
|
+
"@ryansonshine/commitizen": "^4.2.8",
|
|
44
|
+
"@ryansonshine/cz-conventional-changelog": "^3.3.4",
|
|
45
|
+
"@types/jest": "^27.5.2",
|
|
46
|
+
"@types/node": "^12.20.11",
|
|
47
|
+
"@typescript-eslint/eslint-plugin": "^4.22.0",
|
|
48
|
+
"@typescript-eslint/parser": "^4.22.0",
|
|
49
|
+
"conventional-changelog-conventionalcommits": "^5.0.0",
|
|
50
|
+
"husky": "^6.0.0",
|
|
51
|
+
"jest": "^27.2.0",
|
|
52
|
+
"lint-staged": "^13.2.1",
|
|
53
|
+
"semantic-release": "^21.0.1",
|
|
54
|
+
"ts-jest": "^27.0.5",
|
|
55
|
+
"ts-node": "^10.2.1",
|
|
56
|
+
"typedoc": "^0.26.6",
|
|
57
|
+
"typedoc-plugin-markdown": "^4.2.5",
|
|
58
|
+
"typescript": "^4.2.4"
|
|
59
|
+
},
|
|
60
|
+
"config": {
|
|
61
|
+
"commitizen": {
|
|
62
|
+
"path": "./node_modules/@ryansonshine/cz-conventional-changelog"
|
|
63
|
+
}
|
|
64
|
+
},
|
|
65
|
+
"lint-staged": {
|
|
66
|
+
"*.ts": "eslint --cache --cache-location .eslintcache --fix"
|
|
67
|
+
},
|
|
68
|
+
"release": {
|
|
69
|
+
"branches": [
|
|
70
|
+
"main"
|
|
71
|
+
],
|
|
72
|
+
"plugins": [
|
|
73
|
+
[
|
|
74
|
+
"@semantic-release/commit-analyzer",
|
|
75
|
+
{
|
|
76
|
+
"preset": "conventionalcommits",
|
|
77
|
+
"releaseRules": [
|
|
78
|
+
{
|
|
79
|
+
"type": "build",
|
|
80
|
+
"scope": "deps",
|
|
81
|
+
"release": "patch"
|
|
82
|
+
}
|
|
83
|
+
]
|
|
84
|
+
}
|
|
85
|
+
],
|
|
86
|
+
[
|
|
87
|
+
"@semantic-release/release-notes-generator",
|
|
88
|
+
{
|
|
89
|
+
"preset": "conventionalcommits",
|
|
90
|
+
"presetConfig": {
|
|
91
|
+
"types": [
|
|
92
|
+
{
|
|
93
|
+
"type": "feat",
|
|
94
|
+
"section": "Features"
|
|
95
|
+
},
|
|
96
|
+
{
|
|
97
|
+
"type": "fix",
|
|
98
|
+
"section": "Bug Fixes"
|
|
99
|
+
},
|
|
100
|
+
{
|
|
101
|
+
"type": "build",
|
|
102
|
+
"section": "Dependencies and Other Build Updates",
|
|
103
|
+
"hidden": false
|
|
104
|
+
}
|
|
105
|
+
]
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
],
|
|
109
|
+
"@semantic-release/npm",
|
|
110
|
+
"@semantic-release/github"
|
|
111
|
+
]
|
|
112
|
+
}
|
|
113
|
+
}
|