@soyio/soyio-rn-sdk 2.0.0 → 2.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/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, it should be done in the following manner:
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,6 +93,51 @@ export default function App() {
89
93
  }
90
94
  ```
91
95
 
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.
99
+
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:
103
+
104
+ ```jsx
105
+ import { useSoyioAuth } from "@soyio/soyio-rn-sdk";
106
+
107
+ export default function App() {
108
+ const options = {
109
+ uriScheme: "<company custom uri scheme>"
110
+ customColor: "<custom color>", // Optional
111
+ isSandbox: true, // 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
+
92
141
  ### 2. Signature attempt (coming soon...)
93
142
 
94
143
  The **`signature_attempt`** is a process where, using a previously created `signature_attempt_id`, a request is initiated in which a user can digitally sign a document. To sign the document, the user must be authenticated. This authentication can occur either through an access key or facial video. It's important to note that for this request, the user must have been previously verified with Soyio.
@@ -82,7 +82,7 @@ var useSoyioAuth = function (_a) {
82
82
  return __generator(this, function (_b) {
83
83
  switch (_b.label) {
84
84
  case 0:
85
- disclosureBaseUri = (0, utils_1.getRequestUrl)(options, 'disclosure');
85
+ disclosureBaseUri = (0, utils_1.getRequestUrl)(options, __assign({ request: 'disclosure' }, registerParams));
86
86
  disclosureUri = "".concat(disclosureBaseUri, "?").concat((0, utils_1.buildUrlParams)(options, registerParams));
87
87
  redirectUrl = (0, utils_1.getRedirectUrl)(options.uriScheme);
88
88
  return [4 /*yield*/, (0, utils_1.getBrowserOptions)()];
@@ -1,17 +1,25 @@
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
+ };
2
14
  export type SoyioWidgetParams = {
3
- companyId: string;
15
+ companyId?: string;
4
16
  userReference?: string;
5
17
  uriScheme: string;
6
18
  isSandbox?: boolean;
7
19
  customColor?: string;
8
20
  developmentUrl?: string;
9
21
  };
10
- export type DisclosureParams = {
11
- templateId: string;
12
- userEmail?: string;
13
- forceError?: SoyioErrors;
14
- };
22
+ export type DisclosureParams = NewDisclosureParams | ExistingDisclosureParams;
15
23
  export type SignatureParams = {
16
24
  signatureTemplateId: string;
17
25
  identityId: string;
@@ -24,3 +32,4 @@ export type SoyioWidgetViewPropsType = {
24
32
  message?: string;
25
33
  }) => void;
26
34
  };
35
+ export {};
@@ -1,6 +1,11 @@
1
1
  import * as WebBrowser from 'expo-web-browser';
2
- import { DisclosureParams, SoyioWidgetParams } from './types';
3
- export declare function getRequestUrl(options: SoyioWidgetParams, request: 'disclosure' | 'signature'): string;
2
+ import { DisclosureParams, SignatureParams, SoyioWidgetParams } from './types';
3
+ type RequestUrlParams = {
4
+ request: 'disclosure';
5
+ } & DisclosureParams | {
6
+ request: 'signature';
7
+ } & SignatureParams;
8
+ export declare function getRequestUrl(options: SoyioWidgetParams, params: RequestUrlParams): string;
4
9
  export declare function buildUrlParams(widgetParams: SoyioWidgetParams, requestParams: DisclosureParams): string;
5
10
  export declare function getBrowserOptions(): Promise<WebBrowser.AuthSessionOpenOptions>;
6
11
  export declare function getRedirectUrl(scheme: string): string;
@@ -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 getRequestUrl(options, request) {
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
- return "".concat(baseUrl, "/").concat(request);
85
+ var path = getPath(params);
86
+ return "".concat(baseUrl, "/").concat(path);
80
87
  }
81
88
  exports.getRequestUrl = getRequestUrl;
82
89
  function buildUrlParams(widgetParams, requestParams) {
@@ -131,15 +138,18 @@ function getRedirectUrl(scheme) {
131
138
  }
132
139
  exports.getRedirectUrl = getRedirectUrl;
133
140
  function parseUrlResponseParams(url) {
134
- var regex = /^(\w+):\/\/(\w+)\?(.+)$/;
141
+ var regex = /^([\w-]+):\/\/(\w+)\?(.+)$/;
135
142
  var match = url.match(regex);
136
143
  var requestType = match[2], queryString = match[3];
137
- var params = new URLSearchParams(queryString);
138
144
  var result = {
139
145
  request: requestType,
140
146
  };
141
- params.forEach(function (value, key) {
142
- result[key] = value;
147
+ queryString.split('&').forEach(function (pair) {
148
+ var _a = pair.split('=').map(decodeURIComponent), key = _a[0], rawValue = _a[1];
149
+ if (key) {
150
+ var value = rawValue === 'null' ? null : rawValue;
151
+ result[key] = value;
152
+ }
143
153
  });
144
154
  return result;
145
155
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@soyio/soyio-rn-sdk",
3
- "version": "2.0.0",
3
+ "version": "2.1.0",
4
4
  "license": "MIT",
5
5
  "author": "Ignacio Méndez",
6
6
  "main": "./package/index.js",