UNPKG

apitally

Version:

Simple API monitoring & analytics for REST APIs built with Express, Fastify, NestJS, AdonisJS, Hono, H3, Elysia, Hapi, and Koa.

1 lines 3.3 kB
{"version":3,"sources":["../../src/hapi/utils.ts","../../src/common/packageVersions.ts"],"sourcesContent":["import type { Boom } from \"@hapi/boom\";\nimport type { RequestRoute, ResponseObject, Server } from \"@hapi/hapi\";\n\nimport { getPackageVersion } from \"../common/packageVersions.js\";\nimport type { StartupData } from \"../common/types.js\";\n\nexport function getAppInfo(server: Server, appVersion?: string): StartupData {\n const versions: Array<[string, string]> = [];\n if (process.versions.node) {\n versions.push([\"nodejs\", process.versions.node]);\n }\n const hapiVersion = getPackageVersion(\"@hapi/hapi\");\n const apitallyVersion = getPackageVersion(\"../..\");\n if (hapiVersion) {\n versions.push([\"hapi\", hapiVersion]);\n }\n if (apitallyVersion) {\n versions.push([\"apitally\", apitallyVersion]);\n }\n if (appVersion) {\n versions.push([\"app\", appVersion]);\n }\n\n return {\n paths: server\n .table()\n .map((route: RequestRoute) => ({\n method: route.method.toUpperCase(),\n path: route.path,\n }))\n .filter(\n (route) =>\n route.method &&\n route.path &&\n ![\"HEAD\", \"OPTIONS\"].includes(route.method),\n ),\n versions: Object.fromEntries(versions),\n client: \"js:hapi\",\n };\n}\n\nexport function isBoom(response: ResponseObject | Boom): response is Boom {\n return \"isBoom\" in response && response.isBoom === true;\n}\n","import { createRequire } from \"node:module\";\n\nexport function getPackageVersion(name: string): string | null {\n const packageJsonPath = `${name}/package.json`;\n try {\n return require(packageJsonPath).version || null;\n } catch (error) {\n try {\n const _require = createRequire(import.meta.url);\n return _require(packageJsonPath).version || null;\n } catch (error) {\n return null;\n }\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAGA;;;;;;;;ACHA,yBAA8B;AAA9B;AAEO,SAASA,kBAAkBC,MAAY;AAC5C,QAAMC,kBAAkB,GAAGD,IAAAA;AAC3B,MAAI;AACF,WAAOE,QAAQD,eAAAA,EAAiBE,WAAW;EAC7C,SAASC,OAAO;AACd,QAAI;AACF,YAAMC,eAAWC,kCAAc,YAAYC,GAAG;AAC9C,aAAOF,SAASJ,eAAAA,EAAiBE,WAAW;IAC9C,SAASC,QAAO;AACd,aAAO;IACT;EACF;AACF;AAZgBL;;;ADIT,SAASS,WAAWC,QAAgBC,YAAmB;AAC5D,QAAMC,WAAoC,CAAA;AAC1C,MAAIC,QAAQD,SAASE,MAAM;AACzBF,aAASG,KAAK;MAAC;MAAUF,QAAQD,SAASE;KAAK;EACjD;AACA,QAAME,cAAcC,kBAAkB,YAAA;AACtC,QAAMC,kBAAkBD,kBAAkB,OAAA;AAC1C,MAAID,aAAa;AACfJ,aAASG,KAAK;MAAC;MAAQC;KAAY;EACrC;AACA,MAAIE,iBAAiB;AACnBN,aAASG,KAAK;MAAC;MAAYG;KAAgB;EAC7C;AACA,MAAIP,YAAY;AACdC,aAASG,KAAK;MAAC;MAAOJ;KAAW;EACnC;AAEA,SAAO;IACLQ,OAAOT,OACJU,MAAK,EACLC,IAAI,CAACC,WAAyB;MAC7BC,QAAQD,MAAMC,OAAOC,YAAW;MAChCC,MAAMH,MAAMG;IACd,EAAA,EACCC,OACC,CAACJ,UACCA,MAAMC,UACND,MAAMG,QACN,CAAC;MAAC;MAAQ;MAAWE,SAASL,MAAMC,MAAM,CAAA;IAEhDX,UAAUgB,OAAOC,YAAYjB,QAAAA;IAC7BkB,QAAQ;EACV;AACF;AAjCgBrB;AAmCT,SAASsB,OAAOC,UAA+B;AACpD,SAAO,YAAYA,YAAYA,SAASD,WAAW;AACrD;AAFgBA;","names":["getPackageVersion","name","packageJsonPath","require","version","error","_require","createRequire","url","getAppInfo","server","appVersion","versions","process","node","push","hapiVersion","getPackageVersion","apitallyVersion","paths","table","map","route","method","toUpperCase","path","filter","includes","Object","fromEntries","client","isBoom","response"]}