UNPKG

alignai

Version:

Server-side Align AI SDK for Node.js

48 lines (47 loc) 1.83 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.validateCustomPropertiesOrThrow = exports.validateUserIdOrThrow = exports.validateSessionIdOrThrow = exports.ValidationError = void 0; const consts_1 = require("./consts"); class ValidationError extends Error { constructor(message) { super(message); this.name = 'ValidationError'; } } exports.ValidationError = ValidationError; function validateSessionIdOrThrow(sessionId) { if (!sessionId) { throw new ValidationError('sessionId is required'); } if (sessionId.length > 64) { throw new ValidationError('sessionId must be at most 64 characters'); } } exports.validateSessionIdOrThrow = validateSessionIdOrThrow; function validateUserIdOrThrow(userId) { if (!userId) { throw new ValidationError('userId is required'); } if (userId.length > 64) { throw new ValidationError('userId must be at most 64 characters'); } } exports.validateUserIdOrThrow = validateUserIdOrThrow; function validateCustomPropertiesOrThrow(customProperties) { const entries = Object.entries(customProperties); if (entries.length > 10) { throw new ValidationError('customProperties must have at most 10 keys'); } entries.forEach(([key, value]) => { if (!key) { throw new ValidationError('key of customProperty is required'); } if (!consts_1.customPropertyKeyRegex.test(key)) { throw new ValidationError(`key of customProperty must match ${consts_1.customPropertyKeyPattern}`); } if (value.length > 256) { throw new ValidationError('value of customProperty must be at most 256 characters'); } }); } exports.validateCustomPropertiesOrThrow = validateCustomPropertiesOrThrow;