Skip to content

External Services Configuration

This guide covers the configuration of external services and integrations used by the Daisy application.

Service Overview

Azure Services

Azure Service Bus

Configuration for message queuing and event handling:

typescript
interface AzureServiceBusConfig {
  connectionString: string;
  webSocketQueue: string;
  gdprScanReportQueue: string;
  securityScanReportQueue: string;
  daisyCommandCreateChargeQueue: string;
}

Environment variables:

bash
AZURE_SERVICE_BUS_CONNECTION_STRING=your_connection_string
AZURE_SERVICE_BUS_WEBSOCKET_QUEUE=websocket_queue_name
AZURE_SERVICE_BUS_GDPR_SCAN_QUEUE=gdpr_scan_queue_name
AZURE_SERVICE_BUS_SECURITY_SCAN_QUEUE=security_scan_queue_name
AZURE_SERVICE_BUS_DAISY_COMMAND_QUEUE=daisy_command_queue_name

Azure Blob Storage

Configuration for file storage:

typescript
interface AzureBlobConfig {
  connectionString: string;
  accountName: string;
  accountKey: string;
}

Environment variables:

bash
AZURE_STORAGE_CONNECTION_STRING=your_connection_string
AZURE_STORAGE_ACCOUNT_NAME=your_account_name
AZURE_STORAGE_ACCOUNT_KEY=your_account_key

AI Services

Fireworks AI

Configuration for AI model access:

typescript
interface FireworksConfig {
  apiKey: string;
  models: {
    deepseekV3: string;
    deepseekR1: string;
  };
}

Environment variables:

bash
FIREWORKS_API_KEY=your_api_key
FIREWORKS_MODEL_DEEPSEEK_V3=accounts/fireworks/models/deepseek-v3-0324
FIREWORKS_MODEL_DEEPSEEK_R1=accounts/fireworks/models/deepseek-r1

Google Vertex AI

Configuration for Google's AI services:

typescript
interface VertexAIConfig {
  projectId: string;
  location: string;
  credentials: {
    client_email: string;
    private_key: string;
    // other credentials
  };
}

Environment variables:

bash
GOOGLE_PROJECT_ID=your_project_id
GOOGLE_LOCATION=your_location
GOOGLE_APPLICATION_CREDENTIALS=path/to/credentials.json

File Conversion

CloudConvert

Configuration for file format conversion:

typescript
interface CloudConvertConfig {
  apiKey: string;
  sandbox: boolean;
}

Environment variables:

bash
CLOUD_CONVERT_API_KEY=your_api_key
CLOUD_CONVERT_SANDBOX=false

Payment Processing

Stripe

Configuration for payment processing:

typescript
interface StripeConfig {
  apiKey: string;
  webhookSecret: string;
  priceId: string;
}

Environment variables:

bash
STRIPE_API_KEY=your_api_key
STRIPE_WEBHOOK_SECRET=your_webhook_secret
STRIPE_PRICE_ID=your_price_id

Usage Examples

Azure Service Bus Integration

typescript
@Injectable()
class MessageService {
  constructor(
    @Inject(azureServiceBusConfig.KEY)
    private config: TAzureServiceBusConfig,
  ) {}

  async sendMessage(message: any) {
    const client = new ServiceBusClient(this.config.connectionString);
    const sender = client.createSender(this.config.webSocketQueue);

    await sender.sendMessages({
      body: message,
      contentType: 'application/json',
    });
  }
}

File Storage

typescript
@Injectable()
class StorageService {
  private blobService: BlobServiceClient;

  constructor(@Inject(azureBlobConfig.KEY) config: TAzureBlobConfig) {
    this.blobService = BlobServiceClient.fromConnectionString(
      config.connectionString,
    );
  }

  async uploadFile(containerName: string, file: Buffer) {
    const containerClient = this.blobService.getContainerClient(containerName);
    await containerClient.uploadBlob(file);
  }
}

AI Model Integration

typescript
@Injectable()
class AIService {
  constructor(
    @Inject(fireworksConfig.KEY)
    private config: TFireworksConfig,
  ) {}

  async generateText(prompt: string) {
    const model = new ChatFireworks({
      apiKey: this.config.apiKey,
      model: this.config.models.deepseekV3,
    });

    return await model.invoke(prompt);
  }
}

Security Best Practices

1. API Key Management

  • Use environment variables
  • Rotate keys regularly
  • Implement key versioning
  • Monitor key usage

2. Service Access

  • Implement IP whitelisting
  • Use minimum required permissions
  • Enable audit logging
  • Monitor service usage

3. Error Handling

typescript
try {
  await service.operation();
} catch (error) {
  if (error.code === 'AuthenticationFailed') {
    // Handle authentication errors
  } else if (error.code === 'QuotaExceeded') {
    // Handle quota issues
  }
  // Log and handle other errors
}

Monitoring

Key Metrics

  1. Service Health

    • Availability
    • Response times
    • Error rates
    • Usage quotas
  2. Cost Management

    • API calls
    • Storage usage
    • Bandwidth usage
    • Processing time
  3. Security

    • Authentication failures
    • Rate limit hits
    • Unusual patterns
    • Access logs

Cost Optimization

1. Resource Usage

  • Implement caching
  • Batch operations
  • Optimize storage
  • Monitor usage patterns

2. Service Tiers

typescript
const serviceConfig = {
  tier: process.env.NODE_ENV === 'production' ? 'premium' : 'basic',
  features: {
    highAvailability: true,
    encryption: true,
    backup: true,
  },
};

3. Usage Tracking

typescript
async function trackUsage(params: {
  service: string;
  operation: string;
  cost: number;
}) {
  await metrics.record({
    ...params,
    timestamp: new Date(),
    environment: process.env.NODE_ENV,
  });
}

Troubleshooting

Common Issues

  1. Connection Problems

    • Check network connectivity
    • Verify credentials
    • Check service status
    • Review firewall rules
  2. Rate Limiting

    • Implement backoff strategy
    • Monitor usage patterns
    • Optimize requests
    • Use bulk operations
  3. Integration Issues

    • Validate configurations
    • Check API versions
    • Review documentation
    • Test in isolation

Service Dependencies

Required Services

  • Azure Service Bus
  • Azure Blob Storage
  • Fireworks AI
  • Google Vertex AI
  • CloudConvert
  • Stripe

Optional Services

  • Azure Monitor
  • Application Insights
  • Log Analytics

Released under the MIT License.