smart-home-engine 1.12.13 → 1.14.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.
@@ -1,4 +1,4 @@
1
- import{m as O}from"./monaco-langs-Dt8a9eeo.js";import{t as I}from"./index-0kMmvnH2.js";/*!-----------------------------------------------------------------------------
1
+ import{m as O}from"./monaco-langs-Dt8a9eeo.js";import{t as I}from"./index-BbvxIUTP.js";/*!-----------------------------------------------------------------------------
2
2
  * Copyright (c) Microsoft Corporation. All rights reserved.
3
3
  * Version: 0.52.2(404545bded1df6ffa41ea0af4e8ddb219018c6c1)
4
4
  * Released under the MIT license
@@ -172,7 +172,7 @@
172
172
  }
173
173
  })();
174
174
  </script>
175
- <script type="module" crossorigin src="/assets/index-0kMmvnH2.js"></script>
175
+ <script type="module" crossorigin src="/assets/index-BbvxIUTP.js"></script>
176
176
  <link rel="modulepreload" crossorigin href="/assets/monaco-langs-Dt8a9eeo.js">
177
177
  <link rel="stylesheet" crossorigin href="/assets/monaco-langs-DyX1CsEw.css">
178
178
  <link rel="stylesheet" crossorigin href="/assets/index-BXB4YlVH.css">
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "smart-home-engine",
3
- "version": "1.12.13",
3
+ "version": "1.14.0",
4
4
  "description": "Node.js based script runner for use in MQTT based Smart Home environments",
5
5
  "main": "src/index.js",
6
6
  "scripts": {
package/src/index.js CHANGED
@@ -95,6 +95,15 @@ function makeLabel(filePath) {
95
95
  }
96
96
 
97
97
  log.setLevel(['debug', 'info', 'warn', 'error'].indexOf(config.verbosity) === -1 ? 'info' : config.verbosity);
98
+
99
+ // Safety net: unhandled Promise rejections from async script callbacks are not caught
100
+ // by the per-script domain (Node.js domains don't intercept Promise rejections).
101
+ // Log the error instead of letting Node.js crash the process.
102
+ process.on('unhandledRejection', (reason) => {
103
+ const msg = reason instanceof Error ? reason.stack || reason.message : String(reason);
104
+ log.error('unhandled promise rejection — add try/catch to async script callbacks:\n' + msg);
105
+ });
106
+
98
107
  log.info('she ' + pkg.version + ' starting');
99
108
  log.debug('loaded config: ', config);
100
109
 
@@ -154,7 +154,12 @@ module.exports = function (she, ctx = {}) {
154
154
  * @param {RequestInit} [options]
155
155
  * @returns {Promise<string|object>}
156
156
  */
157
- fetch: function Sandbox_http_fetch(url, options) {
157
+ fetch: function Sandbox_http_fetch(url, options, callback) {
158
+ // Support she.http.fetch(url, callback) shorthand (no options)
159
+ if (typeof options === 'function') {
160
+ callback = options;
161
+ options = undefined;
162
+ }
158
163
  const TIMEOUT_MS = 30_000;
159
164
  let signal = options?.signal;
160
165
  let timer;
@@ -163,13 +168,24 @@ module.exports = function (she, ctx = {}) {
163
168
  signal = ac.signal;
164
169
  timer = setTimeout(() => ac.abort(new Error(`she.http.fetch timed out after ${TIMEOUT_MS / 1000}s`)), TIMEOUT_MS);
165
170
  }
166
- return fetch(url, { ...options, signal })
167
- .then((r) => {
168
- if (!r.ok) throw new Error(`HTTP ${r.status} ${r.statusText}`);
171
+ const promise = fetch(url, { ...options, signal })
172
+ .then(async (r) => {
169
173
  const ct = r.headers.get('content-type') || '';
170
- return ct.includes('json') ? r.json() : r.text();
174
+ const body = ct.includes('json') ? await r.json() : await r.text();
175
+ const headers = {};
176
+ r.headers.forEach((v, k) => {
177
+ headers[k] = v;
178
+ });
179
+ const res = { body, code: r.status, headers };
180
+ if (!r.ok) throw Object.assign(new Error(`HTTP ${r.status} ${r.statusText}`), res);
181
+ return res;
171
182
  })
172
183
  .finally(() => clearTimeout(timer));
184
+ if (typeof callback === 'function') {
185
+ promise.then((res) => callback(null, res)).catch((err) => callback(err, null));
186
+ return undefined;
187
+ }
188
+ return promise;
173
189
  },
174
190
  /**
175
191
  * Register a POST webhook endpoint at /api/<scriptName><path>.
@@ -74,8 +74,8 @@ she.mqtt.min(srcs[], topicOrCb) Publish minimum of source values (0 if none
74
74
  she.now() Current timestamp in ms
75
75
  she.debug / .info / .warn / .error Structured logging (prefixed with script name)
76
76
  she.global Shared mutable object across all scripts
77
- she.http.fetch(url, [opts]) HTTP/HTTPS fetch → Promise<string|object>
78
- Auto-parses JSON by Content-Type. Throws on non-2xx.
77
+ she.http.fetch(url, [opts], [cb]) HTTP/HTTPS fetch → { body, code, headers }; or cb(err, res)
78
+ Auto-parses JSON by Content-Type. Rejects/errs on non-2xx.
79
79
  she.http.sub(path, cb) Register POST /api/<script><path> webhook endpoint
80
80
  cb(body, { params, query, headers })
81
81
  she.config.latitude Read-only: geographic latitude from daemon config