npm package diff

Package: @forge/runtime

Versions: 6.0.0-next.0-experimental-97e4b11 - 6.0.0-next.1

File: package/out/sandbox/invocation-request.js

Index: package/out/sandbox/invocation-request.js
===================================================================
--- package/out/sandbox/invocation-request.js
+++ package/out/sandbox/invocation-request.js
@@ -1,271 +0,0 @@
-"use strict";
-Object.defineProperty(exports, "__esModule", { value: true });
-exports.InvocationRequest = exports.xenInvocationRequestFactory = void 0;
-const app_manifest_1 = require("../app-manifest");
-const feature_flag_1 = require("../feature-flag");
-const ari_1 = require("@forge/util/packages/ari");
-const __1 = require("..");
-class XenInvocationRequestImpl {
-    request;
-    invocationId;
-    featureFlags;
-    serviceTokens = [];
-    constructor(request, invocationId) {
-        this.request = request;
-        this.invocationId = invocationId;
-        this.serviceTokens = this.buildServiceTokens(request._meta.tokens);
-    }
-    buildServiceTokens(tokens) {
-        return tokens.map((token) => ({
-            id: token.id,
-            service: token.service,
-            token: token.token,
-            externalAccountId: token.externalAccountId || '',
-            displayName: token.displayName || '',
-            avatarUrl: token.avatarUrl,
-            scopes: token.scopes || []
-        }));
-    }
-    getFeatureFlags() {
-        if (!this.featureFlags) {
-            this.featureFlags = feature_flag_1.FeatureFlags.fromRequestMetaData(this.request._meta);
-        }
-        return this.featureFlags;
-    }
-    isFeatureFlagEnabled(flag) {
-        return this.getFeatureFlags().isFeatureFlagEnabled(flag);
-    }
-    getInvocationId() {
-        return this.invocationId;
-    }
-    getAppId() {
-        return this.request._meta.appContext.appId;
-    }
-    getEnvironmentId() {
-        return this.request._meta.appContext.environmentId;
-    }
-    getCloudId() {
-        const ari = ari_1.AnyAri.parse(this.request._meta.contextAri);
-        if (ari.cloudId) {
-            return ari.cloudId;
-        }
-        if (ari.resourceType === ari_1.ResourceType.Site) {
-            return ari.resourceId;
-        }
-        return undefined;
-    }
-    getContextAri() {
-        return this.request._meta.contextAri;
-    }
-    getRmsConfig() {
-        return this.request._meta.rms;
-    }
-    getAaid() {
-        return this.request._meta.aaid;
-    }
-    getInvocationResourceOwner() {
-        return ari_1.AnyAri.parse(this.request._meta.contextAri).resourceOwner;
-    }
-    getWorkspaceId() {
-        const ari = ari_1.AnyAri.parse(this.request._meta.contextAri);
-        return ari.resourceType === 'workspace' ? ari.resourceId : undefined;
-    }
-    getAppVersion() {
-        return this.request._meta.appContext.appVersion;
-    }
-    getLimits() {
-        return this.request._meta.limits;
-    }
-    getAppToken() {
-        return this.request._meta.appToken;
-    }
-    getProxy() {
-        return this.request._meta?.proxy;
-    }
-    getAllTokens() {
-        return this.serviceTokens;
-    }
-    getUserVariables() {
-        return this.request.variables;
-    }
-    getHandler() {
-        return this.request.handler;
-    }
-    getBody() {
-        return this.request.body;
-    }
-    getLicense() {
-        return this.request._meta.license;
-    }
-    getEgressAllowList() {
-        return this.request._meta.fetchAllowList;
-    }
-    getTracing() {
-        return this.request._meta.tracing;
-    }
-    __deprecatedGetMeta() {
-        return this.request._meta;
-    }
-}
-function xenInvocationRequestFactory(invocation) {
-    const { request, ctx: { requestId } } = invocation;
-    const externalRequestBody = (0, __1.validateInvocation)(request);
-    return new XenInvocationRequestImpl(externalRequestBody, requestId);
-}
-exports.xenInvocationRequestFactory = xenInvocationRequestFactory;
-class InvocationRequest {
-    sandboxConfig;
-    xenInvocationRequest;
-    manifest;
-    static async setup(sandboxConfig, xenInvocationRequest) {
-        const manifest = await app_manifest_1.AppManifest.fromFile(sandboxConfig.appPath);
-        return this.setupSync(sandboxConfig, xenInvocationRequest, manifest);
-    }
-    static setupSync(sandboxConfig, xenInvocationRequest, manifest) {
-        return new InvocationRequest(sandboxConfig, xenInvocationRequest, manifest);
-    }
-    thirdPartyAuthTokenReferences;
-    constructor(sandboxConfig, xenInvocationRequest, manifest) {
-        this.sandboxConfig = sandboxConfig;
-        this.xenInvocationRequest = xenInvocationRequest;
-        this.manifest = manifest;
-        this.thirdPartyAuthTokenReferences = this.getThirdPartyTokenReferences();
-    }
-    getAppAri() {
-        return this.manifest.manifest.app.id;
-    }
-    isFeatureFlagEnabled(flag) {
-        return this.xenInvocationRequest.isFeatureFlagEnabled(flag);
-    }
-    getAppId() {
-        return this.xenInvocationRequest.getAppId();
-    }
-    getEnvironmentId() {
-        return this.xenInvocationRequest.getEnvironmentId();
-    }
-    getEgressAllowList() {
-        return this.xenInvocationRequest.getEgressAllowList();
-    }
-    getHostForRemote(remote) {
-        return this.manifest.getHostForRemote(remote);
-    }
-    getDefaultRemoteForProvider(provider) {
-        return this.manifest.getDefaultRemoteForProvider(provider);
-    }
-    getExternalAuthProviderConfig(provider) {
-        return this.manifest.getExternalAuthProviderConfig(provider);
-    }
-    getSandboxConfig() {
-        return this.sandboxConfig;
-    }
-    getInvocationId() {
-        return this.xenInvocationRequest.getInvocationId();
-    }
-    getCloudId() {
-        return this.xenInvocationRequest.getCloudId();
-    }
-    getWorkspaceId() {
-        return this.xenInvocationRequest.getWorkspaceId();
-    }
-    getContextAri() {
-        return this.xenInvocationRequest.getContextAri();
-    }
-    getRmsConfig() {
-        return this.xenInvocationRequest.getRmsConfig();
-    }
-    getInvocationResourceOwner() {
-        return this.xenInvocationRequest.getInvocationResourceOwner();
-    }
-    getAppToken() {
-        return this.xenInvocationRequest.getAppToken();
-    }
-    getProxy() {
-        return this.xenInvocationRequest.getProxy();
-    }
-    getAaid() {
-        return this.xenInvocationRequest.getAaid();
-    }
-    getTokenByTokenId(requestedServiceKey, tokenId) {
-        const allTokens = this.getAllTokens(requestedServiceKey);
-        const filteredTokens = tokenId !== undefined ? allTokens.filter((token) => token.id == tokenId) : allTokens;
-        return this.pickTokenToUse(filteredTokens);
-    }
-    getTokenByExternalAccount(requestedServiceKey, externalAccountIdToFilter) {
-        const tokens = this.getTokensByServiceAndAccount(requestedServiceKey, externalAccountIdToFilter);
-        return this.pickTokenToUse(tokens);
-    }
-    getTokensByServiceAndAccount(requestedServiceKey, externalAccountIdToFilter) {
-        const tokens = this.getAllTokens(requestedServiceKey);
-        return externalAccountIdToFilter !== undefined
-            ? tokens.filter(({ externalAccountId }) => externalAccountId === externalAccountIdToFilter)
-            : tokens;
-    }
-    static isSuperset(superset, subset) {
-        return !subset || subset.every((scopeInSubset) => superset.includes(scopeInSubset));
-    }
-    getExternalAuthAccounts(serviceKey, externalAccountId, scopes) {
-        return this.getTokensByServiceAndAccount(serviceKey, externalAccountId)
-            .filter((serviceToken) => InvocationRequest.isSuperset(serviceToken.scopes, scopes))
-            .map((token) => ({
-            id: token.externalAccountId,
-            displayName: token.displayName,
-            avatarUrl: token.avatarUrl,
-            scopes: token.scopes
-        }));
-    }
-    getTokenIDsForService(serviceKey) {
-        return this.getAllTokens(serviceKey).map((token) => token.id);
-    }
-    getAllTokens(serviceKey) {
-        return this.xenInvocationRequest
-            .getAllTokens()
-            .filter(({ service }) => serviceKey === undefined || service === serviceKey);
-    }
-    getAtlassianTokenServiceKey() {
-        return 'atlassian-token-service-key';
-    }
-    pickTokenToUse(serviceTokens) {
-        return serviceTokens ? serviceTokens[0] : undefined;
-    }
-    getAtlassianServiceToken() {
-        const atlassianTokens = this.getAllTokens(this.getAtlassianTokenServiceKey());
-        return this.pickTokenToUse(atlassianTokens)?.token;
-    }
-    getAppTokenKey() {
-        return '__atlassian-app-token';
-    }
-    getThirdPartyTokenReferenceList(serviceKey) {
-        return (this.thirdPartyAuthTokenReferences
-            ?.filter((ref) => ref.serviceKey === serviceKey)
-            .map((service) => service.reference) || []);
-    }
-    getThirdPartyTokenReferences() {
-        return this.getThirdPartyTokens().map(({ service, token }, index) => {
-            const reference = `${service}-${index + 1}`;
-            return {
-                reference,
-                token,
-                serviceKey: service
-            };
-        });
-    }
-    getThirdPartyTokens() {
-        return this.getAllTokens().filter(({ service }) => service !== this.getAtlassianTokenServiceKey());
-    }
-    getThirdPartyToken(serviceKey) {
-        return this.thirdPartyAuthTokenReferences?.find((ref) => ref.reference === serviceKey || ref.serviceKey === serviceKey)?.token;
-    }
-    getAppVersion() {
-        return this.xenInvocationRequest.getAppVersion();
-    }
-    getLimits() {
-        return this.xenInvocationRequest.getLimits();
-    }
-    getLicense() {
-        return this.xenInvocationRequest.getLicense();
-    }
-    getTracing() {
-        return this.xenInvocationRequest.getTracing();
-    }
-}
-exports.InvocationRequest = InvocationRequest;