@stainlessdev/xray-hono 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 ADDED
@@ -0,0 +1,82 @@
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
+ createEmitter: () => import_xray_core.createEmitter,
24
+ createHonoMiddleware: () => createHonoMiddleware
25
+ });
26
+ module.exports = __toCommonJS(index_exports);
27
+ var import_factory = require("hono/factory");
28
+ var import_route = require("hono/route");
29
+ var import_xray_core = require("@stainlessdev/xray-core");
30
+ var import_internal = require("@stainlessdev/xray-core/internal");
31
+ var import_xray_fetch = require("@stainlessdev/xray-fetch");
32
+ function createHonoMiddleware(xray, options) {
33
+ return (0, import_factory.createMiddleware)(async (c, next) => {
34
+ const request = c.req.raw;
35
+ if (!request) {
36
+ await next();
37
+ return;
38
+ }
39
+ const wrapped = (0, import_xray_fetch.wrapFetchPreserve)(
40
+ async (req) => {
41
+ const ctx = (0, import_xray_fetch.getXrayContext)(req);
42
+ if (ctx) {
43
+ c.set("xray", ctx);
44
+ }
45
+ let route = resolveRoutePath(c, -1);
46
+ try {
47
+ await next();
48
+ return c.res;
49
+ } finally {
50
+ if (!route) {
51
+ route = resolveRoutePath(c);
52
+ }
53
+ if (route && ctx) {
54
+ (0, import_internal.setContextRoute)(ctx, route);
55
+ }
56
+ }
57
+ },
58
+ xray,
59
+ options
60
+ );
61
+ const response = await wrapped(request);
62
+ if (response instanceof Response && response !== c.res) {
63
+ c.res = response;
64
+ }
65
+ });
66
+ }
67
+ function resolveRoutePath(ctx, index) {
68
+ try {
69
+ if (index === void 0) {
70
+ return (0, import_route.routePath)(ctx);
71
+ }
72
+ return (0, import_route.routePath)(ctx, index);
73
+ } catch {
74
+ return void 0;
75
+ }
76
+ }
77
+ // Annotate the CommonJS export names for ESM import in node:
78
+ 0 && (module.exports = {
79
+ createEmitter,
80
+ createHonoMiddleware
81
+ });
82
+ //# sourceMappingURL=index.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/index.ts"],"sourcesContent":["import type { Env } from 'hono';\nimport { createMiddleware } from 'hono/factory';\nimport { routePath } from 'hono/route';\nimport type { XrayEmitter, XrayContext } from '@stainlessdev/xray-core';\nimport { createEmitter } from '@stainlessdev/xray-core';\nimport { setContextRoute } from '@stainlessdev/xray-core/internal';\nimport { getXrayContext, wrapFetchPreserve, type WrapOptions } from '@stainlessdev/xray-fetch';\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-fetch';\n\nexport type HonoXrayEnv = {\n Variables: { xray: XrayContext };\n};\n\nexport function createHonoMiddleware<E extends Env = Env>(\n xray: XrayEmitter,\n options?: WrapOptions,\n) {\n return createMiddleware<E & HonoXrayEnv>(async (c, next) => {\n const request = c.req.raw;\n if (!request) {\n await next();\n return;\n }\n\n const wrapped = wrapFetchPreserve(\n async (req) => {\n const ctx = getXrayContext(req);\n if (ctx) {\n c.set('xray', ctx);\n }\n\n let route = resolveRoutePath(c, -1);\n try {\n await next();\n return c.res;\n } finally {\n if (!route) {\n route = resolveRoutePath(c);\n }\n if (route && ctx) {\n setContextRoute(ctx, route);\n }\n }\n },\n xray,\n options,\n );\n\n const response = await wrapped(request);\n if (response instanceof Response && response !== c.res) {\n c.res = response;\n }\n });\n}\n\nfunction resolveRoutePath(ctx: unknown, index?: number): string | undefined {\n try {\n if (index === undefined) {\n return routePath(ctx as Parameters<typeof routePath>[0]);\n }\n return routePath(ctx as Parameters<typeof routePath>[0], index);\n } catch {\n return undefined;\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,qBAAiC;AACjC,mBAA0B;AAE1B,uBAA8B;AAC9B,sBAAgC;AAChC,wBAAoE;AAiB7D,SAAS,qBACd,MACA,SACA;AACA,aAAO,iCAAkC,OAAO,GAAG,SAAS;AAC1D,UAAM,UAAU,EAAE,IAAI;AACtB,QAAI,CAAC,SAAS;AACZ,YAAM,KAAK;AACX;AAAA,IACF;AAEA,UAAM,cAAU;AAAA,MACd,OAAO,QAAQ;AACb,cAAM,UAAM,kCAAe,GAAG;AAC9B,YAAI,KAAK;AACP,YAAE,IAAI,QAAQ,GAAG;AAAA,QACnB;AAEA,YAAI,QAAQ,iBAAiB,GAAG,EAAE;AAClC,YAAI;AACF,gBAAM,KAAK;AACX,iBAAO,EAAE;AAAA,QACX,UAAE;AACA,cAAI,CAAC,OAAO;AACV,oBAAQ,iBAAiB,CAAC;AAAA,UAC5B;AACA,cAAI,SAAS,KAAK;AAChB,iDAAgB,KAAK,KAAK;AAAA,UAC5B;AAAA,QACF;AAAA,MACF;AAAA,MACA;AAAA,MACA;AAAA,IACF;AAEA,UAAM,WAAW,MAAM,QAAQ,OAAO;AACtC,QAAI,oBAAoB,YAAY,aAAa,EAAE,KAAK;AACtD,QAAE,MAAM;AAAA,IACV;AAAA,EACF,CAAC;AACH;AAEA,SAAS,iBAAiB,KAAc,OAAoC;AAC1E,MAAI;AACF,QAAI,UAAU,QAAW;AACvB,iBAAO,wBAAU,GAAsC;AAAA,IACzD;AACA,eAAO,wBAAU,KAAwC,KAAK;AAAA,EAChE,QAAQ;AACN,WAAO;AAAA,EACT;AACF;","names":[]}
@@ -0,0 +1,15 @@
1
+ import * as hono from 'hono';
2
+ import { Env } from 'hono';
3
+ import { XrayContext, XrayEmitter } from '@stainlessdev/xray-core';
4
+ export { CaptureConfig, RedactionConfig, RequestLog, XrayConfig, XrayContext, XrayEmitter, createEmitter } from '@stainlessdev/xray-core';
5
+ import { WrapOptions } from '@stainlessdev/xray-fetch';
6
+ export { WrapOptions } from '@stainlessdev/xray-fetch';
7
+
8
+ type HonoXrayEnv = {
9
+ Variables: {
10
+ xray: XrayContext;
11
+ };
12
+ };
13
+ declare function createHonoMiddleware<E extends Env = Env>(xray: XrayEmitter, options?: WrapOptions): hono.MiddlewareHandler<E & HonoXrayEnv, string, {}, Response>;
14
+
15
+ export { type HonoXrayEnv, createHonoMiddleware };
@@ -0,0 +1,15 @@
1
+ import * as hono from 'hono';
2
+ import { Env } from 'hono';
3
+ import { XrayContext, XrayEmitter } from '@stainlessdev/xray-core';
4
+ export { CaptureConfig, RedactionConfig, RequestLog, XrayConfig, XrayContext, XrayEmitter, createEmitter } from '@stainlessdev/xray-core';
5
+ import { WrapOptions } from '@stainlessdev/xray-fetch';
6
+ export { WrapOptions } from '@stainlessdev/xray-fetch';
7
+
8
+ type HonoXrayEnv = {
9
+ Variables: {
10
+ xray: XrayContext;
11
+ };
12
+ };
13
+ declare function createHonoMiddleware<E extends Env = Env>(xray: XrayEmitter, options?: WrapOptions): hono.MiddlewareHandler<E & HonoXrayEnv, string, {}, Response>;
14
+
15
+ export { type HonoXrayEnv, createHonoMiddleware };
package/dist/index.js ADDED
@@ -0,0 +1,56 @@
1
+ // src/index.ts
2
+ import { createMiddleware } from "hono/factory";
3
+ import { routePath } from "hono/route";
4
+ import { createEmitter } from "@stainlessdev/xray-core";
5
+ import { setContextRoute } from "@stainlessdev/xray-core/internal";
6
+ import { getXrayContext, wrapFetchPreserve } from "@stainlessdev/xray-fetch";
7
+ function createHonoMiddleware(xray, options) {
8
+ return createMiddleware(async (c, next) => {
9
+ const request = c.req.raw;
10
+ if (!request) {
11
+ await next();
12
+ return;
13
+ }
14
+ const wrapped = wrapFetchPreserve(
15
+ async (req) => {
16
+ const ctx = getXrayContext(req);
17
+ if (ctx) {
18
+ c.set("xray", ctx);
19
+ }
20
+ let route = resolveRoutePath(c, -1);
21
+ try {
22
+ await next();
23
+ return c.res;
24
+ } finally {
25
+ if (!route) {
26
+ route = resolveRoutePath(c);
27
+ }
28
+ if (route && ctx) {
29
+ setContextRoute(ctx, route);
30
+ }
31
+ }
32
+ },
33
+ xray,
34
+ options
35
+ );
36
+ const response = await wrapped(request);
37
+ if (response instanceof Response && response !== c.res) {
38
+ c.res = response;
39
+ }
40
+ });
41
+ }
42
+ function resolveRoutePath(ctx, index) {
43
+ try {
44
+ if (index === void 0) {
45
+ return routePath(ctx);
46
+ }
47
+ return routePath(ctx, index);
48
+ } catch {
49
+ return void 0;
50
+ }
51
+ }
52
+ export {
53
+ createEmitter,
54
+ createHonoMiddleware
55
+ };
56
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/index.ts"],"sourcesContent":["import type { Env } from 'hono';\nimport { createMiddleware } from 'hono/factory';\nimport { routePath } from 'hono/route';\nimport type { XrayEmitter, XrayContext } from '@stainlessdev/xray-core';\nimport { createEmitter } from '@stainlessdev/xray-core';\nimport { setContextRoute } from '@stainlessdev/xray-core/internal';\nimport { getXrayContext, wrapFetchPreserve, type WrapOptions } from '@stainlessdev/xray-fetch';\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-fetch';\n\nexport type HonoXrayEnv = {\n Variables: { xray: XrayContext };\n};\n\nexport function createHonoMiddleware<E extends Env = Env>(\n xray: XrayEmitter,\n options?: WrapOptions,\n) {\n return createMiddleware<E & HonoXrayEnv>(async (c, next) => {\n const request = c.req.raw;\n if (!request) {\n await next();\n return;\n }\n\n const wrapped = wrapFetchPreserve(\n async (req) => {\n const ctx = getXrayContext(req);\n if (ctx) {\n c.set('xray', ctx);\n }\n\n let route = resolveRoutePath(c, -1);\n try {\n await next();\n return c.res;\n } finally {\n if (!route) {\n route = resolveRoutePath(c);\n }\n if (route && ctx) {\n setContextRoute(ctx, route);\n }\n }\n },\n xray,\n options,\n );\n\n const response = await wrapped(request);\n if (response instanceof Response && response !== c.res) {\n c.res = response;\n }\n });\n}\n\nfunction resolveRoutePath(ctx: unknown, index?: number): string | undefined {\n try {\n if (index === undefined) {\n return routePath(ctx as Parameters<typeof routePath>[0]);\n }\n return routePath(ctx as Parameters<typeof routePath>[0], index);\n } catch {\n return undefined;\n }\n}\n"],"mappings":";AACA,SAAS,wBAAwB;AACjC,SAAS,iBAAiB;AAE1B,SAAS,qBAAqB;AAC9B,SAAS,uBAAuB;AAChC,SAAS,gBAAgB,yBAA2C;AAiB7D,SAAS,qBACd,MACA,SACA;AACA,SAAO,iBAAkC,OAAO,GAAG,SAAS;AAC1D,UAAM,UAAU,EAAE,IAAI;AACtB,QAAI,CAAC,SAAS;AACZ,YAAM,KAAK;AACX;AAAA,IACF;AAEA,UAAM,UAAU;AAAA,MACd,OAAO,QAAQ;AACb,cAAM,MAAM,eAAe,GAAG;AAC9B,YAAI,KAAK;AACP,YAAE,IAAI,QAAQ,GAAG;AAAA,QACnB;AAEA,YAAI,QAAQ,iBAAiB,GAAG,EAAE;AAClC,YAAI;AACF,gBAAM,KAAK;AACX,iBAAO,EAAE;AAAA,QACX,UAAE;AACA,cAAI,CAAC,OAAO;AACV,oBAAQ,iBAAiB,CAAC;AAAA,UAC5B;AACA,cAAI,SAAS,KAAK;AAChB,4BAAgB,KAAK,KAAK;AAAA,UAC5B;AAAA,QACF;AAAA,MACF;AAAA,MACA;AAAA,MACA;AAAA,IACF;AAEA,UAAM,WAAW,MAAM,QAAQ,OAAO;AACtC,QAAI,oBAAoB,YAAY,aAAa,EAAE,KAAK;AACtD,QAAE,MAAM;AAAA,IACV;AAAA,EACF,CAAC;AACH;AAEA,SAAS,iBAAiB,KAAc,OAAoC;AAC1E,MAAI;AACF,QAAI,UAAU,QAAW;AACvB,aAAO,UAAU,GAAsC;AAAA,IACzD;AACA,WAAO,UAAU,KAAwC,KAAK;AAAA,EAChE,QAAQ;AACN,WAAO;AAAA,EACT;AACF;","names":[]}
package/package.json ADDED
@@ -0,0 +1,60 @@
1
+ {
2
+ "name": "@stainlessdev/xray-hono",
3
+ "version": "0.1.0-branch.bg-publish-to-npm.18b1cb1",
4
+ "description": "Hono 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-fetch": "0.1.0-branch.bg-publish-to-npm.18b1cb1"
25
+ },
26
+ "devDependencies": {
27
+ "@hono/node-server": "^1.19.8",
28
+ "@opentelemetry/api": "^1.9.0",
29
+ "@opentelemetry/core": "^2.2.0",
30
+ "@opentelemetry/otlp-transformer": "^0.208.0",
31
+ "@opentelemetry/resources": "^2.2.0",
32
+ "@opentelemetry/sdk-trace-base": "^2.2.0",
33
+ "@opentelemetry/semantic-conventions": "^1.29.0",
34
+ "@types/node": "^20.11.0",
35
+ "hono": "^4.11.4",
36
+ "oxlint": "^1.39.0",
37
+ "tsup": "^8.0.0",
38
+ "tsx": "^4.19.0",
39
+ "typescript": "^5.4.0"
40
+ },
41
+ "peerDependencies": {
42
+ "@opentelemetry/api": "^1.9.0",
43
+ "@opentelemetry/core": "^2.2.0",
44
+ "@opentelemetry/otlp-transformer": "^0.208.0",
45
+ "@opentelemetry/resources": "^2.2.0",
46
+ "@opentelemetry/sdk-trace-base": "^2.2.0",
47
+ "@opentelemetry/semantic-conventions": "^1.29.0",
48
+ "hono": ">=4.8.0"
49
+ },
50
+ "engines": {
51
+ "node": ">=20"
52
+ },
53
+ "scripts": {
54
+ "build": "tsup",
55
+ "test": "tsx --test test/*.test.ts",
56
+ "typecheck": "tsc --noEmit",
57
+ "lint": "oxlint",
58
+ "clean": "rm -rf dist"
59
+ }
60
+ }