import type { Except, JsonValue, SetOptional } from 'type-fest'; import type { BasicMetaSysProps, CollectionProp, DefaultElements, MakeRequest, MetaLinkProps, SysLink } from '../common-types'; interface EqualityConstraint { equals: [Doc, string]; } interface Doc { doc: 'sys.id' | 'sys.contentType.sys.id' | 'sys.environment.sys.id'; } interface InConstraint { in: [Doc, [string, ...string[]]]; } interface RegexpConstraint { regexp: [Doc, Pattern]; } interface Pattern { pattern: string; } interface NotConstraint { not: EqualityConstraint | InConstraint | RegexpConstraint; } export type WebhookCalls = { total: number; healthy: number; }; export type WebhookCallRequest = { url: string; method: string; headers: { [key: string]: string; }; body: string; }; export type WebhookCallResponse = WebhookCallRequest & { statusCode: number; }; export type WebhookHealthSys = Except; export type WebhookCallDetailsSys = Except; export type WebhookHeader = { key: string; value: string; secret?: boolean; }; export type WebhookFilter = EqualityConstraint | InConstraint | RegexpConstraint | NotConstraint; export type WebhookTransformation = { method?: null | 'POST' | 'GET' | 'PUT' | 'PATCH' | 'DELETE'; contentType?: null | 'application/vnd.contentful.management.v1+json' | 'application/vnd.contentful.management.v1+json; charset=utf-8' | 'application/json' | 'application/json; charset=utf-8' | 'application/x-www-form-urlencoded' | 'application/x-www-form-urlencoded; charset=utf-8'; includeContentLength?: boolean | null; body?: JsonValue; }; export type CreateWebhooksProps = SetOptional, 'headers' | 'active'>; export type UpdateWebhookProps = SetOptional, 'headers' | 'name' | 'topics' | 'url' | 'active'>; export type UpsertWebhookSigningSecretPayload = { value: string; }; export type WebhookCallDetailsProps = { /** * System metadata */ sys: WebhookCallDetailsSys; /** * Request object */ request: WebhookCallRequest; /** * Request object */ response: WebhookCallResponse; /** * Status code of the request */ statusCode: number; /** * Errors */ errors: any[]; /** * Type of the webhook */ eventType: string; /** * Url of the request */ url: string; /** * Timestamp of the request */ requestAt: string; /** * Timestamp of the response */ responseAt: string; }; export type WebhookCallOverviewProps = Except; export type WebhookHealthProps = { /** * System metadata */ sys: WebhookHealthSys & { space: { sys: MetaLinkProps; }; }; /** * Webhook call statistics */ calls: WebhookCalls; }; export type WebhookSigningSecretSys = Except; export type WebhookSigningSecretProps = { sys: WebhookSigningSecretSys & { space: { sys: MetaLinkProps; }; }; redactedValue: string; }; export type WebhookRetryPolicyPayload = { maxRetries: number; }; export type WebhookRetryPolicySys = Except; export type WebhookRetryPolicyProps = { sys: WebhookRetryPolicySys & { space: { sys: MetaLinkProps; }; }; maxRetries: number; }; export type WebhookProps = { /** * System metadata */ sys: BasicMetaSysProps & { space: SysLink; }; /** * Webhook name */ name: string; /** * Webhook url */ url: string; /** * Topics the webhook wants to subscribe to */ topics: string[]; /** * Username for basic http auth */ httpBasicUsername?: string; /** * Password for basic http auth */ httpBasicPassword?: string; /** * Headers that should be appended to the webhook request */ headers: Array; /** * Webhook filters */ filters?: WebhookFilter[]; /** * Transformation to apply */ transformation?: WebhookTransformation; /** * Whether the Webhook is active. If set to false, no calls will be made */ active: boolean; }; export interface WebHooks extends WebhookProps, DefaultElements { /** * Sends an update to the server with any changes made to the object's properties * @return Object returned from the server with updated changes. * ```javascript * const contentful = require('contentful-management') * * const client = contentful.createClient({ * accessToken: '' * }) * * client.getSpace('') * .then((space) => space.getWebhook('')) * .then((webhook) => { * webhook.name = 'new webhook name' * return webhook.update() * }) * .then((webhook) => console.log(`webhook ${webhook.sys.id} updated.`)) * .catch(console.error) * ``` */ update(): Promise; /** * Deletes this object on the server. * @return Promise for the deletion. It contains no data, but the Promise error case should be handled. * ```javascript * const contentful = require('contentful-management') * * const client = contentful.createClient({ * accessToken: '' * }) * * client.getSpace('') * .then((space) => space.getWebhook('')) * .then((webhook) => webhook.delete()) * .then((webhook) => console.log(`webhook ${webhook.sys.id} updated.`)) * .catch(console.error) * ``` */ delete(): Promise; /** * List of the most recent webhook calls. See https://www.contentful.com/developers/docs/references/content-management-api/#/reference/webhook-calls/webhook-call-overviews for more details. * @return Promise for list of calls * ```javascript * const contentful = require('contentful-management') * * const client = contentful.createClient({ * accessToken: '' * }) * * client.getSpace('') * .then((space) => space.getWebhook('')) * .then((webhook) => webhook.getCalls()) * .then((response) => console.log(response.items)) // webhook calls * .catch(console.error) * ``` */ getCalls(): Promise>; /** * Webhook call with specific id. See https://www.contentful.com/developers/docs/references/content-management-api/#/reference/webhook-calls/webhook-call-overviews for more details * @return Promise for call details * ```javascript * const contentful = require('contentful-management') * * const client = contentful.createClient({ * accessToken: '' * }) * * client.getSpace('') * .then((space) => space.getWebhook('')) * .then((webhook) => webhook.getCall('')) * .then((webhookCall) => console.log(webhookCall)) * .catch(console.error) * ``` */ getCall(id: string): Promise; /** * Overview of the health of webhook calls. See https://www.contentful.com/developers/docs/references/content-management-api/#/reference/webhook-calls/webhook-call-overviews for more details. * @return Promise for health info * ```javascript * const contentful = require('contentful-management') * * const client = contentful.createClient({ * accessToken: '' * }) * * client.getSpace('') * .then((space) => space.getWebhook('')) * .then((webhook) => webhook.getHealth()) * .then((webhookHealth) => console.log(webhookHealth)) * .catch(console.error) * ``` */ getHealth(): Promise; } /** * @private * @param makeRequest - function to make requests via an adapter * @param data - Raw webhook data * @return Wrapped webhook data */ export declare function wrapWebhook(makeRequest: MakeRequest, data: WebhookProps): WebHooks; /** * @private */ export declare const wrapWebhookCollection: (makeRequest: MakeRequest, data: CollectionProp) => import("../common-types").Collection; export {};