node-alarm-dot-com 2.1.0-beta.5 → 2.1.0-beta.6

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.
@@ -3,106 +3,124 @@
3
3
  * It's then parsed and the authentication token stored for future use.
4
4
  */
5
5
  export interface IdentityResponse {
6
- data: {
7
- id: number;
8
- type: 'identity';
9
- attributes: {
10
- timezone: string;
11
- initialSetupSteps: [];
12
- helpTours: number[];
13
- logoSource: string;
14
- logoName: string;
15
- dealerPath: string;
16
- favIconUrl: string;
17
- poweredByPath: string;
18
- copyrightInfo: string;
19
- trademarkInfo: string;
20
- hasCompletedOnboarding: boolean;
21
- isEnterprise: boolean;
22
- isAccessControl: boolean;
23
- isCommercial: boolean;
24
- isPointCentral: boolean;
25
- isPcRpm: boolean;
26
- isPointCentralSTR: boolean;
27
- isMobileApp: boolean;
28
- useWebsockets: boolean;
29
- websocketServiceEndpoint: string;
30
- enabledWebsocketMessageHandlers: null;
31
- canBrowserEnableFlashDirectly: boolean;
32
- supportsEnableFlashPrompt: boolean;
33
- supportedNativeBridgeFeatures: null;
34
- hasTroubleConditionsService: boolean;
35
- errorReportingConfiguration: {
36
- providerName: string;
37
- apiKey: null;
38
- scriptUrl: null;
39
- isEnabled: boolean;
40
- machineName: string;
41
- logErrorsToConsole: boolean;
42
- showNotificationOnError: boolean;
43
- redirectToErrorRouteOnUnhandledError: boolean;
44
- environment: string;
45
- servicePlan: string;
46
- };
47
- enableHomeScreenConfiguration: boolean;
48
- accountType: number;
49
- externalTerms: string;
50
- externalPrivacyPolicy: string;
51
- applicationSessionProperties: {
52
- shouldTimeout: boolean;
53
- keepAliveUrl: string;
54
- enableKeepAlive: boolean;
55
- logoutTimeoutMs: number;
56
- inactivityWarningTimeoutMs: number;
57
- };
58
- postLoginRedirect: null;
59
- canDonateClips: boolean;
60
- hasInternalBetaAccess: boolean;
61
- };
62
- relationships: {
63
- dealer: {
64
- data: Relationship;
65
- };
66
- primaryColor: {
67
- data: Relationship;
68
- };
69
- secondaryColor: {
70
- data: Relationship;
71
- };
72
- navColor: {
73
- data: Relationship;
74
- };
75
- profile: {
76
- data: Relationship;
77
- };
78
- accountInformation: {
79
- data: Relationship;
80
- };
81
- availableRouteItems: {
82
- data: Relationship[];
83
- meta: {
84
- count: string;
85
- };
86
- };
87
- wizard: {
88
- data: Relationship[] | null;
89
- };
90
- clipDonationAgreement: {
91
- data: Relationship;
92
- };
93
- selectedSystem: {
94
- data: Relationship;
95
- };
96
- selectedSystemGroup: {
97
- data: Relationship | null;
98
- };
99
- };
100
- };
6
+ data: IdentityData[];
101
7
  included: any[];
102
8
  meta: {
103
9
  transformer_version: string;
104
10
  };
105
11
  }
12
+ export interface IdentityData {
13
+ id: number;
14
+ type: 'identity';
15
+ attributes: {
16
+ timezone: string;
17
+ preferredTimezone: string;
18
+ initialSetupSteps: [];
19
+ helpTours: number[];
20
+ logoSource: string;
21
+ logoName: string;
22
+ dealerPath: string;
23
+ mobileAppBrand: string;
24
+ favIconUrl: string;
25
+ poweredByPath: string;
26
+ copyrightInfo: string;
27
+ trademarkInfo: string;
28
+ hasCompletedOnboarding: boolean;
29
+ isEnterprise: boolean;
30
+ isAccessControl: boolean;
31
+ isCommercial: boolean;
32
+ isPointCentral: boolean;
33
+ isPcRpm: boolean;
34
+ isPointCentralSTR: boolean;
35
+ isPointCentralAccessControl: boolean;
36
+ isPointCentralAccessControlSTR: boolean;
37
+ isUsingEnterpriseLocationsCache: boolean;
38
+ isMobileApp: boolean;
39
+ isMobileTechApp: boolean;
40
+ isVisualIdentification: boolean;
41
+ isEscalatedEvents: boolean;
42
+ isWindowsDevice: boolean;
43
+ applicationBuildNumber: number;
44
+ canViewHighlights: boolean;
45
+ canViewVideoClips: boolean;
46
+ hasAccessToAudioForNonDoorbellCameras: boolean;
47
+ hasSmartArmingSensorBased: boolean;
48
+ isSmartDisarmEligible: boolean;
49
+ canEditNoiseSensors: boolean;
50
+ isManagedAccessAccount: boolean;
51
+ supportedNativeBridgeFeatures: null;
52
+ supportedNativeViewTransitions: null;
53
+ supportedDisplayModeFeatures: null;
54
+ hasTroubleConditionsService: boolean;
55
+ errorReportingConfiguration: {
56
+ providerName: string;
57
+ apiKey: null;
58
+ scriptUrl: null;
59
+ isEnabled: boolean;
60
+ machineName: string;
61
+ logErrorsToConsole: boolean;
62
+ showNotificationOnError: boolean;
63
+ redirectToErrorRouteOnUnhandledError: boolean;
64
+ environment: string;
65
+ servicePlan: string;
66
+ };
67
+ enableHomeScreenConfiguration: boolean;
68
+ accountType: number;
69
+ externalTerms: string;
70
+ externalPrivacyPolicy: string;
71
+ shouldHidePrivacyPolicyLink: boolean;
72
+ shouldHideTermsAndConditionsLink: boolean;
73
+ applicationSessionProperties: {
74
+ shouldTimeout: boolean;
75
+ keepAliveUrl: string;
76
+ enableKeepAlive: boolean;
77
+ logoutTimeoutMs: number;
78
+ inactivityWarningTimeoutMs: number;
79
+ };
80
+ postLoginRedirect: null;
81
+ localizeTempUnitsToCelsius: boolean;
82
+ canDonateClips: boolean;
83
+ hasInternalBetaAccess: boolean;
84
+ };
85
+ relationships: {
86
+ dealer: {
87
+ data: Relationship;
88
+ };
89
+ primaryColor: {
90
+ data: Relationship;
91
+ };
92
+ secondaryColor: {
93
+ data: Relationship;
94
+ };
95
+ navColor: {
96
+ data: Relationship;
97
+ };
98
+ profile: {
99
+ data: Relationship;
100
+ };
101
+ accountInformation: {
102
+ data: Relationship;
103
+ };
104
+ availableRouteItems: {
105
+ data: Relationship[];
106
+ meta: {
107
+ count: string;
108
+ };
109
+ };
110
+ wizard: {
111
+ data: Relationship[] | null;
112
+ };
113
+ clipDonationAgreement: {
114
+ data: Relationship;
115
+ };
116
+ selectedSystem: {
117
+ data: Relationship;
118
+ };
119
+ selectedSystemGroup: {
120
+ data: Relationship | null;
121
+ };
122
+ };
123
+ }
106
124
  export interface Relationship {
107
125
  id: string;
108
126
  type: 'devices/partition' | 'devices/lock' | 'video/camera' | 'devices/garage-door' | 'automation/scene' | 'devices/sensor' | 'devices/light' | 'devices/thermostat' | 'geolocation/geo-device' | 'geolocation/fence' | 'systems/configuration' | 'navigation/route-item' | 'dealers/dealer' | 'ui/color' | 'profile/profile' | 'accountInformation/account-information';
package/dist/index.d.ts CHANGED
@@ -3,9 +3,10 @@
3
3
  */
4
4
  import { AuthOpts } from './_models/AuthOpts';
5
5
  import { ApiDeviceState } from './_models/DeviceStates';
6
+ import { IdentityResponse } from './_models/IdentityResponse';
6
7
  import { PartitionActionOptions } from './_models/PartitionActionOptions';
7
8
  import { FlattenedSystemState } from './_models/SystemState';
8
- import { THERMOSTAT_STATES } from "./_models/States";
9
+ import { THERMOSTAT_STATES } from './_models/States';
9
10
  export * from './_models/AuthOpts';
10
11
  export * from './_models/DeviceStates';
11
12
  export * from './_models/IdentityResponse';
@@ -23,6 +24,11 @@ export * from './_models/SensorType';
23
24
  * @returns {Promise}
24
25
  */
25
26
  export declare function login(username: string, password: string, existingMfaToken?: string): Promise<AuthOpts>;
27
+ /**
28
+ * This function returns the alarm.com system identity for the currently logged in system.
29
+ * The information returned is useful for finding current systems and global config.
30
+ */
31
+ export declare function getIdentitiesState(loginCookies: string, ajaxKey: string): Promise<IdentityResponse>;
26
32
  /**
27
33
  * Retrieve information about the current state of a security system including
28
34
  * attributes, partitions, accessory components and relationships.
package/dist/index.js CHANGED
@@ -20,7 +20,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
20
20
  return (mod && mod.__esModule) ? mod : { "default": mod };
21
21
  };
22
22
  Object.defineProperty(exports, "__esModule", { value: true });
23
- exports.authenticatedPost = exports.authenticatedGet = exports.setThermostatTargetCoolTemperature = exports.setThermostatTargetHeatTemperature = exports.setThermostatState = exports.openGarage = exports.closeGarage = exports.setLockUnsecure = exports.setLockSecure = exports.setLightOff = exports.setLightOn = exports.disarm = exports.armAway = exports.armStay = exports.getComponents = exports.getCurrentState = exports.login = void 0;
23
+ exports.authenticatedPost = exports.authenticatedGet = exports.setThermostatTargetCoolTemperature = exports.setThermostatTargetHeatTemperature = exports.setThermostatState = exports.openGarage = exports.closeGarage = exports.setLockUnsecure = exports.setLockSecure = exports.setLightOff = exports.setLightOn = exports.disarm = exports.armAway = exports.armStay = exports.getComponents = exports.getCurrentState = exports.getIdentitiesState = exports.login = void 0;
24
24
  const node_fetch_1 = __importDefault(require("node-fetch"));
25
25
  __exportStar(require("./_models/AuthOpts"), exports);
26
26
  __exportStar(require("./_models/DeviceStates"), exports);
@@ -55,7 +55,9 @@ const UA = `node-alarm-dot-com/${require('../package.json').version}`;
55
55
  async function login(username, password, existingMfaToken) {
56
56
  let loginCookies;
57
57
  let ajaxKey;
58
- let loginFormBody, identities, systems;
58
+ let loginFormBody;
59
+ let identities;
60
+ let systems;
59
61
  // load initial alarm.com page to gather required hidden form fields
60
62
  await get(ADCLOGIN_URL)
61
63
  .then((res) => {
@@ -107,7 +109,29 @@ async function login(username, password, existingMfaToken) {
107
109
  .catch((err) => {
108
110
  throw new Error(`POST ${ADCFORMLOGIN_URL} failed: ${err.message || err}`);
109
111
  });
110
- await get(IDENTITIES_URL, {
112
+ await getIdentitiesState(loginCookies, ajaxKey)
113
+ .then((res) => {
114
+ systems = (res.data || []).map((d) => {
115
+ return d.relationships.selectedSystem.data.id;
116
+ });
117
+ })
118
+ .catch((err) => {
119
+ throw new Error(`GET ${IDENTITIES_URL} failed: ${err.message || err}`);
120
+ });
121
+ return {
122
+ cookie: loginCookies,
123
+ ajaxKey: ajaxKey,
124
+ systems: systems,
125
+ identities: identities
126
+ };
127
+ }
128
+ exports.login = login;
129
+ /**
130
+ * This function returns the alarm.com system identity for the currently logged in system.
131
+ * The information returned is useful for finding current systems and global config.
132
+ */
133
+ async function getIdentitiesState(loginCookies, ajaxKey) {
134
+ return await get(IDENTITIES_URL, {
111
135
  /* eslint-disable @typescript-eslint/naming-convention */
112
136
  headers: {
113
137
  Accept: 'application/vnd.api+json',
@@ -120,20 +144,13 @@ async function login(username, password, existingMfaToken) {
120
144
  })
121
145
  .then((res) => {
122
146
  // gather identities and systems
123
- identities = res.body;
124
- systems = (identities.data || []).map((d) => getValue(d, 'relationships.selectedSystem.data.id'));
147
+ return res.body;
125
148
  })
126
149
  .catch((err) => {
127
150
  throw new Error(`GET ${IDENTITIES_URL} failed: ${err.message || err}`);
128
151
  });
129
- return {
130
- cookie: loginCookies,
131
- ajaxKey: ajaxKey,
132
- systems: systems,
133
- identities: identities
134
- };
135
152
  }
136
- exports.login = login;
153
+ exports.getIdentitiesState = getIdentitiesState;
137
154
  /**
138
155
  * Retrieve information about the current state of a security system including
139
156
  * attributes, partitions, accessory components and relationships.
@@ -171,16 +188,14 @@ async function getCurrentState(systemID, authOpts) {
171
188
  if (typeof garageIDs[0] !== 'undefined') {
172
189
  components.set('garages', await getComponents(GARAGE_URL, garageIDs, authOpts));
173
190
  }
174
- const thermostatIDs = rels.thermostats.data.map(thermostat => thermostat.id);
191
+ const thermostatIDs = rels.thermostats.data.map((thermostat) => thermostat.id);
175
192
  if (typeof thermostatIDs[0] !== 'undefined') {
176
193
  components.set('thermostats', await getComponents(THERMOSTAT_URL, thermostatIDs, authOpts));
177
194
  }
178
195
  return {
179
196
  id: res.data.id,
180
197
  attributes: res.data.attributes,
181
- partitions: components.has('partitions')
182
- ? components.get('partitions').data
183
- : [],
198
+ partitions: components.has('partitions') ? components.get('partitions').data : [],
184
199
  sensors: components.has('sensors') ? components.get('sensors').data : [],
185
200
  lights: components.has('lights') ? components.get('lights').data : [],
186
201
  locks: components.has('locks') ? components.get('locks').data : [],
@@ -596,14 +611,9 @@ async function get(url, opts) {
596
611
  status = res.status;
597
612
  resHeaders = res.headers;
598
613
  const type = res.headers.get('content-type') || '';
599
- const body = await (type.indexOf('json') !== -1
600
- ? res.status === 204
601
- ? {}
602
- : res.json()
603
- : res.text());
614
+ const body = await (type.indexOf('json') !== -1 ? (res.status === 204 ? {} : res.json()) : res.text());
604
615
  if (status === 409) {
605
- throw new Error('Two factor is enabled on this account but not setup in the plugin.' +
606
- ' See the wiki for details');
616
+ throw new Error('Two factor is enabled on this account but not setup in the plugin.' + ' See the wiki for details');
607
617
  }
608
618
  if (status >= 400) {
609
619
  throw new Error(body.Message || body || status);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "node-alarm-dot-com",
3
- "version": "2.1.0-beta.5",
3
+ "version": "2.1.0-beta.6",
4
4
  "betaVersion": "2.1.0",
5
5
  "description": "An interface module written in node.js to arm and disarm Alarm.com security systems.",
6
6
  "author": {