@scrypted/server 0.7.93 → 0.7.95

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.

Files changed (185) hide show
  1. package/dist/asynciterable-utils.d.ts +2 -0
  2. package/dist/asynciterable-utils.js +24 -0
  3. package/dist/asynciterable-utils.js.map +1 -0
  4. package/dist/cert.d.ts +6 -0
  5. package/dist/cert.js +75 -0
  6. package/dist/cert.js.map +1 -0
  7. package/dist/collection.d.ts +1 -0
  8. package/dist/collection.js +16 -0
  9. package/dist/collection.js.map +1 -0
  10. package/dist/db-types.d.ts +38 -0
  11. package/dist/db-types.js +45 -0
  12. package/dist/db-types.js.map +1 -0
  13. package/dist/event-registry.d.ts +19 -0
  14. package/dist/event-registry.js +92 -0
  15. package/dist/event-registry.js.map +1 -0
  16. package/dist/http-interfaces.d.ts +3 -0
  17. package/dist/http-interfaces.js +73 -0
  18. package/dist/http-interfaces.js.map +1 -0
  19. package/dist/infer-defaults.d.ts +11 -0
  20. package/dist/infer-defaults.js +119 -0
  21. package/dist/infer-defaults.js.map +1 -0
  22. package/dist/io.d.ts +22 -0
  23. package/dist/io.js +3 -0
  24. package/dist/io.js.map +1 -0
  25. package/dist/level.d.ts +110 -0
  26. package/dist/level.js +135 -0
  27. package/dist/level.js.map +1 -0
  28. package/dist/listen-zero.d.ts +13 -0
  29. package/dist/listen-zero.js +48 -0
  30. package/dist/listen-zero.js.map +1 -0
  31. package/dist/logger.d.ts +29 -0
  32. package/dist/logger.js +78 -0
  33. package/dist/logger.js.map +1 -0
  34. package/dist/media-helpers.d.ts +5 -0
  35. package/dist/media-helpers.js +89 -0
  36. package/dist/media-helpers.js.map +1 -0
  37. package/dist/mixin/mixin-cycle.d.ts +3 -0
  38. package/dist/mixin/mixin-cycle.js +32 -0
  39. package/dist/mixin/mixin-cycle.js.map +1 -0
  40. package/dist/plugin/acl.d.ts +16 -0
  41. package/dist/plugin/acl.js +83 -0
  42. package/dist/plugin/acl.js.map +1 -0
  43. package/dist/plugin/descriptor.d.ts +22 -0
  44. package/dist/plugin/descriptor.js +35 -0
  45. package/dist/plugin/descriptor.js.map +1 -0
  46. package/dist/plugin/media.d.ts +71 -0
  47. package/dist/plugin/media.js +420 -0
  48. package/dist/plugin/media.js.map +1 -0
  49. package/dist/plugin/mediaobject.d.ts +10 -0
  50. package/dist/plugin/mediaobject.js +26 -0
  51. package/dist/plugin/mediaobject.js.map +1 -0
  52. package/dist/plugin/plugin-api.d.ts +106 -0
  53. package/dist/plugin/plugin-api.js +120 -0
  54. package/dist/plugin/plugin-api.js.map +1 -0
  55. package/dist/plugin/plugin-console.d.ts +28 -0
  56. package/dist/plugin/plugin-console.js +291 -0
  57. package/dist/plugin/plugin-console.js.map +1 -0
  58. package/dist/plugin/plugin-debug.d.ts +4 -0
  59. package/dist/plugin/plugin-debug.js +3 -0
  60. package/dist/plugin/plugin-debug.js.map +1 -0
  61. package/dist/plugin/plugin-device.d.ts +54 -0
  62. package/dist/plugin/plugin-device.js +413 -0
  63. package/dist/plugin/plugin-device.js.map +1 -0
  64. package/dist/plugin/plugin-error.d.ts +2 -0
  65. package/dist/plugin/plugin-error.js +7 -0
  66. package/dist/plugin/plugin-error.js.map +1 -0
  67. package/dist/plugin/plugin-host-api.d.ts +43 -0
  68. package/dist/plugin/plugin-host-api.js +179 -0
  69. package/dist/plugin/plugin-host-api.js.map +1 -0
  70. package/dist/plugin/plugin-host.d.ts +45 -0
  71. package/dist/plugin/plugin-host.js +398 -0
  72. package/dist/plugin/plugin-host.js.map +1 -0
  73. package/dist/plugin/plugin-http.d.ts +18 -0
  74. package/dist/plugin/plugin-http.js +120 -0
  75. package/dist/plugin/plugin-http.js.map +1 -0
  76. package/dist/plugin/plugin-lazy-remote.d.ts +31 -0
  77. package/dist/plugin/plugin-lazy-remote.js +75 -0
  78. package/dist/plugin/plugin-lazy-remote.js.map +1 -0
  79. package/dist/plugin/plugin-npm-dependencies.d.ts +8 -0
  80. package/dist/plugin/plugin-npm-dependencies.js +103 -0
  81. package/dist/plugin/plugin-npm-dependencies.js.map +1 -0
  82. package/dist/plugin/plugin-remote-stats.d.ts +8 -0
  83. package/dist/plugin/plugin-remote-stats.js +30 -0
  84. package/dist/plugin/plugin-remote-stats.js.map +1 -0
  85. package/dist/plugin/plugin-remote-websocket.d.ts +29 -0
  86. package/dist/plugin/plugin-remote-websocket.js +152 -0
  87. package/dist/plugin/plugin-remote-websocket.js.map +1 -0
  88. package/dist/plugin/plugin-remote-worker.d.ts +5 -0
  89. package/dist/plugin/plugin-remote-worker.js +348 -0
  90. package/dist/plugin/plugin-remote-worker.js.map +1 -0
  91. package/dist/plugin/plugin-remote.d.ts +75 -0
  92. package/dist/plugin/plugin-remote.js +598 -0
  93. package/dist/plugin/plugin-remote.js.map +1 -0
  94. package/dist/plugin/plugin-repl.d.ts +2 -0
  95. package/dist/plugin/plugin-repl.js +74 -0
  96. package/dist/plugin/plugin-repl.js.map +1 -0
  97. package/dist/plugin/plugin-state-check.d.ts +1 -0
  98. package/dist/plugin/plugin-state-check.js +27 -0
  99. package/dist/plugin/plugin-state-check.js.map +1 -0
  100. package/dist/plugin/plugin-volume.d.ts +3 -0
  101. package/dist/plugin/plugin-volume.js +31 -0
  102. package/dist/plugin/plugin-volume.js.map +1 -0
  103. package/dist/plugin/runtime/child-process-worker.d.ts +20 -0
  104. package/dist/plugin/runtime/child-process-worker.js +42 -0
  105. package/dist/plugin/runtime/child-process-worker.js.map +1 -0
  106. package/dist/plugin/runtime/node-fork-worker.d.ts +9 -0
  107. package/dist/plugin/runtime/node-fork-worker.js +67 -0
  108. package/dist/plugin/runtime/node-fork-worker.js.map +1 -0
  109. package/dist/plugin/runtime/node-thread-worker.d.ts +20 -0
  110. package/dist/plugin/runtime/node-thread-worker.js +73 -0
  111. package/dist/plugin/runtime/node-thread-worker.js.map +1 -0
  112. package/dist/plugin/runtime/python-worker.d.ts +10 -0
  113. package/dist/plugin/runtime/python-worker.js +91 -0
  114. package/dist/plugin/runtime/python-worker.js.map +1 -0
  115. package/dist/plugin/runtime/runtime-worker.d.ts +26 -0
  116. package/dist/plugin/runtime/runtime-worker.js +3 -0
  117. package/dist/plugin/runtime/runtime-worker.js.map +1 -0
  118. package/dist/plugin/socket-serializer.d.ts +5 -0
  119. package/dist/plugin/socket-serializer.js +17 -0
  120. package/dist/plugin/socket-serializer.js.map +1 -0
  121. package/dist/plugin/system.d.ts +39 -0
  122. package/dist/plugin/system.js +216 -0
  123. package/dist/plugin/system.js.map +1 -0
  124. package/dist/rpc-buffer-serializer.d.ts +11 -0
  125. package/dist/rpc-buffer-serializer.js +30 -0
  126. package/dist/rpc-buffer-serializer.js.map +1 -0
  127. package/dist/rpc-serializer.d.ts +24 -0
  128. package/dist/rpc-serializer.js +144 -0
  129. package/dist/rpc-serializer.js.map +1 -0
  130. package/dist/rpc.d.ts +147 -0
  131. package/dist/rpc.js +689 -0
  132. package/dist/rpc.js.map +1 -0
  133. package/dist/runtime.d.ts +103 -0
  134. package/dist/runtime.js +815 -0
  135. package/dist/runtime.js.map +1 -0
  136. package/dist/scrypted-main-exports.d.ts +6 -0
  137. package/dist/scrypted-main-exports.js +57 -0
  138. package/dist/scrypted-main-exports.js.map +1 -0
  139. package/dist/scrypted-main.d.ts +1 -0
  140. package/dist/scrypted-main.js +8 -0
  141. package/dist/scrypted-main.js.map +1 -0
  142. package/dist/scrypted-plugin-main.d.ts +2 -0
  143. package/dist/scrypted-plugin-main.js +43 -0
  144. package/dist/scrypted-plugin-main.js.map +1 -0
  145. package/dist/scrypted-server-main.d.ts +6 -0
  146. package/dist/scrypted-server-main.js +559 -0
  147. package/dist/scrypted-server-main.js.map +1 -0
  148. package/dist/server-settings.d.ts +5 -0
  149. package/dist/server-settings.js +91 -0
  150. package/dist/server-settings.js.map +1 -0
  151. package/dist/services/addresses.d.ts +7 -0
  152. package/dist/services/addresses.js +43 -0
  153. package/dist/services/addresses.js.map +1 -0
  154. package/dist/services/alerts.d.ts +9 -0
  155. package/dist/services/alerts.js +27 -0
  156. package/dist/services/alerts.js.map +1 -0
  157. package/dist/services/cors.d.ts +18 -0
  158. package/dist/services/cors.js +18 -0
  159. package/dist/services/cors.js.map +1 -0
  160. package/dist/services/info.d.ts +5 -0
  161. package/dist/services/info.js +18 -0
  162. package/dist/services/info.js.map +1 -0
  163. package/dist/services/plugin.d.ts +46 -0
  164. package/dist/services/plugin.js +172 -0
  165. package/dist/services/plugin.js.map +1 -0
  166. package/dist/services/service-control.d.ts +8 -0
  167. package/dist/services/service-control.js +39 -0
  168. package/dist/services/service-control.js.map +1 -0
  169. package/dist/services/users.d.ts +19 -0
  170. package/dist/services/users.js +75 -0
  171. package/dist/services/users.js.map +1 -0
  172. package/dist/sleep.d.ts +1 -0
  173. package/dist/sleep.js +8 -0
  174. package/dist/sleep.js.map +1 -0
  175. package/dist/state.d.ts +39 -0
  176. package/dist/state.js +247 -0
  177. package/dist/state.js.map +1 -0
  178. package/dist/threading.d.ts +3 -0
  179. package/dist/threading.js +93 -0
  180. package/dist/threading.js.map +1 -0
  181. package/dist/usertoken.d.ts +11 -0
  182. package/dist/usertoken.js +52 -0
  183. package/dist/usertoken.js.map +1 -0
  184. package/package.json +2 -2
  185. package/src/plugin/plugin-host-api.ts +3 -1
@@ -0,0 +1,110 @@
1
+ export interface AbstractOptions {
2
+ readonly [k: string]: any;
3
+ }
4
+ export type ErrorCallback = (err: Error | undefined) => void;
5
+ export type ErrorValueCallback<V> = (err: Error | undefined, value: V) => void;
6
+ export type ErrorKeyValueCallback<K, V> = (err: Error | undefined, key: K, value: V) => void;
7
+ export interface AbstractOpenOptions extends AbstractOptions {
8
+ createIfMissing?: boolean;
9
+ errorIfExists?: boolean;
10
+ }
11
+ export interface AbstractGetOptions extends AbstractOptions {
12
+ asBuffer?: boolean;
13
+ }
14
+ export interface LevelDocument {
15
+ _id?: any;
16
+ _documentType?: string;
17
+ }
18
+ export interface LevelDocumentConstructor<T extends LevelDocument> {
19
+ new (): T;
20
+ }
21
+ export interface AbstractLevelDOWN<K = any, V = any> {
22
+ open(cb?: ErrorCallback): Promise<void>;
23
+ open(options: AbstractOpenOptions, cb?: ErrorCallback): Promise<void>;
24
+ close(cb?: ErrorCallback): void;
25
+ get(key: K, cb?: ErrorValueCallback<V>): Promise<V>;
26
+ get(key: K, options: AbstractGetOptions, cb?: ErrorValueCallback<V>): Promise<V>;
27
+ put(key: K, value: V, cb?: ErrorCallback): Promise<void>;
28
+ put(key: K, value: V, options: AbstractOptions, cb?: ErrorCallback): Promise<void>;
29
+ del(key: K, cb?: ErrorCallback): Promise<void>;
30
+ del(key: K, options: AbstractOptions, cb?: ErrorCallback): Promise<void>;
31
+ batch(): AbstractChainedBatch<K, V>;
32
+ batch(array: ReadonlyArray<AbstractBatch<K, V>>, cb?: ErrorCallback): AbstractChainedBatch<K, V>;
33
+ batch(array: ReadonlyArray<AbstractBatch<K, V>>, options: AbstractOptions, cb?: ErrorCallback): AbstractChainedBatch<K, V>;
34
+ iterator(options?: AbstractIteratorOptions<K>): AbstractIterator<K, V>;
35
+ [Symbol.asyncIterator](): AsyncIterator<{
36
+ key: K;
37
+ value: V;
38
+ }>;
39
+ nextId(): number;
40
+ tryGet<T extends LevelDocument>(documentConstructor: LevelDocumentConstructor<T>, _id: any, options?: AbstractGetOptions): Promise<T | undefined>;
41
+ getAll<T extends LevelDocument>(documentConstructor: LevelDocumentConstructor<T>, options?: AbstractGetOptions): AsyncIterable<T>;
42
+ upsert<T extends LevelDocument>(value: T, options?: AbstractOptions): Promise<T>;
43
+ remove<T extends LevelDocument>(value: T): Promise<void>;
44
+ removeId<T extends LevelDocument>(documentConstructor: LevelDocumentConstructor<T>, _id: any): Promise<void>;
45
+ removeAll<T extends LevelDocument>(documentConstructor: LevelDocumentConstructor<T>): Promise<void>;
46
+ getCount<T extends LevelDocument>(documentConstructor: LevelDocumentConstructor<T>, options?: AbstractGetOptions): Promise<number>;
47
+ }
48
+ export interface AbstractLevelDOWNConstructor {
49
+ new <K = any, V = any>(location: string): AbstractLevelDOWN<K, V>;
50
+ <K = any, V = any>(location: string): AbstractLevelDOWN<K, V>;
51
+ }
52
+ export interface AbstractIteratorOptions<K = any> extends AbstractOptions {
53
+ gt?: K;
54
+ gte?: K;
55
+ lt?: K;
56
+ lte?: K;
57
+ reverse?: boolean;
58
+ limit?: number;
59
+ keys?: boolean;
60
+ values?: boolean;
61
+ keyAsBuffer?: boolean;
62
+ valueAsBuffer?: boolean;
63
+ }
64
+ export type AbstractBatch<K = any, V = any> = PutBatch<K, V> | DelBatch<K, V>;
65
+ export interface PutBatch<K = any, V = any> {
66
+ readonly type: 'put';
67
+ readonly key: K;
68
+ readonly value: V;
69
+ }
70
+ export interface DelBatch<K = any, V = any> {
71
+ readonly type: 'del';
72
+ readonly key: K;
73
+ }
74
+ export interface AbstractChainedBatch<K = any, V = any> extends AbstractOptions {
75
+ put: (key: K, value: V) => this;
76
+ del: (key: K) => this;
77
+ clear: () => this;
78
+ write(cb?: ErrorCallback): any;
79
+ write(options: any, cb?: ErrorCallback): any;
80
+ }
81
+ export interface AbstractChainedBatchConstructor {
82
+ new <K = any, V = any>(db: any): AbstractChainedBatch<K, V>;
83
+ <K = any, V = any>(db: any): AbstractChainedBatch<K, V>;
84
+ }
85
+ export interface AbstractIterator<K, V> extends AbstractOptions {
86
+ db: AbstractLevelDOWN<K, V>;
87
+ next(cb?: ErrorKeyValueCallback<K, V>): this;
88
+ end(cb?: ErrorCallback): void;
89
+ }
90
+ export interface AbstractIteratorConstructor {
91
+ new <K = any, V = any>(db: any): AbstractIterator<K, V>;
92
+ <K = any, V = any>(db: any): AbstractIterator<K, V>;
93
+ }
94
+ export interface Level extends AbstractLevelDOWN {
95
+ readonly location: string;
96
+ readonly prefix: string;
97
+ readonly version: string | number;
98
+ destroy(location: string, cb?: (err: Error | undefined) => void): void;
99
+ destroy(location: string, prefix: string, cb?: (err: Error | undefined) => void): void;
100
+ }
101
+ interface LevelOptions {
102
+ readonly prefix?: string;
103
+ readonly version?: string | number;
104
+ }
105
+ interface LevelConstructor {
106
+ new (location: string, options?: LevelOptions): Level;
107
+ (location: string, options?: LevelOptions): Level;
108
+ }
109
+ declare const _default: LevelConstructor;
110
+ export default _default;
package/dist/level.js ADDED
@@ -0,0 +1,135 @@
1
+ "use strict";
2
+ // Type definitions for abstract-leveldown 5.0
3
+ // Project: https://github.com/Level/abstract-leveldown
4
+ // Definitions by: Meirion Hughes <https://github.com/MeirionHughes>
5
+ // Daniel Byrne <https://github.com/danwbyrne>
6
+ // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
7
+ // TypeScript Version: 2.3
8
+ Object.defineProperty(exports, "__esModule", { value: true });
9
+ const level = require('level');
10
+ function createLevelDocument(documentConstructor, json) {
11
+ const doc = new documentConstructor();
12
+ Object.assign(doc, JSON.parse(json));
13
+ return doc;
14
+ }
15
+ const wrapped = (location, options) => {
16
+ const ret = level(location, options);
17
+ ret.tryGet = async (documentConstructor, _id, options) => {
18
+ try {
19
+ const _documentType = documentConstructor.name;
20
+ const key = `${_documentType}/${_id}`;
21
+ const json = await ret.get(key, options);
22
+ return createLevelDocument(documentConstructor, json);
23
+ }
24
+ catch (e) {
25
+ }
26
+ };
27
+ const iterable = {
28
+ async *[Symbol.asyncIterator]() {
29
+ const iterator = ret.iterator();
30
+ try {
31
+ while (true) {
32
+ const { key, value } = await new Promise((resolve, reject) => {
33
+ iterator.next((err, key, value) => {
34
+ if (err) {
35
+ reject(err);
36
+ }
37
+ else {
38
+ resolve({ key, value });
39
+ }
40
+ });
41
+ });
42
+ if (key == null && value == null)
43
+ break;
44
+ yield {
45
+ key,
46
+ value,
47
+ };
48
+ }
49
+ }
50
+ finally {
51
+ await new Promise(resolve => iterator.end(resolve));
52
+ }
53
+ }
54
+ };
55
+ ret[Symbol.asyncIterator] = iterable[Symbol.asyncIterator];
56
+ ret.getAll = (documentConstructor, options) => {
57
+ const _documentType = documentConstructor.name;
58
+ const prefix = `${_documentType}/`;
59
+ return {
60
+ async *[Symbol.asyncIterator]() {
61
+ for await (const entry of ret) {
62
+ if (entry.key.startsWith(prefix)) {
63
+ const doc = createLevelDocument(documentConstructor, entry.value);
64
+ if (doc._documentType === _documentType) {
65
+ yield doc;
66
+ }
67
+ }
68
+ }
69
+ }
70
+ };
71
+ };
72
+ ret.getCount = async (documentConstructor, options) => {
73
+ let count = 0;
74
+ for await (const doc of ret.getAll(documentConstructor)) {
75
+ count++;
76
+ }
77
+ return count;
78
+ };
79
+ let curId;
80
+ const oldOpen = ret.open.bind(ret);
81
+ ret.open = async (...args) => {
82
+ try {
83
+ curId = parseInt(await ret.get('_id'));
84
+ }
85
+ catch (e) {
86
+ }
87
+ if (!curId)
88
+ curId = 0;
89
+ return oldOpen(...args);
90
+ };
91
+ ret.nextId = () => {
92
+ if (typeof curId !== 'number')
93
+ throw new Error('curId is not a number');
94
+ return ++curId;
95
+ };
96
+ const saveId = async () => {
97
+ return ret.put("_id", curId);
98
+ };
99
+ ret.upsert = async (value, options) => {
100
+ const _documentType = value.constructor.name;
101
+ if (!value._id)
102
+ value._id = ret.nextId();
103
+ await saveId();
104
+ value._documentType = _documentType;
105
+ const key = `${_documentType}/${value._id}`;
106
+ await ret.put(key, JSON.stringify(value), options);
107
+ return value;
108
+ };
109
+ ret.remove = async (value) => {
110
+ const _documentType = value.constructor.name;
111
+ let { _id } = value;
112
+ const key = `${_documentType}/${_id}`;
113
+ await ret.del(key);
114
+ };
115
+ ret.removeId = async (documentConstructor, _id) => {
116
+ const _documentType = documentConstructor.name;
117
+ const key = `${_documentType}/${_id}`;
118
+ await ret.del(key);
119
+ };
120
+ ret.removeAll = async (documentConstructor) => {
121
+ const _documentType = documentConstructor.name;
122
+ const prefix = `${_documentType}/`;
123
+ for await (const entry of ret) {
124
+ if (entry.key.startsWith(prefix)) {
125
+ const doc = createLevelDocument(documentConstructor, entry.value);
126
+ if (doc._documentType === _documentType) {
127
+ await ret.del(entry.key);
128
+ }
129
+ }
130
+ }
131
+ };
132
+ return ret;
133
+ };
134
+ exports.default = wrapped;
135
+ //# sourceMappingURL=level.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"level.js","sourceRoot":"","sources":["../src/level.ts"],"names":[],"mappings":";AAAA,8CAA8C;AAC9C,uDAAuD;AACvD,oEAAoE;AACpE,8DAA8D;AAC9D,kEAAkE;AAClE,0BAA0B;;AAmJ1B,MAAM,KAAK,GAAG,OAAO,CAAC,OAAO,CAAqB,CAAC;AAEnD,SAAS,mBAAmB,CAAC,mBAAwB,EAAE,IAAS;IAC5D,MAAM,GAAG,GAAG,IAAI,mBAAmB,EAAE,CAAC;IACtC,MAAM,CAAC,MAAM,CAAC,GAAG,EAAE,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC;IACrC,OAAO,GAAG,CAAC;AACf,CAAC;AAED,MAAM,OAAO,GAAG,CAAC,QAAgB,EAAE,OAAsB,EAAE,EAAE;IACzD,MAAM,GAAG,GAAG,KAAK,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAC;IACrC,GAAG,CAAC,MAAM,GAAG,KAAK,EAAE,mBAAwB,EAAE,GAAQ,EAAE,OAA4B,EAAgB,EAAE;QAClG,IAAI;YACA,MAAM,aAAa,GAAG,mBAAmB,CAAC,IAAI,CAAC;YAC/C,MAAM,GAAG,GAAG,GAAG,aAAa,IAAI,GAAG,EAAE,CAAC;YACtC,MAAM,IAAI,GAAG,MAAM,GAAG,CAAC,GAAG,CAAC,GAAG,EAAE,OAAO,CAAC,CAAC;YACzC,OAAO,mBAAmB,CAAC,mBAAmB,EAAE,IAAI,CAAC,CAAC;SACzD;QACD,OAAO,CAAC,EAAE;SACT;IACL,CAAC,CAAA;IAED,MAAM,QAAQ,GAAG;QACb,KAAK,CAAA,CAAC,CAAC,MAAM,CAAC,aAAa,CAAC;YACxB,MAAM,QAAQ,GAAG,GAAG,CAAC,QAAQ,EAAE,CAAC;YAChC,IAAI;gBACA,OAAO,IA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gBAC9B,MAAM,GAAG,GAAG,mBAAmB,CAAC,mBAAmB,EAAE,KAAK,CAAC,KAAK,CAAC,CAAC;gBAClE,IAAI,GAAG,CAAC,aAAa,KAAK,aAAa,EAAE;oBACrC,MAAM,GAAG,CAAC,GAAG,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;iBAC5B;aACJ;SACJ;IACL,CAAC,CAAA;IAED,OAAO,GAAG,CAAC;AACf,CAAC,CAAC;AAEF,kBAAe,OAA2B,CAAC"}
@@ -0,0 +1,13 @@
1
+ /// <reference types="node" />
2
+ import net from 'net';
3
+ export declare class ListenZeroSingleClientTimeoutError extends Error {
4
+ constructor();
5
+ }
6
+ export declare function listenZero(server: net.Server, hostname?: string): Promise<number>;
7
+ export declare function listenZeroSingleClient(hostname?: string): Promise<{
8
+ server: net.Server;
9
+ url: string;
10
+ host: string;
11
+ port: number;
12
+ clientPromise: Promise<net.Socket>;
13
+ }>;
@@ -0,0 +1,48 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.listenZeroSingleClient = exports.listenZero = exports.ListenZeroSingleClientTimeoutError = void 0;
7
+ const events_1 = require("events");
8
+ const net_1 = __importDefault(require("net"));
9
+ class ListenZeroSingleClientTimeoutError extends Error {
10
+ constructor() {
11
+ super('timeout waiting for client');
12
+ }
13
+ }
14
+ exports.ListenZeroSingleClientTimeoutError = ListenZeroSingleClientTimeoutError;
15
+ async function listenZero(server, hostname) {
16
+ server.listen(0, hostname);
17
+ await (0, events_1.once)(server, 'listening');
18
+ return server.address().port;
19
+ }
20
+ exports.listenZero = listenZero;
21
+ async function listenZeroSingleClient(hostname) {
22
+ const server = new net_1.default.Server();
23
+ const port = await listenZero(server, hostname);
24
+ const clientPromise = new Promise((resolve, reject) => {
25
+ const timeout = setTimeout(() => {
26
+ server.close();
27
+ reject(new ListenZeroSingleClientTimeoutError());
28
+ }, 30000);
29
+ server.on('connection', client => {
30
+ server.close();
31
+ clearTimeout(timeout);
32
+ resolve(client);
33
+ });
34
+ });
35
+ clientPromise.catch(() => { });
36
+ let host = hostname;
37
+ if (!host || host === '0.0.0.0')
38
+ host = '127.0.0.1';
39
+ return {
40
+ server,
41
+ url: `tcp://${host}:${port}`,
42
+ host,
43
+ port,
44
+ clientPromise,
45
+ };
46
+ }
47
+ exports.listenZeroSingleClient = listenZeroSingleClient;
48
+ //# sourceMappingURL=listen-zero.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"listen-zero.js","sourceRoot":"","sources":["../src/listen-zero.ts"],"names":[],"mappings":";;;;;;AAAA,mCAA8B;AAC9B,8CAAsB;AAEtB,MAAa,kCAAmC,SAAQ,KAAK;IACzD;QACI,KAAK,CAAC,4BAA4B,CAAC,CAAA;IACvC,CAAC;CACJ;AAJD,gFAIC;AAEM,KAAK,UAAU,UAAU,CAAC,MAAkB,EAAE,QAAiB;IAClE,MAAM,CAAC,MAAM,CAAC,CAAC,EAAE,QAAQ,CAAC,CAAC;IAC3B,MAAM,IAAA,aAAI,EAAC,MAAM,EAAE,WAAW,CAAC,CAAC;IAChC,OAAQ,MAAM,CAAC,OAAO,EAAsB,CAAC,IAAI,CAAC;AACtD,CAAC;AAJD,gCAIC;AAEM,KAAK,UAAU,sBAAsB,CAAC,QAAiB;IAC1D,MAAM,MAAM,GAAG,IAAI,aAAG,CAAC,MAAM,EAAE,CAAC;IAChC,MAAM,IAAI,GAAG,MAAM,UAAU,CAAC,MAAM,EAAE,QAAQ,CAAC,CAAC;IAEhD,MAAM,aAAa,GAAG,IAAI,OAAO,CAAa,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;QAC9D,MAAM,OAAO,GAAG,UAAU,CAAC,GAAG,EAAE;YAC5B,MAAM,CAAC,KAAK,EAAE,CAAC;YACf,MAAM,CAAC,IAAI,kCAAkC,EAAE,CAAC,CAAC;QACrD,CAAC,EAAE,KAAK,CAAC,CAAA;QACT,MAAM,CAAC,EAAE,CAAC,YAAY,EAAE,MAAM,CAAC,EAAE;YAC7B,MAAM,CAAC,KAAK,EAAE,CAAC;YACf,YAAY,CAAC,OAAO,CAAC,CAAC;YAEtB,OAAO,CAAC,MAAM,CAAC,CAAC;QACpB,CAAC,CAAC,CAAC;IACP,CAAC,CAAC,CAAC;IAEH,aAAa,CAAC,KAAK,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC,CAAC;IAE/B,IAAI,IAAI,GAAG,QAAQ,CAAC;IACpB,IAAI,CAAC,IAAI,IAAI,IAAI,KAAK,SAAS;QAC3B,IAAI,GAAG,WAAW,CAAC;IAEvB,OAAO;QACH,MAAM;QACN,GAAG,EAAE,SAAS,IAAI,IAAI,IAAI,EAAE;QAC5B,IAAI;QACJ,IAAI;QACJ,aAAa;KAChB,CAAA;AACL,CAAC;AA9BD,wDA8BC"}
@@ -0,0 +1,29 @@
1
+ /// <reference types="node" />
2
+ import { EventEmitter } from 'events';
3
+ import { ScryptedRuntime } from './runtime';
4
+ import { PluginLogger } from './plugin/plugin-api';
5
+ export declare function makeAlertId(path: string, msg: string): string;
6
+ export interface LogEntry {
7
+ title: string;
8
+ timestamp: number;
9
+ level: string;
10
+ message: string;
11
+ path: string;
12
+ }
13
+ export declare class Logger extends EventEmitter implements PluginLogger {
14
+ logs: LogEntry[];
15
+ children: {
16
+ [id: string]: Logger;
17
+ };
18
+ path: string;
19
+ title: string;
20
+ scrypted: ScryptedRuntime;
21
+ constructor(scrypted: ScryptedRuntime, path: string, title: string);
22
+ log(level: string, message: string): Promise<void>;
23
+ purge(before: number): void;
24
+ clear(): Promise<void>;
25
+ clearAlert(message: string): Promise<void>;
26
+ clearAlerts(): Promise<void>;
27
+ getLogger(id: string, title: string): Logger;
28
+ getLogs(): LogEntry[];
29
+ }
package/dist/logger.js ADDED
@@ -0,0 +1,78 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.Logger = exports.makeAlertId = void 0;
7
+ const events_1 = require("events");
8
+ const crypto_1 = __importDefault(require("crypto"));
9
+ const db_types_1 = require("./db-types");
10
+ function makeAlertId(path, msg) {
11
+ return crypto_1.default.createHash('sha256').update(path).update(msg).digest('base64');
12
+ }
13
+ exports.makeAlertId = makeAlertId;
14
+ class Logger extends events_1.EventEmitter {
15
+ logs = [];
16
+ children = {};
17
+ path;
18
+ title;
19
+ scrypted;
20
+ constructor(scrypted, path, title) {
21
+ super();
22
+ this.scrypted = scrypted;
23
+ this.path = path;
24
+ this.title = title;
25
+ }
26
+ async log(level, message) {
27
+ const timestamp = Date.now();
28
+ const entry = {
29
+ timestamp,
30
+ level,
31
+ message,
32
+ path: this.path,
33
+ title: this.title,
34
+ };
35
+ this.logs.push(entry);
36
+ console.log(level, this.title, message);
37
+ this.emit('log', entry);
38
+ }
39
+ purge(before) {
40
+ this.logs = this.logs.filter(log => log.timestamp > before);
41
+ for (const child of Object.values(this.children)) {
42
+ child.purge(before);
43
+ }
44
+ }
45
+ async clear() {
46
+ await this.clearAlerts();
47
+ this.logs = [];
48
+ for (const child of Object.values(this.children)) {
49
+ await child.clear();
50
+ }
51
+ }
52
+ async clearAlert(message) {
53
+ const id = makeAlertId(this.path, message);
54
+ await this.scrypted.datastore.removeId(db_types_1.ScryptedAlert, id);
55
+ }
56
+ async clearAlerts() {
57
+ for await (const alert of this.scrypted.datastore.getAll(db_types_1.ScryptedAlert)) {
58
+ if (alert.path.startsWith(this.path)) {
59
+ await this.scrypted.datastore.remove(alert);
60
+ }
61
+ }
62
+ }
63
+ getLogger(id, title) {
64
+ if (this.children[id])
65
+ return this.children[id];
66
+ const ret = new Logger(this.scrypted, `${this.path}/${id}`, title);
67
+ ret.on('log', entry => this.emit('log', entry));
68
+ this.children[id] = ret;
69
+ return ret;
70
+ }
71
+ getLogs() {
72
+ const allLogs = Object.values(this.children).map(child => child.getLogs()).flat().concat(this.logs);
73
+ allLogs.sort((a, b) => a.timestamp - b.timestamp);
74
+ return allLogs;
75
+ }
76
+ }
77
+ exports.Logger = Logger;
78
+ //# sourceMappingURL=logger.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"logger.js","sourceRoot":"","sources":["../src/logger.ts"],"names":[],"mappings":";;;;;;AAAA,mCAAsC;AAEtC,oDAA4B;AAC5B,yCAA2C;AAG3C,SAAgB,WAAW,CAAC,IAAY,EAAE,GAAW;IACjD,OAAO,gBAAM,CAAC,UAAU,CAAC,QAAQ,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC;AACjF,CAAC;AAFD,kCAEC;AAUD,MAAa,MAAO,SAAQ,qBAAY;IACpC,IAAI,GAAe,EAAE,CAAC;IACtB,QAAQ,GAA6B,EAAE,CAAC;IACxC,IAAI,CAAS;IACb,KAAK,CAAS;IACd,QAAQ,CAAkB;IAE1B,YAAY,QAAyB,EAAE,IAAY,EAAE,KAAa;QAC9D,KAAK,EAAE,CAAC;QACR,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;QACzB,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACjB,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;IACvB,CAAC;IAED,KAAK,CAAC,GAAG,CAAC,KAAa,EAAE,OAAe;QACpC,MAAM,SAAS,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC;QAC7B,MAAM,KAAK,GAAG;YACV,SAAS;YACT,KAAK;YACL,OAAO;YACP,IAAI,EAAE,IAAI,CAAC,IAAI;YACf,KAAK,EAAE,IAAI,CAAC,KAAK;SACpB,CAAC;QACF,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;QAEtB,OAAO,CAAC,GAAG,CAAC,KAAK,EAAE,IAAI,CAAC,KAAK,EAAE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IAAI,IAAI,CAAC,QAAQ,CAAC,EAAE,CAAC;YACjB,OAAO,IAAI,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC;QAE7B,MAAM,GAAG,GAAG,IAAI,MAAM,CAAC,IAAI,CAAC,QAAQ,EAAE,GAAG,IAAI,CAAC,IAAI,IAAI,EAAE,EAAE,EAAE,KAAK,CAAC,CAAC;QACnE,GAAG,CAAC,EAAE,CAAC,KAAK,EAAE,KAAK,CAAC,EAAE,CAAC,IAAI,CAAC,IAAI,CAAC,KAAK,EAAE,KAAK,CAAC,CAAC,CAAC;QAChD,IAAI,CAAC,QAAQ,CAAC,EAAE,CAAC,GAAG,GAAG,CAAC;QACxB,OAAO,GAAG,CAAC;IACf,CAAC;IAED,OAAO;QACH,MAAM,OAAO,GAAG,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC,GAAG,CAAC,KAAK,CAAC,EAAE,CAAC,KAAK,CAAC,OAAO,EAAE,CAAC,CAAC,IAAI,EAAE,CAAC,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QACpG,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,SAAS,GAAG,CAAC,CAAC,SAAS,CAAC,CAAC;QAClD,OAAO,OAAO,CAAC;IACnB,CAAC;CACJ;AAzED,wBAyEC"}
@@ -0,0 +1,5 @@
1
+ /// <reference types="node" />
2
+ import { ChildProcess } from "child_process";
3
+ export declare function safeKillFFmpeg(cp: ChildProcess): void;
4
+ export declare function ffmpegLogInitialOutput(console: Console, cp: ChildProcess, forever?: boolean, storage?: Storage): void;
5
+ export declare function safePrintFFmpegArguments(console: Console, args: string[]): void;
@@ -0,0 +1,89 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.safePrintFFmpegArguments = exports.ffmpegLogInitialOutput = exports.safeKillFFmpeg = void 0;
7
+ const process_1 = __importDefault(require("process"));
8
+ const filtered = [
9
+ 'decode_slice_header error',
10
+ 'no frame!',
11
+ 'non-existing PPS',
12
+ ];
13
+ function safeKillFFmpeg(cp) {
14
+ if (!cp)
15
+ return;
16
+ // this will allow ffmpeg to send rtsp TEARDOWN etc
17
+ try {
18
+ cp.stdin.write('q\n');
19
+ }
20
+ catch (e) {
21
+ }
22
+ setTimeout(() => {
23
+ for (const f of cp.stdio) {
24
+ try {
25
+ f?.destroy();
26
+ }
27
+ catch (e) {
28
+ }
29
+ }
30
+ cp.kill();
31
+ setTimeout(() => {
32
+ cp.kill('SIGKILL');
33
+ }, 2000);
34
+ }, 2000);
35
+ }
36
+ exports.safeKillFFmpeg = safeKillFFmpeg;
37
+ function ffmpegLogInitialOutput(console, cp, forever, storage) {
38
+ if (!console)
39
+ return;
40
+ const SCRYPTED_FFMPEG_NOISY = !!process_1.default.env.SCRYPTED_FFMPEG_NOISY || !!storage?.getItem('SCRYPTED_FFMPEG_NOISY');
41
+ function logger(log) {
42
+ const ret = (buffer) => {
43
+ const str = buffer.toString();
44
+ for (const filter of filtered) {
45
+ if (str.indexOf(filter) !== -1)
46
+ return;
47
+ }
48
+ if (!SCRYPTED_FFMPEG_NOISY && !forever && (str.indexOf('frame=') !== -1 || str.indexOf('size=') !== -1)) {
49
+ log(str);
50
+ log('video/audio detected, discarding further input');
51
+ cp.stdout.removeListener('data', ret);
52
+ cp.stderr.removeListener('data', ret);
53
+ return;
54
+ }
55
+ log(str);
56
+ };
57
+ return ret;
58
+ }
59
+ ;
60
+ cp.stdout?.on('data', logger(console.log));
61
+ cp.stderr?.on('data', logger(console.error));
62
+ cp.on('exit', () => console.log('ffmpeg exited'));
63
+ }
64
+ exports.ffmpegLogInitialOutput = ffmpegLogInitialOutput;
65
+ function safePrintFFmpegArguments(console, args) {
66
+ if (!console)
67
+ return;
68
+ const ret = [];
69
+ let redactNext = false;
70
+ for (const arg of args) {
71
+ try {
72
+ if (redactNext) {
73
+ const url = new URL(arg);
74
+ ret.push(`${url.protocol}[REDACTED]`);
75
+ }
76
+ else {
77
+ ret.push(arg);
78
+ }
79
+ }
80
+ catch (e) {
81
+ ret.push(arg);
82
+ }
83
+ // input arguments may contain passwords.
84
+ redactNext = arg === '-i';
85
+ }
86
+ console.log(ret.join(' '));
87
+ }
88
+ exports.safePrintFFmpegArguments = safePrintFFmpegArguments;
89
+ //# sourceMappingURL=media-helpers.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"media-helpers.js","sourceRoot":"","sources":["../src/media-helpers.ts"],"names":[],"mappings":";;;;;;AACA,sDAA8B;AAE9B,MAAM,QAAQ,GAAG;IACb,2BAA2B;IAC3B,WAAW;IACX,kBAAkB;CACrB,CAAC;AAEF,SAAgB,cAAc,CAAC,EAAgB;IAC3C,IAAI,CAAC,EAAE;QACH,OAAO;IACX,mDAAmD;IACnD,IAAI;QACA,EAAE,CAAC,KAAK,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;KACzB;IACD,OAAO,CAAC,EAAE;KACT;IACD,UAAU,CAAC,GAAG,EAAE;QACZ,KAAK,MAAM,CAAC,IAAI,EAAE,CAAC,KAAK,EAAE;YACtB,IAAI;gBACA,CAAC,EAAE,OAAO,EAAE,CAAC;aAChB;YACD,OAAO,CAAC,EAAE;aACT;SACJ;QACD,EAAE,CAAC,IAAI,EAAE,CAAC;QACV,UAAU,CAAC,GAAG,EAAE;YACZ,EAAE,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;QACvB,CAAC,EAAE,IAAI,CAAC,CAAC;IACb,CAAC,EAAE,IAAI,CAAC,CAAC;AACb,CAAC;AAtBD,wCAsBC;AAED,SAAgB,sBAAsB,CAAC,OAAgB,EAAE,EAAgB,EAAE,OAAiB,EAAE,OAAiB;IAC3G,IAAI,CAAC,OAAO;QACR,OAAO;IAEX,MAAM,qBAAqB,GAAG,CAAC,CAAC,iBAAO,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,wBAAwB,CAAC,OAAgB,EAAE,IAAc;IACrE,IAAI,CAAC,OAAO;QACR,OAAO;IACX,MAAM,GAAG,GAAG,EAAE,CAAC;IACf,IAAI,UAAU,GAAG,KAAK,CAAC;IACvB,KAAK,MAAM,GAAG,IAAI,IAAI,EAAE;QACpB,IAAI;YACA,IAAI,UAAU,EAAE;gBACZ,MAAM,GAAG,GAAG,IAAI,GAAG,CAAC,GAAG,CAAC,CAAC;gBACzB,GAAG,CAAC,IAAI,CAAC,GAAG,GAAG,CAAC,QAAQ,YAAY,CAAC,CAAA;aACxC;iBACI;gBACD,GAAG,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;aACjB;SACJ;QACD,OAAO,CAAC,EAAE;YACN,GAAG,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;SACjB;QAED,yCAAyC;QACzC,UAAU,GAAG,GAAG,KAAK,IAAI,CAAC;KAC7B;IAED,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC;AAC/B,CAAC;AAxBD,4DAwBC"}
@@ -0,0 +1,3 @@
1
+ import { ScryptedRuntime } from "../runtime";
2
+ export declare function getMixins(scrypted: ScryptedRuntime, id: string): any;
3
+ export declare function hasMixinCycle(scrypted: ScryptedRuntime, id: string, mixins?: string[]): boolean;
@@ -0,0 +1,32 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.hasMixinCycle = exports.getMixins = void 0;
4
+ const types_1 = require("@scrypted/types");
5
+ const state_1 = require("../state");
6
+ function getMixins(scrypted, id) {
7
+ const pluginDevice = scrypted.findPluginDeviceById(id);
8
+ if (!pluginDevice)
9
+ return [];
10
+ return (0, state_1.getState)(pluginDevice, types_1.ScryptedInterfaceProperty.mixins) || [];
11
+ }
12
+ exports.getMixins = getMixins;
13
+ function hasMixinCycle(scrypted, id, mixins) {
14
+ mixins = mixins || getMixins(scrypted, id);
15
+ // given the mixins for a device, find all the mixins for those mixins,
16
+ // and create a visited graph.
17
+ // if the visited graphs includes the original device, that indicates
18
+ // a cyclical dependency for that device.
19
+ const visitedMixins = new Set(mixins);
20
+ mixins = mixins.slice();
21
+ while (mixins.length) {
22
+ const mixin = mixins.pop();
23
+ if (visitedMixins.has(mixin))
24
+ continue;
25
+ visitedMixins.add(mixin);
26
+ const providerMixins = getMixins(scrypted, mixin);
27
+ mixins.push(...providerMixins);
28
+ }
29
+ return visitedMixins.has(id);
30
+ }
31
+ exports.hasMixinCycle = hasMixinCycle;
32
+ //# sourceMappingURL=mixin-cycle.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mixin-cycle.js","sourceRoot":"","sources":["../../src/mixin/mixin-cycle.ts"],"names":[],"mappings":";;;AAAA,2CAA4D;AAE5D,oCAAoC;AAEpC,SAAgB,SAAS,CAAC,QAAyB,EAAE,EAAU;IAC3D,MAAM,YAAY,GAAG,QAAQ,CAAC,oBAAoB,CAAC,EAAE,CAAC,CAAC;IACvD,IAAI,CAAC,YAAY;QACb,OAAO,EAAE,CAAC;IACd,OAAO,IAAA,gBAAQ,EAAC,YAAY,EAAE,iCAAyB,CAAC,MAAM,CAAC,IAAI,EAAE,CAAC;AAC1E,CAAC;AALD,8BAKC;AAED,SAAgB,aAAa,CAAC,QAAyB,EAAE,EAAU,EAAE,MAAiB;IAClF,MAAM,GAAG,MAAM,IAAI,SAAS,CAAC,QAAQ,EAAE,EAAE,CAAC,CAAC;IAE3C,uEAAuE;IACvE,8BAA8B;IAC9B,qEAAqE;IACrE,yCAAyC;IACzC,MAAM,aAAa,GAAG,IAAI,GAAG,CAAC,MAAM,CAAC,CAAC;IAEtC,MAAM,GAAG,MAAM,CAAC,KAAK,EAAE,CAAC;IACxB,OAAO,MAAM,CAAC,MAAM,EAAE;QAClB,MAAM,KAAK,GAAG,MAAM,CAAC,GAAG,EAAE,CAAC;QAC3B,IAAI,aAAa,CAAC,GAAG,CAAC,KAAK,CAAC;YACxB,SAAS;QACb,aAAa,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;QACzB,MAAM,cAAc,GAAG,SAAS,CAAC,QAAQ,EAAE,KAAK,CAAC,CAAC;QAClD,MAAM,CAAC,IAAI,CAAC,GAAG,cAAc,CAAC,CAAC;KAClC;IAED,OAAO,aAAa,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;AACjC,CAAC;AApBD,sCAoBC"}
@@ -0,0 +1,16 @@
1
+ import { EventDetails, ScryptedInterface, ScryptedUserAccessControl } from "@scrypted/types";
2
+ /**
3
+ * Scrypted Access Controls allow selective reading of state, subscription to evemts,
4
+ * and invocation of methods.
5
+ * Everything else should be rejected.
6
+ */
7
+ export declare class AccessControls {
8
+ acl: ScryptedUserAccessControl;
9
+ constructor(acl: ScryptedUserAccessControl);
10
+ deny(reason?: string): void;
11
+ shouldRejectDevice(id: string): boolean;
12
+ shouldRejectProperty(id: string, property: string): boolean;
13
+ shouldRejectEvent(id: string, eventDetails: EventDetails): boolean;
14
+ shouldRejectInterface(id: string, scryptedInterface: ScryptedInterface): boolean;
15
+ shouldRejectMethod(id: string, method: string): boolean;
16
+ }