Skip to content

feat(s3): Enhance S3 integration with account management and folder retrieval

zakariae yahya a demandé de fusionner feauture/anir-integration vers develop

## Description

Fix S3 account creation workflow to properly handle metadata parsing and automatically select newly created accounts in the wizard. This ensures bucket information is correctly displayed after account creation.

Objectives

  • Parse JSON metadata returned from backend
  • Support both camelCase (backend) and snake_case (TypeScript types)
  • Automatically select created account after creation
  • Display bucket details in wizard form

Files Changed

1. src/shared/api/endpoints/integration-service/s3-endpoints.ts

Status: No changes needed

  • Already contains all required endpoints for S3 CRUD operations
  • Properly documented with request/response examples

2. src/shared/api/stores/integration-service/s3-store.ts

Status: No changes needed

  • Types already support metadata structure
  • S3Account interface includes extra_metadata with bucket info
  • S3AccountCreateRequest has all required fields

3. src/shared/components/wizard/anir-wizard/s3-config.tsx

Changes: FIXED

Issue 1: Metadata JSON Parsing (Line 598-609)

Before:

// Directly accessed metadata without parsing
createdAccount.extra_metadata?.bucket_name

After:

// Parse JSON metadata if necessary
let parsedMetadata: any = {};
const metaStr = (createdAccount as any).extraMetadata || (createdAccount as any).extra_metadata;
if (metaStr) {
  try {
    parsedMetadata = typeof metaStr === 'string'
      ? JSON.parse(metaStr)
      : metaStr;
  } catch (e) {
    parsedMetadata = metaStr;
  }
}

Reason: Backend returns extraMetadata as a JSON string (e.g., "{"bucket_name": "..."}")

Issue 2: Account Auto-Selection (Line 628-630)

Before:

// Account not selected after creation
// Dropdown remained empty

After:

selectedAccounts: {
  ...prev.selectedAccounts || {},
  'amazon-s3': createdAccount.uid,  // Auto-select
},

Reason: Allows immediate access to bucket contents without manual reselection

Issue 3: Account Name Compatibility (Line 620)

Before:

name: createdAccount.accountName  // TypeScript error

After:

name: (createdAccount as any).accountName || createdAccount.account_name,

Reason: Supports both API response formats (camelCase & snake_case)


Testing

Test Case 1: Create S3 Account

Steps:

  • Fill form:
    • Account name: zakariae.yahya
    • S3 bucket name: iavia-documents-test
    • Access Key ID: AKIA...
    • Secret Access Key: ...
    • Region: eu-west-3
  • Click "Enregistrer"

Expected Result:

  • Account created successfully
  • Metadata parsed from JSON
  • Account automatically selected in dropdown
  • Bucket details displayed in form
  • Can proceed to next step

Test Case 2: Verify Wizard Data

Steps:

  • Check console or devtools:
    wizardData.selectedAccounts['amazon-s3']
    // Should equal: createdAccount.uid (not empty)

Test Case 3: Activate Agent

Steps:

  • Complete wizard through step 4
  • Click "Activer ANIR"

Expected Result:

  • Wizard completes successfully
  • Agent created with S3 integration
  • Indexation job created with frequency

Backend Integration

  • Works with POST /integrations/accounts/amazon-s3
  • Handles extraMetadata as JSON string
  • Supports metadata with fields:
    • bucket_name
    • access_key_id
    • secret_access_key
    • bucket_region

Related Issues

  • S3 Account Creation not selecting newly created account
  • Metadata not displayed after account creation
  • Type errors with accountName field

Rapports de requête de fusion