UNPKG

@jumio/websdk

Version:

Jumio WebSDK is a powerful, flexible software development kit that simplifies the integration of Jumio's services into your web applications.

409 lines (408 loc) 12.1 kB
import { j as H, o as re, c as le, a as ce, b as de, g as ue, D as pe, d as fe, e as me, f as R, L as _, R as j, h as ve, i as I, S as V, V as w, k as z, l as _e, m as T, s as Y, n as be, p as F, q as b, r as B, t as x, u as ye, v as Ee, w as C, x as L, y as he, z as Te, A as Ie } from "../index.W6WfC45m.js"; function ke(s, t, e, n) { const l = (d) => { t.notify(14, { error: d }), de("Error reported to customer", { "error.message": d.message }); }, c = le([ce(s, "profile")], l), a = e(n); return { async send({ event: d, ...m }) { const u = new FormData(), p = H(d); if (!p) throw new Error("Failed to serialize event"); u.append("event", new Blob([p], { type: "application/json" }), "event.json"); let k = p.length; for (const [g, o] of re(m)) { const y = H(o); if (!y) throw new Error("Failed to serialize attachment"); const E = await ge(a, y); k += E.outputBytesCount, u.append(g, new Blob([E.output]), g); } c.send({ data: u, bytesCount: k }); } }; } function ge(s, t) { return new Promise((e) => { s.write(t), s.finish((n) => { e(n); }); }); } function De() { const s = ue(); return (t) => { s.send("profile", t); }; } function Ae(s, t, e) { const n = ke(s, t, e, pe.PROFILING); return ({ profile: l, trace: c }) => { const a = { event: l, "wall-time.json": c }; n.send(a); }; } const Se = /\/(?![vV]\d{1,2}\/)([^/\d?]*\d+[^/?]*)/g; function Oe(s) { return s ? s.replace(Se, "/?") : "/"; } const G = (s, t) => s || Oe(t); function Ne(s, t, e) { const n = fe(t), l = Pe(s, t.applicationId, e), c = Re(n); return { ...l, attachments: ["wall-time.json"], start: new Date(s.startClocks.timeStamp).toISOString(), end: new Date(s.endClocks.timeStamp).toISOString(), family: "chrome", runtime: "chrome", format: "json", version: 4, tags_profiler: c.join(","), _dd: { clock_drift: me() } }; } function Pe(s, t, e) { const { ids: n, names: l } = we(s.views), c = s.longTasks.map((p) => p.id).filter((p) => p !== void 0), a = s.actions?.map((p) => p.id).filter((p) => p !== void 0) ?? [], { ids: d, labels: m } = Le(s.vitals), u = { application: { id: t } }; return e && (u.session = { id: e }), n.length && (u.view = { id: n, name: l }), c.length && (u.long_task = { id: c }), a.length && (u.action = { id: a, label: [] }), d.length && (u.vital = { id: d, label: m }), u; } function we(s) { const t = { ids: [], names: [] }; for (const e of s) t.ids.push(e.viewId), e.viewName && t.names.push(e.viewName); return t.names = Array.from(new Set(t.names)), t; } function Le(s) { const t = { ids: [], labels: [] }; if (!s) return t; for (const e of s) t.ids.push(e.id), t.labels.push(e.label); return t.labels = Array.from(new Set(t.labels)), t; } function Re(s) { return s.concat([ "language:javascript", "runtime:chrome", "family:chrome", "host:browser" ]); } const Ve = V; function Me(s) { const t = R({ expireDelay: Ve }); return s.subscribe(_.RAW_RUM_EVENT_COLLECTED, ({ rawRumEvent: e, startClocks: n, duration: l }) => { e.type === "long_task" && t.add({ id: e.long_task.id, startClocks: n, duration: l, entryType: e.long_task.entry_type === ve.LONG_TASK ? j.LONG_TASK : j.LONG_ANIMATION_FRAME }, n.relative).close(I(n.relative, l)); }), t; } const Ue = V; function qe(s) { const t = R({ expireDelay: Ue }); return s.subscribe(_.ACTION_STARTED, (e) => { t.add({ id: e.id, label: "", startClocks: e.startClocks, duration: void 0 }, e.startClocks.relative); }), s.subscribe(_.RAW_RUM_EVENT_COLLECTED, ({ rawRumEvent: e, startClocks: n, duration: l }) => { if (e.type === "action") { const c = t.getEntries(n.relative).find((d) => d.value.id === e.action.id), a = l ?? 0; c ? (c.value.duration = a, c.close(I(n.relative, a))) : t.add({ id: e.action.id, label: "", startClocks: n, duration: l }, n.relative).close(I(n.relative, a)); } }), t; } const He = V; function je(s) { const t = R({ expireDelay: He }); return s.subscribe(_.DURATION_VITAL_STARTED, (e) => { t.add({ id: e.id, type: w.DURATION, startClocks: e.startClocks, duration: void 0, label: e.name }, e.startClocks.relative); }), s.subscribe(_.RAW_RUM_EVENT_COLLECTED, ({ rawRumEvent: e, startClocks: n, duration: l }) => { if (e.type !== "vital") return; if (e.vital.type === w.OPERATION_STEP) { if (e.vital.step_type === "start") t.add({ id: e.vital.id, type: e.vital.type, operationKey: e.vital.operation_key, startClocks: n, label: e.vital.name }, n.relative); else if (e.vital.step_type === "end") { const a = t.findAllEntries().find((d) => d.value.type === w.OPERATION_STEP && d.value.label === e.vital.name && d.value.operationKey === e.vital.operation_key); if (!a) return; a.value.duration = z(a.value.startClocks.relative, n.relative), a.close(n.relative); } return; } const c = t.getEntries(n.relative).find((a) => a.value.id === e.vital.id); if (c) { c.value.duration = l, c.close(I(n.relative, l)); return; } t.add({ id: e.vital.id, type: e.vital.type, operationKey: e.vital.operation_key, startClocks: n, duration: l, label: e.vital.name }, n.relative).close(I(n.relative, l)); }), t; } function Fe(s, t) { const e = s?.data?.attributes; if (!e || typeof e.admitted != "boolean" || typeof e.reason != "string") return t; const n = e.reason === "backend_client_not_initialized" ? "backend_unavailable" : e.reason; return { decision: e.admitted ? "quota_ok" : "quota_ko", reason: n }; } function Be(s, t) { return be({ proxy: s.proxy, site: s.site, path: "/api/v2/profiling/quota", parameters: `session_id=${t}`, subdomain: "quota" }); } function xe(s, t, e = 5e3) { const n = Be(s, t), l = new AbortController(); let c; const a = _e(n, { credentials: "omit", signal: l.signal, headers: new Headers({ "DD-CLIENT-TOKEN": s.clientToken }) }).then((m) => { const u = m.status === 429 ? { decision: "quota_ko", reason: "quota_exceeded" } : { decision: "quota_ok", reason: "api-error" }; return m.json().then((p) => (T(c), Fe(p, u)), () => (T(c), u)); }).catch(() => (T(c), { decision: "quota_ok", reason: "api-error" })), d = new Promise((m) => { c = Y(() => { l.abort(), m({ decision: "quota_ok", reason: "timeout" }); }, e); }); return Promise.race([a, d]); } const Ce = { sampleIntervalMs: 10, collectIntervalMs: 6e4, minProfileDurationMs: 5e3 }; function ze(s, t, e, n, l, c, a = Ce) { const d = F() ? b(De)() : b(Ae)(s, t, l); let m; const u = [], p = b(Me)(t), k = b(qe)(t), g = b(je)(t); let o = { state: "stopped", stateReason: "initializing" }, y = 0; t.subscribe(_.SESSION_EXPIRED, () => { O("session-expired"); }), t.subscribe(_.SESSION_RENEWED, () => { if (o.state === "stopped" && (o.stateReason === "session-expired" || o.stateReason === "quota_ko")) { const i = e.findTrackedSession(); if (!i || !he(i.id, Te(s.sessionSampleRate, s.profilingSampleRate))) return; E(); } }); function E() { if (o.state === "running") return; const i = c.findView(); m = i ? { startClocks: i.startClocks, viewId: i.id, viewName: G(i.name, document.location.pathname) } : void 0, u.push(B(window, x.VISIBILITY_CHANGE, Z).stop, B(window, x.BEFORE_UNLOAD, ee).stop), h(), K(); } function K() { if (F()) return; const i = ++y, r = e.findTrackedSession()?.id; r && b(xe)(s, r).then((f) => { i === y && (o.state !== "running" && o.state !== "paused" || f.decision === "quota_ko" && O("quota_ko", f.reason)); }).catch(L); } function W() { O("stopped-by-user"); } function O(i, r) { X(i), u.forEach((f) => f()), u.length = 0, n.set({ status: "stopped", error_reason: void 0, quota_reason: r }); } function Q(i) { if (i.state === "running") return { cleanupTasks: i.cleanupTasks }; const r = [], f = t.subscribe(_.VIEW_CREATED, (v) => { const D = { viewId: v.id, viewName: G(v.name, document.location.pathname), startClocks: v.startClocks }; M(D), m = D; }); return r.push(f.unsubscribe), { cleanupTasks: r }; } function h() { const i = ye.Profiler; if (!i) throw n.set({ status: "error", error_reason: "not-supported-by-browser" }), new Error("RUM Profiler is not supported in this browser."); o.state === "running" && N(o); const { cleanupTasks: r } = Q(o); let f; try { f = new i({ sampleInterval: a.sampleIntervalMs, maxBufferSize: Math.round(a.collectIntervalMs * 1.5 / a.sampleIntervalMs) }); } catch (v) { v instanceof Error && v.message.includes("disabled by Document Policy") ? (Ee.warn("[DD_RUM] Profiler startup failed. Ensure your server includes the `Document-Policy: js-profiling` response header when serving HTML pages.", v), n.set({ status: "error", error_reason: "missing-document-policy-header" })) : n.set({ status: "error", error_reason: "unexpected-exception" }); return; } n.set({ status: "running", error_reason: void 0 }), o = { state: "running", startClocks: C(), profiler: f, timeoutId: Y(h, a.collectIntervalMs), views: [], cleanupTasks: r, longTasks: [], sessionId: e.findTrackedSession()?.id }, M(m), f.addEventListener("samplebufferfull", P); } function N(i) { T(i.timeoutId), i.profiler.removeEventListener("samplebufferfull", P); const { startClocks: r, views: f, sessionId: v } = i; i.profiler.stop().then((D) => { const U = C(), A = z(r.relative, U.relative), q = p.findAll(r.relative, A), ie = k.findAll(r.relative, A), oe = g.findAll(r.relative, A).map((S) => ({ id: S.id, label: S.label, startClocks: S.startClocks, duration: S.duration })), ae = A < a.minProfileDurationMs; q.length === 0 && ae || J(Object.assign({}, D, { startClocks: r, endClocks: U, clocksOrigin: Ie(), longTasks: q, actions: ie, vitals: oe, views: f, sampleInterval: a.sampleIntervalMs }), v); }).catch(L); } function X(i) { if (o.state !== "running") { (o.state === "paused" || o.state === "stopped" && i === "stopped-by-user") && (o = { state: "stopped", stateReason: i }); return; } const r = o; o = { state: "stopped", stateReason: i }, r.cleanupTasks.forEach((f) => f()), i === "quota_ko" ? (T(r.timeoutId), r.profiler.removeEventListener("samplebufferfull", P), r.profiler.stop().catch(L)) : N(r); } function $() { if (o.state !== "running") return; const i = o; o = { state: "paused" }, i.cleanupTasks.forEach((r) => r()), N(i); } function M(i) { o.state !== "running" || !i || o.views.push(i); } function J(i, r) { d({ profile: Ne(i, s, r), trace: i }); } function P() { h(); } function Z() { document.visibilityState === "hidden" && o.state === "running" ? $() : document.visibilityState === "visible" && o.state === "paused" && h(); } function ee() { h(); } function te() { return o.state === "stopped"; } function se() { return o.state === "running"; } function ne() { return o.state === "paused"; } return { start: E, stop: W, isStopped: te, isRunning: se, isPaused: ne }; } export { ze as createRumProfiler }; //# sourceMappingURL=datadogProfiler-BoZokRBn.js.map