UNPKG

@smontero/ppp-client-api

Version:

Project People & Profile client api

171 lines (145 loc) 4.23 kB
"use strict"; var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); Object.defineProperty(exports, "__esModule", { value: true }); exports["default"] = void 0; var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck")); var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass")); var _awsAmplify = _interopRequireDefault(require("aws-amplify")); var _assert = _interopRequireDefault(require("assert")); var _events = require("events"); var _service = require("./service"); var _util = require("./util"); var config = { test: { AWS: { Auth: { region: "us-east-1", userPoolId: "us-east-1_gd8OvMUK6", userPoolWebClientId: "7teoo5g0smkmcv5nbnc5k0je1i", identityPoolId: "us-east-1:d12d4fad-28f0-4fa6-ac6c-d07329f1107c" }, Storage: { AWSS3: { region: "us-east-1", bucket: "ppp-service-dev-attachmentsbucket-1mf7xzdc3x721" } }, API: { endpoints: [{ name: "profileApi", endpoint: "https://qberjy1f98.execute-api.us-east-1.amazonaws.com/dev" }] } }, loginContract: "logintester1", maxImageSize: "1000000", imageTypes: "image/png, image/jpeg" }, prod: { AWS: { Auth: { region: "us-east-1", userPoolId: "us-east-1_9voNzsQ2J", userPoolWebClientId: "6a2p1a1jsei5ttp3t3vro1f0c5", identityPoolId: "us-east-1:58bf768c-7607-41eb-b512-78314549d61b" }, Storage: { AWSS3: { region: "us-east-1", bucket: "ppp-service-prod-attachmentsbucket-1qc5rzodik7x6" } }, API: { endpoints: [{ name: "profileApi", endpoint: "https://ttac1sv2yj.execute-api.us-east-1.amazonaws.com/prod" }] } }, loginContract: "eosio.login", maxImageSize: "1000000", imageTypes: "image/png, image/jpeg" } }; var PPP = /*#__PURE__*/ function () { function PPP() { (0, _classCallCheck2["default"])(this, PPP); } (0, _createClass2["default"])(PPP, null, [{ key: "configure", /** * Configures the PPP client * @param {string} environment to be used test or prod * @param {string} [originAppId] required for standalone apps, the appId of the app using the PPP client */ value: function configure(environment, originAppId) { this._config = config[environment]; this.originAppId = originAppId; if (!this._config) { throw Error("No configuration found for specified environment: ".concat(environment)); } _awsAmplify["default"].configure(this._config.AWS); } }, { key: "getConfig", value: function getConfig(property) { (0, _assert["default"])(this._config, "PPP configure method should be called first"); return _util.Util.getPath(this._config, property); } }, { key: "setActiveUser", value: function setActiveUser(activeUser) { this.activeUser = activeUser; this.events.emit('activeUserChanged', activeUser); } /** * @returns {AuthApi} */ }, { key: "authApi", value: function authApi() { if (!this._authApi) { this._authApi = new _service.AuthApi(this.activeUser); this._authApi.init(); this._authApi.on('signOut', function () { return PPP.setActiveUser(null); }); } return this._authApi; } /** * @returns {ProfileApi} */ }, { key: "profileApi", value: function profileApi() { if (!this._profileApi) { this._profileApi = new _service.ProfileApi(this.activeUser); this._profileApi.init(); } return this._profileApi; } /** * @returns {OauthApi} */ }, { key: "oauthApi", value: function oauthApi() { if (!this._oauthApi) { this._oauthApi = new _service.OauthApi(this.activeUser); this._oauthApi.init(); } return this._oauthApi; } }]); return PPP; }(); PPP._config = null; PPP.activeUser = null; PPP.events = new _events.EventEmitter(); var _default = PPP; exports["default"] = _default;