Skip to content

Commit 6f0c59f

Browse files
fix(olostep): address BubbleLab review feedback
1 parent e4af3de commit 6f0c59f

3 files changed

Lines changed: 39 additions & 7 deletions

File tree

packages/bubble-core/src/bubbles/service-bubble/olostep.test.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { describe, it, expect, beforeAll, vi } from 'vitest';
1+
import { describe, it, expect, beforeAll, afterAll, afterEach, vi } from 'vitest';
22
import { OlostepBubble, type OlostepParamsInput } from './olostep.js';
33
import { CredentialType } from '@bubblelab/shared-schemas';
44
import { BubbleFactory } from '../../bubble-factory.js';
@@ -19,6 +19,14 @@ beforeAll(async () => {
1919
await factory.registerDefaults();
2020
});
2121

22+
afterEach(() => {
23+
mockFetch.mockReset();
24+
});
25+
26+
afterAll(() => {
27+
vi.unstubAllGlobals();
28+
});
29+
2230
/**
2331
* Unit tests for Olostep Service Bubble
2432
*

packages/bubble-core/src/bubbles/service-bubble/olostep.ts

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -316,13 +316,28 @@ export class OlostepBubble extends ServiceBubble<OlostepParams, OlostepResult> {
316316
return this.params.credentials?.[CredentialType.OLOSTEP_API_KEY];
317317
}
318318

319+
private async fetchWithTimeout(
320+
input: string,
321+
init: RequestInit,
322+
timeoutMs = 30000
323+
): Promise<Response> {
324+
const controller = new AbortController();
325+
const timeout = setTimeout(() => controller.abort(), timeoutMs);
326+
327+
try {
328+
return await fetch(input, { ...init, signal: controller.signal });
329+
} finally {
330+
clearTimeout(timeout);
331+
}
332+
}
333+
319334
public async testCredential(): Promise<boolean> {
320335
const apiKey = this.chooseCredential();
321336
if (!apiKey) return false;
322337

323338
try {
324339
// Simple health check with minimal scrape
325-
const response = await fetch(`${OLOSTEP_API_URL}/scrapes`, {
340+
const response = await this.fetchWithTimeout(`${OLOSTEP_API_URL}/scrapes`, {
326341
method: 'POST',
327342
headers: {
328343
Authorization: `Bearer ${apiKey}`,
@@ -529,7 +544,7 @@ export class OlostepBubble extends ServiceBubble<OlostepParams, OlostepResult> {
529544
payload: Record<string, unknown>,
530545
apiKey: string
531546
): Promise<any> {
532-
const response = await fetch(`${OLOSTEP_API_URL}${endpoint}`, {
547+
const response = await this.fetchWithTimeout(`${OLOSTEP_API_URL}${endpoint}`, {
533548
method: 'POST',
534549
headers: {
535550
Authorization: `Bearer ${apiKey}`,
@@ -548,9 +563,11 @@ export class OlostepBubble extends ServiceBubble<OlostepParams, OlostepResult> {
548563
}
549564

550565
if (!response.ok) {
551-
throw new Error(
552-
json?.error?.message || json?.message || `HTTP ${response.status}`
553-
);
566+
const errorMessage =
567+
typeof json?.error === 'string'
568+
? json.error
569+
: json?.error?.message || json?.message;
570+
throw new Error(errorMessage || `HTTP ${response.status}`);
554571
}
555572

556573
return json;

packages/bubble-core/src/index.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,14 @@ export {
192192
export type { FirecrawlParamsInput } from './bubbles/service-bubble/firecrawl.js';
193193
export { FirecrawlBubble } from './bubbles/service-bubble/firecrawl.js';
194194
export { OlostepBubble } from './bubbles/service-bubble/olostep.js';
195-
export type { OlostepParamsInput } from './bubbles/service-bubble/olostep.js';
195+
export type {
196+
OlostepParamsInput,
197+
OlostepScrapeParams,
198+
OlostepBatchParams,
199+
OlostepCrawlParams,
200+
OlostepMapParams,
201+
OlostepAnswerParams,
202+
} from './bubbles/service-bubble/olostep.js';
196203
export { InsForgeDbBubble } from './bubbles/service-bubble/insforge-db.js';
197204
export type { InsForgeDbParamsInput } from './bubbles/service-bubble/insforge-db.js';
198205
export {

0 commit comments

Comments
 (0)