@forge/manifest 3.1.0-next.0 → 3.1.0-next.4

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.
@@ -3,7 +3,10 @@ import { ValidatorInterface } from './validator-interface';
3
3
  import { ManifestSchema } from '../schema/manifest';
4
4
  export interface MappingEntry {
5
5
  productEvent: string;
6
- oAuthScopes: string[];
6
+ oAuthScopes: {
7
+ current: string[];
8
+ deprecated?: string[];
9
+ };
7
10
  }
8
11
  export interface MappingConfig {
9
12
  mapping: MappingEntry[];
@@ -1 +1 @@
1
- {"version":3,"file":"product-trigger-scopes-validator.d.ts","sourceRoot":"","sources":["../../src/validators/product-trigger-scopes-validator.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,wBAAwB,EAAmB,MAAM,UAAU,CAAC;AACrF,OAAO,EAAE,kBAAkB,EAAE,MAAM,uBAAuB,CAAC;AAC3D,OAAO,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AAIpD,MAAM,WAAW,YAAY;IAC3B,YAAY,EAAE,MAAM,CAAC;IACrB,WAAW,EAAE,MAAM,EAAE,CAAC;CACvB;AAED,MAAM,WAAW,aAAa;IAC5B,OAAO,EAAE,YAAY,EAAE,CAAC;CACzB;AAED,qBAAa,6BAA6B,CAAC,CAAC,CAC1C,YAAW,kBAAkB,CAAC,cAAc,CAAC,cAAc,CAAC,GAAG,SAAS,EAAE,cAAc,CAAC;IAC7E,OAAO,CAAC,QAAQ,CAAC,MAAM;gBAAN,MAAM,EAAE,aAAa;IAElD,QAAQ,CAAC,QAAQ,EAAE,cAAc,CAAC,cAAc,CAAC,GAAG,SAAS,GAAG,wBAAwB,CAAC,cAAc,CAAC;CAgDzG"}
1
+ {"version":3,"file":"product-trigger-scopes-validator.d.ts","sourceRoot":"","sources":["../../src/validators/product-trigger-scopes-validator.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,wBAAwB,EAAmB,MAAM,UAAU,CAAC;AACrF,OAAO,EAAE,kBAAkB,EAAE,MAAM,uBAAuB,CAAC;AAC3D,OAAO,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AAIpD,MAAM,WAAW,YAAY;IAC3B,YAAY,EAAE,MAAM,CAAC;IACrB,WAAW,EAAE;QACX,OAAO,EAAE,MAAM,EAAE,CAAC;QAClB,UAAU,CAAC,EAAE,MAAM,EAAE,CAAC;KACvB,CAAC;CACH;AAED,MAAM,WAAW,aAAa;IAC5B,OAAO,EAAE,YAAY,EAAE,CAAC;CACzB;AAED,qBAAa,6BAA6B,CAAC,CAAC,CAC1C,YAAW,kBAAkB,CAAC,cAAc,CAAC,cAAc,CAAC,GAAG,SAAS,EAAE,cAAc,CAAC;IAC7E,OAAO,CAAC,QAAQ,CAAC,MAAM;gBAAN,MAAM,EAAE,aAAa;IAElD,QAAQ,CAAC,QAAQ,EAAE,cAAc,CAAC,cAAc,CAAC,GAAG,SAAS,GAAG,wBAAwB,CAAC,cAAc,CAAC;CAsEzG"}
@@ -16,9 +16,9 @@ class ProductTriggerScopesValidator {
16
16
  };
17
17
  }
18
18
  const validationErrors = [];
19
- const getRequiredScopesForProductEvent = (productEvent) => {
19
+ const getRequiredScopes = (productEvent, status) => {
20
20
  var _a;
21
- return ((_a = this.config.mapping.find((value) => value.productEvent == productEvent)) === null || _a === void 0 ? void 0 : _a.oAuthScopes) || [];
21
+ return (_a = this.config.mapping.find((value) => value.productEvent == productEvent)) === null || _a === void 0 ? void 0 : _a.oAuthScopes[status];
22
22
  };
23
23
  const addValidationError = (scope, event) => {
24
24
  validationErrors.push(Object.assign({ message: text_1.errors.permissions.missingPermissionFromScope(scope, event), reference: text_1.References.MissingScopes, level: 'error', metadata: {
@@ -33,11 +33,27 @@ class ProductTriggerScopesValidator {
33
33
  }
34
34
  const manifestScopes = ((_a = manifest.typedContent.permissions) === null || _a === void 0 ? void 0 : _a.scopes) || [];
35
35
  manifest.typedContent.modules.trigger.forEach((element) => {
36
- element.events.forEach((event) => {
37
- const requiredScopes = getRequiredScopesForProductEvent(event);
38
- const missingScopes = requiredScopes.filter((requiredScope) => !manifestScopes.includes(requiredScope));
39
- missingScopes.forEach((missingScope) => addValidationError(missingScope, event));
40
- });
36
+ for (const event of element.events) {
37
+ const currentScopes = getRequiredScopes(event, 'current');
38
+ if (!currentScopes)
39
+ continue;
40
+ const missingCurrentScopes = currentScopes.filter((scope) => !manifestScopes.includes(scope));
41
+ if (missingCurrentScopes.length === 0)
42
+ continue;
43
+ const deprecatedScopes = getRequiredScopes(event, 'deprecated');
44
+ const missingDeprecatedScopes = deprecatedScopes === null || deprecatedScopes === void 0 ? void 0 : deprecatedScopes.filter((scope) => !manifestScopes.includes(scope));
45
+ if ((missingDeprecatedScopes === null || missingDeprecatedScopes === void 0 ? void 0 : missingDeprecatedScopes.length) === 0)
46
+ continue;
47
+ if (missingCurrentScopes.length < currentScopes.length) {
48
+ missingCurrentScopes.forEach((scope) => addValidationError(scope, event));
49
+ continue;
50
+ }
51
+ if (missingDeprecatedScopes && deprecatedScopes && missingDeprecatedScopes.length < deprecatedScopes.length) {
52
+ missingDeprecatedScopes.forEach((scope) => addValidationError(scope, event));
53
+ continue;
54
+ }
55
+ missingCurrentScopes.forEach((scope) => addValidationError(scope, event));
56
+ }
41
57
  });
42
58
  return {
43
59
  success: validationErrors.length === 0,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@forge/manifest",
3
- "version": "3.1.0-next.0",
3
+ "version": "3.1.0-next.4",
4
4
  "description": "Definitions and validations of the Forge manifest",
5
5
  "main": "out/index.js",
6
6
  "scripts": {