From 9c99e6afa79e8d2231cb3e854a440aae58a4dce4 Mon Sep 17 00:00:00 2001 From: Nikos Polykandriotis Date: Sat, 18 Nov 2023 00:42:14 +0200 Subject: [PATCH] feat: drop create sms endpoint This feature is beeing dropped from the Backend API. For a brief period it will still be available for instances that have used it in the past 7 days (13-11-2023 to 20-11-2023). New instances will get a 403 forbidden response if they try to access it. --- clerk/clerk.go | 8 ----- clerk/sms.go | 34 --------------------- clerk/sms_test.go | 57 ----------------------------------- tests/integration/sms_test.go | 35 --------------------- 4 files changed, 134 deletions(-) delete mode 100644 clerk/sms.go delete mode 100644 clerk/sms_test.go delete mode 100644 tests/integration/sms_test.go diff --git a/clerk/clerk.go b/clerk/clerk.go index 19f0ef77..6d853e61 100644 --- a/clerk/clerk.go +++ b/clerk/clerk.go @@ -36,7 +36,6 @@ const ( RedirectURLsUrl = "redirect_urls" SAMLConnectionsUrl = "saml_connections" SessionsUrl = "sessions" - SMSUrl = "sms_messages" TemplatesUrl = "templates" UsersUrl = "users" UsersCountUrl = UsersUrl + "/count" @@ -69,7 +68,6 @@ type Client interface { RedirectURLs() *RedirectURLsService SAMLConnections() *SAMLConnectionsService Sessions() *SessionsService - SMS() *SMSService Templates() *TemplatesService Users() *UsersService Webhooks() *WebhooksService @@ -105,7 +103,6 @@ type client struct { redirectURLs *RedirectURLsService samlConnections *SAMLConnectionsService sessions *SessionsService - sms *SMSService templates *TemplatesService users *UsersService webhooks *WebhooksService @@ -154,7 +151,6 @@ func NewClient(token string, options ...ClerkOption) (Client, error) { client.redirectURLs = (*RedirectURLsService)(commonService) client.samlConnections = (*SAMLConnectionsService)(commonService) client.sessions = (*SessionsService)(commonService) - client.sms = (*SMSService)(commonService) client.templates = (*TemplatesService)(commonService) client.users = (*UsersService)(commonService) client.webhooks = (*WebhooksService)(commonService) @@ -331,10 +327,6 @@ func (c *client) Sessions() *SessionsService { return c.sessions } -func (c *client) SMS() *SMSService { - return c.sms -} - func (c *client) Templates() *TemplatesService { return c.templates } diff --git a/clerk/sms.go b/clerk/sms.go deleted file mode 100644 index 3f9cf66e..00000000 --- a/clerk/sms.go +++ /dev/null @@ -1,34 +0,0 @@ -package clerk - -import ( - "encoding/json" -) - -type SMSService service - -type SMSMessage struct { - Message string `json:"message"` - PhoneNumberID string `json:"phone_number_id"` -} - -type SMSMessageResponse struct { - Object string `json:"object"` - ID string `json:"id"` - FromPhoneNumber string `json:"from_phone_number"` - ToPhoneNumber *string `json:"to_phone_number,omitempty"` - Status string `json:"status"` - DeliveredByClerk bool `json:"delivered_by_clerk"` - Data json.RawMessage `json:"data"` - SMSMessage -} - -func (s *SMSService) Create(message SMSMessage) (*SMSMessageResponse, error) { - req, _ := s.client.NewRequest("POST", SMSUrl, &message) - - var smsResponse SMSMessageResponse - _, err := s.client.Do(req, &smsResponse) - if err != nil { - return nil, err - } - return &smsResponse, nil -} diff --git a/clerk/sms_test.go b/clerk/sms_test.go deleted file mode 100644 index 9ae8eaa3..00000000 --- a/clerk/sms_test.go +++ /dev/null @@ -1,57 +0,0 @@ -package clerk - -import ( - "encoding/json" - "fmt" - "net/http" - "reflect" - "testing" -) - -func TestSMSService_Create_happyPath(t *testing.T) { - token := "token" - var message SMSMessage - _ = json.Unmarshal([]byte(dummySMSMessageResponseJson), &message) - - client, mux, _, teardown := setup(token) - defer teardown() - - mux.HandleFunc("/sms_messages", func(w http.ResponseWriter, req *http.Request) { - testHttpMethod(t, req, "POST") - testHeader(t, req, "Authorization", "Bearer "+token) - fmt.Fprint(w, dummySMSMessageResponseJson) - }) - - got, _ := client.SMS().Create(message) - - var want SMSMessageResponse - _ = json.Unmarshal([]byte(dummySMSMessageResponseJson), &want) - - if !reflect.DeepEqual(*got, want) { - t.Errorf("Response = %v, want %v", *got, message) - } -} - -func TestSMSService_Create_invalidServer(t *testing.T) { - client, _ := NewClient("token") - - var message SMSMessage - _ = json.Unmarshal([]byte(dummySMSMessageResponseJson), &message) - - _, err := client.SMS().Create(message) - if err == nil { - t.Errorf("Expected error to be returned") - } -} - -const dummySMSMessageResponseJson = `{ - "from_phone_number": "12345678", - "id": "sms_1mvjlpmFtRaoee3pm7lS8c3NuAX", - "message": "This is a test message", - "object": "sms_message", - "phone_number_id": "idn_1mebQ9KkZWrhb9rL6iEiXQGF8Yj", - "status": "queued", - "to_phone_number": "87654321", - "data": { "baz": "xyz" }, - "delivered_by_clerk": true -}` diff --git a/tests/integration/sms_test.go b/tests/integration/sms_test.go deleted file mode 100644 index f677a195..00000000 --- a/tests/integration/sms_test.go +++ /dev/null @@ -1,35 +0,0 @@ -//go:build integration -// +build integration - -package integration - -import ( - "testing" - - "github.com/clerkinc/clerk-sdk-go/clerk" -) - -func TestSMS(t *testing.T) { - client := createClient() - - users, _ := client.Users().ListAll(clerk.ListAllUsersParams{}) - if users == nil || len(users) == 0 { - return - } - - user := users[0] - - if user.PrimaryPhoneNumberID == nil { - return - } - - message := clerk.SMSMessage{ - Message: "Go SDK test message", - PhoneNumberID: *user.PrimaryPhoneNumberID, - } - - _, err := client.SMS().Create(message) - if err != nil { - t.Fatalf("SMS.Create returned error: %v", err) - } -}