From ad65234a8c5ca86de8f9238737e4367a4c3a9d97 Mon Sep 17 00:00:00 2001 From: jazibsawar Date: Sun, 27 Oct 2024 21:17:36 +0200 Subject: [PATCH] add: insert object revision endpoint support --- .changeset/angry-ducks-exist.md | 5 +++++ src/clients/bucket/index.ts | 2 ++ src/clients/bucket/objectRevisions/index.ts | 18 ++++++++++++++++++ 3 files changed, 25 insertions(+) create mode 100644 .changeset/angry-ducks-exist.md create mode 100644 src/clients/bucket/objectRevisions/index.ts diff --git a/.changeset/angry-ducks-exist.md b/.changeset/angry-ducks-exist.md new file mode 100644 index 0000000..c09b4a6 --- /dev/null +++ b/.changeset/angry-ducks-exist.md @@ -0,0 +1,5 @@ +--- +'@cosmicjs/sdk': minor +--- + +add insert objectRevision method diff --git a/src/clients/bucket/index.ts b/src/clients/bucket/index.ts index e3ce240..b0bbcd4 100644 --- a/src/clients/bucket/index.ts +++ b/src/clients/bucket/index.ts @@ -3,6 +3,7 @@ import { validateAndExtractAPIConfig } from '../../utils/config.validation'; import { mediaChainMethods } from './media'; import { objectsChainMethods } from './objects'; import { objectTypesChainMethods } from './objectTypes'; +import { objectRevisionsChainMethods } from './objectRevisions'; export const createBucketClient = (config: BucketConfig) => { const bucketConfig: BucketConfig = { @@ -15,6 +16,7 @@ export const createBucketClient = (config: BucketConfig) => { return { objects: objectsChainMethods(bucketConfig, apiConfig), objectTypes: objectTypesChainMethods(bucketConfig, apiConfig), + objectRevisions: objectRevisionsChainMethods(bucketConfig, apiConfig), media: mediaChainMethods(bucketConfig, apiConfig), }; }; diff --git a/src/clients/bucket/objectRevisions/index.ts b/src/clients/bucket/objectRevisions/index.ts new file mode 100644 index 0000000..94dcbc2 --- /dev/null +++ b/src/clients/bucket/objectRevisions/index.ts @@ -0,0 +1,18 @@ +import HTTP_METHODS from '../../../constants/httpMethods.constants'; +import { APIConfig, BucketConfig } from '../../../types/config.types'; +import { GenericObject } from '../../../types/generic.types'; +import { requestHandler } from '../../../utils/request.handler'; +import { validateWriteKeyAndReturnHeaders } from '../../../utils/writeKey.validation'; + +let headers: GenericObject; + +export const objectRevisionsChainMethods = ( + bucketConfig: BucketConfig, + apiConfig: APIConfig +) => ({ + async insertOne(objectId: string, data: GenericObject) { + const endpoint = `${apiConfig.apiUrl}/buckets/${bucketConfig.bucketSlug}/objects/${objectId}/revisions`; + headers = validateWriteKeyAndReturnHeaders(bucketConfig.writeKey); + return requestHandler(HTTP_METHODS.POST, endpoint, data, headers); + }, +});