Skip to content

Commit

Permalink
refactor: refactored dynamic options fn signature
Browse files Browse the repository at this point in the history
Signed-off-by: Rubicon Lee <rex@wakflo.com>
  • Loading branch information
raff-wakflo committed Nov 24, 2024
1 parent 50fc01f commit d4f1747
Show file tree
Hide file tree
Showing 29 changed files with 205 additions and 205 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ require (
github.com/opus-domini/fast-shot v1.1.2
github.com/rs/zerolog v1.33.0
github.com/shopspring/decimal v1.4.0
github.com/wakflo/go-sdk v0.7.2
github.com/wakflo/go-sdk v0.8.0
golang.org/x/oauth2 v0.20.0
google.golang.org/api v0.181.0
)
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -188,8 +188,8 @@ github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsT
github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
github.com/vektah/gqlparser/v2 v2.5.11 h1:JJxLtXIoN7+3x6MBdtIP59TP1RANnY7pXOaDnADQSf8=
github.com/vektah/gqlparser/v2 v2.5.11/go.mod h1:1rCcfwB2ekJofmluGWXMSEnPMZgbxzwj6FaZ/4OT8Cc=
github.com/wakflo/go-sdk v0.7.2 h1:Yq39uMKhwY9+OMN4MIwKTLfQk4SmS2xDqsQpfp2mrIs=
github.com/wakflo/go-sdk v0.7.2/go.mod h1:m7L9EX6ndBYzKLcoONrb4EBVPtCsqbE4VGvifCwJoBM=
github.com/wakflo/go-sdk v0.8.0 h1:D2/8/slxK5es3GWptzwyWVy9ZY+xL6OxJS/NrrBdkbk=
github.com/wakflo/go-sdk v0.8.0/go.mod h1:yqyuXMQlVHMsKdJGww//yUzinRq8BWzvIgcG4P66XrE=
github.com/xo/terminfo v0.0.0-20220910002029-abceb7e1c41e h1:JVG44RsyaB9T2KIHavMF/ppJZNG9ZpyihvCd0w101no=
github.com/xo/terminfo v0.0.0-20220910002029-abceb7e1c41e/go.mod h1:RbqR21r5mrJuqunuUZ/Dhy/avygyECGrLceyNeo4LiM=
go.opencensus.io v0.24.0 h1:y73uSU6J157QMP2kn2r30vwW1A2W2WFwSCGnAVxeaD0=
Expand Down
22 changes: 10 additions & 12 deletions internal/connectors/airtable/shared.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ var sharedAuth = autoform.NewCustomAuthField().
var baseAPI = "https://api.airtable.com"

func getBasesInput() *sdkcore.AutoFormSchema {
getBases := func(ctx *sdkcore.DynamicFieldContext) (interface{}, error) {
getBases := func(ctx *sdkcore.DynamicFieldContext) (*sdkcore.DynamicOptionsResponse, error) {
client := fastshot.NewClient(baseAPI).
Auth().BearerToken(ctx.Auth.Extra["api-key"]).
Header().
Expand All @@ -62,15 +62,13 @@ func getBasesInput() *sdkcore.AutoFormSchema {
return nil, err
}

var bases Response
err = json.Unmarshal(bytes, &bases)
var baseRsp Response
err = json.Unmarshal(bytes, &baseRsp)
if err != nil {
return nil, err
}

base := bases.Bases

return base, nil
return ctx.Respond(baseRsp.Bases, len(baseRsp.Bases))
}

return autoform.NewDynamicField(sdkcore.String).
Expand All @@ -82,7 +80,7 @@ func getBasesInput() *sdkcore.AutoFormSchema {
}

func getTablesInput() *sdkcore.AutoFormSchema {
getTables := func(ctx *sdkcore.DynamicFieldContext) (interface{}, error) {
getTables := func(ctx *sdkcore.DynamicFieldContext) (*sdkcore.DynamicOptionsResponse, error) {
input := sdk.DynamicInputToType[struct {
Bases string `json:"bases"`
}](ctx)
Expand Down Expand Up @@ -114,7 +112,7 @@ func getTablesInput() *sdkcore.AutoFormSchema {
return nil, err
}

return bases.Tables, nil
return ctx.Respond(bases.Tables, len(bases.Tables))
}

return autoform.NewDynamicField(sdkcore.String).
Expand All @@ -126,7 +124,7 @@ func getTablesInput() *sdkcore.AutoFormSchema {
}

func getFieldsInput() *sdkcore.AutoFormSchema {
getFields := func(ctx *sdkcore.DynamicFieldContext) (interface{}, error) {
getFields := func(ctx *sdkcore.DynamicFieldContext) (*sdkcore.DynamicOptionsResponse, error) {
input := sdk.DynamicInputToType[struct {
Bases string `json:"bases"`
Table string `json:"table"`
Expand Down Expand Up @@ -167,7 +165,7 @@ func getFieldsInput() *sdkcore.AutoFormSchema {
}
}

return selectedTable.Fields, nil
return ctx.Respond(selectedTable.Fields, len(selectedTable.Fields))
}

return autoform.NewDynamicField(sdkcore.String).
Expand All @@ -178,7 +176,7 @@ func getFieldsInput() *sdkcore.AutoFormSchema {
}

func getViewsInput() *sdkcore.AutoFormSchema {
getViews := func(ctx *sdkcore.DynamicFieldContext) (interface{}, error) {
getViews := func(ctx *sdkcore.DynamicFieldContext) (*sdkcore.DynamicOptionsResponse, error) {
input := sdk.DynamicInputToType[struct {
Bases string `json:"bases"`
Table string `json:"table"`
Expand Down Expand Up @@ -219,7 +217,7 @@ func getViewsInput() *sdkcore.AutoFormSchema {
}
}

return selectedTable.Views, nil
return ctx.Respond(selectedTable.Views, len(selectedTable.Views))
}

return autoform.NewDynamicField(sdkcore.String).
Expand Down
15 changes: 9 additions & 6 deletions internal/connectors/asana/shared.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ var (
var baseAPI = "https://app.asana.com/api/1.0"

func getWorkspacesInput() *sdkcore.AutoFormSchema {
getWorkspaces := func(ctx *sdkcore.DynamicFieldContext) (interface{}, error) {
getWorkspaces := func(ctx *sdkcore.DynamicFieldContext) (*sdkcore.DynamicOptionsResponse, error) {
client := fastshot.NewClient(baseAPI).
Auth().BearerToken(ctx.Auth.AccessToken).
Header().
Expand Down Expand Up @@ -64,12 +64,13 @@ func getWorkspacesInput() *sdkcore.AutoFormSchema {
}

workspace := workspaces.Data
return arrutil.Map[Workspace, map[string]any](workspace, func(input Workspace) (target map[string]any, find bool) {
items := arrutil.Map[Workspace, map[string]any](workspace, func(input Workspace) (target map[string]any, find bool) {
return map[string]any{
"id": input.GID,
"name": input.Name,
}, true
}), nil
})
return ctx.Respond(items, len(items))
}

return autoform.NewDynamicField(sdkcore.String).
Expand All @@ -81,7 +82,7 @@ func getWorkspacesInput() *sdkcore.AutoFormSchema {
}

func getProjectsInput() *sdkcore.AutoFormSchema {
getProjects := func(ctx *sdkcore.DynamicFieldContext) (interface{}, error) {
getProjects := func(ctx *sdkcore.DynamicFieldContext) (*sdkcore.DynamicOptionsResponse, error) {
qu := fastshot.NewClient(baseAPI).
Auth().BearerToken(ctx.Auth.AccessToken).
Header().
Expand Down Expand Up @@ -111,12 +112,14 @@ func getProjectsInput() *sdkcore.AutoFormSchema {

projects := response.Data

return arrutil.Map[Project, map[string]any](projects, func(input Project) (target map[string]any, find bool) {
items := arrutil.Map[Project, map[string]any](projects, func(input Project) (target map[string]any, find bool) {
return map[string]any{
"id": input.GID,
"name": input.Name,
}, true
}), nil
})

return ctx.Respond(items, len(items))
}

return autoform.NewDynamicField(sdkcore.String).
Expand Down
22 changes: 13 additions & 9 deletions internal/connectors/calendly/shared.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ var (
const baseURL = "https://api.calendly.com"

func getCurrentCalendlyUserInput(title string, desc string, required bool) *sdkcore.AutoFormSchema {
getCurrentUser := func(ctx *sdkcore.DynamicFieldContext) (interface{}, error) {
getCurrentUser := func(ctx *sdkcore.DynamicFieldContext) (*sdkcore.DynamicOptionsResponse, error) {
client := fastshot.NewClient(baseURL).
Auth().BearerToken(ctx.Auth.AccessToken).
Header().
Expand Down Expand Up @@ -58,12 +58,12 @@ func getCurrentCalendlyUserInput(title string, desc string, required bool) *sdkc

user := body.Resource

return []map[string]any{
return ctx.Respond([]map[string]any{
{
"id": user.URI,
"name": user.Name,
},
}, nil
}, 1)
}

return autoform.NewDynamicField(sdkcore.String).
Expand All @@ -74,7 +74,7 @@ func getCurrentCalendlyUserInput(title string, desc string, required bool) *sdkc
}

func getCalendlyEventInput(title string, desc string, required bool) *sdkcore.AutoFormSchema {
getEvents := func(ctx *sdkcore.DynamicFieldContext) (interface{}, error) {
getEvents := func(ctx *sdkcore.DynamicFieldContext) (*sdkcore.DynamicOptionsResponse, error) {
input := sdk.DynamicInputToType[struct {
User string `json:"user"`
}](ctx)
Expand Down Expand Up @@ -112,14 +112,16 @@ func getCalendlyEventInput(title string, desc string, required bool) *sdkcore.Au
}
events := body.Events

return arrutil.Map[Event, map[string]any](events, func(input Event) (target map[string]any, find bool) {
items := arrutil.Map[Event, map[string]any](events, func(input Event) (target map[string]any, find bool) {
return map[string]any{
"id": input.URI,
"name": input.Name,
"start": input.StartTime,
"end": input.EndTime,
}, true
}), nil
})

return ctx.Respond(items, len(items))
}

return autoform.NewDynamicField(sdkcore.String).
Expand All @@ -131,7 +133,7 @@ func getCalendlyEventInput(title string, desc string, required bool) *sdkcore.Au
}

func getCalendlyEventTypeInput(title string, desc string, required bool) *sdkcore.AutoFormSchema {
getEventTypes := func(ctx *sdkcore.DynamicFieldContext) (interface{}, error) {
getEventTypes := func(ctx *sdkcore.DynamicFieldContext) (*sdkcore.DynamicOptionsResponse, error) {
input := sdk.DynamicInputToType[struct {
User string `json:"user"`
}](ctx)
Expand Down Expand Up @@ -168,12 +170,14 @@ func getCalendlyEventTypeInput(title string, desc string, required bool) *sdkcor
return nil, err
}

return arrutil.Map[EventType, map[string]any](body.Collection, func(input EventType) (target map[string]any, find bool) {
items := arrutil.Map[EventType, map[string]any](body.Collection, func(input EventType) (target map[string]any, find bool) {
return map[string]any{
"id": input.URI,
"name": input.Name,
}, true
}), nil
})

return ctx.Respond(items, len(items))
}

return autoform.NewDynamicField(sdkcore.String).
Expand Down
39 changes: 15 additions & 24 deletions internal/connectors/clickup/shared.go
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ func getTeams(accessToken string) ([]Team, error) {
}

func getWorkSpaceInput(title string, desc string, required bool) *sdkcore.AutoFormSchema {
getWorkspaces := func(ctx *sdkcore.DynamicFieldContext) (interface{}, error) {
getWorkspaces := func(ctx *sdkcore.DynamicFieldContext) (*sdkcore.DynamicOptionsResponse, error) {
client := fastshot.NewClient(baseURL).
Auth().BearerToken(ctx.Auth.AccessToken).
Header().
Expand Down Expand Up @@ -223,10 +223,7 @@ func getWorkSpaceInput(title string, desc string, required bool) *sdkcore.AutoFo
if err != nil {
return nil, err
}

teams := body.Teams

return teams, nil
return ctx.Respond(body.Teams, len(body.Teams))
}

return autoform.NewDynamicField(sdkcore.String).
Expand All @@ -237,7 +234,7 @@ func getWorkSpaceInput(title string, desc string, required bool) *sdkcore.AutoFo
}

func getSpacesInput(title string, desc string, required bool) *sdkcore.AutoFormSchema {
getSpaces := func(ctx *sdkcore.DynamicFieldContext) (interface{}, error) {
getSpaces := func(ctx *sdkcore.DynamicFieldContext) (*sdkcore.DynamicOptionsResponse, error) {
input := sdk.DynamicInputToType[struct {
WorkspaceID string `json:"workspace-id,omitempty"`
}](ctx)
Expand Down Expand Up @@ -272,9 +269,7 @@ func getSpacesInput(title string, desc string, required bool) *sdkcore.AutoFormS
return nil, err
}

spaces := body.Spaces

return spaces, nil
return ctx.Respond(body.Spaces, len(body.Spaces))
}

return autoform.NewDynamicField(sdkcore.String).
Expand All @@ -285,7 +280,7 @@ func getSpacesInput(title string, desc string, required bool) *sdkcore.AutoFormS
}

func getFoldersInput(title string, desc string, required bool) *sdkcore.AutoFormSchema {
getFolders := func(ctx *sdkcore.DynamicFieldContext) (interface{}, error) {
getFolders := func(ctx *sdkcore.DynamicFieldContext) (*sdkcore.DynamicOptionsResponse, error) {
input := sdk.DynamicInputToType[struct {
SpaceID string `json:"space-id,omitempty"`
}](ctx)
Expand Down Expand Up @@ -320,9 +315,7 @@ func getFoldersInput(title string, desc string, required bool) *sdkcore.AutoForm
return nil, err
}

folders := body.Folders

return folders, nil
return ctx.Respond(body.Folders, len(body.Folders))
}

return autoform.NewDynamicField(sdkcore.String).
Expand All @@ -333,7 +326,7 @@ func getFoldersInput(title string, desc string, required bool) *sdkcore.AutoForm
}

func getListsInput(title string, desc string, required bool) *sdkcore.AutoFormSchema {
getLists := func(ctx *sdkcore.DynamicFieldContext) (interface{}, error) {
getLists := func(ctx *sdkcore.DynamicFieldContext) (*sdkcore.DynamicOptionsResponse, error) {
input := sdk.DynamicInputToType[struct {
FolderID string `json:"folder-id,omitempty"`
}](ctx)
Expand Down Expand Up @@ -368,9 +361,7 @@ func getListsInput(title string, desc string, required bool) *sdkcore.AutoFormSc
return nil, err
}

lists := body.Lists

return lists, nil
return ctx.Respond(body.Lists, len(body.Lists))
}

return autoform.NewDynamicField(sdkcore.String).
Expand All @@ -381,7 +372,7 @@ func getListsInput(title string, desc string, required bool) *sdkcore.AutoFormSc
}

func getTasksInput(title string, desc string, required bool) *sdkcore.AutoFormSchema {
getTasks := func(ctx *sdkcore.DynamicFieldContext) (interface{}, error) {
getTasks := func(ctx *sdkcore.DynamicFieldContext) (*sdkcore.DynamicOptionsResponse, error) {
input := sdk.DynamicInputToType[struct {
ListID string `json:"list-id,omitempty"`
}](ctx)
Expand Down Expand Up @@ -415,9 +406,7 @@ func getTasksInput(title string, desc string, required bool) *sdkcore.AutoFormSc
return nil, err
}

tasks := body.Tasks

return tasks, nil
return ctx.Respond(body.Tasks, len(body.Tasks))
}

return autoform.NewDynamicField(sdkcore.String).
Expand All @@ -428,7 +417,7 @@ func getTasksInput(title string, desc string, required bool) *sdkcore.AutoFormSc
}

func getAssigneeInput(title string, desc string, required bool) *sdkcore.AutoFormSchema {
getAssignees := func(ctx *sdkcore.DynamicFieldContext) (interface{}, error) {
getAssignees := func(ctx *sdkcore.DynamicFieldContext) (*sdkcore.DynamicOptionsResponse, error) {
input := sdk.DynamicInputToType[struct {
ListID string `json:"list-id,omitempty"`
}](ctx)
Expand Down Expand Up @@ -465,12 +454,14 @@ func getAssigneeInput(title string, desc string, required bool) *sdkcore.AutoFor

members := body.Members

return arrutil.Map[Member, map[string]any](members, func(input Member) (target map[string]any, find bool) {
items := arrutil.Map[Member, map[string]any](members, func(input Member) (target map[string]any, find bool) {
return map[string]any{
"id": input.ID,
"name": input.Username,
}, true
}), nil
})

return ctx.Respond(items, len(items))
}

return autoform.NewDynamicField(sdkcore.String).
Expand Down
8 changes: 5 additions & 3 deletions internal/connectors/freshdesk/shared.go
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ func GetTicket(baseURL, apiKey, ticketID string) (interface{}, error) {
}

func getTicketInput() *sdkcore.AutoFormSchema {
getTickets := func(ctx *sdkcore.DynamicFieldContext) (interface{}, error) {
getTickets := func(ctx *sdkcore.DynamicFieldContext) (*sdkcore.DynamicOptionsResponse, error) {
baseAPI := "https://" + ctx.Auth.Extra["domain"] + ".freshdesk.com"
qu := fastshot.NewClient(baseAPI).
Auth().BasicAuth(ctx.Auth.Extra["api-key"], "X").
Expand Down Expand Up @@ -286,12 +286,14 @@ func getTicketInput() *sdkcore.AutoFormSchema {
return nil, err
}

return arrutil.Map[Ticket, map[string]any](tickets, func(input Ticket) (target map[string]any, find bool) {
items := arrutil.Map[Ticket, map[string]any](tickets, func(input Ticket) (target map[string]any, find bool) {
return map[string]any{
"id": input.ID,
"name": input.Subject,
}, true
}), nil
})

return ctx.Respond(items, len(items))
}

return autoform.NewDynamicField(sdkcore.String).
Expand Down
Loading

0 comments on commit d4f1747

Please sign in to comment.