jsdo.adal
Version:
Azure authentication for jsdo
1,262 lines (1,093 loc) • 641 kB
JavaScript
/*!
* lib/progress.auth.adal
*
* Copyright (c) 2010 - 2019 Robin Herbots
* Licensed under the MIT license
* Version: 0.0.6
*/
(function webpackUniversalModuleDefinition(root, factory) {
if(typeof exports === 'object' && typeof module === 'object')
module.exports = factory();
else if(typeof define === 'function' && define.amd)
define([], factory);
else {
var a = factory();
for(var i in a) (typeof exports === 'object' ? exports : root)[i] = a[i];
}
})(window, function() {
return /******/ (function(modules) { // webpackBootstrap
/******/ // The module cache
/******/ var installedModules = {};
/******/
/******/ // The require function
/******/ function __webpack_require__(moduleId) {
/******/
/******/ // Check if module is in cache
/******/ if(installedModules[moduleId]) {
/******/ return installedModules[moduleId].exports;
/******/ }
/******/ // Create a new module (and put it into the cache)
/******/ var module = installedModules[moduleId] = {
/******/ i: moduleId,
/******/ l: false,
/******/ exports: {}
/******/ };
/******/
/******/ // Execute the module function
/******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
/******/
/******/ // Flag the module as loaded
/******/ module.l = true;
/******/
/******/ // Return the exports of the module
/******/ return module.exports;
/******/ }
/******/
/******/
/******/ // expose the modules object (__webpack_modules__)
/******/ __webpack_require__.m = modules;
/******/
/******/ // expose the module cache
/******/ __webpack_require__.c = installedModules;
/******/
/******/ // define getter function for harmony exports
/******/ __webpack_require__.d = function(exports, name, getter) {
/******/ if(!__webpack_require__.o(exports, name)) {
/******/ Object.defineProperty(exports, name, { enumerable: true, get: getter });
/******/ }
/******/ };
/******/
/******/ // define __esModule on exports
/******/ __webpack_require__.r = function(exports) {
/******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) {
/******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
/******/ }
/******/ Object.defineProperty(exports, '__esModule', { value: true });
/******/ };
/******/
/******/ // create a fake namespace object
/******/ // mode & 1: value is a module id, require it
/******/ // mode & 2: merge all properties of value into the ns
/******/ // mode & 4: return value when already ns object
/******/ // mode & 8|1: behave like require
/******/ __webpack_require__.t = function(value, mode) {
/******/ if(mode & 1) value = __webpack_require__(value);
/******/ if(mode & 8) return value;
/******/ if((mode & 4) && typeof value === 'object' && value && value.__esModule) return value;
/******/ var ns = Object.create(null);
/******/ __webpack_require__.r(ns);
/******/ Object.defineProperty(ns, 'default', { enumerable: true, value: value });
/******/ if(mode & 2 && typeof value != 'string') for(var key in value) __webpack_require__.d(ns, key, function(key) { return value[key]; }.bind(null, key));
/******/ return ns;
/******/ };
/******/
/******/ // getDefaultExport function for compatibility with non-harmony modules
/******/ __webpack_require__.n = function(module) {
/******/ var getter = module && module.__esModule ?
/******/ function getDefault() { return module['default']; } :
/******/ function getModuleExports() { return module; };
/******/ __webpack_require__.d(getter, 'a', getter);
/******/ return getter;
/******/ };
/******/
/******/ // Object.prototype.hasOwnProperty.call
/******/ __webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };
/******/
/******/ // __webpack_public_path__
/******/ __webpack_require__.p = "";
/******/
/******/
/******/ // Load entry module and return exports
/******/ return __webpack_require__(__webpack_require__.s = 0);
/******/ })
/************************************************************************/
/******/ ([
/* 0 */
/***/ (function(module, exports, __webpack_require__) {
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
var _progress = __webpack_require__(1);
var _progress2 = _interopRequireDefault(_progress);
__webpack_require__(2);
__webpack_require__(3);
__webpack_require__(4);
__webpack_require__(5);
var _adalAngular = __webpack_require__(6);
var _adalAngular2 = _interopRequireDefault(_adalAngular);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
/*
* progress.auth.adal.js
* http://github.com/RobinHerbots/jsdo.adal
* Copyright (c) 2018 - Robin Herbots
* Licensed under the MIT license (http://www.opensource.org/licenses/mit-license.php)
*/
window.AuthenticationContext = _adalAngular2.default; //AuthenticationContext should be available on the window. See AuthenticationContext.prototype.getRequestInfo
_progress2.default.data.AuthenticationProviderAdal = function (uri, adalConfig) {
var authContext = new _adalAngular2.default(adalConfig);
authContext.callback = adalConfig.callback;
// Check For & Handle Redirect From AAD After Login
if (authContext.isCallback(window.location.hash)) {
authContext.handleWindowCallback();
}
// process constructor arguments, etc.
this._initialize(uri, _progress2.default.data.Session.AUTH_TYPE_ADAL, { "_loginURI": _progress2.default.data.AuthenticationProvider._homeLoginURIBase });
function setAuthorizationHeader(xhr, uri) {
var resource = authContext.getResourceForEndpoint(uri);
var dfd = $.Deferred();
if (resource !== null) {
authContext.acquireToken(resource, function (error, token) {
if (error || !token) {
authContext.error(error);
dfd.reject(error);
return;
}
xhr.setRequestHeader('Authorization', "Bearer " + token);
dfd.resolve();
});
} else dfd.reject("Unknown resource");
return dfd.promise();
}
this._reset = function () {
// if (authContext) authContext.logOut();
_progress2.default.data.AuthenticationProviderAdal.prototype._reset.apply(this);
};
this.hasClientCredentials = function () {
return authContext && authContext.getCachedUser() && authContext.getCachedToken(adalConfig.clientId);
};
//we need to override because we need to control the promises from adal.js
this._loginProto = function (sendParam) {
var deferred = $.Deferred(),
xhr,
uriForRequest,
header,
that = this;
if (authContext && !(authContext.getCachedUser() && authContext.getCachedToken(adalConfig.clientId))) {
authContext.login();
return;
}
if (this._loggedIn) {
// "The login method was not executed because the AuthenticationProvider is
// already logged in."
throw new Error(_progress2.default.data._getMsgText("jsdoMSG051", "AuthenticationProvider"));
}
xhr = new XMLHttpRequest();
xhr.onreadystatechange = function () {
if (xhr.readyState === 4) {
// process the response from the Web application
that._processLoginResult(xhr, deferred);
}
};
if (_progress2.default.data.Session._useTimeStamp) {
uriForRequest = _progress2.default.data.Session._addTimeStampToURL(this._loginURI);
} else {
uriForRequest = this._loginURI;
}
this._openLoginRequest(xhr, uriForRequest);
xhr.setRequestHeader("Accept", "application/json");
setAuthorizationHeader(xhr, uri).then(function () {
xhr.send(sendParam);
}, function () {
deferred.reject(that.arguments);
});
return deferred.promise();
};
// this method is needed for internal jsdo calls see comment in progress.auth.js
this._openRequestAndAuthorize = function (xhr, verb, uri, async, callback) {
if (this.hasClientCredentials()) {
xhr.open(verb, uri, async);
_progress2.default.data.Session._setNoCacheHeaders(xhr);
setAuthorizationHeader(xhr, uri).then(function () {
callback();
}, function () {
callback(new Error(_progress2.default.data._getMsgText("jsdoMSG125", "AuthenticationProvider")));
});
} else {
callback(new Error(_progress2.default.data._getMsgText("jsdoMSG125", "AuthenticationProvider")));
}
};
};
//inherit from base AuthenticationProvider
_progress2.default.data.AuthenticationProviderAdal.prototype = _progress2.default.data.AuthenticationProvider.prototype;
exports.default = _progress2.default;
/***/ }),
/* 1 */
/***/ (function(module, exports, __webpack_require__) {
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
window.progress = {};
exports.default = window.progress;
/***/ }),
/* 2 */
/***/ (function(module, exports, __webpack_require__) {
/*** IMPORTS FROM imports-loader ***/
var {default:progress} = __webpack_require__(1);
"use strict";
var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; };
/*
progress.util.js Version: 4.4.0-7
Copyright (c) 2014-2017 Progress Software Corporation and/or its subsidiaries or affiliates.
Contains support objects used by the jsdo and/or session object
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
/*global progress:true*/
/*jslint nomen: true*/
(function () {
/* Define these if not defined yet - they may already be defined if
* progress.js was included first */
if (typeof progress === "undefined") {
progress = {};
}
if (typeof progress.data === "undefined") {
progress.data = {};
}
progress.util = {};
var STRING_OBJECT_TYPE = "String",
DATE_OBJECT_TYPE = "Date",
CHARACTER_ABL_TYPE = "CHARACTER";
/**
* Utility class that allows subscribing and unsubscribing from named events.
*
* @returns {progress.util.Observable}
*/
progress.util.Observable = function () {
/*
* Example format of the events object. Some event delegates may only
* have a function setup, others may optionally have scope, and possibly an operation filter
*
* var events = {
* afterfill : [{
* scope : {}, // this is optional
* fn : function () {},
* operation : 'getCustomers' // this is optional
* }, ...]
*
* }
*
*
*
*/
/*
* remove the given function from the array of observers
*/
function _filterObservers(observers, fn, scope, operation) {
return observers.filter(function (el) {
if (el.fn !== fn || el.scope !== scope || el.operation !== operation) {
return el;
}
}, this);
}
/*
* validate the arguments passed to the subscribe function
*/
this.validateSubscribe = function (args, evt, listenerData) {
if (args.length >= 2 && typeof args[0] === 'string' && typeof args[1] === 'string') {
listenerData.operation = args[1];
listenerData.fn = args[2];
listenerData.scope = args[3];
} else if (args.length >= 2 && typeof args[0] === 'string' && typeof args[1] === 'function') {
listenerData.operation = undefined;
listenerData.scope = args[2];
listenerData.fn = args[1];
} else {
throw new Error();
}
};
/*
* bind the specified function so it receives callbacks when the
* specified event name is called. Event name is not case sensitive.
* An optional scope can be provided so that the function is executed
* in the given scope. If no scope is given, then the function will be
* called without scope.
*
* If the same function is registered for the same event a second time with
* the same scope the original subscription is removed and replaced with the new function
* to be called in the new scope.
*
* This method has two signatures.
*
* Signature 1:
* @param evt The name of the event to bind a handler to. String. Not case sensitive.
* @param fn The function callback for the event . Function.
* @param scope The scope the function is to be run in. Object. Optional.
*
* Signature 2:
*
* @param evt The name of the event to bind a handler to. String. Not case sensitive
* @param operation The name of the operation to bind to. String. Case sensitive.
* @param fn The function callback for the event . Function.
* @param scope The scope the function is to be run in. Object. Optional.
*/
this.subscribe = function (evt, operation, fn, scope) {
var listenerData, observers;
if (!evt) {
throw new Error(progress.data._getMsgText("jsdoMSG037", this.toString(), "subscribe"));
}
if (typeof evt !== 'string') {
throw new Error(progress.data._getMsgText("jsdoMSG033", this.toString(), "subscribe", progress.data._getMsgText("jsdoMSG039")));
}
this._events = this._events || {};
evt = evt.toLowerCase();
listenerData = { fn: undefined, scope: undefined, operation: undefined };
try {
this.validateSubscribe(arguments, evt, listenerData);
} catch (e) {
throw new Error(progress.data._getMsgText("jsdoMSG033", this.toString(), "subscribe", e.message));
}
observers = this._events[evt] || [];
// make sure we don't add duplicates
observers = _filterObservers(observers, listenerData.fn, listenerData.scope, listenerData.operation);
observers.push(listenerData);
this._events[evt] = observers;
return this;
};
/*
* remove the specified function so it no longer receives events from
* the given name. event name is not case sensitive.
*
* This method has two signaturues.
* Signature 1:
* @param evt Required. The name of the event for which to unbind the given function. String.
* @param fn Required. The function to remove from the named event. Function.
* @param scope Optional. The function scope in which to remove the listener. Object.
*
* Signature 2:
*
* @param evt Required. The name of the event for which to unbind the given function.
String. Not case sensitive
* @param operation Required. The name of the operation to receive events. String. Case Sensitive
* @param fn Required. The function to remove from the named event. Function.
* @param scope Optional. The function scope in which to remove the listener. Object.
*
*/
this.unsubscribe = function (evt, operation, fn, scope) {
var listenerData, observers;
if (!evt) {
throw new Error(progress.data._getMsgText("jsdoMSG037", this.toString(), "unsubscribe"));
}
if (typeof evt !== 'string') {
throw new Error(progress.data._getMsgText("jsdoMSG033", this.toString(), "unsubscribe", progress.data._getMsgText("jsdoMSG037")));
}
this._events = this._events || {};
evt = evt.toLowerCase();
listenerData = { fn: undefined, scope: undefined, operation: undefined };
try {
this.validateSubscribe(arguments, evt, listenerData);
} catch (e) {
// throw new Error("Invalid signature for unsubscribe. " + e.message);
throw new Error(progress.data._getMsgText("jsdoMSG033", this.toString(), "unsubscribe", e.message));
}
observers = this._events[evt] || [];
if (observers.length > 0) {
this._events[evt] = _filterObservers(observers, listenerData.fn, listenerData.scope, listenerData.operation);
}
return this;
};
/*
* trigger an event of the given name, and pass the specified data to
* the subscribers of the event. Event name is not case sensitive.
* A variable numbers of arguments can be passed as arguments to the event handler.
*
* This method has two signatures
* Signature 1:
* @param evt The name of the event to fire. String. Not case sensitive.
* @param operation The name of the operation. String. Case sensitive
* @param args Optional. A variable number of arguments to pass to the event handlers.
*
* Signature 2:
* @param evt The name of the event to fire. String. Not case sensitive
* @param args Optional. A variable number of arguments to pass to the event handlers.
*/
this.trigger = function (evt, operation, args) {
var observers, op;
if (!evt) {
throw new Error(progress.data._getMsgText("jsdoMSG037", this.toString(), "trigger"));
}
this._events = this._events || {};
evt = evt.toLowerCase();
observers = this._events[evt] || [];
if (observers.length > 0) {
args = Array.prototype.slice.call(arguments);
if (arguments.length >= 2 && typeof evt === 'string' && typeof operation === 'string') {
// in alt format the second argument is the event name,
// and the first is the operation name
op = operation;
args = args.length > 2 ? args.slice(2) : [];
} else if (arguments.length >= 1 && typeof evt === 'string') {
op = undefined;
args = args.length > 1 ? args.slice(1) : [];
} else {
throw new Error(progress.data._getMsgText("jsdoMSG033", this.toString(), "trigger"));
}
observers.forEach(function (el) {
if (el.operation === op) {
el.fn.apply(el.scope, args);
}
});
}
return this;
};
// unbind all listeners from the given event. If the
// evt is undefined, then all listeners for all events are unbound
// evnt name is not case sensitive
// @param evt Optional. The name of the event to unbind. If not passed, then all events are unbound
this.unsubscribeAll = function (evt, operation) {
var observers;
if (evt) {
this._events = this._events || {};
if (typeof evt === 'string') {
evt = evt.toLowerCase();
observers = this._events[evt] || [];
observers.forEach(function (el) {
if (el.operation) {
this.unsubscribe(evt, el.operation, el.fn, el.scope);
} else {
this.unsubscribe(evt, el.fn, el.scope);
}
}, this);
}
} else {
this._events = {};
}
return this;
};
};
/**
* Utility class that saves/reads data to localStorage
*
* @returns {progress.data.LocalStorage}
*/
progress.data.LocalStorage = function LocalStorage() {
/*global localStorage */
if (typeof localStorage === "undefined") {
// "progress.data.LocalStorage: No support for localStorage."
throw new Error(progress.data._getMsgText("jsdoMSG126", "progress.data.LocalStorage", "localStorage"));
}
// "Methods"
this.saveToLocalStorage = function (name, dataObj) {
localStorage.setItem(name, JSON.stringify(dataObj));
};
this.readFromLocalStorage = function (name) {
var jsonStr = localStorage.getItem(name),
dataObj = null;
if (jsonStr !== null) {
try {
dataObj = JSON.parse(jsonStr);
} catch (e) {
dataObj = null;
}
}
return dataObj;
};
this.clearLocalStorage = function (name) {
localStorage.removeItem(name);
};
}; // End of LocalStorage
/////////////////////////////////////////////////////////////////////////////////////////
// Utility Functions
/*
* Converts the specified filter object to an OpenEdge ABL Where String.
*
* @param tableRef - handle to the table in jsdo, where string is applied to.
* @param filter - the filter object to convert.
*
* @returns - translated OE where string.
*/
progress.util._convertToABLWhereString = function (tableRef, filter) {
var result = [],
logic = filter.logic || "and",
idx,
length,
field,
fieldInfo,
type,
format,
operator,
value,
ablType,
//filters = (filter.filters) ? filter.filters : [filter],
filters = filter.filters || [filter],
whereOperators = {
eq: "=",
neq: "<>",
gt: ">",
gte: ">=",
lt: "<",
lte: "<=",
contains: "INDEX",
doesnotcontain: "INDEX",
endswith: "R-INDEX",
startswith: "BEGINS",
isnull: "ISNULL",
isnotnull: "ISNOTNULL",
isempty: "ISEMPTY",
isnotempty: "ISNOTEMPTY"
};
for (idx = 0, length = filters.length; idx < length; idx += 1) {
filter = filters[idx];
field = filter.field;
value = filter.value;
if (filter.filters) {
filter = progress.util._convertToABLWhereString(tableRef, filter);
} else {
// Use original field name instead of serialized name
if (field && tableRef._name) {
fieldInfo = tableRef._jsdo[tableRef._name]._fields[field.toLowerCase()];
if (fieldInfo && fieldInfo.origName) {
field = fieldInfo.origName;
}
}
operator = whereOperators[filter.operator];
if (operator === undefined) {
throw new Error("The operator " + filter.operator + " is not valid.");
}
switch (filter.operator) {
case "isnull":
case "isnotnull":
case "isempty":
case "isnotempty":
value = undefined;
break;
}
if (operator && value !== undefined) {
type = progress.util._getObjectType(value);
// We need to build a template format string for the where string.
// We'll first add positional info for the value
if (type === STRING_OBJECT_TYPE) {
format = "'{1}'";
value = value.replace(/'/g, "~'");
} else if (type === DATE_OBJECT_TYPE) {
ablType = tableRef._getABLType(field);
if (ablType === "DATE") {
format = "DATE({1:MM, dd, yyyy})";
} else if (ablType === "DATETIME-TZ") {
// zzz here means to translate timezone offset into minutes
format = "DATETIME-TZ({1:MM, dd, yyyy, hh, mm, ss, fff, zzz})";
} else {
format = "DATETIME({1:MM, dd, yyyy, hh, mm, ss, fff})";
}
} else {
format = "{1}";
}
// Most where strings are in the format: field operator value. Ex. custnum < 100
// An exception to this is INDEX() and R-INDEX() which have format: operator field value
// Ex. R-INDEX(name, "LTD")
if (operator === "INDEX" || operator === "R-INDEX") {
if (type !== STRING_OBJECT_TYPE) {
throw new Error("Error parsing filter object. The operator " + filter.operator + " requires a string value");
}
if (filter.operator === "doesnotcontain") {
format = "{0}(" + "{2}, " + format + ") = 0";
} else if (filter.operator === "contains") {
format = "{0}(" + "{2}, " + format + ") > 0";
} else {
// else filter.operator = "endswith"
format = "{2} MATCHES '*{1}'";
}
} else {
format = "{2} {0} " + format;
}
filter = progress.util._format(format, operator, value, field);
} else if (operator && value === undefined) {
if (filter.operator === "isempty" || filter.operator === "isnotempty") {
ablType = tableRef._getABLType(field);
if (ablType !== CHARACTER_ABL_TYPE) {
throw new Error("Error parsing filter object. The operator " + filter.operator + " requires a CHARACTER field");
}
if (filter.operator === "isempty") {
format = "{2} = ''";
} else if (filter.operator === "isnotempty") {
format = "{2} <> ''";
}
} else {
if (filter.operator === "isnull") {
format = "{2} = ?";
} else if (filter.operator === "isnotnull") {
format = "{2} <> ?";
} else {
format = "{2} {0} ?";
}
}
// format, operator {0}, value {1}, field {2}
filter = progress.util._format(format, operator, value, field);
}
}
result.push(filter);
}
filter = result.join(" " + logic + " ");
if (result.length > 1) {
filter = "(" + filter + ")";
}
return filter;
};
/*
* Converts the specified filter object to an SQL Query String.
*
* @param tableName - tableName of table in jsdo, where clause is applied to.
* @param filter - the filter object to convert.
*
* @returns - translated SQL where clause.
*/
progress.util._convertToSQLQueryString = function (tableRef, filter, addSelect) {
var result = [],
logic = filter.logic || "and",
idx,
length,
field,
type,
format,
operator,
value,
fieldFormat,
filters = filter.filters || [filter],
filterStr,
usingLike = true,
whereOperators = {
eq: "=",
neq: "!=",
gt: ">",
gte: ">=",
lt: "<",
lte: "<=",
contains: "LIKE",
doesnotcontain: "NOT LIKE",
endswith: "LIKE",
startswith: "LIKE",
isnull: "ISNULL",
isnotnull: "ISNOTNULL",
isempty: "ISEMPTY",
isnotempty: "ISNOTEMPTY"
};
if (typeof addSelect === "undefined") {
addSelect = false;
}
for (idx = 0, length = filters.length; idx < length; idx += 1) {
filter = filters[idx];
field = filter.field;
value = filter.value;
if (filter.filters) {
filterStr = progress.util._convertToSQLQueryString(tableRef, filter, false);
} else {
operator = whereOperators[filter.operator];
if (operator === undefined) {
throw new Error("The operator " + filter.operator + " is not valid.");
}
switch (filter.operator) {
case "isnull":
case "isnotnull":
case "isempty":
case "isnotempty":
value = undefined;
break;
}
if (operator && value !== undefined) {
type = progress.util._getObjectType(value);
if (operator === "LIKE" || operator === "NOT LIKE") {
if (type !== STRING_OBJECT_TYPE) {
throw new Error("Error parsing filter object. The operator " + filter.operator + " requires a string value");
}
}
if (type === STRING_OBJECT_TYPE) {
format = "'{1}'";
value = value.replace(/'/g, "''");
} else if (type === DATE_OBJECT_TYPE) {
fieldFormat = tableRef._getFormat(field);
if (fieldFormat === "date") {
format = "'{1:yyyy-MM-dd}'";
} else if (fieldFormat === "date-time") {
format = "{1:#ISO(iso)}";
} else if (fieldFormat === "time") {
format = "'{1:FFF}'";
}
} else {
format = "{1}";
}
// We need to build a template format string for the where string.
// We'll first add positional info for the value, which is represented by {1}
if (filter.operator === "startswith") {
format = "'{1}%'";
} else if (filter.operator === "endswith") {
format = "'%{1}'";
} else if (filter.operator === "contains" || filter.operator === "doesnotcontain") {
format = "'%{1}%'";
} else {
usingLike = false;
}
if (usingLike) {
value = value.replace(/%/g, '\\%');
value = value.replace(/_/g, '\\_');
}
format = "{2} {0} " + format;
filterStr = progress.util._format(format, operator, value, field);
} else if (operator && value === undefined) {
if (filter.operator === "isempty" || filter.operator === "isnotempty") {
type = tableRef._fields[field.toLowerCase()].type;
if (type !== STRING_OBJECT_TYPE.toLowerCase()) {
throw new Error("Error parsing filter object. The operator " + filter.operator + " requires a string field");
}
if (filter.operator === "isempty") {
format = "{2} = ''";
} else if (filter.operator === "isnotempty") {
format = "{2} != ''";
}
} else {
if (filter.operator === "isnull") {
format = "{2} IS NULL";
} else if (filter.operator === "isnotnull") {
format = "{2} IS NOT NULL";
} else {
format = "{2} {0} NULL";
}
}
// format, operator {0}, value {1}, field {2}
filterStr = progress.util._format(format, operator, value, field);
}
}
result.push(filterStr);
}
filterStr = result.join(" " + logic + " ");
if (result.length > 1) {
filterStr = "(" + filterStr + ")";
}
if (addSelect === true) {
filterStr = "SELECT * FROM " + tableRef._name + " WHERE " + filterStr;
}
return filterStr;
};
/*
* Returns the object type; Example "String", "Date"
* Constants for object type values are defined above.
*
* @param value - the object whose type is returned
*/
progress.util._getObjectType = function (value) {
// Returns [object xxx]. Removing [object ]
return Object.prototype.toString.call(value).slice(8, -1);
};
/*
* Substitutes in a variable number of arguments into specified format string (with place-holders)
*
* @param fmt - the format string with place-holders, eg. "{0} text {1}".
*
* @returns - formatted string.
*/
progress.util._format = function (fmt) {
/*jslint regexp: true*/
var values = arguments,
formatRegExp = /\{(\d+)(:[^\}]+)?\}/g;
/*jslint regexp: false*/
return fmt.replace(formatRegExp, function (match, index, placeholderFormat) {
var value = values[parseInt(index, 10) + 1];
return progress.util._toString(value, placeholderFormat ? placeholderFormat.substring(1) : "");
});
};
/*
* Converts the specified value param to a string.
*
* @param value - object to convert
* @param fmt - optional format string with place-holders, eg. "MM dd yyyy".
*
* @returns - converted string.
*/
progress.util._toString = function (value, fmt) {
var str;
if (fmt) {
if (progress.util._getObjectType(value) === "Date") {
return progress.util._formatDate(value, fmt);
}
}
if (typeof value === "number") {
str = value.toString();
} else {
str = value !== undefined ? value : "";
}
return str;
};
/*
* Accepts string representing number and optionally pads it with "0"'s to conform to
* specified number of digits.
*
* @param number - string representing number to pad.
* @param digit - number of digits desired for padded string. If not specified, default is 2.
*
* @returns - padded string representing number.
*/
progress.util._pad = function (number, digits) {
var zeros = ["", "0", "00", "000", "0000"],
end;
number = String(number);
digits = digits || 2;
end = digits - number.length;
if (end) {
return zeros[digits].substring(0, end) + number;
}
return number;
};
/*
* Converts the specified date param to a string.
*
* @param date - date object to convert
* @param fmt - format string with place-holders, eg. "MM dd yyyy".
*
* @returns - converted string.
*/
progress.util._formatDate = function (date, format) {
/*jslint regexp: true*/
var dateFormatRegExp = /dd|MM|yyyy|hh|mm|fff|FFF|ss|zzz|iso|"[^"]*"|'[^']*'/g;
/*jslint regexp: false*/
return format.replace(dateFormatRegExp, function (match) {
var minutes, result, sign;
if (match === "dd") {
result = progress.util._pad(date.getDate());
} else if (match === "MM") {
result = progress.util._pad(date.getMonth() + 1);
} else if (match === "yyyy") {
result = progress.util._pad(date.getFullYear(), 4);
} else if (match === "hh") {
result = progress.util._pad(date.getHours());
} else if (match === "mm") {
result = progress.util._pad(date.getMinutes());
} else if (match === "ss") {
result = progress.util._pad(date.getSeconds());
} else if (match === "fff") {
result = progress.util._pad(date.getMilliseconds(), 3);
} else if (match === "FFF") {
result = String(date.getTime());
} else if (match === "zzz") {
// timezone is returned in minutes
minutes = date.getTimezoneOffset();
sign = minutes < 0;
result = (sign ? "+" : "-") + minutes;
} else if (match === "iso") {
result = date.toISOString();
}
return result !== undefined ? result : match.slice(1, match.length - 1);
});
};
/*
* Processes settings in a jsdoSettings object.
* This method is used by project templates.
*/
progress.util.jsdoSettingsProcessor = function jsdoSettingsProcessor(jsdoSettings) {
if ((typeof jsdoSettings === "undefined" ? "undefined" : _typeof(jsdoSettings)) === 'object') {
if (jsdoSettings.authenticationModel === undefined || jsdoSettings.authenticationModel === "") {
jsdoSettings.authenticationModel = "ANONYMOUS";
}
}
};
})();
/***/ }),
/* 3 */
/***/ (function(module, exports, __webpack_require__) {
/*** IMPORTS FROM imports-loader ***/
var {default:progress} = __webpack_require__(1);
"use strict";
var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; };
/*
progress.session.js Version: 4.4.1-2
Copyright (c) 2012-2017 Progress Software Corporation and/or its subsidiaries or affiliates.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
(function () {
/* define these if not defined yet - they may already be defined if
progress.js was included first */
if (typeof progress === "undefined") {
progress = {};
}
if (typeof progress.data === "undefined") {
progress.data = {};
}
progress.data.ServicesManager = {};
progress.data.ServicesManager._services = [];
progress.data.ServicesManager._resources = [];
progress.data.ServicesManager._data = [];
progress.data.ServicesManager._sessions = [];
progress.data.ServicesManager._jsdosessions = [];
/*
progress.data.ServicesManager.put = function(id, jsdo) {
progress.data.ServicesManager._data[id] = jsdo;
};
progress.data.ServicesManager.get = function(id) {
return progress.data.ServicesManager._data[id];
};
*/
progress.data.ServicesManager.addResource = function (id, resource) {
if (progress.data.ServicesManager._resources[id] === undefined) progress.data.ServicesManager._resources[id] = resource;else throw new Error("A resource named '" + id + "' was already loaded.");
};
progress.data.ServicesManager.getResource = function (id) {
return progress.data.ServicesManager._resources[id];
};
progress.data.ServicesManager.addService = function (id, service) {
if (progress.data.ServicesManager._services[id] === undefined) progress.data.ServicesManager._services[id] = service;else throw new Error("A service named '" + id + "' was already loaded.");
};
progress.data.ServicesManager.getService = function (id) {
return progress.data.ServicesManager._services[id];
};
progress.data.ServicesManager.addSession = function (catalogURI, session) {
if (progress.data.ServicesManager._sessions[catalogURI] === undefined) progress.data.ServicesManager._sessions[catalogURI] = session;else throw new Error("Cannot load catalog '" + catalogURI + "' multiple times.");
};
progress.data.ServicesManager.addJSDOSession = function (catalogURI, jsdosession) {
if (progress.data.ServicesManager._jsdosessions[catalogURI] === undefined) {
progress.data.ServicesManager._jsdosessions[catalogURI] = jsdosession;
} else {
throw new Error("Cannot load catalog '" + catalogURI + "' multiple times.");
}
};
progress.data.ServicesManager.getSession = function (catalogURI) {
try {
return progress.data.ServicesManager._sessions[catalogURI];
} catch (e) {
return null;
}
};
progress.data.ServicesManager.cleanSession = function (session) {
var servicesKey,
resourcesKey,
sessionsKey,
service,
services = progress.data.ServicesManager._services,
resources = progress.data.ServicesManager._resources,
sessions = progress.data.ServicesManager._sessions,
jsdosessions = progress.data.ServicesManager._jsdosessions;
// Delete the services and resources in the ServicesManager
// associated with the Session given
for (servicesKey in services) {
service = null;
if (services[servicesKey]._session === session) {
service = services[servicesKey];
delete services[servicesKey];
}
if (!service) {
continue;
}
for (resourcesKey in resources) {
if (resources[resourcesKey].service === service) {
delete resources[resourcesKey];
}
}
}
// Delete the session and jsdosession from the ServicesManager
for (sessionsKey in sessions) {
if (sessions[sessionsKey] === session) {
delete sessions[sessionsKey];
if (jsdosessions[sessionsKey]) {
delete jsdosessions[sessionsKey];
}
}
}
};
/*
* Scans URL for parameters of the form {name}
* Returns array with the names
*/
function extractParamsFromURL(url) {
var urlParams = [];
if (typeof url == 'string') {
var paramName = null;
for (var i = 0; i < url.length; i++) {
if (url.charAt(i) == '{') {
paramName = "";
} else if (url.charAt(i) == '}') {
if (paramName) urlParams.push(paramName);
paramName = null;
} else if (paramName !== null) {
paramName += url.charAt(i);
}
}
}
return urlParams;
}
/*
* Adds the catalog.json file provided by the catalog parameter, which is a JSDO
* that has loaded the catalog
*/
progress.data.ServicesManager.addCatalog = function (services, session) {
if (!services) {
throw new Error("Cannot find 'services' property in catalog file.");
}
if (services instanceof Array) {
// first check if there are duplicates before we add them to our cache,
// which only handles unique values
for (var j = 0; j < services.length; j++) {
// don't allow services with the same name across sessions
if (progress.data.ServicesManager.getService(services[j].name) !== undefined) throw new Error("A service named '" + services[j].name + "' was already loaded.");
var resources = services[j].resources;
if (resources instanceof Array) {
for (var i = 0; i < resources.length; i++) {
if (progress.data.ServicesManager.getResource(resources[i].name) !== undefined) throw new Error("A resource named '" + resources[i].name + "' was already loaded.");
}
} else {
throw new Error("Missing 'resources' array in catalog.");
}
}
for (var j = 0; j < services.length; j++) {
services[j]._session = session;
this.addService(services[j].name, services[j]); // Register the service
var resources = services[j].resources;
var baseAddress = services[j].address;
if (resources instanceof Array) {
for (var i = 0; i < resources.length; i++) {
var resource = resources[i];
resource.fn = {};
resource.service = services[j];
resources[i].url = baseAddress + resources[i].path;
// Register resource
progress.data.ServicesManager.addResource(resources[i].name, resources[i]);
// Process schema
resource.fields = null;
resource.primaryKeys = null;
if (resource.schema) {
resource.fields = {};
resource.primaryKeys = {};
resource._dataSetName = undefined;
resource._tempTableName = undefined;
var properties = null;
try {
if (typeof resource.schema.properties != 'undefined') {
var keys = Object.keys(resource.schema.properties);
properties = resource.schema.properties;
if (keys.length == 1) {
if (typeof resource.schema.properties[keys[0]].properties != 'undefined') {
// Schema corresponds to a DataSet
resource._dataSetName = keys[0];
} else if (typeof resource.schema.properties[keys[0]].items != 'undefined') {
// Schema corresponds to a temp-table
resource.dataProperty = keys[0];
properties = resource.schema.properties[keys[0]].items.properties;
resource._tempTableName = resource.dataProperty;
resource.primaryKeys[resource._tempTableName] = resource.schema.properties[keys[0]].primaryKey;
}
}
} else {
var keys = Object.keys(resource.schema);
if (keys.length == 1) {
resource.dataProperty = keys[0];
if (typeof resource.schema[keys[0]].items != 'undefined') {
// Catalog format correspond to Table Schema
properties = resource.schema[keys[0]].items.properties;
resource._tempTableName = resource.dataProperty;
resource.primaryKeys[resource._tempTableName] = resource.schema[keys[0]].primaryKey;
} else if (typeof resource.schema[keys[0]].properties != 'undefined') {
// Catalog format correspond to DataSet Schema
resource._dataSetName = keys[0];
resource.dataProperty = null;
properties = resource.sche