sunuid-sdk 1.0.36 → 1.0.38

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -2114,6 +2114,8 @@ function _unsupportedIterableToArray(r, a) {
2114
2114
  key: "sanitizeRequestData",
2115
2115
  value: function sanitizeRequestData(data) {
2116
2116
  var sanitized = {};
2117
+
2118
+ // D'abord, copier tous les champs de data
2117
2119
  for (var _i = 0, _Object$entries = Object.entries(data); _i < _Object$entries.length; _i++) {
2118
2120
  var _Object$entries$_i = _slicedToArray(_Object$entries[_i], 2),
2119
2121
  key = _Object$entries$_i[0],
@@ -2127,19 +2129,12 @@ function _unsupportedIterableToArray(r, a) {
2127
2129
  }
2128
2130
  }
2129
2131
 
2130
- // Ajouter les credentials dans le body (API SunuID les attend ici)
2132
+ // Ensuite, ajouter/écraser les credentials (API SunuID les attend ici)
2131
2133
  // Utiliser les vraies valeurs (originales) si disponibles, sinon les valeurs directes
2132
2134
  sanitized.client_id = this.config.originalClientId || this.config.clientId;
2133
2135
  sanitized.secret_id = this.config.originalSecretId || this.config.secretId;
2134
2136
 
2135
- // Debug: Vérifier les credentials
2136
- console.log('🔍 Credentials dans sanitizeRequestData - clientId:', this.config.clientId);
2137
- console.log('🔍 Credentials dans sanitizeRequestData - secretId:', this.config.secretId ? '***' + this.config.secretId.slice(-4) : 'null');
2138
- console.log('🔍 Credentials dans sanitizeRequestData - sanitizedClientId:', sanitized.client_id);
2139
- console.log('🔍 Credentials dans sanitizeRequestData - sanitizedSecretId:', sanitized.secret_id ? '***' + sanitized.secret_id.slice(-4) : 'null');
2140
- console.log('🔍 Credentials dans sanitizeRequestData - data complet:', JSON.stringify(sanitized, null, 2));
2141
-
2142
- // Debug: Vérifier les credentials
2137
+ // Debug: Vérifier les credentials et les données
2143
2138
  console.log('🔍 Credentials dans sanitizeRequestData - clientId:', this.config.clientId);
2144
2139
  console.log('🔍 Credentials dans sanitizeRequestData - secretId:', this.config.secretId ? '***' + this.config.secretId.slice(-4) : 'null');
2145
2140
  console.log('🔍 Credentials dans sanitizeRequestData - sanitizedClientId:', sanitized.client_id);
@@ -2176,7 +2171,7 @@ function _unsupportedIterableToArray(r, a) {
2176
2171
  key: "fetchPartnerInfo",
2177
2172
  value: (function () {
2178
2173
  var _fetchPartnerInfo = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee17() {
2179
- var response, authTest, _t12;
2174
+ var response, data, partnerId, _t12;
2180
2175
  return _regenerator().w(function (_context18) {
2181
2176
  while (1) switch (_context18.p = _context18.n) {
2182
2177
  case 0:
@@ -2190,32 +2185,46 @@ function _unsupportedIterableToArray(r, a) {
2190
2185
  case 1:
2191
2186
  response = _context18.v;
2192
2187
  console.log('📋 Réponse debug API:', response);
2193
- if (response.success && response.authentication && response.authentication.auth_test) {
2194
- authTest = response.authentication.auth_test;
2195
- this.config.partnerId = authTest.partner_id;
2196
2188
 
2197
- // Récupérer le service_id depuis la réponse
2198
- if (response.service_id) {
2199
- this.config.serviceId = response.service_id;
2200
- } else {
2201
- // Fallback: utiliser le partner_id comme service_id
2202
- this.config.serviceId = authTest.partner_id;
2189
+ // Vérifier la structure de la réponse
2190
+ if (response.success && response.data) {
2191
+ data = response.data; // Essayer de récupérer le partner_id depuis différentes structures possibles
2192
+ partnerId = null;
2193
+ if (data.partner_id) {
2194
+ partnerId = data.partner_id;
2195
+ } else if (data.authentication && data.authentication.auth_test && data.authentication.auth_test.partner_id) {
2196
+ partnerId = data.authentication.auth_test.partner_id;
2197
+ } else if (data.auth_test && data.auth_test.partner_id) {
2198
+ partnerId = data.auth_test.partner_id;
2203
2199
  }
2200
+ if (partnerId) {
2201
+ this.config.partnerId = partnerId;
2202
+
2203
+ // Récupérer le service_id depuis la réponse
2204
+ if (data.service_id) {
2205
+ this.config.serviceId = data.service_id;
2206
+ } else {
2207
+ // Fallback: utiliser le partner_id comme service_id
2208
+ this.config.serviceId = partnerId;
2209
+ }
2204
2210
 
2205
- // Utiliser le partner_id pour déterminer le nom du partenaire
2206
- // Pour l'instant, on utilise une logique simple basée sur l'ID
2207
- if (authTest.partner_id === 21) {
2208
- this.config.partnerName = 'Fayma';
2211
+ // Utiliser le partner_id pour déterminer le nom du partenaire
2212
+ if (partnerId === 21) {
2213
+ this.config.partnerName = 'Fayma';
2214
+ } else {
2215
+ this.config.partnerName = "Partner_".concat(partnerId);
2216
+ }
2217
+ console.log('✅ Informations partenaire récupérées:', {
2218
+ partnerName: this.config.partnerName,
2219
+ partnerId: this.config.partnerId,
2220
+ serviceId: this.config.serviceId
2221
+ });
2209
2222
  } else {
2210
- this.config.partnerName = "Partner_".concat(authTest.partner_id);
2223
+ console.warn('⚠️ Partner ID non trouvé dans la réponse, utilisation du partner_id par défaut');
2224
+ this.config.partnerName = "Partner_".concat(this.config.partnerId || 'unknown');
2211
2225
  }
2212
- console.log('✅ Informations partenaire récupérées:', {
2213
- partnerName: this.config.partnerName,
2214
- partnerId: this.config.partnerId,
2215
- serviceId: this.config.serviceId
2216
- });
2217
2226
  } else {
2218
- console.warn('⚠️ Impossible de récupérer les informations du partenaire, utilisation du partner_id');
2227
+ console.warn('⚠️ Structure de réponse invalide, utilisation du partner_id par défaut');
2219
2228
  this.config.partnerName = "Partner_".concat(this.config.partnerId || 'unknown');
2220
2229
  }
2221
2230
  _context18.n = 3;
@@ -2275,12 +2284,19 @@ function _unsupportedIterableToArray(r, a) {
2275
2284
  api: false,
2276
2285
  websocket: false,
2277
2286
  ready: false
2278
- }; // Vérifier l'API en utilisant l'endpoint debug
2287
+ }; // Vérifier l'API en utilisant l'endpoint debug avec les credentials
2279
2288
  _context19.p = 1;
2280
2289
  _context19.n = 2;
2281
2290
  return fetch(this.config.apiUrl + '/debug', {
2282
- method: 'GET',
2283
- timeout: 3000
2291
+ method: 'POST',
2292
+ headers: {
2293
+ 'Content-Type': 'application/json'
2294
+ },
2295
+ body: JSON.stringify({
2296
+ type: this.config.type,
2297
+ client_id: this.config.clientId,
2298
+ secret_id: this.config.secretId
2299
+ })
2284
2300
  });
2285
2301
  case 2:
2286
2302
  testResponse = _context19.v;
@@ -2292,12 +2308,14 @@ function _unsupportedIterableToArray(r, a) {
2292
2308
  return testResponse.json();
2293
2309
  case 3:
2294
2310
  debugData = _context19.v;
2295
- status.api = debugData.status === 'operational';
2296
- console.log('🔍 API Status:', debugData.status);
2311
+ // L'API est accessible si on reçoit une réponse avec success: true
2312
+ status.api = debugData.success === true;
2313
+ console.log('🔍 API Status:', status.api ? 'accessible' : 'inaccessible');
2297
2314
  _context19.n = 5;
2298
2315
  break;
2299
2316
  case 4:
2300
2317
  status.api = false;
2318
+ console.log('🔍 API Status: HTTP', testResponse.status);
2301
2319
  case 5:
2302
2320
  _context19.n = 7;
2303
2321
  break;