stytchauth / stytch-go

Official Stytch Backend SDK for Go
MIT License
47 stars 10 forks source link

doc: Mark Users.GetPending as deprecated #118

Closed jeremy-stytch closed 1 year ago

jeremy-stytch commented 1 year ago

With the Users Search endpoint, you can get all of your pending users by adding a Status: "pending" filter. This can replace any and all existing calls to the Get Pending Users endpoint.

The Search method also supports more filters to further constrain results. This library also provides a SearchAll convenience helper for iterating through all the results of a search.

We'd like to remove the GetPending method from this library to limit our maintenance work and remove some complexity for customers.

This marks the GetPending method as deprecated. It will be removed in the next major version of stytch-go.

Migration Guide

This migrates from GetPending to SearchAll, which has a cleaner iteration pattern:

Before

ctx := context.TODO()

params := &b2c.UsersGetPendingParams{
    Limit: 200,
}

res, err := client.Users.GetPending(ctx, params)
if err != nil {
    panic(err)
}

// TODO: Do something with res.Users

for res.HasMore {
    params.StartingAfterID = res.StartingAfterID

    res, err = client.Users.GetPending(ctx, params)
    if err != nil {
        panic(err)
    }

    // TODO: Do something with res.Users
}

After

ctx := context.TODO()

params := &b2c.UsersSearchParams{
    Limit: 200,
    Query: &b2c.UsersSearchQuery{
        Operator: b2c.UserSearchOperatorOR,
        Operands: []json.Marshaler{
            b2c.UsersSearchQueryStatusFilter{Status: "pending"},
        },
    },
}

pendingUsers := client.Users.SearchAll(params)

for pendingUsers.HasNext() {
    users, err := pendingUsers.Next(ctx)
    if err != nil {
        panic(err)
    }

    // TODO: Do something with users
}

If you prefer to keep the same iteration pattern that GetPending has, use Search directly instead:

ctx := context.TODO()

params := &b2c.UsersSearchParams{
    Limit: 200,
    Query: &b2c.UsersSearchQuery{
        Operator: b2c.UserSearchOperatorOR,
        Operands: []json.Marshaler{
            b2c.UsersSearchQueryStatusFilter{Status: "pending"},
        },
    },
}

res, err := client.Users.Search(ctx, params)
if err != nil {
    panic(err)
}

// TODO: Do something with res.Results

for res.ResultsMetadata.NextCursor != "" {
    params.Cursor = res.ResultsMetadata.NextCursor

    res, err = client.Users.Search(ctx, params)
    if err != nil {
        panic(err)
    }

    // TODO: Do something with res.Results
}