const XMLHttpRequest = require("xmlhttprequest").XMLHttpRequest;
const spauth = require("node-sp-auth");
const rp = require("request-promise");
const express = require("express");
const app = express();
const url = require("./config").url;
const credentialOptions = require("./config").credentialOptions;
const port = 80;
RestRequest = (url, params) => {
const _spPageContextInfo = url;
let req = new XMLHttpRequest();
req.onreadystatechange = function() {
if (req.readyState != 4)
// Loaded
return;
console.log(req.responseText);
};
req.open("POST", url, true);
req.setRequestHeader("Content-Type", "application/json;charset=utf-8");
req.setRequestHeader("ACCEPT", "application/json; odata.metadata=minimal");
req.setRequestHeader("x-requestdigest", _spPageContextInfo);
req.setRequestHeader("ODATA-VERSION", "4.0");
req.send(params ? JSON.stringify(params) : void 0);
};
RestRequest("/_api/thememanager/GetTenantThemingOptions");
const pal = {
palette: {
themePrimary: "#00ffff",
themeLighterAlt: "#f3fcfc",
themeLighter: "#daffff",
themeLight: "#affefe",
themeTertiary: "#76ffff",
themeSecondary: "#39ffff",
themeDarkAlt: "#00c4c4",
themeDark: "#009090",
themeDarker: "#005252",
neutralLighterAlt: "#f8f8f8",
neutralLighter: "#f4f4f4",
neutralLight: "#eaeaea",
neutralQuaternaryAlt: "#dadada",
neutralQuaternary: "#d0d0d0",
neutralTertiaryAlt: "#c8c8c8",
neutralTertiary: "#a6a6a6",
neutralSecondaryAlt: "#767676",
neutralSecondary: "#666666",
neutralPrimary: "#333",
neutralPrimaryAlt: "#3c3c3c",
neutralDark: "#212121",
black: "#000000",
white: "#fff",
primaryBackground: "#fff",
primaryText: "#333"
}
};
app.listen(port, () => {
console.log(`App listening on port ${port}`);
});
app.get("/", (req, res) => {
//get auth options
spauth.getAuth(url, credentialOptions).then(options => {
//perform request with any http-enabled library (request-promise in a sample below):
let headers = options.headers;
headers["Accept"] = "application/json;odata=verbose";
rp.get({
url: url,
headers: headers
}).then(response => {
res.send(response);
RestRequest("/_api/thememanager/AddTenantTheme", {
name: "DPT Cyna",
themeJson: JSON.stringify(pal)
});
});
});
});