-
Notifications
You must be signed in to change notification settings - Fork 20
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: Organization Memberships API #231
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package clerk | ||
|
||
import "encoding/json" | ||
|
||
type OrganizationMembership struct { | ||
APIResource | ||
Object string `json:"object"` | ||
ID string `json:"id"` | ||
Organization *Organization `json:"organization"` | ||
Permissions []string `json:"permissions"` | ||
PublicMetadata json.RawMessage `json:"public_metadata"` | ||
PrivateMetadata json.RawMessage `json:"private_metadata"` | ||
Role string `json:"role"` | ||
CreatedAt int64 `json:"created_at"` | ||
UpdatedAt int64 `json:"updated_at"` | ||
PublicUserData *OrganizationMembershipPublicUserData `json:"public_user_data,omitempty"` | ||
} | ||
|
||
type OrganizationMembershipList struct { | ||
APIResource | ||
OrganizationMemberships []*OrganizationMembership `json:"data"` | ||
TotalCount int64 `json:"total_count"` | ||
} | ||
|
||
type OrganizationMembershipPublicUserData struct { | ||
UserID string `json:"user_id"` | ||
FirstName *string `json:"first_name"` | ||
LastName *string `json:"last_name"` | ||
ImageURL *string `json:"image_url"` | ||
HasImage bool `json:"has_image"` | ||
Identifier string `json:"identifier"` | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,145 @@ | ||
// Package organizationmembership provides the Organization Memberships API. | ||
package organizationmembership | ||
|
||
import ( | ||
"context" | ||
"net/http" | ||
"net/url" | ||
|
||
"github.com/clerk/clerk-sdk-go/v2" | ||
) | ||
|
||
//go:generate go run ../cmd/gen/main.go | ||
|
||
const path = "/organizations" | ||
|
||
// Client is used to invoke the Organization Memberships API. | ||
type Client struct { | ||
Backend clerk.Backend | ||
} | ||
|
||
type ClientConfig struct { | ||
clerk.BackendConfig | ||
} | ||
|
||
func NewClient(config *ClientConfig) *Client { | ||
return &Client{ | ||
Backend: clerk.NewBackend(&config.BackendConfig), | ||
} | ||
} | ||
|
||
type CreateParams struct { | ||
clerk.APIParams | ||
UserID *string `json:"user_id,omitempty"` | ||
Role *string `json:"role,omitempty"` | ||
OrganizationID string `json:"-"` | ||
} | ||
|
||
// Create adds a new member to the organization. | ||
func (c *Client) Create(ctx context.Context, params *CreateParams) (*clerk.OrganizationMembership, error) { | ||
path, err := clerk.JoinPath(path, params.OrganizationID, "/memberships") | ||
if err != nil { | ||
return nil, err | ||
} | ||
req := clerk.NewAPIRequest(http.MethodPost, path) | ||
req.SetParams(params) | ||
membership := &clerk.OrganizationMembership{} | ||
err = c.Backend.Call(ctx, req, membership) | ||
return membership, err | ||
} | ||
|
||
type UpdateParams struct { | ||
clerk.APIParams | ||
Role *string `json:"role,omitempty"` | ||
OrganizationID string `json:"-"` | ||
UserID string `json:"-"` | ||
} | ||
|
||
// Update updates an organization membership. | ||
func (c *Client) Update(ctx context.Context, params *UpdateParams) (*clerk.OrganizationMembership, error) { | ||
path, err := clerk.JoinPath(path, params.OrganizationID, "/memberships", params.UserID) | ||
if err != nil { | ||
return nil, err | ||
} | ||
req := clerk.NewAPIRequest(http.MethodPatch, path) | ||
req.SetParams(params) | ||
membership := &clerk.OrganizationMembership{} | ||
err = c.Backend.Call(ctx, req, membership) | ||
return membership, err | ||
} | ||
|
||
type DeleteParams struct { | ||
clerk.APIParams | ||
OrganizationID string `json:"-"` | ||
UserID string `json:"-"` | ||
} | ||
|
||
// Delete removes a member from an organization. | ||
func (c *Client) Delete(ctx context.Context, params *DeleteParams) (*clerk.OrganizationMembership, error) { | ||
path, err := clerk.JoinPath(path, params.OrganizationID, "/memberships", params.UserID) | ||
if err != nil { | ||
return nil, err | ||
} | ||
req := clerk.NewAPIRequest(http.MethodDelete, path) | ||
membership := &clerk.OrganizationMembership{} | ||
err = c.Backend.Call(ctx, req, membership) | ||
return membership, err | ||
} | ||
|
||
type ListParams struct { | ||
clerk.APIParams | ||
clerk.ListParams | ||
OrderBy *string `json:"order_by,omitempty"` | ||
Query *string `json:"query,omitempty"` | ||
Roles []string `json:"role,omitempty"` | ||
UserIDs []string `json:"user_id,omitempty"` | ||
EmailAddresses []string `json:"email_address,omitempty"` | ||
PhoneNumbers []string `json:"phone_number,omitempty"` | ||
Usernames []string `json:"username,omitempty"` | ||
Web3Wallets []string `json:"web3_wallet,omitempty"` | ||
OrganizationID string `json:"-"` | ||
} | ||
|
||
// ToQuery returns the parameters as url.Values so they can be used | ||
// in a URL query string. | ||
func (params *ListParams) ToQuery() url.Values { | ||
q := params.ListParams.ToQuery() | ||
if params.OrderBy != nil { | ||
q.Set("order_by", *params.OrderBy) | ||
} | ||
if params.Query != nil { | ||
q.Set("query", *params.Query) | ||
} | ||
if params.Roles != nil { | ||
q["role"] = params.Roles | ||
} | ||
if params.UserIDs != nil { | ||
q["user_id"] = params.UserIDs | ||
} | ||
if params.EmailAddresses != nil { | ||
q["email_address"] = params.EmailAddresses | ||
} | ||
if params.PhoneNumbers != nil { | ||
q["phone_number"] = params.PhoneNumbers | ||
} | ||
if params.Usernames != nil { | ||
q["username"] = params.Usernames | ||
} | ||
if params.Web3Wallets != nil { | ||
q["web3_wallet"] = params.Web3Wallets | ||
} | ||
return q | ||
} | ||
|
||
// List returns a list of organization memberships. | ||
func (c *Client) List(ctx context.Context, params *ListParams) (*clerk.OrganizationMembershipList, error) { | ||
path, err := clerk.JoinPath(path, params.OrganizationID, "/memberships") | ||
if err != nil { | ||
return nil, err | ||
} | ||
req := clerk.NewAPIRequest(http.MethodGet, path) | ||
req.SetParams(params) | ||
list := &clerk.OrganizationMembershipList{} | ||
err = c.Backend.Call(ctx, req, list) | ||
return list, err | ||
} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@georgepsarakis I think you've voiced a concern about "array" parameters in the query string and how using
Set
won't work with them.Your instinct was right. We need to add values and not overwrite them in order to support arrays.