@smileid/web-components 1.0.0-beta

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.
Files changed (73) hide show
  1. package/.eslintrc.cjs +72 -0
  2. package/components/README.md +14 -0
  3. package/components/attribution/PoweredBySmileId.js +42 -0
  4. package/components/camera-permission/CameraPermission.js +136 -0
  5. package/components/camera-permission/CameraPermission.stories.js +21 -0
  6. package/components/combobox/src/Combobox.js +586 -0
  7. package/components/combobox/src/index.js +1 -0
  8. package/components/document/src/DocumentCaptureScreens.js +317 -0
  9. package/components/document/src/DocumentCaptureScreens.stories.js +51 -0
  10. package/components/document/src/README.md +108 -0
  11. package/components/document/src/document-capture/DocumentCapture.js +677 -0
  12. package/components/document/src/document-capture/DocumentCapture.stories.js +71 -0
  13. package/components/document/src/document-capture/README.md +89 -0
  14. package/components/document/src/document-capture/index.js +3 -0
  15. package/components/document/src/document-capture-instructions/DocumentCaptureInstructions.js +499 -0
  16. package/components/document/src/document-capture-instructions/DocumentCaptureInstructions.stories.js +17 -0
  17. package/components/document/src/document-capture-instructions/README.md +56 -0
  18. package/components/document/src/document-capture-instructions/index.js +3 -0
  19. package/components/document/src/document-capture-review/DocumentCaptureReview.js +378 -0
  20. package/components/document/src/document-capture-review/DocumentCaptureReview.stories.js +14 -0
  21. package/components/document/src/document-capture-review/README.md +79 -0
  22. package/components/document/src/document-capture-review/index.js +3 -0
  23. package/components/document/src/index.js +3 -0
  24. package/components/end-user-consent/src/EndUserConsent.js +809 -0
  25. package/components/end-user-consent/src/EndUserConsent.stories.js +23 -0
  26. package/components/end-user-consent/src/index.js +4 -0
  27. package/components/navigation/src/Navigation.js +160 -0
  28. package/components/navigation/src/Navigation.stories.js +24 -0
  29. package/components/navigation/src/index.js +3 -0
  30. package/components/selfie/README.md +201 -0
  31. package/components/selfie/src/SelfieCaptureScreens.js +224 -0
  32. package/components/selfie/src/SelfieCaptureScreens.stories.js +21 -0
  33. package/components/selfie/src/index.js +5 -0
  34. package/components/selfie/src/selfie-capture/SelfieCapture.js +878 -0
  35. package/components/selfie/src/selfie-capture/SelfieCapture.stories.js +23 -0
  36. package/components/selfie/src/selfie-capture/index.js +3 -0
  37. package/components/selfie/src/selfie-capture-instructions/SelfieCaptureInstructions.js +638 -0
  38. package/components/selfie/src/selfie-capture-instructions/SelfieCaptureInstructions.stories.js +17 -0
  39. package/components/selfie/src/selfie-capture-instructions/index.js +3 -0
  40. package/components/selfie/src/selfie-capture-review/SelfieCaptureReview.js +348 -0
  41. package/components/selfie/src/selfie-capture-review/SelfieCaptureReview.stories.js +17 -0
  42. package/components/selfie/src/selfie-capture-review/index.js +3 -0
  43. package/components/signature-pad/package.json +30 -0
  44. package/components/signature-pad/src/SignaturePad.js +477 -0
  45. package/components/signature-pad/src/SignaturePad.stories.js +24 -0
  46. package/components/signature-pad/src/index.js +3 -0
  47. package/components/smart-camera-web/src/SmartCameraWeb.js +246 -0
  48. package/components/smart-camera-web/src/SmartCameraWeb.stories.js +35 -0
  49. package/components/totp-consent/src/TotpConsent.js +935 -0
  50. package/components/totp-consent/src/index.js +4 -0
  51. package/cypress/e2e/smart-camera-web-attribution.cy.js +21 -0
  52. package/cypress/e2e/smart-camera-web-back-press.cy.js +481 -0
  53. package/cypress/e2e/smart-camera-web-hide-instructions.cy.js +334 -0
  54. package/cypress/e2e/smart-camera-web.cy.js +309 -0
  55. package/cypress/fixtures/example.json +5 -0
  56. package/cypress/pages/capture-back-of-id-hide-attribution.html +44 -0
  57. package/cypress/pages/capture-back-of-id-navigation.html +72 -0
  58. package/cypress/pages/smart-camera-web-hide-instructions.html +38 -0
  59. package/cypress/pages/smart-camera-web.html +38 -0
  60. package/cypress/support/commands.js +144 -0
  61. package/cypress/support/e2e.js +20 -0
  62. package/cypress.config.js +11 -0
  63. package/domain/camera/src/README.md +38 -0
  64. package/domain/camera/src/SmartCamera.js +81 -0
  65. package/domain/constants/src/Constants.js +27 -0
  66. package/domain/file-upload/README.md +35 -0
  67. package/domain/file-upload/src/SmartFileUpload.js +65 -0
  68. package/esbuild.js +119 -0
  69. package/index.js +5 -0
  70. package/package.json +46 -0
  71. package/styles/README.md +3 -0
  72. package/styles/src/styles.js +348 -0
  73. package/styles/src/typography.js +52 -0
@@ -0,0 +1,317 @@
1
+ import { IMAGE_TYPE } from '../../../domain/constants/src/Constants';
2
+ import styles from '../../../styles/src/styles';
3
+ import SmartCamera from '../../../domain/camera/src/SmartCamera';
4
+
5
+ import './document-capture';
6
+ import './document-capture-review';
7
+ import './document-capture-instructions';
8
+ import { version as COMPONENTS_VERSION } from '../../../package.json';
9
+
10
+ async function getPermissions(captureScreen) {
11
+ try {
12
+ await SmartCamera.getMedia({
13
+ audio: false,
14
+ video: SmartCamera.environmentOptions,
15
+ });
16
+ captureScreen.removeAttribute('data-camera-error');
17
+ captureScreen.setAttribute('data-camera-ready', true);
18
+ } catch (error) {
19
+ captureScreen.removeAttribute('data-camera-ready');
20
+ captureScreen.setAttribute(
21
+ 'data-camera-error',
22
+ SmartCamera.handleCameraError(error),
23
+ );
24
+ }
25
+ }
26
+
27
+ class DocumentCaptureScreens extends HTMLElement {
28
+ constructor() {
29
+ super();
30
+ this.activeScreen = null;
31
+ }
32
+
33
+ connectedCallback() {
34
+ this.innerHTML = `
35
+ ${styles}
36
+ <div>
37
+ <document-capture-instructions id='document-capture-instructions-front' ${this.title} ${this.documentCaptureModes} ${this.showNavigation} ${this.hideInstructions ? 'hidden' : ''}></document-capture-instructions>
38
+ <document-capture id='document-capture-front' side-of-id='Front'
39
+ ${this.title} ${this.showNavigation} ${this.hideInstructions ? '' : 'hidden'}
40
+ ${this.documentCaptureModes} ${this.documentType}
41
+ ></document-capture>
42
+ <document-capture-instructions id='document-capture-instructions-back' side-of-id='Back' title='Submit Back of ID' ${this.documentCaptureModes} ${this.showNavigation} hidden></document-capture-instructions>
43
+ <document-capture id='document-capture-back' side-of-id='Back' ${this.title} ${this.showNavigation}
44
+ ${this.documentCaptureModes}
45
+ hidden
46
+ ></document-capture>
47
+ <document-capture-review id='front-of-document-capture-review' hidden></document-capture-review>
48
+ <document-capture-review id='back-of-document-capture-review' hidden></document-capture-review>
49
+ </div>
50
+ `;
51
+
52
+ this._data = {
53
+ images: [],
54
+ meta: {
55
+ libraryVersion: COMPONENTS_VERSION,
56
+ },
57
+ };
58
+
59
+ this.documentInstruction = this.querySelector(
60
+ 'document-capture-instructions',
61
+ );
62
+ this.documentInstructionBack = this.querySelector(
63
+ '#document-capture-instructions-back',
64
+ );
65
+ this.idCapture = this.querySelector('#document-capture-front');
66
+ this.idReview = this.querySelector('#front-of-document-capture-review');
67
+ this.idCaptureBack = this.querySelector('#document-capture-back');
68
+ this.backOfIdReview = this.querySelector(
69
+ '#back-of-document-capture-review',
70
+ );
71
+ this.thankYouScreen = this.querySelector('thank-you');
72
+
73
+ if (this.hideInstructions) {
74
+ getPermissions(this.idCapture);
75
+ this.setActiveScreen(this.idCapture);
76
+ } else {
77
+ this.setActiveScreen(this.documentInstruction);
78
+ }
79
+
80
+ this.setUpEventListeners();
81
+ }
82
+
83
+ disconnectedCallback() {
84
+ SmartCamera.stopMedia();
85
+ if (this.activeScreen) {
86
+ this.activeScreen.removeAttribute('hidden');
87
+ }
88
+ this.activeScreen = null;
89
+ this.innerHTML = '';
90
+ }
91
+
92
+ setUpEventListeners() {
93
+ this.documentInstruction.addEventListener(
94
+ 'document-capture-instructions.cancelled',
95
+ () => {
96
+ this.handleBackEvents();
97
+ },
98
+ );
99
+
100
+ this.documentInstruction.addEventListener(
101
+ 'document-capture-instructions.capture',
102
+ async () => {
103
+ this.setActiveScreen(this.idCapture);
104
+ await getPermissions(this.idCapture);
105
+ },
106
+ );
107
+ this.documentInstruction.addEventListener(
108
+ 'document-capture-instructions.upload',
109
+ async (event) => {
110
+ this.idReview.setAttribute('data-image', event.detail.image);
111
+ this._data.images.push({
112
+ image: event.detail.image.split(',')[1],
113
+ image_type_id: IMAGE_TYPE.ID_CARD_IMAGE_BASE64,
114
+ });
115
+ this.setActiveScreen(this.idReview);
116
+ },
117
+ );
118
+
119
+ this.idCapture.addEventListener('document-capture.publish', (event) => {
120
+ this.idReview.setAttribute('data-image', event.detail.image);
121
+ this._data.images.push({
122
+ image: event.detail.image.split(',')[1],
123
+ image_type_id: IMAGE_TYPE.ID_CARD_IMAGE_BASE64,
124
+ });
125
+ SmartCamera.stopMedia();
126
+ this.setActiveScreen(this.idReview);
127
+ });
128
+
129
+ this.idCapture.addEventListener('document-capture.cancelled', () => {
130
+ if (this.hideInstructions) {
131
+ this.handleBackEvents();
132
+ } else {
133
+ this.setActiveScreen(this.documentInstruction);
134
+ }
135
+ });
136
+
137
+ this.idReview.addEventListener(
138
+ 'document-capture-review.rejected',
139
+ async () => {
140
+ this.idReview.removeAttribute('data-image');
141
+ this._data.images.pop();
142
+ if (this.hideInstructions) {
143
+ this.setActiveScreen(this.idCapture);
144
+ await getPermissions(this.idCapture);
145
+ } else {
146
+ this.setActiveScreen(this.documentInstruction);
147
+ }
148
+ },
149
+ );
150
+
151
+ this.idReview.addEventListener(
152
+ 'document-capture-review.accepted',
153
+ async () => {
154
+ if (this.hideBackOfId) {
155
+ this._publishSelectedImages();
156
+ } else if (this.hideInstructions) {
157
+ this.setActiveScreen(this.idCaptureBack);
158
+ await getPermissions(this.idCaptureBack);
159
+ } else {
160
+ this.setActiveScreen(this.documentInstructionBack);
161
+ }
162
+ },
163
+ );
164
+
165
+ this.documentInstructionBack.addEventListener(
166
+ 'document-capture-instructions.capture',
167
+ async () => {
168
+ this.setActiveScreen(this.idCaptureBack);
169
+ await getPermissions(this.idCaptureBack);
170
+ },
171
+ );
172
+
173
+ this.documentInstructionBack.addEventListener(
174
+ 'document-capture-instructions.cancelled',
175
+ async () => {
176
+ this.idReview.removeAttribute('data-image');
177
+ this._data.images.pop();
178
+ if (this.hideInstructions) {
179
+ this.setActiveScreen(this.idCapture);
180
+ await getPermissions(this.idCapture);
181
+ } else {
182
+ this.setActiveScreen(this.documentInstruction);
183
+ }
184
+ },
185
+ );
186
+
187
+ this.documentInstructionBack.addEventListener(
188
+ 'document-capture-instructions.upload',
189
+ async (event) => {
190
+ this.idReview.setAttribute('data-image', event.detail.image);
191
+ this._data.images.push({
192
+ image: event.detail.image.split(',')[1],
193
+ image_type_id: IMAGE_TYPE.ID_CARD_BACK_IMAGE_BASE64,
194
+ });
195
+ this.setActiveScreen(this.backOfIdReview);
196
+ },
197
+ );
198
+ this.idCaptureBack.addEventListener('document-capture.publish', (event) => {
199
+ this.backOfIdReview.setAttribute('data-image', event.detail.image);
200
+ this._data.images.push({
201
+ image: event.detail.image.split(',')[1],
202
+ image_type_id: IMAGE_TYPE.ID_CARD_BACK_IMAGE_BASE64,
203
+ });
204
+ this.setActiveScreen(this.backOfIdReview);
205
+ SmartCamera.stopMedia();
206
+ });
207
+
208
+ this.idCaptureBack.addEventListener(
209
+ 'document-capture.cancelled',
210
+ async () => {
211
+ if (this.hideInstructions) {
212
+ this.setActiveScreen(this.idCapture);
213
+ await getPermissions(this.idCapture);
214
+ } else {
215
+ this.setActiveScreen(this.documentInstructionBack);
216
+ }
217
+ },
218
+ );
219
+
220
+ this.backOfIdReview.addEventListener(
221
+ 'document-capture-review.rejected',
222
+ async () => {
223
+ this.backOfIdReview.removeAttribute('data-image');
224
+ this._data.images.pop();
225
+ if (this.hideInstructions) {
226
+ this.setActiveScreen(this.idCaptureBack);
227
+ await getPermissions(this.idCaptureBack);
228
+ } else {
229
+ this.setActiveScreen(this.documentInstructionBack);
230
+ }
231
+ },
232
+ );
233
+
234
+ this.backOfIdReview.addEventListener(
235
+ 'document-capture-review.accepted',
236
+ () => {
237
+ this._publishSelectedImages();
238
+ },
239
+ );
240
+
241
+ const screens = [
242
+ this.documentInstruction,
243
+ this.idCapture,
244
+ this.documentInstructionBack,
245
+ this.idCaptureBack,
246
+ this.idReview,
247
+ this.backOfIdReview,
248
+ ];
249
+
250
+ screens.forEach((screen) => {
251
+ screen.addEventListener(`${screen.nodeName.toLowerCase()}.close`, () =>
252
+ this.handleCloseEvents(),
253
+ );
254
+ });
255
+ }
256
+
257
+ _publishSelectedImages() {
258
+ this.dispatchEvent(
259
+ new CustomEvent('document-capture-screens.publish', {
260
+ detail: this._data,
261
+ }),
262
+ );
263
+ }
264
+
265
+ get hideInstructions() {
266
+ return this.hasAttribute('hide-instructions');
267
+ }
268
+
269
+ get hideBackOfId() {
270
+ return this.hasAttribute('hide-back-of-id');
271
+ }
272
+
273
+ get showNavigation() {
274
+ return this.hasAttribute('show-navigation') ? 'show-navigation' : '';
275
+ }
276
+
277
+ get title() {
278
+ return this.hasAttribute('title')
279
+ ? `title=${this.getAttribute('title')}`
280
+ : '';
281
+ }
282
+
283
+ get documentCaptureModes() {
284
+ return this.hasAttribute('document-capture-modes')
285
+ ? `document-capture-modes='${this.getAttribute('document-capture-modes')}'`
286
+ : '';
287
+ }
288
+
289
+ get documentType() {
290
+ return this.hasAttribute('document-type')
291
+ ? `document-type='${this.getAttribute('document-type')}'`
292
+ : '';
293
+ }
294
+
295
+ handleBackEvents() {
296
+ this.dispatchEvent(new CustomEvent('document-capture-screens.cancelled'));
297
+ }
298
+
299
+ handleCloseEvents() {
300
+ this.dispatchEvent(new CustomEvent('document-capture-screens.close'));
301
+ }
302
+
303
+ setActiveScreen(screen) {
304
+ this.activeScreen?.setAttribute('hidden', '');
305
+ screen.removeAttribute('hidden');
306
+ this.activeScreen = screen;
307
+ }
308
+ }
309
+
310
+ if (
311
+ 'customElements' in window &&
312
+ !customElements.get('document-capture-screens')
313
+ ) {
314
+ customElements.define('document-capture-screens', DocumentCaptureScreens);
315
+ }
316
+
317
+ export default DocumentCaptureScreens;
@@ -0,0 +1,51 @@
1
+ import './index';
2
+
3
+ const meta = {
4
+ component: 'document-capture-screens',
5
+ };
6
+
7
+ export default meta;
8
+
9
+ export const DocumentCapture = {
10
+ render: () => `
11
+ <document-capture-screens>
12
+ </document-capture-screens>
13
+ `,
14
+ };
15
+
16
+ export const DocumentCaptureHiddenInstructions = {
17
+ render: () => `
18
+ <document-capture-screens hide-instructions>
19
+ </document-capture-screens>
20
+ `,
21
+ };
22
+
23
+ export const DocumentCaptureHideBackOfId = {
24
+ render: () => `
25
+ <document-capture-screens
26
+ hide-back-of-id
27
+ >
28
+ </document-capture-screens>
29
+ `,
30
+ };
31
+
32
+ export const DocumentCaptureAllowAttributes = {
33
+ render: () => `
34
+ <document-capture-screens document-capture-screens-modes='camera,upload'>
35
+ </document-capture-screens>
36
+ `,
37
+ };
38
+
39
+ export const DocumentCaptureHideInstructionNBackOfId = {
40
+ render: () => `
41
+ <document-capture-screens hide-back-of-id hide-instructions>
42
+ </document-capture-screens>
43
+ `,
44
+ };
45
+
46
+ export const DocumentCapturePortraitMode = {
47
+ render: () => `
48
+ <document-capture-screens hide-back-of-id hide-instructions document-type="GREEN_BOOK">
49
+ </document-capture-screens>
50
+ `,
51
+ };
@@ -0,0 +1,108 @@
1
+ # DocumentCapture Web Component
2
+
3
+ ## Overview
4
+
5
+ The `DocumentCapture` is a bespoke web component designed for capturing document images using a camera. It leverages the `SmartCamera` module for camera interaction and permission management.
6
+
7
+ ### Importing the Component
8
+
9
+ To utilize the DocumentCapture component within your project, import it into your JavaScript file as follows:
10
+
11
+ ```js
12
+ import '@smileid/components/document-capture';
13
+ ```
14
+
15
+ ### Using the Component
16
+
17
+ The DocumentCapture component can be embedded in your HTML similarly to any standard HTML element:
18
+
19
+ ```html
20
+ <document-capture></document-capture>
21
+ ```
22
+
23
+ ### Attributes
24
+
25
+ Customize the component's behavior with the following attributes:
26
+
27
+ #### `hide-instructions`
28
+
29
+ Omits the capture instructions. This attribute is boolean and does not require a value.
30
+
31
+ ```html
32
+ <document-capture hide-instructions></document-capture>
33
+ ```
34
+
35
+ #### `hide-back-of-id`
36
+
37
+ Excludes the option to capture the ID's back side. This attribute is boolean.
38
+
39
+ ```html
40
+ <document-capture hide-back-of-id></document-capture>
41
+ ```
42
+
43
+ #### `show-navigation`
44
+
45
+ Displays navigation controls for the capture process. This attribute is boolean.
46
+
47
+ ```html
48
+ <document-capture show-navigation></document-capture>
49
+ ```
50
+
51
+ #### `document-capture-modes`
52
+
53
+ Specifies the capture modes, accepting `camera`, `upload`, or both. Value required.
54
+
55
+ ```html
56
+ <document-capture document-capture-modes="camera,upload"></document-capture>
57
+ ```
58
+
59
+ ### Permissions
60
+
61
+ Camera permissions are essential for functionality. The component requests permissions automatically. Upon granting, `data-camera-ready` is set to true, and `data-camera-error` is removed. Denied permissions result in `data-camera-error` being set with an error message.
62
+
63
+ For manual permission handling, appropriately set `data-camera-ready` and `data-camera-error`.
64
+
65
+ ### Error Handling
66
+
67
+ Errors during permission requests or document capture are managed by the component, setting `data-camera-error` with the respective error message.
68
+
69
+ ### Event Handlers
70
+
71
+ Capture events emit `document-capture-screens.publish`, providing captured images and metadata:
72
+
73
+ ```json
74
+ {
75
+ "detail": {
76
+ "images": [{ "image": "base64-encoded image", "image_type_id": "" }],
77
+ "meta": {
78
+ "version": "library version"
79
+ }
80
+ }
81
+ }
82
+ ```
83
+
84
+ To handle this event:
85
+
86
+ ```js
87
+ document
88
+ .querySelector('document-capture')
89
+ .addEventListener('document-capture-screens.publish', function (event) {
90
+ console.log(event.detail);
91
+ });
92
+ ```
93
+
94
+ ### Dependencies
95
+
96
+ `DocumentCaptureScreens` relies on the following modules:
97
+
98
+ - [document-capture-instructions](./document-capture-instructions/README.md)
99
+ - [document-capture](./document-capture/README.md)
100
+ - [document-capture-review](./document-capture-review/README.md)
101
+ - [SmartCamera](../../../domain/camera/src/README.md)
102
+ - [FileUpload](../../../domain/file-upload/README.md)
103
+
104
+ These dependencies are automatically imported with the component.
105
+
106
+ ### Compatibility
107
+
108
+ Designed for modern browsers supporting custom web components, with specific enhancements for multi-camera Samsung devices to prevent blurry image edges. Report compatibility issues with other devices to our support team.