homey-api 1.7.0 → 1.7.2

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.
@@ -0,0 +1,59 @@
1
+ // Class
2
+
3
+ /**
4
+ * @class <%= Api.name %>
5
+ *
6
+ * @description
7
+ * <% if(Api.JSDOC_DESCRIPTION) { %>
8
+ <%- Api.JSDOC_DESCRIPTION.split('\n').join('\n *'); %>
9
+ * <% } %>
10
+ * This API is available at `https://<%= Api.SPECIFICATION.host %><%= Api.SPECIFICATION.basePath %>`
11
+ *
12
+ * <% if(Api.JSDOC_EXAMPLE) { %>
13
+ * @example <%- Api.JSDOC_EXAMPLE %>
14
+ * <% } %>
15
+ *
16
+ * <% if(Api.JSDOC_PRIVATE === true) { %>
17
+ * @private
18
+ * <% } %>
19
+ *
20
+ * @param {object} [opts]
21
+ * @param {string} [opts.baseUrl=`https://<%= Api.SPECIFICATION.host %><%= Api.SPECIFICATION.basePath %>`] - The Base URL of the API. Set `<%= envKey %>_BASEURL=http://...` as environment variable on Node.js, or in `window.localStorage` on browsers to override.
22
+ * @param {boolean} [opts.debug=false] - Send debug messages to `console.log` if set to `true`. Set `<%= envKey %>_DEBUG=1` as environment variable on Node.js, or in `window.localStorage` on browsers to override.
23
+ * @param {secret} [opts.secret] - A shared secret for APIs with a `secret` parameter in an endpoint. Set `<%= envKey %>_SECRET=...` as environment variable on Node.js, or in `window.localStorage` on browsers to override.
24
+ * <% if( Api.JSDOC_PARAMS ) { %>
25
+ <%- Api.JSDOC_PARAMS.split('\n').join('\n *'); %>
26
+ * <% } %>
27
+ */
28
+
29
+ // Methods
30
+ <% Object.entries(Api.SPECIFICATION.operations).forEach(([ operationId, operation ]) => { %>
31
+ /**
32
+ * <h4>HTTP</h4>
33
+ *
34
+ * `<%= String(operation.method).toUpperCase() %> <%= operation.path %>`
35
+ *
36
+ * @async
37
+ * @function <%= Api.name %>#<%= operationId %>
38
+ * <% if(operation.private) { %>
39
+ * @private
40
+ * <% } %>
41
+ *
42
+ * <% if (Object.keys(operation.parameters || {}).length) { %>
43
+ * @param {object} opts
44
+ * <% Object.entries(operation.parameters).forEach(([parameterId, parameter]) => { %>
45
+ * <% if (parameter.required) { %>
46
+ * @param {<%= String(parameter.type).replace(/\,/g, '|') %>} opts.<%= parameterId %> - In `<%= parameter.in %>` <% if( parameter.unpack ) { %><span>(unpacked)</span><% } %>
47
+ * <% } else { %>
48
+ * @param {<%= String(parameter.type).replace(/\,/g, '|') %>} [opts.<%= parameterId %>] - In `<%= parameter.in %>` <% if( parameter.unpack ) { %><span>(unpacked)</span><% } %>
49
+ * <% } %>
50
+ * <% if (Object.keys(parameter.properties || {}).length) { %>
51
+ * <% Object.entries(parameter.properties).forEach(([propertyId, property]) => { %>
52
+ * @param {<%= String(property.type).replace(/\,/g, '|') %>} opts.<%= parameterId %>.<%= propertyId %>
53
+ * <% }) %>
54
+ * <% } %>
55
+ * <% }) %>
56
+ * <% } %>
57
+ *
58
+ */
59
+ <% }) %>
@@ -0,0 +1,35 @@
1
+ // Class
2
+
3
+ /**
4
+ * <%= itemName %> as returned by {@link <%= HomeyAPI %>.<%= managerName %>}.
5
+ * @class <%= itemName %>
6
+ * @hideconstructor
7
+ * @memberof <%= HomeyAPI %>.<%= managerName %>
8
+ *
9
+ * <% if(manager.private) { %>
10
+ * @private
11
+ * <% } %>
12
+ */
13
+
14
+ // Properties
15
+
16
+ <% if (item.schema) { %>
17
+ <% for (const [propertyId, property] of Object.entries(item.schema.properties || {}) ) { %>
18
+ /**
19
+ * <% if (property.type) { %>
20
+ * @var {<%= String(property.type || '*').replace(/\,/g, '|') %>} <%= HomeyAPI %>.<%= managerName %>.<%= itemName %>#<%= propertyId %>
21
+ * <% } %>
22
+ */
23
+ <% } %>
24
+ <% } %>
25
+
26
+ /**
27
+ * @memberof <%= HomeyAPI %>.<%= managerName%>.<%= itemName %>
28
+ * @event update
29
+ * @param {object} <%= item.id %>
30
+ */
31
+
32
+ /**
33
+ * @memberof <%= HomeyAPI %>.<%= managerName%>.<%= itemName %>
34
+ * @event delete
35
+ */
@@ -0,0 +1,76 @@
1
+ // Class
2
+
3
+ /**
4
+ * @description Access this instance at `{@link <%= HomeyAPI %>}.<%= manager.idCamelCase; %>`.
5
+ * @class <%= managerName %>
6
+ * @hideconstructor
7
+ * @extends <%= HomeyAPI %>.Manager
8
+ * @memberof <%= HomeyAPI %>
9
+ *
10
+ * <% if(manager.private) { %>
11
+ * @private
12
+ * <% } %>
13
+ */
14
+
15
+ // Methods
16
+ <% Object.entries(manager.operations || {}).forEach(([ operationId, operation ]) => { %>
17
+ /**
18
+ * <h4>Scopes</h4>
19
+ *
20
+ * `<%= operation.scopes.length ? operation.scopes.join(', ') : '-' %>`
21
+ *
22
+ * <h4>HTTP</h4>
23
+ *
24
+ * `<%= operation.method %> /api/manager/<%= manager.id %><%= operation.path %>`
25
+ *
26
+ * @async
27
+ * @function <%= HomeyAPI %>.<%= managerName %>#<%= operationId %>
28
+ * <% if(operation.private) { %>
29
+ * @private
30
+ * <% } %>
31
+ *
32
+ * <% if (Object.keys(operation.parameters || {}).length) { %>
33
+ * @param {object} opts
34
+ * <% Object.entries(operation.parameters).forEach(([ parameterId, parameter ]) => { %>
35
+ * <% if (parameter.required) { %>
36
+ * @param {<%= String(parameter.type || '*').replace(/\,/g, '|') %>} opts.<%= parameterId %>
37
+ * <% } else { %>
38
+ * @param {<%= String(parameter.type || '*').replace(/\,/g, '|') %>} [opts.<%= parameterId %>]
39
+ * <% } %>
40
+ * <% }) %>
41
+ * <% } %>
42
+ *
43
+ * <% if(operation.crud) { %>
44
+ * <% if(operation.crud.type === 'getOne' || operation.crud.type === 'createOne' || operation.crud.type === 'updateOne') { %>
45
+ * @returns {Promise<<%= HomeyAPI %>.<%= managerName %>.<%= operation.crud.item %>>}
46
+ * <% } else if(operation.crud.type === 'getAll') { %>
47
+ * @returns {Promise<<%= HomeyAPI %>.<%= managerName %>.<%= operation.crud.item %>>}
48
+ * <% } %>
49
+ * <% } else { %>
50
+ * @returns {Promise<any>}
51
+ * <% } %>
52
+ */
53
+ <% }) %>
54
+
55
+
56
+
57
+ // CRUD Events
58
+ <% Object.entries(manager.items || {}).forEach(([ itemName, item ]) => { %>
59
+ /**
60
+ * @memberof <%= HomeyAPI %>.<%= managerName%>
61
+ * @event "<%= item.id %>.create"
62
+ * @param {<%= HomeyAPI %>.<%= managerName %>.<%= itemName %>} <%= item.id %>
63
+ */
64
+
65
+ /**
66
+ * @memberof <%= HomeyAPI %>.<%= managerName%>
67
+ * @event "<%= item.id %>.update"
68
+ * @param {<%= HomeyAPI %>.<%= managerName %>.<%= itemName %>} <%= item.id %>
69
+ */
70
+
71
+ /**
72
+ * @memberof <%= HomeyAPI %>.<%= managerName%>
73
+ * @event "<%= item.id %>.delete"
74
+ * @param {<%= HomeyAPI %>.<%= managerName %>.<%= itemName %>} <%= item.id %>
75
+ */
76
+ <% }) %>
@@ -0,0 +1,62 @@
1
+ <%
2
+ function jsdocToTypescript(type) {
3
+ return type.names
4
+ .flatMap(type => type.split('|'))
5
+ .map(type => {
6
+ if (type === 'secret') return 'string';
7
+ if (type === 'array') return 'Array<any>';
8
+ if (type === 'date') return 'string';
9
+ // replace Promise.<> with Promise<>
10
+ return type.replace(/\.\</g, '<');
11
+ })
12
+ .join(' | ');
13
+ }
14
+ %>
15
+
16
+ <% function renderParam(params) { %>
17
+ <% Object.entries(params).forEach(([key, value]) => { %>
18
+ <% if (typeof value === 'object') { %>
19
+ <%= key %>: {<%= renderParam(value) %>},
20
+ <% } else { %>
21
+ <%= key %>: <%- jsdocToTypescript({ names: [value] }) %>,
22
+ <% } %>
23
+ <% }) %>
24
+ <% } %>
25
+
26
+ <% function renderClass(namespaceClass) { %>
27
+ export class <%= namespaceClass.name %> <%= Array.isArray(namespaceClass.augments) ? 'extends ' + namespaceClass.augments[0] : '' %> {
28
+ <% if (namespaceClass.constructor && namespaceClass.hideconstructor !== true) { %>
29
+ constructor(
30
+ <% if (namespaceClass.constructor.params) { %>
31
+ <%= renderParam(namespaceClass.constructor.params) %>
32
+ <% } %>
33
+ )
34
+ <% } %>
35
+
36
+ <% namespaceClass.members.forEach(classMember => { %>
37
+ <%= classMember.name %>: <%- jsdocToTypescript(classMember.type) %>;
38
+ <% }) %>
39
+
40
+ <% namespaceClass.functions.forEach(classFunction => { %>
41
+ <%= classFunction.name %>(
42
+ <% if (classFunction.params) { %>
43
+ <%= renderParam(classFunction.params) %>
44
+ <% } %>
45
+ ):
46
+ <%- classFunction.returns
47
+ ? jsdocToTypescript(classFunction.returns[0].type)
48
+ : classFunction.async ? 'Promise<any>' : 'any'
49
+ %>;
50
+ <% }) %>
51
+ }
52
+ <% } %>
53
+
54
+ <% global.forEach(globalClass => renderClass(globalClass)) %>
55
+
56
+ <% Object.entries(namespaces).forEach(([namespaceId, namespaceClasses]) => { %>
57
+ <% if (namespaceClasses.length) { %>
58
+ export namespace <%= namespaceId %> {
59
+ <% namespaceClasses.forEach(namespaceClass => renderClass(namespaceClass)) %>
60
+ }
61
+ <% } %>
62
+ <% }); %>
@@ -201,6 +201,29 @@
201
201
  ):
202
202
  Promise<void>;
203
203
 
204
+ authenticateWithAuthorizationCode(
205
+
206
+
207
+
208
+
209
+ opts: {
210
+
211
+
212
+ code: String,
213
+
214
+
215
+
216
+ removeCodeFromHistory: Boolean,
217
+
218
+
219
+ },
220
+
221
+
222
+
223
+
224
+ ):
225
+ Promise<AthomCloudAPI.Token>;
226
+
204
227
  }
205
228
 
206
229
  export class HomeyAPI {
@@ -2985,6 +2985,73 @@
2985
2985
  ):
2986
2986
  Promise<void>;
2987
2987
 
2988
+ authenticateWithAuthorizationCode(
2989
+
2990
+
2991
+
2992
+
2993
+ opts: {
2994
+
2995
+
2996
+ code: String,
2997
+
2998
+
2999
+
3000
+ removeCodeFromHistory: Boolean,
3001
+
3002
+
3003
+ },
3004
+
3005
+
3006
+
3007
+
3008
+ ):
3009
+ Promise<AthomCloudAPI.Token>;
3010
+
3011
+ updateUserMe(
3012
+
3013
+
3014
+
3015
+
3016
+ opts: {
3017
+
3018
+
3019
+ firstname: String,
3020
+
3021
+
3022
+
3023
+ lastname: String,
3024
+
3025
+
3026
+
3027
+ email: String,
3028
+
3029
+
3030
+ },
3031
+
3032
+
3033
+
3034
+
3035
+ ):
3036
+ Promise<AthomCloudAPI.User>;
3037
+
3038
+ updateUserMeAvatar(
3039
+
3040
+
3041
+
3042
+
3043
+ imageBuffer: Buffer,
3044
+
3045
+
3046
+
3047
+ imageType: "jpg" | "jpeg" | "png" | "gif",
3048
+
3049
+
3050
+
3051
+
3052
+ ):
3053
+ Promise<Object>;
3054
+
2988
3055
  }
2989
3056
 
2990
3057
  export class AthomConnectAPI {
@@ -206,6 +206,9 @@ for(const {@link HomeyAPIV2.ManagerDevices.Device device} of Object.values(devic
206
206
  * @returns {Promise<void>}
207
207
  */
208
208
  async logout() {
209
+ // Delete Cached User
210
+ this.__user = null;
211
+
209
212
  // Delete Token from Store
210
213
  await this.__resetStore();
211
214
  this.__token = null;
@@ -549,7 +552,7 @@ for(const {@link HomeyAPIV2.ManagerDevices.Device device} of Object.values(devic
549
552
  * Update the currently authenticated user's avatar.
550
553
  *
551
554
  * @private
552
- * @param {Buffer} imageBuffer Buffer of the new avatat
555
+ * @param {Buffer} imageBuffer Buffer of the new avatar
553
556
  * @param {"jpg"|"jpeg"|"png"|"gif"} imageType Type of the new avatar
554
557
  * @returns {Promise<Object>}
555
558
  */
package/package.json CHANGED
@@ -1,8 +1,14 @@
1
1
  {
2
2
  "name": "homey-api",
3
- "version": "1.7.0",
3
+ "version": "1.7.2",
4
4
  "description": "Homey API",
5
5
  "main": "index.js",
6
+ "files": [
7
+ "/lib",
8
+ "/assets",
9
+ "/index.js",
10
+ "/index.browser.js"
11
+ ],
6
12
  "types": "assets/types/homey-api.d.ts",
7
13
  "scripts": {
8
14
  "test": "echo \"Error: no test specified\" && exit 1",
@@ -44,6 +50,7 @@
44
50
  "socket.io-client": "^1.7.4"
45
51
  },
46
52
  "devDependencies": {
53
+ "@athombv/jsdoc-template": "^1.6.1",
47
54
  "@babel/core": "^7.16.0",
48
55
  "@babel/plugin-proposal-class-properties": "^7.16.0",
49
56
  "@babel/preset-env": "^7.16.0",
@@ -53,7 +60,6 @@
53
60
  "eslint": "^7.32.0",
54
61
  "eslint-config-athom": "^2.1.1",
55
62
  "fs-extra": "^10.0.0",
56
- "homey-jsdoc-template": "github:athombv/homey-jsdoc-template#1.5.1",
57
63
  "http-server": "^0.12.3",
58
64
  "jsdoc": "^3.6.7",
59
65
  "jsdoc-to-markdown": "^7.1.0",
@@ -72,4 +78,4 @@
72
78
  "not IE 11",
73
79
  "not IE_Mob 11"
74
80
  ]
75
- }
81
+ }