@authid/web-component 1.4.0 → 1.5.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/CHANGELOG.txt CHANGED
@@ -1,3 +1,9 @@
1
- 1.4.0
2
- -----
3
- CHANGED: removed loader graphics, user should provide own one while waiting for the 'load' event.
1
+ 1.5.0
2
+ -----
3
+ CHANGED: all dependencies are loaded by default unless disabled.
4
+ CHANGED: component initialization issues are detected now.
5
+ NEW: component emits "error" event, if loading error occurs.
6
+
7
+ 1.4.0
8
+ -----
9
+ CHANGED: removed loader graphics, user should provide own one while waiting for the 'load' event.
package/README.md CHANGED
@@ -1,24 +1,24 @@
1
-
2
- # authID integration as a Web Component
3
-
4
- This [authID](https://authid.ai/) Web Component provides a convenient integration overlay. The overlay hovers over your website in desktop environment and occupies maximum space in mobile environment.
5
-
6
- This integration is the most universal one as it can be used with any frontend technology.
7
-
8
- ## API
9
-
10
- * `authid-component` - a custom HTML component with the following attributes:
11
- - `data-url` - required parameter with operation/transaction URL received from authID,
12
- - `data-target` - force selection of either `mobile` or `desktop` integration variant, `auto` is the default.
13
- *NOTE: this parameter is obsolete, and it has no effect at the moment.*
14
- - `data-webauth="true"` - enable automatic handling of Passkey features.
15
- - `data-control="true"` - enable advanced control features.
16
-
17
- ## Example
18
-
19
- Please see `example.html` for full details.
20
-
21
- ```html
22
- <script src="path-to/authid-web-component.js"></script>
23
- <authid-component data-url="https://id.authid.ai/?...."></authid-component>
24
- ```
1
+
2
+ # authID integration as a Web Component
3
+
4
+ This [authID](https://authid.ai/) Web Component provides a convenient integration overlay. The overlay hovers over your website in desktop environment and occupies maximum space in mobile environment.
5
+
6
+ This integration is the most universal one as it can be used with any frontend technology.
7
+
8
+ ## API
9
+
10
+ * `authid-component` - a custom HTML component with the following attributes:
11
+ - `data-url` - required parameter with operation/transaction URL received from authID,
12
+ - `data-target` - force selection of either `mobile` or `desktop` integration variant, `auto` is the default.
13
+ *NOTE: this parameter is obsolete, and it has no effect at the moment.*
14
+ - `data-webauth="true"` - enable automatic handling of Passkey features.
15
+ - `data-control="true"` - enable advanced control features.
16
+
17
+ ## Example
18
+
19
+ Please see `example.html` for full details.
20
+
21
+ ```html
22
+ <script src="path-to/authid-web-component.js"></script>
23
+ <authid-component data-url="https://id.authid.ai/?...."></authid-component>
24
+ ```
@@ -1,85 +1,136 @@
1
- /**
2
- * Copyright 2022-2023 authID.ai (Ipsidy, Inc.)
3
- *
4
- * Licensed under the Apache License, Version 2.0 (the "License");
5
- * you may not use this file except in compliance with the License.
6
- * You may obtain a copy of the License at
7
-
8
- * http://www.apache.org/licenses/LICENSE-2.0
9
-
10
- * Unless required by applicable law or agreed to in writing, software
11
- * distributed under the License is distributed on an "AS IS" BASIS,
12
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
- * See the License for the specific language governing permissions and
14
- * limitations under the License.
15
- */
16
- class AuthIDComponent extends HTMLElement {
17
- connectedCallback() {
18
- const dataUrl = this.getAttribute('data-url');
19
- if (!dataUrl) {
20
- throw new Error('Missing data-url configuration!');
21
- }
22
-
23
- let dataTarget = this.getAttribute('data-target');
24
-
25
- if (!dataTarget || dataTarget === 'auto') {
26
- dataTarget = /Mobi|Android/i.test(navigator.userAgent) ? 'mobile' : 'desktop';
27
- }
28
-
29
- const iframe = document.createElement('iframe');
30
- iframe.setAttribute('allow', 'fullscreen *;camera *;encrypted-media *;');
31
- iframe.setAttribute('src', dataUrl);
32
-
33
- const styleNode = document.createElement('style');
34
- styleNode.textContent = (
35
- 'div, iframe {' +
36
- 'position: fixed;' +
37
- 'top: 0;' +
38
- 'left: 0;' +
39
- 'height: 100vh;' +
40
- 'width: 100vw;' +
41
- 'border: 0;' +
42
- 'padding: 0;' +
43
- 'margin: 0;' +
44
- '}'
45
- );
46
-
47
- const shadow = this.attachShadow({ mode: 'closed' });
48
- shadow.appendChild(styleNode);
49
- const container = document.createElement('div');
50
- shadow.appendChild(container);
51
-
52
- const dataWebauth = this.getAttribute('data-webauth');
53
-
54
- if (dataWebauth && dataWebauth !== 'false' && dataWebauth !== 'no') {
55
- const webauthHandler = document.createElement('script');
56
- webauthHandler.setAttribute('src', dataUrl.replace('/?', '/webauthhandler.js?'));
57
- shadow.appendChild(webauthHandler);
58
- }
59
-
60
- const dataControl = this.getAttribute('data-control');
61
-
62
- if (dataControl && dataControl !== 'false' && dataControl !== 'no') {
63
- const controlHandler = document.createElement('script');
64
- controlHandler.setAttribute('src', dataUrl.replace('/?', '/controlhandler.js?'));
65
- shadow.appendChild(controlHandler);
66
- }
67
-
68
- shadow.appendChild(iframe);
69
-
70
- iframe.addEventListener('load', () => {
71
- shadow.removeChild(container);
72
-
73
- shadow.dispatchEvent(new CustomEvent('load', {
74
- composed: true,
75
- bubbles: true,
76
- }));
77
- }, { capture: true, once: true });
78
-
79
- if (window.getComputedStyle(this)['z-index'] === 'auto') {
80
- this.style['z-index'] = 1000;
81
- }
82
- }
83
- }
84
-
85
- window.customElements.define('authid-component', AuthIDComponent);
1
+ /**
2
+ * Copyright 2022-2023 authID.ai (Ipsidy, Inc.)
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+ class AuthIDComponent extends HTMLElement {
17
+ connectedCallback() {
18
+ const dataUrl = this.getAttribute('data-url');
19
+ if (!dataUrl) {
20
+ throw new Error('Missing data-url configuration!');
21
+ }
22
+
23
+ let dataTarget = this.getAttribute('data-target');
24
+
25
+ if (!dataTarget || dataTarget === 'auto') {
26
+ dataTarget = /Mobi|Android/i.test(navigator.userAgent) ? 'mobile' : 'desktop';
27
+ }
28
+
29
+ const iframe = document.createElement('iframe');
30
+ iframe.setAttribute('allow', 'fullscreen *;camera *;encrypted-media *;');
31
+ iframe.setAttribute('src', dataUrl);
32
+
33
+ const styleNode = document.createElement('style');
34
+ styleNode.textContent = (
35
+ 'div, iframe {' +
36
+ 'position: fixed;' +
37
+ 'top: 0;' +
38
+ 'left: 0;' +
39
+ 'height: 100vh;' +
40
+ 'width: 100vw;' +
41
+ 'border: 0;' +
42
+ 'padding: 0;' +
43
+ 'margin: 0;' +
44
+ '}'
45
+ );
46
+
47
+ const shadow = this.attachShadow({ mode: 'closed' });
48
+ shadow.appendChild(styleNode);
49
+ const container = document.createElement('div');
50
+ shadow.appendChild(container);
51
+
52
+ const dataWebauth = this.getAttribute('data-webauth');
53
+ const dataControl = this.getAttribute('data-control');
54
+
55
+ const requiredDeps = [];
56
+ const loadedDeps = [];
57
+ let depFailed = false;
58
+
59
+ const tryAttachIframe = () => {
60
+ if (depFailed) return;
61
+ if (loadedDeps.length === requiredDeps.length) {
62
+ shadow.appendChild(iframe);
63
+ }
64
+ };
65
+
66
+ const onDepError = () => {
67
+ if (depFailed) return;
68
+ depFailed = true;
69
+ shadow.dispatchEvent(new CustomEvent('error', {
70
+ composed: true,
71
+ bubbles: true,
72
+ detail: { message: 'Dependency load failed.' },
73
+ }));
74
+ };
75
+
76
+ if (dataWebauth !== 'false' && dataWebauth !== 'no') {
77
+ requiredDeps.push('webauthhandler');
78
+ const webauthHandler = document.createElement('script');
79
+ webauthHandler.setAttribute('src', dataUrl.replace('/?', '/webauthhandler.js?'));
80
+ webauthHandler.onload = () => {
81
+ loadedDeps.push('webauthhandler');
82
+ tryAttachIframe();
83
+ };
84
+ webauthHandler.onerror = onDepError;
85
+ shadow.appendChild(webauthHandler);
86
+ }
87
+
88
+ if (dataControl !== 'false' && dataControl !== 'no') {
89
+ requiredDeps.push('controlhandler');
90
+ const controlHandler = document.createElement('script');
91
+ controlHandler.setAttribute('src', dataUrl.replace('/?', '/controlhandler.js?'));
92
+ controlHandler.onload = () => {
93
+ loadedDeps.push('controlhandler');
94
+ tryAttachIframe();
95
+ };
96
+ controlHandler.onerror = onDepError;
97
+ shadow.appendChild(controlHandler);
98
+ }
99
+
100
+ tryAttachIframe();
101
+
102
+ let wasInit = false;
103
+
104
+ const messageHandler = (event) => {
105
+ if (event.origin !== new URL(dataUrl).origin) return;
106
+ if (event.data && event.data.type === 'authid:init') {
107
+ wasInit = true;
108
+
109
+ shadow.dispatchEvent(new CustomEvent('load', {
110
+ composed: true,
111
+ bubbles: true,
112
+ }));
113
+ }
114
+ };
115
+
116
+ window.addEventListener('message', messageHandler);
117
+
118
+ iframe.addEventListener('load', () => {
119
+ setTimeout(() => {
120
+ if (!wasInit) {
121
+ shadow.dispatchEvent(new CustomEvent('error', {
122
+ composed: true,
123
+ bubbles: true,
124
+ detail: { message: 'Component initialization failed.' },
125
+ }));
126
+ }
127
+ }, 1e3);
128
+ }, { capture: true, once: true });
129
+
130
+ if (window.getComputedStyle(this)['z-index'] === 'auto') {
131
+ this.style['z-index'] = 1000;
132
+ }
133
+ }
134
+ }
135
+
136
+ window.customElements.define('authid-component', AuthIDComponent);
@@ -0,0 +1,38 @@
1
+ import { defineConfig } from "eslint/config";
2
+ import globals from "globals";
3
+ import path from "node:path";
4
+ import { fileURLToPath } from "node:url";
5
+ import js from "@eslint/js";
6
+ import { FlatCompat } from "@eslint/eslintrc";
7
+
8
+ const __filename = fileURLToPath(import.meta.url);
9
+ const __dirname = path.dirname(__filename);
10
+ const compat = new FlatCompat({
11
+ baseDirectory: __dirname,
12
+ recommendedConfig: js.configs.recommended,
13
+ allConfig: js.configs.all
14
+ });
15
+
16
+ export default defineConfig([{
17
+ extends: compat.extends("eslint:recommended"),
18
+
19
+ languageOptions: {
20
+ globals: {
21
+ ...globals.browser,
22
+ ENABLE_DEBUG: "readonly",
23
+ BUILD_ID: "readonly",
24
+ },
25
+
26
+ ecmaVersion: 6,
27
+ sourceType: "script",
28
+ },
29
+
30
+ rules: {
31
+ complexity: ["error", 25],
32
+
33
+ "no-unused-vars": ["error", {
34
+ argsIgnorePattern: "^_",
35
+ varsIgnorePattern: "^_",
36
+ }],
37
+ },
38
+ }]);
package/example.html CHANGED
@@ -1,20 +1,24 @@
1
- <html>
2
- <head>
3
- <title>authID Web Component example</title>
4
- <meta name="viewport" content="initial-scale=1,user-scalable=no">
5
- <style>
6
- body {
7
- background-color: darkslateblue;
8
- }
9
- </style>
10
- <script src="./authid-web-component.js"></script>
11
- </head>
12
- <body>
13
- <authid-component data-url="https://id.authid.ai/?demo" data-webauth="true"></authid-component>
14
- <script>
15
- document.getElementsByTagName('authid-component')[0].addEventListener('load', function(){
16
- console.log('Iframe has just loaded, the component is ready');
17
- });
18
- </script>
19
- </body>
20
- </html>
1
+ <html>
2
+ <head>
3
+ <title>authID Web Component example</title>
4
+ <meta name="viewport" content="initial-scale=1">
5
+ <style>
6
+ body {
7
+ background-color: darkslateblue;
8
+ }
9
+ </style>
10
+ <script src="./authid-web-component.js"></script>
11
+ </head>
12
+ <body>
13
+ <authid-component data-url="https://id.authid.ai/?demo"></authid-component>
14
+ <script>
15
+ document.getElementsByTagName('authid-component')[0].addEventListener('load', function(){
16
+ console.log('authID web component has just loaded.');
17
+ });
18
+
19
+ document.getElementsByTagName('authid-component')[0].addEventListener('error', function () {
20
+ alert('authID web component failed to load');
21
+ });
22
+ </script>
23
+ </body>
24
+ </html>
package/package.json CHANGED
@@ -1,20 +1,20 @@
1
- {
2
- "name": "@authid/web-component",
3
- "version": "1.4.0",
4
- "description": "authID integration as a Web Component",
5
- "main": "authid-web-component.js",
6
- "scripts": {
7
- "test": "eslint --ext .js ."
8
- },
9
- "keywords": [
10
- "authid",
11
- "identity",
12
- "authentication",
13
- "kyc"
14
- ],
15
- "author": "authID Team <team@authid.ai>",
16
- "license": "Apache-2.0",
17
- "devDependencies": {
18
- "eslint": "^8.36.0"
19
- }
20
- }
1
+ {
2
+ "name": "@authid/web-component",
3
+ "version": "1.5.0",
4
+ "description": "authID integration as a Web Component",
5
+ "main": "authid-web-component.js",
6
+ "scripts": {
7
+ "test": "eslint --ext .js . --ignore-pattern eslint.*"
8
+ },
9
+ "keywords": [
10
+ "authid",
11
+ "identity",
12
+ "authentication",
13
+ "kyc"
14
+ ],
15
+ "author": "authID Team <team@authid.ai>",
16
+ "license": "Apache-2.0",
17
+ "devDependencies": {
18
+ "eslint": "^9.39.1"
19
+ }
20
+ }
package/.eslintrc.yml DELETED
@@ -1,15 +0,0 @@
1
- env:
2
- browser: true
3
- extends: 'eslint:recommended'
4
- parserOptions:
5
- ecmaVersion: 6
6
- rules: {
7
- "complexity": ["error", 25],
8
- "no-unused-vars": ["error", {
9
- "argsIgnorePattern": "^_",
10
- "varsIgnorePattern": "^_"
11
- }],
12
- }
13
- globals:
14
- ENABLE_DEBUG: readonly
15
- BUILD_ID: readonly