@lvble/core 2.0.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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) [2023] [Ignacio Andrés Miranda Figueroa]
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, 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,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,115 @@
1
+ # @lvble/core
2
+
3
+ **@lvble/core** is a JavaScript package that provides a set of core functionalities for building interactive web applications with the lvble platform. It includes widgets and popups.
4
+
5
+ ## ⚡️ Quick start
6
+
7
+ ### NPM
8
+
9
+ You can install **@lvble/core** using npm (Node Package Manager). Make sure you have Node.js and npm installed on your machine. Open your terminal or command prompt and run the following command:
10
+
11
+ ```bash
12
+ npm install @lvble/core
13
+ ```
14
+
15
+ In your `index.html`:
16
+
17
+ ```html
18
+ <html>
19
+ <head>
20
+ <title>PMS</title>
21
+ </head>
22
+
23
+ <body>
24
+ <h1>Welcome to the best PMS ever!</h1>
25
+ <table style="width: 50%; margin: 0 auto;">
26
+ <tr>
27
+ <th>Lvble</th>
28
+ </tr>
29
+ <tr>
30
+ <td><button onclick="openLvbleExperience()">Lvble</button></td>
31
+ </tr>
32
+ <tr>
33
+ <td>Status</td>
34
+ </tr>
35
+ </table>
36
+ <script type="module" src="/main.js"></script>
37
+ </body>
38
+ </html>
39
+ ```
40
+
41
+ And in your `main.js` file:
42
+
43
+ ```javascript
44
+ import { Lvble } from "@lvble/core";
45
+ // Widgets
46
+ const l = Lvble({
47
+ environment: "sandbox",
48
+ token: "token.",
49
+ });
50
+ const lvbleWidget = l.createWidget({
51
+ mode: "onboarding",
52
+ onEvent: function (eventType: string, data: any) {
53
+ switch (eventType) {
54
+ case "EXPERIENCE_OPENED":
55
+ ...
56
+ break;
57
+ case "EXPERIENCE_CLOSED":
58
+ ...
59
+ break;
60
+ ...
61
+ default:
62
+ break;
63
+ }
64
+ }
65
+ });
66
+
67
+ document
68
+ .getElementById("lvble-widget")
69
+ .appendChild(lvbleWidget);
70
+
71
+ // Lvble experience
72
+ const lvbleExperience = Lvble({
73
+ environment: "sandbox",
74
+ token: "token",
75
+ });
76
+
77
+ const openLvbleExperience = () =>
78
+ lvbleExperience.open({
79
+ mode: "onboarding",
80
+ onEvent: function (eventType: string, data: any) {
81
+ switch (eventType) {
82
+ case "EXPERIENCE_OPENED":
83
+ ...
84
+ break;
85
+ case "EXPERIENCE_CLOSED":
86
+ ...
87
+ break;
88
+ ...
89
+ default:
90
+ break;
91
+ }
92
+ }
93
+ });
94
+
95
+ ```
96
+
97
+ ### `<script>` tag
98
+
99
+ Alternatively, you can include **@lvble/core** directly in your HTML file using a script tag like it's 1997 😎
100
+ Add the following line inside the `<head>` or at the end of the `<body>` tag:
101
+
102
+ ```html
103
+ <script src="https://unpkg.com/@lvble/core"></script>
104
+ ```
105
+
106
+ Please refer to the documentation of **@lvble/core** for a complete list of available functionalities and their usage instructions.
107
+
108
+ ## Kudos
109
+
110
+ [This template](https://github.com/IgnacioNMiranda/vite-component-library-template)
111
+ [Ignacio Miranda Figueroa](https://www.linkedin.com/in/ignacio-miranda-figueroa/)
112
+
113
+ ## License
114
+
115
+ [MIT](LICENSE)
@@ -0,0 +1,119 @@
1
+ var f = Object.defineProperty;
2
+ var p = (e, o, t) => o in e ? f(e, o, { enumerable: !0, configurable: !0, writable: !0, value: t }) : e[o] = t;
3
+ var l = (e, o, t) => (p(e, typeof o != "symbol" ? o + "" : o, t), t);
4
+ var k = /* @__PURE__ */ ((e) => (e.Local = "local", e.Sandbox = "sandbox", e.Production = "production", e))(k || {});
5
+ const h = {
6
+ local: "http://localhost:3001",
7
+ sandbox: "https://widget.sandbox.pms.nowlvble.com",
8
+ production: "https://api.production.partners.nowlvble.com"
9
+ }, d = {
10
+ local: "http://localhost:3001",
11
+ sandbox: "https://experience.sandbox.pms.nowlvble.com",
12
+ production: "https://api.production.partners.nowlvble.com"
13
+ };
14
+ class y extends HTMLElement {
15
+ constructor() {
16
+ super();
17
+ l(this, "_typeToEvent", {
18
+ onboarding: "finishOnboarding",
19
+ offboarding: "finishOffboarding",
20
+ split: "finishSplit",
21
+ repay: "finishRepay"
22
+ /* FinishRepay */
23
+ });
24
+ l(this, "_iframe");
25
+ this.attachShadow({ mode: "open" });
26
+ }
27
+ get mode() {
28
+ return this.getAttribute("mode");
29
+ }
30
+ set mode(t) {
31
+ t ? this.setAttribute("mode", t) : this.removeAttribute("mode");
32
+ }
33
+ get environment() {
34
+ return this.getAttribute("environment");
35
+ }
36
+ set environment(t) {
37
+ t ? this.setAttribute("environment", t) : this.removeAttribute("environment");
38
+ }
39
+ get token() {
40
+ return this.getAttribute("token");
41
+ }
42
+ set token(t) {
43
+ t ? this.setAttribute("token", t) : this.removeAttribute("token");
44
+ }
45
+ connectedCallback() {
46
+ var r;
47
+ const t = `${h[this.environment]}?token=${this.token}&environment=${this.environment}`, n = document.createElement("iframe");
48
+ n.src = t, n.width = "100%", n.height = "100%", n.style.borderStyle = "solid", n.style.borderRadius = "10px", n.style.borderColor = "transparent", this._iframe = n, (r = this.shadowRoot) == null || r.appendChild(n);
49
+ }
50
+ disconnectedCallback() {
51
+ this.shadowRoot && (this.shadowRoot.innerHTML = "");
52
+ }
53
+ }
54
+ customElements.get("lvble-widget") ?? customElements.define("lvble-widget", y);
55
+ const $ = {
56
+ onboarding: customElements.get("lvble-widget"),
57
+ repay: customElements.get("lvble-widget")
58
+ }, E = (e) => ({
59
+ /**
60
+ * This function creates a widget that can be embedded in your website.
61
+ *
62
+ * @param createOptions The options for creating the widget. See CreateWidgetOptions for more information.
63
+ * @returns The widget.
64
+ */
65
+ // TODO: Add support for no mode
66
+ createWidget: (o) => {
67
+ const t = o.mode ? new $[o.mode]() : new (customElements.get(
68
+ "lvble-widget"
69
+ ))();
70
+ t.environment = e.environment, t.token = e.token, t.mode = o.mode;
71
+ const n = (r) => {
72
+ if (r.origin != h[e.environment]) {
73
+ console.debug(
74
+ `Received message from unknown origin: ${r.origin}`
75
+ );
76
+ return;
77
+ }
78
+ const s = r.data;
79
+ o.onEvent(s.eventType, s);
80
+ };
81
+ return window.addEventListener("message", n), t;
82
+ },
83
+ /**
84
+ * This function opens a popup with the relevant mode.
85
+ * @param openOptions The options for opening the widget. See OpenOptions for more information.
86
+ * @returns undefined.
87
+ */
88
+ open: (o) => {
89
+ const t = {
90
+ onboarding: `${d[e.environment]}?token=${e.token}`,
91
+ offboarding: `${d[e.environment]}?token=${e.token}`,
92
+ split: `${d[e.environment]}?token=${e.token}`,
93
+ repay: `${d[e.environment]}?token=${e.token}`
94
+ }, n = o.mode ? t[o.mode] : "", r = 450, s = 800, b = screen.width / 2 - r / 2, g = screen.height / 2 - s / 2;
95
+ window.open(
96
+ n,
97
+ "LvblePopup",
98
+ "width=" + r + ",height=" + s + ",location=no,left=" + b + ",top=" + g
99
+ );
100
+ const v = (i) => {
101
+ if (i.origin != d[e.environment]) {
102
+ console.debug(
103
+ `Received message from unknown origin: ${i.origin}`
104
+ );
105
+ return;
106
+ }
107
+ const a = i.data, u = document.querySelectorAll("lvble-widget");
108
+ i = JSON.parse(JSON.stringify(i)), u.forEach((w) => {
109
+ var c, m;
110
+ (m = ((c = w.shadowRoot) == null ? void 0 : c.querySelector("iframe")).contentWindow) == null || m.postMessage(i, "*");
111
+ }), o.onEvent(a.eventType, a);
112
+ };
113
+ window.addEventListener("message", v);
114
+ }
115
+ }), A = E;
116
+ export {
117
+ k as Environment,
118
+ A as Lvble
119
+ };
@@ -0,0 +1 @@
1
+ (function(o,n){typeof exports=="object"&&typeof module<"u"?n(exports):typeof define=="function"&&define.amd?define(["exports"],n):(o=typeof globalThis<"u"?globalThis:o||self,n(o["@lvble/core"]={}))})(this,function(o){"use strict";var $=Object.defineProperty;var x=(o,n,d)=>n in o?$(o,n,{enumerable:!0,configurable:!0,writable:!0,value:d}):o[n]=d;var m=(o,n,d)=>(x(o,typeof n!="symbol"?n+"":n,d),d);var n=(e=>(e.Local="local",e.Sandbox="sandbox",e.Production="production",e))(n||{});const d={local:"http://localhost:3001",sandbox:"https://widget.sandbox.pms.nowlvble.com",production:"https://api.production.partners.nowlvble.com"},c={local:"http://localhost:3001",sandbox:"https://experience.sandbox.pms.nowlvble.com",production:"https://api.production.partners.nowlvble.com"};class v extends HTMLElement{constructor(){super();m(this,"_typeToEvent",{onboarding:"finishOnboarding",offboarding:"finishOffboarding",split:"finishSplit",repay:"finishRepay"});m(this,"_iframe");this.attachShadow({mode:"open"})}get mode(){return this.getAttribute("mode")}set mode(t){t?this.setAttribute("mode",t):this.removeAttribute("mode")}get environment(){return this.getAttribute("environment")}set environment(t){t?this.setAttribute("environment",t):this.removeAttribute("environment")}get token(){return this.getAttribute("token")}set token(t){t?this.setAttribute("token",t):this.removeAttribute("token")}connectedCallback(){var s;const t=`${d[this.environment]}?token=${this.token}&environment=${this.environment}`,r=document.createElement("iframe");r.src=t,r.width="100%",r.height="100%",r.style.borderStyle="solid",r.style.borderRadius="10px",r.style.borderColor="transparent",this._iframe=r,(s=this.shadowRoot)==null||s.appendChild(r)}disconnectedCallback(){this.shadowRoot&&(this.shadowRoot.innerHTML="")}}customElements.get("lvble-widget")??customElements.define("lvble-widget",v);const g={onboarding:customElements.get("lvble-widget"),repay:customElements.get("lvble-widget")},f=e=>({createWidget:i=>{const t=i.mode?new g[i.mode]:new(customElements.get("lvble-widget"));t.environment=e.environment,t.token=e.token,t.mode=i.mode;const r=s=>{if(s.origin!=d[e.environment]){console.debug(`Received message from unknown origin: ${s.origin}`);return}const a=s.data;i.onEvent(a.eventType,a)};return window.addEventListener("message",r),t},open:i=>{const t={onboarding:`${c[e.environment]}?token=${e.token}`,offboarding:`${c[e.environment]}?token=${e.token}`,split:`${c[e.environment]}?token=${e.token}`,repay:`${c[e.environment]}?token=${e.token}`},r=i.mode?t[i.mode]:"",s=450,a=800,p=screen.width/2-s/2,w=screen.height/2-a/2;window.open(r,"LvblePopup","width="+s+",height="+a+",location=no,left="+p+",top="+w);const k=l=>{if(l.origin!=c[e.environment]){console.debug(`Received message from unknown origin: ${l.origin}`);return}const h=l.data,y=document.querySelectorAll("lvble-widget");l=JSON.parse(JSON.stringify(l)),y.forEach(E=>{var b,u;(u=((b=E.shadowRoot)==null?void 0:b.querySelector("iframe")).contentWindow)==null||u.postMessage(l,"*")}),i.onEvent(h.eventType,h)};window.addEventListener("message",k)}});o.Environment=n,o.Lvble=f,Object.defineProperty(o,Symbol.toStringTag,{value:"Module"})});
@@ -0,0 +1 @@
1
+ export * from './lib/index'
@@ -0,0 +1,2 @@
1
+ export * from './lvble';
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["index.ts"],"names":[],"mappings":"AAAA,cAAc,SAAS,CAAA"}
@@ -0,0 +1,93 @@
1
+ export declare enum Environment {
2
+ Local = "local",
3
+ Sandbox = "sandbox",
4
+ Production = "production"
5
+ }
6
+ export declare type Mode = "onboarding" | "offboarding" | "split" | "repay";
7
+ export declare type ErrorData = {
8
+ type: "error";
9
+ reason: string;
10
+ };
11
+ export declare type OnboardingData = ErrorData | {
12
+ type: "success";
13
+ status: string;
14
+ };
15
+ export declare type SplitData = ErrorData | {
16
+ type: "success";
17
+ external_id: string;
18
+ settlement_id: string;
19
+ amount: number;
20
+ };
21
+ export declare type CloseData = ErrorData | {
22
+ type: "close";
23
+ };
24
+ export declare type EventData = OnboardingData | SplitData | CloseData;
25
+ declare enum EventType {
26
+ FinishOnboarding = "finishOnboarding",
27
+ FinishOffboarding = "finishOffboarding",
28
+ FinishSplit = "finishSplit",
29
+ FinishRepay = "finishRepay"
30
+ }
31
+ export interface InitOptions {
32
+ environment: Environment;
33
+ token: string;
34
+ }
35
+ export interface OpenOptions {
36
+ mode?: Mode;
37
+ onEvent: (eventType: string, data: any) => void;
38
+ }
39
+ export interface CreateWidgetOptions extends OpenOptions {
40
+ mode?: Extract<Mode, "onboarding" | "repay">;
41
+ onEvent: (eventType: string, data: any) => void;
42
+ }
43
+ declare class LvbleWidget extends HTMLElement {
44
+ _typeToEvent: {
45
+ onboarding: EventType;
46
+ offboarding: EventType;
47
+ split: EventType;
48
+ repay: EventType;
49
+ };
50
+ _iframe?: HTMLIFrameElement;
51
+ constructor();
52
+ get mode(): Mode;
53
+ set mode(val: Mode | undefined);
54
+ get environment(): Environment;
55
+ set environment(val: Environment);
56
+ get token(): string;
57
+ set token(val: string);
58
+ connectedCallback(): void;
59
+ disconnectedCallback(): void;
60
+ }
61
+ declare const lvble: (initOptions: InitOptions) => {
62
+ /**
63
+ * This function creates a widget that can be embedded in your website.
64
+ *
65
+ * @param createOptions The options for creating the widget. See CreateWidgetOptions for more information.
66
+ * @returns The widget.
67
+ */
68
+ createWidget: (createOptions: CreateWidgetOptions) => LvbleWidget;
69
+ /**
70
+ * This function opens a popup with the relevant mode.
71
+ * @param openOptions The options for opening the widget. See OpenOptions for more information.
72
+ * @returns undefined.
73
+ */
74
+ open: (openOptions: OpenOptions) => void;
75
+ };
76
+ export declare type LvbleType = ReturnType<typeof lvble>;
77
+ export declare const Lvble: (initOptions: InitOptions) => {
78
+ /**
79
+ * This function creates a widget that can be embedded in your website.
80
+ *
81
+ * @param createOptions The options for creating the widget. See CreateWidgetOptions for more information.
82
+ * @returns The widget.
83
+ */
84
+ createWidget: (createOptions: CreateWidgetOptions) => LvbleWidget;
85
+ /**
86
+ * This function opens a popup with the relevant mode.
87
+ * @param openOptions The options for opening the widget. See OpenOptions for more information.
88
+ * @returns undefined.
89
+ */
90
+ open: (openOptions: OpenOptions) => void;
91
+ };
92
+ export {};
93
+ //# sourceMappingURL=lvble.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"lvble.d.ts","sourceRoot":"","sources":["lvble.ts"],"names":[],"mappings":"AAAA,oBAAY,WAAW;IACrB,KAAK,UAAU;IACf,OAAO,YAAY;IACnB,UAAU,eAAe;CAC1B;AAaD,oBAAY,IAAI,GAAG,YAAY,GAAG,aAAa,GAAG,OAAO,GAAG,OAAO,CAAC;AACpE,oBAAY,SAAS,GAAG;IACtB,IAAI,EAAE,OAAO,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;CAChB,CAAC;AACF,oBAAY,cAAc,GACtB,SAAS,GACT;IACE,IAAI,EAAE,SAAS,CAAC;IAChB,MAAM,EAAE,MAAM,CAAC;CAChB,CAAC;AACN,oBAAY,SAAS,GACjB,SAAS,GACT;IACE,IAAI,EAAE,SAAS,CAAC;IAChB,WAAW,EAAE,MAAM,CAAC;IACpB,aAAa,EAAE,MAAM,CAAC;IACtB,MAAM,EAAE,MAAM,CAAC;CAChB,CAAC;AACN,oBAAY,SAAS,GACjB,SAAS,GACT;IACE,IAAI,EAAE,OAAO,CAAC;CACf,CAAC;AAEN,oBAAY,SAAS,GAAG,cAAc,GAAG,SAAS,GAAG,SAAS,CAAC;AAE/D,aAAK,SAAS;IACZ,gBAAgB,qBAAqB;IACrC,iBAAiB,sBAAsB;IACvC,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.json ADDED
@@ -0,0 +1,37 @@
1
+ {
2
+ "name": "@lvble/core",
3
+ "private": false,
4
+ "version": "2.0.0",
5
+ "main": "./dist/@lvble/core.umd.js",
6
+ "module": "./dist/@lvble/core.es.js",
7
+ "types": "./dist/index.d.ts",
8
+ "exports": {
9
+ ".": {
10
+ "import": "./dist/@lvble/core.es.js",
11
+ "require": "./dist/@lvble/core.umd.js"
12
+ },
13
+ "./dist/style.css": "./dist/style.css"
14
+ },
15
+ "engines": {
16
+ "node": "16.18.1"
17
+ },
18
+ "scripts": {
19
+ "dev": "start-storybook -p 6006",
20
+ "build": "build-storybook",
21
+ "build:lib": "tsc && vite build --watch",
22
+ "lint:fix": "eslint --ext .js,.jsx,.ts,.tsx --fix",
23
+ "format:prettier": "prettier --write \"src/**/*.{ts,tsx,js,mdx}\"",
24
+ "test": "vitest",
25
+ "test:cov": "vitest run --coverage",
26
+ "prepack": "json -f package.json -I -e \"delete this.devDependencies; delete this.dependencies\""
27
+ },
28
+ "peerDependencies": {},
29
+ "files": [
30
+ "dist"
31
+ ],
32
+ "lint-staged": {
33
+ "*.{ts,tsx,js,jsx,json,css,md}": [
34
+ "prettier -w"
35
+ ]
36
+ }
37
+ }