@forge/lint

6.0.3-next.206.1.0-next.21
out/lint/linters/server-side-linter/graphql-client.js
+out/lint/linters/server-side-linter/graphql-client.jsNew file
+105
Index: package/out/lint/linters/server-side-linter/graphql-client.js
===================================================================
--- package/out/lint/linters/server-side-linter/graphql-client.js
+++ package/out/lint/linters/server-side-linter/graphql-client.js
@@ -0,0 +1,105 @@
+"use strict";
+Object.defineProperty(exports, "__esModule", { value: true });
+exports.GraphqlClient = exports.InvalidManifestError = exports.MissingManifestError = exports.NoManifestURLError = void 0;
+const cli_shared_1 = require("@forge/cli-shared");
+class NoManifestURLError extends Error {
+    constructor() {
+        super(cli_shared_1.Text.artifact.error.noManifestUrl);
+    }
+}
+exports.NoManifestURLError = NoManifestURLError;
+class MissingManifestError extends cli_shared_1.UserError {
+    constructor() {
+        super(cli_shared_1.Text.lint.errorMissingManifest);
+    }
+}
+exports.MissingManifestError = MissingManifestError;
+class InvalidManifestError extends cli_shared_1.UserError {
+    constructor() {
+        super(cli_shared_1.Text.lint.errorInvalidManifest);
+    }
+}
+exports.InvalidManifestError = InvalidManifestError;
+class GraphqlClient {
+    graphqlClient;
+    constructor(graphqlClient) {
+        this.graphqlClient = graphqlClient;
+    }
+    async createAppManifestUploadUrl(appId, environmentKey) {
+        const mutation = `
+      mutation forge_cli_createAppManifestUploadUrl($input: CreateAppManifestUploadUrlInput!) {
+        createAppManifestUploadUrl(input: $input) {
+          success
+          preSignedUrl
+          errors {
+            message
+            extensions {
+              errorType
+              statusCode
+            }
+          }
+        }
+      }`;
+        const { response: { createAppManifestUploadUrl: { success, preSignedUrl, errors } }, requestId } = await this.graphqlClient.mutate(mutation, {
+            input: {
+                appId,
+                environmentKey
+            }
+        });
+        if (!success) {
+            const error = (0, cli_shared_1.getError)(errors);
+            throw new cli_shared_1.GraphQlMutationError(`${error.message} (requestId: ${requestId || 'unknown'})`, {
+                requestId,
+                code: error.code,
+                statusCode: error.statusCode
+            });
+        }
+        if (!preSignedUrl) {
+            throw new NoManifestURLError();
+        }
+        return preSignedUrl;
+    }
+    async getAppPreDeploymentCheck(appId, environmentKey, manifestUrl, bypassRules, buildTag, majorVersion) {
+        const query = `
+      query forge_cli_appPreDeploymentCheck($input: AppPreDeploymentCheckInput!) {
+        appPreDeploymentCheck(input: $input) {
+          outcome {
+            rule
+            category
+            value
+            reason
+            changes {
+              key
+              added
+              removed
+            }
+            errors {
+              key
+              message
+              line
+              column
+            }
+          }
+        }
+      }
+    `;
+        const result = await this.graphqlClient.query(query, {
+            input: {
+                appId,
+                environmentKey,
+                manifestUrl,
+                bypassRules,
+                buildTag,
+                majorVersion
+            }
+        });
+        if (!result.appPreDeploymentCheck) {
+            throw new MissingManifestError();
+        }
+        if (!result.appPreDeploymentCheck.outcome) {
+            throw new InvalidManifestError();
+        }
+        return result.appPreDeploymentCheck.outcome.filter((p) => p !== null);
+    }
+}
+exports.GraphqlClient = GraphqlClient;