idmission-web-sdk 0.0.35 → 0.0.37
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 +30 -0
- package/dist/sdk2.cjs.development.js +19 -12
- package/dist/sdk2.cjs.development.js.map +1 -1
- package/dist/sdk2.cjs.production.js +1 -1
- package/dist/sdk2.cjs.production.js.map +1 -1
- package/dist/sdk2.esm.js +19 -12
- package/dist/sdk2.esm.js.map +1 -1
- package/dist/sdk2.umd.development.js +19 -12
- package/dist/sdk2.umd.development.js.map +1 -1
- package/dist/sdk2.umd.production.js +1 -1
- package/dist/sdk2.umd.production.js.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -452,3 +452,33 @@ Render a fullscreen capture component that analyzes frames from the user's front
|
|
|
452
452
|
```js
|
|
453
453
|
IDmissionSDK.renderCustomerIdentification('#target-element', { submissionToken: 'my-idmission-token' });
|
|
454
454
|
```
|
|
455
|
+
|
|
456
|
+
## Other Functionality
|
|
457
|
+
|
|
458
|
+
### Intercepting (and modifying) API calls to IDmission's backend with `onBeforeSubmit`
|
|
459
|
+
|
|
460
|
+
Each customer flow documented above includes an optional `onBeforeSubmit` prop, which bears the type signature `(request: SubmissionRequest) => Promise<SubmissionRequest>`. This can be useful if you would like to include some custom functionality that interrupts the WebSDK's outgoing request to IDmission's servers, allowing you a chance to modify the request before it is dispatched.
|
|
461
|
+
|
|
462
|
+
To delay the submission until some async condition has been met by your application:
|
|
463
|
+
|
|
464
|
+
```js
|
|
465
|
+
onBeforeSubmit: () => new Promise((resolve) => {
|
|
466
|
+
// do whatever you want in here, websdk will delay submission until you call:
|
|
467
|
+
resolve()
|
|
468
|
+
})
|
|
469
|
+
```
|
|
470
|
+
|
|
471
|
+
Calling `resolve()` without an argument as shown above will result in no modification being made to the request that will be sent to IDmission's servers.
|
|
472
|
+
|
|
473
|
+
To alter the submission request before it goes out:
|
|
474
|
+
|
|
475
|
+
```js
|
|
476
|
+
onBeforeSubmit: (req) => new Promise((resolve) => {
|
|
477
|
+
req.myRandomExtraThing = '123'
|
|
478
|
+
resolve(req)
|
|
479
|
+
})
|
|
480
|
+
```
|
|
481
|
+
|
|
482
|
+
Note that you will receive the request as a parameter to `onBeforeSubmit`, and must `resolve` with the altered version in order for your changes to be committed.
|
|
483
|
+
|
|
484
|
+
If the promise is rejected or an error is thrown, that rejection value or error will be printed to the logs and the request will be sent without any modifications committed.
|
|
@@ -395,7 +395,7 @@ var SubmissionProvider = function SubmissionProvider(_a) {
|
|
|
395
395
|
}, []);
|
|
396
396
|
var submit = React.useCallback(function () {
|
|
397
397
|
return tslib.__awaiter(void 0, void 0, void 0, function () {
|
|
398
|
-
var submissionResponse_1, submissionRequest_1, metadata, platform, onBeforeSubmitResult, host, endpoint, response, submissionResponse_2,
|
|
398
|
+
var submissionResponse_1, submissionRequest_1, metadata, platform, onBeforeSubmitResult, e_1, host, endpoint, response, submissionResponse_2, e_2;
|
|
399
399
|
var _a;
|
|
400
400
|
return tslib.__generator(this, function (_b) {
|
|
401
401
|
switch (_b.label) {
|
|
@@ -414,7 +414,7 @@ var SubmissionProvider = function SubmissionProvider(_a) {
|
|
|
414
414
|
setSubmissionStatus(SubmissionStatus.SUBMITTING);
|
|
415
415
|
_b.label = 1;
|
|
416
416
|
case 1:
|
|
417
|
-
_b.trys.push([1,
|
|
417
|
+
_b.trys.push([1, 8,, 9]);
|
|
418
418
|
submissionRequest_1 = {
|
|
419
419
|
securityData: {
|
|
420
420
|
userName: '',
|
|
@@ -515,13 +515,20 @@ var SubmissionProvider = function SubmissionProvider(_a) {
|
|
|
515
515
|
metadata.GeoLocation = JSON.stringify(geolocationResult);
|
|
516
516
|
}
|
|
517
517
|
submissionRequest_1.additionalData.metadata = JSON.stringify(metadata);
|
|
518
|
-
if (!onBeforeSubmit) return [3,
|
|
519
|
-
|
|
518
|
+
if (!onBeforeSubmit) return [3, 5];
|
|
519
|
+
_b.label = 2;
|
|
520
520
|
case 2:
|
|
521
|
+
_b.trys.push([2, 4,, 5]);
|
|
522
|
+
return [4, onBeforeSubmit(submissionRequest_1)];
|
|
523
|
+
case 3:
|
|
521
524
|
onBeforeSubmitResult = _b.sent();
|
|
522
525
|
if (onBeforeSubmitResult) submissionRequest_1 = onBeforeSubmitResult;
|
|
523
|
-
|
|
524
|
-
case
|
|
526
|
+
return [3, 5];
|
|
527
|
+
case 4:
|
|
528
|
+
e_1 = _b.sent();
|
|
529
|
+
console.error('onBeforeSubmit was rejected with', e_1);
|
|
530
|
+
return [3, 5];
|
|
531
|
+
case 5:
|
|
525
532
|
host = url || determineSubmissionHost(environment, token);
|
|
526
533
|
endpoint = determineSubmissionEndpoint(action, !!(idFrontImage || idBackImage || passportImage), !!selfieImage, !!token);
|
|
527
534
|
return [4, fetch(host + endpoint, {
|
|
@@ -529,22 +536,22 @@ var SubmissionProvider = function SubmissionProvider(_a) {
|
|
|
529
536
|
headers: apiHeaders(token),
|
|
530
537
|
body: JSON.stringify(submissionRequest_1)
|
|
531
538
|
})];
|
|
532
|
-
case
|
|
539
|
+
case 6:
|
|
533
540
|
response = _b.sent();
|
|
534
541
|
return [4, response.json()];
|
|
535
|
-
case
|
|
542
|
+
case 7:
|
|
536
543
|
submissionResponse_2 = _b.sent();
|
|
537
544
|
setSubmissionRequest(submissionRequest_1);
|
|
538
545
|
setSubmissionResponse(submissionResponse_2);
|
|
539
546
|
setSubmissionStatus(SubmissionStatus.SUBMITTED);
|
|
540
547
|
onResponseReceived === null || onResponseReceived === void 0 ? void 0 : onResponseReceived(submissionResponse_2);
|
|
541
548
|
return [2, submissionResponse_2];
|
|
542
|
-
case
|
|
543
|
-
|
|
549
|
+
case 8:
|
|
550
|
+
e_2 = _b.sent();
|
|
544
551
|
setSubmissionStatus(SubmissionStatus.FAILED);
|
|
545
|
-
onRequestFailure === null || onRequestFailure === void 0 ? void 0 : onRequestFailure(
|
|
552
|
+
onRequestFailure === null || onRequestFailure === void 0 ? void 0 : onRequestFailure(e_2);
|
|
546
553
|
return [2, null];
|
|
547
|
-
case
|
|
554
|
+
case 9:
|
|
548
555
|
return [2];
|
|
549
556
|
}
|
|
550
557
|
});
|