From 3a0e3c466a99475a8c2e388b9573e628cd298280 Mon Sep 17 00:00:00 2001 From: "Mamadou Khoussa [028918 DSI/DAC/DIF/DS]" Date: Fri, 24 Oct 2025 22:43:46 +0000 Subject: [PATCH] fix it --- .../adaptor/dtos/orange.challenge.dto.ts | 146 ++++++++++++++++++ .../challenge/adaptor/orange.adaptor.ts | 12 +- 2 files changed, 153 insertions(+), 5 deletions(-) create mode 100644 src/modules/challenge/adaptor/dtos/orange.challenge.dto.ts diff --git a/src/modules/challenge/adaptor/dtos/orange.challenge.dto.ts b/src/modules/challenge/adaptor/dtos/orange.challenge.dto.ts new file mode 100644 index 0000000..7467165 --- /dev/null +++ b/src/modules/challenge/adaptor/dtos/orange.challenge.dto.ts @@ -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 = {}; + + /** + * 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; + } +} \ No newline at end of file diff --git a/src/modules/challenge/adaptor/orange.adaptor.ts b/src/modules/challenge/adaptor/orange.adaptor.ts index 837747c..e7b175c 100644 --- a/src/modules/challenge/adaptor/orange.adaptor.ts +++ b/src/modules/challenge/adaptor/orange.adaptor.ts @@ -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}`); }