@spotable/attio-sdk
Version:
Client for Attio REST API
80 lines (70 loc) • 2.36 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.generateNoteFetcher = generateNoteFetcher;
const fs_1 = require("../../helpers/fs");
const fileHeader_1 = require("../types/fileHeader");
const webhookEventFactory_1 = require("../webhookEventFactory");
const FILE_NAME = "note.ts";
function generateNoteFetcher(outputDir) {
const content = `${(0, fileHeader_1.generateFileHeader)(FILE_NAME)}
import { AttioClient } from "./attioClient";
import { BaseFetcher } from "./base";
import { AttioWebhookEventPopulatedListener } from "./webhook";
import { AttioNote, WebhookEventDataByType } from "../types";
export interface AttioNoteQueryParams {
limit?: number;
offset?: number;
parent_object?: string;
parent_record_id?: string;
}
export interface AttioNoteInput extends Pick<AttioNote, "parent_object" | "parent_record_id" | "title" | "created_at"> {
content: string;
format: "plaintext" | "markdown";
}
export class AttioNoteFetcher extends BaseFetcher {
constructor(client: AttioClient) {
super(client);
}
protected createBaseUrl(): string {
return "/notes";
}
async getAll(query: AttioNoteQueryParams = {}): Promise<AttioNote[]> {
return this.extractData(
this.client.doFetch(this.createBaseUrl(), {
query,
})
);
}
async create(data: AttioNoteInput): Promise<AttioNote> {
return this.extractData(
this.client.doFetch(this.createBaseUrl(), {
method: "POST",
body: data,
})
);
}
async getById(id: string): Promise<AttioNote> {
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: ["note.created", "note.updated", "note.deleted"],
idKey: "note_id",
populatedType: "AttioNote",
})}
${(0, webhookEventFactory_1.generateWebhookEventFunction)({
eventName: "note-content.updated",
customPrefix: "onContent",
idKey: "note_id",
populatedType: "AttioNote",
})}
}`;
(0, fs_1.writeGeneratedFile)(outputDir, FILE_NAME, content);
}
//# sourceMappingURL=noteFetcher.js.map