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