@forge/api 6.1.1-experimental-3f68b81 → 6.1.1-experimental-78c5fee
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 +5 -4
- package/out/api/permissions.d.ts +4 -4
- package/out/api/permissions.d.ts.map +1 -1
- package/out/api/permissions.js +119 -93
- package/out/api/runtime.d.ts +2 -0
- package/out/api/runtime.d.ts.map +1 -1
- package/out/api/runtime.js +49 -33
- package/package.json +2 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
# @forge/api
|
|
2
2
|
|
|
3
|
-
## 6.1.1-experimental-
|
|
3
|
+
## 6.1.1-experimental-78c5fee
|
|
4
4
|
|
|
5
5
|
### Patch Changes
|
|
6
6
|
|
|
7
|
-
-
|
|
8
|
-
- Updated dependencies [
|
|
9
|
-
|
|
7
|
+
- c561a03: Added backend SDK for permission handling
|
|
8
|
+
- Updated dependencies [c561a03]
|
|
9
|
+
- Updated dependencies [2d37370]
|
|
10
|
+
- @forge/manifest@10.5.0-next.0-experimental-78c5fee
|
|
10
11
|
|
|
11
12
|
## 6.1.1
|
|
12
13
|
|
package/out/api/permissions.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { PermissionRequirements, MissingPermissions } from './runtime';
|
|
1
|
+
import { PermissionRequirements, MissingPermissions, ExternalResourceType } from './runtime';
|
|
2
2
|
export declare function extractUrlString(url: string | {
|
|
3
3
|
address: string;
|
|
4
4
|
} | {
|
|
@@ -8,16 +8,16 @@ export type { PermissionRequirements };
|
|
|
8
8
|
export type { MissingPermissions };
|
|
9
9
|
export interface PermissionResult {
|
|
10
10
|
granted: boolean;
|
|
11
|
-
missing
|
|
11
|
+
missing?: MissingPermissions;
|
|
12
12
|
}
|
|
13
13
|
export declare const hasPermission: (requirements: Partial<PermissionRequirements>) => PermissionResult;
|
|
14
14
|
export declare const hasScope: (scope: string) => boolean;
|
|
15
15
|
export declare const canFetchFrom: (type: 'backend' | 'client', url: string) => boolean;
|
|
16
|
-
export declare const canLoadResource: (type:
|
|
16
|
+
export declare const canLoadResource: (type: ExternalResourceType, url: string) => boolean;
|
|
17
17
|
export declare const permissions: {
|
|
18
18
|
hasPermission: (requirements: Partial<PermissionRequirements>) => PermissionResult;
|
|
19
19
|
hasScope: (scope: string) => boolean;
|
|
20
20
|
canFetchFrom: (type: 'backend' | 'client', url: string) => boolean;
|
|
21
|
-
canLoadResource: (type:
|
|
21
|
+
canLoadResource: (type: ExternalResourceType, url: string) => boolean;
|
|
22
22
|
};
|
|
23
23
|
//# sourceMappingURL=permissions.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"permissions.d.ts","sourceRoot":"","sources":["../../src/api/permissions.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"permissions.d.ts","sourceRoot":"","sources":["../../src/api/permissions.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,sBAAsB,EACtB,kBAAkB,EAGlB,oBAAoB,EAErB,MAAM,WAAW,CAAC;AAQnB,wBAAgB,gBAAgB,CAAC,GAAG,EAAE,MAAM,GAAG;IAAE,OAAO,EAAE,MAAM,CAAA;CAAE,GAAG;IAAE,MAAM,EAAE,MAAM,CAAA;CAAE,GAAG,MAAM,CAQ/F;AAeD,YAAY,EAAE,sBAAsB,EAAE,CAAC;AAKvC,YAAY,EAAE,kBAAkB,EAAE,CAAC;AAKnC,MAAM,WAAW,gBAAgB;IAC/B,OAAO,EAAE,OAAO,CAAC;IACjB,OAAO,CAAC,EAAE,kBAAkB,CAAC;CAC9B;AA6HD,eAAO,MAAM,aAAa,iBAAkB,QAAQ,sBAAsB,CAAC,KAAG,gBA2C7E,CAAC;AAmBF,eAAO,MAAM,QAAQ,UAAW,MAAM,KAAG,OAaxC,CAAC;AAyBF,eAAO,MAAM,YAAY,SAAU,SAAS,GAAG,QAAQ,OAAO,MAAM,KAAG,OAiBtE,CAAC;AAyBF,eAAO,MAAM,eAAe,SAAU,oBAAoB,OAAO,MAAM,KAAG,OAiBzE,CAAC;AAKF,eAAO,MAAM,WAAW;kCApKoB,QAAQ,sBAAsB,CAAC,KAAG,gBAAgB;sBA8D9D,MAAM,KAAG,OAAO;yBAsCb,SAAS,GAAG,QAAQ,OAAO,MAAM,KAAG,OAAO;4BA0CxC,oBAAoB,OAAO,MAAM,KAAG,OAAO;CA2BhF,CAAC"}
|
package/out/api/permissions.js
CHANGED
|
@@ -14,123 +14,149 @@ function extractUrlString(url) {
|
|
|
14
14
|
return url.remote;
|
|
15
15
|
}
|
|
16
16
|
exports.extractUrlString = extractUrlString;
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
const currentGrantedScopes = Array.isArray(currentGrantedPermissions.scopes)
|
|
27
|
-
? currentGrantedPermissions.scopes
|
|
28
|
-
: [];
|
|
29
|
-
const missingScopes = requirements.scopes.filter((scope) => !currentGrantedScopes.includes(scope));
|
|
17
|
+
function wrapInSyncMetrics(options, cb) {
|
|
18
|
+
const metrics = (0, runtime_1.__getRuntime)().metrics;
|
|
19
|
+
metrics.counter(options.name, options.tags).incr();
|
|
20
|
+
return cb();
|
|
21
|
+
}
|
|
22
|
+
function hasMissingScopes(requiredScopes, currentlyGrantedScopes, missingPermissions) {
|
|
23
|
+
if (requiredScopes && Array.isArray(requiredScopes) && requiredScopes.length > 0) {
|
|
24
|
+
const currentGrantedScopes = Array.isArray(currentlyGrantedScopes) ? currentlyGrantedScopes : [];
|
|
25
|
+
const missingScopes = requiredScopes.filter((scope) => !currentGrantedScopes.includes(scope));
|
|
30
26
|
if (missingScopes.length > 0) {
|
|
31
27
|
missingPermissions.scopes = missingScopes;
|
|
32
|
-
|
|
28
|
+
return true;
|
|
33
29
|
}
|
|
34
30
|
}
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
31
|
+
return false;
|
|
32
|
+
}
|
|
33
|
+
function hasMissingFetchPermissions(requiredFetch, currentlyGrantedFetch, missingPermissions) {
|
|
34
|
+
if (!requiredFetch) {
|
|
35
|
+
return false;
|
|
36
|
+
}
|
|
37
|
+
let hasMissing = false;
|
|
38
|
+
const fetchTypes = ['backend', 'client'];
|
|
39
|
+
for (const fetchType of fetchTypes) {
|
|
40
|
+
const requiredUrls = requiredFetch[fetchType];
|
|
41
|
+
if (requiredUrls && requiredUrls.length > 0) {
|
|
42
|
+
const missingUrls = requiredUrls.filter((requiredUrl) => {
|
|
43
|
+
const currentlyGrantedUrls = currentlyGrantedFetch?.[fetchType] ?? [];
|
|
44
|
+
const isUrlAlreadyGranted = currentlyGrantedUrls.some((currentGrantedUrl) => {
|
|
45
|
+
return (0, minimatch_1.minimatch)(extractUrlString(requiredUrl), extractUrlString(currentGrantedUrl));
|
|
47
46
|
});
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
47
|
+
return !isUrlAlreadyGranted;
|
|
48
|
+
});
|
|
49
|
+
if (missingUrls.length > 0) {
|
|
50
|
+
if (!missingPermissions.external) {
|
|
51
|
+
missingPermissions.external = {};
|
|
51
52
|
}
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
const missingClient = external.fetch.client.filter((requiredUrl) => {
|
|
55
|
-
const currentGrantedClientUrls = currentGrantedExternal.fetch?.client || [];
|
|
56
|
-
const isUrlAlreadyGranted = currentGrantedClientUrls.some((currentGrantedUrl) => {
|
|
57
|
-
return (0, minimatch_1.minimatch)(extractUrlString(requiredUrl), extractUrlString(currentGrantedUrl));
|
|
58
|
-
});
|
|
59
|
-
return !isUrlAlreadyGranted;
|
|
60
|
-
});
|
|
61
|
-
if (missingClient.length > 0) {
|
|
62
|
-
missingFetch.client = missingClient.map(extractUrlString);
|
|
63
|
-
hasMissingPermissions = true;
|
|
53
|
+
if (!missingPermissions.external.fetch) {
|
|
54
|
+
missingPermissions.external.fetch = {};
|
|
64
55
|
}
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
missingPermissions.external = { ...missingPermissions.external, fetch: missingFetch };
|
|
56
|
+
missingPermissions.external.fetch[fetchType] = missingUrls.map(extractUrlString);
|
|
57
|
+
hasMissing = true;
|
|
68
58
|
}
|
|
69
59
|
}
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
60
|
+
}
|
|
61
|
+
return hasMissing;
|
|
62
|
+
}
|
|
63
|
+
function hasMissingExternalResourceTypes(requiredExternal, currentGrantedExternal, missingPermissions) {
|
|
64
|
+
let hasMissing = false;
|
|
65
|
+
for (const type of runtime_1.EXTERNAL_RESOURCE_TYPES) {
|
|
66
|
+
const externalUrls = requiredExternal[type];
|
|
67
|
+
if (externalUrls && externalUrls.length > 0) {
|
|
68
|
+
const missingUrls = externalUrls.filter((requiredUrl) => {
|
|
69
|
+
const currentGrantedUrls = currentGrantedExternal[type] || [];
|
|
70
|
+
const isUrlAlreadyGranted = currentGrantedUrls.some((currentGrantedUrl) => {
|
|
71
|
+
return (0, minimatch_1.minimatch)(extractUrlString(requiredUrl), extractUrlString(currentGrantedUrl));
|
|
80
72
|
});
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
missingPermissions.external
|
|
86
|
-
hasMissingPermissions = true;
|
|
73
|
+
return !isUrlAlreadyGranted;
|
|
74
|
+
});
|
|
75
|
+
if (missingUrls.length > 0) {
|
|
76
|
+
if (!missingPermissions.external) {
|
|
77
|
+
missingPermissions.external = {};
|
|
87
78
|
}
|
|
79
|
+
missingPermissions.external[type] = missingUrls.map(extractUrlString);
|
|
80
|
+
hasMissing = true;
|
|
88
81
|
}
|
|
89
82
|
}
|
|
90
83
|
}
|
|
91
|
-
return
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
}
|
|
84
|
+
return hasMissing;
|
|
85
|
+
}
|
|
86
|
+
const hasPermission = (requirements) => {
|
|
87
|
+
return wrapInSyncMetrics({ name: 'api.permissions.hasPermission' }, () => {
|
|
88
|
+
if (!(0, runtime_1.arePermsAvailableInRuntime)()) {
|
|
89
|
+
throw new errors_1.ApiNotReadyError('API not ready: this feature is not available yet');
|
|
90
|
+
}
|
|
91
|
+
const appContext = (0, runtime_1.getAppContext)();
|
|
92
|
+
const currentlyGrantedPermissions = appContext.permissions;
|
|
93
|
+
const missingPermissions = {};
|
|
94
|
+
let hasMissingPermissions = false;
|
|
95
|
+
if (hasMissingScopes(requirements.scopes, currentlyGrantedPermissions.scopes, missingPermissions)) {
|
|
96
|
+
hasMissingPermissions = true;
|
|
97
|
+
}
|
|
98
|
+
if (requirements.external) {
|
|
99
|
+
const { external: requiredExternal } = requirements;
|
|
100
|
+
const currentlyGrantedExternal = currentlyGrantedPermissions.external || {};
|
|
101
|
+
if (hasMissingFetchPermissions(requiredExternal.fetch, currentlyGrantedExternal.fetch, missingPermissions)) {
|
|
102
|
+
hasMissingPermissions = true;
|
|
103
|
+
}
|
|
104
|
+
if (hasMissingExternalResourceTypes(requiredExternal, currentlyGrantedExternal, missingPermissions)) {
|
|
105
|
+
hasMissingPermissions = true;
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
return {
|
|
109
|
+
granted: !hasMissingPermissions,
|
|
110
|
+
...(hasMissingPermissions && {
|
|
111
|
+
missing: new runtime_1.MissingPermissions(missingPermissions.scopes, missingPermissions.external, missingPermissions.content)
|
|
112
|
+
})
|
|
113
|
+
};
|
|
114
|
+
});
|
|
95
115
|
};
|
|
96
116
|
exports.hasPermission = hasPermission;
|
|
97
117
|
const hasScope = (scope) => {
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
118
|
+
return wrapInSyncMetrics({ name: 'api.permissions.hasScope' }, () => {
|
|
119
|
+
if (!(0, runtime_1.arePermsAvailableInRuntime)()) {
|
|
120
|
+
throw new errors_1.ApiNotReadyError('API not ready: this feature is not available yet');
|
|
121
|
+
}
|
|
122
|
+
const appContext = (0, runtime_1.getAppContext)();
|
|
123
|
+
const currentScopes = appContext.permissions.scopes;
|
|
124
|
+
if (Array.isArray(currentScopes)) {
|
|
125
|
+
return currentScopes.includes(scope);
|
|
126
|
+
}
|
|
127
|
+
return false;
|
|
128
|
+
});
|
|
107
129
|
};
|
|
108
130
|
exports.hasScope = hasScope;
|
|
109
131
|
const canFetchFrom = (type, url) => {
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
return
|
|
132
|
+
return wrapInSyncMetrics({ name: 'api.permissions.canFetchFrom' }, () => {
|
|
133
|
+
if (!(0, runtime_1.arePermsAvailableInRuntime)()) {
|
|
134
|
+
throw new errors_1.ApiNotReadyError('API not ready: this feature is not available yet');
|
|
135
|
+
}
|
|
136
|
+
const appContext = (0, runtime_1.getAppContext)();
|
|
137
|
+
const grantedUrls = appContext.permissions.external?.fetch?.[type];
|
|
138
|
+
if (!grantedUrls || grantedUrls.length === 0) {
|
|
139
|
+
return false;
|
|
140
|
+
}
|
|
141
|
+
return grantedUrls.some((grantedUrl) => {
|
|
142
|
+
return (0, minimatch_1.minimatch)(url, extractUrlString(grantedUrl));
|
|
143
|
+
});
|
|
120
144
|
});
|
|
121
145
|
};
|
|
122
146
|
exports.canFetchFrom = canFetchFrom;
|
|
123
147
|
const canLoadResource = (type, url) => {
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
return
|
|
148
|
+
return wrapInSyncMetrics({ name: 'api.permissions.canLoadResource' }, () => {
|
|
149
|
+
if (!(0, runtime_1.arePermsAvailableInRuntime)()) {
|
|
150
|
+
throw new errors_1.ApiNotReadyError('API not ready: this feature is not available yet');
|
|
151
|
+
}
|
|
152
|
+
const appContext = (0, runtime_1.getAppContext)();
|
|
153
|
+
const grantedUrls = appContext.permissions.external?.[type];
|
|
154
|
+
if (!grantedUrls || grantedUrls.length === 0) {
|
|
155
|
+
return false;
|
|
156
|
+
}
|
|
157
|
+
return grantedUrls.some((grantedUrl) => {
|
|
158
|
+
return (0, minimatch_1.minimatch)(url, extractUrlString(grantedUrl));
|
|
159
|
+
});
|
|
134
160
|
});
|
|
135
161
|
};
|
|
136
162
|
exports.canLoadResource = canLoadResource;
|
package/out/api/runtime.d.ts
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import { AppAri, EnvironmentAri, InstallationAri } from './ari';
|
|
2
2
|
import { Permissions as ManifestPermissions, External as ManifestExternal, Scopes as ManifestScopes, Content1 as ManifestContent } from '@forge/manifest';
|
|
3
|
+
export declare const EXTERNAL_RESOURCE_TYPES: readonly ["fonts", "styles", "frames", "images", "media", "scripts"];
|
|
4
|
+
export declare type ExternalResourceType = (typeof EXTERNAL_RESOURCE_TYPES)[number];
|
|
3
5
|
interface Timer {
|
|
4
6
|
stop(tags?: Record<string, string>): void;
|
|
5
7
|
}
|
package/out/api/runtime.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"runtime.d.ts","sourceRoot":"","sources":["../../src/api/runtime.ts"],"names":[],"mappings":"AACA,OAAO,EAAoD,MAAM,EAAE,cAAc,EAAE,eAAe,EAAE,MAAM,OAAO,CAAC;AAClH,OAAO,EACL,WAAW,IAAI,mBAAmB,EAClC,QAAQ,IAAI,gBAAgB,EAC5B,MAAM,IAAI,cAAc,EACxB,QAAQ,IAAI,eAAe,EAC5B,MAAM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;AAEF,wBAAgB,YAAY,IAAI,YAAY,CAO3C;AAED,wBAAgB,aAAa,IAAI,UAAU,CAkC1C;AAED,wBAAgB,aAAa,CAAC,IAAI,SAAS,OAAO,EAAE,EAAE,GAAG,EACvD,IAAI,EAAE,MAAM,EACZ,EAAE,EAAE,CAAC,GAAG,IAAI,EAAE,IAAI,KAAK,OAAO,CAAC,GAAG,CAAC,GAClC,CAAC,GAAG,IAAI,EAAE,IAAI,KAAK,OAAO,CAAC,GAAG,CAAC,CAqBjC;AAED,wBAAgB,qBAAqB,CAAC,IAAI,SAAS,CAAC,GAAG,IAAI,EAAE,KAAK,EAAE,KAAK,OAAO,EAAE,EAAE,EAAE,IAAI,GAAG,IAAI,CAShG;AAmBD,wBAAgB,0BAA0B,IAAI,OAAO,CAIpD"}
|
package/out/api/runtime.js
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.arePermsAvailableInRuntime = exports.bindInvocationContext = exports.wrapInMetrics = exports.getAppContext = exports.__getRuntime = exports.MissingPermissions = exports.PermissionRequirements = exports.RuntimePermissions = exports.Permissions = void 0;
|
|
3
|
+
exports.arePermsAvailableInRuntime = exports.bindInvocationContext = exports.wrapInMetrics = exports.getAppContext = exports.__getRuntime = exports.MissingPermissions = exports.PermissionRequirements = exports.RuntimePermissions = exports.Permissions = exports.EXTERNAL_RESOURCE_TYPES = void 0;
|
|
4
4
|
const errors_1 = require("./errors");
|
|
5
5
|
const ari_1 = require("./ari");
|
|
6
|
+
exports.EXTERNAL_RESOURCE_TYPES = ['fonts', 'styles', 'frames', 'images', 'media', 'scripts'];
|
|
6
7
|
function extractUrlString(item) {
|
|
7
8
|
if (typeof item === 'string') {
|
|
8
9
|
return item;
|
|
@@ -14,34 +15,54 @@ function extractUrlString(item) {
|
|
|
14
15
|
return item.remote;
|
|
15
16
|
}
|
|
16
17
|
}
|
|
18
|
+
function formatScopesSection(scopes) {
|
|
19
|
+
if (scopes && Array.isArray(scopes) && scopes.length > 0) {
|
|
20
|
+
return `Scopes: ${scopes.join(', ')}`;
|
|
21
|
+
}
|
|
22
|
+
return null;
|
|
23
|
+
}
|
|
24
|
+
function formatExternalSection(external) {
|
|
25
|
+
if (!external) {
|
|
26
|
+
return null;
|
|
27
|
+
}
|
|
28
|
+
const externalParts = [];
|
|
29
|
+
addFetchPermissions(external, externalParts);
|
|
30
|
+
addResourcePermissions(external, externalParts);
|
|
31
|
+
return externalParts.length > 0 ? `External: ${externalParts.join('; ')}` : null;
|
|
32
|
+
}
|
|
33
|
+
function addFetchPermissions(external, externalParts) {
|
|
34
|
+
if (!external.fetch) {
|
|
35
|
+
return;
|
|
36
|
+
}
|
|
37
|
+
if (external.fetch.backend && external.fetch.backend.length > 0) {
|
|
38
|
+
const backendUrls = external.fetch.backend.map(extractUrlString).join(', ');
|
|
39
|
+
externalParts.push(`Fetch Backend: ${backendUrls}`);
|
|
40
|
+
}
|
|
41
|
+
if (external.fetch.client && external.fetch.client.length > 0) {
|
|
42
|
+
const clientUrls = external.fetch.client.map(extractUrlString).join(', ');
|
|
43
|
+
externalParts.push(`Fetch Client: ${clientUrls}`);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
function addResourcePermissions(external, externalParts) {
|
|
47
|
+
for (const type of exports.EXTERNAL_RESOURCE_TYPES) {
|
|
48
|
+
const externalUrls = external[type];
|
|
49
|
+
if (externalUrls && externalUrls.length > 0) {
|
|
50
|
+
const capitalizedType = type.charAt(0).toUpperCase() + type.slice(1);
|
|
51
|
+
const urlList = externalUrls.map(extractUrlString).join(', ');
|
|
52
|
+
externalParts.push(`${capitalizedType}: ${urlList}`);
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
}
|
|
17
56
|
class Permissions {
|
|
18
57
|
format() {
|
|
19
58
|
const parts = [];
|
|
20
|
-
|
|
21
|
-
|
|
59
|
+
const scopesSection = formatScopesSection(this.scopes);
|
|
60
|
+
if (scopesSection) {
|
|
61
|
+
parts.push(scopesSection);
|
|
22
62
|
}
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
if (this.external.fetch.backend && this.external.fetch.backend.length > 0) {
|
|
27
|
-
const backendUrls = this.external.fetch.backend.map(extractUrlString).join(', ');
|
|
28
|
-
externalParts.push(`Fetch Backend: ${backendUrls}`);
|
|
29
|
-
}
|
|
30
|
-
if (this.external.fetch.client && this.external.fetch.client.length > 0) {
|
|
31
|
-
const clientUrls = this.external.fetch.client.map(extractUrlString).join(', ');
|
|
32
|
-
externalParts.push(`Fetch Client: ${clientUrls}`);
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
const resourceTypes = ['fonts', 'frames', 'navigation', 'images', 'media', 'scripts', 'styles'];
|
|
36
|
-
for (const type of resourceTypes) {
|
|
37
|
-
const externalUrls = this.external[type];
|
|
38
|
-
if (externalUrls && externalUrls.length > 0) {
|
|
39
|
-
externalParts.push(`${type.charAt(0).toUpperCase() + type.slice(1)}: ${externalUrls.join(', ')}`);
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
if (externalParts.length > 0) {
|
|
43
|
-
parts.push(`External: ${externalParts.join('; ')}`);
|
|
44
|
-
}
|
|
63
|
+
const externalSection = formatExternalSection(this.external);
|
|
64
|
+
if (externalSection) {
|
|
65
|
+
parts.push(externalSection);
|
|
45
66
|
}
|
|
46
67
|
return parts.length > 0 ? parts.join('; ') : 'No permissions specified';
|
|
47
68
|
}
|
|
@@ -142,13 +163,8 @@ function bindInvocationContext(fn) {
|
|
|
142
163
|
}
|
|
143
164
|
exports.bindInvocationContext = bindInvocationContext;
|
|
144
165
|
function arePermsAvailableInRuntime() {
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
return !!(permissions && typeof permissions === 'object');
|
|
149
|
-
}
|
|
150
|
-
catch {
|
|
151
|
-
return false;
|
|
152
|
-
}
|
|
166
|
+
const runtime = __getRuntime();
|
|
167
|
+
const permissions = runtime.appContext.permissions;
|
|
168
|
+
return !!(permissions && typeof permissions === 'object');
|
|
153
169
|
}
|
|
154
170
|
exports.arePermsAvailableInRuntime = arePermsAvailableInRuntime;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@forge/api",
|
|
3
|
-
"version": "6.1.1-experimental-
|
|
3
|
+
"version": "6.1.1-experimental-78c5fee",
|
|
4
4
|
"description": "Forge API methods",
|
|
5
5
|
"author": "Atlassian",
|
|
6
6
|
"license": "SEE LICENSE IN LICENSE.txt",
|
|
@@ -28,7 +28,7 @@
|
|
|
28
28
|
"@forge/auth": "0.0.8",
|
|
29
29
|
"@forge/egress": "2.0.3",
|
|
30
30
|
"@forge/i18n": "0.0.7",
|
|
31
|
-
"@forge/manifest": "^10.
|
|
31
|
+
"@forge/manifest": "^10.5.0-next.0-experimental-78c5fee",
|
|
32
32
|
"@forge/storage": "2.0.2",
|
|
33
33
|
"headers-utils": "^3.0.2",
|
|
34
34
|
"minimatch": "^9.0.5"
|