smithy-lang / smithy-typescript

Smithy code generators for TypeScript. (in development)
Apache License 2.0
224 stars 83 forks source link

feat: automatic idempotency tokens for header values #1327

Closed kuhe closed 3 months ago

kuhe commented 3 months ago

https://smithy.io/2.0/spec/behavior-traits.html#idempotencytoken-trait

Client implementations MAY automatically provide a value for a request token member if and only if the member is not explicitly provided.

This adds the automatic default token for headers. Previously added for query params in https://github.com/aws/aws-sdk-js-v3/pull/4272.

before

const headers: any = map({}, isSerializableHeaderValue, {
  "content-type": "application/json",
  [_xact]: input[_CT]!,
});

after

import { v4 as generateIdempotencyToken } from "uuid";

const headers: any = map({}, isSerializableHeaderValue, {
  "content-type": "application/json",
  [_xact]: input[_CT] ?? generateIdempotencyToken(),
});