"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.S3Plugin = exports.S3ActionType = void 0;
const index_js_1 = require("../../types/index.js");
const constants_js_1 = require("./constants.js");
const index_js_2 = require("./shared/index.js");
const utils_js_1 = require("./utils.js");
const S3PluginVersions = {
    V1: '0.0.1',
    V5: '0.0.5',
    V6: '0.0.6',
    V10: '0.0.10',
    V11: '0.0.11'
};
var S3ActionType;
(function (S3ActionType) {
    /**
     * @deprecated Use LIST_BUCKET_OBJECTS instead.
     */
    S3ActionType["LIST_OBJECTS"] = "LIST_OBJECTS";
    S3ActionType["LIST_BUCKET_OBJECTS"] = "LIST_BUCKET_OBJECTS";
    S3ActionType["GET_OBJECT"] = "GET_OBJECT";
    S3ActionType["DELETE_OBJECT"] = "DELETE_OBJECT";
    S3ActionType["UPLOAD_OBJECT"] = "UPLOAD_OBJECT";
    S3ActionType["LIST_BUCKETS"] = "LIST_BUCKETS";
    S3ActionType["CREATE_BUCKET"] = "CREATE_BUCKET";
    S3ActionType["UPLOAD_MULTIPLE_OBJECTS"] = "UPLOAD_MULTIPLE_OBJECTS";
    S3ActionType["GENERATE_PRESIGNED_URL"] = "GENERATE_PRESIGNED_URL";
})(S3ActionType || (exports.S3ActionType = S3ActionType = {}));
const S3_ACTION_DISPLAY_NAMES = {
    [S3ActionType.LIST_OBJECTS]: 'List files',
    [S3ActionType.LIST_BUCKET_OBJECTS]: 'List bucket objects',
    [S3ActionType.GET_OBJECT]: 'Read file',
    [S3ActionType.DELETE_OBJECT]: 'Delete files',
    [S3ActionType.UPLOAD_OBJECT]: 'Upload file',
    [S3ActionType.LIST_BUCKETS]: 'List buckets',
    [S3ActionType.CREATE_BUCKET]: 'Create bucket',
    [S3ActionType.UPLOAD_MULTIPLE_OBJECTS]: 'Upload multiple files',
    [S3ActionType.GENERATE_PRESIGNED_URL]: 'Generate presigned URL'
};
const S3_DROPDOWN_ACTIONS_V1_TO_V10 = (0, utils_js_1.sortByDisplayName)([
    {
        key: S3ActionType.LIST_OBJECTS,
        value: S3ActionType.LIST_OBJECTS,
        displayName: S3_ACTION_DISPLAY_NAMES[S3ActionType.LIST_OBJECTS]
    },
    {
        key: S3ActionType.GET_OBJECT,
        value: S3ActionType.GET_OBJECT,
        displayName: S3_ACTION_DISPLAY_NAMES[S3ActionType.GET_OBJECT]
    },
    {
        key: S3ActionType.DELETE_OBJECT,
        value: S3ActionType.DELETE_OBJECT,
        displayName: S3_ACTION_DISPLAY_NAMES[S3ActionType.DELETE_OBJECT]
    },
    {
        key: S3ActionType.UPLOAD_OBJECT,
        value: S3ActionType.UPLOAD_OBJECT,
        displayName: S3_ACTION_DISPLAY_NAMES[S3ActionType.UPLOAD_OBJECT]
    },
    {
        key: S3ActionType.UPLOAD_MULTIPLE_OBJECTS,
        value: S3ActionType.UPLOAD_MULTIPLE_OBJECTS,
        displayName: S3_ACTION_DISPLAY_NAMES[S3ActionType.UPLOAD_MULTIPLE_OBJECTS]
    },
    {
        key: S3ActionType.LIST_BUCKETS,
        value: S3ActionType.LIST_BUCKETS,
        displayName: S3_ACTION_DISPLAY_NAMES[S3ActionType.LIST_BUCKETS]
    },
    {
        key: S3ActionType.GENERATE_PRESIGNED_URL,
        value: S3ActionType.GENERATE_PRESIGNED_URL,
        displayName: S3_ACTION_DISPLAY_NAMES[S3ActionType.GENERATE_PRESIGNED_URL]
    }
]);
const S3_DROPDOWN_ACTIONS_V11 = (0, utils_js_1.sortByDisplayName)([
    {
        key: S3ActionType.LIST_OBJECTS,
        value: S3ActionType.LIST_OBJECTS,
        displayName: (0, utils_js_1.markAsDeprecated)(S3_ACTION_DISPLAY_NAMES[S3ActionType.LIST_OBJECTS])
    },
    {
        key: S3ActionType.LIST_BUCKET_OBJECTS,
        value: S3ActionType.LIST_BUCKET_OBJECTS,
        displayName: S3_ACTION_DISPLAY_NAMES[S3ActionType.LIST_BUCKET_OBJECTS]
    },
    {
        key: S3ActionType.GET_OBJECT,
        value: S3ActionType.GET_OBJECT,
        displayName: S3_ACTION_DISPLAY_NAMES[S3ActionType.GET_OBJECT]
    },
    {
        key: S3ActionType.DELETE_OBJECT,
        value: S3ActionType.DELETE_OBJECT,
        displayName: S3_ACTION_DISPLAY_NAMES[S3ActionType.DELETE_OBJECT]
    },
    {
        key: S3ActionType.UPLOAD_OBJECT,
        value: S3ActionType.UPLOAD_OBJECT,
        displayName: S3_ACTION_DISPLAY_NAMES[S3ActionType.UPLOAD_OBJECT]
    },
    {
        key: S3ActionType.UPLOAD_MULTIPLE_OBJECTS,
        value: S3ActionType.UPLOAD_MULTIPLE_OBJECTS,
        displayName: S3_ACTION_DISPLAY_NAMES[S3ActionType.UPLOAD_MULTIPLE_OBJECTS]
    },
    {
        key: S3ActionType.LIST_BUCKETS,
        value: S3ActionType.LIST_BUCKETS,
        displayName: S3_ACTION_DISPLAY_NAMES[S3ActionType.LIST_BUCKETS]
    },
    {
        key: S3ActionType.GENERATE_PRESIGNED_URL,
        value: S3ActionType.GENERATE_PRESIGNED_URL,
        displayName: S3_ACTION_DISPLAY_NAMES[S3ActionType.GENERATE_PRESIGNED_URL]
    }
]);
const DEFAULT_S3_PRESIGNED_URL_EXPIRATION_SECONDS = 60 * 10;
exports.S3Plugin = {
    id: 's3',
    name: 'Amazon S3',
    moduleName: 'S3Plugin',
    modulePath: 'plugins/s3/S3Plugin',
    iconLocation: `${constants_js_1.PUBLIC_INTEGRATIONS_LOGO_URL}/s3.png`,
    docsUrl: `${constants_js_1.DOCS_BASE_URL}/aws-s3`,
    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: S3PluginVersions.V1,
                        componentType: index_js_1.FormComponentType.INPUT_TEXT,
                        rules: [{ required: true, message: 'Display name is required' }]
                    },
                    {
                        label: 'Region',
                        name: 'authentication.custom.region.value',
                        startVersion: S3PluginVersions.V1,
                        componentType: index_js_1.FormComponentType.INPUT_TEXT,
                        agentType: index_js_1.AgentType.MULTITENANT
                    },
                    {
                        label: 'Access key ID',
                        name: 'authentication.custom.accessKeyID.value',
                        startVersion: S3PluginVersions.V1,
                        componentType: index_js_1.FormComponentType.INPUT_TEXT,
                        agentType: index_js_1.AgentType.MULTITENANT
                    },
                    {
                        label: 'Secret key',
                        name: 'authentication.custom.secretKey.value',
                        startVersion: S3PluginVersions.V1,
                        componentType: index_js_1.FormComponentType.INPUT_TEXT,
                        dataType: index_js_1.InputDataType.PASSWORD,
                        agentType: index_js_1.AgentType.MULTITENANT
                    },
                    {
                        label: 'IAM role ARN (optional)',
                        name: 'authentication.custom.iamRoleArn.value',
                        startVersion: S3PluginVersions.V6,
                        componentType: index_js_1.FormComponentType.INPUT_TEXT,
                        agentType: index_js_1.AgentType.MULTITENANT,
                        rules: [{ required: false }]
                    }
                ]
            },
            (0, index_js_2.getAWSAuthSection)({ startVersion: S3PluginVersions.V5, startVersionForRoleAssumption: S3PluginVersions.V6 })
        ]
    },
    actionTemplate: {
        sections: [
            {
                name: 'main',
                items: [
                    {
                        label: 'Action',
                        name: 'action',
                        startVersion: S3PluginVersions.V1,
                        endVersion: S3PluginVersions.V10,
                        componentType: index_js_1.FormComponentType.DROPDOWN,
                        initialValue: S3ActionType.GET_OBJECT,
                        rules: [{ required: true }],
                        options: S3_DROPDOWN_ACTIONS_V1_TO_V10
                    },
                    {
                        label: 'Action',
                        name: 'action',
                        startVersion: S3PluginVersions.V11,
                        componentType: index_js_1.FormComponentType.DROPDOWN,
                        initialValue: S3ActionType.GET_OBJECT,
                        rules: [{ required: true }],
                        options: S3_DROPDOWN_ACTIONS_V11
                    },
                    {
                        label: 'Bucket name',
                        name: 'resource',
                        startVersion: S3PluginVersions.V1,
                        componentType: index_js_1.FormComponentType.DYNAMIC_INPUT_TEXT,
                        display: {
                            show: {
                                action: [
                                    S3ActionType.LIST_OBJECTS,
                                    S3ActionType.GET_OBJECT,
                                    S3ActionType.UPLOAD_OBJECT,
                                    S3ActionType.DELETE_OBJECT,
                                    S3ActionType.UPLOAD_MULTIPLE_OBJECTS,
                                    S3ActionType.GENERATE_PRESIGNED_URL
                                ]
                            }
                        }
                    },
                    {
                        label: 'Bucket name',
                        name: 'resource',
                        startVersion: S3PluginVersions.V11,
                        componentType: index_js_1.FormComponentType.DYNAMIC_INPUT_TEXT,
                        display: {
                            show: {
                                action: [S3ActionType.LIST_BUCKET_OBJECTS]
                            }
                        }
                    },
                    {
                        label: 'Prefix (optional)',
                        name: 'listFilesConfig.prefix',
                        startVersion: S3PluginVersions.V11,
                        componentType: index_js_1.FormComponentType.DYNAMIC_INPUT_TEXT,
                        display: {
                            show: {
                                action: [S3ActionType.LIST_BUCKET_OBJECTS]
                            }
                        },
                        tooltip: {
                            markdownText: 'Common prefix of keys to return. Use a value without a leading slash.'
                        }
                    },
                    {
                        label: 'Delimiter (optional)',
                        name: 'listFilesConfig.delimiter',
                        startVersion: S3PluginVersions.V11,
                        componentType: index_js_1.FormComponentType.DYNAMIC_INPUT_TEXT,
                        display: {
                            show: {
                                action: [S3ActionType.LIST_BUCKET_OBJECTS]
                            }
                        },
                        tooltip: {
                            markdownText: 'Keys containing this substring will be removed from the response and rolled up into the CommonPrefixes list. This will return keys in a hierarchical format, letting you navigate folders within your S3 bucket. '
                        }
                    },
                    {
                        label: 'File name',
                        name: 'path',
                        startVersion: S3PluginVersions.V1,
                        componentType: index_js_1.FormComponentType.DYNAMIC_INPUT_TEXT,
                        display: {
                            show: {
                                action: [
                                    S3ActionType.UPLOAD_OBJECT,
                                    S3ActionType.GET_OBJECT,
                                    S3ActionType.DELETE_OBJECT,
                                    S3ActionType.GENERATE_PRESIGNED_URL
                                ]
                            }
                        }
                    },
                    {
                        label: 'File content',
                        name: 'body',
                        startVersion: S3PluginVersions.V1,
                        componentType: index_js_1.FormComponentType.CODE_EDITOR,
                        language: index_js_1.EditorLanguage.TEXT,
                        display: {
                            show: {
                                action: [S3ActionType.UPLOAD_OBJECT]
                            }
                        }
                    },
                    {
                        name: 'responseType',
                        label: 'File content type',
                        startVersion: S3PluginVersions.V10,
                        componentType: index_js_1.FormComponentType.DROPDOWN,
                        initialValue: index_js_1.ActionResponseType.TEXT,
                        display: {
                            show: {
                                action: [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 objects array',
                        name: 'fileObjects',
                        startVersion: S3PluginVersions.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: [S3ActionType.UPLOAD_MULTIPLE_OBJECTS]
                            }
                        }
                    },
                    {
                        label: 'Presigned URL method',
                        name: 'custom.presignedMethod',
                        startVersion: S3PluginVersions.V1,
                        componentType: index_js_1.FormComponentType.DROPDOWN,
                        initialValue: 'PRESIGNED_METHOD_GET',
                        display: {
                            show: {
                                action: [S3ActionType.GENERATE_PRESIGNED_URL]
                            }
                        },
                        options: [
                            {
                                key: 'PRESIGNED_METHOD_GET',
                                value: 'PRESIGNED_METHOD_GET',
                                displayName: 'GET (download)'
                            },
                            {
                                key: 'PRESIGNED_METHOD_PUT',
                                value: 'PRESIGNED_METHOD_PUT',
                                displayName: 'PUT (upload)'
                            }
                        ]
                    },
                    {
                        label: 'Presigned URL expiration (seconds)',
                        name: 'custom.presignedExpiration.value',
                        startVersion: S3PluginVersions.V1,
                        componentType: index_js_1.FormComponentType.INPUT_TEXT,
                        initialValue: DEFAULT_S3_PRESIGNED_URL_EXPIRATION_SECONDS,
                        dataType: index_js_1.InputDataType.NUMBER,
                        display: {
                            show: {
                                action: [S3ActionType.GENERATE_PRESIGNED_URL]
                            }
                        }
                    }
                ]
            }
        ]
    }
};
//# sourceMappingURL=s3.js.map