I have built a Single page application
. I have deployed the html file to the root of the sharepoint site and js files are stored in the Assets Library. They are referenced from there. I am trying to check if the current logged in user has access to the sharepoint site/web, among other things using rest api
.
The following endpoint _api/web/effectivebasepermissions
returns:
High, low response :
{High: '2147483647', Low: '4294967295'}
then I will have to check this response againts SP.BasePermissions()
as follows:
var my_basePermissions = new SP.BasePermissions();
my_basePermissions.initPropertiesFromJson(my_effectivePermissions);
console.log("my_basePermissions = " + JSON.stringify(my_basePermissions, null, 4));
var manageWeb = my_basePermissions.has(SP.PermissionKind.manageWeb);
To access SP.BasePermissions, I need to reference SP.js
. I tried the following, found in this other post: https://sharepoint.stackexchange.com/questions/213236/spx-and-typescript-how-to-add-references-to-sp-js
import { SPComponentLoader } from '@microsoft/sp-loader';
try {
SPComponentLoader.loadScript(siteColUrl + '/_layouts/15/init.js', {
globalExportsName: '$_global_init'
})
.then((): Promise<{}> => {
return SPComponentLoader.loadScript(siteColUrl + '/_layouts/15/MicrosoftAjax.js', {
globalExportsName: 'Sys'
});
})
.then((): Promise<{}> => {
return SPComponentLoader.loadScript(siteColUrl + '/_layouts/15/SP.Runtime.js', {
globalExportsName: 'SP'
});
})
.then((): Promise<{}> => {
return SPComponentLoader.loadScript(siteColUrl + '/_layouts/15/SP.js', {
globalExportsName: 'SP'
});
})
.then((): Promise<{}> => {
return SPComponentLoader.loadScript(siteColUrl + '/_layouts/15/SP.taxonomy.js', {
globalExportsName: 'SP'
});
})
.then((): void => {
this.setState({ loadingScripts: false });
})
.catch((reason: any) => {
this.setState({ loadingScripts: false, errors: [...this.state.errors, reason] });
});
} catch (error) {
this.setState({ loadingScripts: false, errors: [...this.state.errors, error] });
}
}
I get the following error:
Module not found: Error: Can't resolve '@ms/sp-telemetry' in '\node_modules\@microsoft\sp-loader\lib-commonjs\utilities'
Ok, so the question is, how can I reference and load SP.js, for example, in my react js app?