diff --git a/.gitignore b/.gitignore index 2556d792..606ad516 100644 --- a/.gitignore +++ b/.gitignore @@ -8,4 +8,5 @@ /hooks /out .idea -*.iml \ No newline at end of file +*.iml +dist diff --git a/Gruntfile.js b/Gruntfile.js index 39c60592..32ec3873 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -1,36 +1,39 @@ -module.exports = function(grunt) { +module.exports = function (grunt) { - var fs = require("fs"); - var path = require("path"); + const fs = require("fs"); + const path = require("path"); - var WEB_SERVER_HOST = "test.cloudcms.com"; - var WEB_SERVER_PORT = 8000; - var WEB_SERVER_BASE_PATH = "."; + const WEB_SERVER_HOST = "0.0.0.0"; + const WEB_SERVER_PORT = 8000; + const WEB_SERVER_BASE_PATH = "."; - var PROXY_HOST = "test.cloudcms.com"; - var PROXY_PORT = 8080; - var PROXY_TIMEOUT = 5 * 60 * 1000; + const PROXY_HOST = "test.cloudcms.net"; + const PROXY_PORT = 8080; + const PROXY_TIMEOUT = 5 * 60 * 1000; grunt.loadNpmTasks('grunt-contrib-connect'); grunt.loadNpmTasks('grunt-connect-proxy'); - grunt.loadNpmTasks('grunt-closure-compiler'); grunt.loadNpmTasks('grunt-jsdoc'); grunt.loadNpmTasks('grunt-aws-s3'); grunt.loadNpmTasks('grunt-invalidate-cloudfront'); grunt.loadNpmTasks('grunt-release'); grunt.loadNpmTasks('grunt-bumpup'); + grunt.loadNpmTasks('grunt-contrib-jshint'); + grunt.loadNpmTasks('grunt-contrib-qunit'); + grunt.loadNpmTasks('grunt-exec'); + grunt.loadNpmTasks('grunt-terser'); // register one or more task lists (you should ALWAYS have a "default" task list) - grunt.registerTask('test', ['configureProxies:testing', 'connect:testing', 'qunit']); + grunt.registerTask('test', ['configureProxies:testing' ,'connect:testing', 'qunit']); grunt.registerTask('web', ['configureProxies:standalone', 'connect:standalone']); - grunt.registerTask('closure', ['closure-compiler']); grunt.registerTask('cdn', ['aws_s3:clean_version', 'aws_s3:clean_latest', 'aws_s3:publish_version', 'aws_s3:publish_latest', 'invalidate_cloudfront:production_version', 'invalidate_cloudfront:production_latest']); grunt.registerTask('bump', ['bumpup', 'writeVersionProperties']); + grunt.registerTask('clean-package-compress', ['exec:antClean', 'exec:antPackage', 'terser']); - var pkg = grunt.file.readJSON('package.json'); + const pkg = grunt.file.readJSON('package.json'); // aws configuration - var awsConfig = { + let awsConfig = { cloudfrontDistributionIds: [] }; try { @@ -39,56 +42,54 @@ module.exports = function(grunt) { } // github configuration - var githubConfig = {}; + let githubConfig = {}; try { githubConfig = grunt.file.readJSON("../settings/__github.json"); + } catch (e) { } - catch (e) {} process.env.GITHUB_USERNAME = githubConfig.username; process.env.GITHUB_PASSWORD = githubConfig.password; - var name = "gitana-javascript-driver"; - + const name = "gitana-javascript-driver"; + // injects a proxy into the middleware stack - var middleware = function(connect, options) - { - // default - var middlewares = []; - var directory = options.directory || options.base[options.base.length - 1]; + middleware = function (connect, options) { + + // Setup the proxy + const middlewares = [require('grunt-connect-proxy/lib/utils').proxyRequest]; + + // Serve static files. if (!Array.isArray(options.base)) { options.base = [options.base]; } options.base.forEach(function(base) { - // Serve static files. middlewares.push(connect.static(base)); }); + // Make directory browse-able. + const directory = options.directory || options.base[options.base.length - 1]; middlewares.push(connect.directory(directory)); - - // push our proxy logic ahead on the middlewares - var proxy = require('grunt-connect-proxy/lib/utils').proxyRequest; - middlewares.unshift(proxy); - + return middlewares; }; - grunt.registerTask("writeVersionProperties", "Writes a version.properties file for ant to pick up", function() { + grunt.registerTask("writeVersionProperties", "Writes a version.properties file for ant to pick up", function () { - var pkg = grunt.file.readJSON('package.json'); - var version = pkg.version; + const pkg = grunt.file.readJSON('package.json'); + const version = pkg.version; grunt.file.delete("version.properties"); fs.writeFileSync("version.properties", "version=" + version); }); // applies some cosmetic spacing - grunt.event.on('qunit.begin', function (url) { + grunt.event.on('qunit.begin', function () { grunt.log.ok(""); }); // config - grunt.initConfig({ + grunt.config.init({ "qunit": { "all": { @@ -127,6 +128,7 @@ module.exports = function(grunt) { }, "testing": { "options": { + "logger": "dev", "base": WEB_SERVER_BASE_PATH, "hostname": WEB_SERVER_HOST, "port": WEB_SERVER_PORT, @@ -148,20 +150,20 @@ module.exports = function(grunt) { }, "jshint": { - "gitana": { - "options": { - "multistr": true, - "scripturl": true, - "laxcomma": true, - "-W069": true, // "['variable'] is better written in dot notation - "-W041": true, // "Use '===' to compare with null or 0 - "-W004": true, // duplicate variables - "-W014": true, // line breaking + - "-W065": true, // radix - "-W083": true // functions in loops - }, - src: ["js/gitana/**/*.js"] - } + "options": { + "multistr": true, + "scripturl": true, + "laxcomma": true, + "-W069": true, // "["constiable"] is better written in dot notation + "-W041": true, // "Use "===" to compare with null or 0 + "-W004": true, // duplicate constiables + "-W014": true, // line breaking + + "-W065": true, // radix + "-W083": true, // functions in loops + "esversion": 6 + }, + all: ["js/gitana/**/*.js"] + }, "closure-compiler": { @@ -298,6 +300,28 @@ module.exports = function(grunt) { "passwordVar": "GITHUB_PASSWORD" } } + }, + "exec": { + "antClean": { + "command": "ant clean" + }, + "antPackage": { + "command": "ant package" + } + }, + "terser": { + "options": { + "compress": { + "passes": 3 + }, + "ecma": 6, + "output": { + "beautify": false + }, + "toplevel": true, + "module": true + }, + "./dist/gitana.min.js": ["./js/gitana/**/*.js"] } }); diff --git a/README.md b/README.md index 60c38819..d0845206 100644 --- a/README.md +++ b/README.md @@ -149,7 +149,7 @@ This will install the latest versions of Grunt and all Grunt and Node.js depende Then, to build, run the following: ```` -ant clean package +grunt clean-package-compress ```` This will produce the latest gitana.js and gitana.min.js files in your dist diff --git a/bower.json b/bower.json index cf7a5ad3..55d2a4d0 100644 --- a/bower.json +++ b/bower.json @@ -1,7 +1,7 @@ { "name": "gitana", "description": "Gitana JavaScript Driver for Cloud CMS", - "version": "1.0.305", + "version": "1.0.307", "main": "dist/gitana.js", "license": "Apache-2.0", "keywords": [ diff --git a/build.xml b/build.xml index 9aea9999..7758c07b 100644 --- a/build.xml +++ b/build.xml @@ -13,8 +13,6 @@ - - @@ -314,24 +312,7 @@ - - Compressing Javascript... - - - - - - - - - - - - - - - - + diff --git a/component.json b/component.json index b5c53167..ddb649a8 100644 --- a/component.json +++ b/component.json @@ -1,6 +1,6 @@ { "name": "gitana", - "version": "1.0.305", + "version": "1.0.307", "main": [ "dist/gitana.js" ], diff --git a/dist/gitana.js b/dist/gitana.js new file mode 100644 index 00000000..7f1e87cf --- /dev/null +++ b/dist/gitana.js @@ -0,0 +1,35962 @@ +/* +Gitana JavaScript Driver - Version 1.0.304 + +Copyright 2019 Gitana Software, Inc. + +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. + +For more information, please contact Gitana Software, Inc. at this +address: + + info@cloudcms.com +*/ +/** + * UMD wrapper for compatibility with browser, Node and AMD. + * + * Based on: + * https://github.com/umdjs/umd/blob/master/returnExports.js + */ +(function (root, factory) +{ + if (typeof exports === 'object') + { + // Node. Does not work with strict CommonJS, but + // only CommonJS-like environments that support module.exports, + // like Node. + //module.exports = factory(require('b')); + module.exports = factory(); + } + else if (typeof define === 'function' && define.amd) + { + // AMD. Register as an anonymous module. + //define(['b'], factory); + define('gitana', [], factory); + } + else + { + // Browser globals + //root.returnExports = factory(root.b); + root["Gitana"] = factory(); + } + +}(this, function () { + + //use b in some fashion. + + // Just return a value to define the module export. + // This example returns an object, but the module + // can return a function as the exported value. + //return {}; + + /** + * This gets added into the Gitana Driver to ensure compilation time compatibility with + * the Appcelerator Titanium framework. + */ +/* jQuery Sizzle - these are to fool the Ti compiler into not reporting errors! */ + +/** + * The driver assumes a globally-scoped "window" variable which is a legacy of browser-compatibility. + * Frameworks such as Titanium do not have a window root-scoped variable, so we fake one. + * + * At minimum, the window variable must have a setTimeout variable. + */ +if (typeof window === "undefined") +{ + window = { + "setTimeout": function(func, milliseconds) + { + setTimeout(func, milliseconds); + } + }; +} +/* + Based on Base.js 1.1a (c) 2006-2010, Dean Edwards + Updated to pass JSHint and converted into a module by Kenneth Powers + License: http://www.opensource.org/licenses/mit-license.php + + GitHub: https://github.com/KenPowers/Base.js-Module + */ +/*global define:true module:true*/ +/*jshint eqeqeq:true*/ +(function (name, global, definition) { +// if (typeof module !== 'undefined') { +// module.exports = definition(); +// } else if (typeof define !== 'undefined' && typeof define.amd === 'object') { +// define(definition); +// } else { + global[name] = definition(); +// } +})('Base', this, function () { + // Base Object + var Base = function () {}; + + // Implementation + Base.extend = function (_instance, _static) { // subclass + const extend = Base.prototype.extend; + // build the prototype + Base._prototyping = true; + const proto = new this(); + extend.call(proto, _instance); + proto.base = function () { + // call this method from any other method to invoke that method's ancestor + }; + delete Base._prototyping; + // create the wrapper for the constructor function + //const constructor = proto.constructor.valueOf(); //-dean + const constructor = proto.constructor; + const klass = proto.constructor = function () { + if (!Base._prototyping) { + if (this._constructing || this.constructor === klass) { // instantiation + this._constructing = true; + constructor.apply(this, arguments); + delete this._constructing; + } else if (arguments[0] !== null) { // casting + return (arguments[0].extend || extend).call(arguments[0], proto); + } + } + }; + // build the class interface + klass.ancestor = this; + klass.extend = this.extend; + klass.forEach = this.forEach; + klass.implement = this.implement; + klass.prototype = proto; + klass.toString = this.toString; + klass.valueOf = function (type) { + return (type === 'object') ? klass : constructor.valueOf(); + }; + extend.call(klass, _static); + // class initialization + if (typeof klass.init === 'function') klass.init(); + return klass; + }; + + Base.prototype = { + extend: function (source, value) { + if (arguments.length > 1) { // extending with a name/value pair + const ancestor = this[source]; + if (ancestor && (typeof value === 'function') && // overriding a method? + // the valueOf() comparison is to avoid circular references + (!ancestor.valueOf || ancestor.valueOf() !== value.valueOf()) && /\bbase\b/.test(value)) { + // get the underlying method + const method = value.valueOf(); + // override + value = function () { + const previous = this.base || Base.prototype.base; + this.base = ancestor; + const returnValue = method.apply(this, arguments); + this.base = previous; + return returnValue; + }; + // point to the underlying method + value.valueOf = function (type) { + return (type === 'object') ? value : method; + }; + value.toString = Base.toString; + } + this[source] = value; + } else if (source) { // extending with an object literal + let extend = Base.prototype.extend; + // if this object has a customized extend method then use it + if (!Base._prototyping && typeof this !== 'function') { + extend = this.extend || extend; + } + const proto = { + toSource: null + }; + // do the "toString" and other methods manually + const hidden = ['constructor', 'toString', 'valueOf']; + // if we are prototyping then include the constructor + for (let i = Base._prototyping ? 0 : 1; i < hidden.length; i++) { + const h = hidden[i]; + if (source[h] !== proto[h]) + extend.call(this, h, source[h]); + } + // copy each of the source object's properties to this object + for (let key in source) { + if (!proto[key]) extend.call(this, key, source[key]); + } + } + return this; + } + }; + + // initialize + Base = Base.extend({ + constructor: function () { + this.extend(arguments[0]); + } + }, { + ancestor: Object, + version: '1.1', + forEach: function (object, block, context) { + for (let key in object) { + if (this.prototype[key] === undefined) { + block.call(context, object[key], key, object); + } + } + }, + implement: function () { + for (let i = 0; i < arguments.length; i++) { + if (typeof arguments[i] === 'function') { + // if it's a function, call it + arguments[i](this.prototype); + } else { + // add the interface using the extend method + this.prototype.extend(arguments[i]); + } + } + return this; + }, + toString: function () { + return String(this.valueOf()); + } + }); + + // Return Base implementation + return Base; +});/* + json2.js + 2012-10-08 + + Public Domain. + + NO WARRANTY EXPRESSED OR IMPLIED. USE AT YOUR OWN RISK. + + See http://www.JSON.org/js.html + + + This code should be minified before deployment. + See http://javascript.crockford.com/jsmin.html + + USE YOUR OWN COPY. IT IS EXTREMELY UNWISE TO LOAD CODE FROM SERVERS YOU DO + NOT CONTROL. + + + This file creates a global JSON object containing two methods: stringify + and parse. + + JSON.stringify(value, replacer, space) + value any JavaScript value, usually an object or array. + + replacer an optional parameter that determines how object + values are stringified for objects. It can be a + function or an array of strings. + + space an optional parameter that specifies the indentation + of nested structures. If it is omitted, the text will + be packed without extra whitespace. If it is a number, + it will specify the number of spaces to indent at each + level. If it is a string (such as '\t' or ' '), + it contains the characters used to indent at each level. + + This method produces a JSON text from a JavaScript value. + + When an object value is found, if the object contains a toJSON + method, its toJSON method will be called and the result will be + stringified. A toJSON method does not serialize: it returns the + value represented by the name/value pair that should be serialized, + or undefined if nothing should be serialized. The toJSON method + will be passed the key associated with the value, and this will be + bound to the value + + For example, this would serialize Dates as ISO strings. + + Date.prototype.toJSON = function (key) { + function f(n) { + // Format integers to have at least two digits. + return n < 10 ? '0' + n : n; + } + + return this.getUTCFullYear() + '-' + + f(this.getUTCMonth() + 1) + '-' + + f(this.getUTCDate()) + 'T' + + f(this.getUTCHours()) + ':' + + f(this.getUTCMinutes()) + ':' + + f(this.getUTCSeconds()) + 'Z'; + }; + + You can provide an optional replacer method. It will be passed the + key and value of each member, with this bound to the containing + object. The value that is returned from your method will be + serialized. If your method returns undefined, then the member will + be excluded from the serialization. + + If the replacer parameter is an array of strings, then it will be + used to select the members to be serialized. It filters the results + such that only members with keys listed in the replacer array are + stringified. + + Values that do not have JSON representations, such as undefined or + functions, will not be serialized. Such values in objects will be + dropped; in arrays they will be replaced with null. You can use + a replacer function to replace those with JSON values. + JSON.stringify(undefined) returns undefined. + + The optional space parameter produces a stringification of the + value that is filled with line breaks and indentation to make it + easier to read. + + If the space parameter is a non-empty string, then that string will + be used for indentation. If the space parameter is a number, then + the indentation will be that many spaces. + + Example: + + text = JSON.stringify(['e', {pluribus: 'unum'}]); + // text is '["e",{"pluribus":"unum"}]' + + + text = JSON.stringify(['e', {pluribus: 'unum'}], null, '\t'); + // text is '[\n\t"e",\n\t{\n\t\t"pluribus": "unum"\n\t}\n]' + + text = JSON.stringify([new Date()], function (key, value) { + return this[key] instanceof Date ? + 'Date(' + this[key] + ')' : value; + }); + // text is '["Date(---current time---)"]' + + + JSON.parse(text, reviver) + This method parses a JSON text to produce an object or array. + It can throw a SyntaxError exception. + + The optional reviver parameter is a function that can filter and + transform the results. It receives each of the keys and values, + and its return value is used instead of the original value. + If it returns what it received, then the structure is not modified. + If it returns undefined then the member is deleted. + + Example: + + // Parse the text. Values that look like ISO date strings will + // be converted to Date objects. + + myData = JSON.parse(text, function (key, value) { + const a; + if (typeof value === 'string') { + a = + /^(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2}):(\d{2}(?:\.\d*)?)Z$/.exec(value); + if (a) { + return new Date(Date.UTC(+a[1], +a[2] - 1, +a[3], +a[4], + +a[5], +a[6])); + } + } + return value; + }); + + myData = JSON.parse('["Date(09/09/2001)"]', function (key, value) { + const d; + if (typeof value === 'string' && + value.slice(0, 5) === 'Date(' && + value.slice(-1) === ')') { + d = new Date(value.slice(5, -1)); + if (d) { + return d; + } + } + return value; + }); + + + This is a reference implementation. You are free to copy, modify, or + redistribute. + */ + +/*jslint evil: true, regexp: true */ + +/*members "", "\b", "\t", "\n", "\f", "\r", "\"", JSON, "\\", apply, + call, charCodeAt, getUTCDate, getUTCFullYear, getUTCHours, + getUTCMinutes, getUTCMonth, getUTCSeconds, hasOwnProperty, join, + lastIndex, length, parse, prototype, push, replace, slice, stringify, + test, toJSON, toString, valueOf + */ + + +// Create a JSON object only if one does not already exist. We create the +// methods in a closure to avoid creating global variables. + +if (typeof JSON !== 'object') { + JSON = {}; +} + +(function () { + 'use strict'; + + function f(n) { + // Format integers to have at least two digits. + return n < 10 ? '0' + n : n; + } + + if (typeof Date.prototype.toJSON !== 'function') { + + Date.prototype.toJSON = function (key) { + + return isFinite(this.valueOf()) + ? this.getUTCFullYear() + '-' + + f(this.getUTCMonth() + 1) + '-' + + f(this.getUTCDate()) + 'T' + + f(this.getUTCHours()) + ':' + + f(this.getUTCMinutes()) + ':' + + f(this.getUTCSeconds()) + 'Z' + : null; + }; + + String.prototype.toJSON = + Number.prototype.toJSON = + Boolean.prototype.toJSON = function (key) { + return this.valueOf(); + }; + } + + let cx = /[\u0000\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g, + escapable = /[\\\"\x00-\x1f\x7f-\x9f\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g, + gap, + indent, + meta = { // table of character substitutions + '\b': '\\b', + '\t': '\\t', + '\n': '\\n', + '\f': '\\f', + '\r': '\\r', + '"' : '\\"', + '\\': '\\\\' + }, + rep; + + + function quote(string) { + +// If the string contains no control characters, no quote characters, and no +// backslash characters, then we can safely slap some quotes around it. +// Otherwise we must also replace the offending characters with safe escape +// sequences. + + escapable.lastIndex = 0; + return escapable.test(string) ? '"' + string.replace(escapable, function (a) { + const c = meta[a]; + return typeof c === 'string' + ? c + : '\\u' + ('0000' + a.charCodeAt(0).toString(16)).slice(-4); + }) + '"' : '"' + string + '"'; + } + + + function str(key, holder) { + +// Produce a string from holder[key]. + + let i, // The loop counter. + k, // The member key. + v, // The member value. + length, + mind = gap, + partial, + value = holder[key]; + +// If the value has a toJSON method, call it to obtain a replacement value. + + if (value && typeof value === 'object' && + typeof value.toJSON === 'function') { + value = value.toJSON(key); + } + +// If we were called with a replacer function, then call the replacer to +// obtain a replacement value. + + if (typeof rep === 'function') { + value = rep.call(holder, key, value); + } + +// What happens next depends on the value's type. + + switch (typeof value) { + case 'string': + return quote(value); + + case 'number': + +// JSON numbers must be finite. Encode non-finite numbers as null. + + return isFinite(value) ? String(value) : 'null'; + + case 'boolean': + case 'null': + +// If the value is a boolean or null, convert it to a string. Note: +// typeof null does not produce 'null'. The case is included here in +// the remote chance that this gets fixed someday. + + return String(value); + +// If the type is 'object', we might be dealing with an object or an array or +// null. + + case 'object': + +// Due to a specification blunder in ECMAScript, typeof null is 'object', +// so watch out for that case. + + if (!value) { + return 'null'; + } + +// Make an array to hold the partial results of stringifying this object value. + + gap += indent; + partial = []; + +// Is the value an array? + + if (Object.prototype.toString.apply(value) === '[object Array]') { + +// The value is an array. Stringify every element. Use null as a placeholder +// for non-JSON values. + + length = value.length; + for (i = 0; i < length; i += 1) { + partial[i] = str(i, value) || 'null'; + } + +// Join all of the elements together, separated with commas, and wrap them in +// brackets. + + v = partial.length === 0 + ? '[]' + : gap + ? '[\n' + gap + partial.join(',\n' + gap) + '\n' + mind + ']' + : '[' + partial.join(',') + ']'; + gap = mind; + return v; + } + +// If the replacer is an array, use it to select the members to be stringified. + + if (rep && typeof rep === 'object') { + length = rep.length; + for (i = 0; i < length; i += 1) { + if (typeof rep[i] === 'string') { + k = rep[i]; + v = str(k, value); + if (v) { + partial.push(quote(k) + (gap ? ': ' : ':') + v); + } + } + } + } else { + +// Otherwise, iterate through all of the keys in the object. + + for (k in value) { + if (Object.prototype.hasOwnProperty.call(value, k)) { + v = str(k, value); + if (v) { + partial.push(quote(k) + (gap ? ': ' : ':') + v); + } + } + } + } + +// Join all of the member texts together, separated with commas, +// and wrap them in braces. + + v = partial.length === 0 + ? '{}' + : gap + ? '{\n' + gap + partial.join(',\n' + gap) + '\n' + mind + '}' + : '{' + partial.join(',') + '}'; + gap = mind; + return v; + } + } + +// If the JSON object does not yet have a stringify method, give it one. + + if (typeof JSON.stringify !== 'function') { + JSON.stringify = function (value, replacer, space) { + +// The stringify method takes a value and an optional replacer, and an optional +// space parameter, and returns a JSON text. The replacer can be a function +// that can replace values, or an array of strings that will select the keys. +// A default replacer method can be provided. Use of the space parameter can +// produce text that is more easily readable. + + let i; + gap = ''; + indent = ''; + +// If the space parameter is a number, make an indent string containing that +// many spaces. + + if (typeof space === 'number') { + for (i = 0; i < space; i += 1) { + indent += ' '; + } + +// If the space parameter is a string, it will be used as the indent string. + + } else if (typeof space === 'string') { + indent = space; + } + +// If there is a replacer, it must be a function or an array. +// Otherwise, throw an error. + + rep = replacer; + if (replacer && typeof replacer !== 'function' && + (typeof replacer !== 'object' || + typeof replacer.length !== 'number')) { + throw new Error('JSON.stringify'); + } + +// Make a fake root object containing our value under the key of ''. +// Return the result of stringifying the value. + + return str('', {'': value}); + }; + } + + +// If the JSON object does not yet have a parse method, give it one. + + if (typeof JSON.parse !== 'function') { + JSON.parse = function (text, reviver) { + +// The parse method takes a text and an optional reviver function, and returns +// a JavaScript value if the text is a valid JSON text. + + let j; + + function walk(holder, key) { + +// The walk method is used to recursively walk the resulting structure so +// that modifications can be made. + + let k, v, value = holder[key]; + if (value && typeof value === 'object') { + for (k in value) { + if (Object.prototype.hasOwnProperty.call(value, k)) { + v = walk(value, k); + if (v !== undefined) { + value[k] = v; + } else { + delete value[k]; + } + } + } + } + return reviver.call(holder, key, value); + } + + +// Parsing happens in four stages. In the first stage, we replace certain +// Unicode characters with escape sequences. JavaScript handles many characters +// incorrectly, either silently deleting them, or treating them as line endings. + + text = String(text); + cx.lastIndex = 0; + if (cx.test(text)) { + text = text.replace(cx, function (a) { + return '\\u' + + ('0000' + a.charCodeAt(0).toString(16)).slice(-4); + }); + } + +// In the second stage, we run the text against regular expressions that look +// for non-JSON patterns. We are especially concerned with '()' and 'new' +// because they can cause invocation, and '=' because it can cause mutation. +// But just to be safe, we want to reject all unexpected forms. + +// We split the second stage into 4 regexp operations in order to work around +// crippling inefficiencies in IE's and Safari's regexp engines. First we +// replace the JSON backslash pairs with '@' (a non-JSON character). Second, we +// replace all simple value tokens with ']' characters. Third, we delete all +// open brackets that follow a colon or comma or that begin the text. Finally, +// we look to see that the remaining characters are only whitespace or ']' or +// ',' or ':' or '{' or '}'. If that is so, then the text is safe for eval. + + if (/^[\],:{}\s]*$/ + .test(text.replace(/\\(?:["\\\/bfnrt]|u[0-9a-fA-F]{4})/g, '@') + .replace(/"[^"\\\n\r]*"|true|false|null|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?/g, ']') + .replace(/(?:^|:|,)(?:\s*\[)+/g, ''))) { + +// In the third stage we use the eval function to compile the text into a +// JavaScript structure. The '{' operator is subject to a syntactic ambiguity +// in JavaScript: it can begin a block or an object literal. We wrap the text +// in parens to eliminate the ambiguity. + + j = eval('(' + text + ')'); + +// In the optional fourth stage, we recursively walk the new structure, passing +// each name/value pair to a reviver function for possible transformation. + + return typeof reviver === 'function' + ? walk({'': j}, '') + : j; + } + +// If the text is not JSON parseable, then a SyntaxError is thrown. + + throw new SyntaxError('JSON.parse'); + }; + } +}());(function(window) +{ + Gitana = Base.extend( + /** @lends Gitana.prototype */ + { + /** + * @constructs + * + * @class Gitana + * + * Configuration options should look like: + * + * @param settings + * @param settings.clientKey: {String} the oauth2 client id, + * @param settings.clientSecret: {String} the oauth2 client secret, + * @param settings.baseURL: {String} the relative URI path of the base URL (assumed to be "/proxy"), + * @param settings.locale: {String} optional locale (assumed to be en_US), + * @param settings.storage: {String|Object} Gitana.OAuth2.Storage implementation or a string identifying where to store + * Gitana OAuth2 tokens ("local", "session", "memory") or empty for memory-only storage + * @param settings.host {String} + * + */ + constructor: function(settings) + { + const self = this; + + if (!settings) + { + settings = {}; + } + + if (settings.host) + { + settings.baseURL = settings.host + "/proxy"; + } + + this.applicationInfo = {}; + this.stackInfo = {}; + + // build config + const config = { + "clientKey": null, + "clientSecret": null, + "baseURL": "/proxy", + "locale": (Gitana.DEFAULT_LOCALE ? Gitana.DEFAULT_LOCALE : null), + "application": null, + "loadAppHelper": true, + "storage": null + }; + if (Gitana.DEFAULT_CONFIG) + { + for (let k in Gitana.DEFAULT_CONFIG) + { + if (Gitana.DEFAULT_CONFIG.hasOwnProperty(k)) + { + config[k] = Gitana.DEFAULT_CONFIG[k]; + } + } + } + Gitana.copyKeepers(config, Gitana.loadDefaultConfig()); + Gitana.copyKeepers(config, settings); + + if (typeof(config.cacheBuster) === "undefined") + { + config.cacheBuster = true; + } + + // auto-migrate to support cloudfront + if (Gitana.AUTO_UPGRADE_TO_CLOUDFRONT) + { + if (config.baseURL) + { + config.baseURL = config.baseURL.replace("https://api.cloudcms.com", "https://api1.cloudcms.com"); + config.baseURL = config.baseURL.replace("http://api.cloudcms.com", "http://api1.cloudcms.com"); + } + } + + + ////////////////////////////////////////////////////////////////////////// + // + // APPLY CONFIGURATION SETTINGS + // + + // baseURL + this.baseURL = config.baseURL; + + // locale + this.locale = config.locale; + + + + + ////////////////////////////////////////////////////////////////////////// + // + // APPLY OAUTH2 SETTINGS + // + + // set up our oAuth2 connection + const options = {}; + if (config.clientKey) { + options.clientKey = config.clientKey; + } + if (config.clientSecret) { + options.clientSecret = config.clientSecret; + } + if (this.baseURL) + { + options.baseURL = this.baseURL; + options.tokenURL = "/oauth/token"; + } + // the driver requires the "api" scope to be granted + options.requestedScope = "api"; + + + + ////////////////////////////////////////////////////////////////////////// + // + // PRIVILEGED METHODS + // + // + + this.updateOptions = function(o) + { + if (o) + { + Gitana.copyInto(options, o); + } + }; + + this.resetHttp = function(config) + { + const o = {}; + Gitana.copyInto(o, options); + + if (config) + { + Gitana.copyInto(o, config); + } + + if (!o.storage) + { + o.storage = this.getOriginalConfiguration().storage; + } + + self.http = new Gitana.OAuth2Http(o, o.storage); + }; + + this.setAuthInfo = function(authInfo) + { + this.authInfo = authInfo; + }; + + this.setStackInfo = function(stackInfo) + { + this.stackInfo = stackInfo; + }; + + this.setApplicationInfo = function(applicationInfo) + { + this.applicationInfo = applicationInfo; + }; + + this.getOriginalConfiguration = function() + { + return config; + }; + + this.getHttpHeaders = function() + { + const self = this; + + const headers = {}; + + if (self.http && self.http.getBearerAuthorizationHeader()) + { + headers["Authorization"] = self.http.getBearerAuthorizationHeader(); + } + + return headers; + }; + }, + + /** + * Sets the authentication info + */ + getAuthInfo: function() + { + return this.authInfo; + }, + + getStackInfo: function() + { + return this.stackInfo; + }, + + getApplicationInfo: function() + { + return this.applicationInfo; + }, + + /** + * Sets the default locale for interactions with the Gitana server by this driver. + * + * @public + * + * @param {String} locale locale string + */ + setLocale: function(locale) + { + this.locale = locale; + }, + + /** + * Retrieves the default locale being used by this driver. + * + * @returns {String} locale string + */ + getLocale: function() + { + return this.locale; + }, + + /** + * Default AJAX failure callback + * + * @public + */ + defaultFailureCallback: function(http) + { + // if we're in debug mode, log a bunch of good stuff out to console + if (this.debug) + { + if (typeof console != "undefined") + { + let message = "Received bad http state (" + http.status + ")"; + let stacktrace = null; + + let json = null; + + const responseText = http.responseText; + if (responseText) + { + json = JSON.parse(responseText); + if (json && json.message) + { + message = message + ": " + json.message; + } + } + + if (json && json["stacktrace"]) + { + stacktrace = json["stacktrace"]; + } + + console.log(message); + if (stacktrace) + { + console.log(stacktrace); + } + } + } + }, + + + /** + * Performs Ajax communication with the Gitana server. + * + * NOTE: For the most part, you shouldn't have to use this function since most of the things you'd want + * to do with the Gitana server are wrapped by helper functions. + * + * @see Gitana.Driver#gitanaGet + * @see Gitana.Driver#gitanaPost + * @see Gitana.Driver#gitanaPut + * @see Gitana.Driver#gitanaDel + * @see Gitana.Driver#gitanaRequest + * + * @public + * + * @param {String} method The kind of method to invoke - "get", "post", "put", or "del" + * @param {String} url The full URL to the resource being requested (i.e. "http://server:port/uri"} + * @param {String} [contentType] In the case of a payload carrying request (i.e. not GET), the content type being sent. + * @param {Object} [data] In the case of a payload carrying request (i.e. not GET), the data to plug into the payload. + * @param {Object} [headers] A key/value map of headers to place into the request. + * @param {Function} [successCallback] The function to call if the operation succeeds. + * @param {Function} [failureCallback] The function to call if the operation fails. If none provided, the default driver callback is used. + */ + ajax: function(method, url, contentType, data, headers, successCallback, failureCallback) + { + + // ensure headers + if (!headers) + { + headers = {}; + } + + // treat the method + if (method === null) { + method = "GET"; + } + method = method.toUpperCase(); + + // flags + let json = false; + if (contentType === "application/json") + { + json = true; + } + + // error checking + if ( (method === "POST" || method === "PUT") ) + { + headers["Content-Type"] = contentType; + if (!contentType) + { + Gitana.debug("Performing method: " + method + " but missing content type"); + return; + } + } + + let toSend = data; + + // special handling for json + if (json) + { + // if empty payload for payload-bearing methods, populate with {} + if (method === "PUT" || method === "POST") + { + if (!data) + { + data = {}; + } + } + + if (!Gitana.isString(data)) + { + // stringify + toSend = Gitana.stringify(data); + } + } + + // + // if the URL is relative and we're running in a browser, then we can pad the URL + // based on the URL of the browser + // + // otherwise, we can't handle relative URLs + // + if (url.substring(0,1) === "/") + { + // if window.location exists, then we're running on a browser + if (!Gitana.isUndefined(window.location)) + { + let u = window.location.protocol + "//" + window.location.host; + if (window.location.host.indexOf(":") === -1) + { + if (window.location.port) { + u += ":" + window.location.port; + } + } + url = u + url; + } + else + { + // relative urls are not supported outside of the browser + throw new Error("Relative URL not supported outside of the browser: " + url); + } + } + + const config = { + "method": method, + "url": url, + "data": toSend, + "headers": headers, + "success": successCallback, + "failure": failureCallback + }; + + Gitana.requestCount++; + this.http.request(config); + + return this; + }, + + /** + * Send an HTTP request via AJAX to the Gitana Server. + * + * This method will additionally make sure of the following: + * + * 1) That the Gitana Driver authentication ticket is plugged onto the request. + * 2) That the Gitana Driver locale is plugged onto the request. + * 3) That full object data is returned (including metadata). + * + * @public + * + * @param {String} method The kind of method to invoke - "get", "post", "put", or "del" + * @param {String} url Either a full URL (i.e. "http://server:port/uri") or a URI against the driver's server URL (i.e. /repositories/...) + * @param {Object} params parameter map + * @param {String} contentType If the case of a payload carrying request (i.e. not GET), the content type being sent. + * @param {Object} data In the case of a payload carrying request (i.e. not GET), the JSON to plug into the payload. + * @param headers + * @param {Function} [successCallback] The function to call if the operation succeeds. + * @param {Function} [failureCallback] The function to call if the operation fails. + */ + gitanaRequest: function(method, url, params, contentType, data, headers, successCallback, failureCallback) + { + // ensure we have some params + if (!params) + { + params = {}; + } + + // if url has query string params, move into params + // strip back url so that it does not have query params + const x1 = url.indexOf("?"); + if (x1 > -1) + { + const qs = url.substring(x1 + 1); + url = url.substring(0, x1); + + const parts = qs.split("&"); + for (let x2 = 0; x2 < parts.length; x2++) + { + const keyValuePair = parts[x2].split("="); + params[keyValuePair[0]] = keyValuePair[1]; + } + } + + // make sure we compute the real url + if (Gitana.startsWith(url, "/")) { + url = this.baseURL + url; + } + + if (!failureCallback) + { + failureCallback = this.defaultFailureCallback; + } + + if (!headers) + { + headers = {}; + } + + /** + * Primary success callback handler for oAuth call to server. + * + * @param responseObject + * @param xhr + */ + const onSuccess = function(responseObject, xhr) + { + if (successCallback) + { + // call back with just the response text (or json) + + let arg = responseObject.text; + if (contentType === "application/json") + { + try { + arg = new Gitana.Response(JSON.parse(arg)); + } catch (ex) { + failureCallback(ex); + } + } + + successCallback(arg); + } + }; + + /** + * Primary failure callback handler for oAuth call to server. + * + * @param responseObject + * @param xhr + */ + const onFailure = function(responseObject, xhr) + { + if (failureCallback) + { + const httpError = {}; + + if (responseObject && responseObject.timeout) + { + // due to a timeout + httpError["statusText"] = "Connection timed out"; + httpError["status"] = xhr.status; + httpError["errorType"] = "timeout"; + httpError["message"] = "Connection timed out"; + httpError["xhr"] = xhr; + httpError["response"] = responseObject; + + if (responseObject.info) + { + httpError["info"] = responseObject.info; + } + } + else + { + // due to an HTTP error + httpError["statusText"] = xhr.statusText; + httpError["status"] = xhr.status; + httpError["errorType"] = "http"; + httpError["xhr"] = xhr; + + if (responseObject) + { + httpError["response"] = responseObject; + } + + let message = null; + let stacktrace = null; + + if (contentType === "application/json") + { + try + { + const arg = responseObject.text; + + const obj = new Gitana.Response(JSON.parse(arg)); + if (obj.message) + { + message = obj.message; + } + if (obj.stacktrace) + { + stacktrace = obj.stacktrace; + } + } + catch (e) { } + } + if (message) + { + httpError.message = message; + } + if (stacktrace) + { + httpError.stacktrace = stacktrace; + } + } + + failureCallback(httpError); + } + }; + + // copy in globally defined params + if (Gitana.HTTP_PARAMS) + { + for (let k in Gitana.HTTP_PARAMS) + { + if (Gitana.HTTP_PARAMS.hasOwnProperty(k)) + { + params[k] = Gitana.HTTP_PARAMS[k]; + } + } + } + + // copy in globally defined headers + if (Gitana.HTTP_HEADERS) + { + for (let k in Gitana.HTTP_HEADERS) + { + if (Gitana.HTTP_HEADERS.hasOwnProperty(k)) + { + headers[k] = Gitana.HTTP_HEADERS[k]; + } + } + } + + // adjust url to include "full" as well as "metadata" if not included + if (Gitana.isEmpty(params["metadata"])) + { + params["metadata"] = true; + } + if (Gitana.isEmpty(params["full"])) + { + params["full"] = true; + } + + // set the locale + if (this.locale === null) + { + if (!params["locale"]) + { + params["locale"] = "default"; + } + } + else if (typeof(this.locale) !== "undefined") + { + headers["accept-language"] = this.locale; + params["locale"] = this.locale; + } + + // cache buster + let cacheBuster = null; + if (this.getOriginalConfiguration().cacheBuster === true) + { + cacheBuster = new Date().getTime(); + } + else if (typeof(this.getOriginalConfiguration().cacheBuster) === "string") + { + cacheBuster = this.getOriginalConfiguration().cacheBuster; + } + else if (typeof(this.getOriginalConfiguration().cacheBuster) === "function") + { + cacheBuster = this.getOriginalConfiguration().cacheBuster(); + } + if (cacheBuster) + { + params["cb"] = cacheBuster; + } + + // update URL to include params + for (let paramKey in params) + { + let paramValue = params[paramKey]; + if (Gitana.isFunction(paramValue)) + { + paramValue = paramValue.call(); + } + else if (Gitana.isString(paramValue)) + { + // make sure all param strings are escaped + paramValue = Gitana.escape(paramValue); + } + else if (Gitana.isNumber(paramValue)) + { + // NOTHING TO DO + } + else + { + paramValue = Gitana.escape(Gitana.stringify(paramValue, false)); + } + + // apply + if (url.indexOf("?") > -1) + { + url = url + "&" + paramKey + "=" + paramValue; + } + else + { + url = url + "?" + paramKey + "=" + paramValue; + } + } + + return this.ajax(method, url, contentType, data, headers, onSuccess, onFailure); + }, + + /** + * Sends an HTTP GET request to the Gitana server. + * + * @public + * + * @param {String} url Either a full URL (i.e. "http://server:port/uri") or a URI against the driver's server URL (i.e. /repositories/...) + * @param {Object} params request parameters + * @param {Object} headers request headers + * @param {Function} [successCallback] The function to call if the operation succeeds. + * @param {Function} [failureCallback] The function to call if the operation fails. + */ + gitanaGet: function(url, params, headers, successCallback, failureCallback) + { + return this.gitanaRequest("GET", url, params, "application/json", null, headers, successCallback, failureCallback); + }, + + /** + * Sends an HTTP GET request to the Gitana server. + * + * @public + * + * @param {String} url Either a full URL (i.e. "http://server:port/uri") or a URI against the driver's server URL (i.e. /repositories/...) + * @param {Object} params request parameters + * @param {Function} [successCallback] The function to call if the operation succeeds. + * @param {Function} [failureCallback] The function to call if the operation fails. + */ + gitanaDownload: function(url, params, successCallback, failureCallback) + { + return this.gitanaRequest("GET", url, params, null, null, {}, successCallback, failureCallback); + }, + + /** + * Sends an HTTP POST request to the Gitana server. + * + * @public + * + * @param {String} url Either a full URL (i.e. "http://server:port/uri") or a URI against the driver's server URL (i.e. /repositories/...) + * @param {Object} params request parameters + * @param {Object} [jsonData] The JSON to plug into the payload. + * @param {Function} [successCallback] The function to call if the operation succeeds. + * @param {Function} [failureCallback] The function to call if the operation fails. + */ + gitanaPost: function(url, params, jsonData, successCallback, failureCallback) + { + return this.gitanaRequest("POST", url, params, "application/json", jsonData, {}, successCallback, failureCallback); + }, + + /** + * Sends an HTTP POST request to the Gitana server. + * + * @public + * + * @param {String} url Either a full URL (i.e. "http://server:port/uri") or a URI against the driver's server URL (i.e. /repositories/...) + * @param {Object} params request parameters + * @param {String} contentType content type being sent + * @param {Object} data The JSON to plug into the payload. + * @param {Function} [successCallback] The function to call if the operation succeeds. + * @param {Function} [failureCallback] The function to call if the operation fails. + */ + gitanaUpload: function(url, params, contentType, data, successCallback, failureCallback) + { + return this.gitanaRequest("POST", url, params, contentType, data, {}, successCallback, failureCallback); + }, + + /** + * Sends an HTTP PUT request to the Gitana server. + * + * @public + * + * @param {String} url Either a full URL (i.e. "http://server:port/uri") or a URI against the driver's server URL (i.e. /repositories/...) + * @param {Object} params request parameters + * @param {Object} [jsonData] The JSON to plug into the payload. + * @param {Function} [successCallback] The function to call if the operation succeeds. + * @param {Function} [failureCallback] The function to call if the operation fails. + */ + gitanaPut: function(url, params, jsonData, successCallback, failureCallback) + { + return this.gitanaRequest("PUT", url, params, "application/json", jsonData, {}, successCallback, failureCallback); + }, + + /** + * Sends an HTTP PATCH request to the Gitana server. + * + * @public + * + * @param {String} url Either a full URL (i.e. "http://server:port/uri") or a URI against the driver's server URL (i.e. /repositories/...) + * @param {Object} params request parameters + * @param {Object} [jsonData] The JSON to plug into the payload. + * @param {Function} [successCallback] The function to call if the operation succeeds. + * @param {Function} [failureCallback] The function to call if the operation fails. + */ + gitanaPatch: function(url, params, jsonData, successCallback, failureCallback) + { + return this.gitanaRequest("PATCH", url, params, "application/json", jsonData, {}, successCallback, failureCallback); + }, + + /** + * Sends an HTTP DELETE request to the Gitana server. + * + * @public + * + * @param {String} url Either a full URL (i.e. "http://server:port/uri") or a URI against the driver's server URL (i.e. /repositories/...) + * @param {Object} params request parameters + * @param {Function} [successCallback] The function to call if the operation succeeds. + * @param {Function} [failureCallback] The function to call if the operation fails. + */ + gitanaDelete: function(url, params, successCallback, failureCallback) + { + return this.gitanaRequest("DELETE", url, params, "application/json", null, {}, successCallback, failureCallback); + }, + + getFactory: function() + { + return new Gitana.ObjectFactory(); + }, + + + ////////////////////////////////////////////////////////////////////////////////////////// + // + // CHAINING METHODS + // + ////////////////////////////////////////////////////////////////////////////////////////// + + /** + * Authenticates as the supplied user. + * + * A user can either be authenticated using username/password credentials or via an authentication code. + * + * Authorization Code flow: + * + * { + * "code": "", + * "redirectUri": "" + * } + + * Username/password flow: + * + * { + * "username": "", + * "password": "" + * } + * + * Implicit flow: + * + * { + * "accessToken": "", + * "redirectUri": "" + * } + * + * Using Gitana Ticket from a cookie: + * + * { + * "cookie": true + * } + * + * Using Gitana Ticket (explicitly provided): + * + * { + * "ticket": "" + * } + * + * An authentication failure handler can be passed as the final argument + * + * @chained platform + * + * @param {Object} settings + * @param {Function} authFailureHandler failure handler + */ + authenticate: function(settings, authFailureHandler) + { + const driver = this; + + // build config + const config = { + "code": null, + "redirectUri": null, + "username": null, + "password": null, + "accessToken": null, + "ticket": null, + "cookie": null, + "ticketMaxAge": null, + "headers": {} + }; + Gitana.copyKeepers(config, Gitana.loadDefaultConfig()); + Gitana.copyKeepers(config, settings); + + // some adjustments + if (config.ticket || config.accessToken || config.code) + { + delete config.username; + delete config.password; + + if (config.ticket) + { + delete config.accessToken; + delete config.code; + } + else if (config.accessToken) + { + delete config.ticket; + delete config.code; + } + else if (config.code) + { + delete config.accessToken; + delete config.ticket; + } + } + + // platform config (for cache key determination) + const platformConfig = { + "key": null, + "ticket": null, + "username": null, + "clientKey": null + }; + Gitana.copyKeepers(platformConfig, this.getOriginalConfiguration()); + Gitana.copyKeepers(platformConfig, settings); + let platformCacheKey = platformConfig.key; + if (!platformCacheKey) + { + platformCacheKey = Gitana.determinePlatformCacheKey(platformConfig, true); + } + if (platformCacheKey) + { + this.platformCacheKey = platformCacheKey; + } + + const params = {}; + const headers = {}; + + // copy in any custom headers + if (config.headers) { + for (const header in config.headers) { + headers[header] = config.headers[header]; + } + } + + // build a cluster instance + const cluster = new Gitana.Cluster(this, {}); + + const applyPlatformCache = function(driver, platform) + { + const platformCacheKey = driver.platformCacheKey; + if (platformCacheKey) + { + Gitana.PLATFORM_CACHE(platformCacheKey, platform); + } + + // always cache on ticket as well + const ticket = driver.getAuthInfo().getTicket(); + if (ticket) { + Gitana.PLATFORM_CACHE(ticket, platform); + } + }; + + // run with this = platform + const doAuthenticate = function() + { + const platform = this; + + // we provide a fallback if no flow type is specified, using "password" flow with guest/guest + if (!config.code && !config.username && !config.accessToken && !config.cookie && !config.ticket) + { + config.username = "guest"; + config.password = "guest"; + } + + // + // authenticate via the authentication flow + // + if (config.code) + { + // clear existing cookie and ticket + config.authorizationFlow = Gitana.OAuth2Http.AUTHORIZATION_CODE; + driver.resetHttp(config); + Gitana.deleteCookie("GITANA_TICKET", "/"); + + // fetch the auth info + driver.gitanaGet("/auth/info", params, headers, function(response) { + + const authInfo = new Gitana.AuthInfo(response); + driver.setAuthInfo(authInfo); + + // TODO: fix this + // kill the JSESSIONID cookie which comes back from the proxy and ties us to a session + // on the Gitana server + Gitana.deleteCookie("JSESSIONID", "/"); + + // apply platform cache + applyPlatformCache(driver, platform); + + // now continue the platform chain after we reload + platform.reload(); + platform.next(); + + }, function(http) { + + // if authentication fails, respond to custom auth failure handler + if (authFailureHandler) + { + authFailureHandler.call(platform, http); + } + + }); + } + + // + // authenticate via password flow + // + else if (config.username) + { + // clear existing cookie and ticket + config.authorizationFlow = Gitana.OAuth2Http.PASSWORD; + driver.resetHttp(config); + Gitana.deleteCookie("GITANA_TICKET", "/"); + + // retrieve auth info and plug into the driver + driver.gitanaGet("/auth/info", params, headers, function(response) { + const authInfo = new Gitana.AuthInfo(response); + driver.setAuthInfo(authInfo); + + // TODO: fix this + // kill the JSESSIONID cookie which comes back from the proxy and ties us to a session + // on the Gitana server + Gitana.deleteCookie("JSESSIONID", "/"); + + // apply platform cache + applyPlatformCache(driver, platform); + + // now continue the platform chain after we reload + platform.reload(); + platform.next(); + + }, function(http) { + + // if authentication fails, respond to custom auth failure handler + if (authFailureHandler) + { + authFailureHandler.call(platform, http); + } + + }); + } + + // + // authenticate with an existing token + // + else if (config.accessToken) + { + // clear existing cookie and ticket + config.authorizationFlow = Gitana.OAuth2Http.TOKEN; + driver.resetHttp(config); + Gitana.deleteCookie("GITANA_TICKET", "/"); + + // fetch the auth info + driver.gitanaGet("/auth/info", params, headers, function(response) { + + const authInfo = new Gitana.AuthInfo(response); + driver.setAuthInfo(authInfo); + + // TODO: fix this + // kill the JSESSIONID cookie which comes back from the proxy and ties us to a session + // on the Gitana server + Gitana.deleteCookie("JSESSIONID", "/"); + + // apply platform cache + applyPlatformCache(driver, platform); + + // now continue the platform chain after we reload + platform.reload(); + platform.next(); + + }, function(http) { + + // if authentication fails, respond to custom auth failure handler + if (authFailureHandler) + { + authFailureHandler.call(platform, http); + } + + }); + } + + // + // authenticate using an existing cookie + // + else if (config.cookie) + { + // reuse an existing cookie (token flow) + config.authorizationFlow = Gitana.OAuth2Http.COOKIE; + driver.resetHttp(config); + + // fetch the auth info + driver.gitanaGet("/auth/info", params, headers, function(response) { + + const authInfo = new Gitana.AuthInfo(response); + driver.setAuthInfo(authInfo); + + if (authInfo.accessToken) + { + driver.http.accessToken(authInfo.accessToken); + } + + // TODO: fix this + // kill the JSESSIONID cookie which comes back from the proxy and ties us to a session + // on the Gitana server + Gitana.deleteCookie("JSESSIONID", "/"); + + // apply platform cache + applyPlatformCache(driver, platform); + + // now continue the platform chain after we reload + platform.reload(); + platform.next(); + + }, function(http) { + + // if authentication fails, respond to custom auth failure handler + if (authFailureHandler) + { + authFailureHandler.call(platform, http); + } + + }); + } + + // + // authenticate using an explicit gitana ticket + // + else if (config.ticket) + { + // reuse an existing cookie (token flow) + config.authorizationFlow = Gitana.OAuth2Http.TICKET; + driver.resetHttp(config); + + headers["GITANA_TICKET"] = config.ticket; + + // fetch the auth info + driver.gitanaGet("/auth/info", params, headers, function(response) { + + const authInfo = new Gitana.AuthInfo(response); + driver.setAuthInfo(authInfo); + + // TODO: fix this + // kill the JSESSIONID cookie which comes back from the proxy and ties us to a session + // on the Gitana server + Gitana.deleteCookie("JSESSIONID", "/"); + + // apply platform cache + applyPlatformCache(driver, platform); + + // now continue the platform chain after we reload + platform.reload(); + platform.next(); + + }, function(http) { + + // if authentication fails, respond to custom auth failure handler + if (authFailureHandler) + { + authFailureHandler.call(platform, http); + } + + }); + } + else + { + const message = "Unsupported authentication flow - you must provide either a username, authorization code, access token or select cookie-based authentication"; + + if (authFailureHandler) + { + authFailureHandler.call(platform, { + "message": message + }); + } + else + { + throw new Error(message); + } + } + }; + + const result = this.getFactory().platform(cluster); + return Chain(result).then(function() { + + // NOTE: this = platform + + doAuthenticate.call(this); + + // tell the chain that we'll manually handle calling next() + return false; + }); + }, + + reloadAuthInfo: function(callback) + { + const driver = this; + + driver.gitanaGet("/auth/info", {}, {}, function(response) { + + const authInfo = new Gitana.AuthInfo(response); + driver.setAuthInfo(authInfo); + + callback(); + + }, function(http) { + callback(null, http); + }); + }, + + /** + * Clears any authentication for the driver. + */ + clearAuthentication: function() + { + if (this.http.clearStorage) + { + this.http.clearStorage(); + } + + this.resetHttp(); + Gitana.deleteCookie("GITANA_TICKET", "/"); + }, + + /** + * Refreshes the authentication access token. + * + * @param callback + */ + refreshAuthentication: function(callback) + { + this.http.refresh(function(err) { + callback(err); + }); + }, + + /** + * Destructor function, called at the end of the driver instance's lifecycle + */ + destroy: function() + { + this.clearAuthentication(); + } + + }); + + + // + // STATICS + // Special Groups + + Gitana.EVERYONE = { + "name": "everyone", + "type": "GROUP" + }; + + // temporary location for this code + Gitana.toCopyDependencyChain = function(typedID) + { + let array = []; + + if (typedID.getType() === "node") + { + array = array.concat(Gitana.toCopyDependencyChain(typedID.getBranch())); + array = array.concat({ + "typeId": "changeset", + "id": typedID.getSystemMetadata().getChangesetId() + }); + } + else if (typedID.getType() === "association") + { + array = array.concat(Gitana.toCopyDependencyChain(typedID.getBranch())); + array = array.concat({ + "typeId": "changeset", + "id": typedID.getSystemMetadata().getChangesetId() + }); + } + else if (typedID.getType() === "branch") + { + array = array.concat(Gitana.toCopyDependencyChain(typedID.getRepository())); + } + else if (typedID.getType() === "platform") + { + // nothing to do here + } + else if (typedID.getType() === "stack") + { + array = array.concat(Gitana.toCopyDependencyChain(typedID.getPlatform())); + } + else if (typedID.getType() === "project") + { + array = array.concat(Gitana.toCopyDependencyChain(typedID.getPlatform())); + } + else + { + array = array.concat(Gitana.toCopyDependencyChain(typedID.getPlatform())); + } + + array.push(Gitana.toDependencyObject(typedID)); + + return array; + }; + + Gitana.toDependencyObject = function(typedID) + { + return { + "typeId": typedID.getType(), + "id": typedID.getId() + }; + }; + + Gitana.TypedIDConstants = {}; + Gitana.TypedIDConstants.TYPE_APPLICATION = "application"; + Gitana.TypedIDConstants.TYPE_EMAIL = "email"; + Gitana.TypedIDConstants.TYPE_EMAIL_PROVIDER = "emailprovider"; + Gitana.TypedIDConstants.TYPE_REGISTRATION = "registration"; + Gitana.TypedIDConstants.TYPE_PAGE_RENDITION = "pageRendition"; + Gitana.TypedIDConstants.TYPE_SETTINGS = "settings"; + Gitana.TypedIDConstants.TYPE_MESSAGE = "message"; + + // cluster + Gitana.TypedIDConstants.TYPE_CLUSTER = "cluster"; + Gitana.TypedIDConstants.TYPE_JOB = "job"; + Gitana.TypedIDConstants.TYPE_LOG_ENTRY = "logEntry"; + + // directory + Gitana.TypedIDConstants.TYPE_DIRECTORY = "directory"; + Gitana.TypedIDConstants.TYPE_IDENTITY = "identity"; + Gitana.TypedIDConstants.TYPE_CONNECTION = "connection"; + + // domain + Gitana.TypedIDConstants.TYPE_DOMAIN = "domain"; + Gitana.TypedIDConstants.TYPE_DOMAIN_GROUP = "group"; + Gitana.TypedIDConstants.TYPE_DOMAIN_USER = "user"; + + // platform + Gitana.TypedIDConstants.TYPE_PLATFORM = "platform"; + Gitana.TypedIDConstants.TYPE_ACCESS_POLICY = "accessPolicy"; + Gitana.TypedIDConstants.TYPE_AUTHENTICATION_GRANT = "authenticationGrant"; + Gitana.TypedIDConstants.TYPE_BILLING_PROVIDERS_CONFIGURATION = "billingProviderConfiguration"; + Gitana.TypedIDConstants.TYPE_DEPLOYMENT_RECEIVER = "deployment-receiver"; + Gitana.TypedIDConstants.TYPE_DEPLOYMENT_PACKAGE = "deployment-package"; + Gitana.TypedIDConstants.TYPE_DEPLOYMENT_STRATEGY = "deployment-strategy"; + Gitana.TypedIDConstants.TYPE_DEPLOYMENT_TARGET = "deployment-target"; + Gitana.TypedIDConstants.TYPE_CLIENT = "client"; + Gitana.TypedIDConstants.TYPE_DESCRIPTOR = "externalServiceDescriptor"; + Gitana.TypedIDConstants.TYPE_STACK = "stack"; + Gitana.TypedIDConstants.TYPE_PROJECT = "project"; + Gitana.TypedIDConstants.TYPE_SCHEDULED_WORK = "scheduled-work"; + Gitana.TypedIDConstants.TYPE_REPORT = "report"; + Gitana.TypedIDConstants.TYPE_WORKFLOW_INSTANCE = "workflowInstance"; + Gitana.TypedIDConstants.TYPE_WORKFLOW_MODEL = "workflowModel"; + Gitana.TypedIDConstants.TYPE_WORKFLOW_TASK = "workflowTask"; + Gitana.TypedIDConstants.TYPE_WORKFLOW_COMMENT = "workflowComment"; + Gitana.TypedIDConstants.TYPE_UICONFIG = "uiconfig"; + + // registrar + Gitana.TypedIDConstants.TYPE_REGISTRAR = "registrar"; + Gitana.TypedIDConstants.TYPE_METER = "meter"; + Gitana.TypedIDConstants.TYPE_PLAN = "plan"; + Gitana.TypedIDConstants.TYPE_TENANT = "tenant"; + + // repository + Gitana.TypedIDConstants.TYPE_REPOSITORY = "repository"; + Gitana.TypedIDConstants.TYPE_ASSOCIATION = "association"; + Gitana.TypedIDConstants.TYPE_BRANCH = "branch"; + Gitana.TypedIDConstants.TYPE_CHANGESET = "changeset"; + Gitana.TypedIDConstants.TYPE_NODE = "node"; + Gitana.TypedIDConstants.TYPE_RELEASE = "release"; + Gitana.TypedIDConstants.TYPE_MERGE_CONFLICT = "mergeConflict"; + Gitana.TypedIDConstants.TYPE_DELETION = "deletion"; + + // vault + Gitana.TypedIDConstants.TYPE_VAULT = "vault"; + Gitana.TypedIDConstants.TYPE_ARCHIVE = "archive"; + + // web host + Gitana.TypedIDConstants.TYPE_WEB_HOST = "webhost"; + Gitana.TypedIDConstants.TYPE_AUTO_CLIENT_MAPPING = "autoClientMapping"; + Gitana.TypedIDConstants.TYPE_TRUSTED_DOMAIN_MAPPING = "trustedDomainMapping"; + Gitana.TypedIDConstants.TYPE_DEPLOYED_APPLICATION = "deployedApplication"; + + Gitana.handleJobCompletion = function(chain, cluster, jobId, synchronous, reportFn) + { + const jobFinalizer = function() { + + return Chain(cluster).readJob(jobId).then(function() { + + if (reportFn) { + reportFn(this); + } + + if (!synchronous || (synchronous && (this.getState() === "FINISHED" || this.getState() === "ERROR"))) + { + chain.loadFrom(this); + chain.next(); + } + else + { + // reset timeout + window.setTimeout(jobFinalizer, 1000); + } + + }); + }; + + // set timeout + window.setTimeout(jobFinalizer, 1000); + }; + + /** Extension point for loading default config for server-side containers **/ + Gitana.loadDefaultConfig = function() + { + }; + + /** + * Simple in-memory cache implementation for use by-default by the driver. + * + * @return {Function} + */ + Gitana.MemoryCache = function() + { + const cache = {}; + + return function(k, v) + { + if (!Gitana.isUndefined(v)) + { + if (v) { + cache[k] = v; + } + else { + delete cache[k]; + } + } + + // support for "clear" method - removes everything from cache + if (k === "clear") + { + const za = []; + for (let z in cache) + { + za.push(z); + } + for (let i = 0; i < za.length; i++) + { + delete cache[za[i]]; + } + } + + return cache[k]; + }; + }; + + + ///////////////////////////////////////////////////////////////////////////////////////////////////////// + // + // PLATFORM CACHE + // + // + + // extension point - override with other implementations + Gitana.PLATFORM_CACHE = Gitana.MemoryCache(); + + Gitana.determinePlatformCacheKey = function(config, fallbackToDefault) + { + let cacheKey = null; + + // "ticket" authentication - key = ticket + if (config.ticket) { + cacheKey = config.ticket; + } + else if (config.clientKey && config.username) { + cacheKey = config.clientKey + ":" + config.username; + } + else if (fallbackToDefault) + { + // if no config provided, use "default" key + cacheKey = "default"; + } + + return cacheKey; + }; + + /** + * Connects to a Gitana platform. + * + * @param config + * @param callback {Object} optional callback function that gets called once the server has been connected to. If no + * "application" config parameter is present, then the callback function is called with the this + * context set to the platform. If an "application" config parameter is present, then the stack + * for the application is loaded and references are resolved and the this context will be the + * app helper instance. This callback also acts as an error handler for any authentication issues. + * If an auth error happens, the err is passed to the callback as the first and only argument. + * + * @return {*} + */ + Gitana.connect = function(config, callback) + { + // allow for no config, callback-only + if (Gitana.isFunction(config)) { + callback = config; + config = null; + } + + let missingConfig = false; + + if (!config) { + config = {}; + missingConfig = true; + } + + if (Gitana.isString(config)) { + config = {"key": config}; + } + + // by default, set invalidatePlatformCache to false + if (typeof(config.invalidatePlatformCache) === "undefined") + { + config.invalidatePlatformCache = false; + } + + // if no config key specified, we can generate one... + if (!config.key) + { + config.key = Gitana.determinePlatformCacheKey(config, missingConfig); + } + + // default to load app helper if not defined + if (typeof(config.loadAppHelper) === "undefined") + { + config.loadAppHelper = true; + } + + // this gets called once the platform is drawn from cache or created + // fires the callback and passes in the platform or the app helper + const setupContext = function(platformCacheKey) + { + // NOTE: this == platform + + // if their configuration contains the "application" setting, then auto-load the app() context + // note that config.application could be undefined (we require explicit NULL here for copyKeepers) + if (config.loadAppHelper) + { + const appConfig = { + "application": (config.application ? config.application: null), + "appCacheKey": null + }; + Gitana.copyKeepers(appConfig, Gitana.loadDefaultConfig()); + Gitana.copyKeepers(appConfig, this.getDriver().getOriginalConfiguration()); + Gitana.copyKeepers(appConfig, config); + if (appConfig.application) { + + const appSettings = { + "application": appConfig.application + }; + if (appConfig.appCacheKey) { + appSettings.appCacheKey = appConfig.appCacheKey; + } + if (!appSettings.appCacheKey) + { + if (platformCacheKey) + { + appSettings.appCacheKey = platformCacheKey + "_" + appConfig.application; + } + } + this.app(appSettings, function(err) { + if (callback) { + // NOTE: this == app helper + callback.call(this, err); + } + }); + } + else { + if (callback) { + callback.call(this); + } + } + } + else + { + if (callback) { + callback.call(this); + } + } + }; + + // support for invalidatePlatformCache + if (config.key && config.invalidatePlatformCache) + { + Gitana.disconnect(config.key); + } + + // either retrieve platform from cache or authenticate + let platform = null; + if (config.key) { + platform = Gitana.PLATFORM_CACHE(config.key); + } + if (platform) + { + // platform already loaded + + // spawn off a new copy for thread safety + platform = Chain(new Gitana.Platform(platform.getCluster(), platform)); + setupContext.call(platform, config.key); + return platform; + } + + // if they didn't provide a config and made it this far, then lets assume a cookie based config? + if (missingConfig) + { + config["cookie"] = true; + } + + // load it up + return new Gitana(config).authenticate(config, function(err) { + + // if we failed to authenticate, force disconnect in case we were pulling from cache + if (err && config.key) { + Gitana.disconnect(config.key); + } + + if (callback) { + callback.call(this, err); + } + + }).then(function() { + + // NOTE: this == platform + + setupContext.call(this, config.key); + + }); + }; + + /** + * Disconnects a platform from the cache. + * + * @param key + * @param expireAccessToken + */ + Gitana.disconnect = function(key, expireAccessToken) + { + if (!key) { + key = "default"; + } + + const platform = Gitana.PLATFORM_CACHE(key); + if (platform) + { + // if we are meant to expire the server-side access token, + // fire off a signal to the Cloud CMS server to do so + // we ignore whether this succeeds or fails + if (expireAccessToken) + { + platform.getDriver().gitanaPost("/auth/expire", {}, {}, function() { + // success + }, function(err) { + // error + }); + } + + const badKeys = []; + for (let k in Gitana.APPS) + { + if (k.indexOf(key + "_") === 0) + { + badKeys.push(k); + } + } + for (let i = 0; i < badKeys.length; i++) + { + delete Gitana.APPS[badKeys[i]]; + } + + const ticket = platform.getDriver().getAuthInfo().getTicket(); + if (ticket) + { + Gitana.PLATFORM_CACHE(ticket, null); + } + + Gitana.PLATFORM_CACHE(key, null); + + platform.getDriver().destroy(); + } + }; + + // holds a total count of Ajax requests originated from the driver + Gitana.requestCount = 0; + + // version of the driver + Gitana.VERSION = "1.0.304"; + + // allow for optional global assignment + // TODO: until we clean up the "window" variable reliance, we have to always set onto window again + // TODO: to support loading within NodeJS + //if (window && !window.Gitana) { + if (window) { + window.Gitana = Gitana; + } + + // helper function for escaping + Gitana.escape = function(text) + { + if (text) { + text = encodeURIComponent(text); + } + + return text; + }; + + /** + * Resets the driver (used for test purposes). + */ + Gitana.reset = function() + { + Gitana.HTTP_TIMEOUT = 120000; + + Gitana.PLATFORM_CACHE("clear"); + Gitana.deleteCookie("GITANA_TICKET"); + }; + + // insertion point for on-load adjustments (cloudcms-net server) + Gitana.__INSERT_MARKER = null; + + // toggles use of GET method when possible (rather than POST) + // useful for branch.queryNodes() + Gitana.PREFER_GET_OVER_POST = false; + + // whether to set the withCredential flag by default + Gitana.XHR_WITH_CREDENTIALS = true; + + // whether to send the special X-CLOUDCMS-ORIGIN header + Gitana.HTTP_X_CLOUDCMS_ORIGIN_HEADER = true; + + // method to call when a refresh token fails to acquire the access token + Gitana.REFRESH_TOKEN_FAILURE_FN = function(http) { + http.clearStorage(); + Gitana.deleteCookie("GITANA_TICKET"); + }; + + // a way to specify HTTP parameters to attach to every request + Gitana.HTTP_PARAMS = {}; + + // a way to specify HTTP headers to attach to every request + Gitana.HTTP_HEADERS = {}; + + // a way to configure the XHR headers ahead of send + Gitana.configureRequestHeaders = function(method, url, headers, options) + { + // no implementation + }; + + //////////////////////////////////////////////////////////////////////////////////////////////// + // + // support for CSRF / XSRF + // + //////////////////////////////////////////////////////////////////////////////////////////////// + + // the CSRF token can be explicitly stored here if you want to forgo cookies as a storage mechanism + Gitana.CSRF_TOKEN = null; + + // these cookies can be consulted by the driver to acquire the csrf token + // override this with different cookie names if your framework requires it + Gitana.CSRF_COOKIE_NAMES = ["CSRF-TOKEN", "XSRF-TOKEN"]; + + // the csrf token is sent over the wire using XHR and this header name + Gitana.CSRF_HEADER_NAME = "X-CSRF-TOKEN"; + + //////////////////////////////////////////////////////////////////////////////////////////////// + // + // default locale - set to undefined to allow the browser to specify, null to override browser with empty + // + //////////////////////////////////////////////////////////////////////////////////////////////// + + Gitana.DEFAULT_LOCALE = undefined; + + Gitana.defaultErrorHandler = function(err) + { + if (console && console.warn) + { + console.warn(err); + } + }; + + // the driver auto-upgrades connections to "api.cloudcms.com" to "api1.cloudcms.com" which is a permanent domain + // for our cloudfront-hosted API. + // over time, the "api.cloudcms.com" domain will transition to cloudfront as well (by the end of 2017 at the latest) + Gitana.AUTO_UPGRADE_TO_CLOUDFRONT = true; + + // allow for custom headers to be sent with OAuth2 token request + Gitana.OAUTH2_TOKEN_REQUEST_HEADERS = {}; + +})(window); +(function(global) { + Gitana.Error = function () {}; + Gitana.Error.prototype = new Error(); + Gitana.Error.prototype.constructor = Gitana.Error; +}(this));(function(window) +{ + Gitana.WorkQueue = function(maxSize) { + + if (!maxSize) { + maxSize = 3; + } + + let blockExecution = false; + + const pendingWorkFns = []; + let activeCount = 0; + + const processWork = function () { + + // if another "thread" is running the processor, don't bother + if (blockExecution) + { + return; + } + + blockExecution = true; + + // add as many pending work items as we can, loop until full or no more pending + let process = true; + do + { + // if nothing to work on, bail + if (pendingWorkFns.length === 0) + { + process = false; + } + + // if we're full, bail + if (activeCount >= maxSize) + { + process = false; + } + + if (process) + { + // increment active count + activeCount++; + + //console.log("Active work items: " + activeCount); + + // define execution function and splice/bind to 0th element from pending list + const executionFn = function(workFn) { + return function() { + workFn(function () { + + // decrement active count + activeCount--; + + //console.log("Active work items: " + activeCount); + + // process more work on timeout + window.setTimeout(processWork); + }); + + }; + }(pendingWorkFns.splice(0, 1)[0]); + + // execute on timeout + window.setTimeout(executionFn); + } + + } while (process); + + blockExecution = false; + }; + + return function(workFn) { + pendingWorkFns.push(workFn); + + // execute on timeout + window.setTimeout(processWork); + }; + + }; + +})(window); +(function(global) +{ + // the default timeout for xhr connections + // this is set long at 2 minutes + Gitana.HTTP_TIMEOUT = 120000; + Gitana.HTTP_TIMEOUT_FN = function(xhr, method, url) + { + // nothing to do; + }; + + // set a high limit on concurrent HTTP requests + Gitana.HTTP_WORK_QUEUE_SIZE = 100000; + + Gitana.HTTP_XHR_FACTORY = function() { + return null; + }; + + Gitana.Http = Base.extend( + /** @lends Gitana.Http.prototype */ + { + /** + * @constructs + * + * @class Gitana.Http + */ + constructor: function() + { + // the http work queue + const enqueue = new Gitana.WorkQueue(Gitana.HTTP_WORK_QUEUE_SIZE); + + /////////////////////////////////////////////////////////////////////////////////////// + // + // PRIVILEDGED METHODS + // + + this.invoke = function(options) + { + const self = this; + + // add work to be done to the queue + enqueue(function(options) { + return function(workDoneFn) { + + const method = options.method || 'GET'; + const url = options.url; + const data = options.data; + const headers = options.headers || {}; + let success = options.success || function () {}; + let failure = options.failure || function () {}; + + // wrap a bit further to support release of the http work queue + const _success = success; + success = function() { + workDoneFn(); + const args = Array.prototype.slice.call(arguments); + _success.apply(self, args); + }; + const _failure = failure; + failure = function() { + workDoneFn(); + const args = Array.prototype.slice.call(arguments); + _failure.apply(self, args); + }; + + // make sure that all responses come back as JSON if they can (instead of XML) + headers["Accept"] = "application/json"; + + // ensure that CSRF token is applied (if available) + // the csrf token + let csrfToken = Gitana.CSRF_TOKEN; + if (!csrfToken) + { + // if we were not explicitly provided the token, look it up from a cookie + // NOTE: this only works in the browser + for (let t = 0; t < Gitana.CSRF_COOKIE_NAMES.length; t++) + { + const cookieName = Gitana.CSRF_COOKIE_NAMES[t]; + + const cookieValue = Gitana.readCookie(cookieName); + if (cookieValue) + { + csrfToken = cookieValue; + break; + } + } + } + if (csrfToken) + { + headers[Gitana.CSRF_HEADER_NAME] = csrfToken; + } + + // XHR_CACHE_FN + if (typeof(Gitana.XHR_CACHE_FN) !== "undefined" && Gitana.XHR_CACHE_FN !== null) + { + const responseObject = Gitana.XHR_CACHE_FN({ + method: method, + url: url, + headers: headers + }); + + if (responseObject) + { + return success(responseObject); + } + } + + // plug in a special Cloud CMS header to identify the CORS domain of the browser + if (Gitana.HTTP_X_CLOUDCMS_ORIGIN_HEADER) + { + if (typeof(window) !== "undefined") + { + if (window.location && window.location.origin) + { + headers["X-CLOUDCMS-ORIGIN"] = window.location.origin; + } + } + } + + const xhr = Gitana.Http.Request(); + + if (Gitana.XHR_WITH_CREDENTIALS) + { + xhr.withCredentials = true; + } + + // timeout handler + const httpTimeoutFn = function () { + xhr.abort(); + + if (Gitana.HTTP_TIMEOUT_FN) + { + Gitana.HTTP_TIMEOUT_FN(xhr, method, url); + } + + //console.log("HTTP Request timed out"); + + const responseObject = { + "timeout": true, + "text": "Http Request timed out", + "info": { + "method": method, + "url": url + } + }; + + // everything what is 400 and above is a failure code + failure(responseObject, xhr); + + return false; + }; + let httpTimeoutHolder = null; + if (Gitana.HTTP_TIMEOUT > 0) + { + httpTimeoutHolder = setTimeout(httpTimeoutFn, Gitana.HTTP_TIMEOUT); + } + + xhr.onreadystatechange = function () { + if (xhr.readyState === 4) + { + let regex = /^(.*?):\s*(.*?)\r?$/mg, requestHeaders = headers, responseHeaders = {}, responseHeadersString = '', match; + + if (!!xhr.getAllResponseHeaders) + { + responseHeadersString = xhr.getAllResponseHeaders(); + while ((match = regex.exec(responseHeadersString))) + { + responseHeaders[match[1]] = match[2]; + } + } + else if (!!xhr.getResponseHeaders) + { + responseHeadersString = xhr.getResponseHeaders(); + for (let i = 0, len = responseHeadersString.length; i < len; ++i) + { + responseHeaders[responseHeadersString[i][0]] = responseHeadersString[i][1]; + } + } + + let includeXML = false; + if ('Content-Type' in responseHeaders) + { + if (responseHeaders['Content-Type'] === 'text/xml') + { + includeXML = true; + } + } + + const responseObject = { + text: xhr.responseText, + xml: (includeXML ? xhr.responseXML : ''), + requestHeaders: requestHeaders, + responseHeaders: responseHeaders + }; + + // handle the response + if (xhr.status === 0) + { + // not handled + } + if ((xhr.status >= 200 && xhr.status <= 226) || xhr.status === 304) + { + if (httpTimeoutHolder) + { + clearTimeout(httpTimeoutHolder); + } + + // XHR_CACHE_FN + if (typeof(Gitana.XHR_CACHE_FN) !== "undefined" && Gitana.XHR_CACHE_FN !== null) + { + Gitana.XHR_CACHE_FN({ + method: method, + url: url, + headers: headers + }, responseObject); + } + + // ok + success(responseObject, xhr); + } + else if (xhr.status >= 400) + { + if (httpTimeoutHolder) + { + clearTimeout(httpTimeoutHolder); + } + + // everything what is 400 and above is a failure code + failure(responseObject, xhr); + } + else if (xhr.status >= 300 && xhr.status <= 303) + { + if (httpTimeoutHolder) + { + clearTimeout(httpTimeoutHolder); + } + + // some kind of redirect, probably to a login server + // indicates missing access token? + failure(responseObject, xhr); + } + } + }; + + if (Gitana.configureRequestHeaders) + { + Gitana.configureRequestHeaders(method, url, headers, options); + } + + xhr.open(method, url, true); + /* + xhr.timeout = Gitana.HTTP_TIMEOUT; + xhr.ontimeout = function () { + failure({ + "timeout": true + }, xhr); + }; + */ + + xhr.setRequestHeader('X-Requested-With', 'XMLHttpRequest'); + for (const header in headers) + { + xhr.setRequestHeader(header, headers[header]); + } + + try + { + xhr.send(data); + } + catch (e) + { + console.log(e); + } + }; + }(options)); + }; + }, + + /** + * Performs an HTTP call. + * + * @param options + */ + request: function(options) + { + return this.invoke(options); + } + }); + + Gitana.Http.toQueryString = function(params) + { + let queryString = ""; + + if (params) + { + for (const k in params) + { + if (queryString.length > 0) + { + queryString += "&"; + } + + let val = null; + if (params[k]) + { + val = params[k]; + + // url encode + val = Gitana.Http.URLEncode(val); + } + + if (val) + { + queryString += k + "=" + val; + } + } + } + + return queryString; + }; + + Gitana.Http.Request = function() + { + let XHR = null; + + // allow for custom XHR factory + if (Gitana.HTTP_XHR_FACTORY) { + XHR = Gitana.HTTP_XHR_FACTORY(); + } + + if (!XHR) + { + // legacy support for titanium + if (typeof global.Titanium !== 'undefined' && typeof global.Titanium.Network.createHTTPClient !== 'undefined') + { + XHR = global.Titanium.Network.createHTTPClient(); + } + else + { + // W3C (browser) + XHR = new global.XMLHttpRequest(); + } + } + + return XHR; + }; + + const Hash = function() {}; + Hash.prototype = + { + join: function(string) + { + string = string || ''; + return this.values().join(string); + }, + + keys: function() + { + let i, arr = [], self = this; + for (i in self) { + if (self.hasOwnProperty(i)) { + arr.push(i); + } + } + + return arr; + }, + + values: function() + { + let i, arr = [], self = this; + for (i in self) { + if (self.hasOwnProperty(i)) { + arr.push(self[i]); + } + } + + return arr; + }, + shift: function(){throw 'not implemented';}, + unshift: function(){throw 'not implemented';}, + push: function(){throw 'not implemented';}, + pop: function(){throw 'not implemented';}, + sort: function(){throw 'not implemented';}, + + ksort: function(func){ + let self = this, keys = self.keys(), i, value, key; + + if (func === undefined) { + keys.sort(); + } else { + keys.sort(func); + } + + for (i = 0; i < keys.length; i++) { + key = keys[i]; + value = self[key]; + delete self[key]; + self[key] = value; + } + + return self; + }, + toObject: function () { + let obj = {}, i, self = this; + for (i in self) { + if (self.hasOwnProperty(i)) { + obj[i] = self[i]; + } + } + + return obj; + } + }; + + const Collection = function(obj) + { + let args = arguments, args_callee = args.callee, + i, collection = this; + + if (!(this instanceof args_callee)) { + return new args_callee(obj); + } + + for(i in obj) { + if (obj.hasOwnProperty(i)) { + collection[i] = obj[i]; + } + } + + return collection; + }; + Collection.prototype = new Hash(); + + Gitana.Http.URI = function(url) + { + let args = arguments, args_callee = args.callee, + parsed_uri, scheme, host, port, path, query, anchor, + parser = /^([^:\/?#]+?:\/\/)*([^\/:?#]*)?(:[^\/?#]*)*([^?#]*)(\?[^#]*)?(#(.*))*/, + uri = this; + + if (!(this instanceof args_callee)) + { + return new args_callee(url); + } + + uri.scheme = ''; + uri.host = ''; + uri.port = ''; + uri.path = ''; + uri.query = new Gitana.Http.QueryString(); + uri.anchor = ''; + + if (url !== null) + { + parsed_uri = url.match(parser); + + scheme = parsed_uri[1]; + host = parsed_uri[2]; + port = parsed_uri[3]; + path = parsed_uri[4]; + query = parsed_uri[5]; + anchor = parsed_uri[6]; + + scheme = (scheme !== undefined) ? scheme.replace('://', '').toLowerCase() : 'http'; + port = (port ? port.replace(':', '') : (scheme === 'https' ? '443' : '80')); + // correct the scheme based on port number + scheme = (scheme === 'http' && port === '443' ? 'https' : scheme); + query = query ? query.replace('?', '') : ''; + anchor = anchor ? anchor.replace('#', '') : ''; + + + // Fix the host name to include port if non-standard ports were given + if ((scheme === 'https' && port !== '443') || (scheme === 'http' && port !== '80')) { + host = host + ':' + port; + } + + uri.scheme = scheme; + uri.host = host; + uri.port = port; + uri.path = path || '/'; + uri.query.setQueryParams(query); + uri.anchor = anchor || ''; + } + }; + + Gitana.Http.URI.prototype = { + scheme: '', + host: '', + port: '', + path: '', + query: '', + anchor: '', + toString: function () { + const self = this, query = self.query + ''; + return self.scheme + '://' + self.host + self.path + (query !== '' ? '?' + query : '') + (self.anchor !== '' ? '#' + self.anchor : ''); + } + }; + + Gitana.Http.QueryString = function(obj) + { + let args = arguments, args_callee = args.callee, + i, querystring = this; + + if (!(this instanceof args_callee)) { + return new args_callee(obj); + } + + if (obj !== undefined) { + for (i in obj) { + if (obj.hasOwnProperty(i)) { + querystring[i] = obj[i]; + } + } + } + + return querystring; + }; + + // QueryString is a type of collection So inherit + Gitana.Http.QueryString.prototype = new Collection(); + + Gitana.Http.QueryString.prototype.toString = function () + { + let i, self = this, q_arr = [], ret = '', + val = '', encode = Gitana.Http.URLEncode; + self.ksort(); // lexicographical byte value ordering of the keys + + for (i in self) { + if (self.hasOwnProperty(i)) { + if (i !== undefined && self[i] !== undefined) { + val = encode(i) + '=' + encode(self[i]); + q_arr.push(val); + } + } + } + + if (q_arr.length > 0) { + ret = q_arr.join('&'); + } + + return ret; + }; + + Gitana.Http.QueryString.prototype.setQueryParams = function (query) + { + let args = arguments, args_length = args.length, i, query_array, + query_array_length, querystring = this, key_value; + + if (args_length === 1) { + if (typeof query === 'object') { + // iterate + for (i in query) { + if (query.hasOwnProperty(i)) { + querystring[i] = query[i]; + } + } + } else if (typeof query === 'string') { + // split string on '&' + query_array = query.split('&'); + // iterate over each of the array items + for (i = 0, query_array_length = query_array.length; i < query_array_length; i++) { + // split on '=' to get key, value + key_value = query_array[i].split('='); + querystring[key_value[0]] = key_value[1]; + } + } + } else { + for (i = 0; i < arg_length; i += 2) { + // treat each arg as key, then value + querystring[args[i]] = args[i+1]; + } + } + }; + + Gitana.Http.URLEncode = function(string) + { + function hex(code) { + let hex = code.toString(16).toUpperCase(); + if (hex.length < 2) { + hex = 0 + hex; + } + return '%' + hex; + } + + if (!string) { + return ''; + } + + string = string + ''; + let reserved_chars = /[ \r\n!*"'();:@&=+$,\/?%#\[\]<>{}|`^\\\u0080-\uffff]/, + str_len = string.length, i, string_arr = string.split(''), c; + + for (i = 0; i < str_len; i++) + { + c = string_arr[i].match(reserved_chars); + if (c) + { + c = c[0].charCodeAt(0); + + if (c < 128) { + string_arr[i] = hex(c); + } else if (c < 2048) { + string_arr[i] = hex(192+(c>>6)) + hex(128+(c&63)); + } else if (c < 65536) { + string_arr[i] = hex(224+(c>>12)) + hex(128+((c>>6)&63)) + hex(128+(c&63)); + } else if (c < 2097152) { + string_arr[i] = hex(240+(c>>18)) + hex(128+((c>>12)&63)) + hex(128+((c>>6)&63)) + hex(128+(c&63)); + } + } + } + + return string_arr.join(''); + }; + + Gitana.Http.URLDecode = function (string) + { + if (!string) + { + return ''; + } + + return string.replace(/%[a-fA-F0-9]{2}/ig, function (match) { + return String.fromCharCode(parseInt(match.replace('%', ''), 16)); + }); + }; + +}(this)); +(function() +{ + Gitana.OAuth2Http = Gitana.Http.extend( + /** @lends Gitana.OAuth2Http.prototype */ + { + /** + * @constructs + * + * @class Gitana.OAuth2Http + */ + constructor: function(options, storage) + { + const self = this; + + // storage for OAuth credentials + // this can either be a string ("local", "session", "memory") or a storage instance or empty + // if empty, memory-based storage is assumed + if (storage === null || typeof(storage) === "string") + { + storage = new Gitana.OAuth2Http.Storage(storage); + } + + // cookie mode + this.cookieMode = null; + + // ticket mode + this.ticketMode = null; + + // preset the error state + this.error = null; + this.errorDescription = null; + this.errorUri = null; + + // gitana urls + let tokenURL = "/oauth/token"; + if (options.tokenURL) + { + tokenURL = options.tokenURL; + } + + // base URL? + let baseURL = null; + if (options.baseURL) + { + baseURL = options.baseURL; + } + + // client + const clientKey = options.clientKey; + const clientSecret = options.clientSecret; + + // authorization flow + // if none specified, assume AUTHORIZATION CODE + this.authorizationFlow = options.authorizationFlow || Gitana.OAuth2Http.AUTHORIZATION_CODE; + + // optional + if (options.requestedScope) + { + this.requestedScope = options.requestedScope; + } + + if (this.authorizationFlow === Gitana.OAuth2Http.AUTHORIZATION_CODE) + { + this.code = options.code; + this.redirectUri = options.redirectUri; + } + + if (this.authorizationFlow === Gitana.OAuth2Http.PASSWORD) + { + this.username = options.username; + + if (options.password) + { + this.password = options.password; + } + else + { + this.password = ""; + } + } + + if (this.authorizationFlow === Gitana.OAuth2Http.COOKIE) + { + this.cookieMode = true; + } + + if (this.authorizationFlow === Gitana.OAuth2Http.TICKET) + { + this.ticketMode = options.ticket; + } + + this.ticketMaxAge = options.ticketMaxAge; + + + //////////////////////////////////////////////////////////////////////////////////////////////// + // + // ACCESSORS + // + //////////////////////////////////////////////////////////////////////////////////////////////// + + /** + * Clears persisted storage of auth data + */ + this.clearStorage = function() + { + storage.clear(); + }; + + /** + * Gets or saves the access token + * + * @param value {String} optional value + */ + this.accessToken = function(value) + { + return storage.poke("accessToken", value); + }; + + /** + * Gets or saves the refresh token + * + * @param value [String] optional value + */ + this.refreshToken = function(value) + { + return storage.poke("refreshToken", value); + }; + + /** + * Gets or saves the granted scope + * + * @param value [String] optional value + */ + this.grantedScope = function(value) + { + return storage.poke("grantedScope", value); + }; + + /** + * Gets or saves the expires in value + * + * @param value [String] optional value + */ + this.expiresIn = function(value) + { + return storage.poke("expiresIn", value); + }; + + /** + * Gets or saves the grant time + * + * @param value [String] optional value + */ + this.grantTime = function(value) + { + return storage.poke("grantTime", value); + }; + + this.getClientAuthorizationHeader = function() { + + let basicString = clientKey + ":"; + if (clientSecret) + { + basicString += clientSecret; + } + return "Basic " + Gitana.btoa(basicString); + }; + + this.getBearerAuthorizationHeader = function() + { + return "Bearer " + self.accessToken(); + }; + + this.getPrefixedTokenURL = function() + { + return this.getPrefixedURL(tokenURL); + }; + + this.getPrefixedURL = function(url) + { + let rebasedURL = url; + if (baseURL && Gitana.startsWith(url, "/")) + { + rebasedURL = baseURL + url; + } + + return rebasedURL; + }; + + + // if they initiatialized with an access token, clear and write into persisted state + // unless they're continuing an existing token + if (this.authorizationFlow === Gitana.OAuth2Http.TOKEN) + { + const existingAccessToken = this.accessToken(); + if (existingAccessToken !== options.accessToken) + { + storage.clear(); + } + + this.accessToken(options.accessToken); + } + + this.base(); + }, + + /** + * Performs an HTTP call using OAuth2. + * + * @param options + */ + request: function(options) + { + const self = this; + + /** + * Call over to Gitana and acquires an access token using flow authorization. + * + * @param success + * @param failure + */ + const doGetAccessToken = function(success, failure) + { + const onSuccess = function(response, xhr) + { + const object = JSON.parse(response.text); + if (object["error"]) + { + self.error = object["error"]; + self.errorDescription = object["error_description"]; + self.errorUri = object["error_uri"]; + + return failure(response, xhr); + } + + const _accessToken = object["access_token"]; + const _refreshToken = object["refresh_token"]; + const _expiresIn = object["expires_in"]; + const _grantedScope = object["scope"]; + const _grantTime = new Date().getTime(); + + // store into persistent storage + self.clearStorage(); + self.accessToken(_accessToken); + self.refreshToken(_refreshToken); + self.expiresIn(_expiresIn); + self.grantedScope(_grantedScope); + self.grantTime(_grantTime); + + // console.log("doGetAccessToken -> " + JSON.stringify(object)); + + success(); + }; + + const onFailure = function(http, xhr) { + failure(http, xhr); + }; + + const o = { + success: onSuccess, + failure: onFailure, + headers: {}, + url: self.getPrefixedTokenURL(), + method: Gitana.OAuth2Http.TOKEN_METHOD + }; + + if (Gitana.OAUTH2_TOKEN_REQUEST_HEADERS) + { + for (var k in Gitana.OAUTH2_TOKEN_REQUEST_HEADERS) + { + o.headers[k] = Gitana.OAUTH2_TOKEN_REQUEST_HEADERS[k]; + } + } + + o.headers["Authorization"] = self.getClientAuthorizationHeader(); + + // query string + const qs = {}; + + // ticket max age + if (self.ticketMaxAge) + { + qs["ticketMaxAge"] = self.ticketMaxAge; + } + + // if we're POSTing, do so as application/x-www-form-urlencoded to make secure over the wire + if ("post" === Gitana.OAuth2Http.TOKEN_METHOD.toLowerCase()) + { + o.headers["Content-Type"] = "application/x-www-form-urlencoded"; + + // url encoded payload + const urlEncodedTokens = {}; + urlEncodedTokens["grant_type"] = self.authorizationFlow; + if (self.requestedScope) { + urlEncodedTokens["scope"] = self.requestedScope; + } + if (self.authorizationFlow === Gitana.OAuth2Http.AUTHORIZATION_CODE) + { + urlEncodedTokens["code"] = self.code; + if (self.redirectUri) { + urlEncodedTokens["redirect_uri"] = self.redirectUri; + } + } + else if (self.authorizationFlow === Gitana.OAuth2Http.PASSWORD) + { + urlEncodedTokens["username"] = self.username; + urlEncodedTokens["password"] = self.password; + } + o.data = "" + Gitana.Http.toQueryString(urlEncodedTokens); + } + else + { + qs["grant_type"] = self.authorizationFlow; + if (self.requestedScope) { + qs["scope"] = self.requestedScope; + } + if (self.authorizationFlow === Gitana.OAuth2Http.AUTHORIZATION_CODE) + { + qs["code"] = self.code; + if (self.redirectUri) { + qs["redirect_uri"] = self.redirectUri; + } + } + else if (self.authorizationFlow === Gitana.OAuth2Http.PASSWORD) + { + qs["username"] = self.username; + qs["password"] = self.password; + } + } + + // append into query string + const queryString = Gitana.Http.toQueryString(qs); + if (queryString) + { + if (o.url.indexOf("?") > -1) + { + o.url = o.url + "&" + queryString; + } + else + { + o.url = o.url + "?" + queryString; + } + } + + self.invoke(o); + }; + + if (typeof(Gitana.REFRESH_TOKEN_LOCKS) === "undefined") + { + Gitana.REFRESH_TOKEN_LOCKS = {}; + } + if (typeof(Gitana.REFRESH_TOKEN_LOCK_REATTEMPT_MS) === "undefined") + { + Gitana.REFRESH_TOKEN_LOCK_REATTEMPT_MS = 75; + } + + const waitForPendingRefresh = function(key, oldAccessToken) + { + setTimeout(function() { + + // if another "thread" is still refreshing, keep on waiting + if (Gitana.REFRESH_TOKEN_LOCKS[key]) { + return waitForPendingRefresh(); + } + + // if we get this far, we take advantage of the new access key + // first check to make sure that it is a different access key + const newAccessToken = self.accessToken(); + + // we try the call again under the assumption that the access token is valid + // if the access token is different, we allow for another attempted refresh + // otherwise we do not to avoid spinning around forever + const autoAttemptRefresh = (newAccessToken === oldAccessToken); + + // fire the call + doCall(autoAttemptRefresh); + + }, Gitana.REFRESH_TOKEN_LOCK_REATTEMPT_MS); + }; + + /** + * Calls over to Gitana and acquires an access token using an existing refresh token. + * + * We use a refresh token lock here (scoped to the module) so that only one event loop per refresh token + * is allowed to perform the refresh at a time. This is to avoid making excessive network calls and also + * helps to avoid race/bounce conditions when multiple refresh tokens come back, spinning things out of + * control. Eventually it settles down but better to avoid altogether. + * + * @param success + * @param failure + */ + const doRefreshAccessToken = function(success, failure) { + + const key = self.refreshToken(); + const oldAccessToken = self.accessToken(); + + // if another "thread" is refreshing for this refresh key, then we wait until it finishes + // when it finishes, we either use the acquired access token or make another attempt + if (Gitana.REFRESH_TOKEN_LOCKS[key]) { + return waitForPendingRefresh(key, oldAccessToken); + } + + // claim that we are the "thread" doing the refresh + Gitana.REFRESH_TOKEN_LOCKS[key] = true; + + // make the http call for the refresh + _doRefreshAccessToken(function(response) { + + // all done, delete the lock + delete Gitana.REFRESH_TOKEN_LOCKS[key]; + + // callback + success(response); + + }, function(http, xhr) { + + // didn't work, release the lock + delete Gitana.REFRESH_TOKEN_LOCKS[key]; + + // callback + failure(http, xhr); + }); + }; + + const _doRefreshAccessToken = function(success, failure) { + + const onSuccess = function(response) + { + const object = JSON.parse(response.text); + if (response["error"]) + { + self.error = object["error"]; + self.errorDescription = object["error_description"]; + self.errorUri = object["error_uri"]; + } + else + { + const _accessToken = object["access_token"]; + const _refreshToken = object["refresh_token"]; + const _expiresIn = object["expires_in"]; + //self.grantedScope = object["scope"]; // this doesn't come back on refresh, assumed the same + const _grantTime = new Date().getTime(); + const _grantedScope = self.grantedScope(); + + // store into persistent storage + self.clearStorage(); + self.accessToken(_accessToken); + self.refreshToken(_refreshToken); + self.expiresIn(_expiresIn); + self.grantedScope(_grantedScope); + self.grantTime(_grantTime); + } + + success(response); + }; + + const onFailure = function(http, xhr) { + + Gitana.REFRESH_TOKEN_FAILURE_FN(self, http, xhr); + + failure(http, xhr); + }; + + const o = { + success: onSuccess, + failure: onFailure, + headers: {}, + url: self.getPrefixedTokenURL(), + method: Gitana.OAuth2Http.TOKEN_METHOD + }; + + if (Gitana.OAUTH2_TOKEN_REQUEST_HEADERS) + { + for (var k in Gitana.OAUTH2_TOKEN_REQUEST_HEADERS) + { + o.headers[k] = Gitana.OAUTH2_TOKEN_REQUEST_HEADERS[k]; + } + } + + o.headers["Authorization"] = self.getClientAuthorizationHeader(); + + // query string + const qs = {}; + + // ticket max age + if (self.ticketMaxAge) + { + qs["ticketMaxAge"] = self.ticketMaxAge; + } + + // if we're POSTing, do so as application/x-www-form-urlencoded to make secure over the wire + if ("post" === Gitana.OAuth2Http.TOKEN_METHOD.toLowerCase()) + { + o.headers["Content-Type"] = "application/x-www-form-urlencoded"; + + // url encoded payload + const urlEncodedTokens = {}; + urlEncodedTokens["grant_type"] = "refresh_token"; + urlEncodedTokens["refresh_token"] = self.refreshToken(); + if (self.requestedScope) + { + urlEncodedTokens["scope"] = self.requestedScope; + } + o.data = "" + Gitana.Http.toQueryString(urlEncodedTokens); + } + else + { + qs["grant_type"] = "refresh_token"; + qs["refresh_token"] = self.refreshToken(); + if (self.requestedScope) + { + qs["scope"] = self.requestedScope; + } + } + + // append into query string + const queryString = Gitana.Http.toQueryString(qs); + if (queryString) + { + if (o.url.indexOf("?") > -1) + { + o.url = o.url + "&" + queryString; + } + else + { + o.url = o.url + "?" + queryString; + } + } + + self.invoke(o); + }; + + const doCall = function(autoAttemptRefresh) + { + const successHandler = function(response) + { + options.success(response); + }; + + const failureHandler = function(http, xhr) + { + if (autoAttemptRefresh) + { + // there are a few good reasons why this might naturally fail + // + // 1. our access token is invalid, has expired or has been forcefully invalidated on the Cloud CMS server + // in this case, we get back a 200 and something like http.text = + // {"error":"invalid_token","error_description":"Invalid access token: blahblahblah"} + // + // 2. the access token no longer permits access to the resource + // in this case, we get back a 401 + // it might not make much sense to re-request a new access token, but we do just in case. + + let notJson = false; + let isInvalidToken = false; + if (http.text) + { + let responseData = {}; + + // catch if http.text is not JSON + try + { + responseData = JSON.parse(http.text); + } + catch (e) + { + console.log("Error response is not json"); + console.log(e); + console.log(http.text); + notJson = true; + } + + if (responseData.error) + { + if (responseData.error === "invalid_token") + { + isInvalidToken = true; + } + } + } + const is401 = (http.code === 401); + const is400 = (http.code === 400); + const is403 = (http.code === 403); + const isTimeout = http.timeout; + + // handle both cases + if (is401 || is400 || is403 || isInvalidToken || (notJson && !isTimeout)) + { + if (self.refreshToken()) + { + // use the refresh token to acquire a new access token + doRefreshAccessToken(function() { + + // success, got a new access token + + doCall(false); + + }, function() { + + // failure, nothing else we can do + // call into intended failure handler with the original failure http object + options.failure(http, xhr); + }); + } + else + { + // fail case - nothing we can do + options.failure(http, xhr); + } + } + else + { + // some other kind of error + options.failure(http, xhr); + } + } + else + { + // we aren't allowed to automatically attempt to get a new token via refresh token + options.failure(http, xhr); + } + }; + + // call through to the protected resource (with custom success/failure handling) + const o = {}; + Gitana.copyInto(o, options); + o.success = successHandler; + o.failure = failureHandler; + if (!o.headers) + { + o.headers = {}; + } + if (Gitana.OAUTH2_TOKEN_REQUEST_HEADERS) + { + for (var k in Gitana.OAUTH2_TOKEN_REQUEST_HEADERS) + { + o.headers[k] = Gitana.OAUTH2_TOKEN_REQUEST_HEADERS[k]; + } + } + if (!self.cookieMode && !self.ticketMode) + { + o.headers["Authorization"] = self.getBearerAuthorizationHeader(); + } + if (self.ticketMode) + { + o.headers["GITANA_TICKET"] = encodeURIComponent(self.ticketMode); + } + o.url = self.getPrefixedURL(o.url); + + // make the call + self.invoke(o); + }; + + // if we have an access token and it's about to expire (within 20 seconds of it's expiry), + // we force an early refresh of the access token so that concurrent requests don't get access problems + // this is important for any browser-originated requests that rely on a persisted cookie (GITANA_TICKET) + // + // also provide some debugging if needed + let forceRefresh = false; + if (self.accessToken()) + { + const grantTime = self.grantTime(); + if (grantTime) + { + const expiresIn = self.expiresIn(); + if (expiresIn) + { + // NOTE: expiresIn is in seconds + const expirationTimeMs = self.grantTime() + (self.expiresIn() * 1000); + const nowTimeMs = new Date().getTime(); + + const timeRemainingMs = expirationTimeMs - nowTimeMs; + if (timeRemainingMs <= 0) + { + // console.log("Access Token is expired, refresh will be attempted!"); + } + else + { + // console.log("Access Token Time Remaining: " + timeRemainingMs); + } + + if (timeRemainingMs <= 20000) + { + // console.log("Access Token only has 20 seconds left, forcing early refresh"); + forceRefresh = true; + } + } + } + } + + // if no access token, request one + if ((!self.accessToken() || forceRefresh) && !this.cookieMode && !this.ticketMode) + { + if (!self.refreshToken()) + { + // no refresh token, do an authorization call + doGetAccessToken(function() { + + // got an access token, so proceed + doCall(true); + + }, function(http, xhr) { + + // access denied + options.failure(http, xhr); + + }); + } + else + { + // we have a refresh token, so do a refresh call + doRefreshAccessToken(function() { + + // got an access token, so proceed + doCall(true); + + }, function(http, xhr) { + + // unable to get an access token + options.failure(http, xhr); + + }); + } + } + else + { + // we already have an access token + doCall(true); + } + }, + + /** + * Refreshes the OAuth2 access token. + */ + refresh: function(callback) + { + const self = this; + + const currentRefreshToken = self.refreshToken(); + if (!currentRefreshToken) + { + return callback({ + "message": "The driver does not have a refresh token, cannot refresh" + }); + } + + const onSuccess = function(response) + { + const object = JSON.parse(response.text); + if (object["error"]) + { + self.error = object["error"]; + self.errorDescription = object["error_description"]; + self.errorUri = object["error_uri"]; + + return callback({ + "error": self.error, + "message": self.errorDescription + }); + } + else + { + const _accessToken = object["access_token"]; + const _refreshToken = object["refresh_token"]; + const _expiresIn = object["expires_in"]; + //self.grantedScope = object["scope"]; // this doesn't come back on refresh, assumed the same + const _grantTime = new Date().getTime(); + const _grantedScope = self.grantedScope(); + + // store into persistent storage + self.clearStorage(); + self.accessToken(_accessToken); + self.refreshToken(_refreshToken); + self.expiresIn(_expiresIn); + self.grantedScope(_grantedScope); + self.grantTime(_grantTime); + + callback(); + } + }; + + const onFailure = function(http, xhr) + { + if (Gitana.REFRESH_TOKEN_FAILURE_FN) + { + Gitana.REFRESH_TOKEN_FAILURE_FN(self, http, xhr); + } + + // clear storage + self.clearStorage(); + + callback({ + "message": "Unable to refresh access token" + }); + }; + + const o = { + success: onSuccess, + failure: onFailure, + headers: {}, + url: self.getPrefixedTokenURL(), + method: Gitana.OAuth2Http.TOKEN_METHOD + }; + + if (Gitana.OAUTH2_TOKEN_REQUEST_HEADERS) + { + for (var k in Gitana.OAUTH2_TOKEN_REQUEST_HEADERS) + { + o.headers[k] = Gitana.OAUTH2_TOKEN_REQUEST_HEADERS[k]; + } + } + + o.headers["Authorization"] = self.getClientAuthorizationHeader(); + + // query string + const qs = {}; + + // ticket max age + if (self.ticketMaxAge) + { + qs["ticketMaxAge"] = self.ticketMaxAge; + } + + // if we're POSTing, do so as application/x-www-form-urlencoded to make secure over the wire + if ("post" === Gitana.OAuth2Http.TOKEN_METHOD.toLowerCase()) + { + o.headers["Content-Type"] = "application/x-www-form-urlencoded"; + + // url encoded data + const urlEncodedTokens = {}; + urlEncodedTokens["grant_type"] = "refresh_token"; + urlEncodedTokens["refresh_token"] = self.refreshToken(); + if (self.requestedScope) + { + urlEncodedTokens["scope"] = self.requestedScope; + } + o.data = "" + Gitana.Http.toQueryString(urlEncodedTokens); + } + else + { + qs["grant_type"] = "refresh_token"; + qs["refresh_token"] = self.refreshToken(); + if (self.requestedScope) + { + qs["scope"] = self.requestedScope; + } + } + + // append into query string + const queryString = Gitana.Http.toQueryString(qs); + if (queryString) + { + if (o.url.indexOf("?") > -1) + { + o.url = o.url + "&" + queryString; + } + else + { + o.url = o.url + "?" + queryString; + } + } + + self.invoke(o); + } + + }); + + /** + * Provides a storage location for OAuth2 credentials + * + * @param scope + * + * @return storage instance + * @constructor + */ + Gitana.OAuth2Http.Storage = function(scope) + { + // in-memory implementation of HTML5 storage interface + const memoryStorage = function() { + + const memory = {}; + + const m = {}; + m.removeItem = function(key) + { + delete memory[key]; + }; + + m.getItem = function(key) + { + return memory[key]; + }; + + m.setItem = function(key, value) + { + memory[key] = value; + }; + + return m; + }(); + + /** + * Determines whether the current runtime environment supports HTML5 local storage + * + * @return {Boolean} + */ + const supportsLocalStorage = function() + { + try { + return 'localStorage' in window && window['localStorage'] !== null; + } catch (e) { + return false; + } + }; + + /** + * Determines whether the current runtime environment supports HTML5 session storage. + * + * @return {Boolean} + */ + const supportsSessionStorage = function() + { + try { + return 'sessionStorage' in window && window['sessionStorage'] !== null; + } catch (e) { + return false; + } + }; + + const acquireStorage = function() + { + let storage = null; + + // store + if (scope === "session" && supportsSessionStorage()) + { + storage = sessionStorage; + } + else if (scope === "local" && supportsLocalStorage()) + { + storage = localStorage; + } + else + { + // fall back to memory-based storage + storage = memoryStorage; + } + + return storage; + }; + + // result object + const r = {}; + + /** + * Clears state. + */ + r.clear = function() + { + // we first set to empty to account for a bug in Chrome + // this bug is with the removeItem method where it sometimes doesn't work, so force to empty to handle worst case + // https://bugs.chromium.org/p/chromium/issues/detail?id=765524 + acquireStorage().setItem("gitanaAuthState", ""); + + // now do the actual remove + acquireStorage().removeItem("gitanaAuthState"); + }; + + /** + * Pokes and peeks the value of a key in the state. + * + * @param key + * @param value + * + * @return {*} + */ + r.poke = function(key, value) + { + let state = {}; + + const stateString = acquireStorage().getItem("gitanaAuthState"); + if (stateString && stateString !== "") { + state = JSON.parse(stateString); + } + + let touch = false; + if (typeof(value) !== "undefined" && value !== null) + { + state[key] = value; + touch = true; + } + else if (value === null) + { + delete state[key]; + touch = true; + } + + if (touch) { + acquireStorage().setItem("gitanaAuthState", JSON.stringify(state)); + } + + return state[key]; + }; + + return r; + }; + +}(this)); + +// statics +Gitana.OAuth2Http.PASSWORD = "password"; +Gitana.OAuth2Http.AUTHORIZATION_CODE = "authorization_code"; +Gitana.OAuth2Http.TOKEN = "token"; +Gitana.OAuth2Http.COOKIE = "cookie"; +Gitana.OAuth2Http.TICKET = "ticket"; + +// method to use for retrieving access and refresh tokens +//Gitana.OAuth2Http.TOKEN_METHOD = "GET"; +Gitana.OAuth2Http.TOKEN_METHOD = "POST"; + + + +(function(window) +{ + /** + * Creates a chain. If an object is provided, the chain is augmented onto the object. + * + * @param object + * @param skipAutoTrap + */ + Chain = function(object, skipAutoTrap) + { + if (!object) + { + object = {}; + } + + // wraps the object into a proxy + const proxiedObject = Chain.proxy(object); + + // the following methods get pushed onto the chained object + // methods for managing chain state + proxiedObject.__queue = (function() { + let queue = []; + return function(x) { + if (x) { if (x === 'empty') { queue = []; } else { queue.push(x); }} + return queue; + }; + })(); + proxiedObject.__response = (function() { + let response = null; + return function(x) { + if (!Gitana.isUndefined(x)) { if (x) { response = x; } else { response = null; } } + return response; + }; + })(); + proxiedObject.__waiting = (function() { + let waiting = false; + return function(x) { + if (!Gitana.isUndefined(x)) { waiting = x; } + return waiting; + }; + })(); + proxiedObject.__parent = (function() { + let parent = null; + return function(x) { + if (!Gitana.isUndefined(x)) { if (x) { parent = x; } else { parent = null; } } + return parent; + }; + })(); + proxiedObject.__id = (function() { + let id = Chain.idCount; + Chain.idCount++; + return function() { + return id; + }; + })(); + proxiedObject.__helper = (function() { + let helper = null; + return function(x) { + if (x) { helper = x; } + return helper; + }; + })(); + // marks any chain links which are placeholders for functions + proxiedObject.__transparent = (function() { + let transparent = false; // assume not transparent + return function(x) { + if (!Gitana.isUndefined(x)) { transparent = x; } + return transparent; + }; + })(); + // provides consume behavior for copy into (from another object into this one) + if (!proxiedObject.__copyState) { + proxiedObject.__copyState = function(other) { + Gitana.copyInto(this, other); + }; + } + + + + + /** + * Queues either a callback function, an array of callback functions or a subchain. + * + * @param element + * @param [functionName] function name for debugging + */ + proxiedObject.then = function(element, functionName) + { + const self = this; + + let autorun = false; + + // + // ARRAY + // + // if we're given an array of functions, we'll automatically build out a function that orchestrates + // the concurrent execution of parallel chains. + // + // the function will be pushed onto the queue + // + if (Gitana.isArray(element)) + { + const array = element; + + // parallel function invoker + const parallelInvoker = function() + { + // build out parallel functions + const fns = []; + for (let i = 0; i < array.length; i++) + { + const fn = function(func) + { + return function(done) + { + // each function gets loaded onto its own "parallel" chain + // the parallel chain contains a subchain and the onComplete method + // the parallel chain is a clone of this chain + // the subchain runs the function + // these are serial so that the subchain must complete before the onComplete method is called + const parallelChain = Chain(); // note: empty chain (parent) + parallelChain.__waiting(true); // this prevents auto-run (which would ground out the first subchain call) + parallelChain.subchain(self).then(function () { // TODO: should we self.clone() for parallel operations? + func.call(this); + }); + parallelChain.then(function () { + done(); + }); + parallelChain.__waiting(false); // switch back to normal + parallelChain.run(); + }; + }(array[i]); + fns.push(fn); + } + + let count = 0; + const total = fns.length; + const onComplete = function() + { + count++; + if (count === total) + { + // manually signal that we're done + self.next(); + } + }; + + // run all of the functions in parallel + for (let i = 0; i < fns.length; i++) + { + window.setTimeout(function(fn) { + return function() { + fn(function() { + onComplete(); + }); + }; + }(fns[i])); + } + + // return false so that we wait for manual self.next() signal + return false; + }; + + // build a subchain (transparent) + const subchain = this.subchain(null, true); // don't auto add, we'll do it ourselves + subchain.__queue(parallelInvoker); + if (functionName) { subchain.__helper(functionName); } + element = subchain; + } + + // + // FUNCTION + // + // if we're given a function, then we're being asked to execute a function serially. + // to facilitate this, we'll wrap it in a subchain and push the subchain down into the queue. + // the reason is just to make things a little easier and predictive of what the end user might do with + // the chain. they probably don't expect it to just exit out if they try to to + // this.then(something) + // in other words, they should always feel like they have their own chain (which in fact they do) + else if (Gitana.isFunction(element)) + { + // create the subchain + // this does a re-entrant call that adds it to the queue (as a subchain) + const subchain = this.subchain(null, true); // don't auto add, we'll do it ourselves + subchain.__queue(element); + if (functionName) { subchain.__helper(functionName); } + element = subchain; + + // note: because we're given a function, we can tell this chain to try to "autorun" + autorun = true; + } + + + // anything that arrives this far is just a subchain + this.__queue(element); + + + // if we're able to autorun (meaning that we were told to then() a function)... + // we climb the parents until we find the topmost parent and tell it to run. + if (autorun && !this.__waiting()) + { + let runner = this; + while (runner.__parent()) + { + runner = runner.__parent(); + } + + if (!runner.__waiting()) + { + runner.run(); + } + } + + // always hand back reference to ourselves + return this; + }; + + /** + * Run the next element in the queue + */ + proxiedObject.run = function() + { + const self = this; + + // short cut, if nothing in the queue, bail + if (this.__queue().length === 0 || this.__waiting()) + { + return this; + } + + // mark that we're running something + this.__waiting(true); + + // the element to run + const element = this.__queue().shift(); + + // case: callback function + if (Gitana.isFunction(element)) + { + // it's a callback function + const callback = element; + + // try to determine response and previous response + let response = null; + let previousResponse = null; + if (this.__parent()) + { + response = this.__parent().__response(); + if (this.__parent().__parent()) + { + previousResponse = this.__parent().__parent().__response(); + } + } + + // async + window.setTimeout(function() + { + Chain.log(self, (self.__helper() ? self.__helper()+ " " : "") + "> " + element.toString()); + + // execute with "this = chain" + const returned = callback.call(self, response, previousResponse); + if (returned !== false) + { + self.next(returned); + } + }, 0); + } + else + { + // it's a subchain element (object) + // we make sure to copy response forward + const subchain = element; + subchain.__response(this.__response()); + + // pre-emptively copy forward into subchain + // only do this if the subchain is transparent + if (subchain.__transparent()) + { + //Gitana.copyInto(subchain, this); + subchain.__copyState(this); + } + + // BEFORE CHAIN RUN CALLBACK + // this provides a way for a chained object to adjust its method signatures and state ahead + // of actually executing, usually based on some data that was loaded (such as the type of object + // like a domain user or group) + // + if (subchain.beforeChainRun) + { + subchain.beforeChainRun.call(subchain); + } + + subchain.run(); + } + + return this; + }; + + /** + * Creates a subchain and adds it to the queue. + * + * If no argument is provided, the generated subchain will be cloned from the current chain element. + */ + proxiedObject.subchain = function(object, noAutoAdd) + { + let transparent = false; + if (!object) { + transparent = true; + } + + if (!object) + { + object = this; + } + + const subchain = Chain(object, true); + subchain.__parent(this); + + // BEFORE CHAIN RUN CALLBACK + // this provides a way for a chained object to adjust its method signatures and state ahead + // of actually executing, usually based on some data that was loaded (such as the type of object + // like a domain user or group) + // + if (subchain.beforeChainRun) + { + subchain.beforeChainRun.call(subchain); + } + + if (!noAutoAdd) + { + this.then(subchain); + } + + subchain.__transparent(transparent); + + return subchain; + }; + + /** + * Completes the current element in the chain and provides the response that was generated. + * + * The response is pushed into the chain as the current response and the current response is bumped + * back as the previous response. + * + * If the response is null, nothing will be bumped. + * + * @param {Object} response + */ + proxiedObject.next = function(response) + { + // toggle responses + if (typeof response !== "undefined") + { + this.__response(response); + } + + // no longer processing callback + this.__waiting(false); + + // if there isn't anything left in the queue, then we're done + // if we have a parent, we can signal that we've completed + if (this.__queue().length === 0) + { + if (this.__parent()) + { + // copy response up to parent + const r = this.__response(); + this.__parent().__response(r); + this.__response(null); + + // if the current node is transparent, then copy back to parent + //if (this.__transparent()) + if (this.__transparent()) + { + Gitana.deleteProperties(this.__parent()); + //Gitana.copyInto(this.__parent(), this); + this.__parent().__copyState(this); + } + + // inform parent that we're done + this.__parent().next(); + } + + // clear parent so that this chain can be relinked + this.__parent(null); + this.__queue('empty'); + } + else + { + // run the next element in the queue + this.run(); + } + }; + + /** + * Tells the chain to sleep the given number of milliseconds + */ + proxiedObject.wait = function(ms) + { + return this.then(function() { + + const wake = function(chain) + { + return function() + { + chain.next(); + }; + }(this); + + window.setTimeout(wake, ms); + + return false; + }); + }; + + /** + * Registers an error handler; + * + * @param errorHandler + */ + proxiedObject.trap = function(errorHandler) + { + this.errorHandler = errorHandler; + + return this; + }; + + /** + * Handles the error. + * + * @param err + */ + proxiedObject.error = function(err) + { + // find the first error handler we can walking up the chain + let errorHandler = null; + let ancestor = this; + while (ancestor && !errorHandler) + { + errorHandler = ancestor.errorHandler; + if (!errorHandler) + { + ancestor = ancestor.__parent(); + } + } + + // clean up the chain so that it can still be used + this.__queue('empty'); + this.__response(null); + + // disconnect and stop the parent from processing + if (this.__parent()) + { + this.__parent().__queue('empty'); + this.__parent().__waiting(false); + } + + if (!errorHandler) + { + errorHandler = Gitana.defaultErrorHandler; + } + + // invoke error handler + const code = errorHandler.call(this, err); + + // finish out the chain if we didn't get "false" + if (code !== false) + { + this.next(); + } + }; + + /** + * Completes a chain and hands control back up to the parent. + */ + proxiedObject.done = function() + { + return this.__parent(); + }; + + /** + * Creates a new chain for this object + */ + proxiedObject.chain = function() + { + return Chain(this, true).then(function() { + // empty chain to kick start + }); + }; + + + // each object that gets chained provides a clone() method + // if there is already a clone property, don't override it + // this allows implementation classes to control how they get cloned + if (!proxiedObject.clone) + { + /** + * Clones this chain and resets chain properties. + */ + proxiedObject.clone = function() + { + return Chain.clone(this); + }; + } + + // apply auto trap? + if (!skipAutoTrap && autoTrap()) + { + proxiedObject.trap(autoTrap()); + } + + return proxiedObject; + }; + + /** + * Wraps the given object into a proxy. + * + * If the object is an existing proxy, it is unpackaged and re-proxied. + * @param o + */ + Chain.proxy = function(o) + { + if (o.__original && o.__original()) + { + // NOTE: we can't just unproxy since that loses all state of the current object + + // unproxy back to original + //o = Chain.unproxy(o); + + // for now, we can do this? + delete o.__original; + } + + // clone the object using clone() method + let proxy = null; + if (o.clone) { + proxy = o.clone(); + } else { + proxy = Chain.clone(o); + } + proxy.__original = function() { + return o; + }; + + return proxy; + }; + + /** + * Hands back the original object for a proxy. + * + * @param proxy + */ + Chain.unproxy = function(proxy) + { + let o = null; + + if (proxy.__original && proxy.__original()) + { + o = proxy.__original(); + } + + return o; + }; + + Chain.debug = false; + Chain.log = function(chain, text) + { + if (Chain.debug && !Gitana.isUndefined(console)) + { + const f = function() + { + let identifier = this.__id(); + if (this.__transparent()) { + identifier += "[t]"; + } + + if (!this.__parent()) + { + return identifier; + } + + return f.call(this.__parent()) + " > " + identifier; + }; + + const identifier = f.call(chain); + + console.log("Chain[" + identifier + "] " + text); + } + }; + // clone workhorse method + Chain.clone = function(object) + { + // based on Crockford's solution for clone using prototype on function + // this copies all properties and methods + // includes copies of chain functions + function F() {} + F.prototype = object; + const clone = new F(); + + // copy properties + Gitana.copyInto(clone, object); + + return clone; + }; + + let autoTrapValue = null; + const autoTrap = Chain.autoTrap = function(_autoTrap) + { + if (_autoTrap) + { + autoTrapValue = _autoTrap; + } + + return autoTrapValue; + }; + + Chain.idCount = 0; + +})(window);(function(window) +{ + Gitana = window.Gitana; + + Gitana.Chainable = Base.extend( + /** @lends Gitana.Chainable.prototype */ + { + /** + * @constructs + * + * @param {Gitana.Driver} driver + * + * @class Provides common chaining functions used by various interface methods + */ + constructor: function(driver) + { + this.base(); + + /** + * Override the Chain.__copyState method so that it utilizes a base method that we can override + * on a per-class basis. + */ + this.__copyState = function(other) { + Gitana.copyInto(this, other); + this.chainCopyState(other); + }; + + + + /////////////////////////////////////////////////////////////////////////////////////////////////////// + // + // privileged methods + // + /////////////////////////////////////////////////////////////////////////////////////////////////////// + + this.getDriver = function() + { + return driver; + }; + + this.getFactory = function() + { + return new Gitana.ObjectFactory(); + }; + + this.httpError = function(httpError) + { + const err = new Gitana.Error(); + err.name = "Http Error"; + err.message = httpError.message; + err.status = httpError.status; + err.statusText = httpError.statusText; + + if (httpError.errorType) + { + err.errorType = httpError.errorType; + } + + // stack trace might be available + if (httpError.stacktrace) + { + err.stacktrace = httpError.stacktrace; + } + + // info that might come back + if (httpError.info) + { + err.info = httpError.info; + } + + // any text? if so, capture it + if (httpError.response && httpError.response.text) + { + err.responseText = httpError.response.text; + + // and also make an attempt to convert to JSON data + try { + err.responseData = JSON.parse(err.responseText); + } catch (e) { } + } + + this.error(err); + + return false; + }; + + this.missingNodeError = function(id) + { + const err = new Gitana.Error(); + err.name = "Missing Node error"; + err.message = "The node: " + id + " could not be found"; + + this.error(err); + + return false; + }; + + + + + ///////////////////////////////////////////////////////////////////////////////////////// + // + // PRIVILEGED + // CHAIN HANDLERS + // + ///////////////////////////////////////////////////////////////////////////////////////// + + /** + * Performs a GET from the server and populates the chainable. + * Proceeds with the chain as bound to the chainable. + * + * @param chainable + * @param uri + * @param params + */ + this.chainGet = function(chainable, uri, params) + { + const self = this; + + return this.subchain(chainable).then(function() { + + const chain = this; + + // allow for closures on uri for late resolution + if (Gitana.isFunction(uri)) { + uri = uri.call(self); + } + + driver.gitanaGet(uri, params, {}, function(response) { + chain.handleResponse(response); + chain.next(); + }, function(http) { + self.httpError(http); + }); + + // NOTE: we return false to tell the chain that we'll manually call next() + return false; + }); + }; + + /** + * Creates an object on the server (write + read). + * Proceeds with the chain as bound to the chainable. + * + * @param chainable + * @param object + * @param uri + * @param params + */ + this.chainCreate = function(chainable, object, uri, params) + { + const self = this; + + return this.subchain(chainable).then(function() { + + const chain = this; + + // allow for closures on uri for late resolution + if (Gitana.isFunction(uri)) { + uri = uri.call(self); + } + + // create + driver.gitanaPost(uri, params, object, function(status) { + driver.gitanaGet(uri + "/" + status.getId(), null, {}, function(response) { + chain.handleResponse(response); + chain.next(); + }, function(http) { + self.httpError(http); + }); + }, function(http) { + self.httpError(http); + }); + + // NOTE: we return false to tell the chain that we'll manually call next() + return false; + + }, "chainCreate"); + }; + + /** + * Creates an object on the server using one URL and then reads it back using another URL. + * This exists because the security responses don't include _doc fields like other responses. + * + * Proceeds with the chain as bound to the chainable. + * + * @param chainable + * @param object + * @param createUri + * @param readUri + */ + this.chainCreateEx = function(chainable, object, createUri, readUri) + { + const self = this; + + return this.subchain(chainable).then(function() { + + const chain = this; + + // allow for closures on uri for late resolution + if (Gitana.isFunction(createUri)) { + createUri = createUri.call(self); + } + + // create + driver.gitanaPost(createUri, null, object, function(status) { + + // allow for closures on uri for late resolution + if (Gitana.isFunction(readUri)) { + readUri = readUri.call(self, status); + } + + driver.gitanaGet(readUri, null, {}, function(response) { + chain.handleResponse(response); + chain.next(); + }, function(http) { + self.httpError(http); + }); + }, function(http) { + self.httpError(http); + }); + + // NOTE: we return false to tell the chain that we'll manually call next() + return false; + }); + }; + + /** + * Performs a POST to the server and populates the chainable with results. + * Proceeds with the chain as bound to the chainable. + * + * @param chainable + * @param uri + * @param params + * @param payload + * @param handleFn + */ + this.chainPost = function(chainable, uri, params, payload, handleFn) + { + const self = this; + + return this.subchain(chainable).then(function() { + + const chain = this; + + // allow for closures on uri for late resolution + if (Gitana.isFunction(uri)) { + uri = uri.call(self); + } + + // create + driver.gitanaPost(uri, params, payload, function(response) { + if (handleFn) { + handleFn(chain, response); + } else { + chain.handleResponse(response); + } + chain.next(); + }, function(http) { + self.httpError(http); + }); + + // NOTE: we return false to tell the chain that we'll manually call next() + return false; + }); + }; + + /** + * Performs a POST to the server. The response is not handled. + * Proceeds with the chain as bound to the chainable. + * + * @param chainable + * @param uri + * @param params + * @param payload (optional) + * @param contentType (optional) - example "text/plain" + */ + this.chainPostEmpty = function(chainable, uri, params, payload, contentType) + { + const self = this; + + // if no payload, set to empty + if (!payload && contentType) + { + if (contentType.indexOf("text/") > -1) + { + payload = ""; + } + else if (contentType === "application/json") + { + payload = {}; + } + } + + return this.subchain(chainable).then(function() { + + const chain = this; + + // allow for closures on uri for late resolution + if (Gitana.isFunction(uri)) { + uri = uri.call(self); + } + + // create + driver.gitanaPost(uri, params, payload, function() { + chain.next(); + }, function(http) { + self.httpError(http); + }); + + // NOTE: we return false to tell the chain that we'll manually call next() + return false; + }); + }; + + /** + * Performs a POST to the server. The response is not handled. + * Proceeds with the chain as bound to the chainable. + * + * @param chainable + * @param uri + * @param params + * @param contentType (optional) - example "text/plain" + * @param payload (optional) + */ + this.chainUpload = function(chainable, uri, params, contentType, payload) + { + const self = this; + + // if no payload, set to empty + if (!payload && contentType) + { + if (contentType.indexOf("text/") > -1) + { + payload = ""; + } + else if (contentType === "application/json") + { + payload = {}; + } + } + + return this.subchain(chainable).then(function() { + + const chain = this; + + // allow for closures on uri for late resolution + if (Gitana.isFunction(uri)) { + uri = uri.call(self); + } + + // create + driver.gitanaUpload(uri, params, contentType, payload, function() { + chain.next(); + }, function(http) { + self.httpError(http); + }); + + // NOTE: we return false to tell the chain that we'll manually call next() + return false; + }); + }; + + /** + * Performs a GET to the server and pushes the response into the chain. + * Proceeds with the chain as bound to the chainable. + * + * @param chainable + * @param uri + * @param params + */ + this.chainGetResponse = function(chainable, uri, params) + { + const self = this; + + return this.subchain(chainable).then(function() { + + const chain = this; + + // allow for closures on uri for late resolution + if (Gitana.isFunction(uri)) { + uri = uri.call(self); + } + + driver.gitanaGet(uri, params, {}, function(response) { + chain.next(response); + }, function(http) { + self.httpError(http); + }); + + // NOTE: we return false to tell the chain that we'll manually call next() + return false; + }); + }; + + /** + * Performs a GET to the server and pushes the text response to the callback. + * + * @param chainable + * @param uri + * @param params + */ + this.chainGetResponseText = function(chainable, uri, params) + { + const self = this; + + return this.subchain(chainable).then(function() { + + const chain = this; + + // allow for closures on uri for late resolution + if (Gitana.isFunction(uri)) { + uri = uri.call(self); + } + + driver.gitanaRequest("GET", uri, params, "text/plain", null, {}, function(response) { + chain.next(response); + }, function(http) { + self.httpError(http); + }); + + // NOTE: we return false to tell the chain that we'll manually call next() + return false; + }); + }; + + /** + * Performs a GET to the server and pushes the "rows" response attribute into the chain. + * Proceeds with the chain as bound to the chainable. + * + * @param chainable + * @param uri + * @param params + */ + this.chainGetResponseRows = function(chainable, uri, params) + { + return this.chainGetResponse(chainable, uri, params).then(function(response) { + return response["rows"]; + }); + }; + + /** + * Performs a GET to the server and checks whether the "rows" array attribute of the response + * has the given value. + * + * Proceeds with the chain as bound to the chainable. + * + * @param chainable + * @param uri + * @param value + */ + this.chainHasResponseRow = function(chainable, uri, value) + { + return this.chainGetResponse(chainable, uri).then(function(response) { + let authorized = false; + for (let i = 0; i < response.rows.length; i++) + { + if (response.rows[i].toLowerCase() === value.toLowerCase()) + { + authorized = true; + } + } + return authorized; + }); + }; + + /** + * Performs a POST to the server and pushes the response into the chain. + * Proceeds with the chain as bound to the chainable. + * + * @param chainable + * @param uri + * @param params + * @param payload + */ + this.chainPostResponse = function(chainable, uri, params, payload) + { + const self = this; + + return this.subchain(chainable).then(function() { + + const chain = this; + + // allow for closures on uri for late resolution + if (Gitana.isFunction(uri)) { + uri = uri.call(self); + } + + driver.gitanaPost(uri, params, payload, function(response) { + chain.next(response); + }, function(http) { + self.httpError(http); + }); + + // NOTE: we return false to tell the chain that we'll manually call next() + return false; + }); + }; + + + /** + * Helper to gets the principal id for a principal object, json structure or principal id itself. + * This returns something like "domainId/principalId" + * + * @param principal + * @param defaultDomainId + */ + this.extractPrincipalDomainQualifiedId = function(principal, defaultDomainId) + { + const identifiers = this.extractPrincipalIdentifiers(principal, defaultDomainId); + + return identifiers["domain"] + "/" + identifiers["principal"]; + }; + + /** + * Helper to gets the principal id for a principal object, json structure or principal id itself. + * This returns something like "domainId/principalId" + * + * @param principal principal object or string (principal id or domain qualified principal id) + * @param defaultDomainId + */ + this.extractPrincipalIdentifiers = function(principal, defaultDomainId) + { + const identifiers = {}; + + if (!defaultDomainId) + { + defaultDomainId = "default"; + } + + if (Gitana.isString(principal)) + { + const x = principal.indexOf("/"); + if (x > -1) + { + identifiers["domain"] = principal.substring(0, x); + identifiers["principal"] = principal.substring(x + 1); + } + else + { + identifiers["domain"] = defaultDomainId; + identifiers["principal"] = principal; + } + } + else if (principal.objectType && principal.objectType() === "Gitana.DomainPrincipal") + { + identifiers["domain"] = principal.getDomainId(); + identifiers["principal"] = principal.getId(); + } + else if (principal.objectType && principal.objectType() === "Gitana.TeamMember") + { + identifiers["domain"] = principal["domainId"]; + identifiers["principal"] = principal["_doc"]; + } + else if (principal["_doc"]) + { + identifiers["domain"] = defaultDomainId; + identifiers["principal"] = principal["_doc"]; + } + else if (principal["name"]) + { + identifiers["domain"] = defaultDomainId; + identifiers["principal"] = principal["name"]; + } + + return identifiers; + }; + }, + + /** + * Used internally during chain copy going forward or backward through the chain. + * + * This is wired into the Chain.__copyState method and allows a convenient way to override + * chain copy behavior on a per-object-type basis. + * + * @param otherObject + */ + chainCopyState: function(otherObject) + { + } + + }); + +})(window); +(function(window) +{ + Gitana = window.Gitana; + + Gitana.Response = Base.extend( + /** @lends Gitana.Response.prototype */ + { + /** + * @constructs + * + * @class Gitana Response that wraps a response document from the Gitana server. + * + * @param {Object} object json response object + */ + constructor: function(object) + { + Gitana.copyInto(this, object); + }, + + /** + * Gets the id ("_doc") field of the response (if one is available). + * + * @public + * + * @returns {String} id + */ + getId: function() + { + return this["_doc"]; + }, + + /** + * Indicates whether this response is a Status Document. + * + * @public + * + * @returns {Boolean} whether this is a status document + */ + isStatusDocument: function() + { + return (this["ok"] || this["error"]); + }, + + /** + * Indicates whether this response is a List Document. + * + * @public + * + * @returns {Boolean} whether this is a list document + */ + isListDocument: function() + { + return this["total_rows"] && this["rows"] && this["offset"]; + }, + + /** + * Indicates whether this response is a Data Document. + * + * @public + * + * @returns {Boolean} whether this is a data document + */ + isDataDocument: function() + { + return (!this.isStatusDocument() && !this.isListDocument()); + }, + + /** + * Indicates whether the response is "ok". + * + * @public + * + * @returns {Boolean} whether the response is "ok" + */ + isOk: function() + { + // assume things are ok + let ok = true; + + if (this.isStatusDocument()) { + if (this["ok"] != null) { + ok = this["ok"]; + } + } + + // any document type can specify an error + if (this["error"]) { + ok = false; + } + + return ok; + }, + + /** + * Indicates whetehr the response is in an error state. + * + * @public + * + * @returns {Boolean} whether the response is in an error state + */ + isError: function() + { + return !this.isOk(); + } + + }); + +})(window); +(function(window) +{ + Gitana = window.Gitana; + + Gitana.AuthInfo = Base.extend( + /** @lends Gitana.AuthInfo.prototype */ + { + /** + * @constructs + * + * @class Gitana.AuthInfo holds authentication info for the driver + * + * @param {Object} object json response object + */ + constructor: function(object) + { + Gitana.copyInto(this, object); + }, + + getPrincipalId: function() + { + return this["principalId"]; + }, + + getPrincipalDomainId: function() + { + return this["principalDomainId"]; + }, + + getPrincipalName: function() + { + return this["principalName"]; + }, + + getTenantId: function() + { + return this["tenantId"]; + }, + + getTenantTitle: function() + { + return this["tenantTitle"]; + }, + + getTenantDescription: function() + { + return this["tenantDescription"]; + }, + + getClientId: function() + { + return this["clientId"]; + }, + + getTicket: function() + { + return this["ticket"]; + } + }); + +})(window); +(function(window) +{ + Gitana = window.Gitana; + + Gitana.SystemMetadata = Base.extend( + /** @lends Gitana.SystemMetadata.prototype */ + { + /** + * @constructs + * + * @class System Metadata + */ + constructor: function() + { + this.base(); + }, + + updateFrom: function(json) + { + // clear old system properties + Gitana.deleteProperties(this, false); + + Gitana.copyInto(this, json); + }, + + get: function(key) + { + return this[key]; + }, + + /** + * Retrieves the changeset id. + * + * @public + * + * @return the changeset id + */ + getChangesetId: function() + { + return this.get("changeset"); + }, + + /** + * Retrieves the name of the user who created this object. + * + * @public + * + * @return the user name of the creator + */ + getCreatedBy: function() + { + return this.get("created_by"); + }, + + /** + * Retrieves the id of the user who created this object. + * + * @public + * + * @return the user id of the creator + */ + getCreatedByPrincipalId: function() + { + return this.get("created_by_principal_id"); + }, + + /** + * Retrieves the domain id of the user who created this object. + * + * @public + * + * @return the user domain id of the creator + */ + getCreatedByPrincipalDomainId: function() + { + return this.get("created_by_principal_domain_id"); + }, + + /* + readCreatedByPrincipal: function(platform) + { + return this.subchain(platform).readDomain(this.getCreatedByPrincipalDomainId).readPrincipal(this.getCreatedByPrincipalId); + }, + */ + + /** + * Retrieves the id of the user who modified this object. + * + * @public + * + * @return the user id of the modifier + */ + getModifiedBy: function() + { + return this.get("modified_by"); + }, + + /** + * Retrieves the id of the user who modified this object. + * + * @public + * + * @return the user id of the modifier + */ + getModifiedByPrincipalId: function() + { + return this.get("modified_by_principal_id"); + }, + + /** + * Retrieves the domain id of the user who modified this object. + * + * @public + * + * @return the user domain id of the modifier + */ + getModifiedByPrincipalDomainId: function() + { + return this.get("modified_by_principal_domain_id"); + }, + + /* + readModifiedByPrincipal: function(platform) + { + return this.subchain(platform).readDomain(this.getModifiedByPrincipalDomainId).readPrincipal(this.getModifiedByPrincipalId); + }, + */ + + /** + * Retrieves the timestamp for creation of this object. + * + * @public + * + * @return creation timestamp + */ + getCreatedOn: function() + { + if (!this.createdOn) + { + this.createdOn = new Gitana.Timestamp(this.get("created_on")); + } + + return this.createdOn; + }, + + /** + * Retrieves the timestamp for modification of this object. + * + * @public + * + * @return modification timestamp + */ + getModifiedOn: function() + { + if (!this.modifiedOn) + { + this.modifiedOn = new Gitana.Timestamp(this.get("modified_on")); + } + + return this.modifiedOn; + } + + }); + +})(window); +(function(window) +{ + Gitana = window.Gitana; + + Gitana.Timestamp = Base.extend( + /** @lends Gitana.Timestamp.prototype */ + { + /** + * @constructs + * + * @class Timestamp + * + * @param {Object} object the timestamp json object + */ + constructor: function(object) + { + this.base(object); + }, + + /** + * @returns {number} the year + */ + getYear: function() + { + return this["year"]; + }, + + /** + @returns {number} the month + */ + getMonth: function() + { + return this["month"]; + }, + + /** + * @returns {number} the day of the month + */ + getDay: function() + { + return this["day_of_month"]; + }, + + /** + * @returns {number} the hour of the day (24 hour clock) + */ + getHour: function() + { + return this["hour"]; + }, + + /** + * @returns {number} the minute + */ + getMinute: function() + { + return this["minute"]; + }, + + /** + * @returns {number} the second + */ + getSecond: function() + { + return this["second"]; + }, + + /** + * @returns {number} the millisecond (0-1000) + */ + getMillisecond: function() + { + return this["millisecond"]; + }, + + /** + * @returns {number} absolute millisecond + */ + getTime: function() + { + return this["ms"]; + }, + + /** + * @returns {String} text-friendly timestamp + */ + getTimestamp: function() + { + return this["timestamp"]; + } + + }); + +})(window); +(function(window) +{ + Gitana.uniqueIdCounter = 0; + + /** + * Builds an array from javascript method arguments. + * + * @inner + * + * @param {arguments} args + * + * @returns {Array} an array + */ + Gitana.makeArray = function(args) { + return Array.prototype.slice.call(args); + }; + + /** + * Serializes a object into a JSON string and optionally makes it pretty by indenting. + * + * @inner + * + * @param {Object} object The javascript object. + * @param {Boolean} pretty Whether the resulting string should have indentation. + * + * @returns {String} string + */ + Gitana.stringify = function(object, pretty) { + + let val = null; + + if (!Gitana.isEmpty(object)) + { + if (pretty) + { + val = JSON.stringify(object, null, " "); + } + else + { + val = JSON.stringify(object); + } + } + + return val; + }; + + /** + * Determines whether the given argument is a String. + * + * @inner + * + * @param arg argument + * + * @returns {Boolean} whether it is a String + */ + Gitana.isString = function( arg ) { + return (typeof arg === "string"); + }; + + /** + * Determines whether the given argument is a Number. + * + * @inner + * + * @param arg argument + * + * @returns {Boolean} whether it is a Number + */ + Gitana.isNumber = function( arg ) { + return (typeof arg === "number"); + }; + + /** + * Determines whether the given argument is a Boolean. + * + * @inner + * + * @param arg argument + * + * @returns {Boolean} whether it is a Boolean + */ + Gitana.isBoolean = function( arg ) { + return (typeof arg === "boolean"); + }; + + /** + * Determines whether the given argument is a Function. + * + * @inner + * + * @param arg argument + * + * @returns {Boolean} whether it is a Function + */ + Gitana.isFunction = function(arg) { + return Object.prototype.toString.call(arg) === "[object Function]"; + }; + + /** + * Determines whether the given argument is an Object. + * + * @param obj + * + * @returns {boolean} whether it is an Object + */ + Gitana.isObject = function(obj) { + return !Gitana.isUndefined(obj) && Object.prototype.toString.call(obj) === '[object Object]'; + }; + + /** + * Determines whether a bit of text starts with a given prefix. + * + * @inner + * + * @param {String} text A bit of text. + * @param {String} prefix The prefix. + * + * @returns {Boolean} whether the text starts with the prefix. + */ + Gitana.startsWith = function(text, prefix) { + return text.substr(0, prefix.length) === prefix; + }; + + /** + * Copies the members of the source object into the target object. + * This includes both properties and functions from the source object. + * + * @inner + * + * @param {Object} target Target object. + * @param {Object} source Source object. + */ + Gitana.copyInto = function(target, source) { + for (let i in source) { + if (source.hasOwnProperty(i) && !this.isFunction(source[i])) { + target[i] = source[i]; + } + } + }; + + /** + * Deletes any owned properties of the given object. If specified, owned functions will also be deleted. + * + * @inner + * + * @param object {Object} object + * @param deleteFunctions + */ + Gitana.deleteProperties = function(object, deleteFunctions) { + const keys = []; + for (let k in object) { keys.push(k); } + + for (let i = 0; i < keys.length; i++) + { + const key = keys[i]; + + if (object.hasOwnProperty(key)) { + if (!Gitana.isFunction(object[key]) || (deleteFunctions && Gitana.isFunction(object[key]))) { + delete object[key]; + } + } + } + }; + + + /** + * Stamps the functions and properties from the source object to the target object. + * + * @inner + * + * @param {Object} target Target object. + * @param {Object} source Source object. + */ + Gitana.stampInto = function(target, source) { + for (let i in source) + { + if (source.hasOwnProperty(i)) + { + target[i] = source[i]; + } + } + }; + + Gitana.contains = function(a, obj) + { + let i = a.length; + while (i--) + { + if (a[i] === obj) + { + return true; + } + } + return false; + }; + + Gitana.isArray = function(obj) + { + return obj.push && obj.slice; + }; + + Gitana.isUndefined = function(obj) + { + return (typeof obj === "undefined"); + }; + + Gitana.isEmpty = function(obj) + { + return this.isUndefined(obj) || obj === null; + }; + + Gitana.generateId = function() + { + Gitana.uniqueIdCounter++; + return "gitana-" + Gitana.uniqueIdCounter; + }; + + Gitana.isNode = function(o) + { + return ( + typeof Node === "object" ? o instanceof Node : + typeof o === "object" && typeof o.nodeType === "number" && typeof o.nodeName==="string"); + }; + + Gitana.isElement = function(o) + { + return ( + typeof HTMLElement === "object" ? o instanceof HTMLElement : //DOM2 + typeof o === "object" && o.nodeType === 1 && typeof o.nodeName==="string"); + }; + + Gitana.debug = function(str) + { + if (!this.isUndefined(console)) + { + console.log(str); + } + }; + + Gitana.error = function(str) + { + if (!this.isUndefined(console)) + { + console.error(str); + } + }; + + Gitana.getNumberOfKeys = function(map) + { + let count = 0; + for (let key in map) { + count++; + } + + return count; + }; + + /** + * Writes a cookie. + * + * @param {String} name + * @param {String} value + * @param {String} path optional path (assumed "/" if not provided) + * @param {Number} days optional # of days to store cookie + * if null or -1, assume session cookie + * if 0, assume expired cookie + * if > 0, assume # of days + * @param {String} domain optional domain (otherwise assumes wildcard base domain) + */ + Gitana.writeCookie = function(name, value, path, days, domain) + { + if (typeof(document) !== "undefined") + { + const createCookie = function(name, value, path, days, host) + { + // path + if (!path) + { + path = "/"; + } + const pathString = ";path=" + path; + + // expiration + let expirationString = ""; + if (typeof(days) === "undefined" || days === -1) + { + // session cookie + } + else if (days === 0) + { + // expired cookie + expirationString = ";expires=Thu, 01 Jan 1970 00:00:01 GMT"; + } + else if (days > 0) + { + const date = new Date(); + date.setTime(date.getTime()+(days*24*60*60*1000)); + expirationString = ";expires="+date.toGMTString(); + } + + // domain + let domainString = ""; + if (host) + { + domainString = ";domain=" + host; + } + + document.cookie = name + "=" + value + expirationString + pathString + domainString + ";"; + }; + + createCookie(name, value, path, days, domain); + } + }; + + /** + * Deletes a cookie. + * + * @param name + * @param path + */ + Gitana.deleteCookie = function(name, path) + { + const existsCookie = function(name) + { + return Gitana.readCookie(name); + }; + + if (typeof(document) != "undefined") + { + // first attempt, let the browser sort out the assumed domain + // this works for most modern browsers + if (existsCookie(name)) + { + // use expiration time of 0 to signal expired cookie + Gitana.writeCookie(name, "", path, 0); + } + + // second attempt, if necessary, plug in an assumed domain + // this is needed for phantomjs + if (existsCookie(name)) + { + // see if we can resolve a domain + if (window) + { + let domain = window.location.host; + if (domain) + { + // remove :port + const i = domain.indexOf(":"); + if (i > -1) + { + domain = domain.substring(0, i); + } + } + + // use expiration time of 0 to signal expired cookie + Gitana.writeCookie(name, "", path, 0, domain); + } + } + } + }; + + /** + * + * @param name + * @return {null} + */ + Gitana.readCookie = function(name) + { + function _readCookie(name) + { + const nameEQ = name + "="; + const ca = document.cookie.split(';'); + for (let i = 0; i < ca.length; i++) + { + let c = ca[i]; + while (c.charAt(0) ===' ') + { + c = c.substring(1,c.length); + } + + if (c.indexOf(nameEQ) === 0) + { + return c.substring(nameEQ.length,c.length); + } + } + return null; + } + + let value = null; + + if (typeof(document) !== "undefined") + { + value = _readCookie(name); + } + + return value; + }; + + + /** + * + * @param paramName + * @return {string|null} + */ + Gitana.getCurrentQueryStringParameter = function(paramName) + { + let searchString = window.location.search.substring(1), i, val, params = searchString.split("&"); + + for (i = 0; i < params.length; i++) + { + val = params[i].split("="); + + if (val[0] === paramName) + { + return unescape(val[1]); + } + } + + return null; + }; + + /** + * + * @param paramName + * @return {string|null} + */ + Gitana.getCurrentHashStringParameter = function(paramName) + { + const searchString = window.location.href.substring(window.location.href.indexOf("#") + 1); + const params = searchString.split("&"); + + for (i = 0; i < params.length; i++) + { + val = params[i].split("="); + + if (val[0] === paramName) + { + return unescape(val[1]); + } + } + + return null; + }; + + /** + * + * @param string + * @return {string|string} + */ + Gitana.btoa = function(string) + { + const b64 = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/='; + + let i = 0, length = string.length, ascii, index, output = ''; + + for (; i < length; i+=3) { + ascii = [ + string.charCodeAt(i), + string.charCodeAt(i+1), + string.charCodeAt(i+2) + ]; + + index = [ + ascii[0] >> 2, + ((ascii[0] & 3) << 4) | ascii[1] >> 4, + ((ascii[1] & 15) << 2) | ascii[2] >> 6, + ascii[2] & 63 + ]; + + if (isNaN(ascii[1])) { + index[2] = 64; + } + if (isNaN(ascii[2])) { + index[3] = 64; + } + + output += b64.charAt(index[0]) + b64.charAt(index[1]) + b64.charAt(index[2]) + b64.charAt(index[3]); + } + + return output; + }; + + /** + * Copies only those members that are already represented on the target. + * + * @inner + * + * @param {Object} target Target object. + * @param {Object} source Source object. + */ + Gitana.copyKeepers = function(target, source) { + + if (!source) { return; } + + for (let i in source) { + if (source.hasOwnProperty(i) && !this.isFunction(source[i])) { + if (!Gitana.isUndefined(target[i])) { + target[i] = source[i]; + } + } + } + }; + +})(window);(function(window) { + + Gitana = window.Gitana; + + const STATUS_UNRESOLVED = 'unresolved'; + const STATUS_RESOLVED = 'resolved'; + const STATUS_REJECTED = 'rejected'; + + const triggerAll = function(val, cbs) { + for (let i = 0; i < cbs.length; i++) { + const cb = cbs[i]; + trigger(val, cb); + } + }; + + const trigger = function(val, cb) { + setTimeout(cb.bind(null, val), 0); + }; + + const resolve = function(val) { + if (this.isUnresolved()) { + this.status = STATUS_RESOLVED; + this.val = val; + triggerAll(val, this.successCallbacks); + delete this.successCallbacks; + delete this.errorCallbacks; + } + }; + + const reject = function(err) { + if (this.isUnresolved()) { + this.status = STATUS_REJECTED; + this.val = err; + triggerAll(err, this.errorCallbacks); + delete this.successCallbacks; + delete this.errorCallbacks; + } + }; + + const Defer = function() { + this.promise = new Gitana.Promise(this); + + this.status = STATUS_UNRESOLVED; + + this.successCallbacks = []; + this.errorCallbacks = []; + + this.resolve = resolve.bind(this); + this.reject = reject.bind(this); + }; + + Defer.prototype.push = function(happy, sad) { + if (this.isUnresolved()) { + if (typeof happy === 'function') { this.successCallbacks.push(happy); } + if (typeof sad === 'function') { this.errorCallbacks.push(sad); } + } else if (this.isResolved()) { + trigger(this.val, happy); + } else if (this.isRejected()) { + trigger(this.val, sad); + } + }; + + Defer.prototype.isUnresolved = function() { + return this.status === STATUS_UNRESOLVED; + }; + + Defer.prototype.isResolved = function() { + return this.status === STATUS_RESOLVED; + }; + + Defer.prototype.isRejected = function() { + return this.status === STATUS_REJECTED; + }; + + Defer.all = function(args) { + if (args === undefined) { + return Gitana.Promise.resolved(); + } + if (!Gitana.isArray(args)) { args = arguments; } + const def = new Defer(); + let left = args.length; + const results = []; + for (let i = 0; i < args.length; i++) { + const promise = args[i]; + (function(cur) { + promise.then(function(res) { + left--; + results[cur] = res; + if (left <= 0) { + def.resolve(results); + } + }, def.reject); + })(i); + } + return def.promise; + }; + + Gitana.Defer = Defer; + +})(window); +(function(window) { + + Gitana = window.Gitana; + + const then = function(happy, sad) { + this.push(happy, sad); + }; + + const success = function(happy) { + then.call(this, happy); + }; + + const fail = function(sad) { + then.call(this, undefined, sad); + }; + + const complete = function(cb) { + then.call(this, cb, cb); + }; + + const Promise = function(defer) { + + this.then = then.bind(defer); + this.success = success.bind(defer); + this.fail = fail.bind(defer); + this.complete = complete.bind(defer); + + this.status = function() { + return defer.status; + }; + + }; + + Promise.resolved = function(val) { + const def = new Gitana.Defer(); + def.resolve(val); + return def.promise; + }; + + Gitana.Promise = Promise; + +})(window); +(function(window) { + + Gitana = window.Gitana; + + const DEFAULT_CONCURRENCY = 1; + + const chunk = function(array, size) { + const chunks = []; + for (let i = 0; i < array.length; i += size) { + chunks.push(array.slice(i, i + size)); + } + return chunks; + }; + + const Queue = function(concurrency) { + this.concurrency = concurrency || DEFAULT_CONCURRENCY; + this.work = []; + }; + + Queue.prototype.add = function(fn) { + this.work.push(fn); + }; + + Queue.prototype.go = function() { + const def = new Gitana.Defer(); + const chunks = chunk(this.work, this.concurrency); + const results = []; + (function loop(promise) { + promise.then(function(res) { + results.push.apply(results, res); + if (chunks.length > 0) { + const cbs = chunks.shift(); + const ps = []; + for (let i = cbs.length - 1; i >= 0; i--) { + const cb = cbs[i]; + const p = cb(); + ps.push(p); + } + loop(Gitana.Defer.all(ps)); + } else { + def.resolve(results); + } + }, def.reject); + })(Gitana.Promise.resolved([])); + return def.promise; + }; + + Gitana.Queue = Queue; + +})(window); +(function(window) +{ + Gitana.Methods = {}; + + /** + * Produces the common function to handle listAttachments() on constious attachables within Gitana. + * + * @param {Function} [mapClass] map implementation class (if none provided, uses Gitana.BinaryAttachmentMap) + * + * @return {Function} + */ + Gitana.Methods.listAttachments = function(mapClass) { + + if (!mapClass) { + mapClass = Gitana.BinaryAttachmentMap; + } + + return function(local) { + + const self = this; + + const result = this.subchain(new mapClass(this)); + if (!local) + { + // front-load some work that fetches from remote server + result.then(function() { + + const chain = this; + + self.getDriver().gitanaGet(self.getUri() + "/attachments", null, {}, function(response) { + chain.handleResponse(response); + chain.next(); + }); + + return false; + }); + } + else + { + // try to populate the map from our cached values on the node (if they exist) + const existingMap = self.getSystemMetadata()["attachments"]; + if (existingMap) + { + // attachments that come off of system() don't have "attachmentId" on their json object + // instead, the "attachmentId" is the key into the map. + + // so here, in terms of normalizing things, we copy "attachmentId" into the json object + for (const key in existingMap) + { + const value = result[key]; + value["attachmentId"] = key; + } + } + + //result.handleResponse(existingMap); + } + + return result; + }; + }; + + /** + * Produces the common function to handle attach() of attachments to an attachable within Gitana. + * + * @param [attachmentClass] attachment implementation class (if none provided, uses Gitana.BinaryAttachment) + * @param [paramsFunction] optional population function for url params + * + * @return {Function} + */ + Gitana.Methods.attach = function(attachmentClass, paramsFunction) { + + if (!attachmentClass) { + attachmentClass = Gitana.BinaryAttachment; + } + + return function(attachmentId, contentType, data) + { + const self = this; + + if (!attachmentId) + { + attachmentId = "default"; + } + + // the thing we're handing back + const result = this.subchain(new attachmentClass(this)); + + // preload some work onto a subchain + result.then(function() { + + // params + const params = {}; + if (paramsFunction) { + paramsFunction(params); + } + + // upload the attachment + let uploadUri = self.getUri() + "/attachments/" + attachmentId; + + // if data is a Node read stream, we use a helper function possibly to conduct the upload + if (data && data.read && typeof(data.read) === "function" && Gitana.streamUpload) + { + this.subchain(self).then(function() { + + const chain = this; + + uploadUri = self.getDriver().baseURL + uploadUri; + Gitana.streamUpload(self.getDriver(), data, uploadUri, contentType, function() { + + // read back attachment information and plug onto result + Chain(self).reload().then(function() { + this.listAttachments().then(function() { + this.select(attachmentId).then(function () { + result.handleResponse(this); + chain.next(); + }); + }); + }); + }); + + return false; + }); + } + else + { + this.chainUpload(this, uploadUri, params, contentType, data).then(function () { + + // read back attachment information and plug onto result + this.subchain(self).listAttachments().then(function () { + + // TODO: update attachment information on attachable.system() ? + + this.select(attachmentId).then(function () { + result.handleResponse(this); + }); + }); + }); + } + }); + + return result; + }; + }; + + /** + * Produces the common function to handle unattach() of attachments from an attachable within Gitana. + * + * @return {Function} + */ + Gitana.Methods.unattach = function() + { + return function(attachmentId) { + + return this.then(function() { + this.chainDelete(this, this.getUri() + "/attachments/" + attachmentId).then(function() { + // TODO + }); + }); + }; + }; + + Gitana.Methods.getPreviewUri = function(prefix) + { + if (!prefix) { + prefix = "preview"; + } + + return function(name, config) { + + let url = this.getDriver().baseURL + this.getUri() + "/" + prefix + "/" + name; + + if (config) + { + let first = true; + + for (const key in config) + { + if (first) + { + url += "?"; + } + else + { + url += "&"; + } + + const value = config[key]; + if (value) + { + url += key + "=" + value; + } + + first = false; + } + } + + return url; + }; + }; + +})(window);(function(window) +{ + // if we're running on the Cloud CMS hosted platform, we can auto-acquire the client key that we should use + (function() { + + // check to make sure location exists (only available in browsers) + if (typeof window.location != "undefined") + { + if (typeof(Gitana.autoConfigUri) === "undefined") + { + let uri = window.location.href; + let z1 = uri.indexOf(window.location.pathname); + z1 = uri.indexOf("/", z1 + 2); + if (z1 > -1) + { + uri = uri.substring(0, z1); + } + + if (uri.indexOf("cloudcms.net") > -1) + { + Gitana.autoConfigUri = uri; + } + } + } + + }()); + +})(window);(function(window) +{ + Gitana = window.Gitana; + + /** + * Object factory + * + * Produces object instances (nodes included) for given json. + */ + Gitana.ObjectFactory = Base.extend( + /** @lends Gitana.ObjectFactory.prototype */ + { + constructor: function() + { + this.create = function(klass, existing, object) + { + return new klass(existing, object); + }; + }, + + platformDataStoreMap: function(platform, object) + { + return this.create(Gitana.PlatformDataStoreMap, platform, object); + }, + + platformDataStore: function(platform, object) + { + const type = object.datastoreTypeId; + + return this[type](platform, object); + }, + + + + ////////////////////////////////////////////////////////////////////////////////////////////////////////// + // + // CLUSTER + // + ////////////////////////////////////////////////////////////////////////////////////////////////////////// + + platform: function(cluster, object) + { + return this.create(Gitana.Platform, cluster, object); + }, + + job: function(cluster, object) + { + let type = null; + + if (object) + { + if (Gitana.isString(object)) + { + type = object; + } + else + { + type = object["type"]; + } + } + + let job = null; + if ("copy" === type) + { + job = this.create(Gitana.CopyJob, cluster, object); + } + else if ("export" === type) + { + job = this.create(Gitana.TransferExportJob, cluster, object); + } + else if ("import" === type) + { + job = this.create(Gitana.TransferImportJob, cluster, object); + } + else + { + job = this.create(Gitana.Job, cluster, object); + } + + return job; + }, + + jobMap: function(cluster, object) + { + return this.create(Gitana.JobMap, cluster, object); + }, + + logEntry: function(cluster, object) + { + return this.create(Gitana.LogEntry, cluster, object); + }, + + logEntryMap: function(cluster, object) + { + return this.create(Gitana.LogEntryMap, cluster, object); + }, + + + + ////////////////////////////////////////////////////////////////////////////////////////////////////////// + // + // PLATFORM + // + ////////////////////////////////////////////////////////////////////////////////////////////////////////// + + stack: function(platform, object) + { + return this.create(Gitana.Stack, platform, object); + }, + + stackMap: function(platform, object) + { + return this.create(Gitana.StackMap, platform, object); + }, + + project: function(platform, object) + { + return this.create(Gitana.Project, platform, object); + }, + + projectMap: function(platform, object) + { + return this.create(Gitana.ProjectMap, platform, object); + }, + + uiConfig: function(platform, object) + { + return this.create(Gitana.UIConfig, platform, object); + }, + + uiConfigMap: function(platform, object) + { + return this.create(Gitana.UIConfigMap, platform, object); + }, + + scheduledWork: function(platform, object) + { + return this.create(Gitana.ScheduledWork, platform, object); + }, + + scheduledWorkMap: function(platform, object) + { + return this.create(Gitana.ScheduledWorkMap, platform, object); + }, + + report: function(platform, object) + { + return this.create(Gitana.Report, platform, object); + }, + + reportMap: function(platform, object) + { + return this.create(Gitana.ReportMap, platform, object); + }, + + repository: function(platform, object) + { + return this.create(Gitana.Repository, platform, object); + }, + + repositoryMap: function(platform, object) + { + return this.create(Gitana.RepositoryMap, platform, object); + }, + + domain: function(platform, object) + { + return this.create(Gitana.Domain, platform, object); + }, + + domainMap: function(platform, object) + { + return this.create(Gitana.DomainMap, platform, object); + }, + + vault: function(platform, object) + { + return this.create(Gitana.Vault, platform, object); + }, + + vaultMap: function(platform, object) + { + return this.create(Gitana.VaultMap, platform, object); + }, + + registrar: function(platform, object) + { + return this.create(Gitana.Registrar, platform, object); + }, + + registrarMap: function(platform, object) + { + return this.create(Gitana.RegistrarMap, platform, object); + }, + + directory: function(platform, object) + { + return this.create(Gitana.Directory, platform, object); + }, + + directoryMap: function(platform, object) + { + return this.create(Gitana.DirectoryMap, platform, object); + }, + + application: function(platform, object) + { + return this.create(Gitana.Application, platform, object); + }, + + applicationMap: function(platform, object) + { + return this.create(Gitana.ApplicationMap, platform, object); + }, + + webhost: function(platform, object) + { + return this.create(Gitana.WebHost, platform, object); + }, + + webhostMap: function(platform, object) + { + return this.create(Gitana.WebHostMap, platform, object); + }, + + autoClientMapping: function(webhost, object) + { + return this.create(Gitana.AutoClientMapping, webhost, object); + }, + + autoClientMappingMap: function(webhost, object) + { + return this.create(Gitana.AutoClientMappingMap, webhost, object); + }, + + trustedDomainMapping: function(webhost, object) + { + return this.create(Gitana.TrustedDomainMapping, webhost, object); + }, + + trustedDomainMappingMap: function(webhost, object) + { + return this.create(Gitana.TrustedDomainMappingMap, webhost, object); + }, + + deployedApplication: function(webhost, object) + { + return this.create(Gitana.DeployedApplication, webhost, object); + }, + + deployedApplicationMap: function(webhost, object) + { + return this.create(Gitana.DeployedApplicationMap, webhost, object); + }, + + descriptor: function(platform, object) + { + return this.create(Gitana.Descriptor, platform, object); + }, + + descriptorMap: function(platform, object) + { + return this.create(Gitana.DescriptorMap, platform, object); + }, + + client: function(platform, object) + { + const client = this.create(Gitana.Client, platform, object); + Gitana.stampInto(client, Gitana.ClientMethods); + + return client; + }, + + clientMap: function(platform, object) + { + return this.create(Gitana.ClientMap, platform, object); + }, + + accessPolicy: function(platform, object) + { + return this.create(Gitana.AccessPolicy, platform, object); + }, + + accessPolicyMap: function(platform, object) + { + return this.create(Gitana.AccessPolicyMap, platform, object); + }, + + authenticationGrant: function(platform, object) + { + return this.create(Gitana.AuthenticationGrant, platform, object); + }, + + authenticationGrantMap: function(platform, object) + { + return this.create(Gitana.AuthenticationGrantMap, platform, object); + }, + + billingProviderConfiguration: function(platform, object) + { + return this.create(Gitana.BillingProviderConfiguration, platform, object); + }, + + billingProviderConfigurationMap: function(platform, object) + { + return this.create(Gitana.BillingProviderConfigurationMap, platform, object); + }, + + workflowModel: function(platform, object) + { + return this.create(Gitana.WorkflowModel, platform, object); + }, + + workflowModelMap: function(platform, object) + { + return this.create(Gitana.WorkflowModelMap, platform, object); + }, + + workflowInstance: function(platform, object) + { + return this.create(Gitana.WorkflowInstance, platform, object); + }, + + workflowInstanceMap: function(platform, object) + { + return this.create(Gitana.WorkflowInstanceMap, platform, object); + }, + + workflowTask: function(platform, object) + { + return this.create(Gitana.WorkflowTask, platform, object); + }, + + workflowTaskMap: function(platform, object) + { + return this.create(Gitana.WorkflowTaskMap, platform, object); + }, + + workflowComment: function(platform, object) + { + return this.create(Gitana.WorkflowComment, platform, object); + }, + + workflowCommentMap: function(platform, object) + { + return this.create(Gitana.WorkflowCommentMap, platform, object); + }, + + deploymentReceiver: function(platform, object) + { + return this.create(Gitana.DeploymentReceiver, platform, object); + }, + + deploymentReceiverMap: function(platform, object) + { + return this.create(Gitana.DeploymentReceiverMap, platform, object); + }, + + deploymentPackage: function(platform, object) + { + return this.create(Gitana.DeploymentPackage, platform, object); + }, + + deploymentPackageMap: function(platform, object) + { + return this.create(Gitana.DeploymentPackageMap, platform, object); + }, + + deploymentStrategy: function(platform, object) + { + return this.create(Gitana.DeploymentStrategy, platform, object); + }, + + deploymentStrategyMap: function(platform, object) + { + return this.create(Gitana.DeploymentStrategyMap, platform, object); + }, + + deploymentTarget: function(platform, object) + { + return this.create(Gitana.DeploymentTarget, platform, object); + }, + + deploymentTargetMap: function(platform, object) + { + return this.create(Gitana.DeploymentTargetMap, platform, object); + }, + + + + + ////////////////////////////////////////////////////////////////////////////////////////////////////////// + // + // REPOSITORY + // + ////////////////////////////////////////////////////////////////////////////////////////////////////////// + + changeset: function(repository, object) + { + return this.create(Gitana.Changeset, repository, object); + }, + + branch: function(repository, object) + { + return this.create(Gitana.Branch, repository, object); + }, + + /** + * Creates a node + * + * @param branch + * @param object either object or the string type id + */ + node: function(branch, object) + { + let objectClass = null; + + if (object) + { + // allow for object to be the type id + if (Gitana.isString(object)) + { + object = { + "_type": object + }; + } + + // see if we can derive a more accurate type + const type = object["_type"]; + if (type) + { + if (Gitana.ObjectFactory.registry[type]) + { + objectClass = Gitana.ObjectFactory.registry[type]; + } + } + if (!objectClass) + { + // allow default trip through to association for association types + if (type && Gitana.startsWith(type, "a:")) + { + objectClass = Gitana.Association; + } + } + if (!objectClass) + { + // check out if it says its an association via special key + if (object.__is_association && object.__is_association()) + { + objectClass = Gitana.Association; + } + } + } + if (!objectClass) + { + // assume node + objectClass = Gitana.Node; + } + + // instantiate and set any properties + return this.create(objectClass, branch, object); + }, + + association: function(branch, object) + { + return this.create(Gitana.Association, branch, object); + }, + + release: function(repository, object) + { + return this.create(Gitana.Release, repository, object); + }, + + mergeConflict: function(repository, object) + { + return this.create(Gitana.MergeConflict, repository, object); + }, + + deletion: function(branch, object) + { + return this.create(Gitana.Deletion, branch, object); + }, + + branchMap: function(repository, object) + { + return this.create(Gitana.BranchMap, repository, object); + }, + + changesetMap: function(repository, object) + { + return this.create(Gitana.ChangesetMap, repository, object); + }, + + releaseMap: function(repository, object) + { + return this.create(Gitana.ReleaseMap, repository, object); + }, + + mergeConflictMap: function(repository, object) + { + return this.create(Gitana.MergeConflictMap, repository, object); + }, + + nodeMap: function(branch, object) + { + return this.create(Gitana.NodeMap, branch, object); + }, + + deletionMap: function(branch, object) + { + return this.create(Gitana.DeletionMap, branch, object); + }, + + definition: function(branch, object) + { + return this.create(Gitana.Definition, branch, object); + }, + + form: function(branch, object) + { + return this.create(Gitana.Form, branch, object); + }, + + traversalResults: function(branch, object) + { + return this.create(Gitana.TraversalResults, branch, object); + }, + + + + ////////////////////////////////////////////////////////////////////////////////////////////////////////// + // + // DOMAINS + // + ////////////////////////////////////////////////////////////////////////////////////////////////////////// + + domainPrincipal: function(domain, object) + { + // create the principal + const principal = this.create(Gitana.DomainPrincipal, domain, object); + + // extend the principal pre-emptively if we have an object + if (object) + { + this.extendPrincipal(principal); + } + + return principal; + }, + + domainPrincipalMap: function(domain, object) + { + return this.create(Gitana.PrincipalMap, domain, object); + }, + + extendPrincipal: function(principal) + { + if (principal.getType() && principal.objectType() === "Gitana.DomainPrincipal") + { + if (principal.getType() === "USER") + { + Gitana.stampInto(principal, Gitana.DomainUser); + } + else if (principal.getType() === "GROUP") + { + Gitana.stampInto(principal, Gitana.DomainGroup); + } + } + }, + + + + ////////////////////////////////////////////////////////////////////////////////////////////////////////// + // + // VAULTS + // + ////////////////////////////////////////////////////////////////////////////////////////////////////////// + + archive: function(vault, object) + { + return this.create(Gitana.Archive, vault, object); + }, + + archiveMap: function(vault, object) + { + return this.create(Gitana.ArchiveMap, vault, object); + }, + + + + ////////////////////////////////////////////////////////////////////////////////////////////////////////// + // + // MISCELLANEOUS + // + ////////////////////////////////////////////////////////////////////////////////////////////////////////// + + team: function(cluster, teamable, object) + { + return new Gitana.Team(cluster, teamable, object); + }, + + teamMap: function(cluster, teamable, object) + { + return new Gitana.TeamMap(cluster, teamable, object); + }, + + activity: function(datastore, object) + { + return new Gitana.Activity(datastore, object); + }, + + activityMap: function(datastore, object) + { + return new Gitana.ActivityMap(datastore, object); + }, + + role: function(cluster, roleContainer, object) + { + return new Gitana.Role(cluster, roleContainer, object); + }, + + roleMap: function(cluster, roleContainer, object) + { + return new Gitana.RoleMap(cluster, roleContainer, object); + }, + + resultMap: function(driver, resultMap) + { + return new Gitana.ResultMap(driver, resultMap); + }, + + + + ////////////////////////////////////////////////////////////////////////////////////////////////////////// + // + // REGISTRAR + // + ////////////////////////////////////////////////////////////////////////////////////////////////////////// + + tenant: function(registrar, object) + { + return this.create(Gitana.Tenant, registrar, object); + }, + + tenantMap: function(registrar, object) + { + return this.create(Gitana.TenantMap, registrar, object); + }, + + plan: function(registrar, object) + { + return this.create(Gitana.Plan, registrar, object); + }, + + planMap: function(registrar, object) + { + return this.create(Gitana.PlanMap, registrar, object); + }, + + meter: function(registrar, object) + { + return this.create(Gitana.Meter, registrar, object); + }, + + meterMap: function(registrar, object) + { + return this.create(Gitana.MeterMap, registrar, object); + }, + + ////////////////////////////////////////////////////////////////////////////////////////////////////////// + // + // DIRECTORY + // + ////////////////////////////////////////////////////////////////////////////////////////////////////////// + + identity: function(directory, object) + { + return this.create(Gitana.Identity, directory, object); + }, + + identityMap: function(directory, object) + { + return this.create(Gitana.IdentityMap, directory, object); + }, + + connection: function(directory, object) + { + return this.create(Gitana.Connection, directory, object); + }, + + connectionMap: function(directory, object) + { + return this.create(Gitana.ConnectionMap, directory, object); + }, + + ////////////////////////////////////////////////////////////////////////////////////////////////////////// + // + // APPLICATION + // + ////////////////////////////////////////////////////////////////////////////////////////////////////////// + + settings: function(application, object) + { + return this.create(Gitana.Settings, application, object); + }, + + settingsMap: function(application, object) + { + return this.create(Gitana.SettingsMap, application, object); + }, + + registration: function(application, object) + { + return this.create(Gitana.Registration, application, object); + }, + + registrationMap: function(application, object) + { + return this.create(Gitana.RegistrationMap, application, object); + }, + + pageRendition: function(application, object) + { + return this.create(Gitana.PageRendition, application, object); + }, + + pageRenditionMap: function(application, object) + { + return this.create(Gitana.PageRenditionMap, application, object); + }, + + email: function(application, object) + { + return this.create(Gitana.Email, application, object); + }, + + emailMap: function(application, object) + { + return this.create(Gitana.EmailMap, application, object); + }, + + emailProvider: function(application, object) + { + return this.create(Gitana.EmailProvider, application, object); + }, + + emailProviderMap: function(application, object) + { + return this.create(Gitana.EmailProviderMap, application, object); + }, + + message: function(application, object) + { + return this.create(Gitana.Message, application, object); + }, + + messageMap: function(application, object) + { + return this.create(Gitana.MessageMap, application, object); + } + + }); + + // static methods for registration + Gitana.ObjectFactory.registry = { }; + Gitana.ObjectFactory.register = function(qname, objectClass) + { + Gitana.ObjectFactory.registry[qname] = objectClass; + }; + +})(window); +(function(window) +{ + Gitana = window.Gitana; + + Gitana.AbstractPersistable = Gitana.Chainable.extend( + /** @lends Gitana.AbstractPersistable.prototype */ + { + /** + * @constructs + * @augments Gitana.Chainable + * + * @class Abstract base class for abstract objects and maps + * + * @param {Gitana} driver Gitana driver + * @param {Object} [object] + */ + constructor: function(driver, object) + { + this.base(driver); + + // auto-load response + if (object) + { + this.handleResponse.call(this, object); + } + }, + + /** + * @EXTENSION_POINT + * + * Convert the json response object into the things we want to preserve on the object. + * This should set the "object" property but may choose to set other properties as well. + * + * @param response + */ + handleResponse: function(response) + { + // remove our properties (not functions) + Gitana.deleteProperties(this, false); + + // special handling - if response contains "_ref", remove it + if (response["_ref"]) { + delete response["_ref"]; + } + + // copy properties + Gitana.copyInto(this, response); + + // handle any system properties + this.handleSystemProperties(response); + }, + + /** + * Gets called after the response is handled and allows the object to pull out special values from + * the "object" field so that they don't sit on the JSON object + */ + handleSystemProperties: function(response) + { + // utilize the chainCopyState method in case the response is a Gitana object + this.chainCopyState(response); + }, + + /** + * Hands back a cleanup, properties-only JSON simple object. + */ + json: function() + { + return JSON.parse(JSON.stringify(this)); + } + + }); + +})(window); +(function(window) +{ + Gitana = window.Gitana; + + Gitana.AbstractMap = Gitana.AbstractPersistable.extend( + /** @lends Gitana.AbstractMap.prototype */ + { + /** + * @constructs + * @augments Gitana.AbstractPersistable + * + * @class Abstract base class for a map of Gitana objects + * + * @param {Gitana} driver + * @param {Object} object + */ + constructor: function(driver, object) + { + ////////////////////////////////////////////////////////////////////////////////////////////// + // + // PRIVILEGED METHODS + // + ////////////////////////////////////////////////////////////////////////////////////////////// + + // auto-manage a list of keys + this.__keys = (function() { + const list = []; + return function(x) { + if (!Gitana.isUndefined(x)) { + if (x === 'empty') { + while (list.length > 0) { list.shift(); } + } else { + if (!x && x.length) { + for (let i = 0; i < x.length; i++) { + list.push(x[i]); + } + } + else + { + list.push(x); + } + } + } + return list; + }; + })(); + + this.__totalRows = (function() { + let _totalRows = null; + return function(totalRows) { + if (!Gitana.isUndefined(totalRows)) { _totalRows = totalRows; } + return _totalRows; + }; + })(); + + this.__size = (function() { + let _size = null; + return function(size) { + if (!Gitana.isUndefined(size)) { _size = size; } + return _size; + }; + })(); + + this.__offset = (function() { + let _offset = 0; + return function(offset) { + if (!Gitana.isUndefined(offset) && offset >= 0) { _offset = offset; } + return _offset; + }; + })(); + + this.base(driver, object); + + // in case the incoming object is a state-carrying object (like another map) + if (object) + { + this.chainCopyState(object); + } + }, + + refs: function() + { + const references = []; + + for (let i = 0; i < this.__keys().length; i++) + { + const key = this.__keys()[i]; + + const object = this[key]; + if (object.ref) + { + references.push(object.ref()); + } + } + + return references; + }, + + /** + * Override to include: + * + * __keys + * __totalRows + * __size + * __offset + * + * @param otherObject + */ + chainCopyState: function(otherObject) + { + this.base(otherObject); + + // include keys + if (otherObject.__keys) { + this.__keys('empty'); + for (let i = 0; i < otherObject.__keys().length; i++) + { + const k = otherObject.__keys()[i]; + this.__keys().push(k); + } + } + + if (otherObject.__totalRows) { + this.__totalRows(otherObject.__totalRows()); + } + if (otherObject.__size) { + this.__size(otherObject.__size()); + } + if (otherObject.__offset) { + this.__offset(otherObject.__offset()); + } + + }, + + clear: function() + { + // clear object properties (but not member functions) + Gitana.deleteProperties(this, false); + + // empty keys + this.__keys('empty'); + }, + + /** + * @override + * + * Convert the json response object into the things we want to preserve on the object. + * This should set the "object" property but may choose to set other properties as well. + * + * @param response + */ + handleResponse: function(response) + { + this.clear(); + + if (response) + { + // is it a gitana map? + if (response.totalRows && response.size && response.offset) { + this.__totalRows(response.totalRows()); + this.__size(response.size()); + this.__offset(response.offset()); + } + else + { + // otherwise assume it is a gitana result set + this.__totalRows(response["total_rows"]); + this.__size(response["size"]); + this.__offset(response["offset"]); + } + + if (response.rows) + { + // parse array + if (Gitana.isArray(response.rows)) + { + for (let i = 0; i < response.rows.length; i++) + { + const o = this.buildObject(response.rows[i]); + this[o.getId()] = o; + + this.__keys().push(o.getId()); + } + } + else + { + // parse object + for (let key in response.rows) + { + if (response.rows.hasOwnProperty(key) && !Gitana.isFunction(response.rows[key])) + { + const value = response.rows[key]; + + const o = this.buildObject(value); + + // determine key + let k = (o.getId && o.getId()); + if (!k) { + k = key; + } + this[k] = o; + + this.__keys().push(k); + } + } + } + this.__size(this.__keys().length); + } + else + { + // otherwise, assume it is key/value pairs + // it also might be another Gitana Map + + for (let key in response) + { + if (response.hasOwnProperty(key) && !Gitana.isFunction(response[key])) + { + const value = response[key]; + + const o = this.buildObject(value); + + // determine key + let k = (o.getId && o.getId()); + if (!k) { + k = key; + } + this[k] = o; + + this[k] = o; + + this.__keys().push(k); + } + } + this.__size(this.__keys().length); + } + } + }, + + /** + * @abstract + * + * @param json + */ + buildObject: function(json) + { + + }, + + get: function(key) + { + return this[key]; + }, + + asArray: function() + { + const array = []; + for (let i = 0; i < this.__keys().length; i++) + { + const k = this.__keys()[i]; + + array.push(this[k]); + } + + return array; + }, + + size: function(callback) + { + if (callback) + { + return this.then(function() { + callback.call(this, this.__size()); + }); + } + + return this.__size(); + }, + + offset: function(callback) + { + if (callback) + { + return this.then(function() { + callback.call(this, this.__offset()); + }); + } + + return this.__offset(); + }, + + totalRows: function(callback) + { + if (callback) + { + return this.then(function() { + callback.call(this, this.__totalRows()); + }); + } + + return this.__totalRows(); + }, + + + /** + * Iterates over the map and fires the callback function in SERIAL for each element in the map. + * The scope for the callback is the object from the map (i.e. repository object, node object). + * + * The arguments to the callback function are (key, value) where value is the same as "this". + * + * NOTE: This works against elements in the map in SERIAL. One at a time. If you are doing concurrent + * remote operations for members of the set such that each operation is independent, you may want to use + * the eachX() method. + * + * @chained this + * + * @param callback + */ + each: function(callback) + { + return this.then(function() { + + // run functions + for (let i = 0; i < this.__keys().length; i++) + { + // key and value from the map + const key = this.__keys()[i]; + const value = this[key]; + + // a function that fires our callback + // wrap in a closure so that we store the callback and key + // note: this = the value wrapped in a chain, so we don't pass in value + const f = function(callback, key, index, map) + { + return function() + { + callback.call(this, key, this, index); + + // manually copy resulting value back + Gitana.deleteProperties(map[key]); + Gitana.copyInto(map[key], this); + }; + + }(callback, key, i, this); + + // create subchain mounted on this chainable and the run function + this.subchain(value).then(f); + } + + return this; + }); + }, + + /** + * Iterates over the map and fires the callback function in PARALLEL for each element in the map. + * The scope for the callback is the object from the map (i.e. repository object, node object). + * + * The arguments to the callback function are (key, value) where value is the same as "this". + * + * NOTE: This works against elements in the map in PARALLEL. All map members are fired against at the same + * time on separate timeouts. There is no guaranteed order for their completion. If you require serial + * execution, use the each() method. + * + * @chained + * + * @param callback + */ + eachX: function(callback) + { + return this.then(function() { + + // create an array of functions that invokes the callback for each element in the array + const functions = []; + for (let i = 0; i < this.__keys().length; i++) + { + const key = this.__keys()[i]; + const value = this[key]; + + const f = function(callback, key, value, index) { + + return function() + { + // NOTE: we're running a parallel chain that is managed for us by the Chain then() method. + // we can't change the parallel chain but we can subchain from it + // in our subchain we run our method + // the parallel chain kind of acts like one-hop noop so that we can take over and do our thing + this.subchain(value).then(function() { + callback.call(this, key, this, index); + }); + }; + + }(callback, key, value, i); + + functions.push(f); + } + + // kick off all these functions in parallel + // adding them to the subchain + return this.then(functions); + }); + }, + + /** + * Iterates over the map and applies the callback filter function to each element. + * It should hand back true if it wants to keep the value and false to remove it. + * + * NOTE: the "this" for the callback is the object from the map. + * + * @chained + * + * @param callback + */ + filter: function(callback) + { + return this.then(function() { + + const keysToKeep = []; + const keysToRemove = []; + + for (let i = 0; i < this.__keys().length; i++) + { + const key = this.__keys()[i]; + const object = this[key]; + + const keepIt = callback.call(object); + if (keepIt) + { + keysToKeep.push(key); + } + else + { + keysToRemove.push(key); + } + } + + // remove any keys we don't want from the map + for (let i = 0; i < keysToRemove.length; i++) + { + delete this[keysToRemove[i]]; + } + + // swap keys to keep + // NOTE: we first clear the keys but we can't use slice(0,0) since that produces a NEW array + // instead, do this shift trick + this.__keys('empty'); + for (let i = 0; i < keysToKeep.length; i++) + { + this.__keys().push(keysToKeep[i]); + } + }); + }, + + /** + * Applies a comparator to sort the map. + * + * If no comparator is applied, the map will be sorted by its modification timestamp (if possible). + * + * The comparator can be a string that uses dot-notation to identify a field in the JSON that + * should be sorted. (example: "title" or "property1.property2.property3") + * + * Finally, the comparator can be a function. It takes (previousValue, currentValue) and hands back: + * -1 if the currentValue is less than the previousValue (should be sorted lower) + * 0 if they are equivalent + * 1 if they currentValue is greater than the previousValue (should be sorted higher) + * + * @chained + * + * @param comparator + */ + sort: function(comparator) + { + return this.then(function() { + + // build a temporary array of values + const array = []; + for (let i = 0; i < this.__keys().length; i++) { + const key = this.__keys()[i]; + array.push(this[key]); + } + + // sort the array + array.sort(comparator); + + // now reset keys according to the order of the array + this.__keys("empty"); + for (let i = 0; i < array.length; i++) + { + this.__keys().push(array[i].getId()); + } + + }); + }, + + /** + * Limits the number of elements in the map. + * + * @chained + * + * @param size + */ + limit: function(size) + { + return this.then(function() { + + const keysToRemove = []; + + if (size > this.__keys().length) + { + // keep everything + return; + } + + // figure out which keys to remove + for (let i = 0; i < this.__keys().length; i++) + { + if (i >= size) + { + keysToRemove.push(this.__keys()[i]); + } + } + + // truncate the keys + // NOTE: we can't use slice here since that produces a new array + while (this.__keys().length > size) + { + this.__keys().pop(); + } + + // remove any keys to remove from map + for (let i = 0; i < keysToRemove.length; i++) + { + delete this[keysToRemove[i]]; + } + + // reset the size + this.__size(this.__keys().length); + }); + }, + + /** + * Paginates elements in the map. + * + * @chained + * + * @param pagination + */ + paginate: function(pagination) + { + return this.then(function() { + + const skip = pagination.skip; + const limit = pagination.limit; + + const keysToRemove = []; + + // figure out which keys to remove + for (let i = 0; i < this.__keys().length; i++) + { + if (i < skip || i >= skip + limit) + { + keysToRemove.push(this.__keys()[i]); + } + } + + // truncate the keys + // NOTE: we can't use slice here since that produces a new array + while (this.__keys().length > limit + skip) + { + this.__keys().pop(); + } + + // remove any keys to remove from map + for (let i = 0; i < keysToRemove.length; i++) + { + delete this[keysToRemove[i]]; + } + + // reset the limit + this.__size(this.__keys().length); + }); + }, + + /** + * Counts the number of elements in the map and fires it into a callback function. + */ + count: function(callback) + { + if (callback) + { + return this.then(function() { + callback.call(this, this.__keys().length); + }); + } + + return this.__keys().length; + }, + + /** + * Keeps the first element in the map + */ + keepOne: function(emptyHandler) + { + const self = this; + + let json = {}; + if (this.__keys().length > 0) + { + json = this[this.__keys()[0]]; + } + + const chainable = this.buildObject(json); + + return this.subchain(chainable).then(function() { + + const chain = this; + + this.subchain(self).then(function() { + + if (this.__keys().length > 0) + { + const obj = this[this.__keys()[0]]; + + if (chain.loadFrom) + { + // for objects, like nodes or branches + chain.loadFrom(obj); + } + else + { + // non-objects? (i.e. binary or attachment maps) + chain.handleResponse(obj); + } + } + else + { + const err = new Gitana.Error(); + err.name = "Empty Map"; + err.message = "The map doesn't have any elements in it"; + + if (emptyHandler) + { + emptyHandler.call(self, err); + } + else + { + this.error(err); + } + + return false; + } + + }); + }); + }, + + /** + * Selects an individual element from the map and continues the chain. + * + * @param key + */ + select: function(key) + { + const self = this; + + let json = {}; + if (this[key]) + { + json = this[key]; + } + + // what we hand back + const result = this.subchain(this.buildObject(json)); + + // preload some work + return result.then(function() { + + const chain = this; + + this.subchain(self).then(function() { + + const obj = this[key]; + if (!obj) + { + const err = new Gitana.Error(); + err.name = "No element with key: " + key; + err.message = err.name; + + this.error(err); + + return false; + } + + if (result.loadFrom) + { + // for objects, like nodes or branches + chain.loadFrom(obj); + } + else + { + // non-objects? (i.e. binary or attachment maps) + chain.handleResponse(obj); + } + + }); + }); + } + + }); + +})(window); +(function(window) +{ + Gitana = window.Gitana; + + Gitana.AbstractObject = Gitana.AbstractPersistable.extend( + /** @lends Gitana.AbstractObject.prototype */ + { + /** + * @constructs + * @augments Gitana.AbstractPersistable + * + * @class Abstract base class for Gitana document objects. + * + * @param {Gitana} driver + * @param {Object} [object] + */ + constructor: function(driver, object) + { + this.__system = (function() { + const _system = new Gitana.SystemMetadata(); + return function(system) { + if (!Gitana.isUndefined(system)) { _system.updateFrom(system); } + return _system; + }; + })(); + + + + + /////////////////////////////////////////////////////////////////////////////////////////////// + // + // INSTANCE CHAINABLE METHODS + // + /////////////////////////////////////////////////////////////////////////////////////////////// + + /** + * Executes an HTTP delete for this object and continues the chain with the chainable. + * + * @param chainable + * @param uri + * @param params + */ + this.chainDelete = function(chainable, uri, params) + { + const self = this; + + return this.subchain(chainable).then(function() { + + const chain = this; + + // allow for closures on uri for late resolution + if (Gitana.isFunction(uri)) { + uri = uri.call(self); + } + + // delete + chain.getDriver().gitanaDelete(uri, params, function() { + chain.next(); + }, function(http) { + self.httpError(http); + }); + + // NOTE: we return false to tell the chain that we'll manually call next() + return false; + }); + }; + + /** + * Reloads this object from the server and then passes control to the chainable. + * + * @param chainable + * @param uri + * @param params + */ + this.chainReload = function(chainable, uri, params) + { + const self = this; + + return this.subchain(chainable).then(function() { + + const chain = this; + + // allow for closures on uri for late resolution + if (Gitana.isFunction(uri)) { + uri = uri.call(self); + } + + // reload + chain.getDriver().gitanaGet(uri, params, {}, function(obj) { + chain.handleResponse(obj); + chain.next(); + }, function(http) { + self.httpError(http); + }); + + // NOTE: we return false to tell the chain that we'll manually call next() + return false; + }); + }; + + /** + * Executes an update (write + read) of this object and then passes control to the chainable. + * + * @param chainable + * @param uri + * @param params + */ + this.chainUpdate = function(chainable, uri, params) + { + const self = this; + + return this.subchain(chainable).then(function() { + + const chain = this; + + // allow for closures on uri for late resolution + if (Gitana.isFunction(uri)) { + uri = uri.call(self); + } + + // delete + chain.getDriver().gitanaPut(uri, params, chain, function() { + chain.getDriver().gitanaGet(uri, params, {}, function(obj) { + chain.handleResponse(obj); + chain.next(); + }, function(http) { + self.httpError(http); + }); + }, function(http) { + self.httpError(http); + }); + + // NOTE: we return false to tell the chain that we'll manually call next() + return false; + }); + }; + + /** + * Performs a PATCH to the server and populates the chainable with results. + * Proceeds with the chain as bound to the chainable. + * + * @param chainable + * @param uri + * @param params + * @param payload + */ + this.chainPatch = function(chainable, uri, params, payload) + { + const self = this; + + return this.subchain(chainable).then(function() { + + const chain = this; + + // allow for closures on uri for late resolution + if (Gitana.isFunction(uri)) { + uri = uri.call(self); + } + + // create + driver.gitanaPatch(uri, params, payload, function(response) { + chain.handleResponse(response); + chain.next(); + }, function(http) { + self.httpError(http); + }); + + // NOTE: we return false to tell the chain that we'll manually call next() + return false; + }); + }; + + + // finally chain to parent prototype + this.base(driver, object); + }, + + /** + * Override to include: + * + * __system + * + * @param otherObject + */ + chainCopyState: function(otherObject) + { + this.base(otherObject); + + // include __system properties? + if (otherObject.__system) { + this.__system(otherObject.__system()); + } + }, + + /** + * @EXTENSION_POINT + */ + getUri: function() + { + return null; + }, + + /** + * @abstract + */ + getType: function() + { + return null; + }, + + /** + * @abstract + * + * @returns {String} a string denoting a reference to this object. + */ + ref: function() + { + return null; + }, + + /** + * Hands back the URI of this object as referenced by the browser. + */ + getProxiedUri: function() + { + return this.getDriver().baseURL + this.getUri(); + }, + + /** + * Get a json property + * + * @param key + */ + get: function(key) + { + return this[key]; + }, + + /** + * Set a json property + * + * @param key + * @param value + */ + set: function(key ,value) + { + this[key] = value; + }, + + /** + * Hands back the ID ("_doc") of this object. + * + * @public + * + * @returns {String} id + */ + getId: function() + { + return this.get("_doc"); + }, + + /** + * Hands back the system metadata for this object. + * + * @public + * + * @returns {Gitana.SystemMetadata} system metadata + */ + getSystemMetadata: function() + { + return this.__system(); + }, + + /** + * The title for the object. + * + * @public + * + * @returns {String} the title + */ + getTitle: function() + { + return this.get("title"); + }, + + /** + * The description for the object. + * + * @public + * + * @returns {String} the description + */ + getDescription: function() + { + return this.get("description"); + }, + + // TODO: this is a temporary workaround at the moment + // it has to do all kinds of special treatment for _ variables because these variables are + // actually system managed but they're on the top level object. + // + // TODO: + // 1) gitana repo system managed properties should all be under _system + // 2) the system block should be pulled off the object on read and not required on write + + /** + * Replaces all of the properties of this object with those of the given object. + * This method should be used to update the state of this object. + * + * Any functions from the incoming object will not be copied. + * + * @public + * + * @param object {Object} object containing the properties + */ + replacePropertiesWith: function(object) + { + // create a copy of the incoming object + const candidate = {}; + Gitana.copyInto(candidate, object); + + // we don't allow the following values to be replaced + const backups = {}; + backups["_doc"] = this["_doc"]; + delete candidate["_doc"]; + backups["_type"] = this["_type"]; + delete candidate["_type"]; + backups["_qname"] = this["_qname"]; + delete candidate["_qname"]; + + // remove our properties (not functions) + Gitana.deleteProperties(this, false); + + // restore + this["_doc"] = backups["_doc"]; + this["_type"] = backups["_type"]; + this["_qname"] = backups["_qname"]; + + // copy in candidate properties + Gitana.copyInto(this, candidate); + }, + + /** + * @override + */ + handleSystemProperties: function(response) + { + this.base(response); + + if (this["_system"]) + { + // strip out system metadata + const json = this["_system"]; + delete this["_system"]; + + // update system properties + this.__system().updateFrom(json); + } + }, + + /** + * Helper function to convert the object portion to JSON + * + * @param pretty + */ + stringify: function(pretty) + { + return Gitana.stringify(this, pretty); + }, + + /** + * Helper method that loads this object from another object of the same type. + * + * For example, loading a node from another loaded node. + * + * @param anotherObject + */ + loadFrom: function(anotherObject) + { + this.handleResponse(anotherObject); + } + + }); + +})(window); +(function(window) +{ + Gitana = window.Gitana; + + Gitana.AbstractSelfableObject = Gitana.AbstractObject.extend( + /** @lends Gitana.AbstractSelfableObject.prototype */ + { + /** + * @constructs + * @augments Gitana.AbstractObject + * + * @class Abstract base class for selfable Gitana document objects. + * + * @param {Gitana} driver + * @param {Object} [object] + */ + constructor: function(driver, object) + { + // finally chain to parent prototype + this.base(driver, object); + }, + + + + ////////////////////////////////////////////////////////////////////////////////////////////////// + // + // SELFABLE + // + ////////////////////////////////////////////////////////////////////////////////////////////////// + + /** + * Delete + * + * @chained this + * + * @public + */ + del: function() + { + const self = this; + + const uriFunction = function() + { + return self.getUri(); + }; + + // NOTE: pass control back to the server instance + return this.chainDelete(this.getPlatform(), uriFunction); + }, + + /** + * Reload + * + * @chained this + * + * @public + */ + reload: function() + { + const self = this; + + const uriFunction = function() + { + return self.getUri(); + }; + + return this.chainReload(null, uriFunction); + }, + + /** + * Update + * + * @chained this + * + * @public + */ + update: function() + { + const self = this; + + const uriFunction = function() + { + return self.getUri(); + }; + + return this.chainUpdate(null, uriFunction); + } + + }); + +})(window); +(function(window) +{ + Gitana = window.Gitana; + + Gitana.AbstractSelfableACLObject = Gitana.AbstractSelfableObject.extend( + /** @lends Gitana.AbstractSelfableACLObject.prototype */ + { + /** + * @constructs + * @augments Gitana.AbstractSelfableObject + * + * @class Abstract base class for selfable ACL Gitana document objects. + * + * @param {Gitana} driver + * @param {Object} [object] + */ + constructor: function(driver, object) + { + // finally chain to parent prototype + this.base(driver, object); + }, + + + + ////////////////////////////////////////////////////////////////////////////////////////// + // + // ACL METHODS + // + ////////////////////////////////////////////////////////////////////////////////////////// + + /** + * Retrieve full ACL and pass into chaining method. + * + * @chained this + * + * @param callback + */ + loadACL: function(callback) + { + const self = this; + + const uriFunction = function() + { + return self.getUri() + "/acl/list"; + }; + + return this.chainGetResponse(this, uriFunction).then(function(response) { + callback.call(this, response); + }); + }, + + /** + * Retrieve list of authorities and pass into chaining method. + * + * @chained this + * + * @param {Gitana.DomainPrincipal|String} principal the principal or the principal id + * @param callback + */ + listAuthorities: function(principal, callback) + { + const principalDomainQualifiedId = this.extractPrincipalDomainQualifiedId(principal); + + const self = this; + + const uriFunction = function() + { + return self.getUri() + "/acl?id=" + principalDomainQualifiedId; + }; + + return this.chainGetResponseRows(this, uriFunction).then(function(response) { + callback.call(this, response); + }); + }, + + /** + * Checks whether the given principal has a granted authority for this object. + * This passes the result (true/false) to the chaining function. + * + * @chained this + * + * @param {Gitana.DomainPrincipal|String} principal the principal or the principal id + * @param {String} authorityId the id of the authority + * @param callback + */ + checkAuthority: function(principal, authorityId, callback) + { + const principalDomainQualifiedId = this.extractPrincipalDomainQualifiedId(principal); + + const self = this; + + const uriFunction = function() + { + return self.getUri() + "/authorities/" + authorityId + "/check?id=" + principalDomainQualifiedId; + }; + + return this.chainPostResponse(this, uriFunction).then(function(response) { + callback.call(this, response["check"]); + }); + }, + + /** + * Grants an authority to a principal against this object. + * + * @chained this + * + * @param {Gitana.DomainPrincipal|String} principal the principal or the principal id + * @param {String} authorityId the id of the authority + */ + grantAuthority: function(principal, authorityId) + { + const principalDomainQualifiedId = this.extractPrincipalDomainQualifiedId(principal); + + const self = this; + + const uriFunction = function() + { + return self.getUri() + "/authorities/" + authorityId + "/grant?id=" + principalDomainQualifiedId; + }; + + return this.chainPostEmpty(null, uriFunction); + }, + + /** + * Revokes an authority from a principal against this object. + * + * @chained this + * + * @param {Gitana.DomainPrincipal|String} principal the principal or the principal id + * @param {String} authorityId the id of the authority + */ + revokeAuthority: function(principal, authorityId) + { + const principalDomainQualifiedId = this.extractPrincipalDomainQualifiedId(principal); + + const self = this; + + const uriFunction = function() + { + return self.getUri() + "/authorities/" + authorityId + "/revoke?id=" + principalDomainQualifiedId; + }; + + return this.chainPostEmpty(null, uriFunction); + }, + + /** + * Revokes all authorities for a principal against the server. + * + * @chained this + * + * @param {Gitana.Principal|String} principal the principal or the principal id + */ + revokeAllAuthorities: function(principal) + { + return this.revokeAuthority(principal, "all"); + }, + + /** + * Loads the authority grants for a given set of principals. + * + * @chained this + * + * @param principalIds + * @param callback + */ + loadAuthorityGrants: function(principalIds, callback) + { + if (!principalIds) + { + principalIds = []; + } + + const json = { + "principals": principalIds + }; + + return this.chainPostResponse(this, this.getUri() + "/authorities", {}, json).then(function(response) { + callback.call(this, response); + }); + }, + + /** + * Checks whether the given principal has a permission against this object. + * This passes the result (true/false) to the chaining function. + * + * @chained this + * + * @param {Gitana.DomainPrincipal|String} principal the principal or the principal id + * @param {String} permissionId the id of the permission + * @param callback + */ + checkPermission: function(principal, permissionId, callback) + { + const principalDomainQualifiedId = this.extractPrincipalDomainQualifiedId(principal); + + const uriFunction = function() + { + return self.getUri() + "/permissions/" + permissionId + "/check?id=" + principalDomainQualifiedId; + }; + + return this.chainPostResponse(this, uriFunction).then(function(response) { + callback.call(this, response["check"]); + }); + } + + + ////////////////////////////////////////////////////////////////////////////////////////// + // + // END OF ACL METHODS + // + ////////////////////////////////////////////////////////////////////////////////////////// + + + }); + +})(window); +(function(window) +{ + Gitana = window.Gitana; + + Gitana.DataStore = Gitana.AbstractObject.extend( + /** @lends Gitana.DataStore.prototype */ + { + /** + * @constructs + * @augments Gitana.AbstractObject + * + * @class DataStore + * + * @param {Gitana} driver + * @param {Object} object json object (if no callback required for populating) + */ + constructor: function(driver, object) + { + this.base(driver, object); + }, + + /** + * @abstract + */ + getUri: function() + { + return null; + }, + + /** + * @abstract + */ + getType: function() + { + return null; + }, + + /** + * @abstract + * + * @returns {String} a string denoting a reference to this datastore + */ + ref: function() + { + return this.getType() + "://" + this.getId(); + }, + + ////////////////////////////////////////////////////////////////////////////////////////// + // + // ACL METHODS + // + ////////////////////////////////////////////////////////////////////////////////////////// + + /** + * Retrieve full ACL and pass into chaining method. + * + * @chained this + * + * @param callback + */ + loadACL: function(callback) + { + const uriFunction = function() + { + return this.getUri() + "/acl/list"; + }; + + return this.chainGetResponse(this, uriFunction).then(function(response) { + callback.call(this, response); + }); + }, + + /** + * Retrieve list of authorities and pass into chaining method. + * + * @chained this + * + * @param {Gitana.Principal|String} principal the principal or the principal id + * @param callback + */ + listAuthorities: function(principal, callback) + { + const principalDomainQualifiedId = this.extractPrincipalDomainQualifiedId(principal); + + const uriFunction = function() + { + return this.getUri() + "/acl?id=" + principalDomainQualifiedId; + }; + + return this.chainGetResponseRows(this, uriFunction).then(function(response) { + callback.call(this, response); + }); + }, + + /** + * Checks whether the given principal has a granted authority for this object. + * This passes the result (true/false) to the chaining function. + * + * @chained this + * + * @param {Gitana.Principal|String} principal the principal or the principal id + * @param {String} authorityId the id of the authority + * @param callback + */ + checkAuthority: function(principal, authorityId, callback) + { + const principalDomainQualifiedId = this.extractPrincipalDomainQualifiedId(principal); + + const uriFunction = function() + { + return this.getUri() + "/authorities/" + authorityId + "/check?id=" + principalDomainQualifiedId; + }; + + return this.chainPostResponse(this, uriFunction).then(function(response) { + callback.call(this, response["check"]); + }); + }, + + /** + * Grants an authority to a principal against this object. + * + * @chained this + * + * @param {Gitana.Principal|String} principal the principal or the principal id + * @param {String} authorityId the id of the authority + */ + grantAuthority: function(principal, authorityId) + { + const principalDomainQualifiedId = this.extractPrincipalDomainQualifiedId(principal); + + const uriFunction = function() + { + return this.getUri() + "/authorities/" + authorityId + "/grant?id=" + principalDomainQualifiedId; + }; + + return this.chainPostEmpty(null, uriFunction); + }, + + /** + * Revokes an authority from a principal against this object. + * + * @chained this + * + * @param {Gitana.Principal|String} principal the principal or the principal id + * @param {String} authorityId the id of the authority + */ + revokeAuthority: function(principal, authorityId) + { + const principalDomainQualifiedId = this.extractPrincipalDomainQualifiedId(principal); + + const uriFunction = function() + { + return this.getUri() + "/authorities/" + authorityId + "/revoke?id=" + principalDomainQualifiedId; + }; + + return this.chainPostEmpty(null, uriFunction); + }, + + /** + * Revokes all authorities for a principal against the server. + * + * @chained server + * + * @param {Gitana.Principal|String} principal the principal or the principal id + */ + revokeAllAuthorities: function(principal) + { + return this.revokeAuthority(principal, "all"); + }, + + /** + * Loads the authority grants for a given set of principals. + * + * @chained repository + * + * @param principalIds + * @param callback + */ + loadAuthorityGrants: function(principalIds, callback) + { + if (!principalIds) + { + principalIds = []; + } + + const json = { + "principals": principalIds + }; + + return this.chainPostResponse(this, this.getUri() + "/authorities", {}, json).then(function(response) { + callback.call(this, response); + }); + }, + + /** + * Checks whether the given principal has a permission against this object. + * This passes the result (true/false) to the chaining function. + * + * @chained this + * + * @param {Gitana.Principal|String} principal the principal or the principal id + * @param {String} permissionId the id of the permission + * @param callback + */ + checkPermission: function(principal, permissionId, callback) + { + const principalDomainQualifiedId = this.extractPrincipalDomainQualifiedId(principal); + + const uriFunction = function() + { + return this.getUri() + "/permissions/" + permissionId + "/check?id=" + principalDomainQualifiedId; + }; + + return this.chainPostResponse(this, uriFunction).then(function(response) { + callback.call(this, response["check"]); + }); + }, + + + ////////////////////////////////////////////////////////////////////////////////////////// + // + // END OF ACL METHODS + // + ////////////////////////////////////////////////////////////////////////////////////////// + + + + ////////////////////////////////////////////////////////////////////////////////////////// + // + // TEAMABLE + // + ////////////////////////////////////////////////////////////////////////////////////////// + + /** + * Reads a team. + * + * @param teamKey + * + * @chainable team + */ + readTeam: function(teamKey) + { + const uriFunction = function() + { + return this.getUri() + "/teams/" + teamKey; + }; + + const chainable = this.getFactory().team(this.getPlatform(), this); + return this.chainGet(chainable, uriFunction); + }, + + /** + * Lists teams. + * + * @chainable map of teams + */ + listTeams: function() + { + const uriFunction = function() + { + return this.getUri() + "/teams"; + }; + + const chainable = this.getFactory().teamMap(this.getCluster(), this); + return this.chainGet(chainable, uriFunction); + }, + + /** + * Creates a team. + * + * @param teamKey + * @param object + * + * @chainable team + */ + createTeam: function(teamKey, object) + { + if (!object) + { + object = {}; + } + + const uriFunction = function() + { + return this.getUri() + "/teams?key=" + teamKey; + }; + + const self = this; + + const chainable = this.getFactory().team(this.getPlatform(), this); + return this.chainPostResponse(chainable, uriFunction, {}, object).then(function() { + + const chain = this; + + Chain(self).readTeam(teamKey).then(function() { + chain.handleResponse(this); + chain.next(); + }); + + // we manually advance the chain + return false; + }); + }, + + /** + * Gets the owners team + * + * @chained team + */ + readOwnersTeam: function() + { + return this.readTeam("owners"); + }, + + ////////////////////////////////////////////////////////////////////////////////////////// + // + // END OF TEAMABLE + // + ////////////////////////////////////////////////////////////////////////////////////////// + + + + + ////////////////////////////////////////////////////////////////////////////////////////// + // + // ACTIVITIES + // + ////////////////////////////////////////////////////////////////////////////////////////// + + /** + * Lists activities. + * + * @chained activity map + * + * @param {Object} pagination pagination (optional) + */ + listActivities: function(pagination) + { + // prepare params (with pagination) + const params = {}; + if (pagination) + { + Gitana.copyInto(params, pagination); + } + + const chainable = this.getFactory().activityMap(this); + return this.chainGet(chainable, "/activities", params); + }, + + /** + * Read an activity. + * + * @chained activity + * + * @param {String} activityId the activity id + */ + readActivity: function(activityId) + { + const chainable = this.getFactory().activity(this); + return this.chainGet(chainable, "/activities/" + activityId); + }, + + /** + * Queries for activities. + * + * @chained activity map + * + * @param {Object} query query. + * @param {Object} pagination pagination (optional) + */ + queryActivities: function(query, pagination) + { + const chainable = this.getFactory().activityMap(this); + + // prepare params (with pagination) + const params = {}; + if (pagination) + { + Gitana.copyInto(params, pagination); + } + + return this.chainPost(chainable, "/activities/query", params, query); + }, + + + + + ////////////////////////////////////////////////////////////////////////////////////////// + // + // ROLE CONTAINER + // + ////////////////////////////////////////////////////////////////////////////////////////// + + /** + * Reads a role. + * + * @param roleKeyOrId + * @param inherited whether to check inherited role containers + * + * @chainable role + */ + readRole: function(roleKeyOrId, inherited) + { + const params = {}; + + if (inherited) + { + params.inherited = true; + } + + const uriFunction = function() + { + return this.getUri() + "/roles/" + roleKeyOrId; + }; + + const chainable = this.getFactory().role(this.getCluster(), this); + return this.chainGet(chainable, uriFunction, params); + }, + + /** + * Lists roles. + * + * @param inherited whether to draw from inherited role containers + * + * @chainable map of teams + */ + listRoles: function(inherited) + { + const params = {}; + + if (inherited) + { + params.inherited = true; + } + + const uriFunction = function() + { + return this.getUri() + "/roles"; + }; + + const chainable = this.getFactory().roleMap(this.getCluster(), this); + return this.chainGet(chainable, uriFunction, params); + }, + + /** + * Creates a role. + * + * @param roleKey + * @param object + * + * @chainable team + */ + createRole: function(roleKey, object) + { + if (!object) + { + object = {}; + } + object.roleKey = roleKey; + + const uriFunction = function() + { + return this.getUri() + "/roles"; + }; + + const self = this; + + const chainable = this.getFactory().role(this.getPlatform(), this, roleKey); + return this.chainPostResponse(chainable, uriFunction, {}, object).then(function() { + this.subchain(self).readRole(roleKey).then(function() { + Gitana.copyInto(chainable, this); + }); + }); + }, + + ////////////////////////////////////////////////////////////////////////////////////////// + // + // END OF ROLE CONTAINER + // + ////////////////////////////////////////////////////////////////////////////////////////// + + + + + + ////////////////////////////////////////////////////////////////////////////////////////// + // + // COMMON DATA STORE THINGS + // + ////////////////////////////////////////////////////////////////////////////////////////// + + getMaxSize: function() + { + return this.get("maxSize"); + }, + + getSize: function() + { + return this.get("size"); + }, + + getObjectCount: function() + { + return this.get("objectcount"); + } + + }); + +})(window); +(function(window) +{ + Gitana = window.Gitana; + + Gitana.ContainedDataStore = Gitana.DataStore.extend( + /** @lends Gitana.ContainedDataStore.prototype */ + { + /** + * @constructs + * @augments Gitana.DataStore + * + * @class ContainedDataStore + * + * @param {Gitana.DataStore} container + * @param {Object} object json object (if no callback required for populating) + */ + constructor: function(container, object) + { + this.base(container.getDriver(), object); + + + ////////////////////////////////////////////////////////////////////////////////////////////// + // + // PRIVILEGED METHODS + // + ////////////////////////////////////////////////////////////////////////////////////////////// + + this.getContainer = function() + { + return container; + }; + + this.getContainerId = function() + { + return container.getId(); + }; + + }, + + /** + * Delete + * + * @chained container datastore + * + * @public + */ + del: function() + { + const uriFunction = function() + { + return this.getUri(); + }; + + // NOTE: pass control back to the container datastore instance + return this.chainDelete(this.getContainer(), uriFunction); + }, + + /** + * Reload + * + * @chained this + * + * @public + */ + reload: function() + { + const uriFunction = function() + { + return this.getUri(); + }; + + return this.chainReload(null, uriFunction); + }, + + /** + * Update + * + * @chained this + * + * @public + */ + update: function() + { + const uriFunction = function() + { + return this.getUri(); + }; + + return this.chainUpdate(null, uriFunction); + }, + + + ////////////////////////////////////////////////////////////////////////////////////////// + // + // TRANSFER + // + ////////////////////////////////////////////////////////////////////////////////////////// + + /** + * Exports an archive. + * + * @chained job + * + * @param {Object} settings + */ + exportArchive: function(settings) + { + const self = this; + + let vaultId = settings.vault; + if (!Gitana.isString(vaultId)) + { + vaultId = vaultId.getId(); + } + const groupId = settings.group; + const artifactId = settings.artifact; + const versionId = settings.version; + const configuration = (settings.configuration ? settings.configuration : {}); + const synchronous = !settings.async; + + // archive additional properties + const title = settings.title; + const description = settings.description; + const published = settings.published; + + // we continue the chain with a job + const chainable = this.getFactory().job(this.getCluster(), "export"); + + // fire off import and job queue checking + return this.subchain(chainable).then(function() { + + const chain = this; + + // create + const params = {}; + params["vault"] = vaultId; + params["group"] = groupId; + params["artifact"] = artifactId; + params["version"] = versionId; + params["schedule"] = "ASYNCHRONOUS"; + if (title) { + params["title"] = title; + } + if (description) { + params["description"] = description; + } + if (published) { + params["published"] = published; + } + this.getDriver().gitanaPost(self.getUri() + "/export", params, configuration, function(response) { + Gitana.handleJobCompletion(chain, self.getCluster(), response.getId(), synchronous); + }, function(http) { + self.httpError(http); + }); + + // NOTE: we return false to tell the chain that we'll manually call next() + return false; + }); + }, + + /** + * Imports an archive. + * + * @chained job + * + * @param {Object} settings + * @param {Function} reportFn function + */ + importArchive: function(settings, reportFn) + { + const self = this; + + let vaultId = settings.vault; + if (!Gitana.isString(vaultId)) + { + vaultId = vaultId.getId(); + } + const groupId = settings.group; + const artifactId = settings.artifact; + const versionId = settings.version; + const configuration = (settings.configuration ? settings.configuration : {}); + const synchronous = !settings.async; + + // we continue the chain with a job + const chainable = this.getFactory().job(this.getCluster(), "import"); + + // fire off import and job queue checking + return this.subchain(chainable).then(function() { + + const chain = this; + + // create + this.getDriver().gitanaPost(self.getUri() + "/import?vault=" + vaultId + "&group=" + groupId + "&artifact=" + artifactId + "&version=" + versionId + "&schedule=ASYNCHRONOUS", {}, configuration, function(response) { + + Gitana.handleJobCompletion(chain, self.getCluster(), response.getId(), synchronous, reportFn); + + }, function(http) { + self.httpError(http); + }); + + // NOTE: we return false to tell the chain that we'll manually call next() + return false; + }); + + } + + }); + +})(window); +(function(window) +{ + Gitana = window.Gitana; + + Gitana.BinaryAttachment = Gitana.AbstractPersistable.extend( + /** @lends Gitana.BinaryAttachment.prototype */ + { + /** + * @constructs + * @augments Gitana.AbstractPersistable + * + * @class Binary Attachment + * + * @param {Object} persistable gitana object + * @param {Object} attachment + */ + constructor: function(persistable, attachment) + { + this.base(persistable.getDriver(), attachment); + + this.objectType = function() { return "Gitana.BinaryAttachment"; }; + + this.persistable = function() { + return persistable; + }; + }, + + getId: function() + { + return this.attachmentId; + }, + + getLength: function() + { + return this.length; + }, + + getContentType: function() + { + return this.contentType; + }, + + getFilename: function() + { + return this.filename; + }, + + getUri: function() + { + return this.persistable().getUri() + "/attachments/" + this.getId(); + }, + + getDownloadUri: function() + { + return this.getDriver().baseURL + this.getUri(); + }, + + getPreviewUri: function(name, config) + { + if (!config) + { + config = {}; + } + + config.attachment = this.attachmentId; + + return this.persistable().getPreviewUri(name, config); + }, + + /** + * Deletes the attachment, hands back control to the persistable. + * + * @chained persistable + */ + del: function() + { + const self = this; + + const result = this.subchain(this.persistable()); + + // our work (first in chain) + result.subchain(self).then(function() { + + const chain = this; + + // delete the attachment + this.getDriver().gitanaDelete(this.getUri(), null, function() { + + chain.next(); + + }, function(http) { + self.httpError(http); + }); + + return false; + }); + + return result; + }, + + /** + * Downloads the attachment. + * + * @chained attachment + * @param callback + */ + download: function(callback) + { + const self = this; + + return this.then(function() { + + const chain = this; + + // download + this.getDriver().gitanaDownload(this.getUri(), null, function(data) { + callback.call(self, data); + chain.next(); + }, function(http) { + self.httpError(http); + }); + + return false; + }); + }, + + stream: function(callback) + { + if (!Gitana.streamDownload) { + throw new Error("XHR streaming not supported - this method will only work when running in Node.js"); + } + + Gitana.streamDownload(this, function(err, stream) { + callback(err, stream); + }); + } + + }); + +})(window); +(function(window) +{ + Gitana = window.Gitana; + + Gitana.BinaryAttachmentMap = Gitana.AbstractMap.extend( + /** @lends Gitana.BinaryAttachmentMap.prototype */ + { + constructor: function(persistable, object) + { + this.objectType = function() { return "Gitana.BinaryAttachmentMap"; }; + + this.__persistable = (function() { + let _persistable = persistable; + return function(p) { + if (!Gitana.isUndefined(p)) { _persistable = p; } + return _persistable; + }; + })(); + + if (!object) + { + object = this.__persistable().getSystemMetadata()["attachments"]; + } + + // must come at end because loading of object requires persistable() method + this.base(this.__persistable().getDriver(), object); + }, + + /** + * Override to include: + * + * __persistable + * + * @param otherObject + */ + chainCopyState: function(otherObject) + { + this.base(otherObject); + + if (otherObject.__persistable) { + this.__persistable(otherObject.__persistable()); + } + }, + + /** + * @override + */ + clone: function() + { + return new Gitana.BinaryAttachmentMap(this.__persistable(), this); + }, + + /** + * @param attachment + */ + buildObject: function(attachment) + { + return new Gitana.BinaryAttachment(this.__persistable(), attachment); + } + + }); + +})(window); +(function(window) +{ + Gitana = window.Gitana; + + Gitana.Team = Gitana.AbstractObject.extend( + /** @lends Gitana.Team.prototype */ + { + /** + * @constructs + * @augments Gitana.AbstractObject + * + * @class Team + * + * @param {Gitana.Cluster} cluster + * @param {Object} teamable + * @param {Object} object json object (if no callback required for populating) + */ + constructor: function(cluster, teamable, object) + { + this.__teamable = (function() { + let _teamable = null; + return function(teamable) { + if (!Gitana.isUndefined(teamable)) { _teamable = teamable; } + return _teamable; + }; + })(); + + this.__teamable(teamable); + + this.objectType = function() { return "Gitana.Team"; }; + + this.getCluster = function() + { + return cluster; + }; + + this.base(cluster.getDriver(), object); + }, + + /** + * @override + */ + clone: function() + { + return this.getFactory().team(this.getCluster(), this.__teamable(), this); + }, + + getUri: function() + { + return this.__teamable().getUri() + "/teams/" + this.getKey(); + }, + + getType: function() + { + return "team"; + }, + + /** + * Delete + * + * @chained team + * + * @public + */ + del: function() + { + const uriFunction = function() + { + return this.getUri(); + }; + + // NOTE: pass control back to the teamable + return this.chainDelete(this.__teamable(), uriFunction); + }, + + /** + * Reload + * + * @chained team + * + * @public + */ + reload: function() + { + const uriFunction = function() + { + return this.getUri(); + }; + + return this.chainReload(null, uriFunction); + }, + + /** + * Update + * + * @chained team + * + * @public + */ + update: function() + { + const uriFunction = function() + { + return this.getUri(); + }; + + return this.chainUpdate(null, uriFunction); + }, + + /** + * Adds a member to the team. + * + * @param {String|Object} principal either the principal object or the principal id + * + * @chained team + */ + addMember: function(principal) + { + const self = this; + + const uriFunction = function() + { + const principalDomainQualifiedId = self.extractPrincipalDomainQualifiedId(principal); + + return this.getUri() + "/members/add?id=" + principalDomainQualifiedId; + }; + + return this.chainPostEmpty(null, uriFunction); + }, + + /** + * Removes a member from the team. + * + * @param {String|Object} principal - either the principal object or the principal id + * + * @chained team + */ + removeMember: function(principal) + { + const principalDomainQualifiedId = this.extractPrincipalDomainQualifiedId(principal); + + const uriFunction = function() + { + return this.getUri() + "/members/remove?id=" + principalDomainQualifiedId; + }; + + return this.chainPostEmpty(null, uriFunction); + }, + + /** + * Checks whether a principal is a member of the team. + * + * @param {String|Object} principal -either the principal object or the principal id + * @param callback function(check) + * + * @chained team + */ + hasMember: function(principal, callback) + { + const self = this; + + const uriFunction = function() + { + return this.getUri() + "/members/check"; + }; + + const params = {}; + params.id = self.extractPrincipalDomainQualifiedId(principal); + + return this.chainPostResponse(null, uriFunction, params).then(function(response) { + callback(response.belongs); + }); + }, + + + /** + * Lists members of a team + * + * @param pagination + * + * @chained principal map + */ + listMembers: function(pagination) + { + const params = {}; + if (pagination) + { + Gitana.copyInto(params, pagination); + } + + const uriFunction = function() + { + return this.getUri() + "/members"; + }; + + const chainable = new Gitana.TeamMemberMap(this); + return this.chainGet(chainable, uriFunction, params); + }, + + /** + * Grants an authority to this team. + * + * @param authorityId + * + * @chained team + */ + grant: function(authorityId) + { + const uriFunction = function() + { + return this.getUri() + "/authorities/" + authorityId + "/grant"; + }; + + return this.chainPostEmpty(null, uriFunction); + }, + + /** + * Revokes an authority from this team. + * + * @param authorityId + * + * @chained team + */ + revoke: function(authorityId) + { + const uriFunction = function() + { + return this.getUri() + "/authorities/" + authorityId + "/revoke"; + }; + + return this.chainPostEmpty(null, uriFunction); + }, + + /** + * Loads the authorities for this team and fires them into a callback. + * + * @param callback + * + * @chained team + */ + loadAuthorities: function(callback) + { + const uriFunction = function() + { + return this.getUri() + "/authorities"; + }; + + return this.chainGetResponse(this, uriFunction).then(function(response) { + callback.call(this, response["authorities"]); + }); + }, + + + ////////////////////////////////////////////////////////////////////////////////////// + // + // ACCESSORS + // + ////////////////////////////////////////////////////////////////////////////////////// + + /** + * Returns the team key + */ + getKey: function() + { + return this.get("key"); + }, + + getGroupId: function() + { + return this.get("groupId"); + }, + + getRoleKeys: function() + { + return this.get("roleKeys"); + } + + + + }); + +})(window); +(function(window) +{ + Gitana = window.Gitana; + + Gitana.TeamMap = Gitana.AbstractMap.extend( + /** @lends Gitana.TeamMap.prototype */ + { + /** + * @constructs + * @augments Gitana.AbstractMap + * + * @class Map of teams + * + * @param {Gitana.Cluster} cluster Gitana cluster instance. + * @param {Object} teamable + * @param {Object} object + */ + constructor: function(cluster, teamable, object) + { + this.__teamable = (function() { + let _teamable = null; + return function(teamable) { + if (!Gitana.isUndefined(teamable)) { _teamable = teamable; } + return _teamable; + }; + })(); + + this.__teamable(teamable); + + this.objectType = function() { return "Gitana.TeamMap"; }; + + this.getCluster = function() + { + return cluster; + }; + + ////////////////////////////////////////////////////////////////////////////////////////////// + // + // CALL THROUGH TO BASE CLASS (at the end) + // + ////////////////////////////////////////////////////////////////////////////////////////////// + + this.base(cluster.getDriver(), object); + }, + + /** + * @override + */ + clone: function() + { + return this.getFactory().teamMap(this.getCluster(), this.__teamable(), this); + }, + + /** + * @param json + */ + buildObject: function(json) + { + return this.getFactory().team(this.getCluster(), this.__teamable(), json); + } + + }); + +})(window); +(function(window) +{ + Gitana = window.Gitana; + + Gitana.TeamMember = Gitana.AbstractObject.extend( + /** @lends Gitana.TeamMember.prototype */ + { + /** + * @constructs + * @augments Gitana.AbstractObject + * + * @class TeamMember + * + * @param {Gitana.Cluster} team + * @param {Object} object json object (if no callback required for populating) + */ + constructor: function(team, object) + { + this.base(team.getDriver(), object); + + this.objectType = function() { return "Gitana.TeamMember"; }; + + + + ////////////////////////////////////////////////////////////////////////////////////////////// + // + // PRIVILEGED METHODS + // + ////////////////////////////////////////////////////////////////////////////////////////////// + + this.getTeam = function() { return team; }; + this.getCluster = function() { return team.getCluster(); }; + this.getClusterId = function() { return team.getClusterId(); }; + } + + /*, + + domain: function() + { + const self = this; + + const result = this.subchain(new Gitana.Domain({ + "_doc": this.domainId + })); + + return result.then(function() { + // TODO: read the domain and populate + }); + }, + + principal: function() + { + const self = this; + + // domain + const domain = new Gitana.Domain({ + "" + }) + // temp web host + const webhost = new Gitana.WebHost(this.getPlatform()); + + // we hand back a deployed application and preload some work + const chainable = this.getFactory().deployedApplication(webhost); + return this.chainPost(chainable, uriFunction).then(function() { + + // load the real web host + const webhostId = self["deployments"][deploymentKey]["webhost"]; + this.subchain(this.getPlatform()).readWebHost(webhostId).then(function() { + webhost.loadFrom(this); + }); + + }); + } + */ + }); + +})(window); +(function(window) +{ + Gitana = window.Gitana; + + Gitana.TeamMemberMap = Gitana.AbstractMap.extend( + /** @lends Gitana.TeamMemberMap.prototype */ + { + /** + * @constructs + * @augments Gitana.AbstractMap + * + * @class Map of team members + * + * @param {Gitana.Team} team + * @param {Object} object + */ + constructor: function(team, object) + { + this.objectType = function() { return "Gitana.TeamMemberMap"; }; + + this.getTeam = function() + { + return team; + }; + + ////////////////////////////////////////////////////////////////////////////////////////////// + // + // CALL THROUGH TO BASE CLASS (at the end) + // + ////////////////////////////////////////////////////////////////////////////////////////////// + + this.base(team.getDriver(), object); + }, + + /** + * @override + */ + clone: function() + { + return new Gitana.TeamMemberMap(this.getTeam(), this); + }, + + /** + * @param json + */ + buildObject: function(json) + { + return new Gitana.TeamMember(this.getTeam(), json); + } + + }); + +})(window); +(function(window) +{ + Gitana = window.Gitana; + + Gitana.Activity = Gitana.AbstractObject.extend( + /** @lends Gitana.Activity.prototype */ + { + /** + * @constructs + * @augments Gitana.AbstractObject + * + * @class Activity + * + * @param {Gitana.DataStore} datastore + * @param {Object} object json object (if no callback required for populating) + */ + constructor: function(datastore, object) + { + this.base(datastore.getDriver(), object); + + this.objectType = function() { return "Gitana.Activity"; }; + + this.getDataStore = function() + { + return datastore; + }; + }, + + getUri: function() + { + return this.getDataStore().getUri() + "/activities/" + this.getId(); + }, + + /** + * @override + */ + clone: function() + { + return new Gitana.Activity(this.getDataStore(), this); + }, + + /** + * Delete + * + * @chained datastore + * + * @public + */ + del: function() + { + const uriFunction = function() + { + return this.getUri(); + }; + + // NOTE: pass control back to the datastore + return this.chainDelete(this.getDataStore(), uriFunction); + }, + + /** + * Reload + * + * @chained security group + * + * @public + */ + reload: function() + { + const uriFunction = function() + { + return this.getUri(); + }; + + return this.chainReload(null, uriFunction); + }, + + /** + * Update + * + * @chained security group + * + * @public + */ + update: function() + { + const uriFunction = function() + { + return this.getUri(); + }; + + return this.chainUpdate(null, uriFunction); + }, + + + ////////////////////////////////////////////////////////////////////////////////////// + // + // ACCESSORS + // + ////////////////////////////////////////////////////////////////////////////////////// + + getType: function() + { + return this.get("type"); + }, + + getTimestamp: function() + { + return this.get("timestamp"); + }, + + + // user + + getUserDomainId: function() + { + return this.get("userDomainId"); + }, + + getUserId: function() + { + return this.get("userId"); + }, + + getUserTitle: function() + { + return this.get("userTitle"); + }, + + getUserEmail: function() + { + return this.get("userEmail"); + }, + + getUserName: function() + { + return this.get("userName"); + }, + + + // object + + getObjectDataStoreTypeId: function() + { + return this.get("objectDatastoreTypeId"); + }, + + getObjectDataStoreId: function() + { + return this.get("objectDatastoreId"); + }, + + getObjectDataStoreTitle: function() + { + return this.get("objectDatastoreTitle"); + }, + + getObjectTypeId: function() + { + return this.get("objectTypeId"); + }, + + getObjectId: function() + { + return this.get("objectId"); + }, + + getObjectTitle: function() + { + return this.get("objectTitle"); + }, + + + // other + + getOtherDataStoreTypeId: function() + { + return this.get("otherDatastoreTypeId"); + }, + + getOtherDataStoreId: function() + { + return this.get("otherDatastoreId"); + }, + + getOtherDataStoreTitle: function() + { + return this.get("otherDatastoreTitle"); + }, + + getOtherTypeId: function() + { + return this.get("otherTypeId"); + }, + + getOtherId: function() + { + return this.get("otherId"); + }, + + getOtherTitle: function() + { + return this.get("otherTitle"); + } + + }); + +})(window); +(function(window) +{ + Gitana = window.Gitana; + + Gitana.ActivityMap = Gitana.AbstractMap.extend( + /** @lends Gitana.ActivityMap.prototype */ + { + /** + * @constructs + * @augments Gitana.AbstractMap + * + * @class Map of activities + * + * @param {Object} datastore Gitana datastore + * @param {Object} object + */ + constructor: function(datastore, object) + { + this.objectType = function() { return "Gitana.ActivityMap"; }; + + this.getDataStore = function() + { + return datastore; + }; + + ////////////////////////////////////////////////////////////////////////////////////////////// + // + // CALL THROUGH TO BASE CLASS (at the end) + // + ////////////////////////////////////////////////////////////////////////////////////////////// + + this.base(datastore.getDriver(), object); + }, + + /** + * @override + */ + clone: function() + { + return this.getFactory().activityMap(this.getDataStore(), this); + }, + + /** + * @param json + */ + buildObject: function(json) + { + return this.getFactory().activity(this.getDataStore(), json); + } + + }); + +})(window); +(function(window) +{ + Gitana = window.Gitana; + + Gitana.Role = Gitana.AbstractObject.extend( + /** @lends Gitana.Role.prototype */ + { + /** + * @constructs + * @augments Gitana.AbstractObject + * + * @class Role + * + * @param {Gitana.Cluster} cluster + * @param {Object} roleContainer + * @param {Object} object json object (if no callback required for populating) + */ + constructor: function(cluster, roleContainer, object) + { + this.base(cluster.getDriver(), object); + + this.objectType = function() { return "Gitana.Role"; }; + + this.roleContainer = roleContainer; + + this.getCluster = function() + { + return cluster; + }; + }, + + getUri: function() + { + return this.roleContainer.getUri() + "/roles/" + this.getId(); + }, + + getType: function() + { + return "role"; + }, + + /** + * Delete + * + * @chained team + * + * @public + */ + del: function() + { + const uriFunction = function() + { + return this.getUri(); + }; + + // NOTE: pass control back to the role container + return this.chainDelete(this.roleContainer, uriFunction); + }, + + /** + * Reload + * + * @chained role + * + * @public + */ + reload: function() + { + const uriFunction = function() + { + return this.getUri(); + }; + + return this.chainReload(null, uriFunction); + }, + + /** + * Update + * + * @chained team + * + * @public + */ + update: function() + { + const uriFunction = function() + { + return this.getUri(); + }; + + return this.chainUpdate(null, uriFunction); + }, + + ////////////////////////////////////////////////////////////////////////////////////// + // + // ACCESSORS + // + ////////////////////////////////////////////////////////////////////////////////////// + + /** + * Returns the role key + */ + getRoleKey: function() + { + return this.roleKey; + }, + + getPermissions: function() + { + return this.object["permissions"]; + } + }); + +})(window); +(function(window) +{ + Gitana = window.Gitana; + + Gitana.RoleMap = Gitana.AbstractMap.extend( + /** @lends Gitana.RoleMap.prototype */ + { + /** + * @constructs + * @augments Gitana.AbstractMap + * + * @class Map of roles + * + * @param {Gitana.Cluster} cluster Gitana cluster instance. + * @param {Object} roleContainer container + * @param {Object} object + */ + constructor: function(cluster, roleContainer, object) + { + this.objectType = function() { return "Gitana.RoleMap"; }; + + this.getCluster = function() + { + return cluster; + }; + + ////////////////////////////////////////////////////////////////////////////////////////////// + // + // CALL THROUGH TO BASE CLASS (at the end) + // + ////////////////////////////////////////////////////////////////////////////////////////////// + + this.base(cluster.getDriver(), object); + + this.roleContainer = roleContainer; + }, + + /** + * @override + */ + clone: function() + { + return this.getFactory().roleMap(this.getCluster(), this.roleContainer, this); + }, + + /** + * @param json + */ + buildObject: function(json) + { + return this.getFactory().role(this.getCluster(), this.roleContainer, json); + } + + }); + +})(window); +(function(window) +{ + Gitana = window.Gitana; + + Gitana.ResultMap = Gitana.AbstractMap.extend( + /** @lends Gitana.ResultMap.prototype */ + { + /** + * @constructs + * @augments Gitana.AbstractMap + * + * @class Generalized result maps + * + * @param {Gitana} driver + * @param {Object} resultMap + */ + constructor: function(driver, resultMap) + { + this.objectType = function() { return "Gitana.ResultMap"; }; + + ////////////////////////////////////////////////////////////////////////////////////////////// + // + // CALL THROUGH TO BASE CLASS (at the end) + // + ////////////////////////////////////////////////////////////////////////////////////////////// + + this.base(driver, resultMap); + }, + + /** + * @override + */ + clone: function() + { + return this.getFactory().resultMap(this.getDriver(), this); + }, + + /** + * @param object + */ + buildObject: function(object) + { + return object; + } + + }); + +})(window); +(function(window) +{ + Gitana = window.Gitana; + + Gitana.Cluster = Gitana.DataStore.extend( + /** @lends Gitana.Cluster.prototype */ + { + /** + * @constructs + * @augments Gitana.DataStore + * + * @class Cluster + * + * @param {Gitana.Driver} driver + * @param {Object} object json object (if no callback required for populating) + */ + constructor: function(driver, object) + { + this.objectType = function() { return "Gitana.Cluster"; }; + + this.base(driver, object); + }, + + /** + * @OVERRIDE + */ + getUri: function() + { + return ""; + }, + + /** + * @OVERRIDE + */ + getType: function() + { + return Gitana.TypedIDConstants.TYPE_CLUSTER; + }, + + /** + * @override + */ + clone: function() + { + return new Gitana.Cluster(this.getDriver(), this); + }, + + /** + * Loads the contained types for a type as a string array and passes it into a callback function. + * + * @param type + * @param callback + * @return this + */ + loadContainedTypes: function(type, callback) + { + const uriFunction = function() + { + return "/tools/types/contained/" + type; + }; + + return this.chainPostResponse(this, uriFunction).then(function(response) { + callback.call(this, response["types"]); + }); + }, + + + + ////////////////////////////////////////////////////////////////////////////////////////// + // + // JOB METHODS + // + ////////////////////////////////////////////////////////////////////////////////////////// + + /** + * Queries for jobs. + * + * @chained job map + * + * @param {Object} query Query for finding a job. + * @param {Object} pagination pagination (optional) + */ + queryJobs: function(query, pagination) + { + const chainable = this.getFactory().jobMap(this); + + // prepare params (with pagination) + const params = {}; + if (pagination) + { + Gitana.copyInto(params, pagination); + } + + return this.chainPost(chainable, "/jobs/query", params, query); + }, + + /** + * Read a job. + * + * @chained job + * + * @param {String} jobId + */ + readJob: function(jobId) + { + const chainable = this.getFactory().job(this); + + return this.chainGet(chainable, "/jobs/" + jobId); + }, + + /** + * Kills a job + * + * @chained server + * + * @param {String} jobId + */ + killJob: function(jobId) + { + return this.chainPostEmpty(null, "/jobs/" + jobId + "/kill"); + }, + + /** + * Queries for unstarted jobs. + * + * @chained job map + * + * @param {Object} query Query for finding a job. + * @param {Object} pagination pagination (optional) + */ + queryUnstartedJobs: function(query, pagination) + { + const chainable = this.getFactory().jobMap(this); + + // prepare params (with pagination) + const params = {}; + if (pagination) + { + Gitana.copyInto(params, pagination); + } + + return this.chainPost(chainable, "/jobs/unstarted/query", params, query); + }, + + /** + * Queries for running jobs. + * + * @chained job map + * + * @param {Object} query Query for finding a job. + * @param {Object} pagination pagination (optional) + */ + queryRunningJobs: function(query, pagination) + { + const chainable = this.getFactory().jobMap(this); + + // prepare params (with pagination) + const params = {}; + if (pagination) + { + Gitana.copyInto(params, pagination); + } + + return this.chainPost(chainable, "/jobs/running/query", params, query); + }, + + /** + * Queries for failed jobs. + * + * @chained job map + * + * @param {Object} query Query for finding a job. + * @param {Object} pagination pagination (optional) + */ + queryFailedJobs: function(query, pagination) + { + const chainable = this.getFactory().jobMap(this); + + // prepare params (with pagination) + const params = {}; + if (pagination) + { + Gitana.copyInto(params, pagination); + } + + return this.chainPost(chainable, "/jobs/failed/query", params, query); + }, + + /** + * Queries for waiting jobs. + * + * @chained job map + * + * @param {Object} query Query for finding a job. + * @param {Object} pagination pagination (optional) + */ + queryWaitingJobs: function(query, pagination) + { + const chainable = this.getFactory().jobMap(this); + + // prepare params (with pagination) + const params = {}; + if (pagination) + { + Gitana.copyInto(params, pagination); + } + + return this.chainPost(chainable, "/jobs/waiting/query", params, query); + }, + + /** + * Queries for finished jobs. + * + * @chained job map + * + * @param {Object} query Query for finding a job. + * @param {Object} pagination pagination (optional) + */ + queryFinishedJobs: function(query, pagination) + { + const chainable = this.getFactory().jobMap(this); + + // prepare params (with pagination) + const params = {}; + if (pagination) + { + Gitana.copyInto(params, pagination); + } + + return this.chainPost(chainable, "/jobs/finished/query", params, query); + }, + + waitForJobCompletion: function(jobId, callback, progressCallback) + { + const chainable = this; + + const f = function() + { + window.setTimeout(function() { + + Chain(chainable).readJob(jobId).then(function() { + + if(progressCallback && Gitana.isFunction(progressCallback)) { + progressCallback(this); + } + + if (this.state === "FINISHED") { + callback(this); + chainable.next(); + } else if (this.state === "ERROR") { + callback(this); + chainable.next(); + } else { + f(); + } + }); + + }, 1000); + }; + f(); + } + + }); + +})(window); +(function(window) +{ + Gitana = window.Gitana; + + Gitana.AbstractClusterObject = Gitana.AbstractObject.extend( + /** @lends Gitana.AbstractClusterObject.prototype */ + { + /** + * @constructs + * @augments Gitana.AbstractObject + * + * @class AbstractClusterObject + * + * @param {Gitana.Cluster} cluster + * @param {Object} object json object (if no callback required for populating) + */ + constructor: function(cluster, object) + { + this.base(cluster.getDriver(), object); + + this.objectType = function() { return "Gitana.Job"; }; + + this.getCluster = function() + { + return cluster; + }; + }, + + /** + * @OVERRIDE + */ + ref: function() + { + return this.getType() + "://" + this.getId(); + } + + }); + +})(window); +(function(window) +{ + Gitana = window.Gitana; + + Gitana.Job = Gitana.AbstractClusterObject.extend( + /** @lends Gitana.Job.prototype */ + { + /** + * @constructs + * @augments Gitana.AbstractClusterObject + * + * @class Job + * + * @param {Gitana.Cluster} cluster + * @param {Object} object json object (if no callback required for populating) + */ + constructor: function(cluster, object) + { + this.base(cluster, object); + + this.objectType = function() { return "Gitana.Job"; }; + }, + + /** + * @override + */ + clone: function() + { + return new Gitana.Job(this.getCluster(), this); + }, + + /** + * @returns {String} the type id of the job + */ + getType: function() + { + return this.get("type"); + }, + + /** + * @returns {String} the id of the principal that this job will run as + */ + getRunAsPrincipalId: function() + { + return this.get("runAsPrincipal"); + }, + + /** + * @returns {String} the domain of the principal that this job will run as + */ + getRunAsPrincipalDomainId: function() + { + return this.get("runAsPrincipalDomain"); + }, + + /** + * @returns {String} the state of the job + */ + getState: function() + { + return this.get("state"); + }, + + /** + * @returns {String} the platform id + */ + getPlatformId: function() + { + return this.get("platformId"); + }, + + /** + * @returns {Number} the priority of the job + */ + getPriority: function() + { + return this.get("priority"); + }, + + /** + * @returns {Number} the number of attempts made to run this job + */ + getAttempts: function() + { + return this.get("attempts"); + }, + + /** + * @returns {Object} when the job is scheduled to start (or null) + */ + getScheduledStartTime: function() + { + return this.get("schedule_start_ms"); + }, + + /** + * @returns [Array] array of status log objects + */ + getLogEntries: function() + { + return this.get("log_entries"); + }, + + getCurrentThread: function() + { + return this.get("current_thread"); + }, + + getCurrentServer: function() + { + return this.get("current_server"); + }, + + getCurrentServerTimeStamp: function() + { + return this.get("current_server_timestamp"); + }, + + getSubmittedBy: function() + { + return this.get("submitted_by"); + }, + + getSubmittedTimestamp: function() + { + return this.get("submitted_timestamp"); + }, + + getStarted: function() + { + return this.get("started"); + }, + + getStartedBy: function() + { + return this.get("started_by"); + }, + + getStartedTimestamp: function() + { + return this.get("started_timestamp"); + }, + + getStopped: function() + { + return this.get("stopped"); + }, + + getStoppedTimestamp: function() + { + return this.get("stopped_timestamp"); + }, + + getPaused: function() + { + return this.get("paused"); + }, + + getPausedBy: function() + { + return this.get("paused_by"); + }, + + getPausedTimestamp: function() + { + return this.get("paused_timestamp"); + } + }); + +})(window); +(function(window) +{ + Gitana = window.Gitana; + + Gitana.JobMap = Gitana.AbstractMap.extend( + /** @lends Gitana.JobMap.prototype */ + { + /** + * @constructs + * @augments Gitana.AbstractMap + * + * @class Map of jobs + * + * @param {Gitana.Cluster} cluster Gitana cluster instance. + * @param {Object} object + */ + constructor: function(cluster, object) + { + this.objectType = function() { return "Gitana.JobMap"; }; + + this.getCluster = function() + { + return cluster; + }; + + ////////////////////////////////////////////////////////////////////////////////////////////// + // + // CALL THROUGH TO BASE CLASS (at the end) + // + ////////////////////////////////////////////////////////////////////////////////////////////// + + this.base(cluster.getDriver(), object); + }, + + /** + * @override + */ + clone: function() + { + return this.getFactory().jobMap(this.getCluster(), this); + }, + + /** + * @param json + */ + buildObject: function(json) + { + return this.getFactory().job(this.getCluster(), json); + } + + }); + +})(window); +(function(window) +{ + Gitana = window.Gitana; + + Gitana.LogEntry = Gitana.AbstractObject.extend( + /** @lends Gitana.LogEntry.prototype */ + { + /** + * @constructs + * @augments Gitana.AbstractObject + * + * @class LogEntry + * + * @param {Gitana.Platform} platform + * @param {Object} object json object (if no callback required for populating) + */ + constructor: function(platform, object) + { + this.base(platform.getDriver(), object); + + this.objectType = function() { return "Gitana.LogEntry"; }; + + this.getPlatform = function() + { + return platform; + }; + }, + + /** + * @override + */ + clone: function() + { + return new Gitana.LogEntry(this.getPlatform(), this); + }, + + /** + * @OVERRIDE + */ + getType: function() + { + return Gitana.TypedIDConstants.TYPE_LOG_ENTRY; + }, + + /** + * @returns {String} the id of the principal that logged this entry + */ + getPrincipalId: function() + { + return this.get("principalId"); + }, + + /** + * @returns {String} the id of the repository against which this log entry was logged (or null) + */ + getRepositoryId: function() + { + return this.get("repositoryId"); + }, + + /** + * @returns {String} the id of the branch against which this log entry was logged (or null) + */ + getBranchId: function() + { + return this.get("branchId"); + }, + + /** + * @returns {String} log level + */ + getLevel: function() + { + return this.get("level"); + }, + + /** + * @returns {String} thread id + */ + getThread: function() + { + return this.get("thread"); + }, + + /** + * @returns {Object} timestamp + */ + getTimestamp: function() + { + return this.get("timestamp"); + }, + + /** + * @returns {String} message + */ + getMessage: function() + { + return this.get("message"); + }, + + /** + * @returns {String} filename + */ + getFilename: function() + { + return this.get("filename"); + }, + + /** + * @returns {String} method + */ + getMethod: function() + { + return this.get("method"); + }, + + /** + * @returns {Number} line number + */ + getLineNumber: function() + { + return this.get("line"); + }, + + /** + * @returns {Object} class descriptor + */ + getClassDescriptor: function() + { + return this.get("class"); + }, + + /** + * @returns [Array] throwables + */ + getThrowables: function() + { + return this.get("throwables"); + } + + }); + +})(window); +(function(window) +{ + Gitana = window.Gitana; + + Gitana.LogEntryMap = Gitana.AbstractMap.extend( + /** @lends Gitana.LogEntryMap.prototype */ + { + /** + * @constructs + * @augments Gitana.AbstractMap + * + * @class Map of log entries + * + * @param {Gitana.Platform} platform Gitana server instance. + * @param {Object} object + */ + constructor: function(platform, object) + { + this.objectType = function() { return "Gitana.LogEntryMap"; }; + + this.getPlatform = function() + { + return platform; + }; + + ////////////////////////////////////////////////////////////////////////////////////////////// + // + // CALL THROUGH TO BASE CLASS (at the end) + // + ////////////////////////////////////////////////////////////////////////////////////////////// + + this.base(platform.getDriver(), object); + }, + + /** + * @override + */ + clone: function() + { + return this.getFactory().logEntryMap(this.getPlatform(), this); + }, + + /** + * @param json + */ + buildObject: function(json) + { + return this.getFactory().logEntry(this.getPlatform(), json); + } + + }); + +})(window); +(function(window) +{ + Gitana = window.Gitana; + + Gitana.CopyJob = Gitana.Job.extend( + /** @lends Gitana.CopyJob.prototype */ + { + /** + * @constructs + * @augments Gitana.AbstractObject + * + * @class CopyJob + * + * @param {Gitana.Cluster} cluster + * @param {Object} object json object (if no callback required for populating) + */ + constructor: function(cluster, object) + { + this.base(cluster, object); + + this.objectType = function() { return "Gitana.CopyJob"; }; + }, + + /** + * @override + */ + clone: function() + { + return new Gitana.CopyJob(this.getCluster(), this); + }, + + getImports: function() + { + const importObjects = []; + + const array = this.get("imports"); + for (let i = 0; i < array.length; i++) + { + const object = array[i]; + + const sources = object["sources"]; + const targets = object["targets"]; + + const importObject = { + sources, + targets, + getType: function() + { + return this.targets[this.targets.length - 1]["typeId"]; + }, + getSourceId: function() + { + return this.sources[this.sources.length - 1]["id"]; + }, + getTargetId: function() + { + return this.targets[this.targets.length - 1]["id"]; + } + }; + importObjects.push(importObject); + } + + return importObjects; + }, + + getSingleImportTargetId: function() + { + let targetId = null; + + const importObjects = this.getImports(); + if (importObjects.length > 0) + { + targetId = importObjects[0].getTargetId(); + } + + return targetId; + } + + }); + +})(window); +(function(window) +{ + Gitana = window.Gitana; + + Gitana.TransferImportJob = Gitana.Job.extend( + /** @lends Gitana.TransferImportJob.prototype */ + { + /** + * @constructs + * @augments Gitana.AbstractObject + * + * @class TransferImportJob + * + * @param {Gitana.Cluster} cluster + * @param {Object} object json object (if no callback required for populating) + */ + constructor: function(cluster, object) + { + this.base(cluster, object); + + this.objectType = function() { return "Gitana.TransferImportJob"; }; + }, + + /** + * @override + */ + clone: function() + { + return new Gitana.TransferExportJob(this.getCluster(), this); + }, + + getImports: function() + { + const importObjects = []; + + const array = this.get("imports"); + for (let i = 0; i < array.length; i++) + { + const object = array[i]; + + const sources = object["sources"]; + const targets = object["targets"]; + + const importObject = { + sources, + targets, + getType: function() + { + return this.targets[this.targets.length - 1]["typeId"]; + }, + getSourceId: function() + { + return this.sources[this.sources.length - 1]["id"]; + }, + getTargetId: function() + { + return this.targets[this.targets.length - 1]["id"]; + } + }; + importObjects.push(importObject); + } + + return importObjects; + }, + + getSingleImportTargetId: function() + { + let targetId = null; + + const importObjects = this.getImports(); + if (importObjects.length > 0) + { + targetId = importObjects[0].getTargetId(); + } + + return targetId; + } + }); + +})(window); +(function(window) +{ + Gitana = window.Gitana; + + Gitana.TransferExportJob = Gitana.Job.extend( + /** @lends Gitana.TransferExportJob.prototype */ + { + /** + * @constructs + * @augments Gitana.AbstractObject + * + * @class TransferExportJob + * + * @param {Gitana.Cluster} cluster + * @param {Object} object json object (if no callback required for populating) + */ + constructor: function(cluster, object) + { + this.base(cluster, object); + + this.objectType = function() { return "Gitana.TransferExportJob"; }; + }, + + /** + * @override + */ + clone: function() + { + return new Gitana.TransferExportJob(this.getCluster(), this); + }, + + getImports: function() + { + const importObjects = []; + + const array = this.get("imports"); + for (let i = 0; i < array.length; i++) + { + const object = array[i]; + + const sources = object["sources"]; + const targets = object["targets"]; + + const importObject = { + sources, + targets, + getType: function() + { + return this.targets[this.targets.length - 1]["typeId"]; + }, + getSourceId: function() + { + return this.sources[this.sources.length - 1]["id"]; + }, + getTargetId: function() + { + return this.targets[this.targets.length - 1]["id"]; + } + }; + importObjects.push(importObject); + } + + return importObjects; + }, + + getSingleImportTargetId: function() + { + let targetId = null; + + const importObjects = this.getImports(); + if (importObjects.length > 0) + { + targetId = importObjects[0].getTargetId(); + } + + return targetId; + } + }); + +})(window); +(function(window) +{ + Gitana = window.Gitana; + + Gitana.Platform = Gitana.ContainedDataStore.extend( + /** @lends Gitana.Platform.prototype */ + { + /** + * @constructs + * @augments Gitana.DataStore + * + * @class Platform + * + * @param {Gitana.Cluster} cluster + * @param {Object} object json object (if no callback required for populating) + */ + constructor: function(cluster, object) + { + this.objectType = function() { return "Gitana.Platform"; }; + + this.base(cluster, object); + + + ////////////////////////////////////////////////////////////////////////////////////////////// + // + // PRIVILEGED METHODS + // + ////////////////////////////////////////////////////////////////////////////////////////////// + + this.getCluster = function() + { + return cluster; + }; + + this.getClusterId = function() + { + return cluster.getId(); + }; + + }, + + /** + * This method is provided to make the platform datastore compatible for teams. + */ + getPlatform: function() + { + return this; + }, + + /** + * Reads the cluster. + * + * @chained cluster + */ + readCluster: function() + { + return this.subchain(this.getCluster()); + }, + + /** + * @OVERRIDE + */ + getUri: function() + { + return ""; + }, + + /** + * @OVERRIDE + */ + getType: function() + { + return Gitana.TypedIDConstants.TYPE_PLATFORM; + }, + + /** + * @override + */ + clone: function() + { + return this.getFactory().platform(this.getCluster(), this); + }, + + /** @Override **/ + del: function() + { + // not implemented + return this; + }, + + /** @Override **/ + reload: function() + { + const uriFunction = function() + { + return this.getUri() + "/"; + }; + + return this.chainReload(null, uriFunction); + }, + + /** @Override **/ + update: function() + { + const uriFunction = function() + { + return this.getUri() + "/"; + }; + + return this.chainUpdate(null, uriFunction); + }, + + /** + * Hands back the primary domain instance for this platform. + * + * @chained domain + */ + readPrimaryDomain: function() + { + const self = this; + + const uriFunction = function() + { + return self.getUri() + "/domains/primary"; + }; + + const chainable = this.getFactory().domain(this); + return this.chainGet(chainable, uriFunction); + }, + + /** + * Loads information about the platform. + * + * @param callback + */ + loadInfo: function(callback) + { + const uriFunction = function() + { + return "/info"; + }; + + return this.chainGetResponse(this, uriFunction, {}).then(function(response) { + callback(response); + }); + }, + + + + ///////////////////////////////////////////////////////////////////////////////////////////////// + // + // REPOSITORIES + // + ///////////////////////////////////////////////////////////////////////////////////////////////// + + /** + * Lists repositories. + * + * @chained repository map + * + * @param {Object} pagination pagination (optional) + */ + listRepositories: function(pagination) + { + // prepare params (with pagination) + const params = {}; + if (pagination) + { + Gitana.copyInto(params, pagination); + } + + const chainable = this.getFactory().repositoryMap(this); + return this.chainGet(chainable, "/repositories", params); + }, + + /** + * Read a repository. + * + * @chained repository + * + * @param {String} repositoryId the repository id + */ + readRepository: function(repositoryId) + { + const chainable = this.getFactory().repository(this); + return this.chainGet(chainable, "/repositories/" + repositoryId); + }, + + /** + * Create a repository + * + * @chained repository + * + * @param {Object} object JSON object + */ + createRepository: function(object) + { + const chainable = this.getFactory().repository(this); + return this.chainCreate(chainable, object, "/repositories"); + }, + + /** + * Queries for a repository. + * + * @chained repository map + * + * @param {Object} query Query for finding a repository. + * @param {Object} pagination pagination (optional) + */ + queryRepositories: function(query, pagination) + { + const chainable = this.getFactory().repositoryMap(this); + + // prepare params (with pagination) + const params = {}; + if (pagination) + { + Gitana.copyInto(params, pagination); + } + + return this.chainPost(chainable, "/repositories/query", params, query); + }, + + /** + * Performs a bulk check of permissions against permissioned objects of type repository. + * + * Example of checks array: + * + * [{ + * "permissionedId": "", + * "domainId": "", (optional) + * "principalId": "", + * "permissionId": "" + * }] + * + * The callback receives an array of results, example: + * + * [{ + * "permissionedId": "", + * "domainId": "", (optional) + * "principalId": "", + * "permissionId": "", + * "result": true + * }] + * + * The order of elements in the array will be the same for checks and results. + * + * @param checks + * @param callback + */ + checkRepositoryPermissions: function(checks, callback) + { + const uriFunction = function() + { + return "/repositories/permissions/check"; + }; + + const object = { + "checks": checks + }; + + return this.chainPostResponse(this, uriFunction, {}, object).then(function(response) { + callback.call(this, response["results"]); + }); + }, + + /** + * Performs a bulk check of authorities against permissioned objects of type repository. + * + * Example of checks array: + * + * [{ + * "permissionedId": "", + * "domainId": "", (optional) + * "principalId": "", + * "authorityId": "" + * }] + * + * The callback receives an array of results, example: + * + * [{ + * "permissionedId": "", + * "domainId": "", (optional) + * "principalId": "", + * "authorityId": "", + * "result": true + * }] + * + * The order of elements in the array will be the same for checks and results. + * + * @param checks + * @param callback + */ + checkRepositoryAuthorities: function(checks, callback) + { + const uriFunction = function() + { + return "/repositories/authorities/check"; + }; + + const object = { + "checks": checks + }; + + return this.chainPostResponse(this, uriFunction, {}, object).then(function(response) { + callback.call(this, response["results"]); + }); + }, + + + + ///////////////////////////////////////////////////////////////////////////////////////////////// + // + // DOMAINS + // + ///////////////////////////////////////////////////////////////////////////////////////////////// + + /** + * Lists domains. + * + * @chained domain map + * + * @param {Object} pagination pagination (optional) + */ + listDomains: function(pagination) + { + // prepare params (with pagination) + const params = {}; + if (pagination) + { + Gitana.copyInto(params, pagination); + } + + const chainable = this.getFactory().domainMap(this); + return this.chainGet(chainable, "/domains", params); + }, + + /** + * Read a domain. + * + * @chained domain + * + * @param {String} domainId the domain id + */ + readDomain: function(domainId) + { + const chainable = this.getFactory().domain(this); + return this.chainGet(chainable, "/domains/" + domainId); + }, + + /** + * Create a domain + * + * @chained domain + * + * @param {Object} object JSON object + */ + createDomain: function(object) + { + const chainable = this.getFactory().domain(this); + return this.chainCreate(chainable, object, "/domains"); + }, + + /** + * Queries for a domain. + * + * @chained domain map + * + * @param {Object} query Query for finding a domain. + * @param {Object} pagination pagination (optional) + */ + queryDomains: function(query, pagination) + { + const chainable = this.getFactory().domainMap(this); + + // prepare params (with pagination) + const params = {}; + if (pagination) + { + Gitana.copyInto(params, pagination); + } + + return this.chainPost(chainable, "/domains/query", params, query); + }, + + /** + * Performs a bulk check of permissions against permissioned objects of type domain. + * + * Example of checks array: + * + * [{ + * "permissionedId": "", + * "principalId": "", + * "permissionId": "" + * }] + * + * The callback receives an array of results, example: + * + * [{ + * "permissionedId": "", + * "principalId": "", + * "permissionId": "", + * "result": true + * }] + * + * The order of elements in the array will be the same for checks and results. + * + * @param checks + * @param callback + */ + checkDomainPermissions: function(checks, callback) + { + const uriFunction = function() + { + return "/domains/permissions/check"; + }; + + const object = { + "checks": checks + }; + + return this.chainPostResponse(this, uriFunction, {}, object).then(function(response) { + callback.call(this, response["results"]); + }); + }, + + /** + * Performs a bulk check of permissions against permissioned objects of type domain. + * + * Example of checks array: + * + * [{ + * "permissionedId": "", + * "principalId": "", + * "authorityId": "" + * }] + * + * The callback receives an array of results, example: + * + * [{ + * "permissionedId": "", + * "principalId": "", + * "authorityId": "", + * "result": true + * }] + * + * The order of elements in the array will be the same for checks and results. + * + * @param checks + * @param callback + */ + checkDomainAuthorities: function(checks, callback) + { + const uriFunction = function() + { + return "/domains/authorities/check"; + }; + + const object = { + "checks": checks + }; + + return this.chainPostResponse(this, uriFunction, {}, object).then(function(response) { + callback.call(this, response["results"]); + }); + }, + + + + + + ///////////////////////////////////////////////////////////////////////////////////////////////// + // + // VAULTS + // + ///////////////////////////////////////////////////////////////////////////////////////////////// + + /** + * Lists vaults. + * + * @chained vault map + * + * @param {Object} pagination pagination (optional) + */ + listVaults: function(pagination) + { + // prepare params (with pagination) + const params = {}; + if (pagination) + { + Gitana.copyInto(params, pagination); + } + + const chainable = this.getFactory().vaultMap(this); + return this.chainGet(chainable, "/vaults", params); + }, + + /** + * Read a vault. + * + * @chained vault + * + * @param {String} vaultId the vault id + */ + readVault: function(vaultId) + { + const chainable = this.getFactory().vault(this); + return this.chainGet(chainable, "/vaults/" + vaultId); + }, + + /** + * Create a vault + * + * @chained vault + * + * @param {Object} object JSON object + */ + createVault: function(object) + { + const chainable = this.getFactory().vault(this); + return this.chainCreate(chainable, object, "/vaults"); + }, + + /** + * Queries for a vault. + * + * @chained vault map + * + * @param {Object} query Query for finding a vault. + * @param {Object} pagination pagination (optional) + */ + queryVaults: function(query, pagination) + { + const chainable = this.getFactory().vaultMap(this); + + // prepare params (with pagination) + const params = {}; + if (pagination) + { + Gitana.copyInto(params, pagination); + } + + return this.chainPost(chainable, "/vaults/query", params, query); + }, + + /** + * Performs a bulk check of permissions against permissioned objects of type vault. + * + * Example of checks array: + * + * [{ + * "permissionedId": "", + * "principalId": "", + * "permissionId": "" + * }] + * + * The callback receives an array of results, example: + * + * [{ + * "permissionedId": "", + * "principalId": "", + * "permissionId": "", + * "result": true + * }] + * + * The order of elements in the array will be the same for checks and results. + * + * @param checks + * @param callback + */ + checkVaultPermissions: function(checks, callback) + { + const uriFunction = function() + { + return "/vaults/permissions/check"; + }; + + const object = { + "checks": checks + }; + + return this.chainPostResponse(this, uriFunction, {}, object).then(function(response) { + callback.call(this, response["results"]); + }); + }, + + /** + * Performs a bulk check of authorities against permissioned objects of type vault. + * + * Example of checks array: + * + * [{ + * "permissionedId": "", + * "principalId": "", + * "authorityId": "" + * }] + * + * The callback receives an array of results, example: + * + * [{ + * "permissionedId": "", + * "principalId": "", + * "authorityId": "", + * "result": true + * }] + * + * The order of elements in the array will be the same for checks and results. + * + * @param checks + * @param callback + */ + checkVaultAuthorities: function(checks, callback) + { + const uriFunction = function() + { + return "/vaults/authorities/check"; + }; + + const object = { + "checks": checks + }; + + return this.chainPostResponse(this, uriFunction, {}, object).then(function(response) { + callback.call(this, response["results"]); + }); + }, + + + + ////////////////////////////////////////////////////////////////////////////////////////// + // + // AUTHENTICATION METHODS + // + ////////////////////////////////////////////////////////////////////////////////////////// + + /** + * Logs in as the given user. + * + * This delegates a call to the underlying driver. + * + * @param {Object} config login config + * @param {Function} authFailureHandler failure handler + */ + authenticate: function(config, authFailureHandler) + { + return this.getDriver().authenticate(config, authFailureHandler); + }, + + /** + * Clears authentication against the server. + * + * @param expireAccessToken (optional, assumed false) + * + * @chained server + * + * @public + */ + logout: function(expireAccessToken) + { + return this.subchain().then(function() { + + const platformCacheKey = this.getDriver().platformCacheKey; + if (platformCacheKey) + { + Gitana.disconnect(platformCacheKey, expireAccessToken); + } + + this.getDriver().clearAuthentication(); + + delete this.getDriver().platformCacheKey; + }); + }, + + + + ////////////////////////////////////////////////////////////////////////////////////////// + // + // STACKS + // + ////////////////////////////////////////////////////////////////////////////////////////// + + /** + * Lists the stacks. + * + * @param pagination + * + * @chained stack map + */ + listStacks: function(pagination) + { + const params = {}; + if (pagination) + { + Gitana.copyInto(params, pagination); + } + + const chainable = this.getFactory().stackMap(this); + return this.chainGet(chainable, "/stacks", params); + }, + + /** + * Reads a stack. + * + * @param stackId + * + * @chained stack + */ + readStack: function(stackId) + { + const chainable = this.getFactory().stack(this); + return this.chainGet(chainable, "/stacks/" + stackId); + }, + + /** + * Create a stack + * + * @chained stack + * + * @param {Object} object JSON object + */ + createStack: function(object) + { + if (!object) + { + object = {}; + } + + const chainable = this.getFactory().stack(this); + return this.chainCreate(chainable, object, "/stacks"); + }, + + /** + * Queries for stacks. + * + * @chained stack map + * + * @param {Object} query + * @param {Object} pagination pagination (optional) + */ + queryStacks: function(query, pagination) + { + const params = {}; + if (pagination) + { + Gitana.copyInto(params, pagination); + } + + const uriFunction = function() + { + return "/stacks/query"; + }; + + const chainable = this.getFactory().stackMap(this); + return this.chainPost(chainable, uriFunction, params, query); + }, + + /** + * Finds a stack for a given data store. + * + * @param datastoreType + * @param datastoreId + * + * @chained stack + */ + findStackForDataStore: function(datastoreType, datastoreId) + { + const chainable = this.getFactory().stack(this); + return this.chainGet(chainable, "/stacks/find/" + datastoreType + "/" + datastoreId); + }, + + + /** + * Performs a bulk check of permissions against permissioned objects of type stack. + * + * Example of checks array: + * + * [{ + * "permissionedId": "", + * "principalId": "", + * "permissionId": "" + * }] + * + * The callback receives an array of results, example: + * + * [{ + * "permissionedId": "", + * "principalId": "", + * "permissionId": "", + * "result": true + * }] + * + * The order of elements in the array will be the same for checks and results. + * + * @param checks + * @param callback + */ + checkStackPermissions: function(checks, callback) + { + const uriFunction = function() + { + return "/stacks/permissions/check"; + }; + + const object = { + "checks": checks + }; + + return this.chainPostResponse(this, uriFunction, {}, object).then(function(response) { + callback.call(this, response["results"]); + }); + }, + + /** + * Performs a bulk check of authorities against permissioned objects of type stack. + * + * Example of checks array: + * + * [{ + * "permissionedId": "", + * "principalId": "", + * "authorityId": "" + * }] + * + * The callback receives an array of results, example: + * + * [{ + * "permissionedId": "", + * "principalId": "", + * "authorityId": "", + * "result": true + * }] + * + * The order of elements in the array will be the same for checks and results. + * + * @param checks + * @param callback + */ + checkStackAuthorities: function(checks, callback) + { + const uriFunction = function() + { + return "/stacks/authorities/check"; + }; + + const object = { + "checks": checks + }; + + return this.chainPostResponse(this, uriFunction, {}, object).then(function(response) { + callback.call(this, response["results"]); + }); + }, + + + + + + ////////////////////////////////////////////////////////////////////////////////////////// + // + // PROJECTS + // + ////////////////////////////////////////////////////////////////////////////////////////// + + /** + * Lists the projects. + * + * @param pagination + * + * @chained project map + */ + listProjects: function(pagination) + { + const params = {}; + if (pagination) + { + Gitana.copyInto(params, pagination); + } + + const chainable = this.getFactory().projectMap(this); + return this.chainGet(chainable, "/projects", params); + }, + + /** + * Reads a project. + * + * @param projectId + * + * @chained project + */ + readProject: function(projectId) + { + const chainable = this.getFactory().project(this); + return this.chainGet(chainable, "/projects/" + projectId); + }, + + /** + * Create a project + * + * @chained project + * + * @param {Object} object JSON object + */ + createProject: function(object) + { + if (!object) + { + object = {}; + } + + const chainable = this.getFactory().project(this); + return this.chainCreate(chainable, object, "/projects"); + }, + + /** + * Create a project asynchronously. + * This runs a background job to do the actual project creation and hands back a job ID. + * + * @chained project + * + * @param {Object} object JSON object + * @param {Object} params request parameters + * @param callback + */ + startCreateProject: function(object, params, callback) + { + const uriFunction = function() + { + return "/projects/start"; + }; + + if (!object) + { + object = {}; + } + + if (!params) + { + params = {}; + } + + return this.chainPostResponse(this, uriFunction, params, object).then(function(response) { + + const jobId = response._doc; + + callback(jobId); + }); + }, + + /** + * Queries for projects. + * + * @chained project map + * + * @param {Object} query + * @param {Object} pagination pagination (optional) + */ + queryProjects: function(query, pagination) + { + const params = {}; + if (pagination) + { + Gitana.copyInto(params, pagination); + } + + const uriFunction = function() + { + return "/projects/query"; + }; + + const chainable = this.getFactory().projectMap(this); + return this.chainPost(chainable, uriFunction, params, query); + }, + + /** + * Performs a bulk check of permissions against permissioned objects of type project. + * + * Example of checks array: + * + * [{ + * "permissionedId": "", + * "principalId": "", + * "permissionId": "" + * }] + * + * The callback receives an array of results, example: + * + * [{ + * "permissionedId": "", + * "principalId": "", + * "permissionId": "", + * "result": true + * }] + * + * The order of elements in the array will be the same for checks and results. + * + * @param checks + * @param callback + */ + checkProjectPermissions: function(checks, callback) + { + const uriFunction = function() + { + return "/projects/permissions/check"; + }; + + const object = { + "checks": checks + }; + + return this.chainPostResponse(this, uriFunction, {}, object).then(function(response) { + callback.call(this, response["results"]); + }); + }, + + /** + * Performs a bulk check of authorities against permissioned objects of type project. + * + * Example of checks array: + * + * [{ + * "permissionedId": "", + * "principalId": "", + * "authorityId": "" + * }] + * + * The callback receives an array of results, example: + * + * [{ + * "permissionedId": "", + * "principalId": "", + * "authorityId": "", + * "result": true + * }] + * + * The order of elements in the array will be the same for checks and results. + * + * @param checks + * @param callback + */ + checkProjectAuthorities: function(checks, callback) + { + const uriFunction = function() + { + return "/projects/authorities/check"; + }; + + const object = { + "checks": checks + }; + + return this.chainPostResponse(this, uriFunction, {}, object).then(function(response) { + callback.call(this, response["results"]); + }); + }, + + ///////////////////////////////////////////////////////////////////////////////////////////////// + // + // PROJECT TYPES + // + ///////////////////////////////////////////////////////////////////////////////////////////////// + + /** + * Lists the project types available for this platform. + * + * @chained project type map + * + * @param {Object} pagination pagination (optional) + */ + listProjectTypes: function(pagination) + { + // prepare params (with pagination) + const params = {}; + if (pagination) + { + Gitana.copyInto(params, pagination); + } + + const chainable = this.getFactory().projectMap(this); + return this.chainGet(chainable, "/projecttypes", params); + }, + + + + + + ////////////////////////////////////////////////////////////////////////////////////////// + // + // LOGS + // + ////////////////////////////////////////////////////////////////////////////////////////// + + /** + * Queries for log entries. + * + * @chained log entry map + * + * @param {Object} query Query for finding log entries. + * @param {Object} pagination pagination (optional) + */ + queryLogEntries: function(query, pagination) + { + const self = this; + + const uriFunction = function() + { + return self.getUri() + "/logs/query"; + }; + + if (!query) + { + query = {}; + } + + const chainable = this.getFactory().logEntryMap(this.getCluster()); + + // prepare params (with pagination) + const params = {}; + if (pagination) + { + Gitana.copyInto(params, pagination); + } + + return this.chainPost(chainable, uriFunction, params, query); + }, + + /** + * Read a log entry. + * + * @chained log entry + * + * @param {String} logEntryId + */ + readLogEntry: function(logEntryId) + { + const self = this; + + const uriFunction = function() + { + return self.getUri() + "/logs/" + logEntryId; + }; + + const chainable = this.getFactory().logEntry(this.getCluster()); + + return this.chainGet(chainable, uriFunction); + }, + + /** + * Reads the last 100 lines of the log as text. + * The callback receives the text as the argument. + * + * @param callback + */ + readLog: function(callback) + { + const uriFunction = function () { + return "/logs/logfile"; + }; + + return this.chainGetResponseText(this, uriFunction).then(function(text) { + callback.call(this, text); + }); + }, + + /** + * Creates and reads back a log entry. + * + * @param message + * @param level + * @param obj + */ + createLogEntry: function(message, level, obj) + { + + if (!obj) { + obj = {}; + } + obj.message = message; + obj.level = level; + + const chainable = this.getFactory().logEntry(this.getCluster()); + return this.chainCreate(chainable, obj, "/logs"); + }, + + /** + * Performs a blind post create of a log entry. The result is not read back nor handled. + * + * @param message + * @param level + * @param obj + */ + postLogEntry: function(message, level, obj) + { + const self = this; + + const uriFunction = function() + { + return self.getUri() + "/logs"; + }; + + if (!obj) { + obj = {}; + } + obj.message = message; + obj.level = level; + + return this.chainPostEmpty(null, uriFunction, {}, obj, "application/json"); + }, + + + ///////////////////////////////////////////////////////////////////////////////////////////////// + // + // REGISTRARS + // + ///////////////////////////////////////////////////////////////////////////////////////////////// + + /** + * Lists registrars. + * + * @chained registrar map + * + * @param {Object} pagination pagination (optional) + */ + listRegistrars: function(pagination) + { + // prepare params (with pagination) + const params = {}; + if (pagination) + { + Gitana.copyInto(params, pagination); + } + + const chainable = this.getFactory().registrarMap(this); + return this.chainGet(chainable, "/registrars", params); + }, + + /** + * Read a registrar. + * + * @chained registrar + * + * @param {String} registrarId the registrar id + */ + readRegistrar: function(registrarId) + { + const chainable = this.getFactory().registrar(this); + return this.chainGet(chainable, "/registrars/" + registrarId); + }, + + /** + * Create a registrar + * + * @chained registrar + * + * @param {Object} object JSON object + */ + createRegistrar: function(object) + { + const chainable = this.getFactory().registrar(this); + return this.chainCreate(chainable, object, "/registrars"); + }, + + /** + * Queries for a registrar. + * + * @chained registrar map + * + * @param {Object} query Query for finding a vault. + * @param {Object} pagination pagination (optional) + */ + queryRegistrars: function(query, pagination) + { + const chainable = this.getFactory().registrarMap(this); + + // prepare params (with pagination) + const params = {}; + if (pagination) + { + Gitana.copyInto(params, pagination); + } + + return this.chainPost(chainable, "/registrars/query", params, query); + }, + + /** + * Performs a bulk check of permissions against permissioned objects of type vault. + * + * Example of checks array: + * + * [{ + * "permissionedId": "", + * "principalId": "", + * "permissionId": "" + * }] + * + * The callback receives an array of results, example: + * + * [{ + * "permissionedId": "", + * "principalId": "", + * "permissionId": "", + * "result": true + * }] + * + * The order of elements in the array will be the same for checks and results. + * + * @param checks + * @param callback + */ + checkRegistrarPermissions: function(checks, callback) + { + const uriFunction = function() + { + return "/registrars/permissions/check"; + }; + + const object = { + "checks": checks + }; + + return this.chainPostResponse(this, uriFunction, {}, object).then(function(response) { + callback.call(this, response["results"]); + }); + }, + + /** + * Performs a bulk check of authorities against permissioned objects of type vault. + * + * Example of checks array: + * + * [{ + * "permissionedId": "", + * "principalId": "", + * "authorityId": "" + * }] + * + * The callback receives an array of results, example: + * + * [{ + * "permissionedId": "", + * "principalId": "", + * "authorityId": "", + * "result": true + * }] + * + * The order of elements in the array will be the same for checks and results. + * + * @param checks + * @param callback + */ + checkRegistrarAuthorities: function(checks, callback) + { + const uriFunction = function() + { + return "/registrars/authorities/check"; + }; + + const object = { + "checks": checks + }; + + return this.chainPostResponse(this, uriFunction, {}, object).then(function(response) { + callback.call(this, response["results"]); + }); + }, + + + + ///////////////////////////////////////////////////////////////////////////////////////////////// + // + // APPLICATIONS + // + ///////////////////////////////////////////////////////////////////////////////////////////////// + + /** + * Lists applications. + * + * @chained application map + * + * @param {Object} pagination pagination (optional) + */ + listApplications: function(pagination) + { + // prepare params (with pagination) + const params = {}; + if (pagination) + { + Gitana.copyInto(params, pagination); + } + + const chainable = this.getFactory().applicationMap(this); + return this.chainGet(chainable, "/applications", params); + }, + + /** + * Read an application. + * + * @chained application + * + * @param {String} applicationId the application id + */ + readApplication: function(applicationId) + { + const uriFunction = function() { + return "/applications/" + applicationId; + }; + + const chainable = this.getFactory().application(this); + return this.chainGet(chainable, uriFunction); + }, + + /** + * Create an application + * + * @chained application + * + * @param {Object} object JSON object + */ + createApplication: function(object) + { + const chainable = this.getFactory().application(this); + return this.chainCreate(chainable, object, "/applications"); + }, + + /** + * Queries for an application. + * + * @chained application map + * + * @param {Object} query Query for finding a vault. + * @param {Object} pagination pagination (optional) + */ + queryApplications: function(query, pagination) + { + const chainable = this.getFactory().applicationMap(this); + + // prepare params (with pagination) + const params = {}; + if (pagination) + { + Gitana.copyInto(params, pagination); + } + + return this.chainPost(chainable, "/applications/query", params, query); + }, + + /** + * Performs a bulk check of permissions against permissioned objects of type vault. + * + * Example of checks array: + * + * [{ + * "permissionedId": "", + * "principalId": "", + * "permissionId": "" + * }] + * + * The callback receives an array of results, example: + * + * [{ + * "permissionedId": "", + * "principalId": "", + * "permissionId": "", + * "result": true + * }] + * + * The order of elements in the array will be the same for checks and results. + * + * @param checks + * @param callback + */ + checkApplicationPermissions: function(checks, callback) + { + const uriFunction = function() + { + return "/applications/permissions/check"; + }; + + const object = { + "checks": checks + }; + + return this.chainPostResponse(this, uriFunction, {}, object).then(function(response) { + callback.call(this, response["results"]); + }); + }, + + /** + * Performs a bulk check of authorities against permissioned objects of type vault. + * + * Example of checks array: + * + * [{ + * "permissionedId": "", + * "principalId": "", + * "authorityId": "" + * }] + * + * The callback receives an array of results, example: + * + * [{ + * "permissionedId": "", + * "principalId": "", + * "authorityId": "", + * "result": true + * }] + * + * The order of elements in the array will be the same for checks and results. + * + * @param checks + * @param callback + */ + checkApplicationAuthorities: function(checks, callback) + { + const uriFunction = function() + { + return "/applications/authorities/check"; + }; + + const object = { + "checks": checks + }; + + return this.chainPostResponse(this, uriFunction, {}, object).then(function(response) { + callback.call(this, response["results"]); + }); + }, + + ///////////////////////////////////////////////////////////////////////////////////////////////// + // + // APPLICATION TYPES + // + ///////////////////////////////////////////////////////////////////////////////////////////////// + + /** + * Lists the application types available for this platform. + * + * @chained application type map + * + * @param {Object} pagination pagination (optional) + */ + listApplicationTypes: function(pagination) + { + // prepare params (with pagination) + const params = {}; + if (pagination) + { + Gitana.copyInto(params, pagination); + } + + const chainable = this.getFactory().applicationMap(this); + return this.chainGet(chainable, "/applicationtypes", params); + }, + + + + + ////////////////////////////////////////////////////////////////////////////////////////// + // + // CLIENTS + // + ////////////////////////////////////////////////////////////////////////////////////////// + + /** + * Lists the clients. + * + * @param pagination + * + * @chained client map + */ + listClients: function(pagination) + { + const params = {}; + if (pagination) + { + Gitana.copyInto(params, pagination); + } + + const chainable = this.getFactory().clientMap(this); + return this.chainGet(chainable, "/clients", params); + }, + + /** + * Reads a client. + * + * @param clientId + * + * @chained client + */ + readClient: function(clientId) + { + const chainable = this.getFactory().client(this); + return this.chainGet(chainable, "/clients/" + clientId); + }, + + /** + * Create a client + * + * @chained client + * + * @param {Object} object JSON object + */ + createClient: function(object) + { + if (!object) + { + object = {}; + } + + const chainable = this.getFactory().client(this); + return this.chainCreate(chainable, object, "/clients"); + }, + + /** + * Queries for clients. + * + * @chained client map + * + * @param {Object} query + * @param {Object} pagination pagination (optional) + */ + queryClients: function(query, pagination) + { + const params = {}; + if (pagination) + { + Gitana.copyInto(params, pagination); + } + + const uriFunction = function() + { + return "/clients/query"; + }; + + const chainable = this.getFactory().clientMap(this); + return this.chainPost(chainable, uriFunction, params, query); + }, + + /** + * Performs a bulk check of permissions against permissioned objects of type client. + * + * Example of checks array: + * + * [{ + * "permissionedId": "", + * "principalId": "", + * "permissionId": "" + * }] + * + * The callback receives an array of results, example: + * + * [{ + * "permissionedId": "", + * "principalId": "", + * "permissionId": "", + * "result": true + * }] + * + * The order of elements in the array will be the same for checks and results. + * + * @param checks + * @param callback + */ + checkClientPermissions: function(checks, callback) + { + const uriFunction = function() + { + return "/clients/permissions/check"; + }; + + const object = { + "checks": checks + }; + + return this.chainPostResponse(this, uriFunction, {}, object).then(function(response) { + callback.call(this, response["results"]); + }); + }, + + /** + * Performs a bulk check of authorities against permissioned objects of type client. + * + * Example of checks array: + * + * [{ + * "permissionedId": "", + * "principalId": "", + * "authorityId": "" + * }] + * + * The callback receives an array of results, example: + * + * [{ + * "permissionedId": "", + * "principalId": "", + * "authorityId": "", + * "result": true + * }] + * + * The order of elements in the array will be the same for checks and results. + * + * @param checks + * @param callback + */ + checkClientAuthorities: function(checks, callback) + { + const uriFunction = function() + { + return "/clients/authorities/check"; + }; + + const object = { + "checks": checks + }; + + return this.chainPostResponse(this, uriFunction, {}, object).then(function(response) { + callback.call(this, response["results"]); + }); + }, + + ////////////////////////////////////////////////////////////////////////////////////////// + // + // ACCESS POLICIES + // + ////////////////////////////////////////////////////////////////////////////////////////// + + /** + * Reads an access policy. + * + * @param {String} accessPolicyId + * + * @chained accessPolicy + */ + readAccessPolicy: function(accessPolicyId) + { + const chainable = this.getFactory().accessPolicy(this); + return this.chainGet(chainable, "/access/policies/" + accessPolicyId); + }, + + /** + * Create an Access Policy + * + * @param {Object} object + * + * @chained accessPolicy + */ + createAccessPolicy: function(object) + { + if (!object) + { + object = {}; + } + + const chainable = this.getFactory().accessPolicy(this); + return this.chainCreate(chainable, object, "/access/policies"); + }, + + /** + * List all Access Policies in the platform. + * + * @param {Object} pagination + * + * @chained accessPolicyMap + */ + listAccessPolicies: function(pagination) + { + const params = {}; + if (pagination) + { + Gitana.copyInto(params, pagination); + } + + params.clientId = this.getId(); + + const chainable = this.getFactory().accessPolicyMap(this.getPlatform()); + return this.chainGet(chainable, "/access/policies", params); + }, + + /** + * Query for Access Policies. + * + * @param {Object} query + * @param {Object} pagination + * + * @chained accessPolicyMap + */ + queryAccessPolicies: function(query, pagination) + { + const params = {}; + if (pagination) + { + Gitana.copyInto(params, pagination); + } + + const chainable = this.getFactory().accessPolicyMap(this.getPlatform()); + return this.chainPost(chainable, "/access/policies/query", params, query); + }, + + /** + * Finds Access Policies bound to a particular resource. + * + * @param {String} ref + * @param {Object} pagination + * + * @chained accessPolicyMap + */ + findAccessPolicies: function(ref, pagination) + { + const params = {}; + params.ref = ref; + + if (pagination) + { + Gitana.copyInto(params, pagination); + } + + const chainable = this.getFactory().accessPolicyMap(this.getPlatform()); + return this.chainPost(chainable, "/access/policies/find", params); + }, + + /** + * Lists target documents bound to a particular Access Policy. + * + * @param {String} accessPolicyId + * @param {Object} pagination + */ + listAccessPolicyTargets: function(accessPolicyId, pagination) + { + const params = {}; + params.accessPolicyId = accessPolicyId; + + if (pagination) + { + Gitana.copyInto(params, pagination); + } + + const uri = "/access/policies/" + accessPolicyId + "/targets"; + + const chainable = this.getFactory().accessPolicyMap(this.getPlatform()); + return this.chainGet(chainable, uri, params); + }, + + /** + * Assign an access policy to a particular resource. + * + * @param {String} accessPolicyId + * @param {String} ref + */ + assignAccessPolicy: function(accessPolicyId, ref) + { + const params = {}; + params.ref = ref; + + const uri = "/access/policies/" + accessPolicyId + "/assign"; + + const chainable = this.getFactory().accessPolicyMap(this.getPlatform()); + return this.chainPost(chainable, uri, params); + }, + + /** + * Unassign an access policy from a particular resource. + * + * @param {String} accessPolicyId + * @param {String} ref + */ + unassignAccessPolicy: function(accessPolicyId, ref) + { + const params = {}; + params.ref = ref; + + const uri = "/access/policies/" + accessPolicyId + "/unassign"; + + const chainable = this.getFactory().accessPolicyMap(this.getPlatform()); + return this.chainPost(chainable, uri, params); + }, + + /** + * Unassign all access policies from a particular resource. + * + * @param {String} ref + */ + unassignAllAccessPolicies: function(ref) + { + const params = {}; + params.ref = ref; + + const chainable = this.getFactory().accessPolicyMap(this.getPlatform()); + return this.chainPost(chainable, "/access/policies/unassignall", params); + }, + + ////////////////////////////////////////////////////////////////////////////////////////// + // + // AUTHENTICATION GRANTS + // + ////////////////////////////////////////////////////////////////////////////////////////// + + /** + * Reads an authentication grant. + * + * @param authenticationGrantId + * + * @chained authentication grant + */ + readAuthenticationGrant: function(authenticationGrantId) + { + const chainable = this.getFactory().authenticationGrant(this); + return this.chainGet(chainable, "/auth/grants/" + authenticationGrantId); + }, + + /** + * Create an authentication grant + * + * @chained authentication grant + * + * @param {Object} object JSON object + */ + createAuthenticationGrant: function(object) + { + if (!object) + { + object = {}; + } + + const chainable = this.getFactory().authenticationGrant(this); + return this.chainCreate(chainable, object, "/auth/grants"); + }, + + /** + * Queries for authentication grants. + * + * @chained authentication grant map + * + * @param {Object} query + * @param {Object} pagination pagination (optional) + */ + queryAuthenticationGrants: function(query, pagination) + { + const params = {}; + if (pagination) + { + Gitana.copyInto(params, pagination); + } + + const uriFunction = function() + { + return "/auth/grants/query"; + }; + + const chainable = this.getFactory().authenticationGrantMap(this); + return this.chainPost(chainable, uriFunction, params, query); + }, + + /** + * Performs a bulk check of permissions against permissioned objects of type authentication grant. + * + * Example of checks array: + * + * [{ + * "permissionedId": "", + * "principalId": "", + * "permissionId": "" + * }] + * + * The callback receives an array of results, example: + * + * [{ + * "permissionedId": "", + * "principalId": "", + * "permissionId": "", + * "result": true + * }] + * + * The order of elements in the array will be the same for checks and results. + * + * @param checks + * @param callback + */ + checkAuthenticationGrantPermissions: function(checks, callback) + { + const uriFunction = function() + { + return "/auth/grants/permissions/check"; + }; + + const object = { + "checks": checks + }; + + return this.chainPostResponse(this, uriFunction, {}, object).then(function(response) { + callback.call(this, response["results"]); + }); + }, + + /** + * Performs a bulk check of authorities against permissioned objects of type authentication grant. + * + * Example of checks array: + * + * [{ + * "permissionedId": "", + * "principalId": "", + * "authorityId": "" + * }] + * + * The callback receives an array of results, example: + * + * [{ + * "permissionedId": "", + * "principalId": "", + * "authorityId": "", + * "result": true + * }] + * + * The order of elements in the array will be the same for checks and results. + * + * @param checks + * @param callback + */ + checkAuthenticationGrantAuthorities: function(checks, callback) + { + const uriFunction = function() + { + return "/auth/grants/authorities/check"; + }; + + const object = { + "checks": checks + }; + + return this.chainPostResponse(this, uriFunction, {}, object).then(function(response) { + callback.call(this, response["results"]); + }); + }, + + + + ///////////////////////////////////////////////////////////////////////////////////////////////// + // + // DIRECTORIES + // + ///////////////////////////////////////////////////////////////////////////////////////////////// + + /** + * Lists directories. + * + * @chained directory map + * + * @param {Object} pagination pagination (optional) + */ + listDirectories: function(pagination) + { + // prepare params (with pagination) + const params = {}; + if (pagination) + { + Gitana.copyInto(params, pagination); + } + + const chainable = this.getFactory().directoryMap(this); + return this.chainGet(chainable, "/directories", params); + }, + + /** + * Read a directory. + * + * @chained directory + * + * @param {String} directoryId the directory id + */ + readDirectory: function(directoryId) + { + const chainable = this.getFactory().directory(this); + return this.chainGet(chainable, "/directories/" + directoryId); + }, + + /** + * Create a directory. + * + * @chained directory + * + * @param {Object} object JSON object + */ + createDirectory: function(object) + { + const chainable = this.getFactory().directory(this); + return this.chainCreate(chainable, object, "/directories"); + }, + + /** + * Queries for a directory. + * + * @chained directory map + * + * @param {Object} query Query for finding a directory. + * @param {Object} pagination pagination (optional) + */ + queryDirectories: function(query, pagination) + { + const chainable = this.getFactory().directoryMap(this); + + // prepare params (with pagination) + const params = {}; + if (pagination) + { + Gitana.copyInto(params, pagination); + } + + return this.chainPost(chainable, "/directories/query", params, query); + }, + + /** + * Performs a bulk check of permissions against permissioned objects of type directory. + * + * Example of checks array: + * + * [{ + * "permissionedId": "", + * "principalId": "", + * "permissionId": "" + * }] + * + * The callback receives an array of results, example: + * + * [{ + * "permissionedId": "", + * "principalId": "", + * "permissionId": "", + * "result": true + * }] + * + * The order of elements in the array will be the same for checks and results. + * + * @param checks + * @param callback + */ + checkDirectoryPermissions: function(checks, callback) + { + const uriFunction = function() + { + return "/directories/permissions/check"; + }; + + const object = { + "checks": checks + }; + + return this.chainPostResponse(this, uriFunction, {}, object).then(function(response) { + callback.call(this, response["results"]); + }); + }, + + /** + * Performs a bulk check of authorities against permissioned objects of type directory. + * + * Example of checks array: + * + * [{ + * "permissionedId": "", + * "principalId": "", + * "authorityId": "" + * }] + * + * The callback receives an array of results, example: + * + * [{ + * "permissionedId": "", + * "principalId": "", + * "authorityId": "", + * "result": true + * }] + * + * The order of elements in the array will be the same for checks and results. + * + * @param checks + * @param callback + */ + checkDirectoryAuthorities: function(checks, callback) + { + const uriFunction = function() + { + return "/directories/authorities/check"; + }; + + const object = { + "checks": checks + }; + + return this.chainPostResponse(this, uriFunction, {}, object).then(function(response) { + callback.call(this, response["results"]); + }); + }, + + + + + ////////////////////////////////////////////////////////////////////////////////////////// + // + // BILLING PROVIDER CONFIGURATIONS + // + ////////////////////////////////////////////////////////////////////////////////////////// + + /** + * Lists the billing provider configurations. + * + * @param pagination + * + * @chained billing provider configuration map + */ + listBillingProviderConfigurations: function(pagination) + { + const params = {}; + if (pagination) + { + Gitana.copyInto(params, pagination); + } + + const chainable = this.getFactory().billingProviderConfigurationMap(this); + return this.chainGet(chainable, "/billing/configurations", params); + }, + + /** + * Reads a billing provider configuration. + * + * @param billingProviderConfigurationId + * + * @chained billing provider configuration + */ + readBillingProviderConfiguration: function(billingProviderConfigurationId) + { + const chainable = this.getFactory().billingProviderConfiguration(this); + return this.chainGet(chainable, "/billing/configurations/" + billingProviderConfigurationId); + }, + + /** + * Create a billing provider configuration. + * + * @chained billing provider configuration + * + * @param {String} providerId + * @param {Object} object JSON object + */ + createBillingProviderConfiguration: function(providerId, object) + { + if (!object) + { + object = {}; + } + object["providerId"] = providerId; + + const chainable = this.getFactory().billingProviderConfiguration(this); + return this.chainCreate(chainable, object, "/billing/configurations"); + }, + + /** + * Queries for billing provider configurations. + * + * @chained billing provider configuration map + * + * @param {Object} query + * @param {Object} pagination pagination (optional) + */ + queryBillingProviderConfigurations: function(query, pagination) + { + const params = {}; + if (pagination) + { + Gitana.copyInto(params, pagination); + } + + const uriFunction = function() + { + return "/billing/configurations/query"; + }; + + const chainable = this.getFactory().billingProviderConfigurationMap(this); + return this.chainPost(chainable, uriFunction, params, query); + }, + + /** + * Performs a bulk check of permissions against permissioned objects of type billing provider configuration. + * + * Example of checks array: + * + * [{ + * "permissionedId": "", + * "principalId": "", + * "permissionId": "" + * }] + * + * The callback receives an array of results, example: + * + * [{ + * "permissionedId": "", + * "principalId": "", + * "permissionId": "", + * "result": true + * }] + * + * The order of elements in the array will be the same for checks and results. + * + * @param checks + * @param callback + */ + checkBillingProviderConfigurationPermissions: function(checks, callback) + { + const uriFunction = function() + { + return "/billing/configurations/permissions/check"; + }; + + const object = { + "checks": checks + }; + + return this.chainPostResponse(this, uriFunction, {}, object).then(function(response) { + callback.call(this, response["results"]); + }); + }, + + /** + * Performs a bulk check of authorities against permissioned objects of type billing provider configuration. + * + * Example of checks array: + * + * [{ + * "permissionedId": "", + * "principalId": "", + * "authorityId": "" + * }] + * + * The callback receives an array of results, example: + * + * [{ + * "permissionedId": "", + * "principalId": "", + * "authorityId": "", + * "result": true + * }] + * + * The order of elements in the array will be the same for checks and results. + * + * @param checks + * @param callback + */ + checkBillingProviderConfigurationAuthorities: function(checks, callback) + { + const uriFunction = function() + { + return "/billing/configurations/authorities/check"; + }; + + const object = { + "checks": checks + }; + + return this.chainPostResponse(this, uriFunction, {}, object).then(function(response) { + callback.call(this, response["results"]); + }); + }, + + + ///////////////////////////////////////////////////////////////////////////////////////////////// + // + // WEB HOSTS + // + ///////////////////////////////////////////////////////////////////////////////////////////////// + + /** + * Lists web hosts. + * + * @chained web host map + * + * @param {Object} pagination pagination (optional) + */ + listWebHosts: function(pagination) + { + // prepare params (with pagination) + const params = {}; + if (pagination) + { + Gitana.copyInto(params, pagination); + } + + const chainable = this.getFactory().webhostMap(this); + return this.chainGet(chainable, "/webhosts", params); + }, + + /** + * Read a web host + * + * @chained web host + * + * @param {String} webhostId the web host id + */ + readWebHost: function(webhostId) + { + const chainable = this.getFactory().webhost(this); + return this.chainGet(chainable, "/webhosts/" + webhostId); + }, + + /** + * Create a web host. + * + * @chained web host + * + * @param {Object} object JSON object + */ + createWebHost: function(object) + { + const chainable = this.getFactory().webhost(this); + return this.chainCreate(chainable, object, "/webhosts"); + }, + + /** + * Queries for web hosts. + * + * @chained web host map + * + * @param {Object} query Query for finding web hosts. + * @param {Object} pagination pagination (optional) + */ + queryWebHosts: function(query, pagination) + { + const chainable = this.getFactory().webhostMap(this); + + // prepare params (with pagination) + const params = {}; + if (pagination) + { + Gitana.copyInto(params, pagination); + } + + return this.chainPost(chainable, "/webhosts/query", params, query); + }, + + /** + * Performs a bulk check of permissions against permissioned objects of type web host. + * + * Example of checks array: + * + * [{ + * "permissionedId": "", + * "principalId": "", + * "permissionId": "" + * }] + * + * The callback receives an array of results, example: + * + * [{ + * "permissionedId": "", + * "principalId": "", + * "permissionId": "", + * "result": true + * }] + * + * The order of elements in the array will be the same for checks and results. + * + * @param checks + * @param callback + */ + checkWebHostPermissions: function(checks, callback) + { + const uriFunction = function() + { + return "/webhosts/permissions/check"; + }; + + const object = { + "checks": checks + }; + + return this.chainPostResponse(this, uriFunction, {}, object).then(function(response) { + callback.call(this, response["results"]); + }); + }, + + /** + * Performs a bulk check of authorities against permissioned objects of type web host. + * + * Example of checks array: + * + * [{ + * "permissionedId": "", + * "principalId": "", + * "authorityId": "" + * }] + * + * The callback receives an array of results, example: + * + * [{ + * "permissionedId": "", + * "principalId": "", + * "authorityId": "", + * "result": true + * }] + * + * The order of elements in the array will be the same for checks and results. + * + * @param checks + * @param callback + */ + checkWebHostAuthorities: function(checks, callback) + { + const uriFunction = function() + { + return "/webhosts/authorities/check"; + }; + + const object = { + "checks": checks + }; + + return this.chainPostResponse(this, uriFunction, {}, object).then(function(response) { + callback.call(this, response["results"]); + }); + }, + + + + ////////////////////////////////////////////////////////////////////////////////////////////////////// + // + // CURRENT TENANT ATTACHMENTS + // + ////////////////////////////////////////////////////////////////////////////////////////////////////// + + /** + * Hands back a map of attachments for the platform's parent tenant. + * + * @chained attachment map + * + * @public + */ + listTenantAttachments: function() + { + const self = this; + + // we bind the attachment map to a modified copy of platform with the URI adjusted + // so that it forms "/tenant/attachments/" for any lookups + const pseudoTenant = this.clone(); + pseudoTenant.getUri = function () { + return "/tenant"; + }; + + const result = this.subchain(new Gitana.BinaryAttachmentMap(pseudoTenant)); + result.then(function() { + + const chain = this; + + self.getDriver().gitanaGet(self.getUri() + "/tenant/attachments", null, {}, function(response) { + chain.handleResponse(response); + chain.next(); + }); + + return false; + }); + + return result; + }, + + /** + * Picks off a single attachment from this platform's parent tenant + * + * @chained attachment + * + * @param attachmentId + */ + tenantAttachment: function(attachmentId) + { + return this.listTenantAttachments().select(attachmentId); + }, + + /** + * Creates an attachment to this platform's parent tenant. + * + * When using this method from within the JS driver, it really only works for text-based content such + * as JSON or text. + * + * @chained attachment + * + * @param attachmentId (use null or false for default attachment) + * @param contentType + * @param data + */ + tenantAttach: function(attachmentId, contentType, data) + { + const self = this; + + const tenant = this.clone(); + tenant.getUri = function () { + return "/tenant"; + }; + + // the thing we're handing back + const result = this.subchain(new Gitana.BinaryAttachment(tenant)); + + // preload some work onto a subchain + result.subchain().then(function() { + + // upload the attachment + const uploadUri = self.getUri() + "/tenant/attachments/" + attachmentId; + this.chainUpload(this, uploadUri, null, contentType, data).then(function() { + + // read back attachment information and plug onto result + this.subchain(self).listTenantAttachments().then(function() { + this.select(attachmentId).then(function() { + result.handleResponse(this); + }); + }); + }); + }); + + return result; + }, + + /** + * Deletes an attachment from this platform's parent tenant. + * + * @param attachmentId + */ + tenantUnattach: function(attachmentId) + { + return this.subchain().then(function() { + + this.chainDelete(this, this.getUri() + "/tenant/attachments/" + attachmentId).then(function() { + + // TODO + + }); + }); + }, + + /** + * Generates a URI to a preview resource. + */ + getTenantPreviewUri: Gitana.Methods.getPreviewUri("tenant/preview"), + + + /** + * Connects to a specific application on the platform. Preloads any application data and stack information + * and then fires into a callback with context set to application helper. + * + * @param settings + * @param callback + */ + app: function(settings, callback) + { + const self = this; + + // support for null appkey + if (Gitana.isFunction(settings)) { + callback = settings; + settings = null; + } + + if (Gitana.isString(settings)) { + settings = { "application": settings }; + } + + // build preload config + const config = { + "application": null, + "appCacheKey": null + }; + Gitana.copyKeepers(config, Gitana.loadDefaultConfig()); + Gitana.copyKeepers(config, self.getDriver().getOriginalConfiguration()); + Gitana.copyKeepers(config, settings); + + // is this app context already cached? + const cacheKey = config.appCacheKey; + if (cacheKey) + { + if (Gitana.APPS && Gitana.APPS[cacheKey]) + { + return callback.call(Chain(Gitana.APPS[cacheKey])); + } + } + + if (!config.application) { + callback.call(self, new Error("No application configured")); + return; + } + + // load and cache + const helper = new Gitana.AppHelper(self, config); + if (!Gitana.APPS) { + Gitana.APPS = {}; + } + + helper.init.call(helper, function(err) { + + if (err) + { + callback(err); + return; + } + + if (cacheKey) + { + Gitana.APPS[cacheKey] = helper; + } + + callback.call(Chain(helper)); + }); + }, + + + + /** + * Retrieves authorities and permissions for multiple reference/principal combinations. + * + * Example of entries array: + * + * [{ + * "permissioned": "", + * "principalId": "" + * }] + * + * The callback receives an array of results, example: + * + * [{ + * "permissioned": "", + * "principalId": "", + * "authorities": [...], + * "permissions": [...] + * }] + * + * The order of elements in the array will be the same for checks and results. + * + * @param entries + * @param callback + */ + accessLookups: function(entries, callback) + { + const uriFunction = function() + { + return "/access/lookup"; + }; + + const object = { + "entries": entries + }; + + return this.chainPostResponse(this, uriFunction, {}, object).then(function(response) { + callback.call(this, response["entries"]); + }); + }, + + /** + * Retrieves authorities and permissions for multiple reference/principal combinations. + * + * Example of entries array: + * + * [{ + * "permissioned": "", + * "principalId": "" + * }] + * + * The callback receives an array of results, example: + * + * [{ + * "permissioned": "", + * "principalId": "", + * "permissionId|authorityId": "", + * "hasPermission|hasAuthority": true | false + * }] + * + * The order of elements in the array will be the same for checks and results. + * + * @param entries + * @param callback + */ + accessChecks: function(entries, callback) + { + const uriFunction = function() + { + return "/access/check"; + }; + + const object = { + "entries": entries + }; + + return this.chainPostResponse(this, uriFunction, {}, object).then(function(response) { + callback.call(this, response["entries"]); + }); + }, + + /** + * Reads one or more referenceable objects by reference id. + * + * Example of entries array: + * + * [{ + * "ref": "" + * }] + * + * The callback receives an array of results, example: + * + * [{ + * "ref": "", + * "entry": { ... object } + * }] + * + * The order of elements in the array will be the same for checks and results. + * + * @param entries + * @param callback + */ + referenceReads: function(entries, callback) + { + const uriFunction = function() + { + return "/ref/read"; + }; + + const object = { + "entries": entries + }; + + return this.chainPostResponse(this, uriFunction, {}, object).then(function(response) { + callback.call(this, response["entries"]); + }); + }, + + /** + * Calculates the JSON Patch diff between two objects. + * + * @param sourceRef + * @param targetRef + * + * @param callback + */ + referenceDiff: function(sourceRef, targetRef, callback) + { + const uriFunction = function() + { + return "/ref/diff"; + }; + + const params = { + "source": sourceRef, + "target": targetRef + }; + + return this.chainGetResponse(this, uriFunction, params).then(function(response) { + callback.call(this, response); + }); + }, + + /** + * Applies a JSON Patch to an object to produce a patched object. + * + * @param sourceRef + * @param diffObject + * + * @param callback + */ + referenceMerge: function(sourceRef, diffObject, callback) + { + const uriFunction = function() + { + return "/ref/merge"; + }; + + const params = { + "source": sourceRef + }; + + return this.chainPostResponse(this, uriFunction, params, diffObject).then(function(response) { + callback.call(this, response); + }); + }, + + /////////////////////////////////////////////////////////////////////////////////////////////////////// + // + // ADMIN + // + /////////////////////////////////////////////////////////////////////////////////////////////////////// + + adminIndexDatastores: function() + { + const self = this; + + return this.then(function() { + + const chain = this; + + // call + const uri = self.getUri() + "/admin/index"; + self.getDriver().gitanaPost(uri, null, {}, function() { + chain.next(); + }); + + // NOTE: we return false to tell the chain that we'll manually call next() + return false; + }); + }, + + adminRepair: function() + { + const self = this; + + return this.then(function() { + + const chain = this; + + // call + const uri = self.getUri() + "/admin/repair"; + self.getDriver().gitanaPost(uri, null, {}, function() { + chain.next(); + }); + + // NOTE: we return false to tell the chain that we'll manually call next() + return false; + }); + }, + + + ////////////////////////////////////////////////////////////////////////////////////////// + // + // RULE + // + ////////////////////////////////////////////////////////////////////////////////////////// + + /** + * Lists the available rule actions. + * + * @param pagination + * + * @param callback + * @chained action descriptor map + */ + listRuleActions: function(pagination, callback) + { + const params = {}; + if (pagination) + { + Gitana.copyInto(params, pagination); + } + + const uriFunction = function() + { + return "/rule/actions"; + }; + + return this.chainGetResponse(this, uriFunction, params).then(function(response) { + callback(response); + }); + }, + + /** + * Reads a rule action. + * + * + * @chained a + * @param actionId + * @param callback + */ + readRuleAction: function(actionId, callback) + { + const uriFunction = function() + { + return "/rule/actions/" + actionId; + }; + + return this.chainGetResponse(this, uriFunction, {}).then(function(response) { + callback(response); + }); + }, + + /** + * Lists the available rule conditions. + * + * @param pagination + * + * @param callback + * @chained condition descriptor map + */ + listRuleConditions: function(pagination, callback) + { + const params = {}; + if (pagination) + { + Gitana.copyInto(params, pagination); + } + + const uriFunction = function() + { + return "/rule/conditions"; + }; + + return this.chainGetResponse(this, uriFunction, params).then(function(response) { + callback(response); + }); + }, + + /** + * Reads a rule condition. + * + * @param conditionId + * + * @param callback + * @chained a + */ + readRuleCondition: function(conditionId, callback) + { + const uriFunction = function() + { + return "/rule/conditions/" + conditionId; + }; + + return this.chainGetResponse(this, uriFunction, {}).then(function(response) { + callback(response); + }); + }, + + + + ////////////////////////////////////////////////////////////////////////////////////////// + // + // WORKFLOW MODELS + // + ////////////////////////////////////////////////////////////////////////////////////////// + + /** + * Lists the deployed workflow models. + * + * @param pagination + * + * @chained workflow model map + */ + listWorkflowModels: function(pagination) + { + const params = {}; + if (pagination) + { + Gitana.copyInto(params, pagination); + } + + const chainable = this.getFactory().workflowModelMap(this); + return this.chainGet(chainable, "/workflow/models", params); + }, + + /** + * Lists all workflow models. + * + * @param pagination + * + * @chained workflow model map + */ + listAllWorkflowModels: function(pagination) + { + const params = {}; + if (pagination) + { + Gitana.copyInto(params, pagination); + } + + const chainable = this.getFactory().workflowModelMap(this); + return this.chainGet(chainable, "/workflow/models?all=true", params); + }, + + /** + * Reads a workflow model. + * + * @param {String} workflowModelId + * @param {String} workflowModelVersionId + * + * @chained workflowModel + */ + readWorkflowModel: function(workflowModelId, workflowModelVersionId) + { + const uriFunction = function() + { + let url = "/workflow/models/" + workflowModelId; + if (workflowModelVersionId) + { + url += "/versions/" + workflowModelVersionId; + } + + return url; + }; + + const chainable = this.getFactory().workflowModel(this); + return this.chainGet(chainable, uriFunction); + }, + + /** + * Create a workflow model + * + * @chained workflow model + * + * @param {String} id + * @param {Object} object JSON object + */ + createWorkflowModel: function(id, object) + { + if (!object) + { + object = {}; + } + + object.id = id; + + const chainable = this.getFactory().workflowModel(this); + return this.chainCreate(chainable, object, "/workflow/models"); + }, + + /** + * Queries for deployed workflow models. + * + * @chained workflow model map + * + * @param {Object} query + * @param {Object} pagination pagination (optional) + */ + queryWorkflowModels: function(query, pagination) + { + const params = {}; + if (pagination) + { + Gitana.copyInto(params, pagination); + } + + const uriFunction = function() + { + return "/workflow/models/query"; + }; + + const chainable = this.getFactory().workflowModelMap(this); + return this.chainPost(chainable, uriFunction, params, query); + }, + + /** + * Queries for all (deployed and not deployed) workflow models. + * + * @chained workflow model map + * + * @param {Object} query + * @param {Object} pagination pagination (optional) + */ + queryAllWorkflowModels: function(query, pagination) + { + const params = {}; + if (pagination) + { + Gitana.copyInto(params, pagination); + } + + const uriFunction = function() + { + return "/workflow/models/query?all=true"; + }; + + const chainable = this.getFactory().workflowModelMap(this); + return this.chainPost(chainable, uriFunction, params, query); + }, + + /** + * Performs a bulk check of permissions against permissioned objects of type workflow model. + * + * Example of checks array: + * + * [{ + * "permissionedId": "", + * "principalId": "", + * "permissionId": "" + * }] + * + * The callback receives an array of results, example: + * + * [{ + * "permissionedId": "", + * "principalId": "", + * "permissionId": "", + * "result": true + * }] + * + * The order of elements in the array will be the same for checks and results. + * + * @param checks + * @param callback + */ + checkWorkflowModelPermissions: function(checks, callback) + { + const uriFunction = function() + { + return "/workflow/models/permissions/check"; + }; + + const object = { + "checks": checks + }; + + return this.chainPostResponse(this, uriFunction, {}, object).then(function(response) { + callback.call(this, response["results"]); + }); + }, + + /** + * Performs a bulk check of authorities against permissioned objects of type workflow model. + * + * Example of checks array: + * + * [{ + * "permissionedId": "", + * "principalId": "", + * "authorityId": "" + * }] + * + * The callback receives an array of results, example: + * + * [{ + * "permissionedId": "", + * "principalId": "", + * "authorityId": "", + * "result": true + * }] + * + * The order of elements in the array will be the same for checks and results. + * + * @param checks + * @param callback + */ + checkWorkflowModelAuthorities: function(checks, callback) + { + const uriFunction = function() + { + return "/workflow/models/authorities/check"; + }; + + const object = { + "checks": checks + }; + + return this.chainPostResponse(this, uriFunction, {}, object).then(function(response) { + callback.call(this, response["results"]); + }); + }, + + /** + * Lists the workflow model versions. + * + * @param id + * @param pagination + * + * @chained workflow model map + */ + listWorkflowModelVersions: function(id, pagination) + { + const params = {}; + if (pagination) + { + Gitana.copyInto(params, pagination); + } + + const uriFunction = function() + { + return "/workflow/models/" + id + "/versions"; + }; + + const chainable = this.getFactory().workflowModelMap(this); + return this.chainGet(chainable, uriFunction, params); + }, + + /** + * Queries for workflow model versions. + * + * @chained workflow model map + * + * @param {String} id + * @param {Object} query + * @param {Object} pagination pagination (optional) + */ + queryWorkflowModelVersions: function(id, query, pagination) + { + const params = {}; + if (pagination) + { + Gitana.copyInto(params, pagination); + } + + const uriFunction = function() + { + + return "/workflow/models/" + id + "/versions/query"; + }; + + const chainable = this.getFactory().workflowModelMap(this); + return this.chainPost(chainable, uriFunction, params, query); + }, + + + ////////////////////////////////////////////////////////////////////////////////////////// + // + // WORKFLOW INSTANCES + // + ////////////////////////////////////////////////////////////////////////////////////////// + + /** + * Lists the workflows. + * + * @param pagination + * + * @chained client map + */ + listWorkflows: function(pagination) + { + const params = {}; + if (pagination) + { + Gitana.copyInto(params, pagination); + } + + const chainable = this.getFactory().workflowInstanceMap(this); + return this.chainGet(chainable, "/workflow/instances", params); + }, + + /** + * Reads a workflow. + * + * @param workflowId + * + * @chained workflow + */ + readWorkflow: function(workflowId) + { + const chainable = this.getFactory().workflowInstance(this); + return this.chainGet(chainable, "/workflow/instances/" + workflowId); + }, + + /** + * Create a workflow + * + * @chained workflow + * + * @param {String} workflowModelId workflow id + * @param {Object} object JSON object + */ + createWorkflow: function(workflowModelId, object) + { + if (!object) + { + object = {}; + } + + const params = { + "modelId": workflowModelId + }; + + const chainable = this.getFactory().workflowInstance(this); + return this.chainCreate(chainable, object, "/workflow/instances", params); + }, + + /** + * Queries for workflows. + * + * @chained workflow map + * + * @param {Object} query + * @param {Object} pagination pagination (optional) + */ + queryWorkflows: function(query, pagination) + { + const params = {}; + if (pagination) + { + Gitana.copyInto(params, pagination); + } + + const uriFunction = function() + { + return "/workflow/instances/query"; + }; + + const chainable = this.getFactory().workflowInstanceMap(this); + return this.chainPost(chainable, uriFunction, params, query); + }, + + /** + * Performs a bulk check of permissions against permissioned objects of type workflow instance. + * + * Example of checks array: + * + * [{ + * "permissionedId": "", + * "principalId": "", + * "permissionId": "" + * }] + * + * The callback receives an array of results, example: + * + * [{ + * "permissionedId": "", + * "principalId": "", + * "permissionId": "", + * "result": true + * }] + * + * The order of elements in the array will be the same for checks and results. + * + * @param checks + * @param callback + */ + checkWorkflowInstancePermissions: function(checks, callback) + { + const uriFunction = function() + { + return "/workflow/instance/permissions/check"; + }; + + const object = { + "checks": checks + }; + + return this.chainPostResponse(this, uriFunction, {}, object).then(function(response) { + callback.call(this, response["results"]); + }); + }, + + /** + * Performs a bulk check of authorities against permissioned objects of type workflow instance. + * + * Example of checks array: + * + * [{ + * "permissionedId": "", + * "principalId": "", + * "authorityId": "" + * }] + * + * The callback receives an array of results, example: + * + * [{ + * "permissionedId": "", + * "principalId": "", + * "authorityId": "", + * "result": true + * }] + * + * The order of elements in the array will be the same for checks and results. + * + * @param checks + * @param callback + */ + checkWorkflowInstanceAuthorities: function(checks, callback) + { + const uriFunction = function() + { + return "/workflow/instance/authorities/check"; + }; + + const object = { + "checks": checks + }; + + return this.chainPostResponse(this, uriFunction, {}, object).then(function(response) { + callback.call(this, response["results"]); + }); + }, + + ////////////////////////////////////////////////////////////////////////////////////////// + // + // WORKFLOW TASKS + // + ////////////////////////////////////////////////////////////////////////////////////////// + + /** + * Lists the workflow tasks. + * + * @param pagination + * + * @chained workflow task map + */ + listWorkflowTasks: function(pagination) + { + const params = {}; + if (pagination) + { + Gitana.copyInto(params, pagination); + } + + const chainable = this.getFactory().workflowTaskMap(this); + return this.chainGet(chainable, "/workflow/tasks", params); + }, + + /** + * Reads a workflow task. + * + * @param workflowTaskId + * + * @chained workflow task + */ + readWorkflowTask: function(workflowTaskId) + { + const chainable = this.getFactory().workflowTask(this); + return this.chainGet(chainable, "/workflow/tasks/" + workflowTaskId); + }, + + /** + * Queries for workflow tasks. + * + * @chained workflow task map + * + * @param {Object} query + * @param {Object} pagination pagination (optional) + */ + queryWorkflowTasks: function(query, pagination) + { + const params = {}; + if (pagination) + { + Gitana.copyInto(params, pagination); + } + + const uriFunction = function() + { + return "/workflow/tasks/query"; + }; + + const chainable = this.getFactory().workflowTaskMap(this); + return this.chainPost(chainable, uriFunction, params, query); + }, + + /** + * Performs a bulk check of permissions against permissioned objects of type workflow task. + * + * Example of checks array: + * + * [{ + * "permissionedId": "", + * "principalId": "", + * "permissionId": "" + * }] + * + * The callback receives an array of results, example: + * + * [{ + * "permissionedId": "", + * "principalId": "", + * "permissionId": "", + * "result": true + * }] + * + * The order of elements in the array will be the same for checks and results. + * + * @param checks + * @param callback + */ + checkWorkflowTaskPermissions: function(checks, callback) + { + const uriFunction = function() + { + return "/workflow/task/permissions/check"; + }; + + const object = { + "checks": checks + }; + + return this.chainPostResponse(this, uriFunction, {}, object).then(function(response) { + callback.call(this, response["results"]); + }); + }, + + /** + * Performs a bulk check of authorities against permissioned objects of type workflow task. + * + * Example of checks array: + * + * [{ + * "permissionedId": "", + * "principalId": "", + * "authorityId": "" + * }] + * + * The callback receives an array of results, example: + * + * [{ + * "permissionedId": "", + * "principalId": "", + * "authorityId": "", + * "result": true + * }] + * + * The order of elements in the array will be the same for checks and results. + * + * @param checks + * @param callback + */ + checkWorkflowTaskAuthorities: function(checks, callback) + { + const uriFunction = function() + { + return "/workflow/task/authorities/check"; + }; + + const object = { + "checks": checks + }; + + return this.chainPostResponse(this, uriFunction, {}, object).then(function(response) { + callback.call(this, response["results"]); + }); + }, + + + ////////////////////////////////////////////////////////////////////////////////////////// + // + // WORKFLOW COMMENTS + // + ////////////////////////////////////////////////////////////////////////////////////////// + + /** + * Lists the workflow comments. + * + * @param pagination + * + * @chained workflow comment map + */ + listWorkflowComments: function(pagination) + { + const params = {}; + if (pagination) + { + Gitana.copyInto(params, pagination); + } + + const chainable = this.getFactory().workflowCommentMap(this); + return this.chainGet(chainable, "/workflow/comments", params); + }, + + /** + * Reads a workflow comment. + * + * @param workflowCommentId + * + * @chained workflow comment + */ + readWorkflowComment: function(workflowCommentId) + { + const chainable = this.getFactory().workflowComment(this); + return this.chainGet(chainable, "/workflow/comments/" + workflowCommentId); + }, + + /** + * Create a workflow comment + * + * @chained workflow comment + * + * @param {String} workflowId + * @param {String} workflowTaskId + * @param {Object} object JSON object + */ + createWorkflowComment: function(workflowId, workflowTaskId, object) + { + + const createUri = function() + { + let uri = "/workflow/instances/" + workflowId + "/comments"; + if (workflowTaskId) + { + uri += "?taskId=" + workflowTaskId; + } + + return uri; + }; + + const readUri = function(status) + { + return "/workflow/comments/" + status._doc; + }; + + const chainable = this.getFactory().workflowComment(this); + + return this.chainCreateEx(chainable, object, createUri, readUri); + }, + + /** + * Queries for workflow comments. + * + * @chained workflow comment map + * + * @param {Object} query + * @param {Object} pagination pagination (optional) + */ + queryWorkflowComments: function(query, pagination) + { + const params = {}; + if (pagination) + { + Gitana.copyInto(params, pagination); + } + + const uriFunction = function() + { + return "/workflow/comments/query"; + }; + + const chainable = this.getFactory().workflowCommentMap(this); + return this.chainPost(chainable, uriFunction, params, query); + }, + + /** + * Performs a bulk check of permissions against permissioned objects of type workflow task. + * + * Example of checks array: + * + * [{ + * "permissionedId": "", + * "principalId": "", + * "permissionId": "" + * }] + * + * The callback receives an array of results, example: + * + * [{ + * "permissionedId": "", + * "principalId": "", + * "permissionId": "", + * "result": true + * }] + * + * The order of elements in the array will be the same for checks and results. + * + * @param checks + * @param callback + */ + checkWorkflowCommentPermissions: function(checks, callback) + { + const uriFunction = function() + { + return "/workflow/comments/permissions/check"; + }; + + const object = { + "checks": checks + }; + + return this.chainPostResponse(this, uriFunction, {}, object).then(function(response) { + callback.call(this, response["results"]); + }); + }, + + /** + * Performs a bulk check of authorities against permissioned objects of type workflow task. + * + * Example of checks array: + * + * [{ + * "permissionedId": "", + * "principalId": "", + * "authorityId": "" + * }] + * + * The callback receives an array of results, example: + * + * [{ + * "permissionedId": "", + * "principalId": "", + * "authorityId": "", + * "result": true + * }] + * + * The order of elements in the array will be the same for checks and results. + * + * @param checks + * @param callback + */ + checkWorkflowCommentAuthorities: function(checks, callback) + { + const uriFunction = function() + { + return "/workflow/comments/authorities/check"; + }; + + const object = { + "checks": checks + }; + + return this.chainPostResponse(this, uriFunction, {}, object).then(function(response) { + callback.call(this, response["results"]); + }); + }, + + + ////////////////////////////////////////////////////////////////////////////////////////// + // + // WORKFLOW TASKS - CURRENT USER + // + ////////////////////////////////////////////////////////////////////////////////////////// + + /** + * Lists tasks for the current user. + * + * @param filter empty or "assigned" or "unassigned" + * @param pagination + * + * @returns {*} + */ + listTasksForCurrentUser: function(filter, pagination) + { + const params = {}; + if (pagination) + { + Gitana.copyInto(params, pagination); + } + + if (filter) + { + params.filter = filter; + } + + const chainable = this.getFactory().workflowTaskMap(this); + return this.chainGet(chainable, "/workflow/user/tasks", params); + }, + + /** + * Lists tasks for the current user. + * + * @param filter empty or "assigned" or "unassigned" + * @param query + * @param pagination + * + * @returns {*} + */ + queryTasksForCurrentUser: function(filter, query, pagination) + { + const params = {}; + if (pagination) + { + Gitana.copyInto(params, pagination); + } + + if (filter) + { + params.filter = filter; + } + + const chainable = this.getFactory().workflowTaskMap(this); + return this.chainPost(chainable, "/workflow/user/tasks/query", params, query); + }, + + queryTasks: function(query, pagination) + { + const params = {}; + if (pagination) + { + Gitana.copyInto(params, pagination); + } + + const chainable = this.getFactory().workflowTaskMap(this); + return this.chainPost(chainable, "/workflow/tasks/query", params, query); + }, + + ////////////////////////////////////////////////////////////////////////////////////////// + // + // WORKFLOW HISTORY + // + ////////////////////////////////////////////////////////////////////////////////////////// + + /** + * Loads the history for a workflow. + * + * @param workflowId the id of the workflow to load the history for + * @param pagination + * @param callback + */ + loadWorkflowHistory: function(workflowId, pagination, callback) + { + const uriFunction = function() + { + return "/workflow/instances/" + workflowId + "/history"; + }; + + // prepare params (with pagination) + const params = {}; + if (pagination) + { + Gitana.copyInto(params, pagination); + } + + return this.chainGetResponse(this, uriFunction, params).then(function(response) { + callback(response); + }); + }, + + + + ////////////////////////////////////////////////////////////////////////////////////////// + // + // SCHEDULED WORK ITEMS + // + ////////////////////////////////////////////////////////////////////////////////////////// + + /** + * Lists the scheduled work items. + * + * @param pagination + * + * @chained scheduled work item map + */ + listScheduledWorkItems: function(pagination) + { + const params = {}; + if (pagination) + { + Gitana.copyInto(params, pagination); + } + + const chainable = this.getFactory().scheduledWorkMap(this); + return this.chainGet(chainable, "/work/scheduled", params); + }, + + /** + * Reads a scheduled work item. + * + * @param scheduledWorkId + * + * @chained scheduled work + */ + readScheduledWorkItem: function(scheduledWorkId) + { + const chainable = this.getFactory().scheduledWork(this); + return this.chainGet(chainable, "/work/scheduled/" + scheduledWorkId); + }, + + /** + * Create a scheduled work item + * + * @chained scheduled work + * + * @param {Object} object JSON object + */ + createScheduledWorkItem: function(object) + { + if (!object) + { + object = {}; + } + + const chainable = this.getFactory().scheduledWork(this); + return this.chainCreate(chainable, object, "/work/scheduled"); + }, + + /** + * Queries for scheduled work items. + * + * @chained scheduled work item map + * + * @param {Object} query + * @param {Object} pagination pagination (optional) + */ + queryScheduledWorkItems: function(query, pagination) + { + const params = {}; + if (pagination) + { + Gitana.copyInto(params, pagination); + } + + const uriFunction = function() + { + return "/work/scheduled/query"; + }; + + const chainable = this.getFactory().scheduledWorkMap(this); + return this.chainPost(chainable, uriFunction, params, query); + }, + + /** + * Performs a bulk check of permissions against permissioned objects of type scheduled work. + * + * Example of checks array: + * + * [{ + * "permissionedId": "", + * "principalId": "", + * "permissionId": "" + * }] + * + * The callback receives an array of results, example: + * + * [{ + * "permissionedId": "", + * "principalId": "", + * "permissionId": "", + * "result": true + * }] + * + * The order of elements in the array will be the same for checks and results. + * + * @param checks + * @param callback + */ + checkScheduledWorkPermissions: function(checks, callback) + { + const uriFunction = function() + { + return "/work/scheduled/permissions/check"; + }; + + const object = { + "checks": checks + }; + + return this.chainPostResponse(this, uriFunction, {}, object).then(function(response) { + callback.call(this, response["results"]); + }); + }, + + /** + * Performs a bulk check of authorities against permissioned objects of type scheduled work. + * + * Example of checks array: + * + * [{ + * "permissionedId": "", + * "principalId": "", + * "authorityId": "" + * }] + * + * The callback receives an array of results, example: + * + * [{ + * "permissionedId": "", + * "principalId": "", + * "authorityId": "", + * "result": true + * }] + * + * The order of elements in the array will be the same for checks and results. + * + * @param checks + * @param callback + */ + checkScheduledWorkAuthorities: function(checks, callback) + { + const uriFunction = function() + { + return "/work/scheduled/authorities/check"; + }; + + const object = { + "checks": checks + }; + + return this.chainPostResponse(this, uriFunction, {}, object).then(function(response) { + callback.call(this, response["results"]); + }); + }, + + + + + + ////////////////////////////////////////////////////////////////////////////////////////// + // + // REPORTS + // + ////////////////////////////////////////////////////////////////////////////////////////// + + /** + * Lists the reports. + * + * @param pagination + * + * @chained scheduled work item map + */ + listReports: function(pagination) + { + const params = {}; + if (pagination) + { + Gitana.copyInto(params, pagination); + } + + const chainable = this.getFactory().reportMap(this); + return this.chainGet(chainable, "/reports", params); + }, + + /** + * Reads a report. + * + * @param reportId + * + * @chained report + */ + readReport: function(reportId) + { + const chainable = this.getFactory().report(this); + return this.chainGet(chainable, "/reports/" + reportId); + }, + + /** + * Create a report + * + * @chained report + * + * @param {Object} object JSON object + */ + createReport: function(object) + { + if (!object) + { + object = {}; + } + + const chainable = this.getFactory().report(this); + return this.chainCreate(chainable, object, "/reports"); + }, + + /** + * Queries for reports. + * + * @chained report map + * + * @param {Object} query + * @param {Object} pagination pagination (optional) + */ + queryReports: function(query, pagination) + { + const params = {}; + if (pagination) + { + Gitana.copyInto(params, pagination); + } + + const uriFunction = function() + { + return "/reports/query"; + }; + + const chainable = this.getFactory().reportMap(this); + return this.chainPost(chainable, uriFunction, params, query); + }, + + /** + * Performs a bulk check of permissions against permissioned objects of type report. + * + * Example of checks array: + * + * [{ + * "permissionedId": "", + * "principalId": "", + * "permissionId": "" + * }] + * + * The callback receives an array of results, example: + * + * [{ + * "permissionedId": "", + * "principalId": "", + * "permissionId": "", + * "result": true + * }] + * + * The order of elements in the array will be the same for checks and results. + * + * @param checks + * @param callback + */ + checkReportPermissions: function(checks, callback) + { + const uriFunction = function() + { + return "/reports/permissions/check"; + }; + + const object = { + "checks": checks + }; + + return this.chainPostResponse(this, uriFunction, {}, object).then(function(response) { + callback.call(this, response["results"]); + }); + }, + + /** + * Performs a bulk check of authorities against permissioned objects of type report. + * + * Example of checks array: + * + * [{ + * "permissionedId": "", + * "principalId": "", + * "authorityId": "" + * }] + * + * The callback receives an array of results, example: + * + * [{ + * "permissionedId": "", + * "principalId": "", + * "authorityId": "", + * "result": true + * }] + * + * The order of elements in the array will be the same for checks and results. + * + * @param checks + * @param callback + */ + checkReportAuthorities: function(checks, callback) + { + const uriFunction = function() + { + return "/reports/authorities/check"; + }; + + const object = { + "checks": checks + }; + + return this.chainPostResponse(this, uriFunction, {}, object).then(function(response) { + callback.call(this, response["results"]); + }); + }, + + /** + * Executes a report. + * + * @chained report + * + * @param {String} reportId the id of the report to run + * @param {Object} config additional config + * @param {Object} pagination + * @param {Function} callback callback to fire + */ + executeReport: function(reportId, config, pagination, callback) + { + if (typeof(config) === "function") + { + callback = config; + config = {}; + pagination = null; + } + + if (typeof(pagination) === "function") + { + callback = pagination; + pagination = null; + + if (!config) { + config = {}; + } + } + + const params = {}; + if (pagination) + { + Gitana.copyInto(params, pagination); + } + + const uriFunction = function() + { + return "/reports/" + reportId + "/execute"; + }; + + return this.chainPostResponse(this, uriFunction, params, config).then(function(response) { + callback.call(this, response); + }); + }, + + + + ////////////////////////////////////////////////////////////////////////////////////////// + // + // EXPORTS + // + ////////////////////////////////////////////////////////////////////////////////////////// + + /** + * Runs an export and waits for the export to complete. + * + * This runs an asynchronous background poll checking status for the job to complete. + * Once complete, the exportId and status are passed to the callback. + * + * @param objects + * @param configuration + * @param callback + * @returns {*} + */ + runExport: function(objects, configuration, callback) + { + const uriFunction = function() + { + return "/ref/exports/start"; + }; + + if (!configuration) + { + configuration = {}; + } + + let references = []; + if (objects.refs) + { + references = objects.refs(); + } + else if (objects.length) + { + for (let i = 0; i < objects.length; i++) + { + references.push(objects[i].ref()); + } + } + configuration.references = references; + + const chainable = this; + + return this.chainPostResponse(this, uriFunction, {}, configuration).then(function(response) { + + const exportId = response._doc; + + // wait for the export to finish... + const f = function() + { + window.setTimeout(function() { + + Chain(chainable).readExportStatus(exportId, function(status) { + if (status.state === "FINISHED") { + callback(exportId, status); + chainable.next(); + } else if (status.state === "ERROR") { + callback(exportId, status); + chainable.next(); + } else { + f(); + } + }); + + }, 1000); + }; + f(); + + return false; + + }); + }, + + /** + * Retrieves the status for a running export job. + * The status includes the "fileCount" field which indicates the total number of exported files. + * + * @param exportId + * @param callback + * @returns {*} + */ + readExportStatus: function(exportId, callback) + { + const uriFunction = function() + { + return "/ref/exports/" + exportId + "/status"; + }; + + return this.chainGetResponse(this, uriFunction).then(function(response) { + callback(response); + }); + }, + + /** + * Gets the download URL for a completed export. + * + * @param exportId + * @param index + * @param useDispositionHeader + * @returns {string} + */ + exportDownloadUrl: function(exportId, index, useDispositionHeader) + { + let url = "/ref/exports/" + exportId + "/download"; + + if (index) + { + url += "/" + index; + } + + if (useDispositionHeader) + { + url += "?a=true"; + } + + return url; + }, + + + + + + + + ////////////////////////////////////////////////////////////////////////////////////////// + // + // EXTERNAL SERVICE DESCRIPTORS + // + ////////////////////////////////////////////////////////////////////////////////////////// + + /** + * Lists the service descriptors. + * + * @param pagination + * + * @chained descriptor map + */ + listServiceDescriptors: function(pagination) + { + const params = {}; + if (pagination) + { + Gitana.copyInto(params, pagination); + } + + const chainable = this.getFactory().descriptorMap(this); + return this.chainGet(chainable, "/descriptors", params); + }, + + /** + * Reads a service descriptor. + * + * @param descriptorId + * + * @chained descriptor + */ + readServiceDescriptor: function(descriptorId) + { + const chainable = this.getFactory().descriptor(this); + return this.chainGet(chainable, "/descriptors/" + descriptorId); + }, + + /** + * Create a service descriptor + * + * @chained descriptor + * + * @param {Object} object JSON object + */ + createServiceDescriptor: function(object) + { + if (!object) + { + object = {}; + } + + const chainable = this.getFactory().descriptor(this); + return this.chainCreate(chainable, object, "/descriptors"); + }, + + /** + * Queries for descriptors. + * + * @chained descriptor map + * + * @param {Object} query + * @param {Object} pagination pagination (optional) + */ + queryServiceDescriptors: function(query, pagination) + { + const params = {}; + if (pagination) + { + Gitana.copyInto(params, pagination); + } + + const uriFunction = function() + { + return "/descriptors/query"; + }; + + const chainable = this.getFactory().descriptorMap(this); + return this.chainPost(chainable, uriFunction, params, query); + }, + + /** + * Performs a bulk check of permissions against permissioned objects of type external service descriptor. + * + * Example of checks array: + * + * [{ + * "permissionedId": "", + * "principalId": "", + * "permissionId": "" + * }] + * + * The callback receives an array of results, example: + * + * [{ + * "permissionedId": "", + * "principalId": "", + * "permissionId": "", + * "result": true + * }] + * + * The order of elements in the array will be the same for checks and results. + * + * @param checks + * @param callback + */ + checkServiceDescriptorPermissions: function(checks, callback) + { + const uriFunction = function() + { + return "/descriptors/permissions/check"; + }; + + const object = { + "checks": checks + }; + + return this.chainPostResponse(this, uriFunction, {}, object).then(function(response) { + callback.call(this, response["results"]); + }); + }, + + /** + * Performs a bulk check of authorities against permissioned objects of type external service descriptor. + * + * Example of checks array: + * + * [{ + * "permissionedId": "", + * "principalId": "", + * "authorityId": "" + * }] + * + * The callback receives an array of results, example: + * + * [{ + * "permissionedId": "", + * "principalId": "", + * "authorityId": "", + * "result": true + * }] + * + * The order of elements in the array will be the same for checks and results. + * + * @param checks + * @param callback + */ + checkServiceDescriptorAuthorities: function(checks, callback) + { + const uriFunction = function() + { + return "/descriptors/authorities/check"; + }; + + const object = { + "checks": checks + }; + + return this.chainPostResponse(this, uriFunction, {}, object).then(function(response) { + callback.call(this, response["results"]); + }); + }, + + + + + ////////////////////////////////////////////////////////////////////////////////////////// + // + // UI CONFIGS + // + ////////////////////////////////////////////////////////////////////////////////////////// + + /** + * Lists the UI config instances. + * + * @param pagination + * + * @chained ui config map + */ + listUIConfigs: function(pagination) + { + const params = {}; + if (pagination) + { + Gitana.copyInto(params, pagination); + } + + const chainable = this.getFactory().uiConfigMap(this); + return this.chainGet(chainable, "/uiconfigs", params); + }, + + /** + * Reads a UI config instance. + * + * @param uiConfigId + * + * @chained uiConfig + */ + readUIConfig: function(uiConfigId) + { + const chainable = this.getFactory().uiConfig(this); + return this.chainGet(chainable, "/uiconfigs/" + uiConfigId); + }, + + /** + * Create a UI config instance + * + * @chained uiConfig + * + * @param {Object} object JSON object + */ + createUIConfig: function(object) + { + if (!object) + { + object = {}; + } + + const chainable = this.getFactory().uiConfig(this); + return this.chainCreate(chainable, object, "/uiconfigs"); + }, + + /** + * Queries for UI configs. + * + * @chained UI config map + * + * @param {Object} query + * @param {Object} pagination pagination (optional) + */ + queryUIConfigs: function(query, pagination) + { + const params = {}; + if (pagination) + { + Gitana.copyInto(params, pagination); + } + + const uriFunction = function() + { + return "/uiconfigs/query"; + }; + + const chainable = this.getFactory().uiConfigMap(this); + return this.chainPost(chainable, uriFunction, params, query); + }, + + /** + * Performs a bulk check of permissions against permissioned objects of type uiconfig. + * + * Example of checks array: + * + * [{ + * "permissionedId": "", + * "principalId": "", + * "permissionId": "" + * }] + * + * The callback receives an array of results, example: + * + * [{ + * "permissionedId": "", + * "principalId": "", + * "permissionId": "", + * "result": true + * }] + * + * The order of elements in the array will be the same for checks and results. + * + * @param checks + * @param callback + */ + checkUIConfigPermissions: function(checks, callback) + { + const uriFunction = function() + { + return "/uiconfigs/permissions/check"; + }; + + const object = { + "checks": checks + }; + + return this.chainPostResponse(this, uriFunction, {}, object).then(function(response) { + callback.call(this, response["results"]); + }); + }, + + /** + * Performs a bulk check of authorities against permissioned objects of type uiconfig. + * + * Example of checks array: + * + * [{ + * "permissionedId": "", + * "principalId": "", + * "authorityId": "" + * }] + * + * The callback receives an array of results, example: + * + * [{ + * "permissionedId": "", + * "principalId": "", + * "authorityId": "", + * "result": true + * }] + * + * The order of elements in the array will be the same for checks and results. + * + * @param checks + * @param callback + */ + checkUIConfigAuthorities: function(checks, callback) + { + const uriFunction = function() + { + return "/uiconfigs/authorities/check"; + }; + + const object = { + "checks": checks + }; + + return this.chainPostResponse(this, uriFunction, {}, object).then(function(response) { + callback.call(this, response["results"]); + }); + }, + + + + + ////////////////////////////////////////////////////////////////////////////////////////// + // + // DEPLOYMENT RECEIVERS + // + ////////////////////////////////////////////////////////////////////////////////////////// + + /** + * Lists the deployment receivers. + * + * @param pagination + * + * @chained deployment receiver map + */ + listDeploymentReceivers: function(pagination) + { + const params = {}; + if (pagination) + { + Gitana.copyInto(params, pagination); + } + + const chainable = this.getFactory().deploymentReceiverMap(this); + return this.chainGet(chainable, "/deployment/receivers", params); + }, + + /** + * Reads a deployment receiver. + * + * @param deploymentReceiverId + * + * @chained deploymentReceiver + */ + readDeploymentReceiver: function(deploymentReceiverId) + { + const chainable = this.getFactory().deploymentReceiver(this); + return this.chainGet(chainable, "/deployment/receivers/" + deploymentReceiverId); + }, + + /** + * Create a deployment receiver + * + * @chained deployment receiver + * + * @param {Object} object JSON object + */ + createDeploymentReceiver: function(object) + { + if (!object) + { + object = {}; + } + + const chainable = this.getFactory().deploymentReceiver(this); + return this.chainCreate(chainable, object, "/deployment/receivers"); + }, + + /** + * Queries for deployment receivers. + * + * @chained deployment receiver map + * + * @param {Object} query + * @param {Object} pagination pagination (optional) + */ + queryDeploymentReceivers: function(query, pagination) + { + const params = {}; + if (pagination) + { + Gitana.copyInto(params, pagination); + } + + const uriFunction = function() + { + return "/deployment/receivers/query"; + }; + + const chainable = this.getFactory().deploymentReceiverMap(this); + return this.chainPost(chainable, uriFunction, params, query); + }, + + /** + * Performs a bulk check of permissions against permissioned objects of type deployment receiver. + * + * Example of checks array: + * + * [{ + * "permissionedId": "", + * "principalId": "", + * "permissionId": "" + * }] + * + * The callback receives an array of results, example: + * + * [{ + * "permissionedId": "", + * "principalId": "", + * "permissionId": "", + * "result": true + * }] + * + * The order of elements in the array will be the same for checks and results. + * + * @param checks + * @param callback + */ + checkDeploymentReceiverPermissions: function(checks, callback) + { + const uriFunction = function() + { + return "/deployment/receivers/permissions/check"; + }; + + const object = { + "checks": checks + }; + + return this.chainPostResponse(this, uriFunction, {}, object).then(function(response) { + callback.call(this, response["results"]); + }); + }, + + /** + * Performs a bulk check of authorities against permissioned objects of type deployment receiver. + * + * Example of checks array: + * + * [{ + * "permissionedId": "", + * "principalId": "", + * "authorityId": "" + * }] + * + * The callback receives an array of results, example: + * + * [{ + * "permissionedId": "", + * "principalId": "", + * "authorityId": "", + * "result": true + * }] + * + * The order of elements in the array will be the same for checks and results. + * + * @param checks + * @param callback + */ + checkDeploymentReceiverAuthorities: function(checks, callback) + { + const uriFunction = function() + { + return "/deployment/receivers/authorities/check"; + }; + + const object = { + "checks": checks + }; + + return this.chainPostResponse(this, uriFunction, {}, object).then(function(response) { + callback.call(this, response["results"]); + }); + }, + + + + + ////////////////////////////////////////////////////////////////////////////////////////// + // + // DEPLOYMENT PACKAGES + // + ////////////////////////////////////////////////////////////////////////////////////////// + + /** + * Lists the deployment packages. + * + * @param pagination + * + * @chained deployment package map + */ + listDeploymentPackages: function(pagination) + { + const params = {}; + if (pagination) + { + Gitana.copyInto(params, pagination); + } + + const chainable = this.getFactory().deploymentPackageMap(this); + return this.chainGet(chainable, "/deployment/packages", params); + }, + + /** + * Reads a deployment package + * + * @param deploymentPackageId + * + * @chained deployment package + */ + readDeploymentPackage: function(deploymentPackageId) + { + const chainable = this.getFactory().deploymentPackage(this); + return this.chainGet(chainable, "/deployment/packages/" + deploymentPackageId); + }, + + /** + * Queries for deployment packages + * + * @chained deployment package map + * + * @param {Object} query + * @param {Object} pagination pagination (optional) + */ + queryDeploymentPackages: function(query, pagination) + { + const params = {}; + if (pagination) + { + Gitana.copyInto(params, pagination); + } + + const uriFunction = function() + { + return "/deployment/packages/query"; + }; + + const chainable = this.getFactory().deploymentPackageMap(this); + return this.chainPost(chainable, uriFunction, params, query); + }, + + /** + * Performs a bulk check of permissions against permissioned objects of type deployment package. + * + * Example of checks array: + * + * [{ + * "permissionedId": "", + * "principalId": "", + * "permissionId": "" + * }] + * + * The callback receives an array of results, example: + * + * [{ + * "permissionedId": "", + * "principalId": "", + * "permissionId": "", + * "result": true + * }] + * + * The order of elements in the array will be the same for checks and results. + * + * @param checks + * @param callback + */ + checkDeploymentPackagePermissions: function(checks, callback) + { + const uriFunction = function() + { + return "/deployment/packages/permissions/check"; + }; + + const object = { + "checks": checks + }; + + return this.chainPostResponse(this, uriFunction, {}, object).then(function(response) { + callback.call(this, response["results"]); + }); + }, + + /** + * Performs a bulk check of authorities against permissioned objects of type deployment package. + * + * Example of checks array: + * + * [{ + * "permissionedId": "", + * "principalId": "", + * "authorityId": "" + * }] + * + * The callback receives an array of results, example: + * + * [{ + * "permissionedId": "", + * "principalId": "", + * "authorityId": "", + * "result": true + * }] + * + * The order of elements in the array will be the same for checks and results. + * + * @param checks + * @param callback + */ + checkDeploymentPackageAuthorities: function(checks, callback) + { + const uriFunction = function() + { + return "/deployment/packages/authorities/check"; + }; + + const object = { + "checks": checks + }; + + return this.chainPostResponse(this, uriFunction, {}, object).then(function(response) { + callback.call(this, response["results"]); + }); + }, + + + + + ////////////////////////////////////////////////////////////////////////////////////////// + // + // DEPLOYMENT STRATEGY + // + ////////////////////////////////////////////////////////////////////////////////////////// + + /** + * Lists the deployment strategies. + * + * @param pagination + * + * @chained deployment strategy map + */ + listDeploymentStrategies: function(pagination) + { + const params = {}; + if (pagination) + { + Gitana.copyInto(params, pagination); + } + + const chainable = this.getFactory().deploymentStrategyMap(this); + return this.chainGet(chainable, "/deployment/strategies", params); + }, + + /** + * Reads a deployment strategy. + * + * @param deploymentStrategyId + * + * @chained deployment strategy + */ + readDeploymentStrategy: function(deploymentStrategyId) + { + const chainable = this.getFactory().deploymentStrategy(this); + return this.chainGet(chainable, "/deployment/strategies/" + deploymentStrategyId); + }, + + /** + * Create a deployment strategy. + * + * @chained deployment strategy + * + * @param {Object} object JSON object + */ + createDeploymentStrategy: function(object) + { + if (!object) + { + object = {}; + } + + const chainable = this.getFactory().deploymentStrategy(this); + return this.chainCreate(chainable, object, "/deployment/strategies"); + }, + + /** + * Queries for deployment strategies + * + * @chained deployment strategy map + * + * @param {Object} query + * @param {Object} pagination pagination (optional) + */ + queryDeploymentStrategies: function(query, pagination) + { + const params = {}; + if (pagination) + { + Gitana.copyInto(params, pagination); + } + + const uriFunction = function() + { + return "/deployment/strategies/query"; + }; + + const chainable = this.getFactory().deploymentStrategyMap(this); + return this.chainPost(chainable, uriFunction, params, query); + }, + + /** + * Performs a bulk check of permissions against permissioned objects of type deployment strategy. + * + * Example of checks array: + * + * [{ + * "permissionedId": "", + * "principalId": "", + * "permissionId": "" + * }] + * + * The callback receives an array of results, example: + * + * [{ + * "permissionedId": "", + * "principalId": "", + * "permissionId": "", + * "result": true + * }] + * + * The order of elements in the array will be the same for checks and results. + * + * @param checks + * @param callback + */ + checkDeploymentStrategyPermissions: function(checks, callback) + { + const uriFunction = function() + { + return "/deployment/strategies/permissions/check"; + }; + + const object = { + "checks": checks + }; + + return this.chainPostResponse(this, uriFunction, {}, object).then(function(response) { + callback.call(this, response["results"]); + }); + }, + + /** + * Performs a bulk check of authorities against permissioned objects of type deployment strategy. + * + * Example of checks array: + * + * [{ + * "permissionedId": "", + * "principalId": "", + * "authorityId": "" + * }] + * + * The callback receives an array of results, example: + * + * [{ + * "permissionedId": "", + * "principalId": "", + * "authorityId": "", + * "result": true + * }] + * + * The order of elements in the array will be the same for checks and results. + * + * @param checks + * @param callback + */ + checkDeploymentStrategyAuthorities: function(checks, callback) + { + const uriFunction = function() + { + return "/deployment/strategies/authorities/check"; + }; + + const object = { + "checks": checks + }; + + return this.chainPostResponse(this, uriFunction, {}, object).then(function(response) { + callback.call(this, response["results"]); + }); + }, + + + + + ////////////////////////////////////////////////////////////////////////////////////////// + // + // DEPLOYMENT TARGET + // + ////////////////////////////////////////////////////////////////////////////////////////// + + /** + * Lists the deployment targets. + * + * @param pagination + * + * @chained deployment target map + */ + listDeploymentTargets: function(pagination) + { + const params = {}; + if (pagination) + { + Gitana.copyInto(params, pagination); + } + + const chainable = this.getFactory().deploymentTargetMap(this); + return this.chainGet(chainable, "/deployment/targets", params); + }, + + /** + * Reads a deployment target. + * + * @param deploymentTargetId + * + * @chained deployment target + */ + readDeploymentTarget: function(deploymentTargetId) + { + const chainable = this.getFactory().deploymentTarget(this); + return this.chainGet(chainable, "/deployment/targets/" + deploymentTargetId); + }, + + /** + * Create a deployment target. + * + * @chained deployment target + * + * @param {Object} object JSON object + */ + createDeploymentTarget: function(object) + { + if (!object) + { + object = {}; + } + + const chainable = this.getFactory().deploymentTarget(this); + return this.chainCreate(chainable, object, "/deployment/targets"); + }, + + /** + * Queries for deployment targets + * + * @chained deployment target map + * + * @param {Object} query + * @param {Object} pagination pagination (optional) + */ + queryDeploymentTargets: function(query, pagination) + { + const params = {}; + if (pagination) + { + Gitana.copyInto(params, pagination); + } + + const uriFunction = function() + { + return "/deployment/targets/query"; + }; + + const chainable = this.getFactory().deploymentTargetMap(this); + return this.chainPost(chainable, uriFunction, params, query); + }, + + /** + * Performs a bulk check of permissions against permissioned objects of type deployment target. + * + * Example of checks array: + * + * [{ + * "permissionedId": "", + * "principalId": "", + * "permissionId": "" + * }] + * + * The callback receives an array of results, example: + * + * [{ + * "permissionedId": "", + * "principalId": "", + * "permissionId": "", + * "result": true + * }] + * + * The order of elements in the array will be the same for checks and results. + * + * @param checks + * @param callback + */ + checkDeploymentTargetPermissions: function(checks, callback) + { + const uriFunction = function() + { + return "/deployment/targets/permissions/check"; + }; + + const object = { + "checks": checks + }; + + return this.chainPostResponse(this, uriFunction, {}, object).then(function(response) { + callback.call(this, response["results"]); + }); + }, + + /** + * Performs a bulk check of authorities against permissioned objects of type deployment target. + * + * Example of checks array: + * + * [{ + * "permissionedId": "", + * "principalId": "", + * "authorityId": "" + * }] + * + * The callback receives an array of results, example: + * + * [{ + * "permissionedId": "", + * "principalId": "", + * "authorityId": "", + * "result": true + * }] + * + * The order of elements in the array will be the same for checks and results. + * + * @param checks + * @param callback + */ + checkDeploymentTargetAuthorities: function(checks, callback) + { + const uriFunction = function() + { + return "/deployment/targets/authorities/check"; + }; + + const object = { + "checks": checks + }; + + return this.chainPostResponse(this, uriFunction, {}, object).then(function(response) { + callback.call(this, response["results"]); + }); + } + + }); + +})(window); +(function(window) +{ + Gitana = window.Gitana; + + Gitana.AbstractPlatformDataStore = Gitana.ContainedDataStore.extend( + /** @lends Gitana.AbstractPlatformDataStore.prototype */ + { + /** + * @constructs + * @augments Gitana.DataStore + * + * @class AbstractPlatformDataStore + * + * @param {Gitana.Platform} platform + * @param {Object} object json object (if no callback required for populating) + */ + constructor: function(platform, object) + { + this.base(platform, object); + + + ////////////////////////////////////////////////////////////////////////////////////////////// + // + // PRIVILEGED METHODS + // + ////////////////////////////////////////////////////////////////////////////////////////////// + + this.getPlatform = function() + { + return platform; + }; + + this.getPlatformId = function() + { + return platform.getId(); + }; + + this.getCluster = function() + { + return platform.getCluster(); + }; + + this.getClusterId = function() + { + return platform.getClusterId(); + }; + }, + + /** + * @returns {String} a string denoting a reference to this platform datastore + */ + ref: function() + { + return this.getType() + "://" + this.getPlatformId() + "/" + this.getId(); + }, + + + + + ////////////////////////////////////////////////////////////////////////////////////////////// + // + // COPY + // + ////////////////////////////////////////////////////////////////////////////////////////////// + + /** + * Copies this object into the target. + * + * @chained job + * + * @param target + * @param asynchronous + * @param config + */ + copy: function(target, asynchronous, config) + { + const self = this; + + const payload = { + "sources": Gitana.toCopyDependencyChain(this), + "targets": Gitana.toCopyDependencyChain(target) + }; + + if (config) { + payload.configuration = config; + } + + // we continue the chain with a job + const chainable = this.getFactory().job(this.getCluster(), "copy"); + + // fire off copy and job queue checking + return this.subchain(chainable).then(function() { + + const chain = this; + + // create + this.getDriver().gitanaPost("/tools/copy?schedule=ASYNCHRONOUS", {}, payload, function(response) { + + Gitana.handleJobCompletion(chain, self.getCluster(), response.getId(), !asynchronous); + + }, function(http) { + self.httpError(http); + }); + + // NOTE: we return false to tell the chain that we'll manually call next() + return false; + }); + }, + + /** + * Finds the stack for this data store. + * @chained stack + */ + findStack: function() + { + return this.subchain(this.getPlatform()).findStackForDataStore(this.getType(), this.getId()); + }, + + ////////////////////////////////////////////////////////////////////////////////////////// + // + // INFO + // + ////////////////////////////////////////////////////////////////////////////////////////// + + /** + * Loads information about the datastore. + * + * @param callback + */ + loadInfo: function(callback) + { + const uriFunction = function() + { + return this.getUri() + "/info"; + }; + + return this.chainGetResponse(this, uriFunction, {}).then(function(response) { + callback(response); + }); + } + + }); + +})(window); +(function(window) +{ + Gitana = window.Gitana; + + Gitana.AbstractPlatformObject = Gitana.AbstractSelfableACLObject.extend( + /** @lends Gitana.AbstractPlatformObject.prototype */ + { + /** + * @constructs + * @augments Gitana.AbstractSelfableACLObject + * + * @class AbstractPlatformObject + * + * @param {Gitana.Platform} platform + * @param {Object} [object] json object (if no callback required for populating) + */ + constructor: function(platform, object) + { + this.base(platform.getDriver(), object); + + + ////////////////////////////////////////////////////////////////////////////////////////////// + // + // PRIVILEGED METHODS + // + ////////////////////////////////////////////////////////////////////////////////////////////// + + this.getPlatform = function() + { + return platform; + }; + + this.getPlatformId = function() + { + return platform.getId(); + }; + + this.getCluster = function() + { + return platform.getCluster(); + }; + + this.getClusterId = function() + { + return platform.getClusterId(); + }; + }, + + /** + * @OVERRIDE + */ + ref: function() + { + return this.getType() + "://" + this.getPlatformId() + "/" + this.getId(); + }, + + + ////////////////////////////////////////////////////////////////////////////////////////// + // + // TRANSFER + // + ////////////////////////////////////////////////////////////////////////////////////////// + + /** + * Exports an archive. + * + * @chained job + * + * @param {Object} settings + */ + exportArchive: function(settings) + { + const self = this; + + let vaultId = settings.vault; + if (!Gitana.isString(vaultId)) + { + vaultId = vaultId.getId(); + } + const groupId = settings.group; + const artifactId = settings.artifact; + const versionId = settings.version; + const configuration = (settings.configuration ? settings.configuration : {}); + const synchronous = !settings.async; + + // archive additional properties + const title = settings.title; + const description = settings.description; + const published = settings.published; + + // we continue the chain with a job + const chainable = this.getFactory().job(this.getCluster(), "export"); + + // fire off import and job queue checking + return this.subchain(chainable).then(function() { + + const chain = this; + + // create + const params = {}; + params["vault"] = vaultId; + params["group"] = groupId; + params["artifact"] = artifactId; + params["version"] = versionId; + params["schedule"] = "ASYNCHRONOUS"; + if (title) { + params["title"] = title; + } + if (description) { + params["description"] = description; + } + if (published) { + params["published"] = published; + } + this.getDriver().gitanaPost(self.getUri() + "/export", params, configuration, function(response) { + Gitana.handleJobCompletion(chain, self.getCluster(), response.getId(), synchronous); + }, function(http) { + self.httpError(http); + }); + + // NOTE: we return false to tell the chain that we'll manually call next() + return false; + }); + }, + + /** + * Imports an archive. + * + * @chained job + * + * @param {Object} settings + * @param {Function} reportFn + */ + importArchive: function(settings, reportFn) + { + const self = this; + + let vaultId = settings.vault; + if (!Gitana.isString(vaultId)) + { + vaultId = vaultId.getId(); + } + const groupId = settings.group; + const artifactId = settings.artifact; + const versionId = settings.version; + const configuration = (settings.configuration ? settings.configuration : {}); + const synchronous = !settings.async; + + // we continue the chain with a job + const chainable = this.getFactory().job(this.getCluster(), "import"); + + // fire off import and job queue checking + return this.subchain(chainable).then(function() { + + const chain = this; + + // create + this.getDriver().gitanaPost(self.getUri() + "/import?vault=" + vaultId + "&group=" + groupId + "&artifact=" + artifactId + "&version=" + versionId + "&schedule=ASYNCHRONOUS", {}, configuration, function(response) { + + Gitana.handleJobCompletion(chain, self.getCluster(), response.getId(), synchronous, reportFn); + + }, function(http) { + self.httpError(http); + }); + + // NOTE: we return false to tell the chain that we'll manually call next() + return false; + }); + + }, + + + ////////////////////////////////////////////////////////////////////////////////////////////// + // + // COPY + // + ////////////////////////////////////////////////////////////////////////////////////////////// + + /** + * Copies this object into the target. + * + * @chained job + * + * @param target + * @param asynchronous + * @param config + */ + copy: function(target, asynchronous, config) + { + const self = this; + + const payload = { + "sources": Gitana.toCopyDependencyChain(this), + "targets": Gitana.toCopyDependencyChain(target) + }; + + if (config) { + payload.configuration = config; + } + + // we continue the chain with a job + const chainable = this.getFactory().job(this.getCluster(), "copy"); + + // fire off copy and job queue checking + return this.subchain(chainable).then(function() { + + const chain = this; + + // create + this.getDriver().gitanaPost("/tools/copy?schedule=ASYNCHRONOUS", {}, payload, function(response) { + + Gitana.handleJobCompletion(chain, self.getCluster(), response.getId(), !asynchronous); + + }, function(http) { + self.httpError(http); + }); + + // NOTE: we return false to tell the chain that we'll manually call next() + return false; + }); + } + + + }); + +})(window); +(function(window) +{ + Gitana = window.Gitana; + + Gitana.AbstractPlatformObjectMap = Gitana.AbstractMap.extend( + /** @lends Gitana.AbstractPlatformObjectMap.prototype */ + { + /** + * @constructs + * @augments Gitana.AbstractMap + * + * @class AbstractPlatformObjectMap + * + * @param {Gitana.Platform} platform Gitana platform instance. + * @param {Object} object + */ + constructor: function(platform, object) + { + ////////////////////////////////////////////////////////////////////////////////////////////// + // + // PRIVILEGED METHODS + // + ////////////////////////////////////////////////////////////////////////////////////////////// + + this.getPlatform = function() + { + return platform; + }; + + this.getPlatformId = function() + { + return platform.getId(); + }; + + this.getCluster = function() + { + return platform.getCluster(); + }; + + this.getClusterId = function() + { + return platform.getClusterId(); + }; + + // NOTE: call this last + this.base(platform.getDriver(), object); + } + + }); + +})(window); +(function(window) +{ + Gitana = window.Gitana; + + Gitana.Stack = Gitana.AbstractPlatformObject.extend( + /** @lends Gitana.Stack.prototype */ + { + /** + * @constructs + * @augments Gitana.AbstractPlatformObject + * + * @class Stack + * + * @param {Gitana.Platform} platform + * @param {Object} object json object (if no callback required for populating) + */ + constructor: function(platform, object) + { + this.base(platform, object); + + this.objectType = function() { return "Gitana.Stack"; }; + }, + + /** + * @OVERRIDE + */ + getType: function() + { + return Gitana.TypedIDConstants.TYPE_STACK; + }, + + /** + * @OVERRIDE + */ + getUri: function() + { + return "/stacks/" + this.getId(); + }, + + /** + * @override + */ + clone: function() + { + return this.getFactory().stack(this.getPlatform(), this); + }, + + getKey: function() + { + return this.get("key"); + }, + + + + + + ////////////////////////////////////////////////////////////////////////////////////////// + // + // TEAMABLE + // + ////////////////////////////////////////////////////////////////////////////////////////// + + /** + * Reads a team. + * + * @param teamKey + * + * @chainable team + */ + readTeam: function(teamKey) + { + const uriFunction = function() + { + return this.getUri() + "/teams/" + teamKey; + }; + + const chainable = this.getFactory().team(this.getPlatform(), this); + return this.chainGet(chainable, uriFunction); + }, + + /** + * Lists teams. + * + * @chainable map of teams + */ + listTeams: function(pagination) + { + const params = {}; + if (pagination) + { + Gitana.copyInto(params, pagination); + } + + const uriFunction = function() + { + return this.getUri() + "/teams"; + }; + + const chainable = this.getFactory().teamMap(this.getCluster(), this); + return this.chainGet(chainable, uriFunction, params); + }, + + /** + * Creates a team. + * + * @param teamKey + * @param object + * + * @chainable team + */ + createTeam: function(teamKey, object) + { + if (!object) + { + object = {}; + } + + const uriFunction = function() + { + return this.getUri() + "/teams?key=" + teamKey; + }; + + const self = this; + + const chainable = this.getFactory().team(this.getPlatform(), this); + return this.chainPostResponse(chainable, uriFunction, {}, object).then(function() { + + const chain = this; + + Chain(self).readTeam(teamKey).then(function() { + chain.handleResponse(this); + chain.next(); + }); + + // we manually advance the chain + return false; + }); + }, + + /** + * Gets the owners team + * + * @chained team + */ + readOwnersTeam: function() + { + return this.readTeam("owners"); + }, + + ////////////////////////////////////////////////////////////////////////////////////////// + // + // END OF TEAMABLE + // + ////////////////////////////////////////////////////////////////////////////////////////// + + + + + ////////////////////////////////////////////////////////////////////////////////////////// + // + // ROLE CONTAINER + // + ////////////////////////////////////////////////////////////////////////////////////////// + + /** + * Reads a role. + * + * @param roleKeyOrId + * @param inherited whether to check inherited role containers + * + * @chainable role + */ + readRole: function(roleKeyOrId, inherited) + { + const params = {}; + + if (inherited) + { + params.inherited = true; + } + + const uriFunction = function() + { + return this.getUri() + "/roles/" + roleKeyOrId; + }; + + const chainable = this.getFactory().role(this.getCluster(), this); + return this.chainGet(chainable, uriFunction, params); + }, + + /** + * Lists roles. + * + * @param inherited whether to draw from inherited role containers + * + * @chainable map of roles + */ + listRoles: function(inherited) + { + const params = {}; + + if (inherited) + { + params.inherited = true; + } + + const uriFunction = function() + { + return this.getUri() + "/roles"; + }; + + const chainable = this.getFactory().roleMap(this.getCluster(), this); + return this.chainGet(chainable, uriFunction, params); + }, + + /** + * Creates a role. + * + * @param roleKey + * @param object + * + * @chainable role + */ + createRole: function(roleKey, object) + { + if (!object) + { + object = {}; + } + object.roleKey = roleKey; + + const uriFunction = function() + { + return this.getUri() + "/roles"; + }; + + const self = this; + + const chainable = this.getFactory().role(this.getPlatform(), this, roleKey); + return this.chainPostResponse(chainable, uriFunction, {}, object).then(function() { + this.subchain(self).readRole(roleKey).then(function() { + Gitana.copyInto(chainable, this); + }); + }); + }, + + ////////////////////////////////////////////////////////////////////////////////////////// + // + // END OF ROLE CONTAINER + // + ////////////////////////////////////////////////////////////////////////////////////////// + + + + + + + ////////////////////////////////////////////////////////////////////////////////////////// + // + // ATTACHMENTS + // + ////////////////////////////////////////////////////////////////////////////////////////// + + /** + * Hands back an attachments map. + * + * @chained attachment map + * + * @param local + * + * @public + */ + listAttachments: Gitana.Methods.listAttachments(), + + /** + * Picks off a single attachment + * + * @chained attachment + * + * @param attachmentId + */ + attachment: function(attachmentId) + { + return this.listAttachments().select(attachmentId); + }, + + /** + * Creates an attachment. + * + * When using this method from within the JS driver, it really only works for text-based content such + * as JSON or text. + * + * @chained attachment + * + * @param attachmentId (use null or false for default attachment) + * @param contentType + * @param data + */ + attach: Gitana.Methods.attach(), + + /** + * Deletes an attachment. + * + * @param attachmentId + */ + unattach: Gitana.Methods.unattach(), + + /** + * Generates a URI to a preview resource. + */ + getPreviewUri: Gitana.Methods.getPreviewUri(), + + + + ////////////////////////////////////////////////////////////////////////////////////////// + // + // LOGS + // + ////////////////////////////////////////////////////////////////////////////////////////// + + /** + * Queries for log entries. + * + * @chained log entry map + * + * @param {Object} query Query for finding log entries. + * @param {Object} pagination pagination (optional) + */ + queryLogEntries: function(query, pagination) + { + const self = this; + const uriFunction = function() + { + return self.getUri() + "/logs/query"; + }; + + if (!query) + { + query = {}; + } + + const chainable = this.getFactory().logEntryMap(this.getCluster()); + + // prepare params (with pagination) + const params = {}; + if (pagination) + { + Gitana.copyInto(params, pagination); + } + + return this.chainPost(chainable, uriFunction, params, query); + }, + + /** + * Read a log entry. + * + * @chained log entry + * + * @param {String} logEntryId + */ + readLogEntry: function(logEntryId) + { + const self = this; + const uriFunction = function() + { + return self.getUri() + "/logs/" + logEntryId; + }; + + const chainable = this.getFactory().logEntry(this.getCluster()); + + return this.chainGet(chainable, uriFunction); + }, + + /** + * Reads the last 100 lines of the log as text. + * The callback receives the text as the argument. + * + * @param callback + */ + readLog: function(callback) + { + + const uriFunction = function () { + return this.getUri() + "/logs/logfile"; + }; + + return this.chainGetResponseText(this, uriFunction).then(function(text) { + callback.call(this, text); + }); + }, + + + + ////////////////////////////////////////////////////////////////////////////////////////// + // + // STACK OPERATIONS + // + ////////////////////////////////////////////////////////////////////////////////////////// + + /** + * Assigns a data store to the stack + * It takes datastore and key (optional) as input or a json object than contains + * datastore type, id and key (optional) + * + * @chained this + * + * @param {Gitana.DataStore} datastore a platform datastore + * @param {String} key optional key + */ + assignDataStore: function(datastore, key) + { + const self = this; + + const uriFunction = function() + { + return self.getUri() + "/datastores/assign"; + }; + + const args = Gitana.makeArray(arguments); + + let params; + + if (args.length === 1) + { + const arg = args.shift(); + + if (arg.getType && arg.getId) + { + params = { + "type": arg.getType(), + "id": arg.getId() + }; + } + else + { + params = arg; + } + } + else + { + datastore = args.shift(); + key = args.shift(); + params = { + "type": datastore.getType(), + "id": datastore.getId() + }; + + if (key) + { + params["key"] = key; + } + } + + return this.chainPostEmpty(null, uriFunction, params); + }, + + /** + * Unassigns a data store from the stack + * + * @chained this + * + * @param {String} key optional key + */ + unassignDataStore: function(key) + { + const self = this; + + const uriFunction = function() + { + return self.getUri() + "/datastores/unassign"; + }; + + const params = { + "key": key + }; + + return this.chainPostEmpty(null, uriFunction, params); + + }, + + /** + * Lists the data stores in this stack. + * + * @chained datastore map + * + * @param pagination + */ + listDataStores: function(pagination) + { + const self = this; + + const uriFunction = function() + { + return self.getUri() + "/datastores"; + }; + + const chainable = this.getFactory().platformDataStoreMap(this.getPlatform()); + + // prepare params (with pagination) + const params = {}; + if (pagination) + { + Gitana.copyInto(params, pagination); + } + + return this.chainGet(chainable, uriFunction, params); + }, + + /** + * Lists the data stores in this stack. + * + * @chained datastore map + * + * @param {Object} query + * @param {Object} pagination pagination (optional) + */ + queryDataStores: function(query, pagination) + { + const self = this; + + // prepare params (with pagination) + const params = {}; + if (pagination) + { + Gitana.copyInto(params, pagination); + } + + const uriFunction = function() + { + return self.getUri() + "/datastores/query"; + }; + + const chainable = this.getFactory().platformDataStoreMap(this.getPlatform()); + + return this.chainPost(chainable, uriFunction, params, query); + }, + + /** + * Checks whether a datastore exists for the given key on this stack. + * This passes the result (true/false) to the chaining function. + * + * @chained this + * + * @param {String} key the datastore key + * @param {Function} callback + */ + existsDataStore: function(key, callback) + { + const self = this; + + const uriFunction = function() + { + return self.getUri() + "/datastores/exists?key=" + key; + }; + + return this.chainPostResponse(this, uriFunction).then(function(response) { + callback.call(this, response["exists"]); + }); + }, + + /** + * Reads a data store for this stack by its key. + * + * @chained this + * + * @param {String} key the datastore key + * @param [callback] a callback receiver to grab the actual typed object once retrieved + */ + readDataStore: function(key, callback) + { + const self = this; + + return this.then(function() { + + const chain = this; + + Chain(self).queryDataStores().then(function() { + + const datastore = this[key]; + datastore["_doc"] = datastore["datastoreId"]; + delete datastore["datastoreTypeId"]; + + if (callback) + { + callback.call(datastore); + } + + chain.next(); + }); + + // NOTE: we return false to tell the chain that we'll manually call next() + return false; + }); + } + + }); + +})(window); +(function(window) +{ + Gitana = window.Gitana; + + Gitana.StackMap = Gitana.AbstractPlatformObjectMap.extend( + /** @lends Gitana.StackMap.prototype */ + { + /** + * @constructs + * @augments Gitana.AbstractMap + * + * @class Map of stacks + * + * @param {Gitana.Platform} platform Gitana platform instance. + * @param {Object} object + */ + constructor: function(platform, object) + { + this.objectType = function() { return "Gitana.StackMap"; }; + + + ////////////////////////////////////////////////////////////////////////////////////////////// + // + // CALL THROUGH TO BASE CLASS (at the end) + // + ////////////////////////////////////////////////////////////////////////////////////////////// + + this.base(platform, object); + }, + + /** + * @override + */ + clone: function() + { + return this.getFactory().stackMap(this.getPlatform(), this); + }, + + /** + * @param json + */ + buildObject: function(json) + { + return this.getFactory().stack(this.getPlatform(), json); + } + + }); + +})(window); +(function(window) +{ + Gitana = window.Gitana; + + Gitana.Client = Gitana.AbstractPlatformObject.extend( + /** @lends Gitana.Client.prototype */ + { + /** + * @constructs + * @augments Gitana.AbstractPlatformObject + * + * @class Client + * + * @param {Gitana.Platform} platform + * @param {Object} object json object (if no callback required for populating) + */ + constructor: function(platform, object) + { + this.base(platform, object); + + this.objectType = function() { return "Gitana.Client"; }; + }, + + /** + * @OVERRIDE + */ + getType: function() + { + return Gitana.TypedIDConstants.TYPE_CLIENT; + }, + + /** + * @OVERRIDE + */ + getUri: function() + { + return "/clients/" + this.getId(); + }, + + /** + * @override + */ + clone: function() + { + return this.getFactory().client(this.getPlatform(), this); + }, + + /** + * Gets the authorized grant types for the client + */ + getAuthorizedGrantTypes: function() + { + return this.get("authorizedGrantTypes"); + }, + + /** + * Gets the scope for the client + */ + getScope: function() + { + return this.get("scope"); + }, + + /** + * Gets the allow open driver authentication option for the client + */ + getAllowOpenDriverAuthentication: function() + { + return this.get("allowOpenDriverAuthentication"); + }, + + /** + * Returns whether the client is enabled or not + */ + getEnabled: function() + { + return this.get("enabled"); + }, + + /** + * Lists the authentication grants for this client + * + * @param pagination + * + * @chained authentication grant map + */ + listAuthenticationGrants: function(pagination) + { + const params = {}; + if (pagination) + { + Gitana.copyInto(params, pagination); + } + + params.clientId = this.getId(); + + const chainable = this.getFactory().authenticationGrantMap(this.getPlatform()); + return this.chainGet(chainable, "/auth/grants", params); + } + + }); + +})(window); +(function(window) +{ + Gitana = window.Gitana; + + Gitana.ClientMap = Gitana.AbstractPlatformObjectMap.extend( + /** @lends Gitana.ClientMap.prototype */ + { + /** + * @constructs + * @augments Gitana.AbstractMap + * + * @class Map of clients + * + * @param {Gitana.Platform} platform Gitana platform instance. + * @param {Object} object + */ + constructor: function(platform, object) + { + this.objectType = function() { return "Gitana.ClientMap"; }; + + + ////////////////////////////////////////////////////////////////////////////////////////////// + // + // CALL THROUGH TO BASE CLASS (at the end) + // + ////////////////////////////////////////////////////////////////////////////////////////////// + + this.base(platform, object); + }, + + /** + * @override + */ + clone: function() + { + return this.getFactory().clientMap(this.getPlatform(), this); + }, + + /** + * @param json + */ + buildObject: function(json) + { + return this.getFactory().client(this.getPlatform(), json); + } + + }); + +})(window); +(function(window) +{ + Gitana = window.Gitana; + + Gitana.AuthenticationGrant = Gitana.AbstractPlatformObject.extend( + /** @lends Gitana.AuthenticationGrant.prototype */ + { + /** + * @constructs + * @augments Gitana.AbstractPlatformObject + * + * @class AuthenticationGrant + * + * @param {Gitana.Platform} platform + * @param {Object} object json object (if no callback required for populating) + */ + constructor: function(platform, object) + { + this.base(platform, object); + + this.objectType = function() { return "Gitana.AuthenticationGrant"; }; + }, + + /** + * @OVERRIDE + */ + getType: function() + { + return Gitana.TypedIDConstants.TYPE_AUTHENTICATION_GRANT; + }, + + /** + * @OVERRIDE + */ + getUri: function() + { + return "/auth/grants/" + this.getId(); + }, + + /** + * @override + */ + clone: function() + { + return this.getFactory().authenticationGrant(this.getPlatform(), this); + }, + + + /////////////////////////////// + // AUTH GRANT OPERATIONS + /////////////////////////////// + + getKey: function() + { + return this.get("key"); + }, + + getSecret: function() + { + return this.get("secret"); + }, + + getPrincipalDomainId: function() + { + return this.get("principalDomainId"); + }, + + getPrincipalId: function() + { + return this.get("principalId"); + }, + + getClientId: function() + { + return this.get("clientId"); + }, + + getEnabled: function() + { + return this.get("enabled"); + }, + + getAllowOpenDriverAuthentication: function() + { + return this.get("allowOpenDriverAuthentication"); + } + + }); + +})(window); +(function(window) +{ + Gitana = window.Gitana; + + Gitana.AuthenticationGrantMap = Gitana.AbstractPlatformObjectMap.extend( + /** @lends Gitana.AuthenticationGrantMap.prototype */ + { + /** + * @constructs + * @augments Gitana.AbstractMap + * + * @class Map of authentication grants + * + * @param {Gitana.Platform} platform Gitana platform instance. + * @param {Object} object + */ + constructor: function(platform, object) + { + this.objectType = function() { return "Gitana.AuthenticationGrantMap"; }; + + + ////////////////////////////////////////////////////////////////////////////////////////////// + // + // CALL THROUGH TO BASE CLASS (at the end) + // + ////////////////////////////////////////////////////////////////////////////////////////////// + + this.base(platform, object); + }, + + /** + * @override + */ + clone: function() + { + return this.getFactory().authenticationGrantMap(this.getPlatform(), this); + }, + + /** + * @param json + */ + buildObject: function(json) + { + return this.getFactory().authenticationGrant(this.getPlatform(), json); + } + + }); + +})(window); +(function(window) +{ + Gitana = window.Gitana; + + Gitana.PlatformDataStoreMap = Gitana.AbstractMap.extend( + /** @lends Gitana.PlatformDataStoreMap.prototype */ + { + /** + * @constructs + * @augments Gitana.AbstractMap + * + * @class Map of platform datastore objects + * + * @param {Gitana} platform Gitana platform + * @param {Object} object + */ + constructor: function(platform, object) + { + this.objectType = function() { return "Gitana.PlatformDataStoreMap"; }; + + this.getPlatform = function() + { + return platform; + }; + + ////////////////////////////////////////////////////////////////////////////////////////////// + // + // CALL THROUGH TO BASE CLASS (at the end) + // + ////////////////////////////////////////////////////////////////////////////////////////////// + + this.base(platform.getDriver(), object); + }, + + /** + * @override + */ + clone: function() + { + return this.getFactory().platformDataStoreMap(this.getPlatform(), this); + }, + + /** + * @param json + */ + buildObject: function(json) + { + return this.getFactory().platformDataStore(this.getPlatform(), json); + } + + }); + +})(window); +(function(window) +{ + Gitana = window.Gitana; + + Gitana.DeploymentReceiver = Gitana.AbstractPlatformObject.extend( + /** @lends Gitana.DeploymentReceiver.prototype */ + { + /** + * @constructs + * @augments Gitana.AbstractPlatformObject + * + * @class DeploymentReceiver + * + * @param {Gitana.Platform} platform + * @param {Object} object json object (if no callback required for populating) + */ + constructor: function(platform, object) + { + this.base(platform, object); + + this.objectType = function() { return "Gitana.DeploymentReceiver"; }; + }, + + /** + * @OVERRIDE + */ + getType: function() + { + return Gitana.TypedIDConstants.TYPE_DEPLOYMENT_RECEIVER; + }, + + /** + * @OVERRIDE + */ + getUri: function() + { + return "/deployment/receivers/" + this.getId(); + }, + + /** + * @override + */ + clone: function() + { + return this.getFactory().deploymentReceiver(this.getPlatform(), this); + } + + }); + +})(window); +(function(window) +{ + Gitana = window.Gitana; + + Gitana.DeploymentReceiverMap = Gitana.AbstractPlatformObjectMap.extend( + /** @lends Gitana.DeploymentReceiverMap.prototype */ + { + /** + * @constructs + * @augments Gitana.AbstractMap + * + * @class Map of deployment receivers + * + * @param {Gitana.Platform} platform Gitana platform instance. + * @param {Object} object + */ + constructor: function(platform, object) + { + this.objectType = function() { return "Gitana.DeploymentReceiverMap"; }; + + + ////////////////////////////////////////////////////////////////////////////////////////////// + // + // CALL THROUGH TO BASE CLASS (at the end) + // + ////////////////////////////////////////////////////////////////////////////////////////////// + + this.base(platform, object); + }, + + /** + * @override + */ + clone: function() + { + return this.getFactory().deploymentReceiverMap(this.getPlatform(), this); + }, + + /** + * @param json + */ + buildObject: function(json) + { + return this.getFactory().deploymentReceiver(this.getPlatform(), json); + } + + }); + +})(window); +(function(window) +{ + Gitana = window.Gitana; + + Gitana.DeploymentPackage = Gitana.AbstractPlatformObject.extend( + /** @lends Gitana.DeploymentPackage.prototype */ + { + /** + * @constructs + * @augments Gitana.AbstractPlatformObject + * + * @class DeploymentPackage + * + * @param {Gitana.Platform} platform + * @param {Object} object json object (if no callback required for populating) + */ + constructor: function(platform, object) + { + this.base(platform, object); + + this.objectType = function() { return "Gitana.DeploymentPackage"; }; + }, + + /** + * @OVERRIDE + */ + getType: function() + { + return Gitana.TypedIDConstants.TYPE_DEPLOYMENT_PACKAGE; + }, + + /** + * @OVERRIDE + */ + getUri: function() + { + return "/deployment/packages/" + this.getId(); + }, + + /** + * @override + */ + clone: function() + { + return this.getFactory().deploymentPackage(this.getPlatform(), this); + } + + }); + +})(window); +(function(window) +{ + Gitana = window.Gitana; + + Gitana.DeploymentPackageMap = Gitana.AbstractPlatformObjectMap.extend( + /** @lends Gitana.DeploymentPackageMap.prototype */ + { + /** + * @constructs + * @augments Gitana.AbstractMap + * + * @class Map of deployment packages + * + * @param {Gitana.Platform} platform Gitana platform instance. + * @param {Object} object + */ + constructor: function(platform, object) + { + this.objectType = function() { return "Gitana.DeploymentPackageMap"; }; + + + ////////////////////////////////////////////////////////////////////////////////////////////// + // + // CALL THROUGH TO BASE CLASS (at the end) + // + ////////////////////////////////////////////////////////////////////////////////////////////// + + this.base(platform, object); + }, + + /** + * @override + */ + clone: function() + { + return this.getFactory().deploymentPackageMap(this.getPlatform(), this); + }, + + /** + * @param json + */ + buildObject: function(json) + { + return this.getFactory().deploymentPackage(this.getPlatform(), json); + } + + }); + +})(window); +(function(window) +{ + Gitana = window.Gitana; + + Gitana.DeploymentStrategy = Gitana.AbstractPlatformObject.extend( + /** @lends Gitana.DeploymentStrategy.prototype */ + { + /** + * @constructs + * @augments Gitana.AbstractPlatformObject + * + * @class DeploymentStrategy + * + * @param {Gitana.Platform} platform + * @param {Object} object json object (if no callback required for populating) + */ + constructor: function(platform, object) + { + this.base(platform, object); + + this.objectType = function() { return "Gitana.DeploymentStrategy"; }; + }, + + /** + * @OVERRIDE + */ + getType: function() + { + return Gitana.TypedIDConstants.TYPE_DEPLOYMENT_STRATEGY; + }, + + /** + * @OVERRIDE + */ + getUri: function() + { + return "/deployment/strategies/" + this.getId(); + }, + + /** + * @override + */ + clone: function() + { + return this.getFactory().deploymentStrategy(this.getPlatform(), this); + } + + }); + +})(window); +(function(window) +{ + Gitana = window.Gitana; + + Gitana.DeploymentStrategyMap = Gitana.AbstractPlatformObjectMap.extend( + /** @lends Gitana.DeploymentStrategyMap.prototype */ + { + /** + * @constructs + * @augments Gitana.AbstractMap + * + * @class Map of deployment strategies + * + * @param {Gitana.Platform} platform Gitana platform instance. + * @param {Object} object + */ + constructor: function(platform, object) + { + this.objectType = function() { return "Gitana.DeploymentStrategyMap"; }; + + + ////////////////////////////////////////////////////////////////////////////////////////////// + // + // CALL THROUGH TO BASE CLASS (at the end) + // + ////////////////////////////////////////////////////////////////////////////////////////////// + + this.base(platform, object); + }, + + /** + * @override + */ + clone: function() + { + return this.getFactory().deploymentStrategyMap(this.getPlatform(), this); + }, + + /** + * @param json + */ + buildObject: function(json) + { + return this.getFactory().deploymentStrategy(this.getPlatform(), json); + } + + }); + +})(window); +(function(window) +{ + Gitana = window.Gitana; + + Gitana.DeploymentTarget = Gitana.AbstractPlatformObject.extend( + /** @lends Gitana.DeploymentTarget.prototype */ + { + /** + * @constructs + * @augments Gitana.AbstractPlatformObject + * + * @class DeploymentTarget + * + * @param {Gitana.Platform} platform + * @param {Object} object json object (if no callback required for populating) + */ + constructor: function(platform, object) + { + this.base(platform, object); + + this.objectType = function() { return "Gitana.DeploymentTarget"; }; + }, + + /** + * @OVERRIDE + */ + getType: function() + { + return Gitana.TypedIDConstants.TYPE_DEPLOYMENT_TARGET; + }, + + /** + * @OVERRIDE + */ + getUri: function() + { + return "/deployment/targets/" + this.getId(); + }, + + /** + * @override + */ + clone: function() + { + return this.getFactory().deploymentTarget(this.getPlatform(), this); + } + + }); + +})(window); +(function(window) +{ + Gitana = window.Gitana; + + Gitana.DeploymentTargetMap = Gitana.AbstractPlatformObjectMap.extend( + /** @lends Gitana.DeploymentTargetMap.prototype */ + { + /** + * @constructs + * @augments Gitana.AbstractMap + * + * @class Map of deployment targets + * + * @param {Gitana.Platform} platform Gitana platform instance. + * @param {Object} object + */ + constructor: function(platform, object) + { + this.objectType = function() { return "Gitana.DeploymentTargetMap"; }; + + + ////////////////////////////////////////////////////////////////////////////////////////////// + // + // CALL THROUGH TO BASE CLASS (at the end) + // + ////////////////////////////////////////////////////////////////////////////////////////////// + + this.base(platform, object); + }, + + /** + * @override + */ + clone: function() + { + return this.getFactory().deploymentTargetMap(this.getPlatform(), this); + }, + + /** + * @param json + */ + buildObject: function(json) + { + return this.getFactory().deploymentTarget(this.getPlatform(), json); + } + + }); + +})(window); +(function(window) +{ + Gitana = window.Gitana; + + Gitana.BillingProviderConfiguration = Gitana.AbstractPlatformObject.extend( + /** @lends Gitana.BillingProviderConfiguration.prototype */ + { + /** + * @constructs + * @augments Gitana.AbstractPlatformObject + * + * @class BillingProviderConfiguration + * + * @param {Gitana.Platform} platform + * @param {Object} object json object (if no callback required for populating) + */ + constructor: function(platform, object) + { + this.base(platform, object); + + this.objectType = function() { return "Gitana.BillingProviderConfiguration"; }; + }, + + /** + * @OVERRIDE + */ + getType: function() + { + return Gitana.TypedIDConstants.TYPE_BILLING_PROVIDER_CONFIGURATION; + }, + + /** + * @OVERRIDE + */ + getUri: function() + { + return "/billing/configurations/" + this.getId(); + }, + + /** + * @override + */ + clone: function() + { + return this.getFactory().billingProviderConfiguration(this.getPlatform(), this); + } + + }); + +})(window); +(function(window) +{ + Gitana = window.Gitana; + + Gitana.BillingProviderConfigurationMap = Gitana.AbstractPlatformObjectMap.extend( + /** @lends Gitana.BillingProviderConfigurationMap.prototype */ + { + /** + * @constructs + * @augments Gitana.AbstractMap + * + * @class Map of billing provider configurations + * + * @param {Gitana.Platform} platform Gitana platform instance. + * @param {Object} object + */ + constructor: function(platform, object) + { + this.objectType = function() { return "Gitana.BillingProviderConfigurationMap"; }; + + + ////////////////////////////////////////////////////////////////////////////////////////////// + // + // CALL THROUGH TO BASE CLASS (at the end) + // + ////////////////////////////////////////////////////////////////////////////////////////////// + + this.base(platform, object); + }, + + /** + * @override + */ + clone: function() + { + return this.getFactory().billingProviderConfigurationMap(this.getPlatform(), this); + }, + + /** + * @param json + */ + buildObject: function(json) + { + return this.getFactory().billingProviderConfiguration(this.getPlatform(), json); + } + + }); + +})(window); +(function(window) +{ + Gitana = window.Gitana; + + Gitana.Project = Gitana.AbstractPlatformObject.extend( + /** @lends Gitana.Project.prototype */ + { + /** + * @constructs + * @augments Gitana.AbstractPlatformObject + * + * @class Project + * + * @param {Gitana.Platform} platform + * @param {Object} object json object (if no callback required for populating) + */ + constructor: function(platform, object) + { + this.base(platform, object); + + this.objectType = function() { return "Gitana.Project"; }; + }, + + /** + * @OVERRIDE + */ + getType: function() + { + return Gitana.TypedIDConstants.TYPE_PROJECT; + }, + + /** + * @OVERRIDE + */ + getUri: function() + { + return "/projects/" + this.getId(); + }, + + /** + * @override + */ + clone: function() + { + return this.getFactory().project(this.getPlatform(), this); + }, + + + + + ////////////////////////////////////////////////////////////////////////////////////////// + // + // ATTACHMENTS + // + ////////////////////////////////////////////////////////////////////////////////////////// + + /** + * Hands back an attachments map. + * + * @chained attachment map + * + * @param local + * + * @public + */ + listAttachments: Gitana.Methods.listAttachments(), + + /** + * Picks off a single attachment + * + * @chained attachment + * + * @param attachmentId + */ + attachment: function(attachmentId) + { + return this.listAttachments().select(attachmentId); + }, + + /** + * Creates an attachment. + * + * When using this method from within the JS driver, it really only works for text-based content such + * as JSON or text. + * + * @chained attachment + * + * @param attachmentId (use null or false for default attachment) + * @param contentType + * @param data + */ + attach: Gitana.Methods.attach(), + + /** + * Deletes an attachment. + * + * @param attachmentId + */ + unattach: Gitana.Methods.unattach(), + + /** + * Generates a URI to a preview resource. + */ + getPreviewUri: Gitana.Methods.getPreviewUri(), + + /** + * Reads the stack for the project, if it exists. + * + * @chained stack + */ + readStack: function() + { + const self = this; + + const uriFunction = function() + { + return self.getPlatform().getUri() + "/stacks/" + self["stackId"]; + }; + + const chainable = this.getFactory().stack(this.getPlatform()); + return this.chainGet(chainable, uriFunction); + }, + + /////////////////////////////////////////////////////////////////////////////////////////////////////// + // + // ADMIN + // + /////////////////////////////////////////////////////////////////////////////////////////////////////// + + adminMaintenance: function() + { + const self = this; + + return this.then(function() { + + const chain = this; + + // call + const uri = self.getUri() + "/admin/maintenance"; + self.getDriver().gitanaPost(uri, null, {}, function() { + chain.next(); + }); + + // NOTE: we return false to tell the chain that we'll manually call next() + return false; + }); + }, + + /////////////////////////////////////////////////////////////////////////////////////////////////////// + // + // INVITE USER TO PROJECT + // + /////////////////////////////////////////////////////////////////////////////////////////////////////// + + inviteUser: function(userId) + { + const self = this; + + const params = {}; + params["id"] = userId; + + const uriFunction = function() + { + return self.getUri() + "/users/invite"; + }; + + return this.chainPostEmpty(null, uriFunction, params); + } + + }); + +})(window); +(function(window) +{ + Gitana = window.Gitana; + + Gitana.ProjectMap = Gitana.AbstractPlatformObjectMap.extend( + /** @lends Gitana.ProjectMap.prototype */ + { + /** + * @constructs + * @augments Gitana.AbstractMap + * + * @class Map of projects + * + * @param {Gitana.Platform} platform Gitana platform instance. + * @param {Object} object + */ + constructor: function(platform, object) + { + this.objectType = function() { return "Gitana.ProjectMap"; }; + + + ////////////////////////////////////////////////////////////////////////////////////////////// + // + // CALL THROUGH TO BASE CLASS (at the end) + // + ////////////////////////////////////////////////////////////////////////////////////////////// + + this.base(platform, object); + }, + + /** + * @override + */ + clone: function() + { + return this.getFactory().projectMap(this.getPlatform(), this); + }, + + /** + * @param json + */ + buildObject: function(json) + { + return this.getFactory().project(this.getPlatform(), json); + } + + }); + +})(window); +(function(window) +{ + Gitana = window.Gitana; + + Gitana.Descriptor = Gitana.AbstractPlatformObject.extend( + /** @lends Gitana.Descriptor.prototype */ + { + /** + * @constructs + * @augments Gitana.AbstractPlatformObject + * + * @class Descriptor + * + * @param {Gitana.Platform} platform + * @param {Object} object json object (if no callback required for populating) + */ + constructor: function(platform, object) + { + this.base(platform, object); + + this.objectType = function() { return "Gitana.Descriptor"; }; + }, + + /** + * @OVERRIDE + */ + getType: function() + { + return Gitana.TypedIDConstants.TYPE_DESCRIPTOR; + }, + + /** + * @OVERRIDE + */ + getUri: function() + { + return "/descriptors/" + this.getId(); + }, + + /** + * @override + */ + clone: function() + { + return this.getFactory().descriptor(this.getPlatform(), this); + }, + + /** + * Tests whether the service works for this descriptor. + * + * @param data + * @param callback + * @returns {*} + */ + test: function(data, callback) + { + const self = this; + + if (typeof(data) === "function") + { + callback = data; + data = {}; + } + + const uriFunction = function() + { + return self.getUri() + "/test"; + }; + + const params = {}; + + return this.chainPostResponse(this, uriFunction, params, data).then(function(response) { + callback(response); + }); + } + + }); + +})(window); +(function(window) +{ + Gitana = window.Gitana; + + Gitana.DescriptorMap = Gitana.AbstractPlatformObjectMap.extend( + /** @lends Gitana.DescriptorMap.prototype */ + { + /** + * @constructs + * @augments Gitana.AbstractMap + * + * @class Map of descriptors + * + * @param {Gitana.Platform} platform Gitana platform instance. + * @param {Object} object + */ + constructor: function(platform, object) + { + this.objectType = function() { return "Gitana.DescriptorMap"; }; + + + ////////////////////////////////////////////////////////////////////////////////////////////// + // + // CALL THROUGH TO BASE CLASS (at the end) + // + ////////////////////////////////////////////////////////////////////////////////////////////// + + this.base(platform, object); + }, + + /** + * @override + */ + clone: function() + { + return this.getFactory().descriptorMap(this.getPlatform(), this); + }, + + /** + * @param json + */ + buildObject: function(json) + { + return this.getFactory().descriptor(this.getPlatform(), json); + } + + }); + +})(window); +(function(window) +{ + Gitana = window.Gitana; + + Gitana.UIConfig = Gitana.AbstractPlatformObject.extend( + /** @lends Gitana.UIConfig.prototype */ + { + /** + * @constructs + * @augments Gitana.AbstractPlatformObject + * + * @class UIConfig + * + * @param {Gitana.Platform} platform + * @param {Object} object json object (if no callback required for populating) + */ + constructor: function(platform, object) + { + this.base(platform, object); + + this.objectType = function() { return "Gitana.UIConfig"; }; + }, + + /** + * @OVERRIDE + */ + getType: function() + { + return Gitana.TypedIDConstants.TYPE_UICONFIG; + }, + + /** + * @OVERRIDE + */ + getUri: function() + { + return "/uiconfigs/" + this.getId(); + }, + + /** + * @override + */ + clone: function() + { + return this.getFactory().uiConfig(this.getPlatform(), this); + } + }); + +})(window); +(function(window) +{ + Gitana = window.Gitana; + + Gitana.UIConfigMap = Gitana.AbstractPlatformObjectMap.extend( + /** @lends Gitana.UIConfigMap.prototype */ + { + /** + * @constructs + * @augments Gitana.AbstractMap + * + * @class Map of ui configs + * + * @param {Gitana.Platform} platform Gitana platform instance. + * @param {Object} object + */ + constructor: function(platform, object) + { + this.objectType = function() { return "Gitana.UIConfigMap"; }; + + + ////////////////////////////////////////////////////////////////////////////////////////////// + // + // CALL THROUGH TO BASE CLASS (at the end) + // + ////////////////////////////////////////////////////////////////////////////////////////////// + + this.base(platform, object); + }, + + /** + * @override + */ + clone: function() + { + return this.getFactory().uiConfigMap(this.getPlatform(), this); + }, + + /** + * @param json + */ + buildObject: function(json) + { + return this.getFactory().uiConfig(this.getPlatform(), json); + } + + }); + +})(window); +(function(window) +{ + Gitana = window.Gitana; + + Gitana.ScheduledWork = Gitana.AbstractPlatformObject.extend( + /** @lends Gitana.ScheduledWork.prototype */ + { + /** + * @constructs + * @augments Gitana.AbstractPlatformObject + * + * @class ScheduledWork + * + * @param {Gitana.Platform} platform + * @param {Object} object json object (if no callback required for populating) + */ + constructor: function(platform, object) + { + this.base(platform, object); + + this.objectType = function() { return "Gitana.ScheduledWork"; }; + }, + + /** + * @OVERRIDE + */ + getType: function() + { + return Gitana.TypedIDConstants.TYPE_SCHEDULED_WORK; + }, + + /** + * @OVERRIDE + */ + getUri: function() + { + return "/work/scheduled/" + this.getId(); + }, + + /** + * @override + */ + clone: function() + { + return this.getFactory().scheduledWork(this.getPlatform(), this); + }, + + /** + * Manually triggers the scheduled + * @returns {*} + */ + trigger: function() + { + const self = this; + + return this.then(function() { + + const chain = this; + + // call + const uri = self.getUri() + "/trigger"; + self.getDriver().gitanaPost(uri, null, {}, function() { + chain.next(); + }); + + // NOTE: we return false to tell the chain that we'll manually call next() + return false; + }); + } + + }); + +})(window); +(function(window) +{ + Gitana = window.Gitana; + + Gitana.ScheduledWorkMap = Gitana.AbstractPlatformObjectMap.extend( + /** @lends Gitana.ScheduledWorkMap.prototype */ + { + /** + * @constructs + * @augments Gitana.AbstractMap + * + * @class Map of scheduled work items + * + * @param {Gitana.Platform} platform Gitana platform instance. + * @param {Object} object + */ + constructor: function(platform, object) + { + this.objectType = function() { return "Gitana.ScheduledWorkMap"; }; + + + ////////////////////////////////////////////////////////////////////////////////////////////// + // + // CALL THROUGH TO BASE CLASS (at the end) + // + ////////////////////////////////////////////////////////////////////////////////////////////// + + this.base(platform, object); + }, + + /** + * @override + */ + clone: function() + { + return this.getFactory().scheduledWorkMap(this.getPlatform(), this); + }, + + /** + * @param json + */ + buildObject: function(json) + { + return this.getFactory().scheduledWork(this.getPlatform(), json); + } + + }); + +})(window); +(function(window) +{ + Gitana = window.Gitana; + + Gitana.Report = Gitana.AbstractPlatformObject.extend( + /** @lends Gitana.Report.prototype */ + { + /** + * @constructs + * @augments Gitana.AbstractPlatformObject + * + * @class Report + * + * @param {Gitana.Platform} platform + * @param {Object} object json object (if no callback required for populating) + */ + constructor: function(platform, object) + { + this.base(platform, object); + + this.objectType = function() { return "Gitana.Report"; }; + }, + + /** + * @OVERRIDE + */ + getType: function() + { + return Gitana.TypedIDConstants.TYPE_REPORT; + }, + + /** + * @OVERRIDE + */ + getUri: function() + { + return "/reports/" + this.getId(); + }, + + /** + * @override + */ + clone: function() + { + return this.getFactory().report(this.getPlatform(), this); + } + + }); + +})(window); +(function(window) +{ + Gitana = window.Gitana; + + Gitana.ReportMap = Gitana.AbstractPlatformObjectMap.extend( + /** @lends Gitana.ReportMap.prototype */ + { + /** + * @constructs + * @augments Gitana.AbstractMap + * + * @class Map of reports + * + * @param {Gitana.Platform} platform Gitana platform instance. + * @param {Object} object + */ + constructor: function(platform, object) + { + this.objectType = function() { return "Gitana.ReportMap"; }; + + + ////////////////////////////////////////////////////////////////////////////////////////////// + // + // CALL THROUGH TO BASE CLASS (at the end) + // + ////////////////////////////////////////////////////////////////////////////////////////////// + + this.base(platform, object); + }, + + /** + * @override + */ + clone: function() + { + return this.getFactory().reportMap(this.getPlatform(), this); + }, + + /** + * @param json + */ + buildObject: function(json) + { + return this.getFactory().report(this.getPlatform(), json); + } + + }); + +})(window); +(function(window) +{ + Gitana = window.Gitana; + + Gitana.WorkflowInstance = Gitana.AbstractPlatformObject.extend( + /** @lends Gitana.WorkflowInstance.prototype */ + { + /** + * @constructs + * @augments Gitana.AbstractPlatformObject + * + * @class WorkflowInstance + * + * @param {Gitana.Platform} platform + * @param {Object} object json object (if no callback required for populating) + */ + constructor: function(platform, object) + { + this.base(platform, object); + + this.objectType = function() { return "Gitana.WorkflowInstance"; }; + + this.toReference = function(resource) + { + return resource.ref(); + }; + + this.toResourceId = function(resourceOrResourceId) + { + let id = resourceOrResourceId; + + if (resourceOrResourceId && resourceOrResourceId.getId) + { + id = resourceOrResourceId.getId(); + } + + return id; + }; + }, + + /** + * @OVERRIDE + */ + getType: function() + { + return Gitana.TypedIDConstants.TYPE_WORKFLOW_INSTANCE; + }, + + /** + * @OVERRIDE + */ + getUri: function() + { + return "/workflow/instances/" + this.getId(); + }, + + /** + * @override + */ + clone: function() + { + return this.getFactory().workflowInstance(this.getPlatform(), this); + }, + + + + ////////////////////////////////////////////////////////////////////////////////////////////////// + // + // ACCESSORS + // + ////////////////////////////////////////////////////////////////////////////////////////////////// + + loadResourceList: function(callback) + { + const uriFunction = function() + { + return this.getUri() + "/resources"; + }; + + return this.chainGetResponse(this, uriFunction).then(function(response) { + callback.call(this, response["rows"]); + }); + }, + + loadResource: function(id, callback) + { + const uriFunction = function() + { + return this.getUri() + "/resources/" + id; + }; + + return this.chainGetResponse(this, uriFunction).then(function(response) { + callback.call(this, response); + }); + }, + + addResource: function(resource) + { + const uriFunction = function() + { + return this.getUri() + "/resources/add"; + }; + + const reference = this.toReference(resource); + + const params = { + "reference": reference + }; + + return this.chainPostResponse(this, uriFunction, params); + }, + + removeResource: function(resourceOrResourceId) + { + const uriFunction = function() + { + const resourceId = this.toResourceId(resourceOrResourceId); + + return this.getUri() + "/resources/" + resourceId + "/remove"; + }; + + return this.chainPostResponse(this, uriFunction); + }, + + removeAllResources: function() + { + const uriFunction = function() + { + return this.getUri() + "/resources/removeall"; + }; + + return this.chainPostResponse(this, uriFunction); + }, + + /** + * Starts the workflow. The workflow can only be started once. If already started, + * an error will be thrown. + * + * @param {Object} data + * + * @returns {*} + */ + start: function(data) + { + const uriFunction = function() + { + return this.getUri() + "/start"; + }; + + return this.chainPost(this, uriFunction, {}, data); + }, + + /** + * Terminates the workflow. A workflow can only be terminated once. If already terminated, + * an error will be thrown. + * + * @returns {*} + */ + terminate: function() + { + const uriFunction = function() + { + return this.getUri() + "/terminate"; + }; + + return this.chainPostResponse(this, uriFunction); + }, + + /** + * Suspends the workflow. + * + * @returns {*} + */ + suspend: function() + { + const uriFunction = function() + { + return this.getUri() + "/suspend"; + }; + + return this.chainPostResponse(this, uriFunction); + }, + + /** + * Resumes the workflow. + * + * @returns {*} + */ + resume: function() + { + const uriFunction = function() + { + return this.getUri() + "/resume"; + }; + + return this.chainPostResponse(this, uriFunction); + }, + + /** + * Upgrades the model for this workflow. + * + * @returns {*} + */ + upgradeModel: function(newModel, newModelVersion) + { + const uriFunction = function() + { + return this.getUri() + "/upgrade"; + }; + + const params = { + "id": newModel, + "version": newModelVersion + }; + + return this.chainPost(this, uriFunction, params); + } + + }); + +})(window); +(function(window) +{ + Gitana = window.Gitana; + + Gitana.WorkflowInstanceMap = Gitana.AbstractPlatformObjectMap.extend( + /** @lends Gitana.WorkflowInstanceMap.prototype */ + { + /** + * @constructs + * @augments Gitana.AbstractMap + * + * @class Map of workflow instances + * + * @param {Gitana.Platform} platform Gitana platform instance. + * @param {Object} object + */ + constructor: function(platform, object) + { + this.objectType = function() { return "Gitana.WorkflowInstanceMap"; }; + + + ////////////////////////////////////////////////////////////////////////////////////////////// + // + // CALL THROUGH TO BASE CLASS (at the end) + // + ////////////////////////////////////////////////////////////////////////////////////////////// + + this.base(platform, object); + }, + + /** + * @override + */ + clone: function() + { + return this.getFactory().workflowInstanceMap(this.getPlatform(), this); + }, + + /** + * @param json + */ + buildObject: function(json) + { + return this.getFactory().workflowInstance(this.getPlatform(), json); + } + + }); + +})(window); +(function(window) +{ + Gitana = window.Gitana; + + Gitana.WorkflowModel = Gitana.AbstractPlatformObject.extend( + /** @lends Gitana.WorkflowModel.prototype */ + { + /** + * @constructs + * @augments Gitana.AbstractPlatformObject + * + * @class WorkflowModel + * + * @param {Gitana.Platform} platform + * @param {Object} object json object (if no callback required for populating) + */ + constructor: function(platform, object) + { + this.base(platform, object); + + this.objectType = function() { return "Gitana.WorkflowModel"; }; + }, + + /** + * @OVERRIDE + */ + getType: function() + { + return Gitana.TypedIDConstants.TYPE_WORKFLOW_MODEL; + }, + + /** + * @OVERRIDE + */ + getUri: function() + { + return "/workflow/models/" + this.id + "/versions/" + this.version; + }, + + /** + * @override + */ + clone: function() + { + return this.getFactory().workflowModel(this.getPlatform(), this); + }, + + /** + * Update the workflow model. + * + * @param {String} force whether to force the update if the model is already deployed + * + * @chained this + * + * @public + */ + update: function(force) + { + const self = this; + + const params = {}; + + if (force) + { + params.force = true; + } + + const uriFunction = function() + { + return self.getUri(); + }; + + return this.chainUpdate(null, uriFunction, params); + }, + + /** + * Deploys this workflow model. + * + * @returns {*} + */ + deploy: function() + { + const self = this; + + const uriFunction = function() + { + return self.getUri() + "/deploy"; + }; + + return this.chainPostEmpty(null, uriFunction); + }, + + /** + * Undeploys this workflow model. + * + * @returns {*} + */ + undeploy: function() + { + const self = this; + + const uriFunction = function() + { + return self.getUri() + "/undeploy"; + }; + + return this.chainPostEmpty(null, uriFunction); + } + + }); + +})(window); +(function(window) +{ + Gitana = window.Gitana; + + Gitana.WorkflowModelMap = Gitana.AbstractPlatformObjectMap.extend( + /** @lends Gitana.WorkflowModelMap.prototype */ + { + /** + * @constructs + * @augments Gitana.AbstractMap + * + * @class Map of workflow models + * + * @param {Gitana.Platform} platform Gitana platform instance. + * @param {Object} object + */ + constructor: function(platform, object) + { + this.objectType = function() { return "Gitana.WorkflowModelMap"; }; + + + ////////////////////////////////////////////////////////////////////////////////////////////// + // + // CALL THROUGH TO BASE CLASS (at the end) + // + ////////////////////////////////////////////////////////////////////////////////////////////// + + this.base(platform, object); + }, + + /** + * @override + */ + clone: function() + { + return this.getFactory().workflowModelMap(this.getPlatform(), this); + }, + + /** + * @param json + */ + buildObject: function(json) + { + return this.getFactory().workflowModel(this.getPlatform(), json); + } + + }); + +})(window); +(function(window) +{ + Gitana = window.Gitana; + + Gitana.WorkflowTask = Gitana.AbstractPlatformObject.extend( + /** @lends Gitana.WorkflowTask.prototype */ + { + /** + * @constructs + * @augments Gitana.AbstractPlatformObject + * + * @class WorkflowTask + * + * @param {Gitana.Platform} platform + * @param {Object} object json object (if no callback required for populating) + */ + constructor: function(platform, object) + { + this.base(platform, object); + + this.objectType = function() { return "Gitana.WorkflowTask"; }; + + this.toReference = function(resource) + { + return resource.ref(); + }; + + this.toResourceId = function(resourceOrResourceId) + { + let id = resourceOrResourceId; + + if (resourceOrResourceId && resourceOrResourceId.getId) + { + id = resourceOrResourceId.getId(); + } + + return id; + }; + }, + + /** + * @OVERRIDE + */ + getType: function() + { + return Gitana.TypedIDConstants.TYPE_WORKFLOW_TASK; + }, + + /** + * @OVERRIDE + */ + getUri: function() + { + return "/workflow/tasks/" + this.getId(); + }, + + /** + * @override + */ + clone: function() + { + return this.getFactory().workflowTask(this.getPlatform(), this); + }, + + ////////////////////////////////////////////////////////////////////////////////////////////////// + // + // ACCESSORS + // + ////////////////////////////////////////////////////////////////////////////////////////////////// + + loadResourceList: function(callback) + { + const uriFunction = function() + { + return this.getUri() + "/resources"; + }; + + return this.chainGetResponse(this, uriFunction).then(function(response) { + callback.call(this, response["rows"]); + }); + }, + + loadResource: function(id, callback) + { + const uriFunction = function() + { + return this.getUri() + "/resources/" + id; + }; + + return this.chainGetResponse(this, uriFunction).then(function(response) { + callback.call(this, response); + }); + }, + + addResource: function(resource) + { + const uriFunction = function() + { + return this.getUri() + "/resources/add"; + }; + + const reference = this.toReference(resource); + + const params = { + "reference": reference + }; + + return this.chainPostResponse(this, uriFunction, params); + }, + + removeResource: function(resourceOrResourceId) + { + const uriFunction = function() + { + const resourceId = this.toResourceId(resourceOrResourceId); + + return this.getUri() + "/resources/" + resourceId + "/remove"; + }; + + return this.chainPostResponse(this, uriFunction); + }, + + removeAllResources: function() + { + const uriFunction = function() + { + return this.getUri() + "/resources/removeall"; + }; + + return this.chainPostResponse(this, uriFunction); + }, + + ////////////////////////////////////////////////////////////////////////////////////////////////// + // + // DELEGATION + // + ////////////////////////////////////////////////////////////////////////////////////////////////// + + /** + * Claims this task for the current user. + * + * @chained next task + * + * @public + */ + claim: function() + { + const uriFunction = function() + { + return this.getUri() + "/claim"; + }; + + const chainable = this.getFactory().workflowTask(this.getPlatform()); + return this.chainPost(chainable, uriFunction, {}, {}); + }, + + /** + * Unclaims this task for the current user. + * + * @chained next task + * + * @public + */ + unclaim: function() + { + const uriFunction = function() + { + return this.getUri() + "/unclaim"; + }; + + const chainable = this.getFactory().workflowTask(this.getPlatform()); + return this.chainPost(chainable, uriFunction, {}, {}); + }, + + /** + * Delegates this task from the current user to another user. + * + * @chained next task + * + * @param user + * + * @public + */ + delegate: function(user) + { + const userDomainQualifiedId = this.extractPrincipalDomainQualifiedId(user); + + const uriFunction = function() + { + return this.getUri() + "/delegate"; + }; + + const params = { + "userId": userDomainQualifiedId + }; + + const chainable = this.getFactory().workflowTask(this.getPlatform()); + return this.chainPost(chainable, uriFunction, params, {}); + }, + + /** + * Acquires a list of delegates to whom the current task can be assigned. + * + * @chained principal map + * + * @param {Object} pagination pagination (optional) + */ + listDelegates: function(pagination) + { + const self = this; + + // prepare params (with pagination) + const params = {}; + if (pagination) + { + Gitana.copyInto(params, pagination); + } + + const uriFunction = function() + { + return self.getUri() + "/delegates"; + }; + + // get to work + const chainable = this.getFactory().domainPrincipalMap(this); + + // all groups + return this.chainGet(chainable, uriFunction, params); + }, + + /** + * Completes this task. + * + * @param routeId + * @param data + * + * @chained next task + * + * @public + */ + complete: function(routeId, data) + { + const uriFunction = function() + { + return this.getUri() + "/complete"; + }; + + const params = { + "routeId": routeId + }; + + const chainable = this.getFactory().workflowTask(this.getPlatform()); + return this.chainPost(chainable, uriFunction, params, data); + }, + + /** + * Moves this task. This function requires the current user to have admin or manager rights over + * the workflow instance. + * + * @param workflowNodeId the workflow model node id to move to next + * @param data (optional) + * + * @chained next task + * + * @public + */ + move: function(workflowNodeId, data) + { + const uriFunction = function() + { + return this.getUri() + "/move"; + }; + + const params = { + "id": workflowNodeId + }; + + const chainable = this.getFactory().workflowTask(this.getPlatform()); + return this.chainPost(chainable, uriFunction, params, data); + }, + + loadRoutes: function(callback) + { + const uriFunction = function() + { + return this.getUri() + "/routes"; + }; + + return this.chainGetResponse(this, uriFunction).then(function(response) { + callback.call(this, response["routes"]); + }); + } + + }); + +})(window); +(function(window) +{ + Gitana = window.Gitana; + + Gitana.WorkflowTaskMap = Gitana.AbstractPlatformObjectMap.extend( + /** @lends Gitana.WorkflowTaskMap.prototype */ + { + /** + * @constructs + * @augments Gitana.AbstractMap + * + * @class Map of workflow tasks + * + * @param {Gitana.Platform} platform Gitana platform instance. + * @param {Object} object + */ + constructor: function(platform, object) + { + this.objectType = function() { return "Gitana.WorkflowTaskMap"; }; + + + ////////////////////////////////////////////////////////////////////////////////////////////// + // + // CALL THROUGH TO BASE CLASS (at the end) + // + ////////////////////////////////////////////////////////////////////////////////////////////// + + this.base(platform, object); + }, + + /** + * @override + */ + clone: function() + { + return this.getFactory().workflowTaskMap(this.getPlatform(), this); + }, + + /** + * @param json + */ + buildObject: function(json) + { + return this.getFactory().workflowTask(this.getPlatform(), json); + } + + }); + +})(window); +(function(window) +{ + Gitana = window.Gitana; + + Gitana.WorkflowComment = Gitana.AbstractPlatformObject.extend( + /** @lends Gitana.WorkflowComment.prototype */ + { + /** + * @constructs + * @augments Gitana.AbstractPlatformObject + * + * @class WorkflowComment + * + * @param {Gitana.Platform} platform + * @param {Object} object json object (if no callback required for populating) + */ + constructor: function(platform, object) + { + this.base(platform, object); + + this.objectType = function() { return "Gitana.WorkflowComment"; }; + }, + + /** + * @OVERRIDE + */ + getType: function() + { + return Gitana.TypedIDConstants.TYPE_WORKFLOW_COMMENT; + }, + + /** + * @OVERRIDE + */ + getUri: function() + { + return "/workflow/comments/" + this.getId(); + }, + + /** + * @override + */ + clone: function() + { + return this.getFactory().workflowComment(this.getPlatform(), this); + } + + }); + +})(window); +(function(window) +{ + Gitana = window.Gitana; + + Gitana.WorkflowCommentMap = Gitana.AbstractPlatformObjectMap.extend( + /** @lends Gitana.WorkflowCommentMap.prototype */ + { + /** + * @constructs + * @augments Gitana.AbstractMap + * + * @class Map of workflow comments + * + * @param {Gitana.Platform} platform Gitana platform instance. + * @param {Object} object + */ + constructor: function(platform, object) + { + this.objectType = function() { return "Gitana.WorkflowCommentMap"; }; + + + ////////////////////////////////////////////////////////////////////////////////////////////// + // + // CALL THROUGH TO BASE CLASS (at the end) + // + ////////////////////////////////////////////////////////////////////////////////////////////// + + this.base(platform, object); + }, + + /** + * @override + */ + clone: function() + { + return this.getFactory().workflowCommentMap(this.getPlatform(), this); + }, + + /** + * @param json + */ + buildObject: function(json) + { + return this.getFactory().workflowComment(this.getPlatform(), json); + } + + }); + +})(window); +(function(window) +{ + Gitana = window.Gitana; + + Gitana.ClientMethods = + { + getKey: function() + { + return this.get("key"); + }, + + getSecret: function() + { + return this.get("secret"); + }, + + getDomainUrls: function() + { + return this.get("domainUrls"); + }, + + getIsTenantDefault: function() + { + return this.get("isTenantDefault"); + }, + + getDefaultTenantId: function() + { + return this.get("defaultTenantId"); + }, + + getAuthorizedGrantTypes: function() + { + return this.get("authorizedGrantTypes"); + }, + + getScope: function() + { + return this.get("scope"); + }, + + getRegisteredRedirectUri: function() + { + return this.get("registeredRedirectUri"); + }, + + getAllowOpenDriverAuthentication: function() + { + return this.get("allowOpenDriverAuthentication"); + }, + + getEnabled: function() + { + return this.get("enabled"); + }, + + getAllowAutoApprovalForImplicitFlow: function() + { + return this.get("allowAutoApprovalForImplicitFlow"); + } + }; + +})(window); +(function(window) +{ + Gitana = window.Gitana; + + Gitana.Application = Gitana.AbstractPlatformDataStore.extend( + /** @lends Gitana.Application.prototype */ + { + /** + * @constructs + * @augments Gitana.AbstractPlatformObject + * + * @class Application + * + * @param {Gitana.Platform} platform + * @param {Object}object json object (if no callback required for populating) + */ + constructor: function(platform, object) + { + this.objectType = function() { return "Gitana.Application"; }; + + this.base(platform, object); + }, + + /** + * @OVERRIDE + */ + getUri: function() + { + return "/applications/" + this.getId(); + }, + + /** + * @OVERRIDE + */ + getType: function() + { + return Gitana.TypedIDConstants.TYPE_APPLICATION; + }, + + /** + * @override + */ + clone: function() + { + return this.getFactory().application(this.getPlatform(), this); + }, + + /** + * Lists the auto-client mappings maintained for this application. + * + * @param callback the callback function + * @param pagination + * + * @chained this + */ + listAutoClientMappingObjects: function(callback, pagination) + { + const self = this; + + const uriFunction = function () + { + return self.getUri() + '/autoclientmappings'; + }; + + // parameters + const params = {}; + if (pagination) + { + Gitana.copyInto(params, pagination); + } + + return this.chainGetResponse(this, uriFunction, params).then(function(response) { + callback.call(this, response["rows"]); + }); + }, + + /** + * Lists the trusted domain mappings maintained for this application. + * + * @param callback the callback function + * @param pagination + * + * @chained this + */ + listTrustedDomainMappingObjects: function(callback, pagination) + { + const self = this; + + const uriFunction = function() + { + return self.getUri() + "/trusteddomainmappings"; + }; + + // parameters + const params = {}; + if (pagination) + { + Gitana.copyInto(params, pagination); + } + + return this.chainGetResponse(this, uriFunction, params).then(function(response) { + callback.call(this, response["rows"]); + }); + }, + + + ////////////////////////////////////////////////////////////////////////////////////////// + // + // SETTINGS + // + ////////////////////////////////////////////////////////////////////////////////////////// + + /** + * Create settings + * + * @chained settings + * + * @param {Object} object JSON object + */ + createSettings: function(object) + { + const self = this; + + // Makes sure we have an empty settings key + if (object["settings"] === null) + { + object["settings"] = {}; + } + + const uriFunction = function() + { + return self.getUri() + "/settings"; + }; + + const chainable = this.getFactory().settings(this); + return this.chainCreate(chainable, object, uriFunction); + }, + + /** + * Lists the settings. + * + * @param pagination + * + * @chained settings map + */ + listSettings: function(pagination) + { + const self = this; + + const params = {}; + if (pagination) + { + Gitana.copyInto(params, pagination); + } + + const uriFunction = function() + { + return self.getUri() + "/settings"; + }; + + const chainable = this.getFactory().settingsMap(this); + return this.chainGet(chainable, uriFunction, params); + }, + + /** + * Reads an setting. + * + * @param settingId + * + * @chained settings + */ + readSettings: function(settingId) + { + const self = this; + + const uriFunction = function() + { + return self.getUri() + "/settings/" + settingId; + }; + + const chainable = this.getFactory().settings(this); + return this.chainGet(chainable, uriFunction); + }, + + /** + * Queries for settings. + * + * @chained settings map + * + * @param {Object} query + * @param {Object} pagination pagination (optional) + */ + querySettings: function(query, pagination) + { + const self = this; + + const params = {}; + if (pagination) + { + Gitana.copyInto(params, pagination); + } + + const uriFunction = function() + { + return self.getUri() + "/settings/query"; + }; + + const chainable = this.getFactory().settingsMap(this); + return this.chainPost(chainable, uriFunction, params, query); + }, + + /** + * Reads the application settings for the given scope and key. + * If the settings doesn't exist, creates an empty one. + * + * @param {String} scope (optional) + * @param {String} key (optional) + */ + readApplicationSettings: function(scope, key) + { + const self = this; + + if (scope === null) + { + scope = "application"; + } + + if (key === null) + { + key = "application"; + } + + const object = { + "scope" : scope, + "key" : key + }; + + const result = this.subchain(new Gitana.Settings(this, object)); + return result.then(function() { + + const chain = this; + const driver = self.getDriver(); + const createUri = self.getUri() + "/settings"; + const queryUri = self.getUri() + "/settings/query"; + + driver.gitanaPost(queryUri, {}, object, function(response) { + const settings = new Gitana.SettingsMap(self); + settings.handleResponse(response); + if (settings.__keys().length > 0) + { + const obj = settings[settings.__keys()[0]]; + chain.loadFrom(obj); + chain.next(); + } + else + { + object["settings"] = {}; + driver.gitanaPost(createUri, null, object, function(status) { + driver.gitanaGet(createUri + "/" + status.getId(), null, {}, function(response) { + chain.handleResponse(response); + chain.next(); + }, function(http) { + self.httpError(http); + }); + }, function(http) { + self.httpError(http); + }); + } + }, function(http) { + self.httpError(http); + }); + + return false; + }); + }, + + /** + * Reads the principal settings. It takes either a single Gitana.DomainPrincipal parameter + * or a domain Id parameter and a principal Id parameter. + */ + readApplicationPrincipalSettings: function() + { + const args = Gitana.makeArray(arguments); + + if (args.length === 1) + { + const principal = args.shift(); + return this.readApplicationSettings("principal", principal.getDomainQualifiedId()); + } + else if (args.length === 2) + { + const domainId = args.shift(); + const principalId = args.shift(); + return this.readApplicationSettings("principal", domainId + "/" + principalId); + } + + }, + + /** + * Performs a bulk check of permissions against permissioned objects of type settings. + * + * Example of checks array: + * + * [{ + * "permissionedId": "", + * "principalId": "", + * "permissionId": "" + * }] + * + * The callback receives an array of results, example: + * + * [{ + * "permissionedId": "", + * "principalId": "", + * "permissionId": "", + * "result": true + * }] + * + * The order of elements in the array will be the same for checks and results. + * + * @param checks + * @param callback + */ + checkSettingPermissions: function(checks, callback) + { + const self = this; + + const uriFunction = function() + { + return self.getUri() + "/settings/permissions/check"; + }; + + const object = { + "checks": checks + }; + + return this.chainPostResponse(this, uriFunction, {}, object).then(function(response) { + callback.call(this, response["results"]); + }); + }, + + /** + * Performs a bulk check of authorities against permissioned objects of type settings. + * + * Example of checks array: + * + * [{ + * "permissionedId": "", + * "principalId": "", + * "authorityId": "" + * }] + * + * The callback receives an array of results, example: + * + * [{ + * "permissionedId": "", + * "principalId": "", + * "authorityId": "", + * "result": true + * }] + * + * The order of elements in the array will be the same for checks and results. + * + * @param checks + * @param callback + */ + checkSettingAuthorities: function(checks, callback) + { + const self = this; + + const uriFunction = function() + { + return self.getUri() + "/settings/authorities/check"; + }; + + const object = { + "checks": checks + }; + + return this.chainPostResponse(this, uriFunction, {}, object).then(function(response) { + callback.call(this, response["results"]); + }); + }, + + + + + ////////////////////////////////////////////////////////////////////////////////////////// + // + // REGISTRATIONS + // + ////////////////////////////////////////////////////////////////////////////////////////// + + /** + * Create registration + * + * @chained registration + * + * @param {Object} object JSON object + */ + createRegistration: function(object) + { + const self = this; + + const chainable = this.getFactory().registration(this); + + const uriFunction = function() + { + return self.getUri() + "/registrations"; + }; + + return this.chainCreate(chainable, object, uriFunction); + }, + + /** + * Lists the registrations. + * + * @param pagination + * + * @chained registration map + */ + listRegistrations: function(pagination) + { + const self = this; + + const params = {}; + if (pagination) + { + Gitana.copyInto(params, pagination); + } + + const uriFunction = function() + { + return self.getUri() + "/registrations"; + }; + + const chainable = this.getFactory().registrationMap(this); + return this.chainGet(chainable, uriFunction, params); + }, + + /** + * Reads a registration. + * + * @param registrationId + * + * @chained registration + */ + readRegistration: function(registrationId) + { + const self = this; + + const chainable = this.getFactory().registration(this); + + const uriFunction = function() + { + return self.getUri() + "/registrations/" + registrationId; + }; + + return this.chainGet(chainable, uriFunction); + }, + + /** + * Queries for registrations. + * + * @chained registration map + * + * @param {Object} query + * @param {Object} pagination pagination (optional) + */ + queryRegistrations: function(query, pagination) + { + const self = this; + + const params = {}; + if (pagination) + { + Gitana.copyInto(params, pagination); + } + + const uriFunction = function() + { + return self.getUri() + "/registrations/query"; + }; + + const chainable = this.getFactory().registrationMap(this); + return this.chainPost(chainable, uriFunction, params, query); + }, + + /** + * Performs a bulk check of permissions against permissioned objects of type registration. + * + * Example of checks array: + * + * [{ + * "permissionedId": "", + * "principalId": "", + * "permissionId": "" + * }] + * + * The callback receives an array of results, example: + * + * [{ + * "permissionedId": "", + * "principalId": "", + * "permissionId": "", + * "result": true + * }] + * + * The order of elements in the array will be the same for checks and results. + * + * @param checks + * @param callback + */ + checkRegistrationPermissions: function(checks, callback) + { + const self = this; + + const uriFunction = function() + { + return self.getUri() + "/registrations/permissions/check"; + }; + + const object = { + "checks": checks + }; + + return this.chainPostResponse(this, uriFunction, {}, object).then(function(response) { + callback.call(this, response["results"]); + }); + }, + + /** + * Performs a bulk check of authorities against permissioned objects of type registration. + * + * Example of checks array: + * + * [{ + * "permissionedId": "", + * "principalId": "", + * "authorityId": "" + * }] + * + * The callback receives an array of results, example: + * + * [{ + * "permissionedId": "", + * "principalId": "", + * "authorityId": "", + * "result": true + * }] + * + * The order of elements in the array will be the same for checks and results. + * + * @param checks + * @param callback + */ + checkRegistrationAuthorities: function(checks, callback) + { + const self = this; + + const uriFunction = function() + { + return self.getUri() + "/registrations/authorities/check"; + }; + + const object = { + "checks": checks + }; + + return this.chainPostResponse(this, uriFunction, {}, object).then(function(response) { + callback.call(this, response["results"]); + }); + }, + + + + ////////////////////////////////////////////////////////////////////////////////////////// + // + // PAGE RENDITIONS + // + ////////////////////////////////////////////////////////////////////////////////////////// + + /** + * Create page rendition + * + * @chained page rendition + * + * @param {String} deploymentKey string key + * @param {Object} object JSON object + */ + createPageRendition: function(deploymentKey, object) + { + const self = this; + + const chainable = this.getFactory().pageRendition(this, deploymentKey); + + const uriFunction = function() + { + return self.getUri() + "/deployments/" + deploymentKey + "/pagerenditions"; + }; + + return this.chainCreate(chainable, object, uriFunction); + }, + + /** + * Lists the page renditions. + * + * @param {String} deploymentKey string key + * @param pagination + * + * @chained page rendition map + */ + listPageRenditions: function(deploymentKey, pagination) + { + const self = this; + + const params = {}; + if (pagination) + { + Gitana.copyInto(params, pagination); + } + + const uriFunction = function() + { + return self.getUri() + "/deployments/" + deploymentKey + "/pagerenditions"; + }; + + const chainable = this.getFactory().pageRenditionMap(this, deploymentKey); + return this.chainGet(chainable, uriFunction, params); + }, + + /** + * Reads a page rendition. + * + * @param {String} deploymentKey string key + * @param pageRenditionIdOrKey + * + * @chained registration + */ + readPageRendition: function(deploymentKey, pageRenditionIdOrKey) + { + const self = this; + + const chainable = this.getFactory().pageRendition(this, deploymentKey); + + const uriFunction = function() + { + return self.getUri() + "/deployments/" + deploymentKey + "/pagerenditions/" + pageRenditionIdOrKey; + }; + + return this.chainGet(chainable, uriFunction); + }, + + /** + * Queries for page renditions. + * + * @chained page rendition map + * + * @param {String} deploymentKey string key + * @param {Object} query + * @param {Object} pagination pagination (optional) + */ + queryPageRenditions: function(deploymentKey, query, pagination) + { + const self = this; + + const params = {}; + if (pagination) + { + Gitana.copyInto(params, pagination); + } + + const uriFunction = function() + { + return self.getUri() + "/deployments/" + deploymentKey + "/pagerenditions/query"; + }; + + const chainable = this.getFactory().pageRenditionMap(this, deploymentKey); + return this.chainPost(chainable, uriFunction, params, query); + }, + + /** + * Performs a bulk check of permissions against permissioned objects of type page rendition. + * + * Example of checks array: + * + * [{ + * "permissionedId": "", + * "principalId": "", + * "permissionId": "" + * }] + * + * The callback receives an array of results, example: + * + * [{ + * "permissionedId": "", + * "principalId": "", + * "permissionId": "", + * "result": true + * }] + * + * The order of elements in the array will be the same for checks and results. + * + * @param {String} deploymentKey string key + * @param checks + * @param callback + */ + checkPageRenditionPermissions: function(deploymentKey, checks, callback) + { + const self = this; + + const uriFunction = function() + { + return self.getUri() + "/deployments/" + deploymentKey + "/pagerenditions/permissions/check"; + }; + + const object = { + "checks": checks + }; + + return this.chainPostResponse(this, uriFunction, {}, object).then(function(response) { + callback.call(this, response["results"]); + }); + }, + + /** + * Performs a bulk check of authorities against permissioned objects of type page rendition. + * + * Example of checks array: + * + * [{ + * "permissionedId": "", + * "principalId": "", + * "authorityId": "" + * }] + * + * The callback receives an array of results, example: + * + * [{ + * "permissionedId": "", + * "principalId": "", + * "authorityId": "", + * "result": true + * }] + * + * The order of elements in the array will be the same for checks and results. + * + * @param {String} deploymentKey string key + * @param checks + * @param callback + */ + checkPageRenditionAuthorities: function(deploymentKey, checks, callback) + { + const self = this; + + const uriFunction = function() + { + return self.getUri() + "/deployments/" + deploymentKey + "/pagerenditions/authorities/check"; + }; + + const object = { + "checks": checks + }; + + return this.chainPostResponse(this, uriFunction, {}, object).then(function(response) { + callback.call(this, response["results"]); + }); + }, + + + + + ////////////////////////////////////////////////////////////////////////////////////////// + // + // EMAIL PROVIDERS + // + ////////////////////////////////////////////////////////////////////////////////////////// + + /** + * Create email provider + * + * @chained email provider + * + * @param {Object} object JSON object + */ + createEmailProvider: function(object) + { + const self = this; + + const chainable = this.getFactory().emailProvider(this); + + const uriFunction = function() + { + return self.getUri() + "/emailproviders"; + }; + + return this.chainCreate(chainable, object, uriFunction); + }, + + /** + * Lists the email providers. + * + * @param pagination + * + * @chained email provider map + */ + listEmailProviders: function(pagination) + { + const self = this; + + const params = {}; + if (pagination) + { + Gitana.copyInto(params, pagination); + } + + const uriFunction = function() + { + return self.getUri() + "/emailproviders"; + }; + + const chainable = this.getFactory().emailProviderMap(this); + return this.chainGet(chainable, uriFunction, params); + }, + + /** + * Reads an email provider. + * + * @param emailProviderId + * + * @chained emailProvider + */ + readEmailProvider: function(emailProviderId) + { + const self = this; + + const chainable = this.getFactory().emailProvider(this); + + const uriFunction = function() + { + return self.getUri() + "/emailproviders/" + emailProviderId; + }; + + return this.chainGet(chainable, uriFunction); + }, + + /** + * Queries for email providers. + * + * @chained email provider map + * + * @param {Object} query + * @param {Object} pagination pagination (optional) + */ + queryEmailProviders: function(query, pagination) + { + const self = this; + + const params = {}; + if (pagination) + { + Gitana.copyInto(params, pagination); + } + + const uriFunction = function() + { + return self.getUri() + "/emailproviders/query"; + }; + + const chainable = this.getFactory().emailProviderMap(this); + return this.chainPost(chainable, uriFunction, params, query); + }, + + /** + * Performs a bulk check of permissions against permissioned objects of type emailprovider. + * + * Example of checks array: + * + * [{ + * "permissionedId": "", + * "principalId": "", + * "permissionId": "" + * }] + * + * The callback receives an array of results, example: + * + * [{ + * "permissionedId": "", + * "principalId": "", + * "permissionId": "", + * "result": true + * }] + * + * The order of elements in the array will be the same for checks and results. + * + * @param checks + * @param callback + */ + checkEmailProviderPermissions: function(checks, callback) + { + const self = this; + + const uriFunction = function() + { + return self.getUri() + "/emailproviders/permissions/check"; + }; + + const object = { + "checks": checks + }; + + return this.chainPostResponse(this, uriFunction, {}, object).then(function(response) { + callback.call(this, response["results"]); + }); + }, + + /** + * Performs a bulk check of authorities against permissioned objects of type emailprovider. + * + * Example of checks array: + * + * [{ + * "permissionedId": "", + * "principalId": "", + * "authorityId": "" + * }] + * + * The callback receives an array of results, example: + * + * [{ + * "permissionedId": "", + * "principalId": "", + * "authorityId": "", + * "result": true + * }] + * + * The order of elements in the array will be the same for checks and results. + * + * @param checks + * @param callback + */ + checkEmailProviderAuthorities: function(checks, callback) + { + const self = this; + + const uriFunction = function() + { + return self.getUri() + "/emailproviders/authorities/check"; + }; + + const object = { + "checks": checks + }; + + return this.chainPostResponse(this, uriFunction, {}, object).then(function(response) { + callback.call(this, response["results"]); + }); + }, + + + + + + + ////////////////////////////////////////////////////////////////////////////////////////// + // + // EMAILS + // + ////////////////////////////////////////////////////////////////////////////////////////// + + /** + * Create email + * + * @chained email + * + * @param {Object} object JSON object + */ + createEmail: function(object) + { + const self = this; + + const chainable = this.getFactory().email(this); + + const uriFunction = function() + { + return self.getUri() + "/emails"; + }; + + return this.chainCreate(chainable, object, uriFunction); + }, + + /** + * Lists the emails. + * + * @param pagination + * + * @chained email map + */ + listEmails: function(pagination) + { + const self = this; + + const params = {}; + if (pagination) + { + Gitana.copyInto(params, pagination); + } + + const uriFunction = function() + { + return self.getUri() + "/emails"; + }; + + const chainable = this.getFactory().emailMap(this); + return this.chainGet(chainable, uriFunction, params); + }, + + /** + * Reads an email. + * + * @param emailId + * + * @chained email + */ + readEmail: function(emailId) + { + const self = this; + + const chainable = this.getFactory().email(this); + + const uriFunction = function() + { + return self.getUri() + "/emails/" + emailId; + }; + + return this.chainGet(chainable, uriFunction); + }, + + /** + * Queries for emails. + * + * @chained email map + * + * @param {Object} query + * @param {Object} pagination pagination (optional) + */ + queryEmails: function(query, pagination) + { + const self = this; + + const params = {}; + if (pagination) + { + Gitana.copyInto(params, pagination); + } + + const uriFunction = function() + { + return self.getUri() + "/emails/query"; + }; + + const chainable = this.getFactory().emailMap(this); + return this.chainPost(chainable, uriFunction, params, query); + }, + + /** + * Performs a bulk check of permissions against permissioned objects of type email. + * + * Example of checks array: + * + * [{ + * "permissionedId": "", + * "principalId": "", + * "permissionId": "" + * }] + * + * The callback receives an array of results, example: + * + * [{ + * "permissionedId": "", + * "principalId": "", + * "permissionId": "", + * "result": true + * }] + * + * The order of elements in the array will be the same for checks and results. + * + * @param checks + * @param callback + */ + checkEmailPermissions: function(checks, callback) + { + const self = this; + + const uriFunction = function() + { + return self.getUri() + "/emails/permissions/check"; + }; + + const object = { + "checks": checks + }; + + return this.chainPostResponse(this, uriFunction, {}, object).then(function(response) { + callback.call(this, response["results"]); + }); + }, + + /** + * Performs a bulk check of authorities against permissioned objects of type email. + * + * Example of checks array: + * + * [{ + * "permissionedId": "", + * "principalId": "", + * "authorityId": "" + * }] + * + * The callback receives an array of results, example: + * + * [{ + * "permissionedId": "", + * "principalId": "", + * "authorityId": "", + * "result": true + * }] + * + * The order of elements in the array will be the same for checks and results. + * + * @param checks + * @param callback + */ + checkEmailAuthorities: function(checks, callback) + { + const self = this; + + const uriFunction = function() + { + return self.getUri() + "/emails/authorities/check"; + }; + + const object = { + "checks": checks + }; + + return this.chainPostResponse(this, uriFunction, {}, object).then(function(response) { + callback.call(this, response["results"]); + }); + }, + + + + ////////////////////////////////////////////////////////////////////////////////////////// + // + // DEPLOYMENT + // + ////////////////////////////////////////////////////////////////////////////////////////// + + /** + * Deploys the application to the environment described by the deployment key. + * + * @chained deployed application + * + * @param deploymentKey + */ + deploy: function(deploymentKey) + { + const self = this; + + const uriFunction = function() + { + return self.getUri() + "/deploy/" + deploymentKey; + }; + + // temp web host + const webhost = new Gitana.WebHost(this.getPlatform()); + + // we hand back a deployed application and preload some work + const chainable = this.getFactory().deployedApplication(webhost); + return this.chainPost(chainable, uriFunction).then(function() { + + // load the real web host + const webhostId = self["deployments"][deploymentKey]["webhost"]; + this.subchain(this.getPlatform()).readWebHost(webhostId).then(function() { + webhost.loadFrom(this); + }); + + }); + }, + + /** + * Undeploys the application from the environment described by the deployment key. + * + * @chained application + * + * @param deploymentKey + */ + undeploy: function(deploymentKey) + { + const self = this; + + const uriFunction = function() + { + return self.getUri() + "/undeploy/" + deploymentKey; + }; + + return this.chainPost(this, uriFunction); + }, + + /** + * Finds the deployed application instance for a given target deployment key. + * + * @chained deployed application + * + * @param deploymentKey + */ + findDeployedApplication: function(deploymentKey) + { + const self = this; + + const uriFunction = function() + { + return self.getUri() + "/deployed/" + deploymentKey; + }; + + // temp web host + const webhost = new Gitana.WebHost(this.getPlatform()); + + // we hand back a deployed application and preload some work + const chainable = this.getFactory().deployedApplication(webhost); + return this.chainGet(chainable, uriFunction).then(function() { + + // load the real web host + const webhostId = self["deployments"][deploymentKey]["webhost"]; + this.subchain(this.getPlatform()).readWebHost(webhostId).then(function() { + webhost.loadFrom(this); + }); + + }); + }, + + /** + * Retrieves information about a deployed application. + * + * @param deploymentKey + * @param callback + */ + loadDeploymentInfo: function(deploymentKey, callback) + { + const self = this; + + const uriFunction = function() + { + return self.getUri() + "/deployed/" + deploymentKey + "/info"; + }; + + return this.chainGetResponse(this, uriFunction, {}).then(function(response) { + callback(response.info); + }); + }, + + refreshDeploymentKeys: function(deploymentKey) + { + const self = this; + + return this.then(function() { + + const chain = this; + + // call + const uri = self.getUri() + "/deployments/" + deploymentKey + "/refreshkeys"; + self.getDriver().gitanaPost(uri, null, {}, function() { + chain.next(); + }); + + // NOTE: we return false to tell the chain that we'll manually call next() + return false; + }); + }, + + /** + * Invalidates all page renditions for a given deployment + * + * @param deploymentKey + * @chained this + * + * @public + */ + invalidateAllPageRenditions: function(deploymentKey) + { + const self = this; + + const uriFunction = function() + { + return self.getUri() + "/deployments/" + deploymentKey + "/pagerenditions/invalidateall"; + }; + + // NOTE: pass control back to the server instance + return this.chainPostEmpty(this, uriFunction); + }, + + + + + ////////////////////////////////////////////////////////////////////////////////////////// + // + // MESSAGES + // + ////////////////////////////////////////////////////////////////////////////////////////// + + /** + * Create message + * + * @chained message + * + * @param {Object} object JSON object + */ + createMessage: function(object) + { + const self = this; + + const chainable = this.getFactory().message(this); + + const uriFunction = function() + { + return self.getUri() + "/messages"; + }; + + return this.chainCreate(chainable, object, uriFunction); + }, + + /** + * Lists the messages. + * + * @param pagination + * + * @chained message map + */ + listMessages: function(pagination) + { + const self = this; + + const params = {}; + if (pagination) + { + Gitana.copyInto(params, pagination); + } + + const uriFunction = function() + { + return self.getUri() + "/messages"; + }; + + const chainable = this.getFactory().messageMap(this); + return this.chainGet(chainable, uriFunction, params); + }, + + /** + * Reads a message. + * + * @param messageId + * + * @chained message + */ + readMessage: function(messageId) + { + const self = this; + + const chainable = this.getFactory().message(this); + + const uriFunction = function() + { + return self.getUri() + "/messages/" + messageId; + }; + + return this.chainGet(chainable, uriFunction); + }, + + /** + * Queries for messages. + * + * @chained message map + * + * @param {Object} query + * @param {Object} pagination pagination (optional) + */ + queryMessages: function(query, pagination) + { + const self = this; + + const params = {}; + if (pagination) + { + Gitana.copyInto(params, pagination); + } + + const uriFunction = function() + { + return self.getUri() + "/messages/query"; + }; + + const chainable = this.getFactory().messageMap(this); + return this.chainPost(chainable, uriFunction, params, query); + }, + + /** + * Performs a bulk check of permissions against permissioned objects of type message. + * + * Example of checks array: + * + * [{ + * "permissionedId": "", + * "principalId": "", + * "permissionId": "" + * }] + * + * The callback receives an array of results, example: + * + * [{ + * "permissionedId": "", + * "principalId": "", + * "permissionId": "", + * "result": true + * }] + * + * The order of elements in the array will be the same for checks and results. + * + * @param checks + * @param callback + */ + checkMessagePermissions: function(checks, callback) + { + const self = this; + + const uriFunction = function() + { + return self.getUri() + "/messages/permissions/check"; + }; + + const object = { + "checks": checks + }; + + return this.chainPostResponse(this, uriFunction, {}, object).then(function(response) { + callback.call(this, response["results"]); + }); + }, + + /** + * Performs a bulk check of authorities against permissioned objects of type message. + * + * Example of checks array: + * + * [{ + * "permissionedId": "", + * "principalId": "", + * "authorityId": "" + * }] + * + * The callback receives an array of results, example: + * + * [{ + * "permissionedId": "", + * "principalId": "", + * "authorityId": "", + * "result": true + * }] + * + * The order of elements in the array will be the same for checks and results. + * + * @param checks + * @param callback + */ + checkMessageAuthorities: function(checks, callback) + { + const self = this; + + const uriFunction = function() + { + return self.getUri() + "/messages/authorities/check"; + }; + + const object = { + "checks": checks + }; + + return this.chainPostResponse(this, uriFunction, {}, object).then(function(response) { + callback.call(this, response["results"]); + }); + } + + }); + +})(window); +(function(window) +{ + Gitana = window.Gitana; + + Gitana.ApplicationMap = Gitana.AbstractPlatformObjectMap.extend( + /** @lends Gitana.ApplicationMap.prototype */ + { + /** + * @constructs + * @augments Gitana.AbstractPlatformObjectMap + * + * @class Map of application objects + * + * @param {Gitana.Platform} platform Gitana platform + * @param {Object} object + */ + constructor: function(platform, object) + { + this.objectType = function() { return "Gitana.ApplicationMap"; }; + + + ////////////////////////////////////////////////////////////////////////////////////////////// + // + // CALL THROUGH TO BASE CLASS (at the end) + // + ////////////////////////////////////////////////////////////////////////////////////////////// + + this.base(platform, object); + }, + + /** + * @override + */ + clone: function() + { + return this.getFactory().applicationMap(this.getPlatform(), this); + }, + + /** + * @param json + */ + buildObject: function(json) + { + return this.getFactory().application(this.getPlatform(), json); + } + + }); + +})(window); +(function(window) +{ + Gitana = window.Gitana; + + Gitana.AbstractApplicationObject = Gitana.AbstractPlatformObject.extend( + /** @lends Gitana.AbstractApplicationObject.prototype */ + { + /** + * @constructs + * @augments Gitana.AbstractPlatformObject + * + * @class AbstractApplicationObject + * + * @param {Gitana.Application} application + * @param {Object} object json object (if no callback required for populating) + */ + constructor: function(application, object) + { + this.base(application.getPlatform(), object); + + + ////////////////////////////////////////////////////////////////////////////////////////////// + // + // PRIVILEGED METHODS + // + ////////////////////////////////////////////////////////////////////////////////////////////// + + /** + * Gets the Gitana Application object. + * + * @inner + * + * @returns {Gitana.Application} The Gitana Application object + */ + this.getApplication = function() { return application; }; + + /** + * Gets the Gitana Application id. + * + * @inner + * + * @returns {String} The Gitana Application id + */ + this.getApplicationId = function() { return application.getId(); }; + }, + + /** + * @OVERRIDE + */ + ref: function() + { + return this.getType() + "://" + this.getPlatformId() + "/" + this.getApplicationId() + "/" + this.getId(); + } + + }); + +})(window); +(function(window) +{ + Gitana = window.Gitana; + + Gitana.Settings = Gitana.AbstractApplicationObject.extend( + /** @lends Gitana.Settings.prototype */ + { + /** + * @constructs + * @augments Gitana.AbstractApplicationObject + * + * @class Settings + * + * @param {Gitana.Application} application + * @param {Object}object json object (if no callback required for populating) + */ + constructor: function(application, object) + { + this.base(application, object); + + this.objectType = function() { return "Gitana.Settings"; }; + }, + + /** + * @override + */ + clone: function() + { + return new Gitana.Settings(this.getApplication(), this); + }, + + /** + * @OVERRIDE + */ + getType: function() + { + return Gitana.TypedIDConstants.TYPE_SETTINGS; + }, + + /** + * @OVERRIDE + */ + getUri: function() + { + return "/applications/" + this.getApplicationId() + "/settings/" + this.getId(); + }, + + /** + * Returns all settings. + */ + getSettings: function() + { + return this["settings"]; + }, + + /** + * Gets setting by key. + * @param key Setting key + */ + getSetting: function(key) + { + return (this.getSettings() ? this.getSettings()[key] : null); + }, + + /** + * Sets setting. + * + * @param key Setting key + * @param val Setting value + */ + setSetting: function(key, val) + { + if (!this.getSettings()) + { + this["settings"] = {}; + } + + this["settings"][key] = val; + }, + + ////////////////////////////////////////////////////////////////////////////////////////// + // + // ATTACHMENTS + // + ////////////////////////////////////////////////////////////////////////////////////////// + + /** + * Hands back an attachments map. + * + * @chained attachment map + * + * @param local + * + * @public + */ + listAttachments: Gitana.Methods.listAttachments(), + + /** + * Picks off a single attachment + * + * @chained attachment + * + * @param attachmentId + */ + attachment: function(attachmentId) + { + return this.listAttachments().select(attachmentId); + }, + + /** + * Creates an attachment. + * + * When using this method from within the JS driver, it really only works for text-based content such + * as JSON or text. + * + * @chained attachment + * + * @param attachmentId (use null or false for default attachment) + * @param contentType + * @param data + */ + attach: Gitana.Methods.attach(), + + /** + * Deletes an attachment. + * + * @param attachmentId + */ + unattach: Gitana.Methods.unattach(), + + /** + * Generates a URI to a preview resource. + */ + getPreviewUri: Gitana.Methods.getPreviewUri() + + }); + +})(window); +(function(window) +{ + Gitana = window.Gitana; + + Gitana.SettingsMap = Gitana.AbstractPlatformObjectMap.extend( + /** @lends Gitana.SettingsMap.prototype */ + { + /** + * @constructs + * @augments Gitana.AbstractPlatformObjectMap + * + * @class SettingsMap + * + * @param {Gitana.Application} application Gitana application instance. + * @param {Object}object + */ + constructor: function(application, object) + { + this.objectType = function() { return "Gitana.SettingsMap"; }; + + + ////////////////////////////////////////////////////////////////////////////////////////////// + // + // PRIVILEGED METHODS + // + ////////////////////////////////////////////////////////////////////////////////////////////// + + /** + * Gets the Gitana Application object. + * + * @inner + * + * @returns {Gitana.Application} The Gitana Application object + */ + this.getApplication = function() { return application; }; + + /** + * Gets the Gitana Application id. + * + * @inner + * + * @returns {String} The Gitana Application id + */ + this.getApplicationId = function() { return application.getId(); }; + + + ////////////////////////////////////////////////////////////////////////////////////////////// + // + // CALL THROUGH TO BASE CLASS (at the end) + // + ////////////////////////////////////////////////////////////////////////////////////////////// + + this.base(application.getPlatform(), object); + }, + + /** + * @override + */ + clone: function() + { + return this.getFactory().settingsMap(this.getApplication(), this); + }, + + /** + * @param json + */ + buildObject: function(json) + { + return this.getFactory().settings(this.getApplication(), json); + } + + }); + +})(window); +(function(window) +{ + Gitana = window.Gitana; + + Gitana.Email = Gitana.AbstractApplicationObject.extend( + /** @lends Gitana.Email.prototype */ + { + /** + * @constructs + * @augments Gitana.AbstractApplicationObject + * + * @class Email + * + * @param {Gitana.Application} application + * @param {Object} object json object (if no callback required for populating) + */ + constructor: function(application, object) + { + this.base(application, object); + + this.objectType = function() { return "Gitana.Email"; }; + }, + + /** + * @override + */ + clone: function() + { + return new Gitana.Email(this.getApplication(), this); + }, + + /** + * @OVERRIDE + */ + getType: function() + { + return Gitana.TypedIDConstants.TYPE_EMAIL; + }, + + /** + * @OVERRIDE + */ + getUri: function() + { + return "/applications/" + this.getApplicationId() + "/emails/" + this.getId(); + }, + + /** + * Sends this email using the given email provider. + * + * @param emailProvider + * + * @chained this + * + * @return this + */ + send: function(emailProvider) + { + return this.then(function() { + this.subchain(emailProvider).send(this); + }); + } + + }); + +})(window); +(function(window) +{ + Gitana = window.Gitana; + + Gitana.EmailMap = Gitana.AbstractPlatformObjectMap.extend( + /** @lends Gitana.EmailMap.prototype */ + { + /** + * @constructs + * @augments Gitana.AbstractPlatformObjectMap + * + * @class EmailMap + * + * @param {Gitana.Application} application Gitana application instance. + * @param {Object} object + */ + constructor: function(application, object) + { + this.objectType = function() { return "Gitana.EmailMap"; }; + + + ////////////////////////////////////////////////////////////////////////////////////////////// + // + // PRIVILEGED METHODS + // + ////////////////////////////////////////////////////////////////////////////////////////////// + + /** + * Gets the Gitana Application object. + * + * @inner + * + * @returns {Gitana.Application} The Gitana Application object + */ + this.getApplication = function() { return application; }; + + /** + * Gets the Gitana Application id. + * + * @inner + * + * @returns {String} The Gitana Application id + */ + this.getApplicationId = function() { return application.getId(); }; + + + ////////////////////////////////////////////////////////////////////////////////////////////// + // + // CALL THROUGH TO BASE CLASS (at the end) + // + ////////////////////////////////////////////////////////////////////////////////////////////// + + this.base(application.getPlatform(), object); + }, + + /** + * @override + */ + clone: function() + { + return this.getFactory().emailMap(this.getApplication(), this); + }, + + /** + * @param json + */ + buildObject: function(json) + { + return this.getFactory().email(this.getApplication(), json); + } + + }); + +})(window); +(function(window) +{ + Gitana = window.Gitana; + + Gitana.EmailProvider = Gitana.AbstractApplicationObject.extend( + /** @lends Gitana.EmailProvider.prototype */ + { + /** + * @constructs + * @augments Gitana.AbstractApplicationObject + * + * @class EmailProvider + * + * @param {Gitana.Application} application + * @param [object] object json object (if no callback required for populating) + */ + constructor: function(application, object) + { + this.base(application, object); + + this.objectType = function() { return "Gitana.EmailProvider"; }; + }, + + /** + * @override + */ + clone: function() + { + return new Gitana.EmailProvider(this.getApplication(), this); + }, + + /** + * @OVERRIDE + */ + getType: function() + { + return Gitana.TypedIDConstants.TYPE_EMAIL_PROVIDER; + }, + + /** + * @OVERRIDE + */ + getUri: function() + { + return "/applications/" + this.getApplicationId() + "/emailproviders/" + this.getId(); + }, + + /** + * Sends the given email using this email provider. + * + * @param {Object} email + * @param {Object} model + * + * @return {*} + */ + send: function(email, model) + { + const self = this; + + if (!model) + { + model = {}; + } + + let emailId = null; + if (Gitana.isString(email)) + { + emailId = email; + } + else + { + emailId = email.getId(); + } + + const uriFunction = function() + { + return self.getUri() + "/send?email=" + emailId; + }; + + return this.chainPostEmpty(null, uriFunction, {}, model); + }, + + /** + * Tests whether the email provider works. + * + * @param from + * @param to + * @returns {*} + */ + test: function(from, to) + { + const self = this; + + const uriFunction = function() + { + return self.getUri() + "/test?from=" + from + "&to=" + to; + }; + + return this.chainPostEmpty(null, uriFunction); + }, + + /** + * Sends an email containing the results of an export. + * + * @param exportId + * @param emailConfig + * @param callback + * @returns {*} + */ + sendForExport: function(exportId, emailConfig, callback) + { + + const uriFunction = function() + { + return "/ref/exports/" + exportId + "/email"; + }; + + const params = {}; + + const payload = { + "applicationId": this.getApplicationId(), + "emailProviderId": this.getId(), + "email": emailConfig + }; + + return this.chainPostResponse(this, uriFunction, params, payload).then(function(response) { + callback(response); + }); + } + + + }); + +})(window); +(function(window) +{ + Gitana = window.Gitana; + + Gitana.EmailProviderMap = Gitana.AbstractPlatformObjectMap.extend( + /** @lends Gitana.EmailProviderMap.prototype */ + { + /** + * @constructs + * @augments Gitana.AbstractPlatformObjectMap + * + * @class EmailProviderMap + * + * @param {Gitana.Application} application Gitana application instance. + * @param {Object} object + */ + constructor: function(application, object) + { + this.objectType = function() { return "Gitana.EmailProviderMap"; }; + + + ////////////////////////////////////////////////////////////////////////////////////////////// + // + // PRIVILEGED METHODS + // + ////////////////////////////////////////////////////////////////////////////////////////////// + + /** + * Gets the Gitana Application object. + * + * @inner + * + * @returns {Gitana.Application} The Gitana Application object + */ + this.getApplication = function() { return application; }; + + /** + * Gets the Gitana Application id. + * + * @inner + * + * @returns {String} The Gitana Application id + */ + this.getApplicationId = function() { return application.getId(); }; + + + ////////////////////////////////////////////////////////////////////////////////////////////// + // + // CALL THROUGH TO BASE CLASS (at the end) + // + ////////////////////////////////////////////////////////////////////////////////////////////// + + this.base(application.getPlatform(), object); + }, + + /** + * @override + */ + clone: function() + { + return this.getFactory().emailProviderMap(this.getApplication(), this); + }, + + /** + * @param json + */ + buildObject: function(json) + { + return this.getFactory().emailProvider(this.getApplication(), json); + } + + }); + +})(window); +(function(window) +{ + Gitana = window.Gitana; + + Gitana.Message = Gitana.AbstractApplicationObject.extend( + /** @lends Gitana.Message.prototype */ + { + /** + * @constructs + * @augments Gitana.AbstractApplicationObject + * + * @class Message + * + * @param {Gitana.Application} application + * @param {Object} object json object (if no callback required for populating) + */ + constructor: function(application, object) + { + this.base(application, object); + + this.objectType = function() { return "Gitana.Message"; }; + }, + + /** + * @override + */ + clone: function() + { + return new Gitana.Message(this.getApplication(), this); + }, + + /** + * @OVERRIDE + */ + getType: function() + { + return Gitana.TypedIDConstants.TYPE_MESSAGE; + }, + + /** + * @OVERRIDE + */ + getUri: function() + { + return "/applications/" + this.getApplicationId() + "/messages/" + this.getId(); + } + + }); + +})(window); +(function(window) +{ + Gitana = window.Gitana; + + Gitana.MessageMap = Gitana.AbstractPlatformObjectMap.extend( + /** @lends Gitana.MessageMap.prototype */ + { + /** + * @constructs + * @augments Gitana.AbstractPlatformObjectMap + * + * @class MessageMap + * + * @param {Gitana.Application} application Gitana application instance. + * @param {Object} object + */ + constructor: function(application, object) + { + this.objectType = function() { return "Gitana.MessageMap"; }; + + + ////////////////////////////////////////////////////////////////////////////////////////////// + // + // PRIVILEGED METHODS + // + ////////////////////////////////////////////////////////////////////////////////////////////// + + /** + * Gets the Gitana Application object. + * + * @inner + * + * @returns {Gitana.Application} The Gitana Application object + */ + this.getApplication = function() { return application; }; + + /** + * Gets the Gitana Application id. + * + * @inner + * + * @returns {String} The Gitana Application id + */ + this.getApplicationId = function() { return application.getId(); }; + + + ////////////////////////////////////////////////////////////////////////////////////////////// + // + // CALL THROUGH TO BASE CLASS (at the end) + // + ////////////////////////////////////////////////////////////////////////////////////////////// + + this.base(application.getPlatform(), object); + }, + + /** + * @override + */ + clone: function() + { + return this.getFactory().messageMap(this.getApplication(), this); + }, + + /** + * @param json + */ + buildObject: function(json) + { + return this.getFactory().message(this.getApplication(), json); + } + + }); + +})(window); +(function(window) +{ + Gitana = window.Gitana; + + Gitana.Registration = Gitana.AbstractApplicationObject.extend( + /** @lends Gitana.Registration.prototype */ + { + /** + * @constructs + * @augments Gitana.AbstractApplicationObject + * + * @class Registration + * + * @param {Gitana.Application} application + * @param {Object} object json object (if no callback required for populating) + */ + constructor: function(application, object) + { + this.base(application, object); + + this.objectType = function() { return "Gitana.Registration"; }; + }, + + /** + * @override + */ + clone: function() + { + return new Gitana.Registration(this.getApplication(), this); + }, + + /** + * @OVERRIDE + */ + getType: function() + { + return Gitana.TypedIDConstants.TYPE_REGISTRATION; + }, + + /** + * @OVERRIDE + */ + getUri: function() + { + return "/applications/" + this.getApplicationId() + "/registrations/" + this.getId(); + }, + + sendConfirmationEmail: function() + { + const self = this; + + const uriFunction = function() + { + return self.getUri() + "/send/confirmation"; + }; + + return this.chainPostEmpty(this, uriFunction, {}, this); + }, + + sendWelcomeEmail: function() + { + const self = this; + + const uriFunction = function() + { + return self.getUri() + "/send/welcome"; + }; + + return this.chainPostEmpty(this, uriFunction, {}, this); + }, + + confirm: function(newUserPassword, paymentMethodObject) + { + if (!paymentMethodObject) + { + paymentMethodObject = {}; + } + + const params = { + "password": newUserPassword + }; + + const self = this; + + const uriFunction = function() + { + return self.getUri() + "/confirm"; + }; + + return this.chainPostEmpty(this, uriFunction, params, paymentMethodObject); + } + }); + +})(window); +(function(window) +{ + Gitana = window.Gitana; + + Gitana.RegistrationMap = Gitana.AbstractPlatformObjectMap.extend( + /** @lends Gitana.RegistrationMap.prototype */ + { + /** + * @constructs + * @augments Gitana.AbstractPlatformObjectMap + * + * @class RegistrationMap + * + * @param {Gitana.Application} application Gitana application instance. + * @param {Object} object + */ + constructor: function(application, object) + { + this.objectType = function() { return "Gitana.RegistrationMap"; }; + + + ////////////////////////////////////////////////////////////////////////////////////////////// + // + // PRIVILEGED METHODS + // + ////////////////////////////////////////////////////////////////////////////////////////////// + + /** + * Gets the Gitana Application object. + * + * @inner + * + * @returns {Gitana.Application} The Gitana Application object + */ + this.getApplication = function() { return application; }; + + /** + * Gets the Gitana Application id. + * + * @inner + * + * @returns {String} The Gitana Application id + */ + this.getApplicationId = function() { return application.getId(); }; + + + ////////////////////////////////////////////////////////////////////////////////////////////// + // + // CALL THROUGH TO BASE CLASS (at the end) + // + ////////////////////////////////////////////////////////////////////////////////////////////// + + this.base(application.getPlatform(), object); + }, + + /** + * @override + */ + clone: function() + { + return this.getFactory().registrationMap(this.getApplication(), this); + }, + + /** + * @param json + */ + buildObject: function(json) + { + return this.getFactory().registration(this.getApplication(), json); + } + + }); + +})(window); +(function(window) +{ + Gitana = window.Gitana; + + Gitana.PageRendition = Gitana.AbstractApplicationObject.extend( + /** @lends Gitana.PageRendition.prototype */ + { + /** + * @constructs + * @augments Gitana.AbstractApplicationObject + * + * @class PageRendition + * + * @param {Gitana.Application} application + * @param {Object} object json object (if no callback required for populating) + */ + constructor: function(application, object) + { + this.base(application, object); + + this.objectType = function() { return "Gitana.PageRendition"; }; + }, + + /** + * @override + */ + clone: function() + { + return new Gitana.PageRendition(this.getApplication(), this); + }, + + /** + * @OVERRIDE + */ + getType: function() + { + return Gitana.TypedIDConstants.TYPE_PAGE_RENDITION; + }, + + /** + * @OVERRIDE + */ + getUri: function() + { + return "/applications/" + this.getApplicationId() + "/deployments/" + this.deploymentKey + "/pagerenditions/" + this.key; + }, + + /** + * Invalidate + * + * @chained this + * + * @public + */ + invalidate: function() + { + const self = this; + + const uriFunction = function() + { + return self.getUri() + "/invalidate"; + }; + + // NOTE: pass control back to the server instance + return this.chainPostEmpty(this, uriFunction); + } + + }); + +})(window); +(function(window) +{ + Gitana = window.Gitana; + + Gitana.PageRenditionMap = Gitana.AbstractPlatformObjectMap.extend( + /** @lends Gitana.PageRenditionMap.prototype */ + { + /** + * @constructs + * @augments Gitana.AbstractPlatformObjectMap + * + * @class PageRenditionMap + * + * @param {Gitana.Application} application Gitana application instance. + * @param {Object} object + */ + constructor: function(application, object) + { + this.objectType = function() { return "Gitana.PageRenditionMap"; }; + + + ////////////////////////////////////////////////////////////////////////////////////////////// + // + // PRIVILEGED METHODS + // + ////////////////////////////////////////////////////////////////////////////////////////////// + + /** + * Gets the Gitana Application object. + * + * @inner + * + * @returns {Gitana.Application} The Gitana Application object + */ + this.getApplication = function() { return application; }; + + /** + * Gets the Gitana Application id. + * + * @inner + * + * @returns {String} The Gitana Application id + */ + this.getApplicationId = function() { return application.getId(); }; + + + ////////////////////////////////////////////////////////////////////////////////////////////// + // + // CALL THROUGH TO BASE CLASS (at the end) + // + ////////////////////////////////////////////////////////////////////////////////////////////// + + this.base(application.getPlatform(), object); + }, + + /** + * @override + */ + clone: function() + { + return this.getFactory().pageRenditionMap(this.getApplication(), this); + }, + + /** + * @param json + */ + buildObject: function(json) + { + return this.getFactory().pageRendition(this.getApplication(), json); + } + + }); + +})(window); +(function(window) +{ + Gitana = window.Gitana; + + Gitana.Directory = Gitana.AbstractPlatformDataStore.extend( + /** @lends Gitana.Directory.prototype */ + { + /** + * @constructs + * @augments Gitana.AbstractPlatformDataStore + * + * @class Directory + * + * @param {Gitana.Platform} platform + * @param {Object}object json object (if no callback required for populating) + */ + constructor: function(platform, object) + { + this.objectType = function() { return "Gitana.Directory"; }; + + this.base(platform, object); + }, + + /** + * @OVERRIDE + */ + getUri: function() + { + return "/directories/" + this.getId(); + }, + + /** + * @OVERRIDE + */ + getType: function() + { + return Gitana.TypedIDConstants.TYPE_DIRECTORY; + }, + + /** + * @override + */ + clone: function() + { + return this.getFactory().directory(this.getPlatform(), this); + }, + + + + + ///////////////////////////////////////////////////////////////////////////////////////////////// + // + // IDENTITIES + // + ///////////////////////////////////////////////////////////////////////////////////////////////// + + /** + * Reads an identity. + * + * @chained identity + * + * @param {String} identityId the identity id + */ + readIdentity: function(identityId) + { + const self = this; + + const uriFunction = function() + { + return self.getUri() + "/identities/" + identityId; + }; + + const chainable = this.getFactory().identity(this); + return this.chainGet(chainable, uriFunction); + }, + + /** + * Acquires a list of all identities. + * + * @chained identity map + * + * @param {Object} pagination pagination (optional) + */ + listIdentities: function(pagination) + { + const self = this; + + // prepare params (with pagination) + const params = {}; + if (pagination) + { + Gitana.copyInto(params, pagination); + } + + const uriFunction = function() + { + return self.getUri() + "/identities"; + }; + + // get to work + const chainable = this.getFactory().identityMap(this); + + // all groups + return this.chainGet(chainable, uriFunction, params); + }, + + /** + * Queries for identities. + * + * @chained identity map + * + * @param {Object} query + * @param {Object}pagination pagination (optional) + */ + queryIdentities: function(query, pagination) + { + const self = this; + + const params = {}; + if (pagination) + { + Gitana.copyInto(params, pagination); + } + + const uriFunction = function() + { + return self.getUri() + "/identities/query"; + }; + + const chainable = this.getFactory().identityMap(this); + return this.chainPost(chainable, uriFunction, params, query); + }, + + /** + * Performs a bulk check of permissions against permissioned objects of type identity. + * + * Example of checks array: + * + * [{ + * "permissionedId": "", + * "principalId": "", + * "permissionId": "" + * }] + * + * The callback receives an array of results, example: + * + * [{ + * "permissionedId": "", + * "principalId": "", + * "permissionId": "", + * "result": true + * }] + * + * The order of elements in the array will be the same for checks and results. + * + * @param checks + * @param callback + */ + checkIdentityPermissions: function(checks, callback) + { + const self = this; + + const object = { + "checks": checks + }; + + const uriFunction = function() + { + return self.getUri() + "/identities/permissions/check"; + }; + + return this.chainPostResponse(this, uriFunction, {}, object).then(function(response) { + callback.call(this, response["results"]); + }); + }, + + /** + * Performs a bulk check of authorities against permissioned objects of type identity. + * + * Example of checks array: + * + * [{ + * "permissionedId": "", + * "principalId": "", + * "authorityId": "" + * }] + * + * The callback receives an array of results, example: + * + * [{ + * "permissionedId": "", + * "principalId": "", + * "authorityId": "", + * "result": true + * }] + * + * The order of elements in the array will be the same for checks and results. + * + * @param checks + * @param callback + */ + checkIdentityAuthorities: function(checks, callback) + { + const self = this; + + const object = { + "checks": checks + }; + + const uriFunction = function() + { + return self.getUri() + "/identities/authorities/check"; + }; + + return this.chainPostResponse(this, uriFunction, {}, object).then(function(response) { + callback.call(this, response["results"]); + }); + }, + + + ///////////////////////////////////////////////////////////////////////////////////////////////// + // + // CONNECTIONS + // + ///////////////////////////////////////////////////////////////////////////////////////////////// + + /** + * Reads a connection. + * + * @chained connection + * + * @param {String} connectionId the connection id + */ + readConnection: function(connectionId) + { + const self = this; + + const uriFunction = function() + { + return self.getUri() + "/connections/" + connectionId; + }; + + const chainable = this.getFactory().connection(this); + return this.chainGet(chainable, uriFunction); + }, + + /** + * Creates a connection. + * + * @chained connection + * + * @param {Object}object JSON object + */ + createConnection: function(object) + { + const self = this; + + if (!object) + { + object = {}; + } + + const uriFunction = function() + { + return self.getUri() + "/connections"; + }; + + const chainable = this.getFactory().connection(this, object); + + return this.chainCreate(chainable, object, uriFunction); + }, + + /** + * Acquires a list of all connections. + * + * @chained identity map + * + * @param {Object} pagination pagination (optional) + */ + listConnections: function(pagination) + { + const self = this; + + // prepare params (with pagination) + const params = {}; + if (pagination) + { + Gitana.copyInto(params, pagination); + } + + const uriFunction = function() + { + return self.getUri() + "/connections"; + }; + + // get to work + const chainable = this.getFactory().connectionMap(this); + + // all groups + return this.chainGet(chainable, uriFunction, params); + }, + + /** + * Queries for connections. + * + * @chained identity map + * + * @param {Object} query + * @param {Object}pagination pagination (optional) + */ + queryConnections: function(query, pagination) + { + const self = this; + + const params = {}; + if (pagination) + { + Gitana.copyInto(params, pagination); + } + + const uriFunction = function() + { + return self.getUri() + "/connections/query"; + }; + + const chainable = this.getFactory().connectionMap(this); + return this.chainPost(chainable, uriFunction, params, query); + }, + + /** + * Performs a bulk check of permissions against permissioned objects of type connection. + * + * Example of checks array: + * + * [{ + * "permissionedId": "", + * "principalId": "", + * "permissionId": "" + * }] + * + * The callback receives an array of results, example: + * + * [{ + * "permissionedId": "", + * "principalId": "", + * "permissionId": "", + * "result": true + * }] + * + * The order of elements in the array will be the same for checks and results. + * + * @param checks + * @param callback + */ + checkConnectionPermissions: function(checks, callback) + { + const self = this; + + const object = { + "checks": checks + }; + + const uriFunction = function() + { + return self.getUri() + "/connections/permissions/check"; + }; + + return this.chainPostResponse(this, uriFunction, {}, object).then(function(response) { + callback.call(this, response["results"]); + }); + }, + + /** + * Performs a bulk check of authorities against permissioned objects of type connection. + * + * Example of checks array: + * + * [{ + * "permissionedId": "", + * "principalId": "", + * "authorityId": "" + * }] + * + * The callback receives an array of results, example: + * + * [{ + * "permissionedId": "", + * "principalId": "", + * "authorityId": "", + * "result": true + * }] + * + * The order of elements in the array will be the same for checks and results. + * + * @param checks + * @param callback + */ + checkConnectionAuthorities: function(checks, callback) + { + const self = this; + + const object = { + "checks": checks + }; + + const uriFunction = function() + { + return self.getUri() + "/connections/authorities/check"; + }; + + return this.chainPostResponse(this, uriFunction, {}, object).then(function(response) { + callback.call(this, response["results"]); + }); + } + + }); + +})(window); +(function(window) +{ + Gitana = window.Gitana; + + Gitana.DirectoryMap = Gitana.AbstractPlatformObjectMap.extend( + /** @lends Gitana.DirectoryMap.prototype */ + { + /** + * @constructs + * @augments Gitana.AbstractPlatformObjectMap + * + * @class Map of directory objects + * + * @param {Gitana.Platform} platform Gitana platform + * @param {Object} object + */ + constructor: function(platform, object) + { + this.objectType = function() { return "Gitana.DirectoryMap"; }; + + + ////////////////////////////////////////////////////////////////////////////////////////////// + // + // CALL THROUGH TO BASE CLASS (at the end) + // + ////////////////////////////////////////////////////////////////////////////////////////////// + + this.base(platform, object); + }, + + /** + * @override + */ + clone: function() + { + return this.getFactory().directoryMap(this.getPlatform(), this); + }, + + /** + * @param json + */ + buildObject: function(json) + { + return this.getFactory().directory(this.getPlatform(), json); + } + + }); + +})(window); +(function(window) +{ + Gitana = window.Gitana; + + Gitana.AbstractDirectoryObject = Gitana.AbstractPlatformObject.extend( + /** @lends Gitana.AbstractDirectoryObject.prototype */ + { + /** + * @constructs + * @augments Gitana.AbstractPlatformObject + * + * @class AbstractDirectoryObject + * + * @param {Gitana.Directory} directory + * @param {Object} object json object (if no callback required for populating) + */ + constructor: function(directory, object) + { + this.base(directory.getPlatform(), object); + + this.objectType = function() { return "Gitana.Connection"; }; + + + ////////////////////////////////////////////////////////////////////////////////////////////// + // + // PRIVILEGED METHODS + // + ////////////////////////////////////////////////////////////////////////////////////////////// + + this.getDirectory = function() + { + return directory; + }; + + this.getDirectoryId = function() + { + return directory.getId(); + }; + }, + + /** + * @OVERRIDE + */ + ref: function() + { + return this.getType() + "://" + this.getPlatformId() + "/" + this.getDirectoryId() + "/" + this.getId(); + } + + }); + +})(window); +(function(window) +{ + Gitana = window.Gitana; + + Gitana.Identity = Gitana.AbstractDirectoryObject.extend( + /** @lends Gitana.Identity.prototype */ + { + /** + * @constructs + * @augments Gitana.AbstractDirectoryObject + * + * @class Identity + * + * @param {Gitana.Directory} directory + * @param {Object} object json object (if no callback required for populating) + */ + constructor: function(directory, object) + { + this.base(directory, object); + + this.objectType = function() { return "Gitana.Identity"; }; + }, + + /** + * @OVERRIDE + */ + getType: function() + { + return Gitana.TypedIDConstants.TYPE_IDENTITY; + }, + + /** + * @OVERRIDE + */ + getUri: function() + { + return "/directories/" + this.getDirectoryId() + "/identities/" + this.getId(); + }, + + /** + * @override + */ + clone: function() + { + return this.getFactory().identity(this.getDirectory(), this); + }, + + /** + * Changes the password for this identity. + * + * @param password + * @param verifyPassword + * + * @chained this + * @public + */ + changePassword: function(password, verifyPassword) + { + const object = { + "password": password, + "verifyPassword": verifyPassword + }; + + return this.chainPostEmpty(null, this.getUri() + "/changepassword", {}, object); + }, + + /** + * Retrieves a list of all of the users on any domain that have this identity applied to them. + * + * @param tenantId + */ + findPolicyUsers: function(tenantId) + { + const self = this; + + const uriFunction = function() + { + return self.getUri() + "/policy/users"; + }; + + const domain = new Gitana.Domain(this.getPlatform()); + + const chainable = this.getFactory().domainPrincipalMap(domain); + + // prepare params + const params = {}; + if (tenantId) + { + params.tenantId = tenantId; + } + + return this.chainGet(chainable, uriFunction, params); + }, + + /** + * Finds the user on a tenant platform that has this identity. + * If multiple users have this identity, the first one is chosen. + * + * @param tenantId + */ + findPolicyUserForTenant: function(tenantId) + { + const self = this; + + const uriFunction = function() + { + return self.getUri() + "/policy/user"; + }; + + const chainable = this.getFactory().domainPrincipal(this); + + // prepare params (with pagination) + const params = {}; + params["tenantId"] = tenantId; + + return this.chainGet(chainable, uriFunction, params); + }, + + /** + * Finds the user on a tenant platform that has this identity. + * If multiple users have this identity, the first one is chosen. + * + * @param tenantId + */ + findPolicyUsersForTenant: function(tenantId) + { + const self = this; + + const uriFunction = function() + { + return self.getUri() + "/policy/users"; + }; + + const chainable = this.getFactory().domainPrincipalMap(this); + + // prepare params (with pagination) + const params = {}; + params["tenantId"] = tenantId; + + return this.chainGet(chainable, uriFunction, params); + }, + + /** + * Retrieves the tenants that this identity participates in. + * Optionally allows you to filter down to a particular registrar. + * + * @chained principal map + * + * @param {String} registrarId + */ + findPolicyTenants: function(registrarId) + { + const self = this; + + const uriFunction = function() + { + return self.getUri() + "/policy/tenants"; + }; + + const chainable = this.getFactory().tenantMap(this); + + // prepare params + const params = {}; + if (registrarId) + { + params["registrarId"] = registrarId; + } + + return this.chainGet(chainable, uriFunction, params); + } + + }); + +})(window); +(function(window) +{ + const Gitana = window.Gitana; + + Gitana.IdentityMap = Gitana.AbstractPlatformObjectMap.extend( + /** @lends Gitana.IdentityMap.prototype */ + { + /** + * @constructs + * @augments Gitana.AbstractPlatformObjectMap + * + * @class Map of identity objects + * + * @param {Gitana.Registrar} directory Gitana directory object + * @param {Object} object + */ + constructor: function(directory, object) + { + this.objectType = function() { return "Gitana.IdentityMap"; }; + + + ////////////////////////////////////////////////////////////////////////////////////////////// + // + // PRIVILEGED METHODS + // + ////////////////////////////////////////////////////////////////////////////////////////////// + + this.getDirectory = function() + { + return directory; + }; + + this.getDirectoryId = function() + { + return directory.getId(); + }; + + ////////////////////////////////////////////////////////////////////////////////////////////// + // + // CALL THROUGH TO BASE CLASS (at the end) + // + ////////////////////////////////////////////////////////////////////////////////////////////// + + this.base(directory.getPlatform(), object); + }, + + /** + * @override + */ + clone: function() + { + return this.getFactory().identityMap(this.getDirectory(), this); + }, + + /** + * @param json + */ + buildObject: function(json) + { + return this.getFactory().identity(this.getDirectory(), json); + } + + }); + +})(window); +(function(window) +{ + Gitana = window.Gitana; + + Gitana.Connection = Gitana.AbstractDirectoryObject.extend( + /** @lends Gitana.Connection.prototype */ + { + /** + * @constructs + * @augments Gitana.AbstractDirectoryObject + * + * @class AbstractDirectoryObject + * + * @param {Gitana.Directory} directory + * @param {Object} object json object (if no callback required for populating) + */ + constructor: function(directory, object) + { + this.base(directory, object); + + this.objectType = function() { return "Gitana.Connection"; }; + }, + + /** + * @OVERRIDE + */ + getType: function() + { + return Gitana.TypedIDConstants.TYPE_CONNECTION; + }, + + /** + * @OVERRIDE + */ + getUri: function() + { + return "/directories/" + this.getDirectoryId() + "/connections/" + this.getId(); + }, + + /** + * @override + */ + clone: function() + { + return this.getFactory().connection(this.getDirectory(), this); + } + + }); + +})(window); +(function(window) +{ + Gitana = window.Gitana; + + Gitana.ConnectionMap = Gitana.AbstractPlatformObjectMap.extend( + /** @lends Gitana.ConnectionMap.prototype */ + { + /** + * @constructs + * @augments Gitana.AbstractPlatformObjectMap + * + * @class Map of connection objects + * + * @param {Gitana.Registrar} directory Gitana directory object + * @param {Object} object + */ + constructor: function(directory, object) + { + this.objectType = function() { return "Gitana.ConnectionMap"; }; + + + ////////////////////////////////////////////////////////////////////////////////////////////// + // + // PRIVILEGED METHODS + // + ////////////////////////////////////////////////////////////////////////////////////////////// + + this.getDirectory = function() + { + return directory; + }; + + this.getDirectoryId = function() + { + return directory.getId(); + }; + + ////////////////////////////////////////////////////////////////////////////////////////////// + // + // CALL THROUGH TO BASE CLASS (at the end) + // + ////////////////////////////////////////////////////////////////////////////////////////////// + + this.base(directory.getPlatform(), object); + }, + + /** + * @override + */ + clone: function() + { + return this.getFactory().connectionMap(this.getDirectory(), this); + }, + + /** + * @param json + */ + buildObject: function(json) + { + return this.getFactory().connection(this.getDirectory(), json); + } + + }); + +})(window); +(function(window) +{ + Gitana = window.Gitana; + + Gitana.Domain = Gitana.AbstractPlatformDataStore.extend( + /** @lends Gitana.Domain.prototype */ + { + /** + * @constructs + * @augments Gitana.AbstractPlatformDataStore + * + * @class Domain + * + * @param {Gitana.Platform} platform + * @param {Object} object json object (if no callback required for populating) + */ + constructor: function(platform, object) + { + this.base(platform, object); + + this.objectType = function() { return "Gitana.Domain"; }; + }, + + /** + * @OVERRIDE + */ + getUri: function() + { + return "/domains/" + this.getId(); + }, + + /** + * @OVERRIDE + */ + getType: function() + { + return Gitana.TypedIDConstants.TYPE_DOMAIN; + }, + + /** + * @override + */ + clone: function() + { + return this.getFactory().domain(this.getPlatform(), this); + }, + + + ////////////////////////////////////////////////////////////////////////////////////////// + // + // PRINCIPALS + // + ////////////////////////////////////////////////////////////////////////////////////////// + + /** + * Acquires a list of all principals. + * + * @chained principal map + * + * @param {Object} pagination pagination (optional) + * @param {Object} options + */ + listPrincipals: function(pagination, options) + { + const self = this; + + // prepare params (with pagination) + const params = {}; + if (pagination) + { + Gitana.copyInto(params, pagination); + } + + // options: see readPrincipal() + if (options) + { + Gitana.copyInto(params, options); + } + + const uriFunction = function() + { + return self.getUri() + "/principals"; + }; + + // get to work + const chainable = this.getFactory().domainPrincipalMap(this); + + // all groups + return this.chainGet(chainable, uriFunction, params); + }, + + /** + * Reads a principal. + * + * The options object is optional and can specify additional arguments for the retrieval. + * This can look like: + * + * { + * "groups": undefined | "direct" | "indirect" + * } + * + * @chained principal + * + * @param {String} principalId the principal id + * @param {Object} options + */ + readPrincipal: function(principalId, options) + { + const self = this; + + const params = {}; + if (options) + { + Gitana.copyInto(params, options); + } + + const uriFunction = function() + { + return self.getUri() + "/principals/" + principalId; + }; + + const chainable = this.getFactory().domainPrincipal(this); + + return this.chainGet(chainable, uriFunction, params); + }, + + /** + * Create a principal. + * + * @chained principal + * + * @param {Object} object JSON object + */ + createPrincipal: function(object) + { + const self = this; + + if (!object) + { + object = {}; + } + + if (!object.name) + { + // TODO: error - requires name + console.log("missing name"); + return; + } + + if (!object.type) + { + // TODO: error - requires type + console.log("missing type"); + return; + } + + const uriFunction = function() + { + return self.getUri() + "/principals"; + }; + + const chainable = this.getFactory().domainPrincipal(this, object); + + return this.chainCreate(chainable, object, uriFunction); + }, + + /** + * Queries for principals. + * + * @chained principal map + * + * @param {Object} query + * @param {Object} pagination pagination (optional) + * @param {Object} options + */ + queryPrincipals: function(query, pagination, options = undefined) + { + const self = this; + + const params = {}; + if (pagination) + { + Gitana.copyInto(params, pagination); + } + + // options: see readPrincipal() + if (options) + { + Gitana.copyInto(params, options); + } + + const uriFunction = function() + { + return self.getUri() + "/principals/query"; + }; + + const chainable = this.getFactory().domainPrincipalMap(this); + return this.chainPost(chainable, uriFunction, params, query); + }, + + + ////////////////////////////////////////////////////////////////////////////////////////// + // + // GROUPS + // + ////////////////////////////////////////////////////////////////////////////////////////// + + /** + * Acquires a list of all groups in the domain. + * + * @chained group map + * + * @param {Object} pagination pagination (optional) + */ + listGroups: function(pagination) + { + const query = { + "type": "GROUP" + }; + + return this.queryPrincipals(query, pagination); + }, + + /** + * Create a group. + * + * @chained group + * + * @param {Object} object JSON object + */ + createGroup: function(object) + { + if (!object) + { + object = {}; + } + object["type"] = "GROUP"; + + return this.createPrincipal(object); + }, + + /** + * Queries for groups. + * + * @chained principal map + * + * @param {Object} query + * @param {Object} pagination pagination (optional) + */ + queryGroups: function(query, pagination) + { + if (!query) + { + query = {}; + } + query["type"] = "GROUP"; + + return this.queryPrincipals(query, pagination); + }, + + + ////////////////////////////////////////////////////////////////////////////////////////// + // + // USERS + // + ////////////////////////////////////////////////////////////////////////////////////////// + + /** + * Acquires a list of all users. + * + * @chained user map + * + * @param {Object} pagination pagination (optional) + */ + listUsers: function(pagination) + { + const query = { + "type": "USER" + }; + + return this.queryPrincipals(query, pagination); + }, + + /** + * Create a user. + * + * @chained user + * + * @param {Object} object JSON object + */ + createUser: function(object) + { + if (!object) + { + object = {}; + } + object["type"] = "USER"; + + return this.createPrincipal(object); + }, + + /** + * Queries for users. + * + * @chained principal map + * + * @param {Object} query + * @param {Object} pagination pagination (optional) + */ + queryUsers: function(query, pagination) + { + if (!query) + { + query = {}; + } + query["type"] = "USER"; + + return this.queryPrincipals(query, pagination); + }, + + + + ////////////////////////////////////////////////////////////////////////////////////////// + // + // MEMBERSHIPS + // + ////////////////////////////////////////////////////////////////////////////////////////// + + /** + * Adds a principal as a member of a group + * + * @chained domain + * + * @public + * + * @param {Gitana.DomainGroup|String} group the group or the group id + * @param {Gitana.DomainPrincipal|String} principal the principal or the principal id + */ + addMember: function(group, principal) + { + const self = this; + + const groupId = this.extractPrincipalIdentifiers(group, this.getId())["principal"]; + const principalDomainQualifiedId = this.extractPrincipalDomainQualifiedId(principal); + + const uriFunction = function() + { + return self.getUri() + "/principals/" + groupId + "/members/add?id=" + principalDomainQualifiedId; + }; + + return this.chainPostEmpty(null, uriFunction); + }, + + /** + * Removes a principal as a member of a group. + * + * @chained domain + * + * @public + * + * @param {Gitana.DomainGroup|String} group the group or the group id + * @param {Gitana.DomainPrincipal|String} principal the principal or the principal id + */ + removeMember: function(group, principal) + { + const self = this; + + const groupId = this.extractPrincipalIdentifiers(group, this.getId())["principal"]; + const principalDomainQualifiedId = this.extractPrincipalDomainQualifiedId(principal); + + const uriFunction = function() + { + return self.getUri() + "/principals/" + groupId + "/members/remove?id=" + principalDomainQualifiedId; + }; + + return this.chainPostEmpty(null, uriFunction); + }, + + /** + * Acquires a list of all of the members who are in this group. + * + * @chained principal map + * + * @public + * + * @param {Object} group + * @param {String} filter type of principal to hand back ("user" or "group") + * @param {Object} pagination + * @param {Boolean} indirect whether to include members that inherit through child groups + */ + listMembers: function(group, filter, pagination, indirect) + { + const self = this; + + const params = {}; + if (pagination) + { + Gitana.copyInto(params, pagination); + } + if (filter) + { + params["filter"] = filter; + } + if (indirect) + { + params["indirect"] = true; + } + + const groupId = this.extractPrincipalIdentifiers(group, this.getId())["principal"]; + + const uriFunction = function() + { + return self.getUri() + "/principals/" + groupId + "/members"; + }; + + const chainable = this.getFactory().domainPrincipalMap(this); + return this.chainGet(chainable, uriFunction, params); + }, + + + + ////////////////////////////////////////////////////////////////////////////////////////// + // + // BULK PERMISSIONS CHECK + // + ////////////////////////////////////////////////////////////////////////////////////////// + + /** + * Performs a bulk check of permissions against permissioned objects of type principal. + * + * Example of checks array: + * + * [{ + * "permissionedId": "", + * "principalId": "", + * "permissionId": "" + * }] + * + * The callback receives an array of results, example: + * + * [{ + * "permissionedId": "", + * "principalId": "", + * "permissionId": "", + * "result": true + * }] + * + * The order of elements in the array will be the same for checks and results. + * + * @param checks + * @param callback + */ + checkPrincipalPermissions: function(checks, callback) + { + const self = this; + + const object = { + "checks": checks + }; + + const uriFunction = function() + { + return self.getUri() + "/principals/permissions/check"; + }; + + return this.chainPostResponse(this, uriFunction, {}, object).then(function(response) { + callback.call(this, response["results"]); + }); + }, + + /** + * Performs a bulk check of authorities against permissioned objects of type principal. + * + * Example of checks array: + * + * [{ + * "permissionedId": "", + * "principalId": "", + * "authorityId": "" + * }] + * + * The callback receives an array of results, example: + * + * [{ + * "permissionedId": "", + * "principalId": "", + * "authorityId": "", + * "result": true + * }] + * + * The order of elements in the array will be the same for checks and results. + * + * @param checks + * @param callback + */ + checkPrincipalAuthorities: function(checks, callback) + { + const self = this; + + const object = { + "checks": checks + }; + + const uriFunction = function() + { + return self.getUri() + "/principals/authorities/check"; + }; + + return this.chainPostResponse(this, uriFunction, {}, object).then(function(response) { + callback.call(this, response["results"]); + }); + }, + + /** + * Performs a bulk check to determine whether a given principal is a member of a given group. Multiple checks + * may be performed at the same time (both direct and indirect). + * + * Example of checks array: + * + * [{ + * "principalId": "", + * "groupId": "", + * "indirect": + * }] + * + * The callback receives an array of results, example: + * + * [{ + * "principalId": "", + * "groupId": "", + * "indirect": , + * "result": true + * }] + * + * The order of elements in the array will be the same for checks and results. + * + * @param checks + * @param callback + */ + checkGroupMemberships: function(checks, callback) + { + const self = this; + + const object = { + "checks": checks + }; + + const uriFunction = function() + { + return self.getUri() + "/principals/membership/check"; + }; + + return this.chainPostResponse(this, uriFunction, {}, object).then(function(response) { + callback.call(this, response["results"]); + }); + } + + }); + +})(window); +(function(window) +{ + Gitana = window.Gitana; + + Gitana.DomainMap = Gitana.AbstractPlatformObjectMap.extend( + /** @lends Gitana.DomainMap.prototype */ + { + /** + * @constructs + * @augments Gitana.AbstractPlatformObjectMap + * + * @class Map of domain objects + * + * @param {Gitana.Platform} platform Gitana platform + * @param {Object} object + */ + constructor: function(platform, object) + { + this.objectType = function() { return "Gitana.DomainMap"; }; + + + ////////////////////////////////////////////////////////////////////////////////////////////// + // + // CALL THROUGH TO BASE CLASS (at the end) + // + ////////////////////////////////////////////////////////////////////////////////////////////// + + this.base(platform, object); + }, + + /** + * @override + */ + clone: function() + { + return this.getFactory().domainMap(this.getPlatform(), this); + }, + + /** + * @param json + */ + buildObject: function(json) + { + return this.getFactory().domain(this.getPlatform(), json); + } + + }); + +})(window); +(function(window) +{ + Gitana = window.Gitana; + + Gitana.AbstractDomainObject = Gitana.AbstractPlatformObject.extend( + /** @lends Gitana.AbstractDomainObject.prototype */ + { + /** + * @constructs + * @augments Gitana.AbstractPlatformObject + * + * @class AbstractDomainObject + * + * @param {Gitana.Domain} domain + * @param {Object} object json object (if no callback required for populating) + */ + constructor: function(domain, object) + { + this.base(domain.getPlatform(), object); + + this.objectType = function() { return "Gitana.DomainPrincipal"; }; + + + + ////////////////////////////////////////////////////////////////////////////////////////////// + // + // PRIVILEGED METHODS + // + ////////////////////////////////////////////////////////////////////////////////////////////// + + /** + * Gets the Gitana Domain object. + * + * @inner + * + * @returns {Gitana.Domain} The Gitana Domain object + */ + this.getDomain = function() { return domain; }; + + /** + * Gets the Gitana Domain id. + * + * @inner + * + * @returns {String} The Gitana Domain id + */ + this.getDomainId = function() { return domain.getId(); }; + }, + + /** + * @OVERRIDE + */ + ref: function() + { + return this.getType() + "://" + this.getPlatformId() + "/" + this.getDomainId() + "/" + this.getId(); + } + + }); + +})(window); +(function(window) +{ + Gitana = window.Gitana; + + Gitana.DomainPrincipal = Gitana.AbstractDomainObject.extend( + /** @lends Gitana.DomainPrincipal.prototype */ + { + /** + * @constructs + * @augments Gitana.AbstractDomainObject + * + * @class DomainPrincipal + * + * @param {Gitana.Domain} domain + * @param {Object} object json object (if no callback required for populating) + */ + constructor: function(domain, object) + { + this.base(domain, object); + + this.objectType = function() { return "Gitana.DomainPrincipal"; }; + }, + + /** + * @override + */ + getUri: function() + { + return "/domains/" + this.getDomainId() + "/principals/" + this.getId(); + }, + + /** + * @override + */ + clone: function() + { + return this.getFactory().domainPrincipal(this.getDomain(), this); + }, + + /** + * @override + */ + beforeChainRun: function() + { + // extend the principal with any type specific methods/properties + this.getFactory().extendPrincipal(this); + }, + + /** + * @returns {String} the principal name + */ + getName: function() + { + return this.get("name"); + }, + + /** + * @returns {String} the principal type ("user" or "group") + */ + getType: function() + { + return this.get("type"); + }, + + /** + * @returns {String} the domain qualified principal name + */ + getDomainQualifiedName: function() + { + return this.getDomainId() + "/" + this.getName(); + }, + + /** + * @returns {String} the domain qualified principal id + */ + getDomainQualifiedId: function() + { + return this.getDomainId() + "/" + this.getId(); + }, + + + + ////////////////////////////////////////////////////////////////////////////////////////// + // + // MEMBERSHIPS + // + ////////////////////////////////////////////////////////////////////////////////////////// + + /** + * Acquires the groups that contain this principal + * + * @chained principal map + * + * @public + * + * @param {Boolean} indirect whether to consider indirect groups + * @param {Object} pagination + */ + listMemberships: function(indirect, pagination) + { + const params = {}; + if (pagination) + { + Gitana.copyInto(params, pagination); + } + + const uriFunction = function() + { + let uri = this.getUri() + "/memberships"; + if (indirect) + { + uri = uri + "?indirect=true"; + } + + return uri; + }; + + const chainable = this.getFactory().domainPrincipalMap(this.getDomain()); + return this.chainGet(chainable, uriFunction, params); + }, + + + ////////////////////////////////////////////////////////////////////////////////////////// + // + // ATTACHMENTS + // + ////////////////////////////////////////////////////////////////////////////////////////// + + /** + * Hands back an attachments map. + * + * @chained attachment map + * + * @param local + * + * @public + */ + listAttachments: Gitana.Methods.listAttachments(), + + /** + * Picks off a single attachment + * + * @chained attachment + * + * @param attachmentId + */ + attachment: function(attachmentId) + { + return this.listAttachments().select(attachmentId); + }, + + /** + * Creates an attachment. + * + * When using this method from within the JS driver, it really only works for text-based content such + * as JSON or text. + * + * @chained attachment + * + * @param attachmentId (use null or false for default attachment) + * @param contentType + * @param data + */ + attach: Gitana.Methods.attach(), + + /** + * Deletes an attachment. + * + * @param attachmentId + */ + unattach: Gitana.Methods.unattach(), + + /** + * Generates a URI to a preview resource. + */ + getPreviewUri: Gitana.Methods.getPreviewUri(), + + /** + * Lists the authentication grants for this principal + * + * @param pagination + * + * @chained authentication grant map + */ + listAuthenticationGrants: function(pagination) + { + const params = {}; + if (pagination) + { + Gitana.copyInto(params, pagination); + } + + params.domainId = this.getDomainId(); + params.principalId = this.getId(); + + const chainable = this.getFactory().authenticationGrantMap(this.getPlatform()); + return this.chainGet(chainable, "/auth/grants", params); + }, + + /** + * Lists the teams that this principal belongs to against the given teamable + * + * @param teamable + * @param pagination (optional) + */ + listTeamMemberships: function(teamable, pagination) + { + const params = { + "teamableType": teamable.getType(), + "teamableId": teamable.getId() + }; + + if (pagination) + { + Gitana.copyInto(params, pagination); + } + + const uriFunction = function() + { + return this.getUri() + "/teams"; + }; + + const chainable = this.getFactory().teamMap(this.getCluster(), this); + return this.chainGet(chainable, uriFunction, params); + } + + }); + +})(window); +(function(window) +{ + Gitana = window.Gitana; + + Gitana.PrincipalMap = Gitana.AbstractPlatformObjectMap.extend( + /** @lends Gitana.PrincipalMap.prototype */ + { + /** + * @constructs + * @augments Gitana.AbstractPlatformObjectMap + * + * @class Map of principal objects + * + * @param {Gitana.Domain} domain Gitana domain instance. + * @param {Object} object + */ + constructor: function(domain, object) + { + this.objectType = function() { return "Gitana.PrincipalMap"; }; + + this.getDomain = function() + { + return domain; + }; + + ////////////////////////////////////////////////////////////////////////////////////////////// + // + // CALL THROUGH TO BASE CLASS (at the end) + // + ////////////////////////////////////////////////////////////////////////////////////////////// + + this.base(domain.getPlatform(), object); + }, + + /** + * @override + */ + clone: function() + { + return this.getFactory().domainPrincipalMap(this.getDomain(), this); + }, + + /** + * @param json + */ + buildObject: function(json) + { + return this.getFactory().domainPrincipal(this.getDomain(), json); + } + + }); + +})(window); +(function(window) +{ + Gitana = window.Gitana; + + Gitana.DomainGroup = + { + TYPE: "GROUP", + + ref: function() + { + return "group://" + this.getPlatformId() + "/" + this.getDomainId() + "/" + this.getId(); + }, + + /** + * Reads the group node for this user. + * + * @param branch + * @param createIfNotFound + * + * @chained person + * @public + */ + readGroupNode: function(branch, createIfNotFound) + { + // what we hand back + const result = this.subchain(this.getFactory().node(branch, "n:group")); + + // work + result.subchain(branch).readGroupNode(this.getId(), createIfNotFound).then(function() { + result.handleResponse(this); + }); + + return result; + }, + + /** + * Acquires a list of all of the members who are in this group. + * + * @chained principal map + * + * @public + * + * @param {String} filter type of principal to hand back ("user" or "group") + * @param {Boolean} indirect whether to include members that inherit through child groups + * @param {Object} pagination + */ + listMembers: function(filter, indirect, pagination) + { + const self = this; + + const params = {}; + if (pagination) + { + Gitana.copyInto(params, pagination); + } + if (filter) + { + params["filter"] = filter; + } + if (indirect) + { + params["indirect"] = true; + } + + const uriFunction = function() + { + return self.getUri() + "/members"; + }; + + const chainable = this.getFactory().domainPrincipalMap(this.getDomain()); + return this.chainGet(chainable, uriFunction, params); + }, + + /** + * Acquires a list of all of the users who are in this group. + * + * @chained principal map + * + * @public + * + * @param {Boolean} inherit whether to include members that inherit through child groups + * @param {Object} pagination + */ + listUsers: function() + { + let inherit = false; + let pagination = null; + const args = Gitana.makeArray(arguments); + const a1 = args.shift(); + if (Gitana.isBoolean(a1)) + { + inherit = a1; + pagination = args.shift(); + } + else + { + pagination = args.shift(); + } + + return this.listMembers("user", inherit, pagination); + }, + + /** + * Acquires a list of all of the groups who are in this group. + * + * @chained principal map + * + * @public + * + * @param {Boolean} inherit whether to include members that inherit through child groups + * @param {Object} pagination + */ + listGroups: function() + { + let inherit = false; + let pagination = null; + const args = Gitana.makeArray(arguments); + const a1 = args.shift(); + if (Gitana.isBoolean(a1)) + { + inherit = a1; + pagination = args.shift(); + } + else + { + pagination = a1; + } + + return this.listMembers("group", inherit, pagination); + }, + + /** + * Adds a principal as a member of this group. + * + * @chained current group + * + * @public + * + * @param {Gitana.Principal|String} principal the principal or the principal id + */ + addMember: function(principal) + { + const principalDomainQualifiedId = this.extractPrincipalDomainQualifiedId(principal); + + return this.chainPostEmpty(null, this.getUri() + "/members/add?id=" + principalDomainQualifiedId); + }, + + /** + * Removes a principal as a member of this group. + * + * @chained current group + * + * @public + * + * @param {Gitana.Principal|String} principal the principal or the principal id + */ + removeMember: function(principal) + { + const principalDomainQualifiedId = this.extractPrincipalDomainQualifiedId(principal); + + return this.chainPostEmpty(null, this.getUri() + "/members/remove?id=" + principalDomainQualifiedId); + } + + }; + +})(window); +(function(window) +{ + Gitana = window.Gitana; + + Gitana.DomainUser = + { + TYPE: "USER", + + ref: function() + { + return "user://" + this.getPlatformId() + "/" + this.getDomainId() + "/" + this.getId(); + }, + + /** + * Reads the person node for this user. + * + * @param branch + * @param createIfNotFound + * + * @chained person + * @public + */ + readPersonNode: function(branch, createIfNotFound) + { + // what we hand back + const result = this.subchain(this.getFactory().node(branch, "n:person")); + + // work + result.subchain(branch).readPersonNode(this.getDomainQualifiedId(), createIfNotFound).then(function() { + result.handleResponse(this); + }); + + return result; + }, + + hasIdentity: function() + { + return (this.getDirectoryId() && this.getIdentityId()); + }, + + getDirectoryId: function() + { + return this.get("directoryId"); + }, + + getIdentityId: function() + { + return this.get("identityId"); + }, + + readDirectory: function() + { + const directory = this.getFactory().directory(this.getPlatform(), { + "_doc": this.getDirectoryId() + }); + + // what we hand back + const result = this.subchain(directory); + + // work + result.subchain(this.getPlatform()).readDirectory(this.getDirectoryId()).then(function() { + result.handleResponse(this); + }); + + return result; + }, + + readIdentity: function() + { + const self = this; + + const directory = this.getFactory().directory(this.getPlatform(), { + "_doc": this.getDirectoryId() + }); + + const identity = this.getFactory().identity(directory, { + "_doc": this.getIdentityId() + }); + + + // what we hand back + const result = this.subchain(identity); + + // work + result.subchain(this.getPlatform()).readDirectory(self.getDirectoryId()).then(function() { + + // NOTE: this = directory + + directory.handleResponse(this); + + this.readIdentity(self.getIdentityId()).then(function() { + + // NOTE: this = identity + + identity.handleResponse(this); + + // all done + }); + + //return false; + }); + + return result; + }, + + ////////////////////////////////////////////////////////////////////////////////////////////////// + // + // PROPERTIES + // + ////////////////////////////////////////////////////////////////////////////////////////////////// + + getFirstName: function() + { + return this.get("firstName"); + }, + + setFirstName: function(firstName) + { + this.set("firstName", firstName); + }, + + getLastName: function() + { + return this.get("lastName"); + }, + + setLastName: function(lastName) + { + this.set("lastName", lastName); + }, + + getCompanyName: function() + { + return this.get("companyName"); + }, + + setCompanyName: function(companyName) + { + this.set("companyName", companyName); + }, + + getEmail: function() + { + return this.get("email"); + }, + + setEmail: function(email) + { + this.set("email", email); + }, + + getJobTitle: function() + { + return this.get("jobTitle"); + }, + + setJobTitle: function(jobTitle) + { + this.set("jobTitle", jobTitle); + }, + + getAddress: function() + { + return this.get("address"); + }, + + setAddress: function(address) + { + this.set("address", address); + }, + + getCity: function() + { + return this.get("city"); + }, + + setCity: function(city) + { + this.set("city", city); + }, + + getState: function() + { + return this.get("state"); + }, + + setState: function(state) + { + this.set("state", state); + }, + + getZipcode: function() + { + return this.get("zipcode"); + }, + + setZipcode: function(zipcode) + { + this.set("zipcode", zipcode); + }, + + getPhoneNumber: function() + { + return this.get("phoneNumber"); + }, + + setPhoneNumber: function(phoneNumber) + { + this.set("phoneNumber", phoneNumber); + } + + }; + +})(window); +(function(window) +{ + Gitana = window.Gitana; + + Gitana.Registrar = Gitana.AbstractPlatformDataStore.extend( + /** @lends Gitana.Registrar.prototype */ + { + /** + * @constructs + * @augments Gitana.AbstractPlatformDataStore + * + * @class Registrar + * + * @param {Gitana.Platform} platform + * @param {Object} object json object (if no callback required for populating) + */ + constructor: function(platform, object) + { + this.objectType = function() { return "Gitana.Registrar"; }; + + this.base(platform, object); + }, + + /** + * @OVERRIDE + */ + getUri: function() + { + return "/registrars/" + this.getId(); + }, + + /** + * @OVERRIDE + */ + getType: function() + { + return Gitana.TypedIDConstants.TYPE_REGISTRAR; + }, + + /** + * @override + */ + clone: function() + { + return this.getFactory().registrar(this.getPlatform(), this); + }, + + + + + ///////////////////////////////////////////////////////////////////////////////////////////////// + // + // TENANTS + // + ///////////////////////////////////////////////////////////////////////////////////////////////// + + /** + * Lists all of the tenants. + * + * @chained tenant map + * + * @param {Object} pagination pagination (optional) + */ + listTenants: function(pagination) + { + const self = this; + + const uriFunction = function() + { + return self.getUri() + "/tenants"; + }; + + // prepare params (with pagination) + const params = {}; + if (pagination) + { + Gitana.copyInto(params, pagination); + } + + const chainable = this.getFactory().tenantMap(this); + return this.chainGet(chainable, uriFunction, params); + }, + + /** + * Queries for a tenant. + * + * @chained tenant map + * + * @param {Object} query Query for finding a tenant. + * @param {Object} pagination pagination (optional) + */ + queryTenants: function(query, pagination) + { + const self = this; + + const uriFunction = function() + { + return self.getUri() + "/tenants/query"; + }; + + const chainable = this.getFactory().tenantMap(this); + + // prepare params (with pagination) + const params = {}; + if (pagination) + { + Gitana.copyInto(params, pagination); + } + + return this.chainPost(chainable, uriFunction, params, query); + }, + + /** + * Reads a tenant. + * + * @chained tenant + * + * @param {String} tenantId the tenant id + */ + readTenant: function(tenantId) + { + const self = this; + + const uriFunction = function() + { + return self.getUri() + "/tenants/" + tenantId; + }; + + const chainable = this.getFactory().tenant(this); + return this.chainGet(chainable, uriFunction); + }, + + /** + * Lookup a tenant for a principal. + * + * @chained tenant + * + * @param {Gitana.Principal} principal + */ + lookupTenantForPrincipal: function(principal) + { + const self = this; + + const uriFunction = function() + { + return self.getUri() + "/tenants/lookup?id=" + principal.getDomainQualifiedId(); + }; + + const chainable = this.getFactory().tenant(this); + return this.chainGet(chainable, uriFunction); + }, + + /** + * Creates a tenant + * + * @chained tenant + * + * @param {Gitana.DomainPrincipal} principal + * @param {String} planKey + * @param {Object} paymentMethod method (required if plan requires a payment method) + */ + createTenant: function(principal, planKey, paymentMethod) + { + const self = this; + + const uriFunction = function() + { + return self.getUri() + "/tenants"; + }; + + // set up object + const object = {}; + object["principalId"] = principal.getId(); + object["domainId"] = principal.getDomainId(); + object["planKey"] = planKey; + if (paymentMethod) + { + object["paymentMethod"] = paymentMethod; + } + + // create + const chainable = this.getFactory().tenant(this); + return this.chainCreate(chainable, object, uriFunction); + }, + + /** + * Performs a bulk check of permissions against permissioned objects of type tenant. + * + * Example of checks array: + * + * [{ + * "permissionedId": "", + * "domainId": "", (optional) + * "principalId": "", + * "permissionId": "" + * }] + * + * The callback receives an array of results, example: + * + * [{ + * "permissionedId": "", + * "domainId": "", (optional) + * "principalId": "", + * "permissionId": "", + * "result": true + * }] + * + * The order of elements in the array will be the same for checks and results. + * + * @param checks + * @param callback + */ + checkTenantPermissions: function(checks, callback) + { + const self = this; + + const uriFunction = function() + { + return self.getUri() + "/tenants/permissions/check"; + }; + + const object = { + "checks": checks + }; + + return this.chainPostResponse(this, uriFunction, {}, object).then(function(response) { + callback.call(this, response["results"]); + }); + }, + + /** + * Performs a bulk check of authorities against permissioned objects of type tenant. + * + * Example of checks array: + * + * [{ + * "permissionedId": "", + * "principalId": "", + * "authorityId": "" + * }] + * + * The callback receives an array of results, example: + * + * [{ + * "permissionedId": "", + * "principalId": "", + * "authorityId": "", + * "result": true + * }] + * + * The order of elements in the array will be the same for checks and results. + * + * @param checks + * @param callback + */ + checkTenantAuthorities: function(checks, callback) + { + const self = this; + + const uriFunction = function() + { + return self.getUri() + "/tenants/authorities/check"; + }; + + const object = { + "checks": checks + }; + + return this.chainPostResponse(this, uriFunction, {}, object).then(function(response) { + callback.call(this, response["results"]); + }); + }, + + + + + + ///////////////////////////////////////////////////////////////////////////////////////////////// + // + // PLANS + // + ///////////////////////////////////////////////////////////////////////////////////////////////// + + /** + * Lists all of the plans. + * + * @chained plan map + * + * @param {Object} pagination pagination (optional) + */ + listPlans: function(pagination) + { + const self = this; + + const uriFunction = function() + { + return self.getUri() + "/plans"; + }; + + // prepare params (with pagination) + const params = {}; + if (pagination) + { + Gitana.copyInto(params, pagination); + } + + const chainable = this.getFactory().planMap(this); + return this.chainGet(chainable, uriFunction, params); + }, + + /** + * Queries for plans. + * + * @chained plan map + * + * @param {Object} query Query for finding a tenant. + * @param {Object} pagination pagination (optional) + */ + queryPlans: function(query, pagination) + { + const self = this; + + const uriFunction = function() + { + return self.getUri() + "/plans/query"; + }; + + const chainable = this.getFactory().planMap(this); + + // prepare params (with pagination) + const params = {}; + if (pagination) + { + Gitana.copyInto(params, pagination); + } + + return this.chainPost(chainable, uriFunction, params, query); + }, + + /** + * Reads a plan. + * + * @chained plan + * + * @param {String} planId the plan id + */ + readPlan: function(planId) + { + const self = this; + + const uriFunction = function() + { + return self.getUri() + "/plans/" + planId; + }; + + const chainable = this.getFactory().plan(this); + return this.chainGet(chainable, uriFunction); + }, + + /** + * Creates a plan + * + * @chained plan + * + * @param {Object} object JSON object + */ + createPlan: function(object) + { + const self = this; + + const uriFunction = function() + { + return self.getUri() + "/plans"; + }; + + const chainable = this.getFactory().plan(this); + return this.chainCreate(chainable, object, uriFunction); + }, + + /** + * Performs a bulk check of permissions against permissioned objects of type plan. + * + * Example of checks array: + * + * [{ + * "permissionedId": "", + * "domainId": "", (optional) + * "principalId": "", + * "permissionId": "" + * }] + * + * The callback receives an array of results, example: + * + * [{ + * "permissionedId": "", + * "domainId": "", (optional) + * "principalId": "", + * "permissionId": "", + * "result": true + * }] + * + * The order of elements in the array will be the same for checks and results. + * + * @param checks + * @param callback + */ + checkPlanPermissions: function(checks, callback) + { + const self = this; + + const uriFunction = function() + { + return self.getUri() + "/plans/permissions/check"; + }; + + const object = { + "checks": checks + }; + + return this.chainPostResponse(this, uriFunction, {}, object).then(function(response) { + callback.call(this, response["results"]); + }); + }, + + /** + * Performs a bulk check of authorities against permissioned objects of type plan. + * + * Example of checks array: + * + * [{ + * "permissionedId": "", + * "principalId": "", + * "authorityId": "" + * }] + * + * The callback receives an array of results, example: + * + * [{ + * "permissionedId": "", + * "principalId": "", + * "authorityId": "", + * "result": true + * }] + * + * The order of elements in the array will be the same for checks and results. + * + * @param checks + * @param callback + */ + checkPlanAuthorities: function(checks, callback) + { + const self = this; + + const uriFunction = function() + { + return self.getUri() + "/plans/authorities/check"; + }; + + const object = { + "checks": checks + }; + + return this.chainPostResponse(this, uriFunction, {}, object).then(function(response) { + callback.call(this, response["results"]); + }); + }, + + + + + ///////////////////////////////////////////////////////////////////////////////////////////////// + // + // METERS + // + ///////////////////////////////////////////////////////////////////////////////////////////////// + + /** + * Lists all of the meters. + * + * @chained meter map + * + * @param {Object} pagination pagination (optional) + */ + listMeters: function(pagination) + { + const self = this; + + const uriFunction = function() + { + return self.getUri() + "/meters"; + }; + + // prepare params (with pagination) + const params = {}; + if (pagination) + { + Gitana.copyInto(params, pagination); + } + + const chainable = this.getFactory().meterMap(this); + return this.chainGet(chainable, uriFunction, params); + }, + + /** + * Queries for meters. + * + * @chained meter map + * + * @param {Object} query Query for finding a tenant. + * @param {Object} pagination pagination (optional) + */ + queryMeters: function(query, pagination) + { + const self = this; + + const uriFunction = function() + { + return self.getUri() + "/meters/query"; + }; + + const chainable = this.getFactory().meterMap(this); + + // prepare params (with pagination) + const params = {}; + if (pagination) + { + Gitana.copyInto(params, pagination); + } + + return this.chainPost(chainable, uriFunction, params, query); + }, + + /** + * Reads a meter. + * + * @chained meter + * + * @param {String} meterId the meter id + */ + readMeter: function(meterId) + { + const self = this; + + const uriFunction = function() + { + return self.getUri() + "/meters/" + meterId; + }; + + const chainable = this.getFactory().meter(this); + return this.chainGet(chainable, uriFunction); + }, + + /** + * Creates a meter + * + * @chained meter + * + * @param {Object} object JSON object + */ + createMeter: function(object) + { + const self = this; + + const uriFunction = function() + { + return self.getUri() + "/meters"; + }; + + const chainable = this.getFactory().meter(this); + return this.chainCreate(chainable, object, uriFunction); + }, + + /** + * Performs a bulk check of permissions against permissioned objects of type meter. + * + * Example of checks array: + * + * [{ + * "permissionedId": "", + * "domainId": "", (optional) + * "principalId": "", + * "permissionId": "" + * }] + * + * The callback receives an array of results, example: + * + * [{ + * "permissionedId": "", + * "domainId": "", (optional) + * "principalId": "", + * "permissionId": "", + * "result": true + * }] + * + * The order of elements in the array will be the same for checks and results. + * + * @param checks + * @param callback + */ + checkMeterPermissions: function(checks, callback) + { + const self = this; + + const uriFunction = function() + { + return self.getUri() + "/meters/permissions/check"; + }; + + const object = { + "checks": checks + }; + + return this.chainPostResponse(this, uriFunction, {}, object).then(function(response) { + callback.call(this, response["results"]); + }); + }, + + /** + * Performs a bulk check of authorities against permissioned objects of type meter. + * + * Example of checks array: + * + * [{ + * "permissionedId": "", + * "principalId": "", + * "authorityId": "" + * }] + * + * The callback receives an array of results, example: + * + * [{ + * "permissionedId": "", + * "principalId": "", + * "authorityId": "", + * "result": true + * }] + * + * The order of elements in the array will be the same for checks and results. + * + * @param checks + * @param callback + */ + checkMeterAuthorities: function(checks, callback) + { + const self = this; + + const uriFunction = function() + { + return self.getUri() + "/meters/authorities/check"; + }; + + const object = { + "checks": checks + }; + + return this.chainPostResponse(this, uriFunction, {}, object).then(function(response) { + callback.call(this, response["results"]); + }); + } + + }); + +})(window); +(function(window) +{ + Gitana = window.Gitana; + + Gitana.RegistrarMap = Gitana.AbstractPlatformObjectMap.extend( + /** @lends Gitana.RegistrarMap.prototype */ + { + /** + * @constructs + * @augments Gitana.AbstractPlatformObjectMap + * + * @class Map of registrar objects + * + * @param {Gitana.Platform} platform Gitana platform + * @param {Object} object + */ + constructor: function(platform, object) + { + this.objectType = function() { return "Gitana.RegistrarMap"; }; + + + ////////////////////////////////////////////////////////////////////////////////////////////// + // + // CALL THROUGH TO BASE CLASS (at the end) + // + ////////////////////////////////////////////////////////////////////////////////////////////// + + this.base(platform, object); + }, + + /** + * @override + */ + clone: function() + { + return this.getFactory().registrarMap(this.getPlatform(), this); + }, + + /** + * @param json + */ + buildObject: function(json) + { + return this.getFactory().registrar(this.getPlatform(), json); + } + + }); + +})(window); +(function(window) +{ + Gitana = window.Gitana; + + Gitana.AbstractRegistrarObject = Gitana.AbstractPlatformObject.extend( + /** @lends Gitana.AbstractRegistrarObject.prototype */ + { + /** + * @constructs + * @augments Gitana.AbstractPlatformObject + * + * @class AbstractRegistrarObject + * + * @param {Gitana.Registrar} registrar + * @param {Object} object json object (if no callback required for populating) + */ + constructor: function(registrar, object) + { + this.base(registrar.getPlatform(), object); + + this.objectType = function() { return "Gitana.Meter"; }; + + + ////////////////////////////////////////////////////////////////////////////////////////////// + // + // PRIVILEGED METHODS + // + ////////////////////////////////////////////////////////////////////////////////////////////// + + this.getRegistrar = function() + { + return registrar; + }; + + this.getRegistrarId = function() + { + return registrar.getId(); + }; + }, + + /** + * @OVERRIDE + */ + ref: function() + { + return this.getType() + "://" + this.getPlatformId() + "/" + this.getRegistrarId() + "/" + this.getId(); + } + + }); + +})(window); +(function(window) +{ + Gitana = window.Gitana; + + Gitana.Meter = Gitana.AbstractRegistrarObject.extend( + /** @lends Gitana.Meter.prototype */ + { + /** + * @constructs + * @augments Gitana.AbstractRegistrarObject + * + * @class Meter + * + * @param {Gitana.Registrar} registrar + * @param {Object} object json object (if no callback required for populating) + */ + constructor: function(registrar, object) + { + this.base(registrar, object); + + this.objectType = function() { return "Gitana.Meter"; }; + }, + + /** + * @OVERRIDE + */ + getType: function() + { + return Gitana.TypedIDConstants.TYPE_PLAN; + }, + + /** + * @OVERRIDE + */ + getUri: function() + { + return "/registrars/" + this.getRegistrarId() + "/meters/" + this.getId(); + }, + + /** + * @override + */ + clone: function() + { + return this.getFactory().meter(this.getRegistrar(), this); + } + + }); + + // constants + + // tenant information + Gitana.Meter.FIELD_TENANT_ID = "tenantId"; + + // meter data + Gitana.Meter.FIELD_METER_TYPE = "meterType"; + Gitana.Meter.FIELD_METER_START = "meterStart"; // timestamp + Gitana.Meter.FIELD_METER_END = "meterEnd"; // timestamp + + // bytes + Gitana.Meter.FIELD_MAX_BYTE_COUNT = "maxByteCount"; + Gitana.Meter.FIELD_RAW_BYTE_COUNT = "rawByteCount"; // raw count (all bytes counter) + Gitana.Meter.FIELD_RAW_BYTE_COUNT_PERCENTAGE = "rawByteCountPercentage"; + Gitana.Meter.FIELD_UNPROCESSED_BYTE_COUNT = "unprocessedByteCount"; // waiting to be processed + Gitana.Meter.FIELD_BILLABLE_BYTE_COUNT = "billableByteCount"; + Gitana.Meter.FIELD_BILLABLE_BYTE_COUNT_PERCENTAGE = "billableByteCountPercentage"; + + // objects + Gitana.Meter.FIELD_MAX_OBJECT_COUNT = "maxObjectCount"; + Gitana.Meter.FIELD_RAW_OBJECT_COUNT = "rawObjectCount"; // raw count (all objects counter) + Gitana.Meter.FIELD_RAW_OBJECT_COUNT_PERCENTAGE = "rawObjectCountPercentage"; + Gitana.Meter.FIELD_UNPROCESSED_OBJECT_COUNT = "unprocessedObjectCount"; + Gitana.Meter.FIELD_BILLABLE_OBJECT_COUNT = "billableObjectCount"; + Gitana.Meter.FIELD_BILLABLE_OBJECT_COUNT_PERCENTAGE = "billableObjectCountPercentage"; + +})(window); +(function(window) +{ + Gitana = window.Gitana; + + Gitana.MeterMap = Gitana.AbstractPlatformObjectMap.extend( + /** @lends Gitana.MeterMap.prototype */ + { + /** + * @constructs + * @augments Gitana.AbstractPlatformObjectMap + * + * @class Map of meter objects + * + * @param {Gitana.Registrar} registrar Gitana registrar object + * @param {Object} object + */ + constructor: function(registrar, object) + { + this.objectType = function() { return "Gitana.MeterMap"; }; + + + ////////////////////////////////////////////////////////////////////////////////////////////// + // + // PRIVILEGED METHODS + // + ////////////////////////////////////////////////////////////////////////////////////////////// + + this.getRegistrar = function() + { + return registrar; + }; + + this.getRegistrarId = function() + { + return registrar.getId(); + }; + + ////////////////////////////////////////////////////////////////////////////////////////////// + // + // CALL THROUGH TO BASE CLASS (at the end) + // + ////////////////////////////////////////////////////////////////////////////////////////////// + + this.base(registrar.getPlatform(), object); + }, + + /** + * @override + */ + clone: function() + { + return this.getFactory().planMap(this.getRegistrar(), this); + }, + + /** + * @param json + */ + buildObject: function(json) + { + return this.getFactory().plan(this.getRegistrar(), json); + } + + }); + +})(window); +(function(window) +{ + Gitana = window.Gitana; + + Gitana.Plan = Gitana.AbstractRegistrarObject.extend( + /** @lends Gitana.Plan.prototype */ + { + /** + * @constructs + * @augments Gitana.AbstractRegistrarObject + * + * @class Plan + * + * @param {Gitana.Registrar} registrar + * @param {Object} object json object (if no callback required for populating) + */ + constructor: function(registrar, object) + { + this.base(registrar, object); + + this.objectType = function() { return "Gitana.Plan"; }; + }, + + /** + * @OVERRIDE + */ + getType: function() + { + return Gitana.TypedIDConstants.TYPE_PLAN; + }, + + /** + * @OVERRIDE + */ + getUri: function() + { + return "/registrars/" + this.getRegistrarId() + "/plans/" + this.getId(); + }, + + /** + * @override + */ + clone: function() + { + return this.getFactory().plan(this.getRegistrar(), this); + }, + + getPlanKey: function() + { + return this.get("planKey"); + } + + }); + +})(window); +(function(window) +{ + Gitana = window.Gitana; + + Gitana.PlanMap = Gitana.AbstractPlatformObjectMap.extend( + /** @lends Gitana.PlanMap.prototype */ + { + /** + * @constructs + * @augments Gitana.AbstractPlatformObjectMap + * + * @class Map of plan objects + * + * @param {Gitana.Registrar} registrar Gitana registrar object + * @param {Object} object + */ + constructor: function(registrar, object) + { + this.objectType = function() { return "Gitana.PlanMap"; }; + + + ////////////////////////////////////////////////////////////////////////////////////////////// + // + // PRIVILEGED METHODS + // + ////////////////////////////////////////////////////////////////////////////////////////////// + + this.getRegistrar = function() + { + return registrar; + }; + + this.getRegistrarId = function() + { + return registrar.getId(); + }; + + ////////////////////////////////////////////////////////////////////////////////////////////// + // + // CALL THROUGH TO BASE CLASS (at the end) + // + ////////////////////////////////////////////////////////////////////////////////////////////// + + this.base(registrar.getPlatform(), object); + }, + + /** + * @override + */ + clone: function() + { + return this.getFactory().planMap(this.getRegistrar(), this); + }, + + /** + * @param json + */ + buildObject: function(json) + { + return this.getFactory().plan(this.getRegistrar(), json); + } + + }); + +})(window); +(function(window) +{ + Gitana = window.Gitana; + + Gitana.Tenant = Gitana.AbstractRegistrarObject.extend( + /** @lends Gitana.Tenant.prototype */ + { + /** + * @constructs + * @augments Gitana.AbstractRegistrarObject + * + * @class Tenant + * + * @param {Gitana.Registrar} registrar + * @param {Object} object json object (if no callback required for populating) + */ + constructor: function(registrar, object) + { + this.base(registrar, object); + + this.objectType = function() { return "Gitana.Tenant"; }; + }, + + /** + * @OVERRIDE + */ + getType: function() + { + return Gitana.TypedIDConstants.TYPE_TENANT; + }, + + /** + * @OVERRIDE + */ + getUri: function() + { + return "/registrars/" + this.getRegistrarId() + "/tenants/" + this.getId(); + }, + + /** + * @override + */ + clone: function() + { + return this.getFactory().tenant(this.getRegistrar(), this); + }, + + /** + * Gets the DNS slug for the tenant + */ + getDnsSlug: function() + { + return this.get("dnsSlug"); + }, + + /** + * Gets the plan key for the tenant + */ + getPlanKey: function() + { + return this.get("planKey"); + }, + + /** + * Gets the id of the principal that is the owner of this tenant. + */ + getPrincipalId: function() + { + return this.get("principalId"); + }, + + /** + * Gets the domain id of the principal that is the owner of this tenant. + */ + getPrincipalDomainId: function() + { + return this.get("domainId"); + }, + + /** + * Gets the id of the platform that belongs to this tenant. + */ + getPlatformId: function() + { + return this.get("platformId"); + }, + + /** + * Hands back the plan that this tenant is subscribed to. + * + * @chained plan + */ + readTenantPlan: function() + { + const self = this; + + const uriFunction = function() + { + return self.getPlatform().getUri() + "/registrars/" + self.getRegistrarId() + "/plans/" + self.getPlanKey(); + }; + + const chainable = this.getFactory().plan(this.getRegistrar()); + return this.chainGet(chainable, uriFunction); + }, + + /** + * Hands back the principal that owns this tenant. + * + * @chained principal + */ + readTenantPrincipal: function() + { + const self = this; + + const uriFunction = function() + { + return self.getPlatform().getUri() + "/domains/" + self.getPrincipalDomainId() + "/principals/" + self.getPrincipalId(); + }; + + // TODO - this is a pretty big hack at the moment + const domain = this.getFactory().domain(this.getPlatform(), { + "_doc": this.getPrincipalDomainId() + }); + + const chainable = this.getFactory().domainPrincipal(domain); + return this.chainGet(chainable, uriFunction); + }, + + + + + ////////////////////////////////////////////////////////////////////////////////////////// + // + // ATTACHMENTS + // + ////////////////////////////////////////////////////////////////////////////////////////// + + /** + * Hands back an attachments map. + * + * @chained attachment map + * + * @param local + * + * @public + */ + listAttachments: Gitana.Methods.listAttachments(), + + /** + * Picks off a single attachment + * + * @chained attachment + * + * @param attachmentId + */ + attachment: function(attachmentId) + { + return this.listAttachments().select(attachmentId); + }, + + /** + * Creates an attachment. + * + * When using this method from within the JS driver, it really only works for text-based content such + * as JSON or text. + * + * @chained attachment + * + * @param attachmentId (use null or false for default attachment) + * @param contentType + * @param data + */ + attach: Gitana.Methods.attach(), + + /** + * Deletes an attachment. + * + * @param attachmentId + */ + unattach: Gitana.Methods.unattach(), + + + + + + ////////////////////////////////////////////////////////////////////////////////////////// + // + // METHODS + // + ////////////////////////////////////////////////////////////////////////////////////////// + + /** + * Lists the allocations to the tenant. + * + * @param callback the callback function + * @param objectType + * @param pagination + * + * @chained this + */ + listAllocatedObjects: function(callback, objectType, pagination) + { + const self = this; + + const uriFunction = function() + { + return self.getUri() + "/objects"; + }; + + // parameters + const params = {}; + if (pagination) + { + Gitana.copyInto(params, pagination); + } + if (objectType) + { + params["type"] = objectType; + } + + return this.chainGetResponse(this, uriFunction, params).then(function(response) { + callback.call(this, response["rows"]); + }); + }, + + listAllocatedRepositoryObjects: function(callback, pagination) + { + return this.listAllocatedObjects(callback, "repository", pagination); + }, + + listAllocatedDomainObjects: function(callback, pagination) + { + return this.listAllocatedObjects(callback, "domain", pagination); + }, + + listAllocatedVaultObjects: function(callback, pagination) + { + return this.listAllocatedObjects(callback, "vault", pagination); + }, + + listAllocatedClientObjects: function(callback, pagination) + { + return this.listAllocatedObjects(callback, "client", pagination); + }, + + listAllocatedRegistrarObjects: function(callback, pagination) + { + return this.listAllocatedObjects(callback, "registrar", pagination); + }, + + listAllocatedStackObjects: function(callback, pagination) + { + return this.listAllocatedObjects(callback, "stack", pagination); + }, + + listAllocatedDirectoryObjects: function(callback, pagination) + { + return this.listAllocatedObjects(callback, "directory", pagination); + }, + + listAllocatedApplicationObjects: function(callback, pagination) + { + return this.listAllocatedObjects(callback, "application", pagination); + }, + + /** + * Retrieves the default client configuration for this tenant. + * + * @param callback the method to receive the client configuration + * + * @chained this + */ + readDefaultAllocatedClientObject: function(callback) + { + const self = this; + + const uriFunction = function() + { + return self.getUri() + "/defaultclient"; + }; + + return this.chainGetResponse(this, uriFunction, {}).then(function(response) { + + const client = {}; + Gitana.copyInto(client, response); + Gitana.stampInto(client, Gitana.ClientMethods); + client.get = function(key) { return this[key]; }; + + callback.call(this, client); + }); + }, + + /** + * Lists the auto-client mappings maintained for this tenant. + * + * @param callback the callback function + * @param pagination + * + * @chained this + */ + listAutoClientMappingObjects: function(callback, pagination) + { + const self = this; + + const uriFunction = function() + { + return self.getUri() + "/autoclientmappings"; + }; + + // parameters + const params = {}; + if (pagination) + { + Gitana.copyInto(params, pagination); + } + + return this.chainGetResponse(this, uriFunction, params).then(function(response) { + callback.call(this, response["rows"]); + }); + } + + }); + +})(window); +(function(window) +{ + Gitana = window.Gitana; + + Gitana.TenantMap = Gitana.AbstractPlatformObjectMap.extend( + /** @lends Gitana.TenantMap.prototype */ + { + /** + * @constructs + * @augments Gitana.AbstractPlatformObjectMap + * + * @class Map of tenant objects + * + * @param {Gitana.Registrar} registrar Gitana registrar object + * @param {Object} object + */ + constructor: function(registrar, object) + { + this.objectType = function() { return "Gitana.TenantMap"; }; + + + ////////////////////////////////////////////////////////////////////////////////////////////// + // + // PRIVILEGED METHODS + // + ////////////////////////////////////////////////////////////////////////////////////////////// + + this.getRegistrar = function() + { + return registrar; + }; + + this.getRegistrarId = function() + { + return registrar.getId(); + }; + + ////////////////////////////////////////////////////////////////////////////////////////////// + // + // CALL THROUGH TO BASE CLASS (at the end) + // + ////////////////////////////////////////////////////////////////////////////////////////////// + + this.base(registrar.getPlatform(), object); + }, + + /** + * @override + */ + clone: function() + { + return this.getFactory().tenantMap(this.getRegistrar(), this); + }, + + /** + * @param json + */ + buildObject: function(json) + { + return this.getFactory().tenant(this.getRegistrar(), json); + } + + }); + +})(window); +(function(window) +{ + Gitana = window.Gitana; + + Gitana.Repository = Gitana.AbstractPlatformDataStore.extend( + /** @lends Gitana.Repository.prototype */ + { + /** + * @constructs + * @augments Gitana.AbstractPlatformDataStore + * + * @class Repository + * + * @param {Gitana.Platform} platform + * @param {Object} object json object (if no callback required for populating) + */ + constructor: function(platform, object) + { + this.base(platform, object); + + this.objectType = function() { return "Gitana.Repository"; }; + }, + + /** + * @OVERRIDE + */ + getType: function() + { + return Gitana.TypedIDConstants.TYPE_REPOSITORY; + }, + + /** + * @OVERRIDE + */ + getUri: function() + { + return "/repositories/" + this.getId(); + }, + + /** + * @override + */ + clone: function() + { + return this.getFactory().repository(this.getPlatform(), this); + }, + + + + ////////////////////////////////////////////////////////////////////////////////////////////////////////// + // + // BRANCHES + // + ////////////////////////////////////////////////////////////////////////////////////////////////////////// + + /** + * List the branches. + * + * @chained branch map + * + * @public + * + * @param {Object} pagination + */ + listBranches: function(pagination) + { + const params = {}; + if (pagination) + { + Gitana.copyInto(params, pagination); + } + + const uriFunction = function() + { + return "/repositories/" + this.getId() + "/branches"; + }; + + const chainable = this.getFactory().branchMap(this); + return this.chainGet(chainable, uriFunction, params); + }, + + /** + * Reads a branch. + * + * @chained branch + * + * @public + * + * @param {String} branchId the branch id + */ + readBranch: function(branchId) + { + const uriFunction = function() + { + return "/repositories/" + this.getId() + "/branches/" + branchId; + }; + + const chainable = this.getFactory().branch(this); + return this.chainGet(chainable, uriFunction); + }, + + /** + * Creates a branch. + * + * @chained branch + * + * @public + * + * @param {String} branchId identifies the branch from which the new branch will be forked. + * @param {String} changesetId identifies the changeset on the branch which serves as the root changeset that + * the new branch will be founded upon. + * @param {Object} object JSON object for the branch + */ + createBranch: function(branchId, changesetId, object) + { + const uriFunction = function() + { + return "/repositories/" + this.getId() + "/branches"; + }; + + const createParams = { + "branch": branchId, + "changeset": changesetId + }; + const chainable = this.getFactory().branch(this); + return this.chainCreate(chainable, object, uriFunction, createParams); + }, + + /** + * Starts the creation of a new branch. + * This runs a background job to do the actual indexing and branch creation. + * + * @chained release + * + * @param {String} branchId identifies the branch from which the new branch will be forked. + * @param {String} changesetId identifies the changeset on the branch which serves as the root changeset that + * the new branch will be founded upon. + * @param [Object] object JSON object for the branch + * @param callback + */ + startCreateBranch: function(branchId, changesetId, object, callback) + { + var self = this; + + if (typeof(object) === "function") { + callback = object; + object = null; + } + + if (typeof(changesetId) === "function") { + callback = changesetId; + changesetId = null; + object = null; + } + + var uriFunction = function() + { + return self.getUri() + "/branches/create/start"; + }; + + if (!object) + { + object = {}; + } + + var params = {}; + params.branch = branchId; + if (changesetId) + { + params.changeset = changesetId; + } + + return this.chainPostResponse(this, uriFunction, params, object).then(function(response) { + + var jobId = response._doc; + + callback(jobId); + }); + }, + + /** + * Creates a snapshot at a given changeset within the repository. + * + * @param changesetId + * @param object + */ + createSnapshot: function(changesetId, object) + { + const uriFunction = function() + { + return "/repositories/" + this.getId() + "/snapshots"; + }; + + const createParams = { + "changeset": changesetId + }; + const chainable = this.getFactory().branch(this); + return this.chainCreate(chainable, object, uriFunction, createParams); + }, + + + /** + * Queries for branches. + * + * Config should be: + * + * { + * Gitana query configs + * } + * + * @public + * + * @param {Object} query + * @param {Object} pagination + */ + queryBranches: function(query, pagination) + { + const params = {}; + if (pagination) + { + Gitana.copyInto(params, pagination); + } + + const uriFunction = function() + { + return "/repositories/" + this.getId() + "/branches/query"; + }; + + const chainable = this.getFactory().branchMap(this); + return this.chainPost(chainable, uriFunction, params, query); + }, + + /** + * Lists the branches that can be pulled into a given branch + * + * @param {String} branchId + * @param {Object} pagination + */ + listPullSources: function(branchId, pagination) + { + const params = {}; + if (pagination) + { + Gitana.copyInto(params, pagination); + } + + const uriFunction = function() + { + return "/repositories/" + this.getId() + "/branches/" + branchId + "/pull/sources"; + }; + + const chainable = this.getFactory().branchMap(this); + return this.chainGet(chainable, uriFunction, params); + }, + + /** + * Performs a bulk check of permissions against permissioned objects of type branch. + * + * Example of checks array: + * + * [{ + * "permissionedId": "", + * "principalId": "", + * "permissionId": "" + * }] + * + * The callback receives an array of results, example: + * + * [{ + * "permissionedId": "", + * "principalId": "", + * "permissionId": "", + * "result": true + * }] + * + * The order of elements in the array will be the same for checks and results. + * + * @param checks + * @param callback + */ + checkBranchPermissions: function(checks, callback) + { + const uriFunction = function() + { + return "/repositories/" + this.getId() + "/branches/permissions/check"; + }; + + const object = { + "checks": checks + }; + + return this.chainPostResponse(this, uriFunction, {}, object).then(function(response) { + callback.call(this, response["results"]); + }); + }, + + /** + * Performs a bulk check of authorities against permissioned objects of type branch. + * + * Example of checks array: + * + * [{ + * "permissionedId": "", + * "principalId": "", + * "authorityId": "" + * }] + * + * The callback receives an array of results, example: + * + * [{ + * "permissionedId": "", + * "principalId": "", + * "authorityId": "", + * "result": true + * }] + * + * The order of elements in the array will be the same for checks and results. + * + * @param checks + * @param callback + */ + checkBranchAuthorities: function(checks, callback) + { + const uriFunction = function() + { + return "/repositories/" + this.getId() + "/branches/authorities/check"; + }; + + const object = { + "checks": checks + }; + + return this.chainPostResponse(this, uriFunction, {}, object).then(function(response) { + callback.call(this, response["results"]); + }); + }, + + /** + * List the changesets in this repository. + * + * @chained + * + * @public + */ + listChangesets: function() + { + const uriFunction = function() + { + return "/repositories/" + this.getId() + "/changesets"; + }; + + const chainable = this.getFactory().changesetMap(this); + return this.chainGet(chainable, uriFunction); + }, + + /** + * Read a changeset. + * + * @chained + * + * @public + * + * @param {String} changesetId the id of the changeset + */ + readChangeset: function(changesetId) + { + const uriFunction = function() + { + return "/repositories/" + this.getId() + "/changesets/" + changesetId; + }; + + const chainable = this.getFactory().changeset(this); + return this.chainGet(chainable, uriFunction); + }, + + /** + * Acquires a list of the parent changesets for a given changeset. + * + * @chained + * + * @public + * + * @param {String} changesetId the id of the changeset + */ + listChangesetParents: function(changesetId) + { + const uriFunction = function() + { + return "/repositories/" + this.getId() + "/changesets/" + changesetId + "/parents"; + }; + + const chainable = this.getFactory().changesetMap(this); + return this.chainGet(chainable, uriFunction); + }, + + /** + * Acquires a list of the child changesets for a given changeset. + * + * @chained + * + * @public + * + * @param {String} changesetId the id of the changeset + */ + listChangesetChildren: function(changesetId) + { + const uriFunction = function() + { + return "/repositories/" + this.getId() + "/changesets/" + changesetId + "/children"; + }; + + const chainable = this.getFactory().changesetMap(this); + return this.chainGet(chainable, uriFunction); + }, + + /** + * Queries for changesets. + * + * Config should be: + * + * { + * Gitana query configs + * } + * + * @public + * + * @param {Object} query + * @param {Object} pagination + */ + queryChangesets: function(query, pagination) + { + const params = {}; + if (pagination) + { + Gitana.copyInto(params, pagination); + } + + const uriFunction = function() + { + return "/repositories/" + this.getId() + "/changesets/query"; + }; + + const chainable = this.getFactory().changesetMap(this); + return this.chainPost(chainable, uriFunction, params, query); + }, + + ////////////////////////////////////////////////////////////////////////////////////////////////////////// + // + // MERGE BRANCH + // + ////////////////////////////////////////////////////////////////////////////////////////////////////////// + + /** + * Merges a branch into a target branch. Runs as a background Job + * + * @public + * + * @param sourceBranchId + * @param targetBranchId + * @param callback + */ + startMerge: function(sourceBranchId, targetBranchId, callback) + { + const params = { + id: sourceBranchId + }; + + const uriFunction = function() + { + return "/repositories/" + this.getId() + "/branches/" + targetBranchId + "/merge/start"; + }; + + return this.chainPostResponse(this, uriFunction, params).then(function(response) { + + const jobId = response._doc; + + callback(jobId); + }); + }, + + /** + * Performs a diff between a source and target branch. Runs as a background Job + * + * @public + * + * @param sourceBranchId + * @param targetBranchId + * @param callback + */ + startDiff: function(sourceBranchId, targetBranchId, callback) + { + const params = { + id: sourceBranchId + }; + + const uriFunction = function() + { + return "/repositories/" + this.getId() + "/branches/" + targetBranchId + "/diff/start"; + }; + + return this.chainPostResponse(this, uriFunction, params).then(function(response) { + + const jobId = response._doc; + + callback(jobId); + }); + }, + + /** + * Finds the changes that will be applied from a source branch to a target branch. Runs as a background Job + * + * @public + * + * @param sourceBranchId + * @param targetBranchId + * @param options (request param options, pagination) + * @param callback + */ + startChanges: function(sourceBranchId, targetBranchId, options, callback) + { + if (typeof(options) === "function") { + callback = options; + options = null; + } + + const params = {}; + + if (typeof(options) === "string") + { + params.view = options; + } + else if (Gitana.isObject(options)) + { + for (const k in options) { + params[k] = options[k]; + } + } + + // source branch ID + params["id"] = sourceBranchId; + + const uriFunction = function() + { + return "/repositories/" + this.getId() + "/branches/" + targetBranchId + "/changes/start"; + }; + + return this.chainPostResponse(this, uriFunction, params).then(function(response) { + + const jobId = response._doc; + + callback(jobId); + }); + }, + + + /** + * Lists the branches with which this branch has merge conflicts. + * + * @public + * + * @param sourceBranchId + * @param mergeType Either "outgoing" or "incoming" + */ + listMerges: function(sourceBranchId, mergeType) + { + const params = {}; + if (mergeType) + { + params.mergeType = mergeType; + } + + const uriFunction = function() + { + return "/repositories/" + this.getId() + "/branches/" + sourceBranchId + "/merges"; + }; + + const chainable = this.getFactory().branchMap(this); + return this.chainGet(chainable, uriFunction, params); + }, + + /** + * Copies nodes from the source branch to the target branch + * + * @param {String} sourceBranchId + * @param {String} targetBranchId + * @param {Object} config + */ + copyFrom: function(sourceBranchId, targetBranchId, config) + { + const params = { + id: sourceBranchId + }; + + const uriFunction = function() + { + return "/repositories/" + this.getId() + "/branches/" + targetBranchId + "/copyfrom"; + }; + + return this.chainPost(this, uriFunction, params, config); + }, + + /** + * Copies nodes from the source branch to the target branch asynchronously. + * + * @param {String} sourceBranchId + * @param {String} targetBranchId + * @param {Object} config + * @param [Function] callback + */ + startCopyFrom: function(sourceBranchId, targetBranchId, config, callback) + { + var params = { + id: sourceBranchId + }; + + var uriFunction = function() + { + return "/repositories/" + this.getId() + "/branches/" + targetBranchId + "/copyfrom/start"; + }; + + return this.chainPostResponse(this, uriFunction, params, config).then(function(response) { + + var jobId = response._doc; + + callback(jobId); + }); + }, + + + ////////////////////////////////////////////////////////////////////////////////////////////////////////// + // + // RELEASES + // + ////////////////////////////////////////////////////////////////////////////////////////////////////////// + + /** + * List the releases. + * + * @chained release map + * + * @public + * + * @param {Object} pagination + */ + listReleases: function(pagination) + { + const params = {}; + if (pagination) + { + Gitana.copyInto(params, pagination); + } + + const uriFunction = function() + { + return "/repositories/" + this.getId() + "/releases"; + }; + + const chainable = this.getFactory().releaseMap(this); + return this.chainGet(chainable, uriFunction, params); + }, + + /** + * Reads a release. + * + * @chained release + * + * @public + * + * @param {String} releaseId the release id + */ + readRelease: function(releaseId) + { + const uriFunction = function() + { + return "/repositories/" + this.getId() + "/releases/" + releaseId; + }; + + const chainable = this.getFactory().release(this); + return this.chainGet(chainable, uriFunction); + }, + + /** + * Creates a release. + * + * @chained release + * + * @public + * + * @param {Object} object JSON object for the release + * @param {String} sourceId optional id of the source release that should be copied + */ + createRelease: function(object, sourceId) + { + const uriFunction = function() + { + return "/repositories/" + this.getId() + "/releases"; + }; + + const params = {}; + if (sourceId) + { + params.sourceId = sourceId; + } + + const chainable = this.getFactory().release(this); + return this.chainCreate(chainable, object, uriFunction, params); + }, + + /** + * Starts the creation of a new release. + * This runs a background job to do the actual indexing and release creation. + * + * @chained release + * + * @param {Object} object JSON object + * @param {String} sourceId optional id of the source release that should be copied + * @param callback + */ + startCreateRelease: function(object, sourceId, callback) + { + const self = this; + + if (typeof(object) === "function") { + callback = object; + sourceId = null; + object = null; + } + + if (typeof(sourceId) === "function") { + callback = sourceId; + sourceId = null; + } + + const uriFunction = function() + { + return self.getUri() + "/releases/create/start"; + }; + + if (!object) + { + object = {}; + } + + const params = {}; + if (sourceId) + { + params.sourceId = sourceId; + } + + return this.chainPostResponse(this, uriFunction, params, object).then(function(response) { + + const jobId = response._doc; + + callback(jobId); + }); + }, + + /** + * Queries for releases. + * + * Config should be: + * + * { + * Gitana query configs + * } + * + * @public + * + * @param {Object} query + * @param {Object} pagination + */ + queryReleases: function(query, pagination) + { + const params = {}; + if (pagination) + { + Gitana.copyInto(params, pagination); + } + + const uriFunction = function() + { + return "/repositories/" + this.getId() + "/releases/query"; + }; + + const chainable = this.getFactory().releaseMap(this); + return this.chainPost(chainable, uriFunction, params, query); + }, + + /** + * Performs a bulk check of permissions against permissioned objects of type release. + * + * Example of checks array: + * + * [{ + * "permissionedId": "", + * "principalId": "", + * "permissionId": "" + * }] + * + * The callback receives an array of results, example: + * + * [{ + * "permissionedId": "", + * "principalId": "", + * "permissionId": "", + * "result": true + * }] + * + * The order of elements in the array will be the same for checks and results. + * + * @param checks + * @param callback + */ + checkReleasePermissions: function(checks, callback) + { + const uriFunction = function() + { + return "/repositories/" + this.getId() + "/releases/permissions/check"; + }; + + const object = { + "checks": checks + }; + + return this.chainPostResponse(this, uriFunction, {}, object).then(function(response) { + callback.call(this, response["results"]); + }); + }, + + /** + * Performs a bulk check of authorities against permissioned objects of type release. + * + * Example of checks array: + * + * [{ + * "permissionedId": "", + * "principalId": "", + * "authorityId": "" + * }] + * + * The callback receives an array of results, example: + * + * [{ + * "permissionedId": "", + * "principalId": "", + * "authorityId": "", + * "result": true + * }] + * + * The order of elements in the array will be the same for checks and results. + * + * @param checks + * @param callback + */ + checkReleaseAuthorities: function(checks, callback) + { + const uriFunction = function() + { + return "/repositories/" + this.getId() + "/releases/authorities/check"; + }; + + const object = { + "checks": checks + }; + + return this.chainPostResponse(this, uriFunction, {}, object).then(function(response) { + callback.call(this, response["results"]); + }); + }, + + ////////////////////////////////////////////////////////////////////////////////////////////////////////// + // + // MERGE CONFLICTS + // + ////////////////////////////////////////////////////////////////////////////////////////////////////////// + + /** + * List the merge conflicts. + * + * @chained merge conflict map + * + * @public + * + * @param {Object} pagination + */ + listConflicts: function(pagination) + { + const params = {}; + if (pagination) + { + Gitana.copyInto(params, pagination); + } + + const uriFunction = function() + { + return "/repositories/" + this.getId() + "/conflicts"; + }; + + const chainable = this.getFactory().mergeConflictMap(this); + return this.chainGet(chainable, uriFunction, params); + }, + + /** + * Reads a merge conflict. + * + * @chained conflict + * + * @public + * + * @param {String} conflictId the merge conflict id + */ + readConflict: function(conflictId) + { + const uriFunction = function() + { + return "/repositories/" + this.getId() + "/conflicts/" + conflictId; + }; + + const chainable = this.getFactory().mergeConflict(this); + return this.chainGet(chainable, uriFunction); + }, + + /** + * Queries for merge conflicts. + * + * Config should be: + * + * { + * Gitana query configs + * } + * + * @public + * + * @param {Object} query + * @param {Object} pagination + */ + queryConflicts: function(query, pagination) + { + const params = {}; + if (pagination) + { + Gitana.copyInto(params, pagination); + } + + const uriFunction = function() + { + return "/repositories/" + this.getId() + "/conflicts/query"; + }; + + const chainable = this.getFactory().mergeConflictMap(this); + return this.chainPost(chainable, uriFunction, params, query); + }, + + /** + * Performs a bulk check of permissions against permissioned objects of type release. + * + * Example of checks array: + * + * [{ + * "permissionedId": "", + * "principalId": "", + * "permissionId": "" + * }] + * + * The callback receives an array of results, example: + * + * [{ + * "permissionedId": "", + * "principalId": "", + * "permissionId": "", + * "result": true + * }] + * + * The order of elements in the array will be the same for checks and results. + * + * @param checks + * @param callback + */ + checkConflictPermissions: function(checks, callback) + { + const uriFunction = function() + { + return "/repositories/" + this.getId() + "/conflicts/permissions/check"; + }; + + const object = { + "checks": checks + }; + + return this.chainPostResponse(this, uriFunction, {}, object).then(function(response) { + callback.call(this, response["results"]); + }); + }, + + /** + * Performs a bulk check of authorities against permissioned objects of type release. + * + * Example of checks array: + * + * [{ + * "permissionedId": "", + * "principalId": "", + * "authorityId": "" + * }] + * + * The callback receives an array of results, example: + * + * [{ + * "permissionedId": "", + * "principalId": "", + * "authorityId": "", + * "result": true + * }] + * + * The order of elements in the array will be the same for checks and results. + * + * @param checks + * @param callback + */ + checkConflictAuthorities: function(checks, callback) + { + const uriFunction = function() + { + return "/repositories/" + this.getId() + "/conflicts/authorities/check"; + }; + + const object = { + "checks": checks + }; + + return this.chainPostResponse(this, uriFunction, {}, object).then(function(response) { + callback.call(this, response["results"]); + }); + }, + + ////////////////////////////////////////////////////////////////////////////////////////// + // + // ACCESSORS + // + ////////////////////////////////////////////////////////////////////////////////////////// + + getMaxSize: function() + { + return this.get("maxSize"); + }, + + getSize: function() + { + return this.get("size"); + }, + + getObjectCount: function() + { + return this.get("objectcount"); + } + + }); + +})(window); +(function(window) +{ + Gitana = window.Gitana; + + Gitana.RepositoryMap = Gitana.AbstractPlatformObjectMap.extend( + /** @lends Gitana.RepositoryMap.prototype */ + { + /** + * @constructs + * @augments Gitana.AbstractPlatformObjectMap + * + * @class Map of repository objects + * + * @param {Gitana.Platform} platform Gitana platform instance. + * @param {Object} object + */ + constructor: function(platform, object) + { + this.objectType = function() { return "Gitana.RepositoryMap"; }; + + + ////////////////////////////////////////////////////////////////////////////////////////////// + // + // CALL THROUGH TO BASE CLASS (at the end) + // + ////////////////////////////////////////////////////////////////////////////////////////////// + + this.base(platform, object); + }, + + /** + * @override + */ + clone: function() + { + return this.getFactory().repositoryMap(this.getPlatform(), this); + }, + + /** + * @param json + */ + buildObject: function(json) + { + return this.getFactory().repository(this.getPlatform(), json); + } + + }); + +})(window); +(function(window) +{ + Gitana = window.Gitana; + + Gitana.AbstractRepositoryObject = Gitana.AbstractPlatformObject.extend( + /** @lends Gitana.AbstractRepositoryObject.prototype */ + { + /** + * @constructs + * @augments Gitana.AbstractPlatformObject + * + * @class Abstract base class for Gitana Node implementations. + * + * @param {Gitana.Branch} repository + * @param {Object} [object] + */ + constructor: function(repository, object) + { + this.base(repository.getPlatform(), object); + + + ////////////////////////////////////////////////////////////////////////////////////////////// + // + // PRIVILEGED METHODS + // + ////////////////////////////////////////////////////////////////////////////////////////////// + + /** + * Gets the Gitana Repository object. + * + * @inner + * + * @returns {Gitana.Repository} The Gitana Repository object + */ + this.getRepository = function() { return repository; }; + + /** + * Gets the Gitana Repository id. + * + * @inner + * + * @returns {String} The Gitana Repository id + */ + this.getRepositoryId = function() { return repository.getId(); }; + }, + + /** + * @OVERRIDE + */ + ref: function() + { + return this.getType() + "://" + this.getPlatformId() + "/" + this.getRepositoryId() + "/" + this.getId(); + } + + }); + +})(window); +(function(window) +{ + Gitana = window.Gitana; + + Gitana.AbstractNode = Gitana.AbstractRepositoryObject.extend( + /** @lends Gitana.AbstractNode.prototype */ + { + /** + * @constructs + * @augments Gitana.AbstractRepositoryObject + * + * @class Abstract base class for Gitana Node implementations. + * + * @param {Gitana.Branch} branch + * @param {Object} [object] + */ + constructor: function(branch, object) + { + // helper methods for system-managed state + + this.__qname = (function() { + let _qname = null; + return function(qname) { + if (!Gitana.isUndefined(qname)) { _qname = qname; } + return _qname; + }; + })(); + + this.__type = (function() { + let _type = null; + return function(type) { + if (!Gitana.isUndefined(type)) { _type = type; } + return _type; + }; + })(); + + this.__features = (function() { + let _features = {}; + return function(features) { + if (!Gitana.isUndefined(features)) { _features = features; } + return _features; + }; + })(); + + this.__stats = (function() { + let _stats = {}; + return function(stats) { + if (!Gitana.isUndefined(stats)) { _stats = stats; } + return _stats; + }; + })(); + + this.__is_association = (function() { + let _is_association = false; + return function(is_association) { + if (!Gitana.isUndefined(is_association)) { _is_association = is_association; } + return _is_association; + }; + })(); + + // now call base + // important this happens AFTER helpers above so that handleSystemProperties works + this.base(branch.getRepository(), object); + + + ////////////////////////////////////////////////////////////////////////////////////////////// + // + // PRIVILEGED METHODS + // + ////////////////////////////////////////////////////////////////////////////////////////////// + + /** + * Gets the Gitana Branch object. + * + * @inner + * + * @returns {Gitana.Branch} The Gitana Branch object + */ + this.getBranch = function() { return branch; }; + + /** + * Gets the Gitana Branch id. + * + * @inner + * + * @returns {String} The Gitana Branch id + */ + this.getBranchId = function() { return branch.getId(); }; + }, + + /** + * @override + */ + getUri: function() + { + return "/repositories/" + this.getRepositoryId() + "/branches/" + this.getBranchId() + "/nodes/" + this.getId(); + }, + + /** + * @override + */ + ref: function() + { + return "node://" + this.getPlatformId() + "/" + this.getRepositoryId() + "/" + this.getBranchId() + "/" + this.getId(); + }, + + /** + * @override + */ + clone: function() + { + return this.getFactory().node(this.getBranch(), this); + }, + + /** + * @override + */ + handleSystemProperties: function(response) + { + this.base(response); + + // strip out "_qname" + if (this["_qname"]) + { + const _qname = this["_qname"]; + delete this["_qname"]; + this.__qname(_qname); + } + + // strip out "_type" + if (this["_type"]) + { + const _type = this["_type"]; + delete this["_type"]; + this.__type(_type); + } + + // strip out "_features" + if (this["_features"]) + { + const _features = this["_features"]; + delete this["_features"]; + this.__features(_features); + } + + // strip out "_statistics" + if (this["_statistics"] && typeof(this["_statistics"]) === "object") + { + const stats = this["_statistics"]; + delete this["_statistics"]; + this.__stats(stats); + } + + // strip out "_is_association" + if (!Gitana.isUndefined(this["_is_association"])) + { + const _is_association = this["_is_association"]; + delete this["_is_association"]; + this.__is_association(_is_association); + } + }, + + /** + * Override to include: + * + * __qname + * __type + * __features + * __stats + * __is_association + * + * @param otherObject + */ + chainCopyState: function(otherObject) + { + this.base(otherObject); + + if (otherObject.__qname) { + this.__qname(otherObject.__qname()); + } + if (otherObject.__type) { + this.__type(otherObject.__type()); + } + if (otherObject.__features) { + this.__features(otherObject.__features()); + } + if (otherObject.__stats) { + this.__stats(otherObject.__stats()); + } + if (otherObject.__is_association) { + this.__is_association(otherObject.__is_association()); + } + }, + + /** + * Hands back the stats. + */ + stats: function() + { + return this.__stats(); + }, + + + /////////////////////////////////////////////////////////////////////////////////////////////////////////// + // + // FEATURES + // + /////////////////////////////////////////////////////////////////////////////////////////////////////////// + + /** + * Hands back a list of the feature ids that this node has. + * + * @public + * + * @param {Function} callback optional callback + * + * @returns {Array} An array of strings that are the ids of the features. + */ + getFeatureIds: function(callback) + { + const self = this; + + const f = function() + { + const featureIds = []; + for (const featureId in this.__features()) { + featureIds[featureIds.length] = featureId; + } + + return featureIds; + }; + + if (callback) + { + + return this.then(function() { + callback.call(this, f.call(self)); + }); + } + + return f.call(self); + }, + + /** + * Gets the configuration for a given feature. + * + * @public + * + * @param {String} featureId the id of the feature + * @param {Function} callback optional callback + * + * @returns {Object} the JSON object configuration for the feature + */ + getFeature: function(featureId, callback) + { + const self = this; + + if (callback) + { + return this.then(function() { + callback.call(this, self.__features()[featureId]); + }); + } + + return self.__features()[featureId]; + }, + + /** + * Removes a feature from this node. + * + * @public + * + * @param {String} featureId the id of the feature + */ + removeFeature: function(featureId) + { + const self = this; + + const uriFunction = function() + { + return self.getUri() + "/features/" + featureId; + }; + + return this.chainDelete(this, uriFunction).reload().then(function() { + self.loadFrom(this); + }); + }, + + /** + * Adds a feature to this node. + * + * @public + * @param {String} featureId the id of the feature + * @param {Object} featureConfig the JSON object configuration for the feature + */ + addFeature: function(featureId, featureConfig) + { + const self = this; + + const uriFunction = function() + { + return self.getUri() + "/features/" + featureId; + }; + + if (!featureConfig) { + featureConfig = {}; + } + + return this.chainPostEmpty(null, uriFunction, {}, featureConfig).reload().then(function() { + self.loadFrom(this); + }); + }, + + /** + * Indicates whether this node has the given feature. + * + * @public + * + * @param {String} featureId the id of the feature + * @param {Function} callback optional callback to receive result (for chaining) + * + * @returns {Boolean} whether this node has this feature + */ + hasFeature: function(featureId, callback = undefined) + { + if (callback) + { + return this.then(function() { + + const hasFeature = !Gitana.isEmpty(this.__features()[featureId]); + + callback.call(this, hasFeature); + }); + } + + return !Gitana.isEmpty(this.__features()[featureId]); + }, + + /** + * Indicates whether the current object is an association. + * + * @public + * + * @returns {Boolean} whether this node is an association + */ + isAssociation: function() + { + return this.__is_association(); + }, + + /** + * Indicates whether this node has the "f:container" feature + * + * @public + * + * @returns {Boolean} whether this node has the "f:container" feature + */ + isContainer: function() + { + return this.hasFeature("f:container"); + }, + + /** + * Touches the node. + * + * @public + * + * @chained node (this) + */ + touch: function() + { + const self = this; + + const uriFunction = function() + { + return self.getUri() + "/touch"; + }; + + return this.chainPost(null, uriFunction); + }, + + /** + * Refreshes the node. This allows the node to reindex and regenerate any renditions it may + * have associated with it. + * + * @public + * + * @chained node (this) + */ + refresh: function() + { + var self = this; + + var uriFunction = function() + { + return self.getUri() + "/refresh"; + }; + + return this.chainPost(null, uriFunction); + }, + + ////////////////////////////////////////////////////////////////////////////////////////// + // + // TYPE + // + ////////////////////////////////////////////////////////////////////////////////////////// + + /** + * Gets the type QName for this node. + * + * @public + * + * @returns {String} the type qname of this node. + */ + getTypeQName: function() + { + return this.__type(); + }, + + /** + * Changes the type QName for this node. + * + * @public + * @param {String} typeQName the qname of the type to change to + */ + changeTypeQName: function(typeQName) + { + const self = this; + + const uriFunction = function() + { + return self.getUri() + "/change_type?type=" + typeQName; + }; + + return this.chainPostEmpty(null, uriFunction).reload().then(function() { + self.loadFrom(this); + }); + }, + + + + + ////////////////////////////////////////////////////////////////////////////////////////// + // + // QNAME + // + ////////////////////////////////////////////////////////////////////////////////////////// + + /** + * Gets the QName for this node. + * + * @public + * + * @returns {String} the qname of this node. + */ + getQName: function() + { + return this.__qname(); + }, + + /** + * Sets the QName of this node. + * + * @public + * @param {String} qname the qname of the type to change to + */ + changeQName: function(qname) + { + const self = this; + + const uriFunction = function() + { + return self.getUri() + "/change_qname?qname=" + qname; + }; + + return this.chainPostEmpty(null, uriFunction).reload().then(function() { + self.loadFrom(this); + }); + }, + + + ////////////////////////////////////////////////////////////////////////////////////////// + // + // ATTACHMENTS + // + ////////////////////////////////////////////////////////////////////////////////////////// + + /** + * Lists the attachments of this node. + * + * If local is set to true, the attachments are drawn from precached values on the node. + * + * @chained attachment map + * + * @param local + * + * @public + */ + listAttachments: Gitana.Methods.listAttachments(Gitana.NodeAttachmentMap), + + /** + * Picks off a single attachment + * + * @chained attachment + * + * @param attachmentId (null for default) + */ + attachment: function(attachmentId) + { + return this.listAttachments().select(attachmentId); + }, + + /** + * Non-chained method for getting a download URI for this node's attachment. + */ + attachmentDownloadUri: function(attachmentId) + { + return this.getDriver().baseURL + this.getUri() + "/attachments/" + attachmentId; + }, + + /** + * Creates an attachment. + * + * When using this method from within the JS driver, it really only works for text-based content such + * as JSON or text. + * + * @chained attachment + * + * @param attachmentId (use null or false for default attachment) + * @param contentType + * @param data + * @param filename + */ + attach: function(attachmentId, contentType, data, filename) + { + const paramsFunction = function(params) { + if (filename) { params["filename"] = filename; } + }; + + const delegate = Gitana.Methods.attach.call(this, Gitana.NodeAttachment, paramsFunction); + return delegate.call(this, attachmentId, contentType, data); + }, + + /** + * Generates a URI to a preview resource. + */ + getPreviewUri: Gitana.Methods.getPreviewUri(), + + + /** + * Deletes an attachment. + * + * @param attachmentId + */ + unattach: Gitana.Methods.unattach() + + }); + +})(window); +(function(window) +{ + Gitana = window.Gitana; + + /** + * Node attachments are similar to binary attachments. They're identical in structure except that they + * additionally provide information about the original filename. + */ + Gitana.NodeAttachment = Gitana.BinaryAttachment.extend( + /** @lends Gitana.NodeAttachment.prototype */ + { + /** + * @constructs + * @augments Gitana.BinaryAttachment + * + * @class Binary Attachment + * + * @param {Object} persistable gitana object + * @param {Object} attachment + */ + constructor: function(persistable, attachment) + { + this.base(persistable, attachment); + }, + + /** + * Gets attachment file name + * @returns {String} attachment file name + */ + getFilename: function() + { + return this.filename; + } + + }); + +})(window); +(function(window) +{ + Gitana = window.Gitana; + + Gitana.NodeAttachmentMap = Gitana.BinaryAttachmentMap.extend( + /** @lends Gitana.NodeAttachmentMap.prototype */ + { + /** + * @constructs + * @augments Gitana.BinaryAttachmentMap + * + * @class Provides access to node attachments + * + * @param persistable + * @param object + */ + constructor: function(persistable, object) + { + this.base(persistable, object); + + this.objectType = function() { return "Gitana.NodeAttachmentMap"; }; + }, + + /** + * @override + */ + clone: function() + { + return new Gitana.NodeAttachmentMap(this.__persistable(), this); + }, + + /** + * @param attachment + */ + buildObject: function(attachment) + { + return new Gitana.NodeAttachment(this.__persistable(), attachment); + } + + + }); + +})(window); +(function(window) +{ + Gitana = window.Gitana; + + Gitana.Association = Gitana.AbstractNode.extend( + /** @lends Gitana.Association.prototype */ + { + /** + * @constructs + * @augments Gitana.AbstractNode + * + * @class Association + * + * @param {Gitana.Branch} branch + * @param {Object} object json object (if no callback required for populating) + */ + constructor: function(branch, object) + { + this.base(branch, object); + + this.objectType = function() { return "Gitana.Association"; }; + }, + + /** + * @OVERRIDE + */ + getType: function() + { + return Gitana.TypedIDConstants.TYPE_ASSOCIATION; + }, + + /** + * @override + */ + isAssociation: function() + { + return true; + }, + + /** + * @returns {String} the directionality of the association + */ + getDirectionality: function() + { + return this.get("directionality"); + }, + + /** + * Gets the source node id for this association. + * + * @public + * + * @returns {String} source node id + */ + getSourceNodeId: function() + { + return this.get("source"); + }, + + /** + * Gets the source node changeset id for this association. + * + * @public + * + * @returns {String} source node changeset id + */ + getSourceNodeChangesetId: function() + { + return this.get("source_changeset"); + }, + + /** + * Gets the source node type for this association. + * + * @public + * + * @returns {String} source node type qname + */ + getSourceNodeType: function() + { + return this.get("source_type"); + }, + + /** + * Gets the target node id for this association. + * + * @public + * + * @returns {String} target node id + */ + getTargetNodeId: function() + { + return this.get("target"); + }, + + /** + * Gets the target node changeset id for this association. + * + * @public + * + * @returns {String} target node changeset id + */ + getTargetNodeChangesetId: function() + { + return this.get("target_changeset"); + }, + + /** + * Gets the target node type for this association. + * + * @public + * + * @returns {String} target node type qname + */ + getTargetNodeType: function() + { + return this.get("target_type"); + }, + + /** + * Reads the source node. + * + * @chained source node + * + * @public + */ + readSourceNode: function() + { + const self = this; + + const result = this.subchain(this.getFactory().node(this.getBranch())); + return result.then(function() { + + const chain = this; + + this.subchain(self.getBranch()).readNode(self.getSourceNodeId()).then(function() { + chain.loadFrom(this); + }); + }); + }, + + /** + * Reads the target node. + * + * @chained target node + * + * @public + */ + readTargetNode: function() + { + const self = this; + + const result = this.subchain(this.getFactory().node(this.getBranch())); + return result.then(function() { + + const chain = this; + + this.subchain(self.getBranch()).readNode(self.getTargetNodeId()).then(function() { + chain.loadFrom(this); + }); + }); + }, + + /** + * Given a node, reads back the other node of the association. + * + * @param {Object} node either a Gitana.Node or a string with the node id + * + * @chained other node + * + * @param node + */ + readOtherNode: function(node) + { + const self = this; + + let nodeId = null; + + if (Gitana.isString(node)) + { + nodeId = node; + } + else + { + nodeId = node.getId(); + } + + const result = this.subchain(this.getFactory().node(this.getBranch())); + result.then(function() { + + const chain = this; + + this.subchain(self).then(function() { + + if (nodeId === this.getSourceNodeId()) + { + this.readTargetNode().then(function() { + chain.loadFrom(this); + }); + } + else if (nodeId === this.getTargetNodeId()) + { + this.readSourceNode().then(function() { + chain.loadFrom(this); + }); + } + else + { + const err = new Gitana.Error(); + err.name = "No node on association"; + err.message = "The node: " + nodeId + " was not found on this association"; + + this.error(err); + + return false; + } + }); + }); + + return result; + }, + + /** + * NOTE: this is not a chained function + * + * Given a node, determines what direction this association describes. + * + * If the association's directionality is UNDIRECTED, the direction is MUTUAL. + * + * If the association's directionality is DIRECTED... + * If the node is the source, the direction is OUTGOING. + * If the node is the target, the direction is INCOMING. + * + * @param {Object} node either a Gitana.Node or a string with the node id + * + * @returns {String} the direction or null if the node isn't on the association + */ + getDirection: function(node) + { + let nodeId = null; + + if (Gitana.isString(node)) + { + nodeId = node; + } + else + { + nodeId = node.getId(); + } + + let direction = null; + + if (this.getDirectionality() === "UNDIRECTED") + { + direction = "MUTUAL"; + } + else + { + if (this.getSourceNodeId() === nodeId) + { + direction = "OUTGOING"; + } + else if (this.getTargetNodeId() === nodeId) + { + direction = "INCOMING"; + } + } + + return direction; + }, + + /** + * NOTE: this is not a chained function. + * + * Determines the node id of the other node. + * + * @param {Object} node either a Gitana.Node or a string with the node id + * + * @returns {String} the id of the other node + */ + getOtherNodeId: function(node) + { + let nodeId = null; + + if (Gitana.isString(node)) + { + nodeId = node; + } + else + { + nodeId = node.getId(); + } + + let otherNodeId = null; + + if (this.getSourceNodeId() === nodeId) + { + otherNodeId = this.getTargetNodeId(); + } + else if (this.getTargetNodeId() === nodeId) + { + otherNodeId = this.getSourceNodeId(); + } + + return otherNodeId; + } + + }); + +})(window); +(function (window) { + Gitana = window.Gitana; + + Gitana.Branch = Gitana.AbstractRepositoryObject.extend( + /** @lends Gitana.Branch.prototype */ + { + /** + * @constructs + * @augments Gitana.AbstractRepositoryObject + * + * @class Branch + * + * @param {Gitana.Repository} repository + * @param {Object} object json object (if no callback required for populating) + */ + constructor: function (repository, object) { + this.base(repository, object); + + this.objectType = function () { + return 'Gitana.Branch'; + }; + }, + + /** + * @OVERRIDE + */ + getType: function () { + return Gitana.TypedIDConstants.TYPE_BRANCH; + }, + + /** + * @OVERRIDE + */ + getUri: function () { + return '/repositories/' + this.getRepositoryId() + '/branches/' + this.getId(); + }, + + /** + * @override + */ + clone: function () { + return this.getFactory().branch(this.getRepository(), this); + }, + + /** + * @returns {Boolean} whether this is the master branch + */ + isMaster: function () { + return (this.getBranchType().toLowerCase() === 'master'); + }, + + /** + * @return {String} the type of branch ("master" or "custom") + */ + getBranchType: function () { + return this.get('type'); + }, + + /** + * @return {String} the tip changeset of the branch + */ + getTip: function () { + return this.get('tip'); + }, + + /** + * Acquires a list of mount nodes under the root of the repository. + * + * @chained node map + * + * @public + * + * @param {Object} pagination + */ + listMounts: function (pagination) { + const self = this; + + const params = {}; + if (pagination) { + Gitana.copyInto(params, pagination); + } + + const uriFunction = function () { + return self.getUri() + '/nodes'; + }; + + const chainable = this.getFactory().nodeMap(this); + return this.chainGet(chainable, uriFunction, params); + }, + + /** + * Reads a node. + * + * @chained node + * + * @public + * + * @param {String} nodeId the node id + * @param {String} path offset + * @param {Object} params + */ + readNode: function (nodeId, path = undefined, params = {}) { + const self = this; + + const uriFunction = function () { + return self.getUri() + '/nodes/' + nodeId; + }; + + if (path) { + params.path = path; + } + + const chainable = this.getFactory().node(this); + return this.chainGet(chainable, uriFunction, params); + }, + + /** + * Reads the root node. + * + * @chained node + * + * @public + */ + rootNode: function () { + return this.readNode('root'); + }, + + /** + * Create a node + * + * @chained node + * + * @public + * + * @param {Object} object JSON object + * @param {Object|String} options a JSON object providing the configuration for the create operation. + * If a string, must follow format (/) + */ + createNode: function (object, options = undefined) { + const self = this; + + const uriFunction = function () { + return self.getUri() + '/nodes'; + }; + + const params = {}; + + if (options) { + let rootNodeId = 'root'; // default + let associationType = 'a:child'; // default + let filePath = null; + let parentFolderPath = null; + let fileName = null; + + // if they pass in a string instead of an options object, then the string can follow the format + // (/root/pages/file.txt) where root is the root node to start from + if (typeof (options) === 'string') { + let rootPrefixedFilePath = options; + + // filePath should not start with "/" + if (Gitana.startsWith(rootPrefixedFilePath, '/')) { + rootPrefixedFilePath = rootPrefixedFilePath.substring(1); + } + + if (rootPrefixedFilePath === '') { + filePath = '/'; + } else { + const i = rootPrefixedFilePath.indexOf('/'); + rootNodeId = rootPrefixedFilePath.substring(0, i); + filePath = rootPrefixedFilePath.substring(i + 1); + } + } else if (typeof (options) === 'object') { + if (options.rootNodeId) { + rootNodeId = options.rootNodeId; + } + if (options.associationType) { + associationType = options.associationType; + } + if (options.fileName) { + fileName = options.fileName; + } else if (options.filename) { + fileName = options.filename; + } + if (options.parentFolderPath) { + parentFolderPath = options.parentFolderPath; + } else if (options.folderPath) { + parentFolderPath = options.folderPath; + } else if (options.folderpath) { + parentFolderPath = options.folderpath; + } + if (options.filePath) { + filePath = options.filePath; + } else if (options.filepath) { + filePath = options.filepath; + } + } + + // plug in the resolved params + if (rootNodeId) { + params.rootNodeId = rootNodeId; + } + if (associationType) { + params.associationType = associationType; + } + if (fileName) { + params.fileName = fileName; + } + if (filePath) { + params.filePath = filePath; + } + if (parentFolderPath) { + params.parentFolderPath = parentFolderPath; + } + + // allow custom params to be passed through + if (options.params) { + for (const param in options.params) { + params[param] = options.params[param]; + } + } + } + + const chainable = this.getFactory().node(this); + return this.chainCreate(chainable, object, uriFunction, params); + }, + + /** + * Searches the branch. + * + * @chained node map + * + * Config should be: + * + * { + * "search": { + * ... Elastic Search Config Block + * } + * } + * + * For a full text term search, you can simply provide text in place of a config json object. + * + * See the Elastic Search documentation for more advanced examples + * + * @public + * + * @param search + * @param {Object} pagination + */ + searchNodes: function (search, pagination) { + const self = this; + + const params = {}; + if (pagination) { + Gitana.copyInto(params, pagination); + } + + if (Gitana.isString(search)) { + search = { + 'search': search + }; + } + + const uriFunction = function () { + return self.getUri() + '/nodes/search'; + }; + + const chainable = this.getFactory().nodeMap(this); + return this.chainPost(chainable, uriFunction, params, search); + }, + + /** + * Queries for nodes on the branch. + * + * Config should be: + * + * { + * Gitana query configs + * } + * + * @chained node map + * + * @public + * + * @param {Object} query + * @param {Object} pagination + */ + queryNodes: function (query, pagination = undefined) { + const self = this; + + if (!query) { + query = {}; + } + + const params = {}; + if (pagination) { + Gitana.copyInto(params, pagination); + } + + const uriFunction = function () { + return self.getUri() + '/nodes/query'; + }; + + const chainable = this.getFactory().nodeMap(this); + + if (!Gitana.PREFER_GET_OVER_POST) { + return this.chainPost(chainable, uriFunction, params, query); + } else { + Gitana.copyInto(params, { + 'query': JSON.stringify(query) + }); + + return this.chainGet(chainable, uriFunction, params); + } + + + }, + + /** + * Queries for a single matching node to a query on the branch. + * + * @chained node + * + * @param query + * @param errHandler + * + * @returns Gitana.Node + */ + queryOne: function (query, errHandler) { + return this.queryNodes(query).keepOne(function (err) { + if (errHandler) { + errHandler(err); + return false; + } + }); + }, + + /** + * Process a GraphQL query to the branch. + * + * @param query + * @param operationName + * @param constiables + * @param callback function(result) + * + * @returns result + */ + graphqlQuery: function (query, operationName, constiables, callback) { + const self = this; + + const params = { + query: query + }; + + if (constiables) { + params.constiables = constiables; + } + + if (operationName) { + params.operationName = operationName; + } + + const uriFunction = function () { + return self.getUri() + '/graphql'; + }; + + if (!Gitana.PREFER_GET_OVER_POST) { + return self.chainPostResponse(self, uriFunction, {}, params).then(function (response) { + callback(response); + }); + } else { + return self.chainGetResponse(self, uriFunction, params).then(function (response) { + callback(response); + }); + } + }, + + /** + * Fetch the GraphQL schema for the branch. + * + * @param callback function(schema) + * + * @returns String + */ + graphqlSchema: function (callback) { + const self = this; + + const uriFunction = function () { + return self.getUri() + '/graphql/schema'; + }; + + return self.chainGetResponseText(self, uriFunction, {}).then(function (response) { + callback(response); + }); + }, + + /** + * Deletes the nodes described the given array of node ids. + * + * @hcained branch + * + * @param nodeIds + * + * @returns Gitana.Branch + */ + deleteNodes: function (nodeIds) { + const self = this; + + const uriFunction = function () { + return self.getUri() + '/nodes/delete'; + }; + + return this.chainPost(this, uriFunction, {}, { + '_docs': nodeIds + }); + }, + + /** + * Performs a bulk check of permissions against permissioned objects of type node. + * + * Example of checks array: + * + * [{ + * "permissionedId": "", + * "principalId": "", + * "permissionId": "" + * }] + * + * The callback receives an array of results, example: + * + * [{ + * "permissionedId": "", + * "principalId": "", + * "permissionId": "", + * "result": true + * }] + * + * The order of elements in the array will be the same for checks and results. + * + * @param checks + * @param callback + */ + checkNodePermissions: function (checks, callback) { + const self = this; + + const uriFunction = function () { + return self.getUri() + '/nodes/permissions/check'; + }; + + const object = { + 'checks': checks + }; + + return this.chainPostResponse(this, uriFunction, {}, object).then(function (response) { + callback.call(this, response['results']); + }); + }, + + /** + * Performs a bulk check of authorities against permissioned objects of type node. + * + * Example of checks array: + * + * [{ + * "permissionedId": "", + * "principalId": "", + * "authorityId": "" + * }] + * + * The callback receives an array of results, example: + * + * [{ + * "permissionedId": "", + * "principalId": "", + * "authorityId": "", + * "result": true + * }] + * + * The order of elements in the array will be the same for checks and results. + * + * @param checks + * @param callback + */ + checkNodeAuthorities: function (checks, callback) { + const self = this; + + const uriFunction = function () { + return self.getUri() + '/nodes/authorities/check'; + }; + + const object = { + 'checks': checks + }; + + return this.chainPostResponse(this, uriFunction, {}, object).then(function (response) { + callback.call(this, response['results']); + }); + }, + + + /** + * Reads the person object for a security user. + * + * @chained node + * + * @param {Object} user either the user id, user name or the user object + * @param {Boolean} createIfNotFound whether to create the person object if it isn't found + */ + readPersonNode: function (user, createIfNotFound) { + const self = this; + + const principalDomainQualifiedId = this.extractPrincipalDomainQualifiedId(user); + + const uriFunction = function () { + let uri = self.getUri() + '/person/acquire?id=' + principalDomainQualifiedId; + if (createIfNotFound) { + uri += '&createIfNotFound=' + createIfNotFound; + } + + return uri; + }; + + const chainable = this.getFactory().node(this, 'n:person'); + return this.chainGet(chainable, uriFunction); + }, + + /** + * Reads the group object for a security group. + * + * @chained node + * + * @param {Object} group eitehr the group id, group name or the group object + * @param {Boolean} createIfNotFound whether to create the group object if it isn't found + */ + readGroupNode: function (group, createIfNotFound) { + const self = this; + + const principalDomainQualifiedId = this.extractPrincipalDomainQualifiedId(group); + + const uriFunction = function () { + let uri = self.getUri() + '/group/acquire?id=' + principalDomainQualifiedId; + if (createIfNotFound) { + uri += '&createIfNotFound=' + createIfNotFound; + } + + return uri; + }; + + const chainable = this.getFactory().node(this, 'n:group'); + return this.chainGet(chainable, uriFunction); + }, + + /** + * Acquire a list of definitions. + * + * @chained node map + * + * @public + * + * @param {String} filter Optional filter of the kind of definition to fetch - "association", "type" or "feature" + * @param {Object} pagination Optional pagination + */ + listDefinitions: function (filter, pagination) { + if (filter && typeof (filter) === 'object') { + pagination = filter; + filter = null; + } + + const self = this; + + const params = {}; + params['capabilities'] = 'true'; + if (filter) { + params['filter'] = filter; + } + if (pagination) { + Gitana.copyInto(params, pagination); + } + + const uriFunction = function () { + return self.getUri() + '/definitions'; + }; + + const chainable = this.getFactory().nodeMap(this); + return this.chainGet(chainable, uriFunction, params); + }, + + /** + * Query and search a list of definitions + * + * @param {*} json contains a search object and a query object + * @param {*} pagination + */ + queryDefinitions: function (json, pagination) { + const self = this; + + const params = {}; + if (pagination) { + Gitana.copyInto(params, pagination); + } + + const uriFunction = function () { + return self.getUri() + '/definitions/query'; + }; + + const chainable = this.getFactory().nodeMap(this); + return this.chainPost(chainable, uriFunction, params, json); + }, + + /** + * Reads a definition by qname. + * + * @chained definition + * + * @public + * + * @param {String} qname the qname + */ + readDefinition: function (qname) { + const self = this; + + const uriFunction = function () { + return self.getUri() + '/definitions/' + qname; + }; + + const chainable = this.getFactory().definition(this); + return this.chainGet(chainable, uriFunction); + }, + + /** + * Loads a list of schemas for an optional given type. + * + * @chained this + * + * @public + * + * @param {String} filter Optional filter of the kind of definition to fetch - "association", "type" or "feature" + * @param {Function} callback + */ + loadSchemas: function (filter, callback) { + if (typeof (filter) === 'function') { + callback = filter; + filter = null; + } + + const self = this; + + return this.then(function () { + + const chain = this; + + // call + let uri = self.getUri() + '/schemas'; + if (filter) { + uri += '?filter=' + filter; + } + self.getDriver().gitanaGet(uri, null, {}, function (response) { + + callback.call(chain, response); + + chain.next(); + }); + + // NOTE: we return false to tell the chain that we'll manually call next() + return false; + }); + }, + + + /** + * Reads a schema by qname. + * + * @chained this + * + * @public + * + * @param {String} qname the qname + * @param callback + */ + loadSchema: function (qname, callback) { + const self = this; + + return this.then(function () { + + const chain = this; + + // call + const uri = self.getUri() + '/schemas/' + qname; + self.getDriver().gitanaGet(uri, null, {}, function (response) { + callback.call(chain, response); + chain.next(); + }); + + // NOTE: we return false to tell the chain that we'll manually call next() + return false; + }); + }, + + /** + * Determines an available QName on this branch given some input. + * This makes a call to the repository and asks it to provide a valid QName. + * + * The valid QName is passed as an argument to the next method in the chain. + * + * Note: This QName is a recommended QName that is valid at the time of the call. + * + * If another thread writes a node with the same QName after this call but ahead of this thread + * attempting to commit, an invalid qname exception may still be thrown back. + * + * @chained this + * + * @public + * + * @param {Object} object an object with "title" or "description" fields to base generation upon + * @param callback + */ + generateQName: function (object, callback) { + const self = this; + + return this.then(function () { + + const chain = this; + + // call + const uri = self.getUri() + '/qnames/generate'; + self.getDriver().gitanaPost(uri, null, object, function (response) { + + const qname = response['_qname']; + + callback.call(chain, qname); + + chain.next(); + }); + + // NOTE: we return false to tell the chain that we'll manually call next() + return false; + }); + }, + + /** + * Creates an association between the source node and the target node of the given type. + * + * @chained branch (this) + * + * @param sourceNode + * @param targetNode + * @param object (or string identifying type) + */ + associate: function (sourceNode, targetNode, object) { + // source + let sourceNodeId = null; + if (Gitana.isString(sourceNode)) { + sourceNodeId = sourceNode; + } else { + sourceNodeId = sourceNode.getId(); + } + + // target + let targetNodeId = null; + if (Gitana.isString(targetNode)) { + targetNodeId = targetNode; + } else { + targetNodeId = targetNode.getId(); + } + + // make sure we hand back the branch + const result = this.subchain(this); + + // run a subchain to do the association + result.subchain(this).then(function () { + this.readNode(sourceNodeId).associate(targetNodeId, object); + }); + + return result; + }, + + /** + * Traverses around the given node. + * + * Note: This is a helper function provided for convenience that delegates off to the node to do the work. + * + * @chained traversal results + * + * @param node or node id + * @param config + */ + traverse: function (node, config) { + let nodeId = null; + if (Gitana.isString(node)) { + nodeId = node; + } else { + nodeId = node.getId(); + } + + return this.readNode(nodeId).traverse(config); + }, + + ////////////////////////////////////////////////////////////////////////////////////////// + // + // CONTAINER (a:child) CONVENIENCE FUNCTIONS + // + ////////////////////////////////////////////////////////////////////////////////////////// + + /** + * Creates a container node. + * + * This is a convenience function that simply applies the container feature to the object + * ahead of calling createNode. + * + * @chained node + * + * @public + * + * @param {Object} object JSON object + */ + createContainer: function (object) { + if (!object) { + object = {}; + } + + if (!object['_features']) { + object['_features'] = {}; + } + + object['_features']['f:container'] = { + 'active': 'true' + }; + + return this.createNode(object); + }, + + + ////////////////////////////////////////////////////////////////////////////////////////// + // + // FIND + // + ////////////////////////////////////////////////////////////////////////////////////////// + + /** + * Finds nodes within a branch + * + * @chained node map + * + * Config should be: + * + * { + * "query": { + * ... Query Block + * }, + * "search": { + * ... Elastic Search Config Block + * } + * } + * + * Alternatively, the value for "search" in the JSON block above can simply be text. + * + * @public + * + * @param {Object} config search configuration + * @param {Object} pagination + */ + find: function (config, pagination) { + const self = this; + + const params = {}; + if (pagination) { + Gitana.copyInto(params, pagination); + } + + const uriFunction = function () { + return self.getUri() + '/nodes/find'; + }; + + const chainable = this.getFactory().nodeMap(this); + return this.chainPost(chainable, uriFunction, params, config); + }, + + /** + * Another way to access the find() method that is more consistent with the API + * that would be expected. + * + * @param config + * @param pagination + * @return {*} + */ + findNodes: function (config, pagination) { + return this.find(config, pagination); + }, + + + /////////////////////////////////////////////////////////////////////////////////////////////////////// + // + // NODE LIST + // + /////////////////////////////////////////////////////////////////////////////////////////////////////// + + + /** + * List the items in a node list. + * + * @chained node map + * + * @public + * + * @param {String} listKey + * @param {Object} pagination + */ + listItems: function (listKey, pagination) { + const self = this; + + const params = {}; + if (pagination) { + Gitana.copyInto(params, pagination); + } + + const uriFunction = function () { + return self.getUri() + '/lists/' + listKey + '/items'; + }; + + const chainable = this.getFactory().nodeMap(this); + return this.chainGet(chainable, uriFunction, pagination); + }, + + /** + * Queries for items in a node list. + * + * @chained node map + * + * @public + * + * @param {String} listKey + * @param {Object} query + * @param {Object} pagination + */ + queryItems: function (listKey, query, pagination) { + const self = this; + + const params = {}; + if (pagination) { + Gitana.copyInto(params, pagination); + } + + const uriFunction = function () { + return self.getUri() + '/lists/' + listKey + '/items/query'; + }; + + const chainable = this.getFactory().nodeMap(this); + return this.chainPost(chainable, uriFunction, params, query); + }, + + + /////////////////////////////////////////////////////////////////////////////////////////////////////// + // + // UTILITIES + // + /////////////////////////////////////////////////////////////////////////////////////////////////////// + + /** + * Loads all of the definitions, forms and key mappings on this branch. + * + * @param filter + * @param callback + */ + loadForms: function (filter, callback) { + const self = this; + + return this.then(function () { + + const chain = this; + + // call + let uri = self.getUri() + '/forms'; + if (filter) { + uri += '?filter=' + filter; + } + self.getDriver().gitanaGet(uri, null, {}, function (response) { + + callback.call(chain, response); + + chain.next(); + }); + + // NOTE: we return false to tell the chain that we'll manually call next() + return false; + }); + }, + + /////////////////////////////////////////////////////////////////////////////////////////////////////// + // + // ADMIN + // + /////////////////////////////////////////////////////////////////////////////////////////////////////// + + adminRebuildPathIndexes: function () { + const self = this; + + return this.then(function () { + + const chain = this; + + // call + const uri = self.getUri() + '/admin/paths/index'; + self.getDriver().gitanaPost(uri, null, {}, function () { + chain.next(); + }); + + // NOTE: we return false to tell the chain that we'll manually call next() + return false; + }); + }, + + adminRebuildSearchIndexes: function () { + const self = this; + + return this.then(function () { + + const chain = this; + + // call + const uri = self.getUri() + '/admin/search/index'; + self.getDriver().gitanaPost(uri, null, {}, function () { + chain.next(); + }); + + // NOTE: we return false to tell the chain that we'll manually call next() + return false; + }); + }, + + adminContentMaintenance: function () { + const self = this; + + return this.then(function () { + + const chain = this; + + // call + const uri = self.getUri() + '/admin/content'; + self.getDriver().gitanaPost(uri, null, {}, function () { + chain.next(); + }); + + // NOTE: we return false to tell the chain that we'll manually call next() + return false; + }); + }, + + adminUpgradeSchema: function () { + const self = this; + + return this.then(function () { + + const chain = this; + + // call + const uri = self.getUri() + '/admin/upgradeschema'; + self.getDriver().gitanaPost(uri, null, {}, function () { + chain.next(); + }); + + // NOTE: we return false to tell the chain that we'll manually call next() + return false; + }); + }, + + createForExport: function (exportId, config, callback) { + const self = this; + + if (!config) { + config = {}; + } + + if (!config.repositoryId) { + config.repositoryId = self.getRepositoryId(); + } + if (!config.branchId) { + config.branchId = self.getId(); + } + if (!config.properties) { + config.properties = {}; + } + if (!config.parentFolderPath) { + config.parentFolderPath = {}; + } + + const uriFunction = function () { + return '/ref/exports/' + exportId + '/generate'; + }; + + const params = {}; + + return this.chainPostResponse(this, uriFunction, params, config).then(function (response) { + callback(response); + }); + }, + + + ////////////////////////////////////////////////////////////////////////////////////////// + // + // INFO + // + ////////////////////////////////////////////////////////////////////////////////////////// + + /** + * Loads information about the branch. + * + * @param callback + */ + loadInfo: function (callback) { + const uriFunction = function () { + return this.getUri() + '/info'; + }; + + return this.chainGetResponse(this, uriFunction, {}).then(function (response) { + callback(response); + }); + }, + + + ////////////////////////////////////////////////////////////////////////////////////////// + // + // INDEXES + // + ////////////////////////////////////////////////////////////////////////////////////////// + + createCustomIndex: function (name, index) { + const self = this; + + let payload = null; + if (typeof (index) === 'undefined') { + payload = name; + } else { + payload = { + 'name': name, + 'index': index + }; + } + + const uriFunction = function () { + return self.getUri() + '/indexes'; + }; + + return this.chainPost(this, uriFunction, {}, payload); + }, + + dropCustomIndex: function (name) { + const self = this; + + const uriFunction = function () { + return self.getUri() + '/indexes/' + name; + }; + + return this.chainDelete(this, uriFunction); + }, + + loadCustomIndexes: function (callback) { + const self = this; + + const uriFunction = function () { + return self.getUri() + '/indexes'; + }; + + return this.chainGetResponse(this, uriFunction, {}).then(function (response) { + callback(response); + }); + }, + + + ////////////////////////////////////////////////////////////////////////////////////////// + // + // HISTORY + // + ////////////////////////////////////////////////////////////////////////////////////////// + + /** + * Loads the historic changesets for a branch. + * + * The config is optional and can specify "root" and "tip" changeset ids. + * + * @param config + * @param pagination (optional) + * @param callback + * @returns {*} + */ + loadHistoryChangesets: function (config, pagination, callback) { + const self = this; + + if (typeof (pagination) === 'function') { + callback = pagination; + pagination = null; + } + + if (typeof (config) === 'function') { + callback = config; + config = {}; + pagination = null; + } + + if (!config) { + config = {}; + } + + const uriFunction = function () { + return self.getUri() + '/history/changesets'; + }; + + const params = {}; + if (pagination) { + Gitana.copyInto(params, pagination); + } + + if (config.root) { + params.root = config.root; + } + if (config.tip) { + params.tip = config.tip; + } + if (config.include_root) { + params.include_root = config.include_root; + } + + return this.chainGetResponse(this, uriFunction, params).then(function (response) { + callback(response); + }); + }, + + /** + * Loads the history node differences for a branch. + * + * The config is optional and can specify "root" and "tip" changeset ids. + * + * @param config + * @param pagination (optional) + * @param callback + * @returns {*} + */ + loadHistoryNodeDiffs: function (config, pagination, callback) { + const self = this; + + if (typeof (pagination) === 'function') { + callback = pagination; + pagination = null; + } + + if (typeof (config) === 'function') { + callback = config; + config = {}; + pagination = null; + } + + if (!config) { + config = {}; + } + + const uriFunction = function () { + return self.getUri() + '/history/nodediffs'; + }; + + const params = {}; + if (pagination) { + Gitana.copyInto(params, pagination); + } + + if (config.root) { + params.root = config.root; + } + if (config.tip) { + params.tip = config.tip; + } + if (config.include_root) { + params.include_root = config.include_root; + } + + return this.chainGetResponse(this, uriFunction, params).then(function (response) { + callback(response); + }); + }, + + + /////////////////////////////////////////////////////////////////////////////////////////////////////////// + /////////////////////////////////////////////////////////////////////////////////////////////////////////// + /////////////////////////////////////////////////////////////////////////////////////////////////////////// + + + /** + * Reads a deletion. + * + * @chained deletion + * + * @public + * + * @param {String} nodeId the node id + */ + readDeletion: function (nodeId) { + const self = this; + + const uriFunction = function () { + return self.getUri() + '/deletions/' + nodeId; + }; + + const params = {}; + + const chainable = this.getFactory().deletion(this); + return this.chainGet(chainable, uriFunction, params); + }, + + /** + * Queries for deletions on the branch. + * + * Config should be: + * + * { + * Gitana query configs + * } + * + * @chained deletion map + * + * @public + * + * @param {Object} query + * @param {Object} pagination + */ + queryDeletions: function (query, pagination) { + const self = this; + + if (!query) { + query = {}; + } + + const params = {}; + if (pagination) { + Gitana.copyInto(params, pagination); + } + + const uriFunction = function () { + return self.getUri() + '/deletions/query'; + }; + + const chainable = this.getFactory().deletionMap(this); + + if (!Gitana.PREFER_GET_OVER_POST) { + return this.chainPost(chainable, uriFunction, params, query); + } else { + Gitana.copyInto(params, { + 'query': JSON.stringify(query) + }); + + return this.chainGet(chainable, uriFunction, params); + } + }, + + /** + * Purges all deletions. + * + * @chained this + */ + purgeAllDeletions: function () { + const self = this; + + const uriFunction = function () { + return self.getUri() + '/deletions/purgeall'; + }; + + return this.chainPostEmpty(null, uriFunction); + }, + + /** + * Archives the branch. + * + * @param callback + * @returns {*} + */ + archive: function (callback) { + const self = this; + + const uriFunction = function () { + return self.getUri() + '/archive'; + }; + + return this.chainPostResponse(this, uriFunction).then(function (response) { + callback(response); + }); + }, + + /** + * Unarchives the branch. + * + * @param callback + * @returns {*} + */ + unarchive: function (callback) { + const self = this; + + const uriFunction = function () { + return self.getUri() + '/unarchive'; + }; + + return this.chainPostResponse(this, uriFunction).then(function (response) { + callback(response); + }); + }, + + /** + * Finds the changes that will be applied from a source branch to a target branch. Runs as a background Job + * + * Params allow for: + * + * root root changeset id + * tip tip changeset id + * include_root whether to include the root changeset + * view "editorial" to filter only to include editorial nodes + * + * @public + * + * @param options (request param options, pagination) + * @param callback + */ + startChangesetHistory: function (options, callback) { + if (typeof (options) === 'function') { + callback = options; + options = null; + } + + const params = {}; + + if (Gitana.isObject(options)) { + for (const k in options) { + params[k] = options[k]; + } + } + + const uriFunction = function () { + return this.getUri() + '/history/start'; + }; + + return this.chainPostResponse(this, uriFunction, params).then(function (response) { + + const jobId = response._doc; + + callback(jobId); + }); + } + + }); + +})(window); +(function(window) +{ + Gitana = window.Gitana; + + Gitana.Changeset = Gitana.AbstractRepositoryObject.extend( + /** @lends Gitana.Changeset.prototype */ + { + /** + * @constructs + * @augments Gitana.AbstractRepositoryObject + * + * @class Changeset + * + * @param {Gitana.Repository} repository + * @param {Object} object json object (if no callback required for populating) + */ + constructor: function(repository, object) + { + this.base(repository, object); + + this.objectType = function() { return "Gitana.Changeset"; }; + }, + + /** + * @OVERRIDE + */ + getType: function() + { + return Gitana.TypedIDConstants.TYPE_CHANGESET; + }, + + /** + * @OVERRIDE + */ + getUri: function() + { + return "/repositories/" + this.getRepositoryId() + "/changesets/" + this.getId(); + }, + + /** + * @override + */ + clone: function() + { + return this.getFactory().changeset(this.getRepository(), this); + }, + + /** + * Lists the nodes on this changeset. + * + * @chained node map + * + * @param {Object} pagination optional pagination + */ + listNodes: function(pagination) + { + const params = {}; + if (pagination) + { + Gitana.copyInto(params, pagination); + } + + const uriFunction = function() + { + return "/repositories/" + this.getRepositoryId() + "/changesets/" + this.getId() + "/nodes"; + }; + + const chainable = this.getFactory().nodeMap(this); + return this.chainGet(chainable, uriFunction, params); + } + + }); + +})(window); +(function(window) +{ + Gitana = window.Gitana; + + Gitana.Node = Gitana.AbstractNode.extend( + /** @lends Gitana.Node.prototype */ + { + /** + * @constructs + * @augments Gitana.AbstractNode + * + * @class Node + * + * @param {Gitana.Branch} branch + * @param {Object} [object] json object (if no callback required for populating) + */ + constructor: function(branch, object) + { + this.base(branch, object); + + this.objectType = function() { return "Gitana.Node"; }; + }, + + /** + * @override + */ + getType: function() + { + return Gitana.TypedIDConstants.TYPE_NODE; + }, + + /** + * Acquires the "child nodes" of this node. This is done by fetching all of the nodes that are outgoing-associated to this + * node with a association of type "a:child". + * + * @chained node map + * + * @public + * + * @param {object} pagination + */ + listChildren: function(pagination) + { + const params = {}; + if (pagination) + { + Gitana.copyInto(params, pagination); + } + + const uriFunction = function() + { + return "/repositories/" + this.getRepositoryId() + "/branches/" + this.getBranchId() + "/nodes/" + this.getId() + "/children"; + }; + + const chainable = this.getFactory().nodeMap(this.getBranch()); + return this.chainGet(chainable, uriFunction, params); + }, + + /** + * Acquires the relatives of this node. + * + * @chained node map + * + * @public + * + * @param {Object} config + * @param {Object} [pagination] + */ + listRelatives: function(config, pagination) + { + let type = null; + let direction = null; + + if (config) + { + type = config.type; + if (config.direction) + { + direction = config.direction.toUpperCase(); + } + } + + const params = {}; + if (pagination) + { + Gitana.copyInto(params, pagination); + } + + const uriFunction = function() + { + let url = "/repositories/" + this.getRepositoryId() + "/branches/" + this.getBranchId() + "/nodes/" + this.getId() + "/relatives"; + if (type) + { + url = url + "?type=" + type; + } + if (direction) + { + if (type) + { + url = url + "&direction=" + direction; + } + else + { + url = url + "?direction=" + direction; + } + } + return url; + }; + + const chainable = this.getFactory().nodeMap(this.getBranch()); + return this.chainGet(chainable, uriFunction, params); + }, + + /** + * Queries for relatives of this node. + * + * @chained node map + * + * @public + * + * @param {Object} query + * @param {Object} config + * @param {Object} [pagination] + */ + queryRelatives: function(query, config, pagination) + { + let type = null; + let direction = null; + + if (config) + { + type = config.type; + if (config.direction) + { + direction = config.direction.toUpperCase(); + } + } + + const params = {}; + if (pagination) + { + Gitana.copyInto(params, pagination); + } + + const uriFunction = function() + { + let url = "/repositories/" + this.getRepositoryId() + "/branches/" + this.getBranchId() + "/nodes/" + this.getId() + "/relatives/query"; + if (type) + { + url = url + "?type=" + type; + } + if (direction) + { + if (type) + { + url = url + "&direction=" + direction; + } + else + { + url = url + "?direction=" + direction; + } + } + return url; + }; + + const chainable = this.getFactory().nodeMap(this.getBranch()); + return this.chainPost(chainable, uriFunction, params, query); + }, + + patch: function(patches) + { + const uriFunction = function() + { + return this.getUri(); + }; + + const chainable = this.getFactory().nodeMap(this.getBranch()); + return this.chainPatch(chainable, uriFunction, null, patches); + }, + + /** + * Retrieves all of the association objects for this node. + * + * @chained node map + * + * @public + * + * @param {Object} config + * @param {Object} pagination + */ + associations: function(config, pagination) + { + let type = null; + let direction = null; + + if (config) + { + type = config.type; + if (config.direction) + { + direction = config.direction.toUpperCase(); + } + } + + const params = {}; + if (pagination) + { + Gitana.copyInto(params, pagination); + } + + const uriFunction = function() + { + let url = "/repositories/" + this.getRepositoryId() + "/branches/" + this.getBranchId() + "/nodes/" + this.getId() + "/associations?a=1"; + if (type) + { + url = url + "&type=" + type; + } + if (direction) + { + url = url + "&direction=" + direction; + } + + return url; + }; + + const chainable = this.getFactory().nodeMap(this.getBranch()); + return this.chainGet(chainable, uriFunction, params); + }, + + /** + * Retrieves all of the incoming association objects for this node. + * + * @chained node map + * + * @public + * + * @param {String} [type] - the type of association + * @param {Object} [pagination] + */ + incomingAssociations: function(type, pagination) + { + const config = { + "direction": "INCOMING" + }; + if (type) { + config.type = type; + } + + return this.associations(config, pagination); + }, + + /** + * Retrieves all of the outgoing association objects for this node. + * + * @chained node map + * + * @public + * + * @param {String} [type] the type of association + * @param {Object} [pagination] + */ + outgoingAssociations: function(type, pagination) + { + const config = { + "direction": "OUTGOING" + }; + if (type) { + config.type = type; + } + + return this.associations(config, pagination); + + }, + + /** + * Associates a target node to this node. + * + * @chained this + * + * @public + * + * @param {String|Gitana.Node} targetNodeId - the id of the target node or the target node itself + * @param {Object|String} [object] either a JSON object or a string identifying the type of association + * @param {Boolean} [undirected] whether the association is undirected (i.e. mutual) + */ + associate: function(targetNodeId, object, undirected) + { + if (!Gitana.isString(targetNodeId)) + { + targetNodeId = targetNodeId.getId(); + } + + if (object) + { + if (Gitana.isString(object)) + { + object = { + "_type": object + }; + } + } + + const uriFunction = function() + { + let url = "/repositories/" + this.getRepositoryId() + "/branches/" + this.getBranchId() + "/nodes/" + this.getId() + "/associate?node=" + targetNodeId; + + if (undirected) + { + url += "&directionality=UNDIRECTED"; + } + + return url; + }; + + return this.chainPostEmpty(null, uriFunction, null, object); + }, + + /** + * Creates an association from another node to this one. + * + * @chained node (this) + * + * @public + * + * @param {Node} sourceNode + * @param {Object} object + * @param {Boolean} [undirected] + */ + associateOf: function(sourceNode, object, undirected) + { + const self = this; + + // what we're handing back (ourselves) + const result = this.subchain(this); + + // our work + result.subchain(sourceNode).then(function() { + this.associate(self, object, undirected); + }); + + return result; + }, + + /** + * Unassociates a target node from this node. + * + * @chained this + * + * @public + * + * @param {String|Gitana.Node} targetNodeId the id of the target node or the target node itself + * @param {String} [type] A string identifying the type of association + * @param {Boolean} [undirected] whether the association is undirected (i.e. mutual) + */ + unassociate: function(targetNodeId, type, undirected) + { + if (!Gitana.isString(targetNodeId)) + { + targetNodeId = targetNodeId.getId(); + } + + const uriFunction = function() + { + let url = "/repositories/" + this.getRepositoryId() + "/branches/" + this.getBranchId() + "/nodes/" + this.getId() + "/unassociate?node=" + targetNodeId; + + if (type) + { + url = url + "&type=" + type; + } + + if (undirected) + { + url += "&directionality=UNDIRECTED"; + } + + return url; + }; + + return this.chainPostEmpty(null, uriFunction); + }, + + /** + * Traverses around the node and returns any nodes found to be connected on the graph. + * + * Example config: + * + * { + * "associations": { + * "a:child": "MUTUAL", + * "a:knows": "INCOMING", + * "a:related": "OUTGOING" + * }, + * "depth": 1, + * "types": [ "custom:type1", "custom:type2" ] + * } + * + * @chained traversal results + * + * @public + * + * @param {Object} config configuration for the traversal + */ + traverse: function(config) + { + // build the payload + const payload = { + "traverse": config + }; + + const uriFunction = function() + { + return "/repositories/" + this.getRepositoryId() + "/branches/" + this.getBranchId() + "/nodes/" + this.getId() + "/traverse"; + }; + + const chainable = this.getFactory().traversalResults(this.getBranch()); + const params = {}; + return this.chainPost(chainable, uriFunction, params, payload); + }, + + /** + * Mounts a node + * + * @chained this + * + * @public + * + * @param {String} mountKey the mount key + */ + mount: function(mountKey) + { + const uriFunction = function() + { + return "/repositories/" + this.getRepositoryId() + "/branches/" + this.getBranchId() + "/nodes/" + this.getId() + "/mount/" + mountKey; + }; + + return this.chainPostEmpty(null, uriFunction, null, object); + }, + + /** + * Unmounts a node + * + * @public + */ + unmount: function() + { + const uriFunction = function() + { + return "/repositories/" + this.getRepositoryId() + "/branches/" + this.getBranchId() + "/nodes/" + this.getId() + "/unmount"; + }; + + return this.chainPostEmpty(null, uriFunction, null, object); + }, + + /** + * Locks a node + * + * @chained this + * + * @public + */ + lock: function() + { + const uriFunction = function() + { + return "/repositories/" + this.getRepositoryId() + "/branches/" + this.getBranchId() + "/nodes/" + this.getId() + "/lock"; + }; + + return this.chainPostEmpty(null, uriFunction); + }, + + /** + * Unlocks a node + * + * @chained this + * + * @public + */ + unlock: function() + { + const uriFunction = function() + { + return "/repositories/" + this.getRepositoryId() + "/branches/" + this.getBranchId() + "/nodes/" + this.getId() + "/unlock"; + }; + + return this.chainPostEmpty(null, uriFunction); + }, + + /** + * Checks whether the node is locked. + * The result is passed into the next method in the chain. + * + * @chained this + * + * @public + */ + checkLocked: function(callback) + { + // TODO: isn't this subchain() redundant? + return this.subchain(this).then(function() { + + const chain = this; + + // call + const uri = "/repositories/" + this.getRepositoryId() + "/branches/" + this.getBranchId() + "/nodes/" + this.getId() + "/lock"; + this.getDriver().gitanaGet(uri, null, {}, function(response) { + + callback.call(chain, response["locked"]); + + chain.next(); + }); + + // NOTE: we return false to tell the chain that we'll manually call next() + return false; + }); + }, + + + ////////////////////////////////////////////////////////////////////////////////////////// + // + // ACL METHODS + // + ////////////////////////////////////////////////////////////////////////////////////////// + + /** + * Retrieve full ACL and pass into chaining method. + * + * @chained node + */ + loadACL: function(callback) + { + const self = this; + + const uriFunction = function() + { + return self.getUri() + "/acl/list"; + }; + + return this.chainGetResponse(this, uriFunction).then(function(response) { + callback.call(this, response); + }); + }, + + /** + * Retrieve list of authorities and pass into chaining method. + * + * @chained node + * + * @param {Gitana.Principal|String} principal the principal or the principal id + */ + listAuthorities: function(principal) + { + const principalDomainQualifiedId = this.extractPrincipalDomainQualifiedId(principal); + + const uriFunction = function() + { + return "/repositories/" + this.getRepositoryId() + "/branches/" + this.getBranchId() + "/nodes/" + this.getId() + "/acl?id=" + principalDomainQualifiedId; + }; + + return this.chainGetResponseRows(this, uriFunction); + }, + + /** + * Checks whether the given principal has a granted authority for this object. + * This passes the result (true/false) to the chaining function. + * + * @chained this + * + * @param {Gitana.Principal|String} principal the principal or the principal id + * @param {String} authorityId the id of the authority + * @param {Function} callback + */ + checkAuthority: function(principal, authorityId, callback) + { + const principalDomainQualifiedId = this.extractPrincipalDomainQualifiedId(principal); + + const uriFunction = function() + { + return "/repositories/" + this.getRepositoryId() + "/branches/" + this.getBranchId() + "/nodes/" + this.getId() + "/authorities/" + authorityId + "/check?id=" + principalDomainQualifiedId; + }; + + return this.chainPostResponse(this, uriFunction).then(function(response) { + callback.call(this, response["check"]); + }); + }, + + /** + * Grants an authority to a principal against this object. + * + * @chained this + * + * @param {Gitana.Principal|String} principal the principal or the principal id + * @param {String} authorityId the id of the authority + */ + grantAuthority: function(principal, authorityId) + { + const principalDomainQualifiedId = this.extractPrincipalDomainQualifiedId(principal); + + const uriFunction = function() + { + return "/repositories/" + this.getRepositoryId() + "/branches/" + this.getBranchId() + "/nodes/" + this.getId() + "/authorities/" + authorityId + "/grant?id=" + principalDomainQualifiedId; + }; + + return this.chainPostEmpty(null, uriFunction); + }, + + /** + * Revokes an authority from a principal against this object. + * + * @chained this + * + * @param {Gitana.Principal|String} principal the principal or the principal id + * @param {String} authorityId the id of the authority + */ + revokeAuthority: function(principal, authorityId) + { + const principalDomainQualifiedId = this.extractPrincipalDomainQualifiedId(principal); + + const uriFunction = function() + { + return "/repositories/" + this.getRepositoryId() + "/branches/" + this.getBranchId() + "/nodes/" + this.getId() + "/authorities/" + authorityId + "/revoke?id=" + principalDomainQualifiedId; + }; + + return this.chainPostEmpty(null, uriFunction); + }, + + /** + * Revokes all authorities for a principal against the server. + * + * @chained this + * + * @param {Gitana.Principal|String} principal the principal or the principal id + */ + revokeAllAuthorities: function(principal) + { + return this.revokeAuthority(principal, "all"); + }, + + /** + * Loads the authority grants for a given set of principals. + * + * @chained repository + * + * @param {Array} principalIds + * @param {Function} callback + */ + loadAuthorityGrants: function(principalIds, callback) + { + if (!principalIds) + { + principalIds = []; + } + + const json = { + "principals": principalIds + }; + + return this.chainPostResponse(this, "/repositories/" + this.getRepositoryId() + "/branches/" + this.getBranchId() + "/nodes/" + this.getId() + "/authorities", {}, json).then(function(response) { + callback.call(this, response); + }); + }, + + /** + * Checks whether the given principal has a permission against this object. + * This passes the result (true/false) to the chaining function. + * + * @chained server + * + * @param {Gitana.Principal|String} principal the principal or the principal id + * @param {String} permissionId the id of the permission + * @param {Function} callback + */ + checkPermission: function(principal, permissionId, callback) + { + const principalDomainQualifiedId = this.extractPrincipalDomainQualifiedId(principal); + + const uriFunction = function() + { + return "/repositories/" + this.getRepositoryId() + "/branches/" + this.getBranchId() + "/nodes/" + this.getId() + "/permissions/" + permissionId + "/check?id=" + principalDomainQualifiedId; + }; + + return this.chainPostResponse(this, uriFunction).then(function(response) { + callback.call(this, response["check"]); + }); + }, + + + + ////////////////////////////////////////////////////////////////////////////////////////// + // + // END OF ACL METHODS + // + ////////////////////////////////////////////////////////////////////////////////////////// + + /** + * Creates a new translation. + * + * @chained translation node + * + * @param {String} edition the edition of the translation (can be any string) + * @param {String} locale the locale string for the translation (i.e. "en_US") + * @param {Object} [object] JSON object + */ + createTranslation: function(edition, locale, object) + { + const uriFunction = function() + { + let url = "/repositories/" + this.getRepositoryId() + "/branches/" + this.getBranchId() + "/nodes/" + this.getId() + "/i18n?locale=" + locale; + if (edition) + { + url += "&edition=" + edition; + } + + return url; + }; + + const chainable = this.getFactory().node(this.getBranch()); + return this.chainCreateEx(chainable, object, uriFunction, uriFunction); + }, + + /** + * Lists all of the editions for this master node. + * Passes them into the next function in the chain. + * + * @chained this + * + * @param {function} callback + */ + editions: function(callback) + { + const uriFunction = function() + { + return "/repositories/" + this.getRepositoryId() + "/branches/" + this.getBranchId() + "/nodes/" + this.getId() + "/i18n/editions"; + }; + + return this.chainGetResponse(this, uriFunction).then(function(response) { + callback.call(this, response["editions"]); + }); + }, + + /** + * Lists all of the locales for the given edition of this master node. + * Passes them into the next function in the chain. + * + * @chained this + * + * @param {String} edition the edition + * @param {function} callback + */ + locales: function(edition, callback) + { + const uriFunction = function() + { + return "/repositories/" + this.getRepositoryId() + "/branches/" + this.getBranchId() + "/nodes/" + this.getId() + "/i18n/locales?edition=" + edition; + }; + + return this.chainGetResponse(this, uriFunction).then(function(response) { + callback.call(this, response["locales"]); + }); + }, + + /** + * Acquires all of the translations for a master node. + * + * @chained node map + * + * @public + * + * @param {String} edition + * @param {Object} [pagination] + */ + listTranslations: function(edition, pagination) + { + const params = {}; + if (edition) + { + params.edition = edition; + } + if (pagination) + { + Gitana.copyInto(params, pagination); + } + + const uriFunction = function() + { + return "/repositories/" + this.getRepositoryId() + "/branches/" + this.getBranchId() + "/nodes/" + this.getId() + "/i18n/translations"; + }; + + const chainable = this.getFactory().nodeMap(this.getBranch()); + return this.chainGet(chainable, uriFunction, params); + }, + + + /** + * Reads a translation node of the current master node into a given locale and optional edition. + * If an edition isn't provided, the tip edition from the master node is assumed. + * + * @chained translation node + * + * @param {String} edition The edition of the translation to use. If not provided, the tip edition is used from the master node. + * @param {String} locale The locale to translate into. + */ + readTranslation: function() + { + let edition; + let locale; + + const args = Gitana.makeArray(arguments); + + if (args.length === 1) + { + locale = args.shift(); + } + else if (args.length > 1) + { + edition = args.shift(); + locale = args.shift(); + } + + const uriFunction = function() + { + let uri = "/repositories/" + this.getRepositoryId() + "/branches/" + this.getBranchId() + "/nodes/" + this.getId() + "/i18n?locale=" + locale; + if (edition) + { + uri += "&edition=" + edition; + } + + return uri; + }; + + const chainable = this.getFactory().node(this.getBranch()); + return this.chainGet(chainable, uriFunction); + }, + + + + ////////////////////////////////////////////////////////////////////////////////////////// + // + // CONTAINER CONVENIENCE FUNCTIONS + // + ////////////////////////////////////////////////////////////////////////////////////////// + + /** + * Create a node as a child of this node. + * + * This is a convenience function around the branch createNode method. It chains a create with a + * childOf() call. + * + * @chained new node + * + * @public + * + * @param {Object} [object] JSON object + */ + createChild: function(object) + { + const self = this; + + // we can't assume we know the branch get since we're chaining + // so create a temporary branch that we'll load later + + const branch = new Gitana.Branch(this.getRepository()); + + // we hand back a node and preload some work + const chainable = this.getFactory().node(branch); + return this.subchain(chainable).then(function() { + + const chain = this; + + // we now plug in branch and create child node + this.subchain(self).then(function() { + + // load branch + branch.loadFrom(this.getBranch()); + + // create child node + this.subchain(branch).createNode(object).then(function() { + + chain.loadFrom(this); + + this.childOf(self); + }); + + }); + + }); + + }, + + /** + * Associates this node as an "a:child" of the source node. + * + * This is a convenience function that simply creates an association from another node to this one. + * + * @chained node (this) + * + * @public + * + * @param {Node} sourceNode + */ + childOf: function(sourceNode) + { + return this.associateOf(sourceNode, "a:child"); + }, + + + ////////////////////////////////////////////////////////////////////////////////////////// + // + // FIND + // + ////////////////////////////////////////////////////////////////////////////////////////// + + /** + * Finds around a node. + * + * @chained node map + * + * Config should be: + * + * { + * "query": { + * ... Query Block + * }, + * "search": { + * ... Elastic Search Config Block + * }, + * "traverse: { + * ... Traversal Configuration + * } + * } + * + * Alternatively, the value for "search" in the JSON block above can simply be text. + * + * @public + * + * @param {Object} config search configuration + * @param {Object} [pagination] + */ + find: function(config, pagination) + { + const params = {}; + if (pagination) + { + Gitana.copyInto(params, pagination); + } + + const uriFunction = function() + { + return "/repositories/" + this.getRepositoryId() + "/branches/" + this.getBranchId() + "/nodes/" + this.getId() + "/find"; + }; + + const chainable = this.getFactory().nodeMap(this.getBranch()); + return this.chainPost(chainable, uriFunction, params, config); + }, + + /** + * Finds relatives of this node. + * + * Config should be: + * + * { + * "query": { + * ... Query Block + * }, + * "search": { + * ... Elastic Search Config Block + * }, + * "traverse: { + * ... Traversal Configuration + * } + * } + * + * Alternatively, the value for "search" in the JSON block above can simply be text. + * + * The associationConfig should look like: + * + * { + * "type": "", + * "direction": "" + * } + * + * @chained node map + * + * @public + * + * @param {Object} config + * @param {Object} associationConfig + * @param {Object} [pagination] + */ + findRelatives: function(config, associationConfig, pagination) + { + let type = null; + let direction = null; + + if (associationConfig) + { + type = associationConfig.type; + if (associationConfig.direction) + { + direction = associationConfig.direction.toUpperCase(); + } + + delete associationConfig.type; + delete associationConfig.direction; + } + + const params = {}; + if (pagination) + { + Gitana.copyInto(params, pagination); + } + + const uriFunction = function() + { + let url = "/repositories/" + this.getRepositoryId() + "/branches/" + this.getBranchId() + "/nodes/" + this.getId() + "/relatives/find"; + if (type) + { + url = url + "?type=" + type; + } + if (direction) + { + if (type) + { + url = url + "&direction=" + direction; + } + else + { + url = url + "?direction=" + direction; + } + } + return url; + }; + + const chainable = this.getFactory().nodeMap(this.getBranch()); + return this.chainPost(chainable, uriFunction, params, config); + }, + + /** + * Retrieves a tree structure for nested folders starting at this node (as the root). + * + * @chained node + * + * @public + * + * @param {Object} config - { "leafPath": "", "basePath": "", "containers": true, "depth": integer, "properties": true|false, "query": {}, "search": {} } + * @param {Function} callback - the callback function to be passed the resulting tree object structure + */ + loadTree: function(config, callback) + { + const self = this; + + if (typeof(config) === "function") + { + callback = config; + config = null; + } + + if (!config) + { + config = {}; + } + + const uriFunction = function() + { + return self.getUri() + "/tree"; + }; + + const params = {}; + if (config.leafPath) + { + params["leaf"] = config.leafPath; + } + else if (config.leaf) + { + params["leaf"] = config.leaf; + } + if (config.basePath) + { + params["base"] = config.basePath; + } + else if (config.base) + { + params["base"] = config.base; + } + if (config.containers) + { + params["containers"] = true; + } + if (config.properties) + { + params["properties"] = true; + } + if (config.object) + { + params["object"] = true; + } + params.depth = 1; + if (config.depth) + { + params["depth"] = config.depth; + } + + const payload = {}; + if (config.query) { + payload.query = config.query; + } + + if(config.search) { + payload.search = config.search; + } + + return this.chainPostResponse(this, uriFunction, params, payload).then(function(response) { + callback.call(this, response); + }); + }, + + /** + * Resolves the path to this node relative to the given root node. + * + * @param {String} rootNodeId + * @param {Function} callback + * @returns {*} + */ + resolvePath: function(rootNodeId, callback) + { + const self = this; + + const uriFunction = function() + { + return self.getUri() + "/path"; + }; + + const params = { + "rootNodeId": rootNodeId + }; + + return this.chainGetResponse(this, uriFunction, params).then(function(response) { + callback.call(this, response.path); + }); + + }, + + //////////////////////////////////////// + // + // VERSIONS + // + //////////////////////////////////////// + + listVersions: function(pagination) + { + const params = {}; + if (pagination) + { + Gitana.copyInto(params, pagination); + } + + const uriFunction = function () { + return this.getUri() + "/versions"; + }; + + const chainable = this.getFactory().nodeMap(this.getBranch()); + + return this.chainGet(chainable, uriFunction, params); + }, + + restoreVersion: function(changesetId) + { + const uriFunction = function() + { + return "/repositories/" + this.getRepositoryId() + "/branches/" + this.getBranchId() + "/nodes/" + this.getId() + "/versions/" + changesetId + "/restore"; + }; + + const chainable = this.getFactory().node(this.getBranch()); + return this.chainPost(chainable, uriFunction, {}, {}); + }, + + //////////////////////////////////////// + // + // MOVE A NODE TO ANOTHER FOLDER + // + //////////////////////////////////////// + + /** + * Moves this node to another folder. + * + * @chained job + * + * @param targetFolder either a node or a node ID + */ + moveToFolder: function(targetFolder) + { + const self = this; + + const params = {}; + params.targetNodeId = targetFolder.getId ? targetFolder.getId() : targetFolder; + + const uriFunction = function() + { + return self.getUri() + "/move"; + }; + + // NOTE: pass control back to the server instance + return this.chainPostEmpty(this, uriFunction, params); + } + + }); + +})(window); +(function(window) +{ + Gitana = window.Gitana; + + Gitana.Release = Gitana.AbstractRepositoryObject.extend( + /** @lends Gitana.Release.prototype */ + { + /** + * @constructs + * @augments Gitana.AbstractRepositoryObject + * + * @class Release + * + * @param {Gitana.Repository} repository + * @param {Object} object json object (if no callback required for populating) + */ + constructor: function(repository, object) + { + this.base(repository, object); + + this.objectType = function() { return "Gitana.Release"; }; + }, + + /** + * @OVERRIDE + */ + getType: function() + { + return Gitana.TypedIDConstants.TYPE_RELEASE; + }, + + /** + * @OVERRIDE + */ + getUri: function() + { + return "/repositories/" + this.getRepositoryId() + "/releases/" + this.getId(); + }, + + /** + * @override + */ + clone: function() + { + return this.getFactory().release(this.getRepository(), this); + }, + + /** + * Finalizes the release. + * + * @param object + * @param callback + * @returns {*} + */ + finalize: function(object, callback) + { + if (typeof(object) === "function") + { + callback = object; + object = null; + } + + if (!object) { + object = {}; + } + + const self = this; + + const uriFunction = function() + { + return self.getUri() + "/finalize"; + }; + + return this.chainPostResponse(this, uriFunction, {}, object).then(function(response) { + callback(response); + }); + }, + + /** + * Unfinalizes the release. + * + * @param callback + * @returns {*} + */ + unfinalize: function(callback) + { + const self = this; + + const uriFunction = function() + { + return self.getUri() + "/unfinalize"; + }; + + return this.chainPostResponse(this, uriFunction).then(function(response) { + callback(response); + }); + }, + + /** + * Loads information about the release. + * + * @param callback + */ + loadInfo: function(callback) + { + const self = this; + + const uriFunction = function() + { + return self.getUri() + "/info"; + }; + + return this.chainGetResponse(this, uriFunction, {}).then(function(response) { + callback(response); + }); + }, + + /** + * Starts the finalization of a release. + * This runs a background job to do the actual finalization and hands back a job ID. + * + * @chained release + * + * @param {Object} object JSON object + * @param callback + */ + startFinalize: function(object, callback) + { + const self = this; + + if (typeof(object) === "function") { + callback = object; + object = null; + } + + const uriFunction = function() + { + return self.getUri() + "/finalize/start"; + }; + + if (!object) + { + object = {}; + } + + return this.chainPostResponse(this, uriFunction, {}, object).then(function(response) { + + const jobId = response._doc; + + callback(jobId); + }); + }, + + /** + * Archives the release. + * + * @param callback + * @returns {*} + */ + archive: function(callback) + { + const self = this; + + const uriFunction = function() + { + return self.getUri() + "/archive"; + }; + + return this.chainPostResponse(this, uriFunction).then(function(response) { + callback(response); + }); + }, + + /** + * Unarchives the release. + * + * @param callback + * @returns {*} + */ + unarchive: function(callback) + { + const self = this; + + const uriFunction = function() + { + return self.getUri() + "/unarchive"; + }; + + return this.chainPostResponse(this, uriFunction).then(function(response) { + callback(response); + }); + }, + + /** + * Releases immediately. + * + * @param callback + * @returns {*} + */ + releaseImmediately: function(callback) + { + const self = this; + + const uriFunction = function() + { + return self.getUri() + "/releaseimmediately"; + }; + + return this.chainPostResponse(this, uriFunction).then(function(response) { + callback(response); + }); + } + + }); + +})(window); +(function(window) +{ + Gitana = window.Gitana; + + Gitana.MergeConflict = Gitana.AbstractRepositoryObject.extend( + /** @lends Gitana.MergeConflict.prototype */ + { + /** + * @constructs + * @augments Gitana.AbstractRepositoryObject + * + * @class MergeConflict + * + * @param {Gitana.Repository} repository + * @param {Object} object json object (if no callback required for populating) + */ + constructor: function(repository, object) + { + this.base(repository, object); + + this.objectType = function() { return "Gitana.MergeConflict"; }; + }, + + /** + * @OVERRIDE + */ + getType: function() + { + return Gitana.TypedIDConstants.TYPE_MERGE_CONFLICT; + }, + + /** + * @OVERRIDE + */ + getUri: function() + { + return "/repositories/" + this.getRepositoryId() + "/conflicts/" + this.getId(); + }, + + /** + * @override + */ + clone: function() + { + return this.getFactory().mergeConflict(this.getRepository(), this); + }, + + resolve: function(resolutionsArrayOrString, callback) + { + const self = this; + + const uriFunction = function() + { + return self.getUri() + "/resolve"; + }; + + const params = {}; + let payload = null; + + if (Gitana.isString(resolutionsArrayOrString)) + { + params.resolution = resolutionsArrayOrString; + } + else if (Gitana.isArray(resolutionsArrayOrString)) + { + payload = { + "resolutions": resolutionsArrayOrString + }; + } + + return this.chainPostResponse(this, uriFunction, params, payload).then(function(response) { + callback(response); + }); + }, + + commit: function(branchId) + { + const self = this; + + const uriFunction = function() + { + return self.getUri() + "/commit"; + }; + + const params = {}; + if (branchId) { + params.branch = branchId; + } + + return this.chainPost(this, uriFunction, params); + } + + }); + +})(window); +(function(window) +{ + Gitana = window.Gitana; + + Gitana.Deletion = Gitana.AbstractRepositoryObject.extend( + /** @lends Gitana.Deletion.prototype */ + { + /** + * @constructs + * @augments Gitana.AbstractRepositoryObject + * + * @class Node + * + * @param {Gitana.Branch} branch + * @param {Object} [object] json object (if no callback required for populating) + */ + constructor: function(branch, object) + { + this.base(branch.getRepository(), object); + + this.objectType = function() { return "Gitana.Deletion"; }; + + ////////////////////////////////////////////////////////////////////////////////////////////// + // + // PRIVILEGED METHODS + // + ////////////////////////////////////////////////////////////////////////////////////////////// + + /** + * Gets the Gitana Branch object. + * + * @inner + * + * @returns {Gitana.Branch} The Gitana Branch object + */ + this.getBranch = function() { return branch; }; + + /** + * Gets the Gitana Branch id. + * + * @inner + * + * @returns {String} The Gitana Branch id + */ + this.getBranchId = function() { return branch.getId(); }; + }, + + /** + * @override + */ + getType: function() + { + return Gitana.TypedIDConstants.TYPE_DELETION; + }, + + /** + * @OVERRIDE + */ + getUri: function() + { + return "/repositories/" + this.getRepositoryId() + "/branches/" + this.getBranchId() + "/deletions/" + this._deletion.nodeId; + }, + + /** + * @override + */ + clone: function() + { + return this.getFactory().deletion(this.getBranch(), this); + }, + + /** + * @override + */ + ref: function() + { + return "deletion://" + this.getPlatformId() + "/" + this.getRepositoryId() + "/" + this.getBranchId() + "/" + this._deletion.nodeId; + }, + + /** + * Restores a deletion to the branch. + * + * @public + * @param {object} data any data to override on the restored node + * @param callback + */ + restore: function(data, callback) + { + const self = this; + + if (typeof(data) === "function") + { + callback = data; + data = {}; + } + + if (!data) { + data = {}; + } + + const uriFunction = function() + { + return self.getUri() + "/restore"; + }; + + return this.chainPostResponse(null, uriFunction, {}, data).then(function(response) { + callback.call(this, response); + }); + } + + }); + +})(window); +(function(window) +{ + Gitana = window.Gitana; + + Gitana.BranchMap = Gitana.AbstractPlatformObjectMap.extend( + /** @lends Gitana.BranchMap.prototype */ + { + /** + * @constructs + * @augments Gitana.AbstractPlatformObjectMap + * + * @class Map of branch objects + * + * @param {Gitana.Repository} repository + * @param {Object} object + */ + constructor: function(repository, object) + { + this.objectType = function() { return "Gitana.BranchMap"; }; + + + ////////////////////////////////////////////////////////////////////////////////////////////// + // + // PRIVILEGED METHODS + // + ////////////////////////////////////////////////////////////////////////////////////////////// + + /** + * Gets the Gitana Repository object. + * + * @inner + * + * @returns {Gitana.Repository} The Gitana Repository object + */ + this.getRepository = function() { return repository; }; + + /** + * Gets the Gitana Repository id. + * + * @inner + * + * @returns {String} The Gitana Repository id + */ + this.getRepositoryId = function() { return repository.getId(); }; + + + ////////////////////////////////////////////////////////////////////////////////////////////// + // + // CALL THROUGH TO BASE CLASS (at the end) + // + ////////////////////////////////////////////////////////////////////////////////////////////// + + this.base(repository.getPlatform(), object); + }, + + /** + * @override + */ + clone: function() + { + return this.getFactory().branchMap(this.getRepository(), this); + }, + + /** + * @param json + */ + buildObject: function(json) + { + return this.getFactory().branch(this.getRepository(), json); + } + + }); + +})(window); +(function(window) +{ + Gitana = window.Gitana; + + Gitana.ChangesetMap = Gitana.AbstractPlatformObjectMap.extend( + /** @lends Gitana.ChangesetMap.prototype */ + { + /** + * @constructs + * @augments Gitana.AbstractPlatformObjectMap + * + * @class Map of changeset objects + * + * @param {Gitana.Repository} repository Gitana repository instance. + * @param {Object} object + */ + constructor: function(repository, object) + { + this.objectType = function() { return "Gitana.ChangesetMap"; }; + + + ////////////////////////////////////////////////////////////////////////////////////////////// + // + // PRIVILEGED METHODS + // + ////////////////////////////////////////////////////////////////////////////////////////////// + + /** + * Gets the Gitana Repository object. + * + * @inner + * + * @returns {Gitana.Repository} The Gitana Repository object + */ + this.getRepository = function() { return repository; }; + + /** + * Gets the Gitana Repository id. + * + * @inner + * + * @returns {String} The Gitana Repository id + */ + this.getRepositoryId = function() { return repository.getId(); }; + + + ////////////////////////////////////////////////////////////////////////////////////////////// + // + // CALL THROUGH TO BASE CLASS (at the end) + // + ////////////////////////////////////////////////////////////////////////////////////////////// + + this.base(repository.getPlatform(), object); + }, + + /** + * @override + */ + clone: function() + { + return this.getFactory().changesetMap(this.getRepository(), this); + }, + + /** + * @param json + */ + buildObject: function(json) + { + return this.getFactory().changeset(this.getRepository(), json); + } + + }); + +})(window); +(function(window) +{ + Gitana = window.Gitana; + + Gitana.NodeMap = Gitana.AbstractPlatformObjectMap.extend( + /** @lends Gitana.NodeMap.prototype */ + { + /** + * @constructs + * @augments Gitana.AbstractPlatformObjectMap + * + * @class Map of node objects + * + * @param {Gitana.Branch} branch Gitana branch instance. + * @param {Object} object + */ + constructor: function(branch, object) + { + this.objectType = function() { return "Gitana.NodeMap"; }; + + + ////////////////////////////////////////////////////////////////////////////////////////////// + // + // PRIVILEGED METHODS + // + ////////////////////////////////////////////////////////////////////////////////////////////// + + /** + * Gets the Gitana Repository object. + * + * @inner + * + * @returns {Gitana.Repository} The Gitana Repository object + */ + this.getRepository = function() { return branch.getRepository(); }; + + /** + * Gets the Gitana Repository id. + * + * @inner + * + * @returns {String} The Gitana Repository id + */ + this.getRepositoryId = function() { return branch.getRepository().getId(); }; + + /** + * Gets the Gitana Branch object. + * + * @inner + * + * @returns {Gitana.Branch} The Gitana Branch object + */ + this.getBranch = function() { return branch; }; + + /** + * Gets the Gitana Branch id. + * + * @inner + * + * @returns {String} The Gitana Branch id + */ + this.getBranchId = function() { return branch.getId(); }; + + + ////////////////////////////////////////////////////////////////////////////////////////////// + // + // CALL THROUGH TO BASE CLASS (at the end) + // + ////////////////////////////////////////////////////////////////////////////////////////////// + + this.base(branch.getPlatform(), object); + }, + + /** + * @override + */ + clone: function() + { + return this.getFactory().nodeMap(this.getBranch(), this); + }, + + /** + * @param json + */ + buildObject: function(json) + { + return this.getFactory().node(this.getBranch(), json); + }, + + /** + * Delete + * + * @chained this + * + * @public + */ + del: function() + { + const self = this; + + const uriFunction = function() + { + return self.getBranch().getUri() + "/nodes/delete"; + }; + + return this.subchain().then(function() { + + const nodeIds = this.__keys(); + + return this.chainPost(this, uriFunction, {}, { + "_docs": nodeIds + }); + }); + } + + }); + +})(window); +(function(window) +{ + Gitana = window.Gitana; + + Gitana.ReleaseMap = Gitana.AbstractPlatformObjectMap.extend( + /** @lends Gitana.ReleaseMap.prototype */ + { + /** + * @constructs + * @augments Gitana.AbstractPlatformObjectMap + * + * @class Map of release objects + * + * @param {Gitana.Repository} repository + * @param {Object} object + */ + constructor: function(repository, object) + { + this.objectType = function() { return "Gitana.ReleaseMap"; }; + + + ////////////////////////////////////////////////////////////////////////////////////////////// + // + // PRIVILEGED METHODS + // + ////////////////////////////////////////////////////////////////////////////////////////////// + + /** + * Gets the Gitana Repository object. + * + * @inner + * + * @returns {Gitana.Repository} The Gitana Repository object + */ + this.getRepository = function() { return repository; }; + + /** + * Gets the Gitana Repository id. + * + * @inner + * + * @returns {String} The Gitana Repository id + */ + this.getRepositoryId = function() { return repository.getId(); }; + + + ////////////////////////////////////////////////////////////////////////////////////////////// + // + // CALL THROUGH TO BASE CLASS (at the end) + // + ////////////////////////////////////////////////////////////////////////////////////////////// + + this.base(repository.getPlatform(), object); + }, + + /** + * @override + */ + clone: function() + { + return this.getFactory().releaseMap(this.getRepository(), this); + }, + + /** + * @param json + */ + buildObject: function(json) + { + return this.getFactory().release(this.getRepository(), json); + } + + }); + +})(window); +(function(window) +{ + Gitana = window.Gitana; + + Gitana.MergeConflictMap = Gitana.AbstractPlatformObjectMap.extend( + /** @lends Gitana.MergeConflictMap.prototype */ + { + /** + * @constructs + * @augments Gitana.AbstractPlatformObjectMap + * + * @class Map of merge conflict objects + * + * @param {Gitana.Repository} repository + * @param {Object} object + */ + constructor: function(repository, object) + { + this.objectType = function() { return "Gitana.MergeConflictMap"; }; + + + ////////////////////////////////////////////////////////////////////////////////////////////// + // + // PRIVILEGED METHODS + // + ////////////////////////////////////////////////////////////////////////////////////////////// + + /** + * Gets the Gitana Repository object. + * + * @inner + * + * @returns {Gitana.Repository} The Gitana Repository object + */ + this.getRepository = function() { return repository; }; + + /** + * Gets the Gitana Repository id. + * + * @inner + * + * @returns {String} The Gitana Repository id + */ + this.getRepositoryId = function() { return repository.getId(); }; + + + ////////////////////////////////////////////////////////////////////////////////////////////// + // + // CALL THROUGH TO BASE CLASS (at the end) + // + ////////////////////////////////////////////////////////////////////////////////////////////// + + this.base(repository.getPlatform(), object); + }, + + /** + * @override + */ + clone: function() + { + return this.getFactory().mergeConflictMap(this.getRepository(), this); + }, + + /** + * @param json + */ + buildObject: function(json) + { + return this.getFactory().mergeConflict(this.getRepository(), json); + } + + }); + +})(window); +(function(window) +{ + Gitana = window.Gitana; + + Gitana.DeletionMap = Gitana.AbstractPlatformObjectMap.extend( + /** @lends Gitana.DeletionMap.prototype */ + { + /** + * @constructs + * @augments Gitana.AbstractPlatformObjectMap + * + * @class Map of deletion objects + * + * @param {Gitana.Branch} branch Gitana branch instance. + * @param {Object} object + */ + constructor: function(branch, object) + { + this.objectType = function() { return "Gitana.DeletionMap"; }; + + + ////////////////////////////////////////////////////////////////////////////////////////////// + // + // PRIVILEGED METHODS + // + ////////////////////////////////////////////////////////////////////////////////////////////// + + /** + * Gets the Gitana Repository object. + * + * @inner + * + * @returns {Gitana.Repository} The Gitana Repository object + */ + this.getRepository = function() { return branch.getRepository(); }; + + /** + * Gets the Gitana Repository id. + * + * @inner + * + * @returns {String} The Gitana Repository id + */ + this.getRepositoryId = function() { return branch.getRepository().getId(); }; + + /** + * Gets the Gitana Branch object. + * + * @inner + * + * @returns {Gitana.Branch} The Gitana Branch object + */ + this.getBranch = function() { return branch; }; + + /** + * Gets the Gitana Branch id. + * + * @inner + * + * @returns {String} The Gitana Branch id + */ + this.getBranchId = function() { return branch.getId(); }; + + + ////////////////////////////////////////////////////////////////////////////////////////////// + // + // CALL THROUGH TO BASE CLASS (at the end) + // + ////////////////////////////////////////////////////////////////////////////////////////////// + + this.base(branch.getPlatform(), object); + }, + + /** + * @override + */ + clone: function() + { + return this.getFactory().deletionMap(this.getBranch(), this); + }, + + /** + * @param json + */ + buildObject: function(json) + { + return this.getFactory().deletion(this.getBranch(), json); + }, + + /** + * Delete + * + * @chained this + * + * @public + */ + del: function() + { + const self = this; + + const uriFunction = function() + { + return self.getBranch().getUri() + "/deletions/delete"; + }; + + return this.subchain().then(function() { + + const nodeIds = this.__keys(); + + return this.chainPost(this, uriFunction, {}, { + "_docs": nodeIds + }); + }); + } + + }); + +})(window); +(function(window) +{ + Gitana = window.Gitana; + + Gitana.TraversalResults = Gitana.AbstractPersistable.extend( + /** @lends Gitana.TraversalResults.prototype */ + { + /** + * @constructs + * @augments Gitana.AbstractPersistable + * + * @class Provides access to traversal results + * + * @param {Gitana.Branch} branch + * @param {Object} object + */ + constructor: function(branch, object) + { + if (!this._nodes) + { + this._nodes = {}; + } + if (!this._associations) + { + this._associations = {}; + } + if (!this._config) + { + this._config = {}; + } + + this.base(branch.getDriver(), object); + + + ////////////////////////////////////////////////////////////////////////////////////////////// + // + // PRIVILEGED METHODS + // + ////////////////////////////////////////////////////////////////////////////////////////////// + + /** + * Gets the Gitana Repository object. + * + * @inner + * + * @returns {Gitana.Repository} The Gitana Repository object + */ + this.getRepository = function() { return branch.getRepository(); }; + + /** + * Gets the Gitana Repository id. + * + * @inner + * + * @returns {String} The Gitana Repository id + */ + this.getRepositoryId = function() { return branch.getRepository().getId(); }; + + /** + * Gets the Gitana Branch object. + * + * @inner + * + * @returns {Gitana.Branch} The Gitana Branch object + */ + this.getBranch = function() { return branch; }; + + /** + * Gets the Gitana Branch id. + * + * @inner + * + * @returns {String} The Gitana Branch id + */ + this.getBranchId = function() { return branch.getId(); }; + }, + + clear: function() + { + // empty the nodes map + Gitana.deleteProperties(this._nodes, true); + + // empty the associations map + Gitana.deleteProperties(this._associations, true); + + // empty the config map + Gitana.deleteProperties(this._config, true); + }, + + /** + * @override + * + * @param response + */ + handleResponse: function(response) + { + this.clear(); + + this.handleSystemProperties(response); + + // copy nodes and associations map values + Gitana.copyInto(this._nodes, response.nodes); + Gitana.copyInto(this._associations, response.associations); + + // copy config + Gitana.copyInto(this._config, response.config); + + // copy center node information + this._config["center"] = response.node; + }, + + /** + * Looks up the node around which this traversal is centered. + */ + center: function() + { + const chainable = this.getFactory().node(this.getBranch()); + + const result = this.subchain(chainable); + + // push our logic to the front + result.subchain(this.getBranch()).readNode(this._config["center"]).then(function() { + result.handleResponse(this); + }); + + return result; + }, + + /** + * Counts the number of nodes in the traversal results + * + * @param callback + */ + nodeCount: function(callback) + { + return this.then(function() { + callback.call(this, Gitana.getNumberOfKeys(this._nodes)); + }); + }, + + /** + * Counts the number of associations in teh traversal results + * + * @param callback + */ + associationCount: function(callback) + { + return this.then(function() { + callback.call(this, Gitana.getNumberOfKeys(this._associations)); + }); + }, + + /** + * Hands back a map of all of the nodes in the traversal results + * + * @chained node map + */ + nodes: function() + { + const self = this; + + // what we're handing back + const result = this.subchain(this.getFactory().nodeMap(this.getBranch())); + + // preload some work and hand back + return result.then(function() { + + const chain = this; + + const response = { + "rows": self._nodes + }; + + chain.handleResponse(response); + }); + }, + + /** + * Hands back a single node + * + * @chained node + * + * @param nodeId + */ + node: function(nodeId) + { + const self = this; + + // hand back a node but preload with work + const result = this.subchain(this.getFactory().node(this.getBranch())); + return result.then(function() { + + const nodeObject = self._nodes[nodeId]; + if (!nodeObject) { + return self.missingNodeError(nodeId); + } + + this.handleResponse(nodeObject); + }); + }, + + /** + * Hands back a map of all of the associations in the traversal results + * + * @chained node map + */ + associations: function() + { + const self = this; + + // what we're handing back + const result = this.subchain(this.getFactory().nodeMap(this.getBranch())); + + // preload some work and hand back + return result.then(function() { + + const chain = this; + + const response = { + "rows": self._associations + }; + + chain.handleResponse(response); + }); + }, + + /** + * Hands back a single association. + * + * @chained association + * + * @param id + */ + association: function(id) + { + const self = this; + + // hand back a node but preload with work + const result = this.subchain(this.getFactory().association(this.getBranch())); + return result.then(function() { + + const associationObject = self._associations[id]; + if (!associationObject) { + return self.missingNodeError(id); + } + + this.handleResponse(associationObject); + }); + } + + }); + +})(window); +(function(window) +{ + Gitana = window.Gitana; + + Gitana.Definition = Gitana.Node.extend( + /** @lends Gitana.Definition.prototype */ + { + /** + * @constructs + * @augments Gitana.Node + * + * @class Definition + * + * @param {Gitana.Branch} branch + * @param {Object} object json object (if no callback required for populating) + */ + constructor: function(branch, object) + { + this.base(branch, object); + + this.objectType = function() { return "Gitana.Definition"; }; + }, + + /** + * @override + */ + clone: function() + { + return this.getFactory().definition(this.getBranch(), this); + }, + + /** + * Acquires a list of associations of type "a:has_form" for this definition. + * + * @chaining node map + * + * @public + */ + listFormAssociations: function() + { + const self = this; + + const uriFunction = function() + { + return self.getUri() + "/forms"; + }; + + const chainable = this.getFactory().nodeMap(this.getBranch()); + return this.chainGet(chainable, uriFunction); + }, + + /** + * Reads a form by form key that is associated to this definition. + * + * @public + * + * @param {String} formKey the form key + */ + readForm: function(formKey) + { + const self = this; + + const uriFunction = function() + { + return self.getUri() + "/forms/" + formKey; + }; + + const chainable = this.getFactory().form(this.getBranch()); + return this.chainGet(chainable, uriFunction); + }, + + /** + * Creates a form and associates it to this definition. + * + * @public + * + * @param {String} formKey the form key + * @param {Object} formObject the object that constitutes the form + * @param {String} formPath optional formPath to pass to create node + */ + createForm: function(formKey, formObject, formPath) + { + const self = this; + + if (typeof(formObject) === "string") + { + formPath = formObject; + formObject = null; + } + + // set up form object + if (!formObject) + { + formObject = {}; + } + formObject["_type"] = "n:form"; + + const chainable = this.getFactory().form(this.getBranch()); + + // subchain that want to hand back + const result = this.subchain(chainable); + + // now push our logic into a subchain that is the first thing in the result + result.subchain(this.getBranch()).createNode(formObject, formPath).then(function() { + const formNode = this; + + // switch to definition node + this.subchain(self).then(function() { + const associationObject = { + "_type": "a:has_form", + "form-key": formKey + }; + this.associate(formNode, associationObject).then(function() { + + const association = this; + + // read back into the form chainable + const uri = "/repositories/" + formNode.getRepositoryId() + "/branches/" + formNode.getBranchId() + "/nodes/" + formNode.getId(); + this.getDriver().gitanaGet(uri, null, {}, function(response) { + + result.handleResponse(response); + association.next(); + }); + + // we manually signal when this then() is done + return false; + }); + }); + }); + + return result; + }, + + /** + * Convenience function to remove a form linked to this definition. + * Note: This doesn't delete the form, it simply unlinks the association. + * + * @chained this + * + * @public + * + * @param {String} formKey the form key + */ + removeFormAssociation: function(formKey) + { + return this.subchain(this).then(function() { + + let association = null; + + this.listFormAssociations().each(function() { + if (this.getFormKey() === formKey) + { + association = this; + } + }).then(function() { + + if (association) + { + this.subchain(association).del(); + } + }); + }); + }, + + /** + * Acquires a list of child definitions. + * + * @param {object} pagination + * + * @chaining node map + * + * @public + */ + listChildDefinitions: function(pagination) + { + const self = this; + + const params = {}; + if (pagination) + { + Gitana.copyInto(params, pagination); + } + + const uriFunction = function() + { + return self.getBranch().getUri() + "/definitions/" + this.getQName() + "/children"; + }; + + const chainable = this.getFactory().nodeMap(this.getBranch()); + return this.chainGet(chainable, uriFunction, params); + } + + }); + + Gitana.ObjectFactory.register("d:type", Gitana.Definition); + Gitana.ObjectFactory.register("d:feature", Gitana.Definition); + Gitana.ObjectFactory.register("d:association", Gitana.Definition); + +})(window); +(function(window) +{ + Gitana = window.Gitana; + + Gitana.Form = Gitana.Node.extend( + /** @lends Gitana.Form.prototype */ + { + /** + * @constructs + * @augments Gitana.Node + * + * @class Form + * + * @param {Gitana.Branch} branch + * @param {Object} object json object (if no callback required for populating) + */ + constructor: function(branch, object) + { + this.base(branch, object); + + this.objectType = function() { return "Gitana.Form"; }; + }, + + /** + * @override + */ + clone: function() + { + return this.getFactory().form(this.getBranch(), this); + }, + + /** + * Gets the engine id for this form. + * + * @public + * + * @returns {String} engine id + */ + getEngineId: function() + { + return this.get("engineId"); + }, + + /** + * Sets the engine id for this form. + * + * @public + * + * @param engineId + */ + setEngineId: function(engineId) + { + this.set("engineId", engineId); + } + + }); + + Gitana.ObjectFactory.register("n:form", Gitana.Form); + +})(window); +(function(window) +{ + Gitana = window.Gitana; + + Gitana.HasFormAssociation = Gitana.Association.extend( + /** @lends Gitana.HasFormAssociation.prototype */ + { + /** + * @constructs + * @augments Gitana.Association + * + * @class Has Form Association + * + * @param {Gitana.Branch} branch + * @param {Object} object json object (if no callback required for populating) + */ + constructor: function(branch, object) + { + this.base(branch, object); + + this.objectType = function() { return "Gitana.HasFormAssociation"; }; + }, + + /** + * @override + */ + clone: function() + { + return new Gitana.HasFormAssociation(this.getBranch(), this); + }, + + /** + * Gets the form key for the association. + * + * @public + * + * @returns {String} form key + */ + getFormKey: function() + { + return this.get("form-key"); + }, + + /** + * Sets the form key for the association. + * + * @public + * + * @param formKey + */ + setFormKey: function(formKey) + { + this.set("form-key", formKey); + } + }); + + Gitana.ObjectFactory.register("a:has_form", Gitana.HasFormAssociation); + +})(window); +(function(window) +{ + Gitana = window.Gitana; + + Gitana.HasTranslationAssociation = Gitana.Association.extend( + /** @lends Gitana.HasTranslationAssociation.prototype */ + { + /** + * @constructs + * @augments Gitana.Association + * + * @class Has Translation Association + * + * @param {Gitana.Branch} branch + * @param {Object} object json object (if no callback required for populating) + */ + constructor: function(branch, object) + { + this.base(branch, object); + + this.objectType = function() { return "Gitana.HasTranslationAssociation"; }; + }, + + /** + * @override + */ + clone: function() + { + return new Gitana.HasTranslationAssociation(this.getBranch(), this); + }, + + /** + * Gets the locale of this association. + * + * @returns {String} locale + */ + getLocale: function() + { + return this.get("locale"); + }, + + /** + * Sets the locale of this association. + * + * @param locale + */ + setLocale: function(locale) + { + this.set("locale", locale); + }, + + /** + * Gets the edition of this association. + * + * @returns {String} edition + */ + getEdition: function() + { + return this.get("edition"); + }, + + /** + * Sets the edition of this association. + * + * @param edition + */ + setEdition: function(edition) + { + this.set("edition", edition); + } + + }); + + Gitana.ObjectFactory.register("a:has_translation", Gitana.HasTranslationAssociation); + +})(window); +(function(window) +{ + Gitana = window.Gitana; + + Gitana.Person = Gitana.Node.extend( + /** @lends Gitana.Person.prototype */ + { + /** + * @constructs + * @augments Gitana.Node + * + * @class Gitana.Person + * + * @param {Gitana.Branch} branch + * @param {Object} [object] json object (if no callback required for populating) + */ + constructor: function(branch, object) + { + this.base(branch, object); + + this.objectType = function() { return "Gitana.Person"; }; + }, + + /** + * @override + */ + clone: function() + { + return new Gitana.Person(this.getBranch(), this); + }, + + getPrincipalName: function() + { + return this.get("principal-name"); + }, + + getPrincipalType: function() + { + return this.get("principal-type"); + }, + + getPrincipalId: function() + { + return this.get("principal-id"); + }, + + getPrincipalDomainId: function() + { + return this.get("principal-domain"); + }, + + /** + * Reads the principal for this person. + * + * @chained domain user + */ + readPrincipal: function() + { + return this.subchain(this.getPlatform()).readDomain(this.getPrincipalDomainId()).readPrincipal(this.getPrincipalId()); + }, + + + + + ////////////////////////////////////////////////////////////////////////////////////////////////// + // + // PROPERTIES + // + ////////////////////////////////////////////////////////////////////////////////////////////////// + + getFirstName: function() + { + return this.get("firstName"); + }, + + setFirstName: function(firstName) + { + this.set("firstName", firstName); + }, + + getLastName: function() + { + return this.get("lastName"); + }, + + setLastName: function(lastName) + { + this.set("lastName", lastName); + }, + + getCompanyName: function() + { + return this.get("companyName"); + }, + + setCompanyName: function(companyName) + { + this.set("companyName", companyName); + }, + + getEmail: function() + { + return this.get("email"); + }, + + setEmail: function(email) + { + this.set("email", email); + }, + + getJobTitle: function() + { + return this.get("jobTitle"); + }, + + setJobTitle: function(jobTitle) + { + this.set("jobTitle", jobTitle); + }, + + getAddress: function() + { + return this.get("address"); + }, + + setAddress: function(address) + { + this.set("address", address); + }, + + getCity: function() + { + return this.get("city"); + }, + + setCity: function(city) + { + this.set("city", city); + }, + + getState: function() + { + return this.get("state"); + }, + + setState: function(state) + { + this.set("state", state); + }, + + getZipcode: function() + { + return this.get("zipcode"); + }, + + setZipcode: function(zipcode) + { + this.set("zipcode", zipcode); + }, + + getPhoneNumber: function() + { + return this.get("phoneNumber"); + }, + + setPhoneNumber: function(phoneNumber) + { + this.set("phoneNumber", phoneNumber); + } + + }); + + Gitana.ObjectFactory.register("n:person", Gitana.Person); + +})(window); +(function(window) +{ + Gitana = window.Gitana; + + Gitana.Vault = Gitana.AbstractPlatformDataStore.extend( + /** @lends Gitana.Vault.prototype */ + { + /** + * @constructs + * @augments Gitana.AbstractPlatformDataStore + * + * @class Vault + * + * @param {Gitana.Platform} platform + * @param {Object} object json object (if no callback required for populating) + */ + constructor: function(platform, object) + { + this.base(platform, object); + + this.objectType = function() { return "Gitana.Vault"; }; + }, + + /** + * @OVERRIDE + */ + getType: function() + { + return Gitana.TypedIDConstants.TYPE_VAULT; + }, + + /** + * @OVERRIDE + */ + getUri: function() + { + return "/vaults/" + this.getId(); + }, + + /** + * @override + */ + clone: function() + { + return this.getFactory().vault(this.getPlatform(), this); + }, + + + + + ////////////////////////////////////////////////////////////////////////////////////////// + // + // ARCHIVES + // + ////////////////////////////////////////////////////////////////////////////////////////// + + /** + * Lists the archives. + * + * @param pagination + * + * @chained archive map + */ + listArchives: function(pagination) + { + const params = {}; + if (pagination) + { + Gitana.copyInto(params, pagination); + } + + const chainable = this.getFactory().archiveMap(this); + return this.chainGet(chainable, this.getUri() + "/archives", params); + }, + + /** + * Reads an archive. + * + * @param archiveId + * + * @chained stack + */ + readArchive: function(archiveId) + { + const chainable = this.getFactory().archive(this); + return this.chainGet(chainable, this.getUri() + "/archives/" + archiveId); + }, + + /** + * Looks up an archive by its identifier information. + * + * @param groupId + * @param artifactId + * @param versionId + * + * @chained stack + */ + lookupArchive: function(groupId, artifactId, versionId) + { + const chainable = this.getFactory().archive(this); + return this.chainGet(chainable, this.getUri() + "/archives/lookup?group=" + groupId + "&artifact=" + artifactId + "&version=" + versionId); + }, + + /** + * Queries for stacks. + * + * @chained stack map + * + * @param {Object} query + * @param {Object} pagination pagination (optional) + */ + queryArchives: function(query, pagination = undefined) + { + const self = this; + + const params = {}; + if (pagination) + { + Gitana.copyInto(params, pagination); + } + + const uriFunction = function() + { + return self.getUri() + "/archives/query"; + }; + + const chainable = this.getFactory().archiveMap(this); + return this.chainPost(chainable, uriFunction, params, query); + }, + + /** + * Performs a bulk check of permissions against permissioned objects of type stack. + * + * Example of checks array: + * + * [{ + * "permissionedId": "", + * "principalId": "", + * "permissionId": "" + * }] + * + * The callback receives an array of results, example: + * + * [{ + * "permissionedId": "", + * "principalId": "", + * "permissionId": "", + * "result": true + * }] + * + * The order of elements in the array will be the same for checks and results. + * + * @param checks + * @param callback + */ + checkArchivePermissions: function(checks, callback) + { + const self = this; + + const uriFunction = function() + { + return self.getUri() + "/archives/permissions/check"; + }; + + const object = { + "checks": checks + }; + + return this.chainPostResponse(this, uriFunction, {}, object).then(function(response) { + callback.call(this, response["results"]); + }); + }, + + /** + * Performs a bulk check of authorities against permissioned objects of type stack. + * + * Example of checks array: + * + * [{ + * "permissionedId": "", + * "principalId": "", + * "authorityId": "" + * }] + * + * The callback receives an array of results, example: + * + * [{ + * "permissionedId": "", + * "principalId": "", + * "authorityId": "", + * "result": true + * }] + * + * The order of elements in the array will be the same for checks and results. + * + * @param checks + * @param callback + */ + checkArchiveAuthorities: function(checks, callback) + { + const self = this; + + const uriFunction = function() + { + return self.getUri() + "/archives/authorities/check"; + }; + + const object = { + "checks": checks + }; + + return this.chainPostResponse(this, uriFunction, {}, object).then(function(response) { + callback.call(this, response["results"]); + }); + } + + }); + +})(window); +(function(window) +{ + Gitana = window.Gitana; + + Gitana.VaultMap = Gitana.AbstractPlatformObjectMap.extend( + /** @lends Gitana.VaultMap.prototype */ + { + /** + * @constructs + * @augments Gitana.AbstractPlatformObjectMap + * + * @class VaultMap + * + * @param {Gitana.Platform} platform Gitana platform + * @param {Object} object + */ + constructor: function(platform, object) + { + this.objectType = function() { return "Gitana.VaultMap"; }; + + + ////////////////////////////////////////////////////////////////////////////////////////////// + // + // CALL THROUGH TO BASE CLASS (at the end) + // + ////////////////////////////////////////////////////////////////////////////////////////////// + + this.base(platform, object); + }, + + /** + * @override + */ + clone: function() + { + return this.getFactory().vaultMap(this.getPlatform(), this); + }, + + /** + * @param json + */ + buildObject: function(json) + { + return this.getFactory().vault(this.getPlatform(), json); + } + + }); + +})(window); +(function(window) +{ + Gitana = window.Gitana; + + Gitana.AbstractVaultObject = Gitana.AbstractPlatformObject.extend( + /** @lends Gitana.AbstractVaultObject.prototype */ + { + /** + * @constructs + * @augments Gitana.AbstractPlatformObject + * + * @class AbstractVaultObject + * + * @param {Gitana.Vault} vault + * @param {Object} object json object (if no callback required for populating) + */ + constructor: function(vault, object) + { + this.base(vault.getPlatform(), object); + + this.objectType = function() { return "Gitana.Archive"; }; + + + + ////////////////////////////////////////////////////////////////////////////////////////////// + // + // PRIVILEGED METHODS + // + ////////////////////////////////////////////////////////////////////////////////////////////// + + /** + * Gets the Gitana Vault object. + * + * @inner + * + * @returns {Gitana.Vault} The Gitana Vault object + */ + this.getVault = function() { return vault; }; + + /** + * Gets the Gitana Vault id. + * + * @inner + * + * @returns {String} The Gitana Vault id + */ + this.getVaultId = function() { return vault.getId(); }; + }, + + /** + * @OVERRIDE + */ + ref: function() + { + return this.getType() + "://" + this.getPlatformId() + "/" + this.getVaultId() + "/" + this.getId(); + } + + }); + +})(window); +(function(window) +{ + Gitana = window.Gitana; + + Gitana.Archive = Gitana.AbstractVaultObject.extend( + /** @lends Gitana.Archive.prototype */ + { + /** + * @constructs + * @augments Gitana.AbstractVaultObject + * + * @class Archive + * + * @param {Gitana.Vault} vault + * @param {Object} object json object (if no callback required for populating) + */ + constructor: function(vault, object) + { + this.base(vault, object); + + this.objectType = function() { return "Gitana.Archive"; }; + }, + + /** + * @OVERRIDE + */ + getType: function() + { + return Gitana.TypedIDConstants.TYPE_ARCHIVE; + }, + + /** + * @OVERRIDE + */ + getUri: function() + { + return "/vaults/" + this.getVaultId() + "/archives/" + this.getId(); + }, + + /** + * @override + */ + clone: function() + { + return this.getFactory().archive(this.getVault(), this); + }, + + /** + * Gets the URI used to download the archive + */ + getDownloadUri: function() + { + return this.getProxiedUri() + "/download"; + }, + + + + ////////////////////////////////////////////////////////////////////////////////////////// + // + // ATTACHMENTS + // + ////////////////////////////////////////////////////////////////////////////////////////// + + /** + * Hands back an attachments map. + * + * @chained attachment map + * + * @param local + * + * @public + */ + listAttachments: Gitana.Methods.listAttachments(), + + /** + * Picks off a single attachment + * + * @chained attachment + * + * @param attachmentId + */ + attachment: function(attachmentId) + { + return this.listAttachments().select(attachmentId); + }, + + /** + * Creates an attachment. + * + * When using this method from within the JS driver, it really only works for text-based content such + * as JSON or text. + * + * @chained attachment + * + * @param attachmentId (use null or false for default attachment) + * @param contentType + * @param data + */ + attach: Gitana.Methods.attach(), + + /** + * Deletes an attachment. + * + * @param attachmentId + */ + unattach: Gitana.Methods.unattach(), + + /** + * Generates a URI to a preview resource. + */ + getPreviewUri: Gitana.Methods.getPreviewUri(), + + /** + * Publishes the archive. + * + * @chained this + * + * @public + */ + publish: function() + { + const self = this; + + const uriFunction = function() + { + return self.getUri() + "/publish"; + }; + + return this.chainPostEmpty(null, uriFunction); + }, + + /** + * Unpublishes the archive. + * + * @chained this + * + * @public + */ + unpublish: function() + { + const self = this; + + const uriFunction = function() + { + return self.getUri() + "/unpublish"; + }; + + return this.chainPostEmpty(null, uriFunction); + } + + }); + +})(window); +(function(window) +{ + Gitana = window.Gitana; + + Gitana.ArchiveMap = Gitana.AbstractPlatformObjectMap.extend( + /** @lends Gitana.ArchiveMap.prototype */ + { + /** + * @constructs + * @augments Gitana.AbstractPlatformObjectMap + * + * @class ArchiveMap + * + * @param {Gitana.Vault} vault Gitana vault instance. + * @param {Object} object + */ + constructor: function(vault, object) + { + this.objectType = function() { return "Gitana.ArchiveMap"; }; + + + ////////////////////////////////////////////////////////////////////////////////////////////// + // + // PRIVILEGED METHODS + // + ////////////////////////////////////////////////////////////////////////////////////////////// + + /** + * Gets the Gitana Vault object. + * + * @inner + * + * @returns {Gitana.Vault} The Gitana Vault object + */ + this.getVault = function() { return vault; }; + + /** + * Gets the Gitana Vault id. + * + * @inner + * + * @returns {String} The Gitana Vault id + */ + this.getVaultId = function() { return vault.getId(); }; + + + ////////////////////////////////////////////////////////////////////////////////////////////// + // + // CALL THROUGH TO BASE CLASS (at the end) + // + ////////////////////////////////////////////////////////////////////////////////////////////// + + this.base(vault.getPlatform(), object); + }, + + /** + * @override + */ + clone: function() + { + return this.getFactory().archiveMap(this.getVault(), this); + }, + + /** + * @param json + */ + buildObject: function(json) + { + return this.getFactory().archive(this.getVault(), json); + } + + }); + +})(window); +(function(window) +{ + Gitana = window.Gitana; + + Gitana.WebHost = Gitana.AbstractPlatformDataStore.extend( + /** @lends Gitana.WebHost.prototype */ + { + /** + * @constructs + * @augments Gitana.AbstractPlatformObject + * + * @class WebHost + * + * @param {Gitana.Platform} platform + * @param {Object} object json object (if no callback required for populating) + */ + constructor: function(platform, object) + { + this.objectType = function() { return "Gitana.WebHost"; }; + + this.base(platform, object); + }, + + /** + * @OVERRIDE + */ + getUri: function() + { + return "/webhosts/" + this.getId(); + }, + + /** + * @OVERRIDE + */ + getType: function() + { + return Gitana.TypedIDConstants.TYPE_WEB_HOST; + }, + + /** + * @override + */ + clone: function() + { + return this.getFactory().webhost(this.getPlatform(), this); + }, + + getUrlPatterns: function() + { + return this.get("urlPatterns"); + }, + + + ////////////////////////////////////////////////////////////////////////////////////////// + // + // AUTO CLIENT MAPPINGS + // + ////////////////////////////////////////////////////////////////////////////////////////// + + /** + * Create auto client mapping + * + * @chained auto client mapping + * + * @param host + * @param applicationId + * @param clientKey + * @param authGrantKey + * @param {Object} object JSON object + */ + createAutoClientMapping: function(host, applicationId, clientKey, authGrantKey, object) + { + if (!object) + { + object = {}; + } + + if (!Gitana.isString(applicationId)) + { + applicationId = applicationId.getId(); + } + + if (!Gitana.isString(clientKey)) + { + clientKey = clientKey.getKey(); + } + + if (!Gitana.isString(authGrantKey)) + { + authGrantKey = authGrantKey.getKey(); + } + + object["host"] = host; + object["applicationId"] = applicationId; + object["clientKey"] = clientKey; + object["authGrantKey"] = authGrantKey; + + const uriFunction = function() + { + return "/webhosts/" + this.getId() + "/autoclientmappings"; + }; + + const chainable = this.getFactory().autoClientMapping(this); + return this.chainCreate(chainable, object, uriFunction); + }, + + /** + * Lists the auto client mappings. + * + * @param pagination + * + * @chained auto client mappings map + */ + listAutoClientMappings: function(pagination) + { + const params = {}; + if (pagination) + { + Gitana.copyInto(params, pagination); + } + + const uriFunction = function() + { + return "/webhosts/" + this.getId() + "/autoclientmappings"; + }; + + const chainable = this.getFactory().autoClientMappingMap(this); + return this.chainGet(chainable, uriFunction, params); + }, + + /** + * Reads an auto client mapping. + * + * @param autoClientMappingId + * + * @chained auto client mapping + */ + readAutoClientMapping: function(autoClientMappingId) + { + const self = this; + + const uriFunction = function() + { + return self.getUri() + "/autoclientmappings/" + autoClientMappingId; + }; + + const chainable = this.getFactory().autoClientMapping(this); + return this.chainGet(chainable, uriFunction); + }, + + /** + * Queries for auto client mappings. + * + * @chained auto client mappings map + * + * @param {Object} query + * @param {Object} pagination pagination (optional) + */ + queryAutoClientMappings: function(query, pagination) + { + const self = this; + + const params = {}; + if (pagination) + { + Gitana.copyInto(params, pagination); + } + + const uriFunction = function() + { + return self.getUri() + "/autoclientmappings/query"; + }; + + const chainable = this.getFactory().autoClientMappingMap(this); + return this.chainPost(chainable, uriFunction, params, query); + }, + + /** + * Performs a bulk check of permissions against permissioned objects of type stack. + * + * Example of checks array: + * + * [{ + * "permissionedId": "", + * "principalId": "", + * "permissionId": "" + * }] + * + * The callback receives an array of results, example: + * + * [{ + * "permissionedId": "", + * "principalId": "", + * "permissionId": "", + * "result": true + * }] + * + * The order of elements in the array will be the same for checks and results. + * + * @param checks + * @param callback + */ + checkAutoClientMappingsPermissions: function(checks, callback) + { + const self = this; + + const uriFunction = function() + { + return self.getUri() + "/autoclientmappings/permissions/check"; + }; + + const object = { + "checks": checks + }; + + return this.chainPostResponse(this, uriFunction, {}, object).then(function(response) { + callback.call(this, response["results"]); + }); + }, + + /** + * Performs a bulk check of authorities against permissioned objects of type stack. + * + * Example of checks array: + * + * [{ + * "permissionedId": "", + * "principalId": "", + * "authorityId": "" + * }] + * + * The callback receives an array of results, example: + * + * [{ + * "permissionedId": "", + * "principalId": "", + * "authorityId": "", + * "result": true + * }] + * + * The order of elements in the array will be the same for checks and results. + * + * @param checks + * @param callback + */ + checkAutoClientMappingsAuthorities: function(checks, callback) + { + const self = this; + + const uriFunction = function() + { + return self.getUri() + "/autoclientmappings/authorities/check"; + }; + + const object = { + "checks": checks + }; + + return this.chainPostResponse(this, uriFunction, {}, object).then(function(response) { + callback.call(this, response["results"]); + }); + }, + + + + + ////////////////////////////////////////////////////////////////////////////////////////// + // + // TRUSTED DOMAIN MAPPINGS + // + ////////////////////////////////////////////////////////////////////////////////////////// + + /** + * Create trusted domain mapping + * + * @chained trusted domain mapping + * + * @param host + * @param scope + * @param platformId + * @param {Object} object JSON object + */ + createTrustedDomainMapping: function(host, scope, platformId, object) + { + if (!object) + { + object = {}; + } + + if (!Gitana.isString(platformId)) + { + platformId = platformId.getId(); + } + + object["host"] = host; + object["scope"] = scope; + object["platformId"] = platformId; + + const uriFunction = function() + { + return "/webhosts/" + this.getId() + "/trusteddomainmappings"; + }; + + const chainable = this.getFactory().trustedDomainMapping(this); + return this.chainCreate(chainable, object, uriFunction); + }, + + /** + * Lists the trusted domain mappings. + * + * @param pagination + * + * @chained trusted domain mappings map + */ + listTrustedDomainMappings: function(pagination) + { + const params = {}; + if (pagination) + { + Gitana.copyInto(params, pagination); + } + + const uriFunction = function() + { + return "/webhosts/" + this.getId() + "/trusteddomainmappings"; + }; + + const chainable = this.getFactory().trustedDomainMappingMap(this); + return this.chainGet(chainable, uriFunction, params); + }, + + /** + * Reads a trusted domain mapping. + * + * @param trustedDomainMappingId + * + * @chained trusted domain mapping + */ + readTrustedDomainMapping: function(trustedDomainMappingId) + { + const self = this; + + const uriFunction = function() + { + return self.getUri() + "/trusteddomainmappings/" + trustedDomainMappingId; + }; + + const chainable = this.getFactory().trustedDomainMapping(this); + return this.chainGet(chainable, uriFunction); + }, + + /** + * Queries for trusted domain mappings. + * + * @chained trusted domain mappings map + * + * @param {Object} query + * @param {Object} pagination pagination (optional) + */ + queryTrustedDomainMappings: function(query, pagination) + { + const self = this; + + const params = {}; + if (pagination) + { + Gitana.copyInto(params, pagination); + } + + const uriFunction = function() + { + return self.getUri() + "/trusteddomainmappings/query"; + }; + + const chainable = this.getFactory().trustedDomainMappingMap(this); + return this.chainPost(chainable, uriFunction, params, query); + }, + + /** + * Performs a bulk check of permissions against permissioned objects of type stack. + * + * Example of checks array: + * + * [{ + * "permissionedId": "", + * "principalId": "", + * "permissionId": "" + * }] + * + * The callback receives an array of results, example: + * + * [{ + * "permissionedId": "", + * "principalId": "", + * "permissionId": "", + * "result": true + * }] + * + * The order of elements in the array will be the same for checks and results. + * + * @param checks + * @param callback + */ + checkTrustedDomainMappingsPermissions: function(checks, callback) + { + const self = this; + + const uriFunction = function() + { + return self.getUri() + "/trusteddomainmappings/permissions/check"; + }; + + const object = { + "checks": checks + }; + + return this.chainPostResponse(this, uriFunction, {}, object).then(function(response) { + callback.call(this, response["results"]); + }); + }, + + /** + * Performs a bulk check of authorities against permissioned objects of type stack. + * + * Example of checks array: + * + * [{ + * "permissionedId": "", + * "principalId": "", + * "authorityId": "" + * }] + * + * The callback receives an array of results, example: + * + * [{ + * "permissionedId": "", + * "principalId": "", + * "authorityId": "", + * "result": true + * }] + * + * The order of elements in the array will be the same for checks and results. + * + * @param checks + * @param callback + */ + checkTrustedDomainMappingsAuthorities: function(checks, callback) + { + const self = this; + + const uriFunction = function() + { + return self.getUri() + "/trusteddomainmappings/authorities/check"; + }; + + const object = { + "checks": checks + }; + + return this.chainPostResponse(this, uriFunction, {}, object).then(function(response) { + callback.call(this, response["results"]); + }); + }, + + + ////////////////////////////////////////////////////////////////////////////////////////// + // + // DEPLOYED APPLICATIONS + // + ////////////////////////////////////////////////////////////////////////////////////////// + + /** + * Lists the deployed applications. + * + * @param pagination + * + * @chained deployed application mappings map + */ + listDeployedApplications: function(pagination) + { + const params = {}; + if (pagination) + { + Gitana.copyInto(params, pagination); + } + + const uriFunction = function() + { + return "/webhosts/" + this.getId() + "/applications"; + }; + + const chainable = this.getFactory().deployedApplicationMap(this); + return this.chainGet(chainable, uriFunction, params); + }, + + /** + * Reads a deployed application. + * + * @param deployedApplicationId + * + * @chained deployed application + */ + readDeployedApplication: function(deployedApplicationId) + { + const uriFunction = function() + { + return "/webhosts/" + this.getId() + "/applications/" + deployedApplicationId; + }; + + const chainable = this.getFactory().deployedApplication(this); + return this.chainGet(chainable, uriFunction); + }, + + /** + * Queries for deployed applications + * + * @chained deployed applications map + * + * @param {Object} query + * @param {Object} pagination pagination (optional) + */ + queryDeployedApplications: function(query, pagination) + { + const self = this; + + const params = {}; + if (pagination) + { + Gitana.copyInto(params, pagination); + } + + const uriFunction = function() + { + return self.getUri() + "/applications/query"; + }; + + const chainable = this.getFactory().deployedApplicationMap(this); + return this.chainPost(chainable, uriFunction, params, query); + }, + + /** + * Performs a bulk check of permissions against permissioned objects of type stack. + * + * Example of checks array: + * + * [{ + * "permissionedId": "", + * "principalId": "", + * "permissionId": "" + * }] + * + * The callback receives an array of results, example: + * + * [{ + * "permissionedId": "", + * "principalId": "", + * "permissionId": "", + * "result": true + * }] + * + * The order of elements in the array will be the same for checks and results. + * + * @param checks + * @param callback + */ + checkDeployedApplicationsPermissions: function(checks, callback) + { + const self = this; + + const uriFunction = function() + { + return self.getUri() + "/applications/permissions/check"; + }; + + const object = { + "checks": checks + }; + + return this.chainPostResponse(this, uriFunction, {}, object).then(function(response) { + callback.call(this, response["results"]); + }); + }, + + /** + * Performs a bulk check of authorities against permissioned objects of type stack. + * + * Example of checks array: + * + * [{ + * "permissionedId": "", + * "principalId": "", + * "authorityId": "" + * }] + * + * The callback receives an array of results, example: + * + * [{ + * "permissionedId": "", + * "principalId": "", + * "authorityId": "", + * "result": true + * }] + * + * The order of elements in the array will be the same for checks and results. + * + * @param checks + * @param callback + */ + checkDeployedApplicationsAuthorities: function(checks, callback) + { + const self = this; + + const uriFunction = function() + { + return self.getUri() + "/applications/authorities/check"; + }; + + const object = { + "checks": checks + }; + + return this.chainPostResponse(this, uriFunction, {}, object).then(function(response) { + callback.call(this, response["results"]); + }); + } + + }); + +})(window); +(function(window) +{ + Gitana = window.Gitana; + + Gitana.WebHostMap = Gitana.AbstractPlatformObjectMap.extend( + /** @lends Gitana.WebHostMap.prototype */ + { + /** + * @constructs + * @augments Gitana.AbstractPlatformObjectMap + * + * @class Map of web host objects + * + * @param {Gitana.Platform} platform Gitana platform + * @param {Object} object + */ + constructor: function(platform, object) + { + this.objectType = function() { return "Gitana.WebHostMap"; }; + + + ////////////////////////////////////////////////////////////////////////////////////////////// + // + // CALL THROUGH TO BASE CLASS (at the end) + // + ////////////////////////////////////////////////////////////////////////////////////////////// + + this.base(platform, object); + }, + + /** + * @override + */ + clone: function() + { + return this.getFactory().webhostMap(this.getPlatform(), this); + }, + + /** + * @param json + */ + buildObject: function(json) + { + return this.getFactory().webhost(this.getPlatform(), json); + } + + }); + +})(window); +(function(window) +{ + Gitana = window.Gitana; + + Gitana.AbstractWebHostObject = Gitana.AbstractPlatformObject.extend( + /** @lends Gitana.AbstractWebHostObject.prototype */ + { + /** + * @constructs + * @augments Gitana.AbstractPlatformObject + * + * @class AbstractWebHostObject + * + * @param {Gitana.WebHost} webhost + * @param {Object} object json object (if no callback required for populating) + */ + constructor: function(webhost, object) + { + this.base(webhost.getPlatform(), object); + + + ////////////////////////////////////////////////////////////////////////////////////////////// + // + // PRIVILEGED METHODS + // + ////////////////////////////////////////////////////////////////////////////////////////////// + + /** + * Gets the Gitana Web Host object. + * + * @inner + * + * @returns {Gitana.WebHost} The Gitana Web Host object + */ + this.getWebHost = function() { return webhost; }; + + /** + * Gets the Gitana Web Host id. + * + * @inner + * + * @returns {String} The Gitana Web Host id + */ + this.getWebHostId = function() { return webhost.getId(); }; + }, + + /** + * @OVERRIDE + */ + ref: function() + { + return this.getType() + "://" + this.getPlatformId() + "/" + this.getWebHostId() + "/" + this.getId(); + } + + }); + +})(window); +(function(window) +{ + Gitana = window.Gitana; + + Gitana.AutoClientMapping = Gitana.AbstractWebHostObject.extend( + /** @lends Gitana.AutoClientMapping.prototype */ + { + /** + * @constructs + * @augments Gitana.AbstractWebHostObject + * + * @class AutoClientMapping + * + * @param {Gitana.WebHost} webhost + * @param {Object} object json object (if no callback required for populating) + */ + constructor: function(webhost, object) + { + this.base(webhost, object); + + this.objectType = function() { return "Gitana.AutoClientMapping"; }; + }, + + /** + * @override + */ + clone: function() + { + return this.getFactory().autoClientMapping(this.getWebHost(), this); + }, + + /** + * @OVERRIDE + */ + getType: function() + { + return Gitana.TypedIDConstants.TYPE_AUTO_CLIENT_MAPPING; + }, + + /** + * @OVERRIDE + */ + getUri: function() + { + return "/webhosts/" + this.getWebHostId() + "/autoclientmappings/" + this.getId(); + }, + + getSourceUri: function() + { + return this.get("uri"); + }, + + getTargetApplicationId: function() + { + return this.get("applicationId"); + }, + + getTargetApplicationKey: function() + { + return this.get("applicationKey"); + }, + + getTargetClientKey: function() + { + return this.get("clientKey"); + }, + + getTargetTenantId: function() + { + return this.get("tenantId"); + }, + + getAutoManage: function() + { + return this.get("automanage"); + } + }); + +})(window); +(function(window) +{ + Gitana = window.Gitana; + + Gitana.TrustedDomainMappingMap = Gitana.AbstractPlatformObjectMap.extend( + /** @lends Gitana.TrustedDomainMappingMap.prototype */ + { + /** + * @constructs + * @augments Gitana.AbstractPlatformObjectMap + * + * @class TrustedDomainMappingMap + * + * @param {Gitana.WebHost} webhost Gitana Web Host instance. + * @param {Object} object + */ + constructor: function(webhost, object) + { + this.objectType = function() { return "Gitana.TrustedDomainMappingMap"; }; + + + ////////////////////////////////////////////////////////////////////////////////////////////// + // + // PRIVILEGED METHODS + // + ////////////////////////////////////////////////////////////////////////////////////////////// + + /** + * Gets the Gitana Web Host object. + * + * @inner + * + * @returns {Gitana.WebHost} The Gitana Web Host object + */ + this.getWebHost = function() { return webhost; }; + + /** + * Gets the Gitana Web Host id. + * + * @inner + * + * @returns {String} The Gitana Web Host id + */ + this.getWebHostId = function() { return webhost.getId(); }; + + + ////////////////////////////////////////////////////////////////////////////////////////////// + // + // CALL THROUGH TO BASE CLASS (at the end) + // + ////////////////////////////////////////////////////////////////////////////////////////////// + + this.base(webhost.getPlatform(), object); + }, + + /** + * @override + */ + clone: function() + { + return this.getFactory().trustedDomainMappingMap(this.getWebHost(), this); + }, + + /** + * @param json + */ + buildObject: function(json) + { + return this.getFactory().trustedDomainMapping(this.getWebHost(), json); + } + + }); + +})(window); +(function(window) +{ + Gitana = window.Gitana; + + Gitana.TrustedDomainMapping = Gitana.AbstractWebHostObject.extend( + /** @lends Gitana.TrustedDomainMapping.prototype */ + { + /** + * @constructs + * @augments Gitana.AbstractWebHostObject + * + * @class TrustedDomainMapping + * + * @param {Gitana.WebHost} webhost + * @param {Object} object json object (if no callback required for populating) + */ + constructor: function(webhost, object) + { + this.base(webhost, object); + + this.objectType = function() { return "Gitana.TrustedDomainMapping"; }; + }, + + /** + * @override + */ + clone: function() + { + return this.getFactory().trustedDomainMapping(this.getWebHost(), this); + }, + + /** + * @OVERRIDE + */ + getType: function() + { + return Gitana.TypedIDConstants.TYPE_TRUSTED_DOMAIN_MAPPING; + }, + + /** + * @OVERRIDE + */ + getUri: function() + { + return "/webhosts/" + this.getWebHostId() + "/trusteddomainmappings/" + this.getId(); + } + }); + +})(window); +(function(window) +{ + Gitana = window.Gitana; + + Gitana.AutoClientMappingMap = Gitana.AbstractPlatformObjectMap.extend( + /** @lends Gitana.AutoClientMappingMap.prototype */ + { + /** + * @constructs + * @augments Gitana.AbstractPlatformObjectMap + * + * @class AutoClientMappingMap + * + * @param {Gitana.WebHost} webhost Gitana Web Host instance. + * @param {Object} object + */ + constructor: function(webhost, object) + { + this.objectType = function() { return "Gitana.AutoClientMappingMap"; }; + + + ////////////////////////////////////////////////////////////////////////////////////////////// + // + // PRIVILEGED METHODS + // + ////////////////////////////////////////////////////////////////////////////////////////////// + + /** + * Gets the Gitana Web Host object. + * + * @inner + * + * @returns {Gitana.WebHost} The Gitana Web Host object + */ + this.getWebHost = function() { return webhost; }; + + /** + * Gets the Gitana Web Host id. + * + * @inner + * + * @returns {String} The Gitana Web Host id + */ + this.getWebHostId = function() { return webhost.getId(); }; + + + ////////////////////////////////////////////////////////////////////////////////////////////// + // + // CALL THROUGH TO BASE CLASS (at the end) + // + ////////////////////////////////////////////////////////////////////////////////////////////// + + this.base(webhost.getPlatform(), object); + }, + + /** + * @override + */ + clone: function() + { + return this.getFactory().autoClientMappingMap(this.getWebHost(), this); + }, + + /** + * @param json + */ + buildObject: function(json) + { + return this.getFactory().autoClientMapping(this.getWebHost(), json); + } + + }); + +})(window); +(function(window) +{ + Gitana = window.Gitana; + + Gitana.DeployedApplication = Gitana.AbstractWebHostObject.extend( + /** @lends Gitana.DeployedApplication.prototype */ + { + /** + * @constructs + * @augments Gitana.AbstractWebHostObject + * + * @class DeployedApplication + * + * @param {Gitana.WebHost} webhost + * @param {Object} object json object (if no callback required for populating) + */ + constructor: function(webhost, object) + { + this.base(webhost, object); + + this.objectType = function() { return "Gitana.DeployedApplication"; }; + }, + + /** + * @override + */ + clone: function() + { + return this.getFactory().deployedApplication(this.getWebHost(), this); + }, + + /** + * @OVERRIDE + */ + getType: function() + { + return Gitana.TypedIDConstants.TYPE_DEPLOYED_APPLICATION; + }, + + /** + * @OVERRIDE + */ + getUri: function() + { + return "/webhosts/" + this.getWebHostId() + "/applications/" + this.getId(); + }, + + + + ////////////////////////////////////////////////////////////////////////////////////////// + // + // DEPLOYMENT + // + ////////////////////////////////////////////////////////////////////////////////////////// + + /** + * Undeploys the deployed application. + * + * @chained deployed application + */ + undeploy: function() + { + const uriFunction = function() + { + return this.getUri() + "/undeploy"; + }; + + // NOTE: pass control back to the web host + return this.chainPostEmpty(this.getWebHost(), uriFunction); + }, + + /** + * Redeploys the deployed application. + * + * @chained deployed application + */ + redeploy: function() + { + const uriFunction = function() + { + return this.getUri() + "/redeploy"; + }; + + // NOTE: pass control back to the web host + return this.chainPostEmpty(this.getWebHost(), uriFunction); + }, + + /** + * Starts the deployed application. + * + * @chained deployed application + */ + start: function() + { + const uriFunction = function() + { + return this.getUri() + "/start"; + }; + + // NOTE: pass control back to the web host + return this.chainPostEmpty(this.getWebHost(), uriFunction); + }, + + /** + * Stops the deployed application. + * + * @chained deployed application + */ + stop: function() + { + const uriFunction = function() + { + return this.getUri() + "/stop"; + }; + + // NOTE: pass control back to the web host + return this.chainPostEmpty(this.getWebHost(), uriFunction); + }, + + /** + * Undeploys the deployed application. + * + * @chained deployed application + */ + restart: function() + { + const uriFunction = function() + { + return this.getUri() + "/restart"; + }; + + // NOTE: pass control back to the web host + return this.chainPostEmpty(this.getWebHost(), uriFunction); + } + + + }); + +})(window); +(function(window) +{ + Gitana = window.Gitana; + + Gitana.DeployedApplicationMap = Gitana.AbstractPlatformObjectMap.extend( + /** @lends Gitana.DeployedApplicationMap.prototype */ + { + /** + * @constructs + * @augments Gitana.AbstractPlatformObjectMap + * + * @class DeployedApplicationMap + * + * @param {Gitana.WebHost} webhost Gitana Web Host instance. + * @param {Object} object + */ + constructor: function(webhost, object) + { + this.objectType = function() { return "Gitana.DeployedApplicationMap"; }; + + + ////////////////////////////////////////////////////////////////////////////////////////////// + // + // PRIVILEGED METHODS + // + ////////////////////////////////////////////////////////////////////////////////////////////// + + /** + * Gets the Gitana Web Host object. + * + * @inner + * + * @returns {Gitana.WebHost} The Gitana Web Host object + */ + this.getWebHost = function() { return webhost; }; + + /** + * Gets the Gitana Web Host id. + * + * @inner + * + * @returns {String} The Gitana Web Host id + */ + this.getWebHostId = function() { return webhost.getId(); }; + + + ////////////////////////////////////////////////////////////////////////////////////////////// + // + // CALL THROUGH TO BASE CLASS (at the end) + // + ////////////////////////////////////////////////////////////////////////////////////////////// + + this.base(webhost.getPlatform(), object); + }, + + /** + * @override + */ + clone: function() + { + return this.getFactory().deployedApplicationMap(this.getWebHost(), this); + }, + + /** + * @param json + */ + buildObject: function(json) + { + return this.getFactory().deployedApplication(this.getWebHost(), json); + } + + }); + +})(window); +(function(window) { +/** + * @ignore + */ + Gitana = window.Gitana; + + Gitana.Context = Gitana.Chainable.extend( + /** @lends Gitana.Context.prototype */ + { + /** + * @constructs + * @augments Gitana.Chainable + * + * @class Utility class for providing Gitana context + * + * @param {Object} configs Configuration parameters + */ + constructor: function(configs) { + this.base(new Gitana(configs['driver'] ? configs['driver'] : {})); + + // cache + if (!this.cache) { + this.cache = {}; + } + this.cache["repository"] = null; + this.cache["branch"] = null; + this.cache["platform"] = null; + + /////////////////////////////////////////////////////////////////////////////////////////////////////// + // + // privileged methods + // + /////////////////////////////////////////////////////////////////////////////////////////////////////// + + this.getConfigs = function() { + return configs; + }; + + this.getRepositoryConfigs = function() { + let repositoryConfigs = configs['repository']; + if (typeof repositoryConfigs === "string") { + repositoryConfigs = { + "repository" : repositoryConfigs + }; + } + return repositoryConfigs; + }; + + this.getBranchConfigs = function() { + let branchConfigs = configs['branch'] ? configs['branch'] : 'master'; + if (typeof branchConfigs === "string") { + if (branchConfigs === 'master') { + branchConfigs = { + 'type' : 'MASTER' + }; + } else { + branchConfigs = { + "_doc" : branchConfigs + }; + } + } + return branchConfigs; + }; + + this.getUserConfigs = function() { + return configs['user']; + }; + + this.getDriverConfigs = function() { + return configs['driver']; + }; + }, + + platform: function(platform) + { + if (platform || platform === null) { + this.cache.platform = platform; + } + + return this.cache.platform ? Chain(this.cache.platform) : null; + }, + + repository: function(repository) + { + if (repository || repository === null) { + this.cache.repository = repository; + } + + return this.cache.repository ? Chain(this.cache.repository) : null; + }, + + branch: function(branch) + { + if (branch || branch === null) { + this.cache.branch = branch; + } + + return this.cache.branch ? Chain(this.cache.branch) : null; + }, + + /** + * Hands back an initialized version of the Gitana Context object + * + * @chained gitana context + */ + init: function () { + + const self = this; + + const loadPlatform = function(successCallback, errorCallback) + { + if (!self.platform()) + { + const authentication = self.getConfigs()["authentication"]; + + self.getDriver().authenticate(authentication, function(http) { + if (errorCallback) { + errorCallback({ + 'message': 'Failed to login Gitana.', + 'reason': 'INVALID_LOGIN', + 'error': http + }); + } + }).then(function() { + + self.platform(this); + + // now move on to repository + loadRepository(successCallback, errorCallback); + }); + } + else + { + loadRepository(successCallback, errorCallback); + } + }; + + const loadRepository = function(successCallback, errorCallback) + { + if (!self.repository()) + { + self.platform().trap(function(error) { + if (errorCallback) { + errorCallback({ + 'message': 'Failed to get repository', + 'error': error + }); + } + }).queryRepositories(self.getRepositoryConfigs()).count(function(count) { + if (errorCallback) { + if (count === 0) { + errorCallback({ + 'message': 'Cannot find any repository' + }); + } + if (count > 1) { + errorCallback({ + 'message': 'Found more than one repository' + }); + } + } + }).keepOne().then(function() { + + self.repository(this); + + // now move on to branch + loadBranch(successCallback, errorCallback); + }); + } + else + { + loadBranch(successCallback, errorCallback); + } + }; + + const loadBranch = function(successCallback, errorCallback) + { + if (!self.branch()) + { + self.repository().trap(function(error) { + if (errorCallback) { + errorCallback({ + 'message': 'Failed to get branch', + 'error': error + }); + } + }).queryBranches(self.getBranchConfigs()).count(function(count) { + if (errorCallback) { + if (count === 0) { + errorCallback({ + 'message': 'Cannot find any branch' + }); + } + if (count > 1) { + errorCallback({ + 'message': 'Found more than one branch' + }); + } + } + }).keepOne().then(function() { + + self.branch(this); + + // now fire the success callback + successCallback.call(); + }); + } + else + { + // fire the success callback + successCallback.call(); + } + }; + + // we hand back a chained version of ourselves + const result = Chain(this); + + // preload work onto the chain + return result.subchain().then(function() { + + const chain = this; + + loadPlatform(function() { + + // success, advance chain manually + chain.next(); + + }, function(err) { + + const errorCallback = self.getConfigs()['error']; + if (errorCallback) + { + errorCallback.call(self, err); + } + + }); + + // return false so that the chain doesn't complete until we manually complete it + return false; + }); + } + }); + + /** + * Static helper function to build and init a new context. + * + * @param config + */ + Gitana.Context.create = function(config) + { + const context = new Gitana.Context(config); + return context.init(); + }; + +})(window);(function(window) +{ + Gitana = window.Gitana; + + Gitana.AppHelper = Gitana.AbstractObject.extend( + /** @lends Gitana.AppHelper.prototype */ + { + /** + * @constructs + * @augments Gitana.AbstractObject + * + * @class AppHelper + * + * @param {Gitana.Platform} platform + * @param {object} config the configuration object (.application) + */ + constructor: function(platform, config) + { + this.objectType = function() { return "Gitana.AppHelper"; }; + + this.base(platform.getDriver()); + + this.getPlatform = function() { + return platform; + }; + + this.getPlatformId = function() { + return platform.getId(); + }; + + this.getApplicationId = function() { + return config["application"]; + }; + + this.cache = Gitana.MemoryCache(); + + this.chainedCacheItem = function(key) + { + let chained = null; + + if (this.cache(key)) + { + chained = Chain(this.cache(key)); + } + + return chained; + }; + }, + + init: function(callback) + { + const self = this; + + const p = function(application) + { + // THIS = application + + const projectId = application["projectId"]; + if (projectId) + { + // read the project + Chain(self.getPlatform()).trap(function() { + + // could not find the project for the application + // this is fine... we are done + callback(); + + }).readProject(projectId).then(function() { + + self.cache("project", this); + + callback(); + + }); + } + else + { + callback(); + } + }; + + Chain(self.getPlatform()).trap(function(err) { + + // ERROR: application not found + + callback(err); + + }).readApplication(self.getApplicationId()).then(function() { + self.cache("application", this); + + const application = this; + + this.subchain(self.getPlatform()).trap(function() { + + // could not locate the stack for the application + // this is perfectly fine (just means an application isn't allocated to a stack) + p(application); + + }).findStackForDataStore(Gitana.TypedIDConstants.TYPE_APPLICATION, self.getApplicationId()).then(function() { + + // this = stack + self.cache("stack", this); + + this.listDataStores().each(function(key) { + this["_doc"] = this["datastoreId"]; + delete this["datastoreTypeId"]; + self.cache("stack.datastore." + key, this); + }); + + this.then(function() { + p(application); + }); + }); + + }); + }, + + platform: function() + { + return Chain(this.getPlatform()); + }, + + application: function() + { + return this.chainedCacheItem("application"); + }, + + stack: function() + { + return this.chainedCacheItem("stack"); + }, + + datastore: function(key) + { + return this.chainedCacheItem("stack.datastore." + key); + }, + + project: function() + { + return this.chainedCacheItem("project"); + } + + }); + +})(window); +(function(window) { + + Gitana = window.Gitana; + + const STATUS_UNRESOLVED = 'unresolved'; + const STATUS_RESOLVED = 'resolved'; + const STATUS_REJECTED = 'rejected'; + + const triggerAll = function(val, cbs) { + for (let i = 0; i < cbs.length; i++) { + const cb = cbs[i]; + trigger(val, cb); + } + }; + + const trigger = function(val, cb) { + setTimeout(cb.bind(null, val), 0); + }; + + const resolve = function(val) { + if (this.isUnresolved()) { + this.status = STATUS_RESOLVED; + this.val = val; + triggerAll(val, this.successCallbacks); + delete this.successCallbacks; + delete this.errorCallbacks; + } + }; + + const reject = function(err) { + if (this.isUnresolved()) { + this.status = STATUS_REJECTED; + this.val = err; + triggerAll(err, this.errorCallbacks); + delete this.successCallbacks; + delete this.errorCallbacks; + } + }; + + const Defer = function() { + this.promise = new Gitana.Promise(this); + + this.status = STATUS_UNRESOLVED; + + this.successCallbacks = []; + this.errorCallbacks = []; + + this.resolve = resolve.bind(this); + this.reject = reject.bind(this); + }; + + Defer.prototype.push = function(happy, sad) { + if (this.isUnresolved()) { + if (typeof happy === 'function') { this.successCallbacks.push(happy); } + if (typeof sad === 'function') { this.errorCallbacks.push(sad); } + } else if (this.isResolved()) { + trigger(this.val, happy); + } else if (this.isRejected()) { + trigger(this.val, sad); + } + }; + + Defer.prototype.isUnresolved = function() { + return this.status === STATUS_UNRESOLVED; + }; + + Defer.prototype.isResolved = function() { + return this.status === STATUS_RESOLVED; + }; + + Defer.prototype.isRejected = function() { + return this.status === STATUS_REJECTED; + }; + + Defer.all = function(args) { + if (args === undefined) { + return Gitana.Promise.resolved(); + } + if (!Gitana.isArray(args)) { args = arguments; } + const def = new Defer(); + let left = args.length; + const results = []; + for (let i = 0; i < args.length; i++) { + const promise = args[i]; + (function(cur) { + promise.then(function(res) { + left--; + results[cur] = res; + if (left <= 0) { + def.resolve(results); + } + }, def.reject); + })(i); + } + return def.promise; + }; + + Gitana.Defer = Defer; + +})(window); +(function(window) { + + Gitana = window.Gitana; + + const then = function(happy, sad) { + this.push(happy, sad); + }; + + const success = function(happy) { + then.call(this, happy); + }; + + const fail = function(sad) { + then.call(this, undefined, sad); + }; + + const complete = function(cb) { + then.call(this, cb, cb); + }; + + const Promise = function(defer) { + + this.then = then.bind(defer); + this.success = success.bind(defer); + this.fail = fail.bind(defer); + this.complete = complete.bind(defer); + + this.status = function() { + return defer.status; + }; + + }; + + Promise.resolved = function(val) { + const def = new Gitana.Defer(); + def.resolve(val); + return def.promise; + }; + + Gitana.Promise = Promise; + +})(window); +(function(window) +{ + Gitana = window.Gitana; + + Gitana.AccessPolicy = Gitana.AbstractPlatformObject.extend( + /** @lends Gitana.AccessPolicy.prototype */ + { + /** + * @constructs + * @augments Gitana.AbstractPlatformObject + * + * @class AccessPolicy + * + * @param {Gitana.Platform} platform + * @param {Object} object json object (if no callback required for populating) + */ + constructor: function(platform, object) + { + this.base(platform, object); + + this.objectType = function() { return "Gitana.AccessPolicy"; }; + }, + + /** + * @OVERRIDE + */ + getType: function() + { + return Gitana.TypedIDConstants.TYPE_ACCESS_POLICY; + }, + + /** + * @OVERRIDE + */ + getUri: function() + { + return "/access/policies/" + this.getId(); + }, + + /** + * @override + */ + clone: function() + { + return this.getFactory().accessPolicy(this.getPlatform(), this); + } + + }); + +})(window); +(function(window) +{ + Gitana = window.Gitana; + + Gitana.AccessPolicyMap = Gitana.AbstractPlatformObjectMap.extend( + /** @lends Gitana.AccessPolicyMap.prototype */ + { + /** + * @constructs + * @augments Gitana.AbstractMap + * + * @class Map of access policies + * + * @param {Gitana.Platform} platform Gitana platform instance. + * @param {Object} object + */ + constructor: function(platform, object) + { + this.objectType = function() { return "Gitana.AccessPolicyMap"; }; + + + ////////////////////////////////////////////////////////////////////////////////////////////// + // + // CALL THROUGH TO BASE CLASS (at the end) + // + ////////////////////////////////////////////////////////////////////////////////////////////// + + this.base(platform, object); + }, + + /** + * @override + */ + clone: function() + { + return this.getFactory().accessPolicyMap(this.getPlatform(), this); + }, + + /** + * @param json + */ + buildObject: function(json) + { + return this.getFactory().accessPolicy(this.getPlatform(), json); + } + + }); + +})(window); + + + return Gitana; + +})); diff --git a/js/gitana/AbstractMap.js b/js/gitana/AbstractMap.js index 6c4834c9..05962a66 100644 --- a/js/gitana/AbstractMap.js +++ b/js/gitana/AbstractMap.js @@ -1,6 +1,6 @@ (function(window) { - var Gitana = window.Gitana; + Gitana = window.Gitana; Gitana.AbstractMap = Gitana.AbstractPersistable.extend( /** @lends Gitana.AbstractMap.prototype */ @@ -12,7 +12,7 @@ * @class Abstract base class for a map of Gitana objects * * @param {Gitana} driver - * @param [Object] object + * @param {Object} object */ constructor: function(driver, object) { @@ -24,14 +24,14 @@ // auto-manage a list of keys this.__keys = (function() { - var list = []; + const list = []; return function(x) { if (!Gitana.isUndefined(x)) { - if (x == 'empty') { + if (x === 'empty') { while (list.length > 0) { list.shift(); } } else { if (!x && x.length) { - for (var i = 0; i < x.length; i++) { + for (let i = 0; i < x.length; i++) { list.push(x[i]); } } @@ -46,7 +46,7 @@ })(); this.__totalRows = (function() { - var _totalRows = null; + let _totalRows = null; return function(totalRows) { if (!Gitana.isUndefined(totalRows)) { _totalRows = totalRows; } return _totalRows; @@ -54,7 +54,7 @@ })(); this.__size = (function() { - var _size = null; + let _size = null; return function(size) { if (!Gitana.isUndefined(size)) { _size = size; } return _size; @@ -62,7 +62,7 @@ })(); this.__offset = (function() { - var _offset = 0; + let _offset = 0; return function(offset) { if (!Gitana.isUndefined(offset) && offset >= 0) { _offset = offset; } return _offset; @@ -80,13 +80,13 @@ refs: function() { - var references = []; + const references = []; - for (var i = 0; i < this.__keys().length; i++) + for (let i = 0; i < this.__keys().length; i++) { - var key = this.__keys()[i]; + const key = this.__keys()[i]; - var object = this[key]; + const object = this[key]; if (object.ref) { references.push(object.ref()); @@ -113,9 +113,9 @@ // include keys if (otherObject.__keys) { this.__keys('empty'); - for (var i = 0; i < otherObject.__keys().length; i++) + for (let i = 0; i < otherObject.__keys().length; i++) { - var k = otherObject.__keys()[i]; + const k = otherObject.__keys()[i]; this.__keys().push(k); } } @@ -174,9 +174,9 @@ // parse array if (Gitana.isArray(response.rows)) { - for (var i = 0; i < response.rows.length; i++) + for (let i = 0; i < response.rows.length; i++) { - var o = this.buildObject(response.rows[i]); + const o = this.buildObject(response.rows[i]); this[o.getId()] = o; this.__keys().push(o.getId()); @@ -185,16 +185,16 @@ else { // parse object - for (var key in response.rows) + for (let key in response.rows) { if (response.rows.hasOwnProperty(key) && !Gitana.isFunction(response.rows[key])) { - var value = response.rows[key]; + const value = response.rows[key]; - var o = this.buildObject(value); + const o = this.buildObject(value); // determine key - var k = (o.getId && o.getId()); + let k = (o.getId && o.getId()); if (!k) { k = key; } @@ -211,16 +211,16 @@ // otherwise, assume it is key/value pairs // it also might be another Gitana Map - for (var key in response) + for (let key in response) { if (response.hasOwnProperty(key) && !Gitana.isFunction(response[key])) { - var value = response[key]; + const value = response[key]; - var o = this.buildObject(value); + const o = this.buildObject(value); // determine key - var k = (o.getId && o.getId()); + let k = (o.getId && o.getId()); if (!k) { k = key; } @@ -253,10 +253,10 @@ asArray: function() { - var array = []; - for (var i = 0; i < this.__keys().length; i++) + const array = []; + for (let i = 0; i < this.__keys().length; i++) { - var k = this.__keys()[i]; + const k = this.__keys()[i]; array.push(this[k]); } @@ -320,16 +320,16 @@ return this.then(function() { // run functions - for (var i = 0; i < this.__keys().length; i++) + for (let i = 0; i < this.__keys().length; i++) { // key and value from the map - var key = this.__keys()[i]; - var value = this[key]; + const key = this.__keys()[i]; + const value = this[key]; // a function that fires our callback // wrap in a closure so that we store the callback and key // note: this = the value wrapped in a chain, so we don't pass in value - var f = function(callback, key, index, map) + const f = function(callback, key, index, map) { return function() { @@ -369,13 +369,13 @@ return this.then(function() { // create an array of functions that invokes the callback for each element in the array - var functions = []; - for (var i = 0; i < this.__keys().length; i++) + const functions = []; + for (let i = 0; i < this.__keys().length; i++) { - var key = this.__keys()[i]; - var value = this[key]; + const key = this.__keys()[i]; + const value = this[key]; - var f = function(callback, key, value, index) { + const f = function(callback, key, value, index) { return function() { @@ -413,15 +413,15 @@ { return this.then(function() { - var keysToKeep = []; - var keysToRemove = []; + const keysToKeep = []; + const keysToRemove = []; - for (var i = 0; i < this.__keys().length; i++) + for (let i = 0; i < this.__keys().length; i++) { - var key = this.__keys()[i]; - var object = this[key]; + const key = this.__keys()[i]; + const object = this[key]; - var keepIt = callback.call(object); + const keepIt = callback.call(object); if (keepIt) { keysToKeep.push(key); @@ -433,7 +433,7 @@ } // remove any keys we don't want from the map - for (var i = 0; i < keysToRemove.length; i++) + for (let i = 0; i < keysToRemove.length; i++) { delete this[keysToRemove[i]]; } @@ -442,7 +442,7 @@ // NOTE: we first clear the keys but we can't use slice(0,0) since that produces a NEW array // instead, do this shift trick this.__keys('empty'); - for (var i = 0; i < keysToKeep.length; i++) + for (let i = 0; i < keysToKeep.length; i++) { this.__keys().push(keysToKeep[i]); } @@ -471,9 +471,9 @@ return this.then(function() { // build a temporary array of values - var array = []; - for (var i = 0; i < this.__keys().length; i++) { - var key = this.__keys()[i]; + const array = []; + for (let i = 0; i < this.__keys().length; i++) { + const key = this.__keys()[i]; array.push(this[key]); } @@ -482,7 +482,7 @@ // now reset keys according to the order of the array this.__keys("empty"); - for (var i = 0; i < array.length; i++) + for (let i = 0; i < array.length; i++) { this.__keys().push(array[i].getId()); } @@ -501,7 +501,7 @@ { return this.then(function() { - var keysToRemove = []; + const keysToRemove = []; if (size > this.__keys().length) { @@ -510,7 +510,7 @@ } // figure out which keys to remove - for (var i = 0; i < this.__keys().length; i++) + for (let i = 0; i < this.__keys().length; i++) { if (i >= size) { @@ -526,7 +526,7 @@ } // remove any keys to remove from map - for (var i = 0; i < keysToRemove.length; i++) + for (let i = 0; i < keysToRemove.length; i++) { delete this[keysToRemove[i]]; } @@ -547,13 +547,13 @@ { return this.then(function() { - var skip = pagination.skip; - var limit = pagination.limit; + const skip = pagination.skip; + const limit = pagination.limit; - var keysToRemove = []; + const keysToRemove = []; // figure out which keys to remove - for (var i = 0; i < this.__keys().length; i++) + for (let i = 0; i < this.__keys().length; i++) { if (i < skip || i >= skip + limit) { @@ -569,7 +569,7 @@ } // remove any keys to remove from map - for (var i = 0; i < keysToRemove.length; i++) + for (let i = 0; i < keysToRemove.length; i++) { delete this[keysToRemove[i]]; } @@ -599,25 +599,25 @@ */ keepOne: function(emptyHandler) { - var self = this; + const self = this; - var json = {}; + let json = {}; if (this.__keys().length > 0) { json = this[this.__keys()[0]]; } - var chainable = this.buildObject(json); + const chainable = this.buildObject(json); return this.subchain(chainable).then(function() { - var chain = this; + const chain = this; this.subchain(self).then(function() { if (this.__keys().length > 0) { - var obj = this[this.__keys()[0]]; + const obj = this[this.__keys()[0]]; if (chain.loadFrom) { @@ -632,7 +632,7 @@ } else { - var err = new Gitana.Error(); + const err = new Gitana.Error(); err.name = "Empty Map"; err.message = "The map doesn't have any elements in it"; @@ -659,28 +659,28 @@ */ select: function(key) { - var self = this; + const self = this; - var json = {}; + let json = {}; if (this[key]) { json = this[key]; } // what we hand back - var result = this.subchain(this.buildObject(json)); + const result = this.subchain(this.buildObject(json)); // preload some work return result.then(function() { - var chain = this; + const chain = this; this.subchain(self).then(function() { - var obj = this[key]; + const obj = this[key]; if (!obj) { - var err = new Gitana.Error(); + const err = new Gitana.Error(); err.name = "No element with key: " + key; err.message = err.name; diff --git a/js/gitana/AbstractObject.js b/js/gitana/AbstractObject.js index c54d87f5..61c858fe 100644 --- a/js/gitana/AbstractObject.js +++ b/js/gitana/AbstractObject.js @@ -1,6 +1,6 @@ (function(window) { - var Gitana = window.Gitana; + Gitana = window.Gitana; Gitana.AbstractObject = Gitana.AbstractPersistable.extend( /** @lends Gitana.AbstractObject.prototype */ @@ -17,7 +17,7 @@ constructor: function(driver, object) { this.__system = (function() { - var _system = new Gitana.SystemMetadata(); + const _system = new Gitana.SystemMetadata(); return function(system) { if (!Gitana.isUndefined(system)) { _system.updateFrom(system); } return _system; @@ -42,11 +42,11 @@ */ this.chainDelete = function(chainable, uri, params) { - var self = this; + const self = this; return this.subchain(chainable).then(function() { - var chain = this; + const chain = this; // allow for closures on uri for late resolution if (Gitana.isFunction(uri)) { @@ -68,16 +68,17 @@ /** * Reloads this object from the server and then passes control to the chainable. * + * @param chainable * @param uri * @param params */ this.chainReload = function(chainable, uri, params) { - var self = this; + const self = this; return this.subchain(chainable).then(function() { - var chain = this; + const chain = this; // allow for closures on uri for late resolution if (Gitana.isFunction(uri)) { @@ -106,11 +107,11 @@ */ this.chainUpdate = function(chainable, uri, params) { - var self = this; + const self = this; return this.subchain(chainable).then(function() { - var chain = this; + const chain = this; // allow for closures on uri for late resolution if (Gitana.isFunction(uri)) { @@ -145,11 +146,11 @@ */ this.chainPatch = function(chainable, uri, params, payload) { - var self = this; + const self = this; return this.subchain(chainable).then(function() { - var chain = this; + const chain = this; // allow for closures on uri for late resolution if (Gitana.isFunction(uri)) { @@ -315,11 +316,11 @@ replacePropertiesWith: function(object) { // create a copy of the incoming object - var candidate = {}; + const candidate = {}; Gitana.copyInto(candidate, object); // we don't allow the following values to be replaced - var backups = {}; + const backups = {}; backups["_doc"] = this["_doc"]; delete candidate["_doc"]; backups["_type"] = this["_type"]; @@ -349,7 +350,7 @@ if (this["_system"]) { // strip out system metadata - var json = this["_system"]; + const json = this["_system"]; delete this["_system"]; // update system properties diff --git a/js/gitana/AbstractPersistable.js b/js/gitana/AbstractPersistable.js index 62a7d8b6..abb790e5 100644 --- a/js/gitana/AbstractPersistable.js +++ b/js/gitana/AbstractPersistable.js @@ -1,6 +1,6 @@ (function(window) { - var Gitana = window.Gitana; + Gitana = window.Gitana; Gitana.AbstractPersistable = Gitana.Chainable.extend( /** @lends Gitana.AbstractPersistable.prototype */ diff --git a/js/gitana/AbstractSelfableACLObject.js b/js/gitana/AbstractSelfableACLObject.js index 57d89b1a..90c8ac68 100644 --- a/js/gitana/AbstractSelfableACLObject.js +++ b/js/gitana/AbstractSelfableACLObject.js @@ -1,6 +1,6 @@ (function(window) { - var Gitana = window.Gitana; + Gitana = window.Gitana; Gitana.AbstractSelfableACLObject = Gitana.AbstractSelfableObject.extend( /** @lends Gitana.AbstractSelfableACLObject.prototype */ @@ -37,9 +37,9 @@ */ loadACL: function(callback) { - var self = this; + const self = this; - var uriFunction = function() + const uriFunction = function() { return self.getUri() + "/acl/list"; }; @@ -59,11 +59,11 @@ */ listAuthorities: function(principal, callback) { - var principalDomainQualifiedId = this.extractPrincipalDomainQualifiedId(principal); + const principalDomainQualifiedId = this.extractPrincipalDomainQualifiedId(principal); - var self = this; + const self = this; - var uriFunction = function() + const uriFunction = function() { return self.getUri() + "/acl?id=" + principalDomainQualifiedId; }; @@ -85,11 +85,11 @@ */ checkAuthority: function(principal, authorityId, callback) { - var principalDomainQualifiedId = this.extractPrincipalDomainQualifiedId(principal); + const principalDomainQualifiedId = this.extractPrincipalDomainQualifiedId(principal); - var self = this; + const self = this; - var uriFunction = function() + const uriFunction = function() { return self.getUri() + "/authorities/" + authorityId + "/check?id=" + principalDomainQualifiedId; }; @@ -109,11 +109,11 @@ */ grantAuthority: function(principal, authorityId) { - var principalDomainQualifiedId = this.extractPrincipalDomainQualifiedId(principal); + const principalDomainQualifiedId = this.extractPrincipalDomainQualifiedId(principal); - var self = this; + const self = this; - var uriFunction = function() + const uriFunction = function() { return self.getUri() + "/authorities/" + authorityId + "/grant?id=" + principalDomainQualifiedId; }; @@ -131,11 +131,11 @@ */ revokeAuthority: function(principal, authorityId) { - var principalDomainQualifiedId = this.extractPrincipalDomainQualifiedId(principal); + const principalDomainQualifiedId = this.extractPrincipalDomainQualifiedId(principal); - var self = this; + const self = this; - var uriFunction = function() + const uriFunction = function() { return self.getUri() + "/authorities/" + authorityId + "/revoke?id=" + principalDomainQualifiedId; }; @@ -160,6 +160,7 @@ * * @chained this * + * @param principalIds * @param callback */ loadAuthorityGrants: function(principalIds, callback) @@ -169,7 +170,7 @@ principalIds = []; } - var json = { + const json = { "principals": principalIds }; @@ -190,9 +191,9 @@ */ checkPermission: function(principal, permissionId, callback) { - var principalDomainQualifiedId = this.extractPrincipalDomainQualifiedId(principal); + const principalDomainQualifiedId = this.extractPrincipalDomainQualifiedId(principal); - var uriFunction = function() + const uriFunction = function() { return self.getUri() + "/permissions/" + permissionId + "/check?id=" + principalDomainQualifiedId; }; diff --git a/js/gitana/AbstractSelfableObject.js b/js/gitana/AbstractSelfableObject.js index 66affab1..76f003a9 100644 --- a/js/gitana/AbstractSelfableObject.js +++ b/js/gitana/AbstractSelfableObject.js @@ -1,6 +1,6 @@ (function(window) { - var Gitana = window.Gitana; + Gitana = window.Gitana; Gitana.AbstractSelfableObject = Gitana.AbstractObject.extend( /** @lends Gitana.AbstractSelfableObject.prototype */ @@ -37,9 +37,9 @@ */ del: function() { - var self = this; + const self = this; - var uriFunction = function() + const uriFunction = function() { return self.getUri(); }; @@ -57,9 +57,9 @@ */ reload: function() { - var self = this; + const self = this; - var uriFunction = function() + const uriFunction = function() { return self.getUri(); }; @@ -76,9 +76,9 @@ */ update: function() { - var self = this; + const self = this; - var uriFunction = function() + const uriFunction = function() { return self.getUri(); }; diff --git a/js/gitana/Activity.js b/js/gitana/Activity.js index ad61b142..c530d123 100644 --- a/js/gitana/Activity.js +++ b/js/gitana/Activity.js @@ -1,6 +1,6 @@ (function(window) { - var Gitana = window.Gitana; + Gitana = window.Gitana; Gitana.Activity = Gitana.AbstractObject.extend( /** @lends Gitana.Activity.prototype */ @@ -12,7 +12,7 @@ * @class Activity * * @param {Gitana.DataStore} datastore - * @param [Object] object json object (if no callback required for populating) + * @param {Object} object json object (if no callback required for populating) */ constructor: function(datastore, object) { @@ -48,7 +48,7 @@ */ del: function() { - var uriFunction = function() + const uriFunction = function() { return this.getUri(); }; @@ -66,7 +66,7 @@ */ reload: function() { - var uriFunction = function() + const uriFunction = function() { return this.getUri(); }; @@ -83,7 +83,7 @@ */ update: function() { - var uriFunction = function() + const uriFunction = function() { return this.getUri(); }; diff --git a/js/gitana/ActivityMap.js b/js/gitana/ActivityMap.js index d0dddab9..6963f7e3 100644 --- a/js/gitana/ActivityMap.js +++ b/js/gitana/ActivityMap.js @@ -1,6 +1,6 @@ (function(window) { - var Gitana = window.Gitana; + Gitana = window.Gitana; Gitana.ActivityMap = Gitana.AbstractMap.extend( /** @lends Gitana.ActivityMap.prototype */ @@ -12,7 +12,7 @@ * @class Map of activities * * @param {Object} datastore Gitana datastore - * @param [Object] object + * @param {Object} object */ constructor: function(datastore, object) { diff --git a/js/gitana/AppHelper.js b/js/gitana/AppHelper.js index d337a90b..6cdbfa27 100644 --- a/js/gitana/AppHelper.js +++ b/js/gitana/AppHelper.js @@ -1,6 +1,6 @@ (function(window) { - var Gitana = window.Gitana; + Gitana = window.Gitana; Gitana.AppHelper = Gitana.AbstractObject.extend( /** @lends Gitana.AppHelper.prototype */ @@ -36,7 +36,7 @@ this.chainedCacheItem = function(key) { - var chained = null; + let chained = null; if (this.cache(key)) { @@ -49,17 +49,17 @@ init: function(callback) { - var self = this; + const self = this; - var p = function(application) + const p = function(application) { // THIS = application - var projectId = application["projectId"]; + const projectId = application["projectId"]; if (projectId) { // read the project - Chain(self.getPlatform()).trap(function(err) { + Chain(self.getPlatform()).trap(function() { // could not find the project for the application // this is fine... we are done @@ -88,9 +88,9 @@ }).readApplication(self.getApplicationId()).then(function() { self.cache("application", this); - var application = this; + const application = this; - this.subchain(self.getPlatform()).trap(function(err) { + this.subchain(self.getPlatform()).trap(function() { // could not locate the stack for the application // this is perfectly fine (just means an application isn't allocated to a stack) diff --git a/js/gitana/AuthInfo.js b/js/gitana/AuthInfo.js index ff783c7d..a77740b2 100644 --- a/js/gitana/AuthInfo.js +++ b/js/gitana/AuthInfo.js @@ -1,6 +1,6 @@ (function(window) { - var Gitana = window.Gitana; + Gitana = window.Gitana; Gitana.AuthInfo = Base.extend( /** @lends Gitana.AuthInfo.prototype */ diff --git a/js/gitana/BinaryAttachment.js b/js/gitana/BinaryAttachment.js index ec60d0d4..13f99439 100644 --- a/js/gitana/BinaryAttachment.js +++ b/js/gitana/BinaryAttachment.js @@ -1,6 +1,6 @@ (function(window) { - var Gitana = window.Gitana; + Gitana = window.Gitana; Gitana.BinaryAttachment = Gitana.AbstractPersistable.extend( /** @lends Gitana.BinaryAttachment.prototype */ @@ -74,14 +74,14 @@ */ del: function() { - var self = this; + const self = this; - var result = this.subchain(this.persistable()); + const result = this.subchain(this.persistable()); // our work (first in chain) result.subchain(self).then(function() { - var chain = this; + const chain = this; // delete the attachment this.getDriver().gitanaDelete(this.getUri(), null, function() { @@ -106,11 +106,11 @@ */ download: function(callback) { - var self = this; + const self = this; return this.then(function() { - var chain = this; + const chain = this; // download this.getDriver().gitanaDownload(this.getUri(), null, function(data) { diff --git a/js/gitana/BinaryAttachmentMap.js b/js/gitana/BinaryAttachmentMap.js index 17f8d219..89002f8f 100644 --- a/js/gitana/BinaryAttachmentMap.js +++ b/js/gitana/BinaryAttachmentMap.js @@ -1,6 +1,6 @@ (function(window) { - var Gitana = window.Gitana; + Gitana = window.Gitana; Gitana.BinaryAttachmentMap = Gitana.AbstractMap.extend( /** @lends Gitana.BinaryAttachmentMap.prototype */ @@ -10,7 +10,7 @@ this.objectType = function() { return "Gitana.BinaryAttachmentMap"; }; this.__persistable = (function() { - var _persistable = persistable; + let _persistable = persistable; return function(p) { if (!Gitana.isUndefined(p)) { _persistable = p; } return _persistable; @@ -51,7 +51,7 @@ }, /** - * @param json + * @param attachment */ buildObject: function(attachment) { diff --git a/js/gitana/Chain.js b/js/gitana/Chain.js index e80e37b9..125787a8 100644 --- a/js/gitana/Chain.js +++ b/js/gitana/Chain.js @@ -4,6 +4,7 @@ * Creates a chain. If an object is provided, the chain is augmented onto the object. * * @param object + * @param skipAutoTrap */ Chain = function(object, skipAutoTrap) { @@ -13,47 +14,47 @@ } // wraps the object into a proxy - var proxiedObject = Chain.proxy(object); + const proxiedObject = Chain.proxy(object); // the following methods get pushed onto the chained object // methods for managing chain state proxiedObject.__queue = (function() { - var queue = []; + let queue = []; return function(x) { - if (x) { if (x == 'empty') { queue = []; } else { queue.push(x); }} + if (x) { if (x === 'empty') { queue = []; } else { queue.push(x); }} return queue; }; })(); proxiedObject.__response = (function() { - var response = null; + let response = null; return function(x) { if (!Gitana.isUndefined(x)) { if (x) { response = x; } else { response = null; } } return response; }; })(); proxiedObject.__waiting = (function() { - var waiting = false; + let waiting = false; return function(x) { if (!Gitana.isUndefined(x)) { waiting = x; } return waiting; }; })(); proxiedObject.__parent = (function() { - var parent = null; + let parent = null; return function(x) { if (!Gitana.isUndefined(x)) { if (x) { parent = x; } else { parent = null; } } return parent; }; })(); proxiedObject.__id = (function() { - var id = Chain.idCount; + let id = Chain.idCount; Chain.idCount++; return function() { return id; }; })(); proxiedObject.__helper = (function() { - var helper = null; + let helper = null; return function(x) { if (x) { helper = x; } return helper; @@ -61,7 +62,7 @@ })(); // marks any chain links which are placeholders for functions proxiedObject.__transparent = (function() { - var transparent = false; // assume not transparent + let transparent = false; // assume not transparent return function(x) { if (!Gitana.isUndefined(x)) { transparent = x; } return transparent; @@ -85,9 +86,9 @@ */ proxiedObject.then = function(element, functionName) { - var self = this; + const self = this; - var autorun = false; + let autorun = false; // // ARRAY @@ -99,16 +100,16 @@ // if (Gitana.isArray(element)) { - var array = element; + const array = element; // parallel function invoker - var parallelInvoker = function() + const parallelInvoker = function() { // build out parallel functions - var fns = []; - for (var i = 0; i < array.length; i++) + const fns = []; + for (let i = 0; i < array.length; i++) { - var fn = function(func) + const fn = function(func) { return function(done) { @@ -117,7 +118,7 @@ // the parallel chain is a clone of this chain // the subchain runs the function // these are serial so that the subchain must complete before the onComplete method is called - var parallelChain = Chain(); // note: empty chain (parent) + const parallelChain = Chain(); // note: empty chain (parent) parallelChain.__waiting(true); // this prevents auto-run (which would ground out the first subchain call) parallelChain.subchain(self).then(function () { // TODO: should we self.clone() for parallel operations? func.call(this); @@ -132,9 +133,9 @@ fns.push(fn); } - var count = 0; - var total = fns.length; - var onComplete = function() + let count = 0; + const total = fns.length; + const onComplete = function() { count++; if (count === total) @@ -145,14 +146,14 @@ }; // run all of the functions in parallel - for (var i = 0; i < fns.length; i++) + for (let i = 0; i < fns.length; i++) { window.setTimeout(function(fn) { return function() { fn(function() { onComplete(); }); - } + }; }(fns[i])); } @@ -161,7 +162,7 @@ }; // build a subchain (transparent) - var subchain = this.subchain(null, true); // don't auto add, we'll do it ourselves + const subchain = this.subchain(null, true); // don't auto add, we'll do it ourselves subchain.__queue(parallelInvoker); if (functionName) { subchain.__helper(functionName); } element = subchain; @@ -180,7 +181,7 @@ { // create the subchain // this does a re-entrant call that adds it to the queue (as a subchain) - var subchain = this.subchain(null, true); // don't auto add, we'll do it ourselves + const subchain = this.subchain(null, true); // don't auto add, we'll do it ourselves subchain.__queue(element); if (functionName) { subchain.__helper(functionName); } element = subchain; @@ -198,7 +199,7 @@ // we climb the parents until we find the topmost parent and tell it to run. if (autorun && !this.__waiting()) { - var runner = this; + let runner = this; while (runner.__parent()) { runner = runner.__parent(); @@ -219,10 +220,10 @@ */ proxiedObject.run = function() { - var self = this; + const self = this; // short cut, if nothing in the queue, bail - if (this.__queue().length == 0 || this.__waiting()) + if (this.__queue().length === 0 || this.__waiting()) { return this; } @@ -231,17 +232,17 @@ this.__waiting(true); // the element to run - var element = this.__queue().shift(); + const element = this.__queue().shift(); // case: callback function if (Gitana.isFunction(element)) { // it's a callback function - var callback = element; + const callback = element; // try to determine response and previous response - var response = null; - var previousResponse = null; + let response = null; + let previousResponse = null; if (this.__parent()) { response = this.__parent().__response(); @@ -257,7 +258,7 @@ Chain.log(self, (self.__helper() ? self.__helper()+ " " : "") + "> " + element.toString()); // execute with "this = chain" - var returned = callback.call(self, response, previousResponse); + const returned = callback.call(self, response, previousResponse); if (returned !== false) { self.next(returned); @@ -268,7 +269,7 @@ { // it's a subchain element (object) // we make sure to copy response forward - var subchain = element; + const subchain = element; subchain.__response(this.__response()); // pre-emptively copy forward into subchain @@ -302,7 +303,7 @@ */ proxiedObject.subchain = function(object, noAutoAdd) { - var transparent = false; + let transparent = false; if (!object) { transparent = true; } @@ -312,7 +313,7 @@ object = this; } - var subchain = Chain(object, true); + const subchain = Chain(object, true); subchain.__parent(this); // BEFORE CHAIN RUN CALLBACK @@ -343,7 +344,7 @@ * * If the response is null, nothing will be bumped. * - * @param [Object] response + * @param {Object} response */ proxiedObject.next = function(response) { @@ -358,12 +359,12 @@ // if there isn't anything left in the queue, then we're done // if we have a parent, we can signal that we've completed - if (this.__queue().length == 0) + if (this.__queue().length === 0) { if (this.__parent()) { // copy response up to parent - var r = this.__response(); + const r = this.__response(); this.__parent().__response(r); this.__response(null); @@ -398,7 +399,7 @@ { return this.then(function() { - var wake = function(chain) + const wake = function(chain) { return function() { @@ -432,8 +433,8 @@ proxiedObject.error = function(err) { // find the first error handler we can walking up the chain - var errorHandler = null; - var ancestor = this; + let errorHandler = null; + let ancestor = this; while (ancestor && !errorHandler) { errorHandler = ancestor.errorHandler; @@ -460,7 +461,7 @@ } // invoke error handler - var code = errorHandler.call(this, err); + const code = errorHandler.call(this, err); // finish out the chain if we didn't get "false" if (code !== false) @@ -531,7 +532,7 @@ } // clone the object using clone() method - var proxy = null; + let proxy = null; if (o.clone) { proxy = o.clone(); } else { @@ -551,7 +552,7 @@ */ Chain.unproxy = function(proxy) { - var o = null; + let o = null; if (proxy.__original && proxy.__original()) { @@ -566,9 +567,9 @@ { if (Chain.debug && !Gitana.isUndefined(console)) { - var f = function() + const f = function() { - var identifier = this.__id(); + let identifier = this.__id(); if (this.__transparent()) { identifier += "[t]"; } @@ -581,7 +582,7 @@ return f.call(this.__parent()) + " > " + identifier; }; - var identifier = f.call(chain); + const identifier = f.call(chain); console.log("Chain[" + identifier + "] " + text); } @@ -594,7 +595,7 @@ // includes copies of chain functions function F() {} F.prototype = object; - var clone = new F(); + const clone = new F(); // copy properties Gitana.copyInto(clone, object); @@ -602,8 +603,8 @@ return clone; }; - var autoTrapValue = null; - var autoTrap = Chain.autoTrap = function(_autoTrap) + let autoTrapValue = null; + const autoTrap = Chain.autoTrap = function(_autoTrap) { if (_autoTrap) { diff --git a/js/gitana/Chainable.js b/js/gitana/Chainable.js index 991810a0..7eea3c8d 100644 --- a/js/gitana/Chainable.js +++ b/js/gitana/Chainable.js @@ -1,6 +1,6 @@ (function(window) { - var Gitana = window.Gitana; + Gitana = window.Gitana; Gitana.Chainable = Base.extend( /** @lends Gitana.Chainable.prototype */ @@ -14,8 +14,6 @@ */ constructor: function(driver) { - var self = this; - this.base(); /** @@ -47,7 +45,7 @@ this.httpError = function(httpError) { - var err = new Gitana.Error(); + const err = new Gitana.Error(); err.name = "Http Error"; err.message = httpError.message; err.status = httpError.status; @@ -88,7 +86,7 @@ this.missingNodeError = function(id) { - var err = new Gitana.Error(); + const err = new Gitana.Error(); err.name = "Missing Node error"; err.message = "The node: " + id + " could not be found"; @@ -117,11 +115,11 @@ */ this.chainGet = function(chainable, uri, params) { - var self = this; + const self = this; return this.subchain(chainable).then(function() { - var chain = this; + const chain = this; // allow for closures on uri for late resolution if (Gitana.isFunction(uri)) { @@ -151,11 +149,11 @@ */ this.chainCreate = function(chainable, object, uri, params) { - var self = this; + const self = this; return this.subchain(chainable).then(function() { - var chain = this; + const chain = this; // allow for closures on uri for late resolution if (Gitana.isFunction(uri)) { @@ -193,11 +191,11 @@ */ this.chainCreateEx = function(chainable, object, createUri, readUri) { - var self = this; + const self = this; return this.subchain(chainable).then(function() { - var chain = this; + const chain = this; // allow for closures on uri for late resolution if (Gitana.isFunction(createUri)) { @@ -239,11 +237,11 @@ */ this.chainPost = function(chainable, uri, params, payload, handleFn) { - var self = this; + const self = this; return this.subchain(chainable).then(function() { - var chain = this; + const chain = this; // allow for closures on uri for late resolution if (Gitana.isFunction(uri)) { @@ -279,7 +277,7 @@ */ this.chainPostEmpty = function(chainable, uri, params, payload, contentType) { - var self = this; + const self = this; // if no payload, set to empty if (!payload && contentType) @@ -296,7 +294,7 @@ return this.subchain(chainable).then(function() { - var chain = this; + const chain = this; // allow for closures on uri for late resolution if (Gitana.isFunction(uri)) { @@ -304,7 +302,7 @@ } // create - driver.gitanaPost(uri, params, payload, function(response) { + driver.gitanaPost(uri, params, payload, function() { chain.next(); }, function(http) { self.httpError(http); @@ -327,7 +325,7 @@ */ this.chainUpload = function(chainable, uri, params, contentType, payload) { - var self = this; + const self = this; // if no payload, set to empty if (!payload && contentType) @@ -344,7 +342,7 @@ return this.subchain(chainable).then(function() { - var chain = this; + const chain = this; // allow for closures on uri for late resolution if (Gitana.isFunction(uri)) { @@ -352,7 +350,7 @@ } // create - driver.gitanaUpload(uri, params, contentType, payload, function(response) { + driver.gitanaUpload(uri, params, contentType, payload, function() { chain.next(); }, function(http) { self.httpError(http); @@ -373,11 +371,11 @@ */ this.chainGetResponse = function(chainable, uri, params) { - var self = this; + const self = this; return this.subchain(chainable).then(function() { - var chain = this; + const chain = this; // allow for closures on uri for late resolution if (Gitana.isFunction(uri)) { @@ -404,11 +402,11 @@ */ this.chainGetResponseText = function(chainable, uri, params) { - var self = this; + const self = this; return this.subchain(chainable).then(function() { - var chain = this; + const chain = this; // allow for closures on uri for late resolution if (Gitana.isFunction(uri)) { @@ -454,10 +452,10 @@ this.chainHasResponseRow = function(chainable, uri, value) { return this.chainGetResponse(chainable, uri).then(function(response) { - var authorized = false; - for (var i = 0; i < response.rows.length; i++) + let authorized = false; + for (let i = 0; i < response.rows.length; i++) { - if (response.rows[i].toLowerCase() == value.toLowerCase()) + if (response.rows[i].toLowerCase() === value.toLowerCase()) { authorized = true; } @@ -473,14 +471,15 @@ * @param chainable * @param uri * @param params + * @param payload */ this.chainPostResponse = function(chainable, uri, params, payload) { - var self = this; + const self = this; return this.subchain(chainable).then(function() { - var chain = this; + const chain = this; // allow for closures on uri for late resolution if (Gitana.isFunction(uri)) { @@ -504,10 +503,11 @@ * This returns something like "domainId/principalId" * * @param principal + * @param defaultDomainId */ this.extractPrincipalDomainQualifiedId = function(principal, defaultDomainId) { - var identifiers = this.extractPrincipalIdentifiers(principal, defaultDomainId); + const identifiers = this.extractPrincipalIdentifiers(principal, defaultDomainId); return identifiers["domain"] + "/" + identifiers["principal"]; }; @@ -521,7 +521,7 @@ */ this.extractPrincipalIdentifiers = function(principal, defaultDomainId) { - var identifiers = {}; + const identifiers = {}; if (!defaultDomainId) { @@ -530,7 +530,7 @@ if (Gitana.isString(principal)) { - var x = principal.indexOf("/"); + const x = principal.indexOf("/"); if (x > -1) { identifiers["domain"] = principal.substring(0, x); @@ -542,12 +542,12 @@ identifiers["principal"] = principal; } } - else if (principal.objectType && principal.objectType() == "Gitana.DomainPrincipal") + else if (principal.objectType && principal.objectType() === "Gitana.DomainPrincipal") { identifiers["domain"] = principal.getDomainId(); identifiers["principal"] = principal.getId(); } - else if (principal.objectType && principal.objectType() == "Gitana.TeamMember") + else if (principal.objectType && principal.objectType() === "Gitana.TeamMember") { identifiers["domain"] = principal["domainId"]; identifiers["principal"] = principal["_doc"]; diff --git a/js/gitana/ContainedDataStore.js b/js/gitana/ContainedDataStore.js index 59a4e04d..9d3d2c0f 100644 --- a/js/gitana/ContainedDataStore.js +++ b/js/gitana/ContainedDataStore.js @@ -1,6 +1,6 @@ (function(window) { - var Gitana = window.Gitana; + Gitana = window.Gitana; Gitana.ContainedDataStore = Gitana.DataStore.extend( /** @lends Gitana.ContainedDataStore.prototype */ @@ -12,7 +12,7 @@ * @class ContainedDataStore * * @param {Gitana.DataStore} container - * @param [Object] object json object (if no callback required for populating) + * @param {Object} object json object (if no callback required for populating) */ constructor: function(container, object) { @@ -46,7 +46,7 @@ */ del: function() { - var uriFunction = function() + const uriFunction = function() { return this.getUri(); }; @@ -64,7 +64,7 @@ */ reload: function() { - var uriFunction = function() + const uriFunction = function() { return this.getUri(); }; @@ -81,7 +81,7 @@ */ update: function() { - var uriFunction = function() + const uriFunction = function() { return this.getUri(); }; @@ -105,34 +105,34 @@ */ exportArchive: function(settings) { - var self = this; + const self = this; - var vaultId = settings.vault; + let vaultId = settings.vault; if (!Gitana.isString(vaultId)) { vaultId = vaultId.getId(); } - var groupId = settings.group; - var artifactId = settings.artifact; - var versionId = settings.version; - var configuration = (settings.configuration ? settings.configuration : {}); - var synchronous = (settings.async ? false : true); + const groupId = settings.group; + const artifactId = settings.artifact; + const versionId = settings.version; + const configuration = (settings.configuration ? settings.configuration : {}); + const synchronous = !settings.async; // archive additional properties - var title = settings.title; - var description = settings.description; - var published = settings.published; + const title = settings.title; + const description = settings.description; + const published = settings.published; // we continue the chain with a job - var chainable = this.getFactory().job(this.getCluster(), "export"); + const chainable = this.getFactory().job(this.getCluster(), "export"); // fire off import and job queue checking return this.subchain(chainable).then(function() { - var chain = this; + const chain = this; // create - var params = {}; + const params = {}; params["vault"] = vaultId; params["group"] = groupId; params["artifact"] = artifactId; @@ -164,30 +164,30 @@ * @chained job * * @param {Object} settings - * @param [Function] report function + * @param {Function} reportFn function */ importArchive: function(settings, reportFn) { - var self = this; + const self = this; - var vaultId = settings.vault; + let vaultId = settings.vault; if (!Gitana.isString(vaultId)) { vaultId = vaultId.getId(); } - var groupId = settings.group; - var artifactId = settings.artifact; - var versionId = settings.version; - var configuration = (settings.configuration ? settings.configuration : {}); - var synchronous = (settings.async ? false : true); + const groupId = settings.group; + const artifactId = settings.artifact; + const versionId = settings.version; + const configuration = (settings.configuration ? settings.configuration : {}); + const synchronous = !settings.async; // we continue the chain with a job - var chainable = this.getFactory().job(this.getCluster(), "import"); + const chainable = this.getFactory().job(this.getCluster(), "import"); // fire off import and job queue checking return this.subchain(chainable).then(function() { - var chain = this; + const chain = this; // create this.getDriver().gitanaPost(self.getUri() + "/import?vault=" + vaultId + "&group=" + groupId + "&artifact=" + artifactId + "&version=" + versionId + "&schedule=ASYNCHRONOUS", {}, configuration, function(response) { diff --git a/js/gitana/Context.js b/js/gitana/Context.js index 68d99c9f..c12daeb4 100644 --- a/js/gitana/Context.js +++ b/js/gitana/Context.js @@ -2,7 +2,7 @@ /** * @ignore */ - var Gitana = window.Gitana; + Gitana = window.Gitana; Gitana.Context = Gitana.Chainable.extend( /** @lends Gitana.Context.prototype */ @@ -13,7 +13,7 @@ * * @class Utility class for providing Gitana context * - * @param [Object] configs Configuration parameters + * @param {Object} configs Configuration parameters */ constructor: function(configs) { this.base(new Gitana(configs['driver'] ? configs['driver'] : {})); @@ -37,8 +37,8 @@ }; this.getRepositoryConfigs = function() { - var repositoryConfigs = configs['repository']; - if (typeof repositoryConfigs == "string") { + let repositoryConfigs = configs['repository']; + if (typeof repositoryConfigs === "string") { repositoryConfigs = { "repository" : repositoryConfigs }; @@ -47,9 +47,9 @@ }; this.getBranchConfigs = function() { - var branchConfigs = configs['branch'] ? configs['branch'] : 'master'; - if (typeof branchConfigs == "string") { - if (branchConfigs == 'master') { + let branchConfigs = configs['branch'] ? configs['branch'] : 'master'; + if (typeof branchConfigs === "string") { + if (branchConfigs === 'master') { branchConfigs = { 'type' : 'MASTER' }; @@ -105,13 +105,13 @@ */ init: function () { - var self = this; + const self = this; - var loadPlatform = function(successCallback, errorCallback) + const loadPlatform = function(successCallback, errorCallback) { if (!self.platform()) { - var authentication = self.getConfigs()["authentication"]; + const authentication = self.getConfigs()["authentication"]; self.getDriver().authenticate(authentication, function(http) { if (errorCallback) { @@ -135,7 +135,7 @@ } }; - var loadRepository = function(successCallback, errorCallback) + const loadRepository = function(successCallback, errorCallback) { if (!self.repository()) { @@ -148,7 +148,7 @@ } }).queryRepositories(self.getRepositoryConfigs()).count(function(count) { if (errorCallback) { - if (count == 0) { + if (count === 0) { errorCallback({ 'message': 'Cannot find any repository' }); @@ -173,7 +173,7 @@ } }; - var loadBranch = function(successCallback, errorCallback) + const loadBranch = function(successCallback, errorCallback) { if (!self.branch()) { @@ -186,7 +186,7 @@ } }).queryBranches(self.getBranchConfigs()).count(function(count) { if (errorCallback) { - if (count == 0) { + if (count === 0) { errorCallback({ 'message': 'Cannot find any branch' }); @@ -213,12 +213,12 @@ }; // we hand back a chained version of ourselves - var result = Chain(this); + const result = Chain(this); // preload work onto the chain return result.subchain().then(function() { - var chain = this; + const chain = this; loadPlatform(function() { @@ -227,7 +227,7 @@ }, function(err) { - var errorCallback = self.getConfigs()['error']; + const errorCallback = self.getConfigs()['error']; if (errorCallback) { errorCallback.call(self, err); @@ -248,7 +248,7 @@ */ Gitana.Context.create = function(config) { - var context = new Gitana.Context(config); + const context = new Gitana.Context(config); return context.init(); }; diff --git a/js/gitana/DataStore.js b/js/gitana/DataStore.js index f86b773c..a72ee1b1 100644 --- a/js/gitana/DataStore.js +++ b/js/gitana/DataStore.js @@ -1,6 +1,6 @@ (function(window) { - var Gitana = window.Gitana; + Gitana = window.Gitana; Gitana.DataStore = Gitana.AbstractObject.extend( /** @lends Gitana.DataStore.prototype */ @@ -12,7 +12,7 @@ * @class DataStore * * @param {Gitana} driver - * @param [Object] object json object (if no callback required for populating) + * @param {Object} object json object (if no callback required for populating) */ constructor: function(driver, object) { @@ -60,7 +60,7 @@ */ loadACL: function(callback) { - var uriFunction = function() + const uriFunction = function() { return this.getUri() + "/acl/list"; }; @@ -80,9 +80,9 @@ */ listAuthorities: function(principal, callback) { - var principalDomainQualifiedId = this.extractPrincipalDomainQualifiedId(principal); + const principalDomainQualifiedId = this.extractPrincipalDomainQualifiedId(principal); - var uriFunction = function() + const uriFunction = function() { return this.getUri() + "/acl?id=" + principalDomainQualifiedId; }; @@ -104,9 +104,9 @@ */ checkAuthority: function(principal, authorityId, callback) { - var principalDomainQualifiedId = this.extractPrincipalDomainQualifiedId(principal); + const principalDomainQualifiedId = this.extractPrincipalDomainQualifiedId(principal); - var uriFunction = function() + const uriFunction = function() { return this.getUri() + "/authorities/" + authorityId + "/check?id=" + principalDomainQualifiedId; }; @@ -126,9 +126,9 @@ */ grantAuthority: function(principal, authorityId) { - var principalDomainQualifiedId = this.extractPrincipalDomainQualifiedId(principal); + const principalDomainQualifiedId = this.extractPrincipalDomainQualifiedId(principal); - var uriFunction = function() + const uriFunction = function() { return this.getUri() + "/authorities/" + authorityId + "/grant?id=" + principalDomainQualifiedId; }; @@ -146,9 +146,9 @@ */ revokeAuthority: function(principal, authorityId) { - var principalDomainQualifiedId = this.extractPrincipalDomainQualifiedId(principal); + const principalDomainQualifiedId = this.extractPrincipalDomainQualifiedId(principal); - var uriFunction = function() + const uriFunction = function() { return this.getUri() + "/authorities/" + authorityId + "/revoke?id=" + principalDomainQualifiedId; }; @@ -173,6 +173,7 @@ * * @chained repository * + * @param principalIds * @param callback */ loadAuthorityGrants: function(principalIds, callback) @@ -182,7 +183,7 @@ principalIds = []; } - var json = { + const json = { "principals": principalIds }; @@ -203,9 +204,9 @@ */ checkPermission: function(principal, permissionId, callback) { - var principalDomainQualifiedId = this.extractPrincipalDomainQualifiedId(principal); + const principalDomainQualifiedId = this.extractPrincipalDomainQualifiedId(principal); - var uriFunction = function() + const uriFunction = function() { return this.getUri() + "/permissions/" + permissionId + "/check?id=" + principalDomainQualifiedId; }; @@ -239,12 +240,12 @@ */ readTeam: function(teamKey) { - var uriFunction = function() + const uriFunction = function() { return this.getUri() + "/teams/" + teamKey; }; - var chainable = this.getFactory().team(this.getPlatform(), this); + const chainable = this.getFactory().team(this.getPlatform(), this); return this.chainGet(chainable, uriFunction); }, @@ -255,12 +256,12 @@ */ listTeams: function() { - var uriFunction = function() + const uriFunction = function() { return this.getUri() + "/teams"; }; - var chainable = this.getFactory().teamMap(this.getCluster(), this); + const chainable = this.getFactory().teamMap(this.getCluster(), this); return this.chainGet(chainable, uriFunction); }, @@ -279,17 +280,17 @@ object = {}; } - var uriFunction = function() + const uriFunction = function() { return this.getUri() + "/teams?key=" + teamKey; }; - var self = this; + const self = this; - var chainable = this.getFactory().team(this.getPlatform(), this); + const chainable = this.getFactory().team(this.getPlatform(), this); return this.chainPostResponse(chainable, uriFunction, {}, object).then(function() { - var chain = this; + const chain = this; Chain(self).readTeam(teamKey).then(function() { chain.handleResponse(this); @@ -331,18 +332,18 @@ * * @chained activity map * - * @param [Object] pagination pagination (optional) + * @param {Object} pagination pagination (optional) */ listActivities: function(pagination) { // prepare params (with pagination) - var params = {}; + const params = {}; if (pagination) { Gitana.copyInto(params, pagination); } - var chainable = this.getFactory().activityMap(this); + const chainable = this.getFactory().activityMap(this); return this.chainGet(chainable, "/activities", params); }, @@ -355,7 +356,7 @@ */ readActivity: function(activityId) { - var chainable = this.getFactory().activity(this); + const chainable = this.getFactory().activity(this); return this.chainGet(chainable, "/activities/" + activityId); }, @@ -365,14 +366,14 @@ * @chained activity map * * @param {Object} query query. - * @param [Object] pagination pagination (optional) + * @param {Object} pagination pagination (optional) */ queryActivities: function(query, pagination) { - var chainable = this.getFactory().activityMap(this); + const chainable = this.getFactory().activityMap(this); // prepare params (with pagination) - var params = {}; + const params = {}; if (pagination) { Gitana.copyInto(params, pagination); @@ -400,19 +401,19 @@ */ readRole: function(roleKeyOrId, inherited) { - var params = {}; + const params = {}; if (inherited) { params.inherited = true; } - var uriFunction = function() + const uriFunction = function() { return this.getUri() + "/roles/" + roleKeyOrId; }; - var chainable = this.getFactory().role(this.getCluster(), this); + const chainable = this.getFactory().role(this.getCluster(), this); return this.chainGet(chainable, uriFunction, params); }, @@ -425,19 +426,19 @@ */ listRoles: function(inherited) { - var params = {}; + const params = {}; if (inherited) { params.inherited = true; } - var uriFunction = function() + const uriFunction = function() { return this.getUri() + "/roles"; }; - var chainable = this.getFactory().roleMap(this.getCluster(), this); + const chainable = this.getFactory().roleMap(this.getCluster(), this); return this.chainGet(chainable, uriFunction, params); }, @@ -457,14 +458,14 @@ } object.roleKey = roleKey; - var uriFunction = function() + const uriFunction = function() { return this.getUri() + "/roles"; }; - var self = this; + const self = this; - var chainable = this.getFactory().role(this.getPlatform(), this, roleKey); + const chainable = this.getFactory().role(this.getPlatform(), this, roleKey); return this.chainPostResponse(chainable, uriFunction, {}, object).then(function() { this.subchain(self).readRole(roleKey).then(function() { Gitana.copyInto(chainable, this); diff --git a/js/gitana/Gitana.js b/js/gitana/Gitana.js index 7f944b73..0685dac3 100644 --- a/js/gitana/Gitana.js +++ b/js/gitana/Gitana.js @@ -10,18 +10,19 @@ * * Configuration options should look like: * - * { - * "clientKey": {String} the oauth2 client id, - * "clientSecret": [String] the oauth2 client secret, - * "baseURL": [String] the relative URI path of the base URL (assumed to be "/proxy"), - * "locale": [String] optional locale (assumed to be en_US), - * "storage": [String|Object] Gitana.OAuth2.Storage implementation or a string identifying where to store + * @param settings + * @param settings.clientKey: {String} the oauth2 client id, + * @param settings.clientSecret: {String} the oauth2 client secret, + * @param settings.baseURL: {String} the relative URI path of the base URL (assumed to be "/proxy"), + * @param settings.locale: {String} optional locale (assumed to be en_US), + * @param settings.storage: {String|Object} Gitana.OAuth2.Storage implementation or a string identifying where to store * Gitana OAuth2 tokens ("local", "session", "memory") or empty for memory-only storage - * } + * @param settings.host {String} + * */ constructor: function(settings) { - var self = this; + const self = this; if (!settings) { @@ -37,7 +38,7 @@ this.stackInfo = {}; // build config - var config = { + const config = { "clientKey": null, "clientSecret": null, "baseURL": "/proxy", @@ -48,7 +49,7 @@ }; if (Gitana.DEFAULT_CONFIG) { - for (var k in Gitana.DEFAULT_CONFIG) + for (let k in Gitana.DEFAULT_CONFIG) { if (Gitana.DEFAULT_CONFIG.hasOwnProperty(k)) { @@ -95,7 +96,7 @@ // // set up our oAuth2 connection - var options = {}; + const options = {}; if (config.clientKey) { options.clientKey = config.clientKey; } @@ -128,7 +129,7 @@ this.resetHttp = function(config) { - var o = {}; + const o = {}; Gitana.copyInto(o, options); if (config) @@ -166,9 +167,9 @@ this.getHttpHeaders = function() { - var self = this; + const self = this; - var headers = {}; + const headers = {}; if (self.http && self.http.getBearerAuthorizationHeader()) { @@ -231,12 +232,12 @@ { if (typeof console != "undefined") { - var message = "Received bad http state (" + http.status + ")"; - var stacktrace = null; + let message = "Received bad http state (" + http.status + ")"; + let stacktrace = null; - var json = null; + let json = null; - var responseText = http.responseText; + const responseText = http.responseText; if (responseText) { json = JSON.parse(responseText); @@ -285,7 +286,6 @@ */ ajax: function(method, url, contentType, data, headers, successCallback, failureCallback) { - var _this = this; // ensure headers if (!headers) @@ -294,20 +294,20 @@ } // treat the method - if (method == null) { + if (method === null) { method = "GET"; } method = method.toUpperCase(); // flags - var json = false; - if (contentType == "application/json") + let json = false; + if (contentType === "application/json") { json = true; } // error checking - if ( (method == "POST" || method == "PUT") ) + if ( (method === "POST" || method === "PUT") ) { headers["Content-Type"] = contentType; if (!contentType) @@ -317,13 +317,13 @@ } } - var toSend = data; + let toSend = data; // special handling for json if (json) { // if empty payload for payload-bearing methods, populate with {} - if (method == "PUT" || method == "POST") + if (method === "PUT" || method === "POST") { if (!data) { @@ -344,13 +344,13 @@ // // otherwise, we can't handle relative URLs // - if (url.substring(0,1) == "/") + if (url.substring(0,1) === "/") { // if window.location exists, then we're running on a browser if (!Gitana.isUndefined(window.location)) { - var u = window.location.protocol + "//" + window.location.host; - if (window.location.host.indexOf(":") == -1) + let u = window.location.protocol + "//" + window.location.host; + if (window.location.host.indexOf(":") === -1) { if (window.location.port) { u += ":" + window.location.port; @@ -365,7 +365,7 @@ } } - var config = { + const config = { "method": method, "url": url, "data": toSend, @@ -394,8 +394,9 @@ * @param {String} method The kind of method to invoke - "get", "post", "put", or "del" * @param {String} url Either a full URL (i.e. "http://server:port/uri") or a URI against the driver's server URL (i.e. /repositories/...) * @param {Object} params parameter map - * @param [String] contentType If the case of a payload carrying request (i.e. not GET), the content type being sent. + * @param {String} contentType If the case of a payload carrying request (i.e. not GET), the content type being sent. * @param {Object} data In the case of a payload carrying request (i.e. not GET), the JSON to plug into the payload. + * @param headers * @param {Function} [successCallback] The function to call if the operation succeeds. * @param {Function} [failureCallback] The function to call if the operation fails. */ @@ -409,16 +410,16 @@ // if url has query string params, move into params // strip back url so that it does not have query params - var x1 = url.indexOf("?"); + const x1 = url.indexOf("?"); if (x1 > -1) { - var qs = url.substring(x1 + 1); + const qs = url.substring(x1 + 1); url = url.substring(0, x1); - var parts = qs.split("&"); - for (var x2 = 0; x2 < parts.length; x2++) + const parts = qs.split("&"); + for (let x2 = 0; x2 < parts.length; x2++) { - var keyValuePair = parts[x2].split("="); + const keyValuePair = parts[x2].split("="); params[keyValuePair[0]] = keyValuePair[1]; } } @@ -444,14 +445,14 @@ * @param responseObject * @param xhr */ - var onSuccess = function(responseObject, xhr) + const onSuccess = function(responseObject, xhr) { if (successCallback) { // call back with just the response text (or json) - var arg = responseObject.text; - if (contentType == "application/json") + let arg = responseObject.text; + if (contentType === "application/json") { try { arg = new Gitana.Response(JSON.parse(arg)); @@ -470,11 +471,11 @@ * @param responseObject * @param xhr */ - var onFailure = function(responseObject, xhr) + const onFailure = function(responseObject, xhr) { if (failureCallback) { - var httpError = {}; + const httpError = {}; if (responseObject && responseObject.timeout) { @@ -504,16 +505,16 @@ httpError["response"] = responseObject; } - var message = null; - var stacktrace = null; + let message = null; + let stacktrace = null; if (contentType === "application/json") { try { - var arg = responseObject.text; + const arg = responseObject.text; - var obj = new Gitana.Response(JSON.parse(arg)); + const obj = new Gitana.Response(JSON.parse(arg)); if (obj.message) { message = obj.message; @@ -542,7 +543,7 @@ // copy in globally defined params if (Gitana.HTTP_PARAMS) { - for (var k in Gitana.HTTP_PARAMS) + for (let k in Gitana.HTTP_PARAMS) { if (Gitana.HTTP_PARAMS.hasOwnProperty(k)) { @@ -554,7 +555,7 @@ // copy in globally defined headers if (Gitana.HTTP_HEADERS) { - for (var k in Gitana.HTTP_HEADERS) + for (let k in Gitana.HTTP_HEADERS) { if (Gitana.HTTP_HEADERS.hasOwnProperty(k)) { @@ -588,7 +589,7 @@ } // cache buster - var cacheBuster = null; + let cacheBuster = null; if (this.getOriginalConfiguration().cacheBuster === true) { cacheBuster = new Date().getTime(); @@ -607,9 +608,9 @@ } // update URL to include params - for (var paramKey in params) + for (let paramKey in params) { - var paramValue = params[paramKey]; + let paramValue = params[paramKey]; if (Gitana.isFunction(paramValue)) { paramValue = paramValue.call(); @@ -697,7 +698,7 @@ * @param {String} url Either a full URL (i.e. "http://server:port/uri") or a URI against the driver's server URL (i.e. /repositories/...) * @param {Object} params request parameters * @param {String} contentType content type being sent - * @param {Object} [jsonData] The JSON to plug into the payload. + * @param {Object} data The JSON to plug into the payload. * @param {Function} [successCallback] The function to call if the operation succeeds. * @param {Function} [failureCallback] The function to call if the operation fails. */ @@ -808,14 +809,14 @@ * @chained platform * * @param {Object} settings - * @param [Function] authentication failure handler + * @param {Function} authFailureHandler failure handler */ authenticate: function(settings, authFailureHandler) { - var driver = this; + const driver = this; // build config - var config = { + const config = { "code": null, "redirectUri": null, "username": null, @@ -853,7 +854,7 @@ } // platform config (for cache key determination) - var platformConfig = { + const platformConfig = { "key": null, "ticket": null, "username": null, @@ -861,7 +862,7 @@ }; Gitana.copyKeepers(platformConfig, this.getOriginalConfiguration()); Gitana.copyKeepers(platformConfig, settings); - var platformCacheKey = platformConfig.key; + let platformCacheKey = platformConfig.key; if (!platformCacheKey) { platformCacheKey = Gitana.determinePlatformCacheKey(platformConfig, true); @@ -871,38 +872,38 @@ this.platformCacheKey = platformCacheKey; } - var params = {}; - var headers = {}; + const params = {}; + const headers = {}; // copy in any custom headers if (config.headers) { - for (var k in config.headers) { - headers[k] = config.headers[k]; + for (const header in config.headers) { + headers[header] = config.headers[header]; } } // build a cluster instance - var cluster = new Gitana.Cluster(this, {}); + const cluster = new Gitana.Cluster(this, {}); - var applyPlatformCache = function(driver, platform) + const applyPlatformCache = function(driver, platform) { - var platformCacheKey = driver.platformCacheKey; + const platformCacheKey = driver.platformCacheKey; if (platformCacheKey) { Gitana.PLATFORM_CACHE(platformCacheKey, platform); } // always cache on ticket as well - var ticket = driver.getAuthInfo().getTicket(); + const ticket = driver.getAuthInfo().getTicket(); if (ticket) { Gitana.PLATFORM_CACHE(ticket, platform); } }; // run with this = platform - var doAuthenticate = function() + const doAuthenticate = function() { - var platform = this; + const platform = this; // we provide a fallback if no flow type is specified, using "password" flow with guest/guest if (!config.code && !config.username && !config.accessToken && !config.cookie && !config.ticket) @@ -924,7 +925,7 @@ // fetch the auth info driver.gitanaGet("/auth/info", params, headers, function(response) { - var authInfo = new Gitana.AuthInfo(response); + const authInfo = new Gitana.AuthInfo(response); driver.setAuthInfo(authInfo); // TODO: fix this @@ -962,7 +963,7 @@ // retrieve auth info and plug into the driver driver.gitanaGet("/auth/info", params, headers, function(response) { - var authInfo = new Gitana.AuthInfo(response); + const authInfo = new Gitana.AuthInfo(response); driver.setAuthInfo(authInfo); // TODO: fix this @@ -1001,7 +1002,7 @@ // fetch the auth info driver.gitanaGet("/auth/info", params, headers, function(response) { - var authInfo = new Gitana.AuthInfo(response); + const authInfo = new Gitana.AuthInfo(response); driver.setAuthInfo(authInfo); // TODO: fix this @@ -1039,7 +1040,7 @@ // fetch the auth info driver.gitanaGet("/auth/info", params, headers, function(response) { - var authInfo = new Gitana.AuthInfo(response); + const authInfo = new Gitana.AuthInfo(response); driver.setAuthInfo(authInfo); if (authInfo.accessToken) @@ -1084,7 +1085,7 @@ // fetch the auth info driver.gitanaGet("/auth/info", params, headers, function(response) { - var authInfo = new Gitana.AuthInfo(response); + const authInfo = new Gitana.AuthInfo(response); driver.setAuthInfo(authInfo); // TODO: fix this @@ -1111,7 +1112,7 @@ } else { - var message = "Unsupported authentication flow - you must provide either a username, authorization code, access token or select cookie-based authentication"; + const message = "Unsupported authentication flow - you must provide either a username, authorization code, access token or select cookie-based authentication"; if (authFailureHandler) { @@ -1126,7 +1127,7 @@ } }; - var result = this.getFactory().platform(cluster); + const result = this.getFactory().platform(cluster); return Chain(result).then(function() { // NOTE: this = platform @@ -1140,11 +1141,11 @@ reloadAuthInfo: function(callback) { - var driver = this; + const driver = this; driver.gitanaGet("/auth/info", {}, {}, function(response) { - var authInfo = new Gitana.AuthInfo(response); + const authInfo = new Gitana.AuthInfo(response); driver.setAuthInfo(authInfo); callback(); @@ -1203,7 +1204,7 @@ // temporary location for this code Gitana.toCopyDependencyChain = function(typedID) { - var array = []; + let array = []; if (typedID.getType() === "node") { @@ -1328,7 +1329,7 @@ Gitana.handleJobCompletion = function(chain, cluster, jobId, synchronous, reportFn) { - var jobFinalizer = function() { + const jobFinalizer = function() { return Chain(cluster).readJob(jobId).then(function() { @@ -1336,7 +1337,7 @@ reportFn(this); } - if (!synchronous || (synchronous && (this.getState() == "FINISHED" || this.getState() == "ERROR"))) + if (!synchronous || (synchronous && (this.getState() === "FINISHED" || this.getState() === "ERROR"))) { chain.loadFrom(this); chain.next(); @@ -1366,7 +1367,7 @@ */ Gitana.MemoryCache = function() { - var cache = {}; + const cache = {}; return function(k, v) { @@ -1381,14 +1382,14 @@ } // support for "clear" method - removes everything from cache - if (k == "clear") + if (k === "clear") { - var za = []; - for (var z in cache) + const za = []; + for (let z in cache) { za.push(z); } - for (var i = 0; i < za.length; i++) + for (let i = 0; i < za.length; i++) { delete cache[za[i]]; } @@ -1410,7 +1411,7 @@ Gitana.determinePlatformCacheKey = function(config, fallbackToDefault) { - var cacheKey = null; + let cacheKey = null; // "ticket" authentication - key = ticket if (config.ticket) { @@ -1432,7 +1433,7 @@ * Connects to a Gitana platform. * * @param config - * @param [callback] optional callback function that gets called once the server has been connected to. If no + * @param callback {Object} optional callback function that gets called once the server has been connected to. If no * "application" config parameter is present, then the callback function is called with the this * context set to the platform. If an "application" config parameter is present, then the stack * for the application is loaded and references are resolved and the this context will be the @@ -1449,7 +1450,7 @@ config = null; } - var missingConfig = false; + let missingConfig = false; if (!config) { config = {}; @@ -1461,7 +1462,7 @@ } // by default, set invalidatePlatformCache to false - if (typeof(config.invalidatePlatformCache) == "undefined") + if (typeof(config.invalidatePlatformCache) === "undefined") { config.invalidatePlatformCache = false; } @@ -1473,14 +1474,14 @@ } // default to load app helper if not defined - if (typeof(config.loadAppHelper) == "undefined") + if (typeof(config.loadAppHelper) === "undefined") { config.loadAppHelper = true; } // this gets called once the platform is drawn from cache or created // fires the callback and passes in the platform or the app helper - var setupContext = function(platformCacheKey) + const setupContext = function(platformCacheKey) { // NOTE: this == platform @@ -1488,7 +1489,7 @@ // note that config.application could be undefined (we require explicit NULL here for copyKeepers) if (config.loadAppHelper) { - var appConfig = { + const appConfig = { "application": (config.application ? config.application: null), "appCacheKey": null }; @@ -1497,7 +1498,7 @@ Gitana.copyKeepers(appConfig, config); if (appConfig.application) { - var appSettings = { + const appSettings = { "application": appConfig.application }; if (appConfig.appCacheKey) { @@ -1538,7 +1539,7 @@ } // either retrieve platform from cache or authenticate - var platform = null; + let platform = null; if (config.key) { platform = Gitana.PLATFORM_CACHE(config.key); } @@ -1591,7 +1592,7 @@ key = "default"; } - var platform = Gitana.PLATFORM_CACHE(key); + const platform = Gitana.PLATFORM_CACHE(key); if (platform) { // if we are meant to expire the server-side access token, @@ -1606,20 +1607,20 @@ }); } - var badKeys = []; - for (var k in Gitana.APPS) + const badKeys = []; + for (let k in Gitana.APPS) { - if (k.indexOf(key + "_") == 0) + if (k.indexOf(key + "_") === 0) { badKeys.push(k); } } - for (var i = 0; i < badKeys.length; i++) + for (let i = 0; i < badKeys.length; i++) { delete Gitana.APPS[badKeys[i]]; } - var ticket = platform.getDriver().getAuthInfo().getTicket(); + const ticket = platform.getDriver().getAuthInfo().getTicket(); if (ticket) { Gitana.PLATFORM_CACHE(ticket, null); diff --git a/js/gitana/GitanaAutoConfig.js b/js/gitana/GitanaAutoConfig.js index e6b9b598..189c7723 100644 --- a/js/gitana/GitanaAutoConfig.js +++ b/js/gitana/GitanaAutoConfig.js @@ -8,8 +8,8 @@ { if (typeof(Gitana.autoConfigUri) === "undefined") { - var uri = window.location.href; - var z1 = uri.indexOf(window.location.pathname); + let uri = window.location.href; + let z1 = uri.indexOf(window.location.pathname); z1 = uri.indexOf("/", z1 + 2); if (z1 > -1) { diff --git a/js/gitana/ObjectFactory.js b/js/gitana/ObjectFactory.js index 80c87d07..1bc9c5a9 100644 --- a/js/gitana/ObjectFactory.js +++ b/js/gitana/ObjectFactory.js @@ -1,6 +1,6 @@ (function(window) { - var Gitana = window.Gitana; + Gitana = window.Gitana; /** * Object factory @@ -14,9 +14,7 @@ { this.create = function(klass, existing, object) { - var created = new klass(existing, object); - - return created; + return new klass(existing, object); }; }, @@ -27,7 +25,7 @@ platformDataStore: function(platform, object) { - var type = object.datastoreTypeId; + const type = object.datastoreTypeId; return this[type](platform, object); }, @@ -47,7 +45,7 @@ job: function(cluster, object) { - var type = null; + let type = null; if (object) { @@ -61,16 +59,16 @@ } } - var job = null; - if ("copy" == type) + let job = null; + if ("copy" === type) { job = this.create(Gitana.CopyJob, cluster, object); } - else if ("export" == type) + else if ("export" === type) { job = this.create(Gitana.TransferExportJob, cluster, object); } - else if ("import" == type) + else if ("import" === type) { job = this.create(Gitana.TransferImportJob, cluster, object); } @@ -267,7 +265,7 @@ client: function(platform, object) { - var client = this.create(Gitana.Client, platform, object); + const client = this.create(Gitana.Client, platform, object); Gitana.stampInto(client, Gitana.ClientMethods); return client; @@ -415,7 +413,7 @@ */ node: function(branch, object) { - var objectClass = null; + let objectClass = null; if (object) { @@ -428,7 +426,7 @@ } // see if we can derive a more accurate type - var type = object["_type"]; + const type = object["_type"]; if (type) { if (Gitana.ObjectFactory.registry[type]) @@ -539,7 +537,7 @@ domainPrincipal: function(domain, object) { // create the principal - var principal = this.create(Gitana.DomainPrincipal, domain, object); + const principal = this.create(Gitana.DomainPrincipal, domain, object); // extend the principal pre-emptively if we have an object if (object) @@ -557,13 +555,13 @@ extendPrincipal: function(principal) { - if (principal.getType() && principal.objectType() == "Gitana.DomainPrincipal") + if (principal.getType() && principal.objectType() === "Gitana.DomainPrincipal") { - if (principal.getType() == "USER") + if (principal.getType() === "USER") { Gitana.stampInto(principal, Gitana.DomainUser); } - else if (principal.getType() == "GROUP") + else if (principal.getType() === "GROUP") { Gitana.stampInto(principal, Gitana.DomainGroup); } diff --git a/js/gitana/Response.js b/js/gitana/Response.js index c0dcacd2..b5b882ee 100644 --- a/js/gitana/Response.js +++ b/js/gitana/Response.js @@ -1,6 +1,6 @@ (function(window) { - var Gitana = window.Gitana; + Gitana = window.Gitana; Gitana.Response = Base.extend( /** @lends Gitana.Response.prototype */ @@ -75,7 +75,7 @@ isOk: function() { // assume things are ok - var ok = true; + let ok = true; if (this.isStatusDocument()) { if (this["ok"] != null) { diff --git a/js/gitana/ResultMap.js b/js/gitana/ResultMap.js index 74560d04..840a140d 100644 --- a/js/gitana/ResultMap.js +++ b/js/gitana/ResultMap.js @@ -1,6 +1,6 @@ (function(window) { - var Gitana = window.Gitana; + Gitana = window.Gitana; Gitana.ResultMap = Gitana.AbstractMap.extend( /** @lends Gitana.ResultMap.prototype */ @@ -12,7 +12,7 @@ * @class Generalized result maps * * @param {Gitana} driver - * @param [Object] resultMap + * @param {Object} resultMap */ constructor: function(driver, resultMap) { diff --git a/js/gitana/Role.js b/js/gitana/Role.js index 63298d99..cf25b8c7 100644 --- a/js/gitana/Role.js +++ b/js/gitana/Role.js @@ -1,6 +1,6 @@ (function(window) { - var Gitana = window.Gitana; + Gitana = window.Gitana; Gitana.Role = Gitana.AbstractObject.extend( /** @lends Gitana.Role.prototype */ @@ -13,8 +13,7 @@ * * @param {Gitana.Cluster} cluster * @param {Object} roleContainer - * @param {String} roleKey - * @param [Object] object json object (if no callback required for populating) + * @param {Object} object json object (if no callback required for populating) */ constructor: function(cluster, roleContainer, object) { @@ -49,7 +48,7 @@ */ del: function() { - var uriFunction = function() + const uriFunction = function() { return this.getUri(); }; @@ -67,7 +66,7 @@ */ reload: function() { - var uriFunction = function() + const uriFunction = function() { return this.getUri(); }; @@ -84,7 +83,7 @@ */ update: function() { - var uriFunction = function() + const uriFunction = function() { return this.getUri(); }; diff --git a/js/gitana/RoleMap.js b/js/gitana/RoleMap.js index 6dec0f28..dd6a5572 100644 --- a/js/gitana/RoleMap.js +++ b/js/gitana/RoleMap.js @@ -1,6 +1,6 @@ (function(window) { - var Gitana = window.Gitana; + Gitana = window.Gitana; Gitana.RoleMap = Gitana.AbstractMap.extend( /** @lends Gitana.RoleMap.prototype */ @@ -12,8 +12,8 @@ * @class Map of roles * * @param {Gitana.Cluster} cluster Gitana cluster instance. - * @param {Object} role container - * @param [Object] object + * @param {Object} roleContainer container + * @param {Object} object */ constructor: function(cluster, roleContainer, object) { diff --git a/js/gitana/SystemMetadata.js b/js/gitana/SystemMetadata.js index 7666161a..6ee68340 100644 --- a/js/gitana/SystemMetadata.js +++ b/js/gitana/SystemMetadata.js @@ -1,6 +1,6 @@ (function(window) { - var Gitana = window.Gitana; + Gitana = window.Gitana; Gitana.SystemMetadata = Base.extend( /** @lends Gitana.SystemMetadata.prototype */ diff --git a/js/gitana/Team.js b/js/gitana/Team.js index cdd5374b..cadee3f3 100644 --- a/js/gitana/Team.js +++ b/js/gitana/Team.js @@ -1,6 +1,6 @@ (function(window) { - var Gitana = window.Gitana; + Gitana = window.Gitana; Gitana.Team = Gitana.AbstractObject.extend( /** @lends Gitana.Team.prototype */ @@ -13,12 +13,12 @@ * * @param {Gitana.Cluster} cluster * @param {Object} teamable - * @param [Object] object json object (if no callback required for populating) + * @param {Object} object json object (if no callback required for populating) */ constructor: function(cluster, teamable, object) { this.__teamable = (function() { - var _teamable = null; + let _teamable = null; return function(teamable) { if (!Gitana.isUndefined(teamable)) { _teamable = teamable; } return _teamable; @@ -64,7 +64,7 @@ */ del: function() { - var uriFunction = function() + const uriFunction = function() { return this.getUri(); }; @@ -82,7 +82,7 @@ */ reload: function() { - var uriFunction = function() + const uriFunction = function() { return this.getUri(); }; @@ -99,7 +99,7 @@ */ update: function() { - var uriFunction = function() + const uriFunction = function() { return this.getUri(); }; @@ -110,17 +110,17 @@ /** * Adds a member to the team. * - * @param {String|Object} either the principal object or the principal id + * @param {String|Object} principal either the principal object or the principal id * * @chained team */ addMember: function(principal) { - var self = this; + const self = this; - var uriFunction = function() + const uriFunction = function() { - var principalDomainQualifiedId = self.extractPrincipalDomainQualifiedId(principal); + const principalDomainQualifiedId = self.extractPrincipalDomainQualifiedId(principal); return this.getUri() + "/members/add?id=" + principalDomainQualifiedId; }; @@ -131,15 +131,15 @@ /** * Removes a member from the team. * - * @param {String|Object} either the principal object or the principal id + * @param {String|Object} principal - either the principal object or the principal id * * @chained team */ removeMember: function(principal) { - var principalDomainQualifiedId = this.extractPrincipalDomainQualifiedId(principal); + const principalDomainQualifiedId = this.extractPrincipalDomainQualifiedId(principal); - var uriFunction = function() + const uriFunction = function() { return this.getUri() + "/members/remove?id=" + principalDomainQualifiedId; }; @@ -150,21 +150,21 @@ /** * Checks whether a principal is a member of the team. * - * @param {String|Object} either the principal object or the principal id + * @param {String|Object} principal -either the principal object or the principal id * @param callback function(check) * * @chained team */ hasMember: function(principal, callback) { - var self = this; + const self = this; - var uriFunction = function() + const uriFunction = function() { return this.getUri() + "/members/check"; }; - var params = {}; + const params = {}; params.id = self.extractPrincipalDomainQualifiedId(principal); return this.chainPostResponse(null, uriFunction, params).then(function(response) { @@ -182,18 +182,18 @@ */ listMembers: function(pagination) { - var params = {}; + const params = {}; if (pagination) { Gitana.copyInto(params, pagination); } - var uriFunction = function() + const uriFunction = function() { return this.getUri() + "/members"; }; - var chainable = new Gitana.TeamMemberMap(this); + const chainable = new Gitana.TeamMemberMap(this); return this.chainGet(chainable, uriFunction, params); }, @@ -206,7 +206,7 @@ */ grant: function(authorityId) { - var uriFunction = function() + const uriFunction = function() { return this.getUri() + "/authorities/" + authorityId + "/grant"; }; @@ -223,7 +223,7 @@ */ revoke: function(authorityId) { - var uriFunction = function() + const uriFunction = function() { return this.getUri() + "/authorities/" + authorityId + "/revoke"; }; @@ -240,7 +240,7 @@ */ loadAuthorities: function(callback) { - var uriFunction = function() + const uriFunction = function() { return this.getUri() + "/authorities"; }; diff --git a/js/gitana/TeamMap.js b/js/gitana/TeamMap.js index db8e641b..c88b1cac 100644 --- a/js/gitana/TeamMap.js +++ b/js/gitana/TeamMap.js @@ -1,6 +1,6 @@ (function(window) { - var Gitana = window.Gitana; + Gitana = window.Gitana; Gitana.TeamMap = Gitana.AbstractMap.extend( /** @lends Gitana.TeamMap.prototype */ @@ -13,12 +13,12 @@ * * @param {Gitana.Cluster} cluster Gitana cluster instance. * @param {Object} teamable - * @param [Object] object + * @param {Object} object */ constructor: function(cluster, teamable, object) { this.__teamable = (function() { - var _teamable = null; + let _teamable = null; return function(teamable) { if (!Gitana.isUndefined(teamable)) { _teamable = teamable; } return _teamable; diff --git a/js/gitana/TeamMember.js b/js/gitana/TeamMember.js index 87cb7490..1c52754a 100644 --- a/js/gitana/TeamMember.js +++ b/js/gitana/TeamMember.js @@ -1,6 +1,6 @@ (function(window) { - var Gitana = window.Gitana; + Gitana = window.Gitana; Gitana.TeamMember = Gitana.AbstractObject.extend( /** @lends Gitana.TeamMember.prototype */ @@ -11,8 +11,8 @@ * * @class TeamMember * - * @param {Gitana.Cluster} cluster - * @param [Object] object json object (if no callback required for populating) + * @param {Gitana.Cluster} team + * @param {Object} object json object (if no callback required for populating) */ constructor: function(team, object) { @@ -37,9 +37,9 @@ domain: function() { - var self = this; + const self = this; - var result = this.subchain(new Gitana.Domain({ + const result = this.subchain(new Gitana.Domain({ "_doc": this.domainId })); @@ -50,21 +50,21 @@ principal: function() { - var self = this; + const self = this; // domain - var domain = new Gitana.Domain({ + const domain = new Gitana.Domain({ "" }) // temp web host - var webhost = new Gitana.WebHost(this.getPlatform()); + const webhost = new Gitana.WebHost(this.getPlatform()); // we hand back a deployed application and preload some work - var chainable = this.getFactory().deployedApplication(webhost); + const chainable = this.getFactory().deployedApplication(webhost); return this.chainPost(chainable, uriFunction).then(function() { // load the real web host - var webhostId = self["deployments"][deploymentKey]["webhost"]; + const webhostId = self["deployments"][deploymentKey]["webhost"]; this.subchain(this.getPlatform()).readWebHost(webhostId).then(function() { webhost.loadFrom(this); }); diff --git a/js/gitana/TeamMemberMap.js b/js/gitana/TeamMemberMap.js index 5af518c2..10d85b89 100644 --- a/js/gitana/TeamMemberMap.js +++ b/js/gitana/TeamMemberMap.js @@ -1,6 +1,6 @@ (function(window) { - var Gitana = window.Gitana; + Gitana = window.Gitana; Gitana.TeamMemberMap = Gitana.AbstractMap.extend( /** @lends Gitana.TeamMemberMap.prototype */ @@ -12,7 +12,7 @@ * @class Map of team members * * @param {Gitana.Team} team - * @param [Object] object + * @param {Object} object */ constructor: function(team, object) { diff --git a/js/gitana/Timestamp.js b/js/gitana/Timestamp.js index 9d6a9b55..6219e000 100644 --- a/js/gitana/Timestamp.js +++ b/js/gitana/Timestamp.js @@ -1,6 +1,6 @@ (function(window) { - var Gitana = window.Gitana; + Gitana = window.Gitana; Gitana.Timestamp = Base.extend( /** @lends Gitana.Timestamp.prototype */ @@ -18,7 +18,7 @@ }, /** - * @returns {Integer} the year + * @returns {number} the year */ getYear: function() { @@ -26,7 +26,7 @@ }, /** - @returns {Integer} the month + @returns {number} the month */ getMonth: function() { @@ -34,7 +34,7 @@ }, /** - * @returns {Integer} the day of the month + * @returns {number} the day of the month */ getDay: function() { @@ -42,7 +42,7 @@ }, /** - * @returns {Integer} the hour of the day (24 hour clock) + * @returns {number} the hour of the day (24 hour clock) */ getHour: function() { @@ -50,7 +50,7 @@ }, /** - * @returns {Integer} the minute + * @returns {number} the minute */ getMinute: function() { @@ -58,7 +58,7 @@ }, /** - * @returns {Integer} the second + * @returns {number} the second */ getSecond: function() { @@ -66,7 +66,7 @@ }, /** - * @returns {Integer} the millisecond (0-1000) + * @returns {number} the millisecond (0-1000) */ getMillisecond: function() { @@ -74,7 +74,7 @@ }, /** - * @returns {Integer} absolute millisecond + * @returns {number} absolute millisecond */ getTime: function() { diff --git a/js/gitana/Utils.js b/js/gitana/Utils.js index 35972c45..5f3cd81f 100644 --- a/js/gitana/Utils.js +++ b/js/gitana/Utils.js @@ -7,7 +7,7 @@ * * @inner * - * @param {arguments} arguments + * @param {arguments} args * * @returns {Array} an array */ @@ -27,7 +27,7 @@ */ Gitana.stringify = function(object, pretty) { - var val = null; + let val = null; if (!Gitana.isEmpty(object)) { @@ -54,7 +54,7 @@ * @returns {Boolean} whether it is a String */ Gitana.isString = function( arg ) { - return (typeof arg == "string"); + return (typeof arg === "string"); }; /** @@ -67,7 +67,7 @@ * @returns {Boolean} whether it is a Number */ Gitana.isNumber = function( arg ) { - return (typeof arg == "number"); + return (typeof arg === "number"); }; /** @@ -80,7 +80,7 @@ * @returns {Boolean} whether it is a Boolean */ Gitana.isBoolean = function( arg ) { - return (typeof arg == "boolean"); + return (typeof arg === "boolean"); }; /** @@ -131,7 +131,7 @@ * @param {Object} source Source object. */ Gitana.copyInto = function(target, source) { - for (var i in source) { + for (let i in source) { if (source.hasOwnProperty(i) && !this.isFunction(source[i])) { target[i] = source[i]; } @@ -144,14 +144,15 @@ * @inner * * @param object {Object} object + * @param deleteFunctions */ Gitana.deleteProperties = function(object, deleteFunctions) { - var keys = []; - for (var k in object) { keys.push(k); } + const keys = []; + for (let k in object) { keys.push(k); } - for (var i = 0; i < keys.length; i++) + for (let i = 0; i < keys.length; i++) { - var key = keys[i]; + const key = keys[i]; if (object.hasOwnProperty(key)) { if (!Gitana.isFunction(object[key]) || (deleteFunctions && Gitana.isFunction(object[key]))) { @@ -171,7 +172,7 @@ * @param {Object} source Source object. */ Gitana.stampInto = function(target, source) { - for (var i in source) + for (let i in source) { if (source.hasOwnProperty(i)) { @@ -182,7 +183,7 @@ Gitana.contains = function(a, obj) { - var i = a.length; + let i = a.length; while (i--) { if (a[i] === obj) @@ -200,12 +201,12 @@ Gitana.isUndefined = function(obj) { - return (typeof obj == "undefined"); + return (typeof obj === "undefined"); }; Gitana.isEmpty = function(obj) { - return this.isUndefined(obj) || obj == null; + return this.isUndefined(obj) || obj === null; }; Gitana.generateId = function() @@ -246,8 +247,8 @@ Gitana.getNumberOfKeys = function(map) { - var count = 0; - for (var key in map) { + let count = 0; + for (let key in map) { count++; } @@ -259,46 +260,46 @@ * * @param {String} name * @param {String} value - * @param [String] path optional path (assumed "/" if not provided) - * @param [Number] days optional # of days to store cookie + * @param {String} path optional path (assumed "/" if not provided) + * @param {Number} days optional # of days to store cookie * if null or -1, assume session cookie * if 0, assume expired cookie * if > 0, assume # of days - * @param [String] domain optional domain (otherwise assumes wildcard base domain) + * @param {String} domain optional domain (otherwise assumes wildcard base domain) */ Gitana.writeCookie = function(name, value, path, days, domain) { if (typeof(document) !== "undefined") { - var createCookie = function(name, value, path, days, host) + const createCookie = function(name, value, path, days, host) { // path if (!path) { path = "/"; } - var pathString = ";path=" + path; + const pathString = ";path=" + path; // expiration - var expirationString = ""; - if (typeof(days) == "undefined" || days == -1) + let expirationString = ""; + if (typeof(days) === "undefined" || days === -1) { // session cookie } - else if (days == 0) + else if (days === 0) { // expired cookie expirationString = ";expires=Thu, 01 Jan 1970 00:00:01 GMT"; } else if (days > 0) { - var date = new Date(); + const date = new Date(); date.setTime(date.getTime()+(days*24*60*60*1000)); expirationString = ";expires="+date.toGMTString(); } // domain - var domainString = ""; + let domainString = ""; if (host) { domainString = ";domain=" + host; @@ -319,7 +320,7 @@ */ Gitana.deleteCookie = function(name, path) { - var existsCookie = function(name, path) + const existsCookie = function(name) { return Gitana.readCookie(name); }; @@ -341,11 +342,11 @@ // see if we can resolve a domain if (window) { - var domain = window.location.host; + let domain = window.location.host; if (domain) { // remove :port - var i = domain.indexOf(":"); + const i = domain.indexOf(":"); if (i > -1) { domain = domain.substring(0, i); @@ -359,21 +360,26 @@ } }; + /** + * + * @param name + * @return {null} + */ Gitana.readCookie = function(name) { function _readCookie(name) { - var nameEQ = name + "="; - var ca = document.cookie.split(';'); - for (var i = 0; i < ca.length; i++) + const nameEQ = name + "="; + const ca = document.cookie.split(';'); + for (let i = 0; i < ca.length; i++) { - var c = ca[i]; - while (c.charAt(0)==' ') + let c = ca[i]; + while (c.charAt(0) ===' ') { c = c.substring(1,c.length); } - if (c.indexOf(nameEQ) == 0) + if (c.indexOf(nameEQ) === 0) { return c.substring(nameEQ.length,c.length); } @@ -381,7 +387,7 @@ return null; } - var value = null; + let value = null; if (typeof(document) !== "undefined") { @@ -392,15 +398,20 @@ }; + /** + * + * @param paramName + * @return {string|null} + */ Gitana.getCurrentQueryStringParameter = function(paramName) { - var searchString = window.location.search.substring(1), i, val, params = searchString.split("&"); + let searchString = window.location.search.substring(1), i, val, params = searchString.split("&"); for (i = 0; i < params.length; i++) { val = params[i].split("="); - if (val[0] == paramName) + if (val[0] === paramName) { return unescape(val[1]); } @@ -409,16 +420,21 @@ return null; }; + /** + * + * @param paramName + * @return {string|null} + */ Gitana.getCurrentHashStringParameter = function(paramName) { - var searchString = window.location.href.substring(window.location.href.indexOf("#") + 1); - var params = searchString.split("&"); + const searchString = window.location.href.substring(window.location.href.indexOf("#") + 1); + const params = searchString.split("&"); for (i = 0; i < params.length; i++) { val = params[i].split("="); - if (val[0] == paramName) + if (val[0] === paramName) { return unescape(val[1]); } @@ -427,11 +443,16 @@ return null; }; + /** + * + * @param string + * @return {string|string} + */ Gitana.btoa = function(string) { - var b64 = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/='; + const b64 = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/='; - var i = 0, length = string.length, ascii, index, output = ''; + let i = 0, length = string.length, ascii, index, output = ''; for (; i < length; i+=3) { ascii = [ @@ -472,7 +493,7 @@ if (!source) { return; } - for (var i in source) { + for (let i in source) { if (source.hasOwnProperty(i) && !this.isFunction(source[i])) { if (!Gitana.isUndefined(target[i])) { target[i] = source[i]; diff --git a/js/gitana/WorkQueue.js b/js/gitana/WorkQueue.js index 29af1cb3..1ac7d1bb 100644 --- a/js/gitana/WorkQueue.js +++ b/js/gitana/WorkQueue.js @@ -6,12 +6,12 @@ maxSize = 3; } - var blockExecution = false; + let blockExecution = false; - var pendingWorkFns = []; - var activeCount = 0; + const pendingWorkFns = []; + let activeCount = 0; - var processWork = function () { + const processWork = function () { // if another "thread" is running the processor, don't bother if (blockExecution) @@ -22,7 +22,7 @@ blockExecution = true; // add as many pending work items as we can, loop until full or no more pending - var process = true; + let process = true; do { // if nothing to work on, bail @@ -45,7 +45,7 @@ //console.log("Active work items: " + activeCount); // define execution function and splice/bind to 0th element from pending list - var executionFn = function(workFn) { + const executionFn = function(workFn) { return function() { workFn(function () { diff --git a/js/gitana/XHRCache.js b/js/gitana/XHRCache.js index f3ebd331..dc93a02c 100644 --- a/js/gitana/XHRCache.js +++ b/js/gitana/XHRCache.js @@ -1,7 +1,7 @@ (function(window) { - var cache = {}; - var expirationTimes = {}; + const cache = {}; + const expirationTimes = {}; /** * Simple memory XHR Cache @@ -12,16 +12,16 @@ { return function(descriptor, responseObject) { - var key = descriptor.method + "/" + descriptor.url; + let key = descriptor.method + "/" + descriptor.url; if (descriptor.headers) { - for (var headerName in descriptor.headers) + for (const headerName in descriptor.headers) { key += "/" + headerName + "=" + descriptor.headers[headerName]; } } - var now = new Date().getTime(); + const now = new Date().getTime(); if (responseObject) { diff --git a/js/gitana/application/AbstractApplicationObject.js b/js/gitana/application/AbstractApplicationObject.js index 2bdeae8c..c8653d7f 100644 --- a/js/gitana/application/AbstractApplicationObject.js +++ b/js/gitana/application/AbstractApplicationObject.js @@ -1,7 +1,7 @@ (function(window) { - var Gitana = window.Gitana; - + Gitana = window.Gitana; + Gitana.AbstractApplicationObject = Gitana.AbstractPlatformObject.extend( /** @lends Gitana.AbstractApplicationObject.prototype */ { @@ -12,7 +12,7 @@ * @class AbstractApplicationObject * * @param {Gitana.Application} application - * @param [Object] object json object (if no callback required for populating) + * @param {Object} object json object (if no callback required for populating) */ constructor: function(application, object) { diff --git a/js/gitana/application/Application.js b/js/gitana/application/Application.js index bcf2e138..36d3a6ca 100644 --- a/js/gitana/application/Application.js +++ b/js/gitana/application/Application.js @@ -1,7 +1,7 @@ (function(window) { - var Gitana = window.Gitana; - + Gitana = window.Gitana; + Gitana.Application = Gitana.AbstractPlatformDataStore.extend( /** @lends Gitana.Application.prototype */ { @@ -12,7 +12,7 @@ * @class Application * * @param {Gitana.Platform} platform - * @param [Object] object json object (if no callback required for populating) + * @param {Object}object json object (if no callback required for populating) */ constructor: function(platform, object) { @@ -55,15 +55,15 @@ */ listAutoClientMappingObjects: function(callback, pagination) { - var self = this; + const self = this; - var uriFunction = function() + const uriFunction = function () { - return self.getUri() + "/autoclientmappings"; + return self.getUri() + '/autoclientmappings'; }; // parameters - var params = {}; + const params = {}; if (pagination) { Gitana.copyInto(params, pagination); @@ -84,15 +84,15 @@ */ listTrustedDomainMappingObjects: function(callback, pagination) { - var self = this; + const self = this; - var uriFunction = function() + const uriFunction = function() { return self.getUri() + "/trusteddomainmappings"; }; // parameters - var params = {}; + const params = {}; if (pagination) { Gitana.copyInto(params, pagination); @@ -115,24 +115,24 @@ * * @chained settings * - * @param [Object] object JSON object + * @param {Object} object JSON object */ createSettings: function(object) { - var self = this; + const self = this; // Makes sure we have an empty settings key - if (object["settings"] == null) + if (object["settings"] === null) { object["settings"] = {}; } - var uriFunction = function() + const uriFunction = function() { return self.getUri() + "/settings"; }; - var chainable = this.getFactory().settings(this); + const chainable = this.getFactory().settings(this); return this.chainCreate(chainable, object, uriFunction); }, @@ -145,20 +145,20 @@ */ listSettings: function(pagination) { - var self = this; + const self = this; - var params = {}; + const params = {}; if (pagination) { Gitana.copyInto(params, pagination); } - var uriFunction = function() + const uriFunction = function() { return self.getUri() + "/settings"; }; - var chainable = this.getFactory().settingsMap(this); + const chainable = this.getFactory().settingsMap(this); return this.chainGet(chainable, uriFunction, params); }, @@ -171,14 +171,14 @@ */ readSettings: function(settingId) { - var self = this; + const self = this; - var uriFunction = function() + const uriFunction = function() { return self.getUri() + "/settings/" + settingId; }; - var chainable = this.getFactory().settings(this); + const chainable = this.getFactory().settings(this); return this.chainGet(chainable, uriFunction); }, @@ -188,24 +188,24 @@ * @chained settings map * * @param {Object} query - * @param [Object] pagination pagination (optional) + * @param {Object} pagination pagination (optional) */ querySettings: function(query, pagination) { - var self = this; + const self = this; - var params = {}; + const params = {}; if (pagination) { Gitana.copyInto(params, pagination); } - var uriFunction = function() + const uriFunction = function() { return self.getUri() + "/settings/query"; }; - var chainable = this.getFactory().settingsMap(this); + const chainable = this.getFactory().settingsMap(this); return this.chainPost(chainable, uriFunction, params, query); }, @@ -218,37 +218,37 @@ */ readApplicationSettings: function(scope, key) { - var self = this; + const self = this; - if (scope == null) + if (scope === null) { scope = "application"; } - if (key == null) + if (key === null) { key = "application"; } - var object = { + const object = { "scope" : scope, "key" : key }; - var result = this.subchain(new Gitana.Settings(this, object)); + const result = this.subchain(new Gitana.Settings(this, object)); return result.then(function() { - var chain = this; - var driver = self.getDriver(); - var createUri = self.getUri() + "/settings"; - var queryUri = self.getUri() + "/settings/query"; + const chain = this; + const driver = self.getDriver(); + const createUri = self.getUri() + "/settings"; + const queryUri = self.getUri() + "/settings/query"; driver.gitanaPost(queryUri, {}, object, function(response) { - var settings = new Gitana.SettingsMap(self); + const settings = new Gitana.SettingsMap(self); settings.handleResponse(response); if (settings.__keys().length > 0) { - var obj = settings[settings.__keys()[0]]; + const obj = settings[settings.__keys()[0]]; chain.loadFrom(obj); chain.next(); } @@ -280,17 +280,17 @@ */ readApplicationPrincipalSettings: function() { - var args = Gitana.makeArray(arguments); + const args = Gitana.makeArray(arguments); - if (args.length == 1) + if (args.length === 1) { - var principal = args.shift(); + const principal = args.shift(); return this.readApplicationSettings("principal", principal.getDomainQualifiedId()); } - else if (args.length == 2) + else if (args.length === 2) { - var domainId = args.shift(); - var principalId = args.shift(); + const domainId = args.shift(); + const principalId = args.shift(); return this.readApplicationSettings("principal", domainId + "/" + principalId); } @@ -323,14 +323,14 @@ */ checkSettingPermissions: function(checks, callback) { - var self = this; + const self = this; - var uriFunction = function() + const uriFunction = function() { return self.getUri() + "/settings/permissions/check"; }; - var object = { + const object = { "checks": checks }; @@ -366,14 +366,14 @@ */ checkSettingAuthorities: function(checks, callback) { - var self = this; + const self = this; - var uriFunction = function() + const uriFunction = function() { return self.getUri() + "/settings/authorities/check"; }; - var object = { + const object = { "checks": checks }; @@ -396,15 +396,15 @@ * * @chained registration * - * @param [Object] object JSON object + * @param {Object} object JSON object */ createRegistration: function(object) { - var self = this; + const self = this; - var chainable = this.getFactory().registration(this); + const chainable = this.getFactory().registration(this); - var uriFunction = function() + const uriFunction = function() { return self.getUri() + "/registrations"; }; @@ -421,20 +421,20 @@ */ listRegistrations: function(pagination) { - var self = this; + const self = this; - var params = {}; + const params = {}; if (pagination) { Gitana.copyInto(params, pagination); } - var uriFunction = function() + const uriFunction = function() { return self.getUri() + "/registrations"; }; - var chainable = this.getFactory().registrationMap(this); + const chainable = this.getFactory().registrationMap(this); return this.chainGet(chainable, uriFunction, params); }, @@ -447,11 +447,11 @@ */ readRegistration: function(registrationId) { - var self = this; + const self = this; - var chainable = this.getFactory().registration(this); + const chainable = this.getFactory().registration(this); - var uriFunction = function() + const uriFunction = function() { return self.getUri() + "/registrations/" + registrationId; }; @@ -465,24 +465,24 @@ * @chained registration map * * @param {Object} query - * @param [Object] pagination pagination (optional) + * @param {Object} pagination pagination (optional) */ queryRegistrations: function(query, pagination) { - var self = this; + const self = this; - var params = {}; + const params = {}; if (pagination) { Gitana.copyInto(params, pagination); } - var uriFunction = function() + const uriFunction = function() { return self.getUri() + "/registrations/query"; }; - var chainable = this.getFactory().registrationMap(this); + const chainable = this.getFactory().registrationMap(this); return this.chainPost(chainable, uriFunction, params, query); }, @@ -513,14 +513,14 @@ */ checkRegistrationPermissions: function(checks, callback) { - var self = this; + const self = this; - var uriFunction = function() + const uriFunction = function() { return self.getUri() + "/registrations/permissions/check"; }; - var object = { + const object = { "checks": checks }; @@ -556,14 +556,14 @@ */ checkRegistrationAuthorities: function(checks, callback) { - var self = this; + const self = this; - var uriFunction = function() + const uriFunction = function() { return self.getUri() + "/registrations/authorities/check"; }; - var object = { + const object = { "checks": checks }; @@ -585,16 +585,16 @@ * * @chained page rendition * - * @param {String} string deployment key - * @param [Object] object JSON object + * @param {String} deploymentKey string key + * @param {Object} object JSON object */ createPageRendition: function(deploymentKey, object) { - var self = this; + const self = this; - var chainable = this.getFactory().pageRendition(this, deploymentKey); + const chainable = this.getFactory().pageRendition(this, deploymentKey); - var uriFunction = function() + const uriFunction = function() { return self.getUri() + "/deployments/" + deploymentKey + "/pagerenditions"; }; @@ -605,45 +605,45 @@ /** * Lists the page renditions. * - * @param {String} string deployment key + * @param {String} deploymentKey string key * @param pagination * * @chained page rendition map */ listPageRenditions: function(deploymentKey, pagination) { - var self = this; + const self = this; - var params = {}; + const params = {}; if (pagination) { Gitana.copyInto(params, pagination); } - var uriFunction = function() + const uriFunction = function() { return self.getUri() + "/deployments/" + deploymentKey + "/pagerenditions"; }; - var chainable = this.getFactory().pageRenditionMap(this, deploymentKey); + const chainable = this.getFactory().pageRenditionMap(this, deploymentKey); return this.chainGet(chainable, uriFunction, params); }, /** * Reads a page rendition. * - * @param {String} string deployment key + * @param {String} deploymentKey string key * @param pageRenditionIdOrKey * * @chained registration */ readPageRendition: function(deploymentKey, pageRenditionIdOrKey) { - var self = this; + const self = this; - var chainable = this.getFactory().pageRendition(this, deploymentKey); + const chainable = this.getFactory().pageRendition(this, deploymentKey); - var uriFunction = function() + const uriFunction = function() { return self.getUri() + "/deployments/" + deploymentKey + "/pagerenditions/" + pageRenditionIdOrKey; }; @@ -656,26 +656,26 @@ * * @chained page rendition map * - * @param {String} string deployment key + * @param {String} deploymentKey string key * @param {Object} query - * @param [Object] pagination pagination (optional) + * @param {Object} pagination pagination (optional) */ queryPageRenditions: function(deploymentKey, query, pagination) { - var self = this; + const self = this; - var params = {}; + const params = {}; if (pagination) { Gitana.copyInto(params, pagination); } - var uriFunction = function() + const uriFunction = function() { return self.getUri() + "/deployments/" + deploymentKey + "/pagerenditions/query"; }; - var chainable = this.getFactory().pageRenditionMap(this, deploymentKey); + const chainable = this.getFactory().pageRenditionMap(this, deploymentKey); return this.chainPost(chainable, uriFunction, params, query); }, @@ -701,20 +701,20 @@ * * The order of elements in the array will be the same for checks and results. * - * @param {String} string deployment key + * @param {String} deploymentKey string key * @param checks * @param callback */ checkPageRenditionPermissions: function(deploymentKey, checks, callback) { - var self = this; + const self = this; - var uriFunction = function() + const uriFunction = function() { return self.getUri() + "/deployments/" + deploymentKey + "/pagerenditions/permissions/check"; }; - var object = { + const object = { "checks": checks }; @@ -745,20 +745,20 @@ * * The order of elements in the array will be the same for checks and results. * - * @param {String} string deployment key + * @param {String} deploymentKey string key * @param checks * @param callback */ checkPageRenditionAuthorities: function(deploymentKey, checks, callback) { - var self = this; + const self = this; - var uriFunction = function() + const uriFunction = function() { return self.getUri() + "/deployments/" + deploymentKey + "/pagerenditions/authorities/check"; }; - var object = { + const object = { "checks": checks }; @@ -781,15 +781,15 @@ * * @chained email provider * - * @param [Object] object JSON object + * @param {Object} object JSON object */ createEmailProvider: function(object) { - var self = this; + const self = this; - var chainable = this.getFactory().emailProvider(this); + const chainable = this.getFactory().emailProvider(this); - var uriFunction = function() + const uriFunction = function() { return self.getUri() + "/emailproviders"; }; @@ -806,20 +806,20 @@ */ listEmailProviders: function(pagination) { - var self = this; + const self = this; - var params = {}; + const params = {}; if (pagination) { Gitana.copyInto(params, pagination); } - var uriFunction = function() + const uriFunction = function() { return self.getUri() + "/emailproviders"; }; - var chainable = this.getFactory().emailProviderMap(this); + const chainable = this.getFactory().emailProviderMap(this); return this.chainGet(chainable, uriFunction, params); }, @@ -832,11 +832,11 @@ */ readEmailProvider: function(emailProviderId) { - var self = this; + const self = this; - var chainable = this.getFactory().emailProvider(this); + const chainable = this.getFactory().emailProvider(this); - var uriFunction = function() + const uriFunction = function() { return self.getUri() + "/emailproviders/" + emailProviderId; }; @@ -850,24 +850,24 @@ * @chained email provider map * * @param {Object} query - * @param [Object] pagination pagination (optional) + * @param {Object} pagination pagination (optional) */ queryEmailProviders: function(query, pagination) { - var self = this; + const self = this; - var params = {}; + const params = {}; if (pagination) { Gitana.copyInto(params, pagination); } - var uriFunction = function() + const uriFunction = function() { return self.getUri() + "/emailproviders/query"; }; - var chainable = this.getFactory().emailProviderMap(this); + const chainable = this.getFactory().emailProviderMap(this); return this.chainPost(chainable, uriFunction, params, query); }, @@ -898,14 +898,14 @@ */ checkEmailProviderPermissions: function(checks, callback) { - var self = this; + const self = this; - var uriFunction = function() + const uriFunction = function() { return self.getUri() + "/emailproviders/permissions/check"; }; - var object = { + const object = { "checks": checks }; @@ -941,14 +941,14 @@ */ checkEmailProviderAuthorities: function(checks, callback) { - var self = this; + const self = this; - var uriFunction = function() + const uriFunction = function() { return self.getUri() + "/emailproviders/authorities/check"; }; - var object = { + const object = { "checks": checks }; @@ -973,15 +973,15 @@ * * @chained email * - * @param [Object] object JSON object + * @param {Object} object JSON object */ createEmail: function(object) { - var self = this; + const self = this; - var chainable = this.getFactory().email(this); + const chainable = this.getFactory().email(this); - var uriFunction = function() + const uriFunction = function() { return self.getUri() + "/emails"; }; @@ -998,20 +998,20 @@ */ listEmails: function(pagination) { - var self = this; + const self = this; - var params = {}; + const params = {}; if (pagination) { Gitana.copyInto(params, pagination); } - var uriFunction = function() + const uriFunction = function() { return self.getUri() + "/emails"; }; - var chainable = this.getFactory().emailMap(this); + const chainable = this.getFactory().emailMap(this); return this.chainGet(chainable, uriFunction, params); }, @@ -1024,11 +1024,11 @@ */ readEmail: function(emailId) { - var self = this; + const self = this; - var chainable = this.getFactory().email(this); + const chainable = this.getFactory().email(this); - var uriFunction = function() + const uriFunction = function() { return self.getUri() + "/emails/" + emailId; }; @@ -1042,24 +1042,24 @@ * @chained email map * * @param {Object} query - * @param [Object] pagination pagination (optional) + * @param {Object} pagination pagination (optional) */ queryEmails: function(query, pagination) { - var self = this; + const self = this; - var params = {}; + const params = {}; if (pagination) { Gitana.copyInto(params, pagination); } - var uriFunction = function() + const uriFunction = function() { return self.getUri() + "/emails/query"; }; - var chainable = this.getFactory().emailMap(this); + const chainable = this.getFactory().emailMap(this); return this.chainPost(chainable, uriFunction, params, query); }, @@ -1090,14 +1090,14 @@ */ checkEmailPermissions: function(checks, callback) { - var self = this; + const self = this; - var uriFunction = function() + const uriFunction = function() { return self.getUri() + "/emails/permissions/check"; }; - var object = { + const object = { "checks": checks }; @@ -1133,14 +1133,14 @@ */ checkEmailAuthorities: function(checks, callback) { - var self = this; + const self = this; - var uriFunction = function() + const uriFunction = function() { return self.getUri() + "/emails/authorities/check"; }; - var object = { + const object = { "checks": checks }; @@ -1166,22 +1166,22 @@ */ deploy: function(deploymentKey) { - var self = this; + const self = this; - var uriFunction = function() + const uriFunction = function() { return self.getUri() + "/deploy/" + deploymentKey; }; // temp web host - var webhost = new Gitana.WebHost(this.getPlatform()); + const webhost = new Gitana.WebHost(this.getPlatform()); // we hand back a deployed application and preload some work - var chainable = this.getFactory().deployedApplication(webhost); + const chainable = this.getFactory().deployedApplication(webhost); return this.chainPost(chainable, uriFunction).then(function() { // load the real web host - var webhostId = self["deployments"][deploymentKey]["webhost"]; + const webhostId = self["deployments"][deploymentKey]["webhost"]; this.subchain(this.getPlatform()).readWebHost(webhostId).then(function() { webhost.loadFrom(this); }); @@ -1198,9 +1198,9 @@ */ undeploy: function(deploymentKey) { - var self = this; + const self = this; - var uriFunction = function() + const uriFunction = function() { return self.getUri() + "/undeploy/" + deploymentKey; }; @@ -1217,22 +1217,22 @@ */ findDeployedApplication: function(deploymentKey) { - var self = this; + const self = this; - var uriFunction = function() + const uriFunction = function() { return self.getUri() + "/deployed/" + deploymentKey; }; // temp web host - var webhost = new Gitana.WebHost(this.getPlatform()); + const webhost = new Gitana.WebHost(this.getPlatform()); // we hand back a deployed application and preload some work - var chainable = this.getFactory().deployedApplication(webhost); + const chainable = this.getFactory().deployedApplication(webhost); return this.chainGet(chainable, uriFunction).then(function() { // load the real web host - var webhostId = self["deployments"][deploymentKey]["webhost"]; + const webhostId = self["deployments"][deploymentKey]["webhost"]; this.subchain(this.getPlatform()).readWebHost(webhostId).then(function() { webhost.loadFrom(this); }); @@ -1244,12 +1244,13 @@ * Retrieves information about a deployed application. * * @param deploymentKey + * @param callback */ loadDeploymentInfo: function(deploymentKey, callback) { - var self = this; + const self = this; - var uriFunction = function() + const uriFunction = function() { return self.getUri() + "/deployed/" + deploymentKey + "/info"; }; @@ -1261,15 +1262,15 @@ refreshDeploymentKeys: function(deploymentKey) { - var self = this; + const self = this; return this.then(function() { - var chain = this; + const chain = this; // call - var uri = self.getUri() + "/deployments/" + deploymentKey + "/refreshkeys"; - self.getDriver().gitanaPost(uri, null, {}, function(response) { + const uri = self.getUri() + "/deployments/" + deploymentKey + "/refreshkeys"; + self.getDriver().gitanaPost(uri, null, {}, function() { chain.next(); }); @@ -1288,9 +1289,9 @@ */ invalidateAllPageRenditions: function(deploymentKey) { - var self = this; + const self = this; - var uriFunction = function() + const uriFunction = function() { return self.getUri() + "/deployments/" + deploymentKey + "/pagerenditions/invalidateall"; }; @@ -1313,15 +1314,15 @@ * * @chained message * - * @param [Object] object JSON object + * @param {Object} object JSON object */ createMessage: function(object) { - var self = this; + const self = this; - var chainable = this.getFactory().message(this); + const chainable = this.getFactory().message(this); - var uriFunction = function() + const uriFunction = function() { return self.getUri() + "/messages"; }; @@ -1338,20 +1339,20 @@ */ listMessages: function(pagination) { - var self = this; + const self = this; - var params = {}; + const params = {}; if (pagination) { Gitana.copyInto(params, pagination); } - var uriFunction = function() + const uriFunction = function() { return self.getUri() + "/messages"; }; - var chainable = this.getFactory().messageMap(this); + const chainable = this.getFactory().messageMap(this); return this.chainGet(chainable, uriFunction, params); }, @@ -1364,11 +1365,11 @@ */ readMessage: function(messageId) { - var self = this; + const self = this; - var chainable = this.getFactory().message(this); + const chainable = this.getFactory().message(this); - var uriFunction = function() + const uriFunction = function() { return self.getUri() + "/messages/" + messageId; }; @@ -1382,24 +1383,24 @@ * @chained message map * * @param {Object} query - * @param [Object] pagination pagination (optional) + * @param {Object} pagination pagination (optional) */ queryMessages: function(query, pagination) { - var self = this; + const self = this; - var params = {}; + const params = {}; if (pagination) { Gitana.copyInto(params, pagination); } - var uriFunction = function() + const uriFunction = function() { return self.getUri() + "/messages/query"; }; - var chainable = this.getFactory().messageMap(this); + const chainable = this.getFactory().messageMap(this); return this.chainPost(chainable, uriFunction, params, query); }, @@ -1430,14 +1431,14 @@ */ checkMessagePermissions: function(checks, callback) { - var self = this; + const self = this; - var uriFunction = function() + const uriFunction = function() { return self.getUri() + "/messages/permissions/check"; }; - var object = { + const object = { "checks": checks }; @@ -1473,14 +1474,14 @@ */ checkMessageAuthorities: function(checks, callback) { - var self = this; + const self = this; - var uriFunction = function() + const uriFunction = function() { return self.getUri() + "/messages/authorities/check"; }; - var object = { + const object = { "checks": checks }; diff --git a/js/gitana/application/ApplicationMap.js b/js/gitana/application/ApplicationMap.js index 8182dc74..53585507 100644 --- a/js/gitana/application/ApplicationMap.js +++ b/js/gitana/application/ApplicationMap.js @@ -1,6 +1,6 @@ (function(window) { - var Gitana = window.Gitana; + Gitana = window.Gitana; Gitana.ApplicationMap = Gitana.AbstractPlatformObjectMap.extend( /** @lends Gitana.ApplicationMap.prototype */ diff --git a/js/gitana/application/Email.js b/js/gitana/application/Email.js index 7a2a1a43..562bcdef 100644 --- a/js/gitana/application/Email.js +++ b/js/gitana/application/Email.js @@ -1,6 +1,6 @@ (function(window) { - var Gitana = window.Gitana; + Gitana = window.Gitana; Gitana.Email = Gitana.AbstractApplicationObject.extend( /** @lends Gitana.Email.prototype */ @@ -12,7 +12,7 @@ * @class Email * * @param {Gitana.Application} application - * @param [Object] object json object (if no callback required for populating) + * @param {Object} object json object (if no callback required for populating) */ constructor: function(application, object) { diff --git a/js/gitana/application/EmailMap.js b/js/gitana/application/EmailMap.js index accc817e..652601b2 100644 --- a/js/gitana/application/EmailMap.js +++ b/js/gitana/application/EmailMap.js @@ -1,6 +1,6 @@ (function(window) { - var Gitana = window.Gitana; + Gitana = window.Gitana; Gitana.EmailMap = Gitana.AbstractPlatformObjectMap.extend( /** @lends Gitana.EmailMap.prototype */ @@ -12,7 +12,7 @@ * @class EmailMap * * @param {Gitana.Application} application Gitana application instance. - * @param [Object] object + * @param {Object} object */ constructor: function(application, object) { diff --git a/js/gitana/application/EmailProvider.js b/js/gitana/application/EmailProvider.js index 7688b418..05d775fb 100644 --- a/js/gitana/application/EmailProvider.js +++ b/js/gitana/application/EmailProvider.js @@ -1,7 +1,7 @@ (function(window) { - var Gitana = window.Gitana; - + Gitana = window.Gitana; + Gitana.EmailProvider = Gitana.AbstractApplicationObject.extend( /** @lends Gitana.EmailProvider.prototype */ { @@ -12,7 +12,7 @@ * @class EmailProvider * * @param {Gitana.Application} application - * @param [Object] object json object (if no callback required for populating) + * @param [object] object json object (if no callback required for populating) */ constructor: function(application, object) { @@ -49,20 +49,20 @@ * Sends the given email using this email provider. * * @param {Object} email - * @param [Object] model + * @param {Object} model * * @return {*} */ send: function(email, model) { - var self = this; + const self = this; if (!model) { model = {}; } - var emailId = null; + let emailId = null; if (Gitana.isString(email)) { emailId = email; @@ -72,7 +72,7 @@ emailId = email.getId(); } - var uriFunction = function() + const uriFunction = function() { return self.getUri() + "/send?email=" + emailId; }; @@ -89,9 +89,9 @@ */ test: function(from, to) { - var self = this; + const self = this; - var uriFunction = function() + const uriFunction = function() { return self.getUri() + "/test?from=" + from + "&to=" + to; }; @@ -109,16 +109,15 @@ */ sendForExport: function(exportId, emailConfig, callback) { - var self = this; - var uriFunction = function() + const uriFunction = function() { return "/ref/exports/" + exportId + "/email"; }; - var params = {}; + const params = {}; - var payload = { + const payload = { "applicationId": this.getApplicationId(), "emailProviderId": this.getId(), "email": emailConfig diff --git a/js/gitana/application/EmailProviderMap.js b/js/gitana/application/EmailProviderMap.js index 767c94a6..be0c884f 100644 --- a/js/gitana/application/EmailProviderMap.js +++ b/js/gitana/application/EmailProviderMap.js @@ -1,6 +1,6 @@ (function(window) { - var Gitana = window.Gitana; + Gitana = window.Gitana; Gitana.EmailProviderMap = Gitana.AbstractPlatformObjectMap.extend( /** @lends Gitana.EmailProviderMap.prototype */ @@ -12,7 +12,7 @@ * @class EmailProviderMap * * @param {Gitana.Application} application Gitana application instance. - * @param [Object] object + * @param {Object} object */ constructor: function(application, object) { diff --git a/js/gitana/application/Message.js b/js/gitana/application/Message.js index 002f3780..c5071eba 100644 --- a/js/gitana/application/Message.js +++ b/js/gitana/application/Message.js @@ -1,6 +1,6 @@ (function(window) { - var Gitana = window.Gitana; + Gitana = window.Gitana; Gitana.Message = Gitana.AbstractApplicationObject.extend( /** @lends Gitana.Message.prototype */ @@ -12,7 +12,7 @@ * @class Message * * @param {Gitana.Application} application - * @param [Object] object json object (if no callback required for populating) + * @param {Object} object json object (if no callback required for populating) */ constructor: function(application, object) { diff --git a/js/gitana/application/MessageMap.js b/js/gitana/application/MessageMap.js index 13be642b..610f7f4f 100644 --- a/js/gitana/application/MessageMap.js +++ b/js/gitana/application/MessageMap.js @@ -1,6 +1,6 @@ (function(window) { - var Gitana = window.Gitana; + Gitana = window.Gitana; Gitana.MessageMap = Gitana.AbstractPlatformObjectMap.extend( /** @lends Gitana.MessageMap.prototype */ @@ -12,7 +12,7 @@ * @class MessageMap * * @param {Gitana.Application} application Gitana application instance. - * @param [Object] object + * @param {Object} object */ constructor: function(application, object) { diff --git a/js/gitana/application/PageRendition.js b/js/gitana/application/PageRendition.js index 194ff59c..baab96b2 100644 --- a/js/gitana/application/PageRendition.js +++ b/js/gitana/application/PageRendition.js @@ -1,6 +1,6 @@ (function(window) { - var Gitana = window.Gitana; + Gitana = window.Gitana; Gitana.PageRendition = Gitana.AbstractApplicationObject.extend( /** @lends Gitana.PageRendition.prototype */ @@ -12,7 +12,7 @@ * @class PageRendition * * @param {Gitana.Application} application - * @param [Object] object json object (if no callback required for populating) + * @param {Object} object json object (if no callback required for populating) */ constructor: function(application, object) { @@ -54,9 +54,9 @@ */ invalidate: function() { - var self = this; + const self = this; - var uriFunction = function() + const uriFunction = function() { return self.getUri() + "/invalidate"; }; diff --git a/js/gitana/application/PageRenditionMap.js b/js/gitana/application/PageRenditionMap.js index 2851fdd4..5f431352 100644 --- a/js/gitana/application/PageRenditionMap.js +++ b/js/gitana/application/PageRenditionMap.js @@ -1,6 +1,6 @@ (function(window) { - var Gitana = window.Gitana; + Gitana = window.Gitana; Gitana.PageRenditionMap = Gitana.AbstractPlatformObjectMap.extend( /** @lends Gitana.PageRenditionMap.prototype */ @@ -12,7 +12,7 @@ * @class PageRenditionMap * * @param {Gitana.Application} application Gitana application instance. - * @param [Object] object + * @param {Object} object */ constructor: function(application, object) { diff --git a/js/gitana/application/Registration.js b/js/gitana/application/Registration.js index f483e91f..93018b27 100644 --- a/js/gitana/application/Registration.js +++ b/js/gitana/application/Registration.js @@ -1,6 +1,6 @@ (function(window) { - var Gitana = window.Gitana; + Gitana = window.Gitana; Gitana.Registration = Gitana.AbstractApplicationObject.extend( /** @lends Gitana.Registration.prototype */ @@ -12,7 +12,7 @@ * @class Registration * * @param {Gitana.Application} application - * @param [Object] object json object (if no callback required for populating) + * @param {Object} object json object (if no callback required for populating) */ constructor: function(application, object) { @@ -47,9 +47,9 @@ sendConfirmationEmail: function() { - var self = this; + const self = this; - var uriFunction = function() + const uriFunction = function() { return self.getUri() + "/send/confirmation"; }; @@ -59,9 +59,9 @@ sendWelcomeEmail: function() { - var self = this; + const self = this; - var uriFunction = function() + const uriFunction = function() { return self.getUri() + "/send/welcome"; }; @@ -76,13 +76,13 @@ paymentMethodObject = {}; } - var params = { + const params = { "password": newUserPassword }; - var self = this; + const self = this; - var uriFunction = function() + const uriFunction = function() { return self.getUri() + "/confirm"; }; diff --git a/js/gitana/application/RegistrationMap.js b/js/gitana/application/RegistrationMap.js index 0208aee8..31928f26 100644 --- a/js/gitana/application/RegistrationMap.js +++ b/js/gitana/application/RegistrationMap.js @@ -1,6 +1,6 @@ (function(window) { - var Gitana = window.Gitana; + Gitana = window.Gitana; Gitana.RegistrationMap = Gitana.AbstractPlatformObjectMap.extend( /** @lends Gitana.RegistrationMap.prototype */ @@ -12,7 +12,7 @@ * @class RegistrationMap * * @param {Gitana.Application} application Gitana application instance. - * @param [Object] object + * @param {Object} object */ constructor: function(application, object) { diff --git a/js/gitana/application/Settings.js b/js/gitana/application/Settings.js index 0a79891f..00bdad0e 100644 --- a/js/gitana/application/Settings.js +++ b/js/gitana/application/Settings.js @@ -1,6 +1,6 @@ (function(window) { - var Gitana = window.Gitana; + Gitana = window.Gitana; Gitana.Settings = Gitana.AbstractApplicationObject.extend( /** @lends Gitana.Settings.prototype */ @@ -12,7 +12,7 @@ * @class Settings * * @param {Gitana.Application} application - * @param [Object] object json object (if no callback required for populating) + * @param {Object}object json object (if no callback required for populating) */ constructor: function(application, object) { diff --git a/js/gitana/application/SettingsMap.js b/js/gitana/application/SettingsMap.js index 3e12b74f..8701b7e0 100644 --- a/js/gitana/application/SettingsMap.js +++ b/js/gitana/application/SettingsMap.js @@ -1,6 +1,6 @@ (function(window) { - var Gitana = window.Gitana; + Gitana = window.Gitana; Gitana.SettingsMap = Gitana.AbstractPlatformObjectMap.extend( /** @lends Gitana.SettingsMap.prototype */ @@ -12,7 +12,7 @@ * @class SettingsMap * * @param {Gitana.Application} application Gitana application instance. - * @param [Object] object + * @param {Object}object */ constructor: function(application, object) { diff --git a/js/gitana/async/Defer.js b/js/gitana/async/Defer.js index ad6377f0..602d06cc 100644 --- a/js/gitana/async/Defer.js +++ b/js/gitana/async/Defer.js @@ -1,23 +1,23 @@ (function(window) { - var Gitana = window.Gitana; + Gitana = window.Gitana; - var STATUS_UNRESOLVED = 'unresolved'; - var STATUS_RESOLVED = 'resolved'; - var STATUS_REJECTED = 'rejected'; + const STATUS_UNRESOLVED = 'unresolved'; + const STATUS_RESOLVED = 'resolved'; + const STATUS_REJECTED = 'rejected'; - var triggerAll = function(val, cbs) { - for (var i = 0; i < cbs.length; i++) { - var cb = cbs[i]; + const triggerAll = function(val, cbs) { + for (let i = 0; i < cbs.length; i++) { + const cb = cbs[i]; trigger(val, cb); } }; - var trigger = function(val, cb) { + const trigger = function(val, cb) { setTimeout(cb.bind(null, val), 0); }; - var resolve = function(val) { + const resolve = function(val) { if (this.isUnresolved()) { this.status = STATUS_RESOLVED; this.val = val; @@ -27,7 +27,7 @@ } }; - var reject = function(err) { + const reject = function(err) { if (this.isUnresolved()) { this.status = STATUS_REJECTED; this.val = err; @@ -37,7 +37,7 @@ } }; - var Defer = function() { + const Defer = function() { this.promise = new Gitana.Promise(this); this.status = STATUS_UNRESOLVED; @@ -77,11 +77,11 @@ return Gitana.Promise.resolved(); } if (!Gitana.isArray(args)) { args = arguments; } - var def = new Defer(); - var left = args.length; - var results = []; - for (var i = 0; i < args.length; i++) { - var promise = args[i]; + const def = new Defer(); + let left = args.length; + const results = []; + for (let i = 0; i < args.length; i++) { + const promise = args[i]; (function(cur) { promise.then(function(res) { left--; diff --git a/js/gitana/async/Promise.js b/js/gitana/async/Promise.js index b70bb37d..82600917 100644 --- a/js/gitana/async/Promise.js +++ b/js/gitana/async/Promise.js @@ -1,24 +1,24 @@ (function(window) { - var Gitana = window.Gitana; + Gitana = window.Gitana; - var then = function(happy, sad) { + const then = function(happy, sad) { this.push(happy, sad); }; - var success = function(happy) { + const success = function(happy) { then.call(this, happy); }; - var fail = function(sad) { + const fail = function(sad) { then.call(this, undefined, sad); }; - var complete = function(cb) { + const complete = function(cb) { then.call(this, cb, cb); }; - var Promise = function(defer) { + const Promise = function(defer) { this.then = then.bind(defer); this.success = success.bind(defer); @@ -32,7 +32,7 @@ }; Promise.resolved = function(val) { - var def = new Gitana.Defer(); + const def = new Gitana.Defer(); def.resolve(val); return def.promise; }; diff --git a/js/gitana/async/Queue.js b/js/gitana/async/Queue.js index 9040a74a..d8ba04be 100644 --- a/js/gitana/async/Queue.js +++ b/js/gitana/async/Queue.js @@ -1,18 +1,18 @@ (function(window) { - var Gitana = window.Gitana; + Gitana = window.Gitana; - var DEFAULT_CONCURRENCY = 1; + const DEFAULT_CONCURRENCY = 1; - var chunk = function(array, size) { - var chunks = []; - for (var i = 0; i < array.length; i += size) { + const chunk = function(array, size) { + const chunks = []; + for (let i = 0; i < array.length; i += size) { chunks.push(array.slice(i, i + size)); } return chunks; }; - var Queue = function(concurrency) { + const Queue = function(concurrency) { this.concurrency = concurrency || DEFAULT_CONCURRENCY; this.work = []; }; @@ -22,19 +22,18 @@ }; Queue.prototype.go = function() { - var def = new Gitana.Defer(); - var chunks = chunk(this.work, this.concurrency); - var results = []; - var promise = Gitana.Promise.resolved([]); + const def = new Gitana.Defer(); + const chunks = chunk(this.work, this.concurrency); + const results = []; (function loop(promise) { promise.then(function(res) { results.push.apply(results, res); if (chunks.length > 0) { - var cbs = chunks.shift(); - var ps = []; - for (var i = cbs.length - 1; i >= 0; i--) { - var cb = cbs[i]; - var p = cb(); + const cbs = chunks.shift(); + const ps = []; + for (let i = cbs.length - 1; i >= 0; i--) { + const cb = cbs[i]; + const p = cb(); ps.push(p); } loop(Gitana.Defer.all(ps)); diff --git a/js/gitana/cluster/AbstractClusterObject.js b/js/gitana/cluster/AbstractClusterObject.js index 9342f919..5c32bf08 100644 --- a/js/gitana/cluster/AbstractClusterObject.js +++ b/js/gitana/cluster/AbstractClusterObject.js @@ -1,6 +1,6 @@ (function(window) { - var Gitana = window.Gitana; + Gitana = window.Gitana; Gitana.AbstractClusterObject = Gitana.AbstractObject.extend( /** @lends Gitana.AbstractClusterObject.prototype */ @@ -12,7 +12,7 @@ * @class AbstractClusterObject * * @param {Gitana.Cluster} cluster - * @param [Object] object json object (if no callback required for populating) + * @param {Object} object json object (if no callback required for populating) */ constructor: function(cluster, object) { diff --git a/js/gitana/cluster/Cluster.js b/js/gitana/cluster/Cluster.js index d2c8e6b4..e66a0d71 100644 --- a/js/gitana/cluster/Cluster.js +++ b/js/gitana/cluster/Cluster.js @@ -1,6 +1,6 @@ (function(window) { - var Gitana = window.Gitana; + Gitana = window.Gitana; Gitana.Cluster = Gitana.DataStore.extend( /** @lends Gitana.Cluster.prototype */ @@ -12,7 +12,7 @@ * @class Cluster * * @param {Gitana.Driver} driver - * @param [Object] object json object (if no callback required for populating) + * @param {Object} object json object (if no callback required for populating) */ constructor: function(driver, object) { @@ -54,7 +54,7 @@ */ loadContainedTypes: function(type, callback) { - var uriFunction = function() + const uriFunction = function() { return "/tools/types/contained/" + type; }; @@ -78,14 +78,14 @@ * @chained job map * * @param {Object} query Query for finding a job. - * @param [Object] pagination pagination (optional) + * @param {Object} pagination pagination (optional) */ queryJobs: function(query, pagination) { - var chainable = this.getFactory().jobMap(this); + const chainable = this.getFactory().jobMap(this); // prepare params (with pagination) - var params = {}; + const params = {}; if (pagination) { Gitana.copyInto(params, pagination); @@ -103,7 +103,7 @@ */ readJob: function(jobId) { - var chainable = this.getFactory().job(this); + const chainable = this.getFactory().job(this); return this.chainGet(chainable, "/jobs/" + jobId); }, @@ -126,14 +126,14 @@ * @chained job map * * @param {Object} query Query for finding a job. - * @param [Object] pagination pagination (optional) + * @param {Object} pagination pagination (optional) */ queryUnstartedJobs: function(query, pagination) { - var chainable = this.getFactory().jobMap(this); + const chainable = this.getFactory().jobMap(this); // prepare params (with pagination) - var params = {}; + const params = {}; if (pagination) { Gitana.copyInto(params, pagination); @@ -148,14 +148,14 @@ * @chained job map * * @param {Object} query Query for finding a job. - * @param [Object] pagination pagination (optional) + * @param {Object} pagination pagination (optional) */ queryRunningJobs: function(query, pagination) { - var chainable = this.getFactory().jobMap(this); + const chainable = this.getFactory().jobMap(this); // prepare params (with pagination) - var params = {}; + const params = {}; if (pagination) { Gitana.copyInto(params, pagination); @@ -170,14 +170,14 @@ * @chained job map * * @param {Object} query Query for finding a job. - * @param [Object] pagination pagination (optional) + * @param {Object} pagination pagination (optional) */ queryFailedJobs: function(query, pagination) { - var chainable = this.getFactory().jobMap(this); + const chainable = this.getFactory().jobMap(this); // prepare params (with pagination) - var params = {}; + const params = {}; if (pagination) { Gitana.copyInto(params, pagination); @@ -192,14 +192,14 @@ * @chained job map * * @param {Object} query Query for finding a job. - * @param [Object] pagination pagination (optional) + * @param {Object} pagination pagination (optional) */ queryWaitingJobs: function(query, pagination) { - var chainable = this.getFactory().jobMap(this); + const chainable = this.getFactory().jobMap(this); // prepare params (with pagination) - var params = {}; + const params = {}; if (pagination) { Gitana.copyInto(params, pagination); @@ -214,14 +214,14 @@ * @chained job map * * @param {Object} query Query for finding a job. - * @param [Object] pagination pagination (optional) + * @param {Object} pagination pagination (optional) */ queryFinishedJobs: function(query, pagination) { - var chainable = this.getFactory().jobMap(this); + const chainable = this.getFactory().jobMap(this); // prepare params (with pagination) - var params = {}; + const params = {}; if (pagination) { Gitana.copyInto(params, pagination); @@ -232,9 +232,9 @@ waitForJobCompletion: function(jobId, callback, progressCallback) { - var chainable = this; + const chainable = this; - var f = function() + const f = function() { window.setTimeout(function() { @@ -244,10 +244,10 @@ progressCallback(this); } - if (this.state == "FINISHED") { + if (this.state === "FINISHED") { callback(this); chainable.next(); - } else if (this.state == "ERROR") { + } else if (this.state === "ERROR") { callback(this); chainable.next(); } else { diff --git a/js/gitana/cluster/CopyJob.js b/js/gitana/cluster/CopyJob.js index e83da5a0..97b845a4 100644 --- a/js/gitana/cluster/CopyJob.js +++ b/js/gitana/cluster/CopyJob.js @@ -1,6 +1,6 @@ (function(window) { - var Gitana = window.Gitana; + Gitana = window.Gitana; Gitana.CopyJob = Gitana.Job.extend( /** @lends Gitana.CopyJob.prototype */ @@ -12,7 +12,7 @@ * @class CopyJob * * @param {Gitana.Cluster} cluster - * @param [Object] object json object (if no callback required for populating) + * @param {Object} object json object (if no callback required for populating) */ constructor: function(cluster, object) { @@ -31,19 +31,19 @@ getImports: function() { - var importObjects = []; + const importObjects = []; - var array = this.get("imports"); - for (var i = 0; i < array.length; i++) + const array = this.get("imports"); + for (let i = 0; i < array.length; i++) { - var object = array[i]; + const object = array[i]; - var sources = object["sources"]; - var targets = object["targest"]; + const sources = object["sources"]; + const targets = object["targets"]; - var importObject = { - "sources": object["sources"], - "targets": object["targets"], + const importObject = { + sources, + targets, getType: function() { return this.targets[this.targets.length - 1]["typeId"]; @@ -65,9 +65,9 @@ getSingleImportTargetId: function() { - var targetId = null; + let targetId = null; - var importObjects = this.getImports(); + const importObjects = this.getImports(); if (importObjects.length > 0) { targetId = importObjects[0].getTargetId(); diff --git a/js/gitana/cluster/Job.js b/js/gitana/cluster/Job.js index 0bff638e..ae271256 100644 --- a/js/gitana/cluster/Job.js +++ b/js/gitana/cluster/Job.js @@ -1,6 +1,6 @@ (function(window) { - var Gitana = window.Gitana; + Gitana = window.Gitana; Gitana.Job = Gitana.AbstractClusterObject.extend( /** @lends Gitana.Job.prototype */ @@ -12,7 +12,7 @@ * @class Job * * @param {Gitana.Cluster} cluster - * @param [Object] object json object (if no callback required for populating) + * @param {Object} object json object (if no callback required for populating) */ constructor: function(cluster, object) { diff --git a/js/gitana/cluster/JobMap.js b/js/gitana/cluster/JobMap.js index 612b3904..49b59909 100644 --- a/js/gitana/cluster/JobMap.js +++ b/js/gitana/cluster/JobMap.js @@ -1,6 +1,6 @@ (function(window) { - var Gitana = window.Gitana; + Gitana = window.Gitana; Gitana.JobMap = Gitana.AbstractMap.extend( /** @lends Gitana.JobMap.prototype */ @@ -12,7 +12,7 @@ * @class Map of jobs * * @param {Gitana.Cluster} cluster Gitana cluster instance. - * @param [Object] object + * @param {Object} object */ constructor: function(cluster, object) { diff --git a/js/gitana/cluster/LogEntry.js b/js/gitana/cluster/LogEntry.js index 200989e1..2557ca85 100644 --- a/js/gitana/cluster/LogEntry.js +++ b/js/gitana/cluster/LogEntry.js @@ -1,6 +1,6 @@ (function(window) { - var Gitana = window.Gitana; + Gitana = window.Gitana; Gitana.LogEntry = Gitana.AbstractObject.extend( /** @lends Gitana.LogEntry.prototype */ @@ -12,7 +12,7 @@ * @class LogEntry * * @param {Gitana.Platform} platform - * @param [Object] object json object (if no callback required for populating) + * @param {Object} object json object (if no callback required for populating) */ constructor: function(platform, object) { diff --git a/js/gitana/cluster/LogEntryMap.js b/js/gitana/cluster/LogEntryMap.js index 23734f62..e9dba9a8 100644 --- a/js/gitana/cluster/LogEntryMap.js +++ b/js/gitana/cluster/LogEntryMap.js @@ -1,6 +1,6 @@ (function(window) { - var Gitana = window.Gitana; + Gitana = window.Gitana; Gitana.LogEntryMap = Gitana.AbstractMap.extend( /** @lends Gitana.LogEntryMap.prototype */ @@ -12,7 +12,7 @@ * @class Map of log entries * * @param {Gitana.Platform} platform Gitana server instance. - * @param [Object] object + * @param {Object} object */ constructor: function(platform, object) { diff --git a/js/gitana/cluster/TransferExportJob.js b/js/gitana/cluster/TransferExportJob.js index 62d641cf..37b239ad 100644 --- a/js/gitana/cluster/TransferExportJob.js +++ b/js/gitana/cluster/TransferExportJob.js @@ -1,6 +1,6 @@ (function(window) { - var Gitana = window.Gitana; + Gitana = window.Gitana; Gitana.TransferExportJob = Gitana.Job.extend( /** @lends Gitana.TransferExportJob.prototype */ @@ -12,7 +12,7 @@ * @class TransferExportJob * * @param {Gitana.Cluster} cluster - * @param [Object] object json object (if no callback required for populating) + * @param {Object} object json object (if no callback required for populating) */ constructor: function(cluster, object) { @@ -31,19 +31,19 @@ getImports: function() { - var importObjects = []; + const importObjects = []; - var array = this.get("imports"); - for (var i = 0; i < array.length; i++) + const array = this.get("imports"); + for (let i = 0; i < array.length; i++) { - var object = array[i]; + const object = array[i]; - var sources = object["sources"]; - var targets = object["targest"]; + const sources = object["sources"]; + const targets = object["targets"]; - var importObject = { - "sources": object["sources"], - "targets": object["targets"], + const importObject = { + sources, + targets, getType: function() { return this.targets[this.targets.length - 1]["typeId"]; @@ -65,9 +65,9 @@ getSingleImportTargetId: function() { - var targetId = null; + let targetId = null; - var importObjects = this.getImports(); + const importObjects = this.getImports(); if (importObjects.length > 0) { targetId = importObjects[0].getTargetId(); diff --git a/js/gitana/cluster/TransferImportJob.js b/js/gitana/cluster/TransferImportJob.js index 78aff86c..1084c905 100644 --- a/js/gitana/cluster/TransferImportJob.js +++ b/js/gitana/cluster/TransferImportJob.js @@ -1,6 +1,6 @@ (function(window) { - var Gitana = window.Gitana; + Gitana = window.Gitana; Gitana.TransferImportJob = Gitana.Job.extend( /** @lends Gitana.TransferImportJob.prototype */ @@ -12,7 +12,7 @@ * @class TransferImportJob * * @param {Gitana.Cluster} cluster - * @param [Object] object json object (if no callback required for populating) + * @param {Object} object json object (if no callback required for populating) */ constructor: function(cluster, object) { @@ -31,19 +31,19 @@ getImports: function() { - var importObjects = []; + const importObjects = []; - var array = this.get("imports"); - for (var i = 0; i < array.length; i++) + const array = this.get("imports"); + for (let i = 0; i < array.length; i++) { - var object = array[i]; + const object = array[i]; - var sources = object["sources"]; - var targets = object["targest"]; + const sources = object["sources"]; + const targets = object["targets"]; - var importObject = { - "sources": object["sources"], - "targets": object["targets"], + const importObject = { + sources, + targets, getType: function() { return this.targets[this.targets.length - 1]["typeId"]; @@ -65,9 +65,9 @@ getSingleImportTargetId: function() { - var targetId = null; + let targetId = null; - var importObjects = this.getImports(); + const importObjects = this.getImports(); if (importObjects.length > 0) { targetId = importObjects[0].getTargetId(); diff --git a/js/gitana/directory/AbstractDirectoryObject.js b/js/gitana/directory/AbstractDirectoryObject.js index a7ef60fc..e05a0dd5 100644 --- a/js/gitana/directory/AbstractDirectoryObject.js +++ b/js/gitana/directory/AbstractDirectoryObject.js @@ -1,6 +1,6 @@ (function(window) { - var Gitana = window.Gitana; + Gitana = window.Gitana; Gitana.AbstractDirectoryObject = Gitana.AbstractPlatformObject.extend( /** @lends Gitana.AbstractDirectoryObject.prototype */ @@ -12,7 +12,7 @@ * @class AbstractDirectoryObject * * @param {Gitana.Directory} directory - * @param [Object] object json object (if no callback required for populating) + * @param {Object} object json object (if no callback required for populating) */ constructor: function(directory, object) { diff --git a/js/gitana/directory/Connection.js b/js/gitana/directory/Connection.js index b3b73e02..8daf6042 100644 --- a/js/gitana/directory/Connection.js +++ b/js/gitana/directory/Connection.js @@ -1,6 +1,6 @@ (function(window) { - var Gitana = window.Gitana; + Gitana = window.Gitana; Gitana.Connection = Gitana.AbstractDirectoryObject.extend( /** @lends Gitana.Connection.prototype */ @@ -12,7 +12,7 @@ * @class AbstractDirectoryObject * * @param {Gitana.Directory} directory - * @param [Object] object json object (if no callback required for populating) + * @param {Object} object json object (if no callback required for populating) */ constructor: function(directory, object) { diff --git a/js/gitana/directory/ConnectionMap.js b/js/gitana/directory/ConnectionMap.js index f380b88f..558273ba 100644 --- a/js/gitana/directory/ConnectionMap.js +++ b/js/gitana/directory/ConnectionMap.js @@ -1,6 +1,6 @@ (function(window) { - var Gitana = window.Gitana; + Gitana = window.Gitana; Gitana.ConnectionMap = Gitana.AbstractPlatformObjectMap.extend( /** @lends Gitana.ConnectionMap.prototype */ diff --git a/js/gitana/directory/Directory.js b/js/gitana/directory/Directory.js index 4f1b4577..db6256c7 100644 --- a/js/gitana/directory/Directory.js +++ b/js/gitana/directory/Directory.js @@ -1,6 +1,6 @@ (function(window) { - var Gitana = window.Gitana; + Gitana = window.Gitana; Gitana.Directory = Gitana.AbstractPlatformDataStore.extend( /** @lends Gitana.Directory.prototype */ @@ -12,7 +12,7 @@ * @class Directory * * @param {Gitana.Platform} platform - * @param [Object] object json object (if no callback required for populating) + * @param {Object}object json object (if no callback required for populating) */ constructor: function(platform, object) { @@ -63,14 +63,14 @@ */ readIdentity: function(identityId) { - var self = this; + const self = this; - var uriFunction = function() + const uriFunction = function() { return self.getUri() + "/identities/" + identityId; }; - var chainable = this.getFactory().identity(this); + const chainable = this.getFactory().identity(this); return this.chainGet(chainable, uriFunction); }, @@ -79,26 +79,26 @@ * * @chained identity map * - * @param [Pagination] pagination pagination (optional) + * @param {Object} pagination pagination (optional) */ listIdentities: function(pagination) { - var self = this; + const self = this; // prepare params (with pagination) - var params = {}; + const params = {}; if (pagination) { Gitana.copyInto(params, pagination); } - var uriFunction = function() + const uriFunction = function() { return self.getUri() + "/identities"; }; // get to work - var chainable = this.getFactory().identityMap(this); + const chainable = this.getFactory().identityMap(this); // all groups return this.chainGet(chainable, uriFunction, params); @@ -110,24 +110,24 @@ * @chained identity map * * @param {Object} query - * @param [Object] pagination pagination (optional) + * @param {Object}pagination pagination (optional) */ queryIdentities: function(query, pagination) { - var self = this; + const self = this; - var params = {}; + const params = {}; if (pagination) { Gitana.copyInto(params, pagination); } - var uriFunction = function() + const uriFunction = function() { return self.getUri() + "/identities/query"; }; - var chainable = this.getFactory().identityMap(this); + const chainable = this.getFactory().identityMap(this); return this.chainPost(chainable, uriFunction, params, query); }, @@ -158,13 +158,13 @@ */ checkIdentityPermissions: function(checks, callback) { - var self = this; + const self = this; - var object = { + const object = { "checks": checks }; - var uriFunction = function() + const uriFunction = function() { return self.getUri() + "/identities/permissions/check"; }; @@ -201,13 +201,13 @@ */ checkIdentityAuthorities: function(checks, callback) { - var self = this; + const self = this; - var object = { + const object = { "checks": checks }; - var uriFunction = function() + const uriFunction = function() { return self.getUri() + "/identities/authorities/check"; }; @@ -233,14 +233,14 @@ */ readConnection: function(connectionId) { - var self = this; + const self = this; - var uriFunction = function() + const uriFunction = function() { return self.getUri() + "/connections/" + connectionId; }; - var chainable = this.getFactory().connection(this); + const chainable = this.getFactory().connection(this); return this.chainGet(chainable, uriFunction); }, @@ -249,23 +249,23 @@ * * @chained connection * - * @param [Object] object JSON object + * @param {Object}object JSON object */ createConnection: function(object) { - var self = this; + const self = this; if (!object) { object = {}; } - var uriFunction = function() + const uriFunction = function() { return self.getUri() + "/connections"; }; - var chainable = this.getFactory().connection(this, object); + const chainable = this.getFactory().connection(this, object); return this.chainCreate(chainable, object, uriFunction); }, @@ -275,26 +275,26 @@ * * @chained identity map * - * @param [Pagination] pagination pagination (optional) + * @param {Object} pagination pagination (optional) */ listConnections: function(pagination) { - var self = this; + const self = this; // prepare params (with pagination) - var params = {}; + const params = {}; if (pagination) { Gitana.copyInto(params, pagination); } - var uriFunction = function() + const uriFunction = function() { return self.getUri() + "/connections"; }; // get to work - var chainable = this.getFactory().connectionMap(this); + const chainable = this.getFactory().connectionMap(this); // all groups return this.chainGet(chainable, uriFunction, params); @@ -306,24 +306,24 @@ * @chained identity map * * @param {Object} query - * @param [Object] pagination pagination (optional) + * @param {Object}pagination pagination (optional) */ queryConnections: function(query, pagination) { - var self = this; + const self = this; - var params = {}; + const params = {}; if (pagination) { Gitana.copyInto(params, pagination); } - var uriFunction = function() + const uriFunction = function() { return self.getUri() + "/connections/query"; }; - var chainable = this.getFactory().connectionMap(this); + const chainable = this.getFactory().connectionMap(this); return this.chainPost(chainable, uriFunction, params, query); }, @@ -354,13 +354,13 @@ */ checkConnectionPermissions: function(checks, callback) { - var self = this; + const self = this; - var object = { + const object = { "checks": checks }; - var uriFunction = function() + const uriFunction = function() { return self.getUri() + "/connections/permissions/check"; }; @@ -397,13 +397,13 @@ */ checkConnectionAuthorities: function(checks, callback) { - var self = this; + const self = this; - var object = { + const object = { "checks": checks }; - var uriFunction = function() + const uriFunction = function() { return self.getUri() + "/connections/authorities/check"; }; diff --git a/js/gitana/directory/DirectoryMap.js b/js/gitana/directory/DirectoryMap.js index e9cf645d..ebe93d39 100644 --- a/js/gitana/directory/DirectoryMap.js +++ b/js/gitana/directory/DirectoryMap.js @@ -1,6 +1,6 @@ (function(window) { - var Gitana = window.Gitana; + Gitana = window.Gitana; Gitana.DirectoryMap = Gitana.AbstractPlatformObjectMap.extend( /** @lends Gitana.DirectoryMap.prototype */ diff --git a/js/gitana/directory/Identity.js b/js/gitana/directory/Identity.js index 72bc87fc..b4dd3acd 100644 --- a/js/gitana/directory/Identity.js +++ b/js/gitana/directory/Identity.js @@ -1,6 +1,6 @@ (function(window) { - var Gitana = window.Gitana; + Gitana = window.Gitana; Gitana.Identity = Gitana.AbstractDirectoryObject.extend( /** @lends Gitana.Identity.prototype */ @@ -12,7 +12,7 @@ * @class Identity * * @param {Gitana.Directory} directory - * @param [Object] object json object (if no callback required for populating) + * @param {Object} object json object (if no callback required for populating) */ constructor: function(directory, object) { @@ -56,7 +56,7 @@ */ changePassword: function(password, verifyPassword) { - var object = { + const object = { "password": password, "verifyPassword": verifyPassword }; @@ -71,19 +71,19 @@ */ findPolicyUsers: function(tenantId) { - var self = this; + const self = this; - var uriFunction = function() + const uriFunction = function() { return self.getUri() + "/policy/users"; }; - var domain = new Gitana.Domain(this.getPlatform()); + const domain = new Gitana.Domain(this.getPlatform()); - var chainable = this.getFactory().domainPrincipalMap(domain); + const chainable = this.getFactory().domainPrincipalMap(domain); // prepare params - var params = {}; + const params = {}; if (tenantId) { params.tenantId = tenantId; @@ -96,21 +96,21 @@ * Finds the user on a tenant platform that has this identity. * If multiple users have this identity, the first one is chosen. * - * @param pagination + * @param tenantId */ findPolicyUserForTenant: function(tenantId) { - var self = this; + const self = this; - var uriFunction = function() + const uriFunction = function() { return self.getUri() + "/policy/user"; }; - var chainable = this.getFactory().domainPrincipal(this); + const chainable = this.getFactory().domainPrincipal(this); // prepare params (with pagination) - var params = {}; + const params = {}; params["tenantId"] = tenantId; return this.chainGet(chainable, uriFunction, params); @@ -120,21 +120,21 @@ * Finds the user on a tenant platform that has this identity. * If multiple users have this identity, the first one is chosen. * - * @param pagination + * @param tenantId */ findPolicyUsersForTenant: function(tenantId) { - var self = this; + const self = this; - var uriFunction = function() + const uriFunction = function() { return self.getUri() + "/policy/users"; }; - var chainable = this.getFactory().domainPrincipalMap(this); + const chainable = this.getFactory().domainPrincipalMap(this); // prepare params (with pagination) - var params = {}; + const params = {}; params["tenantId"] = tenantId; return this.chainGet(chainable, uriFunction, params); @@ -146,21 +146,21 @@ * * @chained principal map * - * @param [String] registrarId + * @param {String} registrarId */ findPolicyTenants: function(registrarId) { - var self = this; + const self = this; - var uriFunction = function() + const uriFunction = function() { return self.getUri() + "/policy/tenants"; }; - var chainable = this.getFactory().tenantMap(this); + const chainable = this.getFactory().tenantMap(this); // prepare params - var params = {}; + const params = {}; if (registrarId) { params["registrarId"] = registrarId; diff --git a/js/gitana/directory/IdentityMap.js b/js/gitana/directory/IdentityMap.js index dede33e9..c6e37cf5 100644 --- a/js/gitana/directory/IdentityMap.js +++ b/js/gitana/directory/IdentityMap.js @@ -1,6 +1,6 @@ (function(window) { - var Gitana = window.Gitana; + const Gitana = window.Gitana; Gitana.IdentityMap = Gitana.AbstractPlatformObjectMap.extend( /** @lends Gitana.IdentityMap.prototype */ diff --git a/js/gitana/domain/AbstractDomainObject.js b/js/gitana/domain/AbstractDomainObject.js index edf6115c..89d09602 100644 --- a/js/gitana/domain/AbstractDomainObject.js +++ b/js/gitana/domain/AbstractDomainObject.js @@ -1,6 +1,6 @@ (function(window) { - var Gitana = window.Gitana; + Gitana = window.Gitana; Gitana.AbstractDomainObject = Gitana.AbstractPlatformObject.extend( /** @lends Gitana.AbstractDomainObject.prototype */ @@ -12,7 +12,7 @@ * @class AbstractDomainObject * * @param {Gitana.Domain} domain - * @param [Object] object json object (if no callback required for populating) + * @param {Object} object json object (if no callback required for populating) */ constructor: function(domain, object) { diff --git a/js/gitana/domain/Domain.js b/js/gitana/domain/Domain.js index c30e128b..2431eb14 100644 --- a/js/gitana/domain/Domain.js +++ b/js/gitana/domain/Domain.js @@ -1,6 +1,6 @@ (function(window) { - var Gitana = window.Gitana; + Gitana = window.Gitana; Gitana.Domain = Gitana.AbstractPlatformDataStore.extend( /** @lends Gitana.Domain.prototype */ @@ -12,7 +12,7 @@ * @class Domain * * @param {Gitana.Platform} platform - * @param [Object] object json object (if no callback required for populating) + * @param {Object} object json object (if no callback required for populating) */ constructor: function(platform, object) { @@ -57,14 +57,15 @@ * * @chained principal map * - * @param [Pagination] pagination pagination (optional) + * @param {Object} pagination pagination (optional) + * @param {Object} options */ listPrincipals: function(pagination, options) { - var self = this; + const self = this; // prepare params (with pagination) - var params = {}; + const params = {}; if (pagination) { Gitana.copyInto(params, pagination); @@ -76,13 +77,13 @@ Gitana.copyInto(params, options); } - var uriFunction = function() + const uriFunction = function() { return self.getUri() + "/principals"; }; // get to work - var chainable = this.getFactory().domainPrincipalMap(this); + const chainable = this.getFactory().domainPrincipalMap(this); // all groups return this.chainGet(chainable, uriFunction, params); @@ -101,24 +102,24 @@ * @chained principal * * @param {String} principalId the principal id - * @param [Object] options + * @param {Object} options */ readPrincipal: function(principalId, options) { - var self = this; + const self = this; - var params = {}; + const params = {}; if (options) { Gitana.copyInto(params, options); } - var uriFunction = function() + const uriFunction = function() { return self.getUri() + "/principals/" + principalId; }; - var chainable = this.getFactory().domainPrincipal(this); + const chainable = this.getFactory().domainPrincipal(this); return this.chainGet(chainable, uriFunction, params); }, @@ -128,11 +129,11 @@ * * @chained principal * - * @param [Object] object JSON object + * @param {Object} object JSON object */ createPrincipal: function(object) { - var self = this; + const self = this; if (!object) { @@ -153,12 +154,12 @@ return; } - var uriFunction = function() + const uriFunction = function() { return self.getUri() + "/principals"; }; - var chainable = this.getFactory().domainPrincipal(this, object); + const chainable = this.getFactory().domainPrincipal(this, object); return this.chainCreate(chainable, object, uriFunction); }, @@ -169,14 +170,14 @@ * @chained principal map * * @param {Object} query - * @param [Object] pagination pagination (optional) - * @param [Object] options + * @param {Object} pagination pagination (optional) + * @param {Object} options */ - queryPrincipals: function(query, pagination, options) + queryPrincipals: function(query, pagination, options = undefined) { - var self = this; + const self = this; - var params = {}; + const params = {}; if (pagination) { Gitana.copyInto(params, pagination); @@ -188,12 +189,12 @@ Gitana.copyInto(params, options); } - var uriFunction = function() + const uriFunction = function() { return self.getUri() + "/principals/query"; }; - var chainable = this.getFactory().domainPrincipalMap(this); + const chainable = this.getFactory().domainPrincipalMap(this); return this.chainPost(chainable, uriFunction, params, query); }, @@ -209,11 +210,11 @@ * * @chained group map * - * @param [Object] pagination pagination (optional) + * @param {Object} pagination pagination (optional) */ listGroups: function(pagination) { - var query = { + const query = { "type": "GROUP" }; @@ -225,8 +226,7 @@ * * @chained group * - * @param {String} groupId the group id - * @param [Object] object JSON object + * @param {Object} object JSON object */ createGroup: function(object) { @@ -245,7 +245,7 @@ * @chained principal map * * @param {Object} query - * @param [Object] pagination pagination (optional) + * @param {Object} pagination pagination (optional) */ queryGroups: function(query, pagination) { @@ -270,11 +270,11 @@ * * @chained user map * - * @param [Object] pagination pagination (optional) + * @param {Object} pagination pagination (optional) */ listUsers: function(pagination) { - var query = { + const query = { "type": "USER" }; @@ -286,8 +286,7 @@ * * @chained user * - * @param {String} userId the user id - * @param [Object] object JSON object + * @param {Object} object JSON object */ createUser: function(object) { @@ -306,7 +305,7 @@ * @chained principal map * * @param {Object} query - * @param [Object] pagination pagination (optional) + * @param {Object} pagination pagination (optional) */ queryUsers: function(query, pagination) { @@ -339,12 +338,12 @@ */ addMember: function(group, principal) { - var self = this; + const self = this; - var groupId = this.extractPrincipalIdentifiers(group, this.getId())["principal"]; - var principalDomainQualifiedId = this.extractPrincipalDomainQualifiedId(principal); + const groupId = this.extractPrincipalIdentifiers(group, this.getId())["principal"]; + const principalDomainQualifiedId = this.extractPrincipalDomainQualifiedId(principal); - var uriFunction = function() + const uriFunction = function() { return self.getUri() + "/principals/" + groupId + "/members/add?id=" + principalDomainQualifiedId; }; @@ -364,12 +363,12 @@ */ removeMember: function(group, principal) { - var self = this; + const self = this; - var groupId = this.extractPrincipalIdentifiers(group, this.getId())["principal"]; - var principalDomainQualifiedId = this.extractPrincipalDomainQualifiedId(principal); + const groupId = this.extractPrincipalIdentifiers(group, this.getId())["principal"]; + const principalDomainQualifiedId = this.extractPrincipalDomainQualifiedId(principal); - var uriFunction = function() + const uriFunction = function() { return self.getUri() + "/principals/" + groupId + "/members/remove?id=" + principalDomainQualifiedId; }; @@ -386,14 +385,14 @@ * * @param {Object} group * @param {String} filter type of principal to hand back ("user" or "group") - * @param [Object] pagination + * @param {Object} pagination * @param {Boolean} indirect whether to include members that inherit through child groups */ listMembers: function(group, filter, pagination, indirect) { - var self = this; + const self = this; - var params = {}; + const params = {}; if (pagination) { Gitana.copyInto(params, pagination); @@ -407,14 +406,14 @@ params["indirect"] = true; } - var groupId = this.extractPrincipalIdentifiers(group, this.getId())["principal"]; + const groupId = this.extractPrincipalIdentifiers(group, this.getId())["principal"]; - var uriFunction = function() + const uriFunction = function() { return self.getUri() + "/principals/" + groupId + "/members"; }; - var chainable = this.getFactory().domainPrincipalMap(this); + const chainable = this.getFactory().domainPrincipalMap(this); return this.chainGet(chainable, uriFunction, params); }, @@ -453,13 +452,13 @@ */ checkPrincipalPermissions: function(checks, callback) { - var self = this; + const self = this; - var object = { + const object = { "checks": checks }; - var uriFunction = function() + const uriFunction = function() { return self.getUri() + "/principals/permissions/check"; }; @@ -496,13 +495,13 @@ */ checkPrincipalAuthorities: function(checks, callback) { - var self = this; + const self = this; - var object = { + const object = { "checks": checks }; - var uriFunction = function() + const uriFunction = function() { return self.getUri() + "/principals/authorities/check"; }; @@ -540,13 +539,13 @@ */ checkGroupMemberships: function(checks, callback) { - var self = this; + const self = this; - var object = { + const object = { "checks": checks }; - var uriFunction = function() + const uriFunction = function() { return self.getUri() + "/principals/membership/check"; }; diff --git a/js/gitana/domain/DomainMap.js b/js/gitana/domain/DomainMap.js index 1c2ba1d6..6cb53c24 100644 --- a/js/gitana/domain/DomainMap.js +++ b/js/gitana/domain/DomainMap.js @@ -1,6 +1,6 @@ (function(window) { - var Gitana = window.Gitana; + Gitana = window.Gitana; Gitana.DomainMap = Gitana.AbstractPlatformObjectMap.extend( /** @lends Gitana.DomainMap.prototype */ diff --git a/js/gitana/domain/DomainPrincipal.js b/js/gitana/domain/DomainPrincipal.js index 7393e386..dd5daf73 100644 --- a/js/gitana/domain/DomainPrincipal.js +++ b/js/gitana/domain/DomainPrincipal.js @@ -1,6 +1,6 @@ (function(window) { - var Gitana = window.Gitana; + Gitana = window.Gitana; Gitana.DomainPrincipal = Gitana.AbstractDomainObject.extend( /** @lends Gitana.DomainPrincipal.prototype */ @@ -12,7 +12,7 @@ * @class DomainPrincipal * * @param {Gitana.Domain} domain - * @param [Object] object json object (if no callback required for populating) + * @param {Object} object json object (if no callback required for populating) */ constructor: function(domain, object) { @@ -94,19 +94,19 @@ * @public * * @param {Boolean} indirect whether to consider indirect groups - * @param {Pagination} pagination + * @param {Object} pagination */ listMemberships: function(indirect, pagination) { - var params = {}; + const params = {}; if (pagination) { Gitana.copyInto(params, pagination); } - var uriFunction = function() + const uriFunction = function() { - var uri = this.getUri() + "/memberships"; + let uri = this.getUri() + "/memberships"; if (indirect) { uri = uri + "?indirect=true"; @@ -115,7 +115,7 @@ return uri; }; - var chainable = this.getFactory().domainPrincipalMap(this.getDomain()); + const chainable = this.getFactory().domainPrincipalMap(this.getDomain()); return this.chainGet(chainable, uriFunction, params); }, @@ -184,7 +184,7 @@ */ listAuthenticationGrants: function(pagination) { - var params = {}; + const params = {}; if (pagination) { Gitana.copyInto(params, pagination); @@ -193,7 +193,7 @@ params.domainId = this.getDomainId(); params.principalId = this.getId(); - var chainable = this.getFactory().authenticationGrantMap(this.getPlatform()); + const chainable = this.getFactory().authenticationGrantMap(this.getPlatform()); return this.chainGet(chainable, "/auth/grants", params); }, @@ -205,7 +205,7 @@ */ listTeamMemberships: function(teamable, pagination) { - var params = { + const params = { "teamableType": teamable.getType(), "teamableId": teamable.getId() }; @@ -215,12 +215,12 @@ Gitana.copyInto(params, pagination); } - var uriFunction = function() + const uriFunction = function() { return this.getUri() + "/teams"; }; - var chainable = this.getFactory().teamMap(this.getCluster(), this); + const chainable = this.getFactory().teamMap(this.getCluster(), this); return this.chainGet(chainable, uriFunction, params); } diff --git a/js/gitana/domain/DomainPrincipalMap.js b/js/gitana/domain/DomainPrincipalMap.js index f3cf108d..75263657 100644 --- a/js/gitana/domain/DomainPrincipalMap.js +++ b/js/gitana/domain/DomainPrincipalMap.js @@ -1,6 +1,6 @@ (function(window) { - var Gitana = window.Gitana; + Gitana = window.Gitana; Gitana.PrincipalMap = Gitana.AbstractPlatformObjectMap.extend( /** @lends Gitana.PrincipalMap.prototype */ @@ -12,7 +12,7 @@ * @class Map of principal objects * * @param {Gitana.Domain} domain Gitana domain instance. - * @param [Object] object + * @param {Object} object */ constructor: function(domain, object) { diff --git a/js/gitana/domain/extends/DomainGroup.js b/js/gitana/domain/extends/DomainGroup.js index 972eca79..1774d880 100644 --- a/js/gitana/domain/extends/DomainGroup.js +++ b/js/gitana/domain/extends/DomainGroup.js @@ -1,6 +1,6 @@ (function(window) { - var Gitana = window.Gitana; + Gitana = window.Gitana; Gitana.DomainGroup = { @@ -23,7 +23,7 @@ readGroupNode: function(branch, createIfNotFound) { // what we hand back - var result = this.subchain(this.getFactory().node(branch, "n:group")); + const result = this.subchain(this.getFactory().node(branch, "n:group")); // work result.subchain(branch).readGroupNode(this.getId(), createIfNotFound).then(function() { @@ -42,13 +42,13 @@ * * @param {String} filter type of principal to hand back ("user" or "group") * @param {Boolean} indirect whether to include members that inherit through child groups - * @param [Object] pagination + * @param {Object} pagination */ listMembers: function(filter, indirect, pagination) { - var self = this; + const self = this; - var params = {}; + const params = {}; if (pagination) { Gitana.copyInto(params, pagination); @@ -62,12 +62,12 @@ params["indirect"] = true; } - var uriFunction = function() + const uriFunction = function() { return self.getUri() + "/members"; }; - var chainable = this.getFactory().domainPrincipalMap(this.getDomain()); + const chainable = this.getFactory().domainPrincipalMap(this.getDomain()); return this.chainGet(chainable, uriFunction, params); }, @@ -78,15 +78,15 @@ * * @public * - * @param [Boolean] inherit whether to include members that inherit through child groups - * @param [Object] pagination + * @param {Boolean} inherit whether to include members that inherit through child groups + * @param {Object} pagination */ listUsers: function() { - var inherit = false; - var pagination = null; - var args = Gitana.makeArray(arguments); - var a1 = args.shift(); + let inherit = false; + let pagination = null; + const args = Gitana.makeArray(arguments); + const a1 = args.shift(); if (Gitana.isBoolean(a1)) { inherit = a1; @@ -107,15 +107,15 @@ * * @public * - * @param [Boolean] inherit whether to include members that inherit through child groups - * @param [Object] pagination + * @param {Boolean} inherit whether to include members that inherit through child groups + * @param {Object} pagination */ listGroups: function() { - var inherit = false; - var pagination = null; - var args = Gitana.makeArray(arguments); - var a1 = args.shift(); + let inherit = false; + let pagination = null; + const args = Gitana.makeArray(arguments); + const a1 = args.shift(); if (Gitana.isBoolean(a1)) { inherit = a1; @@ -140,7 +140,7 @@ */ addMember: function(principal) { - var principalDomainQualifiedId = this.extractPrincipalDomainQualifiedId(principal); + const principalDomainQualifiedId = this.extractPrincipalDomainQualifiedId(principal); return this.chainPostEmpty(null, this.getUri() + "/members/add?id=" + principalDomainQualifiedId); }, @@ -156,7 +156,7 @@ */ removeMember: function(principal) { - var principalDomainQualifiedId = this.extractPrincipalDomainQualifiedId(principal); + const principalDomainQualifiedId = this.extractPrincipalDomainQualifiedId(principal); return this.chainPostEmpty(null, this.getUri() + "/members/remove?id=" + principalDomainQualifiedId); } diff --git a/js/gitana/domain/extends/DomainUser.js b/js/gitana/domain/extends/DomainUser.js index 61e734c5..f3f4ddf9 100644 --- a/js/gitana/domain/extends/DomainUser.js +++ b/js/gitana/domain/extends/DomainUser.js @@ -1,6 +1,6 @@ (function(window) { - var Gitana = window.Gitana; + Gitana = window.Gitana; Gitana.DomainUser = { @@ -23,7 +23,7 @@ readPersonNode: function(branch, createIfNotFound) { // what we hand back - var result = this.subchain(this.getFactory().node(branch, "n:person")); + const result = this.subchain(this.getFactory().node(branch, "n:person")); // work result.subchain(branch).readPersonNode(this.getDomainQualifiedId(), createIfNotFound).then(function() { @@ -50,12 +50,12 @@ readDirectory: function() { - var directory = this.getFactory().directory(this.getPlatform(), { + const directory = this.getFactory().directory(this.getPlatform(), { "_doc": this.getDirectoryId() }); // what we hand back - var result = this.subchain(directory); + const result = this.subchain(directory); // work result.subchain(this.getPlatform()).readDirectory(this.getDirectoryId()).then(function() { @@ -67,19 +67,19 @@ readIdentity: function() { - var self = this; + const self = this; - var directory = this.getFactory().directory(this.getPlatform(), { + const directory = this.getFactory().directory(this.getPlatform(), { "_doc": this.getDirectoryId() }); - var identity = this.getFactory().identity(directory, { + const identity = this.getFactory().identity(directory, { "_doc": this.getIdentityId() }); // what we hand back - var result = this.subchain(identity); + const result = this.subchain(identity); // work result.subchain(this.getPlatform()).readDirectory(self.getDirectoryId()).then(function() { diff --git a/js/gitana/http/Http.js b/js/gitana/http/Http.js index f047348e..cbc26509 100644 --- a/js/gitana/http/Http.js +++ b/js/gitana/http/Http.js @@ -26,7 +26,7 @@ constructor: function() { // the http work queue - var enqueue = new Gitana.WorkQueue(Gitana.HTTP_WORK_QUEUE_SIZE); + const enqueue = new Gitana.WorkQueue(Gitana.HTTP_WORK_QUEUE_SIZE); /////////////////////////////////////////////////////////////////////////////////////// // @@ -35,30 +35,30 @@ this.invoke = function(options) { - var self = this; + const self = this; // add work to be done to the queue enqueue(function(options) { return function(workDoneFn) { - var method = options.method || 'GET'; - var url = options.url; - var data = options.data; - var headers = options.headers || {}; - var success = options.success || function () {}; - var failure = options.failure || function () {}; + const method = options.method || 'GET'; + const url = options.url; + const data = options.data; + const headers = options.headers || {}; + let success = options.success || function () {}; + let failure = options.failure || function () {}; // wrap a bit further to support release of the http work queue - var _success = success; + const _success = success; success = function() { workDoneFn(); - var args = Array.prototype.slice.call(arguments); + const args = Array.prototype.slice.call(arguments); _success.apply(self, args); }; - var _failure = failure; + const _failure = failure; failure = function() { workDoneFn(); - var args = Array.prototype.slice.call(arguments); + const args = Array.prototype.slice.call(arguments); _failure.apply(self, args); }; @@ -67,16 +67,16 @@ // ensure that CSRF token is applied (if available) // the csrf token - var csrfToken = Gitana.CSRF_TOKEN; + let csrfToken = Gitana.CSRF_TOKEN; if (!csrfToken) { // if we were not explicitly provided the token, look it up from a cookie // NOTE: this only works in the browser - for (var t = 0; t < Gitana.CSRF_COOKIE_NAMES.length; t++) + for (let t = 0; t < Gitana.CSRF_COOKIE_NAMES.length; t++) { - var cookieName = Gitana.CSRF_COOKIE_NAMES[t]; + const cookieName = Gitana.CSRF_COOKIE_NAMES[t]; - var cookieValue = Gitana.readCookie(cookieName); + const cookieValue = Gitana.readCookie(cookieName); if (cookieValue) { csrfToken = cookieValue; @@ -92,7 +92,7 @@ // XHR_CACHE_FN if (typeof(Gitana.XHR_CACHE_FN) !== "undefined" && Gitana.XHR_CACHE_FN !== null) { - var responseObject = Gitana.XHR_CACHE_FN({ + const responseObject = Gitana.XHR_CACHE_FN({ method: method, url: url, headers: headers @@ -116,7 +116,7 @@ } } - var xhr = Gitana.Http.Request(); + const xhr = Gitana.Http.Request(); if (Gitana.XHR_WITH_CREDENTIALS) { @@ -124,7 +124,7 @@ } // timeout handler - var httpTimeoutFn = function () { + const httpTimeoutFn = function () { xhr.abort(); if (Gitana.HTTP_TIMEOUT_FN) @@ -134,7 +134,7 @@ //console.log("HTTP Request timed out"); - var responseObject = { + const responseObject = { "timeout": true, "text": "Http Request timed out", "info": { @@ -148,7 +148,7 @@ return false; }; - var httpTimeoutHolder = null; + let httpTimeoutHolder = null; if (Gitana.HTTP_TIMEOUT > 0) { httpTimeoutHolder = setTimeout(httpTimeoutFn, Gitana.HTTP_TIMEOUT); @@ -157,7 +157,7 @@ xhr.onreadystatechange = function () { if (xhr.readyState === 4) { - var regex = /^(.*?):\s*(.*?)\r?$/mg, requestHeaders = headers, responseHeaders = {}, responseHeadersString = '', match; + let regex = /^(.*?):\s*(.*?)\r?$/mg, requestHeaders = headers, responseHeaders = {}, responseHeadersString = '', match; if (!!xhr.getAllResponseHeaders) { @@ -170,22 +170,22 @@ else if (!!xhr.getResponseHeaders) { responseHeadersString = xhr.getResponseHeaders(); - for (var i = 0, len = responseHeadersString.length; i < len; ++i) + for (let i = 0, len = responseHeadersString.length; i < len; ++i) { responseHeaders[responseHeadersString[i][0]] = responseHeadersString[i][1]; } } - var includeXML = false; + let includeXML = false; if ('Content-Type' in responseHeaders) { - if (responseHeaders['Content-Type'] == 'text/xml') + if (responseHeaders['Content-Type'] === 'text/xml') { includeXML = true; } } - var responseObject = { + const responseObject = { text: xhr.responseText, xml: (includeXML ? xhr.responseXML : ''), requestHeaders: requestHeaders, @@ -197,7 +197,7 @@ { // not handled } - if ((xhr.status >= 200 && xhr.status <= 226) || xhr.status == 304) + if ((xhr.status >= 200 && xhr.status <= 226) || xhr.status === 304) { if (httpTimeoutHolder) { @@ -257,7 +257,7 @@ */ xhr.setRequestHeader('X-Requested-With', 'XMLHttpRequest'); - for (var header in headers) + for (const header in headers) { xhr.setRequestHeader(header, headers[header]); } @@ -270,7 +270,7 @@ { console.log(e); } - } + }; }(options)); }; }, @@ -288,18 +288,18 @@ Gitana.Http.toQueryString = function(params) { - var queryString = ""; + let queryString = ""; if (params) { - for (var k in params) + for (const k in params) { if (queryString.length > 0) { queryString += "&"; } - var val = null; + let val = null; if (params[k]) { val = params[k]; @@ -320,7 +320,7 @@ Gitana.Http.Request = function() { - var XHR = null; + let XHR = null; // allow for custom XHR factory if (Gitana.HTTP_XHR_FACTORY) { @@ -344,7 +344,7 @@ return XHR; }; - var Hash = function() {}; + const Hash = function() {}; Hash.prototype = { join: function(string) @@ -355,7 +355,7 @@ keys: function() { - var i, arr = [], self = this; + let i, arr = [], self = this; for (i in self) { if (self.hasOwnProperty(i)) { arr.push(i); @@ -367,7 +367,7 @@ values: function() { - var i, arr = [], self = this; + let i, arr = [], self = this; for (i in self) { if (self.hasOwnProperty(i)) { arr.push(self[i]); @@ -383,9 +383,9 @@ sort: function(){throw 'not implemented';}, ksort: function(func){ - var self = this, keys = self.keys(), i, value, key; + let self = this, keys = self.keys(), i, value, key; - if (func == undefined) { + if (func === undefined) { keys.sort(); } else { keys.sort(func); @@ -401,7 +401,7 @@ return self; }, toObject: function () { - var obj = {}, i, self = this; + let obj = {}, i, self = this; for (i in self) { if (self.hasOwnProperty(i)) { obj[i] = self[i]; @@ -412,9 +412,9 @@ } }; - var Collection = function(obj) + const Collection = function(obj) { - var args = arguments, args_callee = args.callee, args_length = args.length, + let args = arguments, args_callee = args.callee, i, collection = this; if (!(this instanceof args_callee)) { @@ -433,7 +433,7 @@ Gitana.Http.URI = function(url) { - var args = arguments, args_callee = args.callee, + let args = arguments, args_callee = args.callee, parsed_uri, scheme, host, port, path, query, anchor, parser = /^([^:\/?#]+?:\/\/)*([^\/:?#]*)?(:[^\/?#]*)*([^?#]*)(\?[^#]*)?(#(.*))*/, uri = this; @@ -464,7 +464,7 @@ scheme = (scheme !== undefined) ? scheme.replace('://', '').toLowerCase() : 'http'; port = (port ? port.replace(':', '') : (scheme === 'https' ? '443' : '80')); // correct the scheme based on port number - scheme = (scheme == 'http' && port === '443' ? 'https' : scheme); + scheme = (scheme === 'http' && port === '443' ? 'https' : scheme); query = query ? query.replace('?', '') : ''; anchor = anchor ? anchor.replace('#', '') : ''; @@ -491,21 +491,21 @@ query: '', anchor: '', toString: function () { - var self = this, query = self.query + ''; - return self.scheme + '://' + self.host + self.path + (query != '' ? '?' + query : '') + (self.anchor !== '' ? '#' + self.anchor : ''); + const self = this, query = self.query + ''; + return self.scheme + '://' + self.host + self.path + (query !== '' ? '?' + query : '') + (self.anchor !== '' ? '#' + self.anchor : ''); } }; Gitana.Http.QueryString = function(obj) { - var args = arguments, args_callee = args.callee, args_length = args.length, + let args = arguments, args_callee = args.callee, i, querystring = this; if (!(this instanceof args_callee)) { return new args_callee(obj); } - if (obj != undefined) { + if (obj !== undefined) { for (i in obj) { if (obj.hasOwnProperty(i)) { querystring[i] = obj[i]; @@ -521,13 +521,13 @@ Gitana.Http.QueryString.prototype.toString = function () { - var i, self = this, q_arr = [], ret = '', + let i, self = this, q_arr = [], ret = '', val = '', encode = Gitana.Http.URLEncode; self.ksort(); // lexicographical byte value ordering of the keys for (i in self) { if (self.hasOwnProperty(i)) { - if (i != undefined && self[i] != undefined) { + if (i !== undefined && self[i] !== undefined) { val = encode(i) + '=' + encode(self[i]); q_arr.push(val); } @@ -543,10 +543,10 @@ Gitana.Http.QueryString.prototype.setQueryParams = function (query) { - var args = arguments, args_length = args.length, i, query_array, + let args = arguments, args_length = args.length, i, query_array, query_array_length, querystring = this, key_value; - if (args_length == 1) { + if (args_length === 1) { if (typeof query === 'object') { // iterate for (i in query) { @@ -575,7 +575,7 @@ Gitana.Http.URLEncode = function(string) { function hex(code) { - var hex = code.toString(16).toUpperCase(); + let hex = code.toString(16).toUpperCase(); if (hex.length < 2) { hex = 0 + hex; } @@ -587,7 +587,7 @@ } string = string + ''; - var reserved_chars = /[ \r\n!*"'();:@&=+$,\/?%#\[\]<>{}|`^\\\u0080-\uffff]/, + let reserved_chars = /[ \r\n!*"'();:@&=+$,\/?%#\[\]<>{}|`^\\\u0080-\uffff]/, str_len = string.length, i, string_arr = string.split(''), c; for (i = 0; i < str_len; i++) diff --git a/js/gitana/http/OAuth2Http.js b/js/gitana/http/OAuth2Http.js index 6da3565d..b43a38af 100644 --- a/js/gitana/http/OAuth2Http.js +++ b/js/gitana/http/OAuth2Http.js @@ -1,4 +1,4 @@ -(function(global) +(function() { Gitana.OAuth2Http = Gitana.Http.extend( /** @lends Gitana.OAuth2Http.prototype */ @@ -10,7 +10,7 @@ */ constructor: function(options, storage) { - var self = this; + const self = this; // storage for OAuth credentials // this can either be a string ("local", "session", "memory") or a storage instance or empty @@ -32,22 +32,22 @@ this.errorUri = null; // gitana urls - var tokenURL = "/oauth/token"; + let tokenURL = "/oauth/token"; if (options.tokenURL) { tokenURL = options.tokenURL; } // base URL? - var baseURL = null; + let baseURL = null; if (options.baseURL) { baseURL = options.baseURL; } // client - var clientKey = options.clientKey; - var clientSecret = options.clientSecret; + const clientKey = options.clientKey; + const clientSecret = options.clientSecret; // authorization flow // if none specified, assume AUTHORIZATION CODE @@ -59,13 +59,13 @@ this.requestedScope = options.requestedScope; } - if (this.authorizationFlow == Gitana.OAuth2Http.AUTHORIZATION_CODE) + if (this.authorizationFlow === Gitana.OAuth2Http.AUTHORIZATION_CODE) { this.code = options.code; this.redirectUri = options.redirectUri; } - if (this.authorizationFlow == Gitana.OAuth2Http.PASSWORD) + if (this.authorizationFlow === Gitana.OAuth2Http.PASSWORD) { this.username = options.username; @@ -79,12 +79,12 @@ } } - if (this.authorizationFlow == Gitana.OAuth2Http.COOKIE) + if (this.authorizationFlow === Gitana.OAuth2Http.COOKIE) { this.cookieMode = true; } - if (this.authorizationFlow == Gitana.OAuth2Http.TICKET) + if (this.authorizationFlow === Gitana.OAuth2Http.TICKET) { this.ticketMode = options.ticket; } @@ -109,7 +109,7 @@ /** * Gets or saves the access token * - * @param value [String] optional value + * @param value {String} optional value */ this.accessToken = function(value) { @@ -158,7 +158,7 @@ this.getClientAuthorizationHeader = function() { - var basicString = clientKey + ":"; + let basicString = clientKey + ":"; if (clientSecret) { basicString += clientSecret; @@ -178,7 +178,7 @@ this.getPrefixedURL = function(url) { - var rebasedURL = url; + let rebasedURL = url; if (baseURL && Gitana.startsWith(url, "/")) { rebasedURL = baseURL + url; @@ -190,9 +190,9 @@ // if they initiatialized with an access token, clear and write into persisted state // unless they're continuing an existing token - if (this.authorizationFlow == Gitana.OAuth2Http.TOKEN) + if (this.authorizationFlow === Gitana.OAuth2Http.TOKEN) { - var existingAccessToken = this.accessToken(); + const existingAccessToken = this.accessToken(); if (existingAccessToken !== options.accessToken) { storage.clear(); @@ -211,7 +211,7 @@ */ request: function(options) { - var self = this; + const self = this; /** * Call over to Gitana and acquires an access token using flow authorization. @@ -219,11 +219,11 @@ * @param success * @param failure */ - var doGetAccessToken = function(success, failure) + const doGetAccessToken = function(success, failure) { - var onSuccess = function(response, xhr) + const onSuccess = function(response, xhr) { - var object = JSON.parse(response.text); + const object = JSON.parse(response.text); if (object["error"]) { self.error = object["error"]; @@ -233,11 +233,11 @@ return failure(response, xhr); } - var _accessToken = object["access_token"]; - var _refreshToken = object["refresh_token"]; - var _expiresIn = object["expires_in"]; - var _grantedScope = object["scope"]; - var _grantTime = new Date().getTime(); + const _accessToken = object["access_token"]; + const _refreshToken = object["refresh_token"]; + const _expiresIn = object["expires_in"]; + const _grantedScope = object["scope"]; + const _grantTime = new Date().getTime(); // store into persistent storage self.clearStorage(); @@ -252,11 +252,11 @@ success(); }; - var onFailure = function(http, xhr) { + const onFailure = function(http, xhr) { failure(http, xhr); }; - var o = { + const o = { success: onSuccess, failure: onFailure, headers: {}, @@ -275,7 +275,7 @@ o.headers["Authorization"] = self.getClientAuthorizationHeader(); // query string - var qs = {}; + const qs = {}; // ticket max age if (self.ticketMaxAge) @@ -289,7 +289,7 @@ o.headers["Content-Type"] = "application/x-www-form-urlencoded"; // url encoded payload - var urlEncodedTokens = {}; + const urlEncodedTokens = {}; urlEncodedTokens["grant_type"] = self.authorizationFlow; if (self.requestedScope) { urlEncodedTokens["scope"] = self.requestedScope; @@ -329,7 +329,7 @@ } // append into query string - var queryString = Gitana.Http.toQueryString(qs); + const queryString = Gitana.Http.toQueryString(qs); if (queryString) { if (o.url.indexOf("?") > -1) @@ -354,7 +354,7 @@ Gitana.REFRESH_TOKEN_LOCK_REATTEMPT_MS = 75; } - var waitForPendingRefresh = function(key, oldAccessToken) + const waitForPendingRefresh = function(key, oldAccessToken) { setTimeout(function() { @@ -365,17 +365,17 @@ // if we get this far, we take advantage of the new access key // first check to make sure that it is a different access key - var newAccessToken = self.accessToken(); + const newAccessToken = self.accessToken(); // we try the call again under the assumption that the access token is valid // if the access token is different, we allow for another attempted refresh // otherwise we do not to avoid spinning around forever - var autoAttemptRefresh = (newAccessToken === oldAccessToken); + const autoAttemptRefresh = (newAccessToken === oldAccessToken); // fire the call doCall(autoAttemptRefresh); - }, Gitana.REFRESH_TOKEN_LOCK_REATTEMPT_MS) + }, Gitana.REFRESH_TOKEN_LOCK_REATTEMPT_MS); }; /** @@ -389,10 +389,10 @@ * @param success * @param failure */ - var doRefreshAccessToken = function(success, failure) { + const doRefreshAccessToken = function(success, failure) { - var key = self.refreshToken(); - var oldAccessToken = self.accessToken(); + const key = self.refreshToken(); + const oldAccessToken = self.accessToken(); // if another "thread" is refreshing for this refresh key, then we wait until it finishes // when it finishes, we either use the acquired access token or make another attempt @@ -422,11 +422,11 @@ }); }; - var _doRefreshAccessToken = function(success, failure) { + const _doRefreshAccessToken = function(success, failure) { - var onSuccess = function(response) + const onSuccess = function(response) { - var object = JSON.parse(response.text); + const object = JSON.parse(response.text); if (response["error"]) { self.error = object["error"]; @@ -435,12 +435,12 @@ } else { - var _accessToken = object["access_token"]; - var _refreshToken = object["refresh_token"]; - var _expiresIn = object["expires_in"]; + const _accessToken = object["access_token"]; + const _refreshToken = object["refresh_token"]; + const _expiresIn = object["expires_in"]; //self.grantedScope = object["scope"]; // this doesn't come back on refresh, assumed the same - var _grantTime = new Date().getTime(); - var _grantedScope = self.grantedScope(); + const _grantTime = new Date().getTime(); + const _grantedScope = self.grantedScope(); // store into persistent storage self.clearStorage(); @@ -454,14 +454,14 @@ success(response); }; - var onFailure = function(http, xhr) { + const onFailure = function(http, xhr) { Gitana.REFRESH_TOKEN_FAILURE_FN(self, http, xhr); failure(http, xhr); }; - var o = { + const o = { success: onSuccess, failure: onFailure, headers: {}, @@ -480,7 +480,7 @@ o.headers["Authorization"] = self.getClientAuthorizationHeader(); // query string - var qs = {}; + const qs = {}; // ticket max age if (self.ticketMaxAge) @@ -494,7 +494,7 @@ o.headers["Content-Type"] = "application/x-www-form-urlencoded"; // url encoded payload - var urlEncodedTokens = {}; + const urlEncodedTokens = {}; urlEncodedTokens["grant_type"] = "refresh_token"; urlEncodedTokens["refresh_token"] = self.refreshToken(); if (self.requestedScope) @@ -514,7 +514,7 @@ } // append into query string - var queryString = Gitana.Http.toQueryString(qs); + const queryString = Gitana.Http.toQueryString(qs); if (queryString) { if (o.url.indexOf("?") > -1) @@ -530,14 +530,14 @@ self.invoke(o); }; - var doCall = function(autoAttemptRefresh) + const doCall = function(autoAttemptRefresh) { - var successHandler = function(response) + const successHandler = function(response) { options.success(response); }; - var failureHandler = function(http, xhr) + const failureHandler = function(http, xhr) { if (autoAttemptRefresh) { @@ -551,11 +551,11 @@ // in this case, we get back a 401 // it might not make much sense to re-request a new access token, but we do just in case. - var notJson = false; - var isInvalidToken = false; + let notJson = false; + let isInvalidToken = false; if (http.text) { - var responseData = {}; + let responseData = {}; // catch if http.text is not JSON try @@ -572,16 +572,16 @@ if (responseData.error) { - if (responseData.error == "invalid_token") + if (responseData.error === "invalid_token") { isInvalidToken = true; } } } - var is401 = (http.code == 401); - var is400 = (http.code == 400); - var is403 = (http.code == 403); - var isTimeout = http.timeout; + const is401 = (http.code === 401); + const is400 = (http.code === 400); + const is403 = (http.code === 403); + const isTimeout = http.timeout; // handle both cases if (is401 || is400 || is403 || isInvalidToken || (notJson && !isTimeout)) @@ -622,7 +622,7 @@ }; // call through to the protected resource (with custom success/failure handling) - var o = {}; + const o = {}; Gitana.copyInto(o, options); o.success = successHandler; o.failure = failureHandler; @@ -656,20 +656,20 @@ // this is important for any browser-originated requests that rely on a persisted cookie (GITANA_TICKET) // // also provide some debugging if needed - var forceRefresh = false; + let forceRefresh = false; if (self.accessToken()) { - var grantTime = self.grantTime(); + const grantTime = self.grantTime(); if (grantTime) { - var expiresIn = self.expiresIn(); + const expiresIn = self.expiresIn(); if (expiresIn) { // NOTE: expiresIn is in seconds - var expirationTimeMs = self.grantTime() + (self.expiresIn() * 1000); - var nowTimeMs = new Date().getTime(); + const expirationTimeMs = self.grantTime() + (self.expiresIn() * 1000); + const nowTimeMs = new Date().getTime(); - var timeRemainingMs = expirationTimeMs - nowTimeMs; + const timeRemainingMs = expirationTimeMs - nowTimeMs; if (timeRemainingMs <= 0) { // console.log("Access Token is expired, refresh will be attempted!"); @@ -734,10 +734,9 @@ */ refresh: function(callback) { - var self = this; + const self = this; - var currentAccessToken = self.accessToken(); - var currentRefreshToken = self.refreshToken(); + const currentRefreshToken = self.refreshToken(); if (!currentRefreshToken) { return callback({ @@ -745,9 +744,9 @@ }); } - var onSuccess = function(response) + const onSuccess = function(response) { - var object = JSON.parse(response.text); + const object = JSON.parse(response.text); if (object["error"]) { self.error = object["error"]; @@ -761,12 +760,12 @@ } else { - var _accessToken = object["access_token"]; - var _refreshToken = object["refresh_token"]; - var _expiresIn = object["expires_in"]; + const _accessToken = object["access_token"]; + const _refreshToken = object["refresh_token"]; + const _expiresIn = object["expires_in"]; //self.grantedScope = object["scope"]; // this doesn't come back on refresh, assumed the same - var _grantTime = new Date().getTime(); - var _grantedScope = self.grantedScope(); + const _grantTime = new Date().getTime(); + const _grantedScope = self.grantedScope(); // store into persistent storage self.clearStorage(); @@ -780,7 +779,7 @@ } }; - var onFailure = function(http, xhr) + const onFailure = function(http, xhr) { if (Gitana.REFRESH_TOKEN_FAILURE_FN) { @@ -795,7 +794,7 @@ }); }; - var o = { + const o = { success: onSuccess, failure: onFailure, headers: {}, @@ -814,7 +813,7 @@ o.headers["Authorization"] = self.getClientAuthorizationHeader(); // query string - var qs = {}; + const qs = {}; // ticket max age if (self.ticketMaxAge) @@ -828,7 +827,7 @@ o.headers["Content-Type"] = "application/x-www-form-urlencoded"; // url encoded data - var urlEncodedTokens = {}; + const urlEncodedTokens = {}; urlEncodedTokens["grant_type"] = "refresh_token"; urlEncodedTokens["refresh_token"] = self.refreshToken(); if (self.requestedScope) @@ -848,7 +847,7 @@ } // append into query string - var queryString = Gitana.Http.toQueryString(qs); + const queryString = Gitana.Http.toQueryString(qs); if (queryString) { if (o.url.indexOf("?") > -1) @@ -877,11 +876,11 @@ Gitana.OAuth2Http.Storage = function(scope) { // in-memory implementation of HTML5 storage interface - var memoryStorage = function() { + const memoryStorage = function() { - var memory = {}; + const memory = {}; - var m = {}; + const m = {}; m.removeItem = function(key) { delete memory[key]; @@ -905,7 +904,7 @@ * * @return {Boolean} */ - var supportsLocalStorage = function() + const supportsLocalStorage = function() { try { return 'localStorage' in window && window['localStorage'] !== null; @@ -919,7 +918,7 @@ * * @return {Boolean} */ - var supportsSessionStorage = function() + const supportsSessionStorage = function() { try { return 'sessionStorage' in window && window['sessionStorage'] !== null; @@ -928,16 +927,16 @@ } }; - var acquireStorage = function() + const acquireStorage = function() { - var storage = null; + let storage = null; // store - if (scope == "session" && supportsSessionStorage()) + if (scope === "session" && supportsSessionStorage()) { storage = sessionStorage; } - else if (scope == "local" && supportsLocalStorage()) + else if (scope === "local" && supportsLocalStorage()) { storage = localStorage; } @@ -951,7 +950,7 @@ }; // result object - var r = {}; + const r = {}; /** * Clears state. @@ -977,14 +976,14 @@ */ r.poke = function(key, value) { - var state = {}; + let state = {}; - var stateString = acquireStorage().getItem("gitanaAuthState"); + const stateString = acquireStorage().getItem("gitanaAuthState"); if (stateString && stateString !== "") { state = JSON.parse(stateString); } - var touch = false; + let touch = false; if (typeof(value) !== "undefined" && value !== null) { state[key] = value; diff --git a/js/gitana/methods/GitanaMethods.js b/js/gitana/methods/GitanaMethods.js index 54598f59..c50adbe7 100644 --- a/js/gitana/methods/GitanaMethods.js +++ b/js/gitana/methods/GitanaMethods.js @@ -3,9 +3,9 @@ Gitana.Methods = {}; /** - * Produces the common function to handle listAttachments() on various attachables within Gitana. + * Produces the common function to handle listAttachments() on constious attachables within Gitana. * - * @param [mapClass] map implementation class (if none provided, uses Gitana.BinaryAttachmentMap) + * @param {Function} [mapClass] map implementation class (if none provided, uses Gitana.BinaryAttachmentMap) * * @return {Function} */ @@ -17,15 +17,15 @@ return function(local) { - var self = this; + const self = this; - var result = this.subchain(new mapClass(this)); + const result = this.subchain(new mapClass(this)); if (!local) { // front-load some work that fetches from remote server result.then(function() { - var chain = this; + const chain = this; self.getDriver().gitanaGet(self.getUri() + "/attachments", null, {}, function(response) { chain.handleResponse(response); @@ -38,16 +38,16 @@ else { // try to populate the map from our cached values on the node (if they exist) - var existingMap = self.getSystemMetadata()["attachments"]; + const existingMap = self.getSystemMetadata()["attachments"]; if (existingMap) { // attachments that come off of system() don't have "attachmentId" on their json object // instead, the "attachmentId" is the key into the map. // so here, in terms of normalizing things, we copy "attachmentId" into the json object - for (var key in existingMap) + for (const key in existingMap) { - var value = result[key]; + const value = result[key]; value["attachmentId"] = key; } } @@ -75,7 +75,7 @@ return function(attachmentId, contentType, data) { - var self = this; + const self = this; if (!attachmentId) { @@ -83,29 +83,29 @@ } // the thing we're handing back - var result = this.subchain(new attachmentClass(this)); + const result = this.subchain(new attachmentClass(this)); // preload some work onto a subchain result.then(function() { // params - var params = {}; + const params = {}; if (paramsFunction) { paramsFunction(params); } // upload the attachment - var uploadUri = self.getUri() + "/attachments/" + attachmentId; + let uploadUri = self.getUri() + "/attachments/" + attachmentId; // if data is a Node read stream, we use a helper function possibly to conduct the upload if (data && data.read && typeof(data.read) === "function" && Gitana.streamUpload) { this.subchain(self).then(function() { - var chain = this; + const chain = this; uploadUri = self.getDriver().baseURL + uploadUri; - Gitana.streamUpload(self.getDriver(), data, uploadUri, contentType, function(err) { + Gitana.streamUpload(self.getDriver(), data, uploadUri, contentType, function() { // read back attachment information and plug onto result Chain(self).reload().then(function() { @@ -167,13 +167,13 @@ return function(name, config) { - var url = this.getDriver().baseURL + this.getUri() + "/" + prefix + "/" + name; + let url = this.getDriver().baseURL + this.getUri() + "/" + prefix + "/" + name; if (config) { - var first = true; + let first = true; - for (var key in config) + for (const key in config) { if (first) { @@ -184,7 +184,7 @@ url += "&"; } - var value = config[key]; + const value = config[key]; if (value) { url += key + "=" + value; diff --git a/js/gitana/platform/AbstractPlatformDataStore.js b/js/gitana/platform/AbstractPlatformDataStore.js index 585de24f..5d401b86 100644 --- a/js/gitana/platform/AbstractPlatformDataStore.js +++ b/js/gitana/platform/AbstractPlatformDataStore.js @@ -1,6 +1,6 @@ (function(window) { - var Gitana = window.Gitana; + Gitana = window.Gitana; Gitana.AbstractPlatformDataStore = Gitana.ContainedDataStore.extend( /** @lends Gitana.AbstractPlatformDataStore.prototype */ @@ -12,7 +12,7 @@ * @class AbstractPlatformDataStore * * @param {Gitana.Platform} platform - * @param [Object] object json object (if no callback required for populating) + * @param {Object} object json object (if no callback required for populating) */ constructor: function(platform, object) { @@ -74,9 +74,9 @@ */ copy: function(target, asynchronous, config) { - var self = this; + const self = this; - var payload = { + const payload = { "sources": Gitana.toCopyDependencyChain(this), "targets": Gitana.toCopyDependencyChain(target) }; @@ -86,12 +86,12 @@ } // we continue the chain with a job - var chainable = this.getFactory().job(this.getCluster(), "copy"); + const chainable = this.getFactory().job(this.getCluster(), "copy"); // fire off copy and job queue checking return this.subchain(chainable).then(function() { - var chain = this; + const chain = this; // create this.getDriver().gitanaPost("/tools/copy?schedule=ASYNCHRONOUS", {}, payload, function(response) { @@ -109,10 +109,6 @@ /** * Finds the stack for this data store. - * - * @param datastoreType - * @param datastoreId - * * @chained stack */ findStack: function() @@ -133,7 +129,7 @@ */ loadInfo: function(callback) { - var uriFunction = function() + const uriFunction = function() { return this.getUri() + "/info"; }; diff --git a/js/gitana/platform/AbstractPlatformObject.js b/js/gitana/platform/AbstractPlatformObject.js index 2beae98e..af8b5737 100644 --- a/js/gitana/platform/AbstractPlatformObject.js +++ b/js/gitana/platform/AbstractPlatformObject.js @@ -1,7 +1,7 @@ (function(window) { - var Gitana = window.Gitana; - + Gitana = window.Gitana; + Gitana.AbstractPlatformObject = Gitana.AbstractSelfableACLObject.extend( /** @lends Gitana.AbstractPlatformObject.prototype */ { @@ -70,34 +70,34 @@ */ exportArchive: function(settings) { - var self = this; + const self = this; - var vaultId = settings.vault; + let vaultId = settings.vault; if (!Gitana.isString(vaultId)) { vaultId = vaultId.getId(); } - var groupId = settings.group; - var artifactId = settings.artifact; - var versionId = settings.version; - var configuration = (settings.configuration ? settings.configuration : {}); - var synchronous = (settings.async ? false : true); + const groupId = settings.group; + const artifactId = settings.artifact; + const versionId = settings.version; + const configuration = (settings.configuration ? settings.configuration : {}); + const synchronous = !settings.async; // archive additional properties - var title = settings.title; - var description = settings.description; - var published = settings.published; + const title = settings.title; + const description = settings.description; + const published = settings.published; // we continue the chain with a job - var chainable = this.getFactory().job(this.getCluster(), "export"); + const chainable = this.getFactory().job(this.getCluster(), "export"); // fire off import and job queue checking return this.subchain(chainable).then(function() { - var chain = this; + const chain = this; // create - var params = {}; + const params = {}; params["vault"] = vaultId; params["group"] = groupId; params["artifact"] = artifactId; @@ -129,30 +129,30 @@ * @chained job * * @param {Object} settings - * @param [Function] reportFn + * @param {Function} reportFn */ importArchive: function(settings, reportFn) { - var self = this; + const self = this; - var vaultId = settings.vault; + let vaultId = settings.vault; if (!Gitana.isString(vaultId)) { vaultId = vaultId.getId(); } - var groupId = settings.group; - var artifactId = settings.artifact; - var versionId = settings.version; - var configuration = (settings.configuration ? settings.configuration : {}); - var synchronous = (settings.async ? false : true); + const groupId = settings.group; + const artifactId = settings.artifact; + const versionId = settings.version; + const configuration = (settings.configuration ? settings.configuration : {}); + const synchronous = !settings.async; // we continue the chain with a job - var chainable = this.getFactory().job(this.getCluster(), "import"); + const chainable = this.getFactory().job(this.getCluster(), "import"); // fire off import and job queue checking return this.subchain(chainable).then(function() { - var chain = this; + const chain = this; // create this.getDriver().gitanaPost(self.getUri() + "/import?vault=" + vaultId + "&group=" + groupId + "&artifact=" + artifactId + "&version=" + versionId + "&schedule=ASYNCHRONOUS", {}, configuration, function(response) { @@ -187,9 +187,9 @@ */ copy: function(target, asynchronous, config) { - var self = this; + const self = this; - var payload = { + const payload = { "sources": Gitana.toCopyDependencyChain(this), "targets": Gitana.toCopyDependencyChain(target) }; @@ -199,12 +199,12 @@ } // we continue the chain with a job - var chainable = this.getFactory().job(this.getCluster(), "copy"); + const chainable = this.getFactory().job(this.getCluster(), "copy"); // fire off copy and job queue checking return this.subchain(chainable).then(function() { - var chain = this; + const chain = this; // create this.getDriver().gitanaPost("/tools/copy?schedule=ASYNCHRONOUS", {}, payload, function(response) { diff --git a/js/gitana/platform/AbstractPlatformObjectMap.js b/js/gitana/platform/AbstractPlatformObjectMap.js index 80c53fdd..a7fb4c3a 100644 --- a/js/gitana/platform/AbstractPlatformObjectMap.js +++ b/js/gitana/platform/AbstractPlatformObjectMap.js @@ -1,6 +1,6 @@ (function(window) { - var Gitana = window.Gitana; + Gitana = window.Gitana; Gitana.AbstractPlatformObjectMap = Gitana.AbstractMap.extend( /** @lends Gitana.AbstractPlatformObjectMap.prototype */ @@ -12,7 +12,7 @@ * @class AbstractPlatformObjectMap * * @param {Gitana.Platform} platform Gitana platform instance. - * @param [Object] object + * @param {Object} object */ constructor: function(platform, object) { diff --git a/js/gitana/platform/AccessPolicy.js b/js/gitana/platform/AccessPolicy.js index 16a76155..733cd624 100644 --- a/js/gitana/platform/AccessPolicy.js +++ b/js/gitana/platform/AccessPolicy.js @@ -1,6 +1,6 @@ (function(window) { - var Gitana = window.Gitana; + Gitana = window.Gitana; Gitana.AccessPolicy = Gitana.AbstractPlatformObject.extend( /** @lends Gitana.AccessPolicy.prototype */ @@ -12,7 +12,7 @@ * @class AccessPolicy * * @param {Gitana.Platform} platform - * @param [Object] object json object (if no callback required for populating) + * @param {Object} object json object (if no callback required for populating) */ constructor: function(platform, object) { diff --git a/js/gitana/platform/AccessPolicyMap.js b/js/gitana/platform/AccessPolicyMap.js index 594eb180..e0205153 100644 --- a/js/gitana/platform/AccessPolicyMap.js +++ b/js/gitana/platform/AccessPolicyMap.js @@ -1,6 +1,6 @@ (function(window) { - var Gitana = window.Gitana; + Gitana = window.Gitana; Gitana.AccessPolicyMap = Gitana.AbstractPlatformObjectMap.extend( /** @lends Gitana.AccessPolicyMap.prototype */ @@ -12,7 +12,7 @@ * @class Map of access policies * * @param {Gitana.Platform} platform Gitana platform instance. - * @param [Object] object + * @param {Object} object */ constructor: function(platform, object) { diff --git a/js/gitana/platform/AuthenticationGrant.js b/js/gitana/platform/AuthenticationGrant.js index 89e0508a..0badae1b 100644 --- a/js/gitana/platform/AuthenticationGrant.js +++ b/js/gitana/platform/AuthenticationGrant.js @@ -1,6 +1,6 @@ (function(window) { - var Gitana = window.Gitana; + Gitana = window.Gitana; Gitana.AuthenticationGrant = Gitana.AbstractPlatformObject.extend( /** @lends Gitana.AuthenticationGrant.prototype */ @@ -12,7 +12,7 @@ * @class AuthenticationGrant * * @param {Gitana.Platform} platform - * @param [Object] object json object (if no callback required for populating) + * @param {Object} object json object (if no callback required for populating) */ constructor: function(platform, object) { diff --git a/js/gitana/platform/AuthenticationGrantMap.js b/js/gitana/platform/AuthenticationGrantMap.js index 3727cdd7..11c1d43a 100644 --- a/js/gitana/platform/AuthenticationGrantMap.js +++ b/js/gitana/platform/AuthenticationGrantMap.js @@ -1,6 +1,6 @@ (function(window) { - var Gitana = window.Gitana; + Gitana = window.Gitana; Gitana.AuthenticationGrantMap = Gitana.AbstractPlatformObjectMap.extend( /** @lends Gitana.AuthenticationGrantMap.prototype */ @@ -12,7 +12,7 @@ * @class Map of authentication grants * * @param {Gitana.Platform} platform Gitana platform instance. - * @param [Object] object + * @param {Object} object */ constructor: function(platform, object) { diff --git a/js/gitana/platform/BillingProviderConfiguration.js b/js/gitana/platform/BillingProviderConfiguration.js index 11c43d36..52a36452 100644 --- a/js/gitana/platform/BillingProviderConfiguration.js +++ b/js/gitana/platform/BillingProviderConfiguration.js @@ -1,6 +1,6 @@ (function(window) { - var Gitana = window.Gitana; + Gitana = window.Gitana; Gitana.BillingProviderConfiguration = Gitana.AbstractPlatformObject.extend( /** @lends Gitana.BillingProviderConfiguration.prototype */ @@ -12,7 +12,7 @@ * @class BillingProviderConfiguration * * @param {Gitana.Platform} platform - * @param [Object] object json object (if no callback required for populating) + * @param {Object} object json object (if no callback required for populating) */ constructor: function(platform, object) { diff --git a/js/gitana/platform/BillingProviderConfigurationMap.js b/js/gitana/platform/BillingProviderConfigurationMap.js index 264a3546..7ab0ed45 100644 --- a/js/gitana/platform/BillingProviderConfigurationMap.js +++ b/js/gitana/platform/BillingProviderConfigurationMap.js @@ -1,6 +1,6 @@ (function(window) { - var Gitana = window.Gitana; + Gitana = window.Gitana; Gitana.BillingProviderConfigurationMap = Gitana.AbstractPlatformObjectMap.extend( /** @lends Gitana.BillingProviderConfigurationMap.prototype */ @@ -12,7 +12,7 @@ * @class Map of billing provider configurations * * @param {Gitana.Platform} platform Gitana platform instance. - * @param [Object] object + * @param {Object} object */ constructor: function(platform, object) { diff --git a/js/gitana/platform/Client.js b/js/gitana/platform/Client.js index 2d808096..c26c0d56 100644 --- a/js/gitana/platform/Client.js +++ b/js/gitana/platform/Client.js @@ -1,6 +1,6 @@ (function(window) { - var Gitana = window.Gitana; + Gitana = window.Gitana; Gitana.Client = Gitana.AbstractPlatformObject.extend( /** @lends Gitana.Client.prototype */ @@ -12,7 +12,7 @@ * @class Client * * @param {Gitana.Platform} platform - * @param [Object] object json object (if no callback required for populating) + * @param {Object} object json object (if no callback required for populating) */ constructor: function(platform, object) { @@ -86,7 +86,7 @@ */ listAuthenticationGrants: function(pagination) { - var params = {}; + const params = {}; if (pagination) { Gitana.copyInto(params, pagination); @@ -94,7 +94,7 @@ params.clientId = this.getId(); - var chainable = this.getFactory().authenticationGrantMap(this.getPlatform()); + const chainable = this.getFactory().authenticationGrantMap(this.getPlatform()); return this.chainGet(chainable, "/auth/grants", params); } diff --git a/js/gitana/platform/ClientMap.js b/js/gitana/platform/ClientMap.js index cc0f4aec..237a901c 100644 --- a/js/gitana/platform/ClientMap.js +++ b/js/gitana/platform/ClientMap.js @@ -1,6 +1,6 @@ (function(window) { - var Gitana = window.Gitana; + Gitana = window.Gitana; Gitana.ClientMap = Gitana.AbstractPlatformObjectMap.extend( /** @lends Gitana.ClientMap.prototype */ @@ -12,7 +12,7 @@ * @class Map of clients * * @param {Gitana.Platform} platform Gitana platform instance. - * @param [Object] object + * @param {Object} object */ constructor: function(platform, object) { diff --git a/js/gitana/platform/DeploymentPackage.js b/js/gitana/platform/DeploymentPackage.js index b739b1b5..3d8439db 100644 --- a/js/gitana/platform/DeploymentPackage.js +++ b/js/gitana/platform/DeploymentPackage.js @@ -1,6 +1,6 @@ (function(window) { - var Gitana = window.Gitana; + Gitana = window.Gitana; Gitana.DeploymentPackage = Gitana.AbstractPlatformObject.extend( /** @lends Gitana.DeploymentPackage.prototype */ @@ -12,7 +12,7 @@ * @class DeploymentPackage * * @param {Gitana.Platform} platform - * @param [Object] object json object (if no callback required for populating) + * @param {Object} object json object (if no callback required for populating) */ constructor: function(platform, object) { diff --git a/js/gitana/platform/DeploymentPackageMap.js b/js/gitana/platform/DeploymentPackageMap.js index d64f650e..c2ce8c06 100644 --- a/js/gitana/platform/DeploymentPackageMap.js +++ b/js/gitana/platform/DeploymentPackageMap.js @@ -1,6 +1,6 @@ (function(window) { - var Gitana = window.Gitana; + Gitana = window.Gitana; Gitana.DeploymentPackageMap = Gitana.AbstractPlatformObjectMap.extend( /** @lends Gitana.DeploymentPackageMap.prototype */ @@ -12,7 +12,7 @@ * @class Map of deployment packages * * @param {Gitana.Platform} platform Gitana platform instance. - * @param [Object] object + * @param {Object} object */ constructor: function(platform, object) { diff --git a/js/gitana/platform/DeploymentReceiver.js b/js/gitana/platform/DeploymentReceiver.js index ede2472b..b37e3574 100644 --- a/js/gitana/platform/DeploymentReceiver.js +++ b/js/gitana/platform/DeploymentReceiver.js @@ -1,6 +1,6 @@ (function(window) { - var Gitana = window.Gitana; + Gitana = window.Gitana; Gitana.DeploymentReceiver = Gitana.AbstractPlatformObject.extend( /** @lends Gitana.DeploymentReceiver.prototype */ @@ -12,7 +12,7 @@ * @class DeploymentReceiver * * @param {Gitana.Platform} platform - * @param [Object] object json object (if no callback required for populating) + * @param {Object} object json object (if no callback required for populating) */ constructor: function(platform, object) { diff --git a/js/gitana/platform/DeploymentReceiverMap.js b/js/gitana/platform/DeploymentReceiverMap.js index cd3fbc73..f4f4f677 100644 --- a/js/gitana/platform/DeploymentReceiverMap.js +++ b/js/gitana/platform/DeploymentReceiverMap.js @@ -1,6 +1,6 @@ (function(window) { - var Gitana = window.Gitana; + Gitana = window.Gitana; Gitana.DeploymentReceiverMap = Gitana.AbstractPlatformObjectMap.extend( /** @lends Gitana.DeploymentReceiverMap.prototype */ @@ -12,7 +12,7 @@ * @class Map of deployment receivers * * @param {Gitana.Platform} platform Gitana platform instance. - * @param [Object] object + * @param {Object} object */ constructor: function(platform, object) { diff --git a/js/gitana/platform/DeploymentStrategy.js b/js/gitana/platform/DeploymentStrategy.js index fb3f08de..78ee9db3 100644 --- a/js/gitana/platform/DeploymentStrategy.js +++ b/js/gitana/platform/DeploymentStrategy.js @@ -1,6 +1,6 @@ (function(window) { - var Gitana = window.Gitana; + Gitana = window.Gitana; Gitana.DeploymentStrategy = Gitana.AbstractPlatformObject.extend( /** @lends Gitana.DeploymentStrategy.prototype */ @@ -12,7 +12,7 @@ * @class DeploymentStrategy * * @param {Gitana.Platform} platform - * @param [Object] object json object (if no callback required for populating) + * @param {Object} object json object (if no callback required for populating) */ constructor: function(platform, object) { diff --git a/js/gitana/platform/DeploymentStrategyMap.js b/js/gitana/platform/DeploymentStrategyMap.js index 36abc3ff..7cc80805 100644 --- a/js/gitana/platform/DeploymentStrategyMap.js +++ b/js/gitana/platform/DeploymentStrategyMap.js @@ -1,6 +1,6 @@ (function(window) { - var Gitana = window.Gitana; + Gitana = window.Gitana; Gitana.DeploymentStrategyMap = Gitana.AbstractPlatformObjectMap.extend( /** @lends Gitana.DeploymentStrategyMap.prototype */ @@ -12,7 +12,7 @@ * @class Map of deployment strategies * * @param {Gitana.Platform} platform Gitana platform instance. - * @param [Object] object + * @param {Object} object */ constructor: function(platform, object) { diff --git a/js/gitana/platform/DeploymentTarget.js b/js/gitana/platform/DeploymentTarget.js index e45389fd..682f0646 100644 --- a/js/gitana/platform/DeploymentTarget.js +++ b/js/gitana/platform/DeploymentTarget.js @@ -1,6 +1,6 @@ (function(window) { - var Gitana = window.Gitana; + Gitana = window.Gitana; Gitana.DeploymentTarget = Gitana.AbstractPlatformObject.extend( /** @lends Gitana.DeploymentTarget.prototype */ @@ -12,7 +12,7 @@ * @class DeploymentTarget * * @param {Gitana.Platform} platform - * @param [Object] object json object (if no callback required for populating) + * @param {Object} object json object (if no callback required for populating) */ constructor: function(platform, object) { diff --git a/js/gitana/platform/DeploymentTargetMap.js b/js/gitana/platform/DeploymentTargetMap.js index a566f811..762c877e 100644 --- a/js/gitana/platform/DeploymentTargetMap.js +++ b/js/gitana/platform/DeploymentTargetMap.js @@ -1,6 +1,6 @@ (function(window) { - var Gitana = window.Gitana; + Gitana = window.Gitana; Gitana.DeploymentTargetMap = Gitana.AbstractPlatformObjectMap.extend( /** @lends Gitana.DeploymentTargetMap.prototype */ @@ -12,7 +12,7 @@ * @class Map of deployment targets * * @param {Gitana.Platform} platform Gitana platform instance. - * @param [Object] object + * @param {Object} object */ constructor: function(platform, object) { diff --git a/js/gitana/platform/Descriptor.js b/js/gitana/platform/Descriptor.js index c767e61d..5b64fd9b 100644 --- a/js/gitana/platform/Descriptor.js +++ b/js/gitana/platform/Descriptor.js @@ -1,6 +1,6 @@ (function(window) { - var Gitana = window.Gitana; + Gitana = window.Gitana; Gitana.Descriptor = Gitana.AbstractPlatformObject.extend( /** @lends Gitana.Descriptor.prototype */ @@ -12,7 +12,7 @@ * @class Descriptor * * @param {Gitana.Platform} platform - * @param [Object] object json object (if no callback required for populating) + * @param {Object} object json object (if no callback required for populating) */ constructor: function(platform, object) { @@ -48,14 +48,13 @@ /** * Tests whether the service works for this descriptor. * - * @param exportId - * @param emailConfig + * @param data * @param callback * @returns {*} */ test: function(data, callback) { - var self = this; + const self = this; if (typeof(data) === "function") { @@ -63,12 +62,12 @@ data = {}; } - var uriFunction = function() + const uriFunction = function() { return self.getUri() + "/test"; }; - var params = {}; + const params = {}; return this.chainPostResponse(this, uriFunction, params, data).then(function(response) { callback(response); diff --git a/js/gitana/platform/DescriptorMap.js b/js/gitana/platform/DescriptorMap.js index 717a440f..ec98b545 100644 --- a/js/gitana/platform/DescriptorMap.js +++ b/js/gitana/platform/DescriptorMap.js @@ -1,6 +1,6 @@ (function(window) { - var Gitana = window.Gitana; + Gitana = window.Gitana; Gitana.DescriptorMap = Gitana.AbstractPlatformObjectMap.extend( /** @lends Gitana.DescriptorMap.prototype */ @@ -12,7 +12,7 @@ * @class Map of descriptors * * @param {Gitana.Platform} platform Gitana platform instance. - * @param [Object] object + * @param {Object} object */ constructor: function(platform, object) { diff --git a/js/gitana/platform/Platform.js b/js/gitana/platform/Platform.js index ba9de884..3b31da58 100644 --- a/js/gitana/platform/Platform.js +++ b/js/gitana/platform/Platform.js @@ -1,6 +1,6 @@ (function(window) { - var Gitana = window.Gitana; + Gitana = window.Gitana; Gitana.Platform = Gitana.ContainedDataStore.extend( /** @lends Gitana.Platform.prototype */ @@ -12,7 +12,7 @@ * @class Platform * * @param {Gitana.Cluster} cluster - * @param [Object] object json object (if no callback required for populating) + * @param {Object} object json object (if no callback required for populating) */ constructor: function(cluster, object) { @@ -91,7 +91,7 @@ /** @Override **/ reload: function() { - var uriFunction = function() + const uriFunction = function() { return this.getUri() + "/"; }; @@ -102,7 +102,7 @@ /** @Override **/ update: function() { - var uriFunction = function() + const uriFunction = function() { return this.getUri() + "/"; }; @@ -117,14 +117,14 @@ */ readPrimaryDomain: function() { - var self = this; + const self = this; - var uriFunction = function() + const uriFunction = function() { return self.getUri() + "/domains/primary"; }; - var chainable = this.getFactory().domain(this); + const chainable = this.getFactory().domain(this); return this.chainGet(chainable, uriFunction); }, @@ -135,7 +135,7 @@ */ loadInfo: function(callback) { - var uriFunction = function() + const uriFunction = function() { return "/info"; }; @@ -158,18 +158,18 @@ * * @chained repository map * - * @param [Object] pagination pagination (optional) + * @param {Object} pagination pagination (optional) */ listRepositories: function(pagination) { // prepare params (with pagination) - var params = {}; + const params = {}; if (pagination) { Gitana.copyInto(params, pagination); } - var chainable = this.getFactory().repositoryMap(this); + const chainable = this.getFactory().repositoryMap(this); return this.chainGet(chainable, "/repositories", params); }, @@ -182,7 +182,7 @@ */ readRepository: function(repositoryId) { - var chainable = this.getFactory().repository(this); + const chainable = this.getFactory().repository(this); return this.chainGet(chainable, "/repositories/" + repositoryId); }, @@ -191,11 +191,11 @@ * * @chained repository * - * @param [Object] object JSON object + * @param {Object} object JSON object */ createRepository: function(object) { - var chainable = this.getFactory().repository(this); + const chainable = this.getFactory().repository(this); return this.chainCreate(chainable, object, "/repositories"); }, @@ -205,14 +205,14 @@ * @chained repository map * * @param {Object} query Query for finding a repository. - * @param [Object] pagination pagination (optional) + * @param {Object} pagination pagination (optional) */ queryRepositories: function(query, pagination) { - var chainable = this.getFactory().repositoryMap(this); + const chainable = this.getFactory().repositoryMap(this); // prepare params (with pagination) - var params = {}; + const params = {}; if (pagination) { Gitana.copyInto(params, pagination); @@ -250,12 +250,12 @@ */ checkRepositoryPermissions: function(checks, callback) { - var uriFunction = function() + const uriFunction = function() { return "/repositories/permissions/check"; }; - var object = { + const object = { "checks": checks }; @@ -293,12 +293,12 @@ */ checkRepositoryAuthorities: function(checks, callback) { - var uriFunction = function() + const uriFunction = function() { return "/repositories/authorities/check"; }; - var object = { + const object = { "checks": checks }; @@ -320,18 +320,18 @@ * * @chained domain map * - * @param [Object] pagination pagination (optional) + * @param {Object} pagination pagination (optional) */ listDomains: function(pagination) { // prepare params (with pagination) - var params = {}; + const params = {}; if (pagination) { Gitana.copyInto(params, pagination); } - var chainable = this.getFactory().domainMap(this); + const chainable = this.getFactory().domainMap(this); return this.chainGet(chainable, "/domains", params); }, @@ -344,7 +344,7 @@ */ readDomain: function(domainId) { - var chainable = this.getFactory().domain(this); + const chainable = this.getFactory().domain(this); return this.chainGet(chainable, "/domains/" + domainId); }, @@ -353,11 +353,11 @@ * * @chained domain * - * @param [Object] object JSON object + * @param {Object} object JSON object */ createDomain: function(object) { - var chainable = this.getFactory().domain(this); + const chainable = this.getFactory().domain(this); return this.chainCreate(chainable, object, "/domains"); }, @@ -367,14 +367,14 @@ * @chained domain map * * @param {Object} query Query for finding a domain. - * @param [Object] pagination pagination (optional) + * @param {Object} pagination pagination (optional) */ queryDomains: function(query, pagination) { - var chainable = this.getFactory().domainMap(this); + const chainable = this.getFactory().domainMap(this); // prepare params (with pagination) - var params = {}; + const params = {}; if (pagination) { Gitana.copyInto(params, pagination); @@ -410,12 +410,12 @@ */ checkDomainPermissions: function(checks, callback) { - var uriFunction = function() + const uriFunction = function() { return "/domains/permissions/check"; }; - var object = { + const object = { "checks": checks }; @@ -451,12 +451,12 @@ */ checkDomainAuthorities: function(checks, callback) { - var uriFunction = function() + const uriFunction = function() { return "/domains/authorities/check"; }; - var object = { + const object = { "checks": checks }; @@ -480,18 +480,18 @@ * * @chained vault map * - * @param [Object] pagination pagination (optional) + * @param {Object} pagination pagination (optional) */ listVaults: function(pagination) { // prepare params (with pagination) - var params = {}; + const params = {}; if (pagination) { Gitana.copyInto(params, pagination); } - var chainable = this.getFactory().vaultMap(this); + const chainable = this.getFactory().vaultMap(this); return this.chainGet(chainable, "/vaults", params); }, @@ -504,7 +504,7 @@ */ readVault: function(vaultId) { - var chainable = this.getFactory().vault(this); + const chainable = this.getFactory().vault(this); return this.chainGet(chainable, "/vaults/" + vaultId); }, @@ -513,11 +513,11 @@ * * @chained vault * - * @param [Object] object JSON object + * @param {Object} object JSON object */ createVault: function(object) { - var chainable = this.getFactory().vault(this); + const chainable = this.getFactory().vault(this); return this.chainCreate(chainable, object, "/vaults"); }, @@ -527,14 +527,14 @@ * @chained vault map * * @param {Object} query Query for finding a vault. - * @param [Object] pagination pagination (optional) + * @param {Object} pagination pagination (optional) */ queryVaults: function(query, pagination) { - var chainable = this.getFactory().vaultMap(this); + const chainable = this.getFactory().vaultMap(this); // prepare params (with pagination) - var params = {}; + const params = {}; if (pagination) { Gitana.copyInto(params, pagination); @@ -570,12 +570,12 @@ */ checkVaultPermissions: function(checks, callback) { - var uriFunction = function() + const uriFunction = function() { return "/vaults/permissions/check"; }; - var object = { + const object = { "checks": checks }; @@ -611,12 +611,12 @@ */ checkVaultAuthorities: function(checks, callback) { - var uriFunction = function() + const uriFunction = function() { return "/vaults/authorities/check"; }; - var object = { + const object = { "checks": checks }; @@ -639,7 +639,7 @@ * This delegates a call to the underlying driver. * * @param {Object} config login config - * @param [Function] authentication failure handler + * @param {Function} authFailureHandler failure handler */ authenticate: function(config, authFailureHandler) { @@ -657,11 +657,9 @@ */ logout: function(expireAccessToken) { - var self = this; - return this.subchain().then(function() { - var platformCacheKey = this.getDriver().platformCacheKey; + const platformCacheKey = this.getDriver().platformCacheKey; if (platformCacheKey) { Gitana.disconnect(platformCacheKey, expireAccessToken); @@ -690,13 +688,13 @@ */ listStacks: function(pagination) { - var params = {}; + const params = {}; if (pagination) { Gitana.copyInto(params, pagination); } - var chainable = this.getFactory().stackMap(this); + const chainable = this.getFactory().stackMap(this); return this.chainGet(chainable, "/stacks", params); }, @@ -709,7 +707,7 @@ */ readStack: function(stackId) { - var chainable = this.getFactory().stack(this); + const chainable = this.getFactory().stack(this); return this.chainGet(chainable, "/stacks/" + stackId); }, @@ -718,7 +716,7 @@ * * @chained stack * - * @param [Object] object JSON object + * @param {Object} object JSON object */ createStack: function(object) { @@ -727,7 +725,7 @@ object = {}; } - var chainable = this.getFactory().stack(this); + const chainable = this.getFactory().stack(this); return this.chainCreate(chainable, object, "/stacks"); }, @@ -737,22 +735,22 @@ * @chained stack map * * @param {Object} query - * @param [Object] pagination pagination (optional) + * @param {Object} pagination pagination (optional) */ queryStacks: function(query, pagination) { - var params = {}; + const params = {}; if (pagination) { Gitana.copyInto(params, pagination); } - var uriFunction = function() + const uriFunction = function() { return "/stacks/query"; }; - var chainable = this.getFactory().stackMap(this); + const chainable = this.getFactory().stackMap(this); return this.chainPost(chainable, uriFunction, params, query); }, @@ -766,7 +764,7 @@ */ findStackForDataStore: function(datastoreType, datastoreId) { - var chainable = this.getFactory().stack(this); + const chainable = this.getFactory().stack(this); return this.chainGet(chainable, "/stacks/find/" + datastoreType + "/" + datastoreId); }, @@ -798,12 +796,12 @@ */ checkStackPermissions: function(checks, callback) { - var uriFunction = function() + const uriFunction = function() { return "/stacks/permissions/check"; }; - var object = { + const object = { "checks": checks }; @@ -839,12 +837,12 @@ */ checkStackAuthorities: function(checks, callback) { - var uriFunction = function() + const uriFunction = function() { return "/stacks/authorities/check"; }; - var object = { + const object = { "checks": checks }; @@ -872,13 +870,13 @@ */ listProjects: function(pagination) { - var params = {}; + const params = {}; if (pagination) { Gitana.copyInto(params, pagination); } - var chainable = this.getFactory().projectMap(this); + const chainable = this.getFactory().projectMap(this); return this.chainGet(chainable, "/projects", params); }, @@ -891,7 +889,7 @@ */ readProject: function(projectId) { - var chainable = this.getFactory().project(this); + const chainable = this.getFactory().project(this); return this.chainGet(chainable, "/projects/" + projectId); }, @@ -900,7 +898,7 @@ * * @chained project * - * @param [Object] object JSON object + * @param {Object} object JSON object */ createProject: function(object) { @@ -909,7 +907,7 @@ object = {}; } - var chainable = this.getFactory().project(this); + const chainable = this.getFactory().project(this); return this.chainCreate(chainable, object, "/projects"); }, @@ -919,12 +917,13 @@ * * @chained project * - * @param [Object] object JSON object - * @param [Object] params request parameters + * @param {Object} object JSON object + * @param {Object} params request parameters + * @param callback */ startCreateProject: function(object, params, callback) { - var uriFunction = function() + const uriFunction = function() { return "/projects/start"; }; @@ -941,7 +940,7 @@ return this.chainPostResponse(this, uriFunction, params, object).then(function(response) { - var jobId = response._doc; + const jobId = response._doc; callback(jobId); }); @@ -953,22 +952,22 @@ * @chained project map * * @param {Object} query - * @param [Object] pagination pagination (optional) + * @param {Object} pagination pagination (optional) */ queryProjects: function(query, pagination) { - var params = {}; + const params = {}; if (pagination) { Gitana.copyInto(params, pagination); } - var uriFunction = function() + const uriFunction = function() { return "/projects/query"; }; - var chainable = this.getFactory().projectMap(this); + const chainable = this.getFactory().projectMap(this); return this.chainPost(chainable, uriFunction, params, query); }, @@ -999,12 +998,12 @@ */ checkProjectPermissions: function(checks, callback) { - var uriFunction = function() + const uriFunction = function() { return "/projects/permissions/check"; }; - var object = { + const object = { "checks": checks }; @@ -1040,12 +1039,12 @@ */ checkProjectAuthorities: function(checks, callback) { - var uriFunction = function() + const uriFunction = function() { return "/projects/authorities/check"; }; - var object = { + const object = { "checks": checks }; @@ -1065,18 +1064,18 @@ * * @chained project type map * - * @param [Object] pagination pagination (optional) + * @param {Object} pagination pagination (optional) */ listProjectTypes: function(pagination) { // prepare params (with pagination) - var params = {}; + const params = {}; if (pagination) { Gitana.copyInto(params, pagination); } - var chainable = this.getFactory().projectMap(this); + const chainable = this.getFactory().projectMap(this); return this.chainGet(chainable, "/projecttypes", params); }, @@ -1096,13 +1095,13 @@ * @chained log entry map * * @param {Object} query Query for finding log entries. - * @param [Object] pagination pagination (optional) + * @param {Object} pagination pagination (optional) */ queryLogEntries: function(query, pagination) { - var self = this; + const self = this; - var uriFunction = function() + const uriFunction = function() { return self.getUri() + "/logs/query"; }; @@ -1112,10 +1111,10 @@ query = {}; } - var chainable = this.getFactory().logEntryMap(this.getCluster()); + const chainable = this.getFactory().logEntryMap(this.getCluster()); // prepare params (with pagination) - var params = {}; + const params = {}; if (pagination) { Gitana.copyInto(params, pagination); @@ -1133,14 +1132,14 @@ */ readLogEntry: function(logEntryId) { - var self = this; + const self = this; - var uriFunction = function() + const uriFunction = function() { return self.getUri() + "/logs/" + logEntryId; }; - var chainable = this.getFactory().logEntry(this.getCluster()); + const chainable = this.getFactory().logEntry(this.getCluster()); return this.chainGet(chainable, uriFunction); }, @@ -1153,9 +1152,7 @@ */ readLog: function(callback) { - var self = this; - - var uriFunction = function () { + const uriFunction = function () { return "/logs/logfile"; }; @@ -1173,12 +1170,6 @@ */ createLogEntry: function(message, level, obj) { - var self = this; - - var uriFunction = function() - { - return self.getUri() + "/logs"; - }; if (!obj) { obj = {}; @@ -1186,7 +1177,7 @@ obj.message = message; obj.level = level; - var chainable = this.getFactory().logEntry(this.getCluster()); + const chainable = this.getFactory().logEntry(this.getCluster()); return this.chainCreate(chainable, obj, "/logs"); }, @@ -1199,9 +1190,9 @@ */ postLogEntry: function(message, level, obj) { - var self = this; + const self = this; - var uriFunction = function() + const uriFunction = function() { return self.getUri() + "/logs"; }; @@ -1227,18 +1218,18 @@ * * @chained registrar map * - * @param [Object] pagination pagination (optional) + * @param {Object} pagination pagination (optional) */ listRegistrars: function(pagination) { // prepare params (with pagination) - var params = {}; + const params = {}; if (pagination) { Gitana.copyInto(params, pagination); } - var chainable = this.getFactory().registrarMap(this); + const chainable = this.getFactory().registrarMap(this); return this.chainGet(chainable, "/registrars", params); }, @@ -1251,7 +1242,7 @@ */ readRegistrar: function(registrarId) { - var chainable = this.getFactory().registrar(this); + const chainable = this.getFactory().registrar(this); return this.chainGet(chainable, "/registrars/" + registrarId); }, @@ -1260,11 +1251,11 @@ * * @chained registrar * - * @param [Object] object JSON object + * @param {Object} object JSON object */ createRegistrar: function(object) { - var chainable = this.getFactory().registrar(this); + const chainable = this.getFactory().registrar(this); return this.chainCreate(chainable, object, "/registrars"); }, @@ -1274,14 +1265,14 @@ * @chained registrar map * * @param {Object} query Query for finding a vault. - * @param [Object] pagination pagination (optional) + * @param {Object} pagination pagination (optional) */ queryRegistrars: function(query, pagination) { - var chainable = this.getFactory().registrarMap(this); + const chainable = this.getFactory().registrarMap(this); // prepare params (with pagination) - var params = {}; + const params = {}; if (pagination) { Gitana.copyInto(params, pagination); @@ -1317,12 +1308,12 @@ */ checkRegistrarPermissions: function(checks, callback) { - var uriFunction = function() + const uriFunction = function() { return "/registrars/permissions/check"; }; - var object = { + const object = { "checks": checks }; @@ -1358,12 +1349,12 @@ */ checkRegistrarAuthorities: function(checks, callback) { - var uriFunction = function() + const uriFunction = function() { return "/registrars/authorities/check"; }; - var object = { + const object = { "checks": checks }; @@ -1385,18 +1376,18 @@ * * @chained application map * - * @param [Object] pagination pagination (optional) + * @param {Object} pagination pagination (optional) */ listApplications: function(pagination) { // prepare params (with pagination) - var params = {}; + const params = {}; if (pagination) { Gitana.copyInto(params, pagination); } - var chainable = this.getFactory().applicationMap(this); + const chainable = this.getFactory().applicationMap(this); return this.chainGet(chainable, "/applications", params); }, @@ -1409,11 +1400,11 @@ */ readApplication: function(applicationId) { - var uriFunction = function() { + const uriFunction = function() { return "/applications/" + applicationId; }; - var chainable = this.getFactory().application(this); + const chainable = this.getFactory().application(this); return this.chainGet(chainable, uriFunction); }, @@ -1422,11 +1413,11 @@ * * @chained application * - * @param [Object] object JSON object + * @param {Object} object JSON object */ createApplication: function(object) { - var chainable = this.getFactory().application(this); + const chainable = this.getFactory().application(this); return this.chainCreate(chainable, object, "/applications"); }, @@ -1436,14 +1427,14 @@ * @chained application map * * @param {Object} query Query for finding a vault. - * @param [Object] pagination pagination (optional) + * @param {Object} pagination pagination (optional) */ queryApplications: function(query, pagination) { - var chainable = this.getFactory().applicationMap(this); + const chainable = this.getFactory().applicationMap(this); // prepare params (with pagination) - var params = {}; + const params = {}; if (pagination) { Gitana.copyInto(params, pagination); @@ -1479,12 +1470,12 @@ */ checkApplicationPermissions: function(checks, callback) { - var uriFunction = function() + const uriFunction = function() { return "/applications/permissions/check"; }; - var object = { + const object = { "checks": checks }; @@ -1520,12 +1511,12 @@ */ checkApplicationAuthorities: function(checks, callback) { - var uriFunction = function() + const uriFunction = function() { return "/applications/authorities/check"; }; - var object = { + const object = { "checks": checks }; @@ -1545,18 +1536,18 @@ * * @chained application type map * - * @param [Object] pagination pagination (optional) + * @param {Object} pagination pagination (optional) */ listApplicationTypes: function(pagination) { // prepare params (with pagination) - var params = {}; + const params = {}; if (pagination) { Gitana.copyInto(params, pagination); } - var chainable = this.getFactory().applicationMap(this); + const chainable = this.getFactory().applicationMap(this); return this.chainGet(chainable, "/applicationtypes", params); }, @@ -1578,13 +1569,13 @@ */ listClients: function(pagination) { - var params = {}; + const params = {}; if (pagination) { Gitana.copyInto(params, pagination); } - var chainable = this.getFactory().clientMap(this); + const chainable = this.getFactory().clientMap(this); return this.chainGet(chainable, "/clients", params); }, @@ -1597,7 +1588,7 @@ */ readClient: function(clientId) { - var chainable = this.getFactory().client(this); + const chainable = this.getFactory().client(this); return this.chainGet(chainable, "/clients/" + clientId); }, @@ -1606,7 +1597,7 @@ * * @chained client * - * @param [Object] object JSON object + * @param {Object} object JSON object */ createClient: function(object) { @@ -1615,7 +1606,7 @@ object = {}; } - var chainable = this.getFactory().client(this); + const chainable = this.getFactory().client(this); return this.chainCreate(chainable, object, "/clients"); }, @@ -1625,22 +1616,22 @@ * @chained client map * * @param {Object} query - * @param [Object] pagination pagination (optional) + * @param {Object} pagination pagination (optional) */ queryClients: function(query, pagination) { - var params = {}; + const params = {}; if (pagination) { Gitana.copyInto(params, pagination); } - var uriFunction = function() + const uriFunction = function() { return "/clients/query"; }; - var chainable = this.getFactory().clientMap(this); + const chainable = this.getFactory().clientMap(this); return this.chainPost(chainable, uriFunction, params, query); }, @@ -1671,12 +1662,12 @@ */ checkClientPermissions: function(checks, callback) { - var uriFunction = function() + const uriFunction = function() { return "/clients/permissions/check"; }; - var object = { + const object = { "checks": checks }; @@ -1712,12 +1703,12 @@ */ checkClientAuthorities: function(checks, callback) { - var uriFunction = function() + const uriFunction = function() { return "/clients/authorities/check"; }; - var object = { + const object = { "checks": checks }; @@ -1741,7 +1732,7 @@ */ readAccessPolicy: function(accessPolicyId) { - var chainable = this.getFactory().accessPolicy(this); + const chainable = this.getFactory().accessPolicy(this); return this.chainGet(chainable, "/access/policies/" + accessPolicyId); }, @@ -1759,7 +1750,7 @@ object = {}; } - var chainable = this.getFactory().accessPolicy(this); + const chainable = this.getFactory().accessPolicy(this); return this.chainCreate(chainable, object, "/access/policies"); }, @@ -1772,7 +1763,7 @@ */ listAccessPolicies: function(pagination) { - var params = {}; + const params = {}; if (pagination) { Gitana.copyInto(params, pagination); @@ -1780,7 +1771,7 @@ params.clientId = this.getId(); - var chainable = this.getFactory().accessPolicyMap(this.getPlatform()); + const chainable = this.getFactory().accessPolicyMap(this.getPlatform()); return this.chainGet(chainable, "/access/policies", params); }, @@ -1794,13 +1785,13 @@ */ queryAccessPolicies: function(query, pagination) { - var params = {}; + const params = {}; if (pagination) { Gitana.copyInto(params, pagination); } - var chainable = this.getFactory().accessPolicyMap(this.getPlatform()); + const chainable = this.getFactory().accessPolicyMap(this.getPlatform()); return this.chainPost(chainable, "/access/policies/query", params, query); }, @@ -1814,7 +1805,7 @@ */ findAccessPolicies: function(ref, pagination) { - var params = {}; + const params = {}; params.ref = ref; if (pagination) @@ -1822,7 +1813,7 @@ Gitana.copyInto(params, pagination); } - var chainable = this.getFactory().accessPolicyMap(this.getPlatform()); + const chainable = this.getFactory().accessPolicyMap(this.getPlatform()); return this.chainPost(chainable, "/access/policies/find", params); }, @@ -1834,7 +1825,7 @@ */ listAccessPolicyTargets: function(accessPolicyId, pagination) { - var params = {}; + const params = {}; params.accessPolicyId = accessPolicyId; if (pagination) @@ -1842,9 +1833,9 @@ Gitana.copyInto(params, pagination); } - var uri = "/access/policies/" + accessPolicyId + "/targets"; + const uri = "/access/policies/" + accessPolicyId + "/targets"; - var chainable = this.getFactory().accessPolicyMap(this.getPlatform()); + const chainable = this.getFactory().accessPolicyMap(this.getPlatform()); return this.chainGet(chainable, uri, params); }, @@ -1856,12 +1847,12 @@ */ assignAccessPolicy: function(accessPolicyId, ref) { - var params = {}; + const params = {}; params.ref = ref; - var uri = "/access/policies/" + accessPolicyId + "/assign"; + const uri = "/access/policies/" + accessPolicyId + "/assign"; - var chainable = this.getFactory().accessPolicyMap(this.getPlatform()); + const chainable = this.getFactory().accessPolicyMap(this.getPlatform()); return this.chainPost(chainable, uri, params); }, @@ -1873,12 +1864,12 @@ */ unassignAccessPolicy: function(accessPolicyId, ref) { - var params = {}; + const params = {}; params.ref = ref; - var uri = "/access/policies/" + accessPolicyId + "/unassign"; + const uri = "/access/policies/" + accessPolicyId + "/unassign"; - var chainable = this.getFactory().accessPolicyMap(this.getPlatform()); + const chainable = this.getFactory().accessPolicyMap(this.getPlatform()); return this.chainPost(chainable, uri, params); }, @@ -1889,10 +1880,10 @@ */ unassignAllAccessPolicies: function(ref) { - var params = {}; + const params = {}; params.ref = ref; - var chainable = this.getFactory().accessPolicyMap(this.getPlatform()); + const chainable = this.getFactory().accessPolicyMap(this.getPlatform()); return this.chainPost(chainable, "/access/policies/unassignall", params); }, @@ -1911,7 +1902,7 @@ */ readAuthenticationGrant: function(authenticationGrantId) { - var chainable = this.getFactory().authenticationGrant(this); + const chainable = this.getFactory().authenticationGrant(this); return this.chainGet(chainable, "/auth/grants/" + authenticationGrantId); }, @@ -1920,7 +1911,7 @@ * * @chained authentication grant * - * @param [Object] object JSON object + * @param {Object} object JSON object */ createAuthenticationGrant: function(object) { @@ -1929,7 +1920,7 @@ object = {}; } - var chainable = this.getFactory().authenticationGrant(this); + const chainable = this.getFactory().authenticationGrant(this); return this.chainCreate(chainable, object, "/auth/grants"); }, @@ -1939,22 +1930,22 @@ * @chained authentication grant map * * @param {Object} query - * @param [Object] pagination pagination (optional) + * @param {Object} pagination pagination (optional) */ queryAuthenticationGrants: function(query, pagination) { - var params = {}; + const params = {}; if (pagination) { Gitana.copyInto(params, pagination); } - var uriFunction = function() + const uriFunction = function() { return "/auth/grants/query"; }; - var chainable = this.getFactory().authenticationGrantMap(this); + const chainable = this.getFactory().authenticationGrantMap(this); return this.chainPost(chainable, uriFunction, params, query); }, @@ -1985,12 +1976,12 @@ */ checkAuthenticationGrantPermissions: function(checks, callback) { - var uriFunction = function() + const uriFunction = function() { return "/auth/grants/permissions/check"; }; - var object = { + const object = { "checks": checks }; @@ -2026,12 +2017,12 @@ */ checkAuthenticationGrantAuthorities: function(checks, callback) { - var uriFunction = function() + const uriFunction = function() { return "/auth/grants/authorities/check"; }; - var object = { + const object = { "checks": checks }; @@ -2053,18 +2044,18 @@ * * @chained directory map * - * @param [Object] pagination pagination (optional) + * @param {Object} pagination pagination (optional) */ listDirectories: function(pagination) { // prepare params (with pagination) - var params = {}; + const params = {}; if (pagination) { Gitana.copyInto(params, pagination); } - var chainable = this.getFactory().directoryMap(this); + const chainable = this.getFactory().directoryMap(this); return this.chainGet(chainable, "/directories", params); }, @@ -2077,7 +2068,7 @@ */ readDirectory: function(directoryId) { - var chainable = this.getFactory().directory(this); + const chainable = this.getFactory().directory(this); return this.chainGet(chainable, "/directories/" + directoryId); }, @@ -2086,11 +2077,11 @@ * * @chained directory * - * @param [Object] object JSON object + * @param {Object} object JSON object */ createDirectory: function(object) { - var chainable = this.getFactory().directory(this); + const chainable = this.getFactory().directory(this); return this.chainCreate(chainable, object, "/directories"); }, @@ -2100,14 +2091,14 @@ * @chained directory map * * @param {Object} query Query for finding a directory. - * @param [Object] pagination pagination (optional) + * @param {Object} pagination pagination (optional) */ queryDirectories: function(query, pagination) { - var chainable = this.getFactory().directoryMap(this); + const chainable = this.getFactory().directoryMap(this); // prepare params (with pagination) - var params = {}; + const params = {}; if (pagination) { Gitana.copyInto(params, pagination); @@ -2143,12 +2134,12 @@ */ checkDirectoryPermissions: function(checks, callback) { - var uriFunction = function() + const uriFunction = function() { return "/directories/permissions/check"; }; - var object = { + const object = { "checks": checks }; @@ -2184,12 +2175,12 @@ */ checkDirectoryAuthorities: function(checks, callback) { - var uriFunction = function() + const uriFunction = function() { return "/directories/authorities/check"; }; - var object = { + const object = { "checks": checks }; @@ -2216,13 +2207,13 @@ */ listBillingProviderConfigurations: function(pagination) { - var params = {}; + const params = {}; if (pagination) { Gitana.copyInto(params, pagination); } - var chainable = this.getFactory().billingProviderConfigurationMap(this); + const chainable = this.getFactory().billingProviderConfigurationMap(this); return this.chainGet(chainable, "/billing/configurations", params); }, @@ -2235,7 +2226,7 @@ */ readBillingProviderConfiguration: function(billingProviderConfigurationId) { - var chainable = this.getFactory().billingProviderConfiguration(this); + const chainable = this.getFactory().billingProviderConfiguration(this); return this.chainGet(chainable, "/billing/configurations/" + billingProviderConfigurationId); }, @@ -2245,7 +2236,7 @@ * @chained billing provider configuration * * @param {String} providerId - * @param [Object] object JSON object + * @param {Object} object JSON object */ createBillingProviderConfiguration: function(providerId, object) { @@ -2255,7 +2246,7 @@ } object["providerId"] = providerId; - var chainable = this.getFactory().billingProviderConfiguration(this); + const chainable = this.getFactory().billingProviderConfiguration(this); return this.chainCreate(chainable, object, "/billing/configurations"); }, @@ -2265,22 +2256,22 @@ * @chained billing provider configuration map * * @param {Object} query - * @param [Object] pagination pagination (optional) + * @param {Object} pagination pagination (optional) */ queryBillingProviderConfigurations: function(query, pagination) { - var params = {}; + const params = {}; if (pagination) { Gitana.copyInto(params, pagination); } - var uriFunction = function() + const uriFunction = function() { return "/billing/configurations/query"; }; - var chainable = this.getFactory().billingProviderConfigurationMap(this); + const chainable = this.getFactory().billingProviderConfigurationMap(this); return this.chainPost(chainable, uriFunction, params, query); }, @@ -2311,12 +2302,12 @@ */ checkBillingProviderConfigurationPermissions: function(checks, callback) { - var uriFunction = function() + const uriFunction = function() { return "/billing/configurations/permissions/check"; }; - var object = { + const object = { "checks": checks }; @@ -2352,12 +2343,12 @@ */ checkBillingProviderConfigurationAuthorities: function(checks, callback) { - var uriFunction = function() + const uriFunction = function() { return "/billing/configurations/authorities/check"; }; - var object = { + const object = { "checks": checks }; @@ -2378,18 +2369,18 @@ * * @chained web host map * - * @param [Object] pagination pagination (optional) + * @param {Object} pagination pagination (optional) */ listWebHosts: function(pagination) { // prepare params (with pagination) - var params = {}; + const params = {}; if (pagination) { Gitana.copyInto(params, pagination); } - var chainable = this.getFactory().webhostMap(this); + const chainable = this.getFactory().webhostMap(this); return this.chainGet(chainable, "/webhosts", params); }, @@ -2402,7 +2393,7 @@ */ readWebHost: function(webhostId) { - var chainable = this.getFactory().webhost(this); + const chainable = this.getFactory().webhost(this); return this.chainGet(chainable, "/webhosts/" + webhostId); }, @@ -2411,11 +2402,11 @@ * * @chained web host * - * @param [Object] object JSON object + * @param {Object} object JSON object */ createWebHost: function(object) { - var chainable = this.getFactory().webhost(this); + const chainable = this.getFactory().webhost(this); return this.chainCreate(chainable, object, "/webhosts"); }, @@ -2425,14 +2416,14 @@ * @chained web host map * * @param {Object} query Query for finding web hosts. - * @param [Object] pagination pagination (optional) + * @param {Object} pagination pagination (optional) */ queryWebHosts: function(query, pagination) { - var chainable = this.getFactory().webhostMap(this); + const chainable = this.getFactory().webhostMap(this); // prepare params (with pagination) - var params = {}; + const params = {}; if (pagination) { Gitana.copyInto(params, pagination); @@ -2468,12 +2459,12 @@ */ checkWebHostPermissions: function(checks, callback) { - var uriFunction = function() + const uriFunction = function() { return "/webhosts/permissions/check"; }; - var object = { + const object = { "checks": checks }; @@ -2509,12 +2500,12 @@ */ checkWebHostAuthorities: function(checks, callback) { - var uriFunction = function() + const uriFunction = function() { return "/webhosts/authorities/check"; }; - var object = { + const object = { "checks": checks }; @@ -2540,19 +2531,19 @@ */ listTenantAttachments: function() { - var self = this; + const self = this; // we bind the attachment map to a modified copy of platform with the URI adjusted // so that it forms "/tenant/attachments/" for any lookups - var pseudoTenant = this.clone(); + const pseudoTenant = this.clone(); pseudoTenant.getUri = function () { return "/tenant"; }; - var result = this.subchain(new Gitana.BinaryAttachmentMap(pseudoTenant)); + const result = this.subchain(new Gitana.BinaryAttachmentMap(pseudoTenant)); result.then(function() { - var chain = this; + const chain = this; self.getDriver().gitanaGet(self.getUri() + "/tenant/attachments", null, {}, function(response) { chain.handleResponse(response); @@ -2591,21 +2582,21 @@ */ tenantAttach: function(attachmentId, contentType, data) { - var self = this; + const self = this; - var tenant = this.clone(); + const tenant = this.clone(); tenant.getUri = function () { return "/tenant"; }; // the thing we're handing back - var result = this.subchain(new Gitana.BinaryAttachment(tenant)); + const result = this.subchain(new Gitana.BinaryAttachment(tenant)); // preload some work onto a subchain result.subchain().then(function() { // upload the attachment - var uploadUri = self.getUri() + "/tenant/attachments/" + attachmentId; + const uploadUri = self.getUri() + "/tenant/attachments/" + attachmentId; this.chainUpload(this, uploadUri, null, contentType, data).then(function() { // read back attachment information and plug onto result @@ -2652,7 +2643,7 @@ */ app: function(settings, callback) { - var self = this; + const self = this; // support for null appkey if (Gitana.isFunction(settings)) { @@ -2665,7 +2656,7 @@ } // build preload config - var config = { + const config = { "application": null, "appCacheKey": null }; @@ -2674,7 +2665,7 @@ Gitana.copyKeepers(config, settings); // is this app context already cached? - var cacheKey = config.appCacheKey; + const cacheKey = config.appCacheKey; if (cacheKey) { if (Gitana.APPS && Gitana.APPS[cacheKey]) @@ -2689,7 +2680,7 @@ } // load and cache - var helper = new Gitana.AppHelper(self, config); + const helper = new Gitana.AppHelper(self, config); if (!Gitana.APPS) { Gitana.APPS = {}; } @@ -2734,17 +2725,17 @@ * * The order of elements in the array will be the same for checks and results. * - * @param checks + * @param entries * @param callback */ accessLookups: function(entries, callback) { - var uriFunction = function() + const uriFunction = function() { return "/access/lookup"; }; - var object = { + const object = { "entries": entries }; @@ -2774,17 +2765,17 @@ * * The order of elements in the array will be the same for checks and results. * - * @param checks + * @param entries * @param callback */ accessChecks: function(entries, callback) { - var uriFunction = function() + const uriFunction = function() { return "/access/check"; }; - var object = { + const object = { "entries": entries }; @@ -2811,17 +2802,17 @@ * * The order of elements in the array will be the same for checks and results. * - * @param checks + * @param entries * @param callback */ referenceReads: function(entries, callback) { - var uriFunction = function() + const uriFunction = function() { return "/ref/read"; }; - var object = { + const object = { "entries": entries }; @@ -2840,12 +2831,12 @@ */ referenceDiff: function(sourceRef, targetRef, callback) { - var uriFunction = function() + const uriFunction = function() { return "/ref/diff"; }; - var params = { + const params = { "source": sourceRef, "target": targetRef }; @@ -2865,12 +2856,12 @@ */ referenceMerge: function(sourceRef, diffObject, callback) { - var uriFunction = function() + const uriFunction = function() { return "/ref/merge"; }; - var params = { + const params = { "source": sourceRef }; @@ -2887,15 +2878,15 @@ adminIndexDatastores: function() { - var self = this; + const self = this; return this.then(function() { - var chain = this; + const chain = this; // call - var uri = self.getUri() + "/admin/index"; - self.getDriver().gitanaPost(uri, null, {}, function(response) { + const uri = self.getUri() + "/admin/index"; + self.getDriver().gitanaPost(uri, null, {}, function() { chain.next(); }); @@ -2906,15 +2897,15 @@ adminRepair: function() { - var self = this; + const self = this; return this.then(function() { - var chain = this; + const chain = this; // call - var uri = self.getUri() + "/admin/repair"; - self.getDriver().gitanaPost(uri, null, {}, function(response) { + const uri = self.getUri() + "/admin/repair"; + self.getDriver().gitanaPost(uri, null, {}, function() { chain.next(); }); @@ -2935,17 +2926,18 @@ * * @param pagination * + * @param callback * @chained action descriptor map */ listRuleActions: function(pagination, callback) { - var params = {}; + const params = {}; if (pagination) { Gitana.copyInto(params, pagination); } - var uriFunction = function() + const uriFunction = function() { return "/rule/actions"; }; @@ -2958,13 +2950,14 @@ /** * Reads a rule action. * - * @param actioqnId * * @chained a + * @param actionId + * @param callback */ readRuleAction: function(actionId, callback) { - var uriFunction = function() + const uriFunction = function() { return "/rule/actions/" + actionId; }; @@ -2979,17 +2972,18 @@ * * @param pagination * + * @param callback * @chained condition descriptor map */ listRuleConditions: function(pagination, callback) { - var params = {}; + const params = {}; if (pagination) { Gitana.copyInto(params, pagination); } - var uriFunction = function() + const uriFunction = function() { return "/rule/conditions"; }; @@ -3004,11 +2998,12 @@ * * @param conditionId * + * @param callback * @chained a */ readRuleCondition: function(conditionId, callback) { - var uriFunction = function() + const uriFunction = function() { return "/rule/conditions/" + conditionId; }; @@ -3035,13 +3030,13 @@ */ listWorkflowModels: function(pagination) { - var params = {}; + const params = {}; if (pagination) { Gitana.copyInto(params, pagination); } - var chainable = this.getFactory().workflowModelMap(this); + const chainable = this.getFactory().workflowModelMap(this); return this.chainGet(chainable, "/workflow/models", params); }, @@ -3054,13 +3049,13 @@ */ listAllWorkflowModels: function(pagination) { - var params = {}; + const params = {}; if (pagination) { Gitana.copyInto(params, pagination); } - var chainable = this.getFactory().workflowModelMap(this); + const chainable = this.getFactory().workflowModelMap(this); return this.chainGet(chainable, "/workflow/models?all=true", params); }, @@ -3068,15 +3063,15 @@ * Reads a workflow model. * * @param {String} workflowModelId - * @param [String] workflowModelVersionId + * @param {String} workflowModelVersionId * * @chained workflowModel */ readWorkflowModel: function(workflowModelId, workflowModelVersionId) { - var uriFunction = function() + const uriFunction = function() { - var url = "/workflow/models/" + workflowModelId; + let url = "/workflow/models/" + workflowModelId; if (workflowModelVersionId) { url += "/versions/" + workflowModelVersionId; @@ -3085,7 +3080,7 @@ return url; }; - var chainable = this.getFactory().workflowModel(this); + const chainable = this.getFactory().workflowModel(this); return this.chainGet(chainable, uriFunction); }, @@ -3095,7 +3090,7 @@ * @chained workflow model * * @param {String} id - * @param [Object] object JSON object + * @param {Object} object JSON object */ createWorkflowModel: function(id, object) { @@ -3106,7 +3101,7 @@ object.id = id; - var chainable = this.getFactory().workflowModel(this); + const chainable = this.getFactory().workflowModel(this); return this.chainCreate(chainable, object, "/workflow/models"); }, @@ -3116,22 +3111,22 @@ * @chained workflow model map * * @param {Object} query - * @param [Object] pagination pagination (optional) + * @param {Object} pagination pagination (optional) */ queryWorkflowModels: function(query, pagination) { - var params = {}; + const params = {}; if (pagination) { Gitana.copyInto(params, pagination); } - var uriFunction = function() + const uriFunction = function() { return "/workflow/models/query"; }; - var chainable = this.getFactory().workflowModelMap(this); + const chainable = this.getFactory().workflowModelMap(this); return this.chainPost(chainable, uriFunction, params, query); }, @@ -3141,22 +3136,22 @@ * @chained workflow model map * * @param {Object} query - * @param [Object] pagination pagination (optional) + * @param {Object} pagination pagination (optional) */ queryAllWorkflowModels: function(query, pagination) { - var params = {}; + const params = {}; if (pagination) { Gitana.copyInto(params, pagination); } - var uriFunction = function() + const uriFunction = function() { return "/workflow/models/query?all=true"; }; - var chainable = this.getFactory().workflowModelMap(this); + const chainable = this.getFactory().workflowModelMap(this); return this.chainPost(chainable, uriFunction, params, query); }, @@ -3187,12 +3182,12 @@ */ checkWorkflowModelPermissions: function(checks, callback) { - var uriFunction = function() + const uriFunction = function() { return "/workflow/models/permissions/check"; }; - var object = { + const object = { "checks": checks }; @@ -3228,12 +3223,12 @@ */ checkWorkflowModelAuthorities: function(checks, callback) { - var uriFunction = function() + const uriFunction = function() { return "/workflow/models/authorities/check"; }; - var object = { + const object = { "checks": checks }; @@ -3252,20 +3247,18 @@ */ listWorkflowModelVersions: function(id, pagination) { - var params = {}; + const params = {}; if (pagination) { Gitana.copyInto(params, pagination); } - var uriFunction = function() + const uriFunction = function() { - var self = this; - return "/workflow/models/" + id + "/versions"; }; - var chainable = this.getFactory().workflowModelMap(this); + const chainable = this.getFactory().workflowModelMap(this); return this.chainGet(chainable, uriFunction, params); }, @@ -3276,24 +3269,23 @@ * * @param {String} id * @param {Object} query - * @param [Object] pagination pagination (optional) + * @param {Object} pagination pagination (optional) */ queryWorkflowModelVersions: function(id, query, pagination) { - var params = {}; + const params = {}; if (pagination) { Gitana.copyInto(params, pagination); } - var uriFunction = function() + const uriFunction = function() { - var self = this; return "/workflow/models/" + id + "/versions/query"; }; - var chainable = this.getFactory().workflowModelMap(this); + const chainable = this.getFactory().workflowModelMap(this); return this.chainPost(chainable, uriFunction, params, query); }, @@ -3313,13 +3305,13 @@ */ listWorkflows: function(pagination) { - var params = {}; + const params = {}; if (pagination) { Gitana.copyInto(params, pagination); } - var chainable = this.getFactory().workflowInstanceMap(this); + const chainable = this.getFactory().workflowInstanceMap(this); return this.chainGet(chainable, "/workflow/instances", params); }, @@ -3332,7 +3324,7 @@ */ readWorkflow: function(workflowId) { - var chainable = this.getFactory().workflowInstance(this); + const chainable = this.getFactory().workflowInstance(this); return this.chainGet(chainable, "/workflow/instances/" + workflowId); }, @@ -3342,7 +3334,7 @@ * @chained workflow * * @param {String} workflowModelId workflow id - * @param [Object] object JSON object + * @param {Object} object JSON object */ createWorkflow: function(workflowModelId, object) { @@ -3351,11 +3343,11 @@ object = {}; } - var params = { + const params = { "modelId": workflowModelId }; - var chainable = this.getFactory().workflowInstance(this); + const chainable = this.getFactory().workflowInstance(this); return this.chainCreate(chainable, object, "/workflow/instances", params); }, @@ -3365,22 +3357,22 @@ * @chained workflow map * * @param {Object} query - * @param [Object] pagination pagination (optional) + * @param {Object} pagination pagination (optional) */ queryWorkflows: function(query, pagination) { - var params = {}; + const params = {}; if (pagination) { Gitana.copyInto(params, pagination); } - var uriFunction = function() + const uriFunction = function() { return "/workflow/instances/query"; }; - var chainable = this.getFactory().workflowInstanceMap(this); + const chainable = this.getFactory().workflowInstanceMap(this); return this.chainPost(chainable, uriFunction, params, query); }, @@ -3411,12 +3403,12 @@ */ checkWorkflowInstancePermissions: function(checks, callback) { - var uriFunction = function() + const uriFunction = function() { return "/workflow/instance/permissions/check"; }; - var object = { + const object = { "checks": checks }; @@ -3452,12 +3444,12 @@ */ checkWorkflowInstanceAuthorities: function(checks, callback) { - var uriFunction = function() + const uriFunction = function() { return "/workflow/instance/authorities/check"; }; - var object = { + const object = { "checks": checks }; @@ -3481,13 +3473,13 @@ */ listWorkflowTasks: function(pagination) { - var params = {}; + const params = {}; if (pagination) { Gitana.copyInto(params, pagination); } - var chainable = this.getFactory().workflowTaskMap(this); + const chainable = this.getFactory().workflowTaskMap(this); return this.chainGet(chainable, "/workflow/tasks", params); }, @@ -3500,7 +3492,7 @@ */ readWorkflowTask: function(workflowTaskId) { - var chainable = this.getFactory().workflowTask(this); + const chainable = this.getFactory().workflowTask(this); return this.chainGet(chainable, "/workflow/tasks/" + workflowTaskId); }, @@ -3510,22 +3502,22 @@ * @chained workflow task map * * @param {Object} query - * @param [Object] pagination pagination (optional) + * @param {Object} pagination pagination (optional) */ queryWorkflowTasks: function(query, pagination) { - var params = {}; + const params = {}; if (pagination) { Gitana.copyInto(params, pagination); } - var uriFunction = function() + const uriFunction = function() { return "/workflow/tasks/query"; }; - var chainable = this.getFactory().workflowTaskMap(this); + const chainable = this.getFactory().workflowTaskMap(this); return this.chainPost(chainable, uriFunction, params, query); }, @@ -3556,12 +3548,12 @@ */ checkWorkflowTaskPermissions: function(checks, callback) { - var uriFunction = function() + const uriFunction = function() { return "/workflow/task/permissions/check"; }; - var object = { + const object = { "checks": checks }; @@ -3597,12 +3589,12 @@ */ checkWorkflowTaskAuthorities: function(checks, callback) { - var uriFunction = function() + const uriFunction = function() { return "/workflow/task/authorities/check"; }; - var object = { + const object = { "checks": checks }; @@ -3627,13 +3619,13 @@ */ listWorkflowComments: function(pagination) { - var params = {}; + const params = {}; if (pagination) { Gitana.copyInto(params, pagination); } - var chainable = this.getFactory().workflowCommentMap(this); + const chainable = this.getFactory().workflowCommentMap(this); return this.chainGet(chainable, "/workflow/comments", params); }, @@ -3646,7 +3638,7 @@ */ readWorkflowComment: function(workflowCommentId) { - var chainable = this.getFactory().workflowComment(this); + const chainable = this.getFactory().workflowComment(this); return this.chainGet(chainable, "/workflow/comments/" + workflowCommentId); }, @@ -3656,16 +3648,15 @@ * @chained workflow comment * * @param {String} workflowId - * @param [String] workflowTaskId - * @param [Object] object JSON object + * @param {String} workflowTaskId + * @param {Object} object JSON object */ createWorkflowComment: function(workflowId, workflowTaskId, object) { - var params = {}; - var createUri = function() + const createUri = function() { - var uri = "/workflow/instances/" + workflowId + "/comments"; + let uri = "/workflow/instances/" + workflowId + "/comments"; if (workflowTaskId) { uri += "?taskId=" + workflowTaskId; @@ -3674,12 +3665,12 @@ return uri; }; - var readUri = function(status) + const readUri = function(status) { return "/workflow/comments/" + status._doc; }; - var chainable = this.getFactory().workflowComment(this); + const chainable = this.getFactory().workflowComment(this); return this.chainCreateEx(chainable, object, createUri, readUri); }, @@ -3690,22 +3681,22 @@ * @chained workflow comment map * * @param {Object} query - * @param [Object] pagination pagination (optional) + * @param {Object} pagination pagination (optional) */ queryWorkflowComments: function(query, pagination) { - var params = {}; + const params = {}; if (pagination) { Gitana.copyInto(params, pagination); } - var uriFunction = function() + const uriFunction = function() { return "/workflow/comments/query"; }; - var chainable = this.getFactory().workflowCommentMap(this); + const chainable = this.getFactory().workflowCommentMap(this); return this.chainPost(chainable, uriFunction, params, query); }, @@ -3736,12 +3727,12 @@ */ checkWorkflowCommentPermissions: function(checks, callback) { - var uriFunction = function() + const uriFunction = function() { return "/workflow/comments/permissions/check"; }; - var object = { + const object = { "checks": checks }; @@ -3777,12 +3768,12 @@ */ checkWorkflowCommentAuthorities: function(checks, callback) { - var uriFunction = function() + const uriFunction = function() { return "/workflow/comments/authorities/check"; }; - var object = { + const object = { "checks": checks }; @@ -3808,7 +3799,7 @@ */ listTasksForCurrentUser: function(filter, pagination) { - var params = {}; + const params = {}; if (pagination) { Gitana.copyInto(params, pagination); @@ -3819,7 +3810,7 @@ params.filter = filter; } - var chainable = this.getFactory().workflowTaskMap(this); + const chainable = this.getFactory().workflowTaskMap(this); return this.chainGet(chainable, "/workflow/user/tasks", params); }, @@ -3834,7 +3825,7 @@ */ queryTasksForCurrentUser: function(filter, query, pagination) { - var params = {}; + const params = {}; if (pagination) { Gitana.copyInto(params, pagination); @@ -3845,19 +3836,19 @@ params.filter = filter; } - var chainable = this.getFactory().workflowTaskMap(this); + const chainable = this.getFactory().workflowTaskMap(this); return this.chainPost(chainable, "/workflow/user/tasks/query", params, query); }, queryTasks: function(query, pagination) { - var params = {}; + const params = {}; if (pagination) { Gitana.copyInto(params, pagination); } - var chainable = this.getFactory().workflowTaskMap(this); + const chainable = this.getFactory().workflowTaskMap(this); return this.chainPost(chainable, "/workflow/tasks/query", params, query); }, @@ -3871,19 +3862,18 @@ * Loads the history for a workflow. * * @param workflowId the id of the workflow to load the history for - * @param workflowTaskId the current workflow task (or null if full history) * @param pagination * @param callback */ loadWorkflowHistory: function(workflowId, pagination, callback) { - var uriFunction = function() + const uriFunction = function() { return "/workflow/instances/" + workflowId + "/history"; }; // prepare params (with pagination) - var params = {}; + const params = {}; if (pagination) { Gitana.copyInto(params, pagination); @@ -3911,13 +3901,13 @@ */ listScheduledWorkItems: function(pagination) { - var params = {}; + const params = {}; if (pagination) { Gitana.copyInto(params, pagination); } - var chainable = this.getFactory().scheduledWorkMap(this); + const chainable = this.getFactory().scheduledWorkMap(this); return this.chainGet(chainable, "/work/scheduled", params); }, @@ -3930,7 +3920,7 @@ */ readScheduledWorkItem: function(scheduledWorkId) { - var chainable = this.getFactory().scheduledWork(this); + const chainable = this.getFactory().scheduledWork(this); return this.chainGet(chainable, "/work/scheduled/" + scheduledWorkId); }, @@ -3939,7 +3929,7 @@ * * @chained scheduled work * - * @param [Object] object JSON object + * @param {Object} object JSON object */ createScheduledWorkItem: function(object) { @@ -3948,7 +3938,7 @@ object = {}; } - var chainable = this.getFactory().scheduledWork(this); + const chainable = this.getFactory().scheduledWork(this); return this.chainCreate(chainable, object, "/work/scheduled"); }, @@ -3958,22 +3948,22 @@ * @chained scheduled work item map * * @param {Object} query - * @param [Object] pagination pagination (optional) + * @param {Object} pagination pagination (optional) */ queryScheduledWorkItems: function(query, pagination) { - var params = {}; + const params = {}; if (pagination) { Gitana.copyInto(params, pagination); } - var uriFunction = function() + const uriFunction = function() { return "/work/scheduled/query"; }; - var chainable = this.getFactory().scheduledWorkMap(this); + const chainable = this.getFactory().scheduledWorkMap(this); return this.chainPost(chainable, uriFunction, params, query); }, @@ -4004,12 +3994,12 @@ */ checkScheduledWorkPermissions: function(checks, callback) { - var uriFunction = function() + const uriFunction = function() { return "/work/scheduled/permissions/check"; }; - var object = { + const object = { "checks": checks }; @@ -4045,12 +4035,12 @@ */ checkScheduledWorkAuthorities: function(checks, callback) { - var uriFunction = function() + const uriFunction = function() { return "/work/scheduled/authorities/check"; }; - var object = { + const object = { "checks": checks }; @@ -4078,13 +4068,13 @@ */ listReports: function(pagination) { - var params = {}; + const params = {}; if (pagination) { Gitana.copyInto(params, pagination); } - var chainable = this.getFactory().reportMap(this); + const chainable = this.getFactory().reportMap(this); return this.chainGet(chainable, "/reports", params); }, @@ -4097,7 +4087,7 @@ */ readReport: function(reportId) { - var chainable = this.getFactory().report(this); + const chainable = this.getFactory().report(this); return this.chainGet(chainable, "/reports/" + reportId); }, @@ -4106,7 +4096,7 @@ * * @chained report * - * @param [Object] object JSON object + * @param {Object} object JSON object */ createReport: function(object) { @@ -4115,7 +4105,7 @@ object = {}; } - var chainable = this.getFactory().report(this); + const chainable = this.getFactory().report(this); return this.chainCreate(chainable, object, "/reports"); }, @@ -4125,22 +4115,22 @@ * @chained report map * * @param {Object} query - * @param [Object] pagination pagination (optional) + * @param {Object} pagination pagination (optional) */ queryReports: function(query, pagination) { - var params = {}; + const params = {}; if (pagination) { Gitana.copyInto(params, pagination); } - var uriFunction = function() + const uriFunction = function() { return "/reports/query"; }; - var chainable = this.getFactory().reportMap(this); + const chainable = this.getFactory().reportMap(this); return this.chainPost(chainable, uriFunction, params, query); }, @@ -4171,12 +4161,12 @@ */ checkReportPermissions: function(checks, callback) { - var uriFunction = function() + const uriFunction = function() { return "/reports/permissions/check"; }; - var object = { + const object = { "checks": checks }; @@ -4212,12 +4202,12 @@ */ checkReportAuthorities: function(checks, callback) { - var uriFunction = function() + const uriFunction = function() { return "/reports/authorities/check"; }; - var object = { + const object = { "checks": checks }; @@ -4232,8 +4222,8 @@ * @chained report * * @param {String} reportId the id of the report to run - * @param [Object] config additional config - * @param [Object] pagination + * @param {Object} config additional config + * @param {Object} pagination * @param {Function} callback callback to fire */ executeReport: function(reportId, config, pagination, callback) @@ -4255,13 +4245,13 @@ } } - var params = {}; + const params = {}; if (pagination) { Gitana.copyInto(params, pagination); } - var uriFunction = function() + const uriFunction = function() { return "/reports/" + reportId + "/execute"; }; @@ -4292,9 +4282,7 @@ */ runExport: function(objects, configuration, callback) { - var self = this; - - var uriFunction = function() + const uriFunction = function() { return "/ref/exports/start"; }; @@ -4304,36 +4292,36 @@ configuration = {}; } - var references = []; + let references = []; if (objects.refs) { references = objects.refs(); } else if (objects.length) { - for (var i = 0; i < objects.length; i++) + for (let i = 0; i < objects.length; i++) { references.push(objects[i].ref()); } } configuration.references = references; - var chainable = this; + const chainable = this; return this.chainPostResponse(this, uriFunction, {}, configuration).then(function(response) { - var exportId = response._doc; + const exportId = response._doc; // wait for the export to finish... - var f = function() + const f = function() { window.setTimeout(function() { Chain(chainable).readExportStatus(exportId, function(status) { - if (status.state == "FINISHED") { + if (status.state === "FINISHED") { callback(exportId, status); chainable.next(); - } else if (status.state == "ERROR") { + } else if (status.state === "ERROR") { callback(exportId, status); chainable.next(); } else { @@ -4360,7 +4348,7 @@ */ readExportStatus: function(exportId, callback) { - var uriFunction = function() + const uriFunction = function() { return "/ref/exports/" + exportId + "/status"; }; @@ -4380,7 +4368,7 @@ */ exportDownloadUrl: function(exportId, index, useDispositionHeader) { - var url = "/ref/exports/" + exportId + "/download"; + let url = "/ref/exports/" + exportId + "/download"; if (index) { @@ -4416,13 +4404,13 @@ */ listServiceDescriptors: function(pagination) { - var params = {}; + const params = {}; if (pagination) { Gitana.copyInto(params, pagination); } - var chainable = this.getFactory().descriptorMap(this); + const chainable = this.getFactory().descriptorMap(this); return this.chainGet(chainable, "/descriptors", params); }, @@ -4435,7 +4423,7 @@ */ readServiceDescriptor: function(descriptorId) { - var chainable = this.getFactory().descriptor(this); + const chainable = this.getFactory().descriptor(this); return this.chainGet(chainable, "/descriptors/" + descriptorId); }, @@ -4444,7 +4432,7 @@ * * @chained descriptor * - * @param [Object] object JSON object + * @param {Object} object JSON object */ createServiceDescriptor: function(object) { @@ -4453,7 +4441,7 @@ object = {}; } - var chainable = this.getFactory().descriptor(this); + const chainable = this.getFactory().descriptor(this); return this.chainCreate(chainable, object, "/descriptors"); }, @@ -4463,22 +4451,22 @@ * @chained descriptor map * * @param {Object} query - * @param [Object] pagination pagination (optional) + * @param {Object} pagination pagination (optional) */ queryServiceDescriptors: function(query, pagination) { - var params = {}; + const params = {}; if (pagination) { Gitana.copyInto(params, pagination); } - var uriFunction = function() + const uriFunction = function() { return "/descriptors/query"; }; - var chainable = this.getFactory().descriptorMap(this); + const chainable = this.getFactory().descriptorMap(this); return this.chainPost(chainable, uriFunction, params, query); }, @@ -4509,12 +4497,12 @@ */ checkServiceDescriptorPermissions: function(checks, callback) { - var uriFunction = function() + const uriFunction = function() { return "/descriptors/permissions/check"; }; - var object = { + const object = { "checks": checks }; @@ -4550,12 +4538,12 @@ */ checkServiceDescriptorAuthorities: function(checks, callback) { - var uriFunction = function() + const uriFunction = function() { return "/descriptors/authorities/check"; }; - var object = { + const object = { "checks": checks }; @@ -4582,13 +4570,13 @@ */ listUIConfigs: function(pagination) { - var params = {}; + const params = {}; if (pagination) { Gitana.copyInto(params, pagination); } - var chainable = this.getFactory().uiConfigMap(this); + const chainable = this.getFactory().uiConfigMap(this); return this.chainGet(chainable, "/uiconfigs", params); }, @@ -4601,7 +4589,7 @@ */ readUIConfig: function(uiConfigId) { - var chainable = this.getFactory().uiConfig(this); + const chainable = this.getFactory().uiConfig(this); return this.chainGet(chainable, "/uiconfigs/" + uiConfigId); }, @@ -4610,7 +4598,7 @@ * * @chained uiConfig * - * @param [Object] object JSON object + * @param {Object} object JSON object */ createUIConfig: function(object) { @@ -4619,7 +4607,7 @@ object = {}; } - var chainable = this.getFactory().uiConfig(this); + const chainable = this.getFactory().uiConfig(this); return this.chainCreate(chainable, object, "/uiconfigs"); }, @@ -4629,22 +4617,22 @@ * @chained UI config map * * @param {Object} query - * @param [Object] pagination pagination (optional) + * @param {Object} pagination pagination (optional) */ queryUIConfigs: function(query, pagination) { - var params = {}; + const params = {}; if (pagination) { Gitana.copyInto(params, pagination); } - var uriFunction = function() + const uriFunction = function() { return "/uiconfigs/query"; }; - var chainable = this.getFactory().uiConfigMap(this); + const chainable = this.getFactory().uiConfigMap(this); return this.chainPost(chainable, uriFunction, params, query); }, @@ -4675,12 +4663,12 @@ */ checkUIConfigPermissions: function(checks, callback) { - var uriFunction = function() + const uriFunction = function() { return "/uiconfigs/permissions/check"; }; - var object = { + const object = { "checks": checks }; @@ -4716,12 +4704,12 @@ */ checkUIConfigAuthorities: function(checks, callback) { - var uriFunction = function() + const uriFunction = function() { return "/uiconfigs/authorities/check"; }; - var object = { + const object = { "checks": checks }; @@ -4748,13 +4736,13 @@ */ listDeploymentReceivers: function(pagination) { - var params = {}; + const params = {}; if (pagination) { Gitana.copyInto(params, pagination); } - var chainable = this.getFactory().deploymentReceiverMap(this); + const chainable = this.getFactory().deploymentReceiverMap(this); return this.chainGet(chainable, "/deployment/receivers", params); }, @@ -4767,7 +4755,7 @@ */ readDeploymentReceiver: function(deploymentReceiverId) { - var chainable = this.getFactory().deploymentReceiver(this); + const chainable = this.getFactory().deploymentReceiver(this); return this.chainGet(chainable, "/deployment/receivers/" + deploymentReceiverId); }, @@ -4776,7 +4764,7 @@ * * @chained deployment receiver * - * @param [Object] object JSON object + * @param {Object} object JSON object */ createDeploymentReceiver: function(object) { @@ -4785,7 +4773,7 @@ object = {}; } - var chainable = this.getFactory().deploymentReceiver(this); + const chainable = this.getFactory().deploymentReceiver(this); return this.chainCreate(chainable, object, "/deployment/receivers"); }, @@ -4795,22 +4783,22 @@ * @chained deployment receiver map * * @param {Object} query - * @param [Object] pagination pagination (optional) + * @param {Object} pagination pagination (optional) */ queryDeploymentReceivers: function(query, pagination) { - var params = {}; + const params = {}; if (pagination) { Gitana.copyInto(params, pagination); } - var uriFunction = function() + const uriFunction = function() { return "/deployment/receivers/query"; }; - var chainable = this.getFactory().deploymentReceiverMap(this); + const chainable = this.getFactory().deploymentReceiverMap(this); return this.chainPost(chainable, uriFunction, params, query); }, @@ -4841,12 +4829,12 @@ */ checkDeploymentReceiverPermissions: function(checks, callback) { - var uriFunction = function() + const uriFunction = function() { return "/deployment/receivers/permissions/check"; }; - var object = { + const object = { "checks": checks }; @@ -4882,12 +4870,12 @@ */ checkDeploymentReceiverAuthorities: function(checks, callback) { - var uriFunction = function() + const uriFunction = function() { return "/deployment/receivers/authorities/check"; }; - var object = { + const object = { "checks": checks }; @@ -4914,13 +4902,13 @@ */ listDeploymentPackages: function(pagination) { - var params = {}; + const params = {}; if (pagination) { Gitana.copyInto(params, pagination); } - var chainable = this.getFactory().deploymentPackageMap(this); + const chainable = this.getFactory().deploymentPackageMap(this); return this.chainGet(chainable, "/deployment/packages", params); }, @@ -4933,7 +4921,7 @@ */ readDeploymentPackage: function(deploymentPackageId) { - var chainable = this.getFactory().deploymentPackage(this); + const chainable = this.getFactory().deploymentPackage(this); return this.chainGet(chainable, "/deployment/packages/" + deploymentPackageId); }, @@ -4943,22 +4931,22 @@ * @chained deployment package map * * @param {Object} query - * @param [Object] pagination pagination (optional) + * @param {Object} pagination pagination (optional) */ queryDeploymentPackages: function(query, pagination) { - var params = {}; + const params = {}; if (pagination) { Gitana.copyInto(params, pagination); } - var uriFunction = function() + const uriFunction = function() { return "/deployment/packages/query"; }; - var chainable = this.getFactory().deploymentPackageMap(this); + const chainable = this.getFactory().deploymentPackageMap(this); return this.chainPost(chainable, uriFunction, params, query); }, @@ -4989,12 +4977,12 @@ */ checkDeploymentPackagePermissions: function(checks, callback) { - var uriFunction = function() + const uriFunction = function() { return "/deployment/packages/permissions/check"; }; - var object = { + const object = { "checks": checks }; @@ -5030,12 +5018,12 @@ */ checkDeploymentPackageAuthorities: function(checks, callback) { - var uriFunction = function() + const uriFunction = function() { return "/deployment/packages/authorities/check"; }; - var object = { + const object = { "checks": checks }; @@ -5062,13 +5050,13 @@ */ listDeploymentStrategies: function(pagination) { - var params = {}; + const params = {}; if (pagination) { Gitana.copyInto(params, pagination); } - var chainable = this.getFactory().deploymentStrategyMap(this); + const chainable = this.getFactory().deploymentStrategyMap(this); return this.chainGet(chainable, "/deployment/strategies", params); }, @@ -5081,7 +5069,7 @@ */ readDeploymentStrategy: function(deploymentStrategyId) { - var chainable = this.getFactory().deploymentStrategy(this); + const chainable = this.getFactory().deploymentStrategy(this); return this.chainGet(chainable, "/deployment/strategies/" + deploymentStrategyId); }, @@ -5090,7 +5078,7 @@ * * @chained deployment strategy * - * @param [Object] object JSON object + * @param {Object} object JSON object */ createDeploymentStrategy: function(object) { @@ -5099,7 +5087,7 @@ object = {}; } - var chainable = this.getFactory().deploymentStrategy(this); + const chainable = this.getFactory().deploymentStrategy(this); return this.chainCreate(chainable, object, "/deployment/strategies"); }, @@ -5109,22 +5097,22 @@ * @chained deployment strategy map * * @param {Object} query - * @param [Object] pagination pagination (optional) + * @param {Object} pagination pagination (optional) */ queryDeploymentStrategies: function(query, pagination) { - var params = {}; + const params = {}; if (pagination) { Gitana.copyInto(params, pagination); } - var uriFunction = function() + const uriFunction = function() { return "/deployment/strategies/query"; }; - var chainable = this.getFactory().deploymentStrategyMap(this); + const chainable = this.getFactory().deploymentStrategyMap(this); return this.chainPost(chainable, uriFunction, params, query); }, @@ -5155,12 +5143,12 @@ */ checkDeploymentStrategyPermissions: function(checks, callback) { - var uriFunction = function() + const uriFunction = function() { return "/deployment/strategies/permissions/check"; }; - var object = { + const object = { "checks": checks }; @@ -5196,12 +5184,12 @@ */ checkDeploymentStrategyAuthorities: function(checks, callback) { - var uriFunction = function() + const uriFunction = function() { return "/deployment/strategies/authorities/check"; }; - var object = { + const object = { "checks": checks }; @@ -5228,13 +5216,13 @@ */ listDeploymentTargets: function(pagination) { - var params = {}; + const params = {}; if (pagination) { Gitana.copyInto(params, pagination); } - var chainable = this.getFactory().deploymentTargetMap(this); + const chainable = this.getFactory().deploymentTargetMap(this); return this.chainGet(chainable, "/deployment/targets", params); }, @@ -5247,7 +5235,7 @@ */ readDeploymentTarget: function(deploymentTargetId) { - var chainable = this.getFactory().deploymentTarget(this); + const chainable = this.getFactory().deploymentTarget(this); return this.chainGet(chainable, "/deployment/targets/" + deploymentTargetId); }, @@ -5256,7 +5244,7 @@ * * @chained deployment target * - * @param [Object] object JSON object + * @param {Object} object JSON object */ createDeploymentTarget: function(object) { @@ -5265,7 +5253,7 @@ object = {}; } - var chainable = this.getFactory().deploymentTarget(this); + const chainable = this.getFactory().deploymentTarget(this); return this.chainCreate(chainable, object, "/deployment/targets"); }, @@ -5275,22 +5263,22 @@ * @chained deployment target map * * @param {Object} query - * @param [Object] pagination pagination (optional) + * @param {Object} pagination pagination (optional) */ queryDeploymentTargets: function(query, pagination) { - var params = {}; + const params = {}; if (pagination) { Gitana.copyInto(params, pagination); } - var uriFunction = function() + const uriFunction = function() { return "/deployment/targets/query"; }; - var chainable = this.getFactory().deploymentTargetMap(this); + const chainable = this.getFactory().deploymentTargetMap(this); return this.chainPost(chainable, uriFunction, params, query); }, @@ -5321,12 +5309,12 @@ */ checkDeploymentTargetPermissions: function(checks, callback) { - var uriFunction = function() + const uriFunction = function() { return "/deployment/targets/permissions/check"; }; - var object = { + const object = { "checks": checks }; @@ -5362,12 +5350,12 @@ */ checkDeploymentTargetAuthorities: function(checks, callback) { - var uriFunction = function() + const uriFunction = function() { return "/deployment/targets/authorities/check"; }; - var object = { + const object = { "checks": checks }; diff --git a/js/gitana/platform/PlatformDataStoreMap.js b/js/gitana/platform/PlatformDataStoreMap.js index 976b33be..f26a2241 100644 --- a/js/gitana/platform/PlatformDataStoreMap.js +++ b/js/gitana/platform/PlatformDataStoreMap.js @@ -1,6 +1,6 @@ (function(window) { - var Gitana = window.Gitana; + Gitana = window.Gitana; Gitana.PlatformDataStoreMap = Gitana.AbstractMap.extend( /** @lends Gitana.PlatformDataStoreMap.prototype */ diff --git a/js/gitana/platform/Project.js b/js/gitana/platform/Project.js index 29a72cb8..18ea0934 100644 --- a/js/gitana/platform/Project.js +++ b/js/gitana/platform/Project.js @@ -1,6 +1,6 @@ (function(window) { - var Gitana = window.Gitana; + Gitana = window.Gitana; Gitana.Project = Gitana.AbstractPlatformObject.extend( /** @lends Gitana.Project.prototype */ @@ -12,7 +12,7 @@ * @class Project * * @param {Gitana.Platform} platform - * @param [Object] object json object (if no callback required for populating) + * @param {Object} object json object (if no callback required for populating) */ constructor: function(platform, object) { @@ -110,14 +110,14 @@ */ readStack: function() { - var self = this; + const self = this; - var uriFunction = function() + const uriFunction = function() { return self.getPlatform().getUri() + "/stacks/" + self["stackId"]; }; - var chainable = this.getFactory().stack(this.getPlatform()); + const chainable = this.getFactory().stack(this.getPlatform()); return this.chainGet(chainable, uriFunction); }, @@ -129,15 +129,15 @@ adminMaintenance: function() { - var self = this; + const self = this; return this.then(function() { - var chain = this; + const chain = this; // call - var uri = self.getUri() + "/admin/maintenance"; - self.getDriver().gitanaPost(uri, null, {}, function(response) { + const uri = self.getUri() + "/admin/maintenance"; + self.getDriver().gitanaPost(uri, null, {}, function() { chain.next(); }); @@ -154,12 +154,12 @@ inviteUser: function(userId) { - var self = this; + const self = this; - var params = {}; + const params = {}; params["id"] = userId; - var uriFunction = function() + const uriFunction = function() { return self.getUri() + "/users/invite"; }; diff --git a/js/gitana/platform/ProjectMap.js b/js/gitana/platform/ProjectMap.js index e254494a..6b57faf4 100644 --- a/js/gitana/platform/ProjectMap.js +++ b/js/gitana/platform/ProjectMap.js @@ -1,6 +1,6 @@ (function(window) { - var Gitana = window.Gitana; + Gitana = window.Gitana; Gitana.ProjectMap = Gitana.AbstractPlatformObjectMap.extend( /** @lends Gitana.ProjectMap.prototype */ @@ -12,7 +12,7 @@ * @class Map of projects * * @param {Gitana.Platform} platform Gitana platform instance. - * @param [Object] object + * @param {Object} object */ constructor: function(platform, object) { diff --git a/js/gitana/platform/Report.js b/js/gitana/platform/Report.js index 7c35cd02..ed5a1fb6 100644 --- a/js/gitana/platform/Report.js +++ b/js/gitana/platform/Report.js @@ -1,6 +1,6 @@ (function(window) { - var Gitana = window.Gitana; + Gitana = window.Gitana; Gitana.Report = Gitana.AbstractPlatformObject.extend( /** @lends Gitana.Report.prototype */ @@ -12,7 +12,7 @@ * @class Report * * @param {Gitana.Platform} platform - * @param [Object] object json object (if no callback required for populating) + * @param {Object} object json object (if no callback required for populating) */ constructor: function(platform, object) { diff --git a/js/gitana/platform/ReportMap.js b/js/gitana/platform/ReportMap.js index 2ae49b21..4720f07e 100644 --- a/js/gitana/platform/ReportMap.js +++ b/js/gitana/platform/ReportMap.js @@ -1,6 +1,6 @@ (function(window) { - var Gitana = window.Gitana; + Gitana = window.Gitana; Gitana.ReportMap = Gitana.AbstractPlatformObjectMap.extend( /** @lends Gitana.ReportMap.prototype */ @@ -12,7 +12,7 @@ * @class Map of reports * * @param {Gitana.Platform} platform Gitana platform instance. - * @param [Object] object + * @param {Object} object */ constructor: function(platform, object) { diff --git a/js/gitana/platform/ScheduledWork.js b/js/gitana/platform/ScheduledWork.js index 9bcf6c0a..510ded2e 100644 --- a/js/gitana/platform/ScheduledWork.js +++ b/js/gitana/platform/ScheduledWork.js @@ -1,6 +1,6 @@ (function(window) { - var Gitana = window.Gitana; + Gitana = window.Gitana; Gitana.ScheduledWork = Gitana.AbstractPlatformObject.extend( /** @lends Gitana.ScheduledWork.prototype */ @@ -12,7 +12,7 @@ * @class ScheduledWork * * @param {Gitana.Platform} platform - * @param [Object] object json object (if no callback required for populating) + * @param {Object} object json object (if no callback required for populating) */ constructor: function(platform, object) { @@ -51,15 +51,15 @@ */ trigger: function() { - var self = this; + const self = this; return this.then(function() { - var chain = this; + const chain = this; // call - var uri = self.getUri() + "/trigger"; - self.getDriver().gitanaPost(uri, null, {}, function(response) { + const uri = self.getUri() + "/trigger"; + self.getDriver().gitanaPost(uri, null, {}, function() { chain.next(); }); diff --git a/js/gitana/platform/ScheduledWorkMap.js b/js/gitana/platform/ScheduledWorkMap.js index 95700a1d..4813fd23 100644 --- a/js/gitana/platform/ScheduledWorkMap.js +++ b/js/gitana/platform/ScheduledWorkMap.js @@ -1,6 +1,6 @@ (function(window) { - var Gitana = window.Gitana; + Gitana = window.Gitana; Gitana.ScheduledWorkMap = Gitana.AbstractPlatformObjectMap.extend( /** @lends Gitana.ScheduledWorkMap.prototype */ @@ -12,7 +12,7 @@ * @class Map of scheduled work items * * @param {Gitana.Platform} platform Gitana platform instance. - * @param [Object] object + * @param {Object} object */ constructor: function(platform, object) { diff --git a/js/gitana/platform/Stack.js b/js/gitana/platform/Stack.js index f92c5efa..60bba04b 100644 --- a/js/gitana/platform/Stack.js +++ b/js/gitana/platform/Stack.js @@ -1,6 +1,6 @@ (function(window) { - var Gitana = window.Gitana; + Gitana = window.Gitana; Gitana.Stack = Gitana.AbstractPlatformObject.extend( /** @lends Gitana.Stack.prototype */ @@ -12,7 +12,7 @@ * @class Stack * * @param {Gitana.Platform} platform - * @param [Object] object json object (if no callback required for populating) + * @param {Object} object json object (if no callback required for populating) */ constructor: function(platform, object) { @@ -69,12 +69,12 @@ */ readTeam: function(teamKey) { - var uriFunction = function() + const uriFunction = function() { return this.getUri() + "/teams/" + teamKey; }; - var chainable = this.getFactory().team(this.getPlatform(), this); + const chainable = this.getFactory().team(this.getPlatform(), this); return this.chainGet(chainable, uriFunction); }, @@ -85,18 +85,18 @@ */ listTeams: function(pagination) { - var params = {}; + const params = {}; if (pagination) { Gitana.copyInto(params, pagination); } - var uriFunction = function() + const uriFunction = function() { return this.getUri() + "/teams"; }; - var chainable = this.getFactory().teamMap(this.getCluster(), this); + const chainable = this.getFactory().teamMap(this.getCluster(), this); return this.chainGet(chainable, uriFunction, params); }, @@ -115,17 +115,17 @@ object = {}; } - var uriFunction = function() + const uriFunction = function() { return this.getUri() + "/teams?key=" + teamKey; }; - var self = this; + const self = this; - var chainable = this.getFactory().team(this.getPlatform(), this); + const chainable = this.getFactory().team(this.getPlatform(), this); return this.chainPostResponse(chainable, uriFunction, {}, object).then(function() { - var chain = this; + const chain = this; Chain(self).readTeam(teamKey).then(function() { chain.handleResponse(this); @@ -172,19 +172,19 @@ */ readRole: function(roleKeyOrId, inherited) { - var params = {}; + const params = {}; if (inherited) { params.inherited = true; } - var uriFunction = function() + const uriFunction = function() { return this.getUri() + "/roles/" + roleKeyOrId; }; - var chainable = this.getFactory().role(this.getCluster(), this); + const chainable = this.getFactory().role(this.getCluster(), this); return this.chainGet(chainable, uriFunction, params); }, @@ -197,19 +197,19 @@ */ listRoles: function(inherited) { - var params = {}; + const params = {}; if (inherited) { params.inherited = true; } - var uriFunction = function() + const uriFunction = function() { return this.getUri() + "/roles"; }; - var chainable = this.getFactory().roleMap(this.getCluster(), this); + const chainable = this.getFactory().roleMap(this.getCluster(), this); return this.chainGet(chainable, uriFunction, params); }, @@ -229,14 +229,14 @@ } object.roleKey = roleKey; - var uriFunction = function() + const uriFunction = function() { return this.getUri() + "/roles"; }; - var self = this; + const self = this; - var chainable = this.getFactory().role(this.getPlatform(), this, roleKey); + const chainable = this.getFactory().role(this.getPlatform(), this, roleKey); return this.chainPostResponse(chainable, uriFunction, {}, object).then(function() { this.subchain(self).readRole(roleKey).then(function() { Gitana.copyInto(chainable, this); @@ -324,12 +324,12 @@ * @chained log entry map * * @param {Object} query Query for finding log entries. - * @param [Object] pagination pagination (optional) + * @param {Object} pagination pagination (optional) */ queryLogEntries: function(query, pagination) { - var self = this; - var uriFunction = function() + const self = this; + const uriFunction = function() { return self.getUri() + "/logs/query"; }; @@ -339,10 +339,10 @@ query = {}; } - var chainable = this.getFactory().logEntryMap(this.getCluster()); + const chainable = this.getFactory().logEntryMap(this.getCluster()); // prepare params (with pagination) - var params = {}; + const params = {}; if (pagination) { Gitana.copyInto(params, pagination); @@ -356,17 +356,17 @@ * * @chained log entry * - * @param {String} jobId + * @param {String} logEntryId */ readLogEntry: function(logEntryId) { - var self = this; - var uriFunction = function() + const self = this; + const uriFunction = function() { return self.getUri() + "/logs/" + logEntryId; }; - var chainable = this.getFactory().logEntry(this.getCluster()); + const chainable = this.getFactory().logEntry(this.getCluster()); return this.chainGet(chainable, uriFunction); }, @@ -379,9 +379,8 @@ */ readLog: function(callback) { - var self = this; - var uriFunction = function () { + const uriFunction = function () { return this.getUri() + "/logs/logfile"; }; @@ -410,20 +409,20 @@ */ assignDataStore: function(datastore, key) { - var self = this; + const self = this; - var uriFunction = function() + const uriFunction = function() { return self.getUri() + "/datastores/assign"; }; - var args = Gitana.makeArray(arguments); + const args = Gitana.makeArray(arguments); - var params; + let params; - if (args.length == 1) + if (args.length === 1) { - var arg = args.shift(); + const arg = args.shift(); if (arg.getType && arg.getId) { @@ -464,14 +463,14 @@ */ unassignDataStore: function(key) { - var self = this; + const self = this; - var uriFunction = function() + const uriFunction = function() { return self.getUri() + "/datastores/unassign"; }; - var params = { + const params = { "key": key }; @@ -488,17 +487,17 @@ */ listDataStores: function(pagination) { - var self = this; + const self = this; - var uriFunction = function() + const uriFunction = function() { return self.getUri() + "/datastores"; }; - var chainable = this.getFactory().platformDataStoreMap(this.getPlatform()); + const chainable = this.getFactory().platformDataStoreMap(this.getPlatform()); // prepare params (with pagination) - var params = {}; + const params = {}; if (pagination) { Gitana.copyInto(params, pagination); @@ -513,25 +512,25 @@ * @chained datastore map * * @param {Object} query - * @param [Object] pagination pagination (optional) + * @param {Object} pagination pagination (optional) */ queryDataStores: function(query, pagination) { - var self = this; + const self = this; // prepare params (with pagination) - var params = {}; + const params = {}; if (pagination) { Gitana.copyInto(params, pagination); } - var uriFunction = function() + const uriFunction = function() { return self.getUri() + "/datastores/query"; }; - var chainable = this.getFactory().platformDataStoreMap(this.getPlatform()); + const chainable = this.getFactory().platformDataStoreMap(this.getPlatform()); return this.chainPost(chainable, uriFunction, params, query); }, @@ -547,9 +546,9 @@ */ existsDataStore: function(key, callback) { - var self = this; + const self = this; - var uriFunction = function() + const uriFunction = function() { return self.getUri() + "/datastores/exists?key=" + key; }; @@ -569,15 +568,15 @@ */ readDataStore: function(key, callback) { - var self = this; + const self = this; return this.then(function() { - var chain = this; + const chain = this; Chain(self).queryDataStores().then(function() { - var datastore = this[key]; + const datastore = this[key]; datastore["_doc"] = datastore["datastoreId"]; delete datastore["datastoreTypeId"]; diff --git a/js/gitana/platform/StackMap.js b/js/gitana/platform/StackMap.js index 00c27dfd..c47f3c02 100644 --- a/js/gitana/platform/StackMap.js +++ b/js/gitana/platform/StackMap.js @@ -1,6 +1,6 @@ (function(window) { - var Gitana = window.Gitana; + Gitana = window.Gitana; Gitana.StackMap = Gitana.AbstractPlatformObjectMap.extend( /** @lends Gitana.StackMap.prototype */ @@ -12,7 +12,7 @@ * @class Map of stacks * * @param {Gitana.Platform} platform Gitana platform instance. - * @param [Object] object + * @param {Object} object */ constructor: function(platform, object) { diff --git a/js/gitana/platform/UIConfig.js b/js/gitana/platform/UIConfig.js index 858a22c2..8f3d1891 100644 --- a/js/gitana/platform/UIConfig.js +++ b/js/gitana/platform/UIConfig.js @@ -1,6 +1,6 @@ (function(window) { - var Gitana = window.Gitana; + Gitana = window.Gitana; Gitana.UIConfig = Gitana.AbstractPlatformObject.extend( /** @lends Gitana.UIConfig.prototype */ @@ -12,7 +12,7 @@ * @class UIConfig * * @param {Gitana.Platform} platform - * @param [Object] object json object (if no callback required for populating) + * @param {Object} object json object (if no callback required for populating) */ constructor: function(platform, object) { diff --git a/js/gitana/platform/UIConfigMap.js b/js/gitana/platform/UIConfigMap.js index 51276a82..b52d9280 100644 --- a/js/gitana/platform/UIConfigMap.js +++ b/js/gitana/platform/UIConfigMap.js @@ -1,6 +1,6 @@ (function(window) { - var Gitana = window.Gitana; + Gitana = window.Gitana; Gitana.UIConfigMap = Gitana.AbstractPlatformObjectMap.extend( /** @lends Gitana.UIConfigMap.prototype */ @@ -12,7 +12,7 @@ * @class Map of ui configs * * @param {Gitana.Platform} platform Gitana platform instance. - * @param [Object] object + * @param {Object} object */ constructor: function(platform, object) { diff --git a/js/gitana/platform/WorkflowComment.js b/js/gitana/platform/WorkflowComment.js index 861e2cde..2b542df1 100644 --- a/js/gitana/platform/WorkflowComment.js +++ b/js/gitana/platform/WorkflowComment.js @@ -1,6 +1,6 @@ (function(window) { - var Gitana = window.Gitana; + Gitana = window.Gitana; Gitana.WorkflowComment = Gitana.AbstractPlatformObject.extend( /** @lends Gitana.WorkflowComment.prototype */ @@ -12,7 +12,7 @@ * @class WorkflowComment * * @param {Gitana.Platform} platform - * @param [Object] object json object (if no callback required for populating) + * @param {Object} object json object (if no callback required for populating) */ constructor: function(platform, object) { diff --git a/js/gitana/platform/WorkflowCommentMap.js b/js/gitana/platform/WorkflowCommentMap.js index 6763c5f7..55184010 100644 --- a/js/gitana/platform/WorkflowCommentMap.js +++ b/js/gitana/platform/WorkflowCommentMap.js @@ -1,6 +1,6 @@ (function(window) { - var Gitana = window.Gitana; + Gitana = window.Gitana; Gitana.WorkflowCommentMap = Gitana.AbstractPlatformObjectMap.extend( /** @lends Gitana.WorkflowCommentMap.prototype */ @@ -12,7 +12,7 @@ * @class Map of workflow comments * * @param {Gitana.Platform} platform Gitana platform instance. - * @param [Object] object + * @param {Object} object */ constructor: function(platform, object) { diff --git a/js/gitana/platform/WorkflowInstance.js b/js/gitana/platform/WorkflowInstance.js index d9ff7d20..bf02e2bc 100644 --- a/js/gitana/platform/WorkflowInstance.js +++ b/js/gitana/platform/WorkflowInstance.js @@ -1,6 +1,6 @@ (function(window) { - var Gitana = window.Gitana; + Gitana = window.Gitana; Gitana.WorkflowInstance = Gitana.AbstractPlatformObject.extend( /** @lends Gitana.WorkflowInstance.prototype */ @@ -12,7 +12,7 @@ * @class WorkflowInstance * * @param {Gitana.Platform} platform - * @param [Object] object json object (if no callback required for populating) + * @param {Object} object json object (if no callback required for populating) */ constructor: function(platform, object) { @@ -27,7 +27,7 @@ this.toResourceId = function(resourceOrResourceId) { - var id = resourceOrResourceId; + let id = resourceOrResourceId; if (resourceOrResourceId && resourceOrResourceId.getId) { @@ -72,7 +72,7 @@ loadResourceList: function(callback) { - var uriFunction = function() + const uriFunction = function() { return this.getUri() + "/resources"; }; @@ -84,7 +84,7 @@ loadResource: function(id, callback) { - var uriFunction = function() + const uriFunction = function() { return this.getUri() + "/resources/" + id; }; @@ -96,14 +96,14 @@ addResource: function(resource) { - var uriFunction = function() + const uriFunction = function() { return this.getUri() + "/resources/add"; }; - var reference = this.toReference(resource); + const reference = this.toReference(resource); - var params = { + const params = { "reference": reference }; @@ -112,9 +112,9 @@ removeResource: function(resourceOrResourceId) { - var uriFunction = function() + const uriFunction = function() { - var resourceId = this.toResourceId(resourceOrResourceId); + const resourceId = this.toResourceId(resourceOrResourceId); return this.getUri() + "/resources/" + resourceId + "/remove"; }; @@ -124,7 +124,7 @@ removeAllResources: function() { - var uriFunction = function() + const uriFunction = function() { return this.getUri() + "/resources/removeall"; }; @@ -136,13 +136,13 @@ * Starts the workflow. The workflow can only be started once. If already started, * an error will be thrown. * - * @param [Object] data + * @param {Object} data * * @returns {*} */ start: function(data) { - var uriFunction = function() + const uriFunction = function() { return this.getUri() + "/start"; }; @@ -158,7 +158,7 @@ */ terminate: function() { - var uriFunction = function() + const uriFunction = function() { return this.getUri() + "/terminate"; }; @@ -173,7 +173,7 @@ */ suspend: function() { - var uriFunction = function() + const uriFunction = function() { return this.getUri() + "/suspend"; }; @@ -188,7 +188,7 @@ */ resume: function() { - var uriFunction = function() + const uriFunction = function() { return this.getUri() + "/resume"; }; @@ -203,12 +203,12 @@ */ upgradeModel: function(newModel, newModelVersion) { - var uriFunction = function() + const uriFunction = function() { return this.getUri() + "/upgrade"; }; - var params = { + const params = { "id": newModel, "version": newModelVersion }; diff --git a/js/gitana/platform/WorkflowInstanceMap.js b/js/gitana/platform/WorkflowInstanceMap.js index 459e0b66..393b01de 100644 --- a/js/gitana/platform/WorkflowInstanceMap.js +++ b/js/gitana/platform/WorkflowInstanceMap.js @@ -1,6 +1,6 @@ (function(window) { - var Gitana = window.Gitana; + Gitana = window.Gitana; Gitana.WorkflowInstanceMap = Gitana.AbstractPlatformObjectMap.extend( /** @lends Gitana.WorkflowInstanceMap.prototype */ @@ -12,7 +12,7 @@ * @class Map of workflow instances * * @param {Gitana.Platform} platform Gitana platform instance. - * @param [Object] object + * @param {Object} object */ constructor: function(platform, object) { diff --git a/js/gitana/platform/WorkflowModel.js b/js/gitana/platform/WorkflowModel.js index 76f0a2b5..2750b765 100644 --- a/js/gitana/platform/WorkflowModel.js +++ b/js/gitana/platform/WorkflowModel.js @@ -1,6 +1,6 @@ (function(window) { - var Gitana = window.Gitana; + Gitana = window.Gitana; Gitana.WorkflowModel = Gitana.AbstractPlatformObject.extend( /** @lends Gitana.WorkflowModel.prototype */ @@ -12,7 +12,7 @@ * @class WorkflowModel * * @param {Gitana.Platform} platform - * @param [Object] object json object (if no callback required for populating) + * @param {Object} object json object (if no callback required for populating) */ constructor: function(platform, object) { @@ -48,7 +48,7 @@ /** * Update the workflow model. * - * @param [string] force whether to force the update if the model is already deployed + * @param {String} force whether to force the update if the model is already deployed * * @chained this * @@ -56,16 +56,16 @@ */ update: function(force) { - var self = this; + const self = this; - var params = {}; + const params = {}; if (force) { params.force = true; } - var uriFunction = function() + const uriFunction = function() { return self.getUri(); }; @@ -80,9 +80,9 @@ */ deploy: function() { - var self = this; + const self = this; - var uriFunction = function() + const uriFunction = function() { return self.getUri() + "/deploy"; }; @@ -97,9 +97,9 @@ */ undeploy: function() { - var self = this; + const self = this; - var uriFunction = function() + const uriFunction = function() { return self.getUri() + "/undeploy"; }; diff --git a/js/gitana/platform/WorkflowModelMap.js b/js/gitana/platform/WorkflowModelMap.js index e6877bfb..f110f4b7 100644 --- a/js/gitana/platform/WorkflowModelMap.js +++ b/js/gitana/platform/WorkflowModelMap.js @@ -1,6 +1,6 @@ (function(window) { - var Gitana = window.Gitana; + Gitana = window.Gitana; Gitana.WorkflowModelMap = Gitana.AbstractPlatformObjectMap.extend( /** @lends Gitana.WorkflowModelMap.prototype */ @@ -12,7 +12,7 @@ * @class Map of workflow models * * @param {Gitana.Platform} platform Gitana platform instance. - * @param [Object] object + * @param {Object} object */ constructor: function(platform, object) { diff --git a/js/gitana/platform/WorkflowTask.js b/js/gitana/platform/WorkflowTask.js index 867626d5..cf0d8e1a 100644 --- a/js/gitana/platform/WorkflowTask.js +++ b/js/gitana/platform/WorkflowTask.js @@ -1,6 +1,6 @@ (function(window) { - var Gitana = window.Gitana; + Gitana = window.Gitana; Gitana.WorkflowTask = Gitana.AbstractPlatformObject.extend( /** @lends Gitana.WorkflowTask.prototype */ @@ -12,7 +12,7 @@ * @class WorkflowTask * * @param {Gitana.Platform} platform - * @param [Object] object json object (if no callback required for populating) + * @param {Object} object json object (if no callback required for populating) */ constructor: function(platform, object) { @@ -27,7 +27,7 @@ this.toResourceId = function(resourceOrResourceId) { - var id = resourceOrResourceId; + let id = resourceOrResourceId; if (resourceOrResourceId && resourceOrResourceId.getId) { @@ -70,7 +70,7 @@ loadResourceList: function(callback) { - var uriFunction = function() + const uriFunction = function() { return this.getUri() + "/resources"; }; @@ -82,7 +82,7 @@ loadResource: function(id, callback) { - var uriFunction = function() + const uriFunction = function() { return this.getUri() + "/resources/" + id; }; @@ -94,14 +94,14 @@ addResource: function(resource) { - var uriFunction = function() + const uriFunction = function() { return this.getUri() + "/resources/add"; }; - var reference = this.toReference(resource); + const reference = this.toReference(resource); - var params = { + const params = { "reference": reference }; @@ -110,9 +110,9 @@ removeResource: function(resourceOrResourceId) { - var uriFunction = function() + const uriFunction = function() { - var resourceId = this.toResourceId(resourceOrResourceId); + const resourceId = this.toResourceId(resourceOrResourceId); return this.getUri() + "/resources/" + resourceId + "/remove"; }; @@ -122,7 +122,7 @@ removeAllResources: function() { - var uriFunction = function() + const uriFunction = function() { return this.getUri() + "/resources/removeall"; }; @@ -145,12 +145,12 @@ */ claim: function() { - var uriFunction = function() + const uriFunction = function() { return this.getUri() + "/claim"; }; - var chainable = this.getFactory().workflowTask(this.getPlatform()); + const chainable = this.getFactory().workflowTask(this.getPlatform()); return this.chainPost(chainable, uriFunction, {}, {}); }, @@ -163,12 +163,12 @@ */ unclaim: function() { - var uriFunction = function() + const uriFunction = function() { return this.getUri() + "/unclaim"; }; - var chainable = this.getFactory().workflowTask(this.getPlatform()); + const chainable = this.getFactory().workflowTask(this.getPlatform()); return this.chainPost(chainable, uriFunction, {}, {}); }, @@ -183,18 +183,18 @@ */ delegate: function(user) { - var userDomainQualifiedId = this.extractPrincipalDomainQualifiedId(user); + const userDomainQualifiedId = this.extractPrincipalDomainQualifiedId(user); - var uriFunction = function() + const uriFunction = function() { return this.getUri() + "/delegate"; }; - var params = { + const params = { "userId": userDomainQualifiedId }; - var chainable = this.getFactory().workflowTask(this.getPlatform()); + const chainable = this.getFactory().workflowTask(this.getPlatform()); return this.chainPost(chainable, uriFunction, params, {}); }, @@ -203,26 +203,26 @@ * * @chained principal map * - * @param [Pagination] pagination pagination (optional) + * @param {Object} pagination pagination (optional) */ listDelegates: function(pagination) { - var self = this; + const self = this; // prepare params (with pagination) - var params = {}; + const params = {}; if (pagination) { Gitana.copyInto(params, pagination); } - var uriFunction = function() + const uriFunction = function() { return self.getUri() + "/delegates"; }; // get to work - var chainable = this.getFactory().domainPrincipalMap(this); + const chainable = this.getFactory().domainPrincipalMap(this); // all groups return this.chainGet(chainable, uriFunction, params); @@ -240,16 +240,16 @@ */ complete: function(routeId, data) { - var uriFunction = function() + const uriFunction = function() { return this.getUri() + "/complete"; }; - var params = { + const params = { "routeId": routeId }; - var chainable = this.getFactory().workflowTask(this.getPlatform()); + const chainable = this.getFactory().workflowTask(this.getPlatform()); return this.chainPost(chainable, uriFunction, params, data); }, @@ -266,22 +266,22 @@ */ move: function(workflowNodeId, data) { - var uriFunction = function() + const uriFunction = function() { return this.getUri() + "/move"; }; - var params = { + const params = { "id": workflowNodeId }; - var chainable = this.getFactory().workflowTask(this.getPlatform()); + const chainable = this.getFactory().workflowTask(this.getPlatform()); return this.chainPost(chainable, uriFunction, params, data); }, loadRoutes: function(callback) { - var uriFunction = function() + const uriFunction = function() { return this.getUri() + "/routes"; }; diff --git a/js/gitana/platform/WorkflowTaskMap.js b/js/gitana/platform/WorkflowTaskMap.js index 47b6f280..77b48564 100644 --- a/js/gitana/platform/WorkflowTaskMap.js +++ b/js/gitana/platform/WorkflowTaskMap.js @@ -1,6 +1,6 @@ (function(window) { - var Gitana = window.Gitana; + Gitana = window.Gitana; Gitana.WorkflowTaskMap = Gitana.AbstractPlatformObjectMap.extend( /** @lends Gitana.WorkflowTaskMap.prototype */ @@ -12,7 +12,7 @@ * @class Map of workflow tasks * * @param {Gitana.Platform} platform Gitana platform instance. - * @param [Object] object + * @param {Object} object */ constructor: function(platform, object) { diff --git a/js/gitana/platform/extends/ClientMethods.js b/js/gitana/platform/extends/ClientMethods.js index 5a435628..4fe1e803 100644 --- a/js/gitana/platform/extends/ClientMethods.js +++ b/js/gitana/platform/extends/ClientMethods.js @@ -1,6 +1,6 @@ (function(window) { - var Gitana = window.Gitana; + Gitana = window.Gitana; Gitana.ClientMethods = { diff --git a/js/gitana/registrar/AbstractRegistrarObject.js b/js/gitana/registrar/AbstractRegistrarObject.js index fee8543c..d98ecd57 100644 --- a/js/gitana/registrar/AbstractRegistrarObject.js +++ b/js/gitana/registrar/AbstractRegistrarObject.js @@ -1,6 +1,6 @@ (function(window) { - var Gitana = window.Gitana; + Gitana = window.Gitana; Gitana.AbstractRegistrarObject = Gitana.AbstractPlatformObject.extend( /** @lends Gitana.AbstractRegistrarObject.prototype */ @@ -12,7 +12,7 @@ * @class AbstractRegistrarObject * * @param {Gitana.Registrar} registrar - * @param [Object] object json object (if no callback required for populating) + * @param {Object} object json object (if no callback required for populating) */ constructor: function(registrar, object) { diff --git a/js/gitana/registrar/Meter.js b/js/gitana/registrar/Meter.js index a4fcac5e..a2ade8dd 100644 --- a/js/gitana/registrar/Meter.js +++ b/js/gitana/registrar/Meter.js @@ -1,6 +1,6 @@ (function(window) { - var Gitana = window.Gitana; + Gitana = window.Gitana; Gitana.Meter = Gitana.AbstractRegistrarObject.extend( /** @lends Gitana.Meter.prototype */ @@ -12,7 +12,7 @@ * @class Meter * * @param {Gitana.Registrar} registrar - * @param [Object] object json object (if no callback required for populating) + * @param {Object} object json object (if no callback required for populating) */ constructor: function(registrar, object) { diff --git a/js/gitana/registrar/MeterMap.js b/js/gitana/registrar/MeterMap.js index ba1537de..2792a232 100644 --- a/js/gitana/registrar/MeterMap.js +++ b/js/gitana/registrar/MeterMap.js @@ -1,6 +1,6 @@ (function(window) { - var Gitana = window.Gitana; + Gitana = window.Gitana; Gitana.MeterMap = Gitana.AbstractPlatformObjectMap.extend( /** @lends Gitana.MeterMap.prototype */ diff --git a/js/gitana/registrar/Plan.js b/js/gitana/registrar/Plan.js index 7b710929..1fd14267 100644 --- a/js/gitana/registrar/Plan.js +++ b/js/gitana/registrar/Plan.js @@ -1,6 +1,6 @@ (function(window) { - var Gitana = window.Gitana; + Gitana = window.Gitana; Gitana.Plan = Gitana.AbstractRegistrarObject.extend( /** @lends Gitana.Plan.prototype */ @@ -12,7 +12,7 @@ * @class Plan * * @param {Gitana.Registrar} registrar - * @param [Object] object json object (if no callback required for populating) + * @param {Object} object json object (if no callback required for populating) */ constructor: function(registrar, object) { diff --git a/js/gitana/registrar/PlanMap.js b/js/gitana/registrar/PlanMap.js index f6399aca..67c19c7a 100644 --- a/js/gitana/registrar/PlanMap.js +++ b/js/gitana/registrar/PlanMap.js @@ -1,6 +1,6 @@ (function(window) { - var Gitana = window.Gitana; + Gitana = window.Gitana; Gitana.PlanMap = Gitana.AbstractPlatformObjectMap.extend( /** @lends Gitana.PlanMap.prototype */ diff --git a/js/gitana/registrar/Registrar.js b/js/gitana/registrar/Registrar.js index 7c4ccc99..34fafbce 100644 --- a/js/gitana/registrar/Registrar.js +++ b/js/gitana/registrar/Registrar.js @@ -1,6 +1,6 @@ (function(window) { - var Gitana = window.Gitana; + Gitana = window.Gitana; Gitana.Registrar = Gitana.AbstractPlatformDataStore.extend( /** @lends Gitana.Registrar.prototype */ @@ -12,7 +12,7 @@ * @class Registrar * * @param {Gitana.Platform} platform - * @param [Object] object json object (if no callback required for populating) + * @param {Object} object json object (if no callback required for populating) */ constructor: function(platform, object) { @@ -59,25 +59,25 @@ * * @chained tenant map * - * @param [Object] pagination pagination (optional) + * @param {Object} pagination pagination (optional) */ listTenants: function(pagination) { - var self = this; + const self = this; - var uriFunction = function() + const uriFunction = function() { return self.getUri() + "/tenants"; }; // prepare params (with pagination) - var params = {}; + const params = {}; if (pagination) { Gitana.copyInto(params, pagination); } - var chainable = this.getFactory().tenantMap(this); + const chainable = this.getFactory().tenantMap(this); return this.chainGet(chainable, uriFunction, params); }, @@ -87,21 +87,21 @@ * @chained tenant map * * @param {Object} query Query for finding a tenant. - * @param [Object] pagination pagination (optional) + * @param {Object} pagination pagination (optional) */ queryTenants: function(query, pagination) { - var self = this; + const self = this; - var uriFunction = function() + const uriFunction = function() { return self.getUri() + "/tenants/query"; }; - var chainable = this.getFactory().tenantMap(this); + const chainable = this.getFactory().tenantMap(this); // prepare params (with pagination) - var params = {}; + const params = {}; if (pagination) { Gitana.copyInto(params, pagination); @@ -119,14 +119,14 @@ */ readTenant: function(tenantId) { - var self = this; + const self = this; - var uriFunction = function() + const uriFunction = function() { return self.getUri() + "/tenants/" + tenantId; }; - var chainable = this.getFactory().tenant(this); + const chainable = this.getFactory().tenant(this); return this.chainGet(chainable, uriFunction); }, @@ -139,14 +139,14 @@ */ lookupTenantForPrincipal: function(principal) { - var self = this; + const self = this; - var uriFunction = function() + const uriFunction = function() { return self.getUri() + "/tenants/lookup?id=" + principal.getDomainQualifiedId(); }; - var chainable = this.getFactory().tenant(this); + const chainable = this.getFactory().tenant(this); return this.chainGet(chainable, uriFunction); }, @@ -157,19 +157,19 @@ * * @param {Gitana.DomainPrincipal} principal * @param {String} planKey - * @param [Object] payment method (required if plan requires a payment method) + * @param {Object} paymentMethod method (required if plan requires a payment method) */ createTenant: function(principal, planKey, paymentMethod) { - var self = this; + const self = this; - var uriFunction = function() + const uriFunction = function() { return self.getUri() + "/tenants"; }; // set up object - var object = {}; + const object = {}; object["principalId"] = principal.getId(); object["domainId"] = principal.getDomainId(); object["planKey"] = planKey; @@ -179,7 +179,7 @@ } // create - var chainable = this.getFactory().tenant(this); + const chainable = this.getFactory().tenant(this); return this.chainCreate(chainable, object, uriFunction); }, @@ -212,14 +212,14 @@ */ checkTenantPermissions: function(checks, callback) { - var self = this; + const self = this; - var uriFunction = function() + const uriFunction = function() { return self.getUri() + "/tenants/permissions/check"; }; - var object = { + const object = { "checks": checks }; @@ -255,14 +255,14 @@ */ checkTenantAuthorities: function(checks, callback) { - var self = this; + const self = this; - var uriFunction = function() + const uriFunction = function() { return self.getUri() + "/tenants/authorities/check"; }; - var object = { + const object = { "checks": checks }; @@ -286,25 +286,25 @@ * * @chained plan map * - * @param [Object] pagination pagination (optional) + * @param {Object} pagination pagination (optional) */ listPlans: function(pagination) { - var self = this; + const self = this; - var uriFunction = function() + const uriFunction = function() { return self.getUri() + "/plans"; }; // prepare params (with pagination) - var params = {}; + const params = {}; if (pagination) { Gitana.copyInto(params, pagination); } - var chainable = this.getFactory().planMap(this); + const chainable = this.getFactory().planMap(this); return this.chainGet(chainable, uriFunction, params); }, @@ -314,21 +314,21 @@ * @chained plan map * * @param {Object} query Query for finding a tenant. - * @param [Object] pagination pagination (optional) + * @param {Object} pagination pagination (optional) */ queryPlans: function(query, pagination) { - var self = this; + const self = this; - var uriFunction = function() + const uriFunction = function() { return self.getUri() + "/plans/query"; }; - var chainable = this.getFactory().planMap(this); + const chainable = this.getFactory().planMap(this); // prepare params (with pagination) - var params = {}; + const params = {}; if (pagination) { Gitana.copyInto(params, pagination); @@ -346,14 +346,14 @@ */ readPlan: function(planId) { - var self = this; + const self = this; - var uriFunction = function() + const uriFunction = function() { return self.getUri() + "/plans/" + planId; }; - var chainable = this.getFactory().plan(this); + const chainable = this.getFactory().plan(this); return this.chainGet(chainable, uriFunction); }, @@ -362,18 +362,18 @@ * * @chained plan * - * @param [Object] object JSON object + * @param {Object} object JSON object */ createPlan: function(object) { - var self = this; + const self = this; - var uriFunction = function() + const uriFunction = function() { return self.getUri() + "/plans"; }; - var chainable = this.getFactory().plan(this); + const chainable = this.getFactory().plan(this); return this.chainCreate(chainable, object, uriFunction); }, @@ -406,14 +406,14 @@ */ checkPlanPermissions: function(checks, callback) { - var self = this; + const self = this; - var uriFunction = function() + const uriFunction = function() { return self.getUri() + "/plans/permissions/check"; }; - var object = { + const object = { "checks": checks }; @@ -449,14 +449,14 @@ */ checkPlanAuthorities: function(checks, callback) { - var self = this; + const self = this; - var uriFunction = function() + const uriFunction = function() { return self.getUri() + "/plans/authorities/check"; }; - var object = { + const object = { "checks": checks }; @@ -479,25 +479,25 @@ * * @chained meter map * - * @param [Object] pagination pagination (optional) + * @param {Object} pagination pagination (optional) */ listMeters: function(pagination) { - var self = this; + const self = this; - var uriFunction = function() + const uriFunction = function() { return self.getUri() + "/meters"; }; // prepare params (with pagination) - var params = {}; + const params = {}; if (pagination) { Gitana.copyInto(params, pagination); } - var chainable = this.getFactory().meterMap(this); + const chainable = this.getFactory().meterMap(this); return this.chainGet(chainable, uriFunction, params); }, @@ -507,21 +507,21 @@ * @chained meter map * * @param {Object} query Query for finding a tenant. - * @param [Object] pagination pagination (optional) + * @param {Object} pagination pagination (optional) */ queryMeters: function(query, pagination) { - var self = this; + const self = this; - var uriFunction = function() + const uriFunction = function() { return self.getUri() + "/meters/query"; }; - var chainable = this.getFactory().meterMap(this); + const chainable = this.getFactory().meterMap(this); // prepare params (with pagination) - var params = {}; + const params = {}; if (pagination) { Gitana.copyInto(params, pagination); @@ -539,14 +539,14 @@ */ readMeter: function(meterId) { - var self = this; + const self = this; - var uriFunction = function() + const uriFunction = function() { return self.getUri() + "/meters/" + meterId; }; - var chainable = this.getFactory().meter(this); + const chainable = this.getFactory().meter(this); return this.chainGet(chainable, uriFunction); }, @@ -555,18 +555,18 @@ * * @chained meter * - * @param [Object] object JSON object + * @param {Object} object JSON object */ createMeter: function(object) { - var self = this; + const self = this; - var uriFunction = function() + const uriFunction = function() { return self.getUri() + "/meters"; }; - var chainable = this.getFactory().meter(this); + const chainable = this.getFactory().meter(this); return this.chainCreate(chainable, object, uriFunction); }, @@ -599,14 +599,14 @@ */ checkMeterPermissions: function(checks, callback) { - var self = this; + const self = this; - var uriFunction = function() + const uriFunction = function() { return self.getUri() + "/meters/permissions/check"; }; - var object = { + const object = { "checks": checks }; @@ -642,14 +642,14 @@ */ checkMeterAuthorities: function(checks, callback) { - var self = this; + const self = this; - var uriFunction = function() + const uriFunction = function() { return self.getUri() + "/meters/authorities/check"; }; - var object = { + const object = { "checks": checks }; diff --git a/js/gitana/registrar/RegistrarMap.js b/js/gitana/registrar/RegistrarMap.js index fb2193e4..e7386586 100644 --- a/js/gitana/registrar/RegistrarMap.js +++ b/js/gitana/registrar/RegistrarMap.js @@ -1,6 +1,6 @@ (function(window) { - var Gitana = window.Gitana; + Gitana = window.Gitana; Gitana.RegistrarMap = Gitana.AbstractPlatformObjectMap.extend( /** @lends Gitana.RegistrarMap.prototype */ diff --git a/js/gitana/registrar/Tenant.js b/js/gitana/registrar/Tenant.js index cba327f1..3254b21b 100644 --- a/js/gitana/registrar/Tenant.js +++ b/js/gitana/registrar/Tenant.js @@ -1,6 +1,6 @@ (function(window) { - var Gitana = window.Gitana; + Gitana = window.Gitana; Gitana.Tenant = Gitana.AbstractRegistrarObject.extend( /** @lends Gitana.Tenant.prototype */ @@ -12,7 +12,7 @@ * @class Tenant * * @param {Gitana.Registrar} registrar - * @param [Object] object json object (if no callback required for populating) + * @param {Object} object json object (if no callback required for populating) */ constructor: function(registrar, object) { @@ -92,14 +92,14 @@ */ readTenantPlan: function() { - var self = this; + const self = this; - var uriFunction = function() + const uriFunction = function() { return self.getPlatform().getUri() + "/registrars/" + self.getRegistrarId() + "/plans/" + self.getPlanKey(); }; - var chainable = this.getFactory().plan(this.getRegistrar()); + const chainable = this.getFactory().plan(this.getRegistrar()); return this.chainGet(chainable, uriFunction); }, @@ -110,19 +110,19 @@ */ readTenantPrincipal: function() { - var self = this; + const self = this; - var uriFunction = function() + const uriFunction = function() { return self.getPlatform().getUri() + "/domains/" + self.getPrincipalDomainId() + "/principals/" + self.getPrincipalId(); }; // TODO - this is a pretty big hack at the moment - var domain = this.getFactory().domain(this.getPlatform(), { + const domain = this.getFactory().domain(this.getPlatform(), { "_doc": this.getPrincipalDomainId() }); - var chainable = this.getFactory().domainPrincipal(domain); + const chainable = this.getFactory().domainPrincipal(domain); return this.chainGet(chainable, uriFunction); }, @@ -200,15 +200,15 @@ */ listAllocatedObjects: function(callback, objectType, pagination) { - var self = this; + const self = this; - var uriFunction = function() + const uriFunction = function() { return self.getUri() + "/objects"; }; // parameters - var params = {}; + const params = {}; if (pagination) { Gitana.copyInto(params, pagination); @@ -272,16 +272,16 @@ */ readDefaultAllocatedClientObject: function(callback) { - var self = this; + const self = this; - var uriFunction = function() + const uriFunction = function() { return self.getUri() + "/defaultclient"; }; return this.chainGetResponse(this, uriFunction, {}).then(function(response) { - var client = {}; + const client = {}; Gitana.copyInto(client, response); Gitana.stampInto(client, Gitana.ClientMethods); client.get = function(key) { return this[key]; }; @@ -300,15 +300,15 @@ */ listAutoClientMappingObjects: function(callback, pagination) { - var self = this; + const self = this; - var uriFunction = function() + const uriFunction = function() { return self.getUri() + "/autoclientmappings"; }; // parameters - var params = {}; + const params = {}; if (pagination) { Gitana.copyInto(params, pagination); diff --git a/js/gitana/registrar/TenantMap.js b/js/gitana/registrar/TenantMap.js index 22cd9b41..e1546a64 100644 --- a/js/gitana/registrar/TenantMap.js +++ b/js/gitana/registrar/TenantMap.js @@ -1,6 +1,6 @@ (function(window) { - var Gitana = window.Gitana; + Gitana = window.Gitana; Gitana.TenantMap = Gitana.AbstractPlatformObjectMap.extend( /** @lends Gitana.TenantMap.prototype */ diff --git a/js/gitana/repository/AbstractNode.js b/js/gitana/repository/AbstractNode.js index e5c34b0b..c3c96541 100644 --- a/js/gitana/repository/AbstractNode.js +++ b/js/gitana/repository/AbstractNode.js @@ -1,6 +1,6 @@ (function(window) { - var Gitana = window.Gitana; + Gitana = window.Gitana; Gitana.AbstractNode = Gitana.AbstractRepositoryObject.extend( /** @lends Gitana.AbstractNode.prototype */ @@ -19,7 +19,7 @@ // helper methods for system-managed state this.__qname = (function() { - var _qname = null; + let _qname = null; return function(qname) { if (!Gitana.isUndefined(qname)) { _qname = qname; } return _qname; @@ -27,7 +27,7 @@ })(); this.__type = (function() { - var _type = null; + let _type = null; return function(type) { if (!Gitana.isUndefined(type)) { _type = type; } return _type; @@ -35,7 +35,7 @@ })(); this.__features = (function() { - var _features = {}; + let _features = {}; return function(features) { if (!Gitana.isUndefined(features)) { _features = features; } return _features; @@ -43,7 +43,7 @@ })(); this.__stats = (function() { - var _stats = {}; + let _stats = {}; return function(stats) { if (!Gitana.isUndefined(stats)) { _stats = stats; } return _stats; @@ -51,7 +51,7 @@ })(); this.__is_association = (function() { - var _is_association = false; + let _is_association = false; return function(is_association) { if (!Gitana.isUndefined(is_association)) { _is_association = is_association; } return _is_association; @@ -122,7 +122,7 @@ // strip out "_qname" if (this["_qname"]) { - var _qname = this["_qname"]; + const _qname = this["_qname"]; delete this["_qname"]; this.__qname(_qname); } @@ -130,7 +130,7 @@ // strip out "_type" if (this["_type"]) { - var _type = this["_type"]; + const _type = this["_type"]; delete this["_type"]; this.__type(_type); } @@ -138,15 +138,15 @@ // strip out "_features" if (this["_features"]) { - var _features = this["_features"]; + const _features = this["_features"]; delete this["_features"]; this.__features(_features); } // strip out "_statistics" - if (this["_statistics"] && typeof(this["_statistics"]) == "object") + if (this["_statistics"] && typeof(this["_statistics"]) === "object") { - var stats = this["_statistics"]; + const stats = this["_statistics"]; delete this["_statistics"]; this.__stats(stats); } @@ -154,7 +154,7 @@ // strip out "_is_association" if (!Gitana.isUndefined(this["_is_association"])) { - var _is_association = this["_is_association"]; + const _is_association = this["_is_association"]; delete this["_is_association"]; this.__is_association(_is_association); } @@ -212,18 +212,18 @@ * * @public * - * @param [Function] callback optional callback + * @param {Function} callback optional callback * * @returns {Array} An array of strings that are the ids of the features. */ getFeatureIds: function(callback) { - var self = this; + const self = this; - var f = function() + const f = function() { - var featureIds = []; - for (var featureId in this.__features()) { + const featureIds = []; + for (const featureId in this.__features()) { featureIds[featureIds.length] = featureId; } @@ -247,13 +247,13 @@ * @public * * @param {String} featureId the id of the feature - * @param [Function] callback optional callback + * @param {Function} callback optional callback * * @returns {Object} the JSON object configuration for the feature */ getFeature: function(featureId, callback) { - var self = this; + const self = this; if (callback) { @@ -274,9 +274,9 @@ */ removeFeature: function(featureId) { - var self = this; + const self = this; - var uriFunction = function() + const uriFunction = function() { return self.getUri() + "/features/" + featureId; }; @@ -291,13 +291,13 @@ * * @public * @param {String} featureId the id of the feature - * @param [Object] featureConfig the JSON object configuration for the feature + * @param {Object} featureConfig the JSON object configuration for the feature */ addFeature: function(featureId, featureConfig) { - var self = this; + const self = this; - var uriFunction = function() + const uriFunction = function() { return self.getUri() + "/features/" + featureId; }; @@ -317,17 +317,17 @@ * @public * * @param {String} featureId the id of the feature - * @param [Function] callback optional callback to receive result (for chaining) + * @param {Function} callback optional callback to receive result (for chaining) * * @returns {Boolean} whether this node has this feature */ - hasFeature: function(featureId, callback) + hasFeature: function(featureId, callback = undefined) { if (callback) { return this.then(function() { - var hasFeature = !Gitana.isEmpty(this.__features()[featureId]); + const hasFeature = !Gitana.isEmpty(this.__features()[featureId]); callback.call(this, hasFeature); }); @@ -369,9 +369,9 @@ */ touch: function() { - var self = this; + const self = this; - var uriFunction = function() + const uriFunction = function() { return self.getUri() + "/touch"; }; @@ -425,9 +425,9 @@ */ changeTypeQName: function(typeQName) { - var self = this; + const self = this; - var uriFunction = function() + const uriFunction = function() { return self.getUri() + "/change_type?type=" + typeQName; }; @@ -462,13 +462,13 @@ * Sets the QName of this node. * * @public - * @param {String} typeQName the qname of the type to change to + * @param {String} qname the qname of the type to change to */ changeQName: function(qname) { - var self = this; + const self = this; - var uriFunction = function() + const uriFunction = function() { return self.getUri() + "/change_qname?qname=" + qname; }; @@ -533,11 +533,11 @@ */ attach: function(attachmentId, contentType, data, filename) { - var paramsFunction = function(params) { + const paramsFunction = function(params) { if (filename) { params["filename"] = filename; } }; - var delegate = Gitana.Methods.attach.call(this, Gitana.NodeAttachment, paramsFunction); + const delegate = Gitana.Methods.attach.call(this, Gitana.NodeAttachment, paramsFunction); return delegate.call(this, attachmentId, contentType, data); }, diff --git a/js/gitana/repository/AbstractRepositoryObject.js b/js/gitana/repository/AbstractRepositoryObject.js index c362d299..2b63c858 100644 --- a/js/gitana/repository/AbstractRepositoryObject.js +++ b/js/gitana/repository/AbstractRepositoryObject.js @@ -1,6 +1,6 @@ (function(window) { - var Gitana = window.Gitana; + Gitana = window.Gitana; Gitana.AbstractRepositoryObject = Gitana.AbstractPlatformObject.extend( /** @lends Gitana.AbstractRepositoryObject.prototype */ @@ -11,7 +11,7 @@ * * @class Abstract base class for Gitana Node implementations. * - * @param {Gitana.Branch} branch + * @param {Gitana.Branch} repository * @param {Object} [object] */ constructor: function(repository, object) diff --git a/js/gitana/repository/Association.js b/js/gitana/repository/Association.js index fe7f11ba..19b621d4 100644 --- a/js/gitana/repository/Association.js +++ b/js/gitana/repository/Association.js @@ -1,6 +1,6 @@ (function(window) { - var Gitana = window.Gitana; + Gitana = window.Gitana; Gitana.Association = Gitana.AbstractNode.extend( /** @lends Gitana.Association.prototype */ @@ -12,7 +12,7 @@ * @class Association * * @param {Gitana.Branch} branch - * @param [Object] object json object (if no callback required for populating) + * @param {Object} object json object (if no callback required for populating) */ constructor: function(branch, object) { @@ -126,12 +126,12 @@ */ readSourceNode: function() { - var self = this; + const self = this; - var result = this.subchain(this.getFactory().node(this.getBranch())); + const result = this.subchain(this.getFactory().node(this.getBranch())); return result.then(function() { - var chain = this; + const chain = this; this.subchain(self.getBranch()).readNode(self.getSourceNodeId()).then(function() { chain.loadFrom(this); @@ -148,12 +148,12 @@ */ readTargetNode: function() { - var self = this; + const self = this; - var result = this.subchain(this.getFactory().node(this.getBranch())); + const result = this.subchain(this.getFactory().node(this.getBranch())); return result.then(function() { - var chain = this; + const chain = this; this.subchain(self.getBranch()).readNode(self.getTargetNodeId()).then(function() { chain.loadFrom(this); @@ -172,9 +172,9 @@ */ readOtherNode: function(node) { - var self = this; + const self = this; - var nodeId = null; + let nodeId = null; if (Gitana.isString(node)) { @@ -185,20 +185,20 @@ nodeId = node.getId(); } - var result = this.subchain(this.getFactory().node(this.getBranch())); + const result = this.subchain(this.getFactory().node(this.getBranch())); result.then(function() { - var chain = this; + const chain = this; this.subchain(self).then(function() { - if (nodeId == this.getSourceNodeId()) + if (nodeId === this.getSourceNodeId()) { this.readTargetNode().then(function() { chain.loadFrom(this); }); } - else if (nodeId == this.getTargetNodeId()) + else if (nodeId === this.getTargetNodeId()) { this.readSourceNode().then(function() { chain.loadFrom(this); @@ -206,7 +206,7 @@ } else { - var err = new Gitana.Error(); + const err = new Gitana.Error(); err.name = "No node on association"; err.message = "The node: " + nodeId + " was not found on this association"; @@ -237,7 +237,7 @@ */ getDirection: function(node) { - var nodeId = null; + let nodeId = null; if (Gitana.isString(node)) { @@ -248,19 +248,19 @@ nodeId = node.getId(); } - var direction = null; + let direction = null; - if (this.getDirectionality() == "UNDIRECTED") + if (this.getDirectionality() === "UNDIRECTED") { direction = "MUTUAL"; } else { - if (this.getSourceNodeId() == nodeId) + if (this.getSourceNodeId() === nodeId) { direction = "OUTGOING"; } - else if (this.getTargetNodeId() == nodeId) + else if (this.getTargetNodeId() === nodeId) { direction = "INCOMING"; } @@ -280,7 +280,7 @@ */ getOtherNodeId: function(node) { - var nodeId = null; + let nodeId = null; if (Gitana.isString(node)) { @@ -291,13 +291,13 @@ nodeId = node.getId(); } - var otherNodeId = null; + let otherNodeId = null; - if (this.getSourceNodeId() == nodeId) + if (this.getSourceNodeId() === nodeId) { otherNodeId = this.getTargetNodeId(); } - else if (this.getTargetNodeId() == nodeId) + else if (this.getTargetNodeId() === nodeId) { otherNodeId = this.getSourceNodeId(); } diff --git a/js/gitana/repository/Branch.js b/js/gitana/repository/Branch.js index 7f07f957..99c409c3 100644 --- a/js/gitana/repository/Branch.js +++ b/js/gitana/repository/Branch.js @@ -1,1584 +1,1445 @@ -(function(window) -{ - var Gitana = window.Gitana; +(function (window) { + Gitana = window.Gitana; Gitana.Branch = Gitana.AbstractRepositoryObject.extend( - /** @lends Gitana.Branch.prototype */ - { - /** - * @constructs - * @augments Gitana.AbstractRepositoryObject - * - * @class Branch - * - * @param {Gitana.Repository} repository - * @param [Object] object json object (if no callback required for populating) - */ - constructor: function(repository, object) + /** @lends Gitana.Branch.prototype */ { - this.base(repository, object); - - this.objectType = function() { return "Gitana.Branch"; }; - }, - - /** - * @OVERRIDE - */ - getType: function() - { - return Gitana.TypedIDConstants.TYPE_BRANCH; - }, - - /** - * @OVERRIDE - */ - getUri: function() - { - return "/repositories/" + this.getRepositoryId() + "/branches/" + this.getId(); - }, - - /** - * @override - */ - clone: function() - { - return this.getFactory().branch(this.getRepository(), this); - }, - - /** - * @returns {Boolean} whether this is the master branch - */ - isMaster: function() - { - return (this.getBranchType().toLowerCase() == "master"); - }, - - /** - * @return {String} the type of branch ("master" or "custom") - */ - getBranchType: function() - { - return this.get("type"); - }, - - /** - * @return {String} the tip changeset of the branch - */ - getTip: function() - { - return this.get("tip"); - }, - - /** - * Acquires a list of mount nodes under the root of the repository. - * - * @chained node map - * - * @public - * - * @param [Object] pagination - */ - listMounts: function(pagination) - { - var self = this; + /** + * @constructs + * @augments Gitana.AbstractRepositoryObject + * + * @class Branch + * + * @param {Gitana.Repository} repository + * @param {Object} object json object (if no callback required for populating) + */ + constructor: function (repository, object) { + this.base(repository, object); + + this.objectType = function () { + return 'Gitana.Branch'; + }; + }, + + /** + * @OVERRIDE + */ + getType: function () { + return Gitana.TypedIDConstants.TYPE_BRANCH; + }, + + /** + * @OVERRIDE + */ + getUri: function () { + return '/repositories/' + this.getRepositoryId() + '/branches/' + this.getId(); + }, + + /** + * @override + */ + clone: function () { + return this.getFactory().branch(this.getRepository(), this); + }, + + /** + * @returns {Boolean} whether this is the master branch + */ + isMaster: function () { + return (this.getBranchType().toLowerCase() === 'master'); + }, + + /** + * @return {String} the type of branch ("master" or "custom") + */ + getBranchType: function () { + return this.get('type'); + }, + + /** + * @return {String} the tip changeset of the branch + */ + getTip: function () { + return this.get('tip'); + }, + + /** + * Acquires a list of mount nodes under the root of the repository. + * + * @chained node map + * + * @public + * + * @param {Object} pagination + */ + listMounts: function (pagination) { + const self = this; + + const params = {}; + if (pagination) { + Gitana.copyInto(params, pagination); + } - var params = {}; - if (pagination) - { - Gitana.copyInto(params, pagination); - } + const uriFunction = function () { + return self.getUri() + '/nodes'; + }; - var uriFunction = function() - { - return self.getUri() + "/nodes"; - }; - - var chainable = this.getFactory().nodeMap(this); - return this.chainGet(chainable, uriFunction, params); - }, - - /** - * Reads a node. - * - * @chained node - * - * @public - * - * @param {String} nodeId the node id - * @param [String] offset path - * @param [String] params - */ - readNode: function(nodeId, path, params) - { - var self = this; - - var uriFunction = function() - { - return self.getUri() + "/nodes/" + nodeId; - }; + const chainable = this.getFactory().nodeMap(this); + return this.chainGet(chainable, uriFunction, params); + }, + + /** + * Reads a node. + * + * @chained node + * + * @public + * + * @param {String} nodeId the node id + * @param {String} path offset + * @param {Object} params + */ + readNode: function (nodeId, path = undefined, params = {}) { + const self = this; + + const uriFunction = function () { + return self.getUri() + '/nodes/' + nodeId; + }; - params = params || {}; + if (path) { + params.path = path; + } - if (path) { - params.path = path; - } + const chainable = this.getFactory().node(this); + return this.chainGet(chainable, uriFunction, params); + }, + + /** + * Reads the root node. + * + * @chained node + * + * @public + */ + rootNode: function () { + return this.readNode('root'); + }, + + /** + * Create a node + * + * @chained node + * + * @public + * + * @param {Object} object JSON object + * @param {Object|String} options a JSON object providing the configuration for the create operation. + * If a string, must follow format (/) + */ + createNode: function (object, options = undefined) { + const self = this; + + const uriFunction = function () { + return self.getUri() + '/nodes'; + }; - var chainable = this.getFactory().node(this); - return this.chainGet(chainable, uriFunction, params); - }, - - /** - * Reads the root node. - * - * @chained node - * - * @public - */ - rootNode: function() - { - return this.readNode("root"); - }, - - /** - * Create a node - * - * @chained node - * - * @public - * - * @param [Object] object JSON object - * @param [Object|String] options a JSON object providing the configuration for the create operation. - * If a string, must follow format (/) - */ - createNode: function(object, options) - { - var self = this; - - var uriFunction = function() - { - return self.getUri() + "/nodes"; - }; - - var params = {}; - - if (options) - { - var rootNodeId = "root"; // default - var associationType = "a:child"; // default - var filePath = null; - var parentFolderPath = null; - var fileName = null; - - // if they pass in a string instead of an options object, then the string can follow the format - // (/root/pages/file.txt) where root is the root node to start from - if (typeof(options) === "string") - { - var rootPrefixedFilePath = options; - - // filePath should not start with "/" - if (Gitana.startsWith(rootPrefixedFilePath, "/")) { - rootPrefixedFilePath = rootPrefixedFilePath.substring(1); + const params = {}; + + if (options) { + let rootNodeId = 'root'; // default + let associationType = 'a:child'; // default + let filePath = null; + let parentFolderPath = null; + let fileName = null; + + // if they pass in a string instead of an options object, then the string can follow the format + // (/root/pages/file.txt) where root is the root node to start from + if (typeof (options) === 'string') { + let rootPrefixedFilePath = options; + + // filePath should not start with "/" + if (Gitana.startsWith(rootPrefixedFilePath, '/')) { + rootPrefixedFilePath = rootPrefixedFilePath.substring(1); + } + + if (rootPrefixedFilePath === '') { + filePath = '/'; + } else { + const i = rootPrefixedFilePath.indexOf('/'); + rootNodeId = rootPrefixedFilePath.substring(0, i); + filePath = rootPrefixedFilePath.substring(i + 1); + } + } else if (typeof (options) === 'object') { + if (options.rootNodeId) { + rootNodeId = options.rootNodeId; + } + if (options.associationType) { + associationType = options.associationType; + } + if (options.fileName) { + fileName = options.fileName; + } else if (options.filename) { + fileName = options.filename; + } + if (options.parentFolderPath) { + parentFolderPath = options.parentFolderPath; + } else if (options.folderPath) { + parentFolderPath = options.folderPath; + } else if (options.folderpath) { + parentFolderPath = options.folderpath; + } + if (options.filePath) { + filePath = options.filePath; + } else if (options.filepath) { + filePath = options.filepath; + } } - if (rootPrefixedFilePath == "") { - filePath = "/"; - } else { - var i = rootPrefixedFilePath.indexOf("/"); - rootNodeId = rootPrefixedFilePath.substring(0, i); - filePath = rootPrefixedFilePath.substring(i + 1); - } - } - else if (typeof(options) === "object") - { - if (options.rootNodeId) { - rootNodeId = options.rootNodeId; - } - if (options.associationType) { - associationType = options.associationType; + // plug in the resolved params + if (rootNodeId) { + params.rootNodeId = rootNodeId; } - if (options.fileName) { - fileName = options.fileName; + if (associationType) { + params.associationType = associationType; } - else if (options.filename) { - fileName = options.filename; + if (fileName) { + params.fileName = fileName; } - if (options.parentFolderPath) { - parentFolderPath = options.parentFolderPath; + if (filePath) { + params.filePath = filePath; } - else if (options.folderPath) { - parentFolderPath = options.folderPath; + if (parentFolderPath) { + params.parentFolderPath = parentFolderPath; } - else if (options.folderpath) { - parentFolderPath = options.folderpath; - } - if (options.filePath) { - filePath = options.filePath; - } - else if (options.filepath) { - filePath = options.filepath; + + // allow custom params to be passed through + if (options.params) { + for (const param in options.params) { + params[param] = options.params[param]; + } } } - // plug in the resolved params - if (rootNodeId) { - params.rootNodeId = rootNodeId; - } - if (associationType) { - params.associationType = associationType; - } - if (fileName) { - params.fileName = fileName; - } - if (filePath) { - params.filePath = filePath; - } - if (parentFolderPath) { - params.parentFolderPath = parentFolderPath; + const chainable = this.getFactory().node(this); + return this.chainCreate(chainable, object, uriFunction, params); + }, + + /** + * Searches the branch. + * + * @chained node map + * + * Config should be: + * + * { + * "search": { + * ... Elastic Search Config Block + * } + * } + * + * For a full text term search, you can simply provide text in place of a config json object. + * + * See the Elastic Search documentation for more advanced examples + * + * @public + * + * @param search + * @param {Object} pagination + */ + searchNodes: function (search, pagination) { + const self = this; + + const params = {}; + if (pagination) { + Gitana.copyInto(params, pagination); } - // allow custom params to be passed through - if (options.params) { - for (var param in options.params) { - params[param] = options.params[param]; - } + if (Gitana.isString(search)) { + search = { + 'search': search + }; } - } - - var chainable = this.getFactory().node(this); - return this.chainCreate(chainable, object, uriFunction, params); - }, - - /** - * Searches the branch. - * - * @chained node map - * - * Config should be: - * - * { - * "search": { - * ... Elastic Search Config Block - * } - * } - * - * For a full text term search, you can simply provide text in place of a config json object. - * - * See the Elastic Search documentation for more advanced examples - * - * @public - * - * @param search - * @param [Object] pagination - */ - searchNodes: function(search, pagination) - { - var self = this; - - var params = {}; - if (pagination) - { - Gitana.copyInto(params, pagination); - } - if (Gitana.isString(search)) - { - search = { - "search": search + const uriFunction = function () { + return self.getUri() + '/nodes/search'; }; - } - var uriFunction = function() - { - return self.getUri() + "/nodes/search"; - }; - - var chainable = this.getFactory().nodeMap(this); - return this.chainPost(chainable, uriFunction, params, search); - }, - - /** - * Queries for nodes on the branch. - * - * Config should be: - * - * { - * Gitana query configs - * } - * - * @chained node map - * - * @public - * - * @param {Object} query - * @param [Object] pagination - */ - queryNodes: function(query, pagination) - { - var self = this; + const chainable = this.getFactory().nodeMap(this); + return this.chainPost(chainable, uriFunction, params, search); + }, + + /** + * Queries for nodes on the branch. + * + * Config should be: + * + * { + * Gitana query configs + * } + * + * @chained node map + * + * @public + * + * @param {Object} query + * @param {Object} pagination + */ + queryNodes: function (query, pagination = undefined) { + const self = this; + + if (!query) { + query = {}; + } - if (!query) { - query = {}; - } + const params = {}; + if (pagination) { + Gitana.copyInto(params, pagination); + } - var params = {}; - if (pagination) - { - Gitana.copyInto(params, pagination); - } + const uriFunction = function () { + return self.getUri() + '/nodes/query'; + }; - var uriFunction = function() - { - return self.getUri() + "/nodes/query"; - }; + const chainable = this.getFactory().nodeMap(this); - var chainable = this.getFactory().nodeMap(this); + if (!Gitana.PREFER_GET_OVER_POST) { + return this.chainPost(chainable, uriFunction, params, query); + } else { + Gitana.copyInto(params, { + 'query': JSON.stringify(query) + }); - if (!Gitana.PREFER_GET_OVER_POST) - { - return this.chainPost(chainable, uriFunction, params, query); - } - else - { - Gitana.copyInto(params, { - "query": JSON.stringify(query) - }); - - return this.chainGet(chainable, uriFunction, params); - } + return this.chainGet(chainable, uriFunction, params); + } - }, + }, + + /** + * Queries for a single matching node to a query on the branch. + * + * @chained node + * + * @param query + * @param errHandler + * + * @returns Gitana.Node + */ + queryOne: function (query, errHandler) { + return this.queryNodes(query).keepOne(function (err) { + if (errHandler) { + errHandler(err); + return false; + } + }); + }, + + /** + * Process a GraphQL query to the branch. + * + * @param query + * @param operationName + * @param constiables + * @param callback function(result) + * + * @returns result + */ + graphqlQuery: function (query, operationName, constiables, callback) { + const self = this; + + const params = { + query: query + }; - /** - * Queries for a single matching node to a query on the branch. - * - * @chained node - * - * @param query - * @param errHandler - * - * @returns Gitana.Node - */ - queryOne: function(query, errHandler) - { - return this.queryNodes(query).keepOne(function(err) { - if (errHandler) - { - errHandler(err); - return false; + if (constiables) { + params.constiables = constiables; } - }); - }, - - /** - * Process a GraphQL query to the branch. - * - * @param query - * @param operationName - * @param variables - * @param callback function(result) - * - * @returns result - */ - graphqlQuery: function(query, operationName, variables, callback) - { - var self = this; - var params = { - query: query - }; - - if (variables) - { - params.variables = variables; - } + if (operationName) { + params.operationName = operationName; + } - if (operationName) - { - params.operationName = operationName; - } + const uriFunction = function () { + return self.getUri() + '/graphql'; + }; - var uriFunction = function() - { - return self.getUri() + "/graphql"; - }; + if (!Gitana.PREFER_GET_OVER_POST) { + return self.chainPostResponse(self, uriFunction, {}, params).then(function (response) { + callback(response); + }); + } else { + return self.chainGetResponse(self, uriFunction, params).then(function (response) { + callback(response); + }); + } + }, + + /** + * Fetch the GraphQL schema for the branch. + * + * @param callback function(schema) + * + * @returns String + */ + graphqlSchema: function (callback) { + const self = this; + + const uriFunction = function () { + return self.getUri() + '/graphql/schema'; + }; - if (!Gitana.PREFER_GET_OVER_POST) - { - return self.chainPostResponse(self, uriFunction, {}, params).then(function(response) { + return self.chainGetResponseText(self, uriFunction, {}).then(function (response) { callback(response); }); - } - else - { - return self.chainGetResponse(self, uriFunction, params).then(function(response) { - callback(response); + }, + + /** + * Deletes the nodes described the given array of node ids. + * + * @hcained branch + * + * @param nodeIds + * + * @returns Gitana.Branch + */ + deleteNodes: function (nodeIds) { + const self = this; + + const uriFunction = function () { + return self.getUri() + '/nodes/delete'; + }; + + return this.chainPost(this, uriFunction, {}, { + '_docs': nodeIds }); - } - }, - - /** - * Fetch the GraphQL schema for the branch. - * - * @param callback function(schema) - * - * @returns String - */ - graphqlSchema: function(callback) - { - var self = this; - - var uriFunction = function() - { - return self.getUri() + "/graphql/schema"; - }; - - return self.chainGetResponseText(self, uriFunction, {}).then(function(response) { - callback(response); - }); - }, - - /** - * Deletes the nodes described the given array of node ids. - * - * @hcained branch - * - * @param nodeIds - * - * @returns Gitana.Branch - */ - deleteNodes: function(nodeIds) - { - var self = this; - - var uriFunction = function() - { - return self.getUri() + "/nodes/delete"; - }; - - return this.chainPost(this, uriFunction, {}, { - "_docs": nodeIds - }); - }, - - /** - * Performs a bulk check of permissions against permissioned objects of type node. - * - * Example of checks array: - * - * [{ - * "permissionedId": "", - * "principalId": "", - * "permissionId": "" - * }] - * - * The callback receives an array of results, example: - * - * [{ - * "permissionedId": "", - * "principalId": "", - * "permissionId": "", - * "result": true - * }] - * - * The order of elements in the array will be the same for checks and results. - * - * @param checks - * @param callback - */ - checkNodePermissions: function(checks, callback) - { - var self = this; - - var uriFunction = function() - { - return self.getUri() + "/nodes/permissions/check"; - }; - - var object = { - "checks": checks - }; - - return this.chainPostResponse(this, uriFunction, {}, object).then(function(response) { - callback.call(this, response["results"]); - }); - }, - - /** - * Performs a bulk check of authorities against permissioned objects of type node. - * - * Example of checks array: - * - * [{ - * "permissionedId": "", - * "principalId": "", - * "authorityId": "" - * }] - * - * The callback receives an array of results, example: - * - * [{ - * "permissionedId": "", - * "principalId": "", - * "authorityId": "", - * "result": true - * }] - * - * The order of elements in the array will be the same for checks and results. - * - * @param checks - * @param callback - */ - checkNodeAuthorities: function(checks, callback) - { - var self = this; - - var uriFunction = function() - { - return self.getUri() + "/nodes/authorities/check"; - }; - - var object = { - "checks": checks - }; - - return this.chainPostResponse(this, uriFunction, {}, object).then(function(response) { - callback.call(this, response["results"]); - }); - }, - - - /** - * Reads the person object for a security user. - * - * @chained node - * - * @param {Object} user either the user id, user name or the user object - * @param [Boolean] createIfNotFound whether to create the person object if it isn't found - */ - readPersonNode: function(user, createIfNotFound) - { - var self = this; + }, + + /** + * Performs a bulk check of permissions against permissioned objects of type node. + * + * Example of checks array: + * + * [{ + * "permissionedId": "", + * "principalId": "", + * "permissionId": "" + * }] + * + * The callback receives an array of results, example: + * + * [{ + * "permissionedId": "", + * "principalId": "", + * "permissionId": "", + * "result": true + * }] + * + * The order of elements in the array will be the same for checks and results. + * + * @param checks + * @param callback + */ + checkNodePermissions: function (checks, callback) { + const self = this; + + const uriFunction = function () { + return self.getUri() + '/nodes/permissions/check'; + }; - var principalDomainQualifiedId = this.extractPrincipalDomainQualifiedId(user); + const object = { + 'checks': checks + }; - var uriFunction = function() - { - var uri = self.getUri() + "/person/acquire?id=" + principalDomainQualifiedId; - if (createIfNotFound) - { - uri += "&createIfNotFound=" + createIfNotFound; - } + return this.chainPostResponse(this, uriFunction, {}, object).then(function (response) { + callback.call(this, response['results']); + }); + }, + + /** + * Performs a bulk check of authorities against permissioned objects of type node. + * + * Example of checks array: + * + * [{ + * "permissionedId": "", + * "principalId": "", + * "authorityId": "" + * }] + * + * The callback receives an array of results, example: + * + * [{ + * "permissionedId": "", + * "principalId": "", + * "authorityId": "", + * "result": true + * }] + * + * The order of elements in the array will be the same for checks and results. + * + * @param checks + * @param callback + */ + checkNodeAuthorities: function (checks, callback) { + const self = this; + + const uriFunction = function () { + return self.getUri() + '/nodes/authorities/check'; + }; - return uri; - }; - - var chainable = this.getFactory().node(this, "n:person"); - return this.chainGet(chainable, uriFunction); - }, - - /** - * Reads the group object for a security group. - * - * @chained node - * - * @param {Object} group eitehr the group id, group name or the group object - * @param [Boolean] createIfNotFound whether to create the group object if it isn't found - */ - readGroupNode: function(group, createIfNotFound) - { - var self = this; + const object = { + 'checks': checks + }; - var principalDomainQualifiedId = this.extractPrincipalDomainQualifiedId(group); + return this.chainPostResponse(this, uriFunction, {}, object).then(function (response) { + callback.call(this, response['results']); + }); + }, + + + /** + * Reads the person object for a security user. + * + * @chained node + * + * @param {Object} user either the user id, user name or the user object + * @param {Boolean} createIfNotFound whether to create the person object if it isn't found + */ + readPersonNode: function (user, createIfNotFound) { + const self = this; + + const principalDomainQualifiedId = this.extractPrincipalDomainQualifiedId(user); + + const uriFunction = function () { + let uri = self.getUri() + '/person/acquire?id=' + principalDomainQualifiedId; + if (createIfNotFound) { + uri += '&createIfNotFound=' + createIfNotFound; + } - var uriFunction = function() - { - var uri = self.getUri() + "/group/acquire?id=" + principalDomainQualifiedId; - if (createIfNotFound) - { - uri += "&createIfNotFound=" + createIfNotFound; - } + return uri; + }; - return uri; - }; - - var chainable = this.getFactory().node(this, "n:group"); - return this.chainGet(chainable, uriFunction); - }, - - /** - * Acquire a list of definitions. - * - * @chained node map - * - * @public - * - * @param [String] filter Optional filter of the kind of definition to fetch - "association", "type" or "feature" - * @param [Object] pagination Optional pagination - */ - listDefinitions: function(filter, pagination) - { - if (filter && typeof(filter) === "object") - { - pagination = filter; - filter = null; - } + const chainable = this.getFactory().node(this, 'n:person'); + return this.chainGet(chainable, uriFunction); + }, + + /** + * Reads the group object for a security group. + * + * @chained node + * + * @param {Object} group eitehr the group id, group name or the group object + * @param {Boolean} createIfNotFound whether to create the group object if it isn't found + */ + readGroupNode: function (group, createIfNotFound) { + const self = this; + + const principalDomainQualifiedId = this.extractPrincipalDomainQualifiedId(group); + + const uriFunction = function () { + let uri = self.getUri() + '/group/acquire?id=' + principalDomainQualifiedId; + if (createIfNotFound) { + uri += '&createIfNotFound=' + createIfNotFound; + } - var self = this; + return uri; + }; - var params = {}; - params["capabilities"] = "true"; - if (filter) - { - params["filter"] = filter; - } - if (pagination) - { - Gitana.copyInto(params, pagination); - } + const chainable = this.getFactory().node(this, 'n:group'); + return this.chainGet(chainable, uriFunction); + }, + + /** + * Acquire a list of definitions. + * + * @chained node map + * + * @public + * + * @param {String} filter Optional filter of the kind of definition to fetch - "association", "type" or "feature" + * @param {Object} pagination Optional pagination + */ + listDefinitions: function (filter, pagination) { + if (filter && typeof (filter) === 'object') { + pagination = filter; + filter = null; + } - var uriFunction = function() - { - return self.getUri() + "/definitions"; - }; - - var chainable = this.getFactory().nodeMap(this); - return this.chainGet(chainable, uriFunction, params); - }, - - /** - * Query and search a list of definitions - * - * @param {*} json contains a search object and a query object - * @param {*} pagination - */ - queryDefinitions: function(json, pagination) - { - var self = this; + const self = this; - var params = {}; - if (pagination) - { - Gitana.copyInto(params, pagination); - } + const params = {}; + params['capabilities'] = 'true'; + if (filter) { + params['filter'] = filter; + } + if (pagination) { + Gitana.copyInto(params, pagination); + } - var uriFunction = function() - { - return self.getUri() + "/definitions/query"; - }; - - var chainable = this.getFactory().nodeMap(this); - return this.chainPost(chainable, uriFunction, params, json); - }, - - /** - * Reads a definition by qname. - * - * @chained definition - * - * @public - * - * @param {String} qname the qname - */ - readDefinition: function(qname) - { - var self = this; - - var uriFunction = function() - { - return self.getUri() + "/definitions/" + qname; - }; - - var chainable = this.getFactory().definition(this); - return this.chainGet(chainable, uriFunction); - }, - - /** - * Loads a list of schemas for an optional given type. - * - * @chained this - * - * @public - * - * @param [String] filter Optional filter of the kind of definition to fetch - "association", "type" or "feature" - * @param {Function} callback - */ - loadSchemas: function(filter, callback) - { - if (typeof(filter) == "function") - { - callback = filter; - filter = null; - } + const uriFunction = function () { + return self.getUri() + '/definitions'; + }; - var self = this; + const chainable = this.getFactory().nodeMap(this); + return this.chainGet(chainable, uriFunction, params); + }, + + /** + * Query and search a list of definitions + * + * @param {*} json contains a search object and a query object + * @param {*} pagination + */ + queryDefinitions: function (json, pagination) { + const self = this; + + const params = {}; + if (pagination) { + Gitana.copyInto(params, pagination); + } - return this.then(function() { + const uriFunction = function () { + return self.getUri() + '/definitions/query'; + }; - var chain = this; + const chainable = this.getFactory().nodeMap(this); + return this.chainPost(chainable, uriFunction, params, json); + }, + + /** + * Reads a definition by qname. + * + * @chained definition + * + * @public + * + * @param {String} qname the qname + */ + readDefinition: function (qname) { + const self = this; + + const uriFunction = function () { + return self.getUri() + '/definitions/' + qname; + }; - // call - var uri = self.getUri() + "/schemas"; - if (filter) { - uri += "?filter=" + filter; + const chainable = this.getFactory().definition(this); + return this.chainGet(chainable, uriFunction); + }, + + /** + * Loads a list of schemas for an optional given type. + * + * @chained this + * + * @public + * + * @param {String} filter Optional filter of the kind of definition to fetch - "association", "type" or "feature" + * @param {Function} callback + */ + loadSchemas: function (filter, callback) { + if (typeof (filter) === 'function') { + callback = filter; + filter = null; } - self.getDriver().gitanaGet(uri, null, {}, function(response) { - callback.call(chain, response); + const self = this; - chain.next(); - }); + return this.then(function () { - // NOTE: we return false to tell the chain that we'll manually call next() - return false; - }); - }, - - - /** - * Reads a schema by qname. - * - * @chained this - * - * @public - * - * @param {String} qname the qname - */ - loadSchema: function(qname, callback) - { - var self = this; + const chain = this; - return this.then(function() { + // call + let uri = self.getUri() + '/schemas'; + if (filter) { + uri += '?filter=' + filter; + } + self.getDriver().gitanaGet(uri, null, {}, function (response) { - var chain = this; + callback.call(chain, response); - // call - var uri = self.getUri() + "/schemas/" + qname; - self.getDriver().gitanaGet(uri, null, {}, function(response) { - callback.call(chain, response); - chain.next(); - }); + chain.next(); + }); - // NOTE: we return false to tell the chain that we'll manually call next() - return false; - }); - }, - - /** - * Determines an available QName on this branch given some input. - * This makes a call to the repository and asks it to provide a valid QName. - * - * The valid QName is passed as an argument to the next method in the chain. - * - * Note: This QName is a recommended QName that is valid at the time of the call. - * - * If another thread writes a node with the same QName after this call but ahead of this thread - * attempting to commit, an invalid qname exception may still be thrown back. - * - * @chained this - * - * @public - * - * @param {Object} object an object with "title" or "description" fields to base generation upon - */ - generateQName: function(object, callback) - { - var self = this; + // NOTE: we return false to tell the chain that we'll manually call next() + return false; + }); + }, + + + /** + * Reads a schema by qname. + * + * @chained this + * + * @public + * + * @param {String} qname the qname + * @param callback + */ + loadSchema: function (qname, callback) { + const self = this; + + return this.then(function () { + + const chain = this; + + // call + const uri = self.getUri() + '/schemas/' + qname; + self.getDriver().gitanaGet(uri, null, {}, function (response) { + callback.call(chain, response); + chain.next(); + }); + + // NOTE: we return false to tell the chain that we'll manually call next() + return false; + }); + }, + + /** + * Determines an available QName on this branch given some input. + * This makes a call to the repository and asks it to provide a valid QName. + * + * The valid QName is passed as an argument to the next method in the chain. + * + * Note: This QName is a recommended QName that is valid at the time of the call. + * + * If another thread writes a node with the same QName after this call but ahead of this thread + * attempting to commit, an invalid qname exception may still be thrown back. + * + * @chained this + * + * @public + * + * @param {Object} object an object with "title" or "description" fields to base generation upon + * @param callback + */ + generateQName: function (object, callback) { + const self = this; + + return this.then(function () { + + const chain = this; + + // call + const uri = self.getUri() + '/qnames/generate'; + self.getDriver().gitanaPost(uri, null, object, function (response) { + + const qname = response['_qname']; + + callback.call(chain, qname); + + chain.next(); + }); + + // NOTE: we return false to tell the chain that we'll manually call next() + return false; + }); + }, + + /** + * Creates an association between the source node and the target node of the given type. + * + * @chained branch (this) + * + * @param sourceNode + * @param targetNode + * @param object (or string identifying type) + */ + associate: function (sourceNode, targetNode, object) { + // source + let sourceNodeId = null; + if (Gitana.isString(sourceNode)) { + sourceNodeId = sourceNode; + } else { + sourceNodeId = sourceNode.getId(); + } - return this.then(function() { + // target + let targetNodeId = null; + if (Gitana.isString(targetNode)) { + targetNodeId = targetNode; + } else { + targetNodeId = targetNode.getId(); + } - var chain = this; + // make sure we hand back the branch + const result = this.subchain(this); - // call - var uri = self.getUri() + "/qnames/generate"; - self.getDriver().gitanaPost(uri, null, object, function(response) { + // run a subchain to do the association + result.subchain(this).then(function () { + this.readNode(sourceNodeId).associate(targetNodeId, object); + }); - var qname = response["_qname"]; + return result; + }, + + /** + * Traverses around the given node. + * + * Note: This is a helper function provided for convenience that delegates off to the node to do the work. + * + * @chained traversal results + * + * @param node or node id + * @param config + */ + traverse: function (node, config) { + let nodeId = null; + if (Gitana.isString(node)) { + nodeId = node; + } else { + nodeId = node.getId(); + } - callback.call(chain, qname); + return this.readNode(nodeId).traverse(config); + }, + + ////////////////////////////////////////////////////////////////////////////////////////// + // + // CONTAINER (a:child) CONVENIENCE FUNCTIONS + // + ////////////////////////////////////////////////////////////////////////////////////////// + + /** + * Creates a container node. + * + * This is a convenience function that simply applies the container feature to the object + * ahead of calling createNode. + * + * @chained node + * + * @public + * + * @param {Object} object JSON object + */ + createContainer: function (object) { + if (!object) { + object = {}; + } - chain.next(); - }); + if (!object['_features']) { + object['_features'] = {}; + } - // NOTE: we return false to tell the chain that we'll manually call next() - return false; - }); - }, - - /** - * Creates an association between the source node and the target node of the given type. - * - * @chained branch (this) - * - * @param sourceNode - * @param targetNode - * @param object (or string identifying type) - */ - associate: function(sourceNode, targetNode, object) - { - // source - var sourceNodeId = null; - if (Gitana.isString(sourceNode)) - { - sourceNodeId = sourceNode; - } - else - { - sourceNodeId = sourceNode.getId(); - } + object['_features']['f:container'] = { + 'active': 'true' + }; - // target - var targetNodeId = null; - if (Gitana.isString(targetNode)) - { - targetNodeId = targetNode; - } - else - { - targetNodeId = targetNode.getId(); - } + return this.createNode(object); + }, + + + ////////////////////////////////////////////////////////////////////////////////////////// + // + // FIND + // + ////////////////////////////////////////////////////////////////////////////////////////// + + /** + * Finds nodes within a branch + * + * @chained node map + * + * Config should be: + * + * { + * "query": { + * ... Query Block + * }, + * "search": { + * ... Elastic Search Config Block + * } + * } + * + * Alternatively, the value for "search" in the JSON block above can simply be text. + * + * @public + * + * @param {Object} config search configuration + * @param {Object} pagination + */ + find: function (config, pagination) { + const self = this; + + const params = {}; + if (pagination) { + Gitana.copyInto(params, pagination); + } - // make sure we hand back the branch - var result = this.subchain(this); - - // run a subchain to do the association - result.subchain(this).then(function() { - this.readNode(sourceNodeId).associate(targetNodeId, object); - }); - - return result; - }, - - /** - * Traverses around the given node. - * - * Note: This is a helper function provided for convenience that delegates off to the node to do the work. - * - * @chained traversal results - * - * @param node or node id - * @param config - */ - traverse: function(node, config) - { - var nodeId = null; - if (Gitana.isString(node)) - { - nodeId = node; - } - else - { - nodeId = node.getId(); - } + const uriFunction = function () { + return self.getUri() + '/nodes/find'; + }; - return this.readNode(nodeId).traverse(config); - }, - - ////////////////////////////////////////////////////////////////////////////////////////// - // - // CONTAINER (a:child) CONVENIENCE FUNCTIONS - // - ////////////////////////////////////////////////////////////////////////////////////////// - - /** - * Creates a container node. - * - * This is a convenience function that simply applies the container feature to the object - * ahead of calling createNode. - * - * @chained node - * - * @public - * - * @param [Object] object JSON object - */ - createContainer: function(object) - { - if (!object) - { - object = {}; - } + const chainable = this.getFactory().nodeMap(this); + return this.chainPost(chainable, uriFunction, params, config); + }, + + /** + * Another way to access the find() method that is more consistent with the API + * that would be expected. + * + * @param config + * @param pagination + * @return {*} + */ + findNodes: function (config, pagination) { + return this.find(config, pagination); + }, + + + /////////////////////////////////////////////////////////////////////////////////////////////////////// + // + // NODE LIST + // + /////////////////////////////////////////////////////////////////////////////////////////////////////// + + + /** + * List the items in a node list. + * + * @chained node map + * + * @public + * + * @param {String} listKey + * @param {Object} pagination + */ + listItems: function (listKey, pagination) { + const self = this; + + const params = {}; + if (pagination) { + Gitana.copyInto(params, pagination); + } - if (!object["_features"]) - { - object["_features"] = {}; - } + const uriFunction = function () { + return self.getUri() + '/lists/' + listKey + '/items'; + }; - object["_features"]["f:container"] = { - "active": "true" - }; - - return this.createNode(object); - }, - - - ////////////////////////////////////////////////////////////////////////////////////////// - // - // FIND - // - ////////////////////////////////////////////////////////////////////////////////////////// - - /** - * Finds nodes within a branch - * - * @chained node map - * - * Config should be: - * - * { - * "query": { - * ... Query Block - * }, - * "search": { - * ... Elastic Search Config Block - * } - * } - * - * Alternatively, the value for "search" in the JSON block above can simply be text. - * - * @public - * - * @param {Object} config search configuration - */ - find: function(config, pagination) - { - var self = this; + const chainable = this.getFactory().nodeMap(this); + return this.chainGet(chainable, uriFunction, pagination); + }, + + /** + * Queries for items in a node list. + * + * @chained node map + * + * @public + * + * @param {String} listKey + * @param {Object} query + * @param {Object} pagination + */ + queryItems: function (listKey, query, pagination) { + const self = this; + + const params = {}; + if (pagination) { + Gitana.copyInto(params, pagination); + } - var params = {}; - if (pagination) - { - Gitana.copyInto(params, pagination); - } + const uriFunction = function () { + return self.getUri() + '/lists/' + listKey + '/items/query'; + }; - var uriFunction = function() - { - return self.getUri() + "/nodes/find"; - }; - - var chainable = this.getFactory().nodeMap(this); - return this.chainPost(chainable, uriFunction, params, config); - }, - - /** - * Another way to access the find() method that is more consistent with the API - * that would be expected. - * - * @param config - * @param pagination - * @return {*} - */ - findNodes: function(config, pagination) - { - return this.find(config, pagination); - }, - - - /////////////////////////////////////////////////////////////////////////////////////////////////////// - // - // NODE LIST - // - /////////////////////////////////////////////////////////////////////////////////////////////////////// - - - /** - * List the items in a node list. - * - * @chained node map - * - * @public - * - * @param {String} listKey - * @param [Object] pagination - */ - listItems: function(listKey, pagination) - { - var self = this; + const chainable = this.getFactory().nodeMap(this); + return this.chainPost(chainable, uriFunction, params, query); + }, - var params = {}; - if (pagination) - { - Gitana.copyInto(params, pagination); - } - var uriFunction = function() - { - return self.getUri() + "/lists/" + listKey + "/items"; - }; - - var chainable = this.getFactory().nodeMap(this); - return this.chainGet(chainable, uriFunction, pagination); - }, - - /** - * Queries for items in a node list. - * - * @chained node map - * - * @public - * - * @param {String} listKey - * @param {Object} query - * @param [Object] pagination - */ - queryItems: function(listKey, query, pagination) - { - var self = this; + /////////////////////////////////////////////////////////////////////////////////////////////////////// + // + // UTILITIES + // + /////////////////////////////////////////////////////////////////////////////////////////////////////// - var params = {}; - if (pagination) - { - Gitana.copyInto(params, pagination); - } + /** + * Loads all of the definitions, forms and key mappings on this branch. + * + * @param filter + * @param callback + */ + loadForms: function (filter, callback) { + const self = this; - var uriFunction = function() - { - return self.getUri() + "/lists/" + listKey + "/items/query"; - }; - - var chainable = this.getFactory().nodeMap(this); - return this.chainPost(chainable, uriFunction, params, query); - }, - - - /////////////////////////////////////////////////////////////////////////////////////////////////////// - // - // UTILITIES - // - /////////////////////////////////////////////////////////////////////////////////////////////////////// - - /** - * Loads all of the definitions, forms and key mappings on this branch. - * - * @param filter - * @param callback - */ - loadForms: function(filter, callback) - { - var self = this; + return this.then(function () { - return this.then(function() { + const chain = this; - var chain = this; + // call + let uri = self.getUri() + '/forms'; + if (filter) { + uri += '?filter=' + filter; + } + self.getDriver().gitanaGet(uri, null, {}, function (response) { - // call - var uri = self.getUri() + "/forms"; - if (filter) { - uri += "?filter=" + filter; - } - self.getDriver().gitanaGet(uri, null, {}, function(response) { + callback.call(chain, response); - callback.call(chain, response); + chain.next(); + }); - chain.next(); + // NOTE: we return false to tell the chain that we'll manually call next() + return false; }); + }, - // NOTE: we return false to tell the chain that we'll manually call next() - return false; - }); - }, + /////////////////////////////////////////////////////////////////////////////////////////////////////// + // + // ADMIN + // + /////////////////////////////////////////////////////////////////////////////////////////////////////// - /////////////////////////////////////////////////////////////////////////////////////////////////////// - // - // ADMIN - // - /////////////////////////////////////////////////////////////////////////////////////////////////////// + adminRebuildPathIndexes: function () { + const self = this; - adminRebuildPathIndexes: function() - { - var self = this; + return this.then(function () { - return this.then(function() { + const chain = this; - var chain = this; + // call + const uri = self.getUri() + '/admin/paths/index'; + self.getDriver().gitanaPost(uri, null, {}, function () { + chain.next(); + }); - // call - var uri = self.getUri() + "/admin/paths/index"; - self.getDriver().gitanaPost(uri, null, {}, function(response) { - chain.next(); + // NOTE: we return false to tell the chain that we'll manually call next() + return false; }); + }, - // NOTE: we return false to tell the chain that we'll manually call next() - return false; - }); - }, + adminRebuildSearchIndexes: function () { + const self = this; - adminRebuildSearchIndexes: function() - { - var self = this; + return this.then(function () { - return this.then(function() { + const chain = this; - var chain = this; + // call + const uri = self.getUri() + '/admin/search/index'; + self.getDriver().gitanaPost(uri, null, {}, function () { + chain.next(); + }); - // call - var uri = self.getUri() + "/admin/search/index"; - self.getDriver().gitanaPost(uri, null, {}, function(response) { - chain.next(); + // NOTE: we return false to tell the chain that we'll manually call next() + return false; }); + }, - // NOTE: we return false to tell the chain that we'll manually call next() - return false; - }); - }, + adminContentMaintenance: function () { + const self = this; - adminContentMaintenance: function() - { - var self = this; + return this.then(function () { - return this.then(function() { + const chain = this; - var chain = this; + // call + const uri = self.getUri() + '/admin/content'; + self.getDriver().gitanaPost(uri, null, {}, function () { + chain.next(); + }); - // call - var uri = self.getUri() + "/admin/content"; - self.getDriver().gitanaPost(uri, null, {}, function(response) { - chain.next(); + // NOTE: we return false to tell the chain that we'll manually call next() + return false; }); + }, - // NOTE: we return false to tell the chain that we'll manually call next() - return false; - }); - }, + adminUpgradeSchema: function () { + const self = this; - adminUpgradeSchema: function() - { - var self = this; + return this.then(function () { - return this.then(function() { + const chain = this; - var chain = this; + // call + const uri = self.getUri() + '/admin/upgradeschema'; + self.getDriver().gitanaPost(uri, null, {}, function () { + chain.next(); + }); - // call - var uri = self.getUri() + "/admin/upgradeschema"; - self.getDriver().gitanaPost(uri, null, {}, function(response) { - chain.next(); + // NOTE: we return false to tell the chain that we'll manually call next() + return false; }); + }, - // NOTE: we return false to tell the chain that we'll manually call next() - return false; - }); - }, - - createForExport: function(exportId, config, callback) - { - var self = this; - - if (!config) - { - config = {}; - } + createForExport: function (exportId, config, callback) { + const self = this; - if (!config.repositoryId) - { - config.repositoryId = self.getRepositoryId(); - } - if (!config.branchId) - { - config.branchId = self.getId(); - } - if (!config.properties) - { - config.properties = {}; - } - if (!config.parentFolderPath) - { - config.parentFolderPath = {}; - } + if (!config) { + config = {}; + } - var uriFunction = function() - { - return "/ref/exports/" + exportId + "/generate"; - }; + if (!config.repositoryId) { + config.repositoryId = self.getRepositoryId(); + } + if (!config.branchId) { + config.branchId = self.getId(); + } + if (!config.properties) { + config.properties = {}; + } + if (!config.parentFolderPath) { + config.parentFolderPath = {}; + } - var params = {}; + const uriFunction = function () { + return '/ref/exports/' + exportId + '/generate'; + }; - return this.chainPostResponse(this, uriFunction, params, config).then(function(response) { - callback(response); - }); - }, + const params = {}; + return this.chainPostResponse(this, uriFunction, params, config).then(function (response) { + callback(response); + }); + }, + + + ////////////////////////////////////////////////////////////////////////////////////////// + // + // INFO + // + ////////////////////////////////////////////////////////////////////////////////////////// + + /** + * Loads information about the branch. + * + * @param callback + */ + loadInfo: function (callback) { + const uriFunction = function () { + return this.getUri() + '/info'; + }; - ////////////////////////////////////////////////////////////////////////////////////////// - // - // INFO - // - ////////////////////////////////////////////////////////////////////////////////////////// + return this.chainGetResponse(this, uriFunction, {}).then(function (response) { + callback(response); + }); + }, + + + ////////////////////////////////////////////////////////////////////////////////////////// + // + // INDEXES + // + ////////////////////////////////////////////////////////////////////////////////////////// + + createCustomIndex: function (name, index) { + const self = this; + + let payload = null; + if (typeof (index) === 'undefined') { + payload = name; + } else { + payload = { + 'name': name, + 'index': index + }; + } - /** - * Loads information about the branch. - * - * @param callback - */ - loadInfo: function(callback) - { - var uriFunction = function() - { - return this.getUri() + "/info"; - }; + const uriFunction = function () { + return self.getUri() + '/indexes'; + }; - return this.chainGetResponse(this, uriFunction, {}).then(function(response) { - callback(response); - }); - }, + return this.chainPost(this, uriFunction, {}, payload); + }, + dropCustomIndex: function (name) { + const self = this; + const uriFunction = function () { + return self.getUri() + '/indexes/' + name; + }; - ////////////////////////////////////////////////////////////////////////////////////////// - // - // INDEXES - // - ////////////////////////////////////////////////////////////////////////////////////////// + return this.chainDelete(this, uriFunction); + }, - createCustomIndex: function(name, index) - { - var self = this; + loadCustomIndexes: function (callback) { + const self = this; - var payload = null; - if (typeof(index) === "undefined") - { - payload = name; - } - else - { - payload = { - "name": name, - "index": index + const uriFunction = function () { + return self.getUri() + '/indexes'; }; - } - var uriFunction = function() - { - return self.getUri() + "/indexes"; - }; - - return this.chainPost(this, uriFunction, {}, payload); - }, + return this.chainGetResponse(this, uriFunction, {}).then(function (response) { + callback(response); + }); + }, + + + ////////////////////////////////////////////////////////////////////////////////////////// + // + // HISTORY + // + ////////////////////////////////////////////////////////////////////////////////////////// + + /** + * Loads the historic changesets for a branch. + * + * The config is optional and can specify "root" and "tip" changeset ids. + * + * @param config + * @param pagination (optional) + * @param callback + * @returns {*} + */ + loadHistoryChangesets: function (config, pagination, callback) { + const self = this; + + if (typeof (pagination) === 'function') { + callback = pagination; + pagination = null; + } - dropCustomIndex: function(name) - { - var self = this; + if (typeof (config) === 'function') { + callback = config; + config = {}; + pagination = null; + } - var uriFunction = function() - { - return self.getUri() + "/indexes/" + name; - }; + if (!config) { + config = {}; + } - return this.chainDelete(this, uriFunction); - }, + const uriFunction = function () { + return self.getUri() + '/history/changesets'; + }; - loadCustomIndexes: function(callback) - { - var self = this; - - var uriFunction = function() - { - return self.getUri() + "/indexes"; - }; - - return this.chainGetResponse(this, uriFunction, {}).then(function(response) { - callback(response); - }); - }, - - - ////////////////////////////////////////////////////////////////////////////////////////// - // - // HISTORY - // - ////////////////////////////////////////////////////////////////////////////////////////// - - /** - * Loads the historic changesets for a branch. - * - * The config is optional and can specify "root" and "tip" changeset ids. - * - * @param config - * @param pagination (optional) - * @param callback - * @returns {*} - */ - loadHistoryChangesets: function(config, pagination, callback) - { - var self = this; + const params = {}; + if (pagination) { + Gitana.copyInto(params, pagination); + } - if (typeof(pagination) === "function") { - callback = pagination; - pagination = null; - } + if (config.root) { + params.root = config.root; + } + if (config.tip) { + params.tip = config.tip; + } + if (config.include_root) { + params.include_root = config.include_root; + } - if (typeof(config) === "function") { - callback = config; - config = {}; - pagination = null; - } + return this.chainGetResponse(this, uriFunction, params).then(function (response) { + callback(response); + }); + }, + + /** + * Loads the history node differences for a branch. + * + * The config is optional and can specify "root" and "tip" changeset ids. + * + * @param config + * @param pagination (optional) + * @param callback + * @returns {*} + */ + loadHistoryNodeDiffs: function (config, pagination, callback) { + const self = this; + + if (typeof (pagination) === 'function') { + callback = pagination; + pagination = null; + } - if (!config) { - config = {}; - } + if (typeof (config) === 'function') { + callback = config; + config = {}; + pagination = null; + } - var uriFunction = function() - { - return self.getUri() + "/history/changesets"; - }; + if (!config) { + config = {}; + } - var params = {}; - if (pagination) - { - Gitana.copyInto(params, pagination); - } + const uriFunction = function () { + return self.getUri() + '/history/nodediffs'; + }; - if (config.root) { - params.root = config.root; - } - if (config.tip) { - params.tip = config.tip; - } - if (config.include_root) { - params.include_root = config.include_root; - } + const params = {}; + if (pagination) { + Gitana.copyInto(params, pagination); + } - return this.chainGetResponse(this, uriFunction, params).then(function(response) { - callback(response); - }); - }, - - /** - * Loads the history node differences for a branch. - * - * The config is optional and can specify "root" and "tip" changeset ids. - * - * @param config - * @param pagination (optional) - * @param callback - * @returns {*} - */ - loadHistoryNodeDiffs: function(config, pagination, callback) - { - var self = this; + if (config.root) { + params.root = config.root; + } + if (config.tip) { + params.tip = config.tip; + } + if (config.include_root) { + params.include_root = config.include_root; + } - if (typeof(pagination) === "function") { - callback = pagination; - pagination = null; - } + return this.chainGetResponse(this, uriFunction, params).then(function (response) { + callback(response); + }); + }, - if (typeof(config) === "function") { - callback = config; - config = {}; - pagination = null; - } - if (!config) { - config = {}; - } + /////////////////////////////////////////////////////////////////////////////////////////////////////////// + /////////////////////////////////////////////////////////////////////////////////////////////////////////// + /////////////////////////////////////////////////////////////////////////////////////////////////////////// - var uriFunction = function() - { - return self.getUri() + "/history/nodediffs"; - }; - var params = {}; - if (pagination) - { - Gitana.copyInto(params, pagination); - } + /** + * Reads a deletion. + * + * @chained deletion + * + * @public + * + * @param {String} nodeId the node id + */ + readDeletion: function (nodeId) { + const self = this; - if (config.root) { - params.root = config.root; - } - if (config.tip) { - params.tip = config.tip; - } - if (config.include_root) { - params.include_root = config.include_root; - } + const uriFunction = function () { + return self.getUri() + '/deletions/' + nodeId; + }; - return this.chainGetResponse(this, uriFunction, params).then(function(response) { - callback(response); - }); - }, + const params = {}; + const chainable = this.getFactory().deletion(this); + return this.chainGet(chainable, uriFunction, params); + }, + + /** + * Queries for deletions on the branch. + * + * Config should be: + * + * { + * Gitana query configs + * } + * + * @chained deletion map + * + * @public + * + * @param {Object} query + * @param {Object} pagination + */ + queryDeletions: function (query, pagination) { + const self = this; + + if (!query) { + query = {}; + } + const params = {}; + if (pagination) { + Gitana.copyInto(params, pagination); + } - /////////////////////////////////////////////////////////////////////////////////////////////////////////// - /////////////////////////////////////////////////////////////////////////////////////////////////////////// - /////////////////////////////////////////////////////////////////////////////////////////////////////////// + const uriFunction = function () { + return self.getUri() + '/deletions/query'; + }; + const chainable = this.getFactory().deletionMap(this); - /** - * Reads a deletion. - * - * @chained deletion - * - * @public - * - * @param {String} nodeId the node id - */ - readDeletion: function(nodeId) - { - var self = this; - - var uriFunction = function() - { - return self.getUri() + "/deletions/" + nodeId; - }; - - var params = {}; - - var chainable = this.getFactory().deletion(this); - return this.chainGet(chainable, uriFunction, params); - }, - - /** - * Queries for deletions on the branch. - * - * Config should be: - * - * { - * Gitana query configs - * } - * - * @chained deletion map - * - * @public - * - * @param {Object} query - * @param [Object] pagination - */ - queryDeletions: function(query, pagination) - { - var self = this; + if (!Gitana.PREFER_GET_OVER_POST) { + return this.chainPost(chainable, uriFunction, params, query); + } else { + Gitana.copyInto(params, { + 'query': JSON.stringify(query) + }); - if (!query) { - query = {}; - } + return this.chainGet(chainable, uriFunction, params); + } + }, + + /** + * Purges all deletions. + * + * @chained this + */ + purgeAllDeletions: function () { + const self = this; + + const uriFunction = function () { + return self.getUri() + '/deletions/purgeall'; + }; - var params = {}; - if (pagination) - { - Gitana.copyInto(params, pagination); - } + return this.chainPostEmpty(null, uriFunction); + }, - var uriFunction = function() - { - return self.getUri() + "/deletions/query"; - }; + /** + * Archives the branch. + * + * @param callback + * @returns {*} + */ + archive: function (callback) { + const self = this; - var chainable = this.getFactory().deletionMap(this); + const uriFunction = function () { + return self.getUri() + '/archive'; + }; - if (!Gitana.PREFER_GET_OVER_POST) - { - return this.chainPost(chainable, uriFunction, params, query); - } - else - { - Gitana.copyInto(params, { - "query": JSON.stringify(query) + return this.chainPostResponse(this, uriFunction).then(function (response) { + callback(response); }); + }, + + /** + * Unarchives the branch. + * + * @param callback + * @returns {*} + */ + unarchive: function (callback) { + const self = this; + + const uriFunction = function () { + return self.getUri() + '/unarchive'; + }; - return this.chainGet(chainable, uriFunction, params); - } - }, - - /** - * Purges all deletions. - * - * @chained this - */ - purgeAllDeletions: function() - { - var self = this; - - var uriFunction = function() - { - return self.getUri() + "/deletions/purgeall"; - }; - - return this.chainPostEmpty(null, uriFunction); - }, - - /** - * Archives the branch. - * - * @param callback - * @returns {*} - */ - archive: function(callback) - { - var self = this; - - var uriFunction = function() - { - return self.getUri() + "/archive"; - }; - - return this.chainPostResponse(this, uriFunction).then(function(response) { - callback(response); - }); - }, - - /** - * Unarchives the branch. - * - * @param callback - * @returns {*} - */ - unarchive: function(callback) - { - var self = this; - - var uriFunction = function() - { - return self.getUri() + "/unarchive"; - }; - - return this.chainPostResponse(this, uriFunction).then(function(response) { - callback(response); - }); - }, - - /** - * Finds the changes that will be applied from a source branch to a target branch. Runs as a background Job - * - * Params allow for: - * - * root root changeset id - * tip tip changeset id - * include_root whether to include the root changeset - * view "editorial" to filter only to include editorial nodes - * - * @public - * - * @param options (request param options, pagination) - * @param callback - */ - startChangesetHistory: function(options, callback) - { - if (typeof(options) === "function") { - callback = options; - options = null; - } + return this.chainPostResponse(this, uriFunction).then(function (response) { + callback(response); + }); + }, + + /** + * Finds the changes that will be applied from a source branch to a target branch. Runs as a background Job + * + * Params allow for: + * + * root root changeset id + * tip tip changeset id + * include_root whether to include the root changeset + * view "editorial" to filter only to include editorial nodes + * + * @public + * + * @param options (request param options, pagination) + * @param callback + */ + startChangesetHistory: function (options, callback) { + if (typeof (options) === 'function') { + callback = options; + options = null; + } - var params = {}; + const params = {}; - if (Gitana.isObject(options)) { - for (var k in options) { - params[k] = options[k]; + if (Gitana.isObject(options)) { + for (const k in options) { + params[k] = options[k]; + } } - } - var uriFunction = function() - { - return this.getUri() + "/history/start"; - }; + const uriFunction = function () { + return this.getUri() + '/history/start'; + }; - return this.chainPostResponse(this, uriFunction, params).then(function(response) { + return this.chainPostResponse(this, uriFunction, params).then(function (response) { - var jobId = response._doc; + const jobId = response._doc; - callback(jobId); - }); - } + callback(jobId); + }); + } - }); + }); })(window); diff --git a/js/gitana/repository/BranchMap.js b/js/gitana/repository/BranchMap.js index f93500fa..78629bb9 100644 --- a/js/gitana/repository/BranchMap.js +++ b/js/gitana/repository/BranchMap.js @@ -1,6 +1,6 @@ (function(window) { - var Gitana = window.Gitana; + Gitana = window.Gitana; Gitana.BranchMap = Gitana.AbstractPlatformObjectMap.extend( /** @lends Gitana.BranchMap.prototype */ @@ -12,7 +12,7 @@ * @class Map of branch objects * * @param {Gitana.Repository} repository - * @param [Object] object + * @param {Object} object */ constructor: function(repository, object) { diff --git a/js/gitana/repository/Changeset.js b/js/gitana/repository/Changeset.js index 4678281b..4cc19bb4 100644 --- a/js/gitana/repository/Changeset.js +++ b/js/gitana/repository/Changeset.js @@ -1,6 +1,6 @@ (function(window) { - var Gitana = window.Gitana; + Gitana = window.Gitana; Gitana.Changeset = Gitana.AbstractRepositoryObject.extend( /** @lends Gitana.Changeset.prototype */ @@ -12,7 +12,7 @@ * @class Changeset * * @param {Gitana.Repository} repository - * @param [Object] object json object (if no callback required for populating) + * @param {Object} object json object (if no callback required for populating) */ constructor: function(repository, object) { @@ -50,22 +50,22 @@ * * @chained node map * - * @param [Object] pagination optional pagination + * @param {Object} pagination optional pagination */ listNodes: function(pagination) { - var params = {}; + const params = {}; if (pagination) { Gitana.copyInto(params, pagination); } - var uriFunction = function() + const uriFunction = function() { return "/repositories/" + this.getRepositoryId() + "/changesets/" + this.getId() + "/nodes"; }; - var chainable = this.getFactory().nodeMap(this); + const chainable = this.getFactory().nodeMap(this); return this.chainGet(chainable, uriFunction, params); } diff --git a/js/gitana/repository/ChangesetMap.js b/js/gitana/repository/ChangesetMap.js index e4b8d11c..0a991f3b 100644 --- a/js/gitana/repository/ChangesetMap.js +++ b/js/gitana/repository/ChangesetMap.js @@ -1,6 +1,6 @@ (function(window) { - var Gitana = window.Gitana; + Gitana = window.Gitana; Gitana.ChangesetMap = Gitana.AbstractPlatformObjectMap.extend( /** @lends Gitana.ChangesetMap.prototype */ @@ -11,8 +11,8 @@ * * @class Map of changeset objects * - * @param {Gitana.Server} server Gitana server instance. - * @param [Object] object + * @param {Gitana.Repository} repository Gitana repository instance. + * @param {Object} object */ constructor: function(repository, object) { diff --git a/js/gitana/repository/Deletion.js b/js/gitana/repository/Deletion.js index bfd87284..e9704527 100644 --- a/js/gitana/repository/Deletion.js +++ b/js/gitana/repository/Deletion.js @@ -1,6 +1,6 @@ (function(window) { - var Gitana = window.Gitana; + Gitana = window.Gitana; Gitana.Deletion = Gitana.AbstractRepositoryObject.extend( /** @lends Gitana.Deletion.prototype */ @@ -81,11 +81,12 @@ * Restores a deletion to the branch. * * @public - * @param [object] data any data to override on the restored node + * @param {object} data any data to override on the restored node + * @param callback */ restore: function(data, callback) { - var self = this; + const self = this; if (typeof(data) === "function") { @@ -97,7 +98,7 @@ data = {}; } - var uriFunction = function() + const uriFunction = function() { return self.getUri() + "/restore"; }; diff --git a/js/gitana/repository/DeletionMap.js b/js/gitana/repository/DeletionMap.js index efcc7a09..09d2da48 100644 --- a/js/gitana/repository/DeletionMap.js +++ b/js/gitana/repository/DeletionMap.js @@ -1,6 +1,6 @@ (function(window) { - var Gitana = window.Gitana; + Gitana = window.Gitana; Gitana.DeletionMap = Gitana.AbstractPlatformObjectMap.extend( /** @lends Gitana.DeletionMap.prototype */ @@ -12,7 +12,7 @@ * @class Map of deletion objects * * @param {Gitana.Branch} branch Gitana branch instance. - * @param [Object] object + * @param {Object} object */ constructor: function(branch, object) { @@ -96,16 +96,16 @@ */ del: function() { - var self = this; + const self = this; - var uriFunction = function() + const uriFunction = function() { return self.getBranch().getUri() + "/deletions/delete"; }; return this.subchain().then(function() { - var nodeIds = this.__keys(); + const nodeIds = this.__keys(); return this.chainPost(this, uriFunction, {}, { "_docs": nodeIds diff --git a/js/gitana/repository/MergeConflict.js b/js/gitana/repository/MergeConflict.js index d56e1025..80abeb41 100644 --- a/js/gitana/repository/MergeConflict.js +++ b/js/gitana/repository/MergeConflict.js @@ -1,6 +1,6 @@ (function(window) { - var Gitana = window.Gitana; + Gitana = window.Gitana; Gitana.MergeConflict = Gitana.AbstractRepositoryObject.extend( /** @lends Gitana.MergeConflict.prototype */ @@ -12,7 +12,7 @@ * @class MergeConflict * * @param {Gitana.Repository} repository - * @param [Object] object json object (if no callback required for populating) + * @param {Object} object json object (if no callback required for populating) */ constructor: function(repository, object) { @@ -47,15 +47,15 @@ resolve: function(resolutionsArrayOrString, callback) { - var self = this; + const self = this; - var uriFunction = function() + const uriFunction = function() { return self.getUri() + "/resolve"; }; - var params = {}; - var payload = null; + const params = {}; + let payload = null; if (Gitana.isString(resolutionsArrayOrString)) { @@ -75,14 +75,14 @@ commit: function(branchId) { - var self = this; + const self = this; - var uriFunction = function() + const uriFunction = function() { return self.getUri() + "/commit"; }; - var params = {}; + const params = {}; if (branchId) { params.branch = branchId; } diff --git a/js/gitana/repository/MergeConflictMap.js b/js/gitana/repository/MergeConflictMap.js index 41e0f19a..a65336a2 100644 --- a/js/gitana/repository/MergeConflictMap.js +++ b/js/gitana/repository/MergeConflictMap.js @@ -1,6 +1,6 @@ (function(window) { - var Gitana = window.Gitana; + Gitana = window.Gitana; Gitana.MergeConflictMap = Gitana.AbstractPlatformObjectMap.extend( /** @lends Gitana.MergeConflictMap.prototype */ @@ -12,7 +12,7 @@ * @class Map of merge conflict objects * * @param {Gitana.Repository} repository - * @param [Object] object + * @param {Object} object */ constructor: function(repository, object) { diff --git a/js/gitana/repository/Node.js b/js/gitana/repository/Node.js index 47e4433b..7f68b8d3 100644 --- a/js/gitana/repository/Node.js +++ b/js/gitana/repository/Node.js @@ -1,6 +1,6 @@ (function(window) { - var Gitana = window.Gitana; + Gitana = window.Gitana; Gitana.Node = Gitana.AbstractNode.extend( /** @lends Gitana.Node.prototype */ @@ -37,22 +37,22 @@ * * @public * - * @param [object] pagination + * @param {object} pagination */ listChildren: function(pagination) { - var params = {}; + const params = {}; if (pagination) { Gitana.copyInto(params, pagination); } - var uriFunction = function() + const uriFunction = function() { return "/repositories/" + this.getRepositoryId() + "/branches/" + this.getBranchId() + "/nodes/" + this.getId() + "/children"; }; - var chainable = this.getFactory().nodeMap(this.getBranch()); + const chainable = this.getFactory().nodeMap(this.getBranch()); return this.chainGet(chainable, uriFunction, params); }, @@ -68,8 +68,8 @@ */ listRelatives: function(config, pagination) { - var type = null; - var direction = null; + let type = null; + let direction = null; if (config) { @@ -80,15 +80,15 @@ } } - var params = {}; + const params = {}; if (pagination) { Gitana.copyInto(params, pagination); } - var uriFunction = function() + const uriFunction = function() { - var url = "/repositories/" + this.getRepositoryId() + "/branches/" + this.getBranchId() + "/nodes/" + this.getId() + "/relatives"; + let url = "/repositories/" + this.getRepositoryId() + "/branches/" + this.getBranchId() + "/nodes/" + this.getId() + "/relatives"; if (type) { url = url + "?type=" + type; @@ -107,7 +107,7 @@ return url; }; - var chainable = this.getFactory().nodeMap(this.getBranch()); + const chainable = this.getFactory().nodeMap(this.getBranch()); return this.chainGet(chainable, uriFunction, params); }, @@ -124,8 +124,8 @@ */ queryRelatives: function(query, config, pagination) { - var type = null; - var direction = null; + let type = null; + let direction = null; if (config) { @@ -136,15 +136,15 @@ } } - var params = {}; + const params = {}; if (pagination) { Gitana.copyInto(params, pagination); } - var uriFunction = function() + const uriFunction = function() { - var url = "/repositories/" + this.getRepositoryId() + "/branches/" + this.getBranchId() + "/nodes/" + this.getId() + "/relatives/query"; + let url = "/repositories/" + this.getRepositoryId() + "/branches/" + this.getBranchId() + "/nodes/" + this.getId() + "/relatives/query"; if (type) { url = url + "?type=" + type; @@ -163,18 +163,18 @@ return url; }; - var chainable = this.getFactory().nodeMap(this.getBranch()); + const chainable = this.getFactory().nodeMap(this.getBranch()); return this.chainPost(chainable, uriFunction, params, query); }, patch: function(patches) { - var uriFunction = function() + const uriFunction = function() { return this.getUri(); }; - var chainable = this.getFactory().nodeMap(this.getBranch()); + const chainable = this.getFactory().nodeMap(this.getBranch()); return this.chainPatch(chainable, uriFunction, null, patches); }, @@ -190,8 +190,8 @@ */ associations: function(config, pagination) { - var type = null; - var direction = null; + let type = null; + let direction = null; if (config) { @@ -202,15 +202,15 @@ } } - var params = {}; + const params = {}; if (pagination) { Gitana.copyInto(params, pagination); } - var uriFunction = function() + const uriFunction = function() { - var url = "/repositories/" + this.getRepositoryId() + "/branches/" + this.getBranchId() + "/nodes/" + this.getId() + "/associations?a=1"; + let url = "/repositories/" + this.getRepositoryId() + "/branches/" + this.getBranchId() + "/nodes/" + this.getId() + "/associations?a=1"; if (type) { url = url + "&type=" + type; @@ -223,7 +223,7 @@ return url; }; - var chainable = this.getFactory().nodeMap(this.getBranch()); + const chainable = this.getFactory().nodeMap(this.getBranch()); return this.chainGet(chainable, uriFunction, params); }, @@ -239,7 +239,7 @@ */ incomingAssociations: function(type, pagination) { - var config = { + const config = { "direction": "INCOMING" }; if (type) { @@ -261,7 +261,7 @@ */ outgoingAssociations: function(type, pagination) { - var config = { + const config = { "direction": "OUTGOING" }; if (type) { @@ -279,7 +279,7 @@ * * @public * - * @param {String|Node} targetNode - the id of the target node or the target node itself + * @param {String|Gitana.Node} targetNodeId - the id of the target node or the target node itself * @param {Object|String} [object] either a JSON object or a string identifying the type of association * @param {Boolean} [undirected] whether the association is undirected (i.e. mutual) */ @@ -300,9 +300,9 @@ } } - var uriFunction = function() + const uriFunction = function() { - var url = "/repositories/" + this.getRepositoryId() + "/branches/" + this.getBranchId() + "/nodes/" + this.getId() + "/associate?node=" + targetNodeId; + let url = "/repositories/" + this.getRepositoryId() + "/branches/" + this.getBranchId() + "/nodes/" + this.getId() + "/associate?node=" + targetNodeId; if (undirected) { @@ -328,10 +328,10 @@ */ associateOf: function(sourceNode, object, undirected) { - var self = this; + const self = this; // what we're handing back (ourselves) - var result = this.subchain(this); + const result = this.subchain(this); // our work result.subchain(sourceNode).then(function() { @@ -348,7 +348,7 @@ * * @public * - * @param {String|Node} targetNode the id of the target node or the target node itself + * @param {String|Gitana.Node} targetNodeId the id of the target node or the target node itself * @param {String} [type] A string identifying the type of association * @param {Boolean} [undirected] whether the association is undirected (i.e. mutual) */ @@ -359,9 +359,9 @@ targetNodeId = targetNodeId.getId(); } - var uriFunction = function() + const uriFunction = function() { - var url = "/repositories/" + this.getRepositoryId() + "/branches/" + this.getBranchId() + "/nodes/" + this.getId() + "/unassociate?node=" + targetNodeId; + let url = "/repositories/" + this.getRepositoryId() + "/branches/" + this.getBranchId() + "/nodes/" + this.getId() + "/unassociate?node=" + targetNodeId; if (type) { @@ -403,17 +403,17 @@ traverse: function(config) { // build the payload - var payload = { + const payload = { "traverse": config }; - var uriFunction = function() + const uriFunction = function() { return "/repositories/" + this.getRepositoryId() + "/branches/" + this.getBranchId() + "/nodes/" + this.getId() + "/traverse"; }; - var chainable = this.getFactory().traversalResults(this.getBranch()); - var params = {}; + const chainable = this.getFactory().traversalResults(this.getBranch()); + const params = {}; return this.chainPost(chainable, uriFunction, params, payload); }, @@ -428,7 +428,7 @@ */ mount: function(mountKey) { - var uriFunction = function() + const uriFunction = function() { return "/repositories/" + this.getRepositoryId() + "/branches/" + this.getBranchId() + "/nodes/" + this.getId() + "/mount/" + mountKey; }; @@ -443,7 +443,7 @@ */ unmount: function() { - var uriFunction = function() + const uriFunction = function() { return "/repositories/" + this.getRepositoryId() + "/branches/" + this.getBranchId() + "/nodes/" + this.getId() + "/unmount"; }; @@ -460,7 +460,7 @@ */ lock: function() { - var uriFunction = function() + const uriFunction = function() { return "/repositories/" + this.getRepositoryId() + "/branches/" + this.getBranchId() + "/nodes/" + this.getId() + "/lock"; }; @@ -477,7 +477,7 @@ */ unlock: function() { - var uriFunction = function() + const uriFunction = function() { return "/repositories/" + this.getRepositoryId() + "/branches/" + this.getBranchId() + "/nodes/" + this.getId() + "/unlock"; }; @@ -498,10 +498,10 @@ // TODO: isn't this subchain() redundant? return this.subchain(this).then(function() { - var chain = this; + const chain = this; // call - var uri = "/repositories/" + this.getRepositoryId() + "/branches/" + this.getBranchId() + "/nodes/" + this.getId() + "/lock"; + const uri = "/repositories/" + this.getRepositoryId() + "/branches/" + this.getBranchId() + "/nodes/" + this.getId() + "/lock"; this.getDriver().gitanaGet(uri, null, {}, function(response) { callback.call(chain, response["locked"]); @@ -528,9 +528,9 @@ */ loadACL: function(callback) { - var self = this; + const self = this; - var uriFunction = function() + const uriFunction = function() { return self.getUri() + "/acl/list"; }; @@ -549,9 +549,9 @@ */ listAuthorities: function(principal) { - var principalDomainQualifiedId = this.extractPrincipalDomainQualifiedId(principal); + const principalDomainQualifiedId = this.extractPrincipalDomainQualifiedId(principal); - var uriFunction = function() + const uriFunction = function() { return "/repositories/" + this.getRepositoryId() + "/branches/" + this.getBranchId() + "/nodes/" + this.getId() + "/acl?id=" + principalDomainQualifiedId; }; @@ -571,9 +571,9 @@ */ checkAuthority: function(principal, authorityId, callback) { - var principalDomainQualifiedId = this.extractPrincipalDomainQualifiedId(principal); + const principalDomainQualifiedId = this.extractPrincipalDomainQualifiedId(principal); - var uriFunction = function() + const uriFunction = function() { return "/repositories/" + this.getRepositoryId() + "/branches/" + this.getBranchId() + "/nodes/" + this.getId() + "/authorities/" + authorityId + "/check?id=" + principalDomainQualifiedId; }; @@ -593,9 +593,9 @@ */ grantAuthority: function(principal, authorityId) { - var principalDomainQualifiedId = this.extractPrincipalDomainQualifiedId(principal); + const principalDomainQualifiedId = this.extractPrincipalDomainQualifiedId(principal); - var uriFunction = function() + const uriFunction = function() { return "/repositories/" + this.getRepositoryId() + "/branches/" + this.getBranchId() + "/nodes/" + this.getId() + "/authorities/" + authorityId + "/grant?id=" + principalDomainQualifiedId; }; @@ -613,9 +613,9 @@ */ revokeAuthority: function(principal, authorityId) { - var principalDomainQualifiedId = this.extractPrincipalDomainQualifiedId(principal); + const principalDomainQualifiedId = this.extractPrincipalDomainQualifiedId(principal); - var uriFunction = function() + const uriFunction = function() { return "/repositories/" + this.getRepositoryId() + "/branches/" + this.getBranchId() + "/nodes/" + this.getId() + "/authorities/" + authorityId + "/revoke?id=" + principalDomainQualifiedId; }; @@ -650,7 +650,7 @@ principalIds = []; } - var json = { + const json = { "principals": principalIds }; @@ -671,9 +671,9 @@ */ checkPermission: function(principal, permissionId, callback) { - var principalDomainQualifiedId = this.extractPrincipalDomainQualifiedId(principal); + const principalDomainQualifiedId = this.extractPrincipalDomainQualifiedId(principal); - var uriFunction = function() + const uriFunction = function() { return "/repositories/" + this.getRepositoryId() + "/branches/" + this.getBranchId() + "/nodes/" + this.getId() + "/permissions/" + permissionId + "/check?id=" + principalDomainQualifiedId; }; @@ -702,9 +702,9 @@ */ createTranslation: function(edition, locale, object) { - var uriFunction = function() + const uriFunction = function() { - var url = "/repositories/" + this.getRepositoryId() + "/branches/" + this.getBranchId() + "/nodes/" + this.getId() + "/i18n?locale=" + locale; + let url = "/repositories/" + this.getRepositoryId() + "/branches/" + this.getBranchId() + "/nodes/" + this.getId() + "/i18n?locale=" + locale; if (edition) { url += "&edition=" + edition; @@ -713,7 +713,7 @@ return url; }; - var chainable = this.getFactory().node(this.getBranch()); + const chainable = this.getFactory().node(this.getBranch()); return this.chainCreateEx(chainable, object, uriFunction, uriFunction); }, @@ -727,7 +727,7 @@ */ editions: function(callback) { - var uriFunction = function() + const uriFunction = function() { return "/repositories/" + this.getRepositoryId() + "/branches/" + this.getBranchId() + "/nodes/" + this.getId() + "/i18n/editions"; }; @@ -748,7 +748,7 @@ */ locales: function(edition, callback) { - var uriFunction = function() + const uriFunction = function() { return "/repositories/" + this.getRepositoryId() + "/branches/" + this.getBranchId() + "/nodes/" + this.getId() + "/i18n/locales?edition=" + edition; }; @@ -770,7 +770,7 @@ */ listTranslations: function(edition, pagination) { - var params = {}; + const params = {}; if (edition) { params.edition = edition; @@ -780,12 +780,12 @@ Gitana.copyInto(params, pagination); } - var uriFunction = function() + const uriFunction = function() { return "/repositories/" + this.getRepositoryId() + "/branches/" + this.getBranchId() + "/nodes/" + this.getId() + "/i18n/translations"; }; - var chainable = this.getFactory().nodeMap(this.getBranch()); + const chainable = this.getFactory().nodeMap(this.getBranch()); return this.chainGet(chainable, uriFunction, params); }, @@ -796,17 +796,17 @@ * * @chained translation node * - * @param {String} [edition] The edition of the translation to use. If not provided, the tip edition is used from the master node. + * @param {String} edition The edition of the translation to use. If not provided, the tip edition is used from the master node. * @param {String} locale The locale to translate into. */ readTranslation: function() { - var edition; - var locale; + let edition; + let locale; - var args = Gitana.makeArray(arguments); + const args = Gitana.makeArray(arguments); - if (args.length == 1) + if (args.length === 1) { locale = args.shift(); } @@ -816,9 +816,9 @@ locale = args.shift(); } - var uriFunction = function() + const uriFunction = function() { - var uri = "/repositories/" + this.getRepositoryId() + "/branches/" + this.getBranchId() + "/nodes/" + this.getId() + "/i18n?locale=" + locale; + let uri = "/repositories/" + this.getRepositoryId() + "/branches/" + this.getBranchId() + "/nodes/" + this.getId() + "/i18n?locale=" + locale; if (edition) { uri += "&edition=" + edition; @@ -827,7 +827,7 @@ return uri; }; - var chainable = this.getFactory().node(this.getBranch()); + const chainable = this.getFactory().node(this.getBranch()); return this.chainGet(chainable, uriFunction); }, @@ -853,18 +853,18 @@ */ createChild: function(object) { - var self = this; + const self = this; // we can't assume we know the branch get since we're chaining // so create a temporary branch that we'll load later - var branch = new Gitana.Branch(this.getRepository()); + const branch = new Gitana.Branch(this.getRepository()); // we hand back a node and preload some work - var chainable = this.getFactory().node(branch); + const chainable = this.getFactory().node(branch); return this.subchain(chainable).then(function() { - var chain = this; + const chain = this; // we now plug in branch and create child node this.subchain(self).then(function() { @@ -937,18 +937,18 @@ */ find: function(config, pagination) { - var params = {}; + const params = {}; if (pagination) { Gitana.copyInto(params, pagination); } - var uriFunction = function() + const uriFunction = function() { return "/repositories/" + this.getRepositoryId() + "/branches/" + this.getBranchId() + "/nodes/" + this.getId() + "/find"; }; - var chainable = this.getFactory().nodeMap(this.getBranch()); + const chainable = this.getFactory().nodeMap(this.getBranch()); return this.chainPost(chainable, uriFunction, params, config); }, @@ -988,8 +988,8 @@ */ findRelatives: function(config, associationConfig, pagination) { - var type = null; - var direction = null; + let type = null; + let direction = null; if (associationConfig) { @@ -1003,15 +1003,15 @@ delete associationConfig.direction; } - var params = {}; + const params = {}; if (pagination) { Gitana.copyInto(params, pagination); } - var uriFunction = function() + const uriFunction = function() { - var url = "/repositories/" + this.getRepositoryId() + "/branches/" + this.getBranchId() + "/nodes/" + this.getId() + "/relatives/find"; + let url = "/repositories/" + this.getRepositoryId() + "/branches/" + this.getBranchId() + "/nodes/" + this.getId() + "/relatives/find"; if (type) { url = url + "?type=" + type; @@ -1030,7 +1030,7 @@ return url; }; - var chainable = this.getFactory().nodeMap(this.getBranch()); + const chainable = this.getFactory().nodeMap(this.getBranch()); return this.chainPost(chainable, uriFunction, params, config); }, @@ -1046,7 +1046,7 @@ */ loadTree: function(config, callback) { - var self = this; + const self = this; if (typeof(config) === "function") { @@ -1059,12 +1059,12 @@ config = {}; } - var uriFunction = function() + const uriFunction = function() { return self.getUri() + "/tree"; }; - var params = {}; + const params = {}; if (config.leafPath) { params["leaf"] = config.leafPath; @@ -1099,7 +1099,7 @@ params["depth"] = config.depth; } - var payload = {}; + const payload = {}; if (config.query) { payload.query = config.query; } @@ -1122,14 +1122,14 @@ */ resolvePath: function(rootNodeId, callback) { - var self = this; + const self = this; - var uriFunction = function() + const uriFunction = function() { return self.getUri() + "/path"; }; - var params = { + const params = { "rootNodeId": rootNodeId }; @@ -1158,11 +1158,11 @@ Gitana.copyInto(params, pagination); } - var uriFunction = function () { + const uriFunction = function () { return this.getUri() + "/versions"; }; - var chainable = this.getFactory().nodeMap(this.getBranch()); + const chainable = this.getFactory().nodeMap(this.getBranch()); return this.chainGet(chainable, uriFunction, params); }, @@ -1182,12 +1182,12 @@ restoreVersion: function(changesetId) { - var uriFunction = function() + const uriFunction = function() { return "/repositories/" + this.getRepositoryId() + "/branches/" + this.getBranchId() + "/nodes/" + this.getId() + "/versions/" + changesetId + "/restore"; }; - var chainable = this.getFactory().node(this.getBranch()); + const chainable = this.getFactory().node(this.getBranch()); return this.chainPost(chainable, uriFunction, {}, {}); }, @@ -1206,12 +1206,12 @@ */ moveToFolder: function(targetFolder) { - var self = this; + const self = this; - var params = {}; + const params = {}; params.targetNodeId = targetFolder.getId ? targetFolder.getId() : targetFolder; - var uriFunction = function() + const uriFunction = function() { return self.getUri() + "/move"; }; diff --git a/js/gitana/repository/NodeAttachment.js b/js/gitana/repository/NodeAttachment.js index 2f9100da..f2b219eb 100644 --- a/js/gitana/repository/NodeAttachment.js +++ b/js/gitana/repository/NodeAttachment.js @@ -1,6 +1,6 @@ (function(window) { - var Gitana = window.Gitana; + Gitana = window.Gitana; /** * Node attachments are similar to binary attachments. They're identical in structure except that they diff --git a/js/gitana/repository/NodeAttachmentMap.js b/js/gitana/repository/NodeAttachmentMap.js index abd4b052..a4c72276 100644 --- a/js/gitana/repository/NodeAttachmentMap.js +++ b/js/gitana/repository/NodeAttachmentMap.js @@ -1,6 +1,6 @@ (function(window) { - var Gitana = window.Gitana; + Gitana = window.Gitana; Gitana.NodeAttachmentMap = Gitana.BinaryAttachmentMap.extend( /** @lends Gitana.NodeAttachmentMap.prototype */ @@ -11,8 +11,8 @@ * * @class Provides access to node attachments * - * @param repository - * @param map + * @param persistable + * @param object */ constructor: function(persistable, object) { @@ -30,7 +30,7 @@ }, /** - * @param json + * @param attachment */ buildObject: function(attachment) { diff --git a/js/gitana/repository/NodeMap.js b/js/gitana/repository/NodeMap.js index d2b58f67..c3bd835e 100644 --- a/js/gitana/repository/NodeMap.js +++ b/js/gitana/repository/NodeMap.js @@ -1,6 +1,6 @@ (function(window) { - var Gitana = window.Gitana; + Gitana = window.Gitana; Gitana.NodeMap = Gitana.AbstractPlatformObjectMap.extend( /** @lends Gitana.NodeMap.prototype */ @@ -12,7 +12,7 @@ * @class Map of node objects * * @param {Gitana.Branch} branch Gitana branch instance. - * @param [Object] object + * @param {Object} object */ constructor: function(branch, object) { @@ -96,16 +96,16 @@ */ del: function() { - var self = this; + const self = this; - var uriFunction = function() + const uriFunction = function() { return self.getBranch().getUri() + "/nodes/delete"; }; return this.subchain().then(function() { - var nodeIds = this.__keys(); + const nodeIds = this.__keys(); return this.chainPost(this, uriFunction, {}, { "_docs": nodeIds diff --git a/js/gitana/repository/Release.js b/js/gitana/repository/Release.js index d5a0f55e..ae107d40 100644 --- a/js/gitana/repository/Release.js +++ b/js/gitana/repository/Release.js @@ -1,6 +1,6 @@ (function(window) { - var Gitana = window.Gitana; + Gitana = window.Gitana; Gitana.Release = Gitana.AbstractRepositoryObject.extend( /** @lends Gitana.Release.prototype */ @@ -12,7 +12,7 @@ * @class Release * * @param {Gitana.Repository} repository - * @param [Object] object json object (if no callback required for populating) + * @param {Object} object json object (if no callback required for populating) */ constructor: function(repository, object) { @@ -48,6 +48,7 @@ /** * Finalizes the release. * + * @param object * @param callback * @returns {*} */ @@ -63,9 +64,9 @@ object = {}; } - var self = this; + const self = this; - var uriFunction = function() + const uriFunction = function() { return self.getUri() + "/finalize"; }; @@ -83,9 +84,9 @@ */ unfinalize: function(callback) { - var self = this; + const self = this; - var uriFunction = function() + const uriFunction = function() { return self.getUri() + "/unfinalize"; }; @@ -102,9 +103,9 @@ */ loadInfo: function(callback) { - var self = this; + const self = this; - var uriFunction = function() + const uriFunction = function() { return self.getUri() + "/info"; }; @@ -120,19 +121,19 @@ * * @chained release * - * @param [Object] object JSON object + * @param {Object} object JSON object * @param callback */ startFinalize: function(object, callback) { - var self = this; + const self = this; if (typeof(object) === "function") { callback = object; object = null; } - var uriFunction = function() + const uriFunction = function() { return self.getUri() + "/finalize/start"; }; @@ -144,7 +145,7 @@ return this.chainPostResponse(this, uriFunction, {}, object).then(function(response) { - var jobId = response._doc; + const jobId = response._doc; callback(jobId); }); @@ -158,9 +159,9 @@ */ archive: function(callback) { - var self = this; + const self = this; - var uriFunction = function() + const uriFunction = function() { return self.getUri() + "/archive"; }; @@ -178,9 +179,9 @@ */ unarchive: function(callback) { - var self = this; + const self = this; - var uriFunction = function() + const uriFunction = function() { return self.getUri() + "/unarchive"; }; @@ -198,9 +199,9 @@ */ releaseImmediately: function(callback) { - var self = this; + const self = this; - var uriFunction = function() + const uriFunction = function() { return self.getUri() + "/releaseimmediately"; }; diff --git a/js/gitana/repository/ReleaseMap.js b/js/gitana/repository/ReleaseMap.js index afeda946..6c354870 100644 --- a/js/gitana/repository/ReleaseMap.js +++ b/js/gitana/repository/ReleaseMap.js @@ -1,6 +1,6 @@ (function(window) { - var Gitana = window.Gitana; + Gitana = window.Gitana; Gitana.ReleaseMap = Gitana.AbstractPlatformObjectMap.extend( /** @lends Gitana.ReleaseMap.prototype */ @@ -12,7 +12,7 @@ * @class Map of release objects * * @param {Gitana.Repository} repository - * @param [Object] object + * @param {Object} object */ constructor: function(repository, object) { diff --git a/js/gitana/repository/Repository.js b/js/gitana/repository/Repository.js index 066e4408..85af41c6 100644 --- a/js/gitana/repository/Repository.js +++ b/js/gitana/repository/Repository.js @@ -1,6 +1,6 @@ (function(window) { - var Gitana = window.Gitana; + Gitana = window.Gitana; Gitana.Repository = Gitana.AbstractPlatformDataStore.extend( /** @lends Gitana.Repository.prototype */ @@ -12,7 +12,7 @@ * @class Repository * * @param {Gitana.Platform} platform - * @param [Object] object json object (if no callback required for populating) + * @param {Object} object json object (if no callback required for populating) */ constructor: function(platform, object) { @@ -60,22 +60,22 @@ * * @public * - * @param [Object] pagination + * @param {Object} pagination */ listBranches: function(pagination) { - var params = {}; + const params = {}; if (pagination) { Gitana.copyInto(params, pagination); } - var uriFunction = function() + const uriFunction = function() { return "/repositories/" + this.getId() + "/branches"; }; - var chainable = this.getFactory().branchMap(this); + const chainable = this.getFactory().branchMap(this); return this.chainGet(chainable, uriFunction, params); }, @@ -90,12 +90,12 @@ */ readBranch: function(branchId) { - var uriFunction = function() + const uriFunction = function() { return "/repositories/" + this.getId() + "/branches/" + branchId; }; - var chainable = this.getFactory().branch(this); + const chainable = this.getFactory().branch(this); return this.chainGet(chainable, uriFunction); }, @@ -109,20 +109,20 @@ * @param {String} branchId identifies the branch from which the new branch will be forked. * @param {String} changesetId identifies the changeset on the branch which serves as the root changeset that * the new branch will be founded upon. - * @param [Object] object JSON object for the branch + * @param {Object} object JSON object for the branch */ createBranch: function(branchId, changesetId, object) { - var uriFunction = function() + const uriFunction = function() { return "/repositories/" + this.getId() + "/branches"; }; - var createParams = { + const createParams = { "branch": branchId, "changeset": changesetId }; - var chainable = this.getFactory().branch(this); + const chainable = this.getFactory().branch(this); return this.chainCreate(chainable, object, uriFunction, createParams); }, @@ -186,15 +186,15 @@ */ createSnapshot: function(changesetId, object) { - var uriFunction = function() + const uriFunction = function() { return "/repositories/" + this.getId() + "/snapshots"; }; - var createParams = { + const createParams = { "changeset": changesetId }; - var chainable = this.getFactory().branch(this); + const chainable = this.getFactory().branch(this); return this.chainCreate(chainable, object, uriFunction, createParams); }, @@ -211,22 +211,22 @@ * @public * * @param {Object} query - * @param [Object] pagination + * @param {Object} pagination */ queryBranches: function(query, pagination) { - var params = {}; + const params = {}; if (pagination) { Gitana.copyInto(params, pagination); } - var uriFunction = function() + const uriFunction = function() { return "/repositories/" + this.getId() + "/branches/query"; }; - var chainable = this.getFactory().branchMap(this); + const chainable = this.getFactory().branchMap(this); return this.chainPost(chainable, uriFunction, params, query); }, @@ -234,22 +234,22 @@ * Lists the branches that can be pulled into a given branch * * @param {String} branchId - * @param [Object] pagination + * @param {Object} pagination */ listPullSources: function(branchId, pagination) { - var params = {}; + const params = {}; if (pagination) { Gitana.copyInto(params, pagination); } - var uriFunction = function() + const uriFunction = function() { return "/repositories/" + this.getId() + "/branches/" + branchId + "/pull/sources"; }; - var chainable = this.getFactory().branchMap(this); + const chainable = this.getFactory().branchMap(this); return this.chainGet(chainable, uriFunction, params); }, @@ -280,12 +280,12 @@ */ checkBranchPermissions: function(checks, callback) { - var uriFunction = function() + const uriFunction = function() { return "/repositories/" + this.getId() + "/branches/permissions/check"; }; - var object = { + const object = { "checks": checks }; @@ -321,12 +321,12 @@ */ checkBranchAuthorities: function(checks, callback) { - var uriFunction = function() + const uriFunction = function() { return "/repositories/" + this.getId() + "/branches/authorities/check"; }; - var object = { + const object = { "checks": checks }; @@ -344,12 +344,12 @@ */ listChangesets: function() { - var uriFunction = function() + const uriFunction = function() { return "/repositories/" + this.getId() + "/changesets"; }; - var chainable = this.getFactory().changesetMap(this); + const chainable = this.getFactory().changesetMap(this); return this.chainGet(chainable, uriFunction); }, @@ -364,12 +364,12 @@ */ readChangeset: function(changesetId) { - var uriFunction = function() + const uriFunction = function() { return "/repositories/" + this.getId() + "/changesets/" + changesetId; }; - var chainable = this.getFactory().changeset(this); + const chainable = this.getFactory().changeset(this); return this.chainGet(chainable, uriFunction); }, @@ -384,12 +384,12 @@ */ listChangesetParents: function(changesetId) { - var uriFunction = function() + const uriFunction = function() { return "/repositories/" + this.getId() + "/changesets/" + changesetId + "/parents"; }; - var chainable = this.getFactory().changesetMap(this); + const chainable = this.getFactory().changesetMap(this); return this.chainGet(chainable, uriFunction); }, @@ -404,12 +404,12 @@ */ listChangesetChildren: function(changesetId) { - var uriFunction = function() + const uriFunction = function() { return "/repositories/" + this.getId() + "/changesets/" + changesetId + "/children"; }; - var chainable = this.getFactory().changesetMap(this); + const chainable = this.getFactory().changesetMap(this); return this.chainGet(chainable, uriFunction); }, @@ -425,22 +425,22 @@ * @public * * @param {Object} query - * @param [Object] pagination + * @param {Object} pagination */ queryChangesets: function(query, pagination) { - var params = {}; + const params = {}; if (pagination) { Gitana.copyInto(params, pagination); } - var uriFunction = function() + const uriFunction = function() { return "/repositories/" + this.getId() + "/changesets/query"; }; - var chainable = this.getFactory().changesetMap(this); + const chainable = this.getFactory().changesetMap(this); return this.chainPost(chainable, uriFunction, params, query); }, @@ -457,48 +457,50 @@ * * @param sourceBranchId * @param targetBranchId + * @param callback */ startMerge: function(sourceBranchId, targetBranchId, callback) { - var params = { + const params = { id: sourceBranchId }; - var uriFunction = function() + const uriFunction = function() { return "/repositories/" + this.getId() + "/branches/" + targetBranchId + "/merge/start"; }; return this.chainPostResponse(this, uriFunction, params).then(function(response) { - var jobId = response._doc; + const jobId = response._doc; callback(jobId); }); }, - /** - * Performs a diff between a source and target branch. Runs as a background Job - * - * @public - * - * @param sourceBranchId - * @param targetBranchId - */ + /** + * Performs a diff between a source and target branch. Runs as a background Job + * + * @public + * + * @param sourceBranchId + * @param targetBranchId + * @param callback + */ startDiff: function(sourceBranchId, targetBranchId, callback) { - var params = { + const params = { id: sourceBranchId }; - var uriFunction = function() + const uriFunction = function() { return "/repositories/" + this.getId() + "/branches/" + targetBranchId + "/diff/start"; }; return this.chainPostResponse(this, uriFunction, params).then(function(response) { - var jobId = response._doc; + const jobId = response._doc; callback(jobId); }); @@ -521,7 +523,7 @@ options = null; } - var params = {}; + const params = {}; if (typeof(options) === "string") { @@ -529,7 +531,7 @@ } else if (Gitana.isObject(options)) { - for (var k in options) { + for (const k in options) { params[k] = options[k]; } } @@ -537,14 +539,14 @@ // source branch ID params["id"] = sourceBranchId; - var uriFunction = function() + const uriFunction = function() { return "/repositories/" + this.getId() + "/branches/" + targetBranchId + "/changes/start"; }; return this.chainPostResponse(this, uriFunction, params).then(function(response) { - var jobId = response._doc; + const jobId = response._doc; callback(jobId); }); @@ -561,18 +563,18 @@ */ listMerges: function(sourceBranchId, mergeType) { - var params = {}; + const params = {}; if (mergeType) { params.mergeType = mergeType; } - var uriFunction = function() + const uriFunction = function() { return "/repositories/" + this.getId() + "/branches/" + sourceBranchId + "/merges"; }; - var chainable = this.getFactory().branchMap(this); + const chainable = this.getFactory().branchMap(this); return this.chainGet(chainable, uriFunction, params); }, @@ -585,16 +587,16 @@ */ copyFrom: function(sourceBranchId, targetBranchId, config) { - var params = { + const params = { id: sourceBranchId }; - var uriFunction = function() + const uriFunction = function() { return "/repositories/" + this.getId() + "/branches/" + targetBranchId + "/copyfrom"; }; - return this.chainPost(this, uriFunction, params, config) + return this.chainPost(this, uriFunction, params, config); }, /** @@ -638,22 +640,22 @@ * * @public * - * @param [Object] pagination + * @param {Object} pagination */ listReleases: function(pagination) { - var params = {}; + const params = {}; if (pagination) { Gitana.copyInto(params, pagination); } - var uriFunction = function() + const uriFunction = function() { return "/repositories/" + this.getId() + "/releases"; }; - var chainable = this.getFactory().releaseMap(this); + const chainable = this.getFactory().releaseMap(this); return this.chainGet(chainable, uriFunction, params); }, @@ -668,12 +670,12 @@ */ readRelease: function(releaseId) { - var uriFunction = function() + const uriFunction = function() { return "/repositories/" + this.getId() + "/releases/" + releaseId; }; - var chainable = this.getFactory().release(this); + const chainable = this.getFactory().release(this); return this.chainGet(chainable, uriFunction); }, @@ -684,23 +686,23 @@ * * @public * - * @param [Object] object JSON object for the release - * @param [String] sourceId optional id of the source release that should be copied + * @param {Object} object JSON object for the release + * @param {String} sourceId optional id of the source release that should be copied */ createRelease: function(object, sourceId) { - var uriFunction = function() + const uriFunction = function() { return "/repositories/" + this.getId() + "/releases"; }; - var params = {}; + const params = {}; if (sourceId) { params.sourceId = sourceId; } - var chainable = this.getFactory().release(this); + const chainable = this.getFactory().release(this); return this.chainCreate(chainable, object, uriFunction, params); }, @@ -710,13 +712,13 @@ * * @chained release * - * @param [Object] object JSON object - * @param [String] sourceId optional id of the source release that should be copied + * @param {Object} object JSON object + * @param {String} sourceId optional id of the source release that should be copied * @param callback */ startCreateRelease: function(object, sourceId, callback) { - var self = this; + const self = this; if (typeof(object) === "function") { callback = object; @@ -729,7 +731,7 @@ sourceId = null; } - var uriFunction = function() + const uriFunction = function() { return self.getUri() + "/releases/create/start"; }; @@ -739,7 +741,7 @@ object = {}; } - var params = {}; + const params = {}; if (sourceId) { params.sourceId = sourceId; @@ -747,7 +749,7 @@ return this.chainPostResponse(this, uriFunction, params, object).then(function(response) { - var jobId = response._doc; + const jobId = response._doc; callback(jobId); }); @@ -765,22 +767,22 @@ * @public * * @param {Object} query - * @param [Object] pagination + * @param {Object} pagination */ queryReleases: function(query, pagination) { - var params = {}; + const params = {}; if (pagination) { Gitana.copyInto(params, pagination); } - var uriFunction = function() + const uriFunction = function() { return "/repositories/" + this.getId() + "/releases/query"; }; - var chainable = this.getFactory().releaseMap(this); + const chainable = this.getFactory().releaseMap(this); return this.chainPost(chainable, uriFunction, params, query); }, @@ -811,12 +813,12 @@ */ checkReleasePermissions: function(checks, callback) { - var uriFunction = function() + const uriFunction = function() { return "/repositories/" + this.getId() + "/releases/permissions/check"; }; - var object = { + const object = { "checks": checks }; @@ -852,12 +854,12 @@ */ checkReleaseAuthorities: function(checks, callback) { - var uriFunction = function() + const uriFunction = function() { return "/repositories/" + this.getId() + "/releases/authorities/check"; }; - var object = { + const object = { "checks": checks }; @@ -879,22 +881,22 @@ * * @public * - * @param [Object] pagination + * @param {Object} pagination */ listConflicts: function(pagination) { - var params = {}; + const params = {}; if (pagination) { Gitana.copyInto(params, pagination); } - var uriFunction = function() + const uriFunction = function() { return "/repositories/" + this.getId() + "/conflicts"; }; - var chainable = this.getFactory().mergeConflictMap(this); + const chainable = this.getFactory().mergeConflictMap(this); return this.chainGet(chainable, uriFunction, params); }, @@ -909,12 +911,12 @@ */ readConflict: function(conflictId) { - var uriFunction = function() + const uriFunction = function() { return "/repositories/" + this.getId() + "/conflicts/" + conflictId; }; - var chainable = this.getFactory().mergeConflict(this); + const chainable = this.getFactory().mergeConflict(this); return this.chainGet(chainable, uriFunction); }, @@ -930,22 +932,22 @@ * @public * * @param {Object} query - * @param [Object] pagination + * @param {Object} pagination */ queryConflicts: function(query, pagination) { - var params = {}; + const params = {}; if (pagination) { Gitana.copyInto(params, pagination); } - var uriFunction = function() + const uriFunction = function() { return "/repositories/" + this.getId() + "/conflicts/query"; }; - var chainable = this.getFactory().mergeConflictMap(this); + const chainable = this.getFactory().mergeConflictMap(this); return this.chainPost(chainable, uriFunction, params, query); }, @@ -976,12 +978,12 @@ */ checkConflictPermissions: function(checks, callback) { - var uriFunction = function() + const uriFunction = function() { return "/repositories/" + this.getId() + "/conflicts/permissions/check"; }; - var object = { + const object = { "checks": checks }; @@ -1017,12 +1019,12 @@ */ checkConflictAuthorities: function(checks, callback) { - var uriFunction = function() + const uriFunction = function() { return "/repositories/" + this.getId() + "/conflicts/authorities/check"; }; - var object = { + const object = { "checks": checks }; diff --git a/js/gitana/repository/RepositoryMap.js b/js/gitana/repository/RepositoryMap.js index 5988a4e5..016b6283 100644 --- a/js/gitana/repository/RepositoryMap.js +++ b/js/gitana/repository/RepositoryMap.js @@ -1,6 +1,6 @@ (function(window) { - var Gitana = window.Gitana; + Gitana = window.Gitana; Gitana.RepositoryMap = Gitana.AbstractPlatformObjectMap.extend( /** @lends Gitana.RepositoryMap.prototype */ diff --git a/js/gitana/repository/TraversalResults.js b/js/gitana/repository/TraversalResults.js index 4e1d4545..4429b0f7 100644 --- a/js/gitana/repository/TraversalResults.js +++ b/js/gitana/repository/TraversalResults.js @@ -1,6 +1,6 @@ (function(window) { - var Gitana = window.Gitana; + Gitana = window.Gitana; Gitana.TraversalResults = Gitana.AbstractPersistable.extend( /** @lends Gitana.TraversalResults.prototype */ @@ -12,7 +12,7 @@ * @class Provides access to traversal results * * @param {Gitana.Branch} branch - * @param [Object] object + * @param {Object} object */ constructor: function(branch, object) { @@ -114,9 +114,9 @@ */ center: function() { - var chainable = this.getFactory().node(this.getBranch()); + const chainable = this.getFactory().node(this.getBranch()); - var result = this.subchain(chainable); + const result = this.subchain(chainable); // push our logic to the front result.subchain(this.getBranch()).readNode(this._config["center"]).then(function() { @@ -157,17 +157,17 @@ */ nodes: function() { - var self = this; + const self = this; // what we're handing back - var result = this.subchain(this.getFactory().nodeMap(this.getBranch())); + const result = this.subchain(this.getFactory().nodeMap(this.getBranch())); // preload some work and hand back return result.then(function() { - var chain = this; + const chain = this; - var response = { + const response = { "rows": self._nodes }; @@ -182,17 +182,17 @@ * * @param nodeId */ - node: function(id) + node: function(nodeId) { - var self = this; + const self = this; // hand back a node but preload with work - var result = this.subchain(this.getFactory().node(this.getBranch())); + const result = this.subchain(this.getFactory().node(this.getBranch())); return result.then(function() { - var nodeObject = self._nodes[id]; + const nodeObject = self._nodes[nodeId]; if (!nodeObject) { - return self.missingNodeError(id); + return self.missingNodeError(nodeId); } this.handleResponse(nodeObject); @@ -206,17 +206,17 @@ */ associations: function() { - var self = this; + const self = this; // what we're handing back - var result = this.subchain(this.getFactory().nodeMap(this.getBranch())); + const result = this.subchain(this.getFactory().nodeMap(this.getBranch())); // preload some work and hand back return result.then(function() { - var chain = this; + const chain = this; - var response = { + const response = { "rows": self._associations }; @@ -233,13 +233,13 @@ */ association: function(id) { - var self = this; + const self = this; // hand back a node but preload with work - var result = this.subchain(this.getFactory().association(this.getBranch())); + const result = this.subchain(this.getFactory().association(this.getBranch())); return result.then(function() { - var associationObject = self._associations[id]; + const associationObject = self._associations[id]; if (!associationObject) { return self.missingNodeError(id); } diff --git a/js/gitana/repository/types/Definition.js b/js/gitana/repository/types/Definition.js index f2744521..a8e59a2b 100644 --- a/js/gitana/repository/types/Definition.js +++ b/js/gitana/repository/types/Definition.js @@ -1,6 +1,6 @@ (function(window) { - var Gitana = window.Gitana; + Gitana = window.Gitana; Gitana.Definition = Gitana.Node.extend( /** @lends Gitana.Definition.prototype */ @@ -12,7 +12,7 @@ * @class Definition * * @param {Gitana.Branch} branch - * @param [Object] object json object (if no callback required for populating) + * @param {Object} object json object (if no callback required for populating) */ constructor: function(branch, object) { @@ -38,14 +38,14 @@ */ listFormAssociations: function() { - var self = this; + const self = this; - var uriFunction = function() + const uriFunction = function() { return self.getUri() + "/forms"; }; - var chainable = this.getFactory().nodeMap(this.getBranch()); + const chainable = this.getFactory().nodeMap(this.getBranch()); return this.chainGet(chainable, uriFunction); }, @@ -58,14 +58,14 @@ */ readForm: function(formKey) { - var self = this; + const self = this; - var uriFunction = function() + const uriFunction = function() { return self.getUri() + "/forms/" + formKey; }; - var chainable = this.getFactory().form(this.getBranch()); + const chainable = this.getFactory().form(this.getBranch()); return this.chainGet(chainable, uriFunction); }, @@ -75,12 +75,12 @@ * @public * * @param {String} formKey the form key - * @param [Object] object the object that constitutes the form - * @param [String] formPath optional formPath to pass to create node + * @param {Object} formObject the object that constitutes the form + * @param {String} formPath optional formPath to pass to create node */ createForm: function(formKey, formObject, formPath) { - var self = this; + const self = this; if (typeof(formObject) === "string") { @@ -95,27 +95,27 @@ } formObject["_type"] = "n:form"; - var chainable = this.getFactory().form(this.getBranch()); + const chainable = this.getFactory().form(this.getBranch()); // subchain that want to hand back - var result = this.subchain(chainable); + const result = this.subchain(chainable); // now push our logic into a subchain that is the first thing in the result result.subchain(this.getBranch()).createNode(formObject, formPath).then(function() { - var formNode = this; + const formNode = this; // switch to definition node this.subchain(self).then(function() { - var associationObject = { + const associationObject = { "_type": "a:has_form", "form-key": formKey }; this.associate(formNode, associationObject).then(function() { - var association = this; + const association = this; // read back into the form chainable - var uri = "/repositories/" + formNode.getRepositoryId() + "/branches/" + formNode.getBranchId() + "/nodes/" + formNode.getId(); + const uri = "/repositories/" + formNode.getRepositoryId() + "/branches/" + formNode.getBranchId() + "/nodes/" + formNode.getId(); this.getDriver().gitanaGet(uri, null, {}, function(response) { result.handleResponse(response); @@ -145,10 +145,10 @@ { return this.subchain(this).then(function() { - var association = null; + let association = null; this.listFormAssociations().each(function() { - if (this.getFormKey() == formKey) + if (this.getFormKey() === formKey) { association = this; } @@ -165,7 +165,7 @@ /** * Acquires a list of child definitions. * - * @param [object] pagination + * @param {object} pagination * * @chaining node map * @@ -173,20 +173,20 @@ */ listChildDefinitions: function(pagination) { - var self = this; + const self = this; - var params = {}; + const params = {}; if (pagination) { Gitana.copyInto(params, pagination); } - var uriFunction = function() + const uriFunction = function() { return self.getBranch().getUri() + "/definitions/" + this.getQName() + "/children"; }; - var chainable = this.getFactory().nodeMap(this.getBranch()); + const chainable = this.getFactory().nodeMap(this.getBranch()); return this.chainGet(chainable, uriFunction, params); } diff --git a/js/gitana/repository/types/Form.js b/js/gitana/repository/types/Form.js index 0585590e..45bb219f 100644 --- a/js/gitana/repository/types/Form.js +++ b/js/gitana/repository/types/Form.js @@ -1,6 +1,6 @@ (function(window) { - var Gitana = window.Gitana; + Gitana = window.Gitana; Gitana.Form = Gitana.Node.extend( /** @lends Gitana.Form.prototype */ @@ -12,7 +12,7 @@ * @class Form * * @param {Gitana.Branch} branch - * @param [Object] object json object (if no callback required for populating) + * @param {Object} object json object (if no callback required for populating) */ constructor: function(branch, object) { diff --git a/js/gitana/repository/types/HasFormAssociation.js b/js/gitana/repository/types/HasFormAssociation.js index 8bf410d8..d9bcb860 100644 --- a/js/gitana/repository/types/HasFormAssociation.js +++ b/js/gitana/repository/types/HasFormAssociation.js @@ -1,6 +1,6 @@ (function(window) { - var Gitana = window.Gitana; + Gitana = window.Gitana; Gitana.HasFormAssociation = Gitana.Association.extend( /** @lends Gitana.HasFormAssociation.prototype */ @@ -12,7 +12,7 @@ * @class Has Form Association * * @param {Gitana.Branch} branch - * @param [Object] object json object (if no callback required for populating) + * @param {Object} object json object (if no callback required for populating) */ constructor: function(branch, object) { diff --git a/js/gitana/repository/types/HasTranslationAssociation.js b/js/gitana/repository/types/HasTranslationAssociation.js index 9e139807..81a978a0 100644 --- a/js/gitana/repository/types/HasTranslationAssociation.js +++ b/js/gitana/repository/types/HasTranslationAssociation.js @@ -1,6 +1,6 @@ (function(window) { - var Gitana = window.Gitana; + Gitana = window.Gitana; Gitana.HasTranslationAssociation = Gitana.Association.extend( /** @lends Gitana.HasTranslationAssociation.prototype */ @@ -12,7 +12,7 @@ * @class Has Translation Association * * @param {Gitana.Branch} branch - * @param [Object] object json object (if no callback required for populating) + * @param {Object} object json object (if no callback required for populating) */ constructor: function(branch, object) { diff --git a/js/gitana/repository/types/Person.js b/js/gitana/repository/types/Person.js index 1aa388db..9c35bca3 100644 --- a/js/gitana/repository/types/Person.js +++ b/js/gitana/repository/types/Person.js @@ -1,6 +1,6 @@ (function(window) { - var Gitana = window.Gitana; + Gitana = window.Gitana; Gitana.Person = Gitana.Node.extend( /** @lends Gitana.Person.prototype */ diff --git a/js/gitana/vault/AbstractVaultObject.js b/js/gitana/vault/AbstractVaultObject.js index 912a35f3..703d58ff 100644 --- a/js/gitana/vault/AbstractVaultObject.js +++ b/js/gitana/vault/AbstractVaultObject.js @@ -1,6 +1,6 @@ (function(window) { - var Gitana = window.Gitana; + Gitana = window.Gitana; Gitana.AbstractVaultObject = Gitana.AbstractPlatformObject.extend( /** @lends Gitana.AbstractVaultObject.prototype */ @@ -12,7 +12,7 @@ * @class AbstractVaultObject * * @param {Gitana.Vault} vault - * @param [Object] object json object (if no callback required for populating) + * @param {Object} object json object (if no callback required for populating) */ constructor: function(vault, object) { diff --git a/js/gitana/vault/Archive.js b/js/gitana/vault/Archive.js index 3c41c643..b36bf3dd 100644 --- a/js/gitana/vault/Archive.js +++ b/js/gitana/vault/Archive.js @@ -1,6 +1,6 @@ (function(window) { - var Gitana = window.Gitana; + Gitana = window.Gitana; Gitana.Archive = Gitana.AbstractVaultObject.extend( /** @lends Gitana.Archive.prototype */ @@ -12,7 +12,7 @@ * @class Archive * * @param {Gitana.Vault} vault - * @param [Object] object json object (if no callback required for populating) + * @param {Object} object json object (if no callback required for populating) */ constructor: function(vault, object) { @@ -119,9 +119,9 @@ */ publish: function() { - var self = this; + const self = this; - var uriFunction = function() + const uriFunction = function() { return self.getUri() + "/publish"; }; @@ -138,9 +138,9 @@ */ unpublish: function() { - var self = this; + const self = this; - var uriFunction = function() + const uriFunction = function() { return self.getUri() + "/unpublish"; }; diff --git a/js/gitana/vault/ArchiveMap.js b/js/gitana/vault/ArchiveMap.js index ed10a0c5..abc0a509 100644 --- a/js/gitana/vault/ArchiveMap.js +++ b/js/gitana/vault/ArchiveMap.js @@ -1,6 +1,6 @@ (function(window) { - var Gitana = window.Gitana; + Gitana = window.Gitana; Gitana.ArchiveMap = Gitana.AbstractPlatformObjectMap.extend( /** @lends Gitana.ArchiveMap.prototype */ @@ -12,7 +12,7 @@ * @class ArchiveMap * * @param {Gitana.Vault} vault Gitana vault instance. - * @param [Object] object + * @param {Object} object */ constructor: function(vault, object) { diff --git a/js/gitana/vault/Vault.js b/js/gitana/vault/Vault.js index 5208842c..44026fc0 100644 --- a/js/gitana/vault/Vault.js +++ b/js/gitana/vault/Vault.js @@ -1,6 +1,6 @@ (function(window) { - var Gitana = window.Gitana; + Gitana = window.Gitana; Gitana.Vault = Gitana.AbstractPlatformDataStore.extend( /** @lends Gitana.Vault.prototype */ @@ -12,7 +12,7 @@ * @class Vault * * @param {Gitana.Platform} platform - * @param [Object] object json object (if no callback required for populating) + * @param {Object} object json object (if no callback required for populating) */ constructor: function(platform, object) { @@ -63,26 +63,26 @@ */ listArchives: function(pagination) { - var params = {}; + const params = {}; if (pagination) { Gitana.copyInto(params, pagination); } - var chainable = this.getFactory().archiveMap(this); + const chainable = this.getFactory().archiveMap(this); return this.chainGet(chainable, this.getUri() + "/archives", params); }, /** * Reads an archive. * - * @param stackId + * @param archiveId * * @chained stack */ readArchive: function(archiveId) { - var chainable = this.getFactory().archive(this); + const chainable = this.getFactory().archive(this); return this.chainGet(chainable, this.getUri() + "/archives/" + archiveId); }, @@ -97,7 +97,7 @@ */ lookupArchive: function(groupId, artifactId, versionId) { - var chainable = this.getFactory().archive(this); + const chainable = this.getFactory().archive(this); return this.chainGet(chainable, this.getUri() + "/archives/lookup?group=" + groupId + "&artifact=" + artifactId + "&version=" + versionId); }, @@ -107,24 +107,24 @@ * @chained stack map * * @param {Object} query - * @param [Object] pagination pagination (optional) + * @param {Object} pagination pagination (optional) */ - queryArchives: function(query, pagination) + queryArchives: function(query, pagination = undefined) { - var self = this; + const self = this; - var params = {}; + const params = {}; if (pagination) { Gitana.copyInto(params, pagination); } - var uriFunction = function() + const uriFunction = function() { return self.getUri() + "/archives/query"; }; - var chainable = this.getFactory().archiveMap(this); + const chainable = this.getFactory().archiveMap(this); return this.chainPost(chainable, uriFunction, params, query); }, @@ -155,14 +155,14 @@ */ checkArchivePermissions: function(checks, callback) { - var self = this; + const self = this; - var uriFunction = function() + const uriFunction = function() { return self.getUri() + "/archives/permissions/check"; }; - var object = { + const object = { "checks": checks }; @@ -198,14 +198,14 @@ */ checkArchiveAuthorities: function(checks, callback) { - var self = this; + const self = this; - var uriFunction = function() + const uriFunction = function() { return self.getUri() + "/archives/authorities/check"; }; - var object = { + const object = { "checks": checks }; diff --git a/js/gitana/vault/VaultMap.js b/js/gitana/vault/VaultMap.js index 48e5e532..ef963e34 100644 --- a/js/gitana/vault/VaultMap.js +++ b/js/gitana/vault/VaultMap.js @@ -1,6 +1,6 @@ (function(window) { - var Gitana = window.Gitana; + Gitana = window.Gitana; Gitana.VaultMap = Gitana.AbstractPlatformObjectMap.extend( /** @lends Gitana.VaultMap.prototype */ diff --git a/js/gitana/webhost/AbstractWebHostObject.js b/js/gitana/webhost/AbstractWebHostObject.js index 4bdb4795..6b022ec3 100644 --- a/js/gitana/webhost/AbstractWebHostObject.js +++ b/js/gitana/webhost/AbstractWebHostObject.js @@ -1,6 +1,6 @@ (function(window) { - var Gitana = window.Gitana; + Gitana = window.Gitana; Gitana.AbstractWebHostObject = Gitana.AbstractPlatformObject.extend( /** @lends Gitana.AbstractWebHostObject.prototype */ @@ -12,7 +12,7 @@ * @class AbstractWebHostObject * * @param {Gitana.WebHost} webhost - * @param [Object] object json object (if no callback required for populating) + * @param {Object} object json object (if no callback required for populating) */ constructor: function(webhost, object) { diff --git a/js/gitana/webhost/AutoClientMapping.js b/js/gitana/webhost/AutoClientMapping.js index 52ecfc72..14b172a2 100644 --- a/js/gitana/webhost/AutoClientMapping.js +++ b/js/gitana/webhost/AutoClientMapping.js @@ -1,6 +1,6 @@ (function(window) { - var Gitana = window.Gitana; + Gitana = window.Gitana; Gitana.AutoClientMapping = Gitana.AbstractWebHostObject.extend( /** @lends Gitana.AutoClientMapping.prototype */ @@ -12,7 +12,7 @@ * @class AutoClientMapping * * @param {Gitana.WebHost} webhost - * @param [Object] object json object (if no callback required for populating) + * @param {Object} object json object (if no callback required for populating) */ constructor: function(webhost, object) { diff --git a/js/gitana/webhost/AutoClientMappingMap.js b/js/gitana/webhost/AutoClientMappingMap.js index 31fb6682..ab850036 100644 --- a/js/gitana/webhost/AutoClientMappingMap.js +++ b/js/gitana/webhost/AutoClientMappingMap.js @@ -1,6 +1,6 @@ (function(window) { - var Gitana = window.Gitana; + Gitana = window.Gitana; Gitana.AutoClientMappingMap = Gitana.AbstractPlatformObjectMap.extend( /** @lends Gitana.AutoClientMappingMap.prototype */ @@ -12,7 +12,7 @@ * @class AutoClientMappingMap * * @param {Gitana.WebHost} webhost Gitana Web Host instance. - * @param [Object] object + * @param {Object} object */ constructor: function(webhost, object) { diff --git a/js/gitana/webhost/DeployedApplication.js b/js/gitana/webhost/DeployedApplication.js index 399affdc..a93aae00 100644 --- a/js/gitana/webhost/DeployedApplication.js +++ b/js/gitana/webhost/DeployedApplication.js @@ -1,6 +1,6 @@ (function(window) { - var Gitana = window.Gitana; + Gitana = window.Gitana; Gitana.DeployedApplication = Gitana.AbstractWebHostObject.extend( /** @lends Gitana.DeployedApplication.prototype */ @@ -12,7 +12,7 @@ * @class DeployedApplication * * @param {Gitana.WebHost} webhost - * @param [Object] object json object (if no callback required for populating) + * @param {Object} object json object (if no callback required for populating) */ constructor: function(webhost, object) { @@ -60,7 +60,7 @@ */ undeploy: function() { - var uriFunction = function() + const uriFunction = function() { return this.getUri() + "/undeploy"; }; @@ -76,7 +76,7 @@ */ redeploy: function() { - var uriFunction = function() + const uriFunction = function() { return this.getUri() + "/redeploy"; }; @@ -92,7 +92,7 @@ */ start: function() { - var uriFunction = function() + const uriFunction = function() { return this.getUri() + "/start"; }; @@ -108,7 +108,7 @@ */ stop: function() { - var uriFunction = function() + const uriFunction = function() { return this.getUri() + "/stop"; }; @@ -124,7 +124,7 @@ */ restart: function() { - var uriFunction = function() + const uriFunction = function() { return this.getUri() + "/restart"; }; diff --git a/js/gitana/webhost/DeployedApplicationMap.js b/js/gitana/webhost/DeployedApplicationMap.js index 9e98d2c2..63467bcc 100644 --- a/js/gitana/webhost/DeployedApplicationMap.js +++ b/js/gitana/webhost/DeployedApplicationMap.js @@ -1,6 +1,6 @@ (function(window) { - var Gitana = window.Gitana; + Gitana = window.Gitana; Gitana.DeployedApplicationMap = Gitana.AbstractPlatformObjectMap.extend( /** @lends Gitana.DeployedApplicationMap.prototype */ @@ -12,7 +12,7 @@ * @class DeployedApplicationMap * * @param {Gitana.WebHost} webhost Gitana Web Host instance. - * @param [Object] object + * @param {Object} object */ constructor: function(webhost, object) { diff --git a/js/gitana/webhost/TrustedDomainMapping.js b/js/gitana/webhost/TrustedDomainMapping.js index 5b864544..5714d386 100644 --- a/js/gitana/webhost/TrustedDomainMapping.js +++ b/js/gitana/webhost/TrustedDomainMapping.js @@ -1,6 +1,6 @@ (function(window) { - var Gitana = window.Gitana; + Gitana = window.Gitana; Gitana.TrustedDomainMapping = Gitana.AbstractWebHostObject.extend( /** @lends Gitana.TrustedDomainMapping.prototype */ @@ -12,7 +12,7 @@ * @class TrustedDomainMapping * * @param {Gitana.WebHost} webhost - * @param [Object] object json object (if no callback required for populating) + * @param {Object} object json object (if no callback required for populating) */ constructor: function(webhost, object) { diff --git a/js/gitana/webhost/TrustedDomainMappingMap.js b/js/gitana/webhost/TrustedDomainMappingMap.js index a10e5eac..70a99255 100644 --- a/js/gitana/webhost/TrustedDomainMappingMap.js +++ b/js/gitana/webhost/TrustedDomainMappingMap.js @@ -1,6 +1,6 @@ (function(window) { - var Gitana = window.Gitana; + Gitana = window.Gitana; Gitana.TrustedDomainMappingMap = Gitana.AbstractPlatformObjectMap.extend( /** @lends Gitana.TrustedDomainMappingMap.prototype */ @@ -12,7 +12,7 @@ * @class TrustedDomainMappingMap * * @param {Gitana.WebHost} webhost Gitana Web Host instance. - * @param [Object] object + * @param {Object} object */ constructor: function(webhost, object) { diff --git a/js/gitana/webhost/WebHost.js b/js/gitana/webhost/WebHost.js index a1f54c71..a6becdd3 100644 --- a/js/gitana/webhost/WebHost.js +++ b/js/gitana/webhost/WebHost.js @@ -1,6 +1,6 @@ (function(window) { - var Gitana = window.Gitana; + Gitana = window.Gitana; Gitana.WebHost = Gitana.AbstractPlatformDataStore.extend( /** @lends Gitana.WebHost.prototype */ @@ -12,7 +12,7 @@ * @class WebHost * * @param {Gitana.Platform} platform - * @param [Object] object json object (if no callback required for populating) + * @param {Object} object json object (if no callback required for populating) */ constructor: function(platform, object) { @@ -66,7 +66,7 @@ * @param applicationId * @param clientKey * @param authGrantKey - * @param [Object] object JSON object + * @param {Object} object JSON object */ createAutoClientMapping: function(host, applicationId, clientKey, authGrantKey, object) { @@ -95,12 +95,12 @@ object["clientKey"] = clientKey; object["authGrantKey"] = authGrantKey; - var uriFunction = function() + const uriFunction = function() { return "/webhosts/" + this.getId() + "/autoclientmappings"; }; - var chainable = this.getFactory().autoClientMapping(this); + const chainable = this.getFactory().autoClientMapping(this); return this.chainCreate(chainable, object, uriFunction); }, @@ -113,18 +113,18 @@ */ listAutoClientMappings: function(pagination) { - var params = {}; + const params = {}; if (pagination) { Gitana.copyInto(params, pagination); } - var uriFunction = function() + const uriFunction = function() { return "/webhosts/" + this.getId() + "/autoclientmappings"; }; - var chainable = this.getFactory().autoClientMappingMap(this); + const chainable = this.getFactory().autoClientMappingMap(this); return this.chainGet(chainable, uriFunction, params); }, @@ -137,14 +137,14 @@ */ readAutoClientMapping: function(autoClientMappingId) { - var self = this; + const self = this; - var uriFunction = function() + const uriFunction = function() { return self.getUri() + "/autoclientmappings/" + autoClientMappingId; }; - var chainable = this.getFactory().autoClientMapping(this); + const chainable = this.getFactory().autoClientMapping(this); return this.chainGet(chainable, uriFunction); }, @@ -154,24 +154,24 @@ * @chained auto client mappings map * * @param {Object} query - * @param [Object] pagination pagination (optional) + * @param {Object} pagination pagination (optional) */ queryAutoClientMappings: function(query, pagination) { - var self = this; + const self = this; - var params = {}; + const params = {}; if (pagination) { Gitana.copyInto(params, pagination); } - var uriFunction = function() + const uriFunction = function() { return self.getUri() + "/autoclientmappings/query"; }; - var chainable = this.getFactory().autoClientMappingMap(this); + const chainable = this.getFactory().autoClientMappingMap(this); return this.chainPost(chainable, uriFunction, params, query); }, @@ -202,14 +202,14 @@ */ checkAutoClientMappingsPermissions: function(checks, callback) { - var self = this; + const self = this; - var uriFunction = function() + const uriFunction = function() { return self.getUri() + "/autoclientmappings/permissions/check"; }; - var object = { + const object = { "checks": checks }; @@ -245,14 +245,14 @@ */ checkAutoClientMappingsAuthorities: function(checks, callback) { - var self = this; + const self = this; - var uriFunction = function() + const uriFunction = function() { return self.getUri() + "/autoclientmappings/authorities/check"; }; - var object = { + const object = { "checks": checks }; @@ -278,7 +278,7 @@ * @param host * @param scope * @param platformId - * @param [Object] object JSON object + * @param {Object} object JSON object */ createTrustedDomainMapping: function(host, scope, platformId, object) { @@ -296,12 +296,12 @@ object["scope"] = scope; object["platformId"] = platformId; - var uriFunction = function() + const uriFunction = function() { return "/webhosts/" + this.getId() + "/trusteddomainmappings"; }; - var chainable = this.getFactory().trustedDomainMapping(this); + const chainable = this.getFactory().trustedDomainMapping(this); return this.chainCreate(chainable, object, uriFunction); }, @@ -314,18 +314,18 @@ */ listTrustedDomainMappings: function(pagination) { - var params = {}; + const params = {}; if (pagination) { Gitana.copyInto(params, pagination); } - var uriFunction = function() + const uriFunction = function() { return "/webhosts/" + this.getId() + "/trusteddomainmappings"; }; - var chainable = this.getFactory().trustedDomainMappingMap(this); + const chainable = this.getFactory().trustedDomainMappingMap(this); return this.chainGet(chainable, uriFunction, params); }, @@ -338,14 +338,14 @@ */ readTrustedDomainMapping: function(trustedDomainMappingId) { - var self = this; + const self = this; - var uriFunction = function() + const uriFunction = function() { return self.getUri() + "/trusteddomainmappings/" + trustedDomainMappingId; }; - var chainable = this.getFactory().trustedDomainMapping(this); + const chainable = this.getFactory().trustedDomainMapping(this); return this.chainGet(chainable, uriFunction); }, @@ -355,24 +355,24 @@ * @chained trusted domain mappings map * * @param {Object} query - * @param [Object] pagination pagination (optional) + * @param {Object} pagination pagination (optional) */ queryTrustedDomainMappings: function(query, pagination) { - var self = this; + const self = this; - var params = {}; + const params = {}; if (pagination) { Gitana.copyInto(params, pagination); } - var uriFunction = function() + const uriFunction = function() { return self.getUri() + "/trusteddomainmappings/query"; }; - var chainable = this.getFactory().trustedDomainMappingMap(this); + const chainable = this.getFactory().trustedDomainMappingMap(this); return this.chainPost(chainable, uriFunction, params, query); }, @@ -403,14 +403,14 @@ */ checkTrustedDomainMappingsPermissions: function(checks, callback) { - var self = this; + const self = this; - var uriFunction = function() + const uriFunction = function() { return self.getUri() + "/trusteddomainmappings/permissions/check"; }; - var object = { + const object = { "checks": checks }; @@ -446,14 +446,14 @@ */ checkTrustedDomainMappingsAuthorities: function(checks, callback) { - var self = this; + const self = this; - var uriFunction = function() + const uriFunction = function() { return self.getUri() + "/trusteddomainmappings/authorities/check"; }; - var object = { + const object = { "checks": checks }; @@ -478,18 +478,18 @@ */ listDeployedApplications: function(pagination) { - var params = {}; + const params = {}; if (pagination) { Gitana.copyInto(params, pagination); } - var uriFunction = function() + const uriFunction = function() { return "/webhosts/" + this.getId() + "/applications"; }; - var chainable = this.getFactory().deployedApplicationMap(this); + const chainable = this.getFactory().deployedApplicationMap(this); return this.chainGet(chainable, uriFunction, params); }, @@ -502,12 +502,12 @@ */ readDeployedApplication: function(deployedApplicationId) { - var uriFunction = function() + const uriFunction = function() { return "/webhosts/" + this.getId() + "/applications/" + deployedApplicationId; }; - var chainable = this.getFactory().deployedApplication(this); + const chainable = this.getFactory().deployedApplication(this); return this.chainGet(chainable, uriFunction); }, @@ -517,24 +517,24 @@ * @chained deployed applications map * * @param {Object} query - * @param [Object] pagination pagination (optional) + * @param {Object} pagination pagination (optional) */ queryDeployedApplications: function(query, pagination) { - var self = this; + const self = this; - var params = {}; + const params = {}; if (pagination) { Gitana.copyInto(params, pagination); } - var uriFunction = function() + const uriFunction = function() { return self.getUri() + "/applications/query"; }; - var chainable = this.getFactory().deployedApplicationMap(this); + const chainable = this.getFactory().deployedApplicationMap(this); return this.chainPost(chainable, uriFunction, params, query); }, @@ -565,14 +565,14 @@ */ checkDeployedApplicationsPermissions: function(checks, callback) { - var self = this; + const self = this; - var uriFunction = function() + const uriFunction = function() { return self.getUri() + "/applications/permissions/check"; }; - var object = { + const object = { "checks": checks }; @@ -608,14 +608,14 @@ */ checkDeployedApplicationsAuthorities: function(checks, callback) { - var self = this; + const self = this; - var uriFunction = function() + const uriFunction = function() { return self.getUri() + "/applications/authorities/check"; }; - var object = { + const object = { "checks": checks }; diff --git a/js/gitana/webhost/WebHostMap.js b/js/gitana/webhost/WebHostMap.js index 064c9fe8..561b5cd8 100644 --- a/js/gitana/webhost/WebHostMap.js +++ b/js/gitana/webhost/WebHostMap.js @@ -1,6 +1,6 @@ (function(window) { - var Gitana = window.Gitana; + Gitana = window.Gitana; Gitana.WebHostMap = Gitana.AbstractPlatformObjectMap.extend( /** @lends Gitana.WebHostMap.prototype */ diff --git a/package-lock.json b/package-lock.json new file mode 100644 index 00000000..900b3a4e --- /dev/null +++ b/package-lock.json @@ -0,0 +1,2560 @@ +{ + "name": "gitanajs", + "version": "1.0.300", + "lockfileVersion": 1, + "requires": true, + "dependencies": { + "@babel/parser": { + "version": "7.4.5", + "resolved": "https://registry.npmjs.org/@babel/parser/-/parser-7.4.5.tgz", + "integrity": "sha512-9mUqkL1FF5T7f0WDFfAoDdiMVPWsdD1gZYzSnaXsxUCUqzuch/8of9G3VUSNiZmMBoRxT3neyVsqeiL/ZPcjew==", + "dev": true + }, + "abbrev": { + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/abbrev/-/abbrev-1.1.1.tgz", + "integrity": "sha512-nne9/IiQ/hzIhY6pdDnbBtz7DjPTKrY00P/zvPSm5pOFkl6xuGrGnXn/VtTNNfNtAfZ9/1RtehkszU9qcTii0Q==", + "dev": true + }, + "agent-base": { + "version": "4.3.0", + "resolved": "https://registry.npmjs.org/agent-base/-/agent-base-4.3.0.tgz", + "integrity": "sha512-salcGninV0nPrwpGNn4VTXBb1SOuXQBiqbrNXoeizJsHrsL6ERFM2Ne3JUSBWRE6aeNJI2ROP/WEEIDUiDe3cg==", + "dev": true, + "requires": { + "es6-promisify": "^5.0.0" + } + }, + "ansi-regex": { + "version": "2.1.1", + "resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-2.1.1.tgz", + "integrity": "sha1-w7M6te42DYbg5ijwRorn7yfWVN8=", + "dev": true + }, + "ansi-styles": { + "version": "2.2.1", + "resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-2.2.1.tgz", + "integrity": "sha1-tDLdM1i2NM914eRmQ2gkBTPB3b4=", + "dev": true + }, + "argparse": { + "version": "1.0.10", + "resolved": "https://registry.npmjs.org/argparse/-/argparse-1.0.10.tgz", + "integrity": "sha512-o5Roy6tNG4SL/FOkCAN6RzjiakZS25RLYFrcMttJqbdd8BWrnA+fGz57iN5Pb06pvBGvl5gQ0B48dJlslXvoTg==", + "dev": true, + "requires": { + "sprintf-js": "~1.0.2" + } + }, + "array-find-index": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/array-find-index/-/array-find-index-1.0.2.tgz", + "integrity": "sha1-3wEKoSh+Fku9pvlyOwqWoexBh6E=", + "dev": true + }, + "array-uniq": { + "version": "1.0.3", + "resolved": "https://registry.npmjs.org/array-uniq/-/array-uniq-1.0.3.tgz", + "integrity": "sha1-r2rId6Jcx/dOBYiUdThY39sk/bY=", + "dev": true + }, + "async": { + "version": "1.5.2", + "resolved": "https://registry.npmjs.org/async/-/async-1.5.2.tgz", + "integrity": "sha1-7GphrlZIDAw8skHJVhjiCJL5Zyo=", + "dev": true + }, + "async-limiter": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/async-limiter/-/async-limiter-1.0.0.tgz", + "integrity": "sha512-jp/uFnooOiO+L211eZOoSyzpOITMXx1rBITauYykG3BRYPu8h0UcxsPNB04RR5vo4Tyz3+ay17tR6JVf9qzYWg==", + "dev": true + }, + "aws-sdk": { + "version": "2.0.31", + "resolved": "https://registry.npmjs.org/aws-sdk/-/aws-sdk-2.0.31.tgz", + "integrity": "sha1-5yzx/caQFb2f0r3z07iMFlB9Jo4=", + "dev": true, + "requires": { + "xml2js": "0.2.6", + "xmlbuilder": "0.4.2" + } + }, + "balanced-match": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/balanced-match/-/balanced-match-1.0.0.tgz", + "integrity": "sha1-ibTRmasr7kneFk6gK4nORi1xt2c=", + "dev": true + }, + "bluebird": { + "version": "3.5.5", + "resolved": "https://registry.npmjs.org/bluebird/-/bluebird-3.5.5.tgz", + "integrity": "sha512-5am6HnnfN+urzt4yfg7IgTbotDjIT/u8AJpEt0sIU9FtXfVeezXAPKswrG+xKUCOYAINpSdgZVDU6QFh+cuH3w==", + "dev": true + }, + "brace-expansion": { + "version": "1.1.11", + "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-1.1.11.tgz", + "integrity": "sha512-iCuPHDFgrHX7H2vEI/5xpz07zSHB00TpugqhmYtVmMO6518mCuRMoOYFldEBl0g187ufozdaHgWKcYFb61qGiA==", + "dev": true, + "requires": { + "balanced-match": "^1.0.0", + "concat-map": "0.0.1" + } + }, + "buffer-crc32": { + "version": "0.2.1", + "resolved": "https://registry.npmjs.org/buffer-crc32/-/buffer-crc32-0.2.1.tgz", + "integrity": "sha1-vj5TgvwCttYySVasGvmKqYsIU0w=", + "dev": true + }, + "buffer-from": { + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/buffer-from/-/buffer-from-1.1.1.tgz", + "integrity": "sha512-MQcXEUbCKtEo7bhqEs6560Hyd4XaovZlO/k9V3hjVUF/zwW7KBVdSK4gIt/bzwS9MbR5qob+F5jusZsb0YQK2A==", + "dev": true + }, + "bytes": { + "version": "0.2.0", + "resolved": "https://registry.npmjs.org/bytes/-/bytes-0.2.0.tgz", + "integrity": "sha1-qtM+wU49wsp06OfUUfm6BTrU96A=", + "dev": true + }, + "camelcase": { + "version": "2.1.1", + "resolved": "https://registry.npmjs.org/camelcase/-/camelcase-2.1.1.tgz", + "integrity": "sha1-fB0W1nmhu+WcoCys7PsBHiAfWh8=", + "dev": true + }, + "camelcase-keys": { + "version": "2.1.0", + "resolved": "https://registry.npmjs.org/camelcase-keys/-/camelcase-keys-2.1.0.tgz", + "integrity": "sha1-MIvur/3ygRkFHvodkyITyRuPkuc=", + "dev": true, + "requires": { + "camelcase": "^2.0.0", + "map-obj": "^1.0.0" + } + }, + "catharsis": { + "version": "0.8.10", + "resolved": "https://registry.npmjs.org/catharsis/-/catharsis-0.8.10.tgz", + "integrity": "sha512-l2OUaz/3PU3MZylspVFJvwHCVfWyvcduPq4lv3AzZ2pJzZCo7kNKFNyatwujD7XgvGkNAE/Jhhbh2uARNwNkfw==", + "dev": true, + "requires": { + "lodash": "^4.17.11" + } + }, + "chalk": { + "version": "1.1.3", + "resolved": "https://registry.npmjs.org/chalk/-/chalk-1.1.3.tgz", + "integrity": "sha1-qBFcVeSnAv5NFQq9OHKCKn4J/Jg=", + "dev": true, + "requires": { + "ansi-styles": "^2.2.1", + "escape-string-regexp": "^1.0.2", + "has-ansi": "^2.0.0", + "strip-ansi": "^3.0.0", + "supports-color": "^2.0.0" + } + }, + "cli": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/cli/-/cli-1.0.1.tgz", + "integrity": "sha1-IoF1NPJL+klQw01TLUjsvGIbjBQ=", + "dev": true, + "requires": { + "exit": "0.1.2", + "glob": "^7.1.1" + }, + "dependencies": { + "glob": { + "version": "7.1.4", + "resolved": "https://registry.npmjs.org/glob/-/glob-7.1.4.tgz", + "integrity": "sha512-hkLPepehmnKk41pUGm3sYxoFs/umurYfYJCerbXEyFIWcAzvpipAgVkBqqT9RBKMGjnq6kMuyYwha6csxbiM1A==", + "dev": true, + "requires": { + "fs.realpath": "^1.0.0", + "inflight": "^1.0.4", + "inherits": "2", + "minimatch": "^3.0.4", + "once": "^1.3.0", + "path-is-absolute": "^1.0.0" + } + } + } + }, + "coffee-script": { + "version": "1.10.0", + "resolved": "https://registry.npmjs.org/coffee-script/-/coffee-script-1.10.0.tgz", + "integrity": "sha1-EpOLz5vhlI+gBvkuDEyegXBRCMA=", + "dev": true + }, + "color-convert": { + "version": "1.9.3", + "resolved": "https://registry.npmjs.org/color-convert/-/color-convert-1.9.3.tgz", + "integrity": "sha512-QfAUtd+vFdAtFQcC8CCyYt1fYWxSqAiK2cSD6zDB8N3cpsEBAvRxp9zOGg6G/SHHJYAT88/az/IuDGALsNVbGg==", + "dev": true, + "requires": { + "color-name": "1.1.3" + } + }, + "color-name": { + "version": "1.1.3", + "resolved": "https://registry.npmjs.org/color-name/-/color-name-1.1.3.tgz", + "integrity": "sha1-p9BVi9icQveV3UIyj3QIMcpTvCU=", + "dev": true + }, + "colors": { + "version": "1.1.2", + "resolved": "https://registry.npmjs.org/colors/-/colors-1.1.2.tgz", + "integrity": "sha1-FopHAXVran9RoSzgyXv6KMCE7WM=", + "dev": true + }, + "combined-stream": { + "version": "1.0.8", + "resolved": "https://registry.npmjs.org/combined-stream/-/combined-stream-1.0.8.tgz", + "integrity": "sha512-FQN4MRfuJeHf7cBbBMJFXhKSDq+2kAArBlmRBvcvFE5BB1HZKXtSFASDhdlz9zOYwxh8lDdnvmMOe/+5cdoEdg==", + "dev": true, + "requires": { + "delayed-stream": "~1.0.0" + } + }, + "commander": { + "version": "2.20.0", + "resolved": "https://registry.npmjs.org/commander/-/commander-2.20.0.tgz", + "integrity": "sha512-7j2y+40w61zy6YC2iRNpUe/NwhNyoXrYpHMrSunaMG64nRnaf96zO/KMQR4OyN/UnE5KLyEBnKHd4aG3rskjpQ==", + "dev": true + }, + "component-emitter": { + "version": "1.2.1", + "resolved": "https://registry.npmjs.org/component-emitter/-/component-emitter-1.2.1.tgz", + "integrity": "sha1-E3kY1teCg/ffemt8WmPhQOaUJeY=", + "dev": true + }, + "concat-map": { + "version": "0.0.1", + "resolved": "https://registry.npmjs.org/concat-map/-/concat-map-0.0.1.tgz", + "integrity": "sha1-2Klr13/Wjfd5OnMDajug1UBdR3s=", + "dev": true + }, + "concat-stream": { + "version": "1.6.2", + "resolved": "https://registry.npmjs.org/concat-stream/-/concat-stream-1.6.2.tgz", + "integrity": "sha512-27HBghJxjiZtIk3Ycvn/4kbJk/1uZuJFfuPEns6LaEvpvG1f0hTea8lilrouyo9mVc2GWdcEZ8OLoGmSADlrCw==", + "dev": true, + "requires": { + "buffer-from": "^1.0.0", + "inherits": "^2.0.3", + "readable-stream": "^2.2.2", + "typedarray": "^0.0.6" + }, + "dependencies": { + "isarray": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/isarray/-/isarray-1.0.0.tgz", + "integrity": "sha1-u5NdSFgsuhaMBoNJV6VKPgcSTxE=", + "dev": true + }, + "readable-stream": { + "version": "2.3.6", + "resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-2.3.6.tgz", + "integrity": "sha512-tQtKA9WIAhBF3+VLAseyMqZeBjW0AHJoxOtYqSUZNJxauErmLbVm2FW1y+J/YA9dUrAC39ITejlZWhVIwawkKw==", + "dev": true, + "requires": { + "core-util-is": "~1.0.0", + "inherits": "~2.0.3", + "isarray": "~1.0.0", + "process-nextick-args": "~2.0.0", + "safe-buffer": "~5.1.1", + "string_decoder": "~1.1.1", + "util-deprecate": "~1.0.1" + } + }, + "string_decoder": { + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/string_decoder/-/string_decoder-1.1.1.tgz", + "integrity": "sha512-n/ShnvDi6FHbbVfviro+WojiFzv+s8MPMHBczVePfUpDJLwoLT0ht1l4YwBCbi8pJAveEEdnkHyPyTP/mzRfwg==", + "dev": true, + "requires": { + "safe-buffer": "~5.1.0" + } + } + } + }, + "connect": { + "version": "2.7.11", + "resolved": "https://registry.npmjs.org/connect/-/connect-2.7.11.tgz", + "integrity": "sha1-9WHV7vcLjXGcOX9yTTS6QGXHej4=", + "dev": true, + "requires": { + "buffer-crc32": "0.2.1", + "bytes": "0.2.0", + "cookie": "0.0.5", + "cookie-signature": "1.0.1", + "debug": "*", + "formidable": "1.0.14", + "fresh": "0.1.0", + "pause": "0.0.1", + "qs": "0.6.5", + "send": "0.1.1" + } + }, + "connect-livereload": { + "version": "0.2.0", + "resolved": "https://registry.npmjs.org/connect-livereload/-/connect-livereload-0.2.0.tgz", + "integrity": "sha1-dXPPWHhG3/0Co+ZeMSK0cN1hXsk=", + "dev": true + }, + "console-browserify": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/console-browserify/-/console-browserify-1.1.0.tgz", + "integrity": "sha1-8CQcRXMKn8YyOyBtvzjtx0HQuxA=", + "dev": true, + "requires": { + "date-now": "^0.1.4" + } + }, + "cookie": { + "version": "0.0.5", + "resolved": "https://registry.npmjs.org/cookie/-/cookie-0.0.5.tgz", + "integrity": "sha1-+az521frdWjJ/MWWJWt7si4wfIE=", + "dev": true + }, + "cookie-signature": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/cookie-signature/-/cookie-signature-1.0.1.tgz", + "integrity": "sha1-ROByFIrwHm6OJK+/EmkNaK5pjss=", + "dev": true + }, + "cookiejar": { + "version": "2.0.6", + "resolved": "https://registry.npmjs.org/cookiejar/-/cookiejar-2.0.6.tgz", + "integrity": "sha1-Cr81atANHFohnYjURRgEbdAmrP4=", + "dev": true + }, + "core-util-is": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/core-util-is/-/core-util-is-1.0.2.tgz", + "integrity": "sha1-tf1UIgqivFq1eqtxQMlAdUUDwac=", + "dev": true + }, + "cross-spawn": { + "version": "6.0.5", + "resolved": "https://registry.npmjs.org/cross-spawn/-/cross-spawn-6.0.5.tgz", + "integrity": "sha512-eTVLrBSt7fjbDygz805pMnstIs2VTBNkRm0qxZd+M7A5XDdxVRWO5MxGBXZhjY4cqLYLdtrGqRf8mBPmzwSpWQ==", + "dev": true, + "requires": { + "nice-try": "^1.0.4", + "path-key": "^2.0.1", + "semver": "^5.5.0", + "shebang-command": "^1.2.0", + "which": "^1.2.9" + } + }, + "currently-unhandled": { + "version": "0.4.1", + "resolved": "https://registry.npmjs.org/currently-unhandled/-/currently-unhandled-0.4.1.tgz", + "integrity": "sha1-mI3zP+qxke95mmE2nddsF635V+o=", + "dev": true, + "requires": { + "array-find-index": "^1.0.1" + } + }, + "date-now": { + "version": "0.1.4", + "resolved": "https://registry.npmjs.org/date-now/-/date-now-0.1.4.tgz", + "integrity": "sha1-6vQ5/U1ISK105cx9vvIAZyueNFs=", + "dev": true + }, + "dateformat": { + "version": "1.0.12", + "resolved": "https://registry.npmjs.org/dateformat/-/dateformat-1.0.12.tgz", + "integrity": "sha1-nxJLZ1lMk3/3BpMuSmQsyo27/uk=", + "dev": true, + "requires": { + "get-stdin": "^4.0.1", + "meow": "^3.3.0" + } + }, + "debug": { + "version": "4.1.1", + "resolved": "https://registry.npmjs.org/debug/-/debug-4.1.1.tgz", + "integrity": "sha512-pYAIzeRo8J6KPEaJ0VWOh5Pzkbw/RetuzehGM7QRRX5he4fPHx2rdKMB256ehJCkX+XRQm16eZLqLNS8RSZXZw==", + "dev": true, + "requires": { + "ms": "^2.1.1" + } + }, + "decamelize": { + "version": "1.2.0", + "resolved": "https://registry.npmjs.org/decamelize/-/decamelize-1.2.0.tgz", + "integrity": "sha1-9lNNFRSCabIDUue+4m9QH5oZEpA=", + "dev": true + }, + "delayed-stream": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/delayed-stream/-/delayed-stream-1.0.0.tgz", + "integrity": "sha1-3zrhmayt+31ECqrgsp4icrJOxhk=", + "dev": true + }, + "dom-serializer": { + "version": "0.1.1", + "resolved": "https://registry.npmjs.org/dom-serializer/-/dom-serializer-0.1.1.tgz", + "integrity": "sha512-l0IU0pPzLWSHBcieZbpOKgkIn3ts3vAh7ZuFyXNwJxJXk/c4Gwj9xaTJwIDVQCXawWD0qb3IzMGH5rglQaO0XA==", + "dev": true, + "requires": { + "domelementtype": "^1.3.0", + "entities": "^1.1.1" + } + }, + "domelementtype": { + "version": "1.3.1", + "resolved": "https://registry.npmjs.org/domelementtype/-/domelementtype-1.3.1.tgz", + "integrity": "sha512-BSKB+TSpMpFI/HOxCNr1O8aMOTZ8hT3pM3GQ0w/mWRmkhEDSFJkkyzz4XQsBV44BChwGkrDfMyjVD0eA2aFV3w==", + "dev": true + }, + "domhandler": { + "version": "2.4.2", + "resolved": "https://registry.npmjs.org/domhandler/-/domhandler-2.4.2.tgz", + "integrity": "sha512-JiK04h0Ht5u/80fdLMCEmV4zkNh2BcoMFBmZ/91WtYZ8qVXSKjiw7fXMgFPnHcSZgOo3XdinHvmnDUeMf5R4wA==", + "dev": true, + "requires": { + "domelementtype": "1" + } + }, + "domutils": { + "version": "1.7.0", + "resolved": "https://registry.npmjs.org/domutils/-/domutils-1.7.0.tgz", + "integrity": "sha512-Lgd2XcJ/NjEw+7tFvfKxOzCYKZsdct5lczQ2ZaQY8Djz7pfAD3Gbp8ySJWtreII/vDlMVmxwa6pHmdxIYgttDg==", + "dev": true, + "requires": { + "dom-serializer": "0", + "domelementtype": "1" + } + }, + "entities": { + "version": "1.1.2", + "resolved": "https://registry.npmjs.org/entities/-/entities-1.1.2.tgz", + "integrity": "sha512-f2LZMYl1Fzu7YSBKg+RoROelpOaNrcGmE9AZubeDfrCEia483oW4MI4VyFd5VNHIgQ/7qm1I0wUHK1eJnn2y2w==", + "dev": true + }, + "error-ex": { + "version": "1.3.2", + "resolved": "https://registry.npmjs.org/error-ex/-/error-ex-1.3.2.tgz", + "integrity": "sha512-7dFHNmqeFSEt2ZBsCriorKnn3Z2pj+fd9kmI6QoWw4//DL+icEBfc0U7qJCisqrTsKTjw4fNFy2pW9OqStD84g==", + "dev": true, + "requires": { + "is-arrayish": "^0.2.1" + } + }, + "es6-promise": { + "version": "4.2.8", + "resolved": "https://registry.npmjs.org/es6-promise/-/es6-promise-4.2.8.tgz", + "integrity": "sha512-HJDGx5daxeIvxdBxvG2cb9g4tEvwIk3i8+nhX0yGrYmZUzbkdg8QbDevheDB8gd0//uPj4c1EQua8Q+MViT0/w==", + "dev": true + }, + "es6-promisify": { + "version": "5.0.0", + "resolved": "https://registry.npmjs.org/es6-promisify/-/es6-promisify-5.0.0.tgz", + "integrity": "sha1-UQnWLz5W6pZ8S2NQWu8IKRyKUgM=", + "dev": true, + "requires": { + "es6-promise": "^4.0.3" + } + }, + "escape-string-regexp": { + "version": "1.0.5", + "resolved": "https://registry.npmjs.org/escape-string-regexp/-/escape-string-regexp-1.0.5.tgz", + "integrity": "sha1-G2HAViGQqN/2rjuyzwIAyhMLhtQ=", + "dev": true + }, + "esprima": { + "version": "2.7.3", + "resolved": "https://registry.npmjs.org/esprima/-/esprima-2.7.3.tgz", + "integrity": "sha1-luO3DVd59q1JzQMmc9HDEnZ7pYE=", + "dev": true + }, + "eventemitter2": { + "version": "0.4.14", + "resolved": "https://registry.npmjs.org/eventemitter2/-/eventemitter2-0.4.14.tgz", + "integrity": "sha1-j2G3XN4BKy6esoTUVFWDtWQ7Yas=", + "dev": true + }, + "eventemitter3": { + "version": "1.2.0", + "resolved": "https://registry.npmjs.org/eventemitter3/-/eventemitter3-1.2.0.tgz", + "integrity": "sha1-HIaZHYFq0eUEdQ5zh0Ik7PO+xQg=", + "dev": true + }, + "exit": { + "version": "0.1.2", + "resolved": "https://registry.npmjs.org/exit/-/exit-0.1.2.tgz", + "integrity": "sha1-BjJjj42HfMghB9MKD/8aF8uhzQw=", + "dev": true + }, + "extend": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/extend/-/extend-3.0.0.tgz", + "integrity": "sha1-WkdDU7nzNT3dgXbf03uRyDpG8dQ=", + "dev": true + }, + "extract-zip": { + "version": "1.6.7", + "resolved": "https://registry.npmjs.org/extract-zip/-/extract-zip-1.6.7.tgz", + "integrity": "sha1-qEC0uK9kAyZMjbV/Txp0Mz74H+k=", + "dev": true, + "requires": { + "concat-stream": "1.6.2", + "debug": "2.6.9", + "mkdirp": "0.5.1", + "yauzl": "2.4.1" + }, + "dependencies": { + "debug": { + "version": "2.6.9", + "resolved": "https://registry.npmjs.org/debug/-/debug-2.6.9.tgz", + "integrity": "sha512-bC7ElrdJaJnPbAP+1EotYvqZsb3ecl5wi6Bfi6BJTUcNowp6cvspg0jXznRTKDjm/E7AdgFBVeAPVMNcKGsHMA==", + "dev": true, + "requires": { + "ms": "2.0.0" + } + }, + "ms": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/ms/-/ms-2.0.0.tgz", + "integrity": "sha1-VgiurfwAvmwpAd9fmGF4jeDVl8g=", + "dev": true + } + } + }, + "fd-slicer": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/fd-slicer/-/fd-slicer-1.0.1.tgz", + "integrity": "sha1-i1vL2ewyfFBBv5qwI/1nUPEXfmU=", + "dev": true, + "requires": { + "pend": "~1.2.0" + } + }, + "find-up": { + "version": "1.1.2", + "resolved": "https://registry.npmjs.org/find-up/-/find-up-1.1.2.tgz", + "integrity": "sha1-ay6YIrGizgpgq2TWEOzK1TyyTQ8=", + "dev": true, + "requires": { + "path-exists": "^2.0.0", + "pinkie-promise": "^2.0.0" + } + }, + "findup-sync": { + "version": "0.3.0", + "resolved": "https://registry.npmjs.org/findup-sync/-/findup-sync-0.3.0.tgz", + "integrity": "sha1-N5MKpdgWt3fANEXhlmzGeQpMCxY=", + "dev": true, + "requires": { + "glob": "~5.0.0" + }, + "dependencies": { + "glob": { + "version": "5.0.15", + "resolved": "https://registry.npmjs.org/glob/-/glob-5.0.15.tgz", + "integrity": "sha1-G8k2ueAvSmA/zCIuz3Yz0wuLk7E=", + "dev": true, + "requires": { + "inflight": "^1.0.4", + "inherits": "2", + "minimatch": "2 || 3", + "once": "^1.3.0", + "path-is-absolute": "^1.0.0" + } + } + } + }, + "form-data": { + "version": "1.0.0-rc3", + "resolved": "https://registry.npmjs.org/form-data/-/form-data-1.0.0-rc3.tgz", + "integrity": "sha1-01vGLn+8KTeuePlIqqDTjZBgdXc=", + "dev": true, + "requires": { + "async": "^1.4.0", + "combined-stream": "^1.0.5", + "mime-types": "^2.1.3" + }, + "dependencies": { + "mime-db": { + "version": "1.40.0", + "resolved": "https://registry.npmjs.org/mime-db/-/mime-db-1.40.0.tgz", + "integrity": "sha512-jYdeOMPy9vnxEqFRRo6ZvTZ8d9oPb+k18PKoYNYUe2stVEBPPwsln/qWzdbmaIvnhZ9v2P+CuecK+fpUfsV2mA==", + "dev": true + }, + "mime-types": { + "version": "2.1.24", + "resolved": "https://registry.npmjs.org/mime-types/-/mime-types-2.1.24.tgz", + "integrity": "sha512-WaFHS3MCl5fapm3oLxU4eYDw77IQM2ACcxQ9RIxfaC3ooc6PFuBMGZZsYpvoXS5D5QTWPieo1jjLdAm3TBP3cQ==", + "dev": true, + "requires": { + "mime-db": "1.40.0" + } + } + } + }, + "formidable": { + "version": "1.0.14", + "resolved": "https://registry.npmjs.org/formidable/-/formidable-1.0.14.tgz", + "integrity": "sha1-Kz9MQRy7X91pXESEPiojUUpDIxo=", + "dev": true + }, + "fresh": { + "version": "0.1.0", + "resolved": "https://registry.npmjs.org/fresh/-/fresh-0.1.0.tgz", + "integrity": "sha1-A+SwF4Qk5MLV0ZpU2IFM3JeTSFA=", + "dev": true + }, + "fs.realpath": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/fs.realpath/-/fs.realpath-1.0.0.tgz", + "integrity": "sha1-FQStJSMVjKpA20onh8sBQRmU6k8=", + "dev": true + }, + "get-stdin": { + "version": "4.0.1", + "resolved": "https://registry.npmjs.org/get-stdin/-/get-stdin-4.0.1.tgz", + "integrity": "sha1-uWjGsKBDhDJJAui/Gl3zJXmkUP4=", + "dev": true + }, + "getobject": { + "version": "0.1.0", + "resolved": "https://registry.npmjs.org/getobject/-/getobject-0.1.0.tgz", + "integrity": "sha1-BHpEl4n6Fg0Bj1SG7ZEyC27HiFw=", + "dev": true + }, + "glob": { + "version": "7.0.6", + "resolved": "https://registry.npmjs.org/glob/-/glob-7.0.6.tgz", + "integrity": "sha1-IRuvr0nlJbjNkyYNFKsTYVKz9Xo=", + "dev": true, + "requires": { + "fs.realpath": "^1.0.0", + "inflight": "^1.0.4", + "inherits": "2", + "minimatch": "^3.0.2", + "once": "^1.3.0", + "path-is-absolute": "^1.0.0" + } + }, + "graceful-fs": { + "version": "4.1.15", + "resolved": "https://registry.npmjs.org/graceful-fs/-/graceful-fs-4.1.15.tgz", + "integrity": "sha512-6uHUhOPEBgQ24HM+r6b/QwWfZq+yiFcipKFrOFiBEnWdy5sdzYoi+pJeQaPI5qOLRFqWmAXUPQNsielzdLoecA==", + "dev": true + }, + "grunt": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/grunt/-/grunt-1.0.1.tgz", + "integrity": "sha1-6HeHZOlEsY8yuw8QuQeEdcnftWs=", + "dev": true, + "requires": { + "coffee-script": "~1.10.0", + "dateformat": "~1.0.12", + "eventemitter2": "~0.4.13", + "exit": "~0.1.1", + "findup-sync": "~0.3.0", + "glob": "~7.0.0", + "grunt-cli": "~1.2.0", + "grunt-known-options": "~1.1.0", + "grunt-legacy-log": "~1.0.0", + "grunt-legacy-util": "~1.0.0", + "iconv-lite": "~0.4.13", + "js-yaml": "~3.5.2", + "minimatch": "~3.0.0", + "nopt": "~3.0.6", + "path-is-absolute": "~1.0.0", + "rimraf": "~2.2.8" + }, + "dependencies": { + "grunt-cli": { + "version": "1.2.0", + "resolved": "https://registry.npmjs.org/grunt-cli/-/grunt-cli-1.2.0.tgz", + "integrity": "sha1-VisRnrsGndtGSs4oRVAb6Xs1tqg=", + "dev": true, + "requires": { + "findup-sync": "~0.3.0", + "grunt-known-options": "~1.1.0", + "nopt": "~3.0.6", + "resolve": "~1.1.0" + } + }, + "resolve": { + "version": "1.1.7", + "resolved": "https://registry.npmjs.org/resolve/-/resolve-1.1.7.tgz", + "integrity": "sha1-IDEU2CrSxe2ejgQRs5ModeiJ6Xs=", + "dev": true + } + } + }, + "grunt-aws-s3": { + "version": "0.14.5", + "resolved": "https://registry.npmjs.org/grunt-aws-s3/-/grunt-aws-s3-0.14.5.tgz", + "integrity": "sha1-9VAZrPvrBbibJFpRzPGoHb+GjfQ=", + "dev": true, + "requires": { + "async": "0.9.x", + "aws-sdk": "2.0.x", + "lodash": "2.4.x", + "mime-types": "2.0.x", + "progress": "1.1.x" + }, + "dependencies": { + "async": { + "version": "0.9.2", + "resolved": "https://registry.npmjs.org/async/-/async-0.9.2.tgz", + "integrity": "sha1-rqdNXmHB+JlhO/ZL2mbUx48v0X0=", + "dev": true + }, + "lodash": { + "version": "2.4.2", + "resolved": "https://registry.npmjs.org/lodash/-/lodash-2.4.2.tgz", + "integrity": "sha1-+t2DS5aDBz2hebPq5tnA0VBT9z4=", + "dev": true + } + } + }, + "grunt-bumpup": { + "version": "0.6.3", + "resolved": "https://registry.npmjs.org/grunt-bumpup/-/grunt-bumpup-0.6.3.tgz", + "integrity": "sha1-dU6Wu2pTN9C5VInl3EmWuvyLtBQ=", + "dev": true, + "requires": { + "moment": "^2.8.3", + "semver": "^4.0.3" + }, + "dependencies": { + "semver": { + "version": "4.3.6", + "resolved": "https://registry.npmjs.org/semver/-/semver-4.3.6.tgz", + "integrity": "sha1-MAvG4OhjdPe6YQaLWx7NV/xlMto=", + "dev": true + } + } + }, + "grunt-cloudfront": { + "version": "0.2.2", + "resolved": "https://registry.npmjs.org/grunt-cloudfront/-/grunt-cloudfront-0.2.2.tgz", + "integrity": "sha1-GsvTBRpA/pDB7PoEQVgqcwwswQs=", + "dev": true, + "requires": { + "aws-sdk": "2.2.18", + "grunt": "~0.4.1", + "moment": "~2.0.0", + "underscore": "~1.4.4" + }, + "dependencies": { + "argparse": { + "version": "0.1.16", + "resolved": "https://registry.npmjs.org/argparse/-/argparse-0.1.16.tgz", + "integrity": "sha1-z9AeD7uj1srtBJ+9dY1A9lGW9Xw=", + "dev": true, + "requires": { + "underscore": "~1.7.0", + "underscore.string": "~2.4.0" + }, + "dependencies": { + "underscore": { + "version": "1.7.0", + "resolved": "https://registry.npmjs.org/underscore/-/underscore-1.7.0.tgz", + "integrity": "sha1-a7rwh3UA02vjTsqlhODbn+8DUgk=", + "dev": true + }, + "underscore.string": { + "version": "2.4.0", + "resolved": "https://registry.npmjs.org/underscore.string/-/underscore.string-2.4.0.tgz", + "integrity": "sha1-jN2PusTi0uoefi6Al8QvRCKA+Fs=", + "dev": true + } + } + }, + "async": { + "version": "0.1.22", + "resolved": "https://registry.npmjs.org/async/-/async-0.1.22.tgz", + "integrity": "sha1-D8GqoIig4+8Ovi2IMbqw3PiEUGE=", + "dev": true + }, + "aws-sdk": { + "version": "2.2.18", + "resolved": "https://registry.npmjs.org/aws-sdk/-/aws-sdk-2.2.18.tgz", + "integrity": "sha1-vsPBEbGfgzp4a8333ViBRnjX+k8=", + "dev": true, + "requires": { + "sax": "0.5.3", + "xml2js": "0.2.8", + "xmlbuilder": "0.4.2" + } + }, + "coffee-script": { + "version": "1.3.3", + "resolved": "https://registry.npmjs.org/coffee-script/-/coffee-script-1.3.3.tgz", + "integrity": "sha1-FQ1rTLUiiUNp7+1qIQHCC8f0pPQ=", + "dev": true + }, + "colors": { + "version": "0.6.2", + "resolved": "https://registry.npmjs.org/colors/-/colors-0.6.2.tgz", + "integrity": "sha1-JCP+ZnisDF2uiFLl0OW+CMmXq8w=", + "dev": true + }, + "dateformat": { + "version": "1.0.2-1.2.3", + "resolved": "https://registry.npmjs.org/dateformat/-/dateformat-1.0.2-1.2.3.tgz", + "integrity": "sha1-sCIMAt6YYXQztyhRz0fePfLNvuk=", + "dev": true + }, + "esprima": { + "version": "1.0.4", + "resolved": "https://registry.npmjs.org/esprima/-/esprima-1.0.4.tgz", + "integrity": "sha1-n1V+CPw7TSbs6d00+Pv0drYlha0=", + "dev": true + }, + "findup-sync": { + "version": "0.1.3", + "resolved": "https://registry.npmjs.org/findup-sync/-/findup-sync-0.1.3.tgz", + "integrity": "sha1-fz56l7gjksZTvwZYm9hRkOk8NoM=", + "dev": true, + "requires": { + "glob": "~3.2.9", + "lodash": "~2.4.1" + }, + "dependencies": { + "glob": { + "version": "3.2.11", + "resolved": "https://registry.npmjs.org/glob/-/glob-3.2.11.tgz", + "integrity": "sha1-Spc/Y1uRkPcV0QmH1cAP0oFevj0=", + "dev": true, + "requires": { + "inherits": "2", + "minimatch": "0.3" + } + }, + "lodash": { + "version": "2.4.2", + "resolved": "https://registry.npmjs.org/lodash/-/lodash-2.4.2.tgz", + "integrity": "sha1-+t2DS5aDBz2hebPq5tnA0VBT9z4=", + "dev": true + }, + "minimatch": { + "version": "0.3.0", + "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-0.3.0.tgz", + "integrity": "sha1-J12O2qxPG7MyZHIInnlJyDlGmd0=", + "dev": true, + "requires": { + "lru-cache": "2", + "sigmund": "~1.0.0" + } + } + } + }, + "glob": { + "version": "3.1.21", + "resolved": "https://registry.npmjs.org/glob/-/glob-3.1.21.tgz", + "integrity": "sha1-0p4KBV3qUTj00H7UDomC6DwgZs0=", + "dev": true, + "requires": { + "graceful-fs": "~1.2.0", + "inherits": "1", + "minimatch": "~0.2.11" + }, + "dependencies": { + "inherits": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/inherits/-/inherits-1.0.2.tgz", + "integrity": "sha1-ykMJ2t7mtUzAuNJH6NfHoJdb3Js=", + "dev": true + } + } + }, + "graceful-fs": { + "version": "1.2.3", + "resolved": "https://registry.npmjs.org/graceful-fs/-/graceful-fs-1.2.3.tgz", + "integrity": "sha1-FaSAaldUfLLS2/J/QuiajDRRs2Q=", + "dev": true + }, + "grunt": { + "version": "0.4.5", + "resolved": "https://registry.npmjs.org/grunt/-/grunt-0.4.5.tgz", + "integrity": "sha1-VpN81RlDJK3/bSB2MYMqnWuk5/A=", + "dev": true, + "requires": { + "async": "~0.1.22", + "coffee-script": "~1.3.3", + "colors": "~0.6.2", + "dateformat": "1.0.2-1.2.3", + "eventemitter2": "~0.4.13", + "exit": "~0.1.1", + "findup-sync": "~0.1.2", + "getobject": "~0.1.0", + "glob": "~3.1.21", + "grunt-legacy-log": "~0.1.0", + "grunt-legacy-util": "~0.2.0", + "hooker": "~0.2.3", + "iconv-lite": "~0.2.11", + "js-yaml": "~2.0.5", + "lodash": "~0.9.2", + "minimatch": "~0.2.12", + "nopt": "~1.0.10", + "rimraf": "~2.2.8", + "underscore.string": "~2.2.1", + "which": "~1.0.5" + } + }, + "grunt-legacy-log": { + "version": "0.1.3", + "resolved": "https://registry.npmjs.org/grunt-legacy-log/-/grunt-legacy-log-0.1.3.tgz", + "integrity": "sha1-7ClCboAwIa9ZAp+H0vnNczWgVTE=", + "dev": true, + "requires": { + "colors": "~0.6.2", + "grunt-legacy-log-utils": "~0.1.1", + "hooker": "~0.2.3", + "lodash": "~2.4.1", + "underscore.string": "~2.3.3" + }, + "dependencies": { + "lodash": { + "version": "2.4.2", + "resolved": "https://registry.npmjs.org/lodash/-/lodash-2.4.2.tgz", + "integrity": "sha1-+t2DS5aDBz2hebPq5tnA0VBT9z4=", + "dev": true + }, + "underscore.string": { + "version": "2.3.3", + "resolved": "https://registry.npmjs.org/underscore.string/-/underscore.string-2.3.3.tgz", + "integrity": "sha1-ccCL9rQosRM/N+ePo6Icgvcymw0=", + "dev": true + } + } + }, + "grunt-legacy-log-utils": { + "version": "0.1.1", + "resolved": "https://registry.npmjs.org/grunt-legacy-log-utils/-/grunt-legacy-log-utils-0.1.1.tgz", + "integrity": "sha1-wHBrndkGThFvNvI/5OawSGcsD34=", + "dev": true, + "requires": { + "colors": "~0.6.2", + "lodash": "~2.4.1", + "underscore.string": "~2.3.3" + }, + "dependencies": { + "lodash": { + "version": "2.4.2", + "resolved": "https://registry.npmjs.org/lodash/-/lodash-2.4.2.tgz", + "integrity": "sha1-+t2DS5aDBz2hebPq5tnA0VBT9z4=", + "dev": true + }, + "underscore.string": { + "version": "2.3.3", + "resolved": "https://registry.npmjs.org/underscore.string/-/underscore.string-2.3.3.tgz", + "integrity": "sha1-ccCL9rQosRM/N+ePo6Icgvcymw0=", + "dev": true + } + } + }, + "grunt-legacy-util": { + "version": "0.2.0", + "resolved": "https://registry.npmjs.org/grunt-legacy-util/-/grunt-legacy-util-0.2.0.tgz", + "integrity": "sha1-kzJIhNv343qf98Am3/RR2UqeVUs=", + "dev": true, + "requires": { + "async": "~0.1.22", + "exit": "~0.1.1", + "getobject": "~0.1.0", + "hooker": "~0.2.3", + "lodash": "~0.9.2", + "underscore.string": "~2.2.1", + "which": "~1.0.5" + } + }, + "iconv-lite": { + "version": "0.2.11", + "resolved": "https://registry.npmjs.org/iconv-lite/-/iconv-lite-0.2.11.tgz", + "integrity": "sha1-HOYKOleGSiktEyH/RgnKS7llrcg=", + "dev": true + }, + "js-yaml": { + "version": "2.0.5", + "resolved": "https://registry.npmjs.org/js-yaml/-/js-yaml-2.0.5.tgz", + "integrity": "sha1-olrmUJmZ6X3yeMZxnaEb0Gh3Q6g=", + "dev": true, + "requires": { + "argparse": "~ 0.1.11", + "esprima": "~ 1.0.2" + } + }, + "lodash": { + "version": "0.9.2", + "resolved": "https://registry.npmjs.org/lodash/-/lodash-0.9.2.tgz", + "integrity": "sha1-jzSZxSRdNG1oLlsNO0B2fgnxqSw=", + "dev": true + }, + "minimatch": { + "version": "0.2.14", + "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-0.2.14.tgz", + "integrity": "sha1-x054BXT2PG+aCQ6Q775u9TpqdWo=", + "dev": true, + "requires": { + "lru-cache": "2", + "sigmund": "~1.0.0" + } + }, + "moment": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/moment/-/moment-2.0.0.tgz", + "integrity": "sha1-K7xbRMMhg3aTq278rb1G7ZRiEf4=", + "dev": true + }, + "nopt": { + "version": "1.0.10", + "resolved": "https://registry.npmjs.org/nopt/-/nopt-1.0.10.tgz", + "integrity": "sha1-bd0hvSoxQXuScn3Vhfim83YI6+4=", + "dev": true, + "requires": { + "abbrev": "1" + } + }, + "sax": { + "version": "0.5.3", + "resolved": "https://registry.npmjs.org/sax/-/sax-0.5.3.tgz", + "integrity": "sha1-N3NxSg2RV8qqcwKXHvpcbc2lUtY=", + "dev": true + }, + "underscore": { + "version": "1.4.4", + "resolved": "https://registry.npmjs.org/underscore/-/underscore-1.4.4.tgz", + "integrity": "sha1-YaajIBBiKvoHljvzJSA88SI51gQ=", + "dev": true + }, + "underscore.string": { + "version": "2.2.1", + "resolved": "https://registry.npmjs.org/underscore.string/-/underscore.string-2.2.1.tgz", + "integrity": "sha1-18D6KvXVoaZ/QlPa7pgTLnM/Dxk=", + "dev": true + }, + "which": { + "version": "1.0.9", + "resolved": "https://registry.npmjs.org/which/-/which-1.0.9.tgz", + "integrity": "sha1-RgwdoPgQED0DIam2M6+eV15kSG8=", + "dev": true + }, + "xml2js": { + "version": "0.2.8", + "resolved": "https://registry.npmjs.org/xml2js/-/xml2js-0.2.8.tgz", + "integrity": "sha1-m4FpCTFjH/CdGVdUn69U9PmAs8I=", + "dev": true, + "requires": { + "sax": "0.5.x" + } + } + } + }, + "grunt-connect-proxy": { + "version": "0.2.0", + "resolved": "https://registry.npmjs.org/grunt-connect-proxy/-/grunt-connect-proxy-0.2.0.tgz", + "integrity": "sha1-XUzoJ7VQgKj11VNgyA9KtWJvRvg=", + "dev": true, + "requires": { + "http-proxy": "~1.11.0", + "lodash": "~0.9.0" + }, + "dependencies": { + "lodash": { + "version": "0.9.2", + "resolved": "https://registry.npmjs.org/lodash/-/lodash-0.9.2.tgz", + "integrity": "sha1-jzSZxSRdNG1oLlsNO0B2fgnxqSw=", + "dev": true + } + } + }, + "grunt-contrib-connect": { + "version": "0.5.0", + "resolved": "https://registry.npmjs.org/grunt-contrib-connect/-/grunt-contrib-connect-0.5.0.tgz", + "integrity": "sha1-AzC+NyTj7u9DhXiyYwjK0wL1+mM=", + "dev": true, + "requires": { + "connect": "~2.7.11", + "connect-livereload": "~0.2.0", + "open": "0.0.4" + } + }, + "grunt-contrib-jshint": { + "version": "2.1.0", + "resolved": "https://registry.npmjs.org/grunt-contrib-jshint/-/grunt-contrib-jshint-2.1.0.tgz", + "integrity": "sha512-65S2/C/6RfjY/umTxfwXXn+wVvaYmykHkHSsW6Q6rhkbv3oudTEgqnFFZvWzWCoHUb+3GMZLbP3oSrNyvshmIQ==", + "dev": true, + "requires": { + "chalk": "^2.4.2", + "hooker": "^0.2.3", + "jshint": "~2.10.2" + }, + "dependencies": { + "ansi-styles": { + "version": "3.2.1", + "resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-3.2.1.tgz", + "integrity": "sha512-VT0ZI6kZRdTh8YyJw3SMbYm/u+NqfsAxEpWO0Pf9sq8/e94WxxOpPKx9FR1FlyCtOVDNOQ+8ntlqFxiRc+r5qA==", + "dev": true, + "requires": { + "color-convert": "^1.9.0" + } + }, + "chalk": { + "version": "2.4.2", + "resolved": "https://registry.npmjs.org/chalk/-/chalk-2.4.2.tgz", + "integrity": "sha512-Mti+f9lpJNcwF4tWV8/OrTTtF1gZi+f8FqlyAdouralcFWFQWF2+NgCHShjkCb+IFBLq9buZwE1xckQU4peSuQ==", + "dev": true, + "requires": { + "ansi-styles": "^3.2.1", + "escape-string-regexp": "^1.0.5", + "supports-color": "^5.3.0" + } + }, + "supports-color": { + "version": "5.5.0", + "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-5.5.0.tgz", + "integrity": "sha512-QjVjwdXIt408MIiAqCX4oUKsgU2EqAGzs2Ppkm4aQYbjm+ZEWEcW4SfFNTr4uMNZma0ey4f5lgLrkB0aX0QMow==", + "dev": true, + "requires": { + "has-flag": "^3.0.0" + } + } + } + }, + "grunt-contrib-qunit": { + "version": "3.1.0", + "resolved": "https://registry.npmjs.org/grunt-contrib-qunit/-/grunt-contrib-qunit-3.1.0.tgz", + "integrity": "sha512-mdk8UltH6mxCD63E0hTXMAts42DOi4z4bBBrY7qnuHiShflMF7IueSMYe0zWaZ2dO8mgujh57Zfny2EbigJhRg==", + "dev": true, + "requires": { + "eventemitter2": "^5.0.1", + "p-each-series": "^1.0.0", + "puppeteer": "^1.11.0" + }, + "dependencies": { + "eventemitter2": { + "version": "5.0.1", + "resolved": "https://registry.npmjs.org/eventemitter2/-/eventemitter2-5.0.1.tgz", + "integrity": "sha1-YZegldX7a1folC9v1+qtY6CclFI=", + "dev": true + } + } + }, + "grunt-exec": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/grunt-exec/-/grunt-exec-3.0.0.tgz", + "integrity": "sha512-cgAlreXf3muSYS5LzW0Cc4xHK03BjFOYk0MqCQ/MZ3k1Xz2GU7D+IAJg4UKicxpO+XdONJdx/NJ6kpy2wI+uHg==", + "dev": true + }, + "grunt-invalidate-cloudfront": { + "version": "0.1.6", + "resolved": "https://registry.npmjs.org/grunt-invalidate-cloudfront/-/grunt-invalidate-cloudfront-0.1.6.tgz", + "integrity": "sha1-NaJRIHgMSSb3j+prh1bekXAIKT4=", + "dev": true, + "requires": { + "aws-sdk": "~2.0.0-rc5" + } + }, + "grunt-jsdoc": { + "version": "2.4.0", + "resolved": "https://registry.npmjs.org/grunt-jsdoc/-/grunt-jsdoc-2.4.0.tgz", + "integrity": "sha512-JpZd1W7HbK0sHbpiL9+VyDFwZlkYoDQMaP+v6z1R23W/NYLoqJM76L9eBOr7O6NycqtddRHN5DzlSkW45MJ82w==", + "dev": true, + "requires": { + "cross-spawn": "^6.0.5", + "jsdoc": "~3.6.0" + } + }, + "grunt-known-options": { + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/grunt-known-options/-/grunt-known-options-1.1.1.tgz", + "integrity": "sha512-cHwsLqoighpu7TuYj5RonnEuxGVFnztcUqTqp5rXFGYL4OuPFofwC4Ycg7n9fYwvK6F5WbYgeVOwph9Crs2fsQ==", + "dev": true + }, + "grunt-legacy-log": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/grunt-legacy-log/-/grunt-legacy-log-1.0.2.tgz", + "integrity": "sha512-WdedTJ/6zCXnI/coaouzqvkI19uwqbcPkdsXiDRKJyB5rOUlOxnCnTVbpeUdEckKVir2uHF3rDBYppj2p6N3+g==", + "dev": true, + "requires": { + "colors": "~1.1.2", + "grunt-legacy-log-utils": "~1.0.0", + "hooker": "~0.2.3", + "lodash": "~4.17.5" + } + }, + "grunt-legacy-log-utils": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/grunt-legacy-log-utils/-/grunt-legacy-log-utils-1.0.0.tgz", + "integrity": "sha1-p7ji0Ps1taUPSvmG/BEnSevJbz0=", + "dev": true, + "requires": { + "chalk": "~1.1.1", + "lodash": "~4.3.0" + }, + "dependencies": { + "lodash": { + "version": "4.3.0", + "resolved": "https://registry.npmjs.org/lodash/-/lodash-4.3.0.tgz", + "integrity": "sha1-79nEpuxT87BUEkKZFcPkgk5NJaQ=", + "dev": true + } + } + }, + "grunt-legacy-util": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/grunt-legacy-util/-/grunt-legacy-util-1.0.0.tgz", + "integrity": "sha1-OGqnjcbtUJhsKxiVcmWxtIq7m4Y=", + "dev": true, + "requires": { + "async": "~1.5.2", + "exit": "~0.1.1", + "getobject": "~0.1.0", + "hooker": "~0.2.3", + "lodash": "~4.3.0", + "underscore.string": "~3.2.3", + "which": "~1.2.1" + }, + "dependencies": { + "lodash": { + "version": "4.3.0", + "resolved": "https://registry.npmjs.org/lodash/-/lodash-4.3.0.tgz", + "integrity": "sha1-79nEpuxT87BUEkKZFcPkgk5NJaQ=", + "dev": true + } + } + }, + "grunt-release": { + "version": "0.14.0", + "resolved": "https://registry.npmjs.org/grunt-release/-/grunt-release-0.14.0.tgz", + "integrity": "sha1-uNYAiJVhlm1g/9zAYGfrAVWX940=", + "dev": true, + "requires": { + "q": "^1.4.1", + "semver": "^5.1.0", + "shelljs": "^0.7.0", + "superagent": "^1.8.3" + } + }, + "grunt-terser": { + "version": "0.1.0", + "resolved": "https://registry.npmjs.org/grunt-terser/-/grunt-terser-0.1.0.tgz", + "integrity": "sha1-l5pXHR7ZdkdzgZ2w9X3Ua8ipxdU=", + "dev": true, + "requires": { + "terser": "^3.8.0" + } + }, + "has-ansi": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/has-ansi/-/has-ansi-2.0.0.tgz", + "integrity": "sha1-NPUEnOHs3ysGSa8+8k5F7TVBbZE=", + "dev": true, + "requires": { + "ansi-regex": "^2.0.0" + } + }, + "has-flag": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/has-flag/-/has-flag-3.0.0.tgz", + "integrity": "sha1-tdRU3CGZriJWmfNGfloH87lVuv0=", + "dev": true + }, + "hooker": { + "version": "0.2.3", + "resolved": "https://registry.npmjs.org/hooker/-/hooker-0.2.3.tgz", + "integrity": "sha1-uDT3I8xKJCqmWWNFnfbZhMXT2Vk=", + "dev": true + }, + "hosted-git-info": { + "version": "2.7.1", + "resolved": "https://registry.npmjs.org/hosted-git-info/-/hosted-git-info-2.7.1.tgz", + "integrity": "sha512-7T/BxH19zbcCTa8XkMlbK5lTo1WtgkFi3GvdWEyNuc4Vex7/9Dqbnpsf4JMydcfj9HCg4zUWFTL3Za6lapg5/w==", + "dev": true + }, + "htmlparser2": { + "version": "3.10.1", + "resolved": "https://registry.npmjs.org/htmlparser2/-/htmlparser2-3.10.1.tgz", + "integrity": "sha512-IgieNijUMbkDovyoKObU1DUhm1iwNYE/fuifEoEHfd1oZKZDaONBSkal7Y01shxsM49R4XaMdGez3WnF9UfiCQ==", + "dev": true, + "requires": { + "domelementtype": "^1.3.1", + "domhandler": "^2.3.0", + "domutils": "^1.5.1", + "entities": "^1.1.1", + "inherits": "^2.0.1", + "readable-stream": "^3.1.1" + }, + "dependencies": { + "readable-stream": { + "version": "3.4.0", + "resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-3.4.0.tgz", + "integrity": "sha512-jItXPLmrSR8jmTRmRWJXCnGJsfy85mB3Wd/uINMXA65yrnFo0cPClFIUWzo2najVNSl+mx7/4W8ttlLWJe99pQ==", + "dev": true, + "requires": { + "inherits": "^2.0.3", + "string_decoder": "^1.1.1", + "util-deprecate": "^1.0.1" + } + }, + "string_decoder": { + "version": "1.2.0", + "resolved": "https://registry.npmjs.org/string_decoder/-/string_decoder-1.2.0.tgz", + "integrity": "sha512-6YqyX6ZWEYguAxgZzHGL7SsCeGx3V2TtOTqZz1xSTSWnqsbWwbptafNyvf/ACquZUXV3DANr5BDIwNYe1mN42w==", + "dev": true, + "requires": { + "safe-buffer": "~5.1.0" + } + } + } + }, + "http-proxy": { + "version": "1.11.3", + "resolved": "https://registry.npmjs.org/http-proxy/-/http-proxy-1.11.3.tgz", + "integrity": "sha1-GRXciIdR4qa/PCq/yxgI+obHI1M=", + "dev": true, + "requires": { + "eventemitter3": "1.x.x", + "requires-port": "0.x.x" + } + }, + "https-proxy-agent": { + "version": "2.2.2", + "resolved": "https://registry.npmjs.org/https-proxy-agent/-/https-proxy-agent-2.2.2.tgz", + "integrity": "sha512-c8Ndjc9Bkpfx/vCJueCPy0jlP4ccCCSNDp8xwCZzPjKJUm+B+u9WX2x98Qx4n1PiMNTWo3D7KK5ifNV/yJyRzg==", + "dev": true, + "requires": { + "agent-base": "^4.3.0", + "debug": "^3.1.0" + }, + "dependencies": { + "debug": { + "version": "3.2.6", + "resolved": "https://registry.npmjs.org/debug/-/debug-3.2.6.tgz", + "integrity": "sha512-mel+jf7nrtEl5Pn1Qx46zARXKDpBbvzezse7p7LqINmdoIk8PYP5SySaxEmYv6TZ0JyEKA1hsCId6DIhgITtWQ==", + "dev": true, + "requires": { + "ms": "^2.1.1" + } + } + } + }, + "iconv-lite": { + "version": "0.4.24", + "resolved": "https://registry.npmjs.org/iconv-lite/-/iconv-lite-0.4.24.tgz", + "integrity": "sha512-v3MXnZAcvnywkTUEZomIActle7RXXeedOR31wwl7VlyoXO4Qi9arvSenNQWne1TcRwhCL1HwLI21bEqdpj8/rA==", + "dev": true, + "requires": { + "safer-buffer": ">= 2.1.2 < 3" + } + }, + "indent-string": { + "version": "2.1.0", + "resolved": "https://registry.npmjs.org/indent-string/-/indent-string-2.1.0.tgz", + "integrity": "sha1-ji1INIdCEhtKghi3oTfppSBJ3IA=", + "dev": true, + "requires": { + "repeating": "^2.0.0" + } + }, + "inflight": { + "version": "1.0.6", + "resolved": "https://registry.npmjs.org/inflight/-/inflight-1.0.6.tgz", + "integrity": "sha1-Sb1jMdfQLQwJvJEKEHW6gWW1bfk=", + "dev": true, + "requires": { + "once": "^1.3.0", + "wrappy": "1" + } + }, + "inherits": { + "version": "2.0.4", + "resolved": "https://registry.npmjs.org/inherits/-/inherits-2.0.4.tgz", + "integrity": "sha512-k/vGaX4/Yla3WzyMCvTQOXYeIHvqOKtnqBduzTHpzpQZzAskKMhZ2K+EnBiSM9zGSoIFeMpXKxa4dYeZIQqewQ==", + "dev": true + }, + "ink-docstrap": { + "version": "1.3.2", + "resolved": "https://registry.npmjs.org/ink-docstrap/-/ink-docstrap-1.3.2.tgz", + "integrity": "sha512-STx5orGQU1gfrkoI/fMU7lX6CSP7LBGO10gXNgOZhwKhUqbtNjCkYSewJtNnLmWP1tAGN6oyEpG1HFPw5vpa5Q==", + "dev": true, + "requires": { + "moment": "^2.14.1", + "sanitize-html": "^1.13.0" + } + }, + "interpret": { + "version": "1.2.0", + "resolved": "https://registry.npmjs.org/interpret/-/interpret-1.2.0.tgz", + "integrity": "sha512-mT34yGKMNceBQUoVn7iCDKDntA7SC6gycMAWzGx1z/CMCTV7b2AAtXlo3nRyHZ1FelRkQbQjprHSYGwzLtkVbw==", + "dev": true + }, + "is-arrayish": { + "version": "0.2.1", + "resolved": "https://registry.npmjs.org/is-arrayish/-/is-arrayish-0.2.1.tgz", + "integrity": "sha1-d8mYQFJ6qOyxqLppe4BkWnqSap0=", + "dev": true + }, + "is-finite": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/is-finite/-/is-finite-1.0.2.tgz", + "integrity": "sha1-zGZ3aVYCvlUO8R6LSqYwU0K20Ko=", + "dev": true, + "requires": { + "number-is-nan": "^1.0.0" + } + }, + "is-utf8": { + "version": "0.2.1", + "resolved": "https://registry.npmjs.org/is-utf8/-/is-utf8-0.2.1.tgz", + "integrity": "sha1-Sw2hRCEE0bM2NA6AeX6GXPOffXI=", + "dev": true + }, + "isarray": { + "version": "0.0.1", + "resolved": "https://registry.npmjs.org/isarray/-/isarray-0.0.1.tgz", + "integrity": "sha1-ihis/Kmo9Bd+Cav8YDiTmwXR7t8=", + "dev": true + }, + "isexe": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/isexe/-/isexe-2.0.0.tgz", + "integrity": "sha1-6PvzdNxVb/iUehDcsFctYz8s+hA=", + "dev": true + }, + "js-yaml": { + "version": "3.5.5", + "resolved": "https://registry.npmjs.org/js-yaml/-/js-yaml-3.5.5.tgz", + "integrity": "sha1-A3fDgBfKvHMisNH7zSWkkWQfL74=", + "dev": true, + "requires": { + "argparse": "^1.0.2", + "esprima": "^2.6.0" + } + }, + "js2xmlparser": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/js2xmlparser/-/js2xmlparser-4.0.0.tgz", + "integrity": "sha512-WuNgdZOXVmBk5kUPMcTcVUpbGRzLfNkv7+7APq7WiDihpXVKrgxo6wwRpRl9OQeEBgKCVk9mR7RbzrnNWC8oBw==", + "dev": true, + "requires": { + "xmlcreate": "^2.0.0" + } + }, + "jsdoc": { + "version": "3.6.2", + "resolved": "https://registry.npmjs.org/jsdoc/-/jsdoc-3.6.2.tgz", + "integrity": "sha512-S2vzg99C5+gb7FWlrK4TVdyzVPGGkdvpDkCEJH1JABi2PKzPeLu5/zZffcJUifgWUJqXWl41Hoc+MmuM2GukIg==", + "dev": true, + "requires": { + "@babel/parser": "^7.4.4", + "bluebird": "^3.5.4", + "catharsis": "^0.8.10", + "escape-string-regexp": "^2.0.0", + "js2xmlparser": "^4.0.0", + "klaw": "^3.0.0", + "markdown-it": "^8.4.2", + "markdown-it-anchor": "^5.0.2", + "marked": "^0.6.2", + "mkdirp": "^0.5.1", + "requizzle": "^0.2.2", + "strip-json-comments": "^3.0.1", + "taffydb": "2.6.2", + "underscore": "~1.9.1" + }, + "dependencies": { + "escape-string-regexp": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/escape-string-regexp/-/escape-string-regexp-2.0.0.tgz", + "integrity": "sha512-UpzcLCXolUWcNu5HtVMHYdXJjArjsF9C0aNnquZYY4uW/Vu0miy5YoWvbV345HauVvcAUnpRuhMMcqTcGOY2+w==", + "dev": true + }, + "underscore": { + "version": "1.9.1", + "resolved": "https://registry.npmjs.org/underscore/-/underscore-1.9.1.tgz", + "integrity": "sha512-5/4etnCkd9c8gwgowi5/om/mYO5ajCaOgdzj/oW+0eQV9WxKBDZw5+ycmKmeaTXjInS/W0BzpGLo2xR2aBwZdg==", + "dev": true + } + } + }, + "jshint": { + "version": "2.10.2", + "resolved": "https://registry.npmjs.org/jshint/-/jshint-2.10.2.tgz", + "integrity": "sha512-e7KZgCSXMJxznE/4WULzybCMNXNAd/bf5TSrvVEq78Q/K8ZwFpmBqQeDtNiHc3l49nV4E/+YeHU/JZjSUIrLAA==", + "dev": true, + "requires": { + "cli": "~1.0.0", + "console-browserify": "1.1.x", + "exit": "0.1.x", + "htmlparser2": "3.8.x", + "lodash": "~4.17.11", + "minimatch": "~3.0.2", + "shelljs": "0.3.x", + "strip-json-comments": "1.0.x" + }, + "dependencies": { + "domhandler": { + "version": "2.3.0", + "resolved": "https://registry.npmjs.org/domhandler/-/domhandler-2.3.0.tgz", + "integrity": "sha1-LeWaCCLVAn+r/28DLCsloqir5zg=", + "dev": true, + "requires": { + "domelementtype": "1" + } + }, + "domutils": { + "version": "1.5.1", + "resolved": "https://registry.npmjs.org/domutils/-/domutils-1.5.1.tgz", + "integrity": "sha1-3NhIiib1Y9YQeeSMn3t+Mjc2gs8=", + "dev": true, + "requires": { + "dom-serializer": "0", + "domelementtype": "1" + } + }, + "entities": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/entities/-/entities-1.0.0.tgz", + "integrity": "sha1-sph6o4ITR/zeZCsk/fyeT7cSvyY=", + "dev": true + }, + "htmlparser2": { + "version": "3.8.3", + "resolved": "https://registry.npmjs.org/htmlparser2/-/htmlparser2-3.8.3.tgz", + "integrity": "sha1-mWwosZFRaovoZQGn15dX5ccMEGg=", + "dev": true, + "requires": { + "domelementtype": "1", + "domhandler": "2.3", + "domutils": "1.5", + "entities": "1.0", + "readable-stream": "1.1" + } + }, + "readable-stream": { + "version": "1.1.14", + "resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-1.1.14.tgz", + "integrity": "sha1-fPTFTvZI44EwhMY23SB54WbAgdk=", + "dev": true, + "requires": { + "core-util-is": "~1.0.0", + "inherits": "~2.0.1", + "isarray": "0.0.1", + "string_decoder": "~0.10.x" + } + }, + "shelljs": { + "version": "0.3.0", + "resolved": "https://registry.npmjs.org/shelljs/-/shelljs-0.3.0.tgz", + "integrity": "sha1-NZbmMHp4FUT1kfN9phg2DzHbV7E=", + "dev": true + }, + "strip-json-comments": { + "version": "1.0.4", + "resolved": "https://registry.npmjs.org/strip-json-comments/-/strip-json-comments-1.0.4.tgz", + "integrity": "sha1-HhX7ysl9Pumb8tc7TGVrCCu6+5E=", + "dev": true + } + } + }, + "klaw": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/klaw/-/klaw-3.0.0.tgz", + "integrity": "sha512-0Fo5oir+O9jnXu5EefYbVK+mHMBeEVEy2cmctR1O1NECcCkPRreJKrS6Qt/j3KC2C148Dfo9i3pCmCMsdqGr0g==", + "dev": true, + "requires": { + "graceful-fs": "^4.1.9" + } + }, + "linkify-it": { + "version": "2.1.0", + "resolved": "https://registry.npmjs.org/linkify-it/-/linkify-it-2.1.0.tgz", + "integrity": "sha512-4REs8/062kV2DSHxNfq5183zrqXMl7WP0WzABH9IeJI+NLm429FgE1PDecltYfnOoFDFlZGh2T8PfZn0r+GTRg==", + "dev": true, + "requires": { + "uc.micro": "^1.0.1" + } + }, + "load-json-file": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/load-json-file/-/load-json-file-1.1.0.tgz", + "integrity": "sha1-lWkFcI1YtLq0wiYbBPWfMcmTdMA=", + "dev": true, + "requires": { + "graceful-fs": "^4.1.2", + "parse-json": "^2.2.0", + "pify": "^2.0.0", + "pinkie-promise": "^2.0.0", + "strip-bom": "^2.0.0" + } + }, + "lodash": { + "version": "4.17.11", + "resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.11.tgz", + "integrity": "sha512-cQKh8igo5QUhZ7lg38DYWAxMvjSAKG0A8wGSVimP07SIUEK2UO+arSRKbRZWtelMtN5V0Hkwh5ryOto/SshYIg==", + "dev": true + }, + "lodash.clonedeep": { + "version": "4.5.0", + "resolved": "https://registry.npmjs.org/lodash.clonedeep/-/lodash.clonedeep-4.5.0.tgz", + "integrity": "sha1-4j8/nE+Pvd6HJSnBBxhXoIblzO8=", + "dev": true + }, + "lodash.escaperegexp": { + "version": "4.1.2", + "resolved": "https://registry.npmjs.org/lodash.escaperegexp/-/lodash.escaperegexp-4.1.2.tgz", + "integrity": "sha1-ZHYsSGGAglGKw99Mz11YhtriA0c=", + "dev": true + }, + "lodash.isplainobject": { + "version": "4.0.6", + "resolved": "https://registry.npmjs.org/lodash.isplainobject/-/lodash.isplainobject-4.0.6.tgz", + "integrity": "sha1-fFJqUtibRcRcxpC4gWO+BJf1UMs=", + "dev": true + }, + "lodash.isstring": { + "version": "4.0.1", + "resolved": "https://registry.npmjs.org/lodash.isstring/-/lodash.isstring-4.0.1.tgz", + "integrity": "sha1-1SfftUVuynzJu5XV2ur4i6VKVFE=", + "dev": true + }, + "lodash.mergewith": { + "version": "4.6.1", + "resolved": "https://registry.npmjs.org/lodash.mergewith/-/lodash.mergewith-4.6.1.tgz", + "integrity": "sha512-eWw5r+PYICtEBgrBE5hhlT6aAa75f411bgDz/ZL2KZqYV03USvucsxcHUIlGTDTECs1eunpI7HOV7U+WLDvNdQ==", + "dev": true + }, + "loud-rejection": { + "version": "1.6.0", + "resolved": "https://registry.npmjs.org/loud-rejection/-/loud-rejection-1.6.0.tgz", + "integrity": "sha1-W0b4AUft7leIcPCG0Eghz5mOVR8=", + "dev": true, + "requires": { + "currently-unhandled": "^0.4.1", + "signal-exit": "^3.0.0" + } + }, + "lru-cache": { + "version": "2.7.3", + "resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-2.7.3.tgz", + "integrity": "sha1-bUUk6LlV+V1PW1iFHOId1y+06VI=", + "dev": true + }, + "map-obj": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/map-obj/-/map-obj-1.0.1.tgz", + "integrity": "sha1-2TPOuSBdgr3PSIb2dCvcK03qFG0=", + "dev": true + }, + "markdown-it": { + "version": "8.4.2", + "resolved": "https://registry.npmjs.org/markdown-it/-/markdown-it-8.4.2.tgz", + "integrity": "sha512-GcRz3AWTqSUphY3vsUqQSFMbgR38a4Lh3GWlHRh/7MRwz8mcu9n2IO7HOh+bXHrR9kOPDl5RNCaEsrneb+xhHQ==", + "dev": true, + "requires": { + "argparse": "^1.0.7", + "entities": "~1.1.1", + "linkify-it": "^2.0.0", + "mdurl": "^1.0.1", + "uc.micro": "^1.0.5" + } + }, + "markdown-it-anchor": { + "version": "5.2.4", + "resolved": "https://registry.npmjs.org/markdown-it-anchor/-/markdown-it-anchor-5.2.4.tgz", + "integrity": "sha512-n8zCGjxA3T+Mx1pG8HEgbJbkB8JFUuRkeTZQuIM8iPY6oQ8sWOPRZJDFC9a/pNg2QkHEjjGkhBEl/RSyzaDZ3A==", + "dev": true + }, + "marked": { + "version": "0.6.2", + "resolved": "https://registry.npmjs.org/marked/-/marked-0.6.2.tgz", + "integrity": "sha512-LqxwVH3P/rqKX4EKGz7+c2G9r98WeM/SW34ybhgNGhUQNKtf1GmmSkJ6cDGJ/t6tiyae49qRkpyTw2B9HOrgUA==", + "dev": true + }, + "mdurl": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/mdurl/-/mdurl-1.0.1.tgz", + "integrity": "sha1-/oWy7HWlkDfyrf7BAP1sYBdhFS4=", + "dev": true + }, + "meow": { + "version": "3.7.0", + "resolved": "https://registry.npmjs.org/meow/-/meow-3.7.0.tgz", + "integrity": "sha1-cstmi0JSKCkKu/qFaJJYcwioAfs=", + "dev": true, + "requires": { + "camelcase-keys": "^2.0.0", + "decamelize": "^1.1.2", + "loud-rejection": "^1.0.0", + "map-obj": "^1.0.1", + "minimist": "^1.1.3", + "normalize-package-data": "^2.3.4", + "object-assign": "^4.0.1", + "read-pkg-up": "^1.0.1", + "redent": "^1.0.0", + "trim-newlines": "^1.0.0" + } + }, + "methods": { + "version": "1.1.2", + "resolved": "https://registry.npmjs.org/methods/-/methods-1.1.2.tgz", + "integrity": "sha1-VSmk1nZUE07cxSZmVoNbD4Ua/O4=", + "dev": true + }, + "mime": { + "version": "1.2.11", + "resolved": "https://registry.npmjs.org/mime/-/mime-1.2.11.tgz", + "integrity": "sha1-WCA+7Ybjpe8XrtK32evUfwpg3RA=", + "dev": true + }, + "mime-db": { + "version": "1.12.0", + "resolved": "https://registry.npmjs.org/mime-db/-/mime-db-1.12.0.tgz", + "integrity": "sha1-PQxjGA9FjrENMlqqN9fFiuMS6dc=", + "dev": true + }, + "mime-types": { + "version": "2.0.14", + "resolved": "https://registry.npmjs.org/mime-types/-/mime-types-2.0.14.tgz", + "integrity": "sha1-MQ4VnbI+B3+Lsit0jav6SVcUCqY=", + "dev": true, + "requires": { + "mime-db": "~1.12.0" + } + }, + "minimatch": { + "version": "3.0.4", + "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-3.0.4.tgz", + "integrity": "sha512-yJHVQEhyqPLUTgt9B83PXu6W3rx4MvvHvSUvToogpwoGDOUQ+yDrR0HRot+yOCdCO7u4hX3pWft6kWBBcqh0UA==", + "dev": true, + "requires": { + "brace-expansion": "^1.1.7" + } + }, + "minimist": { + "version": "1.2.0", + "resolved": "https://registry.npmjs.org/minimist/-/minimist-1.2.0.tgz", + "integrity": "sha1-o1AIsg9BOD7sH7kU9M1d95omQoQ=", + "dev": true + }, + "mkdirp": { + "version": "0.5.1", + "resolved": "https://registry.npmjs.org/mkdirp/-/mkdirp-0.5.1.tgz", + "integrity": "sha1-MAV0OOrGz3+MR2fzhkjWaX11yQM=", + "dev": true, + "requires": { + "minimist": "0.0.8" + }, + "dependencies": { + "minimist": { + "version": "0.0.8", + "resolved": "https://registry.npmjs.org/minimist/-/minimist-0.0.8.tgz", + "integrity": "sha1-hX/Kv8M5fSYluCKCYuhqp6ARsF0=", + "dev": true + } + } + }, + "moment": { + "version": "2.24.0", + "resolved": "https://registry.npmjs.org/moment/-/moment-2.24.0.tgz", + "integrity": "sha512-bV7f+6l2QigeBBZSM/6yTNq4P2fNpSWj/0e7jQcy87A8e7o2nAfP/34/2ky5Vw4B9S446EtIhodAzkFCcR4dQg==", + "dev": true + }, + "ms": { + "version": "2.1.2", + "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.2.tgz", + "integrity": "sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w==", + "dev": true + }, + "nice-try": { + "version": "1.0.5", + "resolved": "https://registry.npmjs.org/nice-try/-/nice-try-1.0.5.tgz", + "integrity": "sha512-1nh45deeb5olNY7eX82BkPO7SSxR5SSYJiPTrTdFUVYwAl8CKMA5N9PjTYkHiRjisVcxcQ1HXdLhx2qxxJzLNQ==", + "dev": true + }, + "nopt": { + "version": "3.0.6", + "resolved": "https://registry.npmjs.org/nopt/-/nopt-3.0.6.tgz", + "integrity": "sha1-xkZdvwirzU2zWTF/eaxopkayj/k=", + "dev": true, + "requires": { + "abbrev": "1" + } + }, + "normalize-package-data": { + "version": "2.5.0", + "resolved": "https://registry.npmjs.org/normalize-package-data/-/normalize-package-data-2.5.0.tgz", + "integrity": "sha512-/5CMN3T0R4XTj4DcGaexo+roZSdSFW/0AOOTROrjxzCG1wrWXEsGbRKevjlIL+ZDE4sZlJr5ED4YW0yqmkK+eA==", + "dev": true, + "requires": { + "hosted-git-info": "^2.1.4", + "resolve": "^1.10.0", + "semver": "2 || 3 || 4 || 5", + "validate-npm-package-license": "^3.0.1" + } + }, + "number-is-nan": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/number-is-nan/-/number-is-nan-1.0.1.tgz", + "integrity": "sha1-CXtgK1NCKlIsGvuHkDGDNpQaAR0=", + "dev": true + }, + "object-assign": { + "version": "4.1.1", + "resolved": "https://registry.npmjs.org/object-assign/-/object-assign-4.1.1.tgz", + "integrity": "sha1-IQmtx5ZYh8/AXLvUQsrIv7s2CGM=", + "dev": true + }, + "once": { + "version": "1.4.0", + "resolved": "https://registry.npmjs.org/once/-/once-1.4.0.tgz", + "integrity": "sha1-WDsap3WWHUsROsF9nFC6753Xa9E=", + "dev": true, + "requires": { + "wrappy": "1" + } + }, + "open": { + "version": "0.0.4", + "resolved": "https://registry.npmjs.org/open/-/open-0.0.4.tgz", + "integrity": "sha1-XeRqCFi59J+fIRqo8mYoVQZX8mI=", + "dev": true + }, + "p-each-series": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/p-each-series/-/p-each-series-1.0.0.tgz", + "integrity": "sha1-kw89Et0fUOdDRFeiLNbwSsatf3E=", + "dev": true, + "requires": { + "p-reduce": "^1.0.0" + } + }, + "p-reduce": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/p-reduce/-/p-reduce-1.0.0.tgz", + "integrity": "sha1-GMKw3ZNqRpClKfgjH1ig/bakffo=", + "dev": true + }, + "parse-json": { + "version": "2.2.0", + "resolved": "https://registry.npmjs.org/parse-json/-/parse-json-2.2.0.tgz", + "integrity": "sha1-9ID0BDTvgHQfhGkJn43qGPVaTck=", + "dev": true, + "requires": { + "error-ex": "^1.2.0" + } + }, + "path-exists": { + "version": "2.1.0", + "resolved": "https://registry.npmjs.org/path-exists/-/path-exists-2.1.0.tgz", + "integrity": "sha1-D+tsZPD8UY2adU3V77YscCJ2H0s=", + "dev": true, + "requires": { + "pinkie-promise": "^2.0.0" + } + }, + "path-is-absolute": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/path-is-absolute/-/path-is-absolute-1.0.1.tgz", + "integrity": "sha1-F0uSaHNVNP+8es5r9TpanhtcX18=", + "dev": true + }, + "path-key": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/path-key/-/path-key-2.0.1.tgz", + "integrity": "sha1-QRyttXTFoUDTpLGRDUDYDMn0C0A=", + "dev": true + }, + "path-parse": { + "version": "1.0.6", + "resolved": "https://registry.npmjs.org/path-parse/-/path-parse-1.0.6.tgz", + "integrity": "sha512-GSmOT2EbHrINBf9SR7CDELwlJ8AENk3Qn7OikK4nFYAu3Ote2+JYNVvkpAEQm3/TLNEJFD/xZJjzyxg3KBWOzw==", + "dev": true + }, + "path-type": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/path-type/-/path-type-1.1.0.tgz", + "integrity": "sha1-WcRPfuSR2nBNpBXaWkBwuk+P5EE=", + "dev": true, + "requires": { + "graceful-fs": "^4.1.2", + "pify": "^2.0.0", + "pinkie-promise": "^2.0.0" + } + }, + "pause": { + "version": "0.0.1", + "resolved": "https://registry.npmjs.org/pause/-/pause-0.0.1.tgz", + "integrity": "sha1-HUCLP9t2kjuVQ9lvtMnf1TXZy10=", + "dev": true + }, + "pend": { + "version": "1.2.0", + "resolved": "https://registry.npmjs.org/pend/-/pend-1.2.0.tgz", + "integrity": "sha1-elfrVQpng/kRUzH89GY9XI4AelA=", + "dev": true + }, + "pify": { + "version": "2.3.0", + "resolved": "https://registry.npmjs.org/pify/-/pify-2.3.0.tgz", + "integrity": "sha1-7RQaasBDqEnqWISY59yosVMw6Qw=", + "dev": true + }, + "pinkie": { + "version": "2.0.4", + "resolved": "https://registry.npmjs.org/pinkie/-/pinkie-2.0.4.tgz", + "integrity": "sha1-clVrgM+g1IqXToDnckjoDtT3+HA=", + "dev": true + }, + "pinkie-promise": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/pinkie-promise/-/pinkie-promise-2.0.1.tgz", + "integrity": "sha1-ITXW36ejWMBprJsXh3YogihFD/o=", + "dev": true, + "requires": { + "pinkie": "^2.0.0" + } + }, + "postcss": { + "version": "7.0.17", + "resolved": "https://registry.npmjs.org/postcss/-/postcss-7.0.17.tgz", + "integrity": "sha512-546ZowA+KZ3OasvQZHsbuEpysvwTZNGJv9EfyCQdsIDltPSWHAeTQ5fQy/Npi2ZDtLI3zs7Ps/p6wThErhm9fQ==", + "dev": true, + "requires": { + "chalk": "^2.4.2", + "source-map": "^0.6.1", + "supports-color": "^6.1.0" + }, + "dependencies": { + "ansi-styles": { + "version": "3.2.1", + "resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-3.2.1.tgz", + "integrity": "sha512-VT0ZI6kZRdTh8YyJw3SMbYm/u+NqfsAxEpWO0Pf9sq8/e94WxxOpPKx9FR1FlyCtOVDNOQ+8ntlqFxiRc+r5qA==", + "dev": true, + "requires": { + "color-convert": "^1.9.0" + } + }, + "chalk": { + "version": "2.4.2", + "resolved": "https://registry.npmjs.org/chalk/-/chalk-2.4.2.tgz", + "integrity": "sha512-Mti+f9lpJNcwF4tWV8/OrTTtF1gZi+f8FqlyAdouralcFWFQWF2+NgCHShjkCb+IFBLq9buZwE1xckQU4peSuQ==", + "dev": true, + "requires": { + "ansi-styles": "^3.2.1", + "escape-string-regexp": "^1.0.5", + "supports-color": "^5.3.0" + }, + "dependencies": { + "supports-color": { + "version": "5.5.0", + "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-5.5.0.tgz", + "integrity": "sha512-QjVjwdXIt408MIiAqCX4oUKsgU2EqAGzs2Ppkm4aQYbjm+ZEWEcW4SfFNTr4uMNZma0ey4f5lgLrkB0aX0QMow==", + "dev": true, + "requires": { + "has-flag": "^3.0.0" + } + } + } + }, + "supports-color": { + "version": "6.1.0", + "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-6.1.0.tgz", + "integrity": "sha512-qe1jfm1Mg7Nq/NSh6XE24gPXROEVsWHxC1LIx//XNlD9iw7YZQGjZNjYN7xGaEG6iKdA8EtNFW6R0gjnVXp+wQ==", + "dev": true, + "requires": { + "has-flag": "^3.0.0" + } + } + } + }, + "process-nextick-args": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/process-nextick-args/-/process-nextick-args-2.0.1.tgz", + "integrity": "sha512-3ouUOpQhtgrbOa17J7+uxOTpITYWaGP7/AhoR3+A+/1e9skrzelGi/dXzEYyvbxubEF6Wn2ypscTKiKJFFn1ag==", + "dev": true + }, + "progress": { + "version": "1.1.8", + "resolved": "https://registry.npmjs.org/progress/-/progress-1.1.8.tgz", + "integrity": "sha1-4mDHj2Fhzdmw5WzD4Khd4Xx6V74=", + "dev": true + }, + "proxy-from-env": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/proxy-from-env/-/proxy-from-env-1.0.0.tgz", + "integrity": "sha1-M8UDmPcOp+uW0h97gXYwpVeRx+4=", + "dev": true + }, + "puppeteer": { + "version": "1.18.1", + "resolved": "https://registry.npmjs.org/puppeteer/-/puppeteer-1.18.1.tgz", + "integrity": "sha512-luUy0HPSuWPsPZ1wAp6NinE0zgetWtudf5zwZ6dHjMWfYpTQcmKveFRox7VBNhQ98OjNA9PQ9PzQyX8k/KrxTg==", + "dev": true, + "requires": { + "debug": "^4.1.0", + "extract-zip": "^1.6.6", + "https-proxy-agent": "^2.2.1", + "mime": "^2.0.3", + "progress": "^2.0.1", + "proxy-from-env": "^1.0.0", + "rimraf": "^2.6.1", + "ws": "^6.1.0" + }, + "dependencies": { + "glob": { + "version": "7.1.4", + "resolved": "https://registry.npmjs.org/glob/-/glob-7.1.4.tgz", + "integrity": "sha512-hkLPepehmnKk41pUGm3sYxoFs/umurYfYJCerbXEyFIWcAzvpipAgVkBqqT9RBKMGjnq6kMuyYwha6csxbiM1A==", + "dev": true, + "requires": { + "fs.realpath": "^1.0.0", + "inflight": "^1.0.4", + "inherits": "2", + "minimatch": "^3.0.4", + "once": "^1.3.0", + "path-is-absolute": "^1.0.0" + } + }, + "mime": { + "version": "2.4.4", + "resolved": "https://registry.npmjs.org/mime/-/mime-2.4.4.tgz", + "integrity": "sha512-LRxmNwziLPT828z+4YkNzloCFC2YM4wrB99k+AV5ZbEyfGNWfG8SO1FUXLmLDBSo89NrJZ4DIWeLjy1CHGhMGA==", + "dev": true + }, + "progress": { + "version": "2.0.3", + "resolved": "https://registry.npmjs.org/progress/-/progress-2.0.3.tgz", + "integrity": "sha512-7PiHtLll5LdnKIMw100I+8xJXR5gW2QwWYkT6iJva0bXitZKa/XMrSbdmg3r2Xnaidz9Qumd0VPaMrZlF9V9sA==", + "dev": true + }, + "rimraf": { + "version": "2.6.3", + "resolved": "https://registry.npmjs.org/rimraf/-/rimraf-2.6.3.tgz", + "integrity": "sha512-mwqeW5XsA2qAejG46gYdENaxXjx9onRNCfn7L0duuP4hCuTIi/QO7PDK07KJfp1d+izWPrzEJDcSqBa0OZQriA==", + "dev": true, + "requires": { + "glob": "^7.1.3" + } + } + } + }, + "q": { + "version": "1.5.1", + "resolved": "https://registry.npmjs.org/q/-/q-1.5.1.tgz", + "integrity": "sha1-fjL3W0E4EpHQRhHxvxQQmsAGUdc=", + "dev": true + }, + "qs": { + "version": "0.6.5", + "resolved": "https://registry.npmjs.org/qs/-/qs-0.6.5.tgz", + "integrity": "sha1-KUsmjksNQlD23eGbO4s0k13/FO8=", + "dev": true + }, + "range-parser": { + "version": "0.0.4", + "resolved": "https://registry.npmjs.org/range-parser/-/range-parser-0.0.4.tgz", + "integrity": "sha1-wEJ//vUcEKy6B4KkbJYC50T/Ygs=", + "dev": true + }, + "read-pkg": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/read-pkg/-/read-pkg-1.1.0.tgz", + "integrity": "sha1-9f+qXs0pyzHAR0vKfXVra7KePyg=", + "dev": true, + "requires": { + "load-json-file": "^1.0.0", + "normalize-package-data": "^2.3.2", + "path-type": "^1.0.0" + } + }, + "read-pkg-up": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/read-pkg-up/-/read-pkg-up-1.0.1.tgz", + "integrity": "sha1-nWPBMnbAZZGNV/ACpX9AobZD+wI=", + "dev": true, + "requires": { + "find-up": "^1.0.0", + "read-pkg": "^1.0.0" + } + }, + "readable-stream": { + "version": "1.0.27-1", + "resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-1.0.27-1.tgz", + "integrity": "sha1-a2eYPCA1fO/QfwFlABoW1xDZEHg=", + "dev": true, + "requires": { + "core-util-is": "~1.0.0", + "inherits": "~2.0.1", + "isarray": "0.0.1", + "string_decoder": "~0.10.x" + } + }, + "rechoir": { + "version": "0.6.2", + "resolved": "https://registry.npmjs.org/rechoir/-/rechoir-0.6.2.tgz", + "integrity": "sha1-hSBLVNuoLVdC4oyWdW70OvUOM4Q=", + "dev": true, + "requires": { + "resolve": "^1.1.6" + } + }, + "redent": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/redent/-/redent-1.0.0.tgz", + "integrity": "sha1-z5Fqsf1fHxbfsggi3W7H9zDCr94=", + "dev": true, + "requires": { + "indent-string": "^2.1.0", + "strip-indent": "^1.0.1" + } + }, + "reduce-component": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/reduce-component/-/reduce-component-1.0.1.tgz", + "integrity": "sha1-4Mk1QsV0UhvqE98PlIjtgqt3xdo=", + "dev": true + }, + "repeating": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/repeating/-/repeating-2.0.1.tgz", + "integrity": "sha1-UhTFOpJtNVJwdSf7q0FdvAjQbdo=", + "dev": true, + "requires": { + "is-finite": "^1.0.0" + } + }, + "requires-port": { + "version": "0.0.1", + "resolved": "https://registry.npmjs.org/requires-port/-/requires-port-0.0.1.tgz", + "integrity": "sha1-S0QUQR2d98hVmV3YmajHiilRwW0=", + "dev": true + }, + "requizzle": { + "version": "0.2.2", + "resolved": "https://registry.npmjs.org/requizzle/-/requizzle-0.2.2.tgz", + "integrity": "sha512-oJ6y7JcUJkblRGhMByGNcszeLgU0qDxNKFCiUZR1XyzHyVsev+Mxb1tyygxLd1ORsKee1SA5BInFdUwY64GE/A==", + "dev": true, + "requires": { + "lodash": "^4.17.11" + } + }, + "resolve": { + "version": "1.11.0", + "resolved": "https://registry.npmjs.org/resolve/-/resolve-1.11.0.tgz", + "integrity": "sha512-WL2pBDjqT6pGUNSUzMw00o4T7If+z4H2x3Gz893WoUQ5KW8Vr9txp00ykiP16VBaZF5+j/OcXJHZ9+PCvdiDKw==", + "dev": true, + "requires": { + "path-parse": "^1.0.6" + } + }, + "rimraf": { + "version": "2.2.8", + "resolved": "https://registry.npmjs.org/rimraf/-/rimraf-2.2.8.tgz", + "integrity": "sha1-5Dm+Kq7jJzIZUnMPmaiSnk/FBYI=", + "dev": true + }, + "safe-buffer": { + "version": "5.1.2", + "resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.1.2.tgz", + "integrity": "sha512-Gd2UZBJDkXlY7GbJxfsE8/nvKkUEU1G38c1siN6QP6a9PT9MmHB8GnpscSmMJSoF8LOIrt8ud/wPtojys4G6+g==", + "dev": true + }, + "safer-buffer": { + "version": "2.1.2", + "resolved": "https://registry.npmjs.org/safer-buffer/-/safer-buffer-2.1.2.tgz", + "integrity": "sha512-YZo3K82SD7Riyi0E1EQPojLz7kpepnSQI9IyPbHHg1XXXevb5dJI7tpyN2ADxGcQbHG7vcyRHk0cbwqcQriUtg==", + "dev": true + }, + "sanitize-html": { + "version": "1.20.1", + "resolved": "https://registry.npmjs.org/sanitize-html/-/sanitize-html-1.20.1.tgz", + "integrity": "sha512-txnH8TQjaQvg2Q0HY06G6CDJLVYCpbnxrdO0WN8gjCKaU5J0KbyGYhZxx5QJg3WLZ1lB7XU9kDkfrCXUozqptA==", + "dev": true, + "requires": { + "chalk": "^2.4.1", + "htmlparser2": "^3.10.0", + "lodash.clonedeep": "^4.5.0", + "lodash.escaperegexp": "^4.1.2", + "lodash.isplainobject": "^4.0.6", + "lodash.isstring": "^4.0.1", + "lodash.mergewith": "^4.6.1", + "postcss": "^7.0.5", + "srcset": "^1.0.0", + "xtend": "^4.0.1" + }, + "dependencies": { + "ansi-styles": { + "version": "3.2.1", + "resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-3.2.1.tgz", + "integrity": "sha512-VT0ZI6kZRdTh8YyJw3SMbYm/u+NqfsAxEpWO0Pf9sq8/e94WxxOpPKx9FR1FlyCtOVDNOQ+8ntlqFxiRc+r5qA==", + "dev": true, + "requires": { + "color-convert": "^1.9.0" + } + }, + "chalk": { + "version": "2.4.2", + "resolved": "https://registry.npmjs.org/chalk/-/chalk-2.4.2.tgz", + "integrity": "sha512-Mti+f9lpJNcwF4tWV8/OrTTtF1gZi+f8FqlyAdouralcFWFQWF2+NgCHShjkCb+IFBLq9buZwE1xckQU4peSuQ==", + "dev": true, + "requires": { + "ansi-styles": "^3.2.1", + "escape-string-regexp": "^1.0.5", + "supports-color": "^5.3.0" + } + }, + "supports-color": { + "version": "5.5.0", + "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-5.5.0.tgz", + "integrity": "sha512-QjVjwdXIt408MIiAqCX4oUKsgU2EqAGzs2Ppkm4aQYbjm+ZEWEcW4SfFNTr4uMNZma0ey4f5lgLrkB0aX0QMow==", + "dev": true, + "requires": { + "has-flag": "^3.0.0" + } + } + } + }, + "sax": { + "version": "0.4.2", + "resolved": "https://registry.npmjs.org/sax/-/sax-0.4.2.tgz", + "integrity": "sha1-OfO2AXM9a+yXEFskKipA/Wl4rDw=", + "dev": true + }, + "semver": { + "version": "5.7.0", + "resolved": "https://registry.npmjs.org/semver/-/semver-5.7.0.tgz", + "integrity": "sha512-Ya52jSX2u7QKghxeoFGpLwCtGlt7j0oY9DYb5apt9nPlJ42ID+ulTXESnt/qAQcoSERyZ5sl3LDIOw0nAn/5DA==", + "dev": true + }, + "send": { + "version": "0.1.1", + "resolved": "https://registry.npmjs.org/send/-/send-0.1.1.tgz", + "integrity": "sha1-C8/L0D3vbi2GEuGr+PSJW0UMYMg=", + "dev": true, + "requires": { + "debug": "*", + "fresh": "0.1.0", + "mime": "~1.2.9", + "range-parser": "0.0.4" + } + }, + "shebang-command": { + "version": "1.2.0", + "resolved": "https://registry.npmjs.org/shebang-command/-/shebang-command-1.2.0.tgz", + "integrity": "sha1-RKrGW2lbAzmJaMOfNj/uXer98eo=", + "dev": true, + "requires": { + "shebang-regex": "^1.0.0" + } + }, + "shebang-regex": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/shebang-regex/-/shebang-regex-1.0.0.tgz", + "integrity": "sha1-2kL0l0DAtC2yypcoVxyxkMmO/qM=", + "dev": true + }, + "shelljs": { + "version": "0.7.8", + "resolved": "https://registry.npmjs.org/shelljs/-/shelljs-0.7.8.tgz", + "integrity": "sha1-3svPh0sNHl+3LhSxZKloMEjprLM=", + "dev": true, + "requires": { + "glob": "^7.0.0", + "interpret": "^1.0.0", + "rechoir": "^0.6.2" + } + }, + "sigmund": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/sigmund/-/sigmund-1.0.1.tgz", + "integrity": "sha1-P/IfGYytIXX587eBhT/ZTQ0ZtZA=", + "dev": true + }, + "signal-exit": { + "version": "3.0.2", + "resolved": "https://registry.npmjs.org/signal-exit/-/signal-exit-3.0.2.tgz", + "integrity": "sha1-tf3AjxKH6hF4Yo5BXiUTK3NkbG0=", + "dev": true + }, + "source-map": { + "version": "0.6.1", + "resolved": "https://registry.npmjs.org/source-map/-/source-map-0.6.1.tgz", + "integrity": "sha512-UjgapumWlbMhkBgzT7Ykc5YXUT46F0iKu8SGXq0bcwP5dz/h0Plj6enJqjz1Zbq2l5WaqYnrVbwWOWMyF3F47g==", + "dev": true + }, + "source-map-support": { + "version": "0.5.12", + "resolved": "https://registry.npmjs.org/source-map-support/-/source-map-support-0.5.12.tgz", + "integrity": "sha512-4h2Pbvyy15EE02G+JOZpUCmqWJuqrs+sEkzewTm++BPi7Hvn/HwcqLAcNxYAyI0x13CpPPn+kMjl+hplXMHITQ==", + "dev": true, + "requires": { + "buffer-from": "^1.0.0", + "source-map": "^0.6.0" + } + }, + "spdx-correct": { + "version": "3.1.0", + "resolved": "https://registry.npmjs.org/spdx-correct/-/spdx-correct-3.1.0.tgz", + "integrity": "sha512-lr2EZCctC2BNR7j7WzJ2FpDznxky1sjfxvvYEyzxNyb6lZXHODmEoJeFu4JupYlkfha1KZpJyoqiJ7pgA1qq8Q==", + "dev": true, + "requires": { + "spdx-expression-parse": "^3.0.0", + "spdx-license-ids": "^3.0.0" + } + }, + "spdx-exceptions": { + "version": "2.2.0", + "resolved": "https://registry.npmjs.org/spdx-exceptions/-/spdx-exceptions-2.2.0.tgz", + "integrity": "sha512-2XQACfElKi9SlVb1CYadKDXvoajPgBVPn/gOQLrTvHdElaVhr7ZEbqJaRnJLVNeaI4cMEAgVCeBMKF6MWRDCRA==", + "dev": true + }, + "spdx-expression-parse": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/spdx-expression-parse/-/spdx-expression-parse-3.0.0.tgz", + "integrity": "sha512-Yg6D3XpRD4kkOmTpdgbUiEJFKghJH03fiC1OPll5h/0sO6neh2jqRDVHOQ4o/LMea0tgCkbMgea5ip/e+MkWyg==", + "dev": true, + "requires": { + "spdx-exceptions": "^2.1.0", + "spdx-license-ids": "^3.0.0" + } + }, + "spdx-license-ids": { + "version": "3.0.4", + "resolved": "https://registry.npmjs.org/spdx-license-ids/-/spdx-license-ids-3.0.4.tgz", + "integrity": "sha512-7j8LYJLeY/Yb6ACbQ7F76qy5jHkp0U6jgBfJsk97bwWlVUnUWsAgpyaCvo17h0/RQGnQ036tVDomiwoI4pDkQA==", + "dev": true + }, + "sprintf-js": { + "version": "1.0.3", + "resolved": "https://registry.npmjs.org/sprintf-js/-/sprintf-js-1.0.3.tgz", + "integrity": "sha1-BOaSb2YolTVPPdAVIDYzuFcpfiw=", + "dev": true + }, + "srcset": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/srcset/-/srcset-1.0.0.tgz", + "integrity": "sha1-pWad4StC87HV6D7QPHEEb8SPQe8=", + "dev": true, + "requires": { + "array-uniq": "^1.0.2", + "number-is-nan": "^1.0.0" + } + }, + "string_decoder": { + "version": "0.10.31", + "resolved": "https://registry.npmjs.org/string_decoder/-/string_decoder-0.10.31.tgz", + "integrity": "sha1-YuIDvEF2bGwoyfyEMB2rHFMQ+pQ=", + "dev": true + }, + "strip-ansi": { + "version": "3.0.1", + "resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-3.0.1.tgz", + "integrity": "sha1-ajhfuIU9lS1f8F0Oiq+UJ43GPc8=", + "dev": true, + "requires": { + "ansi-regex": "^2.0.0" + } + }, + "strip-bom": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/strip-bom/-/strip-bom-2.0.0.tgz", + "integrity": "sha1-YhmoVhZSBJHzV4i9vxRHqZx+aw4=", + "dev": true, + "requires": { + "is-utf8": "^0.2.0" + } + }, + "strip-indent": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/strip-indent/-/strip-indent-1.0.1.tgz", + "integrity": "sha1-DHlipq3vp7vUrDZkYKY4VSrhoKI=", + "dev": true, + "requires": { + "get-stdin": "^4.0.1" + } + }, + "strip-json-comments": { + "version": "3.0.1", + "resolved": "https://registry.npmjs.org/strip-json-comments/-/strip-json-comments-3.0.1.tgz", + "integrity": "sha512-VTyMAUfdm047mwKl+u79WIdrZxtFtn+nBxHeb844XBQ9uMNTuTHdx2hc5RiAJYqwTj3wc/xe5HLSdJSkJ+WfZw==", + "dev": true + }, + "superagent": { + "version": "1.8.5", + "resolved": "https://registry.npmjs.org/superagent/-/superagent-1.8.5.tgz", + "integrity": "sha1-HA3cOvMOgOuE68BcshItqP6UC1U=", + "dev": true, + "requires": { + "component-emitter": "~1.2.0", + "cookiejar": "2.0.6", + "debug": "2", + "extend": "3.0.0", + "form-data": "1.0.0-rc3", + "formidable": "~1.0.14", + "methods": "~1.1.1", + "mime": "1.3.4", + "qs": "2.3.3", + "readable-stream": "1.0.27-1", + "reduce-component": "1.0.1" + }, + "dependencies": { + "debug": { + "version": "2.6.9", + "resolved": "https://registry.npmjs.org/debug/-/debug-2.6.9.tgz", + "integrity": "sha512-bC7ElrdJaJnPbAP+1EotYvqZsb3ecl5wi6Bfi6BJTUcNowp6cvspg0jXznRTKDjm/E7AdgFBVeAPVMNcKGsHMA==", + "dev": true, + "requires": { + "ms": "2.0.0" + } + }, + "mime": { + "version": "1.3.4", + "resolved": "https://registry.npmjs.org/mime/-/mime-1.3.4.tgz", + "integrity": "sha1-EV+eO2s9rylZmDyzjxSaLUDrXVM=", + "dev": true + }, + "ms": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/ms/-/ms-2.0.0.tgz", + "integrity": "sha1-VgiurfwAvmwpAd9fmGF4jeDVl8g=", + "dev": true + }, + "qs": { + "version": "2.3.3", + "resolved": "https://registry.npmjs.org/qs/-/qs-2.3.3.tgz", + "integrity": "sha1-6eha2+ddoLvkyOBHaghikPhjtAQ=", + "dev": true + } + } + }, + "supports-color": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-2.0.0.tgz", + "integrity": "sha1-U10EXOa2Nj+kARcIRimZXp3zJMc=", + "dev": true + }, + "taffydb": { + "version": "2.6.2", + "resolved": "https://registry.npmjs.org/taffydb/-/taffydb-2.6.2.tgz", + "integrity": "sha1-fLy2S1oUG2ou/CxdLGe04VCyomg=", + "dev": true + }, + "terser": { + "version": "3.17.0", + "resolved": "https://registry.npmjs.org/terser/-/terser-3.17.0.tgz", + "integrity": "sha512-/FQzzPJmCpjAH9Xvk2paiWrFq+5M6aVOf+2KRbwhByISDX/EujxsK+BAvrhb6H+2rtrLCHK9N01wO014vrIwVQ==", + "dev": true, + "requires": { + "commander": "^2.19.0", + "source-map": "~0.6.1", + "source-map-support": "~0.5.10" + } + }, + "trim-newlines": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/trim-newlines/-/trim-newlines-1.0.0.tgz", + "integrity": "sha1-WIeWa7WCpFA6QetST301ARgVphM=", + "dev": true + }, + "typedarray": { + "version": "0.0.6", + "resolved": "https://registry.npmjs.org/typedarray/-/typedarray-0.0.6.tgz", + "integrity": "sha1-hnrHTjhkGHsdPUfZlqeOxciDB3c=", + "dev": true + }, + "uc.micro": { + "version": "1.0.6", + "resolved": "https://registry.npmjs.org/uc.micro/-/uc.micro-1.0.6.tgz", + "integrity": "sha512-8Y75pvTYkLJW2hWQHXxoqRgV7qb9B+9vFEtidML+7koHUFapnVJAZ6cKs+Qjz5Aw3aZWHMC6u0wJE3At+nSGwA==", + "dev": true + }, + "underscore.string": { + "version": "3.2.3", + "resolved": "https://registry.npmjs.org/underscore.string/-/underscore.string-3.2.3.tgz", + "integrity": "sha1-gGmSYzZl1eX8tNsfs6hi62jp5to=", + "dev": true + }, + "util-deprecate": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/util-deprecate/-/util-deprecate-1.0.2.tgz", + "integrity": "sha1-RQ1Nyfpw3nMnYvvS1KKJgUGaDM8=", + "dev": true + }, + "validate-npm-package-license": { + "version": "3.0.4", + "resolved": "https://registry.npmjs.org/validate-npm-package-license/-/validate-npm-package-license-3.0.4.tgz", + "integrity": "sha512-DpKm2Ui/xN7/HQKCtpZxoRWBhZ9Z0kqtygG8XCgNQ8ZlDnxuQmWhj566j8fN4Cu3/JmbhsDo7fcAJq4s9h27Ew==", + "dev": true, + "requires": { + "spdx-correct": "^3.0.0", + "spdx-expression-parse": "^3.0.0" + } + }, + "which": { + "version": "1.2.14", + "resolved": "https://registry.npmjs.org/which/-/which-1.2.14.tgz", + "integrity": "sha1-mofEN48D6CfOyvGs31bHNsAcFOU=", + "dev": true, + "requires": { + "isexe": "^2.0.0" + } + }, + "wrappy": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/wrappy/-/wrappy-1.0.2.tgz", + "integrity": "sha1-tSQ9jz7BqjXxNkYFvA0QNuMKtp8=", + "dev": true + }, + "ws": { + "version": "6.2.1", + "resolved": "https://registry.npmjs.org/ws/-/ws-6.2.1.tgz", + "integrity": "sha512-GIyAXC2cB7LjvpgMt9EKS2ldqr0MTrORaleiOno6TweZ6r3TKtoFQWay/2PceJ3RuBasOHzXNn5Lrw1X0bEjqA==", + "dev": true, + "requires": { + "async-limiter": "~1.0.0" + } + }, + "xml2js": { + "version": "0.2.6", + "resolved": "https://registry.npmjs.org/xml2js/-/xml2js-0.2.6.tgz", + "integrity": "sha1-0gnE5N2h/JxFIUHvQcB39a399sQ=", + "dev": true, + "requires": { + "sax": "0.4.2" + } + }, + "xmlbuilder": { + "version": "0.4.2", + "resolved": "https://registry.npmjs.org/xmlbuilder/-/xmlbuilder-0.4.2.tgz", + "integrity": "sha1-F3bWXz/brUcKCNhgTN6xxOVA/4M=", + "dev": true + }, + "xmlcreate": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/xmlcreate/-/xmlcreate-2.0.1.tgz", + "integrity": "sha512-MjGsXhKG8YjTKrDCXseFo3ClbMGvUD4en29H2Cev1dv4P/chlpw6KdYmlCWDkhosBVKRDjM836+3e3pm1cBNJA==", + "dev": true + }, + "xtend": { + "version": "4.0.1", + "resolved": "https://registry.npmjs.org/xtend/-/xtend-4.0.1.tgz", + "integrity": "sha1-pcbVMr5lbiPbgg77lDofBJmNY68=", + "dev": true + }, + "yauzl": { + "version": "2.4.1", + "resolved": "https://registry.npmjs.org/yauzl/-/yauzl-2.4.1.tgz", + "integrity": "sha1-lSj0QtqxsihOWLQ3m7GU4i4MQAU=", + "dev": true, + "requires": { + "fd-slicer": "~1.0.1" + } + } + } +} diff --git a/package.json b/package.json index 52f766c1..2ec604af 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "gitanajs", - "version": "1.0.306", + "version": "1.0.307", "repository": { "type": "git", "url": "git://github.com/gitana/gitana-javascript-driver.git" @@ -23,13 +23,16 @@ "grunt": "1.0.1", "grunt-aws-s3": "^0.14.5", "grunt-bumpup": "^0.6.3", - "grunt-closure-compiler": "^0.0.21", "grunt-cloudfront": "^0.2.2", "grunt-connect-proxy": "^0.2.0", "grunt-contrib-connect": "~0.5.0", + "grunt-contrib-jshint": "^2.1.0", + "grunt-contrib-qunit": "^3.1.0", + "grunt-exec": "^3.0.0", "grunt-invalidate-cloudfront": "^0.1.6", "grunt-jsdoc": "^2.2.1", "grunt-release": "^0.14.0", + "grunt-terser": "^0.1.0", "ink-docstrap": "^1.3.2" } } \ No newline at end of file diff --git a/server/version.js b/server/version.js index d039027c..26036395 100644 --- a/server/version.js +++ b/server/version.js @@ -1,2 +1,2 @@ -var pkg = require("../package"); +const pkg = require('../package'); console.log(pkg.version); \ No newline at end of file diff --git a/thirdparty/base.js b/thirdparty/base.js index 5dc98ac1..bb1fd6fb 100644 --- a/thirdparty/base.js +++ b/thirdparty/base.js @@ -21,19 +21,19 @@ // Implementation Base.extend = function (_instance, _static) { // subclass - var extend = Base.prototype.extend; + const extend = Base.prototype.extend; // build the prototype Base._prototyping = true; - var proto = new this(); + const proto = new this(); extend.call(proto, _instance); proto.base = function () { // call this method from any other method to invoke that method's ancestor }; delete Base._prototyping; // create the wrapper for the constructor function - //var constructor = proto.constructor.valueOf(); //-dean - var constructor = proto.constructor; - var klass = proto.constructor = function () { + //const constructor = proto.constructor.valueOf(); //-dean + const constructor = proto.constructor; + const klass = proto.constructor = function () { if (!Base._prototyping) { if (this._constructing || this.constructor === klass) { // instantiation this._constructing = true; @@ -63,17 +63,17 @@ Base.prototype = { extend: function (source, value) { if (arguments.length > 1) { // extending with a name/value pair - var ancestor = this[source]; + const ancestor = this[source]; if (ancestor && (typeof value === 'function') && // overriding a method? // the valueOf() comparison is to avoid circular references (!ancestor.valueOf || ancestor.valueOf() !== value.valueOf()) && /\bbase\b/.test(value)) { // get the underlying method - var method = value.valueOf(); + const method = value.valueOf(); // override value = function () { - var previous = this.base || Base.prototype.base; + const previous = this.base || Base.prototype.base; this.base = ancestor; - var returnValue = method.apply(this, arguments); + const returnValue = method.apply(this, arguments); this.base = previous; return returnValue; }; @@ -85,24 +85,24 @@ } this[source] = value; } else if (source) { // extending with an object literal - var extend = Base.prototype.extend; + let extend = Base.prototype.extend; // if this object has a customized extend method then use it if (!Base._prototyping && typeof this !== 'function') { extend = this.extend || extend; } - var proto = { + const proto = { toSource: null }; // do the "toString" and other methods manually - var hidden = ['constructor', 'toString', 'valueOf']; + const hidden = ['constructor', 'toString', 'valueOf']; // if we are prototyping then include the constructor - for (var i = Base._prototyping ? 0 : 1; i < hidden.length; i++) { - var h = hidden[i]; + for (let i = Base._prototyping ? 0 : 1; i < hidden.length; i++) { + const h = hidden[i]; if (source[h] !== proto[h]) extend.call(this, h, source[h]); } // copy each of the source object's properties to this object - for (var key in source) { + for (let key in source) { if (!proto[key]) extend.call(this, key, source[key]); } } @@ -119,14 +119,14 @@ ancestor: Object, version: '1.1', forEach: function (object, block, context) { - for (var key in object) { + for (let key in object) { if (this.prototype[key] === undefined) { block.call(context, object[key], key, object); } } }, implement: function () { - for (var i = 0; i < arguments.length; i++) { + for (let i = 0; i < arguments.length; i++) { if (typeof arguments[i] === 'function') { // if it's a function, call it arguments[i](this.prototype); diff --git a/thirdparty/json2.js b/thirdparty/json2.js index 5e3695ba..c86457bf 100644 --- a/thirdparty/json2.js +++ b/thirdparty/json2.js @@ -116,7 +116,7 @@ // be converted to Date objects. myData = JSON.parse(text, function (key, value) { - var a; + const a; if (typeof value === 'string') { a = /^(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2}):(\d{2}(?:\.\d*)?)Z$/.exec(value); @@ -129,7 +129,7 @@ }); myData = JSON.parse('["Date(09/09/2001)"]', function (key, value) { - var d; + const d; if (typeof value === 'string' && value.slice(0, 5) === 'Date(' && value.slice(-1) === ')') { @@ -192,7 +192,7 @@ if (typeof JSON !== 'object') { }; } - var cx = /[\u0000\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g, + let cx = /[\u0000\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g, escapable = /[\\\"\x00-\x1f\x7f-\x9f\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g, gap, indent, @@ -217,7 +217,7 @@ if (typeof JSON !== 'object') { escapable.lastIndex = 0; return escapable.test(string) ? '"' + string.replace(escapable, function (a) { - var c = meta[a]; + const c = meta[a]; return typeof c === 'string' ? c : '\\u' + ('0000' + a.charCodeAt(0).toString(16)).slice(-4); @@ -229,7 +229,7 @@ if (typeof JSON !== 'object') { // Produce a string from holder[key]. - var i, // The loop counter. + let i, // The loop counter. k, // The member key. v, // The member value. length, @@ -364,7 +364,7 @@ if (typeof JSON !== 'object') { // A default replacer method can be provided. Use of the space parameter can // produce text that is more easily readable. - var i; + let i; gap = ''; indent = ''; @@ -408,14 +408,14 @@ if (typeof JSON !== 'object') { // The parse method takes a text and an optional reviver function, and returns // a JavaScript value if the text is a valid JSON text. - var j; + let j; function walk(holder, key) { // The walk method is used to recursively walk the resulting structure so // that modifications can be made. - var k, v, value = holder[key]; + let k, v, value = holder[key]; if (value && typeof value === 'object') { for (k in value) { if (Object.prototype.hasOwnProperty.call(value, k)) { diff --git a/tool/yuicompressor-2.4.7.jar b/tool/yuicompressor-2.4.7.jar deleted file mode 100644 index 3c9a408a..00000000 Binary files a/tool/yuicompressor-2.4.7.jar and /dev/null differ