@webpieces/http-client-browser 0.3.371 → 0.3.373

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/README.md CHANGED
@@ -12,7 +12,7 @@ HeaderRegistry.configure(AppHeaders.getAllHeaders(), CompanyHeaders.getAllHeader
12
12
 
13
13
  const store = new MutableContextStore();
14
14
  const factory = new ClientHttpBrowserFactory(store);
15
- const saveApi = factory.createRpcClient(SaveApi, new ClientConfig(env.apiBaseUrl));
15
+ const saveApi = factory.createRpcClient(SaveApi, new ClientConfig('server'));
16
16
 
17
17
  const res = await saveApi.save({ query: 'test' }); // type-safe
18
18
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@webpieces/http-client-browser",
3
- "version": "0.3.371",
3
+ "version": "0.3.373",
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.371",
26
- "@webpieces/http-client-core": "0.3.371"
25
+ "@webpieces/core-util": "0.3.373",
26
+ "@webpieces/http-client-core": "0.3.373"
27
27
  }
28
28
  }
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.BrowserProxyClient = void 0;
4
+ const core_util_1 = require("@webpieces/core-util");
4
5
  const http_client_core_1 = require("@webpieces/http-client-core");
5
6
  /**
6
7
  * The browser {@link ProxyClient}. Reads context from the app-held store (via {@link ContextMgr}),
@@ -25,7 +26,9 @@ class BrowserProxyClient extends http_client_core_1.ProxyClient {
25
26
  this.initRoutes(apiPrototype);
26
27
  }
27
28
  resolveBaseUrl() {
28
- return Promise.resolve(this.config.baseUrl);
29
+ // A browser cannot derive a GCP URL, so it resolves purely via the registry, which the app
30
+ // populates at startup (per environment). lookup() throws if the svcName was not registered.
31
+ return Promise.resolve(core_util_1.ClientRegistry.lookup(this.config.svcName));
29
32
  }
30
33
  outboundHeaders() {
31
34
  return this.contextMgr.buildOutboundHeaders();
@@ -1 +1 @@
1
- {"version":3,"file":"BrowserProxyClient.js","sourceRoot":"","sources":["../../../../../packages/http/http-client-browser/src/BrowserProxyClient.ts"],"names":[],"mappings":";;;AACA,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;IAEkB,cAAc;QAC7B,OAAO,OAAO,CAAC,OAAO,CAAC,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;IAChD,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;AApCD,gDAoCC","sourcesContent":["import { AuthMeta, ContextMgr } 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 protected override resolveBaseUrl(): Promise<string> {\n return Promise.resolve(this.config.baseUrl);\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,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;IAEkB,cAAc;QAC7B,2FAA2F;QAC3F,6FAA6F;QAC7F,OAAO,OAAO,CAAC,OAAO,CAAC,0BAAc,CAAC,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,CAAC;IACvE,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;AAtCD,gDAsCC","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 protected override resolveBaseUrl(): Promise<string> {\n // A browser cannot derive a GCP URL, so it resolves purely via the registry, which the app\n // populates at startup (per environment). lookup() throws if the svcName was not registered.\n return Promise.resolve(ClientRegistry.lookup(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"]}
@@ -2,21 +2,18 @@
2
2
  * Per-client STATE for a browser HTTP client — nothing else. A plain class; it extends nothing and
3
3
  * is unrelated to the server package's ClientConfig.
4
4
  *
5
- * A browser is simply handed the base URL of the API it calls (usually from an environment config),
6
- * because it has no container metadata to derive one from. That is the only difference from
7
- * http-client-node's ClientConfig, which names a Cloud Run service and resolves the URL from it.
5
+ * A browser cannot read `K_SERVICE`, so it cannot derive a Cloud Run URL. It resolves its base URL
6
+ * entirely through the global {@link ClientRegistry} by `svcName` the Angular app registers each
7
+ * svcName at startup (from its per-environment config; on localhost that URL points at a local port,
8
+ * in the cloud at the deployed host). So this config is just the svcName.
8
9
  *
9
10
  * The context store is NOT config: it is a dependency of {@link ClientHttpBrowserFactory}, shared
10
11
  * by every client it builds.
11
12
  */
12
13
  export declare class ClientConfig {
13
- /** Base URL for all requests (e.g., 'http://localhost:3000') */
14
- readonly baseUrl: string;
15
- /** The callee's name for logging. Defaults to the baseUrl. */
14
+ /** Service name; resolved to a base URL via ClientRegistry (registered at app startup). */
16
15
  readonly svcName: string;
17
16
  constructor(
18
- /** Base URL for all requests (e.g., 'http://localhost:3000') */
19
- baseUrl: string,
20
- /** The callee's name for logging. Defaults to the baseUrl. */
21
- svcName?: string);
17
+ /** Service name; resolved to a base URL via ClientRegistry (registered at app startup). */
18
+ svcName: string);
22
19
  }
@@ -5,22 +5,19 @@ exports.ClientConfig = void 0;
5
5
  * Per-client STATE for a browser HTTP client — nothing else. A plain class; it extends nothing and
6
6
  * is unrelated to the server package's ClientConfig.
7
7
  *
8
- * A browser is simply handed the base URL of the API it calls (usually from an environment config),
9
- * because it has no container metadata to derive one from. That is the only difference from
10
- * http-client-node's ClientConfig, which names a Cloud Run service and resolves the URL from it.
8
+ * A browser cannot read `K_SERVICE`, so it cannot derive a Cloud Run URL. It resolves its base URL
9
+ * entirely through the global {@link ClientRegistry} by `svcName` the Angular app registers each
10
+ * svcName at startup (from its per-environment config; on localhost that URL points at a local port,
11
+ * in the cloud at the deployed host). So this config is just the svcName.
11
12
  *
12
13
  * The context store is NOT config: it is a dependency of {@link ClientHttpBrowserFactory}, shared
13
14
  * by every client it builds.
14
15
  */
15
16
  class ClientConfig {
16
- baseUrl;
17
17
  svcName;
18
18
  constructor(
19
- /** Base URL for all requests (e.g., 'http://localhost:3000') */
20
- baseUrl,
21
- /** The callee's name for logging. Defaults to the baseUrl. */
22
- svcName = baseUrl) {
23
- this.baseUrl = baseUrl;
19
+ /** Service name; resolved to a base URL via ClientRegistry (registered at app startup). */
20
+ svcName) {
24
21
  this.svcName = svcName;
25
22
  }
26
23
  }
@@ -1 +1 @@
1
- {"version":3,"file":"ClientConfig.js","sourceRoot":"","sources":["../../../../../packages/http/http-client-browser/src/ClientConfig.ts"],"names":[],"mappings":";;;AAAA;;;;;;;;;;GAUG;AACH,MAAa,YAAY;IAGD;IAGA;IALpB;IACI,gEAAgE;IAChD,OAAe;IAE/B,8DAA8D;IAC9C,UAAkB,OAAO;QAHzB,YAAO,GAAP,OAAO,CAAQ;QAGf,YAAO,GAAP,OAAO,CAAkB;IAC1C,CAAC;CACP;AARD,oCAQC","sourcesContent":["/**\n * Per-client STATE for a browser HTTP client — nothing else. A plain class; it extends nothing and\n * is unrelated to the server package's ClientConfig.\n *\n * A browser is simply handed the base URL of the API it calls (usually from an environment config),\n * because it has no container metadata to derive one from. That is the only difference from\n * http-client-node's ClientConfig, which names a Cloud Run service and resolves the URL from it.\n *\n * The context store is NOT config: it is a dependency of {@link ClientHttpBrowserFactory}, shared\n * by every client it builds.\n */\nexport class ClientConfig {\n constructor(\n /** Base URL for all requests (e.g., 'http://localhost:3000') */\n public readonly baseUrl: string,\n\n /** The callee's name for logging. Defaults to the baseUrl. */\n public readonly svcName: string = baseUrl,\n ) {}\n}\n"]}
1
+ {"version":3,"file":"ClientConfig.js","sourceRoot":"","sources":["../../../../../packages/http/http-client-browser/src/ClientConfig.ts"],"names":[],"mappings":";;;AAAA;;;;;;;;;;;GAWG;AACH,MAAa,YAAY;IAGD;IAFpB;IACI,2FAA2F;IAC3E,OAAe;QAAf,YAAO,GAAP,OAAO,CAAQ;IAChC,CAAC;CACP;AALD,oCAKC","sourcesContent":["/**\n * Per-client STATE for a browser HTTP client — nothing else. A plain class; it extends nothing and\n * is unrelated to the server package's ClientConfig.\n *\n * A browser cannot read `K_SERVICE`, so it cannot derive a Cloud Run URL. It resolves its base URL\n * entirely through the global {@link ClientRegistry} by `svcName` the Angular app registers each\n * svcName at startup (from its per-environment config; on localhost that URL points at a local port,\n * in the cloud at the deployed host). So this config is just the svcName.\n *\n * The context store is NOT config: it is a dependency of {@link ClientHttpBrowserFactory}, shared\n * by every client it builds.\n */\nexport class ClientConfig {\n constructor(\n /** Service name; resolved to a base URL via ClientRegistry (registered at app startup). */\n public readonly svcName: string,\n ) {}\n}\n"]}
@@ -18,7 +18,7 @@ import { MutableContextStore } from './MutableContextStore';
18
18
  * const store = new MutableContextStore();
19
19
  * const factory = new ClientHttpBrowserFactory(store);
20
20
  *
21
- * const saveApi = factory.createRpcClient(SaveApi, new ClientConfig(env.apiBaseUrl));
21
+ * const saveApi = factory.createRpcClient(SaveApi, new ClientConfig('server'));
22
22
  * const response = await saveApi.save({ query: 'test' }); // type-safe
23
23
  *
24
24
  * // later, when the user logs in / picks a tenant — every subsequent call carries them:
@@ -23,7 +23,7 @@ const MutableContextStore_1 = require("./MutableContextStore");
23
23
  * const store = new MutableContextStore();
24
24
  * const factory = new ClientHttpBrowserFactory(store);
25
25
  *
26
- * const saveApi = factory.createRpcClient(SaveApi, new ClientConfig(env.apiBaseUrl));
26
+ * const saveApi = factory.createRpcClient(SaveApi, new ClientConfig('server'));
27
27
  * const response = await saveApi.save({ query: 'test' }); // type-safe
28
28
  *
29
29
  * // later, when the user logs in / picks a tenant — every subsequent call carries them:
@@ -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(env.apiBaseUrl));\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;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"]}
@@ -13,7 +13,7 @@ import { ContextKey, ContextReader } from '@webpieces/core-util';
13
13
  * // startup:
14
14
  * HeaderRegistry.configure(CompanyHeaders.getAllHeaders(), true);
15
15
  * const factory = new ClientHttpFactory(new ContextMgr(store));
16
- * const client = factory.createRpcClient(SaveApi, new ClientConfig(baseUrl));
16
+ * const client = factory.createRpcClient(SaveApi, new ClientConfig('server'));
17
17
  *
18
18
  * // later, when the user logs in / picks a tenant:
19
19
  * store.set(AppHeaders.AUTHORIZATION, token); // an app-defined key, if it wants auto-attach
@@ -15,7 +15,7 @@ exports.MutableContextStore = void 0;
15
15
  * // startup:
16
16
  * HeaderRegistry.configure(CompanyHeaders.getAllHeaders(), true);
17
17
  * const factory = new ClientHttpFactory(new ContextMgr(store));
18
- * const client = factory.createRpcClient(SaveApi, new ClientConfig(baseUrl));
18
+ * const client = factory.createRpcClient(SaveApi, new ClientConfig('server'));
19
19
  *
20
20
  * // later, when the user logs in / picks a tenant:
21
21
  * store.set(AppHeaders.AUTHORIZATION, token); // an app-defined key, if it wants auto-attach
@@ -1 +1 @@
1
- {"version":3,"file":"MutableContextStore.js","sourceRoot":"","sources":["../../../../../packages/http/http-client-browser/src/MutableContextStore.ts"],"names":[],"mappings":";;;AAEA;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,MAAa,mBAAmB;IACpB,MAAM,GAAwB,IAAI,GAAG,EAAE,CAAC;IAEhD,8DAA8D;IAC9D,GAAG,CAAC,GAAe,EAAE,KAAa;QAC9B,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,GAAG,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC;IACrC,CAAC;IAED,mEAAmE;IACnE,MAAM,CAAC,GAAe;QAClB,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;IACjC,CAAC;IAED,+BAA+B;IAC/B,KAAK;QACD,IAAI,CAAC,MAAM,CAAC,KAAK,EAAE,CAAC;IACxB,CAAC;IAED,IAAI,CAAC,GAAe;QAChB,OAAO,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;IACrC,CAAC;CACJ;AArBD,kDAqBC","sourcesContent":["import { ContextKey, ContextReader } from '@webpieces/core-util';\n\n/**\n * MutableContextStore - the BROWSER ContextReader.\n *\n * Browsers have no AsyncLocalStorage, so apps (Angular/React) hold one of these\n * (e.g. as an Angular service / React context value) and set values as they become\n * known (login token, selected tenant, ...). The ContextMgr then reads from it on\n * every outbound request.\n *\n * Example (Angular):\n * ```typescript\n * const store = new MutableContextStore();\n * // startup:\n * HeaderRegistry.configure(CompanyHeaders.getAllHeaders(), true);\n * const factory = new ClientHttpFactory(new ContextMgr(store));\n * const client = factory.createRpcClient(SaveApi, new ClientConfig(baseUrl));\n *\n * // later, when the user logs in / picks a tenant:\n * store.set(AppHeaders.AUTHORIZATION, token); // an app-defined key, if it wants auto-attach\n * store.set(CompanyHeaders.TENANT_ID, tenantId);\n * ```\n */\nexport class MutableContextStore implements ContextReader {\n private values: Map<string, string> = new Map();\n\n /** Set (or overwrite) the current value for a context key. */\n set(key: ContextKey, value: string): void {\n this.values.set(key.name, value);\n }\n\n /** Remove the current value for a context key (e.g. on logout). */\n remove(key: ContextKey): void {\n this.values.delete(key.name);\n }\n\n /** Clear all stored values. */\n clear(): void {\n this.values.clear();\n }\n\n read(key: ContextKey): string | undefined {\n return this.values.get(key.name);\n }\n}\n"]}
1
+ {"version":3,"file":"MutableContextStore.js","sourceRoot":"","sources":["../../../../../packages/http/http-client-browser/src/MutableContextStore.ts"],"names":[],"mappings":";;;AAEA;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,MAAa,mBAAmB;IACpB,MAAM,GAAwB,IAAI,GAAG,EAAE,CAAC;IAEhD,8DAA8D;IAC9D,GAAG,CAAC,GAAe,EAAE,KAAa;QAC9B,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,GAAG,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC;IACrC,CAAC;IAED,mEAAmE;IACnE,MAAM,CAAC,GAAe;QAClB,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;IACjC,CAAC;IAED,+BAA+B;IAC/B,KAAK;QACD,IAAI,CAAC,MAAM,CAAC,KAAK,EAAE,CAAC;IACxB,CAAC;IAED,IAAI,CAAC,GAAe;QAChB,OAAO,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;IACrC,CAAC;CACJ;AArBD,kDAqBC","sourcesContent":["import { ContextKey, ContextReader } from '@webpieces/core-util';\n\n/**\n * MutableContextStore - the BROWSER ContextReader.\n *\n * Browsers have no AsyncLocalStorage, so apps (Angular/React) hold one of these\n * (e.g. as an Angular service / React context value) and set values as they become\n * known (login token, selected tenant, ...). The ContextMgr then reads from it on\n * every outbound request.\n *\n * Example (Angular):\n * ```typescript\n * const store = new MutableContextStore();\n * // startup:\n * HeaderRegistry.configure(CompanyHeaders.getAllHeaders(), true);\n * const factory = new ClientHttpFactory(new ContextMgr(store));\n * const client = factory.createRpcClient(SaveApi, new ClientConfig('server'));\n *\n * // later, when the user logs in / picks a tenant:\n * store.set(AppHeaders.AUTHORIZATION, token); // an app-defined key, if it wants auto-attach\n * store.set(CompanyHeaders.TENANT_ID, tenantId);\n * ```\n */\nexport class MutableContextStore implements ContextReader {\n private values: Map<string, string> = new Map();\n\n /** Set (or overwrite) the current value for a context key. */\n set(key: ContextKey, value: string): void {\n this.values.set(key.name, value);\n }\n\n /** Remove the current value for a context key (e.g. on logout). */\n remove(key: ContextKey): void {\n this.values.delete(key.name);\n }\n\n /** Clear all stored values. */\n clear(): void {\n this.values.clear();\n }\n\n read(key: ContextKey): string | undefined {\n return this.values.get(key.name);\n }\n}\n"]}
package/src/index.d.ts CHANGED
@@ -17,7 +17,7 @@
17
17
  * const store = new MutableContextStore();
18
18
  * const factory = new ClientHttpBrowserFactory(store);
19
19
  *
20
- * const client = factory.createRpcClient(SaveApi, new ClientConfig('http://localhost:3000'));
20
+ * const client = factory.createRpcClient(SaveApi, new ClientConfig('save-svc'));
21
21
  * const response = await client.save({ query: 'test' });
22
22
  * ```
23
23
  *
@@ -30,5 +30,5 @@ export { MutableContextStore } from './MutableContextStore';
30
30
  export { ProxyClient, ClientErrorTranslator } from '@webpieces/http-client-core';
31
31
  export type { ApiPrototype } from '@webpieces/http-client-core';
32
32
  export { ContextMgr } from '@webpieces/core-util';
33
- export { ContextReader, ContextKey, HeaderRegistry, WebpiecesCoreHeaders, } from '@webpieces/core-util';
33
+ export { ContextReader, ContextKey, HeaderRegistry, ClientRegistry, WebpiecesCoreHeaders, } from '@webpieces/core-util';
34
34
  export { ApiPath, Endpoint, Authentication, AuthenticationConfig, Public, AuthJwt, AuthOidc, AuthSharedSecret, Rpc, PubSub, Queue, ValidateImplementation, } from '@webpieces/core-util';
package/src/index.js CHANGED
@@ -18,14 +18,14 @@
18
18
  * const store = new MutableContextStore();
19
19
  * const factory = new ClientHttpBrowserFactory(store);
20
20
  *
21
- * const client = factory.createRpcClient(SaveApi, new ClientConfig('http://localhost:3000'));
21
+ * const client = factory.createRpcClient(SaveApi, new ClientConfig('save-svc'));
22
22
  * const response = await client.save({ query: 'test' });
23
23
  * ```
24
24
  *
25
25
  * The server twin is @webpieces/http-client-node.
26
26
  */
27
27
  Object.defineProperty(exports, "__esModule", { value: true });
28
- exports.Queue = exports.PubSub = exports.Rpc = exports.AuthSharedSecret = exports.AuthOidc = exports.AuthJwt = exports.Public = exports.AuthenticationConfig = exports.Authentication = exports.Endpoint = exports.ApiPath = exports.WebpiecesCoreHeaders = exports.HeaderRegistry = exports.ContextKey = exports.ContextMgr = exports.ClientErrorTranslator = exports.ProxyClient = exports.MutableContextStore = exports.ClientConfig = exports.BrowserProxyClient = exports.ClientHttpBrowserFactory = void 0;
28
+ exports.Queue = exports.PubSub = exports.Rpc = exports.AuthSharedSecret = exports.AuthOidc = exports.AuthJwt = exports.Public = exports.AuthenticationConfig = exports.Authentication = exports.Endpoint = exports.ApiPath = exports.WebpiecesCoreHeaders = exports.ClientRegistry = exports.HeaderRegistry = exports.ContextKey = exports.ContextMgr = exports.ClientErrorTranslator = exports.ProxyClient = exports.MutableContextStore = exports.ClientConfig = exports.BrowserProxyClient = exports.ClientHttpBrowserFactory = void 0;
29
29
  var ClientHttpBrowserFactory_1 = require("./ClientHttpBrowserFactory");
30
30
  Object.defineProperty(exports, "ClientHttpBrowserFactory", { enumerable: true, get: function () { return ClientHttpBrowserFactory_1.ClientHttpBrowserFactory; } });
31
31
  var BrowserProxyClient_1 = require("./BrowserProxyClient");
@@ -46,6 +46,7 @@ Object.defineProperty(exports, "ContextMgr", { enumerable: true, get: function (
46
46
  var core_util_2 = require("@webpieces/core-util");
47
47
  Object.defineProperty(exports, "ContextKey", { enumerable: true, get: function () { return core_util_2.ContextKey; } });
48
48
  Object.defineProperty(exports, "HeaderRegistry", { enumerable: true, get: function () { return core_util_2.HeaderRegistry; } });
49
+ Object.defineProperty(exports, "ClientRegistry", { enumerable: true, get: function () { return core_util_2.ClientRegistry; } });
49
50
  Object.defineProperty(exports, "WebpiecesCoreHeaders", { enumerable: true, get: function () { return core_util_2.WebpiecesCoreHeaders; } });
50
51
  // Re-export API decorators for convenience (same as http-routing does)
51
52
  var core_util_3 = require("@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,kDAK8B;AAH1B,uGAAA,UAAU,OAAA;AACV,2GAAA,cAAc,OAAA;AACd,iHAAA,oBAAoB,OAAA;AAGxB,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('http://localhost:3000'));\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 WebpiecesCoreHeaders,\n} 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;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,kDAM8B;AAJ1B,uGAAA,UAAU,OAAA;AACV,2GAAA,cAAc,OAAA;AACd,2GAAA,cAAc,OAAA;AACd,iHAAA,oBAAoB,OAAA;AAGxB,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 WebpiecesCoreHeaders,\n} 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"]}