diff --git a/__tests__/non-esm-import/package.json b/__tests__/non-esm-import/package.json new file mode 100644 index 0000000..044f287 --- /dev/null +++ b/__tests__/non-esm-import/package.json @@ -0,0 +1,10 @@ +{ + "name": "non-esm-import", + "version": "1.0.0", + "description": "", + "scripts": { + "test": "echo \"Error: no test specified\" && exit 1" + }, + "author": "", + "license": "ISC" +} diff --git a/__tests__/non-esm-import/test.js b/__tests__/non-esm-import/test.js new file mode 100644 index 0000000..831a7e4 --- /dev/null +++ b/__tests__/non-esm-import/test.js @@ -0,0 +1,4 @@ +(async () => { + const {RadiusServer} = await import('../../dist/index.js'); + console.log('RADIUSServer', RadiusServer); +})(); diff --git a/src/auth.ts b/src/auth.ts index 03d084e..7275563 100644 --- a/src/auth.ts +++ b/src/auth.ts @@ -1,7 +1,7 @@ import NodeCache from 'node-cache'; import { Cache, ExpirationStrategy, MemoryStorage } from '@hokify/node-ts-cache'; -import { IAuthentication } from './interfaces/Authentication'; -import { ILogger } from './interfaces/Logger'; +import { IAuthentication } from './interfaces/Authentication.js'; +import { ILogger } from './interfaces/Logger.js'; const cacheStrategy = new ExpirationStrategy(new MemoryStorage()); /** diff --git a/src/auth/GoogleLDAPAuth.ts b/src/auth/GoogleLDAPAuth.ts index 0c0d3c8..87c67ac 100644 --- a/src/auth/GoogleLDAPAuth.ts +++ b/src/auth/GoogleLDAPAuth.ts @@ -1,8 +1,8 @@ import ldapjs, { ClientOptions } from 'ldapjs'; import * as tls from 'tls'; import * as fs from 'fs'; -import { IAuthentication } from '../interfaces/Authentication'; -import { ILogger } from '../interfaces/Logger'; +import { IAuthentication } from '../interfaces/Authentication.js'; +import { ILogger } from '../interfaces/Logger.js'; const usernameFields = ['posixUid', 'mail']; diff --git a/src/auth/HTTPAuth.ts b/src/auth/HTTPAuth.ts index 8e6e279..0ae04cd 100644 --- a/src/auth/HTTPAuth.ts +++ b/src/auth/HTTPAuth.ts @@ -1,6 +1,6 @@ import fetch from 'node-fetch'; -import { IAuthentication } from '../interfaces/Authentication'; -import { ILogger } from '../interfaces/Logger'; +import { IAuthentication } from '../interfaces/Authentication.js'; +import { ILogger } from '../interfaces/Logger.js'; interface IHTTPAuthOptions { url: string; diff --git a/src/auth/IMAPAuth.ts b/src/auth/IMAPAuth.ts index e685485..a63b3d7 100644 --- a/src/auth/IMAPAuth.ts +++ b/src/auth/IMAPAuth.ts @@ -1,6 +1,6 @@ import * as imaps from 'imap-simple'; -import { IAuthentication } from '../interfaces/Authentication'; -import { ILogger } from '../interfaces/Logger'; +import { IAuthentication } from '../interfaces/Authentication.js'; +import { ILogger } from '../interfaces/Logger.js'; interface IIMAPAuthOptions { host: string; diff --git a/src/auth/LDAPAuth.ts b/src/auth/LDAPAuth.ts index c714456..e80c71d 100644 --- a/src/auth/LDAPAuth.ts +++ b/src/auth/LDAPAuth.ts @@ -1,7 +1,7 @@ import * as LdapAuth from 'ldapauth-fork'; import * as fs from 'fs'; -import { IAuthentication } from '../interfaces/Authentication'; -import { ILogger } from '../interfaces/Logger'; +import { IAuthentication } from '../interfaces/Authentication.js'; +import { ILogger } from '../interfaces/Logger.js'; interface ILDAPAuthOptions { /** ldap url diff --git a/src/auth/SMTPAuth.ts b/src/auth/SMTPAuth.ts index 0559324..2faf2ab 100644 --- a/src/auth/SMTPAuth.ts +++ b/src/auth/SMTPAuth.ts @@ -1,6 +1,6 @@ import { SMTPClient } from 'smtp-client'; -import { IAuthentication } from '../interfaces/Authentication'; -import { ILogger } from '../interfaces/Logger'; +import { IAuthentication } from '../interfaces/Authentication.js'; +import { ILogger } from '../interfaces/Logger.js'; interface ISMTPAuthOptions { host: string; diff --git a/src/auth/StaticAuth.ts b/src/auth/StaticAuth.ts index ab91dc6..16dc778 100644 --- a/src/auth/StaticAuth.ts +++ b/src/auth/StaticAuth.ts @@ -1,5 +1,5 @@ -import { IAuthentication } from '../interfaces/Authentication'; -import { ILogger } from '../interfaces/Logger'; +import { IAuthentication } from '../interfaces/Authentication.js'; +import { ILogger } from '../interfaces/Logger.js'; interface IStaticAuthOtions { validCredentials: { diff --git a/src/index.ts b/src/index.ts index 50c110d..dfdd1e5 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,6 +1,6 @@ -import { IAuthentication } from './interfaces/Authentication'; -import { RadiusServerOptions } from './interfaces/RadiusServerOptions'; -import { RadiusServer } from './radius/RadiusServer'; +import { IAuthentication } from './interfaces/Authentication.js'; +import { RadiusServerOptions } from './interfaces/RadiusServerOptions.js'; +import { RadiusServer } from './radius/RadiusServer.js'; export { IAuthentication as RadiusAuthentication, RadiusServerOptions, RadiusServer }; diff --git a/src/interfaces/EAPMethod.ts b/src/interfaces/EAPMethod.ts index 8c5d3b2..b8a06d5 100644 --- a/src/interfaces/EAPMethod.ts +++ b/src/interfaces/EAPMethod.ts @@ -1,4 +1,22 @@ -import { IPacket, IPacketHandlerResult } from './PacketHandler'; +import { IPacket, IPacketHandlerResult } from './PacketHandler.js'; + +export enum EAPRequestType { + REQUEST = 1, + RESPONSE = 2, + SUCCESS = 3, + FAILURE = 4, +} + +export enum EAPMessageType { + IDENTIFY = 1, + NOTIFICATION = 2, + NAK = 3, + MD5 = 4, + GTC = 6, + TTLS = 21, + PEAP = 25, + EXPANDED = 254, +} export interface IEAPMethod { getEAPType(): number; diff --git a/src/interfaces/RadiusServerOptions.ts b/src/interfaces/RadiusServerOptions.ts index 900b578..51db0b2 100644 --- a/src/interfaces/RadiusServerOptions.ts +++ b/src/interfaces/RadiusServerOptions.ts @@ -1,7 +1,7 @@ import { SecureContextOptions } from 'tls'; -import { IAuthentication } from './Authentication'; -import { ILogger } from './Logger'; -import { LogLevel } from '../logger/ConsoleLogger'; +import { IAuthentication } from './Authentication.js'; +import { ILogger } from './Logger.js'; +import { LogLevel } from '../logger/ConsoleLogger.js'; export type RadiusServerOptions = IRadiusServerOptions & ( diff --git a/src/logger/ConsoleLogger.ts b/src/logger/ConsoleLogger.ts index 3f1319c..69f4a09 100644 --- a/src/logger/ConsoleLogger.ts +++ b/src/logger/ConsoleLogger.ts @@ -1,4 +1,4 @@ -import { ILogger } from '../interfaces/Logger'; +import { ILogger } from '../interfaces/Logger.js'; export enum LogLevel { Verbose = 'verbose', diff --git a/src/radius/handler/eap/EAPHelper.ts b/src/radius/handler/eap/EAPHelper.ts index cacb552..dedddf9 100644 --- a/src/radius/handler/eap/EAPHelper.ts +++ b/src/radius/handler/eap/EAPHelper.ts @@ -1,6 +1,7 @@ import { IPacketHandlerResult, PacketResponseCode } from '../../../interfaces/PacketHandler.js'; +import { EAPMessageType } from '../../../interfaces/EAPMethod.js'; -export function buildEAP(identifier: number, msgType: number, data?: Buffer) { +export function buildEAP(identifier: number, msgType: EAPMessageType, data?: Buffer) { /** build a package according to this: 0 1 2 3 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 diff --git a/src/radius/handler/eap/eapMethods/EAP-TTLS.ts b/src/radius/handler/eap/eapMethods/EAP-TTLS.ts index 8fd34f3..5ac828d 100644 --- a/src/radius/handler/eap/eapMethods/EAP-TTLS.ts +++ b/src/radius/handler/eap/eapMethods/EAP-TTLS.ts @@ -15,7 +15,7 @@ import { PacketResponseCode, } from '../../../../interfaces/PacketHandler.js'; import { MAX_RADIUS_ATTRIBUTE_SIZE, newDeferredPromise } from '../../../../helpers.js'; -import { IEAPMethod } from '../../../../interfaces/EAPMethod.js'; +import { EAPMessageType, IEAPMethod } from '../../../../interfaces/EAPMethod.js'; import { IAuthentication } from '../../../../interfaces/Authentication.js'; import { ILogger } from '../../../../interfaces/Logger.js'; @@ -46,7 +46,7 @@ export class EAPTTLS implements IEAPMethod { private openTLSSockets = new NodeCache({ useClones: false, stdTTL: 3600 }); // keep sockets for about one hour getEAPType(): number { - return 21; + return EAPMessageType.TTLS; } identify(identifier: number, stateID: string): IPacketHandlerResult { @@ -79,7 +79,7 @@ export class EAPTTLS implements IEAPMethod { private buildEAPTTLS( identifier: number, - msgType = 21, + msgType = EAPMessageType.TTLS, msgFlags = 0x00, stateID: string, data?: Buffer, @@ -163,7 +163,7 @@ export class EAPTTLS implements IEAPMethod { private buildEAPTTLSResponse( identifier: number, - msgType = 21, + msgType = EAPMessageType.TTLS, msgFlags = 0x00, stateID: string, data?: Buffer,