@forge/egress 0.0.0-experimental-c8e9749

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 ADDED
@@ -0,0 +1,47 @@
1
+ # @forge/egress
2
+
3
+ ## 0.0.0-experimental-c8e9749
4
+
5
+ ### Patch Changes
6
+
7
+ - aa19308: Add browser field to package.json
8
+
9
+ ## 1.1.2-next.0
10
+
11
+ ### Patch Changes
12
+
13
+ - aa193085: Add browser field to package.json
14
+
15
+ ## 1.1.1
16
+
17
+ ### Patch Changes
18
+
19
+ - 63d168c: Fix browser compatibility
20
+
21
+ ## 1.1.1-next.0
22
+
23
+ ### Patch Changes
24
+
25
+ - 63d168c: Fix browser compatibility
26
+
27
+ ## 1.1.0
28
+
29
+ ### Minor Changes
30
+
31
+ - 174deac: Add support for browser environments
32
+
33
+ ### Patch Changes
34
+
35
+ - 3c0ac54: Move egress related services out of @forge/csp into new @forge/egress package
36
+
37
+ ## 1.1.0-next.1
38
+
39
+ ### Minor Changes
40
+
41
+ - 174deac: Add support for browser environments
42
+
43
+ ## 1.0.1-next.0
44
+
45
+ ### Patch Changes
46
+
47
+ - 3c0ac54: Move egress related services out of @forge/csp into new @forge/egress package
@@ -0,0 +1,11 @@
1
+ export declare class EgressFilteringService {
2
+ private readonly URLs;
3
+ private readonly wildcardDomains;
4
+ private readonly allowsEverything;
5
+ constructor(allowList: string[]);
6
+ private safeURL;
7
+ isValidUrl(url: string): boolean;
8
+ private domainCheck;
9
+ private domainIsAllowed;
10
+ }
11
+ //# sourceMappingURL=egress-filtering-service.d.ts.map
@@ -0,0 +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;IAMnB,OAAO,CAAC,eAAe;CAWxB"}
@@ -0,0 +1,42 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.EgressFilteringService = void 0;
4
+ const tslib_1 = require("tslib");
5
+ const minimatch_1 = tslib_1.__importDefault(require("minimatch"));
6
+ const url_1 = require("url");
7
+ class EgressFilteringService {
8
+ constructor(allowList) {
9
+ this.URLs = allowList.filter((domainOrURL) => !domainOrURL.startsWith('*')).map((url) => this.safeURL(url));
10
+ this.wildcardDomains = allowList
11
+ .filter((domainOrURL) => domainOrURL !== '*')
12
+ .map((url) => this.safeURL(url))
13
+ .filter((url) => decodeURIComponent(url.hostname).startsWith('*'));
14
+ this.allowsEverything = allowList.includes('*');
15
+ }
16
+ safeURL(url, defaultProtocol = 'https://') {
17
+ const protocolRegex = /^(.*:\/\/)/;
18
+ const urlParser = url_1.URL !== null && url_1.URL !== void 0 ? url_1.URL : window.URL;
19
+ return new urlParser(protocolRegex.test(url) ? url : `${defaultProtocol}${url}`);
20
+ }
21
+ isValidUrl(url) {
22
+ if (this.allowsEverything) {
23
+ return true;
24
+ }
25
+ return this.domainIsAllowed(this.safeURL(url));
26
+ }
27
+ domainCheck(domain, allowList) {
28
+ return allowList
29
+ .filter((allowed) => allowed.protocol === domain.protocol)
30
+ .some((url) => (0, minimatch_1.default)(domain.hostname, decodeURIComponent(url.hostname)));
31
+ }
32
+ domainIsAllowed(domain) {
33
+ if (this.domainCheck(domain, this.URLs)) {
34
+ return true;
35
+ }
36
+ if (this.domainCheck(domain, this.wildcardDomains)) {
37
+ return true;
38
+ }
39
+ return false;
40
+ }
41
+ }
42
+ exports.EgressFilteringService = EgressFilteringService;
@@ -0,0 +1,3 @@
1
+ export * from './egress-filtering-service';
2
+ export * from './utils';
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/egress/index.ts"],"names":[],"mappings":"AAEA,cAAc,4BAA4B,CAAC;AAC3C,cAAc,SAAS,CAAC"}
@@ -0,0 +1,5 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const tslib_1 = require("tslib");
4
+ tslib_1.__exportStar(require("./egress-filtering-service"), exports);
5
+ tslib_1.__exportStar(require("./utils"), exports);
@@ -0,0 +1,3 @@
1
+ declare const sortAndGroupEgressPermissionsByDomain: (egressAddresses: string[]) => Array<string>;
2
+ export { sortAndGroupEgressPermissionsByDomain };
3
+ //# sourceMappingURL=utils.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../src/egress/utils.ts"],"names":[],"mappings":"AAGA,QAAA,MAAM,qCAAqC,oBAAqB,MAAM,EAAE,KAAG,MAAM,MAAM,CA6BtF,CAAC;AAEF,OAAO,EAAE,qCAAqC,EAAE,CAAC"}
@@ -0,0 +1,31 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.sortAndGroupEgressPermissionsByDomain = void 0;
4
+ const minimatch_1 = require("minimatch");
5
+ const url_1 = require("url");
6
+ const sortAndGroupEgressPermissionsByDomain = (egressAddresses) => {
7
+ if ((egressAddresses === null || egressAddresses === void 0 ? void 0 : egressAddresses.length) === 0) {
8
+ return [];
9
+ }
10
+ const protocolRegex = /^(.*?:\/\/)/;
11
+ const domains = new Set();
12
+ const wildcardDomains = [];
13
+ egressAddresses.forEach((item) => {
14
+ const itemWithProtocol = protocolRegex.test(item) ? item : `https://${item}`;
15
+ const url = new url_1.URL(itemWithProtocol);
16
+ if (url.hostname.startsWith('*')) {
17
+ domains.add(url.hostname.substring(2));
18
+ wildcardDomains.push((0, minimatch_1.makeRe)(url.hostname));
19
+ }
20
+ else {
21
+ domains.add(url.hostname);
22
+ }
23
+ });
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
+ };
31
+ exports.sortAndGroupEgressPermissionsByDomain = sortAndGroupEgressPermissionsByDomain;
package/out/index.d.ts ADDED
@@ -0,0 +1,2 @@
1
+ export * from './egress';
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,UAAU,CAAC"}
package/out/index.js ADDED
@@ -0,0 +1,4 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const tslib_1 = require("tslib");
4
+ tslib_1.__exportStar(require("./egress"), exports);
package/package.json ADDED
@@ -0,0 +1,21 @@
1
+ {
2
+ "name": "@forge/egress",
3
+ "version": "0.0.0-experimental-c8e9749",
4
+ "description": "Helpers and utils for egress implementation in Forge apps",
5
+ "main": "out/index.js",
6
+ "author": "Atlassian",
7
+ "license": "UNLICENSED",
8
+ "browser": "out/index.js",
9
+ "types": "out/index.d.ts",
10
+ "scripts": {
11
+ "build": "yarn run clean && yarn run compile",
12
+ "compile": "tsc -b -v",
13
+ "clean": "rm -rf ./out && rm -f tsconfig.tsbuildinfo"
14
+ },
15
+ "devDependencies": {
16
+ "@types/jest": "^29.1.2"
17
+ },
18
+ "dependencies": {
19
+ "minimatch": "^5.1.0"
20
+ }
21
+ }