UNPKG

@unito/integration-debugger

Version:

The Unito Integration Debugger

115 lines (114 loc) 6 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const integration_api_1 = require("@unito/integration-api"); const crawler_1 = require("../crawler"); /** * Check: Validate classic attachments * * We validate that any relation with the semantic "attachment" is compliant to the classic attachments schema. * * A classic attachment must have: * - a field of type name with the semantic "displayName" * - a field of type file of type "blob" * - TODO: Complete with other fields */ const check = { label: 'Classic Attachments', prepareOnPreparedSteps: false, validateOnError: false, activatedByDefault: true, prepare: async (_stepResult, _crawlerDriver) => { return []; }, validate: (step, _crawlerDriver) => { if (step.operation !== crawler_1.Operation.GetItem || !step.payloadOut) { return; } const payload = step.payloadOut; const attachmentRelations = payload.relations?.filter(relation => relation.semantic === integration_api_1.RelationSemantics.ATTACHMENTS); if (!attachmentRelations.length) { return; } for (const attachmentRelation of attachmentRelations) { const nameField = attachmentRelation.schema.fields.find(field => field.name === 'name'); if (!nameField || nameField.semantic !== integration_api_1.Semantics.DISPLAY_NAME) { step.errors.push({ keyword: 'unito', message: `The relation is missing a field.`, detailedMessage: `The relation with semantic '${integration_api_1.RelationSemantics.ATTACHMENTS}' must have a field \`name\` with the semantic '${integration_api_1.Semantics.DISPLAY_NAME}'.`, instancePath: step.path, schemaPath: step.schemaPath ?? '', params: { code: 'DISPLAY_NAME_NOT_FOUND', }, }); } const fileField = attachmentRelation.schema.fields.find(field => field.name === 'file'); if (!fileField || fileField.type !== integration_api_1.FieldValueTypes.BLOB) { step.warnings.push({ keyword: 'unito', message: `The relation is missing a field.`, detailedMessage: `The relation with semantic '${integration_api_1.RelationSemantics.ATTACHMENTS}' should have a field \`file\` with the type '${integration_api_1.FieldValueTypes.BLOB}' to enable binary copy.`, instancePath: step.path, schemaPath: step.schemaPath ?? '', params: { code: 'BLOB_NOT_FOUND', }, }); } const idField = attachmentRelation.schema.fields.find(field => field.name === 'id'); if (!idField || idField.type !== integration_api_1.FieldValueTypes.STRING) { step.errors.push({ keyword: 'unito', message: `The relation is missing a field.`, detailedMessage: `The relation with semantic '${integration_api_1.RelationSemantics.ATTACHMENTS}' must have a field \`id\` of type '${integration_api_1.FieldValueTypes.STRING}'.`, instancePath: step.path, schemaPath: step.schemaPath ?? '', params: { code: 'MANDATORY_FIELD_NOT_FOUND', }, }); } const urlField = attachmentRelation.schema.fields.find(field => field.name === 'url'); if (!urlField || urlField.type !== integration_api_1.FieldValueTypes.URL) { step.errors.push({ keyword: 'unito', message: `The relation is missing a field.`, detailedMessage: `The relation with semantic '${integration_api_1.RelationSemantics.ATTACHMENTS}' must have a field \`url\` of type '${integration_api_1.FieldValueTypes.URL}'.`, instancePath: step.path, schemaPath: step.schemaPath ?? '', params: { code: 'MANDATORY_FIELD_NOT_FOUND', }, }); } const sizeInBytesField = attachmentRelation.schema.fields.find(field => field.name === 'sizeInBytes'); if (!sizeInBytesField || sizeInBytesField.type !== integration_api_1.FieldValueTypes.NUMBER) { step.errors.push({ keyword: 'unito', message: `The relation is missing a field.`, detailedMessage: `The relation with semantic '${integration_api_1.RelationSemantics.ATTACHMENTS}' must have a field \`sizeInByte\` of type '${integration_api_1.FieldValueTypes.NUMBER}'.`, instancePath: step.path, schemaPath: step.schemaPath ?? '', params: { code: 'MANDATORY_FIELD_NOT_FOUND', }, }); } const mimeTypeField = attachmentRelation.schema.fields.find(field => field.name === 'mimeType'); if (!mimeTypeField || mimeTypeField.type !== integration_api_1.FieldValueTypes.STRING) { step.errors.push({ keyword: 'unito', message: `The relation is missing a field.`, detailedMessage: `The relation with semantic '${integration_api_1.RelationSemantics.ATTACHMENTS}' must have a field \`mimeType\` of type '${integration_api_1.FieldValueTypes.STRING}'.`, instancePath: step.path, schemaPath: step.schemaPath ?? '', params: { code: 'MANDATORY_FIELD_NOT_FOUND', }, }); } } }, }; exports.default = check;