diff --git a/accesstokens/client.go b/accesstokens/client.go index 2240a3a..7d8c11c 100644 --- a/accesstokens/client.go +++ b/accesstokens/client.go @@ -51,6 +51,7 @@ func (c *Client) IssueTemporaryAccessToken( endpointURL := baseURL + "/temporary-access-tokens" headers := core.MergeHeaders(c.header.Clone(), options.ToHeader()) + headers.Set("Content-Type", "application/json") errorDecoder := func(statusCode int, body io.Reader) error { raw, err := io.ReadAll(body) @@ -96,14 +97,16 @@ func (c *Client) IssueTemporaryAccessToken( if err := c.caller.Call( ctx, &core.CallParams{ - URL: endpointURL, - Method: http.MethodPost, - MaxAttempts: options.MaxAttempts, - Headers: headers, - Client: options.HTTPClient, - Request: request, - Response: &response, - ErrorDecoder: errorDecoder, + URL: endpointURL, + Method: http.MethodPost, + MaxAttempts: options.MaxAttempts, + Headers: headers, + BodyProperties: options.BodyProperties, + QueryParameters: options.QueryParameters, + Client: options.HTTPClient, + Request: request, + Response: &response, + ErrorDecoder: errorDecoder, }, ); err != nil { return nil, err diff --git a/accounts/client.go b/accounts/client.go index b364362..fcf2d6f 100644 --- a/accounts/client.go +++ b/accounts/client.go @@ -104,13 +104,15 @@ func (c *Client) ListAPIKeys( if err := c.caller.Call( ctx, &core.CallParams{ - URL: endpointURL, - Method: http.MethodGet, - MaxAttempts: options.MaxAttempts, - Headers: headers, - Client: options.HTTPClient, - Response: &response, - ErrorDecoder: errorDecoder, + URL: endpointURL, + Method: http.MethodGet, + MaxAttempts: options.MaxAttempts, + Headers: headers, + BodyProperties: options.BodyProperties, + QueryParameters: options.QueryParameters, + Client: options.HTTPClient, + Response: &response, + ErrorDecoder: errorDecoder, }, ); err != nil { return nil, err @@ -135,6 +137,7 @@ func (c *Client) CreateAPIKey( endpointURL := baseURL + "/api-keys" headers := core.MergeHeaders(c.header.Clone(), options.ToHeader()) + headers.Set("Content-Type", "application/json") errorDecoder := func(statusCode int, body io.Reader) error { raw, err := io.ReadAll(body) @@ -180,14 +183,16 @@ func (c *Client) CreateAPIKey( if err := c.caller.Call( ctx, &core.CallParams{ - URL: endpointURL, - Method: http.MethodPost, - MaxAttempts: options.MaxAttempts, - Headers: headers, - Client: options.HTTPClient, - Request: request, - Response: &response, - ErrorDecoder: errorDecoder, + URL: endpointURL, + Method: http.MethodPost, + MaxAttempts: options.MaxAttempts, + Headers: headers, + BodyProperties: options.BodyProperties, + QueryParameters: options.QueryParameters, + Client: options.HTTPClient, + Request: request, + Response: &response, + ErrorDecoder: errorDecoder, }, ); err != nil { return nil, err @@ -258,13 +263,15 @@ func (c *Client) GetAPIKey( if err := c.caller.Call( ctx, &core.CallParams{ - URL: endpointURL, - Method: http.MethodGet, - MaxAttempts: options.MaxAttempts, - Headers: headers, - Client: options.HTTPClient, - Response: &response, - ErrorDecoder: errorDecoder, + URL: endpointURL, + Method: http.MethodGet, + MaxAttempts: options.MaxAttempts, + Headers: headers, + BodyProperties: options.BodyProperties, + QueryParameters: options.QueryParameters, + Client: options.HTTPClient, + Response: &response, + ErrorDecoder: errorDecoder, }, ); err != nil { return nil, err @@ -291,6 +298,7 @@ func (c *Client) UpdateAPIKey( endpointURL := core.EncodeURL(baseURL+"/api-keys/%v", apiKeyID) headers := core.MergeHeaders(c.header.Clone(), options.ToHeader()) + headers.Set("Content-Type", "application/json") errorDecoder := func(statusCode int, body io.Reader) error { raw, err := io.ReadAll(body) @@ -343,14 +351,16 @@ func (c *Client) UpdateAPIKey( if err := c.caller.Call( ctx, &core.CallParams{ - URL: endpointURL, - Method: http.MethodPut, - MaxAttempts: options.MaxAttempts, - Headers: headers, - Client: options.HTTPClient, - Request: request, - Response: &response, - ErrorDecoder: errorDecoder, + URL: endpointURL, + Method: http.MethodPut, + MaxAttempts: options.MaxAttempts, + Headers: headers, + BodyProperties: options.BodyProperties, + QueryParameters: options.QueryParameters, + Client: options.HTTPClient, + Request: request, + Response: &response, + ErrorDecoder: errorDecoder, }, ); err != nil { return nil, err @@ -421,13 +431,15 @@ func (c *Client) DeleteAPIKey( if err := c.caller.Call( ctx, &core.CallParams{ - URL: endpointURL, - Method: http.MethodDelete, - MaxAttempts: options.MaxAttempts, - Headers: headers, - Client: options.HTTPClient, - Response: &response, - ErrorDecoder: errorDecoder, + URL: endpointURL, + Method: http.MethodDelete, + MaxAttempts: options.MaxAttempts, + Headers: headers, + BodyProperties: options.BodyProperties, + QueryParameters: options.QueryParameters, + Client: options.HTTPClient, + Response: &response, + ErrorDecoder: errorDecoder, }, ); err != nil { return nil, err @@ -505,13 +517,15 @@ func (c *Client) CountAPIKeys( if err := c.caller.Call( ctx, &core.CallParams{ - URL: endpointURL, - Method: http.MethodGet, - MaxAttempts: options.MaxAttempts, - Headers: headers, - Client: options.HTTPClient, - Response: &response, - ErrorDecoder: errorDecoder, + URL: endpointURL, + Method: http.MethodGet, + MaxAttempts: options.MaxAttempts, + Headers: headers, + BodyProperties: options.BodyProperties, + QueryParameters: options.QueryParameters, + Client: options.HTTPClient, + Response: &response, + ErrorDecoder: errorDecoder, }, ); err != nil { return nil, err @@ -589,13 +603,15 @@ func (c *Client) ListAPIRequests( if err := c.caller.Call( ctx, &core.CallParams{ - URL: endpointURL, - Method: http.MethodGet, - MaxAttempts: options.MaxAttempts, - Headers: headers, - Client: options.HTTPClient, - Response: &response, - ErrorDecoder: errorDecoder, + URL: endpointURL, + Method: http.MethodGet, + MaxAttempts: options.MaxAttempts, + Headers: headers, + BodyProperties: options.BodyProperties, + QueryParameters: options.QueryParameters, + Client: options.HTTPClient, + Response: &response, + ErrorDecoder: errorDecoder, }, ); err != nil { return nil, err @@ -666,13 +682,15 @@ func (c *Client) GetAPIRequest( if err := c.caller.Call( ctx, &core.CallParams{ - URL: endpointURL, - Method: http.MethodGet, - MaxAttempts: options.MaxAttempts, - Headers: headers, - Client: options.HTTPClient, - Response: &response, - ErrorDecoder: errorDecoder, + URL: endpointURL, + Method: http.MethodGet, + MaxAttempts: options.MaxAttempts, + Headers: headers, + BodyProperties: options.BodyProperties, + QueryParameters: options.QueryParameters, + Client: options.HTTPClient, + Response: &response, + ErrorDecoder: errorDecoder, }, ); err != nil { return nil, err @@ -750,13 +768,15 @@ func (c *Client) CountAPIRequests( if err := c.caller.Call( ctx, &core.CallParams{ - URL: endpointURL, - Method: http.MethodGet, - MaxAttempts: options.MaxAttempts, - Headers: headers, - Client: options.HTTPClient, - Response: &response, - ErrorDecoder: errorDecoder, + URL: endpointURL, + Method: http.MethodGet, + MaxAttempts: options.MaxAttempts, + Headers: headers, + BodyProperties: options.BodyProperties, + QueryParameters: options.QueryParameters, + Client: options.HTTPClient, + Response: &response, + ErrorDecoder: errorDecoder, }, ); err != nil { return nil, err @@ -834,13 +854,15 @@ func (c *Client) ListEnvironments( if err := c.caller.Call( ctx, &core.CallParams{ - URL: endpointURL, - Method: http.MethodGet, - MaxAttempts: options.MaxAttempts, - Headers: headers, - Client: options.HTTPClient, - Response: &response, - ErrorDecoder: errorDecoder, + URL: endpointURL, + Method: http.MethodGet, + MaxAttempts: options.MaxAttempts, + Headers: headers, + BodyProperties: options.BodyProperties, + QueryParameters: options.QueryParameters, + Client: options.HTTPClient, + Response: &response, + ErrorDecoder: errorDecoder, }, ); err != nil { return nil, err @@ -865,6 +887,7 @@ func (c *Client) CreateEnvironment( endpointURL := baseURL + "/environments" headers := core.MergeHeaders(c.header.Clone(), options.ToHeader()) + headers.Set("Content-Type", "application/json") errorDecoder := func(statusCode int, body io.Reader) error { raw, err := io.ReadAll(body) @@ -910,14 +933,16 @@ func (c *Client) CreateEnvironment( if err := c.caller.Call( ctx, &core.CallParams{ - URL: endpointURL, - Method: http.MethodPost, - MaxAttempts: options.MaxAttempts, - Headers: headers, - Client: options.HTTPClient, - Request: request, - Response: &response, - ErrorDecoder: errorDecoder, + URL: endpointURL, + Method: http.MethodPost, + MaxAttempts: options.MaxAttempts, + Headers: headers, + BodyProperties: options.BodyProperties, + QueryParameters: options.QueryParameters, + Client: options.HTTPClient, + Request: request, + Response: &response, + ErrorDecoder: errorDecoder, }, ); err != nil { return nil, err @@ -988,13 +1013,15 @@ func (c *Client) GetEnvironment( if err := c.caller.Call( ctx, &core.CallParams{ - URL: endpointURL, - Method: http.MethodGet, - MaxAttempts: options.MaxAttempts, - Headers: headers, - Client: options.HTTPClient, - Response: &response, - ErrorDecoder: errorDecoder, + URL: endpointURL, + Method: http.MethodGet, + MaxAttempts: options.MaxAttempts, + Headers: headers, + BodyProperties: options.BodyProperties, + QueryParameters: options.QueryParameters, + Client: options.HTTPClient, + Response: &response, + ErrorDecoder: errorDecoder, }, ); err != nil { return nil, err @@ -1021,6 +1048,7 @@ func (c *Client) UpdateEnvironment( endpointURL := core.EncodeURL(baseURL+"/environments/%v", environmentID) headers := core.MergeHeaders(c.header.Clone(), options.ToHeader()) + headers.Set("Content-Type", "application/json") errorDecoder := func(statusCode int, body io.Reader) error { raw, err := io.ReadAll(body) @@ -1073,14 +1101,16 @@ func (c *Client) UpdateEnvironment( if err := c.caller.Call( ctx, &core.CallParams{ - URL: endpointURL, - Method: http.MethodPut, - MaxAttempts: options.MaxAttempts, - Headers: headers, - Client: options.HTTPClient, - Request: request, - Response: &response, - ErrorDecoder: errorDecoder, + URL: endpointURL, + Method: http.MethodPut, + MaxAttempts: options.MaxAttempts, + Headers: headers, + BodyProperties: options.BodyProperties, + QueryParameters: options.QueryParameters, + Client: options.HTTPClient, + Request: request, + Response: &response, + ErrorDecoder: errorDecoder, }, ); err != nil { return nil, err @@ -1151,13 +1181,15 @@ func (c *Client) DeleteEnvironment( if err := c.caller.Call( ctx, &core.CallParams{ - URL: endpointURL, - Method: http.MethodDelete, - MaxAttempts: options.MaxAttempts, - Headers: headers, - Client: options.HTTPClient, - Response: &response, - ErrorDecoder: errorDecoder, + URL: endpointURL, + Method: http.MethodDelete, + MaxAttempts: options.MaxAttempts, + Headers: headers, + BodyProperties: options.BodyProperties, + QueryParameters: options.QueryParameters, + Client: options.HTTPClient, + Response: &response, + ErrorDecoder: errorDecoder, }, ); err != nil { return nil, err diff --git a/billing.go b/billing.go index 094e436..e6365d6 100644 --- a/billing.go +++ b/billing.go @@ -9,6 +9,18 @@ import ( time "time" ) +type CountBillingProductsRequest struct { + IDs []*string `json:"-" url:"ids,omitempty"` + Name *string `json:"-" url:"name,omitempty"` + Q *string `json:"-" url:"q,omitempty"` + // Filter products that are not linked to any plan + WithoutLinkedToPlan *bool `json:"-" url:"without_linked_to_plan,omitempty"` + // Page limit (default 100) + Limit *int `json:"-" url:"limit,omitempty"` + // Page offset (default 0) + Offset *int `json:"-" url:"offset,omitempty"` +} + type CountCustomersRequest struct { Name *string `json:"-" url:"name,omitempty"` FailedToImport *bool `json:"-" url:"failed_to_import,omitempty"` @@ -23,6 +35,8 @@ type ListBillingProductsRequest struct { IDs []*string `json:"-" url:"ids,omitempty"` Name *string `json:"-" url:"name,omitempty"` Q *string `json:"-" url:"q,omitempty"` + // Filter products that are not linked to any plan + WithoutLinkedToPlan *bool `json:"-" url:"without_linked_to_plan,omitempty"` // Page limit (default 100) Limit *int `json:"-" url:"limit,omitempty"` // Page offset (default 0) @@ -52,7 +66,6 @@ type ListInvoicesRequest struct { type ListPaymentMethodsRequest struct { CompanyID *string `json:"-" url:"company_id,omitempty"` CustomerExternalID string `json:"-" url:"customer_external_id"` - InvoiceExternalID *string `json:"-" url:"invoice_external_id,omitempty"` SubscriptionExternalID *string `json:"-" url:"subscription_external_id,omitempty"` // Page limit (default 100) Limit *int `json:"-" url:"limit,omitempty"` @@ -64,12 +77,57 @@ type ListProductPricesRequest struct { IDs []*string `json:"-" url:"ids,omitempty"` Name *string `json:"-" url:"name,omitempty"` Q *string `json:"-" url:"q,omitempty"` + // Filter products that are not linked to any plan + WithoutLinkedToPlan *bool `json:"-" url:"without_linked_to_plan,omitempty"` // Page limit (default 100) Limit *int `json:"-" url:"limit,omitempty"` // Page offset (default 0) Offset *int `json:"-" url:"offset,omitempty"` } +type CountBillingProductsResponse struct { + Data *CountResponse `json:"data,omitempty" url:"data,omitempty"` + // Input parameters + Params *CountBillingProductsParams `json:"params,omitempty" url:"params,omitempty"` + + extraProperties map[string]interface{} + _rawJSON json.RawMessage +} + +func (c *CountBillingProductsResponse) GetExtraProperties() map[string]interface{} { + return c.extraProperties +} + +func (c *CountBillingProductsResponse) UnmarshalJSON(data []byte) error { + type unmarshaler CountBillingProductsResponse + var value unmarshaler + if err := json.Unmarshal(data, &value); err != nil { + return err + } + *c = CountBillingProductsResponse(value) + + extraProperties, err := core.ExtractExtraProperties(data, *c) + if err != nil { + return err + } + c.extraProperties = extraProperties + + c._rawJSON = json.RawMessage(data) + return nil +} + +func (c *CountBillingProductsResponse) String() string { + if len(c._rawJSON) > 0 { + if value, err := core.StringifyJSON(c._rawJSON); err == nil { + return value + } + } + if value, err := core.StringifyJSON(c); err == nil { + return value + } + return fmt.Sprintf("%#v", c) +} + type CountCustomersResponse struct { Data *CountResponse `json:"data,omitempty" url:"data,omitempty"` // Input parameters @@ -601,6 +659,7 @@ type CreateBillingCustomerRequestBody struct { } type CreateBillingPriceRequestBody struct { + Currency string `json:"currency" url:"-"` Interval string `json:"interval" url:"-"` Price int `json:"price" url:"-"` PriceExternalID string `json:"price_external_id" url:"-"` @@ -616,10 +675,13 @@ type CreateBillingProductRequestBody struct { } type CreateBillingSubscriptionsRequestBody struct { + Currency string `json:"currency" url:"-"` CustomerExternalID string `json:"customer_external_id" url:"-"` ExpiredAt time.Time `json:"expired_at" url:"-"` Interval *string `json:"interval,omitempty" url:"-"` Metadata map[string]interface{} `json:"metadata,omitempty" url:"-"` + PeriodEnd *int `json:"period_end,omitempty" url:"-"` + PeriodStart *int `json:"period_start,omitempty" url:"-"` ProductExternalIDs []*BillingProductPricing `json:"product_external_ids,omitempty" url:"-"` Status *string `json:"status,omitempty" url:"-"` SubscriptionExternalID string `json:"subscription_external_id" url:"-"` @@ -649,16 +711,18 @@ func (c *CreateBillingSubscriptionsRequestBody) MarshalJSON() ([]byte, error) { } type CreateInvoiceRequestBody struct { - AmountDue int `json:"amount_due" url:"-"` - AmountPaid int `json:"amount_paid" url:"-"` - AmountRemaining int `json:"amount_remaining" url:"-"` - CollectionMethod string `json:"collection_method" url:"-"` - Currency string `json:"currency" url:"-"` - CustomerExternalID string `json:"customer_external_id" url:"-"` - DueDate *time.Time `json:"due_date,omitempty" url:"-"` - ExternalID string `json:"external_id" url:"-"` - SubscriptionExternalID *string `json:"subscription_external_id,omitempty" url:"-"` - Subtotal int `json:"subtotal" url:"-"` + AmountDue int `json:"amount_due" url:"-"` + AmountPaid int `json:"amount_paid" url:"-"` + AmountRemaining int `json:"amount_remaining" url:"-"` + CollectionMethod string `json:"collection_method" url:"-"` + Currency string `json:"currency" url:"-"` + CustomerExternalID string `json:"customer_external_id" url:"-"` + DueDate *time.Time `json:"due_date,omitempty" url:"-"` + ExternalID *string `json:"external_id,omitempty" url:"-"` + PaymentMethodExternalID *string `json:"payment_method_external_id,omitempty" url:"-"` + SubscriptionExternalID *string `json:"subscription_external_id,omitempty" url:"-"` + Subtotal int `json:"subtotal" url:"-"` + URL *string `json:"url,omitempty" url:"-"` } func (c *CreateInvoiceRequestBody) UnmarshalJSON(data []byte) error { @@ -684,13 +748,17 @@ func (c *CreateInvoiceRequestBody) MarshalJSON() ([]byte, error) { } type CreatePaymentMethodRequestBody struct { + AccountLast4 *string `json:"account_last4,omitempty" url:"-"` + AccountName *string `json:"account_name,omitempty" url:"-"` + BankName *string `json:"bank_name,omitempty" url:"-"` + BillingEmail *string `json:"billing_email,omitempty" url:"-"` + BillingName *string `json:"billing_name,omitempty" url:"-"` CardBrand *string `json:"card_brand,omitempty" url:"-"` CardExpMonth *int `json:"card_exp_month,omitempty" url:"-"` CardExpYear *int `json:"card_exp_year,omitempty" url:"-"` CardLast4 *string `json:"card_last4,omitempty" url:"-"` CustomerExternalID string `json:"customer_external_id" url:"-"` ExternalID string `json:"external_id" url:"-"` - InvoiceExternalID *string `json:"invoice_external_id,omitempty" url:"-"` PaymentMethodType string `json:"payment_method_type" url:"-"` SubscriptionExternalID *string `json:"subscription_external_id,omitempty" url:"-"` } diff --git a/billing/client.go b/billing/client.go index 1cf6fe1..9da8034 100644 --- a/billing/client.go +++ b/billing/client.go @@ -51,6 +51,7 @@ func (c *Client) UpsertBillingCustomer( endpointURL := baseURL + "/billing/customer/upsert" headers := core.MergeHeaders(c.header.Clone(), options.ToHeader()) + headers.Set("Content-Type", "application/json") errorDecoder := func(statusCode int, body io.Reader) error { raw, err := io.ReadAll(body) @@ -96,14 +97,16 @@ func (c *Client) UpsertBillingCustomer( if err := c.caller.Call( ctx, &core.CallParams{ - URL: endpointURL, - Method: http.MethodPost, - MaxAttempts: options.MaxAttempts, - Headers: headers, - Client: options.HTTPClient, - Request: request, - Response: &response, - ErrorDecoder: errorDecoder, + URL: endpointURL, + Method: http.MethodPost, + MaxAttempts: options.MaxAttempts, + Headers: headers, + BodyProperties: options.BodyProperties, + QueryParameters: options.QueryParameters, + Client: options.HTTPClient, + Request: request, + Response: &response, + ErrorDecoder: errorDecoder, }, ); err != nil { return nil, err @@ -181,13 +184,15 @@ func (c *Client) ListCustomers( if err := c.caller.Call( ctx, &core.CallParams{ - URL: endpointURL, - Method: http.MethodGet, - MaxAttempts: options.MaxAttempts, - Headers: headers, - Client: options.HTTPClient, - Response: &response, - ErrorDecoder: errorDecoder, + URL: endpointURL, + Method: http.MethodGet, + MaxAttempts: options.MaxAttempts, + Headers: headers, + BodyProperties: options.BodyProperties, + QueryParameters: options.QueryParameters, + Client: options.HTTPClient, + Response: &response, + ErrorDecoder: errorDecoder, }, ); err != nil { return nil, err @@ -265,13 +270,15 @@ func (c *Client) CountCustomers( if err := c.caller.Call( ctx, &core.CallParams{ - URL: endpointURL, - Method: http.MethodGet, - MaxAttempts: options.MaxAttempts, - Headers: headers, - Client: options.HTTPClient, - Response: &response, - ErrorDecoder: errorDecoder, + URL: endpointURL, + Method: http.MethodGet, + MaxAttempts: options.MaxAttempts, + Headers: headers, + BodyProperties: options.BodyProperties, + QueryParameters: options.QueryParameters, + Client: options.HTTPClient, + Response: &response, + ErrorDecoder: errorDecoder, }, ); err != nil { return nil, err @@ -349,13 +356,15 @@ func (c *Client) ListInvoices( if err := c.caller.Call( ctx, &core.CallParams{ - URL: endpointURL, - Method: http.MethodGet, - MaxAttempts: options.MaxAttempts, - Headers: headers, - Client: options.HTTPClient, - Response: &response, - ErrorDecoder: errorDecoder, + URL: endpointURL, + Method: http.MethodGet, + MaxAttempts: options.MaxAttempts, + Headers: headers, + BodyProperties: options.BodyProperties, + QueryParameters: options.QueryParameters, + Client: options.HTTPClient, + Response: &response, + ErrorDecoder: errorDecoder, }, ); err != nil { return nil, err @@ -380,6 +389,7 @@ func (c *Client) UpsertInvoice( endpointURL := baseURL + "/billing/invoices" headers := core.MergeHeaders(c.header.Clone(), options.ToHeader()) + headers.Set("Content-Type", "application/json") errorDecoder := func(statusCode int, body io.Reader) error { raw, err := io.ReadAll(body) @@ -425,14 +435,16 @@ func (c *Client) UpsertInvoice( if err := c.caller.Call( ctx, &core.CallParams{ - URL: endpointURL, - Method: http.MethodPost, - MaxAttempts: options.MaxAttempts, - Headers: headers, - Client: options.HTTPClient, - Request: request, - Response: &response, - ErrorDecoder: errorDecoder, + URL: endpointURL, + Method: http.MethodPost, + MaxAttempts: options.MaxAttempts, + Headers: headers, + BodyProperties: options.BodyProperties, + QueryParameters: options.QueryParameters, + Client: options.HTTPClient, + Request: request, + Response: &response, + ErrorDecoder: errorDecoder, }, ); err != nil { return nil, err @@ -510,13 +522,15 @@ func (c *Client) ListPaymentMethods( if err := c.caller.Call( ctx, &core.CallParams{ - URL: endpointURL, - Method: http.MethodGet, - MaxAttempts: options.MaxAttempts, - Headers: headers, - Client: options.HTTPClient, - Response: &response, - ErrorDecoder: errorDecoder, + URL: endpointURL, + Method: http.MethodGet, + MaxAttempts: options.MaxAttempts, + Headers: headers, + BodyProperties: options.BodyProperties, + QueryParameters: options.QueryParameters, + Client: options.HTTPClient, + Response: &response, + ErrorDecoder: errorDecoder, }, ); err != nil { return nil, err @@ -541,6 +555,7 @@ func (c *Client) UpsertPaymentMethod( endpointURL := baseURL + "/billing/payment-methods" headers := core.MergeHeaders(c.header.Clone(), options.ToHeader()) + headers.Set("Content-Type", "application/json") errorDecoder := func(statusCode int, body io.Reader) error { raw, err := io.ReadAll(body) @@ -586,14 +601,16 @@ func (c *Client) UpsertPaymentMethod( if err := c.caller.Call( ctx, &core.CallParams{ - URL: endpointURL, - Method: http.MethodPost, - MaxAttempts: options.MaxAttempts, - Headers: headers, - Client: options.HTTPClient, - Request: request, - Response: &response, - ErrorDecoder: errorDecoder, + URL: endpointURL, + Method: http.MethodPost, + MaxAttempts: options.MaxAttempts, + Headers: headers, + BodyProperties: options.BodyProperties, + QueryParameters: options.QueryParameters, + Client: options.HTTPClient, + Request: request, + Response: &response, + ErrorDecoder: errorDecoder, }, ); err != nil { return nil, err @@ -618,6 +635,7 @@ func (c *Client) UpsertBillingPrice( endpointURL := baseURL + "/billing/price/upsert" headers := core.MergeHeaders(c.header.Clone(), options.ToHeader()) + headers.Set("Content-Type", "application/json") errorDecoder := func(statusCode int, body io.Reader) error { raw, err := io.ReadAll(body) @@ -663,14 +681,16 @@ func (c *Client) UpsertBillingPrice( if err := c.caller.Call( ctx, &core.CallParams{ - URL: endpointURL, - Method: http.MethodPost, - MaxAttempts: options.MaxAttempts, - Headers: headers, - Client: options.HTTPClient, - Request: request, - Response: &response, - ErrorDecoder: errorDecoder, + URL: endpointURL, + Method: http.MethodPost, + MaxAttempts: options.MaxAttempts, + Headers: headers, + BodyProperties: options.BodyProperties, + QueryParameters: options.QueryParameters, + Client: options.HTTPClient, + Request: request, + Response: &response, + ErrorDecoder: errorDecoder, }, ); err != nil { return nil, err @@ -748,13 +768,15 @@ func (c *Client) ListProductPrices( if err := c.caller.Call( ctx, &core.CallParams{ - URL: endpointURL, - Method: http.MethodGet, - MaxAttempts: options.MaxAttempts, - Headers: headers, - Client: options.HTTPClient, - Response: &response, - ErrorDecoder: errorDecoder, + URL: endpointURL, + Method: http.MethodGet, + MaxAttempts: options.MaxAttempts, + Headers: headers, + BodyProperties: options.BodyProperties, + QueryParameters: options.QueryParameters, + Client: options.HTTPClient, + Response: &response, + ErrorDecoder: errorDecoder, }, ); err != nil { return nil, err @@ -779,6 +801,7 @@ func (c *Client) UpsertBillingProduct( endpointURL := baseURL + "/billing/product/upsert" headers := core.MergeHeaders(c.header.Clone(), options.ToHeader()) + headers.Set("Content-Type", "application/json") errorDecoder := func(statusCode int, body io.Reader) error { raw, err := io.ReadAll(body) @@ -824,14 +847,16 @@ func (c *Client) UpsertBillingProduct( if err := c.caller.Call( ctx, &core.CallParams{ - URL: endpointURL, - Method: http.MethodPost, - MaxAttempts: options.MaxAttempts, - Headers: headers, - Client: options.HTTPClient, - Request: request, - Response: &response, - ErrorDecoder: errorDecoder, + URL: endpointURL, + Method: http.MethodPost, + MaxAttempts: options.MaxAttempts, + Headers: headers, + BodyProperties: options.BodyProperties, + QueryParameters: options.QueryParameters, + Client: options.HTTPClient, + Request: request, + Response: &response, + ErrorDecoder: errorDecoder, }, ); err != nil { return nil, err @@ -909,13 +934,101 @@ func (c *Client) ListBillingProducts( if err := c.caller.Call( ctx, &core.CallParams{ - URL: endpointURL, - Method: http.MethodGet, - MaxAttempts: options.MaxAttempts, - Headers: headers, - Client: options.HTTPClient, - Response: &response, - ErrorDecoder: errorDecoder, + URL: endpointURL, + Method: http.MethodGet, + MaxAttempts: options.MaxAttempts, + Headers: headers, + BodyProperties: options.BodyProperties, + QueryParameters: options.QueryParameters, + Client: options.HTTPClient, + Response: &response, + ErrorDecoder: errorDecoder, + }, + ); err != nil { + return nil, err + } + return response, nil +} + +func (c *Client) CountBillingProducts( + ctx context.Context, + request *schematicgo.CountBillingProductsRequest, + opts ...option.RequestOption, +) (*schematicgo.CountBillingProductsResponse, error) { + options := core.NewRequestOptions(opts...) + + baseURL := "https://api.schematichq.com" + if c.baseURL != "" { + baseURL = c.baseURL + } + if options.BaseURL != "" { + baseURL = options.BaseURL + } + endpointURL := baseURL + "/billing/products/count" + + queryParams, err := core.QueryValues(request) + if err != nil { + return nil, err + } + if len(queryParams) > 0 { + endpointURL += "?" + queryParams.Encode() + } + + headers := core.MergeHeaders(c.header.Clone(), options.ToHeader()) + + errorDecoder := func(statusCode int, body io.Reader) error { + raw, err := io.ReadAll(body) + if err != nil { + return err + } + apiError := core.NewAPIError(statusCode, errors.New(string(raw))) + decoder := json.NewDecoder(bytes.NewReader(raw)) + switch statusCode { + case 400: + value := new(schematicgo.BadRequestError) + value.APIError = apiError + if err := decoder.Decode(value); err != nil { + return apiError + } + return value + case 401: + value := new(schematicgo.UnauthorizedError) + value.APIError = apiError + if err := decoder.Decode(value); err != nil { + return apiError + } + return value + case 403: + value := new(schematicgo.ForbiddenError) + value.APIError = apiError + if err := decoder.Decode(value); err != nil { + return apiError + } + return value + case 500: + value := new(schematicgo.InternalServerError) + value.APIError = apiError + if err := decoder.Decode(value); err != nil { + return apiError + } + return value + } + return apiError + } + + var response *schematicgo.CountBillingProductsResponse + if err := c.caller.Call( + ctx, + &core.CallParams{ + URL: endpointURL, + Method: http.MethodGet, + MaxAttempts: options.MaxAttempts, + Headers: headers, + BodyProperties: options.BodyProperties, + QueryParameters: options.QueryParameters, + Client: options.HTTPClient, + Response: &response, + ErrorDecoder: errorDecoder, }, ); err != nil { return nil, err @@ -940,6 +1053,7 @@ func (c *Client) UpsertBillingSubscription( endpointURL := baseURL + "/billing/subscription/upsert" headers := core.MergeHeaders(c.header.Clone(), options.ToHeader()) + headers.Set("Content-Type", "application/json") errorDecoder := func(statusCode int, body io.Reader) error { raw, err := io.ReadAll(body) @@ -985,14 +1099,16 @@ func (c *Client) UpsertBillingSubscription( if err := c.caller.Call( ctx, &core.CallParams{ - URL: endpointURL, - Method: http.MethodPost, - MaxAttempts: options.MaxAttempts, - Headers: headers, - Client: options.HTTPClient, - Request: request, - Response: &response, - ErrorDecoder: errorDecoder, + URL: endpointURL, + Method: http.MethodPost, + MaxAttempts: options.MaxAttempts, + Headers: headers, + BodyProperties: options.BodyProperties, + QueryParameters: options.QueryParameters, + Client: options.HTTPClient, + Request: request, + Response: &response, + ErrorDecoder: errorDecoder, }, ); err != nil { return nil, err diff --git a/buffer/buffer.go b/buffer/buffer.go deleted file mode 100644 index cf88839..0000000 --- a/buffer/buffer.go +++ /dev/null @@ -1,148 +0,0 @@ -package buffer - -import ( - "context" - "sync" - "time" - - schematicgo "github.com/schematichq/schematic-go" - "github.com/schematichq/schematic-go/events" -) - -const defaultEventBufferPeriod = 5 * time.Second -const maxEvents = 100 - -type eventBuffer struct { - // error logging channel - errors chan error - - // buffer of events - events []*schematicgo.CreateEventRequestBody - - // API client - eventClient *events.Client - - // frequency to flush the buffer - interval time.Duration - - // logger - logger schematicgo.Logger - - // max number of events to store in buffer - maxEvents int - - // mutexes for flushing and pushing to the buffer - mutexFlush sync.Mutex - mutexPush sync.Mutex - - // channel to signal shutdown - shutdown chan struct{} - - // whether to accept new events - stopped bool -} - -func NewEventBuffer( - client *events.Client, - errors chan error, - logger schematicgo.Logger, - _period *time.Duration, -) *eventBuffer { - period := defaultEventBufferPeriod - if _period != nil { - period = *_period - } - - buffer := &eventBuffer{ - events: []*schematicgo.CreateEventRequestBody{}, - eventClient: client, - errors: errors, - interval: period, - logger: logger, - maxEvents: maxEvents, - mutexFlush: sync.Mutex{}, - mutexPush: sync.Mutex{}, - shutdown: make(chan struct{}), - } - - // Start ticker to flush events periodically - go buffer.periodicFlush() - - return buffer -} - -func (b *eventBuffer) flush() { - b.mutexFlush.Lock() - defer b.mutexFlush.Unlock() - - if len(b.events) == 0 { - return - } - - events := make([]*schematicgo.CreateEventRequestBody, len(b.events)) - for i, event := range b.events { - if event != nil { - events[i] = event - } - } - - req := &schematicgo.CreateEventBatchRequestBody{ - Events: events, - } - - if _, err := b.eventClient.CreateEventBatch(context.Background(), req); err != nil { - b.errors <- err - } - - b.events = b.events[:0] -} - -func (b *eventBuffer) periodicFlush() { - ticker := time.NewTicker(b.interval) - defer ticker.Stop() - - for { - select { - case <-b.shutdown: - // stop accepting new events - b.stopped = true - - // flush any remaining events - b.flush() - - return - case <-ticker.C: - b.flush() - } - } -} - -func (b *eventBuffer) Push(event *schematicgo.CreateEventRequestBody) { - if event == nil { - return - } - - if b.stopped { - b.logger.Printf("ERROR: Event buffer is stopped, not accepting new events") - return - } - - b.mutexPush.Lock() - defer b.mutexPush.Unlock() - - if len(b.events) >= b.maxEvents { - b.flush() - } - - b.events = append(b.events, event) -} - -func (b *eventBuffer) Stop() { - defer func() { - if r := recover(); r != nil { - b.logger.Printf("ERROR: Panic occurred while closing client %v", r) - } - }() - - close(b.shutdown) -} diff --git a/cache/cache.go b/cache/cache.go deleted file mode 100644 index 586f0dd..0000000 --- a/cache/cache.go +++ /dev/null @@ -1,114 +0,0 @@ -package cache - -import ( - "container/list" - "context" - "sync" - "time" -) - -const defaultCacheSize = 1000 // 1000 records -const defaultCacheTTL = 5 * time.Second - -type cachedItem[T any] struct { - key string - value T - expiration time.Time -} - -type localCache[T any] struct { - cache map[string]*list.Element - lruList *list.List - maxSize int - ttl time.Duration - mu sync.RWMutex -} - -func NewDefaultCache[T any]() *localCache[T] { - return NewLocalCache[T](defaultCacheSize, defaultCacheTTL) -} - -func NewLocalCache[T any](maxSize int, ttl time.Duration) *localCache[T] { - return &localCache[T]{ - cache: make(map[string]*list.Element), - lruList: list.New(), - maxSize: maxSize, - ttl: ttl, - } -} - -func (c *localCache[T]) Get(ctx context.Context, key string) (T, bool) { - var empty T - if c == nil || c.maxSize == 0 { - return empty, false - } - - c.mu.RLock() - element, exists := c.cache[key] - c.mu.RUnlock() - - if !exists { - return empty, false - } - - item := element.Value.(*cachedItem[T]) - - // Check if the item has expired - if time.Now().After(item.expiration) { - c.mu.Lock() - c.lruList.Remove(element) - delete(c.cache, key) - c.mu.Unlock() - return empty, false - } - - // Move the accessed item to the front of the list - c.mu.Lock() - c.lruList.MoveToFront(element) - c.mu.Unlock() - - return item.value, true -} - -func (c *localCache[T]) Set(ctx context.Context, key string, val T, ttlOverride *time.Duration) error { - if c == nil || c.maxSize == 0 { - return nil - } - - ttl := c.ttl - if ttlOverride != nil { - ttl = *ttlOverride - } - - c.mu.Lock() - defer c.mu.Unlock() - - // If the key already exists, update it - if element, exists := c.cache[key]; exists { - c.lruList.MoveToFront(element) - item := element.Value.(*cachedItem[T]) - item.value = val - item.expiration = time.Now().Add(ttl) - return nil - } - - // If we're at capacity, remove the least recently used item - if c.lruList.Len() >= c.maxSize { - oldest := c.lruList.Back() - if oldest != nil { - c.lruList.Remove(oldest) - delete(c.cache, oldest.Value.(*cachedItem[T]).key) - } - } - - // Add the new item - item := &cachedItem[T]{ - key: key, - value: val, - expiration: time.Now().Add(ttl), - } - element := c.lruList.PushFront(item) - c.cache[key] = element - - return nil -} diff --git a/client/client.go b/client/client.go deleted file mode 100644 index 6967ed0..0000000 --- a/client/client.go +++ /dev/null @@ -1,99 +0,0 @@ -// This file was auto-generated by Fern from our API Definition. - -package client - -import ( - context "context" - accesstokens "github.com/schematichq/schematic-go/accesstokens" - accounts "github.com/schematichq/schematic-go/accounts" - billing "github.com/schematichq/schematic-go/billing" - companies "github.com/schematichq/schematic-go/companies" - components "github.com/schematichq/schematic-go/components" - core "github.com/schematichq/schematic-go/core" - crm "github.com/schematichq/schematic-go/crm" - entitlements "github.com/schematichq/schematic-go/entitlements" - events "github.com/schematichq/schematic-go/events" - features "github.com/schematichq/schematic-go/features" - option "github.com/schematichq/schematic-go/option" - plangroups "github.com/schematichq/schematic-go/plangroups" - plans "github.com/schematichq/schematic-go/plans" - webhooks "github.com/schematichq/schematic-go/webhooks" - http "net/http" -) - -type Client struct { - baseURL string - caller *core.Caller - header http.Header - - Accounts *accounts.Client - Features *features.Client - Billing *billing.Client - Companies *companies.Client - Entitlements *entitlements.Client - Components *components.Client - Crm *crm.Client - Events *events.Client - Plans *plans.Client - Plangroups *plangroups.Client - Accesstokens *accesstokens.Client - Webhooks *webhooks.Client -} - -func NewClient(opts ...option.RequestOption) *Client { - options := core.NewRequestOptions(opts...) - return &Client{ - baseURL: options.BaseURL, - caller: core.NewCaller( - &core.CallerParams{ - Client: options.HTTPClient, - MaxAttempts: options.MaxAttempts, - }, - ), - header: options.ToHeader(), - Accounts: accounts.NewClient(opts...), - Features: features.NewClient(opts...), - Billing: billing.NewClient(opts...), - Companies: companies.NewClient(opts...), - Entitlements: entitlements.NewClient(opts...), - Components: components.NewClient(opts...), - Crm: crm.NewClient(opts...), - Events: events.NewClient(opts...), - Plans: plans.NewClient(opts...), - Plangroups: plangroups.NewClient(opts...), - Accesstokens: accesstokens.NewClient(opts...), - Webhooks: webhooks.NewClient(opts...), - } -} - -func (c *Client) GetCompanyPlans( - ctx context.Context, - opts ...option.RequestOption, -) error { - options := core.NewRequestOptions(opts...) - - baseURL := "https://api.schematichq.com" - if c.baseURL != "" { - baseURL = c.baseURL - } - if options.BaseURL != "" { - baseURL = options.BaseURL - } - endpointURL := baseURL + "/company-plans" - - headers := core.MergeHeaders(c.header.Clone(), options.ToHeader()) - - if err := c.caller.Call( - ctx, - &core.CallParams{ - URL: endpointURL, - Method: http.MethodGet, - MaxAttempts: options.MaxAttempts, - Headers: headers, - Client: options.HTTPClient, - }, - ); err != nil { - return err - } - return nil -} diff --git a/client/client_test.go b/client/client_test.go deleted file mode 100644 index b7d87df..0000000 --- a/client/client_test.go +++ /dev/null @@ -1,45 +0,0 @@ -// This file was auto-generated by Fern from our API Definition. - -package client - -import ( - option "github.com/schematichq/schematic-go/option" - assert "github.com/stretchr/testify/assert" - http "net/http" - testing "testing" - time "time" -) - -func TestNewClient(t *testing.T) { - t.Run("default", func(t *testing.T) { - c := NewClient() - assert.Empty(t, c.baseURL) - }) - - t.Run("base url", func(t *testing.T) { - c := NewClient( - option.WithBaseURL("test.co"), - ) - assert.Equal(t, "test.co", c.baseURL) - }) - - t.Run("http client", func(t *testing.T) { - httpClient := &http.Client{ - Timeout: 5 * time.Second, - } - c := NewClient( - option.WithHTTPClient(httpClient), - ) - assert.Empty(t, c.baseURL) - }) - - t.Run("http header", func(t *testing.T) { - header := make(http.Header) - header.Set("X-API-Tenancy", "test") - c := NewClient( - option.WithHTTPHeader(header), - ) - assert.Empty(t, c.baseURL) - assert.Equal(t, "test", c.header.Get("X-API-Tenancy")) - }) -} diff --git a/client/schematic_client_test.go b/client/schematic_client_test.go deleted file mode 100644 index 45dd3bb..0000000 --- a/client/schematic_client_test.go +++ /dev/null @@ -1,185 +0,0 @@ -package client_test - -import ( - "bytes" - "context" - "encoding/json" - "io" - http "net/http" - "testing" - "time" - - "github.com/golang/mock/gomock" - schematicgo "github.com/schematichq/schematic-go" - schematicclient "github.com/schematichq/schematic-go/client" - "github.com/schematichq/schematic-go/mocks" - - "github.com/stretchr/testify/assert" -) - -func TestNewSchematicClient(t *testing.T) { - client := schematicclient.NewSchematicClient("test-api-key") - defer client.Close() - assert.NotNil(t, client) -} - -func TestCheckFlagWithCacheHit(t *testing.T) { - ctrl := gomock.NewController(t) - mockHTTPClient := mocks.NewMockHTTPClient(ctrl) - client := schematicclient.NewSchematicClient("test-api-key", schematicclient.WithHTTPClient(mockHTTPClient)) - - defer client.Close() - - assert.NotNil(t, client) - - responseBody := &schematicgo.CheckFlagResponse{ - Data: &schematicgo.CheckFlagResponseData{ - Value: true, - }, - } - - data, err := json.Marshal(responseBody) - - assert.Nil(t, err) - body := bytes.NewReader(data) - - mockHTTPClient.EXPECT().Do(gomock.Any()).Return(&http.Response{ - Status: "200", - StatusCode: 200, - Body: io.NopCloser(body), - }, nil).Times(1) - - // First call should hit the API and set the cache - resp := client.CheckFlag(context.Background(), &schematicgo.CheckFlagRequestBody{}, "test-flag") - assert.True(t, resp) - // Wait enough time for the cache to be set (since this happens in a goroutine) - time.Sleep(10 * time.Millisecond) - // Second call should hit the cache - assert.True(t, client.CheckFlag(context.Background(), &schematicgo.CheckFlagRequestBody{}, "test-flag")) -} - -func TestCheckFlagWithNoCache(t *testing.T) { - ctrl := gomock.NewController(t) - mockHTTPClient := mocks.NewMockHTTPClient(ctrl) - client := schematicclient.NewSchematicClient("test-api-key", schematicclient.WithDisableFlagCheckCache(), schematicclient.WithHTTPClient(mockHTTPClient)) - defer client.Close() - - assert.NotNil(t, client) - - responseBody := &schematicgo.CheckFlagResponse{ - Data: &schematicgo.CheckFlagResponseData{ - Value: true, - }, - } - - for i := 0; i < 2; i++ { - data, err := json.Marshal(responseBody) - assert.Nil(t, err) - mockHTTPClient.EXPECT().Do(gomock.Any()).Return(&http.Response{ - Status: "200", - StatusCode: 200, - Body: io.NopCloser(bytes.NewReader(data)), - }, nil) - } - - // Both calls should hit the API - assert.True(t, client.CheckFlag(context.Background(), &schematicgo.CheckFlagRequestBody{}, "test-flag")) - // Wait enough time in between calls for the cache to be set, were it to be active (since this happens in a goroutine) - time.Sleep(10 * time.Millisecond) - assert.True(t, client.CheckFlag(context.Background(), &schematicgo.CheckFlagRequestBody{}, "test-flag")) -} - -func TestCheckFlagWithCacheOptions(t *testing.T) { - cacheTTL := 50 * time.Millisecond - cacheMaxSize := 1000 - ctrl := gomock.NewController(t) - mockHTTPClient := mocks.NewMockHTTPClient(ctrl) - client := schematicclient.NewSchematicClient("test-api-key", schematicclient.WithLocalFlagCheckCache(cacheMaxSize, cacheTTL), schematicclient.WithHTTPClient(mockHTTPClient)) - defer client.Close() - - assert.NotNil(t, client) - - responseBody := &schematicgo.CheckFlagResponse{ - Data: &schematicgo.CheckFlagResponseData{ - Value: true, - }, - } - - for i := 0; i < 2; i++ { - data, err := json.Marshal(responseBody) - assert.Nil(t, err) - mockHTTPClient.EXPECT().Do(gomock.Any()).Return(&http.Response{ - Status: "200", - StatusCode: 200, - Body: io.NopCloser(bytes.NewReader(data)), - }, nil) - } - - // First call should hit the API and set the cache - assert.True(t, client.CheckFlag(context.Background(), &schematicgo.CheckFlagRequestBody{}, "test-flag")) - // Wait enough time for the cache to finish being set in the goroutine - time.Sleep(10 * time.Millisecond) - // Cache hit - assert.True(t, client.CheckFlag(context.Background(), &schematicgo.CheckFlagRequestBody{}, "test-flag")) - // Wait enough time for the cache to expire - time.Sleep(50 * time.Millisecond) - // Cache miss - assert.True(t, client.CheckFlag(context.Background(), &schematicgo.CheckFlagRequestBody{}, "test-flag")) -} - -func TestTrackEventBatch(t *testing.T) { - //ctrl := gomock.NewController(t) - //mockHTTPClient := mocks.NewMockHTTPClient(ctrl) - client := schematicclient.NewSchematicClient("test-api-key", schematicclient.WithEventBufferPeriod(10*time.Millisecond)) - defer client.Close() - - assert.NotNil(t, client) - - ctx := context.Background() - client.Track(ctx, &schematicgo.EventBodyTrack{Event: "foo", Company: map[string]string{"foo": "bar"}}) - client.Track(ctx, &schematicgo.EventBodyTrack{Event: "bar", Company: map[string]string{"foo": "bar"}}) - time.Sleep(11 * time.Millisecond) -} - -func TestMultipleEventBatches(t *testing.T) { - ctrl := gomock.NewController(t) - mockHTTPClient := mocks.NewMockHTTPClient(ctrl) - client := schematicclient.NewSchematicClient("test-api-key", schematicclient.WithEventBufferPeriod(10*time.Millisecond), schematicclient.WithHTTPClient(mockHTTPClient)) - defer client.Close() - - assert.NotNil(t, client) - - responseBody := &schematicgo.CreateEventBatchResponse{ - Data: &schematicgo.RawEventBatchResponseData{ - Events: []*schematicgo.RawEventResponseData{}, - }, - } - - for i := 0; i < 2; i++ { - data, err := json.Marshal(responseBody) - assert.Nil(t, err) - mockHTTPClient.EXPECT().Do(gomock.Any()).Return(&http.Response{ - Status: "200", - StatusCode: 200, - Body: io.NopCloser(bytes.NewReader(data)), - }, nil) - } - - ctx := context.Background() - client.Track(ctx, &schematicgo.EventBodyTrack{Event: "foo", Company: map[string]string{"foo": "bar"}}) - client.Track(ctx, &schematicgo.EventBodyTrack{Event: "bar", Company: map[string]string{"foo": "bar"}}) - // Wait for event buffer to flush and start submitting second batch - time.Sleep(20 * time.Millisecond) - client.Identify(ctx, &schematicgo.EventBodyIdentify{Keys: map[string]string{"foo": "bar"}}) - client.Track(ctx, &schematicgo.EventBodyTrack{Event: "baz", Company: map[string]string{"foo": "bar"}}) - // Wait for event buffer to flush - time.Sleep(20 * time.Millisecond) -} - -func TestCheckFlagOfflineMode(t *testing.T) { - client := schematicclient.NewSchematicClient("") - client.SetFlagDefault("test-flag", true) - defer client.Close() - - assert.True(t, client.CheckFlag(context.Background(), &schematicgo.CheckFlagRequestBody{}, "test-flag")) -} diff --git a/companies.go b/companies.go index 6c8cf00..ece7ef2 100644 --- a/companies.go +++ b/companies.go @@ -9,9 +9,11 @@ import ( ) type CountCompaniesRequest struct { - IDs []*string `json:"-" url:"ids,omitempty"` - PlanID *string `json:"-" url:"plan_id,omitempty"` - // Search filter + // Filter companies by multiple company IDs (starts with comp\_) + IDs []*string `json:"-" url:"ids,omitempty"` + // Filter companies by plan ID (starts with plan\_) + PlanID *string `json:"-" url:"plan_id,omitempty"` + // Search for companies by name, keys or string traits Q *string `json:"-" url:"q,omitempty"` // Filter out companies that already have a company override for the specified feature ID WithoutFeatureOverrideFor *string `json:"-" url:"without_feature_override_for,omitempty"` @@ -36,8 +38,8 @@ type CountEntityKeyDefinitionsRequest struct { type CountEntityTraitDefinitionsRequest struct { EntityType *CountEntityTraitDefinitionsRequestEntityType `json:"-" url:"entity_type,omitempty"` IDs []*string `json:"-" url:"ids,omitempty"` - TraitType *CountEntityTraitDefinitionsRequestTraitType `json:"-" url:"trait_type,omitempty"` Q *string `json:"-" url:"q,omitempty"` + TraitType *CountEntityTraitDefinitionsRequestTraitType `json:"-" url:"trait_type,omitempty"` // Page limit (default 100) Limit *int `json:"-" url:"limit,omitempty"` // Page offset (default 0) @@ -45,10 +47,13 @@ type CountEntityTraitDefinitionsRequest struct { } type CountUsersRequest struct { - CompanyID *string `json:"-" url:"company_id,omitempty"` - IDs []*string `json:"-" url:"ids,omitempty"` - PlanID *string `json:"-" url:"plan_id,omitempty"` - // Search filter + // Filter users by company ID (starts with comp\_) + CompanyID *string `json:"-" url:"company_id,omitempty"` + // Filter users by multiple user IDs (starts with user\_) + IDs []*string `json:"-" url:"ids,omitempty"` + // Filter users by plan ID (starts with plan\_) + PlanID *string `json:"-" url:"plan_id,omitempty"` + // Search for users by name, keys or string traits Q *string `json:"-" url:"q,omitempty"` // Page limit (default 100) Limit *int `json:"-" url:"limit,omitempty"` @@ -95,9 +100,11 @@ type CreateEntityTraitDefinitionRequestBody struct { } type ListCompaniesRequest struct { - IDs []*string `json:"-" url:"ids,omitempty"` - PlanID *string `json:"-" url:"plan_id,omitempty"` - // Search filter + // Filter companies by multiple company IDs (starts with comp\_) + IDs []*string `json:"-" url:"ids,omitempty"` + // Filter companies by plan ID (starts with plan\_) + PlanID *string `json:"-" url:"plan_id,omitempty"` + // Search for companies by name, keys or string traits Q *string `json:"-" url:"q,omitempty"` // Filter out companies that already have a company override for the specified feature ID WithoutFeatureOverrideFor *string `json:"-" url:"without_feature_override_for,omitempty"` @@ -131,8 +138,8 @@ type ListEntityKeyDefinitionsRequest struct { type ListEntityTraitDefinitionsRequest struct { EntityType *ListEntityTraitDefinitionsRequestEntityType `json:"-" url:"entity_type,omitempty"` IDs []*string `json:"-" url:"ids,omitempty"` - TraitType *ListEntityTraitDefinitionsRequestTraitType `json:"-" url:"trait_type,omitempty"` Q *string `json:"-" url:"q,omitempty"` + TraitType *ListEntityTraitDefinitionsRequestTraitType `json:"-" url:"trait_type,omitempty"` // Page limit (default 100) Limit *int `json:"-" url:"limit,omitempty"` // Page offset (default 0) @@ -140,10 +147,13 @@ type ListEntityTraitDefinitionsRequest struct { } type ListUsersRequest struct { - CompanyID *string `json:"-" url:"company_id,omitempty"` - IDs []*string `json:"-" url:"ids,omitempty"` - PlanID *string `json:"-" url:"plan_id,omitempty"` - // Search filter + // Filter users by company ID (starts with comp\_) + CompanyID *string `json:"-" url:"company_id,omitempty"` + // Filter users by multiple user IDs (starts with user\_) + IDs []*string `json:"-" url:"ids,omitempty"` + // Filter users by plan ID (starts with plan\_) + PlanID *string `json:"-" url:"plan_id,omitempty"` + // Search for users by name, keys or string traits Q *string `json:"-" url:"q,omitempty"` // Page limit (default 100) Limit *int `json:"-" url:"limit,omitempty"` diff --git a/companies/client.go b/companies/client.go index ff20034..9696e6b 100644 --- a/companies/client.go +++ b/companies/client.go @@ -104,13 +104,15 @@ func (c *Client) ListCompanies( if err := c.caller.Call( ctx, &core.CallParams{ - URL: endpointURL, - Method: http.MethodGet, - MaxAttempts: options.MaxAttempts, - Headers: headers, - Client: options.HTTPClient, - Response: &response, - ErrorDecoder: errorDecoder, + URL: endpointURL, + Method: http.MethodGet, + MaxAttempts: options.MaxAttempts, + Headers: headers, + BodyProperties: options.BodyProperties, + QueryParameters: options.QueryParameters, + Client: options.HTTPClient, + Response: &response, + ErrorDecoder: errorDecoder, }, ); err != nil { return nil, err @@ -135,6 +137,7 @@ func (c *Client) UpsertCompany( endpointURL := baseURL + "/companies" headers := core.MergeHeaders(c.header.Clone(), options.ToHeader()) + headers.Set("Content-Type", "application/json") errorDecoder := func(statusCode int, body io.Reader) error { raw, err := io.ReadAll(body) @@ -180,14 +183,16 @@ func (c *Client) UpsertCompany( if err := c.caller.Call( ctx, &core.CallParams{ - URL: endpointURL, - Method: http.MethodPost, - MaxAttempts: options.MaxAttempts, - Headers: headers, - Client: options.HTTPClient, - Request: request, - Response: &response, - ErrorDecoder: errorDecoder, + URL: endpointURL, + Method: http.MethodPost, + MaxAttempts: options.MaxAttempts, + Headers: headers, + BodyProperties: options.BodyProperties, + QueryParameters: options.QueryParameters, + Client: options.HTTPClient, + Request: request, + Response: &response, + ErrorDecoder: errorDecoder, }, ); err != nil { return nil, err @@ -258,13 +263,15 @@ func (c *Client) GetCompany( if err := c.caller.Call( ctx, &core.CallParams{ - URL: endpointURL, - Method: http.MethodGet, - MaxAttempts: options.MaxAttempts, - Headers: headers, - Client: options.HTTPClient, - Response: &response, - ErrorDecoder: errorDecoder, + URL: endpointURL, + Method: http.MethodGet, + MaxAttempts: options.MaxAttempts, + Headers: headers, + BodyProperties: options.BodyProperties, + QueryParameters: options.QueryParameters, + Client: options.HTTPClient, + Response: &response, + ErrorDecoder: errorDecoder, }, ); err != nil { return nil, err @@ -335,13 +342,15 @@ func (c *Client) DeleteCompany( if err := c.caller.Call( ctx, &core.CallParams{ - URL: endpointURL, - Method: http.MethodDelete, - MaxAttempts: options.MaxAttempts, - Headers: headers, - Client: options.HTTPClient, - Response: &response, - ErrorDecoder: errorDecoder, + URL: endpointURL, + Method: http.MethodDelete, + MaxAttempts: options.MaxAttempts, + Headers: headers, + BodyProperties: options.BodyProperties, + QueryParameters: options.QueryParameters, + Client: options.HTTPClient, + Response: &response, + ErrorDecoder: errorDecoder, }, ); err != nil { return nil, err @@ -419,13 +428,15 @@ func (c *Client) CountCompanies( if err := c.caller.Call( ctx, &core.CallParams{ - URL: endpointURL, - Method: http.MethodGet, - MaxAttempts: options.MaxAttempts, - Headers: headers, - Client: options.HTTPClient, - Response: &response, - ErrorDecoder: errorDecoder, + URL: endpointURL, + Method: http.MethodGet, + MaxAttempts: options.MaxAttempts, + Headers: headers, + BodyProperties: options.BodyProperties, + QueryParameters: options.QueryParameters, + Client: options.HTTPClient, + Response: &response, + ErrorDecoder: errorDecoder, }, ); err != nil { return nil, err @@ -450,6 +461,7 @@ func (c *Client) CreateCompany( endpointURL := baseURL + "/companies/create" headers := core.MergeHeaders(c.header.Clone(), options.ToHeader()) + headers.Set("Content-Type", "application/json") errorDecoder := func(statusCode int, body io.Reader) error { raw, err := io.ReadAll(body) @@ -495,14 +507,16 @@ func (c *Client) CreateCompany( if err := c.caller.Call( ctx, &core.CallParams{ - URL: endpointURL, - Method: http.MethodPost, - MaxAttempts: options.MaxAttempts, - Headers: headers, - Client: options.HTTPClient, - Request: request, - Response: &response, - ErrorDecoder: errorDecoder, + URL: endpointURL, + Method: http.MethodPost, + MaxAttempts: options.MaxAttempts, + Headers: headers, + BodyProperties: options.BodyProperties, + QueryParameters: options.QueryParameters, + Client: options.HTTPClient, + Request: request, + Response: &response, + ErrorDecoder: errorDecoder, }, ); err != nil { return nil, err @@ -527,6 +541,7 @@ func (c *Client) DeleteCompanyByKeys( endpointURL := baseURL + "/companies/delete" headers := core.MergeHeaders(c.header.Clone(), options.ToHeader()) + headers.Set("Content-Type", "application/json") errorDecoder := func(statusCode int, body io.Reader) error { raw, err := io.ReadAll(body) @@ -572,14 +587,16 @@ func (c *Client) DeleteCompanyByKeys( if err := c.caller.Call( ctx, &core.CallParams{ - URL: endpointURL, - Method: http.MethodPost, - MaxAttempts: options.MaxAttempts, - Headers: headers, - Client: options.HTTPClient, - Request: request, - Response: &response, - ErrorDecoder: errorDecoder, + URL: endpointURL, + Method: http.MethodPost, + MaxAttempts: options.MaxAttempts, + Headers: headers, + BodyProperties: options.BodyProperties, + QueryParameters: options.QueryParameters, + Client: options.HTTPClient, + Request: request, + Response: &response, + ErrorDecoder: errorDecoder, }, ); err != nil { return nil, err @@ -657,13 +674,15 @@ func (c *Client) LookupCompany( if err := c.caller.Call( ctx, &core.CallParams{ - URL: endpointURL, - Method: http.MethodGet, - MaxAttempts: options.MaxAttempts, - Headers: headers, - Client: options.HTTPClient, - Response: &response, - ErrorDecoder: errorDecoder, + URL: endpointURL, + Method: http.MethodGet, + MaxAttempts: options.MaxAttempts, + Headers: headers, + BodyProperties: options.BodyProperties, + QueryParameters: options.QueryParameters, + Client: options.HTTPClient, + Response: &response, + ErrorDecoder: errorDecoder, }, ); err != nil { return nil, err @@ -741,13 +760,15 @@ func (c *Client) GetActiveDeals( if err := c.caller.Call( ctx, &core.CallParams{ - URL: endpointURL, - Method: http.MethodGet, - MaxAttempts: options.MaxAttempts, - Headers: headers, - Client: options.HTTPClient, - Response: &response, - ErrorDecoder: errorDecoder, + URL: endpointURL, + Method: http.MethodGet, + MaxAttempts: options.MaxAttempts, + Headers: headers, + BodyProperties: options.BodyProperties, + QueryParameters: options.QueryParameters, + Client: options.HTTPClient, + Response: &response, + ErrorDecoder: errorDecoder, }, ); err != nil { return nil, err @@ -825,13 +846,15 @@ func (c *Client) ListCompanyMemberships( if err := c.caller.Call( ctx, &core.CallParams{ - URL: endpointURL, - Method: http.MethodGet, - MaxAttempts: options.MaxAttempts, - Headers: headers, - Client: options.HTTPClient, - Response: &response, - ErrorDecoder: errorDecoder, + URL: endpointURL, + Method: http.MethodGet, + MaxAttempts: options.MaxAttempts, + Headers: headers, + BodyProperties: options.BodyProperties, + QueryParameters: options.QueryParameters, + Client: options.HTTPClient, + Response: &response, + ErrorDecoder: errorDecoder, }, ); err != nil { return nil, err @@ -856,6 +879,7 @@ func (c *Client) GetOrCreateCompanyMembership( endpointURL := baseURL + "/company-memberships" headers := core.MergeHeaders(c.header.Clone(), options.ToHeader()) + headers.Set("Content-Type", "application/json") errorDecoder := func(statusCode int, body io.Reader) error { raw, err := io.ReadAll(body) @@ -901,14 +925,16 @@ func (c *Client) GetOrCreateCompanyMembership( if err := c.caller.Call( ctx, &core.CallParams{ - URL: endpointURL, - Method: http.MethodPost, - MaxAttempts: options.MaxAttempts, - Headers: headers, - Client: options.HTTPClient, - Request: request, - Response: &response, - ErrorDecoder: errorDecoder, + URL: endpointURL, + Method: http.MethodPost, + MaxAttempts: options.MaxAttempts, + Headers: headers, + BodyProperties: options.BodyProperties, + QueryParameters: options.QueryParameters, + Client: options.HTTPClient, + Request: request, + Response: &response, + ErrorDecoder: errorDecoder, }, ); err != nil { return nil, err @@ -979,13 +1005,15 @@ func (c *Client) DeleteCompanyMembership( if err := c.caller.Call( ctx, &core.CallParams{ - URL: endpointURL, - Method: http.MethodDelete, - MaxAttempts: options.MaxAttempts, - Headers: headers, - Client: options.HTTPClient, - Response: &response, - ErrorDecoder: errorDecoder, + URL: endpointURL, + Method: http.MethodDelete, + MaxAttempts: options.MaxAttempts, + Headers: headers, + BodyProperties: options.BodyProperties, + QueryParameters: options.QueryParameters, + Client: options.HTTPClient, + Response: &response, + ErrorDecoder: errorDecoder, }, ); err != nil { return nil, err @@ -1063,13 +1091,15 @@ func (c *Client) GetActiveCompanySubscription( if err := c.caller.Call( ctx, &core.CallParams{ - URL: endpointURL, - Method: http.MethodGet, - MaxAttempts: options.MaxAttempts, - Headers: headers, - Client: options.HTTPClient, - Response: &response, - ErrorDecoder: errorDecoder, + URL: endpointURL, + Method: http.MethodGet, + MaxAttempts: options.MaxAttempts, + Headers: headers, + BodyProperties: options.BodyProperties, + QueryParameters: options.QueryParameters, + Client: options.HTTPClient, + Response: &response, + ErrorDecoder: errorDecoder, }, ); err != nil { return nil, err @@ -1094,6 +1124,7 @@ func (c *Client) UpsertCompanyTrait( endpointURL := baseURL + "/company-traits" headers := core.MergeHeaders(c.header.Clone(), options.ToHeader()) + headers.Set("Content-Type", "application/json") errorDecoder := func(statusCode int, body io.Reader) error { raw, err := io.ReadAll(body) @@ -1139,14 +1170,16 @@ func (c *Client) UpsertCompanyTrait( if err := c.caller.Call( ctx, &core.CallParams{ - URL: endpointURL, - Method: http.MethodPost, - MaxAttempts: options.MaxAttempts, - Headers: headers, - Client: options.HTTPClient, - Request: request, - Response: &response, - ErrorDecoder: errorDecoder, + URL: endpointURL, + Method: http.MethodPost, + MaxAttempts: options.MaxAttempts, + Headers: headers, + BodyProperties: options.BodyProperties, + QueryParameters: options.QueryParameters, + Client: options.HTTPClient, + Request: request, + Response: &response, + ErrorDecoder: errorDecoder, }, ); err != nil { return nil, err @@ -1224,13 +1257,15 @@ func (c *Client) ListEntityKeyDefinitions( if err := c.caller.Call( ctx, &core.CallParams{ - URL: endpointURL, - Method: http.MethodGet, - MaxAttempts: options.MaxAttempts, - Headers: headers, - Client: options.HTTPClient, - Response: &response, - ErrorDecoder: errorDecoder, + URL: endpointURL, + Method: http.MethodGet, + MaxAttempts: options.MaxAttempts, + Headers: headers, + BodyProperties: options.BodyProperties, + QueryParameters: options.QueryParameters, + Client: options.HTTPClient, + Response: &response, + ErrorDecoder: errorDecoder, }, ); err != nil { return nil, err @@ -1308,13 +1343,15 @@ func (c *Client) CountEntityKeyDefinitions( if err := c.caller.Call( ctx, &core.CallParams{ - URL: endpointURL, - Method: http.MethodGet, - MaxAttempts: options.MaxAttempts, - Headers: headers, - Client: options.HTTPClient, - Response: &response, - ErrorDecoder: errorDecoder, + URL: endpointURL, + Method: http.MethodGet, + MaxAttempts: options.MaxAttempts, + Headers: headers, + BodyProperties: options.BodyProperties, + QueryParameters: options.QueryParameters, + Client: options.HTTPClient, + Response: &response, + ErrorDecoder: errorDecoder, }, ); err != nil { return nil, err @@ -1392,13 +1429,15 @@ func (c *Client) ListEntityTraitDefinitions( if err := c.caller.Call( ctx, &core.CallParams{ - URL: endpointURL, - Method: http.MethodGet, - MaxAttempts: options.MaxAttempts, - Headers: headers, - Client: options.HTTPClient, - Response: &response, - ErrorDecoder: errorDecoder, + URL: endpointURL, + Method: http.MethodGet, + MaxAttempts: options.MaxAttempts, + Headers: headers, + BodyProperties: options.BodyProperties, + QueryParameters: options.QueryParameters, + Client: options.HTTPClient, + Response: &response, + ErrorDecoder: errorDecoder, }, ); err != nil { return nil, err @@ -1423,6 +1462,7 @@ func (c *Client) GetOrCreateEntityTraitDefinition( endpointURL := baseURL + "/entity-trait-definitions" headers := core.MergeHeaders(c.header.Clone(), options.ToHeader()) + headers.Set("Content-Type", "application/json") errorDecoder := func(statusCode int, body io.Reader) error { raw, err := io.ReadAll(body) @@ -1468,14 +1508,16 @@ func (c *Client) GetOrCreateEntityTraitDefinition( if err := c.caller.Call( ctx, &core.CallParams{ - URL: endpointURL, - Method: http.MethodPost, - MaxAttempts: options.MaxAttempts, - Headers: headers, - Client: options.HTTPClient, - Request: request, - Response: &response, - ErrorDecoder: errorDecoder, + URL: endpointURL, + Method: http.MethodPost, + MaxAttempts: options.MaxAttempts, + Headers: headers, + BodyProperties: options.BodyProperties, + QueryParameters: options.QueryParameters, + Client: options.HTTPClient, + Request: request, + Response: &response, + ErrorDecoder: errorDecoder, }, ); err != nil { return nil, err @@ -1546,13 +1588,15 @@ func (c *Client) GetEntityTraitDefinition( if err := c.caller.Call( ctx, &core.CallParams{ - URL: endpointURL, - Method: http.MethodGet, - MaxAttempts: options.MaxAttempts, - Headers: headers, - Client: options.HTTPClient, - Response: &response, - ErrorDecoder: errorDecoder, + URL: endpointURL, + Method: http.MethodGet, + MaxAttempts: options.MaxAttempts, + Headers: headers, + BodyProperties: options.BodyProperties, + QueryParameters: options.QueryParameters, + Client: options.HTTPClient, + Response: &response, + ErrorDecoder: errorDecoder, }, ); err != nil { return nil, err @@ -1579,6 +1623,7 @@ func (c *Client) UpdateEntityTraitDefinition( endpointURL := core.EncodeURL(baseURL+"/entity-trait-definitions/%v", entityTraitDefinitionID) headers := core.MergeHeaders(c.header.Clone(), options.ToHeader()) + headers.Set("Content-Type", "application/json") errorDecoder := func(statusCode int, body io.Reader) error { raw, err := io.ReadAll(body) @@ -1631,14 +1676,16 @@ func (c *Client) UpdateEntityTraitDefinition( if err := c.caller.Call( ctx, &core.CallParams{ - URL: endpointURL, - Method: http.MethodPut, - MaxAttempts: options.MaxAttempts, - Headers: headers, - Client: options.HTTPClient, - Request: request, - Response: &response, - ErrorDecoder: errorDecoder, + URL: endpointURL, + Method: http.MethodPut, + MaxAttempts: options.MaxAttempts, + Headers: headers, + BodyProperties: options.BodyProperties, + QueryParameters: options.QueryParameters, + Client: options.HTTPClient, + Request: request, + Response: &response, + ErrorDecoder: errorDecoder, }, ); err != nil { return nil, err @@ -1716,13 +1763,15 @@ func (c *Client) CountEntityTraitDefinitions( if err := c.caller.Call( ctx, &core.CallParams{ - URL: endpointURL, - Method: http.MethodGet, - MaxAttempts: options.MaxAttempts, - Headers: headers, - Client: options.HTTPClient, - Response: &response, - ErrorDecoder: errorDecoder, + URL: endpointURL, + Method: http.MethodGet, + MaxAttempts: options.MaxAttempts, + Headers: headers, + BodyProperties: options.BodyProperties, + QueryParameters: options.QueryParameters, + Client: options.HTTPClient, + Response: &response, + ErrorDecoder: errorDecoder, }, ); err != nil { return nil, err @@ -1800,13 +1849,15 @@ func (c *Client) GetEntityTraitValues( if err := c.caller.Call( ctx, &core.CallParams{ - URL: endpointURL, - Method: http.MethodGet, - MaxAttempts: options.MaxAttempts, - Headers: headers, - Client: options.HTTPClient, - Response: &response, - ErrorDecoder: errorDecoder, + URL: endpointURL, + Method: http.MethodGet, + MaxAttempts: options.MaxAttempts, + Headers: headers, + BodyProperties: options.BodyProperties, + QueryParameters: options.QueryParameters, + Client: options.HTTPClient, + Response: &response, + ErrorDecoder: errorDecoder, }, ); err != nil { return nil, err @@ -1831,6 +1882,7 @@ func (c *Client) UpsertUserTrait( endpointURL := baseURL + "/user-traits" headers := core.MergeHeaders(c.header.Clone(), options.ToHeader()) + headers.Set("Content-Type", "application/json") errorDecoder := func(statusCode int, body io.Reader) error { raw, err := io.ReadAll(body) @@ -1876,14 +1928,16 @@ func (c *Client) UpsertUserTrait( if err := c.caller.Call( ctx, &core.CallParams{ - URL: endpointURL, - Method: http.MethodPost, - MaxAttempts: options.MaxAttempts, - Headers: headers, - Client: options.HTTPClient, - Request: request, - Response: &response, - ErrorDecoder: errorDecoder, + URL: endpointURL, + Method: http.MethodPost, + MaxAttempts: options.MaxAttempts, + Headers: headers, + BodyProperties: options.BodyProperties, + QueryParameters: options.QueryParameters, + Client: options.HTTPClient, + Request: request, + Response: &response, + ErrorDecoder: errorDecoder, }, ); err != nil { return nil, err @@ -1961,13 +2015,15 @@ func (c *Client) ListUsers( if err := c.caller.Call( ctx, &core.CallParams{ - URL: endpointURL, - Method: http.MethodGet, - MaxAttempts: options.MaxAttempts, - Headers: headers, - Client: options.HTTPClient, - Response: &response, - ErrorDecoder: errorDecoder, + URL: endpointURL, + Method: http.MethodGet, + MaxAttempts: options.MaxAttempts, + Headers: headers, + BodyProperties: options.BodyProperties, + QueryParameters: options.QueryParameters, + Client: options.HTTPClient, + Response: &response, + ErrorDecoder: errorDecoder, }, ); err != nil { return nil, err @@ -1992,6 +2048,7 @@ func (c *Client) UpsertUser( endpointURL := baseURL + "/users" headers := core.MergeHeaders(c.header.Clone(), options.ToHeader()) + headers.Set("Content-Type", "application/json") errorDecoder := func(statusCode int, body io.Reader) error { raw, err := io.ReadAll(body) @@ -2037,14 +2094,16 @@ func (c *Client) UpsertUser( if err := c.caller.Call( ctx, &core.CallParams{ - URL: endpointURL, - Method: http.MethodPost, - MaxAttempts: options.MaxAttempts, - Headers: headers, - Client: options.HTTPClient, - Request: request, - Response: &response, - ErrorDecoder: errorDecoder, + URL: endpointURL, + Method: http.MethodPost, + MaxAttempts: options.MaxAttempts, + Headers: headers, + BodyProperties: options.BodyProperties, + QueryParameters: options.QueryParameters, + Client: options.HTTPClient, + Request: request, + Response: &response, + ErrorDecoder: errorDecoder, }, ); err != nil { return nil, err @@ -2115,13 +2174,15 @@ func (c *Client) GetUser( if err := c.caller.Call( ctx, &core.CallParams{ - URL: endpointURL, - Method: http.MethodGet, - MaxAttempts: options.MaxAttempts, - Headers: headers, - Client: options.HTTPClient, - Response: &response, - ErrorDecoder: errorDecoder, + URL: endpointURL, + Method: http.MethodGet, + MaxAttempts: options.MaxAttempts, + Headers: headers, + BodyProperties: options.BodyProperties, + QueryParameters: options.QueryParameters, + Client: options.HTTPClient, + Response: &response, + ErrorDecoder: errorDecoder, }, ); err != nil { return nil, err @@ -2192,13 +2253,15 @@ func (c *Client) DeleteUser( if err := c.caller.Call( ctx, &core.CallParams{ - URL: endpointURL, - Method: http.MethodDelete, - MaxAttempts: options.MaxAttempts, - Headers: headers, - Client: options.HTTPClient, - Response: &response, - ErrorDecoder: errorDecoder, + URL: endpointURL, + Method: http.MethodDelete, + MaxAttempts: options.MaxAttempts, + Headers: headers, + BodyProperties: options.BodyProperties, + QueryParameters: options.QueryParameters, + Client: options.HTTPClient, + Response: &response, + ErrorDecoder: errorDecoder, }, ); err != nil { return nil, err @@ -2276,13 +2339,15 @@ func (c *Client) CountUsers( if err := c.caller.Call( ctx, &core.CallParams{ - URL: endpointURL, - Method: http.MethodGet, - MaxAttempts: options.MaxAttempts, - Headers: headers, - Client: options.HTTPClient, - Response: &response, - ErrorDecoder: errorDecoder, + URL: endpointURL, + Method: http.MethodGet, + MaxAttempts: options.MaxAttempts, + Headers: headers, + BodyProperties: options.BodyProperties, + QueryParameters: options.QueryParameters, + Client: options.HTTPClient, + Response: &response, + ErrorDecoder: errorDecoder, }, ); err != nil { return nil, err @@ -2307,6 +2372,7 @@ func (c *Client) CreateUser( endpointURL := baseURL + "/users/create" headers := core.MergeHeaders(c.header.Clone(), options.ToHeader()) + headers.Set("Content-Type", "application/json") errorDecoder := func(statusCode int, body io.Reader) error { raw, err := io.ReadAll(body) @@ -2352,14 +2418,16 @@ func (c *Client) CreateUser( if err := c.caller.Call( ctx, &core.CallParams{ - URL: endpointURL, - Method: http.MethodPost, - MaxAttempts: options.MaxAttempts, - Headers: headers, - Client: options.HTTPClient, - Request: request, - Response: &response, - ErrorDecoder: errorDecoder, + URL: endpointURL, + Method: http.MethodPost, + MaxAttempts: options.MaxAttempts, + Headers: headers, + BodyProperties: options.BodyProperties, + QueryParameters: options.QueryParameters, + Client: options.HTTPClient, + Request: request, + Response: &response, + ErrorDecoder: errorDecoder, }, ); err != nil { return nil, err @@ -2384,6 +2452,7 @@ func (c *Client) DeleteUserByKeys( endpointURL := baseURL + "/users/delete" headers := core.MergeHeaders(c.header.Clone(), options.ToHeader()) + headers.Set("Content-Type", "application/json") errorDecoder := func(statusCode int, body io.Reader) error { raw, err := io.ReadAll(body) @@ -2429,14 +2498,16 @@ func (c *Client) DeleteUserByKeys( if err := c.caller.Call( ctx, &core.CallParams{ - URL: endpointURL, - Method: http.MethodPost, - MaxAttempts: options.MaxAttempts, - Headers: headers, - Client: options.HTTPClient, - Request: request, - Response: &response, - ErrorDecoder: errorDecoder, + URL: endpointURL, + Method: http.MethodPost, + MaxAttempts: options.MaxAttempts, + Headers: headers, + BodyProperties: options.BodyProperties, + QueryParameters: options.QueryParameters, + Client: options.HTTPClient, + Request: request, + Response: &response, + ErrorDecoder: errorDecoder, }, ); err != nil { return nil, err @@ -2514,13 +2585,15 @@ func (c *Client) LookupUser( if err := c.caller.Call( ctx, &core.CallParams{ - URL: endpointURL, - Method: http.MethodGet, - MaxAttempts: options.MaxAttempts, - Headers: headers, - Client: options.HTTPClient, - Response: &response, - ErrorDecoder: errorDecoder, + URL: endpointURL, + Method: http.MethodGet, + MaxAttempts: options.MaxAttempts, + Headers: headers, + BodyProperties: options.BodyProperties, + QueryParameters: options.QueryParameters, + Client: options.HTTPClient, + Response: &response, + ErrorDecoder: errorDecoder, }, ); err != nil { return nil, err diff --git a/components.go b/components.go index e41ecac..02a7f14 100644 --- a/components.go +++ b/components.go @@ -274,7 +274,7 @@ func (l *ListComponentsResponse) String() string { } type PreviewComponentDataResponse struct { - Data *ComponentHydrateResponseData `json:"data,omitempty" url:"data,omitempty"` + Data *ComponentPreviewResponseData `json:"data,omitempty" url:"data,omitempty"` // Input parameters Params *PreviewComponentDataParams `json:"params,omitempty" url:"params,omitempty"` diff --git a/components/client.go b/components/client.go index 18b6055..dab588e 100644 --- a/components/client.go +++ b/components/client.go @@ -104,13 +104,15 @@ func (c *Client) ListComponents( if err := c.caller.Call( ctx, &core.CallParams{ - URL: endpointURL, - Method: http.MethodGet, - MaxAttempts: options.MaxAttempts, - Headers: headers, - Client: options.HTTPClient, - Response: &response, - ErrorDecoder: errorDecoder, + URL: endpointURL, + Method: http.MethodGet, + MaxAttempts: options.MaxAttempts, + Headers: headers, + BodyProperties: options.BodyProperties, + QueryParameters: options.QueryParameters, + Client: options.HTTPClient, + Response: &response, + ErrorDecoder: errorDecoder, }, ); err != nil { return nil, err @@ -135,6 +137,7 @@ func (c *Client) CreateComponent( endpointURL := baseURL + "/components" headers := core.MergeHeaders(c.header.Clone(), options.ToHeader()) + headers.Set("Content-Type", "application/json") errorDecoder := func(statusCode int, body io.Reader) error { raw, err := io.ReadAll(body) @@ -180,14 +183,16 @@ func (c *Client) CreateComponent( if err := c.caller.Call( ctx, &core.CallParams{ - URL: endpointURL, - Method: http.MethodPost, - MaxAttempts: options.MaxAttempts, - Headers: headers, - Client: options.HTTPClient, - Request: request, - Response: &response, - ErrorDecoder: errorDecoder, + URL: endpointURL, + Method: http.MethodPost, + MaxAttempts: options.MaxAttempts, + Headers: headers, + BodyProperties: options.BodyProperties, + QueryParameters: options.QueryParameters, + Client: options.HTTPClient, + Request: request, + Response: &response, + ErrorDecoder: errorDecoder, }, ); err != nil { return nil, err @@ -258,13 +263,15 @@ func (c *Client) GetComponent( if err := c.caller.Call( ctx, &core.CallParams{ - URL: endpointURL, - Method: http.MethodGet, - MaxAttempts: options.MaxAttempts, - Headers: headers, - Client: options.HTTPClient, - Response: &response, - ErrorDecoder: errorDecoder, + URL: endpointURL, + Method: http.MethodGet, + MaxAttempts: options.MaxAttempts, + Headers: headers, + BodyProperties: options.BodyProperties, + QueryParameters: options.QueryParameters, + Client: options.HTTPClient, + Response: &response, + ErrorDecoder: errorDecoder, }, ); err != nil { return nil, err @@ -291,6 +298,7 @@ func (c *Client) UpdateComponent( endpointURL := core.EncodeURL(baseURL+"/components/%v", componentID) headers := core.MergeHeaders(c.header.Clone(), options.ToHeader()) + headers.Set("Content-Type", "application/json") errorDecoder := func(statusCode int, body io.Reader) error { raw, err := io.ReadAll(body) @@ -343,14 +351,16 @@ func (c *Client) UpdateComponent( if err := c.caller.Call( ctx, &core.CallParams{ - URL: endpointURL, - Method: http.MethodPut, - MaxAttempts: options.MaxAttempts, - Headers: headers, - Client: options.HTTPClient, - Request: request, - Response: &response, - ErrorDecoder: errorDecoder, + URL: endpointURL, + Method: http.MethodPut, + MaxAttempts: options.MaxAttempts, + Headers: headers, + BodyProperties: options.BodyProperties, + QueryParameters: options.QueryParameters, + Client: options.HTTPClient, + Request: request, + Response: &response, + ErrorDecoder: errorDecoder, }, ); err != nil { return nil, err @@ -421,13 +431,15 @@ func (c *Client) DeleteComponent( if err := c.caller.Call( ctx, &core.CallParams{ - URL: endpointURL, - Method: http.MethodDelete, - MaxAttempts: options.MaxAttempts, - Headers: headers, - Client: options.HTTPClient, - Response: &response, - ErrorDecoder: errorDecoder, + URL: endpointURL, + Method: http.MethodDelete, + MaxAttempts: options.MaxAttempts, + Headers: headers, + BodyProperties: options.BodyProperties, + QueryParameters: options.QueryParameters, + Client: options.HTTPClient, + Response: &response, + ErrorDecoder: errorDecoder, }, ); err != nil { return nil, err @@ -505,13 +517,15 @@ func (c *Client) CountComponents( if err := c.caller.Call( ctx, &core.CallParams{ - URL: endpointURL, - Method: http.MethodGet, - MaxAttempts: options.MaxAttempts, - Headers: headers, - Client: options.HTTPClient, - Response: &response, - ErrorDecoder: errorDecoder, + URL: endpointURL, + Method: http.MethodGet, + MaxAttempts: options.MaxAttempts, + Headers: headers, + BodyProperties: options.BodyProperties, + QueryParameters: options.QueryParameters, + Client: options.HTTPClient, + Response: &response, + ErrorDecoder: errorDecoder, }, ); err != nil { return nil, err @@ -589,13 +603,15 @@ func (c *Client) PreviewComponentData( if err := c.caller.Call( ctx, &core.CallParams{ - URL: endpointURL, - Method: http.MethodGet, - MaxAttempts: options.MaxAttempts, - Headers: headers, - Client: options.HTTPClient, - Response: &response, - ErrorDecoder: errorDecoder, + URL: endpointURL, + Method: http.MethodGet, + MaxAttempts: options.MaxAttempts, + Headers: headers, + BodyProperties: options.BodyProperties, + QueryParameters: options.QueryParameters, + Client: options.HTTPClient, + Response: &response, + ErrorDecoder: errorDecoder, }, ); err != nil { return nil, err diff --git a/core/core.go b/core/core.go index 14c86c9..6b5a8f3 100644 --- a/core/core.go +++ b/core/core.go @@ -11,6 +11,7 @@ import ( "net/http" "net/url" "reflect" + "strings" ) const ( @@ -137,6 +138,8 @@ type CallParams struct { Method string MaxAttempts uint Headers http.Header + BodyProperties map[string]interface{} + QueryParameters url.Values Client HTTPClient Request interface{} Response interface{} @@ -146,7 +149,15 @@ type CallParams struct { // Call issues an API call according to the given call parameters. func (c *Caller) Call(ctx context.Context, params *CallParams) error { - req, err := newRequest(ctx, params.URL, params.Method, params.Headers, params.Request) + url := buildURL(params.URL, params.QueryParameters) + req, err := newRequest( + ctx, + url, + params.Method, + params.Headers, + params.Request, + params.BodyProperties, + ) if err != nil { return err } @@ -213,6 +224,23 @@ func (c *Caller) Call(ctx context.Context, params *CallParams) error { return nil } +// buildURL constructs the final URL by appending the given query parameters (if any). +func buildURL( + url string, + queryParameters url.Values, +) string { + if len(queryParameters) == 0 { + return url + } + if strings.ContainsRune(url, '?') { + url += "&" + } else { + url += "?" + } + url += queryParameters.Encode() + return url +} + // newRequest returns a new *http.Request with all of the fields // required to issue the call. func newRequest( @@ -221,8 +249,9 @@ func newRequest( method string, endpointHeaders http.Header, request interface{}, + bodyProperties map[string]interface{}, ) (*http.Request, error) { - requestBody, err := newRequestBody(request) + requestBody, err := newRequestBody(request, bodyProperties) if err != nil { return nil, err } @@ -239,20 +268,25 @@ func newRequest( } // newRequestBody returns a new io.Reader that represents the HTTP request body. -func newRequestBody(request interface{}) (io.Reader, error) { - var requestBody io.Reader - if !isNil(request) { - if body, ok := request.(io.Reader); ok { - requestBody = body - } else { - requestBytes, err := json.Marshal(request) - if err != nil { - return nil, err - } - requestBody = bytes.NewReader(requestBytes) +func newRequestBody(request interface{}, bodyProperties map[string]interface{}) (io.Reader, error) { + if isNil(request) { + if len(bodyProperties) == 0 { + return nil, nil + } + requestBytes, err := json.Marshal(bodyProperties) + if err != nil { + return nil, err } + return bytes.NewReader(requestBytes), nil + } + if body, ok := request.(io.Reader); ok { + return body, nil + } + requestBytes, err := MarshalJSONWithExtraProperties(request, bodyProperties) + if err != nil { + return nil, err } - return requestBody, nil + return bytes.NewReader(requestBytes), nil } // decodeError decodes the error from the given HTTP response. Note that diff --git a/core/core_test.go b/core/core_test.go index adf9e31..e6eaef3 100644 --- a/core/core_test.go +++ b/core/core_test.go @@ -9,6 +9,7 @@ import ( "io" "net/http" "net/http/httptest" + "net/url" "strconv" "testing" @@ -21,11 +22,14 @@ type TestCase struct { description string // Server-side assertions. + givePathSuffix string giveMethod string giveResponseIsOptional bool giveHeader http.Header giveErrorDecoder ErrorDecoder giveRequest *Request + giveQueryParams url.Values + giveBodyProperties map[string]interface{} // Client-side assertions. wantResponse *Response @@ -39,7 +43,9 @@ type Request struct { // Response a simple response body. type Response struct { - Id string `json:"id"` + Id string `json:"id"` + ExtraBodyProperties map[string]interface{} `json:"extraBodyProperties,omitempty"` + QueryParameters url.Values `json:"queryParameters,omitempty"` } // NotFoundError represents a 404. @@ -64,6 +70,23 @@ func TestCall(t *testing.T) { Id: "123", }, }, + { + description: "GET success with query", + givePathSuffix: "?limit=1", + giveMethod: http.MethodGet, + giveHeader: http.Header{ + "X-API-Status": []string{"success"}, + }, + giveRequest: &Request{ + Id: "123", + }, + wantResponse: &Response{ + Id: "123", + QueryParameters: url.Values{ + "limit": []string{"1"}, + }, + }, + }, { description: "GET not found", giveMethod: http.MethodGet, @@ -118,6 +141,62 @@ func TestCall(t *testing.T) { errors.New("failed to process request"), ), }, + { + description: "POST extra properties", + giveMethod: http.MethodPost, + giveHeader: http.Header{ + "X-API-Status": []string{"success"}, + }, + giveRequest: new(Request), + giveBodyProperties: map[string]interface{}{ + "key": "value", + }, + wantResponse: &Response{ + ExtraBodyProperties: map[string]interface{}{ + "key": "value", + }, + }, + }, + { + description: "GET extra query parameters", + giveMethod: http.MethodGet, + giveHeader: http.Header{ + "X-API-Status": []string{"success"}, + }, + giveQueryParams: url.Values{ + "extra": []string{"true"}, + }, + giveRequest: &Request{ + Id: "123", + }, + wantResponse: &Response{ + Id: "123", + QueryParameters: url.Values{ + "extra": []string{"true"}, + }, + }, + }, + { + description: "GET merge extra query parameters", + givePathSuffix: "?limit=1", + giveMethod: http.MethodGet, + giveHeader: http.Header{ + "X-API-Status": []string{"success"}, + }, + giveRequest: &Request{ + Id: "123", + }, + giveQueryParams: url.Values{ + "extra": []string{"true"}, + }, + wantResponse: &Response{ + Id: "123", + QueryParameters: url.Values{ + "limit": []string{"1"}, + "extra": []string{"true"}, + }, + }, + }, } for _, test := range tests { t.Run(test.description, func(t *testing.T) { @@ -134,9 +213,11 @@ func TestCall(t *testing.T) { err := caller.Call( context.Background(), &CallParams{ - URL: server.URL, + URL: server.URL + test.givePathSuffix, Method: test.giveMethod, Headers: test.giveHeader, + BodyProperties: test.giveBodyProperties, + QueryParameters: test.giveQueryParams, Request: test.giveRequest, Response: &response, ResponseIsOptional: test.giveResponseIsOptional, @@ -268,8 +349,14 @@ func newTestServer(t *testing.T, tc *TestCase) *httptest.Server { return } + extraBodyProperties := make(map[string]interface{}) + require.NoError(t, json.Unmarshal(bytes, &extraBodyProperties)) + delete(extraBodyProperties, "id") + response := &Response{ - Id: request.Id, + Id: request.Id, + ExtraBodyProperties: extraBodyProperties, + QueryParameters: r.URL.Query(), } bytes, err = json.Marshal(response) require.NoError(t, err) diff --git a/core/request_option.go b/core/request_option.go index bf6596e..07d8ea5 100644 --- a/core/request_option.go +++ b/core/request_option.go @@ -5,6 +5,7 @@ package core import ( fmt "fmt" http "net/http" + url "net/url" ) // RequestOption adapts the behavior of the client or an individual request. @@ -17,11 +18,13 @@ type RequestOption interface { // This type is primarily used by the generated code and is not meant // to be used directly; use the option package instead. type RequestOptions struct { - BaseURL string - HTTPClient HTTPClient - HTTPHeader http.Header - MaxAttempts uint - APIKey string + BaseURL string + HTTPClient HTTPClient + HTTPHeader http.Header + BodyProperties map[string]interface{} + QueryParameters url.Values + MaxAttempts uint + APIKey string } // NewRequestOptions returns a new *RequestOptions value. @@ -30,7 +33,9 @@ type RequestOptions struct { // to be used directly; use RequestOption instead. func NewRequestOptions(opts ...RequestOption) *RequestOptions { options := &RequestOptions{ - HTTPHeader: make(http.Header), + HTTPHeader: make(http.Header), + BodyProperties: make(map[string]interface{}), + QueryParameters: make(url.Values), } for _, opt := range opts { opt.applyRequestOptions(options) @@ -83,6 +88,24 @@ func (h *HTTPHeaderOption) applyRequestOptions(opts *RequestOptions) { opts.HTTPHeader = h.HTTPHeader } +// BodyPropertiesOption implements the RequestOption interface. +type BodyPropertiesOption struct { + BodyProperties map[string]interface{} +} + +func (b *BodyPropertiesOption) applyRequestOptions(opts *RequestOptions) { + opts.BodyProperties = b.BodyProperties +} + +// QueryParametersOption implements the RequestOption interface. +type QueryParametersOption struct { + QueryParameters url.Values +} + +func (q *QueryParametersOption) applyRequestOptions(opts *RequestOptions) { + opts.QueryParameters = q.QueryParameters +} + // MaxAttemptsOption implements the RequestOption interface. type MaxAttemptsOption struct { MaxAttempts uint diff --git a/crm/client.go b/crm/client.go index 36f68ec..f98bf0c 100644 --- a/crm/client.go +++ b/crm/client.go @@ -51,6 +51,7 @@ func (c *Client) UpsertDealLineItemAssociation( endpointURL := baseURL + "/crm/associations/deal-line-item" headers := core.MergeHeaders(c.header.Clone(), options.ToHeader()) + headers.Set("Content-Type", "application/json") errorDecoder := func(statusCode int, body io.Reader) error { raw, err := io.ReadAll(body) @@ -96,14 +97,16 @@ func (c *Client) UpsertDealLineItemAssociation( if err := c.caller.Call( ctx, &core.CallParams{ - URL: endpointURL, - Method: http.MethodPost, - MaxAttempts: options.MaxAttempts, - Headers: headers, - Client: options.HTTPClient, - Request: request, - Response: &response, - ErrorDecoder: errorDecoder, + URL: endpointURL, + Method: http.MethodPost, + MaxAttempts: options.MaxAttempts, + Headers: headers, + BodyProperties: options.BodyProperties, + QueryParameters: options.QueryParameters, + Client: options.HTTPClient, + Request: request, + Response: &response, + ErrorDecoder: errorDecoder, }, ); err != nil { return nil, err @@ -128,6 +131,7 @@ func (c *Client) UpsertLineItem( endpointURL := baseURL + "/crm/deal-line-item/upsert" headers := core.MergeHeaders(c.header.Clone(), options.ToHeader()) + headers.Set("Content-Type", "application/json") errorDecoder := func(statusCode int, body io.Reader) error { raw, err := io.ReadAll(body) @@ -173,14 +177,16 @@ func (c *Client) UpsertLineItem( if err := c.caller.Call( ctx, &core.CallParams{ - URL: endpointURL, - Method: http.MethodPost, - MaxAttempts: options.MaxAttempts, - Headers: headers, - Client: options.HTTPClient, - Request: request, - Response: &response, - ErrorDecoder: errorDecoder, + URL: endpointURL, + Method: http.MethodPost, + MaxAttempts: options.MaxAttempts, + Headers: headers, + BodyProperties: options.BodyProperties, + QueryParameters: options.QueryParameters, + Client: options.HTTPClient, + Request: request, + Response: &response, + ErrorDecoder: errorDecoder, }, ); err != nil { return nil, err @@ -205,6 +211,7 @@ func (c *Client) UpsertCrmDeal( endpointURL := baseURL + "/crm/deals/upsert" headers := core.MergeHeaders(c.header.Clone(), options.ToHeader()) + headers.Set("Content-Type", "application/json") errorDecoder := func(statusCode int, body io.Reader) error { raw, err := io.ReadAll(body) @@ -250,14 +257,16 @@ func (c *Client) UpsertCrmDeal( if err := c.caller.Call( ctx, &core.CallParams{ - URL: endpointURL, - Method: http.MethodPost, - MaxAttempts: options.MaxAttempts, - Headers: headers, - Client: options.HTTPClient, - Request: request, - Response: &response, - ErrorDecoder: errorDecoder, + URL: endpointURL, + Method: http.MethodPost, + MaxAttempts: options.MaxAttempts, + Headers: headers, + BodyProperties: options.BodyProperties, + QueryParameters: options.QueryParameters, + Client: options.HTTPClient, + Request: request, + Response: &response, + ErrorDecoder: errorDecoder, }, ); err != nil { return nil, err @@ -335,13 +344,15 @@ func (c *Client) ListCrmProducts( if err := c.caller.Call( ctx, &core.CallParams{ - URL: endpointURL, - Method: http.MethodGet, - MaxAttempts: options.MaxAttempts, - Headers: headers, - Client: options.HTTPClient, - Response: &response, - ErrorDecoder: errorDecoder, + URL: endpointURL, + Method: http.MethodGet, + MaxAttempts: options.MaxAttempts, + Headers: headers, + BodyProperties: options.BodyProperties, + QueryParameters: options.QueryParameters, + Client: options.HTTPClient, + Response: &response, + ErrorDecoder: errorDecoder, }, ); err != nil { return nil, err @@ -366,6 +377,7 @@ func (c *Client) UpsertCrmProduct( endpointURL := baseURL + "/crm/products/upsert" headers := core.MergeHeaders(c.header.Clone(), options.ToHeader()) + headers.Set("Content-Type", "application/json") errorDecoder := func(statusCode int, body io.Reader) error { raw, err := io.ReadAll(body) @@ -411,14 +423,16 @@ func (c *Client) UpsertCrmProduct( if err := c.caller.Call( ctx, &core.CallParams{ - URL: endpointURL, - Method: http.MethodPost, - MaxAttempts: options.MaxAttempts, - Headers: headers, - Client: options.HTTPClient, - Request: request, - Response: &response, - ErrorDecoder: errorDecoder, + URL: endpointURL, + Method: http.MethodPost, + MaxAttempts: options.MaxAttempts, + Headers: headers, + BodyProperties: options.BodyProperties, + QueryParameters: options.QueryParameters, + Client: options.HTTPClient, + Request: request, + Response: &response, + ErrorDecoder: errorDecoder, }, ); err != nil { return nil, err diff --git a/custom_types.go b/custom_types.go deleted file mode 100644 index 07817b5..0000000 --- a/custom_types.go +++ /dev/null @@ -1,18 +0,0 @@ -package schematichq - -import ( - "context" - time "time" -) - -type CacheProvider[T any] interface { - Get(ctx context.Context, key string) (T, bool) - Set(ctx context.Context, key string, val T, ttlOverride *time.Duration) error -} - -// gomock generator doesn't like generic args so adding this for the SchematicClient interface -type CacheProviderBool = CacheProvider[bool] - -type Logger interface { - Printf(format string, args ...interface{}) -} diff --git a/entitlements.go b/entitlements.go index 5a916d0..a3ae77c 100644 --- a/entitlements.go +++ b/entitlements.go @@ -9,12 +9,18 @@ import ( ) type CountCompanyOverridesRequest struct { - CompanyID *string `json:"-" url:"company_id,omitempty"` + // Filter company overrides by a single company ID (starting with comp\_) + CompanyID *string `json:"-" url:"company_id,omitempty"` + // Filter company overrides by multiple company IDs (starting with comp\_) CompanyIDs []*string `json:"-" url:"company_ids,omitempty"` - FeatureID *string `json:"-" url:"feature_id,omitempty"` + // Filter company overrides by a single feature ID (starting with feat\_) + FeatureID *string `json:"-" url:"feature_id,omitempty"` + // Filter company overrides by multiple feature IDs (starting with feat\_) FeatureIDs []*string `json:"-" url:"feature_ids,omitempty"` - IDs []*string `json:"-" url:"ids,omitempty"` - Q *string `json:"-" url:"q,omitempty"` + // Filter company overrides by multiple company override IDs (starting with cmov\_) + IDs []*string `json:"-" url:"ids,omitempty"` + // Search for company overrides by feature or company name + Q *string `json:"-" url:"q,omitempty"` // Page limit (default 100) Limit *int `json:"-" url:"limit,omitempty"` // Page offset (default 0) @@ -31,10 +37,11 @@ type CountFeatureCompaniesRequest struct { } type CountFeatureUsageRequest struct { - CompanyID *string `json:"-" url:"company_id,omitempty"` - CompanyKeys map[string]*string `json:"-" url:"company_keys,omitempty"` - FeatureIDs []*string `json:"-" url:"feature_ids,omitempty"` - Q *string `json:"-" url:"q,omitempty"` + CompanyID *string `json:"-" url:"company_id,omitempty"` + CompanyKeys map[string]string `json:"-" url:"company_keys,omitempty"` + FeatureIDs []*string `json:"-" url:"feature_ids,omitempty"` + Q *string `json:"-" url:"q,omitempty"` + WithoutNegativeEntitlements *bool `json:"-" url:"without_negative_entitlements,omitempty"` // Page limit (default 100) Limit *int `json:"-" url:"limit,omitempty"` // Page offset (default 0) @@ -51,12 +58,18 @@ type CountFeatureUsersRequest struct { } type CountPlanEntitlementsRequest struct { - FeatureID *string `json:"-" url:"feature_id,omitempty"` + // Filter plan entitlements by a single feature ID (starting with feat\_) + FeatureID *string `json:"-" url:"feature_id,omitempty"` + // Filter plan entitlements by multiple feature IDs (starting with feat\_) FeatureIDs []*string `json:"-" url:"feature_ids,omitempty"` - IDs []*string `json:"-" url:"ids,omitempty"` - PlanID *string `json:"-" url:"plan_id,omitempty"` - PlanIDs []*string `json:"-" url:"plan_ids,omitempty"` - Q *string `json:"-" url:"q,omitempty"` + // Filter plan entitlements by multiple plan entitlement IDs (starting with pltl\_) + IDs []*string `json:"-" url:"ids,omitempty"` + // Filter plan entitlements by a single plan ID (starting with plan\_) + PlanID *string `json:"-" url:"plan_id,omitempty"` + // Filter plan entitlements by multiple plan IDs (starting with plan\_) + PlanIDs []*string `json:"-" url:"plan_ids,omitempty"` + // Search for plan entitlements by feature or company name + Q *string `json:"-" url:"q,omitempty"` // Page limit (default 100) Limit *int `json:"-" url:"limit,omitempty"` // Page offset (default 0) @@ -89,12 +102,18 @@ type GetFeatureUsageByCompanyRequest struct { } type ListCompanyOverridesRequest struct { - CompanyID *string `json:"-" url:"company_id,omitempty"` + // Filter company overrides by a single company ID (starting with comp\_) + CompanyID *string `json:"-" url:"company_id,omitempty"` + // Filter company overrides by multiple company IDs (starting with comp\_) CompanyIDs []*string `json:"-" url:"company_ids,omitempty"` - FeatureID *string `json:"-" url:"feature_id,omitempty"` + // Filter company overrides by a single feature ID (starting with feat\_) + FeatureID *string `json:"-" url:"feature_id,omitempty"` + // Filter company overrides by multiple feature IDs (starting with feat\_) FeatureIDs []*string `json:"-" url:"feature_ids,omitempty"` - IDs []*string `json:"-" url:"ids,omitempty"` - Q *string `json:"-" url:"q,omitempty"` + // Filter company overrides by multiple company override IDs (starting with cmov\_) + IDs []*string `json:"-" url:"ids,omitempty"` + // Search for company overrides by feature or company name + Q *string `json:"-" url:"q,omitempty"` // Page limit (default 100) Limit *int `json:"-" url:"limit,omitempty"` // Page offset (default 0) @@ -111,10 +130,11 @@ type ListFeatureCompaniesRequest struct { } type ListFeatureUsageRequest struct { - CompanyID *string `json:"-" url:"company_id,omitempty"` - CompanyKeys map[string]*string `json:"-" url:"company_keys,omitempty"` - FeatureIDs []*string `json:"-" url:"feature_ids,omitempty"` - Q *string `json:"-" url:"q,omitempty"` + CompanyID *string `json:"-" url:"company_id,omitempty"` + CompanyKeys map[string]string `json:"-" url:"company_keys,omitempty"` + FeatureIDs []*string `json:"-" url:"feature_ids,omitempty"` + Q *string `json:"-" url:"q,omitempty"` + WithoutNegativeEntitlements *bool `json:"-" url:"without_negative_entitlements,omitempty"` // Page limit (default 100) Limit *int `json:"-" url:"limit,omitempty"` // Page offset (default 0) @@ -131,12 +151,18 @@ type ListFeatureUsersRequest struct { } type ListPlanEntitlementsRequest struct { - FeatureID *string `json:"-" url:"feature_id,omitempty"` + // Filter plan entitlements by a single feature ID (starting with feat\_) + FeatureID *string `json:"-" url:"feature_id,omitempty"` + // Filter plan entitlements by multiple feature IDs (starting with feat\_) FeatureIDs []*string `json:"-" url:"feature_ids,omitempty"` - IDs []*string `json:"-" url:"ids,omitempty"` - PlanID *string `json:"-" url:"plan_id,omitempty"` - PlanIDs []*string `json:"-" url:"plan_ids,omitempty"` - Q *string `json:"-" url:"q,omitempty"` + // Filter plan entitlements by multiple plan entitlement IDs (starting with pltl\_) + IDs []*string `json:"-" url:"ids,omitempty"` + // Filter plan entitlements by a single plan ID (starting with plan\_) + PlanID *string `json:"-" url:"plan_id,omitempty"` + // Filter plan entitlements by multiple plan IDs (starting with plan\_) + PlanIDs []*string `json:"-" url:"plan_ids,omitempty"` + // Search for plan entitlements by feature or company name + Q *string `json:"-" url:"q,omitempty"` // Page limit (default 100) Limit *int `json:"-" url:"limit,omitempty"` // Page offset (default 0) @@ -361,6 +387,7 @@ func (c *CountPlanEntitlementsResponse) String() string { type CreateCompanyOverrideRequestBodyMetricPeriod string const ( + CreateCompanyOverrideRequestBodyMetricPeriodBilling CreateCompanyOverrideRequestBodyMetricPeriod = "billing" CreateCompanyOverrideRequestBodyMetricPeriodCurrentMonth CreateCompanyOverrideRequestBodyMetricPeriod = "current_month" CreateCompanyOverrideRequestBodyMetricPeriodCurrentWeek CreateCompanyOverrideRequestBodyMetricPeriod = "current_week" CreateCompanyOverrideRequestBodyMetricPeriodCurrentDay CreateCompanyOverrideRequestBodyMetricPeriod = "current_day" @@ -368,6 +395,8 @@ const ( func NewCreateCompanyOverrideRequestBodyMetricPeriodFromString(s string) (CreateCompanyOverrideRequestBodyMetricPeriod, error) { switch s { + case "billing": + return CreateCompanyOverrideRequestBodyMetricPeriodBilling, nil case "current_month": return CreateCompanyOverrideRequestBodyMetricPeriodCurrentMonth, nil case "current_week": @@ -457,6 +486,7 @@ func (c *CreateCompanyOverrideResponse) String() string { type CreatePlanEntitlementRequestBodyMetricPeriod string const ( + CreatePlanEntitlementRequestBodyMetricPeriodBilling CreatePlanEntitlementRequestBodyMetricPeriod = "billing" CreatePlanEntitlementRequestBodyMetricPeriodCurrentMonth CreatePlanEntitlementRequestBodyMetricPeriod = "current_month" CreatePlanEntitlementRequestBodyMetricPeriodCurrentWeek CreatePlanEntitlementRequestBodyMetricPeriod = "current_week" CreatePlanEntitlementRequestBodyMetricPeriodCurrentDay CreatePlanEntitlementRequestBodyMetricPeriod = "current_day" @@ -464,6 +494,8 @@ const ( func NewCreatePlanEntitlementRequestBodyMetricPeriodFromString(s string) (CreatePlanEntitlementRequestBodyMetricPeriod, error) { switch s { + case "billing": + return CreatePlanEntitlementRequestBodyMetricPeriodBilling, nil case "current_month": return CreatePlanEntitlementRequestBodyMetricPeriodCurrentMonth, nil case "current_week": @@ -988,6 +1020,7 @@ func (l *ListPlanEntitlementsResponse) String() string { type UpdateCompanyOverrideRequestBodyMetricPeriod string const ( + UpdateCompanyOverrideRequestBodyMetricPeriodBilling UpdateCompanyOverrideRequestBodyMetricPeriod = "billing" UpdateCompanyOverrideRequestBodyMetricPeriodCurrentMonth UpdateCompanyOverrideRequestBodyMetricPeriod = "current_month" UpdateCompanyOverrideRequestBodyMetricPeriodCurrentWeek UpdateCompanyOverrideRequestBodyMetricPeriod = "current_week" UpdateCompanyOverrideRequestBodyMetricPeriodCurrentDay UpdateCompanyOverrideRequestBodyMetricPeriod = "current_day" @@ -995,6 +1028,8 @@ const ( func NewUpdateCompanyOverrideRequestBodyMetricPeriodFromString(s string) (UpdateCompanyOverrideRequestBodyMetricPeriod, error) { switch s { + case "billing": + return UpdateCompanyOverrideRequestBodyMetricPeriodBilling, nil case "current_month": return UpdateCompanyOverrideRequestBodyMetricPeriodCurrentMonth, nil case "current_week": @@ -1084,6 +1119,7 @@ func (u *UpdateCompanyOverrideResponse) String() string { type UpdatePlanEntitlementRequestBodyMetricPeriod string const ( + UpdatePlanEntitlementRequestBodyMetricPeriodBilling UpdatePlanEntitlementRequestBodyMetricPeriod = "billing" UpdatePlanEntitlementRequestBodyMetricPeriodCurrentMonth UpdatePlanEntitlementRequestBodyMetricPeriod = "current_month" UpdatePlanEntitlementRequestBodyMetricPeriodCurrentWeek UpdatePlanEntitlementRequestBodyMetricPeriod = "current_week" UpdatePlanEntitlementRequestBodyMetricPeriodCurrentDay UpdatePlanEntitlementRequestBodyMetricPeriod = "current_day" @@ -1091,6 +1127,8 @@ const ( func NewUpdatePlanEntitlementRequestBodyMetricPeriodFromString(s string) (UpdatePlanEntitlementRequestBodyMetricPeriod, error) { switch s { + case "billing": + return UpdatePlanEntitlementRequestBodyMetricPeriodBilling, nil case "current_month": return UpdatePlanEntitlementRequestBodyMetricPeriodCurrentMonth, nil case "current_week": diff --git a/entitlements/client.go b/entitlements/client.go index ccbb818..aeada69 100644 --- a/entitlements/client.go +++ b/entitlements/client.go @@ -104,13 +104,15 @@ func (c *Client) ListCompanyOverrides( if err := c.caller.Call( ctx, &core.CallParams{ - URL: endpointURL, - Method: http.MethodGet, - MaxAttempts: options.MaxAttempts, - Headers: headers, - Client: options.HTTPClient, - Response: &response, - ErrorDecoder: errorDecoder, + URL: endpointURL, + Method: http.MethodGet, + MaxAttempts: options.MaxAttempts, + Headers: headers, + BodyProperties: options.BodyProperties, + QueryParameters: options.QueryParameters, + Client: options.HTTPClient, + Response: &response, + ErrorDecoder: errorDecoder, }, ); err != nil { return nil, err @@ -135,6 +137,7 @@ func (c *Client) CreateCompanyOverride( endpointURL := baseURL + "/company-overrides" headers := core.MergeHeaders(c.header.Clone(), options.ToHeader()) + headers.Set("Content-Type", "application/json") errorDecoder := func(statusCode int, body io.Reader) error { raw, err := io.ReadAll(body) @@ -180,14 +183,16 @@ func (c *Client) CreateCompanyOverride( if err := c.caller.Call( ctx, &core.CallParams{ - URL: endpointURL, - Method: http.MethodPost, - MaxAttempts: options.MaxAttempts, - Headers: headers, - Client: options.HTTPClient, - Request: request, - Response: &response, - ErrorDecoder: errorDecoder, + URL: endpointURL, + Method: http.MethodPost, + MaxAttempts: options.MaxAttempts, + Headers: headers, + BodyProperties: options.BodyProperties, + QueryParameters: options.QueryParameters, + Client: options.HTTPClient, + Request: request, + Response: &response, + ErrorDecoder: errorDecoder, }, ); err != nil { return nil, err @@ -258,13 +263,15 @@ func (c *Client) GetCompanyOverride( if err := c.caller.Call( ctx, &core.CallParams{ - URL: endpointURL, - Method: http.MethodGet, - MaxAttempts: options.MaxAttempts, - Headers: headers, - Client: options.HTTPClient, - Response: &response, - ErrorDecoder: errorDecoder, + URL: endpointURL, + Method: http.MethodGet, + MaxAttempts: options.MaxAttempts, + Headers: headers, + BodyProperties: options.BodyProperties, + QueryParameters: options.QueryParameters, + Client: options.HTTPClient, + Response: &response, + ErrorDecoder: errorDecoder, }, ); err != nil { return nil, err @@ -291,6 +298,7 @@ func (c *Client) UpdateCompanyOverride( endpointURL := core.EncodeURL(baseURL+"/company-overrides/%v", companyOverrideID) headers := core.MergeHeaders(c.header.Clone(), options.ToHeader()) + headers.Set("Content-Type", "application/json") errorDecoder := func(statusCode int, body io.Reader) error { raw, err := io.ReadAll(body) @@ -343,14 +351,16 @@ func (c *Client) UpdateCompanyOverride( if err := c.caller.Call( ctx, &core.CallParams{ - URL: endpointURL, - Method: http.MethodPut, - MaxAttempts: options.MaxAttempts, - Headers: headers, - Client: options.HTTPClient, - Request: request, - Response: &response, - ErrorDecoder: errorDecoder, + URL: endpointURL, + Method: http.MethodPut, + MaxAttempts: options.MaxAttempts, + Headers: headers, + BodyProperties: options.BodyProperties, + QueryParameters: options.QueryParameters, + Client: options.HTTPClient, + Request: request, + Response: &response, + ErrorDecoder: errorDecoder, }, ); err != nil { return nil, err @@ -421,13 +431,15 @@ func (c *Client) DeleteCompanyOverride( if err := c.caller.Call( ctx, &core.CallParams{ - URL: endpointURL, - Method: http.MethodDelete, - MaxAttempts: options.MaxAttempts, - Headers: headers, - Client: options.HTTPClient, - Response: &response, - ErrorDecoder: errorDecoder, + URL: endpointURL, + Method: http.MethodDelete, + MaxAttempts: options.MaxAttempts, + Headers: headers, + BodyProperties: options.BodyProperties, + QueryParameters: options.QueryParameters, + Client: options.HTTPClient, + Response: &response, + ErrorDecoder: errorDecoder, }, ); err != nil { return nil, err @@ -505,13 +517,15 @@ func (c *Client) CountCompanyOverrides( if err := c.caller.Call( ctx, &core.CallParams{ - URL: endpointURL, - Method: http.MethodGet, - MaxAttempts: options.MaxAttempts, - Headers: headers, - Client: options.HTTPClient, - Response: &response, - ErrorDecoder: errorDecoder, + URL: endpointURL, + Method: http.MethodGet, + MaxAttempts: options.MaxAttempts, + Headers: headers, + BodyProperties: options.BodyProperties, + QueryParameters: options.QueryParameters, + Client: options.HTTPClient, + Response: &response, + ErrorDecoder: errorDecoder, }, ); err != nil { return nil, err @@ -589,13 +603,15 @@ func (c *Client) ListFeatureCompanies( if err := c.caller.Call( ctx, &core.CallParams{ - URL: endpointURL, - Method: http.MethodGet, - MaxAttempts: options.MaxAttempts, - Headers: headers, - Client: options.HTTPClient, - Response: &response, - ErrorDecoder: errorDecoder, + URL: endpointURL, + Method: http.MethodGet, + MaxAttempts: options.MaxAttempts, + Headers: headers, + BodyProperties: options.BodyProperties, + QueryParameters: options.QueryParameters, + Client: options.HTTPClient, + Response: &response, + ErrorDecoder: errorDecoder, }, ); err != nil { return nil, err @@ -673,13 +689,15 @@ func (c *Client) CountFeatureCompanies( if err := c.caller.Call( ctx, &core.CallParams{ - URL: endpointURL, - Method: http.MethodGet, - MaxAttempts: options.MaxAttempts, - Headers: headers, - Client: options.HTTPClient, - Response: &response, - ErrorDecoder: errorDecoder, + URL: endpointURL, + Method: http.MethodGet, + MaxAttempts: options.MaxAttempts, + Headers: headers, + BodyProperties: options.BodyProperties, + QueryParameters: options.QueryParameters, + Client: options.HTTPClient, + Response: &response, + ErrorDecoder: errorDecoder, }, ); err != nil { return nil, err @@ -757,13 +775,15 @@ func (c *Client) ListFeatureUsage( if err := c.caller.Call( ctx, &core.CallParams{ - URL: endpointURL, - Method: http.MethodGet, - MaxAttempts: options.MaxAttempts, - Headers: headers, - Client: options.HTTPClient, - Response: &response, - ErrorDecoder: errorDecoder, + URL: endpointURL, + Method: http.MethodGet, + MaxAttempts: options.MaxAttempts, + Headers: headers, + BodyProperties: options.BodyProperties, + QueryParameters: options.QueryParameters, + Client: options.HTTPClient, + Response: &response, + ErrorDecoder: errorDecoder, }, ); err != nil { return nil, err @@ -841,13 +861,15 @@ func (c *Client) CountFeatureUsage( if err := c.caller.Call( ctx, &core.CallParams{ - URL: endpointURL, - Method: http.MethodGet, - MaxAttempts: options.MaxAttempts, - Headers: headers, - Client: options.HTTPClient, - Response: &response, - ErrorDecoder: errorDecoder, + URL: endpointURL, + Method: http.MethodGet, + MaxAttempts: options.MaxAttempts, + Headers: headers, + BodyProperties: options.BodyProperties, + QueryParameters: options.QueryParameters, + Client: options.HTTPClient, + Response: &response, + ErrorDecoder: errorDecoder, }, ); err != nil { return nil, err @@ -925,13 +947,15 @@ func (c *Client) ListFeatureUsers( if err := c.caller.Call( ctx, &core.CallParams{ - URL: endpointURL, - Method: http.MethodGet, - MaxAttempts: options.MaxAttempts, - Headers: headers, - Client: options.HTTPClient, - Response: &response, - ErrorDecoder: errorDecoder, + URL: endpointURL, + Method: http.MethodGet, + MaxAttempts: options.MaxAttempts, + Headers: headers, + BodyProperties: options.BodyProperties, + QueryParameters: options.QueryParameters, + Client: options.HTTPClient, + Response: &response, + ErrorDecoder: errorDecoder, }, ); err != nil { return nil, err @@ -1009,13 +1033,15 @@ func (c *Client) CountFeatureUsers( if err := c.caller.Call( ctx, &core.CallParams{ - URL: endpointURL, - Method: http.MethodGet, - MaxAttempts: options.MaxAttempts, - Headers: headers, - Client: options.HTTPClient, - Response: &response, - ErrorDecoder: errorDecoder, + URL: endpointURL, + Method: http.MethodGet, + MaxAttempts: options.MaxAttempts, + Headers: headers, + BodyProperties: options.BodyProperties, + QueryParameters: options.QueryParameters, + Client: options.HTTPClient, + Response: &response, + ErrorDecoder: errorDecoder, }, ); err != nil { return nil, err @@ -1093,13 +1119,15 @@ func (c *Client) ListPlanEntitlements( if err := c.caller.Call( ctx, &core.CallParams{ - URL: endpointURL, - Method: http.MethodGet, - MaxAttempts: options.MaxAttempts, - Headers: headers, - Client: options.HTTPClient, - Response: &response, - ErrorDecoder: errorDecoder, + URL: endpointURL, + Method: http.MethodGet, + MaxAttempts: options.MaxAttempts, + Headers: headers, + BodyProperties: options.BodyProperties, + QueryParameters: options.QueryParameters, + Client: options.HTTPClient, + Response: &response, + ErrorDecoder: errorDecoder, }, ); err != nil { return nil, err @@ -1124,6 +1152,7 @@ func (c *Client) CreatePlanEntitlement( endpointURL := baseURL + "/plan-entitlements" headers := core.MergeHeaders(c.header.Clone(), options.ToHeader()) + headers.Set("Content-Type", "application/json") errorDecoder := func(statusCode int, body io.Reader) error { raw, err := io.ReadAll(body) @@ -1169,14 +1198,16 @@ func (c *Client) CreatePlanEntitlement( if err := c.caller.Call( ctx, &core.CallParams{ - URL: endpointURL, - Method: http.MethodPost, - MaxAttempts: options.MaxAttempts, - Headers: headers, - Client: options.HTTPClient, - Request: request, - Response: &response, - ErrorDecoder: errorDecoder, + URL: endpointURL, + Method: http.MethodPost, + MaxAttempts: options.MaxAttempts, + Headers: headers, + BodyProperties: options.BodyProperties, + QueryParameters: options.QueryParameters, + Client: options.HTTPClient, + Request: request, + Response: &response, + ErrorDecoder: errorDecoder, }, ); err != nil { return nil, err @@ -1247,13 +1278,15 @@ func (c *Client) GetPlanEntitlement( if err := c.caller.Call( ctx, &core.CallParams{ - URL: endpointURL, - Method: http.MethodGet, - MaxAttempts: options.MaxAttempts, - Headers: headers, - Client: options.HTTPClient, - Response: &response, - ErrorDecoder: errorDecoder, + URL: endpointURL, + Method: http.MethodGet, + MaxAttempts: options.MaxAttempts, + Headers: headers, + BodyProperties: options.BodyProperties, + QueryParameters: options.QueryParameters, + Client: options.HTTPClient, + Response: &response, + ErrorDecoder: errorDecoder, }, ); err != nil { return nil, err @@ -1280,6 +1313,7 @@ func (c *Client) UpdatePlanEntitlement( endpointURL := core.EncodeURL(baseURL+"/plan-entitlements/%v", planEntitlementID) headers := core.MergeHeaders(c.header.Clone(), options.ToHeader()) + headers.Set("Content-Type", "application/json") errorDecoder := func(statusCode int, body io.Reader) error { raw, err := io.ReadAll(body) @@ -1332,14 +1366,16 @@ func (c *Client) UpdatePlanEntitlement( if err := c.caller.Call( ctx, &core.CallParams{ - URL: endpointURL, - Method: http.MethodPut, - MaxAttempts: options.MaxAttempts, - Headers: headers, - Client: options.HTTPClient, - Request: request, - Response: &response, - ErrorDecoder: errorDecoder, + URL: endpointURL, + Method: http.MethodPut, + MaxAttempts: options.MaxAttempts, + Headers: headers, + BodyProperties: options.BodyProperties, + QueryParameters: options.QueryParameters, + Client: options.HTTPClient, + Request: request, + Response: &response, + ErrorDecoder: errorDecoder, }, ); err != nil { return nil, err @@ -1410,13 +1446,15 @@ func (c *Client) DeletePlanEntitlement( if err := c.caller.Call( ctx, &core.CallParams{ - URL: endpointURL, - Method: http.MethodDelete, - MaxAttempts: options.MaxAttempts, - Headers: headers, - Client: options.HTTPClient, - Response: &response, - ErrorDecoder: errorDecoder, + URL: endpointURL, + Method: http.MethodDelete, + MaxAttempts: options.MaxAttempts, + Headers: headers, + BodyProperties: options.BodyProperties, + QueryParameters: options.QueryParameters, + Client: options.HTTPClient, + Response: &response, + ErrorDecoder: errorDecoder, }, ); err != nil { return nil, err @@ -1494,13 +1532,15 @@ func (c *Client) CountPlanEntitlements( if err := c.caller.Call( ctx, &core.CallParams{ - URL: endpointURL, - Method: http.MethodGet, - MaxAttempts: options.MaxAttempts, - Headers: headers, - Client: options.HTTPClient, - Response: &response, - ErrorDecoder: errorDecoder, + URL: endpointURL, + Method: http.MethodGet, + MaxAttempts: options.MaxAttempts, + Headers: headers, + BodyProperties: options.BodyProperties, + QueryParameters: options.QueryParameters, + Client: options.HTTPClient, + Response: &response, + ErrorDecoder: errorDecoder, }, ); err != nil { return nil, err @@ -1578,13 +1618,15 @@ func (c *Client) GetFeatureUsageByCompany( if err := c.caller.Call( ctx, &core.CallParams{ - URL: endpointURL, - Method: http.MethodGet, - MaxAttempts: options.MaxAttempts, - Headers: headers, - Client: options.HTTPClient, - Response: &response, - ErrorDecoder: errorDecoder, + URL: endpointURL, + Method: http.MethodGet, + MaxAttempts: options.MaxAttempts, + Headers: headers, + BodyProperties: options.BodyProperties, + QueryParameters: options.QueryParameters, + Client: options.HTTPClient, + Response: &response, + ErrorDecoder: errorDecoder, }, ); err != nil { return nil, err diff --git a/events/client.go b/events/client.go index 99909e0..4a9458d 100644 --- a/events/client.go +++ b/events/client.go @@ -51,6 +51,7 @@ func (c *Client) CreateEventBatch( endpointURL := baseURL + "/event-batch" headers := core.MergeHeaders(c.header.Clone(), options.ToHeader()) + headers.Set("Content-Type", "application/json") errorDecoder := func(statusCode int, body io.Reader) error { raw, err := io.ReadAll(body) @@ -96,14 +97,16 @@ func (c *Client) CreateEventBatch( if err := c.caller.Call( ctx, &core.CallParams{ - URL: endpointURL, - Method: http.MethodPost, - MaxAttempts: options.MaxAttempts, - Headers: headers, - Client: options.HTTPClient, - Request: request, - Response: &response, - ErrorDecoder: errorDecoder, + URL: endpointURL, + Method: http.MethodPost, + MaxAttempts: options.MaxAttempts, + Headers: headers, + BodyProperties: options.BodyProperties, + QueryParameters: options.QueryParameters, + Client: options.HTTPClient, + Request: request, + Response: &response, + ErrorDecoder: errorDecoder, }, ); err != nil { return nil, err @@ -181,13 +184,15 @@ func (c *Client) GetEventSummaries( if err := c.caller.Call( ctx, &core.CallParams{ - URL: endpointURL, - Method: http.MethodGet, - MaxAttempts: options.MaxAttempts, - Headers: headers, - Client: options.HTTPClient, - Response: &response, - ErrorDecoder: errorDecoder, + URL: endpointURL, + Method: http.MethodGet, + MaxAttempts: options.MaxAttempts, + Headers: headers, + BodyProperties: options.BodyProperties, + QueryParameters: options.QueryParameters, + Client: options.HTTPClient, + Response: &response, + ErrorDecoder: errorDecoder, }, ); err != nil { return nil, err @@ -258,13 +263,15 @@ func (c *Client) GetEventSummaryBySubtype( if err := c.caller.Call( ctx, &core.CallParams{ - URL: endpointURL, - Method: http.MethodGet, - MaxAttempts: options.MaxAttempts, - Headers: headers, - Client: options.HTTPClient, - Response: &response, - ErrorDecoder: errorDecoder, + URL: endpointURL, + Method: http.MethodGet, + MaxAttempts: options.MaxAttempts, + Headers: headers, + BodyProperties: options.BodyProperties, + QueryParameters: options.QueryParameters, + Client: options.HTTPClient, + Response: &response, + ErrorDecoder: errorDecoder, }, ); err != nil { return nil, err @@ -342,13 +349,15 @@ func (c *Client) ListEvents( if err := c.caller.Call( ctx, &core.CallParams{ - URL: endpointURL, - Method: http.MethodGet, - MaxAttempts: options.MaxAttempts, - Headers: headers, - Client: options.HTTPClient, - Response: &response, - ErrorDecoder: errorDecoder, + URL: endpointURL, + Method: http.MethodGet, + MaxAttempts: options.MaxAttempts, + Headers: headers, + BodyProperties: options.BodyProperties, + QueryParameters: options.QueryParameters, + Client: options.HTTPClient, + Response: &response, + ErrorDecoder: errorDecoder, }, ); err != nil { return nil, err @@ -373,6 +382,7 @@ func (c *Client) CreateEvent( endpointURL := baseURL + "/events" headers := core.MergeHeaders(c.header.Clone(), options.ToHeader()) + headers.Set("Content-Type", "application/json") errorDecoder := func(statusCode int, body io.Reader) error { raw, err := io.ReadAll(body) @@ -418,14 +428,16 @@ func (c *Client) CreateEvent( if err := c.caller.Call( ctx, &core.CallParams{ - URL: endpointURL, - Method: http.MethodPost, - MaxAttempts: options.MaxAttempts, - Headers: headers, - Client: options.HTTPClient, - Request: request, - Response: &response, - ErrorDecoder: errorDecoder, + URL: endpointURL, + Method: http.MethodPost, + MaxAttempts: options.MaxAttempts, + Headers: headers, + BodyProperties: options.BodyProperties, + QueryParameters: options.QueryParameters, + Client: options.HTTPClient, + Request: request, + Response: &response, + ErrorDecoder: errorDecoder, }, ); err != nil { return nil, err @@ -496,13 +508,15 @@ func (c *Client) GetEvent( if err := c.caller.Call( ctx, &core.CallParams{ - URL: endpointURL, - Method: http.MethodGet, - MaxAttempts: options.MaxAttempts, - Headers: headers, - Client: options.HTTPClient, - Response: &response, - ErrorDecoder: errorDecoder, + URL: endpointURL, + Method: http.MethodGet, + MaxAttempts: options.MaxAttempts, + Headers: headers, + BodyProperties: options.BodyProperties, + QueryParameters: options.QueryParameters, + Client: options.HTTPClient, + Response: &response, + ErrorDecoder: errorDecoder, }, ); err != nil { return nil, err @@ -580,13 +594,15 @@ func (c *Client) ListMetricCounts( if err := c.caller.Call( ctx, &core.CallParams{ - URL: endpointURL, - Method: http.MethodGet, - MaxAttempts: options.MaxAttempts, - Headers: headers, - Client: options.HTTPClient, - Response: &response, - ErrorDecoder: errorDecoder, + URL: endpointURL, + Method: http.MethodGet, + MaxAttempts: options.MaxAttempts, + Headers: headers, + BodyProperties: options.BodyProperties, + QueryParameters: options.QueryParameters, + Client: options.HTTPClient, + Response: &response, + ErrorDecoder: errorDecoder, }, ); err != nil { return nil, err @@ -655,13 +671,15 @@ func (c *Client) GetSegmentIntegrationStatus( if err := c.caller.Call( ctx, &core.CallParams{ - URL: endpointURL, - Method: http.MethodGet, - MaxAttempts: options.MaxAttempts, - Headers: headers, - Client: options.HTTPClient, - Response: &response, - ErrorDecoder: errorDecoder, + URL: endpointURL, + Method: http.MethodGet, + MaxAttempts: options.MaxAttempts, + Headers: headers, + BodyProperties: options.BodyProperties, + QueryParameters: options.QueryParameters, + Client: options.HTTPClient, + Response: &response, + ErrorDecoder: errorDecoder, }, ); err != nil { return nil, err diff --git a/features/client.go b/features/client.go index 218c1df..3ce213a 100644 --- a/features/client.go +++ b/features/client.go @@ -7,12 +7,11 @@ import ( context "context" json "encoding/json" errors "errors" - io "io" - http "net/http" - schematicgo "github.com/schematichq/schematic-go" core "github.com/schematichq/schematic-go/core" option "github.com/schematichq/schematic-go/option" + io "io" + http "net/http" ) type Client struct { @@ -52,6 +51,7 @@ func (c *Client) CountAudienceCompanies( endpointURL := baseURL + "/audience/count-companies" headers := core.MergeHeaders(c.header.Clone(), options.ToHeader()) + headers.Set("Content-Type", "application/json") errorDecoder := func(statusCode int, body io.Reader) error { raw, err := io.ReadAll(body) @@ -97,14 +97,16 @@ func (c *Client) CountAudienceCompanies( if err := c.caller.Call( ctx, &core.CallParams{ - URL: endpointURL, - Method: http.MethodPost, - MaxAttempts: options.MaxAttempts, - Headers: headers, - Client: options.HTTPClient, - Request: request, - Response: &response, - ErrorDecoder: errorDecoder, + URL: endpointURL, + Method: http.MethodPost, + MaxAttempts: options.MaxAttempts, + Headers: headers, + BodyProperties: options.BodyProperties, + QueryParameters: options.QueryParameters, + Client: options.HTTPClient, + Request: request, + Response: &response, + ErrorDecoder: errorDecoder, }, ); err != nil { return nil, err @@ -129,6 +131,7 @@ func (c *Client) CountAudienceUsers( endpointURL := baseURL + "/audience/count-users" headers := core.MergeHeaders(c.header.Clone(), options.ToHeader()) + headers.Set("Content-Type", "application/json") errorDecoder := func(statusCode int, body io.Reader) error { raw, err := io.ReadAll(body) @@ -174,14 +177,16 @@ func (c *Client) CountAudienceUsers( if err := c.caller.Call( ctx, &core.CallParams{ - URL: endpointURL, - Method: http.MethodPost, - MaxAttempts: options.MaxAttempts, - Headers: headers, - Client: options.HTTPClient, - Request: request, - Response: &response, - ErrorDecoder: errorDecoder, + URL: endpointURL, + Method: http.MethodPost, + MaxAttempts: options.MaxAttempts, + Headers: headers, + BodyProperties: options.BodyProperties, + QueryParameters: options.QueryParameters, + Client: options.HTTPClient, + Request: request, + Response: &response, + ErrorDecoder: errorDecoder, }, ); err != nil { return nil, err @@ -206,6 +211,7 @@ func (c *Client) ListAudienceCompanies( endpointURL := baseURL + "/audience/get-companies" headers := core.MergeHeaders(c.header.Clone(), options.ToHeader()) + headers.Set("Content-Type", "application/json") errorDecoder := func(statusCode int, body io.Reader) error { raw, err := io.ReadAll(body) @@ -251,14 +257,16 @@ func (c *Client) ListAudienceCompanies( if err := c.caller.Call( ctx, &core.CallParams{ - URL: endpointURL, - Method: http.MethodPost, - MaxAttempts: options.MaxAttempts, - Headers: headers, - Client: options.HTTPClient, - Request: request, - Response: &response, - ErrorDecoder: errorDecoder, + URL: endpointURL, + Method: http.MethodPost, + MaxAttempts: options.MaxAttempts, + Headers: headers, + BodyProperties: options.BodyProperties, + QueryParameters: options.QueryParameters, + Client: options.HTTPClient, + Request: request, + Response: &response, + ErrorDecoder: errorDecoder, }, ); err != nil { return nil, err @@ -283,6 +291,7 @@ func (c *Client) ListAudienceUsers( endpointURL := baseURL + "/audience/get-users" headers := core.MergeHeaders(c.header.Clone(), options.ToHeader()) + headers.Set("Content-Type", "application/json") errorDecoder := func(statusCode int, body io.Reader) error { raw, err := io.ReadAll(body) @@ -328,14 +337,16 @@ func (c *Client) ListAudienceUsers( if err := c.caller.Call( ctx, &core.CallParams{ - URL: endpointURL, - Method: http.MethodPost, - MaxAttempts: options.MaxAttempts, - Headers: headers, - Client: options.HTTPClient, - Request: request, - Response: &response, - ErrorDecoder: errorDecoder, + URL: endpointURL, + Method: http.MethodPost, + MaxAttempts: options.MaxAttempts, + Headers: headers, + BodyProperties: options.BodyProperties, + QueryParameters: options.QueryParameters, + Client: options.HTTPClient, + Request: request, + Response: &response, + ErrorDecoder: errorDecoder, }, ); err != nil { return nil, err @@ -413,13 +424,15 @@ func (c *Client) ListFeatures( if err := c.caller.Call( ctx, &core.CallParams{ - URL: endpointURL, - Method: http.MethodGet, - MaxAttempts: options.MaxAttempts, - Headers: headers, - Client: options.HTTPClient, - Response: &response, - ErrorDecoder: errorDecoder, + URL: endpointURL, + Method: http.MethodGet, + MaxAttempts: options.MaxAttempts, + Headers: headers, + BodyProperties: options.BodyProperties, + QueryParameters: options.QueryParameters, + Client: options.HTTPClient, + Response: &response, + ErrorDecoder: errorDecoder, }, ); err != nil { return nil, err @@ -444,6 +457,7 @@ func (c *Client) CreateFeature( endpointURL := baseURL + "/features" headers := core.MergeHeaders(c.header.Clone(), options.ToHeader()) + headers.Set("Content-Type", "application/json") errorDecoder := func(statusCode int, body io.Reader) error { raw, err := io.ReadAll(body) @@ -489,14 +503,16 @@ func (c *Client) CreateFeature( if err := c.caller.Call( ctx, &core.CallParams{ - URL: endpointURL, - Method: http.MethodPost, - MaxAttempts: options.MaxAttempts, - Headers: headers, - Client: options.HTTPClient, - Request: request, - Response: &response, - ErrorDecoder: errorDecoder, + URL: endpointURL, + Method: http.MethodPost, + MaxAttempts: options.MaxAttempts, + Headers: headers, + BodyProperties: options.BodyProperties, + QueryParameters: options.QueryParameters, + Client: options.HTTPClient, + Request: request, + Response: &response, + ErrorDecoder: errorDecoder, }, ); err != nil { return nil, err @@ -567,13 +583,15 @@ func (c *Client) GetFeature( if err := c.caller.Call( ctx, &core.CallParams{ - URL: endpointURL, - Method: http.MethodGet, - MaxAttempts: options.MaxAttempts, - Headers: headers, - Client: options.HTTPClient, - Response: &response, - ErrorDecoder: errorDecoder, + URL: endpointURL, + Method: http.MethodGet, + MaxAttempts: options.MaxAttempts, + Headers: headers, + BodyProperties: options.BodyProperties, + QueryParameters: options.QueryParameters, + Client: options.HTTPClient, + Response: &response, + ErrorDecoder: errorDecoder, }, ); err != nil { return nil, err @@ -600,6 +618,7 @@ func (c *Client) UpdateFeature( endpointURL := core.EncodeURL(baseURL+"/features/%v", featureID) headers := core.MergeHeaders(c.header.Clone(), options.ToHeader()) + headers.Set("Content-Type", "application/json") errorDecoder := func(statusCode int, body io.Reader) error { raw, err := io.ReadAll(body) @@ -652,14 +671,16 @@ func (c *Client) UpdateFeature( if err := c.caller.Call( ctx, &core.CallParams{ - URL: endpointURL, - Method: http.MethodPut, - MaxAttempts: options.MaxAttempts, - Headers: headers, - Client: options.HTTPClient, - Request: request, - Response: &response, - ErrorDecoder: errorDecoder, + URL: endpointURL, + Method: http.MethodPut, + MaxAttempts: options.MaxAttempts, + Headers: headers, + BodyProperties: options.BodyProperties, + QueryParameters: options.QueryParameters, + Client: options.HTTPClient, + Request: request, + Response: &response, + ErrorDecoder: errorDecoder, }, ); err != nil { return nil, err @@ -730,13 +751,15 @@ func (c *Client) DeleteFeature( if err := c.caller.Call( ctx, &core.CallParams{ - URL: endpointURL, - Method: http.MethodDelete, - MaxAttempts: options.MaxAttempts, - Headers: headers, - Client: options.HTTPClient, - Response: &response, - ErrorDecoder: errorDecoder, + URL: endpointURL, + Method: http.MethodDelete, + MaxAttempts: options.MaxAttempts, + Headers: headers, + BodyProperties: options.BodyProperties, + QueryParameters: options.QueryParameters, + Client: options.HTTPClient, + Response: &response, + ErrorDecoder: errorDecoder, }, ); err != nil { return nil, err @@ -814,13 +837,15 @@ func (c *Client) CountFeatures( if err := c.caller.Call( ctx, &core.CallParams{ - URL: endpointURL, - Method: http.MethodGet, - MaxAttempts: options.MaxAttempts, - Headers: headers, - Client: options.HTTPClient, - Response: &response, - ErrorDecoder: errorDecoder, + URL: endpointURL, + Method: http.MethodGet, + MaxAttempts: options.MaxAttempts, + Headers: headers, + BodyProperties: options.BodyProperties, + QueryParameters: options.QueryParameters, + Client: options.HTTPClient, + Response: &response, + ErrorDecoder: errorDecoder, }, ); err != nil { return nil, err @@ -898,13 +923,15 @@ func (c *Client) ListFlags( if err := c.caller.Call( ctx, &core.CallParams{ - URL: endpointURL, - Method: http.MethodGet, - MaxAttempts: options.MaxAttempts, - Headers: headers, - Client: options.HTTPClient, - Response: &response, - ErrorDecoder: errorDecoder, + URL: endpointURL, + Method: http.MethodGet, + MaxAttempts: options.MaxAttempts, + Headers: headers, + BodyProperties: options.BodyProperties, + QueryParameters: options.QueryParameters, + Client: options.HTTPClient, + Response: &response, + ErrorDecoder: errorDecoder, }, ); err != nil { return nil, err @@ -929,6 +956,7 @@ func (c *Client) CreateFlag( endpointURL := baseURL + "/flags" headers := core.MergeHeaders(c.header.Clone(), options.ToHeader()) + headers.Set("Content-Type", "application/json") errorDecoder := func(statusCode int, body io.Reader) error { raw, err := io.ReadAll(body) @@ -974,14 +1002,16 @@ func (c *Client) CreateFlag( if err := c.caller.Call( ctx, &core.CallParams{ - URL: endpointURL, - Method: http.MethodPost, - MaxAttempts: options.MaxAttempts, - Headers: headers, - Client: options.HTTPClient, - Request: request, - Response: &response, - ErrorDecoder: errorDecoder, + URL: endpointURL, + Method: http.MethodPost, + MaxAttempts: options.MaxAttempts, + Headers: headers, + BodyProperties: options.BodyProperties, + QueryParameters: options.QueryParameters, + Client: options.HTTPClient, + Request: request, + Response: &response, + ErrorDecoder: errorDecoder, }, ); err != nil { return nil, err @@ -1052,13 +1082,15 @@ func (c *Client) GetFlag( if err := c.caller.Call( ctx, &core.CallParams{ - URL: endpointURL, - Method: http.MethodGet, - MaxAttempts: options.MaxAttempts, - Headers: headers, - Client: options.HTTPClient, - Response: &response, - ErrorDecoder: errorDecoder, + URL: endpointURL, + Method: http.MethodGet, + MaxAttempts: options.MaxAttempts, + Headers: headers, + BodyProperties: options.BodyProperties, + QueryParameters: options.QueryParameters, + Client: options.HTTPClient, + Response: &response, + ErrorDecoder: errorDecoder, }, ); err != nil { return nil, err @@ -1085,6 +1117,7 @@ func (c *Client) UpdateFlag( endpointURL := core.EncodeURL(baseURL+"/flags/%v", flagID) headers := core.MergeHeaders(c.header.Clone(), options.ToHeader()) + headers.Set("Content-Type", "application/json") errorDecoder := func(statusCode int, body io.Reader) error { raw, err := io.ReadAll(body) @@ -1137,14 +1170,16 @@ func (c *Client) UpdateFlag( if err := c.caller.Call( ctx, &core.CallParams{ - URL: endpointURL, - Method: http.MethodPut, - MaxAttempts: options.MaxAttempts, - Headers: headers, - Client: options.HTTPClient, - Request: request, - Response: &response, - ErrorDecoder: errorDecoder, + URL: endpointURL, + Method: http.MethodPut, + MaxAttempts: options.MaxAttempts, + Headers: headers, + BodyProperties: options.BodyProperties, + QueryParameters: options.QueryParameters, + Client: options.HTTPClient, + Request: request, + Response: &response, + ErrorDecoder: errorDecoder, }, ); err != nil { return nil, err @@ -1215,13 +1250,15 @@ func (c *Client) DeleteFlag( if err := c.caller.Call( ctx, &core.CallParams{ - URL: endpointURL, - Method: http.MethodDelete, - MaxAttempts: options.MaxAttempts, - Headers: headers, - Client: options.HTTPClient, - Response: &response, - ErrorDecoder: errorDecoder, + URL: endpointURL, + Method: http.MethodDelete, + MaxAttempts: options.MaxAttempts, + Headers: headers, + BodyProperties: options.BodyProperties, + QueryParameters: options.QueryParameters, + Client: options.HTTPClient, + Response: &response, + ErrorDecoder: errorDecoder, }, ); err != nil { return nil, err @@ -1248,6 +1285,7 @@ func (c *Client) UpdateFlagRules( endpointURL := core.EncodeURL(baseURL+"/flags/%v/rules", flagID) headers := core.MergeHeaders(c.header.Clone(), options.ToHeader()) + headers.Set("Content-Type", "application/json") errorDecoder := func(statusCode int, body io.Reader) error { raw, err := io.ReadAll(body) @@ -1300,14 +1338,16 @@ func (c *Client) UpdateFlagRules( if err := c.caller.Call( ctx, &core.CallParams{ - URL: endpointURL, - Method: http.MethodPut, - MaxAttempts: options.MaxAttempts, - Headers: headers, - Client: options.HTTPClient, - Request: request, - Response: &response, - ErrorDecoder: errorDecoder, + URL: endpointURL, + Method: http.MethodPut, + MaxAttempts: options.MaxAttempts, + Headers: headers, + BodyProperties: options.BodyProperties, + QueryParameters: options.QueryParameters, + Client: options.HTTPClient, + Request: request, + Response: &response, + ErrorDecoder: errorDecoder, }, ); err != nil { return nil, err @@ -1334,6 +1374,7 @@ func (c *Client) CheckFlag( endpointURL := core.EncodeURL(baseURL+"/flags/%v/check", key) headers := core.MergeHeaders(c.header.Clone(), options.ToHeader()) + headers.Set("Content-Type", "application/json") errorDecoder := func(statusCode int, body io.Reader) error { raw, err := io.ReadAll(body) @@ -1379,14 +1420,16 @@ func (c *Client) CheckFlag( if err := c.caller.Call( ctx, &core.CallParams{ - URL: endpointURL, - Method: http.MethodPost, - MaxAttempts: options.MaxAttempts, - Headers: headers, - Client: options.HTTPClient, - Request: request, - Response: &response, - ErrorDecoder: errorDecoder, + URL: endpointURL, + Method: http.MethodPost, + MaxAttempts: options.MaxAttempts, + Headers: headers, + BodyProperties: options.BodyProperties, + QueryParameters: options.QueryParameters, + Client: options.HTTPClient, + Request: request, + Response: &response, + ErrorDecoder: errorDecoder, }, ); err != nil { return nil, err @@ -1411,6 +1454,7 @@ func (c *Client) CheckFlags( endpointURL := baseURL + "/flags/check" headers := core.MergeHeaders(c.header.Clone(), options.ToHeader()) + headers.Set("Content-Type", "application/json") errorDecoder := func(statusCode int, body io.Reader) error { raw, err := io.ReadAll(body) @@ -1456,14 +1500,16 @@ func (c *Client) CheckFlags( if err := c.caller.Call( ctx, &core.CallParams{ - URL: endpointURL, - Method: http.MethodPost, - MaxAttempts: options.MaxAttempts, - Headers: headers, - Client: options.HTTPClient, - Request: request, - Response: &response, - ErrorDecoder: errorDecoder, + URL: endpointURL, + Method: http.MethodPost, + MaxAttempts: options.MaxAttempts, + Headers: headers, + BodyProperties: options.BodyProperties, + QueryParameters: options.QueryParameters, + Client: options.HTTPClient, + Request: request, + Response: &response, + ErrorDecoder: errorDecoder, }, ); err != nil { return nil, err @@ -1541,13 +1587,15 @@ func (c *Client) CountFlags( if err := c.caller.Call( ctx, &core.CallParams{ - URL: endpointURL, - Method: http.MethodGet, - MaxAttempts: options.MaxAttempts, - Headers: headers, - Client: options.HTTPClient, - Response: &response, - ErrorDecoder: errorDecoder, + URL: endpointURL, + Method: http.MethodGet, + MaxAttempts: options.MaxAttempts, + Headers: headers, + BodyProperties: options.BodyProperties, + QueryParameters: options.QueryParameters, + Client: options.HTTPClient, + Response: &response, + ErrorDecoder: errorDecoder, }, ); err != nil { return nil, err diff --git a/flags/flags.go b/flags/flags.go deleted file mode 100644 index 157c4cb..0000000 --- a/flags/flags.go +++ /dev/null @@ -1,35 +0,0 @@ -package flags - -import ( - "fmt" - "sort" - "strings" - - schematicgo "github.com/schematichq/schematic-go" -) - -// TODO: Use separators that are not valid characters in key values -func FlagCheckCacheKey(evalCtx *schematicgo.CheckFlagRequestBody, flagKey string) string { - var sb strings.Builder - sb.WriteString(fmt.Sprintf("f:%s;", flagKey)) - - companyKeys := make([]string, 0, len(evalCtx.Company)) - for k := range evalCtx.Company { - companyKeys = append(companyKeys, k) - } - sort.Strings(companyKeys) - for _, k := range companyKeys { - sb.WriteString(fmt.Sprintf("c:%s:%s;", k, *evalCtx.Company[k])) - } - - userKeys := make([]string, 0, len(evalCtx.User)) - for k := range evalCtx.User { - userKeys = append(userKeys, k) - } - sort.Strings(userKeys) - for _, k := range userKeys { - sb.WriteString(fmt.Sprintf("u:%s:%s;", k, *evalCtx.User[k])) - } - - return strings.TrimRight(sb.String(), ";") -} diff --git a/flags/flags_test.go b/flags/flags_test.go deleted file mode 100644 index 8605545..0000000 --- a/flags/flags_test.go +++ /dev/null @@ -1,85 +0,0 @@ -package flags - -import ( - "testing" - - schematicgo "github.com/schematichq/schematic-go" -) - -func TestFlagCheckCacheKey(t *testing.T) { - id1 := "123" - acme := "ACME Inc." - - id2 := "456" - emailJohn := "john@example.com" - - id3 := "789" - xyz := "XYZ Corp." - - id4 := "abc" - emailJane := "jane@example.com" - tests := []struct { - name string - evalCtx *schematicgo.CheckFlagRequestBody - flagKey string - expected string - }{ - { - name: "Empty context and flag key", - evalCtx: &schematicgo.CheckFlagRequestBody{ - Company: map[string]*string{}, - User: map[string]*string{}, - }, - flagKey: "", - expected: "f:", - }, - { - name: "Context with company and user data", - evalCtx: &schematicgo.CheckFlagRequestBody{ - Company: map[string]*string{ - "id": &id1, - "name": &acme, - }, - User: map[string]*string{ - "id": &id2, - "email": &emailJohn, - }, - }, - flagKey: "feature_flag_1", - expected: "f:feature_flag_1;c:id:123;c:name:ACME Inc.;u:email:john@example.com;u:id:456", - }, - { - name: "Context with only company data", - evalCtx: &schematicgo.CheckFlagRequestBody{ - Company: map[string]*string{ - "id": &id3, - "name": &xyz, - }, - User: map[string]*string{}, - }, - flagKey: "feature_flag_2", - expected: "f:feature_flag_2;c:id:789;c:name:XYZ Corp.", - }, - { - name: "Context with only user data", - evalCtx: &schematicgo.CheckFlagRequestBody{ - Company: map[string]*string{}, - User: map[string]*string{ - "id": &id4, - "email": &emailJane, - }, - }, - flagKey: "feature_flag_3", - expected: "f:feature_flag_3;u:email:jane@example.com;u:id:abc", - }, - } - - for _, tt := range tests { - t.Run(tt.name, func(t *testing.T) { - result := FlagCheckCacheKey(tt.evalCtx, tt.flagKey) - if result != tt.expected { - t.Errorf("flagCheckCacheKey() = %v, want %v", result, tt.expected) - } - }) - } -} diff --git a/go.mod b/go.mod index 1ef31a8..7db5ded 100644 --- a/go.mod +++ b/go.mod @@ -3,13 +3,12 @@ module github.com/schematichq/schematic-go go 1.18 require ( - github.com/golang/mock v1.6.0 github.com/google/uuid v1.4.0 - github.com/stretchr/testify v1.9.0 + github.com/stretchr/testify v1.7.0 ) require ( - github.com/davecgh/go-spew v1.1.1 // indirect + github.com/davecgh/go-spew v1.1.0 // indirect github.com/pmezard/go-difflib v1.0.0 // indirect gopkg.in/yaml.v3 v3.0.1 // indirect ) diff --git a/go.sum b/go.sum index 4fa514a..b3766d4 100644 --- a/go.sum +++ b/go.sum @@ -1,37 +1,14 @@ -github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= -github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= -github.com/golang/mock v1.6.0 h1:ErTB+efbowRARo13NNdxyJji2egdxLGQhRaY+DUumQc= -github.com/golang/mock v1.6.0/go.mod h1:p6yTPP+5HYm5mzsMV8JkE6ZKdX+/wYM6Hr+LicevLPs= +github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8= +github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/google/uuid v1.4.0 h1:MtMxsa51/r9yyhkyLsVeVt0B+BGQZzpQiTQ4eHZ8bc4= github.com/google/uuid v1.4.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= -github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg= -github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= -github.com/yuin/goldmark v1.3.5/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k= -golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= -golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= -golang.org/x/mod v0.4.2/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= -golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= -golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= -golang.org/x/net v0.0.0-20210405180319-a5a99cb37ef4/go.mod h1:p54w0d4576C0XHj96bSt6lcn1PtDYWL6XObtHCRCNQM= -golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sync v0.0.0-20210220032951-036812b2e83c/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= -golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20210330210617-4fbd30eecc44/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20210510120138-977fb7262007/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= -golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= -golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= -golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= -golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= -golang.org/x/tools v0.1.1/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk= -golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= -golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= -golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= +github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= +github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY= +github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= diff --git a/http/offline.go b/http/offline.go deleted file mode 100644 index a07e5c8..0000000 --- a/http/offline.go +++ /dev/null @@ -1,18 +0,0 @@ -package http - -import ( - "io" - gohttp "net/http" - "strings" -) - -type NoopClient struct{} - -func (c NoopClient) Do(*gohttp.Request) (*gohttp.Response, error) { - - return &gohttp.Response{ - Status: "200", - StatusCode: 200, - Body: io.NopCloser(strings.NewReader("")), - }, nil -} diff --git a/logger/logger.go b/logger/logger.go deleted file mode 100644 index 11de68d..0000000 --- a/logger/logger.go +++ /dev/null @@ -1,20 +0,0 @@ -package logger - -import ( - "log" - "os" - - schematicgo "github.com/schematichq/schematic-go" -) - -type defaultLogger struct { - logger *log.Logger -} - -func (l defaultLogger) Printf(format string, args ...interface{}) { - l.logger.Printf(format, args...) -} - -func NewDefaultLogger() schematicgo.Logger { - return defaultLogger{logger: log.New(os.Stderr, "schematic ", log.LstdFlags)} -} diff --git a/mocks/http_mock.go b/mocks/http_mock.go deleted file mode 100644 index 9502780..0000000 --- a/mocks/http_mock.go +++ /dev/null @@ -1,50 +0,0 @@ -// Code generated by MockGen. DO NOT EDIT. -// Source: core/core.go - -// Package mocks is a generated GoMock package. -package mocks - -import ( - http "net/http" - reflect "reflect" - - gomock "github.com/golang/mock/gomock" -) - -// MockHTTPClient is a mock of HTTPClient interface. -type MockHTTPClient struct { - ctrl *gomock.Controller - recorder *MockHTTPClientMockRecorder -} - -// MockHTTPClientMockRecorder is the mock recorder for MockHTTPClient. -type MockHTTPClientMockRecorder struct { - mock *MockHTTPClient -} - -// NewMockHTTPClient creates a new mock instance. -func NewMockHTTPClient(ctrl *gomock.Controller) *MockHTTPClient { - mock := &MockHTTPClient{ctrl: ctrl} - mock.recorder = &MockHTTPClientMockRecorder{mock} - return mock -} - -// EXPECT returns an object that allows the caller to indicate expected use. -func (m *MockHTTPClient) EXPECT() *MockHTTPClientMockRecorder { - return m.recorder -} - -// Do mocks base method. -func (m *MockHTTPClient) Do(arg0 *http.Request) (*http.Response, error) { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "Do", arg0) - ret0, _ := ret[0].(*http.Response) - ret1, _ := ret[1].(error) - return ret0, ret1 -} - -// Do indicates an expected call of Do. -func (mr *MockHTTPClientMockRecorder) Do(arg0 interface{}) *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Do", reflect.TypeOf((*MockHTTPClient)(nil).Do), arg0) -} diff --git a/option/request_option.go b/option/request_option.go index 0d5014a..e204e3a 100644 --- a/option/request_option.go +++ b/option/request_option.go @@ -5,6 +5,7 @@ package option import ( core "github.com/schematichq/schematic-go/core" http "net/http" + url "net/url" ) // RequestOption adapts the behavior of an indivdual request. @@ -33,6 +34,28 @@ func WithHTTPHeader(httpHeader http.Header) *core.HTTPHeaderOption { } } +// WithBodyProperties adds the given body properties to the request. +func WithBodyProperties(bodyProperties map[string]interface{}) *core.BodyPropertiesOption { + copiedBodyProperties := make(map[string]interface{}, len(bodyProperties)) + for key, value := range bodyProperties { + copiedBodyProperties[key] = value + } + return &core.BodyPropertiesOption{ + BodyProperties: copiedBodyProperties, + } +} + +// WithQueryParameters adds the given query parameters to the request. +func WithQueryParameters(queryParameters url.Values) *core.QueryParametersOption { + copiedQueryParameters := make(url.Values, len(queryParameters)) + for key, values := range queryParameters { + copiedQueryParameters[key] = values + } + return &core.QueryParametersOption{ + QueryParameters: copiedQueryParameters, + } +} + // WithMaxAttempts configures the maximum number of retry attempts. func WithMaxAttempts(attempts uint) *core.MaxAttemptsOption { return &core.MaxAttemptsOption{ diff --git a/plangroups.go b/plangroups.go index 379a4e3..8611058 100644 --- a/plangroups.go +++ b/plangroups.go @@ -9,6 +9,7 @@ import ( ) type CreatePlanGroupRequestBody struct { + AddOnIDs []string `json:"add_on_ids,omitempty" url:"-"` DefaultPlanID *string `json:"default_plan_id,omitempty" url:"-"` PlanIDs []string `json:"plan_ids,omitempty" url:"-"` } @@ -143,6 +144,7 @@ func (u *UpdatePlanGroupResponse) String() string { } type UpdatePlanGroupRequestBody struct { + AddOnIDs []string `json:"add_on_ids,omitempty" url:"-"` DefaultPlanID *string `json:"default_plan_id,omitempty" url:"-"` PlanIDs []string `json:"plan_ids,omitempty" url:"-"` } diff --git a/plangroups/client.go b/plangroups/client.go index 4fd71ca..41cac39 100644 --- a/plangroups/client.go +++ b/plangroups/client.go @@ -95,13 +95,15 @@ func (c *Client) GetPlanGroup( if err := c.caller.Call( ctx, &core.CallParams{ - URL: endpointURL, - Method: http.MethodGet, - MaxAttempts: options.MaxAttempts, - Headers: headers, - Client: options.HTTPClient, - Response: &response, - ErrorDecoder: errorDecoder, + URL: endpointURL, + Method: http.MethodGet, + MaxAttempts: options.MaxAttempts, + Headers: headers, + BodyProperties: options.BodyProperties, + QueryParameters: options.QueryParameters, + Client: options.HTTPClient, + Response: &response, + ErrorDecoder: errorDecoder, }, ); err != nil { return nil, err @@ -126,6 +128,7 @@ func (c *Client) CreatePlanGroup( endpointURL := baseURL + "/plan-groups" headers := core.MergeHeaders(c.header.Clone(), options.ToHeader()) + headers.Set("Content-Type", "application/json") errorDecoder := func(statusCode int, body io.Reader) error { raw, err := io.ReadAll(body) @@ -171,14 +174,16 @@ func (c *Client) CreatePlanGroup( if err := c.caller.Call( ctx, &core.CallParams{ - URL: endpointURL, - Method: http.MethodPost, - MaxAttempts: options.MaxAttempts, - Headers: headers, - Client: options.HTTPClient, - Request: request, - Response: &response, - ErrorDecoder: errorDecoder, + URL: endpointURL, + Method: http.MethodPost, + MaxAttempts: options.MaxAttempts, + Headers: headers, + BodyProperties: options.BodyProperties, + QueryParameters: options.QueryParameters, + Client: options.HTTPClient, + Request: request, + Response: &response, + ErrorDecoder: errorDecoder, }, ); err != nil { return nil, err @@ -205,6 +210,7 @@ func (c *Client) UpdatePlanGroup( endpointURL := core.EncodeURL(baseURL+"/plan-groups/%v", planGroupID) headers := core.MergeHeaders(c.header.Clone(), options.ToHeader()) + headers.Set("Content-Type", "application/json") errorDecoder := func(statusCode int, body io.Reader) error { raw, err := io.ReadAll(body) @@ -257,14 +263,16 @@ func (c *Client) UpdatePlanGroup( if err := c.caller.Call( ctx, &core.CallParams{ - URL: endpointURL, - Method: http.MethodPut, - MaxAttempts: options.MaxAttempts, - Headers: headers, - Client: options.HTTPClient, - Request: request, - Response: &response, - ErrorDecoder: errorDecoder, + URL: endpointURL, + Method: http.MethodPut, + MaxAttempts: options.MaxAttempts, + Headers: headers, + BodyProperties: options.BodyProperties, + QueryParameters: options.QueryParameters, + Client: options.HTTPClient, + Request: request, + Response: &response, + ErrorDecoder: errorDecoder, }, ); err != nil { return nil, err diff --git a/plans.go b/plans.go index 4dedf4f..67da522 100644 --- a/plans.go +++ b/plans.go @@ -9,15 +9,17 @@ import ( ) type CountPlansRequest struct { - CompanyID *string `json:"-" url:"company_id,omitempty"` - IDs []*string `json:"-" url:"ids,omitempty"` - Q *string `json:"-" url:"q,omitempty"` + CompanyID *string `json:"-" url:"company_id,omitempty"` + // Filter out plans that do not have a billing product ID + HasProductID *bool `json:"-" url:"has_product_id,omitempty"` + IDs []*string `json:"-" url:"ids,omitempty"` // Filter by plan type PlanType *CountPlansRequestPlanType `json:"-" url:"plan_type,omitempty"` - // Filter out plans that do not have a billing product ID - HasProductID *bool `json:"-" url:"has_product_id,omitempty"` + Q *string `json:"-" url:"q,omitempty"` // Filter out plans that already have a plan entitlement for the specified feature ID WithoutEntitlementFor *string `json:"-" url:"without_entitlement_for,omitempty"` + // Filter out plans that have a billing product ID + WithoutProductID *bool `json:"-" url:"without_product_id,omitempty"` // Page limit (default 100) Limit *int `json:"-" url:"limit,omitempty"` // Page offset (default 0) @@ -32,15 +34,17 @@ type CreatePlanRequestBody struct { } type ListPlansRequest struct { - CompanyID *string `json:"-" url:"company_id,omitempty"` - IDs []*string `json:"-" url:"ids,omitempty"` - Q *string `json:"-" url:"q,omitempty"` + CompanyID *string `json:"-" url:"company_id,omitempty"` + // Filter out plans that do not have a billing product ID + HasProductID *bool `json:"-" url:"has_product_id,omitempty"` + IDs []*string `json:"-" url:"ids,omitempty"` // Filter by plan type PlanType *ListPlansRequestPlanType `json:"-" url:"plan_type,omitempty"` - // Filter out plans that do not have a billing product ID - HasProductID *bool `json:"-" url:"has_product_id,omitempty"` + Q *string `json:"-" url:"q,omitempty"` // Filter out plans that already have a plan entitlement for the specified feature ID WithoutEntitlementFor *string `json:"-" url:"without_entitlement_for,omitempty"` + // Filter out plans that have a billing product ID + WithoutProductID *bool `json:"-" url:"without_product_id,omitempty"` // Page limit (default 100) Limit *int `json:"-" url:"limit,omitempty"` // Page offset (default 0) diff --git a/plans/client.go b/plans/client.go index 0403150..b3df681 100644 --- a/plans/client.go +++ b/plans/client.go @@ -97,13 +97,15 @@ func (c *Client) GetAudience( if err := c.caller.Call( ctx, &core.CallParams{ - URL: endpointURL, - Method: http.MethodGet, - MaxAttempts: options.MaxAttempts, - Headers: headers, - Client: options.HTTPClient, - Response: &response, - ErrorDecoder: errorDecoder, + URL: endpointURL, + Method: http.MethodGet, + MaxAttempts: options.MaxAttempts, + Headers: headers, + BodyProperties: options.BodyProperties, + QueryParameters: options.QueryParameters, + Client: options.HTTPClient, + Response: &response, + ErrorDecoder: errorDecoder, }, ); err != nil { return nil, err @@ -130,6 +132,7 @@ func (c *Client) UpdateAudience( endpointURL := core.EncodeURL(baseURL+"/plan-audiences/%v", planAudienceID) headers := core.MergeHeaders(c.header.Clone(), options.ToHeader()) + headers.Set("Content-Type", "application/json") errorDecoder := func(statusCode int, body io.Reader) error { raw, err := io.ReadAll(body) @@ -182,14 +185,16 @@ func (c *Client) UpdateAudience( if err := c.caller.Call( ctx, &core.CallParams{ - URL: endpointURL, - Method: http.MethodPut, - MaxAttempts: options.MaxAttempts, - Headers: headers, - Client: options.HTTPClient, - Request: request, - Response: &response, - ErrorDecoder: errorDecoder, + URL: endpointURL, + Method: http.MethodPut, + MaxAttempts: options.MaxAttempts, + Headers: headers, + BodyProperties: options.BodyProperties, + QueryParameters: options.QueryParameters, + Client: options.HTTPClient, + Request: request, + Response: &response, + ErrorDecoder: errorDecoder, }, ); err != nil { return nil, err @@ -260,13 +265,15 @@ func (c *Client) DeleteAudience( if err := c.caller.Call( ctx, &core.CallParams{ - URL: endpointURL, - Method: http.MethodDelete, - MaxAttempts: options.MaxAttempts, - Headers: headers, - Client: options.HTTPClient, - Response: &response, - ErrorDecoder: errorDecoder, + URL: endpointURL, + Method: http.MethodDelete, + MaxAttempts: options.MaxAttempts, + Headers: headers, + BodyProperties: options.BodyProperties, + QueryParameters: options.QueryParameters, + Client: options.HTTPClient, + Response: &response, + ErrorDecoder: errorDecoder, }, ); err != nil { return nil, err @@ -344,13 +351,15 @@ func (c *Client) ListPlans( if err := c.caller.Call( ctx, &core.CallParams{ - URL: endpointURL, - Method: http.MethodGet, - MaxAttempts: options.MaxAttempts, - Headers: headers, - Client: options.HTTPClient, - Response: &response, - ErrorDecoder: errorDecoder, + URL: endpointURL, + Method: http.MethodGet, + MaxAttempts: options.MaxAttempts, + Headers: headers, + BodyProperties: options.BodyProperties, + QueryParameters: options.QueryParameters, + Client: options.HTTPClient, + Response: &response, + ErrorDecoder: errorDecoder, }, ); err != nil { return nil, err @@ -375,6 +384,7 @@ func (c *Client) CreatePlan( endpointURL := baseURL + "/plans" headers := core.MergeHeaders(c.header.Clone(), options.ToHeader()) + headers.Set("Content-Type", "application/json") errorDecoder := func(statusCode int, body io.Reader) error { raw, err := io.ReadAll(body) @@ -420,14 +430,16 @@ func (c *Client) CreatePlan( if err := c.caller.Call( ctx, &core.CallParams{ - URL: endpointURL, - Method: http.MethodPost, - MaxAttempts: options.MaxAttempts, - Headers: headers, - Client: options.HTTPClient, - Request: request, - Response: &response, - ErrorDecoder: errorDecoder, + URL: endpointURL, + Method: http.MethodPost, + MaxAttempts: options.MaxAttempts, + Headers: headers, + BodyProperties: options.BodyProperties, + QueryParameters: options.QueryParameters, + Client: options.HTTPClient, + Request: request, + Response: &response, + ErrorDecoder: errorDecoder, }, ); err != nil { return nil, err @@ -498,13 +510,15 @@ func (c *Client) GetPlan( if err := c.caller.Call( ctx, &core.CallParams{ - URL: endpointURL, - Method: http.MethodGet, - MaxAttempts: options.MaxAttempts, - Headers: headers, - Client: options.HTTPClient, - Response: &response, - ErrorDecoder: errorDecoder, + URL: endpointURL, + Method: http.MethodGet, + MaxAttempts: options.MaxAttempts, + Headers: headers, + BodyProperties: options.BodyProperties, + QueryParameters: options.QueryParameters, + Client: options.HTTPClient, + Response: &response, + ErrorDecoder: errorDecoder, }, ); err != nil { return nil, err @@ -531,6 +545,7 @@ func (c *Client) UpdatePlan( endpointURL := core.EncodeURL(baseURL+"/plans/%v", planID) headers := core.MergeHeaders(c.header.Clone(), options.ToHeader()) + headers.Set("Content-Type", "application/json") errorDecoder := func(statusCode int, body io.Reader) error { raw, err := io.ReadAll(body) @@ -583,14 +598,16 @@ func (c *Client) UpdatePlan( if err := c.caller.Call( ctx, &core.CallParams{ - URL: endpointURL, - Method: http.MethodPut, - MaxAttempts: options.MaxAttempts, - Headers: headers, - Client: options.HTTPClient, - Request: request, - Response: &response, - ErrorDecoder: errorDecoder, + URL: endpointURL, + Method: http.MethodPut, + MaxAttempts: options.MaxAttempts, + Headers: headers, + BodyProperties: options.BodyProperties, + QueryParameters: options.QueryParameters, + Client: options.HTTPClient, + Request: request, + Response: &response, + ErrorDecoder: errorDecoder, }, ); err != nil { return nil, err @@ -661,13 +678,15 @@ func (c *Client) DeletePlan( if err := c.caller.Call( ctx, &core.CallParams{ - URL: endpointURL, - Method: http.MethodDelete, - MaxAttempts: options.MaxAttempts, - Headers: headers, - Client: options.HTTPClient, - Response: &response, - ErrorDecoder: errorDecoder, + URL: endpointURL, + Method: http.MethodDelete, + MaxAttempts: options.MaxAttempts, + Headers: headers, + BodyProperties: options.BodyProperties, + QueryParameters: options.QueryParameters, + Client: options.HTTPClient, + Response: &response, + ErrorDecoder: errorDecoder, }, ); err != nil { return nil, err @@ -694,6 +713,7 @@ func (c *Client) UpsertBillingProductPlan( endpointURL := core.EncodeURL(baseURL+"/plans/%v/billing_products", planID) headers := core.MergeHeaders(c.header.Clone(), options.ToHeader()) + headers.Set("Content-Type", "application/json") errorDecoder := func(statusCode int, body io.Reader) error { raw, err := io.ReadAll(body) @@ -746,14 +766,16 @@ func (c *Client) UpsertBillingProductPlan( if err := c.caller.Call( ctx, &core.CallParams{ - URL: endpointURL, - Method: http.MethodPut, - MaxAttempts: options.MaxAttempts, - Headers: headers, - Client: options.HTTPClient, - Request: request, - Response: &response, - ErrorDecoder: errorDecoder, + URL: endpointURL, + Method: http.MethodPut, + MaxAttempts: options.MaxAttempts, + Headers: headers, + BodyProperties: options.BodyProperties, + QueryParameters: options.QueryParameters, + Client: options.HTTPClient, + Request: request, + Response: &response, + ErrorDecoder: errorDecoder, }, ); err != nil { return nil, err @@ -831,13 +853,15 @@ func (c *Client) CountPlans( if err := c.caller.Call( ctx, &core.CallParams{ - URL: endpointURL, - Method: http.MethodGet, - MaxAttempts: options.MaxAttempts, - Headers: headers, - Client: options.HTTPClient, - Response: &response, - ErrorDecoder: errorDecoder, + URL: endpointURL, + Method: http.MethodGet, + MaxAttempts: options.MaxAttempts, + Headers: headers, + BodyProperties: options.BodyProperties, + QueryParameters: options.QueryParameters, + Client: options.HTTPClient, + Response: &response, + ErrorDecoder: errorDecoder, }, ); err != nil { return nil, err diff --git a/types.go b/types.go index 3e64b7c..a1c7917 100644 --- a/types.go +++ b/types.go @@ -481,6 +481,7 @@ func (b *BillingCustomerResponseData) String() string { } type BillingCustomerSubscription struct { + Currency string `json:"currency" url:"currency"` ExpiredAt *time.Time `json:"expired_at,omitempty" url:"expired_at,omitempty"` TotalPrice int `json:"total_price" url:"total_price"` @@ -611,53 +612,8 @@ func (b *BillingCustomerWithSubscriptionsResponseData) String() string { return fmt.Sprintf("%#v", b) } -type BillingPlan struct { - Description *string `json:"description,omitempty" url:"description,omitempty"` - ID string `json:"id" url:"id"` - ImageURL *string `json:"image_url,omitempty" url:"image_url,omitempty"` - Name string `json:"name" url:"name"` - PlanPeriod *string `json:"plan_period,omitempty" url:"plan_period,omitempty"` - PlanPrice *int `json:"plan_price,omitempty" url:"plan_price,omitempty"` - - extraProperties map[string]interface{} - _rawJSON json.RawMessage -} - -func (b *BillingPlan) GetExtraProperties() map[string]interface{} { - return b.extraProperties -} - -func (b *BillingPlan) UnmarshalJSON(data []byte) error { - type unmarshaler BillingPlan - var value unmarshaler - if err := json.Unmarshal(data, &value); err != nil { - return err - } - *b = BillingPlan(value) - - extraProperties, err := core.ExtractExtraProperties(data, *b) - if err != nil { - return err - } - b.extraProperties = extraProperties - - b._rawJSON = json.RawMessage(data) - return nil -} - -func (b *BillingPlan) String() string { - if len(b._rawJSON) > 0 { - if value, err := core.StringifyJSON(b._rawJSON); err == nil { - return value - } - } - if value, err := core.StringifyJSON(b); err == nil { - return value - } - return fmt.Sprintf("%#v", b) -} - type BillingPriceResponseData struct { + Currency string `json:"currency" url:"currency"` ExternalPriceID string `json:"external_price_id" url:"external_price_id"` ID string `json:"id" url:"id"` Interval string `json:"interval" url:"interval"` @@ -775,18 +731,19 @@ func (b *BillingProductDetailResponseData) String() string { } type BillingProductForSubscriptionResponseData struct { - AccountID string `json:"account_id" url:"account_id"` - CreatedAt time.Time `json:"created_at" url:"created_at"` - Currency string `json:"currency" url:"currency"` - EnvironmentID string `json:"environment_id" url:"environment_id"` - ExternalID string `json:"external_id" url:"external_id"` - ID string `json:"id" url:"id"` - Interval *string `json:"interval,omitempty" url:"interval,omitempty"` - Name string `json:"name" url:"name"` - Price float64 `json:"price" url:"price"` - Quantity float64 `json:"quantity" url:"quantity"` - SubscriptionID string `json:"subscription_id" url:"subscription_id"` - UpdatedAt time.Time `json:"updated_at" url:"updated_at"` + AccountID string `json:"account_id" url:"account_id"` + CreatedAt time.Time `json:"created_at" url:"created_at"` + Currency string `json:"currency" url:"currency"` + EnvironmentID string `json:"environment_id" url:"environment_id"` + ExternalID string `json:"external_id" url:"external_id"` + ID string `json:"id" url:"id"` + Interval string `json:"interval" url:"interval"` + Name string `json:"name" url:"name"` + Price float64 `json:"price" url:"price"` + PriceExternalID string `json:"price_external_id" url:"price_external_id"` + Quantity float64 `json:"quantity" url:"quantity"` + SubscriptionID string `json:"subscription_id" url:"subscription_id"` + UpdatedAt time.Time `json:"updated_at" url:"updated_at"` extraProperties map[string]interface{} _rawJSON json.RawMessage @@ -896,10 +853,11 @@ func (b *BillingProductPlanResponseData) String() string { } type BillingProductPricing struct { - Interval *string `json:"interval,omitempty" url:"interval,omitempty"` - Price int `json:"price" url:"price"` - PriceExternalID *string `json:"price_external_id,omitempty" url:"price_external_id,omitempty"` - ProductExternalID string `json:"product_external_id" url:"product_external_id"` + Currency string `json:"currency" url:"currency"` + Interval string `json:"interval" url:"interval"` + Price int `json:"price" url:"price"` + PriceExternalID string `json:"price_external_id" url:"price_external_id"` + ProductExternalID string `json:"product_external_id" url:"product_external_id"` extraProperties map[string]interface{} _rawJSON json.RawMessage @@ -1011,11 +969,13 @@ func (b *BillingProductResponseData) String() string { return fmt.Sprintf("%#v", b) } -// The created resource type BillingSubscriptionResponseData struct { + Currency string `json:"currency" url:"currency"` ExpiredAt *time.Time `json:"expired_at,omitempty" url:"expired_at,omitempty"` ExternalID string `json:"external_id" url:"external_id"` - ID int `json:"id" url:"id"` + ID string `json:"id" url:"id"` + Interval string `json:"interval" url:"interval"` + TotalPrice int `json:"total_price" url:"total_price"` UpdatedAt time.Time `json:"updated_at" url:"updated_at"` extraProperties map[string]interface{} @@ -1126,8 +1086,8 @@ func (c *CheckFlagOutputWithFlagKey) String() string { } type CheckFlagRequestBody struct { - Company map[string]*string `json:"company,omitempty" url:"company,omitempty"` - User map[string]*string `json:"user,omitempty" url:"user,omitempty"` + Company map[string]string `json:"company,omitempty" url:"company,omitempty"` + User map[string]string `json:"user,omitempty" url:"user,omitempty"` extraProperties map[string]interface{} _rawJSON json.RawMessage @@ -1302,17 +1262,18 @@ func (c *CompanyCrmDealsResponseData) String() string { } type CompanyDetailResponseData struct { - AddOns []*BillingPlan `json:"add_ons,omitempty" url:"add_ons,omitempty"` - CreatedAt time.Time `json:"created_at" url:"created_at"` - EntityTraits []*EntityTraitDetailResponseData `json:"entity_traits,omitempty" url:"entity_traits,omitempty"` - EnvironmentID string `json:"environment_id" url:"environment_id"` - ID string `json:"id" url:"id"` - Keys []*EntityKeyDetailResponseData `json:"keys,omitempty" url:"keys,omitempty"` - LastSeenAt *time.Time `json:"last_seen_at,omitempty" url:"last_seen_at,omitempty"` - LogoURL *string `json:"logo_url,omitempty" url:"logo_url,omitempty"` - Name string `json:"name" url:"name"` - Plan *BillingPlan `json:"plan,omitempty" url:"plan,omitempty"` - Plans []*PreviewObject `json:"plans,omitempty" url:"plans,omitempty"` + AddOns []*CompanyPlanWithBillingSubView `json:"add_ons,omitempty" url:"add_ons,omitempty"` + BillingSubscriptions []*BillingSubscriptionResponseData `json:"billing_subscriptions,omitempty" url:"billing_subscriptions,omitempty"` + CreatedAt time.Time `json:"created_at" url:"created_at"` + EntityTraits []*EntityTraitDetailResponseData `json:"entity_traits,omitempty" url:"entity_traits,omitempty"` + EnvironmentID string `json:"environment_id" url:"environment_id"` + ID string `json:"id" url:"id"` + Keys []*EntityKeyDetailResponseData `json:"keys,omitempty" url:"keys,omitempty"` + LastSeenAt *time.Time `json:"last_seen_at,omitempty" url:"last_seen_at,omitempty"` + LogoURL *string `json:"logo_url,omitempty" url:"logo_url,omitempty"` + Name string `json:"name" url:"name"` + Plan *CompanyPlanWithBillingSubView `json:"plan,omitempty" url:"plan,omitempty"` + Plans []*GenericPreviewObject `json:"plans,omitempty" url:"plans,omitempty"` // A map of trait names to trait values Traits map[string]interface{} `json:"traits,omitempty" url:"traits,omitempty"` UpdatedAt time.Time `json:"updated_at" url:"updated_at"` @@ -1606,6 +1567,7 @@ type CompanyPlanDetailResponseData struct { Features []*FeatureDetailResponseData `json:"features,omitempty" url:"features,omitempty"` Icon string `json:"icon" url:"icon"` ID string `json:"id" url:"id"` + IsDefault bool `json:"is_default" url:"is_default"` MonthlyPrice *BillingPriceResponseData `json:"monthly_price,omitempty" url:"monthly_price,omitempty"` Name string `json:"name" url:"name"` PlanType string `json:"plan_type" url:"plan_type"` @@ -1673,6 +1635,53 @@ func (c *CompanyPlanDetailResponseData) String() string { return fmt.Sprintf("%#v", c) } +type CompanyPlanWithBillingSubView struct { + BillingProductID *string `json:"billing_product_id,omitempty" url:"billing_product_id,omitempty"` + Description *string `json:"description,omitempty" url:"description,omitempty"` + ID string `json:"id" url:"id"` + ImageURL *string `json:"image_url,omitempty" url:"image_url,omitempty"` + Name string `json:"name" url:"name"` + PlanPeriod *string `json:"plan_period,omitempty" url:"plan_period,omitempty"` + PlanPrice *int `json:"plan_price,omitempty" url:"plan_price,omitempty"` + + extraProperties map[string]interface{} + _rawJSON json.RawMessage +} + +func (c *CompanyPlanWithBillingSubView) GetExtraProperties() map[string]interface{} { + return c.extraProperties +} + +func (c *CompanyPlanWithBillingSubView) UnmarshalJSON(data []byte) error { + type unmarshaler CompanyPlanWithBillingSubView + var value unmarshaler + if err := json.Unmarshal(data, &value); err != nil { + return err + } + *c = CompanyPlanWithBillingSubView(value) + + extraProperties, err := core.ExtractExtraProperties(data, *c) + if err != nil { + return err + } + c.extraProperties = extraProperties + + c._rawJSON = json.RawMessage(data) + return nil +} + +func (c *CompanyPlanWithBillingSubView) String() string { + if len(c._rawJSON) > 0 { + if value, err := core.StringifyJSON(c._rawJSON); err == nil { + return value + } + } + if value, err := core.StringifyJSON(c); err == nil { + return value + } + return fmt.Sprintf("%#v", c) +} + type CompanyResponseData struct { CreatedAt time.Time `json:"created_at" url:"created_at"` EnvironmentID string `json:"environment_id" url:"environment_id"` @@ -1747,12 +1756,14 @@ func (c *CompanyResponseData) String() string { } type CompanySubscriptionResponseData struct { + Currency string `json:"currency" url:"currency"` CustomerExternalID string `json:"customer_external_id" url:"customer_external_id"` ExpiredAt *time.Time `json:"expired_at,omitempty" url:"expired_at,omitempty"` Interval string `json:"interval" url:"interval"` LatestInvoice *InvoiceResponseData `json:"latest_invoice,omitempty" url:"latest_invoice,omitempty"` PaymentMethod *PaymentMethodResponseData `json:"payment_method,omitempty" url:"payment_method,omitempty"` Products []*BillingProductForSubscriptionResponseData `json:"products,omitempty" url:"products,omitempty"` + Status string `json:"status" url:"status"` SubscriptionExternalID string `json:"subscription_external_id" url:"subscription_external_id"` TotalPrice int `json:"total_price" url:"total_price"` @@ -1812,7 +1823,6 @@ func (c *CompanySubscriptionResponseData) String() string { return fmt.Sprintf("%#v", c) } -// The returned resource type ComponentHydrateResponseData struct { ActivePlans []*CompanyPlanDetailResponseData `json:"active_plans,omitempty" url:"active_plans,omitempty"` Company *CompanyDetailResponseData `json:"company,omitempty" url:"company,omitempty"` @@ -1860,6 +1870,55 @@ func (c *ComponentHydrateResponseData) String() string { return fmt.Sprintf("%#v", c) } +// The returned resource +type ComponentPreviewResponseData struct { + ActivePlans []*CompanyPlanDetailResponseData `json:"active_plans,omitempty" url:"active_plans,omitempty"` + Company *CompanyDetailResponseData `json:"company,omitempty" url:"company,omitempty"` + Component *ComponentResponseData `json:"component,omitempty" url:"component,omitempty"` + FeatureUsage *FeatureUsageDetailResponseData `json:"feature_usage,omitempty" url:"feature_usage,omitempty"` + Invoices []*InvoiceResponseData `json:"invoices,omitempty" url:"invoices,omitempty"` + StripeEmbed *StripeEmbedInfo `json:"stripe_embed,omitempty" url:"stripe_embed,omitempty"` + Subscription *CompanySubscriptionResponseData `json:"subscription,omitempty" url:"subscription,omitempty"` + UpcomingInvoice *InvoiceResponseData `json:"upcoming_invoice,omitempty" url:"upcoming_invoice,omitempty"` + + extraProperties map[string]interface{} + _rawJSON json.RawMessage +} + +func (c *ComponentPreviewResponseData) GetExtraProperties() map[string]interface{} { + return c.extraProperties +} + +func (c *ComponentPreviewResponseData) UnmarshalJSON(data []byte) error { + type unmarshaler ComponentPreviewResponseData + var value unmarshaler + if err := json.Unmarshal(data, &value); err != nil { + return err + } + *c = ComponentPreviewResponseData(value) + + extraProperties, err := core.ExtractExtraProperties(data, *c) + if err != nil { + return err + } + c.extraProperties = extraProperties + + c._rawJSON = json.RawMessage(data) + return nil +} + +func (c *ComponentPreviewResponseData) String() string { + if len(c._rawJSON) > 0 { + if value, err := core.StringifyJSON(c._rawJSON); err == nil { + return value + } + } + if value, err := core.StringifyJSON(c); err == nil { + return value + } + return fmt.Sprintf("%#v", c) +} + // The updated resource type ComponentResponseData struct { Ast map[string]float64 `json:"ast,omitempty" url:"ast,omitempty"` @@ -2219,6 +2278,7 @@ const ( CreateOrUpdateConditionRequestBodyConditionTypePlan CreateOrUpdateConditionRequestBodyConditionType = "plan" CreateOrUpdateConditionRequestBodyConditionTypeBillingProduct CreateOrUpdateConditionRequestBodyConditionType = "billing_product" CreateOrUpdateConditionRequestBodyConditionTypeCrmProduct CreateOrUpdateConditionRequestBodyConditionType = "crm_product" + CreateOrUpdateConditionRequestBodyConditionTypeBasePlan CreateOrUpdateConditionRequestBodyConditionType = "base_plan" ) func NewCreateOrUpdateConditionRequestBodyConditionTypeFromString(s string) (CreateOrUpdateConditionRequestBodyConditionType, error) { @@ -2237,6 +2297,8 @@ func NewCreateOrUpdateConditionRequestBodyConditionTypeFromString(s string) (Cre return CreateOrUpdateConditionRequestBodyConditionTypeBillingProduct, nil case "crm_product": return CreateOrUpdateConditionRequestBodyConditionTypeCrmProduct, nil + case "base_plan": + return CreateOrUpdateConditionRequestBodyConditionTypeBasePlan, nil } var t CreateOrUpdateConditionRequestBodyConditionType return "", fmt.Errorf("%s is not a valid %T", s, t) @@ -2250,6 +2312,7 @@ func (c CreateOrUpdateConditionRequestBodyConditionType) Ptr() *CreateOrUpdateCo type CreateOrUpdateConditionRequestBodyMetricPeriod string const ( + CreateOrUpdateConditionRequestBodyMetricPeriodBilling CreateOrUpdateConditionRequestBodyMetricPeriod = "billing" CreateOrUpdateConditionRequestBodyMetricPeriodCurrentMonth CreateOrUpdateConditionRequestBodyMetricPeriod = "current_month" CreateOrUpdateConditionRequestBodyMetricPeriodCurrentWeek CreateOrUpdateConditionRequestBodyMetricPeriod = "current_week" CreateOrUpdateConditionRequestBodyMetricPeriodCurrentDay CreateOrUpdateConditionRequestBodyMetricPeriod = "current_day" @@ -2257,6 +2320,8 @@ const ( func NewCreateOrUpdateConditionRequestBodyMetricPeriodFromString(s string) (CreateOrUpdateConditionRequestBodyMetricPeriod, error) { switch s { + case "billing": + return CreateOrUpdateConditionRequestBodyMetricPeriodBilling, nil case "current_month": return CreateOrUpdateConditionRequestBodyMetricPeriodCurrentMonth, nil case "current_week": @@ -2275,12 +2340,14 @@ func (c CreateOrUpdateConditionRequestBodyMetricPeriod) Ptr() *CreateOrUpdateCon type CreateOrUpdateConditionRequestBodyOperator string const ( - CreateOrUpdateConditionRequestBodyOperatorEq CreateOrUpdateConditionRequestBodyOperator = "eq" - CreateOrUpdateConditionRequestBodyOperatorNe CreateOrUpdateConditionRequestBodyOperator = "ne" - CreateOrUpdateConditionRequestBodyOperatorGt CreateOrUpdateConditionRequestBodyOperator = "gt" - CreateOrUpdateConditionRequestBodyOperatorGte CreateOrUpdateConditionRequestBodyOperator = "gte" - CreateOrUpdateConditionRequestBodyOperatorLt CreateOrUpdateConditionRequestBodyOperator = "lt" - CreateOrUpdateConditionRequestBodyOperatorLte CreateOrUpdateConditionRequestBodyOperator = "lte" + CreateOrUpdateConditionRequestBodyOperatorEq CreateOrUpdateConditionRequestBodyOperator = "eq" + CreateOrUpdateConditionRequestBodyOperatorNe CreateOrUpdateConditionRequestBodyOperator = "ne" + CreateOrUpdateConditionRequestBodyOperatorGt CreateOrUpdateConditionRequestBodyOperator = "gt" + CreateOrUpdateConditionRequestBodyOperatorGte CreateOrUpdateConditionRequestBodyOperator = "gte" + CreateOrUpdateConditionRequestBodyOperatorLt CreateOrUpdateConditionRequestBodyOperator = "lt" + CreateOrUpdateConditionRequestBodyOperatorLte CreateOrUpdateConditionRequestBodyOperator = "lte" + CreateOrUpdateConditionRequestBodyOperatorIsEmpty CreateOrUpdateConditionRequestBodyOperator = "is_empty" + CreateOrUpdateConditionRequestBodyOperatorNotEmpty CreateOrUpdateConditionRequestBodyOperator = "not_empty" ) func NewCreateOrUpdateConditionRequestBodyOperatorFromString(s string) (CreateOrUpdateConditionRequestBodyOperator, error) { @@ -2297,6 +2364,10 @@ func NewCreateOrUpdateConditionRequestBodyOperatorFromString(s string) (CreateOr return CreateOrUpdateConditionRequestBodyOperatorLt, nil case "lte": return CreateOrUpdateConditionRequestBodyOperatorLte, nil + case "is_empty": + return CreateOrUpdateConditionRequestBodyOperatorIsEmpty, nil + case "not_empty": + return CreateOrUpdateConditionRequestBodyOperatorNotEmpty, nil } var t CreateOrUpdateConditionRequestBodyOperator return "", fmt.Errorf("%s is not a valid %T", s, t) @@ -2484,6 +2555,7 @@ func (c *CreateReqCommon) String() string { type CreateReqCommonMetricPeriod string const ( + CreateReqCommonMetricPeriodBilling CreateReqCommonMetricPeriod = "billing" CreateReqCommonMetricPeriodCurrentMonth CreateReqCommonMetricPeriod = "current_month" CreateReqCommonMetricPeriodCurrentWeek CreateReqCommonMetricPeriod = "current_week" CreateReqCommonMetricPeriodCurrentDay CreateReqCommonMetricPeriod = "current_day" @@ -2491,6 +2563,8 @@ const ( func NewCreateReqCommonMetricPeriodFromString(s string) (CreateReqCommonMetricPeriod, error) { switch s { + case "billing": + return CreateReqCommonMetricPeriodBilling, nil case "current_month": return CreateReqCommonMetricPeriodCurrentMonth, nil case "current_week": @@ -3532,9 +3606,9 @@ type EventBodyFlagCheck struct { // The reason why the value was returned Reason string `json:"reason" url:"reason"` // Key-value pairs used to to identify company for which the flag was checked - ReqCompany map[string]*string `json:"req_company,omitempty" url:"req_company,omitempty"` + ReqCompany map[string]string `json:"req_company,omitempty" url:"req_company,omitempty"` // Key-value pairs used to to identify user for which the flag was checked - ReqUser map[string]*string `json:"req_user,omitempty" url:"req_user,omitempty"` + ReqUser map[string]string `json:"req_user,omitempty" url:"req_user,omitempty"` // Schematic rule ID (starting with 'rule\_') of the rule that matched for the flag, if any RuleID *string `json:"rule_id,omitempty" url:"rule_id,omitempty"` // Schematic user ID (starting with 'user\_') of the user evaluated, if any @@ -4576,16 +4650,62 @@ func (f *FlagResponseData) String() string { return fmt.Sprintf("%#v", f) } +type GenericPreviewObject struct { + Description *string `json:"description,omitempty" url:"description,omitempty"` + ID string `json:"id" url:"id"` + ImageURL *string `json:"image_url,omitempty" url:"image_url,omitempty"` + Name string `json:"name" url:"name"` + + extraProperties map[string]interface{} + _rawJSON json.RawMessage +} + +func (g *GenericPreviewObject) GetExtraProperties() map[string]interface{} { + return g.extraProperties +} + +func (g *GenericPreviewObject) UnmarshalJSON(data []byte) error { + type unmarshaler GenericPreviewObject + var value unmarshaler + if err := json.Unmarshal(data, &value); err != nil { + return err + } + *g = GenericPreviewObject(value) + + extraProperties, err := core.ExtractExtraProperties(data, *g) + if err != nil { + return err + } + g.extraProperties = extraProperties + + g._rawJSON = json.RawMessage(data) + return nil +} + +func (g *GenericPreviewObject) String() string { + if len(g._rawJSON) > 0 { + if value, err := core.StringifyJSON(g._rawJSON); err == nil { + return value + } + } + if value, err := core.StringifyJSON(g); err == nil { + return value + } + return fmt.Sprintf("%#v", g) +} + type InvoiceRequestBody struct { - AmountDue int `json:"amount_due" url:"amount_due"` - AmountPaid int `json:"amount_paid" url:"amount_paid"` - AmountRemaining int `json:"amount_remaining" url:"amount_remaining"` - CollectionMethod string `json:"collection_method" url:"collection_method"` - Currency string `json:"currency" url:"currency"` - CustomerExternalID string `json:"customer_external_id" url:"customer_external_id"` - DueDate *time.Time `json:"due_date,omitempty" url:"due_date,omitempty"` - SubscriptionExternalID *string `json:"subscription_external_id,omitempty" url:"subscription_external_id,omitempty"` - Subtotal int `json:"subtotal" url:"subtotal"` + AmountDue int `json:"amount_due" url:"amount_due"` + AmountPaid int `json:"amount_paid" url:"amount_paid"` + AmountRemaining int `json:"amount_remaining" url:"amount_remaining"` + CollectionMethod string `json:"collection_method" url:"collection_method"` + Currency string `json:"currency" url:"currency"` + CustomerExternalID string `json:"customer_external_id" url:"customer_external_id"` + DueDate *time.Time `json:"due_date,omitempty" url:"due_date,omitempty"` + PaymentMethodExternalID *string `json:"payment_method_external_id,omitempty" url:"payment_method_external_id,omitempty"` + SubscriptionExternalID *string `json:"subscription_external_id,omitempty" url:"subscription_external_id,omitempty"` + Subtotal int `json:"subtotal" url:"subtotal"` + URL *string `json:"url,omitempty" url:"url,omitempty"` extraProperties map[string]interface{} _rawJSON json.RawMessage @@ -4644,21 +4764,23 @@ func (i *InvoiceRequestBody) String() string { } type InvoiceResponseData struct { - AmountDue int `json:"amount_due" url:"amount_due"` - AmountPaid int `json:"amount_paid" url:"amount_paid"` - AmountRemaining int `json:"amount_remaining" url:"amount_remaining"` - CollectionMethod string `json:"collection_method" url:"collection_method"` - CompanyID *string `json:"company_id,omitempty" url:"company_id,omitempty"` - CreatedAt time.Time `json:"created_at" url:"created_at"` - Currency string `json:"currency" url:"currency"` - CustomerExternalID string `json:"customer_external_id" url:"customer_external_id"` - DueDate *time.Time `json:"due_date,omitempty" url:"due_date,omitempty"` - EnvironmentID string `json:"environment_id" url:"environment_id"` - ExternalID string `json:"external_id" url:"external_id"` - ID string `json:"id" url:"id"` - SubscriptionExternalID *string `json:"subscription_external_id,omitempty" url:"subscription_external_id,omitempty"` - Subtotal int `json:"subtotal" url:"subtotal"` - UpdatedAt time.Time `json:"updated_at" url:"updated_at"` + AmountDue int `json:"amount_due" url:"amount_due"` + AmountPaid int `json:"amount_paid" url:"amount_paid"` + AmountRemaining int `json:"amount_remaining" url:"amount_remaining"` + CollectionMethod string `json:"collection_method" url:"collection_method"` + CompanyID *string `json:"company_id,omitempty" url:"company_id,omitempty"` + CreatedAt time.Time `json:"created_at" url:"created_at"` + Currency string `json:"currency" url:"currency"` + CustomerExternalID string `json:"customer_external_id" url:"customer_external_id"` + DueDate *time.Time `json:"due_date,omitempty" url:"due_date,omitempty"` + EnvironmentID string `json:"environment_id" url:"environment_id"` + ExternalID *string `json:"external_id,omitempty" url:"external_id,omitempty"` + ID string `json:"id" url:"id"` + PaymentMethodExternalID *string `json:"payment_method_external_id,omitempty" url:"payment_method_external_id,omitempty"` + SubscriptionExternalID *string `json:"subscription_external_id,omitempty" url:"subscription_external_id,omitempty"` + Subtotal int `json:"subtotal" url:"subtotal"` + UpdatedAt time.Time `json:"updated_at" url:"updated_at"` + URL *string `json:"url,omitempty" url:"url,omitempty"` extraProperties map[string]interface{} _rawJSON json.RawMessage @@ -4954,12 +5076,16 @@ func (p *PaginationFilter) String() string { } type PaymentMethodRequestBody struct { + AccountLast4 *string `json:"account_last4,omitempty" url:"account_last4,omitempty"` + AccountName *string `json:"account_name,omitempty" url:"account_name,omitempty"` + BankName *string `json:"bank_name,omitempty" url:"bank_name,omitempty"` + BillingEmail *string `json:"billing_email,omitempty" url:"billing_email,omitempty"` + BillingName *string `json:"billing_name,omitempty" url:"billing_name,omitempty"` CardBrand *string `json:"card_brand,omitempty" url:"card_brand,omitempty"` CardExpMonth *int `json:"card_exp_month,omitempty" url:"card_exp_month,omitempty"` CardExpYear *int `json:"card_exp_year,omitempty" url:"card_exp_year,omitempty"` CardLast4 *string `json:"card_last4,omitempty" url:"card_last4,omitempty"` CustomerExternalID string `json:"customer_external_id" url:"customer_external_id"` - InvoiceExternalID *string `json:"invoice_external_id,omitempty" url:"invoice_external_id,omitempty"` PaymentMethodType string `json:"payment_method_type" url:"payment_method_type"` SubscriptionExternalID *string `json:"subscription_external_id,omitempty" url:"subscription_external_id,omitempty"` @@ -5002,6 +5128,11 @@ func (p *PaymentMethodRequestBody) String() string { } type PaymentMethodResponseData struct { + AccountLast4 *string `json:"account_last4,omitempty" url:"account_last4,omitempty"` + AccountName *string `json:"account_name,omitempty" url:"account_name,omitempty"` + BankName *string `json:"bank_name,omitempty" url:"bank_name,omitempty"` + BillingEmail *string `json:"billing_email,omitempty" url:"billing_email,omitempty"` + BillingName *string `json:"billing_name,omitempty" url:"billing_name,omitempty"` CardBrand *string `json:"card_brand,omitempty" url:"card_brand,omitempty"` CardExpMonth *int `json:"card_exp_month,omitempty" url:"card_exp_month,omitempty"` CardExpYear *int `json:"card_exp_year,omitempty" url:"card_exp_year,omitempty"` @@ -5012,7 +5143,6 @@ type PaymentMethodResponseData struct { EnvironmentID string `json:"environment_id" url:"environment_id"` ExternalID string `json:"external_id" url:"external_id"` ID string `json:"id" url:"id"` - InvoiceExternalID *string `json:"invoice_external_id,omitempty" url:"invoice_external_id,omitempty"` PaymentMethodType string `json:"payment_method_type" url:"payment_method_type"` SubscriptionExternalID *string `json:"subscription_external_id,omitempty" url:"subscription_external_id,omitempty"` UpdatedAt time.Time `json:"updated_at" url:"updated_at"` @@ -5233,6 +5363,7 @@ type PlanDetailResponseData struct { Features []*FeatureDetailResponseData `json:"features,omitempty" url:"features,omitempty"` Icon string `json:"icon" url:"icon"` ID string `json:"id" url:"id"` + IsDefault bool `json:"is_default" url:"is_default"` MonthlyPrice *BillingPriceResponseData `json:"monthly_price,omitempty" url:"monthly_price,omitempty"` Name string `json:"name" url:"name"` PlanType string `json:"plan_type" url:"plan_type"` @@ -5500,6 +5631,7 @@ func (p *PlanGroupPlanDetailResponseData) String() string { // The updated resource type PlanGroupResponseData struct { + AddOnIDs []string `json:"add_on_ids,omitempty" url:"add_on_ids,omitempty"` DefaultPlanID *string `json:"default_plan_id,omitempty" url:"default_plan_id,omitempty"` ID string `json:"id" url:"id"` PlanIDs []string `json:"plan_ids,omitempty" url:"plan_ids,omitempty"` @@ -6357,8 +6489,8 @@ func (s *SegmentStatusResp) String() string { } type StripeEmbedInfo struct { - CustomerEkey *string `json:"customer_ekey,omitempty" url:"customer_ekey,omitempty"` - PublishableKey string `json:"publishable_key" url:"publishable_key"` + PublishableKey string `json:"publishable_key" url:"publishable_key"` + SetupIntentClientSecret *string `json:"setup_intent_client_secret,omitempty" url:"setup_intent_client_secret,omitempty"` extraProperties map[string]interface{} _rawJSON json.RawMessage @@ -6519,6 +6651,7 @@ func (u *UpdateReqCommon) String() string { type UpdateReqCommonMetricPeriod string const ( + UpdateReqCommonMetricPeriodBilling UpdateReqCommonMetricPeriod = "billing" UpdateReqCommonMetricPeriodCurrentMonth UpdateReqCommonMetricPeriod = "current_month" UpdateReqCommonMetricPeriodCurrentWeek UpdateReqCommonMetricPeriod = "current_week" UpdateReqCommonMetricPeriodCurrentDay UpdateReqCommonMetricPeriod = "current_day" @@ -6526,6 +6659,8 @@ const ( func NewUpdateReqCommonMetricPeriodFromString(s string) (UpdateReqCommonMetricPeriod, error) { switch s { + case "billing": + return UpdateReqCommonMetricPeriodBilling, nil case "current_month": return UpdateReqCommonMetricPeriodCurrentMonth, nil case "current_week": @@ -7473,6 +7608,56 @@ func (l *ListEnvironmentsParams) String() string { return fmt.Sprintf("%#v", l) } +// Input parameters +type CountBillingProductsParams struct { + IDs []string `json:"ids,omitempty" url:"ids,omitempty"` + // Page limit (default 100) + Limit *int `json:"limit,omitempty" url:"limit,omitempty"` + Name *string `json:"name,omitempty" url:"name,omitempty"` + // Page offset (default 0) + Offset *int `json:"offset,omitempty" url:"offset,omitempty"` + Q *string `json:"q,omitempty" url:"q,omitempty"` + // Filter products that are not linked to any plan + WithoutLinkedToPlan *bool `json:"without_linked_to_plan,omitempty" url:"without_linked_to_plan,omitempty"` + + extraProperties map[string]interface{} + _rawJSON json.RawMessage +} + +func (c *CountBillingProductsParams) GetExtraProperties() map[string]interface{} { + return c.extraProperties +} + +func (c *CountBillingProductsParams) UnmarshalJSON(data []byte) error { + type unmarshaler CountBillingProductsParams + var value unmarshaler + if err := json.Unmarshal(data, &value); err != nil { + return err + } + *c = CountBillingProductsParams(value) + + extraProperties, err := core.ExtractExtraProperties(data, *c) + if err != nil { + return err + } + c.extraProperties = extraProperties + + c._rawJSON = json.RawMessage(data) + return nil +} + +func (c *CountBillingProductsParams) String() string { + if len(c._rawJSON) > 0 { + if value, err := core.StringifyJSON(c._rawJSON); err == nil { + return value + } + } + if value, err := core.StringifyJSON(c); err == nil { + return value + } + return fmt.Sprintf("%#v", c) +} + // Input parameters type CountCustomersParams struct { FailedToImport *bool `json:"failed_to_import,omitempty" url:"failed_to_import,omitempty"` @@ -7530,6 +7715,8 @@ type ListBillingProductsParams struct { // Page offset (default 0) Offset *int `json:"offset,omitempty" url:"offset,omitempty"` Q *string `json:"q,omitempty" url:"q,omitempty"` + // Filter products that are not linked to any plan + WithoutLinkedToPlan *bool `json:"without_linked_to_plan,omitempty" url:"without_linked_to_plan,omitempty"` extraProperties map[string]interface{} _rawJSON json.RawMessage @@ -7669,7 +7856,6 @@ func (l *ListInvoicesParams) String() string { type ListPaymentMethodsParams struct { CompanyID *string `json:"company_id,omitempty" url:"company_id,omitempty"` CustomerExternalID *string `json:"customer_external_id,omitempty" url:"customer_external_id,omitempty"` - InvoiceExternalID *string `json:"invoice_external_id,omitempty" url:"invoice_external_id,omitempty"` // Page limit (default 100) Limit *int `json:"limit,omitempty" url:"limit,omitempty"` // Page offset (default 0) @@ -7723,6 +7909,8 @@ type ListProductPricesParams struct { // Page offset (default 0) Offset *int `json:"offset,omitempty" url:"offset,omitempty"` Q *string `json:"q,omitempty" url:"q,omitempty"` + // Filter products that are not linked to any plan + WithoutLinkedToPlan *bool `json:"without_linked_to_plan,omitempty" url:"without_linked_to_plan,omitempty"` extraProperties map[string]interface{} _rawJSON json.RawMessage @@ -7764,13 +7952,15 @@ func (l *ListProductPricesParams) String() string { // Input parameters type CountCompaniesParams struct { + // Filter companies by multiple company IDs (starts with comp\_) IDs []string `json:"ids,omitempty" url:"ids,omitempty"` // Page limit (default 100) Limit *int `json:"limit,omitempty" url:"limit,omitempty"` // Page offset (default 0) - Offset *int `json:"offset,omitempty" url:"offset,omitempty"` + Offset *int `json:"offset,omitempty" url:"offset,omitempty"` + // Filter companies by plan ID (starts with plan\_) PlanID *string `json:"plan_id,omitempty" url:"plan_id,omitempty"` - // Search filter + // Search for companies by name, keys or string traits Q *string `json:"q,omitempty" url:"q,omitempty"` // Filter out companies that already have a company override for the specified feature ID WithoutFeatureOverrideFor *string `json:"without_feature_override_for,omitempty" url:"without_feature_override_for,omitempty"` @@ -7992,14 +8182,17 @@ func (c CountEntityTraitDefinitionsResponseParamsTraitType) Ptr() *CountEntityTr // Input parameters type CountUsersParams struct { - CompanyID *string `json:"company_id,omitempty" url:"company_id,omitempty"` - IDs []string `json:"ids,omitempty" url:"ids,omitempty"` + // Filter users by company ID (starts with comp\_) + CompanyID *string `json:"company_id,omitempty" url:"company_id,omitempty"` + // Filter users by multiple user IDs (starts with user\_) + IDs []string `json:"ids,omitempty" url:"ids,omitempty"` // Page limit (default 100) Limit *int `json:"limit,omitempty" url:"limit,omitempty"` // Page offset (default 0) - Offset *int `json:"offset,omitempty" url:"offset,omitempty"` + Offset *int `json:"offset,omitempty" url:"offset,omitempty"` + // Filter users by plan ID (starts with plan\_) PlanID *string `json:"plan_id,omitempty" url:"plan_id,omitempty"` - // Search filter + // Search for users by name, keys or string traits Q *string `json:"q,omitempty" url:"q,omitempty"` extraProperties map[string]interface{} @@ -8182,13 +8375,15 @@ func (g *GetEntityTraitValuesParams) String() string { // Input parameters type ListCompaniesParams struct { + // Filter companies by multiple company IDs (starts with comp\_) IDs []string `json:"ids,omitempty" url:"ids,omitempty"` // Page limit (default 100) Limit *int `json:"limit,omitempty" url:"limit,omitempty"` // Page offset (default 0) - Offset *int `json:"offset,omitempty" url:"offset,omitempty"` + Offset *int `json:"offset,omitempty" url:"offset,omitempty"` + // Filter companies by plan ID (starts with plan\_) PlanID *string `json:"plan_id,omitempty" url:"plan_id,omitempty"` - // Search filter + // Search for companies by name, keys or string traits Q *string `json:"q,omitempty" url:"q,omitempty"` // Filter out companies that already have a company override for the specified feature ID WithoutFeatureOverrideFor *string `json:"without_feature_override_for,omitempty" url:"without_feature_override_for,omitempty"` @@ -8457,14 +8652,17 @@ func (l ListEntityTraitDefinitionsResponseParamsTraitType) Ptr() *ListEntityTrai // Input parameters type ListUsersParams struct { - CompanyID *string `json:"company_id,omitempty" url:"company_id,omitempty"` - IDs []string `json:"ids,omitempty" url:"ids,omitempty"` + // Filter users by company ID (starts with comp\_) + CompanyID *string `json:"company_id,omitempty" url:"company_id,omitempty"` + // Filter users by multiple user IDs (starts with user\_) + IDs []string `json:"ids,omitempty" url:"ids,omitempty"` // Page limit (default 100) Limit *int `json:"limit,omitempty" url:"limit,omitempty"` // Page offset (default 0) - Offset *int `json:"offset,omitempty" url:"offset,omitempty"` + Offset *int `json:"offset,omitempty" url:"offset,omitempty"` + // Filter users by plan ID (starts with plan\_) PlanID *string `json:"plan_id,omitempty" url:"plan_id,omitempty"` - // Search filter + // Search for users by name, keys or string traits Q *string `json:"q,omitempty" url:"q,omitempty"` extraProperties map[string]interface{} @@ -8773,16 +8971,22 @@ func (l *ListCrmProductsParams) String() string { // Input parameters type CountCompanyOverridesParams struct { - CompanyID *string `json:"company_id,omitempty" url:"company_id,omitempty"` + // Filter company overrides by a single company ID (starting with comp\_) + CompanyID *string `json:"company_id,omitempty" url:"company_id,omitempty"` + // Filter company overrides by multiple company IDs (starting with comp\_) CompanyIDs []string `json:"company_ids,omitempty" url:"company_ids,omitempty"` - FeatureID *string `json:"feature_id,omitempty" url:"feature_id,omitempty"` + // Filter company overrides by a single feature ID (starting with feat\_) + FeatureID *string `json:"feature_id,omitempty" url:"feature_id,omitempty"` + // Filter company overrides by multiple feature IDs (starting with feat\_) FeatureIDs []string `json:"feature_ids,omitempty" url:"feature_ids,omitempty"` - IDs []string `json:"ids,omitempty" url:"ids,omitempty"` + // Filter company overrides by multiple company override IDs (starting with cmov\_) + IDs []string `json:"ids,omitempty" url:"ids,omitempty"` // Page limit (default 100) Limit *int `json:"limit,omitempty" url:"limit,omitempty"` // Page offset (default 0) - Offset *int `json:"offset,omitempty" url:"offset,omitempty"` - Q *string `json:"q,omitempty" url:"q,omitempty"` + Offset *int `json:"offset,omitempty" url:"offset,omitempty"` + // Search for company overrides by feature or company name + Q *string `json:"q,omitempty" url:"q,omitempty"` extraProperties map[string]interface{} _rawJSON json.RawMessage @@ -8877,8 +9081,9 @@ type CountFeatureUsageParams struct { // Page limit (default 100) Limit *int `json:"limit,omitempty" url:"limit,omitempty"` // Page offset (default 0) - Offset *int `json:"offset,omitempty" url:"offset,omitempty"` - Q *string `json:"q,omitempty" url:"q,omitempty"` + Offset *int `json:"offset,omitempty" url:"offset,omitempty"` + Q *string `json:"q,omitempty" url:"q,omitempty"` + WithoutNegativeEntitlements *bool `json:"without_negative_entitlements,omitempty" url:"without_negative_entitlements,omitempty"` extraProperties map[string]interface{} _rawJSON json.RawMessage @@ -8967,16 +9172,22 @@ func (c *CountFeatureUsersParams) String() string { // Input parameters type CountPlanEntitlementsParams struct { - FeatureID *string `json:"feature_id,omitempty" url:"feature_id,omitempty"` + // Filter plan entitlements by a single feature ID (starting with feat\_) + FeatureID *string `json:"feature_id,omitempty" url:"feature_id,omitempty"` + // Filter plan entitlements by multiple feature IDs (starting with feat\_) FeatureIDs []string `json:"feature_ids,omitempty" url:"feature_ids,omitempty"` - IDs []string `json:"ids,omitempty" url:"ids,omitempty"` + // Filter plan entitlements by multiple plan entitlement IDs (starting with pltl\_) + IDs []string `json:"ids,omitempty" url:"ids,omitempty"` // Page limit (default 100) Limit *int `json:"limit,omitempty" url:"limit,omitempty"` // Page offset (default 0) - Offset *int `json:"offset,omitempty" url:"offset,omitempty"` - PlanID *string `json:"plan_id,omitempty" url:"plan_id,omitempty"` + Offset *int `json:"offset,omitempty" url:"offset,omitempty"` + // Filter plan entitlements by a single plan ID (starting with plan\_) + PlanID *string `json:"plan_id,omitempty" url:"plan_id,omitempty"` + // Filter plan entitlements by multiple plan IDs (starting with plan\_) PlanIDs []string `json:"plan_ids,omitempty" url:"plan_ids,omitempty"` - Q *string `json:"q,omitempty" url:"q,omitempty"` + // Search for plan entitlements by feature or company name + Q *string `json:"q,omitempty" url:"q,omitempty"` extraProperties map[string]interface{} _rawJSON json.RawMessage @@ -9060,16 +9271,22 @@ func (g *GetFeatureUsageByCompanyParams) String() string { // Input parameters type ListCompanyOverridesParams struct { - CompanyID *string `json:"company_id,omitempty" url:"company_id,omitempty"` + // Filter company overrides by a single company ID (starting with comp\_) + CompanyID *string `json:"company_id,omitempty" url:"company_id,omitempty"` + // Filter company overrides by multiple company IDs (starting with comp\_) CompanyIDs []string `json:"company_ids,omitempty" url:"company_ids,omitempty"` - FeatureID *string `json:"feature_id,omitempty" url:"feature_id,omitempty"` + // Filter company overrides by a single feature ID (starting with feat\_) + FeatureID *string `json:"feature_id,omitempty" url:"feature_id,omitempty"` + // Filter company overrides by multiple feature IDs (starting with feat\_) FeatureIDs []string `json:"feature_ids,omitempty" url:"feature_ids,omitempty"` - IDs []string `json:"ids,omitempty" url:"ids,omitempty"` + // Filter company overrides by multiple company override IDs (starting with cmov\_) + IDs []string `json:"ids,omitempty" url:"ids,omitempty"` // Page limit (default 100) Limit *int `json:"limit,omitempty" url:"limit,omitempty"` // Page offset (default 0) - Offset *int `json:"offset,omitempty" url:"offset,omitempty"` - Q *string `json:"q,omitempty" url:"q,omitempty"` + Offset *int `json:"offset,omitempty" url:"offset,omitempty"` + // Search for company overrides by feature or company name + Q *string `json:"q,omitempty" url:"q,omitempty"` extraProperties map[string]interface{} _rawJSON json.RawMessage @@ -9164,8 +9381,9 @@ type ListFeatureUsageParams struct { // Page limit (default 100) Limit *int `json:"limit,omitempty" url:"limit,omitempty"` // Page offset (default 0) - Offset *int `json:"offset,omitempty" url:"offset,omitempty"` - Q *string `json:"q,omitempty" url:"q,omitempty"` + Offset *int `json:"offset,omitempty" url:"offset,omitempty"` + Q *string `json:"q,omitempty" url:"q,omitempty"` + WithoutNegativeEntitlements *bool `json:"without_negative_entitlements,omitempty" url:"without_negative_entitlements,omitempty"` extraProperties map[string]interface{} _rawJSON json.RawMessage @@ -9254,16 +9472,22 @@ func (l *ListFeatureUsersParams) String() string { // Input parameters type ListPlanEntitlementsParams struct { - FeatureID *string `json:"feature_id,omitempty" url:"feature_id,omitempty"` + // Filter plan entitlements by a single feature ID (starting with feat\_) + FeatureID *string `json:"feature_id,omitempty" url:"feature_id,omitempty"` + // Filter plan entitlements by multiple feature IDs (starting with feat\_) FeatureIDs []string `json:"feature_ids,omitempty" url:"feature_ids,omitempty"` - IDs []string `json:"ids,omitempty" url:"ids,omitempty"` + // Filter plan entitlements by multiple plan entitlement IDs (starting with pltl\_) + IDs []string `json:"ids,omitempty" url:"ids,omitempty"` // Page limit (default 100) Limit *int `json:"limit,omitempty" url:"limit,omitempty"` // Page offset (default 0) - Offset *int `json:"offset,omitempty" url:"offset,omitempty"` - PlanID *string `json:"plan_id,omitempty" url:"plan_id,omitempty"` + Offset *int `json:"offset,omitempty" url:"offset,omitempty"` + // Filter plan entitlements by a single plan ID (starting with plan\_) + PlanID *string `json:"plan_id,omitempty" url:"plan_id,omitempty"` + // Filter plan entitlements by multiple plan IDs (starting with plan\_) PlanIDs []string `json:"plan_ids,omitempty" url:"plan_ids,omitempty"` - Q *string `json:"q,omitempty" url:"q,omitempty"` + // Search for plan entitlements by feature or company name + Q *string `json:"q,omitempty" url:"q,omitempty"` extraProperties map[string]interface{} _rawJSON json.RawMessage @@ -9688,6 +9912,8 @@ type CountPlansParams struct { Q *string `json:"q,omitempty" url:"q,omitempty"` // Filter out plans that already have a plan entitlement for the specified feature ID WithoutEntitlementFor *string `json:"without_entitlement_for,omitempty" url:"without_entitlement_for,omitempty"` + // Filter out plans that have a billing product ID + WithoutProductID *bool `json:"without_product_id,omitempty" url:"without_product_id,omitempty"` extraProperties map[string]interface{} _rawJSON json.RawMessage @@ -9765,6 +9991,8 @@ type ListPlansParams struct { Q *string `json:"q,omitempty" url:"q,omitempty"` // Filter out plans that already have a plan entitlement for the specified feature ID WithoutEntitlementFor *string `json:"without_entitlement_for,omitempty" url:"without_entitlement_for,omitempty"` + // Filter out plans that have a billing product ID + WithoutProductID *bool `json:"without_product_id,omitempty" url:"without_product_id,omitempty"` extraProperties map[string]interface{} _rawJSON json.RawMessage diff --git a/webhooks.go b/webhooks.go index 7399a55..06411db 100644 --- a/webhooks.go +++ b/webhooks.go @@ -9,9 +9,9 @@ import ( ) type CountWebhookEventsRequest struct { - WebhookID *string `json:"-" url:"webhook_id,omitempty"` IDs []*string `json:"-" url:"ids,omitempty"` Q *string `json:"-" url:"q,omitempty"` + WebhookID *string `json:"-" url:"webhook_id,omitempty"` // Page limit (default 100) Limit *int `json:"-" url:"limit,omitempty"` // Page offset (default 0) @@ -33,9 +33,9 @@ type CreateWebhookRequestBody struct { } type ListWebhookEventsRequest struct { - WebhookID *string `json:"-" url:"webhook_id,omitempty"` IDs []*string `json:"-" url:"ids,omitempty"` Q *string `json:"-" url:"q,omitempty"` + WebhookID *string `json:"-" url:"webhook_id,omitempty"` // Page limit (default 100) Limit *int `json:"-" url:"limit,omitempty"` // Page offset (default 0) diff --git a/webhooks/client.go b/webhooks/client.go index ef5fd59..0b50fc5 100644 --- a/webhooks/client.go +++ b/webhooks/client.go @@ -104,13 +104,15 @@ func (c *Client) ListWebhookEvents( if err := c.caller.Call( ctx, &core.CallParams{ - URL: endpointURL, - Method: http.MethodGet, - MaxAttempts: options.MaxAttempts, - Headers: headers, - Client: options.HTTPClient, - Response: &response, - ErrorDecoder: errorDecoder, + URL: endpointURL, + Method: http.MethodGet, + MaxAttempts: options.MaxAttempts, + Headers: headers, + BodyProperties: options.BodyProperties, + QueryParameters: options.QueryParameters, + Client: options.HTTPClient, + Response: &response, + ErrorDecoder: errorDecoder, }, ); err != nil { return nil, err @@ -181,13 +183,15 @@ func (c *Client) GetWebhookEvent( if err := c.caller.Call( ctx, &core.CallParams{ - URL: endpointURL, - Method: http.MethodGet, - MaxAttempts: options.MaxAttempts, - Headers: headers, - Client: options.HTTPClient, - Response: &response, - ErrorDecoder: errorDecoder, + URL: endpointURL, + Method: http.MethodGet, + MaxAttempts: options.MaxAttempts, + Headers: headers, + BodyProperties: options.BodyProperties, + QueryParameters: options.QueryParameters, + Client: options.HTTPClient, + Response: &response, + ErrorDecoder: errorDecoder, }, ); err != nil { return nil, err @@ -265,13 +269,15 @@ func (c *Client) CountWebhookEvents( if err := c.caller.Call( ctx, &core.CallParams{ - URL: endpointURL, - Method: http.MethodGet, - MaxAttempts: options.MaxAttempts, - Headers: headers, - Client: options.HTTPClient, - Response: &response, - ErrorDecoder: errorDecoder, + URL: endpointURL, + Method: http.MethodGet, + MaxAttempts: options.MaxAttempts, + Headers: headers, + BodyProperties: options.BodyProperties, + QueryParameters: options.QueryParameters, + Client: options.HTTPClient, + Response: &response, + ErrorDecoder: errorDecoder, }, ); err != nil { return nil, err @@ -349,13 +355,15 @@ func (c *Client) ListWebhooks( if err := c.caller.Call( ctx, &core.CallParams{ - URL: endpointURL, - Method: http.MethodGet, - MaxAttempts: options.MaxAttempts, - Headers: headers, - Client: options.HTTPClient, - Response: &response, - ErrorDecoder: errorDecoder, + URL: endpointURL, + Method: http.MethodGet, + MaxAttempts: options.MaxAttempts, + Headers: headers, + BodyProperties: options.BodyProperties, + QueryParameters: options.QueryParameters, + Client: options.HTTPClient, + Response: &response, + ErrorDecoder: errorDecoder, }, ); err != nil { return nil, err @@ -380,6 +388,7 @@ func (c *Client) CreateWebhook( endpointURL := baseURL + "/webhooks" headers := core.MergeHeaders(c.header.Clone(), options.ToHeader()) + headers.Set("Content-Type", "application/json") errorDecoder := func(statusCode int, body io.Reader) error { raw, err := io.ReadAll(body) @@ -425,14 +434,16 @@ func (c *Client) CreateWebhook( if err := c.caller.Call( ctx, &core.CallParams{ - URL: endpointURL, - Method: http.MethodPost, - MaxAttempts: options.MaxAttempts, - Headers: headers, - Client: options.HTTPClient, - Request: request, - Response: &response, - ErrorDecoder: errorDecoder, + URL: endpointURL, + Method: http.MethodPost, + MaxAttempts: options.MaxAttempts, + Headers: headers, + BodyProperties: options.BodyProperties, + QueryParameters: options.QueryParameters, + Client: options.HTTPClient, + Request: request, + Response: &response, + ErrorDecoder: errorDecoder, }, ); err != nil { return nil, err @@ -503,13 +514,15 @@ func (c *Client) GetWebhook( if err := c.caller.Call( ctx, &core.CallParams{ - URL: endpointURL, - Method: http.MethodGet, - MaxAttempts: options.MaxAttempts, - Headers: headers, - Client: options.HTTPClient, - Response: &response, - ErrorDecoder: errorDecoder, + URL: endpointURL, + Method: http.MethodGet, + MaxAttempts: options.MaxAttempts, + Headers: headers, + BodyProperties: options.BodyProperties, + QueryParameters: options.QueryParameters, + Client: options.HTTPClient, + Response: &response, + ErrorDecoder: errorDecoder, }, ); err != nil { return nil, err @@ -536,6 +549,7 @@ func (c *Client) UpdateWebhook( endpointURL := core.EncodeURL(baseURL+"/webhooks/%v", webhookID) headers := core.MergeHeaders(c.header.Clone(), options.ToHeader()) + headers.Set("Content-Type", "application/json") errorDecoder := func(statusCode int, body io.Reader) error { raw, err := io.ReadAll(body) @@ -588,14 +602,16 @@ func (c *Client) UpdateWebhook( if err := c.caller.Call( ctx, &core.CallParams{ - URL: endpointURL, - Method: http.MethodPut, - MaxAttempts: options.MaxAttempts, - Headers: headers, - Client: options.HTTPClient, - Request: request, - Response: &response, - ErrorDecoder: errorDecoder, + URL: endpointURL, + Method: http.MethodPut, + MaxAttempts: options.MaxAttempts, + Headers: headers, + BodyProperties: options.BodyProperties, + QueryParameters: options.QueryParameters, + Client: options.HTTPClient, + Request: request, + Response: &response, + ErrorDecoder: errorDecoder, }, ); err != nil { return nil, err @@ -666,13 +682,15 @@ func (c *Client) DeleteWebhook( if err := c.caller.Call( ctx, &core.CallParams{ - URL: endpointURL, - Method: http.MethodDelete, - MaxAttempts: options.MaxAttempts, - Headers: headers, - Client: options.HTTPClient, - Response: &response, - ErrorDecoder: errorDecoder, + URL: endpointURL, + Method: http.MethodDelete, + MaxAttempts: options.MaxAttempts, + Headers: headers, + BodyProperties: options.BodyProperties, + QueryParameters: options.QueryParameters, + Client: options.HTTPClient, + Response: &response, + ErrorDecoder: errorDecoder, }, ); err != nil { return nil, err @@ -750,13 +768,15 @@ func (c *Client) CountWebhooks( if err := c.caller.Call( ctx, &core.CallParams{ - URL: endpointURL, - Method: http.MethodGet, - MaxAttempts: options.MaxAttempts, - Headers: headers, - Client: options.HTTPClient, - Response: &response, - ErrorDecoder: errorDecoder, + URL: endpointURL, + Method: http.MethodGet, + MaxAttempts: options.MaxAttempts, + Headers: headers, + BodyProperties: options.BodyProperties, + QueryParameters: options.QueryParameters, + Client: options.HTTPClient, + Response: &response, + ErrorDecoder: errorDecoder, }, ); err != nil { return nil, err