@selfcommunity/api-services
Version:
Client api for SelfCommunity.
209 lines (201 loc) • 9.05 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.WebhookApiClient = void 0;
const tslib_1 = require("tslib");
const Endpoints_1 = tslib_1.__importDefault(require("../../constants/Endpoints"));
const apiRequest_1 = require("../../utils/apiRequest");
/**
* Contains all the endpoints needed to manage webhooks.
*/
class WebhookApiClient {
/**
* This endpoint retrieves all webhook endpoints
* @param config
*/
static getAllWebhookEndpoints(config) {
return (0, apiRequest_1.apiRequest)(Object.assign(Object.assign({}, config), { url: Endpoints_1.default.WebhookEndpointsList.url({}), method: Endpoints_1.default.WebhookEndpointsList.method }));
}
/**
* This endpoint retrieves webhook events that can be enabled in the endpoint.
* @param config
*/
static getAllWebhookEvents(config) {
return (0, apiRequest_1.apiRequest)(Object.assign(Object.assign({}, config), { url: Endpoints_1.default.WebhookEventsList.url({}), method: Endpoints_1.default.WebhookEventsList.method }));
}
/**
* This endpoint creates a webhook endpoint and connects it to the given webhook events.
* @param data
* @param config
*/
static createWebhookEndpoint(data, config) {
return (0, apiRequest_1.apiRequest)(Object.assign(Object.assign({}, config), { url: Endpoints_1.default.WebhookCreate.url({}), method: Endpoints_1.default.WebhookCreate.method, data: data }));
}
/**
* This endpoint retrieves a specific webhook endpoint using ID.
* @param id
* @param config
*/
static getASpecificWebhookEndpoint(id, config) {
return (0, apiRequest_1.apiRequest)(Object.assign(Object.assign({}, config), { url: Endpoints_1.default.GetSpecificWebhook.url({ id }), method: Endpoints_1.default.GetSpecificWebhook.method }));
}
/**
* This endpoint updates a specific webhook endpoint.
* @param id
* @param params
* @param config
*/
static updateASpecificWebhookEndpoint(id, params, config) {
return (0, apiRequest_1.apiRequest)(Object.assign(Object.assign({}, config), { url: Endpoints_1.default.WebhookUpdate.url({ id }), method: Endpoints_1.default.WebhookUpdate.method, data: params }));
}
/**
* This endpoint updates a specific field for a specific webhook endpoint.
* @param id
* @param params
* @param config
*/
static updateASingleWebhookEndpointField(id, params, config) {
return (0, apiRequest_1.apiRequest)(Object.assign(Object.assign({}, config), { url: Endpoints_1.default.WebhookPatch.url({ id }), method: Endpoints_1.default.WebhookPatch.method, data: params }));
}
/**
* This endpoint deletes a Webhook Endpoint.
* @param id
* @param config
*/
static deleteWebhookEndpoint(id, config) {
return (0, apiRequest_1.apiRequest)(Object.assign(Object.assign({}, config), { url: Endpoints_1.default.WebhookDelete.url({ id }), method: Endpoints_1.default.WebhookDelete.method }));
}
/**
* This endpoint retrieves the attempts related to this endpoint.
* @param id
* @param config
*/
static getAllWebhookEndpointAttempts(id, config) {
return (0, apiRequest_1.apiRequest)(Object.assign(Object.assign({}, config), { url: Endpoints_1.default.WebhookEndpointAttempts.url({ id }), method: Endpoints_1.default.WebhookEndpointAttempts.method }));
}
/**
* This endpoint expires the secret associated with this endpoint.
* @param id
* @param config
*/
static expireWebhookSigningSecret(id, config) {
return (0, apiRequest_1.apiRequest)(Object.assign(Object.assign({}, config), { url: Endpoints_1.default.WebhookExpireSigningSecret.url({ id }), method: Endpoints_1.default.WebhookExpireSigningSecret.method }));
}
/**
* This endpoint reveals the secret associated with this endpoint.
* @param id
* @param config
*/
static revealWebhookSigningSecret(id, config) {
return (0, apiRequest_1.apiRequest)(Object.assign(Object.assign({}, config), { url: Endpoints_1.default.WebhookRevealSigningSecret.url({ id }), method: Endpoints_1.default.WebhookRevealSigningSecret.method }));
}
/**
* This endpoint resends the event specified as parameter to the endpoint specified by the id parameter.
* @param id
* @param event
* @param config
*/
static resendWebhookEndpointEvent(id, event, config) {
return (0, apiRequest_1.apiRequest)(Object.assign(Object.assign({}, config), { url: Endpoints_1.default.WebhookResendEndpointEvent.url({ id }), method: Endpoints_1.default.WebhookResendEndpointEvent.method, data: { event: event } }));
}
/**
* This endpoint resends the events specified as parameters to the endpoint specified by the id parameter.
* @param id
* @param event
* @param config
*/
static resendMultipleWebhookEndpointEvent(id, event, config) {
return (0, apiRequest_1.apiRequest)(Object.assign(Object.assign({}, config), { url: Endpoints_1.default.WebhookResendMultipleEndpointEvent.url({ id }), method: Endpoints_1.default.WebhookResendMultipleEndpointEvent.method, data: { event: event } }));
}
}
exports.WebhookApiClient = WebhookApiClient;
/**
*
:::tip Webhook service can be used in the following way:
```jsx
1. Import the service from our library:
import {WebhookService} from "@selfcommunity/api-services";
```
```jsx
2. Create a function and put the service inside it!
The async function `getAllWebhookEndpoints` will return the paginated list of webhook endpoints.
async getAllWebhookEndpoints() {
return await WebhookService.getAllWebhookEndpoints();
}
```
```jsx
In case of required `params`, just add them inside the brackets.
async getASpecificWebhookEndpoint(webhookId) {
return await WebhookService.getASpecificWebhookEndpoint(webhookId);
}
```
```jsx
If you need to customize the request, you can add optional config params (`AxiosRequestConfig` type).
1. Declare it(or declare them, it is possible to add multiple params)
const headers = headers: {Authorization: `Bearer ${yourToken}`}
2. Add it inside the brackets and pass it to the function, as shown in the previous example!
```
:::
*/
class WebhookService {
static getAllWebhookEndpoints(config) {
return tslib_1.__awaiter(this, void 0, void 0, function* () {
return WebhookApiClient.getAllWebhookEndpoints(config);
});
}
static getAllWebhookEvents(config) {
return tslib_1.__awaiter(this, void 0, void 0, function* () {
return WebhookApiClient.getAllWebhookEvents(config);
});
}
static createWebhookEndpoint(params, config) {
return tslib_1.__awaiter(this, void 0, void 0, function* () {
return WebhookApiClient.createWebhookEndpoint(params, config);
});
}
static getASpecificWebhookEndpoint(id, config) {
return tslib_1.__awaiter(this, void 0, void 0, function* () {
return WebhookApiClient.getASpecificWebhookEndpoint(id, config);
});
}
static updateASpecificWebhookEndpoint(id, params, config) {
return tslib_1.__awaiter(this, void 0, void 0, function* () {
return WebhookApiClient.updateASpecificWebhookEndpoint(id, params, config);
});
}
static updateASingleWebhookEndpointField(id, params, config) {
return tslib_1.__awaiter(this, void 0, void 0, function* () {
return WebhookApiClient.updateASingleWebhookEndpointField(id, params, config);
});
}
static deleteWebhookEndpoint(id, config) {
return tslib_1.__awaiter(this, void 0, void 0, function* () {
return WebhookApiClient.deleteWebhookEndpoint(id, config);
});
}
static getAllWebhookEndpointAttempts(id, config) {
return tslib_1.__awaiter(this, void 0, void 0, function* () {
return WebhookApiClient.getAllWebhookEndpointAttempts(id, config);
});
}
static expireWebhookSigningSecret(id, config) {
return tslib_1.__awaiter(this, void 0, void 0, function* () {
return WebhookApiClient.expireWebhookSigningSecret(id, config);
});
}
static revealWebhookSigningSecret(id, config) {
return tslib_1.__awaiter(this, void 0, void 0, function* () {
return WebhookApiClient.revealWebhookSigningSecret(id, config);
});
}
static resendWebhookEndpointEvent(id, event, config) {
return tslib_1.__awaiter(this, void 0, void 0, function* () {
return WebhookApiClient.resendWebhookEndpointEvent(id, event, config);
});
}
static resendMultipleWebhookEndpointEvent(id, event, config) {
return tslib_1.__awaiter(this, void 0, void 0, function* () {
return WebhookApiClient.resendMultipleWebhookEndpointEvent(id, event, config);
});
}
}
exports.default = WebhookService;