@forge/cache 0.7.0-next.2 → 0.7.0-next.3

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.
@@ -1,12 +1,16 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ const tslib_1 = require("tslib");
4
+ const node_fetch_1 = tslib_1.__importDefault(require("node-fetch"));
3
5
  const api_1 = require("@forge/api");
4
6
  const cache_1 = require("../cache");
7
+ jest.mock('node-fetch');
8
+ const fetchMock = node_fetch_1.default;
5
9
  describe('connect', () => {
6
- let fetchMock;
7
10
  describe('v1', () => {
8
11
  beforeEach(() => {
9
- fetchMock = jest.fn();
12
+ jest.resetAllMocks();
13
+ jest.clearAllMocks();
10
14
  global['api'] = { requestRmsStore: fetchMock };
11
15
  });
12
16
  afterAll(() => {
@@ -18,12 +22,7 @@ describe('connect', () => {
18
22
  });
19
23
  });
20
24
  describe('v2', () => {
21
- let fetchMock;
22
- let orgFetch;
23
25
  beforeEach(() => {
24
- fetchMock = jest.fn();
25
- orgFetch = global['fetch'];
26
- global['fetch'] = fetchMock;
27
26
  global['__forge_runtime__'] = {
28
27
  proxy: {
29
28
  token: 'token',
@@ -39,9 +38,6 @@ describe('connect', () => {
39
38
  }
40
39
  };
41
40
  });
42
- afterAll(() => {
43
- global['fetch'] = orgFetch;
44
- });
45
41
  it('chooses the v2 fetch based on runtime', async () => {
46
42
  const cacheClient = (0, cache_1.connect)();
47
43
  await cacheClient['client']('asdf');
@@ -50,16 +46,6 @@ describe('connect', () => {
50
46
  });
51
47
  });
52
48
  describe('createFetch', () => {
53
- let fetchMock;
54
- let orgFetch;
55
- beforeEach(() => {
56
- fetchMock = jest.fn();
57
- orgFetch = global['fetch'];
58
- global['fetch'] = fetchMock;
59
- });
60
- afterAll(() => {
61
- global['fetch'] = orgFetch;
62
- });
63
49
  it('fetch fails when rms config is not available', async () => {
64
50
  global['__forge_runtime__'] = {
65
51
  proxy: {
@@ -88,8 +74,8 @@ describe('createFetch', () => {
88
74
  const fetch = (0, cache_1.createFetchRmsRuntimeV2)();
89
75
  await fetch('path');
90
76
  const [absoluteUrl, options] = (_a = fetchMock.mock.lastCall) !== null && _a !== void 0 ? _a : ['', {}];
91
- expect(absoluteUrl).toEqual('https://dev.services.atlassian.com/path');
92
- expect((options === null || options === void 0 ? void 0 : options.agent)['keepAlive']).toBeTruthy();
77
+ expect(absoluteUrl.toString()).toEqual('https://rms/path');
78
+ expect((options === null || options === void 0 ? void 0 : options.agent)['passthrough']['keepAlive']).toBeTruthy();
93
79
  expect(options === null || options === void 0 ? void 0 : options.headers).toMatchObject({
94
80
  Authorization: 'Bearer token',
95
81
  Host: 'rockmelon-storage.dev.atl-paas.net',
@@ -1 +1 @@
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;AAInF,oBAAY,QAAQ,GAAG,IAAI,CAAC,iBAAiB,EAAE,MAAM,GAAG,IAAI,GAAG,QAAQ,CAAC,CAAC;AAEzE,oBAAY,UAAU,GAAG;IACvB,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,MAAM,EAAE,CAAC;CAChB,CAAC;AAGF,wBAAsB,eAAe,CAAC,QAAQ,EAAE,QAAQ,GAAG,OAAO,CAAC,GAAG,CAAC,CAYtE;AAED,qBAAa,KAAK;IACJ,OAAO,CAAC,MAAM;gBAAN,MAAM,EAAE,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,WAAW,KAAK,OAAO,CAAC,QAAQ,CAAC;IAGtF,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;IAM5E,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AAC;IAO3F,eAAe,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;IAO7C,eAAe,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;IAO7C,MAAM,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;IAOpC,IAAI,CAAC,OAAO,EAAE,MAAM,EAAE,GAAG,CAAC,EAAE;QAAE,MAAM,CAAC,EAAE,MAAM,CAAC;QAAC,KAAK,CAAC,EAAE,MAAM,CAAA;KAAE,GAAG,OAAO,CAAC,UAAU,CAAC;IAOrF,QAAQ,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;IAOrD,QAAQ,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC;IAO7C,UAAU,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;CAMtD;AAED,wBAAgB,oBAAoB,IAAI,CAAC,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,WAAW,KAAK,OAAO,CAAC,QAAQ,CAAC,CAAC,GAAG,SAAS,CAG/G;AAID,wBAAgB,uBAAuB,IAAI,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,WAAW,KAAK,OAAO,CAAC,QAAQ,CAAC,CA0BpG;AAED,wBAAgB,OAAO,UAItB"}
package/out/cache.js CHANGED
@@ -1,7 +1,9 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.connect = exports.createFetchRmsRuntimeV2 = exports.getFetchRmsRuntimeV1 = exports.Cache = exports.getResponseBody = void 0;
4
+ const tslib_1 = require("tslib");
4
5
  const https_1 = require("https");
6
+ const node_fetch_1 = tslib_1.__importDefault(require("node-fetch"));
5
7
  const api_1 = require("@forge/api");
6
8
  async function getResponseBody(response) {
7
9
  const responseText = await response.text();
@@ -97,8 +99,9 @@ function createFetchRmsRuntimeV2() {
97
99
  if (!(rms === null || rms === void 0 ? void 0 : rms.url) || !(rms === null || rms === void 0 ? void 0 : rms.host)) {
98
100
  throw new Error('RMS config not available.');
99
101
  }
100
- const rmsFullUrl = new URL(rms.url) + path;
101
- 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, 'x-b3-traceid': tracing.traceId, 'x-b3-spanid': tracing.spanId }) }));
102
+ const rmsAgent = new String('FORGE_PRODUCT_REQUEST');
103
+ rmsAgent['passthrough'] = agent;
104
+ return await (0, node_fetch_1.default)(new URL(path, 'https://rms/'), Object.assign(Object.assign({}, options), { agent: rmsAgent, headers: Object.assign(Object.assign({}, options === null || options === void 0 ? void 0 : options.headers), { Authorization: `Bearer ${proxy.token}`, Host: rms.host, 'x-b3-traceid': tracing.traceId, 'x-b3-spanid': tracing.spanId }) }));
102
105
  };
103
106
  }
104
107
  exports.createFetchRmsRuntimeV2 = createFetchRmsRuntimeV2;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@forge/cache",
3
- "version": "0.7.0-next.2",
3
+ "version": "0.7.0-next.3",
4
4
  "description": "Forge Cache methods",
5
5
  "author": "Atlassian",
6
6
  "license": "UNLICENSED",