@scrypted/server 0.1.16 → 0.2.5
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.
Potentially problematic release.
This version of @scrypted/server might be problematic. Click here for more details.
- package/dist/event-registry.js +3 -4
- package/dist/event-registry.js.map +1 -1
- package/dist/plugin/media.js +51 -63
- package/dist/plugin/media.js.map +1 -1
- package/dist/plugin/plugin-api.js +1 -1
- package/dist/plugin/plugin-api.js.map +1 -1
- package/dist/plugin/plugin-device.js +29 -12
- package/dist/plugin/plugin-device.js.map +1 -1
- package/dist/plugin/plugin-host-api.js.map +1 -1
- package/dist/plugin/plugin-host.js +5 -2
- package/dist/plugin/plugin-host.js.map +1 -1
- package/dist/plugin/plugin-remote-worker.js +66 -24
- package/dist/plugin/plugin-remote-worker.js.map +1 -1
- package/dist/plugin/plugin-remote.js +14 -4
- package/dist/plugin/plugin-remote.js.map +1 -1
- package/dist/plugin/runtime/node-fork-worker.js +1 -1
- package/dist/plugin/runtime/node-fork-worker.js.map +1 -1
- package/dist/plugin/system.js +1 -1
- package/dist/plugin/system.js.map +1 -1
- package/dist/rpc.js +2 -2
- package/dist/rpc.js.map +1 -1
- package/dist/runtime.js +11 -16
- package/dist/runtime.js.map +1 -1
- package/dist/scrypted-server-main.js +8 -4
- package/dist/scrypted-server-main.js.map +1 -1
- package/dist/server-settings.js +5 -1
- package/dist/server-settings.js.map +1 -1
- package/dist/services/plugin.js +1 -0
- package/dist/services/plugin.js.map +1 -1
- package/dist/state.js +3 -2
- package/dist/state.js.map +1 -1
- package/package.json +6 -12
- package/scripts/github-workflow-publish-docker.sh +2 -0
- package/scripts/print-package-json-version.js +2 -0
- package/src/event-registry.ts +3 -4
- package/src/plugin/media.ts +69 -82
- package/src/plugin/plugin-api.ts +4 -4
- package/src/plugin/plugin-device.ts +29 -12
- package/src/plugin/plugin-host-api.ts +1 -1
- package/src/plugin/plugin-host.ts +0 -1
- package/src/plugin/plugin-remote-worker.ts +90 -30
- package/src/plugin/plugin-remote.ts +17 -6
- package/src/plugin/runtime/node-fork-worker.ts +1 -1
- package/src/plugin/system.ts +1 -1
- package/src/rpc.ts +2 -1
- package/src/runtime.ts +6 -16
- package/src/scrypted-server-main.ts +8 -4
- package/src/services/plugin.ts +1 -0
- package/src/state.ts +3 -2
package/src/plugin/system.ts
CHANGED
@@ -51,7 +51,7 @@ class DeviceProxyHandler implements PrimitiveProxyHandler<any>, ScryptedDevice {
|
|
51
51
|
if (handled)
|
52
52
|
return handled;
|
53
53
|
|
54
|
-
const interfaces = new Set<string>(this.systemManager.state[this.id].interfaces
|
54
|
+
const interfaces = new Set<string>(this.systemManager.state[this.id].interfaces?.value || []);
|
55
55
|
const prop = p.toString();
|
56
56
|
const isValidProperty = this.systemManager.propertyInterfaces?.[prop] || propertyInterfaces[prop];
|
57
57
|
|
package/src/rpc.ts
CHANGED
@@ -321,7 +321,8 @@ export class RpcPeer {
|
|
321
321
|
const params = Object.assign({}, this.params, coercedParams);
|
322
322
|
let compile: CompileFunction;
|
323
323
|
try {
|
324
|
-
|
324
|
+
// prevent bundlers from trying to include non-existent vm module.
|
325
|
+
compile = module[`require`]('vm').compileFunction;
|
325
326
|
}
|
326
327
|
catch (e) {
|
327
328
|
compile = compileFunction;
|
package/src/runtime.ts
CHANGED
@@ -8,7 +8,6 @@ import http, { ServerResponse } from 'http';
|
|
8
8
|
import https from 'https';
|
9
9
|
import { spawn as ptySpawn } from 'node-pty-prebuilt-multiarch';
|
10
10
|
import path from 'path';
|
11
|
-
import qs from "query-string";
|
12
11
|
import rimraf from 'rimraf';
|
13
12
|
import semver from 'semver';
|
14
13
|
import { PassThrough } from 'stream';
|
@@ -184,12 +183,10 @@ export class ScryptedRuntime extends PluginHttp<HttpPluginData> {
|
|
184
183
|
|
185
184
|
const url = new URL(callback_url as string);
|
186
185
|
if (url.search) {
|
187
|
-
const
|
188
|
-
const state = search.state as string;
|
186
|
+
const state = url.searchParams.get('state');
|
189
187
|
if (state) {
|
190
188
|
const { s, d, r } = JSON.parse(state);
|
191
|
-
|
192
|
-
url.search = '?' + qs.stringify(search);
|
189
|
+
url.searchParams.set('state', s);
|
193
190
|
const oauthClient: ScryptedDevice & OauthClient = this.getDevice(d);
|
194
191
|
await oauthClient.onOauthCallback(url.toString()).catch();
|
195
192
|
res.redirect(r);
|
@@ -197,12 +194,12 @@ export class ScryptedRuntime extends PluginHttp<HttpPluginData> {
|
|
197
194
|
}
|
198
195
|
}
|
199
196
|
if (url.hash) {
|
200
|
-
const hash =
|
201
|
-
const state = hash.state
|
197
|
+
const hash = new URLSearchParams(url.hash.substring(1));
|
198
|
+
const state = hash.get('state');
|
202
199
|
if (state) {
|
203
200
|
const { s, d, r } = JSON.parse(state);
|
204
|
-
hash.state
|
205
|
-
url.hash = '#' +
|
201
|
+
hash.set('state', s);
|
202
|
+
url.hash = '#' + hash.toString();
|
206
203
|
const oauthClient: ScryptedDevice & OauthClient = this.getDevice(d);
|
207
204
|
await oauthClient.onOauthCallback(url.toString());
|
208
205
|
res.redirect(r);
|
@@ -700,12 +697,10 @@ export class ScryptedRuntime extends PluginHttp<HttpPluginData> {
|
|
700
697
|
// JSON stringify over rpc turns undefined into null.
|
701
698
|
if (device.nativeId === null)
|
702
699
|
device.nativeId = undefined;
|
703
|
-
let newDevice = false;
|
704
700
|
let pluginDevice = this.findPluginDevice(pluginId, device.nativeId);
|
705
701
|
if (!pluginDevice) {
|
706
702
|
pluginDevice = new PluginDevice(this.datastore.nextId().toString());
|
707
703
|
pluginDevice.stateVersion = PLUGIN_DEVICE_STATE_VERSION;
|
708
|
-
newDevice = true;
|
709
704
|
}
|
710
705
|
this.pluginDevices[pluginDevice._id] = pluginDevice;
|
711
706
|
pluginDevice.pluginId = pluginId;
|
@@ -754,11 +749,6 @@ export class ScryptedRuntime extends PluginHttp<HttpPluginData> {
|
|
754
749
|
|
755
750
|
const ret = this.notifyPluginDeviceDescriptorChanged(pluginDevice);
|
756
751
|
|
757
|
-
if (newDevice) {
|
758
|
-
const logger = this.getDeviceLogger(pluginDevice);
|
759
|
-
logger.log('a', 'New Device Added.');
|
760
|
-
}
|
761
|
-
|
762
752
|
return {
|
763
753
|
pluginDevicePromise: ret,
|
764
754
|
interfacesChanged,
|
@@ -12,7 +12,6 @@ import { getHostAddresses, SCRYPTED_DEBUG_PORT, SCRYPTED_INSECURE_PORT, SCRYPTED
|
|
12
12
|
import crypto from 'crypto';
|
13
13
|
import cookieParser from 'cookie-parser';
|
14
14
|
import axios from 'axios';
|
15
|
-
import qs from 'query-string';
|
16
15
|
import { RPCResultError } from './rpc';
|
17
16
|
import fs from 'fs';
|
18
17
|
import mkdirp from 'mkdirp';
|
@@ -318,8 +317,8 @@ async function start() {
|
|
318
317
|
|
319
318
|
app.get('/web/component/script/search', async (req, res) => {
|
320
319
|
try {
|
321
|
-
const query =
|
322
|
-
text: req.query.text,
|
320
|
+
const query = new URLSearchParams({
|
321
|
+
text: req.query.text.toString(),
|
323
322
|
})
|
324
323
|
const response = await axios(`https://registry.npmjs.org/-/v1/search?${query}`);
|
325
324
|
res.send(response.data);
|
@@ -405,7 +404,12 @@ async function start() {
|
|
405
404
|
|
406
405
|
app.get('/logout', (req, res) => {
|
407
406
|
res.clearCookie(getLoginUserToken(req.secure));
|
408
|
-
|
407
|
+
if (req.headers['accept']?.startsWith('application/json')) {
|
408
|
+
res.send({});
|
409
|
+
}
|
410
|
+
else {
|
411
|
+
res.redirect('/endpoint/@scrypted/core/public/');
|
412
|
+
}
|
409
413
|
});
|
410
414
|
|
411
415
|
let hasLogin = await db.getCount(ScryptedUser) > 0;
|
package/src/services/plugin.ts
CHANGED
@@ -45,6 +45,7 @@ export class PluginComponent {
|
|
45
45
|
async setMixins(id: string, mixins: string[]) {
|
46
46
|
const pluginDevice = this.scrypted.findPluginDeviceById(id);
|
47
47
|
this.scrypted.stateManager.setPluginDeviceState(pluginDevice, ScryptedInterfaceProperty.mixins, [...new Set(mixins)] || []);
|
48
|
+
this.scrypted.stateManager.updateDescriptor(pluginDevice);
|
48
49
|
await this.scrypted.datastore.upsert(pluginDevice);
|
49
50
|
// device may not exist, so force creation.
|
50
51
|
this.scrypted.rebuildPluginDeviceMixinTable(id);
|
package/src/state.ts
CHANGED
@@ -46,7 +46,7 @@ export class ScryptedStateManager extends EventRegistry {
|
|
46
46
|
if (!eventInterface)
|
47
47
|
throw new Error(`${property} is not a valid property`);
|
48
48
|
|
49
|
-
const changed = setState(device, property, value);
|
49
|
+
const changed = setState(device, property, value) && eventInterface !== ScryptedInterface.ScryptedDevice;
|
50
50
|
|
51
51
|
const eventTime = device?.state?.[property]?.lastEventTime;
|
52
52
|
|
@@ -116,7 +116,7 @@ export class ScryptedStateManager extends EventRegistry {
|
|
116
116
|
let cb = (eventDetails: EventDetails, eventData: any) => {
|
117
117
|
if (denoise && lastData === eventData)
|
118
118
|
return;
|
119
|
-
callback(eventDetails, eventData);
|
119
|
+
callback?.(eventDetails, eventData);
|
120
120
|
};
|
121
121
|
|
122
122
|
const wrappedRegister = super.listenDevice(id, options, cb);
|
@@ -124,6 +124,7 @@ export class ScryptedStateManager extends EventRegistry {
|
|
124
124
|
return new EventListenerRegisterImpl(() => {
|
125
125
|
wrappedRegister.removeListener();
|
126
126
|
cb = undefined;
|
127
|
+
callback = undefined;
|
127
128
|
polling = false;
|
128
129
|
});
|
129
130
|
}
|