@webpieces/http-routing 0.4.413 → 0.4.414

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@webpieces/http-routing",
3
- "version": "0.4.413",
3
+ "version": "0.4.414",
4
4
  "description": "Decorator-based routing with auto-wiring for WebPieces",
5
5
  "type": "commonjs",
6
6
  "main": "./src/index.js",
@@ -22,9 +22,9 @@
22
22
  },
23
23
  "dependencies": {
24
24
  "@inversifyjs/binding-decorators": "1.1.5",
25
- "@webpieces/core-context": "0.4.413",
26
- "@webpieces/core-util": "0.4.413",
27
- "@webpieces/gcp-identity": "0.4.413",
25
+ "@webpieces/core-context": "0.4.414",
26
+ "@webpieces/core-util": "0.4.414",
27
+ "@webpieces/gcp-identity": "0.4.414",
28
28
  "inversify": "7.10.4",
29
29
  "jsonwebtoken": "9.0.2",
30
30
  "minimatch": "10.0.1"
@@ -14,6 +14,13 @@ import { ApiFactory } from './ApiFactory';
14
14
  * `platformHeaders` is true) plus AppModules.getHeaders() (by convention the company-wide set).
15
15
  */
16
16
  export declare class RuntimeSetupOptions {
17
+ /** This service's name — published to ServiceInfo. Names every log line and stamps
18
+ * `requestIdSource` on request-ids this service mints. Must be non-blank. */
19
+ readonly svcName: string;
20
+ /** This build's version — published to ServiceInfo alongside svcName. Opaque to webpieces
21
+ * (a git SHA, a semver tag, a CI build number); it just has to identify THIS build so a log
22
+ * line can say which one emitted it. Must be non-blank. */
23
+ readonly svcVersion: string;
17
24
  /** Logging backend to install (LogManager.setFactory). */
18
25
  readonly loggerFactory: LoggerFactory;
19
26
  /** Include the webpieces platform default headers. */
@@ -21,6 +28,13 @@ export declare class RuntimeSetupOptions {
21
28
  /** Optional WebpiecesConfig (e.g. recording flags); defaults to a fresh one. */
22
29
  readonly config?: WebpiecesConfig | undefined;
23
30
  constructor(
31
+ /** This service's name — published to ServiceInfo. Names every log line and stamps
32
+ * `requestIdSource` on request-ids this service mints. Must be non-blank. */
33
+ svcName: string,
34
+ /** This build's version — published to ServiceInfo alongside svcName. Opaque to webpieces
35
+ * (a git SHA, a semver tag, a CI build number); it just has to identify THIS build so a log
36
+ * line can say which one emitted it. Must be non-blank. */
37
+ svcVersion: string,
24
38
  /** Logging backend to install (LogManager.setFactory). */
25
39
  loggerFactory: LoggerFactory,
26
40
  /** Include the webpieces platform default headers. */
@@ -17,16 +17,27 @@ const WebpiecesRouter_1 = require("./WebpiecesRouter");
17
17
  * `platformHeaders` is true) plus AppModules.getHeaders() (by convention the company-wide set).
18
18
  */
19
19
  class RuntimeSetupOptions {
20
+ svcName;
21
+ svcVersion;
20
22
  loggerFactory;
21
23
  platformHeaders;
22
24
  config;
23
25
  constructor(
26
+ /** This service's name — published to ServiceInfo. Names every log line and stamps
27
+ * `requestIdSource` on request-ids this service mints. Must be non-blank. */
28
+ svcName,
29
+ /** This build's version — published to ServiceInfo alongside svcName. Opaque to webpieces
30
+ * (a git SHA, a semver tag, a CI build number); it just has to identify THIS build so a log
31
+ * line can say which one emitted it. Must be non-blank. */
32
+ svcVersion,
24
33
  /** Logging backend to install (LogManager.setFactory). */
25
34
  loggerFactory,
26
35
  /** Include the webpieces platform default headers. */
27
36
  platformHeaders = true,
28
37
  /** Optional WebpiecesConfig (e.g. recording flags); defaults to a fresh one. */
29
38
  config) {
39
+ this.svcName = svcName;
40
+ this.svcVersion = svcVersion;
30
41
  this.loggerFactory = loggerFactory;
31
42
  this.platformHeaders = platformHeaders;
32
43
  this.config = config;
@@ -51,12 +62,13 @@ async function setupRuntime(options, appModules,
51
62
  /** A single DI module loaded LAST so tests can rebind bindings to mocks.
52
63
  * Or special case servers that want to override specific things */
53
64
  appOverrides) {
54
- // 0. This service must be IDENTIFIED (name + build version). The logging backends and the request
55
- // path READ ServiceInfo without throwing (a missing log field must never 500 live traffic, and
56
- // logging must work before setInfo). So the "a deployed build must say which build it is"
57
- // guarantee is enforced HERE instead the one startup every server runs so a forgotten
58
- // setInfo kills the deploy (the revision never goes healthy) rather than shipping anonymous logs.
59
- core_util_1.ServiceInfo.assertIdentified();
65
+ // 0. IDENTIFY this service (name + build version) FIRST, before anything logs. Name and version
66
+ // are REQUIRED inputs to this call, so a build cannot boot anonymously setInfo throws on a
67
+ // blank value, which kills the deploy (the revision never goes healthy) rather than shipping logs
68
+ // that cannot say which build emitted them. Reads of ServiceInfo elsewhere never throw (a missing
69
+ // log field must never 500 live traffic); the "say which build you are" guarantee lives HERE, the
70
+ // one startup every server runs.
71
+ core_util_1.ServiceInfo.setInfo(options.svcName, options.svcVersion);
60
72
  // 1. Register the global HeaderRegistry FIRST (this service's own keys come from AppModules).
61
73
  core_util_1.HeaderRegistry.configure(appModules.getHeaders(), options.platformHeaders);
62
74
  // 2. Install the logging backend ONCE, before anything else logs.
@@ -1 +1 @@
1
- {"version":3,"file":"setupRuntime.js","sourceRoot":"","sources":["../../../../../packages/http/http-routing/src/setupRuntime.ts"],"names":[],"mappings":";;;AA2CA,oCAqCC;AA/ED,oDAAoH;AACpH,0DAAuE;AACvE,uDAAoD;AACpD,uDAA2D;AAI3D;;;;;;;;;GASG;AACH,MAAa,mBAAmB;IAGR;IAEA;IAEA;IANpB;IACI,0DAA0D;IAC1C,aAA4B;IAC5C,sDAAsD;IACtC,kBAA2B,IAAI;IAC/C,gFAAgF;IAChE,MAAwB;QAJxB,kBAAa,GAAb,aAAa,CAAe;QAE5B,oBAAe,GAAf,eAAe,CAAgB;QAE/B,WAAM,GAAN,MAAM,CAAkB;IACzC,CAAC;CACP;AATD,kDASC;AAED;;;;;;;;;;;;;GAaG;AACI,KAAK,UAAU,YAAY,CAC9B,OAA4B,EAC5B,UAAsB;AACtB;mEACmE;AACnE,YAA8B;IAE9B,kGAAkG;IAClG,+FAA+F;IAC/F,0FAA0F;IAC1F,0FAA0F;IAC1F,kGAAkG;IAClG,uBAAW,CAAC,gBAAgB,EAAE,CAAC;IAE/B,8FAA8F;IAC9F,0BAAc,CAAC,SAAS,CAAC,UAAU,CAAC,UAAU,EAAE,EAAE,OAAO,CAAC,eAAe,CAAC,CAAC;IAE3E,kEAAkE;IAClE,sBAAU,CAAC,UAAU,CAAC,OAAO,CAAC,aAAa,CAAC,CAAC;IAE7C,kGAAkG;IAClG,8FAA8F;IAC9F,kGAAkG;IAClG,gCAAoB,CAAC,OAAO,CAAC,IAAI,2CAA4B,EAAE,CAAC,CAAC;IAEjE,gDAAgD;IAChD,MAAM,MAAM,GAAG,MAAM,wCAAsB,CAAC,MAAM,CAAC;QAC/C,WAAW,EAAE,CAAC,GAAG,UAAU,CAAC,iBAAiB,EAAE,CAAC;QAChD,YAAY,EAAE,YAAY;QAC1B,MAAM,EAAE,OAAO,CAAC,MAAM,IAAI,IAAI,iCAAe,EAAE;KAClD,CAAC,CAAC;IAEH,6FAA6F;IAC7F,KAAK,MAAM,WAAW,IAAI,UAAU,CAAC,iBAAiB,EAAE,EAAE,CAAC;QACvD,WAAW,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC;IAClC,CAAC;IACD,OAAO,MAAM,CAAC;AAClB,CAAC","sourcesContent":["import { ContainerModule } from 'inversify';\nimport { ApiCallContextHolder, HeaderRegistry, LoggerFactory, LogManager, ServiceInfo } from '@webpieces/core-util';\nimport { RequestContextApiCallContext } from '@webpieces/core-context';\nimport { WebpiecesConfig } from './WebpiecesConfig';\nimport { WebpiecesRouterFactory } from './WebpiecesRouter';\nimport { AppModules } from './AppModules';\nimport { ApiFactory } from './ApiFactory';\n\n/**\n * RuntimeSetupOptions - the environment/wiring inputs to {@link setupRuntime} (everything NOT\n * declared by the app's {@link AppModules}): the logging backend, whether to include the platform\n * default headers, and config. Data-only structure (a class, per the webpieces guidelines). The\n * app's own binding modules + route groups + headers come from the AppModules passed alongside;\n * the test-override module is the separate `appOverrides` param of {@link setupRuntime}.\n *\n * Headers: {@link HeaderRegistry.configure} registers the platform defaults (when\n * `platformHeaders` is true) plus AppModules.getHeaders() (by convention the company-wide set).\n */\nexport class RuntimeSetupOptions {\n constructor(\n /** Logging backend to install (LogManager.setFactory). */\n public readonly loggerFactory: LoggerFactory,\n /** Include the webpieces platform default headers. */\n public readonly platformHeaders: boolean = true,\n /** Optional WebpiecesConfig (e.g. recording flags); defaults to a fresh one. */\n public readonly config?: WebpiecesConfig,\n ) {}\n}\n\n/**\n * setupRuntime - the ONE canonical, TRANSPORT-FREE startup sequence, reusable by any company/app\n * AND any framework adapter (express, fastify, a serverless handler, ...). It runs, in the correct\n * fail-fast order:\n *\n * 1. HeaderRegistry.configure (filters read it at construction; logging masks off it)\n * 2. LogManager.setFactory (fails fast unless the registry is configured first)\n * 3. build the router + DI container (from appModules.getBindingModules())\n * 4. configure each appModules.getRoutingModules() onto the router (addRoutes/addFilter)\n *\n * and returns the built {@link ApiFactory} — `apiClients()` for a transport to bind, or\n * `createApiClient()` for in-process tests. There is NO express (or any transport) here; a\n * transport adapter (e.g. WebpiecesExpressRouter in @webpieces/http-server) serves the result.\n */\nexport async function setupRuntime(\n options: RuntimeSetupOptions,\n appModules: AppModules,\n /** A single DI module loaded LAST so tests can rebind bindings to mocks.\n * Or special case servers that want to override specific things */\n appOverrides?: ContainerModule,\n): Promise<ApiFactory> {\n // 0. This service must be IDENTIFIED (name + build version). The logging backends and the request\n // path READ ServiceInfo without throwing (a missing log field must never 500 live traffic, and\n // logging must work before setInfo). So the \"a deployed build must say which build it is\"\n // guarantee is enforced HERE instead the one startup every server runs so a forgotten\n // setInfo kills the deploy (the revision never goes healthy) rather than shipping anonymous logs.\n ServiceInfo.assertIdentified();\n\n // 1. Register the global HeaderRegistry FIRST (this service's own keys come from AppModules).\n HeaderRegistry.configure(appModules.getHeaders(), options.platformHeaders);\n\n // 2. Install the logging backend ONCE, before anything else logs.\n LogManager.setFactory(options.loggerFactory);\n\n // 2b. Bind the SERVER ApiCallContext so LogApiCall (browser-safe core-util) stamps the structured\n // `api` tag into the real RequestContext. Installed here — the one startup that runs on EVERY\n // server — so both inbound (LogApiFilter) and outbound (clients) log lines carry jsonPayload.api.\n ApiCallContextHolder.install(new RequestContextApiCallContext());\n\n // 3. Build the node-only router + DI container.\n const router = await WebpiecesRouterFactory.create({\n appBindings: [...appModules.getBindingModules()],\n appOverrides: appOverrides,\n config: options.config ?? new WebpiecesConfig(),\n });\n\n // 4. Let each route group declare its routes + filters, then hand back the consumer surface.\n for (const routeModule of appModules.getRoutingModules()) {\n routeModule.configure(router);\n }\n return router;\n}\n"]}
1
+ {"version":3,"file":"setupRuntime.js","sourceRoot":"","sources":["../../../../../packages/http/http-routing/src/setupRuntime.ts"],"names":[],"mappings":";;;AAkDA,oCAsCC;AAvFD,oDAAoH;AACpH,0DAAuE;AACvE,uDAAoD;AACpD,uDAA2D;AAI3D;;;;;;;;;GASG;AACH,MAAa,mBAAmB;IAIR;IAIA;IAEA;IAEA;IAEA;IAbpB;IACI;iFAC6E;IAC7D,OAAe;IAC/B;;+DAE2D;IAC3C,UAAkB;IAClC,0DAA0D;IAC1C,aAA4B;IAC5C,sDAAsD;IACtC,kBAA2B,IAAI;IAC/C,gFAAgF;IAChE,MAAwB;QAVxB,YAAO,GAAP,OAAO,CAAQ;QAIf,eAAU,GAAV,UAAU,CAAQ;QAElB,kBAAa,GAAb,aAAa,CAAe;QAE5B,oBAAe,GAAf,eAAe,CAAgB;QAE/B,WAAM,GAAN,MAAM,CAAkB;IACzC,CAAC;CACP;AAhBD,kDAgBC;AAED;;;;;;;;;;;;;GAaG;AACI,KAAK,UAAU,YAAY,CAC9B,OAA4B,EAC5B,UAAsB;AACtB;mEACmE;AACnE,YAA8B;IAE9B,gGAAgG;IAChG,6FAA6F;IAC7F,kGAAkG;IAClG,kGAAkG;IAClG,kGAAkG;IAClG,iCAAiC;IACjC,uBAAW,CAAC,OAAO,CAAC,OAAO,CAAC,OAAO,EAAE,OAAO,CAAC,UAAU,CAAC,CAAC;IAEzD,8FAA8F;IAC9F,0BAAc,CAAC,SAAS,CAAC,UAAU,CAAC,UAAU,EAAE,EAAE,OAAO,CAAC,eAAe,CAAC,CAAC;IAE3E,kEAAkE;IAClE,sBAAU,CAAC,UAAU,CAAC,OAAO,CAAC,aAAa,CAAC,CAAC;IAE7C,kGAAkG;IAClG,8FAA8F;IAC9F,kGAAkG;IAClG,gCAAoB,CAAC,OAAO,CAAC,IAAI,2CAA4B,EAAE,CAAC,CAAC;IAEjE,gDAAgD;IAChD,MAAM,MAAM,GAAG,MAAM,wCAAsB,CAAC,MAAM,CAAC;QAC/C,WAAW,EAAE,CAAC,GAAG,UAAU,CAAC,iBAAiB,EAAE,CAAC;QAChD,YAAY,EAAE,YAAY;QAC1B,MAAM,EAAE,OAAO,CAAC,MAAM,IAAI,IAAI,iCAAe,EAAE;KAClD,CAAC,CAAC;IAEH,6FAA6F;IAC7F,KAAK,MAAM,WAAW,IAAI,UAAU,CAAC,iBAAiB,EAAE,EAAE,CAAC;QACvD,WAAW,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC;IAClC,CAAC;IACD,OAAO,MAAM,CAAC;AAClB,CAAC","sourcesContent":["import { ContainerModule } from 'inversify';\nimport { ApiCallContextHolder, HeaderRegistry, LoggerFactory, LogManager, ServiceInfo } from '@webpieces/core-util';\nimport { RequestContextApiCallContext } from '@webpieces/core-context';\nimport { WebpiecesConfig } from './WebpiecesConfig';\nimport { WebpiecesRouterFactory } from './WebpiecesRouter';\nimport { AppModules } from './AppModules';\nimport { ApiFactory } from './ApiFactory';\n\n/**\n * RuntimeSetupOptions - the environment/wiring inputs to {@link setupRuntime} (everything NOT\n * declared by the app's {@link AppModules}): the logging backend, whether to include the platform\n * default headers, and config. Data-only structure (a class, per the webpieces guidelines). The\n * app's own binding modules + route groups + headers come from the AppModules passed alongside;\n * the test-override module is the separate `appOverrides` param of {@link setupRuntime}.\n *\n * Headers: {@link HeaderRegistry.configure} registers the platform defaults (when\n * `platformHeaders` is true) plus AppModules.getHeaders() (by convention the company-wide set).\n */\nexport class RuntimeSetupOptions {\n constructor(\n /** This service's name — published to ServiceInfo. Names every log line and stamps\n * `requestIdSource` on request-ids this service mints. Must be non-blank. */\n public readonly svcName: string,\n /** This build's version — published to ServiceInfo alongside svcName. Opaque to webpieces\n * (a git SHA, a semver tag, a CI build number); it just has to identify THIS build so a log\n * line can say which one emitted it. Must be non-blank. */\n public readonly svcVersion: string,\n /** Logging backend to install (LogManager.setFactory). */\n public readonly loggerFactory: LoggerFactory,\n /** Include the webpieces platform default headers. */\n public readonly platformHeaders: boolean = true,\n /** Optional WebpiecesConfig (e.g. recording flags); defaults to a fresh one. */\n public readonly config?: WebpiecesConfig,\n ) {}\n}\n\n/**\n * setupRuntime - the ONE canonical, TRANSPORT-FREE startup sequence, reusable by any company/app\n * AND any framework adapter (express, fastify, a serverless handler, ...). It runs, in the correct\n * fail-fast order:\n *\n * 1. HeaderRegistry.configure (filters read it at construction; logging masks off it)\n * 2. LogManager.setFactory (fails fast unless the registry is configured first)\n * 3. build the router + DI container (from appModules.getBindingModules())\n * 4. configure each appModules.getRoutingModules() onto the router (addRoutes/addFilter)\n *\n * and returns the built {@link ApiFactory} — `apiClients()` for a transport to bind, or\n * `createApiClient()` for in-process tests. There is NO express (or any transport) here; a\n * transport adapter (e.g. WebpiecesExpressRouter in @webpieces/http-server) serves the result.\n */\nexport async function setupRuntime(\n options: RuntimeSetupOptions,\n appModules: AppModules,\n /** A single DI module loaded LAST so tests can rebind bindings to mocks.\n * Or special case servers that want to override specific things */\n appOverrides?: ContainerModule,\n): Promise<ApiFactory> {\n // 0. IDENTIFY this service (name + build version) FIRST, before anything logs. Name and version\n // are REQUIRED inputs to this call, so a build cannot boot anonymously setInfo throws on a\n // blank value, which kills the deploy (the revision never goes healthy) rather than shipping logs\n // that cannot say which build emitted them. Reads of ServiceInfo elsewhere never throw (a missing\n // log field must never 500 live traffic); the \"say which build you are\" guarantee lives HERE, the\n // one startup every server runs.\n ServiceInfo.setInfo(options.svcName, options.svcVersion);\n\n // 1. Register the global HeaderRegistry FIRST (this service's own keys come from AppModules).\n HeaderRegistry.configure(appModules.getHeaders(), options.platformHeaders);\n\n // 2. Install the logging backend ONCE, before anything else logs.\n LogManager.setFactory(options.loggerFactory);\n\n // 2b. Bind the SERVER ApiCallContext so LogApiCall (browser-safe core-util) stamps the structured\n // `api` tag into the real RequestContext. Installed here — the one startup that runs on EVERY\n // server — so both inbound (LogApiFilter) and outbound (clients) log lines carry jsonPayload.api.\n ApiCallContextHolder.install(new RequestContextApiCallContext());\n\n // 3. Build the node-only router + DI container.\n const router = await WebpiecesRouterFactory.create({\n appBindings: [...appModules.getBindingModules()],\n appOverrides: appOverrides,\n config: options.config ?? new WebpiecesConfig(),\n });\n\n // 4. Let each route group declare its routes + filters, then hand back the consumer surface.\n for (const routeModule of appModules.getRoutingModules()) {\n routeModule.configure(router);\n }\n return router;\n}\n"]}