Skip to content

Commit

Permalink
adjust types to better fit webhooks
Browse files Browse the repository at this point in the history
  • Loading branch information
IvanKiral committed Mar 26, 2024
1 parent 76c3620 commit 168adba
Showing 1 changed file with 68 additions and 12 deletions.
80 changes: 68 additions & 12 deletions lib/models/webhook-models.ts
Original file line number Diff line number Diff line change
@@ -1,30 +1,86 @@
export type WebhookNotification = {
data: WebhookData;
message: WebhookMessage;
type WebhookPublishedDeliverySlot = "published";
type WebhookPreviewDeliverySlot = "preview";

export type WebhookDeliverySlot = WebhookPublishedDeliverySlot | WebhookPreviewDeliverySlot;

type CommonEvents = "created" | "deleted";
export type AssetEvents = CommonEvents | "metadata_changed";
export type ContentItemPreviewEvents = CommonEvents | "workflow_step_changed" | "metadata_changed";
export type ContentItemPublishedEvents = "published" | "unpublished" | "metadata_changed";
export type ContentTypeEvents = CommonEvents | "changed";
export type LanguageEvents = CommonEvents | "changed";
export type TaxonomyEvents =
| CommonEvents
| "metadata_changed"
| "term_created"
| "term_changed"
| "term_deleted"
| "terms_moved";

export type WebhookNotification = WebhookItemNotification | WebhookObjectNotification;

export type WebhookItemNotification = {
data: {
system: WebhookItemObjectData;
};
message: ContentItemPreviewMessage | ContentItemPublishedMessage;
};

export type WebhookMessage = {
export type WebhookObjectNotification = {
data: {
system: WebhookObjectData;
};
message: AssetMesage | ContentTypeMessage | LanguageMessage | TaxonomyMessage;
};

type WebhookMessageCommon = {
environment_id: string;
object_type: string;
action: string;
delivery_slot: string;
delivery_slot: WebhookDeliverySlot;
};

export type AssetMesage = WebhookMessageCommon & {
object_type: "asset";
action: AssetEvents;
};

export type ContentItemPreviewMessage = WebhookMessageCommon & {
object_type: "content_item";
action: ContentItemPreviewEvents;
delivery_slot: WebhookPreviewDeliverySlot;
};

export type ContentItemPublishedMessage = WebhookMessageCommon & {
object_type: "content_item";
action: ContentItemPublishedEvents;
delivery_slot: WebhookPublishedDeliverySlot;
};

export type ContentTypeMessage = WebhookMessageCommon & {
object_type: "content_type";
action: ContentTypeEvents;
};

export type LanguageMessage = WebhookMessageCommon & {
object_type: "language";
action: LanguageEvents;
};

export type WebhookData = {
system: WebhookObject | WebhookItemObject;
export type TaxonomyMessage = WebhookMessageCommon & {
object_type: "taxonomy";
action: TaxonomyEvents;
};

export type WebhookObject = {
export type WebhookObjectData = {
id: string;
name: string;
codename: string;
last_modified: string;
};

export type WebhookItemObject = {
export type WebhookItemObjectData = {
collection: string;
workflow: string;
workflow_step: string;
language: string;
type: string;
} & WebhookObject;
} & WebhookObjectData;

0 comments on commit 168adba

Please sign in to comment.