@one-commerce/sdk-backoffice-vue3 1.10.0 → 1.12.1-alpha.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.
@@ -61,6 +61,8 @@ exports.Errors = exports.Message = void 0;
61
61
  Message["METHOD_CALL_ERROR"] = "one:method:error";
62
62
  Message["METHOD_RESULT"] = "one:method:result";
63
63
  Message["NAVIGATION_PUSH"] = "one:navigation:push";
64
+ Message["FRAME_HEIGHT_REQUEST"] = "one:frameheight:request";
65
+ Message["FRAME_HEIGHT_CHANGE"] = "one:frameheight:change";
64
66
  })(exports.Message || (exports.Message = {}));
65
67
  (function (Errors) {
66
68
  Errors["METHOD_DOES_NOT_EXISTS"] = "Method does not exists";
@@ -169,6 +171,20 @@ class BackofficeUser extends BaseCallClass {
169
171
  _defineProperty$2(this, "authorities", void 0);
170
172
  }
171
173
 
174
+ }
175
+ class BackofficeTenant extends BaseCallClass {
176
+ constructor(...args) {
177
+ super(...args);
178
+
179
+ _defineProperty$2(this, "serviceName", 'tenant');
180
+
181
+ _defineProperty$2(this, "tenantKey", void 0);
182
+
183
+ _defineProperty$2(this, "language", void 0);
184
+
185
+ _defineProperty$2(this, "currency", void 0);
186
+ }
187
+
172
188
  }
173
189
  class BackofficeOrderpath extends BaseCallClass {
174
190
  constructor(...args) {
@@ -262,6 +278,10 @@ class Sdk extends Events {
262
278
 
263
279
  _defineProperty(this, "channel", void 0);
264
280
 
281
+ _defineProperty(this, "autoheight", true);
282
+
283
+ _defineProperty(this, "heightMutationObserver", null);
284
+
265
285
  _defineProperty(this, "origin", void 0);
266
286
 
267
287
  _defineProperty(this, "isInitialized", false);
@@ -297,18 +317,62 @@ class Sdk extends Events {
297
317
  Sdk.log('Emitting UPDATE with payload ', payload);
298
318
  this.emit(SdkInternalEvents.UPDATE, payload);
299
319
  });
320
+ this.channel.subscribe(main.Message.FRAME_HEIGHT_REQUEST, payload => {
321
+ if (this.autoheight) {
322
+ Sdk.log('Request for iframe height');
323
+ this.sendFrameHeight();
324
+ }
325
+ });
300
326
  this.channel.connect().then(() => {
301
327
  Sdk.log('Connected with ONe SDK');
328
+
329
+ if (this.autoheight) {
330
+ this.initializeHeightObserver();
331
+ }
302
332
  });
303
333
  this.setupOptions(options);
304
334
  Sdk.log('Initialized.');
305
335
  }
306
336
 
337
+ sendFrameHeight() {
338
+ const body = document.body,
339
+ html = document.documentElement;
340
+ const height = Math.max(body.scrollHeight, body.offsetHeight, html.clientHeight, html.scrollHeight, html.offsetHeight);
341
+ this.channel.postMessage(main.Message.FRAME_HEIGHT_CHANGE, height);
342
+ }
343
+
344
+ initializeHeightObserver() {
345
+ if ("MutationObserver" in window) {
346
+ const onMutationObserved = () => {
347
+ this.sendFrameHeight();
348
+ };
349
+
350
+ const target = document.querySelector('body'),
351
+ config = {
352
+ attributes: true,
353
+ attributeOldValue: false,
354
+ characterData: true,
355
+ characterDataOldValue: false,
356
+ childList: true,
357
+ subtree: true
358
+ };
359
+ this.heightMutationObserver = new MutationObserver(onMutationObserved);
360
+ Sdk.log('Create body MutationObserver');
361
+ this.heightMutationObserver.observe(target, config);
362
+ } else {
363
+ Sdk.warn('MutationObserver not available. Auto-height functionality disabled.');
364
+ }
365
+ }
366
+
307
367
  setupOptions(options) {
308
368
  if (options) {
309
369
  if (typeof options.debug !== 'undefined') {
310
370
  Sdk.debug = options.debug;
311
371
  }
372
+
373
+ if (typeof options.autoheight !== 'undefined') {
374
+ this.autoheight = options.autoheight;
375
+ }
312
376
  }
313
377
  }
314
378
 
@@ -359,6 +423,7 @@ class BackofficeSdk extends Sdk {
359
423
  orderpath: new BackofficeOrderpath(this.callFunction.bind(this)),
360
424
  catalog: new BackofficeCatalog(this.callFunction.bind(this)),
361
425
  user: new BackofficeUser(this.callFunction.bind(this)),
426
+ tenant: new BackofficeTenant(this.callFunction.bind(this)),
362
427
  layout: new BackofficeLayout(this.callFunction.bind(this))
363
428
  });
364
429
  }
@@ -393,6 +458,7 @@ var index = {
393
458
  var updateInstances = function updateInstances(payload) {
394
459
  obj.route = payload.route;
395
460
  obj.user.update(payload);
461
+ obj.tenant.update(payload);
396
462
  obj.layout.update(payload);
397
463
  obj.catalog.update(payload);
398
464
  obj.orderpath.update(payload);