From 79297bbc20b52c6cc1561eee24e77ac0a6f1f6c8 Mon Sep 17 00:00:00 2001 From: awstools Date: Wed, 13 Nov 2024 23:18:58 +0000 Subject: [PATCH] feat(client-b2bi): This release adds a GenerateMapping API to allow generation of JSONata or XSLT transformer code based on input and output samples. --- clients/client-b2bi/README.md | 8 ++ clients/client-b2bi/src/B2bi.ts | 20 +++ clients/client-b2bi/src/B2biClient.ts | 3 + .../src/commands/GenerateMappingCommand.ts | 130 ++++++++++++++++++ clients/client-b2bi/src/commands/index.ts | 1 + clients/client-b2bi/src/models/models_0.ts | 43 +++++- .../client-b2bi/src/protocols/Aws_json1_0.ts | 49 +++++++ codegen/sdk-codegen/aws-models/b2bi.json | 122 +++++++++++++++- 8 files changed, 374 insertions(+), 2 deletions(-) create mode 100644 clients/client-b2bi/src/commands/GenerateMappingCommand.ts diff --git a/clients/client-b2bi/README.md b/clients/client-b2bi/README.md index 93d574c887bb..7e08efe8dd21 100644 --- a/clients/client-b2bi/README.md +++ b/clients/client-b2bi/README.md @@ -284,6 +284,14 @@ DeleteTransformer [Command API Reference](https://docs.aws.amazon.com/AWSJavaScriptSDK/v3/latest/client/b2bi/command/DeleteTransformerCommand/) / [Input](https://docs.aws.amazon.com/AWSJavaScriptSDK/v3/latest/Package/-aws-sdk-client-b2bi/Interface/DeleteTransformerCommandInput/) / [Output](https://docs.aws.amazon.com/AWSJavaScriptSDK/v3/latest/Package/-aws-sdk-client-b2bi/Interface/DeleteTransformerCommandOutput/) + +
+ +GenerateMapping + + +[Command API Reference](https://docs.aws.amazon.com/AWSJavaScriptSDK/v3/latest/client/b2bi/command/GenerateMappingCommand/) / [Input](https://docs.aws.amazon.com/AWSJavaScriptSDK/v3/latest/Package/-aws-sdk-client-b2bi/Interface/GenerateMappingCommandInput/) / [Output](https://docs.aws.amazon.com/AWSJavaScriptSDK/v3/latest/Package/-aws-sdk-client-b2bi/Interface/GenerateMappingCommandOutput/) +
diff --git a/clients/client-b2bi/src/B2bi.ts b/clients/client-b2bi/src/B2bi.ts index ecd633e1aca6..be2bbf829c08 100644 --- a/clients/client-b2bi/src/B2bi.ts +++ b/clients/client-b2bi/src/B2bi.ts @@ -48,6 +48,11 @@ import { DeleteTransformerCommandInput, DeleteTransformerCommandOutput, } from "./commands/DeleteTransformerCommand"; +import { + GenerateMappingCommand, + GenerateMappingCommandInput, + GenerateMappingCommandOutput, +} from "./commands/GenerateMappingCommand"; import { GetCapabilityCommand, GetCapabilityCommandInput, @@ -143,6 +148,7 @@ const commands = { DeletePartnershipCommand, DeleteProfileCommand, DeleteTransformerCommand, + GenerateMappingCommand, GetCapabilityCommand, GetPartnershipCommand, GetProfileCommand, @@ -307,6 +313,20 @@ export interface B2bi { cb: (err: any, data?: DeleteTransformerCommandOutput) => void ): void; + /** + * @see {@link GenerateMappingCommand} + */ + generateMapping( + args: GenerateMappingCommandInput, + options?: __HttpHandlerOptions + ): Promise; + generateMapping(args: GenerateMappingCommandInput, cb: (err: any, data?: GenerateMappingCommandOutput) => void): void; + generateMapping( + args: GenerateMappingCommandInput, + options: __HttpHandlerOptions, + cb: (err: any, data?: GenerateMappingCommandOutput) => void + ): void; + /** * @see {@link GetCapabilityCommand} */ diff --git a/clients/client-b2bi/src/B2biClient.ts b/clients/client-b2bi/src/B2biClient.ts index 5eb6a9faeae5..74504a4abd90 100644 --- a/clients/client-b2bi/src/B2biClient.ts +++ b/clients/client-b2bi/src/B2biClient.ts @@ -65,6 +65,7 @@ import { DeleteCapabilityCommandInput, DeleteCapabilityCommandOutput } from "./c import { DeletePartnershipCommandInput, DeletePartnershipCommandOutput } from "./commands/DeletePartnershipCommand"; import { DeleteProfileCommandInput, DeleteProfileCommandOutput } from "./commands/DeleteProfileCommand"; import { DeleteTransformerCommandInput, DeleteTransformerCommandOutput } from "./commands/DeleteTransformerCommand"; +import { GenerateMappingCommandInput, GenerateMappingCommandOutput } from "./commands/GenerateMappingCommand"; import { GetCapabilityCommandInput, GetCapabilityCommandOutput } from "./commands/GetCapabilityCommand"; import { GetPartnershipCommandInput, GetPartnershipCommandOutput } from "./commands/GetPartnershipCommand"; import { GetProfileCommandInput, GetProfileCommandOutput } from "./commands/GetProfileCommand"; @@ -115,6 +116,7 @@ export type ServiceInputTypes = | DeletePartnershipCommandInput | DeleteProfileCommandInput | DeleteTransformerCommandInput + | GenerateMappingCommandInput | GetCapabilityCommandInput | GetPartnershipCommandInput | GetProfileCommandInput @@ -149,6 +151,7 @@ export type ServiceOutputTypes = | DeletePartnershipCommandOutput | DeleteProfileCommandOutput | DeleteTransformerCommandOutput + | GenerateMappingCommandOutput | GetCapabilityCommandOutput | GetPartnershipCommandOutput | GetProfileCommandOutput diff --git a/clients/client-b2bi/src/commands/GenerateMappingCommand.ts b/clients/client-b2bi/src/commands/GenerateMappingCommand.ts new file mode 100644 index 000000000000..2ef14843ca69 --- /dev/null +++ b/clients/client-b2bi/src/commands/GenerateMappingCommand.ts @@ -0,0 +1,130 @@ +// smithy-typescript generated code +import { getEndpointPlugin } from "@smithy/middleware-endpoint"; +import { getSerdePlugin } from "@smithy/middleware-serde"; +import { Command as $Command } from "@smithy/smithy-client"; +import { MetadataBearer as __MetadataBearer } from "@smithy/types"; + +import { B2biClientResolvedConfig, ServiceInputTypes, ServiceOutputTypes } from "../B2biClient"; +import { commonParams } from "../endpoint/EndpointParameters"; +import { GenerateMappingRequest, GenerateMappingResponse } from "../models/models_0"; +import { de_GenerateMappingCommand, se_GenerateMappingCommand } from "../protocols/Aws_json1_0"; + +/** + * @public + */ +export type { __MetadataBearer }; +export { $Command }; +/** + * @public + * + * The input for {@link GenerateMappingCommand}. + */ +export interface GenerateMappingCommandInput extends GenerateMappingRequest {} +/** + * @public + * + * The output of {@link GenerateMappingCommand}. + */ +export interface GenerateMappingCommandOutput extends GenerateMappingResponse, __MetadataBearer {} + +/** + *

Takes sample input and output documents and uses Amazon Bedrock to generate a mapping automatically. Depending on the accuracy and other factors, you can then edit the mapping for your needs.

+ * + *

Before you can use the AI-assisted feature for Amazon Web Services B2B Data Interchange you must enable models in Amazon Bedrock. For details, see AI-assisted template mapping prerequisites in + * the Amazon Web Services B2B Data Interchange User guide.

+ *
+ * @example + * Use a bare-bones client and the command you need to make an API call. + * ```javascript + * import { B2biClient, GenerateMappingCommand } from "@aws-sdk/client-b2bi"; // ES Modules import + * // const { B2biClient, GenerateMappingCommand } = require("@aws-sdk/client-b2bi"); // CommonJS import + * const client = new B2biClient(config); + * const input = { // GenerateMappingRequest + * inputFileContent: "STRING_VALUE", // required + * outputFileContent: "STRING_VALUE", // required + * mappingType: "JSONATA" || "XSLT", // required + * }; + * const command = new GenerateMappingCommand(input); + * const response = await client.send(command); + * // { // GenerateMappingResponse + * // mappingTemplate: "STRING_VALUE", // required + * // mappingAccuracy: Number("float"), + * // }; + * + * ``` + * + * @param GenerateMappingCommandInput - {@link GenerateMappingCommandInput} + * @returns {@link GenerateMappingCommandOutput} + * @see {@link GenerateMappingCommandInput} for command's `input` shape. + * @see {@link GenerateMappingCommandOutput} for command's `response` shape. + * @see {@link B2biClientResolvedConfig | config} for B2biClient's `config` shape. + * + * @throws {@link AccessDeniedException} (client fault) + *

You do not have sufficient access to perform this action.

+ * + * @throws {@link InternalServerException} (server fault) + *

This exception is thrown when an error occurs in the Amazon Web Services B2B Data Interchange service.

+ * + * @throws {@link ThrottlingException} (client fault) + *

The request was denied due to throttling: the data speed and rendering may be limited depending on various parameters and conditions.

+ * + * @throws {@link ValidationException} (client fault) + *

Occurs when a B2BI object cannot be validated against a request from another object.

+ * + * @throws {@link B2biServiceException} + *

Base exception class for all service exceptions from B2bi service.

+ * + * @public + * @example Sample GenerateMapping call + * ```javascript + * // + * const input = { + * "inputFileContent": "Sample input file content", + * "mappingType": "JSONATA", + * "outputFileContent": "Sample output file content" + * }; + * const command = new GenerateMappingCommand(input); + * const response = await client.send(command); + * /* response == + * { + * "mappingAccuracy": 0.95, + * "mappingTemplate": "Sample mapping content" + * } + * *\/ + * // example id: example-1 + * ``` + * + */ +export class GenerateMappingCommand extends $Command + .classBuilder< + GenerateMappingCommandInput, + GenerateMappingCommandOutput, + B2biClientResolvedConfig, + ServiceInputTypes, + ServiceOutputTypes + >() + .ep(commonParams) + .m(function (this: any, Command: any, cs: any, config: B2biClientResolvedConfig, o: any) { + return [ + getSerdePlugin(config, this.serialize, this.deserialize), + getEndpointPlugin(config, Command.getEndpointParameterInstructions()), + ]; + }) + .s("B2BI", "GenerateMapping", {}) + .n("B2biClient", "GenerateMappingCommand") + .f(void 0, void 0) + .ser(se_GenerateMappingCommand) + .de(de_GenerateMappingCommand) + .build() { + /** @internal type navigation helper, not in runtime. */ + protected declare static __types: { + api: { + input: GenerateMappingRequest; + output: GenerateMappingResponse; + }; + sdk: { + input: GenerateMappingCommandInput; + output: GenerateMappingCommandOutput; + }; + }; +} diff --git a/clients/client-b2bi/src/commands/index.ts b/clients/client-b2bi/src/commands/index.ts index e21b52225470..afce46d69dd6 100644 --- a/clients/client-b2bi/src/commands/index.ts +++ b/clients/client-b2bi/src/commands/index.ts @@ -8,6 +8,7 @@ export * from "./DeleteCapabilityCommand"; export * from "./DeletePartnershipCommand"; export * from "./DeleteProfileCommand"; export * from "./DeleteTransformerCommand"; +export * from "./GenerateMappingCommand"; export * from "./GetCapabilityCommand"; export * from "./GetPartnershipCommand"; export * from "./GetProfileCommand"; diff --git a/clients/client-b2bi/src/models/models_0.ts b/clients/client-b2bi/src/models/models_0.ts index b9b86e95c68e..ff5103357266 100644 --- a/clients/client-b2bi/src/models/models_0.ts +++ b/clients/client-b2bi/src/models/models_0.ts @@ -902,6 +902,47 @@ export interface CreateStarterMappingTemplateResponse { mappingTemplate: string | undefined; } +/** + * @public + */ +export interface GenerateMappingRequest { + /** + *

Provide the contents of a sample X12 EDI file (for inbound EDI) or JSON/XML file (for outbound EDI) to use as a starting point for the mapping.

+ * @public + */ + inputFileContent: string | undefined; + + /** + *

Provide the contents of a sample X12 EDI file (for outbound EDI) or JSON/XML file (for inbound EDI) to use as a target for the mapping.

+ * @public + */ + outputFileContent: string | undefined; + + /** + *

Specify the mapping type: either JSONATA or XSLT. + *

+ * @public + */ + mappingType: MappingType | undefined; +} + +/** + * @public + */ +export interface GenerateMappingResponse { + /** + *

Returns a mapping template based on your inputs.

+ * @public + */ + mappingTemplate: string | undefined; + + /** + *

Returns a percentage that estimates the accuracy of the generated mapping.

+ * @public + */ + mappingAccuracy?: number | undefined; +} + /** * @public */ @@ -3006,7 +3047,7 @@ export interface UpdateTransformerRequest { name?: string | undefined; /** - *

Specifies the transformer's status. You can update the state of the transformer, from active to inactive, or inactive to active.

+ *

Specifies the transformer's status. You can update the state of the transformer from inactive to active.

* @public */ status?: TransformerStatus | undefined; diff --git a/clients/client-b2bi/src/protocols/Aws_json1_0.ts b/clients/client-b2bi/src/protocols/Aws_json1_0.ts index 980133c3818f..896d5bf86f5f 100644 --- a/clients/client-b2bi/src/protocols/Aws_json1_0.ts +++ b/clients/client-b2bi/src/protocols/Aws_json1_0.ts @@ -12,6 +12,7 @@ import { decorateServiceException as __decorateServiceException, expectNonNull as __expectNonNull, expectString as __expectString, + limitedParseFloat32 as __limitedParseFloat32, parseRfc3339DateTimeWithOffset as __parseRfc3339DateTimeWithOffset, take, withBaseException, @@ -36,6 +37,7 @@ import { DeleteCapabilityCommandInput, DeleteCapabilityCommandOutput } from "../ import { DeletePartnershipCommandInput, DeletePartnershipCommandOutput } from "../commands/DeletePartnershipCommand"; import { DeleteProfileCommandInput, DeleteProfileCommandOutput } from "../commands/DeleteProfileCommand"; import { DeleteTransformerCommandInput, DeleteTransformerCommandOutput } from "../commands/DeleteTransformerCommand"; +import { GenerateMappingCommandInput, GenerateMappingCommandOutput } from "../commands/GenerateMappingCommand"; import { GetCapabilityCommandInput, GetCapabilityCommandOutput } from "../commands/GetCapabilityCommand"; import { GetPartnershipCommandInput, GetPartnershipCommandOutput } from "../commands/GetPartnershipCommand"; import { GetProfileCommandInput, GetProfileCommandOutput } from "../commands/GetProfileCommand"; @@ -88,6 +90,8 @@ import { EdiConfiguration, EdiType, FormatOptions, + GenerateMappingRequest, + GenerateMappingResponse, GetCapabilityRequest, GetCapabilityResponse, GetPartnershipRequest, @@ -264,6 +268,19 @@ export const se_DeleteTransformerCommand = async ( return buildHttpRpcRequest(context, headers, "/", undefined, body); }; +/** + * serializeAws_json1_0GenerateMappingCommand + */ +export const se_GenerateMappingCommand = async ( + input: GenerateMappingCommandInput, + context: __SerdeContext +): Promise<__HttpRequest> => { + const headers: __HeaderBag = sharedHeaders("GenerateMapping"); + let body: any; + body = JSON.stringify(_json(input)); + return buildHttpRpcRequest(context, headers, "/", undefined, body); +}; + /** * serializeAws_json1_0GetCapabilityCommand */ @@ -692,6 +709,26 @@ export const de_DeleteTransformerCommand = async ( return response; }; +/** + * deserializeAws_json1_0GenerateMappingCommand + */ +export const de_GenerateMappingCommand = async ( + output: __HttpResponse, + context: __SerdeContext +): Promise => { + if (output.statusCode >= 300) { + return de_CommandError(output, context); + } + const data: any = await parseBody(output.body, context); + let contents: any = {}; + contents = de_GenerateMappingResponse(data, context); + const response: GenerateMappingCommandOutput = { + $metadata: deserializeMetadata(output), + ...contents, + }; + return response; +}; + /** * deserializeAws_json1_0GetCapabilityCommand */ @@ -1320,6 +1357,8 @@ const se_CreateTransformerRequest = (input: CreateTransformerRequest, context: _ // se_FormatOptions omitted. +// se_GenerateMappingRequest omitted. + // se_GetCapabilityRequest omitted. // se_GetPartnershipRequest omitted. @@ -1526,6 +1565,16 @@ const de_CreateTransformerResponse = (output: any, context: __SerdeContext): Cre // de_FormatOptions omitted. +/** + * deserializeAws_json1_0GenerateMappingResponse + */ +const de_GenerateMappingResponse = (output: any, context: __SerdeContext): GenerateMappingResponse => { + return take(output, { + mappingAccuracy: __limitedParseFloat32, + mappingTemplate: __expectString, + }) as any; +}; + /** * deserializeAws_json1_0GetCapabilityResponse */ diff --git a/codegen/sdk-codegen/aws-models/b2bi.json b/codegen/sdk-codegen/aws-models/b2bi.json index 782d1d572166..f43508415ba3 100644 --- a/codegen/sdk-codegen/aws-models/b2bi.json +++ b/codegen/sdk-codegen/aws-models/b2bi.json @@ -33,6 +33,9 @@ { "target": "com.amazonaws.b2bi#CreateStarterMappingTemplate" }, + { + "target": "com.amazonaws.b2bi#GenerateMapping" + }, { "target": "com.amazonaws.b2bi#GetTransformerJob" }, @@ -2460,6 +2463,123 @@ } } }, + "com.amazonaws.b2bi#GenerateMapping": { + "type": "operation", + "input": { + "target": "com.amazonaws.b2bi#GenerateMappingRequest" + }, + "output": { + "target": "com.amazonaws.b2bi#GenerateMappingResponse" + }, + "errors": [ + { + "target": "com.amazonaws.b2bi#AccessDeniedException" + }, + { + "target": "com.amazonaws.b2bi#InternalServerException" + }, + { + "target": "com.amazonaws.b2bi#ThrottlingException" + }, + { + "target": "com.amazonaws.b2bi#ValidationException" + } + ], + "traits": { + "smithy.api#documentation": "

Takes sample input and output documents and uses Amazon Bedrock to generate a mapping automatically. Depending on the accuracy and other factors, you can then edit the mapping for your needs.

\n \n

Before you can use the AI-assisted feature for Amazon Web Services B2B Data Interchange you must enable models in Amazon Bedrock. For details, see AI-assisted template mapping prerequisites in\n the Amazon Web Services B2B Data Interchange User guide.

\n
", + "smithy.api#examples": [ + { + "title": "Sample GenerateMapping call", + "input": { + "inputFileContent": "Sample input file content", + "outputFileContent": "Sample output file content", + "mappingType": "JSONATA" + }, + "output": { + "mappingTemplate": "Sample mapping content", + "mappingAccuracy": 0.95 + } + } + ], + "smithy.api#http": { + "uri": "/generate-mapping", + "method": "POST" + }, + "smithy.api#idempotent": {} + } + }, + "com.amazonaws.b2bi#GenerateMappingInputFileContent": { + "type": "string", + "traits": { + "smithy.api#length": { + "min": 0, + "max": 5000000 + } + } + }, + "com.amazonaws.b2bi#GenerateMappingOutputFileContent": { + "type": "string", + "traits": { + "smithy.api#length": { + "min": 0, + "max": 5000000 + } + } + }, + "com.amazonaws.b2bi#GenerateMappingRequest": { + "type": "structure", + "members": { + "inputFileContent": { + "target": "com.amazonaws.b2bi#GenerateMappingInputFileContent", + "traits": { + "smithy.api#documentation": "

Provide the contents of a sample X12 EDI file (for inbound EDI) or JSON/XML file (for outbound EDI) to use as a starting point for the mapping.

", + "smithy.api#required": {} + } + }, + "outputFileContent": { + "target": "com.amazonaws.b2bi#GenerateMappingOutputFileContent", + "traits": { + "smithy.api#documentation": "

Provide the contents of a sample X12 EDI file (for outbound EDI) or JSON/XML file (for inbound EDI) to use as a target for the mapping.

", + "smithy.api#required": {} + } + }, + "mappingType": { + "target": "com.amazonaws.b2bi#MappingType", + "traits": { + "smithy.api#documentation": "

Specify the mapping type: either JSONATA or XSLT.\n

", + "smithy.api#required": {} + } + } + }, + "traits": { + "smithy.api#input": {} + } + }, + "com.amazonaws.b2bi#GenerateMappingResponse": { + "type": "structure", + "members": { + "mappingTemplate": { + "target": "smithy.api#String", + "traits": { + "smithy.api#documentation": "

Returns a mapping template based on your inputs.

", + "smithy.api#required": {} + } + }, + "mappingAccuracy": { + "target": "smithy.api#Float", + "traits": { + "smithy.api#documentation": "

Returns a percentage that estimates the accuracy of the generated mapping.

", + "smithy.api#range": { + "min": 0.0, + "max": 1.0 + } + } + } + }, + "traits": { + "smithy.api#output": {} + } + }, "com.amazonaws.b2bi#GetCapability": { "type": "operation", "input": { @@ -5927,7 +6047,7 @@ "status": { "target": "com.amazonaws.b2bi#TransformerStatus", "traits": { - "smithy.api#documentation": "

Specifies the transformer's status. You can update the state of the transformer, from active to inactive, or inactive to active.

" + "smithy.api#documentation": "

Specifies the transformer's status. You can update the state of the transformer from inactive to active.

" } }, "fileFormat": {