@maschinenlesbar.org/ckan-cli 0.0.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.
Files changed (73) hide show
  1. package/CONTRIBUTING.md +25 -0
  2. package/LICENSE +661 -0
  3. package/LICENSING.md +47 -0
  4. package/README.md +268 -0
  5. package/dist/src/cli/commands/catalogue.d.ts +4 -0
  6. package/dist/src/cli/commands/catalogue.d.ts.map +1 -0
  7. package/dist/src/cli/commands/catalogue.js +103 -0
  8. package/dist/src/cli/commands/catalogue.js.map +1 -0
  9. package/dist/src/cli/commands/portal.d.ts +4 -0
  10. package/dist/src/cli/commands/portal.d.ts.map +1 -0
  11. package/dist/src/cli/commands/portal.js +61 -0
  12. package/dist/src/cli/commands/portal.js.map +1 -0
  13. package/dist/src/cli/index.d.ts +3 -0
  14. package/dist/src/cli/index.d.ts.map +1 -0
  15. package/dist/src/cli/index.js +6 -0
  16. package/dist/src/cli/index.js.map +1 -0
  17. package/dist/src/cli/io.d.ts +15 -0
  18. package/dist/src/cli/io.d.ts.map +1 -0
  19. package/dist/src/cli/io.js +8 -0
  20. package/dist/src/cli/io.js.map +1 -0
  21. package/dist/src/cli/program.d.ts +7 -0
  22. package/dist/src/cli/program.d.ts.map +1 -0
  23. package/dist/src/cli/program.js +77 -0
  24. package/dist/src/cli/program.js.map +1 -0
  25. package/dist/src/cli/run.d.ts +3 -0
  26. package/dist/src/cli/run.d.ts.map +1 -0
  27. package/dist/src/cli/run.js +48 -0
  28. package/dist/src/cli/run.js.map +1 -0
  29. package/dist/src/cli/shared.d.ts +61 -0
  30. package/dist/src/cli/shared.d.ts.map +1 -0
  31. package/dist/src/cli/shared.js +134 -0
  32. package/dist/src/cli/shared.js.map +1 -0
  33. package/dist/src/client/client.d.ts +71 -0
  34. package/dist/src/client/client.d.ts.map +1 -0
  35. package/dist/src/client/client.js +194 -0
  36. package/dist/src/client/client.js.map +1 -0
  37. package/dist/src/client/engine.d.ts +56 -0
  38. package/dist/src/client/engine.d.ts.map +1 -0
  39. package/dist/src/client/engine.js +193 -0
  40. package/dist/src/client/engine.js.map +1 -0
  41. package/dist/src/client/errors.d.ts +40 -0
  42. package/dist/src/client/errors.d.ts.map +1 -0
  43. package/dist/src/client/errors.js +73 -0
  44. package/dist/src/client/errors.js.map +1 -0
  45. package/dist/src/client/http.d.ts +31 -0
  46. package/dist/src/client/http.d.ts.map +1 -0
  47. package/dist/src/client/http.js +111 -0
  48. package/dist/src/client/http.js.map +1 -0
  49. package/dist/src/client/index.d.ts +13 -0
  50. package/dist/src/client/index.d.ts.map +1 -0
  51. package/dist/src/client/index.js +10 -0
  52. package/dist/src/client/index.js.map +1 -0
  53. package/dist/src/client/portals-list.d.ts +3 -0
  54. package/dist/src/client/portals-list.d.ts.map +1 -0
  55. package/dist/src/client/portals-list.js +294 -0
  56. package/dist/src/client/portals-list.js.map +1 -0
  57. package/dist/src/client/portals.d.ts +37 -0
  58. package/dist/src/client/portals.d.ts.map +1 -0
  59. package/dist/src/client/portals.js +122 -0
  60. package/dist/src/client/portals.js.map +1 -0
  61. package/dist/src/client/query.d.ts +9 -0
  62. package/dist/src/client/query.d.ts.map +1 -0
  63. package/dist/src/client/query.js +33 -0
  64. package/dist/src/client/query.js.map +1 -0
  65. package/dist/src/client/types.d.ts +99 -0
  66. package/dist/src/client/types.d.ts.map +1 -0
  67. package/dist/src/client/types.js +8 -0
  68. package/dist/src/client/types.js.map +1 -0
  69. package/dist/src/index.d.ts +2 -0
  70. package/dist/src/index.d.ts.map +1 -0
  71. package/dist/src/index.js +3 -0
  72. package/dist/src/index.js.map +1 -0
  73. package/package.json +71 -0
@@ -0,0 +1,56 @@
1
+ import { type Transport } from "./http.js";
2
+ import { type QueryParams } from "./query.js";
3
+ export declare const DEFAULT_BASE_URL = "https://suche.transparenz.hamburg.de";
4
+ export interface RawResponse {
5
+ data: Buffer;
6
+ contentType: string;
7
+ status: number;
8
+ /** The URL that answered, after any redirects. */
9
+ url: string;
10
+ }
11
+ export interface EngineOptions {
12
+ /** Base URL of the API. Defaults to https://suche.transparenz.hamburg.de (the Hamburg Transparenzportal) */
13
+ baseUrl?: string;
14
+ /** Swappable transport. Defaults to the built-in node http/https transport. */
15
+ transport?: Transport;
16
+ /** Value of the User-Agent header. */
17
+ userAgent?: string;
18
+ /** Per-request timeout in milliseconds (0 disables; capped at `MAX_TIMEOUT_MS`, 2^31 - 1 ms). */
19
+ timeoutMs?: number;
20
+ /** Number of automatic retries for transient (429/503) responses. */
21
+ maxRetries?: number;
22
+ /** Base backoff between retries in milliseconds (grows linearly). */
23
+ retryDelayMs?: number;
24
+ /** Number of HTTP redirects (301/302/303/307/308) to follow. Defaults to 5. */
25
+ maxRedirects?: number;
26
+ /**
27
+ * Hard cap on response body size in bytes (defends against memory exhaustion
28
+ * from a hostile/buggy endpoint). Defaults to 100 MiB; set to 0 for no limit.
29
+ */
30
+ maxResponseBytes?: number;
31
+ /** Injectable sleep, primarily for deterministic tests. */
32
+ sleep?: (ms: number) => Promise<void>;
33
+ }
34
+ export declare class RequestEngine {
35
+ private readonly baseUrl;
36
+ private readonly transport;
37
+ private readonly userAgent;
38
+ private readonly timeoutMs;
39
+ private readonly maxRetries;
40
+ private readonly retryDelayMs;
41
+ private readonly maxRedirects;
42
+ private readonly maxResponseBytes;
43
+ private readonly sleep;
44
+ constructor(options?: EngineOptions);
45
+ /** Build a fully-qualified URL from a path and optional query parameters. */
46
+ buildUrl(path: string, query?: QueryParams): string;
47
+ /** Perform a request with Accept negotiation and transient-error retries. */
48
+ request(method: string, path: string, options?: {
49
+ query?: QueryParams;
50
+ accept: string;
51
+ }): Promise<RawResponse>;
52
+ /** Perform a GET expecting JSON and parse it into `T`. */
53
+ getJson<T>(path: string, query?: QueryParams): Promise<T>;
54
+ private toApiError;
55
+ }
56
+ //# sourceMappingURL=engine.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"engine.d.ts","sourceRoot":"","sources":["../../../src/client/engine.ts"],"names":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AAS;IAC1C,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAgC;IAEtD,YAAY,OAAO,GAAE,aAAkB,EActC;IAED,6EAA6E;IAC7E,QAAQ,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,WAAW,GAAG,MAAM,CAIlD;IAED,6EAA6E;IACvE,OAAO,CACX,MAAM,EAAE,MAAM,EACd,IAAI,EAAE,MAAM,EACZ,OAAO,GAAE;QAAE,KAAK,CAAC,EAAE,WAAW,CAAC;QAAC,MAAM,EAAE,MAAM,CAAA;KAAmC,GAChF,OAAO,CAAC,WAAW,CAAC,CAgEtB;IAED,0DAA0D;IACpD,OAAO,CAAC,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,WAAW,GAAG,OAAO,CAAC,CAAC,CAAC,CAc9D;IAED,OAAO,CAAC,UAAU;CA6BnB"}
@@ -0,0 +1,193 @@
1
+ // The request engine: turns logical (method, path, query) calls into HTTP
2
+ // requests via a Transport, applies retry/backoff for transient statuses
3
+ // (429, 503), and decodes responses.
4
+ import { nodeHttpTransport } from "./http.js";
5
+ import { buildQueryString } from "./query.js";
6
+ import { CkanApiError, CkanNetworkError, CkanParseError, describeCkanError } from "./errors.js";
7
+ export const DEFAULT_BASE_URL = "https://suche.transparenz.hamburg.de";
8
+ const DEFAULT_USER_AGENT = "ckan-cli";
9
+ const DEFAULT_MAX_RESPONSE_BYTES = 100 * 1024 * 1024;
10
+ /**
11
+ * Strip control characters (all C0/C1 controls except tab and newline, plus DEL)
12
+ * out of a string that originates in an attacker-controlled response — the error
13
+ * `detail` extracted from the body. `JSON.parse` decodes an escaped ESC in an
14
+ * error body into a real ESC byte, so without this a hostile/MITM'd endpoint could
15
+ * drive ANSI/OSC escape sequences into the user's terminal when the message is
16
+ * printed to stderr. The CLI's JSON output is escaped separately
17
+ * (`escapeControlChars` in cli/shared.ts): `JSON.stringify` alone leaves DEL and
18
+ * the C1 range raw. So this only needs to cover text that flows into an error message.
19
+ */
20
+ function sanitizeServerText(text) {
21
+ let out = "";
22
+ for (const ch of text) {
23
+ const n = ch.codePointAt(0) ?? 0;
24
+ if (n <= 8 || (n >= 0x0b && n <= 0x1f) || (n >= 0x7f && n <= 0x9f))
25
+ continue;
26
+ out += ch;
27
+ }
28
+ return out;
29
+ }
30
+ /**
31
+ * Reject a base URL whose scheme is not http(s). The default transport already
32
+ * gates this per hop, but the engine is exported as a library and may be handed a
33
+ * custom transport that does no such check, so gate the configured base URL here
34
+ * too (a `file:`/`ftp:` base URL fails fast with a typed error).
35
+ */
36
+ function assertHttpScheme(baseUrl) {
37
+ let url;
38
+ try {
39
+ url = new URL(baseUrl);
40
+ }
41
+ catch {
42
+ throw new CkanNetworkError(`Invalid base URL: ${baseUrl}`);
43
+ }
44
+ if (url.protocol !== "http:" && url.protocol !== "https:") {
45
+ throw new CkanNetworkError(`Unsupported protocol "${url.protocol}" in base URL: ${baseUrl}`);
46
+ }
47
+ }
48
+ const realSleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
49
+ export class RequestEngine {
50
+ baseUrl;
51
+ transport;
52
+ userAgent;
53
+ timeoutMs;
54
+ maxRetries;
55
+ retryDelayMs;
56
+ maxRedirects;
57
+ maxResponseBytes;
58
+ sleep;
59
+ constructor(options = {}) {
60
+ this.baseUrl = (options.baseUrl ?? DEFAULT_BASE_URL).replace(/\/+$/, "");
61
+ // Re-check the base-URL scheme here, not only in the default transport: a
62
+ // library consumer that injects a custom transport would otherwise get no
63
+ // gating at all, and could be steered to a non-http(s) scheme.
64
+ assertHttpScheme(this.baseUrl);
65
+ this.transport = options.transport ?? nodeHttpTransport;
66
+ this.userAgent = options.userAgent ?? DEFAULT_USER_AGENT;
67
+ this.timeoutMs = options.timeoutMs ?? 30_000;
68
+ this.maxRetries = options.maxRetries ?? 2;
69
+ this.retryDelayMs = options.retryDelayMs ?? 200;
70
+ this.maxRedirects = options.maxRedirects ?? 5;
71
+ this.maxResponseBytes = options.maxResponseBytes ?? DEFAULT_MAX_RESPONSE_BYTES;
72
+ this.sleep = options.sleep ?? realSleep;
73
+ }
74
+ /** Build a fully-qualified URL from a path and optional query parameters. */
75
+ buildUrl(path, query) {
76
+ const normalizedPath = path.startsWith("/") ? path : `/${path}`;
77
+ const qs = query ? buildQueryString(query) : "";
78
+ return `${this.baseUrl}${normalizedPath}${qs ? `?${qs}` : ""}`;
79
+ }
80
+ /** Perform a request with Accept negotiation and transient-error retries. */
81
+ async request(method, path, options = { accept: "application/json" }) {
82
+ let url = this.buildUrl(path, options.query);
83
+ let headers = {
84
+ Accept: options.accept,
85
+ "User-Agent": this.userAgent,
86
+ };
87
+ let attempt = 0;
88
+ let redirects = 0;
89
+ // attempts = initial try + maxRetries (redirects are counted separately)
90
+ for (;;) {
91
+ const response = await this.transport({
92
+ method,
93
+ url,
94
+ headers,
95
+ timeoutMs: this.timeoutMs,
96
+ ...(this.maxResponseBytes > 0 ? { maxResponseBytes: this.maxResponseBytes } : {}),
97
+ });
98
+ const status = response.status;
99
+ const retryable = status === 429 || status === 503;
100
+ if (retryable && attempt < this.maxRetries) {
101
+ attempt += 1;
102
+ await this.sleep(this.retryDelayMs * attempt);
103
+ continue;
104
+ }
105
+ // Follow redirects, resolving the Location relative to the current URL.
106
+ if (status >= 300 && status < 400 && redirects < this.maxRedirects) {
107
+ const location = response.headers["location"];
108
+ if (typeof location === "string" && location.length > 0) {
109
+ const previous = new URL(url);
110
+ const next = new URL(location, url);
111
+ // Credential-strip guard: if the redirect crosses origin, drop the
112
+ // request headers so any future auth/cookie header is never re-sent to
113
+ // a different host. (Today only Accept/User-Agent are sent, but this
114
+ // future-proofs against header leakage across origins.)
115
+ if (next.origin !== previous.origin) {
116
+ headers = { Accept: options.accept };
117
+ }
118
+ url = next.toString();
119
+ redirects += 1;
120
+ continue;
121
+ }
122
+ }
123
+ const contentType = String(response.headers["content-type"] ?? "");
124
+ if (status < 200 || status >= 300) {
125
+ // A 3xx that was not followed because the limit was reached: say so, or a
126
+ // bare "HTTP 301" reads like a redirect this client cannot follow.
127
+ const exhausted = status >= 300 && status < 400 && Boolean(response.headers["location"]);
128
+ throw exhausted
129
+ ? new CkanApiError({
130
+ status,
131
+ url,
132
+ method,
133
+ body: response.body.toString("utf8"),
134
+ detail: `stopped after ${this.maxRedirects} redirects (a redirect loop?)`,
135
+ })
136
+ : this.toApiError(method, url, status, response.body);
137
+ }
138
+ return { data: response.body, contentType, status, url };
139
+ }
140
+ }
141
+ /** Perform a GET expecting JSON and parse it into `T`. */
142
+ async getJson(path, query) {
143
+ const res = await this.request("GET", path, { query, accept: "application/json" });
144
+ const text = res.data.toString("utf8");
145
+ try {
146
+ return JSON.parse(text);
147
+ }
148
+ catch (cause) {
149
+ // Name the URL and what came back: a site that is not a CKAN (or not at this
150
+ // path) typically answers with an HTML page and HTTP 200.
151
+ const mediaType = res.contentType.split(";")[0].trim();
152
+ const message = /json/i.test(mediaType)
153
+ ? `Invalid JSON from ${res.url}`
154
+ : `Expected JSON from ${res.url} but got ${mediaType || "a body that is not JSON"}`;
155
+ throw new CkanParseError(message, { cause });
156
+ }
157
+ }
158
+ toApiError(method, url, status, body) {
159
+ const text = body.toString("utf8");
160
+ let detail;
161
+ try {
162
+ const parsed = JSON.parse(text);
163
+ if (typeof parsed === "string") {
164
+ // CKAN's own routing errors (an unknown action name) are a bare JSON string.
165
+ detail = parsed;
166
+ }
167
+ else if (typeof parsed === "object" && parsed !== null) {
168
+ const body = parsed;
169
+ // CKAN nests its error under `error` (a message, or a validation field
170
+ // map; see describeCkanError); plainer APIs use a top-level
171
+ // `detail`/`message`. Prefer the nested CKAN shape, then fall back.
172
+ if (typeof body.error === "object" && body.error !== null) {
173
+ detail = describeCkanError(body.error);
174
+ }
175
+ else if (typeof body.detail === "string") {
176
+ detail = body.detail;
177
+ }
178
+ else if (typeof body.message === "string") {
179
+ detail = body.message;
180
+ }
181
+ }
182
+ }
183
+ catch {
184
+ // Non-JSON error body; leave detail undefined.
185
+ }
186
+ // `detail` came from the response body; strip control characters so a hostile
187
+ // endpoint cannot inject terminal escape sequences via the stderr error message.
188
+ if (detail !== undefined)
189
+ detail = sanitizeServerText(detail);
190
+ return new CkanApiError({ status, url, method, body: text, detail });
191
+ }
192
+ }
193
+ //# sourceMappingURL=engine.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"engine.js","sourceRoot":"","sources":["../../../src/client/engine.ts"],"names":[],"mappings":"AAAA,0EAA0E;AAC1E,yEAAyE;AACzE,qCAAqC;AAErC,OAAO,EAAE,iBAAiB,EAAkB,MAAM,WAAW,CAAC;AAC9D,OAAO,EAAE,gBAAgB,EAAoB,MAAM,YAAY,CAAC;AAChE,OAAO,EAAE,YAAY,EAAE,gBAAgB,EAAE,cAAc,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAEhG,MAAM,CAAC,MAAM,gBAAgB,GAAG,sCAAsC,CAAC;AACvE,MAAM,kBAAkB,GAAG,UAAU,CAAC;AAkCtC,MAAM,0BAA0B,GAAG,GAAG,GAAG,IAAI,GAAG,IAAI,CAAC;AAErD;;;;;;;;;GASG;AACH,SAAS,kBAAkB,CAAC,IAAY;IACtC,IAAI,GAAG,GAAG,EAAE,CAAC;IACb,KAAK,MAAM,EAAE,IAAI,IAAI,EAAE,CAAC;QACtB,MAAM,CAAC,GAAG,EAAE,CAAC,WAAW,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC;QACjC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,IAAI,IAAI,IAAI,CAAC,IAAI,IAAI,CAAC,IAAI,CAAC,CAAC,IAAI,IAAI,IAAI,CAAC,IAAI,IAAI,CAAC;YAAE,SAAS;QAC7E,GAAG,IAAI,EAAE,CAAC;IACZ,CAAC;IACD,OAAO,GAAG,CAAC;AACb,CAAC;AAED;;;;;GAKG;AACH,SAAS,gBAAgB,CAAC,OAAe;IACvC,IAAI,GAAQ,CAAC;IACb,IAAI,CAAC;QACH,GAAG,GAAG,IAAI,GAAG,CAAC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I,CAAC,OAAO,KAAK,QAAQ,EAAE,CAAC;oBAC5C,MAAM,GAAG,IAAI,CAAC,OAAO,CAAC;gBACxB,CAAC;YACH,CAAC;QACH,CAAC;QAAC,MAAM,CAAC;YACP,+CAA+C;QACjD,CAAC;QACD,8EAA8E;QAC9E,iFAAiF;QACjF,IAAI,MAAM,KAAK,SAAS;YAAE,MAAM,GAAG,kBAAkB,CAAC,MAAM,CAAC,CAAC;QAC9D,OAAO,IAAI,YAAY,CAAC,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,EAAE,IAAI,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC,CAAC;IACvE,CAAC;CACF"}
@@ -0,0 +1,40 @@
1
+ /** Base class for every error originating from this client. */
2
+ export declare class CkanError extends Error {
3
+ constructor(message: string, options?: {
4
+ cause?: unknown;
5
+ });
6
+ }
7
+ /**
8
+ * The API responded with a non-2xx status code. `detail` holds a human-readable
9
+ * message extracted from the response body when one is present.
10
+ */
11
+ export declare class CkanApiError extends CkanError {
12
+ readonly status: number;
13
+ readonly detail: string | undefined;
14
+ readonly url: string;
15
+ readonly method: string;
16
+ readonly body: string;
17
+ constructor(args: {
18
+ status: number;
19
+ url: string;
20
+ method: string;
21
+ body: string;
22
+ detail?: string;
23
+ });
24
+ /** True for statuses the API documents as transient and retry-able. */
25
+ get isRetryable(): boolean;
26
+ }
27
+ /** A transport-level failure (DNS, connection reset, timeout, ...). */
28
+ export declare class CkanNetworkError extends CkanError {
29
+ }
30
+ /** The response body could not be parsed as the expected JSON shape. */
31
+ export declare class CkanParseError extends CkanError {
32
+ }
33
+ /**
34
+ * Turn a CKAN `error` object into one readable line. CKAN has two shapes: a
35
+ * `message` (`{"__type": "Not Found Error", "message": "Not found"}`), and a
36
+ * validation error that maps each offending field to its messages instead
37
+ * (`{"__type": "Validation Error", "rows": ["Invalid integer"]}`).
38
+ */
39
+ export declare function describeCkanError(error: unknown): string;
40
+ //# sourceMappingURL=errors.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../../../src/client/errors.ts"],"names":[],"mappings":"AAGA,+DAA+D;AAC/D,qBAAa,SAAU,SAAQ,KAAK;IAClC,YAAY,OAAO,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE;QAAE,KAAK,CAAC,EAAE,OAAO,CAAA;KAAE,EAGzD;CACF;AAED;;;GAGG;AACH,qBAAa,YAAa,SAAQ,SAAS;IACzC,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,CAAC;IACpC,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;IACrB,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IAEtB,YAAY,IAAI,EAAE;QAChB,MAAM,EAAE,MAAM,CAAC;QACf,GAAG,EAAE,MAAM,CAAC;QACZ,MAAM,EAAE,MAAM,CAAC;QACf,IAAI,EAAE,MAAM,CAAC;QACb,MAAM,CAAC,EAAE,MAAM,CAAC;KACjB,EAQA;IAED,uEAAuE;IACvE,IAAI,WAAW,IAAI,OAAO,CAEzB;CACF;AAED,uEAAuE;AACvE,qBAAa,gBAAiB,SAAQ,SAAS;CAAG;AAElD,wEAAwE;AACxE,qBAAa,cAAe,SAAQ,SAAS;CAAG;AAEhD;;;;;GAKG;AACH,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,OAAO,GAAG,MAAM,CAYxD"}
@@ -0,0 +1,73 @@
1
+ // Error types raised by the client. Kept free of any I/O so they are trivial to
2
+ // construct in tests and to `instanceof`-check by consumers.
3
+ /** Base class for every error originating from this client. */
4
+ export class CkanError extends Error {
5
+ constructor(message, options) {
6
+ super(message, options);
7
+ this.name = new.target.name;
8
+ }
9
+ }
10
+ /**
11
+ * The API responded with a non-2xx status code. `detail` holds a human-readable
12
+ * message extracted from the response body when one is present.
13
+ */
14
+ export class CkanApiError extends CkanError {
15
+ status;
16
+ detail;
17
+ url;
18
+ method;
19
+ body;
20
+ constructor(args) {
21
+ const detailPart = args.detail ? `: ${args.detail}` : "";
22
+ super(`HTTP ${args.status} for ${args.method} ${args.url}${detailPart}`);
23
+ this.status = args.status;
24
+ this.url = args.url;
25
+ this.method = args.method;
26
+ this.body = args.body;
27
+ this.detail = args.detail;
28
+ }
29
+ /** True for statuses the API documents as transient and retry-able. */
30
+ get isRetryable() {
31
+ return this.status === 429 || this.status === 503;
32
+ }
33
+ }
34
+ /** A transport-level failure (DNS, connection reset, timeout, ...). */
35
+ export class CkanNetworkError extends CkanError {
36
+ }
37
+ /** The response body could not be parsed as the expected JSON shape. */
38
+ export class CkanParseError extends CkanError {
39
+ }
40
+ /**
41
+ * Turn a CKAN `error` object into one readable line. CKAN has two shapes: a
42
+ * `message` (`{"__type": "Not Found Error", "message": "Not found"}`), and a
43
+ * validation error that maps each offending field to its messages instead
44
+ * (`{"__type": "Validation Error", "rows": ["Invalid integer"]}`).
45
+ */
46
+ export function describeCkanError(error) {
47
+ if (typeof error !== "object" || error === null)
48
+ return String(error);
49
+ const { __type: type, message, ...fields } = error;
50
+ let text;
51
+ if (typeof message === "string") {
52
+ text = solrReason(message) ?? message;
53
+ }
54
+ else {
55
+ text = Object.entries(fields)
56
+ .map(([field, value]) => `${field}: ${Array.isArray(value) ? value.join(", ") : String(value)}`)
57
+ .join("; ");
58
+ }
59
+ return typeof type === "string" ? `${type}: ${text}` : text;
60
+ }
61
+ /**
62
+ * Solr's own reason inside a CKAN "Search Error" message, or undefined. CKAN
63
+ * reports a Solr failure as the whole Solr query in a (nested) Python repr, with
64
+ * the useful part as `[Reason: <java class>: <text>\nWas expecting …]`, its
65
+ * quotes and newlines escaped several levels deep.
66
+ */
67
+ function solrReason(message) {
68
+ const match = /\[Reason: (?:[\w.$]+(?:Exception|Error): )?([\s\S]*?)(?:\\+n|\n|\])/.exec(message);
69
+ if (!match?.[1])
70
+ return undefined;
71
+ return match[1].replace(/\\+(['"])/g, "$1").trim();
72
+ }
73
+ //# sourceMappingURL=errors.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errors.js","sourceRoot":"","sources":["../../../src/client/errors.ts"],"names":[],"mappings":"AAAA,gFAAgF;AAChF,6DAA6D;AAE7D,+DAA+D;AAC/D,MAAM,OAAO,SAAU,SAAQ,KAAK;IAClC,YAAY,OAAe,EAAE,OAA6B;QACxD,KAAK,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;QACxB,IAAI,CAAC,IAAI,GAAG,IAAI,MAAM,CAAC,IAAI,CAAC;IAC9B,CAAC;CACF;AAED;;;GAGG;AACH,MAAM,OAAO,YAAa,SAAQ,SAAS;IAChC,MAAM,CAAS;IACf,MAAM,CAAqB;IAC3B,GAAG,CAAS;IACZ,MAAM,CAAS;IACf,IAAI,CAAS;IAEtB,YAAY,IAMX;QACC,MAAM,UAAU,GAAG,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,KAAK,IAAI,CAAC,MAAM,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;QACzD,KAAK,CAAC,QAAQ,IAAI,CAAC,MAAM,QAAQ,IAAI,CAAC,MAAM,IAAI,IAAI,CAAC,GAAG,GAAG,UAAU,EAAE,CAAC,CAAC;QACzE,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC,MAAM,CAAC;QAC1B,IAAI,CAAC,GAAG,GAAG,IAAI,CAAC,GAAG,CAAC;QACpB,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC,MAAM,CAAC;QAC1B,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC,IAAI,CAAC;QACtB,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC,MAAM,CAAC;IAC5B,CAAC;IAED,uEAAuE;IACvE,IAAI,WAAW;QACb,OAAO,IAAI,CAAC,MAAM,KAAK,GAAG,IAAI,IAAI,CAAC,MAAM,KAAK,GAAG,CAAC;IACpD,CAAC;CACF;AAED,uEAAuE;AACvE,MAAM,OAAO,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AAI,EAAE,CAAC;AACrD,CAAC"}
@@ -0,0 +1,31 @@
1
+ import http from "node:http";
2
+ export interface HttpRequest {
3
+ method: string;
4
+ /** Fully-qualified absolute URL. */
5
+ url: string;
6
+ headers?: Record<string, string>;
7
+ /** Optional request body (already serialised). */
8
+ body?: string | Buffer;
9
+ /** Per-request timeout in milliseconds. */
10
+ timeoutMs?: number;
11
+ /** Hard cap on the response body size in bytes; the request aborts if exceeded. */
12
+ maxResponseBytes?: number;
13
+ }
14
+ export interface HttpResponse {
15
+ status: number;
16
+ headers: http.IncomingHttpHeaders;
17
+ body: Buffer;
18
+ }
19
+ export type Transport = (request: HttpRequest) => Promise<HttpResponse>;
20
+ /**
21
+ * The longest delay Node's timers support (2^31 - 1 ms, about 24.8 days). A longer one
22
+ * prints a TimeoutOverflowWarning and fires after 1 ms, so timeouts are capped here.
23
+ */
24
+ export declare const MAX_TIMEOUT_MS = 2147483647;
25
+ /**
26
+ * Default transport. Resolves with the raw response (including non-2xx) — status
27
+ * interpretation is the client's job. Rejects only on transport-level failures
28
+ * (connection errors, timeouts, malformed URLs).
29
+ */
30
+ export declare const nodeHttpTransport: Transport;
31
+ //# sourceMappingURL=http.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"http.d.ts","sourceRoot":"","sources":["../../../src/client/http.ts"],"names":[],"mappings":"AAQA,OAAO,IAAI,MAAM,WAAW,CAAC;AAI7B,MAAM,WAAW,WAAW;IAC1B,MAAM,EAAE,MAAM,CAAC;IACf,oCAAoC;IACpC,GAAG,EAAE,MAAM,CAAC;IACZ,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACjC,kDAAkD;IAClD,IAAI,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC;IACvB,2CAA2C;IAC3C,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,mFAAmF;IACnF,gBAAgB,CAAC,EAAE,MAAM,CAAC;CAC3B;AAED,MAAM,WAAW,YAAY;IAC3B,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,EAAE,IAAI,CAAC,mBAAmB,CAAC;IAClC,IAAI,EAAE,MAAM,CAAC;CACd;AAED,MAAM,MAAM,SAAS,GAAG,CAAC,OAAO,EAAE,WAAW,KAAK,OAAO,CAAC,YAAY,CAAC,CAAC;AAExE;;;GAGG;AACH,eAAO,MAAM,cAAc,aAAgB,CAAC;AAE5C;;;;GAIG;AACH,eAAO,MAAM,iBAAiB,EAAE,SAiG5B,CAAC"}
@@ -0,0 +1,111 @@
1
+ // HTTP transport built on Node's built-in `http`/`https` modules — no axios,
2
+ // no fetch polyfill, no third-party HTTP client.
3
+ //
4
+ // The transport is a plain function so it can be trivially swapped out in tests
5
+ // (inject a `mock.fn()` returning a canned HttpResponse) without touching the
6
+ // network. The default implementation below is exercised against a real local
7
+ // `http.createServer` in the test-suite.
8
+ import http from "node:http";
9
+ import https from "node:https";
10
+ import { CkanNetworkError } from "./errors.js";
11
+ /**
12
+ * The longest delay Node's timers support (2^31 - 1 ms, about 24.8 days). A longer one
13
+ * prints a TimeoutOverflowWarning and fires after 1 ms, so timeouts are capped here.
14
+ */
15
+ export const MAX_TIMEOUT_MS = 2_147_483_647;
16
+ /**
17
+ * Default transport. Resolves with the raw response (including non-2xx) — status
18
+ * interpretation is the client's job. Rejects only on transport-level failures
19
+ * (connection errors, timeouts, malformed URLs).
20
+ */
21
+ export const nodeHttpTransport = (request) => new Promise((resolve, reject) => {
22
+ let url;
23
+ try {
24
+ url = new URL(request.url);
25
+ }
26
+ catch {
27
+ reject(new CkanNetworkError(`Invalid URL: ${request.url}`));
28
+ return;
29
+ }
30
+ // Only http/https are supported. Reject anything else up front with a clear,
31
+ // typed error instead of letting Node throw an opaque ERR_INVALID_PROTOCOL
32
+ // (and so this never reaches the file:/ftp:/etc. drivers).
33
+ if (url.protocol !== "http:" && url.protocol !== "https:") {
34
+ reject(new CkanNetworkError(`Unsupported protocol "${url.protocol}" in URL: ${request.url}`));
35
+ return;
36
+ }
37
+ const isHttps = url.protocol === "https:";
38
+ const driver = isHttps ? https : http;
39
+ const maxBytes = request.maxResponseBytes;
40
+ // Wall-clock deadline (see below). Declared here so both the settle wrappers
41
+ // and the request setup can reference it; cleared on the first settle.
42
+ let deadline;
43
+ const settleResolve = (value) => {
44
+ if (deadline)
45
+ clearTimeout(deadline);
46
+ resolve(value);
47
+ };
48
+ const settleReject = (err) => {
49
+ if (deadline)
50
+ clearTimeout(deadline);
51
+ reject(err);
52
+ };
53
+ const req = driver.request(url, {
54
+ method: request.method,
55
+ headers: request.headers,
56
+ }, (res) => {
57
+ const chunks = [];
58
+ let received = 0;
59
+ let aborted = false;
60
+ res.on("data", (chunk) => {
61
+ if (aborted)
62
+ return;
63
+ received += chunk.length;
64
+ if (maxBytes !== undefined && received > maxBytes) {
65
+ aborted = true;
66
+ res.destroy();
67
+ settleReject(new CkanNetworkError(`Response exceeded maxResponseBytes (${maxBytes})`));
68
+ return;
69
+ }
70
+ chunks.push(chunk);
71
+ });
72
+ res.on("end", () => {
73
+ if (aborted)
74
+ return;
75
+ settleResolve({
76
+ status: res.statusCode ?? 0,
77
+ headers: res.headers,
78
+ body: Buffer.concat(chunks),
79
+ });
80
+ });
81
+ res.on("error", (err) => {
82
+ if (aborted)
83
+ return; // we already rejected with the size-cap error
84
+ settleReject(new CkanNetworkError(`Response stream error: ${err.message}`, { cause: err }));
85
+ });
86
+ });
87
+ if (request.timeoutMs && request.timeoutMs > 0) {
88
+ // Two complementary guards, both using timeoutMs:
89
+ // - setTimeout: a socket-*inactivity* timeout (no bytes for timeoutMs).
90
+ // - deadline: an overall *wall-clock* deadline, so a server that
91
+ // trickles one byte just under the inactivity window can't keep the
92
+ // request alive forever. Whichever trips first destroys the request.
93
+ const delay = Math.min(request.timeoutMs, MAX_TIMEOUT_MS);
94
+ req.setTimeout(delay, () => {
95
+ req.destroy(new CkanNetworkError(`Request timed out after ${request.timeoutMs}ms`));
96
+ });
97
+ deadline = setTimeout(() => {
98
+ req.destroy(new CkanNetworkError(`Request exceeded the ${request.timeoutMs}ms deadline`));
99
+ }, delay);
100
+ // Don't let a pending deadline timer keep the event loop alive on its own.
101
+ deadline.unref?.();
102
+ }
103
+ req.on("error", (err) => {
104
+ // A timeout destroy already passes an CkanNetworkError; don't double-wrap.
105
+ settleReject(err instanceof CkanNetworkError ? err : new CkanNetworkError(err.message, { cause: err }));
106
+ });
107
+ if (request.body !== undefined)
108
+ req.write(request.body);
109
+ req.end();
110
+ });
111
+ //# sourceMappingURL=http.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"http.js","sourceRoot":"","sources":["../../../src/client/http.ts"],"names":[],"mappings":"AAAA,6EAA6E;AAC7E,iDAAiD;AACjD,EAAE;AACF,gFAAgF;AAChF,8EAA8E;AAC9E,8EAA8E;AAC9E,yCAAyC;AAEzC,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,KAAK,MAAM,YAAY,CAAC;AAC/B,OAAO,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAuB/C;;;GAGG;AACH,MAAM,CAAC,MAAM,cAAc,GAAG,aAAa,CAAC;AAE5C;;;;GAIG;AACH,MAAM,CAAC,MAAM,iBAAiB,GAAc,CAAC,OAAO,EAAE,EAAE,CACtD,IAAI,OAAO,CAAe,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;IAC5C,IAAI,GAAQ,CAAC;IACb,IAAI,CAAC;QACH,GAAG,GAAG,IAAI,GAAG,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC;IAC7B,CAAC;IAAC,MAAM,CAAC;QACP,MAAM,CAAC,IAAI,gBAAgB,CAAC,gBAAgB,OAAO,CAAC,GAAG,EAAE,CAAC,CAAC,CAAC;QAC5D,OAAO;IACT,CAAC;IAED,6EAA6E;IAC7E,2EAA2E;IAC3E,2DAA2D;IAC3D,IAAI,GAAG,CAAC,QAAQ,KAAK,OAAO,IAAI,GAAG,CAAC,QAAQ,KAAK,QAAQ,EAAE,CAAC;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,GAAG,EAAE;YACzB,GAAG,CAAC,OAAO,CACT,IAAI,gBAAgB,CAAC,wBAAwB,OAAO,CAAC,SAAS,aAAa,CAAC,CAC7E,CAAC;QACJ,CAAC,EAAE,KAAK,CAAC,CAAC;QACV,2EAA2E;QAC3E,QAAQ,CAAC,KAAK,EAAE,EAAE,CAAC;IACrB,CAAC;IAED,GAAG,CAAC,EAAE,CAAC,OAAO,EAAE,CAAC,GAAG,EAAE,EAAE;QACtB,2EAA2E;QAC3E,YAAY,CAAC,GAAG,YAAY,gBAAgB,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,IAAI,gBAAgB,CAAC,GAAG,CAAC,OAAO,EAAE,EAAE,KAAK,EAAE,GAAG,EAAE,CAAC,CAAC,CAAC;IAC1G,CAAC,CAAC,CAAC;IAEH,IAAI,OAAO,CAAC,IAAI,KAAK,SAAS;QAAE,GAAG,CAAC,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;IACxD,GAAG,CAAC,GAAG,EAAE,CAAC;AACZ,CAAC,CAAC,CAAC"}
@@ -0,0 +1,13 @@
1
+ export { CkanClient, siteRoot } from "./client.js";
2
+ export { RequestEngine, DEFAULT_BASE_URL } from "./engine.js";
3
+ export type { EngineOptions, RawResponse } from "./engine.js";
4
+ export { MAX_TIMEOUT_MS, nodeHttpTransport } from "./http.js";
5
+ export type { Transport, HttpRequest, HttpResponse } from "./http.js";
6
+ export { buildQueryString } from "./query.js";
7
+ export type { QueryParams, QueryValue } from "./query.js";
8
+ export { CkanError, CkanApiError, CkanNetworkError, CkanParseError, describeCkanError, } from "./errors.js";
9
+ export { PORTALS } from "./portals-list.js";
10
+ export { checkPortal, findPortal, mapLimit, portalKey, withCheck } from "./portals.js";
11
+ export type { PortalCheck } from "./portals.js";
12
+ export * from "./types.js";
13
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/client/index.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AACnD,OAAO,EAAE,aAAa,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAC9D,YAAY,EAAE,aAAa,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAC9D,OAAO,EAAE,cAAc,EAAE,iBAAiB,EAAE,MAAM,WAAW,CAAC;AAC9D,YAAY,EAAE,SAAS,EAAE,WAAW,EAAE,YAAY,EAAE,MAAM,WAAW,CAAC;AACtE,OAAO,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;AAC9C,YAAY,EAAE,WAAW,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAC1D,OAAO,EACL,SAAS,EACT,YAAY,EACZ,gBAAgB,EAChB,cAAc,EACd,iBAAiB,GAClB,MAAM,aAAa,CAAC;AAErB,OAAO,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAC;AAC5C,OAAO,EAAE,WAAW,EAAE,UAAU,EAAE,QAAQ,EAAE,SAAS,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AACvF,YAAY,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAEhD,cAAc,YAAY,CAAC"}
@@ -0,0 +1,10 @@
1
+ // Public entry point for the API client library.
2
+ export { CkanClient, siteRoot } from "./client.js";
3
+ export { RequestEngine, DEFAULT_BASE_URL } from "./engine.js";
4
+ export { MAX_TIMEOUT_MS, nodeHttpTransport } from "./http.js";
5
+ export { buildQueryString } from "./query.js";
6
+ export { CkanError, CkanApiError, CkanNetworkError, CkanParseError, describeCkanError, } from "./errors.js";
7
+ export { PORTALS } from "./portals-list.js";
8
+ export { checkPortal, findPortal, mapLimit, portalKey, withCheck } from "./portals.js";
9
+ export * from "./types.js";
10
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/client/index.ts"],"names":[],"mappings":"AAAA,iDAAiD;AAEjD,OAAO,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AACnD,OAAO,EAAE,aAAa,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAE9D,OAAO,EAAE,cAAc,EAAE,iBAAiB,EAAE,MAAM,WAAW,CAAC;AAE9D,OAAO,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;AAE9C,OAAO,EACL,SAAS,EACT,YAAY,EACZ,gBAAgB,EAChB,cAAc,EACd,iBAAiB,GAClB,MAAM,aAAa,CAAC;AAErB,OAAO,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAC;AAC5C,OAAO,EAAE,WAAW,EAAE,UAAU,EAAE,QAAQ,EAAE,SAAS,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAGvF,cAAc,YAAY,CAAC"}
@@ -0,0 +1,3 @@
1
+ import type { Portal } from "./types.js";
2
+ export declare const PORTALS: readonly Portal[];
3
+ //# sourceMappingURL=portals-list.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"portals-list.d.ts","sourceRoot":"","sources":["../../../src/client/portals-list.ts"],"names":[],"mappings":"AAcA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,YAAY,CAAC;AAQzC,eAAO,MAAM,OAAO,EAAE,SAAS,MAAM,EAkRnC,CAAC"}