Skip to content

Commit

Permalink
fix: implement flexport connector
Browse files Browse the repository at this point in the history
  • Loading branch information
jaymesC committed Oct 19, 2024
1 parent 290bd5b commit 790e4ae
Show file tree
Hide file tree
Showing 8 changed files with 466 additions and 0 deletions.
2 changes: 2 additions & 0 deletions connectors.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import (
"github.com/wakflo/extensions/internal/connectors/delay"
"github.com/wakflo/extensions/internal/connectors/dropbox"
"github.com/wakflo/extensions/internal/connectors/easyship"
"github.com/wakflo/extensions/internal/connectors/flexport"
"github.com/wakflo/extensions/internal/connectors/freshdesk"
"github.com/wakflo/extensions/internal/connectors/freshworkscrm"
googledocs "github.com/wakflo/extensions/internal/connectors/google_docs"
Expand Down Expand Up @@ -105,6 +106,7 @@ func RegisterConnectors() []*sdk.ConnectorPlugin {
openai.NewConnector, // OpenAI
googlecalendar.NewConnector, // Google Calendar
zoom.NewConnector, // Zoom
flexport.NewConnector, // Flexport
}

// 🛑Do-Not-Edit
Expand Down
38 changes: 38 additions & 0 deletions internal/connectors/flexport/lib.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
// Copyright 2022-present Wakflo
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package flexport

import (
sdk "github.com/wakflo/go-sdk/connector"
)

func NewConnector() (*sdk.ConnectorPlugin, error) {
return sdk.CreateConnector(&sdk.CreateConnectorArgs{
Name: "Flexport",
Description: "platform that coordinates global logistics from factory to customer door ",
Logo: "twemoji:small-airplane",
Version: "0.0.1",
Category: sdk.Apps,
Authors: []string{"Wakflo <integrations@wakflo.com>"},
Triggers: []sdk.ITrigger{},
Operations: []sdk.IOperation{
NewGetProductsOperation(),
NewGetOrderOperation(),
NewGetOrderByExternalIDOperation(),
NewGetShipmentOperation(),
NewCancelOrderOperation(),
},
})
}
73 changes: 73 additions & 0 deletions internal/connectors/flexport/operation_cancel_order.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
// Copyright 2022-present Wakflo
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package flexport

import (
"fmt"
"net/http"

"github.com/wakflo/go-sdk/autoform"
sdk "github.com/wakflo/go-sdk/connector"
sdkcore "github.com/wakflo/go-sdk/core"
)

type cancelOrderOperationProps struct {
OrderID string `json:"Id"`
}

type CancelOrderOperation struct {
options *sdk.OperationInfo
}

func NewCancelOrderOperation() *CancelOrderOperation {
return &CancelOrderOperation{
options: &sdk.OperationInfo{
Name: "Cancel Order",
Description: "Cancel Order",
Auth: sharedAuth,
Input: map[string]*sdkcore.AutoFormSchema{
"Id": autoform.NewShortTextField().
SetDisplayName("Order ID").
SetDescription("Order ID").
SetRequired(true).Build(),
},
SampleOutput: map[string]interface{}{},
ErrorSettings: sdkcore.StepErrorSettings{
ContinueOnError: false,
RetryOnError: false,
},
RequireAuth: true,
},
}
}

func (c *CancelOrderOperation) Run(ctx *sdk.RunContext) (sdk.JSON, error) {
input := sdk.InputToType[cancelOrderOperationProps](ctx)

reqURL := fmt.Sprintf("https://logistics-api.flexport.com/logistics/api/2024-07/orders/%s/cancel", input.OrderID)
resp, err := flexportRequest(ctx.Auth.Extra["api-key"], reqURL, http.MethodPost, nil)
if err != nil {
return nil, err
}
return resp, nil
}

func (c *CancelOrderOperation) Test(ctx *sdk.RunContext) (sdk.JSON, error) {
return c.Run(ctx)
}

func (c *CancelOrderOperation) GetInfo() *sdk.OperationInfo {
return c.options
}
71 changes: 71 additions & 0 deletions internal/connectors/flexport/operation_get_all_products.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
// Copyright 2022-present Wakflo
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package flexport

import (
"net/http"

"github.com/wakflo/go-sdk/autoform"
sdk "github.com/wakflo/go-sdk/connector"
sdkcore "github.com/wakflo/go-sdk/core"
)

type createMeetingOperationProps struct{}

type GetProductsOperation struct {
options *sdk.OperationInfo
}

func NewGetProductsOperation() *GetProductsOperation {
return &GetProductsOperation{
options: &sdk.OperationInfo{
Name: "Get all products",
Description: "Get all products",
Auth: sharedAuth,
Input: map[string]*sdkcore.AutoFormSchema{
"topic": autoform.NewShortTextField().
SetDisplayName("").
SetDescription("").
SetRequired(false).Build(),
},
SampleOutput: map[string]interface{}{},
ErrorSettings: sdkcore.StepErrorSettings{
ContinueOnError: false,
RetryOnError: false,
},
RequireAuth: true,
},
}
}

func (c *GetProductsOperation) Run(ctx *sdk.RunContext) (sdk.JSON, error) {
_ = sdk.InputToType[createMeetingOperationProps](ctx)

reqURL := "https://logistics-api.flexport.com/logistics/api/2024-07/products"

resp, err := flexportRequest(ctx.Auth.Extra["api-key"], reqURL, http.MethodGet, nil)
if err != nil {
return nil, err
}
return resp, nil
}

func (c *GetProductsOperation) Test(ctx *sdk.RunContext) (sdk.JSON, error) {
return c.Run(ctx)
}

func (c *GetProductsOperation) GetInfo() *sdk.OperationInfo {
return c.options
}
72 changes: 72 additions & 0 deletions internal/connectors/flexport/operation_get_order.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
// Copyright 2022-present Wakflo
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package flexport

import (
"net/http"

"github.com/wakflo/go-sdk/autoform"
sdk "github.com/wakflo/go-sdk/connector"
sdkcore "github.com/wakflo/go-sdk/core"
)

type getOrderOperationProps struct {
OrderID string `json:"Id"`
}

type GetOrderOperation struct {
options *sdk.OperationInfo
}

func NewGetOrderOperation() *GetOrderOperation {
return &GetOrderOperation{
options: &sdk.OperationInfo{
Name: "Get order by ID",
Description: "Get order by ID",
Auth: sharedAuth,
Input: map[string]*sdkcore.AutoFormSchema{
"Id": autoform.NewShortTextField().
SetDisplayName("Order ID").
SetDescription("Order ID from flexport").
SetRequired(true).Build(),
},
SampleOutput: map[string]interface{}{},
ErrorSettings: sdkcore.StepErrorSettings{
ContinueOnError: false,
RetryOnError: false,
},
RequireAuth: true,
},
}
}

func (c *GetOrderOperation) Run(ctx *sdk.RunContext) (sdk.JSON, error) {
input := sdk.InputToType[getOrderOperationProps](ctx)

reqURL := "https://logistics-api.flexport.com/logistics/api/2024-07/orders/" + input.OrderID
resp, err := flexportRequest(ctx.Auth.Extra["api-key"], reqURL, http.MethodGet, nil)
if err != nil {
return nil, err
}
return resp, nil
}

func (c *GetOrderOperation) Test(ctx *sdk.RunContext) (sdk.JSON, error) {
return c.Run(ctx)
}

func (c *GetOrderOperation) GetInfo() *sdk.OperationInfo {
return c.options
}
72 changes: 72 additions & 0 deletions internal/connectors/flexport/operation_get_order_by_external_id.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
// Copyright 2022-present Wakflo
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package flexport

import (
"net/http"

"github.com/wakflo/go-sdk/autoform"
sdk "github.com/wakflo/go-sdk/connector"
sdkcore "github.com/wakflo/go-sdk/core"
)

type getOrderByExternalIDOperationProps struct {
ExternalOrderID string `json:"Id"`
}

type GetOrderByExternalIDOperation struct {
options *sdk.OperationInfo
}

func NewGetOrderByExternalIDOperation() *GetOrderByExternalIDOperation {
return &GetOrderByExternalIDOperation{
options: &sdk.OperationInfo{
Name: "Get order by External ID",
Description: "Get order using the external order ID given during order creation.",
Auth: sharedAuth,
Input: map[string]*sdkcore.AutoFormSchema{
"Id": autoform.NewShortTextField().
SetDisplayName("External Order ID").
SetDescription("External Order ID from store(woocommerce, shopify etc.)").
SetRequired(true).Build(),
},
SampleOutput: map[string]interface{}{},
ErrorSettings: sdkcore.StepErrorSettings{
ContinueOnError: false,
RetryOnError: false,
},
RequireAuth: true,
},
}
}

func (c *GetOrderByExternalIDOperation) Run(ctx *sdk.RunContext) (sdk.JSON, error) {
input := sdk.InputToType[getOrderByExternalIDOperationProps](ctx)

reqURL := "https://logistics-api.flexport.com/logistics/api/2024-07/orders/external_id/" + input.ExternalOrderID
resp, err := flexportRequest(ctx.Auth.Extra["api-key"], reqURL, http.MethodGet, nil)
if err != nil {
return nil, err
}
return resp, nil
}

func (c *GetOrderByExternalIDOperation) Test(ctx *sdk.RunContext) (sdk.JSON, error) {
return c.Run(ctx)
}

func (c *GetOrderByExternalIDOperation) GetInfo() *sdk.OperationInfo {
return c.options
}
Loading

0 comments on commit 790e4ae

Please sign in to comment.