remote-pay-cloud
Advanced tools
Comparing version 0.0.4 to 0.0.5
@@ -1,2 +0,1 @@ | ||
/** | ||
@@ -18,7 +17,13 @@ * Method of card entry | ||
CardEntryMethods.DEFAULT = ( | ||
CardEntryMethods.ICC_CONTACT | | ||
CardEntryMethods.MAG_STRIPE | | ||
CardEntryMethods.NFC_CONTACTLESS | ||
); | ||
CardEntryMethods.ALL = ( | ||
CardEntryMethods.ICC_CONTACT | | ||
CardEntryMethods.MAG_STRIPE | | ||
CardEntryMethods.NFC_CONTACTLESS | | ||
CardEntryMethods.MANUAL | ||
CardEntryMethods.ICC_CONTACT | | ||
CardEntryMethods.MAG_STRIPE | | ||
CardEntryMethods.NFC_CONTACTLESS | | ||
CardEntryMethods.MANUAL | ||
); | ||
@@ -25,0 +30,0 @@ |
@@ -5,4 +5,4 @@ /** | ||
* @param {string} code a code to classify the error. | ||
* @param {string} message the error message | ||
* @param {Error} cause the original cause of the error if this wraps some lower level system error. | ||
* @param {string} [message] the error message | ||
* @param {Error} [cause] the original cause of the error if this wraps some lower level system error. | ||
* @constructor | ||
@@ -9,0 +9,0 @@ */ |
@@ -1,2 +0,1 @@ | ||
/** | ||
@@ -6,7 +5,7 @@ * Utility to centralize endpoints. | ||
* @constructor | ||
* @param {CloverOAuth} cloverOAuth - used to obtain the access token and the domain for building the endpoints. If | ||
* @param {EndPointConfig} endPointConfig - used to obtain the access token and the domain for building the endpoints. If | ||
* we change this to load endpoints, the access token will still be needed, and the initial endpoint will | ||
* still need a domain/url to use as well. | ||
*/ | ||
function Endpoints(cloverOAuth) { | ||
function Endpoints(endPointConfig) { | ||
@@ -16,3 +15,3 @@ /** | ||
*/ | ||
this.cloverOAuth = cloverOAuth; | ||
this.endPointConfig = endPointConfig; | ||
@@ -28,4 +27,4 @@ /** | ||
variables[Endpoints.MERCHANT_V3_KEY] = merchantId; | ||
variables[Endpoints.ACCESS_TOKEN_KEY] = this.cloverOAuth.getAccessToken(); | ||
return this.cloverOAuth.configuration.domain + | ||
variables[Endpoints.ACCESS_TOKEN_KEY] = this.endPointConfig.getAccessToken(); | ||
return this.endPointConfig.configuration.domain + | ||
this.setVariables(Endpoints.MERCHANT_V3_PATH + Endpoints.ACCESS_TOKEN_SUFFIX, variables); | ||
@@ -43,4 +42,4 @@ }; | ||
variables[Endpoints.MERCHANT_V3_KEY] = merchantId; | ||
variables[Endpoints.ACCESS_TOKEN_KEY] = this.cloverOAuth.getAccessToken(); | ||
return this.cloverOAuth.configuration.domain + | ||
variables[Endpoints.ACCESS_TOKEN_KEY] = this.endPointConfig.getAccessToken(); | ||
return this.endPointConfig.configuration.domain + | ||
this.setVariables(Endpoints.DEVICE_PATH + Endpoints.ACCESS_TOKEN_SUFFIX, variables); | ||
@@ -57,4 +56,4 @@ }; | ||
variables[Endpoints.MERCHANT_V3_KEY] = merchantId; | ||
variables[Endpoints.ACCESS_TOKEN_KEY] = this.cloverOAuth.getAccessToken(); | ||
return this.cloverOAuth.configuration.domain + | ||
variables[Endpoints.ACCESS_TOKEN_KEY] = this.endPointConfig.getAccessToken(); | ||
return this.endPointConfig.configuration.domain + | ||
this.setVariables(Endpoints.REMOTE_PAY_PATH + Endpoints.ACCESS_TOKEN_SUFFIX, variables); | ||
@@ -61,0 +60,0 @@ }; |
24
index.js
module.exports.CloverLib = CloverLib; | ||
function CloverLib() {} | ||
// These exports expose the beta method of using the Clover device | ||
CloverLib.Clover = require("./Clover.js"); | ||
@@ -17,3 +18,26 @@ CloverLib.CloverOAuth = require("./CloverOAuth.js"); | ||
CloverLib.CookiePersistance = require("./CookiePersistance.js"); | ||
CloverLib.JSONToCustomObject = require("./JSONToCustomObject.js"); | ||
CloverLib.MethodToMessage = require("./MethodToMessage.js"); | ||
// These exports expose the v1 interface and objects. | ||
CloverLib.base = require("./base"); | ||
CloverLib.customers = require("./customers"); | ||
CloverLib.device = require("./device"); | ||
CloverLib.hours = require("./hours"); | ||
CloverLib.inventory = require("./inventory"); | ||
CloverLib.order = require("./order"); | ||
CloverLib.payments = require("./payments"); | ||
CloverLib.base = require("./base"); | ||
CloverLib.printer = require("./printer"); | ||
CloverLib.remotepay = require("./remotepay"); | ||
CloverLib.remotemessage = require("./remotemessage"); | ||
CloverLib.CloverConnectorImpl = require("./CloverConnectorImpl.js") | ||
CloverLib.CloverConnectorFactory = require("./CloverConnectorFactory.js") | ||
CloverLib.DelegateCloverConnectorListener = require("./DelegateCloverConnectorListener.js") | ||
CloverLib.DebugCloverConnectorListener = require("./DebugCloverConnectorListener.js") | ||
CloverLib.Logger = require('./Logger.js'); | ||
// | ||
@@ -20,0 +44,0 @@ // Expose the module. |
@@ -6,3 +6,3 @@ var EventEmitter = require("events").EventEmitter | ||
create: create | ||
} | ||
}; | ||
@@ -20,2 +20,3 @@ function create() { | ||
log.enabled = true; | ||
return log; | ||
@@ -22,0 +23,0 @@ |
{ | ||
"name": "remote-pay-cloud", | ||
"version": "0.0.4", | ||
"description": "Access Clover devices through the cloud", | ||
"version": "0.0.5", | ||
"description": "Access Clover devices through the cloud.", | ||
"keywords": [ | ||
@@ -27,4 +27,5 @@ "clover", | ||
"dependencies": { | ||
"prototype": "*", | ||
"eventemitter3": "~1.1.1" | ||
} | ||
} |
var LanMethod = require("./LanMethod.js"); | ||
var DiscoveryRequestMessage = require("./remotemessage/DiscoveryRequestMessage"); | ||
var RemoteMessage = require("./remotemessage/RemoteMessage"); | ||
@@ -7,11 +9,52 @@ /** | ||
* | ||
* @see com.clover.remote.protocol.RemoteMessage | ||
* @param {string} defaultPackageName -the packagename used in constructing the messages | ||
* @param {string} remoteSourceSDK - the name of the sdk in use. Used for metrics. | ||
* @param {string} remoteApplicationID - the semi-integrated application using the sdk. | ||
* @param {string} messageCount - the initial count ot use in message id's | ||
* @constructor | ||
*/ | ||
function RemoteMessageBuilder(defaultPackageName) { | ||
function RemoteMessageBuilder(defaultPackageName, remoteSourceSDK, remoteApplicationID, messageCount) { | ||
this.defaultPackageName = defaultPackageName; | ||
this.remoteSourceSDK = remoteSourceSDK; | ||
this.remoteApplicationID = remoteApplicationID; | ||
this.messageCount = isNaN(parseInt(messageCount)) ? | ||
0 : parseInt(messageCount); | ||
/** | ||
* @private | ||
* @returns {string} | ||
*/ | ||
this.getNextMessageId = function() { | ||
return "s" + this.messageCount++; | ||
}; | ||
/** | ||
* @param {Message} protocolMessage | ||
* @return {RemoteMessage} | ||
*/ | ||
this.buildRemoteMessageObject = function(protocolMessage) { | ||
var remoteMessage = new RemoteMessage(); | ||
remoteMessage.setId(this.getNextMessageId()); | ||
remoteMessage.setMethod(protocolMessage.getMethod()); | ||
remoteMessage.setPackageName(this.defaultPackageName); | ||
remoteMessage.setPayload(JSON.stringify(protocolMessage)); | ||
remoteMessage.setType(RemoteMessageType.COMMAND); | ||
remoteMessage.setRemoteSourceSDK(this.remoteSourceSDK); | ||
remoteMessage.setRemoteApplicationID(this.remoteApplicationID); | ||
return remoteMessage; | ||
}; | ||
/** | ||
* Builds a discovery request message | ||
* | ||
* @returns {RemoteMessage} the constructed message | ||
*/ | ||
this.buildDiscoveryRequestObject = function (supportsOrderModification) { | ||
var protocolMessage = new DiscoveryRequestMessage(); | ||
protocolMessage.setSupportsOrderModification(supportsOrderModification); | ||
return this.buildRemoteMessageObject(protocolMessage); | ||
}; | ||
/** | ||
* Build a message given the inputs | ||
@@ -21,5 +64,5 @@ * | ||
* @param {string} type - one of the RemoteMessageBuilder constants | ||
* @param {json} payload - the json object payload (not a string) | ||
* @param {string} payload - the json object payload (not a string) | ||
* @param {string} packageName - an override of the package name (optional) | ||
* @returns {json} the constructed message - a json object | ||
* @returns {string} the constructed message - a json object | ||
*/ | ||
@@ -35,2 +78,6 @@ this.buildRemoteMessage = function (method, type, payload, packageName) { | ||
lanMessage.type = RemoteMessageBuilder.COMMAND; | ||
lanMessage.remoteSourceSDK = this.remoteSourceSDK; | ||
lanMessage.remoteApplicationID = this.remoteApplicationID; | ||
if (type)lanMessage.type = type; | ||
@@ -44,4 +91,4 @@ // There is an 'id' in the java instance, but I do not see it being used right now. | ||
* | ||
* @param {json} payload - an order object | ||
* @returns {json} the constructed message | ||
* @param {string} payload - an order object | ||
* @returns {string} the constructed message | ||
*/ | ||
@@ -51,3 +98,3 @@ this.buildTxStart = function (payload) { | ||
return this.buildRemoteMessage(LanMethod.TX_START, RemoteMessageBuilder.COMMAND, payload); | ||
} | ||
}; | ||
@@ -57,7 +104,7 @@ /** | ||
* | ||
* @returns {json} the constructed message | ||
* @returns {string} the constructed message | ||
*/ | ||
this.buildDiscoveryRequest = function () { | ||
return this.buildRemoteMessage(LanMethod.DISCOVERY_REQUEST); | ||
} | ||
}; | ||
@@ -67,4 +114,4 @@ /** | ||
* | ||
* @param {json} payload - the signature verified object | ||
* @returns {json} the constructed message | ||
* @param {string} payload - the signature verified object | ||
* @returns {string} the constructed message | ||
*/ | ||
@@ -74,3 +121,3 @@ this.buildSignatureVerified = function (payload) { | ||
return this.buildRemoteMessage(LanMethod.SIGNATURE_VERIFIED, RemoteMessageBuilder.COMMAND, payload); | ||
} | ||
}; | ||
@@ -80,4 +127,4 @@ /** | ||
* | ||
* @param {json} payload - the signature verified object | ||
* @returns {json} the constructed message | ||
* @param {string} payload - the signature verified object | ||
* @returns {string} the constructed message | ||
*/ | ||
@@ -87,3 +134,3 @@ this.buildPaymentVoid = function (payload) { | ||
return this.buildRemoteMessage(LanMethod.PAYMENT_VOIDED, RemoteMessageBuilder.COMMAND, payload); | ||
} | ||
}; | ||
@@ -93,4 +140,4 @@ /** | ||
* | ||
* @param {json} payload - the signature verified object | ||
* @returns {json} the constructed message | ||
* @param {string} payload - the signature verified object | ||
* @returns {string} the constructed message | ||
*/ | ||
@@ -100,3 +147,3 @@ this.buildVoidPayment = function (payload) { | ||
return this.buildRemoteMessage(LanMethod.VOID_PAYMENT, RemoteMessageBuilder.COMMAND, payload); | ||
} | ||
}; | ||
@@ -106,4 +153,4 @@ /** | ||
* | ||
* @param {json} payload - card entry types allowed | ||
* @returns {json} the constructed message | ||
* @param {string} payload - card entry types allowed | ||
* @returns {string} the constructed message | ||
*/ | ||
@@ -113,3 +160,3 @@ this.buildVaultCard = function (payload) { | ||
return this.buildRemoteMessage(LanMethod.VAULT_CARD, RemoteMessageBuilder.COMMAND, payload); | ||
} | ||
}; | ||
@@ -119,4 +166,4 @@ /** | ||
* | ||
* @param {json} payload - the orderid and paymentid with optional amount | ||
* @returns {json} the constructed message | ||
* @param {string} payload - the orderid and paymentid with optional amount | ||
* @returns {string} the constructed message | ||
*/ | ||
@@ -126,3 +173,3 @@ this.buildRefund = function (payload) { | ||
return this.buildRemoteMessage(LanMethod.REFUND_REQUEST, RemoteMessageBuilder.COMMAND, payload); | ||
} | ||
}; | ||
@@ -132,4 +179,4 @@ /** | ||
* | ||
* @param {json} payload - the orderid, paymentid, amount, with optional tipAmount | ||
* @returns {json} the constructed message | ||
* @param {string} payload - the orderid, paymentid, amount, with optional tipAmount | ||
* @returns {string} the constructed message | ||
*/ | ||
@@ -139,3 +186,3 @@ this.buildCapturePreAuth = function (payload) { | ||
return this.buildRemoteMessage(LanMethod.CAPTURE_PREAUTH, RemoteMessageBuilder.COMMAND, payload); | ||
} | ||
};; | ||
@@ -145,4 +192,4 @@ /** | ||
* | ||
* @param {json} payload - optional allowOpenTabs and batchid | ||
* @returns {json} the constructed message | ||
* @param {string} payload - optional allowOpenTabs and batchid | ||
* @returns {string} the constructed message | ||
*/ | ||
@@ -152,3 +199,3 @@ this.buildCloseout = function (payload) { | ||
return this.buildRemoteMessage(LanMethod.CLOSEOUT_REQUEST, RemoteMessageBuilder.COMMAND, payload); | ||
} | ||
}; | ||
@@ -158,4 +205,4 @@ /** | ||
* | ||
* @param {json} payload - the orderid and paymentid with amount | ||
* @returns {json} the constructed message | ||
* @param {string} payload - the orderid and paymentid with amount | ||
* @returns {string} the constructed message | ||
*/ | ||
@@ -165,3 +212,3 @@ this.buildTipAdjust = function (payload) { | ||
return this.buildRemoteMessage(LanMethod.TIP_ADJUST, RemoteMessageBuilder.COMMAND, payload); | ||
} | ||
}; | ||
@@ -171,4 +218,4 @@ /** | ||
* | ||
* @param {json} payload - the orderid and paymentid | ||
* @returns {json} the constructed message | ||
* @param {string} payload - the orderid and paymentid | ||
* @returns {string} the constructed message | ||
*/ | ||
@@ -178,3 +225,3 @@ this.buildShowPaymentReceiptOptions = function (payload) { | ||
return this.buildRemoteMessage(LanMethod.SHOW_PAYMENT_RECEIPT_OPTIONS, RemoteMessageBuilder.COMMAND, payload); | ||
} | ||
}; | ||
@@ -184,4 +231,4 @@ /** | ||
* | ||
* @param {json} payload - an empty map/object | ||
* @returns {json} the constructed message | ||
* @param {string} payload - an empty map/object | ||
* @returns {string} the constructed message | ||
*/ | ||
@@ -191,3 +238,3 @@ this.buildOpenCashDrawer = function (payload) { | ||
return this.buildRemoteMessage(LanMethod.OPEN_CASH_DRAWER, RemoteMessageBuilder.COMMAND, payload); | ||
} | ||
}; | ||
@@ -197,4 +244,4 @@ /** | ||
* | ||
* @param {json} payload - an empty map/object | ||
* @returns {json} the constructed message | ||
* @param {string} payload - an empty map/object | ||
* @returns {string} the constructed message | ||
*/ | ||
@@ -204,3 +251,3 @@ this.buildLastMessageRequest = function (payload) { | ||
return this.buildRemoteMessage(LanMethod.LAST_MSG_REQUEST, RemoteMessageBuilder.COMMAND, payload); | ||
} | ||
}; | ||
@@ -210,4 +257,4 @@ /** | ||
* | ||
* @param {json} payload - the message | ||
* @returns {json} the constructed message | ||
* @param {string} payload - the message | ||
* @returns {string} the constructed message | ||
*/ | ||
@@ -217,3 +264,3 @@ this.buildTerminalMessage = function (payload) { | ||
return this.buildRemoteMessage(LanMethod.TERMINAL_MESSAGE, RemoteMessageBuilder.COMMAND, payload); | ||
} | ||
}; | ||
@@ -223,4 +270,4 @@ /** | ||
* | ||
* @param {json} payload - an object of the form {"textLines" : textLines} | ||
* @returns {json} the constructed message | ||
* @param {string} payload - an object of the form {"textLines" : textLines} | ||
* @returns {string} the constructed message | ||
*/ | ||
@@ -230,3 +277,3 @@ this.buildPrintText = function (payload) { | ||
return this.buildRemoteMessage(LanMethod.PRINT_TEXT, RemoteMessageBuilder.COMMAND, payload); | ||
} | ||
}; | ||
@@ -236,5 +283,5 @@ /** | ||
* | ||
* @param {json} payload - an object that has a single attribute; | ||
* @param {string} payload - an object that has a single attribute; | ||
* "png" : Base64 data. | ||
* @returns {json} the constructed message | ||
* @returns {string} the constructed message | ||
*/ | ||
@@ -244,3 +291,3 @@ this.buildPrintImage = function (payload) { | ||
return this.buildRemoteMessage(LanMethod.PRINT_IMAGE, RemoteMessageBuilder.COMMAND, payload); | ||
} | ||
}; | ||
@@ -250,7 +297,7 @@ /** | ||
* | ||
* @returns {json} the constructed message | ||
* @returns {string} the constructed message | ||
*/ | ||
this.buildShowWelcomeScreen = function () { | ||
return this.buildRemoteMessage(LanMethod.SHOW_WELCOME_SCREEN, RemoteMessageBuilder.COMMAND); | ||
} | ||
}; | ||
@@ -260,7 +307,7 @@ /** | ||
* | ||
* @returns {json} the constructed message | ||
* @returns {string} the constructed message | ||
*/ | ||
this.buildFinishCancel = function () { | ||
return this.buildRemoteMessage(LanMethod.FINISH_CANCEL, RemoteMessageBuilder.COMMAND); | ||
} | ||
}; | ||
@@ -270,7 +317,7 @@ /** | ||
* | ||
* @returns {json} the constructed message | ||
* @returns {string} the constructed message | ||
*/ | ||
this.buildShowThankYouScreen = function () { | ||
return this.buildRemoteMessage(LanMethod.SHOW_THANK_YOU_SCREEN, RemoteMessageBuilder.COMMAND); | ||
} | ||
}; | ||
@@ -280,4 +327,4 @@ /** | ||
* | ||
* @param {json} payload - an order object | ||
* @returns {json} the constructed message | ||
* @param {string} payload - an order object | ||
* @returns {string} the constructed message | ||
*/ | ||
@@ -287,15 +334,15 @@ this.buildShowOrderScreen = function (payload) { | ||
return this.buildRemoteMessage(LanMethod.SHOW_ORDER_SCREEN, RemoteMessageBuilder.COMMAND, payload); | ||
} | ||
}; | ||
/** | ||
* @private | ||
* @returns {json} the ping message | ||
* @returns {string} the ping message | ||
*/ | ||
this.buildPing = function () { | ||
return this.buildRemoteMessage(null, RemoteMessageBuilder.PING); | ||
} | ||
}; | ||
/** | ||
* @private | ||
* @returns {json} a keypress message | ||
* @returns {string} a keypress message | ||
*/ | ||
@@ -305,3 +352,3 @@ this.buildKeyPress = function (payload) { | ||
return this.buildRemoteMessage(LanMethod.KEY_PRESS, RemoteMessageBuilder.COMMAND, payload); | ||
} | ||
}; | ||
@@ -311,3 +358,3 @@ | ||
* @private | ||
* @returns {json} a break message | ||
* @returns {string} a break message | ||
*/ | ||
@@ -317,3 +364,3 @@ this.buildBreak = function (payload) { | ||
return this.buildRemoteMessage(LanMethod.BREAK, RemoteMessageBuilder.COMMAND, payload); | ||
} | ||
}; | ||
@@ -323,7 +370,7 @@ | ||
* @private | ||
* @returns {json} the pong message | ||
* @returns {string} the pong message | ||
*/ | ||
this.buildPong = function () { | ||
return this.buildRemoteMessage(null, RemoteMessageBuilder.PONG); | ||
} | ||
}; | ||
@@ -333,3 +380,3 @@ /** | ||
* | ||
* @returns {json} the constructed message | ||
* @returns {string} the constructed message | ||
*/ | ||
@@ -336,0 +383,0 @@ this.buildShutdown = function () { |
@@ -6,2 +6,3 @@ //********************************************* | ||
var CloverID = require("./CloverID.js"); | ||
var CloverError = require("./CloverError.js"); | ||
var EventEmitter = require("eventemitter3"); | ||
@@ -139,3 +140,5 @@ var XmlHttpSupport = require("./xmlHttpSupport.js"); | ||
} | ||
return; | ||
if (this.deviceSocket && this.deviceSocket.readyState == WebSocket.OPEN) { | ||
return; | ||
} | ||
} | ||
@@ -225,2 +228,3 @@ | ||
if(lag > this.deadConnectionErrorThreshold) { | ||
this.pongReceivedMillis = new Date().getTime(); | ||
this.connectionError(lag); | ||
@@ -340,2 +344,3 @@ } | ||
this.disconnectFromDevice = function() { | ||
this.reconnect = false; | ||
this.forceClose(); | ||
@@ -368,8 +373,10 @@ }; | ||
} | ||
if (this.deviceSocket) { | ||
try { | ||
this.deviceSocket.close(); | ||
} catch (e) { | ||
setTimeout(function() { | ||
if (this.deviceSocket) { | ||
try { | ||
this.deviceSocket.close(); | ||
} catch (e) { | ||
} | ||
} | ||
} | ||
}.bind(this), 2000); | ||
}; | ||
@@ -412,3 +419,2 @@ | ||
* @param {Object} message - the message to send | ||
* @private | ||
*/ | ||
@@ -435,3 +441,4 @@ this.sendMessage = function(message) { | ||
this.disconnectFromDevice(); | ||
throw new Error("Device disconnected"); | ||
throw new CloverError(CloverError.DEVICE_OFFLINE, "Device disconnected, message not sent: " + | ||
stringMessage ); | ||
} | ||
@@ -478,11 +485,11 @@ } | ||
this.pongReceived(message); | ||
} | ||
if(message["type"] == RemoteMessageBuilder.PING) { | ||
} else if(message["type"] == RemoteMessageBuilder.PING) { | ||
this.pingReceived(message); | ||
} | ||
if(message["type"] == RemoteMessageBuilder.FORCE) { | ||
} if(message["type"] == RemoteMessageBuilder.FORCE) { | ||
this.connectionStolen(message); | ||
} | ||
} | ||
this.eventEmitter.emit(message.method, message); | ||
if(message.hasOwnProperty("method")) { | ||
this.eventEmitter.emit(message.method, message); | ||
} | ||
this.eventEmitter.emit(WebSocketDevice.ALL_MESSAGES, message); | ||
@@ -489,0 +496,0 @@ }; |
@@ -14,10 +14,10 @@ //********************************************* | ||
this.setXmlHttpCallback = function(xmlhttp, onDataLoaded, onError) { | ||
this.setXmlHttpCallback = function (xmlhttp, endpoint, onDataLoaded, onError) { | ||
xmlhttp.onreadystatechange = function () { | ||
if (xmlhttp.readyState == 4) | ||
if (xmlhttp.readyState == 4) { | ||
if (xmlhttp.status == 200) { | ||
try { | ||
if(onDataLoaded) { | ||
try { | ||
if (onDataLoaded) { | ||
var data = null; | ||
if(xmlhttp.responseText && xmlhttp.responseText != "") { | ||
if (xmlhttp.responseText && xmlhttp.responseText != "") { | ||
data = JSON.parse(xmlhttp.responseText); | ||
@@ -27,5 +27,5 @@ } | ||
} | ||
} catch(e) { | ||
log.error(e); | ||
if(onDataLoaded) { | ||
} catch (e) { | ||
log.error(endpoint, e); | ||
if (onDataLoaded) { | ||
onDataLoaded({}); | ||
@@ -36,10 +36,12 @@ } | ||
else { | ||
if(onError) { | ||
onError("status returned was not 200"); | ||
if (onError) { | ||
onError({message: "status returned was not 200", endpoint: endpoint, status: xmlhttp.status}); | ||
} | ||
} | ||
} else { | ||
} | ||
} | ||
} | ||
this.getResponseHeader = function(headerName) { | ||
this.getResponseHeader = function (headerName) { | ||
return this.xmlhttp.getResponseHeader(headerName); | ||
@@ -51,4 +53,4 @@ } | ||
*/ | ||
this.doXmlHttp = function(method, endpoint, onDataLoaded, onError) { | ||
this.setXmlHttpCallback(this.xmlhttp, onDataLoaded, onError); | ||
this.doXmlHttp = function (method, endpoint, onDataLoaded, onError) { | ||
this.setXmlHttpCallback(this.xmlhttp, endpoint, onDataLoaded, onError); | ||
@@ -60,17 +62,17 @@ this.xmlhttp.open(method, endpoint, true); | ||
/* | ||
Not sure how to do browser specific hacks in npm | ||
if (navigator.userAgent.search("Firefox")) { | ||
this.xmlhttp.setRequestHeader("Accept", "* / *"); | ||
} | ||
*/ | ||
Not sure how to do browser specific hacks in npm | ||
if (navigator.userAgent.search("Firefox")) { | ||
this.xmlhttp.setRequestHeader("Accept", "* / *"); | ||
} | ||
*/ | ||
this.xmlhttp.send(); | ||
} | ||
this.doXmlHttpSendJson = function(method, sendData, endpoint, onDataLoaded, onError, additionalHeaders) { | ||
this.setXmlHttpCallback(this.xmlhttp, onDataLoaded, onError); | ||
this.doXmlHttpSendJson = function (method, sendData, endpoint, onDataLoaded, onError, additionalHeaders) { | ||
this.setXmlHttpCallback(this.xmlhttp, endpoint, onDataLoaded, onError); | ||
this.xmlhttp.open(method, endpoint, true); | ||
if(additionalHeaders) { | ||
for (var key in additionalHeaders){ | ||
if(additionalHeaders.hasOwnProperty(key)) { | ||
if (additionalHeaders) { | ||
for (var key in additionalHeaders) { | ||
if (additionalHeaders.hasOwnProperty(key)) { | ||
this.xmlhttp.setRequestHeader(key, additionalHeaders[key]); | ||
@@ -92,3 +94,3 @@ } | ||
*/ | ||
this.postData = function(endpoint, onDataLoaded, onError, sendData, additionalHeaders) { | ||
this.postData = function (endpoint, onDataLoaded, onError, sendData, additionalHeaders) { | ||
this.doXmlHttpSendJson("POST", sendData, endpoint, onDataLoaded, onError, additionalHeaders); | ||
@@ -100,3 +102,3 @@ } | ||
*/ | ||
this.getData = function(endpoint, onDataLoaded, onError) { | ||
this.getData = function (endpoint, onDataLoaded, onError) { | ||
this.doXmlHttp("GET", endpoint, onDataLoaded, onError) | ||
@@ -108,3 +110,3 @@ } | ||
*/ | ||
this.options = function(endpoint, onSuccess, onError) { | ||
this.options = function (endpoint, onSuccess, onError) { | ||
this.doXmlHttp("OPTIONS", endpoint, onSuccess, onError) | ||
@@ -116,3 +118,3 @@ } | ||
*/ | ||
this.putData = function(endpoint, onDataLoaded, onError, sendData) { | ||
this.putData = function (endpoint, onDataLoaded, onError, sendData) { | ||
this.doXmlHttpSendJson("PUT", sendData, endpoint, onDataLoaded, onError); | ||
@@ -123,3 +125,3 @@ } | ||
*/ | ||
this.deleteData = function(endpoint, onDataLoaded, onError) { | ||
this.deleteData = function (endpoint, onDataLoaded, onError) { | ||
this.doXmlHttp("DELETE", endpoint, onDataLoaded, onError) | ||
@@ -129,3 +131,2 @@ } | ||
// | ||
@@ -132,0 +133,0 @@ // Expose the module. |
Sorry, the diff of this file is too big to display
Wildcard dependency
QualityPackage has a dependency with a floating version range. This can cause issues if the dependency publishes a new major version.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
910053
271
30913
2
2
1
+ Addedprototype@*
+ Addedprototype@0.0.5(transitive)