UNPKG

@citrineos/util

Version:

The OCPP util module which supplies helpful utilities like cache and queue connectors, etc.

111 lines (110 loc) 5.17 kB
import { OCPP2_0_1 } from '@citrineos/base'; import type { IChargingProfileRepository, IDeviceModelRepository, ITransactionEventRepository } from '@citrineos/data'; import type { ILogObj } from 'tslog'; import { Logger } from 'tslog'; /** * Validate a language tag is an RFC-5646 tag, see: {@link https://tools.ietf.org/html/rfc5646}, * example: US English is: "en-US" * * @param languageTag * @returns {boolean} true if the languageTag is an RFC-5646 tag */ export declare function validateLanguageTag(languageTag: string): boolean; /** * Validate constraints of ChargingProfileType defined in OCPP 2.0.1 * * @param chargingProfileType ChargingProfileType from the request * @param tenantId tenant id the profile belongs to * @param stationId station id * @param deviceModelRepository deviceModelRepository * @param chargingProfileRepository chargingProfileRepository * @param transactionEventRepository transactionEventRepository * @param logger logger * @param evseId evse id */ export declare function validateChargingProfileType(chargingProfileType: OCPP2_0_1.ChargingProfileType, tenantId: number, stationId: string, deviceModelRepository: IDeviceModelRepository, chargingProfileRepository: IChargingProfileRepository, transactionEventRepository: ITransactionEventRepository, logger: Logger<ILogObj>, evseId?: number | null): Promise<void>; /** * Validate ISO15693 ID token format * ISO 15693 UID should be exactly 8 bytes (16 hex characters) */ export declare function validateISO15693IdToken(idToken: string): boolean; /** * Validate ISO14443 ID token format * ISO 14443 UID should be 4 or 7 bytes (8 or 14 hex characters) */ export declare function validateISO14443IdToken(idToken: string): boolean; /** * Validate identifier string format per OCPP 2.0.1. We expect this validation already from the JSON schema, * but we add this extra validation to be sure. * Only allows: a-z, A-Z, 0-9, *, -, _, =, :, +, |, @, . */ export declare function validateIdentifierStringIdToken(idToken: string): boolean; /** * Validates an eMAID string according to eMI³ specifications * @param emaid - The eMAID string to validate * @returns errors - String array with errors, empty if valid */ export declare function validateEMAIDIdToken(emaid: string): string[]; /** * Validate NoAuthorization ID token (should be empty) */ export declare function validateNoAuthorizationIdToken(idToken: string): boolean; /** * Generic validation result for all validators */ export interface ValidationResult { isValid: boolean; errorMessage?: string; } /** * ID token validator - routes to appropriate validator based on type * Returns validation result with detailed error message if invalid */ export declare function validateIdToken(idTokenType: OCPP2_0_1.IdTokenEnumType, idToken: string): ValidationResult; /** * Validate ASCII content - only printable ASCII allowed (characters 32-126) * @param content Content string to validate * @returns {boolean} true if content contains only printable ASCII characters */ export declare function validateASCIIContent(content: string): boolean; /** * Validate HTML content - checks for basic HTML structure validity * @param content Content string to validate * @returns {boolean} true if content appears to be valid HTML */ export declare function validateHTMLContent(content: string): boolean; /** * Validate URI content - checks if content is a valid URI * @param content Content string to validate * @returns {boolean} true if content is a valid URI */ export declare function validateURIContent(content: string): boolean; /** * Validate UTF-8 content - in JavaScript, strings are already UTF-16 encoded * This function checks for invalid surrogate pairs and control characters * @param content Content string to validate * @returns {boolean} true if content is valid UTF-8 */ export declare function validateUTF8Content(content: string): boolean; /** * Message content validator - routes to appropriate validator based on format * Returns validation result with detailed error message if invalid * @param format Message format type (ASCII, HTML, URI, UTF8) * @param content Message content to validate * @returns {ValidationResult} Validation result with error message if invalid */ export declare function validateMessageContent(format: OCPP2_0_1.MessageFormatEnumType, content: string): ValidationResult; /** * Validate a complete MessageContentType object * Convenience function that validates both language tag (if present) and content against format * @param messageContent MessageContentType object to validate * @returns {ValidationResult} Validation result with error message if invalid */ export declare function validateMessageContentType(messageContent: OCPP2_0_1.MessageContentType): ValidationResult; /** * Validate PEM-encoded Certificate Signing Request (CSR) * According to RFC 2986, CSR must be PEM-encoded with proper headers and valid base64 content * @param csr CSR string to validate * @returns {ValidationResult} Validation result with error message if invalid */ export declare function validatePEMEncodedCSR(csr: string): ValidationResult;