@spotable/attio-sdk
Version:
Client for Attio REST API
63 lines (56 loc) • 1.65 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.generateObjectFetcher = generateObjectFetcher;
const fs_1 = require("../../helpers/fs");
const fileHeader_1 = require("../types/fileHeader");
const FILE_NAME = "object.ts";
function generateObjectFetcher(outputDir) {
const content = `${(0, fileHeader_1.generateFileHeader)(FILE_NAME)}
import { AttioClient } from "./attioClient";
import { BaseFetcher } from "./base";
import { AttioObject } from "../types";
export interface AttioObjectInput {
data: {
api_slug: string;
singular_noun: string;
plural_noun: string;
};
}
export class AttioObjectFetcher extends BaseFetcher {
constructor(client: AttioClient) {
super(client);
}
protected createBaseUrl(): string {
return "/objects";
}
async getAll(): Promise<AttioObject[]> {
return this.extractData(
this.client.doFetch(this.createBaseUrl())
);
}
async getById(id: string): Promise<AttioObject> {
return this.extractData(
this.client.doFetch(\`$\{this.createBaseUrl()}/$\{id}\`)
);
}
async create(data: AttioObjectInput): Promise<AttioObject> {
return this.extractData(
this.client.doFetch(this.createBaseUrl(), {
method: "POST",
body: data,
})
);
}
async update(id: string, data: AttioObjectInput): Promise<AttioObject> {
return this.extractData(
this.client.doFetch(\`\${this.createBaseUrl()}/\${id}\`, {
method: "PUT",
body: data,
})
);
}
}
`;
(0, fs_1.writeGeneratedFile)(outputDir, FILE_NAME, content);
}
//# sourceMappingURL=objectFetcher.js.map