diff --git a/invitation.go b/invitation.go index 86afef5..d94a6bc 100644 --- a/invitation.go +++ b/invitation.go @@ -11,6 +11,7 @@ type Invitation struct { Revoked bool `json:"revoked,omitempty"` Status string `json:"status"` URL string `json:"url,omitempty"` + ExpiresAt *int64 `json:"expires_at"` CreatedAt int64 `json:"created_at"` UpdatedAt int64 `json:"updated_at"` } diff --git a/invitation/client.go b/invitation/client.go index 87c70f1..4ac0099 100644 --- a/invitation/client.go +++ b/invitation/client.go @@ -64,6 +64,7 @@ type CreateParams struct { RedirectURL *string `json:"redirect_url,omitempty"` Notify *bool `json:"notify,omitempty"` IgnoreExisting *bool `json:"ignore_existing,omitempty"` + ExpiresInDays *int64 `json:"expires_in_days,omitempty"` } // Create adds a new identifier to the allowlist. diff --git a/invitation/invitation_test.go b/invitation/invitation_test.go index a2b2abd..9f8e5fb 100644 --- a/invitation/invitation_test.go +++ b/invitation/invitation_test.go @@ -110,6 +110,33 @@ func TestInvitationCreate(t *testing.T) { require.Equal(t, emailAddress, invitation.EmailAddress) } +func TestInvitationCreateWithExpiration(t *testing.T) { + emailAddress := "foo@bar.com" + id := "inv_123" + expiresInDays := int64(7) + expiresAt := int64(1700000000) + clerk.SetBackend(clerk.NewBackend(&clerk.BackendConfig{ + HTTPClient: &http.Client{ + Transport: &clerktest.RoundTripper{ + T: t, + In: json.RawMessage(fmt.Sprintf(`{"email_address":"%s","expires_in_days":%d}`, emailAddress, expiresInDays)), + Out: json.RawMessage(fmt.Sprintf(`{"id":"%s","email_address":"%s","expires_at":%d}`, id, emailAddress, expiresAt)), + Method: http.MethodPost, + Path: "/v1/invitations", + }, + }, + })) + + invitation, err := Create(context.Background(), &CreateParams{ + EmailAddress: emailAddress, + ExpiresInDays: &expiresInDays, + }) + require.NoError(t, err) + require.Equal(t, id, invitation.ID) + require.Equal(t, emailAddress, invitation.EmailAddress) + require.Equal(t, expiresAt, *invitation.ExpiresAt) +} + func TestInvitationCreate_Error(t *testing.T) { clerk.SetBackend(clerk.NewBackend(&clerk.BackendConfig{ HTTPClient: &http.Client{