@forge/cli
14.1.0-next.21-experimental-554d41714.1.0-next.19-experimental-fd0ebbc
out/installations/graphql-client.js~
out/installations/graphql-client.jsModified+87−161
Index: package/out/installations/graphql-client.js
===================================================================
--- package/out/installations/graphql-client.js
+++ package/out/installations/graphql-client.js
@@ -4,9 +4,8 @@
const exponential_backoff_1 = require("exponential-backoff");
const ari_1 = require("@forge/util/packages/ari");
const cli_shared_1 = require("@forge/cli-shared");
const egress_1 = require("@forge/egress");
-const installation_helper_1 = require("./installation-helper");
const harmonized_app_installation_errors_1 = require("./harmonized-apps/harmonized-app-installation-errors");
exports.UNINSTALLATION_EVENT_POLL_INTERVAL = 500;
const DECOUPLED_STATE_NOT_ENABLED_CODE = 'DECOUPLED_STATE_NOT_ENABLED';
const APP_INSTALLATION_LIMIT_WARNING = 'APP_INSTALLATION_LIMIT_WARNING';
@@ -137,24 +136,16 @@
pause;
logger;
SITE_RESOURCE_TYPE = 'site';
WORKSPACE_RESOURCE_TYPE = 'workspace';
- UNIT_RESOURCE_TYPE = 'unit';
static buildInstallationContext(product, resourceId, resourceType) {
const ari = ari_1.AnyAri.create({
resourceOwner: (0, cli_shared_1.ariResourceOwner)(product),
resourceType: resourceType,
resourceId: resourceId
});
return ari.toString();
}
- static buildUnitInstallationContext(unitId) {
- return ari_1.AnyAri.create({
- resourceOwner: 'platform',
- resourceType: 'unit',
- resourceId: unitId
- }).toString();
- }
constructor(graphqlClient, sitedProductTranslator, bitbucketTranslator, pause, logger = cli_shared_1.NullLogger) {
this.graphqlClient = graphqlClient;
this.sitedProductTranslator = sitedProductTranslator;
this.bitbucketTranslator = bitbucketTranslator;
@@ -193,15 +184,15 @@
}
}
return undefined;
}
- async submitInstallMutation({ installationContext, appId, environmentKey, licenseOverride, overrides, majorVersionId, environmentType }) {
- const query = `
+ async installAppIntoSite({ environmentKey, site, product, appId, licenseOverride, overrides, majorVersionId, environmentType }) {
+ const workspaceAri = await this.buildInstallationContext(product, site);
+ const query = (0, cli_shared_1.graphql)(`
mutation forge_cli_installApplication($input: AppInstallationInput!) {
installApp(input: $input) {
success
taskId
- installationId
errors {
message
extensions {
errorType
@@ -209,22 +200,22 @@
}
}
}
}
- `;
+ `);
const variables = {
input: {
- installationContext,
+ installationContext: workspaceAri,
appId,
environmentKey,
async: true,
licenseOverride,
overrides,
...(majorVersionId ? { versionId: majorVersionId } : {})
}
};
- const mutationResult = await this.graphqlClient.mutate(query, variables);
- const { response: { installApp: { success, taskId, installationId, errors } }, requestId, extensions } = mutationResult;
+ const { response, requestId, extensions } = await this.graphqlClient.mutate(query, variables);
+ const { success, taskId, errors } = (0, cli_shared_1.requireMutationPayload)(response.installApp, requestId);
const error = (0, cli_shared_1.getError)(errors);
if (!success) {
if (error.code === PERMISSION_DENIED) {
throw new PermissionDeniedError(requestId, ari_1.AnyAri.parse(appId).resourceId, error.statusCode);
@@ -238,134 +229,38 @@
if (!taskId) {
throw new MissingTaskIdError(error.message);
}
await this.monitorAppInstallOrUpgrade(taskId, !!majorVersionId, environmentKey, environmentType);
- return { installationId: installationId ?? undefined, warnings: this.extractInstallWarnings(extensions) };
+ const warnings = this.extractInstallWarnings(extensions);
+ return {
+ warnings
+ };
}
- async installAppIntoSite({ environmentKey, site, product, appId, licenseOverride, overrides, majorVersionId, environmentType }) {
- const { warnings } = await this.submitInstallMutation({
- installationContext: await this.buildInstallationContext(product, site),
- appId,
- environmentKey,
- licenseOverride,
- overrides,
- majorVersionId,
- environmentType
- });
- return { warnings };
- }
- async installAppIntoUnit({ environmentKey, unitId, appId, licenseOverride, overrides, majorVersionId, environmentType }) {
- const { installationId, warnings } = await this.submitInstallMutation({
- installationContext: InstallationsGraphqlClient.buildUnitInstallationContext(unitId),
- appId,
- environmentKey,
- licenseOverride,
- overrides,
- majorVersionId,
- environmentType
- });
- const resolvedInstallationId = installationId ?? (await this.getUnitInstallationId(appId, environmentKey, unitId));
- return { installationId: resolvedInstallationId, warnings };
- }
- async upgradeAppInUnit({ appId, environmentKey, unitId, majorVersionId, isCodeUpgrade }) {
- const { success, errors, taskId, requestId } = await this.submitUpgradeMutation({
- installationContext: InstallationsGraphqlClient.buildUnitInstallationContext(unitId),
- appId,
- environmentKey,
- majorVersionId,
- isCodeUpgrade
- });
- const error = (0, cli_shared_1.getError)(errors);
- if (!success) {
- throw new UpgradeError(`${error.message} (requestId: ${requestId || 'unknown'})`, {
- requestId,
- code: error.code,
- statusCode: error.statusCode
- });
- }
- if (!taskId) {
- throw new MissingTaskIdError(error.message);
- }
- await this.monitorAppInstallOrUpgrade(taskId, !!majorVersionId, environmentKey);
- }
- async submitUpgradeMutation({ installationContext, appId, environmentKey, majorVersionId, isCodeUpgrade }) {
- const query = `
- mutation forge_cli_upgradeApplication($input: AppInstallationUpgradeInput!) {
- upgradeApp(input: $input) {
- success
- taskId
- errors {
- message
- extensions {
- errorType
- statusCode
- }
- }
- }
- }
- `;
- const { response: { upgradeApp: { success, errors, taskId } }, requestId } = await this.graphqlClient.mutate(query, {
- input: {
- installationContext,
- appId,
- environmentKey,
- ...(majorVersionId ? { versionId: majorVersionId } : {}),
- ...(isCodeUpgrade ? { computeOnly: isCodeUpgrade } : {}),
- async: true
- }
- });
- return { success, errors, taskId, requestId };
- }
- async getUnitInstallationId(appId, environmentKey, unitId) {
- const installations = await this.listInstallations(appId, { environment: environmentKey });
- return installations.find((installation) => installation.installedInUnit && installation.unitId === unitId)?.id;
- }
- async getUnitInstallations(appId, environmentKey) {
- const installations = await this.listInstallations(appId, { environment: environmentKey });
- return installations
- .filter((installation) => Boolean(installation.installedInUnit && installation.unitId))
- .map((installation) => ({
- unitId: installation.unitId,
- environmentKey: installation.environmentKey,
- connections: (installation.connections ?? []).map((connection) => connection.product),
- version: installation.version.version,
- isLatest: installation.version.isLatest
- }));
- }
- async getLinkedConnectionProducts(appId, installationId) {
- const installation = await this.getInstallation(appId, installationId);
- return (installation.connections ?? []).map((connection) => connection.product);
- }
- async linkOptionalConnection(installationId, product, site) {
- const context = await this.buildInstallationContext(product, site);
- await this.provisionInstallationLink({
- installationAri: (0, installation_helper_1.buildInstallationContextFromId)(installationId),
- context
- });
- }
async getEntitlementOffering(site, product) {
try {
const productKeys = this.getHamsProductKeys(product);
- const results = await Promise.allSettled(productKeys.map((productKey) => this.graphqlClient.query(`query getEntitlementOffering($hostNames: [String!], $product: String!) {
- tenantContexts(hostNames: $hostNames) {
- cloudUrl
- entitlementInfo(hamsProductKey: $product) {
- entitlement {
- ... on HamsEntitlement {
+ const results = await Promise.allSettled(productKeys.map((productKey) => this.graphqlClient.query((0, cli_shared_1.graphql)(`
+ query getEntitlementOffering($hostNames: [String!], $product: String!) {
+ tenantContexts(hostNames: $hostNames) {
+ cloudUrl
+ entitlementInfo(hamsProductKey: $product) {
+ entitlement {
+ ... on HamsEntitlement {
id
name
currentEdition
}
- ... on CcpEntitlement {
- id
- offering {
- name
+ ... on CcpEntitlement {
+ id
+ offering {
+ name
+ }
}
}
}
}
}
- }`, {
+ `), {
hostNames: [site.hostname],
product: productKey
})));
for (const result of results) {
@@ -404,15 +299,35 @@
}
}
async upgradeInstallation({ site, product, environmentKey, appId, currentVersion, majorVersionId, isCodeUpgrade, targetVersion, isLatest }) {
const workspaceAri = await this.buildInstallationContext(product, site);
- const { success, errors, taskId, requestId } = await this.submitUpgradeMutation({
- installationContext: workspaceAri,
- appId,
- environmentKey,
- majorVersionId,
- isCodeUpgrade
- });
+ const query = (0, cli_shared_1.graphql)(`
+ mutation forge_cli_upgradeApplication($input: AppInstallationUpgradeInput!) {
+ upgradeApp(input: $input) {
+ success
+ taskId
+ errors {
+ message
+ extensions {
+ errorType
+ statusCode
+ }
+ }
+ }
+ }
+ `);
+ const variables = {
+ input: {
+ installationContext: workspaceAri,
+ appId,
+ environmentKey,
+ ...(majorVersionId ? { versionId: majorVersionId } : {}),
+ ...(isCodeUpgrade ? { computeOnly: isCodeUpgrade } : {}),
+ async: true
+ }
+ };
+ const { response, requestId } = await this.graphqlClient.mutate(query, variables);
+ const { success, errors, taskId } = (0, cli_shared_1.requireMutationPayload)(response.upgradeApp, requestId);
const error = (0, cli_shared_1.getError)(errors);
if (!success) {
const { VERSION_DECREASES_ROLLING_RELEASE_CODE, MISSING_APP_MANAGED_PERMISSIONS_ROLLING_RELEASE_CODE } = RollingReleaseValidationErrorCodes;
switch (error.code) {
@@ -475,9 +390,9 @@
}
throw new InstallationRequestFailedError(isUserError, code, (0, harmonized_app_installation_errors_1.expandHarmonizedAppInstallationError)(code, error?.message ?? undefined), requestId);
}
async uninstallApp(input) {
- const query = `
+ const query = (0, cli_shared_1.graphql)(`
mutation forge_cli_uninstallApplication($input: AppUninstallationInput!) {
uninstallApp(input: $input) {
success
taskId
@@ -489,10 +404,11 @@
}
}
}
}
- `;
- const { response: { uninstallApp: { success, errors, taskId } }, requestId } = await this.graphqlClient.mutate(query, { input });
+ `);
+ const { response, requestId } = await this.graphqlClient.mutate(query, { input });
+ const { success, errors, taskId } = (0, cli_shared_1.requireMutationPayload)(response.uninstallApp, requestId);
const error = (0, cli_shared_1.getError)(errors);
if (!success) {
throw new cli_shared_1.GraphQlMutationError(`${error.message} (requestId: ${requestId || 'unknown'})`, {
requestId,
@@ -518,9 +434,9 @@
}
return uninstallsResult;
}
async provisionInstallationLink(input) {
- const query = `
+ const query = (0, cli_shared_1.graphql)(`
mutation forge_cli_provisionInstallationLink($input: ProvisionInstallationLinkInput!) {
ecosystem {
provisionInstallationLink(input: $input) {
success
@@ -534,10 +450,12 @@
}
}
}
}
- `;
- const { response: { ecosystem: { provisionInstallationLink: { success, errors, taskId } } }, requestId } = await this.graphqlClient.mutate(query, { input });
+ `);
+ const { response, requestId } = await this.graphqlClient.mutate(query, { input });
+ const { provisionInstallationLink } = (0, cli_shared_1.requireMutationPayload)(response.ecosystem, requestId);
+ const { success, errors, taskId } = (0, cli_shared_1.requireMutationPayload)(provisionInstallationLink, requestId);
const error = (0, cli_shared_1.getError)(errors);
if (!success) {
throw new cli_shared_1.GraphQlMutationError(`${error.message} (requestId: ${requestId || 'unknown'})`, {
requestId,
@@ -550,9 +468,9 @@
}
await this.monitorAppInstallOrUpgrade(taskId);
}
async deprovisionInstallationLink(input) {
- const query = `
+ const query = (0, cli_shared_1.graphql)(`
mutation forge_cli_deprovisionInstallationLink($input: DeprovisionInstallationLinkInput!) {
ecosystem {
deprovisionInstallationLink(input: $input) {
success
@@ -566,10 +484,12 @@
}
}
}
}
- `;
- const { response: { ecosystem: { deprovisionInstallationLink: { success, errors, taskId } } }, requestId } = await this.graphqlClient.mutate(query, { input });
+ `);
+ const { response, requestId } = await this.graphqlClient.mutate(query, { input });
+ const { deprovisionInstallationLink } = (0, cli_shared_1.requireMutationPayload)(response.ecosystem, requestId);
+ const { success, errors, taskId } = (0, cli_shared_1.requireMutationPayload)(deprovisionInstallationLink, requestId);
const error = (0, cli_shared_1.getError)(errors);
if (!success) {
throw new cli_shared_1.GraphQlMutationError(`${error.message} (requestId: ${requestId || 'unknown'})`, {
requestId,
@@ -594,35 +514,35 @@
}
throw new InstallationNotFoundError(cli_shared_1.Text.installationId.errors.notFound(installationId));
}
async hasNoAppInstallationsForEnv(appId, appEnv) {
- const query = `
+ const query = (0, cli_shared_1.graphql)(`
query forge_cli_hasNoAppInstallationsForEnv($filter: AppInstallationsByAppFilter!) {
ecosystem {
appInstallationsByApp(filter: $filter, first: 1) {
totalCount
}
}
}
- `;
- const result = (await this.graphqlClient.query(query, {
+ `);
+ const result = await this.graphqlClient.query(query, {
filter: {
apps: {
ids: [appId]
},
appEnvironments: {
types: [appEnv]
}
}
- }));
+ });
const totalCount = result?.ecosystem?.appInstallationsByApp?.totalCount ?? -1;
if (totalCount < 0) {
throw new MissingAppError();
}
return totalCount === 0;
}
async getAppInstallationTask(taskId) {
- const query = `
+ const query = (0, cli_shared_1.graphql)(`
query forge_cli_getInstallationTask($id: ID!) {
appInstallationTask(id: $id) {
state
errors {
@@ -633,9 +553,9 @@
}
}
}
}
- `;
+ `);
const { appInstallationTask, requestId } = await this.graphqlClient.query(query, {
id: taskId
});
if (!appInstallationTask) {
@@ -736,10 +656,14 @@
egressAddresses: (0, egress_1.sortAndGroupEgressPermissionsByDomain)(rawEgressAddresses)
};
}
async getAllInstallations(appId, installationFilterOptions) {
- const query = `
- query forge_cli_getEcosystemInstallationsByApp($filter: AppInstallationsByAppFilter!, $first: Int, $after: String) {
+ const query = (0, cli_shared_1.graphql)(`
+ query forge_cli_getEcosystemInstallationsByApp(
+ $filter: AppInstallationsByAppFilter!
+ $first: Int
+ $after: String
+ ) {
ecosystem {
appInstallationsByApp(filter: $filter, first: $first, after: $after) {
nodes {
id
@@ -780,19 +704,20 @@
}
}
}
}
- `;
+ `);
const output = [];
let cursor = undefined;
let hasNext = undefined;
do {
const filter = await InstallationsGraphqlClient.buildInstallationsFilter(appId, installationFilterOptions, this.buildInstallationContext.bind(this));
- const result = (await this.graphqlClient.query(query, {
+ const variables = {
filter,
first: 100,
after: cursor
- }));
+ };
+ const result = await this.graphqlClient.query(query, variables);
if (!result?.ecosystem?.appInstallationsByApp?.nodes) {
throw new MissingAppError();
}
const { nodes, pageInfo } = result.ecosystem.appInstallationsByApp;
@@ -834,9 +759,9 @@
}
return filter;
}
async getVersions(appId, environmentKey, firstN = 1) {
- const query = `
+ const query = (0, cli_shared_1.graphql)(`
query forge_cli_getApplicationEnvironmentLatestVersions($appId: ID!, $environmentKey: String!, $firstN: Int!) {
app(id: $appId) {
appFeatures {
key
@@ -862,9 +787,9 @@
}
}
}
}
- `;
+ `);
const result = await this.graphqlClient.query(query, {
appId,
environmentKey,
firstN
@@ -885,10 +810,10 @@
async getVersionByMajorVersionId(id, environmentKey, majorVersion) {
if (!majorVersion) {
return undefined;
}
- const query = `
- query forge_cli_getApplicationVersionList($id: ID!, $environmentKey: String!, $majorVersion: Int!) {
+ const query = (0, cli_shared_1.graphql)(`
+ query forge_cli_getApplicationVersionListByMajor($id: ID!, $environmentKey: String!, $majorVersion: Int!) {
app(id: $id) {
appFeatures {
key
value
@@ -913,9 +838,10 @@
}
}
}
}
- }`;
+ }
+ `);
const variables = {
id,
environmentKey,
majorVersion