-
Notifications
You must be signed in to change notification settings - Fork 10
DEVORTEX-5439 add webhooks api #125
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
6f4534f
DEVORTEX-5439 add webhooks api
steplov 0a10ff4
DEVORTEX-5439 add webhooks api
steplov 9f08a0c
DEVORTEX-5439 add webhooks api
steplov d69eb4f
DEVORTEX-5439 add webhooks api
steplov 92f11cd
Merge branch 'master' into DEVORTEX-5439
dnetrebenko-smartling fdc725a
DEVORTEX-5439 Added endpoints for events
dnetrebenko-smartling da27b77
2.22.0
dnetrebenko-smartling File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
interface ScrollableResponse<T> { | ||
items: Array<T>; | ||
hasMore: boolean; | ||
scrollId: string | null; | ||
} | ||
|
||
export { ScrollableResponse }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import { SubscriptionEventAttemptStatus } from "./subscription-event-attempt-status"; | ||
|
||
interface SubscriptionAttemptedEventDto { | ||
eventId: string; | ||
eventType: string; | ||
createdDate: Date; | ||
lastAttemptStatus: SubscriptionEventAttemptStatus | ||
} | ||
|
||
export { SubscriptionAttemptedEventDto }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import { SubscriptionEvent } from "../params/subscription-event"; | ||
import { SubscriptionRequestHeader } from "../params/subscription-request-header"; | ||
|
||
interface SubscriptionDto { | ||
subscriptionUid: string; | ||
subscriptionName: string; | ||
subscriptionUrl: string; | ||
accountUid: string; | ||
enabled: boolean; | ||
userUid: string; | ||
description: string | null; | ||
createdDate: string; | ||
requestHeaders: SubscriptionRequestHeader[]; | ||
events: SubscriptionEvent[]; | ||
projectUids: string[]; | ||
} | ||
|
||
export { SubscriptionDto }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import { SubscriptionEventAttemptStatus } from "./subscription-event-attempt-status"; | ||
import { SubscriptionEventTriggerType } from "./subscription-event-trigger-type"; | ||
|
||
interface SubscriptionEventAttemptDto { | ||
attemptId: string; | ||
eventId: string; | ||
response: string | null; | ||
responseDurationMs: number; | ||
responseStatusCode: number; | ||
attemptStatus: SubscriptionEventAttemptStatus; | ||
attemptDate: Date; | ||
url: string; | ||
triggerType: SubscriptionEventTriggerType; | ||
} | ||
|
||
export { SubscriptionEventAttemptDto }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
enum SubscriptionEventAttemptStatus { | ||
SUCCESS = "SUCCESS", | ||
PENDING = "PENDING", | ||
FAIL = "FAIL", | ||
SENDING = "SENDING" | ||
} | ||
|
||
export { SubscriptionEventAttemptStatus }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
interface SubscriptionEventDto { | ||
eventId: string; | ||
eventType: string; | ||
createdDate: Date; | ||
payload: Record<string, unknown>; | ||
} | ||
|
||
export { SubscriptionEventDto }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
enum SubscriptionEventTriggerType { | ||
SCHEDULED = "SCHEDULED", | ||
MANUAL = "MANUAL" | ||
} | ||
|
||
export { SubscriptionEventTriggerType }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
interface SubscriptionSecretDto { | ||
payloadSecret: string; | ||
} | ||
|
||
export { SubscriptionSecretDto }; | ||
Comment on lines
+1
to
+5
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. no actions points: weird naming. it's already clear this secret is in payload. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
interface SubscriptionStatisticsDto { | ||
failEvents: number; | ||
pendingEvents: number; | ||
sendingEvents: number; | ||
successEvents: number; | ||
} | ||
|
||
export { SubscriptionStatisticsDto }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
class WebhookEventTypeDto { | ||
eventType: string; | ||
description: string; | ||
schema: Record<string, unknown>; | ||
} | ||
|
||
export { WebhookEventTypeDto }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
export { SmartlingWebhooksApi } from "./smartling-webhooks-api"; | ||
export { ScrollableResponse } from "./dto/scrollable-response"; | ||
export { SubscriptionAttemptedEventDto } from "./dto/subscription-attempted-event-dto"; | ||
export { SubscriptionEventDto } from "./dto/subscription-event-dto"; | ||
export { SubscriptionEventAttemptDto } from "./dto/subscription-event-attempt-dto"; | ||
export { SubscriptionEventAttemptStatus } from "./dto/subscription-event-attempt-status"; | ||
export { SubscriptionEventTriggerType } from "./dto/subscription-event-trigger-type"; | ||
export { SubscriptionStatisticsDto } from "./dto/subscription-statistics-dto"; | ||
export { SubscriptionDto } from "./dto/subscription-dto"; | ||
export { SubscriptionSecretDto } from "./dto/subscription-secret-dto"; | ||
export { WebhookEventTypeDto } from "./dto/webhook-event-type.dto"; | ||
export { SubscriptionEvent } from "./params/subscription-event"; | ||
export { CreateSubscriptionParameters } from "./params/create-subscription-parameters"; | ||
export { UpdateSubscriptionParameters } from "./params/update-subscription-parameters"; | ||
export { SubscriptionRequestHeader } from "./params/subscription-request-header"; | ||
export { UpdateSubscriptionSecretParameters } from "./params/update-subscription-secret-parameters"; | ||
export { GetSubscriptionEventsParameters } from "./params/get-subscription-events-parameters"; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import { CreateUpdateSubscriptionParameters } from "./create-update-subscription-parameters"; | ||
|
||
export class CreateSubscriptionParameters extends CreateUpdateSubscriptionParameters { | ||
setPayloadSecret(payloadSecret: string): this { | ||
this.set("payloadSecret", payloadSecret); | ||
|
||
return this; | ||
} | ||
} |
70 changes: 70 additions & 0 deletions
70
api/webhooks/params/create-update-subscription-parameters.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
import { BaseParameters } from "../../parameters"; | ||
import { SmartlingException } from "../../exception"; | ||
import { SubscriptionEvent } from "./subscription-event"; | ||
import { SubscriptionRequestHeader } from "./subscription-request-header"; | ||
|
||
const MAX_EVENTS_SIZE = 1000; | ||
const MAX_SUBSCRIPTION_HEADERS_SIZE = 20; | ||
const MAX_PROJECT_UIDS_SIZE = 10; | ||
|
||
export abstract class CreateUpdateSubscriptionParameters extends BaseParameters { | ||
constructor( | ||
subscriptionName: string, | ||
subscriptionUrl: string, | ||
events: SubscriptionEvent[] | ||
) { | ||
super(); | ||
|
||
if (!subscriptionName) { | ||
throw new SmartlingException("Subscription name is required."); | ||
} | ||
|
||
if (!subscriptionUrl) { | ||
throw new SmartlingException("Subscription url is required."); | ||
} | ||
|
||
if (!events.length) { | ||
throw new SmartlingException("At least one event is required."); | ||
} | ||
|
||
if (events.length > MAX_EVENTS_SIZE) { | ||
throw new SmartlingException(`The request contains too many events: ${events.length}. Maximum allowed events number is ${MAX_EVENTS_SIZE}.`); | ||
} | ||
|
||
this.set("subscriptionName", subscriptionName); | ||
this.set("subscriptionUrl", subscriptionUrl); | ||
this.set("events", events); | ||
} | ||
|
||
setDescription(description: string): this { | ||
this.set("description", description); | ||
|
||
return this; | ||
} | ||
|
||
setRequestHeaders(requestHeaders: SubscriptionRequestHeader[]): this { | ||
if (!requestHeaders.length) { | ||
throw new SmartlingException("At least one subscription header is required."); | ||
} | ||
|
||
if (requestHeaders.length > MAX_SUBSCRIPTION_HEADERS_SIZE) { | ||
throw new SmartlingException(`The request contains too many subscription headers: ${requestHeaders.length}. Maximum allowed subscription headers number is ${MAX_SUBSCRIPTION_HEADERS_SIZE}.`); | ||
} | ||
|
||
this.set("requestHeaders", requestHeaders); | ||
return this; | ||
} | ||
|
||
setProjectUids(projectUids: string[]): this { | ||
if (!projectUids.length) { | ||
throw new SmartlingException("At least one project uid is required."); | ||
} | ||
|
||
if (projectUids.length > MAX_PROJECT_UIDS_SIZE) { | ||
throw new SmartlingException(`The request contains too many project uids: ${projectUids.length}. Maximum allowed project uids number is ${MAX_PROJECT_UIDS_SIZE}.`); | ||
} | ||
this.set("projectUids", projectUids); | ||
|
||
return this; | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import { BaseParameters } from "../../parameters"; | ||
import { SubscriptionEventAttemptStatus } from "../dto/subscription-event-attempt-status"; | ||
|
||
export class GetSubscriptionEventsParameters extends BaseParameters { | ||
setLimit(limit: number): this { | ||
this.set("limit", limit); | ||
return this; | ||
} | ||
|
||
setScrollId(scrollId: string): this { | ||
this.set("scrollId", scrollId); | ||
return this; | ||
} | ||
|
||
setAttemptStatus(attemptStatus: SubscriptionEventAttemptStatus): this { | ||
this.set("attemptStatus", attemptStatus); | ||
return this; | ||
} | ||
|
||
setCreatedDateBefore(createdDateBefore: Date): this { | ||
this.set("createdDateBefore", GetSubscriptionEventsParameters.prepareDateParameter(createdDateBefore)); | ||
return this; | ||
} | ||
|
||
setCreatedDateAfter(createdDateAfter: Date): this { | ||
this.set("createdDateAfter", GetSubscriptionEventsParameters.prepareDateParameter(createdDateAfter)); | ||
return this; | ||
} | ||
|
||
setEventTypes(eventTypes: string[]): this { | ||
this.set("eventTypes", eventTypes); | ||
return this; | ||
} | ||
|
||
private static prepareDateParameter(date: Date): string { | ||
return `${date.toISOString().split(".")[0]}Z`; | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
interface SubscriptionEvent { | ||
type: string; | ||
schemaVersion: string; | ||
} | ||
|
||
export { SubscriptionEvent }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
interface SubscriptionRequestHeader { | ||
headerName: string; | ||
headerValue: string; | ||
} | ||
|
||
export { SubscriptionRequestHeader }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import { CreateUpdateSubscriptionParameters } from "./create-update-subscription-parameters"; | ||
import { SubscriptionEvent } from "./subscription-event"; | ||
|
||
export class UpdateSubscriptionParameters extends CreateUpdateSubscriptionParameters { | ||
PavelLoparev marked this conversation as resolved.
Show resolved
Hide resolved
|
||
constructor( | ||
subscriptionName: string, | ||
subscriptionUrl: string, | ||
events: SubscriptionEvent[], | ||
enabled: boolean | ||
) { | ||
super( | ||
subscriptionName, | ||
subscriptionUrl, | ||
events | ||
); | ||
|
||
this.set("enabled", enabled); | ||
} | ||
} |
14 changes: 14 additions & 0 deletions
14
api/webhooks/params/update-subscription-secret-parameters.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import { BaseParameters } from "../../parameters"; | ||
import { SmartlingException } from "../../exception"; | ||
|
||
export class UpdateSubscriptionSecretParameters extends BaseParameters { | ||
constructor(payloadSecret: string) { | ||
super(); | ||
|
||
if (!payloadSecret) { | ||
throw new SmartlingException("Payload secret is required."); | ||
} | ||
|
||
this.set("payloadSecret", payloadSecret); | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Only webhooks api uses this type of pagination? I'm thinking if we should put this response interface to
api/http
where shared response interfaces are located.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i was thinking about it. I can do it and put into a shared directory if you want. but this structure is very specific for Webhooks service and third-party delivery system we use. not sure that it will be helpful for other APIs. so, up to you.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
got it. let's leave as is.