Azure / azure-iot-hub-node

Azure IoT Hub Data Plane Node SDK
MIT License
1 stars 7 forks source link

scheduleTwinUpdate throws an error if "maxExecutionTimeInSeconds" isn't set even if it's marked as optional #29

Open Apokalypt opened 1 year ago

Apokalypt commented 1 year ago

Problem encounter

The "maxExecutionTimeInSeconds" property is marked as optional in your typing file, but it isn't really. In fact, depending on the parameters passed, you may or may not set a default value. The problem is that the Microsoft API expects a value, and so, when you don't set a default value, the API throws an error...

What should happen ?

In ALL cases, when the property "maxExecutionTimeInSeconds" isn't set, you should set the default one OR never set it but ask the developer to set a value

Code to reproduce

const { JobClient } = require('azure-iothub')

const jobClient = JobClient.fromConnectionString(process.env['IotHubConnectionString'])

setImmediate( async () => {
        const id = 'aRandomId'
        await jobClient.scheduleTwinUpdate(
            id,
            "tags.model = 'test' AND deviceId IN ['aValidDeviceId']",
            {
                etag: '*',
                tags: { model: 'test', firmwareGroup: 'test-group-A' },
                properties: {
                    desired: {
                        firmware: 'aValue'
                    }
                }
            },
            new Date()
        )
})