-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: implement trackingmore connector
- Loading branch information
Showing
7 changed files
with
585 additions
and
0 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
package trackingmore | ||
|
||
import sdkcore "github.com/wakflo/go-sdk/core" | ||
|
||
var courierCodes = []*sdkcore.AutoFormSchema{ | ||
{Const: "fedex", Title: "FedEx"}, | ||
{Const: "ups", Title: "UPS"}, | ||
{Const: "usps", Title: "USPS"}, | ||
{Const: "dhl", Title: "DHL"}, | ||
{Const: "speedaf", Title: "Speedaf"}, | ||
{Const: "ontrac", Title: "OnTrac"}, | ||
{Const: "lasership", Title: "LaserShip"}, | ||
{Const: "tforce", Title: "TForce"}, | ||
{Const: "rrdonnelley", Title: "RR Donnelley"}, | ||
{Const: "estes", Title: "Estes"}, | ||
{Const: "old_dominion", Title: "Old Dominion Freight Line"}, | ||
{Const: "saia", Title: "Saia"}, | ||
{Const: "xpo", Title: "XPO Logistics"}, | ||
{Const: "forward_air", Title: "Forward Air"}, | ||
{Const: "speedee", Title: "SpeeDee Delivery"}, | ||
{Const: "gso", Title: "GSO (Golden State Overnight)"}, | ||
{Const: "tnt", Title: "TNT"}, | ||
{Const: "pitney_bowes", Title: "Pitney Bowes"}, | ||
{Const: "purolator", Title: "Purolator"}, | ||
{Const: "newgistics", Title: "Newgistics"}, | ||
{Const: "yrc_freight", Title: "YRC Freight"}, | ||
{Const: "land_air", Title: "Land Air Express"}, | ||
{Const: "u_ship", Title: "uShip"}, | ||
{Const: "xpress_global", Title: "Xpress Global Systems"}, | ||
{Const: "daylight_transport", Title: "Daylight Transport"}, | ||
{Const: "r_l_carriers", Title: "R+L Carriers"}, | ||
{Const: "central_transport", Title: "Central Transport"}, | ||
{Const: "southeastern_freight", Title: "Southeastern Freight Lines"}, | ||
{Const: "ward_trucking", Title: "Ward Trucking"}, | ||
{Const: "cross_country", Title: "Cross Country Courier"}, | ||
{Const: "gls", Title: "GLS"}, | ||
{Const: "roadrunner", Title: "Roadrunner Transportation"}, | ||
{Const: "aaa_cooper", Title: "AAA Cooper Transportation"}, | ||
{Const: "dohrn_transfer", Title: "Dohrn Transfer"}, | ||
{Const: "rwc", Title: "RWC (Regional West)"}, | ||
{Const: "brown_integrated", Title: "Brown Integrated Logistics"}, | ||
{Const: "forwardair", Title: "Forward Air"}, | ||
{Const: "r_l_freight", Title: "R+L Global Logistics"}, | ||
{Const: "sudden_valley", Title: "Sudden Valley"}, | ||
{Const: "best_overland", Title: "Best Overland Freight"}, | ||
{Const: "western_freight", Title: "Western Freight"}, | ||
{Const: "americold", Title: "Americold"}, | ||
{Const: "allied_express", Title: "Allied Express"}, | ||
{Const: "yellow_corp", Title: "Yellow Corporation"}, | ||
{Const: "safelite", Title: "Safelite"}, | ||
{Const: "mainfreight", Title: "Mainfreight"}, | ||
{Const: "dynamex", Title: "Dynamex"}, | ||
{Const: "hermes", Title: "Hermes"}, | ||
{Const: "ups_freight", Title: "UPS Freight"}, | ||
{Const: "fedex_ground", Title: "FedEx Ground"}, | ||
{Const: "usps_priority", Title: "USPS Priority Mail"}, | ||
{Const: "china-post", Title: "China Post"}, | ||
{Const: "china-ems", Title: "China EMS"}, | ||
{Const: "postnord", Title: "PostNord"}, | ||
{Const: "fastway_uk", Title: "Fastway UK"}, | ||
{Const: "xpo_logistics", Title: "XPO Logistics"}, | ||
{Const: "dpd_canada", Title: "DPD Canada"}, | ||
{Const: "intime_express", Title: "InTime Express"}, | ||
{Const: "p4d", Title: "P4D (UK)"}, | ||
{Const: "frakt24", Title: "Frakt24"}, | ||
{Const: "bring_express", Title: "Bring Express"}, | ||
{Const: "mbe_canada", Title: "MBE Canada"}, | ||
{Const: "chit_chat_express", Title: "Chit Chat Express"}, | ||
{Const: "gophr", Title: "Gophr"}, | ||
{Const: "city_sprint", Title: "City Sprint"}, | ||
{Const: "purolator_courier", Title: "Purolator Courier"}, | ||
{Const: "logistics_xpress", Title: "Logistics Xpress"}, | ||
{Const: "ceva_logistics", Title: "CEVA Logistics"}, | ||
{Const: "cool_express", Title: "Cool Express"}, | ||
{Const: "hong-kong-post", Title: "Hong Kong Post"}, | ||
{Const: "singapore-post", Title: "Singapore Post"}, | ||
{Const: "swiss-post", Title: "Swiss Post"}, | ||
{Const: "royal-mail", Title: "Royal Mail"}, | ||
{Const: "postnl-parcels", Title: "PostNL International"}, | ||
{Const: "canada-post", Title: "Canada Post"}, | ||
{Const: "australia-post", Title: "Australia Post"}, | ||
{Const: "new-zealand-post", Title: "New Zealand Post"}, | ||
{Const: "parcel-force", Title: "Parcelforce"}, | ||
{Const: "belgium-post", Title: "Bpost"}, | ||
{Const: "brazil-correios", Title: "Brazil Correios"}, | ||
{Const: "russian-post", Title: "Russian Post"}, | ||
{Const: "malaysia-post", Title: "Malaysia Post"}, | ||
{Const: "maldives-post", Title: "Maldives Post"}, | ||
{Const: "malta-post", Title: "Malta Post"}, | ||
{Const: "mauritius-post", Title: "Mauritius Post"}, | ||
{Const: "correos-mexico", Title: "Mexico Post"}, | ||
{Const: "moldova-post", Title: "Moldova Post"}, | ||
{Const: "la-poste-monaco", Title: "Monaco Post"}, | ||
{Const: "monaco-ems", Title: "Monaco EMS"}, | ||
{Const: "mongol-post", Title: "Mongol Post"}, | ||
{Const: "posta-crne-gore", Title: "Montenegro Post"}, | ||
} |
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,35 @@ | ||
// 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 trackingmore | ||
|
||
import ( | ||
sdk "github.com/wakflo/go-sdk/connector" | ||
) | ||
|
||
func NewConnector() (*sdk.ConnectorPlugin, error) { | ||
return sdk.CreateConnector(&sdk.CreateConnectorArgs{ | ||
Name: "TrackingMore", | ||
Description: "order tracking platform for eCommerce", | ||
Logo: "logos:pivotal-tracker", | ||
Version: "0.0.1", | ||
Category: sdk.Apps, | ||
Authors: []string{"Wakflo <integrations@wakflo.com>"}, | ||
Triggers: []sdk.ITrigger{NewTrackingStatusChange()}, | ||
Operations: []sdk.IOperation{ | ||
NewTrackAPackageOperation(), | ||
// NewCreateTrackingsOperation(), | ||
}, | ||
}) | ||
} |
103 changes: 103 additions & 0 deletions
103
internal/connectors/trackingmore/operation_create_trackings.go
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,103 @@ | ||
// 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 trackingmore | ||
|
||
import ( | ||
"github.com/wakflo/go-sdk/autoform" | ||
sdk "github.com/wakflo/go-sdk/connector" | ||
sdkcore "github.com/wakflo/go-sdk/core" | ||
) | ||
|
||
type createTrackingsProps struct { | ||
TrackingNumber string `json:"tracking_number"` | ||
CourierCode string `json:"courier_code"` | ||
Body []map[string]interface{} `json:"body"` | ||
} | ||
|
||
type CreateTrackingsOperation struct { | ||
options *sdk.OperationInfo | ||
} | ||
|
||
func NewCreateTrackingsOperation() *CreateTrackingsOperation { | ||
return &CreateTrackingsOperation{ | ||
options: &sdk.OperationInfo{ | ||
Name: "Create batch tracking", | ||
Description: "create a batch tracking", | ||
RequireAuth: true, | ||
Auth: sharedAuth, | ||
Input: map[string]*sdkcore.AutoFormSchema{ | ||
"tracking_number": autoform.NewShortTextField(). | ||
SetDisplayName("Tracking Number"). | ||
SetDescription("Tracking number of a package."). | ||
SetRequired(true). | ||
Build(), | ||
"body": autoform.NewGroupArrayField(). | ||
SetDisplayName("Courier Code"). | ||
SetDescription("Courier code"). | ||
SetItems(autoform.NewObjectField().SetDisplayName("").SetProperties( | ||
map[string]*sdkcore.AutoFormSchema{ | ||
"courier_code": autoform.NewSelectField(). | ||
SetDisplayName("Courier Code"). | ||
SetDescription("Courier code"). | ||
SetOptions(courierCodes). | ||
SetRequired(true). | ||
Build(), | ||
"tracking_number": autoform.NewShortTextField(). | ||
SetDisplayName("Tracking Number"). | ||
SetDescription("Tracking number of a package."). | ||
SetRequired(true). | ||
Build(), | ||
}).Build()). | ||
SetRequired(true). | ||
Build(), | ||
}, | ||
ErrorSettings: sdkcore.StepErrorSettings{ | ||
ContinueOnError: false, | ||
RetryOnError: false, | ||
}, | ||
}, | ||
} | ||
} | ||
|
||
func (c *CreateTrackingsOperation) Run(ctx *sdk.RunContext) (sdk.JSON, error) { | ||
input := sdk.InputToType[createTrackingsProps](ctx) | ||
|
||
applicationKey := ctx.Auth.Extra["key"] | ||
|
||
// payload := []map[string]interface{}{ | ||
// { | ||
// "courier_code": "usps", | ||
// "tracking_number": "9269990312443844954410", | ||
// }, | ||
// { | ||
// "courier_code": "fedex", | ||
// "tracking_number": "608285157867", | ||
// }, | ||
//} | ||
|
||
response, err := createBatchTracking(applicationKey, input.Body) | ||
if err != nil { | ||
return nil, err | ||
} | ||
return response, nil | ||
} | ||
|
||
func (c *CreateTrackingsOperation) Test(ctx *sdk.RunContext) (sdk.JSON, error) { | ||
return c.Run(ctx) | ||
} | ||
|
||
func (c *CreateTrackingsOperation) GetInfo() *sdk.OperationInfo { | ||
return c.options | ||
} |
111 changes: 111 additions & 0 deletions
111
internal/connectors/trackingmore/operation_track_a _package.go
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,111 @@ | ||
// 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 trackingmore | ||
|
||
import ( | ||
"errors" | ||
|
||
"github.com/wakflo/go-sdk/autoform" | ||
sdk "github.com/wakflo/go-sdk/connector" | ||
sdkcore "github.com/wakflo/go-sdk/core" | ||
) | ||
|
||
type trackAPackageProps struct { | ||
TrackingNumber string `json:"tracking_number"` | ||
CourierCode string `json:"courier_code"` | ||
Title string `json:"title"` | ||
Note string `json:"note"` | ||
} | ||
|
||
type TrackAPackageOperation struct { | ||
options *sdk.OperationInfo | ||
} | ||
|
||
func NewTrackAPackageOperation() *TrackAPackageOperation { | ||
return &TrackAPackageOperation{ | ||
options: &sdk.OperationInfo{ | ||
Name: "Create a tracking", | ||
Description: "create a tracking for a package", | ||
RequireAuth: true, | ||
Auth: sharedAuth, | ||
Input: map[string]*sdkcore.AutoFormSchema{ | ||
"tracking_number": autoform.NewShortTextField(). | ||
SetDisplayName("Tracking Number"). | ||
SetDescription("Tracking number of a package."). | ||
SetRequired(true). | ||
Build(), | ||
"courier_code": autoform.NewSelectField(). | ||
SetDisplayName("Courier Code"). | ||
SetDescription("Courier code"). | ||
SetOptions(courierCodes). | ||
SetRequired(true). | ||
Build(), | ||
"title": autoform.NewShortTextField(). | ||
SetDisplayName("Title"). | ||
SetDescription("Title of the package."). | ||
SetRequired(true). | ||
Build(), | ||
"note": autoform.NewLongTextField(). | ||
SetDisplayName("Note"). | ||
SetDescription("Note about the package"). | ||
SetRequired(false). | ||
Build(), | ||
}, | ||
ErrorSettings: sdkcore.StepErrorSettings{ | ||
ContinueOnError: false, | ||
RetryOnError: false, | ||
}, | ||
}, | ||
} | ||
} | ||
|
||
func (c *TrackAPackageOperation) Run(ctx *sdk.RunContext) (sdk.JSON, error) { | ||
input := sdk.InputToType[trackAPackageProps](ctx) | ||
|
||
endpoint := "/v4/trackings/create" | ||
applicationKey := ctx.Auth.Extra["key"] | ||
|
||
payload := map[string]interface{}{ | ||
"courier_code": input.CourierCode, | ||
"tracking_number": input.TrackingNumber, | ||
} | ||
|
||
if input.Title != "" { | ||
payload["title"] = input.Title | ||
} | ||
if input.Note != "" { | ||
payload["note"] = input.Note | ||
} | ||
|
||
response, err := createTracking(endpoint, applicationKey, payload) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
data, ok := response["data"].(map[string]interface{}) | ||
if !ok { | ||
return nil, errors.New("invalid response format: data field is not an array") | ||
} | ||
|
||
return sdk.JSON(data), nil | ||
} | ||
|
||
func (c *TrackAPackageOperation) Test(ctx *sdk.RunContext) (sdk.JSON, error) { | ||
return c.Run(ctx) | ||
} | ||
|
||
func (c *TrackAPackageOperation) GetInfo() *sdk.OperationInfo { | ||
return c.options | ||
} |
Oops, something went wrong.