Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 3 additions & 6 deletions lib/packaging-state-machine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -189,13 +189,10 @@ export class PackagingStateMachine extends Construct {
"ExtractDownloadURL",
{
parameters: {
"status.$":
"$.exportStatus.status" as ExportStatus["status"],
"downloadURL.$":
"$.exportStatus.response.response.downloadURL",
"status.$": "$.exportStatus.status",
"downloadURL.$": "$.exportStatus.response.response.downloadURL",
"packageName.$": "$.packageName",
"registry.$": "$.registry",
"FILES": FILES,
"registry.$": "$.registry"
},
resultPath: "$.exportStatus",
},
Expand Down
90 changes: 76 additions & 14 deletions lib/templates/readme.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,21 @@ import { BaseTemplate } from "./base-template";

export class ReadmeTemplate extends BaseTemplate {
protected template(): string {
return "# {} ({})\n\n" +
"## Benchling Webhook Example\n\n" +
"This auto-generated package uses Amazon Step Functions and the " +
"[Quilt Packaging Engine]" +
"(https://docs.quilt.bio/quilt-platform-catalog-user/packaging) " +
"to collect data and metadata " +
"for a Benchling Notebook entry.\n\n" +
"## Files\n\n" +
"- [{}](./{}): Entry data\n" +
"- [{}](./{}): Webhook event message\n";
return "# [{}]({})\n\n" +
"* **id**: {}\n" +
"* **displayId**: {}\n" +
"* **folderId**: {}\n" +
"* **createdAt**: {}\n" +
"* **modifiedAt**: {}\n\n" +
"## Authors:\n" +
"{}\n" +
"## Schema\n\n" +
"* **id**: {}\n" +
"* **name**: {}\n\n" +
"## Fields\n" +
"{}\n\n" +
"## Custom fields\n" +
"{}";
}

protected createContent(): stepfunctions.Pass {
Expand All @@ -23,10 +28,18 @@ export class ReadmeTemplate extends BaseTemplate {
{
parameters: {
"content.$": "States.Format('" + this.template() + "'" +
", $.entry.entryData.name" +
", $.entry.entryData.name" + // {title}
", $.entry.entryData.webURL" + // {url}
", $.entry.entryData.id" +
", $.files.FILES.ENTRY_JSON, $.files.FILES.ENTRY_JSON" +
", $.files.FILES.INPUT_JSON, $.files.FILES.INPUT_JSON" +
", $.entry.entryData.displayId" +
", $.entry.entryData.folderId" +
", $.entry.entryData.createdAt" +
", $.entry.entryData.modifiedAt" +
", $.formattedLists.formattedLists.authorsFormatted" + // Authors
", $.entry.entryData.schema.id" +
", $.entry.entryData.schema.name" +
", $.formattedLists.formattedLists.fieldsFormatted" + // Fields
", $.formattedLists.formattedLists.customFieldsFormatted" + // Custom fields
")",
},
resultPath: "$.content",
Expand All @@ -40,16 +53,65 @@ export class ReadmeTemplate extends BaseTemplate {
"SetupREADME",
{
parameters: {
"FILES": FILES,
"FILES": FILES
},
resultPath: "$.files",
},
);
}

private formatFields(): stepfunctions.Pass {
return new stepfunctions.Pass(this.scope, 'FormatFields', {
parameters: {
"fieldsFormatted.$": "States.Array(States.Format('* Project: {}', $.entry.entryData.fields.Project.displayValue), States.Format('* Study: {}', $.entry.entryData.fields.Study.displayValue))"
},
resultPath: "$.fieldsFormatted"
});
}

private formatCustomFields(): stepfunctions.Pass {
return new stepfunctions.Pass(this.scope, 'FormatCustomFields', {
parameters: {
"customFieldsFormatted.$": "States.Array('* No custom fields defined')"
},
resultPath: "$.customFieldsFormatted"
});
}

private formatAuthors(): stepfunctions.Map {
const appendFormattedAuthor = new stepfunctions.Pass(this.scope, 'AppendFormattedAuthor', {
parameters: {
"formattedAuthor.$": "States.Format('* {} <{}@{}>', $.name, $.handle, $.id)"
},
resultPath: "$.formattedAuthor"
});

return new stepfunctions.Map(this.scope, 'FormatAuthors', {
itemsPath: '$.entry.entryData.authors',
resultPath: "$.authorsFormatted"
}).itemProcessor(appendFormattedAuthor);
}

private joinListVariables(): stepfunctions.Pass {
return new stepfunctions.Pass(this.scope, 'JoinFormattedLists', {
parameters: {
"formattedLists": {
"fieldsFormatted.$": "States.JsonToString($.fieldsFormatted)",
"customFieldsFormatted.$": "States.JsonToString($.customFieldsFormatted)",
"authorsFormatted.$": "States.JsonToString($.authorsFormatted[*].formattedAuthor)"
}
},
resultPath: "$.formattedLists"
});
}

public createMarkdown(): stepfunctions.Chain {
return stepfunctions.Chain
.start(this.setupFiles())
.next(this.formatFields())
.next(this.formatCustomFields())
.next(this.formatAuthors())
.next(this.joinListVariables())
.next(super.createMarkdown());
}
}
102 changes: 91 additions & 11 deletions lib/webhook-state-machine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -134,24 +134,104 @@ export class WebhookStateMachine extends Construct {
"packageName.$":
`States.Format('{}/{}', '${this.props.prefix}', $.message.buttonId)`,
"registry": this.props.bucket.bucketName,
"catalog": this.props.quiltCatalog,
},
resultPath: "$.var",
},
);

const successResponse = new stepfunctions.Pass(this, "ButtonSuccess", {
parameters: {
statusCode: 200,
body: JSON.stringify({
message: "Package creation started",
status: "success"
})
}
});
const makeQuiltLinksTask = new stepfunctions.CustomState(
this,
"MakeButtonQuiltLinks",
{
stateJson: {
Type: "Pass",
Parameters: {
"catalog_url.$":
"States.Format('https://{}/b/{}/packages/{}', $.var.catalog, $.var.registry, $.var.packageName)",
"revise_url.$":
"States.Format('https://{}/b/{}/packages/{}?action=revisePackage', $.var.catalog, $.var.registry, $.var.packageName)",
"sync_uri.$":
"States.Format('quilt+s3://{}#package={}&catalog={}', $.var.registry, $.var.packageName, $.var.catalog)",
},
ResultPath: "$.links",
},
},
);

const makeMarkdownTask = new stepfunctions.CustomState(
this,
"MakeButtonMarkdown",
{
stateJson: {
Type: "Pass",
Parameters: {
"links.$": stepfunctions.JsonPath.stringAt(
"States.Format('" +
"# Quilt Links\n" +
"---\n" +
"- [Quilt Catalog]({})\n" +
"- [Drop Zone]({})\n" +
"- Quilt+ URI: {}\n" +
"---\n" +
"> NOTE: It may take a minute for the package to be created asynchronously.\n"+
"', " +
"$.links.catalog_url, " +
"$.links.revise_url, " +
"$.links.sync_uri" +
")",
),
},
ResultPath: "$.markdown",
},
},
);

const updateCanvasTask = new stepfunctions.CustomState(
this,
"UpdateButtonCanvas",
{
stateJson: {
Type: "Task",
Resource: "arn:aws:states:::http:invoke",
Parameters: {
"ApiEndpoint.$":
"States.Format('{}/api/v2/app-canvases/{}', $.baseURL, $.message.canvasId)",
Method: "PATCH",
Authentication: {
ConnectionArn: this.props.benchlingConnection.attrArn,
},
RequestBody: {
"blocks": [
{
"id": "md1",
"type": "MARKDOWN",
"value.$": "$.markdown.links",
},
{
"id.$": "$.message.buttonId",
"type": "BUTTON",
"text": "Update Package",
"enabled": true,
},
],
"enabled": true,
"featureId": "quilt_integration",
},
},
ResultSelector: {
"canvasId.$": "$.ResponseBody.id",
},
ResultPath: "$.canvas",
},
},
);

return buttonMetadataTask
.next(startPackagingExecution)
.next(successResponse);
.next(makeQuiltLinksTask)
.next(makeMarkdownTask)
.next(updateCanvasTask)
.next(startPackagingExecution);
}

private createCanvasWorkflow(
Expand Down