@stainlessdev/xray-fastify 0.1.0-branch.bg-publish-to-npm.18b1cb1
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/dist/index.cjs +72 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +14 -0
- package/dist/index.d.ts +14 -0
- package/dist/index.js +46 -0
- package/dist/index.js.map +1 -0
- package/package.json +59 -0
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/index.ts
|
|
21
|
+
var index_exports = {};
|
|
22
|
+
__export(index_exports, {
|
|
23
|
+
addFastifyHooks: () => addFastifyHooks,
|
|
24
|
+
createEmitter: () => import_xray_core.createEmitter
|
|
25
|
+
});
|
|
26
|
+
module.exports = __toCommonJS(index_exports);
|
|
27
|
+
var import_xray_core = require("@stainlessdev/xray-core");
|
|
28
|
+
var import_xray_node = require("@stainlessdev/xray-node");
|
|
29
|
+
var import_internal = require("@stainlessdev/xray-core/internal");
|
|
30
|
+
function addFastifyHooks(instance, xray, options) {
|
|
31
|
+
const nodeHandler = (0, import_xray_node.wrapHttpHandler)(() => {
|
|
32
|
+
}, xray, {
|
|
33
|
+
...options,
|
|
34
|
+
onRequest: (ctx) => {
|
|
35
|
+
options?.onRequest?.(ctx);
|
|
36
|
+
}
|
|
37
|
+
});
|
|
38
|
+
instance.addHook(
|
|
39
|
+
"onRequest",
|
|
40
|
+
(request, reply, next) => {
|
|
41
|
+
const req = request;
|
|
42
|
+
const res = reply;
|
|
43
|
+
if (!req.raw || !res.raw) {
|
|
44
|
+
next();
|
|
45
|
+
return;
|
|
46
|
+
}
|
|
47
|
+
nodeHandler(req.raw, res.raw);
|
|
48
|
+
req.xray = (0, import_xray_node.getXrayContext)(req.raw);
|
|
49
|
+
next();
|
|
50
|
+
}
|
|
51
|
+
);
|
|
52
|
+
instance.addHook(
|
|
53
|
+
"preHandler",
|
|
54
|
+
(request, _reply, next) => {
|
|
55
|
+
const anyReq = request;
|
|
56
|
+
const route = anyReq.routeOptions?.url;
|
|
57
|
+
if (route && anyReq.raw) {
|
|
58
|
+
const ctx = (0, import_xray_node.getXrayContext)(anyReq.raw);
|
|
59
|
+
if (ctx) {
|
|
60
|
+
(0, import_internal.setContextRoute)(ctx, route);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
next();
|
|
64
|
+
}
|
|
65
|
+
);
|
|
66
|
+
}
|
|
67
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
68
|
+
0 && (module.exports = {
|
|
69
|
+
addFastifyHooks,
|
|
70
|
+
createEmitter
|
|
71
|
+
});
|
|
72
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["import type { XrayEmitter, XrayContext } from '@stainlessdev/xray-core';\nimport { createEmitter } from '@stainlessdev/xray-core';\nimport { wrapHttpHandler, getXrayContext, type WrapOptions } from '@stainlessdev/xray-node';\nimport { setContextRoute } from '@stainlessdev/xray-core/internal';\n\nexport { createEmitter };\nexport type {\n CaptureConfig,\n RedactionConfig,\n RequestLog,\n XrayConfig,\n XrayContext,\n XrayEmitter,\n} from '@stainlessdev/xray-core';\nexport type { WrapOptions } from '@stainlessdev/xray-node';\n\nexport type FastifyInstance = {\n addHook: {\n (name: 'onRequest', hook: (...args: any[]) => unknown): void;\n (name: 'preHandler', hook: (...args: any[]) => unknown): void;\n };\n};\n\nexport function addFastifyHooks(\n instance: FastifyInstance,\n xray: XrayEmitter,\n options?: WrapOptions,\n): void {\n const nodeHandler = wrapHttpHandler(() => {}, xray, {\n ...options,\n onRequest: (ctx: XrayContext) => {\n options?.onRequest?.(ctx);\n },\n });\n\n instance.addHook(\n 'onRequest',\n (request: unknown, reply: unknown, next: (err?: unknown) => void) => {\n const req = request as { raw?: Parameters<typeof nodeHandler>[0]; xray?: XrayContext };\n const res = reply as { raw?: Parameters<typeof nodeHandler>[1] };\n if (!req.raw || !res.raw) {\n next();\n return;\n }\n nodeHandler(req.raw, res.raw);\n req.xray = getXrayContext(req.raw);\n next();\n },\n );\n\n instance.addHook(\n 'preHandler',\n (request: unknown, _reply: unknown, next: (err?: unknown) => void) => {\n const anyReq = request as {\n routeOptions?: { url?: string };\n raw?: Parameters<typeof nodeHandler>[0];\n };\n const route = anyReq.routeOptions?.url;\n if (route && anyReq.raw) {\n const ctx = getXrayContext(anyReq.raw);\n if (ctx) {\n setContextRoute(ctx, route);\n }\n }\n next();\n },\n );\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,uBAA8B;AAC9B,uBAAkE;AAClE,sBAAgC;AAoBzB,SAAS,gBACd,UACA,MACA,SACM;AACN,QAAM,kBAAc,kCAAgB,MAAM;AAAA,EAAC,GAAG,MAAM;AAAA,IAClD,GAAG;AAAA,IACH,WAAW,CAAC,QAAqB;AAC/B,eAAS,YAAY,GAAG;AAAA,IAC1B;AAAA,EACF,CAAC;AAED,WAAS;AAAA,IACP;AAAA,IACA,CAAC,SAAkB,OAAgB,SAAkC;AACnE,YAAM,MAAM;AACZ,YAAM,MAAM;AACZ,UAAI,CAAC,IAAI,OAAO,CAAC,IAAI,KAAK;AACxB,aAAK;AACL;AAAA,MACF;AACA,kBAAY,IAAI,KAAK,IAAI,GAAG;AAC5B,UAAI,WAAO,iCAAe,IAAI,GAAG;AACjC,WAAK;AAAA,IACP;AAAA,EACF;AAEA,WAAS;AAAA,IACP;AAAA,IACA,CAAC,SAAkB,QAAiB,SAAkC;AACpE,YAAM,SAAS;AAIf,YAAM,QAAQ,OAAO,cAAc;AACnC,UAAI,SAAS,OAAO,KAAK;AACvB,cAAM,UAAM,iCAAe,OAAO,GAAG;AACrC,YAAI,KAAK;AACP,+CAAgB,KAAK,KAAK;AAAA,QAC5B;AAAA,MACF;AACA,WAAK;AAAA,IACP;AAAA,EACF;AACF;","names":[]}
|
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { XrayEmitter } from '@stainlessdev/xray-core';
|
|
2
|
+
export { CaptureConfig, RedactionConfig, RequestLog, XrayConfig, XrayContext, XrayEmitter, createEmitter } from '@stainlessdev/xray-core';
|
|
3
|
+
import { WrapOptions } from '@stainlessdev/xray-node';
|
|
4
|
+
export { WrapOptions } from '@stainlessdev/xray-node';
|
|
5
|
+
|
|
6
|
+
type FastifyInstance = {
|
|
7
|
+
addHook: {
|
|
8
|
+
(name: 'onRequest', hook: (...args: any[]) => unknown): void;
|
|
9
|
+
(name: 'preHandler', hook: (...args: any[]) => unknown): void;
|
|
10
|
+
};
|
|
11
|
+
};
|
|
12
|
+
declare function addFastifyHooks(instance: FastifyInstance, xray: XrayEmitter, options?: WrapOptions): void;
|
|
13
|
+
|
|
14
|
+
export { type FastifyInstance, addFastifyHooks };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { XrayEmitter } from '@stainlessdev/xray-core';
|
|
2
|
+
export { CaptureConfig, RedactionConfig, RequestLog, XrayConfig, XrayContext, XrayEmitter, createEmitter } from '@stainlessdev/xray-core';
|
|
3
|
+
import { WrapOptions } from '@stainlessdev/xray-node';
|
|
4
|
+
export { WrapOptions } from '@stainlessdev/xray-node';
|
|
5
|
+
|
|
6
|
+
type FastifyInstance = {
|
|
7
|
+
addHook: {
|
|
8
|
+
(name: 'onRequest', hook: (...args: any[]) => unknown): void;
|
|
9
|
+
(name: 'preHandler', hook: (...args: any[]) => unknown): void;
|
|
10
|
+
};
|
|
11
|
+
};
|
|
12
|
+
declare function addFastifyHooks(instance: FastifyInstance, xray: XrayEmitter, options?: WrapOptions): void;
|
|
13
|
+
|
|
14
|
+
export { type FastifyInstance, addFastifyHooks };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
// src/index.ts
|
|
2
|
+
import { createEmitter } from "@stainlessdev/xray-core";
|
|
3
|
+
import { wrapHttpHandler, getXrayContext } from "@stainlessdev/xray-node";
|
|
4
|
+
import { setContextRoute } from "@stainlessdev/xray-core/internal";
|
|
5
|
+
function addFastifyHooks(instance, xray, options) {
|
|
6
|
+
const nodeHandler = wrapHttpHandler(() => {
|
|
7
|
+
}, xray, {
|
|
8
|
+
...options,
|
|
9
|
+
onRequest: (ctx) => {
|
|
10
|
+
options?.onRequest?.(ctx);
|
|
11
|
+
}
|
|
12
|
+
});
|
|
13
|
+
instance.addHook(
|
|
14
|
+
"onRequest",
|
|
15
|
+
(request, reply, next) => {
|
|
16
|
+
const req = request;
|
|
17
|
+
const res = reply;
|
|
18
|
+
if (!req.raw || !res.raw) {
|
|
19
|
+
next();
|
|
20
|
+
return;
|
|
21
|
+
}
|
|
22
|
+
nodeHandler(req.raw, res.raw);
|
|
23
|
+
req.xray = getXrayContext(req.raw);
|
|
24
|
+
next();
|
|
25
|
+
}
|
|
26
|
+
);
|
|
27
|
+
instance.addHook(
|
|
28
|
+
"preHandler",
|
|
29
|
+
(request, _reply, next) => {
|
|
30
|
+
const anyReq = request;
|
|
31
|
+
const route = anyReq.routeOptions?.url;
|
|
32
|
+
if (route && anyReq.raw) {
|
|
33
|
+
const ctx = getXrayContext(anyReq.raw);
|
|
34
|
+
if (ctx) {
|
|
35
|
+
setContextRoute(ctx, route);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
next();
|
|
39
|
+
}
|
|
40
|
+
);
|
|
41
|
+
}
|
|
42
|
+
export {
|
|
43
|
+
addFastifyHooks,
|
|
44
|
+
createEmitter
|
|
45
|
+
};
|
|
46
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["import type { XrayEmitter, XrayContext } from '@stainlessdev/xray-core';\nimport { createEmitter } from '@stainlessdev/xray-core';\nimport { wrapHttpHandler, getXrayContext, type WrapOptions } from '@stainlessdev/xray-node';\nimport { setContextRoute } from '@stainlessdev/xray-core/internal';\n\nexport { createEmitter };\nexport type {\n CaptureConfig,\n RedactionConfig,\n RequestLog,\n XrayConfig,\n XrayContext,\n XrayEmitter,\n} from '@stainlessdev/xray-core';\nexport type { WrapOptions } from '@stainlessdev/xray-node';\n\nexport type FastifyInstance = {\n addHook: {\n (name: 'onRequest', hook: (...args: any[]) => unknown): void;\n (name: 'preHandler', hook: (...args: any[]) => unknown): void;\n };\n};\n\nexport function addFastifyHooks(\n instance: FastifyInstance,\n xray: XrayEmitter,\n options?: WrapOptions,\n): void {\n const nodeHandler = wrapHttpHandler(() => {}, xray, {\n ...options,\n onRequest: (ctx: XrayContext) => {\n options?.onRequest?.(ctx);\n },\n });\n\n instance.addHook(\n 'onRequest',\n (request: unknown, reply: unknown, next: (err?: unknown) => void) => {\n const req = request as { raw?: Parameters<typeof nodeHandler>[0]; xray?: XrayContext };\n const res = reply as { raw?: Parameters<typeof nodeHandler>[1] };\n if (!req.raw || !res.raw) {\n next();\n return;\n }\n nodeHandler(req.raw, res.raw);\n req.xray = getXrayContext(req.raw);\n next();\n },\n );\n\n instance.addHook(\n 'preHandler',\n (request: unknown, _reply: unknown, next: (err?: unknown) => void) => {\n const anyReq = request as {\n routeOptions?: { url?: string };\n raw?: Parameters<typeof nodeHandler>[0];\n };\n const route = anyReq.routeOptions?.url;\n if (route && anyReq.raw) {\n const ctx = getXrayContext(anyReq.raw);\n if (ctx) {\n setContextRoute(ctx, route);\n }\n }\n next();\n },\n );\n}\n"],"mappings":";AACA,SAAS,qBAAqB;AAC9B,SAAS,iBAAiB,sBAAwC;AAClE,SAAS,uBAAuB;AAoBzB,SAAS,gBACd,UACA,MACA,SACM;AACN,QAAM,cAAc,gBAAgB,MAAM;AAAA,EAAC,GAAG,MAAM;AAAA,IAClD,GAAG;AAAA,IACH,WAAW,CAAC,QAAqB;AAC/B,eAAS,YAAY,GAAG;AAAA,IAC1B;AAAA,EACF,CAAC;AAED,WAAS;AAAA,IACP;AAAA,IACA,CAAC,SAAkB,OAAgB,SAAkC;AACnE,YAAM,MAAM;AACZ,YAAM,MAAM;AACZ,UAAI,CAAC,IAAI,OAAO,CAAC,IAAI,KAAK;AACxB,aAAK;AACL;AAAA,MACF;AACA,kBAAY,IAAI,KAAK,IAAI,GAAG;AAC5B,UAAI,OAAO,eAAe,IAAI,GAAG;AACjC,WAAK;AAAA,IACP;AAAA,EACF;AAEA,WAAS;AAAA,IACP;AAAA,IACA,CAAC,SAAkB,QAAiB,SAAkC;AACpE,YAAM,SAAS;AAIf,YAAM,QAAQ,OAAO,cAAc;AACnC,UAAI,SAAS,OAAO,KAAK;AACvB,cAAM,MAAM,eAAe,OAAO,GAAG;AACrC,YAAI,KAAK;AACP,0BAAgB,KAAK,KAAK;AAAA,QAC5B;AAAA,MACF;AACA,WAAK;AAAA,IACP;AAAA,EACF;AACF;","names":[]}
|
package/package.json
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@stainlessdev/xray-fastify",
|
|
3
|
+
"version": "0.1.0-branch.bg-publish-to-npm.18b1cb1",
|
|
4
|
+
"description": "Fastify integration for Stainless X-ray request logging",
|
|
5
|
+
"files": [
|
|
6
|
+
"dist"
|
|
7
|
+
],
|
|
8
|
+
"type": "module",
|
|
9
|
+
"main": "./dist/index.cjs",
|
|
10
|
+
"module": "./dist/index.js",
|
|
11
|
+
"types": "./dist/index.d.ts",
|
|
12
|
+
"exports": {
|
|
13
|
+
".": {
|
|
14
|
+
"types": "./dist/index.d.ts",
|
|
15
|
+
"import": "./dist/index.js",
|
|
16
|
+
"require": "./dist/index.cjs"
|
|
17
|
+
}
|
|
18
|
+
},
|
|
19
|
+
"publishConfig": {
|
|
20
|
+
"access": "public"
|
|
21
|
+
},
|
|
22
|
+
"dependencies": {
|
|
23
|
+
"@stainlessdev/xray-core": "0.1.0-branch.bg-publish-to-npm.18b1cb1",
|
|
24
|
+
"@stainlessdev/xray-node": "0.1.0-branch.bg-publish-to-npm.18b1cb1"
|
|
25
|
+
},
|
|
26
|
+
"devDependencies": {
|
|
27
|
+
"@opentelemetry/api": "^1.9.0",
|
|
28
|
+
"@opentelemetry/core": "^2.2.0",
|
|
29
|
+
"@opentelemetry/otlp-transformer": "^0.208.0",
|
|
30
|
+
"@opentelemetry/resources": "^2.2.0",
|
|
31
|
+
"@opentelemetry/sdk-trace-base": "^2.2.0",
|
|
32
|
+
"@opentelemetry/semantic-conventions": "^1.29.0",
|
|
33
|
+
"@types/node": "^20.11.0",
|
|
34
|
+
"fastify": "^5.6.2",
|
|
35
|
+
"oxlint": "^1.39.0",
|
|
36
|
+
"tsup": "^8.0.0",
|
|
37
|
+
"tsx": "^4.19.0",
|
|
38
|
+
"typescript": "^5.4.0"
|
|
39
|
+
},
|
|
40
|
+
"peerDependencies": {
|
|
41
|
+
"@opentelemetry/api": "^1.9.0",
|
|
42
|
+
"@opentelemetry/core": "^2.2.0",
|
|
43
|
+
"@opentelemetry/otlp-transformer": "^0.208.0",
|
|
44
|
+
"@opentelemetry/resources": "^2.2.0",
|
|
45
|
+
"@opentelemetry/sdk-trace-base": "^2.2.0",
|
|
46
|
+
"@opentelemetry/semantic-conventions": "^1.29.0",
|
|
47
|
+
"fastify": ">=5.0.0"
|
|
48
|
+
},
|
|
49
|
+
"engines": {
|
|
50
|
+
"node": ">=20"
|
|
51
|
+
},
|
|
52
|
+
"scripts": {
|
|
53
|
+
"build": "tsup",
|
|
54
|
+
"test": "tsx --test test/*.test.ts",
|
|
55
|
+
"typecheck": "tsc --noEmit",
|
|
56
|
+
"lint": "oxlint",
|
|
57
|
+
"clean": "rm -rf dist"
|
|
58
|
+
}
|
|
59
|
+
}
|