Skip to content

Commit

Permalink
Feat: Add support for vnext webhooks API (#131)
Browse files Browse the repository at this point in the history
* created new webhook contract, updated naming of legacy webhook contracts

* created new webhook model, updated naming of legacy webhook models

* created new webhook responses, updated legacy webhook responses

* added new webhook delivery trigger models

* added new webhook mappers, updated legacy webhook mappers. Maded needed adjustments to contracts, models

* added new webhook endpoints and updated legacy webhook naming

* added needed webhook queries to queries folder and query service class

* added remaining legacy webhook query classes

* updated query exports, updated management client with new webhook methods

* added webhook tests and converted existing tests to legacy webhook

* changed webhook trigger models to match API output. Finished test cases, all tests passing

* made requested changes, updated models contracts test cases and fake responses accordingly

* Uses provided type instead of string literal, restructures types

* Adds missing enabled property, uses health status type, fixes tests property check

---------

Co-authored-by: Richard Sustek <[email protected]>
  • Loading branch information
Nickm615 and Enngage authored Jan 22, 2024
1 parent e713e86 commit f82354b
Show file tree
Hide file tree
Showing 35 changed files with 1,339 additions and 239 deletions.
36 changes: 36 additions & 0 deletions lib/client/imanagement-client.interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import {
AddLanguageQuery,
AddSpaceQuery,
AddTaxonomyQuery,
AddLegacyWebhookQuery,
AddWebhookQuery,
AssetIdentifierQuery,
CancelScheduledPublishingOfLanguageVariantQuery,
Expand All @@ -50,9 +51,11 @@ import {
DeleteQuery,
DeleteTaxonomyQuery,
DeleteWebhookQuery,
DeleteLegacyWebhookQuery,
GetQuery,
GetTaxonomyQuery,
GetWebhookQuery,
GetLegacyWebhookQuery,
LanguageIdAndCodenameIdentifierQuery,
LanguageIdentifierQuery,
ListAssetFoldersQuery,
Expand All @@ -66,6 +69,7 @@ import {
ListLanguageVariantsOfItemQuery,
ListSpacesQuery,
ListTaxonomiesQuery,
ListLegacyWebhooksQuery,
ListWebhooksQuery,
ListWorkflowStepsQuery,
ModifyAssetFoldersQuery,
Expand Down Expand Up @@ -97,7 +101,9 @@ import {
ViewSpaceQuery,
WebhookIdentifierQuery,
WorkflowStepIdentifierQuery,
EnableLegacyWebhookQuery,
EnableWebhookQuery,
DisableLegacyWebhookQuery,
DisableWebhookQuery,
ListCollectionsQuery,
CollectionIdentifierQuery,
Expand Down Expand Up @@ -516,6 +522,36 @@ export interface IManagementClient<TCancelToken> {
*/
listWebhooks(): ListWebhooksQuery;

/**
* Delete a legacy webhook
*/
deleteLegacyWebhook(): WebhookIdentifierQuery<DeleteLegacyWebhookQuery>;

/**
* Adds new legacy webhook
*/
addLegacyWebhook(): DataQuery<AddLegacyWebhookQuery, WebhookModels.IAddLegacyWebhookData>;

/**
* Gets single legacy webhook
*/
getLegacyWebhook(): WebhookIdentifierQuery<GetLegacyWebhookQuery>;

/**
* Enableslegacy webhook
*/
enableLegacyWebhook(): WebhookIdentifierQuery<EnableLegacyWebhookQuery>;

/**
* Disables legacy webhook
*/
disableLegacyWebhook(): WebhookIdentifierQuery<DisableLegacyWebhookQuery>;

/**
* Gets all legacy webhooks
*/
listLegacyWebhooks(): ListLegacyWebhooksQuery;

/**
* Query to get environment information
*/
Expand Down
51 changes: 51 additions & 0 deletions lib/client/management-client.class.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import {
AddLanguageQuery,
AddTaxonomyQuery,
AddWebhookQuery,
AddLegacyWebhookQuery,
AssetIdentifierQuery,
CancelScheduledPublishingOfLanguageVariantQuery,
ChangeWorkflowStepOfLanguageOrVariantQuery,
Expand All @@ -48,8 +49,10 @@ import {
DeleteLanguageVariantQuery,
DeleteTaxonomyQuery,
DeleteWebhookQuery,
DeleteLegacyWebhookQuery,
GetTaxonomyQuery,
GetWebhookQuery,
GetLegacyWebhookQuery,
LanguageIdAndCodenameIdentifierQuery,
LanguageIdentifierQuery,
ListAssetFoldersQuery,
Expand All @@ -63,6 +66,7 @@ import {
ListLanguageVariantsOfItemQuery,
ListTaxonomiesQuery,
ListWebhooksQuery,
ListLegacyWebhooksQuery,
ListWorkflowStepsQuery,
ModifyAssetFoldersQuery,
ModifyContentTypeQuery,
Expand Down Expand Up @@ -95,7 +99,9 @@ import {
GetQuery,
CancelScheduledUnpublishingOfLanguageVariantQuery,
EnableWebhookQuery,
EnableLegacyWebhookQuery,
DisableWebhookQuery,
DisableLegacyWebhookQuery,
ListCollectionsQuery,
CollectionIdentifierQuery,
ListLanguageVariantsByCollectionQuery,
Expand Down Expand Up @@ -1035,6 +1041,51 @@ export class ManagementClient implements IManagementClient<CancelToken> {
return new ListWebhooksQuery(this.config, this.queryService);
}

deleteLegacyWebhook(): WebhookIdentifierQuery<DeleteLegacyWebhookQuery> {
return new WebhookIdentifierQuery<DeleteLegacyWebhookQuery>(
this.config,
this.queryService,
(config, queryService, identifier) => new DeleteLegacyWebhookQuery(config, queryService, identifier)
);
}

addLegacyWebhook(): DataQuery<AddLegacyWebhookQuery, WebhookModels.IAddLegacyWebhookData> {
return new DataQuery<AddLegacyWebhookQuery, WebhookModels.IAddLegacyWebhookData>(
this.config,
this.queryService,
(config, queryService, data) => new AddLegacyWebhookQuery(config, queryService, data)
);
}

enableLegacyWebhook(): WebhookIdentifierQuery<EnableLegacyWebhookQuery> {
return new WebhookIdentifierQuery<EnableLegacyWebhookQuery>(
this.config,
this.queryService,
(config, queryService, identifier) => new EnableLegacyWebhookQuery(config, queryService, identifier)
);
}

disableLegacyWebhook(): WebhookIdentifierQuery<DisableLegacyWebhookQuery> {
return new WebhookIdentifierQuery<DisableLegacyWebhookQuery>(
this.config,
this.queryService,
(config, queryService, identifier) => new DisableLegacyWebhookQuery(config, queryService, identifier)
);
}

getLegacyWebhook(): WebhookIdentifierQuery<GetLegacyWebhookQuery> {
return new WebhookIdentifierQuery<GetLegacyWebhookQuery>(
this.config,
this.queryService,
(config, queryService, identifier) => new GetLegacyWebhookQuery(config, queryService, identifier)
);
}

listLegacyWebhooks(): ListLegacyWebhooksQuery {
return new ListLegacyWebhooksQuery(this.config, this.queryService);
}


environmentInformation(): EnvironmentInformationQuery {
return new EnvironmentInformationQuery(this.config, this.queryService);
}
Expand Down
117 changes: 100 additions & 17 deletions lib/contracts/webhook-contracts.ts
Original file line number Diff line number Diff line change
@@ -1,48 +1,131 @@
import { SharedContracts } from './shared-contracts';

export namespace WebhookContracts {
export type WebhookWorkflowStepOperationContract = 'publish' | 'unpublish' | 'archive' | 'restore' | 'upsert';
export type WebhookManagementContentChangesOperations = 'archive' | 'create' | 'restore';
export type WebhookPreviewContentChangesOperations = 'archive' | 'upsert' | 'restore';
export type WebhookContentTypeActions = 'created' | 'changed' | 'deleted';
export type WebhookAssetActions = 'created' | 'changed' | 'metadata_changed' | 'deleted';
export type WebhookTaxonomyActions =
| 'created'
| 'metadata_changed'
| 'deleted'
| 'term_created'
| 'term_changed'
| 'term_deleted'
| 'terms_moved';
export type WebhookLanguageActions = 'created' | 'changed' | 'deleted';
export type WebhookContentItemActions =
| 'published'
| 'unpublished'
| 'created'
| 'changed'
| 'metadata_changed'
| 'deleted'
| 'workflow_step_changed';
export type WebhookDeliveryTriggerSlots = 'published' | 'preview';
export type WebhookDeliveryTriggersEvents = 'all' | 'specific';

export interface IDeleteWebhookResponseContract {
}
export interface IDeleteWebhookResponseContract {}

export interface IWebhookTransitionsToContract {
export interface ILegacyWebhookTransitionsToContract {
id: string;
}

export type WebhookWorkflowStepOperationContract = 'publish' | 'unpublish' | 'archive' | 'restore' | 'upsert';

export type WebhookManagementContentChangesOperations = 'archive' | 'create' | 'restore';

export interface IWebhookWorkflowStepChangesContract {
export interface ILegacyWebhookWorkflowStepChangesContract {
type: 'content_item_variant';
transitions_to: IWebhookTransitionsToContract[];
transitions_to: ILegacyWebhookTransitionsToContract[];
}

export interface IWebhookManagementApiContentChangesContract {
export interface ILegacyWebhookManagementApiContentChangesContract {
type: 'content_item_variant';
operations: WebhookManagementContentChangesOperations[];
}

export interface IWebhookDeliveryApiContentChangesContract {
export interface ILegacyWebhookDeliveryApiContentChangesContract {
type: 'taxonomy' | 'content_item_variant';
operations: WebhookWorkflowStepOperationContract[];
}

export interface IWebhookContract {
export interface ILegacyWebhookPreviewDeliveryApiContentChangesContract {
type: 'taxonomy' | 'content_item_variant';
operations: WebhookPreviewContentChangesOperations[];
}

export interface IWebhookContentTypeContract {
enabled: boolean;
actions?: WebhookContentTypeActions[];
}

export interface IWebhookAssetContract {
enabled: boolean;
actions?: WebhookAssetActions[];
}

export interface IWebhookTaxonomyContract {
enabled: boolean;
actions?: WebhookTaxonomyActions[];
}

export interface IWebhookLanguageContract {
enabled: boolean;
actions?: WebhookLanguageActions[];
}

export interface IContentItemFilters {
collections?: SharedContracts.IReferenceObjectContract[];
content_types?: SharedContracts.IReferenceObjectContract[];
languages?: SharedContracts.IReferenceObjectContract[];
}
export interface IWebhookContentItemContract {
enabled: boolean;
actions?: WebhookContentItemActions[];
filters?: IContentItemFilters;
}

export interface ILegacyWebhookContract {
id: string;
name: string;
secret: string;
url: string;
last_modified?: string;
health_status?: string;
triggers: {
delivery_api_content_changes: IWebhookDeliveryApiContentChangesContract[],
workflow_step_changes: IWebhookWorkflowStepChangesContract[],
delivery_api_content_changes: ILegacyWebhookDeliveryApiContentChangesContract[];
workflow_step_changes: ILegacyWebhookWorkflowStepChangesContract[];
preview_delivery_api_content_changes: ILegacyWebhookPreviewDeliveryApiContentChangesContract[];
management_api_content_changes: ILegacyWebhookManagementApiContentChangesContract[];
};
}

export interface IGetWebhookContract extends IWebhookContract {
export interface IWebhookContract {
id: string;
name: string;
secret: string;
url: string;
last_modified?: string;
enabled?: boolean;
health_status?: string;
delivery_triggers: {
slot: WebhookDeliveryTriggerSlots;
events: WebhookDeliveryTriggersEvents;
asset?: IWebhookAssetContract;
content_type?: IWebhookContentTypeContract;
taxonomy?: IWebhookTaxonomyContract;
language?: IWebhookLanguageContract;
content_item?: IWebhookContentItemContract;
};
}

export interface IAddWebhookContract extends IWebhookContract {
}
export interface IGetLegacyWebhookContract extends ILegacyWebhookContract {}

export interface IGetWebhookContract extends IWebhookContract {}

export interface IAddLegacyWebhookContract extends ILegacyWebhookContract {}

export interface IAddWebhookContract extends IWebhookContract {}

export type ILegacyWebhookListContract = ILegacyWebhookContract[];

export type IWebhookListContract = IWebhookContract[];
}
Loading

0 comments on commit f82354b

Please sign in to comment.