UNPKG

n8n-nodes-base

Version:

Base nodes of n8n

524 lines 19.5 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.containerFields = exports.containerOperations = void 0; const n8n_workflow_1 = require("n8n-workflow"); const GenericFunctions_1 = require("../GenericFunctions"); exports.containerOperations = [ { displayName: 'Operation', name: 'operation', type: 'options', noDataExpression: true, displayOptions: { show: { resource: ['container'], }, }, options: [ { name: 'Create', value: 'create', description: 'Create a container', routing: { request: { ignoreHttpStatusErrors: true, method: 'PUT', qs: { restype: 'container', }, url: '=/{{ $parameter["containerCreate"] }}', headers: { [GenericFunctions_1.HeaderConstants.X_MS_DATE]: '={{ new Date().toUTCString() }}', [GenericFunctions_1.HeaderConstants.X_MS_VERSION]: GenericFunctions_1.XMsVersion, }, }, output: { postReceive: [ GenericFunctions_1.handleErrorPostReceive, async function (_data, response) { return [ { json: (0, GenericFunctions_1.parseHeaders)(response.headers), }, ]; }, ], }, }, action: 'Create container', }, { name: 'Delete', value: 'delete', description: 'Delete a container', routing: { request: { ignoreHttpStatusErrors: true, method: 'DELETE', qs: { restype: 'container', }, url: '=/{{ $parameter["container"] }}', headers: { [GenericFunctions_1.HeaderConstants.X_MS_DATE]: '={{ new Date().toUTCString() }}', [GenericFunctions_1.HeaderConstants.X_MS_VERSION]: GenericFunctions_1.XMsVersion, }, }, output: { postReceive: [ GenericFunctions_1.handleErrorPostReceive, async function (_data, response) { return [ { json: (0, GenericFunctions_1.parseHeaders)(response.headers), }, ]; }, ], }, }, action: 'Delete container', }, { name: 'Get', value: 'get', description: 'Retrieve data for a specific container', routing: { request: { ignoreHttpStatusErrors: true, method: 'GET', qs: { restype: 'container', }, url: '=/{{ $parameter["container"] }}', headers: { [GenericFunctions_1.HeaderConstants.X_MS_DATE]: '={{ new Date().toUTCString() }}', [GenericFunctions_1.HeaderConstants.X_MS_VERSION]: GenericFunctions_1.XMsVersion, }, }, output: { postReceive: [ GenericFunctions_1.handleErrorPostReceive, async function (_data, response) { const { metadata, ...properties } = (0, GenericFunctions_1.parseHeaders)(response.headers); const simplify = this.getNodeParameter('options.simplify', true); if (simplify) { delete properties.contentLength; delete properties.server; delete properties.requestId; delete properties.version; delete properties.date; delete properties.connection; } return [ { json: { name: this.getNodeParameter('container').value, properties, ...(metadata ? { metadata: metadata } : {}), }, }, ]; }, ], }, }, action: 'Get container', }, { name: 'Get Many', value: 'getAll', description: 'Retrieve a list of containers', routing: { request: { ignoreHttpStatusErrors: true, method: 'GET', qs: { comp: 'list', }, url: '/', headers: { [GenericFunctions_1.HeaderConstants.X_MS_DATE]: '={{ new Date().toUTCString() }}', [GenericFunctions_1.HeaderConstants.X_MS_VERSION]: GenericFunctions_1.XMsVersion, }, }, output: { postReceive: [ GenericFunctions_1.handleErrorPostReceive, async function (data, _response) { return [ { json: await (0, GenericFunctions_1.parseContainerList)(data[0].json), }, ]; }, ], }, }, action: 'Get many container', }, ], default: 'getAll', }, ]; const createFields = [ { displayName: 'Container Name', name: 'containerCreate', default: '', description: 'The name of the new container', displayOptions: { show: { resource: ['container'], operation: ['create'], }, }, placeholder: 'e.g. mycontainer', required: true, routing: { send: { preSend: [ async function (requestOptions) { const container = this.getNodeParameter('containerCreate'); if (container.length < 3 || container.length > 63) { throw new n8n_workflow_1.NodeOperationError(this.getNode(), "'Container Name' must be from 3 through 63 characters long"); } if (/[A-Z]/.test(container)) { throw new n8n_workflow_1.NodeOperationError(this.getNode(), "All letters in 'Container Name' must be lowercase"); } if (!/^[a-z0-9-]+$/.test(container)) { throw new n8n_workflow_1.NodeOperationError(this.getNode(), "'Container Name' can contain only letters, numbers, and the hyphen/minus (-) character"); } if (!/^[a-z0-9].*[a-z0-9]$/.test(container)) { throw new n8n_workflow_1.NodeOperationError(this.getNode(), "'Container Name' must start or end with a letter or number"); } if (/--/.test(container)) { throw new n8n_workflow_1.NodeOperationError(this.getNode(), "Consecutive hyphens are not permitted in 'Container Name'"); } return requestOptions; }, ], }, }, type: 'string', validateType: 'string', }, { displayName: 'Options', name: 'options', default: {}, displayOptions: { show: { resource: ['container'], operation: ['create'], }, }, options: [ { displayName: 'Access Level', name: 'accessLevel', default: '', options: [ { name: 'Blob', value: 'blob', description: "Specifies public read access for blobs. Blob data within this container can be read via anonymous request, but container data isn't available. Clients can't enumerate blobs within the container via anonymous request.", }, { name: 'Container', value: 'container', description: "Specifies full public read access for container and blob data. Clients can enumerate blobs within the container via anonymous request, but they can't enumerate containers within the storage account.", }, { name: 'Private', value: '', description: 'Container data is private to the account owner', }, ], routing: { request: { headers: { [GenericFunctions_1.HeaderConstants.X_MS_BLOB_PUBLIC_ACCESS]: '={{ $value || undefined }}', }, }, }, type: 'options', validateType: 'options', }, { displayName: 'Metadata', name: 'metadata', default: [], description: 'A name-value pair to associate with the container as metadata', options: [ { name: 'metadataValues', displayName: 'Metadata', values: [ { displayName: 'Field Name', name: 'fieldName', default: '', description: 'Names must adhere to the naming rules for <a href="https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/">C# identifiers</a>', type: 'string', }, { displayName: 'Field Value', name: 'fieldValue', default: '', type: 'string', }, ], }, ], placeholder: 'Add metadata', routing: { send: { preSend: [ async function (requestOptions) { requestOptions.headers ??= {}; const metadata = this.getNodeParameter('options.metadata'); for (const data of metadata.metadataValues) { requestOptions.headers[`${GenericFunctions_1.HeaderConstants.PREFIX_X_MS_META}${data.fieldName}`] = data.fieldValue; } return requestOptions; }, ], }, }, type: 'fixedCollection', typeOptions: { multipleValues: true, }, }, ], placeholder: 'Add option', type: 'collection', }, ]; const deleteFields = [ { displayName: 'Container', name: 'container', default: { mode: 'list', value: '', }, description: 'Select the container to delete', displayOptions: { show: { resource: ['container'], operation: ['delete'], }, }, modes: [ { displayName: 'From List', name: 'list', type: 'list', typeOptions: { searchListMethod: 'getContainers', searchable: true, }, }, { displayName: 'By Name', name: 'id', placeholder: 'e.g. mycontainer', type: 'string', }, ], required: true, type: 'resourceLocator', }, ]; const getFields = [ { displayName: 'Container', name: 'container', default: { mode: 'list', value: '', }, description: 'Select the container to get', displayOptions: { show: { resource: ['container'], operation: ['get'], }, }, modes: [ { displayName: 'From List', name: 'list', type: 'list', typeOptions: { searchListMethod: 'getContainers', searchable: true, }, }, { displayName: 'By Name', name: 'id', placeholder: 'e.g. mycontainer', type: 'string', }, ], required: true, type: 'resourceLocator', }, { displayName: 'Options', name: 'options', default: {}, displayOptions: { show: { resource: ['container'], operation: ['get'], }, }, options: [ { displayName: 'Simplify', name: 'simplify', type: 'boolean', default: true, description: 'Whether to return a simplified version of the response instead of the raw data', }, ], placeholder: 'Add option', type: 'collection', }, ]; const getAllFields = [ { displayName: 'Return All', name: 'returnAll', default: false, description: 'Whether to return all results or only up to a given limit', displayOptions: { show: { resource: ['container'], operation: ['getAll'], }, }, routing: { send: { paginate: '={{ $value }}', }, operations: { async pagination(requestOptions) { let executions = []; let marker = undefined; requestOptions.options.qs ??= {}; do { requestOptions.options.qs.marker = marker; const responseData = await this.makeRoutingRequest(requestOptions); marker = responseData[0].json.nextMarker; executions = executions.concat(responseData[0].json.containers.map((item) => ({ json: item }))); } while (marker); return executions; }, }, }, type: 'boolean', }, { displayName: 'Limit', name: 'limit', default: 50, description: 'Max number of results to return', displayOptions: { show: { resource: ['container'], operation: ['getAll'], returnAll: [false], }, }, routing: { send: { property: 'maxresults', type: 'query', value: '={{ $value }}', }, output: { postReceive: [ async function (data, _response) { return data[0].json.containers.map((item) => ({ json: item })); }, ], }, }, type: 'number', typeOptions: { minValue: 1, }, validateType: 'number', }, { displayName: 'Options', name: 'options', default: {}, displayOptions: { show: { resource: ['container'], operation: ['getAll'], }, }, options: [ { displayName: 'Fields', name: 'fields', default: [], description: 'The fields to add to the output', options: [ { name: 'Metadata', value: 'metadata', }, { name: 'Deleted', value: 'deleted', }, { name: 'System', value: 'system', }, ], routing: { send: { property: 'include', type: 'query', value: '={{ $value.join(",") || undefined }}', }, }, type: 'multiOptions', }, { displayName: 'Filter', name: 'filter', default: '', description: 'Filters the results to return only containers with a name that begins with the specified prefix', placeholder: 'e.g. mycontainer', routing: { send: { property: 'prefix', type: 'query', value: '={{ $value ? $value : undefined }}', }, }, type: 'string', validateType: 'string', }, ], placeholder: 'Add option', type: 'collection', }, ]; exports.containerFields = [ ...createFields, ...deleteFields, ...getFields, ...getAllFields, ]; //# sourceMappingURL=ContainerDescription.js.map