@corbado/autocapture 0.1.0-next.3-b8e8889 → 0.1.0-next.5-1f3cd4a
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +10 -14
- package/dist/index.d.mts +3 -92
- package/dist/index.d.ts +3 -92
- package/dist/index.js +1 -1
- package/dist/index.mjs +1 -1
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -9,7 +9,7 @@ It is designed to be dropped into a page it does not own and fail closed when a
|
|
|
9
9
|
instrumented safely. The remaining cases where observation cannot be perfectly transparent are
|
|
10
10
|
called out in the safety invariants and data handling sections below.
|
|
11
11
|
|
|
12
|
-
The package observes
|
|
12
|
+
The package observes three kinds of signal:
|
|
13
13
|
|
|
14
14
|
- **WebAuthn ceremonies** — the lifecycle of `navigator.credentials.get`/`create` passkey
|
|
15
15
|
ceremonies, from invocation to settlement, including silent cancellations.
|
|
@@ -17,10 +17,8 @@ The package observes five kinds of signal:
|
|
|
17
17
|
`XMLHttpRequest` and `fetch`, limited to URLs a caller-provided predicate selects. A page-local
|
|
18
18
|
request ID correlates both callbacks.
|
|
19
19
|
- **In-app navigation** — same-document (SPA) route changes.
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
- **Rendered UI state** — caller-owned semantic snapshots read after selected UI events or
|
|
23
|
-
imperative triggers settle.
|
|
20
|
+
|
|
21
|
+
It also exposes `composedPath()` for selector matching across visible shadow-DOM boundaries.
|
|
24
22
|
|
|
25
23
|
It has no runtime dependencies, ships TypeScript type definitions, and targets ES2019 so it parses
|
|
26
24
|
on older engines.
|
|
@@ -37,7 +35,7 @@ Every observer follows the platform observer pattern (`MutationObserver`, `Resiz
|
|
|
37
35
|
it with a callback, receive events, and call `disconnect()` when finished.
|
|
38
36
|
|
|
39
37
|
```ts
|
|
40
|
-
import { captureWebAuthn, captureNetwork, captureNavigation,
|
|
38
|
+
import { captureWebAuthn, captureNetwork, captureNavigation, composedPath } from "@corbado/autocapture";
|
|
41
39
|
|
|
42
40
|
const webauthn = captureWebAuthn({
|
|
43
41
|
onEvent: (event) => console.log(event.kind, event.mediation, event.phase, event.ceremonyId),
|
|
@@ -63,18 +61,20 @@ const navigation = captureNavigation({
|
|
|
63
61
|
onNavigate: (event) => console.log(event.source, event.path),
|
|
64
62
|
});
|
|
65
63
|
|
|
66
|
-
|
|
67
|
-
|
|
64
|
+
document.addEventListener("click", (event) => {
|
|
65
|
+
const clickedButton = composedPath(event).find(
|
|
66
|
+
(entry) => entry instanceof HTMLButtonElement,
|
|
67
|
+
);
|
|
68
|
+
if (clickedButton) console.log(clickedButton);
|
|
68
69
|
});
|
|
69
70
|
|
|
70
71
|
// when finished
|
|
71
72
|
webauthn.disconnect();
|
|
72
73
|
network.disconnect();
|
|
73
74
|
navigation.disconnect();
|
|
74
|
-
shadowRoots.disconnect();
|
|
75
75
|
```
|
|
76
76
|
|
|
77
|
-
Each call returns a `CaptureHandle` with a mode (`"standard"` or `"unavailable"`) and a
|
|
77
|
+
Each capture call returns a `CaptureHandle` with a mode (`"standard"` or `"unavailable"`) and a
|
|
78
78
|
`disconnect()` method. Environments that cannot be instrumented report `"unavailable"` rather than
|
|
79
79
|
throwing; a misconfigured `captureNetwork` call (missing `match` or `onExchange`) throws a
|
|
80
80
|
`TypeError` instead, since that is a programming error, not a degraded environment. Full event and
|
|
@@ -160,10 +160,6 @@ autocapture are delegated to; one that assigns its wrapper afterwards keeps work
|
|
|
160
160
|
ceremonies stay observed when the wrapper forwards through the method it replaced (the surveyed
|
|
161
161
|
managers do). A later assignment that does not forward displaces WebAuthn telemetry.
|
|
162
162
|
|
|
163
|
-
Shadow capture can retain access to closed roots that the page normally cannot rediscover. Treat the
|
|
164
|
-
callback as a privileged capability and do not enable `includeExisting` without accepting a
|
|
165
|
-
synchronous full-DOM walk.
|
|
166
|
-
|
|
167
163
|
## Runtime support
|
|
168
164
|
|
|
169
165
|
The published bundle targets ES2019 and assumes ES2019-era runtime primitives such as `Promise`,
|
package/dist/index.d.mts
CHANGED
|
@@ -215,55 +215,6 @@ type NavigationCaptureOptions = {
|
|
|
215
215
|
/** Optional diagnostic logger. */
|
|
216
216
|
logger?: Logger;
|
|
217
217
|
};
|
|
218
|
-
/** A shadow root reported by {@link captureShadowRoots}. */
|
|
219
|
-
type ShadowRootAttachedEvent = {
|
|
220
|
-
/** Element that owns the shadow root. */
|
|
221
|
-
host: Element;
|
|
222
|
-
/**
|
|
223
|
-
* Attached shadow root. For a closed root, `host.shadowRoot` remains `null`;
|
|
224
|
-
* retain this reference if later access is required.
|
|
225
|
-
*/
|
|
226
|
-
shadowRoot: ShadowRoot;
|
|
227
|
-
/** Shadow root mode. */
|
|
228
|
-
mode: "open" | "closed";
|
|
229
|
-
};
|
|
230
|
-
/** Options for {@link captureShadowRoots}. */
|
|
231
|
-
type ShadowRootCaptureOptions = {
|
|
232
|
-
/** Receives shadow roots synchronously. Return values are not awaited. */
|
|
233
|
-
onAttached: (event: ShadowRootAttachedEvent) => void;
|
|
234
|
-
/**
|
|
235
|
-
* Also reports open shadow roots that already exist when capture starts.
|
|
236
|
-
* These callbacks may run before `captureShadowRoots()` returns. Existing
|
|
237
|
-
* closed roots cannot be discovered. Defaults to `false`.
|
|
238
|
-
*/
|
|
239
|
-
includeExisting?: boolean;
|
|
240
|
-
/** Optional diagnostic logger. */
|
|
241
|
-
logger?: Logger;
|
|
242
|
-
};
|
|
243
|
-
/** Event that should schedule a rendered UI-state read. */
|
|
244
|
-
type UiStateTrigger = {
|
|
245
|
-
target: EventTarget;
|
|
246
|
-
type: string;
|
|
247
|
-
capture?: boolean;
|
|
248
|
-
};
|
|
249
|
-
/** A capture handle that also accepts imperative triggers such as completed network exchanges. */
|
|
250
|
-
type UiStateCaptureHandle = CaptureHandle & {
|
|
251
|
-
/** Coalesces a state read onto the next task, after the application's synchronous layout work. */
|
|
252
|
-
schedule(): void;
|
|
253
|
-
};
|
|
254
|
-
/** Options for {@link captureUiState}. State interpretation remains application-owned. */
|
|
255
|
-
type UiStateCaptureOptions<T> = {
|
|
256
|
-
/** Reads one allowlisted semantic snapshot. Return undefined to emit nothing. */
|
|
257
|
-
read: () => T | undefined;
|
|
258
|
-
/** Receives the snapshot after the deferred read. Return values are not awaited. */
|
|
259
|
-
onState: (state: T) => void;
|
|
260
|
-
/** DOM/custom events that should schedule a read. */
|
|
261
|
-
triggers?: readonly UiStateTrigger[];
|
|
262
|
-
/** Task delay in milliseconds. Defaults to 0. */
|
|
263
|
-
delayMs?: number;
|
|
264
|
-
/** Optional diagnostic logger. */
|
|
265
|
-
logger?: Logger;
|
|
266
|
-
};
|
|
267
218
|
|
|
268
219
|
/**
|
|
269
220
|
* Observes WebAuthn ceremonies initiated through
|
|
@@ -332,52 +283,12 @@ declare function captureNetwork<RequestBody = unknown, ResponseBody = unknown>(o
|
|
|
332
283
|
declare function captureNavigation(options: NavigationCaptureOptions): CaptureHandle;
|
|
333
284
|
|
|
334
285
|
/**
|
|
335
|
-
*
|
|
336
|
-
*
|
|
337
|
-
*
|
|
338
|
-
* Set `includeExisting` to also report discoverable open roots that already
|
|
339
|
-
* exist. Closed roots created before capture starts cannot be discovered.
|
|
340
|
-
* Callbacks run synchronously; existing roots may be reported before this
|
|
341
|
-
* function returns.
|
|
342
|
-
*
|
|
343
|
-
* Assumes a browser environment whose DOM and shadow DOM primitives behave
|
|
344
|
-
* as specified, and a `logger` that never throws. Behavior in environments
|
|
345
|
-
* that violate these assumptions is undefined.
|
|
346
|
-
*
|
|
347
|
-
* @param options Shadow-root callback and discovery options.
|
|
348
|
-
* @returns A handle used to inspect the capture mode or stop event delivery.
|
|
286
|
+
* Returns the visible composed event path. Outside dispatch the browser path is
|
|
287
|
+
* empty, so the event's retargeted target stands in when one is available.
|
|
349
288
|
*/
|
|
350
|
-
declare function captureShadowRoots(options: ShadowRootCaptureOptions): CaptureHandle;
|
|
351
|
-
/**
|
|
352
|
-
* Returns the first entry in `event.composedPath()` when available, otherwise
|
|
353
|
-
* returns `event.target`. Closed shadow boundaries remain subject to browser
|
|
354
|
-
* retargeting.
|
|
355
|
-
*
|
|
356
|
-
* @param event Event whose target should be resolved.
|
|
357
|
-
* @returns The deepest visible target, or `null` when the event has no target.
|
|
358
|
-
*/
|
|
359
|
-
declare function composedTarget(event: Event): EventTarget | null;
|
|
360
|
-
/** Returns the visible composed event path; outside dispatch the path is empty and the retargeted target stands in. */
|
|
361
289
|
declare function composedPath(event: Event): readonly EventTarget[];
|
|
362
290
|
|
|
363
|
-
/**
|
|
364
|
-
* Defers allowlisted UI-state reads until the application has handled the
|
|
365
|
-
* triggering event. This is useful when a component announces a transition
|
|
366
|
-
* before synchronously updating its DOM, and for state changes that are only
|
|
367
|
-
* observable after a network callback or mutation.
|
|
368
|
-
*/
|
|
369
|
-
declare function captureUiState<T>(options: UiStateCaptureOptions<T>): UiStateCaptureHandle;
|
|
370
|
-
|
|
371
|
-
/**
|
|
372
|
-
* Creates a diagnostic logger that writes to `console.log` with an optional
|
|
373
|
-
* prefix. Logging failures are ignored.
|
|
374
|
-
*
|
|
375
|
-
* @param prefix Prefix added to each message. Defaults to `[autocapture]`.
|
|
376
|
-
* @returns A logger suitable for the capture option objects.
|
|
377
|
-
*/
|
|
378
|
-
declare function createConsoleLogger(prefix?: string): Logger;
|
|
379
|
-
|
|
380
291
|
/** Version identifier embedded in the current build. */
|
|
381
292
|
declare const VERSION: string;
|
|
382
293
|
|
|
383
|
-
export { type CaptureHandle, type HttpExchange, type HttpRequestStarted, type Logger, type NavigationCaptureOptions, type NavigationEvent, type NavigationSource, type NetworkBodyDirection, type NetworkBodyProjectionContext, type NetworkBodyProjector, type NetworkCaptureOptions, type NetworkTransport,
|
|
294
|
+
export { type CaptureHandle, type HttpExchange, type HttpRequestStarted, type Logger, type NavigationCaptureOptions, type NavigationEvent, type NavigationSource, type NetworkBodyDirection, type NetworkBodyProjectionContext, type NetworkBodyProjector, type NetworkCaptureOptions, type NetworkTransport, VERSION, type WebAuthnCaptureOptions, type WebAuthnCeremonyCompletedEvent, type WebAuthnCeremonyContext, type WebAuthnCeremonyEvent, type WebAuthnCeremonyFailedEvent, type WebAuthnCeremonyStartedEvent, type WebAuthnMediation, type WebAuthnUiMode, captureNavigation, captureNetwork, captureWebAuthn, composedPath };
|
package/dist/index.d.ts
CHANGED
|
@@ -215,55 +215,6 @@ type NavigationCaptureOptions = {
|
|
|
215
215
|
/** Optional diagnostic logger. */
|
|
216
216
|
logger?: Logger;
|
|
217
217
|
};
|
|
218
|
-
/** A shadow root reported by {@link captureShadowRoots}. */
|
|
219
|
-
type ShadowRootAttachedEvent = {
|
|
220
|
-
/** Element that owns the shadow root. */
|
|
221
|
-
host: Element;
|
|
222
|
-
/**
|
|
223
|
-
* Attached shadow root. For a closed root, `host.shadowRoot` remains `null`;
|
|
224
|
-
* retain this reference if later access is required.
|
|
225
|
-
*/
|
|
226
|
-
shadowRoot: ShadowRoot;
|
|
227
|
-
/** Shadow root mode. */
|
|
228
|
-
mode: "open" | "closed";
|
|
229
|
-
};
|
|
230
|
-
/** Options for {@link captureShadowRoots}. */
|
|
231
|
-
type ShadowRootCaptureOptions = {
|
|
232
|
-
/** Receives shadow roots synchronously. Return values are not awaited. */
|
|
233
|
-
onAttached: (event: ShadowRootAttachedEvent) => void;
|
|
234
|
-
/**
|
|
235
|
-
* Also reports open shadow roots that already exist when capture starts.
|
|
236
|
-
* These callbacks may run before `captureShadowRoots()` returns. Existing
|
|
237
|
-
* closed roots cannot be discovered. Defaults to `false`.
|
|
238
|
-
*/
|
|
239
|
-
includeExisting?: boolean;
|
|
240
|
-
/** Optional diagnostic logger. */
|
|
241
|
-
logger?: Logger;
|
|
242
|
-
};
|
|
243
|
-
/** Event that should schedule a rendered UI-state read. */
|
|
244
|
-
type UiStateTrigger = {
|
|
245
|
-
target: EventTarget;
|
|
246
|
-
type: string;
|
|
247
|
-
capture?: boolean;
|
|
248
|
-
};
|
|
249
|
-
/** A capture handle that also accepts imperative triggers such as completed network exchanges. */
|
|
250
|
-
type UiStateCaptureHandle = CaptureHandle & {
|
|
251
|
-
/** Coalesces a state read onto the next task, after the application's synchronous layout work. */
|
|
252
|
-
schedule(): void;
|
|
253
|
-
};
|
|
254
|
-
/** Options for {@link captureUiState}. State interpretation remains application-owned. */
|
|
255
|
-
type UiStateCaptureOptions<T> = {
|
|
256
|
-
/** Reads one allowlisted semantic snapshot. Return undefined to emit nothing. */
|
|
257
|
-
read: () => T | undefined;
|
|
258
|
-
/** Receives the snapshot after the deferred read. Return values are not awaited. */
|
|
259
|
-
onState: (state: T) => void;
|
|
260
|
-
/** DOM/custom events that should schedule a read. */
|
|
261
|
-
triggers?: readonly UiStateTrigger[];
|
|
262
|
-
/** Task delay in milliseconds. Defaults to 0. */
|
|
263
|
-
delayMs?: number;
|
|
264
|
-
/** Optional diagnostic logger. */
|
|
265
|
-
logger?: Logger;
|
|
266
|
-
};
|
|
267
218
|
|
|
268
219
|
/**
|
|
269
220
|
* Observes WebAuthn ceremonies initiated through
|
|
@@ -332,52 +283,12 @@ declare function captureNetwork<RequestBody = unknown, ResponseBody = unknown>(o
|
|
|
332
283
|
declare function captureNavigation(options: NavigationCaptureOptions): CaptureHandle;
|
|
333
284
|
|
|
334
285
|
/**
|
|
335
|
-
*
|
|
336
|
-
*
|
|
337
|
-
*
|
|
338
|
-
* Set `includeExisting` to also report discoverable open roots that already
|
|
339
|
-
* exist. Closed roots created before capture starts cannot be discovered.
|
|
340
|
-
* Callbacks run synchronously; existing roots may be reported before this
|
|
341
|
-
* function returns.
|
|
342
|
-
*
|
|
343
|
-
* Assumes a browser environment whose DOM and shadow DOM primitives behave
|
|
344
|
-
* as specified, and a `logger` that never throws. Behavior in environments
|
|
345
|
-
* that violate these assumptions is undefined.
|
|
346
|
-
*
|
|
347
|
-
* @param options Shadow-root callback and discovery options.
|
|
348
|
-
* @returns A handle used to inspect the capture mode or stop event delivery.
|
|
286
|
+
* Returns the visible composed event path. Outside dispatch the browser path is
|
|
287
|
+
* empty, so the event's retargeted target stands in when one is available.
|
|
349
288
|
*/
|
|
350
|
-
declare function captureShadowRoots(options: ShadowRootCaptureOptions): CaptureHandle;
|
|
351
|
-
/**
|
|
352
|
-
* Returns the first entry in `event.composedPath()` when available, otherwise
|
|
353
|
-
* returns `event.target`. Closed shadow boundaries remain subject to browser
|
|
354
|
-
* retargeting.
|
|
355
|
-
*
|
|
356
|
-
* @param event Event whose target should be resolved.
|
|
357
|
-
* @returns The deepest visible target, or `null` when the event has no target.
|
|
358
|
-
*/
|
|
359
|
-
declare function composedTarget(event: Event): EventTarget | null;
|
|
360
|
-
/** Returns the visible composed event path; outside dispatch the path is empty and the retargeted target stands in. */
|
|
361
289
|
declare function composedPath(event: Event): readonly EventTarget[];
|
|
362
290
|
|
|
363
|
-
/**
|
|
364
|
-
* Defers allowlisted UI-state reads until the application has handled the
|
|
365
|
-
* triggering event. This is useful when a component announces a transition
|
|
366
|
-
* before synchronously updating its DOM, and for state changes that are only
|
|
367
|
-
* observable after a network callback or mutation.
|
|
368
|
-
*/
|
|
369
|
-
declare function captureUiState<T>(options: UiStateCaptureOptions<T>): UiStateCaptureHandle;
|
|
370
|
-
|
|
371
|
-
/**
|
|
372
|
-
* Creates a diagnostic logger that writes to `console.log` with an optional
|
|
373
|
-
* prefix. Logging failures are ignored.
|
|
374
|
-
*
|
|
375
|
-
* @param prefix Prefix added to each message. Defaults to `[autocapture]`.
|
|
376
|
-
* @returns A logger suitable for the capture option objects.
|
|
377
|
-
*/
|
|
378
|
-
declare function createConsoleLogger(prefix?: string): Logger;
|
|
379
|
-
|
|
380
291
|
/** Version identifier embedded in the current build. */
|
|
381
292
|
declare const VERSION: string;
|
|
382
293
|
|
|
383
|
-
export { type CaptureHandle, type HttpExchange, type HttpRequestStarted, type Logger, type NavigationCaptureOptions, type NavigationEvent, type NavigationSource, type NetworkBodyDirection, type NetworkBodyProjectionContext, type NetworkBodyProjector, type NetworkCaptureOptions, type NetworkTransport,
|
|
294
|
+
export { type CaptureHandle, type HttpExchange, type HttpRequestStarted, type Logger, type NavigationCaptureOptions, type NavigationEvent, type NavigationSource, type NetworkBodyDirection, type NetworkBodyProjectionContext, type NetworkBodyProjector, type NetworkCaptureOptions, type NetworkTransport, VERSION, type WebAuthnCaptureOptions, type WebAuthnCeremonyCompletedEvent, type WebAuthnCeremonyContext, type WebAuthnCeremonyEvent, type WebAuthnCeremonyFailedEvent, type WebAuthnCeremonyStartedEvent, type WebAuthnMediation, type WebAuthnUiMode, captureNavigation, captureNetwork, captureWebAuthn, composedPath };
|
package/dist/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var ne=Object.defineProperty;var qe=Object.getOwnPropertyDescriptor;var Pe=Object.getOwnPropertyNames;var xe=Object.prototype.hasOwnProperty;var De=(e,t)=>{for(var n in t)ne(e,n,{get:t[n],enumerable:!0})},Le=(e,t,n,r)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of Pe(t))!xe.call(e,o)&&o!==n&&ne(e,o,{get:()=>t[o],enumerable:!(r=qe(t,o))||r.enumerable});return e};var Ne=e=>Le(ne({},"__esModule",{value:!0}),e);var Ve={};De(Ve,{VERSION:()=>ke,captureNavigation:()=>be,captureNetwork:()=>ge,captureShadowRoots:()=>Re,captureUiState:()=>Oe,captureWebAuthn:()=>de,composedPath:()=>se,composedTarget:()=>Ce,createConsoleLogger:()=>Ee});module.exports=Ne(Ve);var re={log:()=>{}};function j(e){return e?{log:(...t)=>{try{let n=e.log(...t);if(n&&(typeof n=="object"||typeof n=="function"))try{Promise.resolve(n).catch(()=>{})}catch{}}catch{}}}:re}var ce=Symbol.for("corbado.autocapture.installed");function M(e){try{return typeof e=="function"&&Object.prototype.hasOwnProperty.call(e,ce)}catch{return!1}}function _(e,t){var r,o;let n=t;try{Object.defineProperty(e,ce,{value:t,configurable:!0})}catch{}try{Object.defineProperty(e,"name",{value:(r=n.name)!=null?r:"",configurable:!0})}catch{}try{Object.defineProperty(e,"length",{value:(o=n.length)!=null?o:0,configurable:!0})}catch{}return e}function b(){return{mode:"unavailable",disconnect:()=>{}}}function W(e,t,n){let r=j(e);return o=>{try{let a=n(o);if(a&&(typeof a=="object"||typeof a=="function"))try{Promise.resolve(a).catch(c=>r.log(`${t} listener failed`,c))}catch(c){r.log(`${t} listener failed`,c)}}catch(a){r.log(`${t} listener failed`,a)}}}function de(e){let t=j(e.logger),n=e.onEvent;if(typeof n!="function")return b();let r=typeof navigator=="undefined"?void 0:navigator,o=r==null?void 0:r.credentials;if(!r||!o)return t.log("webauthn capture unavailable: navigator.credentials missing"),b();let a=o.get,c=o.create;if(typeof a!="function"||typeof c!="function")return t.log("webauthn capture unavailable: credentials methods missing"),b();if(M(a)||M(c))return t.log("webauthn capture unavailable: an equivalent capture is already active"),b();let d=!1,g=0,P=W(t,"webauthn",u=>{if(d)return n(u)}),m=(u,w)=>{let N={invoke(...x){let k=this,R=x[0];if(!d||!Q(R)||!Q(R.publicKey))return Reflect.apply(w,k,x);let z=R.publicKey,p=`wa-${++g}`,C=Reflect.apply(w,k,x),v=Q(R.signal)?R.signal:void 0,f=Be(u,R,z),X={...f,ceremonyId:p,phase:"started",userActivation:je(r)};if(f.kind==="authentication"){let A=z;X.requestOptionsJson=Ie(A,t)}return P(X),Promise.resolve(C).then(A=>(d&&P({...f,ceremonyId:p,phase:"completed",credentialJson:Me(A,u,t),...(v==null?void 0:v.aborted)===!0?{aborted:!0}:{}}),A),A=>{throw d&&P({...f,ceremonyId:p,phase:"failed",error:A,errorName:We(A),...(v==null?void 0:v.aborted)===!0?{aborted:!0}:{}}),A})}}.invoke;return _(N,{name:u,length:0})},O=(u,w)=>{let N=m(u,w),x=Object.getOwnPropertyDescriptor(o,u);if(x&&(!("value"in x)||x.writable!==!0))return null;try{o[u]=N}catch{return null}return()=>{o[u]===N&&(x?o[u]=x.value:delete o[u])}},E=O("get",a),s=E?O("create",c):null;return!E||!s?(E==null||E(),t.log("webauthn capture unavailable: credentials methods cannot be patched safely"),b()):(d=!0,{mode:"standard",disconnect:()=>{d=!1,E(),s()}})}function Be(e,t,n){let r=Te(t.mediation);if(e==="create")return{kind:"registration",mediation:r};let o=n;return{kind:"authentication",mediation:r,uiMode:He(t.uiMode),credentialSet:Array.isArray(o.allowCredentials)&&o.allowCredentials.length>0?"allowlisted":"discoverable"}}function Te(e){return e===void 0?"optional":e==="silent"||e==="optional"||e==="conditional"||e==="required"?e:"unknown"}function He(e){return e===void 0?"default":e==="immediate"?"immediate":"unknown"}function je(e){let t=e.userActivation;return typeof(t==null?void 0:t.isActive)=="boolean"?t.isActive:void 0}function Me(e,t,n){var r;if(e)try{let o=e,a=o.response,c={id:J(o.id),rawId:$(o.rawId),type:J(o.type),authenticatorAttachment:J(o.authenticatorAttachment),response:t==="create"?{clientDataJSON:$(a==null?void 0:a.clientDataJSON),attestationObject:$(a==null?void 0:a.attestationObject),transports:oe((r=a==null?void 0:a.getTransports)==null?void 0:r.call(a))}:{clientDataJSON:$(a==null?void 0:a.clientDataJSON),authenticatorData:$(a==null?void 0:a.authenticatorData),signature:$(a==null?void 0:a.signature),userHandle:$(a==null?void 0:a.userHandle)},...t==="create"?_e(o):{}};return JSON.stringify(c)}catch(o){n.log("credential serialization failed",o);return}}function Ie(e,t){try{let n={},r=J(e.rpId),o=J(e.userVerification),a=oe(e.hints);return r!==void 0&&(n.rpId=r),typeof e.timeout=="number"&&Number.isFinite(e.timeout)&&(n.timeout=e.timeout),o!==void 0&&(n.userVerification=o),a!==void 0&&(n.hints=a),n.challenge=$(e.challenge),Array.isArray(e.allowCredentials)&&(n.allowCredentials=Ue(e.allowCredentials)),JSON.stringify(n)}catch(n){t.log("request options serialization failed",n);return}}function Ue(e){let t=[];for(let n of e){if(!Q(n))continue;let r=n;t.push({type:J(r.type),id:$(r.id),transports:oe(r.transports)})}return t}function oe(e){if(Array.isArray(e))return e.filter(t=>typeof t=="string")}function J(e){return typeof e=="string"?e:void 0}function _e(e){var r;let t=(r=e.getClientExtensionResults)==null?void 0:r.call(e);if(!Q(t))return{};let n=t.credProps;return!n||typeof n.rk!="boolean"?{}:{clientExtensionResults:{credProps:{rk:n.rk}}}}function $(e){let t;if(e instanceof ArrayBuffer)t=new Uint8Array(e);else if(ArrayBuffer.isView(e))t=new Uint8Array(e.buffer,e.byteOffset,e.byteLength);else return;let n="";for(let r of t)n+=String.fromCharCode(r);return btoa(n).replace(/\+/g,"-").replace(/\//g,"_").replace(/=+$/g,"")}function Q(e){return e!==null&&(typeof e=="object"||typeof e=="function")}function We(e){return e instanceof DOMException?e.name:"UnknownError"}var le=0;function pe(){return le+=1,`network-${le}`}function Fe(e,t){let n=e.responseType;if(n===""||n==="text")return t(e.responseText);if(n==="json"){let r=e.response;return r==null?void 0:t(r)}}var Xe=500,fe=Symbol("body-read-timeout");function he(e){return/event-stream|octet-stream/i.test(e)?!1:/json|text|urlencoded/i.test(e)}async function ye(e,t){let n=e.body;if(!n)return;let r=n.getReader(),o;try{let a=new Promise(g=>{o=setTimeout(()=>g(fe),Xe)}),c=new TextDecoder,d=[];for(;;){let g=await Promise.race([r.read(),a]);if(g===fe){t.log("body omitted: read timed out"),r.cancel().catch(()=>{});return}if(g.done)break;d.push(c.decode(g.value,{stream:!0}))}return d.push(c.decode()),d.join("")}catch{r.cancel().catch(()=>{});return}finally{o!==void 0&&clearTimeout(o)}}function ae(e){var t;(t=e==null?void 0:e.body)==null||t.cancel().catch(()=>{})}function ie(e,t,n,r,o){try{let a=Object.getOwnPropertyDescriptor(e,t);Ke(a,{...r,value:n})&&Object.defineProperty(e,t,r)}catch(a){o.log(`${String(t)} restoration skipped`,a)}}function Ke(e,t){return!!e&&"value"in e&&"value"in t&&e.value===t.value&&e.writable===t.writable&&e.enumerable===t.enumerable&&e.configurable===t.configurable}function ge(e){var k,R,z;let{onExchange:t,onRequest:n,match:r}=e;if(typeof t!="function"||typeof r!="function")throw new TypeError("captureNetwork requires onExchange and match callbacks");let o=j(e.logger),a=(k=e.transports)!=null?k:["xhr","fetch"],c=(R=e.bodyCapture)==null?void 0:R.request,d=(z=e.bodyCapture)==null?void 0:z.response,g=typeof c=="function",P=typeof d=="function",m=!1,O=W(o,"network",p=>{if(m)return t(p)}),E=W(o,"network request",p=>{if(m)return n==null?void 0:n(p)}),s=(p,C,v)=>{if(typeof v=="function")try{let f=v(p,C);return f===void 0||typeof(f==null?void 0:f.then)=="function"?void 0:f}catch(f){o.log("body projection failed",f);return}},u=(p,C)=>{try{let v=typeof document!="undefined"?document.baseURI:void 0,f=new URL(String(p),v);return/\/observe\/events\/[^/]+\/?$/.test(f.pathname)?void 0:r(f,C)===!0?{url:f.href,path:f.pathname}:void 0}catch{return}},w=()=>{if(typeof XMLHttpRequest=="undefined")return o.log("xhr capture unavailable: XMLHttpRequest missing"),null;let p=XMLHttpRequest.prototype,C=Object.getOwnPropertyDescriptor(p,"open"),v=Object.getOwnPropertyDescriptor(p,"send");if(!C||!("value"in C)||typeof C.value!="function"||!v||!("value"in v)||typeof v.value!="function")return o.log("xhr capture unavailable: XMLHttpRequest methods missing"),null;let f=C.value,X=v.value;if(M(f)||M(X))return o.log("xhr capture unavailable: an equivalent capture is already active"),null;let A=new WeakMap,q=new Set,L=!1,T={open(...S){var h;let i=Reflect.apply(f,this,S);if(!m||!L)return i;try{let B=A.get(this);B&&(B.reported=!0,(h=B.cleanupListeners)==null||h.call(B));let H=String(S[0]).toUpperCase(),D=u(S[1],H);D?A.set(this,{method:H,url:D.url,path:D.path,reported:!1}):A.delete(this)}catch(B){o.log("xhr open observation failed",B)}return i}}.open,K={send(...S){let i=m&&L?A.get(this):void 0;if(!i||i.reported||i.cleanupListeners)return Reflect.apply(X,this,S);let h=()=>{},B=!1;try{i.requestId=pe();let D={direction:"request",transport:"xhr",method:i.method,url:i.url,path:i.path};i.requestBody=g&&typeof S[0]=="string"?s(S[0],D,c):void 0;let G=()=>{i.outcome===void 0&&(i.outcome="abort")},Y=()=>{i.outcome===void 0&&(i.outcome="timeout")},l=()=>{i.outcome===void 0&&(i.outcome="error")},y=()=>{var V;h();try{if(!m||!L||i.reported||!i.requestId)return;i.reported=!0;let U={direction:"response",transport:"xhr",method:i.method,url:i.url,path:i.path},te=this.status,ue={requestId:i.requestId,transport:"xhr",method:i.method,url:i.url,path:i.path,status:te,ok:te>=200&&te<300,outcome:(V=i.outcome)!=null?V:"load",durationMs:i.startedAt!==void 0?Date.now()-i.startedAt:void 0,responseUrl:this.responseURL||void 0,requestBody:i.requestBody,responseBody:P?Fe(this,Ae=>s(Ae,U,d)):void 0};i.requestEmitted?O(ue):i.pendingExchange=ue}catch(U){o.log("xhr exchange observation failed",U)}finally{A.get(this)===i&&A.delete(this)}},I=()=>{try{this.readyState===XMLHttpRequest.DONE&&this.status!==0&&y()}catch(V){o.log("xhr ready-state observation failed",V)}},F=()=>y();h=()=>{for(let[V,U]of[["readystatechange",I],["abort",G],["timeout",Y],["error",l],["loadend",F]])this.removeEventListener(V,U);i.cleanupListeners===h&&(i.cleanupListeners=void 0),q.delete(h)},this.addEventListener("readystatechange",I),this.addEventListener("abort",G),this.addEventListener("timeout",Y),this.addEventListener("error",l),this.addEventListener("loadend",F),i.cleanupListeners=h,q.add(h),i.startedAt=Date.now(),B=!0}catch(D){o.log("xhr send observation failed",D),h()}let H;try{H=Reflect.apply(X,this,S)}catch(D){throw h(),D}if(B&&i.requestId!==void 0&&i.startedAt!==void 0){i.requestEmitted=!0,E({requestId:i.requestId,transport:"xhr",method:i.method,url:i.url,path:i.path,startedAt:i.startedAt,requestBody:i.requestBody});let D=i.pendingExchange;i.pendingExchange=void 0,D&&O(D)}return H}}.send;return _(T,f),_(K,X),C.writable!==!0||v.writable!==!0?(o.log("xhr capture unavailable: XMLHttpRequest methods are not writable"),null):(Object.defineProperty(p,"open",{...C,value:T}),Object.defineProperty(p,"send",{...v,value:K}),L=!0,()=>{L=!1;for(let S of[...q])S();ie(p,"open",T,C,o),ie(p,"send",K,v,o)})},N=()=>{let p=globalThis,C=Object.getOwnPropertyDescriptor(p,"fetch");if(!C||!("value"in C))return o.log("fetch capture unavailable: fetch is not an own data property"),null;let v=C.value;if(typeof v!="function")return o.log("fetch capture unavailable: fetch missing"),null;if(M(v))return o.log("fetch capture unavailable: an equivalent capture is already active"),null;let f=!1,X=async(q,L,T,K)=>{try{if(!m||!f){ae(T);return}let[S,i]=await Promise.all([K!=null?K:Promise.resolve(void 0),T?ye(T,o):Promise.resolve(void 0)]);if(!m||!f)return;let h={direction:"request",transport:"fetch",method:q.method,url:q.url,path:q.path},B={...h,direction:"response"},H=q.requestBody;H===void 0&&S!==void 0&&(H=s(S,h,c));let D=i!==void 0?s(i,B,d):void 0;O({requestId:q.requestId,transport:"fetch",method:q.method,url:q.url,path:q.path,status:L.status,ok:L.ok,outcome:"load",durationMs:Date.now()-q.startedAt,responseUrl:L.url||void 0,requestBody:H,responseBody:D})}catch(S){o.log("fetch exchange observation failed",S)}},A={fetch(...q){var H,D,G,Y;let L;try{let l=q[0],y=q[1];if(m&&f&&g&&typeof Request!="undefined"&&l instanceof Request&&(y==null?void 0:y.body)===void 0&&l.body){let I=String((H=y==null?void 0:y.method)!=null?H:l.method).toUpperCase(),F=(D=l.headers.get("content-type"))!=null?D:"";u(l.url,I)&&he(F)&&(L=l.clone())}}catch(l){o.log("fetch observation failed",l)}let T,K=Date.now();try{T=Reflect.apply(v,this,q)}catch(l){throw ae(L),l}let S,i;try{if(m&&f){let l=q[0],y=q[1],I=typeof Request!="undefined"&&l instanceof Request,F=String((G=y==null?void 0:y.method)!=null?G:I?l.method:"GET").toUpperCase(),V=I?l.url:l,U=u(V,F);U&&(S={requestId:pe(),method:F,url:U.url,path:U.path,startedAt:K},i=(Y=y==null?void 0:y.signal)!=null?Y:I?l.signal:void 0,g&&typeof(y==null?void 0:y.body)=="string"&&(S.requestBody=s(y.body,{direction:"request",transport:"fetch",method:F,url:U.url,path:U.path},c)))}}catch(l){o.log("fetch observation failed",l)}if(!S)return ae(L),T;let h=S;E({requestId:h.requestId,transport:"fetch",method:h.method,url:h.url,path:h.path,startedAt:h.startedAt,requestBody:h.requestBody});let B=L?ye(L,o):void 0;return T.then(l=>{var I;let y;try{if(m&&f&&P){let F=(I=l.headers.get("content-type"))!=null?I:"";he(F)&&l.body&&(y=l.clone())}}catch{}X(h,l,y,B)},l=>{try{if(!m||!f)return;let y=(i==null?void 0:i.aborted)===!0||(l==null?void 0:l.name)==="AbortError"||typeof DOMException!="undefined"&&l instanceof DOMException&&l.code===DOMException.ABORT_ERR;O({requestId:h.requestId,transport:"fetch",method:h.method,url:h.url,path:h.path,status:0,ok:!1,outcome:y?"abort":"error",durationMs:Date.now()-h.startedAt})}catch(y){o.log("fetch failure observation failed",y)}}),T}}.fetch;return _(A,v),C.writable!==!0?(o.log("fetch capture unavailable: fetch is not writable"),null):(Object.defineProperty(p,"fetch",{...C,value:A}),f=!0,()=>{f=!1,ie(p,"fetch",A,C,o)})},x=[];if(a.includes("xhr")){let p=w();p&&x.push(p)}if(a.includes("fetch")){let p=N();p&&x.push(p)}return x.length===0?b():(m=!0,{mode:"standard",disconnect:()=>{m=!1;for(let p of x.splice(0))p()}})}function be(e){let t=j(),n;try{if(t=j(e.logger),n=e.onNavigate,typeof n!="function")return b()}catch{return b()}let r,o,a,c,d,g;try{if(r=window,o=r==null?void 0:r.history,!r||!o)return t.log("navigation capture unavailable: window/history missing"),b();if(d=me(o,"pushState"),g=me(o,"replaceState"),!d||!g)return t.log("navigation capture unavailable: history method descriptors missing"),b();if(a=d.descriptor.value,c=g.descriptor.value,typeof a!="function"||typeof c!="function")return t.log("navigation capture unavailable: history methods missing"),b();if(typeof r.addEventListener!="function"||typeof r.removeEventListener!="function")return t.log("navigation capture unavailable: window event methods missing"),b()}catch(k){return t.log("navigation capture unavailable: history inspection failed",k),b()}if(M(a)||M(c))return t.log("navigation capture unavailable: an equivalent capture is already active"),b();let P=!1,m=()=>({path:r.location.pathname,search:r.location.search,hash:r.location.hash}),O;try{O=m()}catch(k){return t.log("navigation capture unavailable: location inspection failed",k),b()}let E=W(t,"navigation",k=>{if(P)return n(k)}),s=k=>{if(P)try{let R=m();if(R.path===O.path&&R.search===O.search&&R.hash===O.hash)return;O=R,E({...R,source:k})}catch(R){t.log("navigation observation failed",R)}},u={pushState(...k){let R=Reflect.apply(a,this,k);return s("push"),R}}.pushState,w={replaceState(...k){let R=Reflect.apply(c,this,k);return s("replace"),R}}.replaceState;_(u,a),_(w,c);let N=()=>s("pop"),x=()=>s("hash");try{if(ve(d,u),ve(g,w),o.pushState!==u||o.replaceState!==w)throw new Error("history method replacement did not take effect");r.addEventListener("popstate",N),r.addEventListener("hashchange",x),P=!0}catch(k){return P=!1,ee(r,"popstate",N,t),ee(r,"hashchange",x,t),Z(g,w,t),Z(d,u,t),t.log("navigation capture unavailable: history methods are not writable",k),n=()=>{},E=()=>{},t=j(),b()}return{mode:"standard",disconnect:()=>{P=!1,n=()=>{},ee(r,"popstate",N,t),ee(r,"hashchange",x,t),Z(d,u,t),Z(g,w,t),E=()=>{},t=j()}}}function me(e,t){let n=e;for(;n;){let r=Object.getOwnPropertyDescriptor(n,t);if(r)return!("value"in r)||typeof r.value!="function"?null:{owner:n,key:t,descriptor:r};n=Object.getPrototypeOf(n)}return null}function ve(e,t){if(e.descriptor.writable!==!0)throw new TypeError(`${e.key} is not writable`);let n=Object.getOwnPropertyDescriptor(e.owner,e.key);if(!we(n,e.descriptor))throw new Error(`${e.key} changed during installation`);Object.defineProperty(e.owner,e.key,{...e.descriptor,value:t})}function we(e,t){return!!e&&"value"in e&&"value"in t&&e.value===t.value&&e.writable===t.writable&&e.enumerable===t.enumerable&&e.configurable===t.configurable}function Z(e,t,n){try{let r=Object.getOwnPropertyDescriptor(e.owner,e.key);we(r,{...e.descriptor,value:t})&&Object.defineProperty(e.owner,e.key,e.descriptor)}catch(r){n.log(`navigation ${e.key} restoration skipped`,r)}}function ee(e,t,n,r){try{e.removeEventListener(t,n)}catch(o){r.log(`navigation ${t} listener removal skipped`,o)}}function Re(e){var E;let t=(E=e.logger)!=null?E:re,n=e.onAttached;if(typeof n!="function")return b();let r=Element.prototype,o=Object.getOwnPropertyDescriptor(r,"attachShadow");if(!o||typeof o.value!="function")return t.log("shadow-root capture unavailable: attachShadow not supported"),b();let a=o.value;if(M(a))return t.log("shadow-root capture unavailable: an equivalent capture is already active"),b();let c=!1,d=new WeakSet,g=W(t,"shadow-root",n),P=(s,u)=>{!c||d.has(u)||(d.add(u),g({host:s,shadowRoot:u,mode:u.mode==="closed"?"closed":"open"}))},m={attachShadow(...s){let u=Reflect.apply(a,this,s);return P(this,u),u}}.attachShadow;_(m,a);try{Object.defineProperty(r,"attachShadow",{...o,value:m})}catch(s){return t.log("shadow-root capture unavailable: attachShadow is locked",s),b()}c=!0;let O=s=>{let u=s.querySelectorAll("*");for(let w=0;w<u.length&&c;w++){let N=u[w].shadowRoot;N&&(P(u[w],N),O(N))}};return e.includeExisting&&O(document),{mode:"standard",disconnect:()=>{c=!1;let s=Object.getOwnPropertyDescriptor(r,"attachShadow");$e(s,{...o,value:m})&&Object.defineProperty(r,"attachShadow",o)}}}function Ce(e){var t;return(t=se(e)[0])!=null?t:null}function se(e){let t=e.composedPath();return t.length>0?t:e.target?[e.target]:[]}function $e(e,t){return!!e&&"value"in e&&"value"in t&&e.value===t.value&&e.writable===t.writable&&e.enumerable===t.enumerable&&e.configurable===t.configurable}function Oe(e){var m,O,E;let t=j(e==null?void 0:e.logger),n=e==null?void 0:e.read,r=e==null?void 0:e.onState;if(typeof n!="function"||typeof r!="function")return Se();let o=Number.isFinite(e.delayMs)&&((m=e.delayMs)!=null?m:0)>=0&&(O=e.delayMs)!=null?O:0,a=W(t,"ui-state",r),c=!0,d,g=[],P=()=>{c&&(d!==void 0&&clearTimeout(d),d=setTimeout(()=>{if(d=void 0,!!c)try{let s=n();s!==void 0&&a(s)}catch(s){t.log("ui-state read failed",s)}},o))};try{for(let s of(E=e.triggers)!=null?E:[]){if(!(s!=null&&s.target)||typeof s.target.addEventListener!="function")continue;let u=P;s.target.addEventListener(s.type,u,s.capture===!0),g.push({trigger:s,listener:u})}}catch(s){t.log("ui-state trigger installation failed",s);for(let{trigger:u,listener:w}of g)try{u.target.removeEventListener(u.type,w,u.capture===!0)}catch{}return c=!1,Se()}return{mode:"standard",schedule:P,disconnect:()=>{if(c){c=!1,d!==void 0&&clearTimeout(d),d=void 0;for(let{trigger:s,listener:u}of g)try{s.target.removeEventListener(s.type,u,s.capture===!0)}catch(w){t.log("ui-state trigger removal failed",w)}g.length=0}}}}function Se(){return{mode:"unavailable",schedule:()=>{},disconnect:()=>{}}}function Ee(e="[autocapture]"){return{log:(...t)=>{try{let n=console.log(e,...t);if(n&&(typeof n=="object"||typeof n=="function"))try{Promise.resolve(n).catch(()=>{})}catch{}}catch{}}}}var ke="0.1.0-next.3-b8e8889";0&&(module.exports={VERSION,captureNavigation,captureNetwork,captureShadowRoots,captureUiState,captureWebAuthn,composedPath,composedTarget,createConsoleLogger});
|
|
1
|
+
"use strict";var ne=Object.defineProperty;var Ce=Object.getOwnPropertyDescriptor;var ke=Object.getOwnPropertyNames;var qe=Object.prototype.hasOwnProperty;var Oe=(e,t)=>{for(var o in t)ne(e,o,{get:t[o],enumerable:!0})},Ae=(e,t,o,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let r of ke(t))!qe.call(e,r)&&r!==o&&ne(e,r,{get:()=>t[r],enumerable:!(n=Ce(t,r))||n.enumerable});return e};var Pe=e=>Ae(ne({},"__esModule",{value:!0}),e);var _e={};Oe(_e,{VERSION:()=>we,captureNavigation:()=>me,captureNetwork:()=>he,captureWebAuthn:()=>ue,composedPath:()=>ve});module.exports=Pe(_e);var Ee={log:()=>{}};function U(e){return e?{log:(...t)=>{try{let o=e.log(...t);if(o&&(typeof o=="object"||typeof o=="function"))try{Promise.resolve(o).catch(()=>{})}catch{}}catch{}}}:Ee}var se=Symbol.for("corbado.autocapture.installed");function _(e){try{return typeof e=="function"&&Object.prototype.hasOwnProperty.call(e,se)}catch{return!1}}function X(e,t){var n,r;let o=t;try{Object.defineProperty(e,se,{value:t,configurable:!0})}catch{}try{Object.defineProperty(e,"name",{value:(n=o.name)!=null?n:"",configurable:!0})}catch{}try{Object.defineProperty(e,"length",{value:(r=o.length)!=null?r:0,configurable:!0})}catch{}return e}function C(){return{mode:"unavailable",disconnect:()=>{}}}function $(e,t,o){let n=U(e);return r=>{try{let a=o(r);if(a&&(typeof a=="object"||typeof a=="function"))try{Promise.resolve(a).catch(p=>n.log(`${t} listener failed`,p))}catch(p){n.log(`${t} listener failed`,p)}}catch(a){n.log(`${t} listener failed`,a)}}}function ue(e){let t=U(e.logger),o=e.onEvent;if(typeof o!="function")return C();let n=typeof navigator=="undefined"?void 0:navigator,r=n==null?void 0:n.credentials;if(!n||!r)return t.log("webauthn capture unavailable: navigator.credentials missing"),C();let a=r.get,p=r.create;if(typeof a!="function"||typeof p!="function")return t.log("webauthn capture unavailable: credentials methods missing"),C();if(_(a)||_(p))return t.log("webauthn capture unavailable: an equivalent capture is already active"),C();let y=!1,k=0,B=$(t,"webauthn",h=>{if(y)return o(h)}),q=(h,D)=>{let I={invoke(...O){let v=this,g=O[0];if(!y||!Q(g)||!Q(g.publicKey))return Reflect.apply(D,v,O);let z=g.publicKey,u=`wa-${++k}`,m=Reflect.apply(D,v,O),l=Q(g.signal)?g.signal:void 0,f=xe(h,g,z),W={...f,ceremonyId:u,phase:"started",userActivation:Be(n)};if(f.kind==="authentication"){let w=z;W.requestOptionsJson=Le(w,t)}return B(W),Promise.resolve(m).then(w=>(y&&B({...f,ceremonyId:u,phase:"completed",credentialJson:De(w,h,t),...(l==null?void 0:l.aborted)===!0?{aborted:!0}:{}}),w),w=>{throw y&&B({...f,ceremonyId:u,phase:"failed",error:w,errorName:Te(w),...(l==null?void 0:l.aborted)===!0?{aborted:!0}:{}}),w})}}.invoke;return X(I,{name:h,length:0})},x=(h,D)=>{let I=q(h,D),O=Object.getOwnPropertyDescriptor(r,h);if(O&&(!("value"in O)||O.writable!==!0))return null;try{r[h]=I}catch{return null}return()=>{r[h]===I&&(O?r[h]=O.value:delete r[h])}},S=x("get",a),N=S?x("create",p):null;return!S||!N?(S==null||S(),t.log("webauthn capture unavailable: credentials methods cannot be patched safely"),C()):(y=!0,{mode:"standard",disconnect:()=>{y=!1,S(),N()}})}function xe(e,t,o){let n=Se(t.mediation);if(e==="create")return{kind:"registration",mediation:n};let r=o;return{kind:"authentication",mediation:n,uiMode:Ne(t.uiMode),credentialSet:Array.isArray(r.allowCredentials)&&r.allowCredentials.length>0?"allowlisted":"discoverable"}}function Se(e){return e===void 0?"optional":e==="silent"||e==="optional"||e==="conditional"||e==="required"?e:"unknown"}function Ne(e){return e===void 0?"default":e==="immediate"?"immediate":"unknown"}function Be(e){let t=e.userActivation;return typeof(t==null?void 0:t.isActive)=="boolean"?t.isActive:void 0}function De(e,t,o){var n;if(e)try{let r=e,a=r.response,p={id:J(r.id),rawId:K(r.rawId),type:J(r.type),authenticatorAttachment:J(r.authenticatorAttachment),response:t==="create"?{clientDataJSON:K(a==null?void 0:a.clientDataJSON),attestationObject:K(a==null?void 0:a.attestationObject),transports:re((n=a==null?void 0:a.getTransports)==null?void 0:n.call(a))}:{clientDataJSON:K(a==null?void 0:a.clientDataJSON),authenticatorData:K(a==null?void 0:a.authenticatorData),signature:K(a==null?void 0:a.signature),userHandle:K(a==null?void 0:a.userHandle)},...t==="create"?He(r):{}};return JSON.stringify(p)}catch(r){o.log("credential serialization failed",r);return}}function Le(e,t){try{let o={},n=J(e.rpId),r=J(e.userVerification),a=re(e.hints);return n!==void 0&&(o.rpId=n),typeof e.timeout=="number"&&Number.isFinite(e.timeout)&&(o.timeout=e.timeout),r!==void 0&&(o.userVerification=r),a!==void 0&&(o.hints=a),o.challenge=K(e.challenge),Array.isArray(e.allowCredentials)&&(o.allowCredentials=je(e.allowCredentials)),JSON.stringify(o)}catch(o){t.log("request options serialization failed",o);return}}function je(e){let t=[];for(let o of e){if(!Q(o))continue;let n=o;t.push({type:J(n.type),id:K(n.id),transports:re(n.transports)})}return t}function re(e){if(Array.isArray(e))return e.filter(t=>typeof t=="string")}function J(e){return typeof e=="string"?e:void 0}function He(e){var n;let t=(n=e.getClientExtensionResults)==null?void 0:n.call(e);if(!Q(t))return{};let o=t.credProps;return!o||typeof o.rk!="boolean"?{}:{clientExtensionResults:{credProps:{rk:o.rk}}}}function K(e){let t;if(e instanceof ArrayBuffer)t=new Uint8Array(e);else if(ArrayBuffer.isView(e))t=new Uint8Array(e.buffer,e.byteOffset,e.byteLength);else return;let o="";for(let n of t)o+=String.fromCharCode(n);return btoa(o).replace(/\+/g,"-").replace(/\//g,"_").replace(/=+$/g,"")}function Q(e){return e!==null&&(typeof e=="object"||typeof e=="function")}function Te(e){return e instanceof DOMException?e.name:"UnknownError"}var ce=0;function de(){return ce+=1,`network-${ce}`}function Ie(e,t){let o=e.responseType;if(o===""||o==="text")return t(e.responseText);if(o==="json"){let n=e.response;return n==null?void 0:t(n)}}var Me=500,le=Symbol("body-read-timeout");function pe(e){return/event-stream|octet-stream/i.test(e)?!1:/json|text|urlencoded/i.test(e)}async function fe(e,t){let o=e.body;if(!o)return;let n=o.getReader(),r;try{let a=new Promise(k=>{r=setTimeout(()=>k(le),Me)}),p=new TextDecoder,y=[];for(;;){let k=await Promise.race([n.read(),a]);if(k===le){t.log("body omitted: read timed out"),n.cancel().catch(()=>{});return}if(k.done)break;y.push(p.decode(k.value,{stream:!0}))}return y.push(p.decode()),y.join("")}catch{n.cancel().catch(()=>{});return}finally{r!==void 0&&clearTimeout(r)}}function oe(e){var t;(t=e==null?void 0:e.body)==null||t.cancel().catch(()=>{})}function ie(e,t,o,n,r){try{let a=Object.getOwnPropertyDescriptor(e,t);Ue(a,{...n,value:o})&&Object.defineProperty(e,t,n)}catch(a){r.log(`${String(t)} restoration skipped`,a)}}function Ue(e,t){return!!e&&"value"in e&&"value"in t&&e.value===t.value&&e.writable===t.writable&&e.enumerable===t.enumerable&&e.configurable===t.configurable}function he(e){var v,g,z;let{onExchange:t,onRequest:o,match:n}=e;if(typeof t!="function"||typeof n!="function")throw new TypeError("captureNetwork requires onExchange and match callbacks");let r=U(e.logger),a=(v=e.transports)!=null?v:["xhr","fetch"],p=(g=e.bodyCapture)==null?void 0:g.request,y=(z=e.bodyCapture)==null?void 0:z.response,k=typeof p=="function",B=typeof y=="function",q=!1,x=$(r,"network",u=>{if(q)return t(u)}),S=$(r,"network request",u=>{if(q)return o==null?void 0:o(u)}),N=(u,m,l)=>{if(typeof l=="function")try{return l(u,m)}catch(f){r.log("body projection failed",f);return}},h=(u,m)=>{try{let l=typeof document!="undefined"?document.baseURI:void 0,f=new URL(String(u),l);return n(f,m)===!0?{url:f.href,path:f.pathname}:void 0}catch{return}},D=()=>{if(typeof XMLHttpRequest=="undefined")return r.log("xhr capture unavailable: XMLHttpRequest missing"),null;let u=XMLHttpRequest.prototype,m=Object.getOwnPropertyDescriptor(u,"open"),l=Object.getOwnPropertyDescriptor(u,"send");if(!m||!("value"in m)||typeof m.value!="function"||!l||!("value"in l)||typeof l.value!="function")return r.log("xhr capture unavailable: XMLHttpRequest methods missing"),null;let f=m.value,W=l.value;if(_(f)||_(W))return r.log("xhr capture unavailable: an equivalent capture is already active"),null;let w=new WeakMap,R=new Set,P=!1,L={open(...b){var c;let i=Reflect.apply(f,this,b);if(!q||!P)return i;try{let E=w.get(this);E&&(E.reported=!0,(c=E.cleanupListeners)==null||c.call(E));let j=String(b[0]).toUpperCase(),A=h(b[1],j);A?w.set(this,{method:j,url:A.url,path:A.path,reported:!1}):w.delete(this)}catch(E){r.log("xhr open observation failed",E)}return i}}.open,F={send(...b){let i=q&&P?w.get(this):void 0;if(!i||i.reported||i.cleanupListeners)return Reflect.apply(W,this,b);let c=()=>{},E=!1;try{i.requestId=de();let A={direction:"request",transport:"xhr",method:i.method,url:i.url,path:i.path};i.requestBody=k&&typeof b[0]=="string"?N(b[0],A,p):void 0;let G=()=>{i.outcome===void 0&&(i.outcome="abort")},Y=()=>{i.outcome===void 0&&(i.outcome="timeout")},s=()=>{i.outcome===void 0&&(i.outcome="error")},d=()=>{var V;c();try{if(!q||!P||i.reported||!i.requestId)return;i.reported=!0;let T={direction:"response",transport:"xhr",method:i.method,url:i.url,path:i.path},te=this.status,ae={requestId:i.requestId,transport:"xhr",method:i.method,url:i.url,path:i.path,status:te,ok:te>=200&&te<300,outcome:(V=i.outcome)!=null?V:"load",durationMs:i.startedAt!==void 0?Date.now()-i.startedAt:void 0,responseUrl:this.responseURL||void 0,requestBody:i.requestBody,responseBody:B?Ie(this,Re=>N(Re,T,y)):void 0};i.requestEmitted?x(ae):i.pendingExchange=ae}catch(T){r.log("xhr exchange observation failed",T)}finally{w.get(this)===i&&w.delete(this)}},H=()=>{try{this.readyState===XMLHttpRequest.DONE&&this.status!==0&&d()}catch(V){r.log("xhr ready-state observation failed",V)}},M=()=>d();c=()=>{for(let[V,T]of[["readystatechange",H],["abort",G],["timeout",Y],["error",s],["loadend",M]])this.removeEventListener(V,T);i.cleanupListeners===c&&(i.cleanupListeners=void 0),R.delete(c)},this.addEventListener("readystatechange",H),this.addEventListener("abort",G),this.addEventListener("timeout",Y),this.addEventListener("error",s),this.addEventListener("loadend",M),i.cleanupListeners=c,R.add(c),i.startedAt=Date.now(),E=!0}catch(A){r.log("xhr send observation failed",A),c()}let j;try{j=Reflect.apply(W,this,b)}catch(A){throw c(),A}if(E&&i.requestId!==void 0&&i.startedAt!==void 0){i.requestEmitted=!0,S({requestId:i.requestId,transport:"xhr",method:i.method,url:i.url,path:i.path,startedAt:i.startedAt,requestBody:i.requestBody});let A=i.pendingExchange;i.pendingExchange=void 0,A&&x(A)}return j}}.send;return X(L,f),X(F,W),m.writable!==!0||l.writable!==!0?(r.log("xhr capture unavailable: XMLHttpRequest methods are not writable"),null):(Object.defineProperty(u,"open",{...m,value:L}),Object.defineProperty(u,"send",{...l,value:F}),P=!0,()=>{P=!1;for(let b of[...R])b();ie(u,"open",L,m,r),ie(u,"send",F,l,r)})},I=()=>{let u=globalThis,m=Object.getOwnPropertyDescriptor(u,"fetch");if(!m||!("value"in m))return r.log("fetch capture unavailable: fetch is not an own data property"),null;let l=m.value;if(typeof l!="function")return r.log("fetch capture unavailable: fetch missing"),null;if(_(l))return r.log("fetch capture unavailable: an equivalent capture is already active"),null;let f=!1,W=async(R,P,L,F)=>{try{if(!q||!f){oe(L);return}let[b,i]=await Promise.all([F!=null?F:Promise.resolve(void 0),L?fe(L,r):Promise.resolve(void 0)]);if(!q||!f)return;let c={direction:"request",transport:"fetch",method:R.method,url:R.url,path:R.path},E={...c,direction:"response"},j=R.requestBody;j===void 0&&b!==void 0&&(j=N(b,c,p));let A=i!==void 0?N(i,E,y):void 0;x({requestId:R.requestId,transport:"fetch",method:R.method,url:R.url,path:R.path,status:P.status,ok:P.ok,outcome:"load",durationMs:Date.now()-R.startedAt,responseUrl:P.url||void 0,requestBody:j,responseBody:A})}catch(b){r.log("fetch exchange observation failed",b)}},w={fetch(...R){var j,A,G,Y;let P;try{let s=R[0],d=R[1];if(q&&f&&k&&typeof Request!="undefined"&&s instanceof Request&&(d==null?void 0:d.body)===void 0&&s.body){let H=String((j=d==null?void 0:d.method)!=null?j:s.method).toUpperCase(),M=(A=s.headers.get("content-type"))!=null?A:"";h(s.url,H)&&pe(M)&&(P=s.clone())}}catch(s){r.log("fetch observation failed",s)}let L,F=Date.now();try{L=Reflect.apply(l,this,R)}catch(s){throw oe(P),s}let b,i;try{if(q&&f){let s=R[0],d=R[1],H=typeof Request!="undefined"&&s instanceof Request,M=String((G=d==null?void 0:d.method)!=null?G:H?s.method:"GET").toUpperCase(),V=H?s.url:s,T=h(V,M);T&&(b={requestId:de(),method:M,url:T.url,path:T.path,startedAt:F},i=(Y=d==null?void 0:d.signal)!=null?Y:H?s.signal:void 0,k&&typeof(d==null?void 0:d.body)=="string"&&(b.requestBody=N(d.body,{direction:"request",transport:"fetch",method:M,url:T.url,path:T.path},p)))}}catch(s){r.log("fetch observation failed",s)}if(!b)return oe(P),L;let c=b;S({requestId:c.requestId,transport:"fetch",method:c.method,url:c.url,path:c.path,startedAt:c.startedAt,requestBody:c.requestBody});let E=P?fe(P,r):void 0;return L.then(s=>{var H;let d;try{if(q&&f&&B){let M=(H=s.headers.get("content-type"))!=null?H:"";pe(M)&&s.body&&(d=s.clone())}}catch{}W(c,s,d,E)},s=>{try{if(!q||!f)return;let d=(i==null?void 0:i.aborted)===!0||(s==null?void 0:s.name)==="AbortError"||typeof DOMException!="undefined"&&s instanceof DOMException&&s.code===DOMException.ABORT_ERR;x({requestId:c.requestId,transport:"fetch",method:c.method,url:c.url,path:c.path,status:0,ok:!1,outcome:d?"abort":"error",durationMs:Date.now()-c.startedAt})}catch(d){r.log("fetch failure observation failed",d)}}),L}}.fetch;return X(w,l),m.writable!==!0?(r.log("fetch capture unavailable: fetch is not writable"),null):(Object.defineProperty(u,"fetch",{...m,value:w}),f=!0,()=>{f=!1,ie(u,"fetch",w,m,r)})},O=[];if(a.includes("xhr")){let u=D();u&&O.push(u)}if(a.includes("fetch")){let u=I();u&&O.push(u)}return O.length===0?C():(q=!0,{mode:"standard",disconnect:()=>{q=!1;for(let u of O.splice(0))u()}})}function me(e){let t=U(),o;try{if(t=U(e.logger),o=e.onNavigate,typeof o!="function")return C()}catch{return C()}let n,r,a,p,y,k;try{if(n=window,r=n==null?void 0:n.history,!n||!r)return t.log("navigation capture unavailable: window/history missing"),C();if(y=ye(r,"pushState"),k=ye(r,"replaceState"),!y||!k)return t.log("navigation capture unavailable: history method descriptors missing"),C();if(a=y.descriptor.value,p=k.descriptor.value,typeof a!="function"||typeof p!="function")return t.log("navigation capture unavailable: history methods missing"),C();if(typeof n.addEventListener!="function"||typeof n.removeEventListener!="function")return t.log("navigation capture unavailable: window event methods missing"),C()}catch(v){return t.log("navigation capture unavailable: history inspection failed",v),C()}if(_(a)||_(p))return t.log("navigation capture unavailable: an equivalent capture is already active"),C();let B=!1,q=()=>({path:n.location.pathname,search:n.location.search,hash:n.location.hash}),x;try{x=q()}catch(v){return t.log("navigation capture unavailable: location inspection failed",v),C()}let S=$(t,"navigation",v=>{if(B)return o(v)}),N=v=>{if(B)try{let g=q();if(g.path===x.path&&g.search===x.search&&g.hash===x.hash)return;x=g,S({...g,source:v})}catch(g){t.log("navigation observation failed",g)}},h={pushState(...v){let g=Reflect.apply(a,this,v);return N("push"),g}}.pushState,D={replaceState(...v){let g=Reflect.apply(p,this,v);return N("replace"),g}}.replaceState;X(h,a),X(D,p);let I=()=>N("pop"),O=()=>N("hash");try{if(ge(y,h),ge(k,D),r.pushState!==h||r.replaceState!==D)throw new Error("history method replacement did not take effect");n.addEventListener("popstate",I),n.addEventListener("hashchange",O),B=!0}catch(v){return B=!1,ee(n,"popstate",I,t),ee(n,"hashchange",O,t),Z(k,D,t),Z(y,h,t),t.log("navigation capture unavailable: history methods are not writable",v),o=()=>{},S=()=>{},t=U(),C()}return{mode:"standard",disconnect:()=>{B=!1,o=()=>{},ee(n,"popstate",I,t),ee(n,"hashchange",O,t),Z(y,h,t),Z(k,D,t),S=()=>{},t=U()}}}function ye(e,t){let o=e;for(;o;){let n=Object.getOwnPropertyDescriptor(o,t);if(n)return!("value"in n)||typeof n.value!="function"?null:{owner:o,key:t,descriptor:n};o=Object.getPrototypeOf(o)}return null}function ge(e,t){if(e.descriptor.writable!==!0)throw new TypeError(`${e.key} is not writable`);let o=Object.getOwnPropertyDescriptor(e.owner,e.key);if(!be(o,e.descriptor))throw new Error(`${e.key} changed during installation`);Object.defineProperty(e.owner,e.key,{...e.descriptor,value:t})}function be(e,t){return!!e&&"value"in e&&"value"in t&&e.value===t.value&&e.writable===t.writable&&e.enumerable===t.enumerable&&e.configurable===t.configurable}function Z(e,t,o){try{let n=Object.getOwnPropertyDescriptor(e.owner,e.key);be(n,{...e.descriptor,value:t})&&Object.defineProperty(e.owner,e.key,e.descriptor)}catch(n){o.log(`navigation ${e.key} restoration skipped`,n)}}function ee(e,t,o,n){try{e.removeEventListener(t,o)}catch(r){n.log(`navigation ${t} listener removal skipped`,r)}}function ve(e){let t=e.composedPath();return t.length>0?t:e.target?[e.target]:[]}var we="0.1.0-next.5-1f3cd4a";0&&(module.exports={VERSION,captureNavigation,captureNetwork,captureWebAuthn,composedPath});
|
package/dist/index.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
var ne={log:()=>{}};function j(e){return e?{log:(...t)=>{try{let r=e.log(...t);if(r&&(typeof r=="object"||typeof r=="function"))try{Promise.resolve(r).catch(()=>{})}catch{}}catch{}}}:ne}var se=Symbol.for("corbado.autocapture.installed");function M(e){try{return typeof e=="function"&&Object.prototype.hasOwnProperty.call(e,se)}catch{return!1}}function _(e,t){var n,o;let r=t;try{Object.defineProperty(e,se,{value:t,configurable:!0})}catch{}try{Object.defineProperty(e,"name",{value:(n=r.name)!=null?n:"",configurable:!0})}catch{}try{Object.defineProperty(e,"length",{value:(o=r.length)!=null?o:0,configurable:!0})}catch{}return e}function b(){return{mode:"unavailable",disconnect:()=>{}}}function W(e,t,r){let n=j(e);return o=>{try{let a=r(o);if(a&&(typeof a=="object"||typeof a=="function"))try{Promise.resolve(a).catch(c=>n.log(`${t} listener failed`,c))}catch(c){n.log(`${t} listener failed`,c)}}catch(a){n.log(`${t} listener failed`,a)}}}function be(e){let t=j(e.logger),r=e.onEvent;if(typeof r!="function")return b();let n=typeof navigator=="undefined"?void 0:navigator,o=n==null?void 0:n.credentials;if(!n||!o)return t.log("webauthn capture unavailable: navigator.credentials missing"),b();let a=o.get,c=o.create;if(typeof a!="function"||typeof c!="function")return t.log("webauthn capture unavailable: credentials methods missing"),b();if(M(a)||M(c))return t.log("webauthn capture unavailable: an equivalent capture is already active"),b();let d=!1,g=0,P=W(t,"webauthn",u=>{if(d)return r(u)}),m=(u,w)=>{let N={invoke(...x){let k=this,R=x[0];if(!d||!Q(R)||!Q(R.publicKey))return Reflect.apply(w,k,x);let z=R.publicKey,p=`wa-${++g}`,C=Reflect.apply(w,k,x),v=Q(R.signal)?R.signal:void 0,f=we(u,R,z),X={...f,ceremonyId:p,phase:"started",userActivation:Se(n)};if(f.kind==="authentication"){let A=z;X.requestOptionsJson=Ee(A,t)}return P(X),Promise.resolve(C).then(A=>(d&&P({...f,ceremonyId:p,phase:"completed",credentialJson:Oe(A,u,t),...(v==null?void 0:v.aborted)===!0?{aborted:!0}:{}}),A),A=>{throw d&&P({...f,ceremonyId:p,phase:"failed",error:A,errorName:qe(A),...(v==null?void 0:v.aborted)===!0?{aborted:!0}:{}}),A})}}.invoke;return _(N,{name:u,length:0})},O=(u,w)=>{let N=m(u,w),x=Object.getOwnPropertyDescriptor(o,u);if(x&&(!("value"in x)||x.writable!==!0))return null;try{o[u]=N}catch{return null}return()=>{o[u]===N&&(x?o[u]=x.value:delete o[u])}},E=O("get",a),s=E?O("create",c):null;return!E||!s?(E==null||E(),t.log("webauthn capture unavailable: credentials methods cannot be patched safely"),b()):(d=!0,{mode:"standard",disconnect:()=>{d=!1,E(),s()}})}function we(e,t,r){let n=Re(t.mediation);if(e==="create")return{kind:"registration",mediation:n};let o=r;return{kind:"authentication",mediation:n,uiMode:Ce(t.uiMode),credentialSet:Array.isArray(o.allowCredentials)&&o.allowCredentials.length>0?"allowlisted":"discoverable"}}function Re(e){return e===void 0?"optional":e==="silent"||e==="optional"||e==="conditional"||e==="required"?e:"unknown"}function Ce(e){return e===void 0?"default":e==="immediate"?"immediate":"unknown"}function Se(e){let t=e.userActivation;return typeof(t==null?void 0:t.isActive)=="boolean"?t.isActive:void 0}function Oe(e,t,r){var n;if(e)try{let o=e,a=o.response,c={id:J(o.id),rawId:$(o.rawId),type:J(o.type),authenticatorAttachment:J(o.authenticatorAttachment),response:t==="create"?{clientDataJSON:$(a==null?void 0:a.clientDataJSON),attestationObject:$(a==null?void 0:a.attestationObject),transports:re((n=a==null?void 0:a.getTransports)==null?void 0:n.call(a))}:{clientDataJSON:$(a==null?void 0:a.clientDataJSON),authenticatorData:$(a==null?void 0:a.authenticatorData),signature:$(a==null?void 0:a.signature),userHandle:$(a==null?void 0:a.userHandle)},...t==="create"?Ae(o):{}};return JSON.stringify(c)}catch(o){r.log("credential serialization failed",o);return}}function Ee(e,t){try{let r={},n=J(e.rpId),o=J(e.userVerification),a=re(e.hints);return n!==void 0&&(r.rpId=n),typeof e.timeout=="number"&&Number.isFinite(e.timeout)&&(r.timeout=e.timeout),o!==void 0&&(r.userVerification=o),a!==void 0&&(r.hints=a),r.challenge=$(e.challenge),Array.isArray(e.allowCredentials)&&(r.allowCredentials=ke(e.allowCredentials)),JSON.stringify(r)}catch(r){t.log("request options serialization failed",r);return}}function ke(e){let t=[];for(let r of e){if(!Q(r))continue;let n=r;t.push({type:J(n.type),id:$(n.id),transports:re(n.transports)})}return t}function re(e){if(Array.isArray(e))return e.filter(t=>typeof t=="string")}function J(e){return typeof e=="string"?e:void 0}function Ae(e){var n;let t=(n=e.getClientExtensionResults)==null?void 0:n.call(e);if(!Q(t))return{};let r=t.credProps;return!r||typeof r.rk!="boolean"?{}:{clientExtensionResults:{credProps:{rk:r.rk}}}}function $(e){let t;if(e instanceof ArrayBuffer)t=new Uint8Array(e);else if(ArrayBuffer.isView(e))t=new Uint8Array(e.buffer,e.byteOffset,e.byteLength);else return;let r="";for(let n of t)r+=String.fromCharCode(n);return btoa(r).replace(/\+/g,"-").replace(/\//g,"_").replace(/=+$/g,"")}function Q(e){return e!==null&&(typeof e=="object"||typeof e=="function")}function qe(e){return e instanceof DOMException?e.name:"UnknownError"}var ue=0;function ce(){return ue+=1,`network-${ue}`}function Pe(e,t){let r=e.responseType;if(r===""||r==="text")return t(e.responseText);if(r==="json"){let n=e.response;return n==null?void 0:t(n)}}var xe=500,de=Symbol("body-read-timeout");function le(e){return/event-stream|octet-stream/i.test(e)?!1:/json|text|urlencoded/i.test(e)}async function pe(e,t){let r=e.body;if(!r)return;let n=r.getReader(),o;try{let a=new Promise(g=>{o=setTimeout(()=>g(de),xe)}),c=new TextDecoder,d=[];for(;;){let g=await Promise.race([n.read(),a]);if(g===de){t.log("body omitted: read timed out"),n.cancel().catch(()=>{});return}if(g.done)break;d.push(c.decode(g.value,{stream:!0}))}return d.push(c.decode()),d.join("")}catch{n.cancel().catch(()=>{});return}finally{o!==void 0&&clearTimeout(o)}}function oe(e){var t;(t=e==null?void 0:e.body)==null||t.cancel().catch(()=>{})}function ae(e,t,r,n,o){try{let a=Object.getOwnPropertyDescriptor(e,t);De(a,{...n,value:r})&&Object.defineProperty(e,t,n)}catch(a){o.log(`${String(t)} restoration skipped`,a)}}function De(e,t){return!!e&&"value"in e&&"value"in t&&e.value===t.value&&e.writable===t.writable&&e.enumerable===t.enumerable&&e.configurable===t.configurable}function Le(e){var k,R,z;let{onExchange:t,onRequest:r,match:n}=e;if(typeof t!="function"||typeof n!="function")throw new TypeError("captureNetwork requires onExchange and match callbacks");let o=j(e.logger),a=(k=e.transports)!=null?k:["xhr","fetch"],c=(R=e.bodyCapture)==null?void 0:R.request,d=(z=e.bodyCapture)==null?void 0:z.response,g=typeof c=="function",P=typeof d=="function",m=!1,O=W(o,"network",p=>{if(m)return t(p)}),E=W(o,"network request",p=>{if(m)return r==null?void 0:r(p)}),s=(p,C,v)=>{if(typeof v=="function")try{let f=v(p,C);return f===void 0||typeof(f==null?void 0:f.then)=="function"?void 0:f}catch(f){o.log("body projection failed",f);return}},u=(p,C)=>{try{let v=typeof document!="undefined"?document.baseURI:void 0,f=new URL(String(p),v);return/\/observe\/events\/[^/]+\/?$/.test(f.pathname)?void 0:n(f,C)===!0?{url:f.href,path:f.pathname}:void 0}catch{return}},w=()=>{if(typeof XMLHttpRequest=="undefined")return o.log("xhr capture unavailable: XMLHttpRequest missing"),null;let p=XMLHttpRequest.prototype,C=Object.getOwnPropertyDescriptor(p,"open"),v=Object.getOwnPropertyDescriptor(p,"send");if(!C||!("value"in C)||typeof C.value!="function"||!v||!("value"in v)||typeof v.value!="function")return o.log("xhr capture unavailable: XMLHttpRequest methods missing"),null;let f=C.value,X=v.value;if(M(f)||M(X))return o.log("xhr capture unavailable: an equivalent capture is already active"),null;let A=new WeakMap,q=new Set,L=!1,T={open(...S){var h;let i=Reflect.apply(f,this,S);if(!m||!L)return i;try{let B=A.get(this);B&&(B.reported=!0,(h=B.cleanupListeners)==null||h.call(B));let H=String(S[0]).toUpperCase(),D=u(S[1],H);D?A.set(this,{method:H,url:D.url,path:D.path,reported:!1}):A.delete(this)}catch(B){o.log("xhr open observation failed",B)}return i}}.open,K={send(...S){let i=m&&L?A.get(this):void 0;if(!i||i.reported||i.cleanupListeners)return Reflect.apply(X,this,S);let h=()=>{},B=!1;try{i.requestId=ce();let D={direction:"request",transport:"xhr",method:i.method,url:i.url,path:i.path};i.requestBody=g&&typeof S[0]=="string"?s(S[0],D,c):void 0;let G=()=>{i.outcome===void 0&&(i.outcome="abort")},Y=()=>{i.outcome===void 0&&(i.outcome="timeout")},l=()=>{i.outcome===void 0&&(i.outcome="error")},y=()=>{var V;h();try{if(!m||!L||i.reported||!i.requestId)return;i.reported=!0;let U={direction:"response",transport:"xhr",method:i.method,url:i.url,path:i.path},te=this.status,ie={requestId:i.requestId,transport:"xhr",method:i.method,url:i.url,path:i.path,status:te,ok:te>=200&&te<300,outcome:(V=i.outcome)!=null?V:"load",durationMs:i.startedAt!==void 0?Date.now()-i.startedAt:void 0,responseUrl:this.responseURL||void 0,requestBody:i.requestBody,responseBody:P?Pe(this,ve=>s(ve,U,d)):void 0};i.requestEmitted?O(ie):i.pendingExchange=ie}catch(U){o.log("xhr exchange observation failed",U)}finally{A.get(this)===i&&A.delete(this)}},I=()=>{try{this.readyState===XMLHttpRequest.DONE&&this.status!==0&&y()}catch(V){o.log("xhr ready-state observation failed",V)}},F=()=>y();h=()=>{for(let[V,U]of[["readystatechange",I],["abort",G],["timeout",Y],["error",l],["loadend",F]])this.removeEventListener(V,U);i.cleanupListeners===h&&(i.cleanupListeners=void 0),q.delete(h)},this.addEventListener("readystatechange",I),this.addEventListener("abort",G),this.addEventListener("timeout",Y),this.addEventListener("error",l),this.addEventListener("loadend",F),i.cleanupListeners=h,q.add(h),i.startedAt=Date.now(),B=!0}catch(D){o.log("xhr send observation failed",D),h()}let H;try{H=Reflect.apply(X,this,S)}catch(D){throw h(),D}if(B&&i.requestId!==void 0&&i.startedAt!==void 0){i.requestEmitted=!0,E({requestId:i.requestId,transport:"xhr",method:i.method,url:i.url,path:i.path,startedAt:i.startedAt,requestBody:i.requestBody});let D=i.pendingExchange;i.pendingExchange=void 0,D&&O(D)}return H}}.send;return _(T,f),_(K,X),C.writable!==!0||v.writable!==!0?(o.log("xhr capture unavailable: XMLHttpRequest methods are not writable"),null):(Object.defineProperty(p,"open",{...C,value:T}),Object.defineProperty(p,"send",{...v,value:K}),L=!0,()=>{L=!1;for(let S of[...q])S();ae(p,"open",T,C,o),ae(p,"send",K,v,o)})},N=()=>{let p=globalThis,C=Object.getOwnPropertyDescriptor(p,"fetch");if(!C||!("value"in C))return o.log("fetch capture unavailable: fetch is not an own data property"),null;let v=C.value;if(typeof v!="function")return o.log("fetch capture unavailable: fetch missing"),null;if(M(v))return o.log("fetch capture unavailable: an equivalent capture is already active"),null;let f=!1,X=async(q,L,T,K)=>{try{if(!m||!f){oe(T);return}let[S,i]=await Promise.all([K!=null?K:Promise.resolve(void 0),T?pe(T,o):Promise.resolve(void 0)]);if(!m||!f)return;let h={direction:"request",transport:"fetch",method:q.method,url:q.url,path:q.path},B={...h,direction:"response"},H=q.requestBody;H===void 0&&S!==void 0&&(H=s(S,h,c));let D=i!==void 0?s(i,B,d):void 0;O({requestId:q.requestId,transport:"fetch",method:q.method,url:q.url,path:q.path,status:L.status,ok:L.ok,outcome:"load",durationMs:Date.now()-q.startedAt,responseUrl:L.url||void 0,requestBody:H,responseBody:D})}catch(S){o.log("fetch exchange observation failed",S)}},A={fetch(...q){var H,D,G,Y;let L;try{let l=q[0],y=q[1];if(m&&f&&g&&typeof Request!="undefined"&&l instanceof Request&&(y==null?void 0:y.body)===void 0&&l.body){let I=String((H=y==null?void 0:y.method)!=null?H:l.method).toUpperCase(),F=(D=l.headers.get("content-type"))!=null?D:"";u(l.url,I)&&le(F)&&(L=l.clone())}}catch(l){o.log("fetch observation failed",l)}let T,K=Date.now();try{T=Reflect.apply(v,this,q)}catch(l){throw oe(L),l}let S,i;try{if(m&&f){let l=q[0],y=q[1],I=typeof Request!="undefined"&&l instanceof Request,F=String((G=y==null?void 0:y.method)!=null?G:I?l.method:"GET").toUpperCase(),V=I?l.url:l,U=u(V,F);U&&(S={requestId:ce(),method:F,url:U.url,path:U.path,startedAt:K},i=(Y=y==null?void 0:y.signal)!=null?Y:I?l.signal:void 0,g&&typeof(y==null?void 0:y.body)=="string"&&(S.requestBody=s(y.body,{direction:"request",transport:"fetch",method:F,url:U.url,path:U.path},c)))}}catch(l){o.log("fetch observation failed",l)}if(!S)return oe(L),T;let h=S;E({requestId:h.requestId,transport:"fetch",method:h.method,url:h.url,path:h.path,startedAt:h.startedAt,requestBody:h.requestBody});let B=L?pe(L,o):void 0;return T.then(l=>{var I;let y;try{if(m&&f&&P){let F=(I=l.headers.get("content-type"))!=null?I:"";le(F)&&l.body&&(y=l.clone())}}catch{}X(h,l,y,B)},l=>{try{if(!m||!f)return;let y=(i==null?void 0:i.aborted)===!0||(l==null?void 0:l.name)==="AbortError"||typeof DOMException!="undefined"&&l instanceof DOMException&&l.code===DOMException.ABORT_ERR;O({requestId:h.requestId,transport:"fetch",method:h.method,url:h.url,path:h.path,status:0,ok:!1,outcome:y?"abort":"error",durationMs:Date.now()-h.startedAt})}catch(y){o.log("fetch failure observation failed",y)}}),T}}.fetch;return _(A,v),C.writable!==!0?(o.log("fetch capture unavailable: fetch is not writable"),null):(Object.defineProperty(p,"fetch",{...C,value:A}),f=!0,()=>{f=!1,ae(p,"fetch",A,C,o)})},x=[];if(a.includes("xhr")){let p=w();p&&x.push(p)}if(a.includes("fetch")){let p=N();p&&x.push(p)}return x.length===0?b():(m=!0,{mode:"standard",disconnect:()=>{m=!1;for(let p of x.splice(0))p()}})}function Ne(e){let t=j(),r;try{if(t=j(e.logger),r=e.onNavigate,typeof r!="function")return b()}catch{return b()}let n,o,a,c,d,g;try{if(n=window,o=n==null?void 0:n.history,!n||!o)return t.log("navigation capture unavailable: window/history missing"),b();if(d=fe(o,"pushState"),g=fe(o,"replaceState"),!d||!g)return t.log("navigation capture unavailable: history method descriptors missing"),b();if(a=d.descriptor.value,c=g.descriptor.value,typeof a!="function"||typeof c!="function")return t.log("navigation capture unavailable: history methods missing"),b();if(typeof n.addEventListener!="function"||typeof n.removeEventListener!="function")return t.log("navigation capture unavailable: window event methods missing"),b()}catch(k){return t.log("navigation capture unavailable: history inspection failed",k),b()}if(M(a)||M(c))return t.log("navigation capture unavailable: an equivalent capture is already active"),b();let P=!1,m=()=>({path:n.location.pathname,search:n.location.search,hash:n.location.hash}),O;try{O=m()}catch(k){return t.log("navigation capture unavailable: location inspection failed",k),b()}let E=W(t,"navigation",k=>{if(P)return r(k)}),s=k=>{if(P)try{let R=m();if(R.path===O.path&&R.search===O.search&&R.hash===O.hash)return;O=R,E({...R,source:k})}catch(R){t.log("navigation observation failed",R)}},u={pushState(...k){let R=Reflect.apply(a,this,k);return s("push"),R}}.pushState,w={replaceState(...k){let R=Reflect.apply(c,this,k);return s("replace"),R}}.replaceState;_(u,a),_(w,c);let N=()=>s("pop"),x=()=>s("hash");try{if(he(d,u),he(g,w),o.pushState!==u||o.replaceState!==w)throw new Error("history method replacement did not take effect");n.addEventListener("popstate",N),n.addEventListener("hashchange",x),P=!0}catch(k){return P=!1,ee(n,"popstate",N,t),ee(n,"hashchange",x,t),Z(g,w,t),Z(d,u,t),t.log("navigation capture unavailable: history methods are not writable",k),r=()=>{},E=()=>{},t=j(),b()}return{mode:"standard",disconnect:()=>{P=!1,r=()=>{},ee(n,"popstate",N,t),ee(n,"hashchange",x,t),Z(d,u,t),Z(g,w,t),E=()=>{},t=j()}}}function fe(e,t){let r=e;for(;r;){let n=Object.getOwnPropertyDescriptor(r,t);if(n)return!("value"in n)||typeof n.value!="function"?null:{owner:r,key:t,descriptor:n};r=Object.getPrototypeOf(r)}return null}function he(e,t){if(e.descriptor.writable!==!0)throw new TypeError(`${e.key} is not writable`);let r=Object.getOwnPropertyDescriptor(e.owner,e.key);if(!ye(r,e.descriptor))throw new Error(`${e.key} changed during installation`);Object.defineProperty(e.owner,e.key,{...e.descriptor,value:t})}function ye(e,t){return!!e&&"value"in e&&"value"in t&&e.value===t.value&&e.writable===t.writable&&e.enumerable===t.enumerable&&e.configurable===t.configurable}function Z(e,t,r){try{let n=Object.getOwnPropertyDescriptor(e.owner,e.key);ye(n,{...e.descriptor,value:t})&&Object.defineProperty(e.owner,e.key,e.descriptor)}catch(n){r.log(`navigation ${e.key} restoration skipped`,n)}}function ee(e,t,r,n){try{e.removeEventListener(t,r)}catch(o){n.log(`navigation ${t} listener removal skipped`,o)}}function Be(e){var E;let t=(E=e.logger)!=null?E:ne,r=e.onAttached;if(typeof r!="function")return b();let n=Element.prototype,o=Object.getOwnPropertyDescriptor(n,"attachShadow");if(!o||typeof o.value!="function")return t.log("shadow-root capture unavailable: attachShadow not supported"),b();let a=o.value;if(M(a))return t.log("shadow-root capture unavailable: an equivalent capture is already active"),b();let c=!1,d=new WeakSet,g=W(t,"shadow-root",r),P=(s,u)=>{!c||d.has(u)||(d.add(u),g({host:s,shadowRoot:u,mode:u.mode==="closed"?"closed":"open"}))},m={attachShadow(...s){let u=Reflect.apply(a,this,s);return P(this,u),u}}.attachShadow;_(m,a);try{Object.defineProperty(n,"attachShadow",{...o,value:m})}catch(s){return t.log("shadow-root capture unavailable: attachShadow is locked",s),b()}c=!0;let O=s=>{let u=s.querySelectorAll("*");for(let w=0;w<u.length&&c;w++){let N=u[w].shadowRoot;N&&(P(u[w],N),O(N))}};return e.includeExisting&&O(document),{mode:"standard",disconnect:()=>{c=!1;let s=Object.getOwnPropertyDescriptor(n,"attachShadow");He(s,{...o,value:m})&&Object.defineProperty(n,"attachShadow",o)}}}function Te(e){var t;return(t=ge(e)[0])!=null?t:null}function ge(e){let t=e.composedPath();return t.length>0?t:e.target?[e.target]:[]}function He(e,t){return!!e&&"value"in e&&"value"in t&&e.value===t.value&&e.writable===t.writable&&e.enumerable===t.enumerable&&e.configurable===t.configurable}function je(e){var m,O,E;let t=j(e==null?void 0:e.logger),r=e==null?void 0:e.read,n=e==null?void 0:e.onState;if(typeof r!="function"||typeof n!="function")return me();let o=Number.isFinite(e.delayMs)&&((m=e.delayMs)!=null?m:0)>=0&&(O=e.delayMs)!=null?O:0,a=W(t,"ui-state",n),c=!0,d,g=[],P=()=>{c&&(d!==void 0&&clearTimeout(d),d=setTimeout(()=>{if(d=void 0,!!c)try{let s=r();s!==void 0&&a(s)}catch(s){t.log("ui-state read failed",s)}},o))};try{for(let s of(E=e.triggers)!=null?E:[]){if(!(s!=null&&s.target)||typeof s.target.addEventListener!="function")continue;let u=P;s.target.addEventListener(s.type,u,s.capture===!0),g.push({trigger:s,listener:u})}}catch(s){t.log("ui-state trigger installation failed",s);for(let{trigger:u,listener:w}of g)try{u.target.removeEventListener(u.type,w,u.capture===!0)}catch{}return c=!1,me()}return{mode:"standard",schedule:P,disconnect:()=>{if(c){c=!1,d!==void 0&&clearTimeout(d),d=void 0;for(let{trigger:s,listener:u}of g)try{s.target.removeEventListener(s.type,u,s.capture===!0)}catch(w){t.log("ui-state trigger removal failed",w)}g.length=0}}}}function me(){return{mode:"unavailable",schedule:()=>{},disconnect:()=>{}}}function Me(e="[autocapture]"){return{log:(...t)=>{try{let r=console.log(e,...t);if(r&&(typeof r=="object"||typeof r=="function"))try{Promise.resolve(r).catch(()=>{})}catch{}}catch{}}}}var Ie="0.1.0-next.3-b8e8889";export{Ie as VERSION,Ne as captureNavigation,Le as captureNetwork,Be as captureShadowRoots,je as captureUiState,be as captureWebAuthn,ge as composedPath,Te as composedTarget,Me as createConsoleLogger};
|
|
1
|
+
var ge={log:()=>{}};function U(e){return e?{log:(...t)=>{try{let o=e.log(...t);if(o&&(typeof o=="object"||typeof o=="function"))try{Promise.resolve(o).catch(()=>{})}catch{}}catch{}}}:ge}var ae=Symbol.for("corbado.autocapture.installed");function _(e){try{return typeof e=="function"&&Object.prototype.hasOwnProperty.call(e,ae)}catch{return!1}}function X(e,t){var n,r;let o=t;try{Object.defineProperty(e,ae,{value:t,configurable:!0})}catch{}try{Object.defineProperty(e,"name",{value:(n=o.name)!=null?n:"",configurable:!0})}catch{}try{Object.defineProperty(e,"length",{value:(r=o.length)!=null?r:0,configurable:!0})}catch{}return e}function C(){return{mode:"unavailable",disconnect:()=>{}}}function $(e,t,o){let n=U(e);return r=>{try{let a=o(r);if(a&&(typeof a=="object"||typeof a=="function"))try{Promise.resolve(a).catch(p=>n.log(`${t} listener failed`,p))}catch(p){n.log(`${t} listener failed`,p)}}catch(a){n.log(`${t} listener failed`,a)}}}function me(e){let t=U(e.logger),o=e.onEvent;if(typeof o!="function")return C();let n=typeof navigator=="undefined"?void 0:navigator,r=n==null?void 0:n.credentials;if(!n||!r)return t.log("webauthn capture unavailable: navigator.credentials missing"),C();let a=r.get,p=r.create;if(typeof a!="function"||typeof p!="function")return t.log("webauthn capture unavailable: credentials methods missing"),C();if(_(a)||_(p))return t.log("webauthn capture unavailable: an equivalent capture is already active"),C();let y=!1,k=0,B=$(t,"webauthn",h=>{if(y)return o(h)}),q=(h,D)=>{let I={invoke(...O){let v=this,g=O[0];if(!y||!Q(g)||!Q(g.publicKey))return Reflect.apply(D,v,O);let z=g.publicKey,u=`wa-${++k}`,m=Reflect.apply(D,v,O),l=Q(g.signal)?g.signal:void 0,f=be(h,g,z),W={...f,ceremonyId:u,phase:"started",userActivation:Re(n)};if(f.kind==="authentication"){let w=z;W.requestOptionsJson=ke(w,t)}return B(W),Promise.resolve(m).then(w=>(y&&B({...f,ceremonyId:u,phase:"completed",credentialJson:Ce(w,h,t),...(l==null?void 0:l.aborted)===!0?{aborted:!0}:{}}),w),w=>{throw y&&B({...f,ceremonyId:u,phase:"failed",error:w,errorName:Ae(w),...(l==null?void 0:l.aborted)===!0?{aborted:!0}:{}}),w})}}.invoke;return X(I,{name:h,length:0})},x=(h,D)=>{let I=q(h,D),O=Object.getOwnPropertyDescriptor(r,h);if(O&&(!("value"in O)||O.writable!==!0))return null;try{r[h]=I}catch{return null}return()=>{r[h]===I&&(O?r[h]=O.value:delete r[h])}},S=x("get",a),N=S?x("create",p):null;return!S||!N?(S==null||S(),t.log("webauthn capture unavailable: credentials methods cannot be patched safely"),C()):(y=!0,{mode:"standard",disconnect:()=>{y=!1,S(),N()}})}function be(e,t,o){let n=ve(t.mediation);if(e==="create")return{kind:"registration",mediation:n};let r=o;return{kind:"authentication",mediation:n,uiMode:we(t.uiMode),credentialSet:Array.isArray(r.allowCredentials)&&r.allowCredentials.length>0?"allowlisted":"discoverable"}}function ve(e){return e===void 0?"optional":e==="silent"||e==="optional"||e==="conditional"||e==="required"?e:"unknown"}function we(e){return e===void 0?"default":e==="immediate"?"immediate":"unknown"}function Re(e){let t=e.userActivation;return typeof(t==null?void 0:t.isActive)=="boolean"?t.isActive:void 0}function Ce(e,t,o){var n;if(e)try{let r=e,a=r.response,p={id:J(r.id),rawId:K(r.rawId),type:J(r.type),authenticatorAttachment:J(r.authenticatorAttachment),response:t==="create"?{clientDataJSON:K(a==null?void 0:a.clientDataJSON),attestationObject:K(a==null?void 0:a.attestationObject),transports:ne((n=a==null?void 0:a.getTransports)==null?void 0:n.call(a))}:{clientDataJSON:K(a==null?void 0:a.clientDataJSON),authenticatorData:K(a==null?void 0:a.authenticatorData),signature:K(a==null?void 0:a.signature),userHandle:K(a==null?void 0:a.userHandle)},...t==="create"?Oe(r):{}};return JSON.stringify(p)}catch(r){o.log("credential serialization failed",r);return}}function ke(e,t){try{let o={},n=J(e.rpId),r=J(e.userVerification),a=ne(e.hints);return n!==void 0&&(o.rpId=n),typeof e.timeout=="number"&&Number.isFinite(e.timeout)&&(o.timeout=e.timeout),r!==void 0&&(o.userVerification=r),a!==void 0&&(o.hints=a),o.challenge=K(e.challenge),Array.isArray(e.allowCredentials)&&(o.allowCredentials=qe(e.allowCredentials)),JSON.stringify(o)}catch(o){t.log("request options serialization failed",o);return}}function qe(e){let t=[];for(let o of e){if(!Q(o))continue;let n=o;t.push({type:J(n.type),id:K(n.id),transports:ne(n.transports)})}return t}function ne(e){if(Array.isArray(e))return e.filter(t=>typeof t=="string")}function J(e){return typeof e=="string"?e:void 0}function Oe(e){var n;let t=(n=e.getClientExtensionResults)==null?void 0:n.call(e);if(!Q(t))return{};let o=t.credProps;return!o||typeof o.rk!="boolean"?{}:{clientExtensionResults:{credProps:{rk:o.rk}}}}function K(e){let t;if(e instanceof ArrayBuffer)t=new Uint8Array(e);else if(ArrayBuffer.isView(e))t=new Uint8Array(e.buffer,e.byteOffset,e.byteLength);else return;let o="";for(let n of t)o+=String.fromCharCode(n);return btoa(o).replace(/\+/g,"-").replace(/\//g,"_").replace(/=+$/g,"")}function Q(e){return e!==null&&(typeof e=="object"||typeof e=="function")}function Ae(e){return e instanceof DOMException?e.name:"UnknownError"}var se=0;function ue(){return se+=1,`network-${se}`}function Pe(e,t){let o=e.responseType;if(o===""||o==="text")return t(e.responseText);if(o==="json"){let n=e.response;return n==null?void 0:t(n)}}var Ee=500,ce=Symbol("body-read-timeout");function de(e){return/event-stream|octet-stream/i.test(e)?!1:/json|text|urlencoded/i.test(e)}async function le(e,t){let o=e.body;if(!o)return;let n=o.getReader(),r;try{let a=new Promise(k=>{r=setTimeout(()=>k(ce),Ee)}),p=new TextDecoder,y=[];for(;;){let k=await Promise.race([n.read(),a]);if(k===ce){t.log("body omitted: read timed out"),n.cancel().catch(()=>{});return}if(k.done)break;y.push(p.decode(k.value,{stream:!0}))}return y.push(p.decode()),y.join("")}catch{n.cancel().catch(()=>{});return}finally{r!==void 0&&clearTimeout(r)}}function re(e){var t;(t=e==null?void 0:e.body)==null||t.cancel().catch(()=>{})}function oe(e,t,o,n,r){try{let a=Object.getOwnPropertyDescriptor(e,t);xe(a,{...n,value:o})&&Object.defineProperty(e,t,n)}catch(a){r.log(`${String(t)} restoration skipped`,a)}}function xe(e,t){return!!e&&"value"in e&&"value"in t&&e.value===t.value&&e.writable===t.writable&&e.enumerable===t.enumerable&&e.configurable===t.configurable}function Se(e){var v,g,z;let{onExchange:t,onRequest:o,match:n}=e;if(typeof t!="function"||typeof n!="function")throw new TypeError("captureNetwork requires onExchange and match callbacks");let r=U(e.logger),a=(v=e.transports)!=null?v:["xhr","fetch"],p=(g=e.bodyCapture)==null?void 0:g.request,y=(z=e.bodyCapture)==null?void 0:z.response,k=typeof p=="function",B=typeof y=="function",q=!1,x=$(r,"network",u=>{if(q)return t(u)}),S=$(r,"network request",u=>{if(q)return o==null?void 0:o(u)}),N=(u,m,l)=>{if(typeof l=="function")try{return l(u,m)}catch(f){r.log("body projection failed",f);return}},h=(u,m)=>{try{let l=typeof document!="undefined"?document.baseURI:void 0,f=new URL(String(u),l);return n(f,m)===!0?{url:f.href,path:f.pathname}:void 0}catch{return}},D=()=>{if(typeof XMLHttpRequest=="undefined")return r.log("xhr capture unavailable: XMLHttpRequest missing"),null;let u=XMLHttpRequest.prototype,m=Object.getOwnPropertyDescriptor(u,"open"),l=Object.getOwnPropertyDescriptor(u,"send");if(!m||!("value"in m)||typeof m.value!="function"||!l||!("value"in l)||typeof l.value!="function")return r.log("xhr capture unavailable: XMLHttpRequest methods missing"),null;let f=m.value,W=l.value;if(_(f)||_(W))return r.log("xhr capture unavailable: an equivalent capture is already active"),null;let w=new WeakMap,R=new Set,P=!1,L={open(...b){var c;let i=Reflect.apply(f,this,b);if(!q||!P)return i;try{let E=w.get(this);E&&(E.reported=!0,(c=E.cleanupListeners)==null||c.call(E));let j=String(b[0]).toUpperCase(),A=h(b[1],j);A?w.set(this,{method:j,url:A.url,path:A.path,reported:!1}):w.delete(this)}catch(E){r.log("xhr open observation failed",E)}return i}}.open,F={send(...b){let i=q&&P?w.get(this):void 0;if(!i||i.reported||i.cleanupListeners)return Reflect.apply(W,this,b);let c=()=>{},E=!1;try{i.requestId=ue();let A={direction:"request",transport:"xhr",method:i.method,url:i.url,path:i.path};i.requestBody=k&&typeof b[0]=="string"?N(b[0],A,p):void 0;let G=()=>{i.outcome===void 0&&(i.outcome="abort")},Y=()=>{i.outcome===void 0&&(i.outcome="timeout")},s=()=>{i.outcome===void 0&&(i.outcome="error")},d=()=>{var V;c();try{if(!q||!P||i.reported||!i.requestId)return;i.reported=!0;let T={direction:"response",transport:"xhr",method:i.method,url:i.url,path:i.path},te=this.status,ie={requestId:i.requestId,transport:"xhr",method:i.method,url:i.url,path:i.path,status:te,ok:te>=200&&te<300,outcome:(V=i.outcome)!=null?V:"load",durationMs:i.startedAt!==void 0?Date.now()-i.startedAt:void 0,responseUrl:this.responseURL||void 0,requestBody:i.requestBody,responseBody:B?Pe(this,ye=>N(ye,T,y)):void 0};i.requestEmitted?x(ie):i.pendingExchange=ie}catch(T){r.log("xhr exchange observation failed",T)}finally{w.get(this)===i&&w.delete(this)}},H=()=>{try{this.readyState===XMLHttpRequest.DONE&&this.status!==0&&d()}catch(V){r.log("xhr ready-state observation failed",V)}},M=()=>d();c=()=>{for(let[V,T]of[["readystatechange",H],["abort",G],["timeout",Y],["error",s],["loadend",M]])this.removeEventListener(V,T);i.cleanupListeners===c&&(i.cleanupListeners=void 0),R.delete(c)},this.addEventListener("readystatechange",H),this.addEventListener("abort",G),this.addEventListener("timeout",Y),this.addEventListener("error",s),this.addEventListener("loadend",M),i.cleanupListeners=c,R.add(c),i.startedAt=Date.now(),E=!0}catch(A){r.log("xhr send observation failed",A),c()}let j;try{j=Reflect.apply(W,this,b)}catch(A){throw c(),A}if(E&&i.requestId!==void 0&&i.startedAt!==void 0){i.requestEmitted=!0,S({requestId:i.requestId,transport:"xhr",method:i.method,url:i.url,path:i.path,startedAt:i.startedAt,requestBody:i.requestBody});let A=i.pendingExchange;i.pendingExchange=void 0,A&&x(A)}return j}}.send;return X(L,f),X(F,W),m.writable!==!0||l.writable!==!0?(r.log("xhr capture unavailable: XMLHttpRequest methods are not writable"),null):(Object.defineProperty(u,"open",{...m,value:L}),Object.defineProperty(u,"send",{...l,value:F}),P=!0,()=>{P=!1;for(let b of[...R])b();oe(u,"open",L,m,r),oe(u,"send",F,l,r)})},I=()=>{let u=globalThis,m=Object.getOwnPropertyDescriptor(u,"fetch");if(!m||!("value"in m))return r.log("fetch capture unavailable: fetch is not an own data property"),null;let l=m.value;if(typeof l!="function")return r.log("fetch capture unavailable: fetch missing"),null;if(_(l))return r.log("fetch capture unavailable: an equivalent capture is already active"),null;let f=!1,W=async(R,P,L,F)=>{try{if(!q||!f){re(L);return}let[b,i]=await Promise.all([F!=null?F:Promise.resolve(void 0),L?le(L,r):Promise.resolve(void 0)]);if(!q||!f)return;let c={direction:"request",transport:"fetch",method:R.method,url:R.url,path:R.path},E={...c,direction:"response"},j=R.requestBody;j===void 0&&b!==void 0&&(j=N(b,c,p));let A=i!==void 0?N(i,E,y):void 0;x({requestId:R.requestId,transport:"fetch",method:R.method,url:R.url,path:R.path,status:P.status,ok:P.ok,outcome:"load",durationMs:Date.now()-R.startedAt,responseUrl:P.url||void 0,requestBody:j,responseBody:A})}catch(b){r.log("fetch exchange observation failed",b)}},w={fetch(...R){var j,A,G,Y;let P;try{let s=R[0],d=R[1];if(q&&f&&k&&typeof Request!="undefined"&&s instanceof Request&&(d==null?void 0:d.body)===void 0&&s.body){let H=String((j=d==null?void 0:d.method)!=null?j:s.method).toUpperCase(),M=(A=s.headers.get("content-type"))!=null?A:"";h(s.url,H)&&de(M)&&(P=s.clone())}}catch(s){r.log("fetch observation failed",s)}let L,F=Date.now();try{L=Reflect.apply(l,this,R)}catch(s){throw re(P),s}let b,i;try{if(q&&f){let s=R[0],d=R[1],H=typeof Request!="undefined"&&s instanceof Request,M=String((G=d==null?void 0:d.method)!=null?G:H?s.method:"GET").toUpperCase(),V=H?s.url:s,T=h(V,M);T&&(b={requestId:ue(),method:M,url:T.url,path:T.path,startedAt:F},i=(Y=d==null?void 0:d.signal)!=null?Y:H?s.signal:void 0,k&&typeof(d==null?void 0:d.body)=="string"&&(b.requestBody=N(d.body,{direction:"request",transport:"fetch",method:M,url:T.url,path:T.path},p)))}}catch(s){r.log("fetch observation failed",s)}if(!b)return re(P),L;let c=b;S({requestId:c.requestId,transport:"fetch",method:c.method,url:c.url,path:c.path,startedAt:c.startedAt,requestBody:c.requestBody});let E=P?le(P,r):void 0;return L.then(s=>{var H;let d;try{if(q&&f&&B){let M=(H=s.headers.get("content-type"))!=null?H:"";de(M)&&s.body&&(d=s.clone())}}catch{}W(c,s,d,E)},s=>{try{if(!q||!f)return;let d=(i==null?void 0:i.aborted)===!0||(s==null?void 0:s.name)==="AbortError"||typeof DOMException!="undefined"&&s instanceof DOMException&&s.code===DOMException.ABORT_ERR;x({requestId:c.requestId,transport:"fetch",method:c.method,url:c.url,path:c.path,status:0,ok:!1,outcome:d?"abort":"error",durationMs:Date.now()-c.startedAt})}catch(d){r.log("fetch failure observation failed",d)}}),L}}.fetch;return X(w,l),m.writable!==!0?(r.log("fetch capture unavailable: fetch is not writable"),null):(Object.defineProperty(u,"fetch",{...m,value:w}),f=!0,()=>{f=!1,oe(u,"fetch",w,m,r)})},O=[];if(a.includes("xhr")){let u=D();u&&O.push(u)}if(a.includes("fetch")){let u=I();u&&O.push(u)}return O.length===0?C():(q=!0,{mode:"standard",disconnect:()=>{q=!1;for(let u of O.splice(0))u()}})}function Ne(e){let t=U(),o;try{if(t=U(e.logger),o=e.onNavigate,typeof o!="function")return C()}catch{return C()}let n,r,a,p,y,k;try{if(n=window,r=n==null?void 0:n.history,!n||!r)return t.log("navigation capture unavailable: window/history missing"),C();if(y=pe(r,"pushState"),k=pe(r,"replaceState"),!y||!k)return t.log("navigation capture unavailable: history method descriptors missing"),C();if(a=y.descriptor.value,p=k.descriptor.value,typeof a!="function"||typeof p!="function")return t.log("navigation capture unavailable: history methods missing"),C();if(typeof n.addEventListener!="function"||typeof n.removeEventListener!="function")return t.log("navigation capture unavailable: window event methods missing"),C()}catch(v){return t.log("navigation capture unavailable: history inspection failed",v),C()}if(_(a)||_(p))return t.log("navigation capture unavailable: an equivalent capture is already active"),C();let B=!1,q=()=>({path:n.location.pathname,search:n.location.search,hash:n.location.hash}),x;try{x=q()}catch(v){return t.log("navigation capture unavailable: location inspection failed",v),C()}let S=$(t,"navigation",v=>{if(B)return o(v)}),N=v=>{if(B)try{let g=q();if(g.path===x.path&&g.search===x.search&&g.hash===x.hash)return;x=g,S({...g,source:v})}catch(g){t.log("navigation observation failed",g)}},h={pushState(...v){let g=Reflect.apply(a,this,v);return N("push"),g}}.pushState,D={replaceState(...v){let g=Reflect.apply(p,this,v);return N("replace"),g}}.replaceState;X(h,a),X(D,p);let I=()=>N("pop"),O=()=>N("hash");try{if(fe(y,h),fe(k,D),r.pushState!==h||r.replaceState!==D)throw new Error("history method replacement did not take effect");n.addEventListener("popstate",I),n.addEventListener("hashchange",O),B=!0}catch(v){return B=!1,ee(n,"popstate",I,t),ee(n,"hashchange",O,t),Z(k,D,t),Z(y,h,t),t.log("navigation capture unavailable: history methods are not writable",v),o=()=>{},S=()=>{},t=U(),C()}return{mode:"standard",disconnect:()=>{B=!1,o=()=>{},ee(n,"popstate",I,t),ee(n,"hashchange",O,t),Z(y,h,t),Z(k,D,t),S=()=>{},t=U()}}}function pe(e,t){let o=e;for(;o;){let n=Object.getOwnPropertyDescriptor(o,t);if(n)return!("value"in n)||typeof n.value!="function"?null:{owner:o,key:t,descriptor:n};o=Object.getPrototypeOf(o)}return null}function fe(e,t){if(e.descriptor.writable!==!0)throw new TypeError(`${e.key} is not writable`);let o=Object.getOwnPropertyDescriptor(e.owner,e.key);if(!he(o,e.descriptor))throw new Error(`${e.key} changed during installation`);Object.defineProperty(e.owner,e.key,{...e.descriptor,value:t})}function he(e,t){return!!e&&"value"in e&&"value"in t&&e.value===t.value&&e.writable===t.writable&&e.enumerable===t.enumerable&&e.configurable===t.configurable}function Z(e,t,o){try{let n=Object.getOwnPropertyDescriptor(e.owner,e.key);he(n,{...e.descriptor,value:t})&&Object.defineProperty(e.owner,e.key,e.descriptor)}catch(n){o.log(`navigation ${e.key} restoration skipped`,n)}}function ee(e,t,o,n){try{e.removeEventListener(t,o)}catch(r){n.log(`navigation ${t} listener removal skipped`,r)}}function Be(e){let t=e.composedPath();return t.length>0?t:e.target?[e.target]:[]}var De="0.1.0-next.5-1f3cd4a";export{De as VERSION,Ne as captureNavigation,Se as captureNetwork,me as captureWebAuthn,Be as composedPath};
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@corbado/autocapture",
|
|
3
|
-
"version": "0.1.0-next.
|
|
4
|
-
"description": "Observer-style capture helpers for WebAuthn ceremonies, selected network exchanges, in-app navigation,
|
|
3
|
+
"version": "0.1.0-next.5-1f3cd4a",
|
|
4
|
+
"description": "Observer-style capture helpers for WebAuthn ceremonies, selected network exchanges, in-app navigation, and composed event paths.",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"module": "./dist/index.mjs",
|
|
7
7
|
"types": "./dist/index.d.ts",
|