Skip to content

Commit

Permalink
add trigger webhook and slug support
Browse files Browse the repository at this point in the history
  • Loading branch information
jazibsawar committed Oct 28, 2024
1 parent e279862 commit f8e940a
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/cool-games-cover.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@cosmicjs/sdk': patch
---

Added typescript type for add revision method
3 changes: 2 additions & 1 deletion src/clients/bucket/objectRevisions/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import HTTP_METHODS from '../../../constants/httpMethods.constants';
import { APIConfig, BucketConfig } from '../../../types/config.types';
import { InsertObjectRevisionType } from '../../../types/objectRevision.type';
import { GenericObject } from '../../../types/generic.types';
import { requestHandler } from '../../../utils/request.handler';
import { validateWriteKeyAndReturnHeaders } from '../../../utils/writeKey.validation';
Expand All @@ -10,7 +11,7 @@ export const objectRevisionsChainMethods = (
bucketConfig: BucketConfig,
apiConfig: APIConfig
) => ({
async insertOne(objectId: string, data: GenericObject) {
async insertOne(objectId: string, data: InsertObjectRevisionType) {
const endpoint = `${apiConfig.apiUrl}/buckets/${bucketConfig.bucketSlug}/objects/${objectId}/revisions`;
headers = validateWriteKeyAndReturnHeaders(bucketConfig.writeKey);
return requestHandler(HTTP_METHODS.POST, endpoint, data, headers);
Expand Down
5 changes: 5 additions & 0 deletions src/types/generic.types.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
export type GenericObject = Record<string, any>;
export type NonEmptyObject<T extends Record<string, unknown>> =
T extends Record<string, never> ? never : T;

export type GenericOptionsType = {
slug_field?: boolean;
content_editor?: boolean;
};
15 changes: 15 additions & 0 deletions src/types/objectRevision.type.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { GenericObject, GenericOptionsType } from './generic.types';

export type InsertObjectRevisionType = {
title?: string;
slug?: string;
content?: string;
options?: GenericOptionsType;
publish_at?: number;
unpublish_at?: number;
metadata?: GenericObject;
locale?: string;
thumbnail?: string;
trigger_webhook?: boolean;
pretty?: boolean;
};

0 comments on commit f8e940a

Please sign in to comment.