akio-browser
Advanced tools
Comparing version 0.2.0 to 0.3.0
@@ -8,2 +8,6 @@ "use strict"; | ||
require("core-js/modules/es6.array.index-of"); | ||
require("core-js/modules/es6.promise"); | ||
require("core-js/modules/es6.array.for-each"); | ||
@@ -13,4 +17,2 @@ | ||
require("core-js/modules/es6.array.index-of"); | ||
require("core-js/modules/web.dom.iterable"); | ||
@@ -22,4 +24,2 @@ | ||
require("core-js/modules/es6.promise"); | ||
require("core-js/modules/es6.object.define-property"); | ||
@@ -43,6 +43,2 @@ | ||
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; var ownKeys = Object.keys(source); if (typeof Object.getOwnPropertySymbols === 'function') { ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function (sym) { return Object.getOwnPropertyDescriptor(source, sym).enumerable; })); } ownKeys.forEach(function (key) { _defineProperty(target, key, source[key]); }); } return target; } | ||
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; } | ||
function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; } | ||
@@ -56,2 +52,6 @@ | ||
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; var ownKeys = Object.keys(source); if (typeof Object.getOwnPropertySymbols === 'function') { ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function (sym) { return Object.getOwnPropertyDescriptor(source, sym).enumerable; })); } ownKeys.forEach(function (key) { _defineProperty(target, key, source[key]); }); } return target; } | ||
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; } | ||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } | ||
@@ -69,72 +69,28 @@ | ||
function () { | ||
_createClass(Akio, null, [{ | ||
key: "init", | ||
value: function () { | ||
var _init = _asyncToGenerator( | ||
/*#__PURE__*/ | ||
regeneratorRuntime.mark(function _callee() { | ||
var _ref, | ||
token, | ||
config, | ||
akio, | ||
_args = arguments; | ||
return regeneratorRuntime.wrap(function _callee$(_context) { | ||
while (1) { | ||
switch (_context.prev = _context.next) { | ||
case 0: | ||
_ref = _args.length > 0 && _args[0] !== undefined ? _args[0] : {}, token = _ref.token, config = _objectWithoutProperties(_ref, ["token"]); | ||
akio = new Akio({ | ||
token: token, | ||
config: config | ||
}); | ||
_context.next = 4; | ||
return akio.init(); | ||
case 4: | ||
return _context.abrupt("return", akio); | ||
case 5: | ||
case "end": | ||
return _context.stop(); | ||
} | ||
} | ||
}, _callee); | ||
})); | ||
function init() { | ||
return _init.apply(this, arguments); | ||
} | ||
return init; | ||
}() | ||
}]); | ||
function Akio() { | ||
var _ref2 = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}, | ||
token = _ref2.token, | ||
config = _ref2.config; | ||
_classCallCheck(this, Akio); | ||
// Configure the SDK with user-defined config and also initialize the | ||
// API connection. | ||
this.config = _objectSpread({}, _config.DEFAULT_CONFIG, config); | ||
this.logger = new _logging.Logger({ | ||
debug: this.config.debug, | ||
verbose: this.config.verbose | ||
}); | ||
this.storage = this.getStorage(); | ||
this.api = new _handyApi.default({ | ||
baseUrl: this.config.apiHost | ||
}); // Load up the user and source information from the browser / storage. | ||
this.token = token; | ||
this.sessionId = this.storage.get({ | ||
key: AKIO_SESSION_ID_KEY | ||
}); | ||
this.userId = null; | ||
} | ||
_createClass(Akio, [{ | ||
key: "setUp", | ||
value: function setUp() { | ||
var config = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; | ||
// Configure the SDK with user-defined config and also initialize the | ||
// API connection. | ||
this.config = _objectSpread({}, _config.DEFAULT_CONFIG, config); | ||
this.logger = new _logging.Logger({ | ||
debug: this.config.debug, | ||
verbose: this.config.verbose | ||
}); | ||
this.storage = this.getStorage(); | ||
this.api = new _handyApi.default({ | ||
baseUrl: this.config.apiHost | ||
}); // Load up the user and source information from the browser / storage. | ||
this.sessionId = this.storage.get({ | ||
key: AKIO_SESSION_ID_KEY | ||
}); | ||
this.userId = null; | ||
} | ||
}, { | ||
key: "getStorageType", | ||
@@ -188,22 +144,34 @@ value: function getStorageType() { | ||
value: function () { | ||
var _init2 = _asyncToGenerator( | ||
var _init = _asyncToGenerator( | ||
/*#__PURE__*/ | ||
regeneratorRuntime.mark(function _callee2() { | ||
var token, sessionId, response, json; | ||
return regeneratorRuntime.wrap(function _callee2$(_context2) { | ||
regeneratorRuntime.mark(function _callee(_ref) { | ||
var token, config, sessionId, response, json; | ||
return regeneratorRuntime.wrap(function _callee$(_context) { | ||
while (1) { | ||
switch (_context2.prev = _context2.next) { | ||
switch (_context.prev = _context.next) { | ||
case 0: | ||
token = this.token, sessionId = this.sessionId; | ||
token = _ref.token, config = _objectWithoutProperties(_ref, ["token"]); | ||
// Re-initializing the SDK should re-set it up. | ||
this.setUp(config); | ||
sessionId = this.sessionId; | ||
this.token = token; | ||
if (sessionId) { | ||
_context.next = 6; | ||
break; | ||
} | ||
return _context.abrupt("return", this.logger.error("Error initializing Akio SDK.")); | ||
case 6: | ||
if (token) { | ||
_context2.next = 3; | ||
_context.next = 8; | ||
break; | ||
} | ||
return _context2.abrupt("return", this.logger.error("'init' missing required parameter 'token'.")); | ||
return _context.abrupt("return", this.logger.error("'init' missing required parameter 'token'.")); | ||
case 3: | ||
case 8: | ||
this.logger.verbose("'init' with token: ".concat(token, ".")); | ||
_context2.next = 6; | ||
_context.next = 11; | ||
return this.post({ | ||
@@ -217,18 +185,18 @@ path: '/init', | ||
case 6: | ||
response = _context2.sent; | ||
_context2.next = 9; | ||
case 11: | ||
response = _context.sent; | ||
_context.next = 14; | ||
return response.json(); | ||
case 9: | ||
json = _context2.sent; | ||
case 14: | ||
json = _context.sent; | ||
if (!(response.status !== 200)) { | ||
_context2.next = 12; | ||
_context.next = 17; | ||
break; | ||
} | ||
return _context2.abrupt("return", this.logger.error("Failed to init: ".concat(json.error))); | ||
return _context.abrupt("return", this.logger.error("Failed to init: ".concat(json.error))); | ||
case 12: | ||
case 17: | ||
// If we get a valid response, save the session_id. | ||
@@ -241,12 +209,12 @@ this.sessionId = json.session_id; | ||
case 14: | ||
case 19: | ||
case "end": | ||
return _context2.stop(); | ||
return _context.stop(); | ||
} | ||
} | ||
}, _callee2, this); | ||
}, _callee, this); | ||
})); | ||
function init() { | ||
return _init2.apply(this, arguments); | ||
function init(_x) { | ||
return _init.apply(this, arguments); | ||
} | ||
@@ -261,4 +229,4 @@ | ||
/*#__PURE__*/ | ||
regeneratorRuntime.mark(function _callee3() { | ||
var _ref3, | ||
regeneratorRuntime.mark(function _callee2() { | ||
var _ref2, | ||
userId, | ||
@@ -269,9 +237,9 @@ userAddress, | ||
sessionId, | ||
_args3 = arguments; | ||
_args2 = arguments; | ||
return regeneratorRuntime.wrap(function _callee3$(_context3) { | ||
return regeneratorRuntime.wrap(function _callee2$(_context2) { | ||
while (1) { | ||
switch (_context3.prev = _context3.next) { | ||
switch (_context2.prev = _context2.next) { | ||
case 0: | ||
_ref3 = _args3.length > 0 && _args3[0] !== undefined ? _args3[0] : {}, userId = _ref3.userId, userAddress = _ref3.userAddress, properties = _objectWithoutProperties(_ref3, ["userId", "userAddress"]); | ||
_ref2 = _args2.length > 0 && _args2[0] !== undefined ? _args2[0] : {}, userId = _ref2.userId, userAddress = _ref2.userAddress, properties = _objectWithoutProperties(_ref2, ["userId", "userAddress"]); | ||
token = this.token, sessionId = this.sessionId; | ||
@@ -282,19 +250,19 @@ this.userId = userId; | ||
if (!(!token || !sessionId)) { | ||
_context3.next = 6; | ||
_context2.next = 6; | ||
break; | ||
} | ||
return _context3.abrupt("return", this.logger.error("Called 'identify' before successful 'init'.")); | ||
return _context2.abrupt("return", this.logger.error("Called 'identify' before successful 'init'.")); | ||
case 6: | ||
if (userId) { | ||
_context3.next = 8; | ||
_context2.next = 8; | ||
break; | ||
} | ||
return _context3.abrupt("return", this.logger.error("'identify' missing required parameter 'userId'.")); | ||
return _context2.abrupt("return", this.logger.error("'identify' missing required parameter 'userId'.")); | ||
case 8: | ||
this.logger.verbose("'identify' with userId: ".concat(userId, ".")); | ||
return _context3.abrupt("return", this.post({ | ||
return _context2.abrupt("return", this.post({ | ||
path: '/identify', | ||
@@ -313,6 +281,6 @@ params: { | ||
case "end": | ||
return _context3.stop(); | ||
return _context2.stop(); | ||
} | ||
} | ||
}, _callee3, this); | ||
}, _callee2, this); | ||
})); | ||
@@ -331,4 +299,4 @@ | ||
/*#__PURE__*/ | ||
regeneratorRuntime.mark(function _callee4() { | ||
var _ref4, | ||
regeneratorRuntime.mark(function _callee3() { | ||
var _ref3, | ||
event, | ||
@@ -340,29 +308,29 @@ properties, | ||
userAddress, | ||
_args4 = arguments; | ||
_args3 = arguments; | ||
return regeneratorRuntime.wrap(function _callee4$(_context4) { | ||
return regeneratorRuntime.wrap(function _callee3$(_context3) { | ||
while (1) { | ||
switch (_context4.prev = _context4.next) { | ||
switch (_context3.prev = _context3.next) { | ||
case 0: | ||
_ref4 = _args4.length > 0 && _args4[0] !== undefined ? _args4[0] : {}, event = _ref4.event, properties = _objectWithoutProperties(_ref4, ["event"]); | ||
_ref3 = _args3.length > 0 && _args3[0] !== undefined ? _args3[0] : {}, event = _ref3.event, properties = _objectWithoutProperties(_ref3, ["event"]); | ||
token = this.token, sessionId = this.sessionId, userId = this.userId, userAddress = this.userAddress; | ||
if (!(!token || !sessionId)) { | ||
_context4.next = 4; | ||
_context3.next = 4; | ||
break; | ||
} | ||
return _context4.abrupt("return", this.logger.error("Called 'track' before successful 'init'.")); | ||
return _context3.abrupt("return", this.logger.error("Called 'track' before successful 'init'.")); | ||
case 4: | ||
if (event) { | ||
_context4.next = 6; | ||
_context3.next = 6; | ||
break; | ||
} | ||
return _context4.abrupt("return", this.logger.error("'track' missing required parameter 'event'.")); | ||
return _context3.abrupt("return", this.logger.error("'track' missing required parameter 'event'.")); | ||
case 6: | ||
this.logger.verbose("'track' with event: ".concat(event, ".")); | ||
return _context4.abrupt("return", this.post({ | ||
return _context3.abrupt("return", this.post({ | ||
path: '/track', | ||
@@ -383,6 +351,6 @@ params: { | ||
case "end": | ||
return _context4.stop(); | ||
return _context3.stop(); | ||
} | ||
} | ||
}, _callee4, this); | ||
}, _callee3, this); | ||
})); | ||
@@ -401,14 +369,14 @@ | ||
/*#__PURE__*/ | ||
regeneratorRuntime.mark(function _callee5() { | ||
var _ref5, | ||
regeneratorRuntime.mark(function _callee4() { | ||
var _ref4, | ||
path, | ||
params, | ||
_args5 = arguments; | ||
_args4 = arguments; | ||
return regeneratorRuntime.wrap(function _callee5$(_context5) { | ||
return regeneratorRuntime.wrap(function _callee4$(_context4) { | ||
while (1) { | ||
switch (_context5.prev = _context5.next) { | ||
switch (_context4.prev = _context4.next) { | ||
case 0: | ||
_ref5 = _args5.length > 0 && _args5[0] !== undefined ? _args5[0] : {}, path = _ref5.path, params = _ref5.params; | ||
return _context5.abrupt("return", this.api.request({ | ||
_ref4 = _args4.length > 0 && _args4[0] !== undefined ? _args4[0] : {}, path = _ref4.path, params = _ref4.params; | ||
return _context4.abrupt("return", this.api.request({ | ||
method: 'POST', | ||
@@ -428,6 +396,6 @@ path: path, | ||
case "end": | ||
return _context5.stop(); | ||
return _context4.stop(); | ||
} | ||
} | ||
}, _callee5, this); | ||
}, _callee4, this); | ||
})); | ||
@@ -441,2 +409,37 @@ | ||
}() | ||
}], [{ | ||
key: "init", | ||
value: function () { | ||
var _init2 = _asyncToGenerator( | ||
/*#__PURE__*/ | ||
regeneratorRuntime.mark(function _callee5() { | ||
var options, | ||
akio, | ||
_args5 = arguments; | ||
return regeneratorRuntime.wrap(function _callee5$(_context5) { | ||
while (1) { | ||
switch (_context5.prev = _context5.next) { | ||
case 0: | ||
options = _args5.length > 0 && _args5[0] !== undefined ? _args5[0] : {}; | ||
akio = new Akio(); | ||
_context5.next = 4; | ||
return akio.init(options); | ||
case 4: | ||
return _context5.abrupt("return", akio); | ||
case 5: | ||
case "end": | ||
return _context5.stop(); | ||
} | ||
} | ||
}, _callee5); | ||
})); | ||
function init() { | ||
return _init2.apply(this, arguments); | ||
} | ||
return init; | ||
}() | ||
}]); | ||
@@ -443,0 +446,0 @@ |
{ | ||
"name": "akio-browser", | ||
"version": "0.2.0", | ||
"version": "0.3.0", | ||
"main": "build/akio.js", | ||
@@ -5,0 +5,0 @@ "dependencies": { |
@@ -15,9 +15,9 @@ // Libraries | ||
class Akio { | ||
static async init({token, ...config} = {}) { | ||
const akio = new Akio({token, config}); | ||
await akio.init(); | ||
static async init(options = {}) { | ||
const akio = new Akio(); | ||
await akio.init(options); | ||
return akio; | ||
} | ||
constructor({token, config} = {}) { | ||
setUp(config = {}) { | ||
// Configure the SDK with user-defined config and also initialize the | ||
@@ -33,3 +33,2 @@ // API connection. | ||
// Load up the user and source information from the browser / storage. | ||
this.token = token; | ||
this.sessionId = this.storage.get({key: AKIO_SESSION_ID_KEY}); | ||
@@ -76,5 +75,13 @@ this.userId = null; | ||
async init() { | ||
const {token, sessionId} = this; | ||
async init({token, ...config}) { | ||
// Re-initializing the SDK should re-set it up. | ||
this.setUp(config); | ||
const {sessionId} = this; | ||
this.token = token; | ||
if (!sessionId) { | ||
return this.logger.error(`Error initializing Akio SDK.`); | ||
} | ||
if (!token) { | ||
@@ -81,0 +88,0 @@ return this.logger.error(`'init' missing required parameter 'token'.`) |
130932
863