@soyio/soyio-rn-sdk 1.0.2 → 1.0.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.
package/README.md CHANGED
@@ -61,7 +61,7 @@ export default function App() {
61
61
 
62
62
  // For registering a new identity
63
63
  const registerParams = {
64
- flowTemplateId: "<flow template id>", // Starts with 'vft_'
64
+ flowTemplateId: "<flow template id>", // Starts with 'vt_'
65
65
  userEmail: "<user email>", // Optional
66
66
  forceError: '<error type>', // Optional
67
67
  };
@@ -104,6 +104,7 @@ The `onEventChange` function returns an object with the following properties:
104
104
  - `"open authenticate"`: Triggered when the user initiates the `authenticate` method.
105
105
  - `"dismiss"`: Triggered when the user closes the `WebBrowser`.
106
106
  - `"success"`: Triggered when the authentication flow is successfully completed.
107
+ - `"error"`: Triggered when there was an error on the flow.
107
108
 
108
109
  - `url` (optional): URL associated only with the `success` event.
109
110
 
@@ -112,13 +113,17 @@ The `onEventChange` function returns an object with the following properties:
112
113
 
113
114
  where `<identity_id>` is the unique identifier of the newly registered or authenticated user, respectively.
114
115
 
116
+ - `message` (optional): Additional information associated with the event type received.
117
+ - Possible messages when event type is `error`:
118
+ - `"DENIED_CAMERA_PERMISSION"`: User denies access to its camera.
119
+
115
120
  #### Attribute Descriptions
116
121
 
117
122
  - **`companyId`**: The unique identifier for the company, must start with `'com_'`.
118
123
  - **`userReference`**: (Optional) A reference identifier provided by the company for the user engaging with the widget. This identifier is used in events (`onEvent` and `webhooks`) to inform the company which user the events are associated with.
119
124
  - **`userEmail`**: The user's email address. This field is optional when the flow is `'register'`, where if not provided, Soyio will prompt the user to enter their email. However, for the `'authenticate'` flow, this field should not be provided.
120
125
  - **`forceError`**: (Optional) Triggers specific errors for testing or debugging. Used to simulate failure scenarios.
121
- - **`flowTemplateId`**: Required only in the `'register'` flow, this identifier specifies the order and quantity of documents requested from the user. It must start with `'vft_'`.
126
+ - **`flowTemplateId`**: Required only in the `'register'` flow, this identifier specifies the order and quantity of documents requested from the user. It must start with `'vt_'`.
122
127
  - **`identityId`**: Necessary only in the `'authenticate'` flow, this identifier must start with `'id_'` and signifies the user's identity.
123
128
  - **`customColor`**: (Optional) A hex code string that specifies the base color of the interface during either the authentication or registration flow.
124
129
  - **`isSandbox`**: (Optional) Indicates if the widget should operate in sandbox mode, defaulting to `false`.
@@ -66,22 +66,28 @@ var utils_1 = require("./utils");
66
66
  var useSoyioAuth = function (_a) {
67
67
  var options = _a.options, onEventChange = _a.onEventChange;
68
68
  var register = (0, react_1.useCallback)(function (registerParams) { return __awaiter(void 0, void 0, void 0, function () {
69
- var registerBaseUri, registerUri, redirectUrl, webBrowserOptions, registerResult;
70
- return __generator(this, function (_a) {
71
- switch (_a.label) {
69
+ var registerBaseUri, registerUri, redirectUrl, webBrowserOptions, registerResult, errorMessage;
70
+ var _a;
71
+ return __generator(this, function (_b) {
72
+ switch (_b.label) {
72
73
  case 0:
73
74
  registerBaseUri = (0, utils_1.getFlowUrl)(options, 'register');
74
75
  registerUri = "".concat(registerBaseUri, "?").concat((0, utils_1.buildUrlParams)(options, registerParams));
75
76
  redirectUrl = (0, utils_1.getRedirectUrl)(options.uriScheme);
76
77
  return [4 /*yield*/, (0, utils_1.getBrowserOptions)()];
77
78
  case 1:
78
- webBrowserOptions = _a.sent();
79
+ webBrowserOptions = _b.sent();
79
80
  if (onEventChange)
80
81
  onEventChange({ type: 'open register' });
81
82
  return [4 /*yield*/, WebBrowser.openAuthSessionAsync(registerUri, redirectUrl, webBrowserOptions)];
82
83
  case 2:
83
- registerResult = _a.sent();
84
- if (onEventChange)
84
+ registerResult = _b.sent();
85
+ if ((registerResult.type === 'success') && ((_a = registerResult.url) === null || _a === void 0 ? void 0 : _a.includes('error'))) {
86
+ errorMessage = registerResult.url.match(utils_1.ERROR_URL_REGEX)[1];
87
+ if (onEventChange)
88
+ onEventChange({ type: 'error', message: errorMessage });
89
+ }
90
+ else if (onEventChange)
85
91
  onEventChange(registerResult);
86
92
  return [2 /*return*/];
87
93
  }
@@ -20,5 +20,6 @@ export type SoyioWidgetViewPropsType = {
20
20
  onEventChange?: (event: {
21
21
  type: string;
22
22
  url?: string;
23
+ message?: string;
23
24
  }) => void;
24
25
  };
@@ -4,3 +4,4 @@ export declare function getFlowUrl(options: SoyioWidgetParams, flow: 'authentica
4
4
  export declare function buildUrlParams(widgetParams: SoyioWidgetParams, flowParams: RegisterParams | AuthenticateParams): string;
5
5
  export declare function getBrowserOptions(): Promise<WebBrowser.AuthSessionOpenOptions>;
6
6
  export declare function getRedirectUrl(scheme: string): string;
7
+ export declare const ERROR_URL_REGEX: RegExp;
@@ -70,7 +70,7 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
70
70
  }
71
71
  };
72
72
  Object.defineProperty(exports, "__esModule", { value: true });
73
- exports.getRedirectUrl = exports.getBrowserOptions = exports.buildUrlParams = exports.getFlowUrl = void 0;
73
+ exports.ERROR_URL_REGEX = exports.getRedirectUrl = exports.getBrowserOptions = exports.buildUrlParams = exports.getFlowUrl = void 0;
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");
@@ -80,10 +80,9 @@ function getFlowUrl(options, flow) {
80
80
  }
81
81
  exports.getFlowUrl = getFlowUrl;
82
82
  function buildUrlParams(widgetParams, flowParams) {
83
- // eslint-disable-next-line no-nested-ternary
84
- var platformSuffix = react_native_1.Platform.OS === 'android' ? '-android' : react_native_1.Platform.OS === 'ios' ? '-ios' : '';
83
+ var sdkSuffix = (react_native_1.Platform.OS === 'android' || react_native_1.Platform.OS === 'ios') ? "-".concat(react_native_1.Platform.OS) : '';
85
84
  var baseParams = {
86
- platform: "rn".concat(platformSuffix),
85
+ sdk: "rn".concat(sdkSuffix),
87
86
  uriScheme: widgetParams.uriScheme,
88
87
  companyId: widgetParams.companyId,
89
88
  userReference: widgetParams.userReference,
@@ -131,4 +130,5 @@ function getRedirectUrl(scheme) {
131
130
  return "".concat(scheme, "://");
132
131
  }
133
132
  exports.getRedirectUrl = getRedirectUrl;
133
+ exports.ERROR_URL_REGEX = /[?&]error=([^&]+)/;
134
134
  //# sourceMappingURL=utils.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@soyio/soyio-rn-sdk",
3
- "version": "1.0.2",
3
+ "version": "1.0.4",
4
4
  "license": "MIT",
5
5
  "author": "Ignacio Méndez",
6
6
  "main": "./package/index.js",