@getopenpay/openpay-js
Version:
Accept payments through OpenPay, right on your site
1,728 lines • 657 kB
JavaScript
import { z as o } from "zod";
import { v4 as Ge } from "uuid";
import { connectToChild as jt } from "penpal";
import Me from "chalk";
const xt = "https://cde.getopenpay.com", Vn = o.object({
type: o.string(),
loc: o.array(o.string()),
msg: o.string(),
url: o.string()
}), zn = o.array(Vn), qn = o.object({
code: o.string(),
message: o.string(),
path: o.array(o.string())
}), Yn = o.array(qn), Bn = {
"failed to fetch": "Connection error: please double check if you are connected to the internet, then try again"
}, tt = (e) => {
const n = e.toLowerCase().trim();
return Bn[n] ?? e;
}, Hn = (e) => {
try {
return typeof JSON.parse(e) == "object";
} catch {
return !1;
}
}, Jn = (e) => e.length === 1 ? tt(e[0].msg) : `Please fix the following errors:
${e.map((t) => `• ${tt(t.msg)}`).join(`
`)}`, Kn = (e) => `Encountered the following errors:
${e.map((t) => `- ${t.path.join("/")}: ${t.message}`).join(`
`)}`, V = (e) => {
if (e instanceof Error)
if (Hn(e.message)) {
const n = JSON.parse(e.message);
return zn.safeParse(n).success ? Jn(n) : Yn.safeParse(n).success ? Kn(n) : (console.warn(`Encountered unknown stringified JSON object:
${e.message}`), e.message);
} else
return tt(e.message);
if (typeof e == "object")
try {
return JSON.stringify(e);
} catch (n) {
return n + "";
}
else
return e + "";
}, Zn = (e, n, t) => (...r) => {
try {
return n(...r);
} catch (s) {
t(`[form] Error running callback (${e}):`, s);
return;
}
};
var G = /* @__PURE__ */ ((e) => (e.pockytPaypal = "pockyt-paypal", e.airwallexGooglePay = "airwallex-google-pay", e.airwallexApplePay = "airwallex-apple-pay", e.authorizenetGooglePay = "authorizenet-google-pay", e.authorizenetApplePay = "authorizenet-apple-pay", e.loopCrypto = "loop-crypto", e))(G || {});
const ua = o.nativeEnum(G), T = o.string().trim().min(1, { message: "Cannot be blank" }), E = o.string().trim().optional(), j = (e) => o.nullable(e.optional());
var p = /* @__PURE__ */ ((e) => (e.FIRST_NAME = "firstName", e.LAST_NAME = "lastName", e.EMAIL = "email", e.ZIP_CODE = "zipCode", e.CITY = "city", e.STATE = "state", e.COUNTRY = "country", e.ADDRESS = "address", e.PHONE = "phone", e.PROMOTION_CODE = "promotionCode", e))(p || {});
const $t = o.nativeEnum(p);
var Gt = /* @__PURE__ */ ((e) => (e.CARD_NUMBER = "cardNumber", e.CARD_EXPIRY = "cardExpiry", e.CARD_CVC = "cardCvc", e))(Gt || {});
const Vt = o.nativeEnum(Gt), zt = o.union([$t, Vt]);
var W = /* @__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))(W || {});
const Wn = o.nativeEnum(W), Ve = o.object({
provider: o.string(),
processor_name: j(o.string()),
metadata: j(o.record(o.string(), o.any()))
}), Qn = o.object({
id: o.string()
});
o.object({
cardNumber: E,
expiry: E,
cvc: E
});
o.object({
backgroundColor: E,
color: E,
fontFamily: E,
fontSize: E,
fontWeight: E,
margin: E,
padding: E,
letterSpacing: E,
lineHeight: E,
hideIcon: E
});
const H = 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"
]), Xn = H.extract(["TOKENIZE_STARTED", "CHECKOUT_STARTED"]), er = o.object({ type: Xn }), tr = H.extract(["BLUR", "FOCUS", "CHANGE"]), nr = o.object({
type: tr,
elementType: Vt,
errors: o.array(o.string()).optional()
}), rr = H.extract(["LOAD_ERROR", "TOKENIZE_ERROR", "CHECKOUT_ERROR"]), or = o.object({
type: rr,
message: T,
headers: o.record(o.string(), o.string()).optional()
}), sr = H.extract(["VALIDATION_ERROR"]), ir = o.object({
type: sr,
elementType: zt,
errors: o.array(o.string())
}), ar = o.object({
type: o.literal(H.enum.LAYOUT),
height: T
}), cr = o.object({
type: o.literal(H.enum.LOADED),
sessionId: T,
totalAmountAtoms: o.number(),
currency: E,
checkoutPaymentMethods: o.array(Ve)
}), lr = o.object({
type: o.literal(H.enum.PAYMENT_FLOW_STARTED),
nextActionMetadata: o.record(o.string(), o.any()),
paymentFlowMetadata: o.any().optional(),
startPFMetadata: o.optional(o.record(o.string(), o.any()))
}), ur = o.object({
type: o.literal(H.enum.SETUP_PAYMENT_METHOD_SUCCESS),
paymentMethodId: o.string()
}), Ie = o.object({
firstName: T,
lastName: T,
email: T,
zipCode: T,
country: T,
promotionCode: E
}), dr = o.object({
firstName: E,
lastName: E,
email: T,
zipCode: T,
country: T,
promotionCode: E,
address: E,
city: E,
state: E
}), pr = H.extract(["TOKENIZE", "CHECKOUT", "START_PAYMENT_FLOW"]), mr = o.object({
type: pr,
sessionId: T,
checkoutPaymentMethod: Ve,
paymentFlowMetadata: o.any().optional(),
doNotUseLegacyCCFlow: o.boolean().optional(),
existingCCPMId: E
}).extend(Ie.shape), yr = o.object({
type: o.literal(H.enum.TOKENIZE_SUCCESS),
isReadyForCheckout: o.boolean()
}), fr = o.object({
type: o.literal(H.enum.CHECKOUT_SUCCESS),
invoiceUrls: o.array(o.string()),
subscriptionIds: o.array(o.string()),
customerId: o.string()
}), _r = o.discriminatedUnion("type", [
er,
nr,
or,
ir,
ar,
cr,
mr,
yr,
fr,
lr,
ur
]), hr = o.object({
payload: _r,
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: j(o.string()),
their_pm_id: j(o.string()),
checkout_attempt_id: j(o.string()),
processor_specific_metadata: j(o.record(o.string(), o.any()))
});
const it = o.object({
invoice_urls: o.array(o.string()),
subscription_ids: o.array(o.string()),
customer_id: o.string(),
processors_used: j(o.array(o.string()))
}), gr = o.object({
elementType: o.string(),
errors: o.array(o.string())
});
o.object({
session_id: o.string()
});
const wr = o.object({
success: o.literal(!1),
error_type: o.literal("validation_error"),
errors: o.array(gr)
}), br = o.discriminatedUnion("success", [
o.object({ success: o.literal(!0) }),
wr
]);
o.object({
session_id: o.string(),
checkout_payment_method: Ve,
non_cde_form_fields: Ie,
do_not_use_legacy_cc_flow: o.boolean().optional(),
existing_cc_pm_id: j(o.string()),
extra_metadata: o.record(o.string(), o.any())
});
o.object({
session_id: o.string(),
checkout_payment_method: Ve,
non_cde_form_fields: Ie,
extra_metadata: o.record(o.string(), o.any()).optional()
});
var F = /* @__PURE__ */ ((e) => (e.SUCCESS = "success", e.FAILURE = "failure", e.CANCELLED = "cancelled", e))(F || {});
const vr = o.object({
status: o.enum([
"success",
"failure",
"cancelled"
/* CANCELLED */
]),
href: o.string().optional().nullable()
});
o.object({
href: o.string().optional().nullable()
});
const Er = o.object({
type: o.string(),
redirect_url: o.string(),
initial_intent_id: o.string(),
consent_id: o.string(),
their_pm_id: o.string().optional()
}), qt = o.object({
type: o.string(),
redirect_url: j(o.string()),
initial_intent_id: j(o.string()),
consent_id: j(o.string()),
their_pm_id: j(o.string()),
payment_session: j(o.record(o.string(), o.any()))
}), Cr = o.discriminatedUnion("present", [
o.object({ present: o.literal(!0), href: o.string() }),
o.object({ present: o.literal(!1) })
]), Sr = o.object({
payment_methods: o.array(Qn),
pay_first_success_response: j(it),
required_user_actions: j(o.array(qt))
}), Yt = (e) => {
const n = {};
return Object.entries(e).forEach(([t, r]) => {
try {
const s = $t.parse(t);
Array.isArray(r) ? n[s] = r : Array.isArray(r._errors) && (n[s] = r._errors);
} catch {
return;
}
}), n;
}, Pr = o.object({
stripe_pk: o.string(),
client_secret: o.string(),
stripe_pm_id: o.string()
}), kr = o.object({
type: o.string(),
client_secret: o.string(),
stripe_pk: o.string()
}), Ar = {
usd: "usd",
brl: "brl"
}, ze = async (e) => {
for (let t = 0; t < 10; t++)
mt() || await at(500);
if (!mt())
throw console.log("Stripe JS not found."), new Error("Stripe JS not found.");
return new Stripe(e);
}, Ir = async (e, n) => {
const t = await ze(e);
return {
elements: t.elements(n),
stripe: t
};
}, Tr = async (e, n, t, r, s) => {
const i = await ze(e), a = Ar[t.toLowerCase().trim()];
return i.paymentRequest({
// TODO: replace this with stripe account country as soon as we support it
country: "US",
currency: a,
total: {
label: "Total",
amount: n,
pending: r
},
// requestShipping: true,
requestPayerName: !0,
requestPayerEmail: !0,
disableWallets: []
});
}, at = (e) => new Promise((n) => {
setTimeout(n, e);
}), mt = () => "Stripe" in window, Rr = async (e) => new Promise((n, t) => {
try {
e.on("paymentmethod", async (r) => {
console.log("paymentmethod EVT:: ", r), n(r);
}), e.on("token", async (r) => {
console.log("token EVT:: ", r);
}), e.on("cancel", () => {
t(new Error("Payment cancelled, please click Submit again to pay"));
});
} catch (r) {
t(r);
}
}), Fr = async (e, n) => {
if (!e.stripe_pk || !e.client_secret)
throw new Error(`Invalid next action metadata format: ${JSON.stringify(e)}`);
const r = await (await ze(e.stripe_pk)).confirmCardSetup(e.client_secret, {
payment_method: n.paymentMethod.id
});
if (r.error)
throw n.complete("fail"), new Error(`Payment failed: ${r.error.message ?? "unknown"}`);
return n.complete("success"), r;
}, Mr = async (e) => {
var s, i, a, c;
const t = await (await ze(e.stripe_pk)).confirmCardSetup(e.client_secret, {
payment_method: e.stripe_pm_id
}), r = (s = t.setupIntent) == null ? void 0 : s.status;
if (r === "succeeded")
console.log("[3DS] CONFIRMING PM:", e.stripe_pm_id), console.log("[3DS] Setup intent created:", t.setupIntent);
else throw r === "canceled" ? new Error("Payment cancelled, please click Submit again to pay") : new Error(
`${((i = t.error) == null ? void 0 : i.message) ?? ((c = (a = t.setupIntent) == null ? void 0 : a.last_setup_error) == null ? void 0 : c.message) ?? "Payment failed, please click submit again to pay."}`
);
}, Dr = (e) => JSON.stringify(e), X = (e, n) => Array.from(e.querySelectorAll("[data-opid]") ?? []).reduce((s, i) => {
const a = i.getAttribute("data-opid");
return a ? { ...s, [a]: i.value } : s;
}, {}), Nr = (e) => {
try {
return hr.parse(e);
} catch (n) {
throw console.error("Error parsing event payload:", e, n), n;
}
}, Lr = async (e) => {
if (typeof e != "object" || !e) return !1;
try {
const n = { type: "ping" }, t = await e.send(n);
if (t !== !0)
throw new Error(`Expected 'true' after ping, got ${JSON.stringify(t)}`);
return !0;
} catch (n) {
return console.error("Invalid CDE connection check:", n), !1;
}
}, Or = (e, n) => !!e && n, b = (e) => o.nullable(e.optional());
o.string().trim().min(1, { message: "Cannot be blank" });
const Ur = o.object({
cde_response_type: o.literal("error"),
message: o.string(),
headers: o.record(o.string(), o.string()).optional()
});
o.enum(["usd", "brl"]);
const Bt = o.object({
name: o.string(),
amount_atom_off: b(o.number()),
percent_off: b(o.number()),
currency: b(o.string()),
duration: o.string(),
duration_in_months: b(o.number())
}), Ht = o.object({
amount_subtotal_atom: o.number().int(),
amount_total_atom: o.number().int(),
currency: o.string(),
description: b(o.string()),
price_id: o.string(),
billing_interval: b(o.string()),
billing_interval_count: b(o.number().int()),
quantity: o.number().int()
}), jr = o.record(o.string(), o.any()), xr = o.object({
name: o.string(),
settings: b(jr)
}), he = o.object({
provider: o.string(),
processor_name: b(o.string()),
metadata: b(o.record(o.string(), o.any()))
}), $r = o.object({
quantity: o.number()
}), Gr = o.object({
id: b(o.string()),
billing_interval: b(o.string()),
billing_interval_count: b(o.number().int()),
subscription_items: o.array($r),
trial_start: b(o.string()),
trial_end: b(o.string())
}), Jt = o.object({
amount_atom: o.number()
}), Vr = o.object({
amount_atom: o.number(),
amount_atom_considering_discount_applied: o.number(),
currency: o.string(),
discount_amount_atoms: o.array(Jt),
subscription_item_id: o.string()
}), zr = o.object({
coupon: Bt
}), qr = o.object({
currency: o.string(),
discounts: o.array(zr),
hosted_invoice_url: b(o.string()),
lines: o.array(Vr),
remaining_amount_atom: o.number(),
tax_amount_atom: o.number(),
total_amount_atom: o.number(),
total_discount_amount_atoms: o.array(Jt)
}), yt = o.object({
created: o.array(Gr),
invoices: o.array(qr),
processors_used: b(o.array(o.string()))
}), Kt = o.object({
preview: yt,
preview_post_trial: b(yt),
coupons: o.array(Bt)
}), ft = o.object({
status: o.literal("open"),
locale: b(o.string()),
token: o.string(),
email: b(o.string()),
line_items: o.array(Ht),
amount_subtotal_atom: o.number().int(),
amount_total_atom: o.number().int(),
brand: xr,
subs_preview: b(Kt),
// Null in setup mode
methods_available: o.array(he)
}), Zt = o.discriminatedUnion("mode", [
o.object({
mode: o.literal("setup"),
currency: o.nullable(o.undefined())
}).extend(ft.shape),
o.object({
mode: o.enum(["payment", "subscription"]),
currency: o.string()
}).extend(ft.shape)
]), Yr = o.object({
status: o.literal("complete")
}), Br = o.object({
status: o.literal("expired")
});
o.union([Zt, Yr, Br]);
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()
});
o.object({
secure_token: o.string(),
payment_input: o.any(),
// Should follow AnyPaymentInput from CDE
customer_first_name: o.string().optional(),
customer_last_name: o.string().optional(),
customer_email: o.string(),
customer_zip_code: o.string(),
customer_country: o.string(),
line_items: o.array(Ht),
total_amount_atom: o.number().int(),
cancel_at_end: o.boolean(),
checkout_payment_method: he,
promotion_code: o.string().optional(),
do_not_use_legacy_cc_flow: o.boolean().optional(),
use_confirmed_pm_id: b(o.string())
});
const Wt = o.object({
payment_method_id: o.string()
});
o.object({
id: o.string(),
return_url: o.string()
});
const Hr = o.object({
type: o.string(),
loc: o.array(o.string()),
msg: o.string(),
url: o.string()
});
o.array(Hr);
const Jr = o.object({
new_customer_email: o.string().optional(),
new_customer_address: o.record(o.string(), o.any()).optional(),
new_customer_first_name: o.string().optional(),
new_customer_last_name: o.string().optional()
}), Kr = o.object({
price_id: o.string(),
quantity: o.number().int()
}), Zr = o.object({
line_items: o.array(Kr),
promotion_code: o.string().optional(),
displayed_total_amount_atom: o.number().int()
}), Wr = o.object({
processor_specific_metadata: b(o.record(o.string(), o.any()))
});
o.object({
payment_provider: o.string(),
checkout_payment_method: he,
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: Zr.optional()
}).extend(Jr.shape).extend(Wr.shape);
const Qt = o.object({
required_user_actions: o.array(o.record(o.string(), o.any())),
checkout_attempt_id: b(o.string())
});
o.object({
fields: dr,
checkoutPaymentMethod: he
});
o.object({
session_id: o.string(),
non_cde_form_fields: Ie,
checkout_payment_method: he,
extra_metadata: o.record(o.string(), o.any())
// This is optional in CDE, but not in OJS moving forward
});
const Qr = o.object({
required_user_actions: o.array(o.record(o.string(), o.any())),
cc_pm_id: o.string()
});
o.record(o.any());
o.object({
first_name: b(o.string()),
last_name: b(o.string()),
line1: b(o.string()),
line2: b(o.string()),
line3: b(o.string()),
city: b(o.string()),
state: b(o.string()),
country: b(o.string()),
zip_code: b(o.string()),
email: b(o.string()),
billing_email: b(o.string()),
phone_number: b(o.string()),
update_processor_customer: b(o.boolean())
});
o.object({
id: o.string(),
email: b(o.string()),
first_name: b(o.string()),
last_name: b(o.string()),
phone_number: b(o.string()),
billing_email: b(o.string()),
address: b(o.record(o.string(), o.any()))
});
o.object({
message: o.string()
});
const Xr = o.object({
error_code: o.string()
});
o.object({
checkout_payment_method: he,
processor_specific_metadata: o.record(o.any()).optional()
});
const eo = o.object({
next_action_metadata: b(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 to = o.object({}), no = (e) => e.reduce((n, t) => n + t, 0);
function ro(e, n) {
var t = Object.setPrototypeOf;
t ? t(e, n) : e.__proto__ = n;
}
function oo(e, n) {
n === void 0 && (n = e.constructor);
var t = Error.captureStackTrace;
t && t(e, n);
}
var so = /* @__PURE__ */ function() {
var e = function(t, r) {
return e = Object.setPrototypeOf || {
__proto__: []
} instanceof Array && function(s, i) {
s.__proto__ = i;
} || function(s, i) {
for (var a in i)
Object.prototype.hasOwnProperty.call(i, a) && (s[a] = i[a]);
}, e(t, r);
};
return function(n, t) {
if (typeof t != "function" && t !== null) throw new TypeError("Class extends value " + String(t) + " is not a constructor or null");
e(n, t);
function r() {
this.constructor = n;
}
n.prototype = t === null ? Object.create(t) : (r.prototype = t.prototype, new r());
};
}(), io = function(e) {
so(n, e);
function n(t, r) {
var s = this.constructor, i = e.call(this, t, r) || this;
return Object.defineProperty(i, "name", {
value: s.name,
enumerable: !1,
configurable: !0
}), ro(i, s.prototype), oo(i), i;
}
return n;
}(Error);
const re = (e) => async (n) => {
var t, r;
try {
(r = (t = n.formCallbacks.get).onCheckoutStarted) == null || r.call(t), g("checkout_started", {
cpm: n.checkoutPaymentMethod
});
const s = await e(n);
if (g("checkout_success", {
cpm: n.checkoutPaymentMethod,
...s
}), s.mode === "setup")
n.formCallbacks.get.onSetupPaymentMethodSuccess(s.result.payment_method_id);
else if (s.mode === "checkout")
n.formCallbacks.get.onCheckoutSuccess(
s.result.invoice_urls,
s.result.subscription_ids,
s.result.customer_id,
s.result.processors_used ?? []
);
else
throw new Error(`Unhandled mode: ${s}`);
} catch (s) {
const i = V(s), a = await fn(n.context.anyCdeConnection, i);
n.formCallbacks.get.onCheckoutError(i, a), g("checkout_error", { cpm: n.checkoutPaymentMethod, errorMessage: i, errorCode: a });
}
}, de = (e) => async (n) => {
try {
return await e(n);
} catch (t) {
const { err__: r } = A("init-error-catcher"), s = V(t), i = await fn(n.context.anyCdeConnection, s);
return r(i, s, t), g("init_flow_error", { errorMessage: s, errorCode: i }), { isAvailable: !1, reason: s, errorCode: i, isLoading: !1 };
}
}, A = (e) => {
const n = (...r) => {
window.console.log(`${Me.green.bold("ojs/")}${Me.bold.gray(`${e}`)} `, ...r);
}, t = (...r) => {
window.console.warn(`${Me.red.bold("ojs/")}${Me.bold.gray(`${e}`)} `, ...r);
};
return {
log: n,
err: t,
log__: n,
err__: t
};
};
var nt = function(e, n) {
return nt = Object.setPrototypeOf || { __proto__: [] } instanceof Array && function(t, r) {
t.__proto__ = r;
} || function(t, r) {
for (var s in r) Object.prototype.hasOwnProperty.call(r, s) && (t[s] = r[s]);
}, nt(e, n);
};
function oe(e, n) {
if (typeof n != "function" && n !== null)
throw new TypeError("Class extends value " + String(n) + " is not a constructor or null");
nt(e, n);
function t() {
this.constructor = e;
}
e.prototype = n === null ? Object.create(n) : (t.prototype = n.prototype, new t());
}
function ao(e, n, t, r) {
function s(i) {
return i instanceof t ? i : new t(function(a) {
a(i);
});
}
return new (t || (t = Promise))(function(i, a) {
function c(d) {
try {
u(r.next(d));
} catch (f) {
a(f);
}
}
function l(d) {
try {
u(r.throw(d));
} catch (f) {
a(f);
}
}
function u(d) {
d.done ? i(d.value) : s(d.value).then(c, l);
}
u((r = r.apply(e, n || [])).next());
});
}
function Xt(e, n) {
var t = { label: 0, sent: function() {
if (i[0] & 1) throw i[1];
return i[1];
}, trys: [], ops: [] }, r, s, i, a = Object.create((typeof Iterator == "function" ? Iterator : Object).prototype);
return a.next = c(0), a.throw = c(1), a.return = c(2), typeof Symbol == "function" && (a[Symbol.iterator] = function() {
return this;
}), a;
function c(u) {
return function(d) {
return l([u, d]);
};
}
function l(u) {
if (r) throw new TypeError("Generator is already executing.");
for (; a && (a = 0, u[0] && (t = 0)), t; ) try {
if (r = 1, s && (i = u[0] & 2 ? s.return : u[0] ? s.throw || ((i = s.return) && i.call(s), 0) : s.next) && !(i = i.call(s, u[1])).done) return i;
switch (s = 0, i && (u = [u[0] & 2, i.value]), u[0]) {
case 0:
case 1:
i = u;
break;
case 4:
return t.label++, { value: u[1], done: !1 };
case 5:
t.label++, s = u[1], u = [0];
continue;
case 7:
u = t.ops.pop(), t.trys.pop();
continue;
default:
if (i = t.trys, !(i = i.length > 0 && i[i.length - 1]) && (u[0] === 6 || u[0] === 2)) {
t = 0;
continue;
}
if (u[0] === 3 && (!i || u[1] > i[0] && u[1] < i[3])) {
t.label = u[1];
break;
}
if (u[0] === 6 && t.label < i[1]) {
t.label = i[1], i = u;
break;
}
if (i && t.label < i[2]) {
t.label = i[2], t.ops.push(u);
break;
}
i[2] && t.ops.pop(), t.trys.pop();
continue;
}
u = n.call(e, t);
} catch (d) {
u = [6, d], s = 0;
} finally {
r = i = 0;
}
if (u[0] & 5) throw u[1];
return { value: u[0] ? u[1] : void 0, done: !0 };
}
}
function fe(e) {
var n = typeof Symbol == "function" && Symbol.iterator, t = n && e[n], r = 0;
if (t) return t.call(e);
if (e && typeof e.length == "number") return {
next: function() {
return e && r >= e.length && (e = void 0), { value: e && e[r++], done: !e };
}
};
throw new TypeError(n ? "Object is not iterable." : "Symbol.iterator is not defined.");
}
function je(e, n) {
var t = typeof Symbol == "function" && e[Symbol.iterator];
if (!t) return e;
var r = t.call(e), s, i = [], a;
try {
for (; (n === void 0 || n-- > 0) && !(s = r.next()).done; ) i.push(s.value);
} catch (c) {
a = { error: c };
} finally {
try {
s && !s.done && (t = r.return) && t.call(r);
} finally {
if (a) throw a.error;
}
}
return i;
}
function xe(e, n, t) {
if (t || arguments.length === 2) for (var r = 0, s = n.length, i; r < s; r++)
(i || !(r in n)) && (i || (i = Array.prototype.slice.call(n, 0, r)), i[r] = n[r]);
return e.concat(i || Array.prototype.slice.call(n));
}
function ye(e) {
return this instanceof ye ? (this.v = e, this) : new ye(e);
}
function co(e, n, t) {
if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
var r = t.apply(e, n || []), s, i = [];
return s = Object.create((typeof AsyncIterator == "function" ? AsyncIterator : Object).prototype), c("next"), c("throw"), c("return", a), s[Symbol.asyncIterator] = function() {
return this;
}, s;
function a(y) {
return function(m) {
return Promise.resolve(m).then(y, f);
};
}
function c(y, m) {
r[y] && (s[y] = function(h) {
return new Promise(function(C, w) {
i.push([y, h, C, w]) > 1 || l(y, h);
});
}, m && (s[y] = m(s[y])));
}
function l(y, m) {
try {
u(r[y](m));
} catch (h) {
_(i[0][3], h);
}
}
function u(y) {
y.value instanceof ye ? Promise.resolve(y.value.v).then(d, f) : _(i[0][2], y);
}
function d(y) {
l("next", y);
}
function f(y) {
l("throw", y);
}
function _(y, m) {
y(m), i.shift(), i.length && l(i[0][0], i[0][1]);
}
}
function lo(e) {
if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
var n = e[Symbol.asyncIterator], t;
return n ? n.call(e) : (e = typeof fe == "function" ? fe(e) : e[Symbol.iterator](), t = {}, r("next"), r("throw"), r("return"), t[Symbol.asyncIterator] = function() {
return this;
}, t);
function r(i) {
t[i] = e[i] && function(a) {
return new Promise(function(c, l) {
a = e[i](a), s(c, l, a.done, a.value);
});
};
}
function s(i, a, c, l) {
Promise.resolve(l).then(function(u) {
i({ value: u, done: c });
}, a);
}
}
function D(e) {
return typeof e == "function";
}
function qe(e) {
var n = function(r) {
Error.call(r), r.stack = new Error().stack;
}, t = e(n);
return t.prototype = Object.create(Error.prototype), t.prototype.constructor = t, t;
}
var We = qe(function(e) {
return function(t) {
e(this), this.message = t ? t.length + ` errors occurred during unsubscription:
` + t.map(function(r, s) {
return s + 1 + ") " + r.toString();
}).join(`
`) : "", this.name = "UnsubscriptionError", this.errors = t;
};
});
function $e(e, n) {
if (e) {
var t = e.indexOf(n);
0 <= t && e.splice(t, 1);
}
}
var Te = function() {
function e(n) {
this.initialTeardown = n, this.closed = !1, this._parentage = null, this._finalizers = null;
}
return e.prototype.unsubscribe = function() {
var n, t, r, s, i;
if (!this.closed) {
this.closed = !0;
var a = this._parentage;
if (a)
if (this._parentage = null, Array.isArray(a))
try {
for (var c = fe(a), l = c.next(); !l.done; l = c.next()) {
var u = l.value;
u.remove(this);
}
} catch (h) {
n = { error: h };
} finally {
try {
l && !l.done && (t = c.return) && t.call(c);
} finally {
if (n) throw n.error;
}
}
else
a.remove(this);
var d = this.initialTeardown;
if (D(d))
try {
d();
} catch (h) {
i = h instanceof We ? h.errors : [h];
}
var f = this._finalizers;
if (f) {
this._finalizers = null;
try {
for (var _ = fe(f), y = _.next(); !y.done; y = _.next()) {
var m = y.value;
try {
_t(m);
} catch (h) {
i = i ?? [], h instanceof We ? i = xe(xe([], je(i)), je(h.errors)) : i.push(h);
}
}
} catch (h) {
r = { error: h };
} finally {
try {
y && !y.done && (s = _.return) && s.call(_);
} finally {
if (r) throw r.error;
}
}
}
if (i)
throw new We(i);
}
}, e.prototype.add = function(n) {
var t;
if (n && n !== this)
if (this.closed)
_t(n);
else {
if (n instanceof e) {
if (n.closed || n._hasParent(this))
return;
n._addParent(this);
}
(this._finalizers = (t = this._finalizers) !== null && t !== void 0 ? t : []).push(n);
}
}, e.prototype._hasParent = function(n) {
var t = this._parentage;
return t === n || Array.isArray(t) && t.includes(n);
}, e.prototype._addParent = function(n) {
var t = this._parentage;
this._parentage = Array.isArray(t) ? (t.push(n), t) : t ? [t, n] : n;
}, e.prototype._removeParent = function(n) {
var t = this._parentage;
t === n ? this._parentage = null : Array.isArray(t) && $e(t, n);
}, e.prototype.remove = function(n) {
var t = this._finalizers;
t && $e(t, n), n instanceof e && n._removeParent(this);
}, e.EMPTY = function() {
var n = new e();
return n.closed = !0, n;
}(), e;
}(), en = Te.EMPTY;
function tn(e) {
return e instanceof Te || e && "closed" in e && D(e.remove) && D(e.add) && D(e.unsubscribe);
}
function _t(e) {
D(e) ? e() : e.unsubscribe();
}
var nn = {
onUnhandledError: null,
onStoppedNotification: null,
Promise: void 0,
useDeprecatedSynchronousErrorHandling: !1,
useDeprecatedNextContext: !1
}, rn = {
setTimeout: function(e, n) {
for (var t = [], r = 2; r < arguments.length; r++)
t[r - 2] = arguments[r];
return setTimeout.apply(void 0, xe([e, n], je(t)));
},
clearTimeout: function(e) {
var n = rn.delegate;
return ((n == null ? void 0 : n.clearTimeout) || clearTimeout)(e);
},
delegate: void 0
};
function on(e) {
rn.setTimeout(function() {
throw e;
});
}
function ht() {
}
function Le(e) {
e();
}
var ct = function(e) {
oe(n, e);
function n(t) {
var r = e.call(this) || this;
return r.isStopped = !1, t ? (r.destination = t, tn(t) && t.add(r)) : r.destination = yo, r;
}
return n.create = function(t, r, s) {
return new rt(t, r, s);
}, n.prototype.next = function(t) {
this.isStopped || this._next(t);
}, n.prototype.error = function(t) {
this.isStopped || (this.isStopped = !0, this._error(t));
}, n.prototype.complete = function() {
this.isStopped || (this.isStopped = !0, this._complete());
}, n.prototype.unsubscribe = function() {
this.closed || (this.isStopped = !0, e.prototype.unsubscribe.call(this), this.destination = null);
}, n.prototype._next = function(t) {
this.destination.next(t);
}, n.prototype._error = function(t) {
try {
this.destination.error(t);
} finally {
this.unsubscribe();
}
}, n.prototype._complete = function() {
try {
this.destination.complete();
} finally {
this.unsubscribe();
}
}, n;
}(Te), uo = Function.prototype.bind;
function Qe(e, n) {
return uo.call(e, n);
}
var po = function() {
function e(n) {
this.partialObserver = n;
}
return e.prototype.next = function(n) {
var t = this.partialObserver;
if (t.next)
try {
t.next(n);
} catch (r) {
De(r);
}
}, e.prototype.error = function(n) {
var t = this.partialObserver;
if (t.error)
try {
t.error(n);
} catch (r) {
De(r);
}
else
De(n);
}, e.prototype.complete = function() {
var n = this.partialObserver;
if (n.complete)
try {
n.complete();
} catch (t) {
De(t);
}
}, e;
}(), rt = function(e) {
oe(n, e);
function n(t, r, s) {
var i = e.call(this) || this, a;
if (D(t) || !t)
a = {
next: t ?? void 0,
error: r ?? void 0,
complete: s ?? void 0
};
else {
var c;
i && nn.useDeprecatedNextContext ? (c = Object.create(t), c.unsubscribe = function() {
return i.unsubscribe();
}, a = {
next: t.next && Qe(t.next, c),
error: t.error && Qe(t.error, c),
complete: t.complete && Qe(t.complete, c)
}) : a = t;
}
return i.destination = new po(a), i;
}
return n;
}(ct);
function De(e) {
on(e);
}
function mo(e) {
throw e;
}
var yo = {
closed: !0,
next: ht,
error: mo,
complete: ht
}, lt = function() {
return typeof Symbol == "function" && Symbol.observable || "@@observable";
}();
function fo(e) {
return e;
}
function _o(e) {
return e.length === 0 ? fo : e.length === 1 ? e[0] : function(t) {
return e.reduce(function(r, s) {
return s(r);
}, t);
};
}
var ne = function() {
function e(n) {
n && (this._subscribe = n);
}
return e.prototype.lift = function(n) {
var t = new e();
return t.source = this, t.operator = n, t;
}, e.prototype.subscribe = function(n, t, r) {
var s = this, i = go(n) ? n : new rt(n, t, r);
return Le(function() {
var a = s, c = a.operator, l = a.source;
i.add(c ? c.call(i, l) : l ? s._subscribe(i) : s._trySubscribe(i));
}), i;
}, e.prototype._trySubscribe = function(n) {
try {
return this._subscribe(n);
} catch (t) {
n.error(t);
}
}, e.prototype.forEach = function(n, t) {
var r = this;
return t = gt(t), new t(function(s, i) {
var a = new rt({
next: function(c) {
try {
n(c);
} catch (l) {
i(l), a.unsubscribe();
}
},
error: i,
complete: s
});
r.subscribe(a);
});
}, e.prototype._subscribe = function(n) {
var t;
return (t = this.source) === null || t === void 0 ? void 0 : t.subscribe(n);
}, e.prototype[lt] = function() {
return this;
}, e.prototype.pipe = function() {
for (var n = [], t = 0; t < arguments.length; t++)
n[t] = arguments[t];
return _o(n)(this);
}, e.prototype.toPromise = function(n) {
var t = this;
return n = gt(n), new n(function(r, s) {
var i;
t.subscribe(function(a) {
return i = a;
}, function(a) {
return s(a);
}, function() {
return r(i);
});
});
}, e.create = function(n) {
return new e(n);
}, e;
}();
function gt(e) {
var n;
return (n = e ?? nn.Promise) !== null && n !== void 0 ? n : Promise;
}
function ho(e) {
return e && D(e.next) && D(e.error) && D(e.complete);
}
function go(e) {
return e && e instanceof ct || ho(e) && tn(e);
}
function wo(e) {
return D(e == null ? void 0 : e.lift);
}
function bo(e) {
return function(n) {
if (wo(n))
return n.lift(function(t) {
try {
return e(t, this);
} catch (r) {
this.error(r);
}
});
throw new TypeError("Unable to lift unknown Observable type");
};
}
function vo(e, n, t, r, s) {
return new Eo(e, n, t, r, s);
}
var Eo = function(e) {
oe(n, e);
function n(t, r, s, i, a, c) {
var l = e.call(this, t) || this;
return l.onFinalize = a, l.shouldUnsubscribe = c, l._next = r ? function(u) {
try {
r(u);
} catch (d) {
t.error(d);
}
} : e.prototype._next, l._error = i ? function(u) {
try {
i(u);
} catch (d) {
t.error(d);
} finally {
this.unsubscribe();
}
} : e.prototype._error, l._complete = s ? function() {
try {
s();
} catch (u) {
t.error(u);
} finally {
this.unsubscribe();
}
} : e.prototype._complete, l;
}
return n.prototype.unsubscribe = function() {
var t;
if (!this.shouldUnsubscribe || this.shouldUnsubscribe()) {
var r = this.closed;
e.prototype.unsubscribe.call(this), !r && ((t = this.onFinalize) === null || t === void 0 || t.call(this));
}
}, n;
}(ct), Co = qe(function(e) {
return function() {
e(this), this.name = "ObjectUnsubscribedError", this.message = "object unsubscribed";
};
}), sn = function(e) {
oe(n, e);
function n() {
var t = e.call(this) || this;
return t.closed = !1, t.currentObservers = null, t.observers = [], t.isStopped = !1, t.hasError = !1, t.thrownError = null, t;
}
return n.prototype.lift = function(t) {
var r = new wt(this, this);
return r.operator = t, r;
}, n.prototype._throwIfClosed = function() {
if (this.closed)
throw new Co();
}, n.prototype.next = function(t) {
var r = this;
Le(function() {
var s, i;
if (r._throwIfClosed(), !r.isStopped) {
r.currentObservers || (r.currentObservers = Array.from(r.observers));
try {
for (var a = fe(r.currentObservers), c = a.next(); !c.done; c = a.next()) {
var l = c.value;
l.next(t);
}
} catch (u) {
s = { error: u };
} finally {
try {
c && !c.done && (i = a.return) && i.call(a);
} finally {
if (s) throw s.error;
}
}
}
});
}, n.prototype.error = function(t) {
var r = this;
Le(function() {
if (r._throwIfClosed(), !r.isStopped) {
r.hasError = r.isStopped = !0, r.thrownError = t;
for (var s = r.observers; s.length; )
s.shift().error(t);
}
});
}, n.prototype.complete = function() {
var t = this;
Le(function() {
if (t._throwIfClosed(), !t.isStopped) {
t.isStopped = !0;
for (var r = t.observers; r.length; )
r.shift().complete();
}
});
}, n.prototype.unsubscribe = function() {
this.isStopped = this.closed = !0, this.observers = this.currentObservers = null;
}, Object.defineProperty(n.prototype, "observed", {
get: function() {
var t;
return ((t = this.observers) === null || t === void 0 ? void 0 : t.length) > 0;
},
enumerable: !1,
configurable: !0
}), n.prototype._trySubscribe = function(t) {
return this._throwIfClosed(), e.prototype._trySubscribe.call(this, t);
}, n.prototype._subscribe = function(t) {
return this._throwIfClosed(), this._checkFinalizedStatuses(t), this._innerSubscribe(t);
}, n.prototype._innerSubscribe = function(t) {
var r = this, s = this, i = s.hasError, a = s.isStopped, c = s.observers;
return i || a ? en : (this.currentObservers = null, c.push(t), new Te(function() {
r.currentObservers = null, $e(c, t);
}));
}, n.prototype._checkFinalizedStatuses = function(t) {
var r = this, s = r.hasError, i = r.thrownError, a = r.isStopped;
s ? t.error(i) : a && t.complete();
}, n.prototype.asObservable = function() {
var t = new ne();
return t.source = this, t;
}, n.create = function(t, r) {
return new wt(t, r);
}, n;
}(ne), wt = function(e) {
oe(n, e);
function n(t, r) {
var s = e.call(this) || this;
return s.destination = t, s.source = r, s;
}
return n.prototype.next = function(t) {
var r, s;
(s = (r = this.destination) === null || r === void 0 ? void 0 : r.next) === null || s === void 0 || s.call(r, t);
}, n.prototype.error = function(t) {
var r, s;
(s = (r = this.destination) === null || r === void 0 ? void 0 : r.error) === null || s === void 0 || s.call(r, t);
}, n.prototype.complete = function() {
var t, r;
(r = (t = this.destination) === null || t === void 0 ? void 0 : t.complete) === null || r === void 0 || r.call(t);
}, n.prototype._subscribe = function(t) {
var r, s;
return (s = (r = this.source) === null || r === void 0 ? void 0 : r.subscribe(t)) !== null && s !== void 0 ? s : en;
}, n;
}(sn), So = {
now: function() {
return Date.now();
},
delegate: void 0
}, Po = function(e) {
oe(n, e);
function n(t, r) {
return e.call(this) || this;
}
return n.prototype.schedule = function(t, r) {
return this;
}, n;
}(Te), bt = {
setInterval: function(e, n) {
for (var t = [], r = 2; r < arguments.length; r++)
t[r - 2] = arguments[r];
return setInterval.apply(void 0, xe([e, n], je(t)));
},
clearInterval: function(e) {
return clearInterval(e);
},
delegate: void 0
}, ko = function(e) {
oe(n, e);
function n(t, r) {
var s = e.call(this, t, r) || this;
return s.scheduler = t, s.work = r, s.pending = !1, s;
}
return n.prototype.schedule = function(t, r) {
var s;
if (r === void 0 && (r = 0), this.closed)
return this;
this.state = t;
var i = this.id, a = this.scheduler;
return i != null && (this.id = this.recycleAsyncId(a, i, r)), this.pending = !0, this.delay = r, this.id = (s = this.id) !== null && s !== void 0 ? s : this.requestAsyncId(a, this.id, r), this;
}, n.prototype.requestAsyncId = function(t, r, s) {
return s === void 0 && (s = 0), bt.setInterval(t.flush.bind(t, this), s);
}, n.prototype.recycleAsyncId = function(t, r, s) {
if (s === void 0 && (s = 0), s != null && this.delay === s && this.pending === !1)
return r;
r != null && bt.clearInterval(r);
}, n.prototype.execute = function(t, r) {
if (this.closed)
return new Error("executing a cancelled action");
this.pending = !1;
var s = this._execute(t, r);
if (s)
return s;
this.pending === !1 && this.id != null && (this.id = this.recycleAsyncId(this.scheduler, this.id, null));
}, n.prototype._execute = function(t, r) {
var s = !1, i;
try {
this.work(t);
} catch (a) {
s = !0, i = a || new Error("Scheduled action threw falsy error");
}
if (s)
return this.unsubscribe(), i;
}, n.prototype.unsubscribe = function() {
if (!this.closed) {
var t = this, r = t.id, s = t.scheduler, i = s.actions;
this.work = this.state = this.scheduler = null, this.pending = !1, $e(i, this), r != null && (this.id = this.recycleAsyncId(s, r, null)), this.delay = null, e.prototype.unsubscribe.call(this);
}
}, n;
}(Po), vt = function() {
function e(n, t) {
t === void 0 && (t = e.now), this.schedulerActionCtor = n, this.now = t;
}
return e.prototype.schedule = function(n, t, r) {
return t === void 0 && (t = 0), new this.schedulerActionCtor(this, n).schedule(r, t);
}, e.now = So.now, e;
}(), Ao = function(e) {
oe(n, e);
function n(t, r) {
r === void 0 && (r = vt.now);
var s = e.call(this, t, r) || this;
return s.actions = [], s._active = !1, s;
}
return n.prototype.flush = function(t) {
var r = this.actions;
if (this._active) {
r.push(t);
return;
}
var s;
this._active = !0;
do
if (s = t.execute(t.state, t.delay))
break;
while (t = r.shift());
if (this._active = !1, s) {
for (; t = r.shift(); )
t.unsubscribe();
throw s;
}
}, n;
}(vt), Io = new Ao(ko), To = function(e) {
return e && typeof e.length == "number" && typeof e != "function";
};
function Ro(e) {
return D(e == null ? void 0 : e.then);
}
function Fo(e) {
return D(e[lt]);
}
function Mo(e) {
return Symbol.asyncIterator && D(e == null ? void 0 : e[Symbol.asyncIterator]);
}
function Do(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 No() {
return typeof Symbol != "function" || !Symbol.iterator ? "@@iterator" : Symbol.iterator;
}
var Lo = No();
function Oo(e) {
return D(e == null ? void 0 : e[Lo]);
}
function Uo(e) {
return co(this, arguments, function() {
var t, r, s, i;
return Xt(this, function(a) {
switch (a.label) {
case 0:
t = e.getReader(), a.label = 1;
case 1:
a.trys.push([1, , 9, 10]), a.label = 2;
case 2:
return [4, ye(t.read())];
case 3:
return r = a.sent(), s = r.value, i = r.done, i ? [4, ye(void 0)] : [3, 5];
case 4:
return [2, a.sent()];
case 5:
return [4, ye(s)];
case 6:
return [4, a.sent()];
case 7:
return a.sent(), [3, 2];
case 8:
return [3, 10];
case 9:
return t.releaseLock(), [7];
case 10:
return [2];
}
});
});
}
function jo(e) {
return D(e == null ? void 0 : e.getReader);
}
function xo(e) {
if (e instanceof ne)
return e;
if (e != null) {
if (Fo(e))
return $o(e);
if (To(e))
return Go(e);
if (Ro(e))
return Vo(e);
if (Mo(e))
return an(e);
if (Oo(e))
return zo(e);
if (jo(e))
return qo(e);
}
throw Do(e);
}
function $o(e) {
return new ne(function(n) {
var t = e[lt]();
if (D(t.subscribe))
return t.subscribe(n);
throw new TypeError("Provided object does not correctly implement Symbol.observable");
});
}
function Go(e) {
return new ne(function(n) {
for (var t = 0; t < e.length && !n.closed; t++)
n.next(e[t]);
n.complete();
});
}
function Vo(e) {
return new ne(function(n) {
e.then(function(t) {
n.closed || (n.next(t), n.complete());
}, function(t) {
return n.error(t);
}).then(null, on);
});
}
function zo(e) {
return new ne(function(n) {
var t, r;
try {
for (var s = fe(e), i = s.next(); !i.done; i = s.next()) {
var a = i.value;
if (n.next(a), n.closed)
return;
}
} catch (c) {
t = { error: c };
} finally {
try {
i && !i.done && (r = s.return) && r.call(s);
} finally {
if (t) throw t.error;
}
}
n.complete();
});
}
function an(e) {
return new ne(function(n) {
Yo(e, n).catch(function(t) {
return n.error(t);
});
});
}
function qo(e) {
return an(Uo(e));
}
function Yo(e, n) {
var t, r, s, i;
return ao(this, void 0, void 0, function() {
var a, c;
return Xt(this, function(l) {
switch (l.label) {
case 0:
l.trys.push([0, 5, 6, 11]), t = lo(e), l.label = 1;
case 1:
return [4, t.next()];
case 2:
if (r = l.sent(), !!r.done) return [3, 4];
if (a = r.value, n.next(a), n.closed)
return [2];
l.label = 3;
case 3:
return [3, 1];
case 4:
return [3, 11];
case 5:
return c = l.sent(), s = { error: c }, [3, 11];
case 6:
return l.trys.push([6, , 9, 10]), r && !r.done && (i = t.return) ? [4, i.call(t)] : [3, 8];
case 7:
l.sent(), l.label = 8;
case 8:
return [3, 10];
case 9:
if (s) throw s.error;
return [7];
case 10:
return [7];
case 11:
return n.complete(), [2];
}
});
});
}
function Bo(e, n, t, r, s) {
r === void 0 && (r = 0), s === void 0 && (s = !1);
var i = n.schedule(function() {
t(), s ? e.add(this.schedule(null, r)) : this.unsubscribe();
}, r);
if (e.add(i), !s)
return i;
}
function Ho(e, n) {
var t = D(e) ? e : function() {
return e;
}, r = function(s) {
return s.error(t());
};
return new ne(r);
}
var Jo = qe(function(e) {
return function() {
e(this), this.name = "EmptyError", this.message = "no elements in sequence";
};
});
function Ko(e, n) {
return new Promise(function(t, r) {
var s = !1, i;
e.subscribe({
next: function(a) {
i = a, s = !0;
},
error: r,
complete: function() {
s ? t(i) : r(new Jo());
}
});
});
}
function Zo(e) {
return e instanceof Date && !isNaN(e);
}
var Wo = qe(function(e) {
return function(t) {
t === void 0 && (t = null), e(this), this.message = "Timeout has occurred", this.name = "TimeoutError", this.info = t;
};
});
function Qo(e, n) {
var t = Zo(e) ? { first: e } : typeof e == "number" ? { each: e } : e, r = t.first, s = t.each, i = t.with, a = i === void 0 ? Xo : i, c = t.scheduler, l = c === void 0 ? Io : c, u = t.meta, d = u === void 0 ? null : u;
if (r == null && s == null)
throw new TypeError("No timeout provided.");
return bo(function(f, _) {
var y, m, h = null, C = 0, w = function(S) {
m = Bo(_, l, function() {
try {
y.unsubscribe(), xo(a({
meta: d,
lastValue: h,
seen: C
})).subscribe(_);
} catch (k) {
_.error(k);
}
}, S);
};
y = f.subscribe(vo(_, function(S) {
m == null || m.unsubscribe(), C++, _.next(h = S), s > 0 && w(s);
}, void 0, void 0, function() {
m != null && m.closed || m == null || m.unsubscribe(), h = null;
})), !C && w(r != null ? typeof r == "number" ? r : +r - l.now() : s);
});
}
function Xo(e) {
throw new Wo(e);
}
class Se {
constructor() {
this.set = (n) => {
if (this._current.status === "success")
throw new Error("LoadedOnce is already in success state");
this._current = { status: "success", isSuccess: !0, loadedValue: n }, this._subject.next(n), this._subject.complete();
}, this.throw = (n, t) => {
if (this._current.status === "success")
throw new Error("LoadedOnce is already in success state");
this._current = { status: "error", isSuccess: !1, error: n, errMsg: t }, this._subject.error(n);
}, this.getValueIfLoadedElse = (n) => this._current.status === "success" ? this._current.loadedValue : n, this.subscribe = (n) => {
if (this._current.status === "success") {
n(this._current);
return;
}
this._current.status === "error" && n(this._current);
const t = this._subject.subscribe({
next: () => {
if (this._current.status !== "success")
throw new Error("Invalid state (next): please make sure to update _current before the subject");
n(this._current), t.unsubscribe();
},
error: () => {
if (this._current.status !== "error")
throw new Error("Inva