@ianua/ianus-dataverse-react-fluentui8 1.0.8 → 1.0.10

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/dist/index.d.ts CHANGED
@@ -110,10 +110,14 @@ type Action = {
110
110
  } | {
111
111
  type: "setLicenseDialogVisible";
112
112
  payload: boolean;
113
+ } | {
114
+ type: "setDebugDialogVisible";
115
+ payload: boolean;
113
116
  };
114
117
  type IanusLicenseStateProps = {
115
118
  license?: DataverseLicenseValidationResult;
116
119
  licenseDialogVisible?: boolean;
120
+ debugDialogVisible?: boolean;
117
121
  };
118
122
  type IanusLicenseDispatch = (action: Action) => void;
119
123
  declare const IanusLicenseDispatch: React.Context<IanusLicenseDispatch | undefined>;
package/dist/index.js CHANGED
@@ -84,7 +84,7 @@ __export(index_exports, {
84
84
  module.exports = __toCommonJS(index_exports);
85
85
 
86
86
  // src/IanusGuard.tsx
87
- var React3 = __toESM(require("react"));
87
+ var React4 = __toESM(require("react"));
88
88
  var import_MessageBar = require("@fluentui/react/lib/MessageBar");
89
89
  var import_Button = require("@fluentui/react/lib/Button");
90
90
  var import_Spinner = require("@fluentui/react/lib/Spinner");
@@ -242,6 +242,9 @@ function stateReducer(state, action) {
242
242
  case "setLicenseDialogVisible": {
243
243
  return __spreadProps(__spreadValues({}, state), { licenseDialogVisible: action.payload });
244
244
  }
245
+ case "setDebugDialogVisible": {
246
+ return __spreadProps(__spreadValues({}, state), { debugDialogVisible: action.payload });
247
+ }
245
248
  }
246
249
  }
247
250
  var IanusLicenseState = React.createContext(void 0);
@@ -409,6 +412,77 @@ var LicenseDialog = ({ publisherId, productId, dataProvider, offlineDataProvider
409
412
  );
410
413
  };
411
414
 
415
+ // src/DebugDialog.tsx
416
+ var React3 = __toESM(require("react"));
417
+ var import_react2 = require("@fluentui/react");
418
+ var modalProps2 = {
419
+ isBlocking: false,
420
+ styles: {
421
+ main: {
422
+ width: "80vw !important",
423
+ maxWidth: "80vw !important",
424
+ height: "auto",
425
+ maxHeight: "90vh",
426
+ overflowY: "auto",
427
+ overflowX: "auto"
428
+ }
429
+ }
430
+ };
431
+ var dialogContentProps2 = {
432
+ type: import_react2.DialogType.largeHeader,
433
+ title: "Debug"
434
+ };
435
+ var DebugDialog = ({ publisherId, productId, environmentType, environmentIdentifier, dataProvider, offlineDataProvider, onDismiss }) => {
436
+ const [licenseState, licenseDispatch] = useLicenseContext();
437
+ const licenseColumns = [
438
+ { key: "id", name: "Id", fieldName: "ian_licenseid", minWidth: 100, maxWidth: 200, isResizable: true },
439
+ { key: "name", name: "Name", fieldName: "ian_name", minWidth: 100, maxWidth: 200, isResizable: true },
440
+ { key: "identifier", name: "Identifier", fieldName: "ian_identifier", minWidth: 100, maxWidth: 200, isResizable: true },
441
+ { key: "key", name: "Key", fieldName: "ian_key", minWidth: 100, maxWidth: 200, isResizable: true }
442
+ ];
443
+ const mapRecordsToItems = React3.useCallback(
444
+ (dataset) => dataset.sortedRecordIds.map((id) => {
445
+ const record = dataset.records[id];
446
+ return {
447
+ ian_licenseid: record.getRecordId(),
448
+ ian_name: record.getValue("ian_name"),
449
+ ian_identifier: record.getValue("ian_identifier"),
450
+ ian_key: record.getValue("ian_key")
451
+ };
452
+ }),
453
+ []
454
+ );
455
+ return /* @__PURE__ */ React3.createElement(
456
+ import_react2.Dialog,
457
+ {
458
+ hidden: !(licenseState == null ? void 0 : licenseState.debugDialogVisible),
459
+ onDismiss,
460
+ dialogContentProps: dialogContentProps2,
461
+ modalProps: modalProps2
462
+ },
463
+ /* @__PURE__ */ React3.createElement("p", null, /* @__PURE__ */ React3.createElement(import_react2.Text, null, /* @__PURE__ */ React3.createElement("b", null, "Current environment type:"), " ", environmentType), /* @__PURE__ */ React3.createElement(import_react2.Text, null, /* @__PURE__ */ React3.createElement("b", null, "Current environment identifier:"), " ", environmentIdentifier), /* @__PURE__ */ React3.createElement(import_react2.Text, null, /* @__PURE__ */ React3.createElement("b", null, "Target license identifier:"), " ", publisherId, "_", productId), /* @__PURE__ */ React3.createElement("br", null), /* @__PURE__ */ React3.createElement("br", null), isDataset(dataProvider) && /* @__PURE__ */ React3.createElement(React3.Fragment, null, /* @__PURE__ */ React3.createElement(import_react2.Text, null, /* @__PURE__ */ React3.createElement("b", null, "Licenses in data provider:"), " ", dataProvider.sortedRecordIds.length), /* @__PURE__ */ React3.createElement("br", null), /* @__PURE__ */ React3.createElement(
464
+ import_react2.DetailsList,
465
+ {
466
+ items: mapRecordsToItems(dataProvider),
467
+ columns: licenseColumns,
468
+ setKey: "dataProviderList",
469
+ layoutMode: import_react2.DetailsListLayoutMode.fixedColumns,
470
+ selectionMode: 0
471
+ }
472
+ ), /* @__PURE__ */ React3.createElement("br", null)), offlineDataProvider && isDataset(offlineDataProvider) && /* @__PURE__ */ React3.createElement(React3.Fragment, null, /* @__PURE__ */ React3.createElement(import_react2.Text, null, /* @__PURE__ */ React3.createElement("b", null, "Licenses in offline data provider:"), " ", offlineDataProvider.sortedRecordIds.length), /* @__PURE__ */ React3.createElement("br", null), /* @__PURE__ */ React3.createElement(
473
+ import_react2.DetailsList,
474
+ {
475
+ items: mapRecordsToItems(offlineDataProvider),
476
+ columns: licenseColumns,
477
+ setKey: "offlineDataProviderList",
478
+ layoutMode: import_react2.DetailsListLayoutMode.fixedColumns,
479
+ selectionMode: 0
480
+ }
481
+ ), /* @__PURE__ */ React3.createElement("br", null))),
482
+ /* @__PURE__ */ React3.createElement(import_react2.DialogFooter, null, /* @__PURE__ */ React3.createElement(import_react2.PrimaryButton, { onClick: onDismiss, text: "Close" }))
483
+ );
484
+ };
485
+
412
486
  // src/IanusGuard.tsx
413
487
  var isWebApi = (dataProvider) => {
414
488
  return (dataProvider == null ? void 0 : dataProvider.retrieveMultipleRecords) !== void 0;
@@ -436,17 +510,6 @@ var acquireLicenses = (publisherId, productId, dataProvider) => __async(null, nu
436
510
  throw new Error(`The 'dataProvider' prop must be either of type ComponentFramework.WebApi or ComponentFramework.PropertyTypes.Dataset. You passed '${typeof dataProvider}'.`);
437
511
  }
438
512
  });
439
- var updateResultIfDefined = (result, onLicenseValidated) => {
440
- if (onLicenseValidated) {
441
- try {
442
- onLicenseValidated(result);
443
- } catch (e) {
444
- if (e && e instanceof Error) {
445
- console.error(`Error while calling onLicenseValidated: '${e.message}'`);
446
- }
447
- }
448
- }
449
- };
450
513
  var fetchOrganizationIdFromWebApi = (webApi) => __async(null, null, function* () {
451
514
  const results = yield webApi.retrieveMultipleRecords("organization", "?$top=1&$select=organizationid");
452
515
  if (!results.entities.length) {
@@ -456,13 +519,20 @@ var fetchOrganizationIdFromWebApi = (webApi) => __async(null, null, function* ()
456
519
  return organization.organizationid;
457
520
  });
458
521
  var IanusGuard = ({ publisherId, productId, publicKeys, environmentType, environmentIdentifier, dataProvider, offlineDataProvider, usagePermission, onLicenseValidated, children }) => {
459
- var _a, _b, _c, _d;
522
+ var _a, _b, _c, _d, _e;
460
523
  const [licenseState, licenseDispatch] = useLicenseContext();
461
- const onSettingsFinally = () => {
462
- licenseDispatch({ type: "setLicenseDialogVisible", payload: false });
463
- initLicenseValidation();
464
- };
465
- const runValidation = React3.useCallback(() => __async(null, null, function* () {
524
+ const onLicenseValidatedRef = React4.useRef(onLicenseValidated);
525
+ React4.useEffect(() => {
526
+ onLicenseValidatedRef.current = onLicenseValidated;
527
+ }, [onLicenseValidated]);
528
+ const publicKeysRef = React4.useRef(publicKeys);
529
+ React4.useEffect(() => {
530
+ if (JSON.stringify(publicKeys) !== JSON.stringify(publicKeysRef.current)) {
531
+ publicKeysRef.current = publicKeys;
532
+ }
533
+ }, [publicKeys]);
534
+ const resolvedEnvironmentIdentifierRef = React4.useRef(null);
535
+ const runValidation = React4.useCallback(() => __async(null, null, function* () {
466
536
  try {
467
537
  if (!productId) {
468
538
  return {
@@ -471,7 +541,7 @@ var IanusGuard = ({ publisherId, productId, publicKeys, environmentType, environ
471
541
  reason: "No productId found, pass a productId as prop!"
472
542
  };
473
543
  }
474
- if (!publicKeys || !publicKeys.length) {
544
+ if (!publicKeysRef.current || !publicKeysRef.current.length) {
475
545
  return {
476
546
  isValid: false,
477
547
  isTerminalError: true,
@@ -496,8 +566,17 @@ var IanusGuard = ({ publisherId, productId, publicKeys, environmentType, environ
496
566
  };
497
567
  }
498
568
  const licenseRecord = licenses[0];
499
- const resolvedEnvironmentIdentifier = isWebApi(environmentIdentifier) ? yield fetchOrganizationIdFromWebApi(environmentIdentifier) : environmentIdentifier;
500
- const validationResult = yield validateLicense(publisherId, productId, environmentType, resolvedEnvironmentIdentifier, publicKeys, licenseRecord.ian_key);
569
+ if (resolvedEnvironmentIdentifierRef.current === null) {
570
+ resolvedEnvironmentIdentifierRef.current = isWebApi(environmentIdentifier) ? yield fetchOrganizationIdFromWebApi(environmentIdentifier) : environmentIdentifier;
571
+ }
572
+ if (!resolvedEnvironmentIdentifierRef.current) {
573
+ return {
574
+ isValid: false,
575
+ isTerminalError: true,
576
+ reason: `Failed to determine current environment identifier!`
577
+ };
578
+ }
579
+ const validationResult = yield validateLicense(publisherId, productId, environmentType, resolvedEnvironmentIdentifierRef.current, publicKeysRef.current, licenseRecord.ian_key);
501
580
  return __spreadProps(__spreadValues({}, validationResult), {
502
581
  licenseId: licenseRecord.ian_licenseid,
503
582
  licenseKey: licenseRecord.ian_key
@@ -509,16 +588,31 @@ var IanusGuard = ({ publisherId, productId, publicKeys, environmentType, environ
509
588
  reason: e == null ? void 0 : e.message
510
589
  };
511
590
  }
512
- }), [dataProvider, environmentIdentifier, environmentType, offlineDataProvider, productId, publicKeys, publisherId]);
513
- const initLicenseValidation = React3.useCallback(() => __async(null, null, function* () {
591
+ }), [dataProvider, environmentIdentifier, environmentType, offlineDataProvider, productId, publisherId]);
592
+ const initLicenseValidation = React4.useCallback(() => __async(null, null, function* () {
514
593
  const result = yield runValidation();
515
594
  licenseDispatch({ type: "setLicense", payload: result });
516
- updateResultIfDefined(result, onLicenseValidated);
517
- }), [licenseDispatch, onLicenseValidated, runValidation]);
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(() => {
606
+ licenseDispatch({ type: "setLicenseDialogVisible", payload: false });
607
+ initLicenseValidation();
608
+ }, [initLicenseValidation, licenseDispatch]);
609
+ const onDebugFinally = React4.useCallback(() => {
610
+ licenseDispatch({ type: "setDebugDialogVisible", payload: false });
611
+ }, [licenseDispatch]);
518
612
  const dataTotalResultCount = isDataset(dataProvider) ? dataProvider.paging.totalResultCount : void 0;
519
613
  const dataIsLoading = isDataset(dataProvider) ? dataProvider.loading : void 0;
520
614
  const dataHasError = isDataset(dataProvider) ? dataProvider.error : void 0;
521
- const dataProviderState = React3.useMemo(() => {
615
+ const dataProviderState = React4.useMemo(() => {
522
616
  if (!isDataset(dataProvider)) {
523
617
  return "webapi";
524
618
  } else {
@@ -528,26 +622,26 @@ var IanusGuard = ({ publisherId, productId, publicKeys, environmentType, environ
528
622
  const offlineDataTotalResultCount = offlineDataProvider != null ? offlineDataProvider.paging.totalResultCount : void 0;
529
623
  const offlineDataIsLoading = offlineDataProvider != null ? offlineDataProvider.loading : void 0;
530
624
  const offlineDataHasError = offlineDataProvider != null ? offlineDataProvider.error : void 0;
531
- const offlineDataProviderState = React3.useMemo(() => {
625
+ const offlineDataProviderState = React4.useMemo(() => {
532
626
  if (offlineDataProvider == null) {
533
627
  return "unused";
534
628
  } else {
535
629
  return `dataset-${offlineDataTotalResultCount}-${offlineDataIsLoading}-${offlineDataHasError}`;
536
630
  }
537
631
  }, [offlineDataHasError, offlineDataIsLoading, offlineDataProvider, offlineDataTotalResultCount]);
538
- const dataProviderSignature = React3.useMemo(() => {
632
+ const dataProviderSignature = React4.useMemo(() => {
539
633
  if (isDataset(dataProvider) && dataProvider.records) {
540
634
  return Object.values(dataProvider.records).map((r) => `${r.getRecordId()}-${r.getValue("ian_identifier")}-${r.getValue("ian_key")}`).join("|");
541
635
  }
542
636
  return "";
543
637
  }, [dataProvider]);
544
- const offlineDataProviderSignature = React3.useMemo(() => {
638
+ const offlineDataProviderSignature = React4.useMemo(() => {
545
639
  if (offlineDataProvider && offlineDataProvider.records) {
546
640
  return Object.values(offlineDataProvider.records).map((r) => `${r.getRecordId()}-${r.getValue("ian_identifier")}-${r.getValue("ian_key")}`).join("|");
547
641
  }
548
642
  return "";
549
643
  }, [offlineDataProvider]);
550
- React3.useEffect(() => {
644
+ React4.useEffect(() => {
551
645
  console.log(`Starting license evaluation at ${(/* @__PURE__ */ new Date()).toISOString()}`);
552
646
  console.log(`DataProvider state: ${dataProviderState}`);
553
647
  console.log(`DataProvider signature: ${dataProviderSignature}`);
@@ -560,7 +654,15 @@ var IanusGuard = ({ publisherId, productId, publicKeys, environmentType, environ
560
654
  reason: "Your user is not enabled for using this product"
561
655
  };
562
656
  licenseDispatch({ type: "setLicense", payload: result });
563
- updateResultIfDefined(result, onLicenseValidated);
657
+ if (onLicenseValidatedRef.current) {
658
+ try {
659
+ onLicenseValidatedRef.current(result);
660
+ } catch (e) {
661
+ if (e && e instanceof Error) {
662
+ console.error(`Error while calling onLicenseValidated: '${e.message}'`);
663
+ }
664
+ }
665
+ }
564
666
  } else if (!isDataset(dataProvider) || !dataProvider.error && !dataProvider.loading && dataProvider.paging.totalResultCount >= 0 || offlineDataProvider != null && !offlineDataProvider.error && !offlineDataProvider.loading && offlineDataProvider.paging.totalResultCount >= 0) {
565
667
  initLicenseValidation();
566
668
  } else if (dataProvider.error) {
@@ -570,10 +672,18 @@ var IanusGuard = ({ publisherId, productId, publicKeys, environmentType, environ
570
672
  reason: `Dataset error: ${dataProvider.errorMessage}`
571
673
  };
572
674
  licenseDispatch({ type: "setLicense", payload: result });
573
- updateResultIfDefined(result, onLicenseValidated);
675
+ if (onLicenseValidatedRef.current) {
676
+ try {
677
+ onLicenseValidatedRef.current(result);
678
+ } catch (e) {
679
+ if (e && e instanceof Error) {
680
+ console.error(`Error while calling onLicenseValidated: '${e.message}'`);
681
+ }
682
+ }
683
+ }
574
684
  }
575
- }, [dataProvider, dataProviderState, dataProviderSignature, initLicenseValidation, licenseDispatch, usagePermission, onLicenseValidated, offlineDataProvider, offlineDataProviderState, offlineDataProviderSignature]);
576
- return ((_a = licenseState.license) == null ? void 0 : _a.isValid) ? /* @__PURE__ */ React3.createElement(React3.Fragment, null, licenseState.licenseDialogVisible && /* @__PURE__ */ React3.createElement(LicenseDialog, { publisherId, productId, dataProvider, offlineDataProvider, onSubmit: onSettingsFinally, onCancel: onSettingsFinally }), children) : /* @__PURE__ */ React3.createElement("div", { style: { display: "flex", width: "100%", height: "100%", flex: "1" } }, licenseState.licenseDialogVisible && /* @__PURE__ */ React3.createElement(LicenseDialog, { publisherId, productId, dataProvider, offlineDataProvider, onSubmit: onSettingsFinally, onCancel: onSettingsFinally }), /* @__PURE__ */ React3.createElement("div", { style: { display: "flex", flexDirection: "column", alignItems: "center", justifyContent: "center", flex: 1 } }, ((_b = licenseState.license) == null ? void 0 : _b.isValid) === false && /* @__PURE__ */ React3.createElement(
685
+ }, [dataProvider, dataProviderState, dataProviderSignature, initLicenseValidation, licenseDispatch, usagePermission, offlineDataProvider, offlineDataProviderState, offlineDataProviderSignature]);
686
+ 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(
577
687
  import_MessageBar.MessageBar,
578
688
  {
579
689
  messageBarType: import_MessageBar.MessageBarType.error,
@@ -583,17 +693,17 @@ var IanusGuard = ({ publisherId, productId, publicKeys, environmentType, environ
583
693
  licenseDispatch({ type: "setLicense", payload: void 0 });
584
694
  initLicenseValidation();
585
695
  },
586
- actions: /* @__PURE__ */ React3.createElement("div", null, !((_c = licenseState.license) == null ? void 0 : _c.isTerminalError) && /* @__PURE__ */ React3.createElement(import_Button.MessageBarButton, { onClick: () => licenseDispatch({ type: "setLicenseDialogVisible", payload: true }) }, "Set License"))
696
+ actions: /* @__PURE__ */ React4.createElement("div", null, !((_c = licenseState.license) == null ? void 0 : _c.isTerminalError) && /* @__PURE__ */ React4.createElement(import_Button.MessageBarButton, { onClick: () => licenseDispatch({ type: "setLicenseDialogVisible", payload: true }) }, "Set License"), !((_d = licenseState.license) == null ? void 0 : _d.isTerminalError) && /* @__PURE__ */ React4.createElement(import_Button.MessageBarButton, { onClick: () => licenseDispatch({ type: "setDebugDialogVisible", payload: true }) }, "Debug"))
587
697
  },
588
698
  "An error occured, please try again. Error information: ",
589
- (_d = licenseState.license) == null ? void 0 : _d.reason
590
- ), !licenseState.license && /* @__PURE__ */ React3.createElement(import_Spinner.Spinner, { styles: { root: { width: "auto" } }, label: "Loading..." })));
699
+ (_e = licenseState.license) == null ? void 0 : _e.reason
700
+ ), !licenseState.license && /* @__PURE__ */ React4.createElement(import_Spinner.Spinner, { styles: { root: { width: "auto" } }, label: "Loading..." })));
591
701
  };
592
702
 
593
703
  // src/IanusProvider.tsx
594
- var React4 = __toESM(require("react"));
704
+ var React5 = __toESM(require("react"));
595
705
  var IanusProvider = (props) => {
596
- return /* @__PURE__ */ React4.createElement(IanusLicenseStateProvider, null, /* @__PURE__ */ React4.createElement(IanusGuard, __spreadValues({}, props)));
706
+ return /* @__PURE__ */ React5.createElement(IanusLicenseStateProvider, null, /* @__PURE__ */ React5.createElement(IanusGuard, __spreadValues({}, props)));
597
707
  };
598
708
 
599
709
  // ../../../../ianus-core/GuidTools.ts
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ianua/ianus-dataverse-react-fluentui8",
3
- "version": "1.0.8",
3
+ "version": "1.0.10",
4
4
  "description": "Client-side validation for Ianus Guard licenses in Dataverse using react and FluentUi v8",
5
5
  "scripts": {
6
6
  "build": "tsup"