This commit is contained in:
Mamadou Khoussa [028918 DSI/DAC/DIF/DS] 2025-10-24 22:43:46 +00:00
parent f87650dcc2
commit 3a0e3c466a
2 changed files with 153 additions and 5 deletions

View File

@ -0,0 +1,146 @@
/**
* Structure de la requête pour l'API Orange DCB Challenge v2
*/
export interface OrangeChallengeRequest {
country: string;
method: string;
service: string;
partnerId: string;
identifier: {
type: string;
value: string;
};
confirmationCode: string;
message: string;
otpLength: number;
senderName: string;
}
/**
* Structure de la réponse de l'API Orange DCB Challenge
*/
export interface OrangeChallengeResponse {
challengeId?: string;
message?: string;
expiresIn?: number;
sessionId?: string;
error?: {
code: number | string;
message: string;
description?: string;
};
}
/**
* Builder pour construire des requêtes Orange Challenge
*/
export class OrangeChallengeRequestBuilder {
private request: Partial<OrangeChallengeRequest> = {};
/**
* Définir le pays
*/
withCountry(country: string): this {
this.request.country = country;
return this;
}
/**
* Définir la méthode d'authentification
*/
withMethod(method: string): this {
this.request.method = method;
return this;
}
/**
* Définir le service
*/
withService(service: string): this {
this.request.service = service;
return this;
}
/**
* Définir l'ID du partenaire
*/
withPartnerId(partnerId: string): this {
this.request.partnerId = partnerId;
return this;
}
/**
* Définir l'identifiant (numéro de téléphone, etc.)
*/
withIdentifier(type: string, value: string): this {
this.request.identifier = {
type,
value
};
return this;
}
/**
* Définir le code de confirmation (OTP)
*/
withConfirmationCode(code: string): this {
this.request.confirmationCode = code;
return this;
}
/**
* Définir le message OTP
*/
withMessage(message: string): this {
this.request.message = message;
return this;
}
/**
* Définir la longueur de l'OTP
*/
withOtpLength(length: number): this {
this.request.otpLength = length;
return this;
}
/**
* Définir le nom de l'expéditeur
*/
withSenderName(senderName: string): this {
this.request.senderName = senderName;
return this;
}
/**
* Construire la requête finale
*/
build(): OrangeChallengeRequest {
// Validation des champs obligatoires
if (!this.request.country) {
throw new Error('Country is required');
}
if (!this.request.method) {
throw new Error('Method is required');
}
if (!this.request.service) {
throw new Error('Service is required');
}
if (!this.request.partnerId) {
throw new Error('Partner ID is required');
}
if (!this.request.identifier) {
throw new Error('Identifier is required');
}
return this.request as OrangeChallengeRequest;
}
/**
* Réinitialiser le builder
*/
reset(): this {
this.request = {};
return this;
}
}

View File

@ -3,15 +3,17 @@ import {
OrangeChallengeRequest,
OrangeChallengeResponse,
OrangeChallengeRequestBuilder
} from './dtos/orange-challenge.dto';
} from './dtos/orange.challenge.dto'
import {
OrangeConfig,
DEFAULT_ORANGE_CONFIG,
COUNTRY_CODE_MAPPING,
OTP_METHOD_MAPPING
} from './config/orange.config';
import { OtpChallengeRequestDto } from '../../dtos/otp-challenge-request.dto';
import { OtpChallengeResponseDto, OtpChallengeStatusEnum } from '../../dtos/otp-challenge-response.dto';
} from './orange.config';
//import { OtpChallengeResponseDto, OtpChallengeStatusEnum } from '../../dtos/otp-challenge-response.dto';
import { OtpChallengeRequestDto } from '../dto/challenge.request.dto';
import { OtpChallengeResponseDto, OtpChallengeStatusEnum } from '../dto/challenge.response.dto';
/**
* Adaptateur pour l'API Orange DCB v2
@ -72,7 +74,7 @@ export class OrangeAdapter {
const expiresIn = response.data.expires_in || 3600;
this.tokenExpiresAt = Date.now() + (expiresIn * 1000);
return this.accessToken;
return this.accessToken as string;
} catch (error) {
throw new Error(`Failed to obtain Orange access token: ${error.message}`);
}