New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

gl-sp-frontend

Package Overview
Dependencies
Maintainers
1
Versions
60
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

gl-sp-frontend - npm Package Compare versions

Comparing version 5.0.0 to 6.0.0

0

lib/bundle.d.ts

@@ -0,0 +0,0 @@ export * from './core/services/setup/core-services-setup.service';

@@ -0,0 +0,0 @@ export * from './core/services/setup/core-services-setup.service';

@@ -0,0 +0,0 @@ import { IDeferred, IMetadata } from '../../../bundle';

export {};
//# sourceMappingURL=core-services-list-items.interface.js.map

@@ -0,0 +0,0 @@ import { IAttachment, IAttachmentAddResult, IAttachmentFileInfo, IAttachmentInfo } from '@pnp/sp/attachments/index';

435

lib/core/services/list-items/core-services-list-items.service.js

@@ -1,10 +0,1 @@

var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
import { SpCore } from '../setup/core-services-setup.service';

@@ -19,117 +10,105 @@ import { sp } from '@pnp/sp/presets/core';

}
retrieve(listName, fieldsArray = [], baseUrl) {
return __awaiter(this, void 0, void 0, function* () {
const fields = this.fieldsToStringArray(fieldsArray);
const base = baseUrl == null ? SpCore.baseUrl : baseUrl;
try {
return yield sp.configure(SpCore.config, base).web.lists.getByTitle(listName).items.select(fields).getAll();
}
catch (reason) {
const error = SpCore.onError(reason);
SpCore.showErrorLog(reason);
throw new Error(error.code.toString());
}
});
async retrieve(listName, fieldsArray = [], baseUrl) {
const fields = this.fieldsToStringArray(fieldsArray);
const base = baseUrl == null ? SpCore.baseUrl : baseUrl;
try {
return await sp.configure(SpCore.config, base).web.lists.getByTitle(listName).items.select(fields).getAll();
}
catch (reason) {
const error = SpCore.onError(reason);
SpCore.showErrorLog(reason);
throw new Error(error.code.toString());
}
}
retrieveExternal(listName, fieldsArray = [], baseUrl, top = 0) {
return __awaiter(this, void 0, void 0, function* () {
const fields = this.fieldsToStringArray(fieldsArray);
try {
const listUrl = encodeURI(`${baseUrl}/_api/web/lists/GetByTitle('${listName}')?$select=ItemCount`);
let count = top;
if (top == null || top === 0) {
const result = yield fetch(listUrl, yield SpCore.fetchHeader());
const list = yield result.json();
count = yield list.d.ItemCount;
}
const itemsUrl = encodeURI(`${baseUrl}/_api/web/lists/GetByTitle('${listName}')/items?$select=${fields}&$top=${count}`);
const resultItems = yield fetch(itemsUrl, yield SpCore.fetchHeader());
const fetchItems = yield resultItems.json();
return fetchItems.d.results;
async retrieveExternal(listName, fieldsArray = [], baseUrl, top = 0) {
const fields = this.fieldsToStringArray(fieldsArray);
try {
const listUrl = encodeURI(`${baseUrl}/_api/web/lists/GetByTitle('${listName}')?$select=ItemCount`);
let count = top;
if (top == null || top === 0) {
const result = await fetch(listUrl, await SpCore.fetchHeader());
const list = await result.json();
count = await list.d.ItemCount;
}
catch (reason) {
SpCore.showErrorLog(reason);
return [];
}
});
const itemsUrl = encodeURI(`${baseUrl}/_api/web/lists/GetByTitle('${listName}')/items?$select=${fields}&$top=${count}`);
const resultItems = await fetch(itemsUrl, await SpCore.fetchHeader());
const fetchItems = await resultItems.json();
return fetchItems.d.results;
}
catch (reason) {
SpCore.showErrorLog(reason);
return [];
}
}
retrieveExternalSingle(id, listName, fieldsArray = [], baseUrl) {
return __awaiter(this, void 0, void 0, function* () {
const fields = this.fieldsToStringArray(fieldsArray);
try {
const itemsUrl = encodeURI(`${baseUrl}/_api/web/lists/GetByTitle('${listName}')/items(${id})?$select=${fields}`);
const resultItems = yield fetch(itemsUrl, yield SpCore.fetchHeader());
const fetchItems = yield resultItems.json();
return fetchItems.d;
}
catch (reason) {
SpCore.showErrorLog(reason);
return [];
}
});
async retrieveExternalSingle(id, listName, fieldsArray = [], baseUrl) {
const fields = this.fieldsToStringArray(fieldsArray);
try {
const itemsUrl = encodeURI(`${baseUrl}/_api/web/lists/GetByTitle('${listName}')/items(${id})?$select=${fields}`);
const resultItems = await fetch(itemsUrl, await SpCore.fetchHeader());
const fetchItems = await resultItems.json();
return fetchItems.d;
}
catch (reason) {
SpCore.showErrorLog(reason);
return [];
}
}
retrieveForCombobox(listName, baseUrl, valueField = 'value', textField = 'text') {
return __awaiter(this, void 0, void 0, function* () {
try {
const items = [];
if (listName != null && listName.length > 0) {
const fields = [valueField, textField];
try {
const itemsResult = yield this.retrieve(listName, fields, baseUrl);
for (const item of itemsResult) {
items.push({
text: item[textField],
value: item[valueField].toString()
});
}
return items;
async retrieveForCombobox(listName, baseUrl, valueField = 'value', textField = 'text') {
try {
const items = [];
if (listName != null && listName.length > 0) {
const fields = [valueField, textField];
try {
const itemsResult = await this.retrieve(listName, fields, baseUrl);
for (const item of itemsResult) {
items.push({
text: item[textField],
value: item[valueField].toString()
});
}
catch (reason) {
SpCore.showErrorLog(reason);
return reason;
}
return items;
}
else {
return [];
catch (reason) {
SpCore.showErrorLog(reason);
return reason;
}
}
catch (reason) {
SpCore.showErrorLog(reason);
return reason;
else {
return [];
}
});
}
catch (reason) {
SpCore.showErrorLog(reason);
return reason;
}
}
retrieveExternalForCombobox(listName, baseUrl, valueField = 'value', textField = 'text', top = 0) {
return __awaiter(this, void 0, void 0, function* () {
try {
const fields = [valueField, textField];
const listItems = yield this.retrieveExternal(listName, fields, baseUrl, top);
const comboBox = [];
for (const item of listItems) {
comboBox.push({
text: item[textField],
value: item[valueField].toString()
});
}
return comboBox;
async retrieveExternalForCombobox(listName, baseUrl, valueField = 'value', textField = 'text', top = 0) {
try {
const fields = [valueField, textField];
const listItems = await this.retrieveExternal(listName, fields, baseUrl, top);
const comboBox = [];
for (const item of listItems) {
comboBox.push({
text: item[textField],
value: item[valueField].toString()
});
}
catch (reason) {
SpCore.showErrorLog(reason);
return reason;
}
});
return comboBox;
}
catch (reason) {
SpCore.showErrorLog(reason);
return reason;
}
}
retrieveSingle(listItemId, listName, fieldsArray = [], baseUrl) {
return __awaiter(this, void 0, void 0, function* () {
const fields = this.fieldsToStringArray(fieldsArray);
const base = baseUrl == null ? SpCore.baseUrl : baseUrl;
try {
return yield sp.configure(SpCore.config, base).web.lists.getByTitle(listName).items.getById(listItemId).select(fields).get();
}
catch (reason) {
const error = SpCore.onError(reason);
SpCore.showErrorLog(reason);
throw new Error(error.code.toString());
}
});
async retrieveSingle(listItemId, listName, fieldsArray = [], baseUrl) {
const fields = this.fieldsToStringArray(fieldsArray);
const base = baseUrl == null ? SpCore.baseUrl : baseUrl;
try {
return await sp.configure(SpCore.config, base).web.lists.getByTitle(listName).items.getById(listItemId).select(fields).get();
}
catch (reason) {
const error = SpCore.onError(reason);
SpCore.showErrorLog(reason);
throw new Error(error.code.toString());
}
}

@@ -148,21 +127,19 @@ recycle(listItemId, listName, baseUrl) {

}
recycleDuplicated(listName, field, baseUrl) {
return __awaiter(this, void 0, void 0, function* () {
const base = baseUrl == null ? SpCore.baseUrl : baseUrl;
try {
const data = yield this.retrieve(listName, ['Id', field], base);
const duplicates = yield ArrayRemove.notDuplicatedByKey(data, field, field, true);
for (const duplicate of duplicates) {
const items = data.filter(x => x[field] === duplicate);
for (let i = 1; i < items.length; i++) {
yield this.recycle(items[i].Id, listName, base);
}
async recycleDuplicated(listName, field, baseUrl) {
const base = baseUrl == null ? SpCore.baseUrl : baseUrl;
try {
const data = await this.retrieve(listName, ['Id', field], base);
const duplicates = await ArrayRemove.notDuplicatedByKey(data, field, field, true);
for (const duplicate of duplicates) {
const items = data.filter(x => x[field] === duplicate);
for (let i = 1; i < items.length; i++) {
await this.recycle(items[i].Id, listName, base);
}
return duplicates;
}
catch (reason) {
SpCore.showErrorLog(reason);
return [];
}
});
return duplicates;
}
catch (reason) {
SpCore.showErrorLog(reason);
return [];
}
}

@@ -181,33 +158,29 @@ delete(listItemId, listName, baseUrl) {

}
deleteDuplicated(listName, field, baseUrl) {
return __awaiter(this, void 0, void 0, function* () {
const base = baseUrl == null ? SpCore.baseUrl : baseUrl;
try {
const data = yield this.retrieve(listName, ['Id', field], base);
const duplicates = yield ArrayRemove.notDuplicatedByKey(data, field, field, true);
for (const duplicate of duplicates) {
const items = data.filter(x => x[field] === duplicate);
for (let i = 1; i < items.length; i++) {
yield this.delete(items[i].Id, listName, base);
}
async deleteDuplicated(listName, field, baseUrl) {
const base = baseUrl == null ? SpCore.baseUrl : baseUrl;
try {
const data = await this.retrieve(listName, ['Id', field], base);
const duplicates = await ArrayRemove.notDuplicatedByKey(data, field, field, true);
for (const duplicate of duplicates) {
const items = data.filter(x => x[field] === duplicate);
for (let i = 1; i < items.length; i++) {
await this.delete(items[i].Id, listName, base);
}
return duplicates;
}
catch (reason) {
SpCore.showErrorLog(reason);
return [];
}
});
return duplicates;
}
catch (reason) {
SpCore.showErrorLog(reason);
return [];
}
}
add(listName, data, baseUrl) {
return __awaiter(this, void 0, void 0, function* () {
const base = baseUrl == null ? SpCore.baseUrl : baseUrl;
try {
return yield sp.configure(SpCore.config, base).web.lists.getByTitle(listName).items.add(data);
}
catch (reason) {
SpCore.showErrorLog(reason);
throw new Error(reason);
}
});
async add(listName, data, baseUrl) {
const base = baseUrl == null ? SpCore.baseUrl : baseUrl;
try {
return await sp.configure(SpCore.config, base).web.lists.getByTitle(listName).items.add(data);
}
catch (reason) {
SpCore.showErrorLog(reason);
throw new Error(reason);
}
}

@@ -267,82 +240,74 @@ update(listItemId, listName, data, baseUrl) {

}
retrieveBlob(listItemId, listName, fileName, baseUrl) {
return __awaiter(this, void 0, void 0, function* () {
const base = baseUrl == null ? SpCore.baseUrl : baseUrl;
try {
async retrieveBlob(listItemId, listName, fileName, baseUrl) {
const base = baseUrl == null ? SpCore.baseUrl : baseUrl;
try {
const item = sp.configure(SpCore.config, base).web.lists.getByTitle(listName).items.getById(listItemId);
return await item.attachmentFiles.getByName(fileName).getBlob();
}
catch (reason) {
SpCore.showErrorLog(reason);
return null;
}
}
async retrieveMultipleBlobSameItem(listItemId, listName, fileNames, baseUrl) {
const base = baseUrl == null ? SpCore.baseUrl : baseUrl;
const blobs = [];
try {
for (const fileName of fileNames) {
const item = sp.configure(SpCore.config, base).web.lists.getByTitle(listName).items.getById(listItemId);
return yield item.attachmentFiles.getByName(fileName).getBlob();
blobs.push({
fileName,
file: await item.attachmentFiles.getByName(fileName).getBlob(),
icon: AttachmentIcon.get(fileName)
});
}
catch (reason) {
SpCore.showErrorLog(reason);
return null;
}
});
return blobs;
}
catch (reason) {
SpCore.showErrorLog(reason);
return [];
}
}
retrieveMultipleBlobSameItem(listItemId, listName, fileNames, baseUrl) {
return __awaiter(this, void 0, void 0, function* () {
const base = baseUrl == null ? SpCore.baseUrl : baseUrl;
const blobs = [];
try {
for (const fileName of fileNames) {
const item = sp.configure(SpCore.config, base).web.lists.getByTitle(listName).items.getById(listItemId);
blobs.push({
fileName,
file: yield item.attachmentFiles.getByName(fileName).getBlob(),
icon: AttachmentIcon.get(fileName)
});
}
return blobs;
async retrieveMultipleBlob(data, baseUrl) {
const base = baseUrl == null ? SpCore.baseUrl : baseUrl;
const blobs = [];
try {
for (const content of data) {
const item = sp.configure(SpCore.config, base).web.lists.getByTitle(content.listName).items.getById(content.id);
blobs.push({
fileName: content.fileName,
file: await item.attachmentFiles.getByName(content.fileName).getBlob(),
icon: AttachmentIcon.get(content.fileName)
});
}
catch (reason) {
SpCore.showErrorLog(reason);
return [];
}
});
return blobs;
}
catch (reason) {
SpCore.showErrorLog(reason);
return [];
}
}
retrieveMultipleBlob(data, baseUrl) {
return __awaiter(this, void 0, void 0, function* () {
const base = baseUrl == null ? SpCore.baseUrl : baseUrl;
const blobs = [];
try {
for (const content of data) {
const item = sp.configure(SpCore.config, base).web.lists.getByTitle(content.listName).items.getById(content.id);
blobs.push({
fileName: content.fileName,
file: yield item.attachmentFiles.getByName(content.fileName).getBlob(),
icon: AttachmentIcon.get(content.fileName)
});
}
return blobs;
}
catch (reason) {
SpCore.showErrorLog(reason);
return [];
}
});
async retrieveForBinding(listItemId, listName, baseUrl) {
let base = baseUrl == null ? SpCore.baseUrl : baseUrl;
if (!base.includes('http')) {
base = 'http://' + base;
}
const attachmentList = await this.retrieve(listItemId, listName, base);
const attachments = [];
for (const attachment of attachmentList) {
const host = base.split('://')[0] + '://' + base.split('://')[1].split('/')[0];
const serverRelativeUrl = attachment.ServerRelativeUrl;
const url = encodeURI(host + serverRelativeUrl);
const file = {
id: attachments.length,
new: false,
remove: false,
name: attachment.FileName,
url,
icon: AttachmentIcon.get(attachment.FileName)
};
attachments.push(file);
}
return attachments;
}
retrieveForBinding(listItemId, listName, baseUrl) {
return __awaiter(this, void 0, void 0, function* () {
let base = baseUrl == null ? SpCore.baseUrl : baseUrl;
if (!base.includes('http')) {
base = 'http://' + base;
}
const attachmentList = yield this.retrieve(listItemId, listName, base);
const attachments = [];
for (const attachment of attachmentList) {
const host = base.split('://')[0] + '://' + base.split('://')[1].split('/')[0];
const serverRelativeUrl = attachment.ServerRelativeUrl;
const url = encodeURI(host + serverRelativeUrl);
const file = {
id: attachments.length,
new: false,
remove: false,
name: attachment.FileName,
url,
icon: AttachmentIcon.get(attachment.FileName)
};
attachments.push(file);
}
return attachments;
});
}
retrieveTxtContent(listItemId, listName, fileName = 'attachment', baseUrl) {

@@ -389,3 +354,3 @@ const base = baseUrl == null ? SpCore.baseUrl : baseUrl;

const fields = fieldsArray.toString().replace('[', '').replace(']', '');
return new Promise((resolve, reject) => __awaiter(this, void 0, void 0, function* () {
return new Promise(async (resolve, reject) => {
sp.configure(SpCore.config, base).web.lists.getByTitle(listName).items

@@ -403,3 +368,3 @@ .orderBy(orderBy, ascending)

});
}));
});
}

@@ -409,3 +374,3 @@ retrieveSearchLimited(listName, fieldsArray = [], maxItems = 100, filter = '', orderBy = 'ID', ascending = true, baseUrl) {

const fields = fieldsArray.toString().replace('[', '').replace(']', '');
return new Promise((resolve, reject) => __awaiter(this, void 0, void 0, function* () {
return new Promise(async (resolve, reject) => {
sp.configure(SpCore.config, base).web.lists.getByTitle(listName).items

@@ -424,3 +389,3 @@ .orderBy(orderBy, ascending)

});
}));
});
}

@@ -427,0 +392,0 @@ }

@@ -0,0 +0,0 @@ import { FieldTypes } from '@pnp/sp/fields/index';

export {};
//# sourceMappingURL=core-services-lists.interface.js.map

@@ -0,0 +0,0 @@ import { IListInfo } from '@pnp/sp/presets/core';

@@ -1,10 +0,1 @@

var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
import { SpCore } from '../setup/core-services-setup.service';

@@ -21,95 +12,43 @@ import { sp } from '@pnp/sp/presets/core';

}
exists(listName, baseUrl) {
return __awaiter(this, void 0, void 0, function* () {
const base = baseUrl == null ? SpCore.baseUrl : baseUrl;
try {
const lists = yield this.retrieve(listName, base);
return lists.filter(x => x.Title === listName).length > 0;
}
catch (reason) {
const error = SpCore.onError(reason);
SpCore.showErrorLog(reason);
throw new Error(error.code.toString());
}
});
async exists(listName, baseUrl) {
const base = baseUrl == null ? SpCore.baseUrl : baseUrl;
try {
const lists = await this.retrieve(listName, base);
return lists.filter(x => x.Title === listName).length > 0;
}
catch (reason) {
const error = SpCore.onError(reason);
SpCore.showErrorLog(reason);
throw new Error(error.code.toString());
}
}
retrieveSingle(listName, baseUrl) {
return __awaiter(this, void 0, void 0, function* () {
const base = baseUrl == null ? SpCore.baseUrl : baseUrl;
try {
return yield sp.configure(SpCore.config, base).web.lists.getByTitle(listName).get();
}
catch (reason) {
const error = SpCore.onError(reason);
SpCore.showErrorLog(reason);
throw new Error(error.code.toString());
}
});
async retrieveSingle(listName, baseUrl) {
const base = baseUrl == null ? SpCore.baseUrl : baseUrl;
try {
return await sp.configure(SpCore.config, base).web.lists.getByTitle(listName).get();
}
catch (reason) {
const error = SpCore.onError(reason);
SpCore.showErrorLog(reason);
throw new Error(error.code.toString());
}
}
retrieve(listName, baseUrl) {
return __awaiter(this, void 0, void 0, function* () {
const base = baseUrl == null ? SpCore.baseUrl : baseUrl;
try {
return yield sp.configure(SpCore.config, base).web.lists.get();
}
catch (reason) {
const error = SpCore.onError(reason);
SpCore.showErrorLog(reason);
throw new Error(error.code.toString());
}
});
async retrieve(listName, baseUrl) {
const base = baseUrl == null ? SpCore.baseUrl : baseUrl;
try {
return await sp.configure(SpCore.config, base).web.lists.get();
}
catch (reason) {
const error = SpCore.onError(reason);
SpCore.showErrorLog(reason);
throw new Error(error.code.toString());
}
}
recycle(listName, baseUrl) {
return __awaiter(this, void 0, void 0, function* () {
const base = baseUrl == null ? SpCore.baseUrl : baseUrl;
try {
const exists = yield this.exists(listName, base);
if (exists) {
yield sp.configure(SpCore.config, base).web.lists.getByTitle(listName).recycle();
return {
code: 200,
description: 'Success!',
message: 'The current list has been recycled.'
};
}
else {
return {
code: 503,
description: 'Internal Error!',
message: 'The current list doesn\'t exist.'
};
}
}
catch (reason) {
SpCore.showErrorLog(reason);
async recycle(listName, baseUrl) {
const base = baseUrl == null ? SpCore.baseUrl : baseUrl;
try {
const exists = await this.exists(listName, base);
if (exists) {
await sp.configure(SpCore.config, base).web.lists.getByTitle(listName).recycle();
return {
code: 500,
description: 'Internal Error!',
message: reason.message
};
}
});
}
recreate(listName, baseUrl, fields = [], titleRequired = true, properties) {
return __awaiter(this, void 0, void 0, function* () {
const base = baseUrl == null ? SpCore.baseUrl : baseUrl;
const listProperties = properties != null ? properties : {
AllowContentTypes: true,
BaseTemplate: 100,
BaseType: 0,
ContentTypesEnabled: false,
EnableAttachments: true,
DocumentTemplateUrl: undefined,
EnableVersioning: true,
Description: ''
};
try {
yield this.recycle(listName, baseUrl);
yield sp.configure(SpCore.config, base).web.lists.add(listName, listProperties.Description, listProperties.BaseTemplate, false, listProperties);
yield sp.configure(SpCore.config, base).web.lists.getByTitle(listName).fields.getByTitle('Title').update({
Required: titleRequired,
__metadata: { type: 'SP.FieldText' }
});
yield this.addFields(listName, fields, base);
return {
code: 200,

@@ -120,112 +59,150 @@ description: 'Success!',

}
catch (reason) {
SpCore.showErrorLog(reason);
else {
return {
code: 500,
code: 503,
description: 'Internal Error!',
message: reason.message
message: 'The current list doesn\'t exist.'
};
}
});
}
catch (reason) {
SpCore.showErrorLog(reason);
return {
code: 500,
description: 'Internal Error!',
message: reason.message
};
}
}
addFields(listName, fields, baseUrl) {
return __awaiter(this, void 0, void 0, function* () {
const base = baseUrl == null ? SpCore.baseUrl : baseUrl;
try {
for (const [i, field] of fields.entries()) {
const title = field.Title == null ? `Column${i + 1}` : field.Title;
const required = field.Required == null ? false : field.Required;
const indexed = field.Indexed == null ? false : field.Indexed;
const defaultBooleanValue = field.DefaultValue == null ? '0' : field.DefaultValue;
switch (field.FieldTypeKind) {
case FieldTypes.Text:
yield sp.configure(SpCore.config, base).web.lists.getByTitle(listName).fields.addText(title, undefined, {
Required: required,
Indexed: indexed
});
break;
case FieldTypes.Note:
yield sp.configure(SpCore.config, base).web.lists.getByTitle(listName).fields.addMultilineText(title, 6, false, false, false, false, {
Required: required,
Indexed: indexed
});
break;
case FieldTypes.Boolean:
yield sp.configure(SpCore.config, base).web.lists.getByTitle(listName).fields.addBoolean(title, {
Required: required,
Indexed: indexed,
DefaultValue: defaultBooleanValue
});
break;
case FieldTypes.Number:
yield sp.configure(SpCore.config, base).web.lists.getByTitle(listName).fields.addNumber(title, undefined, undefined, {
Required: required,
Indexed: indexed,
DefaultValue: defaultBooleanValue
});
break;
case FieldTypes.DateTime:
yield sp.configure(SpCore.config, base).web.lists.getByTitle(listName).fields.addDateTime(title, DateTimeFieldFormatType.DateOnly, CalendarType.Gregorian, DateTimeFieldFriendlyFormatType.Disabled, {
Required: required,
Indexed: indexed,
DefaultValue: defaultBooleanValue
});
break;
}
yield sp.configure(SpCore.config, base).web.lists.getByTitle(listName).defaultView.fields.add(title);
async recreate(listName, baseUrl, fields = [], titleRequired = true, properties) {
const base = baseUrl == null ? SpCore.baseUrl : baseUrl;
const listProperties = properties != null ? properties : {
AllowContentTypes: true,
BaseTemplate: 100,
BaseType: 0,
ContentTypesEnabled: false,
EnableAttachments: true,
DocumentTemplateUrl: undefined,
EnableVersioning: true,
Description: ''
};
try {
await this.recycle(listName, baseUrl);
await sp.configure(SpCore.config, base).web.lists.add(listName, listProperties.Description, listProperties.BaseTemplate, false, listProperties);
await sp.configure(SpCore.config, base).web.lists.getByTitle(listName).fields.getByTitle('Title').update({
Required: titleRequired,
__metadata: { type: 'SP.FieldText' }
});
await this.addFields(listName, fields, base);
return {
code: 200,
description: 'Success!',
message: 'The current list has been recycled.'
};
}
catch (reason) {
SpCore.showErrorLog(reason);
return {
code: 500,
description: 'Internal Error!',
message: reason.message
};
}
}
async addFields(listName, fields, baseUrl) {
const base = baseUrl == null ? SpCore.baseUrl : baseUrl;
try {
for (const [i, field] of fields.entries()) {
const title = field.Title == null ? `Column${i + 1}` : field.Title;
const required = field.Required == null ? false : field.Required;
const indexed = field.Indexed == null ? false : field.Indexed;
const defaultBooleanValue = field.DefaultValue == null ? '0' : field.DefaultValue;
switch (field.FieldTypeKind) {
case FieldTypes.Text:
await sp.configure(SpCore.config, base).web.lists.getByTitle(listName).fields.addText(title, undefined, {
Required: required,
Indexed: indexed
});
break;
case FieldTypes.Note:
await sp.configure(SpCore.config, base).web.lists.getByTitle(listName).fields.addMultilineText(title, 6, false, false, false, false, {
Required: required,
Indexed: indexed
});
break;
case FieldTypes.Boolean:
await sp.configure(SpCore.config, base).web.lists.getByTitle(listName).fields.addBoolean(title, {
Required: required,
Indexed: indexed,
DefaultValue: defaultBooleanValue
});
break;
case FieldTypes.Number:
await sp.configure(SpCore.config, base).web.lists.getByTitle(listName).fields.addNumber(title, undefined, undefined, {
Required: required,
Indexed: indexed,
DefaultValue: defaultBooleanValue
});
break;
case FieldTypes.DateTime:
await sp.configure(SpCore.config, base).web.lists.getByTitle(listName).fields.addDateTime(title, DateTimeFieldFormatType.DateOnly, CalendarType.Gregorian, DateTimeFieldFriendlyFormatType.Disabled, {
Required: required,
Indexed: indexed,
DefaultValue: defaultBooleanValue
});
break;
}
await sp.configure(SpCore.config, base).web.lists.getByTitle(listName).defaultView.fields.add(title);
}
return {
code: 200,
description: 'Success!',
message: 'The current list has been recycled.'
};
}
catch (reason) {
SpCore.showErrorLog(reason);
return {
code: 500,
description: 'Internal Error!',
message: reason.message
};
}
}
async rename(listName, name, overwrite = true, baseUrl) {
const base = baseUrl == null ? SpCore.baseUrl : baseUrl;
try {
const exists = await this.exists(name, base);
if (exists && overwrite) {
await this.recycle(listName, base);
await sp.configure(SpCore.config, base).web.lists.getByTitle(listName).update({
Title: `_backup-${listName}`
});
return {
code: 200,
description: 'Success!',
message: 'The current list has been recycled.'
message: 'The current list has been renamed successfully.'
};
}
catch (reason) {
SpCore.showErrorLog(reason);
return {
code: 500,
description: 'Internal Error!',
message: reason.message
};
}
});
}
rename(listName, name, overwrite = true, baseUrl) {
return __awaiter(this, void 0, void 0, function* () {
const base = baseUrl == null ? SpCore.baseUrl : baseUrl;
try {
const exists = yield this.exists(name, base);
if (exists && overwrite) {
yield this.recycle(listName, base);
yield sp.configure(SpCore.config, base).web.lists.getByTitle(listName).update({
Title: `_backup-${listName}`
});
else {
if (exists && !overwrite) {
return {
code: 200,
description: 'Success!',
message: 'The current list has been renamed successfully.'
code: 405,
description: 'Not allowed!',
message: 'The current list exists and was not allowed to overwrite it.'
};
}
else {
if (exists && !overwrite) {
return {
code: 405,
description: 'Not allowed!',
message: 'The current list exists and was not allowed to overwrite it.'
};
}
else {
return {
code: 404,
message: 'Error making HttpClient request in queryable: [404] Not Found',
description: 'List not found',
};
}
return {
code: 404,
message: 'Error making HttpClient request in queryable: [404] Not Found',
description: 'List not found',
};
}
}
catch (reason) {
SpCore.showErrorLog(reason);
throw new Error(reason);
}
});
}
catch (reason) {
SpCore.showErrorLog(reason);
throw new Error(reason);
}
}

@@ -232,0 +209,0 @@ }

@@ -0,0 +0,0 @@ export interface IMetadata {

export {};
//# sourceMappingURL=core-services-setup.interface.js.map

@@ -0,0 +0,0 @@ import { ISpCoreResult } from './core-services-setup.interface';

@@ -1,19 +0,8 @@

var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
import { sp } from "@pnp/sp";
class Core {
constructor() {
this._baseUrl = '';
this._jsonHeader = 'application/json;odata=verbose';
this._config = {
headers: { accept: this._jsonHeader }
};
}
_baseUrl = '';
_jsonHeader = 'application/json;odata=verbose';
_config = {
headers: { accept: this._jsonHeader }
};
get config() { return this._config; }

@@ -23,22 +12,18 @@ get jsonHeader() { return this._jsonHeader; }

set baseUrl(value) { this._baseUrl = value; }
fetchHeader() {
return __awaiter(this, void 0, void 0, function* () {
const digest = yield this.getDigest(this._baseUrl);
return {
headers: {
Accept: 'application/json;odata=verbose',
'X-RequestDigest': digest
},
credentials: 'include'
};
});
async fetchHeader() {
const digest = await this.getDigest(this._baseUrl);
return {
headers: {
Accept: 'application/json;odata=verbose',
'X-RequestDigest': digest
},
credentials: 'include'
};
}
getDigest(url) {
return __awaiter(this, void 0, void 0, function* () {
const context = yield sp.configure(this.config, url).site.getContextInfo();
return context.FormDigestValue;
});
async getDigest(url) {
const context = await sp.configure(this.config, url).site.getContextInfo();
return context.FormDigestValue;
}
setup(url) {
return new Promise((resolve, reject) => __awaiter(this, void 0, void 0, function* () {
return new Promise(async (resolve, reject) => {
if (this._baseUrl.trim().length === 0 && url == null) {

@@ -60,3 +45,3 @@ reject(this.onError({ code: 405, description: null, message: null }));

const base = url == null ? this._baseUrl : url;
yield this.setupDigest(base);
await this.setupDigest(base);
resolve({

@@ -71,6 +56,6 @@ code: 200,

}
}));
});
}
setupDigest(url) {
return new Promise((resolve, reject) => __awaiter(this, void 0, void 0, function* () {
return new Promise(async (resolve, reject) => {
if (this._baseUrl.trim().length === 0 && url == null) {

@@ -81,3 +66,3 @@ reject(this.onError({ code: 405, description: null, message: null }));

this._baseUrl = url;
const digest = yield this.getDigest(url);
const digest = await this.getDigest(url);
try {

@@ -103,3 +88,3 @@ sp.setup({

}
}));
});
}

@@ -106,0 +91,0 @@ onError(reason) {

@@ -0,0 +0,0 @@ export type TUserListField = 'Email' | 'Id' | 'LoginName' | 'Title';

export {};
//# sourceMappingURL=core-services-user.interface.js.map

@@ -0,0 +0,0 @@ import { ISpCoreResult, ISpCurrentUser } from '../setup/core-services-setup.interface';

@@ -1,10 +0,1 @@

var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
import { SpCore } from '../setup/core-services-setup.service';

@@ -18,48 +9,40 @@ import { sp } from '@pnp/sp';

class Core {
currentUser(baseUrl) {
return __awaiter(this, void 0, void 0, function* () {
const base = baseUrl == null ? SpCore.baseUrl : baseUrl;
try {
return yield sp.configure(SpCore.config, base).web.currentUser.get();
}
catch (reason) {
const error = SpCore.onError(reason);
throw new Error(`Error code: ${error.code}.\nError message: ${error.message}.\nError description: ${error.description}`);
}
});
async currentUser(baseUrl) {
const base = baseUrl == null ? SpCore.baseUrl : baseUrl;
try {
return await sp.configure(SpCore.config, base).web.currentUser.get();
}
catch (reason) {
const error = SpCore.onError(reason);
throw new Error(`Error code: ${error.code}.\nError message: ${error.message}.\nError description: ${error.description}`);
}
}
userData(baseUrl, id) {
return __awaiter(this, void 0, void 0, function* () {
const base = baseUrl == null ? SpCore.baseUrl : baseUrl;
try {
return yield sp.configure(SpCore.config, base).web.siteUsers.getById(id).get();
}
catch (reason) {
const error = SpCore.onError(reason);
throw new Error(`Error code: ${error.code}.\nError message: ${error.message}.\nError description: ${error.description}`);
}
});
async userData(baseUrl, id) {
const base = baseUrl == null ? SpCore.baseUrl : baseUrl;
try {
return await sp.configure(SpCore.config, base).web.siteUsers.getById(id).get();
}
catch (reason) {
const error = SpCore.onError(reason);
throw new Error(`Error code: ${error.code}.\nError message: ${error.message}.\nError description: ${error.description}`);
}
}
usersList(base, hasEmail = true) {
return __awaiter(this, void 0, void 0, function* () {
let users = yield sp.configure(SpCore.config, base).web.siteUsers.get();
if (hasEmail) {
users = users.filter(x => x.Email.length > 0);
users = yield ArraySort.byKey(users, 'Title', true);
}
return users;
});
async usersList(base, hasEmail = true) {
let users = await sp.configure(SpCore.config, base).web.siteUsers.get();
if (hasEmail) {
users = users.filter(x => x.Email.length > 0);
users = await ArraySort.byKey(users, 'Title', true);
}
return users;
}
usersListCombobox(base, valueField, textField) {
return __awaiter(this, void 0, void 0, function* () {
const users = yield this.usersList(base, true);
const list = [];
for (const user of users) {
list.push({
value: user[valueField].toString(),
text: user[textField].toString()
});
}
return list;
});
async usersListCombobox(base, valueField, textField) {
const users = await this.usersList(base, true);
const list = [];
for (const user of users) {
list.push({
value: user[valueField].toString(),
text: user[textField].toString()
});
}
return list;
}

@@ -69,22 +52,20 @@ }

class Email {
send(baseUrl, subject, to, body) {
return __awaiter(this, void 0, void 0, function* () {
const base = baseUrl == null ? SpCore.baseUrl : baseUrl;
const emailProps = {
AdditionalHeaders: {
'content-type': 'text/html'
},
Subject: subject,
To: to,
Body: body
};
try {
yield sp.configure(SpCore.config, base).utility.sendEmail(emailProps);
return true;
}
catch (reason) {
const error = SpCore.onError(reason);
throw new Error(`Error code: ${error.code}.\nError message: ${error.message}.\nError description: ${error.description}`);
}
});
async send(baseUrl, subject, to, body) {
const base = baseUrl == null ? SpCore.baseUrl : baseUrl;
const emailProps = {
AdditionalHeaders: {
'content-type': 'text/html'
},
Subject: subject,
To: to,
Body: body
};
try {
await sp.configure(SpCore.config, base).utility.sendEmail(emailProps);
return true;
}
catch (reason) {
const error = SpCore.onError(reason);
throw new Error(`Error code: ${error.code}.\nError message: ${error.message}.\nError description: ${error.description}`);
}
}

@@ -94,28 +75,22 @@ }

class Permissions {
isAdmin(baseUrl) {
return __awaiter(this, void 0, void 0, function* () {
const base = baseUrl == null ? SpCore.baseUrl : baseUrl;
const currentUser = yield SpUserCore.currentUser(base);
return currentUser.IsSiteAdmin;
});
async isAdmin(baseUrl) {
const base = baseUrl == null ? SpCore.baseUrl : baseUrl;
const currentUser = await SpUserCore.currentUser(base);
return currentUser.IsSiteAdmin;
}
isInGroup(groupName, userEmail, baseUrl) {
return __awaiter(this, void 0, void 0, function* () {
const base = baseUrl == null ? SpCore.baseUrl : baseUrl;
try {
const user = yield sp.configure(SpCore.config, base).web.siteGroups.getByName(groupName).users.get();
return user.filter(x => x.Email === userEmail).length > 0;
}
catch (reason) {
const error = SpCore.onError(reason);
throw new Error(`Error code: ${error.code}.\nError message: ${error.message}.\nError description: ${error.description}`);
}
});
async isInGroup(groupName, userEmail, baseUrl) {
const base = baseUrl == null ? SpCore.baseUrl : baseUrl;
try {
const user = await sp.configure(SpCore.config, base).web.siteGroups.getByName(groupName).users.get();
return user.filter(x => x.Email === userEmail).length > 0;
}
catch (reason) {
const error = SpCore.onError(reason);
throw new Error(`Error code: ${error.code}.\nError message: ${error.message}.\nError description: ${error.description}`);
}
}
isCurrentUserInGroup(groupName, baseUrl) {
return __awaiter(this, void 0, void 0, function* () {
const base = baseUrl == null ? SpCore.baseUrl : baseUrl;
const currentUser = yield SpUserCore.currentUser(base);
return yield this.isInGroup(groupName, currentUser.Email, base);
});
async isCurrentUserInGroup(groupName, baseUrl) {
const base = baseUrl == null ? SpCore.baseUrl : baseUrl;
const currentUser = await SpUserCore.currentUser(base);
return await this.isInGroup(groupName, currentUser.Email, base);
}

@@ -122,0 +97,0 @@ }

export * from './bundle';
export * from './bundle';
//# sourceMappingURL=index.js.map
{
"name": "gl-sp-frontend",
"version": "5.0.0",
"version": "6.0.0",
"description": "Common code for SharePoint 2013/2016 using among web front-end development such as ES6+ and TypeScript",

@@ -40,18 +40,25 @@ "main": "lib/bundle.js",

"dependencies": {
"@pnp/sp": "^2.15.0"
},
"peerDependencies": {
"gl-w-array-frontend": "^5.0.0",
"gl-w-attachment-frontend": "^5.0.0",
"gl-w-combobox-frontend": "^5.0.0",
"@pnp/sp": "^2.15.0",
"gl-w-array-frontend": "^4.0.0",
"gl-w-attachment-frontend": "^4.0.0",
"gl-w-combobox-frontend": "^4.0.0"
"typescript": "^5.1.6"
},
"devDependencies": {
"@eslint/js": "^9.1.1",
"@typescript-eslint/eslint-plugin": "^5.62.0",
"@typescript-eslint/eslint-plugin-tslint": "^5.27.1",
"@typescript-eslint/parser": "^5.62.0",
"@typescript-eslint/eslint-plugin": "^7.8.0",
"@typescript-eslint/eslint-plugin-tslint": "^5.62.0",
"@typescript-eslint/parser": "^7.8.0",
"eslint": "^8.57.0",
"globals": "^15.1.0",
"shx": "^0.3.4",
"typescript": "^4.9.5",
"typescript-eslint": "^7.8.0"
"typescript": "^5.1.6",
"typescript-eslint": "^7.8.0",
"gl-w-array-frontend": "^5.0.0",
"gl-w-attachment-frontend": "^5.0.0",
"gl-w-combobox-frontend": "^5.0.0"
}
}

@@ -5,3 +5,3 @@ {

"compilerOptions": {
"target": "ES2015",
"target": "ES2022",
"module": "ESNext",

@@ -12,8 +12,3 @@ "outDir": "lib",

"dom",
"ES2015.Symbol",
"ES2015.Symbol.WellKnown",
"ES2015.Iterable",
"ES2015.Promise",
"ES2015.Core",
"ES2016"
"ES2022"
]

@@ -20,0 +15,0 @@ },

@@ -5,3 +5,3 @@ {

"compilerOptions": {
"target": "ES6",
"target": "ES2022",
"module": "ESNext",

@@ -12,8 +12,3 @@ "outDir": "lib",

"dom",
"ES2015.Symbol",
"ES2015.Symbol.WellKnown",
"ES2015.Iterable",
"ES2015.Promise",
"ES2015.Core",
"ES2016"
"ES2022"
]

@@ -20,0 +15,0 @@ },

{
"compilerOptions": {
"target": "ES2020",
"target": "ES2022",
"module": "ESNext",

@@ -5,0 +5,0 @@ "moduleResolution": "node",

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