Giter Site home page Giter Site logo

commercetools-go-sdk's People

Contributors

bramkaashoek avatar buztard avatar davidweterings avatar demeyerthom avatar dependabot[bot] avatar etiennetremel avatar jberghoef avatar labd-project-manager[bot] avatar michielbijland avatar multiply avatar mvantellingen avatar philippeckelintive avatar pimvernooij avatar pjstevns avatar qdegraaf avatar tleguijt avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

commercetools-go-sdk's Issues

Regression: 404 responses are not handled again

Handling of 404 Not found responses from CommerceTools has a regression: It was not handled properly earlier, fixed at some point, and now it isn't again.

Commit introducing proper handling: 2a3c377
Released in v1.3.0

Commit removing it again: 2463f65#diff-d37bd1a31dfd77757a89090c321d69489ef49983e0270f0a1b82627f3494f854L95 (deep link to a big diff, sorry)

Can you please re-introduce it?


Also, would you consider not including the entire request response in the GenericRequestError? It is potentially leaking resources (open body (IO reader) and maybe more?), and I think the content already contains enough information (can be parsed as other types of errors).

result := GenericRequestError{
	StatusCode: resp.StatusCode,
	Content:    content,
	Response:   resp,
}

Edit: I meant response, not request, sorry

`QueryInput` doesn't support `WithTotal` flag

We are trying to follow the pagination pattern advised in https://docs.commercetools.com/api/general-concepts#paging.

The documentation has an info-box stating:

To improve query performance, the calculation of the total field in the PagedQueryResult should be deactivated by passing false in the withTotal query parameter whenever possible.

However, it doesn't seem possible to set this flag appropriately when calling OrderQuery on a Client. Presumably there should be a WithTotal boolean flag on the QueryInput struct, which is then used its toParams method to set this flag in the request.

Recording as Money, but retrieving as CentAmount

When I'm recording a new product, the expected type for price value is "platform.Money"
However, when I retrieve back this product using products()...Get()..., it returns the price as platform.CentPrecisionMoney.
Is this the planned behaviour?

Here is how I'm saving/storing the product.price

	Prices: []platform.PriceDraft{
				{
					Value: platform.Money{
						CentAmount:   price,
						CurrencyCode: "EUR",
					},
					Country:       ctutils.StringRef(productPriceCountryDefault),
				},
			},

Here is how I'm retrieving the product.price

	if len(dim.MasterVariant.Prices) > 0 {
		if priceValue, ok := dim.MasterVariant.Prices[0].Value.(platform.CentPrecisionMoney); ok {
			cp.Price = float64(priceValue.CentAmount) / 100.0
		}
	}

The SDK doesn't support multiple Expand for Query

I want to expand multiple objects with QueryInput. But it only supports single one, since it's a single string.

This works

commercetools.QueryInput{
		Expand: "customer.obj",
}

This doesn't work

commercetools.QueryInput{
		Expand: "customer.obj&target.obj",
}

Neither this

commercetools.QueryInput{
		Expand: "customer.obj,target.obj",
}

Responses swallowed when there's an unmarshaling error

Problem: If a response results in an error when being unmarshaled, the response is lost. This makes it impossible to differentiate a 200 response from a 400 response.

This code highlights the issue. If I receive an unmarshaling error, I don't know if the fault was mine or not.

Suggested fix: Wrap the err with content included, or use some structured error that contains more information about this issue.

I can work on this, but how to handle this case should be decided by more than just me.

Outdated README published

Description

When I try to use the example in README ( master:latest ), I get some edition-time errors, all described in the attached image. I believe that's nothing more than the wrong version published.

Additional related questions

1 - In order to use the package, I'm importing directly the published master. Is it the intended/recommended way?
2 - The spew package is referenced in the README. Is that on purpose?

IDE error messages:
ct-bugs

A Bug or an outdated README

Description

When I try to use the example in README ( master:latest ), I get several errors.

  • Edition-time: wrong & undefined types, and syntax errors.
  • Runtime: Panic
    In the attached images, I've put the most relevant issues that I had.

Edition-time issues

ct-bugs

Panic

After adapt the code, according the actually supported SDK, I'm having a panic() caused by nilness.

The platform is panicking here

Screenshot 2022-12-21 at 16 43 08

And in order to avoid that, I must to init a specific attribute in the client, as illustrated above:

The attribute that I initialize to make it work is platform.ClientConfig.HTTPClient.Transport.

Otherwise it (the attribute ) ends nil when needed, triggering a panic().
Screenshot 2022-12-21 at 16 44 27

Environment

$ go env
GO111MODULE=""
GOARCH="arm64"
GOEXE=""
GOEXPERIMENT=""
GOFLAGS=""
GOHOSTARCH="arm64"
GOHOSTOS="darwin"
GOINSECURE=""
GONOPROXY=""
GONOSUMDB=""
GOOS="darwin"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/usr/local/go"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/usr/local/go/pkg/tool/darwin_arm64"
GOVCS=""
GOVERSION="go1.19.4"
GCCGO="gccgo"
AR="ar"
CC="clang"
CXX="clang++"
CGO_ENABLED="1"
GOMOD="/dev/null"
GOWORK=""
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"

State Transitions empty/not set value is not respected due to omitempty annotation

The following statement above the State resources Transitions field is not respected:

// Transitions are a way to describe possible transformations of the current state to other states of the same `type` (e.g.: _Initial_ -> _Shipped_).
// When performing a `transitionState` update action and `transitions` is set, the currently referenced state must have a transition to the new state.
// If `transitions` is an empty list, it means the current state is a final state and no further transitions are allowed.
// If `transitions` is not set, the validation is turned off.
// When performing a `transitionState` update action, any other state of the same `type` can be transitioned to.
Transitions []StateReference `json:"transitions,omitempty"`

When creating a State struct with empty Transitions then the Transition is not set while it should set an empty list.

I locally tried and was able to get it working by removing the omitempty from the Transitions field of both struct State and StateDraft in https://github.com/labd/commercetools-go-sdk/blob/main/platform/types_state.go#L10-L48, then it works as expected. Below is an example without the omitempty on the Transitions field:

type StateDraft struct {
	Key         string                    `json:"key"`
	Type        StateTypeEnum             `json:"type"`
	Name        *LocalizedString          `json:"name,omitempty"`
	Description *LocalizedString          `json:"description,omitempty"`
	Initial     *bool                     `json:"initial,omitempty"`
	Roles       []StateRoleEnum           `json:"roles,omitempty"`
	Transitions []StateResourceIdentifier `json:"transitions"`
}

Since these files are automatically generated, is there a way to override this specific setting?

Possibly related to the following issues:

State Role "Return" needed to be added to StateRoleEnum

This is needed to be fixed to allow creation of Order/LineItem states with "Return" State role.
Unfortunately, I can not publish any PR to this repository.

Would be great to add this changes to 'types_state.go'

const (
	StateRoleEnumReviewIncludedInStatistics StateRoleEnum = "ReviewIncludedInStatistics"
	+ StateRoleEnumReturn StateRoleEnum = "Return" // There was no return type
)

Thanks a lot in advance ๐Ÿ˜ƒ

PS: I'm using https://github.com/labd/terraform-provider-commercetools as a tool for CT configurations. And I've faced this issue:
"commercetools_state.order_complete: expected roles.0 to be one of [ReviewIncludedInStatistics], got Return"

CommerceTools API spec updated (bugfix), need a new release

Hi,

There has been an update to the official API spec to fix a bug, which I'd love to see reflected in the SDK as well.

Upstream commit(s):

The bug was that OrderShipmentStateChanged.oldShipmentState was a required field, but it shouldn't have been, as it can be nil.

Is there something I can do to help speed up the release?

Release 0.3.1 or 0.3.2?

This site says the latest release is 0.3.1, but running go mod tidy pulls release 0.3.2 from somewhere (presumably here?) with a completely different interface (no platform package, for example). Which is right?

Introduce new version numbering

Since we are auto generating the code based on RAML specifications of commercetools the version numbers don't really mean anything.

For the Python SDK we switched to calver, we might want to do the same for the Go SDK (although it's not really common in the Go ecosystem)

If we want to follow semver we have the following options:

  • v1.20221123.0 or v1.20220108.0
  • v2022.1123.0 or v2022.0108.0

Bug handling errors or outdated README

I am planning to change our microservices from Node.js to Go, and I found this very interesting and well-structured SDK.

I hope I can use it in my proof-of-concept :)

Trying to follow the example in the README, the code stops with the error:

resource not found

This error occurs after getting the productType.

Screenshot 2023-08-08 at 23 29 19

As commercetools returns error 404 when an item is not found, there is a different switch/case for it in

client_product_types_by_project_key_product_types_key_by_key_get.go

returns a ErrNotFound, which is not detected as valid in the demo code.

I made a local test. If the code is changed to:

Screenshot 2023-08-08 at 23 28 49

and the demo code changed to:

Screenshot 2023-08-08 at 23 36 46

The code works, the productType is added, and the product is created successfully.

As is the first time I am using the SDK, I was unable to make more tests with the code change, or if it can affect other errors handling, etc.

As the code is generated automatically, it is not possible to change the code with the fixes above, how it can be fixed?


Go version: 1.21
Sdk version: 1.3.1

Panic when initializing the client without transport

There has been a version that would panic if provided with a custom HTTPClient with no Transport, but this has been fixed in aa6fe6b

We had a workaround while waiting for a new release with the above fix:

client, err := platform.NewClient(&platform.ClientConfig{
	URL: cfg.CtBaseUrl,
	Credentials: &clientcredentials.Config{/* ... */},
	HTTPClient: &http.Client{
		Timeout: 30 * time.Second,
		// Need to provide a client that has a non-nil Transport, otherwise all requests fail with nil pointer dereference
		// Fixed in https://github.com/labd/commercetools-go-sdk/commit/aa6fe6b17b760e62f343b233498e7712f5968ebb
		// Waiting for new release
		Transport: http.DefaultTransport,
	},
})

Now a new release happened, which seems to revert to the panicking behavior: https://github.com/labd/commercetools-go-sdk/pull/88/files#diff-988b36dc49cd914d3fce440210c5522ad1ede4c33ff6565244c9cbe01ca64613

Is there a way/plan to make this long-term fixed?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.