@ianua/ianus-dataverse-react-fluentui8 1.0.12 → 1.0.13

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 (2) hide show
  1. package/dist/index.js +33 -63
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -532,6 +532,20 @@ var IanusGuard = ({ publisherId, productId, publicKeys, environmentType, environ
532
532
  }
533
533
  }, [publicKeys]);
534
534
  const resolvedEnvironmentIdentifierRef = React4.useRef(null);
535
+ const preventAutomaticReevaluation = React4.useRef(false);
536
+ const handleValidationResult = React4.useCallback((result) => {
537
+ var _a2;
538
+ preventAutomaticReevaluation.current = (_a2 = result == null ? void 0 : result.isValid) != null ? _a2 : false;
539
+ if (onLicenseValidatedRef.current) {
540
+ try {
541
+ onLicenseValidatedRef.current(result);
542
+ } catch (e) {
543
+ if (e && e instanceof Error) {
544
+ console.error(`Error while calling onLicenseValidated: '${e.message}'`);
545
+ }
546
+ }
547
+ }
548
+ }, []);
535
549
  const runValidation = React4.useCallback(() => __async(null, null, function* () {
536
550
  try {
537
551
  if (resolvedEnvironmentIdentifierRef.current === null) {
@@ -592,17 +606,9 @@ var IanusGuard = ({ publisherId, productId, publicKeys, environmentType, environ
592
606
  const initLicenseValidation = React4.useCallback(() => __async(null, null, function* () {
593
607
  const result = yield runValidation();
594
608
  licenseDispatch({ type: "setLicense", payload: result });
595
- if (onLicenseValidatedRef.current) {
596
- try {
597
- onLicenseValidatedRef.current(result);
598
- } catch (e) {
599
- if (e && e instanceof Error) {
600
- console.error(`Error while calling onLicenseValidated: '${e.message}'`);
601
- }
602
- }
603
- }
604
- }), [licenseDispatch, runValidation]);
605
- const onSettingsFinally = React4.useCallback(() => {
609
+ handleValidationResult(result);
610
+ }), [licenseDispatch, runValidation, handleValidationResult]);
611
+ const onLicenseDialogFinally = React4.useCallback(() => {
606
612
  licenseDispatch({ type: "setLicenseDialogVisible", payload: false });
607
613
  initLicenseValidation();
608
614
  }, [initLicenseValidation, licenseDispatch]);
@@ -641,44 +647,24 @@ var IanusGuard = ({ publisherId, productId, publicKeys, environmentType, environ
641
647
  }
642
648
  return "";
643
649
  }, [offlineDataProvider]);
644
- const prevDeps = React4.useRef({
645
- dataProvider,
646
- dataProviderState,
647
- dataProviderSignature,
648
- initLicenseValidation,
649
- licenseDispatch,
650
- usagePermission,
651
- offlineDataProvider,
652
- offlineDataProviderState,
653
- offlineDataProviderSignature
654
- });
650
+ const canResetAutomaticReevaluation = React4.useMemo(() => {
651
+ return isDataset(dataProvider) || offlineDataProvider != null;
652
+ }, [dataProvider, offlineDataProvider]);
653
+ React4.useEffect(() => {
654
+ if (canResetAutomaticReevaluation) {
655
+ preventAutomaticReevaluation.current = false;
656
+ }
657
+ }, [canResetAutomaticReevaluation, dataProviderSignature, offlineDataProviderSignature]);
655
658
  React4.useEffect(() => {
659
+ if (preventAutomaticReevaluation.current) {
660
+ console.log(`Skipping license evaluation as checks have already passed at ${(/* @__PURE__ */ new Date()).toISOString()}`);
661
+ return;
662
+ }
656
663
  console.log(`Starting license evaluation at ${(/* @__PURE__ */ new Date()).toISOString()}`);
657
664
  console.log(`DataProvider state: ${dataProviderState}`);
658
665
  console.log(`DataProvider signature: ${dataProviderSignature}`);
659
666
  console.log(`Offline DataProvider state: ${offlineDataProviderState}`);
660
667
  console.log(`Offline DataProvider signature: ${offlineDataProviderSignature}`);
661
- const prev = prevDeps.current;
662
- if (prev.dataProvider !== dataProvider) console.log("dataProvider changed");
663
- if (prev.dataProviderState !== dataProviderState) console.log("dataProviderState changed");
664
- if (prev.dataProviderSignature !== dataProviderSignature) console.log("dataProviderSignature changed");
665
- if (prev.initLicenseValidation !== initLicenseValidation) console.log("initLicenseValidation changed");
666
- if (prev.licenseDispatch !== licenseDispatch) console.log("licenseDispatch changed");
667
- if (prev.usagePermission !== usagePermission) console.log("usagePermission changed");
668
- if (prev.offlineDataProvider !== offlineDataProvider) console.log("offlineDataProvider changed");
669
- if (prev.offlineDataProviderState !== offlineDataProviderState) console.log("offlineDataProviderState changed");
670
- if (prev.offlineDataProviderSignature !== offlineDataProviderSignature) console.log("offlineDataProviderSignature changed");
671
- prevDeps.current = {
672
- dataProvider,
673
- dataProviderState,
674
- dataProviderSignature,
675
- initLicenseValidation,
676
- licenseDispatch,
677
- usagePermission,
678
- offlineDataProvider,
679
- offlineDataProviderState,
680
- offlineDataProviderSignature
681
- };
682
668
  if (usagePermission != null && !usagePermission) {
683
669
  const result = {
684
670
  isValid: false,
@@ -686,15 +672,7 @@ var IanusGuard = ({ publisherId, productId, publicKeys, environmentType, environ
686
672
  reason: "Your user is not enabled for using this product"
687
673
  };
688
674
  licenseDispatch({ type: "setLicense", payload: result });
689
- if (onLicenseValidatedRef.current) {
690
- try {
691
- onLicenseValidatedRef.current(result);
692
- } catch (e) {
693
- if (e && e instanceof Error) {
694
- console.error(`Error while calling onLicenseValidated: '${e.message}'`);
695
- }
696
- }
697
- }
675
+ handleValidationResult(result);
698
676
  } else if (!isDataset(dataProvider) || !dataProvider.error && !dataProvider.loading && dataProvider.paging.totalResultCount >= 0 || offlineDataProvider != null && !offlineDataProvider.error && !offlineDataProvider.loading && offlineDataProvider.paging.totalResultCount >= 0) {
699
677
  initLicenseValidation();
700
678
  } else if (dataProvider.error) {
@@ -704,18 +682,10 @@ var IanusGuard = ({ publisherId, productId, publicKeys, environmentType, environ
704
682
  reason: `Dataset error: ${dataProvider.errorMessage}`
705
683
  };
706
684
  licenseDispatch({ type: "setLicense", payload: result });
707
- if (onLicenseValidatedRef.current) {
708
- try {
709
- onLicenseValidatedRef.current(result);
710
- } catch (e) {
711
- if (e && e instanceof Error) {
712
- console.error(`Error while calling onLicenseValidated: '${e.message}'`);
713
- }
714
- }
715
- }
685
+ handleValidationResult(result);
716
686
  }
717
- }, [dataProvider, dataProviderState, dataProviderSignature, initLicenseValidation, licenseDispatch, usagePermission, offlineDataProvider, offlineDataProviderState, offlineDataProviderSignature]);
718
- return ((_a = licenseState.license) == null ? void 0 : _a.isValid) ? /* @__PURE__ */ React4.createElement(React4.Fragment, null, licenseState.licenseDialogVisible && /* @__PURE__ */ React4.createElement(LicenseDialog, { publisherId, productId, dataProvider, offlineDataProvider, onSubmit: onSettingsFinally, onCancel: onSettingsFinally }), children) : /* @__PURE__ */ React4.createElement("div", { style: { display: "flex", width: "100%", height: "100%", flex: "1" } }, licenseState.licenseDialogVisible && /* @__PURE__ */ React4.createElement(LicenseDialog, { publisherId, productId, dataProvider, offlineDataProvider, onSubmit: onSettingsFinally, onCancel: onSettingsFinally }), licenseState.debugDialogVisible && /* @__PURE__ */ React4.createElement(DebugDialog, { publisherId, productId, environmentType, environmentIdentifier: resolvedEnvironmentIdentifierRef.current || "", dataProvider, offlineDataProvider, onDismiss: onDebugFinally }), /* @__PURE__ */ React4.createElement("div", { style: { display: "flex", flexDirection: "column", alignItems: "center", justifyContent: "center", flex: 1 } }, ((_b = licenseState.license) == null ? void 0 : _b.isValid) === false && /* @__PURE__ */ React4.createElement(
687
+ }, [dataProvider, dataProviderState, dataProviderSignature, initLicenseValidation, licenseDispatch, usagePermission, offlineDataProvider, offlineDataProviderState, offlineDataProviderSignature, handleValidationResult]);
688
+ return ((_a = licenseState.license) == null ? void 0 : _a.isValid) ? /* @__PURE__ */ React4.createElement(React4.Fragment, null, licenseState.licenseDialogVisible && /* @__PURE__ */ React4.createElement(LicenseDialog, { publisherId, productId, dataProvider, offlineDataProvider, onSubmit: onLicenseDialogFinally, onCancel: onLicenseDialogFinally }), children) : /* @__PURE__ */ React4.createElement("div", { style: { display: "flex", width: "100%", height: "100%", flex: "1" } }, licenseState.licenseDialogVisible && /* @__PURE__ */ React4.createElement(LicenseDialog, { publisherId, productId, dataProvider, offlineDataProvider, onSubmit: onLicenseDialogFinally, onCancel: onLicenseDialogFinally }), licenseState.debugDialogVisible && /* @__PURE__ */ React4.createElement(DebugDialog, { publisherId, productId, environmentType, environmentIdentifier: resolvedEnvironmentIdentifierRef.current || "", dataProvider, offlineDataProvider, onDismiss: onDebugFinally }), /* @__PURE__ */ React4.createElement("div", { style: { display: "flex", flexDirection: "column", alignItems: "center", justifyContent: "center", flex: 1 } }, ((_b = licenseState.license) == null ? void 0 : _b.isValid) === false && /* @__PURE__ */ React4.createElement(
719
689
  import_MessageBar.MessageBar,
720
690
  {
721
691
  messageBarType: import_MessageBar.MessageBarType.error,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ianua/ianus-dataverse-react-fluentui8",
3
- "version": "1.0.12",
3
+ "version": "1.0.13",
4
4
  "description": "Client-side validation for Ianus Guard licenses in Dataverse using react and FluentUi v8",
5
5
  "scripts": {
6
6
  "build": "tsup"