@absolutejs/search 0.2.1 → 0.2.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
@@ -6,6 +6,18 @@ This file is generated by `absolute-changelog` from the entries in
6
6
  `changelog/`. Edit an entry, not this file — and add new ones under
7
7
  `changelog/unreleased/`.
8
8
 
9
+ ## 0.2.3 — 2026-10-22
10
+
11
+ ### Changed
12
+
13
+ - **SearchAttempt includes optional errorCode and errorMessage fields for sanitized provider diagnostics.** (`SearchAttempt`)
14
+
15
+ ## 0.2.2 — 2026-10-22
16
+
17
+ ### Fixed
18
+
19
+ - **Preserve sanitized Brave error codes, explanations and request IDs; classify invalid subscription tokens as unavailable rather than generic HTTP 422 errors.**
20
+
9
21
  ## 0.2.1 — 2026-09-28
10
22
 
11
23
  ### Fixed
package/changelog.json CHANGED
@@ -2,6 +2,29 @@
2
2
  "contract": 1,
3
3
  "name": "@absolutejs/search",
4
4
  "releases": [
5
+ {
6
+ "changes": [
7
+ {
8
+ "kind": "changed",
9
+ "summary": "SearchAttempt includes optional errorCode and errorMessage fields for sanitized provider diagnostics.",
10
+ "symbols": [
11
+ "SearchAttempt"
12
+ ]
13
+ }
14
+ ],
15
+ "date": "2026-10-22",
16
+ "version": "0.2.3"
17
+ },
18
+ {
19
+ "changes": [
20
+ {
21
+ "kind": "fixed",
22
+ "summary": "Preserve sanitized Brave error codes, explanations and request IDs; classify invalid subscription tokens as unavailable rather than generic HTTP 422 errors."
23
+ }
24
+ ],
25
+ "date": "2026-10-22",
26
+ "version": "0.2.2"
27
+ },
5
28
  {
6
29
  "changes": [
7
30
  {
package/dist/brave.js CHANGED
@@ -194,9 +194,17 @@ var createBraveSearch = (options) => {
194
194
  if (!response.ok) {
195
195
  result.status = response.status === 429 ? "rate_limited" : response.status === 401 || response.status === 403 ? "unavailable" : "error";
196
196
  const error = await response.json().catch(() => null);
197
- if (record(error) && record(error.error) && error.error.code === "QUOTA_LIMITED")
198
- result.status = "quota_exceeded";
199
- result.limitations.push(`Brave request failed with HTTP ${response.status}`);
197
+ if (record(error) && record(error.error)) {
198
+ const sanitize = (value) => text(value)?.split(options.apiKey).join("[redacted]").replace(/Bearer\s+\S+/giu, "Bearer [redacted]").replace(/[\r\n]+/gu, " ").slice(0, 500);
199
+ attempt.errorCode = sanitize(error.error.code);
200
+ attempt.errorMessage = sanitize(error.error.detail);
201
+ attempt.providerRequestId ??= sanitize(error.error.id);
202
+ if (attempt.errorCode === "QUOTA_LIMITED")
203
+ result.status = "quota_exceeded";
204
+ if (attempt.errorCode === "SUBSCRIPTION_TOKEN_INVALID")
205
+ result.status = "unavailable";
206
+ }
207
+ result.limitations.push(`Brave request failed with HTTP ${response.status}${attempt.errorCode ? ` (${attempt.errorCode})` : ""}${attempt.errorMessage ? `: ${attempt.errorMessage}` : ""}`);
200
208
  } else {
201
209
  const body = await response.json();
202
210
  if (!record(body))
@@ -214,27 +222,27 @@ var createBraveSearch = (options) => {
214
222
  invalid++;
215
223
  continue;
216
224
  }
217
- const url2 = publicUrl(row.url);
225
+ const url = publicUrl(row.url);
218
226
  const excerpts = mode === "context" ? strings(row.snippets) : [
219
227
  text(row.description),
220
228
  ...strings(row.extra_snippets)
221
229
  ].filter((item) => Boolean(item));
222
- if (!url2 || !text(row.title) || mode === "context" && !excerpts.length) {
230
+ if (!url || !text(row.title) || mode === "context" && !excerpts.length) {
223
231
  invalid++;
224
232
  continue;
225
233
  }
226
234
  const metadata = record(body.sources) && record(body.sources[String(row.url)]) ? body.sources[String(row.url)] : {};
227
235
  const age = Array.isArray(metadata.age) ? text(metadata.age[3]) : undefined;
228
236
  const publishedAt = text(row.page_age) ?? age;
229
- const previous = byUrl.get(url2);
237
+ const previous = byUrl.get(url);
230
238
  if (previous)
231
239
  previous.excerpts = [
232
240
  ...new Set([...previous.excerpts, ...excerpts])
233
241
  ];
234
242
  else
235
- byUrl.set(url2, {
236
- id: url2,
237
- url: url2,
243
+ byUrl.set(url, {
244
+ id: url,
245
+ url,
238
246
  title: String(row.title),
239
247
  excerpts,
240
248
  retrievedAt: new Date(now()).toISOString(),
package/dist/index.js CHANGED
@@ -91,14 +91,14 @@ var withSearchCache = (provider, options) => {
91
91
  if (searchCompleted(result)) {
92
92
  const ttl = result.status === "empty" ? options.emptyTtlMs ?? 60000 : options.ttlMs ?? 300000;
93
93
  if (ttl > 0) {
94
- const entry2 = {
94
+ const entry = {
95
95
  result: structuredClone(result),
96
96
  expiresAt: now() + ttl
97
97
  };
98
98
  while (cache.size >= capacity)
99
99
  cache.delete(cache.keys().next().value);
100
- cache.set(key, entry2);
101
- await options.store?.set(key, entry2);
100
+ cache.set(key, entry);
101
+ await options.store?.set(key, entry);
102
102
  }
103
103
  }
104
104
  return result;
package/dist/types.d.ts CHANGED
@@ -34,6 +34,10 @@ export type SearchAttempt = {
34
34
  durationMs: number;
35
35
  status: SearchStatus;
36
36
  httpStatus?: number;
37
+ /** Provider diagnostic code, retained independently of HTTP status. */
38
+ errorCode?: string;
39
+ /** Bounded provider explanation with the configured credential removed. */
40
+ errorMessage?: string;
37
41
  retryAfterMs?: number;
38
42
  /** A successful HTTP response is billable even if parsing fails. */
39
43
  billing: "fulfilled" | "rejected" | "unknown" | "not_sent";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@absolutejs/search",
3
- "version": "0.2.1",
3
+ "version": "0.2.3",
4
4
  "type": "module",
5
5
  "description": "Provider-neutral web search, grounded evidence, and replaceable search adapters",
6
6
  "license": "BSL-1.1",