From 8deee5c48fc2e69a5ea848f028fcf420a1bfe707 Mon Sep 17 00:00:00 2001 From: Kevin Nderitu Date: Wed, 21 Nov 2018 17:06:41 +0300 Subject: [PATCH 1/9] Redesigned data access in the framework --- build/dist/src/functions/data.d.ts | 69 ++++ build/dist/src/functions/menu.d.ts | 11 + build/dist/src/functions/toast.d.ts | 10 + build/dist/src/service-base.d.ts | 44 +++ build/dist/src/service.d.ts | 55 +-- dist/client-service.js | 504 +++++++++++++++++++++++++++- dist/client-service.js.map | 2 +- dist/client-service.min.js | 2 +- index.ts | 1 + src/functions/data.ts | 112 +++++++ src/functions/menu.ts | 18 + src/functions/toast.ts | 19 ++ src/service-base.ts | 90 +++++ src/service.ts | 107 ++---- src/types.ts | 94 ++++++ 15 files changed, 1016 insertions(+), 122 deletions(-) create mode 100644 build/dist/src/functions/data.d.ts create mode 100644 build/dist/src/functions/menu.d.ts create mode 100644 build/dist/src/functions/toast.d.ts create mode 100644 build/dist/src/service-base.d.ts create mode 100644 src/functions/data.ts create mode 100644 src/functions/menu.ts create mode 100644 src/functions/toast.ts create mode 100644 src/service-base.ts create mode 100644 src/types.ts diff --git a/build/dist/src/functions/data.d.ts b/build/dist/src/functions/data.d.ts new file mode 100644 index 0000000..d6bce9d --- /dev/null +++ b/build/dist/src/functions/data.d.ts @@ -0,0 +1,69 @@ +import { Service } from "../.."; +import { Project, FileDetails, FileParams, TagsParams, TagUpdateParams, Tag, EntityData, PersistedEntityData } from "../types"; +export declare class Data { + _service: Service; + constructor(); + /** + * Saves an entity in Surix + * @param entity EntityData entity to be saved + * @returns Promise + */ + 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?: any): 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(): void; + updateAppData(): void; + /** + * 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/build/dist/src/functions/menu.d.ts b/build/dist/src/functions/menu.d.ts new file mode 100644 index 0000000..5740206 --- /dev/null +++ b/build/dist/src/functions/menu.d.ts @@ -0,0 +1,11 @@ +import { Service } from "../../build/dist"; +import { MenuItem } from "../types"; +export declare class Menu { + _service: Service; + constructor(); + /** + * Populates Surix app menu with the provided items + * @param menu MenuItem[] menu items + */ + populate(menu: MenuItem[]): Promise<{}>; +} diff --git a/build/dist/src/functions/toast.d.ts b/build/dist/src/functions/toast.d.ts new file mode 100644 index 0000000..831dc4d --- /dev/null +++ b/build/dist/src/functions/toast.d.ts @@ -0,0 +1,10 @@ +import { ToastParams } from "../types"; +export declare class Toast { + private _service; + 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/service-base.d.ts b/build/dist/src/service-base.d.ts new file mode 100644 index 0000000..b8444d6 --- /dev/null +++ b/build/dist/src/service-base.d.ts @@ -0,0 +1,44 @@ +export declare class ServiceBase { + private rpcTracker; + private prefix; + protected constructor(); + /** + * Sends a request to Surix + * @param type Request type + * @param payload Request payload + * @returns Promise Returns a 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 + */ + on(eventName: string, handler: any): void; + /** + * Sends the specified message to Surix + * @param msg Message to send to Surix + */ + private sendMessage; + /** + * Creates a promise then sends the message + * @param name Name of the request to send to Surix + * @param body + */ + private rpc; + /** + * This handles the rpcReq type responses from Surix + * @param msg Response from Surix + * @param handler Handles the response + */ + private handleRpcReq; + /** + * Emits a custom event + * @param msg Message to be embedded to the custom event to be emitted + */ + private emit; + /** + * Sets up Surix service + */ + protected setUpService(): void; +} diff --git a/build/dist/src/service.d.ts b/build/dist/src/service.d.ts index 7a95d98..95adf2e 100644 --- a/build/dist/src/service.d.ts +++ b/build/dist/src/service.d.ts @@ -1,49 +1,30 @@ -export declare class Service { - private rpcTracker; - private static instance?; - private prefix; - /** - * Constructor - */ - private constructor(); - /** - * Sends a request to Surix - * @param type Request type - * @param payload Request payload - * @returns Promise Returns a 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 - */ - on(eventName: string, handler: any): void; +import { ServiceBase } from './service-base'; +import { Data } from './functions/data'; +import { Toast } from './functions/toast'; +import { Menu } from './functions/menu'; +export declare class Service extends ServiceBase { + private _data; + private _toast; + private _menu; /** - * Sends the specified message to Surix - * @param msg Message to send to Surix + * Returns all data methods */ - private sendMessage; + readonly data: Data; /** - * Creates a promise then sends the message - * @param name Name of the request to send to Surix - * @param body + * Returns all toast methods */ - private rpc; + readonly toast: Toast; /** - * This handles the rpcReq type responses from Surix - * @param msg Response from Surix - * @param handler Handles the response + * Returns all menu methods */ - private handleRpcReq; + readonly menu: Menu; /** - * Emits a custom event - * @param msg Message to be embedded to the custom event to be emitted + * Constructor */ - private emit; + private constructor(); /** - * Sets up Surix service + * Provides Surix singleton */ - private setUpService; static init(): Service; + private static instance?; } diff --git a/dist/client-service.js b/dist/client-service.js index 6a11ce8..9073c58 100644 --- a/dist/client-service.js +++ b/dist/client-service.js @@ -101,9 +101,9 @@ return /******/ (function(modules) { // webpackBootstrap "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); -var service_1 = __webpack_require__(1); +var service_1 = __webpack_require__(2); exports.Service = service_1.Service; -var requests_1 = __webpack_require__(2); +var requests_1 = __webpack_require__(9); exports.requests = requests_1.requests; @@ -113,6 +113,419 @@ exports.requests = requests_1.requests; "use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +var service_1 = __webpack_require__(5); +exports.Service = service_1.Service; +var requests_1 = __webpack_require__(6); +exports.requests = requests_1.requests; +//# sourceMappingURL=index.js.map + +/***/ }), +/* 2 */ +/***/ (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__(3); +var data_1 = __webpack_require__(4); +var toast_1 = __webpack_require__(7); +var menu_1 = __webpack_require__(8); +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(); + 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 + }); + /** + * 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; + + +/***/ }), +/* 3 */ +/***/ (function(module, exports, __webpack_require__) { + +"use strict"; + +Object.defineProperty(exports, "__esModule", { value: true }); +var ServiceBase = /** @class */ (function () { + function ServiceBase() { + 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 + */ + ServiceBase.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 + */ + ServiceBase.prototype.on = function (eventName, handler) { + document.addEventListener("" + this.prefix + eventName, handler); + }; + /** + * Sends the specified message to Surix + * @param msg Message to send to Surix + */ + ServiceBase.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 + */ + ServiceBase.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 + */ + ServiceBase.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 + */ + ServiceBase.prototype.emit = function (msg) { + var event = new CustomEvent("" + this.prefix + msg.name, { detail: msg }); + document.dispatchEvent(event); + }; + /** + * Sets up Surix service + */ + 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); + break; + case 'event': + _this.emit(msg); + break; + } + }); + }; + return ServiceBase; +}()); +exports.ServiceBase = ServiceBase; + + +/***/ }), +/* 4 */ +/***/ (function(module, exports, __webpack_require__) { + +"use strict"; + +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 __1 = __webpack_require__(0); +var dist_1 = __webpack_require__(1); +var Data = /** @class */ (function () { + function Data() { + this._service = __1.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._service.request(dist_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._service.request(dist_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._service.request(dist_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._service.request(dist_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._service.request(dist_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._service.request(dist_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._service.request(dist_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._service.request(dist_1.requests.data.getTags)]; + case 1: return [2 /*return*/, _a.sent()]; + } + }); + }); + }; + Data.prototype.getAppData = function () { + }; + Data.prototype.updateAppData = function () { + }; + /** + * 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._service.request(dist_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._service.request(dist_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._service.request(dist_1.requests.data.getFiles)]; + case 1: return [2 /*return*/, _a.sent()]; + } + }); + }); + }; + return Data; +}()); +exports.Data = Data; + + +/***/ }), +/* 5 */ +/***/ (function(module, exports, __webpack_require__) { + +"use strict"; + Object.defineProperty(exports, "__esModule", { value: true }); var Service = /** @class */ (function () { /** @@ -217,10 +630,95 @@ var Service = /** @class */ (function () { return Service; }()); exports.Service = Service; +//# sourceMappingURL=service.js.map + +/***/ }), +/* 6 */ +/***/ (function(module, exports, __webpack_require__) { +"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 /***/ }), -/* 2 */ +/* 7 */ +/***/ (function(module, exports, __webpack_require__) { + +"use strict"; + +Object.defineProperty(exports, "__esModule", { value: true }); +var __1 = __webpack_require__(0); +var dist_1 = __webpack_require__(1); +var Toast = /** @class */ (function () { + function Toast() { + this._service = __1.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._service.request(dist_1.requests.toast.show, message); + }; + return Toast; +}()); +exports.Toast = Toast; + + +/***/ }), +/* 8 */ +/***/ (function(module, exports, __webpack_require__) { + +"use strict"; + +Object.defineProperty(exports, "__esModule", { value: true }); +var dist_1 = __webpack_require__(1); +var Menu = /** @class */ (function () { + function Menu() { + this._service = dist_1.Service.init(); + } + /** + * Populates Surix app menu with the provided items + * @param menu MenuItem[] menu items + */ + Menu.prototype.populate = function (menu) { + return this._service.request(dist_1.requests.menu.populate, menu); + }; + return Menu; +}()); +exports.Menu = Menu; + + +/***/ }), +/* 9 */ /***/ (function(module, exports, __webpack_require__) { "use strict"; diff --git a/dist/client-service.js.map b/dist/client-service.js.map index 2fe048e..0d94cba 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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;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","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/./index.ts","webpack://Surix/./build/dist/index.js","webpack://Surix/./src/service.ts","webpack://Surix/./src/service-base.ts","webpack://Surix/./src/functions/data.ts","webpack://Surix/./build/dist/src/service.js","webpack://Surix/./build/dist/src/requests.js","webpack://Surix/./src/functions/toast.ts","webpack://Surix/./src/functions/menu.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;AAIpC,kBAJK,iBAAO,CAIL;AAHX,wCAA0C;AAItC,mBAJK,mBAAQ,CAIL;;;;;;;;ACLZ;AACA,8CAA8C,cAAc;AAC5D;AACA;AACA;AACA;AACA,iC;;;;;;;;;;;;;;;;;;;;;;ACNA,4CAA6C;AAC7C,oCAAwC;AACxC,qCAA0C;AAC1C,oCAAwC;AACxC;IAA6B,2BAAW;IAwBpC;;OAEG;IACH;Q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KACrE;IAED;;;OAGG;IACU,uBAAQ,GAArB;;;;4BACW,qBAAM,IAAI,CAAC,QAAQ,CAAC,OAAO,CAAC,eAAQ,CAAC,IAAI,CAAC,QAAQ,CAAC;4BAA1D,sBAAO,SAAmD,EAAC;;;;KAC9D;IACL,WAAC;AAAD,CAAC;AA3GY,oBAAI;;;;;;;;ACJjB;AACA,8CAA8C,cAAc;AAC5D;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,uCAAuC;AACvC;AACA;AACA;AACA;AACA;AACA;AACA;AACA,SAAS;AACT;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,kEAAkE,cAAc;AAChF;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,SAAS;AACT;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,CAAC;AACD;AACA,mC;;;;;;;ACzGA;AACA,8CAA8C,cAAc;AAC5D;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,KAAK;AACL;AACA;AACA,KAAK;AACL;AACA;AACA,KAAK;AACL;AACA;AACA;AACA;AACA;AACA;AACA;AACA,oC;;;;;;;;;AC7BA,iCAAgC;AAEhC,oCAA4C;AAE5C;IAGI;QACI,IAAI,CAAC,QAAQ,GAAG,WAAO,CAAC,IAAI,EAAE,CAAC;IACnC,CAAC;IAED;;;OAGG;IACI,oBAAI,GAAX,UAAY,OAAoB;QAC5B,OAAO,IAAI,CAAC,QAAQ,CAAC,OAAO,CAAC,eAAQ,CAAC,KAAK,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC;IAC/D,CAAC;IACL,YAAC;AAAD,CAAC;AAdY,sBAAK;;;;;;;;;;ACJlB,oCAAqD;AAGrD;IAGI;QACI,IAAI,CAAC,QAAQ,GAAG,cAAO,CAAC,IAAI,EAAE,CAAC;IACnC,CAAC;IAED;;;OAGG;IACI,uBAAQ,GAAf,UAAgB,IAAgB;QAC5B,OAAO,IAAI,CAAC,QAAQ,CAAC,OAAO,CAAC,eAAQ,CAAC,IAAI,CAAC,QAAQ,EAAE,IAAI,CAAC,CAAC;IAC/D,CAAC;IACL,WAAC;AAAD,CAAC;AAdY,oBAAI;;;;;;;;;;ACHJ,gBAAQ,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;QAC7B,WAAW,EAAE,kBAAkB;QAC/B,QAAQ,EAAE,eAAe;KAC5B;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","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';\nimport { EntityData } from './src/types';\nexport {\n Service,\n requests\n}","\"use strict\";\nObject.defineProperty(exports, \"__esModule\", { value: true });\nvar service_1 = require(\"./src/service\");\nexports.Service = service_1.Service;\nvar requests_1 = require(\"./src/requests\");\nexports.requests = requests_1.requests;\n//# sourceMappingURL=index.js.map","import { ServiceBase } from './service-base';\nimport { Data } from './functions/data';\nimport { Toast } from './functions/toast';\nimport { Menu } from './functions/menu';\nexport class Service extends ServiceBase {\n\n private _data: Data;\n private _toast: Toast;\n private _menu: Menu;\n\n /**\n * Returns all data methods\n */\n public get data () {\n return this._data;\n }\n /**\n * Returns all toast methods\n */\n public get toast () {\n return this._toast;\n }\n /**\n * Returns all menu methods\n */\n public get menu () {\n return this._menu;\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 }\n\n /**\n * Provides Surix singleton\n */\n public static init() {\n if(Service.instance == undefined){\n Service.instance = new Service();\n }\n return Service.instance;\n }\n \n private static instance?: Service = undefined;\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 * 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): Promise {\n return this.rpc(type, payload);\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 protected setUpService() {\n window.addEventListener('message', event => {\n const msg: any = event.data;\n switch(msg.type) {\n case 'rpcRep':\n this.handleRpcReq(msg, this);\n break;\n case 'event':\n this.emit(msg);\n break;\n }\n });\n }\n}","import { Service } from \"../..\";\nimport { Project, FileDetails, FileParams, TagsParams, TagUpdateParams, Tag, EntityData, PersistedEntityData } from \"../types\";\nimport { requests } from \"../../build/dist\";\n\nexport class Data {\n public _service: Service;\n \n public constructor() {\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._service.request(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._service.request(requests.data.project);\n }\n\n /**\n * Returns all the entities present\n * @param query (Optional) query\n * @returns Promise\n */\n public async getEntities(query?: any): Promise {\n return await this._service.request(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._service.request(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._service.request(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._service.request(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._service.request(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._service.request(requests.data.getTags);\n }\n\n public getAppData() {\n\n }\n public updateAppData() {\n\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._service.request(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._service.request(requests.data.getFileById, id);\n }\n\n /**\n * Returns all files\n * @returns Promise\n */\n public async getFiles(): Promise{\n return await this._service.request(requests.data.getFiles);\n }\n}","\"use strict\";\nObject.defineProperty(exports, \"__esModule\", { value: true });\nvar Service = /** @class */ (function () {\n /**\n * Constructor\n */\n function Service() {\n this.prefix = '__surix__';\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 Service.prototype.request = function (type, payload) {\n return this.rpc(type, payload);\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 Service.prototype.on = function (eventName, handler) {\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 Service.prototype.sendMessage = function (msg) {\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 Service.prototype.rpc = function (name, body) {\n var _this = this;\n var reqId = Math.random();\n return new Promise(function (resolve, reject) {\n _this.rpcTracker[reqId] = { resolve: resolve, reject: reject };\n var message = {\n name: name,\n body: 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 Service.prototype.handleRpcReq = function (msg, handler) {\n if (msg.success) {\n handler.rpcTracker[msg.id].resolve(msg.body);\n }\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 Service.prototype.emit = function (msg) {\n var event = new CustomEvent(\"\" + this.prefix + msg.name, { detail: msg });\n document.dispatchEvent(event);\n };\n /**\n * Sets up Surix service\n */\n Service.prototype.setUpService = function () {\n var _this = this;\n window.addEventListener('message', function (event) {\n var msg = 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 Service.init = function () {\n if (Service.instance == undefined) {\n Service.instance = new Service();\n }\n return Service.instance;\n };\n Service.instance = undefined;\n return Service;\n}());\nexports.Service = Service;\n//# sourceMappingURL=service.js.map","\"use strict\";\nObject.defineProperty(exports, \"__esModule\", { value: true });\nexports.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 uploadFile: 'data.uploadFile',\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};\n//# sourceMappingURL=requests.js.map","import { Service } from \"../..\";\nimport { ToastParams } from \"../types\";\nimport { requests } from \"../../build/dist\";\n\nexport class Toast {\n private _service: Service;\n\n public constructor() {\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) {\n return this._service.request(requests.toast.show, message);\n }\n}","import { Service, requests } from \"../../build/dist\";\nimport { MenuItem } from \"../types\";\n\nexport class Menu {\n public _service: Service;\n\n public constructor() {\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[]) {\n return this._service.request(requests.menu.populate, menu);\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 diff --git a/dist/client-service.min.js b/dist/client-service.min.js index 0f36589..f2b2e0a 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(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 i=t[r]={i:r,l:!1,exports:{}};return e[r].call(i.exports,i,i.exports,n),i.l=!0,i.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 i in e)n.d(r,i,function(t){return e[t]}.bind(null,i));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(2);t.Service=r.Service;var i=n(9);t.requests=i.requests},function(e,t,n){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var r=n(5);t.Service=r.Service;var i=n(6);t.requests=i.requests},function(e,t,n){"use strict";var r=this&&this.__extends||function(){var e=function(t,n){return(e=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var n in t)t.hasOwnProperty(n)&&(e[n]=t[n])})(t,n)};return function(t,n){function r(){this.constructor=t}e(t,n),t.prototype=null===n?Object.create(n):(r.prototype=n.prototype,new r)}}();Object.defineProperty(t,"__esModule",{value:!0});var i=n(3),o=n(4),a=n(7),s=n(8),u=function(e){function t(){var t=e.call(this)||this;return t._data=new o.Data,t._toast=new a.Toast,t._menu=new s.Menu,t}return r(t,e),Object.defineProperty(t.prototype,"data",{get:function(){return this._data},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"toast",{get:function(){return this._toast},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"menu",{get:function(){return this._menu},enumerable:!0,configurable:!0}),t.init=function(){return void 0==t.instance&&(t.instance=new t),t.instance},t.instance=void 0,t}(i.ServiceBase);t.Service=u},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(i,o){n.rpcTracker[r]={resolve:i,reject:o};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}();t.ServiceBase=r},function(e,t,n){"use strict";var r=this&&this.__awaiter||function(e,t,n,r){return new(n||(n=Promise))(function(i,o){function a(e){try{u(r.next(e))}catch(e){o(e)}}function s(e){try{u(r.throw(e))}catch(e){o(e)}}function u(e){e.done?i(e.value):new n(function(t){t(e.value)}).then(a,s)}u((r=r.apply(e,t||[])).next())})},i=this&&this.__generator||function(e,t){var n,r,i,o,a={label:0,sent:function(){if(1&i[0])throw i[1];return i[1]},trys:[],ops:[]};return o={next:s(0),throw:s(1),return:s(2)},"function"==typeof Symbol&&(o[Symbol.iterator]=function(){return this}),o;function s(o){return function(s){return function(o){if(n)throw new TypeError("Generator is already executing.");for(;a;)try{if(n=1,r&&(i=2&o[0]?r.return:o[0]?r.throw||((i=r.return)&&i.call(r),0):r.next)&&!(i=i.call(r,o[1])).done)return i;switch(r=0,i&&(o=[2&o[0],i.value]),o[0]){case 0:case 1:i=o;break;case 4:return a.label++,{value:o[1],done:!1};case 5:a.label++,r=o[1],o=[0];continue;case 7:o=a.ops.pop(),a.trys.pop();continue;default:if(!(i=(i=a.trys).length>0&&i[i.length-1])&&(6===o[0]||2===o[0])){a=0;continue}if(3===o[0]&&(!i||o[1]>i[0]&&o[1] + */ + public async createEntity(entity: EntityData): Promise { + return await this._service.request(requests.data.createEntity, entity); + } + + /** + * Returns the current project + * @returns Promise + */ + public async project(): Promise { + return await this._service.request(requests.data.project); + } + + /** + * Returns all the entities present + * @param query (Optional) query + * @returns Promise + */ + public async getEntities(query?: any): Promise { + return await this._service.request(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._service.request(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._service.request(requests.data.addTagsToEntity, params); + } + + /** + * Removes tags from an entity + * @param params TagsParams tag parameters + */ + public async removeTagsFromEntity(params: TagsParams): Promise { + return await this._service.request(requests.data.removeTagsFromEntity, params); + } + + /** + * Updates tags on an existing entity + * @param params Update params + */ + public async updateTag(params: TagUpdateParams): Promise { + return await this._service.request(requests.data.updateTag, params); + } + + /** + * Returns all the tags available + * @returns Promise + */ + public async getTags(): Promise { + return await this._service.request(requests.data.getTags); + } + + public getAppData() { + + } + public updateAppData() { + + } + + /** + * 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._service.request(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._service.request(requests.data.getFileById, id); + } + + /** + * Returns all files + * @returns Promise + */ + public async getFiles(): Promise{ + return await this._service.request(requests.data.getFiles); + } +} \ No newline at end of file diff --git a/src/functions/menu.ts b/src/functions/menu.ts new file mode 100644 index 0000000..5d4c1bb --- /dev/null +++ b/src/functions/menu.ts @@ -0,0 +1,18 @@ +import { Service, requests } from "../../build/dist"; +import { MenuItem } from "../types"; + +export class Menu { + public _service: Service; + + public constructor() { + this._service = Service.init(); + } + + /** + * Populates Surix app menu with the provided items + * @param menu MenuItem[] menu items + */ + public populate(menu: MenuItem[]) { + return this._service.request(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..edbd7e4 --- /dev/null +++ b/src/functions/toast.ts @@ -0,0 +1,19 @@ +import { Service } from "../.."; +import { ToastParams } from "../types"; +import { requests } from "../../build/dist"; + +export class Toast { + private _service: Service; + + public constructor() { + 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) { + return this._service.request(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..3a318b3 --- /dev/null +++ b/src/service-base.ts @@ -0,0 +1,90 @@ +export class ServiceBase { + private rpcTracker: any; + private prefix: string = '__surix__'; + + protected 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): Promise { + 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 on(eventName: string, handler: any) { + 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 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]; + } + /** + * 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.handleRpcReq(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..3a55402 100644 --- a/src/service.ts +++ b/src/service.ts @@ -1,103 +1,50 @@ +import { ServiceBase } from './service-base'; +import { Data } from './functions/data'; +import { Toast } from './functions/toast'; +import { Menu } from './functions/menu'; +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; /** - * 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 () { + 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 () { + 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 () { + return this._menu; } /** - * This handles the rpcReq type responses from Surix - * @param msg Response from Surix - * @param handler Handles the response - */ - 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]; - } - /** - * 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(); } + /** - * 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() { 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.ts b/src/types.ts new file mode 100644 index 0000000..79601f0 --- /dev/null +++ b/src/types.ts @@ -0,0 +1,94 @@ +export interface FieldPair { + type: 'boolean' | 'text' | 'phone' | 'number' | 'datetime' | 'object' | 'file' | 'list'; + value: boolean | string | number | UnitField | EntityListValueData | EntityFileValueData; +} + +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 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 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; +} \ No newline at end of file From e113a946acb2faa1d0ce8eb966cb40b6f30df578 Mon Sep 17 00:00:00 2001 From: Kevin Nderitu Date: Wed, 21 Nov 2018 17:17:21 +0300 Subject: [PATCH 2/9] Added extra query support --- index.ts | 2 +- src/functions/data.ts | 10 +++++----- src/types.ts | 11 +++++++++++ 3 files changed, 17 insertions(+), 6 deletions(-) diff --git a/index.ts b/index.ts index 6e589dc..7b27889 100644 --- a/index.ts +++ b/index.ts @@ -1,6 +1,6 @@ import { Service } from './src/service'; import { requests } from './src/requests'; -import { EntityData } from './src/types'; +import { EntityData, AppData } from './src/types'; export { Service, requests diff --git a/src/functions/data.ts b/src/functions/data.ts index 1f2a287..e20334a 100644 --- a/src/functions/data.ts +++ b/src/functions/data.ts @@ -1,5 +1,5 @@ import { Service } from "../.."; -import { Project, FileDetails, FileParams, TagsParams, TagUpdateParams, Tag, EntityData, PersistedEntityData } from "../types"; +import { Project, FileDetails, FileParams, TagsParams, TagUpdateParams, Tag, EntityData, PersistedEntityData, AppData } from "../types"; import { requests } from "../../build/dist"; export class Data { @@ -77,11 +77,11 @@ export class Data { return await this._service.request(requests.data.getTags); } - public getAppData() { - + public async getAppData() { + return await this._service.request(requests.data.getAppData); } - public updateAppData() { - + public async updateAppData(appData: AppData) { + return await this._service.request(requests.data.updateAppData, appData); } /** diff --git a/src/types.ts b/src/types.ts index 79601f0..3238f0e 100644 --- a/src/types.ts +++ b/src/types.ts @@ -3,6 +3,14 @@ export interface FieldPair { 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 } @@ -22,6 +30,9 @@ export interface EntityData { tags?: string[] } +export interface AppData { + data: AppDataField; +} export interface PersistedEntityData extends HasId, HasTimestamps, EntityData {} export interface ToastParams { From 0c824f3b7d2bfc1f92a82e2bd4df2959a2ed21b1 Mon Sep 17 00:00:00 2001 From: Kevin Nderitu Date: Thu, 22 Nov 2018 16:10:12 +0300 Subject: [PATCH 3/9] Restructured client-service --- build/dist/index.js | 7 - build/dist/index.js.map | 1 - build/dist/src/functions/menu.d.ts | 11 - build/dist/src/functions/toast.d.ts | 10 - build/dist/src/requests.js | 30 - build/dist/src/requests.js.map | 1 - build/dist/src/service.js | 106 ---- build/dist/src/service.js.map | 1 - dist/client-service.js | 558 ++++++++----------- dist/client-service.js.map | 2 +- dist/client-service.min.js | 2 +- {build/dist => dist}/index.d.ts | 0 {build/dist => dist}/src/functions/data.d.ts | 11 +- dist/src/functions/menu.d.ts | 10 + dist/src/functions/toast.d.ts | 10 + {build/dist => dist}/src/requests.d.ts | 0 dist/src/service-base.d.ts | 51 ++ {build/dist => dist}/src/service.d.ts | 0 src/types.ts => dist/src/types.d.ts | 28 +- index.d.ts | 3 + index.ts | 2 +- package.json | 5 +- src/functions/data.d.ts | 68 +++ src/functions/data.ts | 55 +- src/functions/menu.d.ts | 10 + src/functions/menu.ts | 16 +- src/functions/toast.d.ts | 10 + src/functions/toast.ts | 17 +- src/requests.d.ts | 27 + {build/dist/src => src}/service-base.d.ts | 2 +- src/service-base.ts | 14 +- src/service.d.ts | 30 + src/service.ts | 8 +- src/types.d.ts | 129 +++++ tsconfig.json | 2 +- 35 files changed, 691 insertions(+), 546 deletions(-) delete mode 100644 build/dist/index.js delete mode 100644 build/dist/index.js.map delete mode 100644 build/dist/src/functions/menu.d.ts delete mode 100644 build/dist/src/functions/toast.d.ts delete mode 100644 build/dist/src/requests.js delete mode 100644 build/dist/src/requests.js.map delete mode 100644 build/dist/src/service.js delete mode 100644 build/dist/src/service.js.map rename {build/dist => dist}/index.d.ts (100%) rename {build/dist => dist}/src/functions/data.d.ts (83%) create mode 100644 dist/src/functions/menu.d.ts create mode 100644 dist/src/functions/toast.d.ts rename {build/dist => dist}/src/requests.d.ts (100%) create mode 100644 dist/src/service-base.d.ts rename {build/dist => dist}/src/service.d.ts (100%) rename src/types.ts => dist/src/types.d.ts (67%) create mode 100644 index.d.ts create mode 100644 src/functions/data.d.ts create mode 100644 src/functions/menu.d.ts create mode 100644 src/functions/toast.d.ts create mode 100644 src/requests.d.ts rename {build/dist/src => src}/service-base.d.ts (94%) create mode 100644 src/service.d.ts create mode 100644 src/types.d.ts 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/functions/menu.d.ts b/build/dist/src/functions/menu.d.ts deleted file mode 100644 index 5740206..0000000 --- a/build/dist/src/functions/menu.d.ts +++ /dev/null @@ -1,11 +0,0 @@ -import { Service } from "../../build/dist"; -import { MenuItem } from "../types"; -export declare class Menu { - _service: Service; - constructor(); - /** - * Populates Surix app menu with the provided items - * @param menu MenuItem[] menu items - */ - populate(menu: MenuItem[]): Promise<{}>; -} diff --git a/build/dist/src/functions/toast.d.ts b/build/dist/src/functions/toast.d.ts deleted file mode 100644 index 831dc4d..0000000 --- a/build/dist/src/functions/toast.d.ts +++ /dev/null @@ -1,10 +0,0 @@ -import { ToastParams } from "../types"; -export declare class Toast { - private _service; - 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.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/service.js.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"service.js","sourceRoot":"","sources":["../../../src/service.ts"],"names":[],"mappings":";;AACA;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,UAAU,SAAiB,EAAE,OAAY;QACrC,QAAQ,CAAC,gBAAgB,CAAC,KAAG,IAAI,CAAC,MAAM,GAAG,SAAW,EAAE,OAAO,CAAC,CAAC;IACrE,CAAC;IACD;;;OAGG;IACK,6BAAW,GAAnB,UAAoB,GAAQ;QACxB,MAAM,CAAC,MAAM,CAAC,WAAW,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC;IACxC,CAAC;IACD;;;;OAIG;IACK,qBAAG,GAAX,UAAY,IAAY,EAAE,IAAS;QAAnC,iBAYC;QAXG,IAAM,KAAK,GAAG,IAAI,CAAC,MAAM,EAAE,CAAC;QAC5B,OAAO,IAAI,OAAO,CAAC,UAAC,OAAO,EAAE,MAAM;YAC/B,KAAI,CAAC,UAAU,CAAC,KAAK,CAAC,GAAG,EAAE,O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QACL,CAAC,CAAC,CAAC;IACP,CAAC;IAEa,YAAI,GAAlB;QACI,IAAG,OAAO,CAAC,QAAQ,IAAI,SAAS,EAAC;YAC7B,OAAO,CAAC,QAAQ,GAAG,IAAI,OAAO,EAAE,CAAC;SACpC;QACD,OAAO,OAAO,CAAC,QAAQ,CAAC;IAC5B,CAAC;IAlGc,gBAAQ,GAAa,SAAS,CAAC;IAmGlD,cAAC;CAAA,AArGD,IAqGC;AArGY,0BAAO"} \ No newline at end of file diff --git a/dist/client-service.js b/dist/client-service.js index 9073c58..1016e0f 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); /******/ }) /************************************************************************/ /******/ ([ @@ -100,113 +100,6 @@ return /******/ (function(modules) { // webpackBootstrap "use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); -var service_1 = __webpack_require__(2); -exports.Service = service_1.Service; -var requests_1 = __webpack_require__(9); -exports.requests = requests_1.requests; - - -/***/ }), -/* 1 */ -/***/ (function(module, exports, __webpack_require__) { - -"use strict"; - -Object.defineProperty(exports, "__esModule", { value: true }); -var service_1 = __webpack_require__(5); -exports.Service = service_1.Service; -var requests_1 = __webpack_require__(6); -exports.requests = requests_1.requests; -//# sourceMappingURL=index.js.map - -/***/ }), -/* 2 */ -/***/ (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__(3); -var data_1 = __webpack_require__(4); -var toast_1 = __webpack_require__(7); -var menu_1 = __webpack_require__(8); -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(); - 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 - }); - /** - * 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; - - -/***/ }), -/* 3 */ -/***/ (function(module, exports, __webpack_require__) { - -"use strict"; - Object.defineProperty(exports, "__esModule", { value: true }); var ServiceBase = /** @class */ (function () { function ServiceBase() { @@ -214,13 +107,23 @@ var ServiceBase = /** @class */ (function () { 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 */ 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); }; /** @@ -271,7 +174,7 @@ var ServiceBase = /** @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 @@ -303,12 +206,157 @@ var ServiceBase = /** @class */ (function () { exports.ServiceBase = ServiceBase; +/***/ }), +/* 1 */ +/***/ (function(module, exports, __webpack_require__) { + +"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', + createFile: 'data.createFile', + getFileById: 'data.getFileById', + getFiles: 'data.getFiles' + }, + 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' + } +}; + + +/***/ }), +/* 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 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(); + 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 + }); + /** + * 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); } } @@ -345,11 +393,14 @@ var __generator = (this && this.__generator) || function (thisArg, body) { } }; Object.defineProperty(exports, "__esModule", { value: true }); -var __1 = __webpack_require__(0); -var dist_1 = __webpack_require__(1); -var Data = /** @class */ (function () { +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() { - this._service = __1.Service.init(); + return _super.call(this) || this; + //this._service = Service.init(); } /** * Saves an entity in Surix @@ -360,7 +411,7 @@ var Data = /** @class */ (function () { return __awaiter(this, void 0, void 0, function () { return __generator(this, function (_a) { switch (_a.label) { - case 0: return [4 /*yield*/, this._service.request(dist_1.requests.data.createEntity, entity)]; + case 0: return [4 /*yield*/, this.internalRequest(requests_1.requests.data.createEntity, entity)]; case 1: return [2 /*return*/, _a.sent()]; } }); @@ -374,7 +425,7 @@ var Data = /** @class */ (function () { return __awaiter(this, void 0, void 0, function () { return __generator(this, function (_a) { switch (_a.label) { - case 0: return [4 /*yield*/, this._service.request(dist_1.requests.data.project)]; + case 0: return [4 /*yield*/, this.internalRequest(requests_1.requests.data.project)]; case 1: return [2 /*return*/, _a.sent()]; } }); @@ -389,7 +440,7 @@ var Data = /** @class */ (function () { return __awaiter(this, void 0, void 0, function () { return __generator(this, function (_a) { switch (_a.label) { - case 0: return [4 /*yield*/, this._service.request(dist_1.requests.data.getEntities, query)]; + case 0: return [4 /*yield*/, this.internalRequest(requests_1.requests.data.getEntities, query)]; case 1: return [2 /*return*/, _a.sent()]; } }); @@ -404,7 +455,7 @@ var Data = /** @class */ (function () { return __awaiter(this, void 0, void 0, function () { return __generator(this, function (_a) { switch (_a.label) { - case 0: return [4 /*yield*/, this._service.request(dist_1.requests.data.getEntityById, id)]; + case 0: return [4 /*yield*/, this.internalRequest(requests_1.requests.data.getEntityById, id)]; case 1: return [2 /*return*/, _a.sent()]; } }); @@ -419,7 +470,7 @@ var Data = /** @class */ (function () { return __awaiter(this, void 0, void 0, function () { return __generator(this, function (_a) { switch (_a.label) { - case 0: return [4 /*yield*/, this._service.request(dist_1.requests.data.addTagsToEntity, params)]; + case 0: return [4 /*yield*/, this.internalRequest(requests_1.requests.data.addTagsToEntity, params)]; case 1: return [2 /*return*/, _a.sent()]; } }); @@ -433,7 +484,7 @@ var Data = /** @class */ (function () { return __awaiter(this, void 0, void 0, function () { return __generator(this, function (_a) { switch (_a.label) { - case 0: return [4 /*yield*/, this._service.request(dist_1.requests.data.removeTagsFromEntity, params)]; + case 0: return [4 /*yield*/, this.internalRequest(requests_1.requests.data.removeTagsFromEntity, params)]; case 1: return [2 /*return*/, _a.sent()]; } }); @@ -447,7 +498,7 @@ var Data = /** @class */ (function () { return __awaiter(this, void 0, void 0, function () { return __generator(this, function (_a) { switch (_a.label) { - case 0: return [4 /*yield*/, this._service.request(dist_1.requests.data.updateTag, params)]; + case 0: return [4 /*yield*/, this.internalRequest(requests_1.requests.data.updateTag, params)]; case 1: return [2 /*return*/, _a.sent()]; } }); @@ -461,15 +512,31 @@ var Data = /** @class */ (function () { return __awaiter(this, void 0, void 0, function () { return __generator(this, function (_a) { switch (_a.label) { - case 0: return [4 /*yield*/, this._service.request(dist_1.requests.data.getTags)]; + 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 () { + 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. @@ -480,7 +547,7 @@ var Data = /** @class */ (function () { return __awaiter(this, void 0, void 0, function () { return __generator(this, function (_a) { switch (_a.label) { - case 0: return [4 /*yield*/, this._service.request(dist_1.requests.data.createFile, file)]; + case 0: return [4 /*yield*/, this.internalRequest(requests_1.requests.data.createFile, file)]; case 1: return [2 /*return*/, _a.sent()]; } }); @@ -495,7 +562,7 @@ var Data = /** @class */ (function () { return __awaiter(this, void 0, void 0, function () { return __generator(this, function (_a) { switch (_a.label) { - case 0: return [4 /*yield*/, this._service.request(dist_1.requests.data.getFileById, id)]; + case 0: return [4 /*yield*/, this.internalRequest(requests_1.requests.data.getFileById, id)]; case 1: return [2 /*return*/, _a.sent()]; } }); @@ -509,14 +576,14 @@ var Data = /** @class */ (function () { return __awaiter(this, void 0, void 0, function () { return __generator(this, function (_a) { switch (_a.label) { - case 0: return [4 /*yield*/, this._service.request(dist_1.requests.data.getFiles)]; + 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; @@ -526,235 +593,82 @@ exports.Data = Data; "use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); -var Service = /** @class */ (function () { - /** - * Constructor - */ - function Service() { - this.prefix = '__surix__'; - this.rpcTracker = {}; - this.setUpService(); +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); } - /** - * 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; + return function (d, b) { + extendStatics(d, b); + function __() { this.constructor = d; } + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); }; - Service.instance = undefined; - return Service; -}()); -exports.Service = Service; -//# sourceMappingURL=service.js.map - -/***/ }), -/* 6 */ -/***/ (function(module, exports, __webpack_require__) { - -"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 - -/***/ }), -/* 7 */ -/***/ (function(module, exports, __webpack_require__) { - -"use strict"; - +})(); Object.defineProperty(exports, "__esModule", { value: true }); -var __1 = __webpack_require__(0); -var dist_1 = __webpack_require__(1); -var Toast = /** @class */ (function () { +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() { - this._service = __1.Service.init(); + 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._service.request(dist_1.requests.toast.show, message); + return this.internalRequest(requests_1.requests.toast.show, message); }; return Toast; -}()); +}(service_base_1.ServiceBase)); exports.Toast = Toast; /***/ }), -/* 8 */ +/* 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 dist_1 = __webpack_require__(1); -var Menu = /** @class */ (function () { +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() { - this._service = dist_1.Service.init(); + 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._service.request(dist_1.requests.menu.populate, menu); + return this.internalRequest(requests_1.requests.menu.populate, menu); }; return Menu; -}()); +}(service_base_1.ServiceBase)); exports.Menu = Menu; -/***/ }), -/* 9 */ -/***/ (function(module, exports, __webpack_require__) { - -"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', - createFile: 'data.createFile', - getFileById: 'data.getFileById', - getFiles: 'data.getFiles' - }, - 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' - } -}; - - /***/ }) /******/ ]); }); diff --git a/dist/client-service.js.map b/dist/client-service.js.map index 0d94cba..a928891 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/./build/dist/index.js","webpack://Surix/./src/service.ts","webpack://Surix/./src/service-base.ts","webpack://Surix/./src/functions/data.ts","webpack://Surix/./build/dist/src/service.js","webpack://Surix/./build/dist/src/requests.js","webpack://Surix/./src/functions/toast.ts","webpack://Surix/./src/functions/menu.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,0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B;IAEA,CAAC;IAED;;;;OAIG;IACU,yBAAU,GAAvB,UAAwB,IAAgB;;;;4BAC7B,qBAAM,IAAI,CAAC,QAAQ,CAAC,OAAO,CAAC,eAAQ,CAAC,IAAI,CAAC,UAAU,EAAE,IAAI,CAAC;4BAAlE,sBAAO,SAA2D,EAAC;;;;KACtE;IAED;;;;OAIG;IACU,0BAAW,GAAxB,UAAyB,EAAU;;;;4BACxB,qBAAM,IAAI,CAAC,QAAQ,CAAC,OAAO,CAAC,eAAQ,CAAC,IAAI,CAAC,WAAW,EAAE,EAAE,CAAC;4BAAjE,sBAAO,SAA0D,EAAC;;;;KACrE;IAED;;;OAGG;IACU,uBAAQ,GAArB;;;;4BACW,qBAAM,IAAI,CAAC,QAAQ,CAAC,OAAO,CAAC,eAAQ,CAAC,IAAI,CAAC,QAAQ,CAAC;4BAA1D,sBAAO,SAAmD,EAAC;;;;KAC9D;IACL,WAAC;AAAD,CAAC;AA3GY,oBAAI;;;;;;;;ACJjB;AACA,8CAA8C,cAAc;AAC5D;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,uCAAuC;AACvC;AACA;AACA;AACA;AACA;AACA;AACA;AACA,SAAS;AACT;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,kEAAkE,cAAc;AAChF;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,SAAS;AACT;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,CAAC;AACD;AACA,mC;;;;;;;ACzGA;AACA,8CAA8C,cAAc;AAC5D;AACA;AAC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B;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","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';\nimport { EntityData } from './src/types';\nexport {\n Service,\n requests\n}","\"use strict\";\nObject.defineProperty(exports, \"__esModule\", { value: true });\nvar service_1 = require(\"./src/service\");\nexports.Service = service_1.Service;\nvar requests_1 = require(\"./src/requests\");\nexports.requests = requests_1.requests;\n//# sourceMappingURL=index.js.map","import { ServiceBase } from './service-base';\nimport { Data } from './functions/data';\nimport { Toast } from './functions/toast';\nimport { Menu } from './functions/menu';\nexport class Service extends ServiceBase {\n\n private _data: Data;\n private _toast: Toast;\n private _menu: Menu;\n\n /**\n * Returns all data methods\n */\n public get data () {\n return this._data;\n }\n /**\n * Returns all toast methods\n */\n public get toast () {\n return this._toast;\n }\n /**\n * Returns all menu methods\n */\n public get menu () {\n return this._menu;\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 }\n\n /**\n * Provides Surix singleton\n */\n public static init() {\n if(Service.instance == undefined){\n Service.instance = new Service();\n }\n return Service.instance;\n }\n \n private static instance?: Service = undefined;\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 * 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): Promise {\n return this.rpc(type, payload);\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 protected setUpService() {\n window.addEventListener('message', event => {\n const msg: any = event.data;\n switch(msg.type) {\n case 'rpcRep':\n this.handleRpcReq(msg, this);\n break;\n case 'event':\n this.emit(msg);\n break;\n }\n });\n }\n}","import { Service } from \"../..\";\nimport { Project, FileDetails, FileParams, TagsParams, TagUpdateParams, Tag, EntityData, PersistedEntityData } from \"../types\";\nimport { requests } from \"../../build/dist\";\n\nexport class Data {\n public _service: Service;\n \n public constructor() {\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._service.request(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._service.request(requests.data.project);\n }\n\n /**\n * Returns all the entities present\n * @param query (Optional) query\n * @returns Promise\n */\n public async getEntities(query?: any): Promise {\n return await this._service.request(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._service.request(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._service.request(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._service.request(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._service.request(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._service.request(requests.data.getTags);\n }\n\n public getAppData() {\n\n }\n public updateAppData() {\n\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._service.request(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._service.request(requests.data.getFileById, id);\n }\n\n /**\n * Returns all files\n * @returns Promise\n */\n public async getFiles(): Promise{\n return await this._service.request(requests.data.getFiles);\n }\n}","\"use strict\";\nObject.defineProperty(exports, \"__esModule\", { value: true });\nvar Service = /** @class */ (function () {\n /**\n * Constructor\n */\n function Service() {\n this.prefix = '__surix__';\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 Service.prototype.request = function (type, payload) {\n return this.rpc(type, payload);\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 Service.prototype.on = function (eventName, handler) {\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 Service.prototype.sendMessage = function (msg) {\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 Service.prototype.rpc = function (name, body) {\n var _this = this;\n var reqId = Math.random();\n return new Promise(function (resolve, reject) {\n _this.rpcTracker[reqId] = { resolve: resolve, reject: reject };\n var message = {\n name: name,\n body: 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 Service.prototype.handleRpcReq = function (msg, handler) {\n if (msg.success) {\n handler.rpcTracker[msg.id].resolve(msg.body);\n }\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 Service.prototype.emit = function (msg) {\n var event = new CustomEvent(\"\" + this.prefix + msg.name, { detail: msg });\n document.dispatchEvent(event);\n };\n /**\n * Sets up Surix service\n */\n Service.prototype.setUpService = function () {\n var _this = this;\n window.addEventListener('message', function (event) {\n var msg = 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 Service.init = function () {\n if (Service.instance == undefined) {\n Service.instance = new Service();\n }\n return Service.instance;\n };\n Service.instance = undefined;\n return Service;\n}());\nexports.Service = Service;\n//# sourceMappingURL=service.js.map","\"use strict\";\nObject.defineProperty(exports, \"__esModule\", { value: true });\nexports.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 uploadFile: 'data.uploadFile',\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};\n//# sourceMappingURL=requests.js.map","import { Service } from \"../..\";\nimport { ToastParams } from \"../types\";\nimport { requests } from \"../../build/dist\";\n\nexport class Toast {\n private _service: Service;\n\n public constructor() {\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) {\n return this._service.request(requests.toast.show, message);\n }\n}","import { Service, requests } from \"../../build/dist\";\nimport { MenuItem } from \"../types\";\n\nexport class Menu {\n public _service: Service;\n\n public constructor() {\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[]) {\n return this._service.request(requests.menu.populate, menu);\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"],"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;Q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;;;4BACW,qBAAM,IAAI,CAAC,eAAe,CAAC,mBAAQ,CAAC,IAAI,CAAC,QAAQ,CAAC;4BAAzD,sBAAO,SAAkD,EAAC;;;;KAC7D;IACL,WAAC;AAAD,CAAC,CA5GyB,0BAAW,GA4GpC;AA5GY,oBAAI;;;;;;;;;;;;;;;;;;;;;;;ACfjB,wCAAuC;AACvC,4CAA8C;AAE9C;IAA2B,yBAAW;IAClC,6BAA6B;IAE7B;eACI,iBAAO;QACP,iCAAiC;IACrC,CAAC;IAED;;;OAGG;IACI,oBAAI,GAAX,UAAY,OAAoB;QAC5B,OAAO,IAAI,CAAC,eAAe,CAAC,mBAAQ,CAAC,KAAK,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC;IAC9D,CAAC;IACL,YAAC;AAAD,CAAC,CAf0B,0BAAW,GAerC;AAfY,sBAAK;;;;;;;;;;;;;;;;;;;;;;;ACJlB,wCAAuC;AAEvC,4CAA8C;AAE9C;IAA0B,wBAAW;IACjC,2BAA2B;IAE3B;eACI,iBAAO;QACP,iCAAiC;IACrC,CAAC;IAED;;;OAGG;IACI,uBAAQ,GAAf,UAAgB,IAAgB;QAC5B,OAAO,IAAI,CAAC,eAAe,CAAC,mBAAQ,CAAC,IAAI,CAAC,QAAQ,EAAE,IAAI,CAAC,CAAC;IAC9D,CAAC;IACL,WAAC;AAAD,CAAC,CAfyB,0BAAW,GAepC;AAfY,oBAAI","file":"client-service.js","sourcesContent":["(function webpackUniversalModuleDefinition(root, factory) {\n\tif(typeof exports === 'object' && typeof module === 'object')\n\t\tmodule.exports = factory();\n\telse if(typeof define === 'function' && define.amd)\n\t\tdefine(\"Surix\", [], factory);\n\telse if(typeof exports === 'object')\n\t\texports[\"Surix\"] = factory();\n\telse\n\t\troot[\"Surix\"] = factory();\n})(window, function() {\nreturn "," \t// The module cache\n \tvar installedModules = {};\n\n \t// The require function\n \tfunction __webpack_require__(moduleId) {\n\n \t\t// Check if module is in cache\n \t\tif(installedModules[moduleId]) {\n \t\t\treturn installedModules[moduleId].exports;\n \t\t}\n \t\t// Create a new module (and put it into the cache)\n \t\tvar module = installedModules[moduleId] = {\n \t\t\ti: moduleId,\n \t\t\tl: false,\n \t\t\texports: {}\n \t\t};\n\n \t\t// Execute the module function\n \t\tmodules[moduleId].call(module.exports, module, module.exports, __webpack_require__);\n\n \t\t// Flag the module as loaded\n \t\tmodule.l = true;\n\n \t\t// Return the exports of the module\n \t\treturn module.exports;\n \t}\n\n\n \t// expose the modules object (__webpack_modules__)\n \t__webpack_require__.m = modules;\n\n \t// expose the module cache\n \t__webpack_require__.c = installedModules;\n\n \t// define getter function for harmony exports\n \t__webpack_require__.d = function(exports, name, getter) {\n \t\tif(!__webpack_require__.o(exports, name)) {\n \t\t\tObject.defineProperty(exports, name, { enumerable: true, get: getter });\n \t\t}\n \t};\n\n \t// define __esModule on exports\n \t__webpack_require__.r = function(exports) {\n \t\tif(typeof Symbol !== 'undefined' && Symbol.toStringTag) {\n \t\t\tObject.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });\n \t\t}\n \t\tObject.defineProperty(exports, '__esModule', { value: true });\n \t};\n\n \t// create a fake namespace object\n \t// mode & 1: value is a module id, require it\n \t// mode & 2: merge all properties of value into the ns\n \t// mode & 4: return value when already ns object\n \t// mode & 8|1: behave like require\n \t__webpack_require__.t = function(value, mode) {\n \t\tif(mode & 1) value = __webpack_require__(value);\n \t\tif(mode & 8) return value;\n \t\tif((mode & 4) && typeof value === 'object' && value && value.__esModule) return value;\n \t\tvar ns = Object.create(null);\n \t\t__webpack_require__.r(ns);\n \t\tObject.defineProperty(ns, 'default', { enumerable: true, value: value });\n \t\tif(mode & 2 && typeof value != 'string') for(var key in value) __webpack_require__.d(ns, key, function(key) { return value[key]; }.bind(null, key));\n \t\treturn ns;\n \t};\n\n \t// getDefaultExport function for compatibility with non-harmony modules\n \t__webpack_require__.n = function(module) {\n \t\tvar getter = module && module.__esModule ?\n \t\t\tfunction getDefault() { return module['default']; } :\n \t\t\tfunction getModuleExports() { return module; };\n \t\t__webpack_require__.d(getter, 'a', getter);\n \t\treturn getter;\n \t};\n\n \t// Object.prototype.hasOwnProperty.call\n \t__webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };\n\n \t// __webpack_public_path__\n \t__webpack_require__.p = \"\";\n\n\n \t// Load entry module and return exports\n \treturn __webpack_require__(__webpack_require__.s = 2);\n","export class ServiceBase {\n private rpcTracker: any;\n private prefix: string = '__surix__';\n\n protected constructor() {\n this.rpcTracker = {};\n this.setUpService();\n }\n\n /**\n * Sends a request to Surixs\n * @param type Request type\n * @param payload Request payload\n */\n protected internalRequest(type: string, payload?: any): Promise {\n return this.rpc(type, payload);\n }\n \n /**\n * Sends a request to Surix\n * ====== TO BE DEPRICATED IN FUTURE =======\n * @param type Request type\n * @param payload Request payload \n * @returns Promise Returns a promise\n */\n public request(type: string, payload?: any): Promise {\n console.warn(`service.request method will be DEPRICATED in future. Please consider using service.${type} instead.`);\n return this.rpc(type, payload);\n }\n /**\n * 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 protected setUpService() {\n window.addEventListener('message', event => {\n const msg: any = event.data;\n switch(msg.type) {\n case 'rpcRep':\n this.handleRpcReq(msg, this);\n break;\n case 'event':\n this.emit(msg);\n break;\n }\n });\n }\n}","export const requests = {\n data: {\n createEntity: 'data.createEntity',\n project: 'data.project',\n getEntities: 'data.getEntities',\n getEntityById: 'data.getEntityById',\n addTagsToEntity: 'data.addTagsToEntity',\n removeTagsFromEntity: 'data.removeTagsFromEntity',\n getTags: 'data.getTags',\n updateTag: 'data.updateTag',\n getAppData: 'data.getAppData',\n updateAppData: 'data.updateAppData',\n createFile: 'data.createFile',\n getFileById: 'data.getFileById',\n getFiles: 'data.getFiles'\n },\n toast: {\n show: 'toast.show',\n },\n menu: {\n populate: 'menu.populate'\n },\n events: {\n menuItemClicked: 'menu-item-clicked',\n // TODO: this is for backwards compatibility\n // it is deprecated and will be removed in a future update\n menuClicked: 'menu-item-clicked'\n }\n}","import { Service } from './src/service';\nimport { requests } from './src/requests';\nimport { PersistedEntityData } from './src/types';\nexport {\n Service,\n requests\n}","import { ServiceBase } from './service-base';\nimport { Data } from './functions/data';\nimport { Toast } from './functions/toast';\nimport { Menu } from './functions/menu';\nexport class Service extends ServiceBase {\n\n private _data: Data;\n private _toast: Toast;\n private _menu: Menu;\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 * Constructor\n */\n private constructor() {\n super();\n this._data = new Data();\n this._toast = new Toast();\n this._menu = new Menu();\n }\n\n /**\n * Provides Surix singleton\n */\n public static init(): Service {\n if(Service.instance == undefined){\n Service.instance = new Service();\n }\n return Service.instance;\n }\n \n private static instance?: Service = undefined;\n}","import {\n PersistedEntityData,\n TagUpdateParams,\n FileDetails, \n FileParams, \n TagsParams,\n EntityData,\n Project,\n AppData,\n Tag,\n IData,\n PersistedAppData\n} from \"../types\";\nimport { requests } from \"../requests\";\nimport { ServiceBase } from \"../service-base\";\n\nexport class Data extends ServiceBase implements IData{\n //public _service: Service;\n \n public constructor() {\n super();\n //this._service = Service.init();\n }\n\n /**\n * Saves an entity in Surix\n * @param entity EntityData entity to be saved\n * @returns Promise\n */\n public async createEntity(entity: EntityData): Promise {\n return await this.internalRequest(requests.data.createEntity, entity);\n }\n\n /**\n * Returns the current project\n * @returns Promise\n */\n public async project(): Promise {\n return await this.internalRequest(requests.data.project);\n }\n\n /**\n * Returns all the entities present\n * @param query (Optional) query\n * @returns Promise\n */\n public async getEntities(query?: any): Promise {\n return await this.internalRequest(requests.data.getEntities, query);\n }\n\n /**\n * Returns an entity identified by the id provided\n * @param id Surix Id\n * @returns Promise\n */\n public async getEntityById(id: string): Promise {\n return await this.internalRequest(requests.data.getEntityById, id);\n }\n\n /**\n * Adds tags to an existing entity\n * @param params Parameters to add tags\n * @returns Promise\n */\n public async addTagsToEntity(params: TagsParams): Promise {\n return await this.internalRequest(requests.data.addTagsToEntity, params);\n }\n\n /**\n * Removes tags from an entity\n * @param params TagsParams tag parameters\n */\n public async removeTagsFromEntity(params: TagsParams): Promise {\n return await this.internalRequest(requests.data.removeTagsFromEntity, params);\n }\n\n /**\n * Updates tags on an existing entity\n * @param params Update params\n */\n public async updateTag(params: TagUpdateParams): Promise {\n return await this.internalRequest(requests.data.updateTag, params);\n }\n\n /**\n * Returns all the tags available\n * @returns Promise\n */\n public async getTags(): Promise {\n return await this.internalRequest(requests.data.getTags);\n }\n\n public async getAppData(): Promise {\n return await this.internalRequest(requests.data.getAppData);\n }\n public async updateAppData(appData: AppData): Promise {\n return await this.internalRequest(requests.data.updateAppData, appData);\n }\n\n /**\n * Creates a file on Surix linked to the current project.\n * @param file FileMessage message details\n * @returns Promise\n */\n public async createFile(file: FileParams): Promise {\n return await this.internalRequest(requests.data.createFile, file);\n }\n\n /**\n * Gets a file associated with the id provided\n * @param id string Surix Id\n * @returns Promise\n */\n public async getFileById(id: string): Promise {\n return await this.internalRequest(requests.data.getFileById, id);\n }\n\n /**\n * Returns all files\n * @returns Promise\n */\n public async getFiles(): Promise{\n return await this.internalRequest(requests.data.getFiles);\n }\n}","import { ToastParams, IToast } from '../types';\nimport { requests } from '../requests';\nimport { ServiceBase } from '../service-base';\n\nexport class Toast extends ServiceBase implements IToast {\n // private _service: Service;\n\n public constructor() {\n super();\n //this._service = Service.init();\n }\n\n /**\n * Displays the message provided on toast on Surix\n * @param message ToastMessage message to show on the toast\n */\n public show(message: ToastParams): Promise {\n return this.internalRequest(requests.toast.show, message);\n }\n}","import { requests } from '../requests';\nimport { MenuItem } from '../types';\nimport { ServiceBase } from '../service-base';\n\nexport class Menu extends ServiceBase{\n //public _service: Service;\n\n public constructor() {\n super();\n //this._service = Service.init();\n }\n\n /**\n * Populates Surix app menu with the provided items\n * @param menu MenuItem[] menu items\n */\n public populate(menu: MenuItem[]): Promise {\n return this.internalRequest(requests.menu.populate, menu);\n }\n}"],"sourceRoot":""} \ No newline at end of file diff --git a/dist/client-service.min.js b/dist/client-service.min.js index f2b2e0a..8824fd2 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 i=t[r]={i:r,l:!1,exports:{}};return e[r].call(i.exports,i,i.exports,n),i.l=!0,i.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 i in e)n.d(r,i,function(t){return e[t]}.bind(null,i));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(2);t.Service=r.Service;var i=n(9);t.requests=i.requests},function(e,t,n){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var r=n(5);t.Service=r.Service;var i=n(6);t.requests=i.requests},function(e,t,n){"use strict";var r=this&&this.__extends||function(){var e=function(t,n){return(e=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var n in t)t.hasOwnProperty(n)&&(e[n]=t[n])})(t,n)};return function(t,n){function r(){this.constructor=t}e(t,n),t.prototype=null===n?Object.create(n):(r.prototype=n.prototype,new r)}}();Object.defineProperty(t,"__esModule",{value:!0});var i=n(3),o=n(4),a=n(7),s=n(8),u=function(e){function t(){var t=e.call(this)||this;return t._data=new o.Data,t._toast=new a.Toast,t._menu=new s.Menu,t}return r(t,e),Object.defineProperty(t.prototype,"data",{get:function(){return this._data},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"toast",{get:function(){return this._toast},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"menu",{get:function(){return this._menu},enumerable:!0,configurable:!0}),t.init=function(){return void 0==t.instance&&(t.instance=new t),t.instance},t.instance=void 0,t}(i.ServiceBase);t.Service=u},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(i,o){n.rpcTracker[r]={resolve:i,reject:o};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}();t.ServiceBase=r},function(e,t,n){"use strict";var r=this&&this.__awaiter||function(e,t,n,r){return new(n||(n=Promise))(function(i,o){function a(e){try{u(r.next(e))}catch(e){o(e)}}function s(e){try{u(r.throw(e))}catch(e){o(e)}}function u(e){e.done?i(e.value):new n(function(t){t(e.value)}).then(a,s)}u((r=r.apply(e,t||[])).next())})},i=this&&this.__generator||function(e,t){var n,r,i,o,a={label:0,sent:function(){if(1&i[0])throw i[1];return i[1]},trys:[],ops:[]};return o={next:s(0),throw:s(1),return:s(2)},"function"==typeof Symbol&&(o[Symbol.iterator]=function(){return this}),o;function s(o){return function(s){return function(o){if(n)throw new TypeError("Generator is already executing.");for(;a;)try{if(n=1,r&&(i=2&o[0]?r.return:o[0]?r.throw||((i=r.return)&&i.call(r),0):r.next)&&!(i=i.call(r,o[1])).done)return i;switch(r=0,i&&(o=[2&o[0],i.value]),o[0]){case 0:case 1:i=o;break;case 4:return a.label++,{value:o[1],done:!1};case 5:a.label++,r=o[1],o=[0];continue;case 7:o=a.ops.pop(),a.trys.pop();continue;default:if(!(i=(i=a.trys).length>0&&i[i.length-1])&&(6===o[0]||2===o[0])){a=0;continue}if(3===o[0]&&(!i||o[1]>i[0]&&o[1]0&&o[o.length-1])&&(6===i[0]||2===i[0])){u=0;continue}if(3===i[0]&&(!o||i[1]>o[0]&&i[1] */ getTags(): Promise; - getAppData(): void; - updateAppData(): void; + getAppData(): Promise; + updateAppData(appData: AppData): Promise; /** * Creates a file on Surix linked to the current project. * @param file FileMessage message details 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/dist/src/service-base.d.ts b/dist/src/service-base.d.ts new file mode 100644 index 0000000..a24cce4 --- /dev/null +++ b/dist/src/service-base.d.ts @@ -0,0 +1,51 @@ +export declare class ServiceBase { + private rpcTracker; + private prefix; + protected constructor(); + /** + * Sends a request to Surixs + * @param type Request type + * @param payload Request payload + */ + 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; + /** + * An event listener wrapper + * @param eventName A string representing the event name + * @param handler a function that handles event + */ + on(eventName: string, handler: any): void; + /** + * Sends the specified message to Surix + * @param msg Message to send to Surix + */ + private sendMessage; + /** + * Creates a promise then sends the message + * @param name Name of the request to send to Surix + * @param body + */ + private rpc; + /** + * This handles the rpcReq type responses from Surix + * @param msg Response from Surix + * @param handler Handles the response + */ + private handleRpcReq; + /** + * Emits a custom event + * @param msg Message to be embedded to the custom event to be emitted + */ + private emit; + /** + * Sets up Surix service + */ + protected setUpService(): void; +} diff --git a/build/dist/src/service.d.ts b/dist/src/service.d.ts similarity index 100% rename from build/dist/src/service.d.ts rename to dist/src/service.d.ts diff --git a/src/types.ts b/dist/src/types.d.ts similarity index 67% rename from src/types.ts rename to dist/src/types.d.ts index 3238f0e..1587118 100644 --- a/src/types.ts +++ b/dist/src/types.d.ts @@ -33,6 +33,8 @@ export interface EntityData { export interface AppData { data: AppDataField; } + +export interface PersistedAppData extends AppData, HasTimestamps, HasId {} export interface PersistedEntityData extends HasId, HasTimestamps, EntityData {} export interface ToastParams { @@ -100,6 +102,28 @@ interface HasId { } interface HasTimestamps { -createdAt: Date; -updatedAt: Date; + createdAt: Date; + updatedAt: Date; +} + +export interface IData { + createEntity(entity: EntityData): Promise; + project(): Promise; + getEntities(query?: any): 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.d.ts b/index.d.ts new file mode 100644 index 0000000..4dc46f7 --- /dev/null +++ b/index.d.ts @@ -0,0 +1,3 @@ +import { Service } from './src/service'; +import { requests } from './src/requests'; +export { Service, requests }; diff --git a/index.ts b/index.ts index 7b27889..e6b1015 100644 --- a/index.ts +++ b/index.ts @@ -1,6 +1,6 @@ import { Service } from './src/service'; import { requests } from './src/requests'; -import { EntityData, AppData } from './src/types'; +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.d.ts b/src/functions/data.d.ts new file mode 100644 index 0000000..7b77a9c --- /dev/null +++ b/src/functions/data.d.ts @@ -0,0 +1,68 @@ +import { PersistedEntityData, TagUpdateParams, FileDetails, FileParams, TagsParams, EntityData, Project, AppData, Tag, IData, PersistedAppData } from "../types"; +import { ServiceBase } from "../service-base"; +export declare class Data extends ServiceBase implements IData { + constructor(); + /** + * Saves an entity in Surix + * @param entity EntityData entity to be saved + * @returns Promise + */ + 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?: any): 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/src/functions/data.ts b/src/functions/data.ts index e20334a..425dd66 100644 --- a/src/functions/data.ts +++ b/src/functions/data.ts @@ -1,12 +1,25 @@ -import { Service } from "../.."; -import { Project, FileDetails, FileParams, TagsParams, TagUpdateParams, Tag, EntityData, PersistedEntityData, AppData } from "../types"; -import { requests } from "../../build/dist"; +import { + PersistedEntityData, + TagUpdateParams, + FileDetails, + FileParams, + TagsParams, + EntityData, + Project, + AppData, + Tag, + IData, + PersistedAppData +} from "../types"; +import { requests } from "../requests"; +import { ServiceBase } from "../service-base"; -export class Data { - public _service: Service; +export class Data extends ServiceBase implements IData{ + //public _service: Service; public constructor() { - this._service = Service.init(); + super(); + //this._service = Service.init(); } /** @@ -15,7 +28,7 @@ export class Data { * @returns Promise */ public async createEntity(entity: EntityData): Promise { - return await this._service.request(requests.data.createEntity, entity); + return await this.internalRequest(requests.data.createEntity, entity); } /** @@ -23,7 +36,7 @@ export class Data { * @returns Promise */ public async project(): Promise { - return await this._service.request(requests.data.project); + return await this.internalRequest(requests.data.project); } /** @@ -32,7 +45,7 @@ export class Data { * @returns Promise */ public async getEntities(query?: any): Promise { - return await this._service.request(requests.data.getEntities, query); + return await this.internalRequest(requests.data.getEntities, query); } /** @@ -41,7 +54,7 @@ export class Data { * @returns Promise */ public async getEntityById(id: string): Promise { - return await this._service.request(requests.data.getEntityById, id); + return await this.internalRequest(requests.data.getEntityById, id); } /** @@ -50,7 +63,7 @@ export class Data { * @returns Promise */ public async addTagsToEntity(params: TagsParams): Promise { - return await this._service.request(requests.data.addTagsToEntity, params); + return await this.internalRequest(requests.data.addTagsToEntity, params); } /** @@ -58,7 +71,7 @@ export class Data { * @param params TagsParams tag parameters */ public async removeTagsFromEntity(params: TagsParams): Promise { - return await this._service.request(requests.data.removeTagsFromEntity, params); + return await this.internalRequest(requests.data.removeTagsFromEntity, params); } /** @@ -66,7 +79,7 @@ export class Data { * @param params Update params */ public async updateTag(params: TagUpdateParams): Promise { - return await this._service.request(requests.data.updateTag, params); + return await this.internalRequest(requests.data.updateTag, params); } /** @@ -74,14 +87,14 @@ export class Data { * @returns Promise */ public async getTags(): Promise { - return await this._service.request(requests.data.getTags); + return await this.internalRequest(requests.data.getTags); } - public async getAppData() { - return await this._service.request(requests.data.getAppData); + public async getAppData(): Promise { + return await this.internalRequest(requests.data.getAppData); } - public async updateAppData(appData: AppData) { - return await this._service.request(requests.data.updateAppData, appData); + public async updateAppData(appData: AppData): Promise { + return await this.internalRequest(requests.data.updateAppData, appData); } /** @@ -90,7 +103,7 @@ export class Data { * @returns Promise */ public async createFile(file: FileParams): Promise { - return await this._service.request(requests.data.createFile, file); + return await this.internalRequest(requests.data.createFile, file); } /** @@ -99,7 +112,7 @@ export class Data { * @returns Promise */ public async getFileById(id: string): Promise { - return await this._service.request(requests.data.getFileById, id); + return await this.internalRequest(requests.data.getFileById, id); } /** @@ -107,6 +120,6 @@ export class Data { * @returns Promise */ public async getFiles(): Promise{ - return await this._service.request(requests.data.getFiles); + return await this.internalRequest(requests.data.getFiles); } } \ No newline at end of file diff --git a/src/functions/menu.d.ts b/src/functions/menu.d.ts new file mode 100644 index 0000000..cfc931d --- /dev/null +++ b/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/src/functions/menu.ts b/src/functions/menu.ts index 5d4c1bb..79a76ad 100644 --- a/src/functions/menu.ts +++ b/src/functions/menu.ts @@ -1,18 +1,20 @@ -import { Service, requests } from "../../build/dist"; -import { MenuItem } from "../types"; +import { requests } from '../requests'; +import { MenuItem } from '../types'; +import { ServiceBase } from '../service-base'; -export class Menu { - public _service: Service; +export class Menu extends ServiceBase{ + //public _service: Service; public constructor() { - this._service = Service.init(); + super(); + //this._service = Service.init(); } /** * Populates Surix app menu with the provided items * @param menu MenuItem[] menu items */ - public populate(menu: MenuItem[]) { - return this._service.request(requests.menu.populate, menu); + public populate(menu: MenuItem[]): Promise { + return this.internalRequest(requests.menu.populate, menu); } } \ No newline at end of file diff --git a/src/functions/toast.d.ts b/src/functions/toast.d.ts new file mode 100644 index 0000000..3d1f0ad --- /dev/null +++ b/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/src/functions/toast.ts b/src/functions/toast.ts index edbd7e4..655effc 100644 --- a/src/functions/toast.ts +++ b/src/functions/toast.ts @@ -1,19 +1,20 @@ -import { Service } from "../.."; -import { ToastParams } from "../types"; -import { requests } from "../../build/dist"; +import { ToastParams, IToast } from '../types'; +import { requests } from '../requests'; +import { ServiceBase } from '../service-base'; -export class Toast { - private _service: Service; +export class Toast extends ServiceBase implements IToast { + // private _service: Service; public constructor() { - this._service = Service.init(); + 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) { - return this._service.request(requests.toast.show, message); + public show(message: ToastParams): Promise { + return this.internalRequest(requests.toast.show, message); } } \ No newline at end of file diff --git a/src/requests.d.ts b/src/requests.d.ts new file mode 100644 index 0000000..c8daaf7 --- /dev/null +++ b/src/requests.d.ts @@ -0,0 +1,27 @@ +export declare const requests: { + data: { + createEntity: string; + project: string; + getEntities: string; + getEntityById: string; + addTagsToEntity: string; + removeTagsFromEntity: string; + getTags: string; + updateTag: string; + getAppData: string; + updateAppData: string; + createFile: string; + getFileById: string; + getFiles: string; + }; + toast: { + show: string; + }; + menu: { + populate: string; + }; + events: { + menuItemClicked: string; + menuClicked: string; + }; +}; diff --git a/build/dist/src/service-base.d.ts b/src/service-base.d.ts similarity index 94% rename from build/dist/src/service-base.d.ts rename to src/service-base.d.ts index b8444d6..b6688f7 100644 --- a/build/dist/src/service-base.d.ts +++ b/src/service-base.d.ts @@ -8,7 +8,7 @@ export declare class ServiceBase { * @param payload Request payload * @returns Promise Returns a promise */ - request(type: string, payload?: any): Promise; + protected request(type: string, payload?: any): Promise; /** * An event listener wrapper * @param eventName A string representing the event name diff --git a/src/service-base.ts b/src/service-base.ts index 3a318b3..3a0cdcb 100644 --- a/src/service-base.ts +++ b/src/service-base.ts @@ -6,13 +6,25 @@ export class ServiceBase { 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); } /** @@ -61,7 +73,7 @@ export class ServiceBase { } // 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 diff --git a/src/service.d.ts b/src/service.d.ts new file mode 100644 index 0000000..95adf2e --- /dev/null +++ b/src/service.d.ts @@ -0,0 +1,30 @@ +import { ServiceBase } from './service-base'; +import { Data } from './functions/data'; +import { Toast } from './functions/toast'; +import { Menu } from './functions/menu'; +export declare class Service extends ServiceBase { + private _data; + private _toast; + private _menu; + /** + * Returns all data methods + */ + readonly data: Data; + /** + * Returns all toast methods + */ + readonly toast: Toast; + /** + * Returns all menu methods + */ + readonly menu: Menu; + /** + * Constructor + */ + private constructor(); + /** + * Provides Surix singleton + */ + static init(): Service; + private static instance?; +} diff --git a/src/service.ts b/src/service.ts index 3a55402..2836d1d 100644 --- a/src/service.ts +++ b/src/service.ts @@ -11,19 +11,19 @@ export class Service extends ServiceBase { /** * Returns all data methods */ - public get data () { + public get data (): Data { return this._data; } /** * Returns all toast methods */ - public get toast () { + public get toast (): Toast { return this._toast; } /** * Returns all menu methods */ - public get menu () { + public get menu (): Menu { return this._menu; } /** @@ -39,7 +39,7 @@ export class Service extends ServiceBase { /** * Provides Surix singleton */ - public static init() { + public static init(): Service { if(Service.instance == undefined){ Service.instance = new Service(); } diff --git a/src/types.d.ts b/src/types.d.ts new file mode 100644 index 0000000..1587118 --- /dev/null +++ b/src/types.d.ts @@ -0,0 +1,129 @@ +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 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?: any): 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, From 81a4c9e6af05df9de11f98e821301eb632a18a06 Mon Sep 17 00:00:00 2001 From: Kevin Nderitu Date: Thu, 22 Nov 2018 17:02:49 +0300 Subject: [PATCH 4/9] Added events handler --- README.md | 43 +- build/dist/index.js | 7 - build/dist/index.js.map | 1 - build/dist/src/functions/menu.d.ts | 11 - build/dist/src/functions/toast.d.ts | 10 - build/dist/src/requests.js | 30 - build/dist/src/requests.js.map | 1 - build/dist/src/service.js | 106 ---- build/dist/src/service.js.map | 1 - dist/client-service.js | 601 +++++++++---------- dist/client-service.js.map | 2 +- dist/client-service.min.js | 2 +- {build/dist => dist}/index.d.ts | 0 {build/dist => dist}/src/functions/data.d.ts | 11 +- dist/src/functions/events.d.ts | 8 + dist/src/functions/menu.d.ts | 10 + dist/src/functions/toast.d.ts | 10 + {build/dist => dist}/src/requests.d.ts | 0 dist/src/service-base.d.ts | 58 ++ dist/src/service.d.ts | 36 ++ src/types.ts => dist/src/types.d.ts | 28 +- index.d.ts | 3 + index.ts | 2 +- package.json | 5 +- src/functions/data.d.ts | 68 +++ src/functions/data.ts | 55 +- src/functions/events.ts | 13 + src/functions/menu.d.ts | 10 + src/functions/menu.ts | 16 +- src/functions/toast.d.ts | 10 + src/functions/toast.ts | 17 +- src/requests.d.ts | 27 + {build/dist/src => src}/service-base.d.ts | 2 +- src/service-base.ts | 29 +- {build/dist/src => src}/service.d.ts | 0 src/service.ts | 18 +- src/types.d.ts | 129 ++++ tsconfig.json | 2 +- 38 files changed, 824 insertions(+), 558 deletions(-) delete mode 100644 build/dist/index.js delete mode 100644 build/dist/index.js.map delete mode 100644 build/dist/src/functions/menu.d.ts delete mode 100644 build/dist/src/functions/toast.d.ts delete mode 100644 build/dist/src/requests.js delete mode 100644 build/dist/src/requests.js.map delete mode 100644 build/dist/src/service.js delete mode 100644 build/dist/src/service.js.map rename {build/dist => dist}/index.d.ts (100%) rename {build/dist => dist}/src/functions/data.d.ts (83%) create mode 100644 dist/src/functions/events.d.ts create mode 100644 dist/src/functions/menu.d.ts create mode 100644 dist/src/functions/toast.d.ts rename {build/dist => dist}/src/requests.d.ts (100%) create mode 100644 dist/src/service-base.d.ts create mode 100644 dist/src/service.d.ts rename src/types.ts => dist/src/types.d.ts (67%) create mode 100644 index.d.ts create mode 100644 src/functions/data.d.ts create mode 100644 src/functions/events.ts create mode 100644 src/functions/menu.d.ts create mode 100644 src/functions/toast.d.ts create mode 100644 src/requests.d.ts rename {build/dist/src => src}/service-base.d.ts (94%) rename {build/dist/src => src}/service.d.ts (100%) create mode 100644 src/types.d.ts diff --git a/README.md b/README.md index 65cf414..de8dd6c 100644 --- a/README.md +++ b/README.md @@ -20,9 +20,10 @@ const service = Surix.Service.init(); const requests = Surix.requests; ``` `Service` is the service itself. -`requests` contains all the request types available. -`requests.data` contains: +Service contains all the methods grouped according to their operations + +`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. @@ -37,11 +38,13 @@ const requests = Surix.requests; - `getFiles`: Queries files from the current Surix project. - `getFileById`: Gets a single file by its Surix id. -`requests.toast` contains: +`toast` contains: - `show`: Displays a message on Surix toast (expects message: string parameter). -`requests.menu` contains: +`menu` contains: - `populate`: Submits the menu items to Surix. The menu is updated immidiately (expects items: any parameter). +`on` is a function used to register events. + `requests.events` contains: - `menuItemClicked`: The event dispatched when a menu item is clicked. @@ -75,7 +78,7 @@ 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 @@ -88,7 +91,7 @@ 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 @@ -104,7 +107,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 +117,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 +135,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 +149,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 +166,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 @@ -181,7 +184,7 @@ const args = { } }; -surix.request(requests.data.updateTag, args).then(updatedTag => { +surix.data.updateTag(args).then(updatedTag => { //Tag updated successfully }).catch(error) => { //Error @@ -190,7 +193,7 @@ surix.request(requests.data.updateTag, args).then(updatedTag => { ### Get all tags in the project ```javascript -service.request(requests.data.getTags).then((tags) => { +service.data.getTags().then((tags) => { // Do something with the tags }).catch((err) => { // handle error @@ -208,7 +211,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 +220,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 +241,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 +259,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 +270,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,7 +282,7 @@ 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 @@ -305,5 +308,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/functions/menu.d.ts b/build/dist/src/functions/menu.d.ts deleted file mode 100644 index 5740206..0000000 --- a/build/dist/src/functions/menu.d.ts +++ /dev/null @@ -1,11 +0,0 @@ -import { Service } from "../../build/dist"; -import { MenuItem } from "../types"; -export declare class Menu { - _service: Service; - constructor(); - /** - * Populates Surix app menu with the provided items - * @param menu MenuItem[] menu items - */ - populate(menu: MenuItem[]): Promise<{}>; -} diff --git a/build/dist/src/functions/toast.d.ts b/build/dist/src/functions/toast.d.ts deleted file mode 100644 index 831dc4d..0000000 --- a/build/dist/src/functions/toast.d.ts +++ /dev/null @@ -1,10 +0,0 @@ -import { ToastParams } from "../types"; -export declare class Toast { - private _service; - 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.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/service.js.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"service.js","sourceRoot":"","sources":["../../../src/service.ts"],"names":[],"mappings":";;AACA;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,UAAU,SAAiB,EAAE,OAAY;QACrC,QAAQ,CAAC,gBAAgB,CAAC,KAAG,IAAI,CAAC,MAAM,GAAG,SAAW,EAAE,OAAO,CAAC,CAAC;IACrE,CAAC;IACD;;;OAGG;IACK,6BAAW,GAAnB,UAAoB,GAAQ;QACxB,MAAM,CAAC,MAAM,CAAC,WAAW,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC;IACxC,CAAC;IACD;;;;OAIG;IACK,qBAAG,GAAX,UAAY,IAAY,EAAE,IAAS;QAAnC,iBAYC;QAXG,IAAM,KAAK,GAAG,IAAI,CAAC,MAAM,EAAE,CAAC;QAC5B,OAAO,IAAI,OAAO,CAAC,UAAC,OAAO,EAAE,MAAM;YAC/B,KAAI,CAAC,UAAU,CAAC,KAAK,CAAC,GAAG,EAAE,OAAO,SAAA,EAAE,MAAM,QAAA,EAAE,CAAC;YAC7C,IAAM,OAAO,GAAG;gBACZ,IAAI,MAAA;gBACJ,IAAI,MAAA;gBACJ,IAAI,EAAE,QAAQ;gBACd,EAAE,EAAE,KAAK;aACZ,CAAA;YACD,KAAI,CAAC,WAAW,CAAC,OAAO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AC5B,CAAC;IAlGc,gBAAQ,GAAa,SAAS,CAAC;IAmGlD,cAAC;CAAA,AArGD,IAqGC;AArGY,0BAAO"} \ No newline at end of file diff --git a/dist/client-service.js b/dist/client-service.js index 9073c58..f9a15b9 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); /******/ }) /************************************************************************/ /******/ ([ @@ -100,113 +100,6 @@ return /******/ (function(modules) { // webpackBootstrap "use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); -var service_1 = __webpack_require__(2); -exports.Service = service_1.Service; -var requests_1 = __webpack_require__(9); -exports.requests = requests_1.requests; - - -/***/ }), -/* 1 */ -/***/ (function(module, exports, __webpack_require__) { - -"use strict"; - -Object.defineProperty(exports, "__esModule", { value: true }); -var service_1 = __webpack_require__(5); -exports.Service = service_1.Service; -var requests_1 = __webpack_require__(6); -exports.requests = requests_1.requests; -//# sourceMappingURL=index.js.map - -/***/ }), -/* 2 */ -/***/ (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__(3); -var data_1 = __webpack_require__(4); -var toast_1 = __webpack_require__(7); -var menu_1 = __webpack_require__(8); -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(); - 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 - }); - /** - * 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; - - -/***/ }), -/* 3 */ -/***/ (function(module, exports, __webpack_require__) { - -"use strict"; - Object.defineProperty(exports, "__esModule", { value: true }); var ServiceBase = /** @class */ (function () { function ServiceBase() { @@ -214,13 +107,23 @@ var ServiceBase = /** @class */ (function () { 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 */ 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); }; /** @@ -228,7 +131,17 @@ var ServiceBase = /** @class */ (function () { * @param eventName A string representing the event name * @param handler a function that handles event */ + 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); }; /** @@ -271,7 +184,7 @@ var ServiceBase = /** @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 @@ -303,12 +216,169 @@ var ServiceBase = /** @class */ (function () { exports.ServiceBase = ServiceBase; +/***/ }), +/* 1 */ +/***/ (function(module, exports, __webpack_require__) { + +"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', + createFile: 'data.createFile', + getFileById: 'data.getFileById', + getFiles: 'data.getFiles' + }, + 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' + } +}; + + +/***/ }), +/* 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); } } @@ -345,11 +415,14 @@ var __generator = (this && this.__generator) || function (thisArg, body) { } }; Object.defineProperty(exports, "__esModule", { value: true }); -var __1 = __webpack_require__(0); -var dist_1 = __webpack_require__(1); -var Data = /** @class */ (function () { +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() { - this._service = __1.Service.init(); + return _super.call(this) || this; + //this._service = Service.init(); } /** * Saves an entity in Surix @@ -360,7 +433,7 @@ var Data = /** @class */ (function () { return __awaiter(this, void 0, void 0, function () { return __generator(this, function (_a) { switch (_a.label) { - case 0: return [4 /*yield*/, this._service.request(dist_1.requests.data.createEntity, entity)]; + case 0: return [4 /*yield*/, this.internalRequest(requests_1.requests.data.createEntity, entity)]; case 1: return [2 /*return*/, _a.sent()]; } }); @@ -374,7 +447,7 @@ var Data = /** @class */ (function () { return __awaiter(this, void 0, void 0, function () { return __generator(this, function (_a) { switch (_a.label) { - case 0: return [4 /*yield*/, this._service.request(dist_1.requests.data.project)]; + case 0: return [4 /*yield*/, this.internalRequest(requests_1.requests.data.project)]; case 1: return [2 /*return*/, _a.sent()]; } }); @@ -389,7 +462,7 @@ var Data = /** @class */ (function () { return __awaiter(this, void 0, void 0, function () { return __generator(this, function (_a) { switch (_a.label) { - case 0: return [4 /*yield*/, this._service.request(dist_1.requests.data.getEntities, query)]; + case 0: return [4 /*yield*/, this.internalRequest(requests_1.requests.data.getEntities, query)]; case 1: return [2 /*return*/, _a.sent()]; } }); @@ -404,7 +477,7 @@ var Data = /** @class */ (function () { return __awaiter(this, void 0, void 0, function () { return __generator(this, function (_a) { switch (_a.label) { - case 0: return [4 /*yield*/, this._service.request(dist_1.requests.data.getEntityById, id)]; + case 0: return [4 /*yield*/, this.internalRequest(requests_1.requests.data.getEntityById, id)]; case 1: return [2 /*return*/, _a.sent()]; } }); @@ -419,7 +492,7 @@ var Data = /** @class */ (function () { return __awaiter(this, void 0, void 0, function () { return __generator(this, function (_a) { switch (_a.label) { - case 0: return [4 /*yield*/, this._service.request(dist_1.requests.data.addTagsToEntity, params)]; + case 0: return [4 /*yield*/, this.internalRequest(requests_1.requests.data.addTagsToEntity, params)]; case 1: return [2 /*return*/, _a.sent()]; } }); @@ -433,7 +506,7 @@ var Data = /** @class */ (function () { return __awaiter(this, void 0, void 0, function () { return __generator(this, function (_a) { switch (_a.label) { - case 0: return [4 /*yield*/, this._service.request(dist_1.requests.data.removeTagsFromEntity, params)]; + case 0: return [4 /*yield*/, this.internalRequest(requests_1.requests.data.removeTagsFromEntity, params)]; case 1: return [2 /*return*/, _a.sent()]; } }); @@ -447,7 +520,7 @@ var Data = /** @class */ (function () { return __awaiter(this, void 0, void 0, function () { return __generator(this, function (_a) { switch (_a.label) { - case 0: return [4 /*yield*/, this._service.request(dist_1.requests.data.updateTag, params)]; + case 0: return [4 /*yield*/, this.internalRequest(requests_1.requests.data.updateTag, params)]; case 1: return [2 /*return*/, _a.sent()]; } }); @@ -461,15 +534,31 @@ var Data = /** @class */ (function () { return __awaiter(this, void 0, void 0, function () { return __generator(this, function (_a) { switch (_a.label) { - case 0: return [4 /*yield*/, this._service.request(dist_1.requests.data.getTags)]; + 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 () { + 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. @@ -480,7 +569,7 @@ var Data = /** @class */ (function () { return __awaiter(this, void 0, void 0, function () { return __generator(this, function (_a) { switch (_a.label) { - case 0: return [4 /*yield*/, this._service.request(dist_1.requests.data.createFile, file)]; + case 0: return [4 /*yield*/, this.internalRequest(requests_1.requests.data.createFile, file)]; case 1: return [2 /*return*/, _a.sent()]; } }); @@ -495,7 +584,7 @@ var Data = /** @class */ (function () { return __awaiter(this, void 0, void 0, function () { return __generator(this, function (_a) { switch (_a.label) { - case 0: return [4 /*yield*/, this._service.request(dist_1.requests.data.getFileById, id)]; + case 0: return [4 /*yield*/, this.internalRequest(requests_1.requests.data.getFileById, id)]; case 1: return [2 /*return*/, _a.sent()]; } }); @@ -509,14 +598,14 @@ var Data = /** @class */ (function () { return __awaiter(this, void 0, void 0, function () { return __generator(this, function (_a) { switch (_a.label) { - case 0: return [4 /*yield*/, this._service.request(dist_1.requests.data.getFiles)]; + 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; @@ -526,233 +615,119 @@ exports.Data = Data; "use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); -var Service = /** @class */ (function () { - /** - * Constructor - */ - function Service() { - this.prefix = '__surix__'; - this.rpcTracker = {}; - this.setUpService(); +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); } - /** - * 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; + return function (d, b) { + extendStatics(d, b); + function __() { this.constructor = d; } + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); }; - Service.instance = undefined; - return Service; -}()); -exports.Service = Service; -//# sourceMappingURL=service.js.map - -/***/ }), -/* 6 */ -/***/ (function(module, exports, __webpack_require__) { - -"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 - -/***/ }), -/* 7 */ -/***/ (function(module, exports, __webpack_require__) { - -"use strict"; - +})(); Object.defineProperty(exports, "__esModule", { value: true }); -var __1 = __webpack_require__(0); -var dist_1 = __webpack_require__(1); -var Toast = /** @class */ (function () { +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() { - this._service = __1.Service.init(); + 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._service.request(dist_1.requests.toast.show, message); + return this.internalRequest(requests_1.requests.toast.show, message); }; return Toast; -}()); +}(service_base_1.ServiceBase)); exports.Toast = Toast; /***/ }), -/* 8 */ +/* 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 dist_1 = __webpack_require__(1); -var Menu = /** @class */ (function () { +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() { - this._service = dist_1.Service.init(); + 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._service.request(dist_1.requests.menu.populate, menu); + return this.internalRequest(requests_1.requests.menu.populate, menu); }; return Menu; -}()); +}(service_base_1.ServiceBase)); exports.Menu = Menu; /***/ }), -/* 9 */ +/* 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 }); -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', - createFile: 'data.createFile', - getFileById: 'data.getFileById', - getFiles: 'data.getFiles' - }, - 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' +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 0d94cba..800f40e 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/./build/dist/index.js","webpack://Surix/./src/service.ts","webpack://Surix/./src/service-base.ts","webpack://Surix/./src/functions/data.ts","webpack://Surix/./build/dist/src/service.js","webpack://Surix/./build/dist/src/requests.js","webpack://Surix/./src/functions/toast.ts","webpack://Surix/./src/functions/menu.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;AAIpC,kBAJK,iBAAO,CAIL;AAHX,wCAA0C;AAItC,mBAJK,mBAAQ,CAIL;;;;;;;;ACLZ;AACA,8CAA8C,cAAc;AAC5D;AACA;AACA;AACA;AACA,iC;;;;;;;;;;;;;;;;;;;;;;ACNA,4CAA6C;AAC7C,oCAAwC;AACxC,qCAA0C;AAC1C,oCAAwC;AACxC;IAA6B,2BAAW;IAwBpC;;OAEG;IACH;QAAA,YACI,iBAAO,SAIV;QAHG,KAAI,CAAC,KAAK,GAAG,IAAI,WAAI,EAAE,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Q,CAAC,OAAO,CAAC,eAAQ,CAAC,IAAI,CAAC,QAAQ,CAAC;4BAA1D,sBAAO,SAAmD,EAAC;;;;KAC9D;IACL,WAAC;AAAD,CAAC;AA3GY,oBAAI;;;;;;;;ACJjB;AACA,8CAA8C,cAAc;AAC5D;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,uCAAuC;AACvC;AACA;AACA;AACA;AACA;AACA;AACA;AACA,SAAS;AACT;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,kEAAkE,cAAc;AAChF;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,SAAS;AACT;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,CAAC;AACD;AACA,mC;;;;;;;ACzGA;AACA,8CAA8C,cAAc;AAC5D;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,KAAK;AACL;AACA;AACA,KAAK;AACL;AACA;AACA,KAAK;AACL;AACA;AACA;AACA;AACA;AACA;AACA;AACA,oC;;;;;;;;;AC7BA,iCAAgC;AAEhC,oCAA4C;AAE5C;IAGI;QACI,IAAI,CAAC,QAAQ,GAAG,WAAO,CAAC,IAAI,EAAE,CAAC;IACnC,CAAC;IAED;;;OAGG;IACI,oBAAI,GAAX,UAAY,OAAoB;QAC5B,OAAO,IAAI,CAAC,QAAQ,CAAC,OAAO,CAAC,eAAQ,CAAC,KAAK,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC;IAC/D,CAAC;IACL,YAAC;AAAD,CAAC;AAdY,sBAAK;;;;;;;;;;ACJlB,oCAAqD;AAGrD;IAGI;QACI,IAAI,CAAC,QAAQ,GAAG,cAAO,CAAC,IAAI,EAAE,CAAC;IACnC,CAAC;IAED;;;OAGG;IACI,uBAAQ,GAAf,UAAgB,IAAgB;QAC5B,OAAO,IAAI,CAAC,QAAQ,CAAC,OAAO,CAAC,eAAQ,CAAC,IAAI,CAAC,QAAQ,EAAE,IAAI,CAAC,CAAC;IAC/D,CAAC;IACL,WAAC;AAAD,CAAC;AAdY,oBAAI;;;;;;;;;;ACHJ,gBAAQ,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;QAC7B,WAAW,EAAE,kBAAkB;QAC/B,QAAQ,EAAE,eAAe;KAC5B;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","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';\nimport { EntityData } from './src/types';\nexport {\n Service,\n requests\n}","\"use strict\";\nObject.defineProperty(exports, \"__esModule\", { value: true });\nvar service_1 = require(\"./src/service\");\nexports.Service = service_1.Service;\nvar requests_1 = require(\"./src/requests\");\nexports.requests = requests_1.requests;\n//# sourceMappingURL=index.js.map","import { ServiceBase } from './service-base';\nimport { Data } from './functions/data';\nimport { Toast } from './functions/toast';\nimport { Menu } from './functions/menu';\nexport class Service extends ServiceBase {\n\n private _data: Data;\n private _toast: Toast;\n private _menu: Menu;\n\n /**\n * Returns all data methods\n */\n public get data () {\n return this._data;\n }\n /**\n * Returns all toast methods\n */\n public get toast () {\n return this._toast;\n }\n /**\n * Returns all menu methods\n */\n public get menu () {\n return this._menu;\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 }\n\n /**\n * Provides Surix singleton\n */\n public static init() {\n if(Service.instance == undefined){\n Service.instance = new Service();\n }\n return Service.instance;\n }\n \n private static instance?: Service = undefined;\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 * 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): Promise {\n return this.rpc(type, payload);\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 protected setUpService() {\n window.addEventListener('message', event => {\n const msg: any = event.data;\n switch(msg.type) {\n case 'rpcRep':\n this.handleRpcReq(msg, this);\n break;\n case 'event':\n this.emit(msg);\n break;\n }\n });\n }\n}","import { Service } from \"../..\";\nimport { Project, FileDetails, FileParams, TagsParams, TagUpdateParams, Tag, EntityData, PersistedEntityData } from \"../types\";\nimport { requests } from \"../../build/dist\";\n\nexport class Data {\n public _service: Service;\n \n public constructor() {\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._service.request(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._service.request(requests.data.project);\n }\n\n /**\n * Returns all the entities present\n * @param query (Optional) query\n * @returns Promise\n */\n public async getEntities(query?: any): Promise {\n return await this._service.request(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._service.request(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._service.request(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._service.request(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._service.request(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._service.request(requests.data.getTags);\n }\n\n public getAppData() {\n\n }\n public updateAppData() {\n\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._service.request(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._service.request(requests.data.getFileById, id);\n }\n\n /**\n * Returns all files\n * @returns Promise\n */\n public async getFiles(): Promise{\n return await this._service.request(requests.data.getFiles);\n }\n}","\"use strict\";\nObject.defineProperty(exports, \"__esModule\", { value: true });\nvar Service = /** @class */ (function () {\n /**\n * Constructor\n */\n function Service() {\n this.prefix = '__surix__';\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 Service.prototype.request = function (type, payload) {\n return this.rpc(type, payload);\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 Service.prototype.on = function (eventName, handler) {\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 Service.prototype.sendMessage = function (msg) {\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 Service.prototype.rpc = function (name, body) {\n var _this = this;\n var reqId = Math.random();\n return new Promise(function (resolve, reject) {\n _this.rpcTracker[reqId] = { resolve: resolve, reject: reject };\n var message = {\n name: name,\n body: 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 Service.prototype.handleRpcReq = function (msg, handler) {\n if (msg.success) {\n handler.rpcTracker[msg.id].resolve(msg.body);\n }\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 Service.prototype.emit = function (msg) {\n var event = new CustomEvent(\"\" + this.prefix + msg.name, { detail: msg });\n document.dispatchEvent(event);\n };\n /**\n * Sets up Surix service\n */\n Service.prototype.setUpService = function () {\n var _this = this;\n window.addEventListener('message', function (event) {\n var msg = 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 Service.init = function () {\n if (Service.instance == undefined) {\n Service.instance = new Service();\n }\n return Service.instance;\n };\n Service.instance = undefined;\n return Service;\n}());\nexports.Service = Service;\n//# sourceMappingURL=service.js.map","\"use strict\";\nObject.defineProperty(exports, \"__esModule\", { value: true });\nexports.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 uploadFile: 'data.uploadFile',\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};\n//# sourceMappingURL=requests.js.map","import { Service } from \"../..\";\nimport { ToastParams } from \"../types\";\nimport { requests } from \"../../build/dist\";\n\nexport class Toast {\n private _service: Service;\n\n public constructor() {\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) {\n return this._service.request(requests.toast.show, message);\n }\n}","import { Service, requests } from \"../../build/dist\";\nimport { MenuItem } from \"../types\";\n\nexport class Menu {\n public _service: Service;\n\n public constructor() {\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[]) {\n return this._service.request(requests.menu.populate, menu);\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,GAAG,CAAC,IAAI,EAAE,OAAO,CAAC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BAAQ,CAAC,IAAI,CAAC,QAAQ,CAAC;4BAAzD,sBAAO,SAAkD,EAAC;;;;KAC7D;IACL,WAAC;AAAD,CAAC,CA5GyB,0BAAW,GA4GpC;AA5GY,oBAAI;;;;;;;;;;;;;;;;;;;;;;;ACfjB,wCAAuC;AACvC,4CAA8C;AAE9C;IAA2B,yBAAW;IAClC,6BAA6B;IAE7B;eACI,iBAAO;QACP,iCAAiC;IACrC,CAAC;IAED;;;OAGG;IACI,oBAAI,GAAX,UAAY,OAAoB;QAC5B,OAAO,IAAI,CAAC,eAAe,CAAC,mBAAQ,CAAC,KAAK,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC;IAC9D,CAAC;IACL,YAAC;AAAD,CAAC,CAf0B,0BAAW,GAerC;AAfY,sBAAK;;;;;;;;;;;;;;;;;;;;;;;ACJlB,wCAAuC;AAEvC,4CAA8C;AAE9C;IAA0B,wBAAW;IACjC,2BAA2B;IAE3B;eACI,iBAAO;QACP,iCAAiC;IACrC,CAAC;IAED;;;OAGG;IACI,uBAAQ,GAAf,UAAgB,IAAgB;QAC5B,OAAO,IAAI,CAAC,eAAe,CAAC,mBAAQ,CAAC,IAAI,CAAC,QAAQ,EAAE,IAAI,CAAC,CAAC;IAC9D,CAAC;IACL,WAAC;AAAD,CAAC,CAfyB,0BAAW,GAepC;AAfY,oBAAI;;;;;;;;;;;;;;;;;;;;;;;ACJjB,4CAA8C;AAC9C,iCAAiC;AAEjC;IAA4B,0BAAW;IAAvC;;IASA,CAAC;IAPG;;;OAGG;IACI,gCAAe,GAAtB,UAAuB,OAA4B;QAC/C,IAAI,CAAC,UAAU,CAAC,YAAQ,CAAC,MAAM,CAAC,eAAe,EAAE,OAAO,CAAC,CAAC;IAC9D,CAAC;IACL,aAAC;AAAD,CAAC,CAT2B,0BAAW,GAStC;AATY,wBAAM","file":"client-service.js","sourcesContent":["(function webpackUniversalModuleDefinition(root, factory) {\n\tif(typeof exports === 'object' && typeof module === 'object')\n\t\tmodule.exports = factory();\n\telse if(typeof define === 'function' && define.amd)\n\t\tdefine(\"Surix\", [], factory);\n\telse if(typeof exports === 'object')\n\t\texports[\"Surix\"] = factory();\n\telse\n\t\troot[\"Surix\"] = factory();\n})(window, function() {\nreturn "," \t// The module cache\n \tvar installedModules = {};\n\n \t// The require function\n \tfunction __webpack_require__(moduleId) {\n\n \t\t// Check if module is in cache\n \t\tif(installedModules[moduleId]) {\n \t\t\treturn installedModules[moduleId].exports;\n \t\t}\n \t\t// Create a new module (and put it into the cache)\n \t\tvar module = installedModules[moduleId] = {\n \t\t\ti: moduleId,\n \t\t\tl: false,\n \t\t\texports: {}\n \t\t};\n\n \t\t// Execute the module function\n \t\tmodules[moduleId].call(module.exports, module, module.exports, __webpack_require__);\n\n \t\t// Flag the module as loaded\n \t\tmodule.l = true;\n\n \t\t// Return the exports of the module\n \t\treturn module.exports;\n \t}\n\n\n \t// expose the modules object (__webpack_modules__)\n \t__webpack_require__.m = modules;\n\n \t// expose the module cache\n \t__webpack_require__.c = installedModules;\n\n \t// define getter function for harmony exports\n \t__webpack_require__.d = function(exports, name, getter) {\n \t\tif(!__webpack_require__.o(exports, name)) {\n \t\t\tObject.defineProperty(exports, name, { enumerable: true, get: getter });\n \t\t}\n \t};\n\n \t// define __esModule on exports\n \t__webpack_require__.r = function(exports) {\n \t\tif(typeof Symbol !== 'undefined' && Symbol.toStringTag) {\n \t\t\tObject.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });\n \t\t}\n \t\tObject.defineProperty(exports, '__esModule', { value: true });\n \t};\n\n \t// create a fake namespace object\n \t// mode & 1: value is a module id, require it\n \t// mode & 2: merge all properties of value into the ns\n \t// mode & 4: return value when already ns object\n \t// mode & 8|1: behave like require\n \t__webpack_require__.t = function(value, mode) {\n \t\tif(mode & 1) value = __webpack_require__(value);\n \t\tif(mode & 8) return value;\n \t\tif((mode & 4) && typeof value === 'object' && value && value.__esModule) return value;\n \t\tvar ns = Object.create(null);\n \t\t__webpack_require__.r(ns);\n \t\tObject.defineProperty(ns, 'default', { enumerable: true, value: value });\n \t\tif(mode & 2 && typeof value != 'string') for(var key in value) __webpack_require__.d(ns, key, function(key) { return value[key]; }.bind(null, key));\n \t\treturn ns;\n \t};\n\n \t// getDefaultExport function for compatibility with non-harmony modules\n \t__webpack_require__.n = function(module) {\n \t\tvar getter = module && module.__esModule ?\n \t\t\tfunction getDefault() { return module['default']; } :\n \t\t\tfunction getModuleExports() { return module; };\n \t\t__webpack_require__.d(getter, 'a', getter);\n \t\treturn getter;\n \t};\n\n \t// Object.prototype.hasOwnProperty.call\n \t__webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };\n\n \t// __webpack_public_path__\n \t__webpack_require__.p = \"\";\n\n\n \t// Load entry module and return exports\n \treturn __webpack_require__(__webpack_require__.s = 2);\n","export class ServiceBase {\n private rpcTracker: any;\n private prefix: string = '__surix__';\n\n protected constructor() {\n this.rpcTracker = {};\n this.setUpService();\n }\n\n /**\n * Sends a request to Surixs\n * @param type Request type\n * @param payload Request payload\n */\n protected internalRequest(type: string, payload?: any): Promise {\n return this.rpc(type, payload);\n }\n \n /**\n * Sends a request to Surix \n * ====== TO BE DEPRICATED IN FUTURE =======\n * @param type Request type\n * @param payload Request payload \n * @returns Promise Returns a promise\n */\n public request(type: string, payload?: any): Promise {\n console.warn(`service.request method will be DEPRICATED in future. Please consider using service.${type} instead.`);\n return this.rpc(type, payload);\n }\n\n /**\n * An event listener wrapper \n * @param eventName A string representing the event name\n * @param handler a function that handles event\n */\n public internalOn(eventName: string, handler: any) {\n document.addEventListener(`${this.prefix}${eventName}`, handler);\n }\n\n /**\n * An event listener wrapper \n * ======== TO BE DEPRICATED IN FUTURE ============\n * @param eventName A string representing the event name\n * @param handler a function that handles event\n */\n public on(eventName: string, handler: any) {\n console.warn(`service.on method will be DEPRICATED in future. Please consider using service.events.${eventName} instead.`);\n document.addEventListener(`${this.prefix}${eventName}`, handler);\n }\n\n /**\n * Sends the specified message to Surix\n * @param msg Message to send to Surix\n */\n private sendMessage(msg: any) {\n window.parent.postMessage(msg, '*');\n }\n /**\n * Creates a promise then sends the message\n * @param name Name of the request to send to Surix\n * @param body \n */\n private rpc(name: string, body: any) {\n const reqId = Math.random();\n return new Promise((resolve, reject) => {\n this.rpcTracker[reqId] = { resolve, reject };\n const message = {\n name, \n body, \n type: 'rpcReq', \n id: reqId\n }\n this.sendMessage(message);\n });\n }\n /**\n * This handles the rpcReq type responses from Surix\n * @param msg Response from Surix\n * @param handler Handles the response\n */\n private handleRpcReq(msg: any, handler: any) {\n if(msg.success) {\n handler.rpcTracker[msg.id].resolve(msg.body);\n } else {\n handler.rpcTracker[msg.id].reject(msg.body);\n }\n // Remove the promise from the handler because \n // it has already been taken care of.\n delete handler.rpcTracker[msg.id];\n }\n /**\n * Emits a custom event\n * @param msg Message to be embedded to the custom event to be emitted\n */\n private emit(msg: any) {\n const event: Event = new CustomEvent(`${this.prefix}${msg.name}`, {detail: msg});\n document.dispatchEvent(event);\n }\n /**\n * Sets up Surix service\n */\n protected setUpService() {\n window.addEventListener('message', event => {\n const msg: any = event.data;\n switch(msg.type) {\n case 'rpcRep':\n this.handleRpcReq(msg, this);\n break;\n case 'event':\n this.emit(msg);\n break;\n }\n });\n }\n}","export const requests = {\n data: {\n createEntity: 'data.createEntity',\n project: 'data.project',\n getEntities: 'data.getEntities',\n getEntityById: 'data.getEntityById',\n addTagsToEntity: 'data.addTagsToEntity',\n removeTagsFromEntity: 'data.removeTagsFromEntity',\n getTags: 'data.getTags',\n updateTag: 'data.updateTag',\n getAppData: 'data.getAppData',\n updateAppData: 'data.updateAppData',\n createFile: 'data.createFile',\n getFileById: 'data.getFileById',\n getFiles: 'data.getFiles'\n },\n toast: {\n show: 'toast.show',\n },\n menu: {\n populate: 'menu.populate'\n },\n events: {\n menuItemClicked: 'menu-item-clicked',\n // TODO: this is for backwards compatibility\n // it is deprecated and will be removed in a future update\n menuClicked: 'menu-item-clicked'\n }\n}","import { Service } from './src/service';\nimport { requests } from './src/requests';\nimport { PersistedEntityData } from './src/types';\nexport {\n Service,\n requests\n}","import { ServiceBase } from './service-base';\nimport { Data } from './functions/data';\nimport { Toast } from './functions/toast';\nimport { Menu } from './functions/menu';\nimport { Events } from './functions/events';\nexport class Service extends ServiceBase {\n\n private _data: Data;\n private _toast: Toast;\n private _menu: Menu;\n private _events: Events;\n\n /**\n * Returns all data methods\n */\n public get data (): Data {\n return this._data;\n }\n /**\n * Returns all toast methods\n */\n public get toast (): Toast {\n return this._toast;\n }\n /**\n * Returns all menu methods\n */\n public get menu (): Menu {\n return this._menu;\n }\n\n /**\n * Returns all methods associated with events.\n */\n public get events (): Events {\n return this._events;\n }\n /**\n * Constructor\n */\n private constructor() {\n super();\n this._data = new Data();\n this._toast = new Toast();\n this._menu = new Menu();\n this._events = new Events();\n }\n\n /**\n * Provides Surix singleton\n */\n public static init(): Service {\n if(Service.instance == undefined){\n Service.instance = new Service();\n }\n return Service.instance;\n }\n \n private static instance?: Service = undefined;\n}","import {\n PersistedEntityData,\n TagUpdateParams,\n FileDetails, \n FileParams, \n TagsParams,\n EntityData,\n Project,\n AppData,\n Tag,\n IData,\n PersistedAppData\n} from \"../types\";\nimport { requests } from \"../requests\";\nimport { ServiceBase } from \"../service-base\";\n\nexport class Data extends ServiceBase implements IData{\n //public _service: Service;\n \n public constructor() {\n super();\n //this._service = Service.init();\n }\n\n /**\n * Saves an entity in Surix\n * @param entity EntityData entity to be saved\n * @returns Promise\n */\n public async createEntity(entity: EntityData): Promise {\n return await this.internalRequest(requests.data.createEntity, entity);\n }\n\n /**\n * Returns the current project\n * @returns Promise\n */\n public async project(): Promise {\n return await this.internalRequest(requests.data.project);\n }\n\n /**\n * Returns all the entities present\n * @param query (Optional) query\n * @returns Promise\n */\n public async getEntities(query?: any): Promise {\n return await this.internalRequest(requests.data.getEntities, query);\n }\n\n /**\n * Returns an entity identified by the id provided\n * @param id Surix Id\n * @returns Promise\n */\n public async getEntityById(id: string): Promise {\n return await this.internalRequest(requests.data.getEntityById, id);\n }\n\n /**\n * Adds tags to an existing entity\n * @param params Parameters to add tags\n * @returns Promise\n */\n public async addTagsToEntity(params: TagsParams): Promise {\n return await this.internalRequest(requests.data.addTagsToEntity, params);\n }\n\n /**\n * Removes tags from an entity\n * @param params TagsParams tag parameters\n */\n public async removeTagsFromEntity(params: TagsParams): Promise {\n return await this.internalRequest(requests.data.removeTagsFromEntity, params);\n }\n\n /**\n * Updates tags on an existing entity\n * @param params Update params\n */\n public async updateTag(params: TagUpdateParams): Promise {\n return await this.internalRequest(requests.data.updateTag, params);\n }\n\n /**\n * Returns all the tags available\n * @returns Promise\n */\n public async getTags(): Promise {\n return await this.internalRequest(requests.data.getTags);\n }\n\n public async getAppData(): Promise {\n return await this.internalRequest(requests.data.getAppData);\n }\n public async updateAppData(appData: AppData): Promise {\n return await this.internalRequest(requests.data.updateAppData, appData);\n }\n\n /**\n * Creates a file on Surix linked to the current project.\n * @param file FileMessage message details\n * @returns Promise\n */\n public async createFile(file: FileParams): Promise {\n return await this.internalRequest(requests.data.createFile, file);\n }\n\n /**\n * Gets a file associated with the id provided\n * @param id string Surix Id\n * @returns Promise\n */\n public async getFileById(id: string): Promise {\n return await this.internalRequest(requests.data.getFileById, id);\n }\n\n /**\n * Returns all files\n * @returns Promise\n */\n public async getFiles(): Promise{\n return await this.internalRequest(requests.data.getFiles);\n }\n}","import { ToastParams, IToast } from '../types';\nimport { requests } from '../requests';\nimport { ServiceBase } from '../service-base';\n\nexport class Toast extends ServiceBase implements IToast {\n // private _service: Service;\n\n public constructor() {\n super();\n //this._service = Service.init();\n }\n\n /**\n * Displays the message provided on toast on Surix\n * @param message ToastMessage message to show on the toast\n */\n public show(message: ToastParams): Promise {\n return this.internalRequest(requests.toast.show, message);\n }\n}","import { requests } from '../requests';\nimport { MenuItem } from '../types';\nimport { ServiceBase } from '../service-base';\n\nexport class Menu extends ServiceBase{\n //public _service: Service;\n\n public constructor() {\n super();\n //this._service = Service.init();\n }\n\n /**\n * Populates Surix app menu with the provided items\n * @param menu MenuItem[] menu items\n */\n public populate(menu: MenuItem[]): Promise {\n return this.internalRequest(requests.menu.populate, menu);\n }\n}","import { ServiceBase } from \"../service-base\";\nimport { requests } from \"../..\";\n\nexport class Events extends ServiceBase {\n\n /**\n * Registers an event onto the handler provided.\n * @param handler Function to handle events\n */\n public menuItemClicked(handler: (event: any) => any) {\n this.internalOn(requests.events.menuItemClicked, handler);\n }\n}"],"sourceRoot":""} \ No newline at end of file diff --git a/dist/client-service.min.js b/dist/client-service.min.js index f2b2e0a..95ba434 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 i=t[r]={i:r,l:!1,exports:{}};return e[r].call(i.exports,i,i.exports,n),i.l=!0,i.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 i in e)n.d(r,i,function(t){return e[t]}.bind(null,i));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(2);t.Service=r.Service;var i=n(9);t.requests=i.requests},function(e,t,n){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var r=n(5);t.Service=r.Service;var i=n(6);t.requests=i.requests},function(e,t,n){"use strict";var r=this&&this.__extends||function(){var e=function(t,n){return(e=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var n in t)t.hasOwnProperty(n)&&(e[n]=t[n])})(t,n)};return function(t,n){function r(){this.constructor=t}e(t,n),t.prototype=null===n?Object.create(n):(r.prototype=n.prototype,new r)}}();Object.defineProperty(t,"__esModule",{value:!0});var i=n(3),o=n(4),a=n(7),s=n(8),u=function(e){function t(){var t=e.call(this)||this;return t._data=new o.Data,t._toast=new a.Toast,t._menu=new s.Menu,t}return r(t,e),Object.defineProperty(t.prototype,"data",{get:function(){return this._data},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"toast",{get:function(){return this._toast},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"menu",{get:function(){return this._menu},enumerable:!0,configurable:!0}),t.init=function(){return void 0==t.instance&&(t.instance=new t),t.instance},t.instance=void 0,t}(i.ServiceBase);t.Service=u},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(i,o){n.rpcTracker[r]={resolve:i,reject:o};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}();t.ServiceBase=r},function(e,t,n){"use strict";var r=this&&this.__awaiter||function(e,t,n,r){return new(n||(n=Promise))(function(i,o){function a(e){try{u(r.next(e))}catch(e){o(e)}}function s(e){try{u(r.throw(e))}catch(e){o(e)}}function u(e){e.done?i(e.value):new n(function(t){t(e.value)}).then(a,s)}u((r=r.apply(e,t||[])).next())})},i=this&&this.__generator||function(e,t){var n,r,i,o,a={label:0,sent:function(){if(1&i[0])throw i[1];return i[1]},trys:[],ops:[]};return o={next:s(0),throw:s(1),return:s(2)},"function"==typeof Symbol&&(o[Symbol.iterator]=function(){return this}),o;function s(o){return function(s){return function(o){if(n)throw new TypeError("Generator is already executing.");for(;a;)try{if(n=1,r&&(i=2&o[0]?r.return:o[0]?r.throw||((i=r.return)&&i.call(r),0):r.next)&&!(i=i.call(r,o[1])).done)return i;switch(r=0,i&&(o=[2&o[0],i.value]),o[0]){case 0:case 1:i=o;break;case 4:return a.label++,{value:o[1],done:!1};case 5:a.label++,r=o[1],o=[0];continue;case 7:o=a.ops.pop(),a.trys.pop();continue;default:if(!(i=(i=a.trys).length>0&&i[i.length-1])&&(6===o[0]||2===o[0])){a=0;continue}if(3===o[0]&&(!i||o[1]>i[0]&&o[1]0&&o[o.length-1])&&(6===i[0]||2===i[0])){u=0;continue}if(3===i[0]&&(!o||i[1]>o[0]&&i[1] */ getTags(): Promise; - getAppData(): void; - updateAppData(): void; + getAppData(): Promise; + updateAppData(appData: AppData): Promise; /** * Creates a file on Surix linked to the current project. * @param file FileMessage message details 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/dist/src/service-base.d.ts b/dist/src/service-base.d.ts new file mode 100644 index 0000000..52084ad --- /dev/null +++ b/dist/src/service-base.d.ts @@ -0,0 +1,58 @@ +export declare class ServiceBase { + private rpcTracker; + private prefix; + protected constructor(); + /** + * Sends a request to Surixs + * @param type Request type + * @param payload Request payload + */ + 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; + /** + * 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 + */ + on(eventName: string, handler: any): void; + /** + * Sends the specified message to Surix + * @param msg Message to send to Surix + */ + private sendMessage; + /** + * Creates a promise then sends the message + * @param name Name of the request to send to Surix + * @param body + */ + private rpc; + /** + * This handles the rpcReq type responses from Surix + * @param msg Response from Surix + * @param handler Handles the response + */ + private handleRpcReq; + /** + * Emits a custom event + * @param msg Message to be embedded to the custom event to be emitted + */ + private emit; + /** + * Sets up Surix 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/src/types.ts b/dist/src/types.d.ts similarity index 67% rename from src/types.ts rename to dist/src/types.d.ts index 3238f0e..1587118 100644 --- a/src/types.ts +++ b/dist/src/types.d.ts @@ -33,6 +33,8 @@ export interface EntityData { export interface AppData { data: AppDataField; } + +export interface PersistedAppData extends AppData, HasTimestamps, HasId {} export interface PersistedEntityData extends HasId, HasTimestamps, EntityData {} export interface ToastParams { @@ -100,6 +102,28 @@ interface HasId { } interface HasTimestamps { -createdAt: Date; -updatedAt: Date; + createdAt: Date; + updatedAt: Date; +} + +export interface IData { + createEntity(entity: EntityData): Promise; + project(): Promise; + getEntities(query?: any): 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.d.ts b/index.d.ts new file mode 100644 index 0000000..4dc46f7 --- /dev/null +++ b/index.d.ts @@ -0,0 +1,3 @@ +import { Service } from './src/service'; +import { requests } from './src/requests'; +export { Service, requests }; diff --git a/index.ts b/index.ts index 7b27889..e6b1015 100644 --- a/index.ts +++ b/index.ts @@ -1,6 +1,6 @@ import { Service } from './src/service'; import { requests } from './src/requests'; -import { EntityData, AppData } from './src/types'; +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.d.ts b/src/functions/data.d.ts new file mode 100644 index 0000000..7b77a9c --- /dev/null +++ b/src/functions/data.d.ts @@ -0,0 +1,68 @@ +import { PersistedEntityData, TagUpdateParams, FileDetails, FileParams, TagsParams, EntityData, Project, AppData, Tag, IData, PersistedAppData } from "../types"; +import { ServiceBase } from "../service-base"; +export declare class Data extends ServiceBase implements IData { + constructor(); + /** + * Saves an entity in Surix + * @param entity EntityData entity to be saved + * @returns Promise + */ + 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?: any): 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/src/functions/data.ts b/src/functions/data.ts index e20334a..425dd66 100644 --- a/src/functions/data.ts +++ b/src/functions/data.ts @@ -1,12 +1,25 @@ -import { Service } from "../.."; -import { Project, FileDetails, FileParams, TagsParams, TagUpdateParams, Tag, EntityData, PersistedEntityData, AppData } from "../types"; -import { requests } from "../../build/dist"; +import { + PersistedEntityData, + TagUpdateParams, + FileDetails, + FileParams, + TagsParams, + EntityData, + Project, + AppData, + Tag, + IData, + PersistedAppData +} from "../types"; +import { requests } from "../requests"; +import { ServiceBase } from "../service-base"; -export class Data { - public _service: Service; +export class Data extends ServiceBase implements IData{ + //public _service: Service; public constructor() { - this._service = Service.init(); + super(); + //this._service = Service.init(); } /** @@ -15,7 +28,7 @@ export class Data { * @returns Promise */ public async createEntity(entity: EntityData): Promise { - return await this._service.request(requests.data.createEntity, entity); + return await this.internalRequest(requests.data.createEntity, entity); } /** @@ -23,7 +36,7 @@ export class Data { * @returns Promise */ public async project(): Promise { - return await this._service.request(requests.data.project); + return await this.internalRequest(requests.data.project); } /** @@ -32,7 +45,7 @@ export class Data { * @returns Promise */ public async getEntities(query?: any): Promise { - return await this._service.request(requests.data.getEntities, query); + return await this.internalRequest(requests.data.getEntities, query); } /** @@ -41,7 +54,7 @@ export class Data { * @returns Promise */ public async getEntityById(id: string): Promise { - return await this._service.request(requests.data.getEntityById, id); + return await this.internalRequest(requests.data.getEntityById, id); } /** @@ -50,7 +63,7 @@ export class Data { * @returns Promise */ public async addTagsToEntity(params: TagsParams): Promise { - return await this._service.request(requests.data.addTagsToEntity, params); + return await this.internalRequest(requests.data.addTagsToEntity, params); } /** @@ -58,7 +71,7 @@ export class Data { * @param params TagsParams tag parameters */ public async removeTagsFromEntity(params: TagsParams): Promise { - return await this._service.request(requests.data.removeTagsFromEntity, params); + return await this.internalRequest(requests.data.removeTagsFromEntity, params); } /** @@ -66,7 +79,7 @@ export class Data { * @param params Update params */ public async updateTag(params: TagUpdateParams): Promise { - return await this._service.request(requests.data.updateTag, params); + return await this.internalRequest(requests.data.updateTag, params); } /** @@ -74,14 +87,14 @@ export class Data { * @returns Promise */ public async getTags(): Promise { - return await this._service.request(requests.data.getTags); + return await this.internalRequest(requests.data.getTags); } - public async getAppData() { - return await this._service.request(requests.data.getAppData); + public async getAppData(): Promise { + return await this.internalRequest(requests.data.getAppData); } - public async updateAppData(appData: AppData) { - return await this._service.request(requests.data.updateAppData, appData); + public async updateAppData(appData: AppData): Promise { + return await this.internalRequest(requests.data.updateAppData, appData); } /** @@ -90,7 +103,7 @@ export class Data { * @returns Promise */ public async createFile(file: FileParams): Promise { - return await this._service.request(requests.data.createFile, file); + return await this.internalRequest(requests.data.createFile, file); } /** @@ -99,7 +112,7 @@ export class Data { * @returns Promise */ public async getFileById(id: string): Promise { - return await this._service.request(requests.data.getFileById, id); + return await this.internalRequest(requests.data.getFileById, id); } /** @@ -107,6 +120,6 @@ export class Data { * @returns Promise */ public async getFiles(): Promise{ - return await this._service.request(requests.data.getFiles); + 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.d.ts b/src/functions/menu.d.ts new file mode 100644 index 0000000..cfc931d --- /dev/null +++ b/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/src/functions/menu.ts b/src/functions/menu.ts index 5d4c1bb..79a76ad 100644 --- a/src/functions/menu.ts +++ b/src/functions/menu.ts @@ -1,18 +1,20 @@ -import { Service, requests } from "../../build/dist"; -import { MenuItem } from "../types"; +import { requests } from '../requests'; +import { MenuItem } from '../types'; +import { ServiceBase } from '../service-base'; -export class Menu { - public _service: Service; +export class Menu extends ServiceBase{ + //public _service: Service; public constructor() { - this._service = Service.init(); + super(); + //this._service = Service.init(); } /** * Populates Surix app menu with the provided items * @param menu MenuItem[] menu items */ - public populate(menu: MenuItem[]) { - return this._service.request(requests.menu.populate, menu); + public populate(menu: MenuItem[]): Promise { + return this.internalRequest(requests.menu.populate, menu); } } \ No newline at end of file diff --git a/src/functions/toast.d.ts b/src/functions/toast.d.ts new file mode 100644 index 0000000..3d1f0ad --- /dev/null +++ b/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/src/functions/toast.ts b/src/functions/toast.ts index edbd7e4..655effc 100644 --- a/src/functions/toast.ts +++ b/src/functions/toast.ts @@ -1,19 +1,20 @@ -import { Service } from "../.."; -import { ToastParams } from "../types"; -import { requests } from "../../build/dist"; +import { ToastParams, IToast } from '../types'; +import { requests } from '../requests'; +import { ServiceBase } from '../service-base'; -export class Toast { - private _service: Service; +export class Toast extends ServiceBase implements IToast { + // private _service: Service; public constructor() { - this._service = Service.init(); + 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) { - return this._service.request(requests.toast.show, message); + public show(message: ToastParams): Promise { + return this.internalRequest(requests.toast.show, message); } } \ No newline at end of file diff --git a/src/requests.d.ts b/src/requests.d.ts new file mode 100644 index 0000000..c8daaf7 --- /dev/null +++ b/src/requests.d.ts @@ -0,0 +1,27 @@ +export declare const requests: { + data: { + createEntity: string; + project: string; + getEntities: string; + getEntityById: string; + addTagsToEntity: string; + removeTagsFromEntity: string; + getTags: string; + updateTag: string; + getAppData: string; + updateAppData: string; + createFile: string; + getFileById: string; + getFiles: string; + }; + toast: { + show: string; + }; + menu: { + populate: string; + }; + events: { + menuItemClicked: string; + menuClicked: string; + }; +}; diff --git a/build/dist/src/service-base.d.ts b/src/service-base.d.ts similarity index 94% rename from build/dist/src/service-base.d.ts rename to src/service-base.d.ts index b8444d6..b6688f7 100644 --- a/build/dist/src/service-base.d.ts +++ b/src/service-base.d.ts @@ -8,7 +8,7 @@ export declare class ServiceBase { * @param payload Request payload * @returns Promise Returns a promise */ - request(type: string, payload?: any): Promise; + protected request(type: string, payload?: any): Promise; /** * An event listener wrapper * @param eventName A string representing the event name diff --git a/src/service-base.ts b/src/service-base.ts index 3a318b3..62f682a 100644 --- a/src/service-base.ts +++ b/src/service-base.ts @@ -6,23 +6,48 @@ export class ServiceBase { 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 + * 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 @@ -61,7 +86,7 @@ export class ServiceBase { } // 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 diff --git a/build/dist/src/service.d.ts b/src/service.d.ts similarity index 100% rename from build/dist/src/service.d.ts rename to src/service.d.ts diff --git a/src/service.ts b/src/service.ts index 3a55402..a870188 100644 --- a/src/service.ts +++ b/src/service.ts @@ -2,30 +2,39 @@ 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 { private _data: Data; private _toast: Toast; private _menu: Menu; + private _events: Events; /** * Returns all data methods */ - public get data () { + public get data (): Data { return this._data; } /** * Returns all toast methods */ - public get toast () { + public get toast (): Toast { return this._toast; } /** * Returns all menu methods */ - public get menu () { + public get menu (): Menu { return this._menu; } + + /** + * Returns all methods associated with events. + */ + public get events (): Events { + return this._events; + } /** * Constructor */ @@ -34,12 +43,13 @@ export class Service extends ServiceBase { this._data = new Data(); this._toast = new Toast(); this._menu = new Menu(); + this._events = new Events(); } /** * Provides Surix singleton */ - public static init() { + public static init(): Service { if(Service.instance == undefined){ Service.instance = new Service(); } diff --git a/src/types.d.ts b/src/types.d.ts new file mode 100644 index 0000000..1587118 --- /dev/null +++ b/src/types.d.ts @@ -0,0 +1,129 @@ +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 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?: any): 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, From b8045ea8eebc55287e686cd92eed4945bc133956 Mon Sep 17 00:00:00 2001 From: Kevin Nderitu Date: Fri, 23 Nov 2018 11:02:03 +0300 Subject: [PATCH 5/9] Changed handleRpcReq to handleRpcRep --- src/service-base.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/service-base.ts b/src/service-base.ts index 62f682a..84e1977 100644 --- a/src/service-base.ts +++ b/src/service-base.ts @@ -78,7 +78,7 @@ export class ServiceBase { * @param msg Response from Surix * @param handler Handles the response */ - private handleRpcReq(msg: any, handler: any) { + private handleRpcRep(msg: any, handler: any) { if(msg.success) { handler.rpcTracker[msg.id].resolve(msg.body); } else { @@ -104,7 +104,7 @@ export class ServiceBase { const msg: any = event.data; switch(msg.type) { case 'rpcRep': - this.handleRpcReq(msg, this); + this.handleRpcRep(msg, this); break; case 'event': this.emit(msg); From d33a4642fa546142ab4b84194bcdc2849e197ee4 Mon Sep 17 00:00:00 2001 From: Kevin Nderitu Date: Fri, 23 Nov 2018 11:31:58 +0300 Subject: [PATCH 6/9] Updated the docs --- README.md | 69 +++++++++++++++++++++++++++---------------------------- 1 file changed, 34 insertions(+), 35 deletions(-) diff --git a/README.md b/README.md index de8dd6c..1e808f5 100644 --- a/README.md +++ b/README.md @@ -23,35 +23,32 @@ const requests = Surix.requests; Service contains all the methods grouped according to their operations -`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. - -`toast` contains: -- `show`: Displays a message on Surix toast (expects message: string parameter). - -`menu` contains: -- `populate`: Submits the menu items to Surix. The menu is updated immidiately (expects items: any parameter). -`on` is a function used to register events. - -`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: +[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 = [ @@ -85,6 +82,7 @@ service.menu.populate(menuItems).then(res => { }); ``` +## Toast Methods ### Show a Toast Message: ```javascript const toast = { @@ -97,7 +95,7 @@ service.toast.show(toast).then(res => { // Handle error }); ``` - +## Data Methods ### Fetch Entities: ```javascript // Fetch entities @@ -175,7 +173,7 @@ service.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', @@ -191,7 +189,7 @@ surix.data.updateTag(args).then(updatedTag => { }); ``` -### Get all tags in the project +### Get all tags ```javascript service.data.getTags().then((tags) => { // Do something with the tags @@ -289,17 +287,18 @@ service.data.getFiles().then(files => { }) ``` -## 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 From 71061089a4cf78676fdae5d24f103afba8973e15 Mon Sep 17 00:00:00 2001 From: Kevin Nderitu Date: Fri, 23 Nov 2018 12:20:05 +0300 Subject: [PATCH 7/9] Added query parameter type --- src/functions/data.ts | 5 +++-- src/types.d.ts | 17 ++++++++++++++++- 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/src/functions/data.ts b/src/functions/data.ts index 425dd66..9aeb52c 100644 --- a/src/functions/data.ts +++ b/src/functions/data.ts @@ -9,7 +9,8 @@ import { AppData, Tag, IData, - PersistedAppData + PersistedAppData, + QueryParams } from "../types"; import { requests } from "../requests"; import { ServiceBase } from "../service-base"; @@ -44,7 +45,7 @@ export class Data extends ServiceBase implements IData{ * @param query (Optional) query * @returns Promise */ - public async getEntities(query?: any): Promise { + public async getEntities(query?: QueryParams): Promise { return await this.internalRequest(requests.data.getEntities, query); } diff --git a/src/types.d.ts b/src/types.d.ts index 1587118..a936c0b 100644 --- a/src/types.d.ts +++ b/src/types.d.ts @@ -49,6 +49,21 @@ export interface MenuItem { default?: boolean; } +export interface QueryMatch { + [fieldOrOp: string]: any; +} + +export interface QueryParams { + [key: string]: any; + query?: QueryMatch; + limit?: number; + skip?: number; + sort?: { + [field: string]: number; + }; + tags?: string[]; +} + export interface FileParams { name: string; public: boolean; @@ -109,7 +124,7 @@ interface HasTimestamps { export interface IData { createEntity(entity: EntityData): Promise; project(): Promise; - getEntities(query?: any): Promise; + getEntities(query?: QueryParams): Promise; getEntityById(id: string): Promise; addTagsToEntity(params: TagsParams): Promise; removeTagsFromEntity(params: TagsParams): Promise; From ea35a2015f4a38ab09d3bd883ed63e451bf008ac Mon Sep 17 00:00:00 2001 From: Kevin Nderitu Date: Fri, 23 Nov 2018 12:21:39 +0300 Subject: [PATCH 8/9] Built current changes --- dist/client-service.js | 4 ++-- dist/client-service.js.map | 2 +- dist/client-service.min.js | 2 +- dist/src/functions/data.d.ts | 4 ++-- dist/src/service-base.d.ts | 2 +- dist/src/types.d.ts | 17 ++++++++++++++++- 6 files changed, 23 insertions(+), 8 deletions(-) diff --git a/dist/client-service.js b/dist/client-service.js index f9a15b9..68e6020 100644 --- a/dist/client-service.js +++ b/dist/client-service.js @@ -175,7 +175,7 @@ var ServiceBase = /** @class */ (function () { * @param msg Response from Surix * @param handler Handles the response */ - ServiceBase.prototype.handleRpcReq = function (msg, handler) { + ServiceBase.prototype.handleRpcRep = function (msg, handler) { if (msg.success) { handler.rpcTracker[msg.id].resolve(msg.body); } @@ -203,7 +203,7 @@ var ServiceBase = /** @class */ (function () { var msg = event.data; switch (msg.type) { case 'rpcRep': - _this.handleRpcReq(msg, _this); + _this.handleRpcRep(msg, _this); break; case 'event': _this.emit(msg); diff --git a/dist/client-service.js.map b/dist/client-service.js.map index 800f40e..78b6615 100644 --- a/dist/client-service.js.map +++ b/dist/client-service.js.map @@ -1 +1 @@ -{"version":3,"sources":["webpack://Surix/webpack/universalModuleDefinition","webpack://Surix/webpack/bootstrap","webpack://Surix/./src/service-base.ts","webpack://Surix/./src/requests.ts","webpack://Surix/./index.ts","webpack://Surix/./src/service.ts","webpack://Surix/./src/functions/data.ts","webpack://Surix/./src/functions/toast.ts","webpack://Surix/./src/functions/menu.ts","webpack://Surix/./src/functions/events.ts"],"names":[],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,CAAC;AACD,O;ACVA;AACA;;AAEA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;;AAEA;AACA;;AAEA;AACA;AACA;;;AAGA;AACA;;AAEA;AACA;;AAEA;AACA;AACA;AACA,kDAA0C,gCAAgC;AAC1E;AACA;;AAEA;AACA;AACA;AACA,gEAAwD,kBAAkB;AAC1E;AACA,yDAAiD,cAAc;AAC/D;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,iDAAyC,iCAAiC;AAC1E,wHAAgH,mBAAmB,EAAE;AACrI;AACA;;AAEA;AACA;AACA;AACA,mCAA2B,0BAA0B,EAAE;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,GAAG,CAAC,IAAI,EAAE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AAe,CAAC,mBAAQ,CAAC,IAAI,CAAC,QAAQ,CAAC;4BAAzD,sBAAO,SAAkD,EAAC;;;;KAC7D;IACL,WAAC;AAAD,CAAC,CA5GyB,0BAAW,GA4GpC;AA5GY,oBAAI;;;;;;;;;;;;;;;;;;;;;;;ACfjB,wCAAuC;AACvC,4CAA8C;AAE9C;IAA2B,yBAAW;IAClC,6BAA6B;IAE7B;eACI,iBAAO;QACP,iCAAiC;IACrC,CAAC;IAED;;;OAGG;IACI,oBAAI,GAAX,UAAY,OAAoB;QAC5B,OAAO,IAAI,CAAC,eAAe,CAAC,mBAAQ,CAAC,KAAK,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC;IAC9D,CAAC;IACL,YAAC;AAAD,CAAC,CAf0B,0BAAW,GAerC;AAfY,sBAAK;;;;;;;;;;;;;;;;;;;;;;;ACJlB,wCAAuC;AAEvC,4CAA8C;AAE9C;IAA0B,wBAAW;IACjC,2BAA2B;IAE3B;eACI,iBAAO;QACP,iCAAiC;IACrC,CAAC;IAED;;;OAGG;IACI,uBAAQ,GAAf,UAAgB,IAAgB;QAC5B,OAAO,IAAI,CAAC,eAAe,CAAC,mBAAQ,CAAC,IAAI,CAAC,QAAQ,EAAE,IAAI,CAAC,CAAC;IAC9D,CAAC;IACL,WAAC;AAAD,CAAC,CAfyB,0BAAW,GAepC;AAfY,oBAAI;;;;;;;;;;;;;;;;;;;;;;;ACJjB,4CAA8C;AAC9C,iCAAiC;AAEjC;IAA4B,0BAAW;IAAvC;;IASA,CAAC;IAPG;;;OAGG;IACI,gCAAe,GAAtB,UAAuB,OAA4B;QAC/C,IAAI,CAAC,UAAU,CAAC,YAAQ,CAAC,MAAM,CAAC,eAAe,EAAE,OAAO,CAAC,CAAC;IAC9D,CAAC;IACL,aAAC;AAAD,CAAC,CAT2B,0BAAW,GAStC;AATY,wBAAM","file":"client-service.js","sourcesContent":["(function webpackUniversalModuleDefinition(root, factory) {\n\tif(typeof exports === 'object' && typeof module === 'object')\n\t\tmodule.exports = factory();\n\telse if(typeof define === 'function' && define.amd)\n\t\tdefine(\"Surix\", [], factory);\n\telse if(typeof exports === 'object')\n\t\texports[\"Surix\"] = factory();\n\telse\n\t\troot[\"Surix\"] = factory();\n})(window, function() {\nreturn "," \t// The module cache\n \tvar installedModules = {};\n\n \t// The require function\n \tfunction __webpack_require__(moduleId) {\n\n \t\t// Check if module is in cache\n \t\tif(installedModules[moduleId]) {\n \t\t\treturn installedModules[moduleId].exports;\n \t\t}\n \t\t// Create a new module (and put it into the cache)\n \t\tvar module = installedModules[moduleId] = {\n \t\t\ti: moduleId,\n \t\t\tl: false,\n \t\t\texports: {}\n \t\t};\n\n \t\t// Execute the module function\n \t\tmodules[moduleId].call(module.exports, module, module.exports, __webpack_require__);\n\n \t\t// Flag the module as loaded\n \t\tmodule.l = true;\n\n \t\t// Return the exports of the module\n \t\treturn module.exports;\n \t}\n\n\n \t// expose the modules object (__webpack_modules__)\n \t__webpack_require__.m = modules;\n\n \t// expose the module cache\n \t__webpack_require__.c = installedModules;\n\n \t// define getter function for harmony exports\n \t__webpack_require__.d = function(exports, name, getter) {\n \t\tif(!__webpack_require__.o(exports, name)) {\n \t\t\tObject.defineProperty(exports, name, { enumerable: true, get: getter });\n \t\t}\n \t};\n\n \t// define __esModule on exports\n \t__webpack_require__.r = function(exports) {\n \t\tif(typeof Symbol !== 'undefined' && Symbol.toStringTag) {\n \t\t\tObject.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });\n \t\t}\n \t\tObject.defineProperty(exports, '__esModule', { value: true });\n \t};\n\n \t// create a fake namespace object\n \t// mode & 1: value is a module id, require it\n \t// mode & 2: merge all properties of value into the ns\n \t// mode & 4: return value when already ns object\n \t// mode & 8|1: behave like require\n \t__webpack_require__.t = function(value, mode) {\n \t\tif(mode & 1) value = __webpack_require__(value);\n \t\tif(mode & 8) return value;\n \t\tif((mode & 4) && typeof value === 'object' && value && value.__esModule) return value;\n \t\tvar ns = Object.create(null);\n \t\t__webpack_require__.r(ns);\n \t\tObject.defineProperty(ns, 'default', { enumerable: true, value: value });\n \t\tif(mode & 2 && typeof value != 'string') for(var key in value) __webpack_require__.d(ns, key, function(key) { return value[key]; }.bind(null, key));\n \t\treturn ns;\n \t};\n\n \t// getDefaultExport function for compatibility with non-harmony modules\n \t__webpack_require__.n = function(module) {\n \t\tvar getter = module && module.__esModule ?\n \t\t\tfunction getDefault() { return module['default']; } :\n \t\t\tfunction getModuleExports() { return module; };\n \t\t__webpack_require__.d(getter, 'a', getter);\n \t\treturn getter;\n \t};\n\n \t// Object.prototype.hasOwnProperty.call\n \t__webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };\n\n \t// __webpack_public_path__\n \t__webpack_require__.p = \"\";\n\n\n \t// Load entry module and return exports\n \treturn __webpack_require__(__webpack_require__.s = 2);\n","export class ServiceBase {\n private rpcTracker: any;\n private prefix: string = '__surix__';\n\n protected constructor() {\n this.rpcTracker = {};\n this.setUpService();\n }\n\n /**\n * Sends a request to Surixs\n * @param type Request type\n * @param payload Request payload\n */\n protected internalRequest(type: string, payload?: any): Promise {\n return this.rpc(type, payload);\n }\n \n /**\n * Sends a request to Surix \n * ====== TO BE DEPRICATED IN FUTURE =======\n * @param type Request type\n * @param payload Request payload \n * @returns Promise Returns a promise\n */\n public request(type: string, payload?: any): Promise {\n console.warn(`service.request method will be DEPRICATED in future. Please consider using service.${type} instead.`);\n return this.rpc(type, payload);\n }\n\n /**\n * An event listener wrapper \n * @param eventName A string representing the event name\n * @param handler a function that handles event\n */\n public internalOn(eventName: string, handler: any) {\n document.addEventListener(`${this.prefix}${eventName}`, handler);\n }\n\n /**\n * An event listener wrapper \n * ======== TO BE DEPRICATED IN FUTURE ============\n * @param eventName A string representing the event name\n * @param handler a function that handles event\n */\n public on(eventName: string, handler: any) {\n console.warn(`service.on method will be DEPRICATED in future. Please consider using service.events.${eventName} instead.`);\n document.addEventListener(`${this.prefix}${eventName}`, handler);\n }\n\n /**\n * Sends the specified message to Surix\n * @param msg Message to send to Surix\n */\n private sendMessage(msg: any) {\n window.parent.postMessage(msg, '*');\n }\n /**\n * Creates a promise then sends the message\n * @param name Name of the request to send to Surix\n * @param body \n */\n private rpc(name: string, body: any) {\n const reqId = Math.random();\n return new Promise((resolve, reject) => {\n this.rpcTracker[reqId] = { resolve, reject };\n const message = {\n name, \n body, \n type: 'rpcReq', \n id: reqId\n }\n this.sendMessage(message);\n });\n }\n /**\n * This handles the rpcReq type responses from Surix\n * @param msg Response from Surix\n * @param handler Handles the response\n */\n private handleRpcReq(msg: any, handler: any) {\n if(msg.success) {\n handler.rpcTracker[msg.id].resolve(msg.body);\n } else {\n handler.rpcTracker[msg.id].reject(msg.body);\n }\n // Remove the promise from the handler because \n // it has already been taken care of.\n delete handler.rpcTracker[msg.id];\n }\n /**\n * Emits a custom event\n * @param msg Message to be embedded to the custom event to be emitted\n */\n private emit(msg: any) {\n const event: Event = new CustomEvent(`${this.prefix}${msg.name}`, {detail: msg});\n document.dispatchEvent(event);\n }\n /**\n * Sets up Surix service\n */\n protected setUpService() {\n window.addEventListener('message', event => {\n const msg: any = event.data;\n switch(msg.type) {\n case 'rpcRep':\n this.handleRpcReq(msg, this);\n break;\n case 'event':\n this.emit(msg);\n break;\n }\n });\n }\n}","export const requests = {\n data: {\n createEntity: 'data.createEntity',\n project: 'data.project',\n getEntities: 'data.getEntities',\n getEntityById: 'data.getEntityById',\n addTagsToEntity: 'data.addTagsToEntity',\n removeTagsFromEntity: 'data.removeTagsFromEntity',\n getTags: 'data.getTags',\n updateTag: 'data.updateTag',\n getAppData: 'data.getAppData',\n updateAppData: 'data.updateAppData',\n createFile: 'data.createFile',\n getFileById: 'data.getFileById',\n getFiles: 'data.getFiles'\n },\n toast: {\n show: 'toast.show',\n },\n menu: {\n populate: 'menu.populate'\n },\n events: {\n menuItemClicked: 'menu-item-clicked',\n // TODO: this is for backwards compatibility\n // it is deprecated and will be removed in a future update\n menuClicked: 'menu-item-clicked'\n }\n}","import { Service } from './src/service';\nimport { requests } from './src/requests';\nimport { PersistedEntityData } from './src/types';\nexport {\n Service,\n requests\n}","import { ServiceBase } from './service-base';\nimport { Data } from './functions/data';\nimport { Toast } from './functions/toast';\nimport { Menu } from './functions/menu';\nimport { Events } from './functions/events';\nexport class Service extends ServiceBase {\n\n private _data: Data;\n private _toast: Toast;\n private _menu: Menu;\n private _events: Events;\n\n /**\n * Returns all data methods\n */\n public get data (): Data {\n return this._data;\n }\n /**\n * Returns all toast methods\n */\n public get toast (): Toast {\n return this._toast;\n }\n /**\n * Returns all menu methods\n */\n public get menu (): Menu {\n return this._menu;\n }\n\n /**\n * Returns all methods associated with events.\n */\n public get events (): Events {\n return this._events;\n }\n /**\n * Constructor\n */\n private constructor() {\n super();\n this._data = new Data();\n this._toast = new Toast();\n this._menu = new Menu();\n this._events = new Events();\n }\n\n /**\n * Provides Surix singleton\n */\n public static init(): Service {\n if(Service.instance == undefined){\n Service.instance = new Service();\n }\n return Service.instance;\n }\n \n private static instance?: Service = undefined;\n}","import {\n PersistedEntityData,\n TagUpdateParams,\n FileDetails, \n FileParams, \n TagsParams,\n EntityData,\n Project,\n AppData,\n Tag,\n IData,\n PersistedAppData\n} from \"../types\";\nimport { requests } from \"../requests\";\nimport { ServiceBase } from \"../service-base\";\n\nexport class Data extends ServiceBase implements IData{\n //public _service: Service;\n \n public constructor() {\n super();\n //this._service = Service.init();\n }\n\n /**\n * Saves an entity in Surix\n * @param entity EntityData entity to be saved\n * @returns Promise\n */\n public async createEntity(entity: EntityData): Promise {\n return await this.internalRequest(requests.data.createEntity, entity);\n }\n\n /**\n * Returns the current project\n * @returns Promise\n */\n public async project(): Promise {\n return await this.internalRequest(requests.data.project);\n }\n\n /**\n * Returns all the entities present\n * @param query (Optional) query\n * @returns Promise\n */\n public async getEntities(query?: any): Promise {\n return await this.internalRequest(requests.data.getEntities, query);\n }\n\n /**\n * Returns an entity identified by the id provided\n * @param id Surix Id\n * @returns Promise\n */\n public async getEntityById(id: string): Promise {\n return await this.internalRequest(requests.data.getEntityById, id);\n }\n\n /**\n * Adds tags to an existing entity\n * @param params Parameters to add tags\n * @returns Promise\n */\n public async addTagsToEntity(params: TagsParams): Promise {\n return await this.internalRequest(requests.data.addTagsToEntity, params);\n }\n\n /**\n * Removes tags from an entity\n * @param params TagsParams tag parameters\n */\n public async removeTagsFromEntity(params: TagsParams): Promise {\n return await this.internalRequest(requests.data.removeTagsFromEntity, params);\n }\n\n /**\n * Updates tags on an existing entity\n * @param params Update params\n */\n public async updateTag(params: TagUpdateParams): Promise {\n return await this.internalRequest(requests.data.updateTag, params);\n }\n\n /**\n * Returns all the tags available\n * @returns Promise\n */\n public async getTags(): Promise {\n return await this.internalRequest(requests.data.getTags);\n }\n\n public async getAppData(): Promise {\n return await this.internalRequest(requests.data.getAppData);\n }\n public async updateAppData(appData: AppData): Promise {\n return await this.internalRequest(requests.data.updateAppData, appData);\n }\n\n /**\n * Creates a file on Surix linked to the current project.\n * @param file FileMessage message details\n * @returns Promise\n */\n public async createFile(file: FileParams): Promise {\n return await this.internalRequest(requests.data.createFile, file);\n }\n\n /**\n * Gets a file associated with the id provided\n * @param id string Surix Id\n * @returns Promise\n */\n public async getFileById(id: string): Promise {\n return await this.internalRequest(requests.data.getFileById, id);\n }\n\n /**\n * Returns all files\n * @returns Promise\n */\n public async getFiles(): Promise{\n return await this.internalRequest(requests.data.getFiles);\n }\n}","import { ToastParams, IToast } from '../types';\nimport { requests } from '../requests';\nimport { ServiceBase } from '../service-base';\n\nexport class Toast extends ServiceBase implements IToast {\n // private _service: Service;\n\n public constructor() {\n super();\n //this._service = Service.init();\n }\n\n /**\n * Displays the message provided on toast on Surix\n * @param message ToastMessage message to show on the toast\n */\n public show(message: ToastParams): Promise {\n return this.internalRequest(requests.toast.show, message);\n }\n}","import { requests } from '../requests';\nimport { MenuItem } from '../types';\nimport { ServiceBase } from '../service-base';\n\nexport class Menu extends ServiceBase{\n //public _service: Service;\n\n public constructor() {\n super();\n //this._service = Service.init();\n }\n\n /**\n * Populates Surix app menu with the provided items\n * @param menu MenuItem[] menu items\n */\n public populate(menu: MenuItem[]): Promise {\n return this.internalRequest(requests.menu.populate, menu);\n }\n}","import { ServiceBase } from \"../service-base\";\nimport { requests } from \"../..\";\n\nexport class Events extends ServiceBase {\n\n /**\n * Registers an event onto the handler provided.\n * @param handler Function to handle events\n */\n public menuItemClicked(handler: (event: any) => any) {\n this.internalOn(requests.events.menuItemClicked, handler);\n }\n}"],"sourceRoot":""} \ No newline at end of file +{"version":3,"sources":["webpack://Surix/webpack/universalModuleDefinition","webpack://Surix/webpack/bootstrap","webpack://Surix/./src/service-base.ts","webpack://Surix/./src/requests.ts","webpack://Surix/./index.ts","webpack://Surix/./src/service.ts","webpack://Surix/./src/functions/data.ts","webpack://Surix/./src/functions/toast.ts","webpack://Surix/./src/functions/menu.ts","webpack://Surix/./src/functions/events.ts"],"names":[],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,CAAC;AACD,O;ACVA;AACA;;AAEA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;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,EA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;;;;;ACJjB,4CAA8C;AAC9C,iCAAiC;AAEjC;IAA4B,0BAAW;IAAvC;;IASA,CAAC;IAPG;;;OAGG;IACI,gCAAe,GAAtB,UAAuB,OAA4B;QAC/C,IAAI,CAAC,UAAU,CAAC,YAAQ,CAAC,MAAM,CAAC,eAAe,EAAE,OAAO,CAAC,CAAC;IAC9D,CAAC;IACL,aAAC;AAAD,CAAC,CAT2B,0BAAW,GAStC;AATY,wBAAM","file":"client-service.js","sourcesContent":["(function webpackUniversalModuleDefinition(root, factory) {\n\tif(typeof exports === 'object' && typeof module === 'object')\n\t\tmodule.exports = factory();\n\telse if(typeof define === 'function' && define.amd)\n\t\tdefine(\"Surix\", [], factory);\n\telse if(typeof exports === 'object')\n\t\texports[\"Surix\"] = factory();\n\telse\n\t\troot[\"Surix\"] = factory();\n})(window, function() {\nreturn "," \t// The module cache\n \tvar installedModules = {};\n\n \t// The require function\n \tfunction __webpack_require__(moduleId) {\n\n \t\t// Check if module is in cache\n \t\tif(installedModules[moduleId]) {\n \t\t\treturn installedModules[moduleId].exports;\n \t\t}\n \t\t// Create a new module (and put it into the cache)\n \t\tvar module = installedModules[moduleId] = {\n \t\t\ti: moduleId,\n \t\t\tl: false,\n \t\t\texports: {}\n \t\t};\n\n \t\t// Execute the module function\n \t\tmodules[moduleId].call(module.exports, module, module.exports, __webpack_require__);\n\n \t\t// Flag the module as loaded\n \t\tmodule.l = true;\n\n \t\t// Return the exports of the module\n \t\treturn module.exports;\n \t}\n\n\n \t// expose the modules object (__webpack_modules__)\n \t__webpack_require__.m = modules;\n\n \t// expose the module cache\n \t__webpack_require__.c = installedModules;\n\n \t// define getter function for harmony exports\n \t__webpack_require__.d = function(exports, name, getter) {\n \t\tif(!__webpack_require__.o(exports, name)) {\n \t\t\tObject.defineProperty(exports, name, { enumerable: true, get: getter });\n \t\t}\n \t};\n\n \t// define __esModule on exports\n \t__webpack_require__.r = function(exports) {\n \t\tif(typeof Symbol !== 'undefined' && Symbol.toStringTag) {\n \t\t\tObject.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });\n \t\t}\n \t\tObject.defineProperty(exports, '__esModule', { value: true });\n \t};\n\n \t// create a fake namespace object\n \t// mode & 1: value is a module id, require it\n \t// mode & 2: merge all properties of value into the ns\n \t// mode & 4: return value when already ns object\n \t// mode & 8|1: behave like require\n \t__webpack_require__.t = function(value, mode) {\n \t\tif(mode & 1) value = __webpack_require__(value);\n \t\tif(mode & 8) return value;\n \t\tif((mode & 4) && typeof value === 'object' && value && value.__esModule) return value;\n \t\tvar ns = Object.create(null);\n \t\t__webpack_require__.r(ns);\n \t\tObject.defineProperty(ns, 'default', { enumerable: true, value: value });\n \t\tif(mode & 2 && typeof value != 'string') for(var key in value) __webpack_require__.d(ns, key, function(key) { return value[key]; }.bind(null, key));\n \t\treturn ns;\n \t};\n\n \t// getDefaultExport function for compatibility with non-harmony modules\n \t__webpack_require__.n = function(module) {\n \t\tvar getter = module && module.__esModule ?\n \t\t\tfunction getDefault() { return module['default']; } :\n \t\t\tfunction getModuleExports() { return module; };\n \t\t__webpack_require__.d(getter, 'a', getter);\n \t\treturn getter;\n \t};\n\n \t// Object.prototype.hasOwnProperty.call\n \t__webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };\n\n \t// __webpack_public_path__\n \t__webpack_require__.p = \"\";\n\n\n \t// Load entry module and return exports\n \treturn __webpack_require__(__webpack_require__.s = 2);\n","export class ServiceBase {\n private rpcTracker: any;\n private prefix: string = '__surix__';\n\n protected constructor() {\n this.rpcTracker = {};\n this.setUpService();\n }\n\n /**\n * Sends a request to Surixs\n * @param type Request type\n * @param payload Request payload\n */\n protected internalRequest(type: string, payload?: any): Promise {\n return this.rpc(type, payload);\n }\n \n /**\n * Sends a request to Surix \n * ====== TO BE DEPRICATED IN FUTURE =======\n * @param type Request type\n * @param payload Request payload \n * @returns Promise Returns a promise\n */\n public request(type: string, payload?: any): Promise {\n console.warn(`service.request method will be DEPRICATED in future. Please consider using service.${type} instead.`);\n return this.rpc(type, payload);\n }\n\n /**\n * An event listener wrapper \n * @param eventName A string representing the event name\n * @param handler a function that handles event\n */\n public internalOn(eventName: string, handler: any) {\n document.addEventListener(`${this.prefix}${eventName}`, handler);\n }\n\n /**\n * An event listener wrapper \n * ======== TO BE DEPRICATED IN FUTURE ============\n * @param eventName A string representing the event name\n * @param handler a function that handles event\n */\n public on(eventName: string, handler: any) {\n console.warn(`service.on method will be DEPRICATED in future. Please consider using service.events.${eventName} instead.`);\n document.addEventListener(`${this.prefix}${eventName}`, handler);\n }\n\n /**\n * Sends the specified message to Surix\n * @param msg Message to send to Surix\n */\n private sendMessage(msg: any) {\n window.parent.postMessage(msg, '*');\n }\n /**\n * Creates a promise then sends the message\n * @param name Name of the request to send to Surix\n * @param body \n */\n private rpc(name: string, body: any) {\n const reqId = Math.random();\n return new Promise((resolve, reject) => {\n this.rpcTracker[reqId] = { resolve, reject };\n const message = {\n name, \n body, \n type: 'rpcReq', \n id: reqId\n }\n this.sendMessage(message);\n });\n }\n /**\n * This handles the rpcReq type responses from Surix\n * @param msg Response from Surix\n * @param handler Handles the response\n */\n private handleRpcRep(msg: any, handler: any) {\n if(msg.success) {\n handler.rpcTracker[msg.id].resolve(msg.body);\n } else {\n handler.rpcTracker[msg.id].reject(msg.body);\n }\n // Remove the promise from the handler because \n // it has already been taken care of.\n delete handler.rpcTracker[msg.id];\n }\n /**\n * Emits a custom event\n * @param msg Message to be embedded to the custom event to be emitted\n */\n private emit(msg: any) {\n const event: Event = new CustomEvent(`${this.prefix}${msg.name}`, {detail: msg});\n document.dispatchEvent(event);\n }\n /**\n * Sets up Surix service\n */\n protected setUpService() {\n window.addEventListener('message', event => {\n const msg: any = event.data;\n switch(msg.type) {\n case 'rpcRep':\n this.handleRpcRep(msg, this);\n break;\n case 'event':\n this.emit(msg);\n break;\n }\n });\n }\n}","export const requests = {\n data: {\n createEntity: 'data.createEntity',\n project: 'data.project',\n getEntities: 'data.getEntities',\n getEntityById: 'data.getEntityById',\n addTagsToEntity: 'data.addTagsToEntity',\n removeTagsFromEntity: 'data.removeTagsFromEntity',\n getTags: 'data.getTags',\n updateTag: 'data.updateTag',\n getAppData: 'data.getAppData',\n updateAppData: 'data.updateAppData',\n createFile: 'data.createFile',\n getFileById: 'data.getFileById',\n getFiles: 'data.getFiles'\n },\n toast: {\n show: 'toast.show',\n },\n menu: {\n populate: 'menu.populate'\n },\n events: {\n menuItemClicked: 'menu-item-clicked',\n // TODO: this is for backwards compatibility\n // it is deprecated and will be removed in a future update\n menuClicked: 'menu-item-clicked'\n }\n}","import { Service } from './src/service';\nimport { requests } from './src/requests';\nimport { PersistedEntityData } from './src/types';\nexport {\n Service,\n requests\n}","import { ServiceBase } from './service-base';\nimport { Data } from './functions/data';\nimport { Toast } from './functions/toast';\nimport { Menu } from './functions/menu';\nimport { Events } from './functions/events';\nexport class Service extends ServiceBase {\n\n private _data: Data;\n private _toast: Toast;\n private _menu: Menu;\n private _events: Events;\n\n /**\n * Returns all data methods\n */\n public get data (): Data {\n return this._data;\n }\n /**\n * Returns all toast methods\n */\n public get toast (): Toast {\n return this._toast;\n }\n /**\n * Returns all menu methods\n */\n public get menu (): Menu {\n return this._menu;\n }\n\n /**\n * Returns all methods associated with events.\n */\n public get events (): Events {\n return this._events;\n }\n /**\n * Constructor\n */\n private constructor() {\n super();\n this._data = new Data();\n this._toast = new Toast();\n this._menu = new Menu();\n this._events = new Events();\n }\n\n /**\n * Provides Surix singleton\n */\n public static init(): Service {\n if(Service.instance == undefined){\n Service.instance = new Service();\n }\n return Service.instance;\n }\n \n private static instance?: Service = undefined;\n}","import {\n PersistedEntityData,\n TagUpdateParams,\n FileDetails, \n FileParams, \n TagsParams,\n EntityData,\n Project,\n AppData,\n Tag,\n IData,\n PersistedAppData,\n QueryParams\n} from \"../types\";\nimport { requests } from \"../requests\";\nimport { ServiceBase } from \"../service-base\";\n\nexport class Data extends ServiceBase implements IData{\n //public _service: Service;\n \n public constructor() {\n super();\n //this._service = Service.init();\n }\n\n /**\n * Saves an entity in Surix\n * @param entity EntityData entity to be saved\n * @returns Promise\n */\n public async createEntity(entity: EntityData): Promise {\n return await this.internalRequest(requests.data.createEntity, entity);\n }\n\n /**\n * Returns the current project\n * @returns Promise\n */\n public async project(): Promise {\n return await this.internalRequest(requests.data.project);\n }\n\n /**\n * Returns all the entities present\n * @param query (Optional) query\n * @returns Promise\n */\n public async getEntities(query?: QueryParams): Promise {\n return await this.internalRequest(requests.data.getEntities, query);\n }\n\n /**\n * Returns an entity identified by the id provided\n * @param id Surix Id\n * @returns Promise\n */\n public async getEntityById(id: string): Promise {\n return await this.internalRequest(requests.data.getEntityById, id);\n }\n\n /**\n * Adds tags to an existing entity\n * @param params Parameters to add tags\n * @returns Promise\n */\n public async addTagsToEntity(params: TagsParams): Promise {\n return await this.internalRequest(requests.data.addTagsToEntity, params);\n }\n\n /**\n * Removes tags from an entity\n * @param params TagsParams tag parameters\n */\n public async removeTagsFromEntity(params: TagsParams): Promise {\n return await this.internalRequest(requests.data.removeTagsFromEntity, params);\n }\n\n /**\n * Updates tags on an existing entity\n * @param params Update params\n */\n public async updateTag(params: TagUpdateParams): Promise {\n return await this.internalRequest(requests.data.updateTag, params);\n }\n\n /**\n * Returns all the tags available\n * @returns Promise\n */\n public async getTags(): Promise {\n return await this.internalRequest(requests.data.getTags);\n }\n\n public async getAppData(): Promise {\n return await this.internalRequest(requests.data.getAppData);\n }\n public async updateAppData(appData: AppData): Promise {\n return await this.internalRequest(requests.data.updateAppData, appData);\n }\n\n /**\n * Creates a file on Surix linked to the current project.\n * @param file FileMessage message details\n * @returns Promise\n */\n public async createFile(file: FileParams): Promise {\n return await this.internalRequest(requests.data.createFile, file);\n }\n\n /**\n * Gets a file associated with the id provided\n * @param id string Surix Id\n * @returns Promise\n */\n public async getFileById(id: string): Promise {\n return await this.internalRequest(requests.data.getFileById, id);\n }\n\n /**\n * Returns all files\n * @returns Promise\n */\n public async getFiles(): Promise{\n return await this.internalRequest(requests.data.getFiles);\n }\n}","import { ToastParams, IToast } from '../types';\nimport { requests } from '../requests';\nimport { ServiceBase } from '../service-base';\n\nexport class Toast extends ServiceBase implements IToast {\n // private _service: Service;\n\n public constructor() {\n super();\n //this._service = Service.init();\n }\n\n /**\n * Displays the message provided on toast on Surix\n * @param message ToastMessage message to show on the toast\n */\n public show(message: ToastParams): Promise {\n return this.internalRequest(requests.toast.show, message);\n }\n}","import { requests } from '../requests';\nimport { MenuItem } from '../types';\nimport { ServiceBase } from '../service-base';\n\nexport class Menu extends ServiceBase{\n //public _service: Service;\n\n public constructor() {\n super();\n //this._service = Service.init();\n }\n\n /**\n * Populates Surix app menu with the provided items\n * @param menu MenuItem[] menu items\n */\n public populate(menu: MenuItem[]): Promise {\n return this.internalRequest(requests.menu.populate, menu);\n }\n}","import { ServiceBase } from \"../service-base\";\nimport { requests } from \"../..\";\n\nexport class Events extends ServiceBase {\n\n /**\n * Registers an event onto the handler provided.\n * @param handler Function to handle events\n */\n public menuItemClicked(handler: (event: any) => any) {\n this.internalOn(requests.events.menuItemClicked, handler);\n }\n}"],"sourceRoot":""} \ No newline at end of file diff --git a/dist/client-service.min.js b/dist/client-service.min.js index 95ba434..12e2bd2 100644 --- a/dist/client-service.min.js +++ b/dist/client-service.min.js @@ -1 +1 @@ -!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define("Surix",[],e):"object"==typeof exports?exports.Surix=e():t.Surix=e()}(window,function(){return function(t){var e={};function n(r){if(e[r])return e[r].exports;var o=e[r]={i:r,l:!1,exports:{}};return t[r].call(o.exports,o,o.exports,n),o.l=!0,o.exports}return n.m=t,n.c=e,n.d=function(t,e,r){n.o(t,e)||Object.defineProperty(t,e,{enumerable:!0,get:r})},n.r=function(t){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})},n.t=function(t,e){if(1&e&&(t=n(t)),8&e)return t;if(4&e&&"object"==typeof t&&t&&t.__esModule)return t;var r=Object.create(null);if(n.r(r),Object.defineProperty(r,"default",{enumerable:!0,value:t}),2&e&&"string"!=typeof t)for(var o in t)n.d(r,o,function(e){return t[e]}.bind(null,o));return r},n.n=function(t){var e=t&&t.__esModule?function(){return t.default}:function(){return t};return n.d(e,"a",e),e},n.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},n.p="",n(n.s=2)}([function(t,e,n){"use strict";Object.defineProperty(e,"__esModule",{value:!0});var r=function(){function t(){this.prefix="__surix__",this.rpcTracker={},this.setUpService()}return t.prototype.internalRequest=function(t,e){return this.rpc(t,e)},t.prototype.request=function(t,e){return console.warn("service.request method will be DEPRICATED in future. Please consider using service."+t+" instead."),this.rpc(t,e)},t.prototype.internalOn=function(t,e){document.addEventListener(""+this.prefix+t,e)},t.prototype.on=function(t,e){console.warn("service.on method will be DEPRICATED in future. Please consider using service.events."+t+" instead."),document.addEventListener(""+this.prefix+t,e)},t.prototype.sendMessage=function(t){window.parent.postMessage(t,"*")},t.prototype.rpc=function(t,e){var n=this,r=Math.random();return new Promise(function(o,i){n.rpcTracker[r]={resolve:o,reject:i};var u={name:t,body:e,type:"rpcReq",id:r};n.sendMessage(u)})},t.prototype.handleRpcReq=function(t,e){t.success?e.rpcTracker[t.id].resolve(t.body):e.rpcTracker[t.id].reject(t.body),delete e.rpcTracker[t.id]},t.prototype.emit=function(t){var e=new CustomEvent(""+this.prefix+t.name,{detail:t});document.dispatchEvent(e)},t.prototype.setUpService=function(){var t=this;window.addEventListener("message",function(e){var n=e.data;switch(n.type){case"rpcRep":t.handleRpcReq(n,t);break;case"event":t.emit(n)}})},t}();e.ServiceBase=r},function(t,e,n){"use strict";Object.defineProperty(e,"__esModule",{value:!0}),e.requests={data:{createEntity:"data.createEntity",project:"data.project",getEntities:"data.getEntities",getEntityById:"data.getEntityById",addTagsToEntity:"data.addTagsToEntity",removeTagsFromEntity:"data.removeTagsFromEntity",getTags:"data.getTags",updateTag:"data.updateTag",getAppData:"data.getAppData",updateAppData:"data.updateAppData",createFile:"data.createFile",getFileById:"data.getFileById",getFiles:"data.getFiles"},toast:{show:"toast.show"},menu:{populate:"menu.populate"},events:{menuItemClicked:"menu-item-clicked",menuClicked:"menu-item-clicked"}}},function(t,e,n){"use strict";Object.defineProperty(e,"__esModule",{value:!0});var r=n(3);e.Service=r.Service;var o=n(1);e.requests=o.requests},function(t,e,n){"use strict";var r=this&&this.__extends||function(){var t=function(e,n){return(t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var n in e)e.hasOwnProperty(n)&&(t[n]=e[n])})(e,n)};return function(e,n){function r(){this.constructor=e}t(e,n),e.prototype=null===n?Object.create(n):(r.prototype=n.prototype,new r)}}();Object.defineProperty(e,"__esModule",{value:!0});var o=n(0),i=n(4),u=n(5),s=n(6),a=n(7),c=function(t){function e(){var e=t.call(this)||this;return e._data=new i.Data,e._toast=new u.Toast,e._menu=new s.Menu,e._events=new a.Events,e}return r(e,t),Object.defineProperty(e.prototype,"data",{get:function(){return this._data},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"toast",{get:function(){return this._toast},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"menu",{get:function(){return this._menu},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"events",{get:function(){return this._events},enumerable:!0,configurable:!0}),e.init=function(){return void 0==e.instance&&(e.instance=new e),e.instance},e.instance=void 0,e}(o.ServiceBase);e.Service=c},function(t,e,n){"use strict";var r=this&&this.__extends||function(){var t=function(e,n){return(t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var n in e)e.hasOwnProperty(n)&&(t[n]=e[n])})(e,n)};return function(e,n){function r(){this.constructor=e}t(e,n),e.prototype=null===n?Object.create(n):(r.prototype=n.prototype,new r)}}(),o=this&&this.__awaiter||function(t,e,n,r){return new(n||(n=Promise))(function(o,i){function u(t){try{a(r.next(t))}catch(t){i(t)}}function s(t){try{a(r.throw(t))}catch(t){i(t)}}function a(t){t.done?o(t.value):new n(function(e){e(t.value)}).then(u,s)}a((r=r.apply(t,e||[])).next())})},i=this&&this.__generator||function(t,e){var n,r,o,i,u={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:s(0),throw:s(1),return:s(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function s(i){return function(s){return function(i){if(n)throw new TypeError("Generator is already executing.");for(;u;)try{if(n=1,r&&(o=2&i[0]?r.return:i[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,i[1])).done)return o;switch(r=0,o&&(i=[2&i[0],o.value]),i[0]){case 0:case 1:o=i;break;case 4:return u.label++,{value:i[1],done:!1};case 5:u.label++,r=i[1],i=[0];continue;case 7:i=u.ops.pop(),u.trys.pop();continue;default:if(!(o=(o=u.trys).length>0&&o[o.length-1])&&(6===i[0]||2===i[0])){u=0;continue}if(3===i[0]&&(!o||i[1]>o[0]&&i[1]0&&o[o.length-1])&&(6===i[0]||2===i[0])){u=0;continue}if(3===i[0]&&(!o||i[1]>o[0]&&i[1] */ - getEntities(query?: any): Promise; + getEntities(query?: QueryParams): Promise; /** * Returns an entity identified by the id provided * @param id Surix Id diff --git a/dist/src/service-base.d.ts b/dist/src/service-base.d.ts index 52084ad..8b673f9 100644 --- a/dist/src/service-base.d.ts +++ b/dist/src/service-base.d.ts @@ -45,7 +45,7 @@ export declare class ServiceBase { * @param msg Response from Surix * @param handler Handles the response */ - private handleRpcReq; + private handleRpcRep; /** * Emits a custom event * @param msg Message to be embedded to the custom event to be emitted diff --git a/dist/src/types.d.ts b/dist/src/types.d.ts index 1587118..a936c0b 100644 --- a/dist/src/types.d.ts +++ b/dist/src/types.d.ts @@ -49,6 +49,21 @@ export interface MenuItem { default?: boolean; } +export interface QueryMatch { + [fieldOrOp: string]: any; +} + +export interface QueryParams { + [key: string]: any; + query?: QueryMatch; + limit?: number; + skip?: number; + sort?: { + [field: string]: number; + }; + tags?: string[]; +} + export interface FileParams { name: string; public: boolean; @@ -109,7 +124,7 @@ interface HasTimestamps { export interface IData { createEntity(entity: EntityData): Promise; project(): Promise; - getEntities(query?: any): Promise; + getEntities(query?: QueryParams): Promise; getEntityById(id: string): Promise; addTagsToEntity(params: TagsParams): Promise; removeTagsFromEntity(params: TagsParams): Promise; From b20671632dc3cddde451290672804a83762949ae Mon Sep 17 00:00:00 2001 From: Kevin Nderitu Date: Fri, 23 Nov 2018 12:23:06 +0300 Subject: [PATCH 9/9] Updated version in README --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 1e808f5..78ffe83 100644 --- a/README.md +++ b/README.md @@ -15,7 +15,7 @@ const requests = Surix.requests; ``` or ```javascript - + const service = Surix.Service.init(); const requests = Surix.requests; ```