dotdashpay
Advanced tools
Comparing version 1.1.1-rc to 1.1.1
@@ -13,4 +13,4 @@ /** | ||
var dotdashpay_api_common_protobuf_common_pb = require('../../../../dotdashpay/api/common/protobuf/common_pb.js'); | ||
var dotdashpay_api_common_protobuf_platform_pb = require('../../../../dotdashpay/api/common/protobuf/platform_pb.js'); | ||
var dotdashpay_api_common_protobuf_payment_pb = require('../../../../dotdashpay/api/common/protobuf/payment_pb.js'); | ||
var dotdashpay_api_common_protobuf_platform_pb = require('../../../../dotdashpay/api/common/protobuf/platform_pb.js'); | ||
goog.object.extend(exports, proto.dotdashpay.api); |
@@ -13,4 +13,4 @@ /** | ||
var dotdashpay_api_common_protobuf_common_pb = require('../../../../dotdashpay/api/common/protobuf/common_pb.js'); | ||
var dotdashpay_api_common_protobuf_platform_pb = require('../../../../dotdashpay/api/common/protobuf/platform_pb.js'); | ||
var dotdashpay_api_common_protobuf_payment_pb = require('../../../../dotdashpay/api/common/protobuf/payment_pb.js'); | ||
var dotdashpay_api_common_protobuf_platform_pb = require('../../../../dotdashpay/api/common/protobuf/platform_pb.js'); | ||
goog.object.extend(exports, proto.dotdashpay.api); |
@@ -12,3 +12,3 @@ /** | ||
simulatorConfiguration: { 'apiToken': 'aeac1bc8f0735e4283305652ab' }, | ||
grpcNumRetries: 500, | ||
connectionRetries: 500, | ||
}; | ||
@@ -15,0 +15,0 @@ |
@@ -15,3 +15,2 @@ /** | ||
transactionMode: "PAYMENT", | ||
customerId: "1337", | ||
}; | ||
@@ -18,0 +17,0 @@ |
@@ -15,3 +15,2 @@ /** | ||
transactionMode: "PAYMENT", | ||
customerId: "1337", | ||
}; | ||
@@ -18,0 +17,0 @@ |
@@ -15,3 +15,2 @@ /** | ||
transactionMode: "PAYMENT", | ||
customerId: "1337", | ||
}; | ||
@@ -18,0 +17,0 @@ |
/** | ||
Autogenerated example for SDK request: GetConnectedHardware | ||
**/ | ||
// @reference() | ||
// @reference-end() | ||
// @example-args(Platform.GetConnectedHardware) | ||
var args = {}; | ||
// @example-args-end() | ||
// @example-request(Platform.GetConnectedHardware) | ||
dotdashpay.platform.getConnectedHardware(args) | ||
.onGotConnectedHardware(function(response) { | ||
console.log("Received onGotConnectedHardware response", JSON.stringify(response, null, 2)); | ||
var peripheralIds = response.peripheralIds; // e.g. [['IDTechKioskIII']] | ||
}) | ||
.onGetConnectedHardwareError(function(errorData) { | ||
console.log("Error", JSON.stringify(errorData, null, 2)); | ||
}) | ||
// @example-request-end() | ||
}); | ||
it("should be able to specify a(n) GetConnectedHardwareError response with the simulator", function(done) { | ||
if (!simulate) { | ||
return this.skip("This test is only applicable with the simulator"); | ||
} | ||
var testErrorMessage = "Test error message"; | ||
var testErrorCode = 9000; | ||
dotdashpay.simulator.setResponse("GotConnectedHardware", { | ||
message: testErrorMessage, | ||
code: testErrorCode | ||
}, | ||
true); | ||
dotdashpay.platform.getConnectedHardware(args) | ||
.onGotConnectedHardware(function(response) { | ||
return done(new Error("This example should only have an on*Error callback event, not GotConnectedHardware")); | ||
}) | ||
.onGetConnectedHardwareError(function(errorData) { | ||
assert.equal(testErrorMessage, errorData.message, | ||
"Simulator error message was not returned correctly"); | ||
assert.equal(testErrorCode, errorData.code, | ||
"Simulator error code was not returned correctly"); | ||
dotdashpay.simulator.resetAllResponses(); | ||
return done(); | ||
}) | ||
}); | ||
it("should be able to specify a particular response from the simulator", function(done) { | ||
if (!simulate) { | ||
return this.skip("This test is only applicable with the simulator"); | ||
} | ||
// need a string value that we can overwrite | ||
var newVals = {}; | ||
dotdashpay.simulator.setResponse("GotConnectedHardware", newVals); | ||
dotdashpay.platform.getConnectedHardware(args) | ||
.onGotConnectedHardware(function(response) { | ||
_.each(newVals, function(val, key) { | ||
assert.deepEqual(response[key], val); | ||
}); | ||
return done(); | ||
}) | ||
}); | ||
it("should throw an error when a field is input that does not exist", function(done) { | ||
if (!simulate) { | ||
return this.skip("This test is only applicable with the simulator"); | ||
} | ||
var errRegexp = new RegExp("does not accept an argument with name"); | ||
try { | ||
dotdashpay.platform.getConnectedHardware({ nonExistantFieldNameYEah: 5 }) | ||
} catch (err) { | ||
assert.isTrue(errRegexp.test(String(err))); | ||
return done() | ||
} | ||
return done(new Error("Did not throw an error when rpc 'getConnectedHardware' called with non existant field")); | ||
}); | ||
}); | ||
}); | ||
// @test-end() | ||
// @reference() | ||
// @reference-end() | ||
/** | ||
Autogenerated example for SDK request: Initialize | ||
**/ | ||
// @reference() | ||
// @reference-end() | ||
// @example-args(Platform.Initialize) | ||
var args = { | ||
environment: "MIDDLEWARE_SIMULATOR", | ||
simulatorConfiguration: { 'apiToken': 'aeac1bc8f0735e4283305652ab' }, | ||
connectionRetries: 500, | ||
}; | ||
// @example-args-end() | ||
// @example-request(Platform.Initialize) | ||
dotdashpay.platform.initialize(args) | ||
.onInitialized(function(response) { | ||
console.log("Received onInitialized response", JSON.stringify(response, null, 2)); | ||
}) | ||
.onInitializeError(function(errorData) { | ||
console.log("Error", JSON.stringify(errorData, null, 2)); | ||
}) | ||
// @example-request-end() | ||
}); | ||
it("should be able to specify a(n) InitializeError response with the simulator", function(done) { | ||
if (!simulate) { | ||
return this.skip("This test is only applicable with the simulator"); | ||
} | ||
var testErrorMessage = "Test error message"; | ||
var testErrorCode = 9000; | ||
dotdashpay.simulator.setResponse("Initialized", { | ||
message: testErrorMessage, | ||
code: testErrorCode | ||
}, | ||
true); | ||
dotdashpay.platform.initialize(args) | ||
.onInitialized(function(response) { | ||
return done(new Error("This example should only have an on*Error callback event, not Initialized")); | ||
}) | ||
.onInitializeError(function(errorData) { | ||
assert.equal(testErrorMessage, errorData.message, | ||
"Simulator error message was not returned correctly"); | ||
assert.equal(testErrorCode, errorData.code, | ||
"Simulator error code was not returned correctly"); | ||
dotdashpay.simulator.resetAllResponses(); | ||
return done(); | ||
}) | ||
}); | ||
it("should be able to specify a particular response from the simulator", function(done) { | ||
if (!simulate) { | ||
return this.skip("This test is only applicable with the simulator"); | ||
} | ||
// need a string value that we can overwrite | ||
var newVals = {}; | ||
dotdashpay.simulator.setResponse("Initialized", newVals); | ||
dotdashpay.platform.initialize(args) | ||
.onInitialized(function(response) { | ||
_.each(newVals, function(val, key) { | ||
assert.deepEqual(response[key], val); | ||
}); | ||
return done(); | ||
}) | ||
}); | ||
it("should throw an error when a field is input that does not exist", function(done) { | ||
if (!simulate) { | ||
return this.skip("This test is only applicable with the simulator"); | ||
} | ||
var errRegexp = new RegExp("does not accept an argument with name"); | ||
try { | ||
dotdashpay.platform.initialize({ nonExistantFieldNameYEah: 5 }) | ||
} catch (err) { | ||
assert.isTrue(errRegexp.test(String(err))); | ||
return done() | ||
} | ||
return done(new Error("Did not throw an error when rpc 'initialize' called with non existant field")); | ||
}); | ||
}); | ||
}); | ||
// @test-end() | ||
// @reference() | ||
// @reference-end() | ||
/** | ||
Autogenerated example for SDK request: ListenForInteraction | ||
**/ | ||
// @reference() | ||
// @reference-end() | ||
// @example-args(Platform.ListenForInteraction) | ||
var args = { | ||
useExistingData: false, | ||
existingDataTtlSeconds: 5, | ||
amount: 128, | ||
currency: "USD", | ||
transactionMode: "PAYMENT", | ||
}; | ||
// @example-args-end() | ||
// @example-request(Platform.ListenForInteraction) | ||
dotdashpay.platform.listenForInteraction(args) | ||
.onStartedInteraction(function(response) { | ||
console.log("Received onStartedInteraction response", JSON.stringify(response, null, 2)); | ||
var peripheralId = response.peripheralId; // e.g. "IDTechKioskIII" | ||
}) | ||
.onGotInteraction(function(response) { | ||
console.log("Received onGotInteraction response", JSON.stringify(response, null, 2)); | ||
var transactionChainId = response.transactionChainId; // e.g. "iPqy9F82v5qexbtz" | ||
var peripheralId = response.peripheralId; // e.g. "IDTechKioskIII" | ||
var customerProfile = response.customerProfile; // e.g. {'phoneNumber': '5555555555', 'familyName': 'Customer', 'postalCode': '94609', 'givenName': 'Mimir T.', 'fullName': 'Mimir T. Customer', 'id': 'an-id'} | ||
}) | ||
.onListenForInteractionError(function(errorData) { | ||
console.log("Error", JSON.stringify(errorData, null, 2)); | ||
}) | ||
// @example-request-end() | ||
}); | ||
it("should be able to specify a(n) ListenForInteractionError response with the simulator", function(done) { | ||
if (!simulate) { | ||
return this.skip("This test is only applicable with the simulator"); | ||
} | ||
var testErrorMessage = "Test error message"; | ||
var testErrorCode = 9000; | ||
dotdashpay.simulator.setResponse("StartedInteraction", { | ||
message: testErrorMessage, | ||
code: testErrorCode | ||
}, | ||
true); | ||
dotdashpay.platform.listenForInteraction(args) | ||
.onStartedInteraction(function(response) { | ||
return done(new Error("This example should only have an on*Error callback event, not StartedInteraction")); | ||
}) | ||
.onGotInteraction(function(response) { | ||
return done(new Error("This example should only have an on*Error callback event, not GotInteraction")); | ||
}) | ||
.onListenForInteractionError(function(errorData) { | ||
assert.equal(testErrorMessage, errorData.message, | ||
"Simulator error message was not returned correctly"); | ||
assert.equal(testErrorCode, errorData.code, | ||
"Simulator error code was not returned correctly"); | ||
dotdashpay.simulator.resetAllResponses(); | ||
return done(); | ||
}) | ||
}); | ||
it("should be able to specify a particular response from the simulator", function(done) { | ||
if (!simulate) { | ||
return this.skip("This test is only applicable with the simulator"); | ||
} | ||
// need a string value that we can overwrite | ||
var newVals = { | ||
transactionChainId: "iPqy9F82v5qexbtz" + "-changed", | ||
}; | ||
dotdashpay.simulator.setResponse("GotInteraction", newVals); | ||
dotdashpay.platform.listenForInteraction(args) | ||
.onGotInteraction(function(response) { | ||
_.each(newVals, function(val, key) { | ||
assert.deepEqual(response[key], val); | ||
}); | ||
return done(); | ||
}) | ||
}); | ||
it("should throw an error when a field is input that does not exist", function(done) { | ||
if (!simulate) { | ||
return this.skip("This test is only applicable with the simulator"); | ||
} | ||
var errRegexp = new RegExp("does not accept an argument with name"); | ||
try { | ||
dotdashpay.platform.listenForInteraction({ nonExistantFieldNameYEah: 5 }) | ||
} catch (err) { | ||
assert.isTrue(errRegexp.test(String(err))); | ||
return done() | ||
} | ||
return done(new Error("Did not throw an error when rpc 'listenForInteraction' called with non existant field")); | ||
}); | ||
}); | ||
}); | ||
// @test-end() | ||
// @reference() | ||
// @reference-end() | ||
/** | ||
Autogenerated example for SDK request: GetTransaction | ||
@@ -137,3 +445,2 @@ **/ | ||
transactionMode: "PAYMENT", | ||
customerId: "1337", | ||
}; | ||
@@ -297,3 +604,2 @@ // @example-args-end() | ||
transactionMode: "PAYMENT", | ||
customerId: "1337", | ||
}; | ||
@@ -867,311 +1173,2 @@ // @example-args-end() | ||
// @reference() | ||
// @reference-end() | ||
/** | ||
Autogenerated example for SDK request: GetConnectedHardware | ||
**/ | ||
// @reference() | ||
// @reference-end() | ||
// @example-args(Platform.GetConnectedHardware) | ||
var args = {}; | ||
// @example-args-end() | ||
// @example-request(Platform.GetConnectedHardware) | ||
dotdashpay.platform.getConnectedHardware(args) | ||
.onGotConnectedHardware(function(response) { | ||
console.log("Received onGotConnectedHardware response", JSON.stringify(response, null, 2)); | ||
var peripheralIds = response.peripheralIds; // e.g. [['IDTechKioskIII']] | ||
}) | ||
.onGetConnectedHardwareError(function(errorData) { | ||
console.log("Error", JSON.stringify(errorData, null, 2)); | ||
}) | ||
// @example-request-end() | ||
}); | ||
it("should be able to specify a(n) GetConnectedHardwareError response with the simulator", function(done) { | ||
if (!simulate) { | ||
return this.skip("This test is only applicable with the simulator"); | ||
} | ||
var testErrorMessage = "Test error message"; | ||
var testErrorCode = 9000; | ||
dotdashpay.simulator.setResponse("GotConnectedHardware", { | ||
message: testErrorMessage, | ||
code: testErrorCode | ||
}, | ||
true); | ||
dotdashpay.platform.getConnectedHardware(args) | ||
.onGotConnectedHardware(function(response) { | ||
return done(new Error("This example should only have an on*Error callback event, not GotConnectedHardware")); | ||
}) | ||
.onGetConnectedHardwareError(function(errorData) { | ||
assert.equal(testErrorMessage, errorData.message, | ||
"Simulator error message was not returned correctly"); | ||
assert.equal(testErrorCode, errorData.code, | ||
"Simulator error code was not returned correctly"); | ||
dotdashpay.simulator.resetAllResponses(); | ||
return done(); | ||
}) | ||
}); | ||
it("should be able to specify a particular response from the simulator", function(done) { | ||
if (!simulate) { | ||
return this.skip("This test is only applicable with the simulator"); | ||
} | ||
// need a string value that we can overwrite | ||
var newVals = {}; | ||
dotdashpay.simulator.setResponse("GotConnectedHardware", newVals); | ||
dotdashpay.platform.getConnectedHardware(args) | ||
.onGotConnectedHardware(function(response) { | ||
_.each(newVals, function(val, key) { | ||
assert.deepEqual(response[key], val); | ||
}); | ||
return done(); | ||
}) | ||
}); | ||
it("should throw an error when a field is input that does not exist", function(done) { | ||
if (!simulate) { | ||
return this.skip("This test is only applicable with the simulator"); | ||
} | ||
var errRegexp = new RegExp("does not accept an argument with name"); | ||
try { | ||
dotdashpay.platform.getConnectedHardware({ nonExistantFieldNameYEah: 5 }) | ||
} catch (err) { | ||
assert.isTrue(errRegexp.test(String(err))); | ||
return done() | ||
} | ||
return done(new Error("Did not throw an error when rpc 'getConnectedHardware' called with non existant field")); | ||
}); | ||
}); | ||
}); | ||
// @test-end() | ||
// @reference() | ||
// @reference-end() | ||
/** | ||
Autogenerated example for SDK request: Initialize | ||
**/ | ||
// @reference() | ||
// @reference-end() | ||
// @example-args(Platform.Initialize) | ||
var args = { | ||
environment: "MIDDLEWARE_SIMULATOR", | ||
simulatorConfiguration: { 'apiToken': 'aeac1bc8f0735e4283305652ab' }, | ||
grpcNumRetries: 500, | ||
}; | ||
// @example-args-end() | ||
// @example-request(Platform.Initialize) | ||
dotdashpay.platform.initialize(args) | ||
.onInitialized(function(response) { | ||
console.log("Received onInitialized response", JSON.stringify(response, null, 2)); | ||
}) | ||
.onInitializeError(function(errorData) { | ||
console.log("Error", JSON.stringify(errorData, null, 2)); | ||
}) | ||
// @example-request-end() | ||
}); | ||
it("should be able to specify a(n) InitializeError response with the simulator", function(done) { | ||
if (!simulate) { | ||
return this.skip("This test is only applicable with the simulator"); | ||
} | ||
var testErrorMessage = "Test error message"; | ||
var testErrorCode = 9000; | ||
dotdashpay.simulator.setResponse("Initialized", { | ||
message: testErrorMessage, | ||
code: testErrorCode | ||
}, | ||
true); | ||
dotdashpay.platform.initialize(args) | ||
.onInitialized(function(response) { | ||
return done(new Error("This example should only have an on*Error callback event, not Initialized")); | ||
}) | ||
.onInitializeError(function(errorData) { | ||
assert.equal(testErrorMessage, errorData.message, | ||
"Simulator error message was not returned correctly"); | ||
assert.equal(testErrorCode, errorData.code, | ||
"Simulator error code was not returned correctly"); | ||
dotdashpay.simulator.resetAllResponses(); | ||
return done(); | ||
}) | ||
}); | ||
it("should be able to specify a particular response from the simulator", function(done) { | ||
if (!simulate) { | ||
return this.skip("This test is only applicable with the simulator"); | ||
} | ||
// need a string value that we can overwrite | ||
var newVals = {}; | ||
dotdashpay.simulator.setResponse("Initialized", newVals); | ||
dotdashpay.platform.initialize(args) | ||
.onInitialized(function(response) { | ||
_.each(newVals, function(val, key) { | ||
assert.deepEqual(response[key], val); | ||
}); | ||
return done(); | ||
}) | ||
}); | ||
it("should throw an error when a field is input that does not exist", function(done) { | ||
if (!simulate) { | ||
return this.skip("This test is only applicable with the simulator"); | ||
} | ||
var errRegexp = new RegExp("does not accept an argument with name"); | ||
try { | ||
dotdashpay.platform.initialize({ nonExistantFieldNameYEah: 5 }) | ||
} catch (err) { | ||
assert.isTrue(errRegexp.test(String(err))); | ||
return done() | ||
} | ||
return done(new Error("Did not throw an error when rpc 'initialize' called with non existant field")); | ||
}); | ||
}); | ||
}); | ||
// @test-end() | ||
// @reference() | ||
// @reference-end() | ||
/** | ||
Autogenerated example for SDK request: ListenForInteraction | ||
**/ | ||
// @reference() | ||
// @reference-end() | ||
// @example-args(Platform.ListenForInteraction) | ||
var args = { | ||
useExistingData: false, | ||
existingDataTtlSeconds: 5, | ||
amount: 128, | ||
currency: "USD", | ||
transactionMode: "PAYMENT", | ||
customerId: "1337", | ||
}; | ||
// @example-args-end() | ||
// @example-request(Platform.ListenForInteraction) | ||
dotdashpay.platform.listenForInteraction(args) | ||
.onStartedInteraction(function(response) { | ||
console.log("Received onStartedInteraction response", JSON.stringify(response, null, 2)); | ||
var peripheralId = response.peripheralId; // e.g. "IDTechKioskIII" | ||
}) | ||
.onGotInteraction(function(response) { | ||
console.log("Received onGotInteraction response", JSON.stringify(response, null, 2)); | ||
var transactionChainId = response.transactionChainId; // e.g. "iPqy9F82v5qexbtz" | ||
var peripheralId = response.peripheralId; // e.g. "IDTechKioskIII" | ||
var customerProfile = response.customerProfile; // e.g. {'phoneNumber': '5555555555', 'familyName': 'Customer', 'postalCode': '94609', 'givenName': 'Mimir T.', 'fullName': 'Mimir T. Customer', 'id': 'an-id'} | ||
}) | ||
.onListenForInteractionError(function(errorData) { | ||
console.log("Error", JSON.stringify(errorData, null, 2)); | ||
}) | ||
// @example-request-end() | ||
}); | ||
it("should be able to specify a(n) ListenForInteractionError response with the simulator", function(done) { | ||
if (!simulate) { | ||
return this.skip("This test is only applicable with the simulator"); | ||
} | ||
var testErrorMessage = "Test error message"; | ||
var testErrorCode = 9000; | ||
dotdashpay.simulator.setResponse("StartedInteraction", { | ||
message: testErrorMessage, | ||
code: testErrorCode | ||
}, | ||
true); | ||
dotdashpay.platform.listenForInteraction(args) | ||
.onStartedInteraction(function(response) { | ||
return done(new Error("This example should only have an on*Error callback event, not StartedInteraction")); | ||
}) | ||
.onGotInteraction(function(response) { | ||
return done(new Error("This example should only have an on*Error callback event, not GotInteraction")); | ||
}) | ||
.onListenForInteractionError(function(errorData) { | ||
assert.equal(testErrorMessage, errorData.message, | ||
"Simulator error message was not returned correctly"); | ||
assert.equal(testErrorCode, errorData.code, | ||
"Simulator error code was not returned correctly"); | ||
dotdashpay.simulator.resetAllResponses(); | ||
return done(); | ||
}) | ||
}); | ||
it("should be able to specify a particular response from the simulator", function(done) { | ||
if (!simulate) { | ||
return this.skip("This test is only applicable with the simulator"); | ||
} | ||
// need a string value that we can overwrite | ||
var newVals = { | ||
transactionChainId: "iPqy9F82v5qexbtz" + "-changed", | ||
}; | ||
dotdashpay.simulator.setResponse("GotInteraction", newVals); | ||
dotdashpay.platform.listenForInteraction(args) | ||
.onGotInteraction(function(response) { | ||
_.each(newVals, function(val, key) { | ||
assert.deepEqual(response[key], val); | ||
}); | ||
return done(); | ||
}) | ||
}); | ||
it("should throw an error when a field is input that does not exist", function(done) { | ||
if (!simulate) { | ||
return this.skip("This test is only applicable with the simulator"); | ||
} | ||
var errRegexp = new RegExp("does not accept an argument with name"); | ||
try { | ||
dotdashpay.platform.listenForInteraction({ nonExistantFieldNameYEah: 5 }) | ||
} catch (err) { | ||
assert.isTrue(errRegexp.test(String(err))); | ||
return done() | ||
} | ||
return done(new Error("Did not throw an error when rpc 'listenForInteraction' called with non existant field")); | ||
}); | ||
}); | ||
}); | ||
// @test-end() | ||
// @reference() | ||
// @reference-end() |
@@ -15,3 +15,3 @@ var _ = require("lodash"); | ||
var MIDDLEWARE_URI = ddpUtils.getMiddlewareURI(); | ||
var GRPC_RETRIES = 60; | ||
var GRPC_RETRIES = 2; | ||
logger.debug("Using SDK URI for GRPC bridge: ", SDK_URI); | ||
@@ -108,3 +108,3 @@ logger.debug("Using Middleware URI for GRPC bridge: ", MIDDLEWARE_URI); | ||
name: "SdkError", | ||
message: {errorCode: errorCode, errorMessage: "Unable to communicate with the dotdashpay platform: is it connected? Are the correct ports exposed in the docker solutions?", META: requestArgs.META}, | ||
message: {errorCode: errorCode, errorMessage: "Unable to communicate with the dotdashpay platform: is it up and running successully?", META: requestArgs.META}, | ||
rpc: "SdkError" | ||
@@ -111,0 +111,0 @@ }); |
@@ -10,3 +10,2 @@ /** | ||
var _ = require("lodash"); | ||
var cloudLogger = require("./util/cloud-logger"); | ||
var config = require("./config"); | ||
@@ -16,2 +15,5 @@ var logger = require("./logging"); | ||
var ddputil = require("./util/ddp-utils"); | ||
var protoTools = require("./util/protobuf-tools"); | ||
var ddpProtos = require("../ddp-protobufs-js"); | ||
var sdkErrorCodes = ddpProtos["dotdashpay/api/common/protobuf/public_error_enum_pb"]; | ||
@@ -28,2 +30,7 @@ // internal state | ||
// testing state | ||
var _testingState = { | ||
TESTING: false, | ||
bridge: null | ||
}; | ||
@@ -51,3 +58,2 @@ /** | ||
var setup = function setup(bridge) { | ||
// TODO(cjrd) check that the bridge satisfies the bridge interface | ||
_state.bridge = bridge; | ||
@@ -61,4 +67,3 @@ bridge.setIncomingProtobufHandler(receiveResponse); | ||
sendRequest sends the input request to the the bridge specified in the | ||
setup(..) functio | ||
n | ||
setup(..) function | ||
*/ | ||
@@ -74,10 +79,12 @@ var sendRequest = function sendRequest(request) { | ||
if (request._rpcName === "Initialize") { | ||
logger.info("Initializing the DotDashPay SDK", {initializeArgs: request._protobuf}); | ||
_state.initializeRequestArgs = request; | ||
logger.info("Initializing the DotDashPay SDK", {initializeArgs: request._protobuf}); | ||
config.apiToken = request._protobuf.apiToken || config.apiToken; | ||
var bridge; | ||
if (request._protobuf.environment === "MIDDLEWARE_SIMULATOR") { | ||
if(!request._protobuf.simulatorConfiguration || !request._protobuf.simulatorConfiguration.apiToken) { | ||
throw new Error("You must provide set field 'apiToken' in Initialize like so: Initialize({\"simulatorConfiguration\": {\"apiToken\": \"api-token-here\"}})"); | ||
if (_testingState.TESTING) { | ||
bridge = _testingState.bridge; | ||
if (bridge === null) { | ||
throw new Error("You must set server._testingState.bridge before calling Initialize in the server testing state"); | ||
} | ||
logger.info("DDP SDK is using the testing bridge:", bridge); | ||
} else if (request._protobuf.environment === "MIDDLEWARE_SIMULATOR") { | ||
config.simulate = true; | ||
@@ -92,5 +99,6 @@ logger.info("DDP SDK is using the http firmware simulator"); | ||
bridge = new GRPCBridge({ | ||
grpcNumRetries: request._protobuf.grpcNumRetries | ||
connectionRetries: request._protobuf.connectionRetries | ||
}); | ||
} | ||
setup(bridge); | ||
@@ -104,2 +112,7 @@ } | ||
// TODO(cjrd) should we wait on a signal here instead and only throw this error on a timeout? | ||
if (_state.reInitializing && request._rpcName !== "Initialize") { | ||
throw new Error("DotDashPay SDK is currently reinitializing the DotDashPay platform -- retry your request again soon"); | ||
} | ||
// set up the protobuf META appropriately | ||
@@ -110,4 +123,2 @@ var correlationId = shortid(); | ||
cloudLogger.logAPIRequest(request._protoName, request._protobuf); | ||
// register the request | ||
@@ -150,6 +161,7 @@ _pendingRequests[correlationId] = { request: request, | ||
// TODO(cjrd) check response format and make sure it's valid | ||
var requestWrapper = _pendingRequests[response.message.META.correlationId]; | ||
var correlationId = response.message.META.correlationId; | ||
var requestWrapper = _pendingRequests[correlationId]; | ||
if (!requestWrapper) { | ||
logger.error("Received response without a corresponding request", response); | ||
// TODO(cjrd) errr, this is messy. So, we use a flag to prevent the initialize callbacks | ||
// TODO(cjrd) this is messy. So, we use a flag to prevent the initialize callbacks | ||
// from triggering. I know. this is messy. | ||
@@ -159,6 +171,5 @@ if (response.name === "SystemRestarted" && _state.initializeRequestArgs && _state.firstInitializationComplete) { | ||
logger.info("Received SystemRestarted message from middleware -- reinitializing"); | ||
// reset the server and then reinitialize | ||
// reset the server, and then reinitialize | ||
reset(function() { | ||
_state.reInitializing = true; | ||
sendRequest(_state.initializeRequestArgs); | ||
@@ -175,22 +186,30 @@ }); | ||
if (response.name === "Initialized" && _state.reInitializing) { | ||
logger.info("Finished reinitializing the system -- erroring out of existing requests"); | ||
var errorMessage = protoTools.getProtobuf("SdkError"); | ||
errorMessage.code = sdkErrorCodes.MISC_UNKNOWN; | ||
errorMessage.message = "DotDashPay platform encountered an unexpected error and had to restart. Contact support if this problem persists."; | ||
_.each(_pendingRequests, function (reqWrapperObj, prCorrelationId) { | ||
// don't error out of the reinitialization request | ||
if (prCorrelationId === correlationId) { | ||
return; | ||
} | ||
var errorName = getRPCErrorName(reqWrapperObj.request, prCorrelationId); | ||
logger.debug("Erroring out of existing request with correlationId", prCorrelationId); | ||
if (reqWrapperObj.request._signals[errorName] && reqWrapperObj.request._signals[errorName].getNumListeners() > 0) { | ||
reqWrapperObj.request._signals[errorName].dispatch(errorMessage); | ||
} else { | ||
logger.debug("Unhandled SDK error response for request", reqWrapperObj.request); | ||
} | ||
delete _pendingRequests[prCorrelationId]; | ||
}); | ||
_state.reInitializing = false; | ||
logger.info("Finished reinitializing the system"); | ||
return; | ||
} | ||
// pick the right signal | ||
var reqObj = requestWrapper.request; | ||
// pick the right signal we need, a little bit of work to do if it's a compound request | ||
var signal; | ||
var intermediates = _pendingRequests[response.message.META.correlationId].intermediates; | ||
if (response.name === "SdkError") { | ||
if (intermediates.length === 0) { | ||
signal = reqObj._rpcName + "Error"; | ||
} else { | ||
signal = intermediates[0] + "Error"; | ||
} | ||
} else { | ||
signal = response.rpc; | ||
} | ||
var signal = response.name === "SdkError" ? getRPCErrorName(reqObj, correlationId) : response.rpc; | ||
var intermediates = _pendingRequests[correlationId].intermediates; | ||
if (intermediates.length > 0) { | ||
@@ -208,18 +227,20 @@ if (response.rpc === "GotInteraction") { | ||
logger.debug("Server received handled SDK response", response); | ||
var cloudPromise = cloudLogger.logAPIResponse(response.name, response.message, true); | ||
if (config.simulate && cloudPromise) { | ||
return cloudPromise.then(function () { | ||
reqObj._signals[signal].dispatch(response.message); | ||
}); | ||
} else { | ||
reqObj._signals[signal].dispatch(response.message); | ||
} | ||
reqObj._signals[signal].dispatch(response.message); | ||
} else { | ||
logger.debug("Server received unhandled SDK response", response); | ||
cloudLogger.logAPIResponse(response.name, response.message, false); | ||
} | ||
}; | ||
var getRPCErrorName = function getRPCErrorName(request, correlationId) { | ||
var intermediates = _pendingRequests[correlationId].intermediates; | ||
var name; | ||
if (intermediates.length === 0) { | ||
name = request._rpcName + "Error"; | ||
} else { | ||
name = intermediates[0] + "Error"; | ||
} | ||
return name; | ||
}; | ||
/** | ||
@@ -248,3 +269,4 @@ Completely reset the server state | ||
sendRequest: sendRequest, | ||
reset: reset | ||
reset: reset, | ||
_testingState: _testingState | ||
}; |
@@ -34,3 +34,3 @@ /** | ||
.catch(function(err) { | ||
logger.error({err: err}, "Unable to send api log to coud servers"); | ||
logger.error({err: err}, "Unable to send api log to cloud servers"); | ||
}); | ||
@@ -37,0 +37,0 @@ } |
{ | ||
"name": "dotdashpay", | ||
"version": "1.1.1-rc", | ||
"version": "1.1.1", | ||
"description": "DotDashPay Node SDK", | ||
"main": "index.js", | ||
"engines": { | ||
"node": ">=0.12", | ||
"node": ">=4.0", | ||
"npm": ">=2.0" | ||
@@ -31,5 +31,5 @@ }, | ||
"eslint-config-defaults": "9.0.0", | ||
"istanbul": "0.4.5", | ||
"jsdoc": "3.3.3", | ||
"mocha": "3.0.2", | ||
"nyc": "11.2.1", | ||
"random-port": "0.1.0", | ||
@@ -40,4 +40,3 @@ "sinon": "1.17.1", | ||
"scripts": { | ||
"test": "./test.sh", | ||
"cover": "NODE_ENV=test ./node_modules/istanbul/lib/cli.js cover ./node_modules/mocha/bin/_mocha tests" | ||
"test": "./test.sh" | ||
}, | ||
@@ -44,0 +43,0 @@ "repository": { |
@@ -50,3 +50,3 @@ /** | ||
// middleware may just starting up at this point | ||
grpcNumRetries: process.env.DDP_INTEGRATION_TESTING ? 10000 : 5, | ||
connectionRetries: process.env.DDP_INTEGRATION_TESTING ? 10000 : 5, | ||
simulatorConfiguration: { | ||
@@ -53,0 +53,0 @@ apiToken: "@api-token()" |
@@ -52,3 +52,3 @@ /** | ||
// middleware may just starting up at this point | ||
grpcNumRetries: process.env.DDP_INTEGRATION_TESTING ? 10000 : 5, | ||
connectionRetries: process.env.DDP_INTEGRATION_TESTING ? 10000 : 5, | ||
simulatorConfiguration: { | ||
@@ -55,0 +55,0 @@ apiToken: "@api-token()" |
@@ -16,3 +16,3 @@ /** | ||
simulatorConfiguration: { 'apiToken': 'aeac1bc8f0735e4283305652ab' }, | ||
grpcNumRetries: 500, | ||
connectionRetries: 500, | ||
}; | ||
@@ -55,3 +55,3 @@ describe("Platform", function() { | ||
// middleware may just starting up at this point | ||
grpcNumRetries: process.env.DDP_INTEGRATION_TESTING ? 10000 : 5, | ||
connectionRetries: process.env.DDP_INTEGRATION_TESTING ? 10000 : 5, | ||
simulatorConfiguration: { | ||
@@ -58,0 +58,0 @@ apiToken: "@api-token()" |
@@ -19,3 +19,2 @@ /** | ||
transactionMode: "PAYMENT", | ||
customerId: "1337", | ||
}; | ||
@@ -58,3 +57,3 @@ describe("Platform", function() { | ||
// middleware may just starting up at this point | ||
grpcNumRetries: process.env.DDP_INTEGRATION_TESTING ? 10000 : 5, | ||
connectionRetries: process.env.DDP_INTEGRATION_TESTING ? 10000 : 5, | ||
simulatorConfiguration: { | ||
@@ -61,0 +60,0 @@ apiToken: "@api-token()" |
@@ -19,3 +19,2 @@ /** | ||
transactionMode: "PAYMENT", | ||
customerId: "1337", | ||
}; | ||
@@ -58,3 +57,3 @@ describe("Payment", function() { | ||
// middleware may just starting up at this point | ||
grpcNumRetries: process.env.DDP_INTEGRATION_TESTING ? 10000 : 5, | ||
connectionRetries: process.env.DDP_INTEGRATION_TESTING ? 10000 : 5, | ||
simulatorConfiguration: { | ||
@@ -61,0 +60,0 @@ apiToken: "@api-token()" |
@@ -19,3 +19,2 @@ /** | ||
transactionMode: "PAYMENT", | ||
customerId: "1337", | ||
}; | ||
@@ -58,3 +57,3 @@ describe("Payment", function() { | ||
// middleware may just starting up at this point | ||
grpcNumRetries: process.env.DDP_INTEGRATION_TESTING ? 10000 : 5, | ||
connectionRetries: process.env.DDP_INTEGRATION_TESTING ? 10000 : 5, | ||
simulatorConfiguration: { | ||
@@ -61,0 +60,0 @@ apiToken: "@api-token()" |
@@ -54,3 +54,3 @@ /** | ||
// middleware may just starting up at this point | ||
grpcNumRetries: process.env.DDP_INTEGRATION_TESTING ? 10000 : 5, | ||
connectionRetries: process.env.DDP_INTEGRATION_TESTING ? 10000 : 5, | ||
simulatorConfiguration: { | ||
@@ -57,0 +57,0 @@ apiToken: "@api-token()" |
@@ -52,3 +52,3 @@ /** | ||
// middleware may just starting up at this point | ||
grpcNumRetries: process.env.DDP_INTEGRATION_TESTING ? 10000 : 5, | ||
connectionRetries: process.env.DDP_INTEGRATION_TESTING ? 10000 : 5, | ||
simulatorConfiguration: { | ||
@@ -55,0 +55,0 @@ apiToken: "@api-token()" |
@@ -7,3 +7,3 @@ // This file is loaded by require.test.js to make sure basic | ||
if (process.env.DDP_INTEGRATION_TESTING) { | ||
configuration = {environment: 'DEVELOPMENT', grpcNumRetries: 1} | ||
configuration = {environment: 'DEVELOPMENT', connectionRetries: 1} | ||
} else { | ||
@@ -10,0 +10,0 @@ configuration = { |
@@ -8,4 +8,4 @@ var _ = require("lodash"); | ||
var fail = assert.fail; | ||
var util = require("util"); | ||
describe("Test failure points for the server", function () { | ||
@@ -17,3 +17,2 @@ // remove the server from the cache to force reload | ||
it("Server should throw an error if not initialized correctly", function () { | ||
@@ -28,1 +27,67 @@ try { | ||
}); | ||
describe("Receiving a System Restarted message", function () { | ||
var dotdashpay = require(".."); | ||
// replace the server bridge | ||
var mockBridge = { | ||
sendRequest: function() {}, | ||
setIncomingProtobufHandler: function() {}, | ||
startReceiving: function() {}, | ||
close: function(fn) {fn();} | ||
}; | ||
it("Send a request; receive system restarted; verify that the original requst errors out and the pending request is removed", function (done) { | ||
// The result of this initialize doesn't matter | ||
// it just sets up the bridge state correctly | ||
server._testingState.TESTING = true; | ||
server._testingState.bridge = mockBridge; | ||
var serverReceiveResponse = null; | ||
mockBridge.setIncomingProtobufHandler = function(handler) { | ||
serverReceiveResponse = handler; | ||
}; | ||
// grab the sendRequest so that we can find the correlation id | ||
mockBridge.sendRequest = function(req) { | ||
console.log("testing send request received", util.inspect(req)) | ||
var incomingCorrelationId = req._protobuf.META.correlationId; | ||
// send back an initialized response | ||
if (req._rpcName === "Initialize") { | ||
var initializedResponse = { | ||
name: "Initialized", | ||
rpc: "InitializedResponse", | ||
message: { | ||
META: { correlationId: incomingCorrelationId }, | ||
}, | ||
}; | ||
serverReceiveResponse(initializedResponse); | ||
return | ||
} | ||
} | ||
// environment doesn't matter here | ||
dotdashpay.platform.initialize({environment: "PERIPHERAL_SIMULATOR"}) | ||
// Any request would work here, just using this for simplicity | ||
dotdashpay.platform.listenForInteraction({}) | ||
.onListenForInteractionError(function(err) { | ||
// check that the system does not have any outstanding requests | ||
done(); | ||
}) | ||
// SystemRestarted | ||
var systemRestartedResponse = { | ||
name: "SystemRestarted", | ||
rpc: "SystemRestartedResponse", | ||
message: { | ||
META: { correlationId: "nomatter" } | ||
}, | ||
}; | ||
process.nextTick(function() { | ||
serverReceiveResponse(systemRestartedResponse); | ||
}.bind(this)); | ||
}); | ||
}); |
@@ -54,3 +54,3 @@ /** | ||
// middleware may just starting up at this point | ||
grpcNumRetries: process.env.DDP_INTEGRATION_TESTING ? 10000 : 5, | ||
connectionRetries: process.env.DDP_INTEGRATION_TESTING ? 10000 : 5, | ||
simulatorConfiguration: { | ||
@@ -57,0 +57,0 @@ apiToken: "@api-token()" |
@@ -52,3 +52,3 @@ /** | ||
// middleware may just starting up at this point | ||
grpcNumRetries: process.env.DDP_INTEGRATION_TESTING ? 10000 : 5, | ||
connectionRetries: process.env.DDP_INTEGRATION_TESTING ? 10000 : 5, | ||
simulatorConfiguration: { | ||
@@ -55,0 +55,0 @@ apiToken: "@api-token()" |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
702216
1
16566
101