@webpieces/http-client-browser 0.3.382 → 0.3.383

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-client-browser",
3
- "version": "0.3.382",
3
+ "version": "0.3.383",
4
4
  "description": "Browser HTTP client for webpieces: DI-free (React or Angular), app-managed context store, no AsyncLocalStorage",
5
5
  "type": "commonjs",
6
6
  "main": "./src/index.js",
@@ -22,7 +22,7 @@
22
22
  "access": "public"
23
23
  },
24
24
  "dependencies": {
25
- "@webpieces/core-util": "0.3.382",
26
- "@webpieces/http-client-core": "0.3.382"
25
+ "@webpieces/core-util": "0.3.383",
26
+ "@webpieces/http-client-core": "0.3.383"
27
27
  }
28
28
  }
@@ -1,6 +1,7 @@
1
- import { AuthMeta, ContextMgr } from '@webpieces/core-util';
1
+ import { AuthMeta, ContextMgr, RouteMetadata } from '@webpieces/core-util';
2
2
  import { ApiPrototype, ProxyClient } from '@webpieces/http-client-core';
3
3
  import { ClientConfig } from './ClientConfig';
4
+ import { ResponseHeadersListener } from './ResponseHeadersListener';
4
5
  /**
5
6
  * The browser {@link ProxyClient}. Reads context from the app-held store (via {@link ContextMgr}),
6
7
  * because a browser has no ambient request scope.
@@ -13,8 +14,9 @@ import { ClientConfig } from './ClientConfig';
13
14
  */
14
15
  export declare class BrowserProxyClient extends ProxyClient {
15
16
  private readonly contextMgr;
17
+ private readonly headersListener?;
16
18
  private config;
17
- constructor(contextMgr: ContextMgr);
19
+ constructor(contextMgr: ContextMgr, headersListener?: ResponseHeadersListener | undefined);
18
20
  /** Bind this client to one API contract + base URL. */
19
21
  init(apiPrototype: ApiPrototype<object>, config: ClientConfig): void;
20
22
  /**
@@ -30,6 +32,11 @@ export declare class BrowserProxyClient extends ProxyClient {
30
32
  */
31
33
  protected resolveBaseUrl(): Promise<string>;
32
34
  protected outboundHeaders(): Map<string, string>;
35
+ /**
36
+ * Forward the response headers to the app's listener, if one was registered on the factory.
37
+ * The optional chain makes this a no-op when no listener is present — the default browser case.
38
+ */
39
+ protected onResponseHeaders(route: RouteMetadata, headers: Headers): void;
33
40
  /**
34
41
  * Reject a contract this browser cannot satisfy, at bind time rather than on the first call.
35
42
  * Both service-to-service modes need credentials only a server has: @AuthOidc needs a runtime
@@ -15,10 +15,12 @@ const http_client_core_1 = require("@webpieces/http-client-core");
15
15
  */
16
16
  class BrowserProxyClient extends http_client_core_1.ProxyClient {
17
17
  contextMgr;
18
+ headersListener;
18
19
  config;
19
- constructor(contextMgr) {
20
+ constructor(contextMgr, headersListener) {
20
21
  super();
21
22
  this.contextMgr = contextMgr;
23
+ this.headersListener = headersListener;
22
24
  }
23
25
  /** Bind this client to one API contract + base URL. */
24
26
  init(apiPrototype, config) {
@@ -42,6 +44,13 @@ class BrowserProxyClient extends http_client_core_1.ProxyClient {
42
44
  outboundHeaders() {
43
45
  return this.contextMgr.buildOutboundHeaders();
44
46
  }
47
+ /**
48
+ * Forward the response headers to the app's listener, if one was registered on the factory.
49
+ * The optional chain makes this a no-op when no listener is present — the default browser case.
50
+ */
51
+ onResponseHeaders(route, headers) {
52
+ this.headersListener?.onResponseHeaders(route, headers);
53
+ }
45
54
  /**
46
55
  * Reject a contract this browser cannot satisfy, at bind time rather than on the first call.
47
56
  * Both service-to-service modes need credentials only a server has: @AuthOidc needs a runtime
@@ -1 +1 @@
1
- {"version":3,"file":"BrowserProxyClient.js","sourceRoot":"","sources":["../../../../../packages/http/http-client-browser/src/BrowserProxyClient.ts"],"names":[],"mappings":";;;AAAA,oDAA4E;AAC5E,kEAAwE;AAGxE;;;;;;;;;GASG;AACH,MAAa,kBAAmB,SAAQ,8BAAW;IAGlB;IAFrB,MAAM,CAAgB;IAE9B,YAA6B,UAAsB;QAC/C,KAAK,EAAE,CAAC;QADiB,eAAU,GAAV,UAAU,CAAY;IAEnD,CAAC;IAED,uDAAuD;IACvD,IAAI,CAAC,YAAkC,EAAE,MAAoB;QACzD,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,IAAI,CAAC,UAAU,CAAC,YAAY,CAAC,CAAC;IAClC,CAAC;IAED;;;;;;;;;;OAUG;IACgB,KAAK,CAAC,cAAc;QACnC,OAAO,CAAC,MAAM,0BAAc,CAAC,UAAU,CAAC,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,IAAI,EAAE,CAAC;IACxE,CAAC;IAEkB,eAAe;QAC9B,OAAO,IAAI,CAAC,UAAU,CAAC,oBAAoB,EAAE,CAAC;IAClD,CAAC;IAED;;;;OAIG;IACgB,uBAAuB,CAAC,QAA8B,EAAE,UAAkB;QACzF,MAAM,IAAI,GAAG,QAAQ,EAAE,IAAI,CAAC,IAAI,CAAC;QACjC,IAAI,IAAI,KAAK,MAAM,IAAI,IAAI,KAAK,eAAe,EAAE,CAAC;YAC9C,OAAO;QACX,CAAC;QACD,MAAM,IAAI,KAAK,CACX,YAAY,UAAU,QAAQ,IAAI,KAAK,MAAM,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,kBAAkB,sBAAsB;YACrG,wGAAwG,CAC3G,CAAC;IACN,CAAC;CACJ;AA/CD,gDA+CC","sourcesContent":["import { AuthMeta, ContextMgr, ClientRegistry } from '@webpieces/core-util';\nimport { ApiPrototype, ProxyClient } from '@webpieces/http-client-core';\nimport { ClientConfig } from './ClientConfig';\n\n/**\n * The browser {@link ProxyClient}. Reads context from the app-held store (via {@link ContextMgr}),\n * because a browser has no ambient request scope.\n *\n * It attaches NO outbound credential and does NO recording — both inherit the base's no-ops. A\n * browser cannot mint an OIDC token and must never hold a shared secret; the user's JWT travels as\n * an ordinary transferred context key, set on the store at login.\n *\n * This is the ONLY class in webpieces that names ContextMgr.\n */\nexport class BrowserProxyClient extends ProxyClient {\n private config!: ClientConfig;\n\n constructor(private readonly contextMgr: ContextMgr) {\n super();\n }\n\n /** Bind this client to one API contract + base URL. */\n init(apiPrototype: ApiPrototype<object>, config: ClientConfig): void {\n this.config = config;\n this.initRoutes(apiPrototype);\n }\n\n /**\n * The same chain every client runs — a ClientRegistry mapping, else the installed deriver — but\n * with the BROWSER's fallback: `''`, which makes the URL RELATIVE (`/auth/oauth`) and therefore\n * same-origin, by definition. A browser app almost always calls the backend that served it, so\n * that is the default, and an unregistered svcName must NEVER throw the way it used to — a\n * forgotten registration silently killed sign-in, the request never leaving the page.\n *\n * A mapping still wins, which is exactly how an Angular dev server on :4201 reaches its backend\n * on :8201, while the same bundle served BY that backend in prod registers nothing and goes\n * relative. No `window` access, so this stays SSR-safe and testable.\n */\n protected override async resolveBaseUrl(): Promise<string> {\n return (await ClientRegistry.tryResolve(this.config.svcName)) ?? '';\n }\n\n protected override outboundHeaders(): Map<string, string> {\n return this.contextMgr.buildOutboundHeaders();\n }\n\n /**\n * Reject a contract this browser cannot satisfy, at bind time rather than on the first call.\n * Both service-to-service modes need credentials only a server has: @AuthOidc needs a runtime\n * service account to mint a token, @AuthSharedSecret needs a secret no browser may ship.\n */\n protected override assertEndpointSupported(authMeta: AuthMeta | undefined, methodName: string): void {\n const kind = authMeta?.mode.kind;\n if (kind !== 'oidc' && kind !== 'shared-secret') {\n return;\n }\n throw new Error(\n `Endpoint ${methodName} is @${kind === 'oidc' ? 'AuthOidc' : 'AuthSharedSecret'} — a browser cannot ` +\n `hold service credentials. Call it server-side with ClientHttpFactory from @webpieces/http-client-node.`,\n );\n }\n}\n"]}
1
+ {"version":3,"file":"BrowserProxyClient.js","sourceRoot":"","sources":["../../../../../packages/http/http-client-browser/src/BrowserProxyClient.ts"],"names":[],"mappings":";;;AAAA,oDAA2F;AAC3F,kEAAwE;AAIxE;;;;;;;;;GASG;AACH,MAAa,kBAAmB,SAAQ,8BAAW;IAI1B;IACA;IAJb,MAAM,CAAgB;IAE9B,YACqB,UAAsB,EACtB,eAAyC;QAE1D,KAAK,EAAE,CAAC;QAHS,eAAU,GAAV,UAAU,CAAY;QACtB,oBAAe,GAAf,eAAe,CAA0B;IAG9D,CAAC;IAED,uDAAuD;IACvD,IAAI,CAAC,YAAkC,EAAE,MAAoB;QACzD,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,IAAI,CAAC,UAAU,CAAC,YAAY,CAAC,CAAC;IAClC,CAAC;IAED;;;;;;;;;;OAUG;IACgB,KAAK,CAAC,cAAc;QACnC,OAAO,CAAC,MAAM,0BAAc,CAAC,UAAU,CAAC,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,IAAI,EAAE,CAAC;IACxE,CAAC;IAEkB,eAAe;QAC9B,OAAO,IAAI,CAAC,UAAU,CAAC,oBAAoB,EAAE,CAAC;IAClD,CAAC;IAED;;;OAGG;IACgB,iBAAiB,CAAC,KAAoB,EAAE,OAAgB;QACvE,IAAI,CAAC,eAAe,EAAE,iBAAiB,CAAC,KAAK,EAAE,OAAO,CAAC,CAAC;IAC5D,CAAC;IAED;;;;OAIG;IACgB,uBAAuB,CAAC,QAA8B,EAAE,UAAkB;QACzF,MAAM,IAAI,GAAG,QAAQ,EAAE,IAAI,CAAC,IAAI,CAAC;QACjC,IAAI,IAAI,KAAK,MAAM,IAAI,IAAI,KAAK,eAAe,EAAE,CAAC;YAC9C,OAAO;QACX,CAAC;QACD,MAAM,IAAI,KAAK,CACX,YAAY,UAAU,QAAQ,IAAI,KAAK,MAAM,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,kBAAkB,sBAAsB;YACrG,wGAAwG,CAC3G,CAAC;IACN,CAAC;CACJ;AA1DD,gDA0DC","sourcesContent":["import { AuthMeta, ContextMgr, ClientRegistry, RouteMetadata } from '@webpieces/core-util';\nimport { ApiPrototype, ProxyClient } from '@webpieces/http-client-core';\nimport { ClientConfig } from './ClientConfig';\nimport { ResponseHeadersListener } from './ResponseHeadersListener';\n\n/**\n * The browser {@link ProxyClient}. Reads context from the app-held store (via {@link ContextMgr}),\n * because a browser has no ambient request scope.\n *\n * It attaches NO outbound credential and does NO recording — both inherit the base's no-ops. A\n * browser cannot mint an OIDC token and must never hold a shared secret; the user's JWT travels as\n * an ordinary transferred context key, set on the store at login.\n *\n * This is the ONLY class in webpieces that names ContextMgr.\n */\nexport class BrowserProxyClient extends ProxyClient {\n private config!: ClientConfig;\n\n constructor(\n private readonly contextMgr: ContextMgr,\n private readonly headersListener?: ResponseHeadersListener,\n ) {\n super();\n }\n\n /** Bind this client to one API contract + base URL. */\n init(apiPrototype: ApiPrototype<object>, config: ClientConfig): void {\n this.config = config;\n this.initRoutes(apiPrototype);\n }\n\n /**\n * The same chain every client runs — a ClientRegistry mapping, else the installed deriver — but\n * with the BROWSER's fallback: `''`, which makes the URL RELATIVE (`/auth/oauth`) and therefore\n * same-origin, by definition. A browser app almost always calls the backend that served it, so\n * that is the default, and an unregistered svcName must NEVER throw the way it used to — a\n * forgotten registration silently killed sign-in, the request never leaving the page.\n *\n * A mapping still wins, which is exactly how an Angular dev server on :4201 reaches its backend\n * on :8201, while the same bundle served BY that backend in prod registers nothing and goes\n * relative. No `window` access, so this stays SSR-safe and testable.\n */\n protected override async resolveBaseUrl(): Promise<string> {\n return (await ClientRegistry.tryResolve(this.config.svcName)) ?? '';\n }\n\n protected override outboundHeaders(): Map<string, string> {\n return this.contextMgr.buildOutboundHeaders();\n }\n\n /**\n * Forward the response headers to the app's listener, if one was registered on the factory.\n * The optional chain makes this a no-op when no listener is present — the default browser case.\n */\n protected override onResponseHeaders(route: RouteMetadata, headers: Headers): void {\n this.headersListener?.onResponseHeaders(route, headers);\n }\n\n /**\n * Reject a contract this browser cannot satisfy, at bind time rather than on the first call.\n * Both service-to-service modes need credentials only a server has: @AuthOidc needs a runtime\n * service account to mint a token, @AuthSharedSecret needs a secret no browser may ship.\n */\n protected override assertEndpointSupported(authMeta: AuthMeta | undefined, methodName: string): void {\n const kind = authMeta?.mode.kind;\n if (kind !== 'oidc' && kind !== 'shared-secret') {\n return;\n }\n throw new Error(\n `Endpoint ${methodName} is @${kind === 'oidc' ? 'AuthOidc' : 'AuthSharedSecret'} — a browser cannot ` +\n `hold service credentials. Call it server-side with ClientHttpFactory from @webpieces/http-client-node.`,\n );\n }\n}\n"]}
@@ -1,6 +1,7 @@
1
1
  import { ApiPrototype } from '@webpieces/http-client-core';
2
2
  import { ClientConfig } from './ClientConfig';
3
3
  import { MutableContextStore } from './MutableContextStore';
4
+ import { ResponseHeadersListener } from './ResponseHeadersListener';
4
5
  /**
5
6
  * ClientHttpBrowserFactory - builds type-safe HTTP clients for a BROWSER from API prototypes
6
7
  * carrying @ApiPath/@Endpoint decorators.
@@ -30,8 +31,9 @@ import { MutableContextStore } from './MutableContextStore';
30
31
  * endpoint throws in `createRpcClient`, not on the first call.
31
32
  */
32
33
  export declare class ClientHttpBrowserFactory {
34
+ private readonly headersListener?;
33
35
  private readonly contextMgr;
34
- constructor(store: MutableContextStore);
36
+ constructor(store: MutableContextStore, headersListener?: ResponseHeadersListener | undefined);
35
37
  /**
36
38
  * Create a type-safe HTTP client for one API contract.
37
39
  *
@@ -35,8 +35,10 @@ const MutableContextStore_1 = require("./MutableContextStore");
35
35
  * endpoint throws in `createRpcClient`, not on the first call.
36
36
  */
37
37
  let ClientHttpBrowserFactory = class ClientHttpBrowserFactory {
38
+ headersListener;
38
39
  contextMgr;
39
- constructor(store) {
40
+ constructor(store, headersListener) {
41
+ this.headersListener = headersListener;
40
42
  this.contextMgr = new core_util_1.ContextMgr(store);
41
43
  }
42
44
  /**
@@ -46,7 +48,7 @@ let ClientHttpBrowserFactory = class ClientHttpBrowserFactory {
46
48
  * @param config - This client's state (its baseUrl)
47
49
  */
48
50
  createRpcClient(apiPrototype, config) {
49
- const proxyClient = new BrowserProxyClient_1.BrowserProxyClient(this.contextMgr);
51
+ const proxyClient = new BrowserProxyClient_1.BrowserProxyClient(this.contextMgr, this.headersListener);
50
52
  proxyClient.init(apiPrototype, config);
51
53
  return (0, http_client_core_1.buildClientProxy)(apiPrototype, proxyClient);
52
54
  }
@@ -54,6 +56,6 @@ let ClientHttpBrowserFactory = class ClientHttpBrowserFactory {
54
56
  exports.ClientHttpBrowserFactory = ClientHttpBrowserFactory;
55
57
  exports.ClientHttpBrowserFactory = ClientHttpBrowserFactory = tslib_1.__decorate([
56
58
  (0, core_util_1.DocumentDesign)(),
57
- tslib_1.__metadata("design:paramtypes", [MutableContextStore_1.MutableContextStore])
59
+ tslib_1.__metadata("design:paramtypes", [MutableContextStore_1.MutableContextStore, Object])
58
60
  ], ClientHttpBrowserFactory);
59
61
  //# sourceMappingURL=ClientHttpBrowserFactory.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"ClientHttpBrowserFactory.js","sourceRoot":"","sources":["../../../../../packages/http/http-client-browser/src/ClientHttpBrowserFactory.ts"],"names":[],"mappings":";;;;AAAA,oDAAkE;AAClE,kEAA6E;AAC7E,6DAA0D;AAE1D,+DAA4D;AAE5D;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AAEI,IAAM,wBAAwB,GAA9B,MAAM,wBAAwB;IAChB,UAAU,CAAa;IAExC,YAAY,KAA0B;QAClC,IAAI,CAAC,UAAU,GAAG,IAAI,sBAAU,CAAC,KAAK,CAAC,CAAC;IAC5C,CAAC;IAED;;;;;OAKG;IACH,eAAe,CAAmB,YAA6B,EAAE,MAAoB;QACjF,MAAM,WAAW,GAAG,IAAI,uCAAkB,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;QAC5D,WAAW,CAAC,IAAI,CAAC,YAAY,EAAE,MAAM,CAAC,CAAC;QACvC,OAAO,IAAA,mCAAgB,EAAC,YAAY,EAAE,WAAW,CAAC,CAAC;IACvD,CAAC;CACJ,CAAA;AAlBY,4DAAwB;mCAAxB,wBAAwB;IADpC,IAAA,0BAAc,GAAE;6CAIM,yCAAmB;GAH7B,wBAAwB,CAkBpC","sourcesContent":["import { ContextMgr, DocumentDesign } from '@webpieces/core-util';\nimport { ApiPrototype, buildClientProxy } from '@webpieces/http-client-core';\nimport { BrowserProxyClient } from './BrowserProxyClient';\nimport { ClientConfig } from './ClientConfig';\nimport { MutableContextStore } from './MutableContextStore';\n\n/**\n * ClientHttpBrowserFactory - builds type-safe HTTP clients for a BROWSER from API prototypes\n * carrying @ApiPath/@Endpoint decorators.\n *\n * Deliberately a plain class with NO decorators and NO inversify: this package may be bundled by\n * React just as easily as by Angular, and neither should be forced to adopt a Node DI container.\n * The app provides it through whatever DI it already has — Angular's `useFactory`, a React context,\n * or a module-level `const`.\n *\n * The factory holds the ONE collaborator every browser client shares (the app's\n * {@link MutableContextStore}); each {@link ClientConfig} holds only that one client's base URL.\n *\n * ```typescript\n * // once, at startup (after HeaderRegistry.configure(...)):\n * const store = new MutableContextStore();\n * const factory = new ClientHttpBrowserFactory(store);\n *\n * const saveApi = factory.createRpcClient(SaveApi, new ClientConfig('server'));\n * const response = await saveApi.save({ query: 'test' }); // type-safe\n *\n * // later, when the user logs in / picks a tenant — every subsequent call carries them:\n * store.set(AppHeaders.AUTHORIZATION, token); // an app-defined key, if it wants auto-attach\n * store.set(CompanyHeaders.TENANT_ID, tenantId);\n * ```\n *\n * A browser cannot hold service credentials, so a contract with an @AuthOidc or @AuthSharedSecret\n * endpoint throws in `createRpcClient`, not on the first call.\n */\n@DocumentDesign()\nexport class ClientHttpBrowserFactory {\n private readonly contextMgr: ContextMgr;\n\n constructor(store: MutableContextStore) {\n this.contextMgr = new ContextMgr(store);\n }\n\n /**\n * Create a type-safe HTTP client for one API contract.\n *\n * @param apiPrototype - The API prototype class with @ApiPath/@Endpoint decorators\n * @param config - This client's state (its baseUrl)\n */\n createRpcClient<T extends object>(apiPrototype: ApiPrototype<T>, config: ClientConfig): T {\n const proxyClient = new BrowserProxyClient(this.contextMgr);\n proxyClient.init(apiPrototype, config);\n return buildClientProxy(apiPrototype, proxyClient);\n }\n}\n"]}
1
+ {"version":3,"file":"ClientHttpBrowserFactory.js","sourceRoot":"","sources":["../../../../../packages/http/http-client-browser/src/ClientHttpBrowserFactory.ts"],"names":[],"mappings":";;;;AAAA,oDAAkE;AAClE,kEAA6E;AAC7E,6DAA0D;AAE1D,+DAA4D;AAG5D;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AAEI,IAAM,wBAAwB,GAA9B,MAAM,wBAAwB;IAKZ;IAJJ,UAAU,CAAa;IAExC,YACI,KAA0B,EACT,eAAyC;QAAzC,oBAAe,GAAf,eAAe,CAA0B;QAE1D,IAAI,CAAC,UAAU,GAAG,IAAI,sBAAU,CAAC,KAAK,CAAC,CAAC;IAC5C,CAAC;IAED;;;;;OAKG;IACH,eAAe,CAAmB,YAA6B,EAAE,MAAoB;QACjF,MAAM,WAAW,GAAG,IAAI,uCAAkB,CAAC,IAAI,CAAC,UAAU,EAAE,IAAI,CAAC,eAAe,CAAC,CAAC;QAClF,WAAW,CAAC,IAAI,CAAC,YAAY,EAAE,MAAM,CAAC,CAAC;QACvC,OAAO,IAAA,mCAAgB,EAAC,YAAY,EAAE,WAAW,CAAC,CAAC;IACvD,CAAC;CACJ,CAAA;AArBY,4DAAwB;mCAAxB,wBAAwB;IADpC,IAAA,0BAAc,GAAE;6CAKF,yCAAmB;GAJrB,wBAAwB,CAqBpC","sourcesContent":["import { ContextMgr, DocumentDesign } from '@webpieces/core-util';\nimport { ApiPrototype, buildClientProxy } from '@webpieces/http-client-core';\nimport { BrowserProxyClient } from './BrowserProxyClient';\nimport { ClientConfig } from './ClientConfig';\nimport { MutableContextStore } from './MutableContextStore';\nimport { ResponseHeadersListener } from './ResponseHeadersListener';\n\n/**\n * ClientHttpBrowserFactory - builds type-safe HTTP clients for a BROWSER from API prototypes\n * carrying @ApiPath/@Endpoint decorators.\n *\n * Deliberately a plain class with NO decorators and NO inversify: this package may be bundled by\n * React just as easily as by Angular, and neither should be forced to adopt a Node DI container.\n * The app provides it through whatever DI it already has — Angular's `useFactory`, a React context,\n * or a module-level `const`.\n *\n * The factory holds the ONE collaborator every browser client shares (the app's\n * {@link MutableContextStore}); each {@link ClientConfig} holds only that one client's base URL.\n *\n * ```typescript\n * // once, at startup (after HeaderRegistry.configure(...)):\n * const store = new MutableContextStore();\n * const factory = new ClientHttpBrowserFactory(store);\n *\n * const saveApi = factory.createRpcClient(SaveApi, new ClientConfig('server'));\n * const response = await saveApi.save({ query: 'test' }); // type-safe\n *\n * // later, when the user logs in / picks a tenant — every subsequent call carries them:\n * store.set(AppHeaders.AUTHORIZATION, token); // an app-defined key, if it wants auto-attach\n * store.set(CompanyHeaders.TENANT_ID, tenantId);\n * ```\n *\n * A browser cannot hold service credentials, so a contract with an @AuthOidc or @AuthSharedSecret\n * endpoint throws in `createRpcClient`, not on the first call.\n */\n@DocumentDesign()\nexport class ClientHttpBrowserFactory {\n private readonly contextMgr: ContextMgr;\n\n constructor(\n store: MutableContextStore,\n private readonly headersListener?: ResponseHeadersListener,\n ) {\n this.contextMgr = new ContextMgr(store);\n }\n\n /**\n * Create a type-safe HTTP client for one API contract.\n *\n * @param apiPrototype - The API prototype class with @ApiPath/@Endpoint decorators\n * @param config - This client's state (its baseUrl)\n */\n createRpcClient<T extends object>(apiPrototype: ApiPrototype<T>, config: ClientConfig): T {\n const proxyClient = new BrowserProxyClient(this.contextMgr, this.headersListener);\n proxyClient.init(apiPrototype, config);\n return buildClientProxy(apiPrototype, proxyClient);\n }\n}\n"]}
@@ -0,0 +1,27 @@
1
+ import { RouteMetadata } from '@webpieces/core-util';
2
+ /**
3
+ * The inbound seam an app implements to observe response headers on every RPC call — symmetric with
4
+ * the outbound header propagation done by {@link MutableContextStore} / {@link ContextMgr}.
5
+ *
6
+ * Registered once on {@link ClientHttpBrowserFactory}, it is invoked by {@link BrowserProxyClient}
7
+ * with the `fetch` Response `Headers` after each call, on BOTH the ok and error paths (so a
8
+ * version — or any future — header is observed even on error responses), before the body is read.
9
+ *
10
+ * The driver is client↔server version matching: the server stamps `x-<org>-server-version` on every
11
+ * response, and the browser reads it off each RPC response to detect that a newer server is deployed
12
+ * than this bundle and prompt a reload.
13
+ *
14
+ * ```typescript
15
+ * const factory = new ClientHttpBrowserFactory(store, {
16
+ * onResponseHeaders: (_route, headers) => {
17
+ * const v = headers.get('x-myorg-server-version');
18
+ * if (v) serverVersionBridge.set(v);
19
+ * },
20
+ * });
21
+ * ```
22
+ *
23
+ * This is BUSINESS LOGIC (a method), so it is an interface, not a data class.
24
+ */
25
+ export interface ResponseHeadersListener {
26
+ onResponseHeaders(route: RouteMetadata, headers: Headers): void;
27
+ }
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=ResponseHeadersListener.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ResponseHeadersListener.js","sourceRoot":"","sources":["../../../../../packages/http/http-client-browser/src/ResponseHeadersListener.ts"],"names":[],"mappings":"","sourcesContent":["import { RouteMetadata } from '@webpieces/core-util';\n\n/**\n * The inbound seam an app implements to observe response headers on every RPC call — symmetric with\n * the outbound header propagation done by {@link MutableContextStore} / {@link ContextMgr}.\n *\n * Registered once on {@link ClientHttpBrowserFactory}, it is invoked by {@link BrowserProxyClient}\n * with the `fetch` Response `Headers` after each call, on BOTH the ok and error paths (so a\n * version — or any future — header is observed even on error responses), before the body is read.\n *\n * The driver is client↔server version matching: the server stamps `x-<org>-server-version` on every\n * response, and the browser reads it off each RPC response to detect that a newer server is deployed\n * than this bundle and prompt a reload.\n *\n * ```typescript\n * const factory = new ClientHttpBrowserFactory(store, {\n * onResponseHeaders: (_route, headers) => {\n * const v = headers.get('x-myorg-server-version');\n * if (v) serverVersionBridge.set(v);\n * },\n * });\n * ```\n *\n * This is BUSINESS LOGIC (a method), so it is an interface, not a data class.\n */\nexport interface ResponseHeadersListener {\n onResponseHeaders(route: RouteMetadata, headers: Headers): void;\n}\n"]}
package/src/index.d.ts CHANGED
@@ -27,6 +27,7 @@ export { ClientHttpBrowserFactory } from './ClientHttpBrowserFactory';
27
27
  export { BrowserProxyClient } from './BrowserProxyClient';
28
28
  export { ClientConfig } from './ClientConfig';
29
29
  export { MutableContextStore } from './MutableContextStore';
30
+ export type { ResponseHeadersListener } from './ResponseHeadersListener';
30
31
  export { ProxyClient, ClientErrorTranslator } from '@webpieces/http-client-core';
31
32
  export type { ApiPrototype } from '@webpieces/http-client-core';
32
33
  export { ContextMgr } from '@webpieces/core-util';
package/src/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../packages/http/http-client-browser/src/index.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;;;AAEH,uEAAsE;AAA7D,oIAAA,wBAAwB,OAAA;AACjC,2DAA0D;AAAjD,wHAAA,kBAAkB,OAAA;AAC3B,+CAA8C;AAArC,4GAAA,YAAY,OAAA;AACrB,6DAA4D;AAAnD,0HAAA,mBAAmB,OAAA;AAE5B,wEAAwE;AACxE,gEAAiF;AAAxE,+GAAA,WAAW,OAAA;AAAE,yHAAA,qBAAqB,OAAA;AAG3C,iGAAiG;AACjG,mGAAmG;AACnG,kDAAkD;AAAzC,uGAAA,UAAU,OAAA;AAEnB,yFAAyF;AACzF,kDAO8B;AAL1B,uGAAA,UAAU,OAAA;AACV,2GAAA,cAAc,OAAA;AACd,2GAAA,cAAc,OAAA;AACd,4GAAA,eAAe,OAAA;AACf,iHAAA,oBAAoB,OAAA;AAIxB,uEAAuE;AACvE,kDAa8B;AAZ1B,oGAAA,OAAO,OAAA;AACP,qGAAA,QAAQ,OAAA;AACR,2GAAA,cAAc,OAAA;AACd,iHAAA,oBAAoB,OAAA;AACpB,mGAAA,MAAM,OAAA;AACN,oGAAA,OAAO,OAAA;AACP,qGAAA,QAAQ,OAAA;AACR,6GAAA,gBAAgB,OAAA;AAChB,gGAAA,GAAG,OAAA;AACH,mGAAA,MAAM,OAAA;AACN,kGAAA,KAAK,OAAA","sourcesContent":["/**\n * @webpieces/http-client-browser\n *\n * The BROWSER HTTP client. Reads an API contract's decorators and generates type-safe HTTP\n * clients from it — the same contract the server implements.\n *\n * DI-free on purpose: this may be bundled by React or Angular, so it ships no inversify and no\n * @webpieces/core-context (which is AsyncLocalStorage-backed and Node-only). Browsers have no\n * ambient request scope, so the app holds a {@link MutableContextStore} and sets context values\n * as they become known; every outbound call then transfers them as headers.\n *\n * Usage:\n * ```typescript\n * import { ClientHttpBrowserFactory, ClientConfig, MutableContextStore } from '@webpieces/http-client-browser';\n *\n * HeaderRegistry.configure(CompanyHeaders.getAllHeaders(), true);\n * const store = new MutableContextStore();\n * const factory = new ClientHttpBrowserFactory(store);\n *\n * const client = factory.createRpcClient(SaveApi, new ClientConfig('save-svc'));\n * const response = await client.save({ query: 'test' });\n * ```\n *\n * The server twin is @webpieces/http-client-node.\n */\n\nexport { ClientHttpBrowserFactory } from './ClientHttpBrowserFactory';\nexport { BrowserProxyClient } from './BrowserProxyClient';\nexport { ClientConfig } from './ClientConfig';\nexport { MutableContextStore } from './MutableContextStore';\n\n// The isomorphic engine, re-exported so a browser app needs one import.\nexport { ProxyClient, ClientErrorTranslator } from '@webpieces/http-client-core';\nexport type { ApiPrototype } from '@webpieces/http-client-core';\n\n// ContextMgr is the BROWSER's outbound-header propagation. This is the only package that may use\n// it; the server reads RequestContext directly (RequestContextHeaders in @webpieces/core-context).\nexport { ContextMgr } from '@webpieces/core-util';\n\n// Re-export the context-key contract from core-util for convenience (browser one-import)\nexport {\n ContextReader,\n ContextKey,\n HeaderRegistry,\n ClientRegistry,\n templateDeriver,\n WebpiecesCoreHeaders,\n} from '@webpieces/core-util';\nexport type { ServiceUrlDeriver } from '@webpieces/core-util';\n\n// Re-export API decorators for convenience (same as http-routing does)\nexport {\n ApiPath,\n Endpoint,\n Authentication,\n AuthenticationConfig,\n Public,\n AuthJwt,\n AuthOidc,\n AuthSharedSecret,\n Rpc,\n PubSub,\n Queue,\n ValidateImplementation,\n} from '@webpieces/core-util';\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../packages/http/http-client-browser/src/index.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;;;AAEH,uEAAsE;AAA7D,oIAAA,wBAAwB,OAAA;AACjC,2DAA0D;AAAjD,wHAAA,kBAAkB,OAAA;AAC3B,+CAA8C;AAArC,4GAAA,YAAY,OAAA;AACrB,6DAA4D;AAAnD,0HAAA,mBAAmB,OAAA;AAG5B,wEAAwE;AACxE,gEAAiF;AAAxE,+GAAA,WAAW,OAAA;AAAE,yHAAA,qBAAqB,OAAA;AAG3C,iGAAiG;AACjG,mGAAmG;AACnG,kDAAkD;AAAzC,uGAAA,UAAU,OAAA;AAEnB,yFAAyF;AACzF,kDAO8B;AAL1B,uGAAA,UAAU,OAAA;AACV,2GAAA,cAAc,OAAA;AACd,2GAAA,cAAc,OAAA;AACd,4GAAA,eAAe,OAAA;AACf,iHAAA,oBAAoB,OAAA;AAIxB,uEAAuE;AACvE,kDAa8B;AAZ1B,oGAAA,OAAO,OAAA;AACP,qGAAA,QAAQ,OAAA;AACR,2GAAA,cAAc,OAAA;AACd,iHAAA,oBAAoB,OAAA;AACpB,mGAAA,MAAM,OAAA;AACN,oGAAA,OAAO,OAAA;AACP,qGAAA,QAAQ,OAAA;AACR,6GAAA,gBAAgB,OAAA;AAChB,gGAAA,GAAG,OAAA;AACH,mGAAA,MAAM,OAAA;AACN,kGAAA,KAAK,OAAA","sourcesContent":["/**\n * @webpieces/http-client-browser\n *\n * The BROWSER HTTP client. Reads an API contract's decorators and generates type-safe HTTP\n * clients from it — the same contract the server implements.\n *\n * DI-free on purpose: this may be bundled by React or Angular, so it ships no inversify and no\n * @webpieces/core-context (which is AsyncLocalStorage-backed and Node-only). Browsers have no\n * ambient request scope, so the app holds a {@link MutableContextStore} and sets context values\n * as they become known; every outbound call then transfers them as headers.\n *\n * Usage:\n * ```typescript\n * import { ClientHttpBrowserFactory, ClientConfig, MutableContextStore } from '@webpieces/http-client-browser';\n *\n * HeaderRegistry.configure(CompanyHeaders.getAllHeaders(), true);\n * const store = new MutableContextStore();\n * const factory = new ClientHttpBrowserFactory(store);\n *\n * const client = factory.createRpcClient(SaveApi, new ClientConfig('save-svc'));\n * const response = await client.save({ query: 'test' });\n * ```\n *\n * The server twin is @webpieces/http-client-node.\n */\n\nexport { ClientHttpBrowserFactory } from './ClientHttpBrowserFactory';\nexport { BrowserProxyClient } from './BrowserProxyClient';\nexport { ClientConfig } from './ClientConfig';\nexport { MutableContextStore } from './MutableContextStore';\nexport type { ResponseHeadersListener } from './ResponseHeadersListener';\n\n// The isomorphic engine, re-exported so a browser app needs one import.\nexport { ProxyClient, ClientErrorTranslator } from '@webpieces/http-client-core';\nexport type { ApiPrototype } from '@webpieces/http-client-core';\n\n// ContextMgr is the BROWSER's outbound-header propagation. This is the only package that may use\n// it; the server reads RequestContext directly (RequestContextHeaders in @webpieces/core-context).\nexport { ContextMgr } from '@webpieces/core-util';\n\n// Re-export the context-key contract from core-util for convenience (browser one-import)\nexport {\n ContextReader,\n ContextKey,\n HeaderRegistry,\n ClientRegistry,\n templateDeriver,\n WebpiecesCoreHeaders,\n} from '@webpieces/core-util';\nexport type { ServiceUrlDeriver } from '@webpieces/core-util';\n\n// Re-export API decorators for convenience (same as http-routing does)\nexport {\n ApiPath,\n Endpoint,\n Authentication,\n AuthenticationConfig,\n Public,\n AuthJwt,\n AuthOidc,\n AuthSharedSecret,\n Rpc,\n PubSub,\n Queue,\n ValidateImplementation,\n} from '@webpieces/core-util';\n"]}