/**
* @file exposes static configuration data and web page specific custom data <br/>
* Created on 22.09.2014 for the yalst-trunk project.
* @copyright (c) 2014 Visisoft OHG. All rights reserved.
* @version 1.0
* @module chatButtonParameters
*
* @typedef {Object} ChatButtonParameters
* @property {String} apiUrl
* @property {String} bubblePointerClasses
* @property {String} siteNumber
* @property {string|undefined} department
* @property {string|undefined} chatName
* @property {string|undefined} pickUpSessionId
* @property {string|undefined} pickUpChatId
* @property {string|undefined} pickUpDepartmentId
* @property {string|undefined} referrer2
* @property {Array.<{code: String, name: String}>} languages - only set if multiple front-end languages are supported
* @property {boolean} skipStartForm
* @property {string|undefined} chatType
* @property {boolean} shouldSkipFormsWhenInvited
* @property {boolean} doNotShowInvitation
* @property {Boolean} showLanguageSwitcher
* @property {String} invitationTitle
* @property {"invite" | "auto-invite" | "load-based-auto-invite" | "page-logic-invite" | "no-invitation"} invitationType
* @property {String} lang - locale identifier e.g. 'de'
* @property {Array<{code: String, info: String}>} privacyInfos
* @property {Boolean} privacyInfosChatWindow
* @property {String} customTopImageUrl
* @property {String} customBottomImageUrl
* @property {Boolean} isWhiteLabel
* @property {String} trackingCookie
* @property {String} yalstAdLink
* @property {String} resellerBranding
* @property {boolean} shouldDisplayFinishedChatConversation
* @property {String|undefined} visitorId
*/
define([], function()
{
/// predefined form fields and 'sessionfields' come as a string
// for example "Ihre Postleitzahl : 00000 ; field2 : value2 "
var explodeIntoTrimmedArrayOfPairs = compose( map( compose( map(trim), split(':') ) ), split(';') );
var pairToKeyValue = function (obj, pair)
{
obj[head(pair)] = last(pair);
return obj;
};
var withoutEmptyKeys = reject( compose(isEmpty, head) );
var predefinedFormFieldsArray = withoutEmptyKeys(
explodeIntoTrimmedArrayOfPairs(globalLiveSupportProviderChatConfiguration.predefinedWelcomingFormFields || "") );
var sessionDataFieldsArray = withoutEmptyKeys(
explodeIntoTrimmedArrayOfPairs(globalLiveSupportProviderChatConfiguration.sessionFields || "") );
const chatApiUrlMatch = globalLiveSupportProviderChatConfiguration.apiUrl.match(/(.*)(\/chat.api.php)$/);
if (!chatApiUrlMatch)
{
throw new Error("Expecting 'chat.api.php' as last constituent of the chat api url!");
}
/** @alias module:chatButtonParameters */
var self = globalLiveSupportProviderChatConfiguration;
/**
* Additional pre-defined key-string pairs which can override custom welcoming form fields.<br/>
* They are usually specified either directly as url parameters in the chat button link, or
* by the VisitorApi's startLiveChat command -- in both cases as <tt>paddfields</tt> parameter.
* For the <tt>paddfields</tt> syntax see the documentation there.
* @type {object}
* @example
* // loading the module
* require(['chatButtonParameters'], function(chatParameters)
* {
* // for the paddfields parameter being
* // "Ihre Postleitzahl : 00000 ; field2 : value2 "
* // this will print out
* // "Object {Ihre Postleitzahl : "00000", field2: "value2"}"
* console.log(chatParameters.addFields);
*
* // prints "00000" to the console
* console.log(chatParameters.addFields["Ihre Postleitzahl"]);
* });
*/
self.addFields = reduce(pairToKeyValue, {}, predefinedFormFieldsArray);
/**
* Same as {@link module:chatButtonParameters.addFields} but as array of pairs.<br/>
* E.g. <tt>[["Ihre Postleitzahl", "00000"], ["field2", "value2"]]</tt>
* @type {array}
*/
self.predefinedFormFieldsArray = predefinedFormFieldsArray;
/**
* Chat session relevant pre-defined key-string pairs.<br/>
* They are usually specified either directly as url parameters in the chat button link, or
* by the VisitorApi's startLiveChat command -- in both cases as <tt>sessionfields</tt> parameter.
* For the <tt>sessionfields</tt> syntax see the documentation there.
* @type {object}
* @example
* // loading the module
* require(['chatButtonParameters'], function(chatParameters)
* {
* // for the sessionfields parameter being
* // "Ihre Postleitzahl : 00000 ; field2 : value2 "
* // this will print out
* // "Object {Ihre Postleitzahl : "00000", field2: "value2"}"
* console.log(chatParameters.sessionFields);
*
* // prints "00000" to the console
* console.log(chatParameters.sessionFields["Ihre Postleitzahl"]);
* });
*/
self.sessionFields = reduce(pairToKeyValue, {}, sessionDataFieldsArray);
/// documentation relevant code ///
/**
* The yalst site id addresses a particular configuration of a group of operators on a
* yalst live support server. It is the basic management unit to access the live support
* capabilities on a yalst server.<br/>
* It's formatted as two numbers linked by a dash. E.g. <tt>"20000-1"</tt>
*
* @type {string}
*/
self.siteNumber = globalLiveSupportProviderChatConfiguration.siteNumber;
/**
* The yalst operator department id pre-defined by the embedding web page.<br/>
* Is <tt>undefined</tt> if the chat is unspecified regarding departments.
*
* @type {string|undefined}
*/
self.department = globalLiveSupportProviderChatConfiguration.department;
self.yalstFolderUrl = chatApiUrlMatch[1];
return self;
});