@maschinenlesbar.org/ckan-cli 0.0.5 → 0.0.6
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 +28 -14
- package/dist/src/cli/commands/catalogue.d.ts.map +1 -1
- package/dist/src/cli/commands/catalogue.js +11 -6
- package/dist/src/cli/commands/catalogue.js.map +1 -1
- package/dist/src/cli/commands/portal.d.ts.map +1 -1
- package/dist/src/cli/commands/portal.js +8 -1
- package/dist/src/cli/commands/portal.js.map +1 -1
- package/dist/src/cli/index.js +2 -0
- package/dist/src/cli/index.js.map +1 -1
- package/dist/src/cli/io.d.ts +17 -0
- package/dist/src/cli/io.d.ts.map +1 -1
- package/dist/src/cli/io.js +22 -0
- package/dist/src/cli/io.js.map +1 -1
- package/dist/src/cli/program.d.ts.map +1 -1
- package/dist/src/cli/program.js +24 -5
- package/dist/src/cli/program.js.map +1 -1
- package/dist/src/cli/shared.d.ts +24 -5
- package/dist/src/cli/shared.d.ts.map +1 -1
- package/dist/src/cli/shared.js +70 -7
- package/dist/src/cli/shared.js.map +1 -1
- package/dist/src/client/client.d.ts +7 -1
- package/dist/src/client/client.d.ts.map +1 -1
- package/dist/src/client/client.js +67 -18
- package/dist/src/client/client.js.map +1 -1
- package/dist/src/client/engine.d.ts +53 -2
- package/dist/src/client/engine.d.ts.map +1 -1
- package/dist/src/client/engine.js +152 -48
- package/dist/src/client/engine.js.map +1 -1
- package/dist/src/client/errors.d.ts +6 -0
- package/dist/src/client/errors.d.ts.map +1 -1
- package/dist/src/client/errors.js +23 -2
- package/dist/src/client/errors.js.map +1 -1
- package/dist/src/client/http.js +3 -3
- package/dist/src/client/http.js.map +1 -1
- package/dist/src/client/index.d.ts +2 -2
- package/dist/src/client/index.d.ts.map +1 -1
- package/dist/src/client/index.js +2 -2
- package/dist/src/client/index.js.map +1 -1
- package/dist/src/client/portals.d.ts.map +1 -1
- package/dist/src/client/portals.js +2 -0
- package/dist/src/client/portals.js.map +1 -1
- package/dist/src/client/types.d.ts +5 -0
- package/dist/src/client/types.d.ts.map +1 -1
- package/package.json +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../../src/client/client.ts"],"names":[],"mappings":"AAGA,OAAO,
|
|
1
|
+
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../../src/client/client.ts"],"names":[],"mappings":"AAGA,OAAO,EAAuD,KAAK,aAAa,EAAE,MAAM,aAAa,CAAC;AAEtG,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAC9C,OAAO,KAAK,EAEV,KAAK,EACL,eAAe,EACf,SAAS,EACT,OAAO,EACP,UAAU,EACV,YAAY,EACZ,OAAO,EACP,mBAAmB,EACnB,mBAAmB,EACnB,QAAQ,EACR,MAAM,EACN,aAAa,EACd,MAAM,YAAY,CAAC;AAwEpB;;;;;GAKG;AACH,wBAAgB,QAAQ,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,CAOhD;AAED,qBAAa,UAAU;IACrB,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAgB;IACvC,yDAAyD;IACzD,OAAO,CAAC,QAAQ,CAAC,IAAI,CAAS;IAE9B,YAAY,OAAO,GAAE,aAAkB,EAGtC;IAED,sEAAsE;IAChE,MAAM,CAAC,CAAC,GAAG,SAAS,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,GAAE,WAAgB,GAAG,OAAO,CAAC,CAAC,CAAC,CAuB9E;IAED;;;;OAIG;YACW,KAAK;IAWnB,qEAAqE;IACrE,MAAM,IAAI,OAAO,CAAC,MAAM,CAAC,CAExB;IAED;;;;;;;;;OASG;IACH,aAAa,CAAC,MAAM,GAAE,mBAAwB,GAAG,OAAO,CAAC,mBAAmB,CAAC,CAa5E;IAED,sCAAsC;IACtC,WAAW,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC,CAExC;IAED,uDAAuD;IACvD,gBAAgB,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,YAAY,CAAC,CAElD;IAED,qDAAqD;IACrD,SAAS,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,KAAK,CAAC,CAEpC;IAED,8CAA8C;IAC9C,YAAY,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,QAAQ,CAAC,CAE1C;IAED,kFAAkF;IAC5E,WAAW,CAAC,MAAM,GAAE,UAAe,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC,CAQ5D;IAED;;;OAGG;IACH,gBAAgB,CAAC,MAAM,GAAE,eAAoB,GAAG,OAAO,CAAC,SAAS,EAAE,CAAC,CAEnE;IAED,oFAAoF;IACpF,SAAS,CAAC,MAAM,GAAE,eAAoB,GAAG,OAAO,CAAC,SAAS,EAAE,CAAC,CAE5D;IAED,0DAA0D;IAC1D,OAAO,CAAC,MAAM,GAAE,aAAkB,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC,CAErD;IAED,uCAAuC;IACvC,WAAW,IAAI,OAAO,CAAC,OAAO,EAAE,CAAC,CAEhC;IAED;;;;;;;;;;;OAWG;YACW,cAAc;IAuC5B;;;OAGG;YACW,IAAI;CAInB"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// CkanClient — a typed client over the open (no-auth) read endpoints of any CKAN
|
|
2
2
|
// Action API (`<site>/api/3/action`).
|
|
3
|
-
import { DEFAULT_BASE_URL, RequestEngine } from "./engine.js";
|
|
4
|
-
import { CkanError, CkanParseError, describeCkanError } from "./errors.js";
|
|
3
|
+
import { DEFAULT_BASE_URL, RequestEngine, sanitizeServerText } from "./engine.js";
|
|
4
|
+
import { CkanError, CkanParseError, describeCkanError, redactUrl } from "./errors.js";
|
|
5
5
|
const ACTION = "/api/3/action";
|
|
6
6
|
/**
|
|
7
7
|
* CKAN action names are always `[a-z0-9_]+`. Restricting to that allowlist closes
|
|
@@ -27,7 +27,9 @@ function entryKey(entry) {
|
|
|
27
27
|
* treated as "no filter" rather than forwarded as `query=`.
|
|
28
28
|
*/
|
|
29
29
|
function prune(params) {
|
|
30
|
-
|
|
30
|
+
// A null-prototype object, so a `__proto__` key is kept as a parameter instead
|
|
31
|
+
// of setting the prototype (and being lost).
|
|
32
|
+
const out = Object.create(null);
|
|
31
33
|
for (const [k, v] of Object.entries(params)) {
|
|
32
34
|
if (v === undefined || v === "")
|
|
33
35
|
continue;
|
|
@@ -35,6 +37,34 @@ function prune(params) {
|
|
|
35
37
|
}
|
|
36
38
|
return out;
|
|
37
39
|
}
|
|
40
|
+
/** A JSON object (not null, not an array). */
|
|
41
|
+
function isObject(value) {
|
|
42
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
43
|
+
}
|
|
44
|
+
/** A `package_search` result: an object with a numeric count and a results array. */
|
|
45
|
+
function isSearchResult(value) {
|
|
46
|
+
if (!isObject(value))
|
|
47
|
+
return false;
|
|
48
|
+
const count = value["count"];
|
|
49
|
+
return typeof count === "number" && Number.isSafeInteger(count) && count >= 0 && Array.isArray(value["results"]);
|
|
50
|
+
}
|
|
51
|
+
/** The error for a `result` that does not have the shape the caller relies on. */
|
|
52
|
+
function shapeError(name, expected) {
|
|
53
|
+
return new CkanParseError(`Unexpected response shape from ${ACTION}/${name}: expected ${expected}.`);
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Check a `*_list` limit. CKAN reads `limit=0` as "no limit" (a whole catalogue,
|
|
57
|
+
* 245,893 names on Hamburg), while the `all_fields` pager would read it as "no
|
|
58
|
+
* entries"; so 0, like any non-positive or fractional value, is refused. To get
|
|
59
|
+
* the whole list, leave the limit out.
|
|
60
|
+
*/
|
|
61
|
+
function assertLimit(limit) {
|
|
62
|
+
if (limit === undefined)
|
|
63
|
+
return;
|
|
64
|
+
if (!Number.isSafeInteger(limit) || limit < 1) {
|
|
65
|
+
throw new CkanError(`Invalid limit: expected a positive integer, got ${String(limit)}. Leave it out for the whole list.`);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
38
68
|
/**
|
|
39
69
|
* The site root of a CKAN instance, from what a user is likely to paste: portals
|
|
40
70
|
* document their API as `<site>/api/3/action`, so that suffix (or `/api/3`) is
|
|
@@ -45,7 +75,7 @@ export function siteRoot(baseUrl) {
|
|
|
45
75
|
// The API path is appended to the base URL, so a query string or fragment in it
|
|
46
76
|
// would end up in front of `/api/3/action` and break every request.
|
|
47
77
|
if (/[?#]/.test(baseUrl)) {
|
|
48
|
-
throw new CkanError(`The base URL must not contain a query string or fragment: ${baseUrl}`);
|
|
78
|
+
throw new CkanError(`The base URL must not contain a query string or fragment: ${redactUrl(baseUrl)}`);
|
|
49
79
|
}
|
|
50
80
|
return baseUrl.replace(/\/+$/, "").replace(/\/api\/3(\/action)?$/, "");
|
|
51
81
|
}
|
|
@@ -66,16 +96,33 @@ export class CkanClient {
|
|
|
66
96
|
// Another JSON API at the same path (or a proxy's JSON error page) is not an
|
|
67
97
|
// envelope; say so rather than "failed: undefined".
|
|
68
98
|
if (typeof env !== "object" || env === null || Array.isArray(env) || typeof env.success !== "boolean") {
|
|
69
|
-
throw new CkanParseError(`The answer to "${name}" is not a CKAN Action API response; is ${this.site} a CKAN site?`);
|
|
99
|
+
throw new CkanParseError(`The answer to "${name}" is not a CKAN Action API response; is ${redactUrl(this.site)} a CKAN site?`);
|
|
70
100
|
}
|
|
71
101
|
if (!env.success) {
|
|
72
|
-
|
|
102
|
+
// A success:false envelope can come with HTTP 200, so it never passes the
|
|
103
|
+
// engine's error-detail sanitising: strip terminal controls here too.
|
|
104
|
+
throw new CkanError(`CKAN action "${name}" failed: ${sanitizeServerText(describeCkanError(env.error))}`);
|
|
73
105
|
}
|
|
106
|
+
// `{"success": true}` without a result would print nothing useful (and the CLI
|
|
107
|
+
// would crash rendering `undefined`); CKAN always sends one, `null` included.
|
|
108
|
+
if (env.result === undefined)
|
|
109
|
+
throw shapeError(name, "a result in the envelope");
|
|
74
110
|
return env.result;
|
|
75
111
|
}
|
|
112
|
+
/**
|
|
113
|
+
* An action whose `result` must have a known top-level shape (never a deep
|
|
114
|
+
* schema): a broken or foreign answer becomes a CkanParseError naming the
|
|
115
|
+
* action, not a TypeError further down (`page is not iterable`).
|
|
116
|
+
*/
|
|
117
|
+
async typed(name, params, ok, expected) {
|
|
118
|
+
const result = await this.action(name, params);
|
|
119
|
+
if (!ok(result))
|
|
120
|
+
throw shapeError(name, expected);
|
|
121
|
+
return result;
|
|
122
|
+
}
|
|
76
123
|
/** Site title, CKAN version and enabled extensions of the portal. */
|
|
77
124
|
status() {
|
|
78
|
-
return this.
|
|
125
|
+
return this.typed("status_show", {}, isObject, "a JSON object");
|
|
79
126
|
}
|
|
80
127
|
/**
|
|
81
128
|
* Full-text / faceted dataset search.
|
|
@@ -90,7 +137,7 @@ export class CkanClient {
|
|
|
90
137
|
packageSearch(params = {}) {
|
|
91
138
|
const fq = (params.fq ?? []).filter((f) => f !== "");
|
|
92
139
|
const facetFields = params.facet_field ?? [];
|
|
93
|
-
return this.
|
|
140
|
+
return this.typed("package_search", {
|
|
94
141
|
q: params.q,
|
|
95
142
|
fq: fq.length === 1 ? fq[0] : undefined,
|
|
96
143
|
fq_list: fq.length > 1 ? fq : undefined,
|
|
@@ -99,7 +146,7 @@ export class CkanClient {
|
|
|
99
146
|
sort: params.sort,
|
|
100
147
|
"facet.field": facetFields.length > 0 ? JSON.stringify(facetFields) : undefined,
|
|
101
148
|
"facet.limit": params.facet_limit,
|
|
102
|
-
});
|
|
149
|
+
}, isSearchResult, "an object with a numeric count and a results array");
|
|
103
150
|
}
|
|
104
151
|
/** A single dataset by id or name. */
|
|
105
152
|
packageShow(id) {
|
|
@@ -117,9 +164,10 @@ export class CkanClient {
|
|
|
117
164
|
resourceShow(id) {
|
|
118
165
|
return this.show("resource_show", id);
|
|
119
166
|
}
|
|
120
|
-
/** Dataset names, paged with limit/offset. */
|
|
121
|
-
packageList(params = {}) {
|
|
122
|
-
|
|
167
|
+
/** Dataset names, paged with limit/offset (a positive limit; omit it for all). */
|
|
168
|
+
async packageList(params = {}) {
|
|
169
|
+
assertLimit(params.limit);
|
|
170
|
+
return this.typed("package_list", { limit: params.limit, offset: params.offset }, Array.isArray, "an array");
|
|
123
171
|
}
|
|
124
172
|
/**
|
|
125
173
|
* Organization names, or full objects with `all_fields`. See `groupOrOrgList`
|
|
@@ -134,11 +182,11 @@ export class CkanClient {
|
|
|
134
182
|
}
|
|
135
183
|
/** Tags, optionally only those containing a substring. */
|
|
136
184
|
tagList(params = {}) {
|
|
137
|
-
return this.
|
|
185
|
+
return this.typed("tag_list", { query: params.query }, Array.isArray, "an array");
|
|
138
186
|
}
|
|
139
187
|
/** The licences this portal offers. */
|
|
140
188
|
licenseList() {
|
|
141
|
-
return this.
|
|
189
|
+
return this.typed("license_list", {}, Array.isArray, "an array");
|
|
142
190
|
}
|
|
143
191
|
/**
|
|
144
192
|
* `organization_list` / `group_list`. CKAN caps an `all_fields` list at
|
|
@@ -153,19 +201,20 @@ export class CkanClient {
|
|
|
153
201
|
* that ignores `offset` cannot keep it going.
|
|
154
202
|
*/
|
|
155
203
|
async groupOrOrgList(action, params) {
|
|
204
|
+
assertLimit(params.limit);
|
|
156
205
|
if (!params.all_fields) {
|
|
157
|
-
return this.
|
|
206
|
+
return this.typed(action, { limit: params.limit, offset: params.offset }, Array.isArray, "an array");
|
|
158
207
|
}
|
|
159
208
|
const wanted = params.limit ?? Infinity;
|
|
160
209
|
let offset = params.offset ?? 0;
|
|
161
210
|
const seen = new Set();
|
|
162
211
|
const out = [];
|
|
163
212
|
while (out.length < wanted) {
|
|
164
|
-
const page = await this.
|
|
213
|
+
const page = await this.typed(action, {
|
|
165
214
|
all_fields: true,
|
|
166
215
|
limit: Math.min(ALL_FIELDS_PAGE, wanted - out.length),
|
|
167
216
|
offset: offset === 0 ? undefined : offset,
|
|
168
|
-
});
|
|
217
|
+
}, Array.isArray, "an array");
|
|
169
218
|
let added = 0;
|
|
170
219
|
for (const entry of page) {
|
|
171
220
|
const key = entryKey(entry);
|
|
@@ -188,7 +237,7 @@ export class CkanClient {
|
|
|
188
237
|
async show(action, id) {
|
|
189
238
|
if (id.trim() === "")
|
|
190
239
|
throw new CkanError(`${action} needs an id or name.`);
|
|
191
|
-
return this.
|
|
240
|
+
return this.typed(action, { id }, isObject, "a JSON object");
|
|
192
241
|
}
|
|
193
242
|
}
|
|
194
243
|
//# sourceMappingURL=client.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"client.js","sourceRoot":"","sources":["../../../src/client/client.ts"],"names":[],"mappings":"AAAA,iFAAiF;AACjF,sCAAsC;AAEtC,OAAO,EAAE,gBAAgB,EAAE,aAAa,EAAsB,MAAM,aAAa,CAAC;
|
|
1
|
+
{"version":3,"file":"client.js","sourceRoot":"","sources":["../../../src/client/client.ts"],"names":[],"mappings":"AAAA,iFAAiF;AACjF,sCAAsC;AAEtC,OAAO,EAAE,gBAAgB,EAAE,aAAa,EAAE,kBAAkB,EAAsB,MAAM,aAAa,CAAC;AACtG,OAAO,EAAE,SAAS,EAAE,cAAc,EAAE,iBAAiB,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAkBtF,MAAM,MAAM,GAAG,eAAe,CAAC;AAE/B;;;;;GAKG;AACH,MAAM,WAAW,GAAG,cAAc,CAAC;AAEnC,qEAAqE;AACrE,MAAM,eAAe,GAAG,EAAE,CAAC;AAE3B,0FAA0F;AAC1F,SAAS,QAAQ,CAAC,KAAgB;IAChC,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,IAAI,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE,CAAC;QACzE,MAAM,EAAE,GAAG,KAAK,CAAC,IAAI,CAAC,CAAC;QACvB,IAAI,OAAO,EAAE,KAAK,QAAQ;YAAE,OAAO,MAAM,EAAE,EAAE,CAAC;IAChD,CAAC;IACD,OAAO,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC;AAC/B,CAAC;AAED;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AE,KAAK,EAAE;YAAE,MAAM,IAAI,SAAS,CAAC,GAAG,MAAM,uBAAuB,CAAC,CAAC;QAC5E,OAAO,IAAI,CAAC,KAAK,CAAI,MAAM,EAAE,EAAE,EAAE,EAAE,EAAE,QAAQ,EAAE,eAAe,CAAC,CAAC;IAClE,CAAC;CACF"}
|
|
@@ -17,9 +17,13 @@ export interface EngineOptions {
|
|
|
17
17
|
userAgent?: string;
|
|
18
18
|
/** Per-request timeout in milliseconds (0 disables; capped at `MAX_TIMEOUT_MS`, 2^31 - 1 ms). */
|
|
19
19
|
timeoutMs?: number;
|
|
20
|
-
/**
|
|
20
|
+
/**
|
|
21
|
+
* Number of automatic retries for transient (429/503) responses. Each waits the
|
|
22
|
+
* response's `Retry-After` (up to `MAX_RETRY_AFTER_MS`; a longer one is not
|
|
23
|
+
* retried), or else `retryDelayMs * attempt`.
|
|
24
|
+
*/
|
|
21
25
|
maxRetries?: number;
|
|
22
|
-
/** Base backoff between retries in milliseconds (grows linearly). */
|
|
26
|
+
/** Base backoff between retries in milliseconds (grows linearly); used without a Retry-After. */
|
|
23
27
|
retryDelayMs?: number;
|
|
24
28
|
/** Number of HTTP redirects (301/302/303/307/308) to follow. Defaults to 5. */
|
|
25
29
|
maxRedirects?: number;
|
|
@@ -31,6 +35,53 @@ export interface EngineOptions {
|
|
|
31
35
|
/** Injectable sleep, primarily for deterministic tests. */
|
|
32
36
|
sleep?: (ms: number) => Promise<void>;
|
|
33
37
|
}
|
|
38
|
+
/** Most automatic retries the CLI's --max-retries accepts. */
|
|
39
|
+
export declare const MAX_RETRIES = 10;
|
|
40
|
+
/**
|
|
41
|
+
* Longest `Retry-After` the engine waits out before retrying a 429/503. When the
|
|
42
|
+
* server asks for longer, the engine does not retry at all and surfaces the error at
|
|
43
|
+
* once: retrying early would only land inside the window the server asked us to wait
|
|
44
|
+
* out, and a hostile value must not stall the CLI.
|
|
45
|
+
*/
|
|
46
|
+
export declare const MAX_RETRY_AFTER_MS = 30000;
|
|
47
|
+
/**
|
|
48
|
+
* Parse a `Retry-After` header into a delay in milliseconds (RFC 9110 §10.2.3):
|
|
49
|
+
* either delay-seconds (`"120"`) or an HTTP-date (`"Wed, 21 Oct 2026 07:28:00 GMT"`,
|
|
50
|
+
* turned into the time left from `now`; a date in the past gives 0).
|
|
51
|
+
*
|
|
52
|
+
* Returns `undefined` when the header is absent or malformed — negative (`"-1"`),
|
|
53
|
+
* fractional (`"1.5"`), padded inside, any other date format — so the caller falls
|
|
54
|
+
* back to its own backoff. The strict patterns matter: `Date.parse` alone would
|
|
55
|
+
* read `"1.5"` as a date in 2001 and retry at once.
|
|
56
|
+
*/
|
|
57
|
+
export declare function parseRetryAfter(header: string | string[] | undefined, now?: number): number | undefined;
|
|
58
|
+
/**
|
|
59
|
+
* True for the Unicode bidirectional formatting characters: ALM (U+061C), LRM/RLM
|
|
60
|
+
* (U+200E/U+200F), the embeddings and overrides U+202A–U+202E and the isolates
|
|
61
|
+
* U+2066–U+2069. A terminal applies them to the text that follows, so an override
|
|
62
|
+
* in server text can reorder what the user sees ("Trojan Source" spoofing).
|
|
63
|
+
*/
|
|
64
|
+
export declare function isBidiControl(code: number): boolean;
|
|
65
|
+
/**
|
|
66
|
+
* Make a string that originates in an attacker-controlled response — the error
|
|
67
|
+
* `detail`, a CKAN `success:false` error, the echoed Content-Type — safe to print
|
|
68
|
+
* into an error message on stderr:
|
|
69
|
+
*
|
|
70
|
+
* - C0 and C1 controls and DEL are dropped. A JSON error body can encode an escape
|
|
71
|
+
* (U+001B) that JSON.parse turns into a real control byte; printed raw, a hostile
|
|
72
|
+
* or MITM'd endpoint could drive ANSI/OSC sequences into the terminal (display
|
|
73
|
+
* spoofing, title changes, OSC 52 clipboard writes).
|
|
74
|
+
* - Bidi formatting characters (isBidiControl) are dropped, so server text cannot
|
|
75
|
+
* reorder the visible message.
|
|
76
|
+
* - Every run of whitespace — newlines, tabs, U+2028/U+2029 included — becomes one
|
|
77
|
+
* space and the ends are trimmed, so the text stays on one line and a server
|
|
78
|
+
* cannot forge an `Error:` line of its own.
|
|
79
|
+
*
|
|
80
|
+
* The CLI's JSON output is escaped separately (`escapeControlChars` in
|
|
81
|
+
* cli/shared.ts): `JSON.stringify` alone leaves DEL, C1 and bidi characters raw.
|
|
82
|
+
* Written as a char-code filter so no raw control byte appears in this source.
|
|
83
|
+
*/
|
|
84
|
+
export declare function sanitizeServerText(text: string): string;
|
|
34
85
|
export declare class RequestEngine {
|
|
35
86
|
private readonly baseUrl;
|
|
36
87
|
private readonly transport;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"engine.d.ts","sourceRoot":"","sources":["../../../src/client/engine.ts"],"names":[],"mappings":"AAIA,OAAO,EAAqB,KAAK,SAAS,EAAE,MAAM,WAAW,CAAC;AAC9D,OAAO,EAAoB,KAAK,WAAW,EAAE,MAAM,YAAY,CAAC;AAGhE,eAAO,MAAM,gBAAgB,yCAAyC,CAAC;AAGvE,MAAM,WAAW,WAAW;IAC1B,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,EAAE,MAAM,CAAC;IACpB,MAAM,EAAE,MAAM,CAAC;IACf,kDAAkD;IAClD,GAAG,EAAE,MAAM,CAAC;CACb;AAED,MAAM,WAAW,aAAa;IAC5B,4GAA4G;IAC5G,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,+EAA+E;IAC/E,SAAS,CAAC,EAAE,SAAS,CAAC;IACtB,sCAAsC;IACtC,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,iGAAiG;IACjG,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB
|
|
1
|
+
{"version":3,"file":"engine.d.ts","sourceRoot":"","sources":["../../../src/client/engine.ts"],"names":[],"mappings":"AAIA,OAAO,EAAqB,KAAK,SAAS,EAAE,MAAM,WAAW,CAAC;AAC9D,OAAO,EAAoB,KAAK,WAAW,EAAE,MAAM,YAAY,CAAC;AAGhE,eAAO,MAAM,gBAAgB,yCAAyC,CAAC;AAGvE,MAAM,WA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C,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAS;IACnC,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAS;IACnC,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAS;IACpC,OAAO,CAAC,QAAQ,CAAC,YAAY,CAAS;IACtC,OAAO,CAAC,QAAQ,CAAC,YAAY,CAAS;IACtC,OAAO,CAAC,QAAQ,CAAC,gBAAgB,CAAS;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,CAwEtB;IAED,0DAA0D;IACpD,OAAO,CAAC,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,WAAW,GAAG,OAAO,CAAC,CAAC,CAAC,CAgB9D;IAED,OAAO,CAAC,UAAU;CA6BnB"}
|
|
@@ -3,29 +3,84 @@
|
|
|
3
3
|
// (429, 503), and decodes responses.
|
|
4
4
|
import { nodeHttpTransport } from "./http.js";
|
|
5
5
|
import { buildQueryString } from "./query.js";
|
|
6
|
-
import { CkanApiError, CkanNetworkError, CkanParseError, describeCkanError } from "./errors.js";
|
|
6
|
+
import { CkanApiError, CkanNetworkError, CkanParseError, describeCkanError, redactUrl } from "./errors.js";
|
|
7
7
|
export const DEFAULT_BASE_URL = "https://suche.transparenz.hamburg.de";
|
|
8
8
|
const DEFAULT_USER_AGENT = "ckan-cli";
|
|
9
9
|
const DEFAULT_MAX_RESPONSE_BYTES = 100 * 1024 * 1024;
|
|
10
|
+
/** Most automatic retries the CLI's --max-retries accepts. */
|
|
11
|
+
export const MAX_RETRIES = 10;
|
|
10
12
|
/**
|
|
11
|
-
*
|
|
12
|
-
*
|
|
13
|
-
*
|
|
14
|
-
*
|
|
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.
|
|
13
|
+
* Longest `Retry-After` the engine waits out before retrying a 429/503. When the
|
|
14
|
+
* server asks for longer, the engine does not retry at all and surfaces the error at
|
|
15
|
+
* once: retrying early would only land inside the window the server asked us to wait
|
|
16
|
+
* out, and a hostile value must not stall the CLI.
|
|
19
17
|
*/
|
|
20
|
-
|
|
18
|
+
export const MAX_RETRY_AFTER_MS = 30_000;
|
|
19
|
+
/** An IMF-fixdate (RFC 9110 §5.6.7), the one HTTP-date form senders must generate. */
|
|
20
|
+
const IMF_FIXDATE = /^(Mon|Tue|Wed|Thu|Fri|Sat|Sun), \d{2} (Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec) \d{4} \d{2}:\d{2}:\d{2} GMT$/;
|
|
21
|
+
/**
|
|
22
|
+
* Parse a `Retry-After` header into a delay in milliseconds (RFC 9110 §10.2.3):
|
|
23
|
+
* either delay-seconds (`"120"`) or an HTTP-date (`"Wed, 21 Oct 2026 07:28:00 GMT"`,
|
|
24
|
+
* turned into the time left from `now`; a date in the past gives 0).
|
|
25
|
+
*
|
|
26
|
+
* Returns `undefined` when the header is absent or malformed — negative (`"-1"`),
|
|
27
|
+
* fractional (`"1.5"`), padded inside, any other date format — so the caller falls
|
|
28
|
+
* back to its own backoff. The strict patterns matter: `Date.parse` alone would
|
|
29
|
+
* read `"1.5"` as a date in 2001 and retry at once.
|
|
30
|
+
*/
|
|
31
|
+
export function parseRetryAfter(header, now = Date.now()) {
|
|
32
|
+
const value = (Array.isArray(header) ? header[0] : header)?.trim();
|
|
33
|
+
if (value === undefined || value === "")
|
|
34
|
+
return undefined;
|
|
35
|
+
if (/^\d+$/.test(value))
|
|
36
|
+
return Number(value) * 1000;
|
|
37
|
+
if (!IMF_FIXDATE.test(value))
|
|
38
|
+
return undefined;
|
|
39
|
+
const when = Date.parse(value);
|
|
40
|
+
return Number.isNaN(when) ? undefined : Math.max(0, when - now);
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* True for the Unicode bidirectional formatting characters: ALM (U+061C), LRM/RLM
|
|
44
|
+
* (U+200E/U+200F), the embeddings and overrides U+202A–U+202E and the isolates
|
|
45
|
+
* U+2066–U+2069. A terminal applies them to the text that follows, so an override
|
|
46
|
+
* in server text can reorder what the user sees ("Trojan Source" spoofing).
|
|
47
|
+
*/
|
|
48
|
+
export function isBidiControl(code) {
|
|
49
|
+
return (code === 0x061c ||
|
|
50
|
+
code === 0x200e ||
|
|
51
|
+
code === 0x200f ||
|
|
52
|
+
(code >= 0x202a && code <= 0x202e) ||
|
|
53
|
+
(code >= 0x2066 && code <= 0x2069));
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Make a string that originates in an attacker-controlled response — the error
|
|
57
|
+
* `detail`, a CKAN `success:false` error, the echoed Content-Type — safe to print
|
|
58
|
+
* into an error message on stderr:
|
|
59
|
+
*
|
|
60
|
+
* - C0 and C1 controls and DEL are dropped. A JSON error body can encode an escape
|
|
61
|
+
* (U+001B) that JSON.parse turns into a real control byte; printed raw, a hostile
|
|
62
|
+
* or MITM'd endpoint could drive ANSI/OSC sequences into the terminal (display
|
|
63
|
+
* spoofing, title changes, OSC 52 clipboard writes).
|
|
64
|
+
* - Bidi formatting characters (isBidiControl) are dropped, so server text cannot
|
|
65
|
+
* reorder the visible message.
|
|
66
|
+
* - Every run of whitespace — newlines, tabs, U+2028/U+2029 included — becomes one
|
|
67
|
+
* space and the ends are trimmed, so the text stays on one line and a server
|
|
68
|
+
* cannot forge an `Error:` line of its own.
|
|
69
|
+
*
|
|
70
|
+
* The CLI's JSON output is escaped separately (`escapeControlChars` in
|
|
71
|
+
* cli/shared.ts): `JSON.stringify` alone leaves DEL, C1 and bidi characters raw.
|
|
72
|
+
* Written as a char-code filter so no raw control byte appears in this source.
|
|
73
|
+
*/
|
|
74
|
+
export function sanitizeServerText(text) {
|
|
21
75
|
let out = "";
|
|
22
76
|
for (const ch of text) {
|
|
23
77
|
const n = ch.codePointAt(0) ?? 0;
|
|
24
|
-
|
|
78
|
+
const whitespaceControl = n >= 0x09 && n <= 0x0d;
|
|
79
|
+
if (!whitespaceControl && (n <= 0x1f || (n >= 0x7f && n <= 0x9f) || isBidiControl(n)))
|
|
25
80
|
continue;
|
|
26
81
|
out += ch;
|
|
27
82
|
}
|
|
28
|
-
return out;
|
|
83
|
+
return out.replace(/\s+/g, " ").trim();
|
|
29
84
|
}
|
|
30
85
|
/**
|
|
31
86
|
* Reject a base URL whose scheme is not http(s). The default transport already
|
|
@@ -39,12 +94,24 @@ function assertHttpScheme(baseUrl) {
|
|
|
39
94
|
url = new URL(baseUrl);
|
|
40
95
|
}
|
|
41
96
|
catch {
|
|
42
|
-
throw new CkanNetworkError(`Invalid base URL: ${baseUrl}`);
|
|
97
|
+
throw new CkanNetworkError(`Invalid base URL: ${redactUrl(baseUrl)}`);
|
|
43
98
|
}
|
|
44
99
|
if (url.protocol !== "http:" && url.protocol !== "https:") {
|
|
45
|
-
throw new CkanNetworkError(`Unsupported protocol "${url.protocol}" in base URL: ${baseUrl}`);
|
|
100
|
+
throw new CkanNetworkError(`Unsupported protocol "${url.protocol}" in base URL: ${redactUrl(baseUrl)}`);
|
|
46
101
|
}
|
|
47
102
|
}
|
|
103
|
+
// The headers the engine sets itself, under the exact keys it uses. They are the
|
|
104
|
+
// only ones that follow a cross-origin redirect.
|
|
105
|
+
const ENGINE_HEADERS = new Set(["Accept", "User-Agent"]);
|
|
106
|
+
/**
|
|
107
|
+
* A copy of `headers` with only the engine's own non-credential headers (used on
|
|
108
|
+
* cross-origin redirects). A list of known credential headers is never complete
|
|
109
|
+
* (Proxy-Authorization, X-Auth-Token, ...), so an allowlist is kept instead. A new
|
|
110
|
+
* object, so the one already handed to the transport is not changed.
|
|
111
|
+
*/
|
|
112
|
+
function engineHeadersOnly(headers) {
|
|
113
|
+
return Object.fromEntries(Object.entries(headers).filter(([key]) => ENGINE_HEADERS.has(key)));
|
|
114
|
+
}
|
|
48
115
|
const realSleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
|
|
49
116
|
export class RequestEngine {
|
|
50
117
|
baseUrl;
|
|
@@ -98,42 +165,49 @@ export class RequestEngine {
|
|
|
98
165
|
const status = response.status;
|
|
99
166
|
const retryable = status === 429 || status === 503;
|
|
100
167
|
if (retryable && attempt < this.maxRetries) {
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
168
|
+
// Honour Retry-After; without a usable one, back off linearly. A Retry-After
|
|
169
|
+
// beyond MAX_RETRY_AFTER_MS is not retried: the error below surfaces at once.
|
|
170
|
+
const retryAfter = parseRetryAfter(response.headers["retry-after"]);
|
|
171
|
+
if (retryAfter === undefined || retryAfter <= MAX_RETRY_AFTER_MS) {
|
|
172
|
+
attempt += 1;
|
|
173
|
+
await this.sleep(retryAfter ?? this.retryDelayMs * attempt);
|
|
174
|
+
continue;
|
|
175
|
+
}
|
|
104
176
|
}
|
|
105
177
|
// Follow redirects, resolving the Location relative to the current URL.
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
url = next.toString();
|
|
119
|
-
redirects += 1;
|
|
120
|
-
continue;
|
|
178
|
+
const location = response.headers["location"];
|
|
179
|
+
const isRedirect = status >= 300 && status < 400;
|
|
180
|
+
const nextUrl = isRedirect && redirects < this.maxRedirects ? resolveLocation(location, url) : undefined;
|
|
181
|
+
if (nextUrl !== undefined) {
|
|
182
|
+
// Credential-strip guard: if the redirect crosses origin (scheme + host +
|
|
183
|
+
// port, so an https->http downgrade counts), keep only the engine's own
|
|
184
|
+
// non-credential headers, so any future auth/cookie header is never
|
|
185
|
+
// re-sent to a different host. The User-Agent stays: Hamburg's own
|
|
186
|
+
// http: -> https: hop is cross-origin, and dropping it sent every request
|
|
187
|
+
// through an http:// base URL without one (and ignored --user-agent).
|
|
188
|
+
if (nextUrl.origin !== new URL(url).origin) {
|
|
189
|
+
headers = engineHeadersOnly(headers);
|
|
121
190
|
}
|
|
191
|
+
url = nextUrl.toString();
|
|
192
|
+
redirects += 1;
|
|
193
|
+
continue;
|
|
122
194
|
}
|
|
123
195
|
const contentType = String(response.headers["content-type"] ?? "");
|
|
124
196
|
if (status < 200 || status >= 300) {
|
|
125
|
-
// A 3xx that was not followed
|
|
126
|
-
//
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
197
|
+
// A 3xx that was not followed: say why, or a bare "HTTP 301" reads like a
|
|
198
|
+
// redirect this client cannot follow. Past the limit it is a loop; a
|
|
199
|
+
// missing or malformed Location (which `new URL` would have thrown on as
|
|
200
|
+
// an "Unexpected error") is named as it came, sanitised.
|
|
201
|
+
if (isRedirect) {
|
|
202
|
+
const target = resolveLocation(location, url);
|
|
203
|
+
const detail = target !== undefined
|
|
204
|
+
? `stopped after ${this.maxRedirects} redirects (a redirect loop?)`
|
|
205
|
+
: location
|
|
206
|
+
? `redirect to ${sanitizeServerText(location)} not followed`
|
|
207
|
+
: "redirect not followed (no Location header)";
|
|
208
|
+
throw new CkanApiError({ status, url, method, body: response.body.toString("utf8"), detail });
|
|
209
|
+
}
|
|
210
|
+
throw this.toApiError(method, url, status, response.body);
|
|
137
211
|
}
|
|
138
212
|
return { data: response.body, contentType, status, url };
|
|
139
213
|
}
|
|
@@ -141,17 +215,19 @@ export class RequestEngine {
|
|
|
141
215
|
/** Perform a GET expecting JSON and parse it into `T`. */
|
|
142
216
|
async getJson(path, query) {
|
|
143
217
|
const res = await this.request("GET", path, { query, accept: "application/json" });
|
|
144
|
-
const text = res.data.
|
|
218
|
+
const text = decodeBody(res.data, res.contentType, res.url);
|
|
145
219
|
try {
|
|
146
220
|
return JSON.parse(text);
|
|
147
221
|
}
|
|
148
222
|
catch (cause) {
|
|
149
223
|
// Name the URL and what came back: a site that is not a CKAN (or not at this
|
|
150
224
|
// path) typically answers with an HTML page and HTTP 200.
|
|
151
|
-
|
|
225
|
+
// The Content-Type is server text (latin-1 decoded, so a 0x9B byte is the
|
|
226
|
+
// 8-bit CSI U+009B): sanitise it before it reaches stderr.
|
|
227
|
+
const mediaType = sanitizeServerText(res.contentType.split(";")[0]);
|
|
152
228
|
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"}`;
|
|
229
|
+
? `Invalid JSON from ${redactUrl(res.url)}`
|
|
230
|
+
: `Expected JSON from ${redactUrl(res.url)} but got ${mediaType || "a body that is not JSON"}`;
|
|
155
231
|
throw new CkanParseError(message, { cause });
|
|
156
232
|
}
|
|
157
233
|
}
|
|
@@ -190,4 +266,32 @@ export class RequestEngine {
|
|
|
190
266
|
return new CkanApiError({ status, url, method, body: text, detail });
|
|
191
267
|
}
|
|
192
268
|
}
|
|
269
|
+
/**
|
|
270
|
+
* Decode a response body by the charset of its Content-Type (UTF-8 when none is
|
|
271
|
+
* given, as JSON requires). A leading byte-order mark is dropped: TextDecoder does
|
|
272
|
+
* that by default, where Buffer#toString kept it and JSON.parse then failed. CKAN
|
|
273
|
+
* sends UTF-8; this matters for proxies and mirrors that re-encode.
|
|
274
|
+
*/
|
|
275
|
+
function decodeBody(body, contentType, url) {
|
|
276
|
+
const charset = /;\s*charset\s*=\s*"?([^";\s]+)"?/i.exec(contentType)?.[1] ?? "utf-8";
|
|
277
|
+
let decoder;
|
|
278
|
+
try {
|
|
279
|
+
decoder = new TextDecoder(charset);
|
|
280
|
+
}
|
|
281
|
+
catch {
|
|
282
|
+
throw new CkanParseError(`Unsupported response charset "${sanitizeServerText(charset)}" from ${redactUrl(url)}.`);
|
|
283
|
+
}
|
|
284
|
+
return decoder.decode(body);
|
|
285
|
+
}
|
|
286
|
+
/** Resolve a Location header against the current URL; undefined if missing or malformed. */
|
|
287
|
+
function resolveLocation(location, base) {
|
|
288
|
+
if (location === undefined || location === "")
|
|
289
|
+
return undefined;
|
|
290
|
+
try {
|
|
291
|
+
return new URL(location, base);
|
|
292
|
+
}
|
|
293
|
+
catch {
|
|
294
|
+
return undefined;
|
|
295
|
+
}
|
|
296
|
+
}
|
|
193
297
|
//# sourceMappingURL=engine.js.map
|
|
@@ -1 +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;
|
|
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,SAAS,EAAE,MAAM,aAAa,CAAC;AAE3G,MAAM,CAAC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AO,CAAC,UAAU,SAAS,CAAC,GAAG,CAAC,GAAG,CACxF,CAAC;IACJ,CAAC;IACD,OAAO,OAAO,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;AAC9B,CAAC;AAED,4FAA4F;AAC5F,SAAS,eAAe,CAAC,QAA4B,EAAE,IAAY;IACjE,IAAI,QAAQ,KAAK,SAAS,IAAI,QAAQ,KAAK,EAAE;QAAE,OAAO,SAAS,CAAC;IAChE,IAAI,CAAC;QACH,OAAO,IAAI,GAAG,CAAC,QAAQ,EAAE,IAAI,CAAC,CAAC;IACjC,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,SAAS,CAAC;IACnB,CAAC;AACH,CAAC"}
|
|
@@ -1,3 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Replace the userinfo of a URL (`https://user:secret@host/...`) with `***`, so a
|
|
3
|
+
* credential in a base URL never reaches an error message, a log or CI output.
|
|
4
|
+
* A URL without userinfo, or one that does not parse, is returned unchanged.
|
|
5
|
+
*/
|
|
6
|
+
export declare function redactUrl(url: string): string;
|
|
1
7
|
/** Base class for every error originating from this client. */
|
|
2
8
|
export declare class CkanError extends Error {
|
|
3
9
|
constructor(message: string, options?: {
|
|
@@ -1 +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,CA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