@procedures/http 0.28.0 → 0.28.1
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/CHANGELOG.md +23 -0
- package/README.md +18 -0
- package/dist/.tsbuildinfo +1 -1
- package/dist/host-fetch.d.ts +67 -0
- package/dist/host-fetch.d.ts.map +1 -0
- package/dist/host-fetch.js +80 -0
- package/dist/host-fetch.js.map +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -1
- package/dist/module.d.ts +3 -0
- package/dist/module.d.ts.map +1 -1
- package/dist/module.js +7 -2
- package/dist/module.js.map +1 -1
- package/package.json +2 -2
- package/src/host-fetch.ts +128 -0
- package/src/index.ts +2 -0
- package/src/module.ts +7 -2
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A `fetch` for GET requests that goes through the host policy (audit pass 2, O55).
|
|
3
|
+
*
|
|
4
|
+
* A procedure of another package that reads a URL of its caller uses this function in place of
|
|
5
|
+
* the global `fetch`: `weather.forecast`, and the modules of `@procedures/geo` and
|
|
6
|
+
* `@procedures/ics` that a host makes with it. The request has the same checks as `http.request`:
|
|
7
|
+
*
|
|
8
|
+
* - The host of the URL and of each redirect must pass the host policy. The default policy
|
|
9
|
+
* refuses loopback, private, link-local and the other special addresses.
|
|
10
|
+
* - The connection uses only the addresses that the check allowed (DNS rebinding).
|
|
11
|
+
* - The body of the response has the size limit of the settings.
|
|
12
|
+
*
|
|
13
|
+
* A refusal is `FORBIDDEN` with the reason `host-not-allowed` (`isHostNotAllowed`). When the
|
|
14
|
+
* signal of the caller aborts, the function throws the reason of the signal, as `fetch` does.
|
|
15
|
+
*
|
|
16
|
+
* The option `warnOnRefusal` keeps the behavior before the host policy, for the default modules
|
|
17
|
+
* of 0.28: a refused host gets a deprecation notice and the global `fetch`. Version 0.29.0 removes it.
|
|
18
|
+
*/
|
|
19
|
+
import type { HttpModuleOptions } from "./module.js";
|
|
20
|
+
/** The options of one request. */
|
|
21
|
+
export interface HostFetchInit {
|
|
22
|
+
/** The headers of the request. */
|
|
23
|
+
readonly headers?: Readonly<Record<string, string>> | undefined;
|
|
24
|
+
/** The signal that stops the request. */
|
|
25
|
+
readonly signal?: AbortSignal | undefined;
|
|
26
|
+
}
|
|
27
|
+
/** The response of a request: the parts of a `Response` of `fetch` that the procedures use. */
|
|
28
|
+
export interface HostFetchResponse {
|
|
29
|
+
readonly ok: boolean;
|
|
30
|
+
readonly status: number;
|
|
31
|
+
/** The URL of the response: the last URL after the redirects. */
|
|
32
|
+
readonly url: string;
|
|
33
|
+
text(): Promise<string>;
|
|
34
|
+
json(): Promise<unknown>;
|
|
35
|
+
}
|
|
36
|
+
/** A `fetch` for GET requests through the host policy. */
|
|
37
|
+
export type HostFetch = (url: string, init?: HostFetchInit) => Promise<HostFetchResponse>;
|
|
38
|
+
/** A deprecation notice: the code and the text of a `DeprecationWarning` of Node. */
|
|
39
|
+
export interface DeprecationNotice {
|
|
40
|
+
/** The code of the warning, for example `PROCEDURES_WEATHER_PRIVATE_HOST`. The process emits each code one time. */
|
|
41
|
+
readonly code: string;
|
|
42
|
+
/** The text of the warning. It names the change that removes the notice. */
|
|
43
|
+
readonly message: string;
|
|
44
|
+
}
|
|
45
|
+
/** The options of `createHostFetch()`: the options of `createHttpModule()`, and the notice of a refused host. */
|
|
46
|
+
export interface HostFetchOptions extends HttpModuleOptions {
|
|
47
|
+
/**
|
|
48
|
+
* The notice of a refused host. With this option, a refused host does not throw. The function
|
|
49
|
+
* emits the notice one time in each process. Then it sends the request with the global `fetch`,
|
|
50
|
+
* as before the host policy. Without this option, a refused host throws `FORBIDDEN`.
|
|
51
|
+
*
|
|
52
|
+
* @deprecated The default modules of `weather`, `geo` and `ics` use it in 0.28 only. Version
|
|
53
|
+
* 0.29.0 removes it. Then a refused host always throws.
|
|
54
|
+
*/
|
|
55
|
+
readonly warnOnRefusal?: DeprecationNotice | undefined;
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* This function gives a `fetch` for GET requests through the host policy of the options. The
|
|
59
|
+
* options are the options of `createHttpModule()`. Without options, the policy is the default
|
|
60
|
+
* policy: each public host, and no other host. A bad entry of `allow` throws here.
|
|
61
|
+
*
|
|
62
|
+
* ```ts
|
|
63
|
+
* const forecast = createWeatherModule({ fetch: createHostFetch({ allow: ["localhost:8080"] }) });
|
|
64
|
+
* ```
|
|
65
|
+
*/
|
|
66
|
+
export declare function createHostFetch(options?: HostFetchOptions): HostFetch;
|
|
67
|
+
//# sourceMappingURL=host-fetch.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"host-fetch.d.ts","sourceRoot":"","sources":["../src/host-fetch.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AAEH,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAQrD,kCAAkC;AAClC,MAAM,WAAW,aAAa;IAC5B,kCAAkC;IAClC,QAAQ,CAAC,OAAO,CAAC,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,GAAG,SAAS,CAAC;IAChE,yCAAyC;IACzC,QAAQ,CAAC,MAAM,CAAC,EAAE,WAAW,GAAG,SAAS,CAAC;CAC3C;AAED,+FAA+F;AAC/F,MAAM,WAAW,iBAAiB;IAChC,QAAQ,CAAC,EAAE,EAAE,OAAO,CAAC;IACrB,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,iEAAiE;IACjE,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;IACrB,IAAI,IAAI,OAAO,CAAC,MAAM,CAAC,CAAC;IACxB,IAAI,IAAI,OAAO,CAAC,OAAO,CAAC,CAAC;CAC1B;AAED,0DAA0D;AAC1D,MAAM,MAAM,SAAS,GAAG,CAAC,GAAG,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,aAAa,KAAK,OAAO,CAAC,iBAAiB,CAAC,CAAC;AAE1F,qFAAqF;AACrF,MAAM,WAAW,iBAAiB;IAChC,oHAAoH;IACpH,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,4EAA4E;IAC5E,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;CAC1B;AAED,iHAAiH;AACjH,MAAM,WAAW,gBAAiB,SAAQ,iBAAiB;IACzD;;;;;;;OAOG;IACH,QAAQ,CAAC,aAAa,CAAC,EAAE,iBAAiB,GAAG,SAAS,CAAC;CACxD;AAsBD;;;;;;;;GAQG;AACH,wBAAgB,eAAe,CAAC,OAAO,GAAE,gBAAqB,GAAG,SAAS,CA6BzE"}
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A `fetch` for GET requests that goes through the host policy (audit pass 2, O55).
|
|
3
|
+
*
|
|
4
|
+
* A procedure of another package that reads a URL of its caller uses this function in place of
|
|
5
|
+
* the global `fetch`: `weather.forecast`, and the modules of `@procedures/geo` and
|
|
6
|
+
* `@procedures/ics` that a host makes with it. The request has the same checks as `http.request`:
|
|
7
|
+
*
|
|
8
|
+
* - The host of the URL and of each redirect must pass the host policy. The default policy
|
|
9
|
+
* refuses loopback, private, link-local and the other special addresses.
|
|
10
|
+
* - The connection uses only the addresses that the check allowed (DNS rebinding).
|
|
11
|
+
* - The body of the response has the size limit of the settings.
|
|
12
|
+
*
|
|
13
|
+
* A refusal is `FORBIDDEN` with the reason `host-not-allowed` (`isHostNotAllowed`). When the
|
|
14
|
+
* signal of the caller aborts, the function throws the reason of the signal, as `fetch` does.
|
|
15
|
+
*
|
|
16
|
+
* The option `warnOnRefusal` keeps the behavior before the host policy, for the default modules
|
|
17
|
+
* of 0.28: a refused host gets a deprecation notice and the global `fetch`. Version 0.29.0 removes it.
|
|
18
|
+
*/
|
|
19
|
+
import { httpSettings } from "./module.js";
|
|
20
|
+
import { isHostNotAllowed } from "./policy.js";
|
|
21
|
+
import { httpRequest } from "./procedures/http/request.js";
|
|
22
|
+
/** The longest time of a request of `http.request`: the signal of the caller is the real limit. */
|
|
23
|
+
const LONGEST_MS = 86_400_000;
|
|
24
|
+
/** The codes of the notices that this process emitted. */
|
|
25
|
+
const emitted = new Set();
|
|
26
|
+
/** This function emits a deprecation notice one time in each process, with its code. */
|
|
27
|
+
function emitOnce(notice) {
|
|
28
|
+
if (emitted.has(notice.code))
|
|
29
|
+
return;
|
|
30
|
+
emitted.add(notice.code);
|
|
31
|
+
if (typeof process !== "undefined" && typeof process.emitWarning === "function") {
|
|
32
|
+
process.emitWarning(notice.message, { type: "DeprecationWarning", code: notice.code });
|
|
33
|
+
}
|
|
34
|
+
else {
|
|
35
|
+
console.warn(`[${notice.code}] ${notice.message}`);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
/** This function gives the parts of a `Response` of the global `fetch` that the procedures use. */
|
|
39
|
+
async function globalFetch(url, init) {
|
|
40
|
+
const response = await fetch(url, { ...(init.headers !== undefined ? { headers: { ...init.headers } } : {}), ...(init.signal !== undefined ? { signal: init.signal } : {}) });
|
|
41
|
+
return response;
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* This function gives a `fetch` for GET requests through the host policy of the options. The
|
|
45
|
+
* options are the options of `createHttpModule()`. Without options, the policy is the default
|
|
46
|
+
* policy: each public host, and no other host. A bad entry of `allow` throws here.
|
|
47
|
+
*
|
|
48
|
+
* ```ts
|
|
49
|
+
* const forecast = createWeatherModule({ fetch: createHostFetch({ allow: ["localhost:8080"] }) });
|
|
50
|
+
* ```
|
|
51
|
+
*/
|
|
52
|
+
export function createHostFetch(options = {}) {
|
|
53
|
+
const { warnOnRefusal, ...policyOptions } = options;
|
|
54
|
+
const settings = httpSettings(policyOptions);
|
|
55
|
+
return async (url, init = {}) => {
|
|
56
|
+
let output;
|
|
57
|
+
try {
|
|
58
|
+
output = await httpRequest({ url, method: "GET", ...(init.headers !== undefined ? { headers: { ...init.headers } } : {}), responseType: "text", timeoutMs: LONGEST_MS }, { signal: init.signal }, settings);
|
|
59
|
+
}
|
|
60
|
+
catch (error) {
|
|
61
|
+
if (init.signal?.aborted)
|
|
62
|
+
throw init.signal.reason;
|
|
63
|
+
// Before the host policy, the request went to each host (O55). The notice names the change.
|
|
64
|
+
if (warnOnRefusal !== undefined && isHostNotAllowed(error)) {
|
|
65
|
+
emitOnce(warnOnRefusal);
|
|
66
|
+
return globalFetch(url, init);
|
|
67
|
+
}
|
|
68
|
+
throw error;
|
|
69
|
+
}
|
|
70
|
+
const text = typeof output.body === "string" ? output.body : "";
|
|
71
|
+
return {
|
|
72
|
+
ok: output.ok,
|
|
73
|
+
status: output.status,
|
|
74
|
+
url: output.url,
|
|
75
|
+
text: async () => text,
|
|
76
|
+
json: async () => JSON.parse(text),
|
|
77
|
+
};
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
//# sourceMappingURL=host-fetch.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"host-fetch.js","sourceRoot":"","sources":["../src/host-fetch.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AAGH,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAC3C,OAAO,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAC/C,OAAO,EAAE,WAAW,EAAE,MAAM,8BAA8B,CAAC;AAE3D,mGAAmG;AACnG,MAAM,UAAU,GAAG,UAAU,CAAC;AA4C9B,0DAA0D;AAC1D,MAAM,OAAO,GAAG,IAAI,GAAG,EAAU,CAAC;AAElC,wFAAwF;AACxF,SAAS,QAAQ,CAAC,MAAyB;IACzC,IAAI,OAAO,CAAC,GAAG,CAAC,MAAM,CAAC,IAAI,CAAC;QAAE,OAAO;IACrC,OAAO,CAAC,GAAG,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;IACzB,IAAI,OAAO,OAAO,KAAK,WAAW,IAAI,OAAO,OAAO,CAAC,WAAW,KAAK,UAA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,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,YAAY,EAAE,MAAM,EAAE,SAAS,EAAE,UAAU,EAAE,EAC5I,EAAE,MAAM,EAAE,IAAI,CAAC,MAAM,EAAE,EACvB,QAAQ,CACT,CAAC;QACJ,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,IAAI,IAAI,CAAC,MAAM,EAAE,OAAO;gBAAE,MAAM,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC;YACnD,4FAA4F;YAC5F,IAAI,aAAa,KAAK,SAAS,IAAI,gBAAgB,CAAC,KAAK,CAAC,EAAE,CAAC;gBAC3D,QAAQ,CAAC,aAAa,CAAC,CAAC;gBACxB,OAAO,WAAW,CAAC,GAAG,EAAE,IAAI,CAAC,CAAC;YAChC,CAAC;YACD,MAAM,KAAK,CAAC;QACd,CAAC;QACD,MAAM,IAAI,GAAG,OAAO,MAAM,CAAC,IAAI,KAAK,QAAQ,CAAC,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC;QAChE,OAAO;YACL,EAAE,EAAE,MAAM,CAAC,EAAE;YACb,MAAM,EAAE,MAAM,CAAC,MAAM;YACrB,GAAG,EAAE,MAAM,CAAC,GAAG;YACf,IAAI,EAAE,KAAK,IAAI,EAAE,CAAC,IAAI;YACtB,IAAI,EAAE,KAAK,IAAI,EAAE,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,CAAY;SAC9C,CAAC;IACJ,CAAC,CAAC;AACJ,CAAC"}
|
package/dist/index.d.ts
CHANGED
|
@@ -2,6 +2,7 @@ export * from "./module.js";
|
|
|
2
2
|
export * from "./types.js";
|
|
3
3
|
export { httpRequest, httpJson, httpNdjson, httpSse } from "./procedures/http/index.js";
|
|
4
4
|
export { HOST_NOT_ALLOWED, DEFAULT_HOST_POLICY, createHostPolicy, checkHost, isHostNotAllowed, systemResolver } from "./policy.js";
|
|
5
|
+
export { createHostFetch, type DeprecationNotice, type HostFetch, type HostFetchInit, type HostFetchOptions, type HostFetchResponse } from "./host-fetch.js";
|
|
5
6
|
export type { AllowedTarget, HostPolicy, HostPolicyOptions, HostResolver, ResolvedAddress } from "./policy.js";
|
|
6
7
|
export { isPublicAddress, parseAddress, specialClass } from "./address.js";
|
|
7
8
|
export { HttpError, type HttpErrorCode } from "./errors.js";
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,cAAc,aAAa,CAAC;AAC5B,cAAc,YAAY,CAAC;AAC3B,OAAO,EAAE,WAAW,EAAE,QAAQ,EAAE,UAAU,EAAE,OAAO,EAAE,MAAM,4BAA4B,CAAC;AAExF,OAAO,EAAE,gBAAgB,EAAE,mBAAmB,EAAE,gBAAgB,EAAE,SAAS,EAAE,gBAAgB,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,cAAc,aAAa,CAAC;AAC5B,cAAc,YAAY,CAAC;AAC3B,OAAO,EAAE,WAAW,EAAE,QAAQ,EAAE,UAAU,EAAE,OAAO,EAAE,MAAM,4BAA4B,CAAC;AAExF,OAAO,EAAE,gBAAgB,EAAE,mBAAmB,EAAE,gBAAgB,EAAE,SAAS,EAAE,gBAAgB,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAEnI,OAAO,EAAE,eAAe,EAAE,KAAK,iBAAiB,EAAE,KAAK,SAAS,EAAE,KAAK,aAAa,EAAE,KAAK,gBAAgB,EAAE,KAAK,iBAAiB,EAAE,MAAM,iBAAiB,CAAC;AAC7J,YAAY,EAAE,aAAa,EAAE,UAAU,EAAE,iBAAiB,EAAE,YAAY,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAC/G,OAAO,EAAE,eAAe,EAAE,YAAY,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAC3E,OAAO,EAAE,SAAS,EAAE,KAAK,aAAa,EAAE,MAAM,aAAa,CAAC;AAC5D,OAAO,EAAE,iBAAiB,EAAE,kBAAkB,EAAE,kBAAkB,EAAE,gBAAgB,EAAE,KAAK,YAAY,EAAE,MAAM,eAAe,CAAC;AAC/H,OAAO,EAAE,WAAW,EAAE,SAAS,EAAE,KAAK,UAAU,EAAE,KAAK,eAAe,EAAE,MAAM,cAAc,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -4,6 +4,8 @@ export * from "./types.js";
|
|
|
4
4
|
export { httpRequest, httpJson, httpNdjson, httpSse } from "./procedures/http/index.js";
|
|
5
5
|
// The host policy (roadmap R38)
|
|
6
6
|
export { HOST_NOT_ALLOWED, DEFAULT_HOST_POLICY, createHostPolicy, checkHost, isHostNotAllowed, systemResolver } from "./policy.js";
|
|
7
|
+
// A fetch for GET requests through the host policy, for the procedures of other packages (O55)
|
|
8
|
+
export { createHostFetch } from "./host-fetch.js";
|
|
7
9
|
export { isPublicAddress, parseAddress, specialClass } from "./address.js";
|
|
8
10
|
export { HttpError } from "./errors.js";
|
|
9
11
|
export { DEFAULT_MAX_BYTES, DEFAULT_ITEM_BYTES, DEFAULT_TIMEOUT_MS, DEFAULT_SETTINGS } from "./exchange.js";
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,kGAAkG;AAClG,cAAc,aAAa,CAAC;AAC5B,cAAc,YAAY,CAAC;AAC3B,OAAO,EAAE,WAAW,EAAE,QAAQ,EAAE,UAAU,EAAE,OAAO,EAAE,MAAM,4BAA4B,CAAC;AACxF,gCAAgC;AAChC,OAAO,EAAE,gBAAgB,EAAE,mBAAmB,EAAE,gBAAgB,EAAE,SAAS,EAAE,gBAAgB,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,kGAAkG;AAClG,cAAc,aAAa,CAAC;AAC5B,cAAc,YAAY,CAAC;AAC3B,OAAO,EAAE,WAAW,EAAE,QAAQ,EAAE,UAAU,EAAE,OAAO,EAAE,MAAM,4BAA4B,CAAC;AACxF,gCAAgC;AAChC,OAAO,EAAE,gBAAgB,EAAE,mBAAmB,EAAE,gBAAgB,EAAE,SAAS,EAAE,gBAAgB,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AACnI,+FAA+F;AAC/F,OAAO,EAAE,eAAe,EAA6G,MAAM,iBAAiB,CAAC;AAE7J,OAAO,EAAE,eAAe,EAAE,YAAY,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAC3E,OAAO,EAAE,SAAS,EAAsB,MAAM,aAAa,CAAC;AAC5D,OAAO,EAAE,iBAAiB,EAAE,kBAAkB,EAAE,kBAAkB,EAAE,gBAAgB,EAAqB,MAAM,eAAe,CAAC;AAC/H,OAAO,EAAE,WAAW,EAAE,SAAS,EAAyC,MAAM,cAAc,CAAC"}
|
package/dist/module.d.ts
CHANGED
|
@@ -7,6 +7,7 @@
|
|
|
7
7
|
* gives the same procedures with another host policy or other size limits (roadmap R38).
|
|
8
8
|
*/
|
|
9
9
|
import { type ProcedureModule, type ProcedureRegistry } from "@procedures/client";
|
|
10
|
+
import { type HttpSettings } from "./exchange.js";
|
|
10
11
|
import { type HostPolicyOptions } from "./policy.js";
|
|
11
12
|
/**
|
|
12
13
|
* The module of this package, for `createRegistry()`: its procedures as data. It reaches each
|
|
@@ -33,6 +34,8 @@ export interface HttpModuleOptions extends HostPolicyOptions {
|
|
|
33
34
|
* ```
|
|
34
35
|
*/
|
|
35
36
|
export declare function createHttpModule(options?: HttpModuleOptions): ProcedureModule;
|
|
37
|
+
/** This function gives the settings of the options: the host policy and the size limits. A bad entry of `allow` throws. */
|
|
38
|
+
export declare function httpSettings(options?: HttpModuleOptions): HttpSettings;
|
|
36
39
|
/**
|
|
37
40
|
* This function registers the procedures of @procedures/http in a registry. The default is the
|
|
38
41
|
* global registry. The options are the options of `createHttpModule()`.
|
package/dist/module.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"module.d.ts","sourceRoot":"","sources":["../src/module.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAGH,OAAO,EASL,KAAK,eAAe,EACpB,KAAK,iBAAiB,EACvB,MAAM,oBAAoB,CAAC;
|
|
1
|
+
{"version":3,"file":"module.d.ts","sourceRoot":"","sources":["../src/module.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAGH,OAAO,EASL,KAAK,eAAe,EACpB,KAAK,iBAAiB,EACvB,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAAuC,KAAK,YAAY,EAAE,MAAM,eAAe,CAAC;AACvF,OAAO,EAAoB,KAAK,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAiMvE;;;;GAIG;AACH,eAAO,MAAM,UAAU,EAAE,eAAoF,CAAC;eAE/F,UAAU;AAEzB,4FAA4F;AAC5F,MAAM,WAAW,iBAAkB,SAAQ,iBAAiB;IAC1D,sEAAsE;IACtE,QAAQ,CAAC,eAAe,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IAC9C,kGAAkG;IAClG,QAAQ,CAAC,gBAAgB,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;CAChD;AAED;;;;;;;;;GASG;AACH,wBAAgB,gBAAgB,CAAC,OAAO,GAAE,iBAAsB,GAAG,eAAe,CAGjF;AAED,2HAA2H;AAC3H,wBAAgB,YAAY,CAAC,OAAO,GAAE,iBAAsB,GAAG,YAAY,CAO1E;AAED;;;GAGG;AACH,wBAAgB,sBAAsB,CAAC,QAAQ,GAAE,iBAAsC,EAAE,OAAO,GAAE,iBAAsB,GAAG,IAAI,CAE9H"}
|
package/dist/module.js
CHANGED
|
@@ -192,12 +192,17 @@ export default httpModule;
|
|
|
192
192
|
export function createHttpModule(options = {}) {
|
|
193
193
|
if (Object.values(options).every((value) => value === undefined))
|
|
194
194
|
return httpModule;
|
|
195
|
-
|
|
195
|
+
return defineModule("@procedures/http", httpProcedures(httpSettings(options)));
|
|
196
|
+
}
|
|
197
|
+
/** This function gives the settings of the options: the host policy and the size limits. A bad entry of `allow` throws. */
|
|
198
|
+
export function httpSettings(options = {}) {
|
|
199
|
+
if (Object.values(options).every((value) => value === undefined))
|
|
200
|
+
return DEFAULT_SETTINGS;
|
|
201
|
+
return {
|
|
196
202
|
policy: createHostPolicy(options),
|
|
197
203
|
maxRequestBytes: options.maxRequestBytes ?? DEFAULT_MAX_BYTES,
|
|
198
204
|
maxResponseBytes: options.maxResponseBytes ?? DEFAULT_MAX_BYTES,
|
|
199
205
|
};
|
|
200
|
-
return defineModule("@procedures/http", httpProcedures(settings));
|
|
201
206
|
}
|
|
202
207
|
/**
|
|
203
208
|
* This function registers the procedures of @procedures/http in a registry. The default is the
|
package/dist/module.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"module.js","sourceRoot":"","sources":["../src/module.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EACL,YAAY,EACZ,eAAe,EACf,kBAAkB,EAClB,eAAe,EACf,UAAU,GAMX,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAAE,iBAAiB,EAAE,gBAAgB,EAAqB,MAAM,eAAe,CAAC;AACvF,OAAO,EAAE,gBAAgB,EAA0B,MAAM,aAAa,CAAC;AAEvE,OAAO,EAAE,WAAW,EAAE,MAAM,8BAA8B,CAAC;AAC3D,OAAO,EAAE,QAAQ,EAAE,MAAM,2BAA2B,CAAC;AACrD,OAAO,EAAE,UAAU,EAAE,MAAM,6BAA6B,CAAC;AACzD,OAAO,EAAE,OAAO,EAAE,MAAM,0BAA0B,CAAC;AAYnD,gFAAgF;AAChF,UAAU;AACV,gFAAg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AC,CAAC,CAAC,CAAC;AACzD,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"$schema": "https://json.schemastore.org/package",
|
|
3
3
|
"name": "@procedures/http",
|
|
4
|
-
"version": "0.28.
|
|
4
|
+
"version": "0.28.1",
|
|
5
5
|
"description": "HTTP as procedures: request, JSON, NDJSON and server-sent events, with a host allowlist that refuses private addresses, size limits and the deadline of the call.",
|
|
6
6
|
"keywords": [
|
|
7
7
|
"procedures",
|
|
@@ -69,7 +69,7 @@
|
|
|
69
69
|
"procedures": "./dist/register.js"
|
|
70
70
|
},
|
|
71
71
|
"dependencies": {
|
|
72
|
-
"@procedures/client": "0.28.
|
|
72
|
+
"@procedures/client": "0.28.1",
|
|
73
73
|
"zod": "^4.6.5"
|
|
74
74
|
},
|
|
75
75
|
"scripts": {
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A `fetch` for GET requests that goes through the host policy (audit pass 2, O55).
|
|
3
|
+
*
|
|
4
|
+
* A procedure of another package that reads a URL of its caller uses this function in place of
|
|
5
|
+
* the global `fetch`: `weather.forecast`, and the modules of `@procedures/geo` and
|
|
6
|
+
* `@procedures/ics` that a host makes with it. The request has the same checks as `http.request`:
|
|
7
|
+
*
|
|
8
|
+
* - The host of the URL and of each redirect must pass the host policy. The default policy
|
|
9
|
+
* refuses loopback, private, link-local and the other special addresses.
|
|
10
|
+
* - The connection uses only the addresses that the check allowed (DNS rebinding).
|
|
11
|
+
* - The body of the response has the size limit of the settings.
|
|
12
|
+
*
|
|
13
|
+
* A refusal is `FORBIDDEN` with the reason `host-not-allowed` (`isHostNotAllowed`). When the
|
|
14
|
+
* signal of the caller aborts, the function throws the reason of the signal, as `fetch` does.
|
|
15
|
+
*
|
|
16
|
+
* The option `warnOnRefusal` keeps the behavior before the host policy, for the default modules
|
|
17
|
+
* of 0.28: a refused host gets a deprecation notice and the global `fetch`. Version 0.29.0 removes it.
|
|
18
|
+
*/
|
|
19
|
+
|
|
20
|
+
import type { HttpModuleOptions } from "./module.js";
|
|
21
|
+
import { httpSettings } from "./module.js";
|
|
22
|
+
import { isHostNotAllowed } from "./policy.js";
|
|
23
|
+
import { httpRequest } from "./procedures/http/request.js";
|
|
24
|
+
|
|
25
|
+
/** The longest time of a request of `http.request`: the signal of the caller is the real limit. */
|
|
26
|
+
const LONGEST_MS = 86_400_000;
|
|
27
|
+
|
|
28
|
+
/** The options of one request. */
|
|
29
|
+
export interface HostFetchInit {
|
|
30
|
+
/** The headers of the request. */
|
|
31
|
+
readonly headers?: Readonly<Record<string, string>> | undefined;
|
|
32
|
+
/** The signal that stops the request. */
|
|
33
|
+
readonly signal?: AbortSignal | undefined;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/** The response of a request: the parts of a `Response` of `fetch` that the procedures use. */
|
|
37
|
+
export interface HostFetchResponse {
|
|
38
|
+
readonly ok: boolean;
|
|
39
|
+
readonly status: number;
|
|
40
|
+
/** The URL of the response: the last URL after the redirects. */
|
|
41
|
+
readonly url: string;
|
|
42
|
+
text(): Promise<string>;
|
|
43
|
+
json(): Promise<unknown>;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/** A `fetch` for GET requests through the host policy. */
|
|
47
|
+
export type HostFetch = (url: string, init?: HostFetchInit) => Promise<HostFetchResponse>;
|
|
48
|
+
|
|
49
|
+
/** A deprecation notice: the code and the text of a `DeprecationWarning` of Node. */
|
|
50
|
+
export interface DeprecationNotice {
|
|
51
|
+
/** The code of the warning, for example `PROCEDURES_WEATHER_PRIVATE_HOST`. The process emits each code one time. */
|
|
52
|
+
readonly code: string;
|
|
53
|
+
/** The text of the warning. It names the change that removes the notice. */
|
|
54
|
+
readonly message: string;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/** The options of `createHostFetch()`: the options of `createHttpModule()`, and the notice of a refused host. */
|
|
58
|
+
export interface HostFetchOptions extends HttpModuleOptions {
|
|
59
|
+
/**
|
|
60
|
+
* The notice of a refused host. With this option, a refused host does not throw. The function
|
|
61
|
+
* emits the notice one time in each process. Then it sends the request with the global `fetch`,
|
|
62
|
+
* as before the host policy. Without this option, a refused host throws `FORBIDDEN`.
|
|
63
|
+
*
|
|
64
|
+
* @deprecated The default modules of `weather`, `geo` and `ics` use it in 0.28 only. Version
|
|
65
|
+
* 0.29.0 removes it. Then a refused host always throws.
|
|
66
|
+
*/
|
|
67
|
+
readonly warnOnRefusal?: DeprecationNotice | undefined;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/** The codes of the notices that this process emitted. */
|
|
71
|
+
const emitted = new Set<string>();
|
|
72
|
+
|
|
73
|
+
/** This function emits a deprecation notice one time in each process, with its code. */
|
|
74
|
+
function emitOnce(notice: DeprecationNotice): void {
|
|
75
|
+
if (emitted.has(notice.code)) return;
|
|
76
|
+
emitted.add(notice.code);
|
|
77
|
+
if (typeof process !== "undefined" && typeof process.emitWarning === "function") {
|
|
78
|
+
process.emitWarning(notice.message, { type: "DeprecationWarning", code: notice.code });
|
|
79
|
+
} else {
|
|
80
|
+
console.warn(`[${notice.code}] ${notice.message}`);
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/** This function gives the parts of a `Response` of the global `fetch` that the procedures use. */
|
|
85
|
+
async function globalFetch(url: string, init: HostFetchInit): Promise<HostFetchResponse> {
|
|
86
|
+
const response = await fetch(url, { ...(init.headers !== undefined ? { headers: { ...init.headers } } : {}), ...(init.signal !== undefined ? { signal: init.signal } : {}) });
|
|
87
|
+
return response;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
/**
|
|
91
|
+
* This function gives a `fetch` for GET requests through the host policy of the options. The
|
|
92
|
+
* options are the options of `createHttpModule()`. Without options, the policy is the default
|
|
93
|
+
* policy: each public host, and no other host. A bad entry of `allow` throws here.
|
|
94
|
+
*
|
|
95
|
+
* ```ts
|
|
96
|
+
* const forecast = createWeatherModule({ fetch: createHostFetch({ allow: ["localhost:8080"] }) });
|
|
97
|
+
* ```
|
|
98
|
+
*/
|
|
99
|
+
export function createHostFetch(options: HostFetchOptions = {}): HostFetch {
|
|
100
|
+
const { warnOnRefusal, ...policyOptions } = options;
|
|
101
|
+
const settings = httpSettings(policyOptions);
|
|
102
|
+
return async (url, init = {}) => {
|
|
103
|
+
let output;
|
|
104
|
+
try {
|
|
105
|
+
output = await httpRequest(
|
|
106
|
+
{ url, method: "GET", ...(init.headers !== undefined ? { headers: { ...init.headers } } : {}), responseType: "text", timeoutMs: LONGEST_MS },
|
|
107
|
+
{ signal: init.signal },
|
|
108
|
+
settings,
|
|
109
|
+
);
|
|
110
|
+
} catch (error) {
|
|
111
|
+
if (init.signal?.aborted) throw init.signal.reason;
|
|
112
|
+
// Before the host policy, the request went to each host (O55). The notice names the change.
|
|
113
|
+
if (warnOnRefusal !== undefined && isHostNotAllowed(error)) {
|
|
114
|
+
emitOnce(warnOnRefusal);
|
|
115
|
+
return globalFetch(url, init);
|
|
116
|
+
}
|
|
117
|
+
throw error;
|
|
118
|
+
}
|
|
119
|
+
const text = typeof output.body === "string" ? output.body : "";
|
|
120
|
+
return {
|
|
121
|
+
ok: output.ok,
|
|
122
|
+
status: output.status,
|
|
123
|
+
url: output.url,
|
|
124
|
+
text: async () => text,
|
|
125
|
+
json: async () => JSON.parse(text) as unknown,
|
|
126
|
+
};
|
|
127
|
+
};
|
|
128
|
+
}
|
package/src/index.ts
CHANGED
|
@@ -4,6 +4,8 @@ export * from "./types.js";
|
|
|
4
4
|
export { httpRequest, httpJson, httpNdjson, httpSse } from "./procedures/http/index.js";
|
|
5
5
|
// The host policy (roadmap R38)
|
|
6
6
|
export { HOST_NOT_ALLOWED, DEFAULT_HOST_POLICY, createHostPolicy, checkHost, isHostNotAllowed, systemResolver } from "./policy.js";
|
|
7
|
+
// A fetch for GET requests through the host policy, for the procedures of other packages (O55)
|
|
8
|
+
export { createHostFetch, type DeprecationNotice, type HostFetch, type HostFetchInit, type HostFetchOptions, type HostFetchResponse } from "./host-fetch.js";
|
|
7
9
|
export type { AllowedTarget, HostPolicy, HostPolicyOptions, HostResolver, ResolvedAddress } from "./policy.js";
|
|
8
10
|
export { isPublicAddress, parseAddress, specialClass } from "./address.js";
|
|
9
11
|
export { HttpError, type HttpErrorCode } from "./errors.js";
|
package/src/module.ts
CHANGED
|
@@ -243,12 +243,17 @@ export interface HttpModuleOptions extends HostPolicyOptions {
|
|
|
243
243
|
*/
|
|
244
244
|
export function createHttpModule(options: HttpModuleOptions = {}): ProcedureModule {
|
|
245
245
|
if (Object.values(options).every((value) => value === undefined)) return httpModule;
|
|
246
|
-
|
|
246
|
+
return defineModule("@procedures/http", httpProcedures(httpSettings(options)));
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
/** This function gives the settings of the options: the host policy and the size limits. A bad entry of `allow` throws. */
|
|
250
|
+
export function httpSettings(options: HttpModuleOptions = {}): HttpSettings {
|
|
251
|
+
if (Object.values(options).every((value) => value === undefined)) return DEFAULT_SETTINGS;
|
|
252
|
+
return {
|
|
247
253
|
policy: createHostPolicy(options),
|
|
248
254
|
maxRequestBytes: options.maxRequestBytes ?? DEFAULT_MAX_BYTES,
|
|
249
255
|
maxResponseBytes: options.maxResponseBytes ?? DEFAULT_MAX_BYTES,
|
|
250
256
|
};
|
|
251
|
-
return defineModule("@procedures/http", httpProcedures(settings));
|
|
252
257
|
}
|
|
253
258
|
|
|
254
259
|
/**
|