searxng-sdk 0.1.0
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/LICENSE +21 -0
- package/README.md +86 -0
- package/dist/index.cjs +297 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +95 -0
- package/dist/index.d.ts +95 -0
- package/dist/index.js +268 -0
- package/dist/index.js.map +1 -0
- package/package.json +54 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 intMeric
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
# searxng-sdk
|
|
2
|
+
|
|
3
|
+
Zero-dependency TypeScript SDK for the [SearXNG](https://docs.searxng.org/) search API.
|
|
4
|
+
|
|
5
|
+
## Install
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install searxng-sdk
|
|
9
|
+
# or
|
|
10
|
+
bun add searxng-sdk
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
## Usage
|
|
14
|
+
|
|
15
|
+
```ts
|
|
16
|
+
import { SearxngClient } from "searxng-sdk";
|
|
17
|
+
|
|
18
|
+
const client = new SearxngClient({ baseUrl: "http://localhost:8888" });
|
|
19
|
+
|
|
20
|
+
const { results } = await client
|
|
21
|
+
.search("bitcoin price")
|
|
22
|
+
.categories("news")
|
|
23
|
+
.language("fr")
|
|
24
|
+
.timeRange("day")
|
|
25
|
+
.execute();
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
## API
|
|
29
|
+
|
|
30
|
+
### `new SearxngClient(config)`
|
|
31
|
+
|
|
32
|
+
| Option | Type | Default | Description |
|
|
33
|
+
|---|---|---|---|
|
|
34
|
+
| `baseUrl` | `string` | **required** | SearXNG instance URL |
|
|
35
|
+
| `timeout` | `number` | `10000` | Request timeout in ms |
|
|
36
|
+
| `retry` | `{ maxRetries, baseDelayMs }` | `{ 3, 1000 }` | Retry on 429 with exponential backoff |
|
|
37
|
+
| `defaultLanguage` | `string` | — | Applied to all searches |
|
|
38
|
+
| `defaultCategories` | `string[]` | — | Applied to all searches |
|
|
39
|
+
| `defaultSafesearch` | `0 \| 1 \| 2` | — | Applied to all searches |
|
|
40
|
+
| `headers` | `Record<string, string>` | — | Custom headers (e.g. proxy auth) |
|
|
41
|
+
|
|
42
|
+
### `client.search(query)`
|
|
43
|
+
|
|
44
|
+
Returns a `SearchBuilder` with chainable methods:
|
|
45
|
+
|
|
46
|
+
```ts
|
|
47
|
+
.categories(...categories: string[]) // "general", "news", "images", "videos", "it", "science", ...
|
|
48
|
+
.engines(...engines: string[]) // "google", "bing", "duckduckgo", "wikipedia", ...
|
|
49
|
+
.language(lang: string) // "en", "fr", "de", ...
|
|
50
|
+
.page(n: number) // >= 1
|
|
51
|
+
.timeRange(range) // "day" | "week" | "month" | "year"
|
|
52
|
+
.safesearch(level) // 0 (off) | 1 (moderate) | 2 (strict)
|
|
53
|
+
.execute() // → Promise<SearchResponse>
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
### `SearchResponse`
|
|
57
|
+
|
|
58
|
+
```ts
|
|
59
|
+
{
|
|
60
|
+
query: string;
|
|
61
|
+
results: SearchResult[]; // { title, url, content, engine, publishedDate?, author?, thumbnail?, imgSrc?, category? }
|
|
62
|
+
suggestions: string[];
|
|
63
|
+
corrections: string[];
|
|
64
|
+
infobox?: Infobox; // { title, imgSrc?, content?, attributes, urls, relatedTopics }
|
|
65
|
+
unresponsiveEngines: [string, string][];
|
|
66
|
+
}
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
## Prerequisites
|
|
70
|
+
|
|
71
|
+
Your SearXNG instance must have JSON format enabled in `settings.yml`:
|
|
72
|
+
|
|
73
|
+
```yaml
|
|
74
|
+
search:
|
|
75
|
+
formats:
|
|
76
|
+
- html
|
|
77
|
+
- json
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
## Compatibility
|
|
81
|
+
|
|
82
|
+
Node.js 18+ / Bun / Deno
|
|
83
|
+
|
|
84
|
+
## License
|
|
85
|
+
|
|
86
|
+
MIT
|
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,297 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/index.ts
|
|
21
|
+
var index_exports = {};
|
|
22
|
+
__export(index_exports, {
|
|
23
|
+
SearchBuilder: () => SearchBuilder,
|
|
24
|
+
SearxngClient: () => SearxngClient,
|
|
25
|
+
SearxngError: () => SearxngError
|
|
26
|
+
});
|
|
27
|
+
module.exports = __toCommonJS(index_exports);
|
|
28
|
+
|
|
29
|
+
// src/errors/searxng-error.ts
|
|
30
|
+
var SearxngError = class extends Error {
|
|
31
|
+
constructor(message, status, retryAfter) {
|
|
32
|
+
super(message);
|
|
33
|
+
this.name = "SearxngError";
|
|
34
|
+
this.status = status;
|
|
35
|
+
this.retryAfter = retryAfter;
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
// src/http/fetch.ts
|
|
40
|
+
async function fetchJson(url, options) {
|
|
41
|
+
const controller = new AbortController();
|
|
42
|
+
const timeoutId = setTimeout(() => controller.abort(), options.timeout);
|
|
43
|
+
try {
|
|
44
|
+
const response = await fetch(url, {
|
|
45
|
+
signal: controller.signal,
|
|
46
|
+
headers: {
|
|
47
|
+
Accept: "application/json",
|
|
48
|
+
...options.headers
|
|
49
|
+
}
|
|
50
|
+
});
|
|
51
|
+
clearTimeout(timeoutId);
|
|
52
|
+
if (!response.ok) {
|
|
53
|
+
const retryAfter = parseRetryAfter(response.headers.get("Retry-After"));
|
|
54
|
+
if (response.status === 403) {
|
|
55
|
+
throw new SearxngError(
|
|
56
|
+
"JSON format not enabled on this instance",
|
|
57
|
+
403
|
|
58
|
+
);
|
|
59
|
+
}
|
|
60
|
+
throw new SearxngError(
|
|
61
|
+
`HTTP ${response.status} ${response.statusText}`,
|
|
62
|
+
response.status,
|
|
63
|
+
retryAfter
|
|
64
|
+
);
|
|
65
|
+
}
|
|
66
|
+
let data;
|
|
67
|
+
try {
|
|
68
|
+
data = await response.json();
|
|
69
|
+
} catch {
|
|
70
|
+
throw new SearxngError("Invalid JSON response", response.status);
|
|
71
|
+
}
|
|
72
|
+
return { data, response };
|
|
73
|
+
} catch (error) {
|
|
74
|
+
clearTimeout(timeoutId);
|
|
75
|
+
if (error instanceof SearxngError) {
|
|
76
|
+
throw error;
|
|
77
|
+
}
|
|
78
|
+
if (error instanceof Error && error.name === "AbortError") {
|
|
79
|
+
throw new SearxngError("Request timed out", 0);
|
|
80
|
+
}
|
|
81
|
+
throw new SearxngError(
|
|
82
|
+
`Network error: ${error instanceof Error ? error.message : String(error)}`,
|
|
83
|
+
0
|
|
84
|
+
);
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
function parseRetryAfter(value) {
|
|
88
|
+
if (!value) return void 0;
|
|
89
|
+
const seconds = Number(value);
|
|
90
|
+
return Number.isFinite(seconds) ? seconds : void 0;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
// src/http/retry.ts
|
|
94
|
+
async function withRetry(fn, options) {
|
|
95
|
+
let lastError;
|
|
96
|
+
for (let attempt = 0; attempt <= options.maxRetries; attempt++) {
|
|
97
|
+
try {
|
|
98
|
+
return await fn();
|
|
99
|
+
} catch (error) {
|
|
100
|
+
if (!(error instanceof SearxngError) || error.status !== 429) {
|
|
101
|
+
throw error;
|
|
102
|
+
}
|
|
103
|
+
lastError = error;
|
|
104
|
+
if (attempt === options.maxRetries) {
|
|
105
|
+
break;
|
|
106
|
+
}
|
|
107
|
+
const backoff = options.baseDelayMs * Math.pow(2, attempt);
|
|
108
|
+
const delay = error.retryAfter !== void 0 ? Math.max(error.retryAfter * 1e3, backoff) : backoff;
|
|
109
|
+
await sleep(delay);
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
throw lastError;
|
|
113
|
+
}
|
|
114
|
+
function sleep(ms) {
|
|
115
|
+
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
// src/builders/response-mapper.ts
|
|
119
|
+
function mapRawResponse(raw) {
|
|
120
|
+
return {
|
|
121
|
+
query: String(raw["query"] ?? ""),
|
|
122
|
+
results: mapResults(raw["results"]),
|
|
123
|
+
suggestions: mapStringArray(raw["suggestions"]),
|
|
124
|
+
corrections: mapStringArray(raw["corrections"]),
|
|
125
|
+
infobox: raw["infoboxes"] ? mapInfobox(raw["infoboxes"]) : void 0,
|
|
126
|
+
unresponsiveEngines: mapUnresponsiveEngines(raw["unresponsive_engines"])
|
|
127
|
+
};
|
|
128
|
+
}
|
|
129
|
+
function mapResults(raw) {
|
|
130
|
+
if (!Array.isArray(raw)) return [];
|
|
131
|
+
return raw.map((r) => ({
|
|
132
|
+
title: String(r["title"] ?? ""),
|
|
133
|
+
url: String(r["url"] ?? ""),
|
|
134
|
+
content: String(r["content"] ?? ""),
|
|
135
|
+
engine: String(r["engine"] ?? ""),
|
|
136
|
+
publishedDate: optionalString(r["publishedDate"] ?? r["published_date"]),
|
|
137
|
+
author: optionalString(r["author"]),
|
|
138
|
+
thumbnail: optionalString(r["thumbnail"] ?? r["thumbnail_src"]),
|
|
139
|
+
imgSrc: optionalString(r["img_src"]),
|
|
140
|
+
category: optionalString(r["category"])
|
|
141
|
+
}));
|
|
142
|
+
}
|
|
143
|
+
function mapInfobox(raw) {
|
|
144
|
+
if (!Array.isArray(raw) || raw.length === 0) return void 0;
|
|
145
|
+
const box = raw[0];
|
|
146
|
+
return {
|
|
147
|
+
title: String(box["infobox"] ?? ""),
|
|
148
|
+
imgSrc: optionalString(box["img_src"]),
|
|
149
|
+
content: optionalString(box["content"]),
|
|
150
|
+
attributes: mapInfoboxAttributes(box["attributes"]),
|
|
151
|
+
urls: mapInfoboxUrls(box["urls"]),
|
|
152
|
+
relatedTopics: mapInfoboxRelatedTopics(box["relatedTopics"])
|
|
153
|
+
};
|
|
154
|
+
}
|
|
155
|
+
function mapInfoboxAttributes(raw) {
|
|
156
|
+
if (!Array.isArray(raw)) return [];
|
|
157
|
+
return raw.map((a) => ({
|
|
158
|
+
label: String(a["label"] ?? ""),
|
|
159
|
+
value: String(a["value"] ?? "")
|
|
160
|
+
}));
|
|
161
|
+
}
|
|
162
|
+
function mapInfoboxUrls(raw) {
|
|
163
|
+
if (!Array.isArray(raw)) return [];
|
|
164
|
+
return raw.map((u) => ({
|
|
165
|
+
url: String(u["url"] ?? ""),
|
|
166
|
+
title: String(u["title"] ?? "")
|
|
167
|
+
}));
|
|
168
|
+
}
|
|
169
|
+
function mapInfoboxRelatedTopics(raw) {
|
|
170
|
+
if (!Array.isArray(raw)) return [];
|
|
171
|
+
return raw.map((t) => ({
|
|
172
|
+
name: String(t["name"] ?? ""),
|
|
173
|
+
suggestions: mapStringArray(
|
|
174
|
+
Array.isArray(t["suggestions"]) ? t["suggestions"].map(
|
|
175
|
+
(s) => s["suggestion"] ?? s
|
|
176
|
+
) : void 0
|
|
177
|
+
)
|
|
178
|
+
}));
|
|
179
|
+
}
|
|
180
|
+
function mapUnresponsiveEngines(raw) {
|
|
181
|
+
if (!Array.isArray(raw)) return [];
|
|
182
|
+
return raw.filter((e) => Array.isArray(e) && e.length >= 2).map((e) => [String(e[0]), String(e[1])]);
|
|
183
|
+
}
|
|
184
|
+
function mapStringArray(raw) {
|
|
185
|
+
if (!Array.isArray(raw)) return [];
|
|
186
|
+
return raw.map(String);
|
|
187
|
+
}
|
|
188
|
+
function optionalString(value) {
|
|
189
|
+
if (value === null || value === void 0) return void 0;
|
|
190
|
+
return String(value);
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
// src/builders/search.builder.ts
|
|
194
|
+
var SearchBuilder = class {
|
|
195
|
+
constructor(query, config) {
|
|
196
|
+
this.executed = false;
|
|
197
|
+
if (!query.trim()) {
|
|
198
|
+
throw new SearxngError("Search query must not be empty", 0);
|
|
199
|
+
}
|
|
200
|
+
this.config = config;
|
|
201
|
+
this.params = {
|
|
202
|
+
q: query,
|
|
203
|
+
format: "json",
|
|
204
|
+
language: config.defaultLanguage,
|
|
205
|
+
categories: config.defaultCategories?.join(","),
|
|
206
|
+
safesearch: config.defaultSafesearch
|
|
207
|
+
};
|
|
208
|
+
}
|
|
209
|
+
categories(...categories) {
|
|
210
|
+
this.params.categories = categories.join(",");
|
|
211
|
+
return this;
|
|
212
|
+
}
|
|
213
|
+
engines(...engines) {
|
|
214
|
+
this.params.engines = engines.join(",");
|
|
215
|
+
return this;
|
|
216
|
+
}
|
|
217
|
+
language(lang) {
|
|
218
|
+
this.params.language = lang;
|
|
219
|
+
return this;
|
|
220
|
+
}
|
|
221
|
+
page(pageno) {
|
|
222
|
+
if (pageno < 1) {
|
|
223
|
+
throw new SearxngError("Page number must be >= 1", 0);
|
|
224
|
+
}
|
|
225
|
+
this.params.pageno = pageno;
|
|
226
|
+
return this;
|
|
227
|
+
}
|
|
228
|
+
timeRange(range) {
|
|
229
|
+
this.params.time_range = range;
|
|
230
|
+
return this;
|
|
231
|
+
}
|
|
232
|
+
safesearch(level) {
|
|
233
|
+
this.params.safesearch = level;
|
|
234
|
+
return this;
|
|
235
|
+
}
|
|
236
|
+
async execute() {
|
|
237
|
+
if (this.executed) {
|
|
238
|
+
throw new SearxngError("Builder already executed", 0);
|
|
239
|
+
}
|
|
240
|
+
this.executed = true;
|
|
241
|
+
const url = this.buildUrl();
|
|
242
|
+
const { data } = await withRetry(
|
|
243
|
+
() => fetchJson(url, {
|
|
244
|
+
timeout: this.config.timeout,
|
|
245
|
+
headers: this.config.headers
|
|
246
|
+
}),
|
|
247
|
+
this.config.retry
|
|
248
|
+
);
|
|
249
|
+
return mapRawResponse(data);
|
|
250
|
+
}
|
|
251
|
+
buildUrl() {
|
|
252
|
+
const url = new URL("/search", this.config.baseUrl);
|
|
253
|
+
for (const [key, value] of Object.entries(this.params)) {
|
|
254
|
+
if (value !== void 0) {
|
|
255
|
+
url.searchParams.set(key, String(value));
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
return url.toString();
|
|
259
|
+
}
|
|
260
|
+
};
|
|
261
|
+
|
|
262
|
+
// src/client.ts
|
|
263
|
+
var SearxngClient = class {
|
|
264
|
+
constructor(config) {
|
|
265
|
+
if (!config.baseUrl?.trim()) {
|
|
266
|
+
throw new SearxngError("baseUrl is required", 0);
|
|
267
|
+
}
|
|
268
|
+
if (config.timeout !== void 0 && config.timeout <= 0) {
|
|
269
|
+
throw new SearxngError("timeout must be > 0", 0);
|
|
270
|
+
}
|
|
271
|
+
if (config.retry?.maxRetries !== void 0 && config.retry.maxRetries < 0) {
|
|
272
|
+
throw new SearxngError("retry.maxRetries must be >= 0", 0);
|
|
273
|
+
}
|
|
274
|
+
this.config = {
|
|
275
|
+
baseUrl: config.baseUrl.replace(/\/+$/, ""),
|
|
276
|
+
timeout: config.timeout ?? 1e4,
|
|
277
|
+
retry: {
|
|
278
|
+
maxRetries: config.retry?.maxRetries ?? 3,
|
|
279
|
+
baseDelayMs: config.retry?.baseDelayMs ?? 1e3
|
|
280
|
+
},
|
|
281
|
+
defaultLanguage: config.defaultLanguage,
|
|
282
|
+
defaultCategories: config.defaultCategories,
|
|
283
|
+
defaultSafesearch: config.defaultSafesearch,
|
|
284
|
+
headers: config.headers ?? {}
|
|
285
|
+
};
|
|
286
|
+
}
|
|
287
|
+
search(query) {
|
|
288
|
+
return new SearchBuilder(query, this.config);
|
|
289
|
+
}
|
|
290
|
+
};
|
|
291
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
292
|
+
0 && (module.exports = {
|
|
293
|
+
SearchBuilder,
|
|
294
|
+
SearxngClient,
|
|
295
|
+
SearxngError
|
|
296
|
+
});
|
|
297
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/index.ts","../src/errors/searxng-error.ts","../src/http/fetch.ts","../src/http/retry.ts","../src/builders/response-mapper.ts","../src/builders/search.builder.ts","../src/client.ts"],"sourcesContent":["export { SearxngClient } from \"./client.ts\";\nexport { SearchBuilder } from \"./builders/search.builder.ts\";\nexport { SearxngError } from \"./errors/searxng-error.ts\";\n\nexport type {\n SearxngClientConfig,\n SafeSearch,\n RetryConfig,\n} from \"./types/config.ts\";\nexport type { TimeRange } from \"./types/search-params.ts\";\nexport type {\n SearchResponse,\n SearchResult,\n Infobox,\n InfoboxAttribute,\n InfoboxUrl,\n InfoboxRelatedTopic,\n UnresponsiveEngine,\n} from \"./types/search-response.ts\";\n","export class SearxngError extends Error {\n readonly status: number;\n readonly retryAfter?: number;\n\n constructor(message: string, status: number, retryAfter?: number) {\n super(message);\n this.name = \"SearxngError\";\n this.status = status;\n this.retryAfter = retryAfter;\n }\n}\n","import { SearxngError } from \"../errors/searxng-error.ts\";\n\nexport interface FetchJsonOptions {\n timeout: number;\n headers: Record<string, string>;\n}\n\nexport async function fetchJson<T>(\n url: string,\n options: FetchJsonOptions,\n): Promise<{ data: T; response: Response }> {\n const controller = new AbortController();\n const timeoutId = setTimeout(() => controller.abort(), options.timeout);\n\n try {\n const response = await fetch(url, {\n signal: controller.signal,\n headers: {\n Accept: \"application/json\",\n ...options.headers,\n },\n });\n\n clearTimeout(timeoutId);\n\n if (!response.ok) {\n const retryAfter = parseRetryAfter(response.headers.get(\"Retry-After\"));\n\n if (response.status === 403) {\n throw new SearxngError(\n \"JSON format not enabled on this instance\",\n 403,\n );\n }\n\n throw new SearxngError(\n `HTTP ${response.status} ${response.statusText}`,\n response.status,\n retryAfter,\n );\n }\n\n let data: T;\n try {\n data = (await response.json()) as T;\n } catch {\n throw new SearxngError(\"Invalid JSON response\", response.status);\n }\n\n return { data, response };\n } catch (error) {\n clearTimeout(timeoutId);\n\n if (error instanceof SearxngError) {\n throw error;\n }\n\n if (error instanceof Error && error.name === \"AbortError\") {\n throw new SearxngError(\"Request timed out\", 0);\n }\n\n throw new SearxngError(\n `Network error: ${error instanceof Error ? error.message : String(error)}`,\n 0,\n );\n }\n}\n\nfunction parseRetryAfter(value: string | null): number | undefined {\n if (!value) return undefined;\n const seconds = Number(value);\n return Number.isFinite(seconds) ? seconds : undefined;\n}\n","import { SearxngError } from \"../errors/searxng-error.ts\";\n\nexport interface RetryOptions {\n maxRetries: number;\n baseDelayMs: number;\n}\n\nexport async function withRetry<T>(\n fn: () => Promise<T>,\n options: RetryOptions,\n): Promise<T> {\n let lastError: SearxngError | undefined;\n\n for (let attempt = 0; attempt <= options.maxRetries; attempt++) {\n try {\n return await fn();\n } catch (error) {\n if (!(error instanceof SearxngError) || error.status !== 429) {\n throw error;\n }\n\n lastError = error;\n\n if (attempt === options.maxRetries) {\n break;\n }\n\n const backoff = options.baseDelayMs * Math.pow(2, attempt);\n const delay =\n error.retryAfter !== undefined\n ? Math.max(error.retryAfter * 1000, backoff)\n : backoff;\n\n await sleep(delay);\n }\n }\n\n throw lastError!;\n}\n\nfunction sleep(ms: number): Promise<void> {\n return new Promise((resolve) => setTimeout(resolve, ms));\n}\n","import type {\n SearchResponse,\n SearchResult,\n Infobox,\n InfoboxAttribute,\n InfoboxUrl,\n InfoboxRelatedTopic,\n UnresponsiveEngine,\n} from \"../types/search-response.ts\";\n\ntype RawRecord = Record<string, unknown>;\ntype RawResponse = Record<string, unknown>;\n\nexport function mapRawResponse(raw: RawResponse): SearchResponse {\n return {\n query: String(raw[\"query\"] ?? \"\"),\n results: mapResults(raw[\"results\"]),\n suggestions: mapStringArray(raw[\"suggestions\"]),\n corrections: mapStringArray(raw[\"corrections\"]),\n infobox: raw[\"infoboxes\"] ? mapInfobox(raw[\"infoboxes\"]) : undefined,\n unresponsiveEngines: mapUnresponsiveEngines(raw[\"unresponsive_engines\"]),\n };\n}\n\nfunction mapResults(raw: unknown): SearchResult[] {\n if (!Array.isArray(raw)) return [];\n\n return raw.map((r: RawRecord) => ({\n title: String(r[\"title\"] ?? \"\"),\n url: String(r[\"url\"] ?? \"\"),\n content: String(r[\"content\"] ?? \"\"),\n engine: String(r[\"engine\"] ?? \"\"),\n publishedDate: optionalString(r[\"publishedDate\"] ?? r[\"published_date\"]),\n author: optionalString(r[\"author\"]),\n thumbnail: optionalString(r[\"thumbnail\"] ?? r[\"thumbnail_src\"]),\n imgSrc: optionalString(r[\"img_src\"]),\n category: optionalString(r[\"category\"]),\n }));\n}\n\nfunction mapInfobox(raw: unknown): Infobox | undefined {\n if (!Array.isArray(raw) || raw.length === 0) return undefined;\n\n const box = raw[0] as RawRecord;\n return {\n title: String(box[\"infobox\"] ?? \"\"),\n imgSrc: optionalString(box[\"img_src\"]),\n content: optionalString(box[\"content\"]),\n attributes: mapInfoboxAttributes(box[\"attributes\"]),\n urls: mapInfoboxUrls(box[\"urls\"]),\n relatedTopics: mapInfoboxRelatedTopics(box[\"relatedTopics\"]),\n };\n}\n\nfunction mapInfoboxAttributes(raw: unknown): InfoboxAttribute[] {\n if (!Array.isArray(raw)) return [];\n return raw.map((a: Record<string, unknown>) => ({\n label: String(a[\"label\"] ?? \"\"),\n value: String(a[\"value\"] ?? \"\"),\n }));\n}\n\nfunction mapInfoboxUrls(raw: unknown): InfoboxUrl[] {\n if (!Array.isArray(raw)) return [];\n return raw.map((u: Record<string, unknown>) => ({\n url: String(u[\"url\"] ?? \"\"),\n title: String(u[\"title\"] ?? \"\"),\n }));\n}\n\nfunction mapInfoboxRelatedTopics(raw: unknown): InfoboxRelatedTopic[] {\n if (!Array.isArray(raw)) return [];\n return raw.map((t: Record<string, unknown>) => ({\n name: String(t[\"name\"] ?? \"\"),\n suggestions: mapStringArray(\n Array.isArray(t[\"suggestions\"])\n ? t[\"suggestions\"].map(\n (s: Record<string, unknown>) => s[\"suggestion\"] ?? s,\n )\n : undefined,\n ),\n }));\n}\n\nfunction mapUnresponsiveEngines(raw: unknown): UnresponsiveEngine[] {\n if (!Array.isArray(raw)) return [];\n return raw\n .filter((e): e is [unknown, unknown] => Array.isArray(e) && e.length >= 2)\n .map((e) => [String(e[0]), String(e[1])] as UnresponsiveEngine);\n}\n\nfunction mapStringArray(raw: unknown): string[] {\n if (!Array.isArray(raw)) return [];\n return raw.map(String);\n}\n\nfunction optionalString(value: unknown): string | undefined {\n if (value === null || value === undefined) return undefined;\n return String(value);\n}\n","import type { SafeSearch, ResolvedConfig } from \"../types/config.ts\";\nimport type { SearchParams, TimeRange } from \"../types/search-params.ts\";\nimport type { SearchResponse } from \"../types/search-response.ts\";\nimport { SearxngError } from \"../errors/searxng-error.ts\";\nimport { fetchJson } from \"../http/fetch.ts\";\nimport { withRetry } from \"../http/retry.ts\";\nimport { mapRawResponse } from \"./response-mapper.ts\";\n\nexport class SearchBuilder {\n private readonly params: SearchParams;\n private readonly config: ResolvedConfig;\n private executed = false;\n\n constructor(query: string, config: ResolvedConfig) {\n if (!query.trim()) {\n throw new SearxngError(\"Search query must not be empty\", 0);\n }\n\n this.config = config;\n this.params = {\n q: query,\n format: \"json\",\n language: config.defaultLanguage,\n categories: config.defaultCategories?.join(\",\"),\n safesearch: config.defaultSafesearch,\n };\n }\n\n categories(...categories: string[]): this {\n this.params.categories = categories.join(\",\");\n return this;\n }\n\n engines(...engines: string[]): this {\n this.params.engines = engines.join(\",\");\n return this;\n }\n\n language(lang: string): this {\n this.params.language = lang;\n return this;\n }\n\n page(pageno: number): this {\n if (pageno < 1) {\n throw new SearxngError(\"Page number must be >= 1\", 0);\n }\n this.params.pageno = pageno;\n return this;\n }\n\n timeRange(range: TimeRange): this {\n this.params.time_range = range;\n return this;\n }\n\n safesearch(level: SafeSearch): this {\n this.params.safesearch = level;\n return this;\n }\n\n async execute(): Promise<SearchResponse> {\n if (this.executed) {\n throw new SearxngError(\"Builder already executed\", 0);\n }\n this.executed = true;\n\n const url = this.buildUrl();\n\n const { data } = await withRetry(\n () =>\n fetchJson<Record<string, unknown>>(url, {\n timeout: this.config.timeout,\n headers: this.config.headers,\n }),\n this.config.retry,\n );\n\n return mapRawResponse(data);\n }\n\n private buildUrl(): string {\n const url = new URL(\"/search\", this.config.baseUrl);\n\n for (const [key, value] of Object.entries(this.params)) {\n if (value !== undefined) {\n url.searchParams.set(key, String(value));\n }\n }\n\n return url.toString();\n }\n}\n","import type { SearxngClientConfig, ResolvedConfig } from \"./types/config.ts\";\nimport { SearxngError } from \"./errors/searxng-error.ts\";\nimport { SearchBuilder } from \"./builders/search.builder.ts\";\n\nexport class SearxngClient {\n private readonly config: ResolvedConfig;\n\n constructor(config: SearxngClientConfig) {\n if (!config.baseUrl?.trim()) {\n throw new SearxngError(\"baseUrl is required\", 0);\n }\n\n if (config.timeout !== undefined && config.timeout <= 0) {\n throw new SearxngError(\"timeout must be > 0\", 0);\n }\n\n if (\n config.retry?.maxRetries !== undefined &&\n config.retry.maxRetries < 0\n ) {\n throw new SearxngError(\"retry.maxRetries must be >= 0\", 0);\n }\n\n this.config = {\n baseUrl: config.baseUrl.replace(/\\/+$/, \"\"),\n timeout: config.timeout ?? 10_000,\n retry: {\n maxRetries: config.retry?.maxRetries ?? 3,\n baseDelayMs: config.retry?.baseDelayMs ?? 1_000,\n },\n defaultLanguage: config.defaultLanguage,\n defaultCategories: config.defaultCategories,\n defaultSafesearch: config.defaultSafesearch,\n headers: config.headers ?? {},\n };\n }\n\n search(query: string): SearchBuilder {\n return new SearchBuilder(query, this.config);\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAO,IAAM,eAAN,cAA2B,MAAM;AAAA,EAItC,YAAY,SAAiB,QAAgB,YAAqB;AAChE,UAAM,OAAO;AACb,SAAK,OAAO;AACZ,SAAK,SAAS;AACd,SAAK,aAAa;AAAA,EACpB;AACF;;;ACHA,eAAsB,UACpB,KACA,SAC0C;AAC1C,QAAM,aAAa,IAAI,gBAAgB;A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AACvD,YAAM,IAAI,aAAa,uBAAuB,CAAC;AAAA,IACjD;AAEA,QACE,OAAO,OAAO,eAAe,UAC7B,OAAO,MAAM,aAAa,GAC1B;AACA,YAAM,IAAI,aAAa,iCAAiC,CAAC;AAAA,IAC3D;AAEA,SAAK,SAAS;AAAA,MACZ,SAAS,OAAO,QAAQ,QAAQ,QAAQ,EAAE;AAAA,MAC1C,SAAS,OAAO,WAAW;AAAA,MAC3B,OAAO;AAAA,QACL,YAAY,OAAO,OAAO,cAAc;AAAA,QACxC,aAAa,OAAO,OAAO,eAAe;AAAA,MAC5C;AAAA,MACA,iBAAiB,OAAO;AAAA,MACxB,mBAAmB,OAAO;AAAA,MAC1B,mBAAmB,OAAO;AAAA,MAC1B,SAAS,OAAO,WAAW,CAAC;AAAA,IAC9B;AAAA,EACF;AAAA,EAEA,OAAO,OAA8B;AACnC,WAAO,IAAI,cAAc,OAAO,KAAK,MAAM;AAAA,EAC7C;AACF;","names":[]}
|
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
type SafeSearch = 0 | 1 | 2;
|
|
2
|
+
interface RetryConfig {
|
|
3
|
+
maxRetries?: number;
|
|
4
|
+
baseDelayMs?: number;
|
|
5
|
+
}
|
|
6
|
+
interface SearxngClientConfig {
|
|
7
|
+
baseUrl: string;
|
|
8
|
+
timeout?: number;
|
|
9
|
+
retry?: RetryConfig;
|
|
10
|
+
defaultLanguage?: string;
|
|
11
|
+
defaultCategories?: string[];
|
|
12
|
+
defaultSafesearch?: SafeSearch;
|
|
13
|
+
headers?: Record<string, string>;
|
|
14
|
+
}
|
|
15
|
+
interface ResolvedConfig {
|
|
16
|
+
baseUrl: string;
|
|
17
|
+
timeout: number;
|
|
18
|
+
retry: Required<RetryConfig>;
|
|
19
|
+
defaultLanguage?: string;
|
|
20
|
+
defaultCategories?: string[];
|
|
21
|
+
defaultSafesearch?: SafeSearch;
|
|
22
|
+
headers: Record<string, string>;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
type TimeRange = "day" | "week" | "month" | "year";
|
|
26
|
+
|
|
27
|
+
interface SearchResult {
|
|
28
|
+
title: string;
|
|
29
|
+
url: string;
|
|
30
|
+
content: string;
|
|
31
|
+
engine: string;
|
|
32
|
+
publishedDate?: string;
|
|
33
|
+
author?: string;
|
|
34
|
+
thumbnail?: string;
|
|
35
|
+
imgSrc?: string;
|
|
36
|
+
category?: string;
|
|
37
|
+
}
|
|
38
|
+
interface InfoboxAttribute {
|
|
39
|
+
label: string;
|
|
40
|
+
value: string;
|
|
41
|
+
}
|
|
42
|
+
interface InfoboxUrl {
|
|
43
|
+
url: string;
|
|
44
|
+
title: string;
|
|
45
|
+
}
|
|
46
|
+
interface InfoboxRelatedTopic {
|
|
47
|
+
name: string;
|
|
48
|
+
suggestions: string[];
|
|
49
|
+
}
|
|
50
|
+
interface Infobox {
|
|
51
|
+
title: string;
|
|
52
|
+
imgSrc?: string;
|
|
53
|
+
content?: string;
|
|
54
|
+
attributes: InfoboxAttribute[];
|
|
55
|
+
urls: InfoboxUrl[];
|
|
56
|
+
relatedTopics: InfoboxRelatedTopic[];
|
|
57
|
+
}
|
|
58
|
+
type UnresponsiveEngine = [engine: string, reason: string];
|
|
59
|
+
interface SearchResponse {
|
|
60
|
+
query: string;
|
|
61
|
+
results: SearchResult[];
|
|
62
|
+
suggestions: string[];
|
|
63
|
+
corrections: string[];
|
|
64
|
+
infobox?: Infobox;
|
|
65
|
+
unresponsiveEngines: UnresponsiveEngine[];
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
declare class SearchBuilder {
|
|
69
|
+
private readonly params;
|
|
70
|
+
private readonly config;
|
|
71
|
+
private executed;
|
|
72
|
+
constructor(query: string, config: ResolvedConfig);
|
|
73
|
+
categories(...categories: string[]): this;
|
|
74
|
+
engines(...engines: string[]): this;
|
|
75
|
+
language(lang: string): this;
|
|
76
|
+
page(pageno: number): this;
|
|
77
|
+
timeRange(range: TimeRange): this;
|
|
78
|
+
safesearch(level: SafeSearch): this;
|
|
79
|
+
execute(): Promise<SearchResponse>;
|
|
80
|
+
private buildUrl;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
declare class SearxngClient {
|
|
84
|
+
private readonly config;
|
|
85
|
+
constructor(config: SearxngClientConfig);
|
|
86
|
+
search(query: string): SearchBuilder;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
declare class SearxngError extends Error {
|
|
90
|
+
readonly status: number;
|
|
91
|
+
readonly retryAfter?: number;
|
|
92
|
+
constructor(message: string, status: number, retryAfter?: number);
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
export { type Infobox, type InfoboxAttribute, type InfoboxRelatedTopic, type InfoboxUrl, type RetryConfig, type SafeSearch, SearchBuilder, type SearchResponse, type SearchResult, SearxngClient, type SearxngClientConfig, SearxngError, type TimeRange, type UnresponsiveEngine };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
type SafeSearch = 0 | 1 | 2;
|
|
2
|
+
interface RetryConfig {
|
|
3
|
+
maxRetries?: number;
|
|
4
|
+
baseDelayMs?: number;
|
|
5
|
+
}
|
|
6
|
+
interface SearxngClientConfig {
|
|
7
|
+
baseUrl: string;
|
|
8
|
+
timeout?: number;
|
|
9
|
+
retry?: RetryConfig;
|
|
10
|
+
defaultLanguage?: string;
|
|
11
|
+
defaultCategories?: string[];
|
|
12
|
+
defaultSafesearch?: SafeSearch;
|
|
13
|
+
headers?: Record<string, string>;
|
|
14
|
+
}
|
|
15
|
+
interface ResolvedConfig {
|
|
16
|
+
baseUrl: string;
|
|
17
|
+
timeout: number;
|
|
18
|
+
retry: Required<RetryConfig>;
|
|
19
|
+
defaultLanguage?: string;
|
|
20
|
+
defaultCategories?: string[];
|
|
21
|
+
defaultSafesearch?: SafeSearch;
|
|
22
|
+
headers: Record<string, string>;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
type TimeRange = "day" | "week" | "month" | "year";
|
|
26
|
+
|
|
27
|
+
interface SearchResult {
|
|
28
|
+
title: string;
|
|
29
|
+
url: string;
|
|
30
|
+
content: string;
|
|
31
|
+
engine: string;
|
|
32
|
+
publishedDate?: string;
|
|
33
|
+
author?: string;
|
|
34
|
+
thumbnail?: string;
|
|
35
|
+
imgSrc?: string;
|
|
36
|
+
category?: string;
|
|
37
|
+
}
|
|
38
|
+
interface InfoboxAttribute {
|
|
39
|
+
label: string;
|
|
40
|
+
value: string;
|
|
41
|
+
}
|
|
42
|
+
interface InfoboxUrl {
|
|
43
|
+
url: string;
|
|
44
|
+
title: string;
|
|
45
|
+
}
|
|
46
|
+
interface InfoboxRelatedTopic {
|
|
47
|
+
name: string;
|
|
48
|
+
suggestions: string[];
|
|
49
|
+
}
|
|
50
|
+
interface Infobox {
|
|
51
|
+
title: string;
|
|
52
|
+
imgSrc?: string;
|
|
53
|
+
content?: string;
|
|
54
|
+
attributes: InfoboxAttribute[];
|
|
55
|
+
urls: InfoboxUrl[];
|
|
56
|
+
relatedTopics: InfoboxRelatedTopic[];
|
|
57
|
+
}
|
|
58
|
+
type UnresponsiveEngine = [engine: string, reason: string];
|
|
59
|
+
interface SearchResponse {
|
|
60
|
+
query: string;
|
|
61
|
+
results: SearchResult[];
|
|
62
|
+
suggestions: string[];
|
|
63
|
+
corrections: string[];
|
|
64
|
+
infobox?: Infobox;
|
|
65
|
+
unresponsiveEngines: UnresponsiveEngine[];
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
declare class SearchBuilder {
|
|
69
|
+
private readonly params;
|
|
70
|
+
private readonly config;
|
|
71
|
+
private executed;
|
|
72
|
+
constructor(query: string, config: ResolvedConfig);
|
|
73
|
+
categories(...categories: string[]): this;
|
|
74
|
+
engines(...engines: string[]): this;
|
|
75
|
+
language(lang: string): this;
|
|
76
|
+
page(pageno: number): this;
|
|
77
|
+
timeRange(range: TimeRange): this;
|
|
78
|
+
safesearch(level: SafeSearch): this;
|
|
79
|
+
execute(): Promise<SearchResponse>;
|
|
80
|
+
private buildUrl;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
declare class SearxngClient {
|
|
84
|
+
private readonly config;
|
|
85
|
+
constructor(config: SearxngClientConfig);
|
|
86
|
+
search(query: string): SearchBuilder;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
declare class SearxngError extends Error {
|
|
90
|
+
readonly status: number;
|
|
91
|
+
readonly retryAfter?: number;
|
|
92
|
+
constructor(message: string, status: number, retryAfter?: number);
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
export { type Infobox, type InfoboxAttribute, type InfoboxRelatedTopic, type InfoboxUrl, type RetryConfig, type SafeSearch, SearchBuilder, type SearchResponse, type SearchResult, SearxngClient, type SearxngClientConfig, SearxngError, type TimeRange, type UnresponsiveEngine };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,268 @@
|
|
|
1
|
+
// src/errors/searxng-error.ts
|
|
2
|
+
var SearxngError = class extends Error {
|
|
3
|
+
constructor(message, status, retryAfter) {
|
|
4
|
+
super(message);
|
|
5
|
+
this.name = "SearxngError";
|
|
6
|
+
this.status = status;
|
|
7
|
+
this.retryAfter = retryAfter;
|
|
8
|
+
}
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
// src/http/fetch.ts
|
|
12
|
+
async function fetchJson(url, options) {
|
|
13
|
+
const controller = new AbortController();
|
|
14
|
+
const timeoutId = setTimeout(() => controller.abort(), options.timeout);
|
|
15
|
+
try {
|
|
16
|
+
const response = await fetch(url, {
|
|
17
|
+
signal: controller.signal,
|
|
18
|
+
headers: {
|
|
19
|
+
Accept: "application/json",
|
|
20
|
+
...options.headers
|
|
21
|
+
}
|
|
22
|
+
});
|
|
23
|
+
clearTimeout(timeoutId);
|
|
24
|
+
if (!response.ok) {
|
|
25
|
+
const retryAfter = parseRetryAfter(response.headers.get("Retry-After"));
|
|
26
|
+
if (response.status === 403) {
|
|
27
|
+
throw new SearxngError(
|
|
28
|
+
"JSON format not enabled on this instance",
|
|
29
|
+
403
|
|
30
|
+
);
|
|
31
|
+
}
|
|
32
|
+
throw new SearxngError(
|
|
33
|
+
`HTTP ${response.status} ${response.statusText}`,
|
|
34
|
+
response.status,
|
|
35
|
+
retryAfter
|
|
36
|
+
);
|
|
37
|
+
}
|
|
38
|
+
let data;
|
|
39
|
+
try {
|
|
40
|
+
data = await response.json();
|
|
41
|
+
} catch {
|
|
42
|
+
throw new SearxngError("Invalid JSON response", response.status);
|
|
43
|
+
}
|
|
44
|
+
return { data, response };
|
|
45
|
+
} catch (error) {
|
|
46
|
+
clearTimeout(timeoutId);
|
|
47
|
+
if (error instanceof SearxngError) {
|
|
48
|
+
throw error;
|
|
49
|
+
}
|
|
50
|
+
if (error instanceof Error && error.name === "AbortError") {
|
|
51
|
+
throw new SearxngError("Request timed out", 0);
|
|
52
|
+
}
|
|
53
|
+
throw new SearxngError(
|
|
54
|
+
`Network error: ${error instanceof Error ? error.message : String(error)}`,
|
|
55
|
+
0
|
|
56
|
+
);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
function parseRetryAfter(value) {
|
|
60
|
+
if (!value) return void 0;
|
|
61
|
+
const seconds = Number(value);
|
|
62
|
+
return Number.isFinite(seconds) ? seconds : void 0;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
// src/http/retry.ts
|
|
66
|
+
async function withRetry(fn, options) {
|
|
67
|
+
let lastError;
|
|
68
|
+
for (let attempt = 0; attempt <= options.maxRetries; attempt++) {
|
|
69
|
+
try {
|
|
70
|
+
return await fn();
|
|
71
|
+
} catch (error) {
|
|
72
|
+
if (!(error instanceof SearxngError) || error.status !== 429) {
|
|
73
|
+
throw error;
|
|
74
|
+
}
|
|
75
|
+
lastError = error;
|
|
76
|
+
if (attempt === options.maxRetries) {
|
|
77
|
+
break;
|
|
78
|
+
}
|
|
79
|
+
const backoff = options.baseDelayMs * Math.pow(2, attempt);
|
|
80
|
+
const delay = error.retryAfter !== void 0 ? Math.max(error.retryAfter * 1e3, backoff) : backoff;
|
|
81
|
+
await sleep(delay);
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
throw lastError;
|
|
85
|
+
}
|
|
86
|
+
function sleep(ms) {
|
|
87
|
+
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
// src/builders/response-mapper.ts
|
|
91
|
+
function mapRawResponse(raw) {
|
|
92
|
+
return {
|
|
93
|
+
query: String(raw["query"] ?? ""),
|
|
94
|
+
results: mapResults(raw["results"]),
|
|
95
|
+
suggestions: mapStringArray(raw["suggestions"]),
|
|
96
|
+
corrections: mapStringArray(raw["corrections"]),
|
|
97
|
+
infobox: raw["infoboxes"] ? mapInfobox(raw["infoboxes"]) : void 0,
|
|
98
|
+
unresponsiveEngines: mapUnresponsiveEngines(raw["unresponsive_engines"])
|
|
99
|
+
};
|
|
100
|
+
}
|
|
101
|
+
function mapResults(raw) {
|
|
102
|
+
if (!Array.isArray(raw)) return [];
|
|
103
|
+
return raw.map((r) => ({
|
|
104
|
+
title: String(r["title"] ?? ""),
|
|
105
|
+
url: String(r["url"] ?? ""),
|
|
106
|
+
content: String(r["content"] ?? ""),
|
|
107
|
+
engine: String(r["engine"] ?? ""),
|
|
108
|
+
publishedDate: optionalString(r["publishedDate"] ?? r["published_date"]),
|
|
109
|
+
author: optionalString(r["author"]),
|
|
110
|
+
thumbnail: optionalString(r["thumbnail"] ?? r["thumbnail_src"]),
|
|
111
|
+
imgSrc: optionalString(r["img_src"]),
|
|
112
|
+
category: optionalString(r["category"])
|
|
113
|
+
}));
|
|
114
|
+
}
|
|
115
|
+
function mapInfobox(raw) {
|
|
116
|
+
if (!Array.isArray(raw) || raw.length === 0) return void 0;
|
|
117
|
+
const box = raw[0];
|
|
118
|
+
return {
|
|
119
|
+
title: String(box["infobox"] ?? ""),
|
|
120
|
+
imgSrc: optionalString(box["img_src"]),
|
|
121
|
+
content: optionalString(box["content"]),
|
|
122
|
+
attributes: mapInfoboxAttributes(box["attributes"]),
|
|
123
|
+
urls: mapInfoboxUrls(box["urls"]),
|
|
124
|
+
relatedTopics: mapInfoboxRelatedTopics(box["relatedTopics"])
|
|
125
|
+
};
|
|
126
|
+
}
|
|
127
|
+
function mapInfoboxAttributes(raw) {
|
|
128
|
+
if (!Array.isArray(raw)) return [];
|
|
129
|
+
return raw.map((a) => ({
|
|
130
|
+
label: String(a["label"] ?? ""),
|
|
131
|
+
value: String(a["value"] ?? "")
|
|
132
|
+
}));
|
|
133
|
+
}
|
|
134
|
+
function mapInfoboxUrls(raw) {
|
|
135
|
+
if (!Array.isArray(raw)) return [];
|
|
136
|
+
return raw.map((u) => ({
|
|
137
|
+
url: String(u["url"] ?? ""),
|
|
138
|
+
title: String(u["title"] ?? "")
|
|
139
|
+
}));
|
|
140
|
+
}
|
|
141
|
+
function mapInfoboxRelatedTopics(raw) {
|
|
142
|
+
if (!Array.isArray(raw)) return [];
|
|
143
|
+
return raw.map((t) => ({
|
|
144
|
+
name: String(t["name"] ?? ""),
|
|
145
|
+
suggestions: mapStringArray(
|
|
146
|
+
Array.isArray(t["suggestions"]) ? t["suggestions"].map(
|
|
147
|
+
(s) => s["suggestion"] ?? s
|
|
148
|
+
) : void 0
|
|
149
|
+
)
|
|
150
|
+
}));
|
|
151
|
+
}
|
|
152
|
+
function mapUnresponsiveEngines(raw) {
|
|
153
|
+
if (!Array.isArray(raw)) return [];
|
|
154
|
+
return raw.filter((e) => Array.isArray(e) && e.length >= 2).map((e) => [String(e[0]), String(e[1])]);
|
|
155
|
+
}
|
|
156
|
+
function mapStringArray(raw) {
|
|
157
|
+
if (!Array.isArray(raw)) return [];
|
|
158
|
+
return raw.map(String);
|
|
159
|
+
}
|
|
160
|
+
function optionalString(value) {
|
|
161
|
+
if (value === null || value === void 0) return void 0;
|
|
162
|
+
return String(value);
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
// src/builders/search.builder.ts
|
|
166
|
+
var SearchBuilder = class {
|
|
167
|
+
constructor(query, config) {
|
|
168
|
+
this.executed = false;
|
|
169
|
+
if (!query.trim()) {
|
|
170
|
+
throw new SearxngError("Search query must not be empty", 0);
|
|
171
|
+
}
|
|
172
|
+
this.config = config;
|
|
173
|
+
this.params = {
|
|
174
|
+
q: query,
|
|
175
|
+
format: "json",
|
|
176
|
+
language: config.defaultLanguage,
|
|
177
|
+
categories: config.defaultCategories?.join(","),
|
|
178
|
+
safesearch: config.defaultSafesearch
|
|
179
|
+
};
|
|
180
|
+
}
|
|
181
|
+
categories(...categories) {
|
|
182
|
+
this.params.categories = categories.join(",");
|
|
183
|
+
return this;
|
|
184
|
+
}
|
|
185
|
+
engines(...engines) {
|
|
186
|
+
this.params.engines = engines.join(",");
|
|
187
|
+
return this;
|
|
188
|
+
}
|
|
189
|
+
language(lang) {
|
|
190
|
+
this.params.language = lang;
|
|
191
|
+
return this;
|
|
192
|
+
}
|
|
193
|
+
page(pageno) {
|
|
194
|
+
if (pageno < 1) {
|
|
195
|
+
throw new SearxngError("Page number must be >= 1", 0);
|
|
196
|
+
}
|
|
197
|
+
this.params.pageno = pageno;
|
|
198
|
+
return this;
|
|
199
|
+
}
|
|
200
|
+
timeRange(range) {
|
|
201
|
+
this.params.time_range = range;
|
|
202
|
+
return this;
|
|
203
|
+
}
|
|
204
|
+
safesearch(level) {
|
|
205
|
+
this.params.safesearch = level;
|
|
206
|
+
return this;
|
|
207
|
+
}
|
|
208
|
+
async execute() {
|
|
209
|
+
if (this.executed) {
|
|
210
|
+
throw new SearxngError("Builder already executed", 0);
|
|
211
|
+
}
|
|
212
|
+
this.executed = true;
|
|
213
|
+
const url = this.buildUrl();
|
|
214
|
+
const { data } = await withRetry(
|
|
215
|
+
() => fetchJson(url, {
|
|
216
|
+
timeout: this.config.timeout,
|
|
217
|
+
headers: this.config.headers
|
|
218
|
+
}),
|
|
219
|
+
this.config.retry
|
|
220
|
+
);
|
|
221
|
+
return mapRawResponse(data);
|
|
222
|
+
}
|
|
223
|
+
buildUrl() {
|
|
224
|
+
const url = new URL("/search", this.config.baseUrl);
|
|
225
|
+
for (const [key, value] of Object.entries(this.params)) {
|
|
226
|
+
if (value !== void 0) {
|
|
227
|
+
url.searchParams.set(key, String(value));
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
return url.toString();
|
|
231
|
+
}
|
|
232
|
+
};
|
|
233
|
+
|
|
234
|
+
// src/client.ts
|
|
235
|
+
var SearxngClient = class {
|
|
236
|
+
constructor(config) {
|
|
237
|
+
if (!config.baseUrl?.trim()) {
|
|
238
|
+
throw new SearxngError("baseUrl is required", 0);
|
|
239
|
+
}
|
|
240
|
+
if (config.timeout !== void 0 && config.timeout <= 0) {
|
|
241
|
+
throw new SearxngError("timeout must be > 0", 0);
|
|
242
|
+
}
|
|
243
|
+
if (config.retry?.maxRetries !== void 0 && config.retry.maxRetries < 0) {
|
|
244
|
+
throw new SearxngError("retry.maxRetries must be >= 0", 0);
|
|
245
|
+
}
|
|
246
|
+
this.config = {
|
|
247
|
+
baseUrl: config.baseUrl.replace(/\/+$/, ""),
|
|
248
|
+
timeout: config.timeout ?? 1e4,
|
|
249
|
+
retry: {
|
|
250
|
+
maxRetries: config.retry?.maxRetries ?? 3,
|
|
251
|
+
baseDelayMs: config.retry?.baseDelayMs ?? 1e3
|
|
252
|
+
},
|
|
253
|
+
defaultLanguage: config.defaultLanguage,
|
|
254
|
+
defaultCategories: config.defaultCategories,
|
|
255
|
+
defaultSafesearch: config.defaultSafesearch,
|
|
256
|
+
headers: config.headers ?? {}
|
|
257
|
+
};
|
|
258
|
+
}
|
|
259
|
+
search(query) {
|
|
260
|
+
return new SearchBuilder(query, this.config);
|
|
261
|
+
}
|
|
262
|
+
};
|
|
263
|
+
export {
|
|
264
|
+
SearchBuilder,
|
|
265
|
+
SearxngClient,
|
|
266
|
+
SearxngError
|
|
267
|
+
};
|
|
268
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/errors/searxng-error.ts","../src/http/fetch.ts","../src/http/retry.ts","../src/builders/response-mapper.ts","../src/builders/search.builder.ts","../src/client.ts"],"sourcesContent":["export class SearxngError extends Error {\n readonly status: number;\n readonly retryAfter?: number;\n\n constructor(message: string, status: number, retryAfter?: number) {\n super(message);\n this.name = \"SearxngError\";\n this.status = status;\n this.retryAfter = retryAfter;\n }\n}\n","import { SearxngError } from \"../errors/searxng-error.ts\";\n\nexport interface FetchJsonOptions {\n timeout: number;\n headers: Record<string, string>;\n}\n\nexport async function fetchJson<T>(\n url: string,\n options: FetchJsonOptions,\n): Promise<{ data: T; response: Response }> {\n const controller = new AbortController();\n const timeoutId = setTimeout(() => controller.abort(), options.timeout);\n\n try {\n const response = await fetch(url, {\n signal: controller.signal,\n headers: {\n Accept: \"application/json\",\n ...options.headers,\n },\n });\n\n clearTimeout(timeoutId);\n\n if (!response.ok) {\n const retryAfter = parseRetryAfter(response.headers.get(\"Retry-After\"));\n\n if (response.status === 403) {\n throw new SearxngError(\n \"JSON format not enabled on this instance\",\n 403,\n );\n }\n\n throw new SearxngError(\n `HTTP ${response.status} ${response.statusText}`,\n response.status,\n retryAfter,\n );\n }\n\n let data: T;\n try {\n data = (await response.json()) as T;\n } catch {\n throw new SearxngError(\"Invalid JSON response\", response.status);\n }\n\n return { data, response };\n } catch (error) {\n clearTimeout(timeoutId);\n\n if (error instanceof SearxngError) {\n throw error;\n }\n\n if (error instanceof Error && error.name === \"AbortError\") {\n throw new SearxngError(\"Request timed out\", 0);\n }\n\n throw new SearxngError(\n `Network error: ${error instanceof Error ? error.message : String(error)}`,\n 0,\n );\n }\n}\n\nfunction parseRetryAfter(value: string | null): number | undefined {\n if (!value) return undefined;\n const seconds = Number(value);\n return Number.isFinite(seconds) ? seconds : undefined;\n}\n","import { SearxngError } from \"../errors/searxng-error.ts\";\n\nexport interface RetryOptions {\n maxRetries: number;\n baseDelayMs: number;\n}\n\nexport async function withRetry<T>(\n fn: () => Promise<T>,\n options: RetryOptions,\n): Promise<T> {\n let lastError: SearxngError | undefined;\n\n for (let attempt = 0; attempt <= options.maxRetries; attempt++) {\n try {\n return await fn();\n } catch (error) {\n if (!(error instanceof SearxngError) || error.status !== 429) {\n throw error;\n }\n\n lastError = error;\n\n if (attempt === options.maxRetries) {\n break;\n }\n\n const backoff = options.baseDelayMs * Math.pow(2, attempt);\n const delay =\n error.retryAfter !== undefined\n ? Math.max(error.retryAfter * 1000, backoff)\n : backoff;\n\n await sleep(delay);\n }\n }\n\n throw lastError!;\n}\n\nfunction sleep(ms: number): Promise<void> {\n return new Promise((resolve) => setTimeout(resolve, ms));\n}\n","import type {\n SearchResponse,\n SearchResult,\n Infobox,\n InfoboxAttribute,\n InfoboxUrl,\n InfoboxRelatedTopic,\n UnresponsiveEngine,\n} from \"../types/search-response.ts\";\n\ntype RawRecord = Record<string, unknown>;\ntype RawResponse = Record<string, unknown>;\n\nexport function mapRawResponse(raw: RawResponse): SearchResponse {\n return {\n query: String(raw[\"query\"] ?? \"\"),\n results: mapResults(raw[\"results\"]),\n suggestions: mapStringArray(raw[\"suggestions\"]),\n corrections: mapStringArray(raw[\"corrections\"]),\n infobox: raw[\"infoboxes\"] ? mapInfobox(raw[\"infoboxes\"]) : undefined,\n unresponsiveEngines: mapUnresponsiveEngines(raw[\"unresponsive_engines\"]),\n };\n}\n\nfunction mapResults(raw: unknown): SearchResult[] {\n if (!Array.isArray(raw)) return [];\n\n return raw.map((r: RawRecord) => ({\n title: String(r[\"title\"] ?? \"\"),\n url: String(r[\"url\"] ?? \"\"),\n content: String(r[\"content\"] ?? \"\"),\n engine: String(r[\"engine\"] ?? \"\"),\n publishedDate: optionalString(r[\"publishedDate\"] ?? r[\"published_date\"]),\n author: optionalString(r[\"author\"]),\n thumbnail: optionalString(r[\"thumbnail\"] ?? r[\"thumbnail_src\"]),\n imgSrc: optionalString(r[\"img_src\"]),\n category: optionalString(r[\"category\"]),\n }));\n}\n\nfunction mapInfobox(raw: unknown): Infobox | undefined {\n if (!Array.isArray(raw) || raw.length === 0) return undefined;\n\n const box = raw[0] as RawRecord;\n return {\n title: String(box[\"infobox\"] ?? \"\"),\n imgSrc: optionalString(box[\"img_src\"]),\n content: optionalString(box[\"content\"]),\n attributes: mapInfoboxAttributes(box[\"attributes\"]),\n urls: mapInfoboxUrls(box[\"urls\"]),\n relatedTopics: mapInfoboxRelatedTopics(box[\"relatedTopics\"]),\n };\n}\n\nfunction mapInfoboxAttributes(raw: unknown): InfoboxAttribute[] {\n if (!Array.isArray(raw)) return [];\n return raw.map((a: Record<string, unknown>) => ({\n label: String(a[\"label\"] ?? \"\"),\n value: String(a[\"value\"] ?? \"\"),\n }));\n}\n\nfunction mapInfoboxUrls(raw: unknown): InfoboxUrl[] {\n if (!Array.isArray(raw)) return [];\n return raw.map((u: Record<string, unknown>) => ({\n url: String(u[\"url\"] ?? \"\"),\n title: String(u[\"title\"] ?? \"\"),\n }));\n}\n\nfunction mapInfoboxRelatedTopics(raw: unknown): InfoboxRelatedTopic[] {\n if (!Array.isArray(raw)) return [];\n return raw.map((t: Record<string, unknown>) => ({\n name: String(t[\"name\"] ?? \"\"),\n suggestions: mapStringArray(\n Array.isArray(t[\"suggestions\"])\n ? t[\"suggestions\"].map(\n (s: Record<string, unknown>) => s[\"suggestion\"] ?? s,\n )\n : undefined,\n ),\n }));\n}\n\nfunction mapUnresponsiveEngines(raw: unknown): UnresponsiveEngine[] {\n if (!Array.isArray(raw)) return [];\n return raw\n .filter((e): e is [unknown, unknown] => Array.isArray(e) && e.length >= 2)\n .map((e) => [String(e[0]), String(e[1])] as UnresponsiveEngine);\n}\n\nfunction mapStringArray(raw: unknown): string[] {\n if (!Array.isArray(raw)) return [];\n return raw.map(String);\n}\n\nfunction optionalString(value: unknown): string | undefined {\n if (value === null || value === undefined) return undefined;\n return String(value);\n}\n","import type { SafeSearch, ResolvedConfig } from \"../types/config.ts\";\nimport type { SearchParams, TimeRange } from \"../types/search-params.ts\";\nimport type { SearchResponse } from \"../types/search-response.ts\";\nimport { SearxngError } from \"../errors/searxng-error.ts\";\nimport { fetchJson } from \"../http/fetch.ts\";\nimport { withRetry } from \"../http/retry.ts\";\nimport { mapRawResponse } from \"./response-mapper.ts\";\n\nexport class SearchBuilder {\n private readonly params: SearchParams;\n private readonly config: ResolvedConfig;\n private executed = false;\n\n constructor(query: string, config: ResolvedConfig) {\n if (!query.trim()) {\n throw new SearxngError(\"Search query must not be empty\", 0);\n }\n\n this.config = config;\n this.params = {\n q: query,\n format: \"json\",\n language: config.defaultLanguage,\n categories: config.defaultCategories?.join(\",\"),\n safesearch: config.defaultSafesearch,\n };\n }\n\n categories(...categories: string[]): this {\n this.params.categories = categories.join(\",\");\n return this;\n }\n\n engines(...engines: string[]): this {\n this.params.engines = engines.join(\",\");\n return this;\n }\n\n language(lang: string): this {\n this.params.language = lang;\n return this;\n }\n\n page(pageno: number): this {\n if (pageno < 1) {\n throw new SearxngError(\"Page number must be >= 1\", 0);\n }\n this.params.pageno = pageno;\n return this;\n }\n\n timeRange(range: TimeRange): this {\n this.params.time_range = range;\n return this;\n }\n\n safesearch(level: SafeSearch): this {\n this.params.safesearch = level;\n return this;\n }\n\n async execute(): Promise<SearchResponse> {\n if (this.executed) {\n throw new SearxngError(\"Builder already executed\", 0);\n }\n this.executed = true;\n\n const url = this.buildUrl();\n\n const { data } = await withRetry(\n () =>\n fetchJson<Record<string, unknown>>(url, {\n timeout: this.config.timeout,\n headers: this.config.headers,\n }),\n this.config.retry,\n );\n\n return mapRawResponse(data);\n }\n\n private buildUrl(): string {\n const url = new URL(\"/search\", this.config.baseUrl);\n\n for (const [key, value] of Object.entries(this.params)) {\n if (value !== undefined) {\n url.searchParams.set(key, String(value));\n }\n }\n\n return url.toString();\n }\n}\n","import type { SearxngClientConfig, ResolvedConfig } from \"./types/config.ts\";\nimport { SearxngError } from \"./errors/searxng-error.ts\";\nimport { SearchBuilder } from \"./builders/search.builder.ts\";\n\nexport class SearxngClient {\n private readonly config: ResolvedConfig;\n\n constructor(config: SearxngClientConfig) {\n if (!config.baseUrl?.trim()) {\n throw new SearxngError(\"baseUrl is required\", 0);\n }\n\n if (config.timeout !== undefined && config.timeout <= 0) {\n throw new SearxngError(\"timeout must be > 0\", 0);\n }\n\n if (\n config.retry?.maxRetries !== undefined &&\n config.retry.maxRetries < 0\n ) {\n throw new SearxngError(\"retry.maxRetries must be >= 0\", 0);\n }\n\n this.config = {\n baseUrl: config.baseUrl.replace(/\\/+$/, \"\"),\n timeout: config.timeout ?? 10_000,\n retry: {\n maxRetries: config.retry?.maxRetries ?? 3,\n baseDelayMs: config.retry?.baseDelayMs ?? 1_000,\n },\n defaultLanguage: config.defaultLanguage,\n defaultCategories: config.defaultCategories,\n defaultSafesearch: config.defaultSafesearch,\n headers: config.headers ?? {},\n };\n }\n\n search(query: string): SearchBuilder {\n return new SearchBuilder(query, this.config);\n }\n}\n"],"mappings":";AAAO,IAAM,eAAN,cAA2B,MAAM;AAAA,EAItC,YAAY,SAAiB,QAAgB,YAAqB;AAChE,UAAM,OAAO;AACb,SAAK,OAAO;AACZ,SAAK,SAAS;AACd,SAAK,aAAa;AAAA,EACpB;AACF;;;ACHA,eAAsB,UACpB,KACA,SAC0C;AAC1C,QAAM,aAAa,IAAI,gBAAgB;AACvC,QAAM,YAAY,WAAW,MAAM,WAAW,MAAM,GAAG,QAAQ,OAAO;AAEtE,MAAI;AACF,UAAM,WAAW,MAAM,MAAM,KAAK;AAAA,MAChC,QAAQ,WAAW;AAAA,MACnB,SAAS;AAAA,QACP,QAAQ;AAAA,QACR,GAAG,QAAQ;AAAA,MACb;AAAA,IACF,CAAC;AAED,iBAAa,SAAS;AAEtB,QAAI,CAAC,SAAS,IAAI;AAChB,YAAM,aAAa,gBAAgB,SAAS,QAAQ,IAAI,aAAa,CAAC;AAEtE,UAAI,SAAS,WAAW,KAAK;AAC3B,cAAM,IAAI;AAAA,UACR;AAAA,UACA;AAAA,QACF;AAAA,MACF;AAEA,YAAM,IAAI;AAAA,QACR,QAAQ,SAAS,MAAM,IAA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AW,CAAC;AAAA,IAC9B;AAAA,EACF;AAAA,EAEA,OAAO,OAA8B;AACnC,WAAO,IAAI,cAAc,OAAO,KAAK,MAAM;AAAA,EAC7C;AACF;","names":[]}
|
package/package.json
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "searxng-sdk",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Zero-dependency TypeScript SDK for the SearXNG search API with fluent builder pattern",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "./dist/index.cjs",
|
|
7
|
+
"module": "./dist/index.js",
|
|
8
|
+
"types": "./dist/index.d.ts",
|
|
9
|
+
"exports": {
|
|
10
|
+
".": {
|
|
11
|
+
"import": {
|
|
12
|
+
"types": "./dist/index.d.ts",
|
|
13
|
+
"default": "./dist/index.js"
|
|
14
|
+
},
|
|
15
|
+
"require": {
|
|
16
|
+
"types": "./dist/index.d.cts",
|
|
17
|
+
"default": "./dist/index.cjs"
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
},
|
|
21
|
+
"files": [
|
|
22
|
+
"dist"
|
|
23
|
+
],
|
|
24
|
+
"scripts": {
|
|
25
|
+
"build": "tsup src/index.ts --format esm,cjs --dts --clean --out-dir dist",
|
|
26
|
+
"dev": "tsup --watch",
|
|
27
|
+
"test": "bun test",
|
|
28
|
+
"check": "tsc --noEmit",
|
|
29
|
+
"prepublishOnly": "bun run build"
|
|
30
|
+
},
|
|
31
|
+
"keywords": [
|
|
32
|
+
"searxng",
|
|
33
|
+
"searx",
|
|
34
|
+
"search",
|
|
35
|
+
"sdk",
|
|
36
|
+
"metasearch",
|
|
37
|
+
"privacy"
|
|
38
|
+
],
|
|
39
|
+
"author": "intMeric",
|
|
40
|
+
"license": "MIT",
|
|
41
|
+
"repository": {
|
|
42
|
+
"type": "git",
|
|
43
|
+
"url": "https://github.com/intMeric/searxng-sdk"
|
|
44
|
+
},
|
|
45
|
+
"homepage": "https://github.com/intMeric/searxng-sdk#readme",
|
|
46
|
+
"bugs": {
|
|
47
|
+
"url": "https://github.com/intMeric/searxng-sdk/issues"
|
|
48
|
+
},
|
|
49
|
+
"devDependencies": {
|
|
50
|
+
"@types/bun": "^1.3.9",
|
|
51
|
+
"tsup": "^8.0.0",
|
|
52
|
+
"typescript": "^5.9.0"
|
|
53
|
+
}
|
|
54
|
+
}
|