diff --git a/README.md b/README.md index 65cf414..78ffe83 100644 --- a/README.md +++ b/README.md @@ -15,40 +15,40 @@ const requests = Surix.requests; ``` or ```javascript - + const service = Surix.Service.init(); const requests = Surix.requests; ``` `Service` is the service itself. -`requests` contains all the request types available. - -`requests.data` contains: -- `createEntity`: Creates an entity in the current Surix project (expects entity: any parameter). -- `getEntities` Queries entities from the current Surix project. -- `getEntityById`: Gets a single entity by its Surix id. -- `addTagsToEntity`: Add tags to an existing entity. -- `removeTagsFromEntity`: Removes tags from an entity. -- `getTags`: Gets all the entity tags in the project. -- `updateTag`: Updates the specified tag in an entity. -- `project`: Fetches the current Surix project. -- `getAppData`: Fetches app data stored by the app in the current project -- `updateAppData`: Updates/adds app data to the current project. -- `createFile`: Creates a file in the current Surix project (expects fileParams: any parameter). -- `getFiles`: Queries files from the current Surix project. -- `getFileById`: Gets a single file by its Surix id. - -`requests.toast` contains: -- `show`: Displays a message on Surix toast (expects message: string parameter). - -`requests.menu` contains: -- `populate`: Submits the menu items to Surix. The menu is updated immidiately (expects items: any parameter). -`requests.events` contains: -- `menuItemClicked`: The event dispatched when a menu item is clicked. - -## Methods: -`Service` has one method `request` which takes 2 parameters, the first is the request type, and the second is optional payload. -## -## Populating Surix menu: + +Service contains all the methods grouped according to their operations + +[data](#data-methods) contains: +- [createEntity](#create-entity): Creates an entity in the current Surix project (expects entity: any parameter). +- [getEntities](#fetch-entities): Queries entities from the current Surix project. +- [getEntityById](#fetch-and-entity-by-its-surix-id): Gets a single entity by its Surix id. +- [addTagsToEntity](#add-tags-to-an-entity): Add tags to an existing entity. +- [removeTagsFromEntity](#remove-tags-from-an-entity): Removes tags from an entity. +- [getTags](#get-all-tags): Gets all the entity tags in the project. +- [updateTag](#updating-a-tag): Updates the specified tag in an entity. +- [project](#fetch-project): Fetches the current Surix project. +- [getAppData](#get-app-data): Fetches app data stored by the app in the current project +- [updateAppData](#update-app-data): Updates/adds app data to the current project. +- [createFile](#upload-a-file): Creates a file in the current Surix project (expects fileParams: any parameter). +- [getFiles](#fetch-all-files): Queries files from the current Surix project. +- [getFileById](#fetch-a-file-by-id): Gets a single file by its Surix id. + +[toast](#toast-methods) contains: +- [show](#show-a-toast-message): Displays a message on Surix toast (expects message: string parameter). + +[menu](#menu-methods) contains: +- [populate](#populating-surix-menu): Submits the menu items to Surix. The menu is updated immidiately (expects items: any parameter). + +[events](#events-methods) contains: +- [menuItemClicked](#menu-item-clicked): The event dispatched when a menu item is clicked. + +## Menu Methods +### Populating Surix menu: menu payload is an array of objects: ```javascript const menuItems = [ @@ -75,26 +75,27 @@ const menuItems = [ Populating the menu: ```javascript -service.request(requests.menu.populate, menuItems).then(res => { +service.menu.populate(menuItems).then(res => { // The menu was updated automatically }).catch(err => { // Handle the error }); ``` +## Toast Methods ### Show a Toast Message: ```javascript const toast = { message: 'Welcome to Surix', type: 'info' // could also be 'success', 'error' }; -service.request(requests.toast.show, toast).then(res => { +service.toast.show(toast).then(res => { // Toast was displayed successfully }).catch(err => { // Handle error }); ``` - +## Data Methods ### Fetch Entities: ```javascript // Fetch entities @@ -104,7 +105,7 @@ const query = { }, tags: ['people'] }; -service.request(requests.data.getEntities, query).then((entities) => { +service.data.getEntities(query).then((entities) => { // Do something with the response }).catch(err => { // Handle error @@ -114,7 +115,7 @@ service.request(requests.data.getEntities, query).then((entities) => { ### Fetch and entity by its Surix ID ```javascript const id = '1I7OBNmpPRYMS3s6WmoxeA'; -service.request(requests.data.getEntityById, id).then((entity) => { +service.data.getEntityById(id).then((entity) => { // Do something with the entity }).catch(err => { // Handle error @@ -132,7 +133,7 @@ const entity = { } }; -service.request(requests.data.createEntity, entity).then((createdEntity) => { +service.data.createEntity(entity).then((createdEntity) => { // Do something with the newly created entity }).catch(err => { // Handle the error @@ -146,7 +147,7 @@ const args = { entityId: '1I7OBNmpPRYMS3s6WmoxeA' }; -service.request(requests.data.addTagsToEntity, args).then((updatedEntity) => { +service.data.addTagsToEntity(args).then((updatedEntity) => { // Do something with the updated entity }).catch(err => { // Handle the error @@ -163,7 +164,7 @@ const args = { entityId: '1I7OBNmpPRYMS3s6WmoxeA' }; -service.request(requests.data.removeTagsFromEntity, args).then((updatedEntity) => { +service.data.removeTagsFromEntity(args).then((updatedEntity) => { // Do something with the updated entity }).catch(err => { // Handle the error @@ -172,7 +173,7 @@ service.request(requests.data.removeTagsFromEntity, args).then((updatedEntity) = **Note**: Tags that are not in the entity will be ignored. -### Updating a tag in an entity +### Updating a tag ```javascript const args = { tags: 'people', @@ -181,16 +182,16 @@ const args = { } }; -surix.request(requests.data.updateTag, args).then(updatedTag => { +surix.data.updateTag(args).then(updatedTag => { //Tag updated successfully }).catch(error) => { //Error }); ``` -### Get all tags in the project +### Get all tags ```javascript -service.request(requests.data.getTags).then((tags) => { +service.data.getTags().then((tags) => { // Do something with the tags }).catch((err) => { // handle error @@ -208,7 +209,7 @@ The response of the request is an array of tag objects: ### Fetch Project: ```javascript -service.request(requests.data.project).then(project => { +service.data.project().then(project => { // Do something with the fetched project }).catch(err => { // Handle error @@ -217,7 +218,7 @@ service.request(requests.data.project).then(project => { ### Get App Data: ```javascript -service.request(requests.data.getAppData).then(data => { +service.data.getAppData().then(data => { // do something with the data }).catch(err => { //handler error @@ -238,7 +239,7 @@ const update = { } } }; -service.request(requests.data.updateAppData, update).then(updatedData => { +service.data.updateAppData(update).then(updatedData => { // do something with updated data }).catch(err => { // handler error @@ -256,7 +257,7 @@ const fileParmas = { file, // The file itself (has to be of type File) } -service.request(requests.data.createFile, fileParams).then(fileDetails => { +service.data.createFile(fileParams).then(fileDetails => { // Do something with the file details }).catch(err => { // Handle error @@ -267,7 +268,7 @@ service.request(requests.data.createFile, fileParams).then(fileDetails => { ```javascript const fileId = '123'; -service.request(requests.data.getFileById, fileId).then(fileDetails => { +service.data.getFileById(fileId).then(fileDetails => { // Do something with the fileDetails // NOTE: fileDetails has field downloadUrl that contains a url // to the actual file @@ -279,24 +280,25 @@ service.request(requests.data.getFileById, fileId).then(fileDetails => { ### Fetch all files ```javascript -service.request(requests.data.getFiles).then(files => { +service.data.getFiles().then(files => { // DO something with the files, file is an array of fileDetails }).catch(err => { // Handle error }) ``` -## Events: +## Events Methods There are times where Surix sends information to the app without the app requesting. -### Menu Item Clicked +### Menu Item Clicked: -When one clicks on the menu populated by the app, Surix tells the app about the click using a `requests.events.menuItemClicked` event. +When one clicks on the menu populated by the app, Surix tells the app about the click using a `menuItemClicked` event. Listening to the menu click event: ```javascript let handler = (event) => { const msg = event.detail; + // msg.body contains the action value in your menu item switch(msg.body) { case 'settings': // The settings menu item was clicked @@ -305,5 +307,5 @@ let handler = (event) => { // The mpesa menu item was clicked } -service.on(requests.events.menuItemClicked, handler); +service.events.menuItemClicked(handler); ``` diff --git a/build/dist/index.js b/build/dist/index.js deleted file mode 100644 index 4074299..0000000 --- a/build/dist/index.js +++ /dev/null @@ -1,7 +0,0 @@ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); -var service_1 = require("./src/service"); -exports.Service = service_1.Service; -var requests_1 = require("./src/requests"); -exports.requests = requests_1.requests; -//# sourceMappingURL=index.js.map \ No newline at end of file diff --git a/build/dist/index.js.map b/build/dist/index.js.map deleted file mode 100644 index 9611d8a..0000000 --- a/build/dist/index.js.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.js","sourceRoot":"","sources":["../../index.ts"],"names":[],"mappings":";;AAAA,yCAAwC;AAGpC,kBAHK,iBAAO,CAGL;AAFX,2CAA0C;AAGtC,mBAHK,mBAAQ,CAGL"} \ No newline at end of file diff --git a/build/dist/src/requests.js b/build/dist/src/requests.js deleted file mode 100644 index f3f6b78..0000000 --- a/build/dist/src/requests.js +++ /dev/null @@ -1,30 +0,0 @@ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); -exports.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', - uploadFile: 'data.uploadFile', - }, - toast: { - show: 'toast.show', - }, - menu: { - populate: 'menu.populate' - }, - events: { - menuItemClicked: 'menu-item-clicked', - // TODO: this is for backwards compatibility - // it is deprecated and will be removed in a future update - menuClicked: 'menu-item-clicked' - } -}; -//# sourceMappingURL=requests.js.map \ No newline at end of file diff --git a/build/dist/src/requests.js.map b/build/dist/src/requests.js.map deleted file mode 100644 index 5a5ecfc..0000000 --- a/build/dist/src/requests.js.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"requests.js","sourceRoot":"","sources":["../../../src/requests.ts"],"names":[],"mappings":";;AAAa,QAAA,QAAQ,GAAG;IACpB,IAAI,EAAE;QACF,YAAY,EAAE,mBAAmB;QACjC,OAAO,EAAE,cAAc;QACvB,WAAW,EAAE,kBAAkB;QAC/B,aAAa,EAAE,oBAAoB;QACnC,eAAe,EAAE,sBAAsB;QACvC,oBAAoB,EAAE,2BAA2B;QACjD,OAAO,EAAE,cAAc;QACvB,SAAS,EAAE,gBAAgB;QAC3B,UAAU,EAAE,iBAAiB;QAC7B,aAAa,EAAE,oBAAoB;QACnC,UAAU,EAAE,iBAAiB;KAChC;IACD,KAAK,EAAE;QACH,IAAI,EAAE,YAAY;KACrB;IACD,IAAI,EAAE;QACF,QAAQ,EAAE,eAAe;KAC5B;IACD,MAAM,EAAE;QACJ,eAAe,EAAE,mBAAmB;QACpC,4CAA4C;QAC5C,0DAA0D;QAC1D,WAAW,EAAE,mBAAmB;KACnC;CACJ,CAAA"} \ No newline at end of file diff --git a/build/dist/src/service.js b/build/dist/src/service.js deleted file mode 100644 index 8961d19..0000000 --- a/build/dist/src/service.js +++ /dev/null @@ -1,106 +0,0 @@ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); -var Service = /** @class */ (function () { - /** - * Constructor - */ - function Service() { - this.prefix = '__surix__'; - this.rpcTracker = {}; - this.setUpService(); - } - /** - * Sends a request to Surix - * @param type Request type - * @param payload Request payload - * @returns Promise Returns a promise - */ - Service.prototype.request = function (type, payload) { - return this.rpc(type, payload); - }; - /** - * An event listener wrapper - * @param eventName A string representing the event name - * @param handler a function that handles event - */ - Service.prototype.on = function (eventName, handler) { - document.addEventListener("" + this.prefix + eventName, handler); - }; - /** - * Sends the specified message to Surix - * @param msg Message to send to Surix - */ - Service.prototype.sendMessage = function (msg) { - window.parent.postMessage(msg, '*'); - }; - /** - * Creates a promise then sends the message - * @param name Name of the request to send to Surix - * @param body - */ - Service.prototype.rpc = function (name, body) { - var _this = this; - var reqId = Math.random(); - return new Promise(function (resolve, reject) { - _this.rpcTracker[reqId] = { resolve: resolve, reject: reject }; - var message = { - name: name, - body: body, - type: 'rpcReq', - id: reqId - }; - _this.sendMessage(message); - }); - }; - /** - * This handles the rpcReq type responses from Surix - * @param msg Response from Surix - * @param handler Handles the response - */ - Service.prototype.handleRpcReq = function (msg, handler) { - if (msg.success) { - handler.rpcTracker[msg.id].resolve(msg.body); - } - else { - handler.rpcTracker[msg.id].reject(msg.body); - } - // Remove the promise from the handler because - // it has already been taken care of. - // delete handler.rpcTracker[msg.id]; - }; - /** - * Emits a custom event - * @param msg Message to be embedded to the custom event to be emitted - */ - Service.prototype.emit = function (msg) { - var event = new CustomEvent("" + this.prefix + msg.name, { detail: msg }); - document.dispatchEvent(event); - }; - /** - * Sets up Surix service - */ - Service.prototype.setUpService = function () { - var _this = this; - window.addEventListener('message', function (event) { - var msg = event.data; - switch (msg.type) { - case 'rpcRep': - _this.handleRpcReq(msg, _this); - break; - case 'event': - _this.emit(msg); - break; - } - }); - }; - Service.init = function () { - if (Service.instance == undefined) { - Service.instance = new Service(); - } - return Service.instance; - }; - Service.instance = undefined; - return Service; -}()); -exports.Service = Service; -//# sourceMappingURL=service.js.map \ No newline at end of file diff --git a/build/dist/src/service.js.map b/build/dist/src/service.js.map deleted file mode 100644 index 6360c24..0000000 --- a/build/dist/src/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ist/client-service.js index 6a11ce8..68e6020 100644 --- a/dist/client-service.js +++ b/dist/client-service.js @@ -91,7 +91,7 @@ return /******/ (function(modules) { // webpackBootstrap /******/ /******/ /******/ // Load entry module and return exports -/******/ return __webpack_require__(__webpack_require__.s = 0); +/******/ return __webpack_require__(__webpack_require__.s = 2); /******/ }) /************************************************************************/ /******/ ([ @@ -101,35 +101,29 @@ return /******/ (function(modules) { // webpackBootstrap "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); -var service_1 = __webpack_require__(1); -exports.Service = service_1.Service; -var requests_1 = __webpack_require__(2); -exports.requests = requests_1.requests; - - -/***/ }), -/* 1 */ -/***/ (function(module, exports, __webpack_require__) { - -"use strict"; - -Object.defineProperty(exports, "__esModule", { value: true }); -var Service = /** @class */ (function () { - /** - * Constructor - */ - function Service() { +var ServiceBase = /** @class */ (function () { + function ServiceBase() { this.prefix = '__surix__'; this.rpcTracker = {}; this.setUpService(); } + /** + * Sends a request to Surixs + * @param type Request type + * @param payload Request payload + */ + ServiceBase.prototype.internalRequest = function (type, payload) { + return this.rpc(type, payload); + }; /** * Sends a request to Surix + * ====== TO BE DEPRICATED IN FUTURE ======= * @param type Request type * @param payload Request payload * @returns Promise Returns a promise */ - Service.prototype.request = function (type, payload) { + ServiceBase.prototype.request = function (type, payload) { + console.warn("service.request method will be DEPRICATED in future. Please consider using service." + type + " instead."); return this.rpc(type, payload); }; /** @@ -137,14 +131,24 @@ var Service = /** @class */ (function () { * @param eventName A string representing the event name * @param handler a function that handles event */ - Service.prototype.on = function (eventName, handler) { + ServiceBase.prototype.internalOn = function (eventName, handler) { + document.addEventListener("" + this.prefix + eventName, handler); + }; + /** + * An event listener wrapper + * ======== TO BE DEPRICATED IN FUTURE ============ + * @param eventName A string representing the event name + * @param handler a function that handles event + */ + ServiceBase.prototype.on = function (eventName, handler) { + console.warn("service.on method will be DEPRICATED in future. Please consider using service.events." + eventName + " instead."); document.addEventListener("" + this.prefix + eventName, handler); }; /** * Sends the specified message to Surix * @param msg Message to send to Surix */ - Service.prototype.sendMessage = function (msg) { + ServiceBase.prototype.sendMessage = function (msg) { window.parent.postMessage(msg, '*'); }; /** @@ -152,7 +156,7 @@ var Service = /** @class */ (function () { * @param name Name of the request to send to Surix * @param body */ - Service.prototype.rpc = function (name, body) { + ServiceBase.prototype.rpc = function (name, body) { var _this = this; var reqId = Math.random(); return new Promise(function (resolve, reject) { @@ -171,7 +175,7 @@ var Service = /** @class */ (function () { * @param msg Response from Surix * @param handler Handles the response */ - Service.prototype.handleRpcReq = function (msg, handler) { + ServiceBase.prototype.handleRpcRep = function (msg, handler) { if (msg.success) { handler.rpcTracker[msg.id].resolve(msg.body); } @@ -180,26 +184,26 @@ var Service = /** @class */ (function () { } // Remove the promise from the handler because // it has already been taken care of. - // delete handler.rpcTracker[msg.id]; + delete handler.rpcTracker[msg.id]; }; /** * Emits a custom event * @param msg Message to be embedded to the custom event to be emitted */ - Service.prototype.emit = function (msg) { + ServiceBase.prototype.emit = function (msg) { var event = new CustomEvent("" + this.prefix + msg.name, { detail: msg }); document.dispatchEvent(event); }; /** * Sets up Surix service */ - Service.prototype.setUpService = function () { + ServiceBase.prototype.setUpService = function () { var _this = this; window.addEventListener('message', function (event) { var msg = event.data; switch (msg.type) { case 'rpcRep': - _this.handleRpcReq(msg, _this); + _this.handleRpcRep(msg, _this); break; case 'event': _this.emit(msg); @@ -207,20 +211,13 @@ var Service = /** @class */ (function () { } }); }; - Service.init = function () { - if (Service.instance == undefined) { - Service.instance = new Service(); - } - return Service.instance; - }; - Service.instance = undefined; - return Service; + return ServiceBase; }()); -exports.Service = Service; +exports.ServiceBase = ServiceBase; /***/ }), -/* 2 */ +/* 1 */ /***/ (function(module, exports, __webpack_require__) { "use strict"; @@ -257,6 +254,482 @@ exports.requests = { }; +/***/ }), +/* 2 */ +/***/ (function(module, exports, __webpack_require__) { + +"use strict"; + +Object.defineProperty(exports, "__esModule", { value: true }); +var service_1 = __webpack_require__(3); +exports.Service = service_1.Service; +var requests_1 = __webpack_require__(1); +exports.requests = requests_1.requests; + + +/***/ }), +/* 3 */ +/***/ (function(module, exports, __webpack_require__) { + +"use strict"; + +var __extends = (this && this.__extends) || (function () { + var extendStatics = function (d, b) { + extendStatics = Object.setPrototypeOf || + ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || + function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; + return extendStatics(d, b); + } + return function (d, b) { + extendStatics(d, b); + function __() { this.constructor = d; } + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); + }; +})(); +Object.defineProperty(exports, "__esModule", { value: true }); +var service_base_1 = __webpack_require__(0); +var data_1 = __webpack_require__(4); +var toast_1 = __webpack_require__(5); +var menu_1 = __webpack_require__(6); +var events_1 = __webpack_require__(7); +var Service = /** @class */ (function (_super) { + __extends(Service, _super); + /** + * Constructor + */ + function Service() { + var _this = _super.call(this) || this; + _this._data = new data_1.Data(); + _this._toast = new toast_1.Toast(); + _this._menu = new menu_1.Menu(); + _this._events = new events_1.Events(); + return _this; + } + Object.defineProperty(Service.prototype, "data", { + /** + * Returns all data methods + */ + get: function () { + return this._data; + }, + enumerable: true, + configurable: true + }); + Object.defineProperty(Service.prototype, "toast", { + /** + * Returns all toast methods + */ + get: function () { + return this._toast; + }, + enumerable: true, + configurable: true + }); + Object.defineProperty(Service.prototype, "menu", { + /** + * Returns all menu methods + */ + get: function () { + return this._menu; + }, + enumerable: true, + configurable: true + }); + Object.defineProperty(Service.prototype, "events", { + /** + * Returns all methods associated with events. + */ + get: function () { + return this._events; + }, + enumerable: true, + configurable: true + }); + /** + * Provides Surix singleton + */ + Service.init = function () { + if (Service.instance == undefined) { + Service.instance = new Service(); + } + return Service.instance; + }; + Service.instance = undefined; + return Service; +}(service_base_1.ServiceBase)); +exports.Service = Service; + + +/***/ }), +/* 4 */ +/***/ (function(module, exports, __webpack_require__) { + +"use strict"; + +var __extends = (this && this.__extends) || (function () { + var extendStatics = function (d, b) { + extendStatics = Object.setPrototypeOf || + ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || + function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; + return extendStatics(d, b); + } + return function (d, b) { + extendStatics(d, b); + function __() { this.constructor = d; } + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); + }; +})(); +var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { + return new (P || (P = Promise))(function (resolve, reject) { + function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } + function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } + function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); } + step((generator = generator.apply(thisArg, _arguments || [])).next()); + }); +}; +var __generator = (this && this.__generator) || function (thisArg, body) { + var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; + return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; + function verb(n) { return function (v) { return step([n, v]); }; } + function step(op) { + if (f) throw new TypeError("Generator is already executing."); + while (_) try { + if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t; + if (y = 0, t) op = [op[0] & 2, t.value]; + switch (op[0]) { + case 0: case 1: t = op; break; + case 4: _.label++; return { value: op[1], done: false }; + case 5: _.label++; y = op[1]; op = [0]; continue; + case 7: op = _.ops.pop(); _.trys.pop(); continue; + default: + if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } + if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } + if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } + if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } + if (t[2]) _.ops.pop(); + _.trys.pop(); continue; + } + op = body.call(thisArg, _); + } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } + if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; + } +}; +Object.defineProperty(exports, "__esModule", { value: true }); +var requests_1 = __webpack_require__(1); +var service_base_1 = __webpack_require__(0); +var Data = /** @class */ (function (_super) { + __extends(Data, _super); + //public _service: Service; + function Data() { + return _super.call(this) || this; + //this._service = Service.init(); + } + /** + * Saves an entity in Surix + * @param entity EntityData entity to be saved + * @returns Promise + */ + Data.prototype.createEntity = function (entity) { + return __awaiter(this, void 0, void 0, function () { + return __generator(this, function (_a) { + switch (_a.label) { + case 0: return [4 /*yield*/, this.internalRequest(requests_1.requests.data.createEntity, entity)]; + case 1: return [2 /*return*/, _a.sent()]; + } + }); + }); + }; + /** + * Returns the current project + * @returns Promise + */ + Data.prototype.project = function () { + return __awaiter(this, void 0, void 0, function () { + return __generator(this, function (_a) { + switch (_a.label) { + case 0: return [4 /*yield*/, this.internalRequest(requests_1.requests.data.project)]; + case 1: return [2 /*return*/, _a.sent()]; + } + }); + }); + }; + /** + * Returns all the entities present + * @param query (Optional) query + * @returns Promise + */ + Data.prototype.getEntities = function (query) { + return __awaiter(this, void 0, void 0, function () { + return __generator(this, function (_a) { + switch (_a.label) { + case 0: return [4 /*yield*/, this.internalRequest(requests_1.requests.data.getEntities, query)]; + case 1: return [2 /*return*/, _a.sent()]; + } + }); + }); + }; + /** + * Returns an entity identified by the id provided + * @param id Surix Id + * @returns Promise + */ + Data.prototype.getEntityById = function (id) { + return __awaiter(this, void 0, void 0, function () { + return __generator(this, function (_a) { + switch (_a.label) { + case 0: return [4 /*yield*/, this.internalRequest(requests_1.requests.data.getEntityById, id)]; + case 1: return [2 /*return*/, _a.sent()]; + } + }); + }); + }; + /** + * Adds tags to an existing entity + * @param params Parameters to add tags + * @returns Promise + */ + Data.prototype.addTagsToEntity = function (params) { + return __awaiter(this, void 0, void 0, function () { + return __generator(this, function (_a) { + switch (_a.label) { + case 0: return [4 /*yield*/, this.internalRequest(requests_1.requests.data.addTagsToEntity, params)]; + case 1: return [2 /*return*/, _a.sent()]; + } + }); + }); + }; + /** + * Removes tags from an entity + * @param params TagsParams tag parameters + */ + Data.prototype.removeTagsFromEntity = function (params) { + return __awaiter(this, void 0, void 0, function () { + return __generator(this, function (_a) { + switch (_a.label) { + case 0: return [4 /*yield*/, this.internalRequest(requests_1.requests.data.removeTagsFromEntity, params)]; + case 1: return [2 /*return*/, _a.sent()]; + } + }); + }); + }; + /** + * Updates tags on an existing entity + * @param params Update params + */ + Data.prototype.updateTag = function (params) { + return __awaiter(this, void 0, void 0, function () { + return __generator(this, function (_a) { + switch (_a.label) { + case 0: return [4 /*yield*/, this.internalRequest(requests_1.requests.data.updateTag, params)]; + case 1: return [2 /*return*/, _a.sent()]; + } + }); + }); + }; + /** + * Returns all the tags available + * @returns Promise + */ + Data.prototype.getTags = function () { + return __awaiter(this, void 0, void 0, function () { + return __generator(this, function (_a) { + switch (_a.label) { + case 0: return [4 /*yield*/, this.internalRequest(requests_1.requests.data.getTags)]; + case 1: return [2 /*return*/, _a.sent()]; + } + }); + }); + }; + Data.prototype.getAppData = function () { + return __awaiter(this, void 0, void 0, function () { + return __generator(this, function (_a) { + switch (_a.label) { + case 0: return [4 /*yield*/, this.internalRequest(requests_1.requests.data.getAppData)]; + case 1: return [2 /*return*/, _a.sent()]; + } + }); + }); + }; + Data.prototype.updateAppData = function (appData) { + return __awaiter(this, void 0, void 0, function () { + return __generator(this, function (_a) { + switch (_a.label) { + case 0: return [4 /*yield*/, this.internalRequest(requests_1.requests.data.updateAppData, appData)]; + case 1: return [2 /*return*/, _a.sent()]; + } + }); + }); + }; + /** + * Creates a file on Surix linked to the current project. + * @param file FileMessage message details + * @returns Promise + */ + Data.prototype.createFile = function (file) { + return __awaiter(this, void 0, void 0, function () { + return __generator(this, function (_a) { + switch (_a.label) { + case 0: return [4 /*yield*/, this.internalRequest(requests_1.requests.data.createFile, file)]; + case 1: return [2 /*return*/, _a.sent()]; + } + }); + }); + }; + /** + * Gets a file associated with the id provided + * @param id string Surix Id + * @returns Promise + */ + Data.prototype.getFileById = function (id) { + return __awaiter(this, void 0, void 0, function () { + return __generator(this, function (_a) { + switch (_a.label) { + case 0: return [4 /*yield*/, this.internalRequest(requests_1.requests.data.getFileById, id)]; + case 1: return [2 /*return*/, _a.sent()]; + } + }); + }); + }; + /** + * Returns all files + * @returns Promise + */ + Data.prototype.getFiles = function () { + return __awaiter(this, void 0, void 0, function () { + return __generator(this, function (_a) { + switch (_a.label) { + case 0: return [4 /*yield*/, this.internalRequest(requests_1.requests.data.getFiles)]; + case 1: return [2 /*return*/, _a.sent()]; + } + }); + }); + }; + return Data; +}(service_base_1.ServiceBase)); +exports.Data = Data; + + +/***/ }), +/* 5 */ +/***/ (function(module, exports, __webpack_require__) { + +"use strict"; + +var __extends = (this && this.__extends) || (function () { + var extendStatics = function (d, b) { + extendStatics = Object.setPrototypeOf || + ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || + function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; + return extendStatics(d, b); + } + return function (d, b) { + extendStatics(d, b); + function __() { this.constructor = d; } + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); + }; +})(); +Object.defineProperty(exports, "__esModule", { value: true }); +var requests_1 = __webpack_require__(1); +var service_base_1 = __webpack_require__(0); +var Toast = /** @class */ (function (_super) { + __extends(Toast, _super); + // private _service: Service; + function Toast() { + return _super.call(this) || this; + //this._service = Service.init(); + } + /** + * Displays the message provided on toast on Surix + * @param message ToastMessage message to show on the toast + */ + Toast.prototype.show = function (message) { + return this.internalRequest(requests_1.requests.toast.show, message); + }; + return Toast; +}(service_base_1.ServiceBase)); +exports.Toast = Toast; + + +/***/ }), +/* 6 */ +/***/ (function(module, exports, __webpack_require__) { + +"use strict"; + +var __extends = (this && this.__extends) || (function () { + var extendStatics = function (d, b) { + extendStatics = Object.setPrototypeOf || + ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || + function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; + return extendStatics(d, b); + } + return function (d, b) { + extendStatics(d, b); + function __() { this.constructor = d; } + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); + }; +})(); +Object.defineProperty(exports, "__esModule", { value: true }); +var requests_1 = __webpack_require__(1); +var service_base_1 = __webpack_require__(0); +var Menu = /** @class */ (function (_super) { + __extends(Menu, _super); + //public _service: Service; + function Menu() { + return _super.call(this) || this; + //this._service = Service.init(); + } + /** + * Populates Surix app menu with the provided items + * @param menu MenuItem[] menu items + */ + Menu.prototype.populate = function (menu) { + return this.internalRequest(requests_1.requests.menu.populate, menu); + }; + return Menu; +}(service_base_1.ServiceBase)); +exports.Menu = Menu; + + +/***/ }), +/* 7 */ +/***/ (function(module, exports, __webpack_require__) { + +"use strict"; + +var __extends = (this && this.__extends) || (function () { + var extendStatics = function (d, b) { + extendStatics = Object.setPrototypeOf || + ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || + function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; + return extendStatics(d, b); + } + return function (d, b) { + extendStatics(d, b); + function __() { this.constructor = d; } + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); + }; +})(); +Object.defineProperty(exports, "__esModule", { value: true }); +var service_base_1 = __webpack_require__(0); +var __1 = __webpack_require__(2); +var Events = /** @class */ (function (_super) { + __extends(Events, _super); + function Events() { + return _super !== null && _super.apply(this, arguments) || this; + } + /** + * Registers an event onto the handler provided. + * @param handler Function to handle events + */ + Events.prototype.menuItemClicked = function (handler) { + this.internalOn(__1.requests.events.menuItemClicked, handler); + }; + return Events; +}(service_base_1.ServiceBase)); +exports.Events = Events; + + /***/ }) /******/ ]); }); diff --git a/dist/client-service.js.map b/dist/client-service.js.map index 2fe048e..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/./index.ts","webpack://Surix/./src/service.ts","webpack://Surix/./src/requests.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;AACvD,yCAAiC,eAAe;AAChD;AACA;AACA;;AAEA;AACA,8DAAsD,+DAA+D;;AAErH;AACA;;;AAGA;AACA;;;;;;;;;;AClFA,uCAAwC;AAGpC,kBAHK,iBAAO,CAGL;AAFX,wCAA0C;AAGtC,mBAHK,mBAAQ,CAGL;;;;;;;;;;ACHZ;IAKI;;OAEG;IACH;QALQ,WAAM,GAAW,WAAW,CAAC;QAMjC,IAAI,CAAC,UAAU,GAAG,EAAE,CAAC;QACrB,IAAI,CAAC,YAAY,EAAE,CAAC;IACxB,CAAC;IACD;;;;;OAKG;IACI,yBAAO,GAAd,UAAe,IAAY,EAAE,OAAa;QACtC,OAAO,IAAI,CAAC,GAAG,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC;IACnC,CAAC;IAED;;;;OAIG;IACI,oBAAE,GAAT,UAA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5B;IACD,MAAM,EAAE;QACJ,eAAe,EAAE,mBAAmB;QACpC,4CAA4C;QAC5C,0DAA0D;QAC1D,WAAW,EAAE,mBAAmB;KACnC;CACJ","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 = 0);\n","import { Service } from './src/service';\nimport { requests } from './src/requests';\nexport {\n Service,\n requests\n}","\nexport class Service {\n private rpcTracker: any;\n private static instance?: Service = undefined;\n private prefix: string = '__surix__';\n\n /**\n * Constructor\n */\n private constructor() {\n this.rpcTracker = {};\n this.setUpService();\n }\n /**\n * Sends a request to Surix\n * @param type Request type\n * @param payload Request payload \n * @returns Promise Returns a promise\n */\n public request(type: string, payload?: any) {\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 on(eventName: string, handler: any) {\n document.addEventListener(`${this.prefix}${eventName}`, handler);\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 private 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\n public static init() {\n if(Service.instance == undefined){\n Service.instance = new Service();\n }\n return Service.instance;\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}"],"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;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;AACvD,yCAAiC,eAAe;AAChD;AACA;AACA;;AAEA;AACA,8DAAsD,+DAA+D;;AAErH;AACA;;;AAGA;AACA;;;;;;;;;;AClFA;IAII;QAFQ,WAAM,GAAW,WAAW,CAAC;QAGjC,IAAI,CAAC,UAAU,GAAG,EAAE,CAAC;QACrB,IAAI,CAAC,YAAY,EAAE,CAAC;IACxB,CAAC;IAED;;;;OAIG;IACO,qCAAe,GAAzB,UAA0B,IAAY,EAAE,OAAa;QACjD,OAAO,IAAI,CAAC,GAAG,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC;IACnC,CAAC;IAED;;;;;;OAMG;IACI,6BAAO,GAAd,UAAe,IAAY,EAAE,OAAa;QACtC,OAAO,CAAC,IAAI,CAAC,wFAAsF,IAAI,cAAW,CAAC,CAAC;QACpH,OAAO,IAAI,CAAC,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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 0f36589..12e2bd2 100644 --- a/dist/client-service.min.js +++ b/dist/client-service.min.js @@ -1 +1 @@ -!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define("Surix",[],t):"object"==typeof exports?exports.Surix=t():e.Surix=t()}(window,function(){return function(e){var t={};function n(r){if(t[r])return t[r].exports;var o=t[r]={i:r,l:!1,exports:{}};return e[r].call(o.exports,o,o.exports,n),o.l=!0,o.exports}return n.m=e,n.c=t,n.d=function(e,t,r){n.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:r})},n.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},n.t=function(e,t){if(1&t&&(e=n(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var r=Object.create(null);if(n.r(r),Object.defineProperty(r,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var o in e)n.d(r,o,function(t){return e[t]}.bind(null,o));return r},n.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return n.d(t,"a",t),t},n.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},n.p="",n(n.s=0)}([function(e,t,n){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var r=n(1);t.Service=r.Service;var o=n(2);t.requests=o.requests},function(e,t,n){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var r=function(){function e(){this.prefix="__surix__",this.rpcTracker={},this.setUpService()}return e.prototype.request=function(e,t){return this.rpc(e,t)},e.prototype.on=function(e,t){document.addEventListener(""+this.prefix+e,t)},e.prototype.sendMessage=function(e){window.parent.postMessage(e,"*")},e.prototype.rpc=function(e,t){var n=this,r=Math.random();return new Promise(function(o,i){n.rpcTracker[r]={resolve:o,reject:i};var a={name:e,body:t,type:"rpcReq",id:r};n.sendMessage(a)})},e.prototype.handleRpcReq=function(e,t){e.success?t.rpcTracker[e.id].resolve(e.body):t.rpcTracker[e.id].reject(e.body)},e.prototype.emit=function(e){var t=new CustomEvent(""+this.prefix+e.name,{detail:e});document.dispatchEvent(t)},e.prototype.setUpService=function(){var e=this;window.addEventListener("message",function(t){var n=t.data;switch(n.type){case"rpcRep":e.handleRpcReq(n,e);break;case"event":e.emit(n)}})},e.init=function(){return void 0==e.instance&&(e.instance=new e),e.instance},e.instance=void 0,e}();t.Service=r},function(e,t,n){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.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"}}}])}); \ No newline at end of file +!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.handleRpcRep=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.handleRpcRep(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] + */ + createEntity(entity: EntityData): Promise; + /** + * Returns the current project + * @returns Promise + */ + project(): Promise; + /** + * Returns all the entities present + * @param query (Optional) query + * @returns Promise + */ + getEntities(query?: QueryParams): Promise; + /** + * Returns an entity identified by the id provided + * @param id Surix Id + * @returns Promise + */ + getEntityById(id: string): Promise; + /** + * Adds tags to an existing entity + * @param params Parameters to add tags + * @returns Promise + */ + addTagsToEntity(params: TagsParams): Promise; + /** + * Removes tags from an entity + * @param params TagsParams tag parameters + */ + removeTagsFromEntity(params: TagsParams): Promise; + /** + * Updates tags on an existing entity + * @param params Update params + */ + updateTag(params: TagUpdateParams): Promise; + /** + * Returns all the tags available + * @returns Promise + */ + getTags(): Promise; + getAppData(): Promise; + updateAppData(appData: AppData): Promise; + /** + * Creates a file on Surix linked to the current project. + * @param file FileMessage message details + * @returns Promise + */ + createFile(file: FileParams): Promise; + /** + * Gets a file associated with the id provided + * @param id string Surix Id + * @returns Promise + */ + getFileById(id: string): Promise; + /** + * Returns all files + * @returns Promise + */ + getFiles(): Promise; +} diff --git a/dist/src/functions/events.d.ts b/dist/src/functions/events.d.ts new file mode 100644 index 0000000..9b78bbb --- /dev/null +++ b/dist/src/functions/events.d.ts @@ -0,0 +1,8 @@ +import { ServiceBase } from "../service-base"; +export declare class Events extends ServiceBase { + /** + * Registers an event onto the handler provided. + * @param handler Function to handle events + */ + menuItemClicked(handler: (event: any) => any): void; +} diff --git a/dist/src/functions/menu.d.ts b/dist/src/functions/menu.d.ts new file mode 100644 index 0000000..cfc931d --- /dev/null +++ b/dist/src/functions/menu.d.ts @@ -0,0 +1,10 @@ +import { MenuItem } from '../types'; +import { ServiceBase } from '../service-base'; +export declare class Menu extends ServiceBase { + constructor(); + /** + * Populates Surix app menu with the provided items + * @param menu MenuItem[] menu items + */ + populate(menu: MenuItem[]): Promise; +} diff --git a/dist/src/functions/toast.d.ts b/dist/src/functions/toast.d.ts new file mode 100644 index 0000000..3d1f0ad --- /dev/null +++ b/dist/src/functions/toast.d.ts @@ -0,0 +1,10 @@ +import { ToastParams, IToast } from '../types'; +import { ServiceBase } from '../service-base'; +export declare class Toast extends ServiceBase implements IToast { + constructor(); + /** + * Displays the message provided on toast on Surix + * @param message ToastMessage message to show on the toast + */ + show(message: ToastParams): Promise; +} diff --git a/build/dist/src/requests.d.ts b/dist/src/requests.d.ts similarity index 100% rename from build/dist/src/requests.d.ts rename to dist/src/requests.d.ts diff --git a/build/dist/src/service.d.ts b/dist/src/service-base.d.ts similarity index 60% rename from build/dist/src/service.d.ts rename to dist/src/service-base.d.ts index 7a95d98..8b673f9 100644 --- a/build/dist/src/service.d.ts +++ b/dist/src/service-base.d.ts @@ -1,20 +1,30 @@ -export declare class Service { +export declare class ServiceBase { private rpcTracker; - private static instance?; private prefix; + protected constructor(); /** - * Constructor + * Sends a request to Surixs + * @param type Request type + * @param payload Request payload */ - private constructor(); + protected internalRequest(type: string, payload?: any): Promise; /** * Sends a request to Surix + * ====== TO BE DEPRICATED IN FUTURE ======= * @param type Request type * @param payload Request payload * @returns Promise Returns a promise */ - request(type: string, payload?: any): Promise<{}>; + request(type: string, payload?: any): Promise; + /** + * An event listener wrapper + * @param eventName A string representing the event name + * @param handler a function that handles event + */ + internalOn(eventName: string, handler: any): void; /** * An event listener wrapper + * ======== TO BE DEPRICATED IN FUTURE ============ * @param eventName A string representing the event name * @param handler a function that handles event */ @@ -35,7 +45,7 @@ export declare class Service { * @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 @@ -44,6 +54,5 @@ export declare class Service { /** * Sets up Surix service */ - private setUpService; - static init(): Service; + protected setUpService(): void; } diff --git a/dist/src/service.d.ts b/dist/src/service.d.ts new file mode 100644 index 0000000..227915f --- /dev/null +++ b/dist/src/service.d.ts @@ -0,0 +1,36 @@ +import { ServiceBase } from './service-base'; +import { Data } from './functions/data'; +import { Toast } from './functions/toast'; +import { Menu } from './functions/menu'; +import { Events } from './functions/events'; +export declare class Service extends ServiceBase { + private _data; + private _toast; + private _menu; + private _events; + /** + * Returns all data methods + */ + readonly data: Data; + /** + * Returns all toast methods + */ + readonly toast: Toast; + /** + * Returns all menu methods + */ + readonly menu: Menu; + /** + * Returns all methods associated with events. + */ + readonly events: Events; + /** + * Constructor + */ + private constructor(); + /** + * Provides Surix singleton + */ + static init(): Service; + private static instance?; +} diff --git a/dist/src/types.d.ts b/dist/src/types.d.ts new file mode 100644 index 0000000..a936c0b --- /dev/null +++ b/dist/src/types.d.ts @@ -0,0 +1,144 @@ +export interface FieldPair { + type: 'boolean' | 'text' | 'phone' | 'number' | 'datetime' | 'object' | 'file' | 'list'; + value: boolean | string | number | UnitField | EntityListValueData | EntityFileValueData; +} + +export interface SimpleFieldPair { + type: 'boolean' | 'text' | 'phone' | 'number' | 'datetime'; + value: boolean | string | number; +} + +export interface AppDataField { + [fieldName: string]: SimpleFieldPair; +} +export interface EntityFileValueData { + ref: string +} + +export type EntityListValueData = FieldPair[]; + +export interface UnitField extends FieldPair { + label: string; +} + +export interface BasicFieldValueData { + [fieldName: string]: UnitField | BasicFieldValueData; +} + +export interface EntityData { + data: UnitField | BasicFieldValueData; + tags?: string[] +} + +export interface AppData { + data: AppDataField; +} + +export interface PersistedAppData extends AppData, HasTimestamps, HasId {} +export interface PersistedEntityData extends HasId, HasTimestamps, EntityData {} + +export interface ToastParams { + message: string; + type: 'error' | 'success' | 'info'; +} + +export interface MenuItem { + title: string; + action: string; + icon: string; + 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; + mimeType: string; + file: File; + tags: string[]; +} + +export interface TagsParams { + tags: string[]; + entityId: string; +} + +export interface Tag { + name: string; +} + +export interface TagUpdateParams { + tags: string; + update: Tag +} + +interface CreatedBy extends HasId { + type: string; +} + +export interface FileDetails extends HasTimestamps, HasId { + addedBy: string; + addedAt: Date; + status: string; + tags: string[]; + uploadUrl: string; + mimeType: string; + size: number; + name: string; + filename: string; + public: boolean; + createdBy: CreatedBy; + downloadUrl: string; +} + +export interface Project extends HasId, HasTimestamps { + name: string; + createdBy: string; + users: Array<{ _id: string, role: string }>; + apps: Array<{ _id: string, addedBy: string, addedAt: Date}>; +} + +interface HasId { + _id: string; +} + +interface HasTimestamps { + createdAt: Date; + updatedAt: Date; +} + +export interface IData { + createEntity(entity: EntityData): Promise; + project(): Promise; + getEntities(query?: QueryParams): Promise; + getEntityById(id: string): Promise; + addTagsToEntity(params: TagsParams): Promise; + removeTagsFromEntity(params: TagsParams): Promise; + updateTag(params: TagUpdateParams): Promise; + getTags(): Promise; + getAppData(): Promise; + updateAppData(data: AppData): Promise; + createFile(file: FileParams): Promise; + getFileById(id: string): Promise; + getFiles(): Promise; +} +export interface IToast { + show(message: ToastParams): Promise; +} +export interface IMenu { + populate(menu: MenuItem[]): Promise +} \ No newline at end of file diff --git a/index.ts b/index.ts index 2c4aa20..e6b1015 100644 --- a/index.ts +++ b/index.ts @@ -1,5 +1,6 @@ import { Service } from './src/service'; import { requests } from './src/requests'; +import { PersistedEntityData } from './src/types'; export { Service, requests diff --git a/package.json b/package.json index 73d667b..3103e42 100644 --- a/package.json +++ b/package.json @@ -16,10 +16,9 @@ "webpack-cli": "^3.1.0" }, "scripts": { - "local:build": "yarn clean && node_modules/.bin/webpack --output-path $PWD/local/dist --mode development", - "build": "yarn clean && node_modules/.bin/webpack --mode production", + "build": "yarn clean && node_modules/.bin/webpack --mode production && cp $PWD/src/types.d.ts dist/src", "release": "bash scripts/release.sh", - "clean": "rm -rf local dist", + "clean": "rm -rf local dist build", "test": "jest" }, "repository": { diff --git a/src/functions/data.ts b/src/functions/data.ts new file mode 100644 index 0000000..9aeb52c --- /dev/null +++ b/src/functions/data.ts @@ -0,0 +1,126 @@ +import { + PersistedEntityData, + TagUpdateParams, + FileDetails, + FileParams, + TagsParams, + EntityData, + Project, + AppData, + Tag, + IData, + PersistedAppData, + QueryParams +} from "../types"; +import { requests } from "../requests"; +import { ServiceBase } from "../service-base"; + +export class Data extends ServiceBase implements IData{ + //public _service: Service; + + public constructor() { + super(); + //this._service = Service.init(); + } + + /** + * Saves an entity in Surix + * @param entity EntityData entity to be saved + * @returns Promise + */ + public async createEntity(entity: EntityData): Promise { + return await this.internalRequest(requests.data.createEntity, entity); + } + + /** + * Returns the current project + * @returns Promise + */ + public async project(): Promise { + return await this.internalRequest(requests.data.project); + } + + /** + * Returns all the entities present + * @param query (Optional) query + * @returns Promise + */ + public async getEntities(query?: QueryParams): Promise { + return await this.internalRequest(requests.data.getEntities, query); + } + + /** + * Returns an entity identified by the id provided + * @param id Surix Id + * @returns Promise + */ + public async getEntityById(id: string): Promise { + return await this.internalRequest(requests.data.getEntityById, id); + } + + /** + * Adds tags to an existing entity + * @param params Parameters to add tags + * @returns Promise + */ + public async addTagsToEntity(params: TagsParams): Promise { + return await this.internalRequest(requests.data.addTagsToEntity, params); + } + + /** + * Removes tags from an entity + * @param params TagsParams tag parameters + */ + public async removeTagsFromEntity(params: TagsParams): Promise { + return await this.internalRequest(requests.data.removeTagsFromEntity, params); + } + + /** + * Updates tags on an existing entity + * @param params Update params + */ + public async updateTag(params: TagUpdateParams): Promise { + return await this.internalRequest(requests.data.updateTag, params); + } + + /** + * Returns all the tags available + * @returns Promise + */ + public async getTags(): Promise { + return await this.internalRequest(requests.data.getTags); + } + + public async getAppData(): Promise { + return await this.internalRequest(requests.data.getAppData); + } + public async updateAppData(appData: AppData): Promise { + return await this.internalRequest(requests.data.updateAppData, appData); + } + + /** + * Creates a file on Surix linked to the current project. + * @param file FileMessage message details + * @returns Promise + */ + public async createFile(file: FileParams): Promise { + return await this.internalRequest(requests.data.createFile, file); + } + + /** + * Gets a file associated with the id provided + * @param id string Surix Id + * @returns Promise + */ + public async getFileById(id: string): Promise { + return await this.internalRequest(requests.data.getFileById, id); + } + + /** + * Returns all files + * @returns Promise + */ + public async getFiles(): Promise{ + return await this.internalRequest(requests.data.getFiles); + } +} \ No newline at end of file diff --git a/src/functions/events.ts b/src/functions/events.ts new file mode 100644 index 0000000..b84d14d --- /dev/null +++ b/src/functions/events.ts @@ -0,0 +1,13 @@ +import { ServiceBase } from "../service-base"; +import { requests } from "../.."; + +export class Events extends ServiceBase { + + /** + * Registers an event onto the handler provided. + * @param handler Function to handle events + */ + public menuItemClicked(handler: (event: any) => any) { + this.internalOn(requests.events.menuItemClicked, handler); + } +} \ No newline at end of file diff --git a/src/functions/menu.ts b/src/functions/menu.ts new file mode 100644 index 0000000..79a76ad --- /dev/null +++ b/src/functions/menu.ts @@ -0,0 +1,20 @@ +import { requests } from '../requests'; +import { MenuItem } from '../types'; +import { ServiceBase } from '../service-base'; + +export class Menu extends ServiceBase{ + //public _service: Service; + + public constructor() { + super(); + //this._service = Service.init(); + } + + /** + * Populates Surix app menu with the provided items + * @param menu MenuItem[] menu items + */ + public populate(menu: MenuItem[]): Promise { + return this.internalRequest(requests.menu.populate, menu); + } +} \ No newline at end of file diff --git a/src/functions/toast.ts b/src/functions/toast.ts new file mode 100644 index 0000000..655effc --- /dev/null +++ b/src/functions/toast.ts @@ -0,0 +1,20 @@ +import { ToastParams, IToast } from '../types'; +import { requests } from '../requests'; +import { ServiceBase } from '../service-base'; + +export class Toast extends ServiceBase implements IToast { + // private _service: Service; + + public constructor() { + super(); + //this._service = Service.init(); + } + + /** + * Displays the message provided on toast on Surix + * @param message ToastMessage message to show on the toast + */ + public show(message: ToastParams): Promise { + return this.internalRequest(requests.toast.show, message); + } +} \ No newline at end of file diff --git a/src/service-base.ts b/src/service-base.ts new file mode 100644 index 0000000..84e1977 --- /dev/null +++ b/src/service-base.ts @@ -0,0 +1,115 @@ +export class ServiceBase { + private rpcTracker: any; + private prefix: string = '__surix__'; + + protected constructor() { + this.rpcTracker = {}; + this.setUpService(); + } + + /** + * Sends a request to Surixs + * @param type Request type + * @param payload Request payload + */ + protected internalRequest(type: string, payload?: any): Promise { + return this.rpc(type, payload); + } + + /** + * Sends a request to Surix + * ====== TO BE DEPRICATED IN FUTURE ======= + * @param type Request type + * @param payload Request payload + * @returns Promise Returns a promise + */ + public request(type: string, payload?: any): Promise { + console.warn(`service.request method will be DEPRICATED in future. Please consider using service.${type} instead.`); + return this.rpc(type, payload); + } + + /** + * An event listener wrapper + * @param eventName A string representing the event name + * @param handler a function that handles event + */ + public internalOn(eventName: string, handler: any) { + document.addEventListener(`${this.prefix}${eventName}`, handler); + } + + /** + * An event listener wrapper + * ======== TO BE DEPRICATED IN FUTURE ============ + * @param eventName A string representing the event name + * @param handler a function that handles event + */ + public on(eventName: string, handler: any) { + console.warn(`service.on method will be DEPRICATED in future. Please consider using service.events.${eventName} instead.`); + document.addEventListener(`${this.prefix}${eventName}`, handler); + } + + /** + * Sends the specified message to Surix + * @param msg Message to send to Surix + */ + private sendMessage(msg: any) { + window.parent.postMessage(msg, '*'); + } + /** + * Creates a promise then sends the message + * @param name Name of the request to send to Surix + * @param body + */ + private rpc(name: string, body: any) { + const reqId = Math.random(); + return new Promise((resolve, reject) => { + this.rpcTracker[reqId] = { resolve, reject }; + const message = { + name, + body, + type: 'rpcReq', + id: reqId + } + this.sendMessage(message); + }); + } + /** + * This handles the rpcReq type responses from Surix + * @param msg Response from Surix + * @param handler Handles the response + */ + private handleRpcRep(msg: any, handler: any) { + if(msg.success) { + handler.rpcTracker[msg.id].resolve(msg.body); + } else { + handler.rpcTracker[msg.id].reject(msg.body); + } + // Remove the promise from the handler because + // it has already been taken care of. + delete handler.rpcTracker[msg.id]; + } + /** + * Emits a custom event + * @param msg Message to be embedded to the custom event to be emitted + */ + private emit(msg: any) { + const event: Event = new CustomEvent(`${this.prefix}${msg.name}`, {detail: msg}); + document.dispatchEvent(event); + } + /** + * Sets up Surix service + */ + protected setUpService() { + window.addEventListener('message', event => { + const msg: any = event.data; + switch(msg.type) { + case 'rpcRep': + this.handleRpcRep(msg, this); + break; + case 'event': + this.emit(msg); + break; + } + }); + } +} \ No newline at end of file diff --git a/src/service.ts b/src/service.ts index 3879642..a870188 100644 --- a/src/service.ts +++ b/src/service.ts @@ -1,103 +1,60 @@ +import { ServiceBase } from './service-base'; +import { Data } from './functions/data'; +import { Toast } from './functions/toast'; +import { Menu } from './functions/menu'; +import { Events } from './functions/events'; +export class Service extends ServiceBase { -export class Service { - private rpcTracker: any; - private static instance?: Service = undefined; - private prefix: string = '__surix__'; - - /** - * Constructor - */ - private constructor() { - this.rpcTracker = {}; - this.setUpService(); - } - /** - * Sends a request to Surix - * @param type Request type - * @param payload Request payload - * @returns Promise Returns a promise - */ - public request(type: string, payload?: any) { - return this.rpc(type, payload); - } + private _data: Data; + private _toast: Toast; + private _menu: Menu; + private _events: Events; /** - * An event listener wrapper - * @param eventName A string representing the event name - * @param handler a function that handles event + * Returns all data methods */ - public on(eventName: string, handler: any) { - document.addEventListener(`${this.prefix}${eventName}`, handler); + public get data (): Data { + return this._data; } /** - * Sends the specified message to Surix - * @param msg Message to send to Surix + * Returns all toast methods */ - private sendMessage(msg: any) { - window.parent.postMessage(msg, '*'); + public get toast (): Toast { + return this._toast; } /** - * Creates a promise then sends the message - * @param name Name of the request to send to Surix - * @param body + * Returns all menu methods */ - private rpc(name: string, body: any) { - const reqId = Math.random(); - return new Promise((resolve, reject) => { - this.rpcTracker[reqId] = { resolve, reject }; - const message = { - name, - body, - type: 'rpcReq', - id: reqId - } - this.sendMessage(message); - }); + public get menu (): Menu { + return this._menu; } + /** - * This handles the rpcReq type responses from Surix - * @param msg Response from Surix - * @param handler Handles the response + * Returns all methods associated with events. */ - private handleRpcReq(msg: any, handler: any) { - if(msg.success) { - handler.rpcTracker[msg.id].resolve(msg.body); - } else { - handler.rpcTracker[msg.id].reject(msg.body); - } - // Remove the promise from the handler because - // it has already been taken care of. - // delete handler.rpcTracker[msg.id]; + public get events (): Events { + return this._events; } /** - * Emits a custom event - * @param msg Message to be embedded to the custom event to be emitted + * Constructor */ - private emit(msg: any) { - const event: Event = new CustomEvent(`${this.prefix}${msg.name}`, {detail: msg}); - document.dispatchEvent(event); + private constructor() { + super(); + this._data = new Data(); + this._toast = new Toast(); + this._menu = new Menu(); + this._events = new Events(); } + /** - * Sets up Surix service + * Provides Surix singleton */ - private setUpService() { - window.addEventListener('message', event => { - const msg: any = event.data; - switch(msg.type) { - case 'rpcRep': - this.handleRpcReq(msg, this); - break; - case 'event': - this.emit(msg); - break; - } - }); - } - - public static init() { + public static init(): Service { if(Service.instance == undefined){ Service.instance = new Service(); } return Service.instance; } + + private static instance?: Service = undefined; } \ No newline at end of file diff --git a/src/types.d.ts b/src/types.d.ts new file mode 100644 index 0000000..a936c0b --- /dev/null +++ b/src/types.d.ts @@ -0,0 +1,144 @@ +export interface FieldPair { + type: 'boolean' | 'text' | 'phone' | 'number' | 'datetime' | 'object' | 'file' | 'list'; + value: boolean | string | number | UnitField | EntityListValueData | EntityFileValueData; +} + +export interface SimpleFieldPair { + type: 'boolean' | 'text' | 'phone' | 'number' | 'datetime'; + value: boolean | string | number; +} + +export interface AppDataField { + [fieldName: string]: SimpleFieldPair; +} +export interface EntityFileValueData { + ref: string +} + +export type EntityListValueData = FieldPair[]; + +export interface UnitField extends FieldPair { + label: string; +} + +export interface BasicFieldValueData { + [fieldName: string]: UnitField | BasicFieldValueData; +} + +export interface EntityData { + data: UnitField | BasicFieldValueData; + tags?: string[] +} + +export interface AppData { + data: AppDataField; +} + +export interface PersistedAppData extends AppData, HasTimestamps, HasId {} +export interface PersistedEntityData extends HasId, HasTimestamps, EntityData {} + +export interface ToastParams { + message: string; + type: 'error' | 'success' | 'info'; +} + +export interface MenuItem { + title: string; + action: string; + icon: string; + 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; + mimeType: string; + file: File; + tags: string[]; +} + +export interface TagsParams { + tags: string[]; + entityId: string; +} + +export interface Tag { + name: string; +} + +export interface TagUpdateParams { + tags: string; + update: Tag +} + +interface CreatedBy extends HasId { + type: string; +} + +export interface FileDetails extends HasTimestamps, HasId { + addedBy: string; + addedAt: Date; + status: string; + tags: string[]; + uploadUrl: string; + mimeType: string; + size: number; + name: string; + filename: string; + public: boolean; + createdBy: CreatedBy; + downloadUrl: string; +} + +export interface Project extends HasId, HasTimestamps { + name: string; + createdBy: string; + users: Array<{ _id: string, role: string }>; + apps: Array<{ _id: string, addedBy: string, addedAt: Date}>; +} + +interface HasId { + _id: string; +} + +interface HasTimestamps { + createdAt: Date; + updatedAt: Date; +} + +export interface IData { + createEntity(entity: EntityData): Promise; + project(): Promise; + getEntities(query?: QueryParams): Promise; + getEntityById(id: string): Promise; + addTagsToEntity(params: TagsParams): Promise; + removeTagsFromEntity(params: TagsParams): Promise; + updateTag(params: TagUpdateParams): Promise; + getTags(): Promise; + getAppData(): Promise; + updateAppData(data: AppData): Promise; + createFile(file: FileParams): Promise; + getFileById(id: string): Promise; + getFiles(): Promise; +} +export interface IToast { + show(message: ToastParams): Promise; +} +export interface IMenu { + populate(menu: MenuItem[]): Promise +} \ No newline at end of file diff --git a/tsconfig.json b/tsconfig.json index 0eb3c03..e9e82be 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -3,8 +3,8 @@ "module": "commonjs", "target": "es5", "lib": [ "es2015", "dom" ], - "outDir": "build/dist", "strict": true, + "outDir": "dist", "jsx": "preserve", "moduleResolution": "node", "allowSyntheticDefaultImports": true,