Skip to content

Commit 017df18

Browse files
committed
fix: ReferenceError when using fetch
1 parent 30ff22b commit 017df18

File tree

3 files changed

+21
-7
lines changed

3 files changed

+21
-7
lines changed

lib/index.ts

+18-4
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import fetch from 'node-fetch';
12
import OpenAI from 'openai';
23
import { RequestOptions } from 'openai/core';
34
import {
@@ -340,7 +341,9 @@ export class OpenlayerClient {
340341
}
341342
);
342343

343-
const inferencePipeline = await createInferencePipelineResponse.json();
344+
const inferencePipeline = (await createInferencePipelineResponse.json()) as
345+
| OpenlayerInferencePipeline
346+
| undefined;
344347

345348
if (!inferencePipeline?.id) {
346349
throw new Error('Error creating inference pipeline');
@@ -382,7 +385,11 @@ export class OpenlayerClient {
382385
method: 'POST',
383386
});
384387

385-
const data = await response.json();
388+
const data = (await response.json()) as {
389+
error?: string;
390+
items?: OpenlayerProject[];
391+
};
392+
386393
const { items: projects, error } = data;
387394

388395
if (!Array.isArray(projects)) {
@@ -431,7 +438,11 @@ export class OpenlayerClient {
431438
});
432439

433440
const { items: inferencePipelines, error } =
434-
await inferencePipelineResponse.json();
441+
(await inferencePipelineResponse.json()) as {
442+
error?: string;
443+
items?: OpenlayerInferencePipeline[];
444+
};
445+
435446
const inferencePipeline = Array.isArray(inferencePipelines)
436447
? inferencePipelines.find((p) => p.name === name)
437448
: undefined;
@@ -472,7 +483,10 @@ export class OpenlayerClient {
472483
});
473484

474485
const data = await response.json();
475-
const { items: projects, error } = data;
486+
const { items: projects, error } = data as {
487+
error?: string;
488+
items?: OpenlayerProject[];
489+
};
476490

477491
if (!Array.isArray(projects)) {
478492
throw new Error(

package-lock.json

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "openlayer",
3-
"version": "0.1.32",
3+
"version": "0.1.33",
44
"description": "The Openlayer TypeScript client",
55
"main": "dist/index.js",
66
"types": "dist/index.d.ts",

0 commit comments

Comments
 (0)