@pipechela/ewelink-api 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (43) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +22 -0
  3. package/index.d.ts +223 -0
  4. package/main.js +114 -0
  5. package/package.json +67 -0
  6. package/src/classes/ChangeStateZeroconf.js +34 -0
  7. package/src/classes/DevicePowerUsageRaw.js +58 -0
  8. package/src/classes/WebSocket.js +57 -0
  9. package/src/classes/Zeroconf.js +91 -0
  10. package/src/data/constants.js +7 -0
  11. package/src/data/devices-channel-length.json +20 -0
  12. package/src/data/devices-type-uuid.json +55 -0
  13. package/src/data/errors.js +23 -0
  14. package/src/helpers/device-control.js +58 -0
  15. package/src/helpers/ewelink.js +68 -0
  16. package/src/helpers/utilities.js +29 -0
  17. package/src/mixins/checkDeviceUpdate.js +48 -0
  18. package/src/mixins/checkDevicesUpdates.js +54 -0
  19. package/src/mixins/deviceControl.js +272 -0
  20. package/src/mixins/getCredentials.js +54 -0
  21. package/src/mixins/getDevice.js +37 -0
  22. package/src/mixins/getDeviceChannelCount.js +26 -0
  23. package/src/mixins/getDeviceCurrentTH.js +55 -0
  24. package/src/mixins/getDeviceIP.js +15 -0
  25. package/src/mixins/getDevicePowerState.js +47 -0
  26. package/src/mixins/getDevicePowerUsage.js +27 -0
  27. package/src/mixins/getDevicePowerUsageRaw.js +30 -0
  28. package/src/mixins/getDevices.js +37 -0
  29. package/src/mixins/getFirmwareVersion.js +23 -0
  30. package/src/mixins/getRegion.js +23 -0
  31. package/src/mixins/index.js +43 -0
  32. package/src/mixins/makeRequest.js +54 -0
  33. package/src/mixins/openWebSocket.js +44 -0
  34. package/src/mixins/saveDevicesCache.js +29 -0
  35. package/src/mixins/setDevicePowerState.js +90 -0
  36. package/src/mixins/toggleDevice.js +13 -0
  37. package/src/parsers/parseFirmwareUpdates.js +16 -0
  38. package/src/parsers/parsePowerUsage.js +38 -0
  39. package/src/payloads/credentialsPayload.js +13 -0
  40. package/src/payloads/deviceStatus.js +12 -0
  41. package/src/payloads/wssLoginPayload.js +19 -0
  42. package/src/payloads/wssUpdatePayload.js +17 -0
  43. package/src/payloads/zeroConfUpdatePayload.js +17 -0
@@ -0,0 +1,37 @@
1
+ const { nonce, timestamp, _get } = require('../helpers/utilities');
2
+ const errors = require('../data/errors');
3
+
4
+ module.exports = {
5
+ /**
6
+ * Get information for a specific device
7
+ *
8
+ * @param deviceId
9
+ * @returns {Promise<*|null|{msg: string, error: *}>}
10
+ */
11
+ async getDevice(deviceId) {
12
+ if (this.devicesCache) {
13
+ return this.devicesCache.find(dev => dev.deviceid === deviceId) || null;
14
+ }
15
+
16
+ const { APP_ID } = this;
17
+
18
+ const device = await this.makeRequest({
19
+ uri: `/user/device/${deviceId}`,
20
+ qs: {
21
+ deviceid: deviceId,
22
+ appid: APP_ID,
23
+ nonce,
24
+ ts: timestamp,
25
+ version: 8,
26
+ },
27
+ });
28
+
29
+ const error = _get(device, 'error', false);
30
+
31
+ if (error) {
32
+ return { error, msg: errors[error] };
33
+ }
34
+
35
+ return device;
36
+ },
37
+ };
@@ -0,0 +1,26 @@
1
+ const { _get } = require('../helpers/utilities');
2
+ const errors = require('../data/errors');
3
+
4
+ const { getDeviceChannelCount } = require('../helpers/ewelink');
5
+
6
+ module.exports = {
7
+ /**
8
+ * Get device channel count
9
+ *
10
+ * @param deviceId
11
+ *
12
+ * @returns {Promise<{switchesAmount: *, status: string}|{msg: string, error: *}>}
13
+ */
14
+ async getDeviceChannelCount(deviceId) {
15
+ const device = await this.getDevice(deviceId);
16
+ const error = _get(device, 'error', false);
17
+ const uiid = _get(device, 'extra.extra.uiid', false);
18
+ const switchesAmount = getDeviceChannelCount(uiid);
19
+
20
+ if (error) {
21
+ return { error, msg: errors[error] };
22
+ }
23
+
24
+ return { status: 'ok', switchesAmount };
25
+ },
26
+ };
@@ -0,0 +1,55 @@
1
+ const { _get } = require('../helpers/utilities');
2
+ const errors = require('../data/errors');
3
+
4
+ module.exports = {
5
+ /**
6
+ * Get device current temperature & humidity
7
+ * @param deviceId
8
+ * @param type
9
+ * @returns {Promise<{temperature: *, humidity: *, status: string}|{msg: string, error: *}>}
10
+ */
11
+ async getDeviceCurrentTH(deviceId, type = '') {
12
+ const device = await this.getDevice(deviceId);
13
+ const error = _get(device, 'error', false);
14
+ const temperature = _get(device, 'params.currentTemperature', false);
15
+ const humidity = _get(device, 'params.currentHumidity', false);
16
+
17
+ if (error) {
18
+ return device;
19
+ }
20
+
21
+ if (!temperature || !humidity) {
22
+ return { error: 404, msg: errors.noSensor };
23
+ }
24
+
25
+ const data = { status: 'ok', temperature, humidity };
26
+
27
+ if (type === 'temp') {
28
+ delete data.humidity;
29
+ }
30
+
31
+ if (type === 'humd') {
32
+ delete data.temperature;
33
+ }
34
+
35
+ return data;
36
+ },
37
+
38
+ /**
39
+ * Get device current temperature
40
+ * @param deviceId
41
+ * @returns {Promise<*|{temperature: *, status: string}|{msg: string, error: *}>}
42
+ */
43
+ async getDeviceCurrentTemperature(deviceId) {
44
+ return this.getDeviceCurrentTH(deviceId, 'temp');
45
+ },
46
+
47
+ /**
48
+ * Get device current humidity
49
+ * @param deviceId
50
+ * @returns {Promise<*|{temperature: *, status: string}|{msg: string, error: *}>}
51
+ */
52
+ async getDeviceCurrentHumidity(deviceId) {
53
+ return this.getDeviceCurrentTH(deviceId, 'humd');
54
+ },
55
+ };
@@ -0,0 +1,15 @@
1
+ module.exports = {
2
+ /**
3
+ * Get local IP address from a given MAC
4
+ *
5
+ * @param device
6
+ * @returns {Promise<string>}
7
+ */
8
+ getDeviceIP(device) {
9
+ const mac = device.extra.extra.staMac;
10
+ const arpItem = this.arpTable.find(
11
+ item => item.mac.toLowerCase() === mac.toLowerCase()
12
+ );
13
+ return arpItem.ip;
14
+ },
15
+ };
@@ -0,0 +1,47 @@
1
+ const { _get } = require('../helpers/utilities');
2
+ const errors = require('../data/errors');
3
+
4
+ const deviceStatusPayload = require('../payloads/deviceStatus');
5
+
6
+ module.exports = {
7
+ /**
8
+ * Get current power state for a specific device
9
+ *
10
+ * @param deviceId
11
+ * @param channel
12
+ *
13
+ * @returns {Promise<{state: *, status: string}|{msg: string, error: *}>}
14
+ */
15
+ async getDevicePowerState(deviceId, channel = 1) {
16
+ const status = await this.makeRequest({
17
+ uri: '/user/device/status',
18
+ qs: deviceStatusPayload({
19
+ appid: this.APP_ID,
20
+ deviceId,
21
+ params: 'switch|switches',
22
+ }),
23
+ });
24
+
25
+ const error = _get(status, 'error', false);
26
+
27
+ if (error) {
28
+ const err = error === 400 ? 404 : error;
29
+ return { error: err, msg: errors[err] };
30
+ }
31
+
32
+ let state = _get(status, 'params.switch', false);
33
+ const switches = _get(status, 'params.switches', false);
34
+
35
+ const switchesAmount = switches ? switches.length : 1;
36
+
37
+ if (switchesAmount > 0 && switchesAmount < channel) {
38
+ return { error: 404, msg: errors.ch404 };
39
+ }
40
+
41
+ if (switches) {
42
+ state = switches[channel - 1].switch;
43
+ }
44
+
45
+ return { status: 'ok', state, channel };
46
+ },
47
+ };
@@ -0,0 +1,27 @@
1
+ const { _get } = require('../helpers/utilities');
2
+ const parsePowerUsage = require('../parsers/parsePowerUsage');
3
+
4
+ module.exports = {
5
+ /**
6
+ * Get device power usage for current month
7
+ *
8
+ * @param deviceId
9
+ *
10
+ * @returns {Promise<{error: string}|{daily: *, monthly: *}>}
11
+ */
12
+ async getDevicePowerUsage(deviceId) {
13
+ const response = await this.getDevicePowerUsageRaw(deviceId);
14
+
15
+ const error = _get(response, 'error', false);
16
+ const hundredDaysKwhData = _get(response, 'data.hundredDaysKwhData', false);
17
+
18
+ if (error) {
19
+ return response;
20
+ }
21
+
22
+ return {
23
+ status: 'ok',
24
+ ...parsePowerUsage({ hundredDaysKwhData }),
25
+ };
26
+ },
27
+ };
@@ -0,0 +1,30 @@
1
+ const { _get } = require('../helpers/utilities');
2
+
3
+ const DevicePowerUsageRaw = require('../classes/DevicePowerUsageRaw');
4
+
5
+ module.exports = {
6
+ /**
7
+ * Get device raw power usage
8
+ *
9
+ * @param deviceId
10
+ *
11
+ * @returns {Promise<{error: string}|{response: {hundredDaysKwhData: *}, status: string}>}
12
+ */
13
+ async getDevicePowerUsageRaw(deviceId) {
14
+ const device = await this.getDevice(deviceId);
15
+ const deviceApiKey = _get(device, 'apikey', false);
16
+
17
+ const actionParams = {
18
+ apiUrl: this.getApiWebSocket(),
19
+ at: this.at,
20
+ apiKey: this.apiKey,
21
+ deviceId,
22
+ };
23
+
24
+ if (this.apiKey !== deviceApiKey) {
25
+ actionParams.apiKey = deviceApiKey;
26
+ }
27
+
28
+ return DevicePowerUsageRaw.get(actionParams);
29
+ },
30
+ };
@@ -0,0 +1,37 @@
1
+ const { _get, timestamp } = require('../helpers/utilities');
2
+ const errors = require('../data/errors');
3
+
4
+ module.exports = {
5
+ /**
6
+ * Get all devices information
7
+ *
8
+ * @returns {Promise<{msg: string, error: number}|*>}
9
+ */
10
+ async getDevices() {
11
+ const { APP_ID } = this;
12
+
13
+ const response = await this.makeRequest({
14
+ uri: '/user/device',
15
+ qs: {
16
+ lang: 'en',
17
+ appid: APP_ID,
18
+ ts: timestamp,
19
+ version: 8,
20
+ getTags: 1,
21
+ },
22
+ });
23
+
24
+ const error = _get(response, 'error', false);
25
+ const devicelist = _get(response, 'devicelist', false);
26
+
27
+ if (error) {
28
+ return { error, msg: errors[error] };
29
+ }
30
+
31
+ if (!devicelist) {
32
+ return { error: 404, msg: errors.noDevices };
33
+ }
34
+
35
+ return devicelist;
36
+ },
37
+ };
@@ -0,0 +1,23 @@
1
+ const { _get } = require('../helpers/utilities');
2
+ const errors = require('../data/errors');
3
+
4
+ module.exports = {
5
+ /**
6
+ * Get device firmware version
7
+ *
8
+ * @param deviceId
9
+ *
10
+ * @returns {Promise<{fwVersion: *, status: string}|{msg: string, error: *}>}
11
+ */
12
+ async getFirmwareVersion(deviceId) {
13
+ const device = await this.getDevice(deviceId);
14
+ const error = _get(device, 'error', false);
15
+ const fwVersion = _get(device, 'params.fwVersion', false);
16
+
17
+ if (error || !fwVersion) {
18
+ return { error, msg: errors[error] };
19
+ }
20
+
21
+ return { status: 'ok', fwVersion };
22
+ },
23
+ };
@@ -0,0 +1,23 @@
1
+ const { _get } = require('../helpers/utilities');
2
+ const errors = require('../data/errors');
3
+
4
+ module.exports = {
5
+ async getRegion() {
6
+ if (!this.email || !this.password) {
7
+ return { error: 406, msg: errors.invalidAuth };
8
+ }
9
+
10
+ const credentials = await this.getCredentials();
11
+
12
+ const error = _get(credentials, 'error', false);
13
+
14
+ if (error) {
15
+ return credentials;
16
+ }
17
+
18
+ return {
19
+ email: credentials.user.email,
20
+ region: credentials.region,
21
+ };
22
+ },
23
+ };
@@ -0,0 +1,43 @@
1
+ const { checkDevicesUpdates } = require('./checkDevicesUpdates');
2
+ const { checkDeviceUpdate } = require('./checkDeviceUpdate');
3
+ const deviceControl = require('./deviceControl');
4
+ const { getCredentials } = require('./getCredentials');
5
+ const { getDevice } = require('./getDevice');
6
+ const { getDeviceChannelCount } = require('./getDeviceChannelCount');
7
+ const getDeviceCurrentTH = require('./getDeviceCurrentTH');
8
+ const { getDeviceIP } = require('./getDeviceIP');
9
+ const { getDevicePowerState } = require('./getDevicePowerState');
10
+ const { getDevicePowerUsage } = require('./getDevicePowerUsage');
11
+ const { getDevicePowerUsageRaw } = require('./getDevicePowerUsageRaw');
12
+ const { getDevices } = require('./getDevices');
13
+ const { getFirmwareVersion } = require('./getFirmwareVersion');
14
+ const { getRegion } = require('./getRegion');
15
+ const { makeRequest } = require('./makeRequest');
16
+ const { openWebSocket } = require('./openWebSocket');
17
+ const { saveDevicesCache } = require('./saveDevicesCache');
18
+ const { setDevicePowerState } = require('./setDevicePowerState');
19
+ const { toggleDevice } = require('./toggleDevice');
20
+
21
+ const mixins = {
22
+ checkDevicesUpdates,
23
+ checkDeviceUpdate,
24
+ ...deviceControl,
25
+ getCredentials,
26
+ getDevice,
27
+ getDeviceChannelCount,
28
+ ...getDeviceCurrentTH,
29
+ getDeviceIP,
30
+ getDevicePowerState,
31
+ getDevicePowerUsage,
32
+ getDevicePowerUsageRaw,
33
+ getDevices,
34
+ getFirmwareVersion,
35
+ getRegion,
36
+ makeRequest,
37
+ openWebSocket,
38
+ saveDevicesCache,
39
+ setDevicePowerState,
40
+ toggleDevice,
41
+ };
42
+
43
+ module.exports = mixins;
@@ -0,0 +1,54 @@
1
+ const fetch = require('node-fetch');
2
+ const { _get, _empty, toQueryString } = require('../helpers/utilities');
3
+ const errors = require('../data/errors');
4
+
5
+ module.exports = {
6
+ /**
7
+ * Helper to make api requests
8
+ *
9
+ * @param method
10
+ * @param url
11
+ * @param uri
12
+ * @param body
13
+ * @param qs
14
+ * @returns {Promise<{msg: *, error: *}|*>}
15
+ */
16
+ async makeRequest({ method = 'get', url, uri, body = {}, qs = {} }) {
17
+ const { at } = this;
18
+
19
+ if (!at) {
20
+ await this.getCredentials();
21
+ }
22
+
23
+ let apiUrl = this.getApiUrl();
24
+
25
+ if (url) {
26
+ apiUrl = url;
27
+ }
28
+
29
+ const payload = {
30
+ method,
31
+ headers: {
32
+ Authorization: `Bearer ${this.at}`,
33
+ 'Content-Type': 'application/json',
34
+ },
35
+ };
36
+
37
+ if (!_empty(body)) {
38
+ payload.body = JSON.stringify(body);
39
+ }
40
+
41
+ const queryString = !_empty(qs) ? toQueryString(qs) : '';
42
+ const requestUrl = `${apiUrl}${uri}${queryString}`;
43
+
44
+ const request = await fetch(requestUrl, payload);
45
+
46
+ if (!request.ok) {
47
+ return { error: request.status, msg: errors[request.status] };
48
+ }
49
+
50
+ const response = await request.json();
51
+
52
+ return response
53
+ },
54
+ };
@@ -0,0 +1,44 @@
1
+ const W3CWebSocket = require('websocket').w3cwebsocket;
2
+ const WebSocketAsPromised = require('websocket-as-promised');
3
+
4
+ const wssLoginPayload = require('../payloads/wssLoginPayload');
5
+
6
+ module.exports = {
7
+ /**
8
+ * Open a socket connection to eWeLink
9
+ * and execute callback function with server message as argument
10
+ *
11
+ * @param callback
12
+ * @param heartbeat
13
+ * @returns {Promise<WebSocketAsPromised>}
14
+ */
15
+ async openWebSocket(callback, ...{ heartbeat = 120000 }) {
16
+ const payloadLogin = wssLoginPayload({
17
+ at: this.at,
18
+ apiKey: this.apiKey,
19
+ appid: this.APP_ID,
20
+ });
21
+
22
+ const wsp = new WebSocketAsPromised(this.getApiWebSocket(), {
23
+ createWebSocket: wss => new W3CWebSocket(wss),
24
+ });
25
+
26
+ wsp.onMessage.addListener(message => {
27
+ try {
28
+ const data = JSON.parse(message);
29
+ callback(data);
30
+ } catch (error) {
31
+ callback(message);
32
+ }
33
+ });
34
+
35
+ await wsp.open();
36
+ await wsp.send(payloadLogin);
37
+
38
+ setInterval(async () => {
39
+ await wsp.send('ping');
40
+ }, heartbeat);
41
+
42
+ return wsp;
43
+ },
44
+ };
@@ -0,0 +1,29 @@
1
+ const fs = require('fs');
2
+
3
+ const { _get } = require('../helpers/utilities');
4
+
5
+ module.exports = {
6
+ /**
7
+ * Save devices cache file (useful for using zeroconf)
8
+ * @returns {Promise<string|{msg: string, error: number}|*|Device[]|{msg: string, error: number}>}
9
+ */
10
+ async saveDevicesCache(fileName = './devices-cache.json') {
11
+ const devices = await this.getDevices();
12
+
13
+ const error = _get(devices, 'error', false);
14
+
15
+ if (error || !devices) {
16
+ return devices;
17
+ }
18
+
19
+ const jsonContent = JSON.stringify(devices, null, 2);
20
+
21
+ try {
22
+ fs.writeFileSync(fileName, jsonContent, 'utf8');
23
+ return { status: 'ok', file: fileName };
24
+ } catch (e) {
25
+ console.log('An error occured while writing JSON Object to File.');
26
+ return { error: e.toString() };
27
+ }
28
+ },
29
+ };
@@ -0,0 +1,90 @@
1
+ const { _get, timestamp, nonce } = require('../helpers/utilities');
2
+ const errors = require('../data/errors');
3
+
4
+ const { getDeviceChannelCount } = require('../helpers/ewelink');
5
+
6
+ const ChangeStateZeroconf = require('../classes/ChangeStateZeroconf');
7
+
8
+ module.exports = {
9
+ /**
10
+ * Change power state for a specific device
11
+ *
12
+ * @param deviceId
13
+ * @param state
14
+ * @param channel
15
+ *
16
+ * @returns {Promise<{state: *, status: string}|{msg: string, error: *}>}
17
+ */
18
+ async setDevicePowerState(deviceId, state, channel = 1) {
19
+ const device = await this.getDevice(deviceId);
20
+ const error = _get(device, 'error', false);
21
+ const uiid = _get(device, 'extra.extra.uiid', false);
22
+
23
+ let status = _get(device, 'params.switch', false);
24
+ const switches = _get(device, 'params.switches', false);
25
+
26
+ const switchesAmount = getDeviceChannelCount(uiid);
27
+
28
+ if (switchesAmount > 0 && switchesAmount < channel) {
29
+ return { error: 404, msg: errors.ch404 };
30
+ }
31
+
32
+ if (error || (!status && !switches)) {
33
+ return { error, msg: errors[error] };
34
+ }
35
+
36
+ let stateToSwitch = state;
37
+ const params = {};
38
+
39
+ if (switches) {
40
+ status = switches[channel - 1].switch;
41
+ }
42
+
43
+ if (state === 'toggle') {
44
+ stateToSwitch = status === 'on' ? 'off' : 'on';
45
+ }
46
+
47
+ if (switches) {
48
+ params.switches = switches;
49
+ params.switches[channel - 1].switch = stateToSwitch;
50
+ } else {
51
+ params.switch = stateToSwitch;
52
+ }
53
+
54
+ if (this.devicesCache) {
55
+ const url = this.getZeroconfUrl(device)
56
+ if (url) {
57
+ return ChangeStateZeroconf.set({
58
+ url,
59
+ device,
60
+ params,
61
+ switches,
62
+ state: stateToSwitch,
63
+ });
64
+ }
65
+ }
66
+
67
+ const { APP_ID } = this;
68
+
69
+ const response = await this.makeRequest({
70
+ method: 'post',
71
+ uri: '/user/device/status',
72
+ body: {
73
+ deviceid: deviceId,
74
+ params,
75
+ appid: APP_ID,
76
+ nonce,
77
+ ts: timestamp,
78
+ version: 8,
79
+ },
80
+ });
81
+
82
+ const responseError = _get(response, 'error', false);
83
+
84
+ if (responseError) {
85
+ return { error: responseError, msg: errors[responseError] };
86
+ }
87
+
88
+ return { status: 'ok', state, channel };
89
+ },
90
+ };
@@ -0,0 +1,13 @@
1
+ module.exports = {
2
+ /**
3
+ * Toggle power state for a specific device
4
+ *
5
+ * @param deviceId
6
+ * @param channel
7
+ *
8
+ * @returns {Promise<{state: *, status: string}|{msg: string, error: *}>}
9
+ */
10
+ async toggleDevice(deviceId, channel = 1) {
11
+ return this.setDevicePowerState(deviceId, 'toggle', channel);
12
+ },
13
+ };
@@ -0,0 +1,16 @@
1
+ const { _get } = require('../helpers/utilities');
2
+ const errors = require('../data/errors');
3
+
4
+ const parseFirmwareUpdates = devicesList =>
5
+ devicesList.map(device => {
6
+ const model = _get(device, 'extra.extra.model', false);
7
+ const fwVersion = _get(device, 'params.fwVersion', false);
8
+
9
+ if (!model || !fwVersion) {
10
+ return { error: 500, msg: errors.noFirmware };
11
+ }
12
+
13
+ return { model, version: fwVersion, deviceid: device.deviceid };
14
+ });
15
+
16
+ module.exports = parseFirmwareUpdates;
@@ -0,0 +1,38 @@
1
+ /**
2
+ * Return daily power usage
3
+ *
4
+ * @param hundredDaysKwhData
5
+ *
6
+ * @returns {{daily: *, monthly: *}}
7
+ */
8
+ const parsePowerUsage = ({ hundredDaysKwhData }) => {
9
+ const today = new Date();
10
+ const days = today.getDate();
11
+
12
+ let monthlyUsage = 0;
13
+ const dailyUsage = [];
14
+
15
+ for (let day = 0; day < days; day += 1) {
16
+ const s = hundredDaysKwhData.substr(6 * day, 2);
17
+ const c = hundredDaysKwhData.substr(6 * day + 2, 2);
18
+ const f = hundredDaysKwhData.substr(6 * day + 4, 2);
19
+ const h = parseInt(s, 16);
20
+ const y = parseInt(c, 16);
21
+ const I = parseInt(f, 16);
22
+ const E = parseFloat(`${h}.${y}${I}`);
23
+
24
+ dailyUsage.push({
25
+ day: days - day,
26
+ usage: E,
27
+ });
28
+
29
+ monthlyUsage += E;
30
+ }
31
+
32
+ return {
33
+ monthly: monthlyUsage,
34
+ daily: dailyUsage,
35
+ };
36
+ };
37
+
38
+ module.exports = parsePowerUsage;
@@ -0,0 +1,13 @@
1
+ const { timestamp, nonce } = require('../helpers/utilities');
2
+
3
+ const credentialsPayload = ({ appid, email, phoneNumber, password }) => ({
4
+ appid,
5
+ email,
6
+ phoneNumber,
7
+ password,
8
+ ts: timestamp,
9
+ version: 8,
10
+ nonce,
11
+ });
12
+
13
+ module.exports = credentialsPayload;
@@ -0,0 +1,12 @@
1
+ const { timestamp, nonce } = require('../helpers/utilities');
2
+
3
+ const deviceStatus = ({ appid, deviceId, params }) => ({
4
+ deviceid: deviceId,
5
+ appid,
6
+ nonce,
7
+ ts: timestamp,
8
+ version: 8,
9
+ params,
10
+ });
11
+
12
+ module.exports = deviceStatus;