@mxenabled/web-connect-widget-sdk 0.0.1

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.
@@ -0,0 +1,3 @@
1
+ node_modules
2
+
3
+ dist
package/.prettierrc ADDED
@@ -0,0 +1,6 @@
1
+ {
2
+ "semi": true,
3
+ "singleQuote": true,
4
+ "trailingComma": "es5",
5
+ "printWidth": 80
6
+ }
package/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 MX Technologies Inc.
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy of
6
+ this software and associated documentation files (the "Software"), to deal in
7
+ the Software without restriction, including without limitation the rights to
8
+ use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
9
+ the Software, and to permit persons to whom the Software is furnished to do so,
10
+ subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
17
+ FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
18
+ COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
19
+ IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20
+ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,10 @@
1
+ interface ConnectWidgetProps {
2
+ containerSelector: string;
3
+ iframeProps?: Record<string, unknown>;
4
+ url: string;
5
+ }
6
+ export declare const ConnectWidget: ({ containerSelector, iframeProps, url, }: ConnectWidgetProps) => {
7
+ mount: () => void;
8
+ unmount: () => void;
9
+ };
10
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ export { ConnectWidget } from './ConnectWidget';
package/dist/index.js ADDED
@@ -0,0 +1,30 @@
1
+ const m = ({
2
+ containerSelector: n,
3
+ iframeProps: o,
4
+ url: s
5
+ }) => {
6
+ const t = document.createElement("iframe"), { style: i, ...c } = o || {}, a = {
7
+ height: "100%",
8
+ width: "100%",
9
+ ...i ?? {}
10
+ };
11
+ Object.assign(t.style, a);
12
+ for (const [e, r] of Object.entries(c))
13
+ e.startsWith("data-") ? t.setAttribute(e, String(r)) : Object.assign(t, { [e]: r });
14
+ return t.src = s, {
15
+ mount: () => {
16
+ const e = document.querySelector(n);
17
+ if (!e)
18
+ throw new Error(
19
+ `Container with selector "${n}" not found.`
20
+ );
21
+ e.appendChild(t);
22
+ },
23
+ unmount: () => {
24
+ t.remove();
25
+ }
26
+ };
27
+ };
28
+ export {
29
+ m as ConnectWidget
30
+ };
@@ -0,0 +1 @@
1
+ (function(e,o){typeof exports=="object"&&typeof module<"u"?o(exports):typeof define=="function"&&define.amd?define(["exports"],o):(e=typeof globalThis<"u"?globalThis:e||self,o(e.index={}))})(this,(function(e){"use strict";const o=({containerSelector:i,iframeProps:r,url:d})=>{const t=document.createElement("iframe"),{style:f,...c}=r||{},u={height:"100%",width:"100%",...f??{}};Object.assign(t.style,u);for(const[n,s]of Object.entries(c))n.startsWith("data-")?t.setAttribute(n,String(s)):Object.assign(t,{[n]:s});return t.src=d,{mount:()=>{const n=document.querySelector(i);if(!n)throw new Error(`Container with selector "${i}" not found.`);n.appendChild(t)},unmount:()=>{t.remove()}}};e.ConnectWidget=o,Object.defineProperty(e,Symbol.toStringTag,{value:"Module"})}));
@@ -0,0 +1,24 @@
1
+ import js from '@eslint/js';
2
+ import tseslint from 'typescript-eslint';
3
+ import prettier from 'eslint-plugin-prettier/recommended';
4
+ import { defineConfig, globalIgnores } from 'eslint/config';
5
+
6
+ export default defineConfig([
7
+ globalIgnores(['dist', 'node_modules']),
8
+ {
9
+ files: ['**/*.{ts,js}'],
10
+ extends: [
11
+ js.configs.recommended,
12
+ ...tseslint.configs.recommended,
13
+ prettier,
14
+ ],
15
+ languageOptions: {
16
+ ecmaVersion: 2024,
17
+ sourceType: 'module',
18
+ parser: tseslint.parser,
19
+ parserOptions: {
20
+ tsconfigRootDir: import.meta.dirname,
21
+ },
22
+ },
23
+ },
24
+ ]);
package/package.json ADDED
@@ -0,0 +1,47 @@
1
+ {
2
+ "name": "@mxenabled/web-connect-widget-sdk",
3
+ "version": "0.0.1",
4
+ "description": "MX Connect Web Widget SDK",
5
+ "main": "dist/index.js",
6
+ "type": "module",
7
+ "publishConfig": {
8
+ "access": "public"
9
+ },
10
+ "repository": {
11
+ "type": "git",
12
+ "url": "git+https://github.com/mxenabled/web-connect-widget-sdk.git"
13
+ },
14
+ "author": "",
15
+ "license": "MIT",
16
+ "bugs": {
17
+ "url": "https://github.com/mxenabled/web-connect-widget-sdk/issues"
18
+ },
19
+ "homepage": "https://github.com/mxenabled/web-connect-widget-sdk#readme",
20
+ "scripts": {
21
+ "dev": "vite build --watch",
22
+ "build": "vite build",
23
+ "lint": "eslint \"src/**/*.{ts,js}\"",
24
+ "lint:fix": "eslint \"src/**/*.{ts,js}\" --fix",
25
+ "format": "prettier --write \"src/**/*.{ts,js,json,md}\"",
26
+ "format:check": "prettier --check \"src/**/*.{ts,js,json,md}\"",
27
+ "test": "vitest run",
28
+ "test:watch": "vitest"
29
+ },
30
+ "devDependencies": {
31
+ "@eslint/js": "^9.39.1",
32
+ "@testing-library/dom": "^10.4.1",
33
+ "@testing-library/jest-dom": "^6.9.1",
34
+ "eslint": "^9.39.1",
35
+ "eslint-config-prettier": "^9.0.0",
36
+ "eslint-plugin-prettier": "^5.0.0",
37
+ "jsdom": "^28.1.0",
38
+ "prettier": "^3.0.0",
39
+ "typescript": "~5.9.3",
40
+ "typescript-eslint": "^8.48.0",
41
+ "vite": "^7.0.0",
42
+ "vitest": "^4.0.18"
43
+ },
44
+ "dependencies": {
45
+ "vite-plugin-dts": "^4.5.4"
46
+ }
47
+ }
@@ -0,0 +1,116 @@
1
+ import { afterEach, beforeEach, describe, expect, it } from 'vitest';
2
+ import { getByTestId, queryByTestId } from '@testing-library/dom';
3
+ import { ConnectWidget } from './ConnectWidget';
4
+
5
+ const widgetContainerId = 'widget-container';
6
+ const testId = 'connect-widget-iframe';
7
+
8
+ const createDOM = () => {
9
+ const div = document.createElement('div');
10
+ div.id = widgetContainerId;
11
+ document.body.appendChild(div);
12
+
13
+ return div;
14
+ };
15
+
16
+ describe('ConnectWidget', () => {
17
+ let container: HTMLElement;
18
+
19
+ beforeEach(() => {
20
+ container = createDOM();
21
+ });
22
+ afterEach(() => {
23
+ document.body.replaceChildren();
24
+ });
25
+
26
+ it('mounts and unmounts without error', () => {
27
+ const widget = ConnectWidget({
28
+ containerSelector: `#${widgetContainerId}`,
29
+ iframeProps: {
30
+ 'data-testid': 'connect-widget-iframe',
31
+ },
32
+ url: 'https://example.com',
33
+ });
34
+
35
+ widget.mount();
36
+
37
+ const iframe = getByTestId(container, testId);
38
+
39
+ expect(iframe).toBeTruthy();
40
+
41
+ widget.unmount();
42
+
43
+ expect(queryByTestId(container, testId)).toBeFalsy();
44
+ });
45
+
46
+ it('sets data attributes, styles, and other iframe props correctly', () => {
47
+ const widget = ConnectWidget({
48
+ containerSelector: `#${widgetContainerId}`,
49
+ iframeProps: {
50
+ 'data-testid': testId,
51
+ 'data-custom-attr': 'customValue',
52
+ title: 'Connect Widget Iframe',
53
+ style: {
54
+ border: 'solid 1px black',
55
+ height: '50px',
56
+ width: '50px',
57
+ },
58
+ },
59
+ url: 'https://example.com',
60
+ });
61
+
62
+ widget.mount();
63
+
64
+ const iframe = getByTestId(container, testId);
65
+
66
+ expect(iframe).toBeTruthy();
67
+ expect(iframe).toHaveAttribute('data-custom-attr', 'customValue');
68
+ expect(iframe).toHaveAttribute('title', 'Connect Widget Iframe');
69
+ expect(iframe).toHaveStyle({
70
+ width: '50px',
71
+ height: '50px',
72
+ });
73
+ expect(iframe.style.border).toBe('1px solid black');
74
+
75
+ widget.unmount();
76
+ });
77
+
78
+ it('defaults height and width to 100% if not provided in styles, but still uses the rest of the provided styles', () => {
79
+ const widget = ConnectWidget({
80
+ containerSelector: `#${widgetContainerId}`,
81
+ iframeProps: {
82
+ 'data-testid': testId,
83
+ style: {
84
+ border: 'solid 1px black',
85
+ },
86
+ title: 'Connect Widget Iframe',
87
+ },
88
+ url: 'https://example.com',
89
+ });
90
+
91
+ widget.mount();
92
+
93
+ const iframe = getByTestId(container, testId);
94
+
95
+ expect(iframe).toBeTruthy();
96
+ expect(iframe).toHaveStyle({
97
+ width: '100%',
98
+ height: '100%',
99
+ });
100
+
101
+ expect(iframe.style.border).toBe('1px solid black');
102
+
103
+ widget.unmount();
104
+ });
105
+
106
+ it('throws an error if the container element is not found when mounting', () => {
107
+ const widget = ConnectWidget({
108
+ containerSelector: '#non-existent-container',
109
+ url: 'https://example.com',
110
+ });
111
+
112
+ expect(() => widget.mount()).toThrowError(
113
+ 'Container with selector "#non-existent-container" not found.'
114
+ );
115
+ });
116
+ });
@@ -0,0 +1,50 @@
1
+ interface ConnectWidgetProps {
2
+ containerSelector: string;
3
+ iframeProps?: Record<string, unknown>;
4
+ url: string;
5
+ }
6
+
7
+ export const ConnectWidget = ({
8
+ containerSelector,
9
+ iframeProps,
10
+ url,
11
+ }: ConnectWidgetProps) => {
12
+ const iframe = document.createElement('iframe');
13
+
14
+ const { style: iframeStyle, ...restIframeProps } = iframeProps || {};
15
+
16
+ const style = {
17
+ height: '100%',
18
+ width: '100%',
19
+ ...(iframeStyle ?? {}),
20
+ };
21
+
22
+ Object.assign(iframe.style, style);
23
+
24
+ for (const [key, value] of Object.entries(restIframeProps)) {
25
+ if (key.startsWith('data-')) {
26
+ iframe.setAttribute(key, String(value));
27
+ } else {
28
+ Object.assign(iframe, { [key]: value });
29
+ }
30
+ }
31
+
32
+ iframe.src = url;
33
+
34
+ return {
35
+ mount: () => {
36
+ const container = document.querySelector(containerSelector);
37
+
38
+ if (!container) {
39
+ throw new Error(
40
+ `Container with selector "${containerSelector}" not found.`
41
+ );
42
+ }
43
+
44
+ container.appendChild(iframe);
45
+ },
46
+ unmount: () => {
47
+ iframe.remove();
48
+ },
49
+ };
50
+ };
package/src/index.ts ADDED
@@ -0,0 +1 @@
1
+ export { ConnectWidget } from './ConnectWidget';
package/testSetup.ts ADDED
@@ -0,0 +1 @@
1
+ import '@testing-library/jest-dom/vitest';
package/tsconfig.json ADDED
@@ -0,0 +1,26 @@
1
+ {
2
+ "compilerOptions": {
3
+ "target": "ES2022",
4
+ "useDefineForClassFields": true,
5
+ "module": "ESNext",
6
+ "lib": ["ES2022", "DOM", "DOM.Iterable"],
7
+ "types": ["vite/client", "vitest/globals", "@testing-library/jest-dom"],
8
+ "skipLibCheck": true,
9
+
10
+ /* Bundler mode */
11
+ "moduleResolution": "bundler",
12
+ "allowImportingTsExtensions": true,
13
+ "verbatimModuleSyntax": true,
14
+ "moduleDetection": "force",
15
+ "noEmit": true,
16
+
17
+ /* Linting */
18
+ "strict": true,
19
+ "noUnusedLocals": true,
20
+ "noUnusedParameters": true,
21
+ "erasableSyntaxOnly": true,
22
+ "noFallthroughCasesInSwitch": true,
23
+ "noUncheckedSideEffectImports": true
24
+ },
25
+ "include": ["src"]
26
+ }
package/vite.config.ts ADDED
@@ -0,0 +1,18 @@
1
+ /// <reference types="vitest/config" />
2
+ import { defineConfig } from 'vite';
3
+ import dts from 'vite-plugin-dts';
4
+
5
+ export default defineConfig({
6
+ build: {
7
+ lib: {
8
+ entry: 'src/index.ts',
9
+ name: 'index',
10
+ fileName: 'index',
11
+ },
12
+ },
13
+ plugins: [dts()],
14
+ test: {
15
+ environment: 'jsdom',
16
+ setupFiles: ['./testSetup.ts'],
17
+ },
18
+ });