Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
drainRequester.on('nextRequest', () => {
const request = this._http.buildRequest('GET', path + endpoint.versionQueryString(), httpHeaders, this._config.host, this._config.x509, (err, body, res) => {
if (!err) {
if (body) {
const msg = this._http.toMessage(res, body);
if (this._opts.drain) {
drainRequester.emit('nextRequest');
}
this.emit('message', msg);
}
} else {
err.response = res;
err.responseBody = body;
this.emit('errorReceived', err);
}
});
request.end();
});
let path = endpoint.feedbackPath(config.deviceId, message.lockToken);
let httpHeaders = {
'If-Match': message.lockToken,
'User-Agent': 'azure-iot-device/' + packageJson.version
};
this._insertAuthHeaderIfNecessary(httpHeaders);
/*Codes_SRS_NODE_DEVICE_HTTP_RECEIVER_16_009: [abandon shall construct an HTTP request using information supplied by the caller, as follows:
POST /devices//messages/devicebound//abandon?api-version= HTTP/1.1
Authorization:
If-Match:
Host: ]
*/
if (action === 'abandon') {
path += '/abandon' + endpoint.versionQueryString();
method = 'POST';
resultConstructor = results.MessageAbandoned;
} else if (action === 'reject') {
/*Codes_SRS_NODE_DEVICE_HTTP_RECEIVER_16_010: [reject shall construct an HTTP request using information supplied by the caller, as follows:
DELETE /devices//messages/devicebound/?api-version=&reject HTTP/1.1
Authorization:
If-Match:
Host: ]*/
path += endpoint.versionQueryString() + '&reject';
method = 'DELETE';
resultConstructor = results.MessageRejected;
} else {
/*Codes_SRS_NODE_DEVICE_HTTP_RECEIVER_16_011: [complete shall construct an HTTP request using information supplied by the caller, as follows:
DELETE /devices//messages/devicebound/?api-version= HTTP/1.1
Authorization:
If-Match:
} else if (action === 'reject') {
/*Codes_SRS_NODE_DEVICE_HTTP_RECEIVER_16_010: [reject shall construct an HTTP request using information supplied by the caller, as follows:
DELETE /devices//messages/devicebound/?api-version=&reject HTTP/1.1
Authorization:
If-Match:
Host: ]*/
path += endpoint.versionQueryString() + '&reject';
method = 'DELETE';
resultConstructor = results.MessageRejected;
} else {
/*Codes_SRS_NODE_DEVICE_HTTP_RECEIVER_16_011: [complete shall construct an HTTP request using information supplied by the caller, as follows:
DELETE /devices//messages/devicebound/?api-version= HTTP/1.1
Authorization:
If-Match:
Host: ]*/
path += endpoint.versionQueryString();
method = 'DELETE';
resultConstructor = results.MessageCompleted;
}
/*Codes_SRS_NODE_DEVICE_HTTP_05_008: [If any Http method encounters an error before it can send the request, it shall invoke the done callback function and pass the standard JavaScript Error object with a text description of the error (err.message).]*/
const request = this._http.buildRequest(method, path, httpHeaders, config.host, this._config.x509, (err, body, response) => {
if (done) {
if (!err && response.statusCode === 204) {
const result = new resultConstructor(response);
done(null, result);
} else {
err.response = response;
err.responseBody = body;
done(err);
}
}
delete(deviceId: string, done: Registry.ResponseCallback): void {
/*Codes_SRS_NODE_IOTHUB_REGISTRY_07_007: [The delete method shall throw ReferenceError if the supplied deviceId is falsy.]*/
if (!deviceId) {
throw new ReferenceError('deviceId is \'' + deviceId + '\'');
}
/*Codes_SRS_NODE_IOTHUB_REGISTRY_16_030: [The `delete` method shall construct an HTTP request using information supplied by the caller, as follows:
```
DELETE /devices/?api-version= HTTP/1.1
Authorization:
If-Match: *
Request-Id:
```]*/
const path = endpoint.devicePath(encodeURIComponent(deviceId)) + endpoint.versionQueryString();
const httpHeaders = {
'If-Match': '*'
};
this._restApiClient.executeApiCall('DELETE', path, httpHeaders, null, done);
}
get(deviceId: string, done: Registry.DeviceCallback): void {
/*Codes_SRS_NODE_IOTHUB_REGISTRY_05_006: [The get method shall throw ReferenceError if the supplied deviceId is falsy.]*/
if (!deviceId) {
throw new ReferenceError('deviceId is \'' + deviceId + '\'');
}
/*Codes_SRS_NODE_IOTHUB_REGISTRY_16_028: [The `get` method shall construct an HTTP request using information supplied by the caller, as follows:
```
GET /devices/?api-version= HTTP/1.1
Authorization:
Request-Id:
```]*/
const path = endpoint.devicePath(encodeURIComponent(deviceId)) + endpoint.versionQueryString();
this._restApiClient.executeApiCall('GET', path, null, null, (err, device, httpResponse) => {
if (err) {
done(err);
} else {
done(null, new Device(device), httpResponse);
}
});
}
POST /devices//messages/devicebound//abandon?api-version= HTTP/1.1
Authorization:
If-Match:
Host: ]
*/
if (action === 'abandon') {
path += '/abandon' + endpoint.versionQueryString();
method = 'POST';
resultConstructor = results.MessageAbandoned;
} else if (action === 'reject') {
/*Codes_SRS_NODE_DEVICE_HTTP_RECEIVER_16_010: [reject shall construct an HTTP request using information supplied by the caller, as follows:
DELETE /devices//messages/devicebound/?api-version=&reject HTTP/1.1
Authorization:
If-Match:
Host: ]*/
path += endpoint.versionQueryString() + '&reject';
method = 'DELETE';
resultConstructor = results.MessageRejected;
} else {
/*Codes_SRS_NODE_DEVICE_HTTP_RECEIVER_16_011: [complete shall construct an HTTP request using information supplied by the caller, as follows:
DELETE /devices//messages/devicebound/?api-version= HTTP/1.1
Authorization:
If-Match:
Host: ]*/
path += endpoint.versionQueryString();
method = 'DELETE';
resultConstructor = results.MessageCompleted;
}
/*Codes_SRS_NODE_DEVICE_HTTP_05_008: [If any Http method encounters an error before it can send the request, it shall invoke the done callback function and pass the standard JavaScript Error object with a text description of the error (err.message).]*/
const request = this._http.buildRequest(method, path, httpHeaders, config.host, this._config.x509, (err, body, response) => {
if (done) {
list(done: Callback): void {
/*Codes_SRS_NODE_IOTHUB_REGISTRY_16_029: [The `list` method shall construct an HTTP request using information supplied by the caller, as follows:
```
GET /devices?api-version= HTTP/1.1
Authorization:
Request-Id:
```]*/
const path = endpoint.devicePath('') + endpoint.versionQueryString();
this._restApiClient.executeApiCall('GET', path, null, null, (err, devices, httpResponse) => {
if (err) {
done(err);
} else {
done(null, devices ? devices.map((device) => new Device(device)) : [], httpResponse);
}
});
}
Request-Id:
```
]*/
/*Codes_SRS_NODE_IOTHUB_REGISTRY_06_018: [The `removeDevices` method shall construct an HTTP request using information supplied by the caller, as follows:
```
POST /devices?api-version= HTTP/1.1
Authorization:
Content-Type: application/json; charset=utf-8
Request-Id:
```
]*/
const path = '/devices' + endpoint.versionQueryString();
const httpHeaders = {
'Content-Type': 'application/json; charset=utf-8'
};
this._restApiClient.executeApiCall('POST', path, httpHeaders, devices, done);
}
cancelJob(jobId: string | number, done: JobClient.JobCallback): void {
/*Codes_SRS_NODE_JOB_CLIENT_16_008: [The `cancelJob` method shall throw a `ReferenceError` if `jobId` is `null`, `undefined` or an empty string.]*/
if (jobId === undefined || jobId === null || jobId === '') throw new ReferenceError('jobId cannot be \'' + jobId + '\'');
/*Codes_SRS_NODE_JOB_CLIENT_16_009: [The `cancelJob` method shall construct the HTTP request as follows:
```
POST /jobs/v2//cancel?api-version=
Authorization:
Content-Type: application/json; charset=utf-8
Request-Id:
User-Agent: /
```]*/
const path = '/jobs/v2/' + jobId + '/cancel' + endpoint.versionQueryString();
this._restApiClient.executeApiCall('POST', path, null, null, done);
}