mftsccs-browser 1.1.36-beta → 1.1.38-beta

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.
@@ -13501,7 +13501,11 @@ function GetConnectionBetweenTwoConceptsLinker(ofTheConcept_1, toTheConcept_1, l
13501
13501
  if (fullLinker != "") {
13502
13502
  typeConcept = yield (0,_app__WEBPACK_IMPORTED_MODULE_1__.MakeTheTypeConceptApi)(fullLinker, 999);
13503
13503
  }
13504
- let connections = yield (0,_Api_GetCompositionConnectionsBetweenTwoConcepts__WEBPACK_IMPORTED_MODULE_0__.GetCompositionConnectionsBetweenTwoConcepts)(ofTheConcept.id, toTheConcept.id, typeConcept.id);
13504
+ let connections = [];
13505
+ if (!forward)
13506
+ connections = yield (0,_Api_GetCompositionConnectionsBetweenTwoConcepts__WEBPACK_IMPORTED_MODULE_0__.GetCompositionConnectionsBetweenTwoConcepts)(toTheConcept.id, ofTheConcept.id, typeConcept.id);
13507
+ else
13508
+ connections = yield (0,_Api_GetCompositionConnectionsBetweenTwoConcepts__WEBPACK_IMPORTED_MODULE_0__.GetCompositionConnectionsBetweenTwoConcepts)(ofTheConcept.id, toTheConcept.id, typeConcept.id);
13505
13509
  return connections;
13506
13510
  });
13507
13511
  }
@@ -17987,11 +17991,9 @@ class Validator {
17987
17991
  }
17988
17992
  // 2. Validate using regex pattern for the data type
17989
17993
  if (dataType && value) {
17990
- console.log(`Comment on Data Type ${dataType} and Value ${value}`);
17991
17994
  let pattern = _constant__WEBPACK_IMPORTED_MODULE_1__.DATA_TYPES_RULES[dataType];
17992
- console.log("Find Pattern : ", pattern);
17993
17995
  if (pattern && value !== '' && !pattern.test(value)) {
17994
- errors['dataType'] = `Invalid format for ${dataType} in ${fieldName}`;
17996
+ errors['dataType'] = `Invalid value for ${dataType}`;
17995
17997
  }
17996
17998
  }
17997
17999
  // 3. Check if the provided pattern match with the value or not
@@ -18235,8 +18237,7 @@ __webpack_require__.r(__webpack_exports__);
18235
18237
  /* harmony export */ });
18236
18238
  /* harmony import */ var _StatefulWidget__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./StatefulWidget */ "./src/Widgets/StatefulWidget.ts");
18237
18239
  /* harmony import */ var _app__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../app */ "./src/app.ts");
18238
- /* harmony import */ var _Services_Common_ErrorPosting__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ../Services/Common/ErrorPosting */ "./src/Services/Common/ErrorPosting.ts");
18239
- /* harmony import */ var _BuilderSpeceficFunctions__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ./BuilderSpeceficFunctions */ "./src/Widgets/BuilderSpeceficFunctions.ts");
18240
+ /* harmony import */ var _BuilderSpeceficFunctions__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./BuilderSpeceficFunctions */ "./src/Widgets/BuilderSpeceficFunctions.ts");
18240
18241
  var __awaiter = (undefined && undefined.__awaiter) || function (thisArg, _arguments, P, generator) {
18241
18242
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
18242
18243
  return new (P || (P = Promise))(function (resolve, reject) {
@@ -18250,73 +18251,64 @@ var __awaiter = (undefined && undefined.__awaiter) || function (thisArg, _argume
18250
18251
 
18251
18252
 
18252
18253
 
18253
-
18254
18254
  class BuilderStatefulWidget extends _StatefulWidget__WEBPACK_IMPORTED_MODULE_0__.StatefulWidget {
18255
18255
  constructor() {
18256
18256
  super(...arguments);
18257
18257
  this.childComponents = [];
18258
- this.elementIdentifier = 0;
18259
18258
  this.componentMounted = false;
18260
- this.parentElement = "";
18261
18259
  this.oldHtml = null;
18262
- // subscribers: any = [];
18263
- this.element = null;
18264
18260
  this.phonebooks = [];
18265
18261
  this.childrenData = {};
18266
- this.html = "";
18267
18262
  this.childWidgets = [];
18268
18263
  this.typeValueList = [];
18269
18264
  this.widgetType = "the_element_name";
18270
18265
  this.parentConceptList = [];
18271
18266
  }
18272
- getWidgetCodeFromId(widgetId, token) {
18273
- return __awaiter(this, void 0, void 0, function* () {
18274
- //console.log("getWidgetCodeFromId", widgetId, token);
18275
- return new Promise((resolve, reject) => __awaiter(this, void 0, void 0, function* () {
18276
- try {
18277
- let searchFirst = new _app__WEBPACK_IMPORTED_MODULE_1__.SearchQuery();
18278
- searchFirst.composition = widgetId;
18279
- searchFirst.fullLinkers = [
18280
- "the_widgetcode",
18281
- "the_widgetcode_widget",
18282
- "the_widgetcode_name",
18283
- "the_widgetcode_html",
18284
- "the_widgetcode_css",
18285
- "the_widgetcode_js",
18286
- "the_widgetcode_timestamp",
18287
- "the_widgetcode_typevalue",
18288
- "the_widgetcode_addevent",
18289
- "the_widgetcode_onmount",
18290
- "the_widgetcode_onupdate",
18291
- "the_widgetcode_mountChildWidgets",
18292
- "the_widgetcode_cleanhtml",
18293
- "the_widgetcode_s_child",
18294
- ];
18295
- searchFirst.inpage = 100;
18296
- let searchSecond = new _app__WEBPACK_IMPORTED_MODULE_1__.SearchQuery();
18297
- searchSecond.fullLinkers = [
18298
- "the_childwidget",
18299
- "the_childwidget_typevalue",
18300
- "the_childwidget_widget",
18301
- "the_childwidget_wrapperId",
18302
- ];
18303
- searchSecond.inpage = 100;
18304
- const queryParams = [searchFirst, searchSecond];
18305
- const output = yield (0,_app__WEBPACK_IMPORTED_MODULE_1__.SearchLinkMultipleAll)(queryParams, token);
18306
- //console.log("getWidgetCodeFromId output ->", output);
18307
- resolve(output);
18308
- return output;
18309
- }
18310
- catch (error) {
18311
- console.error("error", error);
18312
- if ((error === null || error === void 0 ? void 0 : error.status) === 401) {
18313
- (0,_Services_Common_ErrorPosting__WEBPACK_IMPORTED_MODULE_2__.HandleHttpError)(error === null || error === void 0 ? void 0 : error.response);
18314
- }
18315
- reject(error);
18316
- }
18317
- }));
18318
- });
18319
- }
18267
+ // async getWidgetCodeFromId(widgetId: number, token: string) {
18268
+ // //console.log("getWidgetCodeFromId", widgetId, token);
18269
+ // return new Promise(async (resolve: any, reject: any) => {
18270
+ // try {
18271
+ // let searchFirst = new SearchQuery();
18272
+ // searchFirst.composition = widgetId;
18273
+ // searchFirst.fullLinkers = [
18274
+ // "the_widgetcode",
18275
+ // "the_widgetcode_widget",
18276
+ // "the_widgetcode_name",
18277
+ // "the_widgetcode_html",
18278
+ // "the_widgetcode_css",
18279
+ // "the_widgetcode_js",
18280
+ // "the_widgetcode_timestamp",
18281
+ // "the_widgetcode_typevalue",
18282
+ // "the_widgetcode_addevent",
18283
+ // "the_widgetcode_onmount",
18284
+ // "the_widgetcode_onupdate",
18285
+ // "the_widgetcode_mountChildWidgets",
18286
+ // "the_widgetcode_cleanhtml",
18287
+ // "the_widgetcode_s_child",
18288
+ // ];
18289
+ // searchFirst.inpage = 100;
18290
+ // let searchSecond = new SearchQuery();
18291
+ // searchSecond.fullLinkers = [
18292
+ // "the_childwidget",
18293
+ // "the_childwidget_typevalue",
18294
+ // "the_childwidget_widget",
18295
+ // "the_childwidget_wrapperId",
18296
+ // ];
18297
+ // searchSecond.inpage = 100;
18298
+ // const queryParams = [searchFirst, searchSecond];
18299
+ // const output = await SearchLinkMultipleAll(queryParams, token);
18300
+ // //console.log("getWidgetCodeFromId output ->", output);
18301
+ // resolve(output);
18302
+ // return output;
18303
+ // } catch (error: any) {
18304
+ // console.error("error", error);
18305
+ // if (error?.status === 401) {
18306
+ // HandleHttpError(error?.response)
18307
+ // }
18308
+ // reject(error);
18309
+ // }
18310
+ // });
18311
+ // }
18320
18312
  // async CreateConceptConnections(){
18321
18313
  // let mainConcept = await
18322
18314
  // for(let i=0; i<this.childrenData.length; i++){
@@ -18428,7 +18420,7 @@ class BuilderStatefulWidget extends _StatefulWidget__WEBPACK_IMPORTED_MODULE_0__
18428
18420
  });
18429
18421
  }
18430
18422
  createTypeEditor(event) {
18431
- (0,_BuilderSpeceficFunctions__WEBPACK_IMPORTED_MODULE_3__.TypeEditor)(event, this);
18423
+ (0,_BuilderSpeceficFunctions__WEBPACK_IMPORTED_MODULE_2__.TypeEditor)(event, this);
18432
18424
  }
18433
18425
  /**
18434
18426
  *
@@ -18450,7 +18442,6 @@ class BuilderStatefulWidget extends _StatefulWidget__WEBPACK_IMPORTED_MODULE_0__
18450
18442
  this.element.innerHTML = this.getHtml();
18451
18443
  parent === null || parent === void 0 ? void 0 : parent.setAttribute("data-type-value", that.widgetType);
18452
18444
  parent.appendChild(this.element);
18453
- this.childWidgetElement = this.getElementByClassName("added-widget-container");
18454
18445
  this.parentElement = parent.id;
18455
18446
  if (this.componentMounted == false || this.widgetMounted == false) {
18456
18447
  // Simulate componentDidMount by calling it after the component is inserted into the DOM
@@ -18462,6 +18453,7 @@ class BuilderStatefulWidget extends _StatefulWidget__WEBPACK_IMPORTED_MODULE_0__
18462
18453
  else {
18463
18454
  this.render();
18464
18455
  }
18456
+ this.childWidgetElement = this.getElementByClassName("added-widget-container");
18465
18457
  }
18466
18458
  });
18467
18459
  }
@@ -18499,55 +18491,57 @@ class BuilderStatefulWidget extends _StatefulWidget__WEBPACK_IMPORTED_MODULE_0__
18499
18491
  // const renderOnmount = AsyncFunction("tsccs", this.addEventFunction);
18500
18492
  // renderOnmount.call(this, tsccs);
18501
18493
  }
18502
- getWidgetClassFunction(widgetId) {
18503
- return __awaiter(this, void 0, void 0, function* () {
18504
- return new Promise((resolve) => __awaiter(this, void 0, void 0, function* () {
18505
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _0, _1, _2, _3, _4;
18506
- const profileData = yield new Promise((resolve2) => {
18507
- let dataFromLocalStorage = (localStorage === null || localStorage === void 0 ? void 0 : localStorage.getItem("profile")) || "";
18508
- if (dataFromLocalStorage) {
18509
- const profileData = JSON.parse(dataFromLocalStorage);
18510
- resolve2(profileData);
18511
- }
18512
- else {
18513
- resolve2();
18514
- }
18515
- });
18516
- const token = profileData === null || profileData === void 0 ? void 0 : profileData.token;
18517
- let output = yield this.getWidgetCodeFromId(widgetId, token);
18518
- const widgetInfo = (_a = output === null || output === void 0 ? void 0 : output.data) === null || _a === void 0 ? void 0 : _a.the_widgetcode;
18519
- const widgetName = (_d = (_c = (_b = widgetInfo === null || widgetInfo === void 0 ? void 0 : widgetInfo.the_widgetcode_name) === null || _b === void 0 ? void 0 : _b[0]) === null || _c === void 0 ? void 0 : _c.data) === null || _d === void 0 ? void 0 : _d.the_name;
18520
- const widgetHTML = (_g = (_f = (_e = widgetInfo === null || widgetInfo === void 0 ? void 0 : widgetInfo.the_widgetcode_html) === null || _e === void 0 ? void 0 : _e[0]) === null || _f === void 0 ? void 0 : _f.data) === null || _g === void 0 ? void 0 : _g.the_html;
18521
- const widgetCSS = (_k = (_j = (_h = widgetInfo === null || widgetInfo === void 0 ? void 0 : widgetInfo.the_widgetcode_css) === null || _h === void 0 ? void 0 : _h[0]) === null || _j === void 0 ? void 0 : _j.data) === null || _k === void 0 ? void 0 : _k.the_css;
18522
- const widgetJS = (_o = (_m = (_l = widgetInfo === null || widgetInfo === void 0 ? void 0 : widgetInfo.the_widgetcode_js) === null || _l === void 0 ? void 0 : _l[0]) === null || _m === void 0 ? void 0 : _m.data) === null || _o === void 0 ? void 0 : _o.the_js;
18523
- const widgetTimestamp = (_r = (_q = (_p = widgetInfo === null || widgetInfo === void 0 ? void 0 : widgetInfo.the_widgetcode_timestamp) === null || _p === void 0 ? void 0 : _p[0]) === null || _q === void 0 ? void 0 : _q.data) === null || _r === void 0 ? void 0 : _r.the_timestamp;
18524
- const widgetPackageId = (_s = widgetInfo === null || widgetInfo === void 0 ? void 0 : widgetInfo.the_widgetcode_widget) === null || _s === void 0 ? void 0 : _s[0].id;
18525
- const widgetAddEvent = (_v = (_u = (_t = widgetInfo === null || widgetInfo === void 0 ? void 0 : widgetInfo.the_widgetcode_addevent) === null || _t === void 0 ? void 0 : _t[0]) === null || _u === void 0 ? void 0 : _u.data) === null || _v === void 0 ? void 0 : _v.the_addevent;
18526
- const widgetOnmount = (_y = (_x = (_w = widgetInfo === null || widgetInfo === void 0 ? void 0 : widgetInfo.the_widgetcode_onmount) === null || _w === void 0 ? void 0 : _w[0]) === null || _x === void 0 ? void 0 : _x.data) === null || _y === void 0 ? void 0 : _y.the_onmount;
18527
- const widgetOnupdate = (_1 = (_0 = (_z = widgetInfo === null || widgetInfo === void 0 ? void 0 : widgetInfo.the_widgetcode_onupdate) === null || _z === void 0 ? void 0 : _z[0]) === null || _0 === void 0 ? void 0 : _0.data) === null || _1 === void 0 ? void 0 : _1.the_onupdate;
18528
- const widgetMountChildWidgets = (_4 = (_3 = (_2 = widgetInfo === null || widgetInfo === void 0 ? void 0 : widgetInfo.the_widgetcode_mountChildWidgets) === null || _2 === void 0 ? void 0 : _2[0]) === null || _3 === void 0 ? void 0 : _3.data) === null || _4 === void 0 ? void 0 : _4.the_mountChildWidgets;
18529
- const widgetData = {
18530
- id: output === null || output === void 0 ? void 0 : output.id,
18531
- name: widgetName,
18532
- html: widgetHTML,
18533
- css: widgetCSS,
18534
- js: widgetJS,
18535
- timestamp: widgetTimestamp,
18536
- widgetId: widgetPackageId,
18537
- addevent: widgetAddEvent,
18538
- onmount: widgetOnmount,
18539
- onupdate: widgetOnupdate,
18540
- mountChildWidgets: widgetMountChildWidgets,
18541
- };
18542
- const widgetInstance = new BuilderStatefulWidget();
18543
- widgetInstance.html = widgetData === null || widgetData === void 0 ? void 0 : widgetData.html;
18544
- widgetInstance.componentDidMountFunction = widgetData === null || widgetData === void 0 ? void 0 : widgetData.onmount;
18545
- widgetInstance.addEventFunction = widgetData === null || widgetData === void 0 ? void 0 : widgetData.addevent;
18546
- widgetInstance.mountChildWidgetsFunction = widgetData === null || widgetData === void 0 ? void 0 : widgetData.mountChildWidgets;
18547
- resolve(widgetInstance);
18548
- }));
18549
- });
18550
- }
18494
+ // async getWidgetClassFunction(widgetId: number) {
18495
+ // return new Promise(async (resolve: any) => {
18496
+ // const profileData: any = await new Promise((resolve2: any) => {
18497
+ // let dataFromLocalStorage: string = localStorage?.getItem("profile") || "";
18498
+ // if (dataFromLocalStorage) {
18499
+ // const profileData = JSON.parse(dataFromLocalStorage);
18500
+ // resolve2(profileData)
18501
+ // } else {
18502
+ // resolve2()
18503
+ // }
18504
+ // });
18505
+ // const token = profileData?.token;
18506
+ // let output: any = await this.getWidgetCodeFromId(widgetId, token);
18507
+ // const widgetInfo = output?.data?.the_widgetcode;
18508
+ // const widgetName = widgetInfo?.the_widgetcode_name?.[0]?.data?.the_name;
18509
+ // const widgetHTML = widgetInfo?.the_widgetcode_html?.[0]?.data?.the_html;
18510
+ // const widgetCSS = widgetInfo?.the_widgetcode_css?.[0]?.data?.the_css;
18511
+ // const widgetJS = widgetInfo?.the_widgetcode_js?.[0]?.data?.the_js;
18512
+ // const widgetTimestamp =
18513
+ // widgetInfo?.the_widgetcode_timestamp?.[0]?.data?.the_timestamp;
18514
+ // const widgetPackageId = widgetInfo?.the_widgetcode_widget?.[0].id;
18515
+ // const widgetAddEvent =
18516
+ // widgetInfo?.the_widgetcode_addevent?.[0]?.data?.the_addevent;
18517
+ // const widgetOnmount =
18518
+ // widgetInfo?.the_widgetcode_onmount?.[0]?.data?.the_onmount;
18519
+ // const widgetOnupdate =
18520
+ // widgetInfo?.the_widgetcode_onupdate?.[0]?.data?.the_onupdate;
18521
+ // const widgetMountChildWidgets =
18522
+ // widgetInfo?.the_widgetcode_mountChildWidgets?.[0]?.data
18523
+ // ?.the_mountChildWidgets;
18524
+ // const widgetData = {
18525
+ // id: output?.id,
18526
+ // name: widgetName,
18527
+ // html: widgetHTML,
18528
+ // css: widgetCSS,
18529
+ // js: widgetJS,
18530
+ // timestamp: widgetTimestamp,
18531
+ // widgetId: widgetPackageId,
18532
+ // addevent: widgetAddEvent,
18533
+ // onmount: widgetOnmount,
18534
+ // onupdate: widgetOnupdate,
18535
+ // mountChildWidgets: widgetMountChildWidgets,
18536
+ // };
18537
+ // const widgetInstance = new BuilderStatefulWidget();
18538
+ // widgetInstance.html = widgetData?.html;
18539
+ // widgetInstance.componentDidMountFunction = widgetData?.onmount;
18540
+ // widgetInstance.addEventFunction = widgetData?.addevent;
18541
+ // widgetInstance.mountChildWidgetsFunction = widgetData?.mountChildWidgets;
18542
+ // resolve(widgetInstance);
18543
+ // });
18544
+ // }
18551
18545
  CreateConnectionBetweenEntityLocal(concept1Data, concept2Data, linker) {
18552
18546
  return __awaiter(this, void 0, void 0, function* () {
18553
18547
  var _a;
@@ -18595,6 +18589,7 @@ var __awaiter = (undefined && undefined.__awaiter) || function (thisArg, _argume
18595
18589
  class StatefulWidget extends _BaseWidget__WEBPACK_IMPORTED_MODULE_0__.BaseWidget {
18596
18590
  constructor() {
18597
18591
  super(...arguments);
18592
+ this.html = "";
18598
18593
  /**
18599
18594
  * These are the child widgets that need to be added to this widget
18600
18595
  */
@@ -18620,7 +18615,7 @@ class StatefulWidget extends _BaseWidget__WEBPACK_IMPORTED_MODULE_0__.BaseWidget
18620
18615
  * @returns the html string that needs to be mounted to the DOM.
18621
18616
  */
18622
18617
  getHtml() {
18623
- return '';
18618
+ return this.html;
18624
18619
  }
18625
18620
  /**
18626
18621
  * This will help us update the data of the child widget. This will also call another function inside of the child widget
@@ -20183,6 +20178,8 @@ var __awaiter = (undefined && undefined.__awaiter) || function (thisArg, _argume
20183
20178
  var serviceWorker;
20184
20179
  const TABID = Date.now().toString(36) + Math.random().toString(36).substring(2);
20185
20180
  let subscribedListeners = [];
20181
+ let serviceWorkerReady = false;
20182
+ let messageQueue = [];
20186
20183
  /**
20187
20184
  * This function lets you update the access token that the package uses. If this is not passed you cannot create, update, view or delete
20188
20185
  * Your concepts using this package.
@@ -20283,16 +20280,6 @@ function init() {
20283
20280
  // console.log("Status: No active worker", registration);
20284
20281
  // }
20285
20282
  // });
20286
- // // // for now asuming its other
20287
- // // await initConceptConnection(
20288
- // // url,
20289
- // // aiurl,
20290
- // // accessToken,
20291
- // // nodeUrl,
20292
- // // enableAi,
20293
- // // applicationName,
20294
- // // isTest
20295
- // // );
20296
20283
  // } else {
20297
20284
  // let serviceWorkerPath = enableSW.path ? enableSW.path : './serviceWorker.bundle.js'
20298
20285
  // if (enableSW.path && enableSW.path.slice(-1) == '/') serviceWorkerPath = enableSW.path + 'serviceWorker.bundle.js'
@@ -20328,6 +20315,25 @@ function init() {
20328
20315
  reject("Not Completed Initialization");
20329
20316
  }, 5000);
20330
20317
  }
20318
+ // state change
20319
+ if (registration.installing || registration.waiting || registration.active) {
20320
+ registration.addEventListener('statechange', (event) => __awaiter(this, void 0, void 0, function* () {
20321
+ var _a;
20322
+ if (((_a = event === null || event === void 0 ? void 0 : event.target) === null || _a === void 0 ? void 0 : _a.state) === 'activating') {
20323
+ serviceWorker = navigator.serviceWorker.controller;
20324
+ console.log('Service Worker is activating statechange');
20325
+ yield sendMessage("init", {
20326
+ url,
20327
+ aiurl,
20328
+ accessToken,
20329
+ nodeUrl,
20330
+ enableAi,
20331
+ applicationName,
20332
+ isTest,
20333
+ });
20334
+ }
20335
+ }));
20336
+ }
20331
20337
  // Listen for updates to the service worker
20332
20338
  console.log("update listen start");
20333
20339
  registration.onupdatefound = () => {
@@ -20335,7 +20341,7 @@ function init() {
20335
20341
  console.log("new worker", newWorker);
20336
20342
  if (newWorker) {
20337
20343
  newWorker.onstatechange = () => __awaiter(this, void 0, void 0, function* () {
20338
- console.log("on state change triggered");
20344
+ console.log("on state change triggered", (newWorker.state === "installed" || newWorker.state === "activated" || newWorker.state === 'redundant'), navigator.serviceWorker.controller);
20339
20345
  // if (newWorker.state === 'activated' && navigator.serviceWorker.controller) {
20340
20346
  if ((newWorker.state === "installed" || newWorker.state === "activated" || newWorker.state === 'redundant') && navigator.serviceWorker.controller) {
20341
20347
  // && navigator.serviceWorker.controller) {
@@ -20353,6 +20359,8 @@ function init() {
20353
20359
  isTest,
20354
20360
  });
20355
20361
  success = true;
20362
+ serviceWorkerReady = true;
20363
+ processMessageQueue();
20356
20364
  resolve();
20357
20365
  }
20358
20366
  });
@@ -20361,6 +20369,7 @@ function init() {
20361
20369
  // Listen for the activation of the new service worker
20362
20370
  registration.addEventListener('controllerchange', () => __awaiter(this, void 0, void 0, function* () {
20363
20371
  if (navigator.serviceWorker.controller) {
20372
+ serviceWorker = navigator.serviceWorker.controller;
20364
20373
  console.log('Service worker has been activated');
20365
20374
  yield sendMessage("init", {
20366
20375
  url,
@@ -20375,6 +20384,12 @@ function init() {
20375
20384
  // You can reload the page if necessary or handle the update process here
20376
20385
  }
20377
20386
  }));
20387
+ // If the service worker is already active, mark it as ready
20388
+ if (registration.active) {
20389
+ serviceWorkerReady = true;
20390
+ console.log('Service Worker is already active');
20391
+ processMessageQueue();
20392
+ }
20378
20393
  }))
20379
20394
  .catch((error) => __awaiter(this, void 0, void 0, function* () {
20380
20395
  yield initConceptConnection();
@@ -20405,9 +20420,15 @@ function init() {
20405
20420
  }
20406
20421
  });
20407
20422
  }
20423
+ /**
20424
+ * Method to send message to the service worker from main thread
20425
+ * @param type string
20426
+ * @param payload any
20427
+ * @returns Promise<any>
20428
+ */
20408
20429
  function sendMessage(type, payload) {
20409
20430
  return __awaiter(this, void 0, void 0, function* () {
20410
- const messageId = Math.random().toString(36).substring(5); // Generate a unique message ID
20431
+ const messageId = Math.random().toString(36).substring(2); // Generate a unique message ID
20411
20432
  payload.messageId = messageId;
20412
20433
  payload.TABID = TABID;
20413
20434
  // let actions = payload.actions
@@ -20415,61 +20436,61 @@ function sendMessage(type, payload) {
20415
20436
  return new Promise((resolve, reject) => {
20416
20437
  // navigator.serviceWorker.ready
20417
20438
  // .then((registration) => {
20418
- const responseHandler = (event) => {
20419
- var _a, _b;
20420
- if (((_a = event === null || event === void 0 ? void 0 : event.data) === null || _a === void 0 ? void 0 : _a.messageId) == messageId) { // Check if the message ID matches
20421
- if ((_b = event.data) === null || _b === void 0 ? void 0 : _b.actions) {
20422
- payload.actions = JSON.parse(JSON.stringify(event.data.actions));
20439
+ if (navigator.serviceWorker.controller) {
20440
+ const responseHandler = (event) => {
20441
+ var _a, _b;
20442
+ if (((_a = event === null || event === void 0 ? void 0 : event.data) === null || _a === void 0 ? void 0 : _a.messageId) == messageId) { // Check if the message ID matches
20443
+ if ((_b = event.data) === null || _b === void 0 ? void 0 : _b.actions) {
20444
+ payload.actions = JSON.parse(JSON.stringify(event.data.actions));
20445
+ }
20446
+ resolve(event.data);
20447
+ navigator.serviceWorker.removeEventListener("message", responseHandler);
20423
20448
  }
20424
- resolve(event.data);
20425
- navigator.serviceWorker.removeEventListener("message", responseHandler);
20449
+ };
20450
+ navigator.serviceWorker.addEventListener("message", responseHandler);
20451
+ // console.log("before sending message", type, 'new', newPayload);
20452
+ // serviceWorker?.postMessage({ type, payload });
20453
+ // Send the message to the service worker
20454
+ if (navigator.serviceWorker.controller) {
20455
+ try {
20456
+ navigator.serviceWorker.controller.postMessage({ type, payload: newPayload });
20457
+ }
20458
+ catch (err) {
20459
+ console.log(err);
20460
+ serviceWorker.postMessage({ type, payload: newPayload });
20461
+ }
20462
+ // navigator.serviceWorker.controller.postMessage({ type, payload });
20426
20463
  }
20427
- };
20428
- navigator.serviceWorker.addEventListener("message", responseHandler);
20429
- // console.log("before sending message", type, 'new', newPayload);
20430
- // serviceWorker?.postMessage({ type, payload });
20431
- // Send the message to the service worker
20432
- if (navigator.serviceWorker.controller) {
20433
- serviceWorker.postMessage({ type, payload: newPayload });
20434
- // navigator.serviceWorker.controller.postMessage({ type, payload });
20464
+ else {
20465
+ // wait one second before checking again
20466
+ setTimeout(() => {
20467
+ // if (navigator.serviceWorker.controller) {
20468
+ if (serviceWorker) {
20469
+ serviceWorker.postMessage({ type, payload });
20470
+ // navigator.serviceWorker.controller.postMessage({ type, payload });
20471
+ }
20472
+ else {
20473
+ console.log('not ready', type);
20474
+ reject("Service worker not ready");
20475
+ }
20476
+ }, 90000); // 90 seconds
20477
+ }
20478
+ // Timeout for waiting for the response (e.g., 5 seconds)
20479
+ setTimeout(() => {
20480
+ reject("No response from service worker after timeout");
20481
+ navigator.serviceWorker.removeEventListener("message", responseHandler);
20482
+ }, 90000); // 90 sec
20435
20483
  }
20436
20484
  else {
20437
- // wait one second before checking again
20438
- setTimeout(() => {
20439
- // if (navigator.serviceWorker.controller) {
20440
- if (serviceWorker) {
20441
- serviceWorker.postMessage({ type, payload });
20442
- // navigator.serviceWorker.controller.postMessage({ type, payload });
20443
- }
20444
- else {
20445
- console.log('not ready', type);
20446
- reject("Service worker not ready");
20447
- }
20448
- }, 60000); // 60 seconds
20485
+ messageQueue.push({ message: { type, payload: newPayload } });
20486
+ console.log('Message Queued', type, payload);
20449
20487
  }
20450
- // Timeout for waiting for the response (e.g., 5 seconds)
20451
- setTimeout(() => {
20452
- reject("No response from service worker after timeout");
20453
- navigator.serviceWorker.removeEventListener("message", responseHandler);
20454
- }, 60000); // 60 sec
20455
20488
  // })
20456
20489
  // .catch(err => reject(err))
20457
20490
  // .finally(() => console.log('finally'))
20458
20491
  });
20459
20492
  });
20460
20493
  }
20461
- function dispatchIdEvent(id, data = {}) {
20462
- // console.log('id event dispatched', id)
20463
- if (serviceWorker) {
20464
- // let event = new Event(`${id}`);
20465
- let event = new CustomEvent(`${id}`, data);
20466
- console.log("event fired from", event);
20467
- dispatchEvent(event);
20468
- }
20469
- else {
20470
- _Constants_general_const__WEBPACK_IMPORTED_MODULE_100__.broadcastChannel.postMessage({ type: 'dispatchEvent', payload: { id } });
20471
- }
20472
- }
20473
20494
  // export function sendMessage(type: string, payload: any) {
20474
20495
  // return new Promise((resolve) => {
20475
20496
  // const responseHandler = (event: any) => {
@@ -20498,8 +20519,27 @@ const broadcastActions = {
20498
20519
  // });
20499
20520
  // });
20500
20521
  return { success: true };
20522
+ }),
20523
+ checkInit: (payload) => __awaiter(void 0, void 0, void 0, function* () {
20524
+ console.log('service worker init 0');
20525
+ if (navigator.serviceWorker.controller) {
20526
+ console.log('service worker init 1');
20527
+ serviceWorker = navigator.serviceWorker.controller;
20528
+ }
20529
+ yield sendMessage("init", {
20530
+ url: _DataStructures_BaseUrl__WEBPACK_IMPORTED_MODULE_98__.BaseUrl.BASE_URL,
20531
+ aiurl: _DataStructures_BaseUrl__WEBPACK_IMPORTED_MODULE_98__.BaseUrl.AI_URL,
20532
+ accessToken: _DataStructures_Security_TokenStorage__WEBPACK_IMPORTED_MODULE_99__.TokenStorage.BearerAccessToken,
20533
+ nodeUrl: _DataStructures_BaseUrl__WEBPACK_IMPORTED_MODULE_98__.BaseUrl.NODE_URL,
20534
+ enableAi: false,
20535
+ applicationName: _DataStructures_BaseUrl__WEBPACK_IMPORTED_MODULE_98__.BaseUrl.BASE_APPLICATION
20536
+ });
20537
+ return { success: true };
20501
20538
  })
20502
20539
  };
20540
+ /**
20541
+ * Method to trigger broadcast message listener
20542
+ */
20503
20543
  function listenBroadCastMessages() {
20504
20544
  // broadcast event can be listened through both the service worker and other tabs
20505
20545
  _Constants_general_const__WEBPACK_IMPORTED_MODULE_100__.broadcastChannel.addEventListener('message', (event) => __awaiter(this, void 0, void 0, function* () {
@@ -20613,6 +20653,31 @@ function initConceptConnection() {
20613
20653
  });
20614
20654
  });
20615
20655
  }
20656
+ /**
20657
+ * Method to dispatch Event received from SW
20658
+ * @param id number|string
20659
+ * @param data any
20660
+ */
20661
+ function dispatchIdEvent(id, data = {}) {
20662
+ // console.log('id event dispatched', id)
20663
+ if (serviceWorker) {
20664
+ // let event = new Event(`${id}`);
20665
+ let event = new CustomEvent(`${id}`, data);
20666
+ console.log("event fired from", event);
20667
+ dispatchEvent(event);
20668
+ }
20669
+ else {
20670
+ _Constants_general_const__WEBPACK_IMPORTED_MODULE_100__.broadcastChannel.postMessage({ type: 'dispatchEvent', payload: { id } });
20671
+ }
20672
+ }
20673
+ function processMessageQueue() {
20674
+ return __awaiter(this, void 0, void 0, function* () {
20675
+ while (messageQueue.length > 0) {
20676
+ const { message, resolve, reject } = messageQueue.shift();
20677
+ yield sendMessage(message.type, message.payload);
20678
+ }
20679
+ });
20680
+ }
20616
20681
 
20617
20682
 
20618
20683
  /***/ })