From f04b0ad92f90e2a586e8f44f4785cd80fb6e4ec7 Mon Sep 17 00:00:00 2001 From: dsinghvi Date: Thu, 21 Sep 2023 19:50:08 -0400 Subject: [PATCH] show example of how to override an sdk method --- src/wrapper/FlatfileClient.ts | 9 +++++++++ src/wrapper/RecordsClient.ts | 23 +++++++++++++++++++++++ 2 files changed, 32 insertions(+) create mode 100644 src/wrapper/RecordsClient.ts diff --git a/src/wrapper/FlatfileClient.ts b/src/wrapper/FlatfileClient.ts index 5b361d77..2c7c10a9 100644 --- a/src/wrapper/FlatfileClient.ts +++ b/src/wrapper/FlatfileClient.ts @@ -3,6 +3,7 @@ import * as environments from "../environments"; import * as core from "../core"; import urlJoin from "url-join"; import { CrossEnvConfig } from "@flatfile/cross-env-config"; +import { Records } from "./RecordsClient"; CrossEnvConfig.alias("FLATFILE_API_URL", "AGENT_INTERNAL_URL"); CrossEnvConfig.alias("FLATFILE_BEARER_TOKEN", "FLATFILE_API_KEY"); @@ -27,6 +28,14 @@ export class FlatfileClient extends FernClient { token: options.token ?? tokenSupplier }); } + + /* reference the overridden records client */ + protected _records: Records | undefined; + + public get records(): Records { + return (this._records ??= new Records(this._options)); + } + } const environmentSupplier = () => { diff --git a/src/wrapper/RecordsClient.ts b/src/wrapper/RecordsClient.ts new file mode 100644 index 00000000..0e24ee41 --- /dev/null +++ b/src/wrapper/RecordsClient.ts @@ -0,0 +1,23 @@ +import { Records as FernRecords } from "../api/resources/records/client/Client"; +import { Flatfile } from ".."; +import * as environments from "../environments"; +import * as core from "../core"; +import * as serializers from "../serialization"; +import urlJoin from "url-join"; +import * as errors from "../errors"; + +export class Records extends FernRecords { + /** + * Adds records to a workbook sheet + * @throws {@link Flatfile.BadRequestError} + * @throws {@link Flatfile.NotFoundError} + */ + public async insert( + sheetId: Flatfile.SheetId, + request: Flatfile.RecordData[], + requestOptions?: FernRecords.RequestOptions + ): Promise { + /* add your own implementation of addRecords */ + throw new Error("Unimplemnted"); + } +}