npm package diff
Package: @forge/cli
Versions: 11.3.0-next.28-experimental-1aaebb0 - 11.3.0-next.32
File: package/out/containers/container-command.js
Index: package/out/containers/container-command.js
===================================================================
--- package/out/containers/container-command.js
+++ package/out/containers/container-command.js
@@ -0,0 +1,159 @@
+"use strict";
+Object.defineProperty(exports, "__esModule", { value: true });
+exports.ContainerCommand = exports.UnexpectedAppContainerRegistryLoginError = void 0;
+const cli_shared_1 = require("@forge/cli-shared");
+class UnexpectedAppContainerRegistryLoginError extends Error {
+ constructor() {
+ super('Unable to retrieve app container registry login details');
+ }
+}
+exports.UnexpectedAppContainerRegistryLoginError = UnexpectedAppContainerRegistryLoginError;
+class ContainerCommand {
+ client;
+ getAppConfig;
+ constructor(client, getAppConfig) {
+ this.client = client;
+ this.getAppConfig = getAppConfig;
+ }
+ async createContainer(key) {
+ const { id: appId } = await this.getAppConfig();
+ const mutation = `
+ mutation forge_cli_createAppContainer($input: AppContainerInput!) {
+ createAppContainer(input: $input) {
+ container {
+ repositoryURI
+ }
+ success
+ errors {
+ message
+ extensions {
+ errorType
+ statusCode
+ }
+ }
+ }
+ }`;
+ const { response: { createAppContainer: { container, success, errors } }, requestId } = await this.client.mutate(mutation, {
+ input: {
+ appId,
+ containerKey: key
+ }
+ });
+ 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
+ });
+ }
+ return container;
+ }
+ async fetchContainers() {
+ const { id: appId } = await this.getAppConfig();
+ const query = `
+ query forge_cli_appContainers($appId: ID!) {
+ appContainers(appId: $appId) {
+ key
+ repositoryURI
+ images(first: 1) {
+ edges {
+ node {
+ digest
+ sizeInBytes
+ pushedAt
+ lastPulledAt
+ tags
+ }
+ }
+ }
+ }
+ }`;
+ const { appContainers } = await this.client.query(query, {
+ appId
+ });
+ return appContainers ?? [];
+ }
+ async deleteContainer(key) {
+ const { id: appId } = await this.getAppConfig();
+ const mutation = `
+ mutation forge_cli_deleteAppContainer($input: AppContainerInput!) {
+ deleteAppContainer(input: $input) {
+ success
+ errors {
+ message
+ extensions {
+ errorType
+ statusCode
+ }
+ }
+ }
+ }`;
+ const { response: { deleteAppContainer: { success, errors } }, requestId } = await this.client.mutate(mutation, {
+ input: {
+ appId,
+ containerKey: key
+ }
+ });
+ 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
+ });
+ }
+ }
+ async fetchLoginDetails() {
+ const { id: appId } = await this.getAppConfig();
+ const query = `
+ query forge_cli_appContainerRegistryLogin($appId: ID!) {
+ appContainerRegistryLogin(appId: $appId) {
+ username
+ password
+ endpoint
+ }
+ }`;
+ const { appContainerRegistryLogin } = await this.client.query(query, {
+ appId
+ });
+ if (!appContainerRegistryLogin) {
+ throw new UnexpectedAppContainerRegistryLoginError();
+ }
+ return appContainerRegistryLogin;
+ }
+ async fetchImages(key, startCursor) {
+ const { id: appId } = await this.getAppConfig();
+ const query = `
+ query forge_cli_appContainer($appId: ID!, $containerKey: String!, $after: ID) {
+ appContainer(appId: $appId, containerKey: $containerKey) {
+ images(first: 10, after: $after) {
+ edges {
+ node {
+ digest
+ sizeInBytes
+ pushedAt
+ lastPulledAt
+ tags
+ }
+ }
+ pageInfo {
+ hasNextPage
+ endCursor
+ }
+ }
+ }
+ }`;
+ const { appContainer } = await this.client.query(query, {
+ appId,
+ containerKey: key,
+ after: startCursor
+ });
+ return {
+ images: appContainer?.images.edges.map(({ node }) => node) ?? [],
+ endCursor: appContainer?.images.pageInfo.endCursor ?? undefined,
+ hasNextPage: appContainer?.images.pageInfo.hasNextPage ?? false
+ };
+ }
+}
+exports.ContainerCommand = ContainerCommand;