Skip to content

Commit

Permalink
Merge pull request #10 from wakflo/feature/web-588-shopify-connector
Browse files Browse the repository at this point in the history
feat: implement shopify connector
  • Loading branch information
raff-wakflo authored Jul 25, 2024
2 parents e185aca + 6ed7efb commit 5d72ccb
Show file tree
Hide file tree
Showing 32 changed files with 2,646 additions and 121 deletions.
5 changes: 4 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,18 @@ go 1.22.2
//replace github.com/wakflo/go-sdk => ../go-sdk

require (
github.com/bold-commerce/go-shopify/v4 v4.5.0
github.com/clarkmcc/go-typescript v0.7.0
github.com/dop251/goja v0.0.0-20240516125602-ccbae20bcec2
github.com/gocarina/gocsv v0.0.0-20240520201108-78e41c74b4b1
github.com/gookit/goutil v0.6.15
github.com/open2b/scriggo v0.56.1
github.com/opus-domini/fast-shot v0.10.0
github.com/rs/zerolog v1.33.0
github.com/shopspring/decimal v0.0.0-20200105231215-408a2507e114
github.com/wakflo/go-sdk v0.4.2
golang.org/x/crypto v0.24.0
golang.org/x/oauth2 v0.20.0
google.golang.org/api v0.181.0
)

Expand All @@ -37,6 +40,7 @@ require (
github.com/golang-jwt/jwt/v5 v5.2.1 // indirect
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
github.com/golang/protobuf v1.5.4 // indirect
github.com/google/go-querystring v1.1.0 // indirect
github.com/google/pprof v0.0.0-20230207041349-798e818bf904 // indirect
github.com/google/s2a-go v0.1.7 // indirect
github.com/google/uuid v1.6.0 // indirect
Expand All @@ -62,7 +66,6 @@ require (
go.opentelemetry.io/otel/trace v1.27.0 // indirect
golang.org/x/exp v0.0.0-20240531132922-fd00a4e0eefc // indirect
golang.org/x/net v0.26.0 // indirect
golang.org/x/oauth2 v0.20.0 // indirect
golang.org/x/sys v0.21.0 // indirect
golang.org/x/text v0.16.0 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20240521202816-d264139d666e // indirect
Expand Down
11 changes: 11 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ github.com/Masterminds/semver/v3 v3.2.1 h1:RN9w6+7QoMeJVGyfmbcgs28Br8cvmnucEXnY0
github.com/Masterminds/semver/v3 v3.2.1/go.mod h1:qvl/7zhW3nngYb5+80sSMF+FG2BjYrf8m9wsX0PNOMQ=
github.com/asaskevich/govalidator v0.0.0-20230301143203-a9d515a09cc2 h1:DklsrG3dyBCFEj5IhUbnKptjxatkF07cF2ak3yi77so=
github.com/asaskevich/govalidator v0.0.0-20230301143203-a9d515a09cc2/go.mod h1:WaHUgvxTVq04UNunO+XhnAqY/wQc+bxr74GqbsZ/Jqw=
github.com/bold-commerce/go-shopify/v4 v4.5.0 h1:47IwwlFFYCqZudVlxVW/LZNS9iNk7YGOzMfIJViL/1o=
github.com/bold-commerce/go-shopify/v4 v4.5.0/go.mod h1:Sjg+C2CLNhYeCbwB6EedKgj2AHEBOP3ng+Eu1IfMf1U=
github.com/cavaliergopher/grab/v3 v3.0.1 h1:4z7TkBfmPjmLAAmkkAZNX/6QJ1nNFdv3SdIHXju0Fr4=
github.com/cavaliergopher/grab/v3 v3.0.1/go.mod h1:1U/KNnD+Ft6JJiYoYBAimKH2XrYptb8Kl3DFGmsjpq4=
github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU=
Expand Down Expand Up @@ -76,9 +78,13 @@ github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMyw
github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU=
github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/go-cmp v0.5.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/go-cmp v0.5.2/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/go-cmp v0.5.3/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
github.com/google/go-querystring v1.0.0/go.mod h1:odCYkC5MyYFN7vkCjXpyrEuKhc/BUO6wN/zVPAxq5ck=
github.com/google/go-querystring v1.1.0 h1:AnCroh3fv4ZBgVIf1Iwtovgjaw/GiKJo8M8yD/fhyJ8=
github.com/google/go-querystring v1.1.0/go.mod h1:Kcdr2DB4koayq7X8pmAG4sNG59So17icRSOU623lUBU=
github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
github.com/google/pprof v0.0.0-20230207041349-798e818bf904 h1:4/hN5RUoecvl+RmJRE2YxKWtnnQls6rQjjW5oV7qg2U=
github.com/google/pprof v0.0.0-20230207041349-798e818bf904/go.mod h1:uglQLonpP8qtYCYyzA+8c/9qtqgA3qsXGYqCPKARAFg=
Expand Down Expand Up @@ -110,6 +116,8 @@ github.com/hashicorp/go-multierror v1.1.1 h1:H5DkEtf6CXdFp0N0Em5UCwQpXMWke8IA0+l
github.com/hashicorp/go-multierror v1.1.1/go.mod h1:iw975J/qwKPdAO1clOe2L8331t/9/fmwbPZ6JB6eMoM=
github.com/huandu/xstrings v1.4.0 h1:D17IlohoQq4UcpqD7fDk80P7l+lwAmlFaBHgOipl2FU=
github.com/huandu/xstrings v1.4.0/go.mod h1:y5/lhBue+AyNmUVz9RLU9xbLR0o4KIIExikq4ovT0aE=
github.com/jarcoal/httpmock v1.3.0 h1:2RJ8GP0IIaWwcC9Fp2BmVi8Kog3v2Hn7VXM3fTd+nuc=
github.com/jarcoal/httpmock v1.3.0/go.mod h1:3yb8rc4BI7TCBhFY8ng0gjuLKJNquuDNiPaZjnENuYg=
github.com/json-iterator/go v1.1.12 h1:PV8peI4a0ysnczrg+LtxykD8LfKY9ML6u2jnxaEnrnM=
github.com/json-iterator/go v1.1.12/go.mod h1:e30LSqwooZae/UwlEbR2852Gd8hjQvJoHmT4TnhNGBo=
github.com/leodido/go-urn v1.4.0 h1:WT9HwE9SGECu3lg4d/dIA+jxlljEa1/ffXKmRjqdmIQ=
Expand All @@ -120,6 +128,7 @@ github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/
github.com/mattn/go-isatty v0.0.19/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY=
github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
github.com/maxatome/go-testdeep v1.12.0/go.mod h1:lPZc/HAcJMP92l7yI6TRz1aZN5URwUBUAfUNvrclaNM=
github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd h1:TRLaZ9cD/w8PVh93nsPXa1VrQ6jlwL5oN8l14QlcNfg=
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
Expand All @@ -136,6 +145,8 @@ github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4/go.mod h1:
github.com/rs/xid v1.5.0/go.mod h1:trrq9SKmegXys3aeAKXMUTdJsYXVwGY3RLcfgqegfbg=
github.com/rs/zerolog v1.33.0 h1:1cU2KZkvPxNyfgEmhHAz/1A9Bz+llsdYzklWFzgp0r8=
github.com/rs/zerolog v1.33.0/go.mod h1:/7mN4D5sKwJLZQ2b/znpjC3/GQWY/xaDXUM0kKWRHss=
github.com/shopspring/decimal v0.0.0-20200105231215-408a2507e114 h1:Pm6R878vxWWWR+Sa3ppsLce/Zq+JNTs6aVvRu13jv9A=
github.com/shopspring/decimal v0.0.0-20200105231215-408a2507e114/go.mod h1:DKyhrW/HYNuLGql+MJL6WCR6knT2jwCFRcu2hWCYk4o=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw=
github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo=
Expand Down
4 changes: 2 additions & 2 deletions internal/connectors/googledrive/lib_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,12 +106,12 @@ func TestNewConnector(t *testing.T) {
t.Errorf("NewConnector() Operations() count = %d, want %d", len(spider.Operations()), 6)
}

// if testCase.isTrigger {
// if testCase.isTrigger {
// _, err = spider.RunTrigger(testCase.operationName, testCase.ctx)
// if err != nil {
// t.Errorf("NewConnector() RunTrigger() with name %v threw an error = %v", testCase.operationName, err)
// }
//} else {
// } else {
// _, err = spider.RunOperation(testCase.operationName, testCase.ctx)
// if err != nil {
// t.Errorf("NewConnector() RunOperation() with name %v threw an error = %v", testCase.operationName, err)
Expand Down
26 changes: 24 additions & 2 deletions internal/connectors/shopify/lib.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,36 @@ import (
func NewConnector() (*sdk.ConnectorPlugin, error) {
return sdk.CreateConnector(&sdk.CreateConnectorArgs{
Name: "Shopify",
Description: "interacts with Shopify API",
Description: "Ecommerce platform for online stores",
Logo: "logos:shopify",
Version: "0.0.1",
Category: sdk.Apps,
Authors: []string{"Wakflo <integrations@wakflo.com>"},
Triggers: []sdk.ITrigger{},
Triggers: []sdk.ITrigger{NewTriggerNewCustomer(), NewTriggerNewOrder()},
Operations: []sdk.IOperation{
NewGetLocationsOperation(),
NewAdjustInventoryLevelOperation(),
NewCreateProductOperation(),
NewUpdateProductOperation(),
NewUpdateOrderOperation(),
NewUpdateCustomerOperation(),
NewCreateDraftOrderOperation(),
NewCreateOrderOperation(),
NewCreateTransactionOperation(),
NewCreateCustomerOperation(),
NewCreateCollectOperation(),
NewGetOrderOperation(),
NewGetCustomerOrdersOperation(),
NewGetTransactionOperation(),
NewGetTransactionsOperation(),
NewListCustomersOperation(),
NewListProductsOperation(),
NewListOrdersOperation(),
NewListDraftOrdersOperation(),
NewCloseOrderOperation(),
NewCancelOrderOperation(),
NewGetCustomerOperation(),
NewGetProductOperation(),
},
})
}
105 changes: 0 additions & 105 deletions internal/connectors/shopify/lib_test.go

This file was deleted.

101 changes: 101 additions & 0 deletions internal/connectors/shopify/operation_adjust_inventory_level.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
// 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 shopify

import (
"context"
"errors"
"fmt"

shopify "github.com/bold-commerce/go-shopify/v4"

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

type adjustInventoryLevelOperationProps struct {
InventoryItemID uint64 `json:"inventoryItemId"`
LocationID uint64 `json:"locationId"`
AvailableAdjustment int `json:"available_adjustment"`
}
type AdjustInventoryLevelOperation struct {
options *sdk.OperationInfo
}

func NewAdjustInventoryLevelOperation() *AdjustInventoryLevelOperation {
return &AdjustInventoryLevelOperation{
options: &sdk.OperationInfo{
Name: "Adjust Inventory Level",
Description: "Adjust inventory level of an item at a location.",
RequireAuth: true,
Auth: sharedAuth,
Input: map[string]*sdkcore.AutoFormSchema{
"inventoryItemId": autoform.NewNumberField().
SetDisplayName("Inventory Item").
SetDescription("The ID of the inventory item.").
SetRequired(true).
Build(),
"locationId": autoform.NewNumberField().
SetDisplayName("Location").
SetDescription("The ID of the location.").
SetRequired(true).
Build(),
"available_adjustment": autoform.NewNumberField().
SetDisplayName("Adjustment Quantity").
SetDescription("Positive values increase inventory, negative values decrease it.").
SetRequired(true).
Build(),
},
ErrorSettings: sdkcore.StepErrorSettings{
ContinueOnError: false,
RetryOnError: false,
},
},
}
}

func (c *AdjustInventoryLevelOperation) Run(ctx *sdk.RunContext) (sdk.JSON, error) {
if ctx.Auth.Extra["token"] == "" {
return nil, errors.New("missing shopify auth token")
}
input := sdk.InputToType[adjustInventoryLevelOperationProps](ctx)
domain := ctx.Auth.Extra["domain"]
shopName := domain + ".myshopify.com"
client := getShopifyClient(shopName, ctx.Auth.Extra["token"])

options := shopify.InventoryLevelAdjustOptions{
InventoryItemId: input.InventoryItemID,
LocationId: input.LocationID,
Adjust: input.AvailableAdjustment,
}

inventoryLevel, err := client.InventoryLevel.Adjust(context.Background(), options)
if err != nil {
return nil, fmt.Errorf("failed to adjust inventory: %v", err)
}

return sdk.JSON(map[string]interface{}{
"adjustedInventoryLevel": inventoryLevel,
}), nil
}

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

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

0 comments on commit 5d72ccb

Please sign in to comment.