@aikaara/chat-sdk 1.5.0 → 1.5.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--vcUguMg.mjs → AikaaraLinkButton-CnvirM17.mjs} +1 -1
- package/dist/{AikaaraLinkButton-BU0Njp0Y.cjs → AikaaraLinkButton-DFT_nAv9.cjs} +1 -1
- package/dist/AikaaraPaymentLink-CL4O6gbc.mjs +263 -0
- package/dist/AikaaraPaymentLink-D_SZ081m.cjs +1 -0
- package/dist/{MountTenant-CdW5PnSv.mjs → MountTenant-YqTsrEgP.mjs} +2 -2
- package/dist/{MountTenant-TQ5sAymp.cjs → MountTenant-wJ3Clo04.cjs} +2 -2
- package/dist/cdn/aikaara-chat.iife.js +17 -17
- 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-D-tyM5fI.mjs +0 -217
- package/dist/AikaaraPaymentLink-Dq3uDB0c.cjs +0 -1
package/dist/headless.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./MountTenant-
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./MountTenant-wJ3Clo04.cjs");class s extends e.EventEmitter{registration=null;pendingEdits=[];constructor(t){super(),this.setupListeners(t)}registerForm(t){this.registration=t;const i=this.pendingEdits.filter(r=>r.entity_type===t.entityType&&String(r.entity_id)===String(t.entityId));if(i.length>0){for(const r of i)t.onFieldUpdate(r.fields),this.emit("edit:applied",{entityType:r.entity_type,entityId:r.entity_id,fields:r.fields});this.pendingEdits=this.pendingEdits.filter(r=>!(r.entity_type===t.entityType&&String(r.entity_id)===String(t.entityId)))}}unregisterForm(t,i){this.registration?.entityType===t&&String(this.registration?.entityId)===String(i)&&(this.registration=null)}get currentForm(){return this.registration}pushFieldUpdates(t,i,r){this.registration&&this.registration.entityType===t&&String(this.registration.entityId)===String(i)?(this.registration.onFieldUpdate(r),this.emit("edit:applied",{entityType:t,entityId:i,fields:r})):(this.pendingEdits.push({action:"edit_entity",entity_type:t,entity_id:i,fields:r}),this.emit("edit:pending",{entityType:t,entityId:i,fields:r}))}async requestSave(){if(!this.registration)return{success:!1,error:"No form registered"};try{return await this.registration.onSave(),this.emit("save:success",{entityType:this.registration.entityType,entityId:this.registration.entityId}),{success:!0}}catch(t){const i=t instanceof Error?t.message:"Save failed";return this.emit("save:error",{entityType:this.registration.entityType,entityId:this.registration.entityId,error:i}),{success:!1,error:i}}}async requestTest(t){if(!this.registration?.onTest)return{success:!1,error:"Current form does not support testing"};try{return await this.registration.onTest(t),{success:!0}}catch(i){return{success:!1,error:i instanceof Error?i.message:"Test failed"}}}setupListeners(t){t.on("action:edit_entity",i=>{this.pushFieldUpdates(i.entity_type,i.entity_id,i.fields)}),t.on("action:save_entity",i=>{this.requestSave()}),t.on("action:test_tool",i=>{this.emit("test:triggered",{toolId:i.tool_id,parameters:i.parameters}),this.requestTest(i.parameters)})}}exports.ActionCableClient=e.ActionCableClient;exports.AikaaraChatClient=e.AikaaraChatClient;exports.ApiClient=e.ApiClient;exports.ChannelSubscription=e.ChannelSubscription;exports.ConnectionManager=e.ConnectionManager;exports.ConversationManager=e.ConversationManager;exports.EventEmitter=e.EventEmitter;exports.MessageStore=e.MessageStore;exports.SessionAuthAdapter=e.SessionAuthAdapter;exports.SsoExchangeAdapter=e.SsoExchangeAdapter;exports.TiledeskTransport=e.TiledeskTransport;exports.TokenDiscoveryError=e.TokenDiscoveryError;exports.TokenDiscoveryReader=e.TokenDiscoveryReader;exports.clearPersistedConversationId=e.clearPersistedConversationId;exports.collectSsoCredentials=e.collectSsoCredentials;exports.createFetchUploadAdapter=e.createFetchUploadAdapter;exports.createPresigned3StepUploadAdapter=e.createPresigned3StepUploadAdapter;exports.createTiledeskHistoryAdapter=e.createTiledeskHistoryAdapter;exports.discoverToken=e.discoverToken;exports.extractTiledeskFileEnvelope=e.extractTiledeskFileEnvelope;exports.inferTiledeskRole=e.inferTiledeskRole;exports.isTiledeskSelfEcho=e.isTiledeskSelfEcho;exports.mountFromSlug=e.mountFromSlug;exports.mountTenantWidget=e.mount;exports.parseTiledeskTemplate=e.parseTiledeskTemplate;exports.runMethodSelectPreflight=e.runMethodSelectPreflight;exports.FormBridge=s;
|
package/dist/headless.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { E as s } from "./MountTenant-
|
|
2
|
-
import { A as p, b as l, k as g, C as c, l as h, m as y, M as u, S as m, n as f, T, o as S, p as _, q as v, s as E, t as C, u as F, v as k, w as A, x as I, y as x, z as U, B as q, D as M, F as b, G as w } from "./MountTenant-
|
|
1
|
+
import { E as s } from "./MountTenant-YqTsrEgP.mjs";
|
|
2
|
+
import { A as p, b as l, k as g, C as c, l as h, m as y, M as u, S as m, n as f, T, o as S, p as _, q as v, s as E, t as C, u as F, v as k, w as A, x as I, y as x, z as U, B as q, D as M, F as b, G as w } from "./MountTenant-YqTsrEgP.mjs";
|
|
3
3
|
class a extends s {
|
|
4
4
|
registration = null;
|
|
5
5
|
pendingEdits = [];
|
package/dist/index.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./MountTenant-
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./MountTenant-wJ3Clo04.cjs"),s=require("./headless.cjs");function l(a){e.registerComponents();const t=document.createElement("aikaara-chat-widget"),i={baseUrl:"base-url",userToken:"user-token",apiKey:"api-key",title:"title",subtitle:"subtitle",theme:"theme",primaryColor:"primary-color",position:"position",width:"width",height:"height",placeholder:"placeholder",welcomeMessage:"welcome-message",avatarUrl:"avatar-url"};for(const[o,n]of Object.entries(i)){const r=a[o];r!=null&&t.setAttribute(n,String(r))}return t.configure(a),document.body.appendChild(t),t}function d(){const a=document.querySelector("aikaara-chat-widget");a&&a.remove()}exports.ActionCableClient=e.ActionCableClient;exports.AikaaraChatBubble=e.AikaaraChatBubble;exports.AikaaraChatClient=e.AikaaraChatClient;exports.AikaaraChatHeader=e.AikaaraChatHeader;exports.AikaaraChatInput=e.AikaaraChatInput;exports.AikaaraChatWidget=e.AikaaraChatWidget;exports.AikaaraErrorBanner=e.AikaaraErrorBanner;exports.AikaaraMessageBubble=e.AikaaraMessageBubble;exports.AikaaraMessageList=e.AikaaraMessageList;exports.AikaaraStreamingMessage=e.AikaaraStreamingMessage;exports.AikaaraTypingIndicator=e.AikaaraTypingIndicator;exports.ApiClient=e.ApiClient;exports.ChannelSubscription=e.ChannelSubscription;exports.ConnectionManager=e.ConnectionManager;exports.ConversationManager=e.ConversationManager;exports.EventEmitter=e.EventEmitter;exports.MessageStore=e.MessageStore;exports.SessionAuthAdapter=e.SessionAuthAdapter;exports.SsoExchangeAdapter=e.SsoExchangeAdapter;exports.TiledeskTransport=e.TiledeskTransport;exports.TokenDiscoveryError=e.TokenDiscoveryError;exports.TokenDiscoveryReader=e.TokenDiscoveryReader;exports.clearPersistedConversationId=e.clearPersistedConversationId;exports.collectSsoCredentials=e.collectSsoCredentials;exports.createFetchUploadAdapter=e.createFetchUploadAdapter;exports.createPresigned3StepUploadAdapter=e.createPresigned3StepUploadAdapter;exports.createTiledeskHistoryAdapter=e.createTiledeskHistoryAdapter;exports.discoverToken=e.discoverToken;exports.extractTiledeskFileEnvelope=e.extractTiledeskFileEnvelope;exports.inferTiledeskRole=e.inferTiledeskRole;exports.isTiledeskSelfEcho=e.isTiledeskSelfEcho;exports.mountFromSlug=e.mountFromSlug;exports.mountTenantWidget=e.mount;exports.parseTiledeskTemplate=e.parseTiledeskTemplate;exports.registerComponents=e.registerComponents;exports.runMethodSelectPreflight=e.runMethodSelectPreflight;exports.FormBridge=s.FormBridge;exports.mount=l;exports.unmount=d;
|
package/dist/index.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { r as o } from "./MountTenant-
|
|
2
|
-
import { A as u, a as m, b as g, c as h, d as k, e as A, f as C, g as T, h as b, i as f, j as v, k as S, C as y, l as M, m as w, E, M as x, S as B, n as F, T as U, o as D, p as I, q as P, s as j, t as q, u as H, v as R, w as W, x as z, y as G, z as K, B as L, D as O, F as J, G as N } from "./MountTenant-
|
|
1
|
+
import { r as o } from "./MountTenant-YqTsrEgP.mjs";
|
|
2
|
+
import { A as u, a as m, b as g, c as h, d as k, e as A, f as C, g as T, h as b, i as f, j as v, k as S, C as y, l as M, m as w, E, M as x, S as B, n as F, T as U, o as D, p as I, q as P, s as j, t as q, u as H, v as R, w as W, x as z, y as G, z as K, B as L, D as O, F as J, G as N } from "./MountTenant-YqTsrEgP.mjs";
|
|
3
3
|
import { FormBridge as V } from "./headless.mjs";
|
|
4
4
|
function l(e) {
|
|
5
5
|
o();
|
package/dist/ui.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const a=require("./MountTenant-
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const a=require("./MountTenant-wJ3Clo04.cjs");exports.AikaaraChat=a.AikaaraChat;exports.AikaaraChatBubble=a.AikaaraChatBubble;exports.AikaaraChatHeader=a.AikaaraChatHeader;exports.AikaaraChatInput=a.AikaaraChatInput;exports.AikaaraChatWidget=a.AikaaraChatWidget;exports.AikaaraComparePlans=a.AikaaraComparePlans;exports.AikaaraErrorBanner=a.AikaaraErrorBanner;exports.AikaaraLinkModal=a.AikaaraLinkModal;exports.AikaaraMessageBubble=a.AikaaraMessageBubble;exports.AikaaraMessageList=a.AikaaraMessageList;exports.AikaaraModalAction=a.AikaaraModalAction;exports.AikaaraOptionList=a.AikaaraOptionList;exports.AikaaraSchemaForm=a.AikaaraSchemaForm;exports.AikaaraSmartEditModal=a.AikaaraSmartEditModal;exports.AikaaraStreamingMessage=a.AikaaraStreamingMessage;exports.AikaaraSubmitAction=a.AikaaraSubmitAction;exports.AikaaraSystemPill=a.AikaaraSystemPill;exports.AikaaraTemplateRenderer=a.AikaaraTemplateRenderer;exports.AikaaraTextInput=a.AikaaraTextInput;exports.AikaaraTypingIndicator=a.AikaaraTypingIndicator;exports.registerComponents=a.registerComponents;
|
package/dist/ui.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { I as i, a as s, c as e, d as t, e as A, J as k, f as n, K as o, g as m, h as d, L as l, N as g, O as p, P as h, i as C, Q as M, R as b, U as c, V as u, j as S, r as I } from "./MountTenant-
|
|
1
|
+
import { I as i, a as s, c as e, d as t, e as A, J as k, f as n, K as o, g as m, h as d, L as l, N as g, O as p, P as h, i as C, Q as M, R as b, U as c, V as u, j as S, r as I } from "./MountTenant-YqTsrEgP.mjs";
|
|
2
2
|
export {
|
|
3
3
|
i as AikaaraChat,
|
|
4
4
|
s as AikaaraChatBubble,
|
package/package.json
CHANGED
|
@@ -1,217 +0,0 @@
|
|
|
1
|
-
const k = "https://checkout.razorpay.com/v1/checkout.js";
|
|
2
|
-
let f = null;
|
|
3
|
-
function m() {
|
|
4
|
-
return window;
|
|
5
|
-
}
|
|
6
|
-
class g extends HTMLElement {
|
|
7
|
-
shadow;
|
|
8
|
-
payloadData = [];
|
|
9
|
-
message = "";
|
|
10
|
-
// Per-payload-index lock so a successful payment disables only that
|
|
11
|
-
// button (other rows in the same template remain clickable).
|
|
12
|
-
paidIdx = {};
|
|
13
|
-
constructor() {
|
|
14
|
-
super(), this.shadow = this.attachShadow({ mode: "open" });
|
|
15
|
-
}
|
|
16
|
-
setPayload(e, n) {
|
|
17
|
-
this.payloadData = Array.isArray(e) ? e : [], this.message = n ?? "", this.render();
|
|
18
|
-
}
|
|
19
|
-
render() {
|
|
20
|
-
const e = this.payloadData.filter(
|
|
21
|
-
(t) => !!t && typeof t == "object" && t.type === "link" && typeof t.url == "string"
|
|
22
|
-
), n = e.map((t, i) => {
|
|
23
|
-
const o = t.name || "Open link", r = !!this.paidIdx[i];
|
|
24
|
-
return `<button class="link${r ? " paid" : ""}" data-i="${i}" type="button"${r ? " disabled" : ""}><span class="lbl">${b(r ? "Paid" : o)}</span>` + (r ? '<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
|
-
}).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">${n}</div>`, this.shadow.querySelectorAll(".link").forEach((t) => {
|
|
27
|
-
t.addEventListener("click", () => {
|
|
28
|
-
if (t.disabled) return;
|
|
29
|
-
const i = Number(t.dataset.i || 0), o = e[i];
|
|
30
|
-
o && this.handleClick(i, o);
|
|
31
|
-
});
|
|
32
|
-
});
|
|
33
|
-
}
|
|
34
|
-
handleClick(e, n) {
|
|
35
|
-
const t = w(n), i = m().__aikaara_descriptor__, o = i?.partnerPayment, r = i?.razorpay;
|
|
36
|
-
if (t && o?.paymentLinkUrl) {
|
|
37
|
-
this.openPartnerPaymentLink(e, t, n, o);
|
|
38
|
-
return;
|
|
39
|
-
}
|
|
40
|
-
if (!t || !r?.keyId) {
|
|
41
|
-
C(n.url, n.name || "Pay"), this.dispatchEvent(
|
|
42
|
-
new CustomEvent("template-action", {
|
|
43
|
-
detail: {
|
|
44
|
-
text: n.name || "link-click",
|
|
45
|
-
attributes: {
|
|
46
|
-
action: { type: "link", url: n.url, orderId: t || n.orderId, openedIn: "modal" }
|
|
47
|
-
}
|
|
48
|
-
},
|
|
49
|
-
bubbles: !0,
|
|
50
|
-
composed: !0
|
|
51
|
-
})
|
|
52
|
-
);
|
|
53
|
-
return;
|
|
54
|
-
}
|
|
55
|
-
_(r.preferredBanksUrl, t, r.preferredBanksMethod, r.preferredBanksHeaders).catch((s) => (console.warn("[payment_link] preferred-banks fetch failed; continuing with default UI", s), [])).then((s) => P().then(() => this.openRazorpay(e, t, r, s))).catch((s) => {
|
|
56
|
-
console.error("[payment_link] Razorpay launch failed", s);
|
|
57
|
-
});
|
|
58
|
-
}
|
|
59
|
-
openPartnerPaymentLink(e, n, t, i) {
|
|
60
|
-
v(n, i).then((o) => {
|
|
61
|
-
if (!o) {
|
|
62
|
-
y("Failed to generate payment link, please try again later");
|
|
63
|
-
return;
|
|
64
|
-
}
|
|
65
|
-
const r = (o.paymentStatus ?? "").toLowerCase();
|
|
66
|
-
if (r === "paid" || r === "success" || r === "completed") {
|
|
67
|
-
this.paidIdx[e] = !0, this.render(), y("Payment already completed");
|
|
68
|
-
return;
|
|
69
|
-
}
|
|
70
|
-
const s = o.vendorPaymentLink;
|
|
71
|
-
if (!s) {
|
|
72
|
-
y("Failed to generate payment link, please try again later");
|
|
73
|
-
return;
|
|
74
|
-
}
|
|
75
|
-
x(s), this.dispatchEvent(
|
|
76
|
-
new CustomEvent("template-action", {
|
|
77
|
-
detail: {
|
|
78
|
-
text: t.name || "link-click",
|
|
79
|
-
attributes: {
|
|
80
|
-
action: { type: "partner-payment", url: s, orderId: n, openedIn: "external" }
|
|
81
|
-
}
|
|
82
|
-
},
|
|
83
|
-
bubbles: !0,
|
|
84
|
-
composed: !0
|
|
85
|
-
})
|
|
86
|
-
);
|
|
87
|
-
}).catch((o) => {
|
|
88
|
-
console.error("[payment_link] partner payment link fetch failed", o), y("Failed to generate payment link, please try again later");
|
|
89
|
-
});
|
|
90
|
-
}
|
|
91
|
-
openRazorpay(e, n, t, i) {
|
|
92
|
-
const o = m(), r = o.__aikaara_runtime__?.identity ?? {}, s = {
|
|
93
|
-
key: t.keyId,
|
|
94
|
-
order_id: n,
|
|
95
|
-
name: t.name || o.__aikaara_descriptor__?.title || "Payment",
|
|
96
|
-
prefill: {},
|
|
97
|
-
handler: () => {
|
|
98
|
-
this.paidIdx[e] = !0, this.render();
|
|
99
|
-
},
|
|
100
|
-
modal: {
|
|
101
|
-
// No auto-hide on dismiss: user can re-click Pay Now. Per spec,
|
|
102
|
-
// button only locks on confirmed success.
|
|
103
|
-
ondismiss: () => {
|
|
104
|
-
}
|
|
105
|
-
}
|
|
106
|
-
};
|
|
107
|
-
typeof r.mobile == "string" ? s.prefill.contact = r.mobile : typeof r.phone == "string" && (s.prefill.contact = r.phone), typeof r.email == "string" && (s.prefill.email = r.email), typeof r.name == "string" ? s.prefill.name = r.name : typeof r.userName == "string" && (s.prefill.name = r.userName), Array.isArray(i) && i.length && (s.config = {
|
|
108
|
-
display: {
|
|
109
|
-
blocks: {
|
|
110
|
-
utib: {
|
|
111
|
-
name: "Pay Using Preferred Netbanking",
|
|
112
|
-
instruments: [{ method: "netbanking", banks: i }]
|
|
113
|
-
}
|
|
114
|
-
},
|
|
115
|
-
sequence: ["block.utib", "netbanking", "card", "upi"],
|
|
116
|
-
preferences: { show_default_blocks: !0 }
|
|
117
|
-
}
|
|
118
|
-
});
|
|
119
|
-
const l = o.Razorpay;
|
|
120
|
-
if (typeof l != "function")
|
|
121
|
-
throw new Error("Razorpay Checkout script not available");
|
|
122
|
-
const c = new l(s);
|
|
123
|
-
c.on("payment.failed", (d) => {
|
|
124
|
-
console.warn("[payment_link] payment.failed", d?.error);
|
|
125
|
-
}), c.open();
|
|
126
|
-
}
|
|
127
|
-
}
|
|
128
|
-
function b(a) {
|
|
129
|
-
return String(a ?? "").replace(/[&<>]/g, (e) => e === "&" ? "&" : e === "<" ? "<" : ">");
|
|
130
|
-
}
|
|
131
|
-
function w(a) {
|
|
132
|
-
if (typeof a.orderId == "string" && a.orderId) return a.orderId;
|
|
133
|
-
try {
|
|
134
|
-
const e = new URL(a.url, window.location.origin), n = e.searchParams.get("orderId") || e.searchParams.get("order_id");
|
|
135
|
-
if (n) return n;
|
|
136
|
-
if (e.hash && e.hash.length > 1) {
|
|
137
|
-
const t = new URLSearchParams(e.hash.replace(/^#/, "")), i = t.get("orderId") || t.get("order_id");
|
|
138
|
-
if (i) return i;
|
|
139
|
-
}
|
|
140
|
-
} catch {
|
|
141
|
-
}
|
|
142
|
-
return null;
|
|
143
|
-
}
|
|
144
|
-
function P() {
|
|
145
|
-
return typeof m().Razorpay == "function" ? Promise.resolve() : f || (f = new Promise((a, e) => {
|
|
146
|
-
const n = document.querySelector('script[data-aikaara-razorpay="1"]');
|
|
147
|
-
if (n) {
|
|
148
|
-
n.addEventListener("load", () => a()), n.addEventListener("error", () => e(new Error("checkout.js failed to load")));
|
|
149
|
-
return;
|
|
150
|
-
}
|
|
151
|
-
const t = document.createElement("script");
|
|
152
|
-
t.src = k, t.async = !0, t.dataset.aikaaraRazorpay = "1", t.onload = () => a(), t.onerror = () => {
|
|
153
|
-
f = null, e(new Error("checkout.js failed to load"));
|
|
154
|
-
}, document.head.appendChild(t);
|
|
155
|
-
}), f);
|
|
156
|
-
}
|
|
157
|
-
function _(a, e, n, t) {
|
|
158
|
-
if (!a) return Promise.resolve([]);
|
|
159
|
-
const i = String(n || "GET").toUpperCase() === "POST" ? "POST" : "GET", o = a.includes("{orderId}") ? a.replace("{orderId}", encodeURIComponent(e)) : a + (a.includes("?") ? "&" : "?") + "orderId=" + encodeURIComponent(e), r = m().__aikaara_runtime__ ?? {};
|
|
160
|
-
return (typeof r.getSessionToken == "function" ? r.getSessionToken() : typeof r.getChatJwt == "function" ? r.getChatJwt() : Promise.resolve(null)).then((l) => {
|
|
161
|
-
const c = { Accept: "application/json", ...t ?? {} };
|
|
162
|
-
l && (c.Authorization = `Bearer ${l}`);
|
|
163
|
-
const d = { method: i, headers: c, credentials: "omit" };
|
|
164
|
-
return i === "POST" && (c["Content-Type"] = "application/json", d.body = JSON.stringify({ orderId: e })), fetch(o, d);
|
|
165
|
-
}).then((l) => {
|
|
166
|
-
if (!l.ok) throw new Error(`preferred-banks ${l.status}`);
|
|
167
|
-
return l.json();
|
|
168
|
-
}).then((l) => {
|
|
169
|
-
const c = l, d = c?.data && typeof c.data == "object" && !Array.isArray(c.data) ? c.data : null;
|
|
170
|
-
return (Array.isArray(l) ? l : Array.isArray(c?.banks) ? c.banks : Array.isArray(c?.data) ? c.data : Array.isArray(d?.preferredPaymentBank) ? d.preferredPaymentBank : Array.isArray(d?.banks) ? d.banks : []).map((p) => {
|
|
171
|
-
if (typeof p == "string") return p;
|
|
172
|
-
if (p && typeof p == "object") {
|
|
173
|
-
const h = p;
|
|
174
|
-
return h.code || h.bankCode || h.bank_code || null;
|
|
175
|
-
}
|
|
176
|
-
return null;
|
|
177
|
-
}).filter((p) => !!p);
|
|
178
|
-
});
|
|
179
|
-
}
|
|
180
|
-
async function v(a, e) {
|
|
181
|
-
const n = String(e.method || "GET").toUpperCase() === "POST" ? "POST" : "GET", t = e.paymentLinkUrl, i = t.includes("{orderId}") ? t.replace("{orderId}", encodeURIComponent(a)) : t + (t.includes("?") ? "&" : "?") + "orderId=" + encodeURIComponent(a), o = m().__aikaara_runtime__ ?? {}, r = typeof o.getSessionToken == "function" ? await o.getSessionToken() : typeof o.getChatJwt == "function" ? await o.getChatJwt() : null, s = { Accept: "application/json", ...e.headers ?? {} };
|
|
182
|
-
r && (s.Authorization = `Bearer ${r}`);
|
|
183
|
-
const l = { method: n, headers: s, credentials: "omit" };
|
|
184
|
-
n === "POST" && (s["Content-Type"] = "application/json", l.body = JSON.stringify({ orderId: a }));
|
|
185
|
-
const c = await fetch(i, l);
|
|
186
|
-
if (!c.ok) throw new Error(`partner-payment-link ${c.status}`);
|
|
187
|
-
const u = (await c.json())?.data;
|
|
188
|
-
return !u || typeof u.vendorPaymentLink != "string" ? null : { vendorPaymentLink: u.vendorPaymentLink, paymentStatus: u.paymentStatus ?? "" };
|
|
189
|
-
}
|
|
190
|
-
function x(a) {
|
|
191
|
-
if (typeof window > "u") return;
|
|
192
|
-
const e = navigator.userAgent.toLowerCase();
|
|
193
|
-
e.includes("iphone") || e.includes("ipad") || e.includes("ipod") ? window.location.href = a : window.open(a, "_blank", "noopener,noreferrer");
|
|
194
|
-
}
|
|
195
|
-
function y(a) {
|
|
196
|
-
try {
|
|
197
|
-
const e = document.querySelector("aikaara-error-banner");
|
|
198
|
-
if (e && typeof e.show == "function") {
|
|
199
|
-
e.show(a);
|
|
200
|
-
return;
|
|
201
|
-
}
|
|
202
|
-
} catch {
|
|
203
|
-
}
|
|
204
|
-
console.warn("[payment_link]", a);
|
|
205
|
-
}
|
|
206
|
-
function C(a, e) {
|
|
207
|
-
if (!a) return;
|
|
208
|
-
let n = document.querySelector("aikaara-link-modal");
|
|
209
|
-
n || (n = document.createElement("aikaara-link-modal"), document.body.appendChild(n)), typeof n.show == "function" ? n.show(a, e) : window.open(a, "_blank", "noopener,noreferrer");
|
|
210
|
-
}
|
|
211
|
-
function S() {
|
|
212
|
-
typeof customElements > "u" || customElements.get("aikaara-template-payment-link") || customElements.define("aikaara-template-payment-link", g);
|
|
213
|
-
}
|
|
214
|
-
export {
|
|
215
|
-
g as AikaaraPaymentLink,
|
|
216
|
-
S as registerAikaaraPaymentLink
|
|
217
|
-
};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const g="https://checkout.razorpay.com/v1/checkout.js";let f=null;function m(){return window}class k extends HTMLElement{shadow;payloadData=[];message="";paidIdx={};constructor(){super(),this.shadow=this.attachShadow({mode:"open"})}setPayload(e,n){this.payloadData=Array.isArray(e)?e:[],this.message=n??"",this.render()}render(){const e=this.payloadData.filter(t=>!!t&&typeof t=="object"&&t.type==="link"&&typeof t.url=="string"),n=e.map((t,i)=>{const o=t.name||"Open link",r=!!this.paidIdx[i];return`<button class="link${r?" paid":""}" data-i="${i}" type="button"${r?" disabled":""}><span class="lbl">${b(r?"Paid":o)}</span>`+(r?'<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">${n}</div>`,this.shadow.querySelectorAll(".link").forEach(t=>{t.addEventListener("click",()=>{if(t.disabled)return;const i=Number(t.dataset.i||0),o=e[i];o&&this.handleClick(i,o)})})}handleClick(e,n){const t=w(n),i=m().__aikaara_descriptor__,o=i?.partnerPayment,r=i?.razorpay;if(t&&o?.paymentLinkUrl){this.openPartnerPaymentLink(e,t,n,o);return}if(!t||!r?.keyId){C(n.url,n.name||"Pay"),this.dispatchEvent(new CustomEvent("template-action",{detail:{text:n.name||"link-click",attributes:{action:{type:"link",url:n.url,orderId:t||n.orderId,openedIn:"modal"}}},bubbles:!0,composed:!0}));return}_(r.preferredBanksUrl,t,r.preferredBanksMethod,r.preferredBanksHeaders).catch(s=>(console.warn("[payment_link] preferred-banks fetch failed; continuing with default UI",s),[])).then(s=>P().then(()=>this.openRazorpay(e,t,r,s))).catch(s=>{console.error("[payment_link] Razorpay launch failed",s)})}openPartnerPaymentLink(e,n,t,i){v(n,i).then(o=>{if(!o){y("Failed to generate payment link, please try again later");return}const r=(o.paymentStatus??"").toLowerCase();if(r==="paid"||r==="success"||r==="completed"){this.paidIdx[e]=!0,this.render(),y("Payment already completed");return}const s=o.vendorPaymentLink;if(!s){y("Failed to generate payment link, please try again later");return}x(s),this.dispatchEvent(new CustomEvent("template-action",{detail:{text:t.name||"link-click",attributes:{action:{type:"partner-payment",url:s,orderId:n,openedIn:"external"}}},bubbles:!0,composed:!0}))}).catch(o=>{console.error("[payment_link] partner payment link fetch failed",o),y("Failed to generate payment link, please try again later")})}openRazorpay(e,n,t,i){const o=m(),r=o.__aikaara_runtime__?.identity??{},s={key:t.keyId,order_id:n,name:t.name||o.__aikaara_descriptor__?.title||"Payment",prefill:{},handler:()=>{this.paidIdx[e]=!0,this.render()},modal:{ondismiss:()=>{}}};typeof r.mobile=="string"?s.prefill.contact=r.mobile:typeof r.phone=="string"&&(s.prefill.contact=r.phone),typeof r.email=="string"&&(s.prefill.email=r.email),typeof r.name=="string"?s.prefill.name=r.name:typeof r.userName=="string"&&(s.prefill.name=r.userName),Array.isArray(i)&&i.length&&(s.config={display:{blocks:{utib:{name:"Pay Using Preferred Netbanking",instruments:[{method:"netbanking",banks:i}]}},sequence:["block.utib","netbanking","card","upi"],preferences:{show_default_blocks:!0}}});const l=o.Razorpay;if(typeof l!="function")throw new Error("Razorpay Checkout script not available");const c=new l(s);c.on("payment.failed",d=>{console.warn("[payment_link] payment.failed",d?.error)}),c.open()}}function b(a){return String(a??"").replace(/[&<>]/g,e=>e==="&"?"&":e==="<"?"<":">")}function w(a){if(typeof a.orderId=="string"&&a.orderId)return a.orderId;try{const e=new URL(a.url,window.location.origin),n=e.searchParams.get("orderId")||e.searchParams.get("order_id");if(n)return n;if(e.hash&&e.hash.length>1){const t=new URLSearchParams(e.hash.replace(/^#/,"")),i=t.get("orderId")||t.get("order_id");if(i)return i}}catch{}return null}function P(){return typeof m().Razorpay=="function"?Promise.resolve():f||(f=new Promise((a,e)=>{const n=document.querySelector('script[data-aikaara-razorpay="1"]');if(n){n.addEventListener("load",()=>a()),n.addEventListener("error",()=>e(new Error("checkout.js failed to load")));return}const t=document.createElement("script");t.src=g,t.async=!0,t.dataset.aikaaraRazorpay="1",t.onload=()=>a(),t.onerror=()=>{f=null,e(new Error("checkout.js failed to load"))},document.head.appendChild(t)}),f)}function _(a,e,n,t){if(!a)return Promise.resolve([]);const i=String(n||"GET").toUpperCase()==="POST"?"POST":"GET",o=a.includes("{orderId}")?a.replace("{orderId}",encodeURIComponent(e)):a+(a.includes("?")?"&":"?")+"orderId="+encodeURIComponent(e),r=m().__aikaara_runtime__??{};return(typeof r.getSessionToken=="function"?r.getSessionToken():typeof r.getChatJwt=="function"?r.getChatJwt():Promise.resolve(null)).then(l=>{const c={Accept:"application/json",...t??{}};l&&(c.Authorization=`Bearer ${l}`);const d={method:i,headers:c,credentials:"omit"};return i==="POST"&&(c["Content-Type"]="application/json",d.body=JSON.stringify({orderId:e})),fetch(o,d)}).then(l=>{if(!l.ok)throw new Error(`preferred-banks ${l.status}`);return l.json()}).then(l=>{const c=l,d=c?.data&&typeof c.data=="object"&&!Array.isArray(c.data)?c.data:null;return(Array.isArray(l)?l:Array.isArray(c?.banks)?c.banks:Array.isArray(c?.data)?c.data:Array.isArray(d?.preferredPaymentBank)?d.preferredPaymentBank:Array.isArray(d?.banks)?d.banks:[]).map(p=>{if(typeof p=="string")return p;if(p&&typeof p=="object"){const h=p;return h.code||h.bankCode||h.bank_code||null}return null}).filter(p=>!!p)})}async function v(a,e){const n=String(e.method||"GET").toUpperCase()==="POST"?"POST":"GET",t=e.paymentLinkUrl,i=t.includes("{orderId}")?t.replace("{orderId}",encodeURIComponent(a)):t+(t.includes("?")?"&":"?")+"orderId="+encodeURIComponent(a),o=m().__aikaara_runtime__??{},r=typeof o.getSessionToken=="function"?await o.getSessionToken():typeof o.getChatJwt=="function"?await o.getChatJwt():null,s={Accept:"application/json",...e.headers??{}};r&&(s.Authorization=`Bearer ${r}`);const l={method:n,headers:s,credentials:"omit"};n==="POST"&&(s["Content-Type"]="application/json",l.body=JSON.stringify({orderId:a}));const c=await fetch(i,l);if(!c.ok)throw new Error(`partner-payment-link ${c.status}`);const u=(await c.json())?.data;return!u||typeof u.vendorPaymentLink!="string"?null:{vendorPaymentLink:u.vendorPaymentLink,paymentStatus:u.paymentStatus??""}}function x(a){if(typeof window>"u")return;const e=navigator.userAgent.toLowerCase();e.includes("iphone")||e.includes("ipad")||e.includes("ipod")?window.location.href=a:window.open(a,"_blank","noopener,noreferrer")}function y(a){try{const e=document.querySelector("aikaara-error-banner");if(e&&typeof e.show=="function"){e.show(a);return}}catch{}console.warn("[payment_link]",a)}function C(a,e){if(!a)return;let n=document.querySelector("aikaara-link-modal");n||(n=document.createElement("aikaara-link-modal"),document.body.appendChild(n)),typeof n.show=="function"?n.show(a,e):window.open(a,"_blank","noopener,noreferrer")}function S(){typeof customElements>"u"||customElements.get("aikaara-template-payment-link")||customElements.define("aikaara-template-payment-link",k)}exports.AikaaraPaymentLink=k;exports.registerAikaaraPaymentLink=S;
|