Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
// Copyright (c) Microsoft. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
'use strict';
var errors = require('azure-iot-common').errors;
var results = require('azure-iot-common').results;
var EventEmitter = require('events');
var AmqpReceiver = require('azure-iot-amqp-base').AmqpReceiver;
function SimulatedAmqp() {
this._config = {
sharedAccessSignature: 'ok'
};
this._receiver = new AmqpReceiver(new EventEmitter());
this.FeedbackReceiver = AmqpReceiver;
}
SimulatedAmqp.prototype.connect = function connect(done) {
if (!!done) done();
};
SimulatedAmqp.prototype.disconnect = function disconnect(done) {
// Copyright (c) Microsoft. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
'use strict';
var amqp10 = require('amqp10');
var AmqpMessage = require('./amqp_message.js');
var AmqpReceiver = require('./amqp_receiver.js');
var errors = require('azure-iot-common').errors;
var results = require('azure-iot-common').results;
var debug = require('debug')('amqp-common');
/**
* @class module:azure-iot-amqp-base.Amqp
* @classdesc Basic AMQP functionality used by higher-level IoT Hub libraries.
* Usually you'll want to avoid using this class and instead rely on higher-level implementations
* of the AMQP transport (see [azure-iot-device-amqp.Amqp]{@link module:azure-iot-device-amqp.Amqp} for example).
*
* @param {String} saslPlainUri URL to the IoT Hub instance including SASL-Plain credentials.
* @param {Boolean} autoSettleMessages Boolean indicating whether messages should be settled automatically or if the calling code will handle it.
* @param {String} sdkVersionString String identifying the SDK used (device or service).
*/
/*Codes_SRS_NODE_COMMON_AMQP_16_001: [The Amqp constructor shall accept three parameters:
A SASL-Plain URI to be used to connect to the IoT Hub instance
A Boolean indicating whether the client should automatically settle messages:
// Copyright (c) Microsoft. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
'use strict';
var EventEmitter = require('events').EventEmitter;
var util = require('util');
var anHourFromNow = require('azure-iot-common').anHourFromNow;
var results = require('azure-iot-common').results;
var ConnectionString = require('./connection_string.js');
var DefaultTransport = require('./amqp.js');
var Message = require('azure-iot-common').Message;
var SharedAccessSignature = require('./shared_access_signature.js');
var DeviceMethod = require('./device_method.js');
var RestApiClient = require('./rest_api_client.js');
/**
* @class module:azure-iothub.Client
* @classdesc Creates an IoT Hub service client. Normally, consumers will
* call one of the factory methods,
* {@link module:azure-iothub.Client.fromConnectionString|fromConnectionString} or
* {@link module:azure-iothub.Client.fromSharedAccessSignature|fromSharedAccessSignature},
* to create an IoT Hub service Client.
* @param {Object} transport An object that implements the interface
* expected of a transport object, e.g.,
// Copyright (c) Microsoft. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
'use strict';
var MqttReceiver = require('./mqtt_receiver.js');
var debug = require('debug')('mqtt-common');
var PackageJson = require('../package.json');
var errors = require('azure-iot-common').errors;
var results = require('azure-iot-common').results;
var endpoint = require('azure-iot-common').endpoint;
var querystring = require('querystring');
/**
* @class module:azure-iot-device-mqtt.MqttBase
* @classdesc Base MQTT transport implementation used by higher-level IoT Hub libraries.
* You generally want to use these higher-level objects (such as [azure-iot-device-mqtt.Mqtt]{@link module:azure-iot-device-mqtt.Mqtt})
* rather than this one.
*
* @param {Object} config The configuration object derived from the connection string.
*/
/*Codes_SRS_NODE_COMMON_MQTT_BASE_16_004: [The `MqttBase` constructor shall instanciate the default MQTT.JS library if no argument is passed to it.]*/
/*Codes_SRS_NODE_COMMON_MQTT_BASE_16_005: [The `MqttBase` constructor shall use the object passed as argument instead of the default MQTT.JS library if it's not falsy.]*/
function MqttBase(mqttprovider) {
this.mqttprovider = mqttprovider ? mqttprovider : require('mqtt');
}
// Copyright (c) Microsoft. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
'use strict';
var EventEmitter = require('events').EventEmitter;
var util = require('util');
var Message = require('azure-iot-common').Message;
var results = require('azure-iot-common').results;
/**
* @class module:azure-iot-amqp-base.AmqpReceiver
* @classdesc The `AmqpReceiver` class is used to receive and settle messages.
*
* @param {Object} amqpReceiver The Receiver object that is created by the client using the `node-amqp10` library.
*
* @fires module:azure-iot-amqp-base.AmqpReceiver#message
* @fires module:azure-iot-amqp-base.AmqpReceiver#errorReceived
*/
/* Codes_SRS_NODE_IOTHUB_AMQPRECEIVER_16_001: [The AmqpReceiver method shall create a new instance of AmqpReceiver.]*/
/* Codes_SRS_NODE_IOTHUB_AMQPRECEIVER_16_002: [The created AmqpReceiver object shall emit a ‘message’ event when a message is received.]*/
/* Codes_SRS_NODE_IOTHUB_AMQPRECEIVER_16_003: [The created AmqpReceiver object shall emit a ‘errorReceived’ event when an error is received.]*/
/* Codes_SRS_NODE_IOTHUB_AMQPRECEIVER_16_004: [If the receiver object passed as an argument is falsy, the AmqpReceiver should throw an ReferenceError]*/
function AmqpReceiver(amqpReceiver) {
if (!amqpReceiver) { throw new ReferenceError('amqpReceiver'); }
// Copyright (c) Microsoft. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
'use strict';
var Base = require('azure-iot-http-base').Http;
var endpoint = require('azure-iot-common').endpoint;
var HttpReceiver = require('./http_receiver.js');
var PackageJson = require('../package.json');
var results = require('azure-iot-common').results;
var translateError = require('./http_errors.js');
var MESSAGE_PROP_HEADER_PREFIX = 'iothub-app-';
/*Codes_SRS_NODE_DEVICE_HTTP_05_009: [When any Http method receives an HTTP response with a status code >= 300, it shall invoke the done callback function with the following arguments:
err - the standard JavaScript Error object, with the Node.js http.ServerResponse object attached as the property response]*/
/*Codes_SRS_NODE_DEVICE_HTTP_05_010: [When any Http method receives an HTTP response with a status code < 300, it shall invoke the done callback function with the following arguments:
err - null
body - the body of the HTTP response
response - the Node.js http.ServerResponse object returned by the transport]*/
function handleResponse(done) {
return function onResponse(err, body, response) {
if (!err) {
done(null, new results.MessageEnqueued(response));
} else {
var error = response ? translateError('Could not send message: ' + err.message, body, response) : err;
// Copyright (c) Microsoft. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
'use strict';
var amqp10 = require('amqp10');
var Promise = require('bluebird');
var AmqpMessage = require('./amqp_message.js');
var AmqpReceiver = require('./amqp_receiver.js');
var errors = require('azure-iot-common').errors;
var results = require('azure-iot-common').results;
var uuid = require('uuid');
var debug = require('debug')('amqp-common');
var _putTokenSendingEndpoint = '$cbs';
var _putTokenReceivingEndpoint = '$cbs';
/**
* @class module:azure-iot-amqp-base.Amqp
* @classdesc Basic AMQP functionality used by higher-level IoT Hub libraries.
* Usually you'll want to avoid using this class and instead rely on higher-level implementations
* of the AMQP transport (see [azure-iot-device-amqp.Amqp]{@link module:azure-iot-device-amqp.Amqp} for example).
*
* @param {Boolean} autoSettleMessages Boolean indicating whether messages should be settled automatically or if the calling code will handle it.
* @param {String} sdkVersionString String identifying the SDK used (device or service).
Client.prototype._disconnectHandler = function (reason) {
/*Codes_SRS_NODE_IOTHUB_CLIENT_16_004: [** The `disconnect` event shall be emitted when the client is disconnected from the server.]*/
var evt = new azure_iot_common_1.results.Disconnected();
evt.reason = reason;
this.emit('disconnect', evt);
};
/**
this._fsm.handle('disconnect', function (err) {
if (err) {
done(getTranslatedError(err, 'error while disconnecting'));
}
else {
done(null, new azure_iot_common_1.results.Disconnected());
}
});
};
_onEnter: function (applicationSuppliedSas, callback) {
if (!applicationSuppliedSas) {
_this._renewalTimeout = setTimeout(_this._handleSASRenewal.bind(_this), _this._renewalNumberOfMilliseconds);
}
callback(null, new azure_iot_common_1.results.Connected());
},
_onExit: function (callback) {