smart-home-engine 1.13.0 → 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-
|
|
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
|
package/dist/web/index.html
CHANGED
|
@@ -172,7 +172,7 @@
|
|
|
172
172
|
}
|
|
173
173
|
})();
|
|
174
174
|
</script>
|
|
175
|
-
<script type="module" crossorigin src="/assets/index-
|
|
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
package/src/sandbox/stdlib.js
CHANGED
|
@@ -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
|
-
|
|
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
|
-
|
|
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])
|
|
78
|
-
Auto-parses JSON by Content-Type.
|
|
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
|