diff --git a/dist/client-service.js b/dist/client-service.js index f9a15b9..68e6020 100644 --- a/dist/client-service.js +++ b/dist/client-service.js @@ -175,7 +175,7 @@ var ServiceBase = /** @class */ (function () { * @param msg Response from Surix * @param handler Handles the response */ - ServiceBase.prototype.handleRpcReq = function (msg, handler) { + ServiceBase.prototype.handleRpcRep = function (msg, handler) { if (msg.success) { handler.rpcTracker[msg.id].resolve(msg.body); } @@ -203,7 +203,7 @@ var ServiceBase = /** @class */ (function () { var msg = event.data; switch (msg.type) { case 'rpcRep': - _this.handleRpcReq(msg, _this); + _this.handleRpcRep(msg, _this); break; case 'event': _this.emit(msg); diff --git a/dist/client-service.js.map b/dist/client-service.js.map index 800f40e..78b6615 100644 --- a/dist/client-service.js.map +++ b/dist/client-service.js.map @@ -1 +1 @@ -{"version":3,"sources":["webpack://Surix/webpack/universalModuleDefinition","webpack://Surix/webpack/bootstrap","webpack://Surix/./src/service-base.ts","webpack://Surix/./src/requests.ts","webpack://Surix/./index.ts","webpack://Surix/./src/service.ts","webpack://Surix/./src/functions/data.ts","webpack://Surix/./src/functions/toast.ts","webpack://Surix/./src/functions/menu.ts","webpack://Surix/./src/functions/events.ts"],"names":[],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,CAAC;AACD,O;ACVA;AACA;;AAEA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;;AAEA;AACA;;AAEA;AACA;AACA;;;AAGA;AACA;;AAEA;AACA;;AAEA;AACA;AACA;AACA,kDAA0C,gCAAgC;AAC1E;AACA;;AAEA;AACA;AACA;AACA,gEAAwD,kBAAkB;AAC1E;AACA,yDAAiD,cAAc;AAC/D;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,iDAAyC,iCAAiC;AAC1E,wHAAgH,mBAAmB,EAAE;AACrI;AACA;;AAEA;AACA;AACA;AACA,mCAA2B,0BAA0B,EAAE;AACv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IAAI,CAAC,eAAe,CAAC,mBAAQ,CAAC,IAAI,CAAC,QAAQ,EAAE,IAAI,CAAC,CAAC;IAC9D,CAAC;IACL,WAAC;AAAD,CAAC,CAfyB,0BAAW,GAepC;AAfY,oBAAI;;;;;;;;;;;;;;;;;;;;;;;ACJjB,4CAA8C;AAC9C,iCAAiC;AAEjC;IAA4B,0BAAW;IAAvC;;IASA,CAAC;IAPG;;;OAGG;IACI,gCAAe,GAAtB,UAAuB,OAA4B;QAC/C,IAAI,CAAC,UAAU,CAAC,YAAQ,CAAC,MAAM,CAAC,eAAe,EAAE,OAAO,CAAC,CAAC;IAC9D,CAAC;IACL,aAAC;AAAD,CAAC,CAT2B,0BAAW,GAStC;AATY,wBAAM","file":"client-service.js","sourcesContent":["(function webpackUniversalModuleDefinition(root, factory) {\n\tif(typeof exports === 'object' && typeof module === 'object')\n\t\tmodule.exports = factory();\n\telse if(typeof define === 'function' && define.amd)\n\t\tdefine(\"Surix\", [], factory);\n\telse if(typeof exports === 'object')\n\t\texports[\"Surix\"] = factory();\n\telse\n\t\troot[\"Surix\"] = factory();\n})(window, function() {\nreturn "," \t// The module cache\n \tvar installedModules = {};\n\n \t// The require function\n \tfunction __webpack_require__(moduleId) {\n\n \t\t// Check if module is in cache\n \t\tif(installedModules[moduleId]) {\n \t\t\treturn installedModules[moduleId].exports;\n \t\t}\n \t\t// Create a new module (and put it into the cache)\n \t\tvar module = installedModules[moduleId] = {\n \t\t\ti: moduleId,\n \t\t\tl: false,\n \t\t\texports: {}\n \t\t};\n\n \t\t// Execute the module function\n \t\tmodules[moduleId].call(module.exports, module, module.exports, __webpack_require__);\n\n \t\t// Flag the module as loaded\n \t\tmodule.l = true;\n\n \t\t// Return the exports of the module\n \t\treturn module.exports;\n \t}\n\n\n \t// expose the modules object (__webpack_modules__)\n \t__webpack_require__.m = modules;\n\n \t// expose the module cache\n \t__webpack_require__.c = installedModules;\n\n \t// define getter function for harmony exports\n \t__webpack_require__.d = function(exports, name, getter) {\n \t\tif(!__webpack_require__.o(exports, name)) {\n \t\t\tObject.defineProperty(exports, name, { enumerable: true, get: getter });\n \t\t}\n \t};\n\n \t// define __esModule on exports\n \t__webpack_require__.r = function(exports) {\n \t\tif(typeof Symbol !== 'undefined' && Symbol.toStringTag) {\n \t\t\tObject.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });\n \t\t}\n \t\tObject.defineProperty(exports, '__esModule', { value: true });\n \t};\n\n \t// create a fake namespace object\n \t// mode & 1: value is a module id, require it\n \t// mode & 2: merge all properties of value into the ns\n \t// mode & 4: return value when already ns object\n \t// mode & 8|1: behave like require\n \t__webpack_require__.t = function(value, mode) {\n \t\tif(mode & 1) value = __webpack_require__(value);\n \t\tif(mode & 8) return value;\n \t\tif((mode & 4) && typeof value === 'object' && value && value.__esModule) return value;\n \t\tvar ns = Object.create(null);\n \t\t__webpack_require__.r(ns);\n \t\tObject.defineProperty(ns, 'default', { enumerable: true, value: value });\n \t\tif(mode & 2 && typeof value != 'string') for(var key in value) __webpack_require__.d(ns, key, function(key) { return value[key]; }.bind(null, key));\n \t\treturn ns;\n \t};\n\n \t// getDefaultExport function for compatibility with non-harmony modules\n \t__webpack_require__.n = function(module) {\n \t\tvar getter = module && module.__esModule ?\n \t\t\tfunction getDefault() { return module['default']; } :\n \t\t\tfunction getModuleExports() { return module; };\n \t\t__webpack_require__.d(getter, 'a', getter);\n \t\treturn getter;\n \t};\n\n \t// Object.prototype.hasOwnProperty.call\n \t__webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };\n\n \t// __webpack_public_path__\n \t__webpack_require__.p = \"\";\n\n\n \t// Load entry module and return exports\n \treturn __webpack_require__(__webpack_require__.s = 2);\n","export class ServiceBase {\n private rpcTracker: any;\n private prefix: string = '__surix__';\n\n protected constructor() {\n this.rpcTracker = {};\n this.setUpService();\n }\n\n /**\n * Sends a request to Surixs\n * @param type Request type\n * @param payload Request payload\n */\n protected internalRequest(type: string, payload?: any): Promise {\n return this.rpc(type, payload);\n }\n \n /**\n * Sends a request to Surix \n * ====== TO BE DEPRICATED IN FUTURE =======\n * @param type Request type\n * @param payload Request payload \n * @returns Promise Returns a promise\n */\n public request(type: string, payload?: any): Promise {\n console.warn(`service.request method will be DEPRICATED in future. Please consider using service.${type} instead.`);\n return this.rpc(type, payload);\n }\n\n /**\n * An event listener wrapper \n * @param eventName A string representing the event name\n * @param handler a function that handles event\n */\n public internalOn(eventName: string, handler: any) {\n document.addEventListener(`${this.prefix}${eventName}`, handler);\n }\n\n /**\n * An event listener wrapper \n * ======== TO BE DEPRICATED IN FUTURE ============\n * @param eventName A string representing the event name\n * @param handler a function that handles event\n */\n public on(eventName: string, handler: any) {\n console.warn(`service.on method will be DEPRICATED in future. Please consider using service.events.${eventName} instead.`);\n document.addEventListener(`${this.prefix}${eventName}`, handler);\n }\n\n /**\n * Sends the specified message to Surix\n * @param msg Message to send to Surix\n */\n private sendMessage(msg: any) {\n window.parent.postMessage(msg, '*');\n }\n /**\n * Creates a promise then sends the message\n * @param name Name of the request to send to Surix\n * @param body \n */\n private rpc(name: string, body: any) {\n const reqId = Math.random();\n return new Promise((resolve, reject) => {\n this.rpcTracker[reqId] = { resolve, reject };\n const message = {\n name, \n body, \n type: 'rpcReq', \n id: reqId\n }\n this.sendMessage(message);\n });\n }\n /**\n * This handles the rpcReq type responses from Surix\n * @param msg Response from Surix\n * @param handler Handles the response\n */\n private handleRpcReq(msg: any, handler: any) {\n if(msg.success) {\n handler.rpcTracker[msg.id].resolve(msg.body);\n } else {\n handler.rpcTracker[msg.id].reject(msg.body);\n }\n // Remove the promise from the handler because \n // it has already been taken care of.\n delete handler.rpcTracker[msg.id];\n }\n /**\n * Emits a custom event\n * @param msg Message to be embedded to the custom event to be emitted\n */\n private emit(msg: any) {\n const event: Event = new CustomEvent(`${this.prefix}${msg.name}`, {detail: msg});\n document.dispatchEvent(event);\n }\n /**\n * Sets up Surix service\n */\n protected setUpService() {\n window.addEventListener('message', event => {\n const msg: any = event.data;\n switch(msg.type) {\n case 'rpcRep':\n this.handleRpcReq(msg, this);\n break;\n case 'event':\n this.emit(msg);\n break;\n }\n });\n }\n}","export const requests = {\n data: {\n createEntity: 'data.createEntity',\n project: 'data.project',\n getEntities: 'data.getEntities',\n getEntityById: 'data.getEntityById',\n addTagsToEntity: 'data.addTagsToEntity',\n removeTagsFromEntity: 'data.removeTagsFromEntity',\n getTags: 'data.getTags',\n updateTag: 'data.updateTag',\n getAppData: 'data.getAppData',\n updateAppData: 'data.updateAppData',\n createFile: 'data.createFile',\n getFileById: 'data.getFileById',\n getFiles: 'data.getFiles'\n },\n toast: {\n show: 'toast.show',\n },\n menu: {\n populate: 'menu.populate'\n },\n events: {\n menuItemClicked: 'menu-item-clicked',\n // TODO: this is for backwards compatibility\n // it is deprecated and will be removed in a future update\n menuClicked: 'menu-item-clicked'\n }\n}","import { Service } from './src/service';\nimport { requests } from './src/requests';\nimport { PersistedEntityData } from './src/types';\nexport {\n Service,\n requests\n}","import { ServiceBase } from './service-base';\nimport { Data } from './functions/data';\nimport { Toast } from './functions/toast';\nimport { Menu } from './functions/menu';\nimport { Events } from './functions/events';\nexport class Service extends ServiceBase {\n\n private _data: Data;\n private _toast: Toast;\n private _menu: Menu;\n private _events: Events;\n\n /**\n * Returns all data methods\n */\n public get data (): Data {\n return this._data;\n }\n /**\n * Returns all toast methods\n */\n public get toast (): Toast {\n return this._toast;\n }\n /**\n * Returns all menu methods\n */\n public get menu (): Menu {\n return this._menu;\n }\n\n /**\n * Returns all methods associated with events.\n */\n public get events (): Events {\n return this._events;\n }\n /**\n * Constructor\n */\n private constructor() {\n super();\n this._data = new Data();\n this._toast = new Toast();\n this._menu = new Menu();\n this._events = new Events();\n }\n\n /**\n * Provides Surix singleton\n */\n public static init(): Service {\n if(Service.instance == undefined){\n Service.instance = new Service();\n }\n return Service.instance;\n }\n \n private static instance?: Service = undefined;\n}","import {\n PersistedEntityData,\n TagUpdateParams,\n FileDetails, \n FileParams, \n TagsParams,\n EntityData,\n Project,\n AppData,\n Tag,\n IData,\n PersistedAppData\n} from \"../types\";\nimport { requests } from \"../requests\";\nimport { ServiceBase } from \"../service-base\";\n\nexport class Data extends ServiceBase implements IData{\n //public _service: Service;\n \n public constructor() {\n super();\n //this._service = Service.init();\n }\n\n /**\n * Saves an entity in Surix\n * @param entity EntityData entity to be saved\n * @returns Promise\n */\n public async createEntity(entity: EntityData): Promise {\n return await this.internalRequest(requests.data.createEntity, entity);\n }\n\n /**\n * Returns the current project\n * @returns Promise\n */\n public async project(): Promise {\n return await this.internalRequest(requests.data.project);\n }\n\n /**\n * Returns all the entities present\n * @param query (Optional) query\n * @returns Promise\n */\n public async getEntities(query?: any): Promise {\n return await this.internalRequest(requests.data.getEntities, query);\n }\n\n /**\n * Returns an entity identified by the id provided\n * @param id Surix Id\n * @returns Promise\n */\n public async getEntityById(id: string): Promise {\n return await this.internalRequest(requests.data.getEntityById, id);\n }\n\n /**\n * Adds tags to an existing entity\n * @param params Parameters to add tags\n * @returns Promise\n */\n public async addTagsToEntity(params: TagsParams): Promise {\n return await this.internalRequest(requests.data.addTagsToEntity, params);\n }\n\n /**\n * Removes tags from an entity\n * @param params TagsParams tag parameters\n */\n public async removeTagsFromEntity(params: TagsParams): Promise {\n return await this.internalRequest(requests.data.removeTagsFromEntity, params);\n }\n\n /**\n * Updates tags on an existing entity\n * @param params Update params\n */\n public async updateTag(params: TagUpdateParams): Promise {\n return await this.internalRequest(requests.data.updateTag, params);\n }\n\n /**\n * Returns all the tags available\n * @returns Promise\n */\n public async getTags(): Promise {\n return await this.internalRequest(requests.data.getTags);\n }\n\n public async getAppData(): Promise {\n return await this.internalRequest(requests.data.getAppData);\n }\n public async updateAppData(appData: AppData): Promise {\n return await this.internalRequest(requests.data.updateAppData, appData);\n }\n\n /**\n * Creates a file on Surix linked to the current project.\n * @param file FileMessage message details\n * @returns Promise\n */\n public async createFile(file: FileParams): Promise {\n return await this.internalRequest(requests.data.createFile, file);\n }\n\n /**\n * Gets a file associated with the id provided\n * @param id string Surix Id\n * @returns Promise\n */\n public async getFileById(id: string): Promise {\n return await this.internalRequest(requests.data.getFileById, id);\n }\n\n /**\n * Returns all files\n * @returns Promise\n */\n public async getFiles(): Promise{\n return await this.internalRequest(requests.data.getFiles);\n }\n}","import { ToastParams, IToast } from '../types';\nimport { requests } from '../requests';\nimport { ServiceBase } from '../service-base';\n\nexport class Toast extends ServiceBase implements IToast {\n // private _service: Service;\n\n public constructor() {\n super();\n //this._service = Service.init();\n }\n\n /**\n * Displays the message provided on toast on Surix\n * @param message ToastMessage message to show on the toast\n */\n public show(message: ToastParams): Promise {\n return this.internalRequest(requests.toast.show, message);\n }\n}","import { requests } from '../requests';\nimport { MenuItem } from '../types';\nimport { ServiceBase } from '../service-base';\n\nexport class Menu extends ServiceBase{\n //public _service: Service;\n\n public constructor() {\n super();\n //this._service = Service.init();\n }\n\n /**\n * Populates Surix app menu with the provided items\n * @param menu MenuItem[] menu items\n */\n public populate(menu: MenuItem[]): Promise {\n return this.internalRequest(requests.menu.populate, menu);\n }\n}","import { ServiceBase } from \"../service-base\";\nimport { requests } from \"../..\";\n\nexport class Events extends ServiceBase {\n\n /**\n * Registers an event onto the handler provided.\n * @param handler Function to handle events\n */\n public menuItemClicked(handler: (event: any) => any) {\n this.internalOn(requests.events.menuItemClicked, handler);\n }\n}"],"sourceRoot":""} \ No newline at end of file +{"version":3,"sources":["webpack://Surix/webpack/universalModuleDefinition","webpack://Surix/webpack/bootstrap","webpack://Surix/./src/service-base.ts","webpack://Surix/./src/requests.ts","webpack://Surix/./index.ts","webpack://Surix/./src/service.ts","webpack://Surix/./src/functions/data.ts","webpack://Surix/./src/functions/toast.ts","webpack://Surix/./src/functions/menu.ts","webpack://Surix/./src/functions/events.ts"],"names":[],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,CAAC;AACD,O;ACVA;AACA;;AAEA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;A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B;QAC5B,OAAO,IAAI,CAAC,eAAe,CAAC,mBAAQ,CAAC,KAAK,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC;IAC9D,CAAC;IACL,YAAC;AAAD,CAAC,CAf0B,0BAAW,GAerC;AAfY,sBAAK;;;;;;;;;;;;;;;;;;;;;;;ACJlB,wCAAuC;AAEvC,4CAA8C;AAE9C;IAA0B,wBAAW;IACjC,2BAA2B;IAE3B;eACI,iBAAO;QACP,iCAAiC;IACrC,CAAC;IAED;;;OAGG;IACI,uBAAQ,GAAf,UAAgB,IAAgB;QAC5B,OAAO,IAAI,CAAC,eAAe,CAAC,mBAAQ,CAAC,IAAI,CAAC,QAAQ,EAAE,IAAI,CAAC,CAAC;IAC9D,CAAC;IACL,WAAC;AAAD,CAAC,CAfyB,0BAAW,GAepC;AAfY,oBAAI;;;;;;;;;;;;;;;;;;;;;;;ACJjB,4CAA8C;AAC9C,iCAAiC;AAEjC;IAA4B,0BAAW;IAAvC;;IASA,CAAC;IAPG;;;OAGG;IACI,gCAAe,GAAtB,UAAuB,OAA4B;QAC/C,IAAI,CAAC,UAAU,CAAC,YAAQ,CAAC,MAAM,CAAC,eAAe,EAAE,OAAO,CAAC,CAAC;IAC9D,CAAC;IACL,aAAC;AAAD,CAAC,CAT2B,0BAAW,GAStC;AATY,wBAAM","file":"client-service.js","sourcesContent":["(function webpackUniversalModuleDefinition(root, factory) {\n\tif(typeof exports === 'object' && typeof module === 'object')\n\t\tmodule.exports = factory();\n\telse if(typeof define === 'function' && define.amd)\n\t\tdefine(\"Surix\", [], factory);\n\telse if(typeof exports === 'object')\n\t\texports[\"Surix\"] = factory();\n\telse\n\t\troot[\"Surix\"] = factory();\n})(window, function() {\nreturn "," \t// The module cache\n \tvar installedModules = {};\n\n \t// The require function\n \tfunction __webpack_require__(moduleId) {\n\n \t\t// Check if module is in cache\n \t\tif(installedModules[moduleId]) {\n \t\t\treturn installedModules[moduleId].exports;\n \t\t}\n \t\t// Create a new module (and put it into the cache)\n \t\tvar module = installedModules[moduleId] = {\n \t\t\ti: moduleId,\n \t\t\tl: false,\n \t\t\texports: {}\n \t\t};\n\n \t\t// Execute the module function\n \t\tmodules[moduleId].call(module.exports, module, module.exports, __webpack_require__);\n\n \t\t// Flag the module as loaded\n \t\tmodule.l = true;\n\n \t\t// Return the exports of the module\n \t\treturn module.exports;\n \t}\n\n\n \t// expose the modules object (__webpack_modules__)\n \t__webpack_require__.m = modules;\n\n \t// expose the module cache\n \t__webpack_require__.c = installedModules;\n\n \t// define getter function for harmony exports\n \t__webpack_require__.d = function(exports, name, getter) {\n \t\tif(!__webpack_require__.o(exports, name)) {\n \t\t\tObject.defineProperty(exports, name, { enumerable: true, get: getter });\n \t\t}\n \t};\n\n \t// define __esModule on exports\n \t__webpack_require__.r = function(exports) {\n \t\tif(typeof Symbol !== 'undefined' && Symbol.toStringTag) {\n \t\t\tObject.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });\n \t\t}\n \t\tObject.defineProperty(exports, '__esModule', { value: true });\n \t};\n\n \t// create a fake namespace object\n \t// mode & 1: value is a module id, require it\n \t// mode & 2: merge all properties of value into the ns\n \t// mode & 4: return value when already ns object\n \t// mode & 8|1: behave like require\n \t__webpack_require__.t = function(value, mode) {\n \t\tif(mode & 1) value = __webpack_require__(value);\n \t\tif(mode & 8) return value;\n \t\tif((mode & 4) && typeof value === 'object' && value && value.__esModule) return value;\n \t\tvar ns = Object.create(null);\n \t\t__webpack_require__.r(ns);\n \t\tObject.defineProperty(ns, 'default', { enumerable: true, value: value });\n \t\tif(mode & 2 && typeof value != 'string') for(var key in value) __webpack_require__.d(ns, key, function(key) { return value[key]; }.bind(null, key));\n \t\treturn ns;\n \t};\n\n \t// getDefaultExport function for compatibility with non-harmony modules\n \t__webpack_require__.n = function(module) {\n \t\tvar getter = module && module.__esModule ?\n \t\t\tfunction getDefault() { return module['default']; } :\n \t\t\tfunction getModuleExports() { return module; };\n \t\t__webpack_require__.d(getter, 'a', getter);\n \t\treturn getter;\n \t};\n\n \t// Object.prototype.hasOwnProperty.call\n \t__webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };\n\n \t// __webpack_public_path__\n \t__webpack_require__.p = \"\";\n\n\n \t// Load entry module and return exports\n \treturn __webpack_require__(__webpack_require__.s = 2);\n","export class ServiceBase {\n private rpcTracker: any;\n private prefix: string = '__surix__';\n\n protected constructor() {\n this.rpcTracker = {};\n this.setUpService();\n }\n\n /**\n * Sends a request to Surixs\n * @param type Request type\n * @param payload Request payload\n */\n protected internalRequest(type: string, payload?: any): Promise {\n return this.rpc(type, payload);\n }\n \n /**\n * Sends a request to Surix \n * ====== TO BE DEPRICATED IN FUTURE =======\n * @param type Request type\n * @param payload Request payload \n * @returns Promise Returns a promise\n */\n public request(type: string, payload?: any): Promise {\n console.warn(`service.request method will be DEPRICATED in future. Please consider using service.${type} instead.`);\n return this.rpc(type, payload);\n }\n\n /**\n * An event listener wrapper \n * @param eventName A string representing the event name\n * @param handler a function that handles event\n */\n public internalOn(eventName: string, handler: any) {\n document.addEventListener(`${this.prefix}${eventName}`, handler);\n }\n\n /**\n * An event listener wrapper \n * ======== TO BE DEPRICATED IN FUTURE ============\n * @param eventName A string representing the event name\n * @param handler a function that handles event\n */\n public on(eventName: string, handler: any) {\n console.warn(`service.on method will be DEPRICATED in future. Please consider using service.events.${eventName} instead.`);\n document.addEventListener(`${this.prefix}${eventName}`, handler);\n }\n\n /**\n * Sends the specified message to Surix\n * @param msg Message to send to Surix\n */\n private sendMessage(msg: any) {\n window.parent.postMessage(msg, '*');\n }\n /**\n * Creates a promise then sends the message\n * @param name Name of the request to send to Surix\n * @param body \n */\n private rpc(name: string, body: any) {\n const reqId = Math.random();\n return new Promise((resolve, reject) => {\n this.rpcTracker[reqId] = { resolve, reject };\n const message = {\n name, \n body, \n type: 'rpcReq', \n id: reqId\n }\n this.sendMessage(message);\n });\n }\n /**\n * This handles the rpcReq type responses from Surix\n * @param msg Response from Surix\n * @param handler Handles the response\n */\n private handleRpcRep(msg: any, handler: any) {\n if(msg.success) {\n handler.rpcTracker[msg.id].resolve(msg.body);\n } else {\n handler.rpcTracker[msg.id].reject(msg.body);\n }\n // Remove the promise from the handler because \n // it has already been taken care of.\n delete handler.rpcTracker[msg.id];\n }\n /**\n * Emits a custom event\n * @param msg Message to be embedded to the custom event to be emitted\n */\n private emit(msg: any) {\n const event: Event = new CustomEvent(`${this.prefix}${msg.name}`, {detail: msg});\n document.dispatchEvent(event);\n }\n /**\n * Sets up Surix service\n */\n protected setUpService() {\n window.addEventListener('message', event => {\n const msg: any = event.data;\n switch(msg.type) {\n case 'rpcRep':\n this.handleRpcRep(msg, this);\n break;\n case 'event':\n this.emit(msg);\n break;\n }\n });\n }\n}","export const requests = {\n data: {\n createEntity: 'data.createEntity',\n project: 'data.project',\n getEntities: 'data.getEntities',\n getEntityById: 'data.getEntityById',\n addTagsToEntity: 'data.addTagsToEntity',\n removeTagsFromEntity: 'data.removeTagsFromEntity',\n getTags: 'data.getTags',\n updateTag: 'data.updateTag',\n getAppData: 'data.getAppData',\n updateAppData: 'data.updateAppData',\n createFile: 'data.createFile',\n getFileById: 'data.getFileById',\n getFiles: 'data.getFiles'\n },\n toast: {\n show: 'toast.show',\n },\n menu: {\n populate: 'menu.populate'\n },\n events: {\n menuItemClicked: 'menu-item-clicked',\n // TODO: this is for backwards compatibility\n // it is deprecated and will be removed in a future update\n menuClicked: 'menu-item-clicked'\n }\n}","import { Service } from './src/service';\nimport { requests } from './src/requests';\nimport { PersistedEntityData } from './src/types';\nexport {\n Service,\n requests\n}","import { ServiceBase } from './service-base';\nimport { Data } from './functions/data';\nimport { Toast } from './functions/toast';\nimport { Menu } from './functions/menu';\nimport { Events } from './functions/events';\nexport class Service extends ServiceBase {\n\n private _data: Data;\n private _toast: Toast;\n private _menu: Menu;\n private _events: Events;\n\n /**\n * Returns all data methods\n */\n public get data (): Data {\n return this._data;\n }\n /**\n * Returns all toast methods\n */\n public get toast (): Toast {\n return this._toast;\n }\n /**\n * Returns all menu methods\n */\n public get menu (): Menu {\n return this._menu;\n }\n\n /**\n * Returns all methods associated with events.\n */\n public get events (): Events {\n return this._events;\n }\n /**\n * Constructor\n */\n private constructor() {\n super();\n this._data = new Data();\n this._toast = new Toast();\n this._menu = new Menu();\n this._events = new Events();\n }\n\n /**\n * Provides Surix singleton\n */\n public static init(): Service {\n if(Service.instance == undefined){\n Service.instance = new Service();\n }\n return Service.instance;\n }\n \n private static instance?: Service = undefined;\n}","import {\n PersistedEntityData,\n TagUpdateParams,\n FileDetails, \n FileParams, \n TagsParams,\n EntityData,\n Project,\n AppData,\n Tag,\n IData,\n PersistedAppData,\n QueryParams\n} from \"../types\";\nimport { requests } from \"../requests\";\nimport { ServiceBase } from \"../service-base\";\n\nexport class Data extends ServiceBase implements IData{\n //public _service: Service;\n \n public constructor() {\n super();\n //this._service = Service.init();\n }\n\n /**\n * Saves an entity in Surix\n * @param entity EntityData entity to be saved\n * @returns Promise\n */\n public async createEntity(entity: EntityData): Promise {\n return await this.internalRequest(requests.data.createEntity, entity);\n }\n\n /**\n * Returns the current project\n * @returns Promise\n */\n public async project(): Promise {\n return await this.internalRequest(requests.data.project);\n }\n\n /**\n * Returns all the entities present\n * @param query (Optional) query\n * @returns Promise\n */\n public async getEntities(query?: QueryParams): Promise {\n return await this.internalRequest(requests.data.getEntities, query);\n }\n\n /**\n * Returns an entity identified by the id provided\n * @param id Surix Id\n * @returns Promise\n */\n public async getEntityById(id: string): Promise {\n return await this.internalRequest(requests.data.getEntityById, id);\n }\n\n /**\n * Adds tags to an existing entity\n * @param params Parameters to add tags\n * @returns Promise\n */\n public async addTagsToEntity(params: TagsParams): Promise {\n return await this.internalRequest(requests.data.addTagsToEntity, params);\n }\n\n /**\n * Removes tags from an entity\n * @param params TagsParams tag parameters\n */\n public async removeTagsFromEntity(params: TagsParams): Promise {\n return await this.internalRequest(requests.data.removeTagsFromEntity, params);\n }\n\n /**\n * Updates tags on an existing entity\n * @param params Update params\n */\n public async updateTag(params: TagUpdateParams): Promise {\n return await this.internalRequest(requests.data.updateTag, params);\n }\n\n /**\n * Returns all the tags available\n * @returns Promise\n */\n public async getTags(): Promise {\n return await this.internalRequest(requests.data.getTags);\n }\n\n public async getAppData(): Promise {\n return await this.internalRequest(requests.data.getAppData);\n }\n public async updateAppData(appData: AppData): Promise {\n return await this.internalRequest(requests.data.updateAppData, appData);\n }\n\n /**\n * Creates a file on Surix linked to the current project.\n * @param file FileMessage message details\n * @returns Promise\n */\n public async createFile(file: FileParams): Promise {\n return await this.internalRequest(requests.data.createFile, file);\n }\n\n /**\n * Gets a file associated with the id provided\n * @param id string Surix Id\n * @returns Promise\n */\n public async getFileById(id: string): Promise {\n return await this.internalRequest(requests.data.getFileById, id);\n }\n\n /**\n * Returns all files\n * @returns Promise\n */\n public async getFiles(): Promise{\n return await this.internalRequest(requests.data.getFiles);\n }\n}","import { ToastParams, IToast } from '../types';\nimport { requests } from '../requests';\nimport { ServiceBase } from '../service-base';\n\nexport class Toast extends ServiceBase implements IToast {\n // private _service: Service;\n\n public constructor() {\n super();\n //this._service = Service.init();\n }\n\n /**\n * Displays the message provided on toast on Surix\n * @param message ToastMessage message to show on the toast\n */\n public show(message: ToastParams): Promise {\n return this.internalRequest(requests.toast.show, message);\n }\n}","import { requests } from '../requests';\nimport { MenuItem } from '../types';\nimport { ServiceBase } from '../service-base';\n\nexport class Menu extends ServiceBase{\n //public _service: Service;\n\n public constructor() {\n super();\n //this._service = Service.init();\n }\n\n /**\n * Populates Surix app menu with the provided items\n * @param menu MenuItem[] menu items\n */\n public populate(menu: MenuItem[]): Promise {\n return this.internalRequest(requests.menu.populate, menu);\n }\n}","import { ServiceBase } from \"../service-base\";\nimport { requests } from \"../..\";\n\nexport class Events extends ServiceBase {\n\n /**\n * Registers an event onto the handler provided.\n * @param handler Function to handle events\n */\n public menuItemClicked(handler: (event: any) => any) {\n this.internalOn(requests.events.menuItemClicked, handler);\n }\n}"],"sourceRoot":""} \ No newline at end of file diff --git a/dist/client-service.min.js b/dist/client-service.min.js index 95ba434..12e2bd2 100644 --- a/dist/client-service.min.js +++ b/dist/client-service.min.js @@ -1 +1 @@ -!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define("Surix",[],e):"object"==typeof exports?exports.Surix=e():t.Surix=e()}(window,function(){return function(t){var e={};function n(r){if(e[r])return e[r].exports;var o=e[r]={i:r,l:!1,exports:{}};return t[r].call(o.exports,o,o.exports,n),o.l=!0,o.exports}return n.m=t,n.c=e,n.d=function(t,e,r){n.o(t,e)||Object.defineProperty(t,e,{enumerable:!0,get:r})},n.r=function(t){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})},n.t=function(t,e){if(1&e&&(t=n(t)),8&e)return t;if(4&e&&"object"==typeof t&&t&&t.__esModule)return t;var r=Object.create(null);if(n.r(r),Object.defineProperty(r,"default",{enumerable:!0,value:t}),2&e&&"string"!=typeof t)for(var o in t)n.d(r,o,function(e){return t[e]}.bind(null,o));return r},n.n=function(t){var e=t&&t.__esModule?function(){return t.default}:function(){return t};return n.d(e,"a",e),e},n.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},n.p="",n(n.s=2)}([function(t,e,n){"use strict";Object.defineProperty(e,"__esModule",{value:!0});var r=function(){function t(){this.prefix="__surix__",this.rpcTracker={},this.setUpService()}return t.prototype.internalRequest=function(t,e){return this.rpc(t,e)},t.prototype.request=function(t,e){return console.warn("service.request method will be DEPRICATED in future. Please consider using service."+t+" instead."),this.rpc(t,e)},t.prototype.internalOn=function(t,e){document.addEventListener(""+this.prefix+t,e)},t.prototype.on=function(t,e){console.warn("service.on method will be DEPRICATED in future. Please consider using service.events."+t+" instead."),document.addEventListener(""+this.prefix+t,e)},t.prototype.sendMessage=function(t){window.parent.postMessage(t,"*")},t.prototype.rpc=function(t,e){var n=this,r=Math.random();return new Promise(function(o,i){n.rpcTracker[r]={resolve:o,reject:i};var u={name:t,body:e,type:"rpcReq",id:r};n.sendMessage(u)})},t.prototype.handleRpcReq=function(t,e){t.success?e.rpcTracker[t.id].resolve(t.body):e.rpcTracker[t.id].reject(t.body),delete e.rpcTracker[t.id]},t.prototype.emit=function(t){var e=new CustomEvent(""+this.prefix+t.name,{detail:t});document.dispatchEvent(e)},t.prototype.setUpService=function(){var t=this;window.addEventListener("message",function(e){var n=e.data;switch(n.type){case"rpcRep":t.handleRpcReq(n,t);break;case"event":t.emit(n)}})},t}();e.ServiceBase=r},function(t,e,n){"use strict";Object.defineProperty(e,"__esModule",{value:!0}),e.requests={data:{createEntity:"data.createEntity",project:"data.project",getEntities:"data.getEntities",getEntityById:"data.getEntityById",addTagsToEntity:"data.addTagsToEntity",removeTagsFromEntity:"data.removeTagsFromEntity",getTags:"data.getTags",updateTag:"data.updateTag",getAppData:"data.getAppData",updateAppData:"data.updateAppData",createFile:"data.createFile",getFileById:"data.getFileById",getFiles:"data.getFiles"},toast:{show:"toast.show"},menu:{populate:"menu.populate"},events:{menuItemClicked:"menu-item-clicked",menuClicked:"menu-item-clicked"}}},function(t,e,n){"use strict";Object.defineProperty(e,"__esModule",{value:!0});var r=n(3);e.Service=r.Service;var o=n(1);e.requests=o.requests},function(t,e,n){"use strict";var r=this&&this.__extends||function(){var t=function(e,n){return(t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var n in e)e.hasOwnProperty(n)&&(t[n]=e[n])})(e,n)};return function(e,n){function r(){this.constructor=e}t(e,n),e.prototype=null===n?Object.create(n):(r.prototype=n.prototype,new r)}}();Object.defineProperty(e,"__esModule",{value:!0});var o=n(0),i=n(4),u=n(5),s=n(6),a=n(7),c=function(t){function e(){var e=t.call(this)||this;return e._data=new i.Data,e._toast=new u.Toast,e._menu=new s.Menu,e._events=new a.Events,e}return r(e,t),Object.defineProperty(e.prototype,"data",{get:function(){return this._data},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"toast",{get:function(){return this._toast},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"menu",{get:function(){return this._menu},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"events",{get:function(){return this._events},enumerable:!0,configurable:!0}),e.init=function(){return void 0==e.instance&&(e.instance=new e),e.instance},e.instance=void 0,e}(o.ServiceBase);e.Service=c},function(t,e,n){"use strict";var r=this&&this.__extends||function(){var t=function(e,n){return(t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var n in e)e.hasOwnProperty(n)&&(t[n]=e[n])})(e,n)};return function(e,n){function r(){this.constructor=e}t(e,n),e.prototype=null===n?Object.create(n):(r.prototype=n.prototype,new r)}}(),o=this&&this.__awaiter||function(t,e,n,r){return new(n||(n=Promise))(function(o,i){function u(t){try{a(r.next(t))}catch(t){i(t)}}function s(t){try{a(r.throw(t))}catch(t){i(t)}}function a(t){t.done?o(t.value):new n(function(e){e(t.value)}).then(u,s)}a((r=r.apply(t,e||[])).next())})},i=this&&this.__generator||function(t,e){var n,r,o,i,u={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:s(0),throw:s(1),return:s(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function s(i){return function(s){return function(i){if(n)throw new TypeError("Generator is already executing.");for(;u;)try{if(n=1,r&&(o=2&i[0]?r.return:i[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,i[1])).done)return o;switch(r=0,o&&(i=[2&i[0],o.value]),i[0]){case 0:case 1:o=i;break;case 4:return u.label++,{value:i[1],done:!1};case 5:u.label++,r=i[1],i=[0];continue;case 7:i=u.ops.pop(),u.trys.pop();continue;default:if(!(o=(o=u.trys).length>0&&o[o.length-1])&&(6===i[0]||2===i[0])){u=0;continue}if(3===i[0]&&(!o||i[1]>o[0]&&i[1]0&&o[o.length-1])&&(6===i[0]||2===i[0])){u=0;continue}if(3===i[0]&&(!o||i[1]>o[0]&&i[1] */ - getEntities(query?: any): Promise; + getEntities(query?: QueryParams): Promise; /** * Returns an entity identified by the id provided * @param id Surix Id diff --git a/dist/src/service-base.d.ts b/dist/src/service-base.d.ts index 52084ad..8b673f9 100644 --- a/dist/src/service-base.d.ts +++ b/dist/src/service-base.d.ts @@ -45,7 +45,7 @@ export declare class ServiceBase { * @param msg Response from Surix * @param handler Handles the response */ - private handleRpcReq; + private handleRpcRep; /** * Emits a custom event * @param msg Message to be embedded to the custom event to be emitted diff --git a/dist/src/types.d.ts b/dist/src/types.d.ts index 1587118..a936c0b 100644 --- a/dist/src/types.d.ts +++ b/dist/src/types.d.ts @@ -49,6 +49,21 @@ export interface MenuItem { default?: boolean; } +export interface QueryMatch { + [fieldOrOp: string]: any; +} + +export interface QueryParams { + [key: string]: any; + query?: QueryMatch; + limit?: number; + skip?: number; + sort?: { + [field: string]: number; + }; + tags?: string[]; +} + export interface FileParams { name: string; public: boolean; @@ -109,7 +124,7 @@ interface HasTimestamps { export interface IData { createEntity(entity: EntityData): Promise; project(): Promise; - getEntities(query?: any): Promise; + getEntities(query?: QueryParams): Promise; getEntityById(id: string): Promise; addTagsToEntity(params: TagsParams): Promise; removeTagsFromEntity(params: TagsParams): Promise;