@forge/cache 0.7.5-next.0 → 0.7.5

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.
@@ -56,7 +56,6 @@ describe('createFetch', () => {
56
56
  await expect((0, cache_1.createFetchRmsRuntimeV2)()).rejects.toThrowError(new Error('RMS config not available.'));
57
57
  });
58
58
  it('creates a fetch that adds the right headers and url', async () => {
59
- var _a;
60
59
  global['__forge_runtime__'] = {
61
60
  proxy: {
62
61
  token: 'token',
@@ -73,10 +72,10 @@ describe('createFetch', () => {
73
72
  };
74
73
  const fetch = (0, cache_1.createFetchRmsRuntimeV2)();
75
74
  await fetch('path');
76
- const [absoluteUrl, options] = (_a = fetchMock.mock.lastCall) !== null && _a !== void 0 ? _a : ['', {}];
75
+ const [absoluteUrl, options] = fetchMock.mock.lastCall ?? ['', {}];
77
76
  expect(absoluteUrl.toString()).toEqual('https://rms/path');
78
- expect((options === null || options === void 0 ? void 0 : options.agent)['passthrough']['keepAlive']).toBeTruthy();
79
- expect(options === null || options === void 0 ? void 0 : options.headers).toMatchObject({
77
+ expect((options?.agent)['passthrough']['keepAlive']).toBeTruthy();
78
+ expect(options?.headers).toMatchObject({
80
79
  Authorization: 'Bearer token',
81
80
  Host: 'rockmelon-storage.dev.atl-paas.net',
82
81
  'x-b3-traceid': 'trace-id-test',
package/out/cache.js CHANGED
@@ -19,6 +19,7 @@ async function getResponseBody(response) {
19
19
  }
20
20
  exports.getResponseBody = getResponseBody;
21
21
  class Cache {
22
+ client;
22
23
  constructor(client) {
23
24
  this.client = client;
24
25
  }
@@ -32,11 +33,11 @@ class Cache {
32
33
  };
33
34
  }
34
35
  async set(key, value, opt) {
35
- const response = await this.client('rms/store/set', this.buildRequest(Object.assign({ key, value }, opt)));
36
+ const response = await this.client('rms/store/set', this.buildRequest({ key, value, ...opt }));
36
37
  await getResponseBody(response);
37
38
  }
38
39
  async setIfNotExists(key, value, opt) {
39
- const response = await this.client('rms/store/setnx', this.buildRequest(Object.assign({ key, value }, opt)));
40
+ const response = await this.client('rms/store/setnx', this.buildRequest({ key, value, ...opt }));
40
41
  const { response: result } = await getResponseBody(response);
41
42
  return result;
42
43
  }
@@ -46,7 +47,7 @@ class Cache {
46
47
  return result;
47
48
  }
48
49
  async getAndSet(key, value, opt) {
49
- const response = await this.client('rms/store/getset', this.buildRequest(Object.assign({ key, value }, opt)));
50
+ const response = await this.client('rms/store/getset', this.buildRequest({ key, value, ...opt }));
50
51
  const { response: result } = await getResponseBody(response);
51
52
  return result;
52
53
  }
@@ -88,26 +89,34 @@ class Cache {
88
89
  }
89
90
  exports.Cache = Cache;
90
91
  function getFetchRmsRuntimeV1() {
91
- var _a;
92
- return (_a = global.api) === null || _a === void 0 ? void 0 : _a.requestRmsStore;
92
+ return global.api?.requestRmsStore;
93
93
  }
94
94
  exports.getFetchRmsRuntimeV1 = getFetchRmsRuntimeV1;
95
95
  function createFetchRmsRuntimeV2() {
96
96
  const agent = new https_1.Agent({ keepAlive: true });
97
97
  return async function (path, options) {
98
98
  const { proxy, rms, tracing } = (0, api_1.__getRuntime)();
99
- if (!(rms === null || rms === void 0 ? void 0 : rms.url) || !(rms === null || rms === void 0 ? void 0 : rms.host)) {
99
+ if (!rms?.url || !rms?.host) {
100
100
  throw new Error('RMS config not available.');
101
101
  }
102
102
  const rmsAgent = new String('FORGE_PRODUCT_REQUEST');
103
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 }) }));
104
+ return await (0, node_fetch_1.default)(new URL(path, 'https://rms/'), {
105
+ ...options,
106
+ agent: rmsAgent,
107
+ headers: {
108
+ ...options?.headers,
109
+ Authorization: `Bearer ${proxy.token}`,
110
+ Host: rms.host,
111
+ 'x-b3-traceid': tracing.traceId,
112
+ 'x-b3-spanid': tracing.spanId
113
+ }
114
+ });
105
115
  };
106
116
  }
107
117
  exports.createFetchRmsRuntimeV2 = createFetchRmsRuntimeV2;
108
118
  function connect() {
109
- var _a;
110
- const fetch = (_a = getFetchRmsRuntimeV1()) !== null && _a !== void 0 ? _a : createFetchRmsRuntimeV2();
119
+ const fetch = getFetchRmsRuntimeV1() ?? createFetchRmsRuntimeV2();
111
120
  return new Cache(fetch);
112
121
  }
113
122
  exports.connect = connect;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@forge/cache",
3
- "version": "0.7.5-next.0",
3
+ "version": "0.7.5",
4
4
  "description": "Forge Cache methods",
5
5
  "author": "Atlassian",
6
6
  "license": "UNLICENSED",
@@ -20,6 +20,6 @@
20
20
  "node-fetch": "2.7.0"
21
21
  },
22
22
  "dependencies": {
23
- "@forge/api": "^3.4.1-next.0"
23
+ "@forge/api": "^3.5.0"
24
24
  }
25
25
  }