Skip to content

Commit 473b52a

Browse files
authored
fix(52): fix readme (#59)
* feat: add content type detection for S3 file uploads * fix: add metadata setup for events channel in state machine * refactor: move readme template handling to PackagingStateMachine * refactor: update readme template to use dynamic file placeholders * refactor: separate readme creation into dedicated step function * refactor: remove redundant createReadme step in state machine * feat: add setupREADME step to initialize files context * refactor: use this.props instead of passing props as method arguments * fix props * refactor: break down state machine definition into smaller methods * readme.readme * merge README task * feat: add string processor lambda to state machine props * refactor: move Lambda functions into PackagingStateMachine class * test: add missing stringProcessor property to state machine tests * refactor: remove lambda function props from webhook state machine * fix: add missing PackagingStateMachine import and remove exportProcessor * refactor: remove unused export processor function from test setup * refactor: remove Lambda function from state machine props * remove obsolete getContentType * Create process-string.ts * Webhook creates Packaging state machine * refactor: use string processor Lambda for writing README to S3 * refactor: move writeReadmeToS3Task after createReadme step * fix: update readme template to use correct files path * Packaging vs PackageEntry * smarter readme * createReadmeTask * feat: add entry markdown template constant * refactor: convert entry template to AWS States Language format * refactor: convert readme template to TypeScript class * refactor: convert entry template to class-based implementation * refactor: update entry template to use States.Format with proper placeholders * refactor: create base template class for markdown generation * fix: update template method names to use standardized base class methods * refactor: restructure state machine content creation with named parameters * cleanup * fix: replace string concatenation with States.Format in state machine * feat: add ENTRY_MD constant and use in state machine * refactor: simplify entry template by removing complex fields * test one template first * Update readme.ts * Update Package --------- Co-authored-by: Dr. Ernie Prabhakar (aider) <19791+drernie@users.noreply.github.com>
1 parent 81f638c commit 473b52a

File tree

11 files changed

+371
-159
lines changed

11 files changed

+371
-159
lines changed

lib/benchling-webhook-stack.ts

Lines changed: 1 addition & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ export class BenchlingWebhookStack extends cdk.Stack {
2323
private readonly bucket: s3.IBucket;
2424
private readonly stateMachine: WebhookStateMachine;
2525
private readonly api: WebhookApi;
26-
private readonly exportProcessor: lambda.IFunction;
2726

2827
constructor(
2928
scope: Construct,
@@ -37,37 +36,9 @@ export class BenchlingWebhookStack extends cdk.Stack {
3736

3837
this.bucket = s3.Bucket.fromBucketName(this, "BWBucket", props.bucketName);
3938

40-
// Create the export processor Lambda
41-
this.exportProcessor = new nodejs.NodejsFunction(this, "ExportProcessor", {
42-
entry: path.join(__dirname, "lambda/process-export.ts"),
43-
handler: "handler",
44-
runtime: lambda.Runtime.NODEJS_18_X,
45-
timeout: cdk.Duration.minutes(5),
46-
memorySize: 1024,
47-
environment: {
48-
NODE_OPTIONS: "--enable-source-maps",
49-
QUILT_CATALOG: props.quiltCatalog || "open.quiltdata.com",
50-
},
51-
architecture: lambda.Architecture.ARM_64,
52-
bundling: {
53-
minify: true,
54-
sourceMap: false,
55-
externalModules: [
56-
"@aws-sdk/client-s3",
57-
],
58-
forceDockerBundling: false,
59-
target: "node18",
60-
define: {
61-
"process.env.NODE_ENV": JSON.stringify(process.env.NODE_ENV || "production"),
62-
},
63-
},
64-
});
65-
66-
// Grant the Lambda function access to the S3 bucket
67-
this.bucket.grantReadWrite(this.exportProcessor);
68-
6939
const benchlingConnection = this.createBenchlingConnection(props);
7040

41+
// Create the webhook state machine
7142
this.stateMachine = new WebhookStateMachine(this, "StateMachine", {
7243
bucket: this.bucket,
7344
prefix: props.prefix,
@@ -76,7 +47,6 @@ export class BenchlingWebhookStack extends cdk.Stack {
7647
account: this.account,
7748
benchlingConnection,
7849
benchlingTenant: props.benchlingTenant,
79-
exportProcessor: this.exportProcessor,
8050
quiltCatalog: props.quiltCatalog,
8151
});
8252

lib/constants.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ export const FILES = {
88
ENTRY_JSON: "entry.json",
99
INPUT_JSON: "input.json",
1010
README_MD: "README.md",
11+
ENTRY_MD: "entry.md",
1112
} as const;
1213

1314
export const MIME_TYPES = {

lib/lambda/process-export.ts

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ export const handler = async (event: ProcessExportEvent): Promise<ProcessExportR
3030
Bucket: event.registry,
3131
Key: key,
3232
Body: fileContent,
33-
ContentType: getContentType(entry.entryName),
3433
}));
3534
}
3635
});
@@ -57,11 +56,3 @@ async function downloadFile(url: string): Promise<Buffer> {
5756
}
5857
return Buffer.from(await response.arrayBuffer());
5958
}
60-
61-
import { MIME_TYPES } from "../constants";
62-
63-
function getContentType(fileName: string): string {
64-
const extension = fileName.split(".").pop()?.toLowerCase() || "";
65-
const mimeTypeKey = extension.toUpperCase() as keyof typeof MIME_TYPES;
66-
return MIME_TYPES[mimeTypeKey] || MIME_TYPES.DEFAULT;
67-
}

lib/lambda/process-string.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import { S3Client, PutObjectCommand } from "@aws-sdk/client-s3";
2+
3+
const s3Client = new S3Client({});
4+
5+
export interface ProcessStringEvent {
6+
bucket: string;
7+
key: string;
8+
body: string;
9+
}
10+
11+
export async function handler(event: ProcessStringEvent): Promise<void> {
12+
const { bucket, key, body } = event;
13+
14+
await s3Client.send(
15+
new PutObjectCommand({
16+
Bucket: bucket,
17+
Key: key,
18+
Body: body,
19+
})
20+
);
21+
}

0 commit comments

Comments
 (0)