@aikaara/chat-sdk 1.4.0 → 1.4.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.
- package/dist/{AikaaraLinkButton--t5yyst9.mjs → AikaaraLinkButton-7J4UqLKS.mjs} +1 -1
- package/dist/{AikaaraLinkButton-DtbxlRUu.cjs → AikaaraLinkButton-BAufu-ks.cjs} +1 -1
- package/dist/AikaaraPaymentLink-C8kp53Qy.cjs +1 -0
- package/dist/{AikaaraPaymentLink-BuQX9XAE.mjs → AikaaraPaymentLink-D4Q4HHQE.mjs} +48 -48
- package/dist/{MountTenant-xtZIgPSM.mjs → MountTenant-CKXpjcbJ.mjs} +79 -78
- package/dist/{MountTenant-DUSZye2K.cjs → MountTenant-D8Ku21tO.cjs} +8 -8
- package/dist/cdn/aikaara-chat.iife.js +5 -5
- package/dist/headless.cjs +1 -1
- package/dist/headless.mjs +2 -2
- package/dist/index.cjs +1 -1
- 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-D8Ku21tO.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 h="https://checkout.razorpay.com/v1/checkout.js";let p=null;function u(){return window}class m extends HTMLElement{shadow;payloadData=[];message="";paidIdx={};constructor(){super(),this.shadow=this.attachShadow({mode:"open"})}setPayload(t,r){this.payloadData=Array.isArray(t)?t:[],this.message=r??"",this.render()}render(){const t=this.payloadData.filter(e=>!!e&&typeof e=="object"&&e.type==="link"&&typeof e.url=="string"),r=t.map((e,a)=>{const o=e.name||"Open link",s=!!this.paidIdx[a];return`<button class="link${s?" paid":""}" data-i="${a}" type="button"${s?" disabled":""}><span class="lbl">${y(s?"Paid":o)}</span>`+(s?'<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">${r}</div>`,this.shadow.querySelectorAll(".link").forEach(e=>{e.addEventListener("click",()=>{if(e.disabled)return;const a=Number(e.dataset.i||0),o=t[a];o&&this.handleClick(a,o)})})}handleClick(t,r){const e=k(r),a=u().__aikaara_descriptor__?.razorpay;if(!e||!a?.keyId){w(r.url,r.name||"Pay"),this.dispatchEvent(new CustomEvent("template-action",{detail:{text:r.name||"link-click",attributes:{action:{type:"link",url:r.url,orderId:e||r.orderId,openedIn:"modal"}}},bubbles:!0,composed:!0}));return}g(a.preferredBanksUrl,e,a.preferredBanksMethod).catch(o=>(console.warn("[payment_link] preferred-banks fetch failed; continuing with default UI",o),[])).then(o=>b().then(()=>this.openRazorpay(t,e,a,o))).catch(o=>{console.error("[payment_link] Razorpay launch failed",o)})}openRazorpay(t,r,e,a){const o=u(),s=o.__aikaara_runtime__?.identity??{},i={key:e.keyId,order_id:r,name:e.name||o.__aikaara_descriptor__?.title||"Payment",prefill:{},handler:()=>{this.paidIdx[t]=!0,this.render()},modal:{ondismiss:()=>{}}};typeof s.mobile=="string"?i.prefill.contact=s.mobile:typeof s.phone=="string"&&(i.prefill.contact=s.phone),typeof s.email=="string"&&(i.prefill.email=s.email),typeof s.name=="string"?i.prefill.name=s.name:typeof s.userName=="string"&&(i.prefill.name=s.userName),Array.isArray(a)&&a.length&&(i.config={display:{blocks:{banks:{name:"Preferred Netbanking",instruments:[{method:"netbanking",banks:a}]}},sequence:["block.banks","netbanking","card","upi"],preferences:{show_default_blocks:!0}}});const d=o.Razorpay;if(typeof d!="function")throw new Error("Razorpay Checkout script not available");const c=new d(i);c.on("payment.failed",l=>{console.warn("[payment_link] payment.failed",l?.error)}),c.open()}}function y(n){return String(n??"").replace(/[&<>]/g,t=>t==="&"?"&":t==="<"?"<":">")}function k(n){if(typeof n.orderId=="string"&&n.orderId)return n.orderId;try{const t=new URL(n.url,window.location.origin),r=t.searchParams.get("orderId")||t.searchParams.get("order_id");if(r)return r;if(t.hash&&t.hash.length>1){const e=new URLSearchParams(t.hash.replace(/^#/,"")),a=e.get("orderId")||e.get("order_id");if(a)return a}}catch{}return null}function b(){return typeof u().Razorpay=="function"?Promise.resolve():p||(p=new Promise((n,t)=>{const r=document.querySelector('script[data-aikaara-razorpay="1"]');if(r){r.addEventListener("load",()=>n()),r.addEventListener("error",()=>t(new Error("checkout.js failed to load")));return}const e=document.createElement("script");e.src=h,e.async=!0,e.dataset.aikaaraRazorpay="1",e.onload=()=>n(),e.onerror=()=>{p=null,t(new Error("checkout.js failed to load"))},document.head.appendChild(e)}),p)}function g(n,t,r){if(!n)return Promise.resolve([]);const e=String(r||"GET").toUpperCase()==="POST"?"POST":"GET",a=n.includes("{orderId}")?n.replace("{orderId}",encodeURIComponent(t)):n+(n.includes("?")?"&":"?")+"orderId="+encodeURIComponent(t),o=u().__aikaara_runtime__??{};return(typeof o.getSessionToken=="function"?o.getSessionToken():typeof o.getChatJwt=="function"?o.getChatJwt():Promise.resolve(null)).then(i=>{const d={Accept:"application/json"};i&&(d.Authorization=`Bearer ${i}`);const c={method:e,headers:d,credentials:"omit"};return e==="POST"&&(d["Content-Type"]="application/json",c.body=JSON.stringify({orderId:t})),fetch(a,c)}).then(i=>{if(!i.ok)throw new Error(`preferred-banks ${i.status}`);return i.json()}).then(i=>{const d=i;return(Array.isArray(i)?i:Array.isArray(d?.banks)?d.banks:Array.isArray(d?.data)?d.data:Array.isArray(d?.data?.banks)?d.data.banks:[]).map(l=>{if(typeof l=="string")return l;if(l&&typeof l=="object"){const f=l;return f.code||f.bankCode||f.bank_code||null}return null}).filter(l=>!!l)})}function w(n,t){if(!n)return;let r=document.querySelector("aikaara-link-modal");r||(r=document.createElement("aikaara-link-modal"),document.body.appendChild(r)),typeof r.show=="function"?r.show(n,t):window.open(n,"_blank","noopener,noreferrer")}function _(){typeof customElements>"u"||customElements.get("aikaara-template-payment-link")||customElements.define("aikaara-template-payment-link",m)}exports.AikaaraPaymentLink=m;exports.registerAikaaraPaymentLink=_;
|
|
@@ -13,33 +13,33 @@ class m extends HTMLElement {
|
|
|
13
13
|
constructor() {
|
|
14
14
|
super(), this.shadow = this.attachShadow({ mode: "open" });
|
|
15
15
|
}
|
|
16
|
-
setPayload(
|
|
17
|
-
this.payloadData = Array.isArray(
|
|
16
|
+
setPayload(t, r) {
|
|
17
|
+
this.payloadData = Array.isArray(t) ? t : [], this.message = r ?? "", this.render();
|
|
18
18
|
}
|
|
19
19
|
render() {
|
|
20
|
-
const
|
|
20
|
+
const t = this.payloadData.filter(
|
|
21
21
|
(e) => !!e && typeof e == "object" && e.type === "link" && typeof e.url == "string"
|
|
22
|
-
),
|
|
23
|
-
const
|
|
24
|
-
return `<button class="link${s ? " paid" : ""}" data-i="${a}" type="button"${s ? " disabled" : ""}><span class="lbl">${y(s ? "Paid" :
|
|
22
|
+
), r = t.map((e, a) => {
|
|
23
|
+
const o = e.name || "Open link", s = !!this.paidIdx[a];
|
|
24
|
+
return `<button class="link${s ? " paid" : ""}" data-i="${a}" type="button"${s ? " disabled" : ""}><span class="lbl">${y(s ? "Paid" : o)}</span>` + (s ? '<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
|
-
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">${
|
|
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">${r}</div>`, this.shadow.querySelectorAll(".link").forEach((e) => {
|
|
27
27
|
e.addEventListener("click", () => {
|
|
28
28
|
if (e.disabled) return;
|
|
29
|
-
const a = Number(e.dataset.i || 0),
|
|
30
|
-
|
|
29
|
+
const a = Number(e.dataset.i || 0), o = t[a];
|
|
30
|
+
o && this.handleClick(a, o);
|
|
31
31
|
});
|
|
32
32
|
});
|
|
33
33
|
}
|
|
34
|
-
handleClick(
|
|
35
|
-
const e = k(
|
|
34
|
+
handleClick(t, r) {
|
|
35
|
+
const e = k(r), a = u().__aikaara_descriptor__?.razorpay;
|
|
36
36
|
if (!e || !a?.keyId) {
|
|
37
|
-
w(
|
|
37
|
+
w(r.url, r.name || "Pay"), this.dispatchEvent(
|
|
38
38
|
new CustomEvent("template-action", {
|
|
39
39
|
detail: {
|
|
40
|
-
text:
|
|
40
|
+
text: r.name || "link-click",
|
|
41
41
|
attributes: {
|
|
42
|
-
action: { type: "link", url:
|
|
42
|
+
action: { type: "link", url: r.url, orderId: e || r.orderId, openedIn: "modal" }
|
|
43
43
|
}
|
|
44
44
|
},
|
|
45
45
|
bubbles: !0,
|
|
@@ -48,18 +48,18 @@ class m extends HTMLElement {
|
|
|
48
48
|
);
|
|
49
49
|
return;
|
|
50
50
|
}
|
|
51
|
-
g(a.preferredBanksUrl, e, a.preferredBanksMethod).catch((
|
|
52
|
-
console.error("[payment_link] Razorpay launch failed",
|
|
51
|
+
g(a.preferredBanksUrl, e, a.preferredBanksMethod).catch((o) => (console.warn("[payment_link] preferred-banks fetch failed; continuing with default UI", o), [])).then((o) => b().then(() => this.openRazorpay(t, e, a, o))).catch((o) => {
|
|
52
|
+
console.error("[payment_link] Razorpay launch failed", o);
|
|
53
53
|
});
|
|
54
54
|
}
|
|
55
|
-
openRazorpay(
|
|
56
|
-
const
|
|
55
|
+
openRazorpay(t, r, e, a) {
|
|
56
|
+
const o = u(), s = o.__aikaara_runtime__?.identity ?? {}, i = {
|
|
57
57
|
key: e.keyId,
|
|
58
|
-
order_id:
|
|
59
|
-
name: e.name ||
|
|
58
|
+
order_id: r,
|
|
59
|
+
name: e.name || o.__aikaara_descriptor__?.title || "Payment",
|
|
60
60
|
prefill: {},
|
|
61
61
|
handler: () => {
|
|
62
|
-
this.paidIdx[
|
|
62
|
+
this.paidIdx[t] = !0, this.render();
|
|
63
63
|
},
|
|
64
64
|
modal: {
|
|
65
65
|
// No auto-hide on dismiss: user can re-click Pay Now. Per spec,
|
|
@@ -68,7 +68,7 @@ class m extends HTMLElement {
|
|
|
68
68
|
}
|
|
69
69
|
}
|
|
70
70
|
};
|
|
71
|
-
typeof s.mobile == "string" ?
|
|
71
|
+
typeof s.mobile == "string" ? i.prefill.contact = s.mobile : typeof s.phone == "string" && (i.prefill.contact = s.phone), typeof s.email == "string" && (i.prefill.email = s.email), typeof s.name == "string" ? i.prefill.name = s.name : typeof s.userName == "string" && (i.prefill.name = s.userName), Array.isArray(a) && a.length && (i.config = {
|
|
72
72
|
display: {
|
|
73
73
|
blocks: {
|
|
74
74
|
banks: {
|
|
@@ -80,25 +80,25 @@ class m extends HTMLElement {
|
|
|
80
80
|
preferences: { show_default_blocks: !0 }
|
|
81
81
|
}
|
|
82
82
|
});
|
|
83
|
-
const d =
|
|
83
|
+
const d = o.Razorpay;
|
|
84
84
|
if (typeof d != "function")
|
|
85
85
|
throw new Error("Razorpay Checkout script not available");
|
|
86
|
-
const c = new d(
|
|
86
|
+
const c = new d(i);
|
|
87
87
|
c.on("payment.failed", (l) => {
|
|
88
88
|
console.warn("[payment_link] payment.failed", l?.error);
|
|
89
89
|
}), c.open();
|
|
90
90
|
}
|
|
91
91
|
}
|
|
92
92
|
function y(n) {
|
|
93
|
-
return String(n ?? "").replace(/[&<>]/g, (
|
|
93
|
+
return String(n ?? "").replace(/[&<>]/g, (t) => t === "&" ? "&" : t === "<" ? "<" : ">");
|
|
94
94
|
}
|
|
95
95
|
function k(n) {
|
|
96
96
|
if (typeof n.orderId == "string" && n.orderId) return n.orderId;
|
|
97
97
|
try {
|
|
98
|
-
const
|
|
99
|
-
if (
|
|
100
|
-
if (
|
|
101
|
-
const e = new URLSearchParams(
|
|
98
|
+
const t = new URL(n.url, window.location.origin), r = t.searchParams.get("orderId") || t.searchParams.get("order_id");
|
|
99
|
+
if (r) return r;
|
|
100
|
+
if (t.hash && t.hash.length > 1) {
|
|
101
|
+
const e = new URLSearchParams(t.hash.replace(/^#/, "")), a = e.get("orderId") || e.get("order_id");
|
|
102
102
|
if (a) return a;
|
|
103
103
|
}
|
|
104
104
|
} catch {
|
|
@@ -106,32 +106,32 @@ function k(n) {
|
|
|
106
106
|
return null;
|
|
107
107
|
}
|
|
108
108
|
function b() {
|
|
109
|
-
return typeof u().Razorpay == "function" ? Promise.resolve() : p || (p = new Promise((n,
|
|
110
|
-
const
|
|
111
|
-
if (
|
|
112
|
-
|
|
109
|
+
return typeof u().Razorpay == "function" ? Promise.resolve() : p || (p = new Promise((n, t) => {
|
|
110
|
+
const r = document.querySelector('script[data-aikaara-razorpay="1"]');
|
|
111
|
+
if (r) {
|
|
112
|
+
r.addEventListener("load", () => n()), r.addEventListener("error", () => t(new Error("checkout.js failed to load")));
|
|
113
113
|
return;
|
|
114
114
|
}
|
|
115
115
|
const e = document.createElement("script");
|
|
116
116
|
e.src = h, e.async = !0, e.dataset.aikaaraRazorpay = "1", e.onload = () => n(), e.onerror = () => {
|
|
117
|
-
p = null,
|
|
117
|
+
p = null, t(new Error("checkout.js failed to load"));
|
|
118
118
|
}, document.head.appendChild(e);
|
|
119
119
|
}), p);
|
|
120
120
|
}
|
|
121
|
-
function g(n,
|
|
121
|
+
function g(n, t, r) {
|
|
122
122
|
if (!n) return Promise.resolve([]);
|
|
123
|
-
const e = String(
|
|
124
|
-
return (typeof
|
|
123
|
+
const e = String(r || "GET").toUpperCase() === "POST" ? "POST" : "GET", a = n.includes("{orderId}") ? n.replace("{orderId}", encodeURIComponent(t)) : n + (n.includes("?") ? "&" : "?") + "orderId=" + encodeURIComponent(t), o = u().__aikaara_runtime__ ?? {};
|
|
124
|
+
return (typeof o.getSessionToken == "function" ? o.getSessionToken() : typeof o.getChatJwt == "function" ? o.getChatJwt() : Promise.resolve(null)).then((i) => {
|
|
125
125
|
const d = { Accept: "application/json" };
|
|
126
|
-
|
|
126
|
+
i && (d.Authorization = `Bearer ${i}`);
|
|
127
127
|
const c = { method: e, headers: d, credentials: "omit" };
|
|
128
|
-
return e === "POST" && (d["Content-Type"] = "application/json", c.body = JSON.stringify({ orderId:
|
|
129
|
-
}).then((
|
|
130
|
-
if (!
|
|
131
|
-
return
|
|
132
|
-
}).then((
|
|
133
|
-
const d =
|
|
134
|
-
return (Array.isArray(
|
|
128
|
+
return e === "POST" && (d["Content-Type"] = "application/json", c.body = JSON.stringify({ orderId: t })), fetch(a, c);
|
|
129
|
+
}).then((i) => {
|
|
130
|
+
if (!i.ok) throw new Error(`preferred-banks ${i.status}`);
|
|
131
|
+
return i.json();
|
|
132
|
+
}).then((i) => {
|
|
133
|
+
const d = i;
|
|
134
|
+
return (Array.isArray(i) ? i : Array.isArray(d?.banks) ? d.banks : Array.isArray(d?.data) ? d.data : Array.isArray(d?.data?.banks) ? d.data.banks : []).map((l) => {
|
|
135
135
|
if (typeof l == "string") return l;
|
|
136
136
|
if (l && typeof l == "object") {
|
|
137
137
|
const f = l;
|
|
@@ -141,10 +141,10 @@ function g(n, r, t) {
|
|
|
141
141
|
}).filter((l) => !!l);
|
|
142
142
|
});
|
|
143
143
|
}
|
|
144
|
-
function w(n,
|
|
144
|
+
function w(n, t) {
|
|
145
145
|
if (!n) return;
|
|
146
|
-
let
|
|
147
|
-
|
|
146
|
+
let r = document.querySelector("aikaara-link-modal");
|
|
147
|
+
r || (r = document.createElement("aikaara-link-modal"), document.body.appendChild(r)), typeof r.show == "function" ? r.show(n, t) : window.open(n, "_blank", "noopener,noreferrer");
|
|
148
148
|
}
|
|
149
149
|
function x() {
|
|
150
150
|
typeof customElements > "u" || customElements.get("aikaara-template-payment-link") || customElements.define("aikaara-template-payment-link", m);
|