@microsoft/webiq 0.0.1-alpha.2 → 0.1.1

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