@c8y/ngx-components 1024.10.1 → 1024.10.2

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.
@@ -8,9 +8,9 @@ import { PackageType, Status, WizardHeaderComponent, IconDirective, WizardBodyCo
8
8
  import * as i3 from '@ngx-translate/core';
9
9
  import { saveAs } from 'file-saver';
10
10
  import { groupBy, uniqBy, get, pick, omit, isUndefined, kebabCase, cloneDeep } from 'lodash-es';
11
- import { BehaviorSubject, defer, merge, combineLatest, Subject, pipe } from 'rxjs';
11
+ import { BehaviorSubject, defer, firstValueFrom, merge, combineLatest, Subject, pipe } from 'rxjs';
12
12
  import { map, shareReplay, debounceTime, take, filter, distinctUntilKeyChanged, tap, switchMap, takeUntil } from 'rxjs/operators';
13
- import { satisfies, gt, coerce, lt } from 'semver';
13
+ import { satisfies, gt, coerce, valid, lt } from 'semver';
14
14
  import { NgIf, NgFor, AsyncPipe, NgClass, NgPlural, NgPluralCase, TitleCasePipe } from '@angular/common';
15
15
  import { PopoverDirective, PopoverModule } from 'ngx-bootstrap/popover';
16
16
  import * as i1$1 from '@angular/forms';
@@ -46,6 +46,7 @@ var ERROR_TYPE;
46
46
  ERROR_TYPE["APPLICATION_CREATION_FAILED"] = "APPLICATION_CREATION_FAILED";
47
47
  ERROR_TYPE["KEY_OR_CONTEXT_PATH_MISMATCH"] = "KEY_OR_CONTEXT_PATH_MISMATCH";
48
48
  ERROR_TYPE["VERSION_NOT_FOUND"] = "VERSION_NOT_FOUND";
49
+ ERROR_TYPE["PACKAGE_VERSION_INVALID"] = "PACKAGE_VERSION_INVALID";
49
50
  })(ERROR_TYPE || (ERROR_TYPE = {}));
50
51
  const PRODUCT_EXPERIENCE_ECOSYSTEM = {
51
52
  APPLICATIONS: {
@@ -117,7 +118,8 @@ const ERROR_MESSAGES = {
117
118
  [ERROR_TYPE.MICROSERVICE_NAME_TOO_LONG]: gettext('Microservice name "{{ name }}" must not be longer than {{ maxChars }} characters.'),
118
119
  [ERROR_TYPE.APPLICATION_CREATION_FAILED]: gettext('Application creation failed.'),
119
120
  [ERROR_TYPE.KEY_OR_CONTEXT_PATH_MISMATCH]: gettext('The "contextPath`KEEP_ORIGINAL`" or "key`KEEP_ORIGINAL`" of the uploaded archive do not match with the existing application.'),
120
- [ERROR_TYPE.VERSION_NOT_FOUND]: gettext('The selected version was not found on the server.')
121
+ [ERROR_TYPE.VERSION_NOT_FOUND]: gettext('The selected version was not found on the server.'),
122
+ [ERROR_TYPE.PACKAGE_VERSION_INVALID]: gettext('The package version is missing or invalid. Version field in the manifest must follow semantic versioning.')
121
123
  };
122
124
  const APP_STATE = {
123
125
  SUBSCRIBED: {
@@ -538,7 +540,7 @@ class EcosystemService {
538
540
  const fileBinary = new Blob([binary], { type: 'application/x-zip-compressed' });
539
541
  saveAs(fileBinary, archive.name);
540
542
  }
541
- catch (e) {
543
+ catch {
542
544
  // empty
543
545
  }
544
546
  }
@@ -601,10 +603,27 @@ class EcosystemService {
601
603
  return true;
602
604
  }
603
605
  }
604
- catch (ex) {
606
+ catch {
605
607
  throw new EcosystemError(ERROR_TYPE.TYPE_VALIDATION);
606
608
  }
607
609
  }
610
+ async isValidPackageVersion(archive) {
611
+ let manifest;
612
+ try {
613
+ manifest = await firstValueFrom(this.getCumulocityJson$(archive));
614
+ }
615
+ catch {
616
+ throw new EcosystemError(ERROR_TYPE.TYPE_VALIDATION);
617
+ }
618
+ if (!manifest?.version) {
619
+ throw new EcosystemError(ERROR_TYPE.PACKAGE_VERSION_INVALID);
620
+ }
621
+ const version = manifest.version;
622
+ if (!valid(version)) {
623
+ throw new EcosystemError(ERROR_TYPE.PACKAGE_VERSION_INVALID);
624
+ }
625
+ return true;
626
+ }
608
627
  async uploadArchiveToApp(archive, app, isNewVersion = false, queryParams) {
609
628
  let uploadOverrides;
610
629
  if (isNewVersion) {
@@ -644,6 +663,9 @@ class EcosystemService {
644
663
  if (!manifest) {
645
664
  return;
646
665
  }
666
+ if (this.isPackage(app)) {
667
+ await this.isValidPackageVersion(archive);
668
+ }
647
669
  await this.validatePackageKeyAndContextPath(manifest, app);
648
670
  }
649
671
  async getCumulocityJson(archive) {
@@ -651,7 +673,7 @@ class EcosystemService {
651
673
  const c8yManifest = await this.getCumulocityJson$(archive).toPromise();
652
674
  return c8yManifest;
653
675
  }
654
- catch (ex) {
676
+ catch {
655
677
  return null;
656
678
  }
657
679
  }
@@ -665,7 +687,7 @@ class EcosystemService {
665
687
  appModel = await this.getCumulocityJson$(archive).toPromise();
666
688
  isPackage = appModel.isPackage;
667
689
  }
668
- catch (e) {
690
+ catch {
669
691
  // do nothing, we allow having HOSTED applications without the manifest file
670
692
  }
671
693
  }
@@ -736,7 +758,7 @@ class EcosystemService {
736
758
  const manifest = await this.applicationService.getAppManifest(selectedPackage, requestedVersion);
737
759
  cleanManifest = omit(manifest, ['name', 'contextPath', 'key']);
738
760
  }
739
- catch (ex) {
761
+ catch {
740
762
  throw new EcosystemError(ERROR_TYPE.VERSION_NOT_FOUND);
741
763
  }
742
764
  config.isSetup = true;
@@ -856,7 +878,7 @@ class EcosystemService {
856
878
  const res = await this.applicationService.binary(app).downloadArchive(archive.id);
857
879
  binary = await res.arrayBuffer();
858
880
  }
859
- catch (ex) {
881
+ catch {
860
882
  const msg = gettext('Could not get the binary.');
861
883
  this.alertService.danger(msg);
862
884
  }
@@ -908,7 +930,7 @@ class EcosystemService {
908
930
  const versionedAppManifest = await this.applicationService.getAppManifest(selectedPackage, requestedVersion);
909
931
  manifest = versionedAppManifest;
910
932
  }
911
- catch (ex) {
933
+ catch {
912
934
  throw new EcosystemError(ERROR_TYPE.VERSION_NOT_FOUND);
913
935
  }
914
936
  }