@forge/egress 1.1.0 → 1.1.1-next.0

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/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # @forge/egress
2
2
 
3
+ ## 1.1.1-next.0
4
+
5
+ ### Patch Changes
6
+
7
+ - 63d168c: Fix browser compatibility
8
+
3
9
  ## 1.1.0
4
10
 
5
11
  ### Minor Changes
@@ -1 +1 @@
1
- {"version":3,"file":"egress-filtering-service.d.ts","sourceRoot":"","sources":["../../src/egress/egress-filtering-service.ts"],"names":[],"mappings":"AAGA,qBAAa,sBAAsB;IACjC,OAAO,CAAC,QAAQ,CAAC,IAAI,CAAQ;IAC7B,OAAO,CAAC,QAAQ,CAAC,eAAe,CAAQ;IACxC,OAAO,CAAC,QAAQ,CAAC,gBAAgB,CAAU;gBAE/B,SAAS,EAAE,MAAM,EAAE;IAU/B,OAAO,CAAC,OAAO;IAQR,UAAU,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO;IAQvC,OAAO,CAAC,WAAW;IAWnB,OAAO,CAAC,eAAe;CAWxB"}
1
+ {"version":3,"file":"egress-filtering-service.d.ts","sourceRoot":"","sources":["../../src/egress/egress-filtering-service.ts"],"names":[],"mappings":"AAGA,qBAAa,sBAAsB;IACjC,OAAO,CAAC,QAAQ,CAAC,IAAI,CAAQ;IAC7B,OAAO,CAAC,QAAQ,CAAC,eAAe,CAAQ;IACxC,OAAO,CAAC,QAAQ,CAAC,gBAAgB,CAAU;gBAE/B,SAAS,EAAE,MAAM,EAAE;IAU/B,OAAO,CAAC,OAAO;IAQR,UAAU,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO;IAQvC,OAAO,CAAC,WAAW;IAMnB,OAAO,CAAC,eAAe;CAWxB"}
@@ -2,7 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.EgressFilteringService = void 0;
4
4
  const tslib_1 = require("tslib");
5
- const micromatch_1 = tslib_1.__importDefault(require("micromatch"));
5
+ const minimatch_1 = tslib_1.__importDefault(require("minimatch"));
6
6
  const url_1 = require("url");
7
7
  class EgressFilteringService {
8
8
  constructor(allowList) {
@@ -25,12 +25,9 @@ class EgressFilteringService {
25
25
  return this.domainIsAllowed(this.safeURL(url));
26
26
  }
27
27
  domainCheck(domain, allowList) {
28
- const hostnameMatchedProtocol = allowList
28
+ return allowList
29
29
  .filter((allowed) => allowed.protocol === domain.protocol)
30
- .map((url) => decodeURIComponent(url.hostname));
31
- return (micromatch_1.default([domain.hostname], hostnameMatchedProtocol, {
32
- dot: true
33
- }).length > 0);
30
+ .some((url) => minimatch_1.default(domain.hostname, decodeURIComponent(url.hostname)));
34
31
  }
35
32
  domainIsAllowed(domain) {
36
33
  if (this.domainCheck(domain, this.URLs)) {
@@ -1 +1 @@
1
- {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../src/egress/utils.ts"],"names":[],"mappings":"AAGA,QAAA,MAAM,qCAAqC,oBAAqB,MAAM,EAAE,KAAG,KAAK,CAAC,MAAM,CA2BtF,CAAC;AAEF,OAAO,EAAE,qCAAqC,EAAE,CAAC"}
1
+ {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../src/egress/utils.ts"],"names":[],"mappings":"AAGA,QAAA,MAAM,qCAAqC,oBAAqB,MAAM,EAAE,KAAG,KAAK,CAAC,MAAM,CA6BtF,CAAC;AAEF,OAAO,EAAE,qCAAqC,EAAE,CAAC"}
@@ -1,31 +1,31 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.sortAndGroupEgressPermissionsByDomain = void 0;
4
- const tslib_1 = require("tslib");
5
- const micromatch_1 = tslib_1.__importDefault(require("micromatch"));
4
+ const minimatch_1 = require("minimatch");
6
5
  const url_1 = require("url");
7
6
  const sortAndGroupEgressPermissionsByDomain = (egressAddresses) => {
8
- const protocolRegex = /^(.*?:\/\/)/;
9
- const domainSet = new Set();
10
- const groupSet = new Set();
11
- const removeSet = new Set();
12
7
  if ((egressAddresses === null || egressAddresses === void 0 ? void 0 : egressAddresses.length) === 0) {
13
8
  return [];
14
9
  }
10
+ const protocolRegex = /^(.*?:\/\/)/;
11
+ const domains = new Set();
12
+ const wildcardDomains = [];
15
13
  egressAddresses.forEach((item) => {
16
14
  const itemWithProtocol = protocolRegex.test(item) ? item : `https://${item}`;
17
15
  const url = new url_1.URL(itemWithProtocol);
18
16
  if (url.hostname.startsWith('*')) {
19
- groupSet.add(url.hostname.substring(2));
20
- removeSet.add('!' + url.hostname);
17
+ domains.add(url.hostname.substring(2));
18
+ wildcardDomains.push(minimatch_1.makeRe(url.hostname));
21
19
  }
22
20
  else {
23
- domainSet.add(url.hostname);
21
+ domains.add(url.hostname);
24
22
  }
25
23
  });
26
- if (removeSet.size === 0) {
27
- return [...domainSet];
28
- }
29
- return [...new Set(micromatch_1.default([...domainSet], [...removeSet]).concat([...groupSet]))].sort();
24
+ return [...domains].sort().reduce((grouped, domain) => {
25
+ if (!wildcardDomains.some((wcd) => wcd.test(domain))) {
26
+ grouped.push(domain);
27
+ }
28
+ return grouped;
29
+ }, []);
30
30
  };
31
31
  exports.sortAndGroupEgressPermissionsByDomain = sortAndGroupEgressPermissionsByDomain;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@forge/egress",
3
- "version": "1.1.0",
3
+ "version": "1.1.1-next.0",
4
4
  "description": "Helpers and utils for egress implementation in Forge apps",
5
5
  "main": "out/index.js",
6
6
  "author": "Atlassian",
@@ -14,6 +14,6 @@
14
14
  "@types/jest": "^26.0.0"
15
15
  },
16
16
  "dependencies": {
17
- "micromatch": "^4.0.2"
17
+ "minimatch": "^5.1.0"
18
18
  }
19
19
  }