feat: CORS enable button...ish still now understanding this

This commit is contained in:
Zakaria
2026-09-27 14:46:04 -04:00
parent 8470b8d17a
commit b474e823ce
17 changed files with 943 additions and 31 deletions
@@ -0,0 +1,29 @@
import {describe, expect, test} from 'bun:test'
import {awsApiGatewaySchema} from '../cloud-spi/apigatewaySchema'
import type {CloudServiceAdapter} from '../cloud-spi/types'
import {CloudAdapterRegistry} from '../registry/CloudAdapterRegistry'
import {CloudProxyService} from './CloudProxyService'
describe('CloudProxyService API Gateway CORS', () => {
test('forwards resource-scoped CORS configuration to the API Gateway adapter', async () => {
const calls: unknown[] = []
const adapter: CloudServiceAdapter = {
cloud: 'aws', service: 'apigateway', schema: awsApiGatewaySchema,
list: async () => [], get: async () => null, create: async () => ({
id: 'api', name: 'api', cloud: 'aws', service: 'apigateway', type: 'rest-api', region: null, createdAt: null, metadata: {},
}), delete: async () => {},
enableApiGatewayCors: async (apiId, input) => {
calls.push({apiId, input})
return {configuredMethods: ['GET'], proxyMethods: ['POST']}
},
}
const service = new CloudProxyService(new CloudAdapterRegistry([adapter]))
await expect(service.enableApiGatewayCors('aws', 'api-123', {
resourceId: 'resource-456', stage: 'dev', origin: '*', headers: 'Content-Type', methods: ['GET', 'POST'],
})).resolves.toEqual({configuredMethods: ['GET'], proxyMethods: ['POST']})
expect(calls).toEqual([{apiId: 'api-123', input: {
resourceId: 'resource-456', stage: 'dev', origin: '*', headers: 'Content-Type', methods: ['GET', 'POST'],
}}])
})
})
@@ -26,8 +26,11 @@ import type {
ApiGatewayTestRouteResult,
ApiGatewayRoutesResult,
ApiGatewayDeleteRouteInput,
ApiGatewayCorsInput,
ApiGatewayCorsResult,
S3LambdaTriggerInput,
S3LambdaTriggerOverview,
S3BucketWebsiteConfiguration,
EventBridgeLambdaTriggerInput,
EventBridgeLambdaTriggerOverview,
EventBridgeRuleInput,
@@ -280,6 +283,12 @@ export class CloudProxyService {
await adapter.deleteApiGatewayRoute(apiId, input)
}
async enableApiGatewayCors(cloud: CloudProvider, apiId: string, input: ApiGatewayCorsInput): Promise<ApiGatewayCorsResult> {
const adapter = this.requireAdapter(cloud, 'apigateway')
if (!adapter.enableApiGatewayCors) throw new NotSupportedError(`API Gateway CORS is not supported for ${cloud}`)
return adapter.enableApiGatewayCors(apiId, input)
}
async createS3LambdaTrigger(cloud: CloudProvider, bucketName: string, input: S3LambdaTriggerInput): Promise<S3LambdaTriggerOverview> {
const adapter = this.requireAdapter(cloud, 'storage')
if (!adapter.createS3LambdaTrigger) throw new NotSupportedError(`S3 Lambda triggers are not supported for ${cloud}`)
@@ -298,6 +307,24 @@ export class CloudProxyService {
await adapter.deleteS3LambdaTrigger(bucketName, triggerId)
}
async getS3BucketWebsite(cloud: CloudProvider, bucketName: string): Promise<S3BucketWebsiteConfiguration | null> {
const adapter = this.requireAdapter(cloud, 'storage')
if (!adapter.getS3BucketWebsite) throw new NotSupportedError(`S3 website hosting is not supported for ${cloud}`)
return adapter.getS3BucketWebsite(bucketName)
}
async putS3BucketWebsite(cloud: CloudProvider, bucketName: string, configuration: S3BucketWebsiteConfiguration): Promise<void> {
const adapter = this.requireAdapter(cloud, 'storage')
if (!adapter.putS3BucketWebsite) throw new NotSupportedError(`S3 website hosting is not supported for ${cloud}`)
await adapter.putS3BucketWebsite(bucketName, configuration)
}
async deleteS3BucketWebsite(cloud: CloudProvider, bucketName: string): Promise<void> {
const adapter = this.requireAdapter(cloud, 'storage')
if (!adapter.deleteS3BucketWebsite) throw new NotSupportedError(`S3 website hosting is not supported for ${cloud}`)
await adapter.deleteS3BucketWebsite(bucketName)
}
async createEventBridgeLambdaTrigger(cloud: CloudProvider, input: EventBridgeLambdaTriggerInput): Promise<EventBridgeLambdaTriggerOverview> {
const adapter = this.requireAdapter(cloud, 'serverless')
if (!adapter.createEventBridgeLambdaTrigger) throw new NotSupportedError(`EventBridge Lambda triggers are not supported for ${cloud}`)