@fastybird/smart-panel-backend 1.1.0-alpha.5 → 1.1.0-alpha.6

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.
Files changed (126) hide show
  1. package/dist/app.module.js +7 -0
  2. package/dist/app.module.js.map +1 -1
  3. package/dist/modules/devices/controllers/channels.properties.controller.js +16 -4
  4. package/dist/modules/devices/controllers/channels.properties.controller.js.map +1 -1
  5. package/dist/modules/devices/controllers/devices.channels.properties.controller.js +16 -4
  6. package/dist/modules/devices/controllers/devices.channels.properties.controller.js.map +1 -1
  7. package/dist/modules/devices/devices.module.js +9 -0
  8. package/dist/modules/devices/devices.module.js.map +1 -1
  9. package/dist/modules/devices/services/channels.properties.service.d.ts +23 -3
  10. package/dist/modules/devices/services/channels.properties.service.js +271 -26
  11. package/dist/modules/devices/services/channels.properties.service.js.map +1 -1
  12. package/dist/modules/devices/services/channels.service.js +42 -38
  13. package/dist/modules/devices/services/channels.service.js.map +1 -1
  14. package/dist/modules/devices/services/device-structure-lock.service.d.ts +10 -2
  15. package/dist/modules/devices/services/device-structure-lock.service.js +86 -7
  16. package/dist/modules/devices/services/device-structure-lock.service.js.map +1 -1
  17. package/dist/modules/devices/services/devices.service.js +37 -33
  18. package/dist/modules/devices/services/devices.service.js.map +1 -1
  19. package/dist/modules/devices/services/module-reset.service.d.ts +3 -1
  20. package/dist/modules/devices/services/module-reset.service.js +21 -16
  21. package/dist/modules/devices/services/module-reset.service.js.map +1 -1
  22. package/dist/modules/devices/services/property-command-dispatch.service.d.ts +43 -0
  23. package/dist/modules/devices/services/property-command-dispatch.service.js +218 -0
  24. package/dist/modules/devices/services/property-command-dispatch.service.js.map +1 -0
  25. package/dist/modules/devices/services/property-command-window.service.d.ts +70 -0
  26. package/dist/modules/devices/services/property-command-window.service.js +200 -0
  27. package/dist/modules/devices/services/property-command-window.service.js.map +1 -0
  28. package/dist/modules/devices/services/property-command.service.d.ts +18 -3
  29. package/dist/modules/devices/services/property-command.service.js +44 -10
  30. package/dist/modules/devices/services/property-command.service.js.map +1 -1
  31. package/dist/modules/devices/services/property-state-coordinator.service.d.ts +4 -0
  32. package/dist/modules/devices/services/property-state-coordinator.service.js +35 -0
  33. package/dist/modules/devices/services/property-state-coordinator.service.js.map +1 -0
  34. package/dist/modules/devices/services/property-value.service.d.ts +1 -0
  35. package/dist/modules/devices/services/property-value.service.js +4 -0
  36. package/dist/modules/devices/services/property-value.service.js.map +1 -1
  37. package/dist/plugins/devices-home-assistant/services/state-changed.event.service.js +2 -3
  38. package/dist/plugins/devices-home-assistant/services/state-changed.event.service.js.map +1 -1
  39. package/dist/plugins/devices-homekit/listeners/homekit-event.listener.js +6 -1
  40. package/dist/plugins/devices-homekit/listeners/homekit-event.listener.js.map +1 -1
  41. package/dist/plugins/devices-homekit/mappers/base.mapper.js +27 -4
  42. package/dist/plugins/devices-homekit/mappers/base.mapper.js.map +1 -1
  43. package/dist/plugins/devices-homekit/mappers/homekit-mapper.interface.d.ts +8 -0
  44. package/dist/plugins/devices-homekit/mappers/thermostat-coordinator.d.ts +7 -0
  45. package/dist/plugins/devices-homekit/mappers/thermostat-coordinator.js +84 -73
  46. package/dist/plugins/devices-homekit/mappers/thermostat-coordinator.js.map +1 -1
  47. package/dist/plugins/devices-shelly-ng/delegates/delegates-manager.service.d.ts +11 -0
  48. package/dist/plugins/devices-shelly-ng/delegates/delegates-manager.service.js +121 -15
  49. package/dist/plugins/devices-shelly-ng/delegates/delegates-manager.service.js.map +1 -1
  50. package/dist/plugins/devices-shelly-ng/delegates/shelly-device.delegate.d.ts +5 -1
  51. package/dist/plugins/devices-shelly-ng/delegates/shelly-device.delegate.js +49 -8
  52. package/dist/plugins/devices-shelly-ng/delegates/shelly-device.delegate.js.map +1 -1
  53. package/dist/plugins/devices-shelly-ng/services/shelly-ng.service.d.ts +9 -1
  54. package/dist/plugins/devices-shelly-ng/services/shelly-ng.service.js +59 -24
  55. package/dist/plugins/devices-shelly-ng/services/shelly-ng.service.js.map +1 -1
  56. package/dist/plugins/devices-shelly-ng/services/shelly-ws-server.service.js +1 -3
  57. package/dist/plugins/devices-shelly-ng/services/shelly-ws-server.service.js.map +1 -1
  58. package/dist/plugins/remote-access-cloudflare-tunnel/controllers/setup.controller.d.ts +17 -0
  59. package/dist/plugins/remote-access-cloudflare-tunnel/controllers/setup.controller.js +147 -0
  60. package/dist/plugins/remote-access-cloudflare-tunnel/controllers/setup.controller.js.map +1 -0
  61. package/dist/plugins/remote-access-cloudflare-tunnel/controllers/status.controller.d.ts +15 -0
  62. package/dist/plugins/remote-access-cloudflare-tunnel/controllers/status.controller.js +98 -0
  63. package/dist/plugins/remote-access-cloudflare-tunnel/controllers/status.controller.js.map +1 -0
  64. package/dist/plugins/remote-access-cloudflare-tunnel/dto/update-config.dto.d.ts +9 -0
  65. package/dist/plugins/remote-access-cloudflare-tunnel/dto/update-config.dto.js +94 -0
  66. package/dist/plugins/remote-access-cloudflare-tunnel/dto/update-config.dto.js.map +1 -0
  67. package/dist/plugins/remote-access-cloudflare-tunnel/models/config.model.d.ts +9 -0
  68. package/dist/plugins/remote-access-cloudflare-tunnel/models/config.model.js +92 -0
  69. package/dist/plugins/remote-access-cloudflare-tunnel/models/config.model.js.map +1 -0
  70. package/dist/plugins/remote-access-cloudflare-tunnel/models/install.model.d.ts +7 -0
  71. package/dist/plugins/remote-access-cloudflare-tunnel/models/install.model.js +48 -0
  72. package/dist/plugins/remote-access-cloudflare-tunnel/models/install.model.js.map +1 -0
  73. package/dist/plugins/remote-access-cloudflare-tunnel/models/status.model.d.ts +42 -0
  74. package/dist/plugins/remote-access-cloudflare-tunnel/models/status.model.js +352 -0
  75. package/dist/plugins/remote-access-cloudflare-tunnel/models/status.model.js.map +1 -0
  76. package/dist/plugins/remote-access-cloudflare-tunnel/remote-access-cloudflare-tunnel.constants.d.ts +24 -0
  77. package/dist/plugins/remote-access-cloudflare-tunnel/remote-access-cloudflare-tunnel.constants.js +27 -0
  78. package/dist/plugins/remote-access-cloudflare-tunnel/remote-access-cloudflare-tunnel.constants.js.map +1 -0
  79. package/dist/plugins/remote-access-cloudflare-tunnel/remote-access-cloudflare-tunnel.exceptions.d.ts +8 -0
  80. package/dist/plugins/remote-access-cloudflare-tunnel/remote-access-cloudflare-tunnel.exceptions.js +19 -0
  81. package/dist/plugins/remote-access-cloudflare-tunnel/remote-access-cloudflare-tunnel.exceptions.js.map +1 -0
  82. package/dist/plugins/remote-access-cloudflare-tunnel/remote-access-cloudflare-tunnel.openapi.d.ts +4 -0
  83. package/dist/plugins/remote-access-cloudflare-tunnel/remote-access-cloudflare-tunnel.openapi.js +20 -0
  84. package/dist/plugins/remote-access-cloudflare-tunnel/remote-access-cloudflare-tunnel.openapi.js.map +1 -0
  85. package/dist/plugins/remote-access-cloudflare-tunnel/remote-access-cloudflare-tunnel.plugin.d.ts +21 -0
  86. package/dist/plugins/remote-access-cloudflare-tunnel/remote-access-cloudflare-tunnel.plugin.js +135 -0
  87. package/dist/plugins/remote-access-cloudflare-tunnel/remote-access-cloudflare-tunnel.plugin.js.map +1 -0
  88. package/dist/plugins/remote-access-cloudflare-tunnel/scripts/cloudflared-setup.sh +185 -0
  89. package/dist/plugins/remote-access-cloudflare-tunnel/services/cloudflare-tunnel-managed.service.d.ts +82 -0
  90. package/dist/plugins/remote-access-cloudflare-tunnel/services/cloudflare-tunnel-managed.service.js +507 -0
  91. package/dist/plugins/remote-access-cloudflare-tunnel/services/cloudflare-tunnel-managed.service.js.map +1 -0
  92. package/dist/plugins/remote-access-cloudflare-tunnel/services/cloudflare-tunnel-provider.service.d.ts +10 -0
  93. package/dist/plugins/remote-access-cloudflare-tunnel/services/cloudflare-tunnel-provider.service.js +37 -0
  94. package/dist/plugins/remote-access-cloudflare-tunnel/services/cloudflare-tunnel-provider.service.js.map +1 -0
  95. package/dist/plugins/remote-access-cloudflare-tunnel/services/cloudflare-tunnel-setup.service.d.ts +38 -0
  96. package/dist/plugins/remote-access-cloudflare-tunnel/services/cloudflare-tunnel-setup.service.js +147 -0
  97. package/dist/plugins/remote-access-cloudflare-tunnel/services/cloudflare-tunnel-setup.service.js.map +1 -0
  98. package/dist/plugins/remote-access-cloudflare-tunnel/services/cloudflared-cli.service.d.ts +15 -0
  99. package/dist/plugins/remote-access-cloudflare-tunnel/services/cloudflared-cli.service.js +67 -0
  100. package/dist/plugins/remote-access-cloudflare-tunnel/services/cloudflared-cli.service.js.map +1 -0
  101. package/dist/plugins/remote-access-cloudflare-tunnel/services/cloudflared-metrics.service.d.ts +8 -0
  102. package/dist/plugins/remote-access-cloudflare-tunnel/services/cloudflared-metrics.service.js +46 -0
  103. package/dist/plugins/remote-access-cloudflare-tunnel/services/cloudflared-metrics.service.js.map +1 -0
  104. package/dist/plugins/remote-access-cloudflare-tunnel/services/cloudflared-process.service.d.ts +27 -0
  105. package/dist/plugins/remote-access-cloudflare-tunnel/services/cloudflared-process.service.js +139 -0
  106. package/dist/plugins/remote-access-cloudflare-tunnel/services/cloudflared-process.service.js.map +1 -0
  107. package/dist/plugins/scenes-local/platforms/local-scene.platform.d.ts +3 -1
  108. package/dist/plugins/scenes-local/platforms/local-scene.platform.js +12 -7
  109. package/dist/plugins/scenes-local/platforms/local-scene.platform.js.map +1 -1
  110. package/dist/plugins/spaces-home-control/services/climate-intent.service.d.ts +3 -1
  111. package/dist/plugins/spaces-home-control/services/climate-intent.service.js +6 -3
  112. package/dist/plugins/spaces-home-control/services/climate-intent.service.js.map +1 -1
  113. package/dist/plugins/spaces-home-control/services/covers-intent.service.d.ts +3 -1
  114. package/dist/plugins/spaces-home-control/services/covers-intent.service.js +6 -3
  115. package/dist/plugins/spaces-home-control/services/covers-intent.service.js.map +1 -1
  116. package/dist/plugins/spaces-home-control/services/lighting-intent.service.d.ts +3 -1
  117. package/dist/plugins/spaces-home-control/services/lighting-intent.service.js +7 -4
  118. package/dist/plugins/spaces-home-control/services/lighting-intent.service.js.map +1 -1
  119. package/dist/plugins/spaces-home-control/services/space-media-activity.service.d.ts +3 -1
  120. package/dist/plugins/spaces-home-control/services/space-media-activity.service.js +11 -5
  121. package/dist/plugins/spaces-home-control/services/space-media-activity.service.js.map +1 -1
  122. package/dist/plugins/spaces-home-control/services/space-undo-history.service.d.ts +3 -1
  123. package/dist/plugins/spaces-home-control/services/space-undo-history.service.js +8 -5
  124. package/dist/plugins/spaces-home-control/services/space-undo-history.service.js.map +1 -1
  125. package/dist/tsconfig.build.tsbuildinfo +1 -1
  126. package/package.json +2 -2
@@ -0,0 +1,218 @@
1
+ "use strict";
2
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
7
+ };
8
+ var __metadata = (this && this.__metadata) || function (k, v) {
9
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.PropertyCommandDispatchService = void 0;
13
+ const common_1 = require("@nestjs/common");
14
+ const devices_constants_1 = require("../devices.constants");
15
+ const property_value_state_model_1 = require("../models/property-value-state.model");
16
+ const property_command_value_utils_1 = require("../utils/property-command-value.utils");
17
+ const channels_properties_service_1 = require("./channels.properties.service");
18
+ const channels_service_1 = require("./channels.service");
19
+ const device_structure_lock_service_1 = require("./device-structure-lock.service");
20
+ const devices_service_1 = require("./devices.service");
21
+ const platform_registry_service_1 = require("./platform.registry.service");
22
+ const property_command_window_service_1 = require("./property-command-window.service");
23
+ const property_state_coordinator_service_1 = require("./property-state-coordinator.service");
24
+ const property_value_source_registry_service_1 = require("./property-value-source.registry.service");
25
+ let PropertyCommandDispatchService = class PropertyCommandDispatchService {
26
+ constructor(channelsPropertiesService, channelsService, devicesService, platformRegistryService, valueSourceRegistry, structureLock, propertyStateCoordinator, commandWindowService) {
27
+ this.channelsPropertiesService = channelsPropertiesService;
28
+ this.channelsService = channelsService;
29
+ this.devicesService = devicesService;
30
+ this.platformRegistryService = platformRegistryService;
31
+ this.valueSourceRegistry = valueSourceRegistry;
32
+ this.structureLock = structureLock;
33
+ this.propertyStateCoordinator = propertyStateCoordinator;
34
+ this.commandWindowService = commandWindowService;
35
+ }
36
+ async dispatchBatch(updates, options = {}) {
37
+ if (updates.length === 0) {
38
+ return { success: true };
39
+ }
40
+ const platform = this.platformRegistryService.get(updates[0].device);
41
+ if (platform === null) {
42
+ return { success: false, reason: 'Unsupported device type' };
43
+ }
44
+ const handles = options.windowHandles ?? (await this.admitWindows(updates, options))?.map(({ handle }) => handle);
45
+ if (handles === undefined) {
46
+ return { success: false, reason: 'Canonical property target is invalid or conflicts within the batch' };
47
+ }
48
+ if (options.windowHandles !== undefined && !(await this.verifyPreopenedWindows(updates, handles))) {
49
+ this.failOwned(handles);
50
+ return { success: false, reason: 'Canonical property target changed before dispatch' };
51
+ }
52
+ try {
53
+ const success = await platform.processBatch([...updates]);
54
+ if (!success) {
55
+ this.failOwned(handles);
56
+ return { success: false, reason: 'Execution failed' };
57
+ }
58
+ return { success: true };
59
+ }
60
+ catch (error) {
61
+ this.failOwned(handles);
62
+ throw error;
63
+ }
64
+ }
65
+ async prepareApiCommand(update, ttlMs) {
66
+ const admitted = await this.admitWindows([update], { ttlMs });
67
+ const first = admitted?.[0];
68
+ if (first === undefined) {
69
+ return null;
70
+ }
71
+ return {
72
+ handle: first.handle,
73
+ canonicalPropertyId: first.admission.canonicalPropertyId,
74
+ baseline: first.admission.baseline,
75
+ optimisticEligible: first.admission.canonicalPropertyId === update.property.id && first.admission.baseline !== null,
76
+ };
77
+ }
78
+ async admitWindows(updates, options) {
79
+ return this.structureLock.runShared(async () => {
80
+ const requestedByCanonical = new Map();
81
+ for (const update of updates) {
82
+ const canonicalPropertyId = this.valueSourceRegistry.resolve(update.property);
83
+ const requested = requestedByCanonical.get(canonicalPropertyId) ?? [];
84
+ requested.push(update);
85
+ requestedByCanonical.set(canonicalPropertyId, requested);
86
+ }
87
+ const admitted = [];
88
+ for (const [canonicalPropertyId, requestedUpdates] of requestedByCanonical) {
89
+ const admission = await this.propertyStateCoordinator.run(canonicalPropertyId, async () => this.createAdmission(canonicalPropertyId, requestedUpdates));
90
+ if (admission === null) {
91
+ this.failOwned(admitted.map(({ handle }) => handle));
92
+ return null;
93
+ }
94
+ if (!admission.eligible) {
95
+ continue;
96
+ }
97
+ admitted.push({
98
+ handle: this.commandWindowService.open({
99
+ canonicalTarget: admission.canonicalTarget,
100
+ requestedTargets: admission.requestedTargets,
101
+ intentId: options.intentId,
102
+ commandedValue: admission.commandedValue,
103
+ previousValue: admission.previousValue,
104
+ ttlMs: options.ttlMs ?? 3_000,
105
+ }),
106
+ admission,
107
+ });
108
+ }
109
+ return admitted;
110
+ });
111
+ }
112
+ async createAdmission(canonicalPropertyId, requestedUpdates) {
113
+ const first = requestedUpdates[0];
114
+ if (first === undefined) {
115
+ return null;
116
+ }
117
+ for (const requested of requestedUpdates) {
118
+ const currentRequested = await this.channelsPropertiesService.findOne(requested.property.id);
119
+ if (currentRequested === null || this.valueSourceRegistry.resolve(currentRequested) !== canonicalPropertyId) {
120
+ return null;
121
+ }
122
+ }
123
+ const sourceProperty = await this.channelsPropertiesService.findOne(canonicalPropertyId);
124
+ if (sourceProperty === null || this.valueSourceRegistry.resolve(sourceProperty) !== sourceProperty.id) {
125
+ return null;
126
+ }
127
+ const sourceChannelId = getEntityId(sourceProperty.channel);
128
+ const sourceChannel = sourceChannelId === null ? null : await this.channelsService.findOne(sourceChannelId);
129
+ const sourceDeviceId = sourceChannel === null ? null : getEntityId(sourceChannel.device);
130
+ const sourceDevice = sourceDeviceId === null ? null : await this.devicesService.findOne(sourceDeviceId);
131
+ if (sourceChannel === null || sourceDevice === null) {
132
+ return null;
133
+ }
134
+ let commandedValue;
135
+ for (const requested of requestedUpdates) {
136
+ const validation = (0, property_command_value_utils_1.validatePropertyCommandValue)(sourceProperty, requested.value);
137
+ if (!validation.valid || validation.value === undefined) {
138
+ return null;
139
+ }
140
+ if (commandedValue !== undefined && commandedValue !== validation.value) {
141
+ return null;
142
+ }
143
+ commandedValue = validation.value;
144
+ }
145
+ if (commandedValue === undefined) {
146
+ return null;
147
+ }
148
+ const requestedTargets = requestedUpdates.map(toTarget);
149
+ const canonicalTarget = toTarget({ device: sourceDevice, channel: sourceChannel, property: sourceProperty });
150
+ const writable = sourceProperty.permissions.includes(devices_constants_1.PermissionType.READ_WRITE);
151
+ const authoritative = this.platformRegistryService.usesAuthoritativePropertyReadback(sourceDevice, sourceProperty);
152
+ return {
153
+ canonicalPropertyId,
154
+ canonicalTarget,
155
+ requestedTargets,
156
+ commandedValue,
157
+ previousValue: sourceProperty.value?.value ?? null,
158
+ baseline: sourceProperty.value === null
159
+ ? null
160
+ : new property_value_state_model_1.PropertyValueState(sourceProperty.value.value, sourceProperty.value.lastUpdated, sourceProperty.value.trend),
161
+ eligible: writable && !authoritative,
162
+ };
163
+ }
164
+ async verifyPreopenedWindows(updates, handles) {
165
+ return this.structureLock.runShared(async () => {
166
+ const requestedByCanonical = new Map();
167
+ for (const update of updates) {
168
+ const current = await this.channelsPropertiesService.findOne(update.property.id);
169
+ if (current === null) {
170
+ return false;
171
+ }
172
+ const canonicalPropertyId = this.valueSourceRegistry.resolve(current);
173
+ const requested = requestedByCanonical.get(canonicalPropertyId) ?? [];
174
+ requested.push({ ...update, property: current });
175
+ requestedByCanonical.set(canonicalPropertyId, requested);
176
+ }
177
+ if (requestedByCanonical.size !== handles.length) {
178
+ return false;
179
+ }
180
+ for (const [canonicalPropertyId, requestedUpdates] of requestedByCanonical) {
181
+ const handle = handles.find((candidate) => candidate.canonicalPropertyId === canonicalPropertyId);
182
+ if (handle === undefined) {
183
+ return false;
184
+ }
185
+ const admission = await this.propertyStateCoordinator.run(canonicalPropertyId, async () => this.createAdmission(canonicalPropertyId, requestedUpdates));
186
+ const window = this.commandWindowService.get(canonicalPropertyId);
187
+ if (admission === null || !admission.eligible || window === null || window.generation !== handle.generation) {
188
+ return false;
189
+ }
190
+ }
191
+ return true;
192
+ });
193
+ }
194
+ failOwned(handles) {
195
+ for (const handle of handles) {
196
+ this.commandWindowService.fail(handle);
197
+ }
198
+ }
199
+ };
200
+ exports.PropertyCommandDispatchService = PropertyCommandDispatchService;
201
+ exports.PropertyCommandDispatchService = PropertyCommandDispatchService = __decorate([
202
+ (0, common_1.Injectable)(),
203
+ __metadata("design:paramtypes", [channels_properties_service_1.ChannelsPropertiesService,
204
+ channels_service_1.ChannelsService,
205
+ devices_service_1.DevicesService,
206
+ platform_registry_service_1.PlatformRegistryService,
207
+ property_value_source_registry_service_1.PropertyValueSourceRegistryService,
208
+ device_structure_lock_service_1.DeviceStructureLockService,
209
+ property_state_coordinator_service_1.PropertyStateCoordinatorService,
210
+ property_command_window_service_1.PropertyCommandWindowService])
211
+ ], PropertyCommandDispatchService);
212
+ const getEntityId = (entity) => typeof entity === 'string' ? entity : (entity?.id ?? null);
213
+ const toTarget = ({ device, channel, property, }) => ({
214
+ deviceId: device.id,
215
+ channelId: channel.id,
216
+ propertyId: property.id,
217
+ });
218
+ //# sourceMappingURL=property-command-dispatch.service.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"property-command-dispatch.service.js","sourceRoot":"","sources":["../../../../src/modules/devices/services/property-command-dispatch.service.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,2CAA4C;AAE5C,4DAAsD;AACtD,qFAA0E;AAE1E,wFAA2G;AAE3G,+EAA0E;AAC1E,yDAAqD;AACrD,mFAA6E;AAC7E,uDAAmD;AACnD,2EAAsE;AACtE,uFAI2C;AAC3C,6FAAuF;AACvF,qGAA8F;AA6CvF,IAAM,8BAA8B,GAApC,MAAM,8BA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AAU,GAAE;qCAGiC,uDAAyB;QACnC,kCAAe;QAChB,gCAAc;QACL,mDAAuB;QAC3B,2EAAkC;QACxC,0DAA0B;QACf,oEAA+B;QACnC,8DAA4B;GATxD,8BAA8B,CA4P1C;AAED,MAAM,WAAW,GAAG,CAA2B,MAAqC,EAAiB,EAAE,CACtG,OAAO,MAAM,KAAK,QAAQ,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,MAAM,EAAE,EAAE,IAAI,IAAI,CAAC,CAAC;AAE5D,MAAM,QAAQ,GAAG,CAAC,EACjB,MAAM,EACN,OAAO,EACP,QAAQ,GACsD,EAA+B,EAAE,CAAC,CAAC;IACjG,QAAQ,EAAE,MAAM,CAAC,EAAE;IACnB,SAAS,EAAE,OAAO,CAAC,EAAE;IACrB,UAAU,EAAE,QAAQ,CAAC,EAAE;CACvB,CAAC,CAAC"}
@@ -0,0 +1,70 @@
1
+ import { PropertyValueState } from '../models/property-value-state.model';
2
+ import { PropertyCommandValue } from '../utils/property-command-value.utils';
3
+ export declare const PROPERTY_COMMAND_CONFIRMATION_GRACE_MS = 1500;
4
+ export type PropertyCommandWindowState = 'pending' | 'confirmed_grace';
5
+ export interface PropertyCommandWindowTarget {
6
+ readonly deviceId: string;
7
+ readonly channelId: string;
8
+ readonly propertyId: string;
9
+ }
10
+ export interface PropertyCommandWindowHandle {
11
+ readonly canonicalPropertyId: string;
12
+ readonly generation: string;
13
+ }
14
+ export interface PropertyCommandReceipt {
15
+ readonly value: PropertyCommandValue;
16
+ readonly receivedAt: number;
17
+ }
18
+ export interface PropertyCommandPatchReceipt {
19
+ readonly baseline: PropertyValueState;
20
+ readonly optimisticState: PropertyValueState;
21
+ }
22
+ export interface PropertyCommandWindow {
23
+ readonly canonicalTarget: PropertyCommandWindowTarget;
24
+ readonly requestedTargets: readonly PropertyCommandWindowTarget[];
25
+ readonly generation: string;
26
+ readonly intentId: string | null;
27
+ readonly commandedValue: PropertyCommandValue;
28
+ readonly previousValue: PropertyCommandValue | null;
29
+ readonly lastReceipt: PropertyCommandReceipt | null;
30
+ readonly heldReceipt: PropertyCommandReceipt | null;
31
+ readonly recoveryReceipt: PropertyCommandReceipt | null;
32
+ readonly rollbackBaseline: PropertyValueState | null;
33
+ readonly patchReceipt: PropertyCommandPatchReceipt | null;
34
+ readonly openedAt: number;
35
+ readonly expiresAt: number;
36
+ readonly state: PropertyCommandWindowState;
37
+ readonly confirmedAt: number | null;
38
+ readonly confirmationExpiresAt: number | null;
39
+ }
40
+ export interface OpenPropertyCommandWindowInput {
41
+ readonly canonicalTarget: PropertyCommandWindowTarget;
42
+ readonly requestedTargets: readonly PropertyCommandWindowTarget[];
43
+ readonly intentId?: string;
44
+ readonly commandedValue: PropertyCommandValue;
45
+ readonly previousValue: PropertyCommandValue | null;
46
+ readonly ttlMs: number;
47
+ }
48
+ export declare class PropertyCommandWindowService {
49
+ private readonly windows;
50
+ private readonly recoveries;
51
+ open(input: OpenPropertyCommandWindowInput): PropertyCommandWindowHandle;
52
+ get(canonicalPropertyId: string): PropertyCommandWindow | null;
53
+ confirm(handle: PropertyCommandWindowHandle, receipt: PropertyCommandReceipt): PropertyCommandWindow | null;
54
+ attachPatchReceipt(handle: PropertyCommandWindowHandle, receipt: PropertyCommandPatchReceipt): boolean;
55
+ hold(handle: PropertyCommandWindowHandle, receipt: PropertyCommandReceipt): PropertyCommandWindow | null;
56
+ close(handle: PropertyCommandWindowHandle): boolean;
57
+ fail(handle: PropertyCommandWindowHandle): boolean;
58
+ sweep(): readonly PropertyCommandWindowHandle[];
59
+ expire(canonicalPropertyId: string): PropertyCommandWindowHandle | null;
60
+ getRecovery(handle: PropertyCommandWindowHandle): PropertyCommandWindow | null;
61
+ completeRecovery(handle: PropertyCommandWindowHandle): boolean;
62
+ cancelRecovery(canonicalPropertyId: string): void;
63
+ cancel(canonicalPropertyId: string): void;
64
+ clear(): void;
65
+ private getCurrent;
66
+ private isExpired;
67
+ private detach;
68
+ private pruneRecoveries;
69
+ private toSnapshot;
70
+ }
@@ -0,0 +1,200 @@
1
+ "use strict";
2
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
7
+ };
8
+ Object.defineProperty(exports, "__esModule", { value: true });
9
+ exports.PropertyCommandWindowService = exports.PROPERTY_COMMAND_CONFIRMATION_GRACE_MS = void 0;
10
+ const node_crypto_1 = require("node:crypto");
11
+ const common_1 = require("@nestjs/common");
12
+ const property_value_state_model_1 = require("../models/property-value-state.model");
13
+ exports.PROPERTY_COMMAND_CONFIRMATION_GRACE_MS = 1_500;
14
+ let PropertyCommandWindowService = class PropertyCommandWindowService {
15
+ constructor() {
16
+ this.windows = new Map();
17
+ this.recoveries = new Map();
18
+ }
19
+ open(input) {
20
+ const now = Date.now();
21
+ const canonicalPropertyId = input.canonicalTarget.propertyId;
22
+ const current = this.getCurrent(canonicalPropertyId, now);
23
+ const ttlMs = Number.isFinite(input.ttlMs) && input.ttlMs > 0 ? input.ttlMs : 3_000;
24
+ const generation = (0, node_crypto_1.randomUUID)();
25
+ const previousValue = current?.commandedValue ?? input.previousValue;
26
+ this.recoveries.delete(canonicalPropertyId);
27
+ this.windows.set(canonicalPropertyId, {
28
+ canonicalTarget: freezeTarget(input.canonicalTarget),
29
+ requestedTargets: input.requestedTargets.map(freezeTarget),
30
+ generation,
31
+ intentId: input.intentId ?? null,
32
+ commandedValue: input.commandedValue,
33
+ previousValue,
34
+ lastReceipt: null,
35
+ heldReceipt: null,
36
+ recoveryReceipt: null,
37
+ rollbackBaseline: current?.rollbackBaseline ?? current?.patchReceipt?.baseline ?? null,
38
+ patchReceipt: null,
39
+ openedAt: now,
40
+ expiresAt: now + ttlMs,
41
+ state: 'pending',
42
+ confirmedAt: null,
43
+ confirmationExpiresAt: null,
44
+ });
45
+ return Object.freeze({ canonicalPropertyId, generation });
46
+ }
47
+ get(canonicalPropertyId) {
48
+ return this.toSnapshot(this.getCurrent(canonicalPropertyId, Date.now()));
49
+ }
50
+ confirm(handle, receipt) {
51
+ const current = this.getCurrent(handle.canonicalPropertyId, Date.now());
52
+ if (current === undefined || current.generation !== handle.generation) {
53
+ return null;
54
+ }
55
+ if (current.state === 'pending') {
56
+ current.state = 'confirmed_grace';
57
+ current.confirmedAt = receipt.receivedAt;
58
+ current.confirmationExpiresAt = receipt.receivedAt + exports.PROPERTY_COMMAND_CONFIRMATION_GRACE_MS;
59
+ current.lastReceipt = freezeReceipt(receipt);
60
+ current.heldReceipt = null;
61
+ current.rollbackBaseline = null;
62
+ current.patchReceipt = null;
63
+ }
64
+ return this.toSnapshot(current);
65
+ }
66
+ attachPatchReceipt(handle, receipt) {
67
+ const current = this.getCurrent(handle.canonicalPropertyId, Date.now());
68
+ if (current === undefined || current.generation !== handle.generation || current.state !== 'pending') {
69
+ return false;
70
+ }
71
+ const baseline = current.rollbackBaseline ?? receipt.baseline;
72
+ current.rollbackBaseline = freezeValueState(baseline);
73
+ current.patchReceipt = freezePatchReceipt({
74
+ baseline,
75
+ optimisticState: receipt.optimisticState,
76
+ });
77
+ return true;
78
+ }
79
+ hold(handle, receipt) {
80
+ const current = this.getCurrent(handle.canonicalPropertyId, Date.now());
81
+ if (current === undefined || current.generation !== handle.generation || current.state !== 'pending') {
82
+ return null;
83
+ }
84
+ current.heldReceipt = freezeReceipt(receipt);
85
+ return this.toSnapshot(current);
86
+ }
87
+ close(handle) {
88
+ const current = this.windows.get(handle.canonicalPropertyId);
89
+ if (current !== undefined && current.generation === handle.generation) {
90
+ this.windows.delete(handle.canonicalPropertyId);
91
+ return true;
92
+ }
93
+ return false;
94
+ }
95
+ fail(handle) {
96
+ const current = this.getCurrent(handle.canonicalPropertyId, Date.now());
97
+ if (current === undefined || current.generation !== handle.generation || current.state !== 'pending') {
98
+ return false;
99
+ }
100
+ this.detach(handle.canonicalPropertyId, current);
101
+ return true;
102
+ }
103
+ sweep() {
104
+ const now = Date.now();
105
+ for (const [canonicalPropertyId, window] of this.windows) {
106
+ if (!this.isExpired(window, now)) {
107
+ continue;
108
+ }
109
+ this.detach(canonicalPropertyId, window);
110
+ }
111
+ this.pruneRecoveries(now);
112
+ return Object.freeze([...this.recoveries.entries()].map(([canonicalPropertyId, recovery]) => Object.freeze({ canonicalPropertyId, generation: recovery.window.generation })));
113
+ }
114
+ expire(canonicalPropertyId) {
115
+ const current = this.windows.get(canonicalPropertyId);
116
+ if (current === undefined || !this.isExpired(current, Date.now())) {
117
+ return null;
118
+ }
119
+ this.detach(canonicalPropertyId, current);
120
+ return Object.freeze({ canonicalPropertyId, generation: current.generation });
121
+ }
122
+ getRecovery(handle) {
123
+ this.pruneRecoveries(Date.now());
124
+ const recovery = this.recoveries.get(handle.canonicalPropertyId);
125
+ return recovery?.window.generation === handle.generation ? this.toSnapshot(recovery.window) : null;
126
+ }
127
+ completeRecovery(handle) {
128
+ const recovery = this.recoveries.get(handle.canonicalPropertyId);
129
+ if (recovery === undefined || recovery.window.generation !== handle.generation) {
130
+ return false;
131
+ }
132
+ this.recoveries.delete(handle.canonicalPropertyId);
133
+ return true;
134
+ }
135
+ cancelRecovery(canonicalPropertyId) {
136
+ this.recoveries.delete(canonicalPropertyId);
137
+ }
138
+ cancel(canonicalPropertyId) {
139
+ this.windows.delete(canonicalPropertyId);
140
+ this.recoveries.delete(canonicalPropertyId);
141
+ }
142
+ clear() {
143
+ this.windows.clear();
144
+ this.recoveries.clear();
145
+ }
146
+ getCurrent(canonicalPropertyId, now) {
147
+ const current = this.windows.get(canonicalPropertyId);
148
+ if (current !== undefined && this.isExpired(current, now)) {
149
+ this.detach(canonicalPropertyId, current);
150
+ return undefined;
151
+ }
152
+ return current;
153
+ }
154
+ isExpired(window, now) {
155
+ return now >= (window.confirmationExpiresAt ?? window.expiresAt);
156
+ }
157
+ detach(canonicalPropertyId, window, now = Date.now()) {
158
+ this.windows.delete(canonicalPropertyId);
159
+ if (window.state === 'pending' && (window.heldReceipt !== null || window.patchReceipt !== null)) {
160
+ this.recoveries.set(canonicalPropertyId, {
161
+ window,
162
+ deadlineAt: now + (window.expiresAt - window.openedAt),
163
+ });
164
+ }
165
+ }
166
+ pruneRecoveries(now) {
167
+ for (const [canonicalPropertyId, recovery] of this.recoveries) {
168
+ if (now >= recovery.deadlineAt) {
169
+ this.recoveries.delete(canonicalPropertyId);
170
+ }
171
+ }
172
+ }
173
+ toSnapshot(window) {
174
+ if (window === undefined) {
175
+ return null;
176
+ }
177
+ return Object.freeze({
178
+ ...window,
179
+ canonicalTarget: freezeTarget(window.canonicalTarget),
180
+ requestedTargets: Object.freeze(window.requestedTargets.map(freezeTarget)),
181
+ lastReceipt: window.lastReceipt === null ? null : freezeReceipt(window.lastReceipt),
182
+ heldReceipt: window.heldReceipt === null ? null : freezeReceipt(window.heldReceipt),
183
+ recoveryReceipt: window.recoveryReceipt === null ? null : freezeReceipt(window.recoveryReceipt),
184
+ rollbackBaseline: window.rollbackBaseline === null ? null : freezeValueState(window.rollbackBaseline),
185
+ patchReceipt: window.patchReceipt === null ? null : freezePatchReceipt(window.patchReceipt),
186
+ });
187
+ }
188
+ };
189
+ exports.PropertyCommandWindowService = PropertyCommandWindowService;
190
+ exports.PropertyCommandWindowService = PropertyCommandWindowService = __decorate([
191
+ (0, common_1.Injectable)()
192
+ ], PropertyCommandWindowService);
193
+ const freezeTarget = (target) => Object.freeze({ ...target });
194
+ const freezeReceipt = (receipt) => Object.freeze({ ...receipt });
195
+ const freezePatchReceipt = (receipt) => Object.freeze({
196
+ baseline: freezeValueState(receipt.baseline),
197
+ optimisticState: freezeValueState(receipt.optimisticState),
198
+ });
199
+ const freezeValueState = (state) => Object.freeze(new property_value_state_model_1.PropertyValueState(state.value, state.lastUpdated, state.trend));
200
+ //# sourceMappingURL=property-command-window.service.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"property-command-window.service.js","sourceRoot":"","sources":["../../../../src/modules/devices/services/property-command-window.service.ts"],"names":[],"mappings":";;;;;;;;;AAAA,6CAAyC;AAEzC,2CAA4C;AAE5C,qFAA0E;AAG7D,QAAA,sCAAsC,GAAG,KAAK,CAAC;AA6ErD,IAAM,4BAA4B,GAAlC,MAAM,4BAA4B;IAAlC;QACW,YAAO,GAAG,IAAI,GAAG,EAAwC,CAAC;QAC1D,eAAU,GAAG,IAAI,GAAG,EAA0B,CAAC;IA4OjE,CAAC;IA1OA,IAAI,CAAC,KAAqC;QACzC,MAAM,GAAG,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC;QACvB,MAAM,mBAAmB,GAAG,KAAK,CAAC,eAAe,CAAC,UAAU,CAAC;QAC7D,MAAM,OAAO,GAAG,IAAI,CAAC,UAAU,CAAC,mBAAmB,EAAE,GAAG,CAAC,CAAC;QAC1D,MAAM,KAAK,GAAG,MAAM,CAAC,QAAQ,CAAC,KAAK,CAAC,KAAK,CAAC,IAAI,KAAK,CAAC,KAAK,GAAG,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC;QACpF,MAAM,UAAU,GAAG,IAAA,wBAAU,GAAE,CAAC;QAChC,MAAM,aAAa,GAAG,OAAO,EAAE,cAAc,IAAI,KAAK,CAAC,aAAa,CAAC;QACrE,IAAI,CAAC,UAAU,CAAC,MAAM,CAAC,mBAAmB,CAAC,CAAC;QAE5C,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,mBAAmB,EAAE;YACrC,eAAe,EAAE,YAAY,CAAC,KAAK,CAAC,eAAe,CAAC;YACpD,gBAAgB,EAAE,KAAK,CAAC,gBAAgB,CAAC,GAAG,CAAC,YAAY,CAAC;YAC1D,UAAU;YACV,QAAQ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CAAC,eAAe,CAAC;YAC/F,gBAAgB,EAAE,MAAM,CAAC,gBAAgB,KAAK,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,gBAAgB,CAAC,MAAM,CAAC,gBAAgB,CAAC;YACrG,YAAY,EAAE,MAAM,CAAC,YAAY,KAAK,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,kBAAkB,CAAC,MAAM,CAAC,YAAY,CAAC;SAC3F,CAAC,CAAC;IACJ,CAAC;CACD,CAAA;AA9OY,oEAA4B;uCAA5B,4BAA4B;IADxC,IAAA,mBAAU,GAAE;GACA,4BAA4B,CA8OxC;AAED,MAAM,YAAY,GAAG,CAAC,MAAmC,EAA+B,EAAE,CAAC,MAAM,CAAC,MAAM,CAAC,EAAE,GAAG,MAAM,EAAE,CAAC,CAAC;AAExH,MAAM,aAAa,GAAG,CAAC,OAA+B,EAA0B,EAAE,CAAC,MAAM,CAAC,MAAM,CAAC,EAAE,GAAG,OAAO,EAAE,CAAC,CAAC;AAEjH,MAAM,kBAAkB,GAAG,CAAC,OAAoC,EAA+B,EAAE,CAChG,MAAM,CAAC,MAAM,CAAC;IACb,QAAQ,EAAE,gBAAgB,CAAC,OAAO,CAAC,QAAQ,CAAC;IAC5C,eAAe,EAAE,gBAAgB,CAAC,OAAO,CAAC,eAAe,CAAC;CAC1D,CAAC,CAAC;AAEJ,MAAM,gBAAgB,GAAG,CAAC,KAAyB,EAAsB,EAAE,CAC1E,MAAM,CAAC,MAAM,CAAC,IAAI,+CAAkB,CAAC,KAAK,CAAC,KAAK,EAAE,KAAK,CAAC,WAAW,EAAE,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC"}
@@ -2,15 +2,26 @@ import { IntentContext } from '../../intents/models/intent.model';
2
2
  import { IntentsService } from '../../intents/services/intents.service';
3
3
  import { ClientUserDto } from '../../websocket/dto/client-user.dto';
4
4
  import { UpdateChannelPropertyDto } from '../dto/update-channel-property.dto';
5
- import { ChannelPropertyEntity, DeviceEntity } from '../entities/devices.entity';
5
+ import { ChannelEntity, ChannelPropertyEntity, DeviceEntity } from '../entities/devices.entity';
6
+ import { PropertyValueState } from '../models/property-value-state.model';
6
7
  import { PropertyCommandValue } from '../utils/property-command-value.utils';
7
8
  import { ChannelsPropertiesService } from './channels.properties.service';
8
9
  import { ChannelsService } from './channels.service';
9
10
  import { DevicesService } from './devices.service';
10
11
  import { PlatformRegistryService } from './platform.registry.service';
12
+ import { PropertyCommandDispatchService } from './property-command-dispatch.service';
13
+ import { PropertyCommandWindowHandle, PropertyCommandWindowService } from './property-command-window.service';
11
14
  export interface PropertyCommandExecutionOptions {
12
15
  requestId?: string;
13
16
  context?: IntentContext;
17
+ apiReceipt?: ApiPropertyCommandReceipt;
18
+ }
19
+ export interface ApiPropertyCommandReceipt {
20
+ readonly handle: PropertyCommandWindowHandle;
21
+ readonly canonicalPropertyId: string;
22
+ readonly baseline: PropertyValueState | null;
23
+ readonly optimisticEligible: boolean;
24
+ readonly ttlMs: number;
14
25
  }
15
26
  export interface DevicePropertyCommandResult {
16
27
  device: string;
@@ -33,8 +44,10 @@ export declare class PropertyCommandService {
33
44
  private readonly channelsPropertiesService;
34
45
  private readonly platformRegistryService;
35
46
  private readonly intentsService;
47
+ private readonly propertyCommandDispatchService;
48
+ private readonly propertyCommandWindowService;
36
49
  private readonly logger;
37
- constructor(devicesService: DevicesService, channelsService: ChannelsService, channelsPropertiesService: ChannelsPropertiesService, platformRegistryService: PlatformRegistryService, intentsService: IntentsService);
50
+ constructor(devicesService: DevicesService, channelsService: ChannelsService, channelsPropertiesService: ChannelsPropertiesService, platformRegistryService: PlatformRegistryService, intentsService: IntentsService, propertyCommandDispatchService: PropertyCommandDispatchService, propertyCommandWindowService: PropertyCommandWindowService);
38
51
  handleInternal(user: ClientUserDto, payload?: object): Promise<{
39
52
  success: boolean;
40
53
  results: Array<{
@@ -51,6 +64,8 @@ export declare class PropertyCommandService {
51
64
  private executeCommands;
52
65
  private resolveCommandIntentTtlMs;
53
66
  private processDeviceCommands;
54
- processApiPropertyCommand(deviceId: string, channelId: string, propertyId: string, value: string | number | boolean): Promise<void>;
67
+ processApiPropertyCommand(deviceId: string, channelId: string, propertyId: string, value: string | number | boolean, receipt?: ApiPropertyCommandReceipt): Promise<void>;
68
+ prepareApiPropertyCommand(device: DeviceEntity | string, channel: ChannelEntity, property: ChannelPropertyEntity, value: string | number | boolean): Promise<ApiPropertyCommandReceipt | null>;
69
+ failApiPropertyCommandReceipt(receipt: ApiPropertyCommandReceipt): void;
55
70
  usesAuthoritativePropertyReadback(device: DeviceEntity | string, property: ChannelPropertyEntity, update?: UpdateChannelPropertyDto): Promise<boolean>;
56
71
  }