@forge/teamwork-graph 5.1.1-next.1 → 5.2.0-next.2-experimental-6664e2b

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,22 @@
1
1
  # @forge/teamwork-graph
2
2
 
3
+ ## 5.2.0-next.2-experimental-6664e2b
4
+
5
+ ### Minor Changes
6
+
7
+ - 5b29d7c: Fall back to the first Jira secondary installation context when the primary context is not Jira.
8
+
9
+ ### Patch Changes
10
+
11
+ - Updated dependencies [406407c]
12
+ - @forge/api@8.1.0-next.1-experimental-6664e2b
13
+
14
+ ## 5.2.0-next.2
15
+
16
+ ### Minor Changes
17
+
18
+ - 5b29d7c: Fall back to the first Jira secondary installation context when the primary context is not Jira.
19
+
3
20
  ## 5.1.1-next.1
4
21
 
5
22
  ### Patch Changes
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=endpoints.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"endpoints.test.d.ts","sourceRoot":"","sources":["../../src/__test__/endpoints.test.ts"],"names":[],"mappings":""}
@@ -0,0 +1,56 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const api_1 = require("@forge/api");
4
+ const endpoints_1 = require("../utils/endpoints");
5
+ jest.mock('@forge/api');
6
+ const JIRA_ARI = 'ari:cloud:jira::site/11111111-1111-1111-1111-111111111111';
7
+ const CONFLUENCE_ARI = 'ari:cloud:confluence::site/22222222-2222-2222-2222-222222222222';
8
+ const BITBUCKET_ARI = 'ari:cloud:bitbucket::workspace/33333333-3333-3333-3333-333333333333';
9
+ const mockRuntime = (runtime) => {
10
+ api_1.__getRuntime.mockReturnValue(runtime);
11
+ };
12
+ const contextAri = (ari) => ({ toString: () => ari });
13
+ describe('getStargateBase', () => {
14
+ beforeEach(() => {
15
+ jest.clearAllMocks();
16
+ });
17
+ it('keeps the placeholder when the primary context is Jira', () => {
18
+ mockRuntime({
19
+ contextAri: JIRA_ARI,
20
+ appContext: { installation: { contexts: [contextAri(CONFLUENCE_ARI)] } }
21
+ });
22
+ expect((0, endpoints_1.getStargateBase)()).toBe(endpoints_1.STARGATE_BASE);
23
+ });
24
+ it('uses the first Jira secondary context when the primary context is not Jira', () => {
25
+ mockRuntime({
26
+ contextAri: CONFLUENCE_ARI,
27
+ appContext: {
28
+ installation: {
29
+ contexts: [contextAri(BITBUCKET_ARI), contextAri(JIRA_ARI), contextAri('ari:cloud:jira::site/other')]
30
+ }
31
+ }
32
+ });
33
+ const encodedJiraAri = 'ari%3Acloud%3Ajira%3A%3Asite%2F11111111-1111-1111-1111-111111111111';
34
+ expect(encodedJiraAri).toBe(encodeURIComponent(JIRA_ARI));
35
+ expect((0, endpoints_1.getStargateBase)()).toBe(`/graph/connector/${encodedJiraAri}`);
36
+ expect((0, endpoints_1.getFullPath)('/entities', (0, endpoints_1.getStargateBase)())).toBe(`/graph/connector/${encodedJiraAri}/entities`);
37
+ });
38
+ it('keeps the placeholder when no secondary context is Jira', () => {
39
+ mockRuntime({
40
+ contextAri: CONFLUENCE_ARI,
41
+ appContext: { installation: { contexts: [contextAri(BITBUCKET_ARI)] } }
42
+ });
43
+ expect((0, endpoints_1.getStargateBase)()).toBe(endpoints_1.STARGATE_BASE);
44
+ });
45
+ it('keeps the placeholder when there are no secondary contexts', () => {
46
+ mockRuntime({ contextAri: CONFLUENCE_ARI, appContext: {} });
47
+ expect((0, endpoints_1.getStargateBase)()).toBe(endpoints_1.STARGATE_BASE);
48
+ });
49
+ it('keeps the placeholder when the runtime is unavailable', () => {
50
+ api_1.__getRuntime.mockImplementation(() => {
51
+ throw new Error('Forge runtime not found.');
52
+ });
53
+ expect((0, endpoints_1.getStargateBase)()).toBe(endpoints_1.STARGATE_BASE);
54
+ expect(endpoints_1.STARGATE_BASE).toContain(endpoints_1.CONTEXT_ARI_PLACEHOLDER);
55
+ });
56
+ });
package/out/graph.js CHANGED
@@ -343,7 +343,7 @@ class TeamWorkGraphClient {
343
343
  };
344
344
  async sendRequest(connectionId, path, options) {
345
345
  try {
346
- const reqPath = (0, endpoints_1.getFullPath)(path);
346
+ const reqPath = (0, endpoints_1.getFullPath)(path, (0, endpoints_1.getStargateBase)());
347
347
  const headers = {
348
348
  ...options?.headers,
349
349
  'Content-Type': 'application/json',
@@ -27,6 +27,8 @@ export declare const ENDPOINTS: {
27
27
  readonly TASK_STATUS_UPDATE: "/scan/{scanId}/taskExecution/{taskExecutionId}/status";
28
28
  };
29
29
  };
30
+ export declare const CONTEXT_ARI_PLACEHOLDER = "{contextAri}";
30
31
  export declare const STARGATE_BASE = "/graph/connector/{contextAri}";
32
+ export declare const getStargateBase: () => string;
31
33
  export declare const getFullPath: (endpoint: string, stargateBase?: string) => string;
32
34
  //# sourceMappingURL=endpoints.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"endpoints.d.ts","sourceRoot":"","sources":["../../src/utils/endpoints.ts"],"names":[],"mappings":"AAMA,eAAO,MAAM,SAAS;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAqCZ,CAAC;AAKX,eAAO,MAAM,aAAa,kCAAkC,CAAC;AAM7D,eAAO,MAAM,WAAW,GAAI,UAAU,MAAM,EAAE,eAAc,MAAsB,KAAG,MAEpF,CAAC"}
1
+ {"version":3,"file":"endpoints.d.ts","sourceRoot":"","sources":["../../src/utils/endpoints.ts"],"names":[],"mappings":"AAOA,eAAO,MAAM,SAAS;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAqCZ,CAAC;AAMX,eAAO,MAAM,uBAAuB,iBAAiB,CAAC;AAKtD,eAAO,MAAM,aAAa,kCAAgD,CAAC;AAc3E,eAAO,MAAM,eAAe,QAAO,MAgBlC,CAAC;AAMF,eAAO,MAAM,WAAW,GAAI,UAAU,MAAM,EAAE,eAAc,MAAsB,KAAG,MAEpF,CAAC"}
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getFullPath = exports.STARGATE_BASE = exports.ENDPOINTS = void 0;
3
+ exports.getFullPath = exports.getStargateBase = exports.STARGATE_BASE = exports.CONTEXT_ARI_PLACEHOLDER = exports.ENDPOINTS = void 0;
4
+ const api_1 = require("@forge/api");
4
5
  exports.ENDPOINTS = {
5
6
  OBJECTS: {
6
7
  BULK: '/entities',
@@ -30,7 +31,27 @@ exports.ENDPOINTS = {
30
31
  TASK_STATUS_UPDATE: '/scan/{scanId}/taskExecution/{taskExecutionId}/status'
31
32
  }
32
33
  };
33
- exports.STARGATE_BASE = '/graph/connector/{contextAri}';
34
+ exports.CONTEXT_ARI_PLACEHOLDER = '{contextAri}';
35
+ exports.STARGATE_BASE = `/graph/connector/${exports.CONTEXT_ARI_PLACEHOLDER}`;
36
+ const JIRA_ARI_PREFIX = 'ari:cloud:jira:';
37
+ const isJiraAri = (ari) => ari.startsWith(JIRA_ARI_PREFIX);
38
+ const getStargateBase = () => {
39
+ let runtime;
40
+ try {
41
+ runtime = (0, api_1.__getRuntime)();
42
+ }
43
+ catch {
44
+ return exports.STARGATE_BASE;
45
+ }
46
+ if (!runtime || isJiraAri(runtime.contextAri ?? '')) {
47
+ return exports.STARGATE_BASE;
48
+ }
49
+ const jiraContext = runtime.appContext?.installation?.contexts?.find((context) => isJiraAri(String(context)));
50
+ return jiraContext
51
+ ? exports.STARGATE_BASE.replace(exports.CONTEXT_ARI_PLACEHOLDER, encodeURIComponent(String(jiraContext)))
52
+ : exports.STARGATE_BASE;
53
+ };
54
+ exports.getStargateBase = getStargateBase;
34
55
  const getFullPath = (endpoint, stargateBase = exports.STARGATE_BASE) => {
35
56
  return `${stargateBase}${endpoint}`;
36
57
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@forge/teamwork-graph",
3
- "version": "5.1.1-next.1",
3
+ "version": "5.2.0-next.2-experimental-6664e2b",
4
4
  "description": "Forge TeamworkGraph SDK",
5
5
  "author": "Atlassian",
6
6
  "license": "UNLICENSED",
@@ -20,7 +20,7 @@
20
20
  "typescript": "5.9.2"
21
21
  },
22
22
  "dependencies": {
23
- "@forge/api": "^8.1.0-next.1"
23
+ "@forge/api": "^8.1.0-next.1-experimental-6664e2b"
24
24
  },
25
25
  "publishConfig": {
26
26
  "registry": "https://packages.atlassian.com/api/npm/npm-public/"