@pnp/sp
Version:
pnp - provides a fluent api for working with SharePoint REST
71 lines • 2.72 kB
JavaScript
import { __decorate } from "tslib";
import { _SPCollection, spInvokableFactory, _SPInstance, } from "../spqueryable.js";
import { body } from "@pnp/queryable";
import { defaultPath } from "../decorators.js";
import { spPost, spPatch, spDelete } from "../operations.js";
let _Subscriptions = class _Subscriptions extends _SPCollection {
/**
* Returns all the webhook subscriptions or the specified webhook subscription
*
* @param subscriptionId The id of a specific webhook subscription to retrieve, omit to retrieve all the webhook subscriptions
*/
getById(subscriptionId) {
return Subscription(this).concat(`('${subscriptionId}')`);
}
/**
* Creates a new webhook subscription
*
* @param notificationUrl The url to receive the notifications
* @param expirationDate The date and time to expire the subscription in the form YYYY-MM-ddTHH:mm:ss+00:00 (maximum of 6 months)
* @param clientState A client specific string (optional)
*/
async add(notificationUrl, expirationDate, clientState) {
const postBody = {
"expirationDateTime": expirationDate,
"notificationUrl": notificationUrl,
"resource": this.toUrl(),
};
if (clientState) {
postBody.clientState = clientState;
}
const data = await spPost(this, body(postBody));
return { data, subscription: this.getById(data.id) };
}
};
_Subscriptions = __decorate([
defaultPath("subscriptions")
], _Subscriptions);
export { _Subscriptions };
export const Subscriptions = spInvokableFactory(_Subscriptions);
export class _Subscription extends _SPInstance {
/**
* Renews this webhook subscription
*
* @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)
* @param notificationUrl The url to receive the notifications (optional)
* @param clientState A client specific string (optional)
*/
async update(expirationDate, notificationUrl, clientState) {
const postBody = {};
if (expirationDate) {
postBody.expirationDateTime = expirationDate;
}
if (notificationUrl) {
postBody.notificationUrl = notificationUrl;
}
if (clientState) {
postBody.clientState = clientState;
}
const data = await spPatch(this, body(postBody));
return { data, subscription: this };
}
/**
* Removes this webhook subscription
*
*/
delete() {
return spDelete(this);
}
}
export const Subscription = spInvokableFactory(_Subscription);
//# sourceMappingURL=types.js.map