UNPKG

sp-js-provisioning

Version:
88 lines 3.85 kB
var __extends = (this && this.__extends) || (function () { var extendStatics = function (d, b) { extendStatics = Object.setPrototypeOf || ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; }; return extendStatics(d, b); }; return function (d, b) { extendStatics(d, b); function __() { this.constructor = d; } d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); }; })(); import { Logger } from '@pnp/logging'; import * as Util from '../util'; import { HandlerBase } from './handlerbase'; /** * Describes the PropertyBagEntries Object Handler */ var PropertyBagEntries = /** @class */ (function (_super) { __extends(PropertyBagEntries, _super); /** * Creates a new instance of the PropertyBagEntries class * * @param config - Provisioning config */ function PropertyBagEntries(config) { return _super.call(this, 'PropertyBagEntries', config) || this; } /** * Provisioning property bag entries * * @param web - The web * @param entries - The property bag entries to provision */ PropertyBagEntries.prototype.ProvisionObjects = function (web, entries) { var _this = this; _super.prototype.scope_started.call(this); return new Promise(function (resolve, reject) { if (Util.isNode()) { Logger.write('PropertyBagEntries Handler not supported in Node.', 3 /* Error */); reject(); } else if (_this.config.spfxContext) { Logger.write('PropertyBagEntries Handler not supported in SPFx.', 3 /* Error */); reject(); } else { web.select('ServerRelativeUrl')().then(function (_a) { var ServerRelativeUrl = _a.ServerRelativeUrl; var context = new SP.ClientContext(ServerRelativeUrl), spWeb = context.get_web(), propertyBag = spWeb.get_allProperties(), indexProps = []; for (var _i = 0, _b = entries.filter(function (entry) { return entry.Overwrite; }); _i < _b.length; _i++) { var entry = _b[_i]; propertyBag.set_item(entry.Key, entry.Value); if (entry.Indexed) { indexProps.push(Util.base64EncodeString(entry.Key)); } } spWeb.update(); context.load(propertyBag); context.executeQueryAsync(function () { if (indexProps.length > 0) { propertyBag.set_item('vti_indexedpropertykeys', indexProps.join('|')); spWeb.update(); context.executeQueryAsync(function () { _super.prototype.scope_ended.call(_this); resolve(true); }, function () { _super.prototype.scope_ended.call(_this); reject(); }); } else { _super.prototype.scope_ended.call(_this); resolve(true); } }, function () { _super.prototype.scope_ended.call(_this); reject(); }); }); } }); }; return PropertyBagEntries; }(HandlerBase)); export { PropertyBagEntries }; //# sourceMappingURL=propertybagentries.js.map