@como/como-client
Advanced tools
Comparing version 0.1.14 to 0.1.15
@@ -39,9 +39,2 @@ 'use strict'; | ||
var updateLocalCreds = function updateLocalCreds(credentials) { | ||
comoData.accessToken = credentials.accessToken; | ||
comoData.token = credentials.accessToken; | ||
comoData.refreshToken = credentials.refreshToken; | ||
comoData.expiresIn = credentials.expiresIn; | ||
}; | ||
var refreshTokenIfNeeded = function () { | ||
@@ -57,3 +50,3 @@ var _ref = (0, _asyncToGenerator3.default)( /*#__PURE__*/_regenerator2.default.mark(function _callee() { | ||
if (!moment(expiresIn).subtract(10, 'seconds').isBefore(moment())) { | ||
if (!(expiresIn && moment(expiresIn).subtract(10, 'seconds').isBefore(moment()))) { | ||
_context.next = 4; | ||
@@ -169,3 +162,3 @@ break; | ||
updateLocalCreds(creds); | ||
como.updateLocalCreds(creds); | ||
if (refreshCallback && isNew) { | ||
@@ -210,2 +203,20 @@ refreshCallback(creds); | ||
/** | ||
* Updates the como.js local credentials settings. | ||
* Used when making api calls to janua. | ||
* | ||
* @param {Object} credentials credentials to update. | ||
* @param {Object} accessToken access token to update. | ||
* @param {Object} refreshToken refresh token to update. | ||
* @param {Object} expiresIn access token expiry date to update. | ||
*/ | ||
como.updateLocalCreds = function () { | ||
var credentials = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; | ||
comoData.accessToken = credentials.accessToken; | ||
comoData.token = credentials.accessToken; | ||
comoData.refreshToken = credentials.refreshToken; | ||
comoData.expiresIn = credentials.expiresIn; | ||
}; | ||
como.getExternalUrlByID = function (itemID, gpsData, assetID, accessibilityData) { | ||
@@ -257,3 +268,3 @@ var locationData = comoData.mainResources[resourceNames.LOCATION_DATA]; | ||
return function (_x6, _x7, _x8, _x9) { | ||
return function (_x7, _x8, _x9, _x10) { | ||
return _ref4.apply(this, arguments); | ||
@@ -325,3 +336,3 @@ }; | ||
return function (_x10) { | ||
return function (_x11) { | ||
return _ref6.apply(this, arguments); | ||
@@ -377,3 +388,3 @@ }; | ||
return function (_x11, _x12, _x13) { | ||
return function (_x12, _x13, _x14) { | ||
return _ref7.apply(this, arguments); | ||
@@ -428,3 +439,3 @@ }; | ||
return function (_x14, _x15) { | ||
return function (_x15, _x16) { | ||
return _ref8.apply(this, arguments); | ||
@@ -496,3 +507,3 @@ }; | ||
return function (_x16, _x17, _x18) { | ||
return function (_x17, _x18, _x19) { | ||
return _ref9.apply(this, arguments); | ||
@@ -575,3 +586,3 @@ }; | ||
return function (_x19, _x20) { | ||
return function (_x20, _x21) { | ||
return _ref13.apply(this, arguments); | ||
@@ -623,3 +634,3 @@ }; | ||
return function (_x21) { | ||
return function (_x22) { | ||
return _ref14.apply(this, arguments); | ||
@@ -786,3 +797,3 @@ }; | ||
return function (_x22) { | ||
return function (_x23) { | ||
return _ref19.apply(this, arguments); | ||
@@ -820,3 +831,3 @@ }; | ||
return function (_x23) { | ||
return function (_x24) { | ||
return _ref20.apply(this, arguments); | ||
@@ -1257,2 +1268,49 @@ }; | ||
como.addPaymentMethod = function () { | ||
var _ref29 = (0, _asyncToGenerator3.default)( /*#__PURE__*/_regenerator2.default.mark(function _callee28(cardToken) { | ||
var _comoData33, api, locationId, token, env; | ||
return _regenerator2.default.wrap(function _callee28$(_context28) { | ||
while (1) { | ||
switch (_context28.prev = _context28.next) { | ||
case 0: | ||
_comoData33 = comoData, api = _comoData33.api, locationId = _comoData33.locationId, token = _comoData33.token, env = _comoData33.env_params; | ||
return _context28.abrupt('return', api.addPaymentMethod(env.services_root, locationId, token, cardToken)); | ||
case 2: | ||
case 'end': | ||
return _context28.stop(); | ||
} | ||
} | ||
}, _callee28, undefined); | ||
})); | ||
return function (_x25) { | ||
return _ref29.apply(this, arguments); | ||
}; | ||
}(); | ||
como.getPaymentMethods = (0, _asyncToGenerator3.default)( /*#__PURE__*/_regenerator2.default.mark(function _callee29() { | ||
var _comoData34, env, locationId, api, responseJson; | ||
return _regenerator2.default.wrap(function _callee29$(_context29) { | ||
while (1) { | ||
switch (_context29.prev = _context29.next) { | ||
case 0: | ||
_comoData34 = comoData, env = _comoData34.env_params, locationId = _comoData34.locationId, api = _comoData34.api; | ||
_context29.next = 3; | ||
return api.getPaymentMethods(env.services_root, locationId); | ||
case 3: | ||
responseJson = _context29.sent; | ||
return _context29.abrupt('return', responseJson); | ||
case 5: | ||
case 'end': | ||
return _context29.stop(); | ||
} | ||
} | ||
}, _callee29, undefined); | ||
})); | ||
module.exports = como; |
@@ -5,6 +5,6 @@ 'use strict'; | ||
hotfix: { | ||
gateway: 'https://janua-dev.como.com', | ||
gateway: 'https://janua-env.como.com', | ||
zapp_root: 'loyalty-zapp', | ||
services_root: 'loyalty-services', | ||
app_modules_root: 'https://janua-dev.como.com/app-modules', | ||
app_modules_root: 'https://janua-env.como.com/app-modules', | ||
app_modules_legacy_root: 'https://appmodules-hotfix.como.com' | ||
@@ -11,0 +11,0 @@ }, |
@@ -87,3 +87,3 @@ 'use strict'; | ||
_context3.next = 3; | ||
return service.post('/v1/auth/registerVerify', body); | ||
return service.post('/v1/auth/register-verify', body); | ||
@@ -90,0 +90,0 @@ case 3: |
@@ -591,2 +591,62 @@ 'use strict'; | ||
}(); | ||
}; | ||
exports.addPaymentMethod = function (service) { | ||
return function () { | ||
var _ref29 = (0, _asyncToGenerator3.default)( /*#__PURE__*/_regenerator2.default.mark(function _callee18(baseUrl, locationId, token, cardToken) { | ||
var url, response; | ||
return _regenerator2.default.wrap(function _callee18$(_context18) { | ||
while (1) { | ||
switch (_context18.prev = _context18.next) { | ||
case 0: | ||
url = baseUrl + '/payments/v2/methods/' + cardToken + '?locationId=' + locationId; | ||
_context18.next = 3; | ||
return service.post(url); | ||
case 3: | ||
response = _context18.sent; | ||
return _context18.abrupt('return', response); | ||
case 5: | ||
case 'end': | ||
return _context18.stop(); | ||
} | ||
} | ||
}, _callee18, undefined); | ||
})); | ||
return function (_x54, _x55, _x56, _x57) { | ||
return _ref29.apply(this, arguments); | ||
}; | ||
}(); | ||
}; | ||
exports.getPaymentMethods = function (service) { | ||
return function () { | ||
var _ref30 = (0, _asyncToGenerator3.default)( /*#__PURE__*/_regenerator2.default.mark(function _callee19(baseUrl, locationId) { | ||
var url, res; | ||
return _regenerator2.default.wrap(function _callee19$(_context19) { | ||
while (1) { | ||
switch (_context19.prev = _context19.next) { | ||
case 0: | ||
url = baseUrl + '/payments/v2/methods?locationId=' + locationId + '&InputType=json&MimeType=application/json'; | ||
_context19.next = 3; | ||
return service.get(url); | ||
case 3: | ||
res = _context19.sent; | ||
return _context19.abrupt('return', res); | ||
case 5: | ||
case 'end': | ||
return _context19.stop(); | ||
} | ||
} | ||
}, _callee19, undefined); | ||
})); | ||
return function (_x58, _x59) { | ||
return _ref30.apply(this, arguments); | ||
}; | ||
}(); | ||
}; |
{ | ||
"name": "@como/como-client", | ||
"version": "0.1.14", | ||
"version": "0.1.15", | ||
"description": "Client module for Como's loaylty API", | ||
@@ -5,0 +5,0 @@ "main": "src/como.js", |
@@ -23,12 +23,5 @@ const moment = require('moment-timezone'); | ||
const updateLocalCreds = credentials => { | ||
comoData.accessToken = credentials.accessToken; | ||
comoData.token = credentials.accessToken; | ||
comoData.refreshToken = credentials.refreshToken; | ||
comoData.expiresIn = credentials.expiresIn; | ||
}; | ||
const refreshTokenIfNeeded = async () => { | ||
const { refresher, expiresIn } = comoData; | ||
if (moment(expiresIn).subtract(10, 'seconds').isBefore(moment())) { | ||
if (expiresIn && moment(expiresIn).subtract(10, 'seconds').isBefore(moment())) { | ||
await refresher(); | ||
@@ -87,3 +80,3 @@ } | ||
const updateCredentials = (creds, isNew = false) => { | ||
updateLocalCreds(creds); | ||
como.updateLocalCreds(creds); | ||
if (refreshCallback && isNew) { | ||
@@ -110,2 +103,17 @@ refreshCallback(creds); | ||
/** | ||
* Updates the como.js local credentials settings. | ||
* Used when making api calls to janua. | ||
* | ||
* @param {Object} credentials credentials to update. | ||
* @param {Object} accessToken access token to update. | ||
* @param {Object} refreshToken refresh token to update. | ||
* @param {Object} expiresIn access token expiry date to update. | ||
*/ | ||
como.updateLocalCreds = (credentials = {}) => { | ||
comoData.accessToken = credentials.accessToken; | ||
comoData.token = credentials.accessToken; | ||
comoData.refreshToken = credentials.refreshToken; | ||
comoData.expiresIn = credentials.expiresIn; | ||
}; | ||
@@ -642,3 +650,17 @@ como.getExternalUrlByID = (itemID, gpsData, assetID, accessibilityData) => { | ||
como.addPaymentMethod = async cardToken => { | ||
const { | ||
api, locationId, token, env_params: env, | ||
} = comoData; | ||
return api.addPaymentMethod(env.services_root, locationId, token, cardToken); | ||
}; | ||
como.getPaymentMethods = async () => { | ||
const { | ||
env_params: env, locationId, api, | ||
} = comoData; | ||
const responseJson = await api.getPaymentMethods(env.services_root, locationId); | ||
return responseJson; | ||
}; | ||
module.exports = como; |
module.exports = { | ||
hotfix: { | ||
gateway: 'https://janua-dev.como.com', | ||
gateway: 'https://janua-env.como.com', | ||
zapp_root: 'loyalty-zapp', | ||
services_root: 'loyalty-services', | ||
app_modules_root: 'https://janua-dev.como.com/app-modules', | ||
app_modules_root: 'https://janua-env.como.com/app-modules', | ||
app_modules_legacy_root: 'https://appmodules-hotfix.como.com', | ||
@@ -8,0 +8,0 @@ }, |
@@ -14,3 +14,3 @@ exports.signOn = service => async (deviceId, locationId) => { | ||
const body = { code, type, form }; | ||
const { data } = await service.post('/v1/auth/registerVerify', body); | ||
const { data } = await service.post('/v1/auth/register-verify', body); | ||
return data; | ||
@@ -17,0 +17,0 @@ }; |
@@ -142,1 +142,13 @@ const moment = require('moment-timezone'); | ||
}; | ||
exports.addPaymentMethod = service => async (baseUrl, locationId, token, cardToken) => { | ||
const url = `${baseUrl}/payments/v2/methods/${cardToken}?locationId=${locationId}`; | ||
const response = await service.post(url); | ||
return response; | ||
}; | ||
exports.getPaymentMethods = service => async (baseUrl, locationId) => { | ||
const url = `${baseUrl}/payments/v2/methods?locationId=${locationId}&InputType=json&MimeType=application/json`; | ||
const res = await service.get(url); | ||
return res; | ||
}; |
331490
3487