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 41b7f4d
Showing 1 changed file with 65 additions and 15 deletions.
80 changes: 65 additions & 15 deletions lib/models/webhook-models.ts
Original file line number Diff line number Diff line change
@@ -1,30 +1,80 @@
export type WebhookNotification = {
data: WebhookData;
message: WebhookMessage;
};
type WebhookPublishedDeliverySlot = 'published';
type WebhookPreviewDeliverySlot = 'preview';

export type WebhookMessage = {
environment_id: string;
object_type: string;
action: string;
delivery_slot: string;
};
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 WebhookData = {
system: WebhookObject | WebhookItemObject;
export type WebhookNotification = WebhookItemNotification | WebhookObjectNotification;

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

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

export type WebhookObject = {
type WebhookMessageCommon = {
environment_id: 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 TaxonomyMessage = WebhookMessageCommon & {
object_type: 'taxonomy',
action: TaxonomyEvents,
}

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 41b7f4d

Please sign in to comment.