@mxenabled/web-connect-widget-sdk 0.0.2 → 0.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 ADDED
@@ -0,0 +1,25 @@
1
+ # MX Web Connect Widget SDK
2
+
3
+ ## Purpose
4
+
5
+ The purpose of this project is to be able to easily integrate the MX connect widget into a web app.
6
+
7
+ ## Implementation guide
8
+
9
+ The implementation guide lives in the MX docs [here](Add something here when it exists).
10
+
11
+ ## How it works
12
+
13
+ This package mounts an connect widget iframe to the DOM, listens for post messages, and provides callbacks for handling MX events.
14
+
15
+ ## API Documentation
16
+
17
+ The api documentation is [here](./API.md)
18
+
19
+ ## Contributing
20
+
21
+ Read the [contributing guide](./CONTRIBUTING.md) to learn about the development process.
22
+
23
+ ## License
24
+
25
+ This project is lincensed under the terms of the [MIT license](LICENSE).
@@ -1,9 +1,11 @@
1
+ import { Event } from './consts';
1
2
  interface ConnectWidgetProps {
2
3
  containerSelector: string;
3
4
  iframeProps?: Record<string, unknown>;
5
+ onEvent: (event: Event) => void;
4
6
  url: string;
5
7
  }
6
- export declare const ConnectWidget: ({ containerSelector, iframeProps, url, }: ConnectWidgetProps) => {
8
+ export declare const ConnectWidget: ({ containerSelector, iframeProps, onEvent, url, }: ConnectWidgetProps) => {
7
9
  mount: () => void;
8
10
  unmount: () => void;
9
11
  };
@@ -0,0 +1,4 @@
1
+ export type Event = {
2
+ metadata: Record<string, unknown>;
3
+ type: string;
4
+ };
package/dist/index.d.ts CHANGED
@@ -1 +1,2 @@
1
1
  export { ConnectWidget } from './ConnectWidget';
2
+ export type { Event } from './consts';
package/dist/index.js CHANGED
@@ -1,30 +1,37 @@
1
- const m = ({
2
- containerSelector: n,
3
- iframeProps: o,
4
- url: s
1
+ const g = ({
2
+ containerSelector: s,
3
+ iframeProps: i,
4
+ onEvent: a,
5
+ url: o
5
6
  }) => {
6
- const t = document.createElement("iframe"), { style: i, ...c } = o || {}, a = {
7
- height: "100%",
8
- width: "100%",
9
- ...i ?? {}
7
+ const t = document.createElement("iframe"), { style: c, ...d } = i || {}, m = c || { height: "100%", width: "100%" };
8
+ Object.assign(t.style, m);
9
+ for (const [e, n] of Object.entries(d))
10
+ e.startsWith("data-") ? t.setAttribute(e, String(n)) : Object.assign(t, { [e]: n });
11
+ t.src = o;
12
+ const r = (e) => {
13
+ if (e.origin !== new URL(o).origin)
14
+ return;
15
+ const { data: n } = e, { metadata: f, type: u } = n;
16
+ a({
17
+ metadata: f,
18
+ type: u
19
+ });
10
20
  };
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, {
21
+ return {
15
22
  mount: () => {
16
- const e = document.querySelector(n);
23
+ const e = document.querySelector(s);
17
24
  if (!e)
18
25
  throw new Error(
19
- `Container with selector "${n}" not found.`
26
+ `Container with selector "${s}" not found.`
20
27
  );
21
- e.appendChild(t);
28
+ e.appendChild(t), window.addEventListener("message", r);
22
29
  },
23
30
  unmount: () => {
24
- t.remove();
31
+ t.remove(), window.removeEventListener("message", r);
25
32
  }
26
33
  };
27
34
  };
28
35
  export {
29
- m as ConnectWidget
36
+ g as ConnectWidget
30
37
  };
@@ -1 +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"})}));
1
+ (function(t,o){typeof exports=="object"&&typeof module<"u"?o(exports):typeof define=="function"&&define.amd?define(["exports"],o):(t=typeof globalThis<"u"?globalThis:t||self,o(t.index={}))})(this,(function(t){"use strict";const o=({containerSelector:s,iframeProps:a,onEvent:c,url:r})=>{const n=document.createElement("iframe"),{style:f,...u}=a||{},m=f||{height:"100%",width:"100%"};Object.assign(n.style,m);for(const[e,i]of Object.entries(u))e.startsWith("data-")?n.setAttribute(e,String(i)):Object.assign(n,{[e]:i});n.src=r;const d=e=>{if(e.origin!==new URL(r).origin)return;const{data:i}=e,{metadata:l,type:g}=i;c({metadata:l,type:g})};return{mount:()=>{const e=document.querySelector(s);if(!e)throw new Error(`Container with selector "${s}" not found.`);e.appendChild(n),window.addEventListener("message",d)},unmount:()=>{n.remove(),window.removeEventListener("message",d)}}};t.ConnectWidget=o,Object.defineProperty(t,Symbol.toStringTag,{value:"Module"})}));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mxenabled/web-connect-widget-sdk",
3
- "version": "0.0.2",
3
+ "version": "0.0.4",
4
4
  "description": "MX Connect Web Widget SDK",
5
5
  "files": [
6
6
  "dist"