benchling_typescript_sdk
Version:
Typescript SDK for Benchling API
32 lines (28 loc) • 1 kB
text/typescript
import { ClientError, UnexpectedBenchlingConfigError } from "../../utils/clientError";
import { BaseClient } from "../BaseClient";
import type { Location } from "../types";
export class Locations {
private client: BaseClient;
constructor(client: BaseClient) {
this.client = client;
}
public async getLocation(locationId: string): Promise<Location> {
return await this.client.fetchData<Location>(`locations/${locationId}`);
}
public async isLocation(locationId: string): Promise<boolean> {
let response = await this.client.fetchData<Location>(`locations/${locationId}`);
if ("barcode" in response) {
return true;
} else if ("error" in response) {
return false;
} else {
throw new ClientError({
message: `Unexpected response from Benchling for location ${locationId}`,
responseBody: JSON.stringify(response),
resStatus: -1,
resStatusText: "Unknown",
url: `/locations/${locationId}`,
});
}
}
}