From dd445c72799beab386d9e5e5055381ea0bcfa184 Mon Sep 17 00:00:00 2001 From: "stainless-app[bot]" <142633134+stainless-app[bot]@users.noreply.github.com> Date: Tue, 19 Mar 2024 02:26:49 +0000 Subject: [PATCH 01/11] docs: fix typo in CONTRIBUTING.md (#132) --- CONTRIBUTING.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index bb5db33..9941cad 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -43,7 +43,7 @@ Most tests require you to [set up a mock server](https://github.com/stoplightio/ ```bash # you will need npm installed -npx prism path/to/your/openapi.yml +npx prism mock path/to/your/openapi.yml ``` ```bash From 5acbf8307554cc006f6a6cd6c6bdf9c2de039eae Mon Sep 17 00:00:00 2001 From: "stainless-app[bot]" <142633134+stainless-app[bot]@users.noreply.github.com> Date: Tue, 19 Mar 2024 10:41:33 +0000 Subject: [PATCH 02/11] chore(internal): update generated pragma comment (#134) --- accesstoken.go | 2 +- accesstoken_test.go | 2 +- account.go | 2 +- account_test.go | 2 +- aliases.go | 2 +- client.go | 2 +- client_test.go | 2 +- finchgo.go | 2 +- hris.go | 2 +- hrisbenefit.go | 2 +- hrisbenefit_test.go | 2 +- hrisbenefitindividual.go | 2 +- hrisbenefitindividual_test.go | 2 +- hriscompany.go | 2 +- hriscompany_test.go | 2 +- hrisdirectory.go | 2 +- hrisdirectory_test.go | 2 +- hrisemployment.go | 2 +- hrisemployment_test.go | 2 +- hrisindividual.go | 2 +- hrisindividual_test.go | 2 +- hrispayment.go | 2 +- hrispayment_test.go | 2 +- hrispaystatement.go | 2 +- hrispaystatement_test.go | 2 +- internal/apierror/apierror.go | 2 +- internal/requestconfig/requestconfig.go | 2 +- internal/shared/pagination.go | 2 +- internal/shared/shared.go | 2 +- internal/version.go | 2 +- job.go | 2 +- jobautomated.go | 2 +- jobautomated_test.go | 2 +- jobmanual.go | 2 +- jobmanual_test.go | 2 +- option/requestoption.go | 2 +- paginationauto_test.go | 2 +- paginationmanual_test.go | 2 +- provider.go | 2 +- provider_test.go | 2 +- requestforwarding.go | 2 +- requestforwarding_test.go | 2 +- sandbox.go | 2 +- sandboxcompany.go | 2 +- sandboxcompany_test.go | 2 +- sandboxconnection.go | 2 +- sandboxconnection_test.go | 2 +- sandboxconnectionaccount.go | 2 +- sandboxconnectionaccount_test.go | 2 +- sandboxdirectory.go | 2 +- sandboxdirectory_test.go | 2 +- sandboxemployment.go | 2 +- sandboxemployment_test.go | 2 +- sandboxindividual.go | 2 +- sandboxindividual_test.go | 2 +- sandboxjob.go | 2 +- sandboxjob_test.go | 2 +- sandboxjobconfiguration.go | 2 +- sandboxjobconfiguration_test.go | 2 +- sandboxpayment.go | 2 +- sandboxpayment_test.go | 2 +- usage_test.go | 2 +- webhook.go | 2 +- webhook_test.go | 2 +- 64 files changed, 64 insertions(+), 64 deletions(-) diff --git a/accesstoken.go b/accesstoken.go index ed192c0..07ca8ca 100644 --- a/accesstoken.go +++ b/accesstoken.go @@ -1,4 +1,4 @@ -// File generated from our OpenAPI spec by Stainless. +// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. package finchgo diff --git a/accesstoken_test.go b/accesstoken_test.go index d502313..52a0987 100644 --- a/accesstoken_test.go +++ b/accesstoken_test.go @@ -1,4 +1,4 @@ -// File generated from our OpenAPI spec by Stainless. +// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. package finchgo_test diff --git a/account.go b/account.go index a978f20..48724cd 100644 --- a/account.go +++ b/account.go @@ -1,4 +1,4 @@ -// File generated from our OpenAPI spec by Stainless. +// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. package finchgo diff --git a/account_test.go b/account_test.go index 9bff782..d53c5d3 100644 --- a/account_test.go +++ b/account_test.go @@ -1,4 +1,4 @@ -// File generated from our OpenAPI spec by Stainless. +// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. package finchgo_test diff --git a/aliases.go b/aliases.go index b046ec4..767990a 100644 --- a/aliases.go +++ b/aliases.go @@ -1,4 +1,4 @@ -// File generated from our OpenAPI spec by Stainless. +// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. package finchgo diff --git a/client.go b/client.go index e76bc0b..78a0d2e 100644 --- a/client.go +++ b/client.go @@ -1,4 +1,4 @@ -// File generated from our OpenAPI spec by Stainless. +// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. package finchgo diff --git a/client_test.go b/client_test.go index 4241e76..fc7d656 100644 --- a/client_test.go +++ b/client_test.go @@ -1,4 +1,4 @@ -// File generated from our OpenAPI spec by Stainless. +// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. package finchgo_test diff --git a/finchgo.go b/finchgo.go index 92a12fd..59c6281 100644 --- a/finchgo.go +++ b/finchgo.go @@ -1,4 +1,4 @@ -// File generated from our OpenAPI spec by Stainless. +// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. package finchgo diff --git a/hris.go b/hris.go index af716c9..9ab7901 100644 --- a/hris.go +++ b/hris.go @@ -1,4 +1,4 @@ -// File generated from our OpenAPI spec by Stainless. +// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. package finchgo diff --git a/hrisbenefit.go b/hrisbenefit.go index b84e80d..14a74b9 100644 --- a/hrisbenefit.go +++ b/hrisbenefit.go @@ -1,4 +1,4 @@ -// File generated from our OpenAPI spec by Stainless. +// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. package finchgo diff --git a/hrisbenefit_test.go b/hrisbenefit_test.go index f100961..8463b5c 100644 --- a/hrisbenefit_test.go +++ b/hrisbenefit_test.go @@ -1,4 +1,4 @@ -// File generated from our OpenAPI spec by Stainless. +// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. package finchgo_test diff --git a/hrisbenefitindividual.go b/hrisbenefitindividual.go index 81f2486..294adc9 100644 --- a/hrisbenefitindividual.go +++ b/hrisbenefitindividual.go @@ -1,4 +1,4 @@ -// File generated from our OpenAPI spec by Stainless. +// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. package finchgo diff --git a/hrisbenefitindividual_test.go b/hrisbenefitindividual_test.go index 5ceb056..9a0bbfa 100644 --- a/hrisbenefitindividual_test.go +++ b/hrisbenefitindividual_test.go @@ -1,4 +1,4 @@ -// File generated from our OpenAPI spec by Stainless. +// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. package finchgo_test diff --git a/hriscompany.go b/hriscompany.go index 8f07715..97d7dbf 100644 --- a/hriscompany.go +++ b/hriscompany.go @@ -1,4 +1,4 @@ -// File generated from our OpenAPI spec by Stainless. +// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. package finchgo diff --git a/hriscompany_test.go b/hriscompany_test.go index 7336173..1d74416 100644 --- a/hriscompany_test.go +++ b/hriscompany_test.go @@ -1,4 +1,4 @@ -// File generated from our OpenAPI spec by Stainless. +// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. package finchgo_test diff --git a/hrisdirectory.go b/hrisdirectory.go index be48dc4..e193fa5 100644 --- a/hrisdirectory.go +++ b/hrisdirectory.go @@ -1,4 +1,4 @@ -// File generated from our OpenAPI spec by Stainless. +// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. package finchgo diff --git a/hrisdirectory_test.go b/hrisdirectory_test.go index f7a70b6..12ae98e 100644 --- a/hrisdirectory_test.go +++ b/hrisdirectory_test.go @@ -1,4 +1,4 @@ -// File generated from our OpenAPI spec by Stainless. +// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. package finchgo_test diff --git a/hrisemployment.go b/hrisemployment.go index bf0ef78..1a09160 100644 --- a/hrisemployment.go +++ b/hrisemployment.go @@ -1,4 +1,4 @@ -// File generated from our OpenAPI spec by Stainless. +// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. package finchgo diff --git a/hrisemployment_test.go b/hrisemployment_test.go index b1ad42f..312df64 100644 --- a/hrisemployment_test.go +++ b/hrisemployment_test.go @@ -1,4 +1,4 @@ -// File generated from our OpenAPI spec by Stainless. +// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. package finchgo_test diff --git a/hrisindividual.go b/hrisindividual.go index 205ea76..3494405 100644 --- a/hrisindividual.go +++ b/hrisindividual.go @@ -1,4 +1,4 @@ -// File generated from our OpenAPI spec by Stainless. +// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. package finchgo diff --git a/hrisindividual_test.go b/hrisindividual_test.go index 4d751cc..3eca037 100644 --- a/hrisindividual_test.go +++ b/hrisindividual_test.go @@ -1,4 +1,4 @@ -// File generated from our OpenAPI spec by Stainless. +// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. package finchgo_test diff --git a/hrispayment.go b/hrispayment.go index 2ad9919..d3c4b25 100644 --- a/hrispayment.go +++ b/hrispayment.go @@ -1,4 +1,4 @@ -// File generated from our OpenAPI spec by Stainless. +// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. package finchgo diff --git a/hrispayment_test.go b/hrispayment_test.go index 4cc72e2..4ff53c1 100644 --- a/hrispayment_test.go +++ b/hrispayment_test.go @@ -1,4 +1,4 @@ -// File generated from our OpenAPI spec by Stainless. +// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. package finchgo_test diff --git a/hrispaystatement.go b/hrispaystatement.go index 21fe327..5ec6bfc 100644 --- a/hrispaystatement.go +++ b/hrispaystatement.go @@ -1,4 +1,4 @@ -// File generated from our OpenAPI spec by Stainless. +// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. package finchgo diff --git a/hrispaystatement_test.go b/hrispaystatement_test.go index 672d55d..e338771 100644 --- a/hrispaystatement_test.go +++ b/hrispaystatement_test.go @@ -1,4 +1,4 @@ -// File generated from our OpenAPI spec by Stainless. +// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. package finchgo_test diff --git a/internal/apierror/apierror.go b/internal/apierror/apierror.go index b179e64..d04ff8e 100644 --- a/internal/apierror/apierror.go +++ b/internal/apierror/apierror.go @@ -1,4 +1,4 @@ -// File generated from our OpenAPI spec by Stainless. +// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. package apierror diff --git a/internal/requestconfig/requestconfig.go b/internal/requestconfig/requestconfig.go index c6e9f2d..e408329 100644 --- a/internal/requestconfig/requestconfig.go +++ b/internal/requestconfig/requestconfig.go @@ -1,4 +1,4 @@ -// File generated from our OpenAPI spec by Stainless. +// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. package requestconfig diff --git a/internal/shared/pagination.go b/internal/shared/pagination.go index ca2d06f..e7b5203 100644 --- a/internal/shared/pagination.go +++ b/internal/shared/pagination.go @@ -1,4 +1,4 @@ -// File generated from our OpenAPI spec by Stainless. +// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. package shared diff --git a/internal/shared/shared.go b/internal/shared/shared.go index 0ca6aac..2c4815f 100644 --- a/internal/shared/shared.go +++ b/internal/shared/shared.go @@ -1,4 +1,4 @@ -// File generated from our OpenAPI spec by Stainless. +// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. package shared diff --git a/internal/version.go b/internal/version.go index 3412443..1f338c3 100644 --- a/internal/version.go +++ b/internal/version.go @@ -1,4 +1,4 @@ -// File generated from our OpenAPI spec by Stainless. +// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. package internal diff --git a/job.go b/job.go index eeb7b2b..f09df46 100644 --- a/job.go +++ b/job.go @@ -1,4 +1,4 @@ -// File generated from our OpenAPI spec by Stainless. +// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. package finchgo diff --git a/jobautomated.go b/jobautomated.go index 05cc741..b20df62 100644 --- a/jobautomated.go +++ b/jobautomated.go @@ -1,4 +1,4 @@ -// File generated from our OpenAPI spec by Stainless. +// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. package finchgo diff --git a/jobautomated_test.go b/jobautomated_test.go index 719255e..b5fa9d1 100644 --- a/jobautomated_test.go +++ b/jobautomated_test.go @@ -1,4 +1,4 @@ -// File generated from our OpenAPI spec by Stainless. +// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. package finchgo_test diff --git a/jobmanual.go b/jobmanual.go index 2230175..ab74c23 100644 --- a/jobmanual.go +++ b/jobmanual.go @@ -1,4 +1,4 @@ -// File generated from our OpenAPI spec by Stainless. +// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. package finchgo diff --git a/jobmanual_test.go b/jobmanual_test.go index c7b733b..f3fe37a 100644 --- a/jobmanual_test.go +++ b/jobmanual_test.go @@ -1,4 +1,4 @@ -// File generated from our OpenAPI spec by Stainless. +// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. package finchgo_test diff --git a/option/requestoption.go b/option/requestoption.go index 26c5b43..ba5a292 100644 --- a/option/requestoption.go +++ b/option/requestoption.go @@ -1,4 +1,4 @@ -// File generated from our OpenAPI spec by Stainless. +// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. package option diff --git a/paginationauto_test.go b/paginationauto_test.go index 38d4e49..c838848 100644 --- a/paginationauto_test.go +++ b/paginationauto_test.go @@ -1,4 +1,4 @@ -// File generated from our OpenAPI spec by Stainless. +// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. package finchgo_test diff --git a/paginationmanual_test.go b/paginationmanual_test.go index 69dc69d..6e60238 100644 --- a/paginationmanual_test.go +++ b/paginationmanual_test.go @@ -1,4 +1,4 @@ -// File generated from our OpenAPI spec by Stainless. +// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. package finchgo_test diff --git a/provider.go b/provider.go index 7523293..94be634 100644 --- a/provider.go +++ b/provider.go @@ -1,4 +1,4 @@ -// File generated from our OpenAPI spec by Stainless. +// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. package finchgo diff --git a/provider_test.go b/provider_test.go index f0196f8..51550cb 100644 --- a/provider_test.go +++ b/provider_test.go @@ -1,4 +1,4 @@ -// File generated from our OpenAPI spec by Stainless. +// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. package finchgo_test diff --git a/requestforwarding.go b/requestforwarding.go index 8469f15..70f08af 100644 --- a/requestforwarding.go +++ b/requestforwarding.go @@ -1,4 +1,4 @@ -// File generated from our OpenAPI spec by Stainless. +// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. package finchgo diff --git a/requestforwarding_test.go b/requestforwarding_test.go index c01f66e..3b0b073 100644 --- a/requestforwarding_test.go +++ b/requestforwarding_test.go @@ -1,4 +1,4 @@ -// File generated from our OpenAPI spec by Stainless. +// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. package finchgo_test diff --git a/sandbox.go b/sandbox.go index 4c55c53..3dc9932 100644 --- a/sandbox.go +++ b/sandbox.go @@ -1,4 +1,4 @@ -// File generated from our OpenAPI spec by Stainless. +// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. package finchgo diff --git a/sandboxcompany.go b/sandboxcompany.go index f79d7c3..cc47fd7 100644 --- a/sandboxcompany.go +++ b/sandboxcompany.go @@ -1,4 +1,4 @@ -// File generated from our OpenAPI spec by Stainless. +// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. package finchgo diff --git a/sandboxcompany_test.go b/sandboxcompany_test.go index ed3201a..1630e84 100644 --- a/sandboxcompany_test.go +++ b/sandboxcompany_test.go @@ -1,4 +1,4 @@ -// File generated from our OpenAPI spec by Stainless. +// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. package finchgo_test diff --git a/sandboxconnection.go b/sandboxconnection.go index d8b2257..2523686 100644 --- a/sandboxconnection.go +++ b/sandboxconnection.go @@ -1,4 +1,4 @@ -// File generated from our OpenAPI spec by Stainless. +// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. package finchgo diff --git a/sandboxconnection_test.go b/sandboxconnection_test.go index d4cc723..b3bf0fc 100644 --- a/sandboxconnection_test.go +++ b/sandboxconnection_test.go @@ -1,4 +1,4 @@ -// File generated from our OpenAPI spec by Stainless. +// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. package finchgo_test diff --git a/sandboxconnectionaccount.go b/sandboxconnectionaccount.go index 881c925..76c49ad 100644 --- a/sandboxconnectionaccount.go +++ b/sandboxconnectionaccount.go @@ -1,4 +1,4 @@ -// File generated from our OpenAPI spec by Stainless. +// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. package finchgo diff --git a/sandboxconnectionaccount_test.go b/sandboxconnectionaccount_test.go index 06d25f3..7e7f949 100644 --- a/sandboxconnectionaccount_test.go +++ b/sandboxconnectionaccount_test.go @@ -1,4 +1,4 @@ -// File generated from our OpenAPI spec by Stainless. +// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. package finchgo_test diff --git a/sandboxdirectory.go b/sandboxdirectory.go index 5c6379e..37b2d97 100644 --- a/sandboxdirectory.go +++ b/sandboxdirectory.go @@ -1,4 +1,4 @@ -// File generated from our OpenAPI spec by Stainless. +// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. package finchgo diff --git a/sandboxdirectory_test.go b/sandboxdirectory_test.go index cf3ce4c..ef8fe1a 100644 --- a/sandboxdirectory_test.go +++ b/sandboxdirectory_test.go @@ -1,4 +1,4 @@ -// File generated from our OpenAPI spec by Stainless. +// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. package finchgo_test diff --git a/sandboxemployment.go b/sandboxemployment.go index 0dd5fed..0218ad5 100644 --- a/sandboxemployment.go +++ b/sandboxemployment.go @@ -1,4 +1,4 @@ -// File generated from our OpenAPI spec by Stainless. +// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. package finchgo diff --git a/sandboxemployment_test.go b/sandboxemployment_test.go index 897e71a..19687a4 100644 --- a/sandboxemployment_test.go +++ b/sandboxemployment_test.go @@ -1,4 +1,4 @@ -// File generated from our OpenAPI spec by Stainless. +// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. package finchgo_test diff --git a/sandboxindividual.go b/sandboxindividual.go index 88af707..34726d6 100644 --- a/sandboxindividual.go +++ b/sandboxindividual.go @@ -1,4 +1,4 @@ -// File generated from our OpenAPI spec by Stainless. +// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. package finchgo diff --git a/sandboxindividual_test.go b/sandboxindividual_test.go index 87f27de..e5da80a 100644 --- a/sandboxindividual_test.go +++ b/sandboxindividual_test.go @@ -1,4 +1,4 @@ -// File generated from our OpenAPI spec by Stainless. +// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. package finchgo_test diff --git a/sandboxjob.go b/sandboxjob.go index 9fac3bb..0b5976e 100644 --- a/sandboxjob.go +++ b/sandboxjob.go @@ -1,4 +1,4 @@ -// File generated from our OpenAPI spec by Stainless. +// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. package finchgo diff --git a/sandboxjob_test.go b/sandboxjob_test.go index f442f2f..55ae722 100644 --- a/sandboxjob_test.go +++ b/sandboxjob_test.go @@ -1,4 +1,4 @@ -// File generated from our OpenAPI spec by Stainless. +// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. package finchgo_test diff --git a/sandboxjobconfiguration.go b/sandboxjobconfiguration.go index 33e77c7..38899fe 100644 --- a/sandboxjobconfiguration.go +++ b/sandboxjobconfiguration.go @@ -1,4 +1,4 @@ -// File generated from our OpenAPI spec by Stainless. +// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. package finchgo diff --git a/sandboxjobconfiguration_test.go b/sandboxjobconfiguration_test.go index 0b46abf..e8882f1 100644 --- a/sandboxjobconfiguration_test.go +++ b/sandboxjobconfiguration_test.go @@ -1,4 +1,4 @@ -// File generated from our OpenAPI spec by Stainless. +// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. package finchgo_test diff --git a/sandboxpayment.go b/sandboxpayment.go index 8e72d20..1781015 100644 --- a/sandboxpayment.go +++ b/sandboxpayment.go @@ -1,4 +1,4 @@ -// File generated from our OpenAPI spec by Stainless. +// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. package finchgo diff --git a/sandboxpayment_test.go b/sandboxpayment_test.go index 83e5c08..ec04b9b 100644 --- a/sandboxpayment_test.go +++ b/sandboxpayment_test.go @@ -1,4 +1,4 @@ -// File generated from our OpenAPI spec by Stainless. +// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. package finchgo_test diff --git a/usage_test.go b/usage_test.go index 15256c8..ddf83e2 100644 --- a/usage_test.go +++ b/usage_test.go @@ -1,4 +1,4 @@ -// File generated from our OpenAPI spec by Stainless. +// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. package finchgo_test diff --git a/webhook.go b/webhook.go index e590458..3e9899b 100644 --- a/webhook.go +++ b/webhook.go @@ -1,4 +1,4 @@ -// File generated from our OpenAPI spec by Stainless. +// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. package finchgo diff --git a/webhook_test.go b/webhook_test.go index 99d2c18..ced3c2e 100644 --- a/webhook_test.go +++ b/webhook_test.go @@ -1,4 +1,4 @@ -// File generated from our OpenAPI spec by Stainless. +// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. package finchgo_test From a12efdce5d7ac1c4486cccfee5c2b83ed99fa279 Mon Sep 17 00:00:00 2001 From: "stainless-app[bot]" <142633134+stainless-app[bot]@users.noreply.github.com> Date: Tue, 19 Mar 2024 14:44:11 +0000 Subject: [PATCH 03/11] feat: add IsKnown method to enums (#135) --- account.go | 16 +++++++++ hris.go | 8 +++++ hrisbenefit.go | 72 +++++++++++++++++++++++++++++++++++++ hrisbenefitindividual.go | 8 +++++ hriscompany.go | 24 +++++++++++++ hrisemployment.go | 16 +++++++++ hrisindividual.go | 32 +++++++++++++++++ hrispaystatement.go | 32 +++++++++++++++++ internal/shared/shared.go | 16 +++++++++ jobautomated.go | 24 +++++++++++++ jobmanual.go | 8 +++++ provider.go | 8 +++++ sandboxcompany.go | 48 +++++++++++++++++++++++++ sandboxconnection.go | 16 +++++++++ sandboxconnectionaccount.go | 24 +++++++++++++ sandboxdirectory.go | 48 +++++++++++++++++++++++++ sandboxemployment.go | 32 +++++++++++++++++ sandboxindividual.go | 64 +++++++++++++++++++++++++++++++++ sandboxjob.go | 8 +++++ sandboxjobconfiguration.go | 32 +++++++++++++++++ sandboxpayment.go | 32 +++++++++++++++++ webhook.go | 72 +++++++++++++++++++++++++++++++++++++ 22 files changed, 640 insertions(+) diff --git a/account.go b/account.go index 48724cd..6f02902 100644 --- a/account.go +++ b/account.go @@ -175,6 +175,14 @@ const ( IntrospectionClientTypeSandbox IntrospectionClientType = "sandbox" ) +func (r IntrospectionClientType) IsKnown() bool { + switch r { + case IntrospectionClientTypeProduction, IntrospectionClientTypeDevelopment, IntrospectionClientTypeSandbox: + return true + } + return false +} + // The type of the connection associated with the token. // // `provider` - connection to an external provider @@ -186,3 +194,11 @@ const ( IntrospectionConnectionTypeProvider IntrospectionConnectionType = "provider" IntrospectionConnectionTypeFinch IntrospectionConnectionType = "finch" ) + +func (r IntrospectionConnectionType) IsKnown() bool { + switch r { + case IntrospectionConnectionTypeProvider, IntrospectionConnectionTypeFinch: + return true + } + return false +} diff --git a/hris.go b/hris.go index 9ab7901..884324e 100644 --- a/hris.go +++ b/hris.go @@ -89,6 +89,14 @@ const ( IncomeUnitFixed IncomeUnit = "fixed" ) +func (r IncomeUnit) IsKnown() bool { + switch r { + case IncomeUnitYearly, IncomeUnitQuarterly, IncomeUnitMonthly, IncomeUnitSemiMonthly, IncomeUnitBiWeekly, IncomeUnitWeekly, IncomeUnitDaily, IncomeUnitHourly, IncomeUnitFixed: + return true + } + return false +} + // The employee's income as reported by the provider. This may not always be // annualized income, but may be in units of bi-weekly, semi-monthly, daily, etc, // depending on what information the provider returns. diff --git a/hrisbenefit.go b/hrisbenefit.go index 14a74b9..272e66a 100644 --- a/hrisbenefit.go +++ b/hrisbenefit.go @@ -137,6 +137,14 @@ const ( BenefitContributionTypePercent BenefitContributionType = "percent" ) +func (r BenefitContributionType) IsKnown() bool { + switch r { + case BenefitContributionTypeFixed, BenefitContributionTypePercent: + return true + } + return false +} + type BenefitFeaturesAndOperations struct { SupportedFeatures BenefitFeaturesAndOperationsSupportedFeatures `json:"supported_features"` SupportedOperations SupportPerBenefitType `json:"supported_operations"` @@ -210,6 +218,14 @@ const ( BenefitFeaturesAndOperationsSupportedFeaturesCompanyContributionPercent BenefitFeaturesAndOperationsSupportedFeaturesCompanyContribution = "percent" ) +func (r BenefitFeaturesAndOperationsSupportedFeaturesCompanyContribution) IsKnown() bool { + switch r { + case BenefitFeaturesAndOperationsSupportedFeaturesCompanyContributionFixed, BenefitFeaturesAndOperationsSupportedFeaturesCompanyContributionPercent: + return true + } + return false +} + type BenefitFeaturesAndOperationsSupportedFeaturesEmployeeDeduction string const ( @@ -217,6 +233,14 @@ const ( BenefitFeaturesAndOperationsSupportedFeaturesEmployeeDeductionPercent BenefitFeaturesAndOperationsSupportedFeaturesEmployeeDeduction = "percent" ) +func (r BenefitFeaturesAndOperationsSupportedFeaturesEmployeeDeduction) IsKnown() bool { + switch r { + case BenefitFeaturesAndOperationsSupportedFeaturesEmployeeDeductionFixed, BenefitFeaturesAndOperationsSupportedFeaturesEmployeeDeductionPercent: + return true + } + return false +} + type BenefitFeaturesAndOperationsSupportedFeaturesHsaContributionLimit string const ( @@ -224,6 +248,14 @@ const ( BenefitFeaturesAndOperationsSupportedFeaturesHsaContributionLimitFamily BenefitFeaturesAndOperationsSupportedFeaturesHsaContributionLimit = "family" ) +func (r BenefitFeaturesAndOperationsSupportedFeaturesHsaContributionLimit) IsKnown() bool { + switch r { + case BenefitFeaturesAndOperationsSupportedFeaturesHsaContributionLimitIndividual, BenefitFeaturesAndOperationsSupportedFeaturesHsaContributionLimitFamily: + return true + } + return false +} + type BenefitFrequency string const ( @@ -232,6 +264,14 @@ const ( BenefitFrequencyMonthly BenefitFrequency = "monthly" ) +func (r BenefitFrequency) IsKnown() bool { + switch r { + case BenefitFrequencyOneTime, BenefitFrequencyEveryPaycheck, BenefitFrequencyMonthly: + return true + } + return false +} + // Type of benefit. type BenefitType string @@ -257,6 +297,14 @@ const ( BenefitTypeCustomPreTax BenefitType = "custom_pre_tax" ) +func (r BenefitType) IsKnown() bool { + switch r { + case BenefitType_401k, BenefitType_401kRoth, BenefitType_401kLoan, BenefitType_403b, BenefitType_403bRoth, BenefitType_457, BenefitType_457Roth, BenefitTypeS125Medical, BenefitTypeS125Dental, BenefitTypeS125Vision, BenefitTypeHsaPre, BenefitTypeHsaPost, BenefitTypeFsaMedical, BenefitTypeFsaDependentCare, BenefitTypeSimpleIRA, BenefitTypeSimple, BenefitTypeCommuter, BenefitTypeCustomPostTax, BenefitTypeCustomPreTax: + return true + } + return false +} + // Each benefit type and their supported features. If the benefit type is not // supported, the property will be null type BenefitsSupport struct { @@ -430,6 +478,14 @@ const ( SupportedBenefitCompanyContributionPercent SupportedBenefitCompanyContribution = "percent" ) +func (r SupportedBenefitCompanyContribution) IsKnown() bool { + switch r { + case SupportedBenefitCompanyContributionFixed, SupportedBenefitCompanyContributionPercent: + return true + } + return false +} + type SupportedBenefitEmployeeDeduction string const ( @@ -437,6 +493,14 @@ const ( SupportedBenefitEmployeeDeductionPercent SupportedBenefitEmployeeDeduction = "percent" ) +func (r SupportedBenefitEmployeeDeduction) IsKnown() bool { + switch r { + case SupportedBenefitEmployeeDeductionFixed, SupportedBenefitEmployeeDeductionPercent: + return true + } + return false +} + type SupportedBenefitHsaContributionLimit string const ( @@ -444,6 +508,14 @@ const ( SupportedBenefitHsaContributionLimitFamily SupportedBenefitHsaContributionLimit = "family" ) +func (r SupportedBenefitHsaContributionLimit) IsKnown() bool { + switch r { + case SupportedBenefitHsaContributionLimitIndividual, SupportedBenefitHsaContributionLimitFamily: + return true + } + return false +} + type UpdateCompanyBenefitResponse struct { BenefitID string `json:"benefit_id,required"` JSON updateCompanyBenefitResponseJSON `json:"-"` diff --git a/hrisbenefitindividual.go b/hrisbenefitindividual.go index 294adc9..d643a56 100644 --- a/hrisbenefitindividual.go +++ b/hrisbenefitindividual.go @@ -154,6 +154,14 @@ const ( IndividualBenefitBodyHsaContributionLimitFamily IndividualBenefitBodyHsaContributionLimit = "family" ) +func (r IndividualBenefitBodyHsaContributionLimit) IsKnown() bool { + switch r { + case IndividualBenefitBodyHsaContributionLimitIndividual, IndividualBenefitBodyHsaContributionLimitFamily: + return true + } + return false +} + type UnenrolledIndividual struct { Body UnenrolledIndividualBody `json:"body"` // HTTP status code diff --git a/hriscompany.go b/hriscompany.go index 97d7dbf..2dd36d4 100644 --- a/hriscompany.go +++ b/hriscompany.go @@ -122,6 +122,14 @@ const ( CompanyAccountsAccountTypeSavings CompanyAccountsAccountType = "savings" ) +func (r CompanyAccountsAccountType) IsKnown() bool { + switch r { + case CompanyAccountsAccountTypeChecking, CompanyAccountsAccountTypeSavings: + return true + } + return false +} + type CompanyDepartment struct { // The department name. Name string `json:"name,nullable"` @@ -204,6 +212,14 @@ const ( CompanyEntitySubtypeBCorporation CompanyEntitySubtype = "b_corporation" ) +func (r CompanyEntitySubtype) IsKnown() bool { + switch r { + case CompanyEntitySubtypeSCorporation, CompanyEntitySubtypeCCorporation, CompanyEntitySubtypeBCorporation: + return true + } + return false +} + // The tax payer type of the company. type CompanyEntityType string @@ -216,3 +232,11 @@ const ( CompanyEntityTypePartnership CompanyEntityType = "partnership" CompanyEntityTypeCooperative CompanyEntityType = "cooperative" ) + +func (r CompanyEntityType) IsKnown() bool { + switch r { + case CompanyEntityTypeLlc, CompanyEntityTypeLp, CompanyEntityTypeCorporation, CompanyEntityTypeSoleProprietor, CompanyEntityTypeNonProfit, CompanyEntityTypePartnership, CompanyEntityTypeCooperative: + return true + } + return false +} diff --git a/hrisemployment.go b/hrisemployment.go index 1a09160..8b473c6 100644 --- a/hrisemployment.go +++ b/hrisemployment.go @@ -209,6 +209,14 @@ const ( EmploymentDataEmploymentSubtypeIndividualContractor EmploymentDataEmploymentSubtype = "individual_contractor" ) +func (r EmploymentDataEmploymentSubtype) IsKnown() bool { + switch r { + case EmploymentDataEmploymentSubtypeFullTime, EmploymentDataEmploymentSubtypeIntern, EmploymentDataEmploymentSubtypePartTime, EmploymentDataEmploymentSubtypeTemp, EmploymentDataEmploymentSubtypeSeasonal, EmploymentDataEmploymentSubtypeIndividualContractor: + return true + } + return false +} + // The main employment type of the individual. type EmploymentDataEmploymentType string @@ -217,6 +225,14 @@ const ( EmploymentDataEmploymentTypeContractor EmploymentDataEmploymentType = "contractor" ) +func (r EmploymentDataEmploymentType) IsKnown() bool { + switch r { + case EmploymentDataEmploymentTypeEmployee, EmploymentDataEmploymentTypeContractor: + return true + } + return false +} + // The manager object representing the manager of the individual within the org. type EmploymentDataManager struct { // A stable Finch `id` (UUID v4) for an individual in the company. diff --git a/hrisindividual.go b/hrisindividual.go index 3494405..0909d05 100644 --- a/hrisindividual.go +++ b/hrisindividual.go @@ -139,6 +139,14 @@ const ( IndividualEmailsTypePersonal IndividualEmailsType = "personal" ) +func (r IndividualEmailsType) IsKnown() bool { + switch r { + case IndividualEmailsTypeWork, IndividualEmailsTypePersonal: + return true + } + return false +} + // The EEOC-defined ethnicity of the individual. type IndividualEthnicity string @@ -153,6 +161,14 @@ const ( IndividualEthnicityDeclineToSpecify IndividualEthnicity = "decline_to_specify" ) +func (r IndividualEthnicity) IsKnown() bool { + switch r { + case IndividualEthnicityAsian, IndividualEthnicityWhite, IndividualEthnicityBlackOrAfricanAmerican, IndividualEthnicityNativeHawaiianOrPacificIslander, IndividualEthnicityAmericanIndianOrAlaskaNative, IndividualEthnicityHispanicOrLatino, IndividualEthnicityTwoOrMoreRaces, IndividualEthnicityDeclineToSpecify: + return true + } + return false +} + // The gender of the individual. type IndividualGender string @@ -163,6 +179,14 @@ const ( IndividualGenderDeclineToSpecify IndividualGender = "decline_to_specify" ) +func (r IndividualGender) IsKnown() bool { + switch r { + case IndividualGenderFemale, IndividualGenderMale, IndividualGenderOther, IndividualGenderDeclineToSpecify: + return true + } + return false +} + type IndividualPhoneNumber struct { Data string `json:"data,nullable"` Type IndividualPhoneNumbersType `json:"type,nullable"` @@ -193,6 +217,14 @@ const ( IndividualPhoneNumbersTypePersonal IndividualPhoneNumbersType = "personal" ) +func (r IndividualPhoneNumbersType) IsKnown() bool { + switch r { + case IndividualPhoneNumbersTypeWork, IndividualPhoneNumbersTypePersonal: + return true + } + return false +} + type IndividualResponse struct { Body Individual `json:"body"` Code int64 `json:"code"` diff --git a/hrispaystatement.go b/hrispaystatement.go index 5ec6bfc..500a739 100644 --- a/hrispaystatement.go +++ b/hrispaystatement.go @@ -159,6 +159,14 @@ const ( PayStatementEarningsTypeOther PayStatementEarningsType = "other" ) +func (r PayStatementEarningsType) IsKnown() bool { + switch r { + case PayStatementEarningsTypeSalary, PayStatementEarningsTypeWage, PayStatementEarningsTypeReimbursement, PayStatementEarningsTypeOvertime, PayStatementEarningsTypeSeverance, PayStatementEarningsTypeDoubleOvertime, PayStatementEarningsTypePto, PayStatementEarningsTypeSick, PayStatementEarningsTypeBonus, PayStatementEarningsTypeCommission, PayStatementEarningsTypeTips, PayStatementEarningsType1099, PayStatementEarningsTypeOther: + return true + } + return false +} + type PayStatementEmployeeDeduction struct { // The deduction amount in cents. Amount int64 `json:"amount,nullable"` @@ -232,6 +240,14 @@ const ( PayStatementPaymentMethodDirectDeposit PayStatementPaymentMethod = "direct_deposit" ) +func (r PayStatementPaymentMethod) IsKnown() bool { + switch r { + case PayStatementPaymentMethodCheck, PayStatementPaymentMethodDirectDeposit: + return true + } + return false +} + type PayStatementTax struct { // The tax amount in cents. Amount int64 `json:"amount,nullable"` @@ -275,6 +291,14 @@ const ( PayStatementTaxesTypeFica PayStatementTaxesType = "fica" ) +func (r PayStatementTaxesType) IsKnown() bool { + switch r { + case PayStatementTaxesTypeState, PayStatementTaxesTypeFederal, PayStatementTaxesTypeLocal, PayStatementTaxesTypeFica: + return true + } + return false +} + // The type of the payment associated with the pay statement. type PayStatementType string @@ -284,6 +308,14 @@ const ( PayStatementTypeOneTimePayment PayStatementType = "one_time_payment" ) +func (r PayStatementType) IsKnown() bool { + switch r { + case PayStatementTypeRegularPayroll, PayStatementTypeOffCyclePayroll, PayStatementTypeOneTimePayment: + return true + } + return false +} + type PayStatementResponse struct { Body PayStatementResponseBody `json:"body"` Code int64 `json:"code"` diff --git a/internal/shared/shared.go b/internal/shared/shared.go index 2c4815f..0a173ff 100644 --- a/internal/shared/shared.go +++ b/internal/shared/shared.go @@ -17,6 +17,14 @@ const ( ConnectionStatusTypeReauth ConnectionStatusType = "reauth" ) +func (r ConnectionStatusType) IsKnown() bool { + switch r { + case ConnectionStatusTypePending, ConnectionStatusTypeProcessing, ConnectionStatusTypeConnected, ConnectionStatusTypeErrorNoAccountSetup, ConnectionStatusTypeErrorPermissions, ConnectionStatusTypeReauth: + return true + } + return false +} + // - `supported`: This operation is supported by both the provider and Finch // // - `not_supported_by_finch`: This operation is not supported by Finch but @@ -36,6 +44,14 @@ const ( OperationSupportClientAccessOnly OperationSupport = "client_access_only" ) +func (r OperationSupport) IsKnown() bool { + switch r { + case OperationSupportSupported, OperationSupportNotSupportedByFinch, OperationSupportNotSupportedByProvider, OperationSupportClientAccessOnly: + return true + } + return false +} + type OperationSupportMatrix struct { // - `supported`: This operation is supported by both the provider and Finch // diff --git a/jobautomated.go b/jobautomated.go index b20df62..9119827 100644 --- a/jobautomated.go +++ b/jobautomated.go @@ -143,6 +143,14 @@ const ( AutomatedAsyncJobStatusPermissionsError AutomatedAsyncJobStatus = "permissions_error" ) +func (r AutomatedAsyncJobStatus) IsKnown() bool { + switch r { + case AutomatedAsyncJobStatusPending, AutomatedAsyncJobStatusInProgress, AutomatedAsyncJobStatusComplete, AutomatedAsyncJobStatusError, AutomatedAsyncJobStatusReauthError, AutomatedAsyncJobStatusPermissionsError: + return true + } + return false +} + // Only `data_sync_all` currently supported type AutomatedAsyncJobType string @@ -150,6 +158,14 @@ const ( AutomatedAsyncJobTypeDataSyncAll AutomatedAsyncJobType = "data_sync_all" ) +func (r AutomatedAsyncJobType) IsKnown() bool { + switch r { + case AutomatedAsyncJobTypeDataSyncAll: + return true + } + return false +} + type JobAutomatedNewResponse struct { // The number of allowed refreshes per hour (per hour, fixed window) AllowedRefreshes int64 `json:"allowed_refreshes,required"` @@ -197,6 +213,14 @@ const ( JobAutomatedNewParamsTypeDataSyncAll JobAutomatedNewParamsType = "data_sync_all" ) +func (r JobAutomatedNewParamsType) IsKnown() bool { + switch r { + case JobAutomatedNewParamsTypeDataSyncAll: + return true + } + return false +} + type JobAutomatedListParams struct { // Number of items to return Limit param.Field[int64] `query:"limit"` diff --git a/jobmanual.go b/jobmanual.go index ab74c23..5de092c 100644 --- a/jobmanual.go +++ b/jobmanual.go @@ -71,3 +71,11 @@ const ( ManualAsyncJobStatusError ManualAsyncJobStatus = "error" ManualAsyncJobStatusComplete ManualAsyncJobStatus = "complete" ) + +func (r ManualAsyncJobStatus) IsKnown() bool { + switch r { + case ManualAsyncJobStatusPending, ManualAsyncJobStatusInProgress, ManualAsyncJobStatusError, ManualAsyncJobStatusComplete: + return true + } + return false +} diff --git a/provider.go b/provider.go index 94be634..55637ee 100644 --- a/provider.go +++ b/provider.go @@ -1039,3 +1039,11 @@ const ( ProviderAuthenticationMethodsTypeAPICredential ProviderAuthenticationMethodsType = "api_credential" ProviderAuthenticationMethodsTypeOAuth ProviderAuthenticationMethodsType = "oauth" ) + +func (r ProviderAuthenticationMethodsType) IsKnown() bool { + switch r { + case ProviderAuthenticationMethodsTypeAssisted, ProviderAuthenticationMethodsTypeCredential, ProviderAuthenticationMethodsTypeAPIToken, ProviderAuthenticationMethodsTypeAPICredential, ProviderAuthenticationMethodsTypeOAuth: + return true + } + return false +} diff --git a/sandboxcompany.go b/sandboxcompany.go index cc47fd7..9cd8ca3 100644 --- a/sandboxcompany.go +++ b/sandboxcompany.go @@ -122,6 +122,14 @@ const ( SandboxCompanyUpdateResponseAccountsAccountTypeSavings SandboxCompanyUpdateResponseAccountsAccountType = "savings" ) +func (r SandboxCompanyUpdateResponseAccountsAccountType) IsKnown() bool { + switch r { + case SandboxCompanyUpdateResponseAccountsAccountTypeChecking, SandboxCompanyUpdateResponseAccountsAccountTypeSavings: + return true + } + return false +} + type SandboxCompanyUpdateResponseDepartment struct { // The department name. Name string `json:"name,nullable"` @@ -205,6 +213,14 @@ const ( SandboxCompanyUpdateResponseEntitySubtypeBCorporation SandboxCompanyUpdateResponseEntitySubtype = "b_corporation" ) +func (r SandboxCompanyUpdateResponseEntitySubtype) IsKnown() bool { + switch r { + case SandboxCompanyUpdateResponseEntitySubtypeSCorporation, SandboxCompanyUpdateResponseEntitySubtypeCCorporation, SandboxCompanyUpdateResponseEntitySubtypeBCorporation: + return true + } + return false +} + // The tax payer type of the company. type SandboxCompanyUpdateResponseEntityType string @@ -218,6 +234,14 @@ const ( SandboxCompanyUpdateResponseEntityTypeCooperative SandboxCompanyUpdateResponseEntityType = "cooperative" ) +func (r SandboxCompanyUpdateResponseEntityType) IsKnown() bool { + switch r { + case SandboxCompanyUpdateResponseEntityTypeLlc, SandboxCompanyUpdateResponseEntityTypeLp, SandboxCompanyUpdateResponseEntityTypeCorporation, SandboxCompanyUpdateResponseEntityTypeSoleProprietor, SandboxCompanyUpdateResponseEntityTypeNonProfit, SandboxCompanyUpdateResponseEntityTypePartnership, SandboxCompanyUpdateResponseEntityTypeCooperative: + return true + } + return false +} + type SandboxCompanyUpdateParams struct { // An array of bank account objects associated with the payroll/HRIS system. Accounts param.Field[[]SandboxCompanyUpdateParamsAccount] `json:"accounts,required"` @@ -266,6 +290,14 @@ const ( SandboxCompanyUpdateParamsAccountsAccountTypeSavings SandboxCompanyUpdateParamsAccountsAccountType = "savings" ) +func (r SandboxCompanyUpdateParamsAccountsAccountType) IsKnown() bool { + switch r { + case SandboxCompanyUpdateParamsAccountsAccountTypeChecking, SandboxCompanyUpdateParamsAccountsAccountTypeSavings: + return true + } + return false +} + type SandboxCompanyUpdateParamsDepartment struct { // The department name. Name param.Field[string] `json:"name"` @@ -308,6 +340,14 @@ const ( SandboxCompanyUpdateParamsEntitySubtypeBCorporation SandboxCompanyUpdateParamsEntitySubtype = "b_corporation" ) +func (r SandboxCompanyUpdateParamsEntitySubtype) IsKnown() bool { + switch r { + case SandboxCompanyUpdateParamsEntitySubtypeSCorporation, SandboxCompanyUpdateParamsEntitySubtypeCCorporation, SandboxCompanyUpdateParamsEntitySubtypeBCorporation: + return true + } + return false +} + // The tax payer type of the company. type SandboxCompanyUpdateParamsEntityType string @@ -320,3 +360,11 @@ const ( SandboxCompanyUpdateParamsEntityTypePartnership SandboxCompanyUpdateParamsEntityType = "partnership" SandboxCompanyUpdateParamsEntityTypeCooperative SandboxCompanyUpdateParamsEntityType = "cooperative" ) + +func (r SandboxCompanyUpdateParamsEntityType) IsKnown() bool { + switch r { + case SandboxCompanyUpdateParamsEntityTypeLlc, SandboxCompanyUpdateParamsEntityTypeLp, SandboxCompanyUpdateParamsEntityTypeCorporation, SandboxCompanyUpdateParamsEntityTypeSoleProprietor, SandboxCompanyUpdateParamsEntityTypeNonProfit, SandboxCompanyUpdateParamsEntityTypePartnership, SandboxCompanyUpdateParamsEntityTypeCooperative: + return true + } + return false +} diff --git a/sandboxconnection.go b/sandboxconnection.go index 2523686..277cd75 100644 --- a/sandboxconnection.go +++ b/sandboxconnection.go @@ -80,6 +80,14 @@ const ( SandboxConnectionNewResponseAuthenticationTypeAssisted SandboxConnectionNewResponseAuthenticationType = "assisted" ) +func (r SandboxConnectionNewResponseAuthenticationType) IsKnown() bool { + switch r { + case SandboxConnectionNewResponseAuthenticationTypeCredential, SandboxConnectionNewResponseAuthenticationTypeAPIToken, SandboxConnectionNewResponseAuthenticationTypeOAuth, SandboxConnectionNewResponseAuthenticationTypeAssisted: + return true + } + return false +} + type SandboxConnectionNewParams struct { ProviderID param.Field[string] `json:"provider_id,required"` AuthenticationType param.Field[SandboxConnectionNewParamsAuthenticationType] `json:"authentication_type"` @@ -101,3 +109,11 @@ const ( SandboxConnectionNewParamsAuthenticationTypeOAuth SandboxConnectionNewParamsAuthenticationType = "oauth" SandboxConnectionNewParamsAuthenticationTypeAssisted SandboxConnectionNewParamsAuthenticationType = "assisted" ) + +func (r SandboxConnectionNewParamsAuthenticationType) IsKnown() bool { + switch r { + case SandboxConnectionNewParamsAuthenticationTypeCredential, SandboxConnectionNewParamsAuthenticationTypeAPIToken, SandboxConnectionNewParamsAuthenticationTypeOAuth, SandboxConnectionNewParamsAuthenticationTypeAssisted: + return true + } + return false +} diff --git a/sandboxconnectionaccount.go b/sandboxconnectionaccount.go index 76c49ad..17a990e 100644 --- a/sandboxconnectionaccount.go +++ b/sandboxconnectionaccount.go @@ -88,6 +88,14 @@ const ( SandboxConnectionAccountNewResponseAuthenticationTypeAssisted SandboxConnectionAccountNewResponseAuthenticationType = "assisted" ) +func (r SandboxConnectionAccountNewResponseAuthenticationType) IsKnown() bool { + switch r { + case SandboxConnectionAccountNewResponseAuthenticationTypeCredential, SandboxConnectionAccountNewResponseAuthenticationTypeAPIToken, SandboxConnectionAccountNewResponseAuthenticationTypeOAuth, SandboxConnectionAccountNewResponseAuthenticationTypeAssisted: + return true + } + return false +} + type SandboxConnectionAccountUpdateResponse struct { AccountID string `json:"account_id,required"` AuthenticationType SandboxConnectionAccountUpdateResponseAuthenticationType `json:"authentication_type,required"` @@ -126,6 +134,14 @@ const ( SandboxConnectionAccountUpdateResponseAuthenticationTypeAssisted SandboxConnectionAccountUpdateResponseAuthenticationType = "assisted" ) +func (r SandboxConnectionAccountUpdateResponseAuthenticationType) IsKnown() bool { + switch r { + case SandboxConnectionAccountUpdateResponseAuthenticationTypeCredential, SandboxConnectionAccountUpdateResponseAuthenticationTypeAPIToken, SandboxConnectionAccountUpdateResponseAuthenticationTypeOAuth, SandboxConnectionAccountUpdateResponseAuthenticationTypeAssisted: + return true + } + return false +} + type SandboxConnectionAccountNewParams struct { CompanyID param.Field[string] `json:"company_id,required" format:"uuid"` ProviderID param.Field[string] `json:"provider_id,required"` @@ -148,6 +164,14 @@ const ( SandboxConnectionAccountNewParamsAuthenticationTypeAssisted SandboxConnectionAccountNewParamsAuthenticationType = "assisted" ) +func (r SandboxConnectionAccountNewParamsAuthenticationType) IsKnown() bool { + switch r { + case SandboxConnectionAccountNewParamsAuthenticationTypeCredential, SandboxConnectionAccountNewParamsAuthenticationTypeAPIToken, SandboxConnectionAccountNewParamsAuthenticationTypeOAuth, SandboxConnectionAccountNewParamsAuthenticationTypeAssisted: + return true + } + return false +} + type SandboxConnectionAccountUpdateParams struct { ConnectionStatus param.Field[shared.ConnectionStatusType] `json:"connection_status"` } diff --git a/sandboxdirectory.go b/sandboxdirectory.go index 37b2d97..bc04c3e 100644 --- a/sandboxdirectory.go +++ b/sandboxdirectory.go @@ -143,6 +143,14 @@ const ( SandboxDirectoryNewParamsBodyEmailsTypePersonal SandboxDirectoryNewParamsBodyEmailsType = "personal" ) +func (r SandboxDirectoryNewParamsBodyEmailsType) IsKnown() bool { + switch r { + case SandboxDirectoryNewParamsBodyEmailsTypeWork, SandboxDirectoryNewParamsBodyEmailsTypePersonal: + return true + } + return false +} + // The employment object. type SandboxDirectoryNewParamsBodyEmployment struct { // The secondary employment type of the individual. Options: `full_time`, `part_time`, `intern`, `temp`, `seasonal` and `individual_contractor`. @@ -167,6 +175,14 @@ const ( SandboxDirectoryNewParamsBodyEmploymentSubtypeIndividualContractor SandboxDirectoryNewParamsBodyEmploymentSubtype = "individual_contractor" ) +func (r SandboxDirectoryNewParamsBodyEmploymentSubtype) IsKnown() bool { + switch r { + case SandboxDirectoryNewParamsBodyEmploymentSubtypeFullTime, SandboxDirectoryNewParamsBodyEmploymentSubtypeIntern, SandboxDirectoryNewParamsBodyEmploymentSubtypePartTime, SandboxDirectoryNewParamsBodyEmploymentSubtypeTemp, SandboxDirectoryNewParamsBodyEmploymentSubtypeSeasonal, SandboxDirectoryNewParamsBodyEmploymentSubtypeIndividualContractor: + return true + } + return false +} + // The main employment type of the individual. type SandboxDirectoryNewParamsBodyEmploymentType string @@ -175,6 +191,14 @@ const ( SandboxDirectoryNewParamsBodyEmploymentTypeContractor SandboxDirectoryNewParamsBodyEmploymentType = "contractor" ) +func (r SandboxDirectoryNewParamsBodyEmploymentType) IsKnown() bool { + switch r { + case SandboxDirectoryNewParamsBodyEmploymentTypeEmployee, SandboxDirectoryNewParamsBodyEmploymentTypeContractor: + return true + } + return false +} + // The EEOC-defined ethnicity of the individual. type SandboxDirectoryNewParamsBodyEthnicity string @@ -189,6 +213,14 @@ const ( SandboxDirectoryNewParamsBodyEthnicityDeclineToSpecify SandboxDirectoryNewParamsBodyEthnicity = "decline_to_specify" ) +func (r SandboxDirectoryNewParamsBodyEthnicity) IsKnown() bool { + switch r { + case SandboxDirectoryNewParamsBodyEthnicityAsian, SandboxDirectoryNewParamsBodyEthnicityWhite, SandboxDirectoryNewParamsBodyEthnicityBlackOrAfricanAmerican, SandboxDirectoryNewParamsBodyEthnicityNativeHawaiianOrPacificIslander, SandboxDirectoryNewParamsBodyEthnicityAmericanIndianOrAlaskaNative, SandboxDirectoryNewParamsBodyEthnicityHispanicOrLatino, SandboxDirectoryNewParamsBodyEthnicityTwoOrMoreRaces, SandboxDirectoryNewParamsBodyEthnicityDeclineToSpecify: + return true + } + return false +} + // The gender of the individual. type SandboxDirectoryNewParamsBodyGender string @@ -199,6 +231,14 @@ const ( SandboxDirectoryNewParamsBodyGenderDeclineToSpecify SandboxDirectoryNewParamsBodyGender = "decline_to_specify" ) +func (r SandboxDirectoryNewParamsBodyGender) IsKnown() bool { + switch r { + case SandboxDirectoryNewParamsBodyGenderFemale, SandboxDirectoryNewParamsBodyGenderMale, SandboxDirectoryNewParamsBodyGenderOther, SandboxDirectoryNewParamsBodyGenderDeclineToSpecify: + return true + } + return false +} + // The manager object representing the manager of the individual within the org. type SandboxDirectoryNewParamsBodyManager struct { // A stable Finch `id` (UUID v4) for an individual in the company. @@ -224,3 +264,11 @@ const ( SandboxDirectoryNewParamsBodyPhoneNumbersTypeWork SandboxDirectoryNewParamsBodyPhoneNumbersType = "work" SandboxDirectoryNewParamsBodyPhoneNumbersTypePersonal SandboxDirectoryNewParamsBodyPhoneNumbersType = "personal" ) + +func (r SandboxDirectoryNewParamsBodyPhoneNumbersType) IsKnown() bool { + switch r { + case SandboxDirectoryNewParamsBodyPhoneNumbersTypeWork, SandboxDirectoryNewParamsBodyPhoneNumbersTypePersonal: + return true + } + return false +} diff --git a/sandboxemployment.go b/sandboxemployment.go index 0218ad5..f03ba1d 100644 --- a/sandboxemployment.go +++ b/sandboxemployment.go @@ -194,6 +194,14 @@ const ( SandboxEmploymentUpdateResponseEmploymentSubtypeIndividualContractor SandboxEmploymentUpdateResponseEmploymentSubtype = "individual_contractor" ) +func (r SandboxEmploymentUpdateResponseEmploymentSubtype) IsKnown() bool { + switch r { + case SandboxEmploymentUpdateResponseEmploymentSubtypeFullTime, SandboxEmploymentUpdateResponseEmploymentSubtypeIntern, SandboxEmploymentUpdateResponseEmploymentSubtypePartTime, SandboxEmploymentUpdateResponseEmploymentSubtypeTemp, SandboxEmploymentUpdateResponseEmploymentSubtypeSeasonal, SandboxEmploymentUpdateResponseEmploymentSubtypeIndividualContractor: + return true + } + return false +} + // The main employment type of the individual. type SandboxEmploymentUpdateResponseEmploymentType string @@ -202,6 +210,14 @@ const ( SandboxEmploymentUpdateResponseEmploymentTypeContractor SandboxEmploymentUpdateResponseEmploymentType = "contractor" ) +func (r SandboxEmploymentUpdateResponseEmploymentType) IsKnown() bool { + switch r { + case SandboxEmploymentUpdateResponseEmploymentTypeEmployee, SandboxEmploymentUpdateResponseEmploymentTypeContractor: + return true + } + return false +} + // The manager object representing the manager of the individual within the org. type SandboxEmploymentUpdateResponseManager struct { // A stable Finch `id` (UUID v4) for an individual in the company. @@ -308,6 +324,14 @@ const ( SandboxEmploymentUpdateParamsEmploymentSubtypeIndividualContractor SandboxEmploymentUpdateParamsEmploymentSubtype = "individual_contractor" ) +func (r SandboxEmploymentUpdateParamsEmploymentSubtype) IsKnown() bool { + switch r { + case SandboxEmploymentUpdateParamsEmploymentSubtypeFullTime, SandboxEmploymentUpdateParamsEmploymentSubtypeIntern, SandboxEmploymentUpdateParamsEmploymentSubtypePartTime, SandboxEmploymentUpdateParamsEmploymentSubtypeTemp, SandboxEmploymentUpdateParamsEmploymentSubtypeSeasonal, SandboxEmploymentUpdateParamsEmploymentSubtypeIndividualContractor: + return true + } + return false +} + // The main employment type of the individual. type SandboxEmploymentUpdateParamsEmploymentType string @@ -316,6 +340,14 @@ const ( SandboxEmploymentUpdateParamsEmploymentTypeContractor SandboxEmploymentUpdateParamsEmploymentType = "contractor" ) +func (r SandboxEmploymentUpdateParamsEmploymentType) IsKnown() bool { + switch r { + case SandboxEmploymentUpdateParamsEmploymentTypeEmployee, SandboxEmploymentUpdateParamsEmploymentTypeContractor: + return true + } + return false +} + // The manager object representing the manager of the individual within the org. type SandboxEmploymentUpdateParamsManager struct { // A stable Finch `id` (UUID v4) for an individual in the company. diff --git a/sandboxindividual.go b/sandboxindividual.go index 34726d6..950c07e 100644 --- a/sandboxindividual.go +++ b/sandboxindividual.go @@ -127,6 +127,14 @@ const ( SandboxIndividualUpdateResponseEmailsTypePersonal SandboxIndividualUpdateResponseEmailsType = "personal" ) +func (r SandboxIndividualUpdateResponseEmailsType) IsKnown() bool { + switch r { + case SandboxIndividualUpdateResponseEmailsTypeWork, SandboxIndividualUpdateResponseEmailsTypePersonal: + return true + } + return false +} + // The EEOC-defined ethnicity of the individual. type SandboxIndividualUpdateResponseEthnicity string @@ -141,6 +149,14 @@ const ( SandboxIndividualUpdateResponseEthnicityDeclineToSpecify SandboxIndividualUpdateResponseEthnicity = "decline_to_specify" ) +func (r SandboxIndividualUpdateResponseEthnicity) IsKnown() bool { + switch r { + case SandboxIndividualUpdateResponseEthnicityAsian, SandboxIndividualUpdateResponseEthnicityWhite, SandboxIndividualUpdateResponseEthnicityBlackOrAfricanAmerican, SandboxIndividualUpdateResponseEthnicityNativeHawaiianOrPacificIslander, SandboxIndividualUpdateResponseEthnicityAmericanIndianOrAlaskaNative, SandboxIndividualUpdateResponseEthnicityHispanicOrLatino, SandboxIndividualUpdateResponseEthnicityTwoOrMoreRaces, SandboxIndividualUpdateResponseEthnicityDeclineToSpecify: + return true + } + return false +} + // The gender of the individual. type SandboxIndividualUpdateResponseGender string @@ -151,6 +167,14 @@ const ( SandboxIndividualUpdateResponseGenderDeclineToSpecify SandboxIndividualUpdateResponseGender = "decline_to_specify" ) +func (r SandboxIndividualUpdateResponseGender) IsKnown() bool { + switch r { + case SandboxIndividualUpdateResponseGenderFemale, SandboxIndividualUpdateResponseGenderMale, SandboxIndividualUpdateResponseGenderOther, SandboxIndividualUpdateResponseGenderDeclineToSpecify: + return true + } + return false +} + type SandboxIndividualUpdateResponsePhoneNumber struct { Data string `json:"data"` Type SandboxIndividualUpdateResponsePhoneNumbersType `json:"type"` @@ -181,6 +205,14 @@ const ( SandboxIndividualUpdateResponsePhoneNumbersTypePersonal SandboxIndividualUpdateResponsePhoneNumbersType = "personal" ) +func (r SandboxIndividualUpdateResponsePhoneNumbersType) IsKnown() bool { + switch r { + case SandboxIndividualUpdateResponsePhoneNumbersTypeWork, SandboxIndividualUpdateResponsePhoneNumbersTypePersonal: + return true + } + return false +} + type SandboxIndividualUpdateParams struct { Dob param.Field[string] `json:"dob"` Emails param.Field[[]SandboxIndividualUpdateParamsEmail] `json:"emails"` @@ -228,6 +260,14 @@ const ( SandboxIndividualUpdateParamsEmailsTypePersonal SandboxIndividualUpdateParamsEmailsType = "personal" ) +func (r SandboxIndividualUpdateParamsEmailsType) IsKnown() bool { + switch r { + case SandboxIndividualUpdateParamsEmailsTypeWork, SandboxIndividualUpdateParamsEmailsTypePersonal: + return true + } + return false +} + // The EEOC-defined ethnicity of the individual. type SandboxIndividualUpdateParamsEthnicity string @@ -242,6 +282,14 @@ const ( SandboxIndividualUpdateParamsEthnicityDeclineToSpecify SandboxIndividualUpdateParamsEthnicity = "decline_to_specify" ) +func (r SandboxIndividualUpdateParamsEthnicity) IsKnown() bool { + switch r { + case SandboxIndividualUpdateParamsEthnicityAsian, SandboxIndividualUpdateParamsEthnicityWhite, SandboxIndividualUpdateParamsEthnicityBlackOrAfricanAmerican, SandboxIndividualUpdateParamsEthnicityNativeHawaiianOrPacificIslander, SandboxIndividualUpdateParamsEthnicityAmericanIndianOrAlaskaNative, SandboxIndividualUpdateParamsEthnicityHispanicOrLatino, SandboxIndividualUpdateParamsEthnicityTwoOrMoreRaces, SandboxIndividualUpdateParamsEthnicityDeclineToSpecify: + return true + } + return false +} + // The gender of the individual. type SandboxIndividualUpdateParamsGender string @@ -252,6 +300,14 @@ const ( SandboxIndividualUpdateParamsGenderDeclineToSpecify SandboxIndividualUpdateParamsGender = "decline_to_specify" ) +func (r SandboxIndividualUpdateParamsGender) IsKnown() bool { + switch r { + case SandboxIndividualUpdateParamsGenderFemale, SandboxIndividualUpdateParamsGenderMale, SandboxIndividualUpdateParamsGenderOther, SandboxIndividualUpdateParamsGenderDeclineToSpecify: + return true + } + return false +} + type SandboxIndividualUpdateParamsPhoneNumber struct { Data param.Field[string] `json:"data"` Type param.Field[SandboxIndividualUpdateParamsPhoneNumbersType] `json:"type"` @@ -267,3 +323,11 @@ const ( SandboxIndividualUpdateParamsPhoneNumbersTypeWork SandboxIndividualUpdateParamsPhoneNumbersType = "work" SandboxIndividualUpdateParamsPhoneNumbersTypePersonal SandboxIndividualUpdateParamsPhoneNumbersType = "personal" ) + +func (r SandboxIndividualUpdateParamsPhoneNumbersType) IsKnown() bool { + switch r { + case SandboxIndividualUpdateParamsPhoneNumbersTypeWork, SandboxIndividualUpdateParamsPhoneNumbersTypePersonal: + return true + } + return false +} diff --git a/sandboxjob.go b/sandboxjob.go index 0b5976e..598678d 100644 --- a/sandboxjob.go +++ b/sandboxjob.go @@ -85,3 +85,11 @@ type SandboxJobNewParamsType string const ( SandboxJobNewParamsTypeDataSyncAll SandboxJobNewParamsType = "data_sync_all" ) + +func (r SandboxJobNewParamsType) IsKnown() bool { + switch r { + case SandboxJobNewParamsTypeDataSyncAll: + return true + } + return false +} diff --git a/sandboxjobconfiguration.go b/sandboxjobconfiguration.go index 38899fe..1e00e58 100644 --- a/sandboxjobconfiguration.go +++ b/sandboxjobconfiguration.go @@ -78,12 +78,28 @@ const ( SandboxJobConfigurationCompletionStatusError SandboxJobConfigurationCompletionStatus = "error" ) +func (r SandboxJobConfigurationCompletionStatus) IsKnown() bool { + switch r { + case SandboxJobConfigurationCompletionStatusComplete, SandboxJobConfigurationCompletionStatusReauthError, SandboxJobConfigurationCompletionStatusPermissionsError, SandboxJobConfigurationCompletionStatusError: + return true + } + return false +} + type SandboxJobConfigurationType string const ( SandboxJobConfigurationTypeDataSyncAll SandboxJobConfigurationType = "data_sync_all" ) +func (r SandboxJobConfigurationType) IsKnown() bool { + switch r { + case SandboxJobConfigurationTypeDataSyncAll: + return true + } + return false +} + type SandboxJobConfigurationUpdateParams struct { CompletionStatus param.Field[SandboxJobConfigurationUpdateParamsCompletionStatus] `json:"completion_status,required"` Type param.Field[SandboxJobConfigurationUpdateParamsType] `json:"type,required"` @@ -102,8 +118,24 @@ const ( SandboxJobConfigurationUpdateParamsCompletionStatusError SandboxJobConfigurationUpdateParamsCompletionStatus = "error" ) +func (r SandboxJobConfigurationUpdateParamsCompletionStatus) IsKnown() bool { + switch r { + case SandboxJobConfigurationUpdateParamsCompletionStatusComplete, SandboxJobConfigurationUpdateParamsCompletionStatusReauthError, SandboxJobConfigurationUpdateParamsCompletionStatusPermissionsError, SandboxJobConfigurationUpdateParamsCompletionStatusError: + return true + } + return false +} + type SandboxJobConfigurationUpdateParamsType string const ( SandboxJobConfigurationUpdateParamsTypeDataSyncAll SandboxJobConfigurationUpdateParamsType = "data_sync_all" ) + +func (r SandboxJobConfigurationUpdateParamsType) IsKnown() bool { + switch r { + case SandboxJobConfigurationUpdateParamsTypeDataSyncAll: + return true + } + return false +} diff --git a/sandboxpayment.go b/sandboxpayment.go index 1781015..b4a04c8 100644 --- a/sandboxpayment.go +++ b/sandboxpayment.go @@ -133,6 +133,14 @@ const ( SandboxPaymentNewParamsPayStatementsEarningsTypeOther SandboxPaymentNewParamsPayStatementsEarningsType = "other" ) +func (r SandboxPaymentNewParamsPayStatementsEarningsType) IsKnown() bool { + switch r { + case SandboxPaymentNewParamsPayStatementsEarningsTypeSalary, SandboxPaymentNewParamsPayStatementsEarningsTypeWage, SandboxPaymentNewParamsPayStatementsEarningsTypeReimbursement, SandboxPaymentNewParamsPayStatementsEarningsTypeOvertime, SandboxPaymentNewParamsPayStatementsEarningsTypeSeverance, SandboxPaymentNewParamsPayStatementsEarningsTypeDoubleOvertime, SandboxPaymentNewParamsPayStatementsEarningsTypePto, SandboxPaymentNewParamsPayStatementsEarningsTypeSick, SandboxPaymentNewParamsPayStatementsEarningsTypeBonus, SandboxPaymentNewParamsPayStatementsEarningsTypeCommission, SandboxPaymentNewParamsPayStatementsEarningsTypeTips, SandboxPaymentNewParamsPayStatementsEarningsType1099, SandboxPaymentNewParamsPayStatementsEarningsTypeOther: + return true + } + return false +} + type SandboxPaymentNewParamsPayStatementsEmployeeDeduction struct { // The deduction amount in cents. Amount param.Field[int64] `json:"amount"` @@ -173,6 +181,14 @@ const ( SandboxPaymentNewParamsPayStatementsPaymentMethodDirectDeposit SandboxPaymentNewParamsPayStatementsPaymentMethod = "direct_deposit" ) +func (r SandboxPaymentNewParamsPayStatementsPaymentMethod) IsKnown() bool { + switch r { + case SandboxPaymentNewParamsPayStatementsPaymentMethodCheck, SandboxPaymentNewParamsPayStatementsPaymentMethodDirectDeposit: + return true + } + return false +} + type SandboxPaymentNewParamsPayStatementsTax struct { // The tax amount in cents. Amount param.Field[int64] `json:"amount"` @@ -200,6 +216,14 @@ const ( SandboxPaymentNewParamsPayStatementsTaxesTypeFica SandboxPaymentNewParamsPayStatementsTaxesType = "fica" ) +func (r SandboxPaymentNewParamsPayStatementsTaxesType) IsKnown() bool { + switch r { + case SandboxPaymentNewParamsPayStatementsTaxesTypeState, SandboxPaymentNewParamsPayStatementsTaxesTypeFederal, SandboxPaymentNewParamsPayStatementsTaxesTypeLocal, SandboxPaymentNewParamsPayStatementsTaxesTypeFica: + return true + } + return false +} + // The type of the payment associated with the pay statement. type SandboxPaymentNewParamsPayStatementsType string @@ -208,3 +232,11 @@ const ( SandboxPaymentNewParamsPayStatementsTypeOffCyclePayroll SandboxPaymentNewParamsPayStatementsType = "off_cycle_payroll" SandboxPaymentNewParamsPayStatementsTypeOneTimePayment SandboxPaymentNewParamsPayStatementsType = "one_time_payment" ) + +func (r SandboxPaymentNewParamsPayStatementsType) IsKnown() bool { + switch r { + case SandboxPaymentNewParamsPayStatementsTypeRegularPayroll, SandboxPaymentNewParamsPayStatementsTypeOffCyclePayroll, SandboxPaymentNewParamsPayStatementsTypeOneTimePayment: + return true + } + return false +} diff --git a/webhook.go b/webhook.go index 3e9899b..837ea89 100644 --- a/webhook.go +++ b/webhook.go @@ -1110,12 +1110,28 @@ const ( AccountUpdateEventDataAuthenticationMethodTypeOAuth AccountUpdateEventDataAuthenticationMethodType = "oauth" ) +func (r AccountUpdateEventDataAuthenticationMethodType) IsKnown() bool { + switch r { + case AccountUpdateEventDataAuthenticationMethodTypeAssisted, AccountUpdateEventDataAuthenticationMethodTypeCredential, AccountUpdateEventDataAuthenticationMethodTypeAPIToken, AccountUpdateEventDataAuthenticationMethodTypeAPICredential, AccountUpdateEventDataAuthenticationMethodTypeOAuth: + return true + } + return false +} + type AccountUpdateEventEventType string const ( AccountUpdateEventEventTypeAccountUpdated AccountUpdateEventEventType = "account.updated" ) +func (r AccountUpdateEventEventType) IsKnown() bool { + switch r { + case AccountUpdateEventEventTypeAccountUpdated: + return true + } + return false +} + type BaseWebhookEvent struct { // Unique Finch id of the employer account that was used to make this connection. AccountID string `json:"account_id,required"` @@ -1172,6 +1188,14 @@ const ( CompanyEventEventTypeCompanyUpdated CompanyEventEventType = "company.updated" ) +func (r CompanyEventEventType) IsKnown() bool { + switch r { + case CompanyEventEventTypeCompanyUpdated: + return true + } + return false +} + type DirectoryEvent struct { Data DirectoryEventData `json:"data"` EventType DirectoryEventEventType `json:"event_type"` @@ -1227,6 +1251,14 @@ const ( DirectoryEventEventTypeDirectoryDeleted DirectoryEventEventType = "directory.deleted" ) +func (r DirectoryEventEventType) IsKnown() bool { + switch r { + case DirectoryEventEventTypeDirectoryCreated, DirectoryEventEventTypeDirectoryUpdated, DirectoryEventEventTypeDirectoryDeleted: + return true + } + return false +} + type EmploymentEvent struct { Data EmploymentEventData `json:"data"` EventType EmploymentEventEventType `json:"event_type"` @@ -1282,6 +1314,14 @@ const ( EmploymentEventEventTypeEmploymentDeleted EmploymentEventEventType = "employment.deleted" ) +func (r EmploymentEventEventType) IsKnown() bool { + switch r { + case EmploymentEventEventTypeEmploymentCreated, EmploymentEventEventTypeEmploymentUpdated, EmploymentEventEventTypeEmploymentDeleted: + return true + } + return false +} + type IndividualEvent struct { Data IndividualEventData `json:"data"` EventType IndividualEventEventType `json:"event_type"` @@ -1337,6 +1377,14 @@ const ( IndividualEventEventTypeIndividualDeleted IndividualEventEventType = "individual.deleted" ) +func (r IndividualEventEventType) IsKnown() bool { + switch r { + case IndividualEventEventTypeIndividualCreated, IndividualEventEventTypeIndividualUpdated, IndividualEventEventTypeIndividualDeleted: + return true + } + return false +} + type JobCompletionEvent struct { Data JobCompletionEventData `json:"data"` EventType JobCompletionEventEventType `json:"event_type"` @@ -1399,6 +1447,14 @@ const ( JobCompletionEventEventTypeJobDataSyncAllUpdated JobCompletionEventEventType = "job.data_sync_all.updated" ) +func (r JobCompletionEventEventType) IsKnown() bool { + switch r { + case JobCompletionEventEventTypeJobBenefitCreateUpdated, JobCompletionEventEventTypeJobBenefitEnrollUpdated, JobCompletionEventEventTypeJobBenefitRegisterUpdated, JobCompletionEventEventTypeJobBenefitUnenrollUpdated, JobCompletionEventEventTypeJobBenefitUpdateUpdated, JobCompletionEventEventTypeJobDataSyncAllUpdated: + return true + } + return false +} + type PayStatementEvent struct { Data PayStatementEventData `json:"data"` EventType PayStatementEventEventType `json:"event_type"` @@ -1458,6 +1514,14 @@ const ( PayStatementEventEventTypePayStatementDeleted PayStatementEventEventType = "pay_statement.deleted" ) +func (r PayStatementEventEventType) IsKnown() bool { + switch r { + case PayStatementEventEventTypePayStatementCreated, PayStatementEventEventTypePayStatementUpdated, PayStatementEventEventTypePayStatementDeleted: + return true + } + return false +} + type PaymentEvent struct { Data PaymentEventData `json:"data"` EventType PaymentEventEventType `json:"event_type"` @@ -1516,6 +1580,14 @@ const ( PaymentEventEventTypePaymentDeleted PaymentEventEventType = "payment.deleted" ) +func (r PaymentEventEventType) IsKnown() bool { + switch r { + case PaymentEventEventTypePaymentCreated, PaymentEventEventTypePaymentUpdated, PaymentEventEventTypePaymentDeleted: + return true + } + return false +} + // Union satisfied by [AccountUpdateEvent], [JobCompletionEvent], [CompanyEvent], // [DirectoryEvent], [EmploymentEvent], [IndividualEvent], [PaymentEvent] or // [PayStatementEvent]. From 2c2438ffd87570117e560da4dd4410c5c1cccc5b Mon Sep 17 00:00:00 2001 From: "stainless-app[bot]" <142633134+stainless-app[bot]@users.noreply.github.com> Date: Wed, 20 Mar 2024 20:00:44 +0000 Subject: [PATCH 04/11] docs(readme): consistent use of sentence case in headings (#136) --- README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 1a63072..ed558cc 100644 --- a/README.md +++ b/README.md @@ -59,7 +59,7 @@ func main() { ``` -### Request Fields +### Request fields All request parameters are wrapped in a generic `Field` type, which we use to distinguish zero values from null or omitted fields. @@ -89,7 +89,7 @@ params := FooParams{ } ``` -### Response Objects +### Response objects All fields in response structs are value types (not pointers or wrappers). @@ -289,7 +289,7 @@ You may also replace the default `http.Client` with accepted (this overwrites any previous client) and receives requests after any middleware has been applied. -## Semantic Versioning +## Semantic versioning This package generally follows [SemVer](https://semver.org/spec/v2.0.0.html) conventions, though certain backwards-incompatible changes may be released as minor versions: From 4fea46dd3dd728c5ef594a3af2faeea248d3cbbf Mon Sep 17 00:00:00 2001 From: "stainless-app[bot]" <142633134+stainless-app[bot]@users.noreply.github.com> Date: Tue, 26 Mar 2024 15:07:48 +0000 Subject: [PATCH 05/11] docs(readme): document file uploads (#137) --- README.md | 13 +++++++++++++ field.go | 15 +++++++++++++++ internal/apiform/encoder.go | 24 ++++++++++++++++++++++-- 3 files changed, 50 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index ed558cc..82bd482 100644 --- a/README.md +++ b/README.md @@ -230,6 +230,19 @@ client.HRIS.Directory.List( ) ``` +### File uploads + +Request parameters that correspond to file uploads in multipart requests are typed as +`param.Field[io.Reader]`. The contents of the `io.Reader` will by default be sent as a multipart form +part with the file name of "anonymous_file" and content-type of "application/octet-stream". + +The file name and content-type can be customized by implementing `Name() string` or `ContentType() +string` on the run-time type of `io.Reader`. Note that `os.File` implements `Name() string`, so a +file returned by `os.Open` will be sent with the file name on disk. + +We also provide a helper `finchgo.FileParam(reader io.Reader, filename string, contentType string)` +which can be used to wrap any `io.Reader` with the appropriate file name and content type. + ## Retries Certain errors will be automatically retried 2 times by default, with a short exponential backoff. diff --git a/field.go b/field.go index 48c999b..1c89174 100644 --- a/field.go +++ b/field.go @@ -2,6 +2,7 @@ package finchgo import ( "github.com/Finch-API/finch-api-go/internal/param" + "io" ) // F is a param field helper used to initialize a [param.Field] generic struct. @@ -33,3 +34,17 @@ func Float(value float64) param.Field[float64] { return F(value) } // Bool is a param field helper which helps specify bools. func Bool(value bool) param.Field[bool] { return F(value) } + +// FileParam is a param field helper which helps files with a mime content-type. +func FileParam(reader io.Reader, filename string, contentType string) param.Field[io.Reader] { + return F[io.Reader](&file{reader, filename, contentType}) +} + +type file struct { + io.Reader + name string + contentType string +} + +func (f *file) Name() string { return f.name } +func (f *file) ContentType() string { return f.contentType } diff --git a/internal/apiform/encoder.go b/internal/apiform/encoder.go index b30ca66..8f16432 100644 --- a/internal/apiform/encoder.go +++ b/internal/apiform/encoder.go @@ -4,10 +4,12 @@ import ( "fmt" "io" "mime/multipart" + "net/textproto" "path" "reflect" "sort" "strconv" + "strings" "sync" "time" @@ -302,15 +304,33 @@ func (e encoder) newInterfaceEncoder() encoderFunc { } } +var quoteEscaper = strings.NewReplacer("\\", "\\\\", `"`, "\\\"") + +func escapeQuotes(s string) string { + return quoteEscaper.Replace(s) +} + func (e *encoder) newReaderTypeEncoder() encoderFunc { return func(key string, value reflect.Value, writer *multipart.Writer) error { reader := value.Convert(reflect.TypeOf((*io.Reader)(nil)).Elem()).Interface().(io.Reader) filename := "anonymous_file" + contentType := "application/octet-stream" if named, ok := reader.(interface{ Name() string }); ok { filename = path.Base(named.Name()) } - filewriter, err := writer.CreateFormFile(key, filename) - io.Copy(filewriter, reader) + if typed, ok := reader.(interface{ ContentType() string }); ok { + contentType = path.Base(typed.ContentType()) + } + + // Below is taken almost 1-for-1 from [multipart.CreateFormFile] + h := make(textproto.MIMEHeader) + h.Set("Content-Disposition", fmt.Sprintf(`form-data; name="%s"; filename="%s"`, escapeQuotes(key), escapeQuotes(filename))) + h.Set("Content-Type", contentType) + filewriter, err := writer.CreatePart(h) + if err != nil { + return err + } + _, err = io.Copy(filewriter, reader) return err } } From da24dc425772a4ba905931de5bc231d8e90665fa Mon Sep 17 00:00:00 2001 From: "stainless-app[bot]" <142633134+stainless-app[bot]@users.noreply.github.com> Date: Tue, 26 Mar 2024 15:44:16 +0000 Subject: [PATCH 06/11] docs: fix typo in docstring for Null() (#138) --- field.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/field.go b/field.go index 1c89174..2660bbd 100644 --- a/field.go +++ b/field.go @@ -12,7 +12,7 @@ import ( // [README]: https://pkg.go.dev/github.com/Finch-API/finch-api-go#readme-request-fields func F[T any](value T) param.Field[T] { return param.Field[T]{Value: value, Present: true} } -// Null is a param field helper which explciitly sends null to the API. +// Null is a param field helper which explicitly sends null to the API. func Null[T any]() param.Field[T] { return param.Field[T]{Null: true, Present: true} } // Raw is a param field helper for specifying values for fields when the From 46f8947f7277ba5c50e91a87c485078ed32235e3 Mon Sep 17 00:00:00 2001 From: Stainless Bot <107565488+stainless-bot@users.noreply.github.com> Date: Wed, 27 Mar 2024 16:42:41 +0000 Subject: [PATCH 07/11] chore: temporary commit --- accesstoken.go | 33 ---------------- api.md | 12 ------ client.go | 86 ---------------------------------------- examples/auth/main.go | 29 -------------- finchgo.go | 12 ------ webhook.go | 92 ------------------------------------------- webhook_test.go | 28 ------------- 7 files changed, 292 deletions(-) delete mode 100644 examples/auth/main.go delete mode 100644 finchgo.go delete mode 100644 webhook_test.go diff --git a/accesstoken.go b/accesstoken.go index 07ca8ca..1b4b072 100644 --- a/accesstoken.go +++ b/accesstoken.go @@ -4,15 +4,12 @@ package finchgo import ( "context" - "errors" "net/http" "github.com/Finch-API/finch-api-go/internal/apijson" "github.com/Finch-API/finch-api-go/internal/param" "github.com/Finch-API/finch-api-go/internal/requestconfig" "github.com/Finch-API/finch-api-go/option" - "github.com/tidwall/gjson" - "github.com/tidwall/sjson" ) // AccessTokenService contains methods and other services that help with @@ -35,39 +32,9 @@ func NewAccessTokenService(opts ...option.RequestOption) (r *AccessTokenService) // Exchange the authorization code for an access token func (r *AccessTokenService) New(ctx context.Context, body AccessTokenNewParams, opts ...option.RequestOption) (res *CreateAccessTokenResponse, err error) { opts = append(r.Options[:], opts...) - - opts = append(opts[:], func(rc *requestconfig.RequestConfig) error { - bodyClientID := gjson.Get(string(rc.Buffer), "client_id") - if !bodyClientID.Exists() { - if rc.ClientID == "" { - return errors.New("client_id must be provided as an argument or with the FINCH_CLIENT_ID environment variable") - } - updatedBody, err := sjson.Set(string(rc.Buffer), "client_id", rc.ClientID) - if err != nil { - return err - } - rc.Buffer = []byte(updatedBody) - } - - bodyClientSecret := gjson.Get(string(rc.Buffer), "client_secret") - if !bodyClientSecret.Exists() { - if rc.ClientSecret == "" { - return errors.New("client_secret must be provided as an argument or with the FINCH_CLIENT_SECRET environment variable") - } - updatedBody, err := sjson.Set(string(rc.Buffer), "client_secret", rc.ClientSecret) - if err != nil { - return err - } - rc.Buffer = []byte(updatedBody) - } - - return nil - }) - path := "auth/token" err = requestconfig.ExecuteNewRequest(ctx, http.MethodPost, path, body, &res, opts...) return - } type CreateAccessTokenResponse struct { diff --git a/api.md b/api.md index fbf9806..c692f3f 100644 --- a/api.md +++ b/api.md @@ -9,13 +9,6 @@ - shared.OperationSupportMatrix - shared.Paging -# finchgo - -Methods: - -- client.GetAuthURL(products string, redirectUri string, sandbox bool, opts ...option.RequestOption) (string, error) -- client.WithAccessToken(accessToken string) (Client, error) - # AccessTokens Response Types: @@ -183,11 +176,6 @@ Response Types: - finchgo.PaymentEvent - finchgo.WebhookEvent -Methods: - -- client.Webhooks.Unwrap(payload []byte, headers http.Header, secret string, now time.Time) (WebhookEvent, error) -- client.Webhooks.VerifySignature(payload []byte, headers http.Header, secret string, now time.Time) error - # RequestForwarding Response Types: diff --git a/client.go b/client.go index 78a0d2e..22fc8b7 100644 --- a/client.go +++ b/client.go @@ -3,15 +3,8 @@ package finchgo import ( - "context" - "encoding/json" - "errors" - "net/http" - "net/url" "os" - "strconv" - "github.com/Finch-API/finch-api-go/internal/requestconfig" "github.com/Finch-API/finch-api-go/option" ) @@ -67,82 +60,3 @@ func NewClient(opts ...option.RequestOption) (r *Client) { return } - -// DEPRECATED: use client.accessTokens().create instead. -func (r *Client) GetAccessToken(ctx context.Context, code string, redirectUri string, opts ...option.RequestOption) (res string, err error) { - opts = append(r.Options[:], opts...) - opts = append(opts[:], option.WithHeaderDel("authorization")) - - path := "/auth/token" - - var result map[string]string - cfg, err := requestconfig.NewRequestConfig(ctx, http.MethodPost, path, nil, &result, opts...) - if err != nil { - return "", err - } - if cfg.ClientID == "" { - return "", errors.New("expected ClientID to be set in order to call GetAccessToken") - } - if cfg.ClientSecret == "" { - return "", errors.New("expected ClientSecret to be set in order to call GetAccessToken") - } - - body := struct { - ClientID string `json:"client_id"` - ClientSecret string `json:"client_secret"` - Code string `json:"code"` - RedirectURI string `json:"redirect_uri"` - }{ - ClientID: cfg.ClientID, - ClientSecret: cfg.ClientSecret, - Code: code, - RedirectURI: redirectUri, - } - cfg.Apply(func(rc *requestconfig.RequestConfig) (err error) { - rc.Buffer, err = json.Marshal(body) - rc.Request.Header.Set("Content-Type", "application/json") - return err - }) - - err = cfg.Execute() - if err != nil { - return "", err - } - accessToken, ok := result["access_token"] - if !ok { - return "", errors.New("access_token not found in response") - } - - return accessToken, nil -} - -// Returns the authorization URL which can be visited in order to obtain an -// authorization code from Finch. The authorization code can then be exchanged for -// an access token for the Finch API by calling getAccessToken(). -func (r *Client) GetAuthURL(products string, redirectUri string, sandbox bool, opts ...option.RequestOption) (res string, err error) { - opts = append(r.Options[:], opts...) - cfg := requestconfig.RequestConfig{} - cfg.Apply(opts...) - - if cfg.ClientID == "" { - return "", errors.New("expected the ClientID to be set in order to call GetAuthUrl") - } - u, err := url.Parse("https://connect.tryfinch.com/authorize") - if err != nil { - return "", err - } - q := u.Query() - q.Set("client_id", cfg.ClientID) - q.Set("products", products) - q.Set("redirect_uri", redirectUri) - q.Set("sandbox", strconv.FormatBool(sandbox)) - u.RawQuery = q.Encode() - return u.String(), nil -} - -// Returns a copy of the current Finch client with the given access token for -// authentication. -func (r *Client) WithAccessToken(accessToken string) (res Client, err error) { - opts := append(r.Options[:], option.WithAccessToken(accessToken)) - return Client{Options: opts}, nil -} diff --git a/examples/auth/main.go b/examples/auth/main.go deleted file mode 100644 index 4fcc730..0000000 --- a/examples/auth/main.go +++ /dev/null @@ -1,29 +0,0 @@ -package main - -import ( - "context" - "fmt" - - finch "github.com/Finch-API/finch-api-go" - "github.com/Finch-API/finch-api-go/option" -) - -func main() { - client := finch.NewClient(option.WithClientID("foo-client-id"), option.WithClientSecret("foo-client-secret")) - - url, err := client.GetAuthURL("products", "https://example.com/redirect", false) - if err != nil { - panic(err.Error()) - } - fmt.Printf("auth url: %s\n", url) - - accessTokenResponse, err := client.AccessTokens.New(context.TODO(), finch.AccessTokenNewParams{ - Code: finch.F("my-code"), - RedirectUri: finch.F("https://example.com/redirect"), - }) - if err != nil { - panic(err.Error()) - } - fmt.Printf("access token: %s\n", accessTokenResponse.AccessToken) - -} diff --git a/finchgo.go b/finchgo.go deleted file mode 100644 index 59c6281..0000000 --- a/finchgo.go +++ /dev/null @@ -1,12 +0,0 @@ -// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. - -package finchgo - -type GetAccessTokenParams struct { -} - -type GetAuthURLParams struct { -} - -type WithAccessTokenParams struct { -} diff --git a/webhook.go b/webhook.go index 837ea89..c5b936b 100644 --- a/webhook.go +++ b/webhook.go @@ -3,16 +3,7 @@ package finchgo import ( - "crypto/hmac" - "crypto/sha256" - "encoding/base64" - "errors" - "fmt" - "net/http" "reflect" - "strconv" - "strings" - "time" "github.com/Finch-API/finch-api-go/internal/apijson" "github.com/Finch-API/finch-api-go/internal/shared" @@ -37,83 +28,6 @@ func NewWebhookService(opts ...option.RequestOption) (r *WebhookService) { return } -// Validates that the given payload was sent by Finch and parses the payload. -func (r *WebhookService) Unwrap(payload []byte, headers http.Header, secret string, now time.Time) (res WebhookEvent, err error) { - err = r.VerifySignature(payload, headers, secret, now) - if err != nil { - return nil, err - } - - event := WebhookEvent(nil) - err = apijson.UnmarshalRoot(payload, &event) - if err != nil { - return nil, err - } - return event, nil -} - -// Validates whether or not the webhook payload was sent by Finch. -// -// An error will be raised if the webhook payload was not sent by Finch. -func (r *WebhookService) VerifySignature(payload []byte, headers http.Header, secret string, now time.Time) (err error) { - parsedSecret, err := base64.StdEncoding.DecodeString(secret) - if err != nil { - return fmt.Errorf("invalid webhook secret: %s", err) - } - - id := headers.Get("finch-event-id") - if len(id) == 0 { - return errors.New("could not find finch-event-id header") - } - sign := headers.Values("finch-signature") - if len(sign) == 0 { - return errors.New("could not find finch-signature header") - } - unixtime := headers.Get("finch-timestamp") - if len(unixtime) == 0 { - return errors.New("could not find finch-timestamp header") - } - - timestamp, err := strconv.ParseInt(unixtime, 10, 64) - if err != nil { - return fmt.Errorf("invalid timestamp header: %s, %s", unixtime, err) - } - - if timestamp < now.Unix()-300 { - return errors.New("webhook timestamp too old") - } - if timestamp > now.Unix()+300 { - return errors.New("webhook timestamp too new") - } - - mac := hmac.New(sha256.New, parsedSecret) - mac.Write([]byte(id)) - mac.Write([]byte(".")) - mac.Write([]byte(unixtime)) - mac.Write([]byte(".")) - mac.Write(payload) - expected := mac.Sum(nil) - - for _, part := range sign { - parts := strings.Split(part, ",") - if len(parts) != 2 { - continue - } - if parts[0] != "v1" { - continue - } - signature, err := base64.StdEncoding.DecodeString(parts[1]) - if err != nil { - continue - } - if hmac.Equal(signature, expected) { - return nil - } - } - - return errors.New("None of the given webhook signatures match the expected signature") -} - type AccountUpdateEvent struct { Data AccountUpdateEventData `json:"data"` EventType AccountUpdateEventEventType `json:"event_type"` @@ -1716,9 +1630,3 @@ func init() { }, ) } - -type WebhookUnwrapParams struct { -} - -type WebhookVerifySignatureParams struct { -} diff --git a/webhook_test.go b/webhook_test.go deleted file mode 100644 index ced3c2e..0000000 --- a/webhook_test.go +++ /dev/null @@ -1,28 +0,0 @@ -// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. - -package finchgo_test - -import ( - "net/http" - "testing" - "time" - - "github.com/Finch-API/finch-api-go" -) - -func TestVerifySignature(t *testing.T) { - secret := "5WbX5kEWLlfzsGNjH64I8lOOqUB6e8FH" - - payload := `{"company_id":"720be419-0293-4d32-a707-32179b0827ab"}` - - header := http.Header{} - header.Add("Finch-Event-Id", "msg_2Lh9KRb0pzN4LePd3XiA4v12Axj") - header.Add("finch-timestamp", "1676312382") - header.Add("finch-signature", "v1,m7y0TV2C+hlHxU42wCieApTSTaA8/047OAplBqxIV/s=") - - client := finchgo.NewClient() - err := client.Webhooks.VerifySignature([]byte(payload), header, secret, time.Unix(1676312382, 0)) - if err != nil { - t.Fatalf("did not expect error %s", err.Error()) - } -} From 4acd051a9bbc90843d33bc7f99c5035670f6573a Mon Sep 17 00:00:00 2001 From: Robert Craigie Date: Wed, 27 Mar 2024 17:18:21 +0000 Subject: [PATCH 08/11] chore: revert temporary commit --- accesstoken.go | 33 ++++++++++++++++ api.md | 12 ++++++ client.go | 86 ++++++++++++++++++++++++++++++++++++++++ examples/auth/main.go | 29 ++++++++++++++ finchgo.go | 12 ++++++ webhook.go | 92 +++++++++++++++++++++++++++++++++++++++++++ webhook_test.go | 28 +++++++++++++ 7 files changed, 292 insertions(+) create mode 100644 examples/auth/main.go create mode 100644 finchgo.go create mode 100644 webhook_test.go diff --git a/accesstoken.go b/accesstoken.go index 1b4b072..07ca8ca 100644 --- a/accesstoken.go +++ b/accesstoken.go @@ -4,12 +4,15 @@ package finchgo import ( "context" + "errors" "net/http" "github.com/Finch-API/finch-api-go/internal/apijson" "github.com/Finch-API/finch-api-go/internal/param" "github.com/Finch-API/finch-api-go/internal/requestconfig" "github.com/Finch-API/finch-api-go/option" + "github.com/tidwall/gjson" + "github.com/tidwall/sjson" ) // AccessTokenService contains methods and other services that help with @@ -32,9 +35,39 @@ func NewAccessTokenService(opts ...option.RequestOption) (r *AccessTokenService) // Exchange the authorization code for an access token func (r *AccessTokenService) New(ctx context.Context, body AccessTokenNewParams, opts ...option.RequestOption) (res *CreateAccessTokenResponse, err error) { opts = append(r.Options[:], opts...) + + opts = append(opts[:], func(rc *requestconfig.RequestConfig) error { + bodyClientID := gjson.Get(string(rc.Buffer), "client_id") + if !bodyClientID.Exists() { + if rc.ClientID == "" { + return errors.New("client_id must be provided as an argument or with the FINCH_CLIENT_ID environment variable") + } + updatedBody, err := sjson.Set(string(rc.Buffer), "client_id", rc.ClientID) + if err != nil { + return err + } + rc.Buffer = []byte(updatedBody) + } + + bodyClientSecret := gjson.Get(string(rc.Buffer), "client_secret") + if !bodyClientSecret.Exists() { + if rc.ClientSecret == "" { + return errors.New("client_secret must be provided as an argument or with the FINCH_CLIENT_SECRET environment variable") + } + updatedBody, err := sjson.Set(string(rc.Buffer), "client_secret", rc.ClientSecret) + if err != nil { + return err + } + rc.Buffer = []byte(updatedBody) + } + + return nil + }) + path := "auth/token" err = requestconfig.ExecuteNewRequest(ctx, http.MethodPost, path, body, &res, opts...) return + } type CreateAccessTokenResponse struct { diff --git a/api.md b/api.md index c692f3f..fbf9806 100644 --- a/api.md +++ b/api.md @@ -9,6 +9,13 @@ - shared.OperationSupportMatrix - shared.Paging +# finchgo + +Methods: + +- client.GetAuthURL(products string, redirectUri string, sandbox bool, opts ...option.RequestOption) (string, error) +- client.WithAccessToken(accessToken string) (Client, error) + # AccessTokens Response Types: @@ -176,6 +183,11 @@ Response Types: - finchgo.PaymentEvent - finchgo.WebhookEvent +Methods: + +- client.Webhooks.Unwrap(payload []byte, headers http.Header, secret string, now time.Time) (WebhookEvent, error) +- client.Webhooks.VerifySignature(payload []byte, headers http.Header, secret string, now time.Time) error + # RequestForwarding Response Types: diff --git a/client.go b/client.go index 22fc8b7..78a0d2e 100644 --- a/client.go +++ b/client.go @@ -3,8 +3,15 @@ package finchgo import ( + "context" + "encoding/json" + "errors" + "net/http" + "net/url" "os" + "strconv" + "github.com/Finch-API/finch-api-go/internal/requestconfig" "github.com/Finch-API/finch-api-go/option" ) @@ -60,3 +67,82 @@ func NewClient(opts ...option.RequestOption) (r *Client) { return } + +// DEPRECATED: use client.accessTokens().create instead. +func (r *Client) GetAccessToken(ctx context.Context, code string, redirectUri string, opts ...option.RequestOption) (res string, err error) { + opts = append(r.Options[:], opts...) + opts = append(opts[:], option.WithHeaderDel("authorization")) + + path := "/auth/token" + + var result map[string]string + cfg, err := requestconfig.NewRequestConfig(ctx, http.MethodPost, path, nil, &result, opts...) + if err != nil { + return "", err + } + if cfg.ClientID == "" { + return "", errors.New("expected ClientID to be set in order to call GetAccessToken") + } + if cfg.ClientSecret == "" { + return "", errors.New("expected ClientSecret to be set in order to call GetAccessToken") + } + + body := struct { + ClientID string `json:"client_id"` + ClientSecret string `json:"client_secret"` + Code string `json:"code"` + RedirectURI string `json:"redirect_uri"` + }{ + ClientID: cfg.ClientID, + ClientSecret: cfg.ClientSecret, + Code: code, + RedirectURI: redirectUri, + } + cfg.Apply(func(rc *requestconfig.RequestConfig) (err error) { + rc.Buffer, err = json.Marshal(body) + rc.Request.Header.Set("Content-Type", "application/json") + return err + }) + + err = cfg.Execute() + if err != nil { + return "", err + } + accessToken, ok := result["access_token"] + if !ok { + return "", errors.New("access_token not found in response") + } + + return accessToken, nil +} + +// Returns the authorization URL which can be visited in order to obtain an +// authorization code from Finch. The authorization code can then be exchanged for +// an access token for the Finch API by calling getAccessToken(). +func (r *Client) GetAuthURL(products string, redirectUri string, sandbox bool, opts ...option.RequestOption) (res string, err error) { + opts = append(r.Options[:], opts...) + cfg := requestconfig.RequestConfig{} + cfg.Apply(opts...) + + if cfg.ClientID == "" { + return "", errors.New("expected the ClientID to be set in order to call GetAuthUrl") + } + u, err := url.Parse("https://connect.tryfinch.com/authorize") + if err != nil { + return "", err + } + q := u.Query() + q.Set("client_id", cfg.ClientID) + q.Set("products", products) + q.Set("redirect_uri", redirectUri) + q.Set("sandbox", strconv.FormatBool(sandbox)) + u.RawQuery = q.Encode() + return u.String(), nil +} + +// Returns a copy of the current Finch client with the given access token for +// authentication. +func (r *Client) WithAccessToken(accessToken string) (res Client, err error) { + opts := append(r.Options[:], option.WithAccessToken(accessToken)) + return Client{Options: opts}, nil +} diff --git a/examples/auth/main.go b/examples/auth/main.go new file mode 100644 index 0000000..4fcc730 --- /dev/null +++ b/examples/auth/main.go @@ -0,0 +1,29 @@ +package main + +import ( + "context" + "fmt" + + finch "github.com/Finch-API/finch-api-go" + "github.com/Finch-API/finch-api-go/option" +) + +func main() { + client := finch.NewClient(option.WithClientID("foo-client-id"), option.WithClientSecret("foo-client-secret")) + + url, err := client.GetAuthURL("products", "https://example.com/redirect", false) + if err != nil { + panic(err.Error()) + } + fmt.Printf("auth url: %s\n", url) + + accessTokenResponse, err := client.AccessTokens.New(context.TODO(), finch.AccessTokenNewParams{ + Code: finch.F("my-code"), + RedirectUri: finch.F("https://example.com/redirect"), + }) + if err != nil { + panic(err.Error()) + } + fmt.Printf("access token: %s\n", accessTokenResponse.AccessToken) + +} diff --git a/finchgo.go b/finchgo.go new file mode 100644 index 0000000..59c6281 --- /dev/null +++ b/finchgo.go @@ -0,0 +1,12 @@ +// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. + +package finchgo + +type GetAccessTokenParams struct { +} + +type GetAuthURLParams struct { +} + +type WithAccessTokenParams struct { +} diff --git a/webhook.go b/webhook.go index c5b936b..837ea89 100644 --- a/webhook.go +++ b/webhook.go @@ -3,7 +3,16 @@ package finchgo import ( + "crypto/hmac" + "crypto/sha256" + "encoding/base64" + "errors" + "fmt" + "net/http" "reflect" + "strconv" + "strings" + "time" "github.com/Finch-API/finch-api-go/internal/apijson" "github.com/Finch-API/finch-api-go/internal/shared" @@ -28,6 +37,83 @@ func NewWebhookService(opts ...option.RequestOption) (r *WebhookService) { return } +// Validates that the given payload was sent by Finch and parses the payload. +func (r *WebhookService) Unwrap(payload []byte, headers http.Header, secret string, now time.Time) (res WebhookEvent, err error) { + err = r.VerifySignature(payload, headers, secret, now) + if err != nil { + return nil, err + } + + event := WebhookEvent(nil) + err = apijson.UnmarshalRoot(payload, &event) + if err != nil { + return nil, err + } + return event, nil +} + +// Validates whether or not the webhook payload was sent by Finch. +// +// An error will be raised if the webhook payload was not sent by Finch. +func (r *WebhookService) VerifySignature(payload []byte, headers http.Header, secret string, now time.Time) (err error) { + parsedSecret, err := base64.StdEncoding.DecodeString(secret) + if err != nil { + return fmt.Errorf("invalid webhook secret: %s", err) + } + + id := headers.Get("finch-event-id") + if len(id) == 0 { + return errors.New("could not find finch-event-id header") + } + sign := headers.Values("finch-signature") + if len(sign) == 0 { + return errors.New("could not find finch-signature header") + } + unixtime := headers.Get("finch-timestamp") + if len(unixtime) == 0 { + return errors.New("could not find finch-timestamp header") + } + + timestamp, err := strconv.ParseInt(unixtime, 10, 64) + if err != nil { + return fmt.Errorf("invalid timestamp header: %s, %s", unixtime, err) + } + + if timestamp < now.Unix()-300 { + return errors.New("webhook timestamp too old") + } + if timestamp > now.Unix()+300 { + return errors.New("webhook timestamp too new") + } + + mac := hmac.New(sha256.New, parsedSecret) + mac.Write([]byte(id)) + mac.Write([]byte(".")) + mac.Write([]byte(unixtime)) + mac.Write([]byte(".")) + mac.Write(payload) + expected := mac.Sum(nil) + + for _, part := range sign { + parts := strings.Split(part, ",") + if len(parts) != 2 { + continue + } + if parts[0] != "v1" { + continue + } + signature, err := base64.StdEncoding.DecodeString(parts[1]) + if err != nil { + continue + } + if hmac.Equal(signature, expected) { + return nil + } + } + + return errors.New("None of the given webhook signatures match the expected signature") +} + type AccountUpdateEvent struct { Data AccountUpdateEventData `json:"data"` EventType AccountUpdateEventEventType `json:"event_type"` @@ -1630,3 +1716,9 @@ func init() { }, ) } + +type WebhookUnwrapParams struct { +} + +type WebhookVerifySignatureParams struct { +} diff --git a/webhook_test.go b/webhook_test.go new file mode 100644 index 0000000..ced3c2e --- /dev/null +++ b/webhook_test.go @@ -0,0 +1,28 @@ +// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. + +package finchgo_test + +import ( + "net/http" + "testing" + "time" + + "github.com/Finch-API/finch-api-go" +) + +func TestVerifySignature(t *testing.T) { + secret := "5WbX5kEWLlfzsGNjH64I8lOOqUB6e8FH" + + payload := `{"company_id":"720be419-0293-4d32-a707-32179b0827ab"}` + + header := http.Header{} + header.Add("Finch-Event-Id", "msg_2Lh9KRb0pzN4LePd3XiA4v12Axj") + header.Add("finch-timestamp", "1676312382") + header.Add("finch-signature", "v1,m7y0TV2C+hlHxU42wCieApTSTaA8/047OAplBqxIV/s=") + + client := finchgo.NewClient() + err := client.Webhooks.VerifySignature([]byte(payload), header, secret, time.Unix(1676312382, 0)) + if err != nil { + t.Fatalf("did not expect error %s", err.Error()) + } +} From 0469fdcad5e8323a6d61419f5190624160f29318 Mon Sep 17 00:00:00 2001 From: "stainless-app[bot]" <142633134+stainless-app[bot]@users.noreply.github.com> Date: Thu, 28 Mar 2024 04:26:58 +0000 Subject: [PATCH 09/11] feat(client): implement raw requests methods on client (#139) --- accesstoken.go | 46 ++++++------ client.go | 76 +++++++++++++++++++- internal/requestconfig/requestconfig.go | 93 +++++++++++++++++++------ option/requestoption.go | 27 +++++-- 4 files changed, 193 insertions(+), 49 deletions(-) diff --git a/accesstoken.go b/accesstoken.go index 07ca8ca..97a4dc8 100644 --- a/accesstoken.go +++ b/accesstoken.go @@ -3,6 +3,7 @@ package finchgo import ( + "bytes" "context" "errors" "net/http" @@ -36,29 +37,32 @@ func NewAccessTokenService(opts ...option.RequestOption) (r *AccessTokenService) func (r *AccessTokenService) New(ctx context.Context, body AccessTokenNewParams, opts ...option.RequestOption) (res *CreateAccessTokenResponse, err error) { opts = append(r.Options[:], opts...) - opts = append(opts[:], func(rc *requestconfig.RequestConfig) error { - bodyClientID := gjson.Get(string(rc.Buffer), "client_id") - if !bodyClientID.Exists() { - if rc.ClientID == "" { - return errors.New("client_id must be provided as an argument or with the FINCH_CLIENT_ID environment variable") + opts = append(opts[:], func(rc *requestconfig.RequestConfig) (err error) { + if body, ok := rc.Body.(*bytes.Buffer); ok { + b := body.Bytes()[:] + + bodyClientID := gjson.GetBytes(b, "client_id") + if !bodyClientID.Exists() { + if rc.ClientID == "" { + return errors.New("client_id must be provided as an argument or with the FINCH_CLIENT_ID environment variable") + } + b, err = sjson.SetBytes(b, "client_id", rc.ClientID) + if err != nil { + return err + } + rc.Body = bytes.NewBuffer(b) } - updatedBody, err := sjson.Set(string(rc.Buffer), "client_id", rc.ClientID) - if err != nil { - return err + bodyClientSecret := gjson.GetBytes(b, "client_secret") + if !bodyClientSecret.Exists() { + if rc.ClientSecret == "" { + return errors.New("client_secret must be provided as an argument or with the FINCH_CLIENT_SECRET environment variable") + } + b, err = sjson.SetBytes(b, "client_secret", rc.ClientSecret) + if err != nil { + return err + } + rc.Body = bytes.NewBuffer(b) } - rc.Buffer = []byte(updatedBody) - } - - bodyClientSecret := gjson.Get(string(rc.Buffer), "client_secret") - if !bodyClientSecret.Exists() { - if rc.ClientSecret == "" { - return errors.New("client_secret must be provided as an argument or with the FINCH_CLIENT_SECRET environment variable") - } - updatedBody, err := sjson.Set(string(rc.Buffer), "client_secret", rc.ClientSecret) - if err != nil { - return err - } - rc.Buffer = []byte(updatedBody) } return nil diff --git a/client.go b/client.go index 78a0d2e..b47fb8b 100644 --- a/client.go +++ b/client.go @@ -3,6 +3,7 @@ package finchgo import ( + "bytes" "context" "encoding/json" "errors" @@ -99,7 +100,11 @@ func (r *Client) GetAccessToken(ctx context.Context, code string, redirectUri st RedirectURI: redirectUri, } cfg.Apply(func(rc *requestconfig.RequestConfig) (err error) { - rc.Buffer, err = json.Marshal(body) + buf, err := json.Marshal(body) + if err != nil { + return err + } + rc.Body = bytes.NewBuffer(buf) rc.Request.Header.Set("Content-Type", "application/json") return err }) @@ -146,3 +151,72 @@ func (r *Client) WithAccessToken(accessToken string) (res Client, err error) { opts := append(r.Options[:], option.WithAccessToken(accessToken)) return Client{Options: opts}, nil } + +// Execute makes a request with the given context, method, URL, request params, +// response, and request options. This is useful for hitting undocumented endpoints +// while retaining the base URL, auth, retries, and other options from the client. +// +// If a byte slice or an [io.Reader] is supplied to params, it will be used as-is +// for the request body. +// +// The params is by default serialized into the body using [encoding/json]. If your +// type implements a MarshalJSON function, it will be used instead to serialize the +// request. If a URLQuery method is implemented, the returned [url.Values] will be +// used as query strings to the url. +// +// If your params struct uses [param.Field], you must provide either [MarshalJSON], +// [URLQuery], and/or [MarshalForm] functions. It is undefined behavior to use a +// struct uses [param.Field] without specifying how it is serialized. +// +// Any "…Params" object defined in this library can be used as the request +// argument. Note that 'path' arguments will not be forwarded into the url. +// +// The response body will be deserialized into the res variable, depending on its +// type: +// +// - A pointer to a [*http.Response] is populated by the raw response. +// - A pointer to a byte array will be populated with the contents of the request +// body. +// - A pointer to any other type uses this library's default JSON decoding, which +// respects UnmarshalJSON if it is defined on the type. +// - A nil value will not read the response body. +// +// For even greater flexibility, see [option.WithResponseInto] and +// [option.WithResponseBodyInto]. +func (r *Client) Execute(ctx context.Context, method string, path string, params interface{}, res interface{}, opts ...option.RequestOption) error { + opts = append(r.Options, opts...) + return requestconfig.ExecuteNewRequest(ctx, method, path, params, res, opts...) +} + +// Get makes a GET request with the given URL, params, and optionally deserializes +// to a response. See [Execute] documentation on the params and response. +func (r *Client) Get(ctx context.Context, path string, params interface{}, res interface{}, opts ...option.RequestOption) error { + return r.Execute(ctx, http.MethodGet, path, params, res, opts...) +} + +// Post makes a POST request with the given URL, params, and optionally +// deserializes to a response. See [Execute] documentation on the params and +// response. +func (r *Client) Post(ctx context.Context, path string, params interface{}, res interface{}, opts ...option.RequestOption) error { + return r.Execute(ctx, http.MethodPost, path, params, res, opts...) +} + +// Put makes a PUT request with the given URL, params, and optionally deserializes +// to a response. See [Execute] documentation on the params and response. +func (r *Client) Put(ctx context.Context, path string, params interface{}, res interface{}, opts ...option.RequestOption) error { + return r.Execute(ctx, http.MethodPut, path, params, res, opts...) +} + +// Patch makes a PATCH request with the given URL, params, and optionally +// deserializes to a response. See [Execute] documentation on the params and +// response. +func (r *Client) Patch(ctx context.Context, path string, params interface{}, res interface{}, opts ...option.RequestOption) error { + return r.Execute(ctx, http.MethodPatch, path, params, res, opts...) +} + +// Delete makes a DELETE request with the given URL, params, and optionally +// deserializes to a response. See [Execute] documentation on the params and +// response. +func (r *Client) Delete(ctx context.Context, path string, params interface{}, res interface{}, opts ...option.RequestOption) error { + return r.Execute(ctx, http.MethodDelete, path, params, res, opts...) +} diff --git a/internal/requestconfig/requestconfig.go b/internal/requestconfig/requestconfig.go index e408329..2565d87 100644 --- a/internal/requestconfig/requestconfig.go +++ b/internal/requestconfig/requestconfig.go @@ -77,24 +77,29 @@ func getPlatformProperties() map[string]string { } func NewRequestConfig(ctx context.Context, method string, u string, body interface{}, dst interface{}, opts ...func(*RequestConfig) error) (*RequestConfig, error) { - var b []byte + var reader io.Reader contentType := "application/json" hasSerializationFunc := false + if body, ok := body.(json.Marshaler); ok { - var err error - b, err = body.MarshalJSON() + content, err := body.MarshalJSON() if err != nil { return nil, err } + reader = bytes.NewBuffer(content) hasSerializationFunc = true } if body, ok := body.(apiform.Marshaler); ok { - var err error - b, contentType, err = body.MarshalMultipart() + var ( + content []byte + err error + ) + content, contentType, err = body.MarshalMultipart() if err != nil { return nil, err } + reader = bytes.NewBuffer(content) hasSerializationFunc = true } if body, ok := body.(apiquery.Queryer); ok { @@ -104,22 +109,30 @@ func NewRequestConfig(ctx context.Context, method string, u string, body interfa u = u + "?" + params } } + if body, ok := body.([]byte); ok { + reader = bytes.NewBuffer(body) + hasSerializationFunc = true + } + if body, ok := body.(io.Reader); ok { + reader = body + hasSerializationFunc = true + } // Fallback to json serialization if none of the serialization functions that we expect // to see is present. if body != nil && !hasSerializationFunc { - var err error - b, err = json.Marshal(body) + content, err := json.Marshal(body) if err != nil { return nil, err } + reader = bytes.NewBuffer(content) } req, err := http.NewRequestWithContext(ctx, method, u, nil) if err != nil { return nil, err } - if b != nil { + if reader != nil { req.Header.Set("Content-Type", contentType) } @@ -136,7 +149,7 @@ func NewRequestConfig(ctx context.Context, method string, u string, body interfa Context: ctx, Request: req, HTTPClient: http.DefaultClient, - Buffer: b, + Body: reader, } cfg.ResponseBodyInto = dst err = cfg.Apply(opts...) @@ -171,7 +184,7 @@ type RequestConfig struct { // ResponseInto copies the \*http.Response of the corresponding request into the // given address ResponseInto **http.Response - Buffer []byte + Body io.Reader } // middleware is exactly the same type as the Middleware type found in the [option] package, @@ -290,15 +303,32 @@ func retryDelay(res *http.Response, retryCount int) time.Duration { } func (cfg *RequestConfig) Execute() (err error) { - cfg.Request.URL, err = cfg.BaseURL.Parse(cfg.Request.URL.String()) + cfg.Request.URL, err = cfg.BaseURL.Parse(strings.TrimLeft(cfg.Request.URL.String(), "/")) if err != nil { return err } - if len(cfg.Buffer) != 0 && cfg.Request.Body == nil { - cfg.Request.ContentLength = int64(len(cfg.Buffer)) - cfg.Request.GetBody = func() (io.ReadCloser, error) { return io.NopCloser(bytes.NewReader(cfg.Buffer)), nil } - cfg.Request.Body, _ = cfg.Request.GetBody() + if cfg.Body != nil && cfg.Request.Body == nil { + switch body := cfg.Body.(type) { + case *bytes.Buffer: + b := body.Bytes() + cfg.Request.ContentLength = int64(body.Len()) + cfg.Request.GetBody = func() (io.ReadCloser, error) { return io.NopCloser(bytes.NewReader(b)), nil } + cfg.Request.Body, _ = cfg.Request.GetBody() + case *bytes.Reader: + cfg.Request.ContentLength = int64(body.Len()) + cfg.Request.GetBody = func() (io.ReadCloser, error) { + _, err := body.Seek(0, 0) + return io.NopCloser(body), err + } + cfg.Request.Body, _ = cfg.Request.GetBody() + default: + if rc, ok := body.(io.ReadCloser); ok { + cfg.Request.Body = rc + } else { + cfg.Request.Body = io.NopCloser(body) + } + } } handler := cfg.HTTPClient.Do @@ -331,9 +361,26 @@ func (cfg *RequestConfig) Execute() (err error) { } } + // Can't actually refresh the body, so we don't attempt to retry here + if cfg.Request.GetBody == nil && cfg.Request.Body != nil { + break + } + time.Sleep(retryDelay(res, retryCount)) } + // Save *http.Response if it is requested to, even if there was an error making the request. This is + // useful in cases where you might want to debug by inspecting the response. Note that if err != nil, + // the response should be generally be empty, but there are edge cases. + if cfg.ResponseInto != nil { + *cfg.ResponseInto = res + } + if responseBodyInto, ok := cfg.ResponseBodyInto.(**http.Response); ok { + *responseBodyInto = res + } + + // If there was a connection error in the final request or any other transport error, + // return that early without trying to coerce into an APIError. if err != nil { return err } @@ -354,16 +401,10 @@ func (cfg *RequestConfig) Execute() (err error) { return &aerr } - if cfg.ResponseInto != nil { - *cfg.ResponseInto = res - } - if cfg.ResponseBodyInto == nil { return nil } - - if responseBodyInto, ok := cfg.ResponseBodyInto.(**http.Response); ok { - *responseBodyInto = res + if _, ok := cfg.ResponseBodyInto.(**http.Response); ok { return nil } @@ -372,7 +413,7 @@ func (cfg *RequestConfig) Execute() (err error) { return fmt.Errorf("error reading response body: %w", err) } - // If we are not json return plaintext + // If we are not json, return plaintext isJSON := strings.Contains(res.Header.Get("content-type"), "application/json") if !isJSON { switch dst := cfg.ResponseBodyInto.(type) { @@ -389,6 +430,12 @@ func (cfg *RequestConfig) Execute() (err error) { return nil } + // If the response happens to be a byte array, deserialize the body as-is. + switch dst := cfg.ResponseBodyInto.(type) { + case *[]byte: + *dst = contents + } + err = json.NewDecoder(bytes.NewReader(contents)).Decode(cfg.ResponseBodyInto) if err != nil { err = fmt.Errorf("error parsing response json: %w", err) diff --git a/option/requestoption.go b/option/requestoption.go index ba5a292..721079d 100644 --- a/option/requestoption.go +++ b/option/requestoption.go @@ -3,6 +3,7 @@ package option import ( + "bytes" "encoding/base64" "fmt" "log" @@ -139,8 +140,17 @@ func WithQueryDel(key string) RequestOption { // [sjson format]: https://github.com/tidwall/sjson func WithJSONSet(key string, value interface{}) RequestOption { return func(r *requestconfig.RequestConfig) (err error) { - r.Buffer, err = sjson.SetBytes(r.Buffer, key, value) - return err + if buffer, ok := r.Body.(*bytes.Buffer); ok { + b := buffer.Bytes() + b, err = sjson.SetBytes(b, key, value) + if err != nil { + return err + } + r.Body = bytes.NewBuffer(b) + return nil + } + + return fmt.Errorf("cannot use WithJSONSet on a body that is not serialized as *bytes.Buffer") } } @@ -150,8 +160,17 @@ func WithJSONSet(key string, value interface{}) RequestOption { // [sjson format]: https://github.com/tidwall/sjson func WithJSONDel(key string) RequestOption { return func(r *requestconfig.RequestConfig) (err error) { - r.Buffer, err = sjson.DeleteBytes(r.Buffer, key) - return err + if buffer, ok := r.Body.(*bytes.Buffer); ok { + b := buffer.Bytes() + b, err = sjson.DeleteBytes(b, key) + if err != nil { + return err + } + r.Body = bytes.NewBuffer(b) + return nil + } + + return fmt.Errorf("cannot use WithJSONDel on a body that is not serialized as *bytes.Buffer") } } From b4172a582939c4b111bbc947b8fd228fa6763ef6 Mon Sep 17 00:00:00 2001 From: "stainless-app[bot]" <142633134+stainless-app[bot]@users.noreply.github.com> Date: Thu, 28 Mar 2024 06:59:10 +0000 Subject: [PATCH 10/11] chore(internal): move pagination types to pagination package (#140) --- api.md | 20 +++++++++---------- hrisbenefit.go | 13 ++++++------ hrisbenefitindividual.go | 14 ++++++------- hrisemployment.go | 8 ++++---- hrisindividual.go | 8 ++++---- hrispayment.go | 8 ++++---- hrispaystatement.go | 7 ++++--- internal/{shared => pagination}/pagination.go | 9 +++++---- internal/requestconfig/requestconfig.go | 6 +++++- jobautomated.go | 8 ++++---- provider.go | 8 ++++---- 11 files changed, 58 insertions(+), 51 deletions(-) rename internal/{shared => pagination}/pagination.go (97%) diff --git a/api.md b/api.md index fbf9806..acc4ed5 100644 --- a/api.md +++ b/api.md @@ -69,7 +69,7 @@ Response Types: Methods: -- client.HRIS.Individuals.GetMany(ctx context.Context, body finchgo.HRISIndividualGetManyParams) (shared.ResponsesPage[finchgo.IndividualResponse], error) +- client.HRIS.Individuals.GetMany(ctx context.Context, body finchgo.HRISIndividualGetManyParams) (pagination.ResponsesPage[finchgo.IndividualResponse], error) ## Employments @@ -80,7 +80,7 @@ Response Types: Methods: -- client.HRIS.Employments.GetMany(ctx context.Context, body finchgo.HRISEmploymentGetManyParams) (shared.ResponsesPage[finchgo.EmploymentDataResponse], error) +- client.HRIS.Employments.GetMany(ctx context.Context, body finchgo.HRISEmploymentGetManyParams) (pagination.ResponsesPage[finchgo.EmploymentDataResponse], error) ## Payments @@ -90,7 +90,7 @@ Response Types: Methods: -- client.HRIS.Payments.List(ctx context.Context, query finchgo.HRISPaymentListParams) (shared.SinglePage[finchgo.Payment], error) +- client.HRIS.Payments.List(ctx context.Context, query finchgo.HRISPaymentListParams) (pagination.SinglePage[finchgo.Payment], error) ## PayStatements @@ -102,7 +102,7 @@ Response Types: Methods: -- client.HRIS.PayStatements.GetMany(ctx context.Context, body finchgo.HRISPayStatementGetManyParams) (shared.ResponsesPage[finchgo.PayStatementResponse], error) +- client.HRIS.PayStatements.GetMany(ctx context.Context, body finchgo.HRISPayStatementGetManyParams) (pagination.ResponsesPage[finchgo.PayStatementResponse], error) ## Benefits @@ -129,8 +129,8 @@ Methods: - client.HRIS.Benefits.New(ctx context.Context, body finchgo.HRISBenefitNewParams) (finchgo.CreateCompanyBenefitsResponse, error) - client.HRIS.Benefits.Get(ctx context.Context, benefitID string) (finchgo.CompanyBenefit, error) - client.HRIS.Benefits.Update(ctx context.Context, benefitID string, body finchgo.HRISBenefitUpdateParams) (finchgo.UpdateCompanyBenefitResponse, error) -- client.HRIS.Benefits.List(ctx context.Context) (shared.SinglePage[finchgo.CompanyBenefit], error) -- client.HRIS.Benefits.ListSupportedBenefits(ctx context.Context) (shared.SinglePage[finchgo.SupportedBenefit], error) +- client.HRIS.Benefits.List(ctx context.Context) (pagination.SinglePage[finchgo.CompanyBenefit], error) +- client.HRIS.Benefits.ListSupportedBenefits(ctx context.Context) (pagination.SinglePage[finchgo.SupportedBenefit], error) ### Individuals @@ -143,8 +143,8 @@ Response Types: Methods: - client.HRIS.Benefits.Individuals.EnrolledIDs(ctx context.Context, benefitID string) (finchgo.HRISBenefitIndividualEnrolledIDsResponse, error) -- client.HRIS.Benefits.Individuals.GetManyBenefits(ctx context.Context, benefitID string, query finchgo.HRISBenefitIndividualGetManyBenefitsParams) (shared.SinglePage[finchgo.IndividualBenefit], error) -- client.HRIS.Benefits.Individuals.UnenrollMany(ctx context.Context, benefitID string, body finchgo.HRISBenefitIndividualUnenrollManyParams) (shared.SinglePage[finchgo.UnenrolledIndividual], error) +- client.HRIS.Benefits.Individuals.GetManyBenefits(ctx context.Context, benefitID string, query finchgo.HRISBenefitIndividualGetManyBenefitsParams) (pagination.SinglePage[finchgo.IndividualBenefit], error) +- client.HRIS.Benefits.Individuals.UnenrollMany(ctx context.Context, benefitID string, body finchgo.HRISBenefitIndividualUnenrollManyParams) (pagination.SinglePage[finchgo.UnenrolledIndividual], error) # Providers @@ -154,7 +154,7 @@ Response Types: Methods: -- client.Providers.List(ctx context.Context) (shared.SinglePage[finchgo.Provider], error) +- client.Providers.List(ctx context.Context) (pagination.SinglePage[finchgo.Provider], error) # Account @@ -211,7 +211,7 @@ Methods: - client.Jobs.Automated.New(ctx context.Context, body finchgo.JobAutomatedNewParams) (finchgo.JobAutomatedNewResponse, error) - client.Jobs.Automated.Get(ctx context.Context, jobID string) (finchgo.AutomatedAsyncJob, error) -- client.Jobs.Automated.List(ctx context.Context, query finchgo.JobAutomatedListParams) (shared.Page[finchgo.AutomatedAsyncJob], error) +- client.Jobs.Automated.List(ctx context.Context, query finchgo.JobAutomatedListParams) (pagination.Page[finchgo.AutomatedAsyncJob], error) ## Manual diff --git a/hrisbenefit.go b/hrisbenefit.go index 272e66a..475e501 100644 --- a/hrisbenefit.go +++ b/hrisbenefit.go @@ -8,6 +8,7 @@ import ( "net/http" "github.com/Finch-API/finch-api-go/internal/apijson" + "github.com/Finch-API/finch-api-go/internal/pagination" "github.com/Finch-API/finch-api-go/internal/param" "github.com/Finch-API/finch-api-go/internal/requestconfig" "github.com/Finch-API/finch-api-go/internal/shared" @@ -59,7 +60,7 @@ func (r *HRISBenefitService) Update(ctx context.Context, benefitID string, body } // List all company-wide deductions and contributions. -func (r *HRISBenefitService) List(ctx context.Context, opts ...option.RequestOption) (res *shared.SinglePage[CompanyBenefit], err error) { +func (r *HRISBenefitService) List(ctx context.Context, opts ...option.RequestOption) (res *pagination.SinglePage[CompanyBenefit], err error) { var raw *http.Response opts = append(r.Options, opts...) opts = append([]option.RequestOption{option.WithResponseInto(&raw)}, opts...) @@ -77,12 +78,12 @@ func (r *HRISBenefitService) List(ctx context.Context, opts ...option.RequestOpt } // List all company-wide deductions and contributions. -func (r *HRISBenefitService) ListAutoPaging(ctx context.Context, opts ...option.RequestOption) *shared.SinglePageAutoPager[CompanyBenefit] { - return shared.NewSinglePageAutoPager(r.List(ctx, opts...)) +func (r *HRISBenefitService) ListAutoPaging(ctx context.Context, opts ...option.RequestOption) *pagination.SinglePageAutoPager[CompanyBenefit] { + return pagination.NewSinglePageAutoPager(r.List(ctx, opts...)) } // Get deductions metadata -func (r *HRISBenefitService) ListSupportedBenefits(ctx context.Context, opts ...option.RequestOption) (res *shared.SinglePage[SupportedBenefit], err error) { +func (r *HRISBenefitService) ListSupportedBenefits(ctx context.Context, opts ...option.RequestOption) (res *pagination.SinglePage[SupportedBenefit], err error) { var raw *http.Response opts = append(r.Options, opts...) opts = append([]option.RequestOption{option.WithResponseInto(&raw)}, opts...) @@ -100,8 +101,8 @@ func (r *HRISBenefitService) ListSupportedBenefits(ctx context.Context, opts ... } // Get deductions metadata -func (r *HRISBenefitService) ListSupportedBenefitsAutoPaging(ctx context.Context, opts ...option.RequestOption) *shared.SinglePageAutoPager[SupportedBenefit] { - return shared.NewSinglePageAutoPager(r.ListSupportedBenefits(ctx, opts...)) +func (r *HRISBenefitService) ListSupportedBenefitsAutoPaging(ctx context.Context, opts ...option.RequestOption) *pagination.SinglePageAutoPager[SupportedBenefit] { + return pagination.NewSinglePageAutoPager(r.ListSupportedBenefits(ctx, opts...)) } type BenefitContribution struct { diff --git a/hrisbenefitindividual.go b/hrisbenefitindividual.go index d643a56..9a3bf94 100644 --- a/hrisbenefitindividual.go +++ b/hrisbenefitindividual.go @@ -10,9 +10,9 @@ import ( "github.com/Finch-API/finch-api-go/internal/apijson" "github.com/Finch-API/finch-api-go/internal/apiquery" + "github.com/Finch-API/finch-api-go/internal/pagination" "github.com/Finch-API/finch-api-go/internal/param" "github.com/Finch-API/finch-api-go/internal/requestconfig" - "github.com/Finch-API/finch-api-go/internal/shared" "github.com/Finch-API/finch-api-go/option" ) @@ -43,7 +43,7 @@ func (r *HRISBenefitIndividualService) EnrolledIDs(ctx context.Context, benefitI } // Get enrollment information for the given individuals. -func (r *HRISBenefitIndividualService) GetManyBenefits(ctx context.Context, benefitID string, query HRISBenefitIndividualGetManyBenefitsParams, opts ...option.RequestOption) (res *shared.SinglePage[IndividualBenefit], err error) { +func (r *HRISBenefitIndividualService) GetManyBenefits(ctx context.Context, benefitID string, query HRISBenefitIndividualGetManyBenefitsParams, opts ...option.RequestOption) (res *pagination.SinglePage[IndividualBenefit], err error) { var raw *http.Response opts = append(r.Options, opts...) opts = append([]option.RequestOption{option.WithResponseInto(&raw)}, opts...) @@ -61,12 +61,12 @@ func (r *HRISBenefitIndividualService) GetManyBenefits(ctx context.Context, bene } // Get enrollment information for the given individuals. -func (r *HRISBenefitIndividualService) GetManyBenefitsAutoPaging(ctx context.Context, benefitID string, query HRISBenefitIndividualGetManyBenefitsParams, opts ...option.RequestOption) *shared.SinglePageAutoPager[IndividualBenefit] { - return shared.NewSinglePageAutoPager(r.GetManyBenefits(ctx, benefitID, query, opts...)) +func (r *HRISBenefitIndividualService) GetManyBenefitsAutoPaging(ctx context.Context, benefitID string, query HRISBenefitIndividualGetManyBenefitsParams, opts ...option.RequestOption) *pagination.SinglePageAutoPager[IndividualBenefit] { + return pagination.NewSinglePageAutoPager(r.GetManyBenefits(ctx, benefitID, query, opts...)) } // Unenroll individuals from a deduction or contribution -func (r *HRISBenefitIndividualService) UnenrollMany(ctx context.Context, benefitID string, body HRISBenefitIndividualUnenrollManyParams, opts ...option.RequestOption) (res *shared.SinglePage[UnenrolledIndividual], err error) { +func (r *HRISBenefitIndividualService) UnenrollMany(ctx context.Context, benefitID string, body HRISBenefitIndividualUnenrollManyParams, opts ...option.RequestOption) (res *pagination.SinglePage[UnenrolledIndividual], err error) { var raw *http.Response opts = append(r.Options, opts...) opts = append([]option.RequestOption{option.WithResponseInto(&raw)}, opts...) @@ -84,8 +84,8 @@ func (r *HRISBenefitIndividualService) UnenrollMany(ctx context.Context, benefit } // Unenroll individuals from a deduction or contribution -func (r *HRISBenefitIndividualService) UnenrollManyAutoPaging(ctx context.Context, benefitID string, body HRISBenefitIndividualUnenrollManyParams, opts ...option.RequestOption) *shared.SinglePageAutoPager[UnenrolledIndividual] { - return shared.NewSinglePageAutoPager(r.UnenrollMany(ctx, benefitID, body, opts...)) +func (r *HRISBenefitIndividualService) UnenrollManyAutoPaging(ctx context.Context, benefitID string, body HRISBenefitIndividualUnenrollManyParams, opts ...option.RequestOption) *pagination.SinglePageAutoPager[UnenrolledIndividual] { + return pagination.NewSinglePageAutoPager(r.UnenrollMany(ctx, benefitID, body, opts...)) } type IndividualBenefit struct { diff --git a/hrisemployment.go b/hrisemployment.go index 8b473c6..8e14a6b 100644 --- a/hrisemployment.go +++ b/hrisemployment.go @@ -7,9 +7,9 @@ import ( "net/http" "github.com/Finch-API/finch-api-go/internal/apijson" + "github.com/Finch-API/finch-api-go/internal/pagination" "github.com/Finch-API/finch-api-go/internal/param" "github.com/Finch-API/finch-api-go/internal/requestconfig" - "github.com/Finch-API/finch-api-go/internal/shared" "github.com/Finch-API/finch-api-go/option" ) @@ -31,7 +31,7 @@ func NewHRISEmploymentService(opts ...option.RequestOption) (r *HRISEmploymentSe } // Read individual employment and income data -func (r *HRISEmploymentService) GetMany(ctx context.Context, body HRISEmploymentGetManyParams, opts ...option.RequestOption) (res *shared.ResponsesPage[EmploymentDataResponse], err error) { +func (r *HRISEmploymentService) GetMany(ctx context.Context, body HRISEmploymentGetManyParams, opts ...option.RequestOption) (res *pagination.ResponsesPage[EmploymentDataResponse], err error) { var raw *http.Response opts = append(r.Options, opts...) opts = append([]option.RequestOption{option.WithResponseInto(&raw)}, opts...) @@ -49,8 +49,8 @@ func (r *HRISEmploymentService) GetMany(ctx context.Context, body HRISEmployment } // Read individual employment and income data -func (r *HRISEmploymentService) GetManyAutoPaging(ctx context.Context, body HRISEmploymentGetManyParams, opts ...option.RequestOption) *shared.ResponsesPageAutoPager[EmploymentDataResponse] { - return shared.NewResponsesPageAutoPager(r.GetMany(ctx, body, opts...)) +func (r *HRISEmploymentService) GetManyAutoPaging(ctx context.Context, body HRISEmploymentGetManyParams, opts ...option.RequestOption) *pagination.ResponsesPageAutoPager[EmploymentDataResponse] { + return pagination.NewResponsesPageAutoPager(r.GetMany(ctx, body, opts...)) } type EmploymentData struct { diff --git a/hrisindividual.go b/hrisindividual.go index 0909d05..c401642 100644 --- a/hrisindividual.go +++ b/hrisindividual.go @@ -7,9 +7,9 @@ import ( "net/http" "github.com/Finch-API/finch-api-go/internal/apijson" + "github.com/Finch-API/finch-api-go/internal/pagination" "github.com/Finch-API/finch-api-go/internal/param" "github.com/Finch-API/finch-api-go/internal/requestconfig" - "github.com/Finch-API/finch-api-go/internal/shared" "github.com/Finch-API/finch-api-go/option" ) @@ -31,7 +31,7 @@ func NewHRISIndividualService(opts ...option.RequestOption) (r *HRISIndividualSe } // Read individual data, excluding income and employment data -func (r *HRISIndividualService) GetMany(ctx context.Context, body HRISIndividualGetManyParams, opts ...option.RequestOption) (res *shared.ResponsesPage[IndividualResponse], err error) { +func (r *HRISIndividualService) GetMany(ctx context.Context, body HRISIndividualGetManyParams, opts ...option.RequestOption) (res *pagination.ResponsesPage[IndividualResponse], err error) { var raw *http.Response opts = append(r.Options, opts...) opts = append([]option.RequestOption{option.WithResponseInto(&raw)}, opts...) @@ -49,8 +49,8 @@ func (r *HRISIndividualService) GetMany(ctx context.Context, body HRISIndividual } // Read individual data, excluding income and employment data -func (r *HRISIndividualService) GetManyAutoPaging(ctx context.Context, body HRISIndividualGetManyParams, opts ...option.RequestOption) *shared.ResponsesPageAutoPager[IndividualResponse] { - return shared.NewResponsesPageAutoPager(r.GetMany(ctx, body, opts...)) +func (r *HRISIndividualService) GetManyAutoPaging(ctx context.Context, body HRISIndividualGetManyParams, opts ...option.RequestOption) *pagination.ResponsesPageAutoPager[IndividualResponse] { + return pagination.NewResponsesPageAutoPager(r.GetMany(ctx, body, opts...)) } type Individual struct { diff --git a/hrispayment.go b/hrispayment.go index d3c4b25..84c6069 100644 --- a/hrispayment.go +++ b/hrispayment.go @@ -10,9 +10,9 @@ import ( "github.com/Finch-API/finch-api-go/internal/apijson" "github.com/Finch-API/finch-api-go/internal/apiquery" + "github.com/Finch-API/finch-api-go/internal/pagination" "github.com/Finch-API/finch-api-go/internal/param" "github.com/Finch-API/finch-api-go/internal/requestconfig" - "github.com/Finch-API/finch-api-go/internal/shared" "github.com/Finch-API/finch-api-go/option" ) @@ -34,7 +34,7 @@ func NewHRISPaymentService(opts ...option.RequestOption) (r *HRISPaymentService) } // Read payroll and contractor related payments by the company. -func (r *HRISPaymentService) List(ctx context.Context, query HRISPaymentListParams, opts ...option.RequestOption) (res *shared.SinglePage[Payment], err error) { +func (r *HRISPaymentService) List(ctx context.Context, query HRISPaymentListParams, opts ...option.RequestOption) (res *pagination.SinglePage[Payment], err error) { var raw *http.Response opts = append(r.Options, opts...) opts = append([]option.RequestOption{option.WithResponseInto(&raw)}, opts...) @@ -52,8 +52,8 @@ func (r *HRISPaymentService) List(ctx context.Context, query HRISPaymentListPara } // Read payroll and contractor related payments by the company. -func (r *HRISPaymentService) ListAutoPaging(ctx context.Context, query HRISPaymentListParams, opts ...option.RequestOption) *shared.SinglePageAutoPager[Payment] { - return shared.NewSinglePageAutoPager(r.List(ctx, query, opts...)) +func (r *HRISPaymentService) ListAutoPaging(ctx context.Context, query HRISPaymentListParams, opts ...option.RequestOption) *pagination.SinglePageAutoPager[Payment] { + return pagination.NewSinglePageAutoPager(r.List(ctx, query, opts...)) } type Payment struct { diff --git a/hrispaystatement.go b/hrispaystatement.go index 500a739..7581aec 100644 --- a/hrispaystatement.go +++ b/hrispaystatement.go @@ -7,6 +7,7 @@ import ( "net/http" "github.com/Finch-API/finch-api-go/internal/apijson" + "github.com/Finch-API/finch-api-go/internal/pagination" "github.com/Finch-API/finch-api-go/internal/param" "github.com/Finch-API/finch-api-go/internal/requestconfig" "github.com/Finch-API/finch-api-go/internal/shared" @@ -35,7 +36,7 @@ func NewHRISPayStatementService(opts ...option.RequestOption) (r *HRISPayStateme // // Deduction and contribution types are supported by the payroll systems that // supports Benefits. -func (r *HRISPayStatementService) GetMany(ctx context.Context, body HRISPayStatementGetManyParams, opts ...option.RequestOption) (res *shared.ResponsesPage[PayStatementResponse], err error) { +func (r *HRISPayStatementService) GetMany(ctx context.Context, body HRISPayStatementGetManyParams, opts ...option.RequestOption) (res *pagination.ResponsesPage[PayStatementResponse], err error) { var raw *http.Response opts = append(r.Options, opts...) opts = append([]option.RequestOption{option.WithResponseInto(&raw)}, opts...) @@ -56,8 +57,8 @@ func (r *HRISPayStatementService) GetMany(ctx context.Context, body HRISPayState // // Deduction and contribution types are supported by the payroll systems that // supports Benefits. -func (r *HRISPayStatementService) GetManyAutoPaging(ctx context.Context, body HRISPayStatementGetManyParams, opts ...option.RequestOption) *shared.ResponsesPageAutoPager[PayStatementResponse] { - return shared.NewResponsesPageAutoPager(r.GetMany(ctx, body, opts...)) +func (r *HRISPayStatementService) GetManyAutoPaging(ctx context.Context, body HRISPayStatementGetManyParams, opts ...option.RequestOption) *pagination.ResponsesPageAutoPager[PayStatementResponse] { + return pagination.NewResponsesPageAutoPager(r.GetMany(ctx, body, opts...)) } type PayStatement struct { diff --git a/internal/shared/pagination.go b/internal/pagination/pagination.go similarity index 97% rename from internal/shared/pagination.go rename to internal/pagination/pagination.go index e7b5203..f81f4e5 100644 --- a/internal/shared/pagination.go +++ b/internal/pagination/pagination.go @@ -1,12 +1,13 @@ // File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. -package shared +package pagination import ( "net/http" "github.com/Finch-API/finch-api-go/internal/apijson" "github.com/Finch-API/finch-api-go/internal/requestconfig" + "github.com/Finch-API/finch-api-go/internal/shared" ) type SinglePage[T any] struct { @@ -194,9 +195,9 @@ func (r *ResponsesPageAutoPager[T]) Index() int { } type Page[T any] struct { - Data []T `json:"data"` - Paging Paging `json:"paging,required"` - JSON pageJSON `json:"-"` + Data []T `json:"data"` + Paging shared.Paging `json:"paging,required"` + JSON pageJSON `json:"-"` cfg *requestconfig.RequestConfig res *http.Response } diff --git a/internal/requestconfig/requestconfig.go b/internal/requestconfig/requestconfig.go index 2565d87..7ca4a3f 100644 --- a/internal/requestconfig/requestconfig.go +++ b/internal/requestconfig/requestconfig.go @@ -386,14 +386,18 @@ func (cfg *RequestConfig) Execute() (err error) { } if res.StatusCode >= 400 { - aerr := apierror.Error{Request: cfg.Request, Response: res, StatusCode: res.StatusCode} contents, err := io.ReadAll(res.Body) + res.Body.Close() if err != nil { return err } + // If there is an APIError, re-populate the response body so that debugging // utilities can conveniently dump the response without issue. res.Body = io.NopCloser(bytes.NewBuffer(contents)) + + // Load the contents into the error format if it is provided. + aerr := apierror.Error{Request: cfg.Request, Response: res, StatusCode: res.StatusCode} err = aerr.UnmarshalJSON(contents) if err != nil { return err diff --git a/jobautomated.go b/jobautomated.go index 9119827..ca3535c 100644 --- a/jobautomated.go +++ b/jobautomated.go @@ -11,9 +11,9 @@ import ( "github.com/Finch-API/finch-api-go/internal/apijson" "github.com/Finch-API/finch-api-go/internal/apiquery" + "github.com/Finch-API/finch-api-go/internal/pagination" "github.com/Finch-API/finch-api-go/internal/param" "github.com/Finch-API/finch-api-go/internal/requestconfig" - "github.com/Finch-API/finch-api-go/internal/shared" "github.com/Finch-API/finch-api-go/option" ) @@ -62,7 +62,7 @@ func (r *JobAutomatedService) Get(ctx context.Context, jobID string, opts ...opt // Get all automated jobs. Automated jobs are completed by a machine. By default, // jobs are sorted in descending order by submission time. For scheduled jobs such // as data syncs, only the next scheduled job is shown. -func (r *JobAutomatedService) List(ctx context.Context, query JobAutomatedListParams, opts ...option.RequestOption) (res *shared.Page[AutomatedAsyncJob], err error) { +func (r *JobAutomatedService) List(ctx context.Context, query JobAutomatedListParams, opts ...option.RequestOption) (res *pagination.Page[AutomatedAsyncJob], err error) { var raw *http.Response opts = append(r.Options, opts...) opts = append([]option.RequestOption{option.WithResponseInto(&raw)}, opts...) @@ -82,8 +82,8 @@ func (r *JobAutomatedService) List(ctx context.Context, query JobAutomatedListPa // Get all automated jobs. Automated jobs are completed by a machine. By default, // jobs are sorted in descending order by submission time. For scheduled jobs such // as data syncs, only the next scheduled job is shown. -func (r *JobAutomatedService) ListAutoPaging(ctx context.Context, query JobAutomatedListParams, opts ...option.RequestOption) *shared.PageAutoPager[AutomatedAsyncJob] { - return shared.NewPageAutoPager(r.List(ctx, query, opts...)) +func (r *JobAutomatedService) ListAutoPaging(ctx context.Context, query JobAutomatedListParams, opts ...option.RequestOption) *pagination.PageAutoPager[AutomatedAsyncJob] { + return pagination.NewPageAutoPager(r.List(ctx, query, opts...)) } type AutomatedAsyncJob struct { diff --git a/provider.go b/provider.go index 55637ee..b91e843 100644 --- a/provider.go +++ b/provider.go @@ -7,8 +7,8 @@ import ( "net/http" "github.com/Finch-API/finch-api-go/internal/apijson" + "github.com/Finch-API/finch-api-go/internal/pagination" "github.com/Finch-API/finch-api-go/internal/requestconfig" - "github.com/Finch-API/finch-api-go/internal/shared" "github.com/Finch-API/finch-api-go/option" ) @@ -30,7 +30,7 @@ func NewProviderService(opts ...option.RequestOption) (r *ProviderService) { } // Return details on all available payroll and HR systems. -func (r *ProviderService) List(ctx context.Context, opts ...option.RequestOption) (res *shared.SinglePage[Provider], err error) { +func (r *ProviderService) List(ctx context.Context, opts ...option.RequestOption) (res *pagination.SinglePage[Provider], err error) { var raw *http.Response opts = append(r.Options, opts...) opts = append([]option.RequestOption{option.WithResponseInto(&raw)}, opts...) @@ -48,8 +48,8 @@ func (r *ProviderService) List(ctx context.Context, opts ...option.RequestOption } // Return details on all available payroll and HR systems. -func (r *ProviderService) ListAutoPaging(ctx context.Context, opts ...option.RequestOption) *shared.SinglePageAutoPager[Provider] { - return shared.NewSinglePageAutoPager(r.List(ctx, opts...)) +func (r *ProviderService) ListAutoPaging(ctx context.Context, opts ...option.RequestOption) *pagination.SinglePageAutoPager[Provider] { + return pagination.NewSinglePageAutoPager(r.List(ctx, opts...)) } type Provider struct { From 43982c96e9676ee691f1fb65c2983945b9635431 Mon Sep 17 00:00:00 2001 From: "stainless-app[bot]" <142633134+stainless-app[bot]@users.noreply.github.com> Date: Fri, 29 Mar 2024 01:02:20 +0000 Subject: [PATCH 11/11] release: 0.16.0 --- .release-please-manifest.json | 2 +- CHANGELOG.md | 25 +++++++++++++++++++++++++ README.md | 2 +- internal/version.go | 2 +- 4 files changed, 28 insertions(+), 3 deletions(-) diff --git a/.release-please-manifest.json b/.release-please-manifest.json index 8f3e0a4..b4e9013 100644 --- a/.release-please-manifest.json +++ b/.release-please-manifest.json @@ -1,3 +1,3 @@ { - ".": "0.15.0" + ".": "0.16.0" } \ No newline at end of file diff --git a/CHANGELOG.md b/CHANGELOG.md index ff9eb73..aeb4e48 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,30 @@ # Changelog +## 0.16.0 (2024-03-29) + +Full Changelog: [v0.15.0...v0.16.0](https://github.com/Finch-API/finch-api-go/compare/v0.15.0...v0.16.0) + +### Features + +* add IsKnown method to enums ([#135](https://github.com/Finch-API/finch-api-go/issues/135)) ([a12efdc](https://github.com/Finch-API/finch-api-go/commit/a12efdce5d7ac1c4486cccfee5c2b83ed99fa279)) +* **client:** implement raw requests methods on client ([#139](https://github.com/Finch-API/finch-api-go/issues/139)) ([0469fdc](https://github.com/Finch-API/finch-api-go/commit/0469fdcad5e8323a6d61419f5190624160f29318)) + + +### Chores + +* **internal:** move pagination types to pagination package ([#140](https://github.com/Finch-API/finch-api-go/issues/140)) ([b4172a5](https://github.com/Finch-API/finch-api-go/commit/b4172a582939c4b111bbc947b8fd228fa6763ef6)) +* **internal:** update generated pragma comment ([#134](https://github.com/Finch-API/finch-api-go/issues/134)) ([5acbf83](https://github.com/Finch-API/finch-api-go/commit/5acbf8307554cc006f6a6cd6c6bdf9c2de039eae)) +* revert temporary commit ([4acd051](https://github.com/Finch-API/finch-api-go/commit/4acd051a9bbc90843d33bc7f99c5035670f6573a)) +* temporary commit ([46f8947](https://github.com/Finch-API/finch-api-go/commit/46f8947f7277ba5c50e91a87c485078ed32235e3)) + + +### Documentation + +* fix typo in CONTRIBUTING.md ([#132](https://github.com/Finch-API/finch-api-go/issues/132)) ([dd445c7](https://github.com/Finch-API/finch-api-go/commit/dd445c72799beab386d9e5e5055381ea0bcfa184)) +* fix typo in docstring for Null() ([#138](https://github.com/Finch-API/finch-api-go/issues/138)) ([da24dc4](https://github.com/Finch-API/finch-api-go/commit/da24dc425772a4ba905931de5bc231d8e90665fa)) +* **readme:** consistent use of sentence case in headings ([#136](https://github.com/Finch-API/finch-api-go/issues/136)) ([2c2438f](https://github.com/Finch-API/finch-api-go/commit/2c2438ffd87570117e560da4dd4410c5c1cccc5b)) +* **readme:** document file uploads ([#137](https://github.com/Finch-API/finch-api-go/issues/137)) ([4fea46d](https://github.com/Finch-API/finch-api-go/commit/4fea46dd3dd728c5ef594a3af2faeea248d3cbbf)) + ## 0.15.0 (2024-03-13) Full Changelog: [v0.14.3...v0.15.0](https://github.com/Finch-API/finch-api-go/compare/v0.14.3...v0.15.0) diff --git a/README.md b/README.md index 82bd482..74298b7 100644 --- a/README.md +++ b/README.md @@ -22,7 +22,7 @@ Or to pin the version: ```sh -go get -u 'github.com/Finch-API/finch-api-go@v0.15.0' +go get -u 'github.com/Finch-API/finch-api-go@v0.16.0' ``` diff --git a/internal/version.go b/internal/version.go index 1f338c3..16d4c3d 100644 --- a/internal/version.go +++ b/internal/version.go @@ -2,4 +2,4 @@ package internal -const PackageVersion = "0.15.0" // x-release-please-version +const PackageVersion = "0.16.0" // x-release-please-version