labd / commercetools-go-sdk Goto Github PK
View Code? Open in Web Editor NEWGo SDK for commercetools
License: MIT License
Go SDK for commercetools
License: MIT License
Seems like the only product search currently supported is ProductProjection searching, is it possible to search using these doccos if not, is it possible to add? Happy to raise a PR with some guidance!
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
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 thePagedQueryResult
should be deactivated by passingfalse
in thewithTotal
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.
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?
Prices: []platform.PriceDraft{
{
Value: platform.Money{
CentAmount: price,
CurrencyCode: "EUR",
},
Country: ctutils.StringRef(productPriceCountryDefault),
},
},
if len(dim.MasterVariant.Prices) > 0 {
if priceValue, ok := dim.MasterVariant.Prices[0].Value.(platform.CentPrecisionMoney); ok {
cp.Price = float64(priceValue.CentAmount) / 100.0
}
}
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",
}
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.
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.
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?
Is there a reason the following line is using .Set
over .Add
?
It's impossible to use slices of input when it overrides every time in the loop. It results in only the last value being sent to the API.
When I try to use the example in README ( master:latest ), I get several errors.
After adapt the code, according the actually supported SDK, I'm having a panic() caused by nilness.
The platform is panicking here
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().
$ 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"
Use https://pkg.go.dev/golang.org/x/exp/cmd/gorelease to detect backwards incompatible changes?
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:
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"
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?
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?
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:
Hi All,
we noticed a case where we try to get an order but receive a nil
pointer and also a nil
error. That seems to be the cause:
In the code above, the error returned by the JSON parser is ignored and never returned to the caller. Is that intentional?
Thank you in advance!
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
.
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:
and the demo code changed to:
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
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?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.