Socket
Socket
Sign inDemoInstall

@pnp/common

Package Overview
Dependencies
Maintainers
13
Versions
155
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@pnp/common - npm Package Compare versions

Comparing version 2.2.0 to 2.3.0

12

collections.js

@@ -5,3 +5,3 @@ import { isFunc, objectDefinedNotNull } from "./util.js";

*/
const objectEntries = isFunc(Object.entries) ? Object.entries : (o) => Object.keys(o).map((k) => [k, o[k]]);
var objectEntries = isFunc(Object.entries) ? Object.entries : function (o) { return Object.keys(o).map(function (k) { return [k, o[k]]; }); };
/**

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

*/
export function mergeMaps(target, ...maps) {
for (let i = 0; i < maps.length; i++) {
maps[i].forEach((v, k) => {
export 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 :)

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

@@ -0,7 +1,9 @@

import { __read, __values } from "tslib";
import { mergeMaps, objectToMap } from "./collections.js";
export function setup(config, runtime = DefaultRuntime) {
export function setup(config, runtime) {
if (runtime === void 0) { runtime = DefaultRuntime; }
runtime.assign(config);
}
// lable mapping for known config values
const s = [
var s = [
"defaultCachingStore",

@@ -15,3 +17,3 @@ "defaultCachingTimeoutSeconds",

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

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

}
export 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);
}

@@ -41,3 +45,3 @@ };

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

@@ -48,5 +52,5 @@ /**

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

@@ -57,21 +61,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 = __values(this._v), _c = _b.next(); !_c.done; _c = _b.next()) {
var _d = __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;
}());
export { Runtime };
// default runtime used globally
const _runtime = new Runtime(new Map([["__isDefault__", true]]));
export const DefaultRuntime = _runtime;
var _runtime = new Runtime(new Map([["__isDefault__", true]]));
export var DefaultRuntime = _runtime;
//# sourceMappingURL=libconfig.js.map

@@ -1,2 +0,2 @@

import { __awaiter } from "tslib";
import { __awaiter, __extends, __generator } from "tslib";
import { assign, objectDefinedNotNull } from "./util.js";

@@ -6,4 +6,4 @@ import { safeGlobal } from "./safe-global.js";

if (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);

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

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

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

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

@@ -34,28 +34,39 @@ /**

*/
export class FetchClient {
fetch(url, options) {
var FetchClient = /** @class */ (function () {
function FetchClient() {
}
FetchClient.prototype.fetch = function (url, options) {
return safeGlobal.fetch(url, options);
}
}
};
return FetchClient;
}());
export { FetchClient };
/**
* Makes requests using the fetch API adding the supplied token to the Authorization header
*/
export class BearerTokenFetchClient extends FetchClient {
constructor(token) {
super();
this.token = token;
var BearerTokenFetchClient = /** @class */ (function (_super) {
__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));
export { BearerTokenFetchClient };
var LambdaFetchClient = /** @class */ (function (_super) {
__extends(LambdaFetchClient, _super);
function LambdaFetchClient(tokenFactory) {
var _this = _super.call(this, null) || this;
_this.tokenFactory = tokenFactory;
return _this;
}
}
export class LambdaFetchClient extends BearerTokenFetchClient {
constructor(tokenFactory) {
super(null);
this.tokenFactory = tokenFactory;
}
/**

@@ -67,16 +78,25 @@ * Executes a fetch request using the supplied url and options

*/
fetch(url, options) {
const _super = Object.create(null, {
fetch: { get: () => super.fetch }
LambdaFetchClient.prototype.fetch = function (url, options) {
return __awaiter(this, void 0, void 0, function () {
var _a;
return __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 __awaiter(this, void 0, void 0, function* () {
this.token = yield this.tokenFactory({ url, options });
return _super.fetch.call(this, url, options);
});
}
}
};
return LambdaFetchClient;
}(BearerTokenFetchClient));
export { LambdaFetchClient };
/**
* Client wrapping the aadTokenProvider available from SPFx >= 1.6
*/
export class SPFxAdalClient extends LambdaFetchClient {
var SPFxAdalClient = /** @class */ (function (_super) {
__extends(SPFxAdalClient, _super);
/**

@@ -86,8 +106,16 @@ *

*/
constructor(context) {
super((params) => __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 __awaiter(_this, void 0, void 0, function () {
var provider;
return __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;
}

@@ -99,9 +127,18 @@ /**

*/
getToken(resource) {
return __awaiter(this, void 0, void 0, function* () {
const provider = yield this.context.aadTokenProviderFactory.getTokenProvider();
return provider.getToken(resource);
SPFxAdalClient.prototype.getToken = function (resource) {
return __awaiter(this, void 0, void 0, function () {
var provider;
return __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));
export { SPFxAdalClient };
//# sourceMappingURL=net.js.map
{
"name": "@pnp/common",
"version": "2.2.0",
"version": "2.3.0",
"description": "pnp - provides shared functionality across all pnp libraries",

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

// export either window or global
export const safeGlobal = typeof global === "undefined" ? window : global;
export var safeGlobal = typeof global === "undefined" ? window : global;
//# sourceMappingURL=safe-global.js.map

@@ -1,2 +0,2 @@

import { __awaiter } from "tslib";
import { __awaiter, __generator } from "tslib";
import { dateAdd, getCtxCallback, jsS, objectDefinedNotNull } from "./util.js";

@@ -8,3 +8,3 @@ import { DefaultRuntime } from "./libconfig.js";

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

@@ -15,3 +15,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;

@@ -26,5 +27,5 @@ this.defaultTimeoutMinutes = defaultTimeoutMinutes;

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

@@ -35,11 +36,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 (!objectDefinedNotNull(o)) {
return null;
}
const persistable = JSON.parse(o);
var persistable = JSON.parse(o);
if (new Date(persistable.expiration) <= new Date()) {

@@ -52,3 +53,3 @@ this.delete(key);

}
}
};
/**

@@ -61,7 +62,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));
}
}
};
/**

@@ -72,7 +73,7 @@ * Deletes a value from the underlying storage

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

@@ -85,40 +86,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 __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 __awaiter(this, void 0, void 0, function () {
var o;
return __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 __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 __awaiter(this, void 0, void 0, function () {
var i, key;
return __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 {

@@ -132,10 +154,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 = DefaultRuntime.get("defaultCachingTimeoutSeconds");
var defaultTimeout = DefaultRuntime.get("defaultCachingTimeoutSeconds");
if (this.defaultTimeoutMinutes > 0) {

@@ -147,46 +169,55 @@ defaultTimeout = this.defaultTimeoutMinutes * 60;

return 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(getCtxCallback(this, this.cacheExpirationHandler), DefaultRuntime.get("cacheExpirationIntervalMilliseconds"));
setTimeout(getCtxCallback(_this, _this.cacheExpirationHandler), DefaultRuntime.get("cacheExpirationIntervalMilliseconds"));
}).catch(console.error);
}
}
};
return PnPClientStorageWrapper;
}());
export { PnPClientStorageWrapper };
/**
* A thin implementation of in-memory storage for use in nodejs
*/
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
*/
export class PnPClientStorage {
var PnPClientStorage = /** @class */ (function () {
/**

@@ -197,25 +228,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;
}());
export { PnPClientStorage };
//# sourceMappingURL=storage.js.map

@@ -10,3 +10,7 @@ /**

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

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

export 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()) {

@@ -64,6 +68,10 @@ case "year":

*/
export function combine(...paths) {
export 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("/")

@@ -80,4 +88,4 @@ .replace(/\\/g, "/");

export 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));

@@ -94,5 +102,5 @@ }

export 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);

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

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

@@ -139,8 +149,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];

@@ -175,3 +185,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];

@@ -203,8 +213,8 @@ }

export 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;

@@ -211,0 +221,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

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