UNPKG

@plattar/plattar-api

Version:

Module for interfacing with the Plattar API (https://www.plattar.com)

1,592 lines (1,330 loc) 75.5 kB
(function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}g.Plattar = f()}})(function(){var define,module,exports;return (function(){function r(e,n,t){function o(i,f){if(!n[i]){if(!e[i]){var c="function"==typeof require&&require;if(!f&&c)return c(i,!0);if(u)return u(i,!0);var a=new Error("Cannot find module '"+i+"'");throw a.code="MODULE_NOT_FOUND",a}var p=n[i]={exports:{}};e[i][0].call(p.exports,function(r){var n=e[i][1][r];return o(n||r)},p,p.exports,r,e,n,t)}return n[i].exports}for(var u="function"==typeof require&&require,i=0;i<t.length;i++)o(t[i]);return o}return r})()({1:[function(require,module,exports){ "use strict"; const Server = require("./server/plattar-server.js"); const Util = require("./util/plattar-util.js"); const Project = require("./types/application.js"); // import Scene and its types const Scene = require("./types/scene/scene.js"); const SceneAnnotation = require("./types/scene/scene-annotation.js"); const SceneAudio = require("./types/scene/scene-audio.js"); const SceneButton = require("./types/scene/scene-button.js"); const SceneCamera = require("./types/scene/scene-camera.js"); const SceneCarousel = require("./types/scene/scene-carousel.js"); const SceneImage = require("./types/scene/scene-image.js"); const SceneModel = require("./types/scene/scene-model.js"); const ScenePanorama = require("./types/scene/scene-panorama.js"); const ScenePoller = require("./types/scene/scene-poller.js"); const SceneProduct = require("./types/scene/scene-product.js"); const SceneShadow = require("./types/scene/scene-shadow.js"); const SceneVideo = require("./types/scene/scene-video.js"); const SceneVolumetric = require("./types/scene/scene-volumetric.js"); const SceneYoutube = require("./types/scene/scene-youtube.js"); const SceneScript = require("./types/scene/scene-script.js"); const SceneGallery = require("./types/scene/scene-gallery.js"); const SceneGalleryImage = require("./types/scene/scene-gallery-image.js"); // import Page and its types const Page = require("./types/page/page.js"); const CardButton = require("./types/page/card-button.js"); const CardHTML = require("./types/page/card-html.js"); const CardIFrame = require("./types/page/card-iframe.js"); const CardImage = require("./types/page/card-image.js"); const CardMap = require("./types/page/card-map.js"); const CardParagraph = require("./types/page/card-paragraph.js"); const CardRow = require("./types/page/card-row.js"); const CardSlider = require("./types/page/card-slider.js"); const CardTitle = require("./types/page/card-title.js"); const CardVideo = require("./types/page/card-video.js"); const CardYoutube = require("./types/page/card-youtube.js"); // import Product and its types const Product = require("./types/product/product.js"); const ProductVariation = require("./types/product/product-variation.js"); const ProductAnnotation = require("./types/product/product-annotation.js"); // import File and its types const FileAudio = require("./types/file/file-audio.js"); const FileVideo = require("./types/file/file-video.js"); const FileModel = require("./types/file/file-model.js"); const FileImage = require("./types/file/file-image.js"); const FileScript = require("./types/file/file-script.js"); // import misc const ScriptEvent = require("./types/misc/script-event.js"); const Tag = require("./types/misc/tag.js"); const ApplicationBuild = require("./types/misc/application-build.js"); const AsyncJob = require("./types/misc/async-job.js"); const AssetLibrary = require("./types/misc/asset-library.js"); // import trigger const TriggerImage = require("./types/trigger/trigger-image.js"); // import content-pipeline const Brief = require("./types/content-pipeline/brief.js"); const CommentBrief = require("./types/content-pipeline/comment-brief.js"); const CommentQuote = require("./types/content-pipeline/comment-quote.js"); const CommentSolution = require("./types/content-pipeline/comment-solution.js"); const PipelineUser = require("./types/content-pipeline/pipeline-user.js"); const Quote = require("./types/content-pipeline/quote.js"); const Rating = require("./types/content-pipeline/rating.js"); const Solution = require("./types/content-pipeline/solution.js"); const Folder = require("./types/content-pipeline/folder.js"); // base types const SceneObject = require("./types/scene/scene-base.js"); const CardObject = require("./types/page/card-base.js"); const ProductObject = require("./types/product/product-base.js"); const FileObject = require("./types/file/file-base.js"); const Version = require("./version"); // create a default server instance to be used globally Server.create(); console.log("using @plattar/plattar-api v" + Version); module.exports = { // core types Server, Util, Project, // scene and types Scene, SceneAnnotation, SceneAudio, SceneButton, SceneCamera, SceneCarousel, SceneImage, SceneModel, ScenePanorama, ScenePoller, SceneProduct, SceneShadow, SceneVideo, SceneVolumetric, SceneYoutube, SceneScript, SceneGallery, SceneGalleryImage, // page and types Page, CardButton, CardHTML, CardIFrame, CardImage, CardMap, CardParagraph, CardRow, CardSlider, CardTitle, CardVideo, CardYoutube, // product and types Product, ProductVariation, ProductAnnotation, // raw file/assets and types FileAudio, FileVideo, FileModel, FileImage, FileScript, FileObject, // misc ScriptEvent, Tag, ApplicationBuild, AsyncJob, AssetLibrary, // triggers TriggerImage, // content-pipeline Brief, CommentBrief, CommentQuote, CommentSolution, PipelineUser, Quote, Rating, Solution, Folder, // base types SceneObject, CardObject, ProductObject, version: Version }; },{"./server/plattar-server.js":5,"./types/application.js":6,"./types/content-pipeline/brief.js":7,"./types/content-pipeline/comment-brief.js":8,"./types/content-pipeline/comment-quote.js":9,"./types/content-pipeline/comment-solution.js":10,"./types/content-pipeline/folder.js":11,"./types/content-pipeline/pipeline-user.js":12,"./types/content-pipeline/quote.js":13,"./types/content-pipeline/rating.js":14,"./types/content-pipeline/solution.js":15,"./types/file/file-audio.js":16,"./types/file/file-base.js":17,"./types/file/file-image.js":18,"./types/file/file-model.js":19,"./types/file/file-script.js":20,"./types/file/file-video.js":21,"./types/misc/application-build.js":25,"./types/misc/asset-library.js":26,"./types/misc/async-job.js":27,"./types/misc/script-event.js":28,"./types/misc/tag.js":29,"./types/page/card-base.js":30,"./types/page/card-button.js":31,"./types/page/card-html.js":32,"./types/page/card-iframe.js":33,"./types/page/card-image.js":34,"./types/page/card-map.js":35,"./types/page/card-paragraph.js":36,"./types/page/card-row.js":37,"./types/page/card-slider.js":38,"./types/page/card-title.js":39,"./types/page/card-video.js":40,"./types/page/card-youtube.js":41,"./types/page/page.js":42,"./types/product/product-annotation.js":43,"./types/product/product-base.js":44,"./types/product/product-variation.js":45,"./types/product/product.js":46,"./types/scene/scene-annotation.js":47,"./types/scene/scene-audio.js":48,"./types/scene/scene-base.js":49,"./types/scene/scene-button.js":50,"./types/scene/scene-camera.js":51,"./types/scene/scene-carousel.js":52,"./types/scene/scene-gallery-image.js":53,"./types/scene/scene-gallery.js":54,"./types/scene/scene-image.js":55,"./types/scene/scene-model.js":56,"./types/scene/scene-panorama.js":57,"./types/scene/scene-poller.js":58,"./types/scene/scene-product.js":59,"./types/scene/scene-script.js":60,"./types/scene/scene-shadow.js":61,"./types/scene/scene-video.js":62,"./types/scene/scene-volumetric.js":63,"./types/scene/scene-youtube.js":64,"./types/scene/scene.js":65,"./types/trigger/trigger-image.js":66,"./util/plattar-util.js":67,"./version":68}],2:[function(require,module,exports){ (function (global){(function (){ "use strict"; // ref: https://github.com/tc39/proposal-global var getGlobal = function () { // the only reliable means to get the global object is // `Function('return this')()` // However, this causes CSP violations in Chrome apps. if (typeof self !== 'undefined') { return self; } if (typeof window !== 'undefined') { return window; } if (typeof global !== 'undefined') { return global; } throw new Error('unable to locate global object'); } var globalObject = getGlobal(); module.exports = exports = globalObject.fetch; // Needed for TypeScript and Webpack. if (globalObject.fetch) { exports.default = globalObject.fetch.bind(globalObject); } exports.Headers = globalObject.Headers; exports.Request = globalObject.Request; exports.Response = globalObject.Response; }).call(this)}).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {}) },{}],3:[function(require,module,exports){ // shim for using process in browser var process = module.exports = {}; // cached from whatever global is present so that test runners that stub it // don't break things. But we need to wrap it in a try catch in case it is // wrapped in strict mode code which doesn't define any globals. It's inside a // function because try/catches deoptimize in certain engines. var cachedSetTimeout; var cachedClearTimeout; function defaultSetTimout() { throw new Error('setTimeout has not been defined'); } function defaultClearTimeout () { throw new Error('clearTimeout has not been defined'); } (function () { try { if (typeof setTimeout === 'function') { cachedSetTimeout = setTimeout; } else { cachedSetTimeout = defaultSetTimout; } } catch (e) { cachedSetTimeout = defaultSetTimout; } try { if (typeof clearTimeout === 'function') { cachedClearTimeout = clearTimeout; } else { cachedClearTimeout = defaultClearTimeout; } } catch (e) { cachedClearTimeout = defaultClearTimeout; } } ()) function runTimeout(fun) { if (cachedSetTimeout === setTimeout) { //normal enviroments in sane situations return setTimeout(fun, 0); } // if setTimeout wasn't available but was latter defined if ((cachedSetTimeout === defaultSetTimout || !cachedSetTimeout) && setTimeout) { cachedSetTimeout = setTimeout; return setTimeout(fun, 0); } try { // when when somebody has screwed with setTimeout but no I.E. maddness return cachedSetTimeout(fun, 0); } catch(e){ try { // When we are in I.E. but the script has been evaled so I.E. doesn't trust the global object when called normally return cachedSetTimeout.call(null, fun, 0); } catch(e){ // same as above but when it's a version of I.E. that must have the global object for 'this', hopfully our context correct otherwise it will throw a global error return cachedSetTimeout.call(this, fun, 0); } } } function runClearTimeout(marker) { if (cachedClearTimeout === clearTimeout) { //normal enviroments in sane situations return clearTimeout(marker); } // if clearTimeout wasn't available but was latter defined if ((cachedClearTimeout === defaultClearTimeout || !cachedClearTimeout) && clearTimeout) { cachedClearTimeout = clearTimeout; return clearTimeout(marker); } try { // when when somebody has screwed with setTimeout but no I.E. maddness return cachedClearTimeout(marker); } catch (e){ try { // When we are in I.E. but the script has been evaled so I.E. doesn't trust the global object when called normally return cachedClearTimeout.call(null, marker); } catch (e){ // same as above but when it's a version of I.E. that must have the global object for 'this', hopfully our context correct otherwise it will throw a global error. // Some versions of I.E. have different rules for clearTimeout vs setTimeout return cachedClearTimeout.call(this, marker); } } } var queue = []; var draining = false; var currentQueue; var queueIndex = -1; function cleanUpNextTick() { if (!draining || !currentQueue) { return; } draining = false; if (currentQueue.length) { queue = currentQueue.concat(queue); } else { queueIndex = -1; } if (queue.length) { drainQueue(); } } function drainQueue() { if (draining) { return; } var timeout = runTimeout(cleanUpNextTick); draining = true; var len = queue.length; while(len) { currentQueue = queue; queue = []; while (++queueIndex < len) { if (currentQueue) { currentQueue[queueIndex].run(); } } queueIndex = -1; len = queue.length; } currentQueue = null; draining = false; runClearTimeout(timeout); } process.nextTick = function (fun) { var args = new Array(arguments.length - 1); if (arguments.length > 1) { for (var i = 1; i < arguments.length; i++) { args[i - 1] = arguments[i]; } } queue.push(new Item(fun, args)); if (queue.length === 1 && !draining) { runTimeout(drainQueue); } }; // v8 likes predictible objects function Item(fun, array) { this.fun = fun; this.array = array; } Item.prototype.run = function () { this.fun.apply(null, this.array); }; process.title = 'browser'; process.browser = true; process.env = {}; process.argv = []; process.version = ''; // empty string to avoid regexp issues process.versions = {}; function noop() {} process.on = noop; process.addListener = noop; process.once = noop; process.off = noop; process.removeListener = noop; process.removeAllListeners = noop; process.emit = noop; process.prependListener = noop; process.prependOnceListener = noop; process.listeners = function (name) { return [] } process.binding = function (name) { throw new Error('process.binding is not supported'); }; process.cwd = function () { return '/' }; process.chdir = function (dir) { throw new Error('process.chdir is not supported'); }; process.umask = function() { return 0; }; },{}],4:[function(require,module,exports){ const fetch = require("node-fetch"); class PlattarQuery { constructor(target, server) { if (!target) { throw new Error("PlattarQuery cannot be created as target object cannot be null"); } if (!server) { throw new Error("PlattarQuery cannot be created as server object cannot be null"); } this._target = target; this._server = server; this._params = []; this._getIncludeQuery = []; } get target() { return this._target; } get server() { return this._server; } getCookie(cname) { try { let name = cname + "="; let decodedCookie = decodeURIComponent(document.cookie); let ca = decodedCookie.split(';'); for (let i = 0; i < ca.length; i++) { let c = ca[i]; while (c.charAt(0) == ' ') { c = c.substring(1); } if (c.indexOf(name) == 0) { return c.substring(name.length, c.length); } } } catch (error) { /* silent */ } return ""; } _get(opt) { return new Promise((resolve, reject) => { const target = this.target; const server = this.server; // we cannot perform a GET request without an ID if (!target.id) { reject(new Error("PlattarQuery." + target.type() + ".get() - object id is missing")); return; } const options = opt || { cache: true }; // look in the cache only if its enabled if (options.cache === true) { // check global cache first const cached = PlattarQuery._GetGlobalCachedObject(target); if (cached) { resolve(cached); return; } } // otherwise, proceed with the fetching op const origin = server.originLocation.api_read; const auth = server.authToken; const headers = { 'cookie': 'laravel_session=' + this.getCookie('laravel_session') }; Object.assign(headers, auth); const reqopts = { method: "GET", headers: headers }; const includeQuery = this._IncludeQuery; const params = this._ParamFor("get"); let endpoint = origin + target.type() + "/" + target.id; if (includeQuery) { endpoint = endpoint + "?include=" + includeQuery; } if (params) { let appender = includeQuery ? "&" : "?"; params.forEach((param) => { endpoint = endpoint + appender + param.key + "=" + param.value; appender = "&"; }); } fetch(endpoint, reqopts) .then((res) => { if (res.ok) { try { return res.json(); } catch (err) { return new Error("PlattarQuery." + target.type() + ".get(" + target.id + ") - critical error occured, cannot proceed"); } } return new Error("PlattarQuery." + target.type() + ".get(" + target.id + ") - unexpected error occured, cannot proceed. error message is " + res.statusText); }) .then((json) => { if (json instanceof Error) { reject(json); } else { const PlattarUtil = require("../util/plattar-util.js"); PlattarUtil.reconstruct(target, json, options); resolve(target); } }); }); } _update() { return new Promise((resolve, reject) => { const target = this.target; const server = this.server; // we cannot perform a GET request without an ID if (!target.id) { reject(new Error("PlattarQuery." + target.type() + ".update() - object id is missing")); return; } // otherwise, proceed with the fetching op const origin = server.originLocation.api_write; const auth = server.authToken; const headers = { 'Accept': 'application/json', 'Content-Type': 'application/json', 'cookie': 'laravel_session=' + this.getCookie('laravel_session') }; Object.assign(headers, auth); const reqopts = { method: "PATCH", headers: headers, body: JSON.stringify( { data: { id: target.id, attributes: target.attributes }, meta: target.meta || {} } ) }; const params = this._ParamFor("update"); let endpoint = origin + target.type() + "/" + target.id; if (params) { let appender = "?"; params.forEach((param) => { endpoint = endpoint + appender + param.key + "=" + param.value; appender = "&"; }); } fetch(endpoint, reqopts) .then((res) => { if (res.ok) { try { return res.json(); } catch (err) { return new Error("PlattarQuery." + target.type() + ".update(" + target.id + ") - critical error occured, cannot proceed"); } } return new Error("PlattarQuery." + target.type() + ".update(" + target.id + ") - unexpected error occured, cannot proceed. error message is " + res.statusText); }) .then((json) => { if (json instanceof Error) { reject(json); } else { if (json.data) { const PlattarUtil = require("../util/plattar-util.js"); PlattarUtil.reconstruct(target, json, { cache: true }); } resolve(target); } }); }); } _create() { return new Promise((resolve, reject) => { const target = this.target; const server = this.server; // otherwise, proceed with the fetching op const origin = server.originLocation.api_write; const auth = server.authToken; const headers = { 'Accept': 'application/json', 'Content-Type': 'application/json', 'cookie': 'laravel_session=' + this.getCookie('laravel_session') }; Object.assign(headers, auth); const reqopts = { method: "POST", headers: headers, body: JSON.stringify( { data: { attributes: target.attributes }, meta: target.meta || {} } ) }; const params = this._ParamFor("create"); let endpoint = origin + target.type(); if (params) { let appender = "?"; params.forEach((param) => { endpoint = endpoint + appender + param.key + "=" + param.value; appender = "&"; }); } fetch(endpoint, reqopts) .then((res) => { if (res.ok) { try { return res.json(); } catch (err) { return new Error("PlattarQuery." + target.type() + ".create() - critical error occured, cannot proceed"); } } return new Error("PlattarQuery." + target.type() + ".create() - unexpected error occured, cannot proceed. error message is " + res.statusText); }) .then((json) => { if (json instanceof Error) { reject(json); } else { if (json.data) { target._id = json.data.id; const PlattarUtil = require("../util/plattar-util.js"); PlattarUtil.reconstruct(target, json, { cache: true }); } resolve(target); } }); }); } _delete() { return new Promise((resolve, reject) => { const target = this.target; const server = this.server; // we cannot perform a GET request without an ID if (!target.id) { reject(new Error("PlattarQuery." + target.type() + ".delete() - object id is missing")); return; } // otherwise, proceed with the fetching op const origin = server.originLocation.api_write; const auth = server.authToken; const headers = { 'Accept': 'application/json', 'Content-Type': 'application/json', 'cookie': 'laravel_session=' + this.getCookie('laravel_session') }; Object.assign(headers, auth); const reqopts = { method: "DELETE", headers: headers, body: JSON.stringify( { data: { id: target.id, attributes: target.attributes }, meta: target.meta || {} } ) }; const params = this._ParamFor("delete"); let endpoint = origin + target.type() + "/" + target.id; if (params) { let appender = "?"; params.forEach((param) => { endpoint = endpoint + appender + param.key + "=" + param.value; appender = "&"; }); } fetch(endpoint, reqopts) .then((res) => { if (res.ok) { try { return res.json(); } catch (err) { return new Error("PlattarQuery." + target.type() + ".delete() - critical error occured, cannot proceed"); } } return new Error("PlattarQuery." + target.type() + ".delete() - unexpected error occured, cannot proceed. error message is " + res.statusText); }) .then((json) => { if (json instanceof Error) { reject(json); } else { if (json.data) { target._id = json.data.id; const PlattarUtil = require("../util/plattar-util.js"); PlattarUtil.reconstruct(target, json, { cache: true }); } resolve(target); } }); }); } /** * Adds a specific request parameter */ _addParameter(key, value, type) { type = type || "all"; this._params.push({ key: key, value: value, type: type.toLowerCase() }); } /** * Includes this query with the next GET operation */ _include(args) { if (!args || args.length <= 0) { return this; } const PlattarUtil = require("../util/plattar-util.js"); args.forEach((obj) => { // object passed is of PlattarObject type if (Array.isArray(obj)) { obj.forEach((strObject) => { if (typeof strObject === "string" || strObject instanceof String) { this._getIncludeQuery.push(strObject); } else { throw new Error("PlattarQuery." + this.target.type() + ".include(...args) - argument of Array must only include Strings"); } }); } else if (PlattarUtil.isPlattarObject(obj)) { const type = obj.type(); if (Array.isArray(type)) { this._include(type); } else { this._getIncludeQuery.push(type); } } else { throw new Error("PlattarQuery." + this.target.type() + ".include(...args) - argument must be of type PlattarObject or Array but was type=" + (typeof obj) + " value=" + obj); } }); return this; } /** * Filters and returns all request parameters for a particular * request type */ _ParamFor(type) { type = type || "all"; const list = this._params.filter((objcheck) => { return objcheck.type === type || objcheck.type === "all"; }); if (list.length > 0) { return list; } return undefined; } /** * Performs a combination of all include queries */ get _IncludeQuery() { if (this._getIncludeQuery.length <= 0) { return undefined; } return `${this._getIncludeQuery.map((item) => `${item}`).join(",")}`; } } /** * Plattar uses GUID for all object ids. This means * that the GUID will not be shared between different * object instances. This allows us to create a global * static cache to optimise fetch operations for all * objects. * * WARNING: These are for internal uses only! */ PlattarQuery._GlobalObjectCache = {}; PlattarQuery._InvalidateGlobalCache = () => { PlattarQuery._GlobalObjectCache = {}; }; PlattarQuery._HasGlobalCachedObject = (obj) => { return PlattarQuery._GlobalObjectCache.hasOwnProperty(obj.id); }; PlattarQuery._GetGlobalCachedObject = (obj) => { return PlattarQuery._HasGlobalCachedObject(obj) ? PlattarQuery._GlobalObjectCache[obj.id] : undefined; }; PlattarQuery._SetGlobalCachedObject = (obj) => { // enable after extensive testing - too many bugs //PlattarQuery._GlobalObjectCache[obj.id] = obj; }; PlattarQuery._DeleteGlobalCachedObject = (obj) => { if (PlattarQuery._HasGlobalCachedObject(obj)) { delete PlattarQuery._GlobalObjectCache[obj.id]; } }; module.exports = PlattarQuery; },{"../util/plattar-util.js":67,"node-fetch":2}],5:[function(require,module,exports){ (function (process){(function (){ const fetch = require("node-fetch"); class PlattarServer { constructor() { this._authToken = {}; this._serverLocation = this.prod; } get prod() { return PlattarServer.match("prod"); } get isProd() { return this._serverLocation.type === "production"; } get review() { return PlattarServer.match("review"); } get isReview() { return this._serverLocation.type === "review"; } get staging() { return PlattarServer.match("staging"); } get isStaging() { return this._serverLocation.type === "staging"; } get dev() { return PlattarServer.match("dev"); } get isDev() { return this._serverLocation.type === "dev"; } get authToken() { return this._authToken; } get originLocation() { return this._serverLocation; } auth(token, opt) { const copt = opt || { validate: false }; return new Promise((resolve, reject) => { const server = this.originLocation.api_write; if (!server) { reject(new Error("Plattar.auth(token) - cannot authenticate as server not set via Plattar.origin(server)")); return; } if (!token) { reject(new Error("Plattar.auth(token) - token variable is undefined")); return; } if (!copt.validate) { this._authToken = { "plattar-auth-token": token }; resolve(this); return; } const endpoint = server + "plattaruser/xauth/validate"; const options = { method: "GET", headers: { "plattar-auth-token": token } }; fetch(endpoint, options).then((res) => { if (res.ok) { this._authToken = { "plattar-auth-token": token }; resolve(this); } else { reject(new Error("Plattar.auth(token) - failed to validate authentication token at " + endpoint)); } }); }); } origin(server, opt) { const copt = opt || { validate: false }; return new Promise((resolve, reject) => { if (!server) { reject(new Error("Plattar.origin(server) - server variable is undefined")); return; } if (!copt.validate) { this._serverLocation = server; resolve(this); return; } const endpoint = server.api_read + "ping"; const options = { method: "GET" }; fetch(endpoint, options).then((res) => { if (res.ok) { this._serverLocation = server; resolve(this); } else { reject(new Error("Plattar.origin(server) - failed to ping server at " + endpoint)); } }); }); } } /** * Matches the provided server name with a provided environment */ PlattarServer.match = (serverName) => { switch (serverName.toLowerCase()) { case "staging.plattar.space": case "cdn-staging.plattar.space": case "staging": return { base: "https://staging.plattar.space/", api_read: "https://api.plattar.space/v3/", api_write: "https://api.plattar.space/v3/", cdn: "https://cdn-staging.plattar.space/", cdn_image: "https://images.plattar.space/", analytics: "https://c.plattar.space/api/v2/analytics", type: "staging" } case "app.plattar.com": case "cdn.plattar.com": case "prod": case "production": return { base: "https://app.plattar.com/", api_read: "https://api.plattar.com/v3/", api_write: "https://api.plattar.com/v3/", cdn: "https://cdn.plattar.com/", cdn_image: "https://images.plattar.com/", analytics: "https://c.plattar.space/api/v2/analytics", type: "production" } case "review.plattar.com": case "review": case "qa": return { base: "https://review.plattar.com/", api_read: "https://review-api.plattar.com/v3/", api_write: "https://review-api.plattar.com/v3/", cdn: "https://cdn.plattar.com/", cdn_image: "https://images.plattar.com/", analytics: "https://c.plattar.space/api/v2/analytics", type: "review" } case "dev": case "developer": case "development": case "local": case "localhost": default: return { base: "https://localhost/", api_read: "https://localhost:3000/v3/", api_write: "https://localhost:3000/v3/", cdn: "https://cdn-dev.plattar.space/", cdn_image: "https://images-dev.plattar.space/", analytics: "https://localhost:3000/api/v2/analytics/", type: "dev" } } }; PlattarServer.create = (origin, auth) => { const newServer = new PlattarServer(); if (origin) { newServer.origin(origin); } if (auth) { newServer.auth(auth); } PlattarServer._default = newServer; return newServer; }; PlattarServer.disableTLS = () => { process.env.NODE_TLS_REJECT_UNAUTHORIZED = "0"; }; PlattarServer.default = () => { return PlattarServer._default; }; PlattarServer.location = () => { return PlattarServer.default().originLocation; }; module.exports = PlattarServer; }).call(this)}).call(this,require('_process')) },{"_process":3,"node-fetch":2}],6:[function(require,module,exports){ const PlattarBase = require("./interfaces/plattar-base.js"); class Application extends PlattarBase { static type() { return "application"; } } module.exports = Application; },{"./interfaces/plattar-base.js":22}],7:[function(require,module,exports){ const PlattarBase = require("../interfaces/plattar-base"); class Brief extends PlattarBase { static type() { return "brief"; } } module.exports = Brief; },{"../interfaces/plattar-base":22}],8:[function(require,module,exports){ const PlattarBase = require("../interfaces/plattar-base"); class CommentBrief extends PlattarBase { static type() { return "commentbrief"; } } module.exports = CommentBrief; },{"../interfaces/plattar-base":22}],9:[function(require,module,exports){ const PlattarBase = require("../interfaces/plattar-base"); class CommentQuote extends PlattarBase { static type() { return "commentquote"; } } module.exports = CommentQuote; },{"../interfaces/plattar-base":22}],10:[function(require,module,exports){ const PlattarBase = require("../interfaces/plattar-base"); class CommentSolution extends PlattarBase { static type() { return "commentsolution"; } } module.exports = CommentSolution; },{"../interfaces/plattar-base":22}],11:[function(require,module,exports){ const PlattarBase = require("../interfaces/plattar-base"); class Folder extends PlattarBase { static type() { return "folder"; } } module.exports = Folder; },{"../interfaces/plattar-base":22}],12:[function(require,module,exports){ const PlattarBase = require("../interfaces/plattar-base"); class PipelineUser extends PlattarBase { static type() { return "pipelineuser"; } } module.exports = PipelineUser; },{"../interfaces/plattar-base":22}],13:[function(require,module,exports){ const PlattarBase = require("../interfaces/plattar-base"); class Quote extends PlattarBase { static type() { return "quote"; } } module.exports = Quote; },{"../interfaces/plattar-base":22}],14:[function(require,module,exports){ const PlattarBase = require("../interfaces/plattar-base"); class Rating extends PlattarBase { static type() { return "rating"; } } module.exports = Rating; },{"../interfaces/plattar-base":22}],15:[function(require,module,exports){ const PlattarBase = require("../interfaces/plattar-base"); class Solution extends PlattarBase { static type() { return "solution"; } } module.exports = Solution; },{"../interfaces/plattar-base":22}],16:[function(require,module,exports){ const FileBase = require("./file-base.js"); class FileAudio extends FileBase { static type() { return "fileaudio"; } } module.exports = FileAudio; },{"./file-base.js":17}],17:[function(require,module,exports){ const PlattarBase = require("../interfaces/plattar-base.js"); const Server = require("../../server/plattar-server.js"); class FileBase extends PlattarBase { constructor(id, server) { super(id, server || Server.default()); if (this.constructor === FileBase) { throw new Error("FileBase is abstract and cannot be created"); } } static type() { const FileAudio = require("./file-audio.js"); const FileVideo = require("./file-video.js"); const FileModel = require("./file-model.js"); const FileImage = require("./file-image.js"); return [FileAudio, FileVideo, FileModel, FileImage]; } /** * Returns the full remote path of the file * Use this path to download the object into your machine */ get sourcePath() { if (!this.attributes.path) { return null; } return this.path + this.attributes.original_filename; } /** * Returns the full remote path of the file backup as a Zip File * Use this path to download the object object into your machine */ get backupPath() { if (!this.attributes.path) { return null; } return this.path + this.attributes.original_upload; } /** * Returns the remote head path to be used with other attributes * to get the final path */ get path() { if (!this.attributes.path) { return null; } return this._query.server.originLocation.cdn + this.attributes.path; } } module.exports = FileBase; },{"../../server/plattar-server.js":5,"../interfaces/plattar-base.js":22,"./file-audio.js":16,"./file-image.js":18,"./file-model.js":19,"./file-video.js":21}],18:[function(require,module,exports){ const FileBase = require("./file-base.js"); class FileImage extends FileBase { static type() { return "fileimage"; } } module.exports = FileImage; },{"./file-base.js":17}],19:[function(require,module,exports){ const FileBase = require("./file-base.js"); class FileModel extends FileBase { static type() { return "filemodel"; } } module.exports = FileModel; },{"./file-base.js":17}],20:[function(require,module,exports){ const FileBase = require("./file-base.js"); class FileScript extends FileBase { static type() { return "filescript"; } } module.exports = FileScript; },{"./file-base.js":17}],21:[function(require,module,exports){ const FileBase = require("./file-base.js"); class FileVideo extends FileBase { static type() { return "filevideo"; } } module.exports = FileVideo; },{"./file-base.js":17}],22:[function(require,module,exports){ const PlattarObject = require("./plattar-object.js"); const Server = require("../../server/plattar-server.js"); class PlattarBase extends PlattarObject { constructor(id, server) { super(id, server || Server.default()); if (this.constructor === PlattarBase) { throw new Error("PlattarBase is abstract and cannot be created"); } } } module.exports = PlattarBase; },{"../../server/plattar-server.js":5,"./plattar-object.js":24}],23:[function(require,module,exports){ /** * Handles the list of relationships for the provided object */ class PlattarObjectRelations { constructor(parent) { this._parent = parent; this._relatedObjects = {}; } /** * The parent that owns this list of relations */ get parent() { return this._parent; } /** * Inserts the provided PlattarObject into the relations list * * @param {*} obj The Object to insert. Object must be instance of PlattarObject */ _put(obj) { if (!obj) { return this; } const PlattarUtil = require("../../util/plattar-util.js"); // we only accept PlattarObject types if (!PlattarUtil.isPlattarObject(obj)) { throw new Error("PlattarObjectRelations._put(PlattarObject) - argument must be type of PlattarObject"); } // this is the first time the object is being inserted // initialise an empty array if (!this._relatedObjects.hasOwnProperty(obj.type())) { this._relatedObjects[obj.type()] = []; } // add the object this._relatedObjects[obj.type()].push(obj); } /** * Search for the specific object type and return a list of all * types. This function will always return a list even if length is zero * * @param {*} obj Object type to search. Object must be an instance of PlattarObject * @param {*} id (optional) Object ID to filter with */ filter(obj, id) { if (!obj) { return []; } const PlattarUtil = require("../../util/plattar-util.js"); // we only accept PlattarObject types if (!PlattarUtil.isPlattarObject(obj)) { throw new Error("PlattarObjectRelations.filter(PlattarObject) - argument must be type of PlattarObject"); } const type = obj.type(); // for array objects, we do each individual object if (Array.isArray(type)) { var compiledList = []; type.forEach((inObject) => { const retArray = this.filter(inObject, id); if (retArray.length > 0) { compiledList = compiledList.concat(retArray); } }); return compiledList; } // check if the key actually exists in the relations if (!this._relatedObjects.hasOwnProperty(type)) { return []; } const list = this._relatedObjects[type]; // if no id is supplied, we just want everything of type if (!id) { return list; } // filter and only return objects that match the provided id return list.filter((objcheck) => { return objcheck.id === id; }); } /** * Search for the specific object type and return the first index. * This function will return undefined if the object cannot be found. * * @param {*} obj Object type to search. Object must be an instance of PlattarObject * @param {*} id (optional) Object ID to filter with */ find(obj, id = null) { if (id === undefined) { return undefined; } const list = this.filter(obj, id); if (list.length <= 0) { return undefined; } return list[0]; } } module.exports = PlattarObjectRelations; },{"../../util/plattar-util.js":67}],24:[function(require,module,exports){ const PlattarQuery = require("../../server/plattar-query.js"); const PlattarObjectRelations = require("./plattar-object-relations.js"); class PlattarObject { constructor(id, server) { if (this.constructor === PlattarObject) { throw new Error("PlattarObject is abstract and cannot be created"); } this._id = id; this._attributes = {}; this._meta = {}; this._query = new PlattarQuery(this, server); this._relationships = new PlattarObjectRelations(this); } /** * Invalidates this specific Object from the Global Cache */ invalidate() { return PlattarQuery._DeleteGlobalCachedObject(this); } /** * Caches the current object in the global cache */ _cache() { return PlattarQuery._SetGlobalCachedObject(this); } /** * Returns the unique GUID of this object */ get id() { return this._id; } /** * Returns all attributes of the object */ get attributes() { return this._attributes; } /** * Returns any meta-data that should be posted */ get meta() { return this._meta; } /** * This can be used to override the current internal attributes * with new Data. Upon next request, the override attributes will * be used */ set overrideAttributes(attributes) { this._attributes = Object.assign({}, attributes); } get relationships() { return this._relationships; } get(opt) { return this._query._get(opt); } update() { return this._query._update(); } create() { return this._query._create(); } delete() { return this._query._delete(); } static type() { throw new Error("PlattarObject.type() - not implemented"); } type() { return this.constructor.type(); } /** * Used for performing additional query parameters */ static include(...args) { if (!args || args.length <= 0) { return []; } const includes = [this.type()]; args.forEach((obj) => { // object passed is of PlattarObject type if (Array.isArray(obj)) { obj.forEach((strObject) => { if (typeof strObject === "string" || strObject instanceof String) { includes.push(`${this.type()}.${strObject}`); } else { throw new Error("PlattarObject." + this.type() + ".include(...args) - argument of Array must only include Strings"); } }); } else if (obj.prototype instanceof PlattarObject) { includes.push(`${this.type()}.${obj.type()}`); } else { throw new Error("PlattarObject." + this.type() + ".include(...args) - argument must be of type PlattarObject or Array but was type=" + (typeof obj) + " value=" + obj); } }); return includes; } /** * Includes this query with the next GET operation */ include(...args) { this._query._include(args); return this; } /** * Adds a parameter for a particular request */ addParameter(key, value, type) { this._query._addParameter(key, value, type); return this; } } module.exports = PlattarObject; },{"../../server/plattar-query.js":4,"./plattar-object-relations.js":23}],25:[function(require,module,exports){ const PlattarBase = require("../interfaces/plattar-base.js"); class ApplicationBuild extends PlattarBase { static type() { return "applicationbuild"; } } module.exports = ApplicationBuild; },{"../interfaces/plattar-base.js":22}],26:[function(require,module,exports){ const PlattarBase