@spotable/attio-sdk
Version:
Client for Attio REST API
65 lines (57 loc) • 1.99 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.generateListFetcher = generateListFetcher;
const fs_1 = require("../../helpers/fs");
const fileHeader_1 = require("../types/fileHeader");
const webhookEventFactory_1 = require("../webhookEventFactory");
const FILE_NAME = "list.ts";
function generateListFetcher(outputDir) {
const content = `${(0, fileHeader_1.generateFileHeader)(FILE_NAME)}
import { AttioClient } from "./attioClient";
import { BaseFetcher } from "./base";
import { AttioWebhookEventPopulatedListener } from "./webhook";
import { AttioList, WebhookEventDataByType } from "../types";
export type AttioListInput = Pick<AttioList, "name" | "api_slug" | "parent_object" | "workspace_access" | "workspace_member_access">;
export class AttioListFetcher extends BaseFetcher {
constructor(client: AttioClient) {
super(client);
}
protected createBaseUrl(): string {
return "/lists";
}
async getAll(): Promise<AttioList[]> {
return this.extractData(
this.client.doFetch(this.createBaseUrl())
);
}
async create(data: AttioListInput): Promise<AttioList> {
return this.extractData(
this.client.doFetch(this.createBaseUrl(), {
method: "POST",
body: data,
})
);
}
async getById(id: string): Promise<AttioList> {
return this.extractData(
this.client.doFetch(\`\${this.createBaseUrl()}/\${id}\`)
);
}
async update(id: string, data: AttioListInput): Promise<AttioList> {
return this.extractData(
this.client.doFetch(\`\${this.createBaseUrl()}/\${id}\`, {
method: "PUT",
body: data,
})
);
}
${(0, webhookEventFactory_1.generateWebhookEventFunctionForList)({
eventNames: ["list.created", "list.updated", "list.deleted"],
idKey: "list_id",
populatedType: "AttioList",
})}
}
`;
(0, fs_1.writeGeneratedFile)(outputDir, FILE_NAME, content);
}
//# sourceMappingURL=listFetcher.js.map