Apologies for the lack of detail. I’m trying to create bindings for the getSecretValue method on the ugly SecretsManager client of the aws-sdk.
This is what I have so far:
type t
type makeOptions = {@as("Region") region: string}
@new @module("aws-sdk") external make: makeOptions => t = "SecretsManager"
type getSecretValueOptions = {}
type awsError = {
message: string,
code: string,
}
type getSecretValueResponse = {
@as("ARN") arn?: string,
@as("Name") name?: string,
@as("VersionId") versionId?: string,
@as("SecretString") secretString?: string,
}
module Request = {
type t<'d, 'e>
type promiseResult<'d, 'e> = 'd
@send external promise: t<'d, 'e> => promise<promiseResult<'d, 'e>> = "promise"
}
@send
external getSecretValue: (t, getSecretValueOptions) => Request.t<getSecretValueResponse, awsError> =
"getSecretValue"
Do you think I’m moving in the right direction? I’m also struggling to safely handle the exception it can throw, AWSError, which is just an object. I’m aware I’m fixating too much on trying to replicate its Typescript definitions, but I’m a beginner on Rescript, so I thought it was a good idea to use those types as a reference.
This is what I have so far using the bindings:
type res = Found(string) | NotFound | Other(Js.Exn.t)
let handler = async (event: createKeyEvent): createKeyResponse => {
let sm = SecretsManager.make({region: Shared.defaultRegion})
let res = switch await SecretsManager.getSecretValue(sm, {})->SecretsManager.Request.promise {
| res => Found(res.secretString)
// if obj is aws AND it has the code "ResourceNotFound", I would like to return a NotFound variant.
// if it's other than that, I would like to return Other(Js.Exn.t)
| exception Js.Exn.Error(obj) => NotFound
}
// ...
}
But I haven’t found a way to check the exception type. I have looked inside the Js module, and the only thing I can see it’d help is to check for the keys inside that object, but I’m not sure if that is a good idea either.
Thanks a lot, and sorry if that was too much help to ask.