UNPKG

@getopenpay/openpay-js

Version:

Accept payments through OpenPay, right on your site

1,768 lines 1.15 MB
import { connectToChild as nn } from "penpal"; import { z as o } from "zod"; import dt from "chalk"; import { v4 as Ge } from "uuid"; function Fo(e, t) { var r = Object.setPrototypeOf; r ? r(e, t) : e.__proto__ = t; } function To(e, t) { t === void 0 && (t = e.constructor); var r = Error.captureStackTrace; r && r(e, t); } var No = /* @__PURE__ */ (function() { var e = function(r, n) { return e = Object.setPrototypeOf || { __proto__: [] } instanceof Array && function(a, i) { a.__proto__ = i; } || function(a, i) { for (var s in i) Object.prototype.hasOwnProperty.call(i, s) && (a[s] = i[s]); }, e(r, n); }; return function(t, r) { if (typeof r != "function" && r !== null) throw new TypeError("Class extends value " + String(r) + " is not a constructor or null"); e(t, r); function n() { this.constructor = t; } t.prototype = r === null ? Object.create(r) : (n.prototype = r.prototype, new n()); }; })(), Lo = (function(e) { No(t, e); function t(r, n) { var a = this.constructor, i = e.call(this, r, n) || this; return Object.defineProperty(i, "name", { value: a.name, enumerable: !1, configurable: !0 }), Fo(i, a.prototype), To(i), i; } return t; })(Error); const T = o.string().trim().min(1, { message: "Please fill in this field" }), P = o.string().trim().optional(), D = (e) => o.nullable(e.optional()); var p = /* @__PURE__ */ ((e) => (e.FIRST_NAME = "firstName", e.LAST_NAME = "lastName", e.PHONE = "phone", e.EMAIL = "email", e.LINE1 = "line1", e.LINE2 = "line2", e.LINE3 = "line3", e.CITY = "city", e.STATE = "state", e.COUNTRY = "country", e.ZIP_CODE = "zipCode", e.SHIPPING_LINE1 = "shippingAddressLine1", e.SHIPPING_LINE2 = "shippingAddressLine2", e.SHIPPING_LINE3 = "shippingAddressLine3", e.SHIPPING_CITY = "shippingAddressCity", e.SHIPPING_STATE = "shippingAddressState", e.SHIPPING_COUNTRY = "shippingAddressCountry", e.SHIPPING_ZIP_CODE = "shippingAddressZipCode", e.IS_SHIPPING_SAME_AS_BILLING = "isShippingSameAsBilling", e.PROMOTION_CODE = "promotionCode", e.IS_BUSINESS_PURCHASE = "isBusinessPurchase", e.BUSINESS_NAME = "businessName", e.TAX_ID = "taxId", e.TAX_ID_TYPE = "taxIdType", e))(p || {}); const on = o.nativeEnum(p); var an = /* @__PURE__ */ ((e) => (e.CARD_NUMBER = "cardNumber", e.CARD_EXPIRY = "cardExpiry", e.CARD_CVC = "cardCvc", e))(an || {}); const sn = o.nativeEnum(an), cn = o.union([on, sn]); var ge = /* @__PURE__ */ ((e) => (e.CARD = "card", e.CARD_NUMBER = "card-number", e.CARD_EXPIRY = "card-expiry", e.CARD_CVC = "card-cvc", e.CDE_BRIDGE = "cde-bridge", e))(ge || {}); const Mo = o.enum(["card", "card-number", "card-expiry", "card-cvc", "cde-bridge"]), Ft = o.object({ provider: o.string(), processor_name: D(o.string()), metadata: D(o.record(o.string(), o.any())) }), xo = o.object({ id: o.string() }), Tt = o.object({ backgroundColor: P, color: P, fontFamily: P, fontSize: P, fontWeight: P, margin: P, padding: P, letterSpacing: P, lineHeight: P, hideIcon: P, placeholderStyle: o.object({ color: P, fontSize: P, fontWeight: P, fontFamily: P, letterSpacing: P, lineHeight: P }).optional() }); Tt.extend({ disableAutoFill: P, placeholder: o.object({ cardNumber: P, expiry: P, cvc: P }).optional() }); Tt.extend({ disableAutoFill: P, placeholder: o.string().optional(), /** * The card icon at the start of the card number input field * It won't affect after the icon changed to card brand after the user input the card number */ icon: o.object({ color: o.string().optional() }).optional() }); Tt.extend({ disableAutoFill: P, placeholder: o.string().optional() }); Tt.extend({ disableAutoFill: P, placeholder: o.string().optional() }); const pe = o.enum([ // Element -> Form "LAYOUT", "LOADED", "BLUR", "FOCUS", "CHANGE", "TOKENIZE_STARTED", "CHECKOUT_STARTED", "PAYMENT_FLOW_STARTED", "TOKENIZE_SUCCESS", "CHECKOUT_SUCCESS", "LOAD_ERROR", "VALIDATION_ERROR", "TOKENIZE_ERROR", "CHECKOUT_ERROR", "SETUP_PAYMENT_METHOD_SUCCESS", // Form -> Element "TOKENIZE", "CHECKOUT", "START_PAYMENT_FLOW" ]), Do = pe.extract(["TOKENIZE_STARTED", "CHECKOUT_STARTED"]), Uo = o.object({ type: Do }), Oo = pe.extract(["BLUR", "FOCUS", "CHANGE"]), jo = o.object({ type: Oo, elementType: sn, errors: o.array(o.string()).optional(), obfuscatedValue: o.string().optional() }), $o = pe.extract(["LOAD_ERROR", "TOKENIZE_ERROR", "CHECKOUT_ERROR"]), Go = o.object({ type: $o, message: T, headers: o.record(o.string(), o.string()).optional() }), qo = pe.extract(["VALIDATION_ERROR"]), Vo = o.object({ type: qo, elementType: cn, errors: o.array(o.string()) }), zo = o.object({ type: o.literal(pe.enum.LAYOUT), height: T }), Bo = o.object({ type: o.literal(pe.enum.LOADED), sessionId: T, totalAmountAtoms: o.number(), currency: P, checkoutPaymentMethods: o.array(Ft) }), Ho = o.object({ type: o.literal(pe.enum.PAYMENT_FLOW_STARTED), nextActionMetadata: o.record(o.string(), o.any()), paymentFlowMetadata: o.any().optional(), startPFMetadata: o.optional(o.record(o.string(), o.any())) }), Ko = o.object({ type: o.literal(pe.enum.SETUP_PAYMENT_METHOD_SUCCESS), paymentMethodId: o.string() }), Ue = o.object({ email: T.email({ message: "Please enter a valid email address" }), firstName: T, lastName: T, phone: P, promotionCode: P, line1: P, line2: P, line3: P, city: P, state: P, country: T, zipCode: P, isShippingSameAsBilling: o.custom().optional().default(!0), shippingAddressLine1: P, shippingAddressLine2: P, shippingAddressLine3: P, shippingAddressCity: P, shippingAddressState: P, shippingAddressCountry: P, shippingAddressZipCode: P, businessName: P, taxId: P, taxIdType: P }), Yo = o.object({ email: T.email({ message: "Please enter a valid email address" }), firstName: P, lastName: P, phone: P, promotionCode: P, line1: P, line2: P, line3: P, city: P, state: P, country: T, zipCode: P, isShippingSameAsBilling: o.custom().optional().default(!0), shippingAddressLine1: P, shippingAddressLine2: P, shippingAddressLine3: P, shippingAddressCity: P, shippingAddressState: P, shippingAddressCountry: P, shippingAddressZipCode: P, businessName: P, taxId: P, taxIdType: P }); o.object({ line1: T, city: T, state: T, country: T }); o.object({ shippingAddressCountry: T, shippingAddressZipCode: T }); o.object({ shippingAddressLine1: T, shippingAddressCity: T, shippingAddressState: T, shippingAddressCountry: T, shippingAddressZipCode: T }); const Wo = pe.extract(["TOKENIZE", "CHECKOUT", "START_PAYMENT_FLOW"]), Jo = o.object({ type: Wo, sessionId: T, checkoutPaymentMethod: Ft, paymentFlowMetadata: o.any().optional(), doNotUseLegacyCCFlow: o.boolean().optional(), existingCCPMId: P, paymentRouteId: P }).extend(Ue.shape), Zo = o.object({ type: o.literal(pe.enum.TOKENIZE_SUCCESS), isReadyForCheckout: o.boolean() }), Qo = o.object({ type: o.literal(pe.enum.CHECKOUT_SUCCESS), invoiceUrls: o.array(o.string()), subscriptionIds: o.array(o.string()), customerId: o.string(), paymentMethodId: P }), Xo = o.discriminatedUnion("type", [ Uo, jo, Go, Vo, zo, Bo, Jo, Zo, Qo, Ho, Ko ]), ea = o.object({ payload: Xo, nonce: T, formId: T, elementId: T }); o.object({ amountAtom: o.number(), /** * The three-letter ISO 4217 currency code for the payment. */ currency: T }); o.enum(["apple_pay", "google_pay"]); o.object({ secure_token: o.string(), promotion_code: o.string().optional() }); o.object({ secure_token: o.string(), existing_cc_pm_id: D(o.string()), their_pm_id: D(o.string()), checkout_attempt_id: D(o.string()), processor_specific_metadata: D(o.record(o.string(), o.any())) }); const tt = o.object({ invoice_urls: o.array(o.string()), subscription_ids: o.array(o.string()), customer_id: o.string(), payment_method_id: D(o.string()), processors_used: D(o.array(o.string())) }), ta = o.object({ elementType: o.string(), errors: o.array(o.string()) }); o.object({ session_id: o.string() }); const ra = o.object({ success: o.literal(!1), error_type: o.literal("validation_error"), errors: o.array(ta) }), na = o.discriminatedUnion("success", [ o.object({ success: o.literal(!0) }), ra ]); o.object({ session_id: o.string(), checkout_payment_method: Ft, non_cde_form_fields: Ue, do_not_use_legacy_cc_flow: o.boolean().optional(), existing_cc_pm_id: D(o.string()), extra_metadata: o.record(o.string(), o.any()), payment_route_id: D(o.string()), customer_language: D(o.string()) }); o.object({ session_id: o.string(), checkout_payment_method: Ft, non_cde_form_fields: Ue, extra_metadata: o.record(o.string(), o.any()).optional(), payment_route_id: D(o.string()), customer_language: D(o.string()) }); var F = /* @__PURE__ */ ((e) => (e.SUCCESS = "success", e.FAILURE = "failure", e.CANCELLED = "cancelled", e))(F || {}); const ln = o.object({ status: o.enum([ "success", "failure", "cancelled" /* CANCELLED */ ]), href: o.string().optional().nullable() }); o.object({ href: o.string().optional().nullable() }); const oa = o.object({ type: o.string(), redirect_url: o.string(), initial_intent_id: o.string(), consent_id: o.string(), their_pm_id: o.string().optional() }), aa = o.object({ bank_name: o.string(), display_name: o.string(), resources: o.object({ logo_url: o.string().optional() }) }), un = o.object({ type: o.string(), redirect_url: D(o.string()), initial_intent_id: D(o.string()), consent_id: D(o.string()), their_pm_id: D(o.string()), payment_session: D(o.record(o.string(), o.any())), available_banks: D(o.array(aa)) }), ia = o.discriminatedUnion("present", [ o.object({ present: o.literal(!0), href: o.string() }), o.object({ present: o.literal(!1) }) ]), sa = o.object({ payment_methods: o.array(xo), pay_first_success_response: D(tt), required_user_actions: D(o.array(un)), post_checkout_redirect_to: D(o.string()), checkout_success_response: D(tt) }), ca = o.object({ institutionNumber: o.string(), transitNumber: o.string(), accountNumber: o.string(), accountType: o.enum(["personal", "business"]) }); o.object({ status: o.enum(["success", "failure"]), payload: ca.optional() }); const la = o.object({ sortCode: o.string(), accountNumber: o.string(), accountType: o.enum(["personal", "business"]) }); o.object({ status: o.enum(["success", "failure"]), payload: la.optional() }); const ua = o.object({ iban: o.string(), accountType: o.enum(["personal", "business"]) }); o.object({ status: o.enum(["success", "failure"]), payload: ua.optional() }); const da = o.object({ account_number: o.string(), aba_routing_number: o.string() }), pa = o.object({ institution_number: o.string(), transit_number: o.string(), account_number: o.string() }), ma = o.object({ account_number: o.string(), sort_code: o.string() }), fa = o.object({ iban: o.string() }), _a = o.object({ status: o.enum(["success", "failure"]), payload: o.union([ da, pa, ma, fa, o.object({ error: o.string() }) ]).optional() }), E = (e) => o.nullable(e.optional()); o.string().trim().min(1, { message: "Cannot be blank" }); const ya = o.object({ cde_response_type: o.literal("error"), message: o.string(), headers: o.record(o.string(), o.string()).optional() }); o.enum(["usd", "brl"]); const dn = o.object({ name: o.string(), amount_atom_off: E(o.number()), percent_off: E(o.number()), currency: E(o.string()), duration: o.string(), duration_in_months: E(o.number()) }), pn = o.object({ amount_subtotal_atom: o.number().int(), amount_total_atom: o.number().int(), currency: o.string(), description: E(o.string()), price_id: o.string(), billing_interval: E(o.string()), billing_interval_count: E(o.number().int()), quantity: o.number().int() }), ha = o.record(o.string(), o.any()), ga = o.object({ name: o.string(), settings: E(ha) }), qe = o.object({ provider: o.string(), processor_name: E(o.string()), metadata: E(o.record(o.string(), o.any())) }), wa = o.object({ quantity: o.number() }), va = o.object({ id: E(o.string()), billing_interval: E(o.string()), billing_interval_count: E(o.number().int()), subscription_items: o.array(wa), trial_start: E(o.string()), trial_end: E(o.string()) }), mn = o.object({ amount_atom: o.number() }), ba = o.object({ amount_atom: o.number(), amount_atom_considering_discount_applied: o.number(), currency: o.string(), discount_amount_atoms: o.array(mn), subscription_item_id: o.string() }), Pa = o.object({ coupon: dn }), Ea = o.object({ currency: o.string(), discounts: o.array(Pa), hosted_invoice_url: E(o.string()), lines: o.array(ba), remaining_amount_atom: o.number(), tax_amount_atom: o.number(), total_amount_atom: o.number(), total_discount_amount_atoms: o.array(mn) }), Ar = o.object({ created: o.array(va), invoices: o.array(Ea), processors_used: E(o.array(o.string())), payment_method_id: E(o.string()) }), fn = o.object({ preview: Ar, preview_post_trial: E(Ar), coupons: o.array(dn) }), Sr = o.object({ status: o.literal("open"), locale: E(o.string()), token: o.string(), email: E(o.string()), checkout_settings: o.record(o.string(), o.any()), line_items: o.array(pn), amount_subtotal_atom: o.number().int(), amount_total_atom: o.number().int(), brand: ga, subs_preview: E(fn), // Null in setup mode methods_available: o.array(qe), return_url: E(o.string()), success_url: E(o.string()), final_feature_rollout_settings: E(o.record(o.string(), o.any())) }), _n = o.discriminatedUnion("mode", [ o.object({ mode: o.literal("setup"), currency: o.nullable(o.undefined()) }).extend(Sr.shape), o.object({ mode: o.enum(["payment", "subscription"]), currency: o.string() }).extend(Sr.shape) ]), Ca = o.object({ status: o.literal("complete") }), Aa = o.object({ status: o.literal("expired") }); o.union([_n, Ca, Aa]); o.object({ logo: o.string(), icon: o.string(), primary_color: o.string(), secondary_color: o.string() }); o.object({ secure_token: o.string(), pm_id: o.string() }); const Pt = o.object({ line1: o.string().optional(), line2: o.string().optional(), line3: o.string().optional(), city: o.string().optional(), state: o.string().optional(), country: o.string(), zip_code: o.string().optional() }); o.object({ secure_token: o.string(), payment_input: o.any(), // Should follow AnyPaymentInput from CDE customer_email: o.string(), customer_last_name: o.string().optional(), customer_first_name: o.string().optional(), customer_address: Pt, customer_shipping_address: Pt.optional(), line_items: o.array(pn), total_amount_atom: o.number().int(), cancel_at_end: o.boolean(), checkout_payment_method: qe, promotion_code: o.string().optional(), do_not_use_legacy_cc_flow: o.boolean().optional(), use_confirmed_pm_id: E(o.string()), payment_route_id: E(o.string()) }); const yn = o.object({ payment_method_id: o.string() }); o.object({ id: o.string(), return_url: o.string() }); const Sa = o.object({ type: o.string(), loc: o.array(o.string()), msg: o.string(), url: o.string() }); o.array(Sa); const ka = o.object({ new_customer_email: o.string().optional(), new_customer_last_name: o.string().optional(), new_customer_first_name: o.string().optional(), customer_business_name: o.string().optional(), customer_tax_id: o.string().optional(), customer_tax_id_type: o.string().optional(), new_customer_address: Pt, new_customer_shipping_address: Pt.optional(), customer_language: o.string().optional(), new_customer_phone: o.string().optional() }), Ia = o.object({ price_id: o.string(), quantity: o.number().int() }), hn = o.object({ line_items: o.array(Ia), promotion_code: o.string().optional(), displayed_total_amount_atom: o.number().int() }), Ra = o.object({ processor_specific_metadata: E(o.record(o.string(), o.any())) }); o.object({ payment_provider: o.string(), checkout_payment_method: qe, existing_cc_pm_id: o.string().optional(), their_existing_pm_id: o.string().optional(), use_pay_first_flow: o.boolean().optional(), pay_first_flow_cart_info: hn.optional(), customer_language: o.string().optional() }).extend(ka.shape).extend(Ra.shape); const gn = o.object({ required_user_actions: o.array(o.record(o.string(), o.any())), checkout_attempt_id: E(o.string()) }); o.object({ fields: Yo, checkoutPaymentMethod: qe, payment_route_id: E(o.string()) }); o.object({ session_id: o.string(), non_cde_form_fields: Ue, checkout_payment_method: qe, extra_metadata: o.record(o.string(), o.any()), // This is optional in CDE, but not in OJS moving forward use_unified_cc_flow: E(o.boolean()), pay_first_flow_cart_info: hn.optional(), payment_route_id: E(o.string()), customer_language: o.string().optional(), existing_cc_pm_id: E(o.string()) }); const Fa = o.object({ required_user_actions: o.array(o.record(o.string(), o.any())), cc_pm_id: o.string(), checkout_success_response: E(tt), checkout_attempt_id: E(o.string()) }); o.record(o.any()); o.object({ first_name: E(o.string()), last_name: E(o.string()), line1: E(o.string()), line2: E(o.string()), line3: E(o.string()), city: E(o.string()), state: E(o.string()), country: E(o.string()), zip_code: E(o.string()), email: E(o.string()), billing_email: E(o.string()), phone_number: E(o.string()), business_name: E(o.string()), tax_id: E(o.string()), tax_id_type: E(o.string()), update_processor_customer: E(o.boolean()) }); o.object({ id: o.string(), email: E(o.string()), first_name: E(o.string()), last_name: E(o.string()), phone_number: E(o.string()), billing_email: E(o.string()), address: E(o.record(o.string(), o.any())) }); o.object({ message: o.string() }); const Ta = o.object({ error_code: o.string() }); o.object({ checkout_payment_method: qe, processor_specific_metadata: o.record(o.any()).optional(), payment_route_id: E(o.string()) }); const Na = o.object({ next_action_metadata: E(o.record(o.any())) }); o.object({ events: o.array( o.object({ event_name: o.string(), device_token: o.string(), properties: o.record(o.any()).optional(), context_properties: o.record(o.any()).optional() }) ) }); o.any().optional(); o.object({ device_token: o.string() }); const La = o.object({}), Ma = o.object({ _unified_cc_action_name: o.string(), _unified_cc_pccs_id: o.string() }).catchall(o.any()), xa = o.object({ type: o.string(), loc: o.array(o.string()), msg: o.string(), url: o.string() }), Da = o.array(xa), Ua = o.object({ code: o.string(), message: o.string(), path: o.array(o.string()) }), Oa = o.array(Ua), ja = { "failed to fetch": "Connection error: please double check if you are connected to the internet, then try again" }, Zt = (e) => { const t = e.toLowerCase().trim(); return ja[t] ?? e; }, $a = (e) => { try { return typeof JSON.parse(e) == "object"; } catch { return !1; } }, Ga = (e) => e.length === 1 ? Zt(e[0].msg) : `Please fix the following errors: ${e.map((r) => `• ${Zt(r.msg)}`).join(` `)}`, qa = (e) => `Encountered the following errors: ${e.map((r) => `- ${r.path.join("/")}: ${r.message}`).join(` `)}`, ae = (e) => { if (e instanceof Error) if ($a(e.message)) { const t = JSON.parse(e.message); return Da.safeParse(t).success ? Ga(t) : Oa.safeParse(t).success ? qa(t) : (console.warn(`Encountered unknown stringified JSON object: ${e.message}`), e.message); } else return Zt(e.message); if (typeof e == "object") try { return JSON.stringify(e); } catch (t) { return t + ""; } else return e + ""; }, Va = (e, t, r) => ((...n) => { try { return t(...n); } catch (a) { r(`[form] Error running callback (${e}):`, a); return; } }), za = (e) => e.reduce((t, r) => t + r, 0), wn = (e) => { e.preventDefault(), e.returnValue = !0; }, Ba = () => { window.addEventListener("beforeunload", wn); }, Ha = () => { window.removeEventListener("beforeunload", wn); }, V = (e) => { let t = !1; return async (r) => { if (t) { console.warn("Skipping submission because it is already in progress"); return; } t = !0; try { r.context.preventNavigationDuringSubmission && Ba(), r.formCallbacks.get.onCheckoutStarted?.(), v("checkout_started", { cpm: r.checkoutPaymentMethod }); const n = await e(r); if (v("checkout_success", { cpm: r.checkoutPaymentMethod, ...n }), Hi(), n.mode === "setup") r.formCallbacks.get.onSetupPaymentMethodSuccess(n.result.payment_method_id); else if (n.mode === "checkout") r.formCallbacks.get.onCheckoutSuccess( n.result.invoice_urls, n.result.subscription_ids, n.result.customer_id, n.result.processors_used ?? [], n.result.payment_method_id ?? "" ); else throw new Error(`Unhandled mode: ${n}`); } catch (n) { t = !1; const a = ae(n), i = await jn(r.context.anyCdeConnection, a); r.formCallbacks.get.onCheckoutError(a, i), v("checkout_error", { cpm: r.checkoutPaymentMethod, errorMessage: a, errorCode: i, error: n }); } finally { t = !1, r.context.preventNavigationDuringSubmission && Ha(); } }; }, ce = (e) => async (t) => { try { return await e(t); } catch (r) { const { err__: n } = k("init-error-catcher"), a = ae(r), i = await jn(t.context.anyCdeConnection, a); return n(i, a, r), v("init_flow_error", { errorMessage: a, errorCode: i, error: r }), { isAvailable: !1, reason: a, errorCode: i, isLoading: !1 }; } }, k = (e) => { const t = (...n) => { window.console.log(`${dt.green.bold("ojs/")}${dt.bold.gray(`${e}`)} `, ...n); }, r = (...n) => { window.console.warn(`${dt.red.bold("ojs/")}${dt.bold.gray(`${e}`)} `, ...n); }; return { log: t, err: r, log__: t, err__: r }; }; var Qt = function(e, t) { return Qt = Object.setPrototypeOf || { __proto__: [] } instanceof Array && function(r, n) { r.__proto__ = n; } || function(r, n) { for (var a in n) Object.prototype.hasOwnProperty.call(n, a) && (r[a] = n[a]); }, Qt(e, t); }; function Ee(e, t) { if (typeof t != "function" && t !== null) throw new TypeError("Class extends value " + String(t) + " is not a constructor or null"); Qt(e, t); function r() { this.constructor = e; } e.prototype = t === null ? Object.create(t) : (r.prototype = t.prototype, new r()); } function Ka(e, t, r, n) { function a(i) { return i instanceof r ? i : new r(function(s) { s(i); }); } return new (r || (r = Promise))(function(i, s) { function l(d) { try { u(n.next(d)); } catch (m) { s(m); } } function c(d) { try { u(n.throw(d)); } catch (m) { s(m); } } function u(d) { d.done ? i(d.value) : a(d.value).then(l, c); } u((n = n.apply(e, t || [])).next()); }); } function vn(e, t) { var r = { label: 0, sent: function() { if (i[0] & 1) throw i[1]; return i[1]; }, trys: [], ops: [] }, n, a, i, s = Object.create((typeof Iterator == "function" ? Iterator : Object).prototype); return s.next = l(0), s.throw = l(1), s.return = l(2), typeof Symbol == "function" && (s[Symbol.iterator] = function() { return this; }), s; function l(u) { return function(d) { return c([u, d]); }; } function c(u) { if (n) throw new TypeError("Generator is already executing."); for (; s && (s = 0, u[0] && (r = 0)), r; ) try { if (n = 1, a && (i = u[0] & 2 ? a.return : u[0] ? a.throw || ((i = a.return) && i.call(a), 0) : a.next) && !(i = i.call(a, u[1])).done) return i; switch (a = 0, i && (u = [u[0] & 2, i.value]), u[0]) { case 0: case 1: i = u; break; case 4: return r.label++, { value: u[1], done: !1 }; case 5: r.label++, a = u[1], u = [0]; continue; case 7: u = r.ops.pop(), r.trys.pop(); continue; default: if (i = r.trys, !(i = i.length > 0 && i[i.length - 1]) && (u[0] === 6 || u[0] === 2)) { r = 0; continue; } if (u[0] === 3 && (!i || u[1] > i[0] && u[1] < i[3])) { r.label = u[1]; break; } if (u[0] === 6 && r.label < i[1]) { r.label = i[1], i = u; break; } if (i && r.label < i[2]) { r.label = i[2], r.ops.push(u); break; } i[2] && r.ops.pop(), r.trys.pop(); continue; } u = t.call(e, r); } catch (d) { u = [6, d], a = 0; } finally { n = i = 0; } if (u[0] & 5) throw u[1]; return { value: u[0] ? u[1] : void 0, done: !0 }; } } function Oe(e) { var t = typeof Symbol == "function" && Symbol.iterator, r = t && e[t], n = 0; if (r) return r.call(e); if (e && typeof e.length == "number") return { next: function() { return e && n >= e.length && (e = void 0), { value: e && e[n++], done: !e }; } }; throw new TypeError(t ? "Object is not iterable." : "Symbol.iterator is not defined."); } function Et(e, t) { var r = typeof Symbol == "function" && e[Symbol.iterator]; if (!r) return e; var n = r.call(e), a, i = [], s; try { for (; (t === void 0 || t-- > 0) && !(a = n.next()).done; ) i.push(a.value); } catch (l) { s = { error: l }; } finally { try { a && !a.done && (r = n.return) && r.call(n); } finally { if (s) throw s.error; } } return i; } function Ct(e, t, r) { if (r || arguments.length === 2) for (var n = 0, a = t.length, i; n < a; n++) (i || !(n in t)) && (i || (i = Array.prototype.slice.call(t, 0, n)), i[n] = t[n]); return e.concat(i || Array.prototype.slice.call(t)); } function Me(e) { return this instanceof Me ? (this.v = e, this) : new Me(e); } function Ya(e, t, r) { if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined."); var n = r.apply(e, t || []), a, i = []; return a = Object.create((typeof AsyncIterator == "function" ? AsyncIterator : Object).prototype), l("next"), l("throw"), l("return", s), a[Symbol.asyncIterator] = function() { return this; }, a; function s(y) { return function(_) { return Promise.resolve(_).then(y, m); }; } function l(y, _) { n[y] && (a[y] = function(g) { return new Promise(function(w, h) { i.push([y, g, w, h]) > 1 || c(y, g); }); }, _ && (a[y] = _(a[y]))); } function c(y, _) { try { u(n[y](_)); } catch (g) { f(i[0][3], g); } } function u(y) { y.value instanceof Me ? Promise.resolve(y.value.v).then(d, m) : f(i[0][2], y); } function d(y) { c("next", y); } function m(y) { c("throw", y); } function f(y, _) { y(_), i.shift(), i.length && c(i[0][0], i[0][1]); } } function Wa(e) { if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined."); var t = e[Symbol.asyncIterator], r; return t ? t.call(e) : (e = typeof Oe == "function" ? Oe(e) : e[Symbol.iterator](), r = {}, n("next"), n("throw"), n("return"), r[Symbol.asyncIterator] = function() { return this; }, r); function n(i) { r[i] = e[i] && function(s) { return new Promise(function(l, c) { s = e[i](s), a(l, c, s.done, s.value); }); }; } function a(i, s, l, c) { Promise.resolve(c).then(function(u) { i({ value: u, done: l }); }, s); } } function Y(e) { return typeof e == "function"; } function Nt(e) { var t = function(n) { Error.call(n), n.stack = new Error().stack; }, r = e(t); return r.prototype = Object.create(Error.prototype), r.prototype.constructor = r, r; } var zt = Nt(function(e) { return function(r) { e(this), this.message = r ? r.length + ` errors occurred during unsubscription: ` + r.map(function(n, a) { return a + 1 + ") " + n.toString(); }).join(` `) : "", this.name = "UnsubscriptionError", this.errors = r; }; }); function At(e, t) { if (e) { var r = e.indexOf(t); 0 <= r && e.splice(r, 1); } } var st = (function() { function e(t) { this.initialTeardown = t, this.closed = !1, this._parentage = null, this._finalizers = null; } return e.prototype.unsubscribe = function() { var t, r, n, a, i; if (!this.closed) { this.closed = !0; var s = this._parentage; if (s) if (this._parentage = null, Array.isArray(s)) try { for (var l = Oe(s), c = l.next(); !c.done; c = l.next()) { var u = c.value; u.remove(this); } } catch (g) { t = { error: g }; } finally { try { c && !c.done && (r = l.return) && r.call(l); } finally { if (t) throw t.error; } } else s.remove(this); var d = this.initialTeardown; if (Y(d)) try { d(); } catch (g) { i = g instanceof zt ? g.errors : [g]; } var m = this._finalizers; if (m) { this._finalizers = null; try { for (var f = Oe(m), y = f.next(); !y.done; y = f.next()) { var _ = y.value; try { kr(_); } catch (g) { i = i ?? [], g instanceof zt ? i = Ct(Ct([], Et(i)), Et(g.errors)) : i.push(g); } } } catch (g) { n = { error: g }; } finally { try { y && !y.done && (a = f.return) && a.call(f); } finally { if (n) throw n.error; } } } if (i) throw new zt(i); } }, e.prototype.add = function(t) { var r; if (t && t !== this) if (this.closed) kr(t); else { if (t instanceof e) { if (t.closed || t._hasParent(this)) return; t._addParent(this); } (this._finalizers = (r = this._finalizers) !== null && r !== void 0 ? r : []).push(t); } }, e.prototype._hasParent = function(t) { var r = this._parentage; return r === t || Array.isArray(r) && r.includes(t); }, e.prototype._addParent = function(t) { var r = this._parentage; this._parentage = Array.isArray(r) ? (r.push(t), r) : r ? [r, t] : t; }, e.prototype._removeParent = function(t) { var r = this._parentage; r === t ? this._parentage = null : Array.isArray(r) && At(r, t); }, e.prototype.remove = function(t) { var r = this._finalizers; r && At(r, t), t instanceof e && t._removeParent(this); }, e.EMPTY = (function() { var t = new e(); return t.closed = !0, t; })(), e; })(), bn = st.EMPTY; function Pn(e) { return e instanceof st || e && "closed" in e && Y(e.remove) && Y(e.add) && Y(e.unsubscribe); } function kr(e) { Y(e) ? e() : e.unsubscribe(); } var Ja = { Promise: void 0 }, Za = { setTimeout: function(e, t) { for (var r = [], n = 2; n < arguments.length; n++) r[n - 2] = arguments[n]; return setTimeout.apply(void 0, Ct([e, t], Et(r))); }, clearTimeout: function(e) { return clearTimeout(e); }, delegate: void 0 }; function En(e) { Za.setTimeout(function() { throw e; }); } function Ir() { } function gt(e) { e(); } var ir = (function(e) { Ee(t, e); function t(r) { var n = e.call(this) || this; return n.isStopped = !1, r ? (n.destination = r, Pn(r) && r.add(n)) : n.destination = ei, n; } return t.create = function(r, n, a) { return new Xt(r, n, a); }, t.prototype.next = function(r) { this.isStopped || this._next(r); }, t.prototype.error = function(r) { this.isStopped || (this.isStopped = !0, this._error(r)); }, t.prototype.complete = function() { this.isStopped || (this.isStopped = !0, this._complete()); }, t.prototype.unsubscribe = function() { this.closed || (this.isStopped = !0, e.prototype.unsubscribe.call(this), this.destination = null); }, t.prototype._next = function(r) { this.destination.next(r); }, t.prototype._error = function(r) { try { this.destination.error(r); } finally { this.unsubscribe(); } }, t.prototype._complete = function() { try { this.destination.complete(); } finally { this.unsubscribe(); } }, t; })(st), Qa = (function() { function e(t) { this.partialObserver = t; } return e.prototype.next = function(t) { var r = this.partialObserver; if (r.next) try { r.next(t); } catch (n) { pt(n); } }, e.prototype.error = function(t) { var r = this.partialObserver; if (r.error) try { r.error(t); } catch (n) { pt(n); } else pt(t); }, e.prototype.complete = function() { var t = this.partialObserver; if (t.complete) try { t.complete(); } catch (r) { pt(r); } }, e; })(), Xt = (function(e) { Ee(t, e); function t(r, n, a) { var i = e.call(this) || this, s; return Y(r) || !r ? s = { next: r ?? void 0, error: n ?? void 0, complete: a ?? void 0 } : s = r, i.destination = new Qa(s), i; } return t; })(ir); function pt(e) { En(e); } function Xa(e) { throw e; } var ei = { closed: !0, next: Ir, error: Xa, complete: Ir }, sr = (function() { return typeof Symbol == "function" && Symbol.observable || "@@observable"; })(); function ti(e) { return e; } function ri(e) { return e.length === 0 ? ti : e.length === 1 ? e[0] : function(r) { return e.reduce(function(n, a) { return a(n); }, r); }; } var we = (function() { function e(t) { t && (this._subscribe = t); } return e.prototype.lift = function(t) { var r = new e(); return r.source = this, r.operator = t, r; }, e.prototype.subscribe = function(t, r, n) { var a = this, i = oi(t) ? t : new Xt(t, r, n); return gt(function() { var s = a, l = s.operator, c = s.source; i.add(l ? l.call(i, c) : c ? a._subscribe(i) : a._trySubscribe(i)); }), i; }, e.prototype._trySubscribe = function(t) { try { return this._subscribe(t); } catch (r) { t.error(r); } }, e.prototype.forEach = function(t, r) { var n = this; return r = Rr(r), new r(function(a, i) { var s = new Xt({ next: function(l) { try { t(l); } catch (c) { i(c), s.unsubscribe(); } }, error: i, complete: a }); n.subscribe(s); }); }, e.prototype._subscribe = function(t) { var r; return (r = this.source) === null || r === void 0 ? void 0 : r.subscribe(t); }, e.prototype[sr] = function() { return this; }, e.prototype.pipe = function() { for (var t = [], r = 0; r < arguments.length; r++) t[r] = arguments[r]; return ri(t)(this); }, e.prototype.toPromise = function(t) { var r = this; return t = Rr(t), new t(function(n, a) { var i; r.subscribe(function(s) { return i = s; }, function(s) { return a(s); }, function() { return n(i); }); }); }, e.create = function(t) { return new e(t); }, e; })(); function Rr(e) { var t; return (t = e ?? Ja.Promise) !== null && t !== void 0 ? t : Promise; } function ni(e) { return e && Y(e.next) && Y(e.error) && Y(e.complete); } function oi(e) { return e && e instanceof ir || ni(e) && Pn(e); } function ai(e) { return Y(e?.lift); } function ii(e) { return function(t) { if (ai(t)) return t.lift(function(r) { try { return e(r, this); } catch (n) { this.error(n); } }); throw new TypeError("Unable to lift unknown Observable type"); }; } function si(e, t, r, n, a) { return new ci(e, t, r, n, a); } var ci = (function(e) { Ee(t, e); function t(r, n, a, i, s, l) { var c = e.call(this, r) || this; return c.onFinalize = s, c.shouldUnsubscribe = l, c._next = n ? function(u) { try { n(u); } catch (d) { r.error(d); } } : e.prototype._next, c._error = i ? function(u) { try { i(u); } catch (d) { r.error(d); } finally { this.unsubscribe(); } } : e.prototype._error, c._complete = a ? function() { try { a(); } catch (u) { r.error(u); } finally { this.unsubscribe(); } } : e.prototype._complete, c; } return t.prototype.unsubscribe = function() { var r; if (!this.shouldUnsubscribe || this.shouldUnsubscribe()) { var n = this.closed; e.prototype.unsubscribe.call(this), !n && ((r = this.onFinalize) === null || r === void 0 || r.call(this)); } }, t; })(ir), li = Nt(function(e) { return function() { e(this), this.name = "ObjectUnsubscribedError", this.message = "object unsubscribed"; }; }), Cn = (function(e) { Ee(t, e); function t() { var r = e.call(this) || this; return r.closed = !1, r.currentObservers = null, r.observers = [], r.isStopped = !1, r.hasError = !1, r.thrownError = null, r; } return t.prototype.lift = function(r) { var n = new Fr(this, this); return n.operator = r, n; }, t.prototype._throwIfClosed = function() { if (this.closed) throw new li(); }, t.prototype.next = function(r) { var n = this; gt(function() { var a, i; if (n._throwIfClosed(), !n.isStopped) { n.currentObservers || (n.currentObservers = Array.from(n.observers)); try { for (var s = Oe(n.currentObservers), l = s.next(); !l.done; l = s.next()) { var c = l.value; c.next(r); } } catch (u) { a = { error: u }; } finally { try { l && !l.done && (i = s.return) && i.call(s); } finally { if (a) throw a.error; } } } }); }, t.prototype.error = function(r) { var n = this; gt(function() { if (n._throwIfClosed(), !n.isStopped) { n.hasError = n.isStopped = !0, n.thrownError = r; for (var a = n.observers; a.length; ) a.shift().error(r); } }); }, t.prototype.complete = function() { var r = this; gt(function() { if (r._throwIfClosed(), !r.isStopped) { r.isStopped = !0; for (var n = r.observers; n.length; ) n.shift().complete(); } }); }, t.prototype.unsubscribe = function() { this.isStopped = this.closed = !0, this.observers = this.currentObservers = null; }, Object.defineProperty(t.prototype, "observed", { get: function() { var r; return ((r = this.observers) === null || r === void 0 ? void 0 : r.length) > 0; }, enumerable: !1, configurable: !0 }), t.prototype._trySubscribe = function(r) { return this._throwIfClosed(), e.prototype._trySubscribe.call(this, r); }, t.prototype._subscribe = function(r) { return this._throwIfClosed(), this._checkFinalizedStatuses(r), this._innerSubscribe(r); }, t.prototype._innerSubscribe = function(r) { var n = this, a = this, i = a.hasError, s = a.isStopped, l = a.observers; return i || s ? bn : (this.currentObservers = null, l.push(r), new st(function() { n.currentObservers = null, At(l, r); })); }, t.prototype._checkFinalizedStatuses = function(r) { var n = this, a = n.hasError, i = n.thrownError, s = n.isStopped; a ? r.error(i) : s && r.complete(); }, t.prototype.asObservable = function() { var r = new we(); return r.source = this, r; }, t.create = function(r, n) { return new Fr(r, n); }, t; })(we), Fr = (function(e) { Ee(t, e); function t(r, n) { var a = e.call(this) || this; return a.destination = r, a.source = n, a; } return t.prototype.next = function(r) { var n, a; (a = (n = this.destination) === null || n === void 0 ? void 0 : n.next) === null || a === void 0 || a.call(n, r); }, t.prototype.error = function(r) { var n, a; (a = (n = this.destination) === null || n === void 0 ? void 0 : n.error) === null || a === void 0 || a.call(n, r); }, t.prototype.complete = function() { var r, n; (n = (r = this.destination) === null || r === void 0 ? void 0 : r.complete) === null || n === void 0 || n.call(r); }, t.prototype._subscribe = function(r) { var n, a; return (a = (n = this.source) === null || n === void 0 ? void 0 : n.subscribe(r)) !== null && a !== void 0 ? a : bn; }, t; })(Cn), ui = { now: function() { return Date.now(); } }, di = (function(e) { Ee(t, e); function t(r, n) { return e.call(this) || this; } return t.prototype.schedule = function(r, n) { return this; }, t; })(st), Tr = { setInterval: function(e, t) { for (var r = [], n = 2; n < arguments.length; n++) r[n - 2] = arguments[n]; return setInterval.apply(void 0, Ct([e, t], Et(r))); }, clearInterval: function(e) { return clearInterval(e); }, delegate: void 0 }, pi = (function(e) { Ee(t, e); function t(r, n) { var a = e.call(this, r, n) || this; return a.scheduler = r, a.work = n, a.pending = !1, a; } return t.prototype.schedule = function(r, n) { var a; if (n === void 0 && (n = 0), this.closed) return this; this.state = r; var i = this.id, s = this.scheduler; return i != null && (this.id = this.recycleAsyncId(s, i, n)), this.pending = !0, this.delay = n, this.id = (a = this.id) !== null && a !== void 0 ? a : this.requestAsyncId(s, this.id, n), this; }, t.prototype.requestAsyncId = function(r, n, a) { return a === void 0 && (a = 0), Tr.setInterval(r.flush.bind(r, this), a); }, t.prototype.recycleAsyncId = function(r, n, a) { if (a === void 0 && (a = 0), a != null && this.delay === a && this.pending === !1) return n; n != null && Tr.clearInterval(n); }, t.prototype.execute = function(r, n) { if (this.closed) return new Error("executing a cancelled action"); this.pending = !1; var a = this._execute(r, n); if (a) return a; this.pending === !1 && this.id != null && (this.id = this.recycleAsyncId(this.scheduler, this.id, null)); }, t.prototype._execute = function(r, n) { var a = !1, i; try { this.work(r); } catch (s) { a = !0, i = s || new Error("Scheduled action threw falsy error"); } if (a) return this.unsubscribe(), i; }, t.prototype.unsubscribe = function() { if (!this.closed) { var r = this, n = r.id, a = r.scheduler, i = a.actions; this.work = this.state = this.scheduler = null, this.pending = !1, At(i, this), n != null && (this.id = this.recycleAsyncId(a, n, null)), this.delay = null, e.prototype.unsubscribe.call(this); } }, t; })(di), Nr = (function() { function e(t, r) { r === void 0 && (r = e.now), this.schedulerActionCtor = t, this.now = r; } return e.prototype.schedule = function(t, r, n) { return r === void 0 && (r = 0), new this.schedulerActionCtor(this, t).schedule(n, r); }, e.now = ui.now, e; })(), mi = (function(e) { Ee(t, e); function t(r, n) { n === void 0 && (n = Nr.now); var a = e.call(this, r, n) || this; return a.actions = [], a._active = !1, a; } return t.prototype.flush = function(r) { var n = this.actions; if (this._active) { n.push(r); return; } var a; this._active = !0; do if (a = r.execute(r.state, r.delay)) break; while (r = n.shift()); if (this._active = !1, a) { for (; r = n.shift(); ) r.unsubscribe(); throw a; } }, t; })(Nr), fi = new mi(pi), _i = (function(e) { return e && typeof e.length == "number" && typeof e != "function"; }); function yi(e) { return Y(e?.then); } function hi(e) { return Y(e[sr]); } function gi(e) { return Symbol.asyncIterator && Y(e?.[Symbol.asyncIterator]); } function wi(e) { return new TypeError("You provided " + (e !== null && typeof e == "object" ? "an invalid object" : "'" + e + "'") + " where a stream was expected. You can provide an Observable, Promise, ReadableStream, Array, AsyncIterable, or Iterable."); } function vi() { return typeof Symbol != "function" || !Symbol.iterator ? "@@iterator" : Symbol.iterator; } var bi = vi(); function Pi(e) { return Y(e?.[bi]); } function Ei(e) { return Ya(this, arguments, function() { var r, n, a, i; return vn(this, function(s) { switch (s.label) { case 0: r = e.getReader(), s.label = 1; case 1: s.trys.push([1, , 9, 10]), s.label = 2; case 2: return [4, Me(r.read())]; case 3: return n = s.sent(), a = n.value, i = n.done, i ? [4, Me(void 0)] : [3, 5]; case 4: return [2, s.sent()]; case 5: return [4, Me(a)]; case 6: return [4, s.sent()]; case 7: return s.sent(), [3, 2]; case 8: return [3, 10]; case 9: return r.releaseLock(), [7]; case 10: return [2]; } }); }); } function Ci(e) { return Y(e?.getReader); } function Ai(e) { if (e instanceof we) return e; if (e != null) { if (hi(e)) return Si(e); if (_i(e)) return ki(e); if (yi(e)) return Ii(e); if (gi(e)) return An(e); if (Pi(e)) return Ri(e); if (Ci(e)) return Fi(e); } throw wi(e); } function Si(e) { return new we(function(t) { var r = e[sr](); if (Y(r.subscribe)) return r.subscribe(t); throw new TypeError("Provided object does not correctly implement Symbol.observable"); }); } function ki(e) { return new we(function(t) { for (var r = 0; r < e.length && !t.closed; r++) t.next(e[r]); t.complete(); }); } function Ii(e) { return new we(function(t) { e.then(function(r) { t.closed || (t.next(r), t.complete()); }, function(r) { return t.error(r); }).then(null, En); }); } function Ri(e) { return new we(function(t) { var r, n; try { for (var a = Oe(e), i = a.next(); !i.done; i = a.next()) { var s = i.value; if (t.next(s), t.closed) return; } } catch (l) { r = { error: l }; } finally { try { i && !i.done && (n = a.return) && n.call(a); } finally { if (r) throw r.error; } } t.complete(); }); } function An(e) { return new we(function(t) { Ti(e, t).catch(function(r) { return t.error(r); }); }); } function Fi(e) { return An(Ei(e)); } function Ti(e, t) { var r, n, a, i; return Ka(this, void 0, void 0, function() { var s, l; return vn(this, function(c) { switch (c.label) { case 0: c.trys.push([0, 5, 6, 11]), r = Wa(e), c.label = 1; case 1: return [4, r.next()]; case 2: if (n = c.sent(), !!n.done) return [3, 4]; if (s = n.value, t.next(s), t.closed) return [2]; c.label = 3; case 3: return [3, 1]; case 4: return [3, 11]; case 5: return l = c.sent(), a = { error: l }, [3, 11]; case 6: return c.trys.push([6, , 9, 10]), n && !n.done && (i = r.return) ? [4, i.call(r)] : [3, 8]; case 7: c.sent(), c.label = 8; case 8: return [3, 10]; case 9: if (a) throw a.error; return [7]; case 10: return [7]; case 11: return t.complete(), [2]; } }); }); } function Ni(e, t, r, n, a) { n === void 0 && (n = 0), a === void 0 && (a = !1); var i = t.schedule(function() { r(), a ? e.add(this.schedule(null, n)) : this.unsubscribe(); }, n); if (e.add(i), !a) return i; } function Li(e, t) { var r = Y(e) ? e : function() { return e; }, n = function(a) { return a.error(r()); }; return new we(n); } var Mi = Nt(function(e) { return function() { e(this), this.name = "EmptyError", this.message = "no elements in sequence"; }; }); function xi(e, t) { return new Promise(function(r, n) { var a = !1, i; e.subscribe({ next: function(s) { i = s, a = !0; }, error: n, complete: function() { a ? r(i) : n(new Mi()); } }); }); } function Di(e) { return e instanceof Date && !isNaN(e); } var Ui = Nt(function(e) { return function(r) { r === void 0 && (r = null), e(this), this.message = "Timeout has occurred", this.name = "TimeoutError", this.info = r; }; }); function Oi(e, t) { var r = Di(e) ? { first: e } : typeof e == "number" ? { each: e } : e, n = r.first, a = r.each, i = r.with, s = i === void 0 ? ji : i, l = r.scheduler, c = l === void 0 ? fi : l, u = r.meta, d = u === void 0 ? null : u; if (n == null && a == null) throw new TypeError("No timeout provided."); return ii(function(m, f) { var y, _, g = null, w = 0, h = function(b) { _ = Ni(f, c, function() { try { y.unsubscribe(), Ai(s({ meta: d, lastValue: g, seen: w })).subscribe(f); } catch (S) { f.error(S); } }, b); }; y = m.subscribe(si(f, function(b) { _?.unsubscribe(), w++, f.next(g = b), a > 0 && h(a); }, void 0, void 0, function() { _?.cl