UNPKG

2.72 kBJavaScriptView Raw
1import { __decorate } from "tslib";
2import { _SPCollection, spInvokableFactory, _SPInstance, } from "../spqueryable.js";
3import { body } from "@pnp/queryable";
4import { defaultPath } from "../decorators.js";
5import { spPost, spPatch, spDelete } from "../operations.js";
6let _Subscriptions = class _Subscriptions extends _SPCollection {
7 /**
8 * Returns all the webhook subscriptions or the specified webhook subscription
9 *
10 * @param subscriptionId The id of a specific webhook subscription to retrieve, omit to retrieve all the webhook subscriptions
11 */
12 getById(subscriptionId) {
13 return Subscription(this).concat(`('${subscriptionId}')`);
14 }
15 /**
16 * Creates a new webhook subscription
17 *
18 * @param notificationUrl The url to receive the notifications
19 * @param expirationDate The date and time to expire the subscription in the form YYYY-MM-ddTHH:mm:ss+00:00 (maximum of 6 months)
20 * @param clientState A client specific string (optional)
21 */
22 async add(notificationUrl, expirationDate, clientState) {
23 const postBody = {
24 "expirationDateTime": expirationDate,
25 "notificationUrl": notificationUrl,
26 "resource": this.toUrl(),
27 };
28 if (clientState) {
29 postBody.clientState = clientState;
30 }
31 const data = await spPost(this, body(postBody));
32 return { data, subscription: this.getById(data.id) };
33 }
34};
35_Subscriptions = __decorate([
36 defaultPath("subscriptions")
37], _Subscriptions);
38export { _Subscriptions };
39export const Subscriptions = spInvokableFactory(_Subscriptions);
40export class _Subscription extends _SPInstance {
41 /**
42 * Renews this webhook subscription
43 *
44 * @param expirationDate The date and time to expire the subscription in the form YYYY-MM-ddTHH:mm:ss+00:00 (maximum of 6 months, optional)
45 * @param notificationUrl The url to receive the notifications (optional)
46 * @param clientState A client specific string (optional)
47 */
48 async update(expirationDate, notificationUrl, clientState) {
49 const postBody = {};
50 if (expirationDate) {
51 postBody.expirationDateTime = expirationDate;
52 }
53 if (notificationUrl) {
54 postBody.notificationUrl = notificationUrl;
55 }
56 if (clientState) {
57 postBody.clientState = clientState;
58 }
59 const data = await spPatch(this, body(postBody));
60 return { data, subscription: this };
61 }
62 /**
63 * Removes this webhook subscription
64 *
65 */
66 delete() {
67 return spDelete(this);
68 }
69}
70export const Subscription = spInvokableFactory(_Subscription);
71//# sourceMappingURL=types.js.map
\No newline at end of file