Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
gpii.request.matchMaker.getSolutions = function (matchMaker, event, model) {
var device = model.device,
os = fluid.get(device, "OS.id"),
version = fluid.get(device, "OS.version");
matchMaker.solutionsReporter.get({
os: os,
version: version
}, function (solutions) {
// TODO: presumably this should read filterSolutionsByVersion - currently a no-op
matchMaker.prefilterSolutions(solutions, os, version);
solutions = matchMaker.prefilterSolutions(solutions, device);
event.fire(solutions);
});
};
// within th application schema.
schema = fluid.get(thisSolutionSchema, ["properties", innerPrefsKey]);
solutionName = fluid.get(thisSolutionSchema, ["title"]);
presentedCommonTerm = undefined;
}
togo = {
schema: schema,
solutionName: solutionName,
presentedCommonTerm: presentedCommonTerm,
prefsValue: val,
prefsKeySegs: [prefsKey, innerPrefsKey]
};
});
} else {
// Handle common terms
var schema = fluid.get(solutionSchemas, [prefsKey]);
delete schema.$schema;
togo = {
schema: schema,
solutionName: fluid.get(solutionSchemas, [prefsKey, "title"]),
presentedCommonTerm: prefsKey,
prefsValue: prefsValue,
prefsKeySegs: [prefsKey]
};
}
return togo;
};
gpii.pspChannel.sessionToPSP = function (model, transformSpec) {
var that = transformSpec.pspChannel;
// populate the default setting controls with schema defaults at the first time
if (!that.defaultSettingControls) {
that.defaultSettingControlsPromise.then(function (defaultSettingControls) {
that.defaultSettingControls = defaultSettingControls;
});
}
var schemas = that.options.settingsSchema;
var outModel = fluid.filterKeys(model, ["gpiiKey", "activePrefsSetName"]);
var settingControls = {};
var activePreferences = fluid.get(model, ["preferences", "contexts", model.activePrefsSetName, "preferences"]);
var activeSolutionIds, activeSolutions;
var applications = fluid.get(model, "activeConfiguration.inferredConfiguration.applications");
if (applications) {
activeSolutionIds = Object.keys(applications);
activeSolutions = fluid.filterKeys(model.solutionsRegistryEntries, activeSolutionIds);
}
fluid.each(activePreferences, function (prefsVal, prefsKey) {
var prefsInfo = gpii.pspChannel.getPreferenceInfo(schemas, prefsKey, prefsVal);
var liveness = gpii.matchMakerFramework.utils.getLeastLiveness(activeSolutions, prefsInfo.presentedCommonTerm);
gpii.pspChannel.emitSettingControl(settingControls, prefsInfo.schema, prefsInfo.prefsValue, prefsInfo.prefsKeySegs, liveness);
});
outModel.settingControls = fluid.extend(true, {}, settingControls, that.defaultSettingControls || {});
outModel.preferences = {
name: fluid.get(model, "preferences.name"),
gpii.pspChannel.sessionToPSP = function (model, transformSpec) {
var that = transformSpec.pspChannel;
// populate the default setting controls with schema defaults at the first time
if (!that.defaultSettingControls) {
that.defaultSettingControlsPromise.then(function (defaultSettingControls) {
that.defaultSettingControls = defaultSettingControls;
});
}
var schemas = that.options.settingsSchema;
var outModel = fluid.filterKeys(model, ["gpiiKey", "activePrefsSetName"]);
var settingControls = {};
var activePreferences = fluid.get(model, ["preferences", "contexts", model.activePrefsSetName, "preferences"]);
var activeSolutionIds, activeSolutions;
var applications = fluid.get(model, "activeConfiguration.inferredConfiguration.applications");
if (applications) {
activeSolutionIds = Object.keys(applications);
activeSolutions = fluid.filterKeys(model.solutionsRegistryEntries, activeSolutionIds);
}
fluid.each(activePreferences, function (prefsVal, prefsKey) {
var prefsInfo = gpii.pspChannel.getPreferenceInfo(schemas, prefsKey, prefsVal);
var liveness = gpii.matchMakerFramework.utils.getLeastLiveness(activeSolutions, prefsInfo.presentedCommonTerm);
gpii.pspChannel.emitSettingControl(settingControls, prefsInfo.schema, prefsInfo.prefsValue, prefsInfo.prefsKeySegs, liveness);
});
outModel.settingControls = fluid.extend(true, {}, settingControls, that.defaultSettingControls || {});
outModel.preferences = {
name: fluid.get(model, "preferences.name"),
contexts: fluid.transform(fluid.get(model, "preferences.contexts"), function (contextVal) {
return fluid.filterKeys(contextVal, ["name"]);
})
gpiiKeyPromise.then(function (gpiiKeyRelatedData) {
var preferencesPromise = fluid.promise();
var payload;
if (gpiiKeyRelatedData) {
// If the GPII key exists:
// 1. If an existing prefs safe already associates with the GPII key, update the prefs safe;
// 2. If no prefs safe is associated with the GPII key, create the prefs safe and associate with the GPII key.
var rawPrefs = fluid.get(gpiiKeyRelatedData, ["prefsSafe", "preferences"]);
payload = ontologyHandler.addPrefsToRawPrefs(preferences, view, rawPrefs || {});
var updatePromise = preferencesService.updatePreferences(payload, gpiiKey, merge);
var mapper = function (updateResponse) {
return {
gpiiKey: updateResponse.gpiiKey,
preferences: fluid.get(updateResponse, ["preferences", view])
};
};
preferencesPromise = fluid.promise.map(updatePromise, mapper);
} else {
// Reject if the GPII key does not exist
fluid.log("Preferences Server, updatePreferences(), updating preferences, rejected due to the missing GPII key: " + gpiiKey);
preferencesPromise.reject(gpii.preferencesServer.errors.missingGpiiKey);
}
gpii.iniFile.getUnwrittenValues = function (state, sectionPath, subSections) {
var items = [];
var section = fluid.get(state.data, sectionPath);
if (section) {
var allKeys = Object.keys(section);
var path = sectionPath.length ? sectionPath.join(state.pathSep) + state.pathSep : "";
fluid.each(allKeys, function (key) {
if (!state.valuesWritten[path + key]) {
var value = section[key];
if (fluid.isPlainObject(value) === !!subSections) {
items.push({
key: key,
value: value
});
}
}
});
}
return items;
gpii.settingsHandlers.webSockets.addClient = function (that, solutionId, client) {
var initialSettings = fluid.get(that.model.settings, [solutionId]);
var currentValue = fluid.get(that.clients, [solutionId, client.id]);
if (!currentValue) {
fluid.set(that.clients, [solutionId, client.id], client);
client.sendTypedMessage("connectionSucceeded", initialSettings);
client.events.onDestroy.addListener(function () {
that.removeClient(client);
});
}
};
var mapper = function (updateResponse) {
return {
gpiiKey: updateResponse.gpiiKey,
preferences: fluid.get(updateResponse, ["preferences", view])
};
};
preferencesPromise = fluid.promise.map(updatePromise, mapper);
clientPromise.then(function (record) {
var client = record ? record.client : undefined;
var clientCredential = record ? record.clientCredential : undefined;
if (client && clientCredential && fluid.get(clientCredential, ["oauth2ClientSecret"]) === expectedOauth2ClientSecret) {
promiseTogo.resolve({
client: client,
clientCredentialId: clientCredential.id
});
} else {
fluid.log("clientService: unauthorized client with oauth2ClientId - " + oauth2ClientId);
promiseTogo.reject(gpii.dbOperation.errors.unauthorized);
}
}, function (err) {
promiseTogo.reject(err);