UNPKG

@spotable/attio-sdk

Version:
63 lines (56 loc) 1.98 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.generateCommentFetcher = generateCommentFetcher; const fs_1 = require("../../helpers/fs"); const fileHeader_1 = require("../types/fileHeader"); const webhookEventFactory_1 = require("../webhookEventFactory"); const FILE_NAME = "comment.ts"; function generateCommentFetcher(outputDir) { const content = `${(0, fileHeader_1.generateFileHeader)(FILE_NAME)} import { AttioClient } from "./attioClient"; import { BaseFetcher } from "./base"; import { AttioWebhookEventPopulatedListener } from "./webhook"; import { AttioComment, WebhookEventDataByType } from "../types"; export type AttioCommentInput = Pick<AttioComment, "author" | "thread_id" | "created_at"> & { content: string; format: "plaintext"; } & ( | { entry: { entry_id: string; list_id: string } } | { record: { object_id: string; record_id: string } } | {} ); export class AttioCommentFetcher extends BaseFetcher { constructor(client: AttioClient) { super(client); } protected createBaseUrl(): string { return "/comments"; } async create(data: AttioCommentInput): Promise<AttioComment> { return this.extractData( this.client.doFetch(this.createBaseUrl(), { method: "POST", body: data, }) ); } async getById(id: string): Promise<AttioComment> { return this.extractData( this.client.doFetch(\`\${this.createBaseUrl()}/\${id}\`) ); } async delete(id: string): Promise<void> { await this.client.doFetch(\`\${this.createBaseUrl()}/\${id}\`, { method: "DELETE", }); } ${(0, webhookEventFactory_1.generateWebhookEventFunctionForList)({ eventNames: ["comment.created", "comment.deleted", "comment.resolved", "comment.unresolved"], idKey: "comment_id", populatedType: "AttioComment", })} } `; (0, fs_1.writeGeneratedFile)(outputDir, FILE_NAME, content); } //# sourceMappingURL=commentFetcher.js.map