balena-register-device

Balena device registration utilities

Usage no npm install needed!

<script type="module">
  import balenaRegisterDevice from 'https://cdn.skypack.dev/balena-register-device';
</script>

README

��b�a�l�e�n�a�-�r�e�g�i�s�t�e�r�-�d�e�v�i�c�e� � �=�=�=�=�=�=�=�=�=�=�=�=�=�=�=�=�=�=�=�=�=� � � � �>� �B�a�l�e�n�a� �d�e�v�i�c�e� �r�e�g�i�s�t�r�a�t�i�o�n� �u�t�i�l�i�t�i�e�s�.� � � � �[�!�[�n�p�m� �v�e�r�s�i�o�n�]�(�h�t�t�p�s�:�/�/�b�a�d�g�e�.�f�u�r�y�.�i�o�/�j�s�/�b�a�l�e�n�a�-�r�e�g�i�s�t�e�r�-�d�e�v�i�c�e�.�s�v�g�)�]�(�h�t�t�p�:�/�/�b�a�d�g�e�.�f�u�r�y�.�i�o�/�j�s�/�b�a�l�e�n�a�-�r�e�g�i�s�t�e�r�-�d�e�v�i�c�e�)� � �[�!�[�d�e�p�e�n�d�e�n�c�i�e�s�]�(�h�t�t�p�s�:�/�/�d�a�v�i�d�-�d�m�.�o�r�g�/�b�a�l�e�n�a�-�i�o�-�m�o�d�u�l�e�s�/�b�a�l�e�n�a�-�r�e�g�i�s�t�e�r�-�d�e�v�i�c�e�.�s�v�g�)�]�(�h�t�t�p�s�:�/�/�d�a�v�i�d�-�d�m�.�o�r�g�/�b�a�l�e�n�a�-�i�o�-�m�o�d�u�l�e�s�/�b�a�l�e�n�a�-�r�e�g�i�s�t�e�r�-�d�e�v�i�c�e�.�s�v�g�)� � �[�!�[�B�u�i�l�d� �S�t�a�t�u�s�]�(�h�t�t�p�s�:�/�/�t�r�a�v�i�s�-�c�i�.�o�r�g�/�b�a�l�e�n�a�-�i�o�-�m�o�d�u�l�e�s�/�b�a�l�e�n�a�-�r�e�g�i�s�t�e�r�-�d�e�v�i�c�e�.�s�v�g�?�b�r�a�n�c�h�=�m�a�s�t�e�r�)�]�(�h�t�t�p�s�:�/�/�t�r�a�v�i�s�-�c�i�.�o�r�g�/�b�a�l�e�n�a�-�i�o�-�m�o�d�u�l�e�s�/�b�a�l�e�n�a�-�r�e�g�i�s�t�e�r�-�d�e�v�i�c�e�)� � �[�!�[�B�u�i�l�d� �s�t�a�t�u�s�]�(�h�t�t�p�s�:�/�/�c�i�.�a�p�p�v�e�y�o�r�.�c�o�m�/�a�p�i�/�p�r�o�j�e�c�t�s�/�s�t�a�t�u�s�/�u�h�8�b�g�4�5�p�x�x�y�x�2�q�i�f�/�b�r�a�n�c�h�/�m�a�s�t�e�r�?�s�v�g�=�t�r�u�e�)�]�(�h�t�t�p�s�:�/�/�c�i�.�a�p�p�v�e�y�o�r�.�c�o�m�/�p�r�o�j�e�c�t�/�r�e�s�i�n�-�i�o�/�b�a�l�e�n�a�-�r�e�g�i�s�t�e�r�-�d�e�v�i�c�e�/�b�r�a�n�c�h�/�m�a�s�t�e�r�)� � � � �I�n�s�t�a�l�l�a�t�i�o�n� � �-�-�-�-�-�-�-�-�-�-�-�-� � � � �I�n�s�t�a�l�l� �balena-register-device� �b�y� �r�u�n�n�i�n�g�:� � � � �sh $ npm install --save balena-register-device � � � � �D�o�c�u�m�e�n�t�a�t�i�o�n� � �-�-�-�-�-�-�-�-�-�-�-�-�-� � � � �B�a�l�e�n�a�-�R�e�g�i�s�t�e�r�-�D�e�v�i�c�e� �e�x�p�o�r�t�s� �a� �f�a�c�t�o�r�y� �f�u�n�c�t�i�o�n�,� �w�h�i�c�h� �m�u�s�t� �b�e� �c�a�l�l�e�d� �w�i�t�h� �a� �d�e�p�e�n�d�e�n�c�i�e�s� �o�b�j�e�c�t�,� �c�o�n�t�a�i�n�i�n�g� �a� �c�o�n�f�i�g�u�r�e�d� �[�balena-request�]�(�h�t�t�p�s�:�/�/�g�i�t�h�u�b�.�c�o�m�/�b�a�l�e�n�a�-�i�o�-�m�o�d�u�l�e�s�/�b�a�l�e�n�a�-�r�e�q�u�e�s�t�)� �i�n�s�t�a�n�c�e�.� � � � �E�x�a�m�p�l�e�:� � �coffee deviceRegister = require('balena-register-device')({ request: request # An instantiated balena-request instance }) � � � � �#�#�#� �d�e�v�i�c�e�R�e�g�i�s�t�e�r�.�g�e�n�e�r�a�t�e�U�n�i�q�u�e�K�e�y�(�)� � � � �G�e�n�e�r�a�t�e� �a� �r�a�n�d�o�m� �k�e�y�,� �u�s�e�f�u�l� �f�o�r� �b�o�t�h� �u�u�i�d� �a�n�d� �a�p�i� �k�e�y�.� � � � �E�x�a�m�p�l�e�:� � �coffee randomKey = deviceRegister.generateUniqueKey() # randomKey is a randomly generated key that can be used as either a uuid or an api key console.log(randomKey) � � � � �#�#�#� �d�e�v�i�c�e�R�e�g�i�s�t�e�r�.�r�e�g�i�s�t�e�r�(�O�b�j�e�c�t� �o�p�t�i�o�n�s�,� �F�u�n�c�t�i�o�n� �c�a�l�l�b�a�c�k�)� � � � �R�e�g�i�s�t�e�r� �a� �d�e�v�i�c�e� �w�i�t�h� �B�a�l�e�n�a�.� � � � ��N�o�t�i�c�e��:� �Y�o�u� �c�a�n� �u�s�e� �t�h�i�s� �f�u�n�c�t�i�o�n� �a�s� �a� �p�r�o�m�i�s�e� �i�f� �y�o�u� �o�m�i�t� �t�h�e� �callback� �a�r�g�u�m�e�n�t�.� � � � �T�h�e� �options� �o�b�j�e�c�t� �r�e�q�u�i�r�e�s� �t�h�e� �f�o�l�l�o�w�i�n�g� �p�r�o�p�e�r�t�i�e�s�:� � � � �-� �Number userId�:� �T�h�e� �u�s�e�r� �i�d� �-� �o�p�t�i�o�n�a�l�.� � �-� �Number applicationId�:� �T�h�e� �a�p�p�l�i�c�a�t�i�o�n� �i�d�.� � �-� �String uuid�:� �T�h�e� �d�e�v�i�c�e�'�s� �U�U�I�D�.� � �-� �String deviceType�:� �T�h�e� �d�e�v�i�c�e� �t�y�p�e� �s�l�u�g�.� � �-� �String deviceApiKey�:� �T�h�e� �A�P�I� �k�e�y� �t�o� �c�r�e�a�t�e� �f�o�r� �t�h�e� �n�e�w�l�y� �r�e�g�i�s�t�e�r�e�d� �d�e�v�i�c�e�.� � �-� �String provisioningApiKey�:� �T�h�e� �p�r�o�v�i�s�i�o�n�i�n�g� �A�P�I� �K�e�y�.� � �-� �String apiEndpoint�:� �T�h�e� �A�P�I� �e�n�d�p�o�i�n�t�.� � � � �T�h�e� �callback� �g�e�t�s� �c�a�l�l�e�d� �w�i�t�h� �t�w�o� �a�r�g�u�m�e�n�t�s�:� �(error, deviceInfo)�,� �w�h�e�r�e� �deviceInfo� �i�s� �a�n� �o�b�j�e�c�t� �c�o�n�t�a�i�n�i�n�g� �o�n�e� �p�r�o�p�e�r�t�y�:� �t�h�e� �id� �f�o�r� �t�h�e� �d�e�v�i�c�e� �t�h�a�t� �w�a�s� �j�u�s�t� �r�e�g�i�s�t�e�r�e�d�.� � � � �E�x�a�m�p�l�e�:� � � � �coffee deviceRegister.register userId: 199 applicationId: 10350 uuid: '...' deviceType: 'raspberry-pi' deviceApiKey: '...' provisioningApiKey: '...' apiEndpoint: 'https://api.balena-cloud.com' , (error, deviceInfo) -> throw error if error? console.log(deviceInfo) # { id } � � � � �T�e�s�t�s� � �-�-�-�-�-� � � � �R�u�n� �t�h�e� �t�e�s�t� �s�u�i�t�e� �b�y� �d�o�i�n�g�:� � � � �sh $ npm test � � � � �C�o�n�t�r�i�b�u�t�e� � �-�-�-�-�-�-�-�-�-�-� � � � �-� �I�s�s�u�e� �T�r�a�c�k�e�r�:� �[�g�i�t�h�u�b�.�c�o�m�/�b�a�l�e�n�a�-�i�o�-�m�o�d�u�l�e�s�/�b�a�l�e�n�a�-�r�e�g�i�s�t�e�r�-�d�e�v�i�c�e�/�i�s�s�u�e�s�]�(�h�t�t�p�s�:�/�/�g�i�t�h�u�b�.�c�o�m�/�b�a�l�e�n�a�-�i�o�-�m�o�d�u�l�e�s�/�b�a�l�e�n�a�-�r�e�g�i�s�t�e�r�-�d�e�v�i�c�e�/�i�s�s�u�e�s�)� � �-� �S�o�u�r�c�e� �C�o�d�e�:� �[�g�i�t�h�u�b�.�c�o�m�/�b�a�l�e�n�a�-�i�o�-�m�o�d�u�l�e�s�/�b�a�l�e�n�a�-�r�e�g�i�s�t�e�r�-�d�e�v�i�c�e�]�(�h�t�t�p�s�:�/�/�g�i�t�h�u�b�.�c�o�m�/�b�a�l�e�n�a�-�i�o�-�m�o�d�u�l�e�s�/�b�a�l�e�n�a�-�r�e�g�i�s�t�e�r�-�d�e�v�i�c�e�)� � � � �B�e�f�o�r�e� �s�u�b�m�i�t�t�i�n�g� �a� �P�R�,� �p�l�e�a�s�e� �m�a�k�e� �s�u�r�e� �t�h�a�t� �y�o�u� �i�n�c�l�u�d�e� �t�e�s�t�s�,� �a�n�d� �t�h�a�t� �[�c�o�f�f�e�e�l�i�n�t�]�(�h�t�t�p�:�/�/�w�w�w�.�c�o�f�f�e�e�l�i�n�t�.�o�r�g�/�)� �r�u�n�s� �w�i�t�h�o�u�t� �a�n�y� �w�a�r�n�i�n�g�:� � � � �sh $ npm run lint � � � � �S�u�p�p�o�r�t� � �-�-�-�-�-�-�-� � � � �I�f� �y�o�u�'�r�e� �h�a�v�i�n�g� �a�n�y� �p�r�o�b�l�e�m�,� �p�l�e�a�s�e� �[�r�a�i�s�e� �a�n� �i�s�s�u�e�]�(�h�t�t�p�s�:�/�/�g�i�t�h�u�b�.�c�o�m�/�b�a�l�e�n�a�-�i�o�-�m�o�d�u�l�e�s�/�b�a�l�e�n�a�-�r�e�g�i�s�t�e�r�-�d�e�v�i�c�e�/�i�s�s�u�e�s�/�n�e�w�)� �o�n� �G�i�t�H�u�b�.� � � � �L�i�c�e�n�s�e� � �-�-�-�-�-�-�-� � � � �T�h�e� �p�r�o�j�e�c�t� �i�s� �l�i�c�e�n�s�e�d� �u�n�d�e�r� �t�h�e� �A�p�a�c�h�e� �2�.�0� �l�i�c�e�n�s�e�.� � �