@webpieces/http-client-browser 0.4.598 → 0.4.600
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.4.
|
|
3
|
+
"version": "0.4.600",
|
|
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.4.
|
|
26
|
-
"@webpieces/http-client-core": "0.4.
|
|
25
|
+
"@webpieces/core-util": "0.4.600",
|
|
26
|
+
"@webpieces/http-client-core": "0.4.600"
|
|
27
27
|
}
|
|
28
28
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { AnyContextKey, ContextReader } from '@webpieces/core-util';
|
|
1
|
+
import { AnyContextKey, AnyUntrustedContextKey, ContextReader } from '@webpieces/core-util';
|
|
2
2
|
/**
|
|
3
3
|
* MutableContextStore - the BROWSER ContextReader.
|
|
4
4
|
*
|
|
@@ -22,10 +22,15 @@ import { AnyContextKey, ContextReader } from '@webpieces/core-util';
|
|
|
22
22
|
*/
|
|
23
23
|
export declare class MutableContextStore implements ContextReader {
|
|
24
24
|
private values;
|
|
25
|
-
/**
|
|
26
|
-
|
|
25
|
+
/**
|
|
26
|
+
* Set (or overwrite) the current value for a context key. UNTRUSTED keys only, by type. A browser cannot PROVE anything — every value in here was typed
|
|
27
|
+
* by the app or the user — so a store that accepted a trusted key would be a forgery side door,
|
|
28
|
+
* exactly the one closed on the {@link ApiCallContext} seam. Narrowing it here makes the mistake
|
|
29
|
+
* a compile error in the browser bundle instead of a 401 at the far end of an HTTP call.
|
|
30
|
+
*/
|
|
31
|
+
set(key: AnyUntrustedContextKey, value: string): void;
|
|
27
32
|
/** Remove the current value for a context key (e.g. on logout). */
|
|
28
|
-
remove(key:
|
|
33
|
+
remove(key: AnyUntrustedContextKey): void;
|
|
29
34
|
/** Clear all stored values. */
|
|
30
35
|
clear(): void;
|
|
31
36
|
read(key: AnyContextKey): string | undefined;
|
|
@@ -24,7 +24,12 @@ exports.MutableContextStore = void 0;
|
|
|
24
24
|
*/
|
|
25
25
|
class MutableContextStore {
|
|
26
26
|
values = new Map();
|
|
27
|
-
/**
|
|
27
|
+
/**
|
|
28
|
+
* Set (or overwrite) the current value for a context key. UNTRUSTED keys only, by type. A browser cannot PROVE anything — every value in here was typed
|
|
29
|
+
* by the app or the user — so a store that accepted a trusted key would be a forgery side door,
|
|
30
|
+
* exactly the one closed on the {@link ApiCallContext} seam. Narrowing it here makes the mistake
|
|
31
|
+
* a compile error in the browser bundle instead of a 401 at the far end of an HTTP call.
|
|
32
|
+
*/
|
|
28
33
|
set(key, value) {
|
|
29
34
|
this.values.set(key.name, value);
|
|
30
35
|
}
|
|
@@ -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
|
|
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;;;;;OAKG;IACH,GAAG,CAAC,GAA2B,EAAE,KAAa;QAC1C,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,GAAG,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC;IACrC,CAAC;IAED,mEAAmE;IACnE,MAAM,CAAC,GAA2B;QAC9B,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,GAAkB;QACnB,OAAO,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;IACrC,CAAC;CACJ;AA1BD,kDA0BC","sourcesContent":["import { AnyContextKey, AnyUntrustedContextKey, 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.ALL_HEADERS, 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 /**\n * Set (or overwrite) the current value for a context key. UNTRUSTED keys only, by type. A browser cannot PROVE anything — every value in here was typed\n * by the app or the user — so a store that accepted a trusted key would be a forgery side door,\n * exactly the one closed on the {@link ApiCallContext} seam. Narrowing it here makes the mistake\n * a compile error in the browser bundle instead of a 401 at the far end of an HTTP call.\n */\n set(key: AnyUntrustedContextKey, 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: AnyUntrustedContextKey): 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: AnyContextKey): string | undefined {\n return this.values.get(key.name);\n }\n}\n"]}
|