Socket
Socket
Sign inDemoInstall

@pnp/common-commonjs

Package Overview
Dependencies
Maintainers
13
Versions
51
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@pnp/common-commonjs - npm Package Compare versions

Comparing version 2.2.0 to 2.3.0

14

collections.js
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.mergeMaps = exports.objectToMap = void 0;
const util_js_1 = require("./util.js");
var util_js_1 = require("./util.js");
/**
* Used to calculate the object properties, with polyfill if needed
*/
const objectEntries = util_js_1.isFunc(Object.entries) ? Object.entries : (o) => Object.keys(o).map((k) => [k, o[k]]);
var objectEntries = util_js_1.isFunc(Object.entries) ? Object.entries : function (o) { return Object.keys(o).map(function (k) { return [k, o[k]]; }); };
/**

@@ -27,5 +27,9 @@ * Converts the supplied object to a map

*/
function mergeMaps(target, ...maps) {
for (let i = 0; i < maps.length; i++) {
maps[i].forEach((v, k) => {
function mergeMaps(target) {
var maps = [];
for (var _i = 1; _i < arguments.length; _i++) {
maps[_i - 1] = arguments[_i];
}
for (var i = 0; i < maps.length; i++) {
maps[i].forEach(function (v, k) {
// let's not run the spfx context through Object.assign :)

@@ -32,0 +36,0 @@ if ((typeof k === "string" && k !== "spfxContext") && Object.prototype.toString.call(v) === "[object Object]") {

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const tslib_1 = require("tslib");
var tslib_1 = require("tslib");
tslib_1.__exportStar(require("./collections.js"), exports);

@@ -5,0 +5,0 @@ tslib_1.__exportStar(require("./libconfig.js"), exports);

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.DefaultRuntime = exports.Runtime = exports.onRuntimeCreate = exports.setup = void 0;
const collections_js_1 = require("./collections.js");
function setup(config, runtime = exports.DefaultRuntime) {
var tslib_1 = require("tslib");
var collections_js_1 = require("./collections.js");
function setup(config, runtime) {
if (runtime === void 0) { runtime = exports.DefaultRuntime; }
runtime.assign(config);

@@ -10,3 +12,3 @@ }

// lable mapping for known config values
const s = [
var s = [
"defaultCachingStore",

@@ -20,3 +22,3 @@ "defaultCachingTimeoutSeconds",

];
const runtimeCreateHooks = [];
var runtimeCreateHooks = [];
function onRuntimeCreate(hook) {

@@ -30,8 +32,10 @@ if (runtimeCreateHooks.indexOf(hook) < 0) {

exports.onRuntimeCreate = onRuntimeCreate;
class Runtime {
constructor(_v = new Map()) {
var Runtime = /** @class */ (function () {
function Runtime(_v) {
var _this = this;
if (_v === void 0) { _v = new Map(); }
this._v = _v;
const defaulter = (key, def) => {
if (!this._v.has(key)) {
this._v.set(key, def);
var defaulter = function (key, def) {
if (!_this._v.has(key)) {
_this._v.set(key, def);
}

@@ -47,3 +51,3 @@ };

defaulter(s[6], false);
runtimeCreateHooks.forEach(hook => hook(this));
runtimeCreateHooks.forEach(function (hook) { return hook(_this); });
}

@@ -54,5 +58,5 @@ /**

*/
assign(config) {
Runtime.prototype.assign = function (config) {
this._v = collections_js_1.mergeMaps(this._v, collections_js_1.objectToMap(config));
}
};
/**

@@ -63,22 +67,34 @@ * Gets a runtime value using T to define the available keys, and R to define the type returned by that key

*/
get(key) {
Runtime.prototype.get = function (key) {
return this._v.get(key);
}
};
/**
* Exports the internal Map representing this runtime
*/
export() {
const expt = new Map();
for (const [key, value] of this._v) {
if (key !== "__isDefault__") {
expt.set(key, value);
Runtime.prototype.export = function () {
var e_1, _a;
var expt = new Map();
try {
for (var _b = tslib_1.__values(this._v), _c = _b.next(); !_c.done; _c = _b.next()) {
var _d = tslib_1.__read(_c.value, 2), key = _d[0], value = _d[1];
if (key !== "__isDefault__") {
expt.set(key, value);
}
}
}
catch (e_1_1) { e_1 = { error: e_1_1 }; }
finally {
try {
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
}
finally { if (e_1) throw e_1.error; }
}
return expt;
}
}
};
return Runtime;
}());
exports.Runtime = Runtime;
// default runtime used globally
const _runtime = new Runtime(new Map([["__isDefault__", true]]));
var _runtime = new Runtime(new Map([["__isDefault__", true]]));
exports.DefaultRuntime = _runtime;
//# sourceMappingURL=libconfig.js.map
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.SPFxAdalClient = exports.LambdaFetchClient = exports.BearerTokenFetchClient = exports.FetchClient = exports.getADALResource = exports.mergeOptions = exports.mergeHeaders = void 0;
const tslib_1 = require("tslib");
const util_js_1 = require("./util.js");
const safe_global_js_1 = require("./safe-global.js");
var tslib_1 = require("tslib");
var util_js_1 = require("./util.js");
var safe_global_js_1 = require("./safe-global.js");
function mergeHeaders(target, source) {
if (util_js_1.objectDefinedNotNull(source)) {
const temp = new Request("", { headers: source });
temp.headers.forEach((value, name) => {
var temp = new Request("", { headers: source });
temp.headers.forEach(function (value, name) {
target.append(name, value);

@@ -18,3 +18,3 @@ });

if (util_js_1.objectDefinedNotNull(source)) {
const headers = util_js_1.assign(target.headers || {}, source.headers);
var headers = util_js_1.assign(target.headers || {}, source.headers);
target = util_js_1.assign(target, source);

@@ -31,4 +31,4 @@ target.headers = headers;

function getADALResource(url) {
const u = new URL(url);
return `${u.protocol}//${u.hostname}`;
var u = new URL(url);
return u.protocol + "//" + u.hostname;
}

@@ -39,7 +39,10 @@ exports.getADALResource = getADALResource;

*/
class FetchClient {
fetch(url, options) {
var FetchClient = /** @class */ (function () {
function FetchClient() {
}
FetchClient.prototype.fetch = function (url, options) {
return safe_global_js_1.safeGlobal.fetch(url, options);
}
}
};
return FetchClient;
}());
exports.FetchClient = FetchClient;

@@ -49,20 +52,26 @@ /**

*/
class BearerTokenFetchClient extends FetchClient {
constructor(token) {
super();
this.token = token;
var BearerTokenFetchClient = /** @class */ (function (_super) {
tslib_1.__extends(BearerTokenFetchClient, _super);
function BearerTokenFetchClient(token) {
var _this = _super.call(this) || this;
_this.token = token;
return _this;
}
fetch(url, options = {}) {
const headers = new Headers();
BearerTokenFetchClient.prototype.fetch = function (url, options) {
if (options === void 0) { options = {}; }
var headers = new Headers();
mergeHeaders(headers, options.headers);
headers.set("Authorization", `Bearer ${this.token}`);
headers.set("Authorization", "Bearer " + this.token);
options.headers = headers;
return super.fetch(url, options);
}
}
return _super.prototype.fetch.call(this, url, options);
};
return BearerTokenFetchClient;
}(FetchClient));
exports.BearerTokenFetchClient = BearerTokenFetchClient;
class LambdaFetchClient extends BearerTokenFetchClient {
constructor(tokenFactory) {
super(null);
this.tokenFactory = tokenFactory;
var LambdaFetchClient = /** @class */ (function (_super) {
tslib_1.__extends(LambdaFetchClient, _super);
function LambdaFetchClient(tokenFactory) {
var _this = _super.call(this, null) || this;
_this.tokenFactory = tokenFactory;
return _this;
}

@@ -75,12 +84,19 @@ /**

*/
fetch(url, options) {
const _super = Object.create(null, {
fetch: { get: () => super.fetch }
LambdaFetchClient.prototype.fetch = function (url, options) {
return tslib_1.__awaiter(this, void 0, void 0, function () {
var _a;
return tslib_1.__generator(this, function (_b) {
switch (_b.label) {
case 0:
_a = this;
return [4 /*yield*/, this.tokenFactory({ url: url, options: options })];
case 1:
_a.token = _b.sent();
return [2 /*return*/, _super.prototype.fetch.call(this, url, options)];
}
});
});
return tslib_1.__awaiter(this, void 0, void 0, function* () {
this.token = yield this.tokenFactory({ url, options });
return _super.fetch.call(this, url, options);
});
}
}
};
return LambdaFetchClient;
}(BearerTokenFetchClient));
exports.LambdaFetchClient = LambdaFetchClient;

@@ -90,3 +106,4 @@ /**

*/
class SPFxAdalClient extends LambdaFetchClient {
var SPFxAdalClient = /** @class */ (function (_super) {
tslib_1.__extends(SPFxAdalClient, _super);
/**

@@ -96,8 +113,16 @@ *

*/
constructor(context) {
super((params) => tslib_1.__awaiter(this, void 0, void 0, function* () {
const provider = yield context.aadTokenProviderFactory.getTokenProvider();
return provider.getToken(getADALResource(params.url));
}));
this.context = context;
function SPFxAdalClient(context) {
var _this = _super.call(this, function (params) { return tslib_1.__awaiter(_this, void 0, void 0, function () {
var provider;
return tslib_1.__generator(this, function (_a) {
switch (_a.label) {
case 0: return [4 /*yield*/, context.aadTokenProviderFactory.getTokenProvider()];
case 1:
provider = _a.sent();
return [2 /*return*/, provider.getToken(getADALResource(params.url))];
}
});
}); }) || this;
_this.context = context;
return _this;
}

@@ -109,10 +134,18 @@ /**

*/
getToken(resource) {
return tslib_1.__awaiter(this, void 0, void 0, function* () {
const provider = yield this.context.aadTokenProviderFactory.getTokenProvider();
return provider.getToken(resource);
SPFxAdalClient.prototype.getToken = function (resource) {
return tslib_1.__awaiter(this, void 0, void 0, function () {
var provider;
return tslib_1.__generator(this, function (_a) {
switch (_a.label) {
case 0: return [4 /*yield*/, this.context.aadTokenProviderFactory.getTokenProvider()];
case 1:
provider = _a.sent();
return [2 /*return*/, provider.getToken(resource)];
}
});
});
}
}
};
return SPFxAdalClient;
}(LambdaFetchClient));
exports.SPFxAdalClient = SPFxAdalClient;
//# sourceMappingURL=net.js.map
{
"name": "@pnp/common-commonjs",
"version": "2.2.0",
"version": "2.3.0",
"description": "pnp - provides shared functionality across all pnp libraries",

@@ -5,0 +5,0 @@ "main": "./index.js",

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.PnPClientStorage = exports.PnPClientStorageWrapper = void 0;
const tslib_1 = require("tslib");
const util_js_1 = require("./util.js");
const libconfig_js_1 = require("./libconfig.js");
var tslib_1 = require("tslib");
var util_js_1 = require("./util.js");
var libconfig_js_1 = require("./libconfig.js");
/**

@@ -11,3 +11,3 @@ * A wrapper class to provide a consistent interface to browser based storage

*/
class PnPClientStorageWrapper {
var PnPClientStorageWrapper = /** @class */ (function () {
/**

@@ -18,3 +18,4 @@ * Creates a new instance of the PnPClientStorageWrapper class

*/
constructor(store, defaultTimeoutMinutes = -1) {
function PnPClientStorageWrapper(store, defaultTimeoutMinutes) {
if (defaultTimeoutMinutes === void 0) { defaultTimeoutMinutes = -1; }
this.store = store;

@@ -29,5 +30,5 @@ this.defaultTimeoutMinutes = defaultTimeoutMinutes;

}
static bind(store) {
PnPClientStorageWrapper.bind = function (store) {
return new PnPClientStorageWrapper(typeof (store) === "undefined" ? new MemoryStorage() : store);
}
};
/**

@@ -38,11 +39,11 @@ * Get a value from storage, or null if that value does not exist

*/
get(key) {
PnPClientStorageWrapper.prototype.get = function (key) {
if (!this.enabled) {
return null;
}
const o = this.store.getItem(key);
var o = this.store.getItem(key);
if (!util_js_1.objectDefinedNotNull(o)) {
return null;
}
const persistable = JSON.parse(o);
var persistable = JSON.parse(o);
if (new Date(persistable.expiration) <= new Date()) {

@@ -55,3 +56,3 @@ this.delete(key);

}
}
};
/**

@@ -64,7 +65,7 @@ * Adds a value to the underlying storage

*/
put(key, o, expire) {
PnPClientStorageWrapper.prototype.put = function (key, o, expire) {
if (this.enabled) {
this.store.setItem(key, this.createPersistable(o, expire));
}
}
};
/**

@@ -75,7 +76,7 @@ * Deletes a value from the underlying storage

*/
delete(key) {
PnPClientStorageWrapper.prototype.delete = function (key) {
if (this.enabled) {
this.store.removeItem(key);
}
}
};
/**

@@ -88,40 +89,61 @@ * Gets an item from the underlying storage, or adds it if it does not exist using the supplied getter function

*/
getOrPut(key, getter, expire) {
return tslib_1.__awaiter(this, void 0, void 0, function* () {
if (!this.enabled) {
return getter();
}
let o = this.get(key);
if (o === null) {
o = yield getter();
this.put(key, o, expire);
}
return o;
PnPClientStorageWrapper.prototype.getOrPut = function (key, getter, expire) {
return tslib_1.__awaiter(this, void 0, void 0, function () {
var o;
return tslib_1.__generator(this, function (_a) {
switch (_a.label) {
case 0:
if (!this.enabled) {
return [2 /*return*/, getter()];
}
o = this.get(key);
if (!(o === null)) return [3 /*break*/, 2];
return [4 /*yield*/, getter()];
case 1:
o = _a.sent();
this.put(key, o, expire);
_a.label = 2;
case 2: return [2 /*return*/, o];
}
});
});
}
};
/**
* Deletes any expired items placed in the store by the pnp library, leaves other items untouched
*/
deleteExpired() {
return tslib_1.__awaiter(this, void 0, void 0, function* () {
if (!this.enabled) {
return;
}
for (let i = 0; i < this.store.length; i++) {
const key = this.store.key(i);
if (key !== null) {
// test the stored item to see if we stored it
if (/["|']?pnp["|']? ?: ?1/i.test(this.store.getItem(key))) {
PnPClientStorageWrapper.prototype.deleteExpired = function () {
return tslib_1.__awaiter(this, void 0, void 0, function () {
var i, key;
return tslib_1.__generator(this, function (_a) {
switch (_a.label) {
case 0:
if (!this.enabled) {
return [2 /*return*/];
}
i = 0;
_a.label = 1;
case 1:
if (!(i < this.store.length)) return [3 /*break*/, 4];
key = this.store.key(i);
if (!(key !== null)) return [3 /*break*/, 3];
if (!/["|']?pnp["|']? ?: ?1/i.test(this.store.getItem(key))) return [3 /*break*/, 3];
// get those items as get will delete from cache if they are expired
yield this.get(key);
}
return [4 /*yield*/, this.get(key)];
case 2:
// get those items as get will delete from cache if they are expired
_a.sent();
_a.label = 3;
case 3:
i++;
return [3 /*break*/, 1];
case 4: return [2 /*return*/];
}
}
});
});
}
};
/**
* Used to determine if the wrapped storage is available currently
*/
test() {
const str = "t";
PnPClientStorageWrapper.prototype.test = function () {
var str = "t";
try {

@@ -135,10 +157,10 @@ this.store.setItem(str, str);

}
}
};
/**
* Creates the persistable to store
*/
createPersistable(o, expire) {
PnPClientStorageWrapper.prototype.createPersistable = function (o, expire) {
if (expire === undefined) {
// ensure we are by default inline with the global library setting
let defaultTimeout = libconfig_js_1.DefaultRuntime.get("defaultCachingTimeoutSeconds");
var defaultTimeout = libconfig_js_1.DefaultRuntime.get("defaultCachingTimeoutSeconds");
if (this.defaultTimeoutMinutes > 0) {

@@ -150,16 +172,18 @@ defaultTimeout = this.defaultTimeoutMinutes * 60;

return util_js_1.jsS({ pnp: 1, expiration: expire, value: o });
}
};
/**
* Deletes expired items added by this library in this.store and sets a timeout to call itself
*/
cacheExpirationHandler() {
PnPClientStorageWrapper.prototype.cacheExpirationHandler = function () {
var _this = this;
if (!this.enabled) {
return;
}
this.deleteExpired().then(() => {
this.deleteExpired().then(function () {
// call ourself in the future
setTimeout(util_js_1.getCtxCallback(this, this.cacheExpirationHandler), libconfig_js_1.DefaultRuntime.get("cacheExpirationIntervalMilliseconds"));
setTimeout(util_js_1.getCtxCallback(_this, _this.cacheExpirationHandler), libconfig_js_1.DefaultRuntime.get("cacheExpirationIntervalMilliseconds"));
}).catch(console.error);
}
}
};
return PnPClientStorageWrapper;
}());
exports.PnPClientStorageWrapper = PnPClientStorageWrapper;

@@ -169,29 +193,35 @@ /**

*/
class MemoryStorage {
constructor(_store = new Map()) {
var MemoryStorage = /** @class */ (function () {
function MemoryStorage(_store) {
if (_store === void 0) { _store = new Map(); }
this._store = _store;
}
get length() {
return this._store.size;
}
clear() {
Object.defineProperty(MemoryStorage.prototype, "length", {
get: function () {
return this._store.size;
},
enumerable: false,
configurable: true
});
MemoryStorage.prototype.clear = function () {
this._store.clear();
}
getItem(key) {
};
MemoryStorage.prototype.getItem = function (key) {
return this._store.get(key);
}
key(index) {
};
MemoryStorage.prototype.key = function (index) {
return Array.from(this._store)[index][0];
}
removeItem(key) {
};
MemoryStorage.prototype.removeItem = function (key) {
this._store.delete(key);
}
setItem(key, data) {
};
MemoryStorage.prototype.setItem = function (key, data) {
this._store.set(key, data);
}
}
};
return MemoryStorage;
}());
/**
* A class that will establish wrappers for both local and session storage
*/
class PnPClientStorage {
var PnPClientStorage = /** @class */ (function () {
/**

@@ -202,26 +232,37 @@ * Creates a new instance of the PnPClientStorage class

*/
constructor(_local = null, _session = null) {
function PnPClientStorage(_local, _session) {
if (_local === void 0) { _local = null; }
if (_session === void 0) { _session = null; }
this._local = _local;
this._session = _session;
}
/**
* Provides access to the local storage of the browser
*/
get local() {
if (this._local === null) {
this._local = new PnPClientStorageWrapper(typeof (localStorage) === "undefined" ? new MemoryStorage() : localStorage);
}
return this._local;
}
/**
* Provides access to the session storage of the browser
*/
get session() {
if (this._session === null) {
this._session = new PnPClientStorageWrapper(typeof (sessionStorage) === "undefined" ? new MemoryStorage() : sessionStorage);
}
return this._session;
}
}
Object.defineProperty(PnPClientStorage.prototype, "local", {
/**
* Provides access to the local storage of the browser
*/
get: function () {
if (this._local === null) {
this._local = new PnPClientStorageWrapper(typeof (localStorage) === "undefined" ? new MemoryStorage() : localStorage);
}
return this._local;
},
enumerable: false,
configurable: true
});
Object.defineProperty(PnPClientStorage.prototype, "session", {
/**
* Provides access to the session storage of the browser
*/
get: function () {
if (this._session === null) {
this._session = new PnPClientStorageWrapper(typeof (sessionStorage) === "undefined" ? new MemoryStorage() : sessionStorage);
}
return this._session;
},
enumerable: false,
configurable: true
});
return PnPClientStorage;
}());
exports.PnPClientStorage = PnPClientStorage;
//# sourceMappingURL=storage.js.map

@@ -13,3 +13,7 @@ "use strict";

// eslint-disable-next-line @typescript-eslint/ban-types
function getCtxCallback(context, method, ...params) {
function getCtxCallback(context, method) {
var params = [];
for (var _i = 2; _i < arguments.length; _i++) {
params[_i - 2] = arguments[_i];
}
return function () {

@@ -30,3 +34,3 @@ method.apply(context, params);

function dateAdd(date, interval, units) {
let ret = new Date(date.toString()); // don't change original date
var ret = new Date(date.toString()); // don't change original date
switch (interval.toLowerCase()) {

@@ -69,6 +73,10 @@ case "year":

*/
function combine(...paths) {
function combine() {
var paths = [];
for (var _i = 0; _i < arguments.length; _i++) {
paths[_i] = arguments[_i];
}
return paths
.filter(path => !stringIsNullOrEmpty(path))
.map(path => path.replace(/^[\\|/]/, "").replace(/[\\|/]$/, ""))
.filter(function (path) { return !stringIsNullOrEmpty(path); })
.map(function (path) { return path.replace(/^[\\|/]/, "").replace(/[\\|/]$/, ""); })
.join("/")

@@ -86,4 +94,4 @@ .replace(/\\/g, "/");

function getRandomString(chars) {
const text = new Array(chars);
for (let i = 0; i < chars; i++) {
var text = new Array(chars);
for (var i = 0; i < chars; i++) {
text[i] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789".charAt(Math.floor(Math.random() * 62));

@@ -101,5 +109,5 @@ }

function getGUID() {
let d = Date.now();
var d = Date.now();
return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, function (c) {
const r = (d + Math.random() * 16) % 16 | 0;
var r = (d + Math.random() * 16) % 16 | 0;
d = Math.floor(d / 16);

@@ -144,3 +152,5 @@ return (c === "x" ? r : (r & 0x3 | 0x8)).toString(16);

*/
function assign(target, source, noOverwrite = false, filter = () => true) {
function assign(target, source, noOverwrite, filter) {
if (noOverwrite === void 0) { noOverwrite = false; }
if (filter === void 0) { filter = function () { return true; }; }
if (!objectDefinedNotNull(source)) {

@@ -150,8 +160,8 @@ return target;

// ensure we don't overwrite things we don't want overwritten
const check = noOverwrite ? (o, i) => !(i in o) : () => true;
var check = noOverwrite ? function (o, i) { return !(i in o); } : function () { return true; };
// final filter we will use
const f = (v) => check(target, v) && filter(v);
var f = function (v) { return check(target, v) && filter(v); };
return Object.getOwnPropertyNames(source)
.filter(f)
.reduce((t, v) => {
.reduce(function (t, v) {
t[v] = source[v];

@@ -189,3 +199,3 @@ return t;

}
const matches = /([0-9A-F]{8}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{12})/i.exec(guid);
var matches = /([0-9A-F]{8}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{12})/i.exec(guid);
return matches === null ? guid : matches[1];

@@ -220,8 +230,8 @@ }

function getHashCode(s) {
let hash = 0;
var hash = 0;
if (s.length === 0) {
return hash;
}
for (let i = 0; i < s.length; i++) {
const chr = s.charCodeAt(i);
for (var i = 0; i < s.length; i++) {
var chr = s.charCodeAt(i);
hash = ((hash << 5) - hash) + chr;

@@ -228,0 +238,0 @@ hash |= 0; // Convert to 32bit integer

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc