n8n
Version:
n8n Workflow Automation Tool
72 lines • 2.91 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.integrationError = integrationError;
exports.connectionUnavailable = connectionUnavailable;
exports.unsupportedQuery = unsupportedQuery;
exports.unsupportedAction = unsupportedAction;
exports.normalizePlatformId = normalizePlatformId;
exports.isRecord = isRecord;
exports.stringValue = stringValue;
exports.stringProperty = stringProperty;
exports.numberProperty = numberProperty;
exports.booleanProperty = booleanProperty;
exports.isoDateProperty = isoDateProperty;
exports.removeUndefinedValues = removeUndefinedValues;
exports.isDefined = isDefined;
const integration_error_codes_1 = require("./integration-error-codes");
function integrationError(code, message) {
return { ok: false, error: { code, message } };
}
function connectionUnavailable() {
return integrationError(integration_error_codes_1.INTEGRATION_ERROR_CODES.CONNECTION_NOT_AVAILABLE, 'The integration connection is not currently available.');
}
function unsupportedQuery(platform, query) {
return integrationError(integration_error_codes_1.INTEGRATION_ERROR_CODES.UNSUPPORTED_QUERY, `The active ${platform} connection does not support ${query}.`);
}
function unsupportedAction(platform, action) {
return integrationError(integration_error_codes_1.INTEGRATION_ERROR_CODES.UNSUPPORTED_ACTION, `The active ${platform} connection does not support ${action}.`);
}
function normalizePlatformId(platform, id) {
return id.includes(':') ? id : `${platform}:${id}`;
}
function isRecord(value) {
return typeof value === 'object' && value !== null && !Array.isArray(value);
}
function stringValue(value) {
return typeof value === 'string' && value.length > 0 ? value : undefined;
}
function stringProperty(value, key) {
if (!isRecord(value))
return undefined;
return stringValue(value[key]);
}
function numberProperty(value, key) {
if (!isRecord(value))
return undefined;
const property = value[key];
return typeof property === 'number' ? property : undefined;
}
function booleanProperty(value, key) {
if (!isRecord(value))
return undefined;
const property = value[key];
return typeof property === 'boolean' ? property : undefined;
}
function isoDateProperty(value, key) {
if (!isRecord(value))
return undefined;
const property = value[key];
if (property instanceof Date)
return property.toISOString();
if (typeof property !== 'string' || property.length === 0)
return undefined;
const date = new Date(property);
return Number.isNaN(date.getTime()) ? undefined : date.toISOString();
}
function removeUndefinedValues(value) {
return Object.fromEntries(Object.entries(value).filter(([, entry]) => entry !== undefined));
}
function isDefined(value) {
return value !== undefined;
}
//# sourceMappingURL=integration-helpers.js.map