@procedures/http 0.69.1 → 0.69.3

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 CHANGED
@@ -1,5 +1,22 @@
1
1
  # @procedures/http
2
2
 
3
+ ## 0.69.3
4
+
5
+ ### Patch Changes
6
+
7
+ - 2db33f1: A request of a map data procedure that the host policy refuses takes no turn of the pace. Before, the refusal waited for the rest of the host, and the next request to the host waited for the refusal.
8
+
9
+ - `geoSend` examines the method and the host policy before the pace. It starts the new optional member `check` of the fetch.
10
+ - The fetch of `createHostFetch()` has `check`. It examines a URL with the host policy and sends nothing. The new type is `HostFetchCheck`.
11
+ - `createGeoPace(clock)` makes a pace on a clock. The default is the real clock. `geoPace()` uses it.
12
+ - @procedures/client@0.69.3
13
+
14
+ ## 0.69.2
15
+
16
+ ### Patch Changes
17
+
18
+ - @procedures/client@0.69.2
19
+
3
20
  ## 0.69.1
4
21
 
5
22
  ### Patch Changes
package/README.md CHANGED
@@ -107,6 +107,8 @@ const registry = createRegistry(createGeoModule({ fetch: createHostFetch({ allow
107
107
 
108
108
  A refusal is `FORBIDDEN` with the reason `host-not-allowed`. When the signal of the caller aborts, the function throws the reason of the signal, as `fetch` does.
109
109
 
110
+ The member `check(url, { method })` of the fetch examines a URL with the same rules, and sends no request. It throws the refusal of the fetch, and nothing for a different fault. A caller with a pace starts it before the pace, so a refusal does not wait. `geoSend` of `@procedures/geo` does this.
111
+
110
112
  The response has `headers`, with names in lowercase. The option `method: "HEAD"` reads only the headers of a page, for example for `frameRefusal`:
111
113
 
112
114
  ```ts
@@ -56,8 +56,21 @@ export interface HostFetchResponse {
56
56
  text(): Promise<string>;
57
57
  json(): Promise<unknown>;
58
58
  }
59
- /** A `fetch` for GET and HEAD requests, and for a POST that only reads, through the host policy. */
60
- export type HostFetch = (url: string, init?: HostFetchInit) => Promise<HostFetchResponse>;
59
+ /**
60
+ * This function examines a URL and a method with the host policy of a `HostFetch`, and sends no
61
+ * request. It throws the `FORBIDDEN` refusal that the fetch throws. For each other fault, for
62
+ * example a host with no address, it throws nothing: the fetch gives that error.
63
+ *
64
+ * A caller with a pace examines a URL before it takes a turn of the host. Thus a refusal does not wait, and the host gets no rest.
65
+ */
66
+ export type HostFetchCheck = (url: string, init?: Pick<HostFetchInit, "method">) => Promise<void>;
67
+ /**
68
+ * A `fetch` for GET and HEAD requests, and for a POST that only reads, through the host policy. The
69
+ * fetch of `createHostFetch()` has the member `check`. Another `HostFetch` can have no `check`.
70
+ */
71
+ export type HostFetch = ((url: string, init?: HostFetchInit) => Promise<HostFetchResponse>) & {
72
+ readonly check?: HostFetchCheck | undefined;
73
+ };
61
74
  /**
62
75
  * This function gives a `fetch` for GET and HEAD requests through the host policy of the options. The
63
76
  * options are the options of `createHttpModule()`. Without options, the policy is the default
@@ -66,11 +79,14 @@ export type HostFetch = (url: string, init?: HostFetchInit) => Promise<HostFetch
66
79
  *
67
80
  * - The fetch throws `FORBIDDEN` with the reason `host-not-allowed` for a POST to a host that is not in `readOnlyPost`.
68
81
  * - The fetch throws an `Error` for a body with a method other than POST.
82
+ * - The member `check` examines a URL with the same rules, and sends nothing (`HostFetchCheck`).
69
83
  *
70
84
  * ```ts
71
85
  * const forecast = createWeatherModule({ fetch: createHostFetch({ allow: ["localhost:8080"] }) });
72
86
  * const soil = createGeoModule({ fetch: createHostFetch({ readOnlyPost: ["sdmdataaccess.sc.egov.usda.gov"] }) });
73
87
  * ```
74
88
  */
75
- export declare function createHostFetch(options?: HostFetchOptions): HostFetch;
89
+ export declare function createHostFetch(options?: HostFetchOptions): HostFetch & {
90
+ readonly check: HostFetchCheck;
91
+ };
76
92
  //# sourceMappingURL=host-fetch.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"host-fetch.d.ts","sourceRoot":"","sources":["../src/host-fetch.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;GAqBG;AAEH,OAAO,KAAK,EAAE,iBAAiB,EAAE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C,GAAG,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,IAAI,CAAC,aAAa,EAAE,QAAQ,CAAC,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;AAElG;;;GAGG;AACH,MAAM,MAAM,SAAS,GAAG,CAAC,CAAC,GAAG,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,aAAa,KAAK,OAAO,CAAC,iBAAiB,CAAC,CAAC,GAAG;IAC5F,QAAQ,CAAC,KAAK,CAAC,EAAE,cAAc,GAAG,SAAS,CAAC;CAC7C,CAAC;AAKF;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,eAAe,CAAC,OAAO,GAAE,gBAAqB,GAAG,SAAS,GAAG;IAAE,QAAQ,CAAC,KAAK,EAAE,cAAc,CAAA;CAAE,CAiE9G"}
@@ -21,7 +21,7 @@
21
21
  * signal of the caller aborts, the function throws the reason of the signal, as `fetch` does.
22
22
  */
23
23
  import { httpSettings } from "./module.js";
24
- import { hostNotAllowed, portOf } from "./policy.js";
24
+ import { checkHost, hostNotAllowed, isHostNotAllowed, portOf } from "./policy.js";
25
25
  import { httpRequest } from "./procedures/http/request.js";
26
26
  /** The longest time of a request of `http.request`: the signal of the caller is the real limit. */
27
27
  const LONGEST_MS = 86_400_000;
@@ -56,6 +56,8 @@ function takesPost(entries, url) {
56
56
  const port = portOf(url);
57
57
  return entries.some((entry) => entry.hostname === hostname && (entry.port === undefined || entry.port === port));
58
58
  }
59
+ /** The procedure of the refusals of `createHostFetch()`: the refusals of `http.request`. */
60
+ const REQUEST_PATH = ["http", "request"];
59
61
  /**
60
62
  * This function gives a `fetch` for GET and HEAD requests through the host policy of the options. The
61
63
  * options are the options of `createHttpModule()`. Without options, the policy is the default
@@ -64,6 +66,7 @@ function takesPost(entries, url) {
64
66
  *
65
67
  * - The fetch throws `FORBIDDEN` with the reason `host-not-allowed` for a POST to a host that is not in `readOnlyPost`.
66
68
  * - The fetch throws an `Error` for a body with a method other than POST.
69
+ * - The member `check` examines a URL with the same rules, and sends nothing (`HostFetchCheck`).
67
70
  *
68
71
  * ```ts
69
72
  * const forecast = createWeatherModule({ fetch: createHostFetch({ allow: ["localhost:8080"] }) });
@@ -73,7 +76,28 @@ function takesPost(entries, url) {
73
76
  export function createHostFetch(options = {}) {
74
77
  const settings = httpSettings(options);
75
78
  const postEntries = (options.readOnlyPost ?? []).map(parsePostEntry);
76
- return async (url, init = {}) => {
79
+ const check = async (url, init = {}) => {
80
+ let target;
81
+ try {
82
+ target = new URL(url);
83
+ }
84
+ catch {
85
+ return;
86
+ }
87
+ if (target.protocol !== "http:" && target.protocol !== "https:")
88
+ return;
89
+ if (init.method === "POST" && !takesPost(postEntries, target)) {
90
+ throw hostNotAllowed(REQUEST_PATH, `the host ${bareHostname(target)}:${portOf(target)} takes no POST: it is not in readOnlyPost of createHostFetch`);
91
+ }
92
+ try {
93
+ await checkHost(settings.policy, target, REQUEST_PATH);
94
+ }
95
+ catch (error) {
96
+ if (isHostNotAllowed(error))
97
+ throw error;
98
+ }
99
+ };
100
+ const hostFetch = async (url, init = {}) => {
77
101
  const method = init.method ?? "GET";
78
102
  if (init.body !== undefined && method !== "POST")
79
103
  throw new Error(`A ${method} request of createHostFetch has no body: a body needs the method POST`);
@@ -86,7 +110,7 @@ export function createHostFetch(options = {}) {
86
110
  throw new Error(`The URL ${JSON.stringify(url)} of the POST is not a URL`, { cause: error });
87
111
  }
88
112
  if (!takesPost(postEntries, target)) {
89
- throw hostNotAllowed(["http", "request"], `the host ${bareHostname(target)}:${portOf(target)} takes no POST: it is not in readOnlyPost of createHostFetch`);
113
+ throw hostNotAllowed(REQUEST_PATH, `the host ${bareHostname(target)}:${portOf(target)} takes no POST: it is not in readOnlyPost of createHostFetch`);
90
114
  }
91
115
  }
92
116
  let output;
@@ -117,5 +141,6 @@ export function createHostFetch(options = {}) {
117
141
  json: async () => JSON.parse(text),
118
142
  };
119
143
  };
144
+ return Object.assign(hostFetch, { check });
120
145
  }
121
146
  //# sourceMappingURL=host-fet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M,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,OAAO,EAAE,MAAM,CAAC,OAAO;YACvB,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;IACF,OAAO,MAAM,CAAC,MAAM,CAAC,SAAS,EAAE,EAAE,KAAK,EAAE,CAAC,CAAC;AAC7C,CAAC"}
package/dist/index.d.ts CHANGED
@@ -2,7 +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 HostFetch, type HostFetchInit, type HostFetchOptions, type HostFetchResponse } from "./host-fetch.js";
5
+ export { createHostFetch, type HostFetch, type HostFetchCheck, type HostFetchInit, type HostFetchOptions, type HostFetchResponse } from "./host-fetch.js";
6
6
  export type { AllowedTarget, HostPolicy, HostPolicyOptions, HostResolver, ResolvedAddress } from "./policy.js";
7
7
  export { MAX_PROXY_REFUSALS, PROXY_HOST, startPolicyProxy, type PolicyProxy, type PolicyProxyOptions, type ProxyRefusal } from "./proxy.js";
8
8
  export { isLocalName, isPublicAddress, parseAddress, specialClass } from "./address.js";
@@ -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,MA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AAgE,MAAM,YAAY,CAAC;AAC5I,OAAO,EAAE,WAAW,EAAE,eAAe,EAAE,YAAY,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AACxF,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;AAC7F,6EAA6E;AAC7E,OAAO,EAAE,YAAY,EAAE,QAAQ,EAAE,YAAY,EAAE,gBAAgB,EAAE,MAAM,YAAY,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.69.1",
4
+ "version": "0.69.3",
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",
@@ -74,7 +74,7 @@
74
74
  "procedures": "./dist/register.js"
75
75
  },
76
76
  "dependencies": {
77
- "@procedures/client": "0.69.1",
77
+ "@procedures/client": "0.69.3",
78
78
  "zod": "^4.6.5"
79
79
  },
80
80
  "scripts": {
package/src/host-fetch.ts CHANGED
@@ -23,7 +23,7 @@
23
23
 
24
24
  import type { HttpModuleOptions } from "./module.js";
25
25
  import { httpSettings } from "./module.js";
26
- import { hostNotAllowed, portOf } from "./policy.js";
26
+ import { checkHost, hostNotAllowed, isHostNotAllowed, portOf } from "./policy.js";
27
27
  import { httpRequest } from "./procedures/http/request.js";
28
28
 
29
29
  /** The longest time of a request of `http.request`: the signal of the caller is the real limit. */
@@ -106,8 +106,25 @@ export interface HostFetchResponse {
106
106
  json(): Promise<unknown>;
107
107
  }
108
108
 
109
- /** A `fetch` for GET and HEAD requests, and for a POST that only reads, through the host policy. */
110
- export type HostFetch = (url: string, init?: HostFetchInit) => Promise<HostFetchResponse>;
109
+ /**
110
+ * This function examines a URL and a method with the host policy of a `HostFetch`, and sends no
111
+ * request. It throws the `FORBIDDEN` refusal that the fetch throws. For each other fault, for
112
+ * example a host with no address, it throws nothing: the fetch gives that error.
113
+ *
114
+ * A caller with a pace examines a URL before it takes a turn of the host. Thus a refusal does not wait, and the host gets no rest.
115
+ */
116
+ export type HostFetchCheck = (url: string, init?: Pick<HostFetchInit, "method">) => Promise<void>;
117
+
118
+ /**
119
+ * A `fetch` for GET and HEAD requests, and for a POST that only reads, through the host policy. The
120
+ * fetch of `createHostFetch()` has the member `check`. Another `HostFetch` can have no `check`.
121
+ */
122
+ export type HostFetch = ((url: string, init?: HostFetchInit) => Promise<HostFetchResponse>) & {
123
+ readonly check?: HostFetchCheck | undefined;
124
+ };
125
+
126
+ /** The procedure of the refusals of `createHostFetch()`: the refusals of `http.request`. */
127
+ const REQUEST_PATH = ["http", "request"];
111
128
 
112
129
  /**
113
130
  * This function gives a `fetch` for GET and HEAD requests through the host policy of the options. The
@@ -117,16 +134,34 @@ export type HostFetch = (url: string, init?: HostFetchInit) => Promise<HostFetch
117
134
  *
118
135
  * - The fetch throws `FORBIDDEN` with the reason `host-not-allowed` for a POST to a host that is not in `readOnlyPost`.
119
136
  * - The fetch throws an `Error` for a body with a method other than POST.
137
+ * - The member `check` examines a URL with the same rules, and sends nothing (`HostFetchCheck`).
120
138
  *
121
139
  * ```ts
122
140
  * const forecast = createWeatherModule({ fetch: createHostFetch({ allow: ["localhost:8080"] }) });
123
141
  * const soil = createGeoModule({ fetch: createHostFetch({ readOnlyPost: ["sdmdataaccess.sc.egov.usda.gov"] }) });
124
142
  * ```
125
143
  */
126
- export function createHostFetch(options: HostFetchOptions = {}): HostFetch {
144
+ export function createHostFetch(options: HostFetchOptions = {}): HostFetch & { readonly check: HostFetchCheck } {
127
145
  const settings = httpSettings(options);
128
146
  const postEntries = (options.readOnlyPost ?? []).map(parsePostEntry);
129
- return async (url, init = {}) => {
147
+ const check: HostFetchCheck = async (url, init = {}) => {
148
+ let target: URL;
149
+ try {
150
+ target = new URL(url);
151
+ } catch {
152
+ return;
153
+ }
154
+ if (target.protocol !== "http:" && target.protocol !== "https:") return;
155
+ if (init.method === "POST" && !takesPost(postEntries, target)) {
156
+ throw hostNotAllowed(REQUEST_PATH, `the host ${bareHostname(target)}:${portOf(target)} takes no POST: it is not in readOnlyPost of createHostFetch`);
157
+ }
158
+ try {
159
+ await checkHost(settings.policy, target, REQUEST_PATH);
160
+ } catch (error) {
161
+ if (isHostNotAllowed(error)) throw error;
162
+ }
163
+ };
164
+ const hostFetch = async (url: string, init: HostFetchInit = {}): Promise<HostFetchResponse> => {
130
165
  const method = init.method ?? "GET";
131
166
  if (init.body !== undefined && method !== "POST") throw new Error(`A ${method} request of createHostFetch has no body: a body needs the method POST`);
132
167
  if (method === "POST") {
@@ -137,7 +172,7 @@ export function createHostFetch(options: HostFetchOptions = {}): HostFetch {
137
172
  throw new Error(`The URL ${JSON.stringify(url)} of the POST is not a URL`, { cause: error });
138
173
  }
139
174
  if (!takesPost(postEntries, target)) {
140
- throw hostNotAllowed(["http", "request"], `the host ${bareHostname(target)}:${portOf(target)} takes no POST: it is not in readOnlyPost of createHostFetch`);
175
+ throw hostNotAllowed(REQUEST_PATH, `the host ${bareHostname(target)}:${portOf(target)} takes no POST: it is not in readOnlyPost of createHostFetch`);
141
176
  }
142
177
  }
143
178
  let output;
@@ -170,4 +205,5 @@ export function createHostFetch(options: HostFetchOptions = {}): HostFetch {
170
205
  json: async () => JSON.parse(text) as unknown,
171
206
  };
172
207
  };
208
+ return Object.assign(hostFetch, { check });
173
209
  }
package/src/index.ts CHANGED
@@ -5,7 +5,7 @@ export { httpRequest, httpJson, httpNdjson, httpSse } from "./procedures/http/in
5
5
  // The host policy (roadmap R38)
6
6
  export { HOST_NOT_ALLOWED, DEFAULT_HOST_POLICY, createHostPolicy, checkHost, isHostNotAllowed, systemResolver } from "./policy.js";
7
7
  // A fetch for GET requests, and for a POST that only reads, through the host policy, for the procedures of other packages (O55)
8
- export { createHostFetch, type HostFetch, type HostFetchInit, type HostFetchOptions, type HostFetchResponse } from "./host-fetch.js";
8
+ export { createHostFetch, type HostFetch, type HostFetchCheck, type HostFetchInit, type HostFetchOptions, type HostFetchResponse } from "./host-fetch.js";
9
9
  export type { AllowedTarget, HostPolicy, HostPolicyOptions, HostResolver, ResolvedAddress } from "./policy.js";
10
10
  // A local forward proxy that applies the host policy to each request of another program, for example a headless browser
11
11
  export { MAX_PROXY_REFUSALS, PROXY_HOST, startPolicyProxy, type PolicyProxy, type PolicyProxyOptions, type ProxyRefusal } from "./proxy.js";