Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(api): api update #3583

Merged
merged 1 commit into from
Nov 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .stats.yml
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
configured_endpoints: 1397
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/cloudflare%2Fcloudflare-cedc346a76dfdf50768c01a48e573dfaeddfe35be8910188d42fe3c5afaaa5bb.yml
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/cloudflare%2Fcloudflare-1504fe697d2d7335627a605468544df46a79e9a8b355f91527556e6d25cf0f7a.yml
100 changes: 89 additions & 11 deletions workers/script.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,10 @@ type Script struct {
CreatedOn time.Time `json:"created_on" format:"date-time"`
// Hashed script content, can be used in a If-None-Match header when updating.
Etag string `json:"etag"`
// Whether a Worker contains assets.
HasAssets bool `json:"has_assets"`
// Whether a Worker contains modules.
HasModules bool `json:"has_modules"`
// Whether Logpush is turned on for the Worker.
Logpush bool `json:"logpush"`
// When the script was last modified.
Expand All @@ -166,6 +170,8 @@ type scriptJSON struct {
ID apijson.Field
CreatedOn apijson.Field
Etag apijson.Field
HasAssets apijson.Field
HasModules apijson.Field
Logpush apijson.Field
ModifiedOn apijson.Field
PlacementMode apijson.Field
Expand All @@ -186,7 +192,7 @@ func (r scriptJSON) RawJSON() string {
type ScriptSetting struct {
// Whether Logpush is turned on for the Worker.
Logpush bool `json:"logpush"`
// Observability settings for the Worker
// Observability settings for the Worker.
Observability ScriptSettingObservability `json:"observability"`
// List of Workers that will consume logs from the attached Worker.
TailConsumers []ConsumerScript `json:"tail_consumers"`
Expand All @@ -210,9 +216,9 @@ func (r scriptSettingJSON) RawJSON() string {
return r.raw
}

// Observability settings for the Worker
// Observability settings for the Worker.
type ScriptSettingObservability struct {
// Whether observability is enabled for the Worker
// Whether observability is enabled for the Worker.
Enabled bool `json:"enabled,required"`
// The sampling rate for incoming requests. From 0 to 1 (1 = 100%, 0.1 = 10%).
// Default is 1.
Expand Down Expand Up @@ -240,7 +246,7 @@ func (r scriptSettingObservabilityJSON) RawJSON() string {
type ScriptSettingParam struct {
// Whether Logpush is turned on for the Worker.
Logpush param.Field[bool] `json:"logpush"`
// Observability settings for the Worker
// Observability settings for the Worker.
Observability param.Field[ScriptSettingObservabilityParam] `json:"observability"`
// List of Workers that will consume logs from the attached Worker.
TailConsumers param.Field[[]ConsumerScriptParam] `json:"tail_consumers"`
Expand All @@ -250,9 +256,9 @@ func (r ScriptSettingParam) MarshalJSON() (data []byte, err error) {
return apijson.MarshalRoot(r)
}

// Observability settings for the Worker
// Observability settings for the Worker.
type ScriptSettingObservabilityParam struct {
// Whether observability is enabled for the Worker
// Whether observability is enabled for the Worker.
Enabled param.Field[bool] `json:"enabled,required"`
// The sampling rate for incoming requests. From 0 to 1 (1 = 100%, 0.1 = 10%).
// Default is 1.
Expand All @@ -270,6 +276,10 @@ type ScriptUpdateResponse struct {
CreatedOn time.Time `json:"created_on" format:"date-time"`
// Hashed script content, can be used in a If-None-Match header when updating.
Etag string `json:"etag"`
// Whether a Worker contains assets.
HasAssets bool `json:"has_assets"`
// Whether a Worker contains modules.
HasModules bool `json:"has_modules"`
// Whether Logpush is turned on for the Worker.
Logpush bool `json:"logpush"`
// When the script was last modified.
Expand All @@ -290,6 +300,8 @@ type scriptUpdateResponseJSON struct {
ID apijson.Field
CreatedOn apijson.Field
Etag apijson.Field
HasAssets apijson.Field
HasModules apijson.Field
Logpush apijson.Field
ModifiedOn apijson.Field
PlacementMode apijson.Field
Expand Down Expand Up @@ -380,6 +392,8 @@ func (r ScriptUpdateParamsBodyObject) implementsWorkersScriptUpdateParamsBodyUni

// JSON encoded metadata about the uploaded parts and Worker configuration.
type ScriptUpdateParamsBodyObjectMetadata struct {
// Configuration for assets within a Worker
Assets param.Field[ScriptUpdateParamsBodyObjectMetadataAssets] `json:"assets"`
// List of bindings available to the worker.
Bindings param.Field[[]ScriptUpdateParamsBodyObjectMetadataBinding] `json:"bindings"`
// Name of the part in the multipart request that contains the script (e.g. the
Expand All @@ -393,6 +407,9 @@ type ScriptUpdateParamsBodyObjectMetadata struct {
// enable upcoming features or opt in or out of specific changes not included in a
// `compatibility_date`.
CompatibilityFlags param.Field[[]string] `json:"compatibility_flags"`
// Retain assets which exist for a previously uploaded Worker version; used in lieu
// of providing a completion token.
KeepAssets param.Field[bool] `json:"keep_assets"`
// List of binding types to keep from previous_upload.
KeepBindings param.Field[[]string] `json:"keep_bindings"`
// Whether Logpush is turned on for the Worker.
Expand All @@ -402,23 +419,84 @@ type ScriptUpdateParamsBodyObjectMetadata struct {
MainModule param.Field[string] `json:"main_module"`
// Migrations to apply for Durable Objects associated with this Worker.
Migrations param.Field[ScriptUpdateParamsBodyObjectMetadataMigrationsUnion] `json:"migrations"`
// Observability settings for the Worker
// Observability settings for the Worker.
Observability param.Field[ScriptUpdateParamsBodyObjectMetadataObservability] `json:"observability"`
Placement param.Field[PlacementConfigurationParam] `json:"placement"`
// List of strings to use as tags for this Worker
// List of strings to use as tags for this Worker.
Tags param.Field[[]string] `json:"tags"`
// List of Workers that will consume logs from the attached Worker.
TailConsumers param.Field[[]ConsumerScriptParam] `json:"tail_consumers"`
// Usage model to apply to invocations.
UsageModel param.Field[ScriptUpdateParamsBodyObjectMetadataUsageModel] `json:"usage_model"`
// Key-value pairs to use as tags for this version of this Worker
// Key-value pairs to use as tags for this version of this Worker.
VersionTags param.Field[map[string]string] `json:"version_tags"`
}

func (r ScriptUpdateParamsBodyObjectMetadata) MarshalJSON() (data []byte, err error) {
return apijson.MarshalRoot(r)
}

// Configuration for assets within a Worker
type ScriptUpdateParamsBodyObjectMetadataAssets struct {
// Configuration for assets within a Worker.
Config param.Field[ScriptUpdateParamsBodyObjectMetadataAssetsConfig] `json:"config"`
// Token provided upon successful upload of all files from a registered manifest.
JWT param.Field[string] `json:"jwt"`
}

func (r ScriptUpdateParamsBodyObjectMetadataAssets) MarshalJSON() (data []byte, err error) {
return apijson.MarshalRoot(r)
}

// Configuration for assets within a Worker.
type ScriptUpdateParamsBodyObjectMetadataAssetsConfig struct {
// Determines the redirects and rewrites of requests for HTML content.
HTMLHandling param.Field[ScriptUpdateParamsBodyObjectMetadataAssetsConfigHTMLHandling] `json:"html_handling"`
// Determines the response when a request does not match a static asset, and there
// is no Worker script.
NotFoundHandling param.Field[ScriptUpdateParamsBodyObjectMetadataAssetsConfigNotFoundHandling] `json:"not_found_handling"`
}

func (r ScriptUpdateParamsBodyObjectMetadataAssetsConfig) MarshalJSON() (data []byte, err error) {
return apijson.MarshalRoot(r)
}

// Determines the redirects and rewrites of requests for HTML content.
type ScriptUpdateParamsBodyObjectMetadataAssetsConfigHTMLHandling string

const (
ScriptUpdateParamsBodyObjectMetadataAssetsConfigHTMLHandlingAutoTrailingSlash ScriptUpdateParamsBodyObjectMetadataAssetsConfigHTMLHandling = "auto-trailing-slash"
ScriptUpdateParamsBodyObjectMetadataAssetsConfigHTMLHandlingForceTrailingSlash ScriptUpdateParamsBodyObjectMetadataAssetsConfigHTMLHandling = "force-trailing-slash"
ScriptUpdateParamsBodyObjectMetadataAssetsConfigHTMLHandlingDropTrailingSlash ScriptUpdateParamsBodyObjectMetadataAssetsConfigHTMLHandling = "drop-trailing-slash"
ScriptUpdateParamsBodyObjectMetadataAssetsConfigHTMLHandlingNone ScriptUpdateParamsBodyObjectMetadataAssetsConfigHTMLHandling = "none"
)

func (r ScriptUpdateParamsBodyObjectMetadataAssetsConfigHTMLHandling) IsKnown() bool {
switch r {
case ScriptUpdateParamsBodyObjectMetadataAssetsConfigHTMLHandlingAutoTrailingSlash, ScriptUpdateParamsBodyObjectMetadataAssetsConfigHTMLHandlingForceTrailingSlash, ScriptUpdateParamsBodyObjectMetadataAssetsConfigHTMLHandlingDropTrailingSlash, ScriptUpdateParamsBodyObjectMetadataAssetsConfigHTMLHandlingNone:
return true
}
return false
}

// Determines the response when a request does not match a static asset, and there
// is no Worker script.
type ScriptUpdateParamsBodyObjectMetadataAssetsConfigNotFoundHandling string

const (
ScriptUpdateParamsBodyObjectMetadataAssetsConfigNotFoundHandlingNone ScriptUpdateParamsBodyObjectMetadataAssetsConfigNotFoundHandling = "none"
ScriptUpdateParamsBodyObjectMetadataAssetsConfigNotFoundHandling404Page ScriptUpdateParamsBodyObjectMetadataAssetsConfigNotFoundHandling = "404-page"
ScriptUpdateParamsBodyObjectMetadataAssetsConfigNotFoundHandlingSinglePageApplication ScriptUpdateParamsBodyObjectMetadataAssetsConfigNotFoundHandling = "single-page-application"
)

func (r ScriptUpdateParamsBodyObjectMetadataAssetsConfigNotFoundHandling) IsKnown() bool {
switch r {
case ScriptUpdateParamsBodyObjectMetadataAssetsConfigNotFoundHandlingNone, ScriptUpdateParamsBodyObjectMetadataAssetsConfigNotFoundHandling404Page, ScriptUpdateParamsBodyObjectMetadataAssetsConfigNotFoundHandlingSinglePageApplication:
return true
}
return false
}

type ScriptUpdateParamsBodyObjectMetadataBinding struct {
// Name of the binding variable.
Name param.Field[string] `json:"name"`
Expand Down Expand Up @@ -463,9 +541,9 @@ type ScriptUpdateParamsBodyObjectMetadataMigrationsUnion interface {
implementsWorkersScriptUpdateParamsBodyObjectMetadataMigrationsUnion()
}

// Observability settings for the Worker
// Observability settings for the Worker.
type ScriptUpdateParamsBodyObjectMetadataObservability struct {
// Whether observability is enabled for the Worker
// Whether observability is enabled for the Worker.
Enabled param.Field[bool] `json:"enabled,required"`
// The sampling rate for incoming requests. From 0 to 1 (1 = 100%, 0.1 = 10%).
// Default is 1.
Expand Down
8 changes: 8 additions & 0 deletions workers/script_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,21 @@ func TestScriptUpdateWithOptionalParams(t *testing.T) {
Body: workers.ScriptUpdateParamsBodyObject{
AnyPartName: cloudflare.F([]io.Reader{io.Reader(bytes.NewBuffer([]byte("some file contents"))), io.Reader(bytes.NewBuffer([]byte("some file contents"))), io.Reader(bytes.NewBuffer([]byte("some file contents")))}),
Metadata: cloudflare.F(workers.ScriptUpdateParamsBodyObjectMetadata{
Assets: cloudflare.F(workers.ScriptUpdateParamsBodyObjectMetadataAssets{
Config: cloudflare.F(workers.ScriptUpdateParamsBodyObjectMetadataAssetsConfig{
HTMLHandling: cloudflare.F(workers.ScriptUpdateParamsBodyObjectMetadataAssetsConfigHTMLHandlingAutoTrailingSlash),
NotFoundHandling: cloudflare.F(workers.ScriptUpdateParamsBodyObjectMetadataAssetsConfigNotFoundHandlingNone),
}),
JWT: cloudflare.F("jwt"),
}),
Bindings: cloudflare.F([]workers.ScriptUpdateParamsBodyObjectMetadataBinding{{
Name: cloudflare.F("MY_ENV_VAR"),
Type: cloudflare.F("plain_text"),
}}),
BodyPart: cloudflare.F("worker.js"),
CompatibilityDate: cloudflare.F("2023-07-25"),
CompatibilityFlags: cloudflare.F([]string{"string", "string", "string"}),
KeepAssets: cloudflare.F(false),
KeepBindings: cloudflare.F([]string{"string", "string", "string"}),
Logpush: cloudflare.F(false),
MainModule: cloudflare.F("worker.js"),
Expand Down
Loading