chore: import upstream snapshot with attribution
CI / Migrate Dev DB (push) Has been skipped
CI / Detect Version (push) Has been cancelled
CI / Migrate DB (push) Has been cancelled
CI / Build Dev ECR (./docker/app.Dockerfile, ECR_APP) (push) Has been cancelled
CI / Build Dev ECR (./docker/db.Dockerfile, ECR_MIGRATIONS) (push) Has been cancelled
CI / Build Dev ECR (./docker/pii.Dockerfile, ECR_PII) (push) Has been cancelled
CI / Build Dev ECR (./docker/realtime.Dockerfile, ECR_REALTIME) (push) Has been cancelled
CI / Deploy Trigger.dev (Dev) (push) Has been cancelled
CI / Build AMD64 (./docker/app.Dockerfile, ECR_APP, ghcr.io/simstudioai/simstudio) (push) Has been cancelled
CI / Build AMD64 (./docker/db.Dockerfile, ECR_MIGRATIONS, ghcr.io/simstudioai/migrations) (push) Has been cancelled
CI / Build AMD64 (./docker/pii.Dockerfile, ECR_PII, ghcr.io/simstudioai/pii) (push) Has been cancelled
CI / Build AMD64 (./docker/realtime.Dockerfile, ECR_REALTIME, ghcr.io/simstudioai/realtime) (push) Has been cancelled
CI / Build ARM64 (GHCR Only) (./docker/app.Dockerfile, ghcr.io/simstudioai/simstudio) (push) Has been cancelled
CI / Build ARM64 (GHCR Only) (./docker/db.Dockerfile, ghcr.io/simstudioai/migrations) (push) Has been cancelled
CI / Build ARM64 (GHCR Only) (./docker/pii.Dockerfile, ghcr.io/simstudioai/pii) (push) Has been cancelled
CI / Build ARM64 (GHCR Only) (./docker/realtime.Dockerfile, ghcr.io/simstudioai/realtime) (push) Has been cancelled
CI / Create GHCR Manifests (ghcr.io/simstudioai/migrations) (push) Has been cancelled
CI / Create GHCR Manifests (ghcr.io/simstudioai/pii) (push) Has been cancelled
CI / Create GHCR Manifests (ghcr.io/simstudioai/realtime) (push) Has been cancelled
CI / Create GHCR Manifests (ghcr.io/simstudioai/simstudio) (push) Has been cancelled
CI / Check Docs Changes (push) Has been cancelled
CI / Process Docs (push) Has been cancelled
CI / Create GitHub Release (push) Has been cancelled
CI / Test and Build (push) Has been cancelled
Publish CLI Package / publish-npm (push) Has been cancelled
Publish Python SDK / publish-pypi (push) Has been cancelled
Publish TypeScript SDK / publish-npm (push) Has been cancelled
CI / Migrate Dev DB (push) Has been skipped
CI / Detect Version (push) Has been cancelled
CI / Migrate DB (push) Has been cancelled
CI / Build Dev ECR (./docker/app.Dockerfile, ECR_APP) (push) Has been cancelled
CI / Build Dev ECR (./docker/db.Dockerfile, ECR_MIGRATIONS) (push) Has been cancelled
CI / Build Dev ECR (./docker/pii.Dockerfile, ECR_PII) (push) Has been cancelled
CI / Build Dev ECR (./docker/realtime.Dockerfile, ECR_REALTIME) (push) Has been cancelled
CI / Deploy Trigger.dev (Dev) (push) Has been cancelled
CI / Build AMD64 (./docker/app.Dockerfile, ECR_APP, ghcr.io/simstudioai/simstudio) (push) Has been cancelled
CI / Build AMD64 (./docker/db.Dockerfile, ECR_MIGRATIONS, ghcr.io/simstudioai/migrations) (push) Has been cancelled
CI / Build AMD64 (./docker/pii.Dockerfile, ECR_PII, ghcr.io/simstudioai/pii) (push) Has been cancelled
CI / Build AMD64 (./docker/realtime.Dockerfile, ECR_REALTIME, ghcr.io/simstudioai/realtime) (push) Has been cancelled
CI / Build ARM64 (GHCR Only) (./docker/app.Dockerfile, ghcr.io/simstudioai/simstudio) (push) Has been cancelled
CI / Build ARM64 (GHCR Only) (./docker/db.Dockerfile, ghcr.io/simstudioai/migrations) (push) Has been cancelled
CI / Build ARM64 (GHCR Only) (./docker/pii.Dockerfile, ghcr.io/simstudioai/pii) (push) Has been cancelled
CI / Build ARM64 (GHCR Only) (./docker/realtime.Dockerfile, ghcr.io/simstudioai/realtime) (push) Has been cancelled
CI / Create GHCR Manifests (ghcr.io/simstudioai/migrations) (push) Has been cancelled
CI / Create GHCR Manifests (ghcr.io/simstudioai/pii) (push) Has been cancelled
CI / Create GHCR Manifests (ghcr.io/simstudioai/realtime) (push) Has been cancelled
CI / Create GHCR Manifests (ghcr.io/simstudioai/simstudio) (push) Has been cancelled
CI / Check Docs Changes (push) Has been cancelled
CI / Process Docs (push) Has been cancelled
CI / Create GitHub Release (push) Has been cancelled
CI / Test and Build (push) Has been cancelled
Publish CLI Package / publish-npm (push) Has been cancelled
Publish Python SDK / publish-pypi (push) Has been cancelled
Publish TypeScript SDK / publish-npm (push) Has been cancelled
This commit is contained in:
@@ -0,0 +1,87 @@
|
||||
import { createLogger } from '@sim/logger'
|
||||
import Stripe from 'stripe'
|
||||
import { env } from '@/lib/core/config/env'
|
||||
|
||||
const logger = createLogger('StripeClient')
|
||||
|
||||
/**
|
||||
* Check if Stripe credentials are valid
|
||||
*/
|
||||
export function hasValidStripeCredentials(): boolean {
|
||||
return !!env.STRIPE_SECRET_KEY
|
||||
}
|
||||
|
||||
/**
|
||||
* Secure Stripe client singleton with initialization guard
|
||||
*/
|
||||
const createStripeClientSingleton = () => {
|
||||
let stripeClient: Stripe | null = null
|
||||
let isInitializing = false
|
||||
|
||||
return {
|
||||
getInstance(): Stripe | null {
|
||||
// If already initialized, return immediately
|
||||
if (stripeClient) return stripeClient
|
||||
|
||||
// Prevent concurrent initialization attempts
|
||||
if (isInitializing) {
|
||||
logger.debug('Stripe client initialization already in progress')
|
||||
return null
|
||||
}
|
||||
|
||||
if (!hasValidStripeCredentials()) {
|
||||
logger.warn('Stripe credentials not available - Stripe operations will be disabled')
|
||||
return null
|
||||
}
|
||||
|
||||
try {
|
||||
isInitializing = true
|
||||
|
||||
stripeClient = new Stripe(env.STRIPE_SECRET_KEY || '', {
|
||||
apiVersion: '2025-08-27.basil',
|
||||
})
|
||||
|
||||
logger.info('Stripe client initialized successfully')
|
||||
return stripeClient
|
||||
} catch (error) {
|
||||
logger.error('Failed to initialize Stripe client', { error })
|
||||
stripeClient = null // Ensure cleanup on failure
|
||||
return null
|
||||
} finally {
|
||||
isInitializing = false
|
||||
}
|
||||
},
|
||||
|
||||
// For testing purposes only - allows resetting the singleton
|
||||
reset(): void {
|
||||
stripeClient = null
|
||||
isInitializing = false
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
const stripeClientSingleton = createStripeClientSingleton()
|
||||
|
||||
/**
|
||||
* Get the Stripe client instance
|
||||
* @returns Stripe client or null if credentials are not available
|
||||
*/
|
||||
export function getStripeClient(): Stripe | null {
|
||||
return stripeClientSingleton.getInstance()
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the Stripe client instance, throwing an error if not available
|
||||
* Use this when Stripe operations are required
|
||||
*/
|
||||
export function requireStripeClient(): Stripe {
|
||||
const client = getStripeClient()
|
||||
|
||||
if (!client) {
|
||||
throw new Error(
|
||||
'Stripe client is not available. Set STRIPE_SECRET_KEY in your environment variables.'
|
||||
)
|
||||
}
|
||||
|
||||
return client
|
||||
}
|
||||
Reference in New Issue
Block a user