Skip to content

Commit

Permalink
release: 0.8.0 (#74)
Browse files Browse the repository at this point in the history
* feat(api): api update (#73)

* feat(api): api update (#75)

* feat(api): api update (#76)

* feat(api): api update (#77)

* feat(api): api update (#78)

* feat(api): api update (#79)

* feat(api): api update (#80)

* chore: refactor client tests (#81)

* fix: fix unicode encoding for json (#82)

* docs: document raw responses (#83)

* codegen metadata

* codegen metadata

* feat(client): send `X-Stainless-Timeout` header (#84)

* release: 0.8.0

---------

Co-authored-by: stainless-app[bot] <142633134+stainless-app[bot]@users.noreply.github.com>
  • Loading branch information
stainless-app[bot] authored Feb 5, 2025
1 parent 1eb86f5 commit 927c7b9
Show file tree
Hide file tree
Showing 12 changed files with 239 additions and 91 deletions.
2 changes: 1 addition & 1 deletion .release-please-manifest.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
".": "0.7.0"
".": "0.8.0"
}
2 changes: 1 addition & 1 deletion .stats.yml
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
configured_endpoints: 15
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/riza%2Friza-api-53d443fce326642ac4579e178d39bd12a49ed8230f1264bda8da4c805d4ae71f.yml
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/riza%2Friza-api-4ca61d8b4e331bab13ac4a139600875a379b3a9c3071e23fe4d9f1997066164c.yml
30 changes: 30 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,35 @@
# Changelog

## 0.8.0 (2025-02-04)

Full Changelog: [v0.7.0...v0.8.0](https://github.com/riza-io/riza-api-go/compare/v0.7.0...v0.8.0)

### Features

* **api:** api update ([#73](https://github.com/riza-io/riza-api-go/issues/73)) ([45a357c](https://github.com/riza-io/riza-api-go/commit/45a357cac0c0337b8ff995306a8b313dcfb1b1d4))
* **api:** api update ([#75](https://github.com/riza-io/riza-api-go/issues/75)) ([feffe59](https://github.com/riza-io/riza-api-go/commit/feffe593826d2de7dd00943a1d808b15ec9af777))
* **api:** api update ([#76](https://github.com/riza-io/riza-api-go/issues/76)) ([bbfad5b](https://github.com/riza-io/riza-api-go/commit/bbfad5b9ea1ad9a3c145b1cfe899ada739a5e6f0))
* **api:** api update ([#77](https://github.com/riza-io/riza-api-go/issues/77)) ([8ab051f](https://github.com/riza-io/riza-api-go/commit/8ab051fddbf908cf482c8945ab8ae2e15c459c12))
* **api:** api update ([#78](https://github.com/riza-io/riza-api-go/issues/78)) ([0525154](https://github.com/riza-io/riza-api-go/commit/0525154baa791111d4fa6b1b84919e79c208e228))
* **api:** api update ([#79](https://github.com/riza-io/riza-api-go/issues/79)) ([87ae631](https://github.com/riza-io/riza-api-go/commit/87ae631c476db0656984dd3a9fa495804143842a))
* **api:** api update ([#80](https://github.com/riza-io/riza-api-go/issues/80)) ([0274b2c](https://github.com/riza-io/riza-api-go/commit/0274b2cce301f580cd9d3a626dfed92b98470785))
* **client:** send `X-Stainless-Timeout` header ([#84](https://github.com/riza-io/riza-api-go/issues/84)) ([a587ed8](https://github.com/riza-io/riza-api-go/commit/a587ed85e2675f8b5c6a442131bf9e3dfb815eb0))


### Bug Fixes

* fix unicode encoding for json ([#82](https://github.com/riza-io/riza-api-go/issues/82)) ([1e7d130](https://github.com/riza-io/riza-api-go/commit/1e7d1302645c5863b77c1413add7123c5d0726db))


### Chores

* refactor client tests ([#81](https://github.com/riza-io/riza-api-go/issues/81)) ([111bb9b](https://github.com/riza-io/riza-api-go/commit/111bb9bb1072de946f756d904021b13ee72a17e0))


### Documentation

* document raw responses ([#83](https://github.com/riza-io/riza-api-go/issues/83)) ([32e915b](https://github.com/riza-io/riza-api-go/commit/32e915b0a00317cdd5850f74a6e7cf0b5e37b148))

## 0.7.0 (2025-01-23)

Full Changelog: [v0.6.0...v0.7.0](https://github.com/riza-io/riza-api-go/compare/v0.6.0...v0.7.0)
Expand Down
27 changes: 26 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ Or to pin the version:
<!-- x-release-please-start-version -->

```sh
go get -u 'github.com/riza-io/riza-api-go@v0.7.0'
go get -u 'github.com/riza-io/riza-api-go@v0.8.0'
```

<!-- x-release-please-end -->
Expand Down Expand Up @@ -254,6 +254,31 @@ client.Command.Exec(
)
```

### Accessing raw response data (e.g. response headers)

You can access the raw HTTP response data by using the `option.WithResponseInto()` request option. This is useful when
you need to examine response headers, status codes, or other details.

```go
// Create a variable to store the HTTP response
var response *http.Response
response, err := client.Command.Exec(
context.TODO(),
riza.CommandExecParams{
Code: riza.F("print('Hello, World!')"),
Language: riza.F(riza.CommandExecParamsLanguagePython),
},
option.WithResponseInto(&response),
)
if err != nil {
// handle error
}
fmt.Printf("%+v\n", response)

fmt.Printf("Status Code: %d\n", response.StatusCode)
fmt.Printf("Headers: %+#v\n", response.Header)
```

### Making custom/undocumented requests

This library is typed for convenient access to the documented API. If you need to access undocumented
Expand Down
42 changes: 21 additions & 21 deletions client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,12 +63,12 @@ func TestRetryAfter(t *testing.T) {
},
}),
)
res, err := client.Command.Exec(context.Background(), riza.CommandExecParams{
_, err := client.Command.Exec(context.Background(), riza.CommandExecParams{
Code: riza.F("print('Hello, World!')"),
Language: riza.F(riza.CommandExecParamsLanguagePython),
})
if err == nil || res != nil {
t.Error("Expected there to be a cancel error and for the response to be nil")
if err == nil {
t.Error("Expected there to be a cancel error")
}

attempts := len(retryCountHeaders)
Expand Down Expand Up @@ -100,12 +100,12 @@ func TestDeleteRetryCountHeader(t *testing.T) {
}),
option.WithHeaderDel("X-Stainless-Retry-Count"),
)
res, err := client.Command.Exec(context.Background(), riza.CommandExecParams{
_, err := client.Command.Exec(context.Background(), riza.CommandExecParams{
Code: riza.F("print('Hello, World!')"),
Language: riza.F(riza.CommandExecParamsLanguagePython),
})
if err == nil || res != nil {
t.Error("Expected there to be a cancel error and for the response to be nil")
if err == nil {
t.Error("Expected there to be a cancel error")
}

expectedRetryCountHeaders := []string{"", "", ""}
Expand All @@ -132,12 +132,12 @@ func TestOverwriteRetryCountHeader(t *testing.T) {
}),
option.WithHeader("X-Stainless-Retry-Count", "42"),
)
res, err := client.Command.Exec(context.Background(), riza.CommandExecParams{
_, err := client.Command.Exec(context.Background(), riza.CommandExecParams{
Code: riza.F("print('Hello, World!')"),
Language: riza.F(riza.CommandExecParamsLanguagePython),
})
if err == nil || res != nil {
t.Error("Expected there to be a cancel error and for the response to be nil")
if err == nil {
t.Error("Expected there to be a cancel error")
}

expectedRetryCountHeaders := []string{"42", "42", "42"}
Expand All @@ -163,12 +163,12 @@ func TestRetryAfterMs(t *testing.T) {
},
}),
)
res, err := client.Command.Exec(context.Background(), riza.CommandExecParams{
_, err := client.Command.Exec(context.Background(), riza.CommandExecParams{
Code: riza.F("print('Hello, World!')"),
Language: riza.F(riza.CommandExecParamsLanguagePython),
})
if err == nil || res != nil {
t.Error("Expected there to be a cancel error and for the response to be nil")
if err == nil {
t.Error("Expected there to be a cancel error")
}
if want := 3; attempts != want {
t.Errorf("Expected %d attempts, got %d", want, attempts)
Expand All @@ -188,12 +188,12 @@ func TestContextCancel(t *testing.T) {
)
cancelCtx, cancel := context.WithCancel(context.Background())
cancel()
res, err := client.Command.Exec(cancelCtx, riza.CommandExecParams{
_, err := client.Command.Exec(cancelCtx, riza.CommandExecParams{
Code: riza.F("print('Hello, World!')"),
Language: riza.F(riza.CommandExecParamsLanguagePython),
})
if err == nil || res != nil {
t.Error("Expected there to be a cancel error and for the response to be nil")
if err == nil {
t.Error("Expected there to be a cancel error")
}
}

Expand All @@ -210,12 +210,12 @@ func TestContextCancelDelay(t *testing.T) {
)
cancelCtx, cancel := context.WithTimeout(context.Background(), 2*time.Millisecond)
defer cancel()
res, err := client.Command.Exec(cancelCtx, riza.CommandExecParams{
_, err := client.Command.Exec(cancelCtx, riza.CommandExecParams{
Code: riza.F("print('Hello, World!')"),
Language: riza.F(riza.CommandExecParamsLanguagePython),
})
if err == nil || res != nil {
t.Error("expected there to be a cancel error and for the response to be nil")
if err == nil {
t.Error("expected there to be a cancel error")
}
}

Expand All @@ -238,12 +238,12 @@ func TestContextDeadline(t *testing.T) {
},
}),
)
res, err := client.Command.Exec(deadlineCtx, riza.CommandExecParams{
_, err := client.Command.Exec(deadlineCtx, riza.CommandExecParams{
Code: riza.F("print('Hello, World!')"),
Language: riza.F(riza.CommandExecParamsLanguagePython),
})
if err == nil || res != nil {
t.Error("expected there to be a deadline error and for the response to be nil")
if err == nil {
t.Error("expected there to be a deadline error")
}
close(testDone)
}()
Expand Down
36 changes: 19 additions & 17 deletions command.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,11 @@ func (r *CommandService) ExecFunc(ctx context.Context, body CommandExecFuncParam
type CommandExecResponse struct {
// The exit code returned by the script. Will often be '0' on success and non-zero
// on failure.
ExitCode int64 `json:"exit_code"`
ExitCode int64 `json:"exit_code,required"`
// The contents of 'stderr' after executing the script.
Stderr string `json:"stderr"`
Stderr string `json:"stderr,required"`
// The contents of 'stdout' after executing the script.
Stdout string `json:"stdout"`
Stdout string `json:"stdout,required"`
JSON commandExecResponseJSON `json:"-"`
}

Expand All @@ -80,13 +80,14 @@ func (r commandExecResponseJSON) RawJSON() string {
}

type CommandExecFuncResponse struct {
Execution CommandExecFuncResponseExecution `json:"execution"`
Output interface{} `json:"output"`
Execution CommandExecFuncResponseExecution `json:"execution,required"`
// The output of the function.
Output interface{} `json:"output,required"`
// The status of the output. "valid" means your function executed successfully and
// returned a valid JSON-serializable object, or void. "json_serialization_error"
// means your function executed successfully, but returned a nonserializable
// object. "error" means your function failed to execute.
OutputStatus CommandExecFuncResponseOutputStatus `json:"output_status"`
OutputStatus CommandExecFuncResponseOutputStatus `json:"output_status,required"`
JSON commandExecFuncResponseJSON `json:"-"`
}

Expand All @@ -111,11 +112,11 @@ func (r commandExecFuncResponseJSON) RawJSON() string {
type CommandExecFuncResponseExecution struct {
// The exit code returned by the script. Will often be '0' on success and non-zero
// on failure.
ExitCode int64 `json:"exit_code"`
ExitCode int64 `json:"exit_code,required"`
// The contents of 'stderr' after executing the script.
Stderr string `json:"stderr"`
Stderr string `json:"stderr,required"`
// The contents of 'stdout' after executing the script.
Stdout string `json:"stdout"`
Stdout string `json:"stdout,required"`
JSON commandExecFuncResponseExecutionJSON `json:"-"`
}

Expand Down Expand Up @@ -299,18 +300,21 @@ func (r CommandExecParamsLimits) MarshalJSON() (data []byte, err error) {
}

type CommandExecFuncParams struct {
// The function to execute. Your code must define a function named 'execute' and
// return a JSON-serializable value.
// The function to execute. Your code must define a function named "execute" that
// takes in a single argument and returns a JSON-serializable value.
Code param.Field[string] `json:"code,required"`
// The interpreter to use when executing code.
Language param.Field[CommandExecFuncParamsLanguage] `json:"language,required"`
// Set of key-value pairs to add to the script's execution environment.
// Set of key-value pairs to add to the function's execution environment.
Env param.Field[map[string]string] `json:"env"`
// List of input files.
Files param.Field[[]CommandExecFuncParamsFile] `json:"files"`
// Configuration for HTTP requests and authentication.
HTTP param.Field[CommandExecFuncParamsHTTP] `json:"http"`
Input param.Field[interface{}] `json:"input"`
HTTP param.Field[CommandExecFuncParamsHTTP] `json:"http"`
// The input to the function. This must be a valid JSON-serializable object. If you
// do not pass an input, your function will be called with None (Python) or null
// (JavaScript/TypeScript) as the argument.
Input param.Field[interface{}] `json:"input"`
// Configuration for execution environment limits.
Limits param.Field[CommandExecFuncParamsLimits] `json:"limits"`
// The ID of the runtime revision to use when executing code.
Expand All @@ -328,13 +332,11 @@ const (
CommandExecFuncParamsLanguagePython CommandExecFuncParamsLanguage = "python"
CommandExecFuncParamsLanguageJavascript CommandExecFuncParamsLanguage = "javascript"
CommandExecFuncParamsLanguageTypescript CommandExecFuncParamsLanguage = "typescript"
CommandExecFuncParamsLanguageRuby CommandExecFuncParamsLanguage = "ruby"
CommandExecFuncParamsLanguagePhp CommandExecFuncParamsLanguage = "php"
)

func (r CommandExecFuncParamsLanguage) IsKnown() bool {
switch r {
case CommandExecFuncParamsLanguagePython, CommandExecFuncParamsLanguageJavascript, CommandExecFuncParamsLanguageTypescript, CommandExecFuncParamsLanguageRuby, CommandExecFuncParamsLanguagePhp:
case CommandExecFuncParamsLanguagePython, CommandExecFuncParamsLanguageJavascript, CommandExecFuncParamsLanguageTypescript:
return true
}
return false
Expand Down
2 changes: 1 addition & 1 deletion command_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ func TestCommandExecFuncWithOptionalParams(t *testing.T) {
option.WithAPIKey("My API Key"),
)
_, err := client.Command.ExecFunc(context.TODO(), riza.CommandExecFuncParams{
Code: riza.F("def execute(input): return { \"name\": \"John\", \"executed\": True }"),
Code: riza.F("def execute(input): return { \"name\": input[\"name\"], \"executed\": True }"),
Language: riza.F(riza.CommandExecFuncParamsLanguagePython),
Env: riza.F(map[string]string{
"foo": "string",
Expand Down
2 changes: 1 addition & 1 deletion internal/apijson/encoder.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ func (e *encoder) newPrimitiveTypeEncoder(t reflect.Type) encoderFunc {
// code more and this current code shouldn't cause any issues
case reflect.String:
return func(v reflect.Value) ([]byte, error) {
return []byte(fmt.Sprintf("%q", v.String())), nil
return json.Marshal(v.Interface())
}
case reflect.Bool:
return func(v reflect.Value) ([]byte, error) {
Expand Down
13 changes: 13 additions & 0 deletions internal/requestconfig/requestconfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ func NewRequestConfig(ctx context.Context, method string, u string, body interfa

req.Header.Set("Accept", "application/json")
req.Header.Set("X-Stainless-Retry-Count", "0")
req.Header.Set("X-Stainless-Timeout", "0")
for k, v := range getDefaultHeaders() {
req.Header.Add(k, v)
}
Expand All @@ -157,6 +158,18 @@ func NewRequestConfig(ctx context.Context, method string, u string, body interfa
if err != nil {
return nil, err
}

// This must run after `cfg.Apply(...)` above in case the request timeout gets modified. We also only
// apply our own logic for it if it's still "0" from above. If it's not, then it was deleted or modified
// by the user and we should respect that.
if req.Header.Get("X-Stainless-Timeout") == "0" {
if cfg.RequestTimeout == time.Duration(0) {
req.Header.Del("X-Stainless-Timeout")
} else {
req.Header.Set("X-Stainless-Timeout", strconv.Itoa(int(cfg.RequestTimeout.Seconds())))
}
}

return &cfg, nil
}

Expand Down
2 changes: 1 addition & 1 deletion internal/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@

package internal

const PackageVersion = "0.7.0" // x-release-please-version
const PackageVersion = "0.8.0" // x-release-please-version
Loading

0 comments on commit 927c7b9

Please sign in to comment.