"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.GCSPlugin = void 0;
const index_js_1 = require("../../types/index.js");
const constants_js_1 = require("./constants.js");
const s3_js_1 = require("./s3.js");
const GCSPluginVersions = {
    V1: '0.0.1'
};
var GCSActionType;
(function (GCSActionType) {
    GCSActionType["LIST_OBJECTS"] = "LIST_OBJECTS";
    GCSActionType["GET_OBJECT"] = "GET_OBJECT";
    GCSActionType["DELETE_OBJECT"] = "DELETE_OBJECT";
    GCSActionType["UPLOAD_OBJECT"] = "UPLOAD_OBJECT";
    GCSActionType["LIST_BUCKETS"] = "LIST_BUCKETS";
    GCSActionType["CREATE_BUCKET"] = "CREATE_BUCKET";
    GCSActionType["UPLOAD_MULTIPLE_OBJECTS"] = "UPLOAD_MULTIPLE_OBJECTS";
    GCSActionType["GENERATE_PRESIGNED_URL"] = "GENERATE_PRESIGNED_URL";
})(GCSActionType || (GCSActionType = {}));
const GCS_ACTION_DISPLAY_NAMES = {
    [GCSActionType.LIST_OBJECTS]: 'List files',
    [GCSActionType.GET_OBJECT]: 'Read file',
    [GCSActionType.DELETE_OBJECT]: 'Delete file',
    [GCSActionType.UPLOAD_OBJECT]: 'Upload file',
    [GCSActionType.LIST_BUCKETS]: 'List buckets',
    [GCSActionType.CREATE_BUCKET]: 'Create bucket',
    [GCSActionType.UPLOAD_MULTIPLE_OBJECTS]: 'Upload multiple files',
    [GCSActionType.GENERATE_PRESIGNED_URL]: 'Generate presigned URL'
};
const DEFAULT_GCS_PRESIGNED_URL_EXPIRATION_SECONDS = 60 * 10;
exports.GCSPlugin = {
    id: 'gcs',
    name: 'Google Cloud Storage',
    moduleName: 'GCSPlugin',
    modulePath: 'plugins/gcs/GCSPlugin',
    iconLocation: `${constants_js_1.PUBLIC_INTEGRATIONS_LOGO_URL}/gcs.png`,
    docsUrl: `${constants_js_1.DOCS_BASE_URL}/google-cloud-storage`,
    type: index_js_1.PluginType.API,
    responseType: index_js_1.PluginResponseType.JSON,
    hasRawRequest: true,
    hasMetadata: true,
    rawRequestName: 'Executed action',
    datasourceTemplate: {
        sections: [
            {
                name: 'main',
                items: [
                    {
                        label: 'Display name',
                        name: 'name',
                        startVersion: GCSPluginVersions.V1,
                        componentType: index_js_1.FormComponentType.INPUT_TEXT,
                        rules: [{ required: true, message: 'Display name is required' }]
                    },
                    {
                        label: 'Service account key',
                        name: 'authentication.custom.googleServiceAccount.value',
                        startVersion: GCSPluginVersions.V1,
                        componentType: index_js_1.FormComponentType.CODE_EDITOR,
                        language: index_js_1.EditorLanguage.JSON,
                        placeholder: constants_js_1.SERVICE_ACCOUNT_GHOST_TEXT,
                        rules: [{ required: true, message: 'Service account key is required' }]
                    }
                ]
            }
        ]
    },
    actionTemplate: {
        sections: [
            {
                name: 'main',
                items: [
                    {
                        label: 'Action',
                        name: 'action',
                        startVersion: GCSPluginVersions.V1,
                        componentType: index_js_1.FormComponentType.DROPDOWN,
                        initialValue: GCSActionType.GET_OBJECT,
                        rules: [{ required: true }],
                        options: [
                            {
                                key: GCSActionType.LIST_OBJECTS,
                                value: GCSActionType.LIST_OBJECTS,
                                displayName: GCS_ACTION_DISPLAY_NAMES[GCSActionType.LIST_OBJECTS]
                            },
                            {
                                key: GCSActionType.GET_OBJECT,
                                value: GCSActionType.GET_OBJECT,
                                displayName: GCS_ACTION_DISPLAY_NAMES[GCSActionType.GET_OBJECT]
                            },
                            {
                                key: GCSActionType.DELETE_OBJECT,
                                value: GCSActionType.DELETE_OBJECT,
                                displayName: GCS_ACTION_DISPLAY_NAMES[GCSActionType.DELETE_OBJECT]
                            },
                            {
                                key: GCSActionType.UPLOAD_OBJECT,
                                value: GCSActionType.UPLOAD_OBJECT,
                                displayName: GCS_ACTION_DISPLAY_NAMES[GCSActionType.UPLOAD_OBJECT]
                            },
                            {
                                key: GCSActionType.UPLOAD_MULTIPLE_OBJECTS,
                                value: GCSActionType.UPLOAD_MULTIPLE_OBJECTS,
                                displayName: GCS_ACTION_DISPLAY_NAMES[GCSActionType.UPLOAD_MULTIPLE_OBJECTS]
                            },
                            {
                                key: GCSActionType.LIST_BUCKETS,
                                value: GCSActionType.LIST_BUCKETS,
                                displayName: GCS_ACTION_DISPLAY_NAMES[GCSActionType.LIST_BUCKETS]
                            },
                            {
                                key: GCSActionType.GENERATE_PRESIGNED_URL,
                                value: GCSActionType.GENERATE_PRESIGNED_URL,
                                displayName: GCS_ACTION_DISPLAY_NAMES[GCSActionType.GENERATE_PRESIGNED_URL]
                            }
                        ]
                    },
                    {
                        label: 'Bucket name prefix (optional)',
                        name: 'prefix',
                        startVersion: GCSPluginVersions.V1,
                        componentType: index_js_1.FormComponentType.DYNAMIC_INPUT_TEXT,
                        display: {
                            show: {
                                action: [GCSActionType.LIST_BUCKETS]
                            }
                        }
                    },
                    {
                        label: 'Bucket name',
                        name: 'resource',
                        startVersion: GCSPluginVersions.V1,
                        componentType: index_js_1.FormComponentType.DYNAMIC_INPUT_TEXT,
                        display: {
                            show: {
                                action: [
                                    GCSActionType.LIST_OBJECTS,
                                    GCSActionType.GET_OBJECT,
                                    GCSActionType.UPLOAD_OBJECT,
                                    GCSActionType.DELETE_OBJECT,
                                    GCSActionType.UPLOAD_MULTIPLE_OBJECTS,
                                    GCSActionType.GENERATE_PRESIGNED_URL
                                ]
                            }
                        }
                    },
                    {
                        label: 'File prefix (optional)',
                        name: 'prefix',
                        startVersion: GCSPluginVersions.V1,
                        componentType: index_js_1.FormComponentType.DYNAMIC_INPUT_TEXT,
                        display: {
                            show: {
                                action: [GCSActionType.LIST_OBJECTS]
                            }
                        }
                    },
                    {
                        label: 'File name',
                        name: 'path',
                        startVersion: GCSPluginVersions.V1,
                        componentType: index_js_1.FormComponentType.DYNAMIC_INPUT_TEXT,
                        display: {
                            show: {
                                action: [
                                    GCSActionType.UPLOAD_OBJECT,
                                    GCSActionType.GET_OBJECT,
                                    GCSActionType.DELETE_OBJECT,
                                    GCSActionType.GENERATE_PRESIGNED_URL
                                ]
                            }
                        }
                    },
                    {
                        name: 'responseType',
                        label: 'File content type',
                        startVersion: GCSPluginVersions.V1,
                        componentType: index_js_1.FormComponentType.DROPDOWN,
                        initialValue: index_js_1.ActionResponseType.AUTO,
                        display: {
                            show: {
                                action: [s3_js_1.S3ActionType.GET_OBJECT]
                            }
                        },
                        options: [
                            {
                                key: index_js_1.ActionResponseType.AUTO,
                                value: index_js_1.ActionResponseType.AUTO,
                                displayName: 'Auto'
                            },
                            {
                                key: index_js_1.ActionResponseType.JSON,
                                value: index_js_1.ActionResponseType.JSON,
                                displayName: 'JSON'
                            },
                            {
                                key: index_js_1.ActionResponseType.TEXT,
                                value: index_js_1.ActionResponseType.TEXT,
                                displayName: 'Text'
                            },
                            {
                                key: index_js_1.ActionResponseType.BINARY,
                                value: index_js_1.ActionResponseType.BINARY,
                                displayName: 'Binary'
                            }
                        ]
                    },
                    {
                        label: 'File content',
                        name: 'body',
                        startVersion: GCSPluginVersions.V1,
                        componentType: index_js_1.FormComponentType.CODE_EDITOR,
                        language: index_js_1.EditorLanguage.TEXT,
                        display: {
                            show: {
                                action: [GCSActionType.UPLOAD_OBJECT]
                            }
                        }
                    },
                    {
                        label: 'File objects array',
                        name: 'fileObjects',
                        startVersion: GCSPluginVersions.V1,
                        componentType: index_js_1.FormComponentType.CODE_EDITOR,
                        language: index_js_1.EditorLanguage.TEXT,
                        placeholder: `File objects represent a Superblocks file entity.

Access the files from {{FilePicker1.files}}, or manipulate the files using:

{{FilePicker1.files.map((file) => ({
  ...file,
  name: 'user-assets/' + file.name,
}))}}
            `,
                        display: {
                            show: {
                                action: [GCSActionType.UPLOAD_MULTIPLE_OBJECTS]
                            }
                        }
                    },
                    {
                        label: 'Presigned URL expiration (seconds)',
                        name: 'custom.presignedExpiration.value',
                        startVersion: GCSPluginVersions.V1,
                        componentType: index_js_1.FormComponentType.INPUT_TEXT,
                        initialValue: DEFAULT_GCS_PRESIGNED_URL_EXPIRATION_SECONDS,
                        dataType: index_js_1.InputDataType.NUMBER,
                        display: {
                            show: {
                                action: [GCSActionType.GENERATE_PRESIGNED_URL]
                            }
                        }
                    }
                ]
            }
        ]
    }
};
//# sourceMappingURL=gcs.js.map