sp-js-provisioning
Version:
SharePoint provisioning with pure JavaScript
111 lines • 4.8 kB
JavaScript
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 __());
};
})();
var __values = (this && this.__values) || function(o) {
var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
if (m) return m.call(o);
if (o && typeof o.length === "number") return {
next: function () {
if (o && i >= o.length) o = void 0;
return { value: o && o[i++], done: !o };
}
};
throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
};
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 e_1, _b;
var ServerRelativeUrl = _a.ServerRelativeUrl;
var context = new SP.ClientContext(ServerRelativeUrl), spWeb = context.get_web(), propertyBag = spWeb.get_allProperties(), indexProps = [];
try {
for (var _c = __values(entries.filter(function (entry) { return entry.Overwrite; })), _d = _c.next(); !_d.done; _d = _c.next()) {
var entry = _d.value;
propertyBag.set_item(entry.Key, entry.Value);
if (entry.Indexed) {
indexProps.push(Util.base64EncodeString(entry.Key));
}
}
}
catch (e_1_1) { e_1 = { error: e_1_1 }; }
finally {
try {
if (_d && !_d.done && (_b = _c.return)) _b.call(_c);
}
finally { if (e_1) throw e_1.error; }
}
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