1 | import { Except, JsonValue, SetOptional } from 'type-fest';
|
2 | import { BasicMetaSysProps, CollectionProp, DefaultElements, MakeRequest, MetaLinkProps, SysLink } from '../common-types';
|
3 | interface EqualityConstraint {
|
4 | equals: [Doc, string];
|
5 | }
|
6 | interface Doc {
|
7 | doc: 'sys.id' | 'sys.contentType.sys.id' | 'sys.environment.sys.id';
|
8 | }
|
9 | interface InConstraint {
|
10 | in: [Doc, [string, ...string[]]];
|
11 | }
|
12 | interface RegexpConstraint {
|
13 | regexp: [Doc, Pattern];
|
14 | }
|
15 | interface Pattern {
|
16 | pattern: string;
|
17 | }
|
18 | interface NotConstraint {
|
19 | not: EqualityConstraint | InConstraint | RegexpConstraint;
|
20 | }
|
21 | export declare type WebhookCalls = {
|
22 | total: number;
|
23 | healthy: number;
|
24 | };
|
25 | export declare type WebhookCallRequest = {
|
26 | url: string;
|
27 | method: string;
|
28 | headers: {
|
29 | [key: string]: string;
|
30 | };
|
31 | body: string;
|
32 | };
|
33 | export declare type WebhookCallResponse = WebhookCallRequest & {
|
34 | statusCode: number;
|
35 | };
|
36 | export declare type WebhookHealthSys = Except<BasicMetaSysProps, 'version' | 'updatedAt' | 'updatedBy' | 'createdAt'>;
|
37 | export declare type WebhookCallDetailsSys = Except<BasicMetaSysProps, 'version' | 'updatedAt' | 'updatedBy'>;
|
38 | export declare type WebhookHeader = {
|
39 | key: string;
|
40 | value: string;
|
41 | secret?: boolean;
|
42 | };
|
43 | export declare type WebhookFilter = EqualityConstraint | InConstraint | RegexpConstraint | NotConstraint;
|
44 | export declare type WebhookTransformation = {
|
45 | method?: null | 'POST' | 'GET' | 'PUT' | 'PATCH' | 'DELETE';
|
46 | 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';
|
47 | includeContentLength?: boolean | null;
|
48 | body?: JsonValue;
|
49 | };
|
50 | export declare type CreateWebhooksProps = SetOptional<Except<WebhookProps, 'sys'>, 'headers' | 'active'>;
|
51 | export declare type UpdateWebhookProps = SetOptional<Except<WebhookProps, 'sys'>, 'headers' | 'name' | 'topics' | 'url' | 'active'>;
|
52 | export declare type WebhookCallDetailsProps = {
|
53 | /**
|
54 | * System metadata
|
55 | */
|
56 | sys: WebhookCallDetailsSys;
|
57 | /**
|
58 | * Request object
|
59 | */
|
60 | request: WebhookCallRequest;
|
61 | /**
|
62 | * Request object
|
63 | */
|
64 | response: WebhookCallResponse;
|
65 | /**
|
66 | * Status code of the request
|
67 | */
|
68 | statusCode: number;
|
69 | /**
|
70 | * Errors
|
71 | */
|
72 | errors: any[];
|
73 | /**
|
74 | * Type of the webhook
|
75 | */
|
76 | eventType: string;
|
77 | /**
|
78 | * Url of the request
|
79 | */
|
80 | url: string;
|
81 | /**
|
82 | * Timestamp of the request
|
83 | */
|
84 | requestAt: string;
|
85 | /**
|
86 | * Timestamp of the response
|
87 | */
|
88 | responseAt: string;
|
89 | };
|
90 | export declare type WebhookCallOverviewProps = Except<WebhookCallDetailsProps, 'request' | 'response'>;
|
91 | export declare type WebhookHealthProps = {
|
92 | /**
|
93 | * System metadata
|
94 | */
|
95 | sys: WebhookHealthSys & {
|
96 | space: {
|
97 | sys: MetaLinkProps;
|
98 | };
|
99 | };
|
100 | /**
|
101 | * Webhook call statistics
|
102 | */
|
103 | calls: WebhookCalls;
|
104 | };
|
105 | export declare type WebhookProps = {
|
106 | /**
|
107 | * System metadata
|
108 | */
|
109 | sys: BasicMetaSysProps & {
|
110 | space: SysLink;
|
111 | };
|
112 | /**
|
113 | * Webhook name
|
114 | */
|
115 | name: string;
|
116 | /**
|
117 | * Webhook url
|
118 | */
|
119 | url: string;
|
120 | /**
|
121 | * Topics the webhook wants to subscribe to
|
122 | */
|
123 | topics: string[];
|
124 | /**
|
125 | * Username for basic http auth
|
126 | */
|
127 | httpBasicUsername?: string;
|
128 | /**
|
129 | * Password for basic http auth
|
130 | */
|
131 | httpBasicPassword?: string;
|
132 | /**
|
133 | * Headers that should be appended to the webhook request
|
134 | */
|
135 | headers: Array<WebhookHeader>;
|
136 | /**
|
137 | * Webhook filters
|
138 | */
|
139 | filters?: WebhookFilter[];
|
140 | /**
|
141 | * Transformation to apply
|
142 | */
|
143 | transformation?: WebhookTransformation;
|
144 | /**
|
145 | * Whether the Webhook is active. If set to false, no calls will be made
|
146 | */
|
147 | active: boolean;
|
148 | };
|
149 | export interface WebHooks extends WebhookProps, DefaultElements<WebhookProps> {
|
150 | /**
|
151 | * Sends an update to the server with any changes made to the object's properties
|
152 | * @return Object returned from the server with updated changes.
|
153 | * ```javascript
|
154 | * const contentful = require('contentful-management')
|
155 | *
|
156 | * const client = contentful.createClient({
|
157 | * accessToken: '<content_management_api_key>'
|
158 | * })
|
159 | *
|
160 | * client.getSpace('<space_id>')
|
161 | * .then((space) => space.getWebhook('<webhook_id>'))
|
162 | * .then((webhook) => {
|
163 | * webhook.name = 'new webhook name'
|
164 | * return webhook.update()
|
165 | * })
|
166 | * .then((webhook) => console.log(`webhook ${webhook.sys.id} updated.`))
|
167 | * .catch(console.error)
|
168 | * ```
|
169 | */
|
170 | update(): Promise<WebHooks>;
|
171 | /**
|
172 | * Deletes this object on the server.
|
173 | * @return Promise for the deletion. It contains no data, but the Promise error case should be handled.
|
174 | * ```javascript
|
175 | * const contentful = require('contentful-management')
|
176 | *
|
177 | * const client = contentful.createClient({
|
178 | * accessToken: '<content_management_api_key>'
|
179 | * })
|
180 | *
|
181 | * client.getSpace('<space_id>')
|
182 | * .then((space) => space.getWebhook('<webhook_id>'))
|
183 | * .then((webhook) => webhook.delete())
|
184 | * .then((webhook) => console.log(`webhook ${webhook.sys.id} updated.`))
|
185 | * .catch(console.error)
|
186 | * ```
|
187 | */
|
188 | delete(): Promise<void>;
|
189 | /**
|
190 | * 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.
|
191 | * @return Promise for list of calls
|
192 | * ```javascript
|
193 | * const contentful = require('contentful-management')
|
194 | *
|
195 | * const client = contentful.createClient({
|
196 | * accessToken: '<content_management_api_key>'
|
197 | * })
|
198 | *
|
199 | * client.getSpace('<space_id>')
|
200 | * .then((space) => space.getWebhook('<webhook_id>'))
|
201 | * .then((webhook) => webhook.getCalls())
|
202 | * .then((response) => console.log(response.items)) // webhook calls
|
203 | * .catch(console.error)
|
204 | * ```
|
205 | */
|
206 | getCalls(): Promise<CollectionProp<WebhookCallOverviewProps>>;
|
207 | /**
|
208 | * 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
|
209 | * @return Promise for call details
|
210 | * ```javascript
|
211 | * const contentful = require('contentful-management')
|
212 | *
|
213 | * const client = contentful.createClient({
|
214 | * accessToken: '<content_management_api_key>'
|
215 | * })
|
216 | *
|
217 | * client.getSpace('<space_id>')
|
218 | * .then((space) => space.getWebhook('<webhook_id>'))
|
219 | * .then((webhook) => webhook.getCall('<call-id>'))
|
220 | * .then((webhookCall) => console.log(webhookCall))
|
221 | * .catch(console.error)
|
222 | * ```
|
223 | */
|
224 | getCall(id: string): Promise<WebhookCallDetailsProps>;
|
225 | /**
|
226 | * 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.
|
227 | * @return Promise for health info
|
228 | * ```javascript
|
229 | * const contentful = require('contentful-management')
|
230 | *
|
231 | * const client = contentful.createClient({
|
232 | * accessToken: '<content_management_api_key>'
|
233 | * })
|
234 | *
|
235 | * client.getSpace('<space_id>')
|
236 | * .then((space) => space.getWebhook('<webhook_id>'))
|
237 | * .then((webhook) => webhook.getHealth())
|
238 | * .then((webhookHealth) => console.log(webhookHealth))
|
239 | * .catch(console.error)
|
240 | * ```
|
241 | */
|
242 | getHealth(): Promise<WebhookHealthProps>;
|
243 | }
|
244 | /**
|
245 | * @private
|
246 | * @param makeRequest - function to make requests via an adapter
|
247 | * @param data - Raw webhook data
|
248 | * @return Wrapped webhook data
|
249 | */
|
250 | export declare function wrapWebhook(makeRequest: MakeRequest, data: WebhookProps): WebHooks;
|
251 | /**
|
252 | * @private
|
253 | */
|
254 | export declare const wrapWebhookCollection: (makeRequest: MakeRequest, data: CollectionProp<WebhookProps>) => import("../common-types").Collection<WebHooks, WebhookProps>;
|
255 | export {};
|