@forge/api 3.2.0-next.4-experimental-cf84ac7 → 3.2.0
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 +11 -4
- package/out/api/fetch.d.ts +8 -1
- package/out/api/fetch.d.ts.map +1 -1
- package/out/api/fetch.js +47 -3
- package/package.json +5 -5
package/CHANGELOG.md
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
# @forge/api
|
|
2
2
|
|
|
3
|
-
## 3.2.0
|
|
3
|
+
## 3.2.0
|
|
4
4
|
|
|
5
5
|
### Minor Changes
|
|
6
6
|
|
|
7
7
|
- e343baf: Add external auth info to metadata for invocations
|
|
8
8
|
- d36502b: This change extends existing methods on external auth providers. We are now providing account details including: externalAccountId, displayName, avatarUrl, granted scopes.
|
|
9
9
|
Moreover, if end user authenticates multiple accounts, it is possible to select what account to use.
|
|
10
|
+
- ea39472: Implement External auth APIs for Node runtime
|
|
10
11
|
|
|
11
12
|
### Patch Changes
|
|
12
13
|
|
|
@@ -17,9 +18,15 @@
|
|
|
17
18
|
- Updated dependencies [5b82e7f]
|
|
18
19
|
- Updated dependencies [882be11]
|
|
19
20
|
- Updated dependencies [32fa518]
|
|
20
|
-
- @forge/util@1.4.1
|
|
21
|
-
- @forge/egress@1.2.13
|
|
22
|
-
- @forge/storage@1.5.15
|
|
21
|
+
- @forge/util@1.4.1
|
|
22
|
+
- @forge/egress@1.2.13
|
|
23
|
+
- @forge/storage@1.5.15
|
|
24
|
+
|
|
25
|
+
## 3.2.0-next.5
|
|
26
|
+
|
|
27
|
+
### Minor Changes
|
|
28
|
+
|
|
29
|
+
- ea39472: Implement External auth APIs for Node runtime
|
|
23
30
|
|
|
24
31
|
## 3.2.0-next.4
|
|
25
32
|
|
package/out/api/fetch.d.ts
CHANGED
|
@@ -2,12 +2,19 @@ import { RequestInit } from 'node-fetch';
|
|
|
2
2
|
import { FetchAPI, FetchMethod } from '..';
|
|
3
3
|
declare type AuthProvider = 'app' | 'user' | 'none';
|
|
4
4
|
declare type RemoteAPI = 'jira' | 'confluence' | 'stargate' | 'bitbucket';
|
|
5
|
+
declare type ExternalAuthProvider = string;
|
|
6
|
+
declare type ExternalAuthRemote = string;
|
|
5
7
|
declare type FetchArgs = {
|
|
6
8
|
provider: AuthProvider;
|
|
7
9
|
remote: RemoteAPI;
|
|
8
10
|
};
|
|
11
|
+
declare type ExternalAuthFetchArgs = {
|
|
12
|
+
provider: ExternalAuthProvider;
|
|
13
|
+
remote: ExternalAuthRemote;
|
|
14
|
+
};
|
|
9
15
|
export declare function fetchProduct(args: FetchArgs): FetchMethod;
|
|
10
|
-
export declare
|
|
16
|
+
export declare function fetchRemote(args: ExternalAuthFetchArgs): FetchMethod;
|
|
17
|
+
export declare const addMagicAgent: (init?: RequestInit, agentOverride?: string) => RequestInit;
|
|
11
18
|
export declare function getNodeRuntimeAPI(): FetchAPI;
|
|
12
19
|
export declare function getSandboxRuntimeAPI(api: any): FetchAPI;
|
|
13
20
|
export {};
|
package/out/api/fetch.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fetch.d.ts","sourceRoot":"","sources":["../../src/api/fetch.ts"],"names":[],"mappings":"AAEA,OAAc,EAAE,WAAW,EAAY,MAAM,YAAY,CAAC;AAS1D,OAAO,EAAE,QAAQ,EAAE,WAAW,EAAE,MAAM,IAAI,CAAC;
|
|
1
|
+
{"version":3,"file":"fetch.d.ts","sourceRoot":"","sources":["../../src/api/fetch.ts"],"names":[],"mappings":"AAEA,OAAc,EAAE,WAAW,EAAY,MAAM,YAAY,CAAC;AAS1D,OAAO,EAAE,QAAQ,EAAE,WAAW,EAAE,MAAM,IAAI,CAAC;AAK3C,aAAK,YAAY,GAAG,KAAK,GAAG,MAAM,GAAG,MAAM,CAAC;AAC5C,aAAK,SAAS,GAAG,MAAM,GAAG,YAAY,GAAG,UAAU,GAAG,WAAW,CAAC;AAElE,aAAK,oBAAoB,GAAG,MAAM,CAAC;AACnC,aAAK,kBAAkB,GAAG,MAAM,CAAC;AAEjC,aAAK,SAAS,GAAG;IAAE,QAAQ,EAAE,YAAY,CAAC;IAAC,MAAM,EAAE,SAAS,CAAA;CAAE,CAAC;AAC/D,aAAK,qBAAqB,GAAG;IAAE,QAAQ,EAAE,oBAAoB,CAAC;IAAC,MAAM,EAAE,kBAAkB,CAAA;CAAE,CAAC;AAS5F,wBAAgB,YAAY,CAAC,IAAI,EAAE,SAAS,GAAG,WAAW,CAkBzD;AAED,wBAAgB,WAAW,CAAC,IAAI,EAAE,qBAAqB,GAAG,WAAW,CAWpE;AAqDD,eAAO,MAAM,aAAa,EAAE,CAAC,IAAI,CAAC,EAAE,WAAW,EAAE,aAAa,CAAC,EAAE,MAAM,KAAK,WAG1E,CAAC;AA0BH,wBAAgB,iBAAiB,IAAI,QAAQ,CAsB5C;AAED,wBAAgB,oBAAoB,CAAC,GAAG,EAAE,GAAG,GAAG,QAAQ,CAEvD"}
|
package/out/api/fetch.js
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getSandboxRuntimeAPI = exports.getNodeRuntimeAPI = exports.addMagicAgent = exports.fetchProduct = void 0;
|
|
3
|
+
exports.getSandboxRuntimeAPI = exports.getNodeRuntimeAPI = exports.addMagicAgent = exports.fetchRemote = exports.fetchProduct = void 0;
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
5
|
const node_fetch_1 = tslib_1.__importDefault(require("node-fetch"));
|
|
6
6
|
const _1 = require(".");
|
|
7
|
+
const runtime_1 = require("./runtime");
|
|
7
8
|
const polyfill_response_1 = require("./polyfill-response");
|
|
8
9
|
const errors_1 = require("./errors");
|
|
9
10
|
function fetchProduct(args) {
|
|
@@ -17,6 +18,34 @@ function fetchProduct(args) {
|
|
|
17
18
|
};
|
|
18
19
|
}
|
|
19
20
|
exports.fetchProduct = fetchProduct;
|
|
21
|
+
function fetchRemote(args) {
|
|
22
|
+
return async (path, init) => {
|
|
23
|
+
const url = `https://${args.remote}${path}`;
|
|
24
|
+
init = (0, exports.addMagicAgent)(init, 'EXTERNAL_AUTH_REQUEST');
|
|
25
|
+
init.headers = Object.assign(Object.assign({}, init.headers), { authorization: `Forge user ${args.provider}` });
|
|
26
|
+
const response = await (0, node_fetch_1.default)(url, init);
|
|
27
|
+
handleProxyResponseErrors(response);
|
|
28
|
+
return response;
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
exports.fetchRemote = fetchRemote;
|
|
32
|
+
function getDefaultRemote(provider) {
|
|
33
|
+
const externalAuthProvider = findExternalAuthProviderConfigOrThrow(provider);
|
|
34
|
+
if (!externalAuthProvider.remotes.length) {
|
|
35
|
+
throw new Error(`Missing remote config for provider ${provider}`);
|
|
36
|
+
}
|
|
37
|
+
return externalAuthProvider.remotes[0].key;
|
|
38
|
+
}
|
|
39
|
+
function findExternalAuthProviderConfigOrThrow(provider) {
|
|
40
|
+
const { externalAuth } = (0, runtime_1.__getRuntime)();
|
|
41
|
+
const externalAuthProvider = externalAuth === null || externalAuth === void 0 ? void 0 : externalAuth.find((externalAuthMetaData) => {
|
|
42
|
+
return externalAuthMetaData.service === provider;
|
|
43
|
+
});
|
|
44
|
+
if (!externalAuthProvider) {
|
|
45
|
+
throw new Error(`Bad provider or missing config for provider ${provider}`);
|
|
46
|
+
}
|
|
47
|
+
return externalAuthProvider;
|
|
48
|
+
}
|
|
20
49
|
const ATLASSIAN_TOKEN_SERVICE_KEY = 'atlassian-token-service-key';
|
|
21
50
|
const handleProxyResponseErrors = (response) => {
|
|
22
51
|
if (response.headers.has('forge-proxy-error')) {
|
|
@@ -33,11 +62,26 @@ function productURL(remote, path) {
|
|
|
33
62
|
}
|
|
34
63
|
return `https://${remote}${path}`;
|
|
35
64
|
}
|
|
36
|
-
const addMagicAgent = (init) => (Object.assign(Object.assign({}, init), { agent: 'FORGE_PRODUCT_REQUEST' }));
|
|
65
|
+
const addMagicAgent = (init, agentOverride) => (Object.assign(Object.assign({}, init), { agent: (agentOverride !== null && agentOverride !== void 0 ? agentOverride : 'FORGE_PRODUCT_REQUEST') }));
|
|
37
66
|
exports.addMagicAgent = addMagicAgent;
|
|
38
67
|
const throwNotImplementedError = () => {
|
|
39
68
|
throw new Error('not implemented');
|
|
40
69
|
};
|
|
70
|
+
const withProvider = (provider, remote) => ({
|
|
71
|
+
hasCredentials: async () => {
|
|
72
|
+
const { tokenAvailable } = findExternalAuthProviderConfigOrThrow(provider);
|
|
73
|
+
return tokenAvailable;
|
|
74
|
+
},
|
|
75
|
+
getAccount: throwNotImplementedError,
|
|
76
|
+
requestCredentials: async () => {
|
|
77
|
+
findExternalAuthProviderConfigOrThrow(provider);
|
|
78
|
+
throw new errors_1.NeedsAuthenticationError('Authentication Required', provider);
|
|
79
|
+
},
|
|
80
|
+
listCredentials: throwNotImplementedError,
|
|
81
|
+
listAccounts: throwNotImplementedError,
|
|
82
|
+
asAccount: throwNotImplementedError,
|
|
83
|
+
fetch: (0, _1.wrapWithRouteUnwrapper)(fetchRemote({ provider, remote: remote !== null && remote !== void 0 ? remote : getDefaultRemote(provider) }))
|
|
84
|
+
});
|
|
41
85
|
function getNodeRuntimeAPI() {
|
|
42
86
|
return {
|
|
43
87
|
fetch: (0, _1.wrapWithRouteUnwrapper)(node_fetch_1.default),
|
|
@@ -50,7 +94,7 @@ function getNodeRuntimeAPI() {
|
|
|
50
94
|
requestBitbucket: (0, _1.wrapRequestProduct)(fetchProduct({ provider: 'user', remote: 'bitbucket' })),
|
|
51
95
|
requestGraph: (0, _1.wrapRequestGraph)(fetchProduct({ provider: 'user', remote: 'stargate' })),
|
|
52
96
|
requestConnectedData: (0, _1.wrapRequestConnectedData)(fetchProduct({ provider: 'user', remote: 'stargate' })),
|
|
53
|
-
withProvider
|
|
97
|
+
withProvider
|
|
54
98
|
}),
|
|
55
99
|
asApp: () => ({
|
|
56
100
|
requestJira: (0, _1.wrapRequestProduct)(fetchProduct({ provider: 'app', remote: 'jira' })),
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@forge/api",
|
|
3
|
-
"version": "3.2.0
|
|
3
|
+
"version": "3.2.0",
|
|
4
4
|
"description": "Forge API methods",
|
|
5
5
|
"author": "Atlassian",
|
|
6
6
|
"license": "UNLICENSED",
|
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
"compile": "tsc -b -v"
|
|
13
13
|
},
|
|
14
14
|
"devDependencies": {
|
|
15
|
-
"@forge/runtime": "5.4.0
|
|
15
|
+
"@forge/runtime": "5.4.0",
|
|
16
16
|
"@types/node": "14.18.63",
|
|
17
17
|
"expect-type": "^0.17.3",
|
|
18
18
|
"jest-matcher-specific-error": "^1.0.0",
|
|
@@ -20,9 +20,9 @@
|
|
|
20
20
|
},
|
|
21
21
|
"dependencies": {
|
|
22
22
|
"@forge/auth": "0.0.5",
|
|
23
|
-
"@forge/egress": "1.2.13
|
|
24
|
-
"@forge/storage": "1.5.15
|
|
25
|
-
"@forge/util": "1.4.1
|
|
23
|
+
"@forge/egress": "1.2.13",
|
|
24
|
+
"@forge/storage": "1.5.15",
|
|
25
|
+
"@forge/util": "1.4.1",
|
|
26
26
|
"@types/node-fetch": "^2.6.11",
|
|
27
27
|
"node-fetch": "2.7.0"
|
|
28
28
|
}
|