@microsoft/webiq 0.0.1-alpha.2 → 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/dist/index.js CHANGED
@@ -1,2 +1,825 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
1
+ 'use strict';
2
+
3
+ // src/auth.ts
4
+ var DEFAULT_SCOPE = "https://api.microsoft.ai/.default";
5
+ var ApiKeyAuth = class {
6
+ apiKey;
7
+ constructor(apiKey) {
8
+ const trimmed = typeof apiKey === "string" ? apiKey.trim() : "";
9
+ if (!trimmed) {
10
+ throw new Error("apiKey must be a non-empty string");
11
+ }
12
+ this.apiKey = trimmed;
13
+ }
14
+ async getHeaders() {
15
+ return { "x-apikey": this.apiKey };
16
+ }
17
+ };
18
+ var EntraIDAuth = class {
19
+ credential;
20
+ scope;
21
+ constructor(credential, options) {
22
+ if (credential === null || credential === void 0) {
23
+ throw new Error("credential must be a TokenCredential instance");
24
+ }
25
+ if (typeof credential.getToken !== "function") {
26
+ throw new Error("credential must implement getToken(scopes, options?)");
27
+ }
28
+ const rawScope = options?.scope;
29
+ const scope = rawScope === void 0 || rawScope === null ? DEFAULT_SCOPE : typeof rawScope === "string" ? rawScope.trim() : "";
30
+ if (!scope) {
31
+ throw new Error("scope must be a non-empty string");
32
+ }
33
+ this.credential = credential;
34
+ this.scope = scope;
35
+ }
36
+ async getHeaders() {
37
+ const tokenResponse = await this.credential.getToken(this.scope);
38
+ if (!tokenResponse || !tokenResponse.token) {
39
+ throw new Error("TokenCredential.getToken returned no token");
40
+ }
41
+ return { Authorization: `Bearer ${tokenResponse.token}` };
42
+ }
43
+ };
44
+ function createAuth(options) {
45
+ if (options.credential) {
46
+ return new EntraIDAuth(options.credential, { scope: options.scope });
47
+ }
48
+ if (options.apiKey !== void 0) {
49
+ return new ApiKeyAuth(options.apiKey);
50
+ }
51
+ throw new Error("Either apiKey or credential must be provided");
52
+ }
53
+
54
+ // src/resources/web.ts
55
+ var WebResource = class {
56
+ constructor(transport) {
57
+ this.transport = transport;
58
+ }
59
+ transport;
60
+ /**
61
+ * Search the web for relevant content.
62
+ *
63
+ * @param query - Search query string (1-1000 chars)
64
+ * @param options - Search options
65
+ * @returns WebResponse with webResults list and traceId
66
+ */
67
+ async search(query, options) {
68
+ const payload = { query };
69
+ if (options?.maxResults !== void 0) {
70
+ payload.maxResults = options.maxResults;
71
+ }
72
+ if (options?.language !== void 0) {
73
+ payload.language = options.language;
74
+ }
75
+ if (options?.region !== void 0) {
76
+ payload.region = options.region;
77
+ }
78
+ if (options?.contentFormat !== void 0) {
79
+ payload.contentFormat = options.contentFormat;
80
+ }
81
+ if (options?.location) {
82
+ payload.location = options.location;
83
+ }
84
+ if (options?.maxLength !== void 0) {
85
+ payload.maxLength = options.maxLength;
86
+ }
87
+ const result = await this.transport.request({
88
+ method: "POST",
89
+ path: "/search/web",
90
+ json: payload,
91
+ timeout: options?.timeout,
92
+ signal: options?.signal
93
+ });
94
+ return result;
95
+ }
96
+ };
97
+
98
+ // src/resources/news.ts
99
+ var NewsResource = class {
100
+ constructor(transport) {
101
+ this.transport = transport;
102
+ }
103
+ transport;
104
+ /**
105
+ * Search for news articles.
106
+ *
107
+ * @param query - Search query string (1-1000 chars)
108
+ * @param options - Search options
109
+ * @returns NewsResponse with newsResults list and traceId
110
+ */
111
+ async search(query, options) {
112
+ const payload = { query };
113
+ if (options?.maxResults !== void 0) {
114
+ payload.maxResults = options.maxResults;
115
+ }
116
+ if (options?.language !== void 0) {
117
+ payload.language = options.language;
118
+ }
119
+ if (options?.region !== void 0) {
120
+ payload.region = options.region;
121
+ }
122
+ if (options?.location !== void 0) {
123
+ payload.location = options.location;
124
+ }
125
+ if (options?.contentFormat !== void 0) {
126
+ payload.contentFormat = options.contentFormat;
127
+ }
128
+ if (options?.maxLength !== void 0) {
129
+ payload.maxLength = options.maxLength;
130
+ }
131
+ const result = await this.transport.request({
132
+ method: "POST",
133
+ path: "/search/news",
134
+ json: payload,
135
+ timeout: options?.timeout,
136
+ signal: options?.signal
137
+ });
138
+ return result;
139
+ }
140
+ };
141
+
142
+ // src/resources/videos.ts
143
+ var VideosResource = class {
144
+ constructor(transport) {
145
+ this.transport = transport;
146
+ }
147
+ transport;
148
+ /**
149
+ * Search for videos.
150
+ *
151
+ * @param query - Search query string (1-1000 chars)
152
+ * @param options - Search options
153
+ * @returns VideosResponse with videoResults, playlists, and traceId
154
+ */
155
+ async search(query, options) {
156
+ const payload = { query };
157
+ if (options?.maxResults !== void 0) {
158
+ payload.maxResults = options.maxResults;
159
+ }
160
+ if (options?.language !== void 0) {
161
+ payload.language = options.language;
162
+ }
163
+ if (options?.region !== void 0) {
164
+ payload.region = options.region;
165
+ }
166
+ if (options?.enablePlaylist !== void 0) {
167
+ payload.enablePlaylist = options.enablePlaylist;
168
+ }
169
+ if (options?.freshness !== void 0) {
170
+ payload.freshness = options.freshness;
171
+ }
172
+ if (options?.embeddable !== void 0) {
173
+ payload.embeddable = options.embeddable;
174
+ }
175
+ if (options?.resolution !== void 0) {
176
+ payload.resolution = options.resolution;
177
+ }
178
+ if (options?.safeSearch !== void 0) {
179
+ payload.safeSearch = options.safeSearch;
180
+ }
181
+ if (options?.duration !== void 0) {
182
+ payload.duration = options.duration;
183
+ }
184
+ const result = await this.transport.request({
185
+ method: "POST",
186
+ path: "/search/videos",
187
+ json: payload,
188
+ timeout: options?.timeout,
189
+ signal: options?.signal
190
+ });
191
+ return result;
192
+ }
193
+ };
194
+
195
+ // src/resources/images.ts
196
+ var ImagesResource = class {
197
+ constructor(transport) {
198
+ this.transport = transport;
199
+ }
200
+ transport;
201
+ /**
202
+ * Search for images.
203
+ *
204
+ * @param query - Search query string (1-1000 chars)
205
+ * @param options - Search options
206
+ * @returns ImagesResponse with imageResults and traceId
207
+ */
208
+ async search(query, options) {
209
+ const payload = { query };
210
+ if (options?.maxResults !== void 0) {
211
+ payload.maxResults = options.maxResults;
212
+ }
213
+ if (options?.language !== void 0) {
214
+ payload.language = options.language;
215
+ }
216
+ if (options?.region !== void 0) {
217
+ payload.region = options.region;
218
+ }
219
+ if (options?.aspectRatio !== void 0) {
220
+ payload.aspectRatio = options.aspectRatio;
221
+ }
222
+ if (options?.color !== void 0) {
223
+ payload.color = options.color;
224
+ }
225
+ if (options?.safeSearch !== void 0) {
226
+ payload.safeSearch = options.safeSearch;
227
+ }
228
+ if (options?.imageSize !== void 0) {
229
+ payload.imageSize = options.imageSize;
230
+ }
231
+ if (options?.watermarkFree !== void 0) {
232
+ payload.watermarkFree = options.watermarkFree;
233
+ }
234
+ if (options?.maxHeight !== void 0) {
235
+ payload.maxHeight = options.maxHeight;
236
+ }
237
+ if (options?.minHeight !== void 0) {
238
+ payload.minHeight = options.minHeight;
239
+ }
240
+ if (options?.maxWidth !== void 0) {
241
+ payload.maxWidth = options.maxWidth;
242
+ }
243
+ if (options?.minWidth !== void 0) {
244
+ payload.minWidth = options.minWidth;
245
+ }
246
+ const result = await this.transport.request({
247
+ method: "POST",
248
+ path: "/search/images",
249
+ json: payload,
250
+ timeout: options?.timeout,
251
+ signal: options?.signal
252
+ });
253
+ return result;
254
+ }
255
+ };
256
+
257
+ // src/resources/browse.ts
258
+ var BrowseResource = class {
259
+ constructor(transport) {
260
+ this.transport = transport;
261
+ }
262
+ transport;
263
+ /**
264
+ * Fetch and extract content from a web page.
265
+ *
266
+ * @param url - The URL of the web page to browse
267
+ * @param options - Fetch options
268
+ * @returns BrowseResponse with url, content, traceId, and optional retryAfter
269
+ */
270
+ async fetch(url, options) {
271
+ const payload = { url };
272
+ if (options?.language !== void 0) {
273
+ payload.language = options.language;
274
+ }
275
+ if (options?.region !== void 0) {
276
+ payload.region = options.region;
277
+ }
278
+ if (options?.contentFormat !== void 0) {
279
+ payload.contentFormat = options.contentFormat;
280
+ }
281
+ if (options?.maxLength !== void 0) {
282
+ payload.maxLength = options.maxLength;
283
+ }
284
+ if (options?.liveCrawl !== void 0) {
285
+ payload.liveCrawl = options.liveCrawl;
286
+ }
287
+ if (options?.includeWebLinks !== void 0) {
288
+ payload.includeWebLinks = options.includeWebLinks;
289
+ }
290
+ if (options?.renderDynamicPages !== void 0) {
291
+ payload.renderDynamicPages = options.renderDynamicPages;
292
+ }
293
+ if (options?.includeImageLinks !== void 0) {
294
+ payload.includeImageLinks = options.includeImageLinks;
295
+ }
296
+ const result = await this.transport.request({
297
+ method: "POST",
298
+ path: "/browse",
299
+ json: payload,
300
+ timeout: options?.timeout,
301
+ signal: options?.signal
302
+ });
303
+ return result;
304
+ }
305
+ };
306
+
307
+ // src/resources/classic.ts
308
+ var ClassicResource = class {
309
+ constructor(transport) {
310
+ this.transport = transport;
311
+ }
312
+ transport;
313
+ /**
314
+ * Perform a classic search returning grouped results across multiple answer types.
315
+ *
316
+ * @param query - Search query string (1-1000 chars)
317
+ * @param options - Search options
318
+ * @returns SearchClassicResponse with querySignals, traceId, and additional answer types
319
+ */
320
+ async search(query, options) {
321
+ const payload = { query };
322
+ if (options?.language !== void 0) {
323
+ payload.language = options.language;
324
+ }
325
+ if (options?.region !== void 0) {
326
+ payload.region = options.region;
327
+ }
328
+ if (options?.maxAnswerTypes !== void 0) {
329
+ payload.maxAnswerTypes = options.maxAnswerTypes;
330
+ }
331
+ if (options?.location) {
332
+ payload.location = options.location;
333
+ }
334
+ if (options?.maxResultsWeb !== void 0) {
335
+ payload.maxResultsWeb = options.maxResultsWeb;
336
+ }
337
+ if (options?.maxLength !== void 0) {
338
+ payload.maxLength = options.maxLength;
339
+ }
340
+ if (options?.contentFormat !== void 0) {
341
+ payload.contentFormat = options.contentFormat;
342
+ }
343
+ if (options?.freshness !== void 0) {
344
+ payload.freshness = options.freshness;
345
+ }
346
+ if (options?.responseFilter !== void 0) {
347
+ payload.responseFilter = options.responseFilter;
348
+ }
349
+ if (options?.safeSearch !== void 0) {
350
+ payload.safeSearch = options.safeSearch;
351
+ }
352
+ const result = await this.transport.request({
353
+ method: "POST",
354
+ path: "/search/classic",
355
+ json: payload,
356
+ timeout: options?.timeout,
357
+ signal: options?.signal
358
+ });
359
+ return result;
360
+ }
361
+ };
362
+
363
+ // src/errors.ts
364
+ var WebIQError = class _WebIQError extends Error {
365
+ constructor(message, options) {
366
+ super(message, options);
367
+ this.name = "WebIQError";
368
+ Object.setPrototypeOf(this, _WebIQError.prototype);
369
+ }
370
+ };
371
+ var APIConnectionError = class _APIConnectionError extends WebIQError {
372
+ constructor(message, options) {
373
+ super(message, options);
374
+ this.name = "APIConnectionError";
375
+ Object.setPrototypeOf(this, _APIConnectionError.prototype);
376
+ }
377
+ };
378
+ var APIStatusError = class _APIStatusError extends WebIQError {
379
+ statusCode;
380
+ body;
381
+ requestId;
382
+ traceId;
383
+ constructor(statusCode, message, options) {
384
+ super(message);
385
+ this.name = "APIStatusError";
386
+ this.statusCode = statusCode;
387
+ this.body = options?.body;
388
+ this.requestId = options?.requestId;
389
+ this.traceId = options?.traceId;
390
+ Object.setPrototypeOf(this, _APIStatusError.prototype);
391
+ }
392
+ };
393
+ var RateLimitError = class _RateLimitError extends APIStatusError {
394
+ constructor(statusCode, message, options) {
395
+ super(statusCode, message, options);
396
+ this.name = "RateLimitError";
397
+ Object.setPrototypeOf(this, _RateLimitError.prototype);
398
+ }
399
+ /** The retry-after value from the API response body, if available. */
400
+ get retryAfter() {
401
+ if (this.body && typeof this.body === "object" && "retryAfter" in this.body) {
402
+ return String(this.body.retryAfter);
403
+ }
404
+ return void 0;
405
+ }
406
+ };
407
+ var AuthenticationError = class _AuthenticationError extends APIStatusError {
408
+ constructor(statusCode, message, options) {
409
+ super(statusCode, message, options);
410
+ this.name = "AuthenticationError";
411
+ Object.setPrototypeOf(this, _AuthenticationError.prototype);
412
+ }
413
+ };
414
+ var PermissionDeniedError = class _PermissionDeniedError extends APIStatusError {
415
+ constructor(statusCode, message, options) {
416
+ super(statusCode, message, options);
417
+ this.name = "PermissionDeniedError";
418
+ Object.setPrototypeOf(this, _PermissionDeniedError.prototype);
419
+ }
420
+ };
421
+
422
+ // src/retry.ts
423
+ function parseRetryAfter(retryAfter) {
424
+ if (typeof retryAfter !== "string") {
425
+ return void 0;
426
+ }
427
+ const trimmed = retryAfter.trim();
428
+ if (trimmed.length === 0) {
429
+ return void 0;
430
+ }
431
+ if (trimmed.endsWith("s") && !trimmed.endsWith("ms")) {
432
+ const value = parseFloat(trimmed.slice(0, -1));
433
+ if (!isNaN(value) && isFinite(value) && value >= 0) {
434
+ return value;
435
+ }
436
+ }
437
+ if (/^\d{4}-\d{2}-\d{2}T/.test(trimmed)) {
438
+ const ms = Date.parse(trimmed);
439
+ if (!isNaN(ms)) {
440
+ return Math.max(0, (ms - Date.now()) / 1e3);
441
+ }
442
+ }
443
+ return void 0;
444
+ }
445
+ var RetryPolicy = class {
446
+ maxRetries;
447
+ baseDelaySeconds;
448
+ maxDelaySeconds;
449
+ retryOnStatus;
450
+ constructor(options) {
451
+ this.maxRetries = options?.maxRetries ?? 2;
452
+ this.baseDelaySeconds = options?.baseDelaySeconds ?? 0.25;
453
+ this.maxDelaySeconds = options?.maxDelaySeconds ?? 4;
454
+ this.retryOnStatus = new Set(options?.retryOnStatus ?? [408, 500, 502, 503, 504]);
455
+ }
456
+ /**
457
+ * Compute the delay before the next retry attempt.
458
+ *
459
+ * @param attempt - Current attempt number (1-based)
460
+ * @param retryAfter - Server-specified retry-after value (if any)
461
+ * @returns Delay in seconds before next attempt
462
+ */
463
+ computeDelay(attempt, retryAfter) {
464
+ if (retryAfter !== void 0) {
465
+ return Math.min(retryAfter, this.maxDelaySeconds);
466
+ }
467
+ const delay = Math.random() * this.baseDelaySeconds * Math.pow(2, attempt - 1);
468
+ return Math.min(delay, this.maxDelaySeconds);
469
+ }
470
+ /**
471
+ * Check if a status code should trigger a retry.
472
+ */
473
+ shouldRetry(statusCode) {
474
+ return this.retryOnStatus.has(statusCode);
475
+ }
476
+ };
477
+ function sleep(seconds) {
478
+ return new Promise((resolve) => setTimeout(resolve, seconds * 1e3));
479
+ }
480
+
481
+ // src/telemetry.ts
482
+ function safeCall(hook, event) {
483
+ if (hook) {
484
+ try {
485
+ hook(event);
486
+ } catch {
487
+ }
488
+ }
489
+ }
490
+ function createTelemetryEvent(method, path, transport, attempt, options) {
491
+ return {
492
+ method,
493
+ path,
494
+ transport,
495
+ attempt,
496
+ ...options
497
+ };
498
+ }
499
+
500
+ // src/transports/base.ts
501
+ var DEFAULT_TIMEOUT = 1e4;
502
+
503
+ // src/transports/http.ts
504
+ function extractMetadata(body, headers) {
505
+ let bodyTraceId;
506
+ let bodyRetryAfter;
507
+ let bodyRequestId;
508
+ if (body && typeof body === "object") {
509
+ const obj = body;
510
+ bodyTraceId = typeof obj.traceId === "string" ? obj.traceId : void 0;
511
+ bodyRetryAfter = typeof obj.retryAfter === "string" ? obj.retryAfter : void 0;
512
+ bodyRequestId = typeof obj.requestId === "string" ? obj.requestId : void 0;
513
+ }
514
+ const headerTraceId = headers?.get("x-traceid") ?? void 0;
515
+ return {
516
+ traceId: headerTraceId || bodyTraceId,
517
+ retryAfter: bodyRetryAfter,
518
+ requestId: bodyRequestId
519
+ };
520
+ }
521
+ var HttpTransport = class {
522
+ baseUrl;
523
+ auth;
524
+ telemetry;
525
+ retry;
526
+ timeout;
527
+ fetchFn;
528
+ activeControllers = /* @__PURE__ */ new Set();
529
+ closed = false;
530
+ constructor(options) {
531
+ this.baseUrl = options.baseUrl.replace(/\/$/, "");
532
+ this.auth = options.auth;
533
+ this.telemetry = options.telemetryHook;
534
+ this.retry = options.retry ?? new RetryPolicy();
535
+ this.timeout = options.timeout ?? DEFAULT_TIMEOUT;
536
+ this.fetchFn = options.fetchFn ?? globalThis.fetch.bind(globalThis);
537
+ }
538
+ async request(options) {
539
+ const { method, path, json, signal: callerSignal } = options;
540
+ const effectiveTimeout = options.timeout ?? this.timeout;
541
+ let attempt = 0;
542
+ while (true) {
543
+ if (this.closed) {
544
+ throw new APIConnectionError("Transport is closed");
545
+ }
546
+ if (callerSignal?.aborted) {
547
+ throw callerSignal.reason ?? new DOMException("Request aborted", "AbortError");
548
+ }
549
+ attempt++;
550
+ const start = Date.now();
551
+ try {
552
+ const authHeaders = await this.auth.getHeaders();
553
+ const abortController = new AbortController();
554
+ this.activeControllers.add(abortController);
555
+ const timeoutId = setTimeout(() => abortController.abort(), effectiveTimeout);
556
+ const fetchSignal = callerSignal ? AbortSignal.any([callerSignal, abortController.signal]) : abortController.signal;
557
+ let response;
558
+ try {
559
+ response = await this.fetchFn(`${this.baseUrl}${path}`, {
560
+ method,
561
+ headers: {
562
+ "Content-Type": "application/json",
563
+ ...authHeaders
564
+ },
565
+ body: json ? JSON.stringify(json) : void 0,
566
+ signal: fetchSignal
567
+ });
568
+ clearTimeout(timeoutId);
569
+ this.activeControllers.delete(abortController);
570
+ } catch (fetchError) {
571
+ clearTimeout(timeoutId);
572
+ this.activeControllers.delete(abortController);
573
+ throw fetchError;
574
+ }
575
+ let body = null;
576
+ const responseText = await response.text();
577
+ if (responseText) {
578
+ try {
579
+ body = JSON.parse(responseText);
580
+ } catch {
581
+ body = { rawContent: responseText.slice(0, 500) };
582
+ }
583
+ }
584
+ const { traceId, retryAfter, requestId } = extractMetadata(body, response.headers);
585
+ const elapsed = Date.now() - start;
586
+ safeCall(
587
+ this.telemetry,
588
+ createTelemetryEvent(method, path, "http", attempt, {
589
+ statusCode: response.status,
590
+ requestId,
591
+ traceId,
592
+ retryAfter,
593
+ elapsedMs: elapsed,
594
+ errorBody: response.status >= 400 ? body : void 0
595
+ })
596
+ );
597
+ if (response.status === 401) {
598
+ throw new AuthenticationError(response.status, "Unauthorized", {
599
+ body,
600
+ requestId,
601
+ traceId
602
+ });
603
+ }
604
+ if (response.status === 403) {
605
+ const message = body && typeof body === "object" && "userMessage" in body ? String(body.userMessage) : "Forbidden";
606
+ throw new PermissionDeniedError(response.status, message, {
607
+ body,
608
+ requestId,
609
+ traceId
610
+ });
611
+ }
612
+ if (response.status === 429 || response.status === 430) {
613
+ const defaultMessage = response.status === 430 ? "Concurrent request limit exceeded" : "Rate limit exceeded";
614
+ const message = body && typeof body === "object" && "userMessage" in body ? String(body.userMessage) : defaultMessage;
615
+ throw new RateLimitError(response.status, message, { body, requestId, traceId });
616
+ }
617
+ if (this.retry.shouldRetry(response.status) && attempt <= this.retry.maxRetries) {
618
+ const delay = this.retry.computeDelay(attempt, parseRetryAfter(retryAfter));
619
+ await sleep(delay);
620
+ continue;
621
+ }
622
+ if (response.status >= 400) {
623
+ const message = body && typeof body === "object" && "userMessage" in body ? String(body.userMessage) : `HTTP ${response.status}`;
624
+ throw new APIStatusError(response.status, message, { body, requestId, traceId });
625
+ }
626
+ return body;
627
+ } catch (error) {
628
+ if (error instanceof APIStatusError || error instanceof AuthenticationError) {
629
+ throw error;
630
+ }
631
+ const elapsed = Date.now() - start;
632
+ safeCall(
633
+ this.telemetry,
634
+ createTelemetryEvent(method, path, "http", attempt, {
635
+ elapsedMs: elapsed,
636
+ error: error instanceof Error ? error : new Error(String(error))
637
+ })
638
+ );
639
+ if (this.closed) {
640
+ throw new APIConnectionError("Transport is closed");
641
+ }
642
+ if (callerSignal?.aborted) {
643
+ throw callerSignal.reason ?? new DOMException("Request aborted", "AbortError");
644
+ }
645
+ if (error instanceof Error && error.name === "AbortError") {
646
+ throw new APIConnectionError(`Request timed out after ${effectiveTimeout}ms`, {
647
+ cause: error
648
+ });
649
+ }
650
+ if (attempt <= this.retry.maxRetries) {
651
+ await sleep(this.retry.computeDelay(attempt));
652
+ continue;
653
+ }
654
+ throw new APIConnectionError(
655
+ error instanceof Error ? error.message : String(error),
656
+ error instanceof Error ? { cause: error } : void 0
657
+ );
658
+ }
659
+ }
660
+ }
661
+ async close() {
662
+ this.closed = true;
663
+ Array.from(this.activeControllers).forEach((controller) => controller.abort());
664
+ this.activeControllers.clear();
665
+ }
666
+ };
667
+
668
+ // src/client.ts
669
+ var WebIQClient = class {
670
+ /** Web search resource */
671
+ web;
672
+ /** News search resource */
673
+ news;
674
+ /** Videos search resource */
675
+ videos;
676
+ /** Images search resource */
677
+ images;
678
+ /** Browse resource */
679
+ browse;
680
+ /** Classic search resource */
681
+ classic;
682
+ _transport;
683
+ _auth;
684
+ constructor(options) {
685
+ if (options.auth) {
686
+ this._auth = options.auth;
687
+ } else if (options.credential) {
688
+ this._auth = createAuth({ credential: options.credential, scope: options.scope });
689
+ } else if (options.apiKey !== void 0) {
690
+ this._auth = createAuth({ apiKey: options.apiKey });
691
+ } else {
692
+ throw new Error("One of apiKey, credential, or auth must be provided");
693
+ }
694
+ const retry = options.retry instanceof RetryPolicy ? options.retry : options.retry ? new RetryPolicy(options.retry) : new RetryPolicy();
695
+ this._transport = new HttpTransport({
696
+ baseUrl: options.baseUrl ?? "https://api.microsoft.ai/v3",
697
+ auth: this._auth,
698
+ telemetryHook: options.telemetryHook,
699
+ retry,
700
+ timeout: options.timeout ?? DEFAULT_TIMEOUT,
701
+ fetchFn: options.fetchFn
702
+ });
703
+ this.web = new WebResource(this._transport);
704
+ this.news = new NewsResource(this._transport);
705
+ this.videos = new VideosResource(this._transport);
706
+ this.images = new ImagesResource(this._transport);
707
+ this.browse = new BrowseResource(this._transport);
708
+ this.classic = new ClassicResource(this._transport);
709
+ }
710
+ /**
711
+ * Close the client and release resources.
712
+ */
713
+ async close() {
714
+ await this._transport.close();
715
+ }
716
+ };
717
+ function createClient(options) {
718
+ return new WebIQClient(options);
719
+ }
720
+
721
+ // src/generated-otc/models/BrowseContentFormat.ts
722
+ var BrowseContentFormat = /* @__PURE__ */ ((BrowseContentFormat2) => {
723
+ BrowseContentFormat2["TEXT"] = "text";
724
+ BrowseContentFormat2["HTML"] = "html";
725
+ BrowseContentFormat2["MARKDOWN"] = "markdown";
726
+ return BrowseContentFormat2;
727
+ })(BrowseContentFormat || {});
728
+
729
+ // src/generated-otc/models/ContentFormat.ts
730
+ var ContentFormat = /* @__PURE__ */ ((ContentFormat2) => {
731
+ ContentFormat2["PASSAGE"] = "passage";
732
+ ContentFormat2["TEXT"] = "text";
733
+ ContentFormat2["HTML"] = "html";
734
+ ContentFormat2["MARKDOWN"] = "markdown";
735
+ return ContentFormat2;
736
+ })(ContentFormat || {});
737
+
738
+ // src/generated-otc/models/SafeSearch.ts
739
+ var SafeSearch = /* @__PURE__ */ ((SafeSearch2) => {
740
+ SafeSearch2["OFF"] = "off";
741
+ SafeSearch2["STRICT"] = "strict";
742
+ return SafeSearch2;
743
+ })(SafeSearch || {});
744
+
745
+ // src/generated-otc/models/SafeSearchMode.ts
746
+ var SafeSearchMode = /* @__PURE__ */ ((SafeSearchMode2) => {
747
+ SafeSearchMode2["OFF"] = "off";
748
+ SafeSearchMode2["MODERATE"] = "moderate";
749
+ SafeSearchMode2["STRICT"] = "strict";
750
+ return SafeSearchMode2;
751
+ })(SafeSearchMode || {});
752
+
753
+ // src/generated-otc/models/VideoDuration.ts
754
+ var VideoDuration = /* @__PURE__ */ ((VideoDuration2) => {
755
+ VideoDuration2["SHORT"] = "short";
756
+ VideoDuration2["MEDIUM"] = "medium";
757
+ VideoDuration2["LONG"] = "long";
758
+ return VideoDuration2;
759
+ })(VideoDuration || {});
760
+
761
+ // src/generated-otc/models/VideoResolution.ts
762
+ var VideoResolution = /* @__PURE__ */ ((VideoResolution2) => {
763
+ VideoResolution2["_360P"] = "360p";
764
+ VideoResolution2["_480P"] = "480p";
765
+ VideoResolution2["_720P"] = "720p";
766
+ VideoResolution2["_1080P"] = "1080p";
767
+ return VideoResolution2;
768
+ })(VideoResolution || {});
769
+
770
+ // src/generated-otc/models/ImageAspectRatio.ts
771
+ var ImageAspectRatio = /* @__PURE__ */ ((ImageAspectRatio2) => {
772
+ ImageAspectRatio2["SQUARE"] = "square";
773
+ ImageAspectRatio2["WIDE"] = "wide";
774
+ ImageAspectRatio2["TALL"] = "tall";
775
+ return ImageAspectRatio2;
776
+ })(ImageAspectRatio || {});
777
+
778
+ // src/generated-otc/models/ImageColor.ts
779
+ var ImageColor = /* @__PURE__ */ ((ImageColor2) => {
780
+ ImageColor2["COLOR_ONLY"] = "colorOnly";
781
+ ImageColor2["MONOCHROME"] = "monochrome";
782
+ return ImageColor2;
783
+ })(ImageColor || {});
784
+
785
+ // src/generated-otc/models/ImageSize.ts
786
+ var ImageSize = /* @__PURE__ */ ((ImageSize2) => {
787
+ ImageSize2["SMALL"] = "small";
788
+ ImageSize2["MEDIUM"] = "medium";
789
+ ImageSize2["LARGE"] = "large";
790
+ ImageSize2["EXTRA_LARGE"] = "extraLarge";
791
+ return ImageSize2;
792
+ })(ImageSize || {});
793
+
794
+ exports.APIConnectionError = APIConnectionError;
795
+ exports.APIStatusError = APIStatusError;
796
+ exports.ApiKeyAuth = ApiKeyAuth;
797
+ exports.AuthenticationError = AuthenticationError;
798
+ exports.BrowseContentFormat = BrowseContentFormat;
799
+ exports.BrowseResource = BrowseResource;
800
+ exports.ClassicResource = ClassicResource;
801
+ exports.ContentFormat = ContentFormat;
802
+ exports.DEFAULT_SCOPE = DEFAULT_SCOPE;
803
+ exports.DEFAULT_TIMEOUT = DEFAULT_TIMEOUT;
804
+ exports.EntraIDAuth = EntraIDAuth;
805
+ exports.HttpTransport = HttpTransport;
806
+ exports.ImageAspectRatio = ImageAspectRatio;
807
+ exports.ImageColor = ImageColor;
808
+ exports.ImageSize = ImageSize;
809
+ exports.ImagesResource = ImagesResource;
810
+ exports.NewsResource = NewsResource;
811
+ exports.PermissionDeniedError = PermissionDeniedError;
812
+ exports.RateLimitError = RateLimitError;
813
+ exports.RetryPolicy = RetryPolicy;
814
+ exports.SafeSearch = SafeSearch;
815
+ exports.SafeSearchMode = SafeSearchMode;
816
+ exports.VideoDuration = VideoDuration;
817
+ exports.VideoResolution = VideoResolution;
818
+ exports.VideosResource = VideosResource;
819
+ exports.WebIQClient = WebIQClient;
820
+ exports.WebIQError = WebIQError;
821
+ exports.WebResource = WebResource;
822
+ exports.createAuth = createAuth;
823
+ exports.createClient = createClient;
824
+ exports.createTelemetryEvent = createTelemetryEvent;
825
+ exports.safeCall = safeCall;