@forge/cache 0.1.0-next.0 → 0.1.0-next.1
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/out/__test__/cache.test.js +18 -10
- package/out/cache.d.ts.map +1 -1
- package/out/cache.js +5 -15
- package/package.json +3 -3
|
@@ -13,27 +13,35 @@ describe('createFetch', () => {
|
|
|
13
13
|
afterAll(() => {
|
|
14
14
|
global['fetch'] = orgFetch;
|
|
15
15
|
});
|
|
16
|
-
it
|
|
17
|
-
['
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
16
|
+
it('fetch fails when rms config is not available', async () => {
|
|
17
|
+
global['__forge_runtime__'] = {
|
|
18
|
+
proxy: {
|
|
19
|
+
token: 'token',
|
|
20
|
+
url: 'https://proxy.atlassian.com'
|
|
21
|
+
}
|
|
22
|
+
};
|
|
23
|
+
expect(cache_1.createFetch).toThrowError(new Error('RMS config not available.'));
|
|
24
|
+
});
|
|
25
|
+
it('creates a fetch that adds the right headers and url', async () => {
|
|
21
26
|
var _a;
|
|
22
27
|
global['__forge_runtime__'] = {
|
|
23
28
|
proxy: {
|
|
24
29
|
token: 'token',
|
|
25
|
-
url:
|
|
30
|
+
url: 'https://proxy.atlassian.com'
|
|
26
31
|
},
|
|
27
|
-
|
|
32
|
+
rms: {
|
|
33
|
+
url: 'https://dev.services.atlassian.com',
|
|
34
|
+
host: 'rockmelon-storage.dev.atl-paas.net'
|
|
35
|
+
}
|
|
28
36
|
};
|
|
29
37
|
const fetch = (0, cache_1.createFetch)();
|
|
30
|
-
await fetch('
|
|
38
|
+
await fetch('path');
|
|
31
39
|
const [absoluteUrl, options] = (_a = fetchMock.mock.lastCall) !== null && _a !== void 0 ? _a : ['', {}];
|
|
32
|
-
expect(absoluteUrl).toEqual('
|
|
40
|
+
expect(absoluteUrl).toEqual('https://dev.services.atlassian.com/path');
|
|
33
41
|
expect((options === null || options === void 0 ? void 0 : options.agent)['keepAlive']).toBeTruthy();
|
|
34
42
|
expect(options === null || options === void 0 ? void 0 : options.headers).toMatchObject({
|
|
35
43
|
Authorization: 'Bearer token',
|
|
36
|
-
Host:
|
|
44
|
+
Host: 'rockmelon-storage.dev.atl-paas.net'
|
|
37
45
|
});
|
|
38
46
|
});
|
|
39
47
|
});
|
package/out/cache.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cache.d.ts","sourceRoot":"","sources":["../src/cache.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"cache.d.ts","sourceRoot":"","sources":["../src/cache.ts"],"names":[],"mappings":"AACA,OAAkB,EAAE,WAAW,EAAE,QAAQ,IAAI,iBAAiB,EAAE,MAAM,YAAY,CAAC;AAEnF,OAAO,EAAmB,OAAO,EAAE,MAAM,gBAAgB,CAAC;AAG1D,oBAAY,QAAQ,GAAG,IAAI,CAAC,iBAAiB,EAAE,MAAM,GAAG,IAAI,GAAG,QAAQ,CAAC,CAAC;AAGzE,wBAAsB,eAAe,CAAC,QAAQ,EAAE,QAAQ,GAAG,OAAO,CAAC,GAAG,CAAC,CAYtE;AAED,qBAAa,KAAK;IACJ,OAAO,CAAC,OAAO;IAAW,OAAO,CAAC,MAAM;gBAAhC,OAAO,EAAE,OAAO,EAAU,MAAM,EAAE,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,WAAW,KAAK,OAAO,CAAC,QAAQ,CAAC;IAEhH,OAAO,CAAC,YAAY;IAUP,GAAG,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,GAAG,CAAC,EAAE;QAAE,UAAU,EAAE,MAAM,CAAA;KAAE,GAAG,OAAO,CAAC,IAAI,CAAC;IAQ5E,cAAc,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,GAAG,CAAC,EAAE;QAAE,UAAU,EAAE,MAAM,CAAA;KAAE,GAAG,OAAO,CAAC,IAAI,GAAG,IAAI,CAAC;IAS9F,GAAG,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;IASjC,eAAe,CAAC,GAAG,EAAE,MAAM,EAAE,GAAG,CAAC,EAAE;QAAE,UAAU,EAAE,MAAM,CAAA;KAAE,GAAG,OAAO,CAAC,MAAM,CAAC;CAQzF;AAID,wBAAgB,WAAW,IAAI,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,WAAW,KAAK,OAAO,CAAC,QAAQ,CAAC,CAwBxF;AAGD,wBAAgB,OAAO,UAEtB"}
|
package/out/cache.js
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.connect = exports.createFetch = exports.Cache = exports.getResponseBody = void 0;
|
|
4
|
-
const path_1 = require("path");
|
|
5
4
|
const https_1 = require("https");
|
|
6
5
|
const api_1 = require("@forge/api");
|
|
7
6
|
const metrics_1 = require("@forge/metrics");
|
|
@@ -61,24 +60,15 @@ class Cache {
|
|
|
61
60
|
}
|
|
62
61
|
}
|
|
63
62
|
exports.Cache = Cache;
|
|
64
|
-
function determineHost(proxyUrl) {
|
|
65
|
-
if (proxyUrl.includes('dev.services.atlassian.com')) {
|
|
66
|
-
return 'rockmelon-storage.dev.atl-paas.net';
|
|
67
|
-
}
|
|
68
|
-
else if (proxyUrl.includes('stg.services.atlassian.com')) {
|
|
69
|
-
return 'rockmelon-storage.staging.atl-paas.net';
|
|
70
|
-
}
|
|
71
|
-
return 'rockmelon-storage.prod.atl-paas.net';
|
|
72
|
-
}
|
|
73
63
|
function createFetch() {
|
|
74
|
-
const { proxy,
|
|
75
|
-
const host = determineHost(proxy.url);
|
|
64
|
+
const { proxy, rms } = (0, api_1.getRuntime)();
|
|
76
65
|
const agent = new https_1.Agent({ keepAlive: true });
|
|
77
|
-
if (!
|
|
78
|
-
throw new Error('
|
|
66
|
+
if (!rms) {
|
|
67
|
+
throw new Error('RMS config not available.');
|
|
79
68
|
}
|
|
80
69
|
return async function (path, options) {
|
|
81
|
-
|
|
70
|
+
const rmsFullUrl = new URL(rms.url) + path;
|
|
71
|
+
return await global['fetch'](rmsFullUrl, Object.assign(Object.assign({}, options), { agent, headers: Object.assign(Object.assign({}, options === null || options === void 0 ? void 0 : options.headers), { Authorization: `Bearer ${proxy.token}`, Host: rms.host }) }));
|
|
82
72
|
};
|
|
83
73
|
}
|
|
84
74
|
exports.createFetch = createFetch;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@forge/cache",
|
|
3
|
-
"version": "0.1.0-next.
|
|
3
|
+
"version": "0.1.0-next.1",
|
|
4
4
|
"description": "Forge Cache methods",
|
|
5
5
|
"author": "Atlassian",
|
|
6
6
|
"license": "UNLICENSED",
|
|
@@ -20,7 +20,7 @@
|
|
|
20
20
|
"node-fetch": "2.6.7"
|
|
21
21
|
},
|
|
22
22
|
"dependencies": {
|
|
23
|
-
"@forge/api": "^2.16.0-next.
|
|
24
|
-
"@forge/metrics": "^0.1.9-next.
|
|
23
|
+
"@forge/api": "^2.16.0-next.2",
|
|
24
|
+
"@forge/metrics": "^0.1.9-next.3"
|
|
25
25
|
}
|
|
26
26
|
}
|