@astropay/payments-lib
Version:
Official AstroPay payments library for web and mobile.
229 lines (228 loc) • 6.8 kB
JavaScript
import { p as x, V as z, W as H, w as O, X as W, Y as v, Z as X, O as Y, M as Z } from "./main-CNabIeI3.js";
function q(e) {
let t = 0;
for (const o of e)
o.stackId !== void 0 && t++;
return t;
}
const g = /* @__PURE__ */ new Map();
let m = !1;
function C() {
m = performance.now();
}
function K() {
m = !1, g.clear();
}
function Q(e, t) {
g.set(t, e);
}
function L(e) {
if (!(m === !1 || e.startTime < m))
return g.get(e.startTime);
}
function $(e) {
if (!(m === !1 || e < m))
for (const t of g.keys())
t < e && g.delete(t);
}
function ee({ rawRumEvent: e, startTime: t }) {
if (e.type !== "long_task")
return;
const o = e.long_task.id;
Q(o, t);
}
const ne = (e, t, o, s) => {
const f = te(e, t, o, s), c = re(e, f), l = t.build("fetch", c);
return x("Sending profile to public profiling intake", { profilingIntakeURL: l, applicationId: o, sessionId: s }), fetch(l, {
body: c.data,
method: "POST"
});
};
function te(e, t, o, s) {
const f = t.tags, c = ie(e, o, s), l = se(f), i = new Date(e.timeOrigin + e.startTime), b = new Date(e.timeOrigin + e.endTime);
return {
...c,
attachments: ["wall-time.json"],
start: i.toISOString(),
end: b.toISOString(),
family: "chrome",
runtime: "chrome",
format: "json",
version: 4,
// Ingestion event version (not the version application tag)
tags_profiler: l.join(",")
};
}
function se(e) {
return e.concat(["language:javascript", "runtime:chrome", "family:chrome", "host:browser"]);
}
function re(e, t) {
const o = new Blob([JSON.stringify(e)], {
type: "application/json"
}), s = new FormData();
return s.append("event", new Blob([JSON.stringify(t)], { type: "application/json" }), "event.json"), s.append("wall-time.json", o, "wall-time.json"), { data: s, bytesCount: 0 };
}
function ie(e, t, o) {
const s = {
application: {
id: t
}
};
o && (s.session = {
id: o
});
const f = Array.from(new Set(e.views.map((l) => l.viewId)));
f.length && (s.view = {
id: f
});
const c = e.longTasks.map((l) => L(l)).filter((l) => l !== void 0);
return c.length && (s.long_task = { id: c }), s;
}
const oe = {
sendProfile: ne
}, ae = {
sampleIntervalMs: 10,
// Sample stack trace every 10ms
collectIntervalMs: 6e4,
// Collect data every minute
minProfileDurationMs: 5e3,
// Require at least 5 seconds of profile data to reduce noise and cost
minNumberOfSamples: 50
// Require at least 50 samples (~500 ms) to report a profile to reduce noise and cost
};
function ce(e, t, o, s = ae) {
const f = z(H.LONG_ANIMATION_FRAME);
let c;
const l = [];
let i = { state: "stopped" };
function b(n) {
i.state !== "running" && (c = n ? { startTime: n.startClocks.relative, viewId: n.id, viewName: n.name } : void 0, l.push(O(e, window, "visibilitychange", _).stop, O(e, window, "beforeunload", j).stop), p());
}
async function h() {
await y("stopped"), K(), l.forEach((n) => n());
}
function M(n) {
if (n.state === "running")
return {
cleanupTasks: n.cleanupTasks,
observer: n.observer
};
const r = [];
let a;
if (e.trackLongTasks) {
a = new PerformanceObserver(R), a.observe({
entryTypes: [D()]
});
const u = t.subscribe(12, (T) => {
ee(T);
});
C(), r.push(() => a == null ? void 0 : a.disconnect()), r.push(u.unsubscribe);
}
const d = t.subscribe(2, (u) => {
k({ viewId: u.id, viewName: u.name, startTime: u.startClocks.relative });
});
return r.push(d.unsubscribe), {
cleanupTasks: r,
observer: a
};
}
function p() {
const n = W().Profiler;
if (!n)
throw new Error("RUM Profiler is not supported in this browser.");
w(i).catch(v);
const { cleanupTasks: r, observer: a } = M(i);
let d;
try {
d = new n({
sampleInterval: s.sampleIntervalMs,
// Keep buffer size at 1.5 times of minimum required to collect data for a profiling instance
maxBufferSize: Math.round(s.collectIntervalMs * 1.5 / s.sampleIntervalMs)
});
} catch (u) {
X.warn("[DD_RUM] Profiler startup failed. Ensure your server includes the `Document-Policy: js-profiling` response header when serving HTML pages.", u);
return;
}
i = {
state: "running",
startTime: performance.now(),
profiler: d,
timeoutId: Y(p, s.collectIntervalMs),
longTasks: [],
views: [],
cleanupTasks: r,
observer: a
}, k(c), d.addEventListener("samplebufferfull", P);
}
async function w(n) {
var r, a;
if (n.state !== "running")
return;
I((a = (r = n.observer) === null || r === void 0 ? void 0 : r.takeRecords()) !== null && a !== void 0 ? a : []), Z(n.timeoutId), n.profiler.removeEventListener("samplebufferfull", P);
const { startTime: d, longTasks: u, views: T } = n, U = performance.now();
await n.profiler.stop().then((E) => {
const S = performance.now(), V = u.length > 0, G = S - d < s.minProfileDurationMs, J = q(E.samples) < s.minNumberOfSamples;
!V && (G || J) || (N(
// Enrich trace with time and instance data
Object.assign(E, {
startTime: d,
endTime: S,
timeOrigin: performance.timeOrigin,
longTasks: u,
views: T,
sampleInterval: s.sampleIntervalMs
})
), $(U));
}).catch(v);
}
async function y(n) {
i.state === "running" && (i.cleanupTasks.forEach((r) => r()), await w(i), i = { state: n });
}
function k(n) {
i.state !== "running" || !n || i.views.push(n);
}
function N(n) {
var r;
const a = (r = o.findTrackedSession()) === null || r === void 0 ? void 0 : r.id;
oe.sendProfile(n, e.profilingEndpointBuilder, e.applicationId, a).catch(v);
}
function P() {
p();
}
function R(n) {
I(n.getEntries());
}
function I(n) {
if (i.state === "running")
for (const r of n)
r.duration < s.sampleIntervalMs || i.longTasks.push({
id: L(r),
duration: r.duration,
entryType: r.entryType,
startTime: r.startTime
});
}
function _() {
document.visibilityState === "hidden" && i.state === "running" ? y("paused").catch(v) : document.visibilityState === "visible" && i.state === "paused" && p();
}
function j() {
p();
}
function D() {
return f ? "long-animation-frame" : "longtask";
}
function A() {
return i.state === "stopped";
}
function B() {
return i.state === "running";
}
function F() {
return i.state === "paused";
}
return { start: b, stop: h, isStopped: A, isRunning: B, isPaused: F };
}
export {
ae as DEFAULT_RUM_PROFILER_CONFIGURATION,
ce as createRumProfiler
};