Skip to content

Commit

Permalink
Merge pull request #42 from cosmicjs/jazib/add-revision-support
Browse files Browse the repository at this point in the history
add: insert object revision endpoint support
  • Loading branch information
jazibsawar authored Oct 27, 2024
2 parents b9bb438 + ad65234 commit 917b373
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .changeset/angry-ducks-exist.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@cosmicjs/sdk': minor
---

add insert objectRevision method
2 changes: 2 additions & 0 deletions src/clients/bucket/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand All @@ -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),
};
};
Expand Down
18 changes: 18 additions & 0 deletions src/clients/bucket/objectRevisions/index.ts
Original file line number Diff line number Diff line change
@@ -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);
},
});

0 comments on commit 917b373

Please sign in to comment.