@forge/api 3.7.0-next.0 → 3.7.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 +6 -0
- package/out/api/ari.js +1 -0
- package/out/api/errors.js +6 -2
- package/out/api/fetch.js +13 -7
- package/out/api/index.js +5 -2
- package/out/api/polyfill-response.js +4 -1
- package/out/authorization/index.js +10 -7
- package/out/index.js +4 -1
- package/out/properties/product-scoped-storage.js +2 -0
- package/out/runtime/fetch-and-storage.js +2 -4
- package/out/safeUrl.js +1 -0
- package/out/webTrigger.js +7 -10
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
package/out/api/ari.js
CHANGED
package/out/api/errors.js
CHANGED
|
@@ -15,11 +15,11 @@ function isHostedCodeError(err) {
|
|
|
15
15
|
}
|
|
16
16
|
exports.isHostedCodeError = isHostedCodeError;
|
|
17
17
|
function isExpectedError(err) {
|
|
18
|
-
|
|
19
|
-
return err.name === exports.NEEDS_AUTHENTICATION_ERR && !!((_a = err.options) === null || _a === void 0 ? void 0 : _a.isExpectedError);
|
|
18
|
+
return err.name === exports.NEEDS_AUTHENTICATION_ERR && !!err.options?.isExpectedError;
|
|
20
19
|
}
|
|
21
20
|
exports.isExpectedError = isExpectedError;
|
|
22
21
|
class HttpError extends Error {
|
|
22
|
+
status;
|
|
23
23
|
constructor(message) {
|
|
24
24
|
super(message);
|
|
25
25
|
}
|
|
@@ -67,6 +67,8 @@ class InvalidWorkspaceRequestedError extends NotAllowedError {
|
|
|
67
67
|
}
|
|
68
68
|
exports.InvalidWorkspaceRequestedError = InvalidWorkspaceRequestedError;
|
|
69
69
|
class NeedsAuthenticationError extends HttpError {
|
|
70
|
+
serviceKey;
|
|
71
|
+
options;
|
|
70
72
|
constructor(error, serviceKey, options) {
|
|
71
73
|
super(error);
|
|
72
74
|
this.serviceKey = serviceKey;
|
|
@@ -78,6 +80,8 @@ class NeedsAuthenticationError extends HttpError {
|
|
|
78
80
|
}
|
|
79
81
|
exports.NeedsAuthenticationError = NeedsAuthenticationError;
|
|
80
82
|
class ProxyRequestError extends HttpError {
|
|
83
|
+
status;
|
|
84
|
+
errorCode;
|
|
81
85
|
constructor(status, errorCode) {
|
|
82
86
|
super(`Forge platform failed to process runtime HTTP request - ${status} - ${errorCode}`);
|
|
83
87
|
this.status = status;
|
package/out/api/fetch.js
CHANGED
|
@@ -23,7 +23,7 @@ function fetchProduct(args) {
|
|
|
23
23
|
const url = productURL(args.remote, path);
|
|
24
24
|
init = (0, exports.addMagicAgent)(init);
|
|
25
25
|
if (!hasAuthorizationHeader(init.headers)) {
|
|
26
|
-
init.headers =
|
|
26
|
+
init.headers = { ...init.headers, authorization: `Forge ${args.provider}` };
|
|
27
27
|
}
|
|
28
28
|
const response = await (0, node_fetch_1.default)(url, init);
|
|
29
29
|
handleProxyResponseErrors(response);
|
|
@@ -40,7 +40,10 @@ function fetchRemote(args) {
|
|
|
40
40
|
}
|
|
41
41
|
remoteUrl.searchParams.append('path', path);
|
|
42
42
|
init = (0, exports.addMagicAgent)(init, 'EXTERNAL_AUTH_REQUEST');
|
|
43
|
-
init.headers =
|
|
43
|
+
init.headers = {
|
|
44
|
+
...init.headers,
|
|
45
|
+
authorization: `Forge user ${args.provider} ${args.account}`
|
|
46
|
+
};
|
|
44
47
|
const response = await (0, node_fetch_1.default)(remoteUrl, init);
|
|
45
48
|
handleProxyResponseErrors(response);
|
|
46
49
|
return response;
|
|
@@ -56,7 +59,7 @@ function getDefaultRemote(provider) {
|
|
|
56
59
|
}
|
|
57
60
|
function findExternalAuthProviderConfigOrThrow(provider) {
|
|
58
61
|
const { externalAuth } = (0, runtime_1.__getRuntime)();
|
|
59
|
-
const externalAuthProvider = externalAuth
|
|
62
|
+
const externalAuthProvider = externalAuth?.find((externalAuthMetaData) => {
|
|
60
63
|
return externalAuthMetaData.service === provider;
|
|
61
64
|
});
|
|
62
65
|
if (!externalAuthProvider) {
|
|
@@ -93,14 +96,14 @@ function lazyThrowNeedsAuthenticationError(serviceKey) {
|
|
|
93
96
|
function buildExternalAuthAccountsInfo(provider, remote) {
|
|
94
97
|
const { accounts } = findExternalAuthProviderConfigOrThrow(provider);
|
|
95
98
|
const buildAccountModel = (account) => {
|
|
96
|
-
const { externalAccountId: id
|
|
97
|
-
return
|
|
99
|
+
const { externalAccountId: id, ...rest } = account;
|
|
100
|
+
return { ...rest, id };
|
|
98
101
|
};
|
|
99
102
|
const buildExternalAuthAccountMethods = (account, outboundAuthAccountId) => ({
|
|
100
103
|
hasCredentials: async (scopes) => wrapInMetrics({ name: 'api.asUser.withProvider.hasCredentials', tags: { passingScopes: String(!!scopes) } }, async () => !scopes || scopes.every((scope) => account.scopes.includes(scope))),
|
|
101
104
|
requestCredentials: lazyThrowNeedsAuthenticationError(provider),
|
|
102
105
|
getAccount: async () => wrapInMetrics({ name: 'api.asUser.withProvider.getAccount' }, async () => account),
|
|
103
|
-
fetch: (0, _1.wrapWithRouteUnwrapper)(fetchRemote({ provider, remote: remote
|
|
106
|
+
fetch: (0, _1.wrapWithRouteUnwrapper)(fetchRemote({ provider, remote: remote ?? getDefaultRemote(provider), account: outboundAuthAccountId }))
|
|
104
107
|
});
|
|
105
108
|
return accounts.map((account) => {
|
|
106
109
|
const authAccount = buildAccountModel(account);
|
|
@@ -110,7 +113,10 @@ function buildExternalAuthAccountsInfo(provider, remote) {
|
|
|
110
113
|
};
|
|
111
114
|
});
|
|
112
115
|
}
|
|
113
|
-
const addMagicAgent = (init, agentOverride) => (
|
|
116
|
+
const addMagicAgent = (init, agentOverride) => ({
|
|
117
|
+
...init,
|
|
118
|
+
agent: (agentOverride ?? 'FORGE_PRODUCT_REQUEST')
|
|
119
|
+
});
|
|
114
120
|
exports.addMagicAgent = addMagicAgent;
|
|
115
121
|
const throwNotImplementedError = () => {
|
|
116
122
|
throw new Error('not implemented');
|
package/out/api/index.js
CHANGED
|
@@ -4,8 +4,11 @@ exports.wrapFetchApiMethods = exports.wrapWithRouteUnwrapper = exports.wrapReque
|
|
|
4
4
|
const safeUrl_1 = require("../safeUrl");
|
|
5
5
|
const wrapRequestGraph = (requestGraphApi) => (query, variables, headers = {}) => requestGraphApi('/graphql', {
|
|
6
6
|
method: 'POST',
|
|
7
|
-
headers:
|
|
8
|
-
body: JSON.stringify(
|
|
7
|
+
headers: { ...headers, 'Content-Type': 'application/json' },
|
|
8
|
+
body: JSON.stringify({
|
|
9
|
+
query,
|
|
10
|
+
...(variables ? { variables } : {})
|
|
11
|
+
})
|
|
9
12
|
});
|
|
10
13
|
exports.wrapRequestGraph = wrapRequestGraph;
|
|
11
14
|
const wrapRequestConnectedData = (fetch) => (path, init) => {
|
|
@@ -4,6 +4,9 @@ exports.transformResponse = void 0;
|
|
|
4
4
|
const node_fetch_1 = require("node-fetch");
|
|
5
5
|
const transformResponse = (fetchApi) => async (url, init) => {
|
|
6
6
|
const response = await fetchApi(url, init);
|
|
7
|
-
return
|
|
7
|
+
return {
|
|
8
|
+
...response,
|
|
9
|
+
headers: new node_fetch_1.Headers(response.headers)
|
|
10
|
+
};
|
|
8
11
|
};
|
|
9
12
|
exports.transformResponse = transformResponse;
|
|
@@ -14,12 +14,15 @@ const authorize = () => {
|
|
|
14
14
|
if (!accountId) {
|
|
15
15
|
throw new Error(`Couldn’t find the accountId of the invoking user. This API can only be used inside user-invoked modules.`);
|
|
16
16
|
}
|
|
17
|
-
return
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
17
|
+
return {
|
|
18
|
+
...(0, auth_1.authorizeConfluenceWithFetch)(async (path, opts) => {
|
|
19
|
+
const res = await (0, __1.asUser)().requestConfluence((0, __1.assumeTrustedRoute)(path), opts);
|
|
20
|
+
return res.json();
|
|
21
|
+
}, accountId),
|
|
22
|
+
...(0, auth_1.authorizeJiraWithFetch)(async (path, opts) => {
|
|
23
|
+
const res = await (0, __1.asUser)().requestJira((0, __1.assumeTrustedRoute)(path), opts);
|
|
24
|
+
return res.json();
|
|
25
|
+
}, accountId)
|
|
26
|
+
};
|
|
24
27
|
};
|
|
25
28
|
exports.authorize = authorize;
|
package/out/index.js
CHANGED
|
@@ -45,7 +45,10 @@ const storage = (0, storage_1.getStorageInstanceWithQuery)(new storage_1.GlobalS
|
|
|
45
45
|
exports.storage = storage;
|
|
46
46
|
const properties = properties_1.propertiesApi;
|
|
47
47
|
exports.properties = properties;
|
|
48
|
-
const API =
|
|
48
|
+
const API = {
|
|
49
|
+
...fetchAPI,
|
|
50
|
+
store: { ...store }
|
|
51
|
+
};
|
|
49
52
|
exports.privacy = {
|
|
50
53
|
reportPersonalData: (0, privacy_1.createReportPersonalData)(fetch_and_storage_1.__requestAtlassianAsApp)
|
|
51
54
|
};
|
|
@@ -3,6 +3,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.ProductScopedStorage = void 0;
|
|
4
4
|
const storage_1 = require("@forge/storage");
|
|
5
5
|
class ProductScopedStorage {
|
|
6
|
+
storageApiPath;
|
|
7
|
+
apiClient;
|
|
6
8
|
constructor(storageApiPath, apiClient) {
|
|
7
9
|
this.storageApiPath = storageApiPath;
|
|
8
10
|
this.apiClient = apiClient;
|
|
@@ -4,8 +4,7 @@ exports.__requestAtlassianAsUser = exports.__requestAtlassianAsApp = exports.get
|
|
|
4
4
|
const fetch_1 = require("../api/fetch");
|
|
5
5
|
const runtime_1 = require("../api/runtime");
|
|
6
6
|
function getContextAri() {
|
|
7
|
-
|
|
8
|
-
return (_c = (_b = (_a = global.api) === null || _a === void 0 ? void 0 : _a.__getAppAri) === null || _b === void 0 ? void 0 : _b.call(_a)) !== null && _c !== void 0 ? _c : (0, runtime_1.__getRuntime)().contextAri;
|
|
7
|
+
return global.api?.__getAppAri?.() ?? (0, runtime_1.__getRuntime)().contextAri;
|
|
9
8
|
}
|
|
10
9
|
exports.getContextAri = getContextAri;
|
|
11
10
|
function getFetchAPI() {
|
|
@@ -19,8 +18,7 @@ function getFetchAPI() {
|
|
|
19
18
|
}
|
|
20
19
|
exports.getFetchAPI = getFetchAPI;
|
|
21
20
|
function getRequestStargate(provider) {
|
|
22
|
-
|
|
23
|
-
return (_b = (_a = global.api) === null || _a === void 0 ? void 0 : _a.asApp().__requestAtlassian) !== null && _b !== void 0 ? _b : (0, fetch_1.fetchProduct)({ provider, remote: 'stargate' });
|
|
21
|
+
return global.api?.asApp().__requestAtlassian ?? (0, fetch_1.fetchProduct)({ provider, remote: 'stargate' });
|
|
24
22
|
}
|
|
25
23
|
exports.getRequestStargate = getRequestStargate;
|
|
26
24
|
exports.__requestAtlassianAsApp = getRequestStargate('app');
|
package/out/safeUrl.js
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.assumeTrustedRoute = exports.requireSafeUrl = exports.route = exports.routeFromAbsolute = exports.isRoute = void 0;
|
|
4
4
|
class ReadonlyRoute {
|
|
5
|
+
value_;
|
|
5
6
|
constructor(value_) {
|
|
6
7
|
this.value_ = value_;
|
|
7
8
|
}
|
package/out/webTrigger.js
CHANGED
|
@@ -4,7 +4,6 @@ exports.webTrigger = void 0;
|
|
|
4
4
|
const runtime_1 = require("./api/runtime");
|
|
5
5
|
const fetch_and_storage_1 = require("./runtime/fetch-and-storage");
|
|
6
6
|
const proxyGetWebTriggerURL = (0, runtime_1.wrapInMetrics)('api.getWebTriggerUrl', async (webTriggerModuleKey, forceCreate) => {
|
|
7
|
-
var _a, _b;
|
|
8
7
|
const runtime = (0, runtime_1.__getRuntime)();
|
|
9
8
|
const response = await (0, fetch_and_storage_1.__requestAtlassianAsApp)('/graphql', {
|
|
10
9
|
method: 'POST',
|
|
@@ -32,14 +31,13 @@ const proxyGetWebTriggerURL = (0, runtime_1.wrapInMetrics)('api.getWebTriggerUrl
|
|
|
32
31
|
throw new Error(`Internal error occurred: Failed to get web trigger URL: ${response.statusText}.`);
|
|
33
32
|
}
|
|
34
33
|
const responseBody = await response.json();
|
|
35
|
-
if (!
|
|
34
|
+
if (!responseBody?.data?.createWebTriggerUrl?.url) {
|
|
36
35
|
throw new Error(`Internal error occurred: Failed to get web trigger URL.`);
|
|
37
36
|
}
|
|
38
37
|
return responseBody.data.createWebTriggerUrl.url;
|
|
39
38
|
});
|
|
40
39
|
const proxyDeleteWebTriggerURL = (0, runtime_1.wrapInMetrics)('api.deleteWebTriggerUrl', async (webTriggerUrl) => {
|
|
41
40
|
const callDelete = async (webTriggerUrlId) => {
|
|
42
|
-
var _a, _b, _c, _d;
|
|
43
41
|
const response = await (0, fetch_and_storage_1.__requestAtlassianAsApp)('/graphql', {
|
|
44
42
|
method: 'POST',
|
|
45
43
|
headers: { 'Content-Type': 'application/json' },
|
|
@@ -61,8 +59,8 @@ const proxyDeleteWebTriggerURL = (0, runtime_1.wrapInMetrics)('api.deleteWebTrig
|
|
|
61
59
|
throw new Error(`Internal error occurred: Failed to delete web trigger URL: ${response.statusText}.`);
|
|
62
60
|
}
|
|
63
61
|
const responseBody = await response.json();
|
|
64
|
-
if (!
|
|
65
|
-
const errorText =
|
|
62
|
+
if (!responseBody?.data?.deleteWebTriggerUrl?.success) {
|
|
63
|
+
const errorText = responseBody?.data?.deleteWebTriggerUrl?.message || 'unknown error';
|
|
66
64
|
throw new Error(`Internal error occurred: Failed to delete web trigger URL: ${errorText}`);
|
|
67
65
|
}
|
|
68
66
|
};
|
|
@@ -72,7 +70,6 @@ const proxyDeleteWebTriggerURL = (0, runtime_1.wrapInMetrics)('api.deleteWebTrig
|
|
|
72
70
|
}
|
|
73
71
|
});
|
|
74
72
|
const proxyGetWebTriggerUrlIds = (0, runtime_1.wrapInMetrics)('api.getWebTriggerUrlIds', async (webTriggerUrl) => {
|
|
75
|
-
var _a;
|
|
76
73
|
const runtime = (0, runtime_1.__getRuntime)();
|
|
77
74
|
const response = await (0, fetch_and_storage_1.__requestAtlassianAsApp)('/graphql', {
|
|
78
75
|
method: 'POST',
|
|
@@ -97,7 +94,7 @@ const proxyGetWebTriggerUrlIds = (0, runtime_1.wrapInMetrics)('api.getWebTrigger
|
|
|
97
94
|
throw new Error(`Internal error occurred: Failed to get web trigger URLs: ${response.statusText}.`);
|
|
98
95
|
}
|
|
99
96
|
const responseBody = await response.json();
|
|
100
|
-
if (!
|
|
97
|
+
if (!responseBody?.data?.webTriggerUrlsByAppContext || responseBody.data.webTriggerUrlsByAppContext.length == 0) {
|
|
101
98
|
throw new Error('Internal error occurred: No web trigger URLs found');
|
|
102
99
|
}
|
|
103
100
|
const result = responseBody.data.webTriggerUrlsByAppContext
|
|
@@ -109,7 +106,7 @@ const proxyGetWebTriggerUrlIds = (0, runtime_1.wrapInMetrics)('api.getWebTrigger
|
|
|
109
106
|
return result;
|
|
110
107
|
});
|
|
111
108
|
exports.webTrigger = {
|
|
112
|
-
getUrl: async (webTriggerModuleKey, forceCreate = false) =>
|
|
113
|
-
deleteUrl: async (webTriggerUrl) =>
|
|
114
|
-
getUrlIds: async (webTriggerUrl) =>
|
|
109
|
+
getUrl: async (webTriggerModuleKey, forceCreate = false) => (global.api?.webTrigger?.getUrl ?? proxyGetWebTriggerURL)(webTriggerModuleKey, forceCreate),
|
|
110
|
+
deleteUrl: async (webTriggerUrl) => (global.api?.webTrigger?.deleteUrl ?? proxyDeleteWebTriggerURL)(webTriggerUrl),
|
|
111
|
+
getUrlIds: async (webTriggerUrl) => (global.api?.webTrigger?.getUrlIds ?? proxyGetWebTriggerUrlIds)(webTriggerUrl)
|
|
115
112
|
};
|