|
|
@@ -2,10 +2,16 @@
|
|
|
|
|
|
const {
|
|
|
serialize: serializeCreatePartyRegistration,
|
|
|
-} = require('../xml/create-party-registration');
|
|
|
+} = require('../xml/register-party/create-party-registration');
|
|
|
+
|
|
|
+const {
|
|
|
+ serialize: serializeQueryRegistration,
|
|
|
+} = require('../xml/register-party/query-registration');
|
|
|
+
|
|
|
const {
|
|
|
parse: parseCreatedPartyRegistration,
|
|
|
-} = require('../xml/created-party-registration');
|
|
|
+} = require('../xml/register-party/created-party-registration');
|
|
|
+
|
|
|
const axios = require('axios');
|
|
|
const { escape } = require('querystring');
|
|
|
|
|
|
@@ -27,6 +33,23 @@ class Ven {
|
|
|
this.commonName = commonName;
|
|
|
}
|
|
|
|
|
|
+ async queryRegistration() {
|
|
|
+ const message = {
|
|
|
+ requestId: '2233',
|
|
|
+ };
|
|
|
+
|
|
|
+ const createdResponse = this.makeRequest(
|
|
|
+ 'EiRegisterParty',
|
|
|
+ message,
|
|
|
+ serializeQueryRegistration,
|
|
|
+ parseCreatedPartyRegistration,
|
|
|
+ );
|
|
|
+
|
|
|
+ // track registrationId for subsequent requests
|
|
|
+ this.registrationId = createdResponse.registrationId;
|
|
|
+ return createdResponse;
|
|
|
+ }
|
|
|
+
|
|
|
async register() {
|
|
|
const message = {
|
|
|
requestId: '2233',
|
|
|
@@ -40,7 +63,20 @@ class Ven {
|
|
|
oadrHttpPullModel: true,
|
|
|
};
|
|
|
|
|
|
- const xml = serializeCreatePartyRegistration(message);
|
|
|
+ const createdResponse = this.makeRequest(
|
|
|
+ 'EiRegisterParty',
|
|
|
+ message,
|
|
|
+ serializeCreatePartyRegistration,
|
|
|
+ parseCreatedPartyRegistration,
|
|
|
+ );
|
|
|
+
|
|
|
+ // track registrationId for subsequent requests
|
|
|
+ this.registrationId = createdResponse.registrationId;
|
|
|
+ return createdResponse;
|
|
|
+ }
|
|
|
+
|
|
|
+ async makeRequest(service, message, serializer, parser) {
|
|
|
+ const xml = serializer(message);
|
|
|
|
|
|
const config = {
|
|
|
headers: {
|
|
|
@@ -53,30 +89,20 @@ class Ven {
|
|
|
|
|
|
// axios will automatically reject HTTP response codes outside the 200-299 range
|
|
|
const httpResponse = await axios.post(
|
|
|
- `${this.endpoint}OpenADR2/Simple/2.0b/EiRegisterParty`,
|
|
|
+ `${this.endpoint}OpenADR2/Simple/2.0b/${service}`,
|
|
|
xml,
|
|
|
config,
|
|
|
);
|
|
|
- const registrationResponse = await parseCreatedPartyRegistration(
|
|
|
- httpResponse.data,
|
|
|
- );
|
|
|
+ const response = await parser(httpResponse.data);
|
|
|
|
|
|
// but OpenADR provides its own response code in the XML envelope, we need to check that
|
|
|
- if (
|
|
|
- registrationResponse.responseCode < 200 ||
|
|
|
- registrationResponse.responseCode >= 300
|
|
|
- ) {
|
|
|
+ if (response.responseCode < 200 || response.responseCode >= 300) {
|
|
|
throw new Error(
|
|
|
- 'Error during registration. ResponseCode=' +
|
|
|
- registrationResponse.responseCode +
|
|
|
- ', ResponseDescription=' +
|
|
|
- registrationResponse.responseDescription,
|
|
|
+ `Error during ${service} call. ResponseCode=${response.responseCode}, ResponseDescription=${response.responseDescription}`,
|
|
|
);
|
|
|
}
|
|
|
|
|
|
- // track registrationId for subsequent requests
|
|
|
- this.registrationId = registrationResponse.registrationId;
|
|
|
- return registrationResponse;
|
|
|
+ return response;
|
|
|
}
|
|
|
}
|
|
|
|