Skip to content

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 7 commits into from
Jul 28, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .npmrc

This file was deleted.

3 changes: 2 additions & 1 deletion api/base/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,8 @@ export class SmartlingBaseApi {
"dueDate",
"actionTime",
"publishDate",
"lastModified"
"lastModified",
"attemptDate"
];

if (dateProperties.includes(key) && value) {
Expand Down
7 changes: 7 additions & 0 deletions api/webhooks/dto/scrollable-response.ts
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;
}
Comment on lines +1 to +5
Copy link
Contributor

@PavelLoparev PavelLoparev Jul 25, 2025

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.

Copy link
Contributor

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.

Copy link
Contributor

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.


export { ScrollableResponse };
10 changes: 10 additions & 0 deletions api/webhooks/dto/subscription-attempted-event-dto.ts
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 };
18 changes: 18 additions & 0 deletions api/webhooks/dto/subscription-dto.ts
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 };
16 changes: 16 additions & 0 deletions api/webhooks/dto/subscription-event-attempt-dto.ts
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 };
8 changes: 8 additions & 0 deletions api/webhooks/dto/subscription-event-attempt-status.ts
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 };
8 changes: 8 additions & 0 deletions api/webhooks/dto/subscription-event-dto.ts
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 };
6 changes: 6 additions & 0 deletions api/webhooks/dto/subscription-event-trigger-type.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
enum SubscriptionEventTriggerType {
SCHEDULED = "SCHEDULED",
MANUAL = "MANUAL"
}

export { SubscriptionEventTriggerType };
5 changes: 5 additions & 0 deletions api/webhooks/dto/subscription-secret-dto.ts
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
Copy link
Contributor

@PavelLoparev PavelLoparev Jul 10, 2025

Choose a reason for hiding this comment

The 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.

8 changes: 8 additions & 0 deletions api/webhooks/dto/subscription-statistics-dto.ts
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 };
7 changes: 7 additions & 0 deletions api/webhooks/dto/webhook-event-type.dto.ts
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 };
17 changes: 17 additions & 0 deletions api/webhooks/index.ts
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";
9 changes: 9 additions & 0 deletions api/webhooks/params/create-subscription-parameters.ts
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 api/webhooks/params/create-update-subscription-parameters.ts
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;
}
}
38 changes: 38 additions & 0 deletions api/webhooks/params/get-subscription-events-parameters.ts
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`;
}
}
6 changes: 6 additions & 0 deletions api/webhooks/params/subscription-event.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
interface SubscriptionEvent {
type: string;
schemaVersion: string;
}

export { SubscriptionEvent };
6 changes: 6 additions & 0 deletions api/webhooks/params/subscription-request-header.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
interface SubscriptionRequestHeader {
headerName: string;
headerValue: string;
}

export { SubscriptionRequestHeader };
19 changes: 19 additions & 0 deletions api/webhooks/params/update-subscription-parameters.ts
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 {
constructor(
subscriptionName: string,
subscriptionUrl: string,
events: SubscriptionEvent[],
enabled: boolean
) {
super(
subscriptionName,
subscriptionUrl,
events
);

this.set("enabled", enabled);
}
}
14 changes: 14 additions & 0 deletions api/webhooks/params/update-subscription-secret-parameters.ts
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);
}
}
Loading