aissue 0.0.0-stage → 2.0.0
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/LICENSE +21 -0
- package/README.md +390 -2
- package/dist/cjs/browser.d.ts +16 -0
- package/dist/cjs/browser.js +80 -0
- package/dist/cjs/core/breadcrumbs.d.ts +48 -0
- package/dist/cjs/core/breadcrumbs.js +313 -0
- package/dist/cjs/core/client.d.ts +54 -0
- package/dist/cjs/core/client.js +293 -0
- package/dist/cjs/core/env.d.ts +19 -0
- package/dist/cjs/core/env.js +71 -0
- package/dist/cjs/core/event.d.ts +35 -0
- package/dist/cjs/core/event.js +187 -0
- package/dist/cjs/core/hub.d.ts +20 -0
- package/dist/cjs/core/hub.js +21 -0
- package/dist/cjs/core/instrument-browser.d.ts +16 -0
- package/dist/cjs/core/instrument-browser.js +208 -0
- package/dist/cjs/core/instrument-node.d.ts +5 -0
- package/dist/cjs/core/instrument-node.js +250 -0
- package/dist/cjs/core/instrument.d.ts +12 -0
- package/dist/cjs/core/instrument.js +137 -0
- package/dist/cjs/core/privacy.d.ts +25 -0
- package/dist/cjs/core/privacy.js +269 -0
- package/dist/cjs/core/stack.d.ts +13 -0
- package/dist/cjs/core/stack.js +147 -0
- package/dist/cjs/core/transport.d.ts +31 -0
- package/dist/cjs/core/transport.js +154 -0
- package/dist/cjs/core/types.d.ts +149 -0
- package/dist/cjs/core/types.js +2 -0
- package/dist/cjs/core/version.d.ts +2 -0
- package/dist/cjs/core/version.js +6 -0
- package/dist/cjs/index.d.ts +27 -0
- package/dist/cjs/index.js +83 -0
- package/dist/cjs/nextjs/client.d.ts +10 -0
- package/dist/cjs/nextjs/client.js +99 -0
- package/dist/cjs/nextjs/index.d.ts +31 -0
- package/dist/cjs/nextjs/index.js +99 -0
- package/dist/cjs/node.d.ts +48 -0
- package/dist/cjs/node.js +223 -0
- package/dist/cjs/package.json +3 -0
- package/dist/cjs/react.d.ts +40 -0
- package/dist/cjs/react.js +90 -0
- package/dist/esm/browser.d.ts +16 -0
- package/dist/esm/browser.js +71 -0
- package/dist/esm/cli.d.ts +2 -0
- package/dist/esm/cli.js +386 -0
- package/dist/esm/core/breadcrumbs.d.ts +48 -0
- package/dist/esm/core/breadcrumbs.js +296 -0
- package/dist/esm/core/client.d.ts +54 -0
- package/dist/esm/core/client.js +285 -0
- package/dist/esm/core/env.d.ts +19 -0
- package/dist/esm/core/env.js +62 -0
- package/dist/esm/core/event.d.ts +35 -0
- package/dist/esm/core/event.js +179 -0
- package/dist/esm/core/hub.d.ts +20 -0
- package/dist/esm/core/hub.js +17 -0
- package/dist/esm/core/instrument-browser.d.ts +16 -0
- package/dist/esm/core/instrument-browser.js +203 -0
- package/dist/esm/core/instrument-node.d.ts +5 -0
- package/dist/esm/core/instrument-node.js +214 -0
- package/dist/esm/core/instrument.d.ts +12 -0
- package/dist/esm/core/instrument.js +132 -0
- package/dist/esm/core/privacy.d.ts +25 -0
- package/dist/esm/core/privacy.js +257 -0
- package/dist/esm/core/stack.d.ts +13 -0
- package/dist/esm/core/stack.js +140 -0
- package/dist/esm/core/transport.d.ts +31 -0
- package/dist/esm/core/transport.js +149 -0
- package/dist/esm/core/types.d.ts +149 -0
- package/dist/esm/core/types.js +1 -0
- package/dist/esm/core/version.d.ts +2 -0
- package/dist/esm/core/version.js +3 -0
- package/dist/esm/index.d.ts +27 -0
- package/dist/esm/index.js +72 -0
- package/dist/esm/nextjs/client.d.ts +10 -0
- package/dist/esm/nextjs/client.js +90 -0
- package/dist/esm/nextjs/index.d.ts +31 -0
- package/dist/esm/nextjs/index.js +88 -0
- package/dist/esm/node.d.ts +48 -0
- package/dist/esm/node.js +210 -0
- package/dist/esm/react.d.ts +40 -0
- package/dist/esm/react.js +47 -0
- package/package.json +141 -4
|
@@ -0,0 +1,250 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
exports.instrumentNode = instrumentNode;
|
|
37
|
+
/**
|
|
38
|
+
* Node-only automatic breadcrumbs: console, fetch (undici), http/https client requests, and a
|
|
39
|
+
* per-request breadcrumb buffer (AsyncLocalStorage) for every incoming http/https server request,
|
|
40
|
+
* so concurrent requests never mix their breadcrumbs.
|
|
41
|
+
*
|
|
42
|
+
* Node built-ins are looked up at runtime (process.getBuiltinModule, else a dynamic import) so
|
|
43
|
+
* that edge bundles that include aissue/nextjs never import them statically.
|
|
44
|
+
*/
|
|
45
|
+
const breadcrumbs_js_1 = require("./breadcrumbs.js");
|
|
46
|
+
const hub_js_1 = require("./hub.js");
|
|
47
|
+
const instrument_js_1 = require("./instrument.js");
|
|
48
|
+
const privacy_js_1 = require("./privacy.js");
|
|
49
|
+
function builtinSync(name) {
|
|
50
|
+
try {
|
|
51
|
+
const p = globalThis.process;
|
|
52
|
+
if (p && typeof p.getBuiltinModule === 'function')
|
|
53
|
+
return p.getBuiltinModule(name) ?? undefined;
|
|
54
|
+
}
|
|
55
|
+
catch {
|
|
56
|
+
// ignore
|
|
57
|
+
}
|
|
58
|
+
return undefined;
|
|
59
|
+
}
|
|
60
|
+
async function builtinAsync(name) {
|
|
61
|
+
const sync = builtinSync(name);
|
|
62
|
+
if (sync)
|
|
63
|
+
return sync;
|
|
64
|
+
try {
|
|
65
|
+
const ns = await Promise.resolve(`${name}`).then(s => __importStar(require(s)));
|
|
66
|
+
return ns && ns.default ? ns.default : ns;
|
|
67
|
+
}
|
|
68
|
+
catch {
|
|
69
|
+
return undefined;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
function setupStorage(asyncHooks) {
|
|
73
|
+
const hub = (0, hub_js_1.getHub)();
|
|
74
|
+
if (hub.breadcrumbStorage)
|
|
75
|
+
return;
|
|
76
|
+
const ALS = (asyncHooks && asyncHooks.AsyncLocalStorage) || globalThis.AsyncLocalStorage;
|
|
77
|
+
if (typeof ALS !== 'function')
|
|
78
|
+
return;
|
|
79
|
+
const als = new ALS();
|
|
80
|
+
hub.breadcrumbStorage = {
|
|
81
|
+
getStore: () => als.getStore(),
|
|
82
|
+
run: (store, fn) => als.run(store, fn),
|
|
83
|
+
};
|
|
84
|
+
}
|
|
85
|
+
/** Every incoming request on an http(s) server gets its own breadcrumb buffer. */
|
|
86
|
+
function instrumentServer(serverProto) {
|
|
87
|
+
if (!serverProto)
|
|
88
|
+
return;
|
|
89
|
+
(0, breadcrumbs_js_1.wrapMethod)(serverProto, 'emit', (original) => function aissueServerEmit(...args) {
|
|
90
|
+
let storage;
|
|
91
|
+
try {
|
|
92
|
+
storage = args[0] === 'request' && (0, breadcrumbs_js_1.breadcrumbsActive)() ? (0, hub_js_1.getHub)().breadcrumbStorage : undefined;
|
|
93
|
+
}
|
|
94
|
+
catch {
|
|
95
|
+
storage = undefined;
|
|
96
|
+
}
|
|
97
|
+
if (!storage)
|
|
98
|
+
return original.apply(this, args);
|
|
99
|
+
return storage.run([], () => original.apply(this, args));
|
|
100
|
+
});
|
|
101
|
+
}
|
|
102
|
+
function requestInfo(args, defaultProtocol) {
|
|
103
|
+
let url;
|
|
104
|
+
let options;
|
|
105
|
+
const [a, b] = args;
|
|
106
|
+
if (typeof a === 'string')
|
|
107
|
+
url = new URL(a);
|
|
108
|
+
else if (a && typeof a === 'object' && typeof a.href === 'string' && typeof a.host === 'string') {
|
|
109
|
+
url = new URL(a.href);
|
|
110
|
+
}
|
|
111
|
+
else if (a && typeof a === 'object')
|
|
112
|
+
options = a;
|
|
113
|
+
if (url && b && typeof b === 'object')
|
|
114
|
+
options = b;
|
|
115
|
+
let full;
|
|
116
|
+
if (url) {
|
|
117
|
+
full = `${url.protocol}//${url.host}${url.pathname}`;
|
|
118
|
+
}
|
|
119
|
+
else if (options) {
|
|
120
|
+
const protocol = typeof options.protocol === 'string' ? options.protocol : defaultProtocol;
|
|
121
|
+
let host = String(options.hostname || options.host || 'localhost');
|
|
122
|
+
const colons = host.split(':').length - 1;
|
|
123
|
+
if (colons === 1)
|
|
124
|
+
host = host.replace(/:\d*$/, ''); // "example.com:8080"
|
|
125
|
+
else if (colons > 1 && !host.startsWith('['))
|
|
126
|
+
host = `[${host}]`; // IPv6
|
|
127
|
+
const port = options.port ? `:${options.port}` : '';
|
|
128
|
+
const defaultPort = (protocol === 'https:' && port === ':443') || (protocol === 'http:' && port === ':80');
|
|
129
|
+
const path = typeof options.path === 'string' ? options.path : '/';
|
|
130
|
+
full = `${protocol}//${host}${defaultPort ? '' : port}${path}`;
|
|
131
|
+
}
|
|
132
|
+
else {
|
|
133
|
+
return undefined;
|
|
134
|
+
}
|
|
135
|
+
full = (0, privacy_js_1.sanitizeUrl)(full);
|
|
136
|
+
if ((0, breadcrumbs_js_1.isAIssueUrl)(full))
|
|
137
|
+
return undefined;
|
|
138
|
+
const method = (options && typeof options.method === 'string' && options.method) || 'GET';
|
|
139
|
+
return { method: method.toUpperCase().slice(0, 16), url: full, start: Date.now() };
|
|
140
|
+
}
|
|
141
|
+
/**
|
|
142
|
+
* Watch a ClientRequest by wrapping its emit: adding 'response' or 'error' listeners would change
|
|
143
|
+
* Node's behaviour (unread responses are no longer dumped; unhandled errors no longer throw).
|
|
144
|
+
*/
|
|
145
|
+
function observeRequest(req, info, buffer) {
|
|
146
|
+
if (!req || typeof req.emit !== 'function')
|
|
147
|
+
return;
|
|
148
|
+
const originalEmit = req.emit;
|
|
149
|
+
let done = false;
|
|
150
|
+
req.emit = function aissueRequestEmit(...args) {
|
|
151
|
+
if (!done && (args[0] === 'response' || args[0] === 'error')) {
|
|
152
|
+
done = true;
|
|
153
|
+
try {
|
|
154
|
+
if (args[0] === 'response') {
|
|
155
|
+
const status = args[1]?.statusCode;
|
|
156
|
+
(0, instrument_js_1.httpBreadcrumb)('http', info, typeof status === 'number' ? status : undefined, buffer);
|
|
157
|
+
}
|
|
158
|
+
else {
|
|
159
|
+
(0, instrument_js_1.httpBreadcrumb)('http', info, undefined, buffer, args[1] ?? 'Error');
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
catch {
|
|
163
|
+
// ignore
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
return originalEmit.apply(this, args);
|
|
167
|
+
};
|
|
168
|
+
}
|
|
169
|
+
function instrumentHttpModule(mod, protocol) {
|
|
170
|
+
if (!mod)
|
|
171
|
+
return false;
|
|
172
|
+
let changed = false;
|
|
173
|
+
for (const name of ['request', 'get']) {
|
|
174
|
+
changed =
|
|
175
|
+
(0, breadcrumbs_js_1.wrapMethod)(mod, name, (original) => function aissueHttpRequest(...args) {
|
|
176
|
+
let info;
|
|
177
|
+
try {
|
|
178
|
+
if ((0, breadcrumbs_js_1.breadcrumbsActive)('http'))
|
|
179
|
+
info = requestInfo(args, protocol);
|
|
180
|
+
}
|
|
181
|
+
catch {
|
|
182
|
+
info = undefined;
|
|
183
|
+
}
|
|
184
|
+
const req = original.apply(this, args);
|
|
185
|
+
if (info) {
|
|
186
|
+
try {
|
|
187
|
+
observeRequest(req, info, (0, breadcrumbs_js_1.currentBuffer)());
|
|
188
|
+
}
|
|
189
|
+
catch {
|
|
190
|
+
// ignore
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
return req;
|
|
194
|
+
}) || changed;
|
|
195
|
+
}
|
|
196
|
+
return changed;
|
|
197
|
+
}
|
|
198
|
+
function install(mods) {
|
|
199
|
+
const steps = [
|
|
200
|
+
() => setupStorage(mods.asyncHooks),
|
|
201
|
+
instrument_js_1.instrumentConsole,
|
|
202
|
+
instrument_js_1.instrumentFetch,
|
|
203
|
+
() => instrumentServer(mods.http?.Server?.prototype),
|
|
204
|
+
() => instrumentServer(mods.https?.Server?.prototype),
|
|
205
|
+
() => {
|
|
206
|
+
const changedHttp = instrumentHttpModule(mods.http, 'http:');
|
|
207
|
+
const changedHttps = instrumentHttpModule(mods.https, 'https:');
|
|
208
|
+
// Make `import { request } from 'node:http'` see the wrappers too.
|
|
209
|
+
if ((changedHttp || changedHttps) && typeof mods.module?.syncBuiltinESMExports === 'function') {
|
|
210
|
+
mods.module.syncBuiltinESMExports();
|
|
211
|
+
}
|
|
212
|
+
},
|
|
213
|
+
];
|
|
214
|
+
for (const step of steps) {
|
|
215
|
+
try {
|
|
216
|
+
step();
|
|
217
|
+
}
|
|
218
|
+
catch {
|
|
219
|
+
// one failing source must not stop the others
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
/**
|
|
224
|
+
* Install Node breadcrumbs (idempotent). Synchronous on Node 20.16+/22.3+ (process.getBuiltinModule);
|
|
225
|
+
* on older versions the built-ins are imported first, so installation completes a moment later.
|
|
226
|
+
*/
|
|
227
|
+
function instrumentNode() {
|
|
228
|
+
try {
|
|
229
|
+
const names = { http: 'node:http', https: 'node:https', asyncHooks: 'node:async_hooks', module: 'node:module' };
|
|
230
|
+
const http = builtinSync(names.http);
|
|
231
|
+
if (http) {
|
|
232
|
+
install({
|
|
233
|
+
http,
|
|
234
|
+
https: builtinSync(names.https),
|
|
235
|
+
asyncHooks: builtinSync(names.asyncHooks),
|
|
236
|
+
module: builtinSync(names.module),
|
|
237
|
+
});
|
|
238
|
+
return;
|
|
239
|
+
}
|
|
240
|
+
Promise.all([
|
|
241
|
+
builtinAsync(names.http),
|
|
242
|
+
builtinAsync(names.https),
|
|
243
|
+
builtinAsync(names.asyncHooks),
|
|
244
|
+
builtinAsync(names.module),
|
|
245
|
+
]).then(([h, hs, ah, m]) => install({ http: h, https: hs, asyncHooks: ah, module: m }), () => install({}));
|
|
246
|
+
}
|
|
247
|
+
catch {
|
|
248
|
+
// never throw into the host app
|
|
249
|
+
}
|
|
250
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { Breadcrumb } from './types.js';
|
|
2
|
+
/** console.log / info / warn / error become `log` breadcrumbs. */
|
|
3
|
+
export declare function instrumentConsole(): void;
|
|
4
|
+
export interface HttpInfo {
|
|
5
|
+
method: string;
|
|
6
|
+
url: string;
|
|
7
|
+
start: number;
|
|
8
|
+
}
|
|
9
|
+
/** Record an http breadcrumb: "GET https://api.example.com/users [200]". */
|
|
10
|
+
export declare function httpBreadcrumb(category: string, info: HttpInfo, status: number | undefined, buffer: Breadcrumb[], error?: unknown): void;
|
|
11
|
+
/** globalThis.fetch: method, URL without the query string, status. Requests to AIssue are skipped. */
|
|
12
|
+
export declare function instrumentFetch(): void;
|
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.instrumentConsole = instrumentConsole;
|
|
4
|
+
exports.httpBreadcrumb = httpBreadcrumb;
|
|
5
|
+
exports.instrumentFetch = instrumentFetch;
|
|
6
|
+
/**
|
|
7
|
+
* Automatic breadcrumbs shared by the browser and Node: console and fetch.
|
|
8
|
+
* Every wrapper is idempotent (an already wrapped function is never wrapped again), never throws
|
|
9
|
+
* into the host, keeps the original behaviour (arguments, `this`, return value, exceptions) and
|
|
10
|
+
* records nothing while the SDK is disabled.
|
|
11
|
+
*/
|
|
12
|
+
const breadcrumbs_js_1 = require("./breadcrumbs.js");
|
|
13
|
+
const privacy_js_1 = require("./privacy.js");
|
|
14
|
+
const CONSOLE_LEVELS = {
|
|
15
|
+
log: 'info',
|
|
16
|
+
info: 'info',
|
|
17
|
+
warn: 'warning',
|
|
18
|
+
error: 'error',
|
|
19
|
+
};
|
|
20
|
+
function consoleBreadcrumb(method, args) {
|
|
21
|
+
if (!args.length)
|
|
22
|
+
return;
|
|
23
|
+
const first = args[0];
|
|
24
|
+
if (typeof first === 'string' && first.startsWith('[aissue]'))
|
|
25
|
+
return; // the SDK's own logs
|
|
26
|
+
const parts = [];
|
|
27
|
+
let length = 0;
|
|
28
|
+
for (const arg of args) {
|
|
29
|
+
if (length > 2000)
|
|
30
|
+
break;
|
|
31
|
+
const text = (0, breadcrumbs_js_1.describeValue)(arg, 2000);
|
|
32
|
+
parts.push(text);
|
|
33
|
+
length += text.length + 1;
|
|
34
|
+
}
|
|
35
|
+
(0, breadcrumbs_js_1.recordBreadcrumb)({ type: 'log', category: 'console', level: CONSOLE_LEVELS[method], message: parts.join(' ') });
|
|
36
|
+
}
|
|
37
|
+
/** console.log / info / warn / error become `log` breadcrumbs. */
|
|
38
|
+
function instrumentConsole() {
|
|
39
|
+
const c = globalThis.console;
|
|
40
|
+
if (!c)
|
|
41
|
+
return;
|
|
42
|
+
for (const method of Object.keys(CONSOLE_LEVELS)) {
|
|
43
|
+
(0, breadcrumbs_js_1.wrapMethod)(c, method, (original) => function aissueConsole(...args) {
|
|
44
|
+
try {
|
|
45
|
+
if ((0, breadcrumbs_js_1.breadcrumbsActive)('console'))
|
|
46
|
+
consoleBreadcrumb(method, args);
|
|
47
|
+
}
|
|
48
|
+
catch {
|
|
49
|
+
// never throw into the host app
|
|
50
|
+
}
|
|
51
|
+
return original.apply(this, args);
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
/** Record an http breadcrumb: "GET https://api.example.com/users [200]". */
|
|
56
|
+
function httpBreadcrumb(category, info, status, buffer, error) {
|
|
57
|
+
try {
|
|
58
|
+
recordHttp(category, info, status, buffer, error);
|
|
59
|
+
}
|
|
60
|
+
catch {
|
|
61
|
+
// never throw into the host app
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
function recordHttp(category, info, status, buffer, error) {
|
|
65
|
+
const data = { method: info.method, url: info.url };
|
|
66
|
+
if (status)
|
|
67
|
+
data.status_code = status;
|
|
68
|
+
data.duration_ms = Math.max(0, Date.now() - info.start);
|
|
69
|
+
if (error !== undefined) {
|
|
70
|
+
const e = error;
|
|
71
|
+
data.error = typeof e?.code === 'string' ? e.code : typeof e?.name === 'string' ? e.name : 'Error';
|
|
72
|
+
}
|
|
73
|
+
(0, breadcrumbs_js_1.recordBreadcrumb)({
|
|
74
|
+
type: 'http',
|
|
75
|
+
category,
|
|
76
|
+
level: error !== undefined ? 'error' : (0, breadcrumbs_js_1.levelForStatus)(status),
|
|
77
|
+
message: `${info.method} ${info.url}${status ? ` [${status}]` : error !== undefined ? ' [failed]' : ''}`,
|
|
78
|
+
data,
|
|
79
|
+
}, buffer);
|
|
80
|
+
}
|
|
81
|
+
function fetchInfo(input, init) {
|
|
82
|
+
let url;
|
|
83
|
+
let method;
|
|
84
|
+
if (typeof input === 'string')
|
|
85
|
+
url = input;
|
|
86
|
+
else if (input && typeof input === 'object') {
|
|
87
|
+
const i = input;
|
|
88
|
+
if (typeof i.href === 'string')
|
|
89
|
+
url = i.href; // URL
|
|
90
|
+
else if (typeof i.url === 'string') {
|
|
91
|
+
url = i.url; // Request
|
|
92
|
+
method = i.method;
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
if (!url || (0, breadcrumbs_js_1.isAIssueUrl)(url))
|
|
96
|
+
return undefined;
|
|
97
|
+
const initMethod = init && typeof init === 'object' ? init.method : undefined;
|
|
98
|
+
if (typeof initMethod === 'string' && initMethod)
|
|
99
|
+
method = initMethod;
|
|
100
|
+
return {
|
|
101
|
+
method: (typeof method === 'string' && method ? method : 'GET').toUpperCase().slice(0, 16),
|
|
102
|
+
url: (0, privacy_js_1.sanitizeUrl)(url),
|
|
103
|
+
start: Date.now(),
|
|
104
|
+
};
|
|
105
|
+
}
|
|
106
|
+
/** globalThis.fetch: method, URL without the query string, status. Requests to AIssue are skipped. */
|
|
107
|
+
function instrumentFetch() {
|
|
108
|
+
(0, breadcrumbs_js_1.wrapMethod)(globalThis, 'fetch', (original) => function aissueFetch(...args) {
|
|
109
|
+
let info;
|
|
110
|
+
try {
|
|
111
|
+
if ((0, breadcrumbs_js_1.breadcrumbsActive)('fetch'))
|
|
112
|
+
info = fetchInfo(args[0], args[1]);
|
|
113
|
+
}
|
|
114
|
+
catch {
|
|
115
|
+
info = undefined;
|
|
116
|
+
}
|
|
117
|
+
const result = original.apply(this, args);
|
|
118
|
+
if (info) {
|
|
119
|
+
try {
|
|
120
|
+
const buffer = (0, breadcrumbs_js_1.currentBuffer)();
|
|
121
|
+
const done = info;
|
|
122
|
+
const promise = result;
|
|
123
|
+
if (promise && typeof promise.then === 'function') {
|
|
124
|
+
// A side branch: the caller's promise is returned untouched.
|
|
125
|
+
promise.then((response) => {
|
|
126
|
+
const status = response?.status;
|
|
127
|
+
httpBreadcrumb('fetch', done, typeof status === 'number' ? status : undefined, buffer);
|
|
128
|
+
}, (error) => httpBreadcrumb('fetch', done, undefined, buffer, error ?? 'Error'));
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
catch {
|
|
132
|
+
// never throw into the host app
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
return result;
|
|
136
|
+
});
|
|
137
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { HeadersInput, QueryInput } from './types.js';
|
|
2
|
+
export declare const FILTERED = "[Filtered]";
|
|
3
|
+
export declare function isSensitiveKey(key: unknown): boolean;
|
|
4
|
+
export declare function truncate(value: string, max: number): string;
|
|
5
|
+
/** "/a/b?x=1#y" -> "/a/b". Also used for Referer. */
|
|
6
|
+
export declare function stripQuery(value: string): string;
|
|
7
|
+
/** The query part of a path or URL ("" when there is none), without the fragment. */
|
|
8
|
+
export declare function queryOf(value: string): string;
|
|
9
|
+
/** Keep only allowlisted headers, with canonical names; strip the query string from Referer. */
|
|
10
|
+
export declare function filterHeaders(input: HeadersInput | undefined | null): Record<string, string>;
|
|
11
|
+
/**
|
|
12
|
+
* Query parameters as {key: [values]}. Values under sensitive-looking keys become ["[Filtered]"].
|
|
13
|
+
* Accepts "a=1&b=2", "?a=1", URLSearchParams, or an object such as Express' req.query.
|
|
14
|
+
*/
|
|
15
|
+
export declare function filterQuery(input: QueryInput | undefined | null): Record<string, string[]>;
|
|
16
|
+
/**
|
|
17
|
+
* JSON-safe copy of arbitrary context: sensitive-looking keys filtered (recursively),
|
|
18
|
+
* depth / size limited, functions and cycles dropped.
|
|
19
|
+
*/
|
|
20
|
+
export declare function scrub(value: unknown, depth?: number, seen?: WeakSet<object>): unknown;
|
|
21
|
+
export declare const EMAIL_PLACEHOLDER = "[email]";
|
|
22
|
+
/** Redact credentials, card numbers and email addresses from free text. Never throws. */
|
|
23
|
+
export declare function scrubText(text: string): string;
|
|
24
|
+
/** "https://user:pass@host/a/b?x=1#y" -> "https://host/a/b" (no credentials, query or fragment). */
|
|
25
|
+
export declare function sanitizeUrl(url: string): string;
|