@luzmo/embed 5.0.11 → 5.0.12

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/CHANGELOG.md CHANGED
@@ -1,6 +1,12 @@
1
1
 
2
2
  All notable changes to this project will be documented in this file.
3
3
 
4
+ ## [5.0.12] - 2024-03-19
5
+
6
+ ### Bugfixes
7
+
8
+ - Fixed getAccessibleDashboards() to correctly work with embed tokens.
9
+
4
10
  ## [5.0.11] - 2024-03-18
5
11
 
6
12
  ### Updates
package/index.cjs CHANGED
@@ -54,7 +54,7 @@ var import_style_map = require("lit/directives/style-map.js");
54
54
  var import_shared_embed = require("@luzmo/shared-embed");
55
55
 
56
56
  // libs/embed-libs/embed/package.json
57
- var version = "5.0.11";
57
+ var version = "5.0.12";
58
58
 
59
59
  // libs/embed-libs/embed/src/lib/luzmo-service.ts
60
60
  var LuzmoService = class {
@@ -356,6 +356,8 @@ var LuzmoDashboard = class extends import_lit2.LitElement {
356
356
  this.browserNotSupported = [];
357
357
  this.VERSION = version + "-wc-luzmo";
358
358
  this.isLibraryLoaded = false;
359
+ this.currentAuthKey = null;
360
+ this.currentAuthToken = null;
359
361
  this.attributesMap = {
360
362
  dashboardId: "dashboard-id",
361
363
  dashboardSlug: "dashboard-slug",
@@ -503,11 +505,10 @@ var LuzmoDashboard = class extends import_lit2.LitElement {
503
505
  this.dashboardReference = oldReference.cloneNode(true);
504
506
  oldReference.replaceWith(this.dashboardReference);
505
507
  this.dashboardReference.addEventListener("load", (payload) => {
506
- setTimeout(() => {
507
- this.containerWidth = this.dashboardReference.offsetWidth;
508
- this.dimensions = payload.detail.dimensions;
509
- SharedLib2._setCalculatedDimensions(this);
510
- });
508
+ this.containerWidth = this.dashboardReference.offsetWidth;
509
+ this.dimensions = payload.detail.dimensions;
510
+ SharedLib2._setCalculatedDimensions(this);
511
+ window.dispatchEvent(new Event("resize"));
511
512
  this.dispatchEvent(new CustomEvent("load", payload));
512
513
  });
513
514
  this.dashboardReference.addEventListener("itemsRendered", (payload) => this.dispatchEvent(new CustomEvent("itemsRendered", payload)));
@@ -687,6 +688,8 @@ var LuzmoDashboard = class extends import_lit2.LitElement {
687
688
  this.apiHost = this.appServer.includes("luzmo.com") ? this.appServer.replace("app", "api") : this.appServer;
688
689
  defaultParameters.apiHost = this.apiHost;
689
690
  }
691
+ this.currentAuthKey = this.authKey;
692
+ this.currentAuthToken = this.authToken;
690
693
  return defaultParameters;
691
694
  }
692
695
  _updateIframeUrl() {
@@ -843,6 +846,8 @@ var LuzmoDashboard = class extends import_lit2.LitElement {
843
846
  return Promise.reject();
844
847
  }
845
848
  setAuthorization(key, token) {
849
+ this.currentAuthKey = key;
850
+ this.currentAuthToken = token;
846
851
  if (this.getIsViewMode() && this.dashboardReference) {
847
852
  return this.dashboardReference.setAuthorization(key, token);
848
853
  }
@@ -879,13 +884,7 @@ var LuzmoDashboard = class extends import_lit2.LitElement {
879
884
  return Promise.reject();
880
885
  }
881
886
  getAccessibleDashboards() {
882
- if (!this.getIsViewMode()) {
883
- return SharedLib2.getAccessibleDashboards(this, this.iframe);
884
- }
885
- if (this.getIsViewMode() && this.dashboardReference) {
886
- return this.dashboardReference.getAccessibleDashboards();
887
- }
888
- return Promise.reject();
887
+ return SharedLib2.getAccessibleDashboards(this);
889
888
  }
890
889
  addFilters(itemId, filters) {
891
890
  return this.dashboardReference.addFilters(itemId, filters);
@@ -1081,6 +1080,12 @@ __decorateClass([
1081
1080
  __decorateClass([
1082
1081
  (0, import_decorators.state)()
1083
1082
  ], LuzmoDashboard.prototype, "dashboardReference", 2);
1083
+ __decorateClass([
1084
+ (0, import_decorators.state)()
1085
+ ], LuzmoDashboard.prototype, "currentAuthKey", 2);
1086
+ __decorateClass([
1087
+ (0, import_decorators.state)()
1088
+ ], LuzmoDashboard.prototype, "currentAuthToken", 2);
1084
1089
 
1085
1090
  // libs/embed-libs/embed/src/lib/dashboard-component/dashboard-component.ts
1086
1091
  var LuzmoDashboard2 = class extends LuzmoDashboard {
package/index.js CHANGED
@@ -37,7 +37,7 @@ import {
37
37
  } from "@luzmo/shared-embed";
38
38
 
39
39
  // libs/embed-libs/embed/package.json
40
- var version = "5.0.11";
40
+ var version = "5.0.12";
41
41
 
42
42
  // libs/embed-libs/embed/src/lib/luzmo-service.ts
43
43
  var LuzmoService = class {
@@ -339,6 +339,8 @@ var LuzmoDashboard = class extends LitElement {
339
339
  this.browserNotSupported = [];
340
340
  this.VERSION = version + "-wc-luzmo";
341
341
  this.isLibraryLoaded = false;
342
+ this.currentAuthKey = null;
343
+ this.currentAuthToken = null;
342
344
  this.attributesMap = {
343
345
  dashboardId: "dashboard-id",
344
346
  dashboardSlug: "dashboard-slug",
@@ -486,11 +488,10 @@ var LuzmoDashboard = class extends LitElement {
486
488
  this.dashboardReference = oldReference.cloneNode(true);
487
489
  oldReference.replaceWith(this.dashboardReference);
488
490
  this.dashboardReference.addEventListener("load", (payload) => {
489
- setTimeout(() => {
490
- this.containerWidth = this.dashboardReference.offsetWidth;
491
- this.dimensions = payload.detail.dimensions;
492
- SharedLib2._setCalculatedDimensions(this);
493
- });
491
+ this.containerWidth = this.dashboardReference.offsetWidth;
492
+ this.dimensions = payload.detail.dimensions;
493
+ SharedLib2._setCalculatedDimensions(this);
494
+ window.dispatchEvent(new Event("resize"));
494
495
  this.dispatchEvent(new CustomEvent("load", payload));
495
496
  });
496
497
  this.dashboardReference.addEventListener("itemsRendered", (payload) => this.dispatchEvent(new CustomEvent("itemsRendered", payload)));
@@ -670,6 +671,8 @@ var LuzmoDashboard = class extends LitElement {
670
671
  this.apiHost = this.appServer.includes("luzmo.com") ? this.appServer.replace("app", "api") : this.appServer;
671
672
  defaultParameters.apiHost = this.apiHost;
672
673
  }
674
+ this.currentAuthKey = this.authKey;
675
+ this.currentAuthToken = this.authToken;
673
676
  return defaultParameters;
674
677
  }
675
678
  _updateIframeUrl() {
@@ -826,6 +829,8 @@ var LuzmoDashboard = class extends LitElement {
826
829
  return Promise.reject();
827
830
  }
828
831
  setAuthorization(key, token) {
832
+ this.currentAuthKey = key;
833
+ this.currentAuthToken = token;
829
834
  if (this.getIsViewMode() && this.dashboardReference) {
830
835
  return this.dashboardReference.setAuthorization(key, token);
831
836
  }
@@ -862,13 +867,7 @@ var LuzmoDashboard = class extends LitElement {
862
867
  return Promise.reject();
863
868
  }
864
869
  getAccessibleDashboards() {
865
- if (!this.getIsViewMode()) {
866
- return SharedLib2.getAccessibleDashboards(this, this.iframe);
867
- }
868
- if (this.getIsViewMode() && this.dashboardReference) {
869
- return this.dashboardReference.getAccessibleDashboards();
870
- }
871
- return Promise.reject();
870
+ return SharedLib2.getAccessibleDashboards(this);
872
871
  }
873
872
  addFilters(itemId, filters) {
874
873
  return this.dashboardReference.addFilters(itemId, filters);
@@ -1064,6 +1063,12 @@ __decorateClass([
1064
1063
  __decorateClass([
1065
1064
  state()
1066
1065
  ], LuzmoDashboard.prototype, "dashboardReference", 2);
1066
+ __decorateClass([
1067
+ state()
1068
+ ], LuzmoDashboard.prototype, "currentAuthKey", 2);
1069
+ __decorateClass([
1070
+ state()
1071
+ ], LuzmoDashboard.prototype, "currentAuthToken", 2);
1067
1072
 
1068
1073
  // libs/embed-libs/embed/src/lib/dashboard-component/dashboard-component.ts
1069
1074
  var LuzmoDashboard2 = class extends LuzmoDashboard {
@@ -54,6 +54,8 @@ export declare class LuzmoDashboard extends LitElement implements SharedLib.ES6L
54
54
  VERSION: string;
55
55
  protected isLibraryLoaded: boolean;
56
56
  protected dashboardReference: SharedLib.LuzmoElement;
57
+ currentAuthKey: string;
58
+ currentAuthToken: string;
57
59
  private attributesMap;
58
60
  _loadTimeoutHandle?: number;
59
61
  _onResize: () => void;
@@ -912,128 +912,108 @@ var exportDashboard = (dashboardComponent, iframe, format) => {
912
912
  };
913
913
 
914
914
  // libs/embed-libs/shared-embed/src/lib/methods/get-accessible-dashboards.ts
915
- var getAccessibleDashboards = (dashboardComponent, iframe) => {
916
- if ((dashboardComponent.dashboardId || dashboardComponent.dashboardSlug) && iframe?.contentWindow) {
917
- const requestId = uuidv4();
918
- iframe.contentWindow.postMessage(
919
- {
920
- action: "getAccessibleDashboards",
921
- _version: dashboardComponent.VERSION,
922
- requestId
923
- },
924
- "*"
925
- );
926
- return new Promise((resolve, reject) => {
927
- dashboardComponent.promises[requestId] = { resolve, reject };
928
- setTimeout(() => {
929
- if (dashboardComponent.promises[requestId]) {
930
- const errorMessage = "getAccessibleDashboards request timed out.";
931
- dashboardComponent.promises[requestId].reject(
932
- new Error(errorMessage)
915
+ var getAccessibleDashboards = (dashboardComponent) => {
916
+ if ((dashboardComponent.currentAuthKey ?? dashboardComponent.authKey) && (dashboardComponent.currentAuthToken ?? dashboardComponent.authToken)) {
917
+ const fetchUser = new Promise((resolve, reject) => {
918
+ void (() => {
919
+ try {
920
+ const responsePromise = window.fetch(
921
+ `${String(dashboardComponent.params.apiHost)}0.1.0/authorization`,
922
+ {
923
+ method: "POST",
924
+ mode: "cors",
925
+ cache: "no-cache",
926
+ headers: { "Content-Type": "application/json" },
927
+ redirect: "follow",
928
+ body: JSON.stringify({
929
+ action: "get",
930
+ version: "0.1.0",
931
+ key: dashboardComponent.currentAuthKey ?? dashboardComponent.authKey,
932
+ token: dashboardComponent.currentAuthToken ?? dashboardComponent.authToken,
933
+ find: {
934
+ where: { id: dashboardComponent.authKey },
935
+ attributes: ["id", "integration_id"],
936
+ include: [
937
+ {
938
+ model: "User",
939
+ attributes: ["id", "name", "locale_id"],
940
+ include: [{ model: "Group" }]
941
+ }
942
+ ]
943
+ }
944
+ })
945
+ }
933
946
  );
934
- delete dashboardComponent.promises[requestId];
947
+ responsePromise.then((response) => response.json()).then((data) => {
948
+ if (!data || !data.rows || data.rows.length === 0 || !data.rows[0].user) {
949
+ reject("Authorization failed, please check authKey and authToken. If the problem persists, please contact support@luzmo.com.");
950
+ } else {
951
+ data.rows[0].user.userGroups = data.rows[0].user.groups.map(
952
+ (group) => group.id
953
+ );
954
+ delete data.rows[0].user.groups;
955
+ resolve({
956
+ integrationId: data.rows[0].integration_id,
957
+ user: data.rows[0].user
958
+ });
959
+ }
960
+ });
961
+ } catch (error) {
962
+ reject(error);
935
963
  }
936
- }, 2e3);
964
+ })();
937
965
  });
938
- }
939
- const fetchUser = new Promise((resolve, reject) => {
940
- void (() => {
966
+ return new Promise((resolve, reject) => void (() => {
941
967
  try {
942
- const responsePromise = window.fetch(
943
- `${String(dashboardComponent.params.apiHost)}0.1.0/authorization`,
944
- {
945
- method: "POST",
946
- mode: "cors",
947
- cache: "no-cache",
948
- headers: { "Content-Type": "application/json" },
949
- redirect: "follow",
950
- body: JSON.stringify({
951
- action: "get",
952
- version: "0.1.0",
953
- key: dashboardComponent.authKey,
954
- token: dashboardComponent.authToken,
955
- find: {
956
- where: { id: dashboardComponent.authKey },
957
- attributes: ["id", "integration_id"],
958
- include: [
959
- {
960
- model: "User",
961
- attributes: ["id", "name", "locale_id"],
962
- include: [{ model: "Group" }]
963
- }
964
- ]
965
- }
966
- })
967
- }
968
- );
969
- responsePromise.then((response) => response.json()).then((data) => {
970
- if (!data || !data.rows || data.rows.length === 0 || !data.rows[0].user || !data.rows[0].integration_id) {
971
- reject();
972
- } else {
973
- data.rows[0].user.userGroups = data.rows[0].user.groups.map(
974
- (group) => group.id
975
- );
976
- delete data.rows[0].user.groups;
977
- resolve({
978
- integrationId: data.rows[0].integration_id,
979
- user: data.rows[0].user
980
- });
981
- }
968
+ fetchUser.then((authorizationData) => {
969
+ const responsePromise = window.fetch(
970
+ `${String(dashboardComponent.params.apiHost)}0.1.0/securable`,
971
+ {
972
+ method: "POST",
973
+ mode: "cors",
974
+ cache: "no-cache",
975
+ headers: { "Content-Type": "application/json" },
976
+ redirect: "follow",
977
+ body: JSON.stringify({
978
+ action: "get",
979
+ version: "0.1.0",
980
+ key: dashboardComponent.currentAuthKey ?? dashboardComponent.authKey,
981
+ token: dashboardComponent.currentAuthToken ?? dashboardComponent.authToken,
982
+ find: {
983
+ where: { type: "dashboard", is_variant: false },
984
+ attributes: ["id", "name", "modified_at"],
985
+ order: [["modified_at", "desc"]],
986
+ include: [
987
+ { model: "Tag", attributes: ["tag"] },
988
+ { model: "User", attributes: ["id", "name"] },
989
+ {
990
+ model: "Group",
991
+ attributes: ["id", "name", "public"]
992
+ },
993
+ { model: "Integration", attributes: ["id", "name"] }
994
+ ]
995
+ }
996
+ })
997
+ }
998
+ );
999
+ responsePromise.then((response) => response.json()).then((data) => {
1000
+ const dashboardList = data.rows.length > 0 ? formatDashboardList(
1001
+ data.rows,
1002
+ authorizationData.integrationId,
1003
+ authorizationData.user,
1004
+ dashboardComponent
1005
+ ) : [];
1006
+ resolve(dashboardList);
1007
+ });
1008
+ }).catch((error) => {
1009
+ reject(error);
982
1010
  });
983
1011
  } catch (error) {
984
1012
  reject(error);
985
1013
  }
986
- })();
987
- });
988
- return new Promise((resolve, reject) => void (() => {
989
- try {
990
- fetchUser.then((authorizationData) => {
991
- const responsePromise = window.fetch(
992
- `${String(dashboardComponent.params.apiHost)}0.1.0/securable`,
993
- {
994
- method: "POST",
995
- mode: "cors",
996
- cache: "no-cache",
997
- headers: { "Content-Type": "application/json" },
998
- redirect: "follow",
999
- body: JSON.stringify({
1000
- action: "get",
1001
- version: "0.1.0",
1002
- key: dashboardComponent.authKey,
1003
- token: dashboardComponent.authToken,
1004
- find: {
1005
- where: { type: "dashboard", is_variant: false },
1006
- attributes: ["id", "name", "modified_at"],
1007
- order: [["modified_at", "desc"]],
1008
- include: [
1009
- { model: "Tag", attributes: ["tag"] },
1010
- { model: "User", attributes: ["id", "name"] },
1011
- {
1012
- model: "Group",
1013
- attributes: ["id", "name", "public"]
1014
- },
1015
- { model: "Integration", attributes: ["id", "name"] }
1016
- ]
1017
- }
1018
- })
1019
- }
1020
- );
1021
- responsePromise.then((response) => response.json()).then((data) => {
1022
- const dashboardList = data.rows.length > 0 ? formatDashboardList(
1023
- data.rows,
1024
- authorizationData.integrationId,
1025
- authorizationData.user,
1026
- dashboardComponent
1027
- ) : [];
1028
- resolve(dashboardList);
1029
- });
1030
- }).catch((error) => {
1031
- reject(error);
1032
- });
1033
- } catch (error) {
1034
- reject(error);
1035
- }
1036
- })());
1014
+ })());
1015
+ }
1016
+ throw new Error("No authKey or authToken found in the luzmo-dashboard component.");
1037
1017
  };
1038
1018
 
1039
1019
  // libs/embed-libs/shared-embed/src/lib/methods/get-data.ts
@@ -1922,7 +1902,7 @@ var o5 = e6(class extends i4 {
1922
1902
  });
1923
1903
 
1924
1904
  // libs/embed-libs/embed/package.json
1925
- var version = "5.0.11";
1905
+ var version = "5.0.12";
1926
1906
 
1927
1907
  // libs/embed-libs/embed/src/lib/luzmo-service.ts
1928
1908
  var LuzmoService = class {
@@ -2222,6 +2202,8 @@ var LuzmoDashboard = class extends s3 {
2222
2202
  this.browserNotSupported = [];
2223
2203
  this.VERSION = version + "-wc-luzmo";
2224
2204
  this.isLibraryLoaded = false;
2205
+ this.currentAuthKey = null;
2206
+ this.currentAuthToken = null;
2225
2207
  this.attributesMap = {
2226
2208
  dashboardId: "dashboard-id",
2227
2209
  dashboardSlug: "dashboard-slug",
@@ -2369,11 +2351,10 @@ var LuzmoDashboard = class extends s3 {
2369
2351
  this.dashboardReference = oldReference.cloneNode(true);
2370
2352
  oldReference.replaceWith(this.dashboardReference);
2371
2353
  this.dashboardReference.addEventListener("load", (payload) => {
2372
- setTimeout(() => {
2373
- this.containerWidth = this.dashboardReference.offsetWidth;
2374
- this.dimensions = payload.detail.dimensions;
2375
- _setCalculatedDimensions(this);
2376
- });
2354
+ this.containerWidth = this.dashboardReference.offsetWidth;
2355
+ this.dimensions = payload.detail.dimensions;
2356
+ _setCalculatedDimensions(this);
2357
+ window.dispatchEvent(new Event("resize"));
2377
2358
  this.dispatchEvent(new CustomEvent("load", payload));
2378
2359
  });
2379
2360
  this.dashboardReference.addEventListener("itemsRendered", (payload) => this.dispatchEvent(new CustomEvent("itemsRendered", payload)));
@@ -2553,6 +2534,8 @@ var LuzmoDashboard = class extends s3 {
2553
2534
  this.apiHost = this.appServer.includes("luzmo.com") ? this.appServer.replace("app", "api") : this.appServer;
2554
2535
  defaultParameters.apiHost = this.apiHost;
2555
2536
  }
2537
+ this.currentAuthKey = this.authKey;
2538
+ this.currentAuthToken = this.authToken;
2556
2539
  return defaultParameters;
2557
2540
  }
2558
2541
  _updateIframeUrl() {
@@ -2709,6 +2692,8 @@ var LuzmoDashboard = class extends s3 {
2709
2692
  return Promise.reject();
2710
2693
  }
2711
2694
  setAuthorization(key, token) {
2695
+ this.currentAuthKey = key;
2696
+ this.currentAuthToken = token;
2712
2697
  if (this.getIsViewMode() && this.dashboardReference) {
2713
2698
  return this.dashboardReference.setAuthorization(key, token);
2714
2699
  }
@@ -2745,13 +2730,7 @@ var LuzmoDashboard = class extends s3 {
2745
2730
  return Promise.reject();
2746
2731
  }
2747
2732
  getAccessibleDashboards() {
2748
- if (!this.getIsViewMode()) {
2749
- return getAccessibleDashboards(this, this.iframe);
2750
- }
2751
- if (this.getIsViewMode() && this.dashboardReference) {
2752
- return this.dashboardReference.getAccessibleDashboards();
2753
- }
2754
- return Promise.reject();
2733
+ return getAccessibleDashboards(this);
2755
2734
  }
2756
2735
  addFilters(itemId, filters) {
2757
2736
  return this.dashboardReference.addFilters(itemId, filters);
@@ -2947,6 +2926,12 @@ __decorateClass([
2947
2926
  __decorateClass([
2948
2927
  r4()
2949
2928
  ], LuzmoDashboard.prototype, "dashboardReference", 2);
2929
+ __decorateClass([
2930
+ r4()
2931
+ ], LuzmoDashboard.prototype, "currentAuthKey", 2);
2932
+ __decorateClass([
2933
+ r4()
2934
+ ], LuzmoDashboard.prototype, "currentAuthToken", 2);
2950
2935
 
2951
2936
  // libs/embed-libs/embed/src/lib/dashboard-component/dashboard-web-component.ts
2952
2937
  var LuzmoDashboardWebComponent = class extends LuzmoDashboard {
@@ -912,128 +912,108 @@ var exportDashboard = (dashboardComponent, iframe, format) => {
912
912
  };
913
913
 
914
914
  // libs/embed-libs/shared-embed/src/lib/methods/get-accessible-dashboards.ts
915
- var getAccessibleDashboards = (dashboardComponent, iframe) => {
916
- if ((dashboardComponent.dashboardId || dashboardComponent.dashboardSlug) && iframe?.contentWindow) {
917
- const requestId = uuidv4();
918
- iframe.contentWindow.postMessage(
919
- {
920
- action: "getAccessibleDashboards",
921
- _version: dashboardComponent.VERSION,
922
- requestId
923
- },
924
- "*"
925
- );
926
- return new Promise((resolve, reject) => {
927
- dashboardComponent.promises[requestId] = { resolve, reject };
928
- setTimeout(() => {
929
- if (dashboardComponent.promises[requestId]) {
930
- const errorMessage = "getAccessibleDashboards request timed out.";
931
- dashboardComponent.promises[requestId].reject(
932
- new Error(errorMessage)
915
+ var getAccessibleDashboards = (dashboardComponent) => {
916
+ if ((dashboardComponent.currentAuthKey ?? dashboardComponent.authKey) && (dashboardComponent.currentAuthToken ?? dashboardComponent.authToken)) {
917
+ const fetchUser = new Promise((resolve, reject) => {
918
+ void (() => {
919
+ try {
920
+ const responsePromise = window.fetch(
921
+ `${String(dashboardComponent.params.apiHost)}0.1.0/authorization`,
922
+ {
923
+ method: "POST",
924
+ mode: "cors",
925
+ cache: "no-cache",
926
+ headers: { "Content-Type": "application/json" },
927
+ redirect: "follow",
928
+ body: JSON.stringify({
929
+ action: "get",
930
+ version: "0.1.0",
931
+ key: dashboardComponent.currentAuthKey ?? dashboardComponent.authKey,
932
+ token: dashboardComponent.currentAuthToken ?? dashboardComponent.authToken,
933
+ find: {
934
+ where: { id: dashboardComponent.authKey },
935
+ attributes: ["id", "integration_id"],
936
+ include: [
937
+ {
938
+ model: "User",
939
+ attributes: ["id", "name", "locale_id"],
940
+ include: [{ model: "Group" }]
941
+ }
942
+ ]
943
+ }
944
+ })
945
+ }
933
946
  );
934
- delete dashboardComponent.promises[requestId];
947
+ responsePromise.then((response) => response.json()).then((data) => {
948
+ if (!data || !data.rows || data.rows.length === 0 || !data.rows[0].user) {
949
+ reject("Authorization failed, please check authKey and authToken. If the problem persists, please contact support@luzmo.com.");
950
+ } else {
951
+ data.rows[0].user.userGroups = data.rows[0].user.groups.map(
952
+ (group) => group.id
953
+ );
954
+ delete data.rows[0].user.groups;
955
+ resolve({
956
+ integrationId: data.rows[0].integration_id,
957
+ user: data.rows[0].user
958
+ });
959
+ }
960
+ });
961
+ } catch (error) {
962
+ reject(error);
935
963
  }
936
- }, 2e3);
964
+ })();
937
965
  });
938
- }
939
- const fetchUser = new Promise((resolve, reject) => {
940
- void (() => {
966
+ return new Promise((resolve, reject) => void (() => {
941
967
  try {
942
- const responsePromise = window.fetch(
943
- `${String(dashboardComponent.params.apiHost)}0.1.0/authorization`,
944
- {
945
- method: "POST",
946
- mode: "cors",
947
- cache: "no-cache",
948
- headers: { "Content-Type": "application/json" },
949
- redirect: "follow",
950
- body: JSON.stringify({
951
- action: "get",
952
- version: "0.1.0",
953
- key: dashboardComponent.authKey,
954
- token: dashboardComponent.authToken,
955
- find: {
956
- where: { id: dashboardComponent.authKey },
957
- attributes: ["id", "integration_id"],
958
- include: [
959
- {
960
- model: "User",
961
- attributes: ["id", "name", "locale_id"],
962
- include: [{ model: "Group" }]
963
- }
964
- ]
965
- }
966
- })
967
- }
968
- );
969
- responsePromise.then((response) => response.json()).then((data) => {
970
- if (!data || !data.rows || data.rows.length === 0 || !data.rows[0].user || !data.rows[0].integration_id) {
971
- reject();
972
- } else {
973
- data.rows[0].user.userGroups = data.rows[0].user.groups.map(
974
- (group) => group.id
975
- );
976
- delete data.rows[0].user.groups;
977
- resolve({
978
- integrationId: data.rows[0].integration_id,
979
- user: data.rows[0].user
980
- });
981
- }
968
+ fetchUser.then((authorizationData) => {
969
+ const responsePromise = window.fetch(
970
+ `${String(dashboardComponent.params.apiHost)}0.1.0/securable`,
971
+ {
972
+ method: "POST",
973
+ mode: "cors",
974
+ cache: "no-cache",
975
+ headers: { "Content-Type": "application/json" },
976
+ redirect: "follow",
977
+ body: JSON.stringify({
978
+ action: "get",
979
+ version: "0.1.0",
980
+ key: dashboardComponent.currentAuthKey ?? dashboardComponent.authKey,
981
+ token: dashboardComponent.currentAuthToken ?? dashboardComponent.authToken,
982
+ find: {
983
+ where: { type: "dashboard", is_variant: false },
984
+ attributes: ["id", "name", "modified_at"],
985
+ order: [["modified_at", "desc"]],
986
+ include: [
987
+ { model: "Tag", attributes: ["tag"] },
988
+ { model: "User", attributes: ["id", "name"] },
989
+ {
990
+ model: "Group",
991
+ attributes: ["id", "name", "public"]
992
+ },
993
+ { model: "Integration", attributes: ["id", "name"] }
994
+ ]
995
+ }
996
+ })
997
+ }
998
+ );
999
+ responsePromise.then((response) => response.json()).then((data) => {
1000
+ const dashboardList = data.rows.length > 0 ? formatDashboardList(
1001
+ data.rows,
1002
+ authorizationData.integrationId,
1003
+ authorizationData.user,
1004
+ dashboardComponent
1005
+ ) : [];
1006
+ resolve(dashboardList);
1007
+ });
1008
+ }).catch((error) => {
1009
+ reject(error);
982
1010
  });
983
1011
  } catch (error) {
984
1012
  reject(error);
985
1013
  }
986
- })();
987
- });
988
- return new Promise((resolve, reject) => void (() => {
989
- try {
990
- fetchUser.then((authorizationData) => {
991
- const responsePromise = window.fetch(
992
- `${String(dashboardComponent.params.apiHost)}0.1.0/securable`,
993
- {
994
- method: "POST",
995
- mode: "cors",
996
- cache: "no-cache",
997
- headers: { "Content-Type": "application/json" },
998
- redirect: "follow",
999
- body: JSON.stringify({
1000
- action: "get",
1001
- version: "0.1.0",
1002
- key: dashboardComponent.authKey,
1003
- token: dashboardComponent.authToken,
1004
- find: {
1005
- where: { type: "dashboard", is_variant: false },
1006
- attributes: ["id", "name", "modified_at"],
1007
- order: [["modified_at", "desc"]],
1008
- include: [
1009
- { model: "Tag", attributes: ["tag"] },
1010
- { model: "User", attributes: ["id", "name"] },
1011
- {
1012
- model: "Group",
1013
- attributes: ["id", "name", "public"]
1014
- },
1015
- { model: "Integration", attributes: ["id", "name"] }
1016
- ]
1017
- }
1018
- })
1019
- }
1020
- );
1021
- responsePromise.then((response) => response.json()).then((data) => {
1022
- const dashboardList = data.rows.length > 0 ? formatDashboardList(
1023
- data.rows,
1024
- authorizationData.integrationId,
1025
- authorizationData.user,
1026
- dashboardComponent
1027
- ) : [];
1028
- resolve(dashboardList);
1029
- });
1030
- }).catch((error) => {
1031
- reject(error);
1032
- });
1033
- } catch (error) {
1034
- reject(error);
1035
- }
1036
- })());
1014
+ })());
1015
+ }
1016
+ throw new Error("No authKey or authToken found in the luzmo-dashboard component.");
1037
1017
  };
1038
1018
 
1039
1019
  // libs/embed-libs/shared-embed/src/lib/methods/get-data.ts
@@ -1922,7 +1902,7 @@ var o5 = e6(class extends i4 {
1922
1902
  });
1923
1903
 
1924
1904
  // libs/embed-libs/embed/package.json
1925
- var version = "5.0.11";
1905
+ var version = "5.0.12";
1926
1906
 
1927
1907
  // libs/embed-libs/embed/src/lib/luzmo-service.ts
1928
1908
  var LuzmoService = class {
@@ -2222,6 +2202,8 @@ var LuzmoDashboard = class extends s3 {
2222
2202
  this.browserNotSupported = [];
2223
2203
  this.VERSION = version + "-wc-luzmo";
2224
2204
  this.isLibraryLoaded = false;
2205
+ this.currentAuthKey = null;
2206
+ this.currentAuthToken = null;
2225
2207
  this.attributesMap = {
2226
2208
  dashboardId: "dashboard-id",
2227
2209
  dashboardSlug: "dashboard-slug",
@@ -2369,11 +2351,10 @@ var LuzmoDashboard = class extends s3 {
2369
2351
  this.dashboardReference = oldReference.cloneNode(true);
2370
2352
  oldReference.replaceWith(this.dashboardReference);
2371
2353
  this.dashboardReference.addEventListener("load", (payload) => {
2372
- setTimeout(() => {
2373
- this.containerWidth = this.dashboardReference.offsetWidth;
2374
- this.dimensions = payload.detail.dimensions;
2375
- _setCalculatedDimensions(this);
2376
- });
2354
+ this.containerWidth = this.dashboardReference.offsetWidth;
2355
+ this.dimensions = payload.detail.dimensions;
2356
+ _setCalculatedDimensions(this);
2357
+ window.dispatchEvent(new Event("resize"));
2377
2358
  this.dispatchEvent(new CustomEvent("load", payload));
2378
2359
  });
2379
2360
  this.dashboardReference.addEventListener("itemsRendered", (payload) => this.dispatchEvent(new CustomEvent("itemsRendered", payload)));
@@ -2553,6 +2534,8 @@ var LuzmoDashboard = class extends s3 {
2553
2534
  this.apiHost = this.appServer.includes("luzmo.com") ? this.appServer.replace("app", "api") : this.appServer;
2554
2535
  defaultParameters.apiHost = this.apiHost;
2555
2536
  }
2537
+ this.currentAuthKey = this.authKey;
2538
+ this.currentAuthToken = this.authToken;
2556
2539
  return defaultParameters;
2557
2540
  }
2558
2541
  _updateIframeUrl() {
@@ -2709,6 +2692,8 @@ var LuzmoDashboard = class extends s3 {
2709
2692
  return Promise.reject();
2710
2693
  }
2711
2694
  setAuthorization(key, token) {
2695
+ this.currentAuthKey = key;
2696
+ this.currentAuthToken = token;
2712
2697
  if (this.getIsViewMode() && this.dashboardReference) {
2713
2698
  return this.dashboardReference.setAuthorization(key, token);
2714
2699
  }
@@ -2745,13 +2730,7 @@ var LuzmoDashboard = class extends s3 {
2745
2730
  return Promise.reject();
2746
2731
  }
2747
2732
  getAccessibleDashboards() {
2748
- if (!this.getIsViewMode()) {
2749
- return getAccessibleDashboards(this, this.iframe);
2750
- }
2751
- if (this.getIsViewMode() && this.dashboardReference) {
2752
- return this.dashboardReference.getAccessibleDashboards();
2753
- }
2754
- return Promise.reject();
2733
+ return getAccessibleDashboards(this);
2755
2734
  }
2756
2735
  addFilters(itemId, filters) {
2757
2736
  return this.dashboardReference.addFilters(itemId, filters);
@@ -2947,6 +2926,12 @@ __decorateClass([
2947
2926
  __decorateClass([
2948
2927
  r4()
2949
2928
  ], LuzmoDashboard.prototype, "dashboardReference", 2);
2929
+ __decorateClass([
2930
+ r4()
2931
+ ], LuzmoDashboard.prototype, "currentAuthKey", 2);
2932
+ __decorateClass([
2933
+ r4()
2934
+ ], LuzmoDashboard.prototype, "currentAuthToken", 2);
2950
2935
 
2951
2936
  // libs/embed-libs/embed/src/lib/dashboard-component/dashboard-component.ts
2952
2937
  var LuzmoDashboard2 = class extends LuzmoDashboard {
package/package.json CHANGED
@@ -1,9 +1,9 @@
1
1
  {
2
2
  "name": "@luzmo/embed",
3
- "version": "5.0.11",
3
+ "version": "5.0.12",
4
4
  "dependencies": {
5
5
  "lit": "3.1.2",
6
- "@luzmo/shared-embed": "5.0.5"
6
+ "@luzmo/shared-embed": "5.0.6"
7
7
  },
8
8
  "type": "module",
9
9
  "keywords": [
package/src/index.d.ts ADDED
@@ -0,0 +1,2 @@
1
+ export type { LoadEvent, ChangedFiltersEvent, CustomEvent, ItemsRenderedEvent, ExportedEvent, DashboardActionEvent, Filter, FilterExpression, FilterOrigin, FilterInput, FilterGroup, ExportType, ItemData, ExportDashboard, AccessibleDashboard, SetEditMode } from '@luzmo/shared-embed';
2
+ export * from './lib/dashboard-component/dashboard-component';
@@ -0,0 +1,98 @@
1
+ import * as SharedLib from '@luzmo/shared-embed';
2
+ import { LitElement, PropertyValues, TemplateResult } from 'lit';
3
+ import { CombinedFilterInput } from '@luzmo/shared-embed';
4
+ /**
5
+ * Luzmo Dashboard
6
+ * Base component isn't registered in customEvents registry so that it can be reused.
7
+ */
8
+ export declare class LuzmoDashboard extends LitElement implements SharedLib.ES6LuzmoDashboard {
9
+ container: HTMLElement;
10
+ luzmoEmbedContainer: HTMLElement;
11
+ iframe: HTMLIFrameElement;
12
+ dashboardId?: SharedLib.DashboardInputs['dashboardId'];
13
+ dashboardSlug?: SharedLib.DashboardInputs['dashboardSlug'];
14
+ itemId?: SharedLib.DashboardInputs['itemId'];
15
+ language: SharedLib.DashboardInputs['language'];
16
+ qeVersion: SharedLib.DashboardInputs['qeVersion'];
17
+ screenMode: SharedLib.DashboardInputs['screenMode'];
18
+ switchScreenModeOnResize: boolean;
19
+ editMode: SharedLib.DashboardInputs['editMode'];
20
+ mainColor?: SharedLib.DashboardInputs['mainColor'];
21
+ accentColor?: SharedLib.DashboardInputs['accentColor'];
22
+ authToken?: SharedLib.DashboardInputs['authToken'];
23
+ authKey?: SharedLib.DashboardInputs['authKey'];
24
+ loaderBackground?: SharedLib.DashboardInputs['loaderBackground'];
25
+ loaderFontColor?: SharedLib.DashboardInputs['loaderFontColor'];
26
+ loaderSpinnerColor?: SharedLib.DashboardInputs['loaderSpinnerColor'];
27
+ loaderSpinnerBackground?: SharedLib.DashboardInputs['loaderSpinnerBackground'];
28
+ appServer?: SharedLib.DashboardInputs['appServer'];
29
+ timezoneId?: SharedLib.DashboardInputs['timezoneId'];
30
+ apiHost?: SharedLib.DashboardInputs['apiHost'];
31
+ itemDimensions: SharedLib.DashboardInputs['itemDimensions'];
32
+ experimental: boolean;
33
+ _containerId: string;
34
+ _iframeId: string;
35
+ params: SharedLib.DashboardContentParams;
36
+ _iframeUrl?: string;
37
+ iframeLoaded: boolean;
38
+ promises: SharedLib.DashboardPromises;
39
+ iframeStyle: SharedLib.IframeStyles;
40
+ _containerStyle: SharedLib.ContainerStyles;
41
+ _loaderStyle: SharedLib.LoaderStyles;
42
+ _lcStyle: SharedLib.LcStyles;
43
+ _loadingCircleStyle: SharedLib.PlStyles;
44
+ _containerLoaderStyle: SharedLib.ContainerLoaderStyles;
45
+ _loaderMsg: string;
46
+ containerWidth?: number;
47
+ dimensions?: SharedLib.DashboardDimensions;
48
+ currentScreenMode?: SharedLib.ScreenMode;
49
+ _itemEmbedding: boolean;
50
+ browserError: boolean;
51
+ browserErrorMsg: string;
52
+ dashboardError: boolean;
53
+ browserNotSupported: any[];
54
+ VERSION: string;
55
+ protected isLibraryLoaded: boolean;
56
+ protected dashboardReference: SharedLib.LuzmoElement;
57
+ currentAuthKey: string;
58
+ currentAuthToken: string;
59
+ private attributesMap;
60
+ _loadTimeoutHandle?: number;
61
+ _onResize: () => void;
62
+ loaderSize: number;
63
+ borderWidth: number;
64
+ minHeight: number;
65
+ iframeHeight?: string;
66
+ iframeWidth?: string;
67
+ _resizeObserver: ResizeObserver;
68
+ constructor(inputParameters?: Record<keyof LuzmoDashboard, any>);
69
+ private loadLibrary;
70
+ private setInputParameters;
71
+ connectedCallback(): void;
72
+ disconnectedCallback(): void;
73
+ firstUpdated(): void;
74
+ initComponent(): void;
75
+ setAllAttributes(): void;
76
+ updated(changedProperties: PropertyValues): void;
77
+ _setOptions(): SharedLib.DashboardContentParams;
78
+ _updateIframeUrl(): void;
79
+ _setupLoader(): void;
80
+ _displayError(): void;
81
+ _calculateDimAfterDashboardLoaded(): void;
82
+ _loaderStyles(): void;
83
+ static get styles(): import("lit").CSSResult[];
84
+ render(): TemplateResult;
85
+ getDashboards(): Promise<LuzmoDashboard[]>;
86
+ getData(itemId: string): Promise<SharedLib.ItemData>;
87
+ getFilters(): Promise<SharedLib.FilterGroup[]>;
88
+ setFilters<K extends CombinedFilterInput>(itemId: string, filters: K): Promise<SharedLib.SetFilters>;
89
+ setAuthorization(key: string, token: string): Promise<void>;
90
+ refreshData(itemId?: string): Promise<void>;
91
+ reloadDashboard(): Promise<void>;
92
+ exportDashboard(format?: SharedLib.ExportType): Promise<SharedLib.ExportDashboard>;
93
+ getAccessibleDashboards(): Promise<SharedLib.AccessibleDashboard[]>;
94
+ addFilters(itemId: string, filters: SharedLib.FilterGroup[]): Promise<SharedLib.AddFilters>;
95
+ setEditMode(editMode?: SharedLib.DashboardEditMode): Promise<SharedLib.SetEditMode>;
96
+ setPreview(preview: boolean): Promise<SharedLib.SetPreview>;
97
+ getIsViewMode(): boolean;
98
+ }
@@ -0,0 +1,3 @@
1
+ import { LuzmoDashboard as LuzmoBaseDashboard } from './dashboard-base';
2
+ export declare class LuzmoDashboard extends LuzmoBaseDashboard {
3
+ }
@@ -0,0 +1 @@
1
+ export declare const dashboardStyles: import("lit").CSSResult;
@@ -0,0 +1 @@
1
+ export declare const _setEventHandler: () => void;
@@ -0,0 +1,6 @@
1
+ import { LuzmoDashboard } from './dashboard-component/dashboard-component';
2
+ declare class LuzmoService {
3
+ _components: LuzmoDashboard[];
4
+ }
5
+ declare const _default: LuzmoService;
6
+ export default _default;