@soyio/soyio-rn-sdk 2.0.1 → 2.2.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/README.md +65 -20
- package/package/src/core.d.ts +2 -1
- package/package/src/core.jsx +27 -12
- package/package/src/types.d.ts +18 -10
- package/package/src/utils.d.ts +9 -4
- package/package/src/utils.js +10 -3
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -50,7 +50,11 @@ This verification can happen in one of the following two ways:
|
|
|
50
50
|
|
|
51
51
|
2. **Authentication**: Through an access key (passkey) or facial video. This can occur when a user has already been validated previously with Soyio.
|
|
52
52
|
|
|
53
|
-
To instantiate this process in the code,
|
|
53
|
+
To instantiate this process in the code, you have two options:
|
|
54
|
+
|
|
55
|
+
#### 1.a Disclosure request on-the-fly:
|
|
56
|
+
|
|
57
|
+
This doesn't require any previous setup. Given your company and disclosure template IDs, you can create disclosure requests freely when the user starts the widget:
|
|
54
58
|
|
|
55
59
|
```jsx
|
|
56
60
|
import { useSoyioAuth } from "@soyio/soyio-rn-sdk";
|
|
@@ -89,41 +93,82 @@ export default function App() {
|
|
|
89
93
|
}
|
|
90
94
|
```
|
|
91
95
|
|
|
92
|
-
|
|
96
|
+
#### 1.b Created disclosure request:
|
|
97
|
+
|
|
98
|
+
You can alternatively create a disclosure request beforehand with some **matchers** to make sure the person completing the request matches the one that your application thinks it is.
|
|
93
99
|
|
|
94
|
-
|
|
100
|
+
For more details about the use case, please refer to [the documentation](https://docs.soyio.id/).
|
|
101
|
+
|
|
102
|
+
To use this option, simply specify the disclosure request ID along with any optional parameters:
|
|
95
103
|
|
|
96
104
|
```jsx
|
|
97
105
|
import { useSoyioAuth } from "@soyio/soyio-rn-sdk";
|
|
98
106
|
|
|
99
107
|
export default function App() {
|
|
100
108
|
const options = {
|
|
101
|
-
companyId: "<company id>", // Starts with 'com_'
|
|
102
109
|
uriScheme: "<company custom uri scheme>"
|
|
103
|
-
userReference: "<company identifier of user>", // Optional
|
|
104
110
|
customColor: "<custom color>", // Optional
|
|
105
|
-
isSandbox:
|
|
111
|
+
isSandbox: false, // Optional
|
|
112
|
+
};
|
|
113
|
+
|
|
114
|
+
// For initialize a disclosure request
|
|
115
|
+
const disclosureParams = {
|
|
116
|
+
disclosureRequestId: "<disclosure request id>", // Starts with 'dreq_'
|
|
117
|
+
userEmail: "<user email>", // Optional
|
|
118
|
+
forceError: '<error type>', // Optional
|
|
119
|
+
};
|
|
120
|
+
|
|
121
|
+
const onEventChange = (event) => {
|
|
122
|
+
console.log("Event:", event);
|
|
123
|
+
};
|
|
124
|
+
|
|
125
|
+
const { disclosure } = useSoyioAuth({ options, onEventChange });
|
|
126
|
+
|
|
127
|
+
const initDisclosureRequest = () => {
|
|
128
|
+
disclosure(disclosureParams);
|
|
129
|
+
};
|
|
130
|
+
|
|
131
|
+
return (
|
|
132
|
+
<View>
|
|
133
|
+
<Button title="Disclosure request" onPress={initDisclosureRequest} />
|
|
134
|
+
</View>
|
|
135
|
+
);
|
|
136
|
+
}
|
|
137
|
+
```
|
|
138
|
+
|
|
139
|
+
Note that user and template properties are not specified here because they must be specified when creating the disclosure request beforehand.
|
|
140
|
+
|
|
141
|
+
### 2. Auth Request
|
|
142
|
+
|
|
143
|
+
The **`auth_request`** is a process where, using a previously created `auth_request_id`, a request is initiated in which a user can authenticate with Soyio. This authentication can occur either through an access key or facial video.
|
|
144
|
+
|
|
145
|
+
```jsx
|
|
146
|
+
import { useSoyioAuth } from "@soyio/soyio-rn-sdk";
|
|
147
|
+
|
|
148
|
+
export default function App() {
|
|
149
|
+
const options = {
|
|
150
|
+
uriScheme: "<company custom uri scheme>"
|
|
151
|
+
customColor: "<custom color>", // Optional
|
|
152
|
+
isSandbox: false, // Optional
|
|
106
153
|
};
|
|
107
154
|
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
signatureTemplateId: "<signature template id>" // Starts with 'st_'
|
|
111
|
-
identityId: "<identity id>", // Starts with 'id_'
|
|
155
|
+
const authRequestParams = {
|
|
156
|
+
authRequestId: "<auth request id>" // Starts with 'authreq_'
|
|
112
157
|
}
|
|
113
158
|
|
|
114
159
|
const onEventChange = (event) => {
|
|
115
160
|
console.log("Event:", event);
|
|
116
161
|
};
|
|
117
162
|
|
|
118
|
-
const {
|
|
163
|
+
const { authentication } = useSoyioAuth({ options, onEventChange });
|
|
119
164
|
|
|
120
|
-
const
|
|
121
|
-
|
|
165
|
+
const initAuthRequest = () => {
|
|
166
|
+
authentication(authRequestParams);
|
|
122
167
|
};
|
|
123
168
|
|
|
124
169
|
return (
|
|
125
170
|
<View>
|
|
126
|
-
<Button title="
|
|
171
|
+
<Button title="Auth Request" onPress={initAuthRequest} />
|
|
127
172
|
</View>
|
|
128
173
|
);
|
|
129
174
|
}
|
|
@@ -131,12 +176,12 @@ export default function App() {
|
|
|
131
176
|
|
|
132
177
|
The `onEventChange` function can return the following objects:
|
|
133
178
|
|
|
134
|
-
1. When
|
|
179
|
+
1. When a request is successful:
|
|
135
180
|
|
|
136
181
|
```js
|
|
137
182
|
{
|
|
138
183
|
type: "success",
|
|
139
|
-
request: "disclosure",
|
|
184
|
+
request: "disclosure" | "authRequest",
|
|
140
185
|
verificationKind: "validation" | "authentication",
|
|
141
186
|
userReference: "<company-user-reference>",
|
|
142
187
|
identityId: "<soyio-identity-id-of-user>",
|
|
@@ -147,7 +192,7 @@ The `onEventChange` function can return the following objects:
|
|
|
147
192
|
|
|
148
193
|
```js
|
|
149
194
|
{
|
|
150
|
-
type: "
|
|
195
|
+
type: "open";
|
|
151
196
|
}
|
|
152
197
|
```
|
|
153
198
|
|
|
@@ -164,8 +209,8 @@ The `onEventChange` function can return the following objects:
|
|
|
164
209
|
```js
|
|
165
210
|
{
|
|
166
211
|
type: "error",
|
|
167
|
-
request: "disclosure",
|
|
168
|
-
error: "
|
|
212
|
+
request: "disclosure" | "authRequest",
|
|
213
|
+
error: "UNEXPECTED_ERROR"
|
|
169
214
|
}
|
|
170
215
|
```
|
|
171
216
|
|
|
@@ -179,7 +224,7 @@ The `onEventChange` function can return the following objects:
|
|
|
179
224
|
- **`customColor`**: (Optional) A hex code string that specifies the base color of the interface
|
|
180
225
|
- **`isSandbox`**: (Optional) Indicates if the widget should operate in sandbox mode, defaulting to `false`.
|
|
181
226
|
- **`uriScheme`**: The unique redirect scheme you've set with `npx uri-scheme add ...`, critical for redirect handling in your app.
|
|
182
|
-
- **`
|
|
227
|
+
- **`authRequestId`**: Identifier of auth request obtained when creating the `AuthRequest`. It must start with `'authreq_'`.
|
|
183
228
|
|
|
184
229
|
#### Error types
|
|
185
230
|
|
package/package/src/core.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import type { DisclosureParams, SoyioWidgetViewPropsType } from './types';
|
|
1
|
+
import type { AuthRequestParams, DisclosureParams, SoyioWidgetViewPropsType } from './types';
|
|
2
2
|
export declare const useSoyioAuth: ({ options, onEventChange }: SoyioWidgetViewPropsType) => {
|
|
3
3
|
disclosure: (registerParams: DisclosureParams) => Promise<void>;
|
|
4
|
+
authentication: (authRequestParams: AuthRequestParams) => Promise<void>;
|
|
4
5
|
};
|
package/package/src/core.jsx
CHANGED
|
@@ -76,29 +76,28 @@ var react_1 = require("react");
|
|
|
76
76
|
var utils_1 = require("./utils");
|
|
77
77
|
var useSoyioAuth = function (_a) {
|
|
78
78
|
var options = _a.options, onEventChange = _a.onEventChange;
|
|
79
|
-
var
|
|
80
|
-
var
|
|
79
|
+
var handleProcess = (0, react_1.useCallback)(function (baseUri, params) { return __awaiter(void 0, void 0, void 0, function () {
|
|
80
|
+
var uri, redirectUrl, webBrowserOptions, result, urlParams;
|
|
81
81
|
var _a;
|
|
82
82
|
return __generator(this, function (_b) {
|
|
83
83
|
switch (_b.label) {
|
|
84
84
|
case 0:
|
|
85
|
-
|
|
86
|
-
disclosureUri = "".concat(disclosureBaseUri, "?").concat((0, utils_1.buildUrlParams)(options, registerParams));
|
|
85
|
+
uri = "".concat(baseUri, "?").concat((0, utils_1.buildUrlParams)(options, params));
|
|
87
86
|
redirectUrl = (0, utils_1.getRedirectUrl)(options.uriScheme);
|
|
88
87
|
return [4 /*yield*/, (0, utils_1.getBrowserOptions)()];
|
|
89
88
|
case 1:
|
|
90
89
|
webBrowserOptions = _b.sent();
|
|
91
90
|
if (onEventChange)
|
|
92
|
-
onEventChange({ type: '
|
|
93
|
-
return [4 /*yield*/, WebBrowser.openAuthSessionAsync(
|
|
91
|
+
onEventChange({ type: 'open' });
|
|
92
|
+
return [4 /*yield*/, WebBrowser.openAuthSessionAsync(uri, redirectUrl, webBrowserOptions)];
|
|
94
93
|
case 2:
|
|
95
|
-
|
|
94
|
+
result = _b.sent();
|
|
96
95
|
if (onEventChange) {
|
|
97
96
|
// 'success' type means that a redirection was triggered by Soyio,
|
|
98
97
|
// but doesn't mean that the process was successful
|
|
99
|
-
if (
|
|
100
|
-
urlParams = (0, utils_1.parseUrlResponseParams)(
|
|
101
|
-
if ((_a =
|
|
98
|
+
if (result.type === 'success') {
|
|
99
|
+
urlParams = (0, utils_1.parseUrlResponseParams)(result.url);
|
|
100
|
+
if ((_a = result.url) === null || _a === void 0 ? void 0 : _a.includes('error')) {
|
|
102
101
|
onEventChange(__assign({ type: 'error' }, urlParams));
|
|
103
102
|
}
|
|
104
103
|
else {
|
|
@@ -106,14 +105,30 @@ var useSoyioAuth = function (_a) {
|
|
|
106
105
|
}
|
|
107
106
|
}
|
|
108
107
|
else {
|
|
109
|
-
onEventChange(
|
|
108
|
+
onEventChange(result);
|
|
110
109
|
}
|
|
111
110
|
}
|
|
112
111
|
return [2 /*return*/];
|
|
113
112
|
}
|
|
114
113
|
});
|
|
115
114
|
}); }, [options, onEventChange]);
|
|
116
|
-
|
|
115
|
+
var disclosure = (0, react_1.useCallback)(function (registerParams) { return __awaiter(void 0, void 0, void 0, function () {
|
|
116
|
+
var disclosureBaseUri;
|
|
117
|
+
return __generator(this, function (_a) {
|
|
118
|
+
disclosureBaseUri = (0, utils_1.getRequestUrl)(options, __assign({ request: 'disclosure' }, registerParams));
|
|
119
|
+
handleProcess(disclosureBaseUri, registerParams);
|
|
120
|
+
return [2 /*return*/];
|
|
121
|
+
});
|
|
122
|
+
}); }, [options, handleProcess]);
|
|
123
|
+
var authentication = (0, react_1.useCallback)(function (authRequestParams) { return __awaiter(void 0, void 0, void 0, function () {
|
|
124
|
+
var authBaseUri;
|
|
125
|
+
return __generator(this, function (_a) {
|
|
126
|
+
authBaseUri = (0, utils_1.getRequestUrl)(options, __assign({ request: 'authentication' }, authRequestParams));
|
|
127
|
+
handleProcess(authBaseUri, authRequestParams);
|
|
128
|
+
return [2 /*return*/];
|
|
129
|
+
});
|
|
130
|
+
}); }, [options, handleProcess]);
|
|
131
|
+
return { disclosure: disclosure, authentication: authentication };
|
|
117
132
|
};
|
|
118
133
|
exports.useSoyioAuth = useSoyioAuth;
|
|
119
134
|
//# sourceMappingURL=core.jsx.map
|
package/package/src/types.d.ts
CHANGED
|
@@ -1,21 +1,28 @@
|
|
|
1
1
|
export type SoyioErrors = 'user_exists' | 'facial_validation_error' | 'document_validation_error' | 'unknown_error';
|
|
2
|
+
type NewDisclosureParams = {
|
|
3
|
+
templateId: string;
|
|
4
|
+
disclosureRequestId?: never;
|
|
5
|
+
userEmail?: string;
|
|
6
|
+
forceError?: SoyioErrors;
|
|
7
|
+
};
|
|
8
|
+
type ExistingDisclosureParams = {
|
|
9
|
+
templateId?: never;
|
|
10
|
+
disclosureRequestId: string;
|
|
11
|
+
userEmail?: never;
|
|
12
|
+
forceError?: SoyioErrors;
|
|
13
|
+
};
|
|
14
|
+
export type AuthRequestParams = {
|
|
15
|
+
authRequestId: `authreq_${string}`;
|
|
16
|
+
};
|
|
2
17
|
export type SoyioWidgetParams = {
|
|
3
|
-
companyId
|
|
18
|
+
companyId?: string;
|
|
4
19
|
userReference?: string;
|
|
5
20
|
uriScheme: string;
|
|
6
21
|
isSandbox?: boolean;
|
|
7
22
|
customColor?: string;
|
|
8
23
|
developmentUrl?: string;
|
|
9
24
|
};
|
|
10
|
-
export type DisclosureParams =
|
|
11
|
-
templateId: string;
|
|
12
|
-
userEmail?: string;
|
|
13
|
-
forceError?: SoyioErrors;
|
|
14
|
-
};
|
|
15
|
-
export type SignatureParams = {
|
|
16
|
-
signatureTemplateId: string;
|
|
17
|
-
identityId: string;
|
|
18
|
-
};
|
|
25
|
+
export type DisclosureParams = NewDisclosureParams | ExistingDisclosureParams;
|
|
19
26
|
export type SoyioWidgetViewPropsType = {
|
|
20
27
|
options: SoyioWidgetParams;
|
|
21
28
|
onEventChange?: (event: {
|
|
@@ -24,3 +31,4 @@ export type SoyioWidgetViewPropsType = {
|
|
|
24
31
|
message?: string;
|
|
25
32
|
}) => void;
|
|
26
33
|
};
|
|
34
|
+
export {};
|
package/package/src/utils.d.ts
CHANGED
|
@@ -1,11 +1,16 @@
|
|
|
1
1
|
import * as WebBrowser from 'expo-web-browser';
|
|
2
|
-
import { DisclosureParams, SoyioWidgetParams } from './types';
|
|
3
|
-
|
|
4
|
-
|
|
2
|
+
import { AuthRequestParams, DisclosureParams, SoyioWidgetParams } from './types';
|
|
3
|
+
type RequestUrlParams = {
|
|
4
|
+
request: 'disclosure';
|
|
5
|
+
} & DisclosureParams | {
|
|
6
|
+
request: 'authentication';
|
|
7
|
+
} & AuthRequestParams;
|
|
8
|
+
export declare function getRequestUrl(options: SoyioWidgetParams, params: RequestUrlParams): string;
|
|
9
|
+
export declare function buildUrlParams(widgetParams: SoyioWidgetParams, requestParams: DisclosureParams | AuthRequestParams): string;
|
|
5
10
|
export declare function getBrowserOptions(): Promise<WebBrowser.AuthSessionOpenOptions>;
|
|
6
11
|
export declare function getRedirectUrl(scheme: string): string;
|
|
7
12
|
type ParsedUrlParameters = {
|
|
8
|
-
request: '
|
|
13
|
+
request: 'disclosure' | 'authentication';
|
|
9
14
|
[key: string]: string;
|
|
10
15
|
};
|
|
11
16
|
export declare function parseUrlResponseParams(url: string): ParsedUrlParameters;
|
package/package/src/utils.js
CHANGED
|
@@ -74,9 +74,16 @@ exports.parseUrlResponseParams = exports.getRedirectUrl = exports.getBrowserOpti
|
|
|
74
74
|
var WebBrowser = __importStar(require("expo-web-browser"));
|
|
75
75
|
var react_native_1 = require("react-native");
|
|
76
76
|
var constants_1 = require("./constants");
|
|
77
|
-
function
|
|
77
|
+
function getPath(params) {
|
|
78
|
+
if (params.request === 'disclosure' && params.disclosureRequestId) {
|
|
79
|
+
return "disclosures/".concat(params.disclosureRequestId);
|
|
80
|
+
}
|
|
81
|
+
return params.request;
|
|
82
|
+
}
|
|
83
|
+
function getRequestUrl(options, params) {
|
|
78
84
|
var baseUrl = options.developmentUrl || (options.isSandbox ? constants_1.SANDBOX_URL : constants_1.PRODUCTION_URL);
|
|
79
|
-
|
|
85
|
+
var path = getPath(params);
|
|
86
|
+
return "".concat(baseUrl, "/").concat(path);
|
|
80
87
|
}
|
|
81
88
|
exports.getRequestUrl = getRequestUrl;
|
|
82
89
|
function buildUrlParams(widgetParams, requestParams) {
|
|
@@ -84,9 +91,9 @@ function buildUrlParams(widgetParams, requestParams) {
|
|
|
84
91
|
var baseParams = {
|
|
85
92
|
sdk: "rn".concat(sdkSuffix),
|
|
86
93
|
uriScheme: widgetParams.uriScheme,
|
|
94
|
+
customColor: widgetParams.customColor,
|
|
87
95
|
companyId: widgetParams.companyId,
|
|
88
96
|
userReference: widgetParams.userReference,
|
|
89
|
-
customColor: widgetParams.customColor,
|
|
90
97
|
};
|
|
91
98
|
var allParams = __assign(__assign({}, baseParams), requestParams);
|
|
92
99
|
var queryParams = Object.entries(allParams)
|