@stainlessdev/xray-fastify 0.1.0-branch.bg-publish-to-npm.18b1cb1 → 0.1.0-branch.bg-fix-examples.3b7695a
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 +12 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +8 -3
- package/dist/index.d.ts +8 -3
- package/dist/index.js +11 -1
- package/dist/index.js.map +1 -1
- package/package.json +3 -3
package/dist/index.cjs
CHANGED
|
@@ -21,12 +21,22 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
21
21
|
var index_exports = {};
|
|
22
22
|
__export(index_exports, {
|
|
23
23
|
addFastifyHooks: () => addFastifyHooks,
|
|
24
|
-
|
|
24
|
+
createCoreEmitter: () => import_xray_core.createEmitter,
|
|
25
|
+
createEmitter: () => createEmitter
|
|
25
26
|
});
|
|
26
27
|
module.exports = __toCommonJS(index_exports);
|
|
27
28
|
var import_xray_core = require("@stainlessdev/xray-core");
|
|
28
29
|
var import_xray_node = require("@stainlessdev/xray-node");
|
|
29
30
|
var import_internal = require("@stainlessdev/xray-core/internal");
|
|
31
|
+
function createEmitter(config, options) {
|
|
32
|
+
const emitter = (0, import_xray_core.createEmitter)(config);
|
|
33
|
+
const register = ((instance) => {
|
|
34
|
+
addFastifyHooks(instance, emitter, options);
|
|
35
|
+
});
|
|
36
|
+
register.flush = emitter.flush;
|
|
37
|
+
register.shutdown = emitter.shutdown;
|
|
38
|
+
return register;
|
|
39
|
+
}
|
|
30
40
|
function addFastifyHooks(instance, xray, options) {
|
|
31
41
|
const nodeHandler = (0, import_xray_node.wrapHttpHandler)(() => {
|
|
32
42
|
}, xray, {
|
|
@@ -67,6 +77,7 @@ function addFastifyHooks(instance, xray, options) {
|
|
|
67
77
|
// Annotate the CommonJS export names for ESM import in node:
|
|
68
78
|
0 && (module.exports = {
|
|
69
79
|
addFastifyHooks,
|
|
80
|
+
createCoreEmitter,
|
|
70
81
|
createEmitter
|
|
71
82
|
});
|
|
72
83
|
//# sourceMappingURL=index.cjs.map
|
package/dist/index.cjs.map
CHANGED
|
@@ -1 +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 {
|
|
1
|
+
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["import type { XrayEmitter, XrayContext, XrayConfig } from '@stainlessdev/xray-core';\nimport { createEmitter as createCoreEmitter } from '@stainlessdev/xray-core';\nimport { wrapHttpHandler, getXrayContext, type WrapOptions } from '@stainlessdev/xray-node';\nimport { setContextRoute } from '@stainlessdev/xray-core/internal';\n\nexport { createCoreEmitter };\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 type FastifyEmitter = ((instance: FastifyInstance) => void) & {\n flush: XrayEmitter['flush'];\n shutdown: XrayEmitter['shutdown'];\n};\n\nexport function createEmitter(config: XrayConfig, options?: WrapOptions): FastifyEmitter {\n const emitter = createCoreEmitter(config);\n const register = ((instance: FastifyInstance) => {\n addFastifyHooks(instance, emitter, options);\n }) as FastifyEmitter;\n register.flush = emitter.flush;\n register.shutdown = emitter.shutdown;\n return register;\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,4CAAAA;AAAA,EAAA;AAAA;AAAA;AACA,uBAAmD;AACnD,uBAAkE;AAClE,sBAAgC;AAyBzB,SAAS,cAAc,QAAoB,SAAuC;AACvF,QAAM,cAAU,iBAAAC,eAAkB,MAAM;AACxC,QAAM,YAAY,CAAC,aAA8B;AAC/C,oBAAgB,UAAU,SAAS,OAAO;AAAA,EAC5C;AACA,WAAS,QAAQ,QAAQ;AACzB,WAAS,WAAW,QAAQ;AAC5B,SAAO;AACT;AAEO,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":["createCoreEmitter","createCoreEmitter"]}
|
package/dist/index.d.cts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { XrayEmitter } from '@stainlessdev/xray-core';
|
|
2
|
-
export { CaptureConfig, RedactionConfig, RequestLog, XrayConfig, XrayContext, XrayEmitter, createEmitter } from '@stainlessdev/xray-core';
|
|
1
|
+
import { XrayEmitter, XrayConfig } from '@stainlessdev/xray-core';
|
|
2
|
+
export { CaptureConfig, RedactionConfig, RequestLog, XrayConfig, XrayContext, XrayEmitter, createEmitter as createCoreEmitter } from '@stainlessdev/xray-core';
|
|
3
3
|
import { WrapOptions } from '@stainlessdev/xray-node';
|
|
4
4
|
export { WrapOptions } from '@stainlessdev/xray-node';
|
|
5
5
|
|
|
@@ -9,6 +9,11 @@ type FastifyInstance = {
|
|
|
9
9
|
(name: 'preHandler', hook: (...args: any[]) => unknown): void;
|
|
10
10
|
};
|
|
11
11
|
};
|
|
12
|
+
type FastifyEmitter = ((instance: FastifyInstance) => void) & {
|
|
13
|
+
flush: XrayEmitter['flush'];
|
|
14
|
+
shutdown: XrayEmitter['shutdown'];
|
|
15
|
+
};
|
|
16
|
+
declare function createEmitter(config: XrayConfig, options?: WrapOptions): FastifyEmitter;
|
|
12
17
|
declare function addFastifyHooks(instance: FastifyInstance, xray: XrayEmitter, options?: WrapOptions): void;
|
|
13
18
|
|
|
14
|
-
export { type FastifyInstance, addFastifyHooks };
|
|
19
|
+
export { type FastifyEmitter, type FastifyInstance, addFastifyHooks, createEmitter };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { XrayEmitter } from '@stainlessdev/xray-core';
|
|
2
|
-
export { CaptureConfig, RedactionConfig, RequestLog, XrayConfig, XrayContext, XrayEmitter, createEmitter } from '@stainlessdev/xray-core';
|
|
1
|
+
import { XrayEmitter, XrayConfig } from '@stainlessdev/xray-core';
|
|
2
|
+
export { CaptureConfig, RedactionConfig, RequestLog, XrayConfig, XrayContext, XrayEmitter, createEmitter as createCoreEmitter } from '@stainlessdev/xray-core';
|
|
3
3
|
import { WrapOptions } from '@stainlessdev/xray-node';
|
|
4
4
|
export { WrapOptions } from '@stainlessdev/xray-node';
|
|
5
5
|
|
|
@@ -9,6 +9,11 @@ type FastifyInstance = {
|
|
|
9
9
|
(name: 'preHandler', hook: (...args: any[]) => unknown): void;
|
|
10
10
|
};
|
|
11
11
|
};
|
|
12
|
+
type FastifyEmitter = ((instance: FastifyInstance) => void) & {
|
|
13
|
+
flush: XrayEmitter['flush'];
|
|
14
|
+
shutdown: XrayEmitter['shutdown'];
|
|
15
|
+
};
|
|
16
|
+
declare function createEmitter(config: XrayConfig, options?: WrapOptions): FastifyEmitter;
|
|
12
17
|
declare function addFastifyHooks(instance: FastifyInstance, xray: XrayEmitter, options?: WrapOptions): void;
|
|
13
18
|
|
|
14
|
-
export { type FastifyInstance, addFastifyHooks };
|
|
19
|
+
export { type FastifyEmitter, type FastifyInstance, addFastifyHooks, createEmitter };
|
package/dist/index.js
CHANGED
|
@@ -1,7 +1,16 @@
|
|
|
1
1
|
// src/index.ts
|
|
2
|
-
import { createEmitter } from "@stainlessdev/xray-core";
|
|
2
|
+
import { createEmitter as createCoreEmitter } from "@stainlessdev/xray-core";
|
|
3
3
|
import { wrapHttpHandler, getXrayContext } from "@stainlessdev/xray-node";
|
|
4
4
|
import { setContextRoute } from "@stainlessdev/xray-core/internal";
|
|
5
|
+
function createEmitter(config, options) {
|
|
6
|
+
const emitter = createCoreEmitter(config);
|
|
7
|
+
const register = ((instance) => {
|
|
8
|
+
addFastifyHooks(instance, emitter, options);
|
|
9
|
+
});
|
|
10
|
+
register.flush = emitter.flush;
|
|
11
|
+
register.shutdown = emitter.shutdown;
|
|
12
|
+
return register;
|
|
13
|
+
}
|
|
5
14
|
function addFastifyHooks(instance, xray, options) {
|
|
6
15
|
const nodeHandler = wrapHttpHandler(() => {
|
|
7
16
|
}, xray, {
|
|
@@ -41,6 +50,7 @@ function addFastifyHooks(instance, xray, options) {
|
|
|
41
50
|
}
|
|
42
51
|
export {
|
|
43
52
|
addFastifyHooks,
|
|
53
|
+
createCoreEmitter,
|
|
44
54
|
createEmitter
|
|
45
55
|
};
|
|
46
56
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +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 {
|
|
1
|
+
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["import type { XrayEmitter, XrayContext, XrayConfig } from '@stainlessdev/xray-core';\nimport { createEmitter as createCoreEmitter } from '@stainlessdev/xray-core';\nimport { wrapHttpHandler, getXrayContext, type WrapOptions } from '@stainlessdev/xray-node';\nimport { setContextRoute } from '@stainlessdev/xray-core/internal';\n\nexport { createCoreEmitter };\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 type FastifyEmitter = ((instance: FastifyInstance) => void) & {\n flush: XrayEmitter['flush'];\n shutdown: XrayEmitter['shutdown'];\n};\n\nexport function createEmitter(config: XrayConfig, options?: WrapOptions): FastifyEmitter {\n const emitter = createCoreEmitter(config);\n const register = ((instance: FastifyInstance) => {\n addFastifyHooks(instance, emitter, options);\n }) as FastifyEmitter;\n register.flush = emitter.flush;\n register.shutdown = emitter.shutdown;\n return register;\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,iBAAiB,yBAAyB;AACnD,SAAS,iBAAiB,sBAAwC;AAClE,SAAS,uBAAuB;AAyBzB,SAAS,cAAc,QAAoB,SAAuC;AACvF,QAAM,UAAU,kBAAkB,MAAM;AACxC,QAAM,YAAY,CAAC,aAA8B;AAC/C,oBAAgB,UAAU,SAAS,OAAO;AAAA,EAC5C;AACA,WAAS,QAAQ,QAAQ;AACzB,WAAS,WAAW,QAAQ;AAC5B,SAAO;AACT;AAEO,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
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@stainlessdev/xray-fastify",
|
|
3
|
-
"version": "0.1.0-branch.bg-
|
|
3
|
+
"version": "0.1.0-branch.bg-fix-examples.3b7695a",
|
|
4
4
|
"description": "Fastify integration for Stainless X-ray request logging",
|
|
5
5
|
"files": [
|
|
6
6
|
"dist"
|
|
@@ -20,8 +20,8 @@
|
|
|
20
20
|
"access": "public"
|
|
21
21
|
},
|
|
22
22
|
"dependencies": {
|
|
23
|
-
"@stainlessdev/xray-core": "0.1.0-branch.bg-
|
|
24
|
-
"@stainlessdev/xray-node": "0.1.0-branch.bg-
|
|
23
|
+
"@stainlessdev/xray-core": "0.1.0-branch.bg-fix-examples.3b7695a",
|
|
24
|
+
"@stainlessdev/xray-node": "0.1.0-branch.bg-fix-examples.3b7695a"
|
|
25
25
|
},
|
|
26
26
|
"devDependencies": {
|
|
27
27
|
"@opentelemetry/api": "^1.9.0",
|