@aikaara/chat-sdk 1.4.0 → 1.4.2
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/dist/{AikaaraLinkButton--t5yyst9.mjs → AikaaraLinkButton-B5WyXn2z.mjs} +1 -1
- package/dist/{AikaaraLinkButton-DtbxlRUu.cjs → AikaaraLinkButton-CrvWSz7J.cjs} +1 -1
- package/dist/AikaaraPaymentLink-BJ3AyrtO.cjs +1 -0
- package/dist/{AikaaraPaymentLink-BuQX9XAE.mjs → AikaaraPaymentLink-BO_xsu0g.mjs} +62 -62
- package/dist/{MountTenant-xtZIgPSM.mjs → MountTenant-Yjsr4BIJ.mjs} +79 -78
- package/dist/{MountTenant-DUSZye2K.cjs → MountTenant-h3MfJKlg.cjs} +8 -8
- package/dist/cdn/aikaara-chat.iife.js +64 -64
- package/dist/headless.cjs +1 -1
- package/dist/headless.d.ts +2 -0
- package/dist/headless.mjs +2 -2
- package/dist/index.cjs +1 -1
- package/dist/index.d.ts +2 -0
- package/dist/index.mjs +2 -2
- package/dist/ui.cjs +1 -1
- package/dist/ui.mjs +1 -1
- package/package.json +1 -1
- package/dist/AikaaraPaymentLink-BlxQSATl.cjs +0 -1
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const p=require("./MountTenant-
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const p=require("./MountTenant-h3MfJKlg.cjs");class l extends HTMLElement{shadow;payload=null;constructor(){super(),this.shadow=this.attachShadow({mode:"open"})}connectedCallback(){this.render()}setPayload(e){this.payload=e,this.render()}render(){const e=this.payload;this.shadow.innerHTML=`
|
|
2
2
|
<style>
|
|
3
3
|
:host { display: block; margin-top: 8px; }
|
|
4
4
|
button {
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const y="https://checkout.razorpay.com/v1/checkout.js";let u=null;function f(){return window}class h extends HTMLElement{shadow;payloadData=[];message="";paidIdx={};constructor(){super(),this.shadow=this.attachShadow({mode:"open"})}setPayload(r,t){this.payloadData=Array.isArray(r)?r:[],this.message=t??"",this.render()}render(){const r=this.payloadData.filter(e=>!!e&&typeof e=="object"&&e.type==="link"&&typeof e.url=="string"),t=r.map((e,n)=>{const i=e.name||"Open link",o=!!this.paidIdx[n];return`<button class="link${o?" paid":""}" data-i="${n}" type="button"${o?" disabled":""}><span class="lbl">${k(o?"Paid":i)}</span>`+(o?'<svg class="icon" viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M3 8.5 L7 12 L13 5"/></svg>':'<svg class="icon" viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="1.6" stroke-linecap="round" stroke-linejoin="round"><path d="M5 11 L11 5 M6 5 H11 V10"/></svg>')+"</button>"}).join("");this.shadow.innerHTML="<style>:host { display:block; margin:6px 0; font-family:inherit; }.bubble { padding:12px 16px; border-radius:14px; background:var(--aikaara-bot-bubble-bg, #d8e5f5); color:var(--aikaara-bot-bubble-text, #1a2845); font-size:14px; line-height:1.55; margin-bottom:10px; }.links { display:flex; flex-direction:column; gap:8px; }.link { display:inline-flex; align-items:center; justify-content:center; gap:8px; padding:11px 22px; border:1.5px solid var(--aikaara-primary, #1849a9); background:var(--aikaara-primary, #1849a9); color:var(--aikaara-primary-contrast, #fff); border-radius:24px; font-size:14px; font-weight:600; cursor:pointer; font-family:inherit; text-decoration:none; transition: filter 120ms; width:150px; align-self:flex-start; }.link:hover:not(:disabled) { filter: brightness(0.94); }.link.paid, .link:disabled { background:#e7f5ec; color:#0e7c3a; border-color:#0e7c3a; cursor:default; }.icon { width:13px; height:13px; }</style>"+(this.message?`<div class="bubble">${this.message}</div>`:"")+`<div class="links">${t}</div>`,this.shadow.querySelectorAll(".link").forEach(e=>{e.addEventListener("click",()=>{if(e.disabled)return;const n=Number(e.dataset.i||0),i=r[n];i&&this.handleClick(n,i)})})}handleClick(r,t){const e=b(t),n=f().__aikaara_descriptor__?.razorpay;if(!e||!n?.keyId){_(t.url,t.name||"Pay"),this.dispatchEvent(new CustomEvent("template-action",{detail:{text:t.name||"link-click",attributes:{action:{type:"link",url:t.url,orderId:e||t.orderId,openedIn:"modal"}}},bubbles:!0,composed:!0}));return}w(n.preferredBanksUrl,e,n.preferredBanksMethod,n.preferredBanksHeaders).catch(i=>(console.warn("[payment_link] preferred-banks fetch failed; continuing with default UI",i),[])).then(i=>g().then(()=>this.openRazorpay(r,e,n,i))).catch(i=>{console.error("[payment_link] Razorpay launch failed",i)})}openRazorpay(r,t,e,n){const i=f(),o=i.__aikaara_runtime__?.identity??{},l={key:e.keyId,order_id:t,name:e.name||i.__aikaara_descriptor__?.title||"Payment",prefill:{},handler:()=>{this.paidIdx[r]=!0,this.render()},modal:{ondismiss:()=>{}}};typeof o.mobile=="string"?l.prefill.contact=o.mobile:typeof o.phone=="string"&&(l.prefill.contact=o.phone),typeof o.email=="string"&&(l.prefill.email=o.email),typeof o.name=="string"?l.prefill.name=o.name:typeof o.userName=="string"&&(l.prefill.name=o.userName),Array.isArray(n)&&n.length&&(l.config={display:{blocks:{banks:{name:"Preferred Netbanking",instruments:[{method:"netbanking",banks:n}]}},sequence:["block.banks","netbanking","card","upi"],preferences:{show_default_blocks:!0}}});const s=i.Razorpay;if(typeof s!="function")throw new Error("Razorpay Checkout script not available");const d=new s(l);d.on("payment.failed",p=>{console.warn("[payment_link] payment.failed",p?.error)}),d.open()}}function k(a){return String(a??"").replace(/[&<>]/g,r=>r==="&"?"&":r==="<"?"<":">")}function b(a){if(typeof a.orderId=="string"&&a.orderId)return a.orderId;try{const r=new URL(a.url,window.location.origin),t=r.searchParams.get("orderId")||r.searchParams.get("order_id");if(t)return t;if(r.hash&&r.hash.length>1){const e=new URLSearchParams(r.hash.replace(/^#/,"")),n=e.get("orderId")||e.get("order_id");if(n)return n}}catch{}return null}function g(){return typeof f().Razorpay=="function"?Promise.resolve():u||(u=new Promise((a,r)=>{const t=document.querySelector('script[data-aikaara-razorpay="1"]');if(t){t.addEventListener("load",()=>a()),t.addEventListener("error",()=>r(new Error("checkout.js failed to load")));return}const e=document.createElement("script");e.src=y,e.async=!0,e.dataset.aikaaraRazorpay="1",e.onload=()=>a(),e.onerror=()=>{u=null,r(new Error("checkout.js failed to load"))},document.head.appendChild(e)}),u)}function w(a,r,t,e){if(!a)return Promise.resolve([]);const n=String(t||"GET").toUpperCase()==="POST"?"POST":"GET",i=a.includes("{orderId}")?a.replace("{orderId}",encodeURIComponent(r)):a+(a.includes("?")?"&":"?")+"orderId="+encodeURIComponent(r),o=f().__aikaara_runtime__??{};return(typeof o.getSessionToken=="function"?o.getSessionToken():typeof o.getChatJwt=="function"?o.getChatJwt():Promise.resolve(null)).then(s=>{const d={Accept:"application/json",...e??{}};s&&(d.Authorization=`Bearer ${s}`);const p={method:n,headers:d,credentials:"omit"};return n==="POST"&&(d["Content-Type"]="application/json",p.body=JSON.stringify({orderId:r})),fetch(i,p)}).then(s=>{if(!s.ok)throw new Error(`preferred-banks ${s.status}`);return s.json()}).then(s=>{const d=s;return(Array.isArray(s)?s:Array.isArray(d?.banks)?d.banks:Array.isArray(d?.data)?d.data:Array.isArray(d?.data?.banks)?d.data.banks:[]).map(c=>{if(typeof c=="string")return c;if(c&&typeof c=="object"){const m=c;return m.code||m.bankCode||m.bank_code||null}return null}).filter(c=>!!c)})}function _(a,r){if(!a)return;let t=document.querySelector("aikaara-link-modal");t||(t=document.createElement("aikaara-link-modal"),document.body.appendChild(t)),typeof t.show=="function"?t.show(a,r):window.open(a,"_blank","noopener,noreferrer")}function x(){typeof customElements>"u"||customElements.get("aikaara-template-payment-link")||customElements.define("aikaara-template-payment-link",h)}exports.AikaaraPaymentLink=h;exports.registerAikaaraPaymentLink=x;
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
const
|
|
2
|
-
let
|
|
3
|
-
function
|
|
1
|
+
const m = "https://checkout.razorpay.com/v1/checkout.js";
|
|
2
|
+
let u = null;
|
|
3
|
+
function f() {
|
|
4
4
|
return window;
|
|
5
5
|
}
|
|
6
|
-
class
|
|
6
|
+
class y extends HTMLElement {
|
|
7
7
|
shadow;
|
|
8
8
|
payloadData = [];
|
|
9
9
|
message = "";
|
|
@@ -19,22 +19,22 @@ class m extends HTMLElement {
|
|
|
19
19
|
render() {
|
|
20
20
|
const r = this.payloadData.filter(
|
|
21
21
|
(e) => !!e && typeof e == "object" && e.type === "link" && typeof e.url == "string"
|
|
22
|
-
), t = r.map((e,
|
|
23
|
-
const i = e.name || "Open link",
|
|
24
|
-
return `<button class="link${
|
|
22
|
+
), t = r.map((e, n) => {
|
|
23
|
+
const i = e.name || "Open link", o = !!this.paidIdx[n];
|
|
24
|
+
return `<button class="link${o ? " paid" : ""}" data-i="${n}" type="button"${o ? " disabled" : ""}><span class="lbl">${k(o ? "Paid" : i)}</span>` + (o ? '<svg class="icon" viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M3 8.5 L7 12 L13 5"/></svg>' : '<svg class="icon" viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="1.6" stroke-linecap="round" stroke-linejoin="round"><path d="M5 11 L11 5 M6 5 H11 V10"/></svg>') + "</button>";
|
|
25
25
|
}).join("");
|
|
26
26
|
this.shadow.innerHTML = "<style>:host { display:block; margin:6px 0; font-family:inherit; }.bubble { padding:12px 16px; border-radius:14px; background:var(--aikaara-bot-bubble-bg, #d8e5f5); color:var(--aikaara-bot-bubble-text, #1a2845); font-size:14px; line-height:1.55; margin-bottom:10px; }.links { display:flex; flex-direction:column; gap:8px; }.link { display:inline-flex; align-items:center; justify-content:center; gap:8px; padding:11px 22px; border:1.5px solid var(--aikaara-primary, #1849a9); background:var(--aikaara-primary, #1849a9); color:var(--aikaara-primary-contrast, #fff); border-radius:24px; font-size:14px; font-weight:600; cursor:pointer; font-family:inherit; text-decoration:none; transition: filter 120ms; width:150px; align-self:flex-start; }.link:hover:not(:disabled) { filter: brightness(0.94); }.link.paid, .link:disabled { background:#e7f5ec; color:#0e7c3a; border-color:#0e7c3a; cursor:default; }.icon { width:13px; height:13px; }</style>" + (this.message ? `<div class="bubble">${this.message}</div>` : "") + `<div class="links">${t}</div>`, this.shadow.querySelectorAll(".link").forEach((e) => {
|
|
27
27
|
e.addEventListener("click", () => {
|
|
28
28
|
if (e.disabled) return;
|
|
29
|
-
const
|
|
30
|
-
i && this.handleClick(
|
|
29
|
+
const n = Number(e.dataset.i || 0), i = r[n];
|
|
30
|
+
i && this.handleClick(n, i);
|
|
31
31
|
});
|
|
32
32
|
});
|
|
33
33
|
}
|
|
34
34
|
handleClick(r, t) {
|
|
35
|
-
const e =
|
|
36
|
-
if (!e || !
|
|
37
|
-
|
|
35
|
+
const e = b(t), n = f().__aikaara_descriptor__?.razorpay;
|
|
36
|
+
if (!e || !n?.keyId) {
|
|
37
|
+
x(t.url, t.name || "Pay"), this.dispatchEvent(
|
|
38
38
|
new CustomEvent("template-action", {
|
|
39
39
|
detail: {
|
|
40
40
|
text: t.name || "link-click",
|
|
@@ -48,12 +48,12 @@ class m extends HTMLElement {
|
|
|
48
48
|
);
|
|
49
49
|
return;
|
|
50
50
|
}
|
|
51
|
-
|
|
51
|
+
w(n.preferredBanksUrl, e, n.preferredBanksMethod, n.preferredBanksHeaders).catch((i) => (console.warn("[payment_link] preferred-banks fetch failed; continuing with default UI", i), [])).then((i) => g().then(() => this.openRazorpay(r, e, n, i))).catch((i) => {
|
|
52
52
|
console.error("[payment_link] Razorpay launch failed", i);
|
|
53
53
|
});
|
|
54
54
|
}
|
|
55
|
-
openRazorpay(r, t, e,
|
|
56
|
-
const i =
|
|
55
|
+
openRazorpay(r, t, e, n) {
|
|
56
|
+
const i = f(), o = i.__aikaara_runtime__?.identity ?? {}, l = {
|
|
57
57
|
key: e.keyId,
|
|
58
58
|
order_id: t,
|
|
59
59
|
name: e.name || i.__aikaara_descriptor__?.title || "Payment",
|
|
@@ -68,88 +68,88 @@ class m extends HTMLElement {
|
|
|
68
68
|
}
|
|
69
69
|
}
|
|
70
70
|
};
|
|
71
|
-
typeof
|
|
71
|
+
typeof o.mobile == "string" ? l.prefill.contact = o.mobile : typeof o.phone == "string" && (l.prefill.contact = o.phone), typeof o.email == "string" && (l.prefill.email = o.email), typeof o.name == "string" ? l.prefill.name = o.name : typeof o.userName == "string" && (l.prefill.name = o.userName), Array.isArray(n) && n.length && (l.config = {
|
|
72
72
|
display: {
|
|
73
73
|
blocks: {
|
|
74
74
|
banks: {
|
|
75
75
|
name: "Preferred Netbanking",
|
|
76
|
-
instruments: [{ method: "netbanking", banks:
|
|
76
|
+
instruments: [{ method: "netbanking", banks: n }]
|
|
77
77
|
}
|
|
78
78
|
},
|
|
79
79
|
sequence: ["block.banks", "netbanking", "card", "upi"],
|
|
80
80
|
preferences: { show_default_blocks: !0 }
|
|
81
81
|
}
|
|
82
82
|
});
|
|
83
|
-
const
|
|
84
|
-
if (typeof
|
|
83
|
+
const s = i.Razorpay;
|
|
84
|
+
if (typeof s != "function")
|
|
85
85
|
throw new Error("Razorpay Checkout script not available");
|
|
86
|
-
const
|
|
87
|
-
|
|
88
|
-
console.warn("[payment_link] payment.failed",
|
|
89
|
-
}),
|
|
86
|
+
const d = new s(l);
|
|
87
|
+
d.on("payment.failed", (p) => {
|
|
88
|
+
console.warn("[payment_link] payment.failed", p?.error);
|
|
89
|
+
}), d.open();
|
|
90
90
|
}
|
|
91
91
|
}
|
|
92
|
-
function
|
|
93
|
-
return String(
|
|
92
|
+
function k(a) {
|
|
93
|
+
return String(a ?? "").replace(/[&<>]/g, (r) => r === "&" ? "&" : r === "<" ? "<" : ">");
|
|
94
94
|
}
|
|
95
|
-
function
|
|
96
|
-
if (typeof
|
|
95
|
+
function b(a) {
|
|
96
|
+
if (typeof a.orderId == "string" && a.orderId) return a.orderId;
|
|
97
97
|
try {
|
|
98
|
-
const r = new URL(
|
|
98
|
+
const r = new URL(a.url, window.location.origin), t = r.searchParams.get("orderId") || r.searchParams.get("order_id");
|
|
99
99
|
if (t) return t;
|
|
100
100
|
if (r.hash && r.hash.length > 1) {
|
|
101
|
-
const e = new URLSearchParams(r.hash.replace(/^#/, "")),
|
|
102
|
-
if (
|
|
101
|
+
const e = new URLSearchParams(r.hash.replace(/^#/, "")), n = e.get("orderId") || e.get("order_id");
|
|
102
|
+
if (n) return n;
|
|
103
103
|
}
|
|
104
104
|
} catch {
|
|
105
105
|
}
|
|
106
106
|
return null;
|
|
107
107
|
}
|
|
108
|
-
function
|
|
109
|
-
return typeof
|
|
108
|
+
function g() {
|
|
109
|
+
return typeof f().Razorpay == "function" ? Promise.resolve() : u || (u = new Promise((a, r) => {
|
|
110
110
|
const t = document.querySelector('script[data-aikaara-razorpay="1"]');
|
|
111
111
|
if (t) {
|
|
112
|
-
t.addEventListener("load", () =>
|
|
112
|
+
t.addEventListener("load", () => a()), t.addEventListener("error", () => r(new Error("checkout.js failed to load")));
|
|
113
113
|
return;
|
|
114
114
|
}
|
|
115
115
|
const e = document.createElement("script");
|
|
116
|
-
e.src =
|
|
117
|
-
|
|
116
|
+
e.src = m, e.async = !0, e.dataset.aikaaraRazorpay = "1", e.onload = () => a(), e.onerror = () => {
|
|
117
|
+
u = null, r(new Error("checkout.js failed to load"));
|
|
118
118
|
}, document.head.appendChild(e);
|
|
119
|
-
}),
|
|
119
|
+
}), u);
|
|
120
120
|
}
|
|
121
|
-
function
|
|
122
|
-
if (!
|
|
123
|
-
const
|
|
124
|
-
return (typeof
|
|
125
|
-
const d = { Accept: "application/json" };
|
|
126
|
-
|
|
127
|
-
const
|
|
128
|
-
return
|
|
129
|
-
}).then((
|
|
130
|
-
if (!
|
|
131
|
-
return
|
|
132
|
-
}).then((
|
|
133
|
-
const d =
|
|
134
|
-
return (Array.isArray(
|
|
135
|
-
if (typeof
|
|
136
|
-
if (
|
|
137
|
-
const
|
|
138
|
-
return
|
|
121
|
+
function w(a, r, t, e) {
|
|
122
|
+
if (!a) return Promise.resolve([]);
|
|
123
|
+
const n = String(t || "GET").toUpperCase() === "POST" ? "POST" : "GET", i = a.includes("{orderId}") ? a.replace("{orderId}", encodeURIComponent(r)) : a + (a.includes("?") ? "&" : "?") + "orderId=" + encodeURIComponent(r), o = f().__aikaara_runtime__ ?? {};
|
|
124
|
+
return (typeof o.getSessionToken == "function" ? o.getSessionToken() : typeof o.getChatJwt == "function" ? o.getChatJwt() : Promise.resolve(null)).then((s) => {
|
|
125
|
+
const d = { Accept: "application/json", ...e ?? {} };
|
|
126
|
+
s && (d.Authorization = `Bearer ${s}`);
|
|
127
|
+
const p = { method: n, headers: d, credentials: "omit" };
|
|
128
|
+
return n === "POST" && (d["Content-Type"] = "application/json", p.body = JSON.stringify({ orderId: r })), fetch(i, p);
|
|
129
|
+
}).then((s) => {
|
|
130
|
+
if (!s.ok) throw new Error(`preferred-banks ${s.status}`);
|
|
131
|
+
return s.json();
|
|
132
|
+
}).then((s) => {
|
|
133
|
+
const d = s;
|
|
134
|
+
return (Array.isArray(s) ? s : Array.isArray(d?.banks) ? d.banks : Array.isArray(d?.data) ? d.data : Array.isArray(d?.data?.banks) ? d.data.banks : []).map((c) => {
|
|
135
|
+
if (typeof c == "string") return c;
|
|
136
|
+
if (c && typeof c == "object") {
|
|
137
|
+
const h = c;
|
|
138
|
+
return h.code || h.bankCode || h.bank_code || null;
|
|
139
139
|
}
|
|
140
140
|
return null;
|
|
141
|
-
}).filter((
|
|
141
|
+
}).filter((c) => !!c);
|
|
142
142
|
});
|
|
143
143
|
}
|
|
144
|
-
function
|
|
145
|
-
if (!
|
|
144
|
+
function x(a, r) {
|
|
145
|
+
if (!a) return;
|
|
146
146
|
let t = document.querySelector("aikaara-link-modal");
|
|
147
|
-
t || (t = document.createElement("aikaara-link-modal"), document.body.appendChild(t)), typeof t.show == "function" ? t.show(
|
|
147
|
+
t || (t = document.createElement("aikaara-link-modal"), document.body.appendChild(t)), typeof t.show == "function" ? t.show(a, r) : window.open(a, "_blank", "noopener,noreferrer");
|
|
148
148
|
}
|
|
149
|
-
function
|
|
150
|
-
typeof customElements > "u" || customElements.get("aikaara-template-payment-link") || customElements.define("aikaara-template-payment-link",
|
|
149
|
+
function _() {
|
|
150
|
+
typeof customElements > "u" || customElements.get("aikaara-template-payment-link") || customElements.define("aikaara-template-payment-link", y);
|
|
151
151
|
}
|
|
152
152
|
export {
|
|
153
|
-
|
|
154
|
-
|
|
153
|
+
y as AikaaraPaymentLink,
|
|
154
|
+
_ as registerAikaaraPaymentLink
|
|
155
155
|
};
|