nayota-show-sdk 1.3.87 → 1.3.89

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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nayota-show-sdk",
3
- "version": "1.3.87",
3
+ "version": "1.3.89",
4
4
  "description": "nayota-show-server rest-api",
5
5
  "type": "module",
6
6
  "main": "index.js",
@@ -257,6 +257,40 @@ function normalizeHierarchyField(data = {}, field) {
257
257
  return getNestedValue(data, `relationInfo.${field}`)
258
258
  }
259
259
 
260
+ function normalizeHierarchyFloorPlanForWrite(data = {}) {
261
+ const relationInfo = data.relationInfo
262
+ const hasLegacyImage = hasOwn(relationInfo, 'image')
263
+
264
+ if (hasLegacyImage) {
265
+ const image = relationInfo.image
266
+
267
+ if (image == null) {
268
+ return null
269
+ }
270
+
271
+ if (typeof image !== 'object') {
272
+ return image
273
+ }
274
+
275
+ const hasImagePath = Boolean(image.imagePath || image.url)
276
+ const hasDimensions = Number(image.width || 0) > 0 && Number(image.height || 0) > 0
277
+ const hasCorners = Array.isArray(image.corners) && image.corners.length > 0
278
+ const hasImageIdentity = Boolean(image.id)
279
+
280
+ if (!hasImagePath && !hasDimensions && !hasCorners && !hasImageIdentity) {
281
+ return null
282
+ }
283
+
284
+ return image
285
+ }
286
+
287
+ if (hasOwn(data, 'floorPlan')) {
288
+ return data.floorPlan
289
+ }
290
+
291
+ return undefined
292
+ }
293
+
260
294
  function normalizeLegacyHierarchyRelationInfo(item = {}) {
261
295
  const relationInfo = removeUndefinedFields({
262
296
  ...(item.relationInfo || {}),
@@ -314,7 +348,7 @@ function mapDepartsToIotBody(data = {}) {
314
348
  latlng: normalizeHierarchyField(data, 'latlng'),
315
349
  zooms: normalizeHierarchyField(data, 'zooms'),
316
350
  powers: normalizeHierarchyField(data, 'powers'),
317
- floorPlan: data.floorPlan,
351
+ floorPlan: normalizeHierarchyFloorPlanForWrite(data),
318
352
  metadata: Object.keys(metadata).length ? metadata : undefined
319
353
  })
320
354
  }
@@ -233,6 +233,47 @@ describe('iotModuleSpecs departs hierarchy compatibility', () => {
233
233
  expect(request.data.metadata).toEqual({ keep: 'value' })
234
234
  })
235
235
 
236
+ test('clears official floorPlan when legacy relationInfo image is explicitly removed', () => {
237
+ const request = departs.updateOne.toRequest({
238
+ _id: 'e245a3f6-d2c7-4ce1-9e02-ba9bbb347ed7',
239
+ floorPlan: {
240
+ imagePath: 'stale.svg',
241
+ width: 100,
242
+ height: 80
243
+ },
244
+ relationInfo: {
245
+ image: null
246
+ }
247
+ })
248
+
249
+ expect(request.data.relationInfo).toEqual({
250
+ image: null
251
+ })
252
+ expect(request.data.floorPlan).toBeNull()
253
+ })
254
+
255
+ test('clears official floorPlan when legacy relationInfo image is emptied by old BMS editor', () => {
256
+ const request = departs.updateOne.toRequest({
257
+ _id: 'e245a3f6-d2c7-4ce1-9e02-ba9bbb347ed7',
258
+ floorPlan: {
259
+ imagePath: 'stale.svg',
260
+ width: 100,
261
+ height: 80
262
+ },
263
+ relationInfo: {
264
+ image: {
265
+ imagePath: '',
266
+ width: 0,
267
+ height: 0,
268
+ zIndex: 0,
269
+ corners: []
270
+ }
271
+ }
272
+ })
273
+
274
+ expect(request.data.floorPlan).toBeNull()
275
+ })
276
+
236
277
  test('rebuilds legacy relationInfo from official hierarchy fields and ignores metadata fallbacks', () => {
237
278
  const response = departs.list.fromResponse({
238
279
  code: 0,