Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add PersonalDataAndDocumentsDetailed kyc schema #122

Merged
merged 6 commits into from Feb 3, 2023

Conversation

cajubelt
Copy link
Contributor

@cajubelt cajubelt commented Feb 2, 2023

similar to #121 but includes more semantics in the zod schemas, in particular:

  • when the back of the document is required
  • what the email should look like

also more DRY with the existing kyc schema

@cajubelt cajubelt changed the title Cajubelt/add kyc schema feat: add PersonalDataAndDocumentsDetailed kyc schema Feb 2, 2023
src/kyc.ts Outdated
DL = 'DL',
}

// need [string, ...string[]] types to get zod enums to compile
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i would have preferred using IdentificationDocumentType[] for both of these, but zod errored out because it doesn't like if you create empty enums I guess. I welcome other ideas of getting this to work though

Copy link
Contributor

@jophish jophish left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM; just one question about how the Zod behaves

IdentificationDocumentType,
...IdentificationDocumentType[],
] = [IdentificationDocumentType.IDC, IdentificationDocumentType.DL]
const documentsWithoutBack: [
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

...and the award for most uses of the word "document" in a single expression goes to... 🤣

}),
)
.and(
z
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i assume the linter did this due to the next line's length, but weird to have a line containing only z here

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

z

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tbh i hate this but yes it's the linter

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

futzed around for a while trying to get the z some company on that line, to no avail

identificationDocumentType: identificationDocumentTypeWithBackSchema,
identificationDocumentBack: z.string(),
})
.or(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If this or is "selected" by the parser (by identificationDocumentBack being omitted from the object), does the type of identificationDocumentType described here (identificationDocumentTypeWithoutBackSchema) override the more general one set above?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That is, if identificationDocumentBack is missing, does this setup cause Zod to enforce that identificationDocumentType be of type identificationDocumentTypeWithoutBackSchema?

Copy link
Contributor Author

@cajubelt cajubelt Feb 3, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think so, but to avoid having to reason about this I just dropped it. seems simpler.

@jophish jophish self-requested a review February 2, 2023 23:09
src/kyc.ts Outdated
z.object({
email: z.string().regex(EMAIL_REGEX),
identificationDocumentFront: z.string(),
identificationDocumentType: identificationDocumentTypeSchema,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, is this line required, considering both of the options below specify a more narrowly typed version of the same field?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah I'll just get rid of it

@cajubelt cajubelt merged commit 12ac31c into main Feb 3, 2023
@cajubelt cajubelt deleted the cajubelt/add-kyc-schema branch February 3, 2023 00:08
@github-actions
Copy link

github-actions bot commented Feb 3, 2023

🎉 This PR is included in version 11.1.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants