@soyio/soyio-rn-sdk 0.2.2
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/.eslintignore +2 -0
- package/.eslintrc.js +46 -0
- package/.expo/README.md +15 -0
- package/.expo/devices.json +3 -0
- package/.expo/metro/externals/assert/index.js +1 -0
- package/.expo/metro/externals/async_hooks/index.js +1 -0
- package/.expo/metro/externals/buffer/index.js +1 -0
- package/.expo/metro/externals/child_process/index.js +1 -0
- package/.expo/metro/externals/cluster/index.js +1 -0
- package/.expo/metro/externals/console/index.js +1 -0
- package/.expo/metro/externals/constants/index.js +1 -0
- package/.expo/metro/externals/crypto/index.js +1 -0
- package/.expo/metro/externals/dgram/index.js +1 -0
- package/.expo/metro/externals/diagnostics_channel/index.js +1 -0
- package/.expo/metro/externals/dns/index.js +1 -0
- package/.expo/metro/externals/domain/index.js +1 -0
- package/.expo/metro/externals/events/index.js +1 -0
- package/.expo/metro/externals/fs/index.js +1 -0
- package/.expo/metro/externals/fs/promises/index.js +1 -0
- package/.expo/metro/externals/http/index.js +1 -0
- package/.expo/metro/externals/http2/index.js +1 -0
- package/.expo/metro/externals/https/index.js +1 -0
- package/.expo/metro/externals/inspector/index.js +1 -0
- package/.expo/metro/externals/module/index.js +1 -0
- package/.expo/metro/externals/net/index.js +1 -0
- package/.expo/metro/externals/os/index.js +1 -0
- package/.expo/metro/externals/path/index.js +1 -0
- package/.expo/metro/externals/perf_hooks/index.js +1 -0
- package/.expo/metro/externals/process/index.js +1 -0
- package/.expo/metro/externals/punycode/index.js +1 -0
- package/.expo/metro/externals/querystring/index.js +1 -0
- package/.expo/metro/externals/readline/index.js +1 -0
- package/.expo/metro/externals/repl/index.js +1 -0
- package/.expo/metro/externals/stream/index.js +1 -0
- package/.expo/metro/externals/string_decoder/index.js +1 -0
- package/.expo/metro/externals/timers/index.js +1 -0
- package/.expo/metro/externals/tls/index.js +1 -0
- package/.expo/metro/externals/trace_events/index.js +1 -0
- package/.expo/metro/externals/tty/index.js +1 -0
- package/.expo/metro/externals/url/index.js +1 -0
- package/.expo/metro/externals/util/index.js +1 -0
- package/.expo/metro/externals/v8/index.js +1 -0
- package/.expo/metro/externals/vm/index.js +1 -0
- package/.expo/metro/externals/wasi/index.js +1 -0
- package/.expo/metro/externals/worker_threads/index.js +1 -0
- package/.expo/metro/externals/zlib/index.js +1 -0
- package/.expo/metro/polyfill.js +1 -0
- package/.expo/metro/polyfill.native.js +1 -0
- package/.expo/metro/shims/react-native-web/dist/cjs/exports/AppRegistry/AppContainer.js +13 -0
- package/.expo/metro/shims/react-native-web/dist/cjs/exports/BackHandler/index.js +10 -0
- package/.expo/metro/shims/react-native-web/dist/exports/AppRegistry/AppContainer.js +12 -0
- package/.expo/metro/shims/react-native-web/dist/exports/BackHandler/index.js +7 -0
- package/.expo/settings.json +8 -0
- package/.github/actions/setup/action.yml +27 -0
- package/.node-version +1 -0
- package/README.md +148 -0
- package/app.json +13 -0
- package/dist/main.es.js +261 -0
- package/dist/main.es.js.map +1 -0
- package/dist/main.umd.js +2 -0
- package/dist/main.umd.js.map +1 -0
- package/dist/src/lib/constants.d.ts +3 -0
- package/dist/src/lib/constants.d.ts.map +1 -0
- package/dist/src/lib/core.d.ts +6 -0
- package/dist/src/lib/core.d.ts.map +1 -0
- package/dist/src/lib/utils.d.ts +4 -0
- package/dist/src/lib/utils.d.ts.map +1 -0
- package/dist/src/main.d.ts +3 -0
- package/dist/src/main.d.ts.map +1 -0
- package/dist/src/types.d.ts +20 -0
- package/dist/src/types.d.ts.map +1 -0
- package/dist/vite.config.d.ts +3 -0
- package/dist/vite.config.d.ts.map +1 -0
- package/package.json +64 -0
- package/scripts/bump.sh +26 -0
- package/src/lib/constants.ts +2 -0
- package/src/lib/core.tsx +45 -0
- package/src/lib/utils.ts +22 -0
- package/src/main.ts +6 -0
- package/src/types.ts +19 -0
- package/tsconfig.build.json +4 -0
- package/tsconfig.json +34 -0
- package/tsconfig.node.json +8 -0
- package/vite.config.ts +27 -0
package/.eslintignore
ADDED
package/.eslintrc.js
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
module.exports = {
|
|
2
|
+
root: true,
|
|
3
|
+
parser: '@typescript-eslint/parser',
|
|
4
|
+
env: {
|
|
5
|
+
browser: true,
|
|
6
|
+
es2021: true,
|
|
7
|
+
node: true,
|
|
8
|
+
},
|
|
9
|
+
extends: [
|
|
10
|
+
'airbnb-base',
|
|
11
|
+
'eslint:recommended',
|
|
12
|
+
'plugin:react/recommended',
|
|
13
|
+
'plugin:@typescript-eslint/recommended',
|
|
14
|
+
],
|
|
15
|
+
plugins: ['import', '@typescript-eslint'],
|
|
16
|
+
parserOptions: {
|
|
17
|
+
ecmaVersion: 2021,
|
|
18
|
+
},
|
|
19
|
+
settings: {
|
|
20
|
+
'import/resolver': {
|
|
21
|
+
node: {
|
|
22
|
+
paths: ['src'],
|
|
23
|
+
},
|
|
24
|
+
typescript: {
|
|
25
|
+
project: './',
|
|
26
|
+
},
|
|
27
|
+
},
|
|
28
|
+
react: {
|
|
29
|
+
version: 'detect',
|
|
30
|
+
},
|
|
31
|
+
},
|
|
32
|
+
rules: {
|
|
33
|
+
'import/no-extraneous-dependencies': ['error', { devDependencies: true }],
|
|
34
|
+
'import/prefer-default-export': 'off',
|
|
35
|
+
'import/extensions': [
|
|
36
|
+
'error',
|
|
37
|
+
'ignorePackages',
|
|
38
|
+
{
|
|
39
|
+
js: 'never',
|
|
40
|
+
jsx: 'never',
|
|
41
|
+
ts: 'never',
|
|
42
|
+
tsx: 'never',
|
|
43
|
+
},
|
|
44
|
+
],
|
|
45
|
+
},
|
|
46
|
+
};
|
package/.expo/README.md
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
> Why do I have a folder named ".expo" in my project?
|
|
2
|
+
|
|
3
|
+
The ".expo" folder is created when an Expo project is started using "expo start" command.
|
|
4
|
+
|
|
5
|
+
> What do the files contain?
|
|
6
|
+
|
|
7
|
+
- "devices.json": contains information about devices that have recently opened this project. This is used to populate the "Development sessions" list in your development builds.
|
|
8
|
+
- "packager-info.json": contains port numbers and process PIDs that are used to serve the application to the mobile device/simulator.
|
|
9
|
+
- "settings.json": contains the server configuration that is used to serve the application manifest.
|
|
10
|
+
|
|
11
|
+
> Should I commit the ".expo" folder?
|
|
12
|
+
|
|
13
|
+
No, you should not share the ".expo" folder. It does not contain any information that is relevant for other developers working on the project, it is specific to your machine.
|
|
14
|
+
|
|
15
|
+
Upon project creation, the ".expo" folder is already added to your ".gitignore" file.
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
module.exports = $$require_external('node:assert');
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
module.exports = $$require_external('node:async_hooks');
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
module.exports = $$require_external('node:buffer');
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
module.exports = $$require_external('node:child_process');
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
module.exports = $$require_external('node:cluster');
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
module.exports = $$require_external('node:console');
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
module.exports = $$require_external('node:constants');
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
module.exports = $$require_external('node:crypto');
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
module.exports = $$require_external('node:dgram');
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
module.exports = $$require_external('node:diagnostics_channel');
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
module.exports = $$require_external('node:dns');
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
module.exports = $$require_external('node:domain');
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
module.exports = $$require_external('node:events');
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
module.exports = $$require_external('node:fs');
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
module.exports = $$require_external('node:fs/promises');
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
module.exports = $$require_external('node:http');
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
module.exports = $$require_external('node:http2');
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
module.exports = $$require_external('node:https');
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
module.exports = $$require_external('node:inspector');
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
module.exports = $$require_external('node:module');
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
module.exports = $$require_external('node:net');
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
module.exports = $$require_external('node:os');
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
module.exports = $$require_external('node:path');
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
module.exports = $$require_external('node:perf_hooks');
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
module.exports = $$require_external('node:process');
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
module.exports = $$require_external('node:punycode');
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
module.exports = $$require_external('node:querystring');
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
module.exports = $$require_external('node:readline');
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
module.exports = $$require_external('node:repl');
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
module.exports = $$require_external('node:stream');
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
module.exports = $$require_external('node:string_decoder');
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
module.exports = $$require_external('node:timers');
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
module.exports = $$require_external('node:tls');
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
module.exports = $$require_external('node:trace_events');
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
module.exports = $$require_external('node:tty');
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
module.exports = $$require_external('node:url');
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
module.exports = $$require_external('node:util');
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
module.exports = $$require_external('node:v8');
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
module.exports = $$require_external('node:vm');
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
module.exports = $$require_external('node:wasi');
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
module.exports = $$require_external('node:worker_threads');
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
module.exports = $$require_external('node:zlib');
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
global.$$require_external = typeof window === "undefined" ? require : () => null;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
global.$$require_external = (moduleId) => {throw new Error(`Node.js standard library module ${moduleId} is not available in this JavaScript environment`);}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
// NOTE(EvanBacon): `react-native-web` adds a extra `div`s around the root HTML, these
|
|
2
|
+
// make static rendering much harder as we expect the root element to be `<html>`.
|
|
3
|
+
// This resolution will alias to a simple in-out component to avoid the extra HTML.
|
|
4
|
+
function AppContainer({ children }) {
|
|
5
|
+
return children;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
if (process.env.NODE_ENV !== 'production') {
|
|
9
|
+
AppContainer.displayName = 'AppContainer';
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
module.exports = AppContainer;
|
|
13
|
+
module.exports.default = AppContainer;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
function emptyFunction() {}
|
|
3
|
+
(exports.__esModule = !0), (exports.default = void 0);
|
|
4
|
+
var BackHandler = {
|
|
5
|
+
exitApp: emptyFunction,
|
|
6
|
+
addEventListener: () => ({ remove: emptyFunction }),
|
|
7
|
+
removeEventListener: emptyFunction,
|
|
8
|
+
},
|
|
9
|
+
_default = BackHandler;
|
|
10
|
+
(exports.default = _default), (module.exports = exports.default);
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
// NOTE(EvanBacon): `react-native-web` adds a extra `div`s around the root HTML, these
|
|
2
|
+
// make static rendering much harder as we expect the root element to be `<html>`.
|
|
3
|
+
// This resolution will alias to a simple in-out component to avoid the extra HTML.
|
|
4
|
+
function AppContainer({ children }) {
|
|
5
|
+
return children;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
if (process.env.NODE_ENV !== 'production') {
|
|
9
|
+
AppContainer.displayName = 'AppContainer';
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export default AppContainer;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
name: Setup
|
|
2
|
+
description: Setup Node.js and install dependencies
|
|
3
|
+
|
|
4
|
+
runs:
|
|
5
|
+
using: composite
|
|
6
|
+
steps:
|
|
7
|
+
- name: Setup Node.js
|
|
8
|
+
uses: actions/setup-node@v3
|
|
9
|
+
with:
|
|
10
|
+
node-version-file: .node-version
|
|
11
|
+
|
|
12
|
+
- name: Cache dependencies
|
|
13
|
+
id: npm-cache
|
|
14
|
+
uses: actions/cache@v3
|
|
15
|
+
with:
|
|
16
|
+
path: |
|
|
17
|
+
**/node_modules
|
|
18
|
+
.npm/install-state.gz
|
|
19
|
+
key: ${{ runner.os }}-npm-${{ hashFiles('package-lock.json') }}-${{ hashFiles('**/package.json', '!node_modules/**') }}
|
|
20
|
+
restore-keys: |
|
|
21
|
+
${{ runner.os }}-npm-${{ hashFiles('npm.lock') }}
|
|
22
|
+
${{ runner.os }}-npm-
|
|
23
|
+
|
|
24
|
+
- name: Install dependencies
|
|
25
|
+
if: steps.npm-cache.outputs.cache-hit != 'true'
|
|
26
|
+
run: npm install --immutable
|
|
27
|
+
shell: bash
|
package/.node-version
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
20
|
package/README.md
ADDED
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
<h1 align="center">Soyio React Native</h1>
|
|
2
|
+
|
|
3
|
+
<p align="center">
|
|
4
|
+
<em>
|
|
5
|
+
Use the Soyio widget within your React Native application as a View.
|
|
6
|
+
</em>
|
|
7
|
+
</p>
|
|
8
|
+
|
|
9
|
+
<p align="center">
|
|
10
|
+
<a href="https://www.npmjs.com/package/@soyio/soyio-webview-rn" target="_blank">
|
|
11
|
+
<img src="https://img.shields.io/npm/v/@soyio/soyio-webview-rn?label=version&logo=nodedotjs&logoColor=%23fff&color=306998" alt="NPM - Version">
|
|
12
|
+
</a>
|
|
13
|
+
</p>
|
|
14
|
+
|
|
15
|
+
## Installation
|
|
16
|
+
|
|
17
|
+
Install using npm! (or your favourite package manager)
|
|
18
|
+
|
|
19
|
+
```sh
|
|
20
|
+
# Using npm
|
|
21
|
+
npm install @soyio/soyio-webview-rn
|
|
22
|
+
|
|
23
|
+
# Using yarn
|
|
24
|
+
yarn add @soyio/soyio-webview-rn
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
## Usage
|
|
28
|
+
|
|
29
|
+
`Soyio React Native` exports a single hook called `useSoyioAuth`. This is a hook that opens a `WebBrowser` using the `openAuthSessionAsync` method by [expo](https://docs.expo.dev/versions/latest/sdk/webbrowser/#webbrowseropenauthsessionasyncurl-redirecturl-options).
|
|
30
|
+
|
|
31
|
+
To use the Soyio hook, use the following _snippet_:
|
|
32
|
+
|
|
33
|
+
```js
|
|
34
|
+
import { useSoyioAuth } from "@soyio/soyio-webview-rn";
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
After retrieving the `useSoyioAuth` hook, you are ready to instantiate the widget:
|
|
38
|
+
|
|
39
|
+
```jsx
|
|
40
|
+
export default function App() {
|
|
41
|
+
const options = {
|
|
42
|
+
userReference: "<company identifier of user>", // OPTIONAL
|
|
43
|
+
companyId: "<company id>", // Starts with 'com_'
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
// For registering a new identity
|
|
47
|
+
const registerParams = {
|
|
48
|
+
flowTemplateId: "<flow template id>", // Starts with 'vft_'
|
|
49
|
+
userEmail: "<user email>", // OPTIONAL
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
// For authenticate existing identity
|
|
53
|
+
const authenticateParams = {
|
|
54
|
+
identityId: "<identity id>", // Starts with 'id_'
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
const onEventChange = (event) => {
|
|
58
|
+
console.log('Event:', event);
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
const { register, authenticate } = useSoyioAuth({ options, onEventChange });
|
|
62
|
+
|
|
63
|
+
const registerNewIdentity = () => {
|
|
64
|
+
register(registerParams);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
const authenticateIdentity = () => {
|
|
68
|
+
authenticate(authenticateParams);
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
return (
|
|
72
|
+
<View>
|
|
73
|
+
<Button title="Register new user" onPress={registerNewIdentity} />
|
|
74
|
+
<Button title="Authenticate identity" onPress={authenticateIdentity} />
|
|
75
|
+
</View>
|
|
76
|
+
);
|
|
77
|
+
}
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
In this implementation, the `WebBrowser` will not open until either `register()` or `authenticate()` is invoked.
|
|
81
|
+
|
|
82
|
+
The `onEventChange` function returns an object with the following properties:
|
|
83
|
+
|
|
84
|
+
- `type`: Indicates the type of event being triggered. Possible values are:
|
|
85
|
+
|
|
86
|
+
- `"open register"`: Triggered when the user initiates the `register` method.
|
|
87
|
+
- `"open authenticate"`: Triggered when the user initiates the `authenticate` method.
|
|
88
|
+
- `"close"`: Triggered when the user closes the `WebBrowser`.
|
|
89
|
+
- `"success"`: Triggered when the authentication flow is successfully completed.
|
|
90
|
+
|
|
91
|
+
- `url` (optional): URL associated only with the `success` event.
|
|
92
|
+
|
|
93
|
+
- For registration: `"demo://registered?userReference=<company user reference>&id=<identity_id>"`
|
|
94
|
+
- For authentication: `"demo://authenticated?userReference=<company user reference>&id=<identity_id>"`
|
|
95
|
+
|
|
96
|
+
where `<identity_id>` is the unique identifier of the newly registered or authenticated user, respectively.
|
|
97
|
+
|
|
98
|
+
The `onEventChange` function should be defined as follows:
|
|
99
|
+
|
|
100
|
+
```typescript
|
|
101
|
+
onEventChange?: (event: { type: string; url?: string }) => void;
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
## TypeScript support
|
|
105
|
+
|
|
106
|
+
This package includes TypeScript declarations for the Soyio View.
|
|
107
|
+
|
|
108
|
+
## Developing
|
|
109
|
+
|
|
110
|
+
To develop the package, you need to use `npm`. Install the dependencies:
|
|
111
|
+
|
|
112
|
+
```sh
|
|
113
|
+
npm install
|
|
114
|
+
```
|
|
115
|
+
|
|
116
|
+
To test locally, I recommend packaging the app. Remember to build the library first:
|
|
117
|
+
|
|
118
|
+
```sh
|
|
119
|
+
npm run build
|
|
120
|
+
npm pack
|
|
121
|
+
```
|
|
122
|
+
|
|
123
|
+
This will create a `soyio-soyio-webview-rn-x.x.x.tgz` file (with the corresponding package version). Now, go to another directory and create a React Native app (using Expo, perhaps). After createing the new application, add the following dependency to its `package.json` file:
|
|
124
|
+
|
|
125
|
+
```json
|
|
126
|
+
{
|
|
127
|
+
"dependencies": {
|
|
128
|
+
...,
|
|
129
|
+
"@soyio/soyio-webview-rn": "file:./path/to/soyio-soyio-webview-rn-x.x.x.tgz",
|
|
130
|
+
...
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
```
|
|
134
|
+
|
|
135
|
+
Where `./path/to/soyio-soyio-webview-rn-x.x.x.tgz` corresponds to the path to the `.tgz` file created on the `npm pack` step. After running `npm install` on the new React Native app, you should be able to use Soyio React Native to import the Soyio View.
|
|
136
|
+
|
|
137
|
+
If you want to create a new _release_, you can run:
|
|
138
|
+
|
|
139
|
+
```sh
|
|
140
|
+
git switch main
|
|
141
|
+
npm run bump! <major|minor|patch>
|
|
142
|
+
```
|
|
143
|
+
|
|
144
|
+
This will create a new branch with the updated version from `main`.
|
|
145
|
+
|
|
146
|
+
## Acknowledgements
|
|
147
|
+
|
|
148
|
+
This implementation was written based on the input and experience of [**fintoc**](https://github.com/fintoc-com/fintoc-react-native) integrating the WebView using React Native, which served as a good starting point for the general idea of this library.
|